@zerodev/sdk 4.2.0 → 4.2.2

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.
Files changed (28) hide show
  1. package/dist/cjs/kernel-zerodev/client/create-client.js +1 -0
  2. package/dist/cjs/kernel-zerodev/client/create-client.js.map +1 -1
  3. package/dist/cjs/kernel-zerodev/constants.js +3 -0
  4. package/dist/cjs/kernel-zerodev/constants.js.map +1 -1
  5. package/dist/cjs/kernel-zerodev/middleware/gas-estimator.js +5 -1
  6. package/dist/cjs/kernel-zerodev/middleware/gas-estimator.js.map +1 -1
  7. package/dist/cjs/kernel-zerodev/provider.d.ts +1 -0
  8. package/dist/cjs/kernel-zerodev/provider.js +7 -0
  9. package/dist/cjs/kernel-zerodev/provider.js.map +1 -1
  10. package/dist/esm/kernel-zerodev/client/create-client.js +1 -0
  11. package/dist/esm/kernel-zerodev/client/create-client.js.map +1 -1
  12. package/dist/esm/kernel-zerodev/constants.js +3 -0
  13. package/dist/esm/kernel-zerodev/constants.js.map +1 -1
  14. package/dist/esm/kernel-zerodev/middleware/gas-estimator.js +5 -1
  15. package/dist/esm/kernel-zerodev/middleware/gas-estimator.js.map +1 -1
  16. package/dist/esm/kernel-zerodev/provider.d.ts +1 -0
  17. package/dist/esm/kernel-zerodev/provider.js +7 -0
  18. package/dist/esm/kernel-zerodev/provider.js.map +1 -1
  19. package/dist/types/kernel-zerodev/client/create-client.d.ts.map +1 -1
  20. package/dist/types/kernel-zerodev/constants.d.ts.map +1 -1
  21. package/dist/types/kernel-zerodev/middleware/gas-estimator.d.ts.map +1 -1
  22. package/dist/types/kernel-zerodev/provider.d.ts +1 -0
  23. package/dist/types/kernel-zerodev/provider.d.ts.map +1 -1
  24. package/package.json +1 -1
  25. package/src/kernel-zerodev/client/create-client.ts +1 -0
  26. package/src/kernel-zerodev/constants.ts +4 -0
  27. package/src/kernel-zerodev/middleware/gas-estimator.ts +6 -1
  28. package/src/kernel-zerodev/provider.ts +2 -0
@@ -12,6 +12,7 @@ function isMethodInErc4337RpcSchema(variable) {
12
12
  "eth_getUserOperationByHash",
13
13
  "eth_supportedEntryPoints",
14
14
  "eth_maxPriorityFeePerGas",
15
+ "rundler_maxPriorityFeePerGas",
15
16
  ].includes(variable);
16
17
  }
17
18
  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;KAE7B,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 ] 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"]}
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;KAEjC,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 ] 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"]}
@@ -66,5 +66,8 @@ exports.CHAIN_ID_TO_NODE = {
66
66
  84531: "https://icy-long-mountain.base-goerli.quiknode.pro/5b80d93e97cc9412a63c10a30841869abbef9596/",
67
67
  100: "https://thrilling-fluent-film.xdai.quiknode.pro/305955cffb9868cdd95b5e3dc9775f20678ad9ac/",
68
68
  10200: "https://nd-810-853-201.p2pify.com/e828b09f0d43591de96c297b3f36fffd",
69
+ 59144: `https://linea-mainnet.infura.io/v3/${exports.INFURA_API_KEY}`,
70
+ 59140: `https://linea-goerli.infura.io/v3/${exports.INFURA_API_KEY}`,
71
+ 204: 'https://opbnb.rpc.thirdweb.com/eed98c1f30120c0508f17c1f01d3102b',
69
72
  };
