@zerodev/sdk 5.4.0-beta.1 → 5.4.0-beta.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/_cjs/accounts/kernel/createKernelAccount.js.map +1 -1
- package/_cjs/actions/paymaster/sponsorUserOperation.js +19 -9
- package/_cjs/actions/paymaster/sponsorUserOperation.js.map +1 -1
- package/_cjs/clients/decorators/kernel.js +2 -3
- package/_cjs/clients/decorators/kernel.js.map +1 -1
- package/_cjs/clients/paymasterClient.js +2 -5
- package/_cjs/clients/paymasterClient.js.map +1 -1
- package/_cjs/constants.js +14 -1
- package/_cjs/constants.js.map +1 -1
- package/_cjs/index.js +1 -0
- package/_cjs/index.js.map +1 -1
- package/_cjs/types/index.js.map +1 -1
- package/_cjs/types/kernel.js.map +1 -1
- package/_cjs/types/utils.js +3 -0
- package/_cjs/types/utils.js.map +1 -0
- package/_cjs/utils/index.js +5 -0
- package/_cjs/utils/index.js.map +1 -0
- package/_cjs/utils/toSigner.js +58 -0
- package/_cjs/utils/toSigner.js.map +1 -0
- package/_esm/accounts/kernel/createKernelAccount.js.map +1 -1
- package/_esm/actions/paymaster/sponsorUserOperation.js +23 -9
- package/_esm/actions/paymaster/sponsorUserOperation.js.map +1 -1
- package/_esm/clients/decorators/kernel.js +2 -3
- package/_esm/clients/decorators/kernel.js.map +1 -1
- package/_esm/clients/paymasterClient.js +3 -6
- package/_esm/clients/paymasterClient.js.map +1 -1
- package/_esm/constants.js +12 -0
- package/_esm/constants.js.map +1 -1
- package/_esm/index.js +1 -0
- package/_esm/index.js.map +1 -1
- package/_esm/types/index.js.map +1 -1
- package/_esm/types/kernel.js.map +1 -1
- package/_esm/types/utils.js +2 -0
- package/_esm/types/utils.js.map +1 -0
- package/_esm/utils/index.js +2 -0
- package/_esm/utils/index.js.map +1 -0
- package/_esm/utils/toSigner.js +56 -0
- package/_esm/utils/toSigner.js.map +1 -0
- package/_types/accounts/kernel/createKernelAccount.d.ts +2 -5
- package/_types/accounts/kernel/createKernelAccount.d.ts.map +1 -1
- package/_types/actions/paymaster/estimateGasInERC20.d.ts +4 -2
- package/_types/actions/paymaster/estimateGasInERC20.d.ts.map +1 -1
- package/_types/actions/paymaster/sponsorUserOperation.d.ts +24 -22
- package/_types/actions/paymaster/sponsorUserOperation.d.ts.map +1 -1
- package/_types/clients/decorators/kernel.d.ts +6 -21
- package/_types/clients/decorators/kernel.d.ts.map +1 -1
- package/_types/clients/paymasterClient.d.ts +5 -7
- package/_types/clients/paymasterClient.d.ts.map +1 -1
- package/_types/constants.d.ts +3 -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/types/index.d.ts +2 -1
- package/_types/types/index.d.ts.map +1 -1
- package/_types/types/kernel.d.ts +5 -4
- package/_types/types/kernel.d.ts.map +1 -1
- package/_types/types/utils.d.ts +3 -0
- package/_types/types/utils.d.ts.map +1 -0
- package/_types/utils/index.d.ts +2 -0
- package/_types/utils/index.d.ts.map +1 -0
- package/_types/utils/toSigner.d.ts +7 -0
- package/_types/utils/toSigner.d.ts.map +1 -0
- package/_types/utils.d.ts +6 -7
- package/_types/utils.d.ts.map +1 -1
- package/accounts/kernel/createKernelAccount.ts +2 -4
- package/actions/paymaster/sponsorUserOperation.ts +50 -68
- package/clients/decorators/kernel.ts +7 -19
- package/clients/paymasterClient.ts +11 -16
- package/constants.ts +20 -0
- package/index.ts +1 -0
- package/package.json +1 -1
- package/types/index.ts +4 -1
- package/types/kernel.ts +6 -4
- package/types/utils.ts +15 -0
- package/utils/index.ts +1 -0
- package/utils/toSigner.ts +106 -0
- package/utils.ts +2 -2
|
@@ -34,6 +34,7 @@ import {
|
|
|
34
34
|
import { KernelVersionToAddressesMap } from "../../constants.js"
|
|
35
35
|
import type {
|
|
36
36
|
CallType,
|
|
37
|
+
EntryPointType,
|
|
37
38
|
GetEntryPointAbi,
|
|
38
39
|
GetKernelVersion,
|
|
39
40
|
KernelPluginManager,
|
|
@@ -96,10 +97,7 @@ export type CreateKernelAccountParameters<
|
|
|
96
97
|
"entryPoint" | "kernelVersion"
|
|
97
98
|
>
|
|
98
99
|
| KernelPluginManager<entryPointVersion>
|
|
99
|
-
entryPoint:
|
|
100
|
-
address: Address
|
|
101
|
-
version: entryPointVersion
|
|
102
|
-
}
|
|
100
|
+
entryPoint: EntryPointType<entryPointVersion>
|
|
103
101
|
index?: bigint
|
|
104
102
|
factoryAddress?: Address
|
|
105
103
|
accountImplementationAddress?: Address
|
|
@@ -1,63 +1,29 @@
|
|
|
1
|
-
import type
|
|
2
|
-
import
|
|
3
|
-
|
|
1
|
+
import { type Address, type Hex, type Prettify, isAddressEqual } from "viem"
|
|
2
|
+
import {
|
|
3
|
+
type EntryPointVersion,
|
|
4
|
+
type GetPaymasterDataParameters,
|
|
5
|
+
type GetPaymasterStubDataReturnType,
|
|
6
|
+
entryPoint06Address
|
|
7
|
+
} from "viem/account-abstraction"
|
|
4
8
|
import type { ZeroDevPaymasterClient } from "../../clients/paymasterClient.js"
|
|
5
|
-
import type { PartialPick } from "../../types/index.js"
|
|
6
9
|
import { deepHexlify } from "../../utils.js"
|
|
7
10
|
|
|
8
|
-
export type SponsorUserOperationParameters
|
|
9
|
-
|
|
10
|
-
> = {
|
|
11
|
-
userOperation: entryPointVersion extends "0.6"
|
|
12
|
-
? PartialBy<
|
|
13
|
-
UserOperation<"0.6">,
|
|
14
|
-
"callGasLimit" | "preVerificationGas" | "verificationGasLimit"
|
|
15
|
-
>
|
|
16
|
-
: PartialBy<
|
|
17
|
-
UserOperation<"0.7">,
|
|
18
|
-
| "callGasLimit"
|
|
19
|
-
| "preVerificationGas"
|
|
20
|
-
| "verificationGasLimit"
|
|
21
|
-
| "paymasterVerificationGasLimit"
|
|
22
|
-
| "paymasterPostOpGasLimit"
|
|
23
|
-
>
|
|
24
|
-
entryPoint: {
|
|
25
|
-
address: Address
|
|
26
|
-
version: entryPointVersion
|
|
27
|
-
}
|
|
11
|
+
export type SponsorUserOperationParameters = {
|
|
12
|
+
userOperation: GetPaymasterDataParameters
|
|
28
13
|
gasToken?: Hex
|
|
29
14
|
shouldOverrideFee?: boolean
|
|
30
15
|
shouldConsume?: boolean
|
|
31
16
|
}
|
|
32
17
|
|
|
33
|
-
export type SponsorUserOperationReturnType<
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
> &
|
|
43
|
-
PartialPick<
|
|
44
|
-
UserOperation<"0.6">,
|
|
45
|
-
"maxFeePerGas" | "maxPriorityFeePerGas"
|
|
46
|
-
>
|
|
47
|
-
: Pick<
|
|
48
|
-
UserOperation<"0.7">,
|
|
49
|
-
| "callGasLimit"
|
|
50
|
-
| "verificationGasLimit"
|
|
51
|
-
| "preVerificationGas"
|
|
52
|
-
| "paymaster"
|
|
53
|
-
| "paymasterVerificationGasLimit"
|
|
54
|
-
| "paymasterPostOpGasLimit"
|
|
55
|
-
| "paymasterData"
|
|
56
|
-
> &
|
|
57
|
-
PartialPick<
|
|
58
|
-
UserOperation<"0.7">,
|
|
59
|
-
"maxFeePerGas" | "maxPriorityFeePerGas"
|
|
60
|
-
>
|
|
18
|
+
export type SponsorUserOperationReturnType = Prettify<
|
|
19
|
+
GetPaymasterStubDataReturnType & {
|
|
20
|
+
maxFeePerGas?: bigint | undefined
|
|
21
|
+
maxPriorityFeePerGas?: bigint | undefined
|
|
22
|
+
callGasLimit?: bigint | undefined
|
|
23
|
+
verificationGasLimit?: bigint | undefined
|
|
24
|
+
preVerificationGas?: bigint | undefined
|
|
25
|
+
}
|
|
26
|
+
>
|
|
61
27
|
|
|
62
28
|
/**
|
|
63
29
|
* Returns paymasterAndData & updated gas parameters required to sponsor a userOperation.
|
|
@@ -66,15 +32,28 @@ export const sponsorUserOperation = async <
|
|
|
66
32
|
entryPointVersion extends EntryPointVersion
|
|
67
33
|
>(
|
|
68
34
|
client: ZeroDevPaymasterClient<entryPointVersion>,
|
|
69
|
-
args: SponsorUserOperationParameters
|
|
70
|
-
): Promise<SponsorUserOperationReturnType
|
|
35
|
+
args: SponsorUserOperationParameters
|
|
36
|
+
): Promise<SponsorUserOperationReturnType> => {
|
|
37
|
+
console.log({ args })
|
|
38
|
+
const {
|
|
39
|
+
userOperation: {
|
|
40
|
+
chainId,
|
|
41
|
+
entryPointAddress,
|
|
42
|
+
context,
|
|
43
|
+
// @ts-ignore
|
|
44
|
+
calls,
|
|
45
|
+
// @ts-ignore
|
|
46
|
+
account,
|
|
47
|
+
..._userOperation
|
|
48
|
+
}
|
|
49
|
+
} = args
|
|
71
50
|
const response = await client.request({
|
|
72
51
|
method: "zd_sponsorUserOperation",
|
|
73
52
|
params: [
|
|
74
53
|
{
|
|
75
54
|
chainId: client.chain?.id as number,
|
|
76
|
-
userOp: deepHexlify(
|
|
77
|
-
entryPointAddress:
|
|
55
|
+
userOp: deepHexlify(_userOperation),
|
|
56
|
+
entryPointAddress: entryPointAddress,
|
|
78
57
|
gasTokenData: args.gasToken && {
|
|
79
58
|
tokenAddress: args.gasToken
|
|
80
59
|
},
|
|
@@ -83,18 +62,19 @@ export const sponsorUserOperation = async <
|
|
|
83
62
|
}
|
|
84
63
|
]
|
|
85
64
|
})
|
|
86
|
-
if (
|
|
65
|
+
if (isAddressEqual(entryPointAddress, entryPoint06Address)) {
|
|
87
66
|
return {
|
|
88
67
|
paymasterAndData: response.paymasterAndData,
|
|
89
68
|
preVerificationGas: BigInt(response.preVerificationGas),
|
|
90
69
|
verificationGasLimit: BigInt(response.verificationGasLimit),
|
|
91
70
|
callGasLimit: BigInt(response.callGasLimit),
|
|
92
|
-
maxFeePerGas:
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
BigInt(response.maxPriorityFeePerGas)
|
|
97
|
-
|
|
71
|
+
maxFeePerGas: response.maxFeePerGas
|
|
72
|
+
? BigInt(response.maxFeePerGas)
|
|
73
|
+
: args.userOperation.maxFeePerGas,
|
|
74
|
+
maxPriorityFeePerGas: response.maxPriorityFeePerGas
|
|
75
|
+
? BigInt(response.maxPriorityFeePerGas)
|
|
76
|
+
: args.userOperation.maxPriorityFeePerGas
|
|
77
|
+
} as SponsorUserOperationReturnType
|
|
98
78
|
}
|
|
99
79
|
const responseV07 = response as {
|
|
100
80
|
preVerificationGas: Hex
|
|
@@ -119,9 +99,11 @@ export const sponsorUserOperation = async <
|
|
|
119
99
|
),
|
|
120
100
|
paymasterPostOpGasLimit: BigInt(responseV07.paymasterPostOpGasLimit),
|
|
121
101
|
paymasterData: responseV07.paymasterData,
|
|
122
|
-
maxFeePerGas: response.maxFeePerGas
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
102
|
+
maxFeePerGas: response.maxFeePerGas
|
|
103
|
+
? BigInt(response.maxFeePerGas)
|
|
104
|
+
: args.userOperation.maxFeePerGas,
|
|
105
|
+
maxPriorityFeePerGas: response.maxPriorityFeePerGas
|
|
106
|
+
? BigInt(response.maxPriorityFeePerGas)
|
|
107
|
+
: args.userOperation.maxPriorityFeePerGas
|
|
108
|
+
} as SponsorUserOperationReturnType
|
|
127
109
|
}
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import type {
|
|
2
2
|
Abi,
|
|
3
|
-
Address,
|
|
4
3
|
Chain,
|
|
5
4
|
Client,
|
|
6
5
|
ContractFunctionArgs,
|
|
@@ -47,37 +46,26 @@ import {
|
|
|
47
46
|
} from "../../actions/paymaster/sponsorUserOperation.js"
|
|
48
47
|
import type { ZeroDevPaymasterClient } from "../paymasterClient.js"
|
|
49
48
|
|
|
50
|
-
export type ZeroDevPaymasterClientActions
|
|
51
|
-
entryPointVersion extends EntryPointVersion
|
|
52
|
-
> = {
|
|
49
|
+
export type ZeroDevPaymasterClientActions = {
|
|
53
50
|
/**
|
|
54
51
|
* Returns paymasterAndData & updated gas parameters required to sponsor a userOperation.
|
|
55
52
|
*/
|
|
56
53
|
sponsorUserOperation: (
|
|
57
|
-
args: SponsorUserOperationParameters
|
|
58
|
-
) => Promise<SponsorUserOperationReturnType
|
|
54
|
+
args: SponsorUserOperationParameters
|
|
55
|
+
) => Promise<SponsorUserOperationReturnType>
|
|
59
56
|
estimateGasInERC20: (
|
|
60
57
|
args: EstimateGasInERC20Parameters
|
|
61
58
|
) => Promise<EstimateGasInERC20ReturnType>
|
|
62
59
|
}
|
|
63
60
|
|
|
64
61
|
export const zerodevPaymasterActions =
|
|
65
|
-
<entryPointVersion extends EntryPointVersion>(
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
}) =>
|
|
69
|
-
(client: Client): ZeroDevPaymasterClientActions<entryPointVersion> => ({
|
|
70
|
-
sponsorUserOperation: async (
|
|
71
|
-
args: Omit<
|
|
72
|
-
SponsorUserOperationParameters<entryPointVersion>,
|
|
73
|
-
"entryPoint"
|
|
74
|
-
>
|
|
75
|
-
) =>
|
|
62
|
+
<entryPointVersion extends EntryPointVersion>() =>
|
|
63
|
+
(client: Client): ZeroDevPaymasterClientActions => ({
|
|
64
|
+
sponsorUserOperation: async (args: SponsorUserOperationParameters) =>
|
|
76
65
|
sponsorUserOperation(
|
|
77
66
|
client as ZeroDevPaymasterClient<entryPointVersion>,
|
|
78
67
|
{
|
|
79
|
-
...args
|
|
80
|
-
entryPoint
|
|
68
|
+
...args
|
|
81
69
|
}
|
|
82
70
|
),
|
|
83
71
|
estimateGasInERC20: async (args: EstimateGasInERC20Parameters) =>
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import {
|
|
2
|
-
type Address,
|
|
3
2
|
type Chain,
|
|
4
3
|
type Client,
|
|
5
4
|
type ClientConfig,
|
|
@@ -12,11 +11,16 @@ import {
|
|
|
12
11
|
import {
|
|
13
12
|
type PaymasterActions,
|
|
14
13
|
type SmartAccount,
|
|
15
|
-
entryPoint07Address,
|
|
16
14
|
paymasterActions
|
|
17
15
|
} from "viem/account-abstraction"
|
|
18
|
-
import type {
|
|
19
|
-
|
|
16
|
+
import type {
|
|
17
|
+
EntryPointType,
|
|
18
|
+
ZeroDevPaymasterRpcSchema
|
|
19
|
+
} from "../types/kernel.js"
|
|
20
|
+
import {
|
|
21
|
+
type ZeroDevPaymasterClientActions,
|
|
22
|
+
zerodevPaymasterActions
|
|
23
|
+
} from "./decorators/kernel.js"
|
|
20
24
|
|
|
21
25
|
export type ZeroDevPaymasterClient<
|
|
22
26
|
entryPointVersion extends "0.6" | "0.7" = "0.7",
|
|
@@ -38,7 +42,7 @@ export type ZeroDevPaymasterClient<
|
|
|
38
42
|
rpcSchema extends RpcSchema
|
|
39
43
|
? [...ZeroDevPaymasterRpcSchema<entryPointVersion>, ...rpcSchema]
|
|
40
44
|
: ZeroDevPaymasterRpcSchema<entryPointVersion>,
|
|
41
|
-
PaymasterActions
|
|
45
|
+
PaymasterActions & ZeroDevPaymasterClientActions
|
|
42
46
|
>
|
|
43
47
|
>
|
|
44
48
|
|
|
@@ -61,10 +65,7 @@ export type ZeroDevPaymasterClientConfig<
|
|
|
61
65
|
| "transport"
|
|
62
66
|
>
|
|
63
67
|
> & {
|
|
64
|
-
entryPoint?:
|
|
65
|
-
address: Address
|
|
66
|
-
version: entryPointVersion
|
|
67
|
-
}
|
|
68
|
+
entryPoint?: EntryPointType<entryPointVersion>
|
|
68
69
|
}
|
|
69
70
|
/**
|
|
70
71
|
* Creates a ZeroDev-specific Paymaster Client with a given [Transport](https://viem.sh/docs/clients/intro.html) configured for a [Chain](https://viem.sh/docs/clients/chains.html).
|
|
@@ -89,7 +90,6 @@ export const createZeroDevPaymasterClient = (
|
|
|
89
90
|
const {
|
|
90
91
|
key = "public",
|
|
91
92
|
name = "ZeroDev Paymaster Client",
|
|
92
|
-
entryPoint,
|
|
93
93
|
transport
|
|
94
94
|
} = parameters
|
|
95
95
|
const client = createClient({
|
|
@@ -104,10 +104,5 @@ export const createZeroDevPaymasterClient = (
|
|
|
104
104
|
name,
|
|
105
105
|
type: "zerodevPaymasterClient"
|
|
106
106
|
})
|
|
107
|
-
return client.extend(paymasterActions).extend(
|
|
108
|
-
zerodevPaymasterActions({
|
|
109
|
-
address: entryPoint?.address ?? entryPoint07Address,
|
|
110
|
-
version: entryPoint?.version ?? "0.7"
|
|
111
|
-
})
|
|
112
|
-
)
|
|
107
|
+
return client.extend(paymasterActions).extend(zerodevPaymasterActions())
|
|
113
108
|
}
|
package/constants.ts
CHANGED
|
@@ -1,5 +1,11 @@
|
|
|
1
1
|
import { type Address, type Hex, zeroAddress } from "viem"
|
|
2
|
+
import {
|
|
3
|
+
type EntryPointVersion,
|
|
4
|
+
entryPoint06Address,
|
|
5
|
+
entryPoint07Address
|
|
6
|
+
} from "viem/account-abstraction"
|
|
2
7
|
import type {
|
|
8
|
+
EntryPointType,
|
|
3
9
|
KERNEL_V2_VERSION_TYPE,
|
|
4
10
|
KERNEL_V3_VERSION_TYPE,
|
|
5
11
|
KERNEL_VERSION_TYPE
|
|
@@ -112,3 +118,17 @@ export const KernelFactoryToInitCodeHashMap: { [key: Address]: Hex } = {
|
|
|
112
118
|
"0x6723b44Abeec4E71eBE3232BD5B455805baDD22f":
|
|
113
119
|
"0x6fe6e6ea30eddce942b9618033ab8429f9ddac594053bec8a6744fffc71976e2"
|
|
114
120
|
}
|
|
121
|
+
|
|
122
|
+
export const getEntryPoint = <TEntryPointVersion extends EntryPointVersion>(
|
|
123
|
+
entryPointVersion: TEntryPointVersion
|
|
124
|
+
): EntryPointType<TEntryPointVersion> => {
|
|
125
|
+
if (entryPointVersion === "0.6")
|
|
126
|
+
return {
|
|
127
|
+
address: entryPoint06Address,
|
|
128
|
+
version: entryPointVersion
|
|
129
|
+
}
|
|
130
|
+
return {
|
|
131
|
+
address: entryPoint07Address,
|
|
132
|
+
version: entryPointVersion
|
|
133
|
+
}
|
|
134
|
+
}
|
package/index.ts
CHANGED
|
@@ -67,3 +67,4 @@ export { isProviderSet, setPimlicoAsProvider } from "./clients/utils.js"
|
|
|
67
67
|
export { getUserOperationGasPrice } from "./actions/account-client/getUserOperationGasPrice.js"
|
|
68
68
|
export { isPluginInitialized } from "./accounts/kernel/utils/plugins/ep0_7/isPluginInitialized.js"
|
|
69
69
|
export * from "./errors/index.js"
|
|
70
|
+
export * from "./utils/index.js"
|
package/package.json
CHANGED
package/types/index.ts
CHANGED
|
@@ -13,11 +13,14 @@ export type {
|
|
|
13
13
|
KERNEL_V3_VERSION_TYPE,
|
|
14
14
|
KERNEL_VERSION_TYPE,
|
|
15
15
|
GetKernelVersion,
|
|
16
|
-
GetEntryPointAbi
|
|
16
|
+
GetEntryPointAbi,
|
|
17
|
+
EntryPointType
|
|
17
18
|
} from "./kernel.js"
|
|
18
19
|
|
|
19
20
|
export { ValidatorMode } from "./kernel.js"
|
|
20
21
|
|
|
22
|
+
export type { Signer } from "./utils.js"
|
|
23
|
+
|
|
21
24
|
export type WithRequired<T, K extends keyof T> = Required<Pick<T, K>>
|
|
22
25
|
|
|
23
26
|
export type PartialPick<T, K extends keyof T> = Partial<Pick<T, K>>
|
package/types/kernel.ts
CHANGED
|
@@ -195,10 +195,7 @@ export type KernelPluginManagerParams<
|
|
|
195
195
|
pluginEnableSignature?: Hex
|
|
196
196
|
validatorInitData?: ValidatorInitData
|
|
197
197
|
action?: Action
|
|
198
|
-
entryPoint:
|
|
199
|
-
address: Address
|
|
200
|
-
version: entryPointVersion
|
|
201
|
-
}
|
|
198
|
+
entryPoint: EntryPointType<entryPointVersion>
|
|
202
199
|
kernelVersion: KERNEL_VERSION_TYPE
|
|
203
200
|
chainId?: number
|
|
204
201
|
} & Partial<PluginValidityData>
|
|
@@ -256,3 +253,8 @@ export type GetKernelVersion<entryPointVersion extends EntryPointVersion> =
|
|
|
256
253
|
entryPointVersion extends "0.6"
|
|
257
254
|
? KERNEL_V2_VERSION_TYPE
|
|
258
255
|
: KERNEL_V3_VERSION_TYPE
|
|
256
|
+
|
|
257
|
+
export type EntryPointType<entryPointVersion extends EntryPointVersion> = {
|
|
258
|
+
address: Address
|
|
259
|
+
version: entryPointVersion
|
|
260
|
+
}
|
package/types/utils.ts
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
Account,
|
|
3
|
+
Chain,
|
|
4
|
+
EIP1193Provider,
|
|
5
|
+
LocalAccount,
|
|
6
|
+
OneOf,
|
|
7
|
+
Transport,
|
|
8
|
+
WalletClient
|
|
9
|
+
} from "viem"
|
|
10
|
+
|
|
11
|
+
export type Signer = OneOf<
|
|
12
|
+
| EIP1193Provider
|
|
13
|
+
| WalletClient<Transport, Chain | undefined, Account>
|
|
14
|
+
| LocalAccount
|
|
15
|
+
>
|
package/utils/index.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./toSigner.js"
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
// Copied from: https://github.com/pimlicolabs/permissionless.js/blob/main/packages/permissionless/utils/toOwner.ts
|
|
2
|
+
import {
|
|
3
|
+
type Account,
|
|
4
|
+
type Address,
|
|
5
|
+
type Chain,
|
|
6
|
+
type EIP1193Provider,
|
|
7
|
+
type EIP1193RequestFn,
|
|
8
|
+
type EIP1474Methods,
|
|
9
|
+
type LocalAccount,
|
|
10
|
+
type Transport,
|
|
11
|
+
type TypedData,
|
|
12
|
+
type TypedDataDefinition,
|
|
13
|
+
type WalletClient,
|
|
14
|
+
createWalletClient,
|
|
15
|
+
custom
|
|
16
|
+
} from "viem"
|
|
17
|
+
import { toAccount } from "viem/accounts"
|
|
18
|
+
|
|
19
|
+
import { signMessage, signTypedData } from "viem/actions"
|
|
20
|
+
import type { Signer } from "../types"
|
|
21
|
+
|
|
22
|
+
export async function toSigner({
|
|
23
|
+
signer,
|
|
24
|
+
address
|
|
25
|
+
}: {
|
|
26
|
+
signer: Signer
|
|
27
|
+
address?: Address
|
|
28
|
+
}): Promise<LocalAccount> {
|
|
29
|
+
if ("type" in signer && signer.type === "local") {
|
|
30
|
+
return signer as LocalAccount
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
let walletClient:
|
|
34
|
+
| WalletClient<Transport, Chain | undefined, Account>
|
|
35
|
+
| undefined = undefined
|
|
36
|
+
|
|
37
|
+
if ("request" in signer) {
|
|
38
|
+
if (!address) {
|
|
39
|
+
try {
|
|
40
|
+
;[address] = await (
|
|
41
|
+
signer.request as EIP1193RequestFn<EIP1474Methods>
|
|
42
|
+
)({
|
|
43
|
+
method: "eth_requestAccounts"
|
|
44
|
+
})
|
|
45
|
+
} catch {
|
|
46
|
+
;[address] = await (
|
|
47
|
+
signer.request as EIP1193RequestFn<EIP1474Methods>
|
|
48
|
+
)({
|
|
49
|
+
method: "eth_accounts"
|
|
50
|
+
})
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
if (!address) {
|
|
54
|
+
// For TS to be happy
|
|
55
|
+
throw new Error("address is required")
|
|
56
|
+
}
|
|
57
|
+
walletClient = createWalletClient({
|
|
58
|
+
account: address,
|
|
59
|
+
transport: custom(signer as EIP1193Provider)
|
|
60
|
+
})
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
if (!walletClient) {
|
|
64
|
+
walletClient = signer as WalletClient<
|
|
65
|
+
Transport,
|
|
66
|
+
Chain | undefined,
|
|
67
|
+
Account
|
|
68
|
+
>
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
return toAccount({
|
|
72
|
+
address: walletClient.account.address,
|
|
73
|
+
async signMessage({ message }) {
|
|
74
|
+
return signMessage(
|
|
75
|
+
walletClient as WalletClient<
|
|
76
|
+
Transport,
|
|
77
|
+
Chain | undefined,
|
|
78
|
+
Account
|
|
79
|
+
>,
|
|
80
|
+
{ message }
|
|
81
|
+
)
|
|
82
|
+
},
|
|
83
|
+
async signTypedData(typedData) {
|
|
84
|
+
const { primaryType, domain, message, types } =
|
|
85
|
+
typedData as TypedDataDefinition<TypedData, string>
|
|
86
|
+
return signTypedData(
|
|
87
|
+
walletClient as WalletClient<
|
|
88
|
+
Transport,
|
|
89
|
+
Chain | undefined,
|
|
90
|
+
Account
|
|
91
|
+
>,
|
|
92
|
+
{
|
|
93
|
+
primaryType,
|
|
94
|
+
domain,
|
|
95
|
+
message,
|
|
96
|
+
types
|
|
97
|
+
}
|
|
98
|
+
)
|
|
99
|
+
},
|
|
100
|
+
async signTransaction(_) {
|
|
101
|
+
throw new Error(
|
|
102
|
+
"Smart account signer doesn't need to sign transactions"
|
|
103
|
+
)
|
|
104
|
+
}
|
|
105
|
+
}) as LocalAccount
|
|
106
|
+
}
|
package/utils.ts
CHANGED
|
@@ -14,7 +14,7 @@ import {
|
|
|
14
14
|
import type { EntryPointVersion } from "viem/account-abstraction"
|
|
15
15
|
import type { ZeroDevPaymasterClient } from "./clients/paymasterClient.js"
|
|
16
16
|
import type { CALL_TYPE, EXEC_TYPE } from "./constants.js"
|
|
17
|
-
import type { GetKernelVersion } from "./types/kernel.js"
|
|
17
|
+
import type { EntryPointType, GetKernelVersion } from "./types/kernel.js"
|
|
18
18
|
|
|
19
19
|
export enum KERNEL_FEATURES {
|
|
20
20
|
ERC1271_SIG_WRAPPER = "ERC1271_SIG_WRAPPER",
|
|
@@ -50,7 +50,7 @@ export const getERC20PaymasterApproveCall = async <
|
|
|
50
50
|
}: {
|
|
51
51
|
gasToken: Address
|
|
52
52
|
approveAmount: bigint
|
|
53
|
-
entryPoint:
|
|
53
|
+
entryPoint: EntryPointType<entryPointVersion>
|
|
54
54
|
}
|
|
55
55
|
): Promise<{ to: Address; value: bigint; data: Hex }> => {
|
|
56
56
|
const response = await client.request({
|