@pushchain/core 4.0.14-alpha.0 → 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 +0 -22
- package/src/lib/orchestrator/orchestrator.js +95 -531
- 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 +16 -55
- package/src/lib/orchestrator/payload-builders.js.map +1 -1
- package/src/lib/progress-hook/progress-hook.js +4 -11
- package/src/lib/progress-hook/progress-hook.js.map +1 -1
- package/src/lib/progress-hook/progress-hook.types.d.ts +2 -3
- package/src/lib/progress-hook/progress-hook.types.js +0 -1
- 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);
|
|
537
|
-
}
|
|
538
|
-
else if (mechanism === 'permit2') {
|
|
539
|
-
throw new Error('Permit2 is not supported yet');
|
|
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');
|
|
540
465
|
}
|
|
541
|
-
|
|
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
|
}
|
|
@@ -840,31 +743,18 @@ class Orchestrator {
|
|
|
840
743
|
}
|
|
841
744
|
else {
|
|
842
745
|
// For value only we don't check below. Only if there is payload to be executed
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
// VALUE ONLY SELF
|
|
746
|
+
if (execute.data && execute.to.toLowerCase() === UEA.toLowerCase()) {
|
|
747
|
+
throw new Error(`You can't execute data on the UEA address`);
|
|
748
|
+
}
|
|
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,167 +1377,6 @@ class Orchestrator {
|
|
|
1504
1377
|
vTypeBytes,
|
|
1505
1378
|
]);
|
|
1506
1379
|
}
|
|
1507
|
-
/**
|
|
1508
|
-
* Reconstructs SEND-TX-* progress events from on-chain transaction data.
|
|
1509
|
-
* Used by trackTransaction to replay progress for already-completed transactions.
|
|
1510
|
-
*
|
|
1511
|
-
* @param universalTxResponse - The transformed transaction response
|
|
1512
|
-
* @param universalTxData - Optional UniversalTx data from gRPC query (for cross-chain txs)
|
|
1513
|
-
* @returns Array of ProgressEvent objects to emit
|
|
1514
|
-
*/
|
|
1515
|
-
reconstructProgressEvents(universalTxResponse, universalTxData) {
|
|
1516
|
-
var _a;
|
|
1517
|
-
const events = [];
|
|
1518
|
-
// Parse origin from CAIP format: "eip155:11155111:0xabc..."
|
|
1519
|
-
const originParts = universalTxResponse.origin.split(':');
|
|
1520
|
-
const chainNamespace = originParts.length >= 2 ? `${originParts[0]}:${originParts[1]}` : originParts[0];
|
|
1521
|
-
const originAddress = originParts.length >= 3 ? originParts[2] : universalTxResponse.from;
|
|
1522
|
-
// SEND_TX_01: Origin Chain Detected (always emit)
|
|
1523
|
-
events.push(progress_hook_1.default[progress_hook_types_1.PROGRESS_HOOK.SEND_TX_01](chainNamespace, originAddress));
|
|
1524
|
-
// SEND_TX_02_01/02: Gas estimation (always emit for reconstructed flow)
|
|
1525
|
-
events.push(progress_hook_1.default[progress_hook_types_1.PROGRESS_HOOK.SEND_TX_02_01]());
|
|
1526
|
-
events.push(progress_hook_1.default[progress_hook_types_1.PROGRESS_HOOK.SEND_TX_02_02](universalTxResponse.gasLimit));
|
|
1527
|
-
// Determine if this is a cross-chain tx (non-Push origin)
|
|
1528
|
-
const isPushOrigin = chainNamespace.includes('eip155:42101') ||
|
|
1529
|
-
chainNamespace.includes('eip155:9') ||
|
|
1530
|
-
chainNamespace.includes('eip155:9001');
|
|
1531
|
-
// SEND_TX_03_01/02: UEA resolution (emit if origin is not Push Chain)
|
|
1532
|
-
if (!isPushOrigin) {
|
|
1533
|
-
events.push(progress_hook_1.default[progress_hook_types_1.PROGRESS_HOOK.SEND_TX_03_01]());
|
|
1534
|
-
events.push(progress_hook_1.default[progress_hook_types_1.PROGRESS_HOOK.SEND_TX_03_02](universalTxResponse.from, true // Assume deployed since tx executed
|
|
1535
|
-
));
|
|
1536
|
-
}
|
|
1537
|
-
// Determine transaction type from universalTxData if available
|
|
1538
|
-
const inboundTx = universalTxData === null || universalTxData === void 0 ? void 0 : universalTxData.inboundTx;
|
|
1539
|
-
const hasFundsFlow = inboundTx && BigInt(inboundTx.amount || '0') > BigInt(0);
|
|
1540
|
-
// SEND_TX_04_02/03: Signature verification (emit for universal tx)
|
|
1541
|
-
if (!isPushOrigin) {
|
|
1542
|
-
events.push(progress_hook_1.default[progress_hook_types_1.PROGRESS_HOOK.SEND_TX_04_02]());
|
|
1543
|
-
events.push(progress_hook_1.default[progress_hook_types_1.PROGRESS_HOOK.SEND_TX_04_03]());
|
|
1544
|
-
}
|
|
1545
|
-
// Funds flow hooks (06-x) - only if funds were bridged
|
|
1546
|
-
if (hasFundsFlow && inboundTx) {
|
|
1547
|
-
const amount = BigInt(inboundTx.amount);
|
|
1548
|
-
// Determine decimals and symbol from asset - default to 18/native for now
|
|
1549
|
-
const decimals = 18;
|
|
1550
|
-
const symbol = 'TOKEN';
|
|
1551
|
-
events.push(progress_hook_1.default[progress_hook_types_1.PROGRESS_HOOK.SEND_TX_06_01](amount, decimals, symbol));
|
|
1552
|
-
events.push(progress_hook_1.default[progress_hook_types_1.PROGRESS_HOOK.SEND_TX_06_02](inboundTx.txHash, amount, decimals, symbol));
|
|
1553
|
-
// Confirmations - emit final state only
|
|
1554
|
-
const confirmations = 1;
|
|
1555
|
-
events.push(progress_hook_1.default[progress_hook_types_1.PROGRESS_HOOK.SEND_TX_06_03](confirmations));
|
|
1556
|
-
events.push(progress_hook_1.default[progress_hook_types_1.PROGRESS_HOOK.SEND_TX_06_03_02](confirmations, confirmations));
|
|
1557
|
-
events.push(progress_hook_1.default[progress_hook_types_1.PROGRESS_HOOK.SEND_TX_06_04]());
|
|
1558
|
-
events.push(progress_hook_1.default[progress_hook_types_1.PROGRESS_HOOK.SEND_TX_06_05]());
|
|
1559
|
-
events.push(progress_hook_1.default[progress_hook_types_1.PROGRESS_HOOK.SEND_TX_06_06](amount, decimals, symbol));
|
|
1560
|
-
}
|
|
1561
|
-
// SEND_TX_07: Broadcasting (always emit)
|
|
1562
|
-
events.push(progress_hook_1.default[progress_hook_types_1.PROGRESS_HOOK.SEND_TX_07]());
|
|
1563
|
-
// Determine outcome from pcTx status if available
|
|
1564
|
-
const pcTx = (_a = universalTxData === null || universalTxData === void 0 ? void 0 : universalTxData.pcTx) === null || _a === void 0 ? void 0 : _a[0];
|
|
1565
|
-
const isFailed = (pcTx === null || pcTx === void 0 ? void 0 : pcTx.status) === 'FAILED';
|
|
1566
|
-
// SEND_TX_99_01/02: Final outcome
|
|
1567
|
-
if (isFailed) {
|
|
1568
|
-
events.push(progress_hook_1.default[progress_hook_types_1.PROGRESS_HOOK.SEND_TX_99_02]((pcTx === null || pcTx === void 0 ? void 0 : pcTx.errorMsg) || 'Unknown error'));
|
|
1569
|
-
}
|
|
1570
|
-
else {
|
|
1571
|
-
events.push(progress_hook_1.default[progress_hook_types_1.PROGRESS_HOOK.SEND_TX_99_01]([universalTxResponse]));
|
|
1572
|
-
}
|
|
1573
|
-
return events;
|
|
1574
|
-
}
|
|
1575
|
-
/**
|
|
1576
|
-
* Tracks a transaction by hash on Push Chain and returns UniversalTxResponse.
|
|
1577
|
-
* Reconstructs and replays SEND-TX-* progress events for completed transactions.
|
|
1578
|
-
*
|
|
1579
|
-
* @param txHash - Transaction hash to track (Push Chain tx hash)
|
|
1580
|
-
* @param options - Tracking options (chain, progressHook, waitForCompletion, advanced config)
|
|
1581
|
-
* @returns Promise resolving to UniversalTxResponse with wait() and progressHook() methods
|
|
1582
|
-
*/
|
|
1583
|
-
trackTransaction(txHash, options) {
|
|
1584
|
-
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
1585
|
-
const { chain = this.getPushChainForNetwork(), progressHook, waitForCompletion = true, advanced = {}, } = options !== null && options !== void 0 ? options : {};
|
|
1586
|
-
const { timeout = 300000, rpcUrls = {} } = advanced;
|
|
1587
|
-
// Event buffer for replay via response.progressHook()
|
|
1588
|
-
const eventBuffer = [];
|
|
1589
|
-
// Helper to emit progress events
|
|
1590
|
-
const emitProgress = (event) => {
|
|
1591
|
-
eventBuffer.push(event);
|
|
1592
|
-
this.printLog(event.message);
|
|
1593
|
-
// Per-transaction hook called FIRST
|
|
1594
|
-
if (progressHook) {
|
|
1595
|
-
progressHook(event);
|
|
1596
|
-
}
|
|
1597
|
-
// Orchestrator-level hook called SECOND
|
|
1598
|
-
if (this.progressHook) {
|
|
1599
|
-
this.progressHook(event);
|
|
1600
|
-
}
|
|
1601
|
-
};
|
|
1602
|
-
// Create client for target chain with optional RPC override
|
|
1603
|
-
const chainRPCs = rpcUrls[chain] || this.rpcUrls[chain] || chain_1.CHAIN_INFO[chain].defaultRPC;
|
|
1604
|
-
const client = new push_client_1.PushClient({
|
|
1605
|
-
rpcUrls: chainRPCs,
|
|
1606
|
-
network: this.pushNetwork,
|
|
1607
|
-
});
|
|
1608
|
-
// Poll for transaction
|
|
1609
|
-
const start = Date.now();
|
|
1610
|
-
let tx;
|
|
1611
|
-
// eslint-disable-next-line no-constant-condition
|
|
1612
|
-
while (true) {
|
|
1613
|
-
try {
|
|
1614
|
-
tx = yield client.getTransaction(txHash);
|
|
1615
|
-
break; // Found transaction
|
|
1616
|
-
}
|
|
1617
|
-
catch (err) {
|
|
1618
|
-
if (!waitForCompletion) {
|
|
1619
|
-
throw new Error(`Transaction ${txHash} not found`);
|
|
1620
|
-
}
|
|
1621
|
-
// Check timeout
|
|
1622
|
-
if (Date.now() - start > timeout) {
|
|
1623
|
-
throw new Error(`Timeout: transaction ${txHash} not confirmed within ${timeout}ms`);
|
|
1624
|
-
}
|
|
1625
|
-
// Brief delay before retry
|
|
1626
|
-
yield new Promise((r) => setTimeout(r, 1000));
|
|
1627
|
-
}
|
|
1628
|
-
}
|
|
1629
|
-
// Try to get UniversalTx data for richer progress reconstruction
|
|
1630
|
-
// (may not exist for direct Push Chain transactions)
|
|
1631
|
-
let universalTxData;
|
|
1632
|
-
try {
|
|
1633
|
-
// Attempt to find UniversalTx by searching pcTx entries
|
|
1634
|
-
// For now, we'll try to look up by the tx hash
|
|
1635
|
-
const utxResponse = yield this.pushClient.getUniversalTxById(txHash);
|
|
1636
|
-
if (utxResponse === null || utxResponse === void 0 ? void 0 : utxResponse.universalTx) {
|
|
1637
|
-
universalTxData = utxResponse.universalTx;
|
|
1638
|
-
}
|
|
1639
|
-
}
|
|
1640
|
-
catch (_a) {
|
|
1641
|
-
// Ignore - direct Push Chain tx or tx not indexed yet
|
|
1642
|
-
}
|
|
1643
|
-
// Transform to UniversalTxResponse
|
|
1644
|
-
const universalTxResponse = yield this.transformToUniversalTxResponse(tx, eventBuffer);
|
|
1645
|
-
// Reconstruct and emit SEND-TX-* progress events
|
|
1646
|
-
const reconstructedEvents = this.reconstructProgressEvents(universalTxResponse, universalTxData);
|
|
1647
|
-
for (const event of reconstructedEvents) {
|
|
1648
|
-
emitProgress(event);
|
|
1649
|
-
}
|
|
1650
|
-
return universalTxResponse;
|
|
1651
|
-
});
|
|
1652
|
-
}
|
|
1653
|
-
/**
|
|
1654
|
-
* Returns the Push Chain enum value for the current network
|
|
1655
|
-
*/
|
|
1656
|
-
getPushChainForNetwork() {
|
|
1657
|
-
if (this.pushNetwork === enums_1.PUSH_NETWORK.MAINNET) {
|
|
1658
|
-
return enums_1.CHAIN.PUSH_MAINNET;
|
|
1659
|
-
}
|
|
1660
|
-
else if (this.pushNetwork === enums_1.PUSH_NETWORK.TESTNET_DONUT ||
|
|
1661
|
-
this.pushNetwork === enums_1.PUSH_NETWORK.TESTNET) {
|
|
1662
|
-
return enums_1.CHAIN.PUSH_TESTNET_DONUT;
|
|
1663
|
-
}
|
|
1664
|
-
else {
|
|
1665
|
-
return enums_1.CHAIN.PUSH_LOCALNET;
|
|
1666
|
-
}
|
|
1667
|
-
}
|
|
1668
1380
|
/**
|
|
1669
1381
|
* Computes UEA for given UniversalAccount
|
|
1670
1382
|
* @dev - This fn calls a view fn of Factory Contract
|
|
@@ -1707,7 +1419,6 @@ class Orchestrator {
|
|
|
1707
1419
|
});
|
|
1708
1420
|
}
|
|
1709
1421
|
_buildMulticallPayloadData(to, data) {
|
|
1710
|
-
this.printLog('_buildMulticallPayloadData — input: ' + data.length + ' calls: ' + JSON.stringify(data, (_, v) => typeof v === 'bigint' ? v.toString() : v, 2));
|
|
1711
1422
|
const allowedChains = [
|
|
1712
1423
|
enums_1.CHAIN.ETHEREUM_SEPOLIA,
|
|
1713
1424
|
enums_1.CHAIN.ARBITRUM_SEPOLIA,
|
|
@@ -1940,17 +1651,17 @@ class Orchestrator {
|
|
|
1940
1651
|
waitForLockerFeeConfirmation(txHashBytes) {
|
|
1941
1652
|
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
1942
1653
|
const chain = this.universalSigner.account.chain;
|
|
1943
|
-
const { vm, defaultRPC,
|
|
1654
|
+
const { vm, defaultRPC, confirmations, timeout } = chain_1.CHAIN_INFO[chain];
|
|
1944
1655
|
const rpcUrls = this.rpcUrls[chain] || defaultRPC;
|
|
1945
1656
|
switch (vm) {
|
|
1946
1657
|
case enums_1.VM.EVM: {
|
|
1947
1658
|
const evmClient = new evm_client_1.EvmClient({ rpcUrls });
|
|
1948
|
-
yield this.waitForEvmConfirmationsWithCountdown(evmClient, (0, viem_1.bytesToHex)(txHashBytes),
|
|
1659
|
+
yield this.waitForEvmConfirmationsWithCountdown(evmClient, (0, viem_1.bytesToHex)(txHashBytes), confirmations, timeout);
|
|
1949
1660
|
return;
|
|
1950
1661
|
}
|
|
1951
1662
|
case enums_1.VM.SVM: {
|
|
1952
1663
|
const svmClient = new svm_client_1.SvmClient({ rpcUrls });
|
|
1953
|
-
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);
|
|
1954
1665
|
return;
|
|
1955
1666
|
}
|
|
1956
1667
|
default:
|
|
@@ -2090,10 +1801,10 @@ class Orchestrator {
|
|
|
2090
1801
|
throw new Error('No direct Uniswap V3 pool found for the given token pair on common fee tiers');
|
|
2091
1802
|
}
|
|
2092
1803
|
const amountInBig = BigInt(bestAmountIn);
|
|
2093
|
-
const amountInHuman = parseFloat(
|
|
1804
|
+
const amountInHuman = parseFloat(push_chain_1.PushChain.utils.helpers.formatUnits(amountInBig, {
|
|
2094
1805
|
decimals: from.decimals,
|
|
2095
1806
|
}));
|
|
2096
|
-
const amountOutHuman = parseFloat(
|
|
1807
|
+
const amountOutHuman = parseFloat(push_chain_1.PushChain.utils.helpers.formatUnits(amountOut, { decimals: to.decimals }));
|
|
2097
1808
|
const rate = amountInHuman > 0 ? amountOutHuman / amountInHuman : 0;
|
|
2098
1809
|
return {
|
|
2099
1810
|
amountIn: bestAmountIn.toString(),
|
|
@@ -2218,7 +1929,7 @@ class Orchestrator {
|
|
|
2218
1929
|
*/
|
|
2219
1930
|
buildGatewayPayloadAndGas(execute, nonce, type, fundsValue) {
|
|
2220
1931
|
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
2221
|
-
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;
|
|
2222
1933
|
const gasEstimate = execute.gasLimit || BigInt(1e7);
|
|
2223
1934
|
const gasAmount = (_a = execute.value) !== null && _a !== void 0 ? _a : BigInt(0);
|
|
2224
1935
|
if (type === 'sendTxWithFunds') {
|
|
@@ -2241,7 +1952,6 @@ class Orchestrator {
|
|
|
2241
1952
|
deadline: execute.deadline || BigInt(9999999999),
|
|
2242
1953
|
vType: tx_1.VerificationType.universalTxVerification,
|
|
2243
1954
|
};
|
|
2244
|
-
this.printLog('(universalPayload) ' + universalPayload);
|
|
2245
1955
|
// Temporary while we don't change the native address from 0xeee... to 0x0000...
|
|
2246
1956
|
let tokenAddress = (_f = (_e = execute.funds) === null || _e === void 0 ? void 0 : _e.token) === null || _f === void 0 ? void 0 : _f.address;
|
|
2247
1957
|
if (((_h = (_g = execute.funds) === null || _g === void 0 ? void 0 : _g.token) === null || _h === void 0 ? void 0 : _h.address) ===
|
|
@@ -2273,23 +1983,10 @@ class Orchestrator {
|
|
|
2273
1983
|
// const pushChainTo = PushChain.utils.tokens.getPRC20Address(
|
|
2274
1984
|
// execute.funds!.token as MoveableToken
|
|
2275
1985
|
// );
|
|
2276
|
-
this.printLog('sendFunds — execute params: ' + JSON.stringify({
|
|
2277
|
-
to: execute.to,
|
|
2278
|
-
value: (_l = (_k = execute.value) === null || _k === void 0 ? void 0 : _k.toString()) !== null && _l !== void 0 ? _l : 'undefined',
|
|
2279
|
-
data: (_m = execute.data) !== null && _m !== void 0 ? _m : 'undefined',
|
|
2280
|
-
fundsAmount: (_p = (_o = execute.funds) === null || _o === void 0 ? void 0 : _o.amount) === null || _p === void 0 ? void 0 : _p.toString(),
|
|
2281
|
-
fundsToken: (_r = (_q = execute.funds) === null || _q === void 0 ? void 0 : _q.token) === null || _r === void 0 ? void 0 : _r.symbol,
|
|
2282
|
-
tokenMechanism: (_t = (_s = execute.funds) === null || _s === void 0 ? void 0 : _s.token) === null || _t === void 0 ? void 0 : _t.mechanism,
|
|
2283
|
-
tokenAddress: (_v = (_u = execute.funds) === null || _u === void 0 ? void 0 : _u.token) === null || _v === void 0 ? void 0 : _v.address,
|
|
2284
|
-
gasLimit: (_x = (_w = execute.gasLimit) === null || _w === void 0 ? void 0 : _w.toString()) !== null && _x !== void 0 ? _x : 'undefined',
|
|
2285
|
-
}, null, 2));
|
|
2286
|
-
this.printLog('sendFunds — multicallData: ' + JSON.stringify(multicallData, (_, v) => typeof v === 'bigint' ? v.toString() : v, 2) + ' (length: ' + multicallData.length + ')');
|
|
2287
|
-
const multicallPayloadData = this._buildMulticallPayloadData(execute.to, multicallData);
|
|
2288
|
-
this.printLog('sendFunds — multicallPayloadData (first 66 chars): ' + multicallPayloadData.slice(0, 66) + ' (full length: ' + multicallPayloadData.length + ')');
|
|
2289
1986
|
const universalPayload = {
|
|
2290
1987
|
to: viem_1.zeroAddress, // We can't simply do `0x` because we will get an error when eip712 signing the transaction.
|
|
2291
|
-
value: (
|
|
2292
|
-
data:
|
|
1988
|
+
value: (_k = execute.value) !== null && _k !== void 0 ? _k : BigInt(0),
|
|
1989
|
+
data: this._buildMulticallPayloadData(execute.to, multicallData),
|
|
2293
1990
|
// data: this._buildMulticallPayloadData(execute.to, [
|
|
2294
1991
|
// { to: pushChainTo, value: execute.value ?? BigInt(0), data },
|
|
2295
1992
|
// ]),
|
|
@@ -2300,36 +1997,18 @@ class Orchestrator {
|
|
|
2300
1997
|
deadline: execute.deadline || BigInt(9999999999),
|
|
2301
1998
|
vType: tx_1.VerificationType.universalTxVerification,
|
|
2302
1999
|
};
|
|
2303
|
-
this.printLog('sendFunds — universalPayload (pre-encode): ' + JSON.stringify({
|
|
2304
|
-
to: viem_1.zeroAddress,
|
|
2305
|
-
value: ((_z = execute.value) !== null && _z !== void 0 ? _z : BigInt(0)).toString(),
|
|
2306
|
-
data: multicallPayloadData,
|
|
2307
|
-
gasLimit: gasEstimate.toString(),
|
|
2308
|
-
maxFeePerGas: (execute.maxFeePerGas || BigInt(1e10)).toString(),
|
|
2309
|
-
maxPriorityFeePerGas: (execute.maxPriorityFeePerGas || BigInt(0)).toString(),
|
|
2310
|
-
nonce: nonce.toString(),
|
|
2311
|
-
deadline: (execute.deadline || BigInt(9999999999)).toString(),
|
|
2312
|
-
}, null, 2));
|
|
2313
2000
|
// Temporary while we don't change the native address from 0xeee... to 0x0000...
|
|
2314
|
-
let tokenAddress = (
|
|
2315
|
-
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) ===
|
|
2316
2003
|
'0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee') {
|
|
2317
2004
|
tokenAddress = viem_1.zeroAddress;
|
|
2318
2005
|
}
|
|
2319
|
-
const encodedPayload = this.encodeUniversalPayload(universalPayload);
|
|
2320
|
-
this.printLog('sendFunds — encodedPayload (first 66 chars): ' + encodedPayload.slice(0, 66) + ' (full length: ' + encodedPayload.length + ')');
|
|
2321
2006
|
const req = this._buildUniversalTxRequest({
|
|
2322
2007
|
recipient: viem_1.zeroAddress,
|
|
2323
2008
|
token: tokenAddress,
|
|
2324
|
-
amount: (
|
|
2325
|
-
payload:
|
|
2009
|
+
amount: (_q = execute.funds) === null || _q === void 0 ? void 0 : _q.amount,
|
|
2010
|
+
payload: this.encodeUniversalPayload(universalPayload),
|
|
2326
2011
|
});
|
|
2327
|
-
this.printLog('sendFunds — final req: ' + JSON.stringify({
|
|
2328
|
-
recipient: viem_1.zeroAddress,
|
|
2329
|
-
token: tokenAddress,
|
|
2330
|
-
amount: (_6 = (_5 = execute.funds) === null || _5 === void 0 ? void 0 : _5.amount) === null || _6 === void 0 ? void 0 : _6.toString(),
|
|
2331
|
-
payloadLength: encodedPayload.length,
|
|
2332
|
-
}, null, 2));
|
|
2333
2012
|
return { payload: universalPayload, gasAmount, req };
|
|
2334
2013
|
}
|
|
2335
2014
|
});
|
|
@@ -2370,8 +2049,8 @@ class Orchestrator {
|
|
|
2370
2049
|
/**
|
|
2371
2050
|
* Transforms a TxResponse to the new UniversalTxResponse format
|
|
2372
2051
|
*/
|
|
2373
|
-
transformToUniversalTxResponse(
|
|
2374
|
-
return tslib_1.__awaiter(this,
|
|
2052
|
+
transformToUniversalTxResponse(tx) {
|
|
2053
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
2375
2054
|
const chain = this.universalSigner.account.chain;
|
|
2376
2055
|
const { vm, chainId } = chain_1.CHAIN_INFO[chain];
|
|
2377
2056
|
let from;
|
|
@@ -2400,32 +2079,6 @@ class Orchestrator {
|
|
|
2400
2079
|
to = universalPayload.to;
|
|
2401
2080
|
value = BigInt(universalPayload.value);
|
|
2402
2081
|
data = universalPayload.data;
|
|
2403
|
-
// Extract 'to' from single-element multicall
|
|
2404
|
-
if (data && data.length >= 10) {
|
|
2405
|
-
const multicallSelector = (0, viem_1.keccak256)((0, viem_1.toBytes)('UEA_MULTICALL')).slice(0, 10);
|
|
2406
|
-
if (data.slice(0, 10) === multicallSelector) {
|
|
2407
|
-
try {
|
|
2408
|
-
const innerData = ('0x' + data.slice(10));
|
|
2409
|
-
const [decodedCalls] = (0, viem_1.decodeAbiParameters)([
|
|
2410
|
-
{
|
|
2411
|
-
type: 'tuple[]',
|
|
2412
|
-
components: [
|
|
2413
|
-
{ name: 'to', type: 'address' },
|
|
2414
|
-
{ name: 'value', type: 'uint256' },
|
|
2415
|
-
{ name: 'data', type: 'bytes' },
|
|
2416
|
-
],
|
|
2417
|
-
},
|
|
2418
|
-
], innerData);
|
|
2419
|
-
// If single call, use its 'to' address
|
|
2420
|
-
if (decodedCalls.length === 1) {
|
|
2421
|
-
to = (0, viem_1.getAddress)(decodedCalls[0].to);
|
|
2422
|
-
}
|
|
2423
|
-
}
|
|
2424
|
-
catch (_a) {
|
|
2425
|
-
// Keep original 'to' if decoding fails
|
|
2426
|
-
}
|
|
2427
|
-
}
|
|
2428
|
-
}
|
|
2429
2082
|
rawTransactionData = {
|
|
2430
2083
|
from: (0, viem_1.getAddress)(tx.from),
|
|
2431
2084
|
to: (0, viem_1.getAddress)(tx.to),
|
|
@@ -2461,39 +2114,6 @@ class Orchestrator {
|
|
|
2461
2114
|
value: tx.value,
|
|
2462
2115
|
};
|
|
2463
2116
|
}
|
|
2464
|
-
// Extract 'to' and 'from' from depositPRC20WithAutoSwap (precompile call)
|
|
2465
|
-
if (data && data.length >= 10) {
|
|
2466
|
-
const depositPRC20Selector = '0x780ad827';
|
|
2467
|
-
if (data.slice(0, 10) === depositPRC20Selector) {
|
|
2468
|
-
try {
|
|
2469
|
-
const decoded = (0, viem_1.decodeFunctionData)({
|
|
2470
|
-
abi: [
|
|
2471
|
-
{
|
|
2472
|
-
name: 'depositPRC20WithAutoSwap',
|
|
2473
|
-
type: 'function',
|
|
2474
|
-
inputs: [
|
|
2475
|
-
{ name: 'prc20', type: 'address' },
|
|
2476
|
-
{ name: 'amount', type: 'uint256' },
|
|
2477
|
-
{ name: 'target', type: 'address' },
|
|
2478
|
-
{ name: 'fee', type: 'uint24' },
|
|
2479
|
-
{ name: 'minPCOut', type: 'uint256' },
|
|
2480
|
-
{ name: 'deadline', type: 'uint256' },
|
|
2481
|
-
],
|
|
2482
|
-
},
|
|
2483
|
-
],
|
|
2484
|
-
data: data,
|
|
2485
|
-
});
|
|
2486
|
-
if (decoded.args) {
|
|
2487
|
-
const target = decoded.args[2];
|
|
2488
|
-
to = (0, viem_1.getAddress)(target);
|
|
2489
|
-
from = '0x0000000000000000000000000000000000000000';
|
|
2490
|
-
}
|
|
2491
|
-
}
|
|
2492
|
-
catch (_b) {
|
|
2493
|
-
// Keep original values if decoding fails
|
|
2494
|
-
}
|
|
2495
|
-
}
|
|
2496
|
-
}
|
|
2497
2117
|
const origin = `${chain_1.VM_NAMESPACE[vm]}:${chainId}:${originAddress}`;
|
|
2498
2118
|
// Create signature from transaction r, s, v values
|
|
2499
2119
|
let signature;
|
|
@@ -2505,7 +2125,7 @@ class Orchestrator {
|
|
|
2505
2125
|
yParity: tx.yParity,
|
|
2506
2126
|
};
|
|
2507
2127
|
}
|
|
2508
|
-
catch (
|
|
2128
|
+
catch (_a) {
|
|
2509
2129
|
// Fallback signature if parsing fails
|
|
2510
2130
|
signature = {
|
|
2511
2131
|
r: '0x0000000000000000000000000000000000000000000000000000000000000000',
|
|
@@ -2536,8 +2156,6 @@ class Orchestrator {
|
|
|
2536
2156
|
typeVerbose = 'eip4844';
|
|
2537
2157
|
}
|
|
2538
2158
|
}
|
|
2539
|
-
// Storage for registered progress callback (used by progressHook method)
|
|
2540
|
-
let registeredProgressHook;
|
|
2541
2159
|
const universalTxResponse = {
|
|
2542
2160
|
// 1. Identity
|
|
2543
2161
|
hash: tx.hash,
|
|
@@ -2562,28 +2180,9 @@ class Orchestrator {
|
|
|
2562
2180
|
accessList: Array.isArray(tx.accessList) ? [...tx.accessList] : [],
|
|
2563
2181
|
// 6. Utilities
|
|
2564
2182
|
wait: () => tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
2565
|
-
// Use trackTransaction with registered hook if available
|
|
2566
|
-
if (registeredProgressHook) {
|
|
2567
|
-
const trackedResponse = yield this.trackTransaction(tx.hash, {
|
|
2568
|
-
waitForCompletion: true,
|
|
2569
|
-
progressHook: registeredProgressHook,
|
|
2570
|
-
});
|
|
2571
|
-
// Get receipt from the tracked response
|
|
2572
|
-
const receipt = yield tx.wait();
|
|
2573
|
-
return this.transformToUniversalTxReceipt(receipt, trackedResponse);
|
|
2574
|
-
}
|
|
2575
2183
|
const receipt = yield tx.wait();
|
|
2576
2184
|
return this.transformToUniversalTxReceipt(receipt, universalTxResponse);
|
|
2577
2185
|
}),
|
|
2578
|
-
progressHook: (callback) => {
|
|
2579
|
-
registeredProgressHook = callback;
|
|
2580
|
-
// Immediately replay buffered events from execution
|
|
2581
|
-
if (eventBuffer.length > 0) {
|
|
2582
|
-
for (const event of eventBuffer) {
|
|
2583
|
-
callback(event);
|
|
2584
|
-
}
|
|
2585
|
-
}
|
|
2586
|
-
},
|
|
2587
2186
|
// 7. Metadata
|
|
2588
2187
|
type,
|
|
2589
2188
|
typeVerbose,
|
|
@@ -2629,9 +2228,10 @@ class Orchestrator {
|
|
|
2629
2228
|
const hookEntry = progress_hook_1.default[hookId];
|
|
2630
2229
|
const hookPayload = hookEntry(...args);
|
|
2631
2230
|
this.printLog(hookPayload.message);
|
|
2632
|
-
if (this.progressHook)
|
|
2633
|
-
|
|
2634
|
-
|
|
2231
|
+
if (!this.progressHook)
|
|
2232
|
+
return;
|
|
2233
|
+
// invoke the user-provided callback
|
|
2234
|
+
this.progressHook(hookPayload);
|
|
2635
2235
|
}
|
|
2636
2236
|
// Derive the SVM gateway log index from a Solana transaction's log messages
|
|
2637
2237
|
getSvmGatewayLogIndexFromTx(txResp) {
|
|
@@ -2700,14 +2300,10 @@ class Orchestrator {
|
|
|
2700
2300
|
});
|
|
2701
2301
|
}
|
|
2702
2302
|
const gatewayLogs = (receipt.logs || []).filter((l) => (l.address || '').toLowerCase() === gatewayAddress.toLowerCase());
|
|
2703
|
-
|
|
2704
|
-
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));
|
|
2705
|
-
// TEMP: use last gateway log instead of hardcoded 0/1 index
|
|
2706
|
-
const logIndexToUse = gatewayLogs.length - 1;
|
|
2303
|
+
const logIndexToUse = evmGatewayMethod === 'sendTxWithFunds' ? 1 : 0;
|
|
2707
2304
|
const firstLog = (gatewayLogs[logIndexToUse] ||
|
|
2708
|
-
(receipt.logs || [])
|
|
2305
|
+
((_a = receipt.logs) === null || _a === void 0 ? void 0 : _a[logIndexToUse]));
|
|
2709
2306
|
const logIndexVal = (_b = firstLog === null || firstLog === void 0 ? void 0 : firstLog.logIndex) !== null && _b !== void 0 ? _b : 0;
|
|
2710
|
-
this.printLog(`queryUniversalTxStatus — logIndexToUse: ${logIndexToUse}, firstLog.logIndex: ${firstLog === null || firstLog === void 0 ? void 0 : firstLog.logIndex}, logIndexVal: ${logIndexVal}`);
|
|
2711
2307
|
logIndexStr =
|
|
2712
2308
|
typeof logIndexVal === 'bigint'
|
|
2713
2309
|
? logIndexVal.toString()
|
|
@@ -2741,21 +2337,9 @@ class Orchestrator {
|
|
|
2741
2337
|
// ID = sha256("${sourceChain}:${txHash}:${logIndex}") as hex string (no 0x)
|
|
2742
2338
|
const idInput = `${sourceChain}:${txHashHex}:${logIndexStr}`;
|
|
2743
2339
|
const idHex = (0, viem_1.sha256)((0, viem_1.stringToBytes)(idInput)).slice(2);
|
|
2744
|
-
|
|
2745
|
-
sourceChain,
|
|
2746
|
-
txHashHex,
|
|
2747
|
-
logIndexStr,
|
|
2748
|
-
idInput,
|
|
2749
|
-
idHex,
|
|
2750
|
-
}, null, 2));
|
|
2751
|
-
// Fetch UniversalTx via gRPC with linear-then-exponential retry
|
|
2752
|
-
const LINEAR_ATTEMPTS = 25;
|
|
2753
|
-
const LINEAR_DELAY_MS = 1500;
|
|
2754
|
-
const EXPONENTIAL_BASE_MS = 2000;
|
|
2755
|
-
const MAX_ATTEMPTS = 30;
|
|
2340
|
+
// Fetch UniversalTx via gRPC with a brief retry window
|
|
2756
2341
|
let universalTxObj;
|
|
2757
|
-
for (let attempt = 0; attempt <
|
|
2758
|
-
this.printLog(`[Sync] Attempt ${attempt + 1}/${MAX_ATTEMPTS} | Query ID: ${idHex}`);
|
|
2342
|
+
for (let attempt = 0; attempt < 15; attempt++) {
|
|
2759
2343
|
try {
|
|
2760
2344
|
const universalTxResp = yield this.pushClient.getUniversalTxById(idHex);
|
|
2761
2345
|
universalTxObj = universalTxResp === null || universalTxResp === void 0 ? void 0 : universalTxResp.universalTx;
|
|
@@ -2766,17 +2350,7 @@ class Orchestrator {
|
|
|
2766
2350
|
// ignore and retry
|
|
2767
2351
|
// console.log(error);
|
|
2768
2352
|
}
|
|
2769
|
-
|
|
2770
|
-
let delay;
|
|
2771
|
-
if (attempt < LINEAR_ATTEMPTS) {
|
|
2772
|
-
delay = LINEAR_DELAY_MS;
|
|
2773
|
-
}
|
|
2774
|
-
else {
|
|
2775
|
-
// Exponential: 2000, 4000, 8000, 16000, ...
|
|
2776
|
-
const exponentialAttempt = attempt - LINEAR_ATTEMPTS;
|
|
2777
|
-
delay = EXPONENTIAL_BASE_MS * Math.pow(2, exponentialAttempt);
|
|
2778
|
-
}
|
|
2779
|
-
yield new Promise((r) => setTimeout(r, delay));
|
|
2353
|
+
yield new Promise((r) => setTimeout(r, 1500));
|
|
2780
2354
|
}
|
|
2781
2355
|
return universalTxObj;
|
|
2782
2356
|
}
|
|
@@ -2788,11 +2362,6 @@ class Orchestrator {
|
|
|
2788
2362
|
// Emit countdown updates while waiting for EVM confirmations
|
|
2789
2363
|
waitForEvmConfirmationsWithCountdown(evmClient, txHash, confirmations, timeoutMs) {
|
|
2790
2364
|
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
2791
|
-
// Skip waiting if zero confirmations requested
|
|
2792
|
-
if (confirmations <= 0) {
|
|
2793
|
-
this.executeProgressHook(progress_hook_types_1.PROGRESS_HOOK.SEND_TX_06_03_02, 0, 0);
|
|
2794
|
-
return;
|
|
2795
|
-
}
|
|
2796
2365
|
// initial emit
|
|
2797
2366
|
this.executeProgressHook(progress_hook_types_1.PROGRESS_HOOK.SEND_TX_06_03, confirmations);
|
|
2798
2367
|
const start = Date.now();
|
|
@@ -2838,11 +2407,6 @@ class Orchestrator {
|
|
|
2838
2407
|
// Emit countdown updates while waiting for SVM confirmations
|
|
2839
2408
|
waitForSvmConfirmationsWithCountdown(svmClient, txSignature, confirmations, timeoutMs) {
|
|
2840
2409
|
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
2841
|
-
// Skip waiting if zero confirmations requested
|
|
2842
|
-
if (confirmations <= 0) {
|
|
2843
|
-
this.executeProgressHook(progress_hook_types_1.PROGRESS_HOOK.SEND_TX_06_03_02, 0, 0);
|
|
2844
|
-
return;
|
|
2845
|
-
}
|
|
2846
2410
|
// initial emit
|
|
2847
2411
|
this.executeProgressHook(progress_hook_types_1.PROGRESS_HOOK.SEND_TX_06_03, confirmations);
|
|
2848
2412
|
const start = Date.now();
|
|
@@ -2963,8 +2527,8 @@ class Orchestrator {
|
|
|
2963
2527
|
var _a, _b;
|
|
2964
2528
|
this.executeProgressHook(progress_hook_types_1.PROGRESS_HOOK.SEND_TX_02_01);
|
|
2965
2529
|
// Determine USD to deposit via gateway (8 decimals) with caps: min=$1, max=$10
|
|
2966
|
-
const oneUsd =
|
|
2967
|
-
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);
|
|
2968
2532
|
const deficit = requiredFunds > ueaBalance ? requiredFunds - ueaBalance : BigInt(0);
|
|
2969
2533
|
let depositUsd = deficit > BigInt(0) ? this.pushClient.pushToUSDC(deficit) : oneUsd;
|
|
2970
2534
|
if (depositUsd < oneUsd)
|
|
@@ -3006,7 +2570,7 @@ class Orchestrator {
|
|
|
3006
2570
|
// Convert USD(8) -> native units using pricing path
|
|
3007
2571
|
const nativeTokenUsdPrice = yield new price_fetch_1.PriceFetch(this.rpcUrls).getPrice(chain); // 8 decimals
|
|
3008
2572
|
const nativeDecimals = chain_1.CHAIN_INFO[chain].vm === enums_1.VM.SVM ? 9 : 18;
|
|
3009
|
-
const oneNativeUnit =
|
|
2573
|
+
const oneNativeUnit = push_chain_1.PushChain.utils.helpers.parseUnits('1', nativeDecimals);
|
|
3010
2574
|
// Ceil division to avoid rounding below min USD on-chain
|
|
3011
2575
|
let nativeAmount = (depositUsd * oneNativeUnit + (nativeTokenUsdPrice - BigInt(1))) /
|
|
3012
2576
|
nativeTokenUsdPrice;
|