@aa-sdk/core 4.50.1 → 4.51.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,4 +1,4 @@
1
- import { zeroHash } from "viem";
1
+ import { concatHex, numberToHex, zeroHash } from "viem";
2
2
  import { AccountNotFoundError } from "../../errors/account.js";
3
3
  import { defaultGasEstimator } from "./gasEstimator.js";
4
4
  /**
@@ -45,16 +45,23 @@ export const default7702GasEstimator = (gasEstimator) => async (struct, params)
45
45
  if (entryPoint.version !== "0.7.0") {
46
46
  throw new Error("This middleware is only compatible with EntryPoint v0.7.0");
47
47
  }
48
- const implementationAddress = await account.getImplementationAddress();
49
- // Note: does not omit the delegation from estimation if the account is already 7702 delegated.
50
- struct.eip7702Auth = {
51
- chainId: "0x0",
52
- nonce: "0x0",
53
- address: implementationAddress,
54
- r: zeroHash, // aka `bytes32(0)`
55
- s: zeroHash,
56
- yParity: "0x0",
57
- };
48
+ const [implementationAddress, code = "0x"] = await Promise.all([
49
+ account.getImplementationAddress(),
50
+ params.client.getCode({ address: params.account.address }),
51
+ ]);
52
+ const isAlreadyDelegated = code.toLowerCase() === concatHex(["0xef0100", implementationAddress]);
53
+ if (!isAlreadyDelegated) {
54
+ struct.eip7702Auth = {
55
+ chainId: numberToHex(params.client.chain?.id ?? 0),
56
+ nonce: numberToHex(await params.client.getTransactionCount({
57
+ address: params.account.address,
58
+ })),
59
+ address: implementationAddress,
60
+ r: zeroHash, // aka `bytes32(0)`
61
+ s: zeroHash,
62
+ yParity: "0x0",
63
+ };
64
+ }
58
65
  return gasEstimator_(struct, params);
59
66
  };
60
67
  //# sourceMappingURL=7702gasEstimator.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"7702gasEstimator.js","sourceRoot":"","sources":["../../../../src/middleware/defaults/7702gasEstimator.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,MAAM,CAAC;AAChC,OAAO,EAAE,oBAAoB,EAAE,MAAM,yBAAyB,CAAC;AAG/D,OAAO,EAAE,mBAAmB,EAAE,MAAM,mBAAmB,CAAC;AAExD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiCG;AACH,MAAM,CAAC,MAAM,uBAAuB,GAGlC,CAAC,YAAiC,EAAE,EAAE,CAAC,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,EAAE;IAC9D,MAAM,aAAa,GAAG,YAAY,IAAI,mBAAmB,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;IAEzE,MAAM,OAAO,GAAG,MAAM,CAAC,OAAO,IAAI,MAAM,CAAC,MAAM,CAAC,OAAO,CAAC;IACxD,IAAI,CAAC,OAAO,EAAE,CAAC;QACb,MAAM,IAAI,oBAAoB,EAAE,CAAC;IACnC,CAAC;IAED,MAAM,UAAU,GAAG,OAAO,CAAC,aAAa,EAAE,CAAC;IAC3C,IAAI,UAAU,CAAC,OAAO,KAAK,OAAO,EAAE,CAAC;QACnC,MAAM,IAAI,KAAK,CACb,2DAA2D,CAC5D,CAAC;IACJ,CAAC;IAED,MAAM,qBAAqB,GAAG,MAAM,OAAO,CAAC,wBAAwB,EAAE,CAAC;IAEvE,+FAA+F;IAE9F,MAAuC,CAAC,WAAW,GAAG;QACrD,OAAO,EAAE,KAAK;QACd,KAAK,EAAE,KAAK;QACZ,OAAO,EAAE,qBAAqB;QAC9B,CAAC,EAAE,QAAQ,EAAE,mBAAmB;QAChC,CAAC,EAAE,QAAQ;QACX,OAAO,EAAE,KAAK;KACf,CAAC;IAEF,OAAO,aAAa,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;AACvC,CAAC,CAAC","sourcesContent":["import { zeroHash } from \"viem\";\nimport { AccountNotFoundError } from \"../../errors/account.js\";\nimport type { UserOperationStruct } from \"../../types.js\";\nimport type { ClientMiddlewareFn } from \"../types\";\nimport { defaultGasEstimator } from \"./gasEstimator.js\";\n\n/**\n * A middleware function to estimate the gas usage of a user operation when using an EIP-7702 delegated account. Has an optional custom gas estimator.\n * This function is only compatible with accounts using EntryPoint v0.7.0, and the account must have an implementation address defined in `getImplementationAddress()`.\n *\n * @example\n * ```ts twoslash\n * import {\n * default7702GasEstimator,\n * default7702UserOpSigner,\n * createSmartAccountClient,\n * type SmartAccountClient,\n * } from \"@aa-sdk/core\";\n * import {\n * createModularAccountV2,\n * type CreateModularAccountV2ClientParams,\n * } from \"@account-kit/smart-contracts\";\n *\n * async function createSMA7702AccountClient(\n * config: CreateModularAccountV2ClientParams\n * ): Promise<SmartAccountClient> {\n * const sma7702Account = await createModularAccountV2({ ...config, mode: \"7702\" });\n *\n * return createSmartAccountClient({\n * account: sma7702Account,\n * gasEstimator: default7702GasEstimator(config.gasEstimator),\n * signUserOperation: default7702UserOpSigner(config.signUserOperation),\n * ...config,\n * });\n * }\n * ```\n *\n * @param {ClientMiddlewareFn} gasEstimator Optional custom gas estimator function\n * @returns {ClientMiddlewareFn} A function that takes user operation struct and parameters, estimates gas usage, and returns the user operation with gas limits.\n */\nexport const default7702GasEstimator: (\n gasEstimator?: ClientMiddlewareFn,\n) => ClientMiddlewareFn =\n (gasEstimator?: ClientMiddlewareFn) => async (struct, params) => {\n const gasEstimator_ = gasEstimator ?? defaultGasEstimator(params.client);\n\n const account = params.account ?? params.client.account;\n if (!account) {\n throw new AccountNotFoundError();\n }\n\n const entryPoint = account.getEntryPoint();\n if (entryPoint.version !== \"0.7.0\") {\n throw new Error(\n \"This middleware is only compatible with EntryPoint v0.7.0\",\n );\n }\n\n const implementationAddress = await account.getImplementationAddress();\n\n // Note: does not omit the delegation from estimation if the account is already 7702 delegated.\n\n (struct as UserOperationStruct<\"0.7.0\">).eip7702Auth = {\n chainId: \"0x0\",\n nonce: \"0x0\",\n address: implementationAddress,\n r: zeroHash, // aka `bytes32(0)`\n s: zeroHash,\n yParity: \"0x0\",\n };\n\n return gasEstimator_(struct, params);\n };\n"]}
