permissionless 0.1.19 → 0.1.21
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/CHANGELOG.md +12 -0
- package/_cjs/accounts/kernel/abi/KernelV3AccountAbi.js +91 -0
- package/_cjs/accounts/kernel/abi/KernelV3AccountAbi.js.map +1 -0
- package/_cjs/accounts/kernel/abi/KernelV3MetaFactoryAbi.js +21 -0
- package/_cjs/accounts/kernel/abi/KernelV3MetaFactoryAbi.js.map +1 -0
- package/_cjs/accounts/kernel/constants.js +27 -0
- package/_cjs/accounts/kernel/constants.js.map +1 -0
- package/_cjs/accounts/kernel/signerToEcdsaKernelSmartAccount.js +138 -45
- package/_cjs/accounts/kernel/signerToEcdsaKernelSmartAccount.js.map +1 -1
- package/_cjs/accounts/kernel/utils/encodeCallData.js +89 -0
- package/_cjs/accounts/kernel/utils/encodeCallData.js.map +1 -0
- package/_cjs/accounts/kernel/utils/getExecMode.js +15 -0
- package/_cjs/accounts/kernel/utils/getExecMode.js.map +1 -0
- package/_cjs/accounts/kernel/utils/getNonceKey.js +24 -0
- package/_cjs/accounts/kernel/utils/getNonceKey.js.map +1 -0
- package/_cjs/accounts/kernel/utils/signMessage.js +28 -0
- package/_cjs/accounts/kernel/utils/signMessage.js.map +1 -0
- package/_cjs/accounts/kernel/utils/signTypedData.js +40 -0
- package/_cjs/accounts/kernel/utils/signTypedData.js.map +1 -0
- package/_cjs/accounts/kernel/utils/wrapMessageHash.js +20 -0
- package/_cjs/accounts/kernel/utils/wrapMessageHash.js.map +1 -0
- package/_esm/accounts/kernel/abi/KernelV3AccountAbi.js +88 -0
- package/_esm/accounts/kernel/abi/KernelV3AccountAbi.js.map +1 -0
- package/_esm/accounts/kernel/abi/KernelV3MetaFactoryAbi.js +18 -0
- package/_esm/accounts/kernel/abi/KernelV3MetaFactoryAbi.js.map +1 -0
- package/_esm/accounts/kernel/constants.js +24 -0
- package/_esm/accounts/kernel/constants.js.map +1 -0
- package/_esm/accounts/kernel/signerToEcdsaKernelSmartAccount.js +165 -52
- package/_esm/accounts/kernel/signerToEcdsaKernelSmartAccount.js.map +1 -1
- package/_esm/accounts/kernel/utils/encodeCallData.js +89 -0
- package/_esm/accounts/kernel/utils/encodeCallData.js.map +1 -0
- package/_esm/accounts/kernel/utils/getExecMode.js +12 -0
- package/_esm/accounts/kernel/utils/getExecMode.js.map +1 -0
- package/_esm/accounts/kernel/utils/getNonceKey.js +21 -0
- package/_esm/accounts/kernel/utils/getNonceKey.js.map +1 -0
- package/_esm/accounts/kernel/utils/signMessage.js +24 -0
- package/_esm/accounts/kernel/utils/signMessage.js.map +1 -0
- package/_esm/accounts/kernel/utils/signTypedData.js +38 -0
- package/_esm/accounts/kernel/utils/signTypedData.js.map +1 -0
- package/_esm/accounts/kernel/utils/wrapMessageHash.js +16 -0
- package/_esm/accounts/kernel/utils/wrapMessageHash.js.map +1 -0
- package/_types/accounts/kernel/abi/KernelV3AccountAbi.d.ts +108 -0
- package/_types/accounts/kernel/abi/KernelV3AccountAbi.d.ts.map +1 -0
- package/_types/accounts/kernel/abi/KernelV3MetaFactoryAbi.d.ts +24 -0
- package/_types/accounts/kernel/abi/KernelV3MetaFactoryAbi.d.ts.map +1 -0
- package/_types/accounts/kernel/constants.d.ts +21 -0
- package/_types/accounts/kernel/constants.d.ts.map +1 -0
- package/_types/accounts/kernel/signerToEcdsaKernelSmartAccount.d.ts +18 -5
- package/_types/accounts/kernel/signerToEcdsaKernelSmartAccount.d.ts.map +1 -1
- package/_types/accounts/kernel/utils/encodeCallData.d.ts +12 -0
- package/_types/accounts/kernel/utils/encodeCallData.d.ts.map +1 -0
- package/_types/accounts/kernel/utils/getExecMode.d.ts +7 -0
- package/_types/accounts/kernel/utils/getExecMode.d.ts.map +1 -0
- package/_types/accounts/kernel/utils/getNonceKey.d.ts +4 -0
- package/_types/accounts/kernel/utils/getNonceKey.d.ts.map +1 -0
- package/_types/accounts/kernel/utils/signMessage.d.ts +4 -0
- package/_types/accounts/kernel/utils/signMessage.d.ts.map +1 -0
- package/_types/accounts/kernel/utils/signTypedData.d.ts +4 -0
- package/_types/accounts/kernel/utils/signTypedData.d.ts.map +1 -0
- package/_types/accounts/kernel/utils/wrapMessageHash.d.ts +9 -0
- package/_types/accounts/kernel/utils/wrapMessageHash.d.ts.map +1 -0
- package/accounts/kernel/abi/KernelV3AccountAbi.ts +88 -0
- package/accounts/kernel/abi/KernelV3MetaFactoryAbi.ts +17 -0
- package/accounts/kernel/constants.ts +21 -0
- package/accounts/kernel/signerToEcdsaKernelSmartAccount.ts +252 -71
- package/accounts/kernel/utils/encodeCallData.ts +114 -0
- package/accounts/kernel/utils/getExecMode.ts +18 -0
- package/accounts/kernel/utils/getNonceKey.ts +32 -0
- package/accounts/kernel/utils/signMessage.ts +48 -0
- package/accounts/kernel/utils/signTypedData.ts +74 -0
- package/accounts/kernel/utils/wrapMessageHash.ts +38 -0
- package/package.json +1 -1
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
export const KernelV3MetaFactoryDeployWithFactoryAbi = [
|
|
2
|
+
{
|
|
3
|
+
type: "function",
|
|
4
|
+
name: "deployWithFactory",
|
|
5
|
+
inputs: [
|
|
6
|
+
{
|
|
7
|
+
name: "factory",
|
|
8
|
+
type: "address",
|
|
9
|
+
internalType: "contract KernelFactory"
|
|
10
|
+
},
|
|
11
|
+
{ name: "createData", type: "bytes", internalType: "bytes" },
|
|
12
|
+
{ name: "salt", type: "bytes32", internalType: "bytes32" }
|
|
13
|
+
],
|
|
14
|
+
outputs: [{ name: "", type: "address", internalType: "address" }],
|
|
15
|
+
stateMutability: "payable"
|
|
16
|
+
}
|
|
17
|
+
] as const
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
export const DUMMY_ECDSA_SIGNATURE =
|
|
2
|
+
"0xfffffffffffffffffffffffffffffff0000000000000000000000000000000007aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa1c"
|
|
3
|
+
export const ROOT_MODE_KERNEL_V2 = "0x00000000"
|
|
4
|
+
export enum CALL_TYPE {
|
|
5
|
+
SINGLE = "0x00",
|
|
6
|
+
BATCH = "0x01",
|
|
7
|
+
DELEGATE_CALL = "0xFF"
|
|
8
|
+
}
|
|
9
|
+
export enum EXEC_TYPE {
|
|
10
|
+
DEFAULT = "0x00",
|
|
11
|
+
TRY_EXEC = "0x01"
|
|
12
|
+
}
|
|
13
|
+
export const VALIDATOR_TYPE = {
|
|
14
|
+
ROOT: "0x00",
|
|
15
|
+
VALIDATOR: "0x01",
|
|
16
|
+
PERMISSION: "0x02"
|
|
17
|
+
} as const
|
|
18
|
+
export enum VALIDATOR_MODE {
|
|
19
|
+
DEFAULT = "0x00",
|
|
20
|
+
ENABLE = "0x01"
|
|
21
|
+
}
|
|
@@ -9,19 +9,24 @@ import {
|
|
|
9
9
|
type TypedDataDefinition,
|
|
10
10
|
concatHex,
|
|
11
11
|
encodeFunctionData,
|
|
12
|
-
isAddressEqual
|
|
12
|
+
isAddressEqual,
|
|
13
|
+
toHex,
|
|
14
|
+
zeroAddress
|
|
13
15
|
} from "viem"
|
|
14
16
|
import {
|
|
15
17
|
getChainId,
|
|
16
18
|
readContract,
|
|
17
|
-
signMessage
|
|
18
|
-
signTypedData
|
|
19
|
+
signMessage as _signMessage
|
|
19
20
|
} from "viem/actions"
|
|
20
21
|
import { getAccountNonce } from "../../actions/public/getAccountNonce"
|
|
21
22
|
import { getSenderAddress } from "../../actions/public/getSenderAddress"
|
|
22
|
-
import type {
|
|
23
|
+
import type {
|
|
24
|
+
ENTRYPOINT_ADDRESS_V07_TYPE,
|
|
25
|
+
EntryPoint,
|
|
26
|
+
Prettify
|
|
27
|
+
} from "../../types"
|
|
23
28
|
import type { ENTRYPOINT_ADDRESS_V06_TYPE } from "../../types/entrypoint"
|
|
24
|
-
import { getEntryPointVersion } from "../../utils"
|
|
29
|
+
import { ENTRYPOINT_ADDRESS_V06, getEntryPointVersion } from "../../utils"
|
|
25
30
|
import { getUserOperationHash } from "../../utils/getUserOperationHash"
|
|
26
31
|
import { isSmartAccountDeployed } from "../../utils/isSmartAccountDeployed"
|
|
27
32
|
import { toSmartAccount } from "../toSmartAccount"
|
|
@@ -30,10 +35,21 @@ import {
|
|
|
30
35
|
SignTransactionNotSupportedBySmartAccount,
|
|
31
36
|
type SmartAccountSigner
|
|
32
37
|
} from "../types"
|
|
33
|
-
import {
|
|
38
|
+
import { KernelInitAbi } from "./abi/KernelAccountAbi"
|
|
39
|
+
import { KernelV3InitAbi } from "./abi/KernelV3AccountAbi"
|
|
40
|
+
import { KernelV3MetaFactoryDeployWithFactoryAbi } from "./abi/KernelV3MetaFactoryAbi"
|
|
41
|
+
import {
|
|
42
|
+
DUMMY_ECDSA_SIGNATURE,
|
|
43
|
+
ROOT_MODE_KERNEL_V2,
|
|
44
|
+
VALIDATOR_TYPE
|
|
45
|
+
} from "./constants"
|
|
46
|
+
import { encodeCallData } from "./utils/encodeCallData"
|
|
47
|
+
import { getNonceKeyWithEncoding } from "./utils/getNonceKey"
|
|
48
|
+
import { signMessage } from "./utils/signMessage"
|
|
49
|
+
import { signTypedData } from "./utils/signTypedData"
|
|
34
50
|
|
|
35
51
|
export type KernelEcdsaSmartAccount<
|
|
36
|
-
entryPoint extends
|
|
52
|
+
entryPoint extends EntryPoint,
|
|
37
53
|
transport extends Transport = Transport,
|
|
38
54
|
chain extends Chain | undefined = Chain | undefined
|
|
39
55
|
> = SmartAccount<entryPoint, "kernelEcdsaSmartAccount", transport, chain>
|
|
@@ -73,52 +89,172 @@ const createAccountAbi = [
|
|
|
73
89
|
}
|
|
74
90
|
] as const
|
|
75
91
|
|
|
92
|
+
export type KernelVersion = "0.2.2" | "0.3.0-beta"
|
|
93
|
+
|
|
76
94
|
/**
|
|
77
|
-
* Default addresses for kernel smart account
|
|
95
|
+
* Default addresses map for different kernel smart account versions
|
|
78
96
|
*/
|
|
79
|
-
const
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
97
|
+
export const KERNEL_VERSION_TO_ADDRESSES_MAP: {
|
|
98
|
+
[key in KernelVersion]: {
|
|
99
|
+
ECDSA_VALIDATOR: Address
|
|
100
|
+
ACCOUNT_LOGIC: Address
|
|
101
|
+
FACTORY_ADDRESS: Address
|
|
102
|
+
META_FACTORY_ADDRESS?: Address
|
|
103
|
+
}
|
|
83
104
|
} = {
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
105
|
+
"0.2.2": {
|
|
106
|
+
ECDSA_VALIDATOR: "0xd9AB5096a832b9ce79914329DAEE236f8Eea0390",
|
|
107
|
+
ACCOUNT_LOGIC: "0x0DA6a956B9488eD4dd761E59f52FDc6c8068E6B5",
|
|
108
|
+
FACTORY_ADDRESS: "0x5de4839a76cf55d0c90e2061ef4386d962E15ae3"
|
|
109
|
+
},
|
|
110
|
+
"0.3.0-beta": {
|
|
111
|
+
ECDSA_VALIDATOR: "0x8104e3Ad430EA6d354d013A6789fDFc71E671c43",
|
|
112
|
+
ACCOUNT_LOGIC: "0x94F097E1ebEB4ecA3AAE54cabb08905B239A7D27",
|
|
113
|
+
FACTORY_ADDRESS: "0x6723b44Abeec4E71eBE3232BD5B455805baDD22f",
|
|
114
|
+
META_FACTORY_ADDRESS: "0xd703aaE79538628d27099B8c4f621bE4CCd142d5"
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
/**
|
|
119
|
+
* Get supported Kernel Smart Account version based on entryPoint
|
|
120
|
+
* @param entryPoint
|
|
121
|
+
*/
|
|
122
|
+
const getKernelVersion = (entryPoint: EntryPoint): KernelVersion => {
|
|
123
|
+
return entryPoint === ENTRYPOINT_ADDRESS_V06 ? "0.2.2" : "0.3.0-beta"
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
type KERNEL_ADDRESSES = {
|
|
127
|
+
ecdsaValidatorAddress: Address
|
|
128
|
+
accountLogicAddress: Address
|
|
129
|
+
factoryAddress: Address
|
|
130
|
+
metaFactoryAddress: Address
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
/**
|
|
134
|
+
* Get default addresses for Kernel Smart Account based on entryPoint or user input
|
|
135
|
+
* @param entryPointAddress
|
|
136
|
+
* @param ecdsaValidatorAddress
|
|
137
|
+
* @param accountLogicAddress
|
|
138
|
+
* @param factoryAddress
|
|
139
|
+
* @param metaFactoryAddress
|
|
140
|
+
*/
|
|
141
|
+
const getDefaultAddresses = <entryPoint extends EntryPoint>(
|
|
142
|
+
entryPointAddress: entryPoint,
|
|
143
|
+
{
|
|
144
|
+
ecdsaValidatorAddress: _ecdsaValidatorAddress,
|
|
145
|
+
accountLogicAddress: _accountLogicAddress,
|
|
146
|
+
factoryAddress: _factoryAddress,
|
|
147
|
+
metaFactoryAddress: _metaFactoryAddress
|
|
148
|
+
}: Partial<KERNEL_ADDRESSES>
|
|
149
|
+
): KERNEL_ADDRESSES => {
|
|
150
|
+
const kernelVersion = getKernelVersion(entryPointAddress)
|
|
151
|
+
const addresses = KERNEL_VERSION_TO_ADDRESSES_MAP[kernelVersion]
|
|
152
|
+
const ecdsaValidatorAddress =
|
|
153
|
+
_ecdsaValidatorAddress ?? addresses.ECDSA_VALIDATOR
|
|
154
|
+
const accountLogicAddress = _accountLogicAddress ?? addresses.ACCOUNT_LOGIC
|
|
155
|
+
const factoryAddress = _factoryAddress ?? addresses.FACTORY_ADDRESS
|
|
156
|
+
const metaFactoryAddress =
|
|
157
|
+
_metaFactoryAddress ?? addresses?.META_FACTORY_ADDRESS ?? zeroAddress // Meta Factory doesn't exists for Kernel v2.2
|
|
158
|
+
|
|
159
|
+
return {
|
|
160
|
+
ecdsaValidatorAddress,
|
|
161
|
+
accountLogicAddress,
|
|
162
|
+
factoryAddress,
|
|
163
|
+
metaFactoryAddress
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
export const getEcdsaRootIdentifierForKernelV3 = (
|
|
168
|
+
validatorAddress: Address
|
|
169
|
+
) => {
|
|
170
|
+
return concatHex([VALIDATOR_TYPE.VALIDATOR, validatorAddress])
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
/**
|
|
174
|
+
* Get the initialization data for a kernel smart account
|
|
175
|
+
* @param entryPoint
|
|
176
|
+
* @param owner
|
|
177
|
+
* @param ecdsaValidatorAddress
|
|
178
|
+
*/
|
|
179
|
+
const getInitialisationData = <entryPoint extends EntryPoint>({
|
|
180
|
+
entryPoint: entryPointAddress,
|
|
181
|
+
owner,
|
|
182
|
+
ecdsaValidatorAddress
|
|
183
|
+
}: {
|
|
184
|
+
entryPoint: entryPoint
|
|
185
|
+
owner: Address
|
|
186
|
+
ecdsaValidatorAddress: Address
|
|
187
|
+
}) => {
|
|
188
|
+
const entryPointVersion = getEntryPointVersion(entryPointAddress)
|
|
189
|
+
|
|
190
|
+
if (entryPointVersion === "v0.6") {
|
|
191
|
+
return encodeFunctionData({
|
|
192
|
+
abi: KernelInitAbi,
|
|
193
|
+
functionName: "initialize",
|
|
194
|
+
args: [ecdsaValidatorAddress, owner]
|
|
195
|
+
})
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
return encodeFunctionData({
|
|
199
|
+
abi: KernelV3InitAbi,
|
|
200
|
+
functionName: "initialize",
|
|
201
|
+
args: [
|
|
202
|
+
getEcdsaRootIdentifierForKernelV3(ecdsaValidatorAddress),
|
|
203
|
+
zeroAddress /* hookAddress */,
|
|
204
|
+
owner,
|
|
205
|
+
"0x" /* hookData */
|
|
206
|
+
]
|
|
207
|
+
})
|
|
87
208
|
}
|
|
88
209
|
|
|
89
210
|
/**
|
|
90
211
|
* Get the account initialization code for a kernel smart account
|
|
212
|
+
* @param entryPoint
|
|
91
213
|
* @param owner
|
|
92
214
|
* @param index
|
|
93
215
|
* @param factoryAddress
|
|
94
216
|
* @param accountLogicAddress
|
|
95
217
|
* @param ecdsaValidatorAddress
|
|
96
218
|
*/
|
|
97
|
-
const getAccountInitCode = async ({
|
|
219
|
+
const getAccountInitCode = async <entryPoint extends EntryPoint>({
|
|
220
|
+
entryPoint: entryPointAddress,
|
|
98
221
|
owner,
|
|
99
222
|
index,
|
|
223
|
+
factoryAddress,
|
|
100
224
|
accountLogicAddress,
|
|
101
225
|
ecdsaValidatorAddress
|
|
102
226
|
}: {
|
|
227
|
+
entryPoint: entryPoint
|
|
103
228
|
owner: Address
|
|
104
229
|
index: bigint
|
|
230
|
+
factoryAddress: Address
|
|
105
231
|
accountLogicAddress: Address
|
|
106
232
|
ecdsaValidatorAddress: Address
|
|
107
233
|
}): Promise<Hex> => {
|
|
108
234
|
if (!owner) throw new Error("Owner account not found")
|
|
235
|
+
const entryPointVersion = getEntryPointVersion(entryPointAddress)
|
|
109
236
|
|
|
110
237
|
// Build the account initialization data
|
|
111
|
-
const initialisationData =
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
238
|
+
const initialisationData = getInitialisationData({
|
|
239
|
+
entryPoint: entryPointAddress,
|
|
240
|
+
ecdsaValidatorAddress,
|
|
241
|
+
owner
|
|
115
242
|
})
|
|
116
243
|
|
|
117
244
|
// Build the account init code
|
|
245
|
+
|
|
246
|
+
if (entryPointVersion === "v0.6") {
|
|
247
|
+
return encodeFunctionData({
|
|
248
|
+
abi: createAccountAbi,
|
|
249
|
+
functionName: "createAccount",
|
|
250
|
+
args: [accountLogicAddress, initialisationData, index]
|
|
251
|
+
})
|
|
252
|
+
}
|
|
253
|
+
|
|
118
254
|
return encodeFunctionData({
|
|
119
|
-
abi:
|
|
120
|
-
functionName: "
|
|
121
|
-
args: [
|
|
255
|
+
abi: KernelV3MetaFactoryDeployWithFactoryAbi,
|
|
256
|
+
functionName: "deployWithFactory",
|
|
257
|
+
args: [factoryAddress, initialisationData, toHex(index, { size: 32 })]
|
|
122
258
|
})
|
|
123
259
|
}
|
|
124
260
|
|
|
@@ -130,9 +266,10 @@ const getAccountInitCode = async ({
|
|
|
130
266
|
* @param ecdsaValidatorAddress
|
|
131
267
|
* @param initCodeProvider
|
|
132
268
|
* @param deployedAccountAddress
|
|
269
|
+
* @param factoryAddress
|
|
133
270
|
*/
|
|
134
271
|
const getAccountAddress = async <
|
|
135
|
-
entryPoint extends
|
|
272
|
+
entryPoint extends EntryPoint,
|
|
136
273
|
TTransport extends Transport = Transport,
|
|
137
274
|
TChain extends Chain | undefined = Chain | undefined
|
|
138
275
|
>({
|
|
@@ -194,14 +331,22 @@ const getAccountAddress = async <
|
|
|
194
331
|
// Find the init code for this account
|
|
195
332
|
const factoryData = await initCodeProvider()
|
|
196
333
|
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
334
|
+
const entryPointVersion = getEntryPointVersion(entryPointAddress)
|
|
335
|
+
if (entryPointVersion === "v0.6") {
|
|
336
|
+
return getSenderAddress<ENTRYPOINT_ADDRESS_V06_TYPE>(client, {
|
|
337
|
+
initCode: concatHex([factoryAddress, factoryData]),
|
|
338
|
+
entryPoint: entryPointAddress as ENTRYPOINT_ADDRESS_V06_TYPE
|
|
339
|
+
})
|
|
340
|
+
}
|
|
341
|
+
return getSenderAddress<ENTRYPOINT_ADDRESS_V07_TYPE>(client, {
|
|
342
|
+
factory: factoryAddress,
|
|
343
|
+
factoryData: factoryData,
|
|
344
|
+
entryPoint: entryPointAddress as ENTRYPOINT_ADDRESS_V07_TYPE
|
|
200
345
|
})
|
|
201
346
|
}
|
|
202
347
|
|
|
203
348
|
export type SignerToEcdsaKernelSmartAccountParameters<
|
|
204
|
-
entryPoint extends
|
|
349
|
+
entryPoint extends EntryPoint,
|
|
205
350
|
TSource extends string = string,
|
|
206
351
|
TAddress extends Address = Address
|
|
207
352
|
> = Prettify<{
|
|
@@ -210,6 +355,7 @@ export type SignerToEcdsaKernelSmartAccountParameters<
|
|
|
210
355
|
address?: Address
|
|
211
356
|
index?: bigint
|
|
212
357
|
factoryAddress?: Address
|
|
358
|
+
metaFactoryAddress?: Address
|
|
213
359
|
accountLogicAddress?: Address
|
|
214
360
|
ecdsaValidatorAddress?: Address
|
|
215
361
|
deployedAccountAddress?: Address
|
|
@@ -226,7 +372,7 @@ export type SignerToEcdsaKernelSmartAccountParameters<
|
|
|
226
372
|
* @param deployedAccountAddress
|
|
227
373
|
*/
|
|
228
374
|
export async function signerToEcdsaKernelSmartAccount<
|
|
229
|
-
entryPoint extends
|
|
375
|
+
entryPoint extends EntryPoint,
|
|
230
376
|
TTransport extends Transport = Transport,
|
|
231
377
|
TChain extends Chain | undefined = Chain | undefined,
|
|
232
378
|
TSource extends string = string,
|
|
@@ -238,17 +384,27 @@ export async function signerToEcdsaKernelSmartAccount<
|
|
|
238
384
|
address,
|
|
239
385
|
entryPoint: entryPointAddress,
|
|
240
386
|
index = BigInt(0),
|
|
241
|
-
factoryAddress
|
|
242
|
-
|
|
243
|
-
|
|
387
|
+
factoryAddress: _factoryAddress,
|
|
388
|
+
metaFactoryAddress: _metaFactoryAddress,
|
|
389
|
+
accountLogicAddress: _accountLogicAddress,
|
|
390
|
+
ecdsaValidatorAddress: _ecdsaValidatorAddress,
|
|
244
391
|
deployedAccountAddress
|
|
245
392
|
}: SignerToEcdsaKernelSmartAccountParameters<entryPoint, TSource, TAddress>
|
|
246
393
|
): Promise<KernelEcdsaSmartAccount<entryPoint, TTransport, TChain>> {
|
|
247
394
|
const entryPointVersion = getEntryPointVersion(entryPointAddress)
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
395
|
+
const kernelVersion = getKernelVersion(entryPointAddress)
|
|
396
|
+
|
|
397
|
+
const {
|
|
398
|
+
accountLogicAddress,
|
|
399
|
+
ecdsaValidatorAddress,
|
|
400
|
+
factoryAddress,
|
|
401
|
+
metaFactoryAddress
|
|
402
|
+
} = getDefaultAddresses(entryPointAddress, {
|
|
403
|
+
ecdsaValidatorAddress: _ecdsaValidatorAddress,
|
|
404
|
+
accountLogicAddress: _accountLogicAddress,
|
|
405
|
+
factoryAddress: _factoryAddress,
|
|
406
|
+
metaFactoryAddress: _metaFactoryAddress
|
|
407
|
+
})
|
|
252
408
|
|
|
253
409
|
// Get the private key related account
|
|
254
410
|
const viemSigner: LocalAccount = {
|
|
@@ -261,8 +417,10 @@ export async function signerToEcdsaKernelSmartAccount<
|
|
|
261
417
|
// Helper to generate the init code for the smart account
|
|
262
418
|
const generateInitCode = () =>
|
|
263
419
|
getAccountInitCode({
|
|
420
|
+
entryPoint: entryPointAddress,
|
|
264
421
|
owner: viemSigner.address,
|
|
265
422
|
index,
|
|
423
|
+
factoryAddress,
|
|
266
424
|
accountLogicAddress,
|
|
267
425
|
ecdsaValidatorAddress
|
|
268
426
|
})
|
|
@@ -277,7 +435,10 @@ export async function signerToEcdsaKernelSmartAccount<
|
|
|
277
435
|
ecdsaValidatorAddress,
|
|
278
436
|
initCodeProvider: generateInitCode,
|
|
279
437
|
deployedAccountAddress,
|
|
280
|
-
factoryAddress
|
|
438
|
+
factoryAddress:
|
|
439
|
+
entryPointVersion === "v0.6"
|
|
440
|
+
? factoryAddress
|
|
441
|
+
: metaFactoryAddress
|
|
281
442
|
}),
|
|
282
443
|
client.chain?.id ?? getChainId(client)
|
|
283
444
|
])
|
|
@@ -292,7 +453,18 @@ export async function signerToEcdsaKernelSmartAccount<
|
|
|
292
453
|
return toSmartAccount({
|
|
293
454
|
address: accountAddress,
|
|
294
455
|
async signMessage({ message }) {
|
|
295
|
-
|
|
456
|
+
const signature = await signMessage(client, {
|
|
457
|
+
account: viemSigner,
|
|
458
|
+
message,
|
|
459
|
+
accountAddress,
|
|
460
|
+
accountVersion: kernelVersion,
|
|
461
|
+
chainId
|
|
462
|
+
})
|
|
463
|
+
|
|
464
|
+
return concatHex([
|
|
465
|
+
getEcdsaRootIdentifierForKernelV3(ecdsaValidatorAddress),
|
|
466
|
+
signature
|
|
467
|
+
])
|
|
296
468
|
},
|
|
297
469
|
async signTransaction(_, __) {
|
|
298
470
|
throw new SignTransactionNotSupportedBySmartAccount()
|
|
@@ -303,13 +475,22 @@ export async function signerToEcdsaKernelSmartAccount<
|
|
|
303
475
|
| keyof TTypedData
|
|
304
476
|
| "EIP712Domain" = keyof TTypedData
|
|
305
477
|
>(typedData: TypedDataDefinition<TTypedData, TPrimaryType>) {
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
478
|
+
const signature = await signTypedData<
|
|
479
|
+
TTypedData,
|
|
480
|
+
TPrimaryType,
|
|
481
|
+
TChain,
|
|
482
|
+
undefined
|
|
483
|
+
>(client, {
|
|
484
|
+
account: viemSigner,
|
|
485
|
+
...typedData,
|
|
486
|
+
accountAddress,
|
|
487
|
+
accountVersion: kernelVersion,
|
|
488
|
+
chainId
|
|
489
|
+
})
|
|
490
|
+
return concatHex([
|
|
491
|
+
getEcdsaRootIdentifierForKernelV3(ecdsaValidatorAddress),
|
|
492
|
+
signature
|
|
493
|
+
])
|
|
313
494
|
},
|
|
314
495
|
client: client,
|
|
315
496
|
publicKey: accountAddress,
|
|
@@ -318,9 +499,16 @@ export async function signerToEcdsaKernelSmartAccount<
|
|
|
318
499
|
|
|
319
500
|
// Get the nonce of the smart account
|
|
320
501
|
async getNonce() {
|
|
502
|
+
const key = getNonceKeyWithEncoding(
|
|
503
|
+
kernelVersion,
|
|
504
|
+
ecdsaValidatorAddress
|
|
505
|
+
// @dev specify the custom nonceKey here when integrating the said feature
|
|
506
|
+
/*, nonceKey */
|
|
507
|
+
)
|
|
321
508
|
return getAccountNonce(client, {
|
|
322
509
|
sender: accountAddress,
|
|
323
|
-
entryPoint: entryPointAddress
|
|
510
|
+
entryPoint: entryPointAddress,
|
|
511
|
+
key
|
|
324
512
|
})
|
|
325
513
|
},
|
|
326
514
|
|
|
@@ -334,12 +522,15 @@ export async function signerToEcdsaKernelSmartAccount<
|
|
|
334
522
|
entryPoint: entryPointAddress,
|
|
335
523
|
chainId: chainId
|
|
336
524
|
})
|
|
337
|
-
const signature = await
|
|
525
|
+
const signature = await _signMessage(client, {
|
|
338
526
|
account: viemSigner,
|
|
339
527
|
message: { raw: hash }
|
|
340
528
|
})
|
|
341
529
|
// Always use the sudo mode, since we will use external paymaster
|
|
342
|
-
|
|
530
|
+
if (kernelVersion === "0.2.2") {
|
|
531
|
+
return concatHex(["0x00000000", signature])
|
|
532
|
+
}
|
|
533
|
+
return signature
|
|
343
534
|
},
|
|
344
535
|
|
|
345
536
|
// Encode the init code
|
|
@@ -353,7 +544,11 @@ export async function signerToEcdsaKernelSmartAccount<
|
|
|
353
544
|
|
|
354
545
|
if (smartAccountDeployed) return "0x"
|
|
355
546
|
|
|
356
|
-
|
|
547
|
+
const _factoryAddress =
|
|
548
|
+
entryPointVersion === "v0.6"
|
|
549
|
+
? factoryAddress
|
|
550
|
+
: metaFactoryAddress
|
|
551
|
+
return concatHex([_factoryAddress, await generateInitCode()])
|
|
357
552
|
},
|
|
358
553
|
|
|
359
554
|
async getFactory() {
|
|
@@ -366,7 +561,9 @@ export async function signerToEcdsaKernelSmartAccount<
|
|
|
366
561
|
|
|
367
562
|
if (smartAccountDeployed) return undefined
|
|
368
563
|
|
|
369
|
-
return
|
|
564
|
+
return entryPointVersion === "v0.6"
|
|
565
|
+
? factoryAddress
|
|
566
|
+
: metaFactoryAddress
|
|
370
567
|
},
|
|
371
568
|
|
|
372
569
|
async getFactoryData() {
|
|
@@ -389,31 +586,15 @@ export async function signerToEcdsaKernelSmartAccount<
|
|
|
389
586
|
|
|
390
587
|
// Encode a call
|
|
391
588
|
async encodeCallData(_tx) {
|
|
392
|
-
|
|
393
|
-
// Encode a batched call
|
|
394
|
-
return encodeFunctionData({
|
|
395
|
-
abi: KernelExecuteAbi,
|
|
396
|
-
functionName: "executeBatch",
|
|
397
|
-
args: [
|
|
398
|
-
_tx.map((tx) => ({
|
|
399
|
-
to: tx.to,
|
|
400
|
-
value: tx.value,
|
|
401
|
-
data: tx.data
|
|
402
|
-
}))
|
|
403
|
-
]
|
|
404
|
-
})
|
|
405
|
-
}
|
|
406
|
-
// Encode a simple call
|
|
407
|
-
return encodeFunctionData({
|
|
408
|
-
abi: KernelExecuteAbi,
|
|
409
|
-
functionName: "execute",
|
|
410
|
-
args: [_tx.to, _tx.value, _tx.data, 0]
|
|
411
|
-
})
|
|
589
|
+
return encodeCallData(_tx, kernelVersion)
|
|
412
590
|
},
|
|
413
591
|
|
|
414
592
|
// Get simple dummy signature
|
|
415
593
|
async getDummySignature(_userOperation) {
|
|
416
|
-
|
|
594
|
+
if (kernelVersion === "0.2.2") {
|
|
595
|
+
return concatHex([ROOT_MODE_KERNEL_V2, DUMMY_ECDSA_SIGNATURE])
|
|
596
|
+
}
|
|
597
|
+
return DUMMY_ECDSA_SIGNATURE
|
|
417
598
|
}
|
|
418
599
|
})
|
|
419
600
|
}
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
import {
|
|
2
|
+
type Address,
|
|
3
|
+
type Hex,
|
|
4
|
+
concatHex,
|
|
5
|
+
encodeAbiParameters,
|
|
6
|
+
encodeFunctionData,
|
|
7
|
+
toHex
|
|
8
|
+
} from "viem"
|
|
9
|
+
import { KernelExecuteAbi } from "../abi/KernelAccountAbi"
|
|
10
|
+
import { KernelV3ExecuteAbi } from "../abi/KernelV3AccountAbi"
|
|
11
|
+
import { CALL_TYPE, EXEC_TYPE } from "../constants"
|
|
12
|
+
import { type KernelVersion } from "../signerToEcdsaKernelSmartAccount"
|
|
13
|
+
import { getExecMode } from "./getExecMode"
|
|
14
|
+
|
|
15
|
+
export const encodeCallData = (
|
|
16
|
+
_tx:
|
|
17
|
+
| {
|
|
18
|
+
to: Address
|
|
19
|
+
value: bigint
|
|
20
|
+
data: Hex
|
|
21
|
+
}
|
|
22
|
+
| {
|
|
23
|
+
to: Address
|
|
24
|
+
value: bigint
|
|
25
|
+
data: Hex
|
|
26
|
+
}[],
|
|
27
|
+
accountVersion: KernelVersion
|
|
28
|
+
) => {
|
|
29
|
+
if (accountVersion === "0.2.2") {
|
|
30
|
+
if (Array.isArray(_tx)) {
|
|
31
|
+
// Encode a batched call
|
|
32
|
+
return encodeFunctionData({
|
|
33
|
+
abi: KernelExecuteAbi,
|
|
34
|
+
functionName: "executeBatch",
|
|
35
|
+
args: [
|
|
36
|
+
_tx.map((tx) => ({
|
|
37
|
+
to: tx.to,
|
|
38
|
+
value: tx.value,
|
|
39
|
+
data: tx.data
|
|
40
|
+
}))
|
|
41
|
+
]
|
|
42
|
+
})
|
|
43
|
+
}
|
|
44
|
+
// Encode a simple call
|
|
45
|
+
return encodeFunctionData({
|
|
46
|
+
abi: KernelExecuteAbi,
|
|
47
|
+
functionName: "execute",
|
|
48
|
+
args: [_tx.to, _tx.value, _tx.data, 0]
|
|
49
|
+
})
|
|
50
|
+
}
|
|
51
|
+
if (Array.isArray(_tx)) {
|
|
52
|
+
// Encode a batched call
|
|
53
|
+
const calldata = encodeAbiParameters(
|
|
54
|
+
[
|
|
55
|
+
{
|
|
56
|
+
name: "executionBatch",
|
|
57
|
+
type: "tuple[]",
|
|
58
|
+
components: [
|
|
59
|
+
{
|
|
60
|
+
name: "target",
|
|
61
|
+
type: "address"
|
|
62
|
+
},
|
|
63
|
+
{
|
|
64
|
+
name: "value",
|
|
65
|
+
type: "uint256"
|
|
66
|
+
},
|
|
67
|
+
{
|
|
68
|
+
name: "callData",
|
|
69
|
+
type: "bytes"
|
|
70
|
+
}
|
|
71
|
+
]
|
|
72
|
+
}
|
|
73
|
+
],
|
|
74
|
+
[
|
|
75
|
+
_tx.map((arg) => {
|
|
76
|
+
return {
|
|
77
|
+
target: arg.to,
|
|
78
|
+
value: arg.value,
|
|
79
|
+
callData: arg.data
|
|
80
|
+
}
|
|
81
|
+
})
|
|
82
|
+
]
|
|
83
|
+
)
|
|
84
|
+
return encodeFunctionData({
|
|
85
|
+
abi: KernelV3ExecuteAbi,
|
|
86
|
+
functionName: "execute",
|
|
87
|
+
args: [
|
|
88
|
+
getExecMode({
|
|
89
|
+
callType: CALL_TYPE.BATCH,
|
|
90
|
+
execType: EXEC_TYPE.DEFAULT
|
|
91
|
+
}),
|
|
92
|
+
calldata
|
|
93
|
+
]
|
|
94
|
+
})
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
const calldata = concatHex([
|
|
98
|
+
_tx.to,
|
|
99
|
+
toHex(_tx.value, { size: 32 }),
|
|
100
|
+
_tx.data
|
|
101
|
+
])
|
|
102
|
+
|
|
103
|
+
return encodeFunctionData({
|
|
104
|
+
abi: KernelV3ExecuteAbi,
|
|
105
|
+
functionName: "execute",
|
|
106
|
+
args: [
|
|
107
|
+
getExecMode({
|
|
108
|
+
callType: CALL_TYPE.SINGLE,
|
|
109
|
+
execType: EXEC_TYPE.DEFAULT
|
|
110
|
+
}),
|
|
111
|
+
calldata
|
|
112
|
+
]
|
|
113
|
+
})
|
|
114
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { type Hex, concatHex, pad } from "viem"
|
|
2
|
+
import { CALL_TYPE, EXEC_TYPE } from "../constants"
|
|
3
|
+
|
|
4
|
+
export const getExecMode = ({
|
|
5
|
+
callType,
|
|
6
|
+
execType
|
|
7
|
+
}: {
|
|
8
|
+
callType: CALL_TYPE
|
|
9
|
+
execType: EXEC_TYPE
|
|
10
|
+
}): Hex => {
|
|
11
|
+
return concatHex([
|
|
12
|
+
callType, // 1 byte
|
|
13
|
+
execType, // 1 byte
|
|
14
|
+
"0x00000000", // 4 bytes
|
|
15
|
+
"0x00000000", // 4 bytes
|
|
16
|
+
pad("0x00000000", { size: 22 })
|
|
17
|
+
])
|
|
18
|
+
}
|