@pushchain/core 6.0.19 → 6.0.21
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/CHANGELOG.md +54 -0
- package/package.json +1 -1
- package/src/lib/cache/cache.js +2 -0
- package/src/lib/constants/abi/index.d.ts +1 -0
- package/src/lib/constants/abi/index.js +8 -1
- package/src/lib/constants/abi/pc20.evm.d.ts +217 -0
- package/src/lib/constants/abi/pc20.evm.js +150 -0
- package/src/lib/constants/abi/prc20.evm.d.ts +172 -0
- package/src/lib/constants/abi/prc20.evm.js +97 -0
- package/src/lib/constants/abi/universalGatewayV0.json +1 -1
- package/src/lib/constants/chain.js +38 -8
- package/src/lib/constants/selectors.js +2 -2
- package/src/lib/constants/tokens.js +4 -3
- package/src/lib/formatters.js +16 -6
- package/src/lib/generated/uexecutor/v1/query.js +2 -4
- package/src/lib/generated/uexecutor/v1/types.d.ts +14 -0
- package/src/lib/generated/uexecutor/v1/types.js +90 -47
- package/src/lib/generated/uexecutor/v2/query.js +2 -4
- package/src/lib/generated/uexecutor/v2/types.d.ts +20 -0
- package/src/lib/generated/uexecutor/v2/types.js +49 -33
- package/src/lib/generated/v1/tx.js +30 -37
- package/src/lib/index.d.ts +4 -1
- package/src/lib/index.js +21 -3
- package/src/lib/internal/buffer.js +1 -2
- package/src/lib/orchestrator/cea-utils.js +73 -83
- package/src/lib/orchestrator/internals/account-manager.js +130 -139
- package/src/lib/orchestrator/internals/cascade.d.ts +0 -6
- package/src/lib/orchestrator/internals/cascade.js +1184 -1059
- package/src/lib/orchestrator/internals/confirmation.js +138 -148
- package/src/lib/orchestrator/internals/error-decoder.js +1 -1
- package/src/lib/orchestrator/internals/errors.js +12 -3
- package/src/lib/orchestrator/internals/execute-funds-only.d.ts +2 -2
- package/src/lib/orchestrator/internals/execute-funds-only.js +297 -259
- package/src/lib/orchestrator/internals/execute-funds-payload.d.ts +2 -2
- package/src/lib/orchestrator/internals/execute-funds-payload.js +220 -220
- package/src/lib/orchestrator/internals/execute-standard.d.ts +0 -8
- package/src/lib/orchestrator/internals/execute-standard.js +339 -342
- package/src/lib/orchestrator/internals/gas-calculator.js +497 -520
- package/src/lib/orchestrator/internals/gas-usd-sizer.js +101 -110
- package/src/lib/orchestrator/internals/gateway-client.js +102 -103
- package/src/lib/orchestrator/internals/helpers.js +30 -27
- package/src/lib/orchestrator/internals/inbound-tracker.js +234 -238
- package/src/lib/orchestrator/internals/outbound-sync.js +463 -452
- package/src/lib/orchestrator/internals/outbound-tracker.js +27 -34
- package/src/lib/orchestrator/internals/payload-builder.d.ts +2 -2
- package/src/lib/orchestrator/internals/payload-builder.js +119 -100
- package/src/lib/orchestrator/internals/pc-usd-oracle.js +121 -129
- package/src/lib/orchestrator/internals/pc20/address-codec.d.ts +31 -0
- package/src/lib/orchestrator/internals/pc20/address-codec.js +124 -0
- package/src/lib/orchestrator/internals/pc20/chain-namespace.d.ts +68 -0
- package/src/lib/orchestrator/internals/pc20/chain-namespace.js +136 -0
- package/src/lib/orchestrator/internals/pc20/errors.d.ts +160 -0
- package/src/lib/orchestrator/internals/pc20/errors.js +236 -0
- package/src/lib/orchestrator/internals/pc20/export.d.ts +172 -0
- package/src/lib/orchestrator/internals/pc20/export.js +412 -0
- package/src/lib/orchestrator/internals/pc20/gate.d.ts +67 -0
- package/src/lib/orchestrator/internals/pc20/gate.js +184 -0
- package/src/lib/orchestrator/internals/pc20/resolver.d.ts +187 -0
- package/src/lib/orchestrator/internals/pc20/resolver.js +658 -0
- package/src/lib/orchestrator/internals/pc20/svm.d.ts +189 -0
- package/src/lib/orchestrator/internals/pc20/svm.js +286 -0
- package/src/lib/orchestrator/internals/pc20/tracking.d.ts +46 -0
- package/src/lib/orchestrator/internals/pc20/tracking.js +109 -0
- package/src/lib/orchestrator/internals/preflight.js +1 -1
- package/src/lib/orchestrator/internals/progress-route-hooks.js +2 -2
- package/src/lib/orchestrator/internals/push-chain-tx.js +319 -331
- package/src/lib/orchestrator/internals/quote.js +90 -94
- package/src/lib/orchestrator/internals/rescue.js +76 -79
- package/src/lib/orchestrator/internals/response-builder.d.ts +28 -1
- package/src/lib/orchestrator/internals/response-builder.js +817 -701
- package/src/lib/orchestrator/internals/route-handlers.d.ts +7 -15
- package/src/lib/orchestrator/internals/route-handlers.js +1512 -1178
- package/src/lib/orchestrator/internals/signing.js +78 -83
- package/src/lib/orchestrator/internals/svm-bridge.d.ts +2 -2
- package/src/lib/orchestrator/internals/svm-bridge.js +161 -93
- package/src/lib/orchestrator/internals/svm-helpers.d.ts +15 -1
- package/src/lib/orchestrator/internals/svm-helpers.js +68 -24
- package/src/lib/orchestrator/internals/svm-rent.d.ts +19 -1
- package/src/lib/orchestrator/internals/svm-rent.js +163 -141
- package/src/lib/orchestrator/internals/tx-transformer.js +26 -23
- package/src/lib/orchestrator/internals/uea-manager.js +89 -86
- package/src/lib/orchestrator/max-pc-for-gas.js +5 -6
- package/src/lib/orchestrator/orchestrator.js +217 -200
- package/src/lib/orchestrator/orchestrator.types.d.ts +121 -1
- package/src/lib/orchestrator/orchestrator.types.js +19 -0
- package/src/lib/orchestrator/payload-builders.d.ts +2 -2
- package/src/lib/orchestrator/payload-builders.js +26 -24
- package/src/lib/orchestrator/route-detector.js +26 -9
- package/src/lib/orchestrator/svm-idl/ix-encoder.js +1 -2
- package/src/lib/orchestrator/svm-idl/normalize-address.js +2 -2
- package/src/lib/orchestrator/svm-idl/resolve.js +1 -2
- package/src/lib/price-fetch/price-fetch.js +67 -68
- package/src/lib/progress-hook/progress-hook.js +124 -72
- package/src/lib/push-chain/push-chain.js +171 -153
- package/src/lib/push-client/push-client.js +223 -237
- package/src/lib/universal/account/account.js +349 -365
- package/src/lib/universal/signer/signer.d.ts +2 -1
- package/src/lib/universal/signer/signer.js +315 -299
- package/src/lib/universal-tx-detector/auto-detect.js +55 -60
- package/src/lib/universal-tx-detector/cascade.js +160 -172
- package/src/lib/universal-tx-detector/child-inbounds.js +67 -75
- package/src/lib/universal-tx-detector/classify.js +2 -3
- package/src/lib/universal-tx-detector/detector-svm.js +139 -147
- package/src/lib/universal-tx-detector/detector.js +145 -157
- package/src/lib/universal-tx-detector/normalize.js +7 -7
- package/src/lib/utils/external-tx-hash.js +1 -2
- package/src/lib/utils.d.ts +44 -0
- package/src/lib/utils.js +762 -683
- package/src/lib/vm-client/evm-client.js +186 -202
- package/src/lib/vm-client/svm-client.d.ts +1 -1
- package/src/lib/vm-client/svm-client.js +220 -224
- package/src/lib/vm-client/vm-client.types.d.ts +14 -2
|
@@ -4,7 +4,6 @@ exports.getPcUsdPrice = exports.__THRESHOLDS = void 0;
|
|
|
4
4
|
exports.sizeOutboundGas = sizeOutboundGas;
|
|
5
5
|
exports.sizeR1PushGas = sizeR1PushGas;
|
|
6
6
|
exports.computeGasUsd = computeGasUsd;
|
|
7
|
-
const tslib_1 = require("tslib");
|
|
8
7
|
/**
|
|
9
8
|
* Gas sizing for outbound transactions (Routes 2/3/4).
|
|
10
9
|
*
|
|
@@ -31,66 +30,64 @@ const TEN_USD_8D = (0, viem_1.parseUnits)('10', 8); // 1_000_000_000
|
|
|
31
30
|
// ============================================================================
|
|
32
31
|
// Public API
|
|
33
32
|
// ============================================================================
|
|
34
|
-
function sizeOutboundGas(ctx, input) {
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
(
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
};
|
|
93
|
-
});
|
|
33
|
+
async function sizeOutboundGas(ctx, input) {
|
|
34
|
+
const { gasFee, originChain, destinationChain } = input;
|
|
35
|
+
// 1) Price gasFee in USD (8 decimals). gasFee is denominated in the
|
|
36
|
+
// destination native (pETH = ETH value, pSOL = SOL value). The price
|
|
37
|
+
// feed lives on the *origin* side (origin gateway's Chainlink/Pyth),
|
|
38
|
+
// but we reuse the same feed via PriceFetch — the asset being priced
|
|
39
|
+
// is ETH or SOL, not the route.
|
|
40
|
+
const destVm = chain_1.CHAIN_INFO[destinationChain].vm;
|
|
41
|
+
const priceSourceChain = destVm === enums_1.VM.SVM ? enums_1.CHAIN.SOLANA_DEVNET : enums_1.CHAIN.ETHEREUM_SEPOLIA;
|
|
42
|
+
const destDecimals = destVm === enums_1.VM.SVM ? 9 : 18;
|
|
43
|
+
let destUsdPrice;
|
|
44
|
+
try {
|
|
45
|
+
destUsdPrice = await new price_fetch_1.PriceFetch(ctx.rpcUrls).getPrice(priceSourceChain);
|
|
46
|
+
}
|
|
47
|
+
catch (err) {
|
|
48
|
+
(0, context_1.printLog)(ctx, `sizeOutboundGas — PriceFetch.getPrice failed (${err instanceof Error ? err.message : String(err)}); treating as Case B passthrough`);
|
|
49
|
+
// Degrade gracefully: assume the raw gasFee is already a sane size and
|
|
50
|
+
// convert 1:1 to native PC. Callers keep their existing fallback logic.
|
|
51
|
+
return passthroughAsCaseB(ctx, gasFee, originChain);
|
|
52
|
+
}
|
|
53
|
+
const oneDestNativeUnit = (0, viem_1.parseUnits)('1', destDecimals);
|
|
54
|
+
const gasUsd = (gasFee * destUsdPrice) / oneDestNativeUnit;
|
|
55
|
+
(0, context_1.printLog)(ctx, `sizeOutboundGas — gasFee=${gasFee.toString()} ${destVm === enums_1.VM.SVM ? 'pSOL' : 'pETH'} (${destDecimals}d), ` +
|
|
56
|
+
`destUsdPrice=${destUsdPrice.toString()} (1e8), gasUsd=${gasUsd.toString()} (1e8)`);
|
|
57
|
+
// 2) Categorize and compute target USD for each leg.
|
|
58
|
+
let category;
|
|
59
|
+
let gasLegUsd;
|
|
60
|
+
let overflowUsd;
|
|
61
|
+
if (gasUsd < ONE_USD_8D) {
|
|
62
|
+
category = 'A';
|
|
63
|
+
gasLegUsd = ONE_USD_8D;
|
|
64
|
+
overflowUsd = BigInt(0);
|
|
65
|
+
}
|
|
66
|
+
else if (gasUsd <= TEN_USD_8D) {
|
|
67
|
+
category = 'B';
|
|
68
|
+
gasLegUsd = gasUsd;
|
|
69
|
+
overflowUsd = BigInt(0);
|
|
70
|
+
}
|
|
71
|
+
else {
|
|
72
|
+
category = 'C';
|
|
73
|
+
gasLegUsd = TEN_USD_8D;
|
|
74
|
+
overflowUsd = gasUsd - TEN_USD_8D;
|
|
75
|
+
}
|
|
76
|
+
// 3) Convert USD targets back to native PC via the per-route WPC/stable oracle.
|
|
77
|
+
const gasLegNativePc = await (0, pc_usd_oracle_1.usdToPc)(ctx, gasLegUsd, originChain);
|
|
78
|
+
const overflowNativePc = overflowUsd > BigInt(0)
|
|
79
|
+
? await (0, pc_usd_oracle_1.usdToPc)(ctx, overflowUsd, originChain)
|
|
80
|
+
: BigInt(0);
|
|
81
|
+
(0, context_1.printLog)(ctx, `sizeOutboundGas — category=${category}, gasLegUsd=${gasLegUsd.toString()}, ` +
|
|
82
|
+
`overflowUsd=${overflowUsd.toString()}, gasLegNativePc=${gasLegNativePc.toString()}, ` +
|
|
83
|
+
`overflowNativePc=${overflowNativePc.toString()}`);
|
|
84
|
+
return {
|
|
85
|
+
category,
|
|
86
|
+
gasLegNativePc,
|
|
87
|
+
overflowNativePc,
|
|
88
|
+
gasUsd,
|
|
89
|
+
overflowUsd,
|
|
90
|
+
};
|
|
94
91
|
}
|
|
95
92
|
// ============================================================================
|
|
96
93
|
// Internal helpers
|
|
@@ -100,62 +97,56 @@ function sizeOutboundGas(ctx, input) {
|
|
|
100
97
|
* Orchestrator alive: return the raw gasFee as a Case B result, converting
|
|
101
98
|
* through the existing PC/USD oracle (or its hardcoded fallback).
|
|
102
99
|
*/
|
|
103
|
-
function passthroughAsCaseB(ctx, gasFee, originChain) {
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
};
|
|
115
|
-
});
|
|
100
|
+
async function passthroughAsCaseB(ctx, gasFee, originChain) {
|
|
101
|
+
const oneUsd = ONE_USD_8D;
|
|
102
|
+
const gasLegNativePc = await (0, pc_usd_oracle_1.usdToPc)(ctx, oneUsd, originChain);
|
|
103
|
+
void gasFee;
|
|
104
|
+
return {
|
|
105
|
+
category: 'B',
|
|
106
|
+
gasLegNativePc,
|
|
107
|
+
overflowNativePc: BigInt(0),
|
|
108
|
+
gasUsd: oneUsd,
|
|
109
|
+
overflowUsd: BigInt(0),
|
|
110
|
+
};
|
|
116
111
|
}
|
|
117
|
-
function sizeR1PushGas(ctx, input) {
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
(
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
return { category, pushGasUsd, paddedDepositUsd };
|
|
143
|
-
});
|
|
112
|
+
async function sizeR1PushGas(ctx, input) {
|
|
113
|
+
const { pushGasFeeWei, originChain } = input;
|
|
114
|
+
// 1) Convert pushGasFeeWei (UPC wei, 18d) → USD (8d) via per-route oracle.
|
|
115
|
+
const pcUsdPrice = await (0, pc_usd_oracle_1.getPcUsdPrice)(ctx, originChain);
|
|
116
|
+
const onePcUnit = (0, viem_1.parseUnits)('1', 18);
|
|
117
|
+
const pushGasUsd = (pushGasFeeWei * pcUsdPrice) / onePcUnit;
|
|
118
|
+
(0, context_1.printLog)(ctx, `sizeR1PushGas — pushGasFeeWei=${pushGasFeeWei.toString()} UPC (18d), ` +
|
|
119
|
+
`pcUsdPrice=${pcUsdPrice.toString()} (1e8), pushGasUsd=${pushGasUsd.toString()} (1e8)`);
|
|
120
|
+
// 2) Bucket.
|
|
121
|
+
let category;
|
|
122
|
+
let paddedDepositUsd;
|
|
123
|
+
if (pushGasUsd < ONE_USD_8D) {
|
|
124
|
+
category = 'A';
|
|
125
|
+
paddedDepositUsd = ONE_USD_8D;
|
|
126
|
+
}
|
|
127
|
+
else if (pushGasUsd <= TEN_USD_8D) {
|
|
128
|
+
category = 'B';
|
|
129
|
+
paddedDepositUsd = pushGasUsd;
|
|
130
|
+
}
|
|
131
|
+
else {
|
|
132
|
+
category = 'C';
|
|
133
|
+
paddedDepositUsd = pushGasUsd;
|
|
134
|
+
}
|
|
135
|
+
(0, context_1.printLog)(ctx, `sizeR1PushGas — category=${category}, paddedDepositUsd=${paddedDepositUsd.toString()} (1e8)`);
|
|
136
|
+
return { category, pushGasUsd, paddedDepositUsd };
|
|
144
137
|
}
|
|
145
138
|
/**
|
|
146
139
|
* Given gasFee (in gasToken units) and destination VM, return gasFee in USD
|
|
147
140
|
* (8 decimals). Exposed for direct use in places that already have the
|
|
148
141
|
* destUsdPrice cached (e.g., rescue flows).
|
|
149
142
|
*/
|
|
150
|
-
function computeGasUsd(ctx, gasFee, destinationChain) {
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
return (gasFee * destUsdPrice) / oneUnit;
|
|
158
|
-
});
|
|
143
|
+
async function computeGasUsd(ctx, gasFee, destinationChain) {
|
|
144
|
+
const destVm = chain_1.CHAIN_INFO[destinationChain].vm;
|
|
145
|
+
const priceSourceChain = destVm === enums_1.VM.SVM ? enums_1.CHAIN.SOLANA_DEVNET : enums_1.CHAIN.ETHEREUM_SEPOLIA;
|
|
146
|
+
const destDecimals = destVm === enums_1.VM.SVM ? 9 : 18;
|
|
147
|
+
const destUsdPrice = await new price_fetch_1.PriceFetch(ctx.rpcUrls).getPrice(priceSourceChain);
|
|
148
|
+
const oneUnit = (0, viem_1.parseUnits)('1', destDecimals);
|
|
149
|
+
return (gasFee * destUsdPrice) / oneUnit;
|
|
159
150
|
}
|
|
160
151
|
/** Test-only export of thresholds. @internal */
|
|
161
152
|
exports.__THRESHOLDS = { ONE_USD_8D, TEN_USD_8D };
|
|
@@ -10,7 +10,6 @@ exports.sendGatewayTxWithFallback = sendGatewayTxWithFallback;
|
|
|
10
10
|
exports.sendGatewayTokenTxWithFallback = sendGatewayTokenTxWithFallback;
|
|
11
11
|
exports.lockFee = lockFee;
|
|
12
12
|
exports.getOriginGatewayContext = getOriginGatewayContext;
|
|
13
|
-
const tslib_1 = require("tslib");
|
|
14
13
|
const bs58_1 = require("../../internal/bs58");
|
|
15
14
|
const web3_js_1 = require("@solana/web3.js");
|
|
16
15
|
const viem_1 = require("viem");
|
|
@@ -41,9 +40,8 @@ const SOURCE_NATIVE_SYMBOL = {
|
|
|
41
40
|
[enums_1.CHAIN.SOLANA_DEVNET]: 'SOL',
|
|
42
41
|
};
|
|
43
42
|
function formatSourceNative(chain, amount) {
|
|
44
|
-
var _a;
|
|
45
43
|
const decimals = chain_1.CHAIN_INFO[chain].vm === enums_1.VM.SVM ? 9 : 18;
|
|
46
|
-
const symbol =
|
|
44
|
+
const symbol = SOURCE_NATIVE_SYMBOL[chain] ?? 'native token';
|
|
47
45
|
return `${utils_1.Utils.helpers.formatUnits(amount, decimals)} ${symbol}`;
|
|
48
46
|
}
|
|
49
47
|
function insufficientSourceBalanceMessage(chain, available, required) {
|
|
@@ -81,120 +79,121 @@ function toGatewayTokenRequestV1(req) {
|
|
|
81
79
|
// ============================================================================
|
|
82
80
|
// Send Gateway Tx (V1 only)
|
|
83
81
|
// ============================================================================
|
|
84
|
-
function sendGatewayTxWithFallback(ctx, evmClient, address, req, signer, value) {
|
|
85
|
-
return
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
value,
|
|
93
|
-
});
|
|
82
|
+
async function sendGatewayTxWithFallback(ctx, evmClient, address, req, signer, value) {
|
|
83
|
+
return evmClient.writeContract({
|
|
84
|
+
abi: GATEWAY_ABI,
|
|
85
|
+
address,
|
|
86
|
+
functionName: 'sendUniversalTx',
|
|
87
|
+
args: [toGatewayRequestV1(req)],
|
|
88
|
+
signer,
|
|
89
|
+
value,
|
|
94
90
|
});
|
|
95
91
|
}
|
|
96
|
-
function sendGatewayTokenTxWithFallback(ctx, evmClient, address, req, signer, value) {
|
|
97
|
-
return
|
|
98
|
-
|
|
92
|
+
async function sendGatewayTokenTxWithFallback(ctx, evmClient, address, req, signer, value) {
|
|
93
|
+
return evmClient.writeContract({
|
|
94
|
+
abi: GATEWAY_ABI,
|
|
95
|
+
address,
|
|
96
|
+
functionName: 'sendUniversalTx',
|
|
97
|
+
args: [toGatewayTokenRequestV1(req)],
|
|
98
|
+
signer,
|
|
99
|
+
...(value !== undefined && { value }),
|
|
99
100
|
});
|
|
100
101
|
}
|
|
101
102
|
// ============================================================================
|
|
102
103
|
// Fee Locking
|
|
103
104
|
// ============================================================================
|
|
104
|
-
function lockFee(ctx, amount, universalPayload,
|
|
105
|
+
async function lockFee(ctx, amount, universalPayload,
|
|
105
106
|
// DEBUG: lockFee entry
|
|
106
107
|
req) {
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
108
|
+
const chain = ctx.universalSigner.account.chain;
|
|
109
|
+
const { lockerContract, vm, defaultRPC } = chain_1.CHAIN_INFO[chain];
|
|
110
|
+
if (!lockerContract) {
|
|
111
|
+
throw new Error(`Locker contract not configured for chain: ${chain}`);
|
|
112
|
+
}
|
|
113
|
+
const rpcUrls = ctx.rpcUrls[chain] || defaultRPC;
|
|
114
|
+
switch (vm) {
|
|
115
|
+
case enums_1.VM.EVM: {
|
|
116
|
+
const evmClient = (0, context_1.getOriginEvmClient)(ctx);
|
|
117
|
+
const nativeTokenUsdPrice = await new price_fetch_1.PriceFetch(ctx.rpcUrls).getPrice(chain);
|
|
118
|
+
const nativeDecimals = 18;
|
|
119
|
+
const oneUsd = utils_1.Utils.helpers.parseUnits('1', 8);
|
|
120
|
+
const maxUsd = utils_1.Utils.helpers.parseUnits('1000', 8);
|
|
121
|
+
let depositUsd = amount < oneUsd ? oneUsd : amount;
|
|
122
|
+
if (depositUsd > maxUsd)
|
|
123
|
+
depositUsd = maxUsd;
|
|
124
|
+
let nativeAmount = (depositUsd * BigInt(10 ** nativeDecimals) +
|
|
125
|
+
(nativeTokenUsdPrice - BigInt(1))) /
|
|
126
|
+
nativeTokenUsdPrice;
|
|
127
|
+
nativeAmount = nativeAmount + BigInt(1);
|
|
128
|
+
const sourceAddress = ctx.universalSigner.account.address;
|
|
129
|
+
const sourceBalance = await evmClient.publicClient.getBalance({
|
|
130
|
+
address: sourceAddress,
|
|
131
|
+
});
|
|
132
|
+
if (sourceBalance < nativeAmount) {
|
|
133
|
+
throw new Error(insufficientSourceBalanceMessage(chain, sourceBalance, nativeAmount));
|
|
134
|
+
}
|
|
135
|
+
const txHash = await sendGatewayTxWithFallback(ctx, evmClient, lockerContract, req, ctx.universalSigner, nativeAmount);
|
|
136
|
+
return (0, viem_1.hexToBytes)(txHash);
|
|
112
137
|
}
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
138
|
+
case enums_1.VM.SVM: {
|
|
139
|
+
const [nativeTokenUsdPrice, svmClient] = await Promise.all([
|
|
140
|
+
new price_fetch_1.PriceFetch(ctx.rpcUrls).getPrice(chain),
|
|
141
|
+
Promise.resolve(new svm_client_1.SvmClient({ rpcUrls })),
|
|
142
|
+
]);
|
|
143
|
+
const nativeDecimals = 9;
|
|
144
|
+
const oneUsd = utils_1.Utils.helpers.parseUnits('1', 8);
|
|
145
|
+
const maxUsd = utils_1.Utils.helpers.parseUnits('1000', 8);
|
|
146
|
+
let depositUsd = amount < oneUsd ? oneUsd : amount;
|
|
147
|
+
if (depositUsd > maxUsd)
|
|
148
|
+
depositUsd = maxUsd;
|
|
149
|
+
let nativeAmount = (depositUsd * BigInt(10 ** nativeDecimals) +
|
|
150
|
+
(nativeTokenUsdPrice - BigInt(1))) /
|
|
151
|
+
nativeTokenUsdPrice;
|
|
152
|
+
nativeAmount = nativeAmount + BigInt(1);
|
|
153
|
+
const programId = new web3_js_1.PublicKey(abi_1.SVM_GATEWAY_IDL.address);
|
|
154
|
+
const [configPda] = web3_js_1.PublicKey.findProgramAddressSync([(0, viem_1.stringToBytes)('config')], programId);
|
|
155
|
+
const [vaultPda] = web3_js_1.PublicKey.findProgramAddressSync([(0, viem_1.stringToBytes)('vault')], programId);
|
|
156
|
+
const [rateLimitConfigPda] = web3_js_1.PublicKey.findProgramAddressSync([(0, viem_1.stringToBytes)('rate_limit_config')], programId);
|
|
157
|
+
const [tokenRateLimitPda] = web3_js_1.PublicKey.findProgramAddressSync([(0, viem_1.stringToBytes)('rate_limit'), web3_js_1.PublicKey.default.toBuffer()], programId);
|
|
158
|
+
const userPk = new web3_js_1.PublicKey(ctx.universalSigner.account.address);
|
|
159
|
+
const { feeVaultPda, protocolFeeLamports } = await (0, svm_helpers_2.getSvmProtocolFee)(svmClient, programId);
|
|
160
|
+
const gasReq = (0, svm_helpers_1.buildSvmUniversalTxRequestFromReq)(req, userPk);
|
|
161
|
+
const requiredLamports = nativeAmount + protocolFeeLamports;
|
|
162
|
+
const sourceBalance = await svmClient.getBalance(userPk.toBase58());
|
|
163
|
+
if (sourceBalance < requiredLamports) {
|
|
164
|
+
throw new Error(insufficientSourceBalanceMessage(chain, sourceBalance, requiredLamports));
|
|
165
|
+
}
|
|
166
|
+
try {
|
|
167
|
+
const txHash = await svmClient.writeContract({
|
|
168
|
+
abi: abi_1.SVM_GATEWAY_IDL,
|
|
169
|
+
address: programId.toBase58(),
|
|
170
|
+
functionName: 'sendUniversalTx',
|
|
171
|
+
args: [gasReq, requiredLamports],
|
|
172
|
+
signer: ctx.universalSigner,
|
|
173
|
+
accounts: {
|
|
174
|
+
config: configPda,
|
|
175
|
+
vault: vaultPda,
|
|
176
|
+
feeVault: feeVaultPda,
|
|
177
|
+
userTokenAccount: vaultPda,
|
|
178
|
+
gatewayTokenAccount: vaultPda,
|
|
179
|
+
user: userPk,
|
|
180
|
+
priceUpdate: new web3_js_1.PublicKey(chain_1.SVM_PYTH_PRICE_FEED),
|
|
181
|
+
rateLimitConfig: rateLimitConfigPda,
|
|
182
|
+
tokenRateLimit: tokenRateLimitPda,
|
|
183
|
+
tokenProgram: new web3_js_1.PublicKey('TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA'),
|
|
184
|
+
systemProgram: web3_js_1.SystemProgram.programId,
|
|
185
|
+
},
|
|
131
186
|
});
|
|
132
|
-
|
|
133
|
-
throw new Error(insufficientSourceBalanceMessage(chain, sourceBalance, nativeAmount));
|
|
134
|
-
}
|
|
135
|
-
const txHash = yield sendGatewayTxWithFallback(ctx, evmClient, lockerContract, req, ctx.universalSigner, nativeAmount);
|
|
136
|
-
return (0, viem_1.hexToBytes)(txHash);
|
|
187
|
+
return new Uint8Array(bs58_1.bs58.decode(txHash));
|
|
137
188
|
}
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
Promise.resolve(new svm_client_1.SvmClient({ rpcUrls })),
|
|
142
|
-
]);
|
|
143
|
-
const nativeDecimals = 9;
|
|
144
|
-
const oneUsd = utils_1.Utils.helpers.parseUnits('1', 8);
|
|
145
|
-
const maxUsd = utils_1.Utils.helpers.parseUnits('1000', 8);
|
|
146
|
-
let depositUsd = amount < oneUsd ? oneUsd : amount;
|
|
147
|
-
if (depositUsd > maxUsd)
|
|
148
|
-
depositUsd = maxUsd;
|
|
149
|
-
let nativeAmount = (depositUsd * BigInt(Math.pow(10, nativeDecimals)) +
|
|
150
|
-
(nativeTokenUsdPrice - BigInt(1))) /
|
|
151
|
-
nativeTokenUsdPrice;
|
|
152
|
-
nativeAmount = nativeAmount + BigInt(1);
|
|
153
|
-
const programId = new web3_js_1.PublicKey(abi_1.SVM_GATEWAY_IDL.address);
|
|
154
|
-
const [configPda] = web3_js_1.PublicKey.findProgramAddressSync([(0, viem_1.stringToBytes)('config')], programId);
|
|
155
|
-
const [vaultPda] = web3_js_1.PublicKey.findProgramAddressSync([(0, viem_1.stringToBytes)('vault')], programId);
|
|
156
|
-
const [rateLimitConfigPda] = web3_js_1.PublicKey.findProgramAddressSync([(0, viem_1.stringToBytes)('rate_limit_config')], programId);
|
|
157
|
-
const [tokenRateLimitPda] = web3_js_1.PublicKey.findProgramAddressSync([(0, viem_1.stringToBytes)('rate_limit'), web3_js_1.PublicKey.default.toBuffer()], programId);
|
|
158
|
-
const userPk = new web3_js_1.PublicKey(ctx.universalSigner.account.address);
|
|
159
|
-
const { feeVaultPda, protocolFeeLamports } = yield (0, svm_helpers_2.getSvmProtocolFee)(svmClient, programId);
|
|
160
|
-
const gasReq = (0, svm_helpers_1.buildSvmUniversalTxRequestFromReq)(req, userPk);
|
|
161
|
-
const requiredLamports = nativeAmount + protocolFeeLamports;
|
|
162
|
-
const sourceBalance = yield svmClient.getBalance(userPk.toBase58());
|
|
163
|
-
if (sourceBalance < requiredLamports) {
|
|
164
|
-
throw new Error(insufficientSourceBalanceMessage(chain, sourceBalance, requiredLamports));
|
|
165
|
-
}
|
|
166
|
-
try {
|
|
167
|
-
const txHash = yield svmClient.writeContract({
|
|
168
|
-
abi: abi_1.SVM_GATEWAY_IDL,
|
|
169
|
-
address: programId.toBase58(),
|
|
170
|
-
functionName: 'sendUniversalTx',
|
|
171
|
-
args: [gasReq, requiredLamports],
|
|
172
|
-
signer: ctx.universalSigner,
|
|
173
|
-
accounts: {
|
|
174
|
-
config: configPda,
|
|
175
|
-
vault: vaultPda,
|
|
176
|
-
feeVault: feeVaultPda,
|
|
177
|
-
userTokenAccount: vaultPda,
|
|
178
|
-
gatewayTokenAccount: vaultPda,
|
|
179
|
-
user: userPk,
|
|
180
|
-
priceUpdate: new web3_js_1.PublicKey(chain_1.SVM_PYTH_PRICE_FEED),
|
|
181
|
-
rateLimitConfig: rateLimitConfigPda,
|
|
182
|
-
tokenRateLimit: tokenRateLimitPda,
|
|
183
|
-
tokenProgram: new web3_js_1.PublicKey('TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA'),
|
|
184
|
-
systemProgram: web3_js_1.SystemProgram.programId,
|
|
185
|
-
},
|
|
186
|
-
});
|
|
187
|
-
return new Uint8Array(bs58_1.bs58.decode(txHash));
|
|
188
|
-
}
|
|
189
|
-
catch (error) {
|
|
190
|
-
(0, context_2.printLog)(ctx, `Error sending UniversalTx: ${error instanceof Error ? error.message : String(error)}`);
|
|
191
|
-
throw error;
|
|
192
|
-
}
|
|
189
|
+
catch (error) {
|
|
190
|
+
(0, context_2.printLog)(ctx, `Error sending UniversalTx: ${error instanceof Error ? error.message : String(error)}`);
|
|
191
|
+
throw error;
|
|
193
192
|
}
|
|
194
|
-
default:
|
|
195
|
-
throw new Error(`Unsupported VM type: ${vm}`);
|
|
196
193
|
}
|
|
197
|
-
|
|
194
|
+
default:
|
|
195
|
+
throw new Error(`Unsupported VM type: ${vm}`);
|
|
196
|
+
}
|
|
198
197
|
}
|
|
199
198
|
// ============================================================================
|
|
200
199
|
// Origin Gateway Context
|
|
@@ -16,7 +16,6 @@ exports.validateMainnetConnection = validateMainnetConnection;
|
|
|
16
16
|
exports.bigintReplacer = bigintReplacer;
|
|
17
17
|
exports.toExecuteParams = toExecuteParams;
|
|
18
18
|
exports.fetchOriginChainTransactionForProgress = fetchOriginChainTransactionForProgress;
|
|
19
|
-
const tslib_1 = require("tslib");
|
|
20
19
|
const web3_js_1 = require("@solana/web3.js");
|
|
21
20
|
const chain_1 = require("../../constants/chain");
|
|
22
21
|
const context_1 = require("./context");
|
|
@@ -141,6 +140,12 @@ function toExecuteParams(params) {
|
|
|
141
140
|
value: params.value,
|
|
142
141
|
data: params.data,
|
|
143
142
|
funds: params.funds,
|
|
143
|
+
// Internal PC20 descriptor must survive param transformation — the payload
|
|
144
|
+
// builders branch on it, and losing it here silently reroutes a resolved
|
|
145
|
+
// PC20 through the static synthetic-token lookup (which throws).
|
|
146
|
+
...(('_pc20' in params)
|
|
147
|
+
? { _pc20: params._pc20 }
|
|
148
|
+
: {}),
|
|
144
149
|
gasLimit: params.gasLimit,
|
|
145
150
|
maxPCForGas: params.maxPCForGas,
|
|
146
151
|
maxFeePerGas: params.maxFeePerGas,
|
|
@@ -154,34 +159,32 @@ function toExecuteParams(params) {
|
|
|
154
159
|
// ============================================================================
|
|
155
160
|
// Origin Chain Transaction for Progress
|
|
156
161
|
// ============================================================================
|
|
157
|
-
function fetchOriginChainTransactionForProgress(ctx, chain, txHashHex, txHashDisplay) {
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
if (
|
|
163
|
-
|
|
164
|
-
throw new Error('EVM transaction hash must be 0x-prefixed');
|
|
165
|
-
}
|
|
166
|
-
const evmClient = (0, context_1.getOriginEvmClient)(ctx);
|
|
167
|
-
const tx = yield evmClient.publicClient.getTransaction({
|
|
168
|
-
hash: txHashHex,
|
|
169
|
-
});
|
|
170
|
-
return tx !== null && tx !== void 0 ? tx : undefined;
|
|
162
|
+
async function fetchOriginChainTransactionForProgress(ctx, chain, txHashHex, txHashDisplay) {
|
|
163
|
+
const { vm, defaultRPC } = chain_1.CHAIN_INFO[chain];
|
|
164
|
+
const rpcUrls = ctx.rpcUrls[chain] || defaultRPC;
|
|
165
|
+
try {
|
|
166
|
+
if (vm === enums_1.VM.EVM) {
|
|
167
|
+
if (!txHashHex.startsWith('0x')) {
|
|
168
|
+
throw new Error('EVM transaction hash must be 0x-prefixed');
|
|
171
169
|
}
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
});
|
|
178
|
-
return tx !== null && tx !== void 0 ? tx : undefined;
|
|
179
|
-
}
|
|
180
|
-
return undefined;
|
|
170
|
+
const evmClient = (0, context_1.getOriginEvmClient)(ctx);
|
|
171
|
+
const tx = await evmClient.publicClient.getTransaction({
|
|
172
|
+
hash: txHashHex,
|
|
173
|
+
});
|
|
174
|
+
return tx ?? undefined;
|
|
181
175
|
}
|
|
182
|
-
|
|
183
|
-
|
|
176
|
+
if (vm === enums_1.VM.SVM) {
|
|
177
|
+
const connection = new web3_js_1.Connection(rpcUrls[0], 'confirmed');
|
|
178
|
+
const tx = await connection.getTransaction(txHashDisplay, {
|
|
179
|
+
maxSupportedTransactionVersion: 0,
|
|
180
|
+
commitment: 'confirmed',
|
|
181
|
+
});
|
|
182
|
+
return tx ?? undefined;
|
|
184
183
|
}
|
|
185
|
-
|
|
184
|
+
return undefined;
|
|
185
|
+
}
|
|
186
|
+
catch {
|
|
187
|
+
return undefined;
|
|
188
|
+
}
|
|
186
189
|
}
|
|
187
190
|
//# sourceMappingURL=helpers.js.map
|