Skip to content

Commit

Permalink
feat: update eip 7702 auth format
Browse files Browse the repository at this point in the history
  • Loading branch information
adamegyed committed Feb 7, 2025
1 parent 6d6c3db commit b3acd54
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 19 deletions.
24 changes: 7 additions & 17 deletions aa-sdk/core/src/middleware/defaults/7702gasEstimator.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { zeroHash, toHex } from "viem";
import { zeroHash } from "viem";
import { AccountNotFoundError } from "../../errors/account.js";
import { ChainNotFoundError } from "../../errors/client.js";
import type { UserOperationStruct } from "../../types.js";
import type { ClientMiddlewareFn } from "../types";
import { defaultGasEstimator } from "./gasEstimator.js";
Expand Down Expand Up @@ -50,38 +49,29 @@ export const default7702GasEstimator: (
throw new AccountNotFoundError();
}

if (!params.client.chain) {
throw new ChainNotFoundError();
}

const entryPoint = account.getEntryPoint();
if (entryPoint.version !== "0.7.0") {
throw new Error(
"This middleware is only compatible with EntryPoint v0.7.0"
);
}

// todo: persist this in context so the signer doesn't have to re-fetch.
const accountNonce = await params.client.getTransactionCount({
address: account.address,
});

const implementationAddress = await account.getImplementationAddress();

// Note: does not omit the delegation from estimation if the account is already 7702 delegated.

(struct as UserOperationStruct<"0.7.0">).eip7702auth = {
chainId: toHex(params.client.chain.id),
nonce: toHex(accountNonce),
(struct as UserOperationStruct<"0.7.0">).eip7702Auth = {
chainId: "0x0",
nonce: "0x0",
address: implementationAddress,
r: zeroHash,
r: zeroHash, // aka `bytes32(0)`
s: zeroHash,
yParity: toHex(0),
yParity: "0x0",
};

const estimatedUO = await gasEstimator_(struct, params);

estimatedUO.eip7702auth = undefined; // Strip out the auth after estimation.
estimatedUO.eip7702Auth = undefined; // Strip out the auth after estimation.

return estimatedUO;
};
2 changes: 1 addition & 1 deletion aa-sdk/core/src/middleware/defaults/7702signer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ export const default7702UserOpSigner: (

return {
...uo,
eip7702auth: {
eip7702Auth: {
// deepHexlify doesn't encode number(0) correctly, it returns "0x"
chainId: toHex(client.chain.id),
nonce: toHex(accountNonce),
Expand Down
2 changes: 1 addition & 1 deletion aa-sdk/core/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ export interface UserOperationRequest_v7 {
// [!endregion UserOperationRequest_v7]

export type Eip7702ExtendedFields = {
eip7702auth?: {
eip7702Auth?: {
chainId: Hex;
nonce: Hex;
address: Address;
Expand Down

0 comments on commit b3acd54

Please sign in to comment.