permissionless 0.0.12 → 0.0.13
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 +10 -0
- package/_cjs/accounts/index.js +9 -2
- package/_cjs/accounts/index.js.map +1 -1
- package/_cjs/accounts/privateKeyToSafeSmartAccount.js +24 -0
- package/_cjs/accounts/privateKeyToSafeSmartAccount.js.map +1 -0
- package/_cjs/accounts/privateKeyToSimpleSmartAccount.js +8 -160
- package/_cjs/accounts/privateKeyToSimpleSmartAccount.js.map +1 -1
- package/_cjs/accounts/signerToSafeSmartAccount.js +492 -0
- package/_cjs/accounts/signerToSafeSmartAccount.js.map +1 -0
- package/_cjs/accounts/signerToSimpleSmartAccount.js +190 -0
- package/_cjs/accounts/signerToSimpleSmartAccount.js.map +1 -0
- package/_cjs/accounts/types.js +20 -0
- package/_cjs/accounts/types.js.map +1 -1
- package/_cjs/actions/bundler/chainId.js.map +1 -1
- package/_cjs/actions/bundler/estimateUserOperationGas.js.map +1 -1
- package/_cjs/actions/bundler/getUserOperationByHash.js.map +1 -1
- package/_cjs/actions/bundler/getUserOperationReceipt.js.map +1 -1
- package/_cjs/actions/bundler/sendUserOperation.js.map +1 -1
- package/_cjs/actions/bundler/supportedEntryPoints.js.map +1 -1
- package/_cjs/actions/bundler/waitForUserOperationReceipt.js.map +1 -1
- package/_cjs/actions/smartAccount/prepareUserOperationRequest.js +3 -1
- package/_cjs/actions/smartAccount/prepareUserOperationRequest.js.map +1 -1
- package/_cjs/actions/smartAccount/sendTransaction.js +3 -2
- package/_cjs/actions/smartAccount/sendTransaction.js.map +1 -1
- package/_cjs/actions/smartAccount/sendTransactions.js +46 -0
- package/_cjs/actions/smartAccount/sendTransactions.js.map +1 -0
- package/_cjs/actions/smartAccount.js +3 -1
- package/_cjs/actions/smartAccount.js.map +1 -1
- package/_cjs/clients/decorators/smartAccount.js +5 -0
- package/_cjs/clients/decorators/smartAccount.js.map +1 -1
- package/_esm/accounts/index.js +6 -3
- package/_esm/accounts/index.js.map +1 -1
- package/_esm/accounts/privateKeyToSafeSmartAccount.js +26 -0
- package/_esm/accounts/privateKeyToSafeSmartAccount.js.map +1 -0
- package/_esm/accounts/privateKeyToSimpleSmartAccount.js +9 -160
- package/_esm/accounts/privateKeyToSimpleSmartAccount.js.map +1 -1
- package/_esm/accounts/signerToSafeSmartAccount.js +499 -0
- package/_esm/accounts/signerToSafeSmartAccount.js.map +1 -0
- package/_esm/accounts/signerToSimpleSmartAccount.js +191 -0
- package/_esm/accounts/signerToSimpleSmartAccount.js.map +1 -0
- package/_esm/accounts/types.js +18 -0
- package/_esm/accounts/types.js.map +1 -1
- package/_esm/actions/bundler/chainId.js.map +1 -1
- package/_esm/actions/bundler/estimateUserOperationGas.js.map +1 -1
- package/_esm/actions/bundler/getUserOperationByHash.js.map +1 -1
- package/_esm/actions/bundler/getUserOperationReceipt.js.map +1 -1
- package/_esm/actions/bundler/sendUserOperation.js.map +1 -1
- package/_esm/actions/bundler/supportedEntryPoints.js.map +1 -1
- package/_esm/actions/bundler/waitForUserOperationReceipt.js.map +1 -1
- package/_esm/actions/pimlico/getUserOperationGasPrice.js +1 -1
- package/_esm/actions/pimlico/getUserOperationStatus.js +1 -1
- package/_esm/actions/smartAccount/prepareUserOperationRequest.js +3 -1
- package/_esm/actions/smartAccount/prepareUserOperationRequest.js.map +1 -1
- package/_esm/actions/smartAccount/sendTransaction.js +3 -2
- package/_esm/actions/smartAccount/sendTransaction.js.map +1 -1
- package/_esm/actions/smartAccount/sendTransactions.js +90 -0
- package/_esm/actions/smartAccount/sendTransactions.js.map +1 -0
- package/_esm/actions/smartAccount.js +2 -1
- package/_esm/actions/smartAccount.js.map +1 -1
- package/_esm/actions/stackup/accounts.js +1 -1
- package/_esm/actions/stackup/sponsorUserOperation.js +1 -1
- package/_esm/clients/decorators/pimlico.js +1 -1
- package/_esm/clients/decorators/smartAccount.js +5 -0
- package/_esm/clients/decorators/smartAccount.js.map +1 -1
- package/_esm/clients/pimlico.js +1 -1
- package/_esm/clients/stackup.js +1 -1
- package/_types/accounts/index.d.ts +6 -3
- package/_types/accounts/index.d.ts.map +1 -1
- package/_types/accounts/privateKeyToSafeSmartAccount.d.ts +26 -0
- package/_types/accounts/privateKeyToSafeSmartAccount.d.ts.map +1 -0
- package/_types/accounts/privateKeyToSimpleSmartAccount.d.ts +5 -11
- package/_types/accounts/privateKeyToSimpleSmartAccount.d.ts.map +1 -1
- package/_types/accounts/signerToSafeSmartAccount.d.ts +28 -0
- package/_types/accounts/signerToSafeSmartAccount.d.ts.map +1 -0
- package/_types/accounts/signerToSimpleSmartAccount.d.ts +15 -0
- package/_types/accounts/signerToSimpleSmartAccount.d.ts.map +1 -0
- package/_types/accounts/types.d.ts +14 -3
- package/_types/accounts/types.d.ts.map +1 -1
- package/_types/actions/bundler/chainId.d.ts +3 -2
- package/_types/actions/bundler/chainId.d.ts.map +1 -1
- package/_types/actions/bundler/estimateUserOperationGas.d.ts +3 -3
- package/_types/actions/bundler/estimateUserOperationGas.d.ts.map +1 -1
- package/_types/actions/bundler/getUserOperationByHash.d.ts +3 -3
- package/_types/actions/bundler/getUserOperationByHash.d.ts.map +1 -1
- package/_types/actions/bundler/getUserOperationReceipt.d.ts +3 -3
- package/_types/actions/bundler/getUserOperationReceipt.d.ts.map +1 -1
- package/_types/actions/bundler/sendUserOperation.d.ts +3 -3
- package/_types/actions/bundler/sendUserOperation.d.ts.map +1 -1
- package/_types/actions/bundler/supportedEntryPoints.d.ts +3 -3
- package/_types/actions/bundler/supportedEntryPoints.d.ts.map +1 -1
- package/_types/actions/bundler/waitForUserOperationReceipt.d.ts +2 -3
- package/_types/actions/bundler/waitForUserOperationReceipt.d.ts.map +1 -1
- package/_types/actions/pimlico/getUserOperationGasPrice.d.ts +1 -1
- package/_types/actions/pimlico/getUserOperationStatus.d.ts +1 -1
- package/_types/actions/smartAccount/prepareUserOperationRequest.d.ts.map +1 -1
- package/_types/actions/smartAccount/sendTransaction.d.ts.map +1 -1
- package/_types/actions/smartAccount/sendTransactions.d.ts +63 -0
- package/_types/actions/smartAccount/sendTransactions.d.ts.map +1 -0
- package/_types/actions/smartAccount.d.ts +2 -1
- package/_types/actions/smartAccount.d.ts.map +1 -1
- package/_types/actions/stackup/accounts.d.ts +1 -1
- package/_types/actions/stackup/sponsorUserOperation.d.ts +1 -1
- package/_types/clients/createSmartAccountClient.d.ts +1 -0
- package/_types/clients/createSmartAccountClient.d.ts.map +1 -1
- package/_types/clients/decorators/bundler.d.ts +1 -1
- package/_types/clients/decorators/pimlico.d.ts +3 -3
- package/_types/clients/decorators/smartAccount.d.ts +51 -0
- package/_types/clients/decorators/smartAccount.d.ts.map +1 -1
- package/_types/clients/pimlico.d.ts +1 -1
- package/_types/clients/stackup.d.ts +1 -1
- package/_types/types/index.d.ts +1 -0
- package/_types/types/index.d.ts.map +1 -1
- package/accounts/index.ts +26 -7
- package/accounts/privateKeyToSafeSmartAccount.ts +73 -0
- package/accounts/privateKeyToSimpleSmartAccount.ts +15 -191
- package/accounts/signerToSafeSmartAccount.ts +775 -0
- package/accounts/signerToSimpleSmartAccount.ts +267 -0
- package/accounts/types.ts +43 -12
- package/actions/bundler/chainId.ts +9 -1
- package/actions/bundler/estimateUserOperationGas.ts +8 -3
- package/actions/bundler/getUserOperationByHash.ts +8 -3
- package/actions/bundler/getUserOperationReceipt.ts +16 -3
- package/actions/bundler/sendUserOperation.ts +8 -3
- package/actions/bundler/supportedEntryPoints.ts +8 -3
- package/actions/bundler/waitForUserOperationReceipt.ts +15 -4
- package/actions/pimlico/getUserOperationGasPrice.ts +1 -1
- package/actions/pimlico/getUserOperationStatus.ts +1 -1
- package/actions/smartAccount/prepareUserOperationRequest.ts +3 -1
- package/actions/smartAccount/sendTransaction.ts +3 -1
- package/actions/smartAccount/sendTransactions.ts +141 -0
- package/actions/smartAccount.ts +8 -1
- package/actions/stackup/accounts.ts +1 -1
- package/actions/stackup/sponsorUserOperation.ts +1 -1
- package/clients/decorators/bundler.ts +1 -1
- package/clients/decorators/pimlico.ts +3 -3
- package/clients/decorators/smartAccount.ts +61 -0
- package/clients/pimlico.ts +1 -1
- package/clients/stackup.ts +1 -1
- package/package.json +2 -2
- package/types/index.ts +5 -0
- package/tsconfig.build.tsbuildinfo +0 -1
|
@@ -0,0 +1,267 @@
|
|
|
1
|
+
import {
|
|
2
|
+
type Account,
|
|
3
|
+
type Address,
|
|
4
|
+
type Chain,
|
|
5
|
+
type Client,
|
|
6
|
+
type Hex,
|
|
7
|
+
type Transport,
|
|
8
|
+
concatHex,
|
|
9
|
+
encodeFunctionData
|
|
10
|
+
} from "viem"
|
|
11
|
+
import { toAccount } from "viem/accounts"
|
|
12
|
+
import {
|
|
13
|
+
getBytecode,
|
|
14
|
+
getChainId,
|
|
15
|
+
signMessage,
|
|
16
|
+
signTypedData
|
|
17
|
+
} from "viem/actions"
|
|
18
|
+
import { getAccountNonce } from "../actions/public/getAccountNonce.js"
|
|
19
|
+
import { getSenderAddress } from "../actions/public/getSenderAddress.js"
|
|
20
|
+
import { getUserOperationHash } from "../utils/getUserOperationHash.js"
|
|
21
|
+
import {
|
|
22
|
+
SignTransactionNotSupportedBySmartAccount,
|
|
23
|
+
type SmartAccount,
|
|
24
|
+
type SmartAccountSigner
|
|
25
|
+
} from "./types.js"
|
|
26
|
+
|
|
27
|
+
export type SimpleSmartAccount<
|
|
28
|
+
transport extends Transport = Transport,
|
|
29
|
+
chain extends Chain | undefined = Chain | undefined
|
|
30
|
+
> = SmartAccount<"SimpleSmartAccount", transport, chain>
|
|
31
|
+
|
|
32
|
+
const getAccountInitCode = async (
|
|
33
|
+
factoryAddress: Address,
|
|
34
|
+
owner: Address,
|
|
35
|
+
index = 0n
|
|
36
|
+
): Promise<Hex> => {
|
|
37
|
+
if (!owner) throw new Error("Owner account not found")
|
|
38
|
+
|
|
39
|
+
return concatHex([
|
|
40
|
+
factoryAddress,
|
|
41
|
+
encodeFunctionData({
|
|
42
|
+
abi: [
|
|
43
|
+
{
|
|
44
|
+
inputs: [
|
|
45
|
+
{
|
|
46
|
+
internalType: "address",
|
|
47
|
+
name: "owner",
|
|
48
|
+
type: "address"
|
|
49
|
+
},
|
|
50
|
+
{
|
|
51
|
+
internalType: "uint256",
|
|
52
|
+
name: "salt",
|
|
53
|
+
type: "uint256"
|
|
54
|
+
}
|
|
55
|
+
],
|
|
56
|
+
name: "createAccount",
|
|
57
|
+
outputs: [
|
|
58
|
+
{
|
|
59
|
+
internalType: "contract SimpleAccount",
|
|
60
|
+
name: "ret",
|
|
61
|
+
type: "address"
|
|
62
|
+
}
|
|
63
|
+
],
|
|
64
|
+
stateMutability: "nonpayable",
|
|
65
|
+
type: "function"
|
|
66
|
+
}
|
|
67
|
+
],
|
|
68
|
+
functionName: "createAccount",
|
|
69
|
+
args: [owner, index]
|
|
70
|
+
}) as Hex
|
|
71
|
+
])
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
const getAccountAddress = async <
|
|
75
|
+
TTransport extends Transport = Transport,
|
|
76
|
+
TChain extends Chain | undefined = Chain | undefined
|
|
77
|
+
>({
|
|
78
|
+
client,
|
|
79
|
+
factoryAddress,
|
|
80
|
+
entryPoint,
|
|
81
|
+
owner,
|
|
82
|
+
index = 0n
|
|
83
|
+
}: {
|
|
84
|
+
client: Client<TTransport, TChain>
|
|
85
|
+
factoryAddress: Address
|
|
86
|
+
owner: Address
|
|
87
|
+
entryPoint: Address
|
|
88
|
+
index?: bigint
|
|
89
|
+
}): Promise<Address> => {
|
|
90
|
+
const initCode = await getAccountInitCode(factoryAddress, owner, index)
|
|
91
|
+
|
|
92
|
+
return getSenderAddress(client, {
|
|
93
|
+
initCode,
|
|
94
|
+
entryPoint
|
|
95
|
+
})
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
/**
|
|
99
|
+
* @description Creates an Simple Account from a private key.
|
|
100
|
+
*
|
|
101
|
+
* @returns A Private Key Simple Account.
|
|
102
|
+
*/
|
|
103
|
+
export async function signerToSimpleSmartAccount<
|
|
104
|
+
TTransport extends Transport = Transport,
|
|
105
|
+
TChain extends Chain | undefined = Chain | undefined
|
|
106
|
+
>(
|
|
107
|
+
client: Client<TTransport, TChain>,
|
|
108
|
+
{
|
|
109
|
+
signer,
|
|
110
|
+
factoryAddress,
|
|
111
|
+
entryPoint,
|
|
112
|
+
index = 0n
|
|
113
|
+
}: {
|
|
114
|
+
signer: SmartAccountSigner
|
|
115
|
+
factoryAddress: Address
|
|
116
|
+
entryPoint: Address
|
|
117
|
+
index?: bigint
|
|
118
|
+
}
|
|
119
|
+
): Promise<SimpleSmartAccount<TTransport, TChain>> {
|
|
120
|
+
const viemSigner: Account =
|
|
121
|
+
signer.type === "local"
|
|
122
|
+
? ({
|
|
123
|
+
...signer,
|
|
124
|
+
signTransaction: (_, __) => {
|
|
125
|
+
throw new SignTransactionNotSupportedBySmartAccount()
|
|
126
|
+
}
|
|
127
|
+
} as Account)
|
|
128
|
+
: (signer as Account)
|
|
129
|
+
|
|
130
|
+
const [accountAddress, chainId] = await Promise.all([
|
|
131
|
+
getAccountAddress<TTransport, TChain>({
|
|
132
|
+
client,
|
|
133
|
+
factoryAddress,
|
|
134
|
+
entryPoint,
|
|
135
|
+
owner: viemSigner.address,
|
|
136
|
+
index
|
|
137
|
+
}),
|
|
138
|
+
getChainId(client)
|
|
139
|
+
])
|
|
140
|
+
|
|
141
|
+
if (!accountAddress) throw new Error("Account address not found")
|
|
142
|
+
|
|
143
|
+
const account = toAccount({
|
|
144
|
+
address: accountAddress,
|
|
145
|
+
async signMessage({ message }) {
|
|
146
|
+
return signMessage(client, { account: viemSigner, message })
|
|
147
|
+
},
|
|
148
|
+
async signTransaction(_, __) {
|
|
149
|
+
throw new SignTransactionNotSupportedBySmartAccount()
|
|
150
|
+
},
|
|
151
|
+
async signTypedData(typedData) {
|
|
152
|
+
return signTypedData(client, { account: viemSigner, ...typedData })
|
|
153
|
+
}
|
|
154
|
+
})
|
|
155
|
+
|
|
156
|
+
return {
|
|
157
|
+
...account,
|
|
158
|
+
client: client,
|
|
159
|
+
publicKey: accountAddress,
|
|
160
|
+
entryPoint: entryPoint,
|
|
161
|
+
source: "SimpleSmartAccount",
|
|
162
|
+
async getNonce() {
|
|
163
|
+
return getAccountNonce(client, {
|
|
164
|
+
sender: accountAddress,
|
|
165
|
+
entryPoint: entryPoint
|
|
166
|
+
})
|
|
167
|
+
},
|
|
168
|
+
async signUserOperation(userOperation) {
|
|
169
|
+
return account.signMessage({
|
|
170
|
+
message: {
|
|
171
|
+
raw: getUserOperationHash({
|
|
172
|
+
userOperation,
|
|
173
|
+
entryPoint: entryPoint,
|
|
174
|
+
chainId: chainId
|
|
175
|
+
})
|
|
176
|
+
}
|
|
177
|
+
})
|
|
178
|
+
},
|
|
179
|
+
async getInitCode() {
|
|
180
|
+
const contractCode = await getBytecode(client, {
|
|
181
|
+
address: accountAddress
|
|
182
|
+
})
|
|
183
|
+
|
|
184
|
+
if ((contractCode?.length ?? 0) > 2) return "0x"
|
|
185
|
+
|
|
186
|
+
return getAccountInitCode(factoryAddress, viemSigner.address, index)
|
|
187
|
+
},
|
|
188
|
+
async encodeDeployCallData(_) {
|
|
189
|
+
throw new Error("Simple account doesn't support account deployment")
|
|
190
|
+
},
|
|
191
|
+
async encodeCallData(args) {
|
|
192
|
+
if (Array.isArray(args)) {
|
|
193
|
+
const argsArray = args as {
|
|
194
|
+
to: Address
|
|
195
|
+
value: bigint
|
|
196
|
+
data: Hex
|
|
197
|
+
}[]
|
|
198
|
+
return encodeFunctionData({
|
|
199
|
+
abi: [
|
|
200
|
+
{
|
|
201
|
+
inputs: [
|
|
202
|
+
{
|
|
203
|
+
internalType: "address[]",
|
|
204
|
+
name: "dest",
|
|
205
|
+
type: "address[]"
|
|
206
|
+
},
|
|
207
|
+
{
|
|
208
|
+
internalType: "bytes[]",
|
|
209
|
+
name: "func",
|
|
210
|
+
type: "bytes[]"
|
|
211
|
+
}
|
|
212
|
+
],
|
|
213
|
+
name: "executeBatch",
|
|
214
|
+
outputs: [],
|
|
215
|
+
stateMutability: "nonpayable",
|
|
216
|
+
type: "function"
|
|
217
|
+
}
|
|
218
|
+
],
|
|
219
|
+
functionName: "executeBatch",
|
|
220
|
+
args: [
|
|
221
|
+
argsArray.map((a) => a.to),
|
|
222
|
+
argsArray.map((a) => a.data)
|
|
223
|
+
]
|
|
224
|
+
})
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
const { to, value, data } = args as {
|
|
228
|
+
to: Address
|
|
229
|
+
value: bigint
|
|
230
|
+
data: Hex
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
return encodeFunctionData({
|
|
234
|
+
abi: [
|
|
235
|
+
{
|
|
236
|
+
inputs: [
|
|
237
|
+
{
|
|
238
|
+
internalType: "address",
|
|
239
|
+
name: "dest",
|
|
240
|
+
type: "address"
|
|
241
|
+
},
|
|
242
|
+
{
|
|
243
|
+
internalType: "uint256",
|
|
244
|
+
name: "value",
|
|
245
|
+
type: "uint256"
|
|
246
|
+
},
|
|
247
|
+
{
|
|
248
|
+
internalType: "bytes",
|
|
249
|
+
name: "func",
|
|
250
|
+
type: "bytes"
|
|
251
|
+
}
|
|
252
|
+
],
|
|
253
|
+
name: "execute",
|
|
254
|
+
outputs: [],
|
|
255
|
+
stateMutability: "nonpayable",
|
|
256
|
+
type: "function"
|
|
257
|
+
}
|
|
258
|
+
],
|
|
259
|
+
functionName: "execute",
|
|
260
|
+
args: [to, value, data]
|
|
261
|
+
})
|
|
262
|
+
},
|
|
263
|
+
async getDummySignature() {
|
|
264
|
+
return "0xfffffffffffffffffffffffffffffff0000000000000000000000000000000007aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa1c"
|
|
265
|
+
}
|
|
266
|
+
}
|
|
267
|
+
}
|
package/accounts/types.ts
CHANGED
|
@@ -1,14 +1,32 @@
|
|
|
1
|
-
import
|
|
2
|
-
Abi,
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
1
|
+
import {
|
|
2
|
+
type Abi,
|
|
3
|
+
type Account,
|
|
4
|
+
type Address,
|
|
5
|
+
BaseError,
|
|
6
|
+
type Client,
|
|
7
|
+
type GetConstructorArgs,
|
|
8
|
+
type Hex,
|
|
9
|
+
type LocalAccount
|
|
8
10
|
} from "viem"
|
|
9
11
|
import type { Chain, Transport } from "viem"
|
|
10
12
|
import { type UserOperation } from "../types/index.js"
|
|
11
13
|
|
|
14
|
+
export class SignTransactionNotSupportedBySmartAccount extends BaseError {
|
|
15
|
+
override name = "SignTransactionNotSupportedBySmartAccount"
|
|
16
|
+
constructor({ docsPath }: { docsPath?: string } = {}) {
|
|
17
|
+
super(
|
|
18
|
+
[
|
|
19
|
+
"A smart account cannot sign or send transaction, it can only sign message or userOperation.",
|
|
20
|
+
"Please send user operation instead."
|
|
21
|
+
].join("\n"),
|
|
22
|
+
{
|
|
23
|
+
docsPath,
|
|
24
|
+
docsSlug: "account"
|
|
25
|
+
}
|
|
26
|
+
)
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
|
|
12
30
|
export type SmartAccount<
|
|
13
31
|
Name extends string = string,
|
|
14
32
|
transport extends Transport = Transport,
|
|
@@ -18,11 +36,19 @@ export type SmartAccount<
|
|
|
18
36
|
entryPoint: Address
|
|
19
37
|
getNonce: () => Promise<bigint>
|
|
20
38
|
getInitCode: () => Promise<Hex>
|
|
21
|
-
encodeCallData: (
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
39
|
+
encodeCallData: (
|
|
40
|
+
args:
|
|
41
|
+
| {
|
|
42
|
+
to: Address
|
|
43
|
+
value: bigint
|
|
44
|
+
data: Hex
|
|
45
|
+
}
|
|
46
|
+
| {
|
|
47
|
+
to: Address
|
|
48
|
+
value: bigint
|
|
49
|
+
data: Hex
|
|
50
|
+
}[]
|
|
51
|
+
) => Promise<Hex>
|
|
26
52
|
getDummySignature(): Promise<Hex>
|
|
27
53
|
encodeDeployCallData: <TAbi extends Abi | readonly unknown[] = Abi>({
|
|
28
54
|
abi,
|
|
@@ -31,3 +57,8 @@ export type SmartAccount<
|
|
|
31
57
|
}: { abi: TAbi; bytecode: Hex } & GetConstructorArgs<TAbi>) => Promise<Hex>
|
|
32
58
|
signUserOperation: (UserOperation: UserOperation) => Promise<Hex>
|
|
33
59
|
}
|
|
60
|
+
|
|
61
|
+
export type SmartAccountSigner<TAddress extends Address = Address> = Omit<
|
|
62
|
+
Account<TAddress>,
|
|
63
|
+
"signTransaction"
|
|
64
|
+
>
|
|
@@ -1,4 +1,6 @@
|
|
|
1
|
+
import type { Account, Chain, Client, Transport } from "viem"
|
|
1
2
|
import type { BundlerClient } from "../../clients/createBundlerClient.js"
|
|
3
|
+
import type { BundlerRpcSchema } from "../../types/bundler.js"
|
|
2
4
|
|
|
3
5
|
/**
|
|
4
6
|
* Returns the supported chain id by the bundler service
|
|
@@ -22,7 +24,13 @@ import type { BundlerClient } from "../../clients/createBundlerClient.js"
|
|
|
22
24
|
* // Return 5n for Goerli
|
|
23
25
|
*
|
|
24
26
|
*/
|
|
25
|
-
export const chainId = async
|
|
27
|
+
export const chainId = async <
|
|
28
|
+
TTransport extends Transport = Transport,
|
|
29
|
+
TChain extends Chain | undefined = Chain | undefined,
|
|
30
|
+
TAccount extends Account | undefined = Account | undefined
|
|
31
|
+
>(
|
|
32
|
+
client: Client<TTransport, TChain, TAccount, BundlerRpcSchema>
|
|
33
|
+
) => {
|
|
26
34
|
return Number(
|
|
27
35
|
await client.request({
|
|
28
36
|
method: "eth_chainId",
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import type { Address } from "viem"
|
|
1
|
+
import type { Account, Address, Chain, Client, Transport } from "viem"
|
|
2
2
|
import type { PartialBy } from "viem/types/utils"
|
|
3
3
|
import type { BundlerClient } from "../../clients/createBundlerClient.js"
|
|
4
|
+
import type { BundlerRpcSchema } from "../../types/bundler.js"
|
|
4
5
|
import type { UserOperation } from "../../types/userOperation.js"
|
|
5
6
|
import type { UserOperationWithBigIntAsHex } from "../../types/userOperation.js"
|
|
6
7
|
import { deepHexlify } from "../../utils/deepHexlify.js"
|
|
@@ -46,8 +47,12 @@ export type EstimateUserOperationGasReturnType = {
|
|
|
46
47
|
* // Return {preVerificationGas: 43492n, verificationGasLimit: 59436n, callGasLimit: 9000n}
|
|
47
48
|
*
|
|
48
49
|
*/
|
|
49
|
-
export const estimateUserOperationGas = async
|
|
50
|
-
|
|
50
|
+
export const estimateUserOperationGas = async <
|
|
51
|
+
TTransport extends Transport = Transport,
|
|
52
|
+
TChain extends Chain | undefined = Chain | undefined,
|
|
53
|
+
TAccount extends Account | undefined = Account | undefined
|
|
54
|
+
>(
|
|
55
|
+
client: Client<TTransport, TChain, TAccount, BundlerRpcSchema>,
|
|
51
56
|
args: EstimateUserOperationGasParameters
|
|
52
57
|
): Promise<EstimateUserOperationGasReturnType> => {
|
|
53
58
|
const { userOperation, entryPoint } = args
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import type { Address, Hash } from "viem"
|
|
1
|
+
import type { Account, Address, Chain, Client, Hash, Transport } from "viem"
|
|
2
2
|
import type { BundlerClient } from "../../clients/createBundlerClient.js"
|
|
3
|
+
import type { BundlerRpcSchema } from "../../types/bundler.js"
|
|
3
4
|
import type { UserOperation } from "../../types/userOperation.js"
|
|
4
5
|
|
|
5
6
|
export type GetUserOperationByHashParameters = {
|
|
@@ -36,8 +37,12 @@ export type GetUserOperationByHashReturnType = {
|
|
|
36
37
|
* getUserOperationByHash(bundlerClient, {hash: userOpHash})
|
|
37
38
|
*
|
|
38
39
|
*/
|
|
39
|
-
export const getUserOperationByHash = async
|
|
40
|
-
|
|
40
|
+
export const getUserOperationByHash = async <
|
|
41
|
+
TTransport extends Transport = Transport,
|
|
42
|
+
TChain extends Chain | undefined = Chain | undefined,
|
|
43
|
+
TAccount extends Account | undefined = Account | undefined
|
|
44
|
+
>(
|
|
45
|
+
client: Client<TTransport, TChain, TAccount, BundlerRpcSchema>,
|
|
41
46
|
{ hash }: GetUserOperationByHashParameters
|
|
42
47
|
): Promise<GetUserOperationByHashReturnType> => {
|
|
43
48
|
const params: [Hash] = [hash]
|
|
@@ -1,5 +1,14 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type {
|
|
2
|
+
Account,
|
|
3
|
+
Address,
|
|
4
|
+
Chain,
|
|
5
|
+
Client,
|
|
6
|
+
Hash,
|
|
7
|
+
Hex,
|
|
8
|
+
Transport
|
|
9
|
+
} from "viem"
|
|
2
10
|
import type { BundlerClient } from "../../clients/createBundlerClient.js"
|
|
11
|
+
import type { BundlerRpcSchema } from "../../types/bundler.js"
|
|
3
12
|
import type { TStatus } from "../../types/userOperation.js"
|
|
4
13
|
import { transactionReceiptStatus } from "../../utils/deepHexlify.js"
|
|
5
14
|
|
|
@@ -62,8 +71,12 @@ export type GetUserOperationReceiptReturnType = {
|
|
|
62
71
|
* getUserOperationReceipt(bundlerClient, {hash: userOpHash})
|
|
63
72
|
*
|
|
64
73
|
*/
|
|
65
|
-
export const getUserOperationReceipt = async
|
|
66
|
-
|
|
74
|
+
export const getUserOperationReceipt = async <
|
|
75
|
+
TTransport extends Transport = Transport,
|
|
76
|
+
TChain extends Chain | undefined = Chain | undefined,
|
|
77
|
+
TAccount extends Account | undefined = Account | undefined
|
|
78
|
+
>(
|
|
79
|
+
client: Client<TTransport, TChain, TAccount, BundlerRpcSchema>,
|
|
67
80
|
{ hash }: GetUserOperationReceiptParameters
|
|
68
81
|
): Promise<GetUserOperationReceiptReturnType | null> => {
|
|
69
82
|
const params: [Hash] = [hash]
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import type { Address, Hash } from "viem"
|
|
1
|
+
import type { Account, Address, Chain, Client, Hash, Transport } from "viem"
|
|
2
2
|
import type { BundlerClient } from "../../clients/createBundlerClient.js"
|
|
3
|
+
import type { BundlerRpcSchema } from "../../types/bundler.js"
|
|
3
4
|
import type {
|
|
4
5
|
UserOperation,
|
|
5
6
|
UserOperationWithBigIntAsHex
|
|
@@ -36,8 +37,12 @@ export type SendUserOperationParameters = {
|
|
|
36
37
|
*
|
|
37
38
|
* // Return '0xe9fad2cd67f9ca1d0b7a6513b2a42066784c8df938518da2b51bb8cc9a89ea34'
|
|
38
39
|
*/
|
|
39
|
-
export const sendUserOperation = async
|
|
40
|
-
|
|
40
|
+
export const sendUserOperation = async <
|
|
41
|
+
TTransport extends Transport = Transport,
|
|
42
|
+
TChain extends Chain | undefined = Chain | undefined,
|
|
43
|
+
TAccount extends Account | undefined = Account | undefined
|
|
44
|
+
>(
|
|
45
|
+
client: Client<TTransport, TChain, TAccount, BundlerRpcSchema>,
|
|
41
46
|
args: SendUserOperationParameters
|
|
42
47
|
): Promise<Hash> => {
|
|
43
48
|
const { userOperation, entryPoint } = args
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import type { Address } from "viem"
|
|
1
|
+
import type { Account, Address, Chain, Client, Transport } from "viem"
|
|
2
2
|
import type { BundlerClient } from "../../clients/createBundlerClient.js"
|
|
3
|
+
import type { BundlerRpcSchema } from "../../types/bundler.js"
|
|
3
4
|
|
|
4
5
|
/**
|
|
5
6
|
* Returns the supported entrypoints by the bundler service
|
|
@@ -23,8 +24,12 @@ import type { BundlerClient } from "../../clients/createBundlerClient.js"
|
|
|
23
24
|
* // Return ['0x5FF137D4b0FDCD49DcA30c7CF57E578a026d2789']
|
|
24
25
|
*
|
|
25
26
|
*/
|
|
26
|
-
export const supportedEntryPoints = async
|
|
27
|
-
|
|
27
|
+
export const supportedEntryPoints = async <
|
|
28
|
+
TTransport extends Transport = Transport,
|
|
29
|
+
TChain extends Chain | undefined = Chain | undefined,
|
|
30
|
+
TAccount extends Account | undefined = Account | undefined
|
|
31
|
+
>(
|
|
32
|
+
client: Client<TTransport, TChain, TAccount, BundlerRpcSchema>
|
|
28
33
|
): Promise<Address[]> => {
|
|
29
34
|
return client.request({
|
|
30
35
|
method: "eth_supportedEntryPoints",
|
|
@@ -1,5 +1,12 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
1
|
+
import {
|
|
2
|
+
type Account,
|
|
3
|
+
BaseError,
|
|
4
|
+
type Chain,
|
|
5
|
+
type Client,
|
|
6
|
+
type Hash,
|
|
7
|
+
type Transport,
|
|
8
|
+
stringify
|
|
9
|
+
} from "viem"
|
|
3
10
|
import { getAction } from "../../utils/getAction.js"
|
|
4
11
|
import { observe } from "../../utils/observe.js"
|
|
5
12
|
import {
|
|
@@ -49,8 +56,12 @@ export type WaitForUserOperationReceiptParameters = {
|
|
|
49
56
|
* hash: '0x4ca7ee652d57678f26e887c149ab0735f41de37bcad58c9f6d3ed5824f15b74d',
|
|
50
57
|
* })
|
|
51
58
|
*/
|
|
52
|
-
export const waitForUserOperationReceipt = <
|
|
53
|
-
|
|
59
|
+
export const waitForUserOperationReceipt = <
|
|
60
|
+
TTransport extends Transport = Transport,
|
|
61
|
+
TChain extends Chain | undefined = Chain | undefined,
|
|
62
|
+
TAccount extends Account | undefined = Account | undefined
|
|
63
|
+
>(
|
|
64
|
+
bundlerClient: Client<TTransport, TChain, TAccount>,
|
|
54
65
|
{
|
|
55
66
|
hash,
|
|
56
67
|
pollingInterval = bundlerClient.pollingInterval,
|
|
@@ -31,7 +31,7 @@ export type GetUserOperationGasPriceReturnType = {
|
|
|
31
31
|
*
|
|
32
32
|
* const bundlerClient = createClient({
|
|
33
33
|
* chain: goerli,
|
|
34
|
-
* transport: http("https://api.pimlico.io/
|
|
34
|
+
* transport: http("https://api.pimlico.io/v2/goerli/rpc?apikey=YOUR_API_KEY_HERE")
|
|
35
35
|
* })
|
|
36
36
|
*
|
|
37
37
|
* await getUserOperationGasPrice(bundlerClient)
|
|
@@ -27,7 +27,7 @@ export type GetUserOperationStatusReturnType = PimlicoUserOperationStatus
|
|
|
27
27
|
*
|
|
28
28
|
* const bundlerClient = createClient({
|
|
29
29
|
* chain: goerli,
|
|
30
|
-
* transport: http("https://api.pimlico.io/
|
|
30
|
+
* transport: http("https://api.pimlico.io/v2/goerli/rpc?apikey=YOUR_API_KEY_HERE")
|
|
31
31
|
* })
|
|
32
32
|
*
|
|
33
33
|
* await getUserOperationStatus(bundlerClient, { hash: userOpHash })
|
|
@@ -87,6 +87,7 @@ export async function sendTransaction<
|
|
|
87
87
|
maxPriorityFeePerGas,
|
|
88
88
|
to,
|
|
89
89
|
value,
|
|
90
|
+
nonce,
|
|
90
91
|
sponsorUserOperation
|
|
91
92
|
} = args
|
|
92
93
|
|
|
@@ -119,7 +120,8 @@ export async function sendTransaction<
|
|
|
119
120
|
paymasterAndData: "0x",
|
|
120
121
|
maxFeePerGas: maxFeePerGas || 0n,
|
|
121
122
|
maxPriorityFeePerGas: maxPriorityFeePerGas || 0n,
|
|
122
|
-
callData: callData
|
|
123
|
+
callData: callData,
|
|
124
|
+
nonce: nonce ? BigInt(nonce) : undefined
|
|
123
125
|
},
|
|
124
126
|
account: account,
|
|
125
127
|
sponsorUserOperation
|