@zerodev/sdk 5.2.0-alpha-3 → 5.2.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.
- package/_cjs/accounts/kernel/abi/kernel_v_3_0_0/KernelAccountAbi.js +115 -58
- package/_cjs/accounts/kernel/abi/kernel_v_3_0_0/KernelAccountAbi.js.map +1 -1
- package/_cjs/accounts/kernel/abi/kernel_v_3_0_0/KernelFactoryAbi.js +39 -0
- package/_cjs/accounts/kernel/abi/kernel_v_3_0_0/KernelFactoryAbi.js.map +1 -0
- package/_cjs/accounts/kernel/abi/kernel_v_3_0_0/KernelFactoryStakerAbi.js +203 -0
- package/_cjs/accounts/kernel/abi/kernel_v_3_0_0/KernelFactoryStakerAbi.js.map +1 -0
- package/_cjs/accounts/kernel/createKernelAccount.js +43 -22
- package/_cjs/accounts/kernel/createKernelAccount.js.map +1 -1
- package/_cjs/accounts/kernel/utils/account/ep0_7/getKernelV3Nonce.js +22 -0
- package/_cjs/accounts/kernel/utils/account/ep0_7/getKernelV3Nonce.js.map +1 -0
- package/_cjs/accounts/kernel/utils/common/getActionSelector.js +19 -0
- package/_cjs/accounts/kernel/utils/common/getActionSelector.js.map +1 -0
- package/_cjs/accounts/kernel/utils/plugins/ep0_6/getEncodedPluginsData.js +22 -0
- package/_cjs/accounts/kernel/utils/plugins/ep0_6/getEncodedPluginsData.js.map +1 -0
- package/_cjs/accounts/kernel/utils/plugins/ep0_6/getPluginsEnableTypedData.js +39 -0
- package/_cjs/accounts/kernel/utils/plugins/ep0_6/getPluginsEnableTypedData.js.map +1 -0
- package/_cjs/accounts/kernel/utils/plugins/ep0_7/getEncodedPluginsData.js +21 -0
- package/_cjs/accounts/kernel/utils/plugins/ep0_7/getEncodedPluginsData.js.map +1 -0
- package/_cjs/accounts/kernel/utils/plugins/ep0_7/getPluginsEnableTypedData.js +41 -0
- package/_cjs/accounts/kernel/utils/plugins/ep0_7/getPluginsEnableTypedData.js.map +1 -0
- package/_cjs/accounts/kernel/utils/plugins/ep0_7/isPluginInitialized.js +20 -0
- package/_cjs/accounts/kernel/utils/plugins/ep0_7/isPluginInitialized.js.map +1 -0
- package/_cjs/accounts/kernel/v1/createKernelV1Account.js +5 -2
- package/_cjs/accounts/kernel/v1/createKernelV1Account.js.map +1 -1
- package/_cjs/accounts/kernel/v2/createKernelV2Account.js +9 -4
- package/_cjs/accounts/kernel/v2/createKernelV2Account.js.map +1 -1
- package/_cjs/accounts/utils/getCustomNonceKeyFromString.js +19 -0
- package/_cjs/accounts/utils/getCustomNonceKeyFromString.js.map +1 -0
- package/_cjs/accounts/utils/index.js +3 -1
- package/_cjs/accounts/utils/index.js.map +1 -1
- package/_cjs/accounts/utils/toKernelPluginManager.js +120 -184
- package/_cjs/accounts/utils/toKernelPluginManager.js.map +1 -1
- package/_cjs/actions/account-client/getUserOperationGasPrice.js +15 -0
- package/_cjs/actions/account-client/getUserOperationGasPrice.js.map +1 -0
- package/_cjs/actions/index.js +3 -1
- package/_cjs/actions/index.js.map +1 -1
- package/_cjs/actions/paymaster/estimateGasInERC20.js +2 -2
- package/_cjs/actions/paymaster/estimateGasInERC20.js.map +1 -1
- package/_cjs/actions/paymaster/sponsorUserOperation.js +1 -2
- package/_cjs/actions/paymaster/sponsorUserOperation.js.map +1 -1
- package/_cjs/clients/decorators/kernel.js +3 -1
- package/_cjs/clients/decorators/kernel.js.map +1 -1
- package/_cjs/clients/kernelAccountClient.js +29 -3
- package/_cjs/clients/kernelAccountClient.js.map +1 -1
- package/_cjs/clients/paymasterClient.js +18 -1
- package/_cjs/clients/paymasterClient.js.map +1 -1
- package/_cjs/clients/utils.js +31 -0
- package/_cjs/clients/utils.js.map +1 -0
- package/_cjs/constants.js +5 -2
- package/_cjs/constants.js.map +1 -1
- package/_cjs/index.js +6 -1
- package/_cjs/index.js.map +1 -1
- package/_cjs/providers/KernelEIP1193Provider.js +37 -0
- package/_cjs/providers/KernelEIP1193Provider.js.map +1 -1
- package/_cjs/types/index.js.map +1 -1
- package/_cjs/types/kernel.js.map +1 -1
- package/_cjs/utils.js +1 -2
- package/_cjs/utils.js.map +1 -1
- package/_esm/accounts/kernel/abi/kernel_v_3_0_0/KernelAccountAbi.js +115 -58
- package/_esm/accounts/kernel/abi/kernel_v_3_0_0/KernelAccountAbi.js.map +1 -1
- package/_esm/accounts/kernel/abi/kernel_v_3_0_0/KernelFactoryAbi.js +36 -0
- package/_esm/accounts/kernel/abi/kernel_v_3_0_0/KernelFactoryAbi.js.map +1 -0
- package/_esm/accounts/kernel/abi/kernel_v_3_0_0/KernelFactoryStakerAbi.js +200 -0
- package/_esm/accounts/kernel/abi/kernel_v_3_0_0/KernelFactoryStakerAbi.js.map +1 -0
- package/_esm/accounts/kernel/createKernelAccount.js +44 -23
- package/_esm/accounts/kernel/createKernelAccount.js.map +1 -1
- package/_esm/accounts/kernel/utils/account/ep0_7/getKernelV3Nonce.js +18 -0
- package/_esm/accounts/kernel/utils/account/ep0_7/getKernelV3Nonce.js.map +1 -0
- package/_esm/accounts/kernel/utils/common/getActionSelector.js +15 -0
- package/_esm/accounts/kernel/utils/common/getActionSelector.js.map +1 -0
- package/_esm/accounts/kernel/utils/plugins/ep0_6/getEncodedPluginsData.js +18 -0
- package/_esm/accounts/kernel/utils/plugins/ep0_6/getEncodedPluginsData.js.map +1 -0
- package/_esm/accounts/kernel/utils/plugins/ep0_6/getPluginsEnableTypedData.js +35 -0
- package/_esm/accounts/kernel/utils/plugins/ep0_6/getPluginsEnableTypedData.js.map +1 -0
- package/_esm/accounts/kernel/utils/plugins/ep0_7/getEncodedPluginsData.js +18 -0
- package/_esm/accounts/kernel/utils/plugins/ep0_7/getEncodedPluginsData.js.map +1 -0
- package/_esm/accounts/kernel/utils/plugins/ep0_7/getPluginsEnableTypedData.js +42 -0
- package/_esm/accounts/kernel/utils/plugins/ep0_7/getPluginsEnableTypedData.js.map +1 -0
- package/_esm/accounts/kernel/utils/plugins/ep0_7/isPluginInitialized.js +16 -0
- package/_esm/accounts/kernel/utils/plugins/ep0_7/isPluginInitialized.js.map +1 -0
- package/_esm/accounts/kernel/v1/createKernelV1Account.js +6 -3
- package/_esm/accounts/kernel/v1/createKernelV1Account.js.map +1 -1
- package/_esm/accounts/kernel/v2/createKernelV2Account.js +10 -5
- package/_esm/accounts/kernel/v2/createKernelV2Account.js.map +1 -1
- package/_esm/accounts/utils/getCustomNonceKeyFromString.js +15 -0
- package/_esm/accounts/utils/getCustomNonceKeyFromString.js.map +1 -0
- package/_esm/accounts/utils/index.js +1 -0
- package/_esm/accounts/utils/index.js.map +1 -1
- package/_esm/accounts/utils/toKernelPluginManager.js +124 -188
- package/_esm/accounts/utils/toKernelPluginManager.js.map +1 -1
- package/_esm/actions/account-client/getUserOperationGasPrice.js +11 -0
- package/_esm/actions/account-client/getUserOperationGasPrice.js.map +1 -0
- package/_esm/actions/index.js +1 -0
- package/_esm/actions/index.js.map +1 -1
- package/_esm/actions/paymaster/estimateGasInERC20.js +2 -2
- package/_esm/actions/paymaster/estimateGasInERC20.js.map +1 -1
- package/_esm/actions/paymaster/sponsorUserOperation.js +1 -2
- package/_esm/actions/paymaster/sponsorUserOperation.js.map +1 -1
- package/_esm/clients/decorators/kernel.js +3 -1
- package/_esm/clients/decorators/kernel.js.map +1 -1
- package/_esm/clients/kernelAccountClient.js +30 -4
- package/_esm/clients/kernelAccountClient.js.map +1 -1
- package/_esm/clients/paymasterClient.js +19 -2
- package/_esm/clients/paymasterClient.js.map +1 -1
- package/_esm/clients/utils.js +26 -0
- package/_esm/clients/utils.js.map +1 -0
- package/_esm/constants.js +4 -1
- package/_esm/constants.js.map +1 -1
- package/_esm/index.js +3 -1
- package/_esm/index.js.map +1 -1
- package/_esm/providers/KernelEIP1193Provider.js +37 -0
- package/_esm/providers/KernelEIP1193Provider.js.map +1 -1
- package/_esm/types/index.js.map +1 -1
- package/_esm/types/kernel.js.map +1 -1
- package/_esm/utils.js +2 -3
- package/_esm/utils.js.map +1 -1
- package/_types/accounts/kernel/abi/kernel_v_3_0_0/KernelAccountAbi.d.ts +110 -20
- package/_types/accounts/kernel/abi/kernel_v_3_0_0/KernelAccountAbi.d.ts.map +1 -1
- package/_types/accounts/kernel/abi/kernel_v_3_0_0/KernelFactoryAbi.d.ts +60 -0
- package/_types/accounts/kernel/abi/kernel_v_3_0_0/KernelFactoryAbi.d.ts.map +1 -0
- package/_types/accounts/kernel/abi/kernel_v_3_0_0/KernelFactoryStakerAbi.d.ts +215 -0
- package/_types/accounts/kernel/abi/kernel_v_3_0_0/KernelFactoryStakerAbi.d.ts.map +1 -0
- package/_types/accounts/kernel/createKernelAccount.d.ts +8 -4
- package/_types/accounts/kernel/createKernelAccount.d.ts.map +1 -1
- package/_types/accounts/kernel/utils/account/ep0_7/getKernelV3Nonce.d.ts +3 -0
- package/_types/accounts/kernel/utils/account/ep0_7/getKernelV3Nonce.d.ts.map +1 -0
- package/_types/accounts/kernel/utils/common/getActionSelector.d.ts +4 -0
- package/_types/accounts/kernel/utils/common/getActionSelector.d.ts.map +1 -0
- package/_types/accounts/kernel/utils/plugins/ep0_6/getEncodedPluginsData.d.ts +9 -0
- package/_types/accounts/kernel/utils/plugins/ep0_6/getEncodedPluginsData.d.ts.map +1 -0
- package/_types/accounts/kernel/utils/plugins/ep0_6/getPluginsEnableTypedData.d.ts +13 -0
- package/_types/accounts/kernel/utils/plugins/ep0_6/getPluginsEnableTypedData.d.ts.map +1 -0
- package/_types/accounts/kernel/utils/plugins/ep0_7/getEncodedPluginsData.d.ts +9 -0
- package/_types/accounts/kernel/utils/plugins/ep0_7/getEncodedPluginsData.d.ts.map +1 -0
- package/_types/accounts/kernel/utils/plugins/ep0_7/getPluginsEnableTypedData.d.ts +10 -0
- package/_types/accounts/kernel/utils/plugins/ep0_7/getPluginsEnableTypedData.d.ts.map +1 -0
- package/_types/accounts/kernel/utils/plugins/ep0_7/isPluginInitialized.d.ts +3 -0
- package/_types/accounts/kernel/utils/plugins/ep0_7/isPluginInitialized.d.ts.map +1 -0
- package/_types/accounts/kernel/v1/createKernelV1Account.d.ts +1 -1
- package/_types/accounts/kernel/v1/createKernelV1Account.d.ts.map +1 -1
- package/_types/accounts/kernel/v2/createKernelV2Account.d.ts +3 -1
- package/_types/accounts/kernel/v2/createKernelV2Account.d.ts.map +1 -1
- package/_types/accounts/utils/getCustomNonceKeyFromString.d.ts +3 -0
- package/_types/accounts/utils/getCustomNonceKeyFromString.d.ts.map +1 -0
- package/_types/accounts/utils/index.d.ts +1 -0
- package/_types/accounts/utils/index.d.ts.map +1 -1
- package/_types/accounts/utils/toKernelPluginManager.d.ts +1 -1
- package/_types/accounts/utils/toKernelPluginManager.d.ts.map +1 -1
- package/_types/actions/account-client/getUserOperationGasPrice.d.ts +9 -0
- package/_types/actions/account-client/getUserOperationGasPrice.d.ts.map +1 -0
- package/_types/actions/index.d.ts +1 -0
- package/_types/actions/index.d.ts.map +1 -1
- package/_types/actions/paymaster/estimateGasInERC20.d.ts.map +1 -1
- package/_types/actions/paymaster/sponsorUserOperation.d.ts.map +1 -1
- package/_types/clients/decorators/kernel.d.ts +8 -1
- package/_types/clients/decorators/kernel.d.ts.map +1 -1
- package/_types/clients/kernelAccountClient.d.ts +12 -4
- package/_types/clients/kernelAccountClient.d.ts.map +1 -1
- package/_types/clients/paymasterClient.d.ts.map +1 -1
- package/_types/clients/utils.d.ts +3 -0
- package/_types/clients/utils.d.ts.map +1 -0
- package/_types/constants.d.ts +4 -1
- package/_types/constants.d.ts.map +1 -1
- package/_types/index.d.ts +3 -1
- package/_types/index.d.ts.map +1 -1
- package/_types/providers/KernelEIP1193Provider.d.ts +2 -0
- package/_types/providers/KernelEIP1193Provider.d.ts.map +1 -1
- package/_types/types/index.d.ts +1 -1
- package/_types/types/index.d.ts.map +1 -1
- package/_types/types/kernel.d.ts +32 -17
- package/_types/types/kernel.d.ts.map +1 -1
- package/_types/utils.d.ts.map +1 -1
- package/accounts/kernel/abi/kernel_v_3_0_0/KernelAccountAbi.ts +115 -58
- package/accounts/kernel/abi/kernel_v_3_0_0/KernelFactoryAbi.ts +35 -0
- package/accounts/kernel/abi/kernel_v_3_0_0/KernelFactoryStakerAbi.ts +199 -0
- package/accounts/kernel/createKernelAccount.ts +59 -26
- package/accounts/kernel/utils/account/ep0_7/getKernelV3Nonce.ts +24 -0
- package/accounts/kernel/utils/common/getActionSelector.ts +20 -0
- package/accounts/kernel/utils/plugins/ep0_6/getEncodedPluginsData.ts +39 -0
- package/accounts/kernel/utils/plugins/ep0_6/getPluginsEnableTypedData.ts +76 -0
- package/accounts/kernel/utils/plugins/ep0_7/getEncodedPluginsData.ts +47 -0
- package/accounts/kernel/utils/plugins/ep0_7/getPluginsEnableTypedData.ts +63 -0
- package/accounts/kernel/utils/plugins/ep0_7/isPluginInitialized.ts +23 -0
- package/accounts/kernel/v1/createKernelV1Account.ts +21 -8
- package/accounts/kernel/v2/createKernelV2Account.ts +17 -6
- package/accounts/utils/getCustomNonceKeyFromString.ts +21 -0
- package/accounts/utils/index.ts +2 -0
- package/accounts/utils/toKernelPluginManager.ts +155 -224
- package/actions/account-client/getUserOperationGasPrice.ts +26 -0
- package/actions/index.ts +5 -0
- package/actions/paymaster/estimateGasInERC20.ts +2 -3
- package/actions/paymaster/sponsorUserOperation.ts +1 -3
- package/clients/decorators/kernel.ts +22 -6
- package/clients/kernelAccountClient.ts +36 -3
- package/clients/paymasterClient.ts +24 -1
- package/clients/utils.ts +28 -0
- package/constants.ts +6 -2
- package/index.ts +6 -1
- package/package.json +4 -4
- package/providers/KernelEIP1193Provider.ts +51 -0
- package/types/index.ts +4 -2
- package/types/kernel.ts +52 -38
- package/utils.ts +2 -3
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { getEntryPointVersion } from "permissionless"
|
|
2
2
|
import type { EntryPoint } from "permissionless/types/entrypoint"
|
|
3
3
|
import {
|
|
4
4
|
type Address,
|
|
@@ -8,25 +8,27 @@ import {
|
|
|
8
8
|
type Transport,
|
|
9
9
|
concat,
|
|
10
10
|
concatHex,
|
|
11
|
-
|
|
12
|
-
|
|
11
|
+
maxUint16,
|
|
12
|
+
maxUint192,
|
|
13
13
|
pad,
|
|
14
|
-
parseAbiParameters,
|
|
15
|
-
toFunctionSelector,
|
|
16
14
|
toHex,
|
|
17
15
|
zeroAddress
|
|
18
16
|
} from "viem"
|
|
19
|
-
import { getChainId
|
|
17
|
+
import { getChainId } from "viem/actions"
|
|
20
18
|
import { VALIDATOR_MODE, VALIDATOR_TYPE } from "../../constants.js"
|
|
21
19
|
import {
|
|
22
20
|
type KernelPluginManager,
|
|
23
21
|
type KernelPluginManagerParams,
|
|
24
22
|
ValidatorMode
|
|
25
23
|
} from "../../types/kernel.js"
|
|
26
|
-
import {
|
|
27
|
-
import {
|
|
28
|
-
import {
|
|
29
|
-
import {
|
|
24
|
+
import { getKernelV3Nonce } from "../kernel/utils/account/ep0_7/getKernelV3Nonce.js"
|
|
25
|
+
import { accountMetadata } from "../kernel/utils/common/accountMetadata.js"
|
|
26
|
+
import { getActionSelector } from "../kernel/utils/common/getActionSelector.js"
|
|
27
|
+
import { getEncodedPluginsData as getEncodedPluginsDataV1 } from "../kernel/utils/plugins/ep0_6/getEncodedPluginsData.js"
|
|
28
|
+
import { getPluginsEnableTypedData as getPluginsEnableTypedDataV1 } from "../kernel/utils/plugins/ep0_6/getPluginsEnableTypedData.js"
|
|
29
|
+
import { getEncodedPluginsData as getEncodedPluginsDataV2 } from "../kernel/utils/plugins/ep0_7/getEncodedPluginsData.js"
|
|
30
|
+
import { getPluginsEnableTypedData as getPluginsEnableTypedDataV2 } from "../kernel/utils/plugins/ep0_7/getPluginsEnableTypedData.js"
|
|
31
|
+
import { isPluginInitialized } from "../kernel/utils/plugins/ep0_7/isPluginInitialized.js"
|
|
30
32
|
|
|
31
33
|
export function isKernelPluginManager<entryPoint extends EntryPoint>(
|
|
32
34
|
// biome-ignore lint/suspicious/noExplicitAny: <explanation>
|
|
@@ -46,12 +48,7 @@ export async function toKernelPluginManager<
|
|
|
46
48
|
regular,
|
|
47
49
|
pluginEnableSignature,
|
|
48
50
|
validatorInitData,
|
|
49
|
-
|
|
50
|
-
executor: zeroAddress,
|
|
51
|
-
selector: toFunctionSelector(
|
|
52
|
-
"execute(address, uint256, bytes, uint8)"
|
|
53
|
-
)
|
|
54
|
-
},
|
|
51
|
+
action,
|
|
55
52
|
validAfter = 0,
|
|
56
53
|
validUntil = 0,
|
|
57
54
|
entryPoint: entryPointAddress,
|
|
@@ -64,36 +61,41 @@ export async function toKernelPluginManager<
|
|
|
64
61
|
if (!activeValidator) {
|
|
65
62
|
throw new Error("One of `sudo` or `regular` validator must be set")
|
|
66
63
|
}
|
|
67
|
-
|
|
64
|
+
action = {
|
|
65
|
+
selector: action?.selector ?? getActionSelector(entryPointVersion),
|
|
66
|
+
address: action?.address ?? zeroAddress
|
|
67
|
+
}
|
|
68
|
+
if (!action) {
|
|
69
|
+
throw new Error("Action data must be set")
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
const getSignatureData = async (
|
|
68
73
|
accountAddress: Address,
|
|
69
74
|
selector: Hex,
|
|
70
|
-
|
|
75
|
+
userOpSignature: Hex = "0x"
|
|
71
76
|
): Promise<Hex> => {
|
|
77
|
+
if (!action) {
|
|
78
|
+
throw new Error("Action data must be set")
|
|
79
|
+
}
|
|
72
80
|
if (entryPointVersion === "v0.6") {
|
|
73
81
|
if (regular) {
|
|
74
|
-
if (await
|
|
82
|
+
if (await isPluginEnabled(accountAddress, selector)) {
|
|
75
83
|
return ValidatorMode.plugin
|
|
76
84
|
}
|
|
77
85
|
|
|
78
86
|
const enableSignature =
|
|
79
87
|
await getPluginEnableSignature(accountAddress)
|
|
80
|
-
const enableData = await regular.getEnableData(accountAddress)
|
|
81
|
-
const enableDataLength = enableData.length / 2 - 1
|
|
82
88
|
if (!enableSignature) {
|
|
83
89
|
throw new Error("Enable signature not set")
|
|
84
90
|
}
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
enableData, // 88 - 88 + enableData.length
|
|
94
|
-
pad(toHex(enableSignature.length / 2 - 1), { size: 32 }), // 32 bytes 88 + enableData.length - 120 + enableData.length
|
|
95
|
-
enableSignature // 120 + enableData.length - 120 + enableData.length + enableSignature.length
|
|
96
|
-
])
|
|
91
|
+
return getEncodedPluginsDataV1({
|
|
92
|
+
accountAddress,
|
|
93
|
+
enableSignature,
|
|
94
|
+
action,
|
|
95
|
+
validator: regular,
|
|
96
|
+
validUntil,
|
|
97
|
+
validAfter
|
|
98
|
+
})
|
|
97
99
|
} else if (sudo) {
|
|
98
100
|
return ValidatorMode.sudo
|
|
99
101
|
} else {
|
|
@@ -103,60 +105,43 @@ export async function toKernelPluginManager<
|
|
|
103
105
|
}
|
|
104
106
|
}
|
|
105
107
|
if (regular) {
|
|
106
|
-
if (
|
|
107
|
-
|
|
108
|
-
(await regular.isEnabled(accountAddress, selector))
|
|
109
|
-
) {
|
|
110
|
-
return sig ?? "0x"
|
|
108
|
+
if (await isPluginEnabled(accountAddress, action.selector)) {
|
|
109
|
+
return userOpSignature
|
|
111
110
|
}
|
|
112
|
-
const enableData = await regular.getEnableData(accountAddress)
|
|
113
111
|
const enableSignature =
|
|
114
112
|
await getPluginEnableSignature(accountAddress)
|
|
115
|
-
return
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
enableData,
|
|
123
|
-
"0x",
|
|
124
|
-
concat([
|
|
125
|
-
executorData.selector,
|
|
126
|
-
executorData.executor,
|
|
127
|
-
zeroAddress,
|
|
128
|
-
"0x"
|
|
129
|
-
]),
|
|
130
|
-
enableSignature,
|
|
131
|
-
sig ?? "0x"
|
|
132
|
-
]
|
|
133
|
-
)
|
|
134
|
-
])
|
|
113
|
+
return getEncodedPluginsDataV2({
|
|
114
|
+
accountAddress,
|
|
115
|
+
action,
|
|
116
|
+
enableSignature,
|
|
117
|
+
userOpSignature,
|
|
118
|
+
validator: regular
|
|
119
|
+
})
|
|
135
120
|
} else if (sudo) {
|
|
136
|
-
return
|
|
121
|
+
return userOpSignature
|
|
137
122
|
} else {
|
|
138
123
|
throw new Error("One of `sudo` or `regular` validator must be set")
|
|
139
124
|
}
|
|
140
125
|
}
|
|
141
126
|
|
|
142
|
-
const
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
})
|
|
155
|
-
} catch (error) {}
|
|
156
|
-
return false
|
|
127
|
+
const isPluginEnabled = async (accountAddress: Address, selector: Hex) => {
|
|
128
|
+
if (!action) {
|
|
129
|
+
throw new Error("Action data must be set")
|
|
130
|
+
}
|
|
131
|
+
if (!regular) throw new Error("regular validator not set")
|
|
132
|
+
if (entryPointVersion === "v0.6") {
|
|
133
|
+
return regular.isEnabled(accountAddress, selector)
|
|
134
|
+
}
|
|
135
|
+
return (
|
|
136
|
+
(await regular.isEnabled(accountAddress, action.selector)) ||
|
|
137
|
+
(await isPluginInitialized(client, accountAddress, regular.address))
|
|
138
|
+
)
|
|
157
139
|
}
|
|
158
140
|
|
|
159
141
|
const getPluginEnableSignature = async (accountAddress: Address) => {
|
|
142
|
+
if (!action) {
|
|
143
|
+
throw new Error("Action data must be set")
|
|
144
|
+
}
|
|
160
145
|
if (pluginEnableSignature) return pluginEnableSignature
|
|
161
146
|
if (!sudo)
|
|
162
147
|
throw new Error(
|
|
@@ -164,153 +149,74 @@ export async function toKernelPluginManager<
|
|
|
164
149
|
)
|
|
165
150
|
if (!regular) throw new Error("regular validator not set")
|
|
166
151
|
|
|
167
|
-
const
|
|
152
|
+
const { version } = await accountMetadata(
|
|
168
153
|
client,
|
|
169
|
-
accountAddress
|
|
154
|
+
accountAddress,
|
|
155
|
+
entryPointAddress
|
|
170
156
|
)
|
|
171
|
-
const _kernelVersion =
|
|
172
|
-
kernelVersion ?? getKernelVersion(entryPointAddress, kernelImplAddr)
|
|
173
157
|
let ownerSig: Hex
|
|
174
158
|
if (entryPointVersion === "v0.6") {
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
ValidatorApproved: [
|
|
184
|
-
{ name: "sig", type: "bytes4" },
|
|
185
|
-
{ name: "validatorData", type: "uint256" },
|
|
186
|
-
{ name: "executor", type: "address" },
|
|
187
|
-
{ name: "enableData", type: "bytes" }
|
|
188
|
-
]
|
|
189
|
-
},
|
|
190
|
-
message: {
|
|
191
|
-
sig: executorData.selector,
|
|
192
|
-
validatorData: hexToBigInt(
|
|
193
|
-
concatHex([
|
|
194
|
-
pad(toHex(validUntil ?? 0), {
|
|
195
|
-
size: 6
|
|
196
|
-
}),
|
|
197
|
-
pad(toHex(validAfter ?? 0), {
|
|
198
|
-
size: 6
|
|
199
|
-
}),
|
|
200
|
-
regular.address
|
|
201
|
-
]),
|
|
202
|
-
{ size: 32 }
|
|
203
|
-
),
|
|
204
|
-
executor: executorData.executor as Address,
|
|
205
|
-
enableData: await regular.getEnableData(accountAddress)
|
|
206
|
-
},
|
|
207
|
-
primaryType: "ValidatorApproved"
|
|
159
|
+
const typeData = await getPluginsEnableTypedDataV1({
|
|
160
|
+
accountAddress,
|
|
161
|
+
chainId,
|
|
162
|
+
kernelVersion: kernelVersion ?? version,
|
|
163
|
+
action,
|
|
164
|
+
validator: regular,
|
|
165
|
+
validUntil,
|
|
166
|
+
validAfter
|
|
208
167
|
})
|
|
168
|
+
ownerSig = await sudo.signTypedData(typeData)
|
|
209
169
|
pluginEnableSignature = ownerSig
|
|
210
170
|
return ownerSig
|
|
211
171
|
}
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
Enable: [
|
|
221
|
-
{ name: "validationId", type: "bytes21" },
|
|
222
|
-
{ name: "nonce", type: "uint32" },
|
|
223
|
-
{ name: "hook", type: "address" },
|
|
224
|
-
{ name: "validatorData", type: "bytes" },
|
|
225
|
-
{ name: "hookData", type: "bytes" },
|
|
226
|
-
{ name: "selectorData", type: "bytes" }
|
|
227
|
-
]
|
|
228
|
-
},
|
|
229
|
-
message: {
|
|
230
|
-
validationId: concat([
|
|
231
|
-
activeValidator.isPermissionValidator
|
|
232
|
-
? VALIDATOR_TYPE.PERMISSION
|
|
233
|
-
: VALIDATOR_TYPE.SECONDARY,
|
|
234
|
-
activeValidator?.isPermissionValidator
|
|
235
|
-
? // @ts-ignore
|
|
236
|
-
pad(regular.getPermissionId() as Hex, {
|
|
237
|
-
size: 20,
|
|
238
|
-
dir: "right"
|
|
239
|
-
})
|
|
240
|
-
: activeValidator.address
|
|
241
|
-
]),
|
|
242
|
-
nonce: await getKernelV3Nonce(accountAddress),
|
|
243
|
-
hook: zeroAddress,
|
|
244
|
-
validatorData: await regular.getEnableData(accountAddress),
|
|
245
|
-
hookData: "0x",
|
|
246
|
-
selectorData: concat([
|
|
247
|
-
executorData.selector,
|
|
248
|
-
executorData.executor,
|
|
249
|
-
zeroAddress,
|
|
250
|
-
"0x"
|
|
251
|
-
])
|
|
252
|
-
},
|
|
253
|
-
primaryType: "Enable"
|
|
172
|
+
const validatorNonce = await getKernelV3Nonce(client, accountAddress)
|
|
173
|
+
const typedData = await getPluginsEnableTypedDataV2({
|
|
174
|
+
accountAddress,
|
|
175
|
+
chainId,
|
|
176
|
+
kernelVersion: version,
|
|
177
|
+
action,
|
|
178
|
+
validator: regular,
|
|
179
|
+
validatorNonce
|
|
254
180
|
})
|
|
181
|
+
ownerSig = await sudo.signTypedData(typedData)
|
|
255
182
|
|
|
256
183
|
return ownerSig
|
|
257
184
|
}
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
client,
|
|
265
|
-
readContract
|
|
266
|
-
)({
|
|
267
|
-
abi: KernelV3AccountAbi,
|
|
268
|
-
address: accountAddress,
|
|
269
|
-
functionName: "currentNonce",
|
|
270
|
-
args: []
|
|
271
|
-
})
|
|
272
|
-
return nonce
|
|
273
|
-
} catch (error) {
|
|
274
|
-
return 2
|
|
275
|
-
}
|
|
185
|
+
const getIdentifier = (isSudo = false) => {
|
|
186
|
+
const validator = (isSudo ? sudo : regular) ?? activeValidator
|
|
187
|
+
return concat([
|
|
188
|
+
VALIDATOR_TYPE[validator.validatorType],
|
|
189
|
+
validator.getIdentifier()
|
|
190
|
+
])
|
|
276
191
|
}
|
|
277
192
|
|
|
278
193
|
return {
|
|
279
194
|
...activeValidator,
|
|
280
|
-
|
|
281
|
-
const validator = (isSudo ? sudo : regular) ?? activeValidator
|
|
282
|
-
return concat([
|
|
283
|
-
validator.isPermissionValidator
|
|
284
|
-
? VALIDATOR_TYPE.PERMISSION
|
|
285
|
-
: VALIDATOR_TYPE.SECONDARY,
|
|
286
|
-
validator?.isPermissionValidator
|
|
287
|
-
? // @ts-ignore
|
|
288
|
-
pad(validator.getPermissionId() as Hex, {
|
|
289
|
-
size: 20,
|
|
290
|
-
dir: "right"
|
|
291
|
-
})
|
|
292
|
-
: validator.address
|
|
293
|
-
])
|
|
294
|
-
},
|
|
195
|
+
getIdentifier,
|
|
295
196
|
signUserOperation: async (userOperation) => {
|
|
296
197
|
const userOpSig =
|
|
297
198
|
await activeValidator.signUserOperation(userOperation)
|
|
298
199
|
if (entryPointVersion === "v0.6") {
|
|
299
200
|
return concatHex([
|
|
300
|
-
await
|
|
201
|
+
await getSignatureData(
|
|
301
202
|
userOperation.sender,
|
|
302
203
|
userOperation.callData.toString().slice(0, 10) as Hex
|
|
303
204
|
),
|
|
304
205
|
userOpSig
|
|
305
206
|
])
|
|
306
207
|
}
|
|
307
|
-
return await
|
|
208
|
+
return await getSignatureData(
|
|
308
209
|
userOperation.sender,
|
|
309
210
|
userOperation.callData.toString().slice(0, 10) as Hex,
|
|
310
211
|
userOpSig
|
|
311
212
|
)
|
|
312
213
|
},
|
|
313
|
-
|
|
214
|
+
getAction: () => {
|
|
215
|
+
if (!action) {
|
|
216
|
+
throw new Error("Action data must be set")
|
|
217
|
+
}
|
|
218
|
+
return action
|
|
219
|
+
},
|
|
314
220
|
getValidityData: () => ({
|
|
315
221
|
validAfter,
|
|
316
222
|
validUntil
|
|
@@ -320,53 +226,76 @@ export async function toKernelPluginManager<
|
|
|
320
226
|
await activeValidator.getDummySignature(userOperation)
|
|
321
227
|
if (entryPointVersion === "v0.6") {
|
|
322
228
|
return concatHex([
|
|
323
|
-
await
|
|
229
|
+
await getSignatureData(
|
|
324
230
|
userOperation.sender,
|
|
325
231
|
userOperation.callData.toString().slice(0, 10) as Hex
|
|
326
232
|
),
|
|
327
233
|
userOpSig
|
|
328
234
|
])
|
|
329
235
|
}
|
|
330
|
-
return await
|
|
236
|
+
return await getSignatureData(
|
|
331
237
|
userOperation.sender,
|
|
332
238
|
userOperation.callData.toString().slice(0, 10) as Hex,
|
|
333
239
|
userOpSig
|
|
334
240
|
)
|
|
335
241
|
},
|
|
336
|
-
getNonceKey: async (
|
|
337
|
-
|
|
338
|
-
|
|
242
|
+
getNonceKey: async (
|
|
243
|
+
accountAddress = zeroAddress,
|
|
244
|
+
customNonceKey = 0n
|
|
245
|
+
) => {
|
|
246
|
+
if (!action) {
|
|
247
|
+
throw new Error("Action data must be set")
|
|
248
|
+
}
|
|
249
|
+
if (entryPointVersion === "v0.6") {
|
|
250
|
+
if (customNonceKey > maxUint192) {
|
|
251
|
+
throw new Error(
|
|
252
|
+
"Custom nonce key must be equal or less than maxUint192 for v0.6"
|
|
253
|
+
)
|
|
254
|
+
}
|
|
339
255
|
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
? VALIDATOR_MODE.DEFAULT
|
|
350
|
-
: VALIDATOR_MODE.ENABLE, // 1 byte
|
|
351
|
-
regular
|
|
352
|
-
? regular.isPermissionValidator
|
|
353
|
-
? VALIDATOR_TYPE.PERMISSION
|
|
354
|
-
: VALIDATOR_TYPE.SECONDARY
|
|
355
|
-
: VALIDATOR_TYPE.SUDO, // 1 byte
|
|
356
|
-
regular?.isPermissionValidator
|
|
357
|
-
? // @ts-ignore
|
|
358
|
-
pad(regular.getPermissionId(), {
|
|
359
|
-
size: 20,
|
|
360
|
-
dir: "right"
|
|
361
|
-
})
|
|
362
|
-
: activeValidator.address, // 20 bytes
|
|
363
|
-
pad(toHex(await activeValidator.getNonceKey()), {
|
|
364
|
-
size: 2
|
|
365
|
-
}) // 10 byte
|
|
366
|
-
]),
|
|
367
|
-
{ size: 24 }
|
|
256
|
+
return await activeValidator.getNonceKey(
|
|
257
|
+
accountAddress,
|
|
258
|
+
customNonceKey
|
|
259
|
+
)
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
if (customNonceKey > maxUint16)
|
|
263
|
+
throw new Error(
|
|
264
|
+
"Custom nonce key must be equal or less than 2 bytes(maxUint16) for v0.7"
|
|
368
265
|
)
|
|
266
|
+
|
|
267
|
+
const validatorMode =
|
|
268
|
+
!regular ||
|
|
269
|
+
(await isPluginEnabled(accountAddress, action.selector))
|
|
270
|
+
? VALIDATOR_MODE.DEFAULT
|
|
271
|
+
: VALIDATOR_MODE.ENABLE
|
|
272
|
+
const validatorType = regular
|
|
273
|
+
? VALIDATOR_TYPE[regular.validatorType]
|
|
274
|
+
: VALIDATOR_TYPE.SUDO
|
|
275
|
+
const encoding = pad(
|
|
276
|
+
concatHex([
|
|
277
|
+
validatorMode, // 1 byte
|
|
278
|
+
validatorType, // 1 byte
|
|
279
|
+
pad(activeValidator.getIdentifier(), {
|
|
280
|
+
size: 20,
|
|
281
|
+
dir: "right"
|
|
282
|
+
}), // 20 bytes
|
|
283
|
+
pad(
|
|
284
|
+
toHex(
|
|
285
|
+
await activeValidator.getNonceKey(
|
|
286
|
+
accountAddress,
|
|
287
|
+
customNonceKey
|
|
288
|
+
)
|
|
289
|
+
),
|
|
290
|
+
{
|
|
291
|
+
size: 2
|
|
292
|
+
}
|
|
293
|
+
) // 2 byte
|
|
294
|
+
]),
|
|
295
|
+
{ size: 24 }
|
|
369
296
|
)
|
|
297
|
+
const encodedNonceKey = BigInt(encoding)
|
|
298
|
+
return encodedNonceKey
|
|
370
299
|
},
|
|
371
300
|
getPluginEnableSignature,
|
|
372
301
|
getValidatorInitData: async () => {
|
|
@@ -376,7 +305,9 @@ export async function toKernelPluginManager<
|
|
|
376
305
|
|
|
377
306
|
enableData:
|
|
378
307
|
(await sudo?.getEnableData()) ??
|
|
379
|
-
(await activeValidator.getEnableData())
|
|
308
|
+
(await activeValidator.getEnableData()),
|
|
309
|
+
|
|
310
|
+
identifier: pad(getIdentifier(true), { size: 21, dir: "right" })
|
|
380
311
|
}
|
|
381
312
|
}
|
|
382
313
|
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import type { Account, Chain, Client, Transport } from "viem"
|
|
2
|
+
import type { Prettify } from "viem/chains"
|
|
3
|
+
import type { ZeroDevAccountClientRpcSchema } from "../../types/kernel.js"
|
|
4
|
+
|
|
5
|
+
export type GetUserOperationGasPriceReturnType = {
|
|
6
|
+
maxFeePerGas: bigint
|
|
7
|
+
maxPriorityFeePerGas: bigint
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export const getUserOperationGasPrice = async <
|
|
11
|
+
TTransport extends Transport = Transport,
|
|
12
|
+
TChain extends Chain | undefined = Chain | undefined,
|
|
13
|
+
TAccount extends Account | undefined = Account | undefined
|
|
14
|
+
>(
|
|
15
|
+
client: Client<TTransport, TChain, TAccount, ZeroDevAccountClientRpcSchema>
|
|
16
|
+
): Promise<Prettify<GetUserOperationGasPriceReturnType>> => {
|
|
17
|
+
const gasPrice = await client.request({
|
|
18
|
+
method: "zd_getUserOperationGasPrice",
|
|
19
|
+
params: []
|
|
20
|
+
})
|
|
21
|
+
|
|
22
|
+
return {
|
|
23
|
+
maxFeePerGas: BigInt(gasPrice.standard.maxFeePerGas),
|
|
24
|
+
maxPriorityFeePerGas: BigInt(gasPrice.standard.maxPriorityFeePerGas)
|
|
25
|
+
}
|
|
26
|
+
}
|
package/actions/index.ts
CHANGED
|
@@ -10,6 +10,11 @@ export {
|
|
|
10
10
|
type SignUserOperationReturnType
|
|
11
11
|
} from "./account-client/signUserOperation.js"
|
|
12
12
|
|
|
13
|
+
export {
|
|
14
|
+
getUserOperationGasPrice,
|
|
15
|
+
type GetUserOperationGasPriceReturnType
|
|
16
|
+
} from "./account-client/getUserOperationGasPrice.js"
|
|
17
|
+
|
|
13
18
|
export {
|
|
14
19
|
estimateGasInERC20,
|
|
15
20
|
type EstimateGasInERC20Parameters,
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { ENTRYPOINT_ADDRESS_V06 } from "permissionless"
|
|
1
2
|
import type { EntryPoint } from "permissionless/types"
|
|
2
3
|
import type {
|
|
3
4
|
UserOperation,
|
|
@@ -5,7 +6,6 @@ import type {
|
|
|
5
6
|
} from "permissionless/types/userOperation.js"
|
|
6
7
|
import { deepHexlify } from "permissionless/utils"
|
|
7
8
|
import type { Address, Hex } from "viem"
|
|
8
|
-
import { KERNEL_ADDRESSES } from "../../accounts/index.js"
|
|
9
9
|
import type { ZeroDevPaymasterClient } from "../../clients/paymasterClient.js"
|
|
10
10
|
|
|
11
11
|
export type EstimateGasInERC20Parameters = {
|
|
@@ -40,8 +40,7 @@ export const estimateGasInERC20 = async <entryPoint extends EntryPoint>(
|
|
|
40
40
|
args.userOperation
|
|
41
41
|
) as UserOperationWithBigIntAsHex<"v0.6">,
|
|
42
42
|
tokenAddress: args.gasTokenAddress,
|
|
43
|
-
entryPointAddress:
|
|
44
|
-
args.entryPoint ?? KERNEL_ADDRESSES.ENTRYPOINT_V0_6
|
|
43
|
+
entryPointAddress: args.entryPoint ?? ENTRYPOINT_ADDRESS_V06
|
|
45
44
|
}
|
|
46
45
|
]
|
|
47
46
|
})
|
|
@@ -10,7 +10,6 @@ import type {
|
|
|
10
10
|
import { ENTRYPOINT_ADDRESS_V06, deepHexlify } from "permissionless/utils"
|
|
11
11
|
import type { Address, Hex } from "viem"
|
|
12
12
|
import type { PartialBy } from "viem/types/utils"
|
|
13
|
-
import { KERNEL_ADDRESSES } from "../../accounts/index.js"
|
|
14
13
|
import type { ZeroDevPaymasterClient } from "../../clients/paymasterClient.js"
|
|
15
14
|
|
|
16
15
|
export type SponsorUserOperationParameters<entryPoint extends EntryPoint> = {
|
|
@@ -70,8 +69,7 @@ export const sponsorUserOperation = async <entryPoint extends EntryPoint>(
|
|
|
70
69
|
) as UserOperationWithBigIntAsHex<
|
|
71
70
|
GetEntryPointVersion<entryPoint>
|
|
72
71
|
>,
|
|
73
|
-
entryPointAddress:
|
|
74
|
-
args.entryPoint ?? KERNEL_ADDRESSES.ENTRYPOINT_V0_6,
|
|
72
|
+
entryPointAddress: args.entryPoint,
|
|
75
73
|
gasTokenData: args.gasToken && {
|
|
76
74
|
tokenAddress: args.gasToken
|
|
77
75
|
},
|
|
@@ -1,8 +1,12 @@
|
|
|
1
1
|
import { type SmartAccountActions, smartAccountActions } from "permissionless"
|
|
2
2
|
import type { SmartAccount } from "permissionless/accounts/types"
|
|
3
3
|
import { type Middleware } from "permissionless/actions/smartAccount"
|
|
4
|
-
import type { EntryPoint } from "permissionless/types"
|
|
4
|
+
import type { EntryPoint, Prettify } from "permissionless/types"
|
|
5
5
|
import type { Chain, Client, Transport } from "viem"
|
|
6
|
+
import {
|
|
7
|
+
type GetUserOperationGasPriceReturnType,
|
|
8
|
+
getUserOperationGasPrice
|
|
9
|
+
} from "../../actions/account-client/getUserOperationGasPrice.js"
|
|
6
10
|
import type {
|
|
7
11
|
SignUserOperationParameters,
|
|
8
12
|
SignUserOperationReturnType
|
|
@@ -38,10 +42,13 @@ export const zerodevPaymasterActions =
|
|
|
38
42
|
sponsorUserOperation: async (
|
|
39
43
|
args: Omit<SponsorUserOperationParameters<entryPoint>, "entryPoint">
|
|
40
44
|
) =>
|
|
41
|
-
sponsorUserOperation
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
+
sponsorUserOperation<entryPoint>(
|
|
46
|
+
client as ZeroDevPaymasterClient<entryPoint>,
|
|
47
|
+
{
|
|
48
|
+
...args,
|
|
49
|
+
entryPoint: entryPointAddress
|
|
50
|
+
}
|
|
51
|
+
),
|
|
45
52
|
estimateGasInERC20: async (args: EstimateGasInERC20Parameters) =>
|
|
46
53
|
estimateGasInERC20(
|
|
47
54
|
client as ZeroDevPaymasterClient<entryPoint>,
|
|
@@ -72,6 +79,14 @@ export type KernelAccountClientActions<
|
|
|
72
79
|
>
|
|
73
80
|
>[1]
|
|
74
81
|
) => Promise<SignUserOperationReturnType>
|
|
82
|
+
/**
|
|
83
|
+
* Returns the live gas prices that you can use to send a user operation.
|
|
84
|
+
*
|
|
85
|
+
* @returns maxFeePerGas & maxPriorityFeePerGas {@link GetUserOperationGasPriceReturnType}
|
|
86
|
+
*/
|
|
87
|
+
getUserOperationGasPrice: () => Promise<
|
|
88
|
+
Prettify<GetUserOperationGasPriceReturnType>
|
|
89
|
+
>
|
|
75
90
|
}
|
|
76
91
|
|
|
77
92
|
export const kernelAccountClientActions =
|
|
@@ -93,5 +108,6 @@ export const kernelAccountClientActions =
|
|
|
93
108
|
...args,
|
|
94
109
|
middleware
|
|
95
110
|
} as SignUserOperationParameters<entryPoint, TSmartAccount>
|
|
96
|
-
)
|
|
111
|
+
),
|
|
112
|
+
getUserOperationGasPrice: async () => getUserOperationGasPrice(client)
|
|
97
113
|
})
|