@pimlico/mock-paymaster 0.0.4 → 0.0.6
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/helpers/erc20-utils.js +26 -15
- package/_cjs/helpers/erc20-utils.js.map +1 -1
- package/_cjs/helpers/schema.js +7 -7
- package/_cjs/helpers/schema.js.map +1 -1
- package/_cjs/helpers/utils.js +1 -13
- package/_cjs/helpers/utils.js.map +1 -1
- package/_cjs/index.js +16 -20
- package/_cjs/index.js.map +1 -1
- package/_cjs/relay.js +24 -11
- package/_cjs/relay.js.map +1 -1
- package/_cjs/setup.js +118 -0
- package/_cjs/setup.js.map +1 -0
- package/_cjs/singletonPaymasters.js +1 -61
- package/_cjs/singletonPaymasters.js.map +1 -1
- package/_esm/helpers/erc20-utils.js +28 -13
- package/_esm/helpers/erc20-utils.js.map +1 -1
- package/_esm/helpers/schema.js +7 -7
- package/_esm/helpers/schema.js.map +1 -1
- package/_esm/helpers/utils.js +1 -12
- package/_esm/helpers/utils.js.map +1 -1
- package/_esm/index.js +15 -21
- package/_esm/index.js.map +1 -1
- package/_esm/relay.js +33 -16
- package/_esm/relay.js.map +1 -1
- package/_esm/setup.js +120 -0
- package/_esm/setup.js.map +1 -0
- package/_esm/singletonPaymasters.js +3 -67
- package/_esm/singletonPaymasters.js.map +1 -1
- package/_types/helpers/erc20-utils.d.ts +4 -2
- package/_types/helpers/erc20-utils.d.ts.map +1 -1
- package/_types/helpers/schema.d.ts +569 -569
- package/_types/helpers/schema.d.ts.map +1 -1
- package/_types/helpers/utils.d.ts +1 -5
- package/_types/helpers/utils.d.ts.map +1 -1
- package/_types/index.d.ts +1 -0
- package/_types/index.d.ts.map +1 -1
- package/_types/relay.d.ts +4 -5
- package/_types/relay.d.ts.map +1 -1
- package/_types/setup.d.ts +11 -0
- package/_types/setup.d.ts.map +1 -0
- package/_types/singletonPaymasters.d.ts +0 -4
- package/_types/singletonPaymasters.d.ts.map +1 -1
- package/helpers/erc20-utils.ts +40 -16
- package/helpers/schema.ts +7 -7
- package/helpers/utils.ts +0 -24
- package/index.ts +19 -22
- package/package.json +2 -2
- package/relay.ts +44 -22
- package/setup.ts +163 -0
- package/singletonPaymasters.ts +2 -91
package/setup.ts
ADDED
|
@@ -0,0 +1,163 @@
|
|
|
1
|
+
import { type Address, concat, getContract, parseEther } from "viem"
|
|
2
|
+
import {
|
|
3
|
+
constants,
|
|
4
|
+
getSingletonPaymaster06Address,
|
|
5
|
+
getSingletonPaymaster06InitCode,
|
|
6
|
+
getSingletonPaymaster07Address,
|
|
7
|
+
getSingletonPaymaster07InitCode,
|
|
8
|
+
getSingletonPaymaster08Address,
|
|
9
|
+
getSingletonPaymaster08InitCode
|
|
10
|
+
} from "./constants.js"
|
|
11
|
+
import {
|
|
12
|
+
singletonPaymaster06Abi,
|
|
13
|
+
singletonPaymaster07Abi,
|
|
14
|
+
singletonPaymaster08Abi
|
|
15
|
+
} from "./helpers/abi.js"
|
|
16
|
+
import {
|
|
17
|
+
create2Salt,
|
|
18
|
+
erc20Address,
|
|
19
|
+
erc20Bytecode,
|
|
20
|
+
getPaymasterUtilityWallet
|
|
21
|
+
} from "./helpers/erc20-utils.js"
|
|
22
|
+
import { getPublicClient } from "./helpers/utils.js"
|
|
23
|
+
|
|
24
|
+
export const deployPaymasters = async ({
|
|
25
|
+
anvilRpc,
|
|
26
|
+
paymasterSigner
|
|
27
|
+
}: {
|
|
28
|
+
anvilRpc: string
|
|
29
|
+
paymasterSigner: Address
|
|
30
|
+
}) => {
|
|
31
|
+
const walletClient = await getPaymasterUtilityWallet(anvilRpc)
|
|
32
|
+
const publicClient = await getPublicClient(anvilRpc)
|
|
33
|
+
|
|
34
|
+
let nonce = await publicClient.getTransactionCount({
|
|
35
|
+
address: walletClient.account.address
|
|
36
|
+
})
|
|
37
|
+
|
|
38
|
+
const paymaster06Address = getSingletonPaymaster06Address(paymasterSigner)
|
|
39
|
+
const paymaster07Address = getSingletonPaymaster07Address(paymasterSigner)
|
|
40
|
+
const paymaster08Address = getSingletonPaymaster08Address(paymasterSigner)
|
|
41
|
+
|
|
42
|
+
// Deploy singleton paymaster 06 if not already deployed.
|
|
43
|
+
const paymaster06Code = await publicClient.getCode({
|
|
44
|
+
address: paymaster06Address
|
|
45
|
+
})
|
|
46
|
+
if (!paymaster06Code) {
|
|
47
|
+
const hash = await walletClient.sendTransaction({
|
|
48
|
+
to: constants.deterministicDeployer,
|
|
49
|
+
data: concat([
|
|
50
|
+
constants.create2Salt,
|
|
51
|
+
getSingletonPaymaster06InitCode(paymasterSigner)
|
|
52
|
+
]),
|
|
53
|
+
nonce: nonce++
|
|
54
|
+
})
|
|
55
|
+
await publicClient.waitForTransactionReceipt({ hash })
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
// Deploy singleton paymaster 07 if not already deployed.
|
|
59
|
+
const paymaster07Code = await publicClient.getCode({
|
|
60
|
+
address: paymaster07Address
|
|
61
|
+
})
|
|
62
|
+
if (!paymaster07Code) {
|
|
63
|
+
const hash = await walletClient.sendTransaction({
|
|
64
|
+
to: constants.deterministicDeployer,
|
|
65
|
+
data: concat([
|
|
66
|
+
constants.create2Salt,
|
|
67
|
+
getSingletonPaymaster07InitCode(paymasterSigner)
|
|
68
|
+
]),
|
|
69
|
+
nonce: nonce++
|
|
70
|
+
})
|
|
71
|
+
await publicClient.waitForTransactionReceipt({ hash })
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
// Deploy singleton paymaster 08 if not already deployed.
|
|
75
|
+
const paymaster08Code = await publicClient.getCode({
|
|
76
|
+
address: paymaster08Address
|
|
77
|
+
})
|
|
78
|
+
if (!paymaster08Code) {
|
|
79
|
+
const hash = await walletClient.sendTransaction({
|
|
80
|
+
to: constants.deterministicDeployer,
|
|
81
|
+
data: concat([
|
|
82
|
+
constants.create2Salt,
|
|
83
|
+
getSingletonPaymaster08InitCode(paymasterSigner)
|
|
84
|
+
]),
|
|
85
|
+
nonce: nonce++
|
|
86
|
+
})
|
|
87
|
+
await publicClient.waitForTransactionReceipt({ hash })
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
const depositAmount = parseEther("50")
|
|
91
|
+
|
|
92
|
+
// Initialize contract instances and fund if needed.
|
|
93
|
+
// Only check deposit balance if the contract was already deployed.
|
|
94
|
+
|
|
95
|
+
// Fund paymaster 06 if balance is less than deposit amount.
|
|
96
|
+
const singletonPaymaster06 = getContract({
|
|
97
|
+
address: paymaster06Address,
|
|
98
|
+
abi: singletonPaymaster06Abi,
|
|
99
|
+
client: walletClient
|
|
100
|
+
})
|
|
101
|
+
const deposit06 = await singletonPaymaster06.read.getDeposit()
|
|
102
|
+
if (deposit06 < depositAmount) {
|
|
103
|
+
await singletonPaymaster06.write.deposit({
|
|
104
|
+
value: depositAmount,
|
|
105
|
+
nonce: nonce++
|
|
106
|
+
})
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
// Fund paymaster 07 if balance is less than deposit amount.
|
|
110
|
+
const singletonPaymaster07 = getContract({
|
|
111
|
+
address: paymaster07Address,
|
|
112
|
+
abi: singletonPaymaster07Abi,
|
|
113
|
+
client: walletClient
|
|
114
|
+
})
|
|
115
|
+
const deposit07 = await singletonPaymaster07.read.getDeposit()
|
|
116
|
+
if (deposit07 < depositAmount) {
|
|
117
|
+
await singletonPaymaster07.write.deposit({
|
|
118
|
+
value: depositAmount,
|
|
119
|
+
nonce: nonce++
|
|
120
|
+
})
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
// Fund paymaster 08 if balance is less than deposit amount.
|
|
124
|
+
const singletonPaymaster08 = getContract({
|
|
125
|
+
address: paymaster08Address,
|
|
126
|
+
abi: singletonPaymaster08Abi,
|
|
127
|
+
client: walletClient
|
|
128
|
+
})
|
|
129
|
+
const deposit08 = await singletonPaymaster08.read.getDeposit()
|
|
130
|
+
if (deposit08 < depositAmount) {
|
|
131
|
+
await singletonPaymaster08.write.deposit({
|
|
132
|
+
value: depositAmount,
|
|
133
|
+
nonce: nonce++
|
|
134
|
+
})
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
export const deployErc20Token = async (anvilRpc: string) => {
|
|
139
|
+
const publicClient = await getPublicClient(anvilRpc)
|
|
140
|
+
|
|
141
|
+
if ((await publicClient.getCode({ address: erc20Address })) === undefined) {
|
|
142
|
+
const walletClient = await getPaymasterUtilityWallet(anvilRpc)
|
|
143
|
+
|
|
144
|
+
await walletClient.sendTransaction({
|
|
145
|
+
to: "0x4e59b44847b379578588920ca78fbf26c0b4956c",
|
|
146
|
+
data: concat([create2Salt, erc20Bytecode])
|
|
147
|
+
})
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
export const setup = async ({
|
|
152
|
+
anvilRpc,
|
|
153
|
+
paymasterSigner
|
|
154
|
+
}: {
|
|
155
|
+
anvilRpc: string
|
|
156
|
+
paymasterSigner: Address
|
|
157
|
+
}) => {
|
|
158
|
+
await deployPaymasters({
|
|
159
|
+
anvilRpc,
|
|
160
|
+
paymasterSigner
|
|
161
|
+
})
|
|
162
|
+
await deployErc20Token(anvilRpc)
|
|
163
|
+
}
|
package/singletonPaymasters.ts
CHANGED
|
@@ -9,26 +9,16 @@ import {
|
|
|
9
9
|
concat,
|
|
10
10
|
encodePacked,
|
|
11
11
|
getContract,
|
|
12
|
-
parseEther,
|
|
13
12
|
toBytes
|
|
14
13
|
} from "viem"
|
|
15
14
|
import {
|
|
16
15
|
type UserOperation,
|
|
17
16
|
toPackedUserOperation
|
|
18
17
|
} from "viem/account-abstraction"
|
|
19
|
-
import {
|
|
20
|
-
constants,
|
|
21
|
-
getSingletonPaymaster06Address,
|
|
22
|
-
getSingletonPaymaster06InitCode,
|
|
23
|
-
getSingletonPaymaster07Address,
|
|
24
|
-
getSingletonPaymaster07InitCode,
|
|
25
|
-
getSingletonPaymaster08Address,
|
|
26
|
-
getSingletonPaymaster08InitCode
|
|
27
|
-
} from "./constants.js"
|
|
18
|
+
import { constants } from "./constants.js"
|
|
28
19
|
import {
|
|
29
20
|
singletonPaymaster06Abi,
|
|
30
|
-
singletonPaymaster07Abi
|
|
31
|
-
singletonPaymaster08Abi
|
|
21
|
+
singletonPaymaster07Abi
|
|
32
22
|
} from "./helpers/abi.js"
|
|
33
23
|
import type { PaymasterMode } from "./helpers/utils.js"
|
|
34
24
|
|
|
@@ -238,82 +228,3 @@ export const getSignedPaymasterData = async ({
|
|
|
238
228
|
paymasterData
|
|
239
229
|
}
|
|
240
230
|
}
|
|
241
|
-
|
|
242
|
-
export const deployPaymasters = async ({
|
|
243
|
-
walletClient,
|
|
244
|
-
publicClient
|
|
245
|
-
}: {
|
|
246
|
-
walletClient: WalletClient<Transport, Chain, Account>
|
|
247
|
-
publicClient: PublicClient<Transport, Chain>
|
|
248
|
-
}) => {
|
|
249
|
-
const owner = walletClient.account.address
|
|
250
|
-
|
|
251
|
-
let nonce = await publicClient.getTransactionCount({
|
|
252
|
-
address: walletClient.account.address
|
|
253
|
-
})
|
|
254
|
-
|
|
255
|
-
// Deploy singleton paymaster 06.
|
|
256
|
-
await walletClient.sendTransaction({
|
|
257
|
-
to: constants.deterministicDeployer,
|
|
258
|
-
data: concat([
|
|
259
|
-
constants.create2Salt,
|
|
260
|
-
getSingletonPaymaster06InitCode(walletClient.account.address)
|
|
261
|
-
]),
|
|
262
|
-
nonce: nonce++
|
|
263
|
-
})
|
|
264
|
-
|
|
265
|
-
// Deploy singleton paymaster 07.
|
|
266
|
-
await walletClient.sendTransaction({
|
|
267
|
-
to: constants.deterministicDeployer,
|
|
268
|
-
data: concat([
|
|
269
|
-
constants.create2Salt,
|
|
270
|
-
getSingletonPaymaster07InitCode(walletClient.account.address)
|
|
271
|
-
]),
|
|
272
|
-
nonce: nonce++
|
|
273
|
-
})
|
|
274
|
-
|
|
275
|
-
// Deploy singleton paymaster 08.
|
|
276
|
-
await walletClient.sendTransaction({
|
|
277
|
-
to: constants.deterministicDeployer,
|
|
278
|
-
data: concat([
|
|
279
|
-
constants.create2Salt,
|
|
280
|
-
getSingletonPaymaster08InitCode(walletClient.account.address)
|
|
281
|
-
]),
|
|
282
|
-
nonce: nonce++
|
|
283
|
-
})
|
|
284
|
-
|
|
285
|
-
// Initialize contract instances.
|
|
286
|
-
const [singletonPaymaster06, singletonPaymaster07, singletonPaymaster08] = [
|
|
287
|
-
getContract({
|
|
288
|
-
address: getSingletonPaymaster06Address(owner),
|
|
289
|
-
abi: singletonPaymaster06Abi,
|
|
290
|
-
client: walletClient
|
|
291
|
-
}),
|
|
292
|
-
getContract({
|
|
293
|
-
address: getSingletonPaymaster07Address(owner),
|
|
294
|
-
abi: singletonPaymaster07Abi,
|
|
295
|
-
client: walletClient
|
|
296
|
-
}),
|
|
297
|
-
getContract({
|
|
298
|
-
address: getSingletonPaymaster08Address(owner),
|
|
299
|
-
abi: singletonPaymaster08Abi,
|
|
300
|
-
client: walletClient
|
|
301
|
-
})
|
|
302
|
-
]
|
|
303
|
-
|
|
304
|
-
// Fund the paymasters.
|
|
305
|
-
await singletonPaymaster06.write.deposit({
|
|
306
|
-
value: parseEther("50"),
|
|
307
|
-
nonce: nonce++
|
|
308
|
-
})
|
|
309
|
-
|
|
310
|
-
await singletonPaymaster07.write.deposit({
|
|
311
|
-
value: parseEther("50"),
|
|
312
|
-
nonce: nonce++
|
|
313
|
-
})
|
|
314
|
-
|
|
315
|
-
await singletonPaymaster08.write.deposit({
|
|
316
|
-
value: parseEther("50"),
|
|
317
|
-
nonce: nonce++
|
|
318
|
-
})
|
|
319
|
-
}
|