@zerodev/sdk 5.1.13 → 5.2.0-alpha-1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/_cjs/accounts/kernel/abi/kernel_v_3_0_0/KernelAccountAbi.js +738 -0
- package/_cjs/accounts/kernel/abi/kernel_v_3_0_0/KernelAccountAbi.js.map +1 -0
- package/_cjs/accounts/kernel/abi/kernel_v_3_0_0/KernelModuleAbi.js +15 -0
- package/_cjs/accounts/kernel/abi/kernel_v_3_0_0/KernelModuleAbi.js.map +1 -0
- package/_cjs/accounts/kernel/createKernelAccount.js +235 -75
- package/_cjs/accounts/kernel/createKernelAccount.js.map +1 -1
- package/_cjs/accounts/kernel/v1/createKernelV1Account.js +29 -18
- package/_cjs/accounts/kernel/v1/createKernelV1Account.js.map +1 -1
- package/_cjs/accounts/utils/6492.js +19 -3
- package/_cjs/accounts/utils/6492.js.map +1 -1
- package/_cjs/accounts/utils/index.js +4 -3
- package/_cjs/accounts/utils/index.js.map +1 -1
- package/_cjs/accounts/utils/toKernelPluginManager.js +194 -62
- package/_cjs/accounts/utils/toKernelPluginManager.js.map +1 -1
- package/_cjs/actions/account-client/signUserOperation.js +1 -1
- package/_cjs/actions/account-client/signUserOperation.js.map +1 -1
- package/_cjs/actions/paymaster/estimateGasInERC20.js.map +1 -1
- package/_cjs/actions/paymaster/sponsorUserOperation.js +17 -14
- package/_cjs/actions/paymaster/sponsorUserOperation.js.map +1 -1
- package/_cjs/clients/decorators/kernel.js +8 -5
- package/_cjs/clients/decorators/kernel.js.map +1 -1
- package/_cjs/clients/kernelAccountClient.js +3 -3
- package/_cjs/clients/kernelAccountClient.js.map +1 -1
- package/_cjs/clients/paymasterClient.js +1 -1
- package/_cjs/clients/paymasterClient.js.map +1 -1
- package/_cjs/constants.js +28 -3
- package/_cjs/constants.js.map +1 -1
- package/_cjs/index.js +5 -1
- package/_cjs/index.js.map +1 -1
- package/_cjs/providers/KernelEIP1193Provider.js.map +1 -1
- package/_cjs/types/kernel.js.map +1 -1
- package/_cjs/utils.js +34 -3
- package/_cjs/utils.js.map +1 -1
- package/_esm/accounts/kernel/abi/kernel_v_3_0_0/KernelAccountAbi.js +735 -0
- package/_esm/accounts/kernel/abi/kernel_v_3_0_0/KernelAccountAbi.js.map +1 -0
- package/_esm/accounts/kernel/abi/kernel_v_3_0_0/KernelModuleAbi.js +12 -0
- package/_esm/accounts/kernel/abi/kernel_v_3_0_0/KernelModuleAbi.js.map +1 -0
- package/_esm/accounts/kernel/createKernelAccount.js +244 -81
- package/_esm/accounts/kernel/createKernelAccount.js.map +1 -1
- package/_esm/accounts/kernel/v1/createKernelV1Account.js +37 -20
- package/_esm/accounts/kernel/v1/createKernelV1Account.js.map +1 -1
- package/_esm/accounts/utils/6492.js +16 -1
- package/_esm/accounts/utils/6492.js.map +1 -1
- package/_esm/accounts/utils/index.js +2 -4
- package/_esm/accounts/utils/index.js.map +1 -1
- package/_esm/accounts/utils/toKernelPluginManager.js +198 -66
- package/_esm/accounts/utils/toKernelPluginManager.js.map +1 -1
- package/_esm/actions/account-client/signUserOperation.js +1 -1
- package/_esm/actions/account-client/signUserOperation.js.map +1 -1
- package/_esm/actions/paymaster/estimateGasInERC20.js.map +1 -1
- package/_esm/actions/paymaster/sponsorUserOperation.js +37 -15
- package/_esm/actions/paymaster/sponsorUserOperation.js.map +1 -1
- package/_esm/clients/decorators/kernel.js +9 -5
- package/_esm/clients/decorators/kernel.js.map +1 -1
- package/_esm/clients/kernelAccountClient.js +3 -3
- package/_esm/clients/kernelAccountClient.js.map +1 -1
- package/_esm/clients/paymasterClient.js +1 -1
- package/_esm/clients/paymasterClient.js.map +1 -1
- package/_esm/constants.js +27 -2
- package/_esm/constants.js.map +1 -1
- package/_esm/index.js +1 -0
- package/_esm/index.js.map +1 -1
- package/_esm/providers/KernelEIP1193Provider.js.map +1 -1
- package/_esm/types/kernel.js +1 -0
- package/_esm/types/kernel.js.map +1 -1
- package/_esm/utils.js +33 -4
- package/_esm/utils.js.map +1 -1
- package/_types/accounts/kernel/abi/kernel_v_3_0_0/KernelAccountAbi.d.ts +843 -0
- package/_types/accounts/kernel/abi/kernel_v_3_0_0/KernelAccountAbi.d.ts.map +1 -0
- package/_types/accounts/kernel/abi/kernel_v_3_0_0/KernelModuleAbi.d.ts +16 -0
- package/_types/accounts/kernel/abi/kernel_v_3_0_0/KernelModuleAbi.d.ts.map +1 -0
- package/_types/accounts/kernel/createKernelAccount.d.ts +14 -11
- package/_types/accounts/kernel/createKernelAccount.d.ts.map +1 -1
- package/_types/accounts/kernel/v1/createKernelV1Account.d.ts +5 -4
- package/_types/accounts/kernel/v1/createKernelV1Account.d.ts.map +1 -1
- package/_types/accounts/utils/6492.d.ts +3 -1
- package/_types/accounts/utils/6492.d.ts.map +1 -1
- package/_types/accounts/utils/index.d.ts +2 -4
- package/_types/accounts/utils/index.d.ts.map +1 -1
- package/_types/accounts/utils/toKernelPluginManager.d.ts +3 -2
- package/_types/accounts/utils/toKernelPluginManager.d.ts.map +1 -1
- package/_types/actions/account-client/signUserOperation.d.ts +7 -7
- package/_types/actions/account-client/signUserOperation.d.ts.map +1 -1
- package/_types/actions/paymaster/estimateGasInERC20.d.ts +3 -2
- package/_types/actions/paymaster/estimateGasInERC20.d.ts.map +1 -1
- package/_types/actions/paymaster/sponsorUserOperation.d.ts +7 -6
- package/_types/actions/paymaster/sponsorUserOperation.d.ts.map +1 -1
- package/_types/clients/decorators/kernel.d.ts +8 -7
- package/_types/clients/decorators/kernel.d.ts.map +1 -1
- package/_types/clients/kernelAccountClient.d.ts +101 -22
- package/_types/clients/kernelAccountClient.d.ts.map +1 -1
- package/_types/clients/paymasterClient.d.ts +6 -3
- package/_types/clients/paymasterClient.d.ts.map +1 -1
- package/_types/constants.d.ts +22 -1
- package/_types/constants.d.ts.map +1 -1
- package/_types/index.d.ts +1 -0
- package/_types/index.d.ts.map +1 -1
- package/_types/providers/KernelEIP1193Provider.d.ts +3 -2
- package/_types/providers/KernelEIP1193Provider.d.ts.map +1 -1
- package/_types/types/kernel.d.ts +44 -12
- package/_types/types/kernel.d.ts.map +1 -1
- package/_types/utils.d.ts +11 -2
- package/_types/utils.d.ts.map +1 -1
- package/accounts/kernel/abi/kernel_v_3_0_0/KernelAccountAbi.ts +736 -0
- package/accounts/kernel/abi/kernel_v_3_0_0/KernelModuleAbi.ts +11 -0
- package/accounts/kernel/createKernelAccount.ts +399 -105
- package/accounts/kernel/v1/createKernelV1Account.ts +67 -28
- package/accounts/utils/6492.ts +27 -1
- package/accounts/utils/index.ts +2 -4
- package/accounts/utils/toKernelPluginManager.ts +261 -80
- package/actions/account-client/signUserOperation.ts +25 -13
- package/actions/paymaster/estimateGasInERC20.ts +5 -4
- package/actions/paymaster/sponsorUserOperation.ts +104 -32
- package/clients/decorators/kernel.ts +44 -35
- package/clients/kernelAccountClient.ts +34 -25
- package/clients/paymasterClient.ts +10 -6
- package/constants.ts +25 -2
- package/index.ts +5 -0
- package/package.json +93 -92
- package/providers/KernelEIP1193Provider.ts +6 -3
- package/types/kernel.ts +96 -40
- package/utils.ts +52 -4
- package/README.md +0 -3
|
@@ -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,
|
|
17
|
-
import {
|
|
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
|
-
|
|
51
|
-
|
|
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 (
|
|
59
|
-
|
|
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
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
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
|
|
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
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
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
|
-
|
|
105
|
-
|
|
106
|
-
|
|
210
|
+
pluginEnableSignature = ownerSig
|
|
211
|
+
return ownerSig
|
|
212
|
+
}
|
|
213
|
+
ownerSig = await sudo.signTypedData({
|
|
107
214
|
domain: {
|
|
108
215
|
name: "Kernel",
|
|
109
|
-
version:
|
|
110
|
-
? getKernelVersion(kernelImplAddr)
|
|
111
|
-
: LATEST_KERNEL_VERSION,
|
|
216
|
+
version: kernelVersion,
|
|
112
217
|
chainId,
|
|
113
218
|
verifyingContract: accountAddress
|
|
114
219
|
},
|
|
115
220
|
types: {
|
|
116
|
-
|
|
117
|
-
{ name: "
|
|
118
|
-
{ name: "
|
|
119
|
-
{ name: "
|
|
120
|
-
{ name: "
|
|
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
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
),
|
|
137
|
-
|
|
138
|
-
|
|
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: "
|
|
254
|
+
primaryType: "Enable"
|
|
141
255
|
})
|
|
142
|
-
|
|
256
|
+
|
|
143
257
|
return ownerSig
|
|
144
258
|
}
|
|
145
259
|
|
|
146
|
-
const
|
|
147
|
-
|
|
148
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
|
3
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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 =
|
|
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(
|
|
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
|