@pushchain/core 4.0.13 → 5.0.0
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/package.json +1 -1
- package/src/lib/constants/abi/universalGatewayV0.json +593 -1800
- package/src/lib/constants/chain.d.ts +1 -2
- package/src/lib/constants/chain.js +16 -46
- package/src/lib/constants/chain.js.map +1 -1
- package/src/lib/constants/tokens.d.ts +1 -7
- package/src/lib/constants/tokens.js +8 -50
- package/src/lib/constants/tokens.js.map +1 -1
- package/src/lib/orchestrator/orchestrator.d.ts +1 -12
- package/src/lib/orchestrator/orchestrator.js +92 -481
- package/src/lib/orchestrator/orchestrator.js.map +1 -1
- package/src/lib/orchestrator/orchestrator.types.d.ts +0 -42
- package/src/lib/orchestrator/payload-builders.d.ts +1 -2
- package/src/lib/orchestrator/payload-builders.js +14 -53
- package/src/lib/orchestrator/payload-builders.js.map +1 -1
- package/src/lib/progress-hook/progress-hook.js +4 -50
- package/src/lib/progress-hook/progress-hook.js.map +1 -1
- package/src/lib/progress-hook/progress-hook.types.d.ts +3 -9
- package/src/lib/progress-hook/progress-hook.types.js +0 -7
- package/src/lib/progress-hook/progress-hook.types.js.map +1 -1
- package/src/lib/push-chain/push-chain.d.ts +0 -4
- package/src/lib/push-chain/push-chain.js +0 -3
- package/src/lib/push-chain/push-chain.js.map +1 -1
- package/src/lib/push-client/push-client.d.ts +3 -10
- package/src/lib/push-client/push-client.js +61 -98
- package/src/lib/push-client/push-client.js.map +1 -1
- package/src/lib/universal/signer/signer.js +3 -17
- package/src/lib/universal/signer/signer.js.map +1 -1
- package/src/lib/utils.d.ts +0 -14
- package/src/lib/utils.js +0 -25
- package/src/lib/utils.js.map +1 -1
|
@@ -15,7 +15,6 @@ const price_fetch_1 = require("../price-fetch/price-fetch");
|
|
|
15
15
|
const progress_hook_1 = tslib_1.__importDefault(require("../progress-hook/progress-hook"));
|
|
16
16
|
const progress_hook_types_1 = require("../progress-hook/progress-hook.types");
|
|
17
17
|
const push_chain_1 = require("../push-chain/push-chain");
|
|
18
|
-
const utils_1 = require("../utils");
|
|
19
18
|
const push_client_1 = require("../push-client/push-client");
|
|
20
19
|
const evm_client_1 = require("../vm-client/evm-client");
|
|
21
20
|
const svm_client_1 = require("../vm-client/svm-client");
|
|
@@ -64,16 +63,7 @@ class Orchestrator {
|
|
|
64
63
|
*/
|
|
65
64
|
execute(execute) {
|
|
66
65
|
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
67
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _j
|
|
68
|
-
// Create buffer to collect events during execution for tx.progressHook() replay
|
|
69
|
-
const eventBuffer = [];
|
|
70
|
-
// Store original progressHook and wrap to collect events
|
|
71
|
-
const originalHook = this.progressHook;
|
|
72
|
-
this.progressHook = (event) => {
|
|
73
|
-
eventBuffer.push(event);
|
|
74
|
-
if (originalHook)
|
|
75
|
-
originalHook(event);
|
|
76
|
-
};
|
|
66
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j;
|
|
77
67
|
try {
|
|
78
68
|
if (execute.funds) {
|
|
79
69
|
if (!execute.data || execute.data === '0x') {
|
|
@@ -123,25 +113,12 @@ class Orchestrator {
|
|
|
123
113
|
const { nonce, deployed } = yield this.getUeaStatusAndNonce();
|
|
124
114
|
const { payload: universalPayload, req } = yield this.buildGatewayPayloadAndGas(execute, nonce, 'sendFunds', bridgeAmount);
|
|
125
115
|
const ueaAddress = this.computeUEAOffchain();
|
|
126
|
-
this.printLog('sendFunds — buildGatewayPayloadAndGas result: ' + JSON.stringify({
|
|
127
|
-
recipient: execute.to,
|
|
128
|
-
ueaAddress,
|
|
129
|
-
isSelfBridge: execute.to.toLowerCase() === ueaAddress.toLowerCase(),
|
|
130
|
-
bridgeAmount: bridgeAmount.toString(),
|
|
131
|
-
bridgeToken,
|
|
132
|
-
isNative,
|
|
133
|
-
tokenAddr,
|
|
134
|
-
nonce: nonce.toString(),
|
|
135
|
-
deployed,
|
|
136
|
-
}, (_, v) => typeof v === 'bigint' ? v.toString() : v, 2));
|
|
137
116
|
// Compute minimal native amount to deposit for gas on Push Chain
|
|
138
117
|
const ueaBalanceForGas = yield this.pushClient.getBalance(ueaAddress);
|
|
139
118
|
const nativeAmount = yield this.calculateNativeAmountForDeposit(chain, BigInt(0), ueaBalanceForGas);
|
|
140
|
-
this.printLog(`sendFunds — nativeAmount: ${nativeAmount.toString()}, ueaBalanceForGas: ${ueaBalanceForGas.toString()}`);
|
|
141
119
|
// We log the SEND_TX_03_01 here because the progress hook for gas estimation should arrive before the resolving of UEA.
|
|
142
120
|
this.executeProgressHook(progress_hook_types_1.PROGRESS_HOOK.SEND_TX_03_01);
|
|
143
121
|
this.executeProgressHook(progress_hook_types_1.PROGRESS_HOOK.SEND_TX_03_02, ueaAddress, deployed);
|
|
144
|
-
this.printLog(`UEA resolved: ${ueaAddress}, deployed: ${deployed}`);
|
|
145
122
|
this.executeProgressHook(progress_hook_types_1.PROGRESS_HOOK.SEND_TX_06_01, amount, execute.funds.token.decimals, symbol);
|
|
146
123
|
if (vm === enums_1.VM.EVM) {
|
|
147
124
|
const evmClient = new evm_client_1.EvmClient({ rpcUrls });
|
|
@@ -180,19 +157,13 @@ class Orchestrator {
|
|
|
180
157
|
// revertInstruction: revertCFG,
|
|
181
158
|
// signatureData: '0x',
|
|
182
159
|
// } as unknown as never;
|
|
183
|
-
this.printLog('FUNDS ONLY SELF — gateway call payload: ' + JSON.stringify({
|
|
184
|
-
gatewayAddress, functionName: 'sendUniversalTx', req,
|
|
185
|
-
value: (isNative ? nativeAmount + bridgeAmount : nativeAmount).toString(),
|
|
186
|
-
isNative, bridgeAmount: bridgeAmount.toString(),
|
|
187
|
-
nativeAmount: nativeAmount.toString(), bridgeToken,
|
|
188
|
-
}, (_, v) => typeof v === 'bigint' ? v.toString() : v, 2));
|
|
189
160
|
txHash = yield evmClient.writeContract({
|
|
190
161
|
abi: abi_1.UNIVERSAL_GATEWAY_V0,
|
|
191
162
|
address: gatewayAddress,
|
|
192
163
|
functionName: 'sendUniversalTx',
|
|
193
164
|
args: [req],
|
|
194
165
|
signer: this.universalSigner,
|
|
195
|
-
value: isNative ?
|
|
166
|
+
value: isNative ? bridgeAmount : BigInt(0),
|
|
196
167
|
});
|
|
197
168
|
}
|
|
198
169
|
else {
|
|
@@ -208,19 +179,13 @@ class Orchestrator {
|
|
|
208
179
|
// revertInstruction: revertCFG,
|
|
209
180
|
// signatureData: '0x',
|
|
210
181
|
// } as unknown as never;
|
|
211
|
-
this.printLog('FUNDS ONLY OTHER — gateway call payload: ' + JSON.stringify({
|
|
212
|
-
gatewayAddress, functionName: 'sendUniversalTx', req,
|
|
213
|
-
value: nativeAmount.toString(),
|
|
214
|
-
isNative, bridgeAmount: bridgeAmount.toString(),
|
|
215
|
-
nativeAmount: nativeAmount.toString(), bridgeToken,
|
|
216
|
-
}, (_, v) => typeof v === 'bigint' ? v.toString() : v, 2));
|
|
217
182
|
txHash = yield evmClient.writeContract({
|
|
218
183
|
abi: abi_1.UNIVERSAL_GATEWAY_V0,
|
|
219
184
|
address: gatewayAddress,
|
|
220
185
|
functionName: 'sendUniversalTx',
|
|
221
186
|
args: [req],
|
|
222
187
|
signer: this.universalSigner,
|
|
223
|
-
value:
|
|
188
|
+
value: nativeAmount,
|
|
224
189
|
});
|
|
225
190
|
}
|
|
226
191
|
}
|
|
@@ -230,37 +195,14 @@ class Orchestrator {
|
|
|
230
195
|
}
|
|
231
196
|
const originTx = yield this.fetchOriginChainTransactionForProgress(chain, txHash, txHash);
|
|
232
197
|
this.executeProgressHook(progress_hook_types_1.PROGRESS_HOOK.SEND_TX_06_02, txHash, bridgeAmount, execute.funds.token.decimals, symbol, originTx);
|
|
233
|
-
yield this.waitForEvmConfirmationsWithCountdown(evmClient, txHash,
|
|
234
|
-
// Funds Confirmed - emit immediately after confirmations
|
|
235
|
-
this.executeProgressHook(progress_hook_types_1.PROGRESS_HOOK.SEND_TX_06_04);
|
|
236
|
-
// Syncing with Push Chain - emit before query
|
|
237
|
-
this.executeProgressHook(progress_hook_types_1.PROGRESS_HOOK.SEND_TX_06_05);
|
|
238
|
-
this.printLog('sendFunds — querying Push Chain status: ' + JSON.stringify({
|
|
239
|
-
txHash,
|
|
240
|
-
evmGatewayMethod: execute.to === ueaAddress ? 'sendFunds' : 'sendTxWithFunds',
|
|
241
|
-
}));
|
|
198
|
+
yield this.waitForEvmConfirmationsWithCountdown(evmClient, txHash, 4, 210000);
|
|
242
199
|
const pushChainUniversalTx = yield this.queryUniversalTxStatusFromGatewayTx(evmClient, gatewayAddress, txHash, execute.to === ueaAddress ? 'sendFunds' : 'sendTxWithFunds');
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
// For sendFunds operations, MintPC (first) succeeds and executePayload (second) may fail
|
|
248
|
-
// Always use the last pcTx entry as it represents the final execution result
|
|
249
|
-
const lastPcTransaction = pushChainUniversalTx.pcTx.at(-1);
|
|
250
|
-
this.printLog('sendFunds — pushChainUniversalTx pcTx: ' + JSON.stringify((_b = pushChainUniversalTx === null || pushChainUniversalTx === void 0 ? void 0 : pushChainUniversalTx.pcTx) === null || _b === void 0 ? void 0 : _b.map((p) => ({ txHash: p.txHash, status: p.status, errorMsg: p.errorMsg })), null, 2));
|
|
251
|
-
this.printLog('sendFunds — using lastPcTransaction: ' + JSON.stringify(lastPcTransaction, null, 2));
|
|
252
|
-
if (!(lastPcTransaction === null || lastPcTransaction === void 0 ? void 0 : lastPcTransaction.txHash)) {
|
|
253
|
-
// Check for error messages in failed entries
|
|
254
|
-
const failedPcTx = pushChainUniversalTx.pcTx.find((pcTx) => pcTx.status === 'FAILED' && pcTx.errorMsg);
|
|
255
|
-
const errorDetails = (failedPcTx === null || failedPcTx === void 0 ? void 0 : failedPcTx.errorMsg)
|
|
256
|
-
? `: ${failedPcTx.errorMsg}`
|
|
257
|
-
: '';
|
|
258
|
-
throw new Error(`No transaction hash found in Push Chain response for gateway tx: ${txHash}${errorDetails}`);
|
|
259
|
-
}
|
|
260
|
-
const tx = yield this.pushClient.getTransaction(lastPcTransaction.txHash);
|
|
261
|
-
const response = yield this.transformToUniversalTxResponse(tx, eventBuffer);
|
|
200
|
+
this.executeProgressHook(progress_hook_types_1.PROGRESS_HOOK.SEND_TX_06_04);
|
|
201
|
+
const lastPcTransaction = pushChainUniversalTx === null || pushChainUniversalTx === void 0 ? void 0 : pushChainUniversalTx.pcTx.at(-1);
|
|
202
|
+
const tx = yield this.pushClient.getTransaction(lastPcTransaction === null || lastPcTransaction === void 0 ? void 0 : lastPcTransaction.txHash);
|
|
203
|
+
const response = yield this.transformToUniversalTxResponse(tx);
|
|
262
204
|
// Funds Flow: Funds credited on Push Chain
|
|
263
|
-
this.executeProgressHook(progress_hook_types_1.PROGRESS_HOOK.
|
|
205
|
+
this.executeProgressHook(progress_hook_types_1.PROGRESS_HOOK.SEND_TX_06_05, bridgeAmount, execute.funds.token.decimals, symbol);
|
|
264
206
|
this.executeProgressHook(progress_hook_types_1.PROGRESS_HOOK.SEND_TX_99_01, [response]);
|
|
265
207
|
return response;
|
|
266
208
|
}
|
|
@@ -293,8 +235,11 @@ class Orchestrator {
|
|
|
293
235
|
if (execute.funds.token.mechanism === 'native') {
|
|
294
236
|
// Native SOL funds-only
|
|
295
237
|
const [tokenRateLimitPda] = web3_js_1.PublicKey.findProgramAddressSync([(0, viem_1.stringToBytes)('rate_limit'), web3_js_1.PublicKey.default.toBuffer()], programId);
|
|
238
|
+
const recipientNative = execute.to === ueaAddress
|
|
239
|
+
? Array.from(Buffer.alloc(20, 0))
|
|
240
|
+
: recipientEvm20;
|
|
296
241
|
const reqNative = this._buildSvmUniversalTxRequest({
|
|
297
|
-
recipient:
|
|
242
|
+
recipient: recipientNative,
|
|
298
243
|
token: web3_js_1.PublicKey.default,
|
|
299
244
|
amount: bridgeAmount,
|
|
300
245
|
payload: '0x',
|
|
@@ -339,8 +284,9 @@ class Orchestrator {
|
|
|
339
284
|
], ASSOCIATED_TOKEN_PROGRAM_ID)[0];
|
|
340
285
|
const [tokenRateLimitPda] = web3_js_1.PublicKey.findProgramAddressSync([(0, viem_1.stringToBytes)('rate_limit'), mintPk.toBuffer()], programId);
|
|
341
286
|
if (execute.to === ueaAddress) {
|
|
287
|
+
const recipientSpl = Array.from(Buffer.alloc(20, 0));
|
|
342
288
|
const reqSpl = this._buildSvmUniversalTxRequest({
|
|
343
|
-
recipient:
|
|
289
|
+
recipient: recipientSpl,
|
|
344
290
|
token: mintPk,
|
|
345
291
|
amount: bridgeAmount,
|
|
346
292
|
payload: '0x',
|
|
@@ -404,30 +350,15 @@ class Orchestrator {
|
|
|
404
350
|
}
|
|
405
351
|
const originTx = yield this.fetchOriginChainTransactionForProgress(chain, '0x', txSignature);
|
|
406
352
|
this.executeProgressHook(progress_hook_types_1.PROGRESS_HOOK.SEND_TX_06_02, txSignature, bridgeAmount, execute.funds.token.decimals, symbol, originTx);
|
|
407
|
-
yield this.waitForSvmConfirmationsWithCountdown(svmClient, txSignature,
|
|
408
|
-
// Funds Confirmed - emit immediately after confirmations
|
|
409
|
-
this.executeProgressHook(progress_hook_types_1.PROGRESS_HOOK.SEND_TX_06_04);
|
|
410
|
-
// Syncing with Push Chain - emit before query
|
|
411
|
-
this.executeProgressHook(progress_hook_types_1.PROGRESS_HOOK.SEND_TX_06_05);
|
|
353
|
+
yield this.waitForSvmConfirmationsWithCountdown(svmClient, txSignature, 25, 300000);
|
|
412
354
|
// After origin confirmations, query Push Chain for UniversalTx status (SVM)
|
|
413
355
|
const pushChainUniversalTx = yield this.queryUniversalTxStatusFromGatewayTx(undefined, undefined, txSignature, 'sendFunds');
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
// Always use the last pcTx entry as it represents the final execution result
|
|
419
|
-
const lastPcTransaction = pushChainUniversalTx.pcTx.at(-1);
|
|
420
|
-
if (!(lastPcTransaction === null || lastPcTransaction === void 0 ? void 0 : lastPcTransaction.txHash)) {
|
|
421
|
-
const failedPcTx = pushChainUniversalTx.pcTx.find((pcTx) => pcTx.status === 'FAILED' && pcTx.errorMsg);
|
|
422
|
-
const errorDetails = (failedPcTx === null || failedPcTx === void 0 ? void 0 : failedPcTx.errorMsg)
|
|
423
|
-
? `: ${failedPcTx.errorMsg}`
|
|
424
|
-
: '';
|
|
425
|
-
throw new Error(`No transaction hash found in Push Chain response for gateway tx: ${txSignature}${errorDetails}`);
|
|
426
|
-
}
|
|
427
|
-
const tx = yield this.pushClient.getTransaction(lastPcTransaction.txHash);
|
|
428
|
-
const response = yield this.transformToUniversalTxResponse(tx, eventBuffer);
|
|
356
|
+
this.executeProgressHook(progress_hook_types_1.PROGRESS_HOOK.SEND_TX_06_04);
|
|
357
|
+
const lastPcTransaction = pushChainUniversalTx === null || pushChainUniversalTx === void 0 ? void 0 : pushChainUniversalTx.pcTx.at(-1);
|
|
358
|
+
const tx = yield this.pushClient.getTransaction(lastPcTransaction === null || lastPcTransaction === void 0 ? void 0 : lastPcTransaction.txHash);
|
|
359
|
+
const response = yield this.transformToUniversalTxResponse(tx);
|
|
429
360
|
// Funds Flow: Funds credited on Push Chain
|
|
430
|
-
this.executeProgressHook(progress_hook_types_1.PROGRESS_HOOK.
|
|
361
|
+
this.executeProgressHook(progress_hook_types_1.PROGRESS_HOOK.SEND_TX_06_05, bridgeAmount, execute.funds.token.decimals, symbol);
|
|
431
362
|
this.executeProgressHook(progress_hook_types_1.PROGRESS_HOOK.SEND_TX_99_01, [response]);
|
|
432
363
|
return response;
|
|
433
364
|
}
|
|
@@ -459,7 +390,7 @@ class Orchestrator {
|
|
|
459
390
|
const gasEstimate = execute.gasLimit || BigInt(1e7);
|
|
460
391
|
const gasPrice = yield this.pushClient.getGasPrice();
|
|
461
392
|
const requiredGasFee = gasEstimate * gasPrice;
|
|
462
|
-
const payloadValue = (
|
|
393
|
+
const payloadValue = (_a = execute.value) !== null && _a !== void 0 ? _a : BigInt(0);
|
|
463
394
|
const requiredFunds = requiredGasFee + payloadValue;
|
|
464
395
|
const ueaAddress = this.computeUEAOffchain();
|
|
465
396
|
const [ueaBalance] = yield Promise.all([
|
|
@@ -468,8 +399,8 @@ class Orchestrator {
|
|
|
468
399
|
// UEA resolved (address, deployment status, balance, nonce)
|
|
469
400
|
this.executeProgressHook(progress_hook_types_1.PROGRESS_HOOK.SEND_TX_03_02, ueaAddress, deployed);
|
|
470
401
|
// Determine USD to deposit via gateway (8 decimals) with caps: min=$1, max=$10
|
|
471
|
-
const oneUsd =
|
|
472
|
-
const tenUsd =
|
|
402
|
+
const oneUsd = push_chain_1.PushChain.utils.helpers.parseUnits('1', 8);
|
|
403
|
+
const tenUsd = push_chain_1.PushChain.utils.helpers.parseUnits('10', 8);
|
|
473
404
|
const deficit = requiredFunds > ueaBalance ? requiredFunds - ueaBalance : BigInt(0);
|
|
474
405
|
let depositUsd = deficit > BigInt(0) ? this.pushClient.pushToUSDC(deficit) : oneUsd;
|
|
475
406
|
if (depositUsd < oneUsd)
|
|
@@ -492,8 +423,8 @@ class Orchestrator {
|
|
|
492
423
|
functionName: 'config',
|
|
493
424
|
args: [configPda.toBase58()],
|
|
494
425
|
});
|
|
495
|
-
const minField = (
|
|
496
|
-
const maxField = (
|
|
426
|
+
const minField = (_b = cfg.minCapUniversalTxUsd) !== null && _b !== void 0 ? _b : cfg.min_cap_universal_tx_usd;
|
|
427
|
+
const maxField = (_c = cfg.maxCapUniversalTxUsd) !== null && _c !== void 0 ? _c : cfg.max_cap_universal_tx_usd;
|
|
497
428
|
const minCapUsd = BigInt(minField.toString());
|
|
498
429
|
const maxCapUsd = BigInt(maxField.toString());
|
|
499
430
|
if (depositUsd < minCapUsd)
|
|
@@ -505,14 +436,14 @@ class Orchestrator {
|
|
|
505
436
|
if (depositUsd > maxCapUsd)
|
|
506
437
|
depositUsd = maxCapUsd;
|
|
507
438
|
}
|
|
508
|
-
catch (
|
|
439
|
+
catch (_k) {
|
|
509
440
|
// best-effort; fallback to previous bounds if read fails
|
|
510
441
|
}
|
|
511
442
|
}
|
|
512
443
|
// Convert USD(8) -> native units using pricing path
|
|
513
444
|
const nativeTokenUsdPrice = yield new price_fetch_1.PriceFetch(this.rpcUrls).getPrice(chain); // 8 decimals
|
|
514
445
|
const nativeDecimals = chain_1.CHAIN_INFO[chain].vm === enums_1.VM.SVM ? 9 : 18;
|
|
515
|
-
const oneNativeUnit =
|
|
446
|
+
const oneNativeUnit = push_chain_1.PushChain.utils.helpers.parseUnits('1', nativeDecimals);
|
|
516
447
|
// Ceil division to avoid rounding below min USD on-chain
|
|
517
448
|
let nativeAmount = (depositUsd * oneNativeUnit + (nativeTokenUsdPrice - BigInt(1))) /
|
|
518
449
|
nativeTokenUsdPrice;
|
|
@@ -529,16 +460,12 @@ class Orchestrator {
|
|
|
529
460
|
this.executeProgressHook(progress_hook_types_1.PROGRESS_HOOK.SEND_TX_06_01, bridgeAmount, execute.funds.token.decimals, symbol);
|
|
530
461
|
if (chain_1.CHAIN_INFO[this.universalSigner.account.chain].vm === enums_1.VM.EVM) {
|
|
531
462
|
const tokenAddr = execute.funds.token.address;
|
|
532
|
-
if (mechanism
|
|
533
|
-
|
|
534
|
-
const evmClientEvm = evmClient;
|
|
535
|
-
const gatewayAddressEvm = gatewayAddress;
|
|
536
|
-
yield this.ensureErc20Allowance(evmClientEvm, tokenAddr, gatewayAddressEvm, bridgeAmount);
|
|
463
|
+
if (mechanism !== 'approve') {
|
|
464
|
+
throw new Error('Only ERC-20 tokens are supported for funds+payload on EVM; native and permit2 are not supported yet');
|
|
537
465
|
}
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
// Native tokens (mechanism === 'native') don't need approval - handled via msg.value
|
|
466
|
+
const evmClientEvm = evmClient;
|
|
467
|
+
const gatewayAddressEvm = gatewayAddress;
|
|
468
|
+
yield this.ensureErc20Allowance(evmClientEvm, tokenAddr, gatewayAddressEvm, bridgeAmount);
|
|
542
469
|
}
|
|
543
470
|
let txHash;
|
|
544
471
|
try {
|
|
@@ -556,7 +483,7 @@ class Orchestrator {
|
|
|
556
483
|
// New behavior: if user provided a gasTokenAddress, pay gas in that token via Uniswap quote
|
|
557
484
|
// Determine pay-with token address, min-out and slippage
|
|
558
485
|
const payWith = execute.payGasWith;
|
|
559
|
-
const gasTokenAddress = (
|
|
486
|
+
const gasTokenAddress = (_d = payWith === null || payWith === void 0 ? void 0 : payWith.token) === null || _d === void 0 ? void 0 : _d.address;
|
|
560
487
|
if (gasTokenAddress) {
|
|
561
488
|
if (chain !== enums_1.CHAIN.ETHEREUM_SEPOLIA) {
|
|
562
489
|
throw new Error(`Only ${push_chain_1.PushChain.utils.chains.getChainName(enums_1.CHAIN.ETHEREUM_SEPOLIA)} is supported for paying gas fees with ERC-20 tokens`);
|
|
@@ -564,7 +491,7 @@ class Orchestrator {
|
|
|
564
491
|
let amountOutMinETH = (payWith === null || payWith === void 0 ? void 0 : payWith.minAmountOut) !== undefined
|
|
565
492
|
? BigInt(payWith.minAmountOut)
|
|
566
493
|
: nativeAmount;
|
|
567
|
-
const slippageBps = (
|
|
494
|
+
const slippageBps = (_e = payWith === null || payWith === void 0 ? void 0 : payWith.slippageBps) !== null && _e !== void 0 ? _e : 100;
|
|
568
495
|
amountOutMinETH = BigInt(push_chain_1.PushChain.utils.conversion.slippageToMinAmount(amountOutMinETH.toString(), { slippageBps }));
|
|
569
496
|
const { gasAmount } = yield this.calculateGasAmountFromAmountOutMinETH(gasTokenAddress, amountOutMinETH);
|
|
570
497
|
const deadline = BigInt(0);
|
|
@@ -576,10 +503,10 @@ class Orchestrator {
|
|
|
576
503
|
ownerAddress,
|
|
577
504
|
});
|
|
578
505
|
if (gasTokenBalance < gasAmount) {
|
|
579
|
-
const sym = (
|
|
580
|
-
const decimals = (
|
|
581
|
-
const needFmt =
|
|
582
|
-
const haveFmt =
|
|
506
|
+
const sym = (_g = (_f = payWith === null || payWith === void 0 ? void 0 : payWith.token) === null || _f === void 0 ? void 0 : _f.symbol) !== null && _g !== void 0 ? _g : 'gas token';
|
|
507
|
+
const decimals = (_j = (_h = payWith === null || payWith === void 0 ? void 0 : payWith.token) === null || _h === void 0 ? void 0 : _h.decimals) !== null && _j !== void 0 ? _j : 18;
|
|
508
|
+
const needFmt = push_chain_1.PushChain.utils.helpers.formatUnits(gasAmount, decimals);
|
|
509
|
+
const haveFmt = push_chain_1.PushChain.utils.helpers.formatUnits(gasTokenBalance, decimals);
|
|
583
510
|
throw new Error(`Insufficient ${sym} balance to cover gas fees: need ${needFmt}, have ${haveFmt}`);
|
|
584
511
|
}
|
|
585
512
|
// Approve gas token to gateway
|
|
@@ -625,19 +552,13 @@ class Orchestrator {
|
|
|
625
552
|
// payload: this.encodeUniversalPayload(universalPayload),
|
|
626
553
|
// });
|
|
627
554
|
// VALUE + PAYLOAD + FUNDS && PAYLOAD + FUNDS
|
|
628
|
-
// For native tokens: msg.value = gas amount + bridge amount
|
|
629
|
-
// For ERC-20 tokens: msg.value = gas amount only (bridge handled via token transfer)
|
|
630
|
-
const isNativeToken = mechanism === 'native';
|
|
631
|
-
const totalValue = isNativeToken
|
|
632
|
-
? nativeAmount + bridgeAmount
|
|
633
|
-
: nativeAmount;
|
|
634
555
|
txHash = yield evmClientEvm.writeContract({
|
|
635
556
|
abi: abi_1.UNIVERSAL_GATEWAY_V0,
|
|
636
557
|
address: gatewayAddressEvm,
|
|
637
558
|
functionName: 'sendUniversalTx',
|
|
638
559
|
args: [req],
|
|
639
560
|
signer: this.universalSigner,
|
|
640
|
-
value:
|
|
561
|
+
value: nativeAmount,
|
|
641
562
|
});
|
|
642
563
|
}
|
|
643
564
|
}
|
|
@@ -661,17 +582,16 @@ class Orchestrator {
|
|
|
661
582
|
// Funds Flow: Funds lock submitted
|
|
662
583
|
this.executeProgressHook(progress_hook_types_1.PROGRESS_HOOK.SEND_TX_06_02, txHash, bridgeAmount, execute.funds.token.decimals, symbol);
|
|
663
584
|
// Awaiting confirmations
|
|
664
|
-
|
|
665
|
-
if (chain_1.CHAIN_INFO[signerChain].vm === enums_1.VM.EVM) {
|
|
585
|
+
if (chain_1.CHAIN_INFO[this.universalSigner.account.chain].vm === enums_1.VM.EVM) {
|
|
666
586
|
const evmClientEvm = evmClient;
|
|
667
|
-
yield this.waitForEvmConfirmationsWithCountdown(evmClientEvm, txHash,
|
|
587
|
+
yield this.waitForEvmConfirmationsWithCountdown(evmClientEvm, txHash, 4, 300000);
|
|
668
588
|
}
|
|
669
589
|
else {
|
|
670
590
|
const svmClient = new svm_client_1.SvmClient({
|
|
671
591
|
rpcUrls: this.rpcUrls[enums_1.CHAIN.SOLANA_DEVNET] ||
|
|
672
592
|
chain_1.CHAIN_INFO[enums_1.CHAIN.SOLANA_DEVNET].defaultRPC,
|
|
673
593
|
});
|
|
674
|
-
yield this.waitForSvmConfirmationsWithCountdown(svmClient, txHash,
|
|
594
|
+
yield this.waitForSvmConfirmationsWithCountdown(svmClient, txHash, 25, 300000);
|
|
675
595
|
}
|
|
676
596
|
// Funds Flow: Confirmed on origin
|
|
677
597
|
let feeLockTxHash = txHash;
|
|
@@ -689,10 +609,7 @@ class Orchestrator {
|
|
|
689
609
|
// ) {
|
|
690
610
|
// await this.sendUniversalTx(deployed, feeLockTxHash);
|
|
691
611
|
// }
|
|
692
|
-
// Funds Confirmed - emit immediately after confirmations
|
|
693
612
|
this.executeProgressHook(progress_hook_types_1.PROGRESS_HOOK.SEND_TX_06_04);
|
|
694
|
-
// Syncing with Push Chain - emit before query
|
|
695
|
-
this.executeProgressHook(progress_hook_types_1.PROGRESS_HOOK.SEND_TX_06_05);
|
|
696
613
|
// After sending Cosmos tx to Push Chain, query UniversalTx status
|
|
697
614
|
let pushChainUniversalTx;
|
|
698
615
|
if (chain_1.CHAIN_INFO[this.universalSigner.account.chain].vm === enums_1.VM.EVM) {
|
|
@@ -705,23 +622,9 @@ class Orchestrator {
|
|
|
705
622
|
pushChainUniversalTx =
|
|
706
623
|
yield this.queryUniversalTxStatusFromGatewayTx(undefined, undefined, txHash, 'sendTxWithFunds');
|
|
707
624
|
}
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
}
|
|
712
|
-
// Always use the last pcTx entry as it represents the final execution result
|
|
713
|
-
const lastPcTransaction = pushChainUniversalTx.pcTx.at(-1);
|
|
714
|
-
if (!(lastPcTransaction === null || lastPcTransaction === void 0 ? void 0 : lastPcTransaction.txHash)) {
|
|
715
|
-
const failedPcTx = pushChainUniversalTx.pcTx.find((pcTx) => pcTx.status === 'FAILED' && pcTx.errorMsg);
|
|
716
|
-
const errorDetails = (failedPcTx === null || failedPcTx === void 0 ? void 0 : failedPcTx.errorMsg)
|
|
717
|
-
? `: ${failedPcTx.errorMsg}`
|
|
718
|
-
: '';
|
|
719
|
-
throw new Error(`No transaction hash found in Push Chain response for gateway tx: ${txHash}${errorDetails}`);
|
|
720
|
-
}
|
|
721
|
-
const tx = yield this.pushClient.getTransaction(lastPcTransaction.txHash);
|
|
722
|
-
const response = yield this.transformToUniversalTxResponse(tx, eventBuffer);
|
|
723
|
-
// Funds Flow: Funds credited on Push Chain
|
|
724
|
-
this.executeProgressHook(progress_hook_types_1.PROGRESS_HOOK.SEND_TX_06_06, bridgeAmount, execute.funds.token.decimals, symbol);
|
|
625
|
+
const lastPcTransaction = pushChainUniversalTx === null || pushChainUniversalTx === void 0 ? void 0 : pushChainUniversalTx.pcTx.at(-1);
|
|
626
|
+
const tx = yield this.pushClient.getTransaction(lastPcTransaction === null || lastPcTransaction === void 0 ? void 0 : lastPcTransaction.txHash);
|
|
627
|
+
const response = yield this.transformToUniversalTxResponse(tx);
|
|
725
628
|
this.executeProgressHook(progress_hook_types_1.PROGRESS_HOOK.SEND_TX_99_01, [response]);
|
|
726
629
|
return response;
|
|
727
630
|
}
|
|
@@ -738,7 +641,7 @@ class Orchestrator {
|
|
|
738
641
|
*/
|
|
739
642
|
if (this.isPushChain(chain)) {
|
|
740
643
|
this.executeProgressHook(progress_hook_types_1.PROGRESS_HOOK.SEND_TX_07);
|
|
741
|
-
const tx = yield this.sendPushTx(execute
|
|
644
|
+
const tx = yield this.sendPushTx(execute);
|
|
742
645
|
this.executeProgressHook(progress_hook_types_1.PROGRESS_HOOK.SEND_TX_99_01, [tx]);
|
|
743
646
|
return tx;
|
|
744
647
|
}
|
|
@@ -843,28 +746,15 @@ class Orchestrator {
|
|
|
843
746
|
if (execute.data && execute.to.toLowerCase() === UEA.toLowerCase()) {
|
|
844
747
|
throw new Error(`You can't execute data on the UEA address`);
|
|
845
748
|
}
|
|
846
|
-
// VALUE ONLY SELF
|
|
749
|
+
// VALUE ONLY SELF
|
|
847
750
|
payloadTo = execute.to;
|
|
848
751
|
payloadData = execute.data || '0x';
|
|
849
|
-
const reqData = this._buildMulticallPayloadData(execute.to, (0, payload_builders_1.buildExecuteMulticall)({ execute, ueaAddress: UEA }));
|
|
850
|
-
const universalPayloadSelf = JSON.parse(JSON.stringify({
|
|
851
|
-
to: viem_1.zeroAddress,
|
|
852
|
-
value: execute.value,
|
|
853
|
-
data: reqData,
|
|
854
|
-
gasLimit: execute.gasLimit || BigInt(5e7),
|
|
855
|
-
maxFeePerGas: execute.maxFeePerGas || BigInt(1e10),
|
|
856
|
-
maxPriorityFeePerGas: execute.maxPriorityFeePerGas || BigInt(0),
|
|
857
|
-
nonce,
|
|
858
|
-
deadline: execute.deadline || BigInt(9999999999),
|
|
859
|
-
vType: feeLockingRequired
|
|
860
|
-
? tx_1.VerificationType.universalTxVerification
|
|
861
|
-
: tx_1.VerificationType.signedVerification,
|
|
862
|
-
}, this.bigintReplacer));
|
|
863
752
|
req = this._buildUniversalTxRequest({
|
|
753
|
+
// recipient: execute.to,
|
|
864
754
|
recipient: viem_1.zeroAddress,
|
|
865
755
|
token: viem_1.zeroAddress,
|
|
866
756
|
amount: BigInt(0),
|
|
867
|
-
payload:
|
|
757
|
+
payload: payloadData,
|
|
868
758
|
});
|
|
869
759
|
}
|
|
870
760
|
}
|
|
@@ -906,7 +796,7 @@ class Orchestrator {
|
|
|
906
796
|
* Fee Locking - For all chains, EVM and Solana
|
|
907
797
|
*/
|
|
908
798
|
const fundDifference = requiredFunds - funds;
|
|
909
|
-
const fixedPushAmount =
|
|
799
|
+
const fixedPushAmount = push_chain_1.PushChain.utils.helpers.parseUnits('0.001', 18); // Minimum lock 0.001 Push tokens
|
|
910
800
|
const lockAmount = funds < requiredFunds ? fundDifference : fixedPushAmount;
|
|
911
801
|
const lockAmountInUSD = this.pushClient.pushToUSDC(lockAmount);
|
|
912
802
|
const feeLockTxHashBytes = yield this.lockFee(lockAmountInUSD, universalPayload, req);
|
|
@@ -931,21 +821,9 @@ class Orchestrator {
|
|
|
931
821
|
* Note: queryTx may be undefined since validators don't recognize new UniversalTx event yet
|
|
932
822
|
*/
|
|
933
823
|
// Transform to UniversalTxResponse (follow sendFunds pattern)
|
|
934
|
-
|
|
935
|
-
|
|
936
|
-
|
|
937
|
-
}
|
|
938
|
-
// Always use the last pcTx entry as it represents the final execution result
|
|
939
|
-
const lastPcTransaction = pushChainUniversalTx.pcTx.at(-1);
|
|
940
|
-
if (!(lastPcTransaction === null || lastPcTransaction === void 0 ? void 0 : lastPcTransaction.txHash)) {
|
|
941
|
-
const failedPcTx = pushChainUniversalTx.pcTx.find((pcTx) => pcTx.status === 'FAILED' && pcTx.errorMsg);
|
|
942
|
-
const errorDetails = (failedPcTx === null || failedPcTx === void 0 ? void 0 : failedPcTx.errorMsg)
|
|
943
|
-
? `: ${failedPcTx.errorMsg}`
|
|
944
|
-
: '';
|
|
945
|
-
throw new Error(`No transaction hash found in Push Chain response for gateway tx: ${feeLockTxHash}${errorDetails}`);
|
|
946
|
-
}
|
|
947
|
-
const tx = yield this.pushClient.getTransaction(lastPcTransaction.txHash);
|
|
948
|
-
const response = yield this.transformToUniversalTxResponse(tx, eventBuffer);
|
|
824
|
+
const lastPcTransaction = pushChainUniversalTx === null || pushChainUniversalTx === void 0 ? void 0 : pushChainUniversalTx.pcTx.at(-1);
|
|
825
|
+
const tx = yield this.pushClient.getTransaction(lastPcTransaction === null || lastPcTransaction === void 0 ? void 0 : lastPcTransaction.txHash);
|
|
826
|
+
const response = yield this.transformToUniversalTxResponse(tx);
|
|
949
827
|
this.executeProgressHook(progress_hook_types_1.PROGRESS_HOOK.SEND_TX_99_01, [response]);
|
|
950
828
|
return response;
|
|
951
829
|
}
|
|
@@ -954,7 +832,7 @@ class Orchestrator {
|
|
|
954
832
|
*/
|
|
955
833
|
this.executeProgressHook(progress_hook_types_1.PROGRESS_HOOK.SEND_TX_07);
|
|
956
834
|
// We don't need to query via gRPC the PC transaction since it's getting returned it here already.
|
|
957
|
-
const transactions = yield this.sendUniversalTx(isUEADeployed, feeLockTxHash, universalPayload, verificationData
|
|
835
|
+
const transactions = yield this.sendUniversalTx(isUEADeployed, feeLockTxHash, universalPayload, verificationData);
|
|
958
836
|
this.executeProgressHook(progress_hook_types_1.PROGRESS_HOOK.SEND_TX_99_01, transactions);
|
|
959
837
|
return transactions[transactions.length - 1];
|
|
960
838
|
}
|
|
@@ -974,10 +852,6 @@ class Orchestrator {
|
|
|
974
852
|
this.executeProgressHook(progress_hook_types_1.PROGRESS_HOOK.SEND_TX_99_02, errMessage);
|
|
975
853
|
throw err;
|
|
976
854
|
}
|
|
977
|
-
finally {
|
|
978
|
-
// Restore original progressHook
|
|
979
|
-
this.progressHook = originalHook;
|
|
980
|
-
}
|
|
981
855
|
});
|
|
982
856
|
}
|
|
983
857
|
/**
|
|
@@ -1005,8 +879,8 @@ class Orchestrator {
|
|
|
1005
879
|
]);
|
|
1006
880
|
const nativeDecimals = 18; // ETH, MATIC, etc.
|
|
1007
881
|
// Ensure deposit respects gateway USD caps (min $1, max $10) and avoid rounding below min
|
|
1008
|
-
const oneUsd =
|
|
1009
|
-
const tenUsd =
|
|
882
|
+
const oneUsd = push_chain_1.PushChain.utils.helpers.parseUnits('1', 8);
|
|
883
|
+
const tenUsd = push_chain_1.PushChain.utils.helpers.parseUnits('10', 8);
|
|
1010
884
|
let depositUsd = amount < oneUsd ? oneUsd : amount;
|
|
1011
885
|
if (depositUsd > tenUsd)
|
|
1012
886
|
depositUsd = tenUsd;
|
|
@@ -1041,8 +915,8 @@ class Orchestrator {
|
|
|
1041
915
|
]);
|
|
1042
916
|
// Ensure deposit respects gateway USD caps (min $1, max $10) and avoid rounding below min
|
|
1043
917
|
const nativeDecimals = 9; // SOL lamports
|
|
1044
|
-
const oneUsd =
|
|
1045
|
-
const tenUsd =
|
|
918
|
+
const oneUsd = push_chain_1.PushChain.utils.helpers.parseUnits('1', 8);
|
|
919
|
+
const tenUsd = push_chain_1.PushChain.utils.helpers.parseUnits('10', 8);
|
|
1046
920
|
let depositUsd = amount < oneUsd ? oneUsd : amount;
|
|
1047
921
|
if (depositUsd > tenUsd)
|
|
1048
922
|
depositUsd = tenUsd;
|
|
@@ -1244,8 +1118,8 @@ class Orchestrator {
|
|
|
1244
1118
|
/**
|
|
1245
1119
|
* Sends a custom Cosmos tx to Push Chain (gasless) to execute user intent.
|
|
1246
1120
|
*/
|
|
1247
|
-
sendUniversalTx(
|
|
1248
|
-
return tslib_1.__awaiter(this,
|
|
1121
|
+
sendUniversalTx(isUEADeployed, feeLockTxHash, universalPayload, verificationData) {
|
|
1122
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
1249
1123
|
var _a, _b;
|
|
1250
1124
|
const { chain, address } = this.universalSigner.account;
|
|
1251
1125
|
const { vm, chainId } = chain_1.CHAIN_INFO[chain];
|
|
@@ -1306,8 +1180,7 @@ class Orchestrator {
|
|
|
1306
1180
|
const evmTxs = yield Promise.all(ethTxHashes.map((hash) => tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
1307
1181
|
return yield this.pushClient.getTransaction(hash);
|
|
1308
1182
|
})));
|
|
1309
|
-
|
|
1310
|
-
return yield Promise.all(evmTxs.map((tx, index) => this.transformToUniversalTxResponse(tx, index === evmTxs.length - 1 ? eventBuffer : [])));
|
|
1183
|
+
return yield Promise.all(evmTxs.map((tx) => this.transformToUniversalTxResponse(tx)));
|
|
1311
1184
|
});
|
|
1312
1185
|
}
|
|
1313
1186
|
/**
|
|
@@ -1316,8 +1189,8 @@ class Orchestrator {
|
|
|
1316
1189
|
* @param execute
|
|
1317
1190
|
* @returns Cosmos Tx Response for a given Evm Tx
|
|
1318
1191
|
*/
|
|
1319
|
-
sendPushTx(
|
|
1320
|
-
return tslib_1.__awaiter(this,
|
|
1192
|
+
sendPushTx(execute) {
|
|
1193
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
1321
1194
|
// For PushChain, multicall is not supported. Ensure data is hex string.
|
|
1322
1195
|
if (Array.isArray(execute.data)) {
|
|
1323
1196
|
throw new Error('Multicall is not supported on PushChain');
|
|
@@ -1329,7 +1202,7 @@ class Orchestrator {
|
|
|
1329
1202
|
signer: this.universalSigner,
|
|
1330
1203
|
});
|
|
1331
1204
|
const txResponse = yield this.pushClient.getTransaction(txHash);
|
|
1332
|
-
return yield this.transformToUniversalTxResponse(txResponse
|
|
1205
|
+
return yield this.transformToUniversalTxResponse(txResponse);
|
|
1333
1206
|
});
|
|
1334
1207
|
}
|
|
1335
1208
|
/**
|
|
@@ -1504,123 +1377,6 @@ class Orchestrator {
|
|
|
1504
1377
|
vTypeBytes,
|
|
1505
1378
|
]);
|
|
1506
1379
|
}
|
|
1507
|
-
/**
|
|
1508
|
-
* Tracks a transaction by hash on Push Chain
|
|
1509
|
-
* @param txHash - Transaction hash to track
|
|
1510
|
-
* @param options - Tracking options (chain, progress hooks, polling config)
|
|
1511
|
-
* @returns Promise resolving to UniversalTxReceipt when transaction is confirmed
|
|
1512
|
-
*/
|
|
1513
|
-
trackTransaction(txHash, options) {
|
|
1514
|
-
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
1515
|
-
const { chain = this.getPushChainForNetwork(), progress, waitForCompletion = true, advanced = {}, } = options !== null && options !== void 0 ? options : {};
|
|
1516
|
-
const { pollingIntervalMs = 1000, timeout = 300000, rpcUrls = {}, } = advanced;
|
|
1517
|
-
// Helper to invoke both per-transaction and orchestrator hooks
|
|
1518
|
-
const invokeProgressHook = (hookPayload) => {
|
|
1519
|
-
this.printLog(hookPayload.message);
|
|
1520
|
-
// Per-transaction hook called FIRST
|
|
1521
|
-
if (progress) {
|
|
1522
|
-
progress(hookPayload);
|
|
1523
|
-
}
|
|
1524
|
-
// Orchestrator-level hook called SECOND
|
|
1525
|
-
if (this.progressHook) {
|
|
1526
|
-
this.progressHook(hookPayload);
|
|
1527
|
-
}
|
|
1528
|
-
};
|
|
1529
|
-
// Emit TRACK_TX_01 - tracking started
|
|
1530
|
-
if (progress || this.progressHook) {
|
|
1531
|
-
const hookPayload = progress_hook_1.default[progress_hook_types_1.PROGRESS_HOOK.TRACK_TX_01](txHash, chain);
|
|
1532
|
-
invokeProgressHook(hookPayload);
|
|
1533
|
-
}
|
|
1534
|
-
// Create client for target chain with optional RPC override
|
|
1535
|
-
const chainRPCs = rpcUrls[chain] || this.rpcUrls[chain] || chain_1.CHAIN_INFO[chain].defaultRPC;
|
|
1536
|
-
const client = new push_client_1.PushClient({
|
|
1537
|
-
rpcUrls: chainRPCs,
|
|
1538
|
-
network: this.pushNetwork,
|
|
1539
|
-
});
|
|
1540
|
-
// Try to get transaction immediately
|
|
1541
|
-
try {
|
|
1542
|
-
const tx = yield client.getTransaction(txHash);
|
|
1543
|
-
if (!waitForCompletion) {
|
|
1544
|
-
// Non-blocking mode: return current receipt immediately
|
|
1545
|
-
const receipt = yield tx.wait(0);
|
|
1546
|
-
const universalTxResponse = yield this.transformToUniversalTxResponse(tx);
|
|
1547
|
-
return this.transformToUniversalTxReceipt(receipt, universalTxResponse);
|
|
1548
|
-
}
|
|
1549
|
-
// Blocking mode: wait for confirmation
|
|
1550
|
-
const receipt = yield tx.wait(1);
|
|
1551
|
-
const universalTxResponse = yield this.transformToUniversalTxResponse(tx);
|
|
1552
|
-
// Emit TRACK_TX_99_01 - tracking complete
|
|
1553
|
-
if (progress || this.progressHook) {
|
|
1554
|
-
const hookPayload = progress_hook_1.default[progress_hook_types_1.PROGRESS_HOOK.TRACK_TX_99_01](txHash, universalTxResponse);
|
|
1555
|
-
invokeProgressHook(hookPayload);
|
|
1556
|
-
}
|
|
1557
|
-
return this.transformToUniversalTxReceipt(receipt, universalTxResponse);
|
|
1558
|
-
}
|
|
1559
|
-
catch (initialError) {
|
|
1560
|
-
// Transaction not found yet - start polling if waitForCompletion is true
|
|
1561
|
-
if (!waitForCompletion) {
|
|
1562
|
-
// Non-blocking and tx not found - throw error
|
|
1563
|
-
const errorMsg = initialError instanceof Error ? initialError.message : 'Transaction not found';
|
|
1564
|
-
if (progress || this.progressHook) {
|
|
1565
|
-
const hookPayload = progress_hook_1.default[progress_hook_types_1.PROGRESS_HOOK.TRACK_TX_99_02](txHash, errorMsg);
|
|
1566
|
-
invokeProgressHook(hookPayload);
|
|
1567
|
-
}
|
|
1568
|
-
throw new Error(`Transaction ${txHash} not found: ${errorMsg}`);
|
|
1569
|
-
}
|
|
1570
|
-
// Blocking mode: poll until found or timeout
|
|
1571
|
-
const start = Date.now();
|
|
1572
|
-
// eslint-disable-next-line no-constant-condition
|
|
1573
|
-
while (true) {
|
|
1574
|
-
// Emit TRACK_TX_02 - querying status
|
|
1575
|
-
if (progress || this.progressHook) {
|
|
1576
|
-
const hookPayload = progress_hook_1.default[progress_hook_types_1.PROGRESS_HOOK.TRACK_TX_02](txHash);
|
|
1577
|
-
invokeProgressHook(hookPayload);
|
|
1578
|
-
}
|
|
1579
|
-
try {
|
|
1580
|
-
const tx = yield client.getTransaction(txHash);
|
|
1581
|
-
const receipt = yield tx.wait(1);
|
|
1582
|
-
const universalTxResponse = yield this.transformToUniversalTxResponse(tx);
|
|
1583
|
-
// Success - emit TRACK_TX_99_01
|
|
1584
|
-
if (progress || this.progressHook) {
|
|
1585
|
-
const hookPayload = progress_hook_1.default[progress_hook_types_1.PROGRESS_HOOK.TRACK_TX_99_01](txHash, universalTxResponse);
|
|
1586
|
-
invokeProgressHook(hookPayload);
|
|
1587
|
-
}
|
|
1588
|
-
return this.transformToUniversalTxReceipt(receipt, universalTxResponse);
|
|
1589
|
-
}
|
|
1590
|
-
catch (err) {
|
|
1591
|
-
// Transaction not found yet or error - continue polling
|
|
1592
|
-
this.printLog(`Transaction ${txHash} not found yet, continuing to poll...`);
|
|
1593
|
-
}
|
|
1594
|
-
// Check timeout
|
|
1595
|
-
if (Date.now() - start > timeout) {
|
|
1596
|
-
const timeoutMsg = `Timeout: transaction ${txHash} not confirmed within ${timeout}ms`;
|
|
1597
|
-
if (progress || this.progressHook) {
|
|
1598
|
-
const hookPayload = progress_hook_1.default[progress_hook_types_1.PROGRESS_HOOK.TRACK_TX_99_02](txHash, 'Timeout');
|
|
1599
|
-
invokeProgressHook(hookPayload);
|
|
1600
|
-
}
|
|
1601
|
-
throw new Error(timeoutMsg);
|
|
1602
|
-
}
|
|
1603
|
-
// Wait before next poll
|
|
1604
|
-
yield new Promise((r) => setTimeout(r, pollingIntervalMs));
|
|
1605
|
-
}
|
|
1606
|
-
}
|
|
1607
|
-
});
|
|
1608
|
-
}
|
|
1609
|
-
/**
|
|
1610
|
-
* Returns the Push Chain enum value for the current network
|
|
1611
|
-
*/
|
|
1612
|
-
getPushChainForNetwork() {
|
|
1613
|
-
if (this.pushNetwork === enums_1.PUSH_NETWORK.MAINNET) {
|
|
1614
|
-
return enums_1.CHAIN.PUSH_MAINNET;
|
|
1615
|
-
}
|
|
1616
|
-
else if (this.pushNetwork === enums_1.PUSH_NETWORK.TESTNET_DONUT ||
|
|
1617
|
-
this.pushNetwork === enums_1.PUSH_NETWORK.TESTNET) {
|
|
1618
|
-
return enums_1.CHAIN.PUSH_TESTNET_DONUT;
|
|
1619
|
-
}
|
|
1620
|
-
else {
|
|
1621
|
-
return enums_1.CHAIN.PUSH_LOCALNET;
|
|
1622
|
-
}
|
|
1623
|
-
}
|
|
1624
1380
|
/**
|
|
1625
1381
|
* Computes UEA for given UniversalAccount
|
|
1626
1382
|
* @dev - This fn calls a view fn of Factory Contract
|
|
@@ -1663,7 +1419,6 @@ class Orchestrator {
|
|
|
1663
1419
|
});
|
|
1664
1420
|
}
|
|
1665
1421
|
_buildMulticallPayloadData(to, data) {
|
|
1666
|
-
this.printLog('_buildMulticallPayloadData — input: ' + data.length + ' calls: ' + JSON.stringify(data, (_, v) => typeof v === 'bigint' ? v.toString() : v, 2));
|
|
1667
1422
|
const allowedChains = [
|
|
1668
1423
|
enums_1.CHAIN.ETHEREUM_SEPOLIA,
|
|
1669
1424
|
enums_1.CHAIN.ARBITRUM_SEPOLIA,
|
|
@@ -1896,17 +1651,17 @@ class Orchestrator {
|
|
|
1896
1651
|
waitForLockerFeeConfirmation(txHashBytes) {
|
|
1897
1652
|
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
1898
1653
|
const chain = this.universalSigner.account.chain;
|
|
1899
|
-
const { vm, defaultRPC,
|
|
1654
|
+
const { vm, defaultRPC, confirmations, timeout } = chain_1.CHAIN_INFO[chain];
|
|
1900
1655
|
const rpcUrls = this.rpcUrls[chain] || defaultRPC;
|
|
1901
1656
|
switch (vm) {
|
|
1902
1657
|
case enums_1.VM.EVM: {
|
|
1903
1658
|
const evmClient = new evm_client_1.EvmClient({ rpcUrls });
|
|
1904
|
-
yield this.waitForEvmConfirmationsWithCountdown(evmClient, (0, viem_1.bytesToHex)(txHashBytes),
|
|
1659
|
+
yield this.waitForEvmConfirmationsWithCountdown(evmClient, (0, viem_1.bytesToHex)(txHashBytes), confirmations, timeout);
|
|
1905
1660
|
return;
|
|
1906
1661
|
}
|
|
1907
1662
|
case enums_1.VM.SVM: {
|
|
1908
1663
|
const svmClient = new svm_client_1.SvmClient({ rpcUrls });
|
|
1909
|
-
yield this.waitForSvmConfirmationsWithCountdown(svmClient, anchor_1.utils.bytes.bs58.encode(txHashBytes),
|
|
1664
|
+
yield this.waitForSvmConfirmationsWithCountdown(svmClient, anchor_1.utils.bytes.bs58.encode(txHashBytes), confirmations, timeout);
|
|
1910
1665
|
return;
|
|
1911
1666
|
}
|
|
1912
1667
|
default:
|
|
@@ -2046,10 +1801,10 @@ class Orchestrator {
|
|
|
2046
1801
|
throw new Error('No direct Uniswap V3 pool found for the given token pair on common fee tiers');
|
|
2047
1802
|
}
|
|
2048
1803
|
const amountInBig = BigInt(bestAmountIn);
|
|
2049
|
-
const amountInHuman = parseFloat(
|
|
1804
|
+
const amountInHuman = parseFloat(push_chain_1.PushChain.utils.helpers.formatUnits(amountInBig, {
|
|
2050
1805
|
decimals: from.decimals,
|
|
2051
1806
|
}));
|
|
2052
|
-
const amountOutHuman = parseFloat(
|
|
1807
|
+
const amountOutHuman = parseFloat(push_chain_1.PushChain.utils.helpers.formatUnits(amountOut, { decimals: to.decimals }));
|
|
2053
1808
|
const rate = amountInHuman > 0 ? amountOutHuman / amountInHuman : 0;
|
|
2054
1809
|
return {
|
|
2055
1810
|
amountIn: bestAmountIn.toString(),
|
|
@@ -2174,7 +1929,7 @@ class Orchestrator {
|
|
|
2174
1929
|
*/
|
|
2175
1930
|
buildGatewayPayloadAndGas(execute, nonce, type, fundsValue) {
|
|
2176
1931
|
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
2177
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q
|
|
1932
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q;
|
|
2178
1933
|
const gasEstimate = execute.gasLimit || BigInt(1e7);
|
|
2179
1934
|
const gasAmount = (_a = execute.value) !== null && _a !== void 0 ? _a : BigInt(0);
|
|
2180
1935
|
if (type === 'sendTxWithFunds') {
|
|
@@ -2197,7 +1952,6 @@ class Orchestrator {
|
|
|
2197
1952
|
deadline: execute.deadline || BigInt(9999999999),
|
|
2198
1953
|
vType: tx_1.VerificationType.universalTxVerification,
|
|
2199
1954
|
};
|
|
2200
|
-
this.printLog('(universalPayload) ' + universalPayload);
|
|
2201
1955
|
// Temporary while we don't change the native address from 0xeee... to 0x0000...
|
|
2202
1956
|
let tokenAddress = (_f = (_e = execute.funds) === null || _e === void 0 ? void 0 : _e.token) === null || _f === void 0 ? void 0 : _f.address;
|
|
2203
1957
|
if (((_h = (_g = execute.funds) === null || _g === void 0 ? void 0 : _g.token) === null || _h === void 0 ? void 0 : _h.address) ===
|
|
@@ -2229,23 +1983,10 @@ class Orchestrator {
|
|
|
2229
1983
|
// const pushChainTo = PushChain.utils.tokens.getPRC20Address(
|
|
2230
1984
|
// execute.funds!.token as MoveableToken
|
|
2231
1985
|
// );
|
|
2232
|
-
this.printLog('sendFunds — execute params: ' + JSON.stringify({
|
|
2233
|
-
to: execute.to,
|
|
2234
|
-
value: (_l = (_k = execute.value) === null || _k === void 0 ? void 0 : _k.toString()) !== null && _l !== void 0 ? _l : 'undefined',
|
|
2235
|
-
data: (_m = execute.data) !== null && _m !== void 0 ? _m : 'undefined',
|
|
2236
|
-
fundsAmount: (_p = (_o = execute.funds) === null || _o === void 0 ? void 0 : _o.amount) === null || _p === void 0 ? void 0 : _p.toString(),
|
|
2237
|
-
fundsToken: (_r = (_q = execute.funds) === null || _q === void 0 ? void 0 : _q.token) === null || _r === void 0 ? void 0 : _r.symbol,
|
|
2238
|
-
tokenMechanism: (_t = (_s = execute.funds) === null || _s === void 0 ? void 0 : _s.token) === null || _t === void 0 ? void 0 : _t.mechanism,
|
|
2239
|
-
tokenAddress: (_v = (_u = execute.funds) === null || _u === void 0 ? void 0 : _u.token) === null || _v === void 0 ? void 0 : _v.address,
|
|
2240
|
-
gasLimit: (_x = (_w = execute.gasLimit) === null || _w === void 0 ? void 0 : _w.toString()) !== null && _x !== void 0 ? _x : 'undefined',
|
|
2241
|
-
}, null, 2));
|
|
2242
|
-
this.printLog('sendFunds — multicallData: ' + JSON.stringify(multicallData, (_, v) => typeof v === 'bigint' ? v.toString() : v, 2) + ' (length: ' + multicallData.length + ')');
|
|
2243
|
-
const multicallPayloadData = this._buildMulticallPayloadData(execute.to, multicallData);
|
|
2244
|
-
this.printLog('sendFunds — multicallPayloadData (first 66 chars): ' + multicallPayloadData.slice(0, 66) + ' (full length: ' + multicallPayloadData.length + ')');
|
|
2245
1986
|
const universalPayload = {
|
|
2246
1987
|
to: viem_1.zeroAddress, // We can't simply do `0x` because we will get an error when eip712 signing the transaction.
|
|
2247
|
-
value: (
|
|
2248
|
-
data:
|
|
1988
|
+
value: (_k = execute.value) !== null && _k !== void 0 ? _k : BigInt(0),
|
|
1989
|
+
data: this._buildMulticallPayloadData(execute.to, multicallData),
|
|
2249
1990
|
// data: this._buildMulticallPayloadData(execute.to, [
|
|
2250
1991
|
// { to: pushChainTo, value: execute.value ?? BigInt(0), data },
|
|
2251
1992
|
// ]),
|
|
@@ -2256,36 +1997,18 @@ class Orchestrator {
|
|
|
2256
1997
|
deadline: execute.deadline || BigInt(9999999999),
|
|
2257
1998
|
vType: tx_1.VerificationType.universalTxVerification,
|
|
2258
1999
|
};
|
|
2259
|
-
this.printLog('sendFunds — universalPayload (pre-encode): ' + JSON.stringify({
|
|
2260
|
-
to: viem_1.zeroAddress,
|
|
2261
|
-
value: ((_z = execute.value) !== null && _z !== void 0 ? _z : BigInt(0)).toString(),
|
|
2262
|
-
data: multicallPayloadData,
|
|
2263
|
-
gasLimit: gasEstimate.toString(),
|
|
2264
|
-
maxFeePerGas: (execute.maxFeePerGas || BigInt(1e10)).toString(),
|
|
2265
|
-
maxPriorityFeePerGas: (execute.maxPriorityFeePerGas || BigInt(0)).toString(),
|
|
2266
|
-
nonce: nonce.toString(),
|
|
2267
|
-
deadline: (execute.deadline || BigInt(9999999999)).toString(),
|
|
2268
|
-
}, null, 2));
|
|
2269
2000
|
// Temporary while we don't change the native address from 0xeee... to 0x0000...
|
|
2270
|
-
let tokenAddress = (
|
|
2271
|
-
if (((
|
|
2001
|
+
let tokenAddress = (_m = (_l = execute.funds) === null || _l === void 0 ? void 0 : _l.token) === null || _m === void 0 ? void 0 : _m.address;
|
|
2002
|
+
if (((_p = (_o = execute.funds) === null || _o === void 0 ? void 0 : _o.token) === null || _p === void 0 ? void 0 : _p.address) ===
|
|
2272
2003
|
'0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee') {
|
|
2273
2004
|
tokenAddress = viem_1.zeroAddress;
|
|
2274
2005
|
}
|
|
2275
|
-
const encodedPayload = this.encodeUniversalPayload(universalPayload);
|
|
2276
|
-
this.printLog('sendFunds — encodedPayload (first 66 chars): ' + encodedPayload.slice(0, 66) + ' (full length: ' + encodedPayload.length + ')');
|
|
2277
2006
|
const req = this._buildUniversalTxRequest({
|
|
2278
2007
|
recipient: viem_1.zeroAddress,
|
|
2279
2008
|
token: tokenAddress,
|
|
2280
|
-
amount: (
|
|
2281
|
-
payload:
|
|
2009
|
+
amount: (_q = execute.funds) === null || _q === void 0 ? void 0 : _q.amount,
|
|
2010
|
+
payload: this.encodeUniversalPayload(universalPayload),
|
|
2282
2011
|
});
|
|
2283
|
-
this.printLog('sendFunds — final req: ' + JSON.stringify({
|
|
2284
|
-
recipient: viem_1.zeroAddress,
|
|
2285
|
-
token: tokenAddress,
|
|
2286
|
-
amount: (_6 = (_5 = execute.funds) === null || _5 === void 0 ? void 0 : _5.amount) === null || _6 === void 0 ? void 0 : _6.toString(),
|
|
2287
|
-
payloadLength: encodedPayload.length,
|
|
2288
|
-
}, null, 2));
|
|
2289
2012
|
return { payload: universalPayload, gasAmount, req };
|
|
2290
2013
|
}
|
|
2291
2014
|
});
|
|
@@ -2326,8 +2049,8 @@ class Orchestrator {
|
|
|
2326
2049
|
/**
|
|
2327
2050
|
* Transforms a TxResponse to the new UniversalTxResponse format
|
|
2328
2051
|
*/
|
|
2329
|
-
transformToUniversalTxResponse(
|
|
2330
|
-
return tslib_1.__awaiter(this,
|
|
2052
|
+
transformToUniversalTxResponse(tx) {
|
|
2053
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
2331
2054
|
const chain = this.universalSigner.account.chain;
|
|
2332
2055
|
const { vm, chainId } = chain_1.CHAIN_INFO[chain];
|
|
2333
2056
|
let from;
|
|
@@ -2356,32 +2079,6 @@ class Orchestrator {
|
|
|
2356
2079
|
to = universalPayload.to;
|
|
2357
2080
|
value = BigInt(universalPayload.value);
|
|
2358
2081
|
data = universalPayload.data;
|
|
2359
|
-
// Extract 'to' from single-element multicall
|
|
2360
|
-
if (data && data.length >= 10) {
|
|
2361
|
-
const multicallSelector = (0, viem_1.keccak256)((0, viem_1.toBytes)('UEA_MULTICALL')).slice(0, 10);
|
|
2362
|
-
if (data.slice(0, 10) === multicallSelector) {
|
|
2363
|
-
try {
|
|
2364
|
-
const innerData = ('0x' + data.slice(10));
|
|
2365
|
-
const [decodedCalls] = (0, viem_1.decodeAbiParameters)([
|
|
2366
|
-
{
|
|
2367
|
-
type: 'tuple[]',
|
|
2368
|
-
components: [
|
|
2369
|
-
{ name: 'to', type: 'address' },
|
|
2370
|
-
{ name: 'value', type: 'uint256' },
|
|
2371
|
-
{ name: 'data', type: 'bytes' },
|
|
2372
|
-
],
|
|
2373
|
-
},
|
|
2374
|
-
], innerData);
|
|
2375
|
-
// If single call, use its 'to' address
|
|
2376
|
-
if (decodedCalls.length === 1) {
|
|
2377
|
-
to = (0, viem_1.getAddress)(decodedCalls[0].to);
|
|
2378
|
-
}
|
|
2379
|
-
}
|
|
2380
|
-
catch (_a) {
|
|
2381
|
-
// Keep original 'to' if decoding fails
|
|
2382
|
-
}
|
|
2383
|
-
}
|
|
2384
|
-
}
|
|
2385
2082
|
rawTransactionData = {
|
|
2386
2083
|
from: (0, viem_1.getAddress)(tx.from),
|
|
2387
2084
|
to: (0, viem_1.getAddress)(tx.to),
|
|
@@ -2417,39 +2114,6 @@ class Orchestrator {
|
|
|
2417
2114
|
value: tx.value,
|
|
2418
2115
|
};
|
|
2419
2116
|
}
|
|
2420
|
-
// Extract 'to' and 'from' from depositPRC20WithAutoSwap (precompile call)
|
|
2421
|
-
if (data && data.length >= 10) {
|
|
2422
|
-
const depositPRC20Selector = '0x780ad827';
|
|
2423
|
-
if (data.slice(0, 10) === depositPRC20Selector) {
|
|
2424
|
-
try {
|
|
2425
|
-
const decoded = (0, viem_1.decodeFunctionData)({
|
|
2426
|
-
abi: [
|
|
2427
|
-
{
|
|
2428
|
-
name: 'depositPRC20WithAutoSwap',
|
|
2429
|
-
type: 'function',
|
|
2430
|
-
inputs: [
|
|
2431
|
-
{ name: 'prc20', type: 'address' },
|
|
2432
|
-
{ name: 'amount', type: 'uint256' },
|
|
2433
|
-
{ name: 'target', type: 'address' },
|
|
2434
|
-
{ name: 'fee', type: 'uint24' },
|
|
2435
|
-
{ name: 'minPCOut', type: 'uint256' },
|
|
2436
|
-
{ name: 'deadline', type: 'uint256' },
|
|
2437
|
-
],
|
|
2438
|
-
},
|
|
2439
|
-
],
|
|
2440
|
-
data: data,
|
|
2441
|
-
});
|
|
2442
|
-
if (decoded.args) {
|
|
2443
|
-
const target = decoded.args[2];
|
|
2444
|
-
to = (0, viem_1.getAddress)(target);
|
|
2445
|
-
from = '0x0000000000000000000000000000000000000000';
|
|
2446
|
-
}
|
|
2447
|
-
}
|
|
2448
|
-
catch (_b) {
|
|
2449
|
-
// Keep original values if decoding fails
|
|
2450
|
-
}
|
|
2451
|
-
}
|
|
2452
|
-
}
|
|
2453
2117
|
const origin = `${chain_1.VM_NAMESPACE[vm]}:${chainId}:${originAddress}`;
|
|
2454
2118
|
// Create signature from transaction r, s, v values
|
|
2455
2119
|
let signature;
|
|
@@ -2461,7 +2125,7 @@ class Orchestrator {
|
|
|
2461
2125
|
yParity: tx.yParity,
|
|
2462
2126
|
};
|
|
2463
2127
|
}
|
|
2464
|
-
catch (
|
|
2128
|
+
catch (_a) {
|
|
2465
2129
|
// Fallback signature if parsing fails
|
|
2466
2130
|
signature = {
|
|
2467
2131
|
r: '0x0000000000000000000000000000000000000000000000000000000000000000',
|
|
@@ -2492,8 +2156,6 @@ class Orchestrator {
|
|
|
2492
2156
|
typeVerbose = 'eip4844';
|
|
2493
2157
|
}
|
|
2494
2158
|
}
|
|
2495
|
-
// Storage for registered progress callback (used by progressHook method)
|
|
2496
|
-
let registeredProgressHook;
|
|
2497
2159
|
const universalTxResponse = {
|
|
2498
2160
|
// 1. Identity
|
|
2499
2161
|
hash: tx.hash,
|
|
@@ -2518,25 +2180,9 @@ class Orchestrator {
|
|
|
2518
2180
|
accessList: Array.isArray(tx.accessList) ? [...tx.accessList] : [],
|
|
2519
2181
|
// 6. Utilities
|
|
2520
2182
|
wait: () => tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
2521
|
-
// Use trackTransaction with registered hook if available
|
|
2522
|
-
if (registeredProgressHook) {
|
|
2523
|
-
return this.trackTransaction(tx.hash, {
|
|
2524
|
-
waitForCompletion: true,
|
|
2525
|
-
progress: registeredProgressHook,
|
|
2526
|
-
});
|
|
2527
|
-
}
|
|
2528
2183
|
const receipt = yield tx.wait();
|
|
2529
2184
|
return this.transformToUniversalTxReceipt(receipt, universalTxResponse);
|
|
2530
2185
|
}),
|
|
2531
|
-
progressHook: (callback) => {
|
|
2532
|
-
registeredProgressHook = callback;
|
|
2533
|
-
// Immediately replay buffered events from execution
|
|
2534
|
-
if (eventBuffer.length > 0) {
|
|
2535
|
-
for (const event of eventBuffer) {
|
|
2536
|
-
callback(event);
|
|
2537
|
-
}
|
|
2538
|
-
}
|
|
2539
|
-
},
|
|
2540
2186
|
// 7. Metadata
|
|
2541
2187
|
type,
|
|
2542
2188
|
typeVerbose,
|
|
@@ -2582,9 +2228,10 @@ class Orchestrator {
|
|
|
2582
2228
|
const hookEntry = progress_hook_1.default[hookId];
|
|
2583
2229
|
const hookPayload = hookEntry(...args);
|
|
2584
2230
|
this.printLog(hookPayload.message);
|
|
2585
|
-
if (this.progressHook)
|
|
2586
|
-
|
|
2587
|
-
|
|
2231
|
+
if (!this.progressHook)
|
|
2232
|
+
return;
|
|
2233
|
+
// invoke the user-provided callback
|
|
2234
|
+
this.progressHook(hookPayload);
|
|
2588
2235
|
}
|
|
2589
2236
|
// Derive the SVM gateway log index from a Solana transaction's log messages
|
|
2590
2237
|
getSvmGatewayLogIndexFromTx(txResp) {
|
|
@@ -2653,14 +2300,10 @@ class Orchestrator {
|
|
|
2653
2300
|
});
|
|
2654
2301
|
}
|
|
2655
2302
|
const gatewayLogs = (receipt.logs || []).filter((l) => (l.address || '').toLowerCase() === gatewayAddress.toLowerCase());
|
|
2656
|
-
|
|
2657
|
-
this.printLog('queryUniversalTxStatus — gatewayLogs: ' + JSON.stringify(gatewayLogs.map((l) => { var _a; return ({ address: l.address, logIndex: l.logIndex, topics: (_a = l.topics) === null || _a === void 0 ? void 0 : _a[0] }); }), null, 2));
|
|
2658
|
-
// TEMP: use last gateway log instead of hardcoded 0/1 index
|
|
2659
|
-
const logIndexToUse = gatewayLogs.length - 1;
|
|
2303
|
+
const logIndexToUse = evmGatewayMethod === 'sendTxWithFunds' ? 1 : 0;
|
|
2660
2304
|
const firstLog = (gatewayLogs[logIndexToUse] ||
|
|
2661
|
-
(receipt.logs || [])
|
|
2305
|
+
((_a = receipt.logs) === null || _a === void 0 ? void 0 : _a[logIndexToUse]));
|
|
2662
2306
|
const logIndexVal = (_b = firstLog === null || firstLog === void 0 ? void 0 : firstLog.logIndex) !== null && _b !== void 0 ? _b : 0;
|
|
2663
|
-
this.printLog(`queryUniversalTxStatus — logIndexToUse: ${logIndexToUse}, firstLog.logIndex: ${firstLog === null || firstLog === void 0 ? void 0 : firstLog.logIndex}, logIndexVal: ${logIndexVal}`);
|
|
2664
2307
|
logIndexStr =
|
|
2665
2308
|
typeof logIndexVal === 'bigint'
|
|
2666
2309
|
? logIndexVal.toString()
|
|
@@ -2694,21 +2337,9 @@ class Orchestrator {
|
|
|
2694
2337
|
// ID = sha256("${sourceChain}:${txHash}:${logIndex}") as hex string (no 0x)
|
|
2695
2338
|
const idInput = `${sourceChain}:${txHashHex}:${logIndexStr}`;
|
|
2696
2339
|
const idHex = (0, viem_1.sha256)((0, viem_1.stringToBytes)(idInput)).slice(2);
|
|
2697
|
-
|
|
2698
|
-
sourceChain,
|
|
2699
|
-
txHashHex,
|
|
2700
|
-
logIndexStr,
|
|
2701
|
-
idInput,
|
|
2702
|
-
idHex,
|
|
2703
|
-
}, null, 2));
|
|
2704
|
-
// Fetch UniversalTx via gRPC with linear-then-exponential retry
|
|
2705
|
-
const LINEAR_ATTEMPTS = 25;
|
|
2706
|
-
const LINEAR_DELAY_MS = 1500;
|
|
2707
|
-
const EXPONENTIAL_BASE_MS = 2000;
|
|
2708
|
-
const MAX_ATTEMPTS = 30;
|
|
2340
|
+
// Fetch UniversalTx via gRPC with a brief retry window
|
|
2709
2341
|
let universalTxObj;
|
|
2710
|
-
for (let attempt = 0; attempt <
|
|
2711
|
-
this.printLog(`[Sync] Attempt ${attempt + 1}/${MAX_ATTEMPTS} | Query ID: ${idHex}`);
|
|
2342
|
+
for (let attempt = 0; attempt < 15; attempt++) {
|
|
2712
2343
|
try {
|
|
2713
2344
|
const universalTxResp = yield this.pushClient.getUniversalTxById(idHex);
|
|
2714
2345
|
universalTxObj = universalTxResp === null || universalTxResp === void 0 ? void 0 : universalTxResp.universalTx;
|
|
@@ -2719,17 +2350,7 @@ class Orchestrator {
|
|
|
2719
2350
|
// ignore and retry
|
|
2720
2351
|
// console.log(error);
|
|
2721
2352
|
}
|
|
2722
|
-
|
|
2723
|
-
let delay;
|
|
2724
|
-
if (attempt < LINEAR_ATTEMPTS) {
|
|
2725
|
-
delay = LINEAR_DELAY_MS;
|
|
2726
|
-
}
|
|
2727
|
-
else {
|
|
2728
|
-
// Exponential: 2000, 4000, 8000, 16000, ...
|
|
2729
|
-
const exponentialAttempt = attempt - LINEAR_ATTEMPTS;
|
|
2730
|
-
delay = EXPONENTIAL_BASE_MS * Math.pow(2, exponentialAttempt);
|
|
2731
|
-
}
|
|
2732
|
-
yield new Promise((r) => setTimeout(r, delay));
|
|
2353
|
+
yield new Promise((r) => setTimeout(r, 1500));
|
|
2733
2354
|
}
|
|
2734
2355
|
return universalTxObj;
|
|
2735
2356
|
}
|
|
@@ -2741,11 +2362,6 @@ class Orchestrator {
|
|
|
2741
2362
|
// Emit countdown updates while waiting for EVM confirmations
|
|
2742
2363
|
waitForEvmConfirmationsWithCountdown(evmClient, txHash, confirmations, timeoutMs) {
|
|
2743
2364
|
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
2744
|
-
// Skip waiting if zero confirmations requested
|
|
2745
|
-
if (confirmations <= 0) {
|
|
2746
|
-
this.executeProgressHook(progress_hook_types_1.PROGRESS_HOOK.SEND_TX_06_03_02, 0, 0);
|
|
2747
|
-
return;
|
|
2748
|
-
}
|
|
2749
2365
|
// initial emit
|
|
2750
2366
|
this.executeProgressHook(progress_hook_types_1.PROGRESS_HOOK.SEND_TX_06_03, confirmations);
|
|
2751
2367
|
const start = Date.now();
|
|
@@ -2791,11 +2407,6 @@ class Orchestrator {
|
|
|
2791
2407
|
// Emit countdown updates while waiting for SVM confirmations
|
|
2792
2408
|
waitForSvmConfirmationsWithCountdown(svmClient, txSignature, confirmations, timeoutMs) {
|
|
2793
2409
|
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
2794
|
-
// Skip waiting if zero confirmations requested
|
|
2795
|
-
if (confirmations <= 0) {
|
|
2796
|
-
this.executeProgressHook(progress_hook_types_1.PROGRESS_HOOK.SEND_TX_06_03_02, 0, 0);
|
|
2797
|
-
return;
|
|
2798
|
-
}
|
|
2799
2410
|
// initial emit
|
|
2800
2411
|
this.executeProgressHook(progress_hook_types_1.PROGRESS_HOOK.SEND_TX_06_03, confirmations);
|
|
2801
2412
|
const start = Date.now();
|
|
@@ -2916,8 +2527,8 @@ class Orchestrator {
|
|
|
2916
2527
|
var _a, _b;
|
|
2917
2528
|
this.executeProgressHook(progress_hook_types_1.PROGRESS_HOOK.SEND_TX_02_01);
|
|
2918
2529
|
// Determine USD to deposit via gateway (8 decimals) with caps: min=$1, max=$10
|
|
2919
|
-
const oneUsd =
|
|
2920
|
-
const tenUsd =
|
|
2530
|
+
const oneUsd = push_chain_1.PushChain.utils.helpers.parseUnits('1', 8);
|
|
2531
|
+
const tenUsd = push_chain_1.PushChain.utils.helpers.parseUnits('10', 8);
|
|
2921
2532
|
const deficit = requiredFunds > ueaBalance ? requiredFunds - ueaBalance : BigInt(0);
|
|
2922
2533
|
let depositUsd = deficit > BigInt(0) ? this.pushClient.pushToUSDC(deficit) : oneUsd;
|
|
2923
2534
|
if (depositUsd < oneUsd)
|
|
@@ -2959,7 +2570,7 @@ class Orchestrator {
|
|
|
2959
2570
|
// Convert USD(8) -> native units using pricing path
|
|
2960
2571
|
const nativeTokenUsdPrice = yield new price_fetch_1.PriceFetch(this.rpcUrls).getPrice(chain); // 8 decimals
|
|
2961
2572
|
const nativeDecimals = chain_1.CHAIN_INFO[chain].vm === enums_1.VM.SVM ? 9 : 18;
|
|
2962
|
-
const oneNativeUnit =
|
|
2573
|
+
const oneNativeUnit = push_chain_1.PushChain.utils.helpers.parseUnits('1', nativeDecimals);
|
|
2963
2574
|
// Ceil division to avoid rounding below min USD on-chain
|
|
2964
2575
|
let nativeAmount = (depositUsd * oneNativeUnit + (nativeTokenUsdPrice - BigInt(1))) /
|
|
2965
2576
|
nativeTokenUsdPrice;
|