@zerodev/sdk 5.1.12 → 5.2.0-alpha-0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (122) hide show
  1. package/_cjs/accounts/kernel/abi/kernel_v_3_0_0/KernelAccountAbi.js +738 -0
  2. package/_cjs/accounts/kernel/abi/kernel_v_3_0_0/KernelAccountAbi.js.map +1 -0
  3. package/_cjs/accounts/kernel/abi/kernel_v_3_0_0/KernelModuleAbi.js +15 -0
  4. package/_cjs/accounts/kernel/abi/kernel_v_3_0_0/KernelModuleAbi.js.map +1 -0
  5. package/_cjs/accounts/kernel/createKernelAccount.js +231 -75
  6. package/_cjs/accounts/kernel/createKernelAccount.js.map +1 -1
  7. package/_cjs/accounts/kernel/v1/createKernelV1Account.js +29 -18
  8. package/_cjs/accounts/kernel/v1/createKernelV1Account.js.map +1 -1
  9. package/_cjs/accounts/utils/6492.js +19 -3
  10. package/_cjs/accounts/utils/6492.js.map +1 -1
  11. package/_cjs/accounts/utils/index.js +4 -3
  12. package/_cjs/accounts/utils/index.js.map +1 -1
  13. package/_cjs/accounts/utils/toKernelPluginManager.js +194 -62
  14. package/_cjs/accounts/utils/toKernelPluginManager.js.map +1 -1
  15. package/_cjs/actions/account-client/signUserOperation.js +1 -1
  16. package/_cjs/actions/account-client/signUserOperation.js.map +1 -1
  17. package/_cjs/actions/paymaster/estimateGasInERC20.js.map +1 -1
  18. package/_cjs/actions/paymaster/sponsorUserOperation.js +17 -14
  19. package/_cjs/actions/paymaster/sponsorUserOperation.js.map +1 -1
  20. package/_cjs/clients/decorators/kernel.js +8 -5
  21. package/_cjs/clients/decorators/kernel.js.map +1 -1
  22. package/_cjs/clients/kernelAccountClient.js +3 -3
  23. package/_cjs/clients/kernelAccountClient.js.map +1 -1
  24. package/_cjs/clients/paymasterClient.js +1 -1
  25. package/_cjs/clients/paymasterClient.js.map +1 -1
  26. package/_cjs/constants.js +28 -3
  27. package/_cjs/constants.js.map +1 -1
  28. package/_cjs/index.js +5 -1
  29. package/_cjs/index.js.map +1 -1
  30. package/_cjs/providers/KernelEIP1193Provider.js.map +1 -1
  31. package/_cjs/types/kernel.js.map +1 -1
  32. package/_cjs/utils.js +34 -3
  33. package/_cjs/utils.js.map +1 -1
  34. package/_esm/accounts/kernel/abi/kernel_v_3_0_0/KernelAccountAbi.js +735 -0
  35. package/_esm/accounts/kernel/abi/kernel_v_3_0_0/KernelAccountAbi.js.map +1 -0
  36. package/_esm/accounts/kernel/abi/kernel_v_3_0_0/KernelModuleAbi.js +12 -0
  37. package/_esm/accounts/kernel/abi/kernel_v_3_0_0/KernelModuleAbi.js.map +1 -0
  38. package/_esm/accounts/kernel/createKernelAccount.js +240 -81
  39. package/_esm/accounts/kernel/createKernelAccount.js.map +1 -1
  40. package/_esm/accounts/kernel/v1/createKernelV1Account.js +37 -20
  41. package/_esm/accounts/kernel/v1/createKernelV1Account.js.map +1 -1
  42. package/_esm/accounts/utils/6492.js +16 -1
  43. package/_esm/accounts/utils/6492.js.map +1 -1
  44. package/_esm/accounts/utils/index.js +2 -4
  45. package/_esm/accounts/utils/index.js.map +1 -1
  46. package/_esm/accounts/utils/toKernelPluginManager.js +198 -66
  47. package/_esm/accounts/utils/toKernelPluginManager.js.map +1 -1
  48. package/_esm/actions/account-client/signUserOperation.js +1 -1
  49. package/_esm/actions/account-client/signUserOperation.js.map +1 -1
  50. package/_esm/actions/paymaster/estimateGasInERC20.js.map +1 -1
  51. package/_esm/actions/paymaster/sponsorUserOperation.js +37 -15
  52. package/_esm/actions/paymaster/sponsorUserOperation.js.map +1 -1
  53. package/_esm/clients/decorators/kernel.js +9 -5
  54. package/_esm/clients/decorators/kernel.js.map +1 -1
  55. package/_esm/clients/kernelAccountClient.js +3 -3
  56. package/_esm/clients/kernelAccountClient.js.map +1 -1
  57. package/_esm/clients/paymasterClient.js +1 -1
  58. package/_esm/clients/paymasterClient.js.map +1 -1
  59. package/_esm/constants.js +27 -2
  60. package/_esm/constants.js.map +1 -1
  61. package/_esm/index.js +1 -0
  62. package/_esm/index.js.map +1 -1
  63. package/_esm/providers/KernelEIP1193Provider.js.map +1 -1
  64. package/_esm/types/kernel.js +1 -0
  65. package/_esm/types/kernel.js.map +1 -1
  66. package/_esm/utils.js +33 -4
  67. package/_esm/utils.js.map +1 -1
  68. package/_types/accounts/kernel/abi/kernel_v_3_0_0/KernelAccountAbi.d.ts +843 -0
  69. package/_types/accounts/kernel/abi/kernel_v_3_0_0/KernelAccountAbi.d.ts.map +1 -0
  70. package/_types/accounts/kernel/abi/kernel_v_3_0_0/KernelModuleAbi.d.ts +16 -0
  71. package/_types/accounts/kernel/abi/kernel_v_3_0_0/KernelModuleAbi.d.ts.map +1 -0
  72. package/_types/accounts/kernel/createKernelAccount.d.ts +14 -11
  73. package/_types/accounts/kernel/createKernelAccount.d.ts.map +1 -1
  74. package/_types/accounts/kernel/v1/createKernelV1Account.d.ts +5 -4
  75. package/_types/accounts/kernel/v1/createKernelV1Account.d.ts.map +1 -1
  76. package/_types/accounts/utils/6492.d.ts +3 -1
  77. package/_types/accounts/utils/6492.d.ts.map +1 -1
  78. package/_types/accounts/utils/index.d.ts +2 -4
  79. package/_types/accounts/utils/index.d.ts.map +1 -1
  80. package/_types/accounts/utils/toKernelPluginManager.d.ts +3 -2
  81. package/_types/accounts/utils/toKernelPluginManager.d.ts.map +1 -1
  82. package/_types/actions/account-client/signUserOperation.d.ts +7 -7
  83. package/_types/actions/account-client/signUserOperation.d.ts.map +1 -1
  84. package/_types/actions/paymaster/estimateGasInERC20.d.ts +3 -2
  85. package/_types/actions/paymaster/estimateGasInERC20.d.ts.map +1 -1
  86. package/_types/actions/paymaster/sponsorUserOperation.d.ts +7 -6
  87. package/_types/actions/paymaster/sponsorUserOperation.d.ts.map +1 -1
  88. package/_types/clients/decorators/kernel.d.ts +8 -7
  89. package/_types/clients/decorators/kernel.d.ts.map +1 -1
  90. package/_types/clients/kernelAccountClient.d.ts +101 -22
  91. package/_types/clients/kernelAccountClient.d.ts.map +1 -1
  92. package/_types/clients/paymasterClient.d.ts +6 -3
  93. package/_types/clients/paymasterClient.d.ts.map +1 -1
  94. package/_types/constants.d.ts +22 -1
  95. package/_types/constants.d.ts.map +1 -1
  96. package/_types/index.d.ts +1 -0
  97. package/_types/index.d.ts.map +1 -1
  98. package/_types/providers/KernelEIP1193Provider.d.ts +3 -2
  99. package/_types/providers/KernelEIP1193Provider.d.ts.map +1 -1
  100. package/_types/types/kernel.d.ts +44 -12
  101. package/_types/types/kernel.d.ts.map +1 -1
  102. package/_types/utils.d.ts +11 -2
  103. package/_types/utils.d.ts.map +1 -1
  104. package/accounts/kernel/abi/kernel_v_3_0_0/KernelAccountAbi.ts +736 -0
  105. package/accounts/kernel/abi/kernel_v_3_0_0/KernelModuleAbi.ts +11 -0
  106. package/accounts/kernel/createKernelAccount.ts +407 -104
  107. package/accounts/kernel/v1/createKernelV1Account.ts +67 -28
  108. package/accounts/utils/6492.ts +27 -1
  109. package/accounts/utils/index.ts +2 -4
  110. package/accounts/utils/toKernelPluginManager.ts +261 -80
  111. package/actions/account-client/signUserOperation.ts +25 -13
  112. package/actions/paymaster/estimateGasInERC20.ts +5 -4
  113. package/actions/paymaster/sponsorUserOperation.ts +104 -32
  114. package/clients/decorators/kernel.ts +44 -35
  115. package/clients/kernelAccountClient.ts +34 -25
  116. package/clients/paymasterClient.ts +10 -6
  117. package/constants.ts +25 -2
  118. package/index.ts +5 -0
  119. package/package.json +93 -92
  120. package/providers/KernelEIP1193Provider.ts +6 -3
  121. package/types/kernel.ts +96 -40
  122. package/utils.ts +52 -4