70
73
  //# sourceMappingURL=constants.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"constants.js","sourceRoot":"","sources":["../../../src/kernel-zerodev/constants.ts"],"names":[],"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D,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;CAC5E,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};\n"]}
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,4CAA4C;QAEnD,KAAK,EAAE,4CAA4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,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"]}
@@ -84,7 +84,11 @@ const getPreVerificationGas = async (userOp) => {
84
84
  exports.getPreVerificationGas = getPreVerificationGas;
85
85
  const eip1559GasPrice = async (provider) => {
86
86
  const [fee, block] = await Promise.all([
87
- provider.rpcClient.getMaxPriorityFeePerGas(),
87
+ provider.bundlerProvider === "ALCHEMY"
88
+ ? provider.rpcClient.request({
89
+ method: "rundler_maxPriorityFeePerGas",
90
+ })
91
+ : provider.rpcClient.getMaxPriorityFeePerGas(),
88
92
  provider.rpcClient.getBlock({ blockTag: "latest" }),
89
93
  ]);
90
94
  const tip = BigInt(fee);
@@ -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,Q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AAG,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.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;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,CAAC;gBACtC,CAAC,CAAC,EAAE,CA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,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"]}
@@ -23,6 +23,7 @@ export declare class ZeroDevProvider extends SmartAccountProvider<HttpTransport>
23
23
  protected projectId: string;
24
24
  protected sendTxMaxRetries: number;
25
25
  protected sendTxRetryIntervalMs: number;
26
+ readonly bundlerProvider?: PaymasterAndBundlerProviders;
26
27
  constructor({ projectId, chain, entryPointAddress, rpcUrl, account, bundlerProvider, opts, }: ZeroDevProviderConfig);
27
28
  getProjectId: () => string;
28
29
  sendTransaction: (request: RpcTransactionRequest, operation?: UserOpDataOperationTypes<UserOperationCallData>) => Promise<Hash>;
@@ -49,6 +49,12 @@ class ZeroDevProvider extends aa_core_1.SmartAccountProvider {
49
49
  writable: true,
50
50
  value: void 0
51
51
  });
52
+ Object.defineProperty(this, "bundlerProvider", {
53
+ enumerable: true,
54
+ configurable: true,
55
+ writable: true,
56
+ value: void 0
57
+ });
52
58
  Object.defineProperty(this, "getProjectId", {
53
59
  enumerable: true,
54
60
  configurable: true,
@@ -262,6 +268,7 @@ class ZeroDevProvider extends aa_core_1.SmartAccountProvider {
262
268
  }
263
269
  }
264
270
  });
271
+ this.bundlerProvider = bundlerProvider;
265
272
  this.projectId = projectId;
266
273
  this.sendTxMaxRetries =
267
274
  opts?.sendTxMaxRetries ?? constants_js_1.DEFAULT_SEND_TX_MAX_RETRIES;
@@ -1 +1 @@
1
- {"version":3,"file":"provider.js","sourceRoot":"","sources":["../../../src/kernel-zerodev/provider.ts"],"names":[],"mappings":";;;AAAA,+BAQc;AACd,8CAe0B;AAC1B,iDAMwB;AACxB,6CAA2E;AAC3E,oEAAwE;AACxE,+DAA0D;AAC1D,2CAA+C;AAC/C,4DAAwE;AACxE,gEAA6E;AAoB7E,IAAY,SAGX;AAHD,WAAY,SAAS;IACnB,yCAAQ,CAAA;IACR,yDAAgB,CAAA;AAClB,CAAC,EAHW,SAAS,yBAAT,SAAS,QAGpB;AAQD,MAAa,eAAgB,SAAQ,8BAAmC;IAKtE,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,kBAAQ,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,EA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I,IAAI,EAAE;YAC1B,IAAI,aAAa,GAAW,EAAE,CAAC;YAC/B,IAAI,eAAe,GAAuB,OAAO,EAAE,KAAK,EAAE,OAAO,CAAC;YAClE,IAAI,eAAe,EAAE,QAAQ,CAAC,UAAU,CAAC,KAAK,IAAI,EAAE;gBAElD,MAAM,OAAO,GAAG,eAAe,CAAC,KAAK,CAAC,kBAAkB,CAAC,CAAC;gBAC1D,IAAI,OAAO,IAAI,IAAI,EAAE;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;IAgBD,2BAA2B,CAAC,MAAwC;QAClE,IAAI,CAAC,IAAI,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;AA9VD,0CA8VC","sourcesContent":["import {\n fromHex,\n type Address,\n type Chain,\n type Hash,\n type Hex,\n type HttpTransport,\n type RpcTransactionRequest,\n} from \"viem\";\nimport {\n deepHexlify,\n resolveProperties,\n type SmartAccountProviderOpts,\n getChain,\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} 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\";\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\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 ?? 10,\n txRetryIntervalMs: opts?.txRetryIntervalMs ?? 10000,\n minPriorityFeePerBid:\n opts?.minPriorityFeePerBid ??\n minPriorityFeePerBidDefaults.get(_chain.id),\n });\n\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 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 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 return 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 };\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 (!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 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","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AK,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;IAgBD,2BAA2B,CAAC,MAAwC;QAClE,IAAI,CAAC,IAAI,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;AAhWD,0CAgWC","sourcesContent":["import {\n fromHex,\n type Address,\n type Chain,\n type Hash,\n type Hex,\n type HttpTransport,\n type RpcTransactionRequest,\n} from \"viem\";\nimport {\n deepHexlify,\n resolveProperties,\n type SmartAccountProviderOpts,\n getChain,\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} 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\";\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\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 ?? 10,\n txRetryIntervalMs: opts?.txRetryIntervalMs ?? 10000,\n minPriorityFeePerBid:\n opts?.minPriorityFeePerBid ??\n minPriorityFeePerBidDefaults.get(_chain.id),\n });\n\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 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 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 return 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 };\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 (!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 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"]}
@@ -9,6 +9,7 @@ function isMethodInErc4337RpcSchema(variable) {
9
9
  "eth_getUserOperationByHash",
10
10
  "eth_supportedEntryPoints",
11
11
  "eth_maxPriorityFeePerGas",
12
+ "rundler_maxPriorityFeePerGas",
12
13
  ].includes(variable);
13
14
  }
