@zerodev/sdk 4.6.10 → 4.6.11

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.
@@ -57,11 +57,10 @@ const withZeroDevGasEstimator = (provider) => {
57
57
  userOpGasEstimates = await provider.rpcClient.estimateUserOperationGas(request, constants_js_1.ENTRYPOINT_ADDRESS);
58
58
  const { preVerificationGas, verificationGasLimit, callGasLimit } = userOpGasEstimates;
59
59
  request.preVerificationGas =
60
- (BigInt(preVerificationGas) * 12n) / 10n ?? request.preVerificationGas;
60
+ BigInt(preVerificationGas) ?? request.preVerificationGas;
61
61
  request.verificationGasLimit =
62
62
  BigInt(verificationGasLimit) ?? request.verificationGasLimit;
63
- request.callGasLimit =
64
- (BigInt(callGasLimit) * 12n) / 10n ?? request.callGasLimit;
63
+ request.callGasLimit = BigInt(callGasLimit) ?? request.callGasLimit;
65
64
  return {
66
65
  ...struct,
67
66
  ...request,
@@ -1 +1 @@
1
- {"version":3,"file":"gas-estimator.js","sourceRoot":"","sources":["../../../../src/kernel-zerodev/middleware/gas-estimator.ts"],"names":[],"mappings":";;;AACA,8CAO0B;AAC1B,kDAAqD;AACrD,wFAA+E;AAGxE,MAAM,uBAAuB,GAAG,CACrC,QAAyB,EACR,EAAE;IACnB,QAAQ,CAAC,iBAAiB,CAAC,KAAK,EAAE,MAAM,EAAE,EAAE;QAC1C,IAAI,SAAS,GAAG,MAAM,IAAA,2BAAiB,EAAC;YACtC,YAAY,EAAE,MAAM,CAAC,YAAY;YACjC,oBAAoB,EAAE,MAAM,CAAC,oBAAoB;SAClD,CAAC,CAAC;QAEH,IAAI,QAAQ,CAAC,eAAe,KAAK,QAAQ,EAAE;YACzC,OAAO,EAAE,YAAY,EAAE,EAAE,EAAE,oBAAoB,EAAE,EAAE,EAAE,CAAC;SACvD;QAED,IAAI,YAAY,EAAE,oBAAoB,CAAC;QAEvC,IAAI;YACF,CAAC,EAAE,YAAY,EAAE,oBAAoB,EAAE,G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C;QACd,CAAC,CAAC;KACH,CAAC,CAAC;IAEH,IAAI,YAAY,GAAG,IAAI,CAAC;IACxB,IAAI,oBAAoB,GAAG,IAAI,CAAC;IAEhC,IAAI,KAAK,IAAI,KAAK,CAAC,aAAa,IAAI,IAAI,EAAE;QAExC,MAAM,UAAU,GAAG,MAAM,CAAC,YAAY,CAAC,CAAC;QACxC,oBAAoB,GAAG,QAAQ,CAAC,CAAC,CAAC,QAAQ,GAAG,KAAK,CAAC,aAAa,CAAC,CAAC,CAAC,IAAI,CAAC;QACxE,IACE,oBAAoB,IAAI,IAAI;YAC5B,oBAAoB,GAAG,MAAM,CAAC,CAAC,CAAC;YAChC,oBAAoB,GAAG,UAAU,EACjC;YACA,oBAAoB,GAAG,UAAU,CAAC;SACnC;QACD,oBAAoB;YAClB,oBAAoB,GAAG,QAAQ,CAAC,oBAAoB;gBAClD,CAAC,CAAC,QAAQ,CAAC,oBAAoB;gBAC/B,CAAC,CAAC,oBAAoB,CAAC;QAC3B,YAAY;YACV,KAAK,CAAC,aAAa,GAAG,MAAM,CAAC,CAAC,CAAC,GAAG,CAAC,oBAAoB,IAAI,CAAC,CAAC,CAAC;KACjE;IAED,OAAO,EAAE,YAAY,EAAE,oBAAoB,EAAE,CAAC;AAChD,CAAC,CAAC;AAlCW,QAAA,UAAU,cAkCrB","sourcesContent":["import type { ZeroDevProvider } from \"../provider.js\";\nimport {\n deepHexlify,\n type Hex,\n type UserOperationStruct,\n resolveProperties,\n type BigNumberish,\n type UserOperationEstimateGasResponse,\n} from \"@alchemy/aa-core\";\nimport { ENTRYPOINT_ADDRESS } from \"../constants.js\";\nimport { calcPreVerificationGas } from \"../utils/calc-pre-verification-gas.js\";\nimport { type PaymasterAndBundlerProviders } from \"../paymaster/types.js\";\n\nexport const withZeroDevGasEstimator = (\n provider: ZeroDevProvider\n): ZeroDevProvider => {\n provider.withFeeDataGetter(async (struct) => {\n let overrides = await resolveProperties({\n maxFeePerGas: struct.maxFeePerGas,\n maxPriorityFeePerGas: struct.maxPriorityFeePerGas,\n });\n\n if (provider.bundlerProvider === \"GELATO\") {\n return { maxFeePerGas: 0n, maxPriorityFeePerGas: 0n };\n }\n\n let maxFeePerGas, maxPriorityFeePerGas;\n\n try {\n ({ maxFeePerGas, maxPriorityFeePerGas } = await eip1559GasPrice(\n provider\n ));\n } catch (error: any) {\n console.warn(\n \"getGas: eth_maxPriorityFeePerGas failed, falling back to legacy gas price.\"\n );\n }\n\n if (maxFeePerGas === undefined || maxPriorityFeePerGas === undefined) {\n const feeData = await getFeeData(provider);\n maxFeePerGas = feeData?.maxFeePerGas ? BigInt(feeData?.maxFeePerGas) : 0n;\n maxPriorityFeePerGas = feeData.maxPriorityFeePerGas\n ? BigInt(feeData.maxPriorityFeePerGas)\n : 0n;\n }\n\n if (overrides.maxFeePerGas || overrides.maxPriorityFeePerGas) {\n return {\n maxFeePerGas: overrides.maxFeePerGas ?? maxFeePerGas,\n maxPriorityFeePerGas:\n overrides.maxPriorityFeePerGas ?? maxPriorityFeePerGas,\n };\n }\n return { maxFeePerGas, maxPriorityFeePerGas };\n });\n\n provider.withGasEstimator(async (struct) => {\n if (\n struct.callGasLimit !== undefined &&\n struct.verificationGasLimit !== undefined &&\n struct.preVerificationGas !== undefined\n ) {\n return struct;\n }\n const initCode = await provider.account?.getInitCode();\n const initGas = await estimateCreationGas(provider, initCode);\n const partialStruct: UserOperationStruct = {\n ...struct,\n callGasLimit:\n initCode !== undefined && initCode.length > 2\n ? BigInt(\"1000000\")\n : BigInt(55000),\n verificationGasLimit: BigInt(110000) + initGas,\n preVerificationGas: BigInt(100000),\n };\n\n partialStruct.preVerificationGas = await getPreVerificationGas(\n partialStruct\n );\n\n const request = deepHexlify(await resolveProperties(partialStruct));\n let userOpGasEstimates: UserOperationEstimateGasResponse | undefined;\n userOpGasEstimates = await provider.rpcClient.estimateUserOperationGas(\n request,\n ENTRYPOINT_ADDRESS\n );\n const { preVerificationGas, verificationGasLimit, callGasLimit } =\n userOpGasEstimates;\n request.preVerificationGas =\n (BigInt(preVerificationGas) * 12n) / 10n ?? request.preVerificationGas;\n request.verificationGasLimit =\n BigInt(verificationGasLimit) ?? request.verificationGasLimit;\n request.callGasLimit =\n (BigInt(callGasLimit) * 12n) / 10n ?? request.callGasLimit;\n\n return {\n ...struct,\n ...request,\n };\n });\n\n return provider;\n};\n\nexport const estimateCreationGas = async (\n provider: ZeroDevProvider,\n initCode?: string\n): Promise<bigint> => {\n if (initCode == null || initCode === \"0x\") return BigInt(0);\n const deployerAddress = initCode.substring(0, 42) as Hex;\n const deployerCallData = (\"0x\" + initCode.substring(42)) as Hex;\n return await provider.rpcClient.estimateGas({\n account: ENTRYPOINT_ADDRESS,\n to: deployerAddress,\n data: deployerCallData,\n });\n};\n\n/**\n * should cover cost of putting calldata on-chain, and some overhead.\n * actual overhead depends on the expected bundle size\n */\nexport const getPreVerificationGas = async (\n userOp: Partial<UserOperationStruct>\n): Promise<number> => {\n const p = await resolveProperties(userOp);\n return calcPreVerificationGas(p);\n};\n\nexport const GAS_PRICE_RPC_METHODS_BY_BUNDLER: {\n [K in PaymasterAndBundlerProviders]: string;\n} = {\n STACKUP: \"eth_maxPriorityFeePerGas\",\n ALCHEMY: \"rundler_maxPriorityFeePerGas\",\n PIMLICO: \"pimlico_getUserOperationGasPrice\",\n GELATO: \"eth_maxPriorityFeePerGas\",\n};\n\nexport const eip1559GasPrice = async (provider: ZeroDevProvider) => {\n let [fee, block] = await Promise.all([\n provider.rpcClient.request({\n method:\n // @ts-expect-error\n GAS_PRICE_RPC_METHODS_BY_BUNDLER[provider.bundlerProvider] ??\n \"eth_maxPriorityFeePerGas\",\n params: [],\n }) as any,\n provider.rpcClient.getBlock({ blockTag: \"latest\" }),\n ]);\n\n if (provider.bundlerProvider === \"PIMLICO\") {\n fee = fee.standard.maxPriorityFeePerGas;\n }\n\n const tip = BigInt(fee);\n const buffer =\n (tip / 100n) *\n BigInt(provider.feeOptions.maxPriorityFeePerGasBufferPercentage);\n let maxPriorityFeePerGas = tip + buffer;\n maxPriorityFeePerGas =\n maxPriorityFeePerGas < provider.minPriorityFeePerBid\n ? provider.minPriorityFeePerBid\n : maxPriorityFeePerGas;\n const maxFeePerGas =\n ((block.baseFeePerGas\n ? BigInt(block.baseFeePerGas) * 2n + maxPriorityFeePerGas\n : maxPriorityFeePerGas) *\n (BigInt(100) +\n BigInt(provider.feeOptions.maxFeePerGasBufferPercentage))) /\n 100n;\n\n return { maxFeePerGas, maxPriorityFeePerGas };\n};\ninterface FeeData {\n maxFeePerGas: BigNumberish | null;\n maxPriorityFeePerGas: BigNumberish | null;\n}\n\nexport const getFeeData = async (\n provider: ZeroDevProvider\n): Promise<FeeData> => {\n const { block, gasPrice } = await resolveProperties({\n block: provider.rpcClient.getBlock({ blockTag: \"latest\" }),\n gasPrice: provider.rpcClient.getGasPrice().catch((error) => {\n console.warn(\"Legacy: Failed to get gas price\", error);\n return null;\n }),\n });\n\n let maxFeePerGas = null;\n let maxPriorityFeePerGas = null;\n\n if (block && block.baseFeePerGas != null) {\n // Set the tip to the min of the tip for the last block and 1.5 gwei\n const minimumTip = BigInt(\"1500000000\");\n maxPriorityFeePerGas = gasPrice ? gasPrice - block.baseFeePerGas : null;\n if (\n maxPriorityFeePerGas == null ||\n maxPriorityFeePerGas - BigInt(0) ||\n maxPriorityFeePerGas > minimumTip\n ) {\n maxPriorityFeePerGas = minimumTip;\n }\n maxPriorityFeePerGas =\n maxPriorityFeePerGas < provider.minPriorityFeePerBid\n ? provider.minPriorityFeePerBid\n : maxPriorityFeePerGas;\n maxFeePerGas =\n block.baseFeePerGas * BigInt(2) + (maxPriorityFeePerGas ?? 0);\n }\n\n return { maxFeePerGas, maxPriorityFeePerGas };\n};\n"]}
1
+ {"version":3,"file":"gas-estimator.js","sourceRoot":"","sources":["../../../../src/kernel-zerodev/middleware/gas-estimator.ts"],"names":[],"mappings":";;;AACA,8CAO0B;AAC1B,kDAAqD;AACrD,wFAA+E;AAGxE,MAAM,uBAAuB,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ZeroDevProvider } from \"../provider.js\";\nimport {\n deepHexlify,\n type Hex,\n type UserOperationStruct,\n resolveProperties,\n type BigNumberish,\n type UserOperationEstimateGasResponse,\n} from \"@alchemy/aa-core\";\nimport { ENTRYPOINT_ADDRESS } from \"../constants.js\";\nimport { calcPreVerificationGas } from \"../utils/calc-pre-verification-gas.js\";\nimport { type PaymasterAndBundlerProviders } from \"../paymaster/types.js\";\n\nexport const withZeroDevGasEstimator = (\n provider: ZeroDevProvider\n): ZeroDevProvider => {\n provider.withFeeDataGetter(async (struct) => {\n let overrides = await resolveProperties({\n maxFeePerGas: struct.maxFeePerGas,\n maxPriorityFeePerGas: struct.maxPriorityFeePerGas,\n });\n\n if (provider.bundlerProvider === \"GELATO\") {\n return { maxFeePerGas: 0n, maxPriorityFeePerGas: 0n };\n }\n\n let maxFeePerGas, maxPriorityFeePerGas;\n\n try {\n ({ maxFeePerGas, maxPriorityFeePerGas } = await eip1559GasPrice(\n provider\n ));\n } catch (error: any) {\n console.warn(\n \"getGas: eth_maxPriorityFeePerGas failed, falling back to legacy gas price.\"\n );\n }\n\n if (maxFeePerGas === undefined || maxPriorityFeePerGas === undefined) {\n const feeData = await getFeeData(provider);\n maxFeePerGas = feeData?.maxFeePerGas ? BigInt(feeData?.maxFeePerGas) : 0n;\n maxPriorityFeePerGas = feeData.maxPriorityFeePerGas\n ? BigInt(feeData.maxPriorityFeePerGas)\n : 0n;\n }\n\n if (overrides.maxFeePerGas || overrides.maxPriorityFeePerGas) {\n return {\n maxFeePerGas: overrides.maxFeePerGas ?? maxFeePerGas,\n maxPriorityFeePerGas:\n overrides.maxPriorityFeePerGas ?? maxPriorityFeePerGas,\n };\n }\n return { maxFeePerGas, maxPriorityFeePerGas };\n });\n\n provider.withGasEstimator(async (struct) => {\n if (\n struct.callGasLimit !== undefined &&\n struct.verificationGasLimit !== undefined &&\n struct.preVerificationGas !== undefined\n ) {\n return struct;\n }\n const initCode = await provider.account?.getInitCode();\n const initGas = await estimateCreationGas(provider, initCode);\n const partialStruct: UserOperationStruct = {\n ...struct,\n callGasLimit:\n initCode !== undefined && initCode.length > 2\n ? BigInt(\"1000000\")\n : BigInt(55000),\n verificationGasLimit: BigInt(110000) + initGas,\n preVerificationGas: BigInt(100000),\n };\n\n partialStruct.preVerificationGas = await getPreVerificationGas(\n partialStruct\n );\n\n const request = deepHexlify(await resolveProperties(partialStruct));\n let userOpGasEstimates: UserOperationEstimateGasResponse | undefined;\n userOpGasEstimates = await provider.rpcClient.estimateUserOperationGas(\n request,\n ENTRYPOINT_ADDRESS\n );\n const { preVerificationGas, verificationGasLimit, callGasLimit } =\n userOpGasEstimates;\n request.preVerificationGas =\n BigInt(preVerificationGas) ?? request.preVerificationGas;\n request.verificationGasLimit =\n BigInt(verificationGasLimit) ?? request.verificationGasLimit;\n request.callGasLimit = BigInt(callGasLimit) ?? request.callGasLimit;\n\n return {\n ...struct,\n ...request,\n };\n });\n\n return provider;\n};\n\nexport const estimateCreationGas = async (\n provider: ZeroDevProvider,\n initCode?: string\n): Promise<bigint> => {\n if (initCode == null || initCode === \"0x\") return BigInt(0);\n const deployerAddress = initCode.substring(0, 42) as Hex;\n const deployerCallData = (\"0x\" + initCode.substring(42)) as Hex;\n return await provider.rpcClient.estimateGas({\n account: ENTRYPOINT_ADDRESS,\n to: deployerAddress,\n data: deployerCallData,\n });\n};\n\n/**\n * should cover cost of putting calldata on-chain, and some overhead.\n * actual overhead depends on the expected bundle size\n */\nexport const getPreVerificationGas = async (\n userOp: Partial<UserOperationStruct>\n): Promise<number> => {\n const p = await resolveProperties(userOp);\n return calcPreVerificationGas(p);\n};\n\nexport const GAS_PRICE_RPC_METHODS_BY_BUNDLER: {\n [K in PaymasterAndBundlerProviders]: string;\n} = {\n STACKUP: \"eth_maxPriorityFeePerGas\",\n ALCHEMY: \"rundler_maxPriorityFeePerGas\",\n PIMLICO: \"pimlico_getUserOperationGasPrice\",\n GELATO: \"eth_maxPriorityFeePerGas\",\n};\n\nexport const eip1559GasPrice = async (provider: ZeroDevProvider) => {\n let [fee, block] = await Promise.all([\n provider.rpcClient.request({\n method:\n // @ts-expect-error\n GAS_PRICE_RPC_METHODS_BY_BUNDLER[provider.bundlerProvider] ??\n \"eth_maxPriorityFeePerGas\",\n params: [],\n }) as any,\n provider.rpcClient.getBlock({ blockTag: \"latest\" }),\n ]);\n\n if (provider.bundlerProvider === \"PIMLICO\") {\n fee = fee.standard.maxPriorityFeePerGas;\n }\n\n const tip = BigInt(fee);\n const buffer =\n (tip / 100n) *\n BigInt(provider.feeOptions.maxPriorityFeePerGasBufferPercentage);\n let maxPriorityFeePerGas = tip + buffer;\n maxPriorityFeePerGas =\n maxPriorityFeePerGas < provider.minPriorityFeePerBid\n ? provider.minPriorityFeePerBid\n : maxPriorityFeePerGas;\n const maxFeePerGas =\n ((block.baseFeePerGas\n ? BigInt(block.baseFeePerGas) * 2n + maxPriorityFeePerGas\n : maxPriorityFeePerGas) *\n (BigInt(100) +\n BigInt(provider.feeOptions.maxFeePerGasBufferPercentage))) /\n 100n;\n\n return { maxFeePerGas, maxPriorityFeePerGas };\n};\ninterface FeeData {\n maxFeePerGas: BigNumberish | null;\n maxPriorityFeePerGas: BigNumberish | null;\n}\n\nexport const getFeeData = async (\n provider: ZeroDevProvider\n): Promise<FeeData> => {\n const { block, gasPrice } = await resolveProperties({\n block: provider.rpcClient.getBlock({ blockTag: \"latest\" }),\n gasPrice: provider.rpcClient.getGasPrice().catch((error) => {\n console.warn(\"Legacy: Failed to get gas price\", error);\n return null;\n }),\n });\n\n let maxFeePerGas = null;\n let maxPriorityFeePerGas = null;\n\n if (block && block.baseFeePerGas != null) {\n // Set the tip to the min of the tip for the last block and 1.5 gwei\n const minimumTip = BigInt(\"1500000000\");\n maxPriorityFeePerGas = gasPrice ? gasPrice - block.baseFeePerGas : null;\n if (\n maxPriorityFeePerGas == null ||\n maxPriorityFeePerGas - BigInt(0) ||\n maxPriorityFeePerGas > minimumTip\n ) {\n maxPriorityFeePerGas = minimumTip;\n }\n maxPriorityFeePerGas =\n maxPriorityFeePerGas < provider.minPriorityFeePerBid\n ? provider.minPriorityFeePerBid\n : maxPriorityFeePerGas;\n maxFeePerGas =\n block.baseFeePerGas * BigInt(2) + (maxPriorityFeePerGas ?? 0);\n }\n\n return { maxFeePerGas, maxPriorityFeePerGas };\n};\n"]}
@@ -55,11 +55,10 @@ export const withZeroDevGasEstimator = (provider) => {
55
55
  userOpGasEstimates = await provider.rpcClient.estimateUserOperationGas(request, ENTRYPOINT_ADDRESS);
56
56
  const { preVerificationGas, verificationGasLimit, callGasLimit } = userOpGasEstimates;
57
57
  request.preVerificationGas =
58
- (BigInt(preVerificationGas) * 12n) / 10n ?? request.preVerificationGas;
58
+ BigInt(preVerificationGas) ?? request.preVerificationGas;
59
59
  request.verificationGasLimit =
60
60
  BigInt(verificationGasLimit) ?? request.verificationGasLimit;
61
- request.callGasLimit =
62
- (BigInt(callGasLimit) * 12n) / 10n ?? request.callGasLimit;
61
+ request.callGasLimit = BigInt(callGasLimit) ?? request.callGasLimit;
63
62
  return {
64
63
  ...struct,
65
64
  ...request,
@@ -1 +1 @@
1
- {"version":3,"file":"gas-estimator.js","sourceRoot":"","sources":["../../../../src/kernel-zerodev/middleware/gas-estimator.ts"],"names":[],"mappings":"AACA,OAAO,EACL,WAAW,EAGX,iBAAiB,GAGlB,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EAAE,kBAAkB,EAAE,MAAM,iBAAiB,CAAC;AACrD,OAAO,EAAE,sBAAsB,EAAE,MAAM,uCAAuC,CAAC;AAC/E,OAAO,EAAqC,MAAM,uBAAuB,CAAC;AAE1E,MAAM,CAAC,MAAM,uBAAuB,GAAG,CACrC,QAAyB,EACR,EAAE;IACnB,QAAQ,CAAC,iBAAiB,CAAC,KAAK,EAAE,MAAM,EAAE,EAAE;QAC1C,IAAI,SAAS,GAAG,MAAM,iBAAiB,CAAC;YACtC,YAAY,EAAE,MAAM,CAAC,YAAY;YACjC,oBAAoB,EAAE,MA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AS,CAAC,WAAW,EAAE,CAAC,KAAK,CAAC,CAAC,KAAK,EAAE,EAAE;YACzD,OAAO,CAAC,IAAI,CAAC,iCAAiC,EAAE,KAAK,CAAC,CAAC;YACvD,OAAO,IAAI,CAAC;QACd,CAAC,CAAC;KACH,CAAC,CAAC;IAEH,IAAI,YAAY,GAAG,IAAI,CAAC;IACxB,IAAI,oBAAoB,GAAG,IAAI,CAAC;IAEhC,IAAI,KAAK,IAAI,KAAK,CAAC,aAAa,IAAI,IAAI,EAAE;QAExC,MAAM,UAAU,GAAG,MAAM,CAAC,YAAY,CAAC,CAAC;QACxC,oBAAoB,GAAG,QAAQ,CAAC,CAAC,CAAC,QAAQ,GAAG,KAAK,CAAC,aAAa,CAAC,CAAC,CAAC,IAAI,CAAC;QACxE,IACE,oBAAoB,IAAI,IAAI;YAC5B,oBAAoB,GAAG,MAAM,CAAC,CAAC,CAAC;YAChC,oBAAoB,GAAG,UAAU,EACjC;YACA,oBAAoB,GAAG,UAAU,CAAC;SACnC;QACD,oBAAoB;YAClB,oBAAoB,GAAG,QAAQ,CAAC,oBAAoB;gBAClD,CAAC,CAAC,QAAQ,CAAC,oBAAoB;gBAC/B,CAAC,CAAC,oBAAoB,CAAC;QAC3B,YAAY;YACV,KAAK,CAAC,aAAa,GAAG,MAAM,CAAC,CAAC,CAAC,GAAG,CAAC,oBAAoB,IAAI,CAAC,CAAC,CAAC;KACjE;IAED,OAAO,EAAE,YAAY,EAAE,oBAAoB,EAAE,CAAC;AAChD,CAAC,CAAC","sourcesContent":["import type { ZeroDevProvider } from \"../provider.js\";\nimport {\n deepHexlify,\n type Hex,\n type UserOperationStruct,\n resolveProperties,\n type BigNumberish,\n type UserOperationEstimateGasResponse,\n} from \"@alchemy/aa-core\";\nimport { ENTRYPOINT_ADDRESS } from \"../constants.js\";\nimport { calcPreVerificationGas } from \"../utils/calc-pre-verification-gas.js\";\nimport { type PaymasterAndBundlerProviders } from \"../paymaster/types.js\";\n\nexport const withZeroDevGasEstimator = (\n provider: ZeroDevProvider\n): ZeroDevProvider => {\n provider.withFeeDataGetter(async (struct) => {\n let overrides = await resolveProperties({\n maxFeePerGas: struct.maxFeePerGas,\n maxPriorityFeePerGas: struct.maxPriorityFeePerGas,\n });\n\n if (provider.bundlerProvider === \"GELATO\") {\n return { maxFeePerGas: 0n, maxPriorityFeePerGas: 0n };\n }\n\n let maxFeePerGas, maxPriorityFeePerGas;\n\n try {\n ({ maxFeePerGas, maxPriorityFeePerGas } = await eip1559GasPrice(\n provider\n ));\n } catch (error: any) {\n console.warn(\n \"getGas: eth_maxPriorityFeePerGas failed, falling back to legacy gas price.\"\n );\n }\n\n if (maxFeePerGas === undefined || maxPriorityFeePerGas === undefined) {\n const feeData = await getFeeData(provider);\n maxFeePerGas = feeData?.maxFeePerGas ? BigInt(feeData?.maxFeePerGas) : 0n;\n maxPriorityFeePerGas = feeData.maxPriorityFeePerGas\n ? BigInt(feeData.maxPriorityFeePerGas)\n : 0n;\n }\n\n if (overrides.maxFeePerGas || overrides.maxPriorityFeePerGas) {\n return {\n maxFeePerGas: overrides.maxFeePerGas ?? maxFeePerGas,\n maxPriorityFeePerGas:\n overrides.maxPriorityFeePerGas ?? maxPriorityFeePerGas,\n };\n }\n return { maxFeePerGas, maxPriorityFeePerGas };\n });\n\n provider.withGasEstimator(async (struct) => {\n if (\n struct.callGasLimit !== undefined &&\n struct.verificationGasLimit !== undefined &&\n struct.preVerificationGas !== undefined\n ) {\n return struct;\n }\n const initCode = await provider.account?.getInitCode();\n const initGas = await estimateCreationGas(provider, initCode);\n const partialStruct: UserOperationStruct = {\n ...struct,\n callGasLimit:\n initCode !== undefined && initCode.length > 2\n ? BigInt(\"1000000\")\n : BigInt(55000),\n verificationGasLimit: BigInt(110000) + initGas,\n preVerificationGas: BigInt(100000),\n };\n\n partialStruct.preVerificationGas = await getPreVerificationGas(\n partialStruct\n );\n\n const request = deepHexlify(await resolveProperties(partialStruct));\n let userOpGasEstimates: UserOperationEstimateGasResponse | undefined;\n userOpGasEstimates = await provider.rpcClient.estimateUserOperationGas(\n request,\n ENTRYPOINT_ADDRESS\n );\n const { preVerificationGas, verificationGasLimit, callGasLimit } =\n userOpGasEstimates;\n request.preVerificationGas =\n (BigInt(preVerificationGas) * 12n) / 10n ?? request.preVerificationGas;\n request.verificationGasLimit =\n BigInt(verificationGasLimit) ?? request.verificationGasLimit;\n request.callGasLimit =\n (BigInt(callGasLimit) * 12n) / 10n ?? request.callGasLimit;\n\n return {\n ...struct,\n ...request,\n };\n });\n\n return provider;\n};\n\nexport const estimateCreationGas = async (\n provider: ZeroDevProvider,\n initCode?: string\n): Promise<bigint> => {\n if (initCode == null || initCode === \"0x\") return BigInt(0);\n const deployerAddress = initCode.substring(0, 42) as Hex;\n const deployerCallData = (\"0x\" + initCode.substring(42)) as Hex;\n return await provider.rpcClient.estimateGas({\n account: ENTRYPOINT_ADDRESS,\n to: deployerAddress,\n data: deployerCallData,\n });\n};\n\n/**\n * should cover cost of putting calldata on-chain, and some overhead.\n * actual overhead depends on the expected bundle size\n */\nexport const getPreVerificationGas = async (\n userOp: Partial<UserOperationStruct>\n): Promise<number> => {\n const p = await resolveProperties(userOp);\n return calcPreVerificationGas(p);\n};\n\nexport const GAS_PRICE_RPC_METHODS_BY_BUNDLER: {\n [K in PaymasterAndBundlerProviders]: string;\n} = {\n STACKUP: \"eth_maxPriorityFeePerGas\",\n ALCHEMY: \"rundler_maxPriorityFeePerGas\",\n PIMLICO: \"pimlico_getUserOperationGasPrice\",\n GELATO: \"eth_maxPriorityFeePerGas\",\n};\n\nexport const eip1559GasPrice = async (provider: ZeroDevProvider) => {\n let [fee, block] = await Promise.all([\n provider.rpcClient.request({\n method:\n // @ts-expect-error\n GAS_PRICE_RPC_METHODS_BY_BUNDLER[provider.bundlerProvider] ??\n \"eth_maxPriorityFeePerGas\",\n params: [],\n }) as any,\n provider.rpcClient.getBlock({ blockTag: \"latest\" }),\n ]);\n\n if (provider.bundlerProvider === \"PIMLICO\") {\n fee = fee.standard.maxPriorityFeePerGas;\n }\n\n const tip = BigInt(fee);\n const buffer =\n (tip / 100n) *\n BigInt(provider.feeOptions.maxPriorityFeePerGasBufferPercentage);\n let maxPriorityFeePerGas = tip + buffer;\n maxPriorityFeePerGas =\n maxPriorityFeePerGas < provider.minPriorityFeePerBid\n ? provider.minPriorityFeePerBid\n : maxPriorityFeePerGas;\n const maxFeePerGas =\n ((block.baseFeePerGas\n ? BigInt(block.baseFeePerGas) * 2n + maxPriorityFeePerGas\n : maxPriorityFeePerGas) *\n (BigInt(100) +\n BigInt(provider.feeOptions.maxFeePerGasBufferPercentage))) /\n 100n;\n\n return { maxFeePerGas, maxPriorityFeePerGas };\n};\ninterface FeeData {\n maxFeePerGas: BigNumberish | null;\n maxPriorityFeePerGas: BigNumberish | null;\n}\n\nexport const getFeeData = async (\n provider: ZeroDevProvider\n): Promise<FeeData> => {\n const { block, gasPrice } = await resolveProperties({\n block: provider.rpcClient.getBlock({ blockTag: \"latest\" }),\n gasPrice: provider.rpcClient.getGasPrice().catch((error) => {\n console.warn(\"Legacy: Failed to get gas price\", error);\n return null;\n }),\n });\n\n let maxFeePerGas = null;\n let maxPriorityFeePerGas = null;\n\n if (block && block.baseFeePerGas != null) {\n // Set the tip to the min of the tip for the last block and 1.5 gwei\n const minimumTip = BigInt(\"1500000000\");\n maxPriorityFeePerGas = gasPrice ? gasPrice - block.baseFeePerGas : null;\n if (\n maxPriorityFeePerGas == null ||\n maxPriorityFeePerGas - BigInt(0) ||\n maxPriorityFeePerGas > minimumTip\n ) {\n maxPriorityFeePerGas = minimumTip;\n }\n maxPriorityFeePerGas =\n maxPriorityFeePerGas < provider.minPriorityFeePerBid\n ? provider.minPriorityFeePerBid\n : maxPriorityFeePerGas;\n maxFeePerGas =\n block.baseFeePerGas * BigInt(2) + (maxPriorityFeePerGas ?? 0);\n }\n\n return { maxFeePerGas, maxPriorityFeePerGas };\n};\n"]}
1
+ {"version":3,"file":"gas-estimator.js","sourceRoot":"","s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,CAAC,CAAC,CAAC,GAAG,CAAC,oBAAoB,IAAI,CAAC,CAAC,CAAC;KACjE;IAED,OAAO,EAAE,YAAY,EAAE,oBAAoB,EAAE,CAAC;AAChD,CAAC,CAAC","sourcesContent":["import type { ZeroDevProvider } from \"../provider.js\";\nimport {\n deepHexlify,\n type Hex,\n type UserOperationStruct,\n resolveProperties,\n type BigNumberish,\n type UserOperationEstimateGasResponse,\n} from \"@alchemy/aa-core\";\nimport { ENTRYPOINT_ADDRESS } from \"../constants.js\";\nimport { calcPreVerificationGas } from \"../utils/calc-pre-verification-gas.js\";\nimport { type PaymasterAndBundlerProviders } from \"../paymaster/types.js\";\n\nexport const withZeroDevGasEstimator = (\n provider: ZeroDevProvider\n): ZeroDevProvider => {\n provider.withFeeDataGetter(async (struct) => {\n let overrides = await resolveProperties({\n maxFeePerGas: struct.maxFeePerGas,\n maxPriorityFeePerGas: struct.maxPriorityFeePerGas,\n });\n\n if (provider.bundlerProvider === \"GELATO\") {\n return { maxFeePerGas: 0n, maxPriorityFeePerGas: 0n };\n }\n\n let maxFeePerGas, maxPriorityFeePerGas;\n\n try {\n ({ maxFeePerGas, maxPriorityFeePerGas } = await eip1559GasPrice(\n provider\n ));\n } catch (error: any) {\n console.warn(\n \"getGas: eth_maxPriorityFeePerGas failed, falling back to legacy gas price.\"\n );\n }\n\n if (maxFeePerGas === undefined || maxPriorityFeePerGas === undefined) {\n const feeData = await getFeeData(provider);\n maxFeePerGas = feeData?.maxFeePerGas ? BigInt(feeData?.maxFeePerGas) : 0n;\n maxPriorityFeePerGas = feeData.maxPriorityFeePerGas\n ? BigInt(feeData.maxPriorityFeePerGas)\n : 0n;\n }\n\n if (overrides.maxFeePerGas || overrides.maxPriorityFeePerGas) {\n return {\n maxFeePerGas: overrides.maxFeePerGas ?? maxFeePerGas,\n maxPriorityFeePerGas:\n overrides.maxPriorityFeePerGas ?? maxPriorityFeePerGas,\n };\n }\n return { maxFeePerGas, maxPriorityFeePerGas };\n });\n\n provider.withGasEstimator(async (struct) => {\n if (\n struct.callGasLimit !== undefined &&\n struct.verificationGasLimit !== undefined &&\n struct.preVerificationGas !== undefined\n ) {\n return struct;\n }\n const initCode = await provider.account?.getInitCode();\n const initGas = await estimateCreationGas(provider, initCode);\n const partialStruct: UserOperationStruct = {\n ...struct,\n callGasLimit:\n initCode !== undefined && initCode.length > 2\n ? BigInt(\"1000000\")\n : BigInt(55000),\n verificationGasLimit: BigInt(110000) + initGas,\n preVerificationGas: BigInt(100000),\n };\n\n partialStruct.preVerificationGas = await getPreVerificationGas(\n partialStruct\n );\n\n const request = deepHexlify(await resolveProperties(partialStruct));\n let userOpGasEstimates: UserOperationEstimateGasResponse | undefined;\n userOpGasEstimates = await provider.rpcClient.estimateUserOperationGas(\n request,\n ENTRYPOINT_ADDRESS\n );\n const { preVerificationGas, verificationGasLimit, callGasLimit } =\n userOpGasEstimates;\n request.preVerificationGas =\n BigInt(preVerificationGas) ?? request.preVerificationGas;\n request.verificationGasLimit =\n BigInt(verificationGasLimit) ?? request.verificationGasLimit;\n request.callGasLimit = BigInt(callGasLimit) ?? request.callGasLimit;\n\n return {\n ...struct,\n ...request,\n };\n });\n\n return provider;\n};\n\nexport const estimateCreationGas = async (\n provider: ZeroDevProvider,\n initCode?: string\n): Promise<bigint> => {\n if (initCode == null || initCode === \"0x\") return BigInt(0);\n const deployerAddress = initCode.substring(0, 42) as Hex;\n const deployerCallData = (\"0x\" + initCode.substring(42)) as Hex;\n return await provider.rpcClient.estimateGas({\n account: ENTRYPOINT_ADDRESS,\n to: deployerAddress,\n data: deployerCallData,\n });\n};\n\n/**\n * should cover cost of putting calldata on-chain, and some overhead.\n * actual overhead depends on the expected bundle size\n */\nexport const getPreVerificationGas = async (\n userOp: Partial<UserOperationStruct>\n): Promise<number> => {\n const p = await resolveProperties(userOp);\n return calcPreVerificationGas(p);\n};\n\nexport const GAS_PRICE_RPC_METHODS_BY_BUNDLER: {\n [K in PaymasterAndBundlerProviders]: string;\n} = {\n STACKUP: \"eth_maxPriorityFeePerGas\",\n ALCHEMY: \"rundler_maxPriorityFeePerGas\",\n PIMLICO: \"pimlico_getUserOperationGasPrice\",\n GELATO: \"eth_maxPriorityFeePerGas\",\n};\n\nexport const eip1559GasPrice = async (provider: ZeroDevProvider) => {\n let [fee, block] = await Promise.all([\n provider.rpcClient.request({\n method:\n // @ts-expect-error\n GAS_PRICE_RPC_METHODS_BY_BUNDLER[provider.bundlerProvider] ??\n \"eth_maxPriorityFeePerGas\",\n params: [],\n }) as any,\n provider.rpcClient.getBlock({ blockTag: \"latest\" }),\n ]);\n\n if (provider.bundlerProvider === \"PIMLICO\") {\n fee = fee.standard.maxPriorityFeePerGas;\n }\n\n const tip = BigInt(fee);\n const buffer =\n (tip / 100n) *\n BigInt(provider.feeOptions.maxPriorityFeePerGasBufferPercentage);\n let maxPriorityFeePerGas = tip + buffer;\n maxPriorityFeePerGas =\n maxPriorityFeePerGas < provider.minPriorityFeePerBid\n ? provider.minPriorityFeePerBid\n : maxPriorityFeePerGas;\n const maxFeePerGas =\n ((block.baseFeePerGas\n ? BigInt(block.baseFeePerGas) * 2n + maxPriorityFeePerGas\n : maxPriorityFeePerGas) *\n (BigInt(100) +\n BigInt(provider.feeOptions.maxFeePerGasBufferPercentage))) /\n 100n;\n\n return { maxFeePerGas, maxPriorityFeePerGas };\n};\ninterface FeeData {\n maxFeePerGas: BigNumberish | null;\n maxPriorityFeePerGas: BigNumberish | null;\n}\n\nexport const getFeeData = async (\n provider: ZeroDevProvider\n): Promise<FeeData> => {\n const { block, gasPrice } = await resolveProperties({\n block: provider.rpcClient.getBlock({ blockTag: \"latest\" }),\n gasPrice: provider.rpcClient.getGasPrice().catch((error) => {\n console.warn(\"Legacy: Failed to get gas price\", error);\n return null;\n }),\n });\n\n let maxFeePerGas = null;\n let maxPriorityFeePerGas = null;\n\n if (block && block.baseFeePerGas != null) {\n // Set the tip to the min of the tip for the last block and 1.5 gwei\n const minimumTip = BigInt(\"1500000000\");\n maxPriorityFeePerGas = gasPrice ? gasPrice - block.baseFeePerGas : null;\n if (\n maxPriorityFeePerGas == null ||\n maxPriorityFeePerGas - BigInt(0) ||\n maxPriorityFeePerGas > minimumTip\n ) {\n maxPriorityFeePerGas = minimumTip;\n }\n maxPriorityFeePerGas =\n maxPriorityFeePerGas < provider.minPriorityFeePerBid\n ? provider.minPriorityFeePerBid\n : maxPriorityFeePerGas;\n maxFeePerGas =\n block.baseFeePerGas * BigInt(2) + (maxPriorityFeePerGas ?? 0);\n }\n\n return { maxFeePerGas, maxPriorityFeePerGas };\n};\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"gas-estimator.d.ts","sourceRoot":"","sources":["../../../../src/kernel-zerodev/middleware/gas-estimator.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAC;AACtD,OAAO,EAGL,KAAK,mBAAmB,EAExB,KAAK,YAAY,EAElB,MAAM,kBAAkB,CAAC;AAG1B,OAAO,EAAE,KAAK,4BAA4B,EAAE,MAAM,uBAAuB,CAAC;AAE1E,eAAO,MAAM,uBAAuB,aACxB,eAAe,KACxB,eAuFF,CAAC;AAEF,eAAO,MAAM,mBAAmB,aACpB,eAAe,aACd,MAAM,KAChB,QAAQ,MAAM,CAShB,CAAC;AAMF,eAAO,MAAM,qBAAqB,WACxB,QAAQ,mBAAmB,CAAC,KACnC,QAAQ,MAAM,CAGhB,CAAC;AAEF,eAAO,MAAM,gCAAgC,EAAE;KAC5C,CAAC,IAAI,4BAA4B,GAAG,MAAM;CAM5C,CAAC;AAEF,eAAO,MAAM,eAAe,aAAoB,eAAe;;;EAkC9D,CAAC;AACF,UAAU,OAAO;IACf,YAAY,EAAE,YAAY,GAAG,IAAI,CAAC;IAClC,oBAAoB,EAAE,YAAY,GAAG,IAAI,CAAC;CAC3C;AAED,eAAO,MAAM,UAAU,aACX,eAAe,KACxB,QAAQ,OAAO,CAgCjB,CAAC"}
1
+ {"version":3,"file":"gas-estimator.d.ts","sourceRoot":"","sources":["../../../../src/kernel-zerodev/middleware/gas-estimator.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAC;AACtD,OAAO,EAGL,KAAK,mBAAmB,EAExB,KAAK,YAAY,EAElB,MAAM,kBAAkB,CAAC;AAG1B,OAAO,EAAE,KAAK,4BAA4B,EAAE,MAAM,uBAAuB,CAAC;AAE1E,eAAO,MAAM,uBAAuB,aACxB,eAAe,KACxB,eAsFF,CAAC;AAEF,eAAO,MAAM,mBAAmB,aACpB,eAAe,aACd,MAAM,KAChB,QAAQ,MAAM,CAShB,CAAC;AAMF,eAAO,MAAM,qBAAqB,WACxB,QAAQ,mBAAmB,CAAC,KACnC,QAAQ,MAAM,CAGhB,CAAC;AAEF,eAAO,MAAM,gCAAgC,EAAE;KAC5C,CAAC,IAAI,4BAA4B,GAAG,MAAM;CAM5C,CAAC;AAEF,eAAO,MAAM,eAAe,aAAoB,eAAe;;;EAkC9D,CAAC;AACF,UAAU,OAAO;IACf,YAAY,EAAE,YAAY,GAAG,IAAI,CAAC;IAClC,oBAAoB,EAAE,YAAY,GAAG,IAAI,CAAC;CAC3C;AAED,eAAO,MAAM,UAAU,aACX,eAAe,KACxB,QAAQ,OAAO,CAgCjB,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zerodev/sdk",
3
- "version": "4.6.10",
3
+ "version": "4.6.11",
4
4
  "description": "A collection of ERC-4337 compliant smart contract account interfaces",
5
5
  "author": "ZeroDev",
6
6
  "license": "MIT",
@@ -87,11 +87,10 @@ export const withZeroDevGasEstimator = (
87
87
  const { preVerificationGas, verificationGasLimit, callGasLimit } =
88
88
  userOpGasEstimates;
89
89
  request.preVerificationGas =
90
- (BigInt(preVerificationGas) * 12n) / 10n ?? request.preVerificationGas;
90
+ BigInt(preVerificationGas) ?? request.preVerificationGas;
91
91
  request.verificationGasLimit =
92
92
  BigInt(verificationGasLimit) ?? request.verificationGasLimit;
93
- request.callGasLimit =
94
- (BigInt(callGasLimit) * 12n) / 10n ?? request.callGasLimit;
93
+ request.callGasLimit = BigInt(callGasLimit) ?? request.callGasLimit;
95
94
 
96
95
  return {
97
96
  ...struct,
@@ -287,10 +287,8 @@ export class RecoveryValidator extends KernelBaseValidator {
287
287
  const guardians: WeightedGuardians = {};
288
288
 
289
289
  let nextGuardian = firstGuardian;
290
- const sentinelValue = "0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF";
291
- while (
292
- nextGuardian.toLowerCase() !== sentinelValue.toLowerCase()
293
- ) {
290
+ const sentinelValue = "0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF";
291
+ while (nextGuardian.toLowerCase() !== sentinelValue.toLowerCase()) {
294
292
  const guardianStorage = await publicClient.readContract({
295
293
  abi: WeightedValidatorAbi,
296
294
  address: RECOVERY_VALIDATOR_ADDRESS,
@@ -434,7 +432,7 @@ export class RecoveryValidator extends KernelBaseValidator {
434
432
  if (this.isSignerSmartContract) {
435
433
  return this.signatures ?? DUMMY_ECDSA_SIG;
436
434
  }
437
-
435
+
438
436
  const hash = getUserOperationHash(
439
437
  {
440
438
  ...userOp,
@@ -264,7 +264,7 @@ export class RecoveryProvider extends ValidatorProvider<
264
264
  });
265
265
  return await walletClient.waitForTransactionReceipt({
266
266
  hash,
267
- timeout: 180000 // 3 minutes
267
+ timeout: 180000, // 3 minutes
268
268
  });
269
269
  }
270
270