@zerodev/sdk 5.2.19 → 5.3.0

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 (90) hide show
  1. package/_cjs/accounts/index.js +5 -5
  2. package/_cjs/accounts/index.js.map +1 -1
  3. package/_cjs/accounts/kernel/abi/kernel_v_3_1/KernelAccountAbi.js +796 -0
  4. package/_cjs/accounts/kernel/abi/kernel_v_3_1/KernelAccountAbi.js.map +1 -0
  5. package/_cjs/accounts/kernel/createKernelAccount.js +57 -26
  6. package/_cjs/accounts/kernel/createKernelAccount.js.map +1 -1
  7. package/_cjs/accounts/kernel/utils/common/accountMetadata.js +2 -3
  8. package/_cjs/accounts/kernel/utils/common/accountMetadata.js.map +1 -1
  9. package/_cjs/accounts/kernel/utils/plugins/ep0_7/getPluginsEnableTypedData.js +1 -1
  10. package/_cjs/accounts/kernel/utils/plugins/ep0_7/getPluginsEnableTypedData.js.map +1 -1
  11. package/_cjs/accounts/kernel/v1/{createKernelV1Account.js → createKernelAccountV1.js} +4 -4
  12. package/_cjs/accounts/kernel/v1/{createKernelV1Account.js.map → createKernelAccountV1.js.map} +1 -1
  13. package/_cjs/accounts/kernel/v2/{createKernelV2Account.js → createKernelAccountV0_2.js} +5 -5
  14. package/_cjs/accounts/kernel/v2/createKernelAccountV0_2.js.map +1 -0
  15. package/_cjs/accounts/utils/toKernelPluginManager.js +10 -4
  16. package/_cjs/accounts/utils/toKernelPluginManager.js.map +1 -1
  17. package/_cjs/constants.js +42 -12
  18. package/_cjs/constants.js.map +1 -1
  19. package/_cjs/index.js +5 -3
  20. package/_cjs/index.js.map +1 -1
  21. package/_cjs/types/index.js.map +1 -1
  22. package/_cjs/types/kernel.js.map +1 -1
  23. package/_cjs/utils.js +17 -16
  24. package/_cjs/utils.js.map +1 -1
  25. package/_esm/accounts/index.js +2 -2
  26. package/_esm/accounts/index.js.map +1 -1
  27. package/_esm/accounts/kernel/abi/kernel_v_3_1/KernelAccountAbi.js +793 -0
  28. package/_esm/accounts/kernel/abi/kernel_v_3_1/KernelAccountAbi.js.map +1 -0
  29. package/_esm/accounts/kernel/createKernelAccount.js +59 -28
  30. package/_esm/accounts/kernel/createKernelAccount.js.map +1 -1
  31. package/_esm/accounts/kernel/utils/common/accountMetadata.js +2 -3
  32. package/_esm/accounts/kernel/utils/common/accountMetadata.js.map +1 -1
  33. package/_esm/accounts/kernel/utils/plugins/ep0_7/getPluginsEnableTypedData.js +1 -1
  34. package/_esm/accounts/kernel/utils/plugins/ep0_7/getPluginsEnableTypedData.js.map +1 -1
  35. package/_esm/accounts/kernel/v1/{createKernelV1Account.js → createKernelAccountV1.js} +2 -2
  36. package/_esm/accounts/kernel/v1/{createKernelV1Account.js.map → createKernelAccountV1.js.map} +1 -1
  37. package/_esm/accounts/kernel/v2/{createKernelV2Account.js → createKernelAccountV0_2.js} +3 -3
  38. package/_esm/accounts/kernel/v2/createKernelAccountV0_2.js.map +1 -0
  39. package/_esm/accounts/utils/toKernelPluginManager.js +10 -4
  40. package/_esm/accounts/utils/toKernelPluginManager.js.map +1 -1
  41. package/_esm/constants.js +49 -11
  42. package/_esm/constants.js.map +1 -1
  43. package/_esm/index.js +2 -1
  44. package/_esm/index.js.map +1 -1
  45. package/_esm/types/index.js.map +1 -1
  46. package/_esm/types/kernel.js.map +1 -1
  47. package/_esm/utils.js +14 -14
  48. package/_esm/utils.js.map +1 -1
  49. package/_types/accounts/index.d.ts +2 -2
  50. package/_types/accounts/index.d.ts.map +1 -1
  51. package/_types/accounts/kernel/abi/kernel_v_3_1/KernelAccountAbi.d.ts +946 -0
  52. package/_types/accounts/kernel/abi/kernel_v_3_1/KernelAccountAbi.d.ts.map +1 -0
  53. package/_types/accounts/kernel/createKernelAccount.d.ts +7 -6
  54. package/_types/accounts/kernel/createKernelAccount.d.ts.map +1 -1
  55. package/_types/accounts/kernel/utils/common/accountMetadata.d.ts +2 -2
  56. package/_types/accounts/kernel/utils/common/accountMetadata.d.ts.map +1 -1
  57. package/_types/accounts/kernel/v1/{createKernelV1Account.d.ts → createKernelAccountV1.d.ts} +5 -5
  58. package/_types/accounts/kernel/v1/{createKernelV1Account.d.ts.map → createKernelAccountV1.d.ts.map} +1 -1
  59. package/_types/accounts/kernel/v2/{createKernelV2Account.d.ts → createKernelAccountV0_2.d.ts} +3 -3
  60. package/_types/accounts/kernel/v2/createKernelAccountV0_2.d.ts.map +1 -0
  61. package/_types/accounts/utils/toKernelPluginManager.d.ts.map +1 -1
  62. package/_types/clients/kernelAccountClient.d.ts +1 -1
  63. package/_types/clients/paymasterClient.d.ts +1 -1
  64. package/_types/constants.d.ts +17 -7
  65. package/_types/constants.d.ts.map +1 -1
  66. package/_types/index.d.ts +2 -1
  67. package/_types/index.d.ts.map +1 -1
  68. package/_types/types/index.d.ts +1 -1
  69. package/_types/types/index.d.ts.map +1 -1
  70. package/_types/types/kernel.d.ts +6 -1
  71. package/_types/types/kernel.d.ts.map +1 -1
  72. package/_types/utils.d.ts +5 -2
  73. package/_types/utils.d.ts.map +1 -1
  74. package/accounts/index.ts +5 -2
  75. package/accounts/kernel/abi/kernel_v_3_1/KernelAccountAbi.ts +792 -0
  76. package/accounts/kernel/createKernelAccount.ts +98 -38
  77. package/accounts/kernel/utils/common/accountMetadata.ts +3 -4
  78. package/accounts/kernel/utils/plugins/ep0_7/getPluginsEnableTypedData.ts +1 -1
  79. package/accounts/kernel/v1/{createKernelV1Account.ts → createKernelAccountV1.ts} +5 -5
  80. package/accounts/kernel/v2/{createKernelV2Account.ts → createKernelAccountV0_2.ts} +6 -3
  81. package/accounts/utils/toKernelPluginManager.ts +14 -4
  82. package/constants.ts +76 -13
  83. package/index.ts +4 -2
  84. package/package.json +2 -2
  85. package/types/index.ts +5 -1
  86. package/types/kernel.ts +15 -1
  87. package/utils.ts +27 -23
  88. package/_cjs/accounts/kernel/v2/createKernelV2Account.js.map +0 -1
  89. package/_esm/accounts/kernel/v2/createKernelV2Account.js.map +0 -1
  90. package/_types/accounts/kernel/v2/createKernelV2Account.d.ts.map +0 -1
