@zerodev/sdk 5.1.13 → 5.2.0-alpha-1

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 (123) hide show
  1. package/_cjs/accounts/kernel/abi/kernel_v_3_0_0/KernelAccountAbi.js +738 -0
  2. package/_cjs/accounts/kernel/abi/kernel_v_3_0_0/KernelAccountAbi.js.map +1 -0
  3. package/_cjs/accounts/kernel/abi/kernel_v_3_0_0/KernelModuleAbi.js +15 -0
  4. package/_cjs/accounts/kernel/abi/kernel_v_3_0_0/KernelModuleAbi.js.map +1 -0
  5. package/_cjs/accounts/kernel/createKernelAccount.js +235 -75
  6. package/_cjs/accounts/kernel/createKernelAccount.js.map +1 -1
  7. package/_cjs/accounts/kernel/v1/createKernelV1Account.js +29 -18
  8. package/_cjs/accounts/kernel/v1/createKernelV1Account.js.map +1 -1
  9. package/_cjs/accounts/utils/6492.js +19 -3
  10. package/_cjs/accounts/utils/6492.js.map +1 -1
  11. package/_cjs/accounts/utils/index.js +4 -3
  12. package/_cjs/accounts/utils/index.js.map +1 -1
  13. package/_cjs/accounts/utils/toKernelPluginManager.js +194 -62
  14. package/_cjs/accounts/utils/toKernelPluginManager.js.map +1 -1
  15. package/_cjs/actions/account-client/signUserOperation.js +1 -1
  16. package/_cjs/actions/account-client/signUserOperation.js.map +1 -1
  17. package/_cjs/actions/paymaster/estimateGasInERC20.js.map +1 -1
  18. package/_cjs/actions/paymaster/sponsorUserOperation.js +17 -14
  19. package/_cjs/actions/paymaster/sponsorUserOperation.js.map +1 -1
  20. package/_cjs/clients/decorators/kernel.js +8 -5
  21. package/_cjs/clients/decorators/kernel.js.map +1 -1
  22. package/_cjs/clients/kernelAccountClient.js +3 -3
  23. package/_cjs/clients/kernelAccountClient.js.map +1 -1
  24. package/_cjs/clients/paymasterClient.js +1 -1
  25. package/_cjs/clients/paymasterClient.js.map +1 -1
  26. package/_cjs/constants.js +28 -3
  27. package/_cjs/constants.js.map +1 -1
  28. package/_cjs/index.js +5 -1
  29. package/_cjs/index.js.map +1 -1
  30. package/_cjs/providers/KernelEIP1193Provider.js.map +1 -1
  31. package/_cjs/types/kernel.js.map +1 -1
  32. package/_cjs/utils.js +34 -3
  33. package/_cjs/utils.js.map +1 -1
  34. package/_esm/accounts/kernel/abi/kernel_v_3_0_0/KernelAccountAbi.js +735 -0
  35. package/_esm/accounts/kernel/abi/kernel_v_3_0_0/KernelAccountAbi.js.map +1 -0
  36. package/_esm/accounts/kernel/abi/kernel_v_3_0_0/KernelModuleAbi.js +12 -0
  37. package/_esm/accounts/kernel/abi/kernel_v_3_0_0/KernelModuleAbi.js.map +1 -0
  38. package/_esm/accounts/kernel/createKernelAccount.js +244 -81
  39. package/_esm/accounts/kernel/createKernelAccount.js.map +1 -1
  40. package/_esm/accounts/kernel/v1/createKernelV1Account.js +37 -20
  41. package/_esm/accounts/kernel/v1/createKernelV1Account.js.map +1 -1
  42. package/_esm/accounts/utils/6492.js +16 -1
  43. package/_esm/accounts/utils/6492.js.map +1 -1
  44. package/_esm/accounts/utils/index.js +2 -4
  45. package/_esm/accounts/utils/index.js.map +1 -1
  46. package/_esm/accounts/utils/toKernelPluginManager.js +198 -66
  47. package/_esm/accounts/utils/toKernelPluginManager.js.map +1 -1
  48. package/_esm/actions/account-client/signUserOperation.js +1 -1
  49. package/_esm/actions/account-client/signUserOperation.js.map +1 -1
  50. package/_esm/actions/paymaster/estimateGasInERC20.js.map +1 -1
  51. package/_esm/actions/paymaster/sponsorUserOperation.js +37 -15
  52. package/_esm/actions/paymaster/sponsorUserOperation.js.map +1 -1
  53. package/_esm/clients/decorators/kernel.js +9 -5
  54. package/_esm/clients/decorators/kernel.js.map +1 -1
  55. package/_esm/clients/kernelAccountClient.js +3 -3
  56. package/_esm/clients/kernelAccountClient.js.map +1 -1
  57. package/_esm/clients/paymasterClient.js +1 -1
  58. package/_esm/clients/paymasterClient.js.map +1 -1
  59. package/_esm/constants.js +27 -2
  60. package/_esm/constants.js.map +1 -1
  61. package/_esm/index.js +1 -0
  62. package/_esm/index.js.map +1 -1
  63. package/_esm/providers/KernelEIP1193Provider.js.map +1 -1
  64. package/_esm/types/kernel.js +1 -0
  65. package/_esm/types/kernel.js.map +1 -1
  66. package/_esm/utils.js +33 -4
  67. package/_esm/utils.js.map +1 -1
  68. package/_types/accounts/kernel/abi/kernel_v_3_0_0/KernelAccountAbi.d.ts +843 -0
  69. package/_types/accounts/kernel/abi/kernel_v_3_0_0/KernelAccountAbi.d.ts.map +1 -0
  70. package/_types/accounts/kernel/abi/kernel_v_3_0_0/KernelModuleAbi.d.ts +16 -0
  71. package/_types/accounts/kernel/abi/kernel_v_3_0_0/KernelModuleAbi.d.ts.map +1 -0
  72. package/_types/accounts/kernel/createKernelAccount.d.ts +14 -11
  73. package/_types/accounts/kernel/createKernelAccount.d.ts.map +1 -1
  74. package/_types/accounts/kernel/v1/createKernelV1Account.d.ts +5 -4
  75. package/_types/accounts/kernel/v1/createKernelV1Account.d.ts.map +1 -1
  76. package/_types/accounts/utils/6492.d.ts +3 -1
  77. package/_types/accounts/utils/6492.d.ts.map +1 -1
  78. package/_types/accounts/utils/index.d.ts +2 -4
  79. package/_types/accounts/utils/index.d.ts.map +1 -1
  80. package/_types/accounts/utils/toKernelPluginManager.d.ts +3 -2
  81. package/_types/accounts/utils/toKernelPluginManager.d.ts.map +1 -1
  82. package/_types/actions/account-client/signUserOperation.d.ts +7 -7
  83. package/_types/actions/account-client/signUserOperation.d.ts.map +1 -1
  84. package/_types/actions/paymaster/estimateGasInERC20.d.ts +3 -2
  85. package/_types/actions/paymaster/estimateGasInERC20.d.ts.map +1 -1
  86. package/_types/actions/paymaster/sponsorUserOperation.d.ts +7 -6
  87. package/_types/actions/paymaster/sponsorUserOperation.d.ts.map +1 -1
  88. package/_types/clients/decorators/kernel.d.ts +8 -7
  89. package/_types/clients/decorators/kernel.d.ts.map +1 -1
  90. package/_types/clients/kernelAccountClient.d.ts +101 -22
  91. package/_types/clients/kernelAccountClient.d.ts.map +1 -1
  92. package/_types/clients/paymasterClient.d.ts +6 -3
  93. package/_types/clients/paymasterClient.d.ts.map +1 -1
  94. package/_types/constants.d.ts +22 -1
  95. package/_types/constants.d.ts.map +1 -1
  96. package/_types/index.d.ts +1 -0
  97. package/_types/index.d.ts.map +1 -1
  98. package/_types/providers/KernelEIP1193Provider.d.ts +3 -2
  99. package/_types/providers/KernelEIP1193Provider.d.ts.map +1 -1
  100. package/_types/types/kernel.d.ts +44 -12
  101. package/_types/types/kernel.d.ts.map +1 -1
  102. package/_types/utils.d.ts +11 -2
  103. package/_types/utils.d.ts.map +1 -1
  104. package/accounts/kernel/abi/kernel_v_3_0_0/KernelAccountAbi.ts +736 -0
  105. package/accounts/kernel/abi/kernel_v_3_0_0/KernelModuleAbi.ts +11 -0
  106. package/accounts/kernel/createKernelAccount.ts +399 -105
  107. package/accounts/kernel/v1/createKernelV1Account.ts +67 -28
  108. package/accounts/utils/6492.ts +27 -1
  109. package/accounts/utils/index.ts +2 -4
  110. package/accounts/utils/toKernelPluginManager.ts +261 -80
  111. package/actions/account-client/signUserOperation.ts +25 -13
  112. package/actions/paymaster/estimateGasInERC20.ts +5 -4
  113. package/actions/paymaster/sponsorUserOperation.ts +104 -32
  114. package/clients/decorators/kernel.ts +44 -35
  115. package/clients/kernelAccountClient.ts +34 -25
  116. package/clients/paymasterClient.ts +10 -6
  117. package/constants.ts +25 -2
  118. package/index.ts +5 -0
  119. package/package.json +93 -92
  120. package/providers/KernelEIP1193Provider.ts +6 -3
  121. package/types/kernel.ts +96 -40
  122. package/utils.ts +52 -4
  123. package/README.md +0 -3
