@zerodev/sdk 4.5.2 → 4.5.4
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.
- package/dist/cjs/kernel-zerodev/middleware/gas-estimator.js +7 -3
- package/dist/cjs/kernel-zerodev/middleware/gas-estimator.js.map +1 -1
- package/dist/cjs/kernel-zerodev/provider.d.ts +6 -0
- package/dist/cjs/kernel-zerodev/provider.js +10 -0
- package/dist/cjs/kernel-zerodev/provider.js.map +1 -1
- package/dist/esm/kernel-zerodev/middleware/gas-estimator.js +7 -3
- package/dist/esm/kernel-zerodev/middleware/gas-estimator.js.map +1 -1
- package/dist/esm/kernel-zerodev/provider.d.ts +6 -0
- package/dist/esm/kernel-zerodev/provider.js +10 -0
- package/dist/esm/kernel-zerodev/provider.js.map +1 -1
- package/dist/types/kernel-zerodev/middleware/gas-estimator.d.ts.map +1 -1
- package/dist/types/kernel-zerodev/provider.d.ts +6 -0
- package/dist/types/kernel-zerodev/provider.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/kernel-zerodev/middleware/gas-estimator.ts +10 -4
- package/src/kernel-zerodev/provider.ts +12 -0
|
@@ -106,15 +106,19 @@ const eip1559GasPrice = async (provider) => {
|
|
|
106
106
|
fee = fee.standard.maxPriorityFeePerGas;
|
|
107
107
|
}
|
|
108
108
|
const tip = BigInt(fee);
|
|
109
|
-
const buffer = (tip / 100n) *
|
|
109
|
+
const buffer = (tip / 100n) *
|
|
110
|
+
BigInt(provider.feeOptions.maxPriorityFeePerGasBufferPercentage);
|
|
110
111
|
let maxPriorityFeePerGas = tip + buffer;
|
|
111
112
|
maxPriorityFeePerGas =
|
|
112
113
|
maxPriorityFeePerGas < provider.minPriorityFeePerBid
|
|
113
114
|
? provider.minPriorityFeePerBid
|
|
114
115
|
: maxPriorityFeePerGas;
|
|
115
|
-
const maxFeePerGas = block.baseFeePerGas
|
|
116
|
+
const maxFeePerGas = ((block.baseFeePerGas
|
|
116
117
|
? BigInt(block.baseFeePerGas) * 2n + maxPriorityFeePerGas
|
|
117
|
-
: maxPriorityFeePerGas
|
|
118
|
+
: maxPriorityFeePerGas) *
|
|
119
|
+
(BigInt(100) +
|
|
120
|
+
BigInt(provider.feeOptions.maxFeePerGasBufferPercentage))) /
|
|
121
|
+
100n;
|
|
118
122
|
return { maxFeePerGas, maxPriorityFeePerGas };
|
|
119
123
|
};
|
|
120
124
|
exports.eip1559GasPrice = eip1559GasPrice;
|
|
@@ -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,GAAG,MAAM,IAAA,uBAAe,EAC7D,QAAQ,CACT,CAAC,CAAC;SACJ;QAAC,OAAO,KAAU,EAAE;YACnB,OAAO,CAAC,IAAI,CACV,4EAA4E,CAC7E,CAAC;SACH;QAED,IAAI,YAAY,KAAK,SAAS,IAAI,oBAAoB,KAAK,SAAS,EAAE;YACpE,MAAM,OAAO,GAAG,MAAM,IAAA,kBAAU,EAAC,QAAQ,CAAC,CAAC;YAC3C,YAAY,GAAG,OA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C;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 = (tip / 100n) * 13n;\n let maxPriorityFeePerGas = tip + buffer;\n maxPriorityFeePerGas =\n maxPriorityFeePerGas < provider.minPriorityFeePerBid\n ? provider.minPriorityFeePerBid\n : maxPriorityFeePerGas;\n const maxFeePerGas = block.baseFeePerGas\n ? BigInt(block.baseFeePerGas) * 2n + maxPriorityFeePerGas\n : maxPriorityFeePerGas;\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,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,GAAG,MAAM,IAAA,uBAAe,EAC7D,QAAQ,CACT,CAAC,CAAC;SACJ;QAAC,OAAO,KAAU,EAAE;YACnB,OAAO,CAAC,IA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AAC;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"]}
|
|
@@ -2,6 +2,10 @@ import { type Address, type Chain, type Hash, type HttpTransport, type RpcTransa
|
|
|
2
2
|
import { type SmartAccountProviderOpts, type UserOperationCallData, type BatchUserOperationCallData, type SendUserOperationResult, type UserOperationStruct, SmartAccountProvider, type AccountMiddlewareFn, type UserOperationOverrides } from "@alchemy/aa-core";
|
|
3
3
|
import { KernelSmartContractAccount } from "./account.js";
|
|
4
4
|
import type { PaymasterAndBundlerProviders, PaymasterConfig, PaymasterPolicy } from "./paymaster/types.js";
|
|
5
|
+
export type FeeOptions = {
|
|
6
|
+
maxFeePerGasBufferPercentage?: number;
|
|
7
|
+
maxPriorityFeePerGasBufferPercentage?: number;
|
|
8
|
+
};
|
|
5
9
|
export type ZeroDevProviderConfig = {
|
|
6
10
|
projectId: string;
|
|
7
11
|
chain: Chain | number;
|
|
@@ -12,6 +16,7 @@ export type ZeroDevProviderConfig = {
|
|
|
12
16
|
opts?: SmartAccountProviderOpts & {
|
|
13
17
|
sendTxMaxRetries?: number;
|
|
14
18
|
sendTxRetryIntervalMs?: number;
|
|
19
|
+
feeOptions?: FeeOptions;
|
|
15
20
|
};
|
|
16
21
|
};
|
|
17
22
|
export declare enum Operation {
|
|
@@ -27,6 +32,7 @@ export declare class ZeroDevProvider extends SmartAccountProvider<HttpTransport>
|
|
|
27
32
|
private _txMaxRetries;
|
|
28
33
|
private _txRetryIntervalMs;
|
|
29
34
|
private _shouldConsume;
|
|
35
|
+
feeOptions: Required<FeeOptions>;
|
|
30
36
|
constructor({ projectId, chain, entryPointAddress, rpcUrl, account, bundlerProvider, opts, }: ZeroDevProviderConfig);
|
|
31
37
|
getProjectId: () => string;
|
|
32
38
|
shouldConsume: () => boolean;
|
|
@@ -74,6 +74,12 @@ class ZeroDevProvider extends aa_core_1.SmartAccountProvider {
|
|
|
74
74
|
writable: true,
|
|
75
75
|
value: true
|
|
76
76
|
});
|
|
77
|
+
Object.defineProperty(this, "feeOptions", {
|
|
78
|
+
enumerable: true,
|
|
79
|
+
configurable: true,
|
|
80
|
+
writable: true,
|
|
81
|
+
value: void 0
|
|
82
|
+
});
|
|
77
83
|
Object.defineProperty(this, "getProjectId", {
|
|
78
84
|
enumerable: true,
|
|
79
85
|
configurable: true,
|
|
@@ -328,6 +334,10 @@ class ZeroDevProvider extends aa_core_1.SmartAccountProvider {
|
|
|
328
334
|
}
|
|
329
335
|
}
|
|
330
336
|
});
|
|
337
|
+
this.feeOptions = {
|
|
338
|
+
maxFeePerGasBufferPercentage: opts?.feeOptions?.maxFeePerGasBufferPercentage ?? 0,
|
|
339
|
+
maxPriorityFeePerGasBufferPercentage: opts?.feeOptions?.maxPriorityFeePerGasBufferPercentage ?? 13,
|
|
340
|
+
};
|
|
331
341
|
this._txMaxRetries = opts?.txMaxRetries ?? 20;
|
|
332
342
|
this._txRetryIntervalMs = opts?.txRetryIntervalMs ?? 5000;
|
|
333
343
|
this.bundlerProvider = bundlerProvider;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"provider.js","sourceRoot":"","sources":["../../../src/kernel-zerodev/provider.ts"],"names":[],"mappings":";;;AAAA,+BASc;AACd,8CAe0B;AAC1B,iDAMwB;AACxB,6CAA2E;AAC3E,oEAAwE;AACxE,+DAA0D;AAC1D,2CAA+C;AAC/C,4DAAwE;AACxE,gEAA6E;AAM7E,yCAAsC;AAetC,IAAY,SAGX;AAHD,WAAY,SAAS;IACnB,yCAAQ,CAAA;IACR,yDAAgB,CAAA;AAClB,CAAC,EAHW,SAAS,yBAAT,SAAS,QAGpB;AAQD,MAAa,eAAgB,SAAQ,8BAAmC;IAStE,YAAY,EACV,SAAS,EACT,KAAK,EACL,iBAAiB,GAAG,iCAAkB,EACtC,MAAM,GAAG,0BAAW,EACpB,OAAO,EACP,eAAe,EACf,IAAI,GACkB;QACtB,MAAM,MAAM,GAAG,OAAO,KAAK,KAAK,QAAQ,CAAC,CAAC,CAAC,IAAA,mBAAQ,EAAC,KAAK,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC;QACnE,MAAM,SAAS,GAAG,IAAA,mDAAgC,EAAC;YACjD,KAAK,EAAE,MAAM;YACb,MAAM;YACN,SAAS;YACT,eAAe;SAChB,CAAC,CAAC;QAEH,KAAK,CAAC,SAAS,EAAE,iBAAiB,EAAE,MAAM,EAAE,OAAO,EAAE;YACnD,GAAG,IAAI;YACP,YAAY,EAAE,IAAI,EAAE,YAAY,IAAI,EAAE;YACtC,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,CAAC,WAAW,EAAE,EAAE;YACvB,MAAM,IAAI,KAAK,CACb,oEAAoE,CACrE,CAAC;SACH;QAED,OAAO,IAAA,0CAA2B,EAAC,IAAI,EAAE,MAAM,CAAC,CAAC;IACnD,CAAC;CAgCF;AA/YD,0CA+YC","sourcesContent":["import {\n fromHex,\n type Address,\n type Chain,\n type Hash,\n type Hex,\n type HttpTransport,\n type RpcTransactionRequest,\n getAbiItem,\n} from \"viem\";\nimport {\n deepHexlify,\n resolveProperties,\n type SmartAccountProviderOpts,\n type UserOperationCallData,\n type BatchUserOperationCallData,\n type SendUserOperationResult,\n asyncPipe,\n noOpMiddleware,\n type UserOperationStruct,\n type BytesLike,\n SmartAccountProvider,\n type AccountMiddlewareFn,\n type UserOperationOverrides,\n EntryPointAbi,\n} from \"@alchemy/aa-core\";\nimport {\n BUNDLER_URL,\n DEFAULT_SEND_TX_MAX_RETRIES,\n DEFAULT_SEND_TX_RETRY_INTERVAL_MS,\n ENTRYPOINT_ADDRESS,\n minPriorityFeePerBidDefaults,\n} from \"./constants.js\";\nimport { KernelSmartContractAccount, isKernelAccount } from \"./account.js\";\nimport { withZeroDevGasEstimator } from \"./middleware/gas-estimator.js\";\nimport { isValidRequest } from \"./utils/ERC4337-utils.js\";\nimport { InvalidOperation } from \"./errors.js\";\nimport { withZeroDevPaymasterAndData } from \"./middleware/paymaster.js\";\nimport { createZeroDevPublicErc4337Client } from \"./client/create-client.js\";\nimport type {\n PaymasterAndBundlerProviders,\n PaymasterConfig,\n PaymasterPolicy,\n} from \"./paymaster/types.js\";\nimport { getChain } from \"./utils.js\";\n\nexport type ZeroDevProviderConfig = {\n projectId: string;\n chain: Chain | number;\n entryPointAddress?: Address;\n rpcUrl?: string;\n account?: KernelSmartContractAccount;\n bundlerProvider?: PaymasterAndBundlerProviders;\n opts?: SmartAccountProviderOpts & {\n sendTxMaxRetries?: number;\n sendTxRetryIntervalMs?: number;\n };\n};\n\nexport enum Operation {\n Call = 0,\n DelegateCall = 1,\n}\n\ntype UserOpDataOperationTypes<T> = T extends UserOperationCallData\n ? Operation.Call | Operation.DelegateCall\n : T extends BatchUserOperationCallData\n ? Operation.Call\n : never;\n\nexport class ZeroDevProvider extends SmartAccountProvider<HttpTransport> {\n protected projectId: string;\n protected sendTxMaxRetries: number;\n protected sendTxRetryIntervalMs: number;\n readonly bundlerProvider?: PaymasterAndBundlerProviders;\n private _txMaxRetries: number;\n private _txRetryIntervalMs: number;\n private _shouldConsume: boolean = true;\n\n constructor({\n projectId,\n chain,\n entryPointAddress = ENTRYPOINT_ADDRESS,\n rpcUrl = BUNDLER_URL,\n account,\n bundlerProvider,\n opts,\n }: ZeroDevProviderConfig) {\n const _chain = typeof chain === \"number\" ? getChain(chain) : chain;\n const rpcClient = createZeroDevPublicErc4337Client({\n chain: _chain,\n rpcUrl,\n projectId,\n bundlerProvider,\n });\n\n super(rpcClient, entryPointAddress, _chain, account, {\n ...opts,\n txMaxRetries: opts?.txMaxRetries ?? 20,\n txRetryIntervalMs: opts?.txRetryIntervalMs ?? 10000,\n minPriorityFeePerBid:\n opts?.minPriorityFeePerBid ??\n minPriorityFeePerBidDefaults.get(_chain.id),\n });\n\n this._txMaxRetries = opts?.txMaxRetries ?? 20;\n this._txRetryIntervalMs = opts?.txRetryIntervalMs ?? 5000;\n this.bundlerProvider = bundlerProvider;\n this.projectId = projectId;\n this.sendTxMaxRetries =\n opts?.sendTxMaxRetries ?? DEFAULT_SEND_TX_MAX_RETRIES;\n this.sendTxRetryIntervalMs =\n opts?.sendTxRetryIntervalMs ?? DEFAULT_SEND_TX_RETRY_INTERVAL_MS;\n\n withZeroDevGasEstimator(this);\n }\n\n getProjectId = (): string => this.projectId;\n\n shouldConsume = (): boolean => this._shouldConsume;\n\n sendTransaction = async (\n request: RpcTransactionRequest,\n operation: UserOpDataOperationTypes<UserOperationCallData> = Operation.Call\n ): Promise<Hash> => {\n if (!request.to) {\n throw new Error(\"transaction is missing to address\");\n }\n\n const overrides: UserOperationOverrides = {};\n if (request.maxFeePerGas) {\n overrides.maxFeePerGas = request.maxFeePerGas;\n }\n if (request.maxPriorityFeePerGas) {\n overrides.maxPriorityFeePerGas = request.maxPriorityFeePerGas;\n }\n\n const { hash } = await this.sendUserOperation(\n {\n target: request.to,\n data: request.data ?? \"0x\",\n value: request.value ? fromHex(request.value, \"bigint\") : 0n,\n },\n overrides,\n operation\n );\n\n return await this.waitForUserOperationTransaction(hash as Hash);\n };\n\n buildUserOperation = async <\n T extends UserOperationCallData | BatchUserOperationCallData\n >(\n data: T,\n overrides?: UserOperationOverrides,\n operation: UserOpDataOperationTypes<T> = Operation.Call as UserOpDataOperationTypes<T>\n ): Promise<UserOperationStruct> => {\n this._shouldConsume = false;\n if (!isKernelAccount(this.account)) {\n throw new Error(\"account not connected!\");\n }\n if (!this.account.validator) {\n throw new Error(\"validator not connected!\");\n }\n\n let callData: BytesLike = \"0x\";\n\n if (Array.isArray(data)) {\n if (operation === Operation.Call) {\n callData = await this.account.encodeBatchExecute(data);\n } else {\n throw InvalidOperation;\n }\n } else if (isKernelAccount(this.account)) {\n if (operation === Operation.DelegateCall) {\n callData = await this.account.encodeExecuteDelegate(\n data.target,\n data.value ?? 0n,\n data.data\n );\n } else if (operation === Operation.Call) {\n callData = await this.account.encodeExecute(\n data.target,\n data.value ?? 0n,\n data.data\n );\n } else {\n throw InvalidOperation;\n }\n } else {\n throw InvalidOperation;\n }\n\n const initCode = await this.account.getInitCode();\n const nonce = await this.account.getNonce();\n const result = await this._runMiddlewareStack(\n {\n initCode,\n sender: this.getAddress(),\n nonce,\n callData,\n signature: await this.account\n .getValidator()\n .getDynamicDummySignature(await this.getAddress(), callData as Hex),\n } as UserOperationStruct,\n overrides\n );\n this._shouldConsume = true;\n return result;\n };\n\n private _runMiddlewareStack = async (\n uo: UserOperationStruct,\n overrides?: UserOperationOverrides\n ): Promise<UserOperationStruct> => {\n const result = await asyncPipe(\n this.dummyPaymasterDataMiddleware,\n this.feeDataGetter,\n this.paymasterDataMiddleware,\n this.gasEstimator,\n this.customMiddleware ?? noOpMiddleware,\n async (struct) => ({ ...struct, ...overrides })\n )(uo);\n\n return deepHexlify(await resolveProperties<UserOperationStruct>(result));\n };\n\n sendUserOperation = async <\n T extends UserOperationCallData | BatchUserOperationCallData\n >(\n data: T,\n overrides?: UserOperationOverrides,\n operation: UserOpDataOperationTypes<T> = Operation.Call as UserOpDataOperationTypes<T>\n ): Promise<SendUserOperationResult> => {\n if (!this._shouldConsume)\n throw new Error(\n \"Cannot send user operation while building user operation\"\n );\n if (!isKernelAccount(this.account)) {\n throw new Error(\"account not connected!\");\n }\n if (!this.account.validator) {\n throw new Error(\"validator not connected!\");\n }\n\n let callData: BytesLike = \"0x\";\n\n if (Array.isArray(data)) {\n if (operation === Operation.Call) {\n callData = await this.account.encodeBatchExecute(data);\n } else {\n throw InvalidOperation;\n }\n } else if (isKernelAccount(this.account)) {\n if (operation === Operation.DelegateCall) {\n callData = await this.account.encodeExecuteDelegate(\n data.target,\n data.value ?? 0n,\n data.data\n );\n } else if (operation === Operation.Call) {\n callData = await this.account.encodeExecute(\n data.target,\n data.value ?? 0n,\n data.data\n );\n } else {\n throw InvalidOperation;\n }\n } else {\n throw InvalidOperation;\n }\n\n const initCode = await this.account.getInitCode();\n let hash: string = \"\";\n let i = 0;\n const nonce = await this.account.getNonce();\n let uoStruct: UserOperationStruct;\n let request: UserOperationStruct;\n let maxFeePerGas, maxPriorityFeePerGas;\n do {\n uoStruct = await asyncPipe(\n this.dummyPaymasterDataMiddleware,\n this.feeDataGetter,\n this.paymasterDataMiddleware,\n this.gasEstimator,\n this.customMiddleware ?? noOpMiddleware,\n async (struct) => ({ ...struct, ...overrides })\n )({\n initCode,\n sender: this.getAddress(),\n nonce,\n callData,\n signature: await this.account\n .getValidator()\n .getDynamicDummySignature(await this.getAddress(), callData as Hex),\n maxFeePerGas,\n maxPriorityFeePerGas,\n } as UserOperationStruct);\n request = deepHexlify(await resolveProperties(uoStruct));\n\n if (!isValidRequest(request)) {\n // this pretty prints the uo\n throw new Error(\n `Request is missing parameters. All properties on UserOperationStruct must be set. uo: ${JSON.stringify(\n request,\n null,\n 2\n )}`\n );\n }\n\n await this.account.approvePlugin();\n\n request.signature = await this.account.validator.getSignature(request);\n try {\n hash = await this.rpcClient.sendUserOperation(\n request,\n this.entryPointAddress\n );\n } catch (error: any) {\n if (this.isReplacementOpError(error) && i++ < this.sendTxMaxRetries) {\n maxFeePerGas = (BigInt(request.maxFeePerGas) * 113n) / 100n;\n maxPriorityFeePerGas =\n (BigInt(request.maxPriorityFeePerGas) * 113n) / 100n;\n\n console.log(\n `After ${\n this.sendTxRetryIntervalMs / 60000\n } minutes, resending tx with Increased Gas fees: maxFeePerGas: ${maxFeePerGas}, maxPriorityFeePerGas: ${maxPriorityFeePerGas}`\n );\n await new Promise((resolve) =>\n setTimeout(resolve, this.sendTxRetryIntervalMs)\n );\n continue;\n }\n throw this.unwrapError(error);\n }\n } while (hash === \"\");\n\n return {\n hash,\n request,\n };\n };\n\n isReplacementOpError(errorIn: any): boolean {\n if (errorIn.cause != null) {\n const failedOpMessage: string | undefined = errorIn?.cause?.message;\n return (\n (failedOpMessage?.includes(\n \"replacement op must increase maxFeePerGas and MaxPriorityFeePerGas\"\n ) ||\n failedOpMessage?.match(/.*replacement.*underpriced.*/) !== null) ??\n false\n );\n }\n return false;\n }\n\n unwrapError(errorIn: any): Error {\n if (errorIn?.cause != null) {\n let paymasterInfo: string = \"\";\n let failedOpMessage: string | undefined = errorIn?.cause?.message;\n if (failedOpMessage?.includes(\"FailedOp\") === true) {\n // TODO: better error extraction methods will be needed\n const matched = failedOpMessage.match(/FailedOp\\((.*)\\)/);\n if (matched != null) {\n const split = matched[1].split(\",\");\n paymasterInfo = `(paymaster address: ${split[1]})`;\n failedOpMessage = split[2];\n }\n }\n const error = new Error(\n `The bundler has failed to include UserOperation in a batch: ${failedOpMessage} ${paymasterInfo}`\n );\n error.stack = errorIn.stack;\n return error;\n }\n return errorIn;\n }\n\n waitForUserOperationTransaction = async (hash: Hash): Promise<Hash> => {\n let blockNumber = await this.rpcClient.getBlockNumber();\n for (let i = 0; i < this._txMaxRetries; i++) {\n if (this.bundlerProvider === \"GELATO\") {\n const receipt = await this.getUserOperationReceipt(\n hash as `0x${string}`\n )\n // TODO: should maybe log the error?\n .catch(() => null);\n if (receipt) {\n return this.getTransaction(receipt.receipt.transactionHash).then(\n (x) => x.hash\n );\n }\n } else {\n const logs = await this.rpcClient.getLogs({\n address: ENTRYPOINT_ADDRESS,\n event: getAbiItem({ abi: EntryPointAbi, name: \"UserOperationEvent\" }),\n args: { userOpHash: hash },\n fromBlock: blockNumber - 100n,\n });\n if (logs.length) {\n return logs[0].transactionHash;\n }\n }\n await new Promise((resolve) =>\n setTimeout(resolve, this._txRetryIntervalMs)\n );\n }\n\n throw new Error(\"Failed to find transaction for User Operation\");\n };\n\n getAccount: () => KernelSmartContractAccount = () => {\n if (!isKernelAccount(this.account)) {\n throw new Error(\"account not connected!\");\n }\n return this.account;\n };\n\n dummyPaymasterDataMiddleware: AccountMiddlewareFn = async (\n struct: UserOperationStruct\n ): Promise<UserOperationStruct> => {\n struct.paymasterAndData = \"0x\";\n return struct;\n };\n\n withZeroDevPaymasterAndData(config: PaymasterConfig<PaymasterPolicy>) {\n if (!this.isConnected()) {\n throw new Error(\n \"ZeroDevProvider: account is not set, did you call `connect` first?\"\n );\n }\n\n return withZeroDevPaymasterAndData(this, config);\n }\n\n request: (args: { method: string; params?: any[] }) => Promise<any> = async (\n args\n ) => {\n const { method, params } = args;\n switch (method) {\n case \"eth_chainId\":\n return this.chain.id;\n case \"eth_sendTransaction\":\n const [tx] = params as [RpcTransactionRequest];\n return this.sendTransaction(tx);\n case \"eth_signTypedData_v4\":\n //@ts-expect-error\n return this.signTypedData(JSON.parse(params[1]));\n case \"personal_sign\":\n if (!this.account) {\n throw new Error(\"account not connected!\");\n }\n const [data, address] = params!;\n if (address.toLowerCase() !== (await this.getAddress()).toLowerCase()) {\n throw new Error(\n \"cannot sign for address that is not the current account\"\n );\n }\n // @ts-ignore\n return this.account.signMessageWith6492(data);\n default:\n // @ts-ignore\n return this.rpcClient.request(args);\n }\n };\n}\n"]}
|
|
1
|
+
{"version":3,"file":"provider.js","sourceRoot":"","sources":["../../../src/kernel-zerodev/provider.ts"],"names":[],"mappings":";;;AAAA,+BASc;AACd,8CAe0B;AAC1B,iDAMwB;AACxB,6CAA2E;AAC3E,oEAAwE;AACxE,+DAA0D;AAC1D,2CAA+C;AAC/C,4DAAwE;AACxE,gEAA6E;AAM7E,yCAAsC;AAoBtC,IAAY,SAGX;AAHD,WAAY,SAAS;IACnB,yCAAQ,CAAA;IACR,yDAAgB,CAAA;AAClB,CAAC,EAHW,SAAS,yBAAT,SAAS,QAGpB;AAQD,MAAa,eAAgB,SAAQ,8BAAmC;IAUtE,YAAY,EACV,SAAS,EACT,KAAK,EACL,iBAAiB,GAAG,iCAAkB,EACtC,MAAM,GAAG,0BAAW,EACpB,OAAO,EACP,eAAe,EACf,IAAI,GACkB;QACtB,MAAM,MAAM,GAAG,OAAO,KAAK,KAAK,QAAQ,CAAC,CAAC,CAAC,IAAA,mBAAQ,EAAC,KAAK,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC;QACnE,MAAM,SAAS,GAAG,IAAA,mDAAgC,EAAC;YACjD,KAAK,EAAE,MAAM;YACb,MAAM;YACN,SAAS;YACT,eAAe;SAChB,CAAC,CAAC;QAEH,KAAK,CAAC,SAAS,EAAE,iBAAiB,EAAE,MAAM,EAAE,OAAO,EAAE;YACnD,GAAG,IAAI;YACP,YAAY,EAAE,IAAI,EAAE,YAAY,IAAI,EAAE;YACtC,iBAAiB,EAAE,IAAI,EAAE,iBAAiB,IAAI,KAAK;YACnD,oBAAoB,EAClB,IAAI,EAAE,oBAAoB;gBAC1B,2CAA4B,CAAC,GAAG,CAAC,MAAM,CAAC,EAAE,CAAC;SAC9C,CAAC,CAAC;QAjCK;;;;;WAAkB;QAClB;;;;;WAAyB;Q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EAAE,EAAE;YACvB,MAAM,IAAI,KAAK,CACb,oEAAoE,CACrE,CAAC;SACH;QAED,OAAO,IAAA,0CAA2B,EAAC,IAAI,EAAE,MAAM,CAAC,CAAC;IACnD,CAAC;CAgCF;AAtZD,0CAsZC","sourcesContent":["import {\n fromHex,\n type Address,\n type Chain,\n type Hash,\n type Hex,\n type HttpTransport,\n type RpcTransactionRequest,\n getAbiItem,\n} from \"viem\";\nimport {\n deepHexlify,\n resolveProperties,\n type SmartAccountProviderOpts,\n type UserOperationCallData,\n type BatchUserOperationCallData,\n type SendUserOperationResult,\n asyncPipe,\n noOpMiddleware,\n type UserOperationStruct,\n type BytesLike,\n SmartAccountProvider,\n type AccountMiddlewareFn,\n type UserOperationOverrides,\n EntryPointAbi,\n} from \"@alchemy/aa-core\";\nimport {\n BUNDLER_URL,\n DEFAULT_SEND_TX_MAX_RETRIES,\n DEFAULT_SEND_TX_RETRY_INTERVAL_MS,\n ENTRYPOINT_ADDRESS,\n minPriorityFeePerBidDefaults,\n} from \"./constants.js\";\nimport { KernelSmartContractAccount, isKernelAccount } from \"./account.js\";\nimport { withZeroDevGasEstimator } from \"./middleware/gas-estimator.js\";\nimport { isValidRequest } from \"./utils/ERC4337-utils.js\";\nimport { InvalidOperation } from \"./errors.js\";\nimport { withZeroDevPaymasterAndData } from \"./middleware/paymaster.js\";\nimport { createZeroDevPublicErc4337Client } from \"./client/create-client.js\";\nimport type {\n PaymasterAndBundlerProviders,\n PaymasterConfig,\n PaymasterPolicy,\n} from \"./paymaster/types.js\";\nimport { getChain } from \"./utils.js\";\n\nexport type FeeOptions = {\n maxFeePerGasBufferPercentage?: number;\n maxPriorityFeePerGasBufferPercentage?: number;\n};\nexport type ZeroDevProviderConfig = {\n projectId: string;\n chain: Chain | number;\n entryPointAddress?: Address;\n rpcUrl?: string;\n account?: KernelSmartContractAccount;\n bundlerProvider?: PaymasterAndBundlerProviders;\n opts?: SmartAccountProviderOpts & {\n sendTxMaxRetries?: number;\n sendTxRetryIntervalMs?: number;\n feeOptions?: FeeOptions;\n };\n};\n\nexport enum Operation {\n Call = 0,\n DelegateCall = 1,\n}\n\ntype UserOpDataOperationTypes<T> = T extends UserOperationCallData\n ? Operation.Call | Operation.DelegateCall\n : T extends BatchUserOperationCallData\n ? Operation.Call\n : never;\n\nexport class ZeroDevProvider extends SmartAccountProvider<HttpTransport> {\n protected projectId: string;\n protected sendTxMaxRetries: number;\n protected sendTxRetryIntervalMs: number;\n readonly bundlerProvider?: PaymasterAndBundlerProviders;\n private _txMaxRetries: number;\n private _txRetryIntervalMs: number;\n private _shouldConsume: boolean = true;\n public feeOptions: Required<FeeOptions>;\n\n constructor({\n projectId,\n chain,\n entryPointAddress = ENTRYPOINT_ADDRESS,\n rpcUrl = BUNDLER_URL,\n account,\n bundlerProvider,\n opts,\n }: ZeroDevProviderConfig) {\n const _chain = typeof chain === \"number\" ? getChain(chain) : chain;\n const rpcClient = createZeroDevPublicErc4337Client({\n chain: _chain,\n rpcUrl,\n projectId,\n bundlerProvider,\n });\n\n super(rpcClient, entryPointAddress, _chain, account, {\n ...opts,\n txMaxRetries: opts?.txMaxRetries ?? 20,\n txRetryIntervalMs: opts?.txRetryIntervalMs ?? 10000,\n minPriorityFeePerBid:\n opts?.minPriorityFeePerBid ??\n minPriorityFeePerBidDefaults.get(_chain.id),\n });\n\n this.feeOptions = {\n maxFeePerGasBufferPercentage:\n opts?.feeOptions?.maxFeePerGasBufferPercentage ?? 0,\n maxPriorityFeePerGasBufferPercentage:\n opts?.feeOptions?.maxPriorityFeePerGasBufferPercentage ?? 13,\n };\n this._txMaxRetries = opts?.txMaxRetries ?? 20;\n this._txRetryIntervalMs = opts?.txRetryIntervalMs ?? 5000;\n this.bundlerProvider = bundlerProvider;\n this.projectId = projectId;\n this.sendTxMaxRetries =\n opts?.sendTxMaxRetries ?? DEFAULT_SEND_TX_MAX_RETRIES;\n this.sendTxRetryIntervalMs =\n opts?.sendTxRetryIntervalMs ?? DEFAULT_SEND_TX_RETRY_INTERVAL_MS;\n\n withZeroDevGasEstimator(this);\n }\n\n getProjectId = (): string => this.projectId;\n\n shouldConsume = (): boolean => this._shouldConsume;\n\n sendTransaction = async (\n request: RpcTransactionRequest,\n operation: UserOpDataOperationTypes<UserOperationCallData> = Operation.Call\n ): Promise<Hash> => {\n if (!request.to) {\n throw new Error(\"transaction is missing to address\");\n }\n\n const overrides: UserOperationOverrides = {};\n if (request.maxFeePerGas) {\n overrides.maxFeePerGas = request.maxFeePerGas;\n }\n if (request.maxPriorityFeePerGas) {\n overrides.maxPriorityFeePerGas = request.maxPriorityFeePerGas;\n }\n\n const { hash } = await this.sendUserOperation(\n {\n target: request.to,\n data: request.data ?? \"0x\",\n value: request.value ? fromHex(request.value, \"bigint\") : 0n,\n },\n overrides,\n operation\n );\n\n return await this.waitForUserOperationTransaction(hash as Hash);\n };\n\n buildUserOperation = async <\n T extends UserOperationCallData | BatchUserOperationCallData\n >(\n data: T,\n overrides?: UserOperationOverrides,\n operation: UserOpDataOperationTypes<T> = Operation.Call as UserOpDataOperationTypes<T>\n ): Promise<UserOperationStruct> => {\n this._shouldConsume = false;\n if (!isKernelAccount(this.account)) {\n throw new Error(\"account not connected!\");\n }\n if (!this.account.validator) {\n throw new Error(\"validator not connected!\");\n }\n\n let callData: BytesLike = \"0x\";\n\n if (Array.isArray(data)) {\n if (operation === Operation.Call) {\n callData = await this.account.encodeBatchExecute(data);\n } else {\n throw InvalidOperation;\n }\n } else if (isKernelAccount(this.account)) {\n if (operation === Operation.DelegateCall) {\n callData = await this.account.encodeExecuteDelegate(\n data.target,\n data.value ?? 0n,\n data.data\n );\n } else if (operation === Operation.Call) {\n callData = await this.account.encodeExecute(\n data.target,\n data.value ?? 0n,\n data.data\n );\n } else {\n throw InvalidOperation;\n }\n } else {\n throw InvalidOperation;\n }\n\n const initCode = await this.account.getInitCode();\n const nonce = await this.account.getNonce();\n const result = await this._runMiddlewareStack(\n {\n initCode,\n sender: this.getAddress(),\n nonce,\n callData,\n signature: await this.account\n .getValidator()\n .getDynamicDummySignature(await this.getAddress(), callData as Hex),\n } as UserOperationStruct,\n overrides\n );\n this._shouldConsume = true;\n return result;\n };\n\n private _runMiddlewareStack = async (\n uo: UserOperationStruct,\n overrides?: UserOperationOverrides\n ): Promise<UserOperationStruct> => {\n const result = await asyncPipe(\n this.dummyPaymasterDataMiddleware,\n this.feeDataGetter,\n this.paymasterDataMiddleware,\n this.gasEstimator,\n this.customMiddleware ?? noOpMiddleware,\n async (struct) => ({ ...struct, ...overrides })\n )(uo);\n\n return deepHexlify(await resolveProperties<UserOperationStruct>(result));\n };\n\n sendUserOperation = async <\n T extends UserOperationCallData | BatchUserOperationCallData\n >(\n data: T,\n overrides?: UserOperationOverrides,\n operation: UserOpDataOperationTypes<T> = Operation.Call as UserOpDataOperationTypes<T>\n ): Promise<SendUserOperationResult> => {\n if (!this._shouldConsume)\n throw new Error(\n \"Cannot send user operation while building user operation\"\n );\n if (!isKernelAccount(this.account)) {\n throw new Error(\"account not connected!\");\n }\n if (!this.account.validator) {\n throw new Error(\"validator not connected!\");\n }\n\n let callData: BytesLike = \"0x\";\n\n if (Array.isArray(data)) {\n if (operation === Operation.Call) {\n callData = await this.account.encodeBatchExecute(data);\n } else {\n throw InvalidOperation;\n }\n } else if (isKernelAccount(this.account)) {\n if (operation === Operation.DelegateCall) {\n callData = await this.account.encodeExecuteDelegate(\n data.target,\n data.value ?? 0n,\n data.data\n );\n } else if (operation === Operation.Call) {\n callData = await this.account.encodeExecute(\n data.target,\n data.value ?? 0n,\n data.data\n );\n } else {\n throw InvalidOperation;\n }\n } else {\n throw InvalidOperation;\n }\n\n const initCode = await this.account.getInitCode();\n let hash: string = \"\";\n let i = 0;\n const nonce = await this.account.getNonce();\n let uoStruct: UserOperationStruct;\n let request: UserOperationStruct;\n let maxFeePerGas, maxPriorityFeePerGas;\n do {\n uoStruct = await asyncPipe(\n this.dummyPaymasterDataMiddleware,\n this.feeDataGetter,\n this.paymasterDataMiddleware,\n this.gasEstimator,\n this.customMiddleware ?? noOpMiddleware,\n async (struct) => ({ ...struct, ...overrides })\n )({\n initCode,\n sender: this.getAddress(),\n nonce,\n callData,\n signature: await this.account\n .getValidator()\n .getDynamicDummySignature(await this.getAddress(), callData as Hex),\n maxFeePerGas,\n maxPriorityFeePerGas,\n } as UserOperationStruct);\n request = deepHexlify(await resolveProperties(uoStruct));\n\n if (!isValidRequest(request)) {\n // this pretty prints the uo\n throw new Error(\n `Request is missing parameters. All properties on UserOperationStruct must be set. uo: ${JSON.stringify(\n request,\n null,\n 2\n )}`\n );\n }\n\n await this.account.approvePlugin();\n\n request.signature = await this.account.validator.getSignature(request);\n try {\n hash = await this.rpcClient.sendUserOperation(\n request,\n this.entryPointAddress\n );\n } catch (error: any) {\n if (this.isReplacementOpError(error) && i++ < this.sendTxMaxRetries) {\n maxFeePerGas = (BigInt(request.maxFeePerGas) * 113n) / 100n;\n maxPriorityFeePerGas =\n (BigInt(request.maxPriorityFeePerGas) * 113n) / 100n;\n\n console.log(\n `After ${\n this.sendTxRetryIntervalMs / 60000\n } minutes, resending tx with Increased Gas fees: maxFeePerGas: ${maxFeePerGas}, maxPriorityFeePerGas: ${maxPriorityFeePerGas}`\n );\n await new Promise((resolve) =>\n setTimeout(resolve, this.sendTxRetryIntervalMs)\n );\n continue;\n }\n throw this.unwrapError(error);\n }\n } while (hash === \"\");\n\n return {\n hash,\n request,\n };\n };\n\n isReplacementOpError(errorIn: any): boolean {\n if (errorIn.cause != null) {\n const failedOpMessage: string | undefined = errorIn?.cause?.message;\n return (\n (failedOpMessage?.includes(\n \"replacement op must increase maxFeePerGas and MaxPriorityFeePerGas\"\n ) ||\n failedOpMessage?.match(/.*replacement.*underpriced.*/) !== null) ??\n false\n );\n }\n return false;\n }\n\n unwrapError(errorIn: any): Error {\n if (errorIn?.cause != null) {\n let paymasterInfo: string = \"\";\n let failedOpMessage: string | undefined = errorIn?.cause?.message;\n if (failedOpMessage?.includes(\"FailedOp\") === true) {\n // TODO: better error extraction methods will be needed\n const matched = failedOpMessage.match(/FailedOp\\((.*)\\)/);\n if (matched != null) {\n const split = matched[1].split(\",\");\n paymasterInfo = `(paymaster address: ${split[1]})`;\n failedOpMessage = split[2];\n }\n }\n const error = new Error(\n `The bundler has failed to include UserOperation in a batch: ${failedOpMessage} ${paymasterInfo}`\n );\n error.stack = errorIn.stack;\n return error;\n }\n return errorIn;\n }\n\n waitForUserOperationTransaction = async (hash: Hash): Promise<Hash> => {\n let blockNumber = await this.rpcClient.getBlockNumber();\n for (let i = 0; i < this._txMaxRetries; i++) {\n if (this.bundlerProvider === \"GELATO\") {\n const receipt = await this.getUserOperationReceipt(\n hash as `0x${string}`\n )\n // TODO: should maybe log the error?\n .catch(() => null);\n if (receipt) {\n return this.getTransaction(receipt.receipt.transactionHash).then(\n (x) => x.hash\n );\n }\n } else {\n const logs = await this.rpcClient.getLogs({\n address: ENTRYPOINT_ADDRESS,\n event: getAbiItem({ abi: EntryPointAbi, name: \"UserOperationEvent\" }),\n args: { userOpHash: hash },\n fromBlock: blockNumber - 100n,\n });\n if (logs.length) {\n return logs[0].transactionHash;\n }\n }\n await new Promise((resolve) =>\n setTimeout(resolve, this._txRetryIntervalMs)\n );\n }\n\n throw new Error(\"Failed to find transaction for User Operation\");\n };\n\n getAccount: () => KernelSmartContractAccount = () => {\n if (!isKernelAccount(this.account)) {\n throw new Error(\"account not connected!\");\n }\n return this.account;\n };\n\n dummyPaymasterDataMiddleware: AccountMiddlewareFn = async (\n struct: UserOperationStruct\n ): Promise<UserOperationStruct> => {\n struct.paymasterAndData = \"0x\";\n return struct;\n };\n\n withZeroDevPaymasterAndData(config: PaymasterConfig<PaymasterPolicy>) {\n if (!this.isConnected()) {\n throw new Error(\n \"ZeroDevProvider: account is not set, did you call `connect` first?\"\n );\n }\n\n return withZeroDevPaymasterAndData(this, config);\n }\n\n request: (args: { method: string; params?: any[] }) => Promise<any> = async (\n args\n ) => {\n const { method, params } = args;\n switch (method) {\n case \"eth_chainId\":\n return this.chain.id;\n case \"eth_sendTransaction\":\n const [tx] = params as [RpcTransactionRequest];\n return this.sendTransaction(tx);\n case \"eth_signTypedData_v4\":\n //@ts-expect-error\n return this.signTypedData(JSON.parse(params[1]));\n case \"personal_sign\":\n if (!this.account) {\n throw new Error(\"account not connected!\");\n }\n const [data, address] = params!;\n if (address.toLowerCase() !== (await this.getAddress()).toLowerCase()) {\n throw new Error(\n \"cannot sign for address that is not the current account\"\n );\n }\n // @ts-ignore\n return this.account.signMessageWith6492(data);\n default:\n // @ts-ignore\n return this.rpcClient.request(args);\n }\n };\n}\n"]}
|
|
@@ -101,15 +101,19 @@ export const eip1559GasPrice = async (provider) => {
|
|
|
101
101
|
fee = fee.standard.maxPriorityFeePerGas;
|
|
102
102
|
}
|
|
103
103
|
const tip = BigInt(fee);
|
|
104
|
-
const buffer = (tip / 100n) *
|
|
104
|
+
const buffer = (tip / 100n) *
|
|
105
|
+
BigInt(provider.feeOptions.maxPriorityFeePerGasBufferPercentage);
|
|
105
106
|
let maxPriorityFeePerGas = tip + buffer;
|
|
106
107
|
maxPriorityFeePerGas =
|
|
107
108
|
maxPriorityFeePerGas < provider.minPriorityFeePerBid
|
|
108
109
|
? provider.minPriorityFeePerBid
|
|
109
110
|
: maxPriorityFeePerGas;
|
|
110
|
-
const maxFeePerGas = block.baseFeePerGas
|
|
111
|
+
const maxFeePerGas = ((block.baseFeePerGas
|
|
111
112
|
? BigInt(block.baseFeePerGas) * 2n + maxPriorityFeePerGas
|
|
112
|
-
: maxPriorityFeePerGas
|
|
113
|
+
: maxPriorityFeePerGas) *
|
|
114
|
+
(BigInt(100) +
|
|
115
|
+
BigInt(provider.feeOptions.maxFeePerGasBufferPercentage))) /
|
|
116
|
+
100n;
|
|
113
117
|
return { maxFeePerGas, maxPriorityFeePerGas };
|
|
114
118
|
};
|
|
115
119
|
export const getFeeData = async (provider) => {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"gas-estimator.js","sourceRo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AoB,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 = (tip / 100n) * 13n;\n let maxPriorityFeePerGas = tip + buffer;\n maxPriorityFeePerGas =\n maxPriorityFeePerGas < provider.minPriorityFeePerBid\n ? provider.minPriorityFeePerBid\n : maxPriorityFeePerGas;\n const maxFeePerGas = block.baseFeePerGas\n ? BigInt(block.baseFeePerGas) * 2n + maxPriorityFeePerGas\n : maxPriorityFeePerGas;\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,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,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,GAAG,MAAM,eAAe,CAC7D,QAAQ,CACT,CAAC,CAAC;SACJ;QAAC,OAAO,KAAU,EAAE;YACnB,OAAO,CAAC,IAAI,CACV,4EAA4E,CAC7E,CAAC;SACH;QAED,IAAI,YAAY,KAAK,SAAS,IAAI,oBAAoB,KAAK,SAAS,EAAE;YACpE,MAAM,OAAO,GAAG,MAAM,UAAU,CAAC,QAAQ,CAAC,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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"]}
|
|
@@ -2,6 +2,10 @@ import { type Address, type Chain, type Hash, type HttpTransport, type RpcTransa
|
|
|
2
2
|
import { type SmartAccountProviderOpts, type UserOperationCallData, type BatchUserOperationCallData, type SendUserOperationResult, type UserOperationStruct, SmartAccountProvider, type AccountMiddlewareFn, type UserOperationOverrides } from "@alchemy/aa-core";
|
|
3
3
|
import { KernelSmartContractAccount } from "./account.js";
|
|
4
4
|
import type { PaymasterAndBundlerProviders, PaymasterConfig, PaymasterPolicy } from "./paymaster/types.js";
|
|
5
|
+
export type FeeOptions = {
|
|
6
|
+
maxFeePerGasBufferPercentage?: number;
|
|
7
|
+
maxPriorityFeePerGasBufferPercentage?: number;
|
|
8
|
+
};
|
|
5
9
|
export type ZeroDevProviderConfig = {
|
|
6
10
|
projectId: string;
|
|
7
11
|
chain: Chain | number;
|
|
@@ -12,6 +16,7 @@ export type ZeroDevProviderConfig = {
|
|
|
12
16
|
opts?: SmartAccountProviderOpts & {
|
|
13
17
|
sendTxMaxRetries?: number;
|
|
14
18
|
sendTxRetryIntervalMs?: number;
|
|
19
|
+
feeOptions?: FeeOptions;
|
|
15
20
|
};
|
|
16
21
|
};
|
|
17
22
|
export declare enum Operation {
|
|
@@ -27,6 +32,7 @@ export declare class ZeroDevProvider extends SmartAccountProvider<HttpTransport>
|
|
|
27
32
|
private _txMaxRetries;
|
|
28
33
|
private _txRetryIntervalMs;
|
|
29
34
|
private _shouldConsume;
|
|
35
|
+
feeOptions: Required<FeeOptions>;
|
|
30
36
|
constructor({ projectId, chain, entryPointAddress, rpcUrl, account, bundlerProvider, opts, }: ZeroDevProviderConfig);
|
|
31
37
|
getProjectId: () => string;
|
|
32
38
|
shouldConsume: () => boolean;
|
|
@@ -71,6 +71,12 @@ export class ZeroDevProvider extends SmartAccountProvider {
|
|
|
71
71
|
writable: true,
|
|
72
72
|
value: true
|
|
73
73
|
});
|
|
74
|
+
Object.defineProperty(this, "feeOptions", {
|
|
75
|
+
enumerable: true,
|
|
76
|
+
configurable: true,
|
|
77
|
+
writable: true,
|
|
78
|
+
value: void 0
|
|
79
|
+
});
|
|
74
80
|
Object.defineProperty(this, "getProjectId", {
|
|
75
81
|
enumerable: true,
|
|
76
82
|
configurable: true,
|
|
@@ -325,6 +331,10 @@ export class ZeroDevProvider extends SmartAccountProvider {
|
|
|
325
331
|
}
|
|
326
332
|
}
|
|
327
333
|
});
|
|
334
|
+
this.feeOptions = {
|
|
335
|
+
maxFeePerGasBufferPercentage: opts?.feeOptions?.maxFeePerGasBufferPercentage ?? 0,
|
|
336
|
+
maxPriorityFeePerGasBufferPercentage: opts?.feeOptions?.maxPriorityFeePerGasBufferPercentage ?? 13,
|
|
337
|
+
};
|
|
328
338
|
this._txMaxRetries = opts?.txMaxRetries ?? 20;
|
|
329
339
|
this._txRetryIntervalMs = opts?.txRetryIntervalMs ?? 5000;
|
|
330
340
|
this.bundlerProvider = bundler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AK,CAAC;SACd;QACD,OAAO,OAAO,CAAC;IACjB,CAAC;IAiDD,2BAA2B,CAAC,MAAwC;QAClE,IAAI,CAAC,IAAI,CAAC,WAAW,EAAE,EAAE;YACvB,MAAM,IAAI,KAAK,CACb,oEAAoE,CACrE,CAAC;SACH;QAED,OAAO,2BAA2B,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC;IACnD,CAAC;CAgCF","sourcesContent":["import {\n fromHex,\n type Address,\n type Chain,\n type Hash,\n type Hex,\n type HttpTransport,\n type RpcTransactionRequest,\n getAbiItem,\n} from \"viem\";\nimport {\n deepHexlify,\n resolveProperties,\n type SmartAccountProviderOpts,\n type UserOperationCallData,\n type BatchUserOperationCallData,\n type SendUserOperationResult,\n asyncPipe,\n noOpMiddleware,\n type UserOperationStruct,\n type BytesLike,\n SmartAccountProvider,\n type AccountMiddlewareFn,\n type UserOperationOverrides,\n EntryPointAbi,\n} from \"@alchemy/aa-core\";\nimport {\n BUNDLER_URL,\n DEFAULT_SEND_TX_MAX_RETRIES,\n DEFAULT_SEND_TX_RETRY_INTERVAL_MS,\n ENTRYPOINT_ADDRESS,\n minPriorityFeePerBidDefaults,\n} from \"./constants.js\";\nimport { KernelSmartContractAccount, isKernelAccount } from \"./account.js\";\nimport { withZeroDevGasEstimator } from \"./middleware/gas-estimator.js\";\nimport { isValidRequest } from \"./utils/ERC4337-utils.js\";\nimport { InvalidOperation } from \"./errors.js\";\nimport { withZeroDevPaymasterAndData } from \"./middleware/paymaster.js\";\nimport { createZeroDevPublicErc4337Client } from \"./client/create-client.js\";\nimport type {\n PaymasterAndBundlerProviders,\n PaymasterConfig,\n PaymasterPolicy,\n} from \"./paymaster/types.js\";\nimport { getChain } from \"./utils.js\";\n\nexport type ZeroDevProviderConfig = {\n projectId: string;\n chain: Chain | number;\n entryPointAddress?: Address;\n rpcUrl?: string;\n account?: KernelSmartContractAccount;\n bundlerProvider?: PaymasterAndBundlerProviders;\n opts?: SmartAccountProviderOpts & {\n sendTxMaxRetries?: number;\n sendTxRetryIntervalMs?: number;\n };\n};\n\nexport enum Operation {\n Call = 0,\n DelegateCall = 1,\n}\n\ntype UserOpDataOperationTypes<T> = T extends UserOperationCallData\n ? Operation.Call | Operation.DelegateCall\n : T extends BatchUserOperationCallData\n ? Operation.Call\n : never;\n\nexport class ZeroDevProvider extends SmartAccountProvider<HttpTransport> {\n protected projectId: string;\n protected sendTxMaxRetries: number;\n protected sendTxRetryIntervalMs: number;\n readonly bundlerProvider?: PaymasterAndBundlerProviders;\n private _txMaxRetries: number;\n private _txRetryIntervalMs: number;\n private _shouldConsume: boolean = true;\n\n constructor({\n projectId,\n chain,\n entryPointAddress = ENTRYPOINT_ADDRESS,\n rpcUrl = BUNDLER_URL,\n account,\n bundlerProvider,\n opts,\n }: ZeroDevProviderConfig) {\n const _chain = typeof chain === \"number\" ? getChain(chain) : chain;\n const rpcClient = createZeroDevPublicErc4337Client({\n chain: _chain,\n rpcUrl,\n projectId,\n bundlerProvider,\n });\n\n super(rpcClient, entryPointAddress, _chain, account, {\n ...opts,\n txMaxRetries: opts?.txMaxRetries ?? 20,\n txRetryIntervalMs: opts?.txRetryIntervalMs ?? 10000,\n minPriorityFeePerBid:\n opts?.minPriorityFeePerBid ??\n minPriorityFeePerBidDefaults.get(_chain.id),\n });\n\n this._txMaxRetries = opts?.txMaxRetries ?? 20;\n this._txRetryIntervalMs = opts?.txRetryIntervalMs ?? 5000;\n this.bundlerProvider = bundlerProvider;\n this.projectId = projectId;\n this.sendTxMaxRetries =\n opts?.sendTxMaxRetries ?? DEFAULT_SEND_TX_MAX_RETRIES;\n this.sendTxRetryIntervalMs =\n opts?.sendTxRetryIntervalMs ?? DEFAULT_SEND_TX_RETRY_INTERVAL_MS;\n\n withZeroDevGasEstimator(this);\n }\n\n getProjectId = (): string => this.projectId;\n\n shouldConsume = (): boolean => this._shouldConsume;\n\n sendTransaction = async (\n request: RpcTransactionRequest,\n operation: UserOpDataOperationTypes<UserOperationCallData> = Operation.Call\n ): Promise<Hash> => {\n if (!request.to) {\n throw new Error(\"transaction is missing to address\");\n }\n\n const overrides: UserOperationOverrides = {};\n if (request.maxFeePerGas) {\n overrides.maxFeePerGas = request.maxFeePerGas;\n }\n if (request.maxPriorityFeePerGas) {\n overrides.maxPriorityFeePerGas = request.maxPriorityFeePerGas;\n }\n\n const { hash } = await this.sendUserOperation(\n {\n target: request.to,\n data: request.data ?? \"0x\",\n value: request.value ? fromHex(request.value, \"bigint\") : 0n,\n },\n overrides,\n operation\n );\n\n return await this.waitForUserOperationTransaction(hash as Hash);\n };\n\n buildUserOperation = async <\n T extends UserOperationCallData | BatchUserOperationCallData\n >(\n data: T,\n overrides?: UserOperationOverrides,\n operation: UserOpDataOperationTypes<T> = Operation.Call as UserOpDataOperationTypes<T>\n ): Promise<UserOperationStruct> => {\n this._shouldConsume = false;\n if (!isKernelAccount(this.account)) {\n throw new Error(\"account not connected!\");\n }\n if (!this.account.validator) {\n throw new Error(\"validator not connected!\");\n }\n\n let callData: BytesLike = \"0x\";\n\n if (Array.isArray(data)) {\n if (operation === Operation.Call) {\n callData = await this.account.encodeBatchExecute(data);\n } else {\n throw InvalidOperation;\n }\n } else if (isKernelAccount(this.account)) {\n if (operation === Operation.DelegateCall) {\n callData = await this.account.encodeExecuteDelegate(\n data.target,\n data.value ?? 0n,\n data.data\n );\n } else if (operation === Operation.Call) {\n callData = await this.account.encodeExecute(\n data.target,\n data.value ?? 0n,\n data.data\n );\n } else {\n throw InvalidOperation;\n }\n } else {\n throw InvalidOperation;\n }\n\n const initCode = await this.account.getInitCode();\n const nonce = await this.account.getNonce();\n const result = await this._runMiddlewareStack(\n {\n initCode,\n sender: this.getAddress(),\n nonce,\n callData,\n signature: await this.account\n .getValidator()\n .getDynamicDummySignature(await this.getAddress(), callData as Hex),\n } as UserOperationStruct,\n overrides\n );\n this._shouldConsume = true;\n return result;\n };\n\n private _runMiddlewareStack = async (\n uo: UserOperationStruct,\n overrides?: UserOperationOverrides\n ): Promise<UserOperationStruct> => {\n const result = await asyncPipe(\n this.dummyPaymasterDataMiddleware,\n this.feeDataGetter,\n this.paymasterDataMiddleware,\n this.gasEstimator,\n this.customMiddleware ?? noOpMiddleware,\n async (struct) => ({ ...struct, ...overrides })\n )(uo);\n\n return deepHexlify(await resolveProperties<UserOperationStruct>(result));\n };\n\n sendUserOperation = async <\n T extends UserOperationCallData | BatchUserOperationCallData\n >(\n data: T,\n overrides?: UserOperationOverrides,\n operation: UserOpDataOperationTypes<T> = Operation.Call as UserOpDataOperationTypes<T>\n ): Promise<SendUserOperationResult> => {\n if (!this._shouldConsume)\n throw new Error(\n \"Cannot send user operation while building user operation\"\n );\n if (!isKernelAccount(this.account)) {\n throw new Error(\"account not connected!\");\n }\n if (!this.account.validator) {\n throw new Error(\"validator not connected!\");\n }\n\n let callData: BytesLike = \"0x\";\n\n if (Array.isArray(data)) {\n if (operation === Operation.Call) {\n callData = await this.account.encodeBatchExecute(data);\n } else {\n throw InvalidOperation;\n }\n } else if (isKernelAccount(this.account)) {\n if (operation === Operation.DelegateCall) {\n callData = await this.account.encodeExecuteDelegate(\n data.target,\n data.value ?? 0n,\n data.data\n );\n } else if (operation === Operation.Call) {\n callData = await this.account.encodeExecute(\n data.target,\n data.value ?? 0n,\n data.data\n );\n } else {\n throw InvalidOperation;\n }\n } else {\n throw InvalidOperation;\n }\n\n const initCode = await this.account.getInitCode();\n let hash: string = \"\";\n let i = 0;\n const nonce = await this.account.getNonce();\n let uoStruct: UserOperationStruct;\n let request: UserOperationStruct;\n let maxFeePerGas, maxPriorityFeePerGas;\n do {\n uoStruct = await asyncPipe(\n this.dummyPaymasterDataMiddleware,\n this.feeDataGetter,\n this.paymasterDataMiddleware,\n this.gasEstimator,\n this.customMiddleware ?? noOpMiddleware,\n async (struct) => ({ ...struct, ...overrides })\n )({\n initCode,\n sender: this.getAddress(),\n nonce,\n callData,\n signature: await this.account\n .getValidator()\n .getDynamicDummySignature(await this.getAddress(), callData as Hex),\n maxFeePerGas,\n maxPriorityFeePerGas,\n } as UserOperationStruct);\n request = deepHexlify(await resolveProperties(uoStruct));\n\n if (!isValidRequest(request)) {\n // this pretty prints the uo\n throw new Error(\n `Request is missing parameters. All properties on UserOperationStruct must be set. uo: ${JSON.stringify(\n request,\n null,\n 2\n )}`\n );\n }\n\n await this.account.approvePlugin();\n\n request.signature = await this.account.validator.getSignature(request);\n try {\n hash = await this.rpcClient.sendUserOperation(\n request,\n this.entryPointAddress\n );\n } catch (error: any) {\n if (this.isReplacementOpError(error) && i++ < this.sendTxMaxRetries) {\n maxFeePerGas = (BigInt(request.maxFeePerGas) * 113n) / 100n;\n maxPriorityFeePerGas =\n (BigInt(request.maxPriorityFeePerGas) * 113n) / 100n;\n\n console.log(\n `After ${\n this.sendTxRetryIntervalMs / 60000\n } minutes, resending tx with Increased Gas fees: maxFeePerGas: ${maxFeePerGas}, maxPriorityFeePerGas: ${maxPriorityFeePerGas}`\n );\n await new Promise((resolve) =>\n setTimeout(resolve, this.sendTxRetryIntervalMs)\n );\n continue;\n }\n throw this.unwrapError(error);\n }\n } while (hash === \"\");\n\n return {\n hash,\n request,\n };\n };\n\n isReplacementOpError(errorIn: any): boolean {\n if (errorIn.cause != null) {\n const failedOpMessage: string | undefined = errorIn?.cause?.message;\n return (\n (failedOpMessage?.includes(\n \"replacement op must increase maxFeePerGas and MaxPriorityFeePerGas\"\n ) ||\n failedOpMessage?.match(/.*replacement.*underpriced.*/) !== null) ??\n false\n );\n }\n return false;\n }\n\n unwrapError(errorIn: any): Error {\n if (errorIn?.cause != null) {\n let paymasterInfo: string = \"\";\n let failedOpMessage: string | undefined = errorIn?.cause?.message;\n if (failedOpMessage?.includes(\"FailedOp\") === true) {\n // TODO: better error extraction methods will be needed\n const matched = failedOpMessage.match(/FailedOp\\((.*)\\)/);\n if (matched != null) {\n const split = matched[1].split(\",\");\n paymasterInfo = `(paymaster address: ${split[1]})`;\n failedOpMessage = split[2];\n }\n }\n const error = new Error(\n `The bundler has failed to include UserOperation in a batch: ${failedOpMessage} ${paymasterInfo}`\n );\n error.stack = errorIn.stack;\n return error;\n }\n return errorIn;\n }\n\n waitForUserOperationTransaction = async (hash: Hash): Promise<Hash> => {\n let blockNumber = await this.rpcClient.getBlockNumber();\n for (let i = 0; i < this._txMaxRetries; i++) {\n if (this.bundlerProvider === \"GELATO\") {\n const receipt = await this.getUserOperationReceipt(\n hash as `0x${string}`\n )\n // TODO: should maybe log the error?\n .catch(() => null);\n if (receipt) {\n return this.getTransaction(receipt.receipt.transactionHash).then(\n (x) => x.hash\n );\n }\n } else {\n const logs = await this.rpcClient.getLogs({\n address: ENTRYPOINT_ADDRESS,\n event: getAbiItem({ abi: EntryPointAbi, name: \"UserOperationEvent\" }),\n args: { userOpHash: hash },\n fromBlock: blockNumber - 100n,\n });\n if (logs.length) {\n return logs[0].transactionHash;\n }\n }\n await new Promise((resolve) =>\n setTimeout(resolve, this._txRetryIntervalMs)\n );\n }\n\n throw new Error(\"Failed to find transaction for User Operation\");\n };\n\n getAccount: () => KernelSmartContractAccount = () => {\n if (!isKernelAccount(this.account)) {\n throw new Error(\"account not connected!\");\n }\n return this.account;\n };\n\n dummyPaymasterDataMiddleware: AccountMiddlewareFn = async (\n struct: UserOperationStruct\n ): Promise<UserOperationStruct> => {\n struct.paymasterAndData = \"0x\";\n return struct;\n };\n\n withZeroDevPaymasterAndData(config: PaymasterConfig<PaymasterPolicy>) {\n if (!this.isConnected()) {\n throw new Error(\n \"ZeroDevProvider: account is not set, did you call `connect` first?\"\n );\n }\n\n return withZeroDevPaymasterAndData(this, config);\n }\n\n request: (args: { method: string; params?: any[] }) => Promise<any> = async (\n args\n ) => {\n const { method, params } = args;\n switch (method) {\n case \"eth_chainId\":\n return this.chain.id;\n case \"eth_sendTransaction\":\n const [tx] = params as [RpcTransactionRequest];\n return this.sendTransaction(tx);\n case \"eth_signTypedData_v4\":\n //@ts-expect-error\n return this.signTypedData(JSON.parse(params[1]));\n case \"personal_sign\":\n if (!this.account) {\n throw new Error(\"account not connected!\");\n }\n const [data, address] = params!;\n if (address.toLowerCase() !== (await this.getAddress()).toLowerCase()) {\n throw new Error(\n \"cannot sign for address that is not the current account\"\n );\n }\n // @ts-ignore\n return this.account.signMessageWith6492(data);\n default:\n // @ts-ignore\n return this.rpcClient.request(args);\n }\n };\n}\n"]}
|
|
1
|
+
{"version":3,"file":"provider.js","sourceRoot":"","sources":["../../../src/kernel-zerodev/provider.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,OAAO,EAOP,UAAU,GACX,MAAM,MAAM,CAAC;AACd,OAAO,EACL,WAAW,EACX,iBAAiB,EAKjB,SAAS,EACT,cAAc,EAGd,oBAAoB,EAGpB,aAAa,GACd,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EACL,WAAW,EACX,2BAA2B,EAC3B,iCAAiC,EACjC,kBAAkB,EAClB,4BAA4B,GAC7B,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAE,0BAA0B,EAAE,eAAe,EAAE,MAAM,cAAc,CAAC;AAC3E,OAAO,EAAE,uBAAuB,EAAE,MAAM,+BAA+B,CAAC;AACxE,OAAO,EAAE,cAAc,EAAE,MAAM,0BAA0B,CAAC;AAC1D,OAAO,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAC/C,OAAO,EAAE,2BAA2B,EAAE,MAAM,2BAA2B,CAAC;AACxE,OAAO,EAAE,gCAAgC,EAAE,MAAM,2BAA2B,CAAC;AAM7E,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAoBtC,MAAM,CAAN,IAAY,SAGX;AAHD,WAAY,SAAS;IACnB,yCAAQ,CAAA;IACR,yDAAgB,CAAA;AAClB,CAAC,EAHW,SAAS,KAAT,SAAS,QAGpB;AAQD,MAAM,OAAO,eAAgB,SAAQ,oBAAmC;IAUtE,YAAY,EACV,SAAS,EACT,KAAK,EACL,iBAAiB,GAAG,kBAAkB,EACtC,MAAM,GAAG,WAAW,EACpB,OAAO,EACP,eAAe,EACf,IAA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;oBACnB,MAAM,KAAK,GAAG,OAAO,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;oBACpC,aAAa,GAAG,uBAAuB,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC;oBACnD,eAAe,GAAG,KAAK,CAAC,CAAC,CAAC,CAAC;iBAC5B;aACF;YACD,MAAM,KAAK,GAAG,IAAI,KAAK,CACrB,+DAA+D,eAAe,IAAI,aAAa,EAAE,CAClG,CAAC;YACF,KAAK,CAAC,KAAK,GAAG,OAAO,CAAC,KAAK,CAAC;YAC5B,OAAO,KAAK,CAAC;SACd;QACD,OAAO,OAAO,CAAC;IACjB,CAAC;IAiDD,2BAA2B,CAAC,MAAwC;QAClE,IAAI,CAAC,IAAI,CAAC,WAAW,EAAE,EAAE;YACvB,MAAM,IAAI,KAAK,CACb,oEAAoE,CACrE,CAAC;SACH;QAED,OAAO,2BAA2B,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC;IACnD,CAAC;CAgCF","sourcesContent":["import {\n fromHex,\n type Address,\n type Chain,\n type Hash,\n type Hex,\n type HttpTransport,\n type RpcTransactionRequest,\n getAbiItem,\n} from \"viem\";\nimport {\n deepHexlify,\n resolveProperties,\n type SmartAccountProviderOpts,\n type UserOperationCallData,\n type BatchUserOperationCallData,\n type SendUserOperationResult,\n asyncPipe,\n noOpMiddleware,\n type UserOperationStruct,\n type BytesLike,\n SmartAccountProvider,\n type AccountMiddlewareFn,\n type UserOperationOverrides,\n EntryPointAbi,\n} from \"@alchemy/aa-core\";\nimport {\n BUNDLER_URL,\n DEFAULT_SEND_TX_MAX_RETRIES,\n DEFAULT_SEND_TX_RETRY_INTERVAL_MS,\n ENTRYPOINT_ADDRESS,\n minPriorityFeePerBidDefaults,\n} from \"./constants.js\";\nimport { KernelSmartContractAccount, isKernelAccount } from \"./account.js\";\nimport { withZeroDevGasEstimator } from \"./middleware/gas-estimator.js\";\nimport { isValidRequest } from \"./utils/ERC4337-utils.js\";\nimport { InvalidOperation } from \"./errors.js\";\nimport { withZeroDevPaymasterAndData } from \"./middleware/paymaster.js\";\nimport { createZeroDevPublicErc4337Client } from \"./client/create-client.js\";\nimport type {\n PaymasterAndBundlerProviders,\n PaymasterConfig,\n PaymasterPolicy,\n} from \"./paymaster/types.js\";\nimport { getChain } from \"./utils.js\";\n\nexport type FeeOptions = {\n maxFeePerGasBufferPercentage?: number;\n maxPriorityFeePerGasBufferPercentage?: number;\n};\nexport type ZeroDevProviderConfig = {\n projectId: string;\n chain: Chain | number;\n entryPointAddress?: Address;\n rpcUrl?: string;\n account?: KernelSmartContractAccount;\n bundlerProvider?: PaymasterAndBundlerProviders;\n opts?: SmartAccountProviderOpts & {\n sendTxMaxRetries?: number;\n sendTxRetryIntervalMs?: number;\n feeOptions?: FeeOptions;\n };\n};\n\nexport enum Operation {\n Call = 0,\n DelegateCall = 1,\n}\n\ntype UserOpDataOperationTypes<T> = T extends UserOperationCallData\n ? Operation.Call | Operation.DelegateCall\n : T extends BatchUserOperationCallData\n ? Operation.Call\n : never;\n\nexport class ZeroDevProvider extends SmartAccountProvider<HttpTransport> {\n protected projectId: string;\n protected sendTxMaxRetries: number;\n protected sendTxRetryIntervalMs: number;\n readonly bundlerProvider?: PaymasterAndBundlerProviders;\n private _txMaxRetries: number;\n private _txRetryIntervalMs: number;\n private _shouldConsume: boolean = true;\n public feeOptions: Required<FeeOptions>;\n\n constructor({\n projectId,\n chain,\n entryPointAddress = ENTRYPOINT_ADDRESS,\n rpcUrl = BUNDLER_URL,\n account,\n bundlerProvider,\n opts,\n }: ZeroDevProviderConfig) {\n const _chain = typeof chain === \"number\" ? getChain(chain) : chain;\n const rpcClient = createZeroDevPublicErc4337Client({\n chain: _chain,\n rpcUrl,\n projectId,\n bundlerProvider,\n });\n\n super(rpcClient, entryPointAddress, _chain, account, {\n ...opts,\n txMaxRetries: opts?.txMaxRetries ?? 20,\n txRetryIntervalMs: opts?.txRetryIntervalMs ?? 10000,\n minPriorityFeePerBid:\n opts?.minPriorityFeePerBid ??\n minPriorityFeePerBidDefaults.get(_chain.id),\n });\n\n this.feeOptions = {\n maxFeePerGasBufferPercentage:\n opts?.feeOptions?.maxFeePerGasBufferPercentage ?? 0,\n maxPriorityFeePerGasBufferPercentage:\n opts?.feeOptions?.maxPriorityFeePerGasBufferPercentage ?? 13,\n };\n this._txMaxRetries = opts?.txMaxRetries ?? 20;\n this._txRetryIntervalMs = opts?.txRetryIntervalMs ?? 5000;\n this.bundlerProvider = bundlerProvider;\n this.projectId = projectId;\n this.sendTxMaxRetries =\n opts?.sendTxMaxRetries ?? DEFAULT_SEND_TX_MAX_RETRIES;\n this.sendTxRetryIntervalMs =\n opts?.sendTxRetryIntervalMs ?? DEFAULT_SEND_TX_RETRY_INTERVAL_MS;\n\n withZeroDevGasEstimator(this);\n }\n\n getProjectId = (): string => this.projectId;\n\n shouldConsume = (): boolean => this._shouldConsume;\n\n sendTransaction = async (\n request: RpcTransactionRequest,\n operation: UserOpDataOperationTypes<UserOperationCallData> = Operation.Call\n ): Promise<Hash> => {\n if (!request.to) {\n throw new Error(\"transaction is missing to address\");\n }\n\n const overrides: UserOperationOverrides = {};\n if (request.maxFeePerGas) {\n overrides.maxFeePerGas = request.maxFeePerGas;\n }\n if (request.maxPriorityFeePerGas) {\n overrides.maxPriorityFeePerGas = request.maxPriorityFeePerGas;\n }\n\n const { hash } = await this.sendUserOperation(\n {\n target: request.to,\n data: request.data ?? \"0x\",\n value: request.value ? fromHex(request.value, \"bigint\") : 0n,\n },\n overrides,\n operation\n );\n\n return await this.waitForUserOperationTransaction(hash as Hash);\n };\n\n buildUserOperation = async <\n T extends UserOperationCallData | BatchUserOperationCallData\n >(\n data: T,\n overrides?: UserOperationOverrides,\n operation: UserOpDataOperationTypes<T> = Operation.Call as UserOpDataOperationTypes<T>\n ): Promise<UserOperationStruct> => {\n this._shouldConsume = false;\n if (!isKernelAccount(this.account)) {\n throw new Error(\"account not connected!\");\n }\n if (!this.account.validator) {\n throw new Error(\"validator not connected!\");\n }\n\n let callData: BytesLike = \"0x\";\n\n if (Array.isArray(data)) {\n if (operation === Operation.Call) {\n callData = await this.account.encodeBatchExecute(data);\n } else {\n throw InvalidOperation;\n }\n } else if (isKernelAccount(this.account)) {\n if (operation === Operation.DelegateCall) {\n callData = await this.account.encodeExecuteDelegate(\n data.target,\n data.value ?? 0n,\n data.data\n );\n } else if (operation === Operation.Call) {\n callData = await this.account.encodeExecute(\n data.target,\n data.value ?? 0n,\n data.data\n );\n } else {\n throw InvalidOperation;\n }\n } else {\n throw InvalidOperation;\n }\n\n const initCode = await this.account.getInitCode();\n const nonce = await this.account.getNonce();\n const result = await this._runMiddlewareStack(\n {\n initCode,\n sender: this.getAddress(),\n nonce,\n callData,\n signature: await this.account\n .getValidator()\n .getDynamicDummySignature(await this.getAddress(), callData as Hex),\n } as UserOperationStruct,\n overrides\n );\n this._shouldConsume = true;\n return result;\n };\n\n private _runMiddlewareStack = async (\n uo: UserOperationStruct,\n overrides?: UserOperationOverrides\n ): Promise<UserOperationStruct> => {\n const result = await asyncPipe(\n this.dummyPaymasterDataMiddleware,\n this.feeDataGetter,\n this.paymasterDataMiddleware,\n this.gasEstimator,\n this.customMiddleware ?? noOpMiddleware,\n async (struct) => ({ ...struct, ...overrides })\n )(uo);\n\n return deepHexlify(await resolveProperties<UserOperationStruct>(result));\n };\n\n sendUserOperation = async <\n T extends UserOperationCallData | BatchUserOperationCallData\n >(\n data: T,\n overrides?: UserOperationOverrides,\n operation: UserOpDataOperationTypes<T> = Operation.Call as UserOpDataOperationTypes<T>\n ): Promise<SendUserOperationResult> => {\n if (!this._shouldConsume)\n throw new Error(\n \"Cannot send user operation while building user operation\"\n );\n if (!isKernelAccount(this.account)) {\n throw new Error(\"account not connected!\");\n }\n if (!this.account.validator) {\n throw new Error(\"validator not connected!\");\n }\n\n let callData: BytesLike = \"0x\";\n\n if (Array.isArray(data)) {\n if (operation === Operation.Call) {\n callData = await this.account.encodeBatchExecute(data);\n } else {\n throw InvalidOperation;\n }\n } else if (isKernelAccount(this.account)) {\n if (operation === Operation.DelegateCall) {\n callData = await this.account.encodeExecuteDelegate(\n data.target,\n data.value ?? 0n,\n data.data\n );\n } else if (operation === Operation.Call) {\n callData = await this.account.encodeExecute(\n data.target,\n data.value ?? 0n,\n data.data\n );\n } else {\n throw InvalidOperation;\n }\n } else {\n throw InvalidOperation;\n }\n\n const initCode = await this.account.getInitCode();\n let hash: string = \"\";\n let i = 0;\n const nonce = await this.account.getNonce();\n let uoStruct: UserOperationStruct;\n let request: UserOperationStruct;\n let maxFeePerGas, maxPriorityFeePerGas;\n do {\n uoStruct = await asyncPipe(\n this.dummyPaymasterDataMiddleware,\n this.feeDataGetter,\n this.paymasterDataMiddleware,\n this.gasEstimator,\n this.customMiddleware ?? noOpMiddleware,\n async (struct) => ({ ...struct, ...overrides })\n )({\n initCode,\n sender: this.getAddress(),\n nonce,\n callData,\n signature: await this.account\n .getValidator()\n .getDynamicDummySignature(await this.getAddress(), callData as Hex),\n maxFeePerGas,\n maxPriorityFeePerGas,\n } as UserOperationStruct);\n request = deepHexlify(await resolveProperties(uoStruct));\n\n if (!isValidRequest(request)) {\n // this pretty prints the uo\n throw new Error(\n `Request is missing parameters. All properties on UserOperationStruct must be set. uo: ${JSON.stringify(\n request,\n null,\n 2\n )}`\n );\n }\n\n await this.account.approvePlugin();\n\n request.signature = await this.account.validator.getSignature(request);\n try {\n hash = await this.rpcClient.sendUserOperation(\n request,\n this.entryPointAddress\n );\n } catch (error: any) {\n if (this.isReplacementOpError(error) && i++ < this.sendTxMaxRetries) {\n maxFeePerGas = (BigInt(request.maxFeePerGas) * 113n) / 100n;\n maxPriorityFeePerGas =\n (BigInt(request.maxPriorityFeePerGas) * 113n) / 100n;\n\n console.log(\n `After ${\n this.sendTxRetryIntervalMs / 60000\n } minutes, resending tx with Increased Gas fees: maxFeePerGas: ${maxFeePerGas}, maxPriorityFeePerGas: ${maxPriorityFeePerGas}`\n );\n await new Promise((resolve) =>\n setTimeout(resolve, this.sendTxRetryIntervalMs)\n );\n continue;\n }\n throw this.unwrapError(error);\n }\n } while (hash === \"\");\n\n return {\n hash,\n request,\n };\n };\n\n isReplacementOpError(errorIn: any): boolean {\n if (errorIn.cause != null) {\n const failedOpMessage: string | undefined = errorIn?.cause?.message;\n return (\n (failedOpMessage?.includes(\n \"replacement op must increase maxFeePerGas and MaxPriorityFeePerGas\"\n ) ||\n failedOpMessage?.match(/.*replacement.*underpriced.*/) !== null) ??\n false\n );\n }\n return false;\n }\n\n unwrapError(errorIn: any): Error {\n if (errorIn?.cause != null) {\n let paymasterInfo: string = \"\";\n let failedOpMessage: string | undefined = errorIn?.cause?.message;\n if (failedOpMessage?.includes(\"FailedOp\") === true) {\n // TODO: better error extraction methods will be needed\n const matched = failedOpMessage.match(/FailedOp\\((.*)\\)/);\n if (matched != null) {\n const split = matched[1].split(\",\");\n paymasterInfo = `(paymaster address: ${split[1]})`;\n failedOpMessage = split[2];\n }\n }\n const error = new Error(\n `The bundler has failed to include UserOperation in a batch: ${failedOpMessage} ${paymasterInfo}`\n );\n error.stack = errorIn.stack;\n return error;\n }\n return errorIn;\n }\n\n waitForUserOperationTransaction = async (hash: Hash): Promise<Hash> => {\n let blockNumber = await this.rpcClient.getBlockNumber();\n for (let i = 0; i < this._txMaxRetries; i++) {\n if (this.bundlerProvider === \"GELATO\") {\n const receipt = await this.getUserOperationReceipt(\n hash as `0x${string}`\n )\n // TODO: should maybe log the error?\n .catch(() => null);\n if (receipt) {\n return this.getTransaction(receipt.receipt.transactionHash).then(\n (x) => x.hash\n );\n }\n } else {\n const logs = await this.rpcClient.getLogs({\n address: ENTRYPOINT_ADDRESS,\n event: getAbiItem({ abi: EntryPointAbi, name: \"UserOperationEvent\" }),\n args: { userOpHash: hash },\n fromBlock: blockNumber - 100n,\n });\n if (logs.length) {\n return logs[0].transactionHash;\n }\n }\n await new Promise((resolve) =>\n setTimeout(resolve, this._txRetryIntervalMs)\n );\n }\n\n throw new Error(\"Failed to find transaction for User Operation\");\n };\n\n getAccount: () => KernelSmartContractAccount = () => {\n if (!isKernelAccount(this.account)) {\n throw new Error(\"account not connected!\");\n }\n return this.account;\n };\n\n dummyPaymasterDataMiddleware: AccountMiddlewareFn = async (\n struct: UserOperationStruct\n ): Promise<UserOperationStruct> => {\n struct.paymasterAndData = \"0x\";\n return struct;\n };\n\n withZeroDevPaymasterAndData(config: PaymasterConfig<PaymasterPolicy>) {\n if (!this.isConnected()) {\n throw new Error(\n \"ZeroDevProvider: account is not set, did you call `connect` first?\"\n );\n }\n\n return withZeroDevPaymasterAndData(this, config);\n }\n\n request: (args: { method: string; params?: any[] }) => Promise<any> = async (\n args\n ) => {\n const { method, params } = args;\n switch (method) {\n case \"eth_chainId\":\n return this.chain.id;\n case \"eth_sendTransaction\":\n const [tx] = params as [RpcTransactionRequest];\n return this.sendTransaction(tx);\n case \"eth_signTypedData_v4\":\n //@ts-expect-error\n return this.signTypedData(JSON.parse(params[1]));\n case \"personal_sign\":\n if (!this.account) {\n throw new Error(\"account not connected!\");\n }\n const [data, address] = params!;\n if (address.toLowerCase() !== (await this.getAddress()).toLowerCase()) {\n throw new Error(\n \"cannot sign for address that is not the current account\"\n );\n }\n // @ts-ignore\n return this.account.signMessageWith6492(data);\n default:\n // @ts-ignore\n return this.rpcClient.request(args);\n }\n };\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;;;
|
|
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"}
|
|
@@ -2,6 +2,10 @@ import { type Address, type Chain, type Hash, type HttpTransport, type RpcTransa
|
|
|
2
2
|
import { type SmartAccountProviderOpts, type UserOperationCallData, type BatchUserOperationCallData, type SendUserOperationResult, type UserOperationStruct, SmartAccountProvider, type AccountMiddlewareFn, type UserOperationOverrides } from "@alchemy/aa-core";
|
|
3
3
|
import { KernelSmartContractAccount } from "./account.js";
|
|
4
4
|
import type { PaymasterAndBundlerProviders, PaymasterConfig, PaymasterPolicy } from "./paymaster/types.js";
|
|
5
|
+
export type FeeOptions = {
|
|
6
|
+
maxFeePerGasBufferPercentage?: number;
|
|
7
|
+
maxPriorityFeePerGasBufferPercentage?: number;
|
|
8
|
+
};
|
|
5
9
|
export type ZeroDevProviderConfig = {
|
|
6
10
|
projectId: string;
|
|
7
11
|
chain: Chain | number;
|
|
@@ -12,6 +16,7 @@ export type ZeroDevProviderConfig = {
|
|
|
12
16
|
opts?: SmartAccountProviderOpts & {
|
|
13
17
|
sendTxMaxRetries?: number;
|
|
14
18
|
sendTxRetryIntervalMs?: number;
|
|
19
|
+
feeOptions?: FeeOptions;
|
|
15
20
|
};
|
|
16
21
|
};
|
|
17
22
|
export declare enum Operation {
|
|
@@ -27,6 +32,7 @@ export declare class ZeroDevProvider extends SmartAccountProvider<HttpTransport>
|
|
|
27
32
|
private _txMaxRetries;
|
|
28
33
|
private _txRetryIntervalMs;
|
|
29
34
|
private _shouldConsume;
|
|
35
|
+
feeOptions: Required<FeeOptions>;
|
|
30
36
|
constructor({ projectId, chain, entryPointAddress, rpcUrl, account, bundlerProvider, opts, }: ZeroDevProviderConfig);
|
|
31
37
|
getProjectId: () => string;
|
|
32
38
|
shouldConsume: () => boolean;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"provider.d.ts","sourceRoot":"","sources":["../../../src/kernel-zerodev/provider.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,KAAK,OAAO,EACZ,KAAK,KAAK,EACV,KAAK,IAAI,EAET,KAAK,aAAa,EAClB,KAAK,qBAAqB,EAE3B,MAAM,MAAM,CAAC;AACd,OAAO,EAGL,KAAK,wBAAwB,EAC7B,KAAK,qBAAqB,EAC1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EACf,IAAI,GACL,EAAE,qBAAqB;IAoCxB,YAAY,QAAO,MAAM,CAAmB;IAE5C,aAAa,QAAO,OAAO,CAAwB;IAEnD,eAAe,YACJ,qBAAqB,cACnB,yBAAyB,qBAAqB,CAAC,KACzD,QAAQ,IAAI,CAAC,CAwBd;IAEF,kBAAkB,sFAIJ,sBAAsB,8CAEjC,QAAQ,mBAAmB,CAAC,CAqD7B;IAEF,OAAO,CAAC,mBAAmB,CAczB;IAEF,iBAAiB,sFAIH,sBAAsB,8CAEjC,QAAQ,uBAAuB,CAAC,CA+GjC;IAEF,oBAAoB,CAAC,OAAO,EAAE,GAAG,GAAG,OAAO;IAc3C,WAAW,CAAC,OAAO,EAAE,GAAG,GAAG,KAAK;IAsBhC,+BAA+B,SAAgB,IAAI,KAAG,QAAQ,IAAI,CAAC,CA+BjE;IAEF,UAAU,EAAE,MAAM,0BAA0B,CAK1C;IAEF,4BAA4B,EAAE,mBAAmB,CAK/C;IAEF,2BAA2B,CAAC,MAAM,EAAE,eAAe,CAAC,eAAe,CAAC;;;IAUpE,OAAO,EAAE,CAAC,IAAI,EAAE;QAAE,MAAM,EAAE,MAAM,CAAC;QAAC,MAAM,CAAC,EAAE,GAAG,EAAE,CAAA;KAAE,KAAK,OAAO,CAAC,GAAG,CAAC,CA6BjE;CACH"}
|
package/package.json
CHANGED
|
@@ -153,15 +153,21 @@ export const eip1559GasPrice = async (provider: ZeroDevProvider) => {
|
|
|
153
153
|
}
|
|
154
154
|
|
|
155
155
|
const tip = BigInt(fee);
|
|
156
|
-
const buffer =
|
|
156
|
+
const buffer =
|
|
157
|
+
(tip / 100n) *
|
|
158
|
+
BigInt(provider.feeOptions.maxPriorityFeePerGasBufferPercentage);
|
|
157
159
|
let maxPriorityFeePerGas = tip + buffer;
|
|
158
160
|
maxPriorityFeePerGas =
|
|
159
161
|
maxPriorityFeePerGas < provider.minPriorityFeePerBid
|
|
160
162
|
? provider.minPriorityFeePerBid
|
|
161
163
|
: maxPriorityFeePerGas;
|
|
162
|
-
const maxFeePerGas =
|
|
163
|
-
|
|
164
|
-
|
|
164
|
+
const maxFeePerGas =
|
|
165
|
+
((block.baseFeePerGas
|
|
166
|
+
? BigInt(block.baseFeePerGas) * 2n + maxPriorityFeePerGas
|
|
167
|
+
: maxPriorityFeePerGas) *
|
|
168
|
+
(BigInt(100) +
|
|
169
|
+
BigInt(provider.feeOptions.maxFeePerGasBufferPercentage))) /
|
|
170
|
+
100n;
|
|
165
171
|
|
|
166
172
|
return { maxFeePerGas, maxPriorityFeePerGas };
|
|
167
173
|
};
|
|
@@ -44,6 +44,10 @@ import type {
|
|
|
44
44
|
} from "./paymaster/types.js";
|
|
45
45
|
import { getChain } from "./utils.js";
|
|
46
46
|
|
|
47
|
+
export type FeeOptions = {
|
|
48
|
+
maxFeePerGasBufferPercentage?: number;
|
|
49
|
+
maxPriorityFeePerGasBufferPercentage?: number;
|
|
50
|
+
};
|
|
47
51
|
export type ZeroDevProviderConfig = {
|
|
48
52
|
projectId: string;
|
|
49
53
|
chain: Chain | number;
|
|
@@ -54,6 +58,7 @@ export type ZeroDevProviderConfig = {
|
|
|
54
58
|
opts?: SmartAccountProviderOpts & {
|
|
55
59
|
sendTxMaxRetries?: number;
|
|
56
60
|
sendTxRetryIntervalMs?: number;
|
|
61
|
+
feeOptions?: FeeOptions;
|
|
57
62
|
};
|
|
58
63
|
};
|
|
59
64
|
|
|
@@ -76,6 +81,7 @@ export class ZeroDevProvider extends SmartAccountProvider<HttpTransport> {
|
|
|
76
81
|
private _txMaxRetries: number;
|
|
77
82
|
private _txRetryIntervalMs: number;
|
|
78
83
|
private _shouldConsume: boolean = true;
|
|
84
|
+
public feeOptions: Required<FeeOptions>;
|
|
79
85
|
|
|
80
86
|
constructor({
|
|
81
87
|
projectId,
|
|
@@ -103,6 +109,12 @@ export class ZeroDevProvider extends SmartAccountProvider<HttpTransport> {
|
|
|
103
109
|
minPriorityFeePerBidDefaults.get(_chain.id),
|
|
104
110
|
});
|
|
105
111
|
|
|
112
|
+
this.feeOptions = {
|
|
113
|
+
maxFeePerGasBufferPercentage:
|
|
114
|
+
opts?.feeOptions?.maxFeePerGasBufferPercentage ?? 0,
|
|
115
|
+
maxPriorityFeePerGasBufferPercentage:
|
|
116
|
+
opts?.feeOptions?.maxPriorityFeePerGasBufferPercentage ?? 13,
|
|
117
|
+
};
|
|
106
118
|
this._txMaxRetries = opts?.txMaxRetries ?? 20;
|
|
107
119
|
this._txRetryIntervalMs = opts?.txRetryIntervalMs ?? 5000;
|
|
108
120
|
this.bundlerProvider = bundlerProvider;
|