@pushchain/core 2.1.7-alpha-v0 → 2.1.7
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/erc20.evm.d.ts +0 -33
- package/src/lib/constants/abi/erc20.evm.js +0 -19
- package/src/lib/constants/abi/erc20.evm.js.map +1 -1
- package/src/lib/constants/abi/universalGatewayV0.evm.d.ts +1 -48
- package/src/lib/constants/abi/universalGatewayV0.evm.js +28 -1060
- package/src/lib/constants/abi/universalGatewayV0.evm.js.map +1 -1
- package/src/lib/constants/abi/universalGatewayV0.json +206 -1223
- package/src/lib/constants/chain.d.ts +5 -0
- package/src/lib/constants/chain.js +22 -2
- package/src/lib/constants/chain.js.map +1 -1
- package/src/lib/constants/tokens.d.ts +2 -1
- package/src/lib/constants/tokens.js +103 -119
- package/src/lib/constants/tokens.js.map +1 -1
- package/src/lib/generated/v1/tx.d.ts +2 -1
- package/src/lib/generated/v1/tx.js +1 -2
- package/src/lib/generated/v1/tx.js.map +1 -1
- package/src/lib/orchestrator/orchestrator.d.ts +2 -4
- package/src/lib/orchestrator/orchestrator.js +79 -409
- package/src/lib/orchestrator/orchestrator.js.map +1 -1
- package/src/lib/orchestrator/orchestrator.types.d.ts +5 -12
- package/src/lib/progress-hook/progress-hook.js +1 -1
- package/src/lib/progress-hook/progress-hook.js.map +1 -1
- package/src/lib/universal/signer/signer.js +27 -0
- package/src/lib/universal/signer/signer.js.map +1 -1
- package/src/lib/vm-client/svm-client.js +3 -24
- package/src/lib/vm-client/svm-client.js.map +1 -1
|
@@ -63,7 +63,7 @@ class Orchestrator {
|
|
|
63
63
|
*/
|
|
64
64
|
execute(execute) {
|
|
65
65
|
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
66
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _j
|
|
66
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j;
|
|
67
67
|
try {
|
|
68
68
|
// FUNDS_TX short-circuit: Bridge tokens from origin chain to Push Chain
|
|
69
69
|
// - EVM (Sepolia): UniversalGatewayV0
|
|
@@ -138,48 +138,16 @@ class Orchestrator {
|
|
|
138
138
|
const bridgeToken = execute.funds.token.mechanism === 'approve'
|
|
139
139
|
? tokenAddr
|
|
140
140
|
: '0x0000000000000000000000000000000000000000';
|
|
141
|
-
const { nonce } = yield this.getUeaStatusAndNonce();
|
|
142
|
-
const { payload: universalPayload } = yield this.buildGatewayPayloadAndGas(execute, nonce, 'sendFunds', bridgeAmount);
|
|
143
|
-
// Get UEA info
|
|
144
|
-
const ueaAddress = this.computeUEAOffchain();
|
|
145
|
-
const ueaVersion = yield this.fetchUEAVersion();
|
|
146
|
-
const eip712Signature = yield this.signUniversalPayload(universalPayload, ueaAddress, ueaVersion);
|
|
147
|
-
const eip712SignatureHex = (0, viem_1.bytesToHex)(eip712Signature);
|
|
148
141
|
let txHash;
|
|
149
142
|
try {
|
|
150
|
-
// Compute minimal native amount to deposit for gas on Push Chain
|
|
151
|
-
const ueaAddressForGas = this.computeUEAOffchain();
|
|
152
|
-
const ueaBalanceForGas = yield this.pushClient.getBalance(ueaAddressForGas);
|
|
153
|
-
const nativeAmount = yield this.calculateNativeAmountForDeposit(chain, BigInt(0), ueaBalanceForGas);
|
|
154
|
-
console.log([
|
|
155
|
-
tokenAddr,
|
|
156
|
-
bridgeAmount,
|
|
157
|
-
universalPayload,
|
|
158
|
-
revertCFG,
|
|
159
|
-
'0x',
|
|
160
|
-
]);
|
|
161
143
|
txHash = yield evmClient.writeContract({
|
|
162
144
|
abi: abi_1.UNIVERSAL_GATEWAY_V0,
|
|
163
145
|
address: gatewayAddress,
|
|
164
|
-
functionName: '
|
|
165
|
-
args: [
|
|
166
|
-
tokenAddr,
|
|
167
|
-
bridgeAmount,
|
|
168
|
-
universalPayload,
|
|
169
|
-
revertCFG,
|
|
170
|
-
'0x',
|
|
171
|
-
],
|
|
146
|
+
functionName: 'sendFunds',
|
|
147
|
+
args: [recipient, bridgeToken, bridgeAmount, revertCFG],
|
|
172
148
|
signer: this.universalSigner,
|
|
173
|
-
value:
|
|
149
|
+
value: isNative ? bridgeAmount : BigInt(0),
|
|
174
150
|
});
|
|
175
|
-
// txHash = await evmClient.writeContract({
|
|
176
|
-
// abi: UNIVERSAL_GATEWAY_V0 as unknown as Abi,
|
|
177
|
-
// address: gatewayAddress,
|
|
178
|
-
// functionName: 'sendFunds',
|
|
179
|
-
// args: [recipient, bridgeToken, bridgeAmount, revertCFG],
|
|
180
|
-
// signer: this.universalSigner,
|
|
181
|
-
// value: isNative ? bridgeAmount : BigInt(0),
|
|
182
|
-
// });
|
|
183
151
|
}
|
|
184
152
|
catch (err) {
|
|
185
153
|
this.executeProgressHook(progress_hook_types_1.PROGRESS_HOOK.SEND_TX_04_04);
|
|
@@ -202,7 +170,7 @@ class Orchestrator {
|
|
|
202
170
|
const [whitelistPda] = web3_js_1.PublicKey.findProgramAddressSync([(0, viem_1.stringToBytes)('whitelist')], programId);
|
|
203
171
|
const userPk = new web3_js_1.PublicKey(this.universalSigner.account.address);
|
|
204
172
|
// pay-with-token gas abstraction is not supported on Solana
|
|
205
|
-
if (
|
|
173
|
+
if (execute.payGasWith !== undefined) {
|
|
206
174
|
throw new Error('Pay-with token is not supported on Solana');
|
|
207
175
|
}
|
|
208
176
|
let txSignature;
|
|
@@ -365,13 +333,13 @@ class Orchestrator {
|
|
|
365
333
|
}
|
|
366
334
|
const mechanism = execute.funds.token.mechanism;
|
|
367
335
|
const { deployed, nonce } = yield this.getUeaStatusAndNonce();
|
|
368
|
-
const { payload: universalPayload } = yield this.buildGatewayPayloadAndGas(execute, nonce
|
|
336
|
+
const { payload: universalPayload } = yield this.buildGatewayPayloadAndGas(execute, nonce);
|
|
369
337
|
this.executeProgressHook(progress_hook_types_1.PROGRESS_HOOK.SEND_TX_02_01);
|
|
370
338
|
// Compute required gas funding on Push Chain and current UEA balance
|
|
371
339
|
const gasEstimate = execute.gasLimit || BigInt(1e7);
|
|
372
340
|
const gasPrice = yield this.pushClient.getGasPrice();
|
|
373
341
|
const requiredGasFee = gasEstimate * gasPrice;
|
|
374
|
-
const payloadValue = (
|
|
342
|
+
const payloadValue = (_a = execute.value) !== null && _a !== void 0 ? _a : BigInt(0);
|
|
375
343
|
const requiredFunds = requiredGasFee + payloadValue;
|
|
376
344
|
const ueaAddress = this.computeUEAOffchain();
|
|
377
345
|
const [ueaBalance] = yield Promise.all([
|
|
@@ -404,8 +372,8 @@ class Orchestrator {
|
|
|
404
372
|
functionName: 'config',
|
|
405
373
|
args: [configPda.toBase58()],
|
|
406
374
|
});
|
|
407
|
-
const minField = (
|
|
408
|
-
const maxField = (
|
|
375
|
+
const minField = (_b = cfg.minCapUniversalTxUsd) !== null && _b !== void 0 ? _b : cfg.min_cap_universal_tx_usd;
|
|
376
|
+
const maxField = (_c = cfg.maxCapUniversalTxUsd) !== null && _c !== void 0 ? _c : cfg.max_cap_universal_tx_usd;
|
|
409
377
|
const minCapUsd = BigInt(minField.toString());
|
|
410
378
|
const maxCapUsd = BigInt(maxField.toString());
|
|
411
379
|
if (depositUsd < minCapUsd)
|
|
@@ -417,7 +385,7 @@ class Orchestrator {
|
|
|
417
385
|
if (depositUsd > maxCapUsd)
|
|
418
386
|
depositUsd = maxCapUsd;
|
|
419
387
|
}
|
|
420
|
-
catch (
|
|
388
|
+
catch (_k) {
|
|
421
389
|
// best-effort; fallback to previous bounds if read fails
|
|
422
390
|
}
|
|
423
391
|
}
|
|
@@ -466,25 +434,10 @@ class Orchestrator {
|
|
|
466
434
|
: (0, viem_1.bytesToHex)(eip712Signature);
|
|
467
435
|
const evmClientEvm = evmClient;
|
|
468
436
|
const gatewayAddressEvm = gatewayAddress;
|
|
469
|
-
// @@@@@@@@@@@@
|
|
470
|
-
// txHash = await evmClientEvm.writeContract({
|
|
471
|
-
// abi: UNIVERSAL_GATEWAY_V0 as unknown as Abi,
|
|
472
|
-
// address: gatewayAddressEvm,
|
|
473
|
-
// functionName: 'sendTxWithFunds',
|
|
474
|
-
// args: [
|
|
475
|
-
// tokenAddr,
|
|
476
|
-
// bridgeAmount,
|
|
477
|
-
// universalPayload,
|
|
478
|
-
// revertCFG,
|
|
479
|
-
// '0x',
|
|
480
|
-
// ],
|
|
481
|
-
// signer: this.universalSigner,
|
|
482
|
-
// value: nativeAmount,
|
|
483
|
-
// });
|
|
484
437
|
// New behavior: if user provided a gasTokenAddress, pay gas in that token via Uniswap quote
|
|
485
438
|
// Determine pay-with token address, min-out and slippage
|
|
486
|
-
const payWith = execute.
|
|
487
|
-
const gasTokenAddress = (
|
|
439
|
+
const payWith = execute.payGasWith;
|
|
440
|
+
const gasTokenAddress = (_d = payWith === null || payWith === void 0 ? void 0 : payWith.token) === null || _d === void 0 ? void 0 : _d.address;
|
|
488
441
|
if (gasTokenAddress) {
|
|
489
442
|
if (chain !== enums_1.CHAIN.ETHEREUM_SEPOLIA) {
|
|
490
443
|
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`);
|
|
@@ -492,7 +445,7 @@ class Orchestrator {
|
|
|
492
445
|
let amountOutMinETH = (payWith === null || payWith === void 0 ? void 0 : payWith.minAmountOut) !== undefined
|
|
493
446
|
? BigInt(payWith.minAmountOut)
|
|
494
447
|
: nativeAmount;
|
|
495
|
-
const slippageBps = (
|
|
448
|
+
const slippageBps = (_e = payWith === null || payWith === void 0 ? void 0 : payWith.slippageBps) !== null && _e !== void 0 ? _e : 100;
|
|
496
449
|
amountOutMinETH = BigInt(push_chain_1.PushChain.utils.conversion.slippageToMinAmount(amountOutMinETH.toString(), { slippageBps }));
|
|
497
450
|
const { gasAmount } = yield this.calculateGasAmountFromAmountOutMinETH(gasTokenAddress, amountOutMinETH);
|
|
498
451
|
const deadline = BigInt(0);
|
|
@@ -504,8 +457,8 @@ class Orchestrator {
|
|
|
504
457
|
ownerAddress,
|
|
505
458
|
});
|
|
506
459
|
if (gasTokenBalance < gasAmount) {
|
|
507
|
-
const sym = (
|
|
508
|
-
const decimals = (
|
|
460
|
+
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';
|
|
461
|
+
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;
|
|
509
462
|
const needFmt = push_chain_1.PushChain.utils.helpers.formatUnits(gasAmount, decimals);
|
|
510
463
|
const haveFmt = push_chain_1.PushChain.utils.helpers.formatUnits(gasTokenBalance, decimals);
|
|
511
464
|
throw new Error(`Insufficient ${sym} balance to cover gas fees: need ${needFmt}, have ${haveFmt}`);
|
|
@@ -526,7 +479,7 @@ class Orchestrator {
|
|
|
526
479
|
deadline,
|
|
527
480
|
universalPayload,
|
|
528
481
|
revertCFG,
|
|
529
|
-
|
|
482
|
+
eip712SignatureHex,
|
|
530
483
|
],
|
|
531
484
|
signer: this.universalSigner,
|
|
532
485
|
});
|
|
@@ -542,7 +495,7 @@ class Orchestrator {
|
|
|
542
495
|
bridgeAmount,
|
|
543
496
|
universalPayload,
|
|
544
497
|
revertCFG,
|
|
545
|
-
|
|
498
|
+
eip712SignatureHex,
|
|
546
499
|
],
|
|
547
500
|
signer: this.universalSigner,
|
|
548
501
|
value: nativeAmount,
|
|
@@ -562,7 +515,7 @@ class Orchestrator {
|
|
|
562
515
|
const userPk = new web3_js_1.PublicKey(this.universalSigner.account.address);
|
|
563
516
|
const priceUpdatePk = new web3_js_1.PublicKey('7UVimffxr9ow1uXYxsr4LHAcV58mLzhmwaeKvJ1pjLiE');
|
|
564
517
|
// pay-with-token gas abstraction is not supported on Solana
|
|
565
|
-
if (
|
|
518
|
+
if (execute.payGasWith !== undefined) {
|
|
566
519
|
throw new Error('Pay-with token is not supported on Solana');
|
|
567
520
|
}
|
|
568
521
|
const isNative = mechanism === 'native' || execute.funds.token.symbol === 'SOL';
|
|
@@ -708,10 +661,6 @@ class Orchestrator {
|
|
|
708
661
|
if (execute.value === undefined) {
|
|
709
662
|
execute.value = BigInt(0);
|
|
710
663
|
}
|
|
711
|
-
// Validate fundGas property - must not be set for now
|
|
712
|
-
if (execute.fundGas) {
|
|
713
|
-
throw new Error('Unsupported token');
|
|
714
|
-
}
|
|
715
664
|
const chain = this.universalSigner.account.chain;
|
|
716
665
|
this.executeProgressHook(progress_hook_types_1.PROGRESS_HOOK.SEND_TX_01, chain);
|
|
717
666
|
this.validateMainnetConnection(chain);
|
|
@@ -765,6 +714,7 @@ class Orchestrator {
|
|
|
765
714
|
enums_1.CHAIN.ARBITRUM_SEPOLIA,
|
|
766
715
|
enums_1.CHAIN.BASE_SEPOLIA,
|
|
767
716
|
enums_1.CHAIN.SOLANA_DEVNET,
|
|
717
|
+
enums_1.CHAIN.BNB_TESTNET,
|
|
768
718
|
];
|
|
769
719
|
if (!allowedChains.includes(this.universalSigner.account.chain)) {
|
|
770
720
|
throw new Error('Multicall is only enabled for Ethereum Sepolia, Arbitrum Sepolia, Base Sepolia, and Solana Devnet');
|
|
@@ -807,7 +757,7 @@ class Orchestrator {
|
|
|
807
757
|
to: payloadTo,
|
|
808
758
|
value: execute.value,
|
|
809
759
|
data: payloadData,
|
|
810
|
-
gasLimit: execute.gasLimit || BigInt(
|
|
760
|
+
gasLimit: execute.gasLimit || BigInt(1e7),
|
|
811
761
|
maxFeePerGas: execute.maxFeePerGas || BigInt(1e10),
|
|
812
762
|
maxPriorityFeePerGas: execute.maxPriorityFeePerGas || BigInt(0),
|
|
813
763
|
nonce,
|
|
@@ -843,101 +793,28 @@ class Orchestrator {
|
|
|
843
793
|
}
|
|
844
794
|
else {
|
|
845
795
|
/**
|
|
846
|
-
* Fee Locking
|
|
796
|
+
* Fee Locking
|
|
847
797
|
*/
|
|
848
798
|
const fundDifference = requiredFunds - funds;
|
|
849
799
|
const fixedPushAmount = push_chain_1.PushChain.utils.helpers.parseUnits('0.001', 18); // Minimum lock 0.001 Push tokens
|
|
850
800
|
const lockAmount = funds < requiredFunds ? fundDifference : fixedPushAmount;
|
|
851
801
|
const lockAmountInUSD = this.pushClient.pushToUSDC(lockAmount);
|
|
852
802
|
this.executeProgressHook(progress_hook_types_1.PROGRESS_HOOK.SEND_TX_05_01, lockAmount);
|
|
853
|
-
const feeLockTxHashBytes = yield this.lockFee(lockAmountInUSD,
|
|
803
|
+
const feeLockTxHashBytes = yield this.lockFee(lockAmountInUSD, executionHash);
|
|
854
804
|
feeLockTxHash = (0, viem_1.bytesToHex)(feeLockTxHashBytes);
|
|
855
805
|
verificationData = (0, viem_1.bytesToHex)(feeLockTxHashBytes);
|
|
806
|
+
/**
|
|
807
|
+
* Waiting for Confirmations
|
|
808
|
+
*/
|
|
856
809
|
const { vm } = chain_1.CHAIN_INFO[chain];
|
|
857
810
|
this.executeProgressHook(progress_hook_types_1.PROGRESS_HOOK.SEND_TX_05_02, vm === enums_1.VM.SVM
|
|
858
811
|
? anchor_1.utils.bytes.bs58.encode(feeLockTxHashBytes)
|
|
859
812
|
: feeLockTxHash, chain_1.CHAIN_INFO[chain].confirmations);
|
|
860
|
-
// Waiting for blocks confirmations
|
|
861
813
|
yield this.waitForLockerFeeConfirmation(feeLockTxHashBytes);
|
|
862
814
|
this.executeProgressHook(progress_hook_types_1.PROGRESS_HOOK.SEND_TX_05_03);
|
|
863
|
-
// Query nodes via gRPC for Push Chain transaction
|
|
864
|
-
const { defaultRPC, lockerContract } = chain_1.CHAIN_INFO[chain];
|
|
865
|
-
yield this.queryUniversalTxStatusFromGatewayTx(new evm_client_1.EvmClient({ rpcUrls: this.rpcUrls[chain] || defaultRPC }), lockerContract, feeLockTxHash, 'sendTxWithGas');
|
|
866
|
-
/**
|
|
867
|
-
* Return response directly (skip sendUniversalTx for sendTxWithGas flow)
|
|
868
|
-
* Note: queryTx may be undefined since validators don't recognize new UniversalTx event yet
|
|
869
|
-
*/
|
|
870
|
-
this.executeProgressHook(progress_hook_types_1.PROGRESS_HOOK.SEND_TX_06);
|
|
871
|
-
// Transform to UniversalTxResponse (follow sendFunds pattern)
|
|
872
|
-
if (vm === enums_1.VM.EVM) {
|
|
873
|
-
// Get EVM transaction for full response
|
|
874
|
-
const evmClient = new evm_client_1.EvmClient({
|
|
875
|
-
rpcUrls: this.rpcUrls[chain] || chain_1.CHAIN_INFO[chain].defaultRPC,
|
|
876
|
-
});
|
|
877
|
-
const tx = yield evmClient.getTransaction(feeLockTxHash);
|
|
878
|
-
const response = yield this.transformToUniversalTxResponse(tx);
|
|
879
|
-
this.executeProgressHook(progress_hook_types_1.PROGRESS_HOOK.SEND_TX_99_01, [response]);
|
|
880
|
-
return response;
|
|
881
|
-
}
|
|
882
|
-
else {
|
|
883
|
-
// SVM: build minimal response (follow sendFunds SVM pattern)
|
|
884
|
-
const chainId = chain_1.CHAIN_INFO[chain].chainId;
|
|
885
|
-
const origin = `${chain_1.VM_NAMESPACE[vm]}:${chainId}:${this.universalSigner.account.address}`;
|
|
886
|
-
const response = {
|
|
887
|
-
hash: anchor_1.utils.bytes.bs58.encode(feeLockTxHashBytes),
|
|
888
|
-
origin,
|
|
889
|
-
blockNumber: BigInt(0),
|
|
890
|
-
blockHash: '',
|
|
891
|
-
transactionIndex: 0,
|
|
892
|
-
chainId,
|
|
893
|
-
from: this.universalSigner.account.address,
|
|
894
|
-
to: '0x0000000000000000000000000000000000000000',
|
|
895
|
-
nonce: 0,
|
|
896
|
-
data: '0x',
|
|
897
|
-
value: BigInt(0),
|
|
898
|
-
gasLimit: BigInt(0),
|
|
899
|
-
gasPrice: undefined,
|
|
900
|
-
maxFeePerGas: undefined,
|
|
901
|
-
maxPriorityFeePerGas: undefined,
|
|
902
|
-
accessList: [],
|
|
903
|
-
wait: () => tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
904
|
-
return ({
|
|
905
|
-
hash: anchor_1.utils.bytes.bs58.encode(feeLockTxHashBytes),
|
|
906
|
-
blockNumber: BigInt(0),
|
|
907
|
-
blockHash: '',
|
|
908
|
-
transactionIndex: 0,
|
|
909
|
-
from: this.universalSigner.account.address,
|
|
910
|
-
to: '0x0000000000000000000000000000000000000000',
|
|
911
|
-
contractAddress: null,
|
|
912
|
-
gasPrice: BigInt(0),
|
|
913
|
-
gasUsed: BigInt(0),
|
|
914
|
-
cumulativeGasUsed: BigInt(0),
|
|
915
|
-
logs: [],
|
|
916
|
-
logsBloom: '0x',
|
|
917
|
-
status: 1,
|
|
918
|
-
raw: {
|
|
919
|
-
from: this.universalSigner.account.address,
|
|
920
|
-
to: '0x0000000000000000000000000000000000000000',
|
|
921
|
-
},
|
|
922
|
-
});
|
|
923
|
-
}),
|
|
924
|
-
type: '99',
|
|
925
|
-
typeVerbose: 'universal',
|
|
926
|
-
signature: { r: '0x0', s: '0x0', v: 0 },
|
|
927
|
-
raw: {
|
|
928
|
-
from: this.universalSigner.account.address,
|
|
929
|
-
to: '0x0000000000000000000000000000000000000000',
|
|
930
|
-
nonce: 0,
|
|
931
|
-
data: '0x',
|
|
932
|
-
value: BigInt(0),
|
|
933
|
-
},
|
|
934
|
-
};
|
|
935
|
-
this.executeProgressHook(progress_hook_types_1.PROGRESS_HOOK.SEND_TX_99_01, [response]);
|
|
936
|
-
return response;
|
|
937
|
-
}
|
|
938
815
|
}
|
|
939
816
|
/**
|
|
940
|
-
*
|
|
817
|
+
* Broadcasting Tx to PC
|
|
941
818
|
*/
|
|
942
819
|
this.executeProgressHook(progress_hook_types_1.PROGRESS_HOOK.SEND_TX_06);
|
|
943
820
|
const transactions = yield this.sendUniversalTx(isUEADeployed, feeLockTxHash, universalPayload, verificationData);
|
|
@@ -967,11 +844,11 @@ class Orchestrator {
|
|
|
967
844
|
*
|
|
968
845
|
* @param amount - Fee amount in USDC (8 Decimals)
|
|
969
846
|
* @param executionHash - Optional execution payload hash (default: zeroHash)
|
|
970
|
-
* @returns Transaction hash
|
|
847
|
+
* @returns Transaction hash of the locking transaction
|
|
971
848
|
*/
|
|
972
|
-
lockFee(
|
|
973
|
-
|
|
974
|
-
|
|
849
|
+
lockFee(amount_1) {
|
|
850
|
+
return tslib_1.__awaiter(this, arguments, void 0, function* (amount, // USD with 8 decimals
|
|
851
|
+
executionHash = viem_1.zeroHash) {
|
|
975
852
|
const chain = this.universalSigner.account.chain;
|
|
976
853
|
const { lockerContract, vm, defaultRPC } = chain_1.CHAIN_INFO[chain];
|
|
977
854
|
if (!lockerContract) {
|
|
@@ -986,88 +863,35 @@ class Orchestrator {
|
|
|
986
863
|
Promise.resolve(new evm_client_1.EvmClient({ rpcUrls })),
|
|
987
864
|
]);
|
|
988
865
|
const nativeDecimals = 18; // ETH, MATIC, etc.
|
|
989
|
-
|
|
990
|
-
const oneUsd = push_chain_1.PushChain.utils.helpers.parseUnits('1', 8);
|
|
991
|
-
const tenUsd = push_chain_1.PushChain.utils.helpers.parseUnits('10', 8);
|
|
992
|
-
let depositUsd = amount < oneUsd ? oneUsd : amount;
|
|
993
|
-
if (depositUsd > tenUsd)
|
|
994
|
-
depositUsd = tenUsd;
|
|
995
|
-
// Ceil division to avoid falling below on-chain min due to rounding, then add 1 wei safety
|
|
996
|
-
let nativeAmount = (depositUsd * BigInt(Math.pow(10, nativeDecimals)) +
|
|
997
|
-
(nativeTokenUsdPrice - BigInt(1))) /
|
|
998
|
-
nativeTokenUsdPrice;
|
|
999
|
-
nativeAmount = nativeAmount + BigInt(1);
|
|
1000
|
-
// Deposit-only funding via UniversalGatewayV0 (no payload execution)
|
|
1001
|
-
const revertCFG = {
|
|
1002
|
-
fundRecipient: this.universalSigner.account.address,
|
|
1003
|
-
revertMsg: '0x',
|
|
1004
|
-
};
|
|
1005
|
-
// Sign the universal payload
|
|
1006
|
-
const ueaAddress = this.computeUEAOffchain();
|
|
1007
|
-
const ueaVersion = yield this.fetchUEAVersion();
|
|
1008
|
-
const eip712Signature = yield this.signUniversalPayload(universalPayload, ueaAddress, ueaVersion);
|
|
1009
|
-
const eip712SignatureHex = typeof eip712Signature === 'string'
|
|
1010
|
-
? eip712Signature
|
|
1011
|
-
: (0, viem_1.bytesToHex)(eip712Signature);
|
|
866
|
+
const nativeAmount = (amount * BigInt(Math.pow(10, nativeDecimals))) / nativeTokenUsdPrice;
|
|
1012
867
|
const txHash = yield evmClient.writeContract({
|
|
1013
|
-
abi: abi_1.
|
|
868
|
+
abi: abi_1.FEE_LOCKER_EVM,
|
|
1014
869
|
address: lockerContract,
|
|
1015
|
-
functionName: '
|
|
1016
|
-
args: [
|
|
870
|
+
functionName: 'addFunds',
|
|
871
|
+
args: [executionHash],
|
|
1017
872
|
signer: this.universalSigner,
|
|
1018
873
|
value: nativeAmount,
|
|
1019
874
|
});
|
|
1020
875
|
return (0, viem_1.hexToBytes)(txHash);
|
|
1021
876
|
}
|
|
1022
877
|
case enums_1.VM.SVM: {
|
|
1023
|
-
// Run price fetching
|
|
1024
|
-
const [nativeTokenUsdPrice, svmClient] = yield Promise.all([
|
|
878
|
+
// Run price fetching, client creation, and PDA computation in parallel
|
|
879
|
+
const [nativeTokenUsdPrice, svmClient, [lockerPda]] = yield Promise.all([
|
|
1025
880
|
new price_fetch_1.PriceFetch(this.rpcUrls).getPrice(chain), // 8 decimals
|
|
1026
881
|
Promise.resolve(new svm_client_1.SvmClient({ rpcUrls })),
|
|
882
|
+
Promise.resolve(anchor.web3.PublicKey.findProgramAddressSync([(0, viem_1.stringToBytes)('locker')], new web3_js_1.PublicKey(lockerContract))),
|
|
1027
883
|
]);
|
|
1028
|
-
// Ensure deposit respects gateway USD caps (min $1, max $10) and avoid rounding below min
|
|
1029
884
|
const nativeDecimals = 9; // SOL lamports
|
|
1030
|
-
const
|
|
1031
|
-
const tenUsd = push_chain_1.PushChain.utils.helpers.parseUnits('10', 8);
|
|
1032
|
-
let depositUsd = amount < oneUsd ? oneUsd : amount;
|
|
1033
|
-
if (depositUsd > tenUsd)
|
|
1034
|
-
depositUsd = tenUsd;
|
|
1035
|
-
// Ceil division to avoid falling below on-chain min due to rounding, then add 1 lamport safety
|
|
1036
|
-
let nativeAmount = (depositUsd * BigInt(Math.pow(10, nativeDecimals)) +
|
|
1037
|
-
(nativeTokenUsdPrice - BigInt(1))) /
|
|
1038
|
-
nativeTokenUsdPrice;
|
|
1039
|
-
nativeAmount = nativeAmount + BigInt(1);
|
|
1040
|
-
// Program & PDAs
|
|
1041
|
-
const programId = new web3_js_1.PublicKey(abi_1.SVM_GATEWAY_IDL.address);
|
|
1042
|
-
const [configPda] = web3_js_1.PublicKey.findProgramAddressSync([(0, viem_1.stringToBytes)('config')], programId);
|
|
1043
|
-
const [vaultPda] = web3_js_1.PublicKey.findProgramAddressSync([(0, viem_1.stringToBytes)('vault')], programId);
|
|
1044
|
-
const userPk = new web3_js_1.PublicKey(this.universalSigner.account.address);
|
|
1045
|
-
const revertSvm = {
|
|
1046
|
-
fundRecipient: userPk,
|
|
1047
|
-
revertMsg: Buffer.from([]),
|
|
1048
|
-
};
|
|
1049
|
-
// const ueaAddressSvm = this.computeUEAOffchain();
|
|
1050
|
-
// const ueaVersion = await this.fetchUEAVersion();
|
|
1051
|
-
// const svmSignature = await this.signUniversalPayload(
|
|
1052
|
-
// universalPayload,
|
|
1053
|
-
// ueaAddressSvm,
|
|
1054
|
-
// ueaVersion
|
|
1055
|
-
// );
|
|
885
|
+
const nativeAmount = (amount * BigInt(Math.pow(10, nativeDecimals))) / nativeTokenUsdPrice;
|
|
1056
886
|
const txHash = yield svmClient.writeContract({
|
|
1057
|
-
abi: abi_1.
|
|
1058
|
-
address:
|
|
1059
|
-
functionName: '
|
|
1060
|
-
args: [
|
|
1061
|
-
universalPayload,
|
|
1062
|
-
revertSvm,
|
|
1063
|
-
new anchor.BN(nativeAmount.toString()),
|
|
1064
|
-
'0x',
|
|
1065
|
-
],
|
|
887
|
+
abi: abi_1.FEE_LOCKER_SVM,
|
|
888
|
+
address: lockerContract,
|
|
889
|
+
functionName: 'addFunds',
|
|
890
|
+
args: [nativeAmount, (0, viem_1.toBytes)(executionHash)],
|
|
1066
891
|
signer: this.universalSigner,
|
|
1067
892
|
accounts: {
|
|
1068
|
-
|
|
1069
|
-
|
|
1070
|
-
user: userPk,
|
|
893
|
+
locker: lockerPda,
|
|
894
|
+
user: new web3_js_1.PublicKey(this.universalSigner.account.address),
|
|
1071
895
|
priceUpdate: new web3_js_1.PublicKey('7UVimffxr9ow1uXYxsr4LHAcV58mLzhmwaeKvJ1pjLiE'),
|
|
1072
896
|
systemProgram: web3_js_1.SystemProgram.programId,
|
|
1073
897
|
},
|
|
@@ -1406,12 +1230,20 @@ class Orchestrator {
|
|
|
1406
1230
|
switch (vm) {
|
|
1407
1231
|
case enums_1.VM.EVM: {
|
|
1408
1232
|
const evmClient = new evm_client_1.EvmClient({ rpcUrls });
|
|
1409
|
-
yield
|
|
1233
|
+
yield evmClient.waitForConfirmations({
|
|
1234
|
+
txHash: (0, viem_1.bytesToHex)(txHashBytes),
|
|
1235
|
+
confirmations,
|
|
1236
|
+
timeoutMs: timeout,
|
|
1237
|
+
});
|
|
1410
1238
|
return;
|
|
1411
1239
|
}
|
|
1412
1240
|
case enums_1.VM.SVM: {
|
|
1413
1241
|
const svmClient = new svm_client_1.SvmClient({ rpcUrls });
|
|
1414
|
-
yield
|
|
1242
|
+
yield svmClient.waitForConfirmations({
|
|
1243
|
+
txSignature: anchor_1.utils.bytes.bs58.encode(txHashBytes),
|
|
1244
|
+
confirmations,
|
|
1245
|
+
timeoutMs: timeout,
|
|
1246
|
+
});
|
|
1415
1247
|
return;
|
|
1416
1248
|
}
|
|
1417
1249
|
default:
|
|
@@ -1641,65 +1473,26 @@ class Orchestrator {
|
|
|
1641
1473
|
});
|
|
1642
1474
|
}
|
|
1643
1475
|
/**
|
|
1644
|
-
*
|
|
1476
|
+
* Builds UniversalPayload for the gateway and computes the native gas deposit.
|
|
1645
1477
|
*/
|
|
1646
|
-
buildGatewayPayloadAndGas(execute, nonce
|
|
1478
|
+
buildGatewayPayloadAndGas(execute, nonce) {
|
|
1647
1479
|
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
1648
1480
|
var _a, _b;
|
|
1649
1481
|
const gasEstimate = execute.gasLimit || BigInt(1e7);
|
|
1650
1482
|
const payloadValue = (_a = execute.value) !== null && _a !== void 0 ? _a : BigInt(0);
|
|
1651
1483
|
const gasAmount = (_b = execute.value) !== null && _b !== void 0 ? _b : BigInt(0);
|
|
1652
|
-
|
|
1653
|
-
|
|
1654
|
-
|
|
1655
|
-
|
|
1656
|
-
|
|
1657
|
-
|
|
1658
|
-
|
|
1659
|
-
|
|
1660
|
-
|
|
1661
|
-
|
|
1662
|
-
|
|
1663
|
-
|
|
1664
|
-
if (type === 'sendTxWithFunds') {
|
|
1665
|
-
if (fundsValue)
|
|
1666
|
-
throw new Error('fundsValue property must be empty');
|
|
1667
|
-
const universalPayload = {
|
|
1668
|
-
to: execute.to,
|
|
1669
|
-
value: payloadValue,
|
|
1670
|
-
data: execute.data || '0x',
|
|
1671
|
-
gasLimit: gasEstimate,
|
|
1672
|
-
maxFeePerGas: execute.maxFeePerGas || BigInt(1e10),
|
|
1673
|
-
maxPriorityFeePerGas: execute.maxPriorityFeePerGas || BigInt(0),
|
|
1674
|
-
nonce,
|
|
1675
|
-
deadline: execute.deadline || BigInt(9999999999),
|
|
1676
|
-
vType: tx_1.VerificationType.universalTxVerification,
|
|
1677
|
-
};
|
|
1678
|
-
return { payload: universalPayload, gasAmount };
|
|
1679
|
-
}
|
|
1680
|
-
else {
|
|
1681
|
-
if (!fundsValue)
|
|
1682
|
-
throw new Error('fundsValue property must not be empty');
|
|
1683
|
-
// The data will be the abi-encoded transfer function from erc-20 function. The recipient will be `execute.to`, the value
|
|
1684
|
-
// will be the fundsValue property.
|
|
1685
|
-
const data = (0, viem_1.encodeFunctionData)({
|
|
1686
|
-
abi: abi_1.ERC20_EVM,
|
|
1687
|
-
functionName: 'transfer',
|
|
1688
|
-
args: [execute.to, fundsValue],
|
|
1689
|
-
});
|
|
1690
|
-
const universalPayload = {
|
|
1691
|
-
to: viem_1.zeroAddress, // We can't simply do `0x` because we will get an error when eip712 signing the transaction.
|
|
1692
|
-
value: payloadValue,
|
|
1693
|
-
data,
|
|
1694
|
-
gasLimit: gasEstimate,
|
|
1695
|
-
maxFeePerGas: execute.maxFeePerGas || BigInt(1e10),
|
|
1696
|
-
maxPriorityFeePerGas: execute.maxPriorityFeePerGas || BigInt(0),
|
|
1697
|
-
nonce,
|
|
1698
|
-
deadline: execute.deadline || BigInt(9999999999),
|
|
1699
|
-
vType: tx_1.VerificationType.universalTxVerification,
|
|
1700
|
-
};
|
|
1701
|
-
return { payload: universalPayload, gasAmount };
|
|
1702
|
-
}
|
|
1484
|
+
const universalPayload = {
|
|
1485
|
+
to: execute.to,
|
|
1486
|
+
value: payloadValue,
|
|
1487
|
+
data: execute.data || '0x',
|
|
1488
|
+
gasLimit: gasEstimate,
|
|
1489
|
+
maxFeePerGas: execute.maxFeePerGas || BigInt(1e10),
|
|
1490
|
+
maxPriorityFeePerGas: execute.maxPriorityFeePerGas || BigInt(0),
|
|
1491
|
+
nonce,
|
|
1492
|
+
deadline: execute.deadline || BigInt(9999999999),
|
|
1493
|
+
vType: tx_1.VerificationType.signedVerification,
|
|
1494
|
+
};
|
|
1495
|
+
return { payload: universalPayload, gasAmount };
|
|
1703
1496
|
});
|
|
1704
1497
|
}
|
|
1705
1498
|
/********************************** HELPER FUNCTIONS **************************************************/
|
|
@@ -1945,16 +1738,15 @@ class Orchestrator {
|
|
|
1945
1738
|
continue;
|
|
1946
1739
|
const discriminatorHex = (0, viem_1.bytesToHex)(decoded.slice(0, 8)).slice(2);
|
|
1947
1740
|
// Skip add_funds discriminator; return the first other Program data event
|
|
1948
|
-
|
|
1949
|
-
|
|
1950
|
-
|
|
1951
|
-
// return i;
|
|
1741
|
+
if (discriminatorHex === '7f1f6cffbb134644')
|
|
1742
|
+
continue;
|
|
1743
|
+
return i;
|
|
1952
1744
|
}
|
|
1953
1745
|
// Fallback to first log
|
|
1954
1746
|
return 0;
|
|
1955
1747
|
}
|
|
1956
1748
|
// Query Push Chain for UniversalTx status given an origin gateway tx (EVM or SVM)
|
|
1957
|
-
queryUniversalTxStatusFromGatewayTx(evmClient, gatewayAddress, txHash,
|
|
1749
|
+
queryUniversalTxStatusFromGatewayTx(evmClient, gatewayAddress, txHash, fromBranch) {
|
|
1958
1750
|
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
1959
1751
|
var _a, _b;
|
|
1960
1752
|
try {
|
|
@@ -1965,22 +1757,11 @@ class Orchestrator {
|
|
|
1965
1757
|
if (vm === enums_1.VM.EVM) {
|
|
1966
1758
|
if (!evmClient || !gatewayAddress)
|
|
1967
1759
|
throw new Error('Missing EVM context');
|
|
1968
|
-
|
|
1969
|
-
|
|
1970
|
-
|
|
1971
|
-
hash: txHash,
|
|
1972
|
-
});
|
|
1973
|
-
}
|
|
1974
|
-
catch (_c) {
|
|
1975
|
-
// Receipt might not be indexed yet on this RPC; wait briefly for it
|
|
1976
|
-
receipt = yield evmClient.publicClient.waitForTransactionReceipt({
|
|
1977
|
-
hash: txHash,
|
|
1978
|
-
confirmations: 0,
|
|
1979
|
-
timeout: chain_1.CHAIN_INFO[chain].timeout,
|
|
1980
|
-
});
|
|
1981
|
-
}
|
|
1760
|
+
const receipt = yield evmClient.publicClient.getTransactionReceipt({
|
|
1761
|
+
hash: txHash,
|
|
1762
|
+
});
|
|
1982
1763
|
const gatewayLogs = (receipt.logs || []).filter((l) => (l.address || '').toLowerCase() === gatewayAddress.toLowerCase());
|
|
1983
|
-
const logIndexToUse =
|
|
1764
|
+
const logIndexToUse = fromBranch === 'sendTxWithFunds' ? 1 : 0;
|
|
1984
1765
|
const firstLog = (gatewayLogs[logIndexToUse] ||
|
|
1985
1766
|
((_a = receipt.logs) === null || _a === void 0 ? void 0 : _a[logIndexToUse]));
|
|
1986
1767
|
const logIndexVal = (_b = firstLog === null || firstLog === void 0 ? void 0 : firstLog.logIndex) !== null && _b !== void 0 ? _b : 0;
|
|
@@ -2048,7 +1829,7 @@ class Orchestrator {
|
|
|
2048
1829
|
// );
|
|
2049
1830
|
return universalTxObj;
|
|
2050
1831
|
}
|
|
2051
|
-
catch (
|
|
1832
|
+
catch (_c) {
|
|
2052
1833
|
// Best-effort; do not fail flow if PC query is unavailable
|
|
2053
1834
|
this.executeProgressHook(progress_hook_types_1.PROGRESS_HOOK.SEND_TX_06_06);
|
|
2054
1835
|
return undefined;
|
|
@@ -2066,31 +1847,15 @@ class Orchestrator {
|
|
|
2066
1847
|
hash: txHash,
|
|
2067
1848
|
});
|
|
2068
1849
|
const targetBlock = receipt.blockNumber + BigInt(confirmations);
|
|
2069
|
-
// Track last emitted confirmation to avoid duplicates
|
|
2070
|
-
let lastEmitted = 0;
|
|
2071
1850
|
// Poll blocks and emit remaining confirmations
|
|
2072
1851
|
// eslint-disable-next-line no-constant-condition
|
|
2073
1852
|
while (true) {
|
|
2074
1853
|
const currentBlock = yield evmClient.publicClient.getBlockNumber();
|
|
2075
|
-
|
|
2076
|
-
if (currentBlock >= targetBlock) {
|
|
2077
|
-
// Only emit if we haven't already shown this confirmation
|
|
2078
|
-
if (lastEmitted < confirmations) {
|
|
2079
|
-
this.executeProgressHook(progress_hook_types_1.PROGRESS_HOOK.SEND_TX_06_04, confirmations, confirmations);
|
|
2080
|
-
}
|
|
1854
|
+
if (currentBlock >= targetBlock)
|
|
2081
1855
|
return;
|
|
2082
|
-
}
|
|
2083
1856
|
const remaining = Number(targetBlock - currentBlock);
|
|
2084
1857
|
const completed = Math.max(1, confirmations - remaining + 1);
|
|
2085
|
-
|
|
2086
|
-
if (completed > lastEmitted) {
|
|
2087
|
-
this.executeProgressHook(progress_hook_types_1.PROGRESS_HOOK.SEND_TX_06_04, completed, confirmations);
|
|
2088
|
-
lastEmitted = completed;
|
|
2089
|
-
// If we've reached required confirmations, we're done
|
|
2090
|
-
if (completed >= confirmations) {
|
|
2091
|
-
return;
|
|
2092
|
-
}
|
|
2093
|
-
}
|
|
1858
|
+
this.executeProgressHook(progress_hook_types_1.PROGRESS_HOOK.SEND_TX_06_04, completed, confirmations);
|
|
2094
1859
|
if (Date.now() - start > timeoutMs) {
|
|
2095
1860
|
throw new Error(`Timeout: transaction ${txHash} not confirmed with ${confirmations} confirmations within ${timeoutMs} ms`);
|
|
2096
1861
|
}
|
|
@@ -2098,44 +1863,6 @@ class Orchestrator {
|
|
|
2098
1863
|
}
|
|
2099
1864
|
});
|
|
2100
1865
|
}
|
|
2101
|
-
// Emit countdown updates while waiting for SVM confirmations
|
|
2102
|
-
waitForSvmConfirmationsWithCountdown(svmClient, txSignature, confirmations, timeoutMs) {
|
|
2103
|
-
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
2104
|
-
var _a;
|
|
2105
|
-
// initial emit
|
|
2106
|
-
this.executeProgressHook(progress_hook_types_1.PROGRESS_HOOK.SEND_TX_06_03, confirmations);
|
|
2107
|
-
const start = Date.now();
|
|
2108
|
-
// Poll for confirmations and emit progress
|
|
2109
|
-
let lastConfirmed = 0;
|
|
2110
|
-
// eslint-disable-next-line no-constant-condition
|
|
2111
|
-
while (true) {
|
|
2112
|
-
const connection = svmClient.connections[svmClient.currentConnectionIndex];
|
|
2113
|
-
const { value } = yield connection.getSignatureStatuses([txSignature]);
|
|
2114
|
-
const status = value[0];
|
|
2115
|
-
if (status) {
|
|
2116
|
-
const currentConfirms = (_a = status.confirmations) !== null && _a !== void 0 ? _a : 0;
|
|
2117
|
-
const hasEnoughConfirmations = currentConfirms >= confirmations;
|
|
2118
|
-
const isSuccessfullyFinalized = status.err === null && status.confirmationStatus !== null;
|
|
2119
|
-
// Emit progress if we have more confirmations than before OR if finalized
|
|
2120
|
-
if (currentConfirms > lastConfirmed ||
|
|
2121
|
-
(isSuccessfullyFinalized && lastConfirmed === 0)) {
|
|
2122
|
-
const confirmCount = isSuccessfullyFinalized && currentConfirms === 0
|
|
2123
|
-
? confirmations
|
|
2124
|
-
: currentConfirms;
|
|
2125
|
-
this.executeProgressHook(progress_hook_types_1.PROGRESS_HOOK.SEND_TX_06_04, Math.max(1, confirmCount), confirmations);
|
|
2126
|
-
lastConfirmed = currentConfirms;
|
|
2127
|
-
}
|
|
2128
|
-
if (hasEnoughConfirmations || isSuccessfullyFinalized) {
|
|
2129
|
-
return;
|
|
2130
|
-
}
|
|
2131
|
-
}
|
|
2132
|
-
if (Date.now() - start > timeoutMs) {
|
|
2133
|
-
throw new Error(`Timeout: transaction ${txSignature} not confirmed with ${confirmations} confirmations within ${timeoutMs} ms`);
|
|
2134
|
-
}
|
|
2135
|
-
yield new Promise((r) => setTimeout(r, 500));
|
|
2136
|
-
}
|
|
2137
|
-
});
|
|
2138
|
-
}
|
|
2139
1866
|
// Fetch and cache UEA version from the contract on Push Chain
|
|
2140
1867
|
fetchUEAVersion() {
|
|
2141
1868
|
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
@@ -2201,63 +1928,6 @@ class Orchestrator {
|
|
|
2201
1928
|
return { gasAmount };
|
|
2202
1929
|
});
|
|
2203
1930
|
}
|
|
2204
|
-
calculateNativeAmountForDeposit(chain, requiredFunds, ueaBalance) {
|
|
2205
|
-
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
2206
|
-
var _a, _b;
|
|
2207
|
-
// Determine USD to deposit via gateway (8 decimals) with caps: min=$1, max=$10
|
|
2208
|
-
const oneUsd = push_chain_1.PushChain.utils.helpers.parseUnits('1', 8);
|
|
2209
|
-
const tenUsd = push_chain_1.PushChain.utils.helpers.parseUnits('10', 8);
|
|
2210
|
-
const deficit = requiredFunds > ueaBalance ? requiredFunds - ueaBalance : BigInt(0);
|
|
2211
|
-
let depositUsd = deficit > BigInt(0) ? this.pushClient.pushToUSDC(deficit) : oneUsd;
|
|
2212
|
-
if (depositUsd < oneUsd)
|
|
2213
|
-
depositUsd = oneUsd;
|
|
2214
|
-
if (depositUsd > tenUsd)
|
|
2215
|
-
throw new Error('Deposit value exceeds max $10 worth of native token');
|
|
2216
|
-
this.executeProgressHook(progress_hook_types_1.PROGRESS_HOOK.SEND_TX_02_02, depositUsd);
|
|
2217
|
-
// If SVM, clamp depositUsd to on-chain Config caps
|
|
2218
|
-
if (chain_1.CHAIN_INFO[chain].vm === enums_1.VM.SVM) {
|
|
2219
|
-
const svmClient = new svm_client_1.SvmClient({
|
|
2220
|
-
rpcUrls: this.rpcUrls[enums_1.CHAIN.SOLANA_DEVNET] ||
|
|
2221
|
-
chain_1.CHAIN_INFO[enums_1.CHAIN.SOLANA_DEVNET].defaultRPC,
|
|
2222
|
-
});
|
|
2223
|
-
const programId = new web3_js_1.PublicKey(abi_1.SVM_GATEWAY_IDL.address);
|
|
2224
|
-
const [configPda] = web3_js_1.PublicKey.findProgramAddressSync([(0, viem_1.stringToBytes)('config')], programId);
|
|
2225
|
-
try {
|
|
2226
|
-
const cfg = yield svmClient.readContract({
|
|
2227
|
-
abi: abi_1.SVM_GATEWAY_IDL,
|
|
2228
|
-
address: abi_1.SVM_GATEWAY_IDL.address,
|
|
2229
|
-
functionName: 'config',
|
|
2230
|
-
args: [configPda.toBase58()],
|
|
2231
|
-
});
|
|
2232
|
-
const minField = (_a = cfg.minCapUniversalTxUsd) !== null && _a !== void 0 ? _a : cfg.min_cap_universal_tx_usd;
|
|
2233
|
-
const maxField = (_b = cfg.maxCapUniversalTxUsd) !== null && _b !== void 0 ? _b : cfg.max_cap_universal_tx_usd;
|
|
2234
|
-
const minCapUsd = BigInt(minField.toString());
|
|
2235
|
-
const maxCapUsd = BigInt(maxField.toString());
|
|
2236
|
-
if (depositUsd < minCapUsd)
|
|
2237
|
-
depositUsd = minCapUsd;
|
|
2238
|
-
// Add 20% safety margin to avoid BelowMinCap due to price drift
|
|
2239
|
-
const withMargin = (minCapUsd * BigInt(12)) / BigInt(10);
|
|
2240
|
-
if (depositUsd < withMargin)
|
|
2241
|
-
depositUsd = withMargin;
|
|
2242
|
-
if (depositUsd > maxCapUsd)
|
|
2243
|
-
depositUsd = maxCapUsd;
|
|
2244
|
-
}
|
|
2245
|
-
catch (_c) {
|
|
2246
|
-
// best-effort; fallback to previous bounds if read fails
|
|
2247
|
-
}
|
|
2248
|
-
}
|
|
2249
|
-
// Convert USD(8) -> native units using pricing path
|
|
2250
|
-
const nativeTokenUsdPrice = yield new price_fetch_1.PriceFetch(this.rpcUrls).getPrice(chain); // 8 decimals
|
|
2251
|
-
const nativeDecimals = chain_1.CHAIN_INFO[chain].vm === enums_1.VM.SVM ? 9 : 18;
|
|
2252
|
-
const oneNativeUnit = push_chain_1.PushChain.utils.helpers.parseUnits('1', nativeDecimals);
|
|
2253
|
-
// Ceil division to avoid rounding below min USD on-chain
|
|
2254
|
-
let nativeAmount = (depositUsd * oneNativeUnit + (nativeTokenUsdPrice - BigInt(1))) /
|
|
2255
|
-
nativeTokenUsdPrice;
|
|
2256
|
-
// Add 1 unit safety to avoid BelowMinCap from rounding differences
|
|
2257
|
-
nativeAmount = nativeAmount + BigInt(1);
|
|
2258
|
-
return nativeAmount;
|
|
2259
|
-
});
|
|
2260
|
-
}
|
|
2261
1931
|
}
|
|
2262
1932
|
exports.Orchestrator = Orchestrator;
|
|
2263
1933
|
//# sourceMappingURL=orchestrator.js.map
|