1
+ {"version":3,"file":"7702gasEstimator.js","sourceRoot":"","sources":["../../../../src/middleware/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ACrD,OAAO,EAAE,WAAW,CAAC,MAAM,CAAC,MAAM,CAAC,KAAK,EAAE,EAAE,IAAI,CAAC,CAAC;YAClD,KAAK,EAAE,WAAW,CAChB,MAAM,MAAM,CAAC,MAAM,CAAC,mBAAmB,CAAC;gBACtC,OAAO,EAAE,MAAM,CAAC,OAAO,CAAC,OAAO;aAChC,CAAC,CACH;YACD,OAAO,EAAE,qBAAqB;YAC9B,CAAC,EAAE,QAAQ,EAAE,mBAAmB;YAChC,CAAC,EAAE,QAAQ;YACX,OAAO,EAAE,KAAK;SACf,CAAC;IACJ,CAAC;IAED,OAAO,aAAa,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;AACvC,CAAC,CAAC","sourcesContent":["import { concatHex, numberToHex, zeroHash } from \"viem\";\nimport { AccountNotFoundError } from \"../../errors/account.js\";\nimport type { UserOperationStruct } from \"../../types.js\";\nimport type { ClientMiddlewareFn } from \"../types\";\nimport { defaultGasEstimator } from \"./gasEstimator.js\";\n\n/**\n * A middleware function to estimate the gas usage of a user operation when using an EIP-7702 delegated account. Has an optional custom gas estimator.\n * This function is only compatible with accounts using EntryPoint v0.7.0, and the account must have an implementation address defined in `getImplementationAddress()`.\n *\n * @example\n * ```ts twoslash\n * import {\n * default7702GasEstimator,\n * default7702UserOpSigner,\n * createSmartAccountClient,\n * type SmartAccountClient,\n * } from \"@aa-sdk/core\";\n * import {\n * createModularAccountV2,\n * type CreateModularAccountV2ClientParams,\n * } from \"@account-kit/smart-contracts\";\n *\n * async function createSMA7702AccountClient(\n * config: CreateModularAccountV2ClientParams\n * ): Promise<SmartAccountClient> {\n * const sma7702Account = await createModularAccountV2({ ...config, mode: \"7702\" });\n *\n * return createSmartAccountClient({\n * account: sma7702Account,\n * gasEstimator: default7702GasEstimator(config.gasEstimator),\n * signUserOperation: default7702UserOpSigner(config.signUserOperation),\n * ...config,\n * });\n * }\n * ```\n *\n * @param {ClientMiddlewareFn} gasEstimator Optional custom gas estimator function\n * @returns {ClientMiddlewareFn} A function that takes user operation struct and parameters, estimates gas usage, and returns the user operation with gas limits.\n */\nexport const default7702GasEstimator: (\n gasEstimator?: ClientMiddlewareFn,\n) => ClientMiddlewareFn =\n (gasEstimator?: ClientMiddlewareFn) => async (struct, params) => {\n const gasEstimator_ = gasEstimator ?? defaultGasEstimator(params.client);\n\n const account = params.account ?? params.client.account;\n if (!account) {\n throw new AccountNotFoundError();\n }\n\n const entryPoint = account.getEntryPoint();\n if (entryPoint.version !== \"0.7.0\") {\n throw new Error(\n \"This middleware is only compatible with EntryPoint v0.7.0\",\n );\n }\n\n const [implementationAddress, code = \"0x\"] = await Promise.all([\n account.getImplementationAddress(),\n params.client.getCode({ address: params.account.address }),\n ]);\n\n const isAlreadyDelegated =\n code.toLowerCase() === concatHex([\"0xef0100\", implementationAddress]);\n\n if (!isAlreadyDelegated) {\n (struct as UserOperationStruct<\"0.7.0\">).eip7702Auth = {\n chainId: numberToHex(params.client.chain?.id ?? 0),\n nonce: numberToHex(\n await params.client.getTransactionCount({\n address: params.account.address,\n }),\n ),\n address: implementationAddress,\n r: zeroHash, // aka `bytes32(0)`\n s: zeroHash,\n yParity: \"0x0\",\n };\n }\n\n return gasEstimator_(struct, params);\n };\n"]}
@@ -1 +1 @@
1
- export declare const VERSION = "4.50.1";
1
+ export declare const VERSION = "4.51.0";
@@ -1,4 +1,4 @@
1
1
  // This file is autogenerated by inject-version.ts. Any changes will be
2
2
  // overwritten on commit!
3
- export const VERSION = "4.50.1";
3
+ export const VERSION = "4.51.0";
4
4
  //# sourceMappingURL=version.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"version.js","sourceRoot":"","sources":["../../src/version.ts"],"names":[],"mappings":"AAAA,uEAAuE;AACvE,yBAAyB;AACzB,MAAM,CAAC,MAAM,OAAO,GAAG,QAAQ,CAAC","sourcesContent":["// This file is autogenerated by inject-version.ts. Any changes will be\n// overwritten on commit!\nexport const VERSION = \"4.50.1\";\n"]}
1
+ {"version":3,"file":"version.js","sourceRoot":"","sources":["../../src/version.ts"],"names":[],"mappings":"AAAA,uEAAuE;AACvE,yBAAyB;AACzB,MAAM,CAAC,MAAM,OAAO,GAAG,QAAQ,CAAC","sourcesContent":["// This file is autogenerated by inject-version.ts. Any changes will be\n// overwritten on commit!\nexport const VERSION = \"4.51.0\";\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"7702gasEstimator.d.ts","sourceRoot":"","sources":["../../../../src/middleware/defaults/7702gasEstimator.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,UAAU,CAAC;AAGnD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiCG;AACH,eAAO,MAAM,uBAAuB,EAAE,CACpC,YAAY,CAAC,EAAE,kBAAkB,KAC9B,kBA8BF,CAAC"}
1
+ {"version":3,"file":"7702gasEstimator.d.ts","sourceRoot":"","sources":["../../../../src/middleware/defaults/7702gasEstimator.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,UAAU,CAAC;AAGnD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiCG;AACH,eAAO,MAAM,uBAAuB,EAAE,CACpC,YAAY,CAAC,EAAE,kBAAkB,KAC9B,kBAwCF,CAAC"}
@@ -1,2 +1,2 @@
1
- export declare const VERSION = "4.50.1";
1
+ export declare const VERSION = "4.51.0";
2
2
  //# sourceMappingURL=version.d.ts.map
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@aa-sdk/core",
3
3
  "license": "MIT",
4
- "version": "4.50.1",
4
+ "version": "4.51.0",
5
5
  "description": "viem based SDK that enables interactions with ERC-4337 Smart Accounts. ABIs are based off the definitions generated in @account-abstraction/contracts",
6
6
  "author": "Alchemy",
7
7
  "type": "module",
@@ -62,5 +62,5 @@
62
62
  "url": "https://github.com/alchemyplatform/aa-sdk/issues"
63
63
  },
64
64
  "homepage": "https://github.com/alchemyplatform/aa-sdk#readme",
65
- "gitHead": "6e5c194d5950f548724f2498da8efb79c3bc25c5"
65
+ "gitHead": "1373ff1caae94dd3fdc94bbd6871385c11cf4c47"
66
66
  }
@@ -1,4 +1,4 @@
1
- import { zeroHash } from "viem";
1
+ import { concatHex, numberToHex, zeroHash } from "viem";
2
2
  import { AccountNotFoundError } from "../../errors/account.js";
3
3
  import type { UserOperationStruct } from "../../types.js";
4
4
  import type { ClientMiddlewareFn } from "../types";
@@ -56,18 +56,28 @@ export const default7702GasEstimator: (
56
56
  );
57
57
  }
58
58
 
59
- const implementationAddress = await account.getImplementationAddress();
59
+ const [implementationAddress, code = "0x"] = await Promise.all([
60
+ account.getImplementationAddress(),
61
+ params.client.getCode({ address: params.account.address }),
62
+ ]);
60
63
 
61
- // Note: does not omit the delegation from estimation if the account is already 7702 delegated.
64
+ const isAlreadyDelegated =
65
+ code.toLowerCase() === concatHex(["0xef0100", implementationAddress]);
62
66
 
63
- (struct as UserOperationStruct<"0.7.0">).eip7702Auth = {
64
- chainId: "0x0",
65
- nonce: "0x0",
66
- address: implementationAddress,
67
- r: zeroHash, // aka `bytes32(0)`
68
- s: zeroHash,
69
- yParity: "0x0",
70
- };
67
+ if (!isAlreadyDelegated) {
68
+ (struct as UserOperationStruct<"0.7.0">).eip7702Auth = {
69
+ chainId: numberToHex(params.client.chain?.id ?? 0),
70
+ nonce: numberToHex(
71
+ await params.client.getTransactionCount({
72
+ address: params.account.address,
73
+ }),
74
+ ),
75
+ address: implementationAddress,
76
+ r: zeroHash, // aka `bytes32(0)`
77
+ s: zeroHash,
78
+ yParity: "0x0",
79
+ };
80
+ }
71
81
 
72
82
  return gasEstimator_(struct, params);
73
83
  };
package/src/version.ts CHANGED
@@ -1,3 +1,3 @@
1
1
  // This file is autogenerated by inject-version.ts. Any changes will be
2
2
  // overwritten on commit!
3
- export const VERSION = "4.50.1";
3
+ export const VERSION = "4.51.0";