@zerodev/sdk 5.4.5 → 5.4.7

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 (66) hide show
  1. package/_cjs/accounts/kernel/createKernelAccount.js +8 -3
  2. package/_cjs/accounts/kernel/createKernelAccount.js.map +1 -1
  3. package/_cjs/accounts/kernel/utils/common/eip712WrapHash.js +6 -2
  4. package/_cjs/accounts/kernel/utils/common/eip712WrapHash.js.map +1 -1
  5. package/_cjs/accounts/kernel/v2/createKernelAccountV0_2.js +1 -0
  6. package/_cjs/accounts/kernel/v2/createKernelAccountV0_2.js.map +1 -1
  7. package/_cjs/actions/account-client/upgradeKernel.js +36 -0
  8. package/_cjs/actions/account-client/upgradeKernel.js.map +1 -0
  9. package/_cjs/actions/public/getKernelImplementationAddress.js +21 -0
  10. package/_cjs/actions/public/getKernelImplementationAddress.js.map +1 -0
  11. package/_cjs/actions/public/index.js +3 -1
  12. package/_cjs/actions/public/index.js.map +1 -1
  13. package/_cjs/clients/decorators/kernel.js +2 -0
  14. package/_cjs/clients/decorators/kernel.js.map +1 -1
  15. package/_cjs/constants.js +10 -1
  16. package/_cjs/constants.js.map +1 -1
  17. package/_cjs/utils.js +3 -1
  18. package/_cjs/utils.js.map +1 -1
  19. package/_esm/accounts/kernel/createKernelAccount.js +9 -4
  20. package/_esm/accounts/kernel/createKernelAccount.js.map +1 -1
  21. package/_esm/accounts/kernel/utils/common/eip712WrapHash.js +6 -2
  22. package/_esm/accounts/kernel/utils/common/eip712WrapHash.js.map +1 -1
  23. package/_esm/accounts/kernel/v2/createKernelAccountV0_2.js +1 -0
  24. package/_esm/accounts/kernel/v2/createKernelAccountV0_2.js.map +1 -1
  25. package/_esm/actions/account-client/upgradeKernel.js +32 -0
  26. package/_esm/actions/account-client/upgradeKernel.js.map +1 -0
  27. package/_esm/actions/public/getKernelImplementationAddress.js +39 -0
  28. package/_esm/actions/public/getKernelImplementationAddress.js.map +1 -0
  29. package/_esm/actions/public/index.js +1 -0
  30. package/_esm/actions/public/index.js.map +1 -1
  31. package/_esm/clients/decorators/kernel.js +2 -0
  32. package/_esm/clients/decorators/kernel.js.map +1 -1
  33. package/_esm/constants.js +9 -0
  34. package/_esm/constants.js.map +1 -1
  35. package/_esm/utils.js +3 -1
  36. package/_esm/utils.js.map +1 -1
  37. package/_types/accounts/kernel/createKernelAccount.d.ts +8 -1
  38. package/_types/accounts/kernel/createKernelAccount.d.ts.map +1 -1
  39. package/_types/accounts/kernel/utils/common/eip712WrapHash.d.ts +1 -1
  40. package/_types/accounts/kernel/utils/common/eip712WrapHash.d.ts.map +1 -1
  41. package/_types/accounts/kernel/v2/createKernelAccountV0_2.d.ts.map +1 -1
  42. package/_types/actions/account-client/upgradeKernel.d.ts +8 -0
  43. package/_types/actions/account-client/upgradeKernel.d.ts.map +1 -0
  44. package/_types/actions/public/getKernelImplementationAddress.d.ts +28 -0
  45. package/_types/actions/public/getKernelImplementationAddress.d.ts.map +1 -0
  46. package/_types/actions/public/index.d.ts +1 -0
  47. package/_types/actions/public/index.d.ts.map +1 -1
  48. package/_types/clients/decorators/kernel.d.ts +9 -0
  49. package/_types/clients/decorators/kernel.d.ts.map +1 -1
  50. package/_types/constants.d.ts +3 -0
  51. package/_types/constants.d.ts.map +1 -1
  52. package/_types/types/kernel.d.ts +1 -1
  53. package/_types/types/kernel.d.ts.map +1 -1
  54. package/_types/utils.d.ts +2 -1
  55. package/_types/utils.d.ts.map +1 -1
  56. package/accounts/kernel/createKernelAccount.ts +32 -9
  57. package/accounts/kernel/utils/common/eip712WrapHash.ts +9 -2
  58. package/accounts/kernel/v2/createKernelAccountV0_2.ts +1 -0
  59. package/actions/account-client/upgradeKernel.ts +65 -0
  60. package/actions/public/getKernelImplementationAddress.ts +52 -0
  61. package/actions/public/index.ts +1 -0
  62. package/clients/decorators/kernel.ts +19 -0
  63. package/constants.ts +15 -0
  64. package/package.json +1 -1
  65. package/types/kernel.ts +1 -1
  66. package/utils.ts +4 -2
@@ -0,0 +1,65 @@
1
+ import type { Chain, Client, Hash, Prettify, Transport } from "viem"
2
+ import {
3
+ type SendUserOperationParameters,
4
+ type SmartAccount,
5
+ sendUserOperation
6
+ } from "viem/account-abstraction"
7
+ import { encodeFunctionData, getAction, parseAccount } from "viem/utils"
8
+ import { KernelV3AccountAbi } from "../../accounts/kernel/abi/kernel_v_3_0_0/KernelAccountAbi.js"
9
+ import { AccountNotFoundError } from "../../errors/index.js"
10
+ import type { KERNEL_VERSION_TYPE } from "../../types/kernel.js"
11
+ import { validateKernelVersionWithEntryPoint } from "../../utils.js"
12
+ import { KernelVersionToAddressesMap } from "../../constants.js";
13
+
14
+ export type UpgradeKernelParameters<
15
+ account extends SmartAccount | undefined,
16
+ accountOverride extends SmartAccount | undefined = undefined,
17
+ calls extends readonly unknown[] = readonly unknown[]
18
+ > = Prettify<
19
+ Partial<SendUserOperationParameters<account, accountOverride, calls>> & {
20
+ kernelVersion: KERNEL_VERSION_TYPE
21
+ }
22
+ >
23
+
24
+ export async function upgradeKernel<
25
+ account extends SmartAccount | undefined,
26
+ chain extends Chain | undefined,
27
+ accountOverride extends SmartAccount | undefined = undefined,
28
+ calls extends readonly unknown[] = readonly unknown[]
29
+ >(
30
+ client: Client<Transport, chain, account>,
31
+ args: Prettify<UpgradeKernelParameters<account, accountOverride, calls>>
32
+ ): Promise<Hash> {
33
+ const { account: account_ = client.account, kernelVersion } = args
34
+ if (!account_)
35
+ throw new AccountNotFoundError({
36
+ docsPath: "/docs/actions/wallet/sendTransaction"
37
+ })
38
+
39
+ const account = parseAccount(account_) as SmartAccount
40
+ validateKernelVersionWithEntryPoint(
41
+ account.entryPoint.version,
42
+ kernelVersion
43
+ )
44
+ const implementation = KernelVersionToAddressesMap[kernelVersion].accountImplementationAddress
45
+
46
+ return await getAction(
47
+ client,
48
+ sendUserOperation,
49
+ "sendUserOperation"
50
+ )({
51
+ ...args,
52
+ calls: [
53
+ {
54
+ to: account.address,
55
+ data: encodeFunctionData({
56
+ abi: KernelV3AccountAbi,
57
+ functionName: "upgradeTo",
58
+ args: [implementation]
59
+ }),
60
+ value: 0n
61
+ }
62
+ ],
63
+ account
64
+ } as SendUserOperationParameters)
65
+ }
@@ -0,0 +1,52 @@
1
+ import type { Address, Client } from "viem"
2
+ import { getStorageAt } from "viem/actions"
3
+ import { getAction, getAddress, isHex, slice, toHex } from "viem/utils"
4
+ import { KERNEL_IMPLEMENTATION_SLOT } from "../../constants"
5
+
6
+ export type GetKernelImplementationAddressParams = {
7
+ address: Address
8
+ }
9
+
10
+ /**
11
+ * Returns the address of the kernel implementation.
12
+ *
13
+ * @param client {@link client} that you created using viem's createPublicClient.
14
+ * @param args {@link GetKernelImplementationAddressParams} address
15
+ * @returns Address
16
+ *
17
+ * @example
18
+ * import { createPublicClient } from "viem"
19
+ * import { getKernelImplementationAddress } from "@zerodev/sdk/actions"
20
+ *
21
+ * const client = createPublicClient({
22
+ * chain: goerli,
23
+ * transport: http("https://goerli.infura.io/v3/your-infura-key")
24
+ * })
25
+ *
26
+ * const kernelImplementationAddress = await getKernelImplementationAddress(client, {
27
+ * address,
28
+ * })
29
+ *
30
+ * // Return 0x0000000000000000000000000000000000000000
31
+ */
32
+ export const getKernelImplementationAddress = async (
33
+ client: Client,
34
+ args: GetKernelImplementationAddressParams
35
+ ): Promise<Address> => {
36
+ const { address } = args
37
+
38
+ const storageValue = await getAction(
39
+ client,
40
+ getStorageAt,
41
+ "getStorageAt"
42
+ )({
43
+ address,
44
+ slot: KERNEL_IMPLEMENTATION_SLOT
45
+ })
46
+ if (!storageValue) {
47
+ throw new Error("Kernel implementation address not found")
48
+ }
49
+ const addressSlice = slice(storageValue, 12)
50
+ const addressHex = isHex(addressSlice) ? addressSlice : toHex(addressSlice)
51
+ return getAddress(addressHex)
52
+ }
@@ -8,3 +8,4 @@ export {
8
8
  getSenderAddress
9
9
  } from "./getSenderAddress.js"
10
10
  export { isSmartAccountDeployed } from "./isSmartAccountDeployed.js"
11
+ export { getKernelImplementationAddress } from "./getKernelImplementationAddress.js"
@@ -45,6 +45,10 @@ import {
45
45
  sponsorUserOperation
46
46
  } from "../../actions/paymaster/sponsorUserOperation.js"
47
47
  import type { ZeroDevPaymasterClient } from "../paymasterClient.js"
48
+ import {
49
+ upgradeKernel,
50
+ type UpgradeKernelParameters
51
+ } from "../../actions/account-client/upgradeKernel.js"
48
52
 
49
53
  export type ZeroDevPaymasterClientActions = {
50
54
  /**
@@ -157,6 +161,20 @@ export type KernelAccountClientActions<
157
161
  * @returns nonce
158
162
  */
159
163
  getKernelV3ModuleCurrentNonce: () => Promise<number>
164
+ /**
165
+ * Creates, signs, and sends a transaction to upgrade the kernel to the network.
166
+ * This function also allows you to sponsor this transaction if sender is a smartAccount
167
+ *
168
+ * @param args - {@link UpgradeKernelParameters}
169
+ * @returns The [Transaction](https://viem.sh/docs/glossary/terms.html#transaction) hash. {@link SendTransactionReturnType}
170
+ */
171
+ upgradeKernel: <
172
+ accountOverride extends SmartAccount | undefined = undefined,
173
+ calls extends readonly unknown[] = readonly unknown[]
174
+ >(
175
+ args: UpgradeKernelParameters<TSmartAccount, accountOverride, calls>
176
+ ) => Promise<Hash>
177
+
160
178
  /**
161
179
  * Creates, signs, and sends a new transaction to the network.
162
180
  * This function also allows you to sponsor this transaction if sender is a smartAccount
@@ -464,6 +482,7 @@ export function kernelAccountClientActions() {
464
482
  invalidateNonce: async (args) => invalidateNonce(client, args),
465
483
  getKernelV3ModuleCurrentNonce: async () =>
466
484
  getKernelV3ModuleCurrentNonce(client),
485
+ upgradeKernel: async (args) => upgradeKernel(client, args),
467
486
  // biome-ignore lint/suspicious/noExplicitAny: <explanation>
468
487
  sendTransaction: (args) => sendTransaction(client, args as any),
469
488
  signMessage: (args) => signMessage(client, args),
package/constants.ts CHANGED
@@ -14,6 +14,9 @@ import type {
14
14
  export const DUMMY_ECDSA_SIG =
15
15
  "0xfffffffffffffffffffffffffffffff0000000000000000000000000000000007aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa1c"
16
16
 
17
+ export const MAGIC_VALUE_SIG_REPLAYABLE =
18
+ "0x0555ad2729e8da1777a4e5020806f8bf7601c3db6bfe402f410a34958363a95a"
19
+
17
20
  // export const KernelImplToVersionMap: { [key: Address]: string } = {
18
21
  // "0x8dD4DBB54d8A8Cf0DE6F9CCC4609470A30EfF18C": "0.2.2",
19
22
  // "0x0DA6a956B9488eD4dd761E59f52FDc6c8068E6B5": "0.2.2",
@@ -74,6 +77,14 @@ export const KernelVersionToAddressesMap: {
74
77
  metaFactoryAddress: "0xd703aaE79538628d27099B8c4f621bE4CCd142d5",
75
78
  initCodeHash:
76
79
  "0x85d96aa1c9a65886d094915d76ccae85f14027a02c1647dde659f869460f03e6"
80
+ },
81
+ "0.3.2": {
82
+ accountImplementationAddress:
83
+ "0xD830D15D3dc0C269F3dBAa0F3e8626d33CFdaBe1",
84
+ factoryAddress: "0x7a1dBAB750f12a90EB1B60D2Ae3aD17D4D81EfFe",
85
+ metaFactoryAddress: "0xd703aaE79538628d27099B8c4f621bE4CCd142d5",
86
+ initCodeHash:
87
+ "0xc7c48c9dd12de68b8a4689b6f8c8c07b61d4d6fa4ddecdd86a6980d045fa67eb"
77
88
  }
78
89
  }
79
90
 
@@ -83,6 +94,7 @@ export const KERNEL_V2_3: KERNEL_V2_VERSION_TYPE = "0.2.3"
83
94
  export const KERNEL_V2_4: KERNEL_V2_VERSION_TYPE = "0.2.4"
84
95
  export const KERNEL_V3_0: KERNEL_V3_VERSION_TYPE = "0.3.0"
85
96
  export const KERNEL_V3_1: KERNEL_V3_VERSION_TYPE = "0.3.1"
97
+ export const KERNEL_V3_2: KERNEL_V3_VERSION_TYPE = "0.3.2"
86
98
 
87
99
  export const TOKEN_ACTION = "0x2087C7FfD0d0DAE80a00EE74325aBF3449e0eaf1"
88
100
  export const ONLY_ENTRYPOINT_HOOK_ADDRESS =
@@ -119,6 +131,9 @@ export const KernelFactoryToInitCodeHashMap: { [key: Address]: Hex } = {
119
131
  "0x6fe6e6ea30eddce942b9618033ab8429f9ddac594053bec8a6744fffc71976e2"
120
132
  }
121
133
 
134
+ export const KERNEL_IMPLEMENTATION_SLOT =
135
+ "0x360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc"
136
+
122
137
  export const getEntryPoint = <TEntryPointVersion extends EntryPointVersion>(
123
138
  entryPointVersion: TEntryPointVersion
124
139
  ): EntryPointType<TEntryPointVersion> => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zerodev/sdk",
3
- "version": "5.4.5",
3
+ "version": "5.4.7",
4
4
  "author": "ZeroDev",
5
5
  "main": "./_cjs/index.js",
6
6
  "module": "./_esm/index.js",
package/types/kernel.ts CHANGED
@@ -243,7 +243,7 @@ export type Execution = {
243
243
 
244
244
  export type KERNEL_V2_VERSION_TYPE = "0.0.2" | "0.2.2" | "0.2.3" | "0.2.4"
245
245
 
246
- export type KERNEL_V3_VERSION_TYPE = "0.3.0" | "0.3.1"
246
+ export type KERNEL_V3_VERSION_TYPE = "0.3.0" | "0.3.1" | "0.3.2"
247
247
 
248
248
  export type KERNEL_VERSION_TYPE =
249
249
  | KERNEL_V2_VERSION_TYPE
package/utils.ts CHANGED
@@ -19,13 +19,15 @@ import type { EntryPointType, GetKernelVersion } from "./types/kernel.js"
19
19
  export enum KERNEL_FEATURES {
20
20
  ERC1271_SIG_WRAPPER = "ERC1271_SIG_WRAPPER",
21
21
  ERC1271_WITH_VALIDATOR = "ERC1271_WITH_VALIDATOR",
22
- ERC1271_SIG_WRAPPER_WITH_WRAPPED_HASH = "ERC1271_SIG_WRAPPER_WITH_WRAPPED_HASH"
22
+ ERC1271_SIG_WRAPPER_WITH_WRAPPED_HASH = "ERC1271_SIG_WRAPPER_WITH_WRAPPED_HASH",
23
+ ERC1271_REPLAYABLE = "ERC1271_REPLAYABLE"
23
24
  }
24
25
 
25
26
  export const KERNEL_FEATURES_BY_VERSION: Record<KERNEL_FEATURES, string> = {
26
27
  [KERNEL_FEATURES.ERC1271_SIG_WRAPPER]: ">=0.2.3 || >=0.3.0-beta",
27
28
  [KERNEL_FEATURES.ERC1271_WITH_VALIDATOR]: ">=0.3.0-beta",
28
- [KERNEL_FEATURES.ERC1271_SIG_WRAPPER_WITH_WRAPPED_HASH]: ">=0.3.0-beta"
29
+ [KERNEL_FEATURES.ERC1271_SIG_WRAPPER_WITH_WRAPPED_HASH]: ">=0.3.0-beta",
30
+ [KERNEL_FEATURES.ERC1271_REPLAYABLE]: ">=0.3.2"
29
31
  }
30
32
 
31
33
  export const hasKernelFeature = (