14
15
  export const createZeroDevPublicErc4337Client = ({ chain, rpcUrl, projectId, bundlerProvider, }) => {
@@ -1 +1 @@
1
- {"version":3,"file":"create-client.js","sourceRoot":"","sources":["../../../../src/kernel-zerodev/client/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,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 ] 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"]}
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;KAEjC,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 ] 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"]}
@@ -63,5 +63,8 @@ export const CHAIN_ID_TO_NODE = {
63
63
  84531: "https://icy-long-mountain.base-goerli.quiknode.pro/5b80d93e97cc9412a63c10a30841869abbef9596/",
64
64
  100: "https://thrilling-fluent-film.xdai.quiknode.pro/305955cffb9868cdd95b5e3dc9775f20678ad9ac/",
65
65
  10200: "https://nd-810-853-201.p2pify.com/e828b09f0d43591de96c297b3f36fffd",
66
+ 59144: `https://linea-mainnet.infura.io/v3/${INFURA_API_KEY}`,
67
+ 59140: `https://linea-goerli.infura.io/v3/${INFURA_API_KEY}`,
68
+ 204: 'https://opbnb.rpc.thirdweb.com/eed98c1f30120c0508f17c1f01d3102b',
66
69
  };
67
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,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cAAc,EAAE;IAC7D,KAAK,EAAE,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;CAC5E,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};\n"]}
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,mBAAmB,GAAG,4CAA4C,CAAC;AAChF,MAAM,CAAC,MAAM,6BAA6B,GACxC,4CAA4C,CAAC;AAC/C,MAAM,CAAC,MAAM,kBAAkB,GAAG,4CAA4C,CAAC;AAC/E,MAAM,CAAC,MAAM,eAAe,GAC1B,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AE,CAAC;IAE/D,4CAA4C,EAAE,UAAU,CAAC,KAAK,EAAE,EAAE,CAAC;CACpE,CAAC;AAEF,MAAM,CAAC,MAAM,4BAA4B,GAAG,IAAI,GAAG,CAAiB;IAClE,CAAC,OAAO,CAAC,EAAE,EAAE,YAAe,CAAC;CAC9B,CAAC,CAAC;AAEH,MAAM,CAAC,MAAM,cAAc,GAAG,kCAAkC,CAAC;AACjE,MAAM,CAAC,MAAM,gBAAgB,GAA8B;IACzD,CAAC,EAAE,gCAAgC,cAAc,EAAE;IACnD,CAAC,EAAE,+BAA+B,cAAc,EAAE;IAClD,QAAQ,EACN,oGAAoG;IACtG,GAAG,EAAE,wCAAwC,cAAc,EAAE;IAC7D,KAAK,EAAE,uCAAuC,cAAc,EAAE;IAC9D,EAAE,EAAE,yCAAyC,cAAc,EAAE;IAC7D,GAAG,EAAE,wCAAwC,cAAc,EAAE;IAC7D,KAAK,EAAE,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: 'https://opbnb.rpc.thirdweb.com/eed98c1f30120c0508f17c1f01d3102b',\n // 5611: 'opBnb-testnet',\n};\n"]}
@@ -78,7 +78,11 @@ export const getPreVerificationGas = async (userOp) => {
78
78
  };