@@ -1,12 +1,15 @@
1
1
  import {
2
+ ENTRYPOINT_ADDRESS_V06,
2
3
  getAccountNonce,
3
4
  getSenderAddress,
4
- getUserOperationHash
5
+ getUserOperationHash,
6
+ isSmartAccountDeployed
5
7
  } from "permissionless"
6
8
  import {
7
9
  SignTransactionNotSupportedBySmartAccount,
8
10
  type SmartAccountSigner
9
11
  } from "permissionless/accounts"
12
+ import type { EntryPoint } from "permissionless/types/entrypoint.js"
10
13
  import {
11
14
  type Address,
12
15
  type Chain,
@@ -21,12 +24,7 @@ import {
21
24
  encodeFunctionData
22
25
  } from "viem"
23
26
  import { toAccount } from "viem/accounts"
24
- import {
25
- getBytecode,
26
- getChainId,
27
- signMessage,
28
- signTypedData
29
- } from "viem/actions"
27
+ import { getChainId, signMessage, signTypedData } from "viem/actions"
30
28
  import { type KernelEncodeCallDataArgs } from "../../../types/kernel.js"
31
29
  import { wrapSignatureWith6492 } from "../../utils/6492.js"
32
30
  import { parseFactoryAddressAndCallDataFromAccountInitCode } from "../../utils/index.js"
@@ -38,9 +36,13 @@ import {
38
36
  } from "./multisend.js"
39
37
 
40
38
  export type KernelV1SmartAccount<
39
+ entryPoint extends EntryPoint,
41
40
  transport extends Transport = Transport,
42
41
  chain extends Chain | undefined = Chain | undefined
43
- > = Omit<KernelSmartAccount<transport, chain>, "kernelPluginManager">
42
+ > = Omit<
43
+ KernelSmartAccount<entryPoint, transport, chain>,
44
+ "kernelPluginManager"
45
+ >
44
46
 
45
47
  const createAccountAbi = [
46
48
  {
@@ -85,6 +87,7 @@ const KERNEL_V1_ADDRESSES: {
85
87
  }
86
88
 
87
89
  export async function createKernelV1Account<
90
+ entryPoint extends EntryPoint,
88
91
  TTransport extends Transport = Transport,
89
92
  TChain extends Chain | undefined = Chain | undefined,
90
93
  TSource extends string = string,
@@ -93,15 +96,15 @@ export async function createKernelV1Account<
93
96
  client: Client<TTransport, TChain, undefined>,
94
97
  {
95
98
  signer,
96
- entrypoint = KERNEL_V1_ADDRESSES.ENTRYPOINT_V0_6,
99
+ entrypoint: entryPointAddress = ENTRYPOINT_ADDRESS_V06 as entryPoint,
97
100
  index = 0n
98
101
  }: {
99
102
  signer: SmartAccountSigner<TSource, TAddress>
100
- entrypoint?: Address
103
+ entrypoint?: entryPoint
101
104
  index?: bigint
102
105
  }
103
- ): Promise<KernelV1SmartAccount<TTransport, TChain>> {
104
- if (entrypoint !== KERNEL_V1_ADDRESSES.ENTRYPOINT_V0_6) {
106
+ ): Promise<KernelV1SmartAccount<entryPoint, TTransport, TChain>> {
107
+ if (entryPointAddress !== ENTRYPOINT_ADDRESS_V06) {
105
108
  throw new Error("Only EntryPoint 0.6 is supported")
106
109
  }
107
110
 
@@ -129,16 +132,21 @@ export async function createKernelV1Account<
129
132
  const initCode = await generateInitCode()
130
133
  const accountAddress = await getSenderAddress(client, {
131
134
  initCode,
132
- entryPoint: entrypoint
135
+ entryPoint: entryPointAddress
133
136
  })
134
137
 
135
138
  if (!accountAddress) throw new Error("Account address not found")
136
139
 
140
+ let smartAccountDeployed = await isSmartAccountDeployed(
141
+ client,
142
+ accountAddress
143
+ )
144
+
137
145
  const account = toAccount({
138
146
  address: accountAddress,
139
147
  async signMessage({ message }) {
140
148
  const [isDeployed, signature] = await Promise.all([
141
- isAccountDeployed(),
149
+ isSmartAccountDeployed(client, accountAddress),
142
150
  signer.signMessage({ message })
143
151
  ])
144
152
  return create6492Signature(isDeployed, signature)
@@ -162,13 +170,13 @@ export async function createKernelV1Account<
162
170
  }
163
171
  })
164
172
 
165
- const isAccountDeployed = async (): Promise<boolean> => {
166
- const contractCode = await getBytecode(client, {
167
- address: accountAddress
168
- })
173
+ // const isAccountDeployed = async (): Promise<boolean> => {
174
+ // const contractCode = await getBytecode(client, {
175
+ // address: accountAddress
176
+ // })
169
177
 
170
- return (contractCode?.length ?? 0) > 2
171
- }
178
+ // return (contractCode?.length ?? 0) > 2
179
+ // }
172
180
 
173
181
  const create6492Signature = async (
174
182
  isDeployed: boolean,
@@ -194,13 +202,40 @@ export async function createKernelV1Account<
194
202
  ...account,
195
203
  client: client,
196
204
  publicKey: accountAddress,
197
- entryPoint: entrypoint,
205
+ entryPoint: entryPointAddress,
198
206
  source: "kernelSmartAccount",
199
207
  generateInitCode,
208
+ async getFactory() {
209
+ if (smartAccountDeployed) return undefined
210
+
211
+ smartAccountDeployed = await isSmartAccountDeployed(
212
+ client,
213
+ accountAddress
214
+ )
215
+
216
+ if (smartAccountDeployed) return undefined
217
+
218
+ return KERNEL_V1_ADDRESSES.FACTORY_ADDRESS
219
+ },
220
+
221
+ async getFactoryData() {
222
+ if (smartAccountDeployed) return undefined
223
+
224
+ smartAccountDeployed = await isSmartAccountDeployed(
225
+ client,
226
+ accountAddress
227
+ )
228
+
229
+ if (smartAccountDeployed) return undefined
230
+
231
+ return parseFactoryAddressAndCallDataFromAccountInitCode(
232
+ await generateInitCode()
233
+ )[1]
234
+ },
200
235
  async getNonce() {
201
236
  return getAccountNonce(client, {
202
237
  sender: accountAddress,
203
- entryPoint: entrypoint
238
+ entryPoint: entryPointAddress
204
239
  })
205
240
  },
206
241
  async signUserOperation(userOperation) {
@@ -209,7 +244,7 @@ export async function createKernelV1Account<
209
244
  ...userOperation,
210
245
  signature: "0x"
211
246
  },
212
- entryPoint: entrypoint,
247
+ entryPoint: entryPointAddress,
213
248
  chainId: chainId
214
249
  })
215
250
  const signature = await signMessage(client, {
@@ -219,11 +254,15 @@ export async function createKernelV1Account<
219
254
  return signature
220
255
  },
221
256
  async getInitCode() {
222
- if (await isAccountDeployed()) {
223
- return "0x"
224
- } else {
225
- return generateInitCode()
226
- }
257
+ if (smartAccountDeployed) return "0x"
258
+
259
+ smartAccountDeployed = await isSmartAccountDeployed(
260
+ client,
261
+ accountAddress
262
+ )
263
+
264
+ if (smartAccountDeployed) return "0x"
265
+ return generateInitCode()
227
266
  },
228
267
  async encodeCallData(_tx) {
229
268
  const tx = _tx as KernelEncodeCallDataArgs
@@ -1,14 +1,19 @@
1
1
  // copied from: https://github.com/alchemyplatform/aa-sdk/blob/266c9757cd721ef0bd97d04c0b592a329f8a9da5/packages/core/src/signer/utils.ts
2
2
 
3
+ import { getAction } from "permissionless"
3
4
  import {
4
5
  type Address,
6
+ type Chain,
7
+ type Client,
5
8
  type Hash,
6
9
  type Hex,
7
10
  type PublicClient,
11
+ type Transport,
8
12
  concat,
9
13
  encodeAbiParameters,
10
14
  parseAbiParameters
11
15
  } from "viem"
16
+ import { getStorageAt } from "viem/actions"
12
17
 
13
18
  export type SignWith6492Params = {
14
19
  factoryAddress: Address
@@ -46,7 +51,7 @@ export const wrapSignatureWith6492 = ({
46
51
  }
47
52
 
48
53
  // defined in https://github.com/AmbireTech/signature-validator/blob/main/index.ts#L13C17-L13C17
49
- const universalValidatorByteCode =
54
+ export const universalValidatorByteCode =
50
55
  "0x60806040523480156200001157600080fd5b50604051620007003803806200070083398101604081905262000034916200056f565b6000620000438484846200004f565b9050806000526001601ff35b600080846001600160a01b0316803b806020016040519081016040528181526000908060200190933c90507f6492649264926492649264926492649264926492649264926492649264926492620000a68462000451565b036200021f57600060608085806020019051810190620000c79190620005ce565b8651929550909350915060000362000192576000836001600160a01b031683604051620000f5919062000643565b6000604051808303816000865af19150503d806000811462000134576040519150601f19603f3d011682016040523d82523d6000602084013e62000139565b606091505b5050905080620001905760405162461bcd60e51b815260206004820152601e60248201527f5369676e617475726556616c696461746f723a206465706c6f796d656e74000060448201526064015b60405180910390fd5b505b604051630b135d3f60e11b808252906001600160a01b038a1690631626ba7e90620001c4908b90869060040162000661565b602060405180830381865afa158015620001e2573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906200020891906200069d565b6001600160e01b031916149450505050506200044a565b805115620002b157604051630b135d3f60e11b808252906001600160a01b03871690631626ba7e9062000259908890889060040162000661565b602060405180830381865afa15801562000277573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906200029d91906200069d565b6001600160e01b031916149150506200044a565b8251604114620003195760405162461bcd60e51b815260206004820152603a6024820152600080516020620006e083398151915260448201527f3a20696e76616c6964207369676e6174757265206c656e677468000000000000606482015260840162000187565b620003236200046b565b506020830151604080850151855186939260009185919081106200034b576200034b620006c9565b016020015160f81c9050601b81148015906200036b57508060ff16601c14155b15620003cf5760405162461bcd60e51b815260206004820152603b6024820152600080516020620006e083398151915260448201527f3a20696e76616c6964207369676e617475726520762076616c75650000000000606482015260840162000187565b6040805160008152602081018083528a905260ff83169181019190915260608101849052608081018390526001600160a01b038a169060019060a0016020604051602081039080840390855afa1580156200042e573d6000803e3d6000fd5b505050602060405103516001600160a01b031614955050505050505b9392505050565b60006020825110156200046357600080fd5b508051015190565b60405180606001604052806003906020820280368337509192915050565b6001600160a01b03811681146200049f57600080fd5b50565b634e487b7160e01b600052604160045260246000fd5b60005b83811015620004d5578181015183820152602001620004bb565b50506000910152565b600082601f830112620004f057600080fd5b81516001600160401b03808211156200050d576200050d620004a2565b604051601f8301601f19908116603f01168101908282118183101715620005385762000538620004a2565b816040528381528660208588010111156200055257600080fd5b62000565846020830160208901620004b8565b9695505050505050565b6000806000606084860312156200058557600080fd5b8351620005928162000489565b6020850151604086015191945092506001600160401b03811115620005b657600080fd5b620005c486828701620004de565b9150509250925092565b600080600060608486031215620005e457600080fd5b8351620005f18162000489565b60208501519093506001600160401b03808211156200060f57600080fd5b6200061d87838801620004de565b935060408601519150808211156200063457600080fd5b50620005c486828701620004de565b6000825162000657818460208701620004b8565b9190910192915050565b828152604060208201526000825180604084015262000688816060850160208701620004b8565b601f01601f1916919091016060019392505050565b600060208284031215620006b057600080fd5b81516001600160e01b0319811681146200044a57600080fd5b634e487b7160e01b600052603260045260246000fdfe5369676e617475726556616c696461746f72237265636f7665725369676e6572"
51
56
 
52
57
  export const verifyEIP6492Signature = async ({
@@ -68,3 +73,24 @@ export const verifyEIP6492Signature = async ({
68
73
 
69
74
  return result.data === "0x01"
70
75
  }
76
+
77
+ export const getKernelImplementationAddress = async <
78
+ TTransport extends Transport = Transport,
79
+ TChain extends Chain | undefined = Chain | undefined
80
+ >(
81
+ client: Client<TTransport, TChain, undefined>,
82
+ accountAddress: Address
83
+ ): Promise<Address | undefined> => {
84
+ let kernelImplAddr: Address | undefined
85
+ try {
86
+ const strgAddr = await getAction(
87
+ client,
88
+ getStorageAt
89
+ )({
90
+ address: accountAddress,
91
+ slot: "0x360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc"
92
+ })
93
+ if (strgAddr) kernelImplAddr = `0x${strgAddr.slice(26)}` as Hex
94
+ } catch (error) {}
95
+ return kernelImplAddr
96
+ }
@@ -1,9 +1,7 @@
1
- import { toKernelPluginManager } from "./toKernelPluginManager.js"
2
- export { toKernelPluginManager }
1
+ export { toKernelPluginManager } from "./toKernelPluginManager.js"
3
2
 
4
3
  import type { Address, Hex } from "viem"
5
- import { verifyEIP6492Signature } from "./6492.js"
6
- export { verifyEIP6492Signature }
4
+ export { verifyEIP6492Signature, universalValidatorByteCode } from "./6492.js"
7
5
 
8
6
  export const parseFactoryAddressAndCallDataFromAccountInitCode = (
9
7
  initCode: Hex