@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,32 @@
1
+ import type { EntryPoint } from "permissionless/types/entrypoint.js"
2
+ import type { KernelSmartAccount } from "../../../createKernelAccount.js"
3
+ import { encodeExecuteBatchCall } from "../../ep0_6/encodeExecuteBatchCall.js"
4
+ import { encodeExecuteDelegateCall } from "../../ep0_6/encodeExecuteDelegateCall.js"
5
+ import { encodeExecuteSingleCall } from "../../ep0_6/encodeExecuteSingleCall.js"
6
+
7
+ export const encodeCallData = async <
8
+ entryPoint extends EntryPoint = EntryPoint
9
+ >(
10
+ tx: Parameters<KernelSmartAccount<entryPoint>["encodeCallData"]>[0]
11
+ ) => {
12
+ if (Array.isArray(tx)) {
13
+ if (tx.some((t) => t.callType === "delegatecall")) {
14
+ throw new Error("Cannot batch delegatecall")
15
+ }
16
+ return encodeExecuteBatchCall(tx)
17
+ }
18
+
19
+ // Default to `call`
20
+ if (!tx.callType || tx.callType === "call") {
21
+ return encodeExecuteSingleCall(tx)
22
+ }
23
+
24
+ if (tx.callType === "delegatecall") {
25
+ return encodeExecuteDelegateCall({
26
+ to: tx.to,
27
+ data: tx.data
28
+ })
29
+ }
30
+
31
+ throw new Error("Invalid call type")
32
+ }
@@ -0,0 +1,18 @@
1
+ import { toSmartAccount } from "permissionless/accounts"
2
+ import { encodeDeployData } from "viem"
3
+ import { safeCreateCallAddress } from "../../../../../constants.js"
4
+ import { encodeSafeCreateCall } from "../../common/encodeSafeCreateCall.js"
5
+ import { encodeExecuteDelegateCall } from "../../ep0_6/encodeExecuteDelegateCall.js"
6
+ import type { DelegateCallArgs } from "../../types.js"
7
+
8
+ export const encodeDeployCallData = (
9
+ tx: Parameters<
10
+ Parameters<typeof toSmartAccount>[0]["encodeDeployCallData"]
11
+ >[0]
12
+ ) => {
13
+ const deployCalldataArgs: DelegateCallArgs = {
14
+ to: safeCreateCallAddress,
15
+ data: encodeSafeCreateCall([0n, encodeDeployData(tx)])
16
+ }
17
+ return encodeExecuteDelegateCall(deployCalldataArgs)
18
+ }
@@ -0,0 +1,40 @@
1
+ import type { EntryPoint } from "permissionless/types/entrypoint.js"
2
+ import { EXEC_TYPE } from "../../../../../constants.js"
3
+ import type { KernelSmartAccount } from "../../../createKernelAccount.js"
4
+ import { encodeExecuteBatchCall } from "../../ep0_7/encodeExecuteBatchCall.js"
5
+ import { encodeExecuteDelegateCall } from "../../ep0_7/encodeExecuteDelegateCall.js"
6
+ import { encodeExecuteSingleCall } from "../../ep0_7/encodeExecuteSingleCall.js"
7
+
8
+ export const encodeCallData = async <
9
+ entryPoint extends EntryPoint = EntryPoint
10
+ >(
11
+ tx: Parameters<KernelSmartAccount<entryPoint>["encodeCallData"]>[0]
12
+ ) => {
13
+ if (Array.isArray(tx)) {
14
+ if (tx.some((t) => t.callType === "delegatecall")) {
15
+ throw new Error("Cannot batch delegatecall")
16
+ }
17
+ // Encode a batched call
18
+ return encodeExecuteBatchCall(tx, {
19
+ execType: EXEC_TYPE.DEFAULT
20
+ })
21
+ }
22
+
23
+ // Default to `call`
24
+ if (!tx.callType || tx.callType === "call") {
25
+ return encodeExecuteSingleCall(tx, {
26
+ execType: EXEC_TYPE.DEFAULT
27
+ })
28
+ }
29
+
30
+ if (tx.callType === "delegatecall") {
31
+ return encodeExecuteDelegateCall(
32
+ { to: tx.to, data: tx.data },
33
+ {
34
+ execType: EXEC_TYPE.DEFAULT
35
+ }
36
+ )
37
+ }
38
+
39
+ throw new Error("Invalid call type")
40
+ }
@@ -0,0 +1,20 @@
1
+ import { toSmartAccount } from "permissionless/accounts"
2
+ import { encodeDeployData } from "viem"
3
+ import { EXEC_TYPE, safeCreateCallAddress } from "../../../../../constants.js"
4
+ import { encodeSafeCreateCall } from "../../common/encodeSafeCreateCall.js"
5
+ import { encodeExecuteDelegateCall } from "../../ep0_7/encodeExecuteDelegateCall.js"
6
+ import type { DelegateCallArgs } from "../../types.js"
7
+
8
+ export const encodeDeployCallData = (
9
+ tx: Parameters<
10
+ Parameters<typeof toSmartAccount>[0]["encodeDeployCallData"]
11
+ >[0]
12
+ ) => {
13
+ const deployCalldataArgs: DelegateCallArgs = {
14
+ to: safeCreateCallAddress,
15
+ data: encodeSafeCreateCall([0n, encodeDeployData(tx)])
16
+ }
17
+ return encodeExecuteDelegateCall(deployCalldataArgs, {
18
+ execType: EXEC_TYPE.DEFAULT
19
+ })
20
+ }
@@ -0,0 +1,62 @@
1
+ import type { EntryPoint } from "permissionless/types/entrypoint.js"
2
+ import {
3
+ type Address,
4
+ type Chain,
5
+ type Client,
6
+ type Transport,
7
+ decodeFunctionResult,
8
+ encodeFunctionData,
9
+ publicActions
10
+ } from "viem"
11
+ import { KERNEL_NAME } from "../../../../constants.js"
12
+ import { getKernelVersion } from "../../../../utils.js"
13
+ import { EIP1271Abi } from "../../abi/EIP1271Abi.js"
14
+
15
+ type AccountMetadata = {
16
+ name: string
17
+ version: string
18
+ chainId: bigint
19
+ }
20
+ export const accountMetadata = async <
21
+ TTransport extends Transport = Transport,
22
+ TChain extends Chain | undefined = Chain | undefined
23
+ >(
24
+ client: Client<TTransport, TChain, undefined>,
25
+ accountAddress: Address,
26
+ entryPointAddress: EntryPoint
27
+ ): Promise<AccountMetadata> => {
28
+ try {
29
+ const domain = await client.request({
30
+ method: "eth_call",
31
+ params: [
32
+ {
33
+ to: accountAddress,
34
+ data: encodeFunctionData({
35
+ abi: EIP1271Abi,
36
+ functionName: "eip712Domain"
37
+ })
38
+ },
39
+ "latest"
40
+ ]
41
+ })
42
+ if (domain !== "0x") {
43
+ const decoded = decodeFunctionResult({
44
+ abi: [...EIP1271Abi],
45
+ functionName: "eip712Domain",
46
+ data: domain
47
+ })
48
+ return {
49
+ name: decoded[1],
50
+ version: decoded[2],
51
+ chainId: decoded[3]
52
+ }
53
+ }
54
+ } catch (error) {}
55
+ return {
56
+ name: KERNEL_NAME,
57
+ version: getKernelVersion(entryPointAddress),
58
+ chainId: client.chain
59
+ ? BigInt(client.chain.id)
60
+ : BigInt(await client.extend(publicActions).getChainId())
61
+ }
62
+ }
@@ -0,0 +1,48 @@
1
+ import {
2
+ type Hex,
3
+ type TypedDataDomain,
4
+ concatHex,
5
+ domainSeparator,
6
+ keccak256
7
+ } from "viem"
8
+ import type { WithRequired } from "../../../../types/index.js"
9
+ import { KERNEL_FEATURES, hasKernelFeature } from "../../../../utils.js"
10
+ import { hashKernelMessageHashWrapper } from "../ep0_7/hashKernelSignatureWrapper.js"
11
+
12
+ export const eip712WrapHash = async (
13
+ messageHash: Hex,
14
+ domain: WithRequired<
15
+ TypedDataDomain,
16
+ "name" | "chainId" | "verifyingContract" | "version"
17
+ >
18
+ ): Promise<Hex> => {
19
+ const { name, version, chainId, verifyingContract } = domain
20
+
21
+ if (!hasKernelFeature(KERNEL_FEATURES.ERC1271_SIG_WRAPPER, version)) {
22
+ return messageHash
23
+ }
24
+
25
+ const _domainSeparator = domainSeparator({
26
+ domain: {
27
+ name,
28
+ version,
29
+ chainId,
30
+ verifyingContract
31
+ }
32
+ })
33
+
34
+ let finalMessageHash = messageHash
35
+ if (
36
+ hasKernelFeature(
37
+ KERNEL_FEATURES.ERC1271_SIG_WRAPPER_WITH_WRAPPED_HASH,
38
+ version
39
+ )
40
+ ) {
41
+ finalMessageHash = hashKernelMessageHashWrapper(finalMessageHash)
42
+ }
43
+
44
+ const digest = keccak256(
45
+ concatHex(["0x1901", _domainSeparator, finalMessageHash])
46
+ )
47
+ return digest
48
+ }
@@ -0,0 +1,14 @@
1
+ import { encodeFunctionData } from "viem"
2
+ import { SafeCreateCallAbi } from "../../abi/SafeCreateCallAbi.js"
3
+
4
+ type EncodeExecuteDelegateCallArgs = Parameters<
5
+ typeof encodeFunctionData<typeof SafeCreateCallAbi, "performCreate">
6
+ >[0]["args"]
7
+
8
+ export const encodeSafeCreateCall = (args: EncodeExecuteDelegateCallArgs) => {
9
+ return encodeFunctionData({
10
+ abi: SafeCreateCallAbi,
11
+ functionName: "performCreate",
12
+ args
13
+ })
14
+ }
@@ -0,0 +1,19 @@
1
+ import { encodeFunctionData } from "viem"
2
+ import { KernelExecuteAbi } from "../../abi/KernelAccountAbi.js"
3
+ import type { CallArgs } from "../types.js"
4
+
5
+ export const encodeExecuteBatchCall = (args: CallArgs[]) => {
6
+ return encodeFunctionData({
7
+ abi: KernelExecuteAbi,
8
+ functionName: "executeBatch",
9
+ args: [
10
+ args.map((arg) => {
11
+ return {
12
+ to: arg.to,
13
+ value: arg.value,
14
+ data: arg.data
15
+ }
16
+ })
17
+ ]
18
+ })
19
+ }
@@ -0,0 +1,11 @@
1
+ import { encodeFunctionData } from "viem"
2
+ import { KernelExecuteAbi } from "../../abi/KernelAccountAbi.js"
3
+ import type { DelegateCallArgs } from "../types.js"
4
+
5
+ export const encodeExecuteDelegateCall = (args: DelegateCallArgs) => {
6
+ return encodeFunctionData({
7
+ abi: KernelExecuteAbi,
8
+ functionName: "executeDelegateCall",
9
+ args: [args.to, args.data]
10
+ })
11
+ }
@@ -0,0 +1,11 @@
1
+ import { encodeFunctionData } from "viem"
2
+ import { KernelExecuteAbi } from "../../abi/KernelAccountAbi.js"
3
+ import type { CallArgs } from "../types.js"
4
+
5
+ export const encodeExecuteSingleCall = (args: CallArgs) => {
6
+ return encodeFunctionData({
7
+ abi: KernelExecuteAbi,
8
+ functionName: "execute",
9
+ args: [args.to, args.value, args.data, 0]
10
+ })
11
+ }
@@ -0,0 +1,51 @@
1
+ import { encodeAbiParameters } from "viem"
2
+ import { CALL_TYPE } from "../../../../constants.js"
3
+ import type { CallArgs } from "../types.js"
4
+ import {
5
+ type EncodeExecuteOptions,
6
+ encodeExecuteCall
7
+ } from "./encodeExecuteCall.js"
8
+
9
+ export const encodeExecuteBatchCall = (
10
+ args: CallArgs[],
11
+ options: Omit<EncodeExecuteOptions, "callType">
12
+ ) => {
13
+ const calldata = encodeAbiParameters(
14
+ [
15
+ {
16
+ name: "executionBatch",
17
+ type: "tuple[]",
18
+ components: [
19
+ {
20
+ name: "target",
21
+ type: "address"
22
+ },
23
+ {
24
+ name: "value",
25
+ type: "uint256"
26
+ },
27
+ {
28
+ name: "callData",
29
+ type: "bytes"
30
+ }
31
+ ]
32
+ }
33
+ ],
34
+ [
35
+ args.map((arg) => {
36
+ return {
37
+ target: arg.to,
38
+ value: arg.value,
39
+ callData: arg.data
40
+ }
41
+ })
42
+ ]
43
+ )
44
+ return encodeExecuteCall(
45
+ { calldata },
46
+ {
47
+ callType: CALL_TYPE.BATCH,
48
+ execType: options.execType
49
+ }
50
+ )
51
+ }
@@ -0,0 +1,38 @@
1
+ import { type Hex, concatHex, encodeFunctionData, toHex } from "viem"
2
+ import { CALL_TYPE } from "../../../../constants.js"
3
+ import { getExecMode } from "../../../../utils.js"
4
+ import { KernelV3ExecuteAbi } from "../../abi/kernel_v_3_0_0/KernelAccountAbi.js"
5
+ import type { CallArgs, DelegateCallArgs } from "../types.js"
6
+
7
+ export type EncodeExecuteOptions = Parameters<typeof getExecMode>[0]
8
+
9
+ type EncodeExecuteCallArgs<TOptions> =
10
+ | (TOptions extends {
11
+ callType: CALL_TYPE.DELEGATE_CALL
12
+ }
13
+ ? DelegateCallArgs
14
+ : CallArgs)
15
+ | { calldata: Hex }
16
+
17
+ export const encodeExecuteCall = <TOptions extends EncodeExecuteOptions>(
18
+ args: EncodeExecuteCallArgs<TOptions>,
19
+ options: TOptions
20
+ ) => {
21
+ let calldata: Hex
22
+ if ("calldata" in args) {
23
+ calldata = args.calldata
24
+ } else {
25
+ calldata = concatHex([
26
+ args.to,
27
+ options.callType !== CALL_TYPE.DELEGATE_CALL
28
+ ? toHex(args.value, { size: 32 })
29
+ : "0x", // No value if delegate call
30
+ args.data
31
+ ])
32
+ }
33
+ return encodeFunctionData({
34
+ abi: KernelV3ExecuteAbi,
35
+ functionName: "execute",
36
+ args: [getExecMode(options), calldata]
37
+ })
38
+ }
@@ -0,0 +1,16 @@
1
+ import { CALL_TYPE } from "../../../../constants.js"
2
+ import type { DelegateCallArgs } from "../types.js"
3
+ import {
4
+ type EncodeExecuteOptions,
5
+ encodeExecuteCall
6
+ } from "./encodeExecuteCall.js"
7
+
8
+ export const encodeExecuteDelegateCall = (
9
+ args: DelegateCallArgs,
10
+ options: Omit<EncodeExecuteOptions, "callType">
11
+ ) => {
12
+ return encodeExecuteCall(args, {
13
+ callType: CALL_TYPE.DELEGATE_CALL,
14
+ execType: options.execType
15
+ })
16
+ }
@@ -0,0 +1,16 @@
1
+ import { CALL_TYPE } from "../../../../constants.js"
2
+ import type { CallArgs } from "../types.js"
3
+ import {
4
+ type EncodeExecuteOptions,
5
+ encodeExecuteCall
6
+ } from "./encodeExecuteCall.js"
7
+
8
+ export const encodeExecuteSingleCall = (
9
+ args: CallArgs,
10
+ options: Omit<EncodeExecuteOptions, "callType">
11
+ ) => {
12
+ return encodeExecuteCall(args, {
13
+ callType: CALL_TYPE.SINGLE,
14
+ execType: options.execType
15
+ })
16
+ }
@@ -0,0 +1,11 @@
1
+ import type { Hex } from "viem"
2
+ import { encodeAbiParameters, keccak256, stringToHex } from "viem"
3
+
4
+ export const hashKernelMessageHashWrapper = (messageHash: Hex) => {
5
+ return keccak256(
6
+ encodeAbiParameters(
7
+ [{ type: "bytes32" }, { type: "bytes32" }],
8
+ [keccak256(stringToHex("Kernel(bytes32 hash)")), messageHash]
9
+ )
10
+ )
11
+ }
@@ -0,0 +1,8 @@
1
+ import type { Address, Hex } from "viem"
2
+
3
+ export type CallArgs = {
4
+ to: Address
5
+ data: Hex
6
+ value: bigint
7
+ }
8
+ export type DelegateCallArgs = Omit<CallArgs, "value">
@@ -28,12 +28,12 @@ import { getChainId, signMessage, signTypedData } from "viem/actions"
28
28
  import { type KernelEncodeCallDataArgs } from "../../../types/kernel.js"
29
29
  import { wrapSignatureWith6492 } from "../../utils/6492.js"
30
30
  import { parseFactoryAddressAndCallDataFromAccountInitCode } from "../../utils/index.js"
31
- import { type KernelSmartAccount } from "../createKernelAccount.js"
32
31
  import {
33
32
  MULTISEND_ADDRESS,
34
33
  encodeMultiSend,
35
34
  multiSendAbi
36
- } from "./multisend.js"
35
+ } from "../../utils/multisend.js"
36
+ import { type KernelSmartAccount } from "../createKernelAccount.js"
37
37
 
38
38
  export type KernelV1SmartAccount<
39
39
  entryPoint extends EntryPoint,
@@ -204,7 +204,6 @@ export async function createKernelV1Account<
204
204
  publicKey: accountAddress,
205
205
  entryPoint: entryPointAddress,
206
206
  source: "kernelSmartAccount",
207
- generateInitCode,
208
207
  async getFactory() {
209
208
  if (smartAccountDeployed) return undefined
210
209