@zerodev/sdk 5.2.1-alpha-10 → 5.2.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 (77) hide show
  1. package/_cjs/accounts/kernel/createKernelAccount.js +14 -7
  2. package/_cjs/accounts/kernel/createKernelAccount.js.map +1 -1
  3. package/_cjs/accounts/kernel/utils/account/ep0_6/encodeModuleInstallCallData.js +27 -0
  4. package/_cjs/accounts/kernel/utils/account/ep0_6/encodeModuleInstallCallData.js.map +1 -0
  5. package/_cjs/accounts/kernel/utils/account/ep0_7/getKernelV3Nonce.js +2 -2
  6. package/_cjs/accounts/kernel/utils/account/ep0_7/getKernelV3Nonce.js.map +1 -1
  7. package/_cjs/accounts/kernel/utils/plugins/ep0_6/getPluginsEnableTypedData.js.map +1 -1
  8. package/_cjs/accounts/kernel/utils/plugins/ep0_7/isPluginInitialized.js +2 -2
  9. package/_cjs/accounts/kernel/utils/plugins/ep0_7/isPluginInitialized.js.map +1 -1
  10. package/_cjs/accounts/kernel/v1/createKernelV1Account.js +3 -0
  11. package/_cjs/accounts/kernel/v1/createKernelV1Account.js.map +1 -1
  12. package/_cjs/accounts/kernel/v2/createKernelV2Account.js +3 -0
  13. package/_cjs/accounts/kernel/v2/createKernelV2Account.js.map +1 -1
  14. package/_cjs/accounts/utils/6492.js +2 -2
  15. package/_cjs/accounts/utils/6492.js.map +1 -1
  16. package/_cjs/accounts/utils/toKernelPluginManager.js +20 -0
  17. package/_cjs/accounts/utils/toKernelPluginManager.js.map +1 -1
  18. package/_cjs/actions/account-client/signUserOperation.js +2 -1
  19. package/_cjs/actions/account-client/signUserOperation.js.map +1 -1
  20. package/_cjs/types/kernel.js.map +1 -1
  21. package/_cjs/utils.js +1 -1
  22. package/_cjs/utils.js.map +1 -1
  23. package/_esm/accounts/kernel/createKernelAccount.js +14 -7
  24. package/_esm/accounts/kernel/createKernelAccount.js.map +1 -1
  25. package/_esm/accounts/kernel/utils/account/ep0_6/encodeModuleInstallCallData.js +23 -0
  26. package/_esm/accounts/kernel/utils/account/ep0_6/encodeModuleInstallCallData.js.map +1 -0
  27. package/_esm/accounts/kernel/utils/account/ep0_7/getKernelV3Nonce.js +2 -2
  28. package/_esm/accounts/kernel/utils/account/ep0_7/getKernelV3Nonce.js.map +1 -1
  29. package/_esm/accounts/kernel/utils/plugins/ep0_6/getPluginsEnableTypedData.js.map +1 -1
  30. package/_esm/accounts/kernel/utils/plugins/ep0_7/isPluginInitialized.js +2 -2
  31. package/_esm/accounts/kernel/utils/plugins/ep0_7/isPluginInitialized.js.map +1 -1
  32. package/_esm/accounts/kernel/v1/createKernelV1Account.js +3 -0
  33. package/_esm/accounts/kernel/v1/createKernelV1Account.js.map +1 -1
  34. package/_esm/accounts/kernel/v2/createKernelV2Account.js +4 -0
  35. package/_esm/accounts/kernel/v2/createKernelV2Account.js.map +1 -1
  36. package/_esm/accounts/utils/6492.js +2 -2
  37. package/_esm/accounts/utils/6492.js.map +1 -1
  38. package/_esm/accounts/utils/toKernelPluginManager.js +20 -0
  39. package/_esm/accounts/utils/toKernelPluginManager.js.map +1 -1
  40. package/_esm/actions/account-client/signUserOperation.js +3 -2
  41. package/_esm/actions/account-client/signUserOperation.js.map +1 -1
  42. package/_esm/types/kernel.js.map +1 -1
  43. package/_esm/utils.js +2 -1
  44. package/_esm/utils.js.map +1 -1
  45. package/_types/accounts/kernel/createKernelAccount.d.ts +1 -0
  46. package/_types/accounts/kernel/createKernelAccount.d.ts.map +1 -1
  47. package/_types/accounts/kernel/utils/account/ep0_6/encodeModuleInstallCallData.d.ts +14 -0
  48. package/_types/accounts/kernel/utils/account/ep0_6/encodeModuleInstallCallData.d.ts.map +1 -0
  49. package/_types/accounts/kernel/utils/account/ep0_7/getKernelV3Nonce.d.ts.map +1 -1
  50. package/_types/accounts/kernel/utils/plugins/ep0_6/getPluginsEnableTypedData.d.ts.map +1 -1
  51. package/_types/accounts/kernel/utils/plugins/ep0_7/isPluginInitialized.d.ts.map +1 -1
  52. package/_types/accounts/kernel/v1/createKernelV1Account.d.ts.map +1 -1
  53. package/_types/accounts/kernel/v2/createKernelV2Account.d.ts +3 -9
  54. package/_types/accounts/kernel/v2/createKernelV2Account.d.ts.map +1 -1
  55. package/_types/accounts/utils/6492.d.ts.map +1 -1
  56. package/_types/accounts/utils/toKernelPluginManager.d.ts.map +1 -1
  57. package/_types/actions/account-client/signUserOperation.d.ts.map +1 -1
  58. package/_types/clients/kernelAccountClient.d.ts +14 -10
  59. package/_types/clients/kernelAccountClient.d.ts.map +1 -1
  60. package/_types/clients/paymasterClient.d.ts +4 -0
  61. package/_types/clients/paymasterClient.d.ts.map +1 -1
  62. package/_types/types/kernel.d.ts +10 -1
  63. package/_types/types/kernel.d.ts.map +1 -1
  64. package/_types/utils.d.ts.map +1 -1
  65. package/accounts/kernel/createKernelAccount.ts +16 -6
  66. package/accounts/kernel/utils/account/ep0_6/encodeModuleInstallCallData.ts +35 -0
  67. package/accounts/kernel/utils/account/ep0_7/getKernelV3Nonce.ts +3 -2
  68. package/accounts/kernel/utils/plugins/ep0_6/getPluginsEnableTypedData.ts +0 -1
  69. package/accounts/kernel/utils/plugins/ep0_7/isPluginInitialized.ts +3 -2
  70. package/accounts/kernel/v1/createKernelV1Account.ts +3 -0
  71. package/accounts/kernel/v2/createKernelV2Account.ts +7 -15
  72. package/accounts/utils/6492.ts +3 -2
  73. package/accounts/utils/toKernelPluginManager.ts +19 -0
  74. package/actions/account-client/signUserOperation.ts +3 -2
  75. package/package.json +3 -3
  76. package/types/kernel.ts +18 -1
  77. package/utils.ts +2 -1
@@ -60,6 +60,7 @@ export type KernelSmartAccount<
60
60
  getNonce: (customNonceKey?: bigint) => Promise<bigint>
61
61
  generateInitCode: () => Promise<Hex>
62
62
  encodeCallData: (args: KernelEncodeCallDataArgs) => Promise<Hex>
63
+ encodeModuleInstallCallData: () => Promise<Hex>
63
64
  }
64
65
 
65
66
  export type CreateKernelAccountParameters<entryPoint extends EntryPoint> = {
@@ -267,21 +268,23 @@ export async function createKernelAccount<
267
268
  plugins,
268
269
  entryPoint: entryPointAddress,
269
270
  index = 0n,
270
- factoryAddress = KERNEL_ADDRESSES.FACTORY_ADDRESS_V0_6,
271
- accountLogicAddress = KERNEL_ADDRESSES.ACCOUNT_LOGIC_V0_6,
271
+ factoryAddress,
272
+ accountLogicAddress,
272
273
  factoryStakerAddress = KERNEL_ADDRESSES.FACTORY_STAKER,
273
274
  deployedAccountAddress
274
275
  }: CreateKernelAccountParameters<entryPoint>
275
276
  ): Promise<KernelSmartAccount<entryPoint, TTransport, TChain>> {
276
277
  const entryPointVersion = getEntryPointVersion(entryPointAddress)
277
278
  accountLogicAddress =
278
- entryPointVersion === "v0.6"
279
+ accountLogicAddress ??
280
+ (entryPointVersion === "v0.6"
279
281
  ? KERNEL_ADDRESSES.ACCOUNT_LOGIC_V0_6
280
- : KERNEL_ADDRESSES.ACCOUNT_LOGIC_V0_7
282
+ : KERNEL_ADDRESSES.ACCOUNT_LOGIC_V0_7)
281
283
  factoryAddress =
282
- entryPointVersion === "v0.6"
284
+ factoryAddress ??
285
+ (entryPointVersion === "v0.6"
283
286
  ? KERNEL_ADDRESSES.FACTORY_ADDRESS_V0_6
284
- : KERNEL_ADDRESSES.FACTORY_ADDRESS_V0_7
287
+ : KERNEL_ADDRESSES.FACTORY_ADDRESS_V0_7)
285
288
 
286
289
  const kernelPluginManager = isKernelPluginManager<entryPoint>(plugins)
287
290
  ? plugins
@@ -294,6 +297,8 @@ export async function createKernelAccount<
294
297
  })
295
298
  // Helper to generate the init code for the smart account
296
299
  const generateInitCode = async () => {
300
+ if (!accountLogicAddress || !factoryAddress)
301
+ throw new Error("Missing account logic address or factory address")
297
302
  return getAccountInitCode<entryPoint>({
298
303
  index,
299
304
  factoryAddress,
@@ -323,6 +328,11 @@ export async function createKernelAccount<
323
328
  return {
324
329
  kernelPluginManager,
325
330
  generateInitCode,
331
+ encodeModuleInstallCallData: async () => {
332
+ return await kernelPluginManager.encodeModuleInstallCallData(
333
+ accountAddress
334
+ )
335
+ },
326
336
  ...toSmartAccount({
327
337
  address: accountAddress,
328
338
  publicKey: accountAddress,
@@ -0,0 +1,35 @@
1
+ import type { ENTRYPOINT_ADDRESS_V06_TYPE } from "permissionless/types/entrypoint"
2
+ import { type Address, type Hex, encodeFunctionData } from "viem"
3
+ import type { PluginInstallData } from "../../../../../types/kernel.js"
4
+ import { KernelAccountAbi } from "../../../abi/KernelAccountAbi.js"
5
+ import { encodeCallData } from "./encodeCallData.js"
6
+
7
+ export const encodeModuleInstallCallData = async ({
8
+ accountAddress,
9
+ enableData,
10
+ executor,
11
+ selector,
12
+ validAfter,
13
+ validUntil,
14
+ validator
15
+ }: {
16
+ accountAddress: Address
17
+ } & PluginInstallData<ENTRYPOINT_ADDRESS_V06_TYPE>): Promise<Hex> => {
18
+ return encodeCallData({
19
+ to: accountAddress,
20
+ value: 0n,
21
+ data: encodeFunctionData({
22
+ abi: KernelAccountAbi,
23
+ functionName: "setExecution",
24
+ args: [
25
+ selector,
26
+ executor,
27
+ validator,
28
+ validUntil,
29
+ validAfter,
30
+ enableData
31
+ ]
32
+ }),
33
+ callType: "call"
34
+ })
35
+ }
@@ -1,6 +1,6 @@
1
- import { getAction } from "permissionless"
2
1
  import type { Address, Client } from "viem"
3
2
  import { readContract } from "viem/actions"
3
+ import { getAction } from "viem/utils"
4
4
  import { KernelV3AccountAbi } from "../../../abi/kernel_v_3_0_0/KernelAccountAbi.js"
5
5
 
6
6
  export const getKernelV3Nonce = async (
@@ -10,7 +10,8 @@ export const getKernelV3Nonce = async (
10
10
  try {
11
11
  const nonce = await getAction(
12
12
  client,
13
- readContract
13
+ readContract,
14
+ "sendTransaction"
14
15
  )({
15
16
  abi: KernelV3AccountAbi,
16
17
  address: accountAddress,
@@ -34,7 +34,6 @@ export const getPluginsEnableTypedData = async <
34
34
  accountAddress: Address
35
35
  chainId: number
36
36
  kernelVersion: string
37
- // { action, validator }: Kernel2_0_plugins
38
37
  } & Kernel2_0_plugins<entryPoint> &
39
38
  PluginValidityData): Promise<
40
39
  Parameters<CustomSource["signTypedData"]>[0]
@@ -1,6 +1,6 @@
1
- import { getAction } from "permissionless"
2
1
  import type { Address, Client } from "viem"
3
2
  import { readContract } from "viem/actions"
3
+ import { getAction } from "viem/utils"
4
4
  import { KernelModuleIsInitializedAbi } from "../../../abi/kernel_v_3_0_0/KernelModuleAbi.js"
5
5
 
6
6
  export const isPluginInitialized = async (
@@ -11,7 +11,8 @@ export const isPluginInitialized = async (
11
11
  try {
12
12
  return await getAction(
13
13
  client,
14
- readContract
14
+ readContract,
15
+ "readContract"
15
16
  )({
16
17
  abi: KernelModuleIsInitializedAbi,
17
18
  address: pluginAddress,
@@ -213,6 +213,9 @@ export async function createKernelV1Account<
213
213
  return {
214
214
  ...account,
215
215
  generateInitCode,
216
+ encodeModuleInstallCallData: async () => {
217
+ throw new Error("Not implemented")
218
+ },
216
219
  client: client,
217
220
  publicKey: accountAddress,
218
221
  entryPoint: entryPointAddress,
@@ -4,10 +4,7 @@ import {
4
4
  getSenderAddress,
5
5
  isSmartAccountDeployed
6
6
  } from "permissionless"
7
- import {
8
- SignTransactionNotSupportedBySmartAccount,
9
- type SmartAccount
10
- } from "permissionless/accounts"
7
+ import { SignTransactionNotSupportedBySmartAccount } from "permissionless/accounts"
11
8
  import type {
12
9
  ENTRYPOINT_ADDRESS_V06_TYPE,
13
10
  EntryPoint
@@ -47,20 +44,10 @@ import {
47
44
  isKernelPluginManager,
48
45
  toKernelPluginManager
49
46
  } from "../../utils/toKernelPluginManager.js"
47
+ import { type KernelSmartAccount } from "../createKernelAccount.js"
50
48
  import { KernelAccountV2Abi } from "./abi/KernelAccountV2Abi.js"
51
49
  import { KernelFactoryV2Abi } from "./abi/KernelFactoryV2Abi.js"
52
50
 
53
- export type KernelSmartAccount<
54
- entryPoint extends EntryPoint,
55
- transport extends Transport = Transport,
56
- chain extends Chain | undefined = Chain | undefined
57
- > = SmartAccount<entryPoint, "kernelSmartAccount", transport, chain> & {
58
- kernelPluginManager: KernelPluginManager<entryPoint>
59
- getNonce: (customNonceKey?: bigint) => Promise<bigint>
60
- generateInitCode: () => Promise<Hex>
61
- encodeCallData: (args: KernelEncodeCallDataArgs) => Promise<Hex>
62
- }
63
-
64
51
  // Safe's library for create and create2: https://github.com/safe-global/safe-contracts/blob/0acdd35a203299585438f53885df630f9d486a86/contracts/libraries/CreateCall.sol
65
52
  // Address was found here: https://github.com/safe-global/safe-deployments/blob/926ec6bbe2ebcac3aa2c2c6c0aff74aa590cbc6a/src/assets/v1.4.1/create_call.json
66
53
  const createCallAddress = "0x9b35Af71d77eaf8d7e40252370304687390A1A52"
@@ -289,6 +276,11 @@ export async function createKernelV2Account<
289
276
  source: "kernelSmartAccount",
290
277
  kernelPluginManager,
291
278
  generateInitCode,
279
+ encodeModuleInstallCallData: async () => {
280
+ return await kernelPluginManager.encodeModuleInstallCallData(
281
+ accountAddress
282
+ )
283
+ },
292
284
  async getFactory() {
293
285
  if (smartAccountDeployed) return undefined
294
286
 
@@ -1,6 +1,5 @@
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"
4
3
  import {
5
4
  type Address,
6
5
  type Chain,
@@ -14,6 +13,7 @@ import {
14
13
  parseAbiParameters
15
14
  } from "viem"
16
15
  import { getStorageAt } from "viem/actions"
16
+ import { getAction } from "viem/utils"
17
17
 
18
18
  export type SignWith6492Params = {
19
19
  factoryAddress: Address
@@ -85,7 +85,8 @@ export const getKernelImplementationAddress = async <
85
85
  try {
86
86
  const strgAddr = await getAction(
87
87
  client,
88
- getStorageAt
88
+ getStorageAt,
89
+ "getStorageAt"
89
90
  )({
90
91
  address: accountAddress,
91
92
  slot: "0x360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc"
@@ -15,6 +15,7 @@ import {
15
15
  zeroAddress
16
16
  } from "viem"
17
17
  import { getChainId } from "viem/actions"
18
+ import { encodeModuleInstallCallData as encodeModuleInstallCallDataEpV06 } from "../../accounts/kernel/utils/account/ep0_6/encodeModuleInstallCallData.js"
18
19
  import { VALIDATOR_MODE, VALIDATOR_TYPE } from "../../constants.js"
19
20
  import {
20
21
  type KernelPluginManager,
@@ -193,6 +194,24 @@ export async function toKernelPluginManager<
193
194
  return {
194
195
  ...activeValidator,
195
196
  getIdentifier,
197
+ encodeModuleInstallCallData: async (accountAddress: Address) => {
198
+ if (!action) {
199
+ throw new Error("Action data must be set")
200
+ }
201
+ if (!regular) throw new Error("regular validator not set")
202
+ if (entryPointVersion === "v0.6") {
203
+ return await encodeModuleInstallCallDataEpV06({
204
+ accountAddress,
205
+ selector: action.selector,
206
+ executor: action.address,
207
+ validator: regular?.address,
208
+ validUntil,
209
+ validAfter,
210
+ enableData: await regular.getEnableData(accountAddress)
211
+ })
212
+ }
213
+ throw new Error("EntryPoint v0.7 not supported yet")
214
+ },
196
215
  signUserOperation: async (userOperation) => {
197
216
  const userOpSig =
198
217
  await activeValidator.signUserOperation(userOperation)
@@ -13,10 +13,10 @@ import type {
13
13
  } from "permissionless/types"
14
14
  import {
15
15
  AccountOrClientNotFoundError,
16
- getAction,
17
16
  parseAccount
18
17
  } from "permissionless/utils"
19
18
  import type { Chain, Client, Transport } from "viem"
19
+ import { getAction } from "viem/utils"
20
20
 
21
21
  export type SignUserOperationParameters<
22
22
  entryPoint extends EntryPoint,
@@ -60,7 +60,8 @@ export async function signUserOperation<
60
60
 
61
61
  const userOperation = await getAction(
62
62
  client,
63
- prepareUserOperationRequest<entryPoint, TTransport, TChain, TAccount>
63
+ prepareUserOperationRequest<entryPoint, TTransport, TChain, TAccount>,
64
+ "prepareUserOperationRequest"
64
65
  )(args)
65
66
 
66
67
  userOperation.signature = await account.signUserOperation(
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zerodev/sdk",
3
- "version": "5.2.1-alpha-10",
3
+ "version": "5.2.1",
4
4
  "author": "ZeroDev",
5
5
  "main": "./_cjs/index.js",
6
6
  "module": "./_esm/index.js",
@@ -90,8 +90,8 @@
90
90
  }
91
91
  },
92
92
  "peerDependencies": {
93
- "viem": "^2.0.0",
94
- "permissionless": "^0.1.4"
93
+ "viem": "^2.9.17",
94
+ "permissionless": "^0.1.17"
95
95
  },
96
96
  "dependencies": {
97
97
  "semver": "^7.6.0"
package/types/kernel.ts CHANGED
@@ -1,4 +1,7 @@
1
- import type { EntryPoint } from "permissionless/types"
1
+ import type {
2
+ ENTRYPOINT_ADDRESS_V06_TYPE,
3
+ EntryPoint
4
+ } from "permissionless/types"
2
5
  import type { GetEntryPointVersion } from "permissionless/types/entrypoint"
3
6
  import type {
4
7
  UserOperation,
@@ -151,8 +154,22 @@ export type KernelPluginManager<entryPoint extends EntryPoint> =
151
154
  getAction(): Action
152
155
  getValidityData(): PluginValidityData
153
156
  getIdentifier(isSudo?: boolean): Hex
157
+ encodeModuleInstallCallData: (accountAddress: Address) => Promise<Hex>
154
158
  }
155
159
 
160
+ export type PluginInstallData<entryPoint extends EntryPoint> =
161
+ entryPoint extends ENTRYPOINT_ADDRESS_V06_TYPE
162
+ ? {
163
+ selector: Hex
164
+ executor: Address
165
+ validator: Address
166
+ validUntil: number
167
+ validAfter: number
168
+ enableData: Hex
169
+ }
170
+ : // TODO: Add support for EP v0.7
171
+ never
172
+
156
173
  export type KernelPluginManagerParams<entryPoint extends EntryPoint> = {
157
174
  sudo?: KernelValidator<entryPoint>
158
175
  regular?: KernelValidator<entryPoint>
package/utils.ts CHANGED
@@ -98,7 +98,8 @@ export const fixSignedData = (sig: Hex): Hex => {
98
98
 
99
99
  let { r, s, v } = hexToSignature(signature)
100
100
  if (v === 0n || v === 1n) v += 27n
101
- const joined = signatureToHex({ r, s, v })
101
+ // biome-ignore lint/style/noNonNullAssertion: <explanation>
102
+ const joined = signatureToHex({ r, s, v: v! })
102
103
  return joined
103
104
  }
104
105