@@ -1,4 +1,5 @@
1
- import { getAction } from "permissionless"
1
+ import { getAction, getEntryPointVersion } from "permissionless"
2
+ import type { EntryPoint } from "permissionless/types/entrypoint"
2
3
  import {
3
4
  type Address,
4
5
  type Chain,
@@ -7,33 +8,39 @@ import {
7
8
  type Transport,
8
9
  concat,
9
10
  concatHex,
11
+ encodeAbiParameters,
10
12
  hexToBigInt,
11
13
  pad,
14
+ parseAbiParameters,
12
15
  toFunctionSelector,
13
16
  toHex,
14
17
  zeroAddress
15
18
  } from "viem"
16
- import { getChainId, getStorageAt } from "viem/actions"
17
- import { LATEST_KERNEL_VERSION } from "../../constants.js"
19
+ import { getChainId, readContract } from "viem/actions"
20
+ import { VALIDATOR_MODE, VALIDATOR_TYPE } from "../../constants.js"
18
21
  import {
19
22
  type KernelPluginManager,
20
23
  type KernelPluginManagerParams,
21
24
  ValidatorMode
22
25
  } from "../../types/kernel.js"
23
26
  import { getKernelVersion } from "../../utils.js"
27
+ import { KernelV3AccountAbi } from "../kernel/abi/kernel_v_3_0_0/KernelAccountAbi.js"
28
+ import { KernelModuleIsInitializedAbi } from "../kernel/abi/kernel_v_3_0_0/KernelModuleAbi.js"
29
+ import { getKernelImplementationAddress } from "./6492.js"
24
30
 
25
- export function isKernelPluginManager(
31
+ export function isKernelPluginManager<entryPoint extends EntryPoint>(
26
32
  // biome-ignore lint/suspicious/noExplicitAny: <explanation>
27
33
  plugin: any
28
- ): plugin is KernelPluginManager {
34
+ ): plugin is KernelPluginManager<entryPoint> {
29
35
  return plugin.getPluginEnableSignature !== undefined
30
36
  }
31
37
 
32
38
  export async function toKernelPluginManager<
39
+ entryPoint extends EntryPoint,
33
40
  TTransport extends Transport = Transport,
34
41
  TChain extends Chain | undefined = Chain | undefined
35
42
  >(
36
- client: Client<TTransport, TChain>,
43
+ client: Client<TTransport, TChain, undefined>,
37
44
  {
38
45
  sudo,
39
46
  regular,
@@ -46,45 +53,108 @@ export async function toKernelPluginManager<
46
53
  )
47
54
  },
48
55
  validAfter = 0,
49
- validUntil = 0
50
- }: KernelPluginManagerParams
51
- ): Promise<KernelPluginManager> {
56
+ validUntil = 0,
57
+ entryPoint: entryPointAddress
58
+ }: KernelPluginManagerParams<entryPoint>
59
+ ): Promise<KernelPluginManager<entryPoint>> {
60
+ const entryPointVersion = getEntryPointVersion(entryPointAddress)
52
61
  const chainId = await getChainId(client)
62
+ const activeValidator = regular || sudo
63
+ if (!activeValidator) {
64
+ throw new Error("One of `sudo` or `regular` validator must be set")
65
+ }
53
66
  const getValidatorSignature = async (
54
67
  accountAddress: Address,
55
- selector: Hex
68
+ selector: Hex,
69
+ sig?: Hex
56
70
  ): Promise<Hex> => {
71
+ if (entryPointVersion === "v0.6") {
72
+ if (regular) {
73
+ if (await regular.isEnabled(accountAddress, selector)) {
74
+ return ValidatorMode.plugin
75
+ }
76
+
77
+ const enableSignature =
78
+ await getPluginEnableSignature(accountAddress)
79
+ const enableData = await regular.getEnableData(accountAddress)
80
+ const enableDataLength = enableData.length / 2 - 1
81
+ if (!enableSignature) {
82
+ throw new Error("Enable signature not set")
83
+ }
84
+
85
+ return concat([
86
+ ValidatorMode.enable,
87
+ pad(toHex(validUntil), { size: 6 }), // 6 bytes 4 - 10
88
+ pad(toHex(validAfter), { size: 6 }), // 6 bytes 10 - 16
89
+ pad(regular.address, { size: 20 }), // 20 bytes 16 - 36
90
+ pad(executorData.executor, { size: 20 }), // 20 bytes 36 - 56
91
+ pad(toHex(enableDataLength), { size: 32 }), // 32 bytes 56 - 88
92
+ enableData, // 88 - 88 + enableData.length
93
+ pad(toHex(enableSignature.length / 2 - 1), { size: 32 }), // 32 bytes 88 + enableData.length - 120 + enableData.length
94
+ enableSignature // 120 + enableData.length - 120 + enableData.length + enableSignature.length
95
+ ])
96
+ } else if (sudo) {
97
+ return ValidatorMode.sudo
98
+ } else {
99
+ throw new Error(
100
+ "One of `sudo` or `regular` validator must be set"
101
+ )
102
+ }
103
+ }
57
104
  if (regular) {
58
- if (await regular.isEnabled(accountAddress, selector)) {
59
- return ValidatorMode.plugin
105
+ if (
106
+ (await isPluginInitialized_7579(accountAddress)) ||
107
+ (await regular.isEnabled(accountAddress, selector))
108
+ ) {
109
+ return sig ?? "0x"
60
110
  }
61
-
111
+ const enableData = await regular.getEnableData(accountAddress)
62
112
  const enableSignature =
63
113
  await getPluginEnableSignature(accountAddress)
64
- const enableData = await regular.getEnableData(accountAddress)
65
- const enableDataLength = enableData.length / 2 - 1
66
- if (!enableSignature) {
67
- throw new Error("Enable signature not set")
68
- }
69
-
70
114
  return concat([
71
- ValidatorMode.enable,
72
- pad(toHex(validUntil), { size: 6 }), // 6 bytes 4 - 10
73
- pad(toHex(validAfter), { size: 6 }), // 6 bytes 10 - 16
74
- pad(regular.address, { size: 20 }), // 20 bytes 16 - 36
75
- pad(executorData.executor, { size: 20 }), // 20 bytes 36 - 56
76
- pad(toHex(enableDataLength), { size: 32 }), // 32 bytes 56 - 88
77
- enableData, // 88 - 88 + enableData.length
78
- pad(toHex(enableSignature.length / 2 - 1), { size: 32 }), // 32 bytes 88 + enableData.length - 120 + enableData.length
79
- enableSignature // 120 + enableData.length - 120 + enableData.length + enableSignature.length
115
+ zeroAddress, // hook address 20 bytes
116
+ encodeAbiParameters(
117
+ parseAbiParameters(
118
+ "bytes validatorData, bytes hookData, bytes selectorData, bytes enableSig, bytes userOpSig"
119
+ ),
120
+ [
121
+ enableData,
122
+ "0x",
123
+ concat([
124
+ executorData.selector,
125
+ executorData.executor,
126
+ zeroAddress,
127
+ "0x"
128
+ ]),
129
+ enableSignature,
130
+ sig ?? "0x"
131
+ ]
132
+ )
80
133
  ])
81
134
  } else if (sudo) {
82
- return ValidatorMode.sudo
135
+ return sig ?? "0x"
83
136
  } else {
84
137
  throw new Error("One of `sudo` or `regular` validator must be set")
85
138
  }
86
139
  }
87
140
 
141
+ const isPluginInitialized_7579 = async (
142
+ accountAddress: Address
143
+ ): Promise<boolean> => {
144
+ try {
145
+ return await getAction(
146
+ client,
147
+ readContract
148
+ )({
149
+ abi: KernelModuleIsInitializedAbi,
150
+ address: activeValidator.address,
151
+ functionName: "isInitialized",
152
+ args: [accountAddress]
153
+ })
154
+ } catch (error) {}
155
+ return false
156
+ }
157
+
88
158
  const getPluginEnableSignature = async (accountAddress: Address) => {
89
159
  if (pluginEnableSignature) return pluginEnableSignature
90
160
  if (!sudo)
@@ -92,72 +162,139 @@ export async function toKernelPluginManager<
92
162
  "sudo validator not set -- need it to enable the validator"
93
163
  )
94
164
  if (!regular) throw new Error("regular validator not set")
95
- let kernelImplAddr: Address | undefined
96
- try {
97
- const strgAddr = await getAction(
98
- client,
99
- getStorageAt
100
- )({
101
- address: accountAddress,
102
- slot: "0x360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc"
165
+
166
+ const kernelImplAddr = await getKernelImplementationAddress(
167
+ client,
168
+ accountAddress
169
+ )
170
+ const kernelVersion = getKernelVersion(
171
+ entryPointAddress,
172
+ kernelImplAddr
173
+ )
174
+ let ownerSig: Hex
175
+ if (entryPointVersion === "v0.6") {
176
+ ownerSig = await sudo.signTypedData({
177
+ domain: {
178
+ name: "Kernel",
179
+ version: kernelVersion,
180
+ chainId,
181
+ verifyingContract: accountAddress
182
+ },
183
+ types: {
184
+ ValidatorApproved: [
185
+ { name: "sig", type: "bytes4" },
186
+ { name: "validatorData", type: "uint256" },
187
+ { name: "executor", type: "address" },
188
+ { name: "enableData", type: "bytes" }
189
+ ]
190
+ },
191
+ message: {
192
+ sig: executorData.selector,
193
+ validatorData: hexToBigInt(
194
+ concatHex([
195
+ pad(toHex(validUntil ?? 0), {
196
+ size: 6
197
+ }),
198
+ pad(toHex(validAfter ?? 0), {
199
+ size: 6
200
+ }),
201
+ regular.address
202
+ ]),
203
+ { size: 32 }
204
+ ),
205
+ executor: executorData.executor as Address,
206
+ enableData: await regular.getEnableData(accountAddress)
207
+ },
208
+ primaryType: "ValidatorApproved"
103
209
  })
104
- if (strgAddr) kernelImplAddr = `0x${strgAddr.slice(26)}` as Hex
105
- } catch (error) {}
106
- const ownerSig = await sudo.signTypedData({
210
+ pluginEnableSignature = ownerSig
211
+ return ownerSig
212
+ }
213
+ ownerSig = await sudo.signTypedData({
107
214
  domain: {
108
215
  name: "Kernel",
109
- version: kernelImplAddr
110
- ? getKernelVersion(kernelImplAddr)
111
- : LATEST_KERNEL_VERSION,
216
+ version: kernelVersion,
112
217
  chainId,
113
218
  verifyingContract: accountAddress
114
219
  },
115
220
  types: {
116
- ValidatorApproved: [
117
- { name: "sig", type: "bytes4" },
118
- { name: "validatorData", type: "uint256" },
119
- { name: "executor", type: "address" },
120
- { name: "enableData", type: "bytes" }
221
+ Enable: [
222
+ { name: "validationId", type: "bytes21" },
223
+ { name: "nonce", type: "uint32" },
224
+ { name: "hook", type: "address" },
225
+ { name: "validatorData", type: "bytes" },
226
+ { name: "hookData", type: "bytes" },
227
+ { name: "selectorData", type: "bytes" }
121
228
  ]
122
229
  },
123
230
  message: {
124
- sig: executorData.selector,
125
- validatorData: hexToBigInt(
126
- concatHex([
127
- pad(toHex(validUntil ?? 0), {
128
- size: 6
129
- }),
130
- pad(toHex(validAfter ?? 0), {
131
- size: 6
132
- }),
133
- regular.address
134
- ]),
135
- { size: 32 }
136
- ),
137
- executor: executorData.executor as Address,
138
- enableData: await regular.getEnableData(accountAddress)
231
+ validationId: concat([
232
+ activeValidator.isPermissionValidator
233
+ ? VALIDATOR_TYPE.PERMISSION
234
+ : VALIDATOR_TYPE.SECONDARY,
235
+ activeValidator?.isPermissionValidator
236
+ ? // @ts-ignore
237
+ pad(regular.getPermissionId() as Hex, {
238
+ size: 20,
239
+ dir: "right"
240
+ })
241
+ : activeValidator.address
242
+ ]),
243
+ nonce: await getKernelV3Nonce(accountAddress),
244
+ hook: zeroAddress,
245
+ validatorData: await regular.getEnableData(accountAddress),
246
+ hookData: "0x",
247
+ selectorData: concat([
248
+ executorData.selector,
249
+ executorData.executor,
250
+ zeroAddress,
251
+ "0x"
252
+ ])
139
253
  },
140
- primaryType: "ValidatorApproved"
254
+ primaryType: "Enable"
141
255
  })
142
- pluginEnableSignature = ownerSig
256
+
143
257
  return ownerSig
144
258
  }
145
259
 
146
- const activeValidator = regular || sudo
147
- if (!activeValidator) {
148
- throw new Error("One of `sudo` or `regular` validator must be set")
260
+ const getKernelV3Nonce = async (
261
+ accountAddress: Address
262
+ ): Promise<number> => {
263
+ try {
264
+ const nonce = await getAction(
265
+ client,
266
+ readContract
267
+ )({
268
+ abi: KernelV3AccountAbi,
269
+ address: accountAddress,
270
+ functionName: "currentNonce",
271
+ args: []
272
+ })
273
+ return nonce
274
+ } catch (error) {
275
+ return 2
276
+ }
149
277
  }
150
278
 
151
279
  return {
152
280
  ...activeValidator,
153
281
  signUserOperation: async (userOperation) => {
154
- return concatHex([
155
- await getValidatorSignature(
156
- userOperation.sender,
157
- userOperation.callData.toString().slice(0, 10) as Hex
158
- ),
282
+ const userOpSig =
159
283
  await activeValidator.signUserOperation(userOperation)
160
- ])
284
+ if (entryPointVersion === "v0.6") {
285
+ return concatHex([
286
+ await getValidatorSignature(
287
+ userOperation.sender,
288
+ userOperation.callData.toString().slice(0, 10) as Hex
289
+ ),
290
+ userOpSig
291
+ ])
292
+ }
293
+ return await getValidatorSignature(
294
+ userOperation.sender,
295
+ userOperation.callData.toString().slice(0, 10) as Hex,
296
+ userOpSig
297
+ )
161
298
  },
162
299
  getExecutorData: () => executorData,
163
300
  getValidityData: () => ({
@@ -165,13 +302,57 @@ export async function toKernelPluginManager<
165
302
  validUntil
166
303
  }),
167
304
  getDummySignature: async (userOperation) => {
168
- return concatHex([
169
- await getValidatorSignature(
170
- userOperation.sender,
171
- userOperation.callData.toString().slice(0, 10) as Hex
172
- ),
305
+ const userOpSig =
173
306
  await activeValidator.getDummySignature(userOperation)
174
- ])
307
+ if (entryPointVersion === "v0.6") {
308
+ return concatHex([
309
+ await getValidatorSignature(
310
+ userOperation.sender,
311
+ userOperation.callData.toString().slice(0, 10) as Hex
312
+ ),
313
+ userOpSig
314
+ ])
315
+ }
316
+ return await getValidatorSignature(
317
+ userOperation.sender,
318
+ userOperation.callData.toString().slice(0, 10) as Hex,
319
+ userOpSig
320
+ )
321
+ },
322
+ getNonceKey: async (accountAddress = zeroAddress) => {
323
+ if (entryPointVersion === "v0.6")
324
+ return await activeValidator.getNonceKey()
325
+
326
+ return BigInt(
327
+ pad(
328
+ concatHex([
329
+ !regular ||
330
+ (await regular.isEnabled(
331
+ accountAddress,
332
+ executorData.selector
333
+ )) ||
334
+ (await isPluginInitialized_7579(accountAddress))
335
+ ? VALIDATOR_MODE.DEFAULT
336
+ : VALIDATOR_MODE.ENABLE, // 1 byte
337
+ regular
338
+ ? regular.isPermissionValidator
339
+ ? VALIDATOR_TYPE.PERMISSION
340
+ : VALIDATOR_TYPE.SECONDARY
341
+ : VALIDATOR_TYPE.SUDO, // 1 byte
342
+ regular?.isPermissionValidator
343
+ ? // @ts-ignore
344
+ pad(regular.getPermissionId(), {
345
+ size: 20,
346
+ dir: "right"
347
+ })
348
+ : activeValidator.address, // 20 bytes
349
+ pad(toHex(await activeValidator.getNonceKey()), {
350
+ size: 2
351
+ }) // 10 byte
352
+ ]),
353
+ { size: 24 }
354
+ )
355
+ )
175
356
  },
176
357
  getPluginEnableSignature,
177
358
  getValidatorInitData: async () => {
@@ -1,8 +1,12 @@
1
1
  import type { SmartAccount } from "permissionless/accounts/types"
2
- import type { SponsorUserOperationMiddleware } from "permissionless/actions/smartAccount"
3
- import { prepareUserOperationRequest } from "permissionless/actions/smartAccount"
2
+ import {
3
+ type Middleware,
4
+ prepareUserOperationRequest
5
+ } from "permissionless/actions/smartAccount"
4
6
  import type {
7
+ EntryPoint,
5
8
  GetAccountParameter,
9
+ GetEntryPointVersion,
6
10
  PartialBy,
7
11
  Prettify,
8
12
  UserOperation
@@ -15,10 +19,13 @@ import {
15
19
  import type { Chain, Client, Transport } from "viem"
16
20
 
17
21
  export type SignUserOperationParameters<
18
- TAccount extends SmartAccount | undefined = SmartAccount | undefined
22
+ entryPoint extends EntryPoint,
23
+ TAccount extends SmartAccount<entryPoint> | undefined =
24
+ | SmartAccount<entryPoint>
25
+ | undefined
19
26
  > = {
20
27
  userOperation: PartialBy<
21
- UserOperation,
28
+ UserOperation<"v0.6">,
22
29
  | "nonce"
23
30
  | "sender"
24
31
  | "initCode"
@@ -30,30 +37,35 @@ export type SignUserOperationParameters<
30
37
  | "verificationGasLimit"
31
38
  | "paymasterAndData"
32
39
  >
33
- } & GetAccountParameter<TAccount> &
34
- SponsorUserOperationMiddleware
40
+ } & GetAccountParameter<entryPoint, TAccount> &
41
+ Middleware<entryPoint>
35
42
 
36
- export type SignUserOperationReturnType = UserOperation
43
+ export type SignUserOperationReturnType = UserOperation<"v0.6">
37
44
 
38
45
  export async function signUserOperation<
46
+ entryPoint extends EntryPoint,
39
47
  TTransport extends Transport = Transport,
40
48
  TChain extends Chain | undefined = Chain | undefined,
41
- TAccount extends SmartAccount | undefined = SmartAccount | undefined
49
+ TAccount extends SmartAccount<entryPoint> | undefined =
50
+ | SmartAccount<entryPoint>
51
+ | undefined
42
52
  >(
43
53
  client: Client<TTransport, TChain, TAccount>,
44
- args: Prettify<SignUserOperationParameters<TAccount>>
54
+ args: Prettify<SignUserOperationParameters<entryPoint, TAccount>>
45
55
  ): Promise<SignUserOperationReturnType> {
46
56
  const { account: account_ = client.account } = args
47
57
  if (!account_) throw new AccountOrClientNotFoundError()
48
58
 
49
- const account = parseAccount(account_) as SmartAccount
59
+ const account = parseAccount(account_) as SmartAccount<entryPoint>
50
60
 
51
61
  const userOperation = await getAction(
52
62
  client,
53
- prepareUserOperationRequest
63
+ prepareUserOperationRequest<entryPoint, TTransport, TChain, TAccount>
54
64
  )(args)
55
65
 
56
- userOperation.signature = await account.signUserOperation(userOperation)
66
+ userOperation.signature = await account.signUserOperation(
67
+ userOperation as UserOperation<GetEntryPointVersion<entryPoint>>
68
+ )
57
69
 
58
- return userOperation
70
+ return userOperation as SignUserOperationReturnType
59
71
  }
@@ -1,3 +1,4 @@
1
+ import type { EntryPoint } from "permissionless/types"
1
2
  import type {
2
3
  UserOperation,
3
4
  UserOperationWithBigIntAsHex
@@ -8,7 +9,7 @@ import { KERNEL_ADDRESSES } from "../../accounts/index.js"
8
9
  import type { ZeroDevPaymasterClient } from "../../clients/paymasterClient.js"
9
10
 
10
11
  export type EstimateGasInERC20Parameters = {
11
- userOperation: UserOperation
12
+ userOperation: UserOperation<"v0.6">
12
13
  gasTokenAddress: Hex
13
14
  entryPoint?: Address
14
15
  }
@@ -26,8 +27,8 @@ export type EstimateGasInERC20ReturnType = {
26
27
  * Returns paymasterAndData & updated gas parameters required to sponsor a userOperation.
27
28
  */
28
29
 
29
- export const estimateGasInERC20 = async (
30
- client: ZeroDevPaymasterClient,
30
+ export const estimateGasInERC20 = async <entryPoint extends EntryPoint>(
31
+ client: ZeroDevPaymasterClient<entryPoint>,
31
32
  args: EstimateGasInERC20Parameters
32
33
  ): Promise<EstimateGasInERC20ReturnType> => {
33
34
  const response = await client.request({
@@ -37,7 +38,7 @@ export const estimateGasInERC20 = async (
37
38
  chainId: client.chain?.id as number,
38
39
  userOp: deepHexlify(
39
40
  args.userOperation
40
- ) as UserOperationWithBigIntAsHex,
41
+ ) as UserOperationWithBigIntAsHex<"v0.6">,
41
42
  tokenAddress: args.gasTokenAddress,
42
43
  entryPointAddress:
43
44
  args.entryPoint ?? KERNEL_ADDRESSES.ENTRYPOINT_V0_6