@pushchain/core 4.0.11 → 4.0.12-alpha.1
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/chain.d.ts +1 -1
- package/src/lib/constants/chain.js +27 -8
- package/src/lib/constants/chain.js.map +1 -1
- package/src/lib/constants/tokens.d.ts +7 -1
- package/src/lib/constants/tokens.js +50 -8
- package/src/lib/constants/tokens.js.map +1 -1
- package/src/lib/orchestrator/orchestrator.js +209 -80
- package/src/lib/orchestrator/orchestrator.js.map +1 -1
- package/src/lib/orchestrator/orchestrator.types.d.ts +6 -0
- package/src/lib/orchestrator/payload-builders.d.ts +2 -1
- package/src/lib/orchestrator/payload-builders.js +38 -6
- package/src/lib/orchestrator/payload-builders.js.map +1 -1
- package/src/lib/push-client/push-client.d.ts +9 -3
- package/src/lib/push-client/push-client.js +98 -61
- package/src/lib/push-client/push-client.js.map +1 -1
|
@@ -64,7 +64,16 @@ class Orchestrator {
|
|
|
64
64
|
*/
|
|
65
65
|
execute(execute) {
|
|
66
66
|
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
67
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o;
|
|
67
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p;
|
|
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
|
+
};
|
|
68
77
|
try {
|
|
69
78
|
if (execute.funds) {
|
|
70
79
|
if (!execute.data || execute.data === '0x') {
|
|
@@ -114,12 +123,25 @@ class Orchestrator {
|
|
|
114
123
|
const { nonce, deployed } = yield this.getUeaStatusAndNonce();
|
|
115
124
|
const { payload: universalPayload, req } = yield this.buildGatewayPayloadAndGas(execute, nonce, 'sendFunds', bridgeAmount);
|
|
116
125
|
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));
|
|
117
137
|
// Compute minimal native amount to deposit for gas on Push Chain
|
|
118
138
|
const ueaBalanceForGas = yield this.pushClient.getBalance(ueaAddress);
|
|
119
139
|
const nativeAmount = yield this.calculateNativeAmountForDeposit(chain, BigInt(0), ueaBalanceForGas);
|
|
140
|
+
this.printLog(`sendFunds — nativeAmount: ${nativeAmount.toString()}, ueaBalanceForGas: ${ueaBalanceForGas.toString()}`);
|
|
120
141
|
// We log the SEND_TX_03_01 here because the progress hook for gas estimation should arrive before the resolving of UEA.
|
|
121
142
|
this.executeProgressHook(progress_hook_types_1.PROGRESS_HOOK.SEND_TX_03_01);
|
|
122
143
|
this.executeProgressHook(progress_hook_types_1.PROGRESS_HOOK.SEND_TX_03_02, ueaAddress, deployed);
|
|
144
|
+
this.printLog(`UEA resolved: ${ueaAddress}, deployed: ${deployed}`);
|
|
123
145
|
this.executeProgressHook(progress_hook_types_1.PROGRESS_HOOK.SEND_TX_06_01, amount, execute.funds.token.decimals, symbol);
|
|
124
146
|
if (vm === enums_1.VM.EVM) {
|
|
125
147
|
const evmClient = new evm_client_1.EvmClient({ rpcUrls });
|
|
@@ -158,13 +180,19 @@ class Orchestrator {
|
|
|
158
180
|
// revertInstruction: revertCFG,
|
|
159
181
|
// signatureData: '0x',
|
|
160
182
|
// } 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));
|
|
161
189
|
txHash = yield evmClient.writeContract({
|
|
162
190
|
abi: abi_1.UNIVERSAL_GATEWAY_V0,
|
|
163
191
|
address: gatewayAddress,
|
|
164
192
|
functionName: 'sendUniversalTx',
|
|
165
193
|
args: [req],
|
|
166
194
|
signer: this.universalSigner,
|
|
167
|
-
value: isNative ? bridgeAmount : nativeAmount,
|
|
195
|
+
value: isNative ? nativeAmount + bridgeAmount : nativeAmount,
|
|
168
196
|
});
|
|
169
197
|
}
|
|
170
198
|
else {
|
|
@@ -180,13 +208,19 @@ class Orchestrator {
|
|
|
180
208
|
// revertInstruction: revertCFG,
|
|
181
209
|
// signatureData: '0x',
|
|
182
210
|
// } 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));
|
|
183
217
|
txHash = yield evmClient.writeContract({
|
|
184
218
|
abi: abi_1.UNIVERSAL_GATEWAY_V0,
|
|
185
219
|
address: gatewayAddress,
|
|
186
220
|
functionName: 'sendUniversalTx',
|
|
187
221
|
args: [req],
|
|
188
222
|
signer: this.universalSigner,
|
|
189
|
-
value: nativeAmount,
|
|
223
|
+
value: isNative ? nativeAmount + bridgeAmount : nativeAmount,
|
|
190
224
|
});
|
|
191
225
|
}
|
|
192
226
|
}
|
|
@@ -201,6 +235,10 @@ class Orchestrator {
|
|
|
201
235
|
this.executeProgressHook(progress_hook_types_1.PROGRESS_HOOK.SEND_TX_06_04);
|
|
202
236
|
// Syncing with Push Chain - emit before query
|
|
203
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
|
+
}));
|
|
204
242
|
const pushChainUniversalTx = yield this.queryUniversalTxStatusFromGatewayTx(evmClient, gatewayAddress, txHash, execute.to === ueaAddress ? 'sendFunds' : 'sendTxWithFunds');
|
|
205
243
|
if (!((_a = pushChainUniversalTx === null || pushChainUniversalTx === void 0 ? void 0 : pushChainUniversalTx.pcTx) === null || _a === void 0 ? void 0 : _a.length)) {
|
|
206
244
|
throw new Error(`Failed to retrieve Push Chain transaction status for gateway tx: ${txHash}. ` +
|
|
@@ -209,6 +247,8 @@ class Orchestrator {
|
|
|
209
247
|
// For sendFunds operations, MintPC (first) succeeds and executePayload (second) may fail
|
|
210
248
|
// Always use the last pcTx entry as it represents the final execution result
|
|
211
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));
|
|
212
252
|
if (!(lastPcTransaction === null || lastPcTransaction === void 0 ? void 0 : lastPcTransaction.txHash)) {
|
|
213
253
|
// Check for error messages in failed entries
|
|
214
254
|
const failedPcTx = pushChainUniversalTx.pcTx.find((pcTx) => pcTx.status === 'FAILED' && pcTx.errorMsg);
|
|
@@ -218,7 +258,7 @@ class Orchestrator {
|
|
|
218
258
|
throw new Error(`No transaction hash found in Push Chain response for gateway tx: ${txHash}${errorDetails}`);
|
|
219
259
|
}
|
|
220
260
|
const tx = yield this.pushClient.getTransaction(lastPcTransaction.txHash);
|
|
221
|
-
const response = yield this.transformToUniversalTxResponse(tx);
|
|
261
|
+
const response = yield this.transformToUniversalTxResponse(tx, eventBuffer);
|
|
222
262
|
// Funds Flow: Funds credited on Push Chain
|
|
223
263
|
this.executeProgressHook(progress_hook_types_1.PROGRESS_HOOK.SEND_TX_06_06, bridgeAmount, execute.funds.token.decimals, symbol);
|
|
224
264
|
this.executeProgressHook(progress_hook_types_1.PROGRESS_HOOK.SEND_TX_99_01, [response]);
|
|
@@ -371,7 +411,7 @@ class Orchestrator {
|
|
|
371
411
|
this.executeProgressHook(progress_hook_types_1.PROGRESS_HOOK.SEND_TX_06_05);
|
|
372
412
|
// After origin confirmations, query Push Chain for UniversalTx status (SVM)
|
|
373
413
|
const pushChainUniversalTx = yield this.queryUniversalTxStatusFromGatewayTx(undefined, undefined, txSignature, 'sendFunds');
|
|
374
|
-
if (!((
|
|
414
|
+
if (!((_c = pushChainUniversalTx === null || pushChainUniversalTx === void 0 ? void 0 : pushChainUniversalTx.pcTx) === null || _c === void 0 ? void 0 : _c.length)) {
|
|
375
415
|
throw new Error(`Failed to retrieve Push Chain transaction status for gateway tx: ${txSignature}. ` +
|
|
376
416
|
`The transaction may have failed on Push Chain or not been indexed yet.`);
|
|
377
417
|
}
|
|
@@ -385,7 +425,7 @@ class Orchestrator {
|
|
|
385
425
|
throw new Error(`No transaction hash found in Push Chain response for gateway tx: ${txSignature}${errorDetails}`);
|
|
386
426
|
}
|
|
387
427
|
const tx = yield this.pushClient.getTransaction(lastPcTransaction.txHash);
|
|
388
|
-
const response = yield this.transformToUniversalTxResponse(tx);
|
|
428
|
+
const response = yield this.transformToUniversalTxResponse(tx, eventBuffer);
|
|
389
429
|
// Funds Flow: Funds credited on Push Chain
|
|
390
430
|
this.executeProgressHook(progress_hook_types_1.PROGRESS_HOOK.SEND_TX_06_06, bridgeAmount, execute.funds.token.decimals, symbol);
|
|
391
431
|
this.executeProgressHook(progress_hook_types_1.PROGRESS_HOOK.SEND_TX_99_01, [response]);
|
|
@@ -419,7 +459,7 @@ class Orchestrator {
|
|
|
419
459
|
const gasEstimate = execute.gasLimit || BigInt(1e7);
|
|
420
460
|
const gasPrice = yield this.pushClient.getGasPrice();
|
|
421
461
|
const requiredGasFee = gasEstimate * gasPrice;
|
|
422
|
-
const payloadValue = (
|
|
462
|
+
const payloadValue = (_d = execute.value) !== null && _d !== void 0 ? _d : BigInt(0);
|
|
423
463
|
const requiredFunds = requiredGasFee + payloadValue;
|
|
424
464
|
const ueaAddress = this.computeUEAOffchain();
|
|
425
465
|
const [ueaBalance] = yield Promise.all([
|
|
@@ -452,8 +492,8 @@ class Orchestrator {
|
|
|
452
492
|
functionName: 'config',
|
|
453
493
|
args: [configPda.toBase58()],
|
|
454
494
|
});
|
|
455
|
-
const minField = (
|
|
456
|
-
const maxField = (
|
|
495
|
+
const minField = (_e = cfg.minCapUniversalTxUsd) !== null && _e !== void 0 ? _e : cfg.min_cap_universal_tx_usd;
|
|
496
|
+
const maxField = (_f = cfg.maxCapUniversalTxUsd) !== null && _f !== void 0 ? _f : cfg.max_cap_universal_tx_usd;
|
|
457
497
|
const minCapUsd = BigInt(minField.toString());
|
|
458
498
|
const maxCapUsd = BigInt(maxField.toString());
|
|
459
499
|
if (depositUsd < minCapUsd)
|
|
@@ -465,7 +505,7 @@ class Orchestrator {
|
|
|
465
505
|
if (depositUsd > maxCapUsd)
|
|
466
506
|
depositUsd = maxCapUsd;
|
|
467
507
|
}
|
|
468
|
-
catch (
|
|
508
|
+
catch (_q) {
|
|
469
509
|
// best-effort; fallback to previous bounds if read fails
|
|
470
510
|
}
|
|
471
511
|
}
|
|
@@ -516,7 +556,7 @@ class Orchestrator {
|
|
|
516
556
|
// New behavior: if user provided a gasTokenAddress, pay gas in that token via Uniswap quote
|
|
517
557
|
// Determine pay-with token address, min-out and slippage
|
|
518
558
|
const payWith = execute.payGasWith;
|
|
519
|
-
const gasTokenAddress = (
|
|
559
|
+
const gasTokenAddress = (_g = payWith === null || payWith === void 0 ? void 0 : payWith.token) === null || _g === void 0 ? void 0 : _g.address;
|
|
520
560
|
if (gasTokenAddress) {
|
|
521
561
|
if (chain !== enums_1.CHAIN.ETHEREUM_SEPOLIA) {
|
|
522
562
|
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`);
|
|
@@ -524,7 +564,7 @@ class Orchestrator {
|
|
|
524
564
|
let amountOutMinETH = (payWith === null || payWith === void 0 ? void 0 : payWith.minAmountOut) !== undefined
|
|
525
565
|
? BigInt(payWith.minAmountOut)
|
|
526
566
|
: nativeAmount;
|
|
527
|
-
const slippageBps = (
|
|
567
|
+
const slippageBps = (_h = payWith === null || payWith === void 0 ? void 0 : payWith.slippageBps) !== null && _h !== void 0 ? _h : 100;
|
|
528
568
|
amountOutMinETH = BigInt(push_chain_1.PushChain.utils.conversion.slippageToMinAmount(amountOutMinETH.toString(), { slippageBps }));
|
|
529
569
|
const { gasAmount } = yield this.calculateGasAmountFromAmountOutMinETH(gasTokenAddress, amountOutMinETH);
|
|
530
570
|
const deadline = BigInt(0);
|
|
@@ -536,8 +576,8 @@ class Orchestrator {
|
|
|
536
576
|
ownerAddress,
|
|
537
577
|
});
|
|
538
578
|
if (gasTokenBalance < gasAmount) {
|
|
539
|
-
const sym = (
|
|
540
|
-
const decimals = (
|
|
579
|
+
const sym = (_k = (_j = payWith === null || payWith === void 0 ? void 0 : payWith.token) === null || _j === void 0 ? void 0 : _j.symbol) !== null && _k !== void 0 ? _k : 'gas token';
|
|
580
|
+
const decimals = (_m = (_l = payWith === null || payWith === void 0 ? void 0 : payWith.token) === null || _l === void 0 ? void 0 : _l.decimals) !== null && _m !== void 0 ? _m : 18;
|
|
541
581
|
const needFmt = utils_1.Utils.helpers.formatUnits(gasAmount, decimals);
|
|
542
582
|
const haveFmt = utils_1.Utils.helpers.formatUnits(gasTokenBalance, decimals);
|
|
543
583
|
throw new Error(`Insufficient ${sym} balance to cover gas fees: need ${needFmt}, have ${haveFmt}`);
|
|
@@ -665,7 +705,7 @@ class Orchestrator {
|
|
|
665
705
|
pushChainUniversalTx =
|
|
666
706
|
yield this.queryUniversalTxStatusFromGatewayTx(undefined, undefined, txHash, 'sendTxWithFunds');
|
|
667
707
|
}
|
|
668
|
-
if (!((
|
|
708
|
+
if (!((_o = pushChainUniversalTx === null || pushChainUniversalTx === void 0 ? void 0 : pushChainUniversalTx.pcTx) === null || _o === void 0 ? void 0 : _o.length)) {
|
|
669
709
|
throw new Error(`Failed to retrieve Push Chain transaction status for gateway tx: ${txHash}. ` +
|
|
670
710
|
`The transaction may have failed on Push Chain or not been indexed yet.`);
|
|
671
711
|
}
|
|
@@ -679,7 +719,7 @@ class Orchestrator {
|
|
|
679
719
|
throw new Error(`No transaction hash found in Push Chain response for gateway tx: ${txHash}${errorDetails}`);
|
|
680
720
|
}
|
|
681
721
|
const tx = yield this.pushClient.getTransaction(lastPcTransaction.txHash);
|
|
682
|
-
const response = yield this.transformToUniversalTxResponse(tx);
|
|
722
|
+
const response = yield this.transformToUniversalTxResponse(tx, eventBuffer);
|
|
683
723
|
// Funds Flow: Funds credited on Push Chain
|
|
684
724
|
this.executeProgressHook(progress_hook_types_1.PROGRESS_HOOK.SEND_TX_06_06, bridgeAmount, execute.funds.token.decimals, symbol);
|
|
685
725
|
this.executeProgressHook(progress_hook_types_1.PROGRESS_HOOK.SEND_TX_99_01, [response]);
|
|
@@ -698,7 +738,7 @@ class Orchestrator {
|
|
|
698
738
|
*/
|
|
699
739
|
if (this.isPushChain(chain)) {
|
|
700
740
|
this.executeProgressHook(progress_hook_types_1.PROGRESS_HOOK.SEND_TX_07);
|
|
701
|
-
const tx = yield this.sendPushTx(execute);
|
|
741
|
+
const tx = yield this.sendPushTx(execute, eventBuffer);
|
|
702
742
|
this.executeProgressHook(progress_hook_types_1.PROGRESS_HOOK.SEND_TX_99_01, [tx]);
|
|
703
743
|
return tx;
|
|
704
744
|
}
|
|
@@ -747,7 +787,7 @@ class Orchestrator {
|
|
|
747
787
|
// execute.to = zeroAddress;
|
|
748
788
|
payloadTo = viem_1.zeroAddress;
|
|
749
789
|
console.warn(`Multicalls should have execute.to as ${viem_1.zeroAddress}`);
|
|
750
|
-
payloadData = this._buildMulticallPayloadData(execute.to, (0, payload_builders_1.buildExecuteMulticall)({ execute, ueaAddress: UEA }));
|
|
790
|
+
payloadData = this._buildMulticallPayloadData(execute.to, (0, payload_builders_1.buildExecuteMulticall)({ execute, ueaAddress: UEA, logger: this.printLog.bind(this) }));
|
|
751
791
|
req = this._buildUniversalTxRequest({
|
|
752
792
|
recipient: viem_1.zeroAddress,
|
|
753
793
|
token: viem_1.zeroAddress,
|
|
@@ -763,7 +803,7 @@ class Orchestrator {
|
|
|
763
803
|
// TODO: Check but I beleive this code section is never reached.
|
|
764
804
|
if (execute.funds) {
|
|
765
805
|
payloadTo = viem_1.zeroAddress;
|
|
766
|
-
payloadData = this._buildMulticallPayloadData(execute.to, (0, payload_builders_1.buildExecuteMulticall)({ execute, ueaAddress: UEA }));
|
|
806
|
+
payloadData = this._buildMulticallPayloadData(execute.to, (0, payload_builders_1.buildExecuteMulticall)({ execute, ueaAddress: UEA, logger: this.printLog.bind(this) }));
|
|
767
807
|
req = this._buildUniversalTxRequest({
|
|
768
808
|
recipient: viem_1.zeroAddress,
|
|
769
809
|
token: viem_1.zeroAddress,
|
|
@@ -776,7 +816,7 @@ class Orchestrator {
|
|
|
776
816
|
// VALUE + PAYLOAD ONLY OTHER
|
|
777
817
|
payloadTo = execute.to;
|
|
778
818
|
payloadData = execute.data || '0x';
|
|
779
|
-
const reqData = this._buildMulticallPayloadData(execute.to, (0, payload_builders_1.buildExecuteMulticall)({ execute, ueaAddress: UEA }));
|
|
819
|
+
const reqData = this._buildMulticallPayloadData(execute.to, (0, payload_builders_1.buildExecuteMulticall)({ execute, ueaAddress: UEA, logger: this.printLog.bind(this) }));
|
|
780
820
|
const universalPayload = JSON.parse(JSON.stringify({
|
|
781
821
|
to: viem_1.zeroAddress,
|
|
782
822
|
value: execute.value,
|
|
@@ -878,7 +918,7 @@ class Orchestrator {
|
|
|
878
918
|
* Note: queryTx may be undefined since validators don't recognize new UniversalTx event yet
|
|
879
919
|
*/
|
|
880
920
|
// Transform to UniversalTxResponse (follow sendFunds pattern)
|
|
881
|
-
if (!((
|
|
921
|
+
if (!((_p = pushChainUniversalTx === null || pushChainUniversalTx === void 0 ? void 0 : pushChainUniversalTx.pcTx) === null || _p === void 0 ? void 0 : _p.length)) {
|
|
882
922
|
throw new Error(`Failed to retrieve Push Chain transaction status for gateway tx: ${feeLockTxHash}. ` +
|
|
883
923
|
`The transaction may have failed on Push Chain or not been indexed yet.`);
|
|
884
924
|
}
|
|
@@ -892,7 +932,7 @@ class Orchestrator {
|
|
|
892
932
|
throw new Error(`No transaction hash found in Push Chain response for gateway tx: ${feeLockTxHash}${errorDetails}`);
|
|
893
933
|
}
|
|
894
934
|
const tx = yield this.pushClient.getTransaction(lastPcTransaction.txHash);
|
|
895
|
-
const response = yield this.transformToUniversalTxResponse(tx);
|
|
935
|
+
const response = yield this.transformToUniversalTxResponse(tx, eventBuffer);
|
|
896
936
|
this.executeProgressHook(progress_hook_types_1.PROGRESS_HOOK.SEND_TX_99_01, [response]);
|
|
897
937
|
return response;
|
|
898
938
|
}
|
|
@@ -901,7 +941,7 @@ class Orchestrator {
|
|
|
901
941
|
*/
|
|
902
942
|
this.executeProgressHook(progress_hook_types_1.PROGRESS_HOOK.SEND_TX_07);
|
|
903
943
|
// We don't need to query via gRPC the PC transaction since it's getting returned it here already.
|
|
904
|
-
const transactions = yield this.sendUniversalTx(isUEADeployed, feeLockTxHash, universalPayload, verificationData);
|
|
944
|
+
const transactions = yield this.sendUniversalTx(isUEADeployed, feeLockTxHash, universalPayload, verificationData, eventBuffer);
|
|
905
945
|
this.executeProgressHook(progress_hook_types_1.PROGRESS_HOOK.SEND_TX_99_01, transactions);
|
|
906
946
|
return transactions[transactions.length - 1];
|
|
907
947
|
}
|
|
@@ -921,6 +961,10 @@ class Orchestrator {
|
|
|
921
961
|
this.executeProgressHook(progress_hook_types_1.PROGRESS_HOOK.SEND_TX_99_02, errMessage);
|
|
922
962
|
throw err;
|
|
923
963
|
}
|
|
964
|
+
finally {
|
|
965
|
+
// Restore original progressHook
|
|
966
|
+
this.progressHook = originalHook;
|
|
967
|
+
}
|
|
924
968
|
});
|
|
925
969
|
}
|
|
926
970
|
/**
|
|
@@ -1187,8 +1231,8 @@ class Orchestrator {
|
|
|
1187
1231
|
/**
|
|
1188
1232
|
* Sends a custom Cosmos tx to Push Chain (gasless) to execute user intent.
|
|
1189
1233
|
*/
|
|
1190
|
-
sendUniversalTx(
|
|
1191
|
-
return tslib_1.__awaiter(this,
|
|
1234
|
+
sendUniversalTx(isUEADeployed_1, feeLockTxHash_1, universalPayload_1, verificationData_1) {
|
|
1235
|
+
return tslib_1.__awaiter(this, arguments, void 0, function* (isUEADeployed, feeLockTxHash, universalPayload, verificationData, eventBuffer = []) {
|
|
1192
1236
|
var _a, _b;
|
|
1193
1237
|
const { chain, address } = this.universalSigner.account;
|
|
1194
1238
|
const { vm, chainId } = chain_1.CHAIN_INFO[chain];
|
|
@@ -1249,7 +1293,8 @@ class Orchestrator {
|
|
|
1249
1293
|
const evmTxs = yield Promise.all(ethTxHashes.map((hash) => tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
1250
1294
|
return yield this.pushClient.getTransaction(hash);
|
|
1251
1295
|
})));
|
|
1252
|
-
|
|
1296
|
+
// Pass eventBuffer only to the last transaction (which is the one returned to user)
|
|
1297
|
+
return yield Promise.all(evmTxs.map((tx, index) => this.transformToUniversalTxResponse(tx, index === evmTxs.length - 1 ? eventBuffer : [])));
|
|
1253
1298
|
});
|
|
1254
1299
|
}
|
|
1255
1300
|
/**
|
|
@@ -1258,8 +1303,8 @@ class Orchestrator {
|
|
|
1258
1303
|
* @param execute
|
|
1259
1304
|
* @returns Cosmos Tx Response for a given Evm Tx
|
|
1260
1305
|
*/
|
|
1261
|
-
sendPushTx(
|
|
1262
|
-
return tslib_1.__awaiter(this,
|
|
1306
|
+
sendPushTx(execute_1) {
|
|
1307
|
+
return tslib_1.__awaiter(this, arguments, void 0, function* (execute, eventBuffer = []) {
|
|
1263
1308
|
// For PushChain, multicall is not supported. Ensure data is hex string.
|
|
1264
1309
|
if (Array.isArray(execute.data)) {
|
|
1265
1310
|
throw new Error('Multicall is not supported on PushChain');
|
|
@@ -1271,7 +1316,7 @@ class Orchestrator {
|
|
|
1271
1316
|
signer: this.universalSigner,
|
|
1272
1317
|
});
|
|
1273
1318
|
const txResponse = yield this.pushClient.getTransaction(txHash);
|
|
1274
|
-
return yield this.transformToUniversalTxResponse(txResponse);
|
|
1319
|
+
return yield this.transformToUniversalTxResponse(txResponse, eventBuffer);
|
|
1275
1320
|
});
|
|
1276
1321
|
}
|
|
1277
1322
|
/**
|
|
@@ -1456,13 +1501,22 @@ class Orchestrator {
|
|
|
1456
1501
|
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
1457
1502
|
const { chain = this.getPushChainForNetwork(), progress, waitForCompletion = true, advanced = {}, } = options !== null && options !== void 0 ? options : {};
|
|
1458
1503
|
const { pollingIntervalMs = 1000, timeout = 300000, rpcUrls = {}, } = advanced;
|
|
1459
|
-
//
|
|
1460
|
-
const
|
|
1504
|
+
// Helper to invoke both per-transaction and orchestrator hooks
|
|
1505
|
+
const invokeProgressHook = (hookPayload) => {
|
|
1506
|
+
this.printLog(hookPayload.message);
|
|
1507
|
+
// Per-transaction hook called FIRST
|
|
1508
|
+
if (progress) {
|
|
1509
|
+
progress(hookPayload);
|
|
1510
|
+
}
|
|
1511
|
+
// Orchestrator-level hook called SECOND
|
|
1512
|
+
if (this.progressHook) {
|
|
1513
|
+
this.progressHook(hookPayload);
|
|
1514
|
+
}
|
|
1515
|
+
};
|
|
1461
1516
|
// Emit TRACK_TX_01 - tracking started
|
|
1462
|
-
if (
|
|
1517
|
+
if (progress || this.progressHook) {
|
|
1463
1518
|
const hookPayload = progress_hook_1.default[progress_hook_types_1.PROGRESS_HOOK.TRACK_TX_01](txHash, chain);
|
|
1464
|
-
|
|
1465
|
-
progressHookFn(hookPayload);
|
|
1519
|
+
invokeProgressHook(hookPayload);
|
|
1466
1520
|
}
|
|
1467
1521
|
// Create client for target chain with optional RPC override
|
|
1468
1522
|
const chainRPCs = rpcUrls[chain] || this.rpcUrls[chain] || chain_1.CHAIN_INFO[chain].defaultRPC;
|
|
@@ -1483,10 +1537,9 @@ class Orchestrator {
|
|
|
1483
1537
|
const receipt = yield tx.wait(1);
|
|
1484
1538
|
const universalTxResponse = yield this.transformToUniversalTxResponse(tx);
|
|
1485
1539
|
// Emit TRACK_TX_99_01 - tracking complete
|
|
1486
|
-
if (
|
|
1540
|
+
if (progress || this.progressHook) {
|
|
1487
1541
|
const hookPayload = progress_hook_1.default[progress_hook_types_1.PROGRESS_HOOK.TRACK_TX_99_01](txHash, universalTxResponse);
|
|
1488
|
-
|
|
1489
|
-
progressHookFn(hookPayload);
|
|
1542
|
+
invokeProgressHook(hookPayload);
|
|
1490
1543
|
}
|
|
1491
1544
|
return this.transformToUniversalTxReceipt(receipt, universalTxResponse);
|
|
1492
1545
|
}
|
|
@@ -1495,31 +1548,29 @@ class Orchestrator {
|
|
|
1495
1548
|
if (!waitForCompletion) {
|
|
1496
1549
|
// Non-blocking and tx not found - throw error
|
|
1497
1550
|
const errorMsg = initialError instanceof Error ? initialError.message : 'Transaction not found';
|
|
1498
|
-
if (
|
|
1551
|
+
if (progress || this.progressHook) {
|
|
1499
1552
|
const hookPayload = progress_hook_1.default[progress_hook_types_1.PROGRESS_HOOK.TRACK_TX_99_02](txHash, errorMsg);
|
|
1500
|
-
|
|
1501
|
-
progressHookFn(hookPayload);
|
|
1553
|
+
invokeProgressHook(hookPayload);
|
|
1502
1554
|
}
|
|
1503
1555
|
throw new Error(`Transaction ${txHash} not found: ${errorMsg}`);
|
|
1504
1556
|
}
|
|
1505
1557
|
// Blocking mode: poll until found or timeout
|
|
1506
1558
|
const start = Date.now();
|
|
1559
|
+
// eslint-disable-next-line no-constant-condition
|
|
1507
1560
|
while (true) {
|
|
1508
1561
|
// Emit TRACK_TX_02 - querying status
|
|
1509
|
-
if (
|
|
1562
|
+
if (progress || this.progressHook) {
|
|
1510
1563
|
const hookPayload = progress_hook_1.default[progress_hook_types_1.PROGRESS_HOOK.TRACK_TX_02](txHash);
|
|
1511
|
-
|
|
1512
|
-
progressHookFn(hookPayload);
|
|
1564
|
+
invokeProgressHook(hookPayload);
|
|
1513
1565
|
}
|
|
1514
1566
|
try {
|
|
1515
1567
|
const tx = yield client.getTransaction(txHash);
|
|
1516
1568
|
const receipt = yield tx.wait(1);
|
|
1517
1569
|
const universalTxResponse = yield this.transformToUniversalTxResponse(tx);
|
|
1518
1570
|
// Success - emit TRACK_TX_99_01
|
|
1519
|
-
if (
|
|
1571
|
+
if (progress || this.progressHook) {
|
|
1520
1572
|
const hookPayload = progress_hook_1.default[progress_hook_types_1.PROGRESS_HOOK.TRACK_TX_99_01](txHash, universalTxResponse);
|
|
1521
|
-
|
|
1522
|
-
progressHookFn(hookPayload);
|
|
1573
|
+
invokeProgressHook(hookPayload);
|
|
1523
1574
|
}
|
|
1524
1575
|
return this.transformToUniversalTxReceipt(receipt, universalTxResponse);
|
|
1525
1576
|
}
|
|
@@ -1530,10 +1581,9 @@ class Orchestrator {
|
|
|
1530
1581
|
// Check timeout
|
|
1531
1582
|
if (Date.now() - start > timeout) {
|
|
1532
1583
|
const timeoutMsg = `Timeout: transaction ${txHash} not confirmed within ${timeout}ms`;
|
|
1533
|
-
if (
|
|
1584
|
+
if (progress || this.progressHook) {
|
|
1534
1585
|
const hookPayload = progress_hook_1.default[progress_hook_types_1.PROGRESS_HOOK.TRACK_TX_99_02](txHash, 'Timeout');
|
|
1535
|
-
|
|
1536
|
-
progressHookFn(hookPayload);
|
|
1586
|
+
invokeProgressHook(hookPayload);
|
|
1537
1587
|
}
|
|
1538
1588
|
throw new Error(timeoutMsg);
|
|
1539
1589
|
}
|
|
@@ -1600,6 +1650,7 @@ class Orchestrator {
|
|
|
1600
1650
|
});
|
|
1601
1651
|
}
|
|
1602
1652
|
_buildMulticallPayloadData(to, data) {
|
|
1653
|
+
this.printLog('_buildMulticallPayloadData — input: ' + data.length + ' calls: ' + JSON.stringify(data, (_, v) => typeof v === 'bigint' ? v.toString() : v, 2));
|
|
1603
1654
|
const allowedChains = [
|
|
1604
1655
|
enums_1.CHAIN.ETHEREUM_SEPOLIA,
|
|
1605
1656
|
enums_1.CHAIN.ARBITRUM_SEPOLIA,
|
|
@@ -2110,7 +2161,7 @@ class Orchestrator {
|
|
|
2110
2161
|
*/
|
|
2111
2162
|
buildGatewayPayloadAndGas(execute, nonce, type, fundsValue) {
|
|
2112
2163
|
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
2113
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q;
|
|
2164
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _0, _1, _2, _3, _4, _5, _6;
|
|
2114
2165
|
const gasEstimate = execute.gasLimit || BigInt(1e7);
|
|
2115
2166
|
const gasAmount = (_a = execute.value) !== null && _a !== void 0 ? _a : BigInt(0);
|
|
2116
2167
|
if (type === 'sendTxWithFunds') {
|
|
@@ -2119,6 +2170,7 @@ class Orchestrator {
|
|
|
2119
2170
|
const multicallData = (0, payload_builders_1.buildExecuteMulticall)({
|
|
2120
2171
|
execute,
|
|
2121
2172
|
ueaAddress: this.computeUEAOffchain(),
|
|
2173
|
+
logger: this.printLog.bind(this),
|
|
2122
2174
|
});
|
|
2123
2175
|
// THIS ABOVE WILL CHANGE WHEN FUNDS ARE PASSED
|
|
2124
2176
|
const universalPayload = {
|
|
@@ -2133,6 +2185,7 @@ class Orchestrator {
|
|
|
2133
2185
|
deadline: execute.deadline || BigInt(9999999999),
|
|
2134
2186
|
vType: tx_1.VerificationType.universalTxVerification,
|
|
2135
2187
|
};
|
|
2188
|
+
this.printLog('(universalPayload) ' + universalPayload);
|
|
2136
2189
|
// Temporary while we don't change the native address from 0xeee... to 0x0000...
|
|
2137
2190
|
let tokenAddress = (_f = (_e = execute.funds) === null || _e === void 0 ? void 0 : _e.token) === null || _f === void 0 ? void 0 : _f.address;
|
|
2138
2191
|
if (((_h = (_g = execute.funds) === null || _g === void 0 ? void 0 : _g.token) === null || _h === void 0 ? void 0 : _h.address) ===
|
|
@@ -2153,6 +2206,7 @@ class Orchestrator {
|
|
|
2153
2206
|
const multicallData = (0, payload_builders_1.buildExecuteMulticall)({
|
|
2154
2207
|
execute,
|
|
2155
2208
|
ueaAddress: this.computeUEAOffchain(),
|
|
2209
|
+
logger: this.printLog.bind(this),
|
|
2156
2210
|
});
|
|
2157
2211
|
// // The data will be the abi-encoded transfer function from erc-20 function. The recipient will be `execute.to`, the value
|
|
2158
2212
|
// // will be the fundsValue property.
|
|
@@ -2164,10 +2218,23 @@ class Orchestrator {
|
|
|
2164
2218
|
// const pushChainTo = PushChain.utils.tokens.getPRC20Address(
|
|
2165
2219
|
// execute.funds!.token as MoveableToken
|
|
2166
2220
|
// );
|
|
2221
|
+
this.printLog('sendFunds — execute params: ' + JSON.stringify({
|
|
2222
|
+
to: execute.to,
|
|
2223
|
+
value: (_l = (_k = execute.value) === null || _k === void 0 ? void 0 : _k.toString()) !== null && _l !== void 0 ? _l : 'undefined',
|
|
2224
|
+
data: (_m = execute.data) !== null && _m !== void 0 ? _m : 'undefined',
|
|
2225
|
+
fundsAmount: (_p = (_o = execute.funds) === null || _o === void 0 ? void 0 : _o.amount) === null || _p === void 0 ? void 0 : _p.toString(),
|
|
2226
|
+
fundsToken: (_r = (_q = execute.funds) === null || _q === void 0 ? void 0 : _q.token) === null || _r === void 0 ? void 0 : _r.symbol,
|
|
2227
|
+
tokenMechanism: (_t = (_s = execute.funds) === null || _s === void 0 ? void 0 : _s.token) === null || _t === void 0 ? void 0 : _t.mechanism,
|
|
2228
|
+
tokenAddress: (_v = (_u = execute.funds) === null || _u === void 0 ? void 0 : _u.token) === null || _v === void 0 ? void 0 : _v.address,
|
|
2229
|
+
gasLimit: (_x = (_w = execute.gasLimit) === null || _w === void 0 ? void 0 : _w.toString()) !== null && _x !== void 0 ? _x : 'undefined',
|
|
2230
|
+
}, null, 2));
|
|
2231
|
+
this.printLog('sendFunds — multicallData: ' + JSON.stringify(multicallData, (_, v) => typeof v === 'bigint' ? v.toString() : v, 2) + ' (length: ' + multicallData.length + ')');
|
|
2232
|
+
const multicallPayloadData = this._buildMulticallPayloadData(execute.to, multicallData);
|
|
2233
|
+
this.printLog('sendFunds — multicallPayloadData (first 66 chars): ' + multicallPayloadData.slice(0, 66) + ' (full length: ' + multicallPayloadData.length + ')');
|
|
2167
2234
|
const universalPayload = {
|
|
2168
2235
|
to: viem_1.zeroAddress, // We can't simply do `0x` because we will get an error when eip712 signing the transaction.
|
|
2169
|
-
value: (
|
|
2170
|
-
data:
|
|
2236
|
+
value: (_y = execute.value) !== null && _y !== void 0 ? _y : BigInt(0),
|
|
2237
|
+
data: multicallPayloadData,
|
|
2171
2238
|
// data: this._buildMulticallPayloadData(execute.to, [
|
|
2172
2239
|
// { to: pushChainTo, value: execute.value ?? BigInt(0), data },
|
|
2173
2240
|
// ]),
|
|
@@ -2178,18 +2245,36 @@ class Orchestrator {
|
|
|
2178
2245
|
deadline: execute.deadline || BigInt(9999999999),
|
|
2179
2246
|
vType: tx_1.VerificationType.universalTxVerification,
|
|
2180
2247
|
};
|
|
2248
|
+
this.printLog('sendFunds — universalPayload (pre-encode): ' + JSON.stringify({
|
|
2249
|
+
to: viem_1.zeroAddress,
|
|
2250
|
+
value: ((_z = execute.value) !== null && _z !== void 0 ? _z : BigInt(0)).toString(),
|
|
2251
|
+
data: multicallPayloadData,
|
|
2252
|
+
gasLimit: gasEstimate.toString(),
|
|
2253
|
+
maxFeePerGas: (execute.maxFeePerGas || BigInt(1e10)).toString(),
|
|
2254
|
+
maxPriorityFeePerGas: (execute.maxPriorityFeePerGas || BigInt(0)).toString(),
|
|
2255
|
+
nonce: nonce.toString(),
|
|
2256
|
+
deadline: (execute.deadline || BigInt(9999999999)).toString(),
|
|
2257
|
+
}, null, 2));
|
|
2181
2258
|
// Temporary while we don't change the native address from 0xeee... to 0x0000...
|
|
2182
|
-
let tokenAddress = (
|
|
2183
|
-
if (((
|
|
2259
|
+
let tokenAddress = (_1 = (_0 = execute.funds) === null || _0 === void 0 ? void 0 : _0.token) === null || _1 === void 0 ? void 0 : _1.address;
|
|
2260
|
+
if (((_3 = (_2 = execute.funds) === null || _2 === void 0 ? void 0 : _2.token) === null || _3 === void 0 ? void 0 : _3.address) ===
|
|
2184
2261
|
'0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee') {
|
|
2185
2262
|
tokenAddress = viem_1.zeroAddress;
|
|
2186
2263
|
}
|
|
2264
|
+
const encodedPayload = this.encodeUniversalPayload(universalPayload);
|
|
2265
|
+
this.printLog('sendFunds — encodedPayload (first 66 chars): ' + encodedPayload.slice(0, 66) + ' (full length: ' + encodedPayload.length + ')');
|
|
2187
2266
|
const req = this._buildUniversalTxRequest({
|
|
2188
2267
|
recipient: viem_1.zeroAddress,
|
|
2189
2268
|
token: tokenAddress,
|
|
2190
|
-
amount: (
|
|
2191
|
-
payload:
|
|
2269
|
+
amount: (_4 = execute.funds) === null || _4 === void 0 ? void 0 : _4.amount,
|
|
2270
|
+
payload: encodedPayload,
|
|
2192
2271
|
});
|
|
2272
|
+
this.printLog('sendFunds — final req: ' + JSON.stringify({
|
|
2273
|
+
recipient: viem_1.zeroAddress,
|
|
2274
|
+
token: tokenAddress,
|
|
2275
|
+
amount: (_6 = (_5 = execute.funds) === null || _5 === void 0 ? void 0 : _5.amount) === null || _6 === void 0 ? void 0 : _6.toString(),
|
|
2276
|
+
payloadLength: encodedPayload.length,
|
|
2277
|
+
}, null, 2));
|
|
2193
2278
|
return { payload: universalPayload, gasAmount, req };
|
|
2194
2279
|
}
|
|
2195
2280
|
});
|
|
@@ -2230,8 +2315,8 @@ class Orchestrator {
|
|
|
2230
2315
|
/**
|
|
2231
2316
|
* Transforms a TxResponse to the new UniversalTxResponse format
|
|
2232
2317
|
*/
|
|
2233
|
-
transformToUniversalTxResponse(
|
|
2234
|
-
return tslib_1.__awaiter(this,
|
|
2318
|
+
transformToUniversalTxResponse(tx_2) {
|
|
2319
|
+
return tslib_1.__awaiter(this, arguments, void 0, function* (tx, eventBuffer = []) {
|
|
2235
2320
|
const chain = this.universalSigner.account.chain;
|
|
2236
2321
|
const { vm, chainId } = chain_1.CHAIN_INFO[chain];
|
|
2237
2322
|
let from;
|
|
@@ -2260,6 +2345,32 @@ class Orchestrator {
|
|
|
2260
2345
|
to = universalPayload.to;
|
|
2261
2346
|
value = BigInt(universalPayload.value);
|
|
2262
2347
|
data = universalPayload.data;
|
|
2348
|
+
// Extract 'to' from single-element multicall
|
|
2349
|
+
if (data && data.length >= 10) {
|
|
2350
|
+
const multicallSelector = (0, viem_1.keccak256)((0, viem_1.toBytes)('UEA_MULTICALL')).slice(0, 10);
|
|
2351
|
+
if (data.slice(0, 10) === multicallSelector) {
|
|
2352
|
+
try {
|
|
2353
|
+
const innerData = ('0x' + data.slice(10));
|
|
2354
|
+
const [decodedCalls] = (0, viem_1.decodeAbiParameters)([
|
|
2355
|
+
{
|
|
2356
|
+
type: 'tuple[]',
|
|
2357
|
+
components: [
|
|
2358
|
+
{ name: 'to', type: 'address' },
|
|
2359
|
+
{ name: 'value', type: 'uint256' },
|
|
2360
|
+
{ name: 'data', type: 'bytes' },
|
|
2361
|
+
],
|
|
2362
|
+
},
|
|
2363
|
+
], innerData);
|
|
2364
|
+
// If single call, use its 'to' address
|
|
2365
|
+
if (decodedCalls.length === 1) {
|
|
2366
|
+
to = (0, viem_1.getAddress)(decodedCalls[0].to);
|
|
2367
|
+
}
|
|
2368
|
+
}
|
|
2369
|
+
catch (_a) {
|
|
2370
|
+
// Keep original 'to' if decoding fails
|
|
2371
|
+
}
|
|
2372
|
+
}
|
|
2373
|
+
}
|
|
2263
2374
|
rawTransactionData = {
|
|
2264
2375
|
from: (0, viem_1.getAddress)(tx.from),
|
|
2265
2376
|
to: (0, viem_1.getAddress)(tx.to),
|
|
@@ -2306,7 +2417,7 @@ class Orchestrator {
|
|
|
2306
2417
|
yParity: tx.yParity,
|
|
2307
2418
|
};
|
|
2308
2419
|
}
|
|
2309
|
-
catch (
|
|
2420
|
+
catch (_b) {
|
|
2310
2421
|
// Fallback signature if parsing fails
|
|
2311
2422
|
signature = {
|
|
2312
2423
|
r: '0x0000000000000000000000000000000000000000000000000000000000000000',
|
|
@@ -2337,6 +2448,8 @@ class Orchestrator {
|
|
|
2337
2448
|
typeVerbose = 'eip4844';
|
|
2338
2449
|
}
|
|
2339
2450
|
}
|
|
2451
|
+
// Storage for registered progress callback (used by progressHook method)
|
|
2452
|
+
let registeredProgressHook;
|
|
2340
2453
|
const universalTxResponse = {
|
|
2341
2454
|
// 1. Identity
|
|
2342
2455
|
hash: tx.hash,
|
|
@@ -2361,9 +2474,25 @@ class Orchestrator {
|
|
|
2361
2474
|
accessList: Array.isArray(tx.accessList) ? [...tx.accessList] : [],
|
|
2362
2475
|
// 6. Utilities
|
|
2363
2476
|
wait: () => tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
2477
|
+
// Use trackTransaction with registered hook if available
|
|
2478
|
+
if (registeredProgressHook) {
|
|
2479
|
+
return this.trackTransaction(tx.hash, {
|
|
2480
|
+
waitForCompletion: true,
|
|
2481
|
+
progress: registeredProgressHook,
|
|
2482
|
+
});
|
|
2483
|
+
}
|
|
2364
2484
|
const receipt = yield tx.wait();
|
|
2365
2485
|
return this.transformToUniversalTxReceipt(receipt, universalTxResponse);
|
|
2366
2486
|
}),
|
|
2487
|
+
progressHook: (callback) => {
|
|
2488
|
+
registeredProgressHook = callback;
|
|
2489
|
+
// Immediately replay buffered events from execution
|
|
2490
|
+
if (eventBuffer.length > 0) {
|
|
2491
|
+
for (const event of eventBuffer) {
|
|
2492
|
+
callback(event);
|
|
2493
|
+
}
|
|
2494
|
+
}
|
|
2495
|
+
},
|
|
2367
2496
|
// 7. Metadata
|
|
2368
2497
|
type,
|
|
2369
2498
|
typeVerbose,
|
|
@@ -2409,10 +2538,9 @@ class Orchestrator {
|
|
|
2409
2538
|
const hookEntry = progress_hook_1.default[hookId];
|
|
2410
2539
|
const hookPayload = hookEntry(...args);
|
|
2411
2540
|
this.printLog(hookPayload.message);
|
|
2412
|
-
if (
|
|
2413
|
-
|
|
2414
|
-
|
|
2415
|
-
this.progressHook(hookPayload);
|
|
2541
|
+
if (this.progressHook) {
|
|
2542
|
+
this.progressHook(hookPayload);
|
|
2543
|
+
}
|
|
2416
2544
|
}
|
|
2417
2545
|
// Derive the SVM gateway log index from a Solana transaction's log messages
|
|
2418
2546
|
getSvmGatewayLogIndexFromTx(txResp) {
|
|
@@ -2457,7 +2585,7 @@ class Orchestrator {
|
|
|
2457
2585
|
// Query Push Chain for UniversalTx status given an origin gateway tx (EVM or SVM)
|
|
2458
2586
|
queryUniversalTxStatusFromGatewayTx(evmClient, gatewayAddress, txHash, evmGatewayMethod) {
|
|
2459
2587
|
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
2460
|
-
var _a, _b
|
|
2588
|
+
var _a, _b;
|
|
2461
2589
|
try {
|
|
2462
2590
|
const chain = this.universalSigner.account.chain;
|
|
2463
2591
|
const { vm } = chain_1.CHAIN_INFO[chain];
|
|
@@ -2472,7 +2600,7 @@ class Orchestrator {
|
|
|
2472
2600
|
hash: txHash,
|
|
2473
2601
|
});
|
|
2474
2602
|
}
|
|
2475
|
-
catch (
|
|
2603
|
+
catch (_c) {
|
|
2476
2604
|
// Receipt might not be indexed yet on this RPC; wait briefly for it
|
|
2477
2605
|
receipt = yield evmClient.publicClient.waitForTransactionReceipt({
|
|
2478
2606
|
hash: txHash,
|
|
@@ -2481,10 +2609,14 @@ class Orchestrator {
|
|
|
2481
2609
|
});
|
|
2482
2610
|
}
|
|
2483
2611
|
const gatewayLogs = (receipt.logs || []).filter((l) => (l.address || '').toLowerCase() === gatewayAddress.toLowerCase());
|
|
2484
|
-
|
|
2612
|
+
this.printLog(`queryUniversalTxStatus — receipt logs count: ${(_a = receipt.logs) === null || _a === void 0 ? void 0 : _a.length}, gateway logs count: ${gatewayLogs.length}, evmGatewayMethod: ${evmGatewayMethod}`);
|
|
2613
|
+
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));
|
|
2614
|
+
// TEMP: use last gateway log instead of hardcoded 0/1 index
|
|
2615
|
+
const logIndexToUse = gatewayLogs.length - 1;
|
|
2485
2616
|
const firstLog = (gatewayLogs[logIndexToUse] ||
|
|
2486
|
-
(
|
|
2617
|
+
(receipt.logs || []).at(-1));
|
|
2487
2618
|
const logIndexVal = (_b = firstLog === null || firstLog === void 0 ? void 0 : firstLog.logIndex) !== null && _b !== void 0 ? _b : 0;
|
|
2619
|
+
this.printLog(`queryUniversalTxStatus — logIndexToUse: ${logIndexToUse}, firstLog.logIndex: ${firstLog === null || firstLog === void 0 ? void 0 : firstLog.logIndex}, logIndexVal: ${logIndexVal}`);
|
|
2488
2620
|
logIndexStr =
|
|
2489
2621
|
typeof logIndexVal === 'bigint'
|
|
2490
2622
|
? logIndexVal.toString()
|
|
@@ -2518,6 +2650,13 @@ class Orchestrator {
|
|
|
2518
2650
|
// ID = sha256("${sourceChain}:${txHash}:${logIndex}") as hex string (no 0x)
|
|
2519
2651
|
const idInput = `${sourceChain}:${txHashHex}:${logIndexStr}`;
|
|
2520
2652
|
const idHex = (0, viem_1.sha256)((0, viem_1.stringToBytes)(idInput)).slice(2);
|
|
2653
|
+
this.printLog('Query ID extraction: ' + JSON.stringify({
|
|
2654
|
+
sourceChain,
|
|
2655
|
+
txHashHex,
|
|
2656
|
+
logIndexStr,
|
|
2657
|
+
idInput,
|
|
2658
|
+
idHex,
|
|
2659
|
+
}, null, 2));
|
|
2521
2660
|
// Fetch UniversalTx via gRPC with linear-then-exponential retry
|
|
2522
2661
|
const LINEAR_ATTEMPTS = 15;
|
|
2523
2662
|
const LINEAR_DELAY_MS = 1500;
|
|
@@ -2525,21 +2664,11 @@ class Orchestrator {
|
|
|
2525
2664
|
const MAX_ATTEMPTS = 20;
|
|
2526
2665
|
let universalTxObj;
|
|
2527
2666
|
for (let attempt = 0; attempt < MAX_ATTEMPTS; attempt++) {
|
|
2528
|
-
|
|
2667
|
+
this.printLog(`[Sync] Attempt ${attempt + 1}/${MAX_ATTEMPTS} | Query ID: ${idHex}`);
|
|
2529
2668
|
try {
|
|
2530
2669
|
const universalTxResp = yield this.pushClient.getUniversalTxById(idHex);
|
|
2531
2670
|
universalTxObj = universalTxResp === null || universalTxResp === void 0 ? void 0 : universalTxResp.universalTx;
|
|
2532
|
-
|
|
2533
|
-
const successfulPcTx = (_c = universalTxObj === null || universalTxObj === void 0 ? void 0 : universalTxObj.pcTx) === null || _c === void 0 ? void 0 : _c.find((pcTx) => pcTx.txHash && pcTx.status === 'SUCCESS');
|
|
2534
|
-
if (universalTxObj && (successfulPcTx === null || successfulPcTx === void 0 ? void 0 : successfulPcTx.txHash))
|
|
2535
|
-
break;
|
|
2536
|
-
// Also break if we have a terminal failure state
|
|
2537
|
-
// universalStatus 4 = PC_EXECUTED_FAILED, 5 = REVERTED
|
|
2538
|
-
const isTerminalFailure = ((_d = universalTxObj === null || universalTxObj === void 0 ? void 0 : universalTxObj.pcTx) === null || _d === void 0 ? void 0 : _d.length) > 0 &&
|
|
2539
|
-
((universalTxObj === null || universalTxObj === void 0 ? void 0 : universalTxObj.universalStatus) === 4 ||
|
|
2540
|
-
(universalTxObj === null || universalTxObj === void 0 ? void 0 : universalTxObj.universalStatus) === 5) &&
|
|
2541
|
-
universalTxObj.pcTx.some((pcTx) => pcTx.status === 'FAILED' || pcTx.status === 'REVERTED');
|
|
2542
|
-
if (isTerminalFailure)
|
|
2671
|
+
if (universalTxObj)
|
|
2543
2672
|
break;
|
|
2544
2673
|
}
|
|
2545
2674
|
catch (error) {
|
|
@@ -2560,7 +2689,7 @@ class Orchestrator {
|
|
|
2560
2689
|
}
|
|
2561
2690
|
return universalTxObj;
|
|
2562
2691
|
}
|
|
2563
|
-
catch (
|
|
2692
|
+
catch (_d) {
|
|
2564
2693
|
return undefined;
|
|
2565
2694
|
}
|
|
2566
2695
|
});
|