@pushchain/core 6.0.20 → 6.0.21
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +48 -0
- package/package.json +1 -1
- package/src/lib/cache/cache.js +2 -0
- package/src/lib/constants/abi/index.d.ts +1 -0
- package/src/lib/constants/abi/index.js +8 -1
- package/src/lib/constants/abi/pc20.evm.d.ts +217 -0
- package/src/lib/constants/abi/pc20.evm.js +150 -0
- package/src/lib/constants/abi/prc20.evm.d.ts +172 -0
- package/src/lib/constants/abi/prc20.evm.js +97 -0
- package/src/lib/constants/abi/universalGatewayV0.json +1 -1
- package/src/lib/constants/chain.js +38 -8
- package/src/lib/constants/selectors.js +2 -2
- package/src/lib/constants/tokens.js +4 -3
- package/src/lib/formatters.js +16 -6
- package/src/lib/generated/uexecutor/v1/query.js +2 -4
- package/src/lib/generated/uexecutor/v1/types.d.ts +14 -0
- package/src/lib/generated/uexecutor/v1/types.js +90 -47
- package/src/lib/generated/uexecutor/v2/query.js +2 -4
- package/src/lib/generated/uexecutor/v2/types.d.ts +20 -0
- package/src/lib/generated/uexecutor/v2/types.js +49 -33
- package/src/lib/generated/v1/tx.js +30 -37
- package/src/lib/index.d.ts +3 -0
- package/src/lib/index.js +21 -3
- package/src/lib/internal/buffer.js +1 -2
- package/src/lib/orchestrator/cea-utils.js +73 -83
- package/src/lib/orchestrator/internals/account-manager.js +130 -139
- package/src/lib/orchestrator/internals/cascade.d.ts +0 -6
- package/src/lib/orchestrator/internals/cascade.js +1184 -1059
- package/src/lib/orchestrator/internals/confirmation.js +138 -148
- package/src/lib/orchestrator/internals/error-decoder.js +1 -1
- package/src/lib/orchestrator/internals/errors.js +12 -3
- package/src/lib/orchestrator/internals/execute-funds-only.d.ts +2 -2
- package/src/lib/orchestrator/internals/execute-funds-only.js +297 -259
- package/src/lib/orchestrator/internals/execute-funds-payload.d.ts +2 -2
- package/src/lib/orchestrator/internals/execute-funds-payload.js +220 -220
- package/src/lib/orchestrator/internals/execute-standard.d.ts +0 -8
- package/src/lib/orchestrator/internals/execute-standard.js +339 -342
- package/src/lib/orchestrator/internals/gas-calculator.js +497 -520
- package/src/lib/orchestrator/internals/gas-usd-sizer.js +101 -110
- package/src/lib/orchestrator/internals/gateway-client.js +102 -103
- package/src/lib/orchestrator/internals/helpers.js +30 -27
- package/src/lib/orchestrator/internals/inbound-tracker.js +234 -238
- package/src/lib/orchestrator/internals/outbound-sync.js +463 -452
- package/src/lib/orchestrator/internals/outbound-tracker.js +27 -34
- package/src/lib/orchestrator/internals/payload-builder.d.ts +2 -2
- package/src/lib/orchestrator/internals/payload-builder.js +119 -100
- package/src/lib/orchestrator/internals/pc-usd-oracle.js +121 -129
- package/src/lib/orchestrator/internals/pc20/address-codec.d.ts +31 -0
- package/src/lib/orchestrator/internals/pc20/address-codec.js +124 -0
- package/src/lib/orchestrator/internals/pc20/chain-namespace.d.ts +68 -0
- package/src/lib/orchestrator/internals/pc20/chain-namespace.js +136 -0
- package/src/lib/orchestrator/internals/pc20/errors.d.ts +160 -0
- package/src/lib/orchestrator/internals/pc20/errors.js +236 -0
- package/src/lib/orchestrator/internals/pc20/export.d.ts +172 -0
- package/src/lib/orchestrator/internals/pc20/export.js +412 -0
- package/src/lib/orchestrator/internals/pc20/gate.d.ts +67 -0
- package/src/lib/orchestrator/internals/pc20/gate.js +184 -0
- package/src/lib/orchestrator/internals/pc20/resolver.d.ts +187 -0
- package/src/lib/orchestrator/internals/pc20/resolver.js +658 -0
- package/src/lib/orchestrator/internals/pc20/svm.d.ts +189 -0
- package/src/lib/orchestrator/internals/pc20/svm.js +286 -0
- package/src/lib/orchestrator/internals/pc20/tracking.d.ts +46 -0
- package/src/lib/orchestrator/internals/pc20/tracking.js +109 -0
- package/src/lib/orchestrator/internals/preflight.js +1 -1
- package/src/lib/orchestrator/internals/progress-route-hooks.js +2 -2
- package/src/lib/orchestrator/internals/push-chain-tx.js +319 -329
- package/src/lib/orchestrator/internals/quote.js +90 -94
- package/src/lib/orchestrator/internals/rescue.js +76 -79
- package/src/lib/orchestrator/internals/response-builder.d.ts +28 -1
- package/src/lib/orchestrator/internals/response-builder.js +817 -701
- package/src/lib/orchestrator/internals/route-handlers.d.ts +7 -15
- package/src/lib/orchestrator/internals/route-handlers.js +1512 -1178
- package/src/lib/orchestrator/internals/signing.js +78 -83
- package/src/lib/orchestrator/internals/svm-bridge.d.ts +2 -2
- package/src/lib/orchestrator/internals/svm-bridge.js +161 -93
- package/src/lib/orchestrator/internals/svm-helpers.d.ts +15 -1
- package/src/lib/orchestrator/internals/svm-helpers.js +68 -24
- package/src/lib/orchestrator/internals/svm-rent.d.ts +19 -1
- package/src/lib/orchestrator/internals/svm-rent.js +163 -141
- package/src/lib/orchestrator/internals/tx-transformer.js +26 -23
- package/src/lib/orchestrator/internals/uea-manager.js +89 -86
- package/src/lib/orchestrator/max-pc-for-gas.js +5 -6
- package/src/lib/orchestrator/orchestrator.js +217 -200
- package/src/lib/orchestrator/orchestrator.types.d.ts +121 -1
- package/src/lib/orchestrator/orchestrator.types.js +19 -0
- package/src/lib/orchestrator/payload-builders.d.ts +2 -2
- package/src/lib/orchestrator/payload-builders.js +26 -24
- package/src/lib/orchestrator/route-detector.js +26 -9
- package/src/lib/orchestrator/svm-idl/ix-encoder.js +1 -2
- package/src/lib/orchestrator/svm-idl/normalize-address.js +2 -2
- package/src/lib/orchestrator/svm-idl/resolve.js +1 -2
- package/src/lib/price-fetch/price-fetch.js +67 -68
- package/src/lib/progress-hook/progress-hook.js +124 -72
- package/src/lib/push-chain/push-chain.js +171 -153
- package/src/lib/push-client/push-client.js +223 -237
- package/src/lib/universal/account/account.js +349 -365
- package/src/lib/universal/signer/signer.js +306 -294
- package/src/lib/universal-tx-detector/auto-detect.js +55 -60
- package/src/lib/universal-tx-detector/cascade.js +160 -172
- package/src/lib/universal-tx-detector/child-inbounds.js +67 -75
- package/src/lib/universal-tx-detector/classify.js +2 -3
- package/src/lib/universal-tx-detector/detector-svm.js +139 -147
- package/src/lib/universal-tx-detector/detector.js +145 -157
- package/src/lib/universal-tx-detector/normalize.js +7 -7
- package/src/lib/utils/external-tx-hash.js +1 -2
- package/src/lib/utils.d.ts +44 -0
- package/src/lib/utils.js +762 -683
- package/src/lib/vm-client/evm-client.js +186 -202
- package/src/lib/vm-client/svm-client.d.ts +1 -1
- package/src/lib/vm-client/svm-client.js +220 -224
- package/src/lib/vm-client/vm-client.types.d.ts +14 -2
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.EvmClient = exports.EIP7702NotSupportedError = void 0;
|
|
4
|
-
const tslib_1 = require("tslib");
|
|
5
4
|
const viem_1 = require("viem");
|
|
6
5
|
/**
|
|
7
6
|
* ABI of the ERC-7821 `execute(bytes32 mode, bytes executionData)` entrypoint —
|
|
@@ -40,6 +39,7 @@ const ERC7821_EXECUTION_TUPLE = {
|
|
|
40
39
|
* safely fall back to a non-7702 path without risk of double execution.
|
|
41
40
|
*/
|
|
42
41
|
class EIP7702NotSupportedError extends Error {
|
|
42
|
+
reason;
|
|
43
43
|
constructor(reason) {
|
|
44
44
|
super('Signer cannot produce an EIP-7702 authorization');
|
|
45
45
|
this.name = 'EIP7702NotSupportedError';
|
|
@@ -57,6 +57,7 @@ exports.EIP7702NotSupportedError = EIP7702NotSupportedError;
|
|
|
57
57
|
* });
|
|
58
58
|
*/
|
|
59
59
|
class EvmClient {
|
|
60
|
+
publicClient;
|
|
60
61
|
constructor({ rpcUrls, chain }) {
|
|
61
62
|
// retryCount/retryDelay make reads (incl. contract reads + Push status
|
|
62
63
|
// queries via PushClient) resilient to transient RPC 5xx (e.g. 502s under
|
|
@@ -86,10 +87,8 @@ class EvmClient {
|
|
|
86
87
|
* console.log('Address has no funds');
|
|
87
88
|
* }
|
|
88
89
|
*/
|
|
89
|
-
getBalance(address) {
|
|
90
|
-
return
|
|
91
|
-
return this.publicClient.getBalance({ address });
|
|
92
|
-
});
|
|
90
|
+
async getBalance(address) {
|
|
91
|
+
return this.publicClient.getBalance({ address });
|
|
93
92
|
}
|
|
94
93
|
/**
|
|
95
94
|
* Performs a read-only call to a smart contract.
|
|
@@ -115,14 +114,12 @@ class EvmClient {
|
|
|
115
114
|
* args: ['0xUserAddress'],
|
|
116
115
|
* });
|
|
117
116
|
*/
|
|
118
|
-
readContract(
|
|
119
|
-
return
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
args,
|
|
125
|
-
});
|
|
117
|
+
async readContract({ abi, address, functionName, args = [], }) {
|
|
118
|
+
return this.publicClient.readContract({
|
|
119
|
+
abi: abi,
|
|
120
|
+
address: address,
|
|
121
|
+
functionName,
|
|
122
|
+
args,
|
|
126
123
|
});
|
|
127
124
|
}
|
|
128
125
|
/**
|
|
@@ -131,17 +128,15 @@ class EvmClient {
|
|
|
131
128
|
* This is a convenience wrapper around readContract using the minimal
|
|
132
129
|
* ERC-20 ABI: balanceOf(address) -> uint256.
|
|
133
130
|
*/
|
|
134
|
-
getErc20Balance(
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
args: [ownerAddress],
|
|
144
|
-
});
|
|
131
|
+
async getErc20Balance({ tokenAddress, ownerAddress, }) {
|
|
132
|
+
const erc20Abi = (0, viem_1.parseAbi)([
|
|
133
|
+
'function balanceOf(address) view returns (uint256)',
|
|
134
|
+
]);
|
|
135
|
+
return this.readContract({
|
|
136
|
+
abi: erc20Abi,
|
|
137
|
+
address: tokenAddress,
|
|
138
|
+
functionName: 'balanceOf',
|
|
139
|
+
args: [ownerAddress],
|
|
145
140
|
});
|
|
146
141
|
}
|
|
147
142
|
/**
|
|
@@ -173,19 +168,17 @@ class EvmClient {
|
|
|
173
168
|
* signer: universalSigner,
|
|
174
169
|
* });
|
|
175
170
|
*/
|
|
176
|
-
writeContract(
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
signer,
|
|
188
|
-
});
|
|
171
|
+
async writeContract({ abi, address, functionName, args = [], value = BigInt(0), signer, }) {
|
|
172
|
+
const data = (0, viem_1.encodeFunctionData)({
|
|
173
|
+
abi: abi,
|
|
174
|
+
functionName,
|
|
175
|
+
args,
|
|
176
|
+
});
|
|
177
|
+
return this.sendTransaction({
|
|
178
|
+
to: address,
|
|
179
|
+
data,
|
|
180
|
+
value,
|
|
181
|
+
signer,
|
|
189
182
|
});
|
|
190
183
|
}
|
|
191
184
|
/**
|
|
@@ -208,44 +201,42 @@ class EvmClient {
|
|
|
208
201
|
* });
|
|
209
202
|
* console.log(`ETH transfer sent: ${txHash}`);
|
|
210
203
|
*/
|
|
211
|
-
sendTransaction(
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
explicitGas
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
:
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
value,
|
|
242
|
-
});
|
|
243
|
-
if (!signer.signAndSendTransaction) {
|
|
244
|
-
throw new Error('signer.signAndSendTransaction is undefined');
|
|
245
|
-
}
|
|
246
|
-
const txHashBytes = yield signer.signAndSendTransaction((0, viem_1.hexToBytes)(unsignedTx));
|
|
247
|
-
return (0, viem_1.bytesToHex)(txHashBytes);
|
|
204
|
+
async sendTransaction({ to, data, value = BigInt(0), signer, nonce: explicitNonce, gas: explicitGas, }) {
|
|
205
|
+
// Estimate gas and fees first (can run in parallel)
|
|
206
|
+
const [gas, feePerGas, chainId] = await Promise.all([
|
|
207
|
+
explicitGas
|
|
208
|
+
? Promise.resolve(explicitGas)
|
|
209
|
+
: data === '0x'
|
|
210
|
+
? Promise.resolve(BigInt(21000))
|
|
211
|
+
: this.publicClient.estimateGas({
|
|
212
|
+
account: signer.account.address,
|
|
213
|
+
to,
|
|
214
|
+
data,
|
|
215
|
+
value,
|
|
216
|
+
}),
|
|
217
|
+
this.publicClient.estimateFeesPerGas(),
|
|
218
|
+
this.publicClient.getChainId(),
|
|
219
|
+
]);
|
|
220
|
+
const nonce = explicitNonce ?? await this.publicClient.getTransactionCount({
|
|
221
|
+
address: signer.account.address,
|
|
222
|
+
blockTag: 'pending',
|
|
223
|
+
});
|
|
224
|
+
const unsignedTx = (0, viem_1.serializeTransaction)({
|
|
225
|
+
chainId,
|
|
226
|
+
type: 'eip1559',
|
|
227
|
+
to,
|
|
228
|
+
data,
|
|
229
|
+
gas,
|
|
230
|
+
nonce,
|
|
231
|
+
maxFeePerGas: feePerGas.maxFeePerGas,
|
|
232
|
+
maxPriorityFeePerGas: feePerGas.maxPriorityFeePerGas,
|
|
233
|
+
value,
|
|
248
234
|
});
|
|
235
|
+
if (!signer.signAndSendTransaction) {
|
|
236
|
+
throw new Error('signer.signAndSendTransaction is undefined');
|
|
237
|
+
}
|
|
238
|
+
const txHashBytes = await signer.signAndSendTransaction((0, viem_1.hexToBytes)(unsignedTx));
|
|
239
|
+
return (0, viem_1.bytesToHex)(txHashBytes);
|
|
249
240
|
}
|
|
250
241
|
/**
|
|
251
242
|
* Executes a batch of calls atomically from a native EOA using EIP-7702.
|
|
@@ -266,95 +257,93 @@ class EvmClient {
|
|
|
266
257
|
*
|
|
267
258
|
* @returns The transaction hash.
|
|
268
259
|
*/
|
|
269
|
-
sendBatch7702(
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
contractAddress: executor,
|
|
312
|
-
chainId,
|
|
313
|
-
nonce: nonce + 1,
|
|
314
|
-
});
|
|
315
|
-
}
|
|
316
|
-
catch (err) {
|
|
317
|
-
throw new EIP7702NotSupportedError(err);
|
|
318
|
-
}
|
|
319
|
-
// Estimate gas against the delegated account: override the EOA's code with
|
|
320
|
-
// the 7702 delegation designator (0xef0100 || executor) so estimation runs
|
|
321
|
-
// the executor. Fall back to a safe ceiling if the node rejects overrides.
|
|
322
|
-
let gas;
|
|
323
|
-
try {
|
|
324
|
-
gas = yield this.publicClient.estimateGas({
|
|
325
|
-
account,
|
|
326
|
-
to: account,
|
|
327
|
-
data,
|
|
328
|
-
stateOverride: [
|
|
329
|
-
{
|
|
330
|
-
address: account,
|
|
331
|
-
code: ('0xef0100' + executor.slice(2)),
|
|
332
|
-
},
|
|
333
|
-
],
|
|
334
|
-
});
|
|
335
|
-
gas = (gas * BigInt(120)) / BigInt(100); // headroom for delegation + auth
|
|
336
|
-
}
|
|
337
|
-
catch (_b) {
|
|
338
|
-
// Estimation unavailable (e.g. node rejects state overrides). Scale the
|
|
339
|
-
// ceiling with the batch size so large batches don't OOG — the legacy
|
|
340
|
-
// per-call loop budgeted ~500k gas per call; mirror that plus overhead.
|
|
341
|
-
gas = BigInt(500000) * BigInt(calls.length) + BigInt(100000);
|
|
342
|
-
}
|
|
343
|
-
const unsignedTx = (0, viem_1.serializeTransaction)({
|
|
260
|
+
async sendBatch7702({ executor, calls, signer, }) {
|
|
261
|
+
if (!signer.signAuthorization) {
|
|
262
|
+
// No capability at all → safe pre-broadcast signal to fall back.
|
|
263
|
+
throw new EIP7702NotSupportedError();
|
|
264
|
+
}
|
|
265
|
+
if (!signer.signAndSendTransaction) {
|
|
266
|
+
throw new Error('signer.signAndSendTransaction is undefined');
|
|
267
|
+
}
|
|
268
|
+
const account = signer.account.address;
|
|
269
|
+
// ERC-7821 maps target == address(0) to address(this); reject it so a batch
|
|
270
|
+
// can't silently behave differently here vs. the sequential fallback.
|
|
271
|
+
if (calls.some((c) => /^0x0{40}$/i.test(c.to) || c.to.toLowerCase() === '0x0')) {
|
|
272
|
+
throw new Error('sendBatch7702: a call has a zero `to` address, which ERC-7821 reinterprets ' +
|
|
273
|
+
'as the account itself. Use an explicit target.');
|
|
274
|
+
}
|
|
275
|
+
// ERC-7821: execute(mode, executionData) where executionData = abi.encode(Execution[]).
|
|
276
|
+
const executionData = (0, viem_1.encodeAbiParameters)([ERC7821_EXECUTION_TUPLE], [
|
|
277
|
+
calls.map((c) => ({ target: c.to, value: c.value, callData: c.data })),
|
|
278
|
+
]);
|
|
279
|
+
const data = (0, viem_1.encodeFunctionData)({
|
|
280
|
+
abi: PUSH_BATCH_EXECUTOR_ABI,
|
|
281
|
+
functionName: 'execute',
|
|
282
|
+
args: [ERC7821_BATCH_MODE, executionData],
|
|
283
|
+
});
|
|
284
|
+
const [feePerGas, chainId, nonce] = await Promise.all([
|
|
285
|
+
this.publicClient.estimateFeesPerGas(),
|
|
286
|
+
this.publicClient.getChainId(),
|
|
287
|
+
this.publicClient.getTransactionCount({
|
|
288
|
+
address: account,
|
|
289
|
+
blockTag: 'pending',
|
|
290
|
+
}),
|
|
291
|
+
]);
|
|
292
|
+
// EIP-7702 self-execution: the transaction consumes `nonce`, so the
|
|
293
|
+
// authorization (validated after the sender's nonce is bumped) must carry
|
|
294
|
+
// `nonce + 1`. This is the only step that can reveal the wallet truly can't
|
|
295
|
+
// sign a 7702 authorization (presence of the method is not a guarantee), so
|
|
296
|
+
// a failure here is surfaced as EIP7702NotSupportedError — pre-broadcast,
|
|
297
|
+
// hence safe for the caller to fall back on.
|
|
298
|
+
let authorization;
|
|
299
|
+
try {
|
|
300
|
+
authorization = await signer.signAuthorization({
|
|
301
|
+
contractAddress: executor,
|
|
344
302
|
chainId,
|
|
345
|
-
|
|
303
|
+
nonce: nonce + 1,
|
|
304
|
+
});
|
|
305
|
+
}
|
|
306
|
+
catch (err) {
|
|
307
|
+
throw new EIP7702NotSupportedError(err);
|
|
308
|
+
}
|
|
309
|
+
// Estimate gas against the delegated account: override the EOA's code with
|
|
310
|
+
// the 7702 delegation designator (0xef0100 || executor) so estimation runs
|
|
311
|
+
// the executor. Fall back to a safe ceiling if the node rejects overrides.
|
|
312
|
+
let gas;
|
|
313
|
+
try {
|
|
314
|
+
gas = await this.publicClient.estimateGas({
|
|
315
|
+
account,
|
|
346
316
|
to: account,
|
|
347
317
|
data,
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
318
|
+
stateOverride: [
|
|
319
|
+
{
|
|
320
|
+
address: account,
|
|
321
|
+
code: ('0xef0100' + executor.slice(2)),
|
|
322
|
+
},
|
|
323
|
+
],
|
|
354
324
|
});
|
|
355
|
-
|
|
356
|
-
|
|
325
|
+
gas = (gas * BigInt(120)) / BigInt(100); // headroom for delegation + auth
|
|
326
|
+
}
|
|
327
|
+
catch {
|
|
328
|
+
// Estimation unavailable (e.g. node rejects state overrides). Scale the
|
|
329
|
+
// ceiling with the batch size so large batches don't OOG — the legacy
|
|
330
|
+
// per-call loop budgeted ~500k gas per call; mirror that plus overhead.
|
|
331
|
+
gas = BigInt(500_000) * BigInt(calls.length) + BigInt(100_000);
|
|
332
|
+
}
|
|
333
|
+
const unsignedTx = (0, viem_1.serializeTransaction)({
|
|
334
|
+
chainId,
|
|
335
|
+
type: 'eip7702',
|
|
336
|
+
to: account,
|
|
337
|
+
data,
|
|
338
|
+
gas,
|
|
339
|
+
nonce,
|
|
340
|
+
maxFeePerGas: feePerGas.maxFeePerGas,
|
|
341
|
+
maxPriorityFeePerGas: feePerGas.maxPriorityFeePerGas,
|
|
342
|
+
value: BigInt(0),
|
|
343
|
+
authorizationList: [authorization],
|
|
357
344
|
});
|
|
345
|
+
const txHashBytes = await signer.signAndSendTransaction((0, viem_1.hexToBytes)(unsignedTx));
|
|
346
|
+
return (0, viem_1.bytesToHex)(txHashBytes);
|
|
358
347
|
}
|
|
359
348
|
/**
|
|
360
349
|
* Estimates the gas required for a transaction.
|
|
@@ -386,14 +375,12 @@ class EvmClient {
|
|
|
386
375
|
* value: BigInt(0),
|
|
387
376
|
* });
|
|
388
377
|
*/
|
|
389
|
-
estimateGas(
|
|
390
|
-
return
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
data,
|
|
396
|
-
});
|
|
378
|
+
async estimateGas({ from, to, value, data, }) {
|
|
379
|
+
return this.publicClient.estimateGas({
|
|
380
|
+
account: from || undefined,
|
|
381
|
+
to,
|
|
382
|
+
value,
|
|
383
|
+
data,
|
|
397
384
|
});
|
|
398
385
|
}
|
|
399
386
|
/**
|
|
@@ -415,10 +402,8 @@ class EvmClient {
|
|
|
415
402
|
* const totalCost = gasPrice * gasEstimate;
|
|
416
403
|
* console.log(`Estimated transaction cost: ${totalCost} wei`);
|
|
417
404
|
*/
|
|
418
|
-
getGasPrice() {
|
|
419
|
-
return
|
|
420
|
-
return this.publicClient.getGasPrice();
|
|
421
|
-
});
|
|
405
|
+
async getGasPrice() {
|
|
406
|
+
return this.publicClient.getGasPrice();
|
|
422
407
|
}
|
|
423
408
|
/**
|
|
424
409
|
* Fetches the full transaction response by hash.
|
|
@@ -430,20 +415,21 @@ class EvmClient {
|
|
|
430
415
|
* const tx = await evmClient.getTransaction('0xabc...');
|
|
431
416
|
* console.log(tx?.from, tx?.to, tx?.value);
|
|
432
417
|
*/
|
|
433
|
-
getTransaction(txHash) {
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
const
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
confirmations,
|
|
442
|
-
});
|
|
443
|
-
return receipt;
|
|
418
|
+
async getTransaction(txHash) {
|
|
419
|
+
const tx = await this.publicClient.getTransaction({ hash: txHash });
|
|
420
|
+
if (!tx)
|
|
421
|
+
throw new Error('No transaction found!');
|
|
422
|
+
const wait = async (confirmations = 1) => {
|
|
423
|
+
const receipt = await this.publicClient.waitForTransactionReceipt({
|
|
424
|
+
hash: txHash,
|
|
425
|
+
confirmations,
|
|
444
426
|
});
|
|
445
|
-
return
|
|
446
|
-
}
|
|
427
|
+
return receipt;
|
|
428
|
+
};
|
|
429
|
+
return {
|
|
430
|
+
...tx,
|
|
431
|
+
wait,
|
|
432
|
+
};
|
|
447
433
|
}
|
|
448
434
|
/**
|
|
449
435
|
* Waits for a transaction to achieve the desired number of confirmations.
|
|
@@ -453,26 +439,24 @@ class EvmClient {
|
|
|
453
439
|
* @param pollIntervalMs - How often to check (default: 1000 ms)
|
|
454
440
|
* @param timeoutMs - Maximum time to wait before error (default: 60000 ms)
|
|
455
441
|
*/
|
|
456
|
-
waitForConfirmations(
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
hash: txHash,
|
|
460
|
-
});
|
|
461
|
-
const targetBlock = receipt.blockNumber + BigInt(confirmations);
|
|
462
|
-
const startTime = Date.now();
|
|
463
|
-
// eslint-disable-next-line no-constant-condition
|
|
464
|
-
while (true) {
|
|
465
|
-
const currentBlock = yield this.publicClient.getBlockNumber();
|
|
466
|
-
if (currentBlock >= targetBlock) {
|
|
467
|
-
return;
|
|
468
|
-
}
|
|
469
|
-
if (Date.now() - startTime > timeoutMs) {
|
|
470
|
-
throw new Error(`Timeout: transaction ${txHash} not confirmed with ${confirmations} confirmations ` +
|
|
471
|
-
`within ${timeoutMs} ms`);
|
|
472
|
-
}
|
|
473
|
-
yield new Promise((r) => setTimeout(r, pollIntervalMs));
|
|
474
|
-
}
|
|
442
|
+
async waitForConfirmations({ txHash, confirmations = 3, pollIntervalMs = 1000, timeoutMs = 30000, }) {
|
|
443
|
+
const receipt = await this.publicClient.waitForTransactionReceipt({
|
|
444
|
+
hash: txHash,
|
|
475
445
|
});
|
|
446
|
+
const targetBlock = receipt.blockNumber + BigInt(confirmations);
|
|
447
|
+
const startTime = Date.now();
|
|
448
|
+
// eslint-disable-next-line no-constant-condition
|
|
449
|
+
while (true) {
|
|
450
|
+
const currentBlock = await this.publicClient.getBlockNumber();
|
|
451
|
+
if (currentBlock >= targetBlock) {
|
|
452
|
+
return;
|
|
453
|
+
}
|
|
454
|
+
if (Date.now() - startTime > timeoutMs) {
|
|
455
|
+
throw new Error(`Timeout: transaction ${txHash} not confirmed with ${confirmations} confirmations ` +
|
|
456
|
+
`within ${timeoutMs} ms`);
|
|
457
|
+
}
|
|
458
|
+
await new Promise((r) => setTimeout(r, pollIntervalMs));
|
|
459
|
+
}
|
|
476
460
|
}
|
|
477
461
|
}
|
|
478
462
|
exports.EvmClient = EvmClient;
|
|
@@ -26,7 +26,7 @@ export declare class SvmClient {
|
|
|
26
26
|
/**
|
|
27
27
|
* Sends a Solana transaction using a smart contract instruction.
|
|
28
28
|
*/
|
|
29
|
-
writeContract({ abi, signer, functionName, args, accounts, extraSigners, }: WriteContractParams): Promise<string>;
|
|
29
|
+
writeContract({ abi, signer, functionName, args, accounts, extraSigners, remainingAccounts, }: WriteContractParams): Promise<string>;
|
|
30
30
|
/**
|
|
31
31
|
* Sends a set of instructions as a manually-signed Solana transaction.
|
|
32
32
|
*/
|