@zerodev/sdk 4.2.2 → 4.2.3
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/client/create-client.js +1 -0
- package/dist/cjs/kernel-zerodev/client/create-client.js.map +1 -1
- package/dist/cjs/kernel-zerodev/constants.js +1 -1
- package/dist/cjs/kernel-zerodev/constants.js.map +1 -1
- package/dist/cjs/kernel-zerodev/middleware/gas-estimator.d.ts +4 -0
- package/dist/cjs/kernel-zerodev/middleware/gas-estimator.js +15 -7
- package/dist/cjs/kernel-zerodev/middleware/gas-estimator.js.map +1 -1
- package/dist/esm/kernel-zerodev/client/create-client.js +1 -0
- package/dist/esm/kernel-zerodev/client/create-client.js.map +1 -1
- package/dist/esm/kernel-zerodev/constants.js +1 -1
- package/dist/esm/kernel-zerodev/constants.js.map +1 -1
- package/dist/esm/kernel-zerodev/middleware/gas-estimator.d.ts +4 -0
- package/dist/esm/kernel-zerodev/middleware/gas-estimator.js +15 -6
- package/dist/esm/kernel-zerodev/middleware/gas-estimator.js.map +1 -1
- package/dist/types/kernel-zerodev/client/create-client.d.ts.map +1 -1
- package/dist/types/kernel-zerodev/middleware/gas-estimator.d.ts +4 -0
- package/dist/types/kernel-zerodev/middleware/gas-estimator.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/kernel-zerodev/client/create-client.ts +1 -0
- package/src/kernel-zerodev/constants.ts +1 -1
- package/src/kernel-zerodev/middleware/gas-estimator.ts +21 -7
|
@@ -13,6 +13,7 @@ function isMethodInErc4337RpcSchema(variable) {
|
|
|
13
13
|
"eth_supportedEntryPoints",
|
|
14
14
|
"eth_maxPriorityFeePerGas",
|
|
15
15
|
"rundler_maxPriorityFeePerGas",
|
|
16
|
+
"pimlico_getUserOperationGasPrice",
|
|
16
17
|
].includes(variable);
|
|
17
18
|
}
|
|
18
19
|
const createZeroDevPublicErc4337Client = ({ chain, rpcUrl, projectId, bundlerProvider, }) => {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"create-client.js","sourceRoot":"","sources":["../../../../src/kernel-zerodev/client/create-client.ts"],"names":[],"mappings":";;;AAAA,8CAK0B;AAC1B,+BAAoE;AACpE,kDAAgE;AAYhE,SAAS,0BAA0B,CACjC,QAAgB;IAEhB,OACE;QACE,uBAAuB;QACvB,8BAA8B;QAC9B,6BAA6B;QAC7B,4BAA4B;QAC5B,0BAA0B;QAC1B,0BAA0B;QAC1B,8BAA8B;
|
|
1
|
+
{"version":3,"file":"create-client.js","sourceRoot":"","sources":["../../../../src/kernel-zerodev/client/create-client.ts"],"names":[],"mappings":";;;AAAA,8CAK0B;AAC1B,+BAAoE;AACpE,kDAAgE;AAYhE,SAAS,0BAA0B,CACjC,QAAgB;IAEhB,OACE;QACE,uBAAuB;QACvB,8BAA8B;QAC9B,6BAA6B;QAC7B,4BAA4B;QAC5B,0BAA0B;QAC1B,0BAA0B;QAC1B,8BAA8B;QAC9B,kCAAkC;KAErC,CAAC,QAAQ,CAAC,QAAqC,CAAC,CAAC;AACpD,CAAC;AAEM,MAAM,gCAAgC,GAAG,CAAC,EAC/C,KAAK,EACL,MAAM,EACN,SAAS,EACT,eAAe,GACK,EAAsC,EAAE;IAC5D,MAAM,gBAAgB,GAAG,IAAA,WAAI,EAAC,MAAM,EAAE;QACpC,YAAY,EAAE;YAEZ,OAAO,EAAE,MAAM,KAAK,0BAAW,CAAC,CAAC,CAAC,EAAE,SAAS,EAAE,eAAe,EAAE,CAAC,CAAC,CAAC,EAAE;SACtE;QACD,IAAI,EAAE,2BAA2B;QACjC,GAAG,EAAE,2BAA2B;QAChC,UAAU,EAAE,CAAC;QACb,OAAO,EAAE,KAAK;KACf,CAAC,CAAC;IACH,MAAM,eAAe,GAAG,IAAA,WAAI,EAAC,+BAAgB,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC,CAAC;IACzD,IAAI,MAAM,GAAG,IAAA,uCAA6B,EACxC,IAAA,yBAAkB,EAAC;QACjB,KAAK;QACL,SAAS,EAAE,IAAA,aAAM,EAAC;YAChB,KAAK,CAAC,OAAO,CAAC,EAAE,MAAM,EAAE,MAAM,EAAE;gBAC9B,IAAI,QAAQ,CAAC;gBACb,IAAI,0BAA0B,CAAC,MAAM,CAAC,EAAE;oBACtC,QAAQ,GAAG,MAAM,gBAAgB,CAAC,EAAE,KAAK,EAAE,CAAC,CAAC,OAAO,CAAC;wBACnD,MAAM;wBACN,MAAM;qBACA,CAAC,CAAC;iBACX;qBAAM;oBACL,QAAQ,GAAG,MAAM,eAAe,CAAC,EAAE,KAAK,EAAE,CAAC,CAAC,OAAO,CAAC;wBAClD,MAAM;wBACN,MAAM;qBACA,CAAC,CAAC;iBACX;gBACD,OAAO,QAAQ,CAAC;YAClB,CAAC;SACF,CAAC;KACH,CAAC,CACH,CAAC;IAEF,OAAO,MAAuD,CAAC;AACjE,CAAC,CAAC;AAzCW,QAAA,gCAAgC,oCAyC3C","sourcesContent":["import {\n createPublicErc4337FromClient,\n type PublicErc4337Client,\n type Erc337RpcSchema,\n type HttpTransport,\n} from \"@alchemy/aa-core\";\nimport { http, createPublicClient, type Chain, custom } from \"viem\";\nimport { BUNDLER_URL, CHAIN_ID_TO_NODE } from \"../constants.js\";\nimport type { PaymasterAndBundlerProviders } from \"../paymaster/types.js\";\n\ninterface ZeroDevClientConfig {\n chain: Chain;\n projectId: string;\n rpcUrl?: string;\n bundlerProvider?: PaymasterAndBundlerProviders;\n}\n\ntype MethodsOfErc4337RpcSchema = Erc337RpcSchema[number][\"Method\"];\n\nfunction isMethodInErc4337RpcSchema(\n variable: string\n): variable is MethodsOfErc4337RpcSchema {\n return (\n [\n \"eth_sendUserOperation\",\n \"eth_estimateUserOperationGas\",\n \"eth_getUserOperationReceipt\",\n \"eth_getUserOperationByHash\",\n \"eth_supportedEntryPoints\",\n \"eth_maxPriorityFeePerGas\",\n \"rundler_maxPriorityFeePerGas\",\n \"pimlico_getUserOperationGasPrice\",\n ] as const\n ).includes(variable as MethodsOfErc4337RpcSchema);\n}\n\nexport const createZeroDevPublicErc4337Client = ({\n chain,\n rpcUrl,\n projectId,\n bundlerProvider,\n}: ZeroDevClientConfig): PublicErc4337Client<HttpTransport> => {\n const erc4337Transport = http(rpcUrl, {\n fetchOptions: {\n // @ts-ignore\n headers: rpcUrl === BUNDLER_URL ? { projectId, bundlerProvider } : {},\n },\n name: \"Connected bundler network\",\n key: \"connected-bundler-network\",\n retryCount: 0,\n timeout: 35000,\n });\n const publicTransport = http(CHAIN_ID_TO_NODE[chain.id]);\n let client = createPublicErc4337FromClient(\n createPublicClient({\n chain,\n transport: custom({\n async request({ method, params }) {\n let response;\n if (isMethodInErc4337RpcSchema(method)) {\n response = await erc4337Transport({ chain }).request({\n method,\n params,\n } as any);\n } else {\n response = await publicTransport({ chain }).request({\n method,\n params,\n } as any);\n }\n return response;\n },\n }),\n })\n );\n\n return client as unknown as PublicErc4337Client<HttpTransport>;\n};\n"]}
|
|
@@ -68,6 +68,6 @@ exports.CHAIN_ID_TO_NODE = {
|
|
|
68
68
|
10200: "https://nd-810-853-201.p2pify.com/e828b09f0d43591de96c297b3f36fffd",
|
|
69
69
|
59144: `https://linea-mainnet.infura.io/v3/${exports.INFURA_API_KEY}`,
|
|
70
70
|
59140: `https://linea-goerli.infura.io/v3/${exports.INFURA_API_KEY}`,
|
|
71
|
-
204:
|
|
71
|
+
204: "https://opbnb.rpc.thirdweb.com/eed98c1f30120c0508f17c1f01d3102b",
|
|
72
72
|
};
|
|
73
73
|
//# sourceMappingURL=constants.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"constants.js","sourceRoot":"","sources":["../../../src/kernel-zerodev/constants.ts"],"names":[],"mappings":";;;AAAA,+BAA4C;AAE5C,wCAAsC;AAEzB,QAAA,2BAA2B,GAAG,CAAC,CAAC;AAChC,QAAA,iCAAiC,GAAG,KAAK,CAAC;AAC1C,QAAA,WAAW,GAAG,wCAAwC,CAAC;AACvD,QAAA,aAA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,2FAA2F;IAChG,KAAK,EAAE,oEAAoE;IAC3E,KAAK,EAAE,sCAAsC,sBAAc,EAAE;IAC7D,KAAK,EAAE,qCAAqC,sBAAc,EAAE;IAC5D,GAAG,EAAE,iEAAiE;CAEvE,CAAC","sourcesContent":["import { parseUnits, type Hex } from \"viem\";\nimport type { IGasTokenAddresses } from \"./paymaster/types.js\";\nimport { polygon } from \"viem/chains\";\n\nexport const DEFAULT_SEND_TX_MAX_RETRIES = 3;\nexport const DEFAULT_SEND_TX_RETRY_INTERVAL_MS = 60000; // 1 minutes\nexport const BUNDLER_URL = \"https://v0-6-meta-bundler.onrender.com\";\nexport const PAYMASTER_URL =\n \"https://meta-aa-provider.onrender.com/api/v1/paymaster\";\nexport const ENTRYPOINT_ADDRESS: Hex =\n \"0x5FF137D4b0FDCD49DcA30c7CF57E578a026d2789\";\nexport const MULTISEND_ADDR: Hex = \"0x8ae01fcf7c655655ff2c6ef907b8b4718ab4e17c\";\nexport const BACKEND_URL = \"https://backend-vikp.onrender.com\";\nexport const API_URL = \"https://prod-api.zerodev.app\";\nexport const ECDSA_VALIDATOR_ADDRESS =\n \"0xd9AB5096a832b9ce79914329DAEE236f8Eea0390\";\nexport const KERNEL_FACTORY_ADDRESS =\n \"0x5de4839a76cf55d0c90e2061ef4386d962E15ae3\";\nexport const KERNEL_IMPL_ADDRESS = \"0x0DA6a956B9488eD4dd761E59f52FDc6c8068E6B5\";\nexport const KILL_SWITCH_VALIDATOR_ADDRESS =\n \"0x7393A7dA58CCfFb78f52adb09705BE6E20F704BC\";\nexport const KILL_SWITCH_ACTION = \"0x3f38e479304c7F18F988269a1bDa7d646bd48243\";\nexport const DUMMY_ECDSA_SIG =\n \"0xfffffffffffffffffffffffffffffff0000000000000000000000000000000007aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa1c\";\nexport const ERC165_SESSION_KEY_VALIDATOR_ADDRESS =\n \"0xe149290800De29D4b0BF9dB82c508255D81902E6\";\nexport const TOKEN_ACTION = \"0x2087C7FfD0d0DAE80a00EE74325aBF3449e0eaf1\";\nexport const SESSION_KEY_VALIDATOR_ADDRESS =\n \"0x1C1D5b70aD6e0c04366aab100261A6Bcc251EA3f\";\nexport const RECOVERY_VALIDATOR_ADDRESS =\n \"0x4fd47D861c349bD49DC61341a922cb72F9dF7E8d\";\nexport const RECOVERY_ACTION = \"0x2f65dB8039fe5CAEE0a8680D2879deB800F31Ae1\";\nexport const oneAddress = \"0x0000000000000000000000000000000000000001\";\n\nexport const gasTokenChainAddresses: IGasTokenAddresses = {\n USDC: {\n 1: \"0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48\",\n // 5: \"0x2f3A40A3db8a7e3D09B0adfEfbCe4f6F81927557\",\n 137: \"0x2791Bca1f2de4661ED88A30C99A7a9449Aa84174\",\n // 80001: \"\",\n // 420: \"0x7F5c764cBc14f9669B88837ca1490cCa17c31607\",\n 42161: \"0xFF970A61A04b1cA14834A43f5dE4533eBDDB5CC8\",\n // 421613: \"\",\n 43114: \"0xB97EF9Ef8734C71904D8002F8b6Bc66Dd9c48a6E\",\n // 43113: \"\",\n // 56: \"\",\n // 97: \"\"\n },\n PEPE: {\n 1: \"0x6982508145454Ce325dDbE47a25d4ec3d2311933\",\n },\n};\n\nexport const ERC20_APPROVAL_AMOUNT: { [key: string]: bigint } = {\n // ETH\n [gasTokenChainAddresses[\"USDC\"][1]]: parseUnits(\"100\", 6),\n\n // Goerli\n [gasTokenChainAddresses[\"USDC\"][5]]: parseUnits(\"100\", 6),\n\n // Polygon\n [gasTokenChainAddresses[\"USDC\"][137]]: parseUnits(\"10\", 6),\n\n // Arbitrum\n [gasTokenChainAddresses[\"USDC\"][42161]]: parseUnits(\"10\", 6),\n\n // Avalanche\n [gasTokenChainAddresses[\"USDC\"][43114]]: parseUnits(\"10\", 6),\n\n // ETH\n [gasTokenChainAddresses[\"PEPE\"][1]]: parseUnits(\"50000000\", 18),\n\n \"0x3870419Ba2BBf0127060bCB37f69A1b1C090992B\": parseUnits(\"100\", 18),\n};\n\nexport const minPriorityFeePerBidDefaults = new Map<number, bigint>([\n [polygon.id, 30_000_000_000n],\n]);\n\nexport const INFURA_API_KEY = \"f36f7f706a58477884ce6fe89165666c\";\nexport const CHAIN_ID_TO_NODE: { [key: number]: string } = {\n 1: `https://mainnet.infura.io/v3/${INFURA_API_KEY}`,\n 5: `https://goerli.infura.io/v3/${INFURA_API_KEY}`,\n 11155111:\n \"https://fittest-ultra-aura.ethereum-sepolia.quiknode.pro/3893d01b1dd411fdfa9b6dd372dd2b4f69fcf1ea/\",\n 137: `https://polygon-mainnet.infura.io/v3/${INFURA_API_KEY}`,\n 80001: `https://polygon-mumbai.infura.io/v3/${INFURA_API_KEY}`,\n 10: `https://optimism-mainnet.infura.io/v3/${INFURA_API_KEY}`,\n 420: `https://optimism-goerli.infura.io/v3/${INFURA_API_KEY}`,\n 42161: `https://arbitrum-mainnet.infura.io/v3/${INFURA_API_KEY}`,\n // 42161: 'https://evocative-stylish-dinghy.arbitrum-mainnet.discover.quiknode.pro/80b526d14fa9fd9a8b0db1e65554acaf00c6a1ab/',\n 421613: `https://arbitrum-goerli.infura.io/v3/${INFURA_API_KEY}`,\n 43114: `https://avalanche-mainnet.infura.io/v3/${INFURA_API_KEY}`,\n 43113: `https://avalanche-fuji.infura.io/v3/${INFURA_API_KEY}`,\n 1313161554: `https://aurora-mainnet.infura.io/v3/${INFURA_API_KEY}`,\n 1313161555: `https://aurora-testnet.infura.io/v3/${INFURA_API_KEY}`,\n 56: \"https://neat-greatest-layer.bsc.quiknode.pro/9405a499ceee314e5f2f68c9d47518d3537fce6a/\",\n 8453: \"https://twilight-red-tree.base-mainnet.quiknode.pro/dc6eb27bf0f917df215922488dd97f4de7d9b08e/\",\n 84531:\n \"https://icy-long-mountain.base-goerli.quiknode.pro/5b80d93e97cc9412a63c10a30841869abbef9596/\",\n 100: \"https://thrilling-fluent-film.xdai.quiknode.pro/305955cffb9868cdd95b5e3dc9775f20678ad9ac/\",\n 10200: \"https://nd-810-853-201.p2pify.com/e828b09f0d43591de96c297b3f36fffd\",\n 59144: `https://linea-mainnet.infura.io/v3/${INFURA_API_KEY}`,\n 59140: `https://linea-goerli.infura.io/v3/${INFURA_API_KEY}`,\n 204:
|
|
1
|
+
{"version":3,"file":"constants.js","sourceRoot":"","sources":["../../../src/kernel-zerodev/constants.ts"],"names":[],"mappings":";;;AAAA,+BAA4C;AAE5C,wCAAsC;AAEzB,QAAA,2BAA2B,GAAG,CAAC,CAAC;AAChC,QAAA,iCAAiC,GAAG,KAAK,CAAC;AAC1C,QAAA,WAAW,GAAG,wCAAwC,CAAC;AACvD,QAAA,aAAa,GACxB,wDAAwD,CAAC;AAC9C,QAAA,kBAAkB,GAC7B,4CAA4C,CAAC;AAClC,QAAA,cAAc,GAAQ,4CAA4C,CAAC;AACnE,QAAA,WAAW,GAAG,mCAAmC,CAAC;AAClD,QAAA,OAAO,GAAG,8BAA8B,CAAC;AACzC,QAAA,uBAAuB,GAClC,4CAA4C,CAAC;AAClC,QAAA,sBAAsB,GACjC,4CAA4C,CAAC;AAClC,QAAA,mBAAmB,GAAG,4CAA4C,CAAC;AACnE,QAAA,6BAA6B,GACxC,4CAA4C,CAAC;AAClC,QAAA,kBAAkB,GAAG,4CAA4C,CAAC;AAClE,QAAA,eAAe,GAC1B,sIAAsI,CAAC;AAC5H,QAAA,oCAAoC,GAC/C,4CAA4C,CAAC;AAClC,QAAA,YAAY,GAAG,4CAA4C,CAAC;AAC5D,QAAA,6BAA6B,GACxC,4CAA4C,CAAC;AAClC,QAAA,0BAA0B,GACrC,4CAA4C,CAAC;AAClC,QAAA,eAAe,GAAG,4CAA4C,CAAC;AAC/D,QAAA,UAAU,GAAG,4CAA4C,CAAC;AAE1D,QAAA,sBAAsB,GAAuB;IACxD,IAAI,EAAE;QACJ,CAAC,EAAE,4CAA4C;QAE/C,GAAG,EAAE,4CAA4C;QAGjD,KAAK,EAAE,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uCAAuC,sBAAc,EAAE;IAC9D,EAAE,EAAE,yCAAyC,sBAAc,EAAE;IAC7D,GAAG,EAAE,wCAAwC,sBAAc,EAAE;IAC7D,KAAK,EAAE,yCAAyC,sBAAc,EAAE;IAEhE,MAAM,EAAE,wCAAwC,sBAAc,EAAE;IAChE,KAAK,EAAE,0CAA0C,sBAAc,EAAE;IACjE,KAAK,EAAE,uCAAuC,sBAAc,EAAE;IAC9D,UAAU,EAAE,uCAAuC,sBAAc,EAAE;IACnE,UAAU,EAAE,uCAAuC,sBAAc,EAAE;IACnE,EAAE,EAAE,wFAAwF;IAC5F,IAAI,EAAE,+FAA+F;IACrG,KAAK,EACH,8FAA8F;IAChG,GAAG,EAAE,2FAA2F;IAChG,KAAK,EAAE,oEAAoE;IAC3E,KAAK,EAAE,sCAAsC,sBAAc,EAAE;IAC7D,KAAK,EAAE,qCAAqC,sBAAc,EAAE;IAC5D,GAAG,EAAE,iEAAiE;CAEvE,CAAC","sourcesContent":["import { parseUnits, type Hex } from \"viem\";\nimport type { IGasTokenAddresses } from \"./paymaster/types.js\";\nimport { polygon } from \"viem/chains\";\n\nexport const DEFAULT_SEND_TX_MAX_RETRIES = 3;\nexport const DEFAULT_SEND_TX_RETRY_INTERVAL_MS = 60000; // 1 minutes\nexport const BUNDLER_URL = \"https://v0-6-meta-bundler.onrender.com\";\nexport const PAYMASTER_URL =\n \"https://meta-aa-provider.onrender.com/api/v1/paymaster\";\nexport const ENTRYPOINT_ADDRESS: Hex =\n \"0x5FF137D4b0FDCD49DcA30c7CF57E578a026d2789\";\nexport const MULTISEND_ADDR: Hex = \"0x8ae01fcf7c655655ff2c6ef907b8b4718ab4e17c\";\nexport const BACKEND_URL = \"https://backend-vikp.onrender.com\";\nexport const API_URL = \"https://prod-api.zerodev.app\";\nexport const ECDSA_VALIDATOR_ADDRESS =\n \"0xd9AB5096a832b9ce79914329DAEE236f8Eea0390\";\nexport const KERNEL_FACTORY_ADDRESS =\n \"0x5de4839a76cf55d0c90e2061ef4386d962E15ae3\";\nexport const KERNEL_IMPL_ADDRESS = \"0x0DA6a956B9488eD4dd761E59f52FDc6c8068E6B5\";\nexport const KILL_SWITCH_VALIDATOR_ADDRESS =\n \"0x7393A7dA58CCfFb78f52adb09705BE6E20F704BC\";\nexport const KILL_SWITCH_ACTION = \"0x3f38e479304c7F18F988269a1bDa7d646bd48243\";\nexport const DUMMY_ECDSA_SIG =\n \"0xfffffffffffffffffffffffffffffff0000000000000000000000000000000007aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa1c\";\nexport const ERC165_SESSION_KEY_VALIDATOR_ADDRESS =\n \"0xe149290800De29D4b0BF9dB82c508255D81902E6\";\nexport const TOKEN_ACTION = \"0x2087C7FfD0d0DAE80a00EE74325aBF3449e0eaf1\";\nexport const SESSION_KEY_VALIDATOR_ADDRESS =\n \"0x1C1D5b70aD6e0c04366aab100261A6Bcc251EA3f\";\nexport const RECOVERY_VALIDATOR_ADDRESS =\n \"0x4fd47D861c349bD49DC61341a922cb72F9dF7E8d\";\nexport const RECOVERY_ACTION = \"0x2f65dB8039fe5CAEE0a8680D2879deB800F31Ae1\";\nexport const oneAddress = \"0x0000000000000000000000000000000000000001\";\n\nexport const gasTokenChainAddresses: IGasTokenAddresses = {\n USDC: {\n 1: \"0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48\",\n // 5: \"0x2f3A40A3db8a7e3D09B0adfEfbCe4f6F81927557\",\n 137: \"0x2791Bca1f2de4661ED88A30C99A7a9449Aa84174\",\n // 80001: \"\",\n // 420: \"0x7F5c764cBc14f9669B88837ca1490cCa17c31607\",\n 42161: \"0xFF970A61A04b1cA14834A43f5dE4533eBDDB5CC8\",\n // 421613: \"\",\n 43114: \"0xB97EF9Ef8734C71904D8002F8b6Bc66Dd9c48a6E\",\n // 43113: \"\",\n // 56: \"\",\n // 97: \"\"\n },\n PEPE: {\n 1: \"0x6982508145454Ce325dDbE47a25d4ec3d2311933\",\n },\n};\n\nexport const ERC20_APPROVAL_AMOUNT: { [key: string]: bigint } = {\n // ETH\n [gasTokenChainAddresses[\"USDC\"][1]]: parseUnits(\"100\", 6),\n\n // Goerli\n [gasTokenChainAddresses[\"USDC\"][5]]: parseUnits(\"100\", 6),\n\n // Polygon\n [gasTokenChainAddresses[\"USDC\"][137]]: parseUnits(\"10\", 6),\n\n // Arbitrum\n [gasTokenChainAddresses[\"USDC\"][42161]]: parseUnits(\"10\", 6),\n\n // Avalanche\n [gasTokenChainAddresses[\"USDC\"][43114]]: parseUnits(\"10\", 6),\n\n // ETH\n [gasTokenChainAddresses[\"PEPE\"][1]]: parseUnits(\"50000000\", 18),\n\n \"0x3870419Ba2BBf0127060bCB37f69A1b1C090992B\": parseUnits(\"100\", 18),\n};\n\nexport const minPriorityFeePerBidDefaults = new Map<number, bigint>([\n [polygon.id, 30_000_000_000n],\n]);\n\nexport const INFURA_API_KEY = \"f36f7f706a58477884ce6fe89165666c\";\nexport const CHAIN_ID_TO_NODE: { [key: number]: string } = {\n 1: `https://mainnet.infura.io/v3/${INFURA_API_KEY}`,\n 5: `https://goerli.infura.io/v3/${INFURA_API_KEY}`,\n 11155111:\n \"https://fittest-ultra-aura.ethereum-sepolia.quiknode.pro/3893d01b1dd411fdfa9b6dd372dd2b4f69fcf1ea/\",\n 137: `https://polygon-mainnet.infura.io/v3/${INFURA_API_KEY}`,\n 80001: `https://polygon-mumbai.infura.io/v3/${INFURA_API_KEY}`,\n 10: `https://optimism-mainnet.infura.io/v3/${INFURA_API_KEY}`,\n 420: `https://optimism-goerli.infura.io/v3/${INFURA_API_KEY}`,\n 42161: `https://arbitrum-mainnet.infura.io/v3/${INFURA_API_KEY}`,\n // 42161: 'https://evocative-stylish-dinghy.arbitrum-mainnet.discover.quiknode.pro/80b526d14fa9fd9a8b0db1e65554acaf00c6a1ab/',\n 421613: `https://arbitrum-goerli.infura.io/v3/${INFURA_API_KEY}`,\n 43114: `https://avalanche-mainnet.infura.io/v3/${INFURA_API_KEY}`,\n 43113: `https://avalanche-fuji.infura.io/v3/${INFURA_API_KEY}`,\n 1313161554: `https://aurora-mainnet.infura.io/v3/${INFURA_API_KEY}`,\n 1313161555: `https://aurora-testnet.infura.io/v3/${INFURA_API_KEY}`,\n 56: \"https://neat-greatest-layer.bsc.quiknode.pro/9405a499ceee314e5f2f68c9d47518d3537fce6a/\",\n 8453: \"https://twilight-red-tree.base-mainnet.quiknode.pro/dc6eb27bf0f917df215922488dd97f4de7d9b08e/\",\n 84531:\n \"https://icy-long-mountain.base-goerli.quiknode.pro/5b80d93e97cc9412a63c10a30841869abbef9596/\",\n 100: \"https://thrilling-fluent-film.xdai.quiknode.pro/305955cffb9868cdd95b5e3dc9775f20678ad9ac/\",\n 10200: \"https://nd-810-853-201.p2pify.com/e828b09f0d43591de96c297b3f36fffd\",\n 59144: `https://linea-mainnet.infura.io/v3/${INFURA_API_KEY}`,\n 59140: `https://linea-goerli.infura.io/v3/${INFURA_API_KEY}`,\n 204: \"https://opbnb.rpc.thirdweb.com/eed98c1f30120c0508f17c1f01d3102b\",\n // 5611: 'opBnb-testnet',\n};\n"]}
|
|
@@ -1,8 +1,12 @@
|
|
|
1
1
|
import type { ZeroDevProvider } from "../provider.js";
|
|
2
2
|
import { type UserOperationStruct, type BigNumberish } from "@alchemy/aa-core";
|
|
3
|
+
import { type PaymasterAndBundlerProviders } from "../paymaster/types.js";
|
|
3
4
|
export declare const withZeroDevGasEstimator: (provider: ZeroDevProvider) => ZeroDevProvider;
|
|
4
5
|
export declare const estimateCreationGas: (provider: ZeroDevProvider, initCode?: string) => Promise<bigint>;
|
|
5
6
|
export declare const getPreVerificationGas: (userOp: Partial<UserOperationStruct>) => Promise<number>;
|
|
7
|
+
export declare const GAS_PRICE_RPC_METHODS_BY_BUNDLER: {
|
|
8
|
+
[K in PaymasterAndBundlerProviders]: string;
|
|
9
|
+
};
|
|
6
10
|
export declare const eip1559GasPrice: (provider: ZeroDevProvider) => Promise<{
|
|
7
11
|
maxFeePerGas: bigint;
|
|
8
12
|
maxPriorityFeePerGas: bigint;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getFeeData = exports.eip1559GasPrice = exports.getPreVerificationGas = exports.estimateCreationGas = exports.withZeroDevGasEstimator = void 0;
|
|
3
|
+
exports.getFeeData = exports.eip1559GasPrice = exports.GAS_PRICE_RPC_METHODS_BY_BUNDLER = exports.getPreVerificationGas = exports.estimateCreationGas = exports.withZeroDevGasEstimator = void 0;
|
|
4
4
|
const aa_core_1 = require("@alchemy/aa-core");
|
|
5
5
|
const constants_js_1 = require("../constants.js");
|
|
6
6
|
const calc_pre_verification_gas_js_1 = require("../utils/calc-pre-verification-gas.js");
|
|
@@ -82,15 +82,23 @@ const getPreVerificationGas = async (userOp) => {
|
|
|
82
82
|
return (0, calc_pre_verification_gas_js_1.calcPreVerificationGas)(p);
|
|
83
83
|
};
|
|
84
84
|
exports.getPreVerificationGas = getPreVerificationGas;
|
|
85
|
+
exports.GAS_PRICE_RPC_METHODS_BY_BUNDLER = {
|
|
86
|
+
STACKUP: "eth_maxPriorityFeePerGas",
|
|
87
|
+
ALCHEMY: "rundler_maxPriorityFeePerGas",
|
|
88
|
+
PIMLICO: "pimlico_getUserOperationGasPrice",
|
|
89
|
+
};
|
|
85
90
|
const eip1559GasPrice = async (provider) => {
|
|
86
|
-
|
|
87
|
-
provider.
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
91
|
+
let [fee, block] = await Promise.all([
|
|
92
|
+
provider.rpcClient.request({
|
|
93
|
+
method: exports.GAS_PRICE_RPC_METHODS_BY_BUNDLER[provider.bundlerProvider] ??
|
|
94
|
+
"eth_maxPriorityFeePerGas",
|
|
95
|
+
params: [],
|
|
96
|
+
}),
|
|
92
97
|
provider.rpcClient.getBlock({ blockTag: "latest" }),
|
|
93
98
|
]);
|
|
99
|
+
if (provider.bundlerProvider === "PIMLICO") {
|
|
100
|
+
fee = fee.standard.maxPriorityFeePerGas;
|
|
101
|
+
}
|
|
94
102
|
const tip = BigInt(fee);
|
|
95
103
|
const buffer = (tip / 100n) * 13n;
|
|
96
104
|
let maxPriorityFeePerGas = tip + buffer;
|
|
@@ -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;AAExE,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,IAAI,EAAE;YACvC,oBAAoB,EAAE,MAAM,CAAC,oBAAoB,IAAI,EAAE;SACxD,CAAC,CAAC;QAEH,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,OAAO,EAAE,YAAY,CAAC,CAAC,CAAC,MAAM,CAAC,OAAO,EAAE,YAAY,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;YAC1E,oBAAoB,GAAG,OAAO,CAAC,oBAAoB;gBACjD,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,oBAAoB,CA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IAAA,2BAAiB,EAAC;QAClD,KAAK,EAAE,QAAQ,CAAC,SAAS,CAAC,QAAQ,CAAC,EAAE,QAAQ,EAAE,QAAQ,EAAE,CAAC;QAC1D,QAAQ,EAAE,QAAQ,CAAC,SAAS,CAAC,WAAW,EAAE,CAAC,KAAK,CAAC,CAAC,KAAK,EAAE,EAAE;YACzD,OAAO,CAAC,IAAI,CAAC,iCAAiC,EAAE,KAAK,CAAC,CAAC;YACvD,OAAO,IAAI,CAAC;QACd,CAAC,CAAC;KACH,CAAC,CAAC;IAEH,IAAI,YAAY,GAAG,IAAI,CAAC;IACxB,IAAI,oBAAoB,GAAG,IAAI,CAAC;IAEhC,IAAI,KAAK,IAAI,KAAK,CAAC,aAAa,IAAI,IAAI,EAAE;QAExC,MAAM,UAAU,GAAG,MAAM,CAAC,YAAY,CAAC,CAAC;QACxC,oBAAoB,GAAG,QAAQ,CAAC,CAAC,CAAC,QAAQ,GAAG,KAAK,CAAC,aAAa,CAAC,CAAC,CAAC,IAAI,CAAC;QACxE,IACE,oBAAoB,IAAI,IAAI;YAC5B,oBAAoB,GAAG,MAAM,CAAC,CAAC,CAAC;YAChC,oBAAoB,GAAG,UAAU,EACjC;YACA,oBAAoB,GAAG,UAAU,CAAC;SACnC;QACD,oBAAoB;YAClB,oBAAoB,GAAG,QAAQ,CAAC,oBAAoB;gBAClD,CAAC,CAAC,QAAQ,CAAC,oBAAoB;gBAC/B,CAAC,CAAC,oBAAoB,CAAC;QAC3B,YAAY;YACV,KAAK,CAAC,aAAa,GAAG,MAAM,CAAC,CAAC,CAAC,GAAG,CAAC,oBAAoB,IAAI,CAAC,CAAC,CAAC;KACjE;IAED,OAAO,EAAE,YAAY,EAAE,oBAAoB,EAAE,CAAC;AAChD,CAAC,CAAC;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\";\n\nexport const withZeroDevGasEstimator = (\n provider: ZeroDevProvider\n): ZeroDevProvider => {\n provider.withFeeDataGetter(async (struct) => {\n let overrides = await resolveProperties({\n maxFeePerGas: struct.maxFeePerGas ?? 0n,\n maxPriorityFeePerGas: struct.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 (\n maxFeePerGas < BigInt(overrides.maxFeePerGas) ||\n maxPriorityFeePerGas < BigInt(overrides.maxPriorityFeePerGas)\n ) {\n return overrides;\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 eip1559GasPrice = async (provider: ZeroDevProvider) => {\n const [fee, block] = await Promise.all([\n provider.bundlerProvider === \"ALCHEMY\"\n ? (provider.rpcClient.request({\n // @ts-expect-error\n method: \"rundler_maxPriorityFeePerGas\",\n }) as Promise<Hex>)\n : provider.rpcClient.getMaxPriorityFeePerGas(),\n provider.rpcClient.getBlock({ blockTag: \"latest\" }),\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,IAAI,EAAE;YACvC,oBAAoB,EAAE,MAAM,CA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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 ?? 0n,\n maxPriorityFeePerGas: struct.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 (\n maxFeePerGas < BigInt(overrides.maxFeePerGas) ||\n maxPriorityFeePerGas < BigInt(overrides.maxPriorityFeePerGas)\n ) {\n return overrides;\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};\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"]}
|
|
@@ -10,6 +10,7 @@ function isMethodInErc4337RpcSchema(variable) {
|
|
|
10
10
|
"eth_supportedEntryPoints",
|
|
11
11
|
"eth_maxPriorityFeePerGas",
|
|
12
12
|
"rundler_maxPriorityFeePerGas",
|
|
13
|
+
"pimlico_getUserOperationGasPrice",
|
|
13
14
|
].includes(variable);
|
|
14
15
|
}
|
|
15
16
|
export const createZeroDevPublicErc4337Client = ({ chain, rpcUrl, projectId, bundlerProvider, }) => {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"create-client.js","sourceRoot":"","sources":["../../../../src/kernel-zerodev/client/create-client.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,6BAA6B,GAI9B,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EAAE,IAAI,EAAE,kBAAkB,EAAc,MAAM,EAAE,MAAM,MAAM,CAAC;AACpE,OAAO,EAAE,WAAW,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAC;AAYhE,SAAS,0BAA0B,CACjC,QAAgB;IAEhB,OACE;QACE,uBAAuB;QACvB,8BAA8B;QAC9B,6BAA6B;QAC7B,4BAA4B;QAC5B,0BAA0B;QAC1B,0BAA0B;QAC1B,8BAA8B;
|
|
1
|
+
{"version":3,"file":"create-client.js","sourceRoot":"","sources":["../../../../src/kernel-zerodev/client/create-client.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,6BAA6B,GAI9B,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EAAE,IAAI,EAAE,kBAAkB,EAAc,MAAM,EAAE,MAAM,MAAM,CAAC;AACpE,OAAO,EAAE,WAAW,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAC;AAYhE,SAAS,0BAA0B,CACjC,QAAgB;IAEhB,OACE;QACE,uBAAuB;QACvB,8BAA8B;QAC9B,6BAA6B;QAC7B,4BAA4B;QAC5B,0BAA0B;QAC1B,0BAA0B;QAC1B,8BAA8B;QAC9B,kCAAkC;KAErC,CAAC,QAAQ,CAAC,QAAqC,CAAC,CAAC;AACpD,CAAC;AAED,MAAM,CAAC,MAAM,gCAAgC,GAAG,CAAC,EAC/C,KAAK,EACL,MAAM,EACN,SAAS,EACT,eAAe,GACK,EAAsC,EAAE;IAC5D,MAAM,gBAAgB,GAAG,IAAI,CAAC,MAAM,EAAE;QACpC,YAAY,EAAE;YAEZ,OAAO,EAAE,MAAM,KAAK,WAAW,CAAC,CAAC,CAAC,EAAE,SAAS,EAAE,eAAe,EAAE,CAAC,CAAC,CAAC,EAAE;SACtE;QACD,IAAI,EAAE,2BAA2B;QACjC,GAAG,EAAE,2BAA2B;QAChC,UAAU,EAAE,CAAC;QACb,OAAO,EAAE,KAAK;KACf,CAAC,CAAC;IACH,MAAM,eAAe,GAAG,IAAI,CAAC,gBAAgB,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC,CAAC;IACzD,IAAI,MAAM,GAAG,6BAA6B,CACxC,kBAAkB,CAAC;QACjB,KAAK;QACL,SAAS,EAAE,MAAM,CAAC;YAChB,KAAK,CAAC,OAAO,CAAC,EAAE,MAAM,EAAE,MAAM,EAAE;gBAC9B,IAAI,QAAQ,CAAC;gBACb,IAAI,0BAA0B,CAAC,MAAM,CAAC,EAAE;oBACtC,QAAQ,GAAG,MAAM,gBAAgB,CAAC,EAAE,KAAK,EAAE,CAAC,CAAC,OAAO,CAAC;wBACnD,MAAM;wBACN,MAAM;qBACA,CAAC,CAAC;iBACX;qBAAM;oBACL,QAAQ,GAAG,MAAM,eAAe,CAAC,EAAE,KAAK,EAAE,CAAC,CAAC,OAAO,CAAC;wBAClD,MAAM;wBACN,MAAM;qBACA,CAAC,CAAC;iBACX;gBACD,OAAO,QAAQ,CAAC;YAClB,CAAC;SACF,CAAC;KACH,CAAC,CACH,CAAC;IAEF,OAAO,MAAuD,CAAC;AACjE,CAAC,CAAC","sourcesContent":["import {\n createPublicErc4337FromClient,\n type PublicErc4337Client,\n type Erc337RpcSchema,\n type HttpTransport,\n} from \"@alchemy/aa-core\";\nimport { http, createPublicClient, type Chain, custom } from \"viem\";\nimport { BUNDLER_URL, CHAIN_ID_TO_NODE } from \"../constants.js\";\nimport type { PaymasterAndBundlerProviders } from \"../paymaster/types.js\";\n\ninterface ZeroDevClientConfig {\n chain: Chain;\n projectId: string;\n rpcUrl?: string;\n bundlerProvider?: PaymasterAndBundlerProviders;\n}\n\ntype MethodsOfErc4337RpcSchema = Erc337RpcSchema[number][\"Method\"];\n\nfunction isMethodInErc4337RpcSchema(\n variable: string\n): variable is MethodsOfErc4337RpcSchema {\n return (\n [\n \"eth_sendUserOperation\",\n \"eth_estimateUserOperationGas\",\n \"eth_getUserOperationReceipt\",\n \"eth_getUserOperationByHash\",\n \"eth_supportedEntryPoints\",\n \"eth_maxPriorityFeePerGas\",\n \"rundler_maxPriorityFeePerGas\",\n \"pimlico_getUserOperationGasPrice\",\n ] as const\n ).includes(variable as MethodsOfErc4337RpcSchema);\n}\n\nexport const createZeroDevPublicErc4337Client = ({\n chain,\n rpcUrl,\n projectId,\n bundlerProvider,\n}: ZeroDevClientConfig): PublicErc4337Client<HttpTransport> => {\n const erc4337Transport = http(rpcUrl, {\n fetchOptions: {\n // @ts-ignore\n headers: rpcUrl === BUNDLER_URL ? { projectId, bundlerProvider } : {},\n },\n name: \"Connected bundler network\",\n key: \"connected-bundler-network\",\n retryCount: 0,\n timeout: 35000,\n });\n const publicTransport = http(CHAIN_ID_TO_NODE[chain.id]);\n let client = createPublicErc4337FromClient(\n createPublicClient({\n chain,\n transport: custom({\n async request({ method, params }) {\n let response;\n if (isMethodInErc4337RpcSchema(method)) {\n response = await erc4337Transport({ chain }).request({\n method,\n params,\n } as any);\n } else {\n response = await publicTransport({ chain }).request({\n method,\n params,\n } as any);\n }\n return response;\n },\n }),\n })\n );\n\n return client as unknown as PublicErc4337Client<HttpTransport>;\n};\n"]}
|
|
@@ -65,6 +65,6 @@ export const CHAIN_ID_TO_NODE = {
|
|
|
65
65
|
10200: "https://nd-810-853-201.p2pify.com/e828b09f0d43591de96c297b3f36fffd",
|
|
66
66
|
59144: `https://linea-mainnet.infura.io/v3/${INFURA_API_KEY}`,
|
|
67
67
|
59140: `https://linea-goerli.infura.io/v3/${INFURA_API_KEY}`,
|
|
68
|
-
204:
|
|
68
|
+
204: "https://opbnb.rpc.thirdweb.com/eed98c1f30120c0508f17c1f01d3102b",
|
|
69
69
|
};
|
|
70
70
|
//# sourceMappingURL=constants.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"constants.js","sourceRoot":"","sources":["../../../src/kernel-zerodev/constants.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAY,MAAM,MAAM,CAAC;AAE5C,OAAO,EAAE,OAAO,EAAE,MAAM,aAAa,CAAC;AAEtC,MAAM,CAAC,MAAM,2BAA2B,GAAG,CAAC,CAAC;AAC7C,MA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AE,yCAAyC,cAAc,EAAE;IAEhE,MAAM,EAAE,wCAAwC,cAAc,EAAE;IAChE,KAAK,EAAE,0CAA0C,cAAc,EAAE;IACjE,KAAK,EAAE,uCAAuC,cAAc,EAAE;IAC9D,UAAU,EAAE,uCAAuC,cAAc,EAAE;IACnE,UAAU,EAAE,uCAAuC,cAAc,EAAE;IACnE,EAAE,EAAE,wFAAwF;IAC5F,IAAI,EAAE,+FAA+F;IACrG,KAAK,EACH,8FAA8F;IAChG,GAAG,EAAE,2FAA2F;IAChG,KAAK,EAAE,oEAAoE;IAC3E,KAAK,EAAE,sCAAsC,cAAc,EAAE;IAC7D,KAAK,EAAE,qCAAqC,cAAc,EAAE;IAC5D,GAAG,EAAE,iEAAiE;CAEvE,CAAC","sourcesContent":["import { parseUnits, type Hex } from \"viem\";\nimport type { IGasTokenAddresses } from \"./paymaster/types.js\";\nimport { polygon } from \"viem/chains\";\n\nexport const DEFAULT_SEND_TX_MAX_RETRIES = 3;\nexport const DEFAULT_SEND_TX_RETRY_INTERVAL_MS = 60000; // 1 minutes\nexport const BUNDLER_URL = \"https://v0-6-meta-bundler.onrender.com\";\nexport const PAYMASTER_URL =\n \"https://meta-aa-provider.onrender.com/api/v1/paymaster\";\nexport const ENTRYPOINT_ADDRESS: Hex =\n \"0x5FF137D4b0FDCD49DcA30c7CF57E578a026d2789\";\nexport const MULTISEND_ADDR: Hex = \"0x8ae01fcf7c655655ff2c6ef907b8b4718ab4e17c\";\nexport const BACKEND_URL = \"https://backend-vikp.onrender.com\";\nexport const API_URL = \"https://prod-api.zerodev.app\";\nexport const ECDSA_VALIDATOR_ADDRESS =\n \"0xd9AB5096a832b9ce79914329DAEE236f8Eea0390\";\nexport const KERNEL_FACTORY_ADDRESS =\n \"0x5de4839a76cf55d0c90e2061ef4386d962E15ae3\";\nexport const KERNEL_IMPL_ADDRESS = \"0x0DA6a956B9488eD4dd761E59f52FDc6c8068E6B5\";\nexport const KILL_SWITCH_VALIDATOR_ADDRESS =\n \"0x7393A7dA58CCfFb78f52adb09705BE6E20F704BC\";\nexport const KILL_SWITCH_ACTION = \"0x3f38e479304c7F18F988269a1bDa7d646bd48243\";\nexport const DUMMY_ECDSA_SIG =\n \"0xfffffffffffffffffffffffffffffff0000000000000000000000000000000007aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa1c\";\nexport const ERC165_SESSION_KEY_VALIDATOR_ADDRESS =\n \"0xe149290800De29D4b0BF9dB82c508255D81902E6\";\nexport const TOKEN_ACTION = \"0x2087C7FfD0d0DAE80a00EE74325aBF3449e0eaf1\";\nexport const SESSION_KEY_VALIDATOR_ADDRESS =\n \"0x1C1D5b70aD6e0c04366aab100261A6Bcc251EA3f\";\nexport const RECOVERY_VALIDATOR_ADDRESS =\n \"0x4fd47D861c349bD49DC61341a922cb72F9dF7E8d\";\nexport const RECOVERY_ACTION = \"0x2f65dB8039fe5CAEE0a8680D2879deB800F31Ae1\";\nexport const oneAddress = \"0x0000000000000000000000000000000000000001\";\n\nexport const gasTokenChainAddresses: IGasTokenAddresses = {\n USDC: {\n 1: \"0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48\",\n // 5: \"0x2f3A40A3db8a7e3D09B0adfEfbCe4f6F81927557\",\n 137: \"0x2791Bca1f2de4661ED88A30C99A7a9449Aa84174\",\n // 80001: \"\",\n // 420: \"0x7F5c764cBc14f9669B88837ca1490cCa17c31607\",\n 42161: \"0xFF970A61A04b1cA14834A43f5dE4533eBDDB5CC8\",\n // 421613: \"\",\n 43114: \"0xB97EF9Ef8734C71904D8002F8b6Bc66Dd9c48a6E\",\n // 43113: \"\",\n // 56: \"\",\n // 97: \"\"\n },\n PEPE: {\n 1: \"0x6982508145454Ce325dDbE47a25d4ec3d2311933\",\n },\n};\n\nexport const ERC20_APPROVAL_AMOUNT: { [key: string]: bigint } = {\n // ETH\n [gasTokenChainAddresses[\"USDC\"][1]]: parseUnits(\"100\", 6),\n\n // Goerli\n [gasTokenChainAddresses[\"USDC\"][5]]: parseUnits(\"100\", 6),\n\n // Polygon\n [gasTokenChainAddresses[\"USDC\"][137]]: parseUnits(\"10\", 6),\n\n // Arbitrum\n [gasTokenChainAddresses[\"USDC\"][42161]]: parseUnits(\"10\", 6),\n\n // Avalanche\n [gasTokenChainAddresses[\"USDC\"][43114]]: parseUnits(\"10\", 6),\n\n // ETH\n [gasTokenChainAddresses[\"PEPE\"][1]]: parseUnits(\"50000000\", 18),\n\n \"0x3870419Ba2BBf0127060bCB37f69A1b1C090992B\": parseUnits(\"100\", 18),\n};\n\nexport const minPriorityFeePerBidDefaults = new Map<number, bigint>([\n [polygon.id, 30_000_000_000n],\n]);\n\nexport const INFURA_API_KEY = \"f36f7f706a58477884ce6fe89165666c\";\nexport const CHAIN_ID_TO_NODE: { [key: number]: string } = {\n 1: `https://mainnet.infura.io/v3/${INFURA_API_KEY}`,\n 5: `https://goerli.infura.io/v3/${INFURA_API_KEY}`,\n 11155111:\n \"https://fittest-ultra-aura.ethereum-sepolia.quiknode.pro/3893d01b1dd411fdfa9b6dd372dd2b4f69fcf1ea/\",\n 137: `https://polygon-mainnet.infura.io/v3/${INFURA_API_KEY}`,\n 80001: `https://polygon-mumbai.infura.io/v3/${INFURA_API_KEY}`,\n 10: `https://optimism-mainnet.infura.io/v3/${INFURA_API_KEY}`,\n 420: `https://optimism-goerli.infura.io/v3/${INFURA_API_KEY}`,\n 42161: `https://arbitrum-mainnet.infura.io/v3/${INFURA_API_KEY}`,\n // 42161: 'https://evocative-stylish-dinghy.arbitrum-mainnet.discover.quiknode.pro/80b526d14fa9fd9a8b0db1e65554acaf00c6a1ab/',\n 421613: `https://arbitrum-goerli.infura.io/v3/${INFURA_API_KEY}`,\n 43114: `https://avalanche-mainnet.infura.io/v3/${INFURA_API_KEY}`,\n 43113: `https://avalanche-fuji.infura.io/v3/${INFURA_API_KEY}`,\n 1313161554: `https://aurora-mainnet.infura.io/v3/${INFURA_API_KEY}`,\n 1313161555: `https://aurora-testnet.infura.io/v3/${INFURA_API_KEY}`,\n 56: \"https://neat-greatest-layer.bsc.quiknode.pro/9405a499ceee314e5f2f68c9d47518d3537fce6a/\",\n 8453: \"https://twilight-red-tree.base-mainnet.quiknode.pro/dc6eb27bf0f917df215922488dd97f4de7d9b08e/\",\n 84531:\n \"https://icy-long-mountain.base-goerli.quiknode.pro/5b80d93e97cc9412a63c10a30841869abbef9596/\",\n 100: \"https://thrilling-fluent-film.xdai.quiknode.pro/305955cffb9868cdd95b5e3dc9775f20678ad9ac/\",\n 10200: \"https://nd-810-853-201.p2pify.com/e828b09f0d43591de96c297b3f36fffd\",\n 59144: `https://linea-mainnet.infura.io/v3/${INFURA_API_KEY}`,\n 59140: `https://linea-goerli.infura.io/v3/${INFURA_API_KEY}`,\n 204:
|
|
1
|
+
{"version":3,"file":"constants.js","sourceRoot":"","sources":["../../../src/kernel-zerodev/constants.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAY,MAAM,MAAM,CAAC;AAE5C,OAAO,EAAE,OAAO,EAAE,MAAM,aAAa,CAAC;AAEtC,MAAM,CAAC,MAAM,2BAA2B,GAAG,CAAC,CAAC;AAC7C,MAAM,CAAC,MAAM,iCAAiC,GAAG,KAAK,CAAC;AACvD,MAAM,CAAC,MAAM,WAAW,GAAG,wCAAwC,CAAC;AACpE,MAAM,CAAC,MAAM,aAAa,GACxB,wDAAwD,CAAC;AAC3D,MAAM,CAAC,MAAM,kBAAkB,GAC7B,4CAA4C,CAAC;AAC/C,MAAM,CAAC,MAAM,cAAc,GAAQ,4CAA4C,CAAC;AAChF,MAAM,CAAC,MAAM,WAAW,GAAG,mCAAmC,CAAC;AAC/D,MAAM,CAAC,MAAM,OAAO,GAAG,8BAA8B,CAAC;AACtD,MAAM,CAAC,MAAM,uBAAuB,GAClC,4CAA4C,CAAC;AAC/C,MAAM,CAAC,MAAM,sBAAsB,GACjC,4CAA4C,CAAC;AAC/C,MAAM,CAAC,MAAM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seUnits, type Hex } from \"viem\";\nimport type { IGasTokenAddresses } from \"./paymaster/types.js\";\nimport { polygon } from \"viem/chains\";\n\nexport const DEFAULT_SEND_TX_MAX_RETRIES = 3;\nexport const DEFAULT_SEND_TX_RETRY_INTERVAL_MS = 60000; // 1 minutes\nexport const BUNDLER_URL = \"https://v0-6-meta-bundler.onrender.com\";\nexport const PAYMASTER_URL =\n \"https://meta-aa-provider.onrender.com/api/v1/paymaster\";\nexport const ENTRYPOINT_ADDRESS: Hex =\n \"0x5FF137D4b0FDCD49DcA30c7CF57E578a026d2789\";\nexport const MULTISEND_ADDR: Hex = \"0x8ae01fcf7c655655ff2c6ef907b8b4718ab4e17c\";\nexport const BACKEND_URL = \"https://backend-vikp.onrender.com\";\nexport const API_URL = \"https://prod-api.zerodev.app\";\nexport const ECDSA_VALIDATOR_ADDRESS =\n \"0xd9AB5096a832b9ce79914329DAEE236f8Eea0390\";\nexport const KERNEL_FACTORY_ADDRESS =\n \"0x5de4839a76cf55d0c90e2061ef4386d962E15ae3\";\nexport const KERNEL_IMPL_ADDRESS = \"0x0DA6a956B9488eD4dd761E59f52FDc6c8068E6B5\";\nexport const KILL_SWITCH_VALIDATOR_ADDRESS =\n \"0x7393A7dA58CCfFb78f52adb09705BE6E20F704BC\";\nexport const KILL_SWITCH_ACTION = \"0x3f38e479304c7F18F988269a1bDa7d646bd48243\";\nexport const DUMMY_ECDSA_SIG =\n \"0xfffffffffffffffffffffffffffffff0000000000000000000000000000000007aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa1c\";\nexport const ERC165_SESSION_KEY_VALIDATOR_ADDRESS =\n \"0xe149290800De29D4b0BF9dB82c508255D81902E6\";\nexport const TOKEN_ACTION = \"0x2087C7FfD0d0DAE80a00EE74325aBF3449e0eaf1\";\nexport const SESSION_KEY_VALIDATOR_ADDRESS =\n \"0x1C1D5b70aD6e0c04366aab100261A6Bcc251EA3f\";\nexport const RECOVERY_VALIDATOR_ADDRESS =\n \"0x4fd47D861c349bD49DC61341a922cb72F9dF7E8d\";\nexport const RECOVERY_ACTION = \"0x2f65dB8039fe5CAEE0a8680D2879deB800F31Ae1\";\nexport const oneAddress = \"0x0000000000000000000000000000000000000001\";\n\nexport const gasTokenChainAddresses: IGasTokenAddresses = {\n USDC: {\n 1: \"0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48\",\n // 5: \"0x2f3A40A3db8a7e3D09B0adfEfbCe4f6F81927557\",\n 137: \"0x2791Bca1f2de4661ED88A30C99A7a9449Aa84174\",\n // 80001: \"\",\n // 420: \"0x7F5c764cBc14f9669B88837ca1490cCa17c31607\",\n 42161: \"0xFF970A61A04b1cA14834A43f5dE4533eBDDB5CC8\",\n // 421613: \"\",\n 43114: \"0xB97EF9Ef8734C71904D8002F8b6Bc66Dd9c48a6E\",\n // 43113: \"\",\n // 56: \"\",\n // 97: \"\"\n },\n PEPE: {\n 1: \"0x6982508145454Ce325dDbE47a25d4ec3d2311933\",\n },\n};\n\nexport const ERC20_APPROVAL_AMOUNT: { [key: string]: bigint } = {\n // ETH\n [gasTokenChainAddresses[\"USDC\"][1]]: parseUnits(\"100\", 6),\n\n // Goerli\n [gasTokenChainAddresses[\"USDC\"][5]]: parseUnits(\"100\", 6),\n\n // Polygon\n [gasTokenChainAddresses[\"USDC\"][137]]: parseUnits(\"10\", 6),\n\n // Arbitrum\n [gasTokenChainAddresses[\"USDC\"][42161]]: parseUnits(\"10\", 6),\n\n // Avalanche\n [gasTokenChainAddresses[\"USDC\"][43114]]: parseUnits(\"10\", 6),\n\n // ETH\n [gasTokenChainAddresses[\"PEPE\"][1]]: parseUnits(\"50000000\", 18),\n\n \"0x3870419Ba2BBf0127060bCB37f69A1b1C090992B\": parseUnits(\"100\", 18),\n};\n\nexport const minPriorityFeePerBidDefaults = new Map<number, bigint>([\n [polygon.id, 30_000_000_000n],\n]);\n\nexport const INFURA_API_KEY = \"f36f7f706a58477884ce6fe89165666c\";\nexport const CHAIN_ID_TO_NODE: { [key: number]: string } = {\n 1: `https://mainnet.infura.io/v3/${INFURA_API_KEY}`,\n 5: `https://goerli.infura.io/v3/${INFURA_API_KEY}`,\n 11155111:\n \"https://fittest-ultra-aura.ethereum-sepolia.quiknode.pro/3893d01b1dd411fdfa9b6dd372dd2b4f69fcf1ea/\",\n 137: `https://polygon-mainnet.infura.io/v3/${INFURA_API_KEY}`,\n 80001: `https://polygon-mumbai.infura.io/v3/${INFURA_API_KEY}`,\n 10: `https://optimism-mainnet.infura.io/v3/${INFURA_API_KEY}`,\n 420: `https://optimism-goerli.infura.io/v3/${INFURA_API_KEY}`,\n 42161: `https://arbitrum-mainnet.infura.io/v3/${INFURA_API_KEY}`,\n // 42161: 'https://evocative-stylish-dinghy.arbitrum-mainnet.discover.quiknode.pro/80b526d14fa9fd9a8b0db1e65554acaf00c6a1ab/',\n 421613: `https://arbitrum-goerli.infura.io/v3/${INFURA_API_KEY}`,\n 43114: `https://avalanche-mainnet.infura.io/v3/${INFURA_API_KEY}`,\n 43113: `https://avalanche-fuji.infura.io/v3/${INFURA_API_KEY}`,\n 1313161554: `https://aurora-mainnet.infura.io/v3/${INFURA_API_KEY}`,\n 1313161555: `https://aurora-testnet.infura.io/v3/${INFURA_API_KEY}`,\n 56: \"https://neat-greatest-layer.bsc.quiknode.pro/9405a499ceee314e5f2f68c9d47518d3537fce6a/\",\n 8453: \"https://twilight-red-tree.base-mainnet.quiknode.pro/dc6eb27bf0f917df215922488dd97f4de7d9b08e/\",\n 84531:\n \"https://icy-long-mountain.base-goerli.quiknode.pro/5b80d93e97cc9412a63c10a30841869abbef9596/\",\n 100: \"https://thrilling-fluent-film.xdai.quiknode.pro/305955cffb9868cdd95b5e3dc9775f20678ad9ac/\",\n 10200: \"https://nd-810-853-201.p2pify.com/e828b09f0d43591de96c297b3f36fffd\",\n 59144: `https://linea-mainnet.infura.io/v3/${INFURA_API_KEY}`,\n 59140: `https://linea-goerli.infura.io/v3/${INFURA_API_KEY}`,\n 204: \"https://opbnb.rpc.thirdweb.com/eed98c1f30120c0508f17c1f01d3102b\",\n // 5611: 'opBnb-testnet',\n};\n"]}
|
|
@@ -1,8 +1,12 @@
|
|
|
1
1
|
import type { ZeroDevProvider } from "../provider.js";
|
|
2
2
|
import { type UserOperationStruct, type BigNumberish } from "@alchemy/aa-core";
|
|
3
|
+
import { type PaymasterAndBundlerProviders } from "../paymaster/types.js";
|
|
3
4
|
export declare const withZeroDevGasEstimator: (provider: ZeroDevProvider) => ZeroDevProvider;
|
|
4
5
|
export declare const estimateCreationGas: (provider: ZeroDevProvider, initCode?: string) => Promise<bigint>;
|
|
5
6
|
export declare const getPreVerificationGas: (userOp: Partial<UserOperationStruct>) => Promise<number>;
|
|
7
|
+
export declare const GAS_PRICE_RPC_METHODS_BY_BUNDLER: {
|
|
8
|
+
[K in PaymasterAndBundlerProviders]: string;
|
|
9
|
+
};
|
|
6
10
|
export declare const eip1559GasPrice: (provider: ZeroDevProvider) => Promise<{
|
|
7
11
|
maxFeePerGas: bigint;
|
|
8
12
|
maxPriorityFeePerGas: bigint;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { deepHexlify, resolveProperties, } from "@alchemy/aa-core";
|
|
2
2
|
import { ENTRYPOINT_ADDRESS } from "../constants.js";
|
|
3
3
|
import { calcPreVerificationGas } from "../utils/calc-pre-verification-gas.js";
|
|
4
|
+
import {} from "../paymaster/types.js";
|
|
4
5
|
export const withZeroDevGasEstimator = (provider) => {
|
|
5
6
|
provider.withFeeDataGetter(async (struct) => {
|
|
6
7
|
let overrides = await resolveProperties({
|
|
@@ -76,15 +77,23 @@ export const getPreVerificationGas = async (userOp) => {
|
|
|
76
77
|
const p = await resolveProperties(userOp);
|
|
77
78
|
return calcPreVerificationGas(p);
|
|
78
79
|
};
|
|
80
|
+
export const GAS_PRICE_RPC_METHODS_BY_BUNDLER = {
|
|
81
|
+
STACKUP: "eth_maxPriorityFeePerGas",
|
|
82
|
+
ALCHEMY: "rundler_maxPriorityFeePerGas",
|
|
83
|
+
PIMLICO: "pimlico_getUserOperationGasPrice",
|
|
84
|
+
};
|
|
79
85
|
export const eip1559GasPrice = async (provider) => {
|
|
80
|
-
|
|
81
|
-
provider.
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
+
let [fee, block] = await Promise.all([
|
|
87
|
+
provider.rpcClient.request({
|
|
88
|
+
method: GAS_PRICE_RPC_METHODS_BY_BUNDLER[provider.bundlerProvider] ??
|
|
89
|
+
"eth_maxPriorityFeePerGas",
|
|
90
|
+
params: [],
|
|
91
|
+
}),
|
|
86
92
|
provider.rpcClient.getBlock({ blockTag: "latest" }),
|
|
87
93
|
]);
|
|
94
|
+
if (provider.bundlerProvider === "PIMLICO") {
|
|
95
|
+
fee = fee.standard.maxPriorityFeePerGas;
|
|
96
|
+
}
|
|
88
97
|
const tip = BigInt(fee);
|
|
89
98
|
const buffer = (tip / 100n) * 13n;
|
|
90
99
|
let maxPriorityFeePerGas = tip + buffer;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"gas-estimator.js","sourceRoot":"","sources":["../../../../src/kernel-zerodev/middleware/gas-estimator.ts"],"names":[],"mappings":"AACA,OAAO,EACL,WAAW,EAGX,iBAAiB,GAGlB,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EAAE,kBAAkB,EAAE,MAAM,iBAAiB,CAAC;AACrD,OAAO,EAAE,sBAAsB,EAAE,MAAM,uCAAuC,CAAC;AAE/E,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,IAAI,EAAE;YACvC,oBAAoB,EAAE,MAAM,CAAC,oBAAoB,IAAI,EAAE;SACxD,CAAC,CAAC;QAE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nC;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\";\n\nexport const withZeroDevGasEstimator = (\n provider: ZeroDevProvider\n): ZeroDevProvider => {\n provider.withFeeDataGetter(async (struct) => {\n let overrides = await resolveProperties({\n maxFeePerGas: struct.maxFeePerGas ?? 0n,\n maxPriorityFeePerGas: struct.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 (\n maxFeePerGas < BigInt(overrides.maxFeePerGas) ||\n maxPriorityFeePerGas < BigInt(overrides.maxPriorityFeePerGas)\n ) {\n return overrides;\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 eip1559GasPrice = async (provider: ZeroDevProvider) => {\n const [fee, block] = await Promise.all([\n provider.bundlerProvider === \"ALCHEMY\"\n ? (provider.rpcClient.request({\n // @ts-expect-error\n method: \"rundler_maxPriorityFeePerGas\",\n }) as Promise<Hex>)\n : provider.rpcClient.getMaxPriorityFeePerGas(),\n provider.rpcClient.getBlock({ blockTag: \"latest\" }),\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,IAAI,EAAE;YACvC,oBAAoB,EAAE,MAAM,CAAC,oBAAoB,IAAI,EAAE;SACxD,CAAC,CAAC;QAEH,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,CAAC;YAC3C,YAAY,GAAG,OAAO,EAAE,YAAY,CAAC,CAAC,CAAC,MAAM,CAAC,OAAO,EAAE,YAAY,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;YAC1E,oBAAoB,GAAG,OAAO,CAAC,oBAAoB;gBACjD,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,oBAAoB,CAAC;gBACtC,CAAC,CA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ex,\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 ?? 0n,\n maxPriorityFeePerGas: struct.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 (\n maxFeePerGas < BigInt(overrides.maxFeePerGas) ||\n maxPriorityFeePerGas < BigInt(overrides.maxPriorityFeePerGas)\n ) {\n return overrides;\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};\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 +1 @@
|
|
|
1
|
-
{"version":3,"file":"create-client.d.ts","sourceRoot":"","sources":["../../../../src/kernel-zerodev/client/create-client.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,KAAK,mBAAmB,EAExB,KAAK,aAAa,EACnB,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EAA4B,KAAK,KAAK,EAAU,MAAM,MAAM,CAAC;AAEpE,OAAO,KAAK,EAAE,4BAA4B,EAAE,MAAM,uBAAuB,CAAC;AAE1E,UAAU,mBAAmB;IAC3B,KAAK,EAAE,KAAK,CAAC;IACb,SAAS,EAAE,MAAM,CAAC;IAClB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,eAAe,CAAC,EAAE,4BAA4B,CAAC;CAChD;
|
|
1
|
+
{"version":3,"file":"create-client.d.ts","sourceRoot":"","sources":["../../../../src/kernel-zerodev/client/create-client.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,KAAK,mBAAmB,EAExB,KAAK,aAAa,EACnB,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EAA4B,KAAK,KAAK,EAAU,MAAM,MAAM,CAAC;AAEpE,OAAO,KAAK,EAAE,4BAA4B,EAAE,MAAM,uBAAuB,CAAC;AAE1E,UAAU,mBAAmB;IAC3B,KAAK,EAAE,KAAK,CAAC;IACb,SAAS,EAAE,MAAM,CAAC;IAClB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,eAAe,CAAC,EAAE,4BAA4B,CAAC;CAChD;AAqBD,eAAO,MAAM,gCAAgC,mDAK1C,mBAAmB,KAAG,oBAAoB,aAAa,CAoCzD,CAAC"}
|
|
@@ -1,8 +1,12 @@
|
|
|
1
1
|
import type { ZeroDevProvider } from "../provider.js";
|
|
2
2
|
import { type UserOperationStruct, type BigNumberish } from "@alchemy/aa-core";
|
|
3
|
+
import { type PaymasterAndBundlerProviders } from "../paymaster/types.js";
|
|
3
4
|
export declare const withZeroDevGasEstimator: (provider: ZeroDevProvider) => ZeroDevProvider;
|
|
4
5
|
export declare const estimateCreationGas: (provider: ZeroDevProvider, initCode?: string) => Promise<bigint>;
|
|
5
6
|
export declare const getPreVerificationGas: (userOp: Partial<UserOperationStruct>) => Promise<number>;
|
|
7
|
+
export declare const GAS_PRICE_RPC_METHODS_BY_BUNDLER: {
|
|
8
|
+
[K in PaymasterAndBundlerProviders]: string;
|
|
9
|
+
};
|
|
6
10
|
export declare const eip1559GasPrice: (provider: ZeroDevProvider) => Promise<{
|
|
7
11
|
maxFeePerGas: bigint;
|
|
8
12
|
maxPriorityFeePerGas: bigint;
|
|
@@ -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;
|
|
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,eAkFF,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;CAK5C,CAAC;AAEF,eAAO,MAAM,eAAe,aAAoB,eAAe;;;EA4B9D,CAAC;AACF,UAAU,OAAO;IACf,YAAY,EAAE,YAAY,GAAG,IAAI,CAAC;IAClC,oBAAoB,EAAE,YAAY,GAAG,IAAI,CAAC;CAC3C;AAED,eAAO,MAAM,UAAU,aACX,eAAe,KACxB,QAAQ,OAAO,CAgCjB,CAAC"}
|
package/package.json
CHANGED
|
@@ -102,6 +102,6 @@ export const CHAIN_ID_TO_NODE: { [key: number]: string } = {
|
|
|
102
102
|
10200: "https://nd-810-853-201.p2pify.com/e828b09f0d43591de96c297b3f36fffd",
|
|
103
103
|
59144: `https://linea-mainnet.infura.io/v3/${INFURA_API_KEY}`,
|
|
104
104
|
59140: `https://linea-goerli.infura.io/v3/${INFURA_API_KEY}`,
|
|
105
|
-
204:
|
|
105
|
+
204: "https://opbnb.rpc.thirdweb.com/eed98c1f30120c0508f17c1f01d3102b",
|
|
106
106
|
// 5611: 'opBnb-testnet',
|
|
107
107
|
};
|
|
@@ -9,6 +9,7 @@ import {
|
|
|
9
9
|
} from "@alchemy/aa-core";
|
|
10
10
|
import { ENTRYPOINT_ADDRESS } from "../constants.js";
|
|
11
11
|
import { calcPreVerificationGas } from "../utils/calc-pre-verification-gas.js";
|
|
12
|
+
import { type PaymasterAndBundlerProviders } from "../paymaster/types.js";
|
|
12
13
|
|
|
13
14
|
export const withZeroDevGasEstimator = (
|
|
14
15
|
provider: ZeroDevProvider
|
|
@@ -121,17 +122,30 @@ export const getPreVerificationGas = async (
|
|
|
121
122
|
return calcPreVerificationGas(p);
|
|
122
123
|
};
|
|
123
124
|
|
|
125
|
+
export const GAS_PRICE_RPC_METHODS_BY_BUNDLER: {
|
|
126
|
+
[K in PaymasterAndBundlerProviders]: string;
|
|
127
|
+
} = {
|
|
128
|
+
STACKUP: "eth_maxPriorityFeePerGas",
|
|
129
|
+
ALCHEMY: "rundler_maxPriorityFeePerGas",
|
|
130
|
+
PIMLICO: "pimlico_getUserOperationGasPrice",
|
|
131
|
+
};
|
|
132
|
+
|
|
124
133
|
export const eip1559GasPrice = async (provider: ZeroDevProvider) => {
|
|
125
|
-
|
|
126
|
-
provider.
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
:
|
|
134
|
+
let [fee, block] = await Promise.all([
|
|
135
|
+
provider.rpcClient.request({
|
|
136
|
+
method:
|
|
137
|
+
// @ts-expect-error
|
|
138
|
+
GAS_PRICE_RPC_METHODS_BY_BUNDLER[provider.bundlerProvider] ??
|
|
139
|
+
"eth_maxPriorityFeePerGas",
|
|
140
|
+
params: [],
|
|
141
|
+
}) as any,
|
|
132
142
|
provider.rpcClient.getBlock({ blockTag: "latest" }),
|
|
133
143
|
]);
|
|
134
144
|
|
|
145
|
+
if (provider.bundlerProvider === "PIMLICO") {
|
|
146
|
+
fee = fee.standard.maxPriorityFeePerGas;
|
|
147
|
+
}
|
|
148
|
+
|
|
135
149
|
const tip = BigInt(fee);
|
|
136
150
|
const buffer = (tip / 100n) * 13n;
|
|
137
151
|
let maxPriorityFeePerGas = tip + buffer;
|