@pushchain/core 5.1.4-alpha.10 → 5.1.4-alpha.12
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
CHANGED
|
@@ -28,6 +28,9 @@ const confirmation_1 = require("./confirmation");
|
|
|
28
28
|
const gateway_client_1 = require("./gateway-client");
|
|
29
29
|
const response_builder_1 = require("./response-builder");
|
|
30
30
|
const push_chain_tx_1 = require("./push-chain-tx");
|
|
31
|
+
const gas_calculator_1 = require("./gas-calculator");
|
|
32
|
+
const helpers_2 = require("./helpers");
|
|
33
|
+
const price_fetch_1 = require("../../price-fetch/price-fetch");
|
|
31
34
|
function executeStandardPayload(ctx, execute, eventBuffer, getResponseCallbacks) {
|
|
32
35
|
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
33
36
|
var _a, _b;
|
|
@@ -202,6 +205,52 @@ function executeStandardPayload(ctx, execute, eventBuffer, getResponseCallbacks)
|
|
|
202
205
|
const effectiveLockAmountInUSD = execute._minimumDepositUsd && execute._minimumDepositUsd > lockAmountInUSD
|
|
203
206
|
? execute._minimumDepositUsd
|
|
204
207
|
: lockAmountInUSD;
|
|
208
|
+
// Pre-flight: predict the actual $PC the UEA will receive after the
|
|
209
|
+
// on-chain pETH → WPC swap and validate it covers requiredFunds.
|
|
210
|
+
// Uses the same Uniswap V3 quoter the chain uses (execute_inbound_gas.go).
|
|
211
|
+
// Mirrors the pattern in route-handlers.ts (Route 2/3).
|
|
212
|
+
const { vm: originVm } = chain_1.CHAIN_INFO[chain];
|
|
213
|
+
if (originVm === enums_1.VM.EVM) {
|
|
214
|
+
try {
|
|
215
|
+
// Replicate lockFee's USD → native conversion (with its $1–$10 clamp)
|
|
216
|
+
const oneUsd = utils_1.Utils.helpers.parseUnits('1', 8);
|
|
217
|
+
const tenUsd = utils_1.Utils.helpers.parseUnits('10', 8);
|
|
218
|
+
let depositUsd = effectiveLockAmountInUSD < oneUsd ? oneUsd : effectiveLockAmountInUSD;
|
|
219
|
+
if (depositUsd > tenUsd)
|
|
220
|
+
depositUsd = tenUsd;
|
|
221
|
+
const ethPrice = yield new price_fetch_1.PriceFetch(ctx.rpcUrls).getPrice(chain);
|
|
222
|
+
if (ethPrice > BigInt(0)) {
|
|
223
|
+
const nativeAmountETH = (depositUsd * BigInt(1e18) + (ethPrice - BigInt(1))) / ethPrice + BigInt(1);
|
|
224
|
+
const originPrc20 = (0, helpers_2.getNativePRC20ForChain)(chain, ctx.pushNetwork);
|
|
225
|
+
const predictedUPC = yield (0, gas_calculator_1.estimateDepositFromLockedNative)(ctx, nativeAmountETH, originPrc20);
|
|
226
|
+
if (predictedUPC > BigInt(0)) {
|
|
227
|
+
// 10% slippage margin (same as route-handlers.ts)
|
|
228
|
+
const safeUPC = (predictedUPC * BigInt(90)) / BigInt(100);
|
|
229
|
+
const totalAvailable = safeUPC + funds;
|
|
230
|
+
(0, context_1.printLog)(ctx, `Fee-lock pre-flight: deposit ${depositUsd.toString()} USD → ` +
|
|
231
|
+
`~${nativeAmountETH.toString()} wei ETH → ~${predictedUPC.toString()} UPC ` +
|
|
232
|
+
`(safe: ${safeUPC.toString()}), existing: ${funds.toString()}, ` +
|
|
233
|
+
`total: ${totalAvailable.toString()}, required: ${requiredFunds.toString()}`);
|
|
234
|
+
if (totalAvailable < requiredFunds) {
|
|
235
|
+
const shortfall = requiredFunds - totalAvailable;
|
|
236
|
+
throw new Error(`Insufficient deposit: the fee-lock will deposit ~${(Number(safeUPC) / 1e18).toFixed(4)} $PC ` +
|
|
237
|
+
`but the transaction requires ~${(Number(requiredFunds) / 1e18).toFixed(4)} $PC ` +
|
|
238
|
+
`(shortfall: ~${(Number(shortfall) / 1e18).toFixed(4)} $PC). ` +
|
|
239
|
+
`The fee-lock deposit is capped at $10 USD. Reduce the transfer value or ` +
|
|
240
|
+
`pre-fund the UEA (${UEA}) on Push Chain.`);
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
catch (err) {
|
|
246
|
+
// If the error is our own insufficient-deposit error, rethrow it
|
|
247
|
+
if (err instanceof Error && err.message.startsWith('Insufficient deposit')) {
|
|
248
|
+
throw err;
|
|
249
|
+
}
|
|
250
|
+
// Otherwise quoter failed — log and continue (same fallback as route-handlers)
|
|
251
|
+
(0, context_1.printLog)(ctx, `Fee-lock pre-flight quote failed, proceeding without validation: ${err instanceof Error ? err.message : String(err)}`);
|
|
252
|
+
}
|
|
253
|
+
}
|
|
205
254
|
const feeLockTxHashBytes = yield (0, gateway_client_1.lockFee)(ctx, effectiveLockAmountInUSD, universalPayload, req);
|
|
206
255
|
feeLockTxHash = (0, viem_1.bytesToHex)(feeLockTxHashBytes);
|
|
207
256
|
verificationData = (0, viem_1.bytesToHex)(feeLockTxHashBytes);
|
|
@@ -195,10 +195,24 @@ function extractPcTxAndTransform(ctx, pushChainUniversalTx, gatewayTxHash, event
|
|
|
195
195
|
const lastPcTransaction = pushChainUniversalTx.pcTx.at(-1);
|
|
196
196
|
(0, context_1.printLog)(ctx, `${label} — pcTx: ` + JSON.stringify(pushChainUniversalTx.pcTx.map((p) => ({ txHash: p.txHash, status: p.status, errorMsg: p.errorMsg })), null, 2));
|
|
197
197
|
(0, context_1.printLog)(ctx, `${label} — using lastPcTransaction: ` + JSON.stringify(lastPcTransaction, null, 2));
|
|
198
|
-
if (!(lastPcTransaction === null || lastPcTransaction === void 0 ? void 0 : lastPcTransaction.txHash)) {
|
|
199
|
-
const failedPcTx =
|
|
198
|
+
if (!(lastPcTransaction === null || lastPcTransaction === void 0 ? void 0 : lastPcTransaction.txHash) || lastPcTransaction.status === 'FAILED') {
|
|
199
|
+
const failedPcTx = (lastPcTransaction === null || lastPcTransaction === void 0 ? void 0 : lastPcTransaction.status) === 'FAILED'
|
|
200
|
+
? lastPcTransaction
|
|
201
|
+
: pushChainUniversalTx.pcTx.find((pcTx) => pcTx.status === 'FAILED' && pcTx.errorMsg);
|
|
200
202
|
const errorDetails = (failedPcTx === null || failedPcTx === void 0 ? void 0 : failedPcTx.errorMsg) ? `: ${failedPcTx.errorMsg}` : '';
|
|
201
|
-
|
|
203
|
+
// Parse known UEA error selectors for actionable hints
|
|
204
|
+
let hint = '';
|
|
205
|
+
if (failedPcTx === null || failedPcTx === void 0 ? void 0 : failedPcTx.errorMsg) {
|
|
206
|
+
if (failedPcTx.errorMsg.includes('0xacfdb444')) {
|
|
207
|
+
hint = ' [ExecutionFailed: the subcall to the target contract reverted. ' +
|
|
208
|
+
'Check that the target address can receive native tokens (has receive/fallback) ' +
|
|
209
|
+
'and that calldata matches a valid function signature.]';
|
|
210
|
+
}
|
|
211
|
+
else if (failedPcTx.errorMsg.includes('0x179a867c')) {
|
|
212
|
+
hint = ' [ExpiredDeadline: the transaction deadline has passed.]';
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
throw new Error(`Push Chain transaction failed for gateway tx: ${gatewayTxHash}${errorDetails}${hint}`);
|
|
202
216
|
}
|
|
203
217
|
const tx = yield ctx.pushClient.getTransaction(lastPcTransaction.txHash);
|
|
204
218
|
return transformFn(tx, eventBuffer);
|
|
@@ -256,7 +256,7 @@ function trackTransaction(ctx, txHash, options, callbacks) {
|
|
|
256
256
|
function transformToUniversalTxResponse(ctx_1, tx_1) {
|
|
257
257
|
return tslib_1.__awaiter(this, arguments, void 0, function* (ctx, tx, eventBuffer = [], callbacks) {
|
|
258
258
|
const chain = ctx.universalSigner.account.chain;
|
|
259
|
-
|
|
259
|
+
let { vm, chainId } = chain_1.CHAIN_INFO[chain];
|
|
260
260
|
let from;
|
|
261
261
|
let to;
|
|
262
262
|
let value;
|
|
@@ -269,6 +269,13 @@ function transformToUniversalTxResponse(ctx_1, tx_1) {
|
|
|
269
269
|
throw new Error('UEA origin account is null');
|
|
270
270
|
}
|
|
271
271
|
originAddress = ueaOrigin.account.address;
|
|
272
|
+
// Use the resolved origin chain for vm/chainId so that the `origin`
|
|
273
|
+
// field reflects the transaction's actual origin, not the tracker's.
|
|
274
|
+
const resolvedChainInfo = chain_1.CHAIN_INFO[ueaOrigin.account.chain];
|
|
275
|
+
if (resolvedChainInfo) {
|
|
276
|
+
vm = resolvedChainInfo.vm;
|
|
277
|
+
chainId = resolvedChainInfo.chainId;
|
|
278
|
+
}
|
|
272
279
|
from = (0, viem_1.getAddress)(tx.to);
|
|
273
280
|
let decoded;
|
|
274
281
|
if (tx.input !== '0x') {
|
|
@@ -565,7 +565,7 @@ function executeUoaToCeaSvm(ctx, params, target, executeFn) {
|
|
|
565
565
|
*/
|
|
566
566
|
function executeCeaToPush(ctx, params, executeFn) {
|
|
567
567
|
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
568
|
-
var _a, _b, _c, _d, _e, _f
|
|
568
|
+
var _a, _b, _c, _d, _e, _f;
|
|
569
569
|
// 1. Validate and extract source chain
|
|
570
570
|
if (!((_a = params.from) === null || _a === void 0 ? void 0 : _a.chain)) {
|
|
571
571
|
throw new Error('Route 3 (CEA -> Push) requires from.chain to specify the source CEA chain');
|
|
@@ -700,27 +700,24 @@ function executeCeaToPush(ctx, params, executeFn) {
|
|
|
700
700
|
// CEA will self-execute this multicall (to=CEA, value=0)
|
|
701
701
|
const ceaPayload = (0, payload_builders_1.buildCeaMulticallPayload)(ceaMulticalls);
|
|
702
702
|
(0, context_1.printLog)(ctx, `executeCeaToPush — CEA payload (first 100 chars): ${ceaPayload.slice(0, 100)}...`);
|
|
703
|
-
// 8. Determine PRC-20 token for the outbound
|
|
704
|
-
//
|
|
705
|
-
//
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
// burnAmount = PRC20 to burn on Push Chain (NOT the bridge amount).
|
|
715
|
-
// Vault deposits burnAmount to CEA. CEA uses burnAmount + pre-existing balance for the bridge.
|
|
716
|
-
const burnAmount = amount;
|
|
703
|
+
// 8. Determine PRC-20 token for the outbound relay.
|
|
704
|
+
// Route 3: ALWAYS use native PRC-20 for chain namespace lookup + gas fees.
|
|
705
|
+
// The CEA uses its OWN pre-existing balance on the external chain to bridge
|
|
706
|
+
// tokens back — no PRC-20 burn is needed on Push Chain.
|
|
707
|
+
// burnAmount = 0 makes this a payload-only outbound relay.
|
|
708
|
+
//
|
|
709
|
+
// Previously this burned pUSDT/pToken equal to the bridge amount, which failed
|
|
710
|
+
// because the UEA never holds pUSDT — the whole point of Route 3 is to get
|
|
711
|
+
// tokens FROM the CEA back to Push Chain, not to round-trip them.
|
|
712
|
+
const prc20Token = (0, helpers_1.getNativePRC20ForChain)(sourceChain, ctx.pushNetwork);
|
|
713
|
+
const burnAmount = BigInt(0);
|
|
717
714
|
(0, context_1.printLog)(ctx, `executeCeaToPush — prc20Token: ${prc20Token}, burnAmount: ${burnAmount.toString()}`);
|
|
718
715
|
// 9. Build outbound request (same structure as Route 2)
|
|
719
716
|
// target = CEA address (for self-execution), value = 0 in payload
|
|
720
717
|
const outboundReq = (0, payload_builders_1.buildOutboundRequest)(ceaAddress, // target: CEA address (to=CEA for self-execution)
|
|
721
718
|
prc20Token, // token: native PRC-20 for source chain (for namespace lookup)
|
|
722
|
-
burnAmount, // amount:
|
|
723
|
-
(
|
|
719
|
+
burnAmount, // amount: 0 (payload-only, CEA uses its own balance)
|
|
720
|
+
(_f = params.gasLimit) !== null && _f !== void 0 ? _f : BigInt(0), ceaPayload, // payload: ABI-encoded CEA multicall
|
|
724
721
|
ueaAddress // revertRecipient: UEA
|
|
725
722
|
);
|
|
726
723
|
(0, context_1.printLog)(ctx, `executeCeaToPush — outbound request: ${JSON.stringify({
|
|
@@ -757,9 +754,43 @@ function executeCeaToPush(ctx, params, executeFn) {
|
|
|
757
754
|
const currentBalance = ueaBalance;
|
|
758
755
|
// Cosmos-EVM tx overhead costs ~1 PC per operation; 3 PC covers approve(s) + buffer.
|
|
759
756
|
const OUTBOUND_GAS_RESERVE_R3 = BigInt(3e18);
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
757
|
+
const ROUTE3_MINIMUM_DEPOSIT_USD = utils_1.Utils.helpers.parseUnits('10', 8); // $10
|
|
758
|
+
// For fresh wallets: predict post-fee-locking UPC balance using the same
|
|
759
|
+
// Uniswap V3 quoter the chain uses (pETH → WPC swap), matching Route 2 logic.
|
|
760
|
+
let effectiveBalance = currentBalance;
|
|
761
|
+
if (!isUEADeployed && effectiveBalance <= OUTBOUND_GAS_RESERVE_R3) {
|
|
762
|
+
const signerChain = ctx.universalSigner.account.chain;
|
|
763
|
+
const ethPrice = yield new price_fetch_1.PriceFetch(ctx.rpcUrls).getPrice(signerChain);
|
|
764
|
+
const nativeAmountETH = ethPrice > BigInt(0)
|
|
765
|
+
? (ROUTE3_MINIMUM_DEPOSIT_USD * BigInt(1e18) + (ethPrice - BigInt(1))) / ethPrice + BigInt(1)
|
|
766
|
+
: BigInt(0);
|
|
767
|
+
if (nativeAmountETH > BigInt(0)) {
|
|
768
|
+
const originPrc20 = (0, helpers_1.getNativePRC20ForChain)(signerChain, ctx.pushNetwork);
|
|
769
|
+
const predictedUPC = yield (0, gas_calculator_1.estimateDepositFromLockedNative)(ctx, nativeAmountETH, originPrc20);
|
|
770
|
+
if (predictedUPC > BigInt(0)) {
|
|
771
|
+
effectiveBalance = (predictedUPC * BigInt(90)) / BigInt(100);
|
|
772
|
+
(0, context_1.printLog)(ctx, `executeCeaToPush — fresh wallet: Uniswap quote predicts ${predictedUPC.toString()} UPC ` +
|
|
773
|
+
`from ${nativeAmountETH.toString()} wei pETH, using ${effectiveBalance.toString()} (90%)`);
|
|
774
|
+
}
|
|
775
|
+
}
|
|
776
|
+
}
|
|
777
|
+
// Balance-aware adjustment matching Route 2 logic:
|
|
778
|
+
// - If balance exceeds target + reserve: use target (200 UPC)
|
|
779
|
+
// - If balance exceeds reserve: use balance - reserve (maximize within budget)
|
|
780
|
+
// - Otherwise: keep original nativeValueForGas (fallback)
|
|
781
|
+
const EVM_NATIVE_VALUE_TARGET_R3 = BigInt(200e18); // 200 UPC
|
|
782
|
+
let adjustedValue;
|
|
783
|
+
if (effectiveBalance > EVM_NATIVE_VALUE_TARGET_R3 + OUTBOUND_GAS_RESERVE_R3) {
|
|
784
|
+
adjustedValue = EVM_NATIVE_VALUE_TARGET_R3;
|
|
785
|
+
}
|
|
786
|
+
else if (effectiveBalance > OUTBOUND_GAS_RESERVE_R3) {
|
|
787
|
+
adjustedValue = effectiveBalance - OUTBOUND_GAS_RESERVE_R3;
|
|
788
|
+
}
|
|
789
|
+
else {
|
|
790
|
+
adjustedValue = nativeValueForGas;
|
|
791
|
+
}
|
|
792
|
+
if (adjustedValue !== nativeValueForGas) {
|
|
793
|
+
(0, context_1.printLog)(ctx, `executeCeaToPush — adjusting nativeValueForGas from ${nativeValueForGas.toString()} to ${adjustedValue.toString()} (effective balance: ${effectiveBalance.toString()})`);
|
|
763
794
|
nativeValueForGas = adjustedValue;
|
|
764
795
|
}
|
|
765
796
|
// 12. Build Push Chain multicalls (approvals + sendUniversalTxOutbound)
|
|
@@ -776,17 +807,11 @@ function executeCeaToPush(ctx, params, executeFn) {
|
|
|
776
807
|
// Sum native values from multicall entries for proper fee calculation
|
|
777
808
|
const multicallNativeValue = pushChainMulticalls.reduce((sum, mc) => { var _a; return sum + ((_a = mc.value) !== null && _a !== void 0 ? _a : BigInt(0)); }, BigInt(0));
|
|
778
809
|
// 13. Execute through the normal execute() flow
|
|
779
|
-
const executeParams = {
|
|
780
|
-
to: ueaAddress,
|
|
781
|
-
value: multicallNativeValue, // ensures correct requiredFunds calculation
|
|
782
|
-
data: pushChainMulticalls,
|
|
783
|
-
_ueaStatus: {
|
|
810
|
+
const executeParams = Object.assign({ to: ueaAddress, value: multicallNativeValue, data: pushChainMulticalls, _ueaStatus: {
|
|
784
811
|
isDeployed: isUEADeployed,
|
|
785
812
|
nonce: ueaNonce,
|
|
786
813
|
balance: ueaBalance,
|
|
787
|
-
},
|
|
788
|
-
_skipFeeLocking: true, // outbound executes on Push Chain, no external fee locking
|
|
789
|
-
};
|
|
814
|
+
}, _skipFeeLocking: isUEADeployed }, (!isUEADeployed ? { _minimumDepositUsd: ROUTE3_MINIMUM_DEPOSIT_USD } : {}));
|
|
790
815
|
const response = yield executeFn(executeParams);
|
|
791
816
|
// Add Route 3 context to response
|
|
792
817
|
response.chain = sourceChain;
|
|
@@ -824,7 +849,6 @@ function executeCeaToPushSvm(ctx, params, sourceChain, executeFn) {
|
|
|
824
849
|
// Determine drain amount and token
|
|
825
850
|
let drainAmount = BigInt(0);
|
|
826
851
|
let tokenMintHex;
|
|
827
|
-
let prc20Token;
|
|
828
852
|
if (((_a = params.funds) === null || _a === void 0 ? void 0 : _a.amount) && params.funds.amount > BigInt(0)) {
|
|
829
853
|
// SPL token drain
|
|
830
854
|
drainAmount = params.funds.amount;
|
|
@@ -833,22 +857,15 @@ function executeCeaToPushSvm(ctx, params, sourceChain, executeFn) {
|
|
|
833
857
|
// Convert SPL mint address to 32-byte hex
|
|
834
858
|
const mintPk = new web3_js_1.PublicKey(token.address);
|
|
835
859
|
tokenMintHex = ('0x' + Buffer.from(mintPk.toBytes()).toString('hex'));
|
|
836
|
-
prc20Token = push_chain_1.PushChain.utils.tokens.getPRC20Address(token);
|
|
837
|
-
}
|
|
838
|
-
else {
|
|
839
|
-
prc20Token = (0, helpers_1.getNativePRC20ForChain)(sourceChain, ctx.pushNetwork);
|
|
840
860
|
}
|
|
841
861
|
}
|
|
842
862
|
else if (params.value && params.value > BigInt(0)) {
|
|
843
863
|
// Native SOL drain
|
|
844
864
|
drainAmount = params.value;
|
|
845
|
-
prc20Token = (0, helpers_1.getNativePRC20ForChain)(sourceChain, ctx.pushNetwork);
|
|
846
|
-
}
|
|
847
|
-
else {
|
|
848
|
-
// Payload-only Route 3 SVM: no funds to drain, just execute data on Push Chain
|
|
849
|
-
drainAmount = BigInt(0);
|
|
850
|
-
prc20Token = (0, helpers_1.getNativePRC20ForChain)(sourceChain, ctx.pushNetwork);
|
|
851
865
|
}
|
|
866
|
+
// Route 3 SVM: ALWAYS use native PRC-20 for chain namespace lookup + gas fees.
|
|
867
|
+
// CEA uses its own pre-existing balance — no PRC-20 burn needed on Push Chain.
|
|
868
|
+
const prc20Token = (0, helpers_1.getNativePRC20ForChain)(sourceChain, ctx.pushNetwork);
|
|
852
869
|
// Build the SVM CPI payload (send_universal_tx_to_uea wrapped in execute)
|
|
853
870
|
// If params.data is provided, pass it as extraPayload for Push Chain execution
|
|
854
871
|
let extraPayload;
|
|
@@ -920,17 +937,11 @@ function executeCeaToPushSvm(ctx, params, sourceChain, executeFn) {
|
|
|
920
937
|
// Sum native values from multicall entries for proper fee calculation
|
|
921
938
|
const multicallNativeValue = pushChainMulticalls.reduce((sum, mc) => { var _a; return sum + ((_a = mc.value) !== null && _a !== void 0 ? _a : BigInt(0)); }, BigInt(0));
|
|
922
939
|
// Execute through the normal execute() flow
|
|
923
|
-
const executeParams = {
|
|
924
|
-
to: ueaAddress,
|
|
925
|
-
value: multicallNativeValue, // ensures correct requiredFunds calculation
|
|
926
|
-
data: pushChainMulticalls,
|
|
927
|
-
_ueaStatus: {
|
|
940
|
+
const executeParams = Object.assign({ to: ueaAddress, value: multicallNativeValue, data: pushChainMulticalls, _ueaStatus: {
|
|
928
941
|
isDeployed: isUEADeployed,
|
|
929
942
|
nonce: ueaNonce,
|
|
930
943
|
balance: ueaBalance,
|
|
931
|
-
},
|
|
932
|
-
_skipFeeLocking: true, // outbound executes on Push Chain, no external fee locking
|
|
933
|
-
};
|
|
944
|
+
}, _skipFeeLocking: isUEADeployed }, (!isUEADeployed ? { _minimumDepositUsd: utils_1.Utils.helpers.parseUnits('10', 8) } : {}));
|
|
934
945
|
const response = yield executeFn(executeParams);
|
|
935
946
|
// Add Route 3 SVM context to response
|
|
936
947
|
response.chain = sourceChain;
|
|
@@ -1078,28 +1089,19 @@ function buildPayloadForRoute(ctx, params, route, nonce) {
|
|
|
1078
1089
|
const gatewayProgramHex = ('0x' + Buffer.from(programPk.toBytes()).toString('hex'));
|
|
1079
1090
|
let drainAmount = BigInt(0);
|
|
1080
1091
|
let tokenMintHex;
|
|
1081
|
-
let prc20Token;
|
|
1082
1092
|
if (((_j = params.funds) === null || _j === void 0 ? void 0 : _j.amount) && params.funds.amount > BigInt(0)) {
|
|
1083
1093
|
drainAmount = params.funds.amount;
|
|
1084
1094
|
const token = params.funds.token;
|
|
1085
1095
|
if (token && token.address) {
|
|
1086
1096
|
const mintPk = new web3_js_1.PublicKey(token.address);
|
|
1087
1097
|
tokenMintHex = ('0x' + Buffer.from(mintPk.toBytes()).toString('hex'));
|
|
1088
|
-
prc20Token = push_chain_1.PushChain.utils.tokens.getPRC20Address(token);
|
|
1089
|
-
}
|
|
1090
|
-
else {
|
|
1091
|
-
prc20Token = (0, helpers_1.getNativePRC20ForChain)(sourceChain, ctx.pushNetwork);
|
|
1092
1098
|
}
|
|
1093
1099
|
}
|
|
1094
1100
|
else if (params.value && params.value > BigInt(0)) {
|
|
1095
1101
|
drainAmount = params.value;
|
|
1096
|
-
prc20Token = (0, helpers_1.getNativePRC20ForChain)(sourceChain, ctx.pushNetwork);
|
|
1097
|
-
}
|
|
1098
|
-
else {
|
|
1099
|
-
// Payload-only Route 3 SVM: no funds to drain, just execute data on Push Chain
|
|
1100
|
-
drainAmount = BigInt(0);
|
|
1101
|
-
prc20Token = (0, helpers_1.getNativePRC20ForChain)(sourceChain, ctx.pushNetwork);
|
|
1102
1102
|
}
|
|
1103
|
+
// Route 3 SVM: ALWAYS use native PRC-20, CEA uses its own balance.
|
|
1104
|
+
const prc20Token = (0, helpers_1.getNativePRC20ForChain)(sourceChain, ctx.pushNetwork);
|
|
1103
1105
|
// Derive CEA PDA as revert recipient
|
|
1104
1106
|
const ueaBytes2 = Buffer.from(ueaAddress.slice(2), 'hex');
|
|
1105
1107
|
const [ceaPda2] = web3_js_1.PublicKey.findProgramAddressSync([Buffer.from('push_identity'), ueaBytes2], programPk);
|
|
@@ -1187,9 +1189,9 @@ function buildPayloadForRoute(ctx, params, route, nonce) {
|
|
|
1187
1189
|
ceaMulticalls.push(sendCall);
|
|
1188
1190
|
const ceaPayload = (0, payload_builders_1.buildCeaMulticallPayload)(ceaMulticalls);
|
|
1189
1191
|
const prc20Token = (0, helpers_1.getNativePRC20ForChain)(sourceChain, ctx.pushNetwork);
|
|
1190
|
-
//
|
|
1191
|
-
//
|
|
1192
|
-
const burnAmount =
|
|
1192
|
+
// Route 3: CEA uses its own pre-existing balance — no PRC-20 burn needed.
|
|
1193
|
+
// burnAmount = 0 makes this a payload-only outbound relay.
|
|
1194
|
+
const burnAmount = BigInt(0);
|
|
1193
1195
|
const outboundReq = (0, payload_builders_1.buildOutboundRequest)(ceaAddress, prc20Token, burnAmount, (_o = params.gasLimit) !== null && _o !== void 0 ? _o : BigInt(0), ceaPayload, ueaAddress);
|
|
1194
1196
|
return { payload: ceaPayload, gatewayRequest: outboundReq };
|
|
1195
1197
|
}
|