@dvmkit/dvm-cli 0.0.0 → 0.1.4
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/LICENSE +67 -0
- package/NOTICE +2 -0
- package/README.md +28 -3
- package/dist/_esm-M2HUAA3B.js +883 -0
- package/dist/_esm-NRGECLJ7.js +35 -0
- package/dist/accounts-S747UW3A.js +73 -0
- package/dist/ccip-XZ5F5J6R.js +18 -0
- package/dist/chains-PINFXYUE.js +1460 -0
- package/dist/channel-store-GOV7TEDN.js +62 -0
- package/dist/chunk-3PPOU55E.js +312 -0
- package/dist/chunk-3TBULV3F.js +551 -0
- package/dist/chunk-4AQ4G7L5.js +1447 -0
- package/dist/chunk-5BUV73FO.js +2351 -0
- package/dist/chunk-6AJ7H2VX.js +4387 -0
- package/dist/chunk-6UGZAFIR.js +1485 -0
- package/dist/chunk-7UPZZGC5.js +30063 -0
- package/dist/chunk-ACNNU5RY.js +5485 -0
- package/dist/chunk-BZNZWRBB.js +189 -0
- package/dist/chunk-EY5K4BM3.js +1780 -0
- package/dist/chunk-G3RLVJF5.js +19 -0
- package/dist/chunk-GIDSTROG.js +16614 -0
- package/dist/chunk-HPRIQEJS.js +258 -0
- package/dist/chunk-IC6OXFYW.js +6484 -0
- package/dist/chunk-IYHTITNZ.js +45 -0
- package/dist/chunk-KC4UPK44.js +113 -0
- package/dist/chunk-MMJR6N3J.js +2426 -0
- package/dist/chunk-MTBCEXJ6.js +4602 -0
- package/dist/chunk-ONQMRWY3.js +83 -0
- package/dist/chunk-PHZHPRQE.js +1181 -0
- package/dist/chunk-RA24J4QM.js +3717 -0
- package/dist/chunk-RWBYCM47.js +339 -0
- package/dist/chunk-SLDVIXCS.js +21369 -0
- package/dist/chunk-TO47XRK7.js +24890 -0
- package/dist/chunk-U5TNSUYW.js +1757 -0
- package/dist/chunk-UU6QMSTQ.js +171 -0
- package/dist/chunk-UXQCP26E.js +2691 -0
- package/dist/chunk-XGABM4H5.js +3339 -0
- package/dist/chunk-YZUBKHHA.js +15436 -0
- package/dist/chunk-ZELLQI7F.js +248 -0
- package/dist/chunk-ZGXCK43G.js +9868 -0
- package/dist/client-D3XFLWOK.js +52 -0
- package/dist/dist-7MMV3EZA.js +46 -0
- package/dist/dvm.js +33650 -0
- package/dist/lifecycle-5RLM5JMN.js +29 -0
- package/dist/mine.wasm-DNBKYCTQ.js +12 -0
- package/dist/pocket-refill-GDYSTECR.js +133 -0
- package/dist/secp256k1-4YWQEMGF.js +19 -0
- package/dist/tempo-lifecycle-DHZPQTSB.js +31 -0
- package/dist/tempo-wallet-5FEOI4CF.js +35 -0
- package/dist/wallet-G3VOUCL4.js +30 -0
- package/dist/x402-VNFA3DBY.js +91 -0
- package/package.json +71 -6
- package/skills/dvm/SKILL.md +71 -0
|
@@ -0,0 +1,4387 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { createRequire as __dvmCreateRequire } from "node:module";
|
|
3
|
+
const require = __dvmCreateRequire(import.meta.url);
|
|
4
|
+
import {
|
|
5
|
+
AccountNotFoundError,
|
|
6
|
+
AccountTypeNotSupportedError,
|
|
7
|
+
BlockNotFoundError,
|
|
8
|
+
NotFoundError,
|
|
9
|
+
assertCurrentChain,
|
|
10
|
+
buildRequest,
|
|
11
|
+
createContractEventFilter,
|
|
12
|
+
createFilterRequestScope,
|
|
13
|
+
decodeEventLog,
|
|
14
|
+
encode,
|
|
15
|
+
encodeEventTopics,
|
|
16
|
+
estimateFeesPerGas,
|
|
17
|
+
estimateGas,
|
|
18
|
+
estimateMaxPriorityFeePerGas,
|
|
19
|
+
fillTransaction,
|
|
20
|
+
formatBlock,
|
|
21
|
+
formatLog,
|
|
22
|
+
formatTransactionReceipt,
|
|
23
|
+
formatUnits,
|
|
24
|
+
from3 as from,
|
|
25
|
+
fromAbi,
|
|
26
|
+
getAction,
|
|
27
|
+
getBlock,
|
|
28
|
+
getBlockNumber,
|
|
29
|
+
getChainId,
|
|
30
|
+
getCode,
|
|
31
|
+
getContractError,
|
|
32
|
+
getContractEvents,
|
|
33
|
+
getFilterChanges,
|
|
34
|
+
getGasPrice,
|
|
35
|
+
getHttpRpcClient,
|
|
36
|
+
getLogs,
|
|
37
|
+
getSelector,
|
|
38
|
+
getSocket,
|
|
39
|
+
getTransaction,
|
|
40
|
+
getTransactionError,
|
|
41
|
+
getTransactionReceipt,
|
|
42
|
+
getWebSocketRpcClient,
|
|
43
|
+
observe,
|
|
44
|
+
parseEventLogs,
|
|
45
|
+
parseTransaction,
|
|
46
|
+
parseUnits,
|
|
47
|
+
poll,
|
|
48
|
+
prepareTransactionRequest,
|
|
49
|
+
readContract,
|
|
50
|
+
receiptStatuses,
|
|
51
|
+
recoverAddress2 as recoverAddress,
|
|
52
|
+
sendRawTransaction,
|
|
53
|
+
sendRawTransactionSync,
|
|
54
|
+
sendTransaction,
|
|
55
|
+
sendTransactionSync,
|
|
56
|
+
uninstallFilter,
|
|
57
|
+
verifyHash2 as verifyHash,
|
|
58
|
+
wait,
|
|
59
|
+
waitForTransactionReceipt,
|
|
60
|
+
watchBlockNumber,
|
|
61
|
+
watchContractEvent,
|
|
62
|
+
withRetry,
|
|
63
|
+
writeContract,
|
|
64
|
+
writeContractSync
|
|
65
|
+
} from "./chunk-ZGXCK43G.js";
|
|
66
|
+
import {
|
|
67
|
+
AtomicityNotSupportedError,
|
|
68
|
+
ContractFunctionRevertedError,
|
|
69
|
+
InvalidInputRpcError,
|
|
70
|
+
RawContractError,
|
|
71
|
+
RpcRequestError,
|
|
72
|
+
TransactionRejectedRpcError,
|
|
73
|
+
UnsupportedNonOptionalCapabilityError,
|
|
74
|
+
UserRejectedRequestError,
|
|
75
|
+
WalletConnectSessionSettlementError,
|
|
76
|
+
addressResolverAbi,
|
|
77
|
+
assertRequest,
|
|
78
|
+
call,
|
|
79
|
+
concat,
|
|
80
|
+
createBatchScheduler,
|
|
81
|
+
decodeAbiParameters,
|
|
82
|
+
decodeFunctionResult,
|
|
83
|
+
deploylessCallViaBytecodeBytecode,
|
|
84
|
+
encodeDeployData,
|
|
85
|
+
encodeFunctionData,
|
|
86
|
+
erc20Abi,
|
|
87
|
+
extract,
|
|
88
|
+
formatTransactionRequest,
|
|
89
|
+
getCallError,
|
|
90
|
+
getChainContractAddress,
|
|
91
|
+
getNodeError,
|
|
92
|
+
isAddressEqual,
|
|
93
|
+
localBatchGatewayUrl,
|
|
94
|
+
multicall3Abi,
|
|
95
|
+
multicall3Bytecode,
|
|
96
|
+
serializeStateOverride,
|
|
97
|
+
textResolverAbi,
|
|
98
|
+
toRpc,
|
|
99
|
+
universalResolverResolveAbi,
|
|
100
|
+
universalResolverReverseAbi,
|
|
101
|
+
withResolvers
|
|
102
|
+
} from "./chunk-IC6OXFYW.js";
|
|
103
|
+
import {
|
|
104
|
+
commitmentToVersionedHash,
|
|
105
|
+
getTransactionCount,
|
|
106
|
+
getTypesForEIP712Domain,
|
|
107
|
+
hashMessage,
|
|
108
|
+
hashTypedData,
|
|
109
|
+
serializeTransaction,
|
|
110
|
+
serializeTypedData,
|
|
111
|
+
validateTypedData
|
|
112
|
+
} from "./chunk-PHZHPRQE.js";
|
|
113
|
+
import {
|
|
114
|
+
secp256k1
|
|
115
|
+
} from "./chunk-UXQCP26E.js";
|
|
116
|
+
import {
|
|
117
|
+
AbiConstructorNotFoundError,
|
|
118
|
+
AbiConstructorParamsNotFoundError,
|
|
119
|
+
AbiDecodingZeroDataError,
|
|
120
|
+
BaseError,
|
|
121
|
+
DecodeLogDataMismatch,
|
|
122
|
+
DecodeLogTopicsMismatch,
|
|
123
|
+
ExecutionRevertedError,
|
|
124
|
+
TransactionNotFoundError,
|
|
125
|
+
UnknownNodeError,
|
|
126
|
+
bytesToHex,
|
|
127
|
+
checksumAddress,
|
|
128
|
+
concat as concat2,
|
|
129
|
+
createCursor,
|
|
130
|
+
formatBlockParameter,
|
|
131
|
+
getAddress,
|
|
132
|
+
hexToBigInt,
|
|
133
|
+
hexToBytes,
|
|
134
|
+
hexToNumber,
|
|
135
|
+
isAddress,
|
|
136
|
+
isHex,
|
|
137
|
+
keccak256,
|
|
138
|
+
numberToHex,
|
|
139
|
+
parseAccount,
|
|
140
|
+
size,
|
|
141
|
+
slice,
|
|
142
|
+
sliceHex,
|
|
143
|
+
stringToBytes,
|
|
144
|
+
stringToHex,
|
|
145
|
+
stringify,
|
|
146
|
+
toBytes,
|
|
147
|
+
toHex,
|
|
148
|
+
trim
|
|
149
|
+
} from "./chunk-MMJR6N3J.js";
|
|
150
|
+
|
|
151
|
+
// node_modules/viem/_esm/actions/public/estimateContractGas.js
|
|
152
|
+
async function estimateContractGas(client, parameters) {
|
|
153
|
+
const { abi: abi2, address, args, functionName, dataSuffix = typeof client.dataSuffix === "string" ? client.dataSuffix : client.dataSuffix?.value, ...request } = parameters;
|
|
154
|
+
const data = encodeFunctionData({
|
|
155
|
+
abi: abi2,
|
|
156
|
+
args,
|
|
157
|
+
functionName
|
|
158
|
+
});
|
|
159
|
+
try {
|
|
160
|
+
const gas = await getAction(client, estimateGas, "estimateGas")({
|
|
161
|
+
data: `${data}${dataSuffix ? dataSuffix.replace("0x", "") : ""}`,
|
|
162
|
+
to: address,
|
|
163
|
+
...request
|
|
164
|
+
});
|
|
165
|
+
return gas;
|
|
166
|
+
} catch (error) {
|
|
167
|
+
const account = request.account ? parseAccount(request.account) : void 0;
|
|
168
|
+
throw getContractError(error, {
|
|
169
|
+
abi: abi2,
|
|
170
|
+
address,
|
|
171
|
+
args,
|
|
172
|
+
docsPath: "/docs/contract/estimateContractGas",
|
|
173
|
+
functionName,
|
|
174
|
+
sender: account?.address
|
|
175
|
+
});
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
// node_modules/viem/_esm/actions/public/simulateContract.js
|
|
180
|
+
async function simulateContract(client, parameters) {
|
|
181
|
+
const { abi: abi2, address, args, functionName, dataSuffix = typeof client.dataSuffix === "string" ? client.dataSuffix : client.dataSuffix?.value, ...callRequest } = parameters;
|
|
182
|
+
const account = callRequest.account ? parseAccount(callRequest.account) : client.account;
|
|
183
|
+
const calldata = encodeFunctionData({ abi: abi2, args, functionName });
|
|
184
|
+
try {
|
|
185
|
+
const { data } = await getAction(client, call, "call")({
|
|
186
|
+
batch: false,
|
|
187
|
+
data: `${calldata}${dataSuffix ? dataSuffix.replace("0x", "") : ""}`,
|
|
188
|
+
to: address,
|
|
189
|
+
...callRequest,
|
|
190
|
+
account
|
|
191
|
+
});
|
|
192
|
+
const result = decodeFunctionResult({
|
|
193
|
+
abi: abi2,
|
|
194
|
+
args,
|
|
195
|
+
functionName,
|
|
196
|
+
data: data || "0x"
|
|
197
|
+
});
|
|
198
|
+
const minimizedAbi = abi2.filter((abiItem) => "name" in abiItem && abiItem.name === parameters.functionName);
|
|
199
|
+
return {
|
|
200
|
+
result,
|
|
201
|
+
request: {
|
|
202
|
+
abi: minimizedAbi,
|
|
203
|
+
address,
|
|
204
|
+
args,
|
|
205
|
+
dataSuffix,
|
|
206
|
+
functionName,
|
|
207
|
+
...callRequest,
|
|
208
|
+
account
|
|
209
|
+
}
|
|
210
|
+
};
|
|
211
|
+
} catch (error) {
|
|
212
|
+
throw getContractError(error, {
|
|
213
|
+
abi: abi2,
|
|
214
|
+
address,
|
|
215
|
+
args,
|
|
216
|
+
docsPath: "/docs/contract/simulateContract",
|
|
217
|
+
functionName,
|
|
218
|
+
sender: account?.address
|
|
219
|
+
});
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
// node_modules/viem/_esm/actions/getContract.js
|
|
224
|
+
function getContract({ abi: abi2, address, client: client_ }) {
|
|
225
|
+
const client = client_;
|
|
226
|
+
const [publicClient, walletClient] = (() => {
|
|
227
|
+
if (!client)
|
|
228
|
+
return [void 0, void 0];
|
|
229
|
+
if ("public" in client && "wallet" in client)
|
|
230
|
+
return [client.public, client.wallet];
|
|
231
|
+
if ("public" in client)
|
|
232
|
+
return [client.public, void 0];
|
|
233
|
+
if ("wallet" in client)
|
|
234
|
+
return [void 0, client.wallet];
|
|
235
|
+
return [client, client];
|
|
236
|
+
})();
|
|
237
|
+
const hasPublicClient = publicClient !== void 0 && publicClient !== null;
|
|
238
|
+
const hasWalletClient = walletClient !== void 0 && walletClient !== null;
|
|
239
|
+
const contract = {};
|
|
240
|
+
let hasReadFunction = false;
|
|
241
|
+
let hasWriteFunction = false;
|
|
242
|
+
let hasEvent = false;
|
|
243
|
+
for (const item of abi2) {
|
|
244
|
+
if (item.type === "function")
|
|
245
|
+
if (item.stateMutability === "view" || item.stateMutability === "pure")
|
|
246
|
+
hasReadFunction = true;
|
|
247
|
+
else
|
|
248
|
+
hasWriteFunction = true;
|
|
249
|
+
else if (item.type === "event")
|
|
250
|
+
hasEvent = true;
|
|
251
|
+
if (hasReadFunction && hasWriteFunction && hasEvent)
|
|
252
|
+
break;
|
|
253
|
+
}
|
|
254
|
+
if (hasPublicClient) {
|
|
255
|
+
if (hasReadFunction)
|
|
256
|
+
contract.read = new Proxy({}, {
|
|
257
|
+
get(_, functionName) {
|
|
258
|
+
return (...parameters) => {
|
|
259
|
+
const { args, options } = getFunctionParameters(parameters);
|
|
260
|
+
return getAction(publicClient, readContract, "readContract")({
|
|
261
|
+
abi: abi2,
|
|
262
|
+
address,
|
|
263
|
+
functionName,
|
|
264
|
+
args,
|
|
265
|
+
...options
|
|
266
|
+
});
|
|
267
|
+
};
|
|
268
|
+
}
|
|
269
|
+
});
|
|
270
|
+
if (hasWriteFunction)
|
|
271
|
+
contract.simulate = new Proxy({}, {
|
|
272
|
+
get(_, functionName) {
|
|
273
|
+
return (...parameters) => {
|
|
274
|
+
const { args, options } = getFunctionParameters(parameters);
|
|
275
|
+
return getAction(publicClient, simulateContract, "simulateContract")({
|
|
276
|
+
abi: abi2,
|
|
277
|
+
address,
|
|
278
|
+
functionName,
|
|
279
|
+
args,
|
|
280
|
+
...options
|
|
281
|
+
});
|
|
282
|
+
};
|
|
283
|
+
}
|
|
284
|
+
});
|
|
285
|
+
if (hasEvent) {
|
|
286
|
+
contract.createEventFilter = new Proxy({}, {
|
|
287
|
+
get(_, eventName) {
|
|
288
|
+
return (...parameters) => {
|
|
289
|
+
const abiEvent = abi2.find((x) => x.type === "event" && x.name === eventName);
|
|
290
|
+
const { args, options } = getEventParameters(parameters, abiEvent);
|
|
291
|
+
return getAction(publicClient, createContractEventFilter, "createContractEventFilter")({
|
|
292
|
+
abi: abi2,
|
|
293
|
+
address,
|
|
294
|
+
eventName,
|
|
295
|
+
args,
|
|
296
|
+
...options
|
|
297
|
+
});
|
|
298
|
+
};
|
|
299
|
+
}
|
|
300
|
+
});
|
|
301
|
+
contract.getEvents = new Proxy({}, {
|
|
302
|
+
get(_, eventName) {
|
|
303
|
+
return (...parameters) => {
|
|
304
|
+
const abiEvent = abi2.find((x) => x.type === "event" && x.name === eventName);
|
|
305
|
+
const { args, options } = getEventParameters(parameters, abiEvent);
|
|
306
|
+
return getAction(publicClient, getContractEvents, "getContractEvents")({
|
|
307
|
+
abi: abi2,
|
|
308
|
+
address,
|
|
309
|
+
eventName,
|
|
310
|
+
args,
|
|
311
|
+
...options
|
|
312
|
+
});
|
|
313
|
+
};
|
|
314
|
+
}
|
|
315
|
+
});
|
|
316
|
+
contract.watchEvent = new Proxy({}, {
|
|
317
|
+
get(_, eventName) {
|
|
318
|
+
return (...parameters) => {
|
|
319
|
+
const abiEvent = abi2.find((x) => x.type === "event" && x.name === eventName);
|
|
320
|
+
const { args, options } = getEventParameters(parameters, abiEvent);
|
|
321
|
+
return getAction(publicClient, watchContractEvent, "watchContractEvent")({
|
|
322
|
+
abi: abi2,
|
|
323
|
+
address,
|
|
324
|
+
eventName,
|
|
325
|
+
args,
|
|
326
|
+
...options
|
|
327
|
+
});
|
|
328
|
+
};
|
|
329
|
+
}
|
|
330
|
+
});
|
|
331
|
+
}
|
|
332
|
+
}
|
|
333
|
+
if (hasWalletClient) {
|
|
334
|
+
if (hasWriteFunction)
|
|
335
|
+
contract.write = new Proxy({}, {
|
|
336
|
+
get(_, functionName) {
|
|
337
|
+
return (...parameters) => {
|
|
338
|
+
const { args, options } = getFunctionParameters(parameters);
|
|
339
|
+
return getAction(walletClient, writeContract, "writeContract")({
|
|
340
|
+
abi: abi2,
|
|
341
|
+
address,
|
|
342
|
+
functionName,
|
|
343
|
+
args,
|
|
344
|
+
...options
|
|
345
|
+
});
|
|
346
|
+
};
|
|
347
|
+
}
|
|
348
|
+
});
|
|
349
|
+
}
|
|
350
|
+
if (hasPublicClient || hasWalletClient) {
|
|
351
|
+
if (hasWriteFunction)
|
|
352
|
+
contract.estimateGas = new Proxy({}, {
|
|
353
|
+
get(_, functionName) {
|
|
354
|
+
return (...parameters) => {
|
|
355
|
+
const { args, options } = getFunctionParameters(parameters);
|
|
356
|
+
const client2 = publicClient ?? walletClient;
|
|
357
|
+
return getAction(client2, estimateContractGas, "estimateContractGas")({
|
|
358
|
+
abi: abi2,
|
|
359
|
+
address,
|
|
360
|
+
functionName,
|
|
361
|
+
args,
|
|
362
|
+
...options,
|
|
363
|
+
account: options.account ?? walletClient.account
|
|
364
|
+
});
|
|
365
|
+
};
|
|
366
|
+
}
|
|
367
|
+
});
|
|
368
|
+
}
|
|
369
|
+
contract.address = address;
|
|
370
|
+
contract.abi = abi2;
|
|
371
|
+
return contract;
|
|
372
|
+
}
|
|
373
|
+
function getFunctionParameters(values) {
|
|
374
|
+
const hasArgs = values.length && Array.isArray(values[0]);
|
|
375
|
+
const args = hasArgs ? values[0] : [];
|
|
376
|
+
const options = (hasArgs ? values[1] : values[0]) ?? {};
|
|
377
|
+
return { args, options };
|
|
378
|
+
}
|
|
379
|
+
function getEventParameters(values, abiEvent) {
|
|
380
|
+
let hasArgs = false;
|
|
381
|
+
if (Array.isArray(values[0]))
|
|
382
|
+
hasArgs = true;
|
|
383
|
+
else if (values.length === 1) {
|
|
384
|
+
hasArgs = abiEvent.inputs.some((x) => x.indexed);
|
|
385
|
+
} else if (values.length === 2) {
|
|
386
|
+
hasArgs = true;
|
|
387
|
+
}
|
|
388
|
+
const args = hasArgs ? values[0] : void 0;
|
|
389
|
+
const options = (hasArgs ? values[1] : values[0]) ?? {};
|
|
390
|
+
return { args, options };
|
|
391
|
+
}
|
|
392
|
+
|
|
393
|
+
// node_modules/viem/_esm/errors/calls.js
|
|
394
|
+
var BundleFailedError = class extends BaseError {
|
|
395
|
+
constructor(result) {
|
|
396
|
+
super(`Call bundle failed with status: ${result.statusCode}`, {
|
|
397
|
+
name: "BundleFailedError"
|
|
398
|
+
});
|
|
399
|
+
Object.defineProperty(this, "result", {
|
|
400
|
+
enumerable: true,
|
|
401
|
+
configurable: true,
|
|
402
|
+
writable: true,
|
|
403
|
+
value: void 0
|
|
404
|
+
});
|
|
405
|
+
this.result = result;
|
|
406
|
+
}
|
|
407
|
+
};
|
|
408
|
+
|
|
409
|
+
// node_modules/viem/_esm/actions/wallet/sendCalls.js
|
|
410
|
+
var fallbackMagicIdentifier = "0x5792579257925792579257925792579257925792579257925792579257925792";
|
|
411
|
+
var fallbackTransactionErrorMagicIdentifier = numberToHex(0, {
|
|
412
|
+
size: 32
|
|
413
|
+
});
|
|
414
|
+
async function sendCalls(client, parameters) {
|
|
415
|
+
const { account: account_ = client.account, chain = client.chain, experimental_fallback, experimental_fallbackDelay = 32, forceAtomic = false, id, version = "2.0.0" } = parameters;
|
|
416
|
+
const account = account_ ? parseAccount(account_) : null;
|
|
417
|
+
let capabilities = parameters.capabilities;
|
|
418
|
+
if (client.dataSuffix && !parameters.capabilities?.dataSuffix) {
|
|
419
|
+
if (typeof client.dataSuffix === "string")
|
|
420
|
+
capabilities = {
|
|
421
|
+
...parameters.capabilities,
|
|
422
|
+
dataSuffix: { value: client.dataSuffix, optional: true }
|
|
423
|
+
};
|
|
424
|
+
else
|
|
425
|
+
capabilities = {
|
|
426
|
+
...parameters.capabilities,
|
|
427
|
+
dataSuffix: {
|
|
428
|
+
value: client.dataSuffix.value,
|
|
429
|
+
...client.dataSuffix.required ? {} : { optional: true }
|
|
430
|
+
}
|
|
431
|
+
};
|
|
432
|
+
}
|
|
433
|
+
const calls = parameters.calls.map((call_) => {
|
|
434
|
+
const call2 = call_;
|
|
435
|
+
const data = call2.abi ? encodeFunctionData({
|
|
436
|
+
abi: call2.abi,
|
|
437
|
+
functionName: call2.functionName,
|
|
438
|
+
args: call2.args
|
|
439
|
+
}) : call2.data;
|
|
440
|
+
return {
|
|
441
|
+
data: call2.dataSuffix && data ? concat2([data, call2.dataSuffix]) : data,
|
|
442
|
+
to: call2.to,
|
|
443
|
+
value: call2.value ? numberToHex(call2.value) : void 0
|
|
444
|
+
};
|
|
445
|
+
});
|
|
446
|
+
try {
|
|
447
|
+
const response = await client.request({
|
|
448
|
+
method: "wallet_sendCalls",
|
|
449
|
+
params: [
|
|
450
|
+
{
|
|
451
|
+
atomicRequired: forceAtomic,
|
|
452
|
+
calls,
|
|
453
|
+
capabilities,
|
|
454
|
+
chainId: numberToHex(chain.id),
|
|
455
|
+
from: account?.address,
|
|
456
|
+
id,
|
|
457
|
+
version
|
|
458
|
+
}
|
|
459
|
+
]
|
|
460
|
+
}, { retryCount: 0 });
|
|
461
|
+
if (typeof response === "string")
|
|
462
|
+
return { id: response };
|
|
463
|
+
return response;
|
|
464
|
+
} catch (err) {
|
|
465
|
+
const error = err;
|
|
466
|
+
if (experimental_fallback && (error.name === "MethodNotFoundRpcError" || error.name === "MethodNotSupportedRpcError" || error.name === "UnknownRpcError" || error.details.toLowerCase().includes("does not exist / is not available") || error.details.toLowerCase().includes("missing or invalid. request()") || error.details.toLowerCase().includes("did not match any variant of untagged enum") || error.details.toLowerCase().includes("account upgraded to unsupported contract") || error.details.toLowerCase().includes("eip-7702 not supported") || error.details.toLowerCase().includes("unsupported wc_ method") || // magic.link
|
|
467
|
+
error.details.toLowerCase().includes("feature toggled misconfigured") || // Trust Wallet
|
|
468
|
+
error.details.toLowerCase().includes("jsonrpcengine: response has no error or result for request"))) {
|
|
469
|
+
if (capabilities) {
|
|
470
|
+
const hasNonOptionalCapability = Object.values(capabilities).some((capability) => !capability.optional);
|
|
471
|
+
if (hasNonOptionalCapability) {
|
|
472
|
+
const message = "non-optional `capabilities` are not supported on fallback to `eth_sendTransaction`.";
|
|
473
|
+
throw new UnsupportedNonOptionalCapabilityError(new BaseError(message, {
|
|
474
|
+
details: message
|
|
475
|
+
}));
|
|
476
|
+
}
|
|
477
|
+
}
|
|
478
|
+
if (forceAtomic && calls.length > 1) {
|
|
479
|
+
const message = "`forceAtomic` is not supported on fallback to `eth_sendTransaction`.";
|
|
480
|
+
throw new AtomicityNotSupportedError(new BaseError(message, {
|
|
481
|
+
details: message
|
|
482
|
+
}));
|
|
483
|
+
}
|
|
484
|
+
const results = [];
|
|
485
|
+
for (const call2 of calls) {
|
|
486
|
+
try {
|
|
487
|
+
const value = await sendTransaction(client, {
|
|
488
|
+
account,
|
|
489
|
+
chain,
|
|
490
|
+
data: call2.data,
|
|
491
|
+
to: call2.to,
|
|
492
|
+
value: call2.value ? hexToBigInt(call2.value) : void 0
|
|
493
|
+
});
|
|
494
|
+
results.push({ status: "fulfilled", value });
|
|
495
|
+
} catch (reason) {
|
|
496
|
+
results.push({ reason, status: "rejected" });
|
|
497
|
+
}
|
|
498
|
+
if (experimental_fallbackDelay > 0)
|
|
499
|
+
await new Promise((resolve) => setTimeout(resolve, experimental_fallbackDelay));
|
|
500
|
+
}
|
|
501
|
+
if (results.every((r) => r.status === "rejected"))
|
|
502
|
+
throw results[0].reason;
|
|
503
|
+
const hashes = results.map((result) => {
|
|
504
|
+
if (result.status === "fulfilled")
|
|
505
|
+
return result.value;
|
|
506
|
+
return fallbackTransactionErrorMagicIdentifier;
|
|
507
|
+
});
|
|
508
|
+
return {
|
|
509
|
+
id: concat2([
|
|
510
|
+
...hashes,
|
|
511
|
+
numberToHex(chain.id, { size: 32 }),
|
|
512
|
+
fallbackMagicIdentifier
|
|
513
|
+
])
|
|
514
|
+
};
|
|
515
|
+
}
|
|
516
|
+
throw getTransactionError(err, {
|
|
517
|
+
...parameters,
|
|
518
|
+
account,
|
|
519
|
+
chain: parameters.chain
|
|
520
|
+
});
|
|
521
|
+
}
|
|
522
|
+
}
|
|
523
|
+
|
|
524
|
+
// node_modules/viem/_esm/actions/wallet/getCallsStatus.js
|
|
525
|
+
async function getCallsStatus(client, parameters) {
|
|
526
|
+
async function getStatus(id) {
|
|
527
|
+
const isTransactions = id.endsWith(fallbackMagicIdentifier.slice(2));
|
|
528
|
+
if (isTransactions) {
|
|
529
|
+
const chainId2 = trim(sliceHex(id, -64, -32));
|
|
530
|
+
const hashes = sliceHex(id, 0, -64).slice(2).match(/.{1,64}/g);
|
|
531
|
+
const receipts2 = await Promise.all(hashes.map((hash) => fallbackTransactionErrorMagicIdentifier.slice(2) !== hash ? client.request({
|
|
532
|
+
method: "eth_getTransactionReceipt",
|
|
533
|
+
params: [`0x${hash}`]
|
|
534
|
+
}, { dedupe: true }) : void 0));
|
|
535
|
+
const status2 = (() => {
|
|
536
|
+
if (receipts2.some((r) => r === null))
|
|
537
|
+
return 100;
|
|
538
|
+
if (receipts2.every((r) => r?.status === "0x1"))
|
|
539
|
+
return 200;
|
|
540
|
+
if (receipts2.every((r) => r?.status === "0x0"))
|
|
541
|
+
return 500;
|
|
542
|
+
return 600;
|
|
543
|
+
})();
|
|
544
|
+
return {
|
|
545
|
+
atomic: false,
|
|
546
|
+
chainId: hexToNumber(chainId2),
|
|
547
|
+
receipts: receipts2.filter(Boolean),
|
|
548
|
+
status: status2,
|
|
549
|
+
version: "2.0.0"
|
|
550
|
+
};
|
|
551
|
+
}
|
|
552
|
+
return client.request({
|
|
553
|
+
method: "wallet_getCallsStatus",
|
|
554
|
+
params: [id]
|
|
555
|
+
});
|
|
556
|
+
}
|
|
557
|
+
const { atomic = false, chainId, receipts, version = "2.0.0", ...response } = await getStatus(parameters.id);
|
|
558
|
+
const [status, statusCode] = (() => {
|
|
559
|
+
const statusCode2 = response.status;
|
|
560
|
+
if (statusCode2 >= 100 && statusCode2 < 200)
|
|
561
|
+
return ["pending", statusCode2];
|
|
562
|
+
if (statusCode2 >= 200 && statusCode2 < 300)
|
|
563
|
+
return ["success", statusCode2];
|
|
564
|
+
if (statusCode2 >= 300 && statusCode2 < 700)
|
|
565
|
+
return ["failure", statusCode2];
|
|
566
|
+
if (statusCode2 === "CONFIRMED")
|
|
567
|
+
return ["success", 200];
|
|
568
|
+
if (statusCode2 === "PENDING")
|
|
569
|
+
return ["pending", 100];
|
|
570
|
+
return [void 0, statusCode2];
|
|
571
|
+
})();
|
|
572
|
+
return {
|
|
573
|
+
...response,
|
|
574
|
+
atomic,
|
|
575
|
+
// @ts-expect-error: for backwards compatibility
|
|
576
|
+
chainId: chainId ? hexToNumber(chainId) : void 0,
|
|
577
|
+
receipts: receipts?.map((receipt) => ({
|
|
578
|
+
...receipt,
|
|
579
|
+
blockNumber: hexToBigInt(receipt.blockNumber),
|
|
580
|
+
gasUsed: hexToBigInt(receipt.gasUsed),
|
|
581
|
+
status: receiptStatuses[receipt.status]
|
|
582
|
+
})) ?? [],
|
|
583
|
+
statusCode,
|
|
584
|
+
status,
|
|
585
|
+
version
|
|
586
|
+
};
|
|
587
|
+
}
|
|
588
|
+
|
|
589
|
+
// node_modules/viem/_esm/actions/wallet/waitForCallsStatus.js
|
|
590
|
+
async function waitForCallsStatus(client, parameters) {
|
|
591
|
+
const {
|
|
592
|
+
id,
|
|
593
|
+
pollingInterval = client.pollingInterval,
|
|
594
|
+
status = ({ statusCode }) => statusCode === 200 || statusCode >= 300,
|
|
595
|
+
retryCount = 4,
|
|
596
|
+
retryDelay = ({ count }) => ~~(1 << count) * 200,
|
|
597
|
+
// exponential backoff
|
|
598
|
+
timeout = 6e4,
|
|
599
|
+
throwOnFailure = false
|
|
600
|
+
} = parameters;
|
|
601
|
+
const observerId = stringify(["waitForCallsStatus", client.uid, id]);
|
|
602
|
+
const { promise, resolve, reject } = withResolvers();
|
|
603
|
+
let timer;
|
|
604
|
+
const unobserve = observe(observerId, { resolve, reject }, (emit) => {
|
|
605
|
+
const unpoll = poll(async () => {
|
|
606
|
+
const done = (fn) => {
|
|
607
|
+
clearTimeout(timer);
|
|
608
|
+
unpoll();
|
|
609
|
+
fn();
|
|
610
|
+
unobserve();
|
|
611
|
+
};
|
|
612
|
+
try {
|
|
613
|
+
const result = await withRetry(async () => {
|
|
614
|
+
const result2 = await getAction(client, getCallsStatus, "getCallsStatus")({ id });
|
|
615
|
+
if (throwOnFailure && result2.status === "failure")
|
|
616
|
+
throw new BundleFailedError(result2);
|
|
617
|
+
return result2;
|
|
618
|
+
}, {
|
|
619
|
+
retryCount,
|
|
620
|
+
delay: retryDelay
|
|
621
|
+
});
|
|
622
|
+
if (!status(result))
|
|
623
|
+
return;
|
|
624
|
+
done(() => emit.resolve(result));
|
|
625
|
+
} catch (error) {
|
|
626
|
+
done(() => emit.reject(error));
|
|
627
|
+
}
|
|
628
|
+
}, {
|
|
629
|
+
interval: pollingInterval,
|
|
630
|
+
emitOnBegin: true
|
|
631
|
+
});
|
|
632
|
+
return unpoll;
|
|
633
|
+
});
|
|
634
|
+
timer = timeout ? setTimeout(() => {
|
|
635
|
+
unobserve();
|
|
636
|
+
clearTimeout(timer);
|
|
637
|
+
reject(new WaitForCallsStatusTimeoutError({ id }));
|
|
638
|
+
}, timeout) : void 0;
|
|
639
|
+
return await promise;
|
|
640
|
+
}
|
|
641
|
+
var WaitForCallsStatusTimeoutError = class extends BaseError {
|
|
642
|
+
constructor({ id }) {
|
|
643
|
+
super(`Timed out while waiting for call bundle with id "${id}" to be confirmed.`, { name: "WaitForCallsStatusTimeoutError" });
|
|
644
|
+
}
|
|
645
|
+
};
|
|
646
|
+
|
|
647
|
+
// node_modules/viem/_esm/utils/uid.js
|
|
648
|
+
var size2 = 256;
|
|
649
|
+
var index = size2;
|
|
650
|
+
var buffer;
|
|
651
|
+
function uid(length = 11) {
|
|
652
|
+
if (!buffer || index + length > size2 * 2) {
|
|
653
|
+
buffer = "";
|
|
654
|
+
index = 0;
|
|
655
|
+
for (let i = 0; i < size2; i++) {
|
|
656
|
+
buffer += (256 + Math.random() * 256 | 0).toString(16).substring(1);
|
|
657
|
+
}
|
|
658
|
+
}
|
|
659
|
+
return buffer.substring(index, index++ + length);
|
|
660
|
+
}
|
|
661
|
+
|
|
662
|
+
// node_modules/viem/_esm/clients/createClient.js
|
|
663
|
+
function createClient(parameters) {
|
|
664
|
+
const { batch, chain, ccipRead, dataSuffix, key = "base", name = "Base Client", tokens, type = "base" } = parameters;
|
|
665
|
+
const experimental_blockTag = parameters.experimental_blockTag ?? (typeof chain?.experimental_preconfirmationTime === "number" ? "pending" : void 0);
|
|
666
|
+
const blockTime = chain?.blockTime ?? 12e3;
|
|
667
|
+
const defaultPollingInterval = Math.min(Math.max(Math.floor(blockTime / 2), 500), 4e3);
|
|
668
|
+
const pollingInterval = parameters.pollingInterval ?? defaultPollingInterval;
|
|
669
|
+
const cacheTime = parameters.cacheTime ?? pollingInterval;
|
|
670
|
+
const account = parameters.account ? parseAccount(parameters.account) : void 0;
|
|
671
|
+
const { config, request, value } = parameters.transport({
|
|
672
|
+
account,
|
|
673
|
+
chain,
|
|
674
|
+
pollingInterval
|
|
675
|
+
});
|
|
676
|
+
const transport = { ...config, ...value };
|
|
677
|
+
const client = {
|
|
678
|
+
account,
|
|
679
|
+
batch,
|
|
680
|
+
cacheTime,
|
|
681
|
+
ccipRead,
|
|
682
|
+
chain,
|
|
683
|
+
dataSuffix,
|
|
684
|
+
key,
|
|
685
|
+
name,
|
|
686
|
+
pollingInterval,
|
|
687
|
+
request,
|
|
688
|
+
tokens,
|
|
689
|
+
transport,
|
|
690
|
+
type,
|
|
691
|
+
uid: uid(),
|
|
692
|
+
...experimental_blockTag ? { experimental_blockTag } : {}
|
|
693
|
+
};
|
|
694
|
+
function extend(base) {
|
|
695
|
+
return (extendFn) => {
|
|
696
|
+
const extended = extendFn(base);
|
|
697
|
+
for (const key2 in client)
|
|
698
|
+
delete extended[key2];
|
|
699
|
+
const combined = { ...base, ...extended };
|
|
700
|
+
for (const key2 in extended) {
|
|
701
|
+
const a = base[key2];
|
|
702
|
+
const b = extended[key2];
|
|
703
|
+
if (isPlainObject(a) && isPlainObject(b))
|
|
704
|
+
combined[key2] = { ...a, ...b };
|
|
705
|
+
}
|
|
706
|
+
return Object.assign(combined, { extend: extend(combined) });
|
|
707
|
+
};
|
|
708
|
+
}
|
|
709
|
+
return Object.assign(client, { extend: extend(client) });
|
|
710
|
+
}
|
|
711
|
+
function isPlainObject(value) {
|
|
712
|
+
if (typeof value !== "object" || value === null)
|
|
713
|
+
return false;
|
|
714
|
+
const prototype = Object.getPrototypeOf(value);
|
|
715
|
+
return prototype === Object.prototype || prototype === null;
|
|
716
|
+
}
|
|
717
|
+
function bindActionDecorators(client, action) {
|
|
718
|
+
const wrapped = (parameters = {}) => action(client, parameters);
|
|
719
|
+
for (const key of [
|
|
720
|
+
"call",
|
|
721
|
+
"calls",
|
|
722
|
+
"callWithPeriod",
|
|
723
|
+
"estimateGas",
|
|
724
|
+
"prepare",
|
|
725
|
+
"prepareRecipient",
|
|
726
|
+
"simulate"
|
|
727
|
+
])
|
|
728
|
+
if (Object.hasOwn(action, key)) {
|
|
729
|
+
const helper = action[key];
|
|
730
|
+
wrapped[key] = (args = {}) => {
|
|
731
|
+
if (helper.length === 1)
|
|
732
|
+
return helper(args);
|
|
733
|
+
return helper(client, args);
|
|
734
|
+
};
|
|
735
|
+
}
|
|
736
|
+
for (const key of ["extractEvent", "extractEvents"])
|
|
737
|
+
if (Object.hasOwn(action, key))
|
|
738
|
+
wrapped[key] = action[key];
|
|
739
|
+
return wrapped;
|
|
740
|
+
}
|
|
741
|
+
function rpcSchema() {
|
|
742
|
+
return null;
|
|
743
|
+
}
|
|
744
|
+
|
|
745
|
+
// node_modules/viem/_esm/utils/ens/errors.js
|
|
746
|
+
function isNullUniversalResolverError(err) {
|
|
747
|
+
if (!(err instanceof BaseError))
|
|
748
|
+
return false;
|
|
749
|
+
const cause = err.walk((e) => e instanceof ContractFunctionRevertedError);
|
|
750
|
+
if (!(cause instanceof ContractFunctionRevertedError))
|
|
751
|
+
return false;
|
|
752
|
+
if (cause.data?.errorName === "HttpError")
|
|
753
|
+
return true;
|
|
754
|
+
if (cause.data?.errorName === "ResolverError")
|
|
755
|
+
return true;
|
|
756
|
+
if (cause.data?.errorName === "ResolverNotContract")
|
|
757
|
+
return true;
|
|
758
|
+
if (cause.data?.errorName === "ResolverNotFound")
|
|
759
|
+
return true;
|
|
760
|
+
if (cause.data?.errorName === "ReverseAddressMismatch")
|
|
761
|
+
return true;
|
|
762
|
+
if (cause.data?.errorName === "UnsupportedResolverProfile")
|
|
763
|
+
return true;
|
|
764
|
+
return false;
|
|
765
|
+
}
|
|
766
|
+
|
|
767
|
+
// node_modules/viem/_esm/utils/ens/encodedLabelToLabelhash.js
|
|
768
|
+
function encodedLabelToLabelhash(label) {
|
|
769
|
+
if (label.length !== 66)
|
|
770
|
+
return null;
|
|
771
|
+
if (label.indexOf("[") !== 0)
|
|
772
|
+
return null;
|
|
773
|
+
if (label.indexOf("]") !== 65)
|
|
774
|
+
return null;
|
|
775
|
+
const hash = `0x${label.slice(1, 65)}`;
|
|
776
|
+
if (!isHex(hash))
|
|
777
|
+
return null;
|
|
778
|
+
return hash;
|
|
779
|
+
}
|
|
780
|
+
|
|
781
|
+
// node_modules/viem/_esm/utils/ens/namehash.js
|
|
782
|
+
function namehash(name) {
|
|
783
|
+
let result = new Uint8Array(32).fill(0);
|
|
784
|
+
if (!name)
|
|
785
|
+
return bytesToHex(result);
|
|
786
|
+
const labels = name.split(".");
|
|
787
|
+
for (let i = labels.length - 1; i >= 0; i -= 1) {
|
|
788
|
+
const hashFromEncodedLabel = encodedLabelToLabelhash(labels[i]);
|
|
789
|
+
const hashed = hashFromEncodedLabel ? toBytes(hashFromEncodedLabel) : keccak256(stringToBytes(labels[i]), "bytes");
|
|
790
|
+
result = keccak256(concat2([result, hashed]), "bytes");
|
|
791
|
+
}
|
|
792
|
+
return bytesToHex(result);
|
|
793
|
+
}
|
|
794
|
+
|
|
795
|
+
// node_modules/viem/_esm/utils/ens/encodeLabelhash.js
|
|
796
|
+
function encodeLabelhash(hash) {
|
|
797
|
+
return `[${hash.slice(2)}]`;
|
|
798
|
+
}
|
|
799
|
+
|
|
800
|
+
// node_modules/viem/_esm/utils/ens/labelhash.js
|
|
801
|
+
function labelhash(label) {
|
|
802
|
+
const result = new Uint8Array(32).fill(0);
|
|
803
|
+
if (!label)
|
|
804
|
+
return bytesToHex(result);
|
|
805
|
+
return encodedLabelToLabelhash(label) || keccak256(stringToBytes(label));
|
|
806
|
+
}
|
|
807
|
+
|
|
808
|
+
// node_modules/viem/_esm/utils/ens/packetToBytes.js
|
|
809
|
+
function packetToBytes(packet) {
|
|
810
|
+
const value = packet.replace(/^\.|\.$/gm, "");
|
|
811
|
+
if (value.length === 0)
|
|
812
|
+
return new Uint8Array(1);
|
|
813
|
+
const bytes = new Uint8Array(stringToBytes(value).byteLength + 2);
|
|
814
|
+
let offset = 0;
|
|
815
|
+
const list = value.split(".");
|
|
816
|
+
for (let i = 0; i < list.length; i++) {
|
|
817
|
+
let encoded = stringToBytes(list[i]);
|
|
818
|
+
if (encoded.byteLength > 255)
|
|
819
|
+
encoded = stringToBytes(encodeLabelhash(labelhash(list[i])));
|
|
820
|
+
bytes[offset] = encoded.length;
|
|
821
|
+
bytes.set(encoded, offset + 1);
|
|
822
|
+
offset += encoded.length + 1;
|
|
823
|
+
}
|
|
824
|
+
if (bytes.byteLength !== offset + 1)
|
|
825
|
+
return bytes.slice(0, offset + 1);
|
|
826
|
+
return bytes;
|
|
827
|
+
}
|
|
828
|
+
|
|
829
|
+
// node_modules/viem/_esm/actions/ens/getEnsAddress.js
|
|
830
|
+
async function getEnsAddress(client, parameters) {
|
|
831
|
+
const { blockNumber, blockTag, coinType, name, gatewayUrls, strict } = parameters;
|
|
832
|
+
const { chain } = client;
|
|
833
|
+
const universalResolverAddress = (() => {
|
|
834
|
+
if (parameters.universalResolverAddress)
|
|
835
|
+
return parameters.universalResolverAddress;
|
|
836
|
+
if (!chain)
|
|
837
|
+
throw new Error("client chain not configured. universalResolverAddress is required.");
|
|
838
|
+
return getChainContractAddress({
|
|
839
|
+
blockNumber,
|
|
840
|
+
chain,
|
|
841
|
+
contract: "ensUniversalResolver"
|
|
842
|
+
});
|
|
843
|
+
})();
|
|
844
|
+
const tlds = chain?.ensTlds;
|
|
845
|
+
if (tlds && !tlds.some((tld) => name.endsWith(tld)))
|
|
846
|
+
return null;
|
|
847
|
+
const args = (() => {
|
|
848
|
+
if (coinType != null)
|
|
849
|
+
return [namehash(name), BigInt(coinType)];
|
|
850
|
+
return [namehash(name)];
|
|
851
|
+
})();
|
|
852
|
+
try {
|
|
853
|
+
const functionData = encodeFunctionData({
|
|
854
|
+
abi: addressResolverAbi,
|
|
855
|
+
functionName: "addr",
|
|
856
|
+
args
|
|
857
|
+
});
|
|
858
|
+
const readContractParameters = {
|
|
859
|
+
address: universalResolverAddress,
|
|
860
|
+
abi: universalResolverResolveAbi,
|
|
861
|
+
functionName: "resolveWithGateways",
|
|
862
|
+
args: [
|
|
863
|
+
toHex(packetToBytes(name)),
|
|
864
|
+
functionData,
|
|
865
|
+
gatewayUrls ?? [localBatchGatewayUrl]
|
|
866
|
+
],
|
|
867
|
+
blockNumber,
|
|
868
|
+
blockTag
|
|
869
|
+
};
|
|
870
|
+
const readContractAction = getAction(client, readContract, "readContract");
|
|
871
|
+
const res = await readContractAction(readContractParameters);
|
|
872
|
+
if (res[0] === "0x")
|
|
873
|
+
return null;
|
|
874
|
+
const address = decodeAddress({ coinType, data: res[0], args });
|
|
875
|
+
if (address === "0x")
|
|
876
|
+
return null;
|
|
877
|
+
if (trim(address) === "0x00")
|
|
878
|
+
return null;
|
|
879
|
+
return address;
|
|
880
|
+
} catch (err) {
|
|
881
|
+
if (strict)
|
|
882
|
+
throw err;
|
|
883
|
+
if (isNullUniversalResolverError(err))
|
|
884
|
+
return null;
|
|
885
|
+
throw err;
|
|
886
|
+
}
|
|
887
|
+
}
|
|
888
|
+
function decodeAddress({ coinType, data, args }) {
|
|
889
|
+
try {
|
|
890
|
+
return decodeFunctionResult({
|
|
891
|
+
abi: addressResolverAbi,
|
|
892
|
+
args,
|
|
893
|
+
functionName: "addr",
|
|
894
|
+
data
|
|
895
|
+
});
|
|
896
|
+
} catch (err) {
|
|
897
|
+
if (coinType == null)
|
|
898
|
+
throw err;
|
|
899
|
+
const address = trim(data);
|
|
900
|
+
if (size(address) === 20)
|
|
901
|
+
return getAddress(address);
|
|
902
|
+
throw err;
|
|
903
|
+
}
|
|
904
|
+
}
|
|
905
|
+
|
|
906
|
+
// node_modules/viem/_esm/errors/ens.js
|
|
907
|
+
var EnsAvatarInvalidMetadataError = class extends BaseError {
|
|
908
|
+
constructor({ data }) {
|
|
909
|
+
super("Unable to extract image from metadata. The metadata may be malformed or invalid.", {
|
|
910
|
+
metaMessages: [
|
|
911
|
+
"- Metadata must be a JSON object with at least an `image`, `image_url` or `image_data` property.",
|
|
912
|
+
"",
|
|
913
|
+
`Provided data: ${JSON.stringify(data)}`
|
|
914
|
+
],
|
|
915
|
+
name: "EnsAvatarInvalidMetadataError"
|
|
916
|
+
});
|
|
917
|
+
}
|
|
918
|
+
};
|
|
919
|
+
var EnsAvatarInvalidNftUriError = class extends BaseError {
|
|
920
|
+
constructor({ reason }) {
|
|
921
|
+
super(`ENS NFT avatar URI is invalid. ${reason}`, {
|
|
922
|
+
name: "EnsAvatarInvalidNftUriError"
|
|
923
|
+
});
|
|
924
|
+
}
|
|
925
|
+
};
|
|
926
|
+
var EnsAvatarUriResolutionError = class extends BaseError {
|
|
927
|
+
constructor({ uri }) {
|
|
928
|
+
super(`Unable to resolve ENS avatar URI "${uri}". The URI may be malformed, invalid, or does not respond with a valid image.`, { name: "EnsAvatarUriResolutionError" });
|
|
929
|
+
}
|
|
930
|
+
};
|
|
931
|
+
var EnsAvatarUnsupportedNamespaceError = class extends BaseError {
|
|
932
|
+
constructor({ namespace }) {
|
|
933
|
+
super(`ENS NFT avatar namespace "${namespace}" is not supported. Must be "erc721" or "erc1155".`, { name: "EnsAvatarUnsupportedNamespaceError" });
|
|
934
|
+
}
|
|
935
|
+
};
|
|
936
|
+
var EnsInvalidChainIdError = class extends BaseError {
|
|
937
|
+
constructor({ chainId }) {
|
|
938
|
+
super(`Invalid ENSIP-11 chainId: ${chainId}. Must be between 0 and 0x7fffffff, or 1.`, {
|
|
939
|
+
name: "EnsInvalidChainIdError"
|
|
940
|
+
});
|
|
941
|
+
}
|
|
942
|
+
};
|
|
943
|
+
|
|
944
|
+
// node_modules/viem/_esm/utils/ens/avatar/utils.js
|
|
945
|
+
var networkRegex = /(?<protocol>https?:\/\/[^/]*|ipfs:\/|ipns:\/|ar:\/)?(?<root>\/)?(?<subpath>ipfs\/|ipns\/)?(?<target>[\w\-.]+)(?<subtarget>\/.*)?/;
|
|
946
|
+
var ipfsHashRegex = /^(Qm[1-9A-HJ-NP-Za-km-z]{44,}|b[A-Za-z2-7]{58,}|B[A-Z2-7]{58,}|z[1-9A-HJ-NP-Za-km-z]{48,}|F[0-9A-F]{50,})(\/(?<target>[\w\-.]+))?(?<subtarget>\/.*)?$/;
|
|
947
|
+
var base64Regex = /^data:([a-zA-Z\-/+]*);base64,([^"].*)/;
|
|
948
|
+
var dataURIRegex = /^data:([a-zA-Z\-/+]*)?(;[a-zA-Z0-9].*?)?(,)/;
|
|
949
|
+
async function isImageUri(uri) {
|
|
950
|
+
try {
|
|
951
|
+
const res = await fetch(uri, { method: "HEAD" });
|
|
952
|
+
if (res.status === 200) {
|
|
953
|
+
const contentType = res.headers.get("content-type");
|
|
954
|
+
return contentType?.startsWith("image/");
|
|
955
|
+
}
|
|
956
|
+
return false;
|
|
957
|
+
} catch (error) {
|
|
958
|
+
if (typeof error === "object" && typeof error.response !== "undefined") {
|
|
959
|
+
return false;
|
|
960
|
+
}
|
|
961
|
+
if (!Object.hasOwn(globalThis, "Image"))
|
|
962
|
+
return false;
|
|
963
|
+
return new Promise((resolve) => {
|
|
964
|
+
const img = new Image();
|
|
965
|
+
img.onload = () => {
|
|
966
|
+
resolve(true);
|
|
967
|
+
};
|
|
968
|
+
img.onerror = () => {
|
|
969
|
+
resolve(false);
|
|
970
|
+
};
|
|
971
|
+
img.src = uri;
|
|
972
|
+
});
|
|
973
|
+
}
|
|
974
|
+
}
|
|
975
|
+
function getGateway(custom2, defaultGateway) {
|
|
976
|
+
if (!custom2)
|
|
977
|
+
return defaultGateway;
|
|
978
|
+
if (custom2.endsWith("/"))
|
|
979
|
+
return custom2.slice(0, -1);
|
|
980
|
+
return custom2;
|
|
981
|
+
}
|
|
982
|
+
function resolveAvatarUri({ uri, gatewayUrls }) {
|
|
983
|
+
const isEncoded = base64Regex.test(uri);
|
|
984
|
+
if (isEncoded)
|
|
985
|
+
return { uri, isOnChain: true, isEncoded };
|
|
986
|
+
const ipfsGateway = getGateway(gatewayUrls?.ipfs, "https://ipfs.io");
|
|
987
|
+
const arweaveGateway = getGateway(gatewayUrls?.arweave, "https://arweave.net");
|
|
988
|
+
const networkRegexMatch = uri.match(networkRegex);
|
|
989
|
+
const { protocol, subpath, target, subtarget = "" } = networkRegexMatch?.groups || {};
|
|
990
|
+
const isIPNS = protocol === "ipns:/" || subpath === "ipns/";
|
|
991
|
+
const isIPFS = protocol === "ipfs:/" || subpath === "ipfs/" || ipfsHashRegex.test(uri);
|
|
992
|
+
if (uri.startsWith("http") && !isIPNS && !isIPFS) {
|
|
993
|
+
let replacedUri = uri;
|
|
994
|
+
if (gatewayUrls?.arweave)
|
|
995
|
+
replacedUri = uri.replace(/https:\/\/arweave.net/g, gatewayUrls?.arweave);
|
|
996
|
+
return { uri: replacedUri, isOnChain: false, isEncoded: false };
|
|
997
|
+
}
|
|
998
|
+
if ((isIPNS || isIPFS) && target) {
|
|
999
|
+
return {
|
|
1000
|
+
uri: `${ipfsGateway}/${isIPNS ? "ipns" : "ipfs"}/${target}${subtarget}`,
|
|
1001
|
+
isOnChain: false,
|
|
1002
|
+
isEncoded: false
|
|
1003
|
+
};
|
|
1004
|
+
}
|
|
1005
|
+
if (protocol === "ar:/" && target) {
|
|
1006
|
+
return {
|
|
1007
|
+
uri: `${arweaveGateway}/${target}${subtarget || ""}`,
|
|
1008
|
+
isOnChain: false,
|
|
1009
|
+
isEncoded: false
|
|
1010
|
+
};
|
|
1011
|
+
}
|
|
1012
|
+
let parsedUri = uri.replace(dataURIRegex, "");
|
|
1013
|
+
if (parsedUri.startsWith("<svg")) {
|
|
1014
|
+
parsedUri = `data:image/svg+xml;base64,${btoa(parsedUri)}`;
|
|
1015
|
+
}
|
|
1016
|
+
if (parsedUri.startsWith("data:") || parsedUri.startsWith("{")) {
|
|
1017
|
+
return {
|
|
1018
|
+
uri: parsedUri,
|
|
1019
|
+
isOnChain: true,
|
|
1020
|
+
isEncoded: false
|
|
1021
|
+
};
|
|
1022
|
+
}
|
|
1023
|
+
throw new EnsAvatarUriResolutionError({ uri });
|
|
1024
|
+
}
|
|
1025
|
+
function getJsonImage(data) {
|
|
1026
|
+
if (typeof data !== "object" || !("image" in data) && !("image_url" in data) && !("image_data" in data)) {
|
|
1027
|
+
throw new EnsAvatarInvalidMetadataError({ data });
|
|
1028
|
+
}
|
|
1029
|
+
return data.image || data.image_url || data.image_data;
|
|
1030
|
+
}
|
|
1031
|
+
async function getMetadataAvatarUri({ gatewayUrls, uri }) {
|
|
1032
|
+
try {
|
|
1033
|
+
const res = await fetch(uri).then((res2) => res2.json());
|
|
1034
|
+
const image = await parseAvatarUri({
|
|
1035
|
+
gatewayUrls,
|
|
1036
|
+
uri: getJsonImage(res)
|
|
1037
|
+
});
|
|
1038
|
+
return image;
|
|
1039
|
+
} catch {
|
|
1040
|
+
throw new EnsAvatarUriResolutionError({ uri });
|
|
1041
|
+
}
|
|
1042
|
+
}
|
|
1043
|
+
async function parseAvatarUri({ gatewayUrls, uri }) {
|
|
1044
|
+
const { uri: resolvedURI, isOnChain } = resolveAvatarUri({ uri, gatewayUrls });
|
|
1045
|
+
if (isOnChain)
|
|
1046
|
+
return resolvedURI;
|
|
1047
|
+
const isImage = await isImageUri(resolvedURI);
|
|
1048
|
+
if (isImage)
|
|
1049
|
+
return resolvedURI;
|
|
1050
|
+
throw new EnsAvatarUriResolutionError({ uri });
|
|
1051
|
+
}
|
|
1052
|
+
function parseNftUri(uri_) {
|
|
1053
|
+
let uri = uri_;
|
|
1054
|
+
if (uri.startsWith("did:nft:")) {
|
|
1055
|
+
uri = uri.replace("did:nft:", "").replace(/_/g, "/");
|
|
1056
|
+
}
|
|
1057
|
+
const [reference, asset_namespace, tokenID] = uri.split("/");
|
|
1058
|
+
const [eip_namespace, chainID] = reference.split(":");
|
|
1059
|
+
const [erc_namespace, contractAddress] = asset_namespace.split(":");
|
|
1060
|
+
if (!eip_namespace || eip_namespace.toLowerCase() !== "eip155")
|
|
1061
|
+
throw new EnsAvatarInvalidNftUriError({ reason: "Only EIP-155 supported" });
|
|
1062
|
+
if (!chainID)
|
|
1063
|
+
throw new EnsAvatarInvalidNftUriError({ reason: "Chain ID not found" });
|
|
1064
|
+
if (!contractAddress)
|
|
1065
|
+
throw new EnsAvatarInvalidNftUriError({
|
|
1066
|
+
reason: "Contract address not found"
|
|
1067
|
+
});
|
|
1068
|
+
if (!tokenID)
|
|
1069
|
+
throw new EnsAvatarInvalidNftUriError({ reason: "Token ID not found" });
|
|
1070
|
+
if (!erc_namespace)
|
|
1071
|
+
throw new EnsAvatarInvalidNftUriError({ reason: "ERC namespace not found" });
|
|
1072
|
+
return {
|
|
1073
|
+
chainID: Number.parseInt(chainID, 10),
|
|
1074
|
+
namespace: erc_namespace.toLowerCase(),
|
|
1075
|
+
contractAddress,
|
|
1076
|
+
tokenID
|
|
1077
|
+
};
|
|
1078
|
+
}
|
|
1079
|
+
async function getNftTokenUri(client, { nft }) {
|
|
1080
|
+
if (nft.namespace === "erc721") {
|
|
1081
|
+
return readContract(client, {
|
|
1082
|
+
address: nft.contractAddress,
|
|
1083
|
+
abi: [
|
|
1084
|
+
{
|
|
1085
|
+
name: "tokenURI",
|
|
1086
|
+
type: "function",
|
|
1087
|
+
stateMutability: "view",
|
|
1088
|
+
inputs: [{ name: "tokenId", type: "uint256" }],
|
|
1089
|
+
outputs: [{ name: "", type: "string" }]
|
|
1090
|
+
}
|
|
1091
|
+
],
|
|
1092
|
+
functionName: "tokenURI",
|
|
1093
|
+
args: [BigInt(nft.tokenID)]
|
|
1094
|
+
});
|
|
1095
|
+
}
|
|
1096
|
+
if (nft.namespace === "erc1155") {
|
|
1097
|
+
return readContract(client, {
|
|
1098
|
+
address: nft.contractAddress,
|
|
1099
|
+
abi: [
|
|
1100
|
+
{
|
|
1101
|
+
name: "uri",
|
|
1102
|
+
type: "function",
|
|
1103
|
+
stateMutability: "view",
|
|
1104
|
+
inputs: [{ name: "_id", type: "uint256" }],
|
|
1105
|
+
outputs: [{ name: "", type: "string" }]
|
|
1106
|
+
}
|
|
1107
|
+
],
|
|
1108
|
+
functionName: "uri",
|
|
1109
|
+
args: [BigInt(nft.tokenID)]
|
|
1110
|
+
});
|
|
1111
|
+
}
|
|
1112
|
+
throw new EnsAvatarUnsupportedNamespaceError({ namespace: nft.namespace });
|
|
1113
|
+
}
|
|
1114
|
+
|
|
1115
|
+
// node_modules/viem/_esm/utils/ens/avatar/parseAvatarRecord.js
|
|
1116
|
+
async function parseAvatarRecord(client, { gatewayUrls, record }) {
|
|
1117
|
+
if (/eip155:/i.test(record))
|
|
1118
|
+
return parseNftAvatarUri(client, { gatewayUrls, record });
|
|
1119
|
+
return parseAvatarUri({ uri: record, gatewayUrls });
|
|
1120
|
+
}
|
|
1121
|
+
async function parseNftAvatarUri(client, { gatewayUrls, record }) {
|
|
1122
|
+
const nft = parseNftUri(record);
|
|
1123
|
+
const nftUri = await getNftTokenUri(client, { nft });
|
|
1124
|
+
const { uri: resolvedNftUri, isOnChain, isEncoded } = resolveAvatarUri({ uri: nftUri, gatewayUrls });
|
|
1125
|
+
if (isOnChain && (resolvedNftUri.includes("data:application/json;base64,") || resolvedNftUri.startsWith("{"))) {
|
|
1126
|
+
const encodedJson = isEncoded ? (
|
|
1127
|
+
// if it is encoded, decode it
|
|
1128
|
+
atob(resolvedNftUri.replace("data:application/json;base64,", ""))
|
|
1129
|
+
) : (
|
|
1130
|
+
// if it isn't encoded assume it is a JSON string, but it could be anything (it will error if it is)
|
|
1131
|
+
resolvedNftUri
|
|
1132
|
+
);
|
|
1133
|
+
const decoded = JSON.parse(encodedJson);
|
|
1134
|
+
return parseAvatarUri({ uri: getJsonImage(decoded), gatewayUrls });
|
|
1135
|
+
}
|
|
1136
|
+
let uriTokenId = nft.tokenID;
|
|
1137
|
+
if (nft.namespace === "erc1155")
|
|
1138
|
+
uriTokenId = uriTokenId.replace("0x", "").padStart(64, "0");
|
|
1139
|
+
return getMetadataAvatarUri({
|
|
1140
|
+
gatewayUrls,
|
|
1141
|
+
uri: resolvedNftUri.replace(/(?:0x)?{id}/, uriTokenId)
|
|
1142
|
+
});
|
|
1143
|
+
}
|
|
1144
|
+
|
|
1145
|
+
// node_modules/viem/_esm/actions/ens/getEnsText.js
|
|
1146
|
+
async function getEnsText(client, parameters) {
|
|
1147
|
+
const { blockNumber, blockTag, key, name, gatewayUrls, strict } = parameters;
|
|
1148
|
+
const { chain } = client;
|
|
1149
|
+
const universalResolverAddress = (() => {
|
|
1150
|
+
if (parameters.universalResolverAddress)
|
|
1151
|
+
return parameters.universalResolverAddress;
|
|
1152
|
+
if (!chain)
|
|
1153
|
+
throw new Error("client chain not configured. universalResolverAddress is required.");
|
|
1154
|
+
return getChainContractAddress({
|
|
1155
|
+
blockNumber,
|
|
1156
|
+
chain,
|
|
1157
|
+
contract: "ensUniversalResolver"
|
|
1158
|
+
});
|
|
1159
|
+
})();
|
|
1160
|
+
const tlds = chain?.ensTlds;
|
|
1161
|
+
if (tlds && !tlds.some((tld) => name.endsWith(tld)))
|
|
1162
|
+
return null;
|
|
1163
|
+
try {
|
|
1164
|
+
const readContractParameters = {
|
|
1165
|
+
address: universalResolverAddress,
|
|
1166
|
+
abi: universalResolverResolveAbi,
|
|
1167
|
+
args: [
|
|
1168
|
+
toHex(packetToBytes(name)),
|
|
1169
|
+
encodeFunctionData({
|
|
1170
|
+
abi: textResolverAbi,
|
|
1171
|
+
functionName: "text",
|
|
1172
|
+
args: [namehash(name), key]
|
|
1173
|
+
}),
|
|
1174
|
+
gatewayUrls ?? [localBatchGatewayUrl]
|
|
1175
|
+
],
|
|
1176
|
+
functionName: "resolveWithGateways",
|
|
1177
|
+
blockNumber,
|
|
1178
|
+
blockTag
|
|
1179
|
+
};
|
|
1180
|
+
const readContractAction = getAction(client, readContract, "readContract");
|
|
1181
|
+
const res = await readContractAction(readContractParameters);
|
|
1182
|
+
if (res[0] === "0x")
|
|
1183
|
+
return null;
|
|
1184
|
+
const record = decodeFunctionResult({
|
|
1185
|
+
abi: textResolverAbi,
|
|
1186
|
+
functionName: "text",
|
|
1187
|
+
data: res[0]
|
|
1188
|
+
});
|
|
1189
|
+
return record === "" ? null : record;
|
|
1190
|
+
} catch (err) {
|
|
1191
|
+
if (strict)
|
|
1192
|
+
throw err;
|
|
1193
|
+
if (isNullUniversalResolverError(err))
|
|
1194
|
+
return null;
|
|
1195
|
+
throw err;
|
|
1196
|
+
}
|
|
1197
|
+
}
|
|
1198
|
+
|
|
1199
|
+
// node_modules/viem/_esm/actions/ens/getEnsAvatar.js
|
|
1200
|
+
async function getEnsAvatar(client, { blockNumber, blockTag, assetGatewayUrls, name, gatewayUrls, strict, universalResolverAddress }) {
|
|
1201
|
+
const record = await getAction(client, getEnsText, "getEnsText")({
|
|
1202
|
+
blockNumber,
|
|
1203
|
+
blockTag,
|
|
1204
|
+
key: "avatar",
|
|
1205
|
+
name,
|
|
1206
|
+
universalResolverAddress,
|
|
1207
|
+
gatewayUrls,
|
|
1208
|
+
strict
|
|
1209
|
+
});
|
|
1210
|
+
if (!record)
|
|
1211
|
+
return null;
|
|
1212
|
+
try {
|
|
1213
|
+
return await parseAvatarRecord(client, {
|
|
1214
|
+
record,
|
|
1215
|
+
gatewayUrls: assetGatewayUrls
|
|
1216
|
+
});
|
|
1217
|
+
} catch {
|
|
1218
|
+
return null;
|
|
1219
|
+
}
|
|
1220
|
+
}
|
|
1221
|
+
|
|
1222
|
+
// node_modules/viem/_esm/actions/ens/getEnsName.js
|
|
1223
|
+
async function getEnsName(client, parameters) {
|
|
1224
|
+
const { address, blockNumber, blockTag, coinType = 60n, gatewayUrls, strict } = parameters;
|
|
1225
|
+
const { chain } = client;
|
|
1226
|
+
const universalResolverAddress = (() => {
|
|
1227
|
+
if (parameters.universalResolverAddress)
|
|
1228
|
+
return parameters.universalResolverAddress;
|
|
1229
|
+
if (!chain)
|
|
1230
|
+
throw new Error("client chain not configured. universalResolverAddress is required.");
|
|
1231
|
+
return getChainContractAddress({
|
|
1232
|
+
blockNumber,
|
|
1233
|
+
chain,
|
|
1234
|
+
contract: "ensUniversalResolver"
|
|
1235
|
+
});
|
|
1236
|
+
})();
|
|
1237
|
+
try {
|
|
1238
|
+
const readContractParameters = {
|
|
1239
|
+
address: universalResolverAddress,
|
|
1240
|
+
abi: universalResolverReverseAbi,
|
|
1241
|
+
args: [address, coinType, gatewayUrls ?? [localBatchGatewayUrl]],
|
|
1242
|
+
functionName: "reverseWithGateways",
|
|
1243
|
+
blockNumber,
|
|
1244
|
+
blockTag
|
|
1245
|
+
};
|
|
1246
|
+
const readContractAction = getAction(client, readContract, "readContract");
|
|
1247
|
+
const [name] = await readContractAction(readContractParameters);
|
|
1248
|
+
return name || null;
|
|
1249
|
+
} catch (err) {
|
|
1250
|
+
if (strict)
|
|
1251
|
+
throw err;
|
|
1252
|
+
if (isNullUniversalResolverError(err))
|
|
1253
|
+
return null;
|
|
1254
|
+
throw err;
|
|
1255
|
+
}
|
|
1256
|
+
}
|
|
1257
|
+
|
|
1258
|
+
// node_modules/viem/_esm/actions/ens/getEnsResolver.js
|
|
1259
|
+
async function getEnsResolver(client, parameters) {
|
|
1260
|
+
const { blockNumber, blockTag, name } = parameters;
|
|
1261
|
+
const { chain } = client;
|
|
1262
|
+
const universalResolverAddress = (() => {
|
|
1263
|
+
if (parameters.universalResolverAddress)
|
|
1264
|
+
return parameters.universalResolverAddress;
|
|
1265
|
+
if (!chain)
|
|
1266
|
+
throw new Error("client chain not configured. universalResolverAddress is required.");
|
|
1267
|
+
return getChainContractAddress({
|
|
1268
|
+
blockNumber,
|
|
1269
|
+
chain,
|
|
1270
|
+
contract: "ensUniversalResolver"
|
|
1271
|
+
});
|
|
1272
|
+
})();
|
|
1273
|
+
const tlds = chain?.ensTlds;
|
|
1274
|
+
if (tlds && !tlds.some((tld) => name.endsWith(tld)))
|
|
1275
|
+
throw new Error(`${name} is not a valid ENS TLD (${tlds?.join(", ")}) for chain "${chain.name}" (id: ${chain.id}).`);
|
|
1276
|
+
const [resolverAddress] = await getAction(client, readContract, "readContract")({
|
|
1277
|
+
address: universalResolverAddress,
|
|
1278
|
+
abi: [
|
|
1279
|
+
{
|
|
1280
|
+
inputs: [{ type: "bytes" }],
|
|
1281
|
+
name: "findResolver",
|
|
1282
|
+
outputs: [
|
|
1283
|
+
{ type: "address" },
|
|
1284
|
+
{ type: "bytes32" },
|
|
1285
|
+
{ type: "uint256" }
|
|
1286
|
+
],
|
|
1287
|
+
stateMutability: "view",
|
|
1288
|
+
type: "function"
|
|
1289
|
+
}
|
|
1290
|
+
],
|
|
1291
|
+
functionName: "findResolver",
|
|
1292
|
+
args: [toHex(packetToBytes(name))],
|
|
1293
|
+
blockNumber,
|
|
1294
|
+
blockTag
|
|
1295
|
+
});
|
|
1296
|
+
return resolverAddress;
|
|
1297
|
+
}
|
|
1298
|
+
|
|
1299
|
+
// node_modules/viem/_esm/actions/public/createAccessList.js
|
|
1300
|
+
async function createAccessList(client, args) {
|
|
1301
|
+
const { account: account_ = client.account, blockNumber, blockTag = "latest", blobs, data, gas, gasPrice, maxFeePerBlobGas, maxFeePerGas, maxPriorityFeePerGas, to, value, ...rest } = args;
|
|
1302
|
+
const account = account_ ? parseAccount(account_) : void 0;
|
|
1303
|
+
try {
|
|
1304
|
+
assertRequest(args);
|
|
1305
|
+
const blockNumberHex = typeof blockNumber === "bigint" ? numberToHex(blockNumber) : void 0;
|
|
1306
|
+
const block = blockNumberHex || blockTag;
|
|
1307
|
+
const chainFormat = client.chain?.formatters?.transactionRequest?.format;
|
|
1308
|
+
const format = chainFormat || formatTransactionRequest;
|
|
1309
|
+
const request = format({
|
|
1310
|
+
// Pick out extra data that might exist on the chain's transaction request type.
|
|
1311
|
+
...extract(rest, { format: chainFormat }),
|
|
1312
|
+
account,
|
|
1313
|
+
blobs,
|
|
1314
|
+
data,
|
|
1315
|
+
gas,
|
|
1316
|
+
gasPrice,
|
|
1317
|
+
maxFeePerBlobGas,
|
|
1318
|
+
maxFeePerGas,
|
|
1319
|
+
maxPriorityFeePerGas,
|
|
1320
|
+
to,
|
|
1321
|
+
value
|
|
1322
|
+
}, "createAccessList");
|
|
1323
|
+
const response = await client.request({
|
|
1324
|
+
method: "eth_createAccessList",
|
|
1325
|
+
params: [request, block]
|
|
1326
|
+
});
|
|
1327
|
+
if (response.error)
|
|
1328
|
+
throw new BaseError(response.error, { details: response.error });
|
|
1329
|
+
return {
|
|
1330
|
+
accessList: response.accessList,
|
|
1331
|
+
gasUsed: BigInt(response.gasUsed)
|
|
1332
|
+
};
|
|
1333
|
+
} catch (err) {
|
|
1334
|
+
throw getCallError(err, {
|
|
1335
|
+
...args,
|
|
1336
|
+
account,
|
|
1337
|
+
chain: client.chain
|
|
1338
|
+
});
|
|
1339
|
+
}
|
|
1340
|
+
}
|
|
1341
|
+
|
|
1342
|
+
// node_modules/viem/_esm/actions/public/createBlockFilter.js
|
|
1343
|
+
async function createBlockFilter(client) {
|
|
1344
|
+
const getRequest = createFilterRequestScope(client, {
|
|
1345
|
+
method: "eth_newBlockFilter"
|
|
1346
|
+
});
|
|
1347
|
+
const id = await client.request({
|
|
1348
|
+
method: "eth_newBlockFilter"
|
|
1349
|
+
});
|
|
1350
|
+
return { id, request: getRequest(id), type: "block" };
|
|
1351
|
+
}
|
|
1352
|
+
|
|
1353
|
+
// node_modules/viem/_esm/actions/public/createEventFilter.js
|
|
1354
|
+
async function createEventFilter(client, { address, args, event, events: events_, fromBlock, strict, toBlock } = {}) {
|
|
1355
|
+
const events = events_ ?? (event ? [event] : void 0);
|
|
1356
|
+
const getRequest = createFilterRequestScope(client, {
|
|
1357
|
+
method: "eth_newFilter"
|
|
1358
|
+
});
|
|
1359
|
+
let topics = [];
|
|
1360
|
+
if (events) {
|
|
1361
|
+
const encoded = events.flatMap((event2) => encodeEventTopics({
|
|
1362
|
+
abi: [event2],
|
|
1363
|
+
eventName: event2.name,
|
|
1364
|
+
args
|
|
1365
|
+
}));
|
|
1366
|
+
topics = [encoded];
|
|
1367
|
+
if (event)
|
|
1368
|
+
topics = topics[0];
|
|
1369
|
+
}
|
|
1370
|
+
const id = await client.request({
|
|
1371
|
+
method: "eth_newFilter",
|
|
1372
|
+
params: [
|
|
1373
|
+
{
|
|
1374
|
+
address,
|
|
1375
|
+
fromBlock: typeof fromBlock === "bigint" ? numberToHex(fromBlock) : fromBlock,
|
|
1376
|
+
toBlock: typeof toBlock === "bigint" ? numberToHex(toBlock) : toBlock,
|
|
1377
|
+
...topics.length ? { topics } : {}
|
|
1378
|
+
}
|
|
1379
|
+
]
|
|
1380
|
+
});
|
|
1381
|
+
return {
|
|
1382
|
+
abi: events,
|
|
1383
|
+
args,
|
|
1384
|
+
eventName: event ? event.name : void 0,
|
|
1385
|
+
fromBlock,
|
|
1386
|
+
id,
|
|
1387
|
+
request: getRequest(id),
|
|
1388
|
+
strict: Boolean(strict),
|
|
1389
|
+
toBlock,
|
|
1390
|
+
type: "event"
|
|
1391
|
+
};
|
|
1392
|
+
}
|
|
1393
|
+
|
|
1394
|
+
// node_modules/viem/_esm/actions/public/createPendingTransactionFilter.js
|
|
1395
|
+
async function createPendingTransactionFilter(client) {
|
|
1396
|
+
const getRequest = createFilterRequestScope(client, {
|
|
1397
|
+
method: "eth_newPendingTransactionFilter"
|
|
1398
|
+
});
|
|
1399
|
+
const id = await client.request({
|
|
1400
|
+
method: "eth_newPendingTransactionFilter"
|
|
1401
|
+
});
|
|
1402
|
+
return { id, request: getRequest(id), type: "transaction" };
|
|
1403
|
+
}
|
|
1404
|
+
|
|
1405
|
+
// node_modules/viem/_esm/actions/public/getBalance.js
|
|
1406
|
+
async function getBalance(client, { address, blockHash, blockNumber, blockTag = client.experimental_blockTag ?? "latest", requireCanonical }) {
|
|
1407
|
+
const block = formatBlockParameter({
|
|
1408
|
+
blockHash,
|
|
1409
|
+
blockNumber,
|
|
1410
|
+
blockTag,
|
|
1411
|
+
requireCanonical
|
|
1412
|
+
});
|
|
1413
|
+
if (client.batch?.multicall && client.chain?.contracts?.multicall3) {
|
|
1414
|
+
const multicall3Address = client.chain.contracts.multicall3.address;
|
|
1415
|
+
const calldata = encodeFunctionData({
|
|
1416
|
+
abi: multicall3Abi,
|
|
1417
|
+
functionName: "getEthBalance",
|
|
1418
|
+
args: [address]
|
|
1419
|
+
});
|
|
1420
|
+
const { data } = await getAction(client, call, "call")({
|
|
1421
|
+
to: multicall3Address,
|
|
1422
|
+
data: calldata,
|
|
1423
|
+
blockHash,
|
|
1424
|
+
blockNumber,
|
|
1425
|
+
blockTag,
|
|
1426
|
+
requireCanonical
|
|
1427
|
+
});
|
|
1428
|
+
return decodeFunctionResult({
|
|
1429
|
+
abi: multicall3Abi,
|
|
1430
|
+
functionName: "getEthBalance",
|
|
1431
|
+
args: [address],
|
|
1432
|
+
data: data || "0x"
|
|
1433
|
+
});
|
|
1434
|
+
}
|
|
1435
|
+
const balance = await client.request({
|
|
1436
|
+
method: "eth_getBalance",
|
|
1437
|
+
params: [address, block]
|
|
1438
|
+
});
|
|
1439
|
+
return BigInt(balance);
|
|
1440
|
+
}
|
|
1441
|
+
|
|
1442
|
+
// node_modules/viem/_esm/actions/public/getBlobBaseFee.js
|
|
1443
|
+
async function getBlobBaseFee(client) {
|
|
1444
|
+
const baseFee = await client.request({
|
|
1445
|
+
method: "eth_blobBaseFee"
|
|
1446
|
+
});
|
|
1447
|
+
return BigInt(baseFee);
|
|
1448
|
+
}
|
|
1449
|
+
|
|
1450
|
+
// node_modules/viem/_esm/actions/public/getBlockReceipts.js
|
|
1451
|
+
async function getBlockReceipts(client, { blockHash, blockNumber, blockTag = client.experimental_blockTag ?? "latest" } = {}) {
|
|
1452
|
+
const blockNumberHex = blockNumber !== void 0 ? numberToHex(blockNumber) : void 0;
|
|
1453
|
+
const receipts = await client.request({
|
|
1454
|
+
method: "eth_getBlockReceipts",
|
|
1455
|
+
params: [blockHash || blockNumberHex || blockTag]
|
|
1456
|
+
}, { dedupe: Boolean(blockHash || blockNumberHex) });
|
|
1457
|
+
if (!receipts)
|
|
1458
|
+
throw new BlockNotFoundError({ blockHash, blockNumber });
|
|
1459
|
+
const format = client.chain?.formatters?.transactionReceipt?.format || formatTransactionReceipt;
|
|
1460
|
+
return receipts.map((receipt) => format(receipt, "getBlockReceipts"));
|
|
1461
|
+
}
|
|
1462
|
+
|
|
1463
|
+
// node_modules/viem/_esm/actions/public/getBlockTransactionCount.js
|
|
1464
|
+
async function getBlockTransactionCount(client, { blockHash, blockNumber, blockTag = "latest" } = {}) {
|
|
1465
|
+
const blockNumberHex = blockNumber !== void 0 ? numberToHex(blockNumber) : void 0;
|
|
1466
|
+
let count;
|
|
1467
|
+
if (blockHash) {
|
|
1468
|
+
count = await client.request({
|
|
1469
|
+
method: "eth_getBlockTransactionCountByHash",
|
|
1470
|
+
params: [blockHash]
|
|
1471
|
+
}, { dedupe: true });
|
|
1472
|
+
} else {
|
|
1473
|
+
count = await client.request({
|
|
1474
|
+
method: "eth_getBlockTransactionCountByNumber",
|
|
1475
|
+
params: [blockNumberHex || blockTag]
|
|
1476
|
+
}, { dedupe: Boolean(blockNumberHex) });
|
|
1477
|
+
}
|
|
1478
|
+
return hexToNumber(count);
|
|
1479
|
+
}
|
|
1480
|
+
|
|
1481
|
+
// node_modules/viem/_esm/actions/public/getDelegation.js
|
|
1482
|
+
async function getDelegation(client, { address, blockNumber, blockTag = "latest" }) {
|
|
1483
|
+
const code = await getCode(client, {
|
|
1484
|
+
address,
|
|
1485
|
+
...blockNumber !== void 0 ? { blockNumber } : { blockTag }
|
|
1486
|
+
});
|
|
1487
|
+
if (!code)
|
|
1488
|
+
return void 0;
|
|
1489
|
+
if (size(code) !== 23)
|
|
1490
|
+
return void 0;
|
|
1491
|
+
if (!code.startsWith("0xef0100"))
|
|
1492
|
+
return void 0;
|
|
1493
|
+
return getAddress(slice(code, 3, 23));
|
|
1494
|
+
}
|
|
1495
|
+
|
|
1496
|
+
// node_modules/viem/_esm/errors/eip712.js
|
|
1497
|
+
var Eip712DomainNotFoundError = class extends BaseError {
|
|
1498
|
+
constructor({ address }) {
|
|
1499
|
+
super(`No EIP-712 domain found on contract "${address}".`, {
|
|
1500
|
+
metaMessages: [
|
|
1501
|
+
"Ensure that:",
|
|
1502
|
+
`- The contract is deployed at the address "${address}".`,
|
|
1503
|
+
"- `eip712Domain()` function exists on the contract.",
|
|
1504
|
+
"- `eip712Domain()` function matches signature to ERC-5267 specification."
|
|
1505
|
+
],
|
|
1506
|
+
name: "Eip712DomainNotFoundError"
|
|
1507
|
+
});
|
|
1508
|
+
}
|
|
1509
|
+
};
|
|
1510
|
+
|
|
1511
|
+
// node_modules/viem/_esm/actions/public/getEip712Domain.js
|
|
1512
|
+
async function getEip712Domain(client, parameters) {
|
|
1513
|
+
const { address, factory, factoryData } = parameters;
|
|
1514
|
+
try {
|
|
1515
|
+
const [fields, name, version, chainId, verifyingContract, salt, extensions] = await getAction(client, readContract, "readContract")({
|
|
1516
|
+
abi,
|
|
1517
|
+
address,
|
|
1518
|
+
functionName: "eip712Domain",
|
|
1519
|
+
factory,
|
|
1520
|
+
factoryData
|
|
1521
|
+
});
|
|
1522
|
+
return {
|
|
1523
|
+
domain: {
|
|
1524
|
+
name,
|
|
1525
|
+
version,
|
|
1526
|
+
chainId: Number(chainId),
|
|
1527
|
+
verifyingContract,
|
|
1528
|
+
salt
|
|
1529
|
+
},
|
|
1530
|
+
extensions,
|
|
1531
|
+
fields
|
|
1532
|
+
};
|
|
1533
|
+
} catch (e) {
|
|
1534
|
+
const error = e;
|
|
1535
|
+
if (error.name === "ContractFunctionExecutionError" && error.cause.name === "ContractFunctionZeroDataError") {
|
|
1536
|
+
throw new Eip712DomainNotFoundError({ address });
|
|
1537
|
+
}
|
|
1538
|
+
throw error;
|
|
1539
|
+
}
|
|
1540
|
+
}
|
|
1541
|
+
var abi = [
|
|
1542
|
+
{
|
|
1543
|
+
inputs: [],
|
|
1544
|
+
name: "eip712Domain",
|
|
1545
|
+
outputs: [
|
|
1546
|
+
{ name: "fields", type: "bytes1" },
|
|
1547
|
+
{ name: "name", type: "string" },
|
|
1548
|
+
{ name: "version", type: "string" },
|
|
1549
|
+
{ name: "chainId", type: "uint256" },
|
|
1550
|
+
{ name: "verifyingContract", type: "address" },
|
|
1551
|
+
{ name: "salt", type: "bytes32" },
|
|
1552
|
+
{ name: "extensions", type: "uint256[]" }
|
|
1553
|
+
],
|
|
1554
|
+
stateMutability: "view",
|
|
1555
|
+
type: "function"
|
|
1556
|
+
}
|
|
1557
|
+
];
|
|
1558
|
+
|
|
1559
|
+
// node_modules/viem/_esm/utils/formatters/feeHistory.js
|
|
1560
|
+
function formatFeeHistory(feeHistory) {
|
|
1561
|
+
return {
|
|
1562
|
+
baseFeePerGas: feeHistory.baseFeePerGas.map((value) => BigInt(value)),
|
|
1563
|
+
gasUsedRatio: feeHistory.gasUsedRatio,
|
|
1564
|
+
oldestBlock: BigInt(feeHistory.oldestBlock),
|
|
1565
|
+
reward: feeHistory.reward?.map((reward) => reward.map((value) => BigInt(value)))
|
|
1566
|
+
};
|
|
1567
|
+
}
|
|
1568
|
+
|
|
1569
|
+
// node_modules/viem/_esm/actions/public/getFeeHistory.js
|
|
1570
|
+
async function getFeeHistory(client, { blockCount, blockNumber, blockTag = "latest", rewardPercentiles }) {
|
|
1571
|
+
const blockNumberHex = typeof blockNumber === "bigint" ? numberToHex(blockNumber) : void 0;
|
|
1572
|
+
const feeHistory = await client.request({
|
|
1573
|
+
method: "eth_feeHistory",
|
|
1574
|
+
params: [
|
|
1575
|
+
numberToHex(blockCount),
|
|
1576
|
+
blockNumberHex || blockTag,
|
|
1577
|
+
rewardPercentiles
|
|
1578
|
+
]
|
|
1579
|
+
}, { dedupe: Boolean(blockNumberHex) });
|
|
1580
|
+
return formatFeeHistory(feeHistory);
|
|
1581
|
+
}
|
|
1582
|
+
|
|
1583
|
+
// node_modules/viem/_esm/actions/public/getFilterLogs.js
|
|
1584
|
+
async function getFilterLogs(_client, { filter }) {
|
|
1585
|
+
const strict = filter.strict ?? false;
|
|
1586
|
+
const logs = await filter.request({
|
|
1587
|
+
method: "eth_getFilterLogs",
|
|
1588
|
+
params: [filter.id]
|
|
1589
|
+
});
|
|
1590
|
+
const formattedLogs = logs.map((log) => formatLog(log));
|
|
1591
|
+
if (!filter.abi)
|
|
1592
|
+
return formattedLogs;
|
|
1593
|
+
return parseEventLogs({
|
|
1594
|
+
abi: filter.abi,
|
|
1595
|
+
logs: formattedLogs,
|
|
1596
|
+
strict
|
|
1597
|
+
});
|
|
1598
|
+
}
|
|
1599
|
+
|
|
1600
|
+
// node_modules/viem/_esm/utils/formatters/proof.js
|
|
1601
|
+
function formatStorageProof(storageProof) {
|
|
1602
|
+
return storageProof.map((proof) => ({
|
|
1603
|
+
...proof,
|
|
1604
|
+
value: BigInt(proof.value)
|
|
1605
|
+
}));
|
|
1606
|
+
}
|
|
1607
|
+
function formatProof(proof) {
|
|
1608
|
+
return {
|
|
1609
|
+
...proof,
|
|
1610
|
+
balance: proof.balance ? BigInt(proof.balance) : void 0,
|
|
1611
|
+
nonce: proof.nonce ? hexToNumber(proof.nonce) : void 0,
|
|
1612
|
+
storageProof: proof.storageProof ? formatStorageProof(proof.storageProof) : void 0
|
|
1613
|
+
};
|
|
1614
|
+
}
|
|
1615
|
+
|
|
1616
|
+
// node_modules/viem/_esm/actions/public/getProof.js
|
|
1617
|
+
async function getProof(client, { address, blockHash, blockNumber, blockTag = "latest", requireCanonical, storageKeys }) {
|
|
1618
|
+
const block = formatBlockParameter({
|
|
1619
|
+
blockHash,
|
|
1620
|
+
blockNumber,
|
|
1621
|
+
blockTag,
|
|
1622
|
+
requireCanonical
|
|
1623
|
+
});
|
|
1624
|
+
const proof = await client.request({
|
|
1625
|
+
method: "eth_getProof",
|
|
1626
|
+
params: [address, storageKeys, block]
|
|
1627
|
+
});
|
|
1628
|
+
return formatProof(proof);
|
|
1629
|
+
}
|
|
1630
|
+
|
|
1631
|
+
// node_modules/viem/_esm/actions/public/getRawTransaction.js
|
|
1632
|
+
async function getRawTransaction(client, { hash }) {
|
|
1633
|
+
const rawTransaction = await client.request({
|
|
1634
|
+
method: "eth_getRawTransactionByHash",
|
|
1635
|
+
params: [hash]
|
|
1636
|
+
}, { dedupe: true });
|
|
1637
|
+
if (!rawTransaction)
|
|
1638
|
+
throw new TransactionNotFoundError({ hash });
|
|
1639
|
+
return rawTransaction;
|
|
1640
|
+
}
|
|
1641
|
+
|
|
1642
|
+
// node_modules/viem/_esm/actions/public/getStorageAt.js
|
|
1643
|
+
async function getStorageAt(client, { address, blockHash, blockNumber, blockTag = "latest", requireCanonical, slot }) {
|
|
1644
|
+
const block = formatBlockParameter({
|
|
1645
|
+
blockHash,
|
|
1646
|
+
blockNumber,
|
|
1647
|
+
blockTag,
|
|
1648
|
+
requireCanonical
|
|
1649
|
+
});
|
|
1650
|
+
const data = await client.request({
|
|
1651
|
+
method: "eth_getStorageAt",
|
|
1652
|
+
params: [address, slot, block]
|
|
1653
|
+
});
|
|
1654
|
+
return data;
|
|
1655
|
+
}
|
|
1656
|
+
|
|
1657
|
+
// node_modules/viem/_esm/actions/public/getTransactionConfirmations.js
|
|
1658
|
+
async function getTransactionConfirmations(client, { hash, transactionReceipt }) {
|
|
1659
|
+
const [blockNumber, transaction] = await Promise.all([
|
|
1660
|
+
getAction(client, getBlockNumber, "getBlockNumber")({}),
|
|
1661
|
+
hash ? getAction(client, getTransaction, "getTransaction")({ hash }) : void 0
|
|
1662
|
+
]);
|
|
1663
|
+
const transactionBlockNumber = transactionReceipt?.blockNumber || transaction?.blockNumber;
|
|
1664
|
+
if (!transactionBlockNumber)
|
|
1665
|
+
return 0n;
|
|
1666
|
+
return blockNumber - transactionBlockNumber + 1n;
|
|
1667
|
+
}
|
|
1668
|
+
|
|
1669
|
+
// node_modules/viem/_esm/actions/public/multicall.js
|
|
1670
|
+
async function multicall(client, parameters) {
|
|
1671
|
+
const { account, authorizationList, allowFailure = true, blockHash, blockNumber, blockOverrides, blockTag, requireCanonical, stateOverride } = parameters;
|
|
1672
|
+
const contracts = parameters.contracts;
|
|
1673
|
+
const batch = typeof client.batch?.multicall === "object" ? client.batch.multicall : {};
|
|
1674
|
+
const batchSize = parameters.batchSize ?? batch.batchSize ?? 1024;
|
|
1675
|
+
const deployless = parameters.deployless ?? batch.deployless ?? false;
|
|
1676
|
+
const multicallAddress = (() => {
|
|
1677
|
+
if (parameters.multicallAddress)
|
|
1678
|
+
return parameters.multicallAddress;
|
|
1679
|
+
if (deployless)
|
|
1680
|
+
return null;
|
|
1681
|
+
if (client.chain) {
|
|
1682
|
+
return getChainContractAddress({
|
|
1683
|
+
blockNumber,
|
|
1684
|
+
chain: client.chain,
|
|
1685
|
+
contract: "multicall3"
|
|
1686
|
+
});
|
|
1687
|
+
}
|
|
1688
|
+
throw new Error("client chain not configured. multicallAddress is required.");
|
|
1689
|
+
})();
|
|
1690
|
+
const chunkedCalls = [[]];
|
|
1691
|
+
let currentChunk = 0;
|
|
1692
|
+
let currentChunkSize = 0;
|
|
1693
|
+
for (let i = 0; i < contracts.length; i++) {
|
|
1694
|
+
const { abi: abi2, address, args, functionName } = contracts[i];
|
|
1695
|
+
try {
|
|
1696
|
+
const callData = encodeFunctionData({ abi: abi2, args, functionName });
|
|
1697
|
+
currentChunkSize += (callData.length - 2) / 2;
|
|
1698
|
+
if (
|
|
1699
|
+
// Check if batching is enabled.
|
|
1700
|
+
batchSize > 0 && // Check if the current size of the batch exceeds the size limit.
|
|
1701
|
+
currentChunkSize > batchSize && // Check if the current chunk is not already empty.
|
|
1702
|
+
chunkedCalls[currentChunk].length > 0
|
|
1703
|
+
) {
|
|
1704
|
+
currentChunk++;
|
|
1705
|
+
currentChunkSize = (callData.length - 2) / 2;
|
|
1706
|
+
chunkedCalls[currentChunk] = [];
|
|
1707
|
+
}
|
|
1708
|
+
chunkedCalls[currentChunk] = [
|
|
1709
|
+
...chunkedCalls[currentChunk],
|
|
1710
|
+
{
|
|
1711
|
+
allowFailure: true,
|
|
1712
|
+
callData,
|
|
1713
|
+
target: address
|
|
1714
|
+
}
|
|
1715
|
+
];
|
|
1716
|
+
} catch (err) {
|
|
1717
|
+
const error = getContractError(err, {
|
|
1718
|
+
abi: abi2,
|
|
1719
|
+
address,
|
|
1720
|
+
args,
|
|
1721
|
+
docsPath: "/docs/contract/multicall",
|
|
1722
|
+
functionName,
|
|
1723
|
+
sender: account
|
|
1724
|
+
});
|
|
1725
|
+
if (!allowFailure)
|
|
1726
|
+
throw error;
|
|
1727
|
+
chunkedCalls[currentChunk] = [
|
|
1728
|
+
...chunkedCalls[currentChunk],
|
|
1729
|
+
{
|
|
1730
|
+
allowFailure: true,
|
|
1731
|
+
callData: "0x",
|
|
1732
|
+
target: address
|
|
1733
|
+
}
|
|
1734
|
+
];
|
|
1735
|
+
}
|
|
1736
|
+
}
|
|
1737
|
+
const batching = Boolean(client.batch?.multicall);
|
|
1738
|
+
const batches = batching ? chunkedCalls.flatMap((calls) => calls.map((call2) => [call2])) : chunkedCalls;
|
|
1739
|
+
const aggregate3Results = await Promise.allSettled(batches.map((calls) => {
|
|
1740
|
+
if (batching)
|
|
1741
|
+
return scheduleMulticall(client, {
|
|
1742
|
+
account,
|
|
1743
|
+
authorizationList,
|
|
1744
|
+
batchSize,
|
|
1745
|
+
blockHash,
|
|
1746
|
+
blockNumber,
|
|
1747
|
+
blockOverrides,
|
|
1748
|
+
blockTag,
|
|
1749
|
+
call: calls[0],
|
|
1750
|
+
multicallAddress,
|
|
1751
|
+
requireCanonical,
|
|
1752
|
+
stateOverride
|
|
1753
|
+
}).then((result) => [result]);
|
|
1754
|
+
return getAction(client, readContract, "readContract")({
|
|
1755
|
+
...multicallAddress === null ? { code: multicall3Bytecode } : { address: multicallAddress },
|
|
1756
|
+
abi: multicall3Abi,
|
|
1757
|
+
account,
|
|
1758
|
+
args: [calls],
|
|
1759
|
+
authorizationList,
|
|
1760
|
+
blockHash,
|
|
1761
|
+
blockNumber,
|
|
1762
|
+
blockOverrides,
|
|
1763
|
+
blockTag,
|
|
1764
|
+
functionName: "aggregate3",
|
|
1765
|
+
requireCanonical,
|
|
1766
|
+
stateOverride
|
|
1767
|
+
});
|
|
1768
|
+
}));
|
|
1769
|
+
const results = [];
|
|
1770
|
+
for (let i = 0; i < aggregate3Results.length; i++) {
|
|
1771
|
+
const result = aggregate3Results[i];
|
|
1772
|
+
if (result.status === "rejected") {
|
|
1773
|
+
if (!allowFailure)
|
|
1774
|
+
throw result.reason;
|
|
1775
|
+
for (let j = 0; j < batches[i].length; j++) {
|
|
1776
|
+
results.push({
|
|
1777
|
+
status: "failure",
|
|
1778
|
+
error: result.reason,
|
|
1779
|
+
result: void 0
|
|
1780
|
+
});
|
|
1781
|
+
}
|
|
1782
|
+
continue;
|
|
1783
|
+
}
|
|
1784
|
+
const aggregate3Result = result.value;
|
|
1785
|
+
for (let j = 0; j < aggregate3Result.length; j++) {
|
|
1786
|
+
const { returnData, success } = aggregate3Result[j];
|
|
1787
|
+
const { callData } = batches[i][j];
|
|
1788
|
+
const { abi: abi2, address, functionName, args } = contracts[results.length];
|
|
1789
|
+
try {
|
|
1790
|
+
if (callData === "0x")
|
|
1791
|
+
throw new AbiDecodingZeroDataError();
|
|
1792
|
+
if (!success)
|
|
1793
|
+
throw new RawContractError({ data: returnData });
|
|
1794
|
+
const result2 = decodeFunctionResult({
|
|
1795
|
+
abi: abi2,
|
|
1796
|
+
args,
|
|
1797
|
+
data: returnData,
|
|
1798
|
+
functionName
|
|
1799
|
+
});
|
|
1800
|
+
results.push(allowFailure ? { result: result2, status: "success" } : result2);
|
|
1801
|
+
} catch (err) {
|
|
1802
|
+
const error = getContractError(err, {
|
|
1803
|
+
abi: abi2,
|
|
1804
|
+
address,
|
|
1805
|
+
args,
|
|
1806
|
+
docsPath: "/docs/contract/multicall",
|
|
1807
|
+
functionName
|
|
1808
|
+
});
|
|
1809
|
+
if (!allowFailure)
|
|
1810
|
+
throw error;
|
|
1811
|
+
results.push({ error, result: void 0, status: "failure" });
|
|
1812
|
+
}
|
|
1813
|
+
}
|
|
1814
|
+
}
|
|
1815
|
+
if (results.length !== contracts.length)
|
|
1816
|
+
throw new BaseError("multicall results mismatch");
|
|
1817
|
+
return results;
|
|
1818
|
+
}
|
|
1819
|
+
async function scheduleMulticall(client, parameters) {
|
|
1820
|
+
const { batchSize, call: call2, multicallAddress, ...rest } = parameters;
|
|
1821
|
+
const { wait: wait2 = 0 } = typeof client.batch?.multicall === "object" ? client.batch.multicall : {};
|
|
1822
|
+
const { schedule } = createBatchScheduler({
|
|
1823
|
+
id: stringify(["multicall", client.uid, batchSize, multicallAddress, rest]),
|
|
1824
|
+
wait: wait2,
|
|
1825
|
+
shouldSplitBatch(calls) {
|
|
1826
|
+
if (batchSize === 0)
|
|
1827
|
+
return false;
|
|
1828
|
+
const size4 = calls.reduce((size5, { callData }) => size5 + (callData.length - 2) / 2, 0);
|
|
1829
|
+
return size4 > batchSize;
|
|
1830
|
+
},
|
|
1831
|
+
fn: (calls) => getAction(client, readContract, "readContract")({
|
|
1832
|
+
...multicallAddress === null ? { code: multicall3Bytecode } : { address: multicallAddress },
|
|
1833
|
+
...rest,
|
|
1834
|
+
abi: multicall3Abi,
|
|
1835
|
+
args: [calls],
|
|
1836
|
+
functionName: "aggregate3"
|
|
1837
|
+
})
|
|
1838
|
+
});
|
|
1839
|
+
const [result] = await schedule(call2);
|
|
1840
|
+
return result;
|
|
1841
|
+
}
|
|
1842
|
+
|
|
1843
|
+
// node_modules/viem/_esm/actions/public/simulateBlocks.js
|
|
1844
|
+
async function simulateBlocks(client, parameters) {
|
|
1845
|
+
const { blockNumber, blockTag = client.experimental_blockTag ?? "latest", blocks, returnFullTransactions, traceTransfers, validation } = parameters;
|
|
1846
|
+
try {
|
|
1847
|
+
const blockStateCalls = [];
|
|
1848
|
+
for (const block2 of blocks) {
|
|
1849
|
+
const blockOverrides = block2.blockOverrides ? toRpc(block2.blockOverrides) : void 0;
|
|
1850
|
+
const calls = block2.calls.map((call_) => {
|
|
1851
|
+
const call2 = call_;
|
|
1852
|
+
const account = call2.account ? parseAccount(call2.account) : void 0;
|
|
1853
|
+
const data = call2.abi ? encodeFunctionData(call2) : call2.data;
|
|
1854
|
+
const request = {
|
|
1855
|
+
...call2,
|
|
1856
|
+
account,
|
|
1857
|
+
data: call2.dataSuffix ? concat2([data || "0x", call2.dataSuffix]) : data,
|
|
1858
|
+
from: call2.from ?? account?.address
|
|
1859
|
+
};
|
|
1860
|
+
assertRequest(request);
|
|
1861
|
+
return formatTransactionRequest(request);
|
|
1862
|
+
});
|
|
1863
|
+
const stateOverrides = block2.stateOverrides ? serializeStateOverride(block2.stateOverrides) : void 0;
|
|
1864
|
+
blockStateCalls.push({
|
|
1865
|
+
blockOverrides,
|
|
1866
|
+
calls,
|
|
1867
|
+
stateOverrides
|
|
1868
|
+
});
|
|
1869
|
+
}
|
|
1870
|
+
const blockNumberHex = typeof blockNumber === "bigint" ? numberToHex(blockNumber) : void 0;
|
|
1871
|
+
const block = blockNumberHex || blockTag;
|
|
1872
|
+
const result = await client.request({
|
|
1873
|
+
method: "eth_simulateV1",
|
|
1874
|
+
params: [
|
|
1875
|
+
{ blockStateCalls, returnFullTransactions, traceTransfers, validation },
|
|
1876
|
+
block
|
|
1877
|
+
]
|
|
1878
|
+
});
|
|
1879
|
+
return result.map((block2, i) => ({
|
|
1880
|
+
...formatBlock(block2),
|
|
1881
|
+
calls: block2.calls.map((call2, j) => {
|
|
1882
|
+
const { abi: abi2, args, functionName, to } = blocks[i].calls[j];
|
|
1883
|
+
const data = call2.error?.data ?? call2.returnData;
|
|
1884
|
+
const gasUsed = BigInt(call2.gasUsed);
|
|
1885
|
+
const logs = call2.logs?.map((log) => formatLog(log));
|
|
1886
|
+
const status = call2.status === "0x1" ? "success" : "failure";
|
|
1887
|
+
const result2 = abi2 && status === "success" && data !== "0x" ? decodeFunctionResult({
|
|
1888
|
+
abi: abi2,
|
|
1889
|
+
data,
|
|
1890
|
+
functionName
|
|
1891
|
+
}) : null;
|
|
1892
|
+
const error = (() => {
|
|
1893
|
+
if (status === "success")
|
|
1894
|
+
return void 0;
|
|
1895
|
+
let error2;
|
|
1896
|
+
if (data === "0x")
|
|
1897
|
+
error2 = new AbiDecodingZeroDataError();
|
|
1898
|
+
else if (data)
|
|
1899
|
+
error2 = new RawContractError({ data });
|
|
1900
|
+
if (!error2)
|
|
1901
|
+
return void 0;
|
|
1902
|
+
return getContractError(error2, {
|
|
1903
|
+
abi: abi2 ?? [],
|
|
1904
|
+
address: to ?? "0x",
|
|
1905
|
+
args,
|
|
1906
|
+
functionName: functionName ?? "<unknown>"
|
|
1907
|
+
});
|
|
1908
|
+
})();
|
|
1909
|
+
return {
|
|
1910
|
+
data,
|
|
1911
|
+
gasUsed,
|
|
1912
|
+
logs,
|
|
1913
|
+
status,
|
|
1914
|
+
...status === "success" ? {
|
|
1915
|
+
result: result2
|
|
1916
|
+
} : {
|
|
1917
|
+
error
|
|
1918
|
+
}
|
|
1919
|
+
};
|
|
1920
|
+
})
|
|
1921
|
+
}));
|
|
1922
|
+
} catch (e) {
|
|
1923
|
+
const cause = e;
|
|
1924
|
+
const error = getNodeError(cause, {});
|
|
1925
|
+
if (error instanceof UnknownNodeError)
|
|
1926
|
+
throw cause;
|
|
1927
|
+
throw error;
|
|
1928
|
+
}
|
|
1929
|
+
}
|
|
1930
|
+
|
|
1931
|
+
// node_modules/ox/_esm/core/AbiConstructor.js
|
|
1932
|
+
function encode2(...parameters) {
|
|
1933
|
+
const [abiConstructor, options] = (() => {
|
|
1934
|
+
if (Array.isArray(parameters[0])) {
|
|
1935
|
+
const [abi2, options2] = parameters;
|
|
1936
|
+
return [fromAbi2(abi2), options2];
|
|
1937
|
+
}
|
|
1938
|
+
return parameters;
|
|
1939
|
+
})();
|
|
1940
|
+
const { bytecode, args } = options;
|
|
1941
|
+
return concat(bytecode, abiConstructor.inputs?.length && args?.length ? encode(abiConstructor.inputs, args) : "0x");
|
|
1942
|
+
}
|
|
1943
|
+
function from2(abiConstructor) {
|
|
1944
|
+
return from(abiConstructor);
|
|
1945
|
+
}
|
|
1946
|
+
function fromAbi2(abi2) {
|
|
1947
|
+
const item = abi2.find((item2) => item2.type === "constructor");
|
|
1948
|
+
if (!item)
|
|
1949
|
+
throw new NotFoundError({ name: "constructor" });
|
|
1950
|
+
return item;
|
|
1951
|
+
}
|
|
1952
|
+
|
|
1953
|
+
// node_modules/ox/_esm/core/AbiFunction.js
|
|
1954
|
+
function encodeData(...parameters) {
|
|
1955
|
+
const [abiFunction, args = []] = (() => {
|
|
1956
|
+
if (Array.isArray(parameters[0])) {
|
|
1957
|
+
const [abi2, name, args3] = parameters;
|
|
1958
|
+
return [fromAbi3(abi2, name, { args: args3 }), args3];
|
|
1959
|
+
}
|
|
1960
|
+
const [abiFunction2, args2] = parameters;
|
|
1961
|
+
return [abiFunction2, args2];
|
|
1962
|
+
})();
|
|
1963
|
+
const { overloads } = abiFunction;
|
|
1964
|
+
const item = overloads ? fromAbi3([abiFunction, ...overloads], abiFunction.name, {
|
|
1965
|
+
args
|
|
1966
|
+
}) : abiFunction;
|
|
1967
|
+
const selector = getSelector2(item);
|
|
1968
|
+
const data = args.length > 0 ? encode(item.inputs, args) : void 0;
|
|
1969
|
+
return data ? concat(selector, data) : selector;
|
|
1970
|
+
}
|
|
1971
|
+
function from3(abiFunction, options = {}) {
|
|
1972
|
+
return from(abiFunction, options);
|
|
1973
|
+
}
|
|
1974
|
+
function fromAbi3(abi2, name, options) {
|
|
1975
|
+
const item = fromAbi(abi2, name, options);
|
|
1976
|
+
if (item.type !== "function")
|
|
1977
|
+
throw new NotFoundError({ name, type: "function" });
|
|
1978
|
+
return item;
|
|
1979
|
+
}
|
|
1980
|
+
function getSelector2(abiItem) {
|
|
1981
|
+
return getSelector(abiItem);
|
|
1982
|
+
}
|
|
1983
|
+
|
|
1984
|
+
// node_modules/viem/_esm/constants/address.js
|
|
1985
|
+
var ethAddress = "0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee";
|
|
1986
|
+
var zeroAddress = "0x0000000000000000000000000000000000000000";
|
|
1987
|
+
|
|
1988
|
+
// node_modules/viem/_esm/actions/public/simulateCalls.js
|
|
1989
|
+
var getBalanceCode = "0x6080604052348015600e575f80fd5b5061016d8061001c5f395ff3fe608060405234801561000f575f80fd5b5060043610610029575f3560e01c8063f8b2cb4f1461002d575b5f80fd5b610047600480360381019061004291906100db565b61005d565b604051610054919061011e565b60405180910390f35b5f8173ffffffffffffffffffffffffffffffffffffffff16319050919050565b5f80fd5b5f73ffffffffffffffffffffffffffffffffffffffff82169050919050565b5f6100aa82610081565b9050919050565b6100ba816100a0565b81146100c4575f80fd5b50565b5f813590506100d5816100b1565b92915050565b5f602082840312156100f0576100ef61007d565b5b5f6100fd848285016100c7565b91505092915050565b5f819050919050565b61011881610106565b82525050565b5f6020820190506101315f83018461010f565b9291505056fea26469706673582212203b9fe929fe995c7cf9887f0bdba8a36dd78e8b73f149b17d2d9ad7cd09d2dc6264736f6c634300081a0033";
|
|
1990
|
+
async function simulateCalls(client, parameters) {
|
|
1991
|
+
const { blockNumber, blockTag, calls, stateOverrides, traceAssetChanges, traceTransfers, validation } = parameters;
|
|
1992
|
+
const account = parameters.account ? parseAccount(parameters.account) : void 0;
|
|
1993
|
+
if (traceAssetChanges && !account)
|
|
1994
|
+
throw new BaseError("`account` is required when `traceAssetChanges` is true");
|
|
1995
|
+
const getBalanceData = account ? encode2(from2("constructor(bytes, bytes)"), {
|
|
1996
|
+
bytecode: deploylessCallViaBytecodeBytecode,
|
|
1997
|
+
args: [
|
|
1998
|
+
getBalanceCode,
|
|
1999
|
+
encodeData(from3("function getBalance(address)"), [account.address])
|
|
2000
|
+
]
|
|
2001
|
+
}) : void 0;
|
|
2002
|
+
const assetAddresses = traceAssetChanges ? await Promise.all(parameters.calls.map(async (call2) => {
|
|
2003
|
+
if (!call2.data && !call2.abi)
|
|
2004
|
+
return;
|
|
2005
|
+
const { accessList } = await createAccessList(client, {
|
|
2006
|
+
account: account.address,
|
|
2007
|
+
...call2,
|
|
2008
|
+
data: call2.abi ? encodeFunctionData(call2) : call2.data
|
|
2009
|
+
});
|
|
2010
|
+
return accessList.map(({ address, storageKeys }) => storageKeys.length > 0 ? address : null);
|
|
2011
|
+
})).then((x) => x.flat().filter(Boolean)) : [];
|
|
2012
|
+
const blocks = await simulateBlocks(client, {
|
|
2013
|
+
blockNumber,
|
|
2014
|
+
blockTag,
|
|
2015
|
+
blocks: [
|
|
2016
|
+
...traceAssetChanges ? [
|
|
2017
|
+
// ETH pre balances
|
|
2018
|
+
{
|
|
2019
|
+
calls: [{ data: getBalanceData }],
|
|
2020
|
+
stateOverrides
|
|
2021
|
+
},
|
|
2022
|
+
// Asset pre balances
|
|
2023
|
+
{
|
|
2024
|
+
calls: assetAddresses.map((address, i) => ({
|
|
2025
|
+
abi: [
|
|
2026
|
+
from3("function balanceOf(address) returns (uint256)")
|
|
2027
|
+
],
|
|
2028
|
+
functionName: "balanceOf",
|
|
2029
|
+
args: [account.address],
|
|
2030
|
+
to: address,
|
|
2031
|
+
from: zeroAddress,
|
|
2032
|
+
nonce: i
|
|
2033
|
+
})),
|
|
2034
|
+
stateOverrides: [
|
|
2035
|
+
{
|
|
2036
|
+
address: zeroAddress,
|
|
2037
|
+
nonce: 0
|
|
2038
|
+
}
|
|
2039
|
+
]
|
|
2040
|
+
}
|
|
2041
|
+
] : [],
|
|
2042
|
+
{
|
|
2043
|
+
calls: [...calls, { to: zeroAddress }].map((call2) => ({
|
|
2044
|
+
...call2,
|
|
2045
|
+
from: account?.address
|
|
2046
|
+
})),
|
|
2047
|
+
stateOverrides
|
|
2048
|
+
},
|
|
2049
|
+
...traceAssetChanges ? [
|
|
2050
|
+
// ETH post balances
|
|
2051
|
+
{
|
|
2052
|
+
calls: [{ data: getBalanceData }]
|
|
2053
|
+
},
|
|
2054
|
+
// Asset post balances
|
|
2055
|
+
{
|
|
2056
|
+
calls: assetAddresses.map((address, i) => ({
|
|
2057
|
+
abi: [
|
|
2058
|
+
from3("function balanceOf(address) returns (uint256)")
|
|
2059
|
+
],
|
|
2060
|
+
functionName: "balanceOf",
|
|
2061
|
+
args: [account.address],
|
|
2062
|
+
to: address,
|
|
2063
|
+
from: zeroAddress,
|
|
2064
|
+
nonce: i
|
|
2065
|
+
})),
|
|
2066
|
+
stateOverrides: [
|
|
2067
|
+
{
|
|
2068
|
+
address: zeroAddress,
|
|
2069
|
+
nonce: 0
|
|
2070
|
+
}
|
|
2071
|
+
]
|
|
2072
|
+
},
|
|
2073
|
+
// Decimals
|
|
2074
|
+
{
|
|
2075
|
+
calls: assetAddresses.map((address, i) => ({
|
|
2076
|
+
to: address,
|
|
2077
|
+
abi: [
|
|
2078
|
+
from3("function decimals() returns (uint256)")
|
|
2079
|
+
],
|
|
2080
|
+
functionName: "decimals",
|
|
2081
|
+
from: zeroAddress,
|
|
2082
|
+
nonce: i
|
|
2083
|
+
})),
|
|
2084
|
+
stateOverrides: [
|
|
2085
|
+
{
|
|
2086
|
+
address: zeroAddress,
|
|
2087
|
+
nonce: 0
|
|
2088
|
+
}
|
|
2089
|
+
]
|
|
2090
|
+
},
|
|
2091
|
+
// Token URI
|
|
2092
|
+
{
|
|
2093
|
+
calls: assetAddresses.map((address, i) => ({
|
|
2094
|
+
to: address,
|
|
2095
|
+
abi: [
|
|
2096
|
+
from3("function tokenURI(uint256) returns (string)")
|
|
2097
|
+
],
|
|
2098
|
+
functionName: "tokenURI",
|
|
2099
|
+
args: [0n],
|
|
2100
|
+
from: zeroAddress,
|
|
2101
|
+
nonce: i
|
|
2102
|
+
})),
|
|
2103
|
+
stateOverrides: [
|
|
2104
|
+
{
|
|
2105
|
+
address: zeroAddress,
|
|
2106
|
+
nonce: 0
|
|
2107
|
+
}
|
|
2108
|
+
]
|
|
2109
|
+
},
|
|
2110
|
+
// Symbols
|
|
2111
|
+
{
|
|
2112
|
+
calls: assetAddresses.map((address, i) => ({
|
|
2113
|
+
to: address,
|
|
2114
|
+
abi: [from3("function symbol() returns (string)")],
|
|
2115
|
+
functionName: "symbol",
|
|
2116
|
+
from: zeroAddress,
|
|
2117
|
+
nonce: i
|
|
2118
|
+
})),
|
|
2119
|
+
stateOverrides: [
|
|
2120
|
+
{
|
|
2121
|
+
address: zeroAddress,
|
|
2122
|
+
nonce: 0
|
|
2123
|
+
}
|
|
2124
|
+
]
|
|
2125
|
+
}
|
|
2126
|
+
] : []
|
|
2127
|
+
],
|
|
2128
|
+
traceTransfers,
|
|
2129
|
+
validation
|
|
2130
|
+
});
|
|
2131
|
+
const block_results = traceAssetChanges ? blocks[2] : blocks[0];
|
|
2132
|
+
const [block_ethPre, block_assetsPre, , block_ethPost, block_assetsPost, block_decimals, block_tokenURI, block_symbols] = traceAssetChanges ? blocks : [];
|
|
2133
|
+
const { calls: block_calls, ...block } = block_results;
|
|
2134
|
+
const results = block_calls.slice(0, -1) ?? [];
|
|
2135
|
+
const ethPre = block_ethPre?.calls ?? [];
|
|
2136
|
+
const assetsPre = block_assetsPre?.calls ?? [];
|
|
2137
|
+
const balancesPre = [...ethPre, ...assetsPre].map((call2) => call2.status === "success" ? hexToBigInt(call2.data) : null);
|
|
2138
|
+
const ethPost = block_ethPost?.calls ?? [];
|
|
2139
|
+
const assetsPost = block_assetsPost?.calls ?? [];
|
|
2140
|
+
const balancesPost = [...ethPost, ...assetsPost].map((call2) => call2.status === "success" ? hexToBigInt(call2.data) : null);
|
|
2141
|
+
const decimals = (block_decimals?.calls ?? []).map((x) => x.status === "success" ? x.result : null);
|
|
2142
|
+
const symbols = (block_symbols?.calls ?? []).map((x) => x.status === "success" ? x.result : null);
|
|
2143
|
+
const tokenURI = (block_tokenURI?.calls ?? []).map((x) => x.status === "success" ? x.result : null);
|
|
2144
|
+
const changes = [];
|
|
2145
|
+
for (const [i, balancePost] of balancesPost.entries()) {
|
|
2146
|
+
const balancePre = balancesPre[i];
|
|
2147
|
+
if (typeof balancePost !== "bigint")
|
|
2148
|
+
continue;
|
|
2149
|
+
if (typeof balancePre !== "bigint")
|
|
2150
|
+
continue;
|
|
2151
|
+
const decimals_ = decimals[i - 1];
|
|
2152
|
+
const symbol_ = symbols[i - 1];
|
|
2153
|
+
const tokenURI_ = tokenURI[i - 1];
|
|
2154
|
+
const token = (() => {
|
|
2155
|
+
if (i === 0)
|
|
2156
|
+
return {
|
|
2157
|
+
address: ethAddress,
|
|
2158
|
+
decimals: 18,
|
|
2159
|
+
symbol: "ETH"
|
|
2160
|
+
};
|
|
2161
|
+
return {
|
|
2162
|
+
address: assetAddresses[i - 1],
|
|
2163
|
+
decimals: tokenURI_ || decimals_ ? Number(decimals_ ?? 1) : void 0,
|
|
2164
|
+
symbol: symbol_ ?? void 0
|
|
2165
|
+
};
|
|
2166
|
+
})();
|
|
2167
|
+
if (changes.some((change) => change.token.address === token.address))
|
|
2168
|
+
continue;
|
|
2169
|
+
changes.push({
|
|
2170
|
+
token,
|
|
2171
|
+
value: {
|
|
2172
|
+
pre: balancePre,
|
|
2173
|
+
post: balancePost,
|
|
2174
|
+
diff: balancePost - balancePre
|
|
2175
|
+
}
|
|
2176
|
+
});
|
|
2177
|
+
}
|
|
2178
|
+
return {
|
|
2179
|
+
assetChanges: changes,
|
|
2180
|
+
block,
|
|
2181
|
+
results
|
|
2182
|
+
};
|
|
2183
|
+
}
|
|
2184
|
+
|
|
2185
|
+
// node_modules/viem/_esm/actions/public/verifyMessage.js
|
|
2186
|
+
async function verifyMessage(client, { address, message, factory, factoryData, signature, ...callRequest }) {
|
|
2187
|
+
const hash = hashMessage(message);
|
|
2188
|
+
return getAction(client, verifyHash, "verifyHash")({
|
|
2189
|
+
address,
|
|
2190
|
+
factory,
|
|
2191
|
+
factoryData,
|
|
2192
|
+
hash,
|
|
2193
|
+
signature,
|
|
2194
|
+
...callRequest
|
|
2195
|
+
});
|
|
2196
|
+
}
|
|
2197
|
+
|
|
2198
|
+
// node_modules/viem/_esm/actions/public/verifyTypedData.js
|
|
2199
|
+
async function verifyTypedData(client, parameters) {
|
|
2200
|
+
const { address, factory, factoryData, signature, message, primaryType, types, domain, ...callRequest } = parameters;
|
|
2201
|
+
const hash = hashTypedData({ message, primaryType, types, domain });
|
|
2202
|
+
return getAction(client, verifyHash, "verifyHash")({
|
|
2203
|
+
address,
|
|
2204
|
+
factory,
|
|
2205
|
+
factoryData,
|
|
2206
|
+
hash,
|
|
2207
|
+
signature,
|
|
2208
|
+
...callRequest
|
|
2209
|
+
});
|
|
2210
|
+
}
|
|
2211
|
+
|
|
2212
|
+
// node_modules/viem/_esm/actions/public/watchBlocks.js
|
|
2213
|
+
function watchBlocks(client, { blockTag = client.experimental_blockTag ?? "latest", emitMissed = false, emitOnBegin = false, onBlock, onError, includeTransactions: includeTransactions_, poll: poll_, pollingInterval = client.pollingInterval }) {
|
|
2214
|
+
const enablePolling = (() => {
|
|
2215
|
+
if (typeof poll_ !== "undefined")
|
|
2216
|
+
return poll_;
|
|
2217
|
+
if (client.transport.type === "webSocket" || client.transport.type === "ipc")
|
|
2218
|
+
return false;
|
|
2219
|
+
if (client.transport.type === "fallback" && (client.transport.transports[0].config.type === "webSocket" || client.transport.transports[0].config.type === "ipc"))
|
|
2220
|
+
return false;
|
|
2221
|
+
return true;
|
|
2222
|
+
})();
|
|
2223
|
+
const includeTransactions = includeTransactions_ ?? false;
|
|
2224
|
+
let prevBlock;
|
|
2225
|
+
const pollBlocks = () => {
|
|
2226
|
+
const observerId = stringify([
|
|
2227
|
+
"watchBlocks",
|
|
2228
|
+
client.uid,
|
|
2229
|
+
blockTag,
|
|
2230
|
+
emitMissed,
|
|
2231
|
+
emitOnBegin,
|
|
2232
|
+
includeTransactions,
|
|
2233
|
+
pollingInterval
|
|
2234
|
+
]);
|
|
2235
|
+
return observe(observerId, { onBlock, onError }, (emit) => poll(async () => {
|
|
2236
|
+
try {
|
|
2237
|
+
const block = await getAction(client, getBlock, "getBlock")({
|
|
2238
|
+
blockTag,
|
|
2239
|
+
includeTransactions
|
|
2240
|
+
});
|
|
2241
|
+
if (block.number !== null && prevBlock?.number != null) {
|
|
2242
|
+
if (block.number === prevBlock.number)
|
|
2243
|
+
return;
|
|
2244
|
+
if (block.number - prevBlock.number > 1 && emitMissed) {
|
|
2245
|
+
for (let i = prevBlock?.number + 1n; i < block.number; i++) {
|
|
2246
|
+
const block2 = await getAction(client, getBlock, "getBlock")({
|
|
2247
|
+
blockNumber: i,
|
|
2248
|
+
includeTransactions
|
|
2249
|
+
});
|
|
2250
|
+
emit.onBlock(block2, prevBlock);
|
|
2251
|
+
prevBlock = block2;
|
|
2252
|
+
}
|
|
2253
|
+
}
|
|
2254
|
+
}
|
|
2255
|
+
if (
|
|
2256
|
+
// If no previous block exists, emit.
|
|
2257
|
+
prevBlock?.number == null || // If the block tag is "pending" with no block number, emit.
|
|
2258
|
+
blockTag === "pending" && block?.number == null || // If the next block number is greater than the previous block number, emit.
|
|
2259
|
+
// We don't want to emit blocks in the past.
|
|
2260
|
+
block.number !== null && block.number > prevBlock.number
|
|
2261
|
+
) {
|
|
2262
|
+
emit.onBlock(block, prevBlock);
|
|
2263
|
+
prevBlock = block;
|
|
2264
|
+
}
|
|
2265
|
+
} catch (err) {
|
|
2266
|
+
emit.onError?.(err);
|
|
2267
|
+
}
|
|
2268
|
+
}, {
|
|
2269
|
+
emitOnBegin,
|
|
2270
|
+
interval: pollingInterval
|
|
2271
|
+
}));
|
|
2272
|
+
};
|
|
2273
|
+
const subscribeBlocks = () => {
|
|
2274
|
+
let active = true;
|
|
2275
|
+
let emitFetched = true;
|
|
2276
|
+
let unsubscribe = () => active = false;
|
|
2277
|
+
(async () => {
|
|
2278
|
+
try {
|
|
2279
|
+
if (emitOnBegin) {
|
|
2280
|
+
getAction(client, getBlock, "getBlock")({
|
|
2281
|
+
blockTag,
|
|
2282
|
+
includeTransactions
|
|
2283
|
+
}).then((block) => {
|
|
2284
|
+
if (!active)
|
|
2285
|
+
return;
|
|
2286
|
+
if (!emitFetched)
|
|
2287
|
+
return;
|
|
2288
|
+
onBlock(block, void 0);
|
|
2289
|
+
emitFetched = false;
|
|
2290
|
+
}).catch(onError);
|
|
2291
|
+
}
|
|
2292
|
+
const transport = (() => {
|
|
2293
|
+
if (client.transport.type === "fallback") {
|
|
2294
|
+
const transport2 = client.transport.transports.find((transport3) => transport3.config.type === "webSocket" || transport3.config.type === "ipc");
|
|
2295
|
+
if (!transport2)
|
|
2296
|
+
return client.transport;
|
|
2297
|
+
return transport2.value;
|
|
2298
|
+
}
|
|
2299
|
+
return client.transport;
|
|
2300
|
+
})();
|
|
2301
|
+
const { unsubscribe: unsubscribe_ } = await transport.subscribe({
|
|
2302
|
+
params: ["newHeads"],
|
|
2303
|
+
async onData(data) {
|
|
2304
|
+
if (!active)
|
|
2305
|
+
return;
|
|
2306
|
+
const block = await getAction(client, getBlock, "getBlock")({
|
|
2307
|
+
blockNumber: data.result?.number,
|
|
2308
|
+
includeTransactions
|
|
2309
|
+
}).catch(() => {
|
|
2310
|
+
});
|
|
2311
|
+
if (!active)
|
|
2312
|
+
return;
|
|
2313
|
+
onBlock(block, prevBlock);
|
|
2314
|
+
emitFetched = false;
|
|
2315
|
+
prevBlock = block;
|
|
2316
|
+
},
|
|
2317
|
+
onError(error) {
|
|
2318
|
+
onError?.(error);
|
|
2319
|
+
}
|
|
2320
|
+
});
|
|
2321
|
+
unsubscribe = unsubscribe_;
|
|
2322
|
+
if (!active)
|
|
2323
|
+
unsubscribe();
|
|
2324
|
+
} catch (err) {
|
|
2325
|
+
onError?.(err);
|
|
2326
|
+
}
|
|
2327
|
+
})();
|
|
2328
|
+
return () => unsubscribe();
|
|
2329
|
+
};
|
|
2330
|
+
return enablePolling ? pollBlocks() : subscribeBlocks();
|
|
2331
|
+
}
|
|
2332
|
+
|
|
2333
|
+
// node_modules/viem/_esm/actions/public/watchEvent.js
|
|
2334
|
+
function watchEvent(client, { address, args, batch = true, event, events, fromBlock, onError, onLogs, poll: poll_, pollingInterval = client.pollingInterval, strict: strict_ }) {
|
|
2335
|
+
const enablePolling = (() => {
|
|
2336
|
+
if (typeof poll_ !== "undefined")
|
|
2337
|
+
return poll_;
|
|
2338
|
+
if (typeof fromBlock === "bigint")
|
|
2339
|
+
return true;
|
|
2340
|
+
if (client.transport.type === "webSocket" || client.transport.type === "ipc")
|
|
2341
|
+
return false;
|
|
2342
|
+
if (client.transport.type === "fallback" && (client.transport.transports[0].config.type === "webSocket" || client.transport.transports[0].config.type === "ipc"))
|
|
2343
|
+
return false;
|
|
2344
|
+
return true;
|
|
2345
|
+
})();
|
|
2346
|
+
const strict = strict_ ?? false;
|
|
2347
|
+
const pollEvent = () => {
|
|
2348
|
+
const observerId = stringify([
|
|
2349
|
+
"watchEvent",
|
|
2350
|
+
address,
|
|
2351
|
+
args,
|
|
2352
|
+
batch,
|
|
2353
|
+
client.uid,
|
|
2354
|
+
event,
|
|
2355
|
+
pollingInterval,
|
|
2356
|
+
fromBlock
|
|
2357
|
+
]);
|
|
2358
|
+
return observe(observerId, { onLogs, onError }, (emit) => {
|
|
2359
|
+
let previousBlockNumber;
|
|
2360
|
+
if (fromBlock !== void 0)
|
|
2361
|
+
previousBlockNumber = fromBlock - 1n;
|
|
2362
|
+
let filter;
|
|
2363
|
+
let initialized = false;
|
|
2364
|
+
const unwatch = poll(async () => {
|
|
2365
|
+
if (!initialized) {
|
|
2366
|
+
try {
|
|
2367
|
+
filter = await getAction(client, createEventFilter, "createEventFilter")({
|
|
2368
|
+
address,
|
|
2369
|
+
args,
|
|
2370
|
+
event,
|
|
2371
|
+
events,
|
|
2372
|
+
strict,
|
|
2373
|
+
fromBlock
|
|
2374
|
+
});
|
|
2375
|
+
} catch {
|
|
2376
|
+
}
|
|
2377
|
+
initialized = true;
|
|
2378
|
+
return;
|
|
2379
|
+
}
|
|
2380
|
+
try {
|
|
2381
|
+
let logs;
|
|
2382
|
+
if (filter) {
|
|
2383
|
+
logs = await getAction(client, getFilterChanges, "getFilterChanges")({ filter });
|
|
2384
|
+
} else {
|
|
2385
|
+
const blockNumber = await getAction(client, getBlockNumber, "getBlockNumber")({});
|
|
2386
|
+
if (previousBlockNumber && previousBlockNumber !== blockNumber) {
|
|
2387
|
+
logs = await getAction(client, getLogs, "getLogs")({
|
|
2388
|
+
address,
|
|
2389
|
+
args,
|
|
2390
|
+
event,
|
|
2391
|
+
events,
|
|
2392
|
+
fromBlock: previousBlockNumber + 1n,
|
|
2393
|
+
toBlock: blockNumber
|
|
2394
|
+
});
|
|
2395
|
+
} else {
|
|
2396
|
+
logs = [];
|
|
2397
|
+
}
|
|
2398
|
+
previousBlockNumber = blockNumber;
|
|
2399
|
+
}
|
|
2400
|
+
if (logs.length === 0)
|
|
2401
|
+
return;
|
|
2402
|
+
if (batch)
|
|
2403
|
+
emit.onLogs(logs);
|
|
2404
|
+
else
|
|
2405
|
+
for (const log of logs)
|
|
2406
|
+
emit.onLogs([log]);
|
|
2407
|
+
} catch (err) {
|
|
2408
|
+
if (filter && err instanceof InvalidInputRpcError)
|
|
2409
|
+
initialized = false;
|
|
2410
|
+
emit.onError?.(err);
|
|
2411
|
+
}
|
|
2412
|
+
}, {
|
|
2413
|
+
emitOnBegin: true,
|
|
2414
|
+
interval: pollingInterval
|
|
2415
|
+
});
|
|
2416
|
+
return async () => {
|
|
2417
|
+
if (filter)
|
|
2418
|
+
await getAction(client, uninstallFilter, "uninstallFilter")({ filter });
|
|
2419
|
+
unwatch();
|
|
2420
|
+
};
|
|
2421
|
+
});
|
|
2422
|
+
};
|
|
2423
|
+
const subscribeEvent = () => {
|
|
2424
|
+
let active = true;
|
|
2425
|
+
let unsubscribe = () => active = false;
|
|
2426
|
+
(async () => {
|
|
2427
|
+
try {
|
|
2428
|
+
const transport = (() => {
|
|
2429
|
+
if (client.transport.type === "fallback") {
|
|
2430
|
+
const transport2 = client.transport.transports.find((transport3) => transport3.config.type === "webSocket" || transport3.config.type === "ipc");
|
|
2431
|
+
if (!transport2)
|
|
2432
|
+
return client.transport;
|
|
2433
|
+
return transport2.value;
|
|
2434
|
+
}
|
|
2435
|
+
return client.transport;
|
|
2436
|
+
})();
|
|
2437
|
+
const events_ = events ?? (event ? [event] : void 0);
|
|
2438
|
+
let topics = [];
|
|
2439
|
+
if (events_) {
|
|
2440
|
+
const encoded = events_.flatMap((event2) => encodeEventTopics({
|
|
2441
|
+
abi: [event2],
|
|
2442
|
+
eventName: event2.name,
|
|
2443
|
+
args
|
|
2444
|
+
}));
|
|
2445
|
+
topics = [encoded];
|
|
2446
|
+
if (event)
|
|
2447
|
+
topics = topics[0];
|
|
2448
|
+
}
|
|
2449
|
+
const { unsubscribe: unsubscribe_ } = await transport.subscribe({
|
|
2450
|
+
params: ["logs", { address, topics }],
|
|
2451
|
+
onData(data) {
|
|
2452
|
+
if (!active)
|
|
2453
|
+
return;
|
|
2454
|
+
const log = data.result;
|
|
2455
|
+
try {
|
|
2456
|
+
const { eventName, args: args2 } = decodeEventLog({
|
|
2457
|
+
abi: events_ ?? [],
|
|
2458
|
+
data: log.data,
|
|
2459
|
+
topics: log.topics,
|
|
2460
|
+
strict
|
|
2461
|
+
});
|
|
2462
|
+
const formatted = formatLog(log, { args: args2, eventName });
|
|
2463
|
+
onLogs([formatted]);
|
|
2464
|
+
} catch (err) {
|
|
2465
|
+
let eventName;
|
|
2466
|
+
let isUnnamed;
|
|
2467
|
+
if (err instanceof DecodeLogDataMismatch || err instanceof DecodeLogTopicsMismatch) {
|
|
2468
|
+
if (strict_)
|
|
2469
|
+
return;
|
|
2470
|
+
eventName = err.abiItem.name;
|
|
2471
|
+
isUnnamed = err.abiItem.inputs?.some((x) => !("name" in x && x.name));
|
|
2472
|
+
}
|
|
2473
|
+
const formatted = formatLog(log, {
|
|
2474
|
+
args: isUnnamed ? [] : {},
|
|
2475
|
+
eventName
|
|
2476
|
+
});
|
|
2477
|
+
onLogs([formatted]);
|
|
2478
|
+
}
|
|
2479
|
+
},
|
|
2480
|
+
onError(error) {
|
|
2481
|
+
onError?.(error);
|
|
2482
|
+
}
|
|
2483
|
+
});
|
|
2484
|
+
unsubscribe = unsubscribe_;
|
|
2485
|
+
if (!active)
|
|
2486
|
+
unsubscribe();
|
|
2487
|
+
} catch (err) {
|
|
2488
|
+
onError?.(err);
|
|
2489
|
+
}
|
|
2490
|
+
})();
|
|
2491
|
+
return () => unsubscribe();
|
|
2492
|
+
};
|
|
2493
|
+
return enablePolling ? pollEvent() : subscribeEvent();
|
|
2494
|
+
}
|
|
2495
|
+
|
|
2496
|
+
// node_modules/viem/_esm/actions/public/watchPendingTransactions.js
|
|
2497
|
+
function watchPendingTransactions(client, { batch = true, onError, onTransactions, poll: poll_, pollingInterval = client.pollingInterval }) {
|
|
2498
|
+
const enablePolling = typeof poll_ !== "undefined" ? poll_ : client.transport.type !== "webSocket" && client.transport.type !== "ipc";
|
|
2499
|
+
const pollPendingTransactions = () => {
|
|
2500
|
+
const observerId = stringify([
|
|
2501
|
+
"watchPendingTransactions",
|
|
2502
|
+
client.uid,
|
|
2503
|
+
batch,
|
|
2504
|
+
pollingInterval
|
|
2505
|
+
]);
|
|
2506
|
+
return observe(observerId, { onTransactions, onError }, (emit) => {
|
|
2507
|
+
let filter;
|
|
2508
|
+
const unwatch = poll(async () => {
|
|
2509
|
+
try {
|
|
2510
|
+
if (!filter) {
|
|
2511
|
+
try {
|
|
2512
|
+
filter = await getAction(client, createPendingTransactionFilter, "createPendingTransactionFilter")({});
|
|
2513
|
+
return;
|
|
2514
|
+
} catch (err) {
|
|
2515
|
+
unwatch();
|
|
2516
|
+
throw err;
|
|
2517
|
+
}
|
|
2518
|
+
}
|
|
2519
|
+
const hashes = await getAction(client, getFilterChanges, "getFilterChanges")({ filter });
|
|
2520
|
+
if (hashes.length === 0)
|
|
2521
|
+
return;
|
|
2522
|
+
if (batch)
|
|
2523
|
+
emit.onTransactions(hashes);
|
|
2524
|
+
else
|
|
2525
|
+
for (const hash of hashes)
|
|
2526
|
+
emit.onTransactions([hash]);
|
|
2527
|
+
} catch (err) {
|
|
2528
|
+
emit.onError?.(err);
|
|
2529
|
+
}
|
|
2530
|
+
}, {
|
|
2531
|
+
emitOnBegin: true,
|
|
2532
|
+
interval: pollingInterval
|
|
2533
|
+
});
|
|
2534
|
+
return async () => {
|
|
2535
|
+
if (filter)
|
|
2536
|
+
await getAction(client, uninstallFilter, "uninstallFilter")({ filter });
|
|
2537
|
+
unwatch();
|
|
2538
|
+
};
|
|
2539
|
+
});
|
|
2540
|
+
};
|
|
2541
|
+
const subscribePendingTransactions = () => {
|
|
2542
|
+
let active = true;
|
|
2543
|
+
let unsubscribe = () => active = false;
|
|
2544
|
+
(async () => {
|
|
2545
|
+
try {
|
|
2546
|
+
const { unsubscribe: unsubscribe_ } = await client.transport.subscribe({
|
|
2547
|
+
params: ["newPendingTransactions"],
|
|
2548
|
+
onData(data) {
|
|
2549
|
+
if (!active)
|
|
2550
|
+
return;
|
|
2551
|
+
const transaction = data.result;
|
|
2552
|
+
onTransactions([transaction]);
|
|
2553
|
+
},
|
|
2554
|
+
onError(error) {
|
|
2555
|
+
onError?.(error);
|
|
2556
|
+
}
|
|
2557
|
+
});
|
|
2558
|
+
unsubscribe = unsubscribe_;
|
|
2559
|
+
if (!active)
|
|
2560
|
+
unsubscribe();
|
|
2561
|
+
} catch (err) {
|
|
2562
|
+
onError?.(err);
|
|
2563
|
+
}
|
|
2564
|
+
})();
|
|
2565
|
+
return () => unsubscribe();
|
|
2566
|
+
};
|
|
2567
|
+
return enablePolling ? pollPendingTransactions() : subscribePendingTransactions();
|
|
2568
|
+
}
|
|
2569
|
+
|
|
2570
|
+
// node_modules/viem/_esm/utils/siwe/parseSiweMessage.js
|
|
2571
|
+
function parseSiweMessage(message) {
|
|
2572
|
+
const { scheme, statement, ...prefix } = message.match(prefixRegex)?.groups ?? {};
|
|
2573
|
+
const { chainId, expirationTime, issuedAt, notBefore, requestId, ...suffix } = message.match(suffixRegex)?.groups ?? {};
|
|
2574
|
+
const resources = message.split("Resources:")[1]?.split("\n- ").slice(1);
|
|
2575
|
+
return {
|
|
2576
|
+
...prefix,
|
|
2577
|
+
...suffix,
|
|
2578
|
+
...chainId ? { chainId: Number(chainId) } : {},
|
|
2579
|
+
...expirationTime ? { expirationTime: new Date(expirationTime) } : {},
|
|
2580
|
+
...issuedAt ? { issuedAt: new Date(issuedAt) } : {},
|
|
2581
|
+
...notBefore ? { notBefore: new Date(notBefore) } : {},
|
|
2582
|
+
...requestId ? { requestId } : {},
|
|
2583
|
+
...resources ? { resources } : {},
|
|
2584
|
+
...scheme ? { scheme } : {},
|
|
2585
|
+
...statement ? { statement } : {}
|
|
2586
|
+
};
|
|
2587
|
+
}
|
|
2588
|
+
var prefixRegex = /^(?:(?<scheme>[a-zA-Z][a-zA-Z0-9+-.]*):\/\/)?(?<domain>[a-zA-Z0-9+-.]*(?::[0-9]{1,5})?) (?:wants you to sign in with your Ethereum account:\n)(?<address>0x[a-fA-F0-9]{40})\n\n(?:(?<statement>.*)\n\n)?/;
|
|
2589
|
+
var suffixRegex = /(?:URI: (?<uri>.+))\n(?:Version: (?<version>.+))\n(?:Chain ID: (?<chainId>\d+))\n(?:Nonce: (?<nonce>[a-zA-Z0-9]+))\n(?:Issued At: (?<issuedAt>.+))(?:\nExpiration Time: (?<expirationTime>.+))?(?:\nNot Before: (?<notBefore>.+))?(?:\nRequest ID: (?<requestId>.+))?/;
|
|
2590
|
+
|
|
2591
|
+
// node_modules/viem/_esm/utils/siwe/validateSiweMessage.js
|
|
2592
|
+
function validateSiweMessage(parameters) {
|
|
2593
|
+
const { address, domain, message, nonce, scheme, time = /* @__PURE__ */ new Date() } = parameters;
|
|
2594
|
+
if (domain && message.domain !== domain)
|
|
2595
|
+
return false;
|
|
2596
|
+
if (nonce && message.nonce !== nonce)
|
|
2597
|
+
return false;
|
|
2598
|
+
if (scheme && message.scheme !== scheme)
|
|
2599
|
+
return false;
|
|
2600
|
+
if (message.expirationTime && time >= message.expirationTime)
|
|
2601
|
+
return false;
|
|
2602
|
+
if (message.notBefore && time < message.notBefore)
|
|
2603
|
+
return false;
|
|
2604
|
+
try {
|
|
2605
|
+
if (!message.address)
|
|
2606
|
+
return false;
|
|
2607
|
+
if (!isAddress(message.address, { strict: false }))
|
|
2608
|
+
return false;
|
|
2609
|
+
if (address && !isAddressEqual(message.address, address))
|
|
2610
|
+
return false;
|
|
2611
|
+
} catch {
|
|
2612
|
+
return false;
|
|
2613
|
+
}
|
|
2614
|
+
return true;
|
|
2615
|
+
}
|
|
2616
|
+
|
|
2617
|
+
// node_modules/viem/_esm/actions/siwe/verifySiweMessage.js
|
|
2618
|
+
async function verifySiweMessage(client, parameters) {
|
|
2619
|
+
const { address, domain, message, nonce, scheme, signature, time = /* @__PURE__ */ new Date(), ...callRequest } = parameters;
|
|
2620
|
+
const parsed = parseSiweMessage(message);
|
|
2621
|
+
if (!parsed.address)
|
|
2622
|
+
return false;
|
|
2623
|
+
const isValid = validateSiweMessage({
|
|
2624
|
+
address,
|
|
2625
|
+
domain,
|
|
2626
|
+
message: parsed,
|
|
2627
|
+
nonce,
|
|
2628
|
+
scheme,
|
|
2629
|
+
time
|
|
2630
|
+
});
|
|
2631
|
+
if (!isValid)
|
|
2632
|
+
return false;
|
|
2633
|
+
const hash = hashMessage(message);
|
|
2634
|
+
return verifyHash(client, {
|
|
2635
|
+
address: parsed.address,
|
|
2636
|
+
hash,
|
|
2637
|
+
signature,
|
|
2638
|
+
...callRequest
|
|
2639
|
+
});
|
|
2640
|
+
}
|
|
2641
|
+
|
|
2642
|
+
// node_modules/viem/_esm/actions/token/internal.js
|
|
2643
|
+
function toAmount(amount, decimals) {
|
|
2644
|
+
return { amount, decimals, formatted: formatUnits(amount, decimals) };
|
|
2645
|
+
}
|
|
2646
|
+
function toBaseUnits(amount, decimals) {
|
|
2647
|
+
if (typeof amount === "bigint")
|
|
2648
|
+
return amount;
|
|
2649
|
+
const resolved = amount.decimals ?? decimals;
|
|
2650
|
+
return parseUnits(amount.formatted, requireTokenDecimals(resolved));
|
|
2651
|
+
}
|
|
2652
|
+
function requireTokenDecimals(decimals) {
|
|
2653
|
+
if (decimals === void 0)
|
|
2654
|
+
throw new Error("Token decimals are required. Pass `amount.decimals` or select a declared token.");
|
|
2655
|
+
return decimals;
|
|
2656
|
+
}
|
|
2657
|
+
function resolveAmountDecimals(amount, decimals) {
|
|
2658
|
+
if (typeof amount === "bigint")
|
|
2659
|
+
return decimals;
|
|
2660
|
+
return amount.decimals ?? decimals;
|
|
2661
|
+
}
|
|
2662
|
+
function resolveToken(client, parameters) {
|
|
2663
|
+
const { decimals, token } = parameters;
|
|
2664
|
+
const declared = findDeclaredToken(client, token);
|
|
2665
|
+
if (declared)
|
|
2666
|
+
return {
|
|
2667
|
+
address: declared.address,
|
|
2668
|
+
decimals: decimals ?? declared.decimals
|
|
2669
|
+
};
|
|
2670
|
+
if (isAddress(token, { strict: false }))
|
|
2671
|
+
return {
|
|
2672
|
+
address: token,
|
|
2673
|
+
decimals: decimals ?? inferDecimals(client, token)
|
|
2674
|
+
};
|
|
2675
|
+
throw new Error(`Token "${token}" is not a declared ERC-20 token on the client's \`tokens\` array (with an address for the client's chain), and is not a valid address.`);
|
|
2676
|
+
}
|
|
2677
|
+
function findDeclaredToken(client, token) {
|
|
2678
|
+
const tokens = client.tokens;
|
|
2679
|
+
const chainId = client.chain?.id;
|
|
2680
|
+
if (!tokens || chainId === void 0)
|
|
2681
|
+
return void 0;
|
|
2682
|
+
const bySymbol = findTokenBySymbol(tokens, token);
|
|
2683
|
+
if (bySymbol)
|
|
2684
|
+
return resolveTokenForChain(bySymbol, chainId);
|
|
2685
|
+
if (isAddress(token, { strict: false }))
|
|
2686
|
+
for (const token_ of tokens) {
|
|
2687
|
+
const resolved = resolveTokenForChain(token_, chainId);
|
|
2688
|
+
if (resolved && isAddressEqual(resolved.address, token))
|
|
2689
|
+
return resolved;
|
|
2690
|
+
}
|
|
2691
|
+
return void 0;
|
|
2692
|
+
}
|
|
2693
|
+
function resolveTokenForChain(token, chainId) {
|
|
2694
|
+
const address = token.addresses[chainId];
|
|
2695
|
+
if (!address)
|
|
2696
|
+
return void 0;
|
|
2697
|
+
return {
|
|
2698
|
+
address,
|
|
2699
|
+
currency: token.currency,
|
|
2700
|
+
decimals: token.decimals,
|
|
2701
|
+
name: token.name,
|
|
2702
|
+
popular: token.popular,
|
|
2703
|
+
symbol: token.symbol
|
|
2704
|
+
};
|
|
2705
|
+
}
|
|
2706
|
+
function findTokenBySymbol(tokens, symbol) {
|
|
2707
|
+
const lowerSymbol = symbol.toLowerCase();
|
|
2708
|
+
for (const token of tokens) {
|
|
2709
|
+
if (token.symbol?.toLowerCase() === lowerSymbol)
|
|
2710
|
+
return token;
|
|
2711
|
+
}
|
|
2712
|
+
return void 0;
|
|
2713
|
+
}
|
|
2714
|
+
function inferDecimals(client, address) {
|
|
2715
|
+
const tokens = client.tokens;
|
|
2716
|
+
const chainId = client.chain?.id;
|
|
2717
|
+
if (tokens && chainId !== void 0)
|
|
2718
|
+
for (const token of tokens) {
|
|
2719
|
+
const resolved = resolveTokenForChain(token, chainId);
|
|
2720
|
+
if (resolved && isAddressEqual(resolved.address, address))
|
|
2721
|
+
return resolved.decimals;
|
|
2722
|
+
}
|
|
2723
|
+
return void 0;
|
|
2724
|
+
}
|
|
2725
|
+
async function resolveTokenWithDecimals(client, parameters) {
|
|
2726
|
+
const { address, decimals } = resolveToken(client, parameters);
|
|
2727
|
+
if (decimals !== void 0)
|
|
2728
|
+
return { address, decimals };
|
|
2729
|
+
return {
|
|
2730
|
+
address,
|
|
2731
|
+
decimals: await readContract(client, {
|
|
2732
|
+
abi: erc20Abi,
|
|
2733
|
+
address,
|
|
2734
|
+
functionName: "decimals"
|
|
2735
|
+
})
|
|
2736
|
+
};
|
|
2737
|
+
}
|
|
2738
|
+
function pickWriteParameters(parameters) {
|
|
2739
|
+
const { account, chain, gas, maxFeePerGas, maxPriorityFeePerGas, nonce } = parameters;
|
|
2740
|
+
return { account, chain, gas, maxFeePerGas, maxPriorityFeePerGas, nonce };
|
|
2741
|
+
}
|
|
2742
|
+
function defineCall(call2) {
|
|
2743
|
+
return {
|
|
2744
|
+
...call2,
|
|
2745
|
+
data: encodeFunctionData(call2),
|
|
2746
|
+
to: call2.address
|
|
2747
|
+
};
|
|
2748
|
+
}
|
|
2749
|
+
|
|
2750
|
+
// node_modules/viem/_esm/actions/token/approve.js
|
|
2751
|
+
async function approve(client, parameters) {
|
|
2752
|
+
return approve.inner(writeContract, client, parameters);
|
|
2753
|
+
}
|
|
2754
|
+
(function(approve2) {
|
|
2755
|
+
async function inner(action, client, parameters) {
|
|
2756
|
+
return await action(client, {
|
|
2757
|
+
...parameters,
|
|
2758
|
+
...approve2.call(client, parameters)
|
|
2759
|
+
});
|
|
2760
|
+
}
|
|
2761
|
+
approve2.inner = inner;
|
|
2762
|
+
function call2(client, parameters) {
|
|
2763
|
+
return defineCall(getCall(client, parameters));
|
|
2764
|
+
}
|
|
2765
|
+
approve2.call = call2;
|
|
2766
|
+
async function estimateGas2(client, parameters) {
|
|
2767
|
+
return estimateContractGas(client, {
|
|
2768
|
+
...pickWriteParameters(parameters),
|
|
2769
|
+
...approve2.call(client, parameters)
|
|
2770
|
+
});
|
|
2771
|
+
}
|
|
2772
|
+
approve2.estimateGas = estimateGas2;
|
|
2773
|
+
async function simulate(client, parameters) {
|
|
2774
|
+
return simulateContract(client, {
|
|
2775
|
+
...pickWriteParameters(parameters),
|
|
2776
|
+
...approve2.call(client, parameters)
|
|
2777
|
+
});
|
|
2778
|
+
}
|
|
2779
|
+
approve2.simulate = simulate;
|
|
2780
|
+
function extractEvent(logs) {
|
|
2781
|
+
const [log] = parseEventLogs({
|
|
2782
|
+
abi: erc20Abi,
|
|
2783
|
+
logs,
|
|
2784
|
+
eventName: "Approval",
|
|
2785
|
+
strict: true
|
|
2786
|
+
});
|
|
2787
|
+
if (!log)
|
|
2788
|
+
throw new Error("`Approval` event not found.");
|
|
2789
|
+
return log;
|
|
2790
|
+
}
|
|
2791
|
+
approve2.extractEvent = extractEvent;
|
|
2792
|
+
})(approve || (approve = {}));
|
|
2793
|
+
function getCall(client, parameters) {
|
|
2794
|
+
const { amount, spender, token } = parameters;
|
|
2795
|
+
const { address, decimals } = resolveToken(client, { token });
|
|
2796
|
+
return {
|
|
2797
|
+
abi: erc20Abi,
|
|
2798
|
+
address,
|
|
2799
|
+
args: [spender, toBaseUnits(amount, decimals)],
|
|
2800
|
+
functionName: "approve"
|
|
2801
|
+
};
|
|
2802
|
+
}
|
|
2803
|
+
|
|
2804
|
+
// node_modules/viem/_esm/actions/token/approveSync.js
|
|
2805
|
+
async function approveSync(client, parameters) {
|
|
2806
|
+
const { amount, token, throwOnReceiptRevert = true } = parameters;
|
|
2807
|
+
const { decimals } = resolveToken(client, { token });
|
|
2808
|
+
const resolved = resolveAmountDecimals(amount, decimals);
|
|
2809
|
+
const receipt = await approve.inner(writeContractSync, client, {
|
|
2810
|
+
...parameters,
|
|
2811
|
+
throwOnReceiptRevert
|
|
2812
|
+
});
|
|
2813
|
+
const { args } = approve.extractEvent(receipt.logs);
|
|
2814
|
+
return {
|
|
2815
|
+
...args,
|
|
2816
|
+
...resolved === void 0 ? {} : { decimals: resolved, formatted: formatUnits(args.value, resolved) },
|
|
2817
|
+
receipt
|
|
2818
|
+
};
|
|
2819
|
+
}
|
|
2820
|
+
|
|
2821
|
+
// node_modules/viem/_esm/actions/token/getAllowance.js
|
|
2822
|
+
async function getAllowance(client, parameters) {
|
|
2823
|
+
const { account, decimals, spender, token, ...rest } = parameters;
|
|
2824
|
+
const [amount, { decimals: resolved }] = await Promise.all([
|
|
2825
|
+
readContract(client, {
|
|
2826
|
+
...rest,
|
|
2827
|
+
...getAllowance.call(client, { account, spender, token })
|
|
2828
|
+
}),
|
|
2829
|
+
resolveTokenWithDecimals(client, {
|
|
2830
|
+
decimals,
|
|
2831
|
+
token
|
|
2832
|
+
})
|
|
2833
|
+
]);
|
|
2834
|
+
return toAmount(amount, resolved);
|
|
2835
|
+
}
|
|
2836
|
+
(function(getAllowance2) {
|
|
2837
|
+
function call2(client, args) {
|
|
2838
|
+
return defineCall({
|
|
2839
|
+
address: resolveToken(client, args).address,
|
|
2840
|
+
abi: erc20Abi,
|
|
2841
|
+
functionName: "allowance",
|
|
2842
|
+
args: [args.account, args.spender]
|
|
2843
|
+
});
|
|
2844
|
+
}
|
|
2845
|
+
getAllowance2.call = call2;
|
|
2846
|
+
})(getAllowance || (getAllowance = {}));
|
|
2847
|
+
|
|
2848
|
+
// node_modules/viem/_esm/actions/token/getBalance.js
|
|
2849
|
+
async function getBalance2(client, parameters) {
|
|
2850
|
+
const { account: account_ = client.account, decimals, token, ...rest } = parameters;
|
|
2851
|
+
if (!account_)
|
|
2852
|
+
throw new AccountNotFoundError();
|
|
2853
|
+
const account = parseAccount(account_).address;
|
|
2854
|
+
const [amount, { decimals: resolved }] = await Promise.all([
|
|
2855
|
+
readContract(client, {
|
|
2856
|
+
...rest,
|
|
2857
|
+
...getBalance2.call(client, { account, token })
|
|
2858
|
+
}),
|
|
2859
|
+
resolveTokenWithDecimals(client, {
|
|
2860
|
+
decimals,
|
|
2861
|
+
token
|
|
2862
|
+
})
|
|
2863
|
+
]);
|
|
2864
|
+
return toAmount(amount, resolved);
|
|
2865
|
+
}
|
|
2866
|
+
(function(getBalance3) {
|
|
2867
|
+
function call2(client, args) {
|
|
2868
|
+
const account_ = args.account ?? client.account;
|
|
2869
|
+
if (!account_)
|
|
2870
|
+
throw new AccountNotFoundError();
|
|
2871
|
+
const account = parseAccount(account_).address;
|
|
2872
|
+
return defineCall({
|
|
2873
|
+
address: resolveToken(client, args).address,
|
|
2874
|
+
abi: erc20Abi,
|
|
2875
|
+
functionName: "balanceOf",
|
|
2876
|
+
args: [account]
|
|
2877
|
+
});
|
|
2878
|
+
}
|
|
2879
|
+
getBalance3.call = call2;
|
|
2880
|
+
})(getBalance2 || (getBalance2 = {}));
|
|
2881
|
+
|
|
2882
|
+
// node_modules/viem/_esm/actions/token/getMetadata.js
|
|
2883
|
+
async function getMetadata(client, parameters) {
|
|
2884
|
+
const { token, ...rest } = parameters;
|
|
2885
|
+
const { address } = resolveToken(client, { token });
|
|
2886
|
+
const declared = findDeclaredToken(client, token);
|
|
2887
|
+
const [decimals_, name, symbol] = await Promise.all([
|
|
2888
|
+
declared?.decimals ?? readContract(client, {
|
|
2889
|
+
...rest,
|
|
2890
|
+
abi: erc20Abi,
|
|
2891
|
+
address,
|
|
2892
|
+
functionName: "decimals"
|
|
2893
|
+
}),
|
|
2894
|
+
declared?.name ?? readContract(client, {
|
|
2895
|
+
...rest,
|
|
2896
|
+
abi: erc20Abi,
|
|
2897
|
+
address,
|
|
2898
|
+
functionName: "name"
|
|
2899
|
+
}),
|
|
2900
|
+
declared?.symbol ?? readContract(client, {
|
|
2901
|
+
...rest,
|
|
2902
|
+
abi: erc20Abi,
|
|
2903
|
+
address,
|
|
2904
|
+
functionName: "symbol"
|
|
2905
|
+
})
|
|
2906
|
+
]);
|
|
2907
|
+
return {
|
|
2908
|
+
decimals: decimals_,
|
|
2909
|
+
name,
|
|
2910
|
+
symbol
|
|
2911
|
+
};
|
|
2912
|
+
}
|
|
2913
|
+
|
|
2914
|
+
// node_modules/viem/_esm/actions/token/getTotalSupply.js
|
|
2915
|
+
async function getTotalSupply(client, parameters) {
|
|
2916
|
+
const { decimals, token, ...rest } = parameters;
|
|
2917
|
+
const [amount, { decimals: resolved }] = await Promise.all([
|
|
2918
|
+
readContract(client, {
|
|
2919
|
+
...rest,
|
|
2920
|
+
...getTotalSupply.call(client, { token })
|
|
2921
|
+
}),
|
|
2922
|
+
resolveTokenWithDecimals(client, {
|
|
2923
|
+
decimals,
|
|
2924
|
+
token
|
|
2925
|
+
})
|
|
2926
|
+
]);
|
|
2927
|
+
return toAmount(amount, resolved);
|
|
2928
|
+
}
|
|
2929
|
+
(function(getTotalSupply2) {
|
|
2930
|
+
function call2(client, args) {
|
|
2931
|
+
return defineCall({
|
|
2932
|
+
address: resolveToken(client, args).address,
|
|
2933
|
+
abi: erc20Abi,
|
|
2934
|
+
args: [],
|
|
2935
|
+
functionName: "totalSupply"
|
|
2936
|
+
});
|
|
2937
|
+
}
|
|
2938
|
+
getTotalSupply2.call = call2;
|
|
2939
|
+
})(getTotalSupply || (getTotalSupply = {}));
|
|
2940
|
+
|
|
2941
|
+
// node_modules/viem/_esm/actions/token/transfer.js
|
|
2942
|
+
async function transfer(client, parameters) {
|
|
2943
|
+
return transfer.inner(writeContract, client, parameters);
|
|
2944
|
+
}
|
|
2945
|
+
(function(transfer2) {
|
|
2946
|
+
async function inner(action, client, parameters) {
|
|
2947
|
+
return await action(client, {
|
|
2948
|
+
...parameters,
|
|
2949
|
+
...transfer2.call(client, parameters)
|
|
2950
|
+
});
|
|
2951
|
+
}
|
|
2952
|
+
transfer2.inner = inner;
|
|
2953
|
+
function call2(client, parameters) {
|
|
2954
|
+
return defineCall(getCall2(client, parameters));
|
|
2955
|
+
}
|
|
2956
|
+
transfer2.call = call2;
|
|
2957
|
+
async function estimateGas2(client, parameters) {
|
|
2958
|
+
return estimateContractGas(client, {
|
|
2959
|
+
...pickWriteParameters(parameters),
|
|
2960
|
+
...transfer2.call(client, parameters)
|
|
2961
|
+
});
|
|
2962
|
+
}
|
|
2963
|
+
transfer2.estimateGas = estimateGas2;
|
|
2964
|
+
async function simulate(client, parameters) {
|
|
2965
|
+
return simulateContract(client, {
|
|
2966
|
+
...pickWriteParameters(parameters),
|
|
2967
|
+
...transfer2.call(client, parameters)
|
|
2968
|
+
});
|
|
2969
|
+
}
|
|
2970
|
+
transfer2.simulate = simulate;
|
|
2971
|
+
function extractEvent(logs) {
|
|
2972
|
+
const [log] = parseEventLogs({
|
|
2973
|
+
abi: erc20Abi,
|
|
2974
|
+
logs,
|
|
2975
|
+
eventName: "Transfer",
|
|
2976
|
+
strict: true
|
|
2977
|
+
});
|
|
2978
|
+
if (!log)
|
|
2979
|
+
throw new Error("`Transfer` event not found.");
|
|
2980
|
+
return log;
|
|
2981
|
+
}
|
|
2982
|
+
transfer2.extractEvent = extractEvent;
|
|
2983
|
+
})(transfer || (transfer = {}));
|
|
2984
|
+
function getCall2(client, parameters) {
|
|
2985
|
+
const { amount, from: from4, to, token } = parameters;
|
|
2986
|
+
const { address, decimals } = resolveToken(client, { token });
|
|
2987
|
+
const value = toBaseUnits(amount, decimals);
|
|
2988
|
+
if (from4)
|
|
2989
|
+
return {
|
|
2990
|
+
abi: erc20Abi,
|
|
2991
|
+
address,
|
|
2992
|
+
args: [from4, to, value],
|
|
2993
|
+
functionName: "transferFrom"
|
|
2994
|
+
};
|
|
2995
|
+
return {
|
|
2996
|
+
abi: erc20Abi,
|
|
2997
|
+
address,
|
|
2998
|
+
args: [to, value],
|
|
2999
|
+
functionName: "transfer"
|
|
3000
|
+
};
|
|
3001
|
+
}
|
|
3002
|
+
|
|
3003
|
+
// node_modules/viem/_esm/actions/token/transferSync.js
|
|
3004
|
+
async function transferSync(client, parameters) {
|
|
3005
|
+
const { amount, token, throwOnReceiptRevert = true } = parameters;
|
|
3006
|
+
const { decimals } = resolveToken(client, { token });
|
|
3007
|
+
const resolved = resolveAmountDecimals(amount, decimals);
|
|
3008
|
+
const receipt = await transfer.inner(writeContractSync, client, {
|
|
3009
|
+
...parameters,
|
|
3010
|
+
throwOnReceiptRevert
|
|
3011
|
+
});
|
|
3012
|
+
const { args } = transfer.extractEvent(receipt.logs);
|
|
3013
|
+
return {
|
|
3014
|
+
...args,
|
|
3015
|
+
...resolved === void 0 ? {} : { decimals: resolved, formatted: formatUnits(args.value, resolved) },
|
|
3016
|
+
receipt
|
|
3017
|
+
};
|
|
3018
|
+
}
|
|
3019
|
+
|
|
3020
|
+
// node_modules/viem/_esm/clients/decorators/public.js
|
|
3021
|
+
function publicActions(client) {
|
|
3022
|
+
return {
|
|
3023
|
+
call: (args) => call(client, args),
|
|
3024
|
+
createAccessList: (args) => createAccessList(client, args),
|
|
3025
|
+
createBlockFilter: () => createBlockFilter(client),
|
|
3026
|
+
createContractEventFilter: (args) => createContractEventFilter(client, args),
|
|
3027
|
+
createEventFilter: (args) => createEventFilter(client, args),
|
|
3028
|
+
createPendingTransactionFilter: () => createPendingTransactionFilter(client),
|
|
3029
|
+
estimateContractGas: (args) => estimateContractGas(client, args),
|
|
3030
|
+
estimateGas: (args) => estimateGas(client, args),
|
|
3031
|
+
getBalance: (args) => getBalance(client, args),
|
|
3032
|
+
getBlobBaseFee: () => getBlobBaseFee(client),
|
|
3033
|
+
getBlock: (args) => getBlock(client, args),
|
|
3034
|
+
getBlockNumber: (args) => getBlockNumber(client, args),
|
|
3035
|
+
getBlockReceipts: (args) => getBlockReceipts(client, args),
|
|
3036
|
+
getBlockTransactionCount: (args) => getBlockTransactionCount(client, args),
|
|
3037
|
+
getBytecode: (args) => getCode(client, args),
|
|
3038
|
+
getChainId: () => getChainId(client),
|
|
3039
|
+
getCode: (args) => getCode(client, args),
|
|
3040
|
+
getContractEvents: (args) => getContractEvents(client, args),
|
|
3041
|
+
getDelegation: (args) => getDelegation(client, args),
|
|
3042
|
+
getEip712Domain: (args) => getEip712Domain(client, args),
|
|
3043
|
+
getEnsAddress: (args) => getEnsAddress(client, args),
|
|
3044
|
+
getEnsAvatar: (args) => getEnsAvatar(client, args),
|
|
3045
|
+
getEnsName: (args) => getEnsName(client, args),
|
|
3046
|
+
getEnsResolver: (args) => getEnsResolver(client, args),
|
|
3047
|
+
getEnsText: (args) => getEnsText(client, args),
|
|
3048
|
+
getFeeHistory: (args) => getFeeHistory(client, args),
|
|
3049
|
+
estimateFeesPerGas: (args) => estimateFeesPerGas(client, args),
|
|
3050
|
+
getFilterChanges: (args) => getFilterChanges(client, args),
|
|
3051
|
+
getFilterLogs: (args) => getFilterLogs(client, args),
|
|
3052
|
+
getGasPrice: () => getGasPrice(client),
|
|
3053
|
+
getLogs: (args) => getLogs(client, args),
|
|
3054
|
+
getProof: (args) => getProof(client, args),
|
|
3055
|
+
estimateMaxPriorityFeePerGas: (args) => estimateMaxPriorityFeePerGas(client, args),
|
|
3056
|
+
fillTransaction: (args) => fillTransaction(client, args),
|
|
3057
|
+
getRawTransaction: (args) => getRawTransaction(client, args),
|
|
3058
|
+
getStorageAt: (args) => getStorageAt(client, args),
|
|
3059
|
+
getTransaction: (args) => getTransaction(client, args),
|
|
3060
|
+
getTransactionConfirmations: (args) => getTransactionConfirmations(client, args),
|
|
3061
|
+
getTransactionCount: (args) => getTransactionCount(client, args),
|
|
3062
|
+
getTransactionReceipt: (args) => getTransactionReceipt(client, args),
|
|
3063
|
+
multicall: (args) => multicall(client, args),
|
|
3064
|
+
prepareTransactionRequest: (args) => prepareTransactionRequest(client, args),
|
|
3065
|
+
readContract: (args) => readContract(client, args),
|
|
3066
|
+
sendRawTransaction: (args) => sendRawTransaction(client, args),
|
|
3067
|
+
sendRawTransactionSync: (args) => sendRawTransactionSync(client, args),
|
|
3068
|
+
simulate: (args) => simulateBlocks(client, args),
|
|
3069
|
+
simulateBlocks: (args) => simulateBlocks(client, args),
|
|
3070
|
+
simulateCalls: (args) => simulateCalls(client, args),
|
|
3071
|
+
simulateContract: (args) => simulateContract(client, args),
|
|
3072
|
+
verifyHash: (args) => verifyHash(client, args),
|
|
3073
|
+
verifyMessage: (args) => verifyMessage(client, args),
|
|
3074
|
+
verifySiweMessage: (args) => verifySiweMessage(client, args),
|
|
3075
|
+
verifyTypedData: (args) => verifyTypedData(client, args),
|
|
3076
|
+
uninstallFilter: (args) => uninstallFilter(client, args),
|
|
3077
|
+
waitForTransactionReceipt: (args) => waitForTransactionReceipt(client, args),
|
|
3078
|
+
watchBlocks: (args) => watchBlocks(client, args),
|
|
3079
|
+
watchBlockNumber: (args) => watchBlockNumber(client, args),
|
|
3080
|
+
watchContractEvent: (args) => watchContractEvent(client, args),
|
|
3081
|
+
watchEvent: (args) => watchEvent(client, args),
|
|
3082
|
+
watchPendingTransactions: (args) => watchPendingTransactions(client, args),
|
|
3083
|
+
token: bindPublicToken(client)
|
|
3084
|
+
};
|
|
3085
|
+
}
|
|
3086
|
+
function bindPublicToken(client) {
|
|
3087
|
+
return {
|
|
3088
|
+
getAllowance: bindActionDecorators(client, getAllowance),
|
|
3089
|
+
getBalance: bindActionDecorators(client, getBalance2),
|
|
3090
|
+
getMetadata: bindActionDecorators(client, getMetadata),
|
|
3091
|
+
getTotalSupply: bindActionDecorators(client, getTotalSupply)
|
|
3092
|
+
};
|
|
3093
|
+
}
|
|
3094
|
+
|
|
3095
|
+
// node_modules/viem/_esm/clients/createPublicClient.js
|
|
3096
|
+
function createPublicClient(parameters) {
|
|
3097
|
+
const { key = "public", name = "Public Client" } = parameters;
|
|
3098
|
+
const client = createClient({
|
|
3099
|
+
...parameters,
|
|
3100
|
+
key,
|
|
3101
|
+
name,
|
|
3102
|
+
type: "publicClient"
|
|
3103
|
+
});
|
|
3104
|
+
return client.extend(publicActions);
|
|
3105
|
+
}
|
|
3106
|
+
|
|
3107
|
+
// node_modules/viem/_esm/actions/test/dropTransaction.js
|
|
3108
|
+
async function dropTransaction(client, { hash }) {
|
|
3109
|
+
await client.request({
|
|
3110
|
+
method: `${client.mode}_dropTransaction`,
|
|
3111
|
+
params: [hash]
|
|
3112
|
+
});
|
|
3113
|
+
}
|
|
3114
|
+
|
|
3115
|
+
// node_modules/viem/_esm/actions/test/dumpState.js
|
|
3116
|
+
async function dumpState(client) {
|
|
3117
|
+
return client.request({
|
|
3118
|
+
method: `${client.mode}_dumpState`
|
|
3119
|
+
});
|
|
3120
|
+
}
|
|
3121
|
+
|
|
3122
|
+
// node_modules/viem/_esm/actions/test/getAutomine.js
|
|
3123
|
+
async function getAutomine(client) {
|
|
3124
|
+
if (client.mode === "ganache")
|
|
3125
|
+
return await client.request({
|
|
3126
|
+
method: "eth_mining"
|
|
3127
|
+
});
|
|
3128
|
+
return await client.request({
|
|
3129
|
+
method: `${client.mode}_getAutomine`
|
|
3130
|
+
});
|
|
3131
|
+
}
|
|
3132
|
+
|
|
3133
|
+
// node_modules/viem/_esm/actions/test/getTxpoolContent.js
|
|
3134
|
+
async function getTxpoolContent(client) {
|
|
3135
|
+
return await client.request({
|
|
3136
|
+
method: "txpool_content"
|
|
3137
|
+
});
|
|
3138
|
+
}
|
|
3139
|
+
|
|
3140
|
+
// node_modules/viem/_esm/actions/test/getTxpoolStatus.js
|
|
3141
|
+
async function getTxpoolStatus(client) {
|
|
3142
|
+
const { pending, queued } = await client.request({
|
|
3143
|
+
method: "txpool_status"
|
|
3144
|
+
});
|
|
3145
|
+
return {
|
|
3146
|
+
pending: hexToNumber(pending),
|
|
3147
|
+
queued: hexToNumber(queued)
|
|
3148
|
+
};
|
|
3149
|
+
}
|
|
3150
|
+
|
|
3151
|
+
// node_modules/viem/_esm/actions/test/impersonateAccount.js
|
|
3152
|
+
async function impersonateAccount(client, { address }) {
|
|
3153
|
+
await client.request({
|
|
3154
|
+
method: `${client.mode}_impersonateAccount`,
|
|
3155
|
+
params: [address]
|
|
3156
|
+
});
|
|
3157
|
+
}
|
|
3158
|
+
|
|
3159
|
+
// node_modules/viem/_esm/actions/test/increaseTime.js
|
|
3160
|
+
async function increaseTime(client, { seconds }) {
|
|
3161
|
+
return await client.request({
|
|
3162
|
+
method: "evm_increaseTime",
|
|
3163
|
+
params: [numberToHex(seconds)]
|
|
3164
|
+
});
|
|
3165
|
+
}
|
|
3166
|
+
|
|
3167
|
+
// node_modules/viem/_esm/actions/test/inspectTxpool.js
|
|
3168
|
+
async function inspectTxpool(client) {
|
|
3169
|
+
return await client.request({
|
|
3170
|
+
method: "txpool_inspect"
|
|
3171
|
+
});
|
|
3172
|
+
}
|
|
3173
|
+
|
|
3174
|
+
// node_modules/viem/_esm/actions/test/loadState.js
|
|
3175
|
+
async function loadState(client, { state }) {
|
|
3176
|
+
await client.request({
|
|
3177
|
+
method: `${client.mode}_loadState`,
|
|
3178
|
+
params: [state]
|
|
3179
|
+
});
|
|
3180
|
+
}
|
|
3181
|
+
|
|
3182
|
+
// node_modules/viem/_esm/actions/test/mine.js
|
|
3183
|
+
async function mine(client, { blocks, interval }) {
|
|
3184
|
+
if (client.mode === "ganache")
|
|
3185
|
+
await client.request({
|
|
3186
|
+
method: "evm_mine",
|
|
3187
|
+
params: [{ blocks: numberToHex(blocks) }]
|
|
3188
|
+
});
|
|
3189
|
+
else
|
|
3190
|
+
await client.request({
|
|
3191
|
+
method: `${client.mode}_mine`,
|
|
3192
|
+
params: [numberToHex(blocks), numberToHex(interval || 0)]
|
|
3193
|
+
});
|
|
3194
|
+
}
|
|
3195
|
+
|
|
3196
|
+
// node_modules/viem/_esm/actions/test/removeBlockTimestampInterval.js
|
|
3197
|
+
async function removeBlockTimestampInterval(client) {
|
|
3198
|
+
await client.request({
|
|
3199
|
+
method: `${client.mode}_removeBlockTimestampInterval`
|
|
3200
|
+
});
|
|
3201
|
+
}
|
|
3202
|
+
|
|
3203
|
+
// node_modules/viem/_esm/actions/test/reset.js
|
|
3204
|
+
async function reset(client, { blockNumber, jsonRpcUrl } = {}) {
|
|
3205
|
+
await client.request({
|
|
3206
|
+
method: `${client.mode}_reset`,
|
|
3207
|
+
params: [{ forking: { blockNumber: Number(blockNumber), jsonRpcUrl } }]
|
|
3208
|
+
});
|
|
3209
|
+
}
|
|
3210
|
+
|
|
3211
|
+
// node_modules/viem/_esm/actions/test/revert.js
|
|
3212
|
+
async function revert(client, { id }) {
|
|
3213
|
+
await client.request({
|
|
3214
|
+
method: "evm_revert",
|
|
3215
|
+
params: [id]
|
|
3216
|
+
});
|
|
3217
|
+
}
|
|
3218
|
+
|
|
3219
|
+
// node_modules/viem/_esm/actions/test/sendUnsignedTransaction.js
|
|
3220
|
+
async function sendUnsignedTransaction(client, args) {
|
|
3221
|
+
const { accessList, data, from: from4, gas, gasPrice, maxFeePerGas, maxPriorityFeePerGas, nonce, to, value, ...rest } = args;
|
|
3222
|
+
const chainFormat = client.chain?.formatters?.transactionRequest?.format;
|
|
3223
|
+
const format = chainFormat || formatTransactionRequest;
|
|
3224
|
+
const request = format({
|
|
3225
|
+
// Pick out extra data that might exist on the chain's transaction request type.
|
|
3226
|
+
...extract(rest, { format: chainFormat }),
|
|
3227
|
+
accessList,
|
|
3228
|
+
data,
|
|
3229
|
+
from: from4,
|
|
3230
|
+
gas,
|
|
3231
|
+
gasPrice,
|
|
3232
|
+
maxFeePerGas,
|
|
3233
|
+
maxPriorityFeePerGas,
|
|
3234
|
+
nonce,
|
|
3235
|
+
to,
|
|
3236
|
+
value
|
|
3237
|
+
}, "sendUnsignedTransaction");
|
|
3238
|
+
const hash = await client.request({
|
|
3239
|
+
method: "eth_sendUnsignedTransaction",
|
|
3240
|
+
params: [request]
|
|
3241
|
+
});
|
|
3242
|
+
return hash;
|
|
3243
|
+
}
|
|
3244
|
+
|
|
3245
|
+
// node_modules/viem/_esm/actions/test/setAutomine.js
|
|
3246
|
+
async function setAutomine(client, enabled) {
|
|
3247
|
+
if (client.mode === "ganache") {
|
|
3248
|
+
if (enabled)
|
|
3249
|
+
await client.request({ method: "miner_start" });
|
|
3250
|
+
else
|
|
3251
|
+
await client.request({ method: "miner_stop" });
|
|
3252
|
+
} else
|
|
3253
|
+
await client.request({
|
|
3254
|
+
method: "evm_setAutomine",
|
|
3255
|
+
params: [enabled]
|
|
3256
|
+
});
|
|
3257
|
+
}
|
|
3258
|
+
|
|
3259
|
+
// node_modules/viem/_esm/actions/test/setBalance.js
|
|
3260
|
+
async function setBalance(client, { address, value }) {
|
|
3261
|
+
if (client.mode === "ganache")
|
|
3262
|
+
await client.request({
|
|
3263
|
+
method: "evm_setAccountBalance",
|
|
3264
|
+
params: [address, numberToHex(value)]
|
|
3265
|
+
});
|
|
3266
|
+
else
|
|
3267
|
+
await client.request({
|
|
3268
|
+
method: `${client.mode}_setBalance`,
|
|
3269
|
+
params: [address, numberToHex(value)]
|
|
3270
|
+
});
|
|
3271
|
+
}
|
|
3272
|
+
|
|
3273
|
+
// node_modules/viem/_esm/actions/test/setBlockGasLimit.js
|
|
3274
|
+
async function setBlockGasLimit(client, { gasLimit }) {
|
|
3275
|
+
await client.request({
|
|
3276
|
+
method: "evm_setBlockGasLimit",
|
|
3277
|
+
params: [numberToHex(gasLimit)]
|
|
3278
|
+
});
|
|
3279
|
+
}
|
|
3280
|
+
|
|
3281
|
+
// node_modules/viem/_esm/actions/test/setBlockTimestampInterval.js
|
|
3282
|
+
async function setBlockTimestampInterval(client, { interval }) {
|
|
3283
|
+
const interval_ = (() => {
|
|
3284
|
+
if (client.mode === "hardhat")
|
|
3285
|
+
return interval * 1e3;
|
|
3286
|
+
return interval;
|
|
3287
|
+
})();
|
|
3288
|
+
await client.request({
|
|
3289
|
+
method: `${client.mode}_setBlockTimestampInterval`,
|
|
3290
|
+
params: [interval_]
|
|
3291
|
+
});
|
|
3292
|
+
}
|
|
3293
|
+
|
|
3294
|
+
// node_modules/viem/_esm/actions/test/setCode.js
|
|
3295
|
+
async function setCode(client, { address, bytecode }) {
|
|
3296
|
+
if (client.mode === "ganache")
|
|
3297
|
+
await client.request({
|
|
3298
|
+
method: "evm_setAccountCode",
|
|
3299
|
+
params: [address, bytecode]
|
|
3300
|
+
});
|
|
3301
|
+
else
|
|
3302
|
+
await client.request({
|
|
3303
|
+
method: `${client.mode}_setCode`,
|
|
3304
|
+
params: [address, bytecode]
|
|
3305
|
+
});
|
|
3306
|
+
}
|
|
3307
|
+
|
|
3308
|
+
// node_modules/viem/_esm/actions/test/setCoinbase.js
|
|
3309
|
+
async function setCoinbase(client, { address }) {
|
|
3310
|
+
await client.request({
|
|
3311
|
+
method: `${client.mode}_setCoinbase`,
|
|
3312
|
+
params: [address]
|
|
3313
|
+
});
|
|
3314
|
+
}
|
|
3315
|
+
|
|
3316
|
+
// node_modules/viem/_esm/actions/test/setIntervalMining.js
|
|
3317
|
+
async function setIntervalMining(client, { interval }) {
|
|
3318
|
+
const interval_ = (() => {
|
|
3319
|
+
if (client.mode === "hardhat")
|
|
3320
|
+
return interval * 1e3;
|
|
3321
|
+
return interval;
|
|
3322
|
+
})();
|
|
3323
|
+
await client.request({
|
|
3324
|
+
method: "evm_setIntervalMining",
|
|
3325
|
+
params: [interval_]
|
|
3326
|
+
});
|
|
3327
|
+
}
|
|
3328
|
+
|
|
3329
|
+
// node_modules/viem/_esm/actions/test/setLoggingEnabled.js
|
|
3330
|
+
async function setLoggingEnabled(client, enabled) {
|
|
3331
|
+
await client.request({
|
|
3332
|
+
method: `${client.mode}_setLoggingEnabled`,
|
|
3333
|
+
params: [enabled]
|
|
3334
|
+
});
|
|
3335
|
+
}
|
|
3336
|
+
|
|
3337
|
+
// node_modules/viem/_esm/actions/test/setMinGasPrice.js
|
|
3338
|
+
async function setMinGasPrice(client, { gasPrice }) {
|
|
3339
|
+
await client.request({
|
|
3340
|
+
method: `${client.mode}_setMinGasPrice`,
|
|
3341
|
+
params: [numberToHex(gasPrice)]
|
|
3342
|
+
});
|
|
3343
|
+
}
|
|
3344
|
+
|
|
3345
|
+
// node_modules/viem/_esm/actions/test/setNextBlockBaseFeePerGas.js
|
|
3346
|
+
async function setNextBlockBaseFeePerGas(client, { baseFeePerGas }) {
|
|
3347
|
+
await client.request({
|
|
3348
|
+
method: `${client.mode}_setNextBlockBaseFeePerGas`,
|
|
3349
|
+
params: [numberToHex(baseFeePerGas)]
|
|
3350
|
+
});
|
|
3351
|
+
}
|
|
3352
|
+
|
|
3353
|
+
// node_modules/viem/_esm/actions/test/setNextBlockTimestamp.js
|
|
3354
|
+
async function setNextBlockTimestamp(client, { timestamp }) {
|
|
3355
|
+
await client.request({
|
|
3356
|
+
method: "evm_setNextBlockTimestamp",
|
|
3357
|
+
params: [numberToHex(timestamp)]
|
|
3358
|
+
});
|
|
3359
|
+
}
|
|
3360
|
+
|
|
3361
|
+
// node_modules/viem/_esm/actions/test/setNonce.js
|
|
3362
|
+
async function setNonce(client, { address, nonce }) {
|
|
3363
|
+
await client.request({
|
|
3364
|
+
method: `${client.mode}_setNonce`,
|
|
3365
|
+
params: [address, numberToHex(nonce)]
|
|
3366
|
+
});
|
|
3367
|
+
}
|
|
3368
|
+
|
|
3369
|
+
// node_modules/viem/_esm/actions/test/setRpcUrl.js
|
|
3370
|
+
async function setRpcUrl(client, jsonRpcUrl) {
|
|
3371
|
+
await client.request({
|
|
3372
|
+
method: `${client.mode}_setRpcUrl`,
|
|
3373
|
+
params: [jsonRpcUrl]
|
|
3374
|
+
});
|
|
3375
|
+
}
|
|
3376
|
+
|
|
3377
|
+
// node_modules/viem/_esm/actions/test/setStorageAt.js
|
|
3378
|
+
async function setStorageAt(client, { address, index: index2, value }) {
|
|
3379
|
+
await client.request({
|
|
3380
|
+
method: `${client.mode}_setStorageAt`,
|
|
3381
|
+
params: [
|
|
3382
|
+
address,
|
|
3383
|
+
typeof index2 === "number" ? numberToHex(index2) : index2,
|
|
3384
|
+
value
|
|
3385
|
+
]
|
|
3386
|
+
});
|
|
3387
|
+
}
|
|
3388
|
+
|
|
3389
|
+
// node_modules/viem/_esm/actions/test/snapshot.js
|
|
3390
|
+
async function snapshot(client) {
|
|
3391
|
+
return await client.request({
|
|
3392
|
+
method: "evm_snapshot"
|
|
3393
|
+
});
|
|
3394
|
+
}
|
|
3395
|
+
|
|
3396
|
+
// node_modules/viem/_esm/actions/test/stopImpersonatingAccount.js
|
|
3397
|
+
async function stopImpersonatingAccount(client, { address }) {
|
|
3398
|
+
await client.request({
|
|
3399
|
+
method: `${client.mode}_stopImpersonatingAccount`,
|
|
3400
|
+
params: [address]
|
|
3401
|
+
});
|
|
3402
|
+
}
|
|
3403
|
+
|
|
3404
|
+
// node_modules/viem/_esm/clients/decorators/test.js
|
|
3405
|
+
function testActions({ mode }) {
|
|
3406
|
+
return (client_) => {
|
|
3407
|
+
const client = client_.extend(() => ({
|
|
3408
|
+
mode
|
|
3409
|
+
}));
|
|
3410
|
+
return {
|
|
3411
|
+
dropTransaction: (args) => dropTransaction(client, args),
|
|
3412
|
+
dumpState: () => dumpState(client),
|
|
3413
|
+
getAutomine: () => getAutomine(client),
|
|
3414
|
+
getTxpoolContent: () => getTxpoolContent(client),
|
|
3415
|
+
getTxpoolStatus: () => getTxpoolStatus(client),
|
|
3416
|
+
impersonateAccount: (args) => impersonateAccount(client, args),
|
|
3417
|
+
increaseTime: (args) => increaseTime(client, args),
|
|
3418
|
+
inspectTxpool: () => inspectTxpool(client),
|
|
3419
|
+
loadState: (args) => loadState(client, args),
|
|
3420
|
+
mine: (args) => mine(client, args),
|
|
3421
|
+
removeBlockTimestampInterval: () => removeBlockTimestampInterval(client),
|
|
3422
|
+
reset: (args) => reset(client, args),
|
|
3423
|
+
revert: (args) => revert(client, args),
|
|
3424
|
+
sendUnsignedTransaction: (args) => sendUnsignedTransaction(client, args),
|
|
3425
|
+
setAutomine: (args) => setAutomine(client, args),
|
|
3426
|
+
setBalance: (args) => setBalance(client, args),
|
|
3427
|
+
setBlockGasLimit: (args) => setBlockGasLimit(client, args),
|
|
3428
|
+
setBlockTimestampInterval: (args) => setBlockTimestampInterval(client, args),
|
|
3429
|
+
setCode: (args) => setCode(client, args),
|
|
3430
|
+
setCoinbase: (args) => setCoinbase(client, args),
|
|
3431
|
+
setIntervalMining: (args) => setIntervalMining(client, args),
|
|
3432
|
+
setLoggingEnabled: (args) => setLoggingEnabled(client, args),
|
|
3433
|
+
setMinGasPrice: (args) => setMinGasPrice(client, args),
|
|
3434
|
+
setNextBlockBaseFeePerGas: (args) => setNextBlockBaseFeePerGas(client, args),
|
|
3435
|
+
setNextBlockTimestamp: (args) => setNextBlockTimestamp(client, args),
|
|
3436
|
+
setNonce: (args) => setNonce(client, args),
|
|
3437
|
+
setRpcUrl: (args) => setRpcUrl(client, args),
|
|
3438
|
+
setStorageAt: (args) => setStorageAt(client, args),
|
|
3439
|
+
snapshot: () => snapshot(client),
|
|
3440
|
+
stopImpersonatingAccount: (args) => stopImpersonatingAccount(client, args)
|
|
3441
|
+
};
|
|
3442
|
+
};
|
|
3443
|
+
}
|
|
3444
|
+
|
|
3445
|
+
// node_modules/viem/_esm/clients/createTestClient.js
|
|
3446
|
+
function createTestClient(parameters) {
|
|
3447
|
+
const { key = "test", name = "Test Client", mode } = parameters;
|
|
3448
|
+
const client = createClient({
|
|
3449
|
+
...parameters,
|
|
3450
|
+
key,
|
|
3451
|
+
name,
|
|
3452
|
+
type: "testClient"
|
|
3453
|
+
});
|
|
3454
|
+
return client.extend((config) => ({
|
|
3455
|
+
mode,
|
|
3456
|
+
...testActions({ mode })(config)
|
|
3457
|
+
}));
|
|
3458
|
+
}
|
|
3459
|
+
|
|
3460
|
+
// node_modules/viem/_esm/actions/wallet/addChain.js
|
|
3461
|
+
async function addChain(client, { chain }) {
|
|
3462
|
+
const { id, name, nativeCurrency, rpcUrls, blockExplorers } = chain;
|
|
3463
|
+
await client.request({
|
|
3464
|
+
method: "wallet_addEthereumChain",
|
|
3465
|
+
params: [
|
|
3466
|
+
{
|
|
3467
|
+
chainId: numberToHex(id),
|
|
3468
|
+
chainName: name,
|
|
3469
|
+
nativeCurrency,
|
|
3470
|
+
rpcUrls: rpcUrls.default.http,
|
|
3471
|
+
blockExplorerUrls: blockExplorers ? Object.values(blockExplorers).map(({ url }) => url) : void 0
|
|
3472
|
+
}
|
|
3473
|
+
]
|
|
3474
|
+
}, { dedupe: true, retryCount: 0 });
|
|
3475
|
+
}
|
|
3476
|
+
|
|
3477
|
+
// node_modules/viem/_esm/actions/wallet/deployContract.js
|
|
3478
|
+
function deployContract(walletClient, parameters) {
|
|
3479
|
+
const { abi: abi2, args, bytecode, ...request } = parameters;
|
|
3480
|
+
const calldata = encodeDeployData({ abi: abi2, args, bytecode });
|
|
3481
|
+
return sendTransaction(walletClient, {
|
|
3482
|
+
...request,
|
|
3483
|
+
...request.authorizationList ? { to: null } : {},
|
|
3484
|
+
data: calldata
|
|
3485
|
+
});
|
|
3486
|
+
}
|
|
3487
|
+
|
|
3488
|
+
// node_modules/viem/_esm/actions/wallet/getAddresses.js
|
|
3489
|
+
async function getAddresses(client) {
|
|
3490
|
+
if (client.account?.type === "local")
|
|
3491
|
+
return [client.account.address];
|
|
3492
|
+
const addresses = await client.request({ method: "eth_accounts" }, { dedupe: true });
|
|
3493
|
+
return addresses.map((address) => checksumAddress(address));
|
|
3494
|
+
}
|
|
3495
|
+
|
|
3496
|
+
// node_modules/viem/_esm/actions/wallet/getCapabilities.js
|
|
3497
|
+
async function getCapabilities(client, parameters = {}) {
|
|
3498
|
+
const { account = client.account, chainId } = parameters;
|
|
3499
|
+
const account_ = account ? parseAccount(account) : void 0;
|
|
3500
|
+
const params = chainId ? [account_?.address, [numberToHex(chainId)]] : [account_?.address];
|
|
3501
|
+
const capabilities_raw = await client.request({
|
|
3502
|
+
method: "wallet_getCapabilities",
|
|
3503
|
+
params
|
|
3504
|
+
});
|
|
3505
|
+
const capabilities = {};
|
|
3506
|
+
for (const [chainId2, capabilities_] of Object.entries(capabilities_raw)) {
|
|
3507
|
+
capabilities[Number(chainId2)] = {};
|
|
3508
|
+
for (let [key, value] of Object.entries(capabilities_)) {
|
|
3509
|
+
if (key === "addSubAccount")
|
|
3510
|
+
key = "unstable_addSubAccount";
|
|
3511
|
+
capabilities[Number(chainId2)][key] = value;
|
|
3512
|
+
}
|
|
3513
|
+
}
|
|
3514
|
+
return typeof chainId === "number" ? capabilities[chainId] : capabilities;
|
|
3515
|
+
}
|
|
3516
|
+
|
|
3517
|
+
// node_modules/viem/_esm/actions/wallet/getPermissions.js
|
|
3518
|
+
async function getPermissions(client) {
|
|
3519
|
+
const permissions = await client.request({ method: "wallet_getPermissions" }, { dedupe: true });
|
|
3520
|
+
return permissions;
|
|
3521
|
+
}
|
|
3522
|
+
|
|
3523
|
+
// node_modules/viem/_esm/actions/wallet/prepareAuthorization.js
|
|
3524
|
+
async function prepareAuthorization(client, parameters) {
|
|
3525
|
+
const { account: account_ = client.account, chainId, nonce } = parameters;
|
|
3526
|
+
if (!account_)
|
|
3527
|
+
throw new AccountNotFoundError({
|
|
3528
|
+
docsPath: "/docs/eip7702/prepareAuthorization"
|
|
3529
|
+
});
|
|
3530
|
+
const account = parseAccount(account_);
|
|
3531
|
+
const executor = (() => {
|
|
3532
|
+
if (!parameters.executor)
|
|
3533
|
+
return void 0;
|
|
3534
|
+
if (parameters.executor === "self")
|
|
3535
|
+
return parameters.executor;
|
|
3536
|
+
return parseAccount(parameters.executor);
|
|
3537
|
+
})();
|
|
3538
|
+
const authorization = {
|
|
3539
|
+
address: parameters.contractAddress ?? parameters.address,
|
|
3540
|
+
chainId,
|
|
3541
|
+
nonce
|
|
3542
|
+
};
|
|
3543
|
+
if (typeof authorization.chainId === "undefined")
|
|
3544
|
+
authorization.chainId = client.chain?.id ?? await getAction(client, getChainId, "getChainId")({});
|
|
3545
|
+
if (typeof authorization.nonce === "undefined") {
|
|
3546
|
+
authorization.nonce = await getAction(client, getTransactionCount, "getTransactionCount")({
|
|
3547
|
+
address: account.address,
|
|
3548
|
+
blockTag: "pending"
|
|
3549
|
+
});
|
|
3550
|
+
if (executor === "self" || executor?.address && isAddressEqual(executor.address, account.address))
|
|
3551
|
+
authorization.nonce += 1;
|
|
3552
|
+
}
|
|
3553
|
+
return authorization;
|
|
3554
|
+
}
|
|
3555
|
+
|
|
3556
|
+
// node_modules/viem/_esm/actions/wallet/requestAddresses.js
|
|
3557
|
+
async function requestAddresses(client) {
|
|
3558
|
+
const addresses = await client.request({ method: "eth_requestAccounts" }, { dedupe: true, retryCount: 0 });
|
|
3559
|
+
return addresses.map((address) => getAddress(address));
|
|
3560
|
+
}
|
|
3561
|
+
|
|
3562
|
+
// node_modules/viem/_esm/actions/wallet/requestPermissions.js
|
|
3563
|
+
async function requestPermissions(client, permissions) {
|
|
3564
|
+
return client.request({
|
|
3565
|
+
method: "wallet_requestPermissions",
|
|
3566
|
+
params: [permissions]
|
|
3567
|
+
}, { retryCount: 0 });
|
|
3568
|
+
}
|
|
3569
|
+
|
|
3570
|
+
// node_modules/viem/_esm/actions/wallet/sendCallsSync.js
|
|
3571
|
+
async function sendCallsSync(client, parameters) {
|
|
3572
|
+
const { chain = client.chain } = parameters;
|
|
3573
|
+
const timeout = parameters.timeout ?? Math.max((chain?.blockTime ?? 0) * 3, 5e3);
|
|
3574
|
+
const result = await getAction(client, sendCalls, "sendCalls")(parameters);
|
|
3575
|
+
const status = await getAction(client, waitForCallsStatus, "waitForCallsStatus")({
|
|
3576
|
+
...parameters,
|
|
3577
|
+
id: result.id,
|
|
3578
|
+
timeout
|
|
3579
|
+
});
|
|
3580
|
+
return status;
|
|
3581
|
+
}
|
|
3582
|
+
|
|
3583
|
+
// node_modules/viem/_esm/actions/wallet/showCallsStatus.js
|
|
3584
|
+
async function showCallsStatus(client, parameters) {
|
|
3585
|
+
const { id } = parameters;
|
|
3586
|
+
await client.request({
|
|
3587
|
+
method: "wallet_showCallsStatus",
|
|
3588
|
+
params: [id]
|
|
3589
|
+
});
|
|
3590
|
+
return;
|
|
3591
|
+
}
|
|
3592
|
+
|
|
3593
|
+
// node_modules/viem/_esm/actions/wallet/signAuthorization.js
|
|
3594
|
+
async function signAuthorization(client, parameters) {
|
|
3595
|
+
const { account: account_ = client.account } = parameters;
|
|
3596
|
+
if (!account_)
|
|
3597
|
+
throw new AccountNotFoundError({
|
|
3598
|
+
docsPath: "/docs/eip7702/signAuthorization"
|
|
3599
|
+
});
|
|
3600
|
+
const account = parseAccount(account_);
|
|
3601
|
+
if (!account.signAuthorization)
|
|
3602
|
+
throw new AccountTypeNotSupportedError({
|
|
3603
|
+
docsPath: "/docs/eip7702/signAuthorization",
|
|
3604
|
+
metaMessages: [
|
|
3605
|
+
"The `signAuthorization` Action does not support JSON-RPC Accounts."
|
|
3606
|
+
],
|
|
3607
|
+
type: account.type
|
|
3608
|
+
});
|
|
3609
|
+
const authorization = await prepareAuthorization(client, parameters);
|
|
3610
|
+
return account.signAuthorization(authorization);
|
|
3611
|
+
}
|
|
3612
|
+
|
|
3613
|
+
// node_modules/viem/_esm/actions/wallet/signMessage.js
|
|
3614
|
+
async function signMessage(client, { account: account_ = client.account, message }) {
|
|
3615
|
+
if (!account_)
|
|
3616
|
+
throw new AccountNotFoundError({
|
|
3617
|
+
docsPath: "/docs/actions/wallet/signMessage"
|
|
3618
|
+
});
|
|
3619
|
+
const account = parseAccount(account_);
|
|
3620
|
+
if (account.signMessage)
|
|
3621
|
+
return account.signMessage({ message });
|
|
3622
|
+
const message_ = (() => {
|
|
3623
|
+
if (typeof message === "string")
|
|
3624
|
+
return stringToHex(message);
|
|
3625
|
+
if (message.raw instanceof Uint8Array)
|
|
3626
|
+
return toHex(message.raw);
|
|
3627
|
+
return message.raw;
|
|
3628
|
+
})();
|
|
3629
|
+
return client.request({
|
|
3630
|
+
method: "personal_sign",
|
|
3631
|
+
params: [message_, account.address]
|
|
3632
|
+
}, { retryCount: 0 });
|
|
3633
|
+
}
|
|
3634
|
+
|
|
3635
|
+
// node_modules/viem/_esm/actions/wallet/signTransaction.js
|
|
3636
|
+
async function signTransaction(client, parameters) {
|
|
3637
|
+
const { account: account_ = client.account, chain = client.chain, ...transaction } = parameters;
|
|
3638
|
+
if (!account_)
|
|
3639
|
+
throw new AccountNotFoundError({
|
|
3640
|
+
docsPath: "/docs/actions/wallet/signTransaction"
|
|
3641
|
+
});
|
|
3642
|
+
const account = parseAccount(account_);
|
|
3643
|
+
assertRequest({
|
|
3644
|
+
account,
|
|
3645
|
+
...parameters
|
|
3646
|
+
});
|
|
3647
|
+
const chainId = await getAction(client, getChainId, "getChainId")({});
|
|
3648
|
+
if (chain !== null)
|
|
3649
|
+
assertCurrentChain({
|
|
3650
|
+
currentChainId: chainId,
|
|
3651
|
+
chain
|
|
3652
|
+
});
|
|
3653
|
+
const formatters = chain?.formatters || client.chain?.formatters;
|
|
3654
|
+
const format = formatters?.transactionRequest?.format || formatTransactionRequest;
|
|
3655
|
+
if (account.signTransaction)
|
|
3656
|
+
return account.signTransaction({
|
|
3657
|
+
...transaction,
|
|
3658
|
+
account,
|
|
3659
|
+
chainId
|
|
3660
|
+
}, { serializer: client.chain?.serializers?.transaction });
|
|
3661
|
+
return await client.request({
|
|
3662
|
+
method: "eth_signTransaction",
|
|
3663
|
+
params: [
|
|
3664
|
+
{
|
|
3665
|
+
...format({
|
|
3666
|
+
...transaction,
|
|
3667
|
+
account
|
|
3668
|
+
}, "signTransaction"),
|
|
3669
|
+
chainId: numberToHex(chainId),
|
|
3670
|
+
from: account.address
|
|
3671
|
+
}
|
|
3672
|
+
]
|
|
3673
|
+
}, { retryCount: 0 });
|
|
3674
|
+
}
|
|
3675
|
+
|
|
3676
|
+
// node_modules/viem/_esm/actions/wallet/signTypedData.js
|
|
3677
|
+
async function signTypedData(client, parameters) {
|
|
3678
|
+
const { account: account_ = client.account, domain, message, primaryType } = parameters;
|
|
3679
|
+
if (!account_)
|
|
3680
|
+
throw new AccountNotFoundError({
|
|
3681
|
+
docsPath: "/docs/actions/wallet/signTypedData"
|
|
3682
|
+
});
|
|
3683
|
+
const account = parseAccount(account_);
|
|
3684
|
+
const types = {
|
|
3685
|
+
EIP712Domain: getTypesForEIP712Domain({ domain }),
|
|
3686
|
+
...parameters.types
|
|
3687
|
+
};
|
|
3688
|
+
validateTypedData({ domain, message, primaryType, types });
|
|
3689
|
+
if (account.signTypedData)
|
|
3690
|
+
return account.signTypedData({ domain, message, primaryType, types });
|
|
3691
|
+
const typedData = serializeTypedData({ domain, message, primaryType, types });
|
|
3692
|
+
return client.request({
|
|
3693
|
+
method: "eth_signTypedData_v4",
|
|
3694
|
+
params: [account.address, typedData]
|
|
3695
|
+
}, { retryCount: 0 });
|
|
3696
|
+
}
|
|
3697
|
+
|
|
3698
|
+
// node_modules/viem/_esm/actions/wallet/switchChain.js
|
|
3699
|
+
async function switchChain(client, { id }) {
|
|
3700
|
+
await client.request({
|
|
3701
|
+
method: "wallet_switchEthereumChain",
|
|
3702
|
+
params: [
|
|
3703
|
+
{
|
|
3704
|
+
chainId: numberToHex(id)
|
|
3705
|
+
}
|
|
3706
|
+
]
|
|
3707
|
+
}, { retryCount: 0 });
|
|
3708
|
+
}
|
|
3709
|
+
|
|
3710
|
+
// node_modules/viem/_esm/actions/wallet/watchAsset.js
|
|
3711
|
+
async function watchAsset(client, params) {
|
|
3712
|
+
const added = await client.request({
|
|
3713
|
+
method: "wallet_watchAsset",
|
|
3714
|
+
params
|
|
3715
|
+
}, { retryCount: 0 });
|
|
3716
|
+
return added;
|
|
3717
|
+
}
|
|
3718
|
+
|
|
3719
|
+
// node_modules/viem/_esm/clients/decorators/wallet.js
|
|
3720
|
+
function walletActions(client) {
|
|
3721
|
+
return {
|
|
3722
|
+
addChain: (args) => addChain(client, args),
|
|
3723
|
+
deployContract: (args) => deployContract(client, args),
|
|
3724
|
+
fillTransaction: (args) => fillTransaction(client, args),
|
|
3725
|
+
getAddresses: () => getAddresses(client),
|
|
3726
|
+
getCallsStatus: (args) => getCallsStatus(client, args),
|
|
3727
|
+
getCapabilities: (args) => getCapabilities(client, args),
|
|
3728
|
+
getChainId: () => getChainId(client),
|
|
3729
|
+
getPermissions: () => getPermissions(client),
|
|
3730
|
+
prepareAuthorization: (args) => prepareAuthorization(client, args),
|
|
3731
|
+
prepareTransactionRequest: (args) => prepareTransactionRequest(client, args),
|
|
3732
|
+
requestAddresses: () => requestAddresses(client),
|
|
3733
|
+
requestPermissions: (args) => requestPermissions(client, args),
|
|
3734
|
+
sendCalls: (args) => sendCalls(client, args),
|
|
3735
|
+
sendCallsSync: (args) => sendCallsSync(client, args),
|
|
3736
|
+
sendRawTransaction: (args) => sendRawTransaction(client, args),
|
|
3737
|
+
sendRawTransactionSync: (args) => sendRawTransactionSync(client, args),
|
|
3738
|
+
sendTransaction: (args) => sendTransaction(client, args),
|
|
3739
|
+
sendTransactionSync: (args) => sendTransactionSync(client, args),
|
|
3740
|
+
showCallsStatus: (args) => showCallsStatus(client, args),
|
|
3741
|
+
signAuthorization: (args) => signAuthorization(client, args),
|
|
3742
|
+
signMessage: (args) => signMessage(client, args),
|
|
3743
|
+
signTransaction: (args) => signTransaction(client, args),
|
|
3744
|
+
signTypedData: (args) => signTypedData(client, args),
|
|
3745
|
+
switchChain: (args) => switchChain(client, args),
|
|
3746
|
+
waitForCallsStatus: (args) => waitForCallsStatus(client, args),
|
|
3747
|
+
watchAsset: (args) => watchAsset(client, args),
|
|
3748
|
+
writeContract: (args) => writeContract(client, args),
|
|
3749
|
+
writeContractSync: (args) => writeContractSync(client, args),
|
|
3750
|
+
token: {
|
|
3751
|
+
approve: bindActionDecorators(client, approve),
|
|
3752
|
+
approveSync: bindActionDecorators(client, approveSync),
|
|
3753
|
+
transfer: bindActionDecorators(client, transfer),
|
|
3754
|
+
transferSync: bindActionDecorators(client, transferSync)
|
|
3755
|
+
}
|
|
3756
|
+
};
|
|
3757
|
+
}
|
|
3758
|
+
|
|
3759
|
+
// node_modules/viem/_esm/clients/createWalletClient.js
|
|
3760
|
+
function createWalletClient(parameters) {
|
|
3761
|
+
const { key = "wallet", name = "Wallet Client", transport } = parameters;
|
|
3762
|
+
const client = createClient({
|
|
3763
|
+
...parameters,
|
|
3764
|
+
key,
|
|
3765
|
+
name,
|
|
3766
|
+
transport,
|
|
3767
|
+
type: "walletClient"
|
|
3768
|
+
});
|
|
3769
|
+
return client.extend(walletActions);
|
|
3770
|
+
}
|
|
3771
|
+
|
|
3772
|
+
// node_modules/viem/_esm/clients/transports/createTransport.js
|
|
3773
|
+
function createTransport({ key, methods, name, request, retryCount = 3, retryDelay = 150, timeout, type }, value) {
|
|
3774
|
+
const uid2 = uid();
|
|
3775
|
+
return {
|
|
3776
|
+
config: {
|
|
3777
|
+
key,
|
|
3778
|
+
methods,
|
|
3779
|
+
name,
|
|
3780
|
+
request,
|
|
3781
|
+
retryCount,
|
|
3782
|
+
retryDelay,
|
|
3783
|
+
timeout,
|
|
3784
|
+
type
|
|
3785
|
+
},
|
|
3786
|
+
request: buildRequest(request, { methods, retryCount, retryDelay, uid: uid2 }),
|
|
3787
|
+
value
|
|
3788
|
+
};
|
|
3789
|
+
}
|
|
3790
|
+
|
|
3791
|
+
// node_modules/viem/_esm/clients/transports/custom.js
|
|
3792
|
+
function custom(provider, config = {}) {
|
|
3793
|
+
const { key = "custom", methods, name = "Custom Provider", retryDelay } = config;
|
|
3794
|
+
return ({ retryCount: defaultRetryCount }) => createTransport({
|
|
3795
|
+
key,
|
|
3796
|
+
methods,
|
|
3797
|
+
name,
|
|
3798
|
+
request: provider.request.bind(provider),
|
|
3799
|
+
retryCount: config.retryCount ?? defaultRetryCount,
|
|
3800
|
+
retryDelay,
|
|
3801
|
+
type: "custom"
|
|
3802
|
+
});
|
|
3803
|
+
}
|
|
3804
|
+
|
|
3805
|
+
// node_modules/viem/_esm/clients/transports/fallback.js
|
|
3806
|
+
function fallback(transports_, config = {}) {
|
|
3807
|
+
const { key = "fallback", name = "Fallback", rank = false, shouldThrow: shouldThrow_ = shouldThrow, retryCount, retryDelay } = config;
|
|
3808
|
+
return (({ chain, pollingInterval = 4e3, timeout, ...rest }) => {
|
|
3809
|
+
let transports = transports_;
|
|
3810
|
+
let onResponse = () => {
|
|
3811
|
+
};
|
|
3812
|
+
const transport = createTransport({
|
|
3813
|
+
key,
|
|
3814
|
+
name,
|
|
3815
|
+
async request({ method, params }) {
|
|
3816
|
+
let includes;
|
|
3817
|
+
const fetch2 = async (i = 0) => {
|
|
3818
|
+
const transport2 = transports[i]({
|
|
3819
|
+
...rest,
|
|
3820
|
+
chain,
|
|
3821
|
+
retryCount: 0,
|
|
3822
|
+
timeout
|
|
3823
|
+
});
|
|
3824
|
+
try {
|
|
3825
|
+
const response = await transport2.request({
|
|
3826
|
+
method,
|
|
3827
|
+
params
|
|
3828
|
+
});
|
|
3829
|
+
onResponse({
|
|
3830
|
+
method,
|
|
3831
|
+
params,
|
|
3832
|
+
response,
|
|
3833
|
+
transport: transport2,
|
|
3834
|
+
status: "success"
|
|
3835
|
+
});
|
|
3836
|
+
return response;
|
|
3837
|
+
} catch (err) {
|
|
3838
|
+
onResponse({
|
|
3839
|
+
error: err,
|
|
3840
|
+
method,
|
|
3841
|
+
params,
|
|
3842
|
+
transport: transport2,
|
|
3843
|
+
status: "error"
|
|
3844
|
+
});
|
|
3845
|
+
if (shouldThrow_(err))
|
|
3846
|
+
throw err;
|
|
3847
|
+
if (i === transports.length - 1)
|
|
3848
|
+
throw err;
|
|
3849
|
+
includes ??= transports.slice(i + 1).some((transport3) => {
|
|
3850
|
+
const { include, exclude } = transport3({ chain }).config.methods || {};
|
|
3851
|
+
if (include)
|
|
3852
|
+
return include.includes(method);
|
|
3853
|
+
if (exclude)
|
|
3854
|
+
return !exclude.includes(method);
|
|
3855
|
+
return true;
|
|
3856
|
+
});
|
|
3857
|
+
if (!includes)
|
|
3858
|
+
throw err;
|
|
3859
|
+
return fetch2(i + 1);
|
|
3860
|
+
}
|
|
3861
|
+
};
|
|
3862
|
+
return fetch2();
|
|
3863
|
+
},
|
|
3864
|
+
retryCount,
|
|
3865
|
+
retryDelay,
|
|
3866
|
+
type: "fallback"
|
|
3867
|
+
}, {
|
|
3868
|
+
onResponse: (fn) => onResponse = fn,
|
|
3869
|
+
transports: transports.map((fn) => fn({ chain, retryCount: 0 }))
|
|
3870
|
+
});
|
|
3871
|
+
if (rank) {
|
|
3872
|
+
const rankOptions = typeof rank === "object" ? rank : {};
|
|
3873
|
+
rankTransports({
|
|
3874
|
+
chain,
|
|
3875
|
+
interval: rankOptions.interval ?? pollingInterval,
|
|
3876
|
+
onTransports: (transports_2) => transports = transports_2,
|
|
3877
|
+
ping: rankOptions.ping,
|
|
3878
|
+
sampleCount: rankOptions.sampleCount,
|
|
3879
|
+
timeout: rankOptions.timeout,
|
|
3880
|
+
transports,
|
|
3881
|
+
weights: rankOptions.weights
|
|
3882
|
+
});
|
|
3883
|
+
}
|
|
3884
|
+
return transport;
|
|
3885
|
+
});
|
|
3886
|
+
}
|
|
3887
|
+
function shouldThrow(error) {
|
|
3888
|
+
if ("code" in error && typeof error.code === "number") {
|
|
3889
|
+
if (error.code === TransactionRejectedRpcError.code || error.code === UserRejectedRequestError.code || error.code === WalletConnectSessionSettlementError.code || ExecutionRevertedError.nodeMessage.test(error.message) || error.code === 5e3)
|
|
3890
|
+
return true;
|
|
3891
|
+
}
|
|
3892
|
+
return false;
|
|
3893
|
+
}
|
|
3894
|
+
function rankTransports({ chain, interval = 4e3, onTransports, ping, sampleCount = 10, timeout = 1e3, transports, weights = {} }) {
|
|
3895
|
+
const { stability: stabilityWeight = 0.7, latency: latencyWeight = 0.3 } = weights;
|
|
3896
|
+
const samples = [];
|
|
3897
|
+
const rankTransports_ = async () => {
|
|
3898
|
+
const sample = await Promise.all(transports.map(async (transport) => {
|
|
3899
|
+
const transport_ = transport({ chain, retryCount: 0, timeout });
|
|
3900
|
+
const start = Date.now();
|
|
3901
|
+
let end;
|
|
3902
|
+
let success;
|
|
3903
|
+
try {
|
|
3904
|
+
await (ping ? ping({ transport: transport_ }) : transport_.request({ method: "net_listening" }));
|
|
3905
|
+
success = 1;
|
|
3906
|
+
} catch {
|
|
3907
|
+
success = 0;
|
|
3908
|
+
} finally {
|
|
3909
|
+
end = Date.now();
|
|
3910
|
+
}
|
|
3911
|
+
const latency = end - start;
|
|
3912
|
+
return { latency, success };
|
|
3913
|
+
}));
|
|
3914
|
+
samples.push(sample);
|
|
3915
|
+
if (samples.length > sampleCount)
|
|
3916
|
+
samples.shift();
|
|
3917
|
+
const maxLatency = Math.max(...samples.map((sample2) => Math.max(...sample2.map(({ latency }) => latency))));
|
|
3918
|
+
const scores = transports.map((_, i) => {
|
|
3919
|
+
const latencies = samples.map((sample2) => sample2[i].latency);
|
|
3920
|
+
const meanLatency = latencies.reduce((acc, latency) => acc + latency, 0) / latencies.length;
|
|
3921
|
+
const latencyScore = 1 - meanLatency / maxLatency;
|
|
3922
|
+
const successes = samples.map((sample2) => sample2[i].success);
|
|
3923
|
+
const stabilityScore = successes.reduce((acc, success) => acc + success, 0) / successes.length;
|
|
3924
|
+
if (stabilityScore === 0)
|
|
3925
|
+
return [0, i];
|
|
3926
|
+
return [
|
|
3927
|
+
latencyWeight * latencyScore + stabilityWeight * stabilityScore,
|
|
3928
|
+
i
|
|
3929
|
+
];
|
|
3930
|
+
}).sort((a, b) => b[0] - a[0]);
|
|
3931
|
+
onTransports(scores.map(([, i]) => transports[i]));
|
|
3932
|
+
await wait(interval);
|
|
3933
|
+
rankTransports_();
|
|
3934
|
+
};
|
|
3935
|
+
rankTransports_();
|
|
3936
|
+
}
|
|
3937
|
+
|
|
3938
|
+
// node_modules/viem/_esm/errors/transport.js
|
|
3939
|
+
var UrlRequiredError = class extends BaseError {
|
|
3940
|
+
constructor() {
|
|
3941
|
+
super("No URL was provided to the Transport. Please provide a valid RPC URL to the Transport.", {
|
|
3942
|
+
docsPath: "/docs/clients/intro",
|
|
3943
|
+
name: "UrlRequiredError"
|
|
3944
|
+
});
|
|
3945
|
+
}
|
|
3946
|
+
};
|
|
3947
|
+
|
|
3948
|
+
// node_modules/viem/_esm/clients/transports/http.js
|
|
3949
|
+
var signalId = 0;
|
|
3950
|
+
var signalIds = /* @__PURE__ */ new WeakMap();
|
|
3951
|
+
function getSignalId(signal) {
|
|
3952
|
+
if (!signal)
|
|
3953
|
+
return "default";
|
|
3954
|
+
const id = signalIds.get(signal);
|
|
3955
|
+
if (id !== void 0)
|
|
3956
|
+
return id;
|
|
3957
|
+
const nextId = signalId++;
|
|
3958
|
+
signalIds.set(signal, nextId);
|
|
3959
|
+
return nextId;
|
|
3960
|
+
}
|
|
3961
|
+
function http(url, config = {}) {
|
|
3962
|
+
const { batch, fetchFn, fetchOptions, key = "http", maxResponseBodySize, methods, name = "HTTP JSON-RPC", onFetchRequest, onFetchResponse, retryDelay, raw } = config;
|
|
3963
|
+
return ({ chain, retryCount: retryCount_, timeout: timeout_ }) => {
|
|
3964
|
+
const { batchSize = 1e3, wait: wait2 = 0 } = typeof batch === "object" ? batch : {};
|
|
3965
|
+
const retryCount = config.retryCount ?? retryCount_;
|
|
3966
|
+
const timeout = timeout_ ?? config.timeout ?? 1e4;
|
|
3967
|
+
const url_ = url || chain?.rpcUrls.default.http[0];
|
|
3968
|
+
if (!url_)
|
|
3969
|
+
throw new UrlRequiredError();
|
|
3970
|
+
const rpcClient = getHttpRpcClient(url_, {
|
|
3971
|
+
fetchFn,
|
|
3972
|
+
fetchOptions,
|
|
3973
|
+
maxResponseBodySize,
|
|
3974
|
+
onRequest: onFetchRequest,
|
|
3975
|
+
onResponse: onFetchResponse,
|
|
3976
|
+
timeout
|
|
3977
|
+
});
|
|
3978
|
+
return createTransport({
|
|
3979
|
+
key,
|
|
3980
|
+
methods,
|
|
3981
|
+
name,
|
|
3982
|
+
async request({ method, params }, options) {
|
|
3983
|
+
const body = { method, params };
|
|
3984
|
+
const fetchOptions2 = options?.signal ? { signal: options.signal } : void 0;
|
|
3985
|
+
const { schedule } = createBatchScheduler({
|
|
3986
|
+
id: `${url_}.${getSignalId(options?.signal)}`,
|
|
3987
|
+
wait: wait2,
|
|
3988
|
+
shouldSplitBatch(requests) {
|
|
3989
|
+
return requests.length > batchSize;
|
|
3990
|
+
},
|
|
3991
|
+
fn: (body2) => rpcClient.request({
|
|
3992
|
+
body: body2,
|
|
3993
|
+
fetchOptions: fetchOptions2
|
|
3994
|
+
}),
|
|
3995
|
+
sort: (a, b) => a.id - b.id
|
|
3996
|
+
});
|
|
3997
|
+
const fn = async (body2) => batch ? schedule(body2) : [
|
|
3998
|
+
await rpcClient.request({
|
|
3999
|
+
body: body2,
|
|
4000
|
+
fetchOptions: fetchOptions2
|
|
4001
|
+
})
|
|
4002
|
+
];
|
|
4003
|
+
const [{ error, result }] = await fn(body);
|
|
4004
|
+
if (raw)
|
|
4005
|
+
return { error, result };
|
|
4006
|
+
if (error)
|
|
4007
|
+
throw new RpcRequestError({
|
|
4008
|
+
body,
|
|
4009
|
+
error,
|
|
4010
|
+
url: url_
|
|
4011
|
+
});
|
|
4012
|
+
return result;
|
|
4013
|
+
},
|
|
4014
|
+
retryCount,
|
|
4015
|
+
retryDelay,
|
|
4016
|
+
timeout,
|
|
4017
|
+
type: "http"
|
|
4018
|
+
}, {
|
|
4019
|
+
fetchOptions,
|
|
4020
|
+
url: url_
|
|
4021
|
+
});
|
|
4022
|
+
};
|
|
4023
|
+
}
|
|
4024
|
+
|
|
4025
|
+
// node_modules/viem/_esm/clients/transports/webSocket.js
|
|
4026
|
+
function webSocket(url, config = {}) {
|
|
4027
|
+
const { keepAlive, key = "webSocket", methods, name = "WebSocket JSON-RPC", reconnect, retryDelay } = config;
|
|
4028
|
+
return ({ chain, retryCount: retryCount_, timeout: timeout_ }) => {
|
|
4029
|
+
const retryCount = config.retryCount ?? retryCount_;
|
|
4030
|
+
const timeout = timeout_ ?? config.timeout ?? 1e4;
|
|
4031
|
+
const url_ = url || chain?.rpcUrls.default.webSocket?.[0];
|
|
4032
|
+
const wsRpcClientOpts = { keepAlive, reconnect };
|
|
4033
|
+
if (!url_)
|
|
4034
|
+
throw new UrlRequiredError();
|
|
4035
|
+
return createTransport({
|
|
4036
|
+
key,
|
|
4037
|
+
methods,
|
|
4038
|
+
name,
|
|
4039
|
+
async request({ method, params }) {
|
|
4040
|
+
const body = { method, params };
|
|
4041
|
+
const rpcClient = await getWebSocketRpcClient(url_, wsRpcClientOpts);
|
|
4042
|
+
const { error, result } = await rpcClient.requestAsync({
|
|
4043
|
+
body,
|
|
4044
|
+
timeout
|
|
4045
|
+
});
|
|
4046
|
+
if (error)
|
|
4047
|
+
throw new RpcRequestError({
|
|
4048
|
+
body,
|
|
4049
|
+
error,
|
|
4050
|
+
url: url_
|
|
4051
|
+
});
|
|
4052
|
+
return result;
|
|
4053
|
+
},
|
|
4054
|
+
retryCount,
|
|
4055
|
+
retryDelay,
|
|
4056
|
+
timeout,
|
|
4057
|
+
type: "webSocket"
|
|
4058
|
+
}, {
|
|
4059
|
+
getSocket() {
|
|
4060
|
+
return getSocket(url_);
|
|
4061
|
+
},
|
|
4062
|
+
getRpcClient() {
|
|
4063
|
+
return getWebSocketRpcClient(url_, wsRpcClientOpts);
|
|
4064
|
+
},
|
|
4065
|
+
async subscribe({ params, onData, onError }) {
|
|
4066
|
+
const rpcClient = await getWebSocketRpcClient(url_, wsRpcClientOpts);
|
|
4067
|
+
const { result: subscriptionId } = await new Promise((resolve, reject) => rpcClient.request({
|
|
4068
|
+
body: {
|
|
4069
|
+
method: "eth_subscribe",
|
|
4070
|
+
params
|
|
4071
|
+
},
|
|
4072
|
+
onError(error) {
|
|
4073
|
+
reject(error);
|
|
4074
|
+
onError?.(error);
|
|
4075
|
+
return;
|
|
4076
|
+
},
|
|
4077
|
+
onResponse(response) {
|
|
4078
|
+
if (response.error) {
|
|
4079
|
+
reject(response.error);
|
|
4080
|
+
onError?.(response.error);
|
|
4081
|
+
return;
|
|
4082
|
+
}
|
|
4083
|
+
if (typeof response.id === "number") {
|
|
4084
|
+
resolve(response);
|
|
4085
|
+
return;
|
|
4086
|
+
}
|
|
4087
|
+
if (response.method !== "eth_subscription")
|
|
4088
|
+
return;
|
|
4089
|
+
onData(response.params);
|
|
4090
|
+
}
|
|
4091
|
+
}));
|
|
4092
|
+
return {
|
|
4093
|
+
subscriptionId,
|
|
4094
|
+
async unsubscribe() {
|
|
4095
|
+
return new Promise((resolve) => rpcClient.request({
|
|
4096
|
+
body: {
|
|
4097
|
+
method: "eth_unsubscribe",
|
|
4098
|
+
params: [subscriptionId]
|
|
4099
|
+
},
|
|
4100
|
+
onResponse: resolve
|
|
4101
|
+
}));
|
|
4102
|
+
}
|
|
4103
|
+
};
|
|
4104
|
+
}
|
|
4105
|
+
});
|
|
4106
|
+
};
|
|
4107
|
+
}
|
|
4108
|
+
|
|
4109
|
+
// node_modules/viem/_esm/constants/unit.js
|
|
4110
|
+
var etherUnits = {
|
|
4111
|
+
gwei: 9,
|
|
4112
|
+
wei: 18
|
|
4113
|
+
};
|
|
4114
|
+
var gweiUnits = {
|
|
4115
|
+
ether: -9,
|
|
4116
|
+
wei: 9
|
|
4117
|
+
};
|
|
4118
|
+
var weiUnits = {
|
|
4119
|
+
ether: -18,
|
|
4120
|
+
gwei: -9
|
|
4121
|
+
};
|
|
4122
|
+
|
|
4123
|
+
// node_modules/viem/_esm/errors/unit.js
|
|
4124
|
+
var InvalidDecimalNumberError = class extends BaseError {
|
|
4125
|
+
constructor({ value }) {
|
|
4126
|
+
super(`Number \`${value}\` is not a valid decimal number.`, {
|
|
4127
|
+
name: "InvalidDecimalNumberError"
|
|
4128
|
+
});
|
|
4129
|
+
}
|
|
4130
|
+
};
|
|
4131
|
+
|
|
4132
|
+
// node_modules/viem/_esm/types/eip1193.js
|
|
4133
|
+
var ProviderRpcError = class extends Error {
|
|
4134
|
+
constructor(code, message) {
|
|
4135
|
+
super(message);
|
|
4136
|
+
Object.defineProperty(this, "code", {
|
|
4137
|
+
enumerable: true,
|
|
4138
|
+
configurable: true,
|
|
4139
|
+
writable: true,
|
|
4140
|
+
value: void 0
|
|
4141
|
+
});
|
|
4142
|
+
Object.defineProperty(this, "details", {
|
|
4143
|
+
enumerable: true,
|
|
4144
|
+
configurable: true,
|
|
4145
|
+
writable: true,
|
|
4146
|
+
value: void 0
|
|
4147
|
+
});
|
|
4148
|
+
this.code = code;
|
|
4149
|
+
this.details = message;
|
|
4150
|
+
}
|
|
4151
|
+
};
|
|
4152
|
+
|
|
4153
|
+
// node_modules/viem/_esm/utils/abi/decodeDeployData.js
|
|
4154
|
+
var docsPath = "/docs/contract/decodeDeployData";
|
|
4155
|
+
function decodeDeployData(parameters) {
|
|
4156
|
+
const { abi: abi2, bytecode, data } = parameters;
|
|
4157
|
+
if (data === bytecode)
|
|
4158
|
+
return { bytecode };
|
|
4159
|
+
const description = abi2.find((x) => "type" in x && x.type === "constructor");
|
|
4160
|
+
if (!description)
|
|
4161
|
+
throw new AbiConstructorNotFoundError({ docsPath });
|
|
4162
|
+
if (!("inputs" in description))
|
|
4163
|
+
throw new AbiConstructorParamsNotFoundError({ docsPath });
|
|
4164
|
+
if (!description.inputs || description.inputs.length === 0)
|
|
4165
|
+
throw new AbiConstructorParamsNotFoundError({ docsPath });
|
|
4166
|
+
const args = decodeAbiParameters(description.inputs, `0x${data.replace(bytecode, "")}`);
|
|
4167
|
+
return { args, bytecode };
|
|
4168
|
+
}
|
|
4169
|
+
|
|
4170
|
+
// node_modules/viem/_esm/utils/blob/fromBlobs.js
|
|
4171
|
+
function fromBlobs(parameters) {
|
|
4172
|
+
const to = parameters.to ?? (typeof parameters.blobs[0] === "string" ? "hex" : "bytes");
|
|
4173
|
+
const blobs = typeof parameters.blobs[0] === "string" ? parameters.blobs.map((x) => hexToBytes(x)) : parameters.blobs;
|
|
4174
|
+
const length = blobs.reduce((length2, blob) => length2 + blob.length, 0);
|
|
4175
|
+
const data = createCursor(new Uint8Array(length));
|
|
4176
|
+
let active = true;
|
|
4177
|
+
for (const [index2, blob] of blobs.entries()) {
|
|
4178
|
+
const cursor = createCursor(blob);
|
|
4179
|
+
const isLastBlob = index2 === blobs.length - 1;
|
|
4180
|
+
while (active && cursor.position < blob.length) {
|
|
4181
|
+
cursor.incrementPosition(1);
|
|
4182
|
+
let consume = 31;
|
|
4183
|
+
if (blob.length - cursor.position < 31)
|
|
4184
|
+
consume = blob.length - cursor.position;
|
|
4185
|
+
for (const _ in Array.from({ length: consume })) {
|
|
4186
|
+
const byte = cursor.readByte();
|
|
4187
|
+
const isTerminator = isLastBlob && byte === 128 && !cursor.inspectBytes(cursor.remaining).includes(128);
|
|
4188
|
+
if (isTerminator) {
|
|
4189
|
+
active = false;
|
|
4190
|
+
break;
|
|
4191
|
+
}
|
|
4192
|
+
data.pushByte(byte);
|
|
4193
|
+
}
|
|
4194
|
+
}
|
|
4195
|
+
}
|
|
4196
|
+
const trimmedData = data.bytes.slice(0, data.position);
|
|
4197
|
+
return to === "hex" ? bytesToHex(trimmedData) : trimmedData;
|
|
4198
|
+
}
|
|
4199
|
+
|
|
4200
|
+
// node_modules/viem/_esm/utils/blob/sidecarsToVersionedHashes.js
|
|
4201
|
+
function sidecarsToVersionedHashes(parameters) {
|
|
4202
|
+
const { sidecars, version } = parameters;
|
|
4203
|
+
const to = parameters.to ?? (typeof sidecars[0].blob === "string" ? "hex" : "bytes");
|
|
4204
|
+
const hashes = [];
|
|
4205
|
+
for (const { commitment } of sidecars) {
|
|
4206
|
+
hashes.push(commitmentToVersionedHash({
|
|
4207
|
+
commitment,
|
|
4208
|
+
to,
|
|
4209
|
+
version
|
|
4210
|
+
}));
|
|
4211
|
+
}
|
|
4212
|
+
return hashes;
|
|
4213
|
+
}
|
|
4214
|
+
|
|
4215
|
+
// node_modules/viem/_esm/utils/ens/toCoinType.js
|
|
4216
|
+
var SLIP44_MSB = 2147483648;
|
|
4217
|
+
function toCoinType(chainId) {
|
|
4218
|
+
if (chainId === 1)
|
|
4219
|
+
return 60n;
|
|
4220
|
+
if (chainId >= SLIP44_MSB || chainId < 0)
|
|
4221
|
+
throw new EnsInvalidChainIdError({ chainId });
|
|
4222
|
+
return BigInt((2147483648 | chainId) >>> 0);
|
|
4223
|
+
}
|
|
4224
|
+
|
|
4225
|
+
// node_modules/viem/_esm/utils/kzg/defineKzg.js
|
|
4226
|
+
function defineKzg({ blobToKzgCommitment, computeBlobKzgProof }) {
|
|
4227
|
+
return {
|
|
4228
|
+
blobToKzgCommitment,
|
|
4229
|
+
computeBlobKzgProof
|
|
4230
|
+
};
|
|
4231
|
+
}
|
|
4232
|
+
|
|
4233
|
+
// node_modules/viem/_esm/utils/kzg/setupKzg.js
|
|
4234
|
+
function setupKzg(parameters, path) {
|
|
4235
|
+
try {
|
|
4236
|
+
parameters.loadTrustedSetup(path);
|
|
4237
|
+
} catch (e) {
|
|
4238
|
+
const error = e;
|
|
4239
|
+
if (!error.message.includes("trusted setup is already loaded"))
|
|
4240
|
+
throw error;
|
|
4241
|
+
}
|
|
4242
|
+
return defineKzg(parameters);
|
|
4243
|
+
}
|
|
4244
|
+
|
|
4245
|
+
// node_modules/viem/_esm/utils/signature/compactSignatureToSignature.js
|
|
4246
|
+
function compactSignatureToSignature({ r, yParityAndS }) {
|
|
4247
|
+
const yParityAndS_bytes = hexToBytes(yParityAndS);
|
|
4248
|
+
const yParity = yParityAndS_bytes[0] & 128 ? 1 : 0;
|
|
4249
|
+
const s = yParityAndS_bytes;
|
|
4250
|
+
if (yParity === 1)
|
|
4251
|
+
s[0] &= 127;
|
|
4252
|
+
return { r, s: bytesToHex(s), yParity };
|
|
4253
|
+
}
|
|
4254
|
+
|
|
4255
|
+
// node_modules/viem/_esm/utils/signature/parseCompactSignature.js
|
|
4256
|
+
function parseCompactSignature(signatureHex) {
|
|
4257
|
+
const { r, s } = secp256k1.Signature.fromCompact(signatureHex.slice(2, 130));
|
|
4258
|
+
return {
|
|
4259
|
+
r: numberToHex(r, { size: 32 }),
|
|
4260
|
+
yParityAndS: numberToHex(s, { size: 32 })
|
|
4261
|
+
};
|
|
4262
|
+
}
|
|
4263
|
+
|
|
4264
|
+
// node_modules/viem/_esm/utils/signature/parseSignature.js
|
|
4265
|
+
function parseSignature(signatureHex) {
|
|
4266
|
+
const { r, s } = secp256k1.Signature.fromCompact(signatureHex.slice(2, 130));
|
|
4267
|
+
const yParityOrV = Number(`0x${signatureHex.slice(130)}`);
|
|
4268
|
+
const [v, yParity] = (() => {
|
|
4269
|
+
if (yParityOrV === 0 || yParityOrV === 1)
|
|
4270
|
+
return [void 0, yParityOrV];
|
|
4271
|
+
if (yParityOrV === 27)
|
|
4272
|
+
return [BigInt(yParityOrV), 0];
|
|
4273
|
+
if (yParityOrV === 28)
|
|
4274
|
+
return [BigInt(yParityOrV), 1];
|
|
4275
|
+
throw new Error("Invalid yParityOrV value");
|
|
4276
|
+
})();
|
|
4277
|
+
if (typeof v !== "undefined")
|
|
4278
|
+
return {
|
|
4279
|
+
r: numberToHex(r, { size: 32 }),
|
|
4280
|
+
s: numberToHex(s, { size: 32 }),
|
|
4281
|
+
v,
|
|
4282
|
+
yParity
|
|
4283
|
+
};
|
|
4284
|
+
return {
|
|
4285
|
+
r: numberToHex(r, { size: 32 }),
|
|
4286
|
+
s: numberToHex(s, { size: 32 }),
|
|
4287
|
+
yParity
|
|
4288
|
+
};
|
|
4289
|
+
}
|
|
4290
|
+
|
|
4291
|
+
// node_modules/viem/_esm/utils/signature/recoverTransactionAddress.js
|
|
4292
|
+
async function recoverTransactionAddress(parameters) {
|
|
4293
|
+
const { serializedTransaction, signature: signature_ } = parameters;
|
|
4294
|
+
const transaction = parseTransaction(serializedTransaction);
|
|
4295
|
+
const signature = signature_ ?? {
|
|
4296
|
+
r: transaction.r,
|
|
4297
|
+
s: transaction.s,
|
|
4298
|
+
v: transaction.v,
|
|
4299
|
+
yParity: transaction.yParity
|
|
4300
|
+
};
|
|
4301
|
+
const serialized = serializeTransaction({
|
|
4302
|
+
...transaction,
|
|
4303
|
+
r: void 0,
|
|
4304
|
+
s: void 0,
|
|
4305
|
+
v: void 0,
|
|
4306
|
+
yParity: void 0,
|
|
4307
|
+
sidecars: void 0
|
|
4308
|
+
});
|
|
4309
|
+
return await recoverAddress({
|
|
4310
|
+
hash: keccak256(serialized),
|
|
4311
|
+
signature
|
|
4312
|
+
});
|
|
4313
|
+
}
|
|
4314
|
+
|
|
4315
|
+
// node_modules/viem/_esm/utils/signature/serializeCompactSignature.js
|
|
4316
|
+
function serializeCompactSignature({ r, yParityAndS }) {
|
|
4317
|
+
return `0x${new secp256k1.Signature(hexToBigInt(r), hexToBigInt(yParityAndS)).toCompactHex()}`;
|
|
4318
|
+
}
|
|
4319
|
+
|
|
4320
|
+
// node_modules/viem/_esm/utils/signature/signatureToCompactSignature.js
|
|
4321
|
+
function signatureToCompactSignature(signature) {
|
|
4322
|
+
const { r, s, v, yParity } = signature;
|
|
4323
|
+
const yParity_ = Number(yParity ?? v - 27n);
|
|
4324
|
+
let yParityAndS = s;
|
|
4325
|
+
if (yParity_ === 1) {
|
|
4326
|
+
const bytes = hexToBytes(s);
|
|
4327
|
+
bytes[0] |= 128;
|
|
4328
|
+
yParityAndS = bytesToHex(bytes);
|
|
4329
|
+
}
|
|
4330
|
+
return { r, yParityAndS };
|
|
4331
|
+
}
|
|
4332
|
+
|
|
4333
|
+
export {
|
|
4334
|
+
estimateContractGas,
|
|
4335
|
+
simulateContract,
|
|
4336
|
+
getContract,
|
|
4337
|
+
BundleFailedError,
|
|
4338
|
+
WaitForCallsStatusTimeoutError,
|
|
4339
|
+
createClient,
|
|
4340
|
+
rpcSchema,
|
|
4341
|
+
namehash,
|
|
4342
|
+
labelhash,
|
|
4343
|
+
EnsAvatarInvalidNftUriError,
|
|
4344
|
+
EnsAvatarUriResolutionError,
|
|
4345
|
+
EnsAvatarUnsupportedNamespaceError,
|
|
4346
|
+
EnsInvalidChainIdError,
|
|
4347
|
+
multicall,
|
|
4348
|
+
ethAddress,
|
|
4349
|
+
zeroAddress,
|
|
4350
|
+
verifyTypedData,
|
|
4351
|
+
toAmount,
|
|
4352
|
+
toBaseUnits,
|
|
4353
|
+
resolveAmountDecimals,
|
|
4354
|
+
publicActions,
|
|
4355
|
+
createPublicClient,
|
|
4356
|
+
testActions,
|
|
4357
|
+
createTestClient,
|
|
4358
|
+
sendCallsSync,
|
|
4359
|
+
signTransaction,
|
|
4360
|
+
signTypedData,
|
|
4361
|
+
walletActions,
|
|
4362
|
+
createWalletClient,
|
|
4363
|
+
createTransport,
|
|
4364
|
+
custom,
|
|
4365
|
+
fallback,
|
|
4366
|
+
shouldThrow,
|
|
4367
|
+
UrlRequiredError,
|
|
4368
|
+
http,
|
|
4369
|
+
webSocket,
|
|
4370
|
+
etherUnits,
|
|
4371
|
+
gweiUnits,
|
|
4372
|
+
weiUnits,
|
|
4373
|
+
InvalidDecimalNumberError,
|
|
4374
|
+
ProviderRpcError,
|
|
4375
|
+
decodeDeployData,
|
|
4376
|
+
fromBlobs,
|
|
4377
|
+
sidecarsToVersionedHashes,
|
|
4378
|
+
toCoinType,
|
|
4379
|
+
defineKzg,
|
|
4380
|
+
setupKzg,
|
|
4381
|
+
compactSignatureToSignature,
|
|
4382
|
+
parseCompactSignature,
|
|
4383
|
+
parseSignature,
|
|
4384
|
+
recoverTransactionAddress,
|
|
4385
|
+
serializeCompactSignature,
|
|
4386
|
+
signatureToCompactSignature
|
|
4387
|
+
};
|