@@ -30,12 +30,15 @@ import {
30
30
  validateTypedData,
31
31
  zeroAddress
32
32
  } from "viem"
33
+ import { KernelVersionToAddressesMap } from "../../constants.js"
33
34
  import type {
35
+ GetKernelVersion,
34
36
  KernelEncodeCallDataArgs,
35
37
  KernelPluginManager,
36
38
  KernelPluginManagerParams
37
39
  } from "../../types/kernel.js"
38
40
  import { KERNEL_FEATURES, hasKernelFeature } from "../../utils.js"
41
+ import { validateKernelVersionWithEntryPoint } from "../../utils.js"
39
42
  import { parseFactoryAddressAndCallDataFromAccountInitCode } from "../utils/index.js"
40
43
  import {
41
44
  isKernelPluginManager,
@@ -44,6 +47,7 @@ import {
44
47
  import { KernelInitAbi } from "./abi/KernelAccountAbi.js"
45
48
  import { KernelV3InitAbi } from "./abi/kernel_v_3_0_0/KernelAccountAbi.js"
46
49
  import { KernelFactoryStakerAbi } from "./abi/kernel_v_3_0_0/KernelFactoryStakerAbi.js"
50
+ import { KernelV3_1AccountAbi } from "./abi/kernel_v_3_1/KernelAccountAbi.js"
47
51
  import { encodeCallData as encodeCallDataEpV06 } from "./utils/account/ep0_6/encodeCallData.js"
48
52
  import { encodeDeployCallData as encodeDeployCallDataV06 } from "./utils/account/ep0_6/encodeDeployCallData.js"
49
53
  import { encodeCallData as encodeCallDataEpV07 } from "./utils/account/ep0_7/encodeCallData.js"
@@ -65,14 +69,18 @@ export type KernelSmartAccount<
65
69
 
66
70
  export type CreateKernelAccountParameters<entryPoint extends EntryPoint> = {
67
71
  plugins:
68
- | Omit<KernelPluginManagerParams<entryPoint>, "entryPoint">
72
+ | Omit<
73
+ KernelPluginManagerParams<entryPoint>,
74
+ "entryPoint" | "kernelVersion"
75
+ >
69
76
  | KernelPluginManager<entryPoint>
70
77
  entryPoint: entryPoint
71
78
  index?: bigint
72
79
  factoryAddress?: Address
73
- accountLogicAddress?: Address
74
- factoryStakerAddress?: Address
80
+ accountImplementationAddress?: Address
81
+ metaFactoryAddress?: Address
75
82
  deployedAccountAddress?: Address
83
+ kernelVersion: GetKernelVersion<entryPoint>
76
84
  }
77
85
 
78
86
  /**
@@ -130,11 +138,13 @@ export const KERNEL_ADDRESSES: {
130
138
  const getKernelInitData = async <entryPoint extends EntryPoint>({
131
139
  entryPoint: entryPointAddress,
132
140
  kernelPluginManager,
133
- initHook
141
+ initHook,
142
+ kernelVersion
134
143
  }: {
135
144
  entryPoint: entryPoint
136
145
  kernelPluginManager: KernelPluginManager<entryPoint>
137
146
  initHook: boolean
147
+ kernelVersion: GetKernelVersion<entryPoint>
138
148
  }) => {
139
149
  const entryPointVersion = getEntryPointVersion(entryPointAddress)
140
150
  const { enableData, identifier, validatorAddress } =
@@ -148,8 +158,24 @@ const getKernelInitData = async <entryPoint extends EntryPoint>({
148
158
  })
149
159
  }
150
160
 
161
+ if (kernelVersion === "0.3.0") {
162
+ return encodeFunctionData({
163
+ abi: KernelV3InitAbi,
164
+ functionName: "initialize",
165
+ args: [
166
+ identifier,
167
+ initHook && kernelPluginManager.hook
168
+ ? kernelPluginManager.hook?.getIdentifier()
169
+ : zeroAddress,
170
+ enableData,
171
+ initHook && kernelPluginManager.hook
172
+ ? await kernelPluginManager.hook?.getEnableData()
173
+ : "0x"
174
+ ]
175
+ })
176
+ }
151
177
  return encodeFunctionData({
152
- abi: KernelV3InitAbi,
178
+ abi: KernelV3_1AccountAbi,
153
179
  functionName: "initialize",
154
180
  args: [
155
181
  identifier,
@@ -159,7 +185,8 @@ const getKernelInitData = async <entryPoint extends EntryPoint>({
159
185
  enableData,
160
186
  initHook && kernelPluginManager.hook
161
187
  ? await kernelPluginManager.hook?.getEnableData()
162
- : "0x"
188
+ : "0x",
189
+ []
163
190
  ]
164
191
  })
165
192
  }
@@ -168,31 +195,34 @@ const getKernelInitData = async <entryPoint extends EntryPoint>({
168
195
  * Get the account initialization code for a kernel smart account
169
196
  * @param index
170
197
  * @param factoryAddress
171
- * @param accountLogicAddress
198
+ * @param accountImplementationAddress
172
199
  * @param ecdsaValidatorAddress
173
200
  */
174
201
  const getAccountInitCode = async <entryPoint extends EntryPoint>({
175
202
  index,
176
203
  factoryAddress,
177
- accountLogicAddress,
178
- factoryStakerAddress,
204
+ accountImplementationAddress,
205
+ metaFactoryAddress,
179
206
  entryPoint: entryPointAddress,
180
207
  kernelPluginManager,
181
- initHook
208
+ initHook,
209
+ kernelVersion
182
210
  }: {
183
211
  index: bigint
184
212
  factoryAddress: Address
185
- accountLogicAddress: Address
186
- factoryStakerAddress: Address
213
+ accountImplementationAddress: Address
214
+ metaFactoryAddress?: Address
187
215
  entryPoint: entryPoint
188
216
  kernelPluginManager: KernelPluginManager<entryPoint>
189
217
  initHook: boolean
218
+ kernelVersion: GetKernelVersion<entryPoint>
190
219
  }): Promise<Hex> => {
191
220
  // Build the account initialization data
192
221
  const initialisationData = await getKernelInitData<entryPoint>({
193
222
  entryPoint: entryPointAddress,
194
223
  kernelPluginManager,
195
- initHook
224
+ initHook,
225
+ kernelVersion
196
226
  })
197
227
  const entryPointVersion = getEntryPointVersion(entryPointAddress)
198
228
 
@@ -203,13 +233,13 @@ const getAccountInitCode = async <entryPoint extends EntryPoint>({
203
233
  encodeFunctionData({
204
234
  abi: createAccountAbi,
205
235
  functionName: "createAccount",
206
- args: [accountLogicAddress, initialisationData, index]
236
+ args: [accountImplementationAddress, initialisationData, index]
207
237
  }) as Hex
208
238
  ])
209
239
  }
210
240
 
211
241
  return concatHex([
212
- factoryStakerAddress,
242
+ metaFactoryAddress ?? zeroAddress,
213
243
  encodeFunctionData({
214
244
  abi: KernelFactoryStakerAbi,
215
245
  functionName: "deployWithFactory",
@@ -261,6 +291,37 @@ const getAccountAddress = async <
261
291
  })
262
292
  }
263
293
 
294
+ const getDefaultAddresses = <entryPoint extends EntryPoint>(
295
+ entryPointAddress: entryPoint,
296
+ kernelVersion: GetKernelVersion<entryPoint>,
297
+ {
298
+ accountImplementationAddress,
299
+ factoryAddress,
300
+ metaFactoryAddress
301
+ }: {
302
+ accountImplementationAddress?: Address
303
+ factoryAddress?: Address
304
+ metaFactoryAddress?: Address
305
+ }
306
+ ) => {
307
+ validateKernelVersionWithEntryPoint(entryPointAddress, kernelVersion)
308
+
309
+ const addresses = KernelVersionToAddressesMap[kernelVersion]
310
+ if (!addresses) {
311
+ throw new Error(
312
+ `No addresses found for kernel version ${kernelVersion}`
313
+ )
314
+ }
315
+
316
+ return {
317
+ accountImplementationAddress:
318
+ accountImplementationAddress ??
319
+ addresses.accountImplementationAddress,
320
+ factoryAddress: factoryAddress ?? addresses.factoryAddress,
321
+ metaFactoryAddress: metaFactoryAddress ?? addresses.metaFactoryAddress
322
+ }
323
+ }
324
+
264
325
  /**
265
326
  * Build a kernel smart account from a private key, that use the ECDSA signer behind the scene
266
327
  * @param client
@@ -268,7 +329,7 @@ const getAccountAddress = async <
268
329
  * @param entryPoint
269
330
  * @param index
270
331
  * @param factoryAddress
271
- * @param accountLogicAddress
332
+ * @param accountImplementationAddress
272
333
  * @param ecdsaValidatorAddress
273
334
  * @param deployedAccountAddress
274
335
  */
@@ -282,23 +343,20 @@ export async function createKernelAccount<
282
343
  plugins,
283
344
  entryPoint: entryPointAddress,
284
345
  index = 0n,
285
- factoryAddress,
286
- accountLogicAddress,
287
- factoryStakerAddress = KERNEL_ADDRESSES.FACTORY_STAKER,
288
- deployedAccountAddress
346
+ factoryAddress: _factoryAddress,
347
+ accountImplementationAddress: _accountImplementationAddress,
348
+ metaFactoryAddress: _metaFactoryAddress,
349
+ deployedAccountAddress,
350
+ kernelVersion
289
351
  }: CreateKernelAccountParameters<entryPoint>
290
352
  ): Promise<KernelSmartAccount<entryPoint, TTransport, TChain>> {
291
353
  const entryPointVersion = getEntryPointVersion(entryPointAddress)
292
- accountLogicAddress =
293
- accountLogicAddress ??
294
- (entryPointVersion === "v0.6"
295
- ? KERNEL_ADDRESSES.ACCOUNT_LOGIC_V0_6
296
- : KERNEL_ADDRESSES.ACCOUNT_LOGIC_V0_7)
297
- factoryAddress =
298
- factoryAddress ??
299
- (entryPointVersion === "v0.6"
300
- ? KERNEL_ADDRESSES.FACTORY_ADDRESS_V0_6
301
- : KERNEL_ADDRESSES.FACTORY_ADDRESS_V0_7)
354
+ const { accountImplementationAddress, factoryAddress, metaFactoryAddress } =
355
+ getDefaultAddresses(entryPointAddress, kernelVersion, {
356
+ accountImplementationAddress: _accountImplementationAddress,
357
+ factoryAddress: _factoryAddress,
358
+ metaFactoryAddress: _metaFactoryAddress
359
+ })
302
360
 
303
361
  const kernelPluginManager = isKernelPluginManager<entryPoint>(plugins)
304
362
  ? plugins
@@ -308,7 +366,8 @@ export async function createKernelAccount<
308
366
  hook: plugins.hook,
309
367
  action: plugins.action,
310
368
  pluginEnableSignature: plugins.pluginEnableSignature,
311
- entryPoint: entryPointAddress
369
+ entryPoint: entryPointAddress,
370
+ kernelVersion
312
371
  })
313
372
 
314
373
  // initHook flag is activated only if both the hook and sudo validator are given
@@ -323,16 +382,17 @@ export async function createKernelAccount<
323
382
 
324
383
  // Helper to generate the init code for the smart account
325
384
  const generateInitCode = async () => {
326
- if (!accountLogicAddress || !factoryAddress)
385
+ if (!accountImplementationAddress || !factoryAddress)
327
386
  throw new Error("Missing account logic address or factory address")
328
387
  return getAccountInitCode<entryPoint>({
329
388
  index,
330
389
  factoryAddress,
331
- accountLogicAddress,
332
- factoryStakerAddress,
390
+ accountImplementationAddress,
391
+ metaFactoryAddress,
333
392
  entryPoint: entryPointAddress,
334
393
  kernelPluginManager,
335
- initHook
394
+ initHook,
395
+ kernelVersion
336
396
  })
337
397
  }
338
398
 
@@ -405,7 +465,7 @@ export async function createKernelAccount<
405
465
  getEntryPointVersion(entryPointAddress)
406
466
  return entryPointVersion === "v0.6"
407
467
  ? factoryAddress
408
- : factoryStakerAddress
468
+ : metaFactoryAddress
409
469
  },
410
470
 
411
471
  async getFactoryData() {
@@ -427,7 +487,7 @@ export async function createKernelAccount<
427
487
  const { name, chainId, version } = await accountMetadata(
428
488
  client,
429
489
  accountAddress,
430
- entryPointAddress
490
+ kernelVersion
431
491
  )
432
492
  const wrappedMessageHash = await eip712WrapHash(messageHash, {
433
493
  name,
@@ -478,7 +538,7 @@ export async function createKernelAccount<
478
538
  const { name, chainId, version } = await accountMetadata(
479
539
  client,
480
540
  accountAddress,
481
- entryPointAddress
541
+ kernelVersion
482
542
  )
483
543
  const wrappedMessageHash = await eip712WrapHash(typedHash, {
484
544
  name,
@@ -1,4 +1,3 @@
1
- import type { EntryPoint } from "permissionless/types/entrypoint.js"
2
1
  import {
3
2
  type Address,
4
3
  type Chain,
@@ -9,7 +8,7 @@ import {
9
8
  publicActions
10
9
  } from "viem"
11
10
  import { KERNEL_NAME } from "../../../../constants.js"
12
- import { getKernelVersion } from "../../../../utils.js"
11
+ import type { KERNEL_VERSION_TYPE } from "../../../../types/kernel.js"
13
12
  import { EIP1271Abi } from "../../abi/EIP1271Abi.js"
14
13
 
15
14
  type AccountMetadata = {
@@ -23,7 +22,7 @@ export const accountMetadata = async <
23
22
  >(
24
23
  client: Client<TTransport, TChain, undefined>,
25
24
  accountAddress: Address,
26
- entryPointAddress: EntryPoint
25
+ kernelVersion: KERNEL_VERSION_TYPE
27
26
  ): Promise<AccountMetadata> => {
28
27
  try {
29
28
  const domain = await client.request({
@@ -54,7 +53,7 @@ export const accountMetadata = async <
54
53
  } catch (error) {}
55
54
  return {
56
55
  name: KERNEL_NAME,
57
- version: getKernelVersion(entryPointAddress),
56
+ version: kernelVersion === "0.3.0" ? "0.3.0-beta" : kernelVersion,
58
57
  chainId: client.chain
59
58
  ? BigInt(client.chain.id)
60
59
  : BigInt(await client.extend(publicActions).getChainId())
@@ -37,7 +37,7 @@ export const getPluginsEnableTypedData = async <
37
37
  return {
38
38
  domain: {
39
39
  name: "Kernel",
40
- version: kernelVersion,
40
+ version: kernelVersion === "0.3.0" ? "0.3.0-beta" : kernelVersion,
41
41
  chainId,
42
42
  verifyingContract: accountAddress
43
43
  },
@@ -39,7 +39,7 @@ import {
39
39
  } from "../../utils/multisend.js"
40
40
  import type { KernelSmartAccount } from "../createKernelAccount.js"
41
41
 
42
- export type KernelV1SmartAccount<
42
+ export type KernelSmartAccountV1<
43
43
  entryPoint extends EntryPoint,
44
44
  transport extends Transport = Transport,
45
45
  chain extends Chain | undefined = Chain | undefined
@@ -90,7 +90,7 @@ const KERNEL_V1_ADDRESSES: {
90
90
  ENTRYPOINT_V0_6: "0x5FF137D4b0FDCD49DcA30c7CF57E578a026d2789"
91
91
  }
92
92
 
93
- export async function createKernelV1Account<
93
+ export async function createKernelAccountV1<
94
94
  entryPoint extends EntryPoint,
95
95
  TTransport extends Transport = Transport,
96
96
  TChain extends Chain | undefined = Chain | undefined,
@@ -100,14 +100,14 @@ export async function createKernelV1Account<
100
100
  client: Client<TTransport, TChain, undefined>,
101
101
  {
102
102
  signer,
103
- entrypoint: entryPointAddress,
103
+ entryPoint: entryPointAddress,
104
104
  index = 0n
105
105
  }: {
106
106
  signer: SmartAccountSigner<TSource, TAddress>
107
- entrypoint: entryPoint
107
+ entryPoint: entryPoint
108
108
  index?: bigint
109
109
  }
110
- ): Promise<KernelV1SmartAccount<entryPoint, TTransport, TChain>> {
110
+ ): Promise<KernelSmartAccountV1<entryPoint, TTransport, TChain>> {
111
111
  const entryPointVersion = getEntryPointVersion(entryPointAddress)
112
112
 
113
113
  if (
@@ -135,7 +135,7 @@ const getAccountAddress = async <
135
135
  * @param ecdsaValidatorAddress
136
136
  * @param deployedAccountAddress
137
137
  */
138
- export async function createKernelV2Account<
138
+ export async function createKernelAccountV0_2<
139
139
  entryPoint extends EntryPoint,
140
140
  TTransport extends Transport = Transport,
141
141
  TChain extends Chain | undefined = Chain | undefined
@@ -149,7 +149,10 @@ export async function createKernelV2Account<
149
149
  deployedAccountAddress
150
150
  }: {
151
151
  plugins:
152
- | KernelPluginManagerParams<entryPoint>
152
+ | Omit<
153
+ KernelPluginManagerParams<entryPoint>,
154
+ "entryPoint" | "kernelVersion"
155
+ >
153
156
  | KernelPluginManager<entryPoint>
154
157
  entryPoint: entryPoint
155
158
  index?: bigint
@@ -169,7 +172,7 @@ export async function createKernelV2Account<
169
172
  regular: plugins.regular,
170
173
  action: plugins.action,
171
174
  pluginEnableSignature: plugins.pluginEnableSignature,
172
- kernelVersion: "0.0.2" ?? plugins.kernelVersion,
175
+ kernelVersion: "0.0.2",
173
176
  entryPoint: entryPointAddress
174
177
  })
175
178
  // Helper to generate the init code for the smart account
@@ -1,5 +1,6 @@
1
1
  import { getEntryPointVersion } from "permissionless"
2
2
  import type { EntryPoint } from "permissionless/types/entrypoint"
3
+ import { satisfies } from "semver"
3
4
  import {
4
5
  type Address,
5
6
  type Chain,
@@ -61,6 +62,14 @@ export async function toKernelPluginManager<
61
62
  kernelVersion
62
63
  }: KernelPluginManagerParams<entryPoint>
63
64
  ): Promise<KernelPluginManager<entryPoint>> {
65
+ if (
66
+ (sudo && !satisfies(kernelVersion, sudo?.supportedKernelVersions)) ||
67
+ (regular && !satisfies(kernelVersion, regular?.supportedKernelVersions))
68
+ ) {
69
+ throw new Error(
70
+ "Either sudo or/and regular validator version mismatch. Update to latest plugin package and use the proper plugin version"
71
+ )
72
+ }
64
73
  const entryPointVersion = getEntryPointVersion(entryPointAddress)
65
74
  const chainId = await getChainId(client)
66
75
  const activeValidator = regular || sudo
@@ -75,7 +84,8 @@ export async function toKernelPluginManager<
75
84
  entryPointVersion === "v0.7" &&
76
85
  (action.address.toLowerCase() !== zeroAddress.toLowerCase() ||
77
86
  action.selector.toLowerCase() !==
78
- getActionSelector(entryPointVersion).toLowerCase())
87
+ getActionSelector(entryPointVersion).toLowerCase()) &&
88
+ kernelVersion === "0.3.0"
79
89
  ) {
80
90
  action.hook = {
81
91
  address: action.hook?.address ?? ONLY_ENTRYPOINT_HOOK_ADDRESS
@@ -169,14 +179,14 @@ export async function toKernelPluginManager<
169
179
  const { version } = await accountMetadata(
170
180
  client,
171
181
  accountAddress,
172
- entryPointAddress
182
+ kernelVersion
173
183
  )
174
184
  let ownerSig: Hex
175
185
  if (entryPointVersion === "v0.6") {
176
186
  const typeData = await getPluginsEnableTypedDataV1({
177
187
  accountAddress,
178
188
  chainId,
179
- kernelVersion: kernelVersion ?? version,
189
+ kernelVersion: version ?? kernelVersion,
180
190
  action,
181
191
  validator: regular,
182
192
  validUntil,
@@ -222,7 +232,7 @@ export async function toKernelPluginManager<
222
232
  const { version } = await accountMetadata(
223
233
  client,
224
234
  accountAddress,
225
- entryPointAddress
235
+ kernelVersion
226
236
  )
227
237
 
228
238
  const validatorNonce = await getKernelV3Nonce(client, accountAddress)
package/constants.ts CHANGED
@@ -1,25 +1,88 @@
1
- import type { EntryPointVersion } from "permissionless/types/entrypoint"
2
- import type { Address, Hex } from "viem"
1
+ import { type Address, type Hex, zeroAddress } from "viem"
2
+ import type {
3
+ KERNEL_V2_VERSION_TYPE,
4
+ KERNEL_V3_VERSION_TYPE,
5
+ KERNEL_VERSION_TYPE
6
+ } from "./types/kernel.js"
3
7
 
4
8
  export const DUMMY_ECDSA_SIG =
5
9
  "0xfffffffffffffffffffffffffffffff0000000000000000000000000000000007aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa1c"
6
10
 
7
- export const KernelImplToVersionMap: { [key: Address]: string } = {
8
- "0x8dD4DBB54d8A8Cf0DE6F9CCC4609470A30EfF18C": "0.2.2",
9
- "0x0DA6a956B9488eD4dd761E59f52FDc6c8068E6B5": "0.2.2",
10
- "0xD3F582F6B4814E989Ee8E96bc3175320B5A540ab": "0.2.3",
11
- "0x5FC0236D6c88a65beD32EECDC5D60a5CAb377717": "0.2.3",
12
- "0xd3082872F8B06073A021b4602e022d5A070d7cfC": "0.2.4",
13
- "0x94F097E1ebEB4ecA3AAE54cabb08905B239A7D27": "0.3.0-beta"
11
+ // export const KernelImplToVersionMap: { [key: Address]: string } = {
12
+ // "0x8dD4DBB54d8A8Cf0DE6F9CCC4609470A30EfF18C": "0.2.2",
13
+ // "0x0DA6a956B9488eD4dd761E59f52FDc6c8068E6B5": "0.2.2",
14
+ // "0xD3F582F6B4814E989Ee8E96bc3175320B5A540ab": "0.2.3",
15
+ // "0x5FC0236D6c88a65beD32EECDC5D60a5CAb377717": "0.2.3",
16
+ // "0xd3082872F8B06073A021b4602e022d5A070d7cfC": "0.2.4",
17
+ // "0x94F097E1ebEB4ecA3AAE54cabb08905B239A7D27": "0.3.0"
18
+ // }
19
+
20
+ export const FACTORY_ADDRESS_V0_6 = "0x5de4839a76cf55d0c90e2061ef4386d962E15ae3"
21
+ export const FACTORY_ADDRESS_V0_6_INIT_CODE_HASH =
22
+ "0xee9d8350bd899dd261db689aafd87eb8a30f085adbaff48152399438ff4eed73"
23
+
24
+ export const KernelVersionToAddressesMap: {
25
+ [key in KERNEL_VERSION_TYPE]: {
26
+ accountImplementationAddress: Address
27
+ factoryAddress: Address
28
+ metaFactoryAddress?: key extends KERNEL_V3_VERSION_TYPE
29
+ ? Address
30
+ : never
31
+ initCodeHash?: Hex
32
+ }
33
+ } = {
34
+ "0.0.2": {
35
+ accountImplementationAddress: zeroAddress,
36
+ factoryAddress: "0xaee9762ce625e0a8f7b184670fb57c37bfe1d0f1"
37
+ },
38
+ "0.2.2": {
39
+ accountImplementationAddress:
40
+ "0x0DA6a956B9488eD4dd761E59f52FDc6c8068E6B5",
41
+ factoryAddress: FACTORY_ADDRESS_V0_6,
42
+ initCodeHash: FACTORY_ADDRESS_V0_6_INIT_CODE_HASH
43
+ },
44
+ "0.2.3": {
45
+ accountImplementationAddress:
46
+ "0xD3F582F6B4814E989Ee8E96bc3175320B5A540ab",
47
+ factoryAddress: FACTORY_ADDRESS_V0_6,
48
+ initCodeHash: FACTORY_ADDRESS_V0_6_INIT_CODE_HASH
49
+ },
50
+ "0.2.4": {
51
+ accountImplementationAddress:
52
+ "0xd3082872F8B06073A021b4602e022d5A070d7cfC",
53
+ factoryAddress: FACTORY_ADDRESS_V0_6,
54
+ initCodeHash: FACTORY_ADDRESS_V0_6_INIT_CODE_HASH
55
+ },
56
+ "0.3.0": {
57
+ accountImplementationAddress:
58
+ "0x94F097E1ebEB4ecA3AAE54cabb08905B239A7D27",
59
+ factoryAddress: "0x6723b44Abeec4E71eBE3232BD5B455805baDD22f",
60
+ metaFactoryAddress: "0xd703aaE79538628d27099B8c4f621bE4CCd142d5",
61
+ initCodeHash:
62
+ "0x6fe6e6ea30eddce942b9618033ab8429f9ddac594053bec8a6744fffc71976e2"
63
+ },
64
+ "0.3.1": {
65
+ accountImplementationAddress:
66
+ "0xBAC849bB641841b44E965fB01A4Bf5F074f84b4D",
67
+ factoryAddress: "0xaac5D4240AF87249B3f71BC8E4A2cae074A3E419",
68
+ metaFactoryAddress: "0xd703aaE79538628d27099B8c4f621bE4CCd142d5",
69
+ initCodeHash:
70
+ "0x85d96aa1c9a65886d094915d76ccae85f14027a02c1647dde659f869460f03e6"
71
+ }
14
72
  }
73
+
74
+ export const KERNEL_V0_2: KERNEL_V2_VERSION_TYPE = "0.0.2"
75
+ export const KERNEL_V2_2: KERNEL_V2_VERSION_TYPE = "0.2.2"
76
+ export const KERNEL_V2_3: KERNEL_V2_VERSION_TYPE = "0.2.3"
77
+ export const KERNEL_V2_4: KERNEL_V2_VERSION_TYPE = "0.2.4"
78
+ export const KERNEL_V3_0: KERNEL_V3_VERSION_TYPE = "0.3.0"
79
+ export const KERNEL_V3_1: KERNEL_V3_VERSION_TYPE = "0.3.1"
80
+
15
81
  export const TOKEN_ACTION = "0x2087C7FfD0d0DAE80a00EE74325aBF3449e0eaf1"
16
82
  export const ONLY_ENTRYPOINT_HOOK_ADDRESS =
17
83
  "0xb230f0A1C7C95fa11001647383c8C7a8F316b900"
18
84
  export const KERNEL_NAME = "Kernel"
19
- export const LATEST_KERNEL_VERSION: { [key in EntryPointVersion]: string } = {
20
- "v0.6": "0.2.4",
21
- "v0.7": "0.3.0-beta"
22
- }
85
+
23
86
  export const VALIDATOR_TYPE = {
24
87
  SUDO: "0x00",
25
88
  SECONDARY: "0x01",
package/index.ts CHANGED
@@ -1,7 +1,8 @@
1
1
  export {
2
2
  createKernelAccount,
3
- createKernelV1Account,
4
- createKernelV2Account,
3
+ createKernelAccountV0_2,
4
+ createKernelAccountV1,
5
+ type KernelSmartAccountV1,
5
6
  type KernelSmartAccount,
6
7
  KERNEL_ADDRESSES,
7
8
  addressToEmptyAccount,
@@ -42,6 +43,7 @@ export {
42
43
  KernelV3ExecuteAbi,
43
44
  KernelV3InitAbi
44
45
  } from "./accounts/kernel/abi/kernel_v_3_0_0/KernelAccountAbi.js"
46
+ export { KernelV3_1AccountAbi } from "./accounts/kernel/abi/kernel_v_3_1/KernelAccountAbi.js"
45
47
  export { KernelV3FactoryAbi } from "./accounts/kernel/abi/kernel_v_3_0_0/KernelFactoryAbi.js"
46
48
  export { KernelFactoryStakerAbi } from "./accounts/kernel/abi/kernel_v_3_0_0/KernelFactoryStakerAbi.js"
47
49
  export { TokenActionsAbi } from "./accounts/kernel/abi/TokenActionsAbi.js"
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zerodev/sdk",
3
- "version": "5.2.19",
3
+ "version": "5.3.0",
4
4
  "author": "ZeroDev",
5
5
  "main": "./_cjs/index.js",
6
6
  "module": "./_esm/index.js",
@@ -118,7 +118,7 @@
118
118
  }
119
119
  },
120
120
  "peerDependencies": {
121
- "viem": "^2.9.17",
121
+ "viem": "^2.15.1",
122
122
  "permissionless": "^0.1.18"
123
123
  },
124
124
  "dependencies": {
package/types/index.ts CHANGED
@@ -8,7 +8,11 @@ export type {
8
8
  KernelEncodeCallDataArgs,
9
9
  PluginValidityData,
10
10
  ZeroDevAccountClientRpcSchema,
11
- ZeroDevUserOperationGasPriceWithBigIntAsHex
11
+ ZeroDevUserOperationGasPriceWithBigIntAsHex,
12
+ KERNEL_V2_VERSION_TYPE,
13
+ KERNEL_V3_VERSION_TYPE,
14
+ KERNEL_VERSION_TYPE,
15
+ GetKernelVersion
12
16
  } from "./kernel.js"
13
17
 
14
18
  export { ValidatorMode } from "./kernel.js"
package/types/kernel.ts CHANGED
@@ -126,6 +126,7 @@ export type KernelValidator<
126
126
  Name extends string = string
127
127
  > = LocalAccount<Name> & {
128
128
  validatorType: ValidatorType
129
+ supportedKernelVersions: string
129
130
  getNonceKey: (
130
131
  accountAddress?: Address,
131
132
  customNonceKey?: bigint
@@ -193,7 +194,7 @@ export type KernelPluginManagerParams<entryPoint extends EntryPoint> = {
193
194
  validatorInitData?: ValidatorInitData
194
195
  action?: Action
195
196
  entryPoint: entryPoint
196
- kernelVersion?: string
197
+ kernelVersion: KERNEL_VERSION_TYPE
197
198
  } & Partial<PluginValidityData>
198
199
 
199
200
  export type Hook = {
@@ -238,3 +239,16 @@ export type Execution = {
238
239
  value: bigint
239
240
  callData: Hex
240
241
  }
242
+
243
+ export type KERNEL_V2_VERSION_TYPE = "0.0.2" | "0.2.2" | "0.2.3" | "0.2.4"
244
+
245
+ export type KERNEL_V3_VERSION_TYPE = "0.3.0" | "0.3.1"
246
+
247
+ export type KERNEL_VERSION_TYPE =
248
+ | KERNEL_V2_VERSION_TYPE
249
+ | KERNEL_V3_VERSION_TYPE
250
+
251
+ export type GetKernelVersion<entryPoint extends EntryPoint> =
252
+ entryPoint extends ENTRYPOINT_ADDRESS_V06_TYPE
253
+ ? KERNEL_V2_VERSION_TYPE
254
+ : KERNEL_V3_VERSION_TYPE