79
79
  export const eip1559GasPrice = async (provider) => {
80
80
  const [fee, block] = await Promise.all([
81
- provider.rpcClient.getMaxPriorityFeePerGas(),
81
+ provider.bundlerProvider === "ALCHEMY"
82
+ ? provider.rpcClient.request({
83
+ method: "rundler_maxPriorityFeePerGas",
84
+ })
85
+ : provider.rpcClient.getMaxPriorityFeePerGas(),
82
86
  provider.rpcClient.getBlock({ blockTag: "latest" }),
83
87
  ]);
84
88
  const tip = BigInt(fee);
@@ -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;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,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,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","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.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;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;QAEH,IAAI,YAAY,EAAE,oBAAoB,CAAC;QAEvC,IAAI;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C,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"]}
@@ -23,6 +23,7 @@ export declare class ZeroDevProvider extends SmartAccountProvider<HttpTransport>
23
23
  protected projectId: string;
24
24
  protected sendTxMaxRetries: number;
25
25
  protected sendTxRetryIntervalMs: number;
26
+ readonly bundlerProvider?: PaymasterAndBundlerProviders;
26
27
  constructor({ projectId, chain, entryPointAddress, rpcUrl, account, bundlerProvider, opts, }: ZeroDevProviderConfig);
27
28
  getProjectId: () => string;
28
29
  sendTransaction: (request: RpcTransactionRequest, operation?: UserOpDataOperationTypes<UserOperationCallData>) => Promise<Hash>;
@@ -46,6 +46,12 @@ export class ZeroDevProvider extends SmartAccountProvider {
46
46
  writable: true,
47
47
  value: void 0
48
48
  });
49
+ Object.defineProperty(this, "bundlerProvider", {
50
+ enumerable: true,
51
+ configurable: true,
52
+ writable: true,
53
+ value: void 0
54
+ });
49
55
  Object.defineProperty(this, "getProjectId", {
50
56
  enumerable: true,
51
57
  configurable: true,
@@ -259,6 +265,7 @@ export class ZeroDevProvider extends SmartAccountProvider {
259
265
  }
260
266
  }
261
267
  });
268
+ this.bundlerProvider = bundlerProvider;
262
269
  this.projectId = projectId;
263
270
  this.sendTxMaxRetries =
264
271
  opts?.sendTxMaxRetries ?? DEFAULT_SEND_TX_MAX_RETRIES;
@@ -1 +1 @@
1
- {"version":3,"file":"provider.js","sourceRoot":"","sources":["../../../src/kernel-zerodev/provider.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,OAAO,GAOR,MAAM,MAAM,CAAC;AACd,OAAO,EACL,WAAW,EACX,iBAAiB,EAEjB,QAAQ,EAIR,SAAS,EACT,cAAc,EAGd,oBAAoB,GAGrB,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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AAC,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;IAgBD,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} from \"viem\";\nimport {\n deepHexlify,\n resolveProperties,\n type SmartAccountProviderOpts,\n getChain,\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} 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\";\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\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 ?? 10,\n txRetryIntervalMs: opts?.txRetryIntervalMs ?? 10000,\n minPriorityFeePerBid:\n opts?.minPriorityFeePerBid ??\n minPriorityFeePerBidDefaults.get(_chain.id),\n });\n\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 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 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 return 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 };\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 (!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 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,GAOR,MAAM,MAAM,CAAC;AACd,OAAO,EACL,WAAW,EACX,iBAAiB,EAEjB,QAAQ,EAIR,SAAS,EACT,cAAc,EAGd,oBAAoB,GAGrB,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,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,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;IAgBD,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} from \"viem\";\nimport {\n deepHexlify,\n resolveProperties,\n type SmartAccountProviderOpts,\n getChain,\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} 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\";\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\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 ?? 10,\n txRetryIntervalMs: opts?.txRetryIntervalMs ?? 10000,\n minPriorityFeePerBid:\n opts?.minPriorityFeePerBid ??\n minPriorityFeePerBidDefaults.get(_chain.id),\n });\n\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 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 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 return 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 };\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 (!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 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":"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;AAmBD,eAAO,MAAM,gCAAgC,mDAK1C,mBAAmB,KAAG,oBAAoB,aAAa,CAoCzD,CAAC"}
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;AAoBD,eAAO,MAAM,gCAAgC,mDAK1C,mBAAmB,KAAG,oBAAoB,aAAa,CAoCzD,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../../../src/kernel-zerodev/constants.ts"],"names":[],"mappings":"AAAA,OAAO,EAAc,KAAK,GAAG,EAAE,MAAM,MAAM,CAAC;AAC5C,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAG/D,eAAO,MAAM,2BAA2B,IAAI,CAAC;AAC7C,eAAO,MAAM,iCAAiC,QAAQ,CAAC;AACvD,eAAO,MAAM,WAAW,2CAA2C,CAAC;AACpE,eAAO,MAAM,aAAa,2DACgC,CAAC;AAC3D,eAAO,MAAM,kBAAkB,EAAE,GACa,CAAC;AAC/C,eAAO,MAAM,cAAc,EAAE,GAAkD,CAAC;AAChF,eAAO,MAAM,WAAW,sCAAsC,CAAC;AAC/D,eAAO,MAAM,OAAO,iCAAiC,CAAC;AACtD,eAAO,MAAM,uBAAuB,+CACU,CAAC;AAC/C,eAAO,MAAM,sBAAsB,+CACW,CAAC;AAC/C,eAAO,MAAM,mBAAmB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,CAGhB,CAAC;AAEF,eAAO,MAAM,eAAe,aAAoB,eAAe;;;EAkB9D,CAAC;AACF,UAAU,OAAO;IACf,YAAY,EAAE,YAAY,GAAG,IAAI,CAAC;IAClC,oBAAoB,EAAE,YAAY,GAAG,IAAI,CAAC;CAC3C;AAED,eAAO,MAAM,UAAU,aACX,eAAe,KACxB,QAAQ,OAAO,CAgCjB,CAAC"}
1
+ {"version":3,"file":"gas-estimator.d.ts","sourceRoot":"","sources":["../../../../src/kernel-zerodev/middleware/gas-estimator.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAC;AACtD,OAAO,EAGL,KAAK,mBAAmB,EAExB,KAAK,YAAY,EAElB,MAAM,kBAAkB,CAAC;AAI1B,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,eAAe,aAAoB,eAAe;;;EAuB9D,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"}
@@ -23,6 +23,7 @@ export declare class ZeroDevProvider extends SmartAccountProvider<HttpTransport>
23
23
  protected projectId: string;
24
24
  protected sendTxMaxRetries: number;
25
25
  protected sendTxRetryIntervalMs: number;
26
+ readonly bundlerProvider?: PaymasterAndBundlerProviders;
26
27
  constructor({ projectId, chain, entryPointAddress, rpcUrl, account, bundlerProvider, opts, }: ZeroDevProviderConfig);
27
28
  getProjectId: () => string;
28
29
  sendTransaction: (request: RpcTransactionRequest, operation?: UserOpDataOperationTypes<UserOperationCallData>) => Promise<Hash>;
@@ -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,EAC3B,MAAM,MAAM,CAAC;AACd,OAAO,EAGL,KAAK,wBAAwB,EAE7B,KAAK,qBAAqB,EAC1B,KAAK,0BAA0B,EAC/B,KAAK,uBAAuB,EAG5B,KAAK,mBAAmB,EAExB,oBAAoB,EACpB,KAAK,mBAAmB,EACxB,KAAK,sBAAsB,EAC5B,MAAM,kBAAkB,CAAC;AAQ1B,OAAO,EAAE,0BAA0B,EAAmB,MAAM,cAAc,CAAC;AAM3E,OAAO,KAAK,EACV,4BAA4B,EAC5B,eAAe,EACf,eAAe,EAChB,MAAM,sBAAsB,CAAC;AAE9B,MAAM,MAAM,qBAAqB,GAAG;IAClC,SAAS,EAAE,MAAM,CAAC;IAClB,KAAK,EAAE,KAAK,GAAG,MAAM,CAAC;IACtB,iBAAiB,CAAC,EAAE,OAAO,CAAC;IAC5B,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,OAAO,CAAC,EAAE,0BAA0B,CAAC;IACrC,eAAe,CAAC,EAAE,4BAA4B,CAAC;IAC/C,IAAI,CAAC,EAAE,wBAAwB,GAAG;QAChC,gBAAgB,CAAC,EAAE,MAAM,CAAC;QAC1B,qBAAqB,CAAC,EAAE,MAAM,CAAC;KAChC,CAAC;CACH,CAAC;AAEF,oBAAY,SAAS;IACnB,IAAI,IAAI;IACR,YAAY,IAAI;CACjB;AAED,KAAK,wBAAwB,CAAC,CAAC,IAAI,CAAC,SAAS,qBAAqB,GAC9D,SAAS,CAAC,IAAI,GAAG,SAAS,CAAC,YAAY,GACvC,CAAC,SAAS,0BAA0B,GACpC,SAAS,CAAC,IAAI,GACd,KAAK,C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oB,EACpB,OAAO,EACP,eAAe,EACf,IAAI,GACL,EAAE,qBAAqB;IA4BxB,YAAY,QAAO,MAAM,CAAmB;IAE5C,eAAe,YACJ,qBAAqB,cACnB,yBAAyB,qBAAqB,CAAC,KACzD,QAAQ,IAAI,CAAC,CAwBd;IAEF,kBAAkB,sFAIJ,sBAAsB,8CAEjC,QAAQ,mBAAmB,CAAC,CAkD7B;IAEF,OAAO,CAAC,mBAAmB,CAczB;IAEF,iBAAiB,sFAIH,sBAAsB,8CAEjC,QAAQ,uBAAuB,CAAC,CA2GjC;IAEF,oBAAoB,CAAC,OAAO,EAAE,GAAG,GAAG,OAAO;IAc3C,WAAW,CAAC,OAAO,EAAE,GAAG,GAAG,KAAK;IAsBhC,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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zerodev/sdk",
3
- "version": "4.2.0",
3
+ "version": "4.2.2",
4
4
  "description": "A collection of ERC-4337 compliant smart contract account interfaces",
5
5
  "author": "ZeroDev",
6
6
  "license": "MIT",
@@ -28,6 +28,7 @@ function isMethodInErc4337RpcSchema(
28
28
  "eth_getUserOperationByHash",
29
29
  "eth_supportedEntryPoints",
30
30
  "eth_maxPriorityFeePerGas",
31
+ "rundler_maxPriorityFeePerGas",
31
32
  ] as const
32
33
  ).includes(variable as MethodsOfErc4337RpcSchema);
33
34
  }
@@ -100,4 +100,8 @@ export const CHAIN_ID_TO_NODE: { [key: number]: string } = {
100
100
  "https://icy-long-mountain.base-goerli.quiknode.pro/5b80d93e97cc9412a63c10a30841869abbef9596/",
101
101
  100: "https://thrilling-fluent-film.xdai.quiknode.pro/305955cffb9868cdd95b5e3dc9775f20678ad9ac/",
102
102
  10200: "https://nd-810-853-201.p2pify.com/e828b09f0d43591de96c297b3f36fffd",
103
+ 59144: `https://linea-mainnet.infura.io/v3/${INFURA_API_KEY}`,
104
+ 59140: `https://linea-goerli.infura.io/v3/${INFURA_API_KEY}`,
105
+ 204: 'https://opbnb.rpc.thirdweb.com/eed98c1f30120c0508f17c1f01d3102b',
106
+ // 5611: 'opBnb-testnet',
103
107
  };
@@ -123,7 +123,12 @@ export const getPreVerificationGas = async (
123
123
 
124
124
  export const eip1559GasPrice = async (provider: ZeroDevProvider) => {
125
125
  const [fee, block] = await Promise.all([
126
- provider.rpcClient.getMaxPriorityFeePerGas(),
126
+ provider.bundlerProvider === "ALCHEMY"
127
+ ? (provider.rpcClient.request({
128
+ // @ts-expect-error
129
+ method: "rundler_maxPriorityFeePerGas",
130
+ }) as Promise<Hex>)
131
+ : provider.rpcClient.getMaxPriorityFeePerGas(),
127
132
  provider.rpcClient.getBlock({ blockTag: "latest" }),
128
133
  ]);
129
134
 
@@ -70,6 +70,7 @@ export class ZeroDevProvider extends SmartAccountProvider<HttpTransport> {
70
70
  protected projectId: string;
71
71
  protected sendTxMaxRetries: number;
72
72
  protected sendTxRetryIntervalMs: number;
73
+ readonly bundlerProvider?: PaymasterAndBundlerProviders;
73
74
 
74
75
  constructor({
75
76
  projectId,
@@ -97,6 +98,7 @@ export class ZeroDevProvider extends SmartAccountProvider<HttpTransport> {
97
98
  minPriorityFeePerBidDefaults.get(_chain.id),
98
99
  });
99
100
 
101
+ this.bundlerProvider = bundlerProvider;
100
102
  this.projectId = projectId;
101
103
  this.sendTxMaxRetries =
102
104
  opts?.sendTxMaxRetries ?? DEFAULT_SEND_TX_MAX_RETRIES;