@zerodev/sdk 5.2.0-alpha-1 → 5.2.0-alpha-3

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 (215) hide show
  1. package/README.md +3 -0
  2. package/_cjs/accounts/index.js +9 -2
  3. package/_cjs/accounts/index.js.map +1 -1
  4. package/_cjs/accounts/kernel/abi/EIP1271Abi.js +37 -0
  5. package/_cjs/accounts/kernel/abi/EIP1271Abi.js.map +1 -0
  6. package/_cjs/accounts/kernel/abi/SafeCreateCallAbi.js +9 -0
  7. package/_cjs/accounts/kernel/abi/SafeCreateCallAbi.js.map +1 -0
  8. package/_cjs/accounts/kernel/createKernelAccount.js +124 -378
  9. package/_cjs/accounts/kernel/createKernelAccount.js.map +1 -1
  10. package/_cjs/accounts/kernel/utils/account/ep0_6/encodeCallData.js +26 -0
  11. package/_cjs/accounts/kernel/utils/account/ep0_6/encodeCallData.js.map +1 -0
  12. package/_cjs/accounts/kernel/utils/account/ep0_6/encodeDeployCallData.js +16 -0
  13. package/_cjs/accounts/kernel/utils/account/ep0_6/encodeDeployCallData.js.map +1 -0
  14. package/_cjs/accounts/kernel/utils/account/ep0_7/encodeCallData.js +30 -0
  15. package/_cjs/accounts/kernel/utils/account/ep0_7/encodeCallData.js.map +1 -0
  16. package/_cjs/accounts/kernel/utils/account/ep0_7/encodeDeployCallData.js +18 -0
  17. package/_cjs/accounts/kernel/utils/account/ep0_7/encodeDeployCallData.js.map +1 -0
  18. package/_cjs/accounts/kernel/utils/common/accountMetadata.js +46 -0
  19. package/_cjs/accounts/kernel/utils/common/accountMetadata.js.map +1 -0
  20. package/_cjs/accounts/kernel/utils/common/eip712WrapHash.js +28 -0
  21. package/_cjs/accounts/kernel/utils/common/eip712WrapHash.js.map +1 -0
  22. package/_cjs/accounts/kernel/utils/common/encodeSafeCreateCall.js +14 -0
  23. package/_cjs/accounts/kernel/utils/common/encodeSafeCreateCall.js.map +1 -0
  24. package/_cjs/accounts/kernel/utils/ep0_6/encodeExecuteBatchCall.js +22 -0
  25. package/_cjs/accounts/kernel/utils/ep0_6/encodeExecuteBatchCall.js.map +1 -0
  26. package/_cjs/accounts/kernel/utils/ep0_6/encodeExecuteDelegateCall.js +14 -0
  27. package/_cjs/accounts/kernel/utils/ep0_6/encodeExecuteDelegateCall.js.map +1 -0
  28. package/_cjs/accounts/kernel/utils/ep0_6/encodeExecuteSingleCall.js +14 -0
  29. package/_cjs/accounts/kernel/utils/ep0_6/encodeExecuteSingleCall.js.map +1 -0
  30. package/_cjs/accounts/kernel/utils/ep0_7/encodeExecuteBatchCall.js +42 -0
  31. package/_cjs/accounts/kernel/utils/ep0_7/encodeExecuteBatchCall.js.map +1 -0
  32. package/_cjs/accounts/kernel/utils/ep0_7/encodeExecuteCall.js +29 -0
  33. package/_cjs/accounts/kernel/utils/ep0_7/encodeExecuteCall.js.map +1 -0
  34. package/_cjs/accounts/kernel/utils/ep0_7/encodeExecuteDelegateCall.js +13 -0
  35. package/_cjs/accounts/kernel/utils/ep0_7/encodeExecuteDelegateCall.js.map +1 -0
  36. package/_cjs/accounts/kernel/utils/ep0_7/encodeExecuteSingleCall.js +13 -0
  37. package/_cjs/accounts/kernel/utils/ep0_7/encodeExecuteSingleCall.js.map +1 -0
  38. package/_cjs/accounts/kernel/utils/ep0_7/hashKernelSignatureWrapper.js +9 -0
  39. package/_cjs/accounts/kernel/utils/ep0_7/hashKernelSignatureWrapper.js.map +1 -0
  40. package/_cjs/accounts/kernel/utils/types.js +3 -0
  41. package/_cjs/accounts/kernel/utils/types.js.map +1 -0
  42. package/_cjs/accounts/kernel/v1/createKernelV1Account.js +1 -2
  43. package/_cjs/accounts/kernel/v1/createKernelV1Account.js.map +1 -1
  44. package/_cjs/accounts/kernel/v2/abi/KernelAccountV2Abi.js +377 -0
  45. package/_cjs/accounts/kernel/v2/abi/KernelAccountV2Abi.js.map +1 -0
  46. package/_cjs/accounts/kernel/v2/abi/KernelFactoryV2Abi.js +115 -0
  47. package/_cjs/accounts/kernel/v2/abi/KernelFactoryV2Abi.js.map +1 -0
  48. package/_cjs/accounts/kernel/v2/createKernelV2Account.js +226 -0
  49. package/_cjs/accounts/kernel/v2/createKernelV2Account.js.map +1 -0
  50. package/_cjs/accounts/utils/multisend.js.map +1 -0
  51. package/_cjs/accounts/utils/toKernelPluginManager.js +19 -4
  52. package/_cjs/accounts/utils/toKernelPluginManager.js.map +1 -1
  53. package/_cjs/constants.js +2 -1
  54. package/_cjs/constants.js.map +1 -1
  55. package/_cjs/index.js +3 -2
  56. package/_cjs/index.js.map +1 -1
  57. package/_cjs/types/kernel.js.map +1 -1
  58. package/_cjs/utils.js +1 -1
  59. package/_cjs/utils.js.map +1 -1
  60. package/_esm/accounts/index.js +5 -1
  61. package/_esm/accounts/index.js.map +1 -1
  62. package/_esm/accounts/kernel/abi/EIP1271Abi.js +34 -0
  63. package/_esm/accounts/kernel/abi/EIP1271Abi.js.map +1 -0
  64. package/_esm/accounts/kernel/abi/SafeCreateCallAbi.js +6 -0
  65. package/_esm/accounts/kernel/abi/SafeCreateCallAbi.js.map +1 -0
  66. package/_esm/accounts/kernel/createKernelAccount.js +135 -398
  67. package/_esm/accounts/kernel/createKernelAccount.js.map +1 -1
  68. package/_esm/accounts/kernel/utils/account/ep0_6/encodeCallData.js +23 -0
  69. package/_esm/accounts/kernel/utils/account/ep0_6/encodeCallData.js.map +1 -0
  70. package/_esm/accounts/kernel/utils/account/ep0_6/encodeDeployCallData.js +13 -0
  71. package/_esm/accounts/kernel/utils/account/ep0_6/encodeDeployCallData.js.map +1 -0
  72. package/_esm/accounts/kernel/utils/account/ep0_7/encodeCallData.js +28 -0
  73. package/_esm/accounts/kernel/utils/account/ep0_7/encodeCallData.js.map +1 -0
  74. package/_esm/accounts/kernel/utils/account/ep0_7/encodeDeployCallData.js +15 -0
  75. package/_esm/accounts/kernel/utils/account/ep0_7/encodeDeployCallData.js.map +1 -0
  76. package/_esm/accounts/kernel/utils/common/accountMetadata.js +42 -0
  77. package/_esm/accounts/kernel/utils/common/accountMetadata.js.map +1 -0
  78. package/_esm/accounts/kernel/utils/common/eip712WrapHash.js +24 -0
  79. package/_esm/accounts/kernel/utils/common/eip712WrapHash.js.map +1 -0
  80. package/_esm/accounts/kernel/utils/common/encodeSafeCreateCall.js +10 -0
  81. package/_esm/accounts/kernel/utils/common/encodeSafeCreateCall.js.map +1 -0
  82. package/_esm/accounts/kernel/utils/ep0_6/encodeExecuteBatchCall.js +18 -0
  83. package/_esm/accounts/kernel/utils/ep0_6/encodeExecuteBatchCall.js.map +1 -0
  84. package/_esm/accounts/kernel/utils/ep0_6/encodeExecuteDelegateCall.js +10 -0
  85. package/_esm/accounts/kernel/utils/ep0_6/encodeExecuteDelegateCall.js.map +1 -0
  86. package/_esm/accounts/kernel/utils/ep0_6/encodeExecuteSingleCall.js +10 -0
  87. package/_esm/accounts/kernel/utils/ep0_6/encodeExecuteSingleCall.js.map +1 -0
  88. package/_esm/accounts/kernel/utils/ep0_7/encodeExecuteBatchCall.js +38 -0
  89. package/_esm/accounts/kernel/utils/ep0_7/encodeExecuteBatchCall.js.map +1 -0
  90. package/_esm/accounts/kernel/utils/ep0_7/encodeExecuteCall.js +25 -0
  91. package/_esm/accounts/kernel/utils/ep0_7/encodeExecuteCall.js.map +1 -0
  92. package/_esm/accounts/kernel/utils/ep0_7/encodeExecuteDelegateCall.js +9 -0
  93. package/_esm/accounts/kernel/utils/ep0_7/encodeExecuteDelegateCall.js.map +1 -0
  94. package/_esm/accounts/kernel/utils/ep0_7/encodeExecuteSingleCall.js +9 -0
  95. package/_esm/accounts/kernel/utils/ep0_7/encodeExecuteSingleCall.js.map +1 -0
  96. package/_esm/accounts/kernel/utils/ep0_7/hashKernelSignatureWrapper.js +5 -0
  97. package/_esm/accounts/kernel/utils/ep0_7/hashKernelSignatureWrapper.js.map +1 -0
  98. package/_esm/accounts/kernel/utils/types.js +2 -0
  99. package/_esm/accounts/kernel/utils/types.js.map +1 -0
  100. package/_esm/accounts/kernel/v1/createKernelV1Account.js +1 -2
  101. package/_esm/accounts/kernel/v1/createKernelV1Account.js.map +1 -1
  102. package/_esm/accounts/kernel/v2/abi/KernelAccountV2Abi.js +374 -0
  103. package/_esm/accounts/kernel/v2/abi/KernelAccountV2Abi.js.map +1 -0
  104. package/_esm/accounts/kernel/v2/abi/KernelFactoryV2Abi.js +112 -0
  105. package/_esm/accounts/kernel/v2/abi/KernelFactoryV2Abi.js.map +1 -0
  106. package/_esm/accounts/kernel/v2/createKernelV2Account.js +264 -0
  107. package/_esm/accounts/kernel/v2/createKernelV2Account.js.map +1 -0
  108. package/_esm/accounts/{kernel/v1 → utils}/multisend.js +1 -1
  109. package/_esm/accounts/utils/multisend.js.map +1 -0
  110. package/_esm/accounts/utils/toKernelPluginManager.js +19 -4
  111. package/_esm/accounts/utils/toKernelPluginManager.js.map +1 -1
  112. package/_esm/constants.js +3 -0
  113. package/_esm/constants.js.map +1 -1
  114. package/_esm/index.js +1 -1
  115. package/_esm/index.js.map +1 -1
  116. package/_esm/types/kernel.js.map +1 -1
  117. package/_esm/utils.js +1 -1
  118. package/_esm/utils.js.map +1 -1
  119. package/_types/accounts/index.d.ts +5 -1
  120. package/_types/accounts/index.d.ts.map +1 -1
  121. package/_types/accounts/kernel/abi/EIP1271Abi.d.ts +54 -0
  122. package/_types/accounts/kernel/abi/EIP1271Abi.d.ts.map +1 -0
  123. package/_types/accounts/kernel/abi/SafeCreateCallAbi.d.ts +35 -0
  124. package/_types/accounts/kernel/abi/SafeCreateCallAbi.d.ts.map +1 -0
  125. package/_types/accounts/kernel/createKernelAccount.d.ts +0 -54
  126. package/_types/accounts/kernel/createKernelAccount.d.ts.map +1 -1
  127. package/_types/accounts/kernel/utils/account/ep0_6/encodeCallData.d.ts +4 -0
  128. package/_types/accounts/kernel/utils/account/ep0_6/encodeCallData.d.ts.map +1 -0
  129. package/_types/accounts/kernel/utils/account/ep0_6/encodeDeployCallData.d.ts +3 -0
  130. package/_types/accounts/kernel/utils/account/ep0_6/encodeDeployCallData.d.ts.map +1 -0
  131. package/_types/accounts/kernel/utils/account/ep0_7/encodeCallData.d.ts +4 -0
  132. package/_types/accounts/kernel/utils/account/ep0_7/encodeCallData.d.ts.map +1 -0
  133. package/_types/accounts/kernel/utils/account/ep0_7/encodeDeployCallData.d.ts +3 -0
  134. package/_types/accounts/kernel/utils/account/ep0_7/encodeDeployCallData.d.ts.map +1 -0
  135. package/_types/accounts/kernel/utils/common/accountMetadata.d.ts +10 -0
  136. package/_types/accounts/kernel/utils/common/accountMetadata.d.ts.map +1 -0
  137. package/_types/accounts/kernel/utils/common/eip712WrapHash.d.ts +4 -0
  138. package/_types/accounts/kernel/utils/common/eip712WrapHash.d.ts.map +1 -0
  139. package/_types/accounts/kernel/utils/common/encodeSafeCreateCall.d.ts +2 -0
  140. package/_types/accounts/kernel/utils/common/encodeSafeCreateCall.d.ts.map +1 -0
  141. package/_types/accounts/kernel/utils/ep0_6/encodeExecuteBatchCall.d.ts +3 -0
  142. package/_types/accounts/kernel/utils/ep0_6/encodeExecuteBatchCall.d.ts.map +1 -0
  143. package/_types/accounts/kernel/utils/ep0_6/encodeExecuteDelegateCall.d.ts +3 -0
  144. package/_types/accounts/kernel/utils/ep0_6/encodeExecuteDelegateCall.d.ts.map +1 -0
  145. package/_types/accounts/kernel/utils/ep0_6/encodeExecuteSingleCall.d.ts +3 -0
  146. package/_types/accounts/kernel/utils/ep0_6/encodeExecuteSingleCall.d.ts.map +1 -0
  147. package/_types/accounts/kernel/utils/ep0_7/encodeExecuteBatchCall.d.ts +4 -0
  148. package/_types/accounts/kernel/utils/ep0_7/encodeExecuteBatchCall.d.ts.map +1 -0
  149. package/_types/accounts/kernel/utils/ep0_7/encodeExecuteCall.d.ts +16 -0
  150. package/_types/accounts/kernel/utils/ep0_7/encodeExecuteCall.d.ts.map +1 -0
  151. package/_types/accounts/kernel/utils/ep0_7/encodeExecuteDelegateCall.d.ts +4 -0
  152. package/_types/accounts/kernel/utils/ep0_7/encodeExecuteDelegateCall.d.ts.map +1 -0
  153. package/_types/accounts/kernel/utils/ep0_7/encodeExecuteSingleCall.d.ts +4 -0
  154. package/_types/accounts/kernel/utils/ep0_7/encodeExecuteSingleCall.d.ts.map +1 -0
  155. package/_types/accounts/kernel/utils/ep0_7/hashKernelSignatureWrapper.d.ts +3 -0
  156. package/_types/accounts/kernel/utils/ep0_7/hashKernelSignatureWrapper.d.ts.map +1 -0
  157. package/_types/accounts/kernel/utils/types.d.ts +8 -0
  158. package/_types/accounts/kernel/utils/types.d.ts.map +1 -0
  159. package/_types/accounts/kernel/v1/createKernelV1Account.d.ts.map +1 -1
  160. package/_types/accounts/kernel/v2/abi/KernelAccountV2Abi.d.ts +447 -0
  161. package/_types/accounts/kernel/v2/abi/KernelAccountV2Abi.d.ts.map +1 -0
  162. package/_types/accounts/kernel/v2/abi/KernelFactoryV2Abi.d.ts +109 -0
  163. package/_types/accounts/kernel/v2/abi/KernelFactoryV2Abi.d.ts.map +1 -0
  164. package/_types/accounts/kernel/v2/createKernelV2Account.d.ts +33 -0
  165. package/_types/accounts/kernel/v2/createKernelV2Account.d.ts.map +1 -0
  166. package/_types/accounts/{kernel/v1 → utils}/multisend.d.ts +1 -1
  167. package/_types/accounts/utils/multisend.d.ts.map +1 -0
  168. package/_types/accounts/utils/toKernelPluginManager.d.ts +1 -1
  169. package/_types/accounts/utils/toKernelPluginManager.d.ts.map +1 -1
  170. package/_types/constants.d.ts +1 -0
  171. package/_types/constants.d.ts.map +1 -1
  172. package/_types/index.d.ts +1 -1
  173. package/_types/index.d.ts.map +1 -1
  174. package/_types/types/index.d.ts +1 -0
  175. package/_types/types/index.d.ts.map +1 -1
  176. package/_types/types/kernel.d.ts +2 -0
  177. package/_types/types/kernel.d.ts.map +1 -1
  178. package/_types/utils.d.ts +4 -1
  179. package/_types/utils.d.ts.map +1 -1
  180. package/accounts/index.ts +5 -2
  181. package/accounts/kernel/abi/EIP1271Abi.ts +33 -0
  182. package/accounts/kernel/abi/SafeCreateCallAbi.ts +6 -0
  183. package/accounts/kernel/createKernelAccount.ts +176 -541
  184. package/accounts/kernel/utils/account/ep0_6/encodeCallData.ts +32 -0
  185. package/accounts/kernel/utils/account/ep0_6/encodeDeployCallData.ts +18 -0
  186. package/accounts/kernel/utils/account/ep0_7/encodeCallData.ts +40 -0
  187. package/accounts/kernel/utils/account/ep0_7/encodeDeployCallData.ts +20 -0
  188. package/accounts/kernel/utils/common/accountMetadata.ts +62 -0
  189. package/accounts/kernel/utils/common/eip712WrapHash.ts +48 -0
  190. package/accounts/kernel/utils/common/encodeSafeCreateCall.ts +14 -0
  191. package/accounts/kernel/utils/ep0_6/encodeExecuteBatchCall.ts +19 -0
  192. package/accounts/kernel/utils/ep0_6/encodeExecuteDelegateCall.ts +11 -0
  193. package/accounts/kernel/utils/ep0_6/encodeExecuteSingleCall.ts +11 -0
  194. package/accounts/kernel/utils/ep0_7/encodeExecuteBatchCall.ts +51 -0
  195. package/accounts/kernel/utils/ep0_7/encodeExecuteCall.ts +38 -0
  196. package/accounts/kernel/utils/ep0_7/encodeExecuteDelegateCall.ts +16 -0
  197. package/accounts/kernel/utils/ep0_7/encodeExecuteSingleCall.ts +16 -0
  198. package/accounts/kernel/utils/ep0_7/hashKernelSignatureWrapper.ts +11 -0
  199. package/accounts/kernel/utils/types.ts +8 -0
  200. package/accounts/kernel/v1/createKernelV1Account.ts +2 -3
  201. package/accounts/kernel/v2/abi/KernelAccountV2Abi.ts +373 -0
  202. package/accounts/kernel/v2/abi/KernelFactoryV2Abi.ts +111 -0
  203. package/accounts/kernel/v2/createKernelV2Account.ts +409 -0
  204. package/accounts/{kernel/v1 → utils}/multisend.ts +1 -1
  205. package/accounts/utils/toKernelPluginManager.ts +21 -7
  206. package/constants.ts +5 -0
  207. package/index.ts +2 -1
  208. package/package.json +1 -1
  209. package/types/index.ts +2 -0
  210. package/types/kernel.ts +2 -0
  211. package/utils.ts +7 -1
  212. package/_cjs/accounts/kernel/v1/multisend.js.map +0 -1
  213. package/_esm/accounts/kernel/v1/multisend.js.map +0 -1
  214. package/_types/accounts/kernel/v1/multisend.d.ts.map +0 -1
  215. /package/_cjs/accounts/{kernel/v1 → utils}/multisend.js +0 -0
@@ -0,0 +1,409 @@
1
+ import {
2
+ ENTRYPOINT_ADDRESS_V06,
3
+ getAccountNonce,
4
+ getSenderAddress,
5
+ isSmartAccountDeployed
6
+ } from "permissionless"
7
+ import {
8
+ SignTransactionNotSupportedBySmartAccount,
9
+ type SmartAccount
10
+ } from "permissionless/accounts"
11
+ import type {
12
+ ENTRYPOINT_ADDRESS_V06_TYPE,
13
+ EntryPoint
14
+ } from "permissionless/types/entrypoint.js"
15
+ import {
16
+ type Address,
17
+ type Chain,
18
+ type Client,
19
+ type EncodeDeployDataParameters,
20
+ type Hash,
21
+ type Hex,
22
+ type Transport,
23
+ type TypedDataDefinition,
24
+ concatHex,
25
+ encodeDeployData,
26
+ encodeFunctionData,
27
+ getTypesForEIP712Domain,
28
+ hashMessage,
29
+ hashTypedData,
30
+ parseAbi,
31
+ validateTypedData
32
+ } from "viem"
33
+ import { toAccount } from "viem/accounts"
34
+ import type {
35
+ KernelEncodeCallDataArgs,
36
+ KernelPluginManager,
37
+ KernelPluginManagerParams
38
+ } from "../../../types/kernel.js"
39
+ import { wrapSignatureWith6492 } from "../../utils/6492.js"
40
+ import { parseFactoryAddressAndCallDataFromAccountInitCode } from "../../utils/index.js"
41
+ import {
42
+ MULTISEND_ADDRESS,
43
+ encodeMultiSend,
44
+ multiSendAbi
45
+ } from "../../utils/multisend.js"
46
+ import {
47
+ isKernelPluginManager,
48
+ toKernelPluginManager
49
+ } from "../../utils/toKernelPluginManager.js"
50
+ import { KernelAccountV2Abi } from "./abi/KernelAccountV2Abi.js"
51
+ import { KernelFactoryV2Abi } from "./abi/KernelFactoryV2Abi.js"
52
+
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
+ encodeCallData: (args: KernelEncodeCallDataArgs) => Promise<Hex>
60
+ }
61
+
62
+ // Safe's library for create and create2: https://github.com/safe-global/safe-contracts/blob/0acdd35a203299585438f53885df630f9d486a86/contracts/libraries/CreateCall.sol
63
+ // Address was found here: https://github.com/safe-global/safe-deployments/blob/926ec6bbe2ebcac3aa2c2c6c0aff74aa590cbc6a/src/assets/v1.4.1/create_call.json
64
+ const createCallAddress = "0x9b35Af71d77eaf8d7e40252370304687390A1A52"
65
+
66
+ const createCallAbi = parseAbi([
67
+ "function performCreate(uint256 value, bytes memory deploymentData) public returns (address newContract)",
68
+ "function performCreate2(uint256 value, bytes memory deploymentData, bytes32 salt) public returns (address newContract)"
69
+ ])
70
+
71
+ /**
72
+ * Default addresses for kernel smart account
73
+ */
74
+ export const KERNEL_ADDRESSES: {
75
+ FACTORY_ADDRESS: Address
76
+ ENTRYPOINT_V0_6: Address
77
+ } = {
78
+ FACTORY_ADDRESS: "0xaee9762ce625e0a8f7b184670fb57c37bfe1d0f1",
79
+ ENTRYPOINT_V0_6: "0x5FF137D4b0FDCD49DcA30c7CF57E578a026d2789"
80
+ }
81
+
82
+ /**
83
+ * Get the account initialization code for a kernel smart account
84
+ * @param index
85
+ * @param factoryAddress
86
+ * @param ecdsaValidatorAddress
87
+ */
88
+ const getAccountInitCode = async ({
89
+ index,
90
+ factoryAddress,
91
+ validatorAddress,
92
+ enableData
93
+ }: {
94
+ index: bigint
95
+ factoryAddress: Address
96
+ validatorAddress: Address
97
+ enableData: Hex
98
+ }): Promise<Hex> => {
99
+ // Build the account init code
100
+ return concatHex([
101
+ factoryAddress,
102
+ encodeFunctionData({
103
+ abi: KernelFactoryV2Abi,
104
+ functionName: "createAccount",
105
+ args: [validatorAddress, enableData, index]
106
+ }) as Hex
107
+ ])
108
+ }
109
+
110
+ /**
111
+ * Check the validity of an existing account address, or fetch the pre-deterministic account address for a kernel smart wallet
112
+ * @param client
113
+ * @param entryPoint
114
+ * @param initCodeProvider
115
+ */
116
+ const getAccountAddress = async <
117
+ entryPoint extends EntryPoint,
118
+ TTransport extends Transport = Transport,
119
+ TChain extends Chain | undefined = Chain | undefined
120
+ >({
121
+ client,
122
+ entryPoint: entryPointAddress,
123
+ initCodeProvider
124
+ }: {
125
+ client: Client<TTransport, TChain, undefined>
126
+ initCodeProvider: () => Promise<Hex>
127
+ entryPoint: entryPoint
128
+ }): Promise<Address> => {
129
+ // Find the init code for this account
130
+ const initCode = await initCodeProvider()
131
+
132
+ // Get the sender address based on the init code
133
+ return getSenderAddress(client, {
134
+ initCode,
135
+ entryPoint: entryPointAddress as ENTRYPOINT_ADDRESS_V06_TYPE
136
+ })
137
+ }
138
+
139
+ /**
140
+ * Build a kernel smart account from a private key, that use the ECDSA signer behind the scene
141
+ * @param client
142
+ * @param privateKey
143
+ * @param entryPoint
144
+ * @param index
145
+ * @param factoryAddress
146
+ * @param ecdsaValidatorAddress
147
+ * @param deployedAccountAddress
148
+ */
149
+ export async function createKernelV2Account<
150
+ entryPoint extends EntryPoint,
151
+ TTransport extends Transport = Transport,
152
+ TChain extends Chain | undefined = Chain | undefined
153
+ >(
154
+ client: Client<TTransport, TChain, undefined>,
155
+ {
156
+ plugins,
157
+ entryPoint: entryPointAddress = ENTRYPOINT_ADDRESS_V06 as entryPoint,
158
+ index = 0n,
159
+ factoryAddress = KERNEL_ADDRESSES.FACTORY_ADDRESS,
160
+ deployedAccountAddress
161
+ }: {
162
+ plugins:
163
+ | KernelPluginManagerParams<entryPoint>
164
+ | KernelPluginManager<entryPoint>
165
+ entryPoint?: entryPoint
166
+ index?: bigint
167
+ factoryAddress?: Address
168
+ deployedAccountAddress?: Address
169
+ }
170
+ ): Promise<KernelSmartAccount<entryPoint, TTransport, TChain>> {
171
+ const kernelPluginManager = isKernelPluginManager<entryPoint>(plugins)
172
+ ? plugins
173
+ : await toKernelPluginManager(client, {
174
+ sudo: plugins.sudo,
175
+ regular: plugins.regular,
176
+ executorData: plugins.executorData,
177
+ pluginEnableSignature: plugins.pluginEnableSignature,
178
+ kernelVersion: "0.0.2" ?? plugins.kernelVersion,
179
+ entryPoint: entryPointAddress
180
+ })
181
+ // Helper to generate the init code for the smart account
182
+ const generateInitCode = async () => {
183
+ const validatorInitData =
184
+ await kernelPluginManager.getValidatorInitData()
185
+ return getAccountInitCode({
186
+ index,
187
+ factoryAddress,
188
+ validatorAddress: validatorInitData.validatorAddress,
189
+ enableData: validatorInitData.enableData
190
+ })
191
+ }
192
+
193
+ // Fetch account address and chain id
194
+ const accountAddress =
195
+ deployedAccountAddress ??
196
+ (await getAccountAddress<entryPoint, TTransport, TChain>({
197
+ client,
198
+ entryPoint: entryPointAddress,
199
+ initCodeProvider: generateInitCode
200
+ }))
201
+
202
+ if (!accountAddress) throw new Error("Account address not found")
203
+
204
+ // Build the EOA Signer
205
+ const account = toAccount({
206
+ address: accountAddress,
207
+ async signMessage({ message }) {
208
+ const messageHash = hashMessage(message)
209
+ const [isDeployed, signature] = await Promise.all([
210
+ isSmartAccountDeployed(client, accountAddress),
211
+ kernelPluginManager.signMessage({
212
+ message: {
213
+ raw: messageHash
214
+ }
215
+ })
216
+ ])
217
+ return create6492Signature(isDeployed, signature)
218
+ },
219
+ async signTransaction(_, __) {
220
+ throw new SignTransactionNotSupportedBySmartAccount()
221
+ },
222
+ async signTypedData(typedData) {
223
+ const types = {
224
+ EIP712Domain: getTypesForEIP712Domain({
225
+ domain: typedData.domain
226
+ }),
227
+ ...typedData.types
228
+ }
229
+
230
+ // Need to do a runtime validation check on addresses, byte ranges, integer ranges, etc
231
+ // as we can't statically check this with TypeScript.
232
+ validateTypedData({
233
+ domain: typedData.domain,
234
+ message: typedData.message,
235
+ primaryType: typedData.primaryType,
236
+ types: types
237
+ } as TypedDataDefinition)
238
+
239
+ const typedHash = hashTypedData(typedData)
240
+ const [isDeployed, signature] = await Promise.all([
241
+ isSmartAccountDeployed(client, accountAddress),
242
+ kernelPluginManager.signMessage({
243
+ message: {
244
+ raw: typedHash
245
+ }
246
+ })
247
+ ])
248
+ return create6492Signature(isDeployed, signature)
249
+ }
250
+ })
251
+
252
+ let smartAccountDeployed = await isSmartAccountDeployed(
253
+ client,
254
+ accountAddress
255
+ )
256
+
257
+ const create6492Signature = async (
258
+ isDeployed: boolean,
259
+ signature: Hash
260
+ ): Promise<Hash> => {
261
+ if (isDeployed) {
262
+ return signature
263
+ }
264
+
265
+ const [factoryAddress, factoryCalldata] =
266
+ parseFactoryAddressAndCallDataFromAccountInitCode(
267
+ await generateInitCode()
268
+ )
269
+
270
+ return wrapSignatureWith6492({
271
+ factoryAddress,
272
+ factoryCalldata,
273
+ signature
274
+ })
275
+ }
276
+
277
+ return {
278
+ ...account,
279
+ client: client,
280
+ publicKey: accountAddress,
281
+ entryPoint: entryPointAddress,
282
+ source: "kernelSmartAccount",
283
+ kernelPluginManager,
284
+ async getFactory() {
285
+ if (smartAccountDeployed) return undefined
286
+
287
+ smartAccountDeployed = await isSmartAccountDeployed(
288
+ client,
289
+ accountAddress
290
+ )
291
+
292
+ if (smartAccountDeployed) return undefined
293
+
294
+ return factoryAddress
295
+ },
296
+
297
+ async getFactoryData() {
298
+ if (smartAccountDeployed) return undefined
299
+
300
+ smartAccountDeployed = await isSmartAccountDeployed(
301
+ client,
302
+ accountAddress
303
+ )
304
+
305
+ if (smartAccountDeployed) return undefined
306
+
307
+ return parseFactoryAddressAndCallDataFromAccountInitCode(
308
+ await generateInitCode()
309
+ )[1]
310
+ },
311
+
312
+ // Get the nonce of the smart account
313
+ async getNonce() {
314
+ const key = await kernelPluginManager.getNonceKey()
315
+ return getAccountNonce(client, {
316
+ sender: accountAddress,
317
+ entryPoint: entryPointAddress,
318
+ key
319
+ })
320
+ },
321
+
322
+ // Sign a user operation
323
+ async signUserOperation(userOperation) {
324
+ return kernelPluginManager.signUserOperation(userOperation)
325
+ },
326
+
327
+ // Encode the init code
328
+ async getInitCode() {
329
+ if (smartAccountDeployed) return "0x"
330
+
331
+ smartAccountDeployed = await isSmartAccountDeployed(
332
+ client,
333
+ accountAddress
334
+ )
335
+
336
+ if (smartAccountDeployed) return "0x"
337
+ return generateInitCode()
338
+ },
339
+
340
+ // Encode the deploy call data
341
+ async encodeDeployCallData(_tx) {
342
+ return encodeFunctionData({
343
+ abi: KernelAccountV2Abi,
344
+ functionName: "execute",
345
+ args: [
346
+ createCallAddress,
347
+ 0n,
348
+ encodeFunctionData({
349
+ abi: createCallAbi,
350
+ functionName: "performCreate",
351
+ args: [
352
+ 0n,
353
+ encodeDeployData({
354
+ abi: _tx.abi,
355
+ bytecode: _tx.bytecode,
356
+ args: _tx.args
357
+ } as EncodeDeployDataParameters)
358
+ ]
359
+ }),
360
+ 1 // Delegate call
361
+ ]
362
+ })
363
+ },
364
+
365
+ // Encode a call
366
+ async encodeCallData(_tx) {
367
+ const tx = _tx as KernelEncodeCallDataArgs
368
+ if (Array.isArray(tx)) {
369
+ const multiSendCallData = encodeFunctionData({
370
+ abi: multiSendAbi,
371
+ functionName: "multiSend",
372
+ args: [encodeMultiSend(tx)]
373
+ })
374
+ return encodeFunctionData({
375
+ abi: KernelAccountV2Abi,
376
+ functionName: "execute",
377
+ args: [MULTISEND_ADDRESS, 0n, multiSendCallData, 1]
378
+ })
379
+ }
380
+
381
+ // Default to `call`
382
+ if (!tx.callType || tx.callType === "call") {
383
+ if (tx.to.toLowerCase() === accountAddress.toLowerCase()) {
384
+ return tx.data
385
+ }
386
+ return encodeFunctionData({
387
+ abi: KernelAccountV2Abi,
388
+ functionName: "execute",
389
+ args: [tx.to, tx.value, tx.data, 0]
390
+ })
391
+ }
392
+
393
+ if (tx.callType === "delegatecall") {
394
+ return encodeFunctionData({
395
+ abi: KernelAccountV2Abi,
396
+ functionName: "execute",
397
+ args: [tx.to, 0n, tx.data, 1]
398
+ })
399
+ }
400
+
401
+ throw new Error("Invalid call type")
402
+ },
403
+
404
+ // Get simple dummy signature
405
+ async getDummySignature(userOperation) {
406
+ return kernelPluginManager.getDummySignature(userOperation)
407
+ }
408
+ }
409
+ }
@@ -2,7 +2,7 @@ import { type Address, type Hex, encodePacked, toBytes } from "viem"
2
2
  import {
3
3
  type CallType,
4
4
  type KernelEncodeCallDataArgs
5
- } from "../../../types/index.js"
5
+ } from "../../types/index.js"
6
6
 
7
7
  export const MULTISEND_ADDRESS = "0x8ae01fcf7c655655ff2c6ef907b8b4718ab4e17c"
8
8
 
@@ -54,7 +54,8 @@ export async function toKernelPluginManager<
54
54
  },
55
55
  validAfter = 0,
56
56
  validUntil = 0,
57
- entryPoint: entryPointAddress
57
+ entryPoint: entryPointAddress,
58
+ kernelVersion
58
59
  }: KernelPluginManagerParams<entryPoint>
59
60
  ): Promise<KernelPluginManager<entryPoint>> {
60
61
  const entryPointVersion = getEntryPointVersion(entryPointAddress)
@@ -167,16 +168,14 @@ export async function toKernelPluginManager<
167
168
  client,
168
169
  accountAddress
169
170
  )
170
- const kernelVersion = getKernelVersion(
171
- entryPointAddress,
172
- kernelImplAddr
173
- )
171
+ const _kernelVersion =
172
+ kernelVersion ?? getKernelVersion(entryPointAddress, kernelImplAddr)
174
173
  let ownerSig: Hex
175
174
  if (entryPointVersion === "v0.6") {
176
175
  ownerSig = await sudo.signTypedData({
177
176
  domain: {
178
177
  name: "Kernel",
179
- version: kernelVersion,
178
+ version: _kernelVersion,
180
179
  chainId,
181
180
  verifyingContract: accountAddress
182
181
  },
@@ -213,7 +212,7 @@ export async function toKernelPluginManager<
213
212
  ownerSig = await sudo.signTypedData({
214
213
  domain: {
215
214
  name: "Kernel",
216
- version: kernelVersion,
215
+ version: _kernelVersion,
217
216
  chainId,
218
217
  verifyingContract: accountAddress
219
218
  },
@@ -278,6 +277,21 @@ export async function toKernelPluginManager<
278
277
 
279
278
  return {
280
279
  ...activeValidator,
280
+ getValidationId: (isSudo = false) => {
281
+ const validator = (isSudo ? sudo : regular) ?? activeValidator
282
+ return concat([
283
+ validator.isPermissionValidator
284
+ ? VALIDATOR_TYPE.PERMISSION
285
+ : VALIDATOR_TYPE.SECONDARY,
286
+ validator?.isPermissionValidator
287
+ ? // @ts-ignore
288
+ pad(validator.getPermissionId() as Hex, {
289
+ size: 20,
290
+ dir: "right"
291
+ })
292
+ : validator.address
293
+ ])
294
+ },
281
295
  signUserOperation: async (userOperation) => {
282
296
  const userOpSig =
283
297
  await activeValidator.signUserOperation(userOperation)
package/constants.ts CHANGED
@@ -36,3 +36,8 @@ export enum EXEC_TYPE {
36
36
  DEFAULT = "0x00",
37
37
  TRY_EXEC = "0x01"
38
38
  }
39
+
40
+ // Safe's library for create and create2: https://github.com/safe-global/safe-contracts/blob/0acdd35a203299585438f53885df630f9d486a86/contracts/libraries/CreateCall.sol
41
+ // Address was found here: https://github.com/safe-global/safe-deployments/blob/926ec6bbe2ebcac3aa2c2c6c0aff74aa590cbc6a/src/assets/v1.4.1/create_call.json
42
+ export const safeCreateCallAddress =
43
+ "0x9b35Af71d77eaf8d7e40252370304687390A1A52"
package/index.ts CHANGED
@@ -1,10 +1,11 @@
1
1
  export {
2
2
  createKernelAccount,
3
3
  createKernelV1Account,
4
+ createKernelV2Account,
4
5
  type KernelSmartAccount,
5
6
  KERNEL_ADDRESSES,
6
7
  addressToEmptyAccount,
7
- EIP1271ABI
8
+ EIP1271Abi
8
9
  } from "./accounts/index.js"
9
10
  export {
10
11
  sponsorUserOperation,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zerodev/sdk",
3
- "version": "5.2.0-alpha-1",
3
+ "version": "5.2.0-alpha-3",
4
4
  "author": "ZeroDev",
5
5
  "main": "./_cjs/index.js",
6
6
  "module": "./_esm/index.js",
package/types/index.ts CHANGED
@@ -10,3 +10,5 @@ export type {
10
10
  } from "./kernel.js"
11
11
 
12
12
  export { ValidatorMode } from "./kernel.js"
13
+
14
+ export type WithRequired<T, K extends keyof T> = Required<Pick<T, K>>
package/types/kernel.ts CHANGED
@@ -136,6 +136,7 @@ export type KernelPluginManager<entryPoint extends EntryPoint> =
136
136
  getValidatorInitData(): Promise<ValidatorInitData>
137
137
  getExecutorData(): ExecutorData
138
138
  getValidityData(): PluginValidityData
139
+ getValidationId(isSudo?: boolean): Hex
139
140
  }
140
141
 
141
142
  export type KernelPluginManagerParams<entryPoint extends EntryPoint> = {
@@ -145,6 +146,7 @@ export type KernelPluginManagerParams<entryPoint extends EntryPoint> = {
145
146
  validatorInitData?: ValidatorInitData
146
147
  executorData?: ExecutorData
147
148
  entryPoint: entryPoint
149
+ kernelVersion?: string
148
150
  } & Partial<PluginValidityData>
149
151
 
150
152
  export type ExecutorData = {
package/utils.ts CHANGED
@@ -103,7 +103,13 @@ export const fixSignedData = (sig: Hex): Hex => {
103
103
  return joined
104
104
  }
105
105
 
106
- export const getExecMode = (callType: CALL_TYPE, execType: EXEC_TYPE): Hex => {
106
+ export const getExecMode = ({
107
+ callType,
108
+ execType
109
+ }: {
110
+ callType: CALL_TYPE
111
+ execType: EXEC_TYPE
112
+ }): Hex => {
107
113
  return concatHex([
108
114
  callType, // 1 byte
109
115
  execType, // 1 byte
@@ -1 +0,0 @@
1
- {"version":3,"file":"multisend.js","sourceRoot":"","sources":["../../../../accounts/kernel/v1/multisend.ts"],"names":[],"mappings":";;;AAAA,+BAAoE;AAMvD,QAAA,iBAAiB,GAAG,4CAA4C,CAAA;AAEhE,QAAA,YAAY,GAAG;IACxB;QACI,IAAI,EAAE,UAAU;QAChB,IAAI,EAAE,WAAW;QACjB,MAAM,EAAE,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,IAAI,EAAE,cAAc,EAAE,CAAC;KACpD;CACJ,CAAA;AAED,MAAM,UAAU,GAAG,CAAC,IAKnB,EAAU,EAAE;IACT,MAAM,IAAI,GAAG,IAAA,cAAO,EAAC,IAAI,CAAC,IAAI,CAAC,CAAA;IAC/B,MAAM,OAAO,GAAG,IAAA,mBAAY,EACxB,CAAC,OAAO,EAAE,SAAS,EA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