@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
|
@@ -1,4 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.resolveRequiredFunds = resolveRequiredFunds;
|
|
4
|
+
exports.executeStandardPayload = executeStandardPayload;
|
|
5
|
+
const gate_1 = require("./pc20/gate");
|
|
2
6
|
/**
|
|
3
7
|
* Standard payload execution flow (no funds) — extracted from Orchestrator.execute().
|
|
4
8
|
*
|
|
@@ -7,10 +11,6 @@
|
|
|
7
11
|
* - Fee-locking path for undeployed/underfunded UEA
|
|
8
12
|
* - Signed verification path for deployed UEA with funds
|
|
9
13
|
*/
|
|
10
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
11
|
-
exports.resolveRequiredFunds = resolveRequiredFunds;
|
|
12
|
-
exports.executeStandardPayload = executeStandardPayload;
|
|
13
|
-
const tslib_1 = require("tslib");
|
|
14
14
|
const bs58_1 = require("../../internal/bs58");
|
|
15
15
|
const viem_1 = require("viem");
|
|
16
16
|
const chain_1 = require("../../constants/chain");
|
|
@@ -83,158 +83,135 @@ function resolveRequiredFunds(requiredGasFee, executeValue, requiredFundsOverrid
|
|
|
83
83
|
? requiredFundsOverride
|
|
84
84
|
: baseRequiredFunds;
|
|
85
85
|
}
|
|
86
|
-
function executeStandardPayload(ctx, execute, eventBuffer, getResponseCallbacks) {
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
86
|
+
async function executeStandardPayload(ctx, execute, eventBuffer, getResponseCallbacks) {
|
|
87
|
+
const transformFn = (tx, buf = []) => (0, response_builder_1.transformToUniversalTxResponse)(ctx, tx, buf, getResponseCallbacks());
|
|
88
|
+
// Set default value for value if undefined
|
|
89
|
+
if (execute.value === undefined) {
|
|
90
|
+
execute.value = BigInt(0);
|
|
91
|
+
}
|
|
92
|
+
const chain = ctx.universalSigner.account.chain;
|
|
93
|
+
(0, context_1.fireProgressHook)(ctx, progress_hook_types_1.PROGRESS_HOOK.SEND_TX_101, chain, ctx.universalSigner.account.address);
|
|
94
|
+
(0, helpers_1.validateMainnetConnection)(chain, ctx.pushClient.pushChainInfo.chainId);
|
|
95
|
+
// Gas estimation fires for both Push-to-Push and external-origin flows so
|
|
96
|
+
// reconstructProgressEvents (which always emits 102-01/02) and live execute
|
|
97
|
+
// stay in lockstep. For the Push-to-Push shortcut we have no origin-chain
|
|
98
|
+
// gas to estimate; surface the tx gas limit as the "cost" to match what
|
|
99
|
+
// the reconstruction path does (it reads universalTxResponse.gasLimit).
|
|
100
|
+
(0, context_1.fireProgressHook)(ctx, progress_hook_types_1.PROGRESS_HOOK.SEND_TX_102_01);
|
|
101
|
+
// Push to Push Tx
|
|
102
|
+
if ((0, helpers_1.isPushChain)(chain)) {
|
|
103
|
+
(0, context_1.fireProgressHook)(ctx, progress_hook_types_1.PROGRESS_HOOK.SEND_TX_103_03_04, execute.gasLimit ?? BigInt(21000), BigInt(0), chain);
|
|
104
|
+
(0, context_1.fireProgressHook)(ctx, progress_hook_types_1.PROGRESS_HOOK.SEND_TX_107);
|
|
105
|
+
let tx;
|
|
106
|
+
try {
|
|
107
|
+
tx = await (0, push_chain_tx_1.sendPushTx)(ctx, execute, eventBuffer, transformFn);
|
|
93
108
|
}
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
(0, context_1.fireProgressHook)(ctx, progress_hook_types_1.PROGRESS_HOOK.SEND_TX_103_03_04, (_a = execute.gasLimit) !== null && _a !== void 0 ? _a : BigInt(21000), BigInt(0), chain);
|
|
106
|
-
(0, context_1.fireProgressHook)(ctx, progress_hook_types_1.PROGRESS_HOOK.SEND_TX_107);
|
|
107
|
-
let tx;
|
|
108
|
-
try {
|
|
109
|
-
tx = yield (0, push_chain_tx_1.sendPushTx)(ctx, execute, eventBuffer, transformFn);
|
|
110
|
-
}
|
|
111
|
-
catch (err) {
|
|
112
|
-
// Push Chain broadcast failed. Wallet rejection surfaces as 104-04;
|
|
113
|
-
// everything else (RPC fail, on-chain revert) as 199-02.
|
|
114
|
-
const errMsg = (0, formatters_1.normalizePublicErrorMessage)(err);
|
|
115
|
-
const { isUserDecline } = (0, progress_hook_1.classifyDeclineError)(errMsg);
|
|
116
|
-
(0, context_1.fireProgressHook)(ctx, isUserDecline ? progress_hook_types_1.PROGRESS_HOOK.SEND_TX_104_04 : progress_hook_types_1.PROGRESS_HOOK.SEND_TX_199_02, errMsg);
|
|
117
|
-
// Mark that a terminal-ish error hook has already fired so the
|
|
118
|
-
// outer orchestrator catch doesn't emit a second 199-02 on top.
|
|
119
|
-
ctx._routeTerminalEmitted = true;
|
|
120
|
-
if (!isUserDecline && !(err instanceof push_chain_tx_1.PushChainExecutionError)) {
|
|
121
|
-
throw new push_chain_tx_1.PushChainExecutionError(errMsg);
|
|
122
|
-
}
|
|
123
|
-
throw err;
|
|
109
|
+
catch (err) {
|
|
110
|
+
// Push Chain broadcast failed. Wallet rejection surfaces as 104-04;
|
|
111
|
+
// everything else (RPC fail, on-chain revert) as 199-02.
|
|
112
|
+
const errMsg = (0, formatters_1.normalizePublicErrorMessage)(err);
|
|
113
|
+
const { isUserDecline } = (0, progress_hook_1.classifyDeclineError)(errMsg);
|
|
114
|
+
(0, context_1.fireProgressHook)(ctx, isUserDecline ? progress_hook_types_1.PROGRESS_HOOK.SEND_TX_104_04 : progress_hook_types_1.PROGRESS_HOOK.SEND_TX_199_02, errMsg);
|
|
115
|
+
// Mark that a terminal-ish error hook has already fired so the
|
|
116
|
+
// outer orchestrator catch doesn't emit a second 199-02 on top.
|
|
117
|
+
ctx._routeTerminalEmitted = true;
|
|
118
|
+
if (!isUserDecline && !(err instanceof push_chain_tx_1.PushChainExecutionError)) {
|
|
119
|
+
throw new push_chain_tx_1.PushChainExecutionError(errMsg);
|
|
124
120
|
}
|
|
125
|
-
|
|
126
|
-
return tx;
|
|
121
|
+
throw err;
|
|
127
122
|
}
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
123
|
+
(0, context_1.fireProgressHook)(ctx, progress_hook_types_1.PROGRESS_HOOK.SEND_TX_199_01, [tx]);
|
|
124
|
+
return tx;
|
|
125
|
+
}
|
|
126
|
+
// Fetch Gas details and estimate cost of execution
|
|
127
|
+
const gasEstimate = execute.gasLimit || BigInt(1e7);
|
|
128
|
+
const gasPrice = await ctx.pushClient.getGasPrice();
|
|
129
|
+
const requiredGasFee = gasEstimate * gasPrice;
|
|
130
|
+
const requiredFunds = resolveRequiredFunds(requiredGasFee, execute.value, execute._requiredFundsOverride);
|
|
131
|
+
// Fetch UEA Details (or use pre-fetched status if available)
|
|
132
|
+
const UEA = (0, uea_manager_1.computeUEAOffchain)(ctx);
|
|
133
|
+
let isUEADeployed;
|
|
134
|
+
let nonce;
|
|
135
|
+
let funds;
|
|
136
|
+
(0, context_1.fireProgressHook)(ctx, progress_hook_types_1.PROGRESS_HOOK.SEND_TX_103_01);
|
|
137
|
+
if (execute._ueaStatus) {
|
|
138
|
+
isUEADeployed = execute._ueaStatus.isDeployed;
|
|
139
|
+
nonce = execute._ueaStatus.nonce;
|
|
140
|
+
funds = execute._ueaStatus.balance;
|
|
141
|
+
}
|
|
142
|
+
else {
|
|
143
|
+
// Skip getCode if accountStatusCache already confirmed deployment
|
|
144
|
+
const deployedHint = ctx.accountStatusCache?.uea?.deployed;
|
|
145
|
+
if (deployedHint) {
|
|
146
|
+
const [balance, ueaNonce] = await Promise.all([
|
|
147
|
+
ctx.pushClient.getBalance(UEA),
|
|
148
|
+
(0, uea_manager_1.getUEANonce)(ctx, UEA),
|
|
149
|
+
]);
|
|
150
|
+
isUEADeployed = true;
|
|
151
|
+
nonce = ueaNonce;
|
|
152
|
+
funds = balance;
|
|
143
153
|
}
|
|
144
154
|
else {
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
isUEADeployed = true;
|
|
153
|
-
nonce = ueaNonce;
|
|
154
|
-
funds = balance;
|
|
155
|
-
}
|
|
156
|
-
else {
|
|
157
|
-
const [code, balance] = yield Promise.all([
|
|
158
|
-
ctx.pushClient.publicClient.getCode({ address: UEA }),
|
|
159
|
-
ctx.pushClient.getBalance(UEA),
|
|
160
|
-
]);
|
|
161
|
-
isUEADeployed = code !== undefined;
|
|
162
|
-
nonce = isUEADeployed ? yield (0, uea_manager_1.getUEANonce)(ctx, UEA) : BigInt(0);
|
|
163
|
-
funds = balance;
|
|
164
|
-
}
|
|
155
|
+
const [code, balance] = await Promise.all([
|
|
156
|
+
ctx.pushClient.publicClient.getCode({ address: UEA }),
|
|
157
|
+
ctx.pushClient.getBalance(UEA),
|
|
158
|
+
]);
|
|
159
|
+
isUEADeployed = code !== undefined;
|
|
160
|
+
nonce = isUEADeployed ? await (0, uea_manager_1.getUEANonce)(ctx, UEA) : BigInt(0);
|
|
161
|
+
funds = balance;
|
|
165
162
|
}
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
}
|
|
177
|
-
const feeLockingRequired = !execute._skipFeeLocking &&
|
|
178
|
-
(!isUEADeployed || funds < requiredFunds) && !feeLockTxHash;
|
|
179
|
-
// Support multicall payload encoding when execute.data is an array
|
|
180
|
-
let payloadData;
|
|
181
|
-
let payloadTo;
|
|
182
|
-
let req;
|
|
183
|
-
if (Array.isArray(execute.data)) {
|
|
184
|
-
payloadTo = viem_1.zeroAddress;
|
|
185
|
-
payloadData = (0, payload_builder_1.buildMulticallPayloadData)(ctx, execute.to, (0, payload_builders_1.buildExecuteMulticall)({ execute, ueaAddress: UEA }));
|
|
186
|
-
// Wrap in full UniversalPayload encoding for gateway req (matches non-array paths)
|
|
187
|
-
const universalPayloadForReq = JSON.parse(JSON.stringify({
|
|
188
|
-
to: viem_1.zeroAddress, value: execute.value,
|
|
189
|
-
data: payloadData,
|
|
190
|
-
gasLimit: execute.gasLimit || BigInt(5e7),
|
|
191
|
-
maxFeePerGas: execute.maxFeePerGas || BigInt(1e10),
|
|
192
|
-
maxPriorityFeePerGas: execute.maxPriorityFeePerGas || BigInt(0),
|
|
193
|
-
nonce, deadline: execute.deadline || BigInt(9999999999),
|
|
194
|
-
vType: feeLockingRequired
|
|
195
|
-
? tx_1.VerificationType.universalTxVerification
|
|
196
|
-
: tx_1.VerificationType.signedVerification,
|
|
197
|
-
}, helpers_1.bigintReplacer));
|
|
198
|
-
req = (0, payload_builder_1.buildUniversalTxRequest)(ctx.universalSigner.account.address, {
|
|
199
|
-
recipient: viem_1.zeroAddress, token: viem_1.zeroAddress, amount: BigInt(0),
|
|
200
|
-
payload: encodePayloadForOriginIfNeeded(ctx, universalPayloadForReq, feeLockingRequired),
|
|
201
|
-
});
|
|
163
|
+
}
|
|
164
|
+
(0, context_1.fireProgressHook)(ctx, progress_hook_types_1.PROGRESS_HOOK.SEND_TX_103_02, UEA, isUEADeployed);
|
|
165
|
+
(0, context_1.fireProgressHook)(ctx, progress_hook_types_1.PROGRESS_HOOK.SEND_TX_103_03_04, requiredFunds, BigInt(0), chain);
|
|
166
|
+
// Validate and decode feeLockTxHash
|
|
167
|
+
let feeLockTxHash = execute.feeLockTxHash;
|
|
168
|
+
if (feeLockTxHash) {
|
|
169
|
+
(0, helpers_1.validateFeeLockTxHash)(feeLockTxHash);
|
|
170
|
+
if (!feeLockTxHash.startsWith('0x')) {
|
|
171
|
+
const decoded = bs58_1.bs58.decode(feeLockTxHash);
|
|
172
|
+
feeLockTxHash = (0, viem_1.bytesToHex)(new Uint8Array(decoded));
|
|
202
173
|
}
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
174
|
+
}
|
|
175
|
+
const feeLockingRequired = !execute._skipFeeLocking &&
|
|
176
|
+
(!isUEADeployed || funds < requiredFunds) && !feeLockTxHash;
|
|
177
|
+
// Support multicall payload encoding when execute.data is an array
|
|
178
|
+
let payloadData;
|
|
179
|
+
let payloadTo;
|
|
180
|
+
let req;
|
|
181
|
+
if (Array.isArray(execute.data)) {
|
|
182
|
+
payloadTo = viem_1.zeroAddress;
|
|
183
|
+
payloadData = (0, payload_builder_1.buildMulticallPayloadData)(ctx, execute.to, (0, payload_builders_1.buildExecuteMulticall)({ execute: (0, gate_1.assertLegacyFunds)(execute), ueaAddress: UEA }));
|
|
184
|
+
// Wrap in full UniversalPayload encoding for gateway req (matches non-array paths)
|
|
185
|
+
const universalPayloadForReq = JSON.parse(JSON.stringify({
|
|
186
|
+
to: viem_1.zeroAddress, value: execute.value,
|
|
187
|
+
data: payloadData,
|
|
188
|
+
gasLimit: execute.gasLimit || BigInt(5e7),
|
|
189
|
+
maxFeePerGas: execute.maxFeePerGas || BigInt(1e10),
|
|
190
|
+
maxPriorityFeePerGas: execute.maxPriorityFeePerGas || BigInt(0),
|
|
191
|
+
nonce, deadline: execute.deadline || BigInt(9999999999),
|
|
192
|
+
vType: feeLockingRequired
|
|
193
|
+
? tx_1.VerificationType.universalTxVerification
|
|
194
|
+
: tx_1.VerificationType.signedVerification,
|
|
195
|
+
}, helpers_1.bigintReplacer));
|
|
196
|
+
req = (0, payload_builder_1.buildUniversalTxRequest)(ctx.universalSigner.account.address, {
|
|
197
|
+
recipient: viem_1.zeroAddress, token: viem_1.zeroAddress, amount: BigInt(0),
|
|
198
|
+
payload: encodePayloadForOriginIfNeeded(ctx, universalPayloadForReq, feeLockingRequired),
|
|
199
|
+
});
|
|
200
|
+
}
|
|
201
|
+
else {
|
|
202
|
+
if (execute.to.toLowerCase() !== UEA.toLowerCase()) {
|
|
203
|
+
if (execute.funds) {
|
|
204
|
+
payloadTo = viem_1.zeroAddress;
|
|
205
|
+
payloadData = (0, payload_builder_1.buildMulticallPayloadData)(ctx, execute.to, (0, payload_builders_1.buildExecuteMulticall)({ execute: (0, gate_1.assertLegacyFunds)(execute), ueaAddress: UEA }));
|
|
206
|
+
req = (0, payload_builder_1.buildUniversalTxRequest)(ctx.universalSigner.account.address, {
|
|
207
|
+
recipient: viem_1.zeroAddress, token: viem_1.zeroAddress, amount: BigInt(0), payload: payloadData,
|
|
208
|
+
});
|
|
232
209
|
}
|
|
233
210
|
else {
|
|
234
211
|
payloadTo = execute.to;
|
|
235
212
|
payloadData = execute.data || '0x';
|
|
236
|
-
const reqData = (0, payload_builder_1.buildMulticallPayloadData)(ctx, execute.to, (0, payload_builders_1.buildExecuteMulticall)({ execute, ueaAddress: UEA }));
|
|
237
|
-
const
|
|
213
|
+
const reqData = (0, payload_builder_1.buildMulticallPayloadData)(ctx, execute.to, (0, payload_builders_1.buildExecuteMulticall)({ execute: (0, gate_1.assertLegacyFunds)(execute), ueaAddress: UEA }));
|
|
214
|
+
const universalPayloadOther = JSON.parse(JSON.stringify({
|
|
238
215
|
to: viem_1.zeroAddress, value: execute.value,
|
|
239
216
|
data: reqData,
|
|
240
217
|
gasLimit: execute.gasLimit || BigInt(5e7),
|
|
@@ -247,223 +224,243 @@ function executeStandardPayload(ctx, execute, eventBuffer, getResponseCallbacks)
|
|
|
247
224
|
}, helpers_1.bigintReplacer));
|
|
248
225
|
req = (0, payload_builder_1.buildUniversalTxRequest)(ctx.universalSigner.account.address, {
|
|
249
226
|
recipient: viem_1.zeroAddress, token: viem_1.zeroAddress, amount: BigInt(0),
|
|
250
|
-
payload: encodePayloadForOriginIfNeeded(ctx,
|
|
227
|
+
payload: encodePayloadForOriginIfNeeded(ctx, universalPayloadOther, feeLockingRequired),
|
|
251
228
|
});
|
|
252
229
|
}
|
|
253
230
|
}
|
|
254
|
-
const universalPayload = JSON.parse(JSON.stringify({
|
|
255
|
-
to: payloadTo, value: execute.value, data: payloadData,
|
|
256
|
-
gasLimit: execute.gasLimit || BigInt(5e7),
|
|
257
|
-
maxFeePerGas: execute.maxFeePerGas || BigInt(1e10),
|
|
258
|
-
maxPriorityFeePerGas: execute.maxPriorityFeePerGas || BigInt(0),
|
|
259
|
-
nonce, deadline: execute.deadline || BigInt(9999999999),
|
|
260
|
-
vType: feeLockingRequired
|
|
261
|
-
? tx_1.VerificationType.universalTxVerification
|
|
262
|
-
: tx_1.VerificationType.signedVerification,
|
|
263
|
-
}, helpers_1.bigintReplacer));
|
|
264
|
-
// Prepare verification data by either signature or fund locking
|
|
265
|
-
let verificationData;
|
|
266
|
-
if (!feeLockingRequired) {
|
|
267
|
-
const ueaVersion = yield (0, uea_manager_1.fetchUEAVersion)(ctx);
|
|
268
|
-
(0, context_1.fireProgressHook)(ctx, progress_hook_types_1.PROGRESS_HOOK.SEND_TX_104_02);
|
|
269
|
-
let signature;
|
|
270
|
-
try {
|
|
271
|
-
signature = yield (0, signing_1.signUniversalPayload)(ctx, universalPayload, UEA, ueaVersion);
|
|
272
|
-
}
|
|
273
|
-
catch (err) {
|
|
274
|
-
// Wallet decline, contract revert during sign, or RPC failure — the
|
|
275
|
-
// 104-04 builder's classifyDeclineError heuristic picks the right
|
|
276
|
-
// copy (real decline → "Verification Declined"; else "Signature Failed").
|
|
277
|
-
const errMsg = (0, formatters_1.normalizePublicErrorMessage)(err);
|
|
278
|
-
(0, context_1.fireProgressHook)(ctx, progress_hook_types_1.PROGRESS_HOOK.SEND_TX_104_04, errMsg);
|
|
279
|
-
ctx._routeTerminalEmitted = true;
|
|
280
|
-
throw new Error(errMsg);
|
|
281
|
-
}
|
|
282
|
-
verificationData = (0, viem_1.bytesToHex)(signature);
|
|
283
|
-
(0, context_1.fireProgressHook)(ctx, progress_hook_types_1.PROGRESS_HOOK.SEND_TX_104_03);
|
|
284
|
-
}
|
|
285
231
|
else {
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
const
|
|
289
|
-
const
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
232
|
+
payloadTo = execute.to;
|
|
233
|
+
payloadData = execute.data || '0x';
|
|
234
|
+
const reqData = (0, payload_builder_1.buildMulticallPayloadData)(ctx, execute.to, (0, payload_builders_1.buildExecuteMulticall)({ execute: (0, gate_1.assertLegacyFunds)(execute), ueaAddress: UEA }));
|
|
235
|
+
const universalPayloadSelf = JSON.parse(JSON.stringify({
|
|
236
|
+
to: viem_1.zeroAddress, value: execute.value,
|
|
237
|
+
data: reqData,
|
|
238
|
+
gasLimit: execute.gasLimit || BigInt(5e7),
|
|
239
|
+
maxFeePerGas: execute.maxFeePerGas || BigInt(1e10),
|
|
240
|
+
maxPriorityFeePerGas: execute.maxPriorityFeePerGas || BigInt(0),
|
|
241
|
+
nonce, deadline: execute.deadline || BigInt(9999999999),
|
|
242
|
+
vType: feeLockingRequired
|
|
243
|
+
? tx_1.VerificationType.universalTxVerification
|
|
244
|
+
: tx_1.VerificationType.signedVerification,
|
|
245
|
+
}, helpers_1.bigintReplacer));
|
|
246
|
+
req = (0, payload_builder_1.buildUniversalTxRequest)(ctx.universalSigner.account.address, {
|
|
247
|
+
recipient: viem_1.zeroAddress, token: viem_1.zeroAddress, amount: BigInt(0),
|
|
248
|
+
payload: encodePayloadForOriginIfNeeded(ctx, universalPayloadSelf, feeLockingRequired),
|
|
249
|
+
});
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
const universalPayload = JSON.parse(JSON.stringify({
|
|
253
|
+
to: payloadTo, value: execute.value, data: payloadData,
|
|
254
|
+
gasLimit: execute.gasLimit || BigInt(5e7),
|
|
255
|
+
maxFeePerGas: execute.maxFeePerGas || BigInt(1e10),
|
|
256
|
+
maxPriorityFeePerGas: execute.maxPriorityFeePerGas || BigInt(0),
|
|
257
|
+
nonce, deadline: execute.deadline || BigInt(9999999999),
|
|
258
|
+
vType: feeLockingRequired
|
|
259
|
+
? tx_1.VerificationType.universalTxVerification
|
|
260
|
+
: tx_1.VerificationType.signedVerification,
|
|
261
|
+
}, helpers_1.bigintReplacer));
|
|
262
|
+
// Prepare verification data by either signature or fund locking
|
|
263
|
+
let verificationData;
|
|
264
|
+
if (!feeLockingRequired) {
|
|
265
|
+
const ueaVersion = await (0, uea_manager_1.fetchUEAVersion)(ctx);
|
|
266
|
+
(0, context_1.fireProgressHook)(ctx, progress_hook_types_1.PROGRESS_HOOK.SEND_TX_104_02);
|
|
267
|
+
let signature;
|
|
268
|
+
try {
|
|
269
|
+
signature = await (0, signing_1.signUniversalPayload)(ctx, universalPayload, UEA, ueaVersion);
|
|
270
|
+
}
|
|
271
|
+
catch (err) {
|
|
272
|
+
// Wallet decline, contract revert during sign, or RPC failure — the
|
|
273
|
+
// 104-04 builder's classifyDeclineError heuristic picks the right
|
|
274
|
+
// copy (real decline → "Verification Declined"; else "Signature Failed").
|
|
275
|
+
const errMsg = (0, formatters_1.normalizePublicErrorMessage)(err);
|
|
276
|
+
(0, context_1.fireProgressHook)(ctx, progress_hook_types_1.PROGRESS_HOOK.SEND_TX_104_04, errMsg);
|
|
277
|
+
ctx._routeTerminalEmitted = true;
|
|
278
|
+
throw new Error(errMsg);
|
|
279
|
+
}
|
|
280
|
+
verificationData = (0, viem_1.bytesToHex)(signature);
|
|
281
|
+
(0, context_1.fireProgressHook)(ctx, progress_hook_types_1.PROGRESS_HOOK.SEND_TX_104_03);
|
|
282
|
+
}
|
|
283
|
+
else {
|
|
284
|
+
// Fee Locking
|
|
285
|
+
const fundDifference = requiredFunds - funds;
|
|
286
|
+
const fixedPushAmount = utils_1.Utils.helpers.parseUnits('0.001', 18);
|
|
287
|
+
const lockAmount = funds < requiredFunds ? fundDifference : fixedPushAmount;
|
|
288
|
+
// Size the USD deposit against the REAL Uniswap pool rate (not the fixed
|
|
289
|
+
// $0.10/PC SDK rate) for EVM origins. The pool typically prices PC much
|
|
290
|
+
// higher than $0.10, so pushToUSDC under-provisions and the resulting
|
|
291
|
+
// deposit gets clamped up to the $1 minimum, producing near-zero WPC.
|
|
292
|
+
// When the quoted USD exceeds the $1000 cap the later clamp kicks in
|
|
293
|
+
// (pool limit surfaces via the pre-flight capacity message).
|
|
294
|
+
// Falls back to pushToUSDC if the quoter is unavailable.
|
|
295
|
+
const { vm: sizingOriginVm } = chain_1.CHAIN_INFO[chain];
|
|
296
|
+
let lockAmountInUSD = ctx.pushClient.pushToUSDC(lockAmount);
|
|
297
|
+
if (sizingOriginVm === enums_1.VM.EVM && lockAmount > BigInt(0)) {
|
|
298
|
+
// Target lockAmount × 1.2 so that the 10% slippage margin applied by
|
|
299
|
+
// the pre-flight check (safeUPC = predictedUPC × 0.9) leaves enough
|
|
300
|
+
// headroom even when Uniswap V3 exactOutput↔exactInput quotes aren't
|
|
301
|
+
// perfectly symmetric (tick-math rounding).
|
|
302
|
+
const targetWPC = (lockAmount * BigInt(12)) / BigInt(10);
|
|
303
|
+
const originPrc20ForSizing = (0, helpers_2.getNativePRC20ForChain)(chain, ctx.pushNetwork);
|
|
304
|
+
const requiredNative = await (0, gas_calculator_1.estimateNativeForDesiredDeposit)(ctx, targetWPC, originPrc20ForSizing);
|
|
305
|
+
if (requiredNative > BigInt(0)) {
|
|
306
|
+
const ethPriceForSizing = await new price_fetch_1.PriceFetch(ctx.rpcUrls).getPrice(chain);
|
|
307
|
+
if (ethPriceForSizing > BigInt(0)) {
|
|
308
|
+
// requiredNative (18-dec wei) × ethPrice (8-dec USD/ETH) / 1e18 = USD in 8-dec
|
|
309
|
+
const poolBasedUsd = (requiredNative * ethPriceForSizing) / BigInt(1e18);
|
|
310
|
+
(0, context_1.printLog)(ctx, `Fee-lock sizing: pushToUSDC=${lockAmountInUSD.toString()} (fixed $0.10/PC), ` +
|
|
311
|
+
`poolBased=${poolBasedUsd.toString()} (pool quote for ${targetWPC.toString()} WPC) — using poolBased`);
|
|
312
|
+
lockAmountInUSD = poolBasedUsd;
|
|
316
313
|
}
|
|
317
314
|
}
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
}
|
|
315
|
+
}
|
|
316
|
+
// Apply minimum deposit override (e.g., Route 2 needs enough UPC for outbound swap)
|
|
317
|
+
const effectiveLockAmountInUSD = execute._minimumDepositUsd && execute._minimumDepositUsd > lockAmountInUSD
|
|
318
|
+
? execute._minimumDepositUsd
|
|
319
|
+
: lockAmountInUSD;
|
|
320
|
+
// Pre-flight: predict the actual $PC the UEA will receive after the
|
|
321
|
+
// on-chain pETH → WPC swap and validate it covers requiredFunds.
|
|
322
|
+
// Uses the same Uniswap V3 quoter the chain uses (execute_inbound_gas.go).
|
|
323
|
+
// Mirrors the pattern in route-handlers.ts (Route 2/3).
|
|
324
|
+
const { vm: originVm } = chain_1.CHAIN_INFO[chain];
|
|
325
|
+
if (originVm === enums_1.VM.EVM) {
|
|
326
|
+
try {
|
|
327
|
+
// Replicate lockFee's USD → native conversion (with its $1–$1000 clamp)
|
|
328
|
+
const oneUsd = utils_1.Utils.helpers.parseUnits('1', 8);
|
|
329
|
+
const maxUsd = utils_1.Utils.helpers.parseUnits('1000', 8);
|
|
330
|
+
let depositUsd = effectiveLockAmountInUSD < oneUsd ? oneUsd : effectiveLockAmountInUSD;
|
|
331
|
+
if (depositUsd > maxUsd)
|
|
332
|
+
depositUsd = maxUsd;
|
|
333
|
+
const ethPrice = await new price_fetch_1.PriceFetch(ctx.rpcUrls).getPrice(chain);
|
|
334
|
+
if (ethPrice > BigInt(0)) {
|
|
335
|
+
const nativeAmountETH = (depositUsd * BigInt(1e18) + (ethPrice - BigInt(1))) / ethPrice + BigInt(1);
|
|
336
|
+
const originPrc20 = (0, helpers_2.getNativePRC20ForChain)(chain, ctx.pushNetwork);
|
|
337
|
+
const predictedUPC = await (0, gas_calculator_1.estimateDepositFromLockedNative)(ctx, nativeAmountETH, originPrc20);
|
|
338
|
+
if (predictedUPC > BigInt(0)) {
|
|
339
|
+
// 10% slippage margin (same as route-handlers.ts)
|
|
340
|
+
const safeUPC = (predictedUPC * BigInt(90)) / BigInt(100);
|
|
341
|
+
const totalAvailable = safeUPC + funds;
|
|
342
|
+
(0, context_1.printLog)(ctx, `Fee-lock pre-flight: deposit ${depositUsd.toString()} USD → ` +
|
|
343
|
+
`~${nativeAmountETH.toString()} wei ETH → ~${predictedUPC.toString()} UPC ` +
|
|
344
|
+
`(safe: ${safeUPC.toString()}), existing: ${funds.toString()}, ` +
|
|
345
|
+
`total: ${totalAvailable.toString()}, required: ${requiredFunds.toString()}`);
|
|
346
|
+
if (totalAvailable < requiredFunds) {
|
|
347
|
+
const shortfall = requiredFunds - totalAvailable;
|
|
348
|
+
// On failure only: probe pool capacity at the max cap so the
|
|
349
|
+
// caller gets a readable "max transferable right now" number.
|
|
350
|
+
// One extra quoter call — not run on the success path.
|
|
351
|
+
let maxTransferableNote = '';
|
|
352
|
+
if (depositUsd < maxUsd) {
|
|
353
|
+
const maxNativeAmountETH = (maxUsd * BigInt(1e18) + (ethPrice - BigInt(1))) / ethPrice + BigInt(1);
|
|
354
|
+
const maxPredictedUPC = await (0, gas_calculator_1.estimateDepositFromLockedNative)(ctx, maxNativeAmountETH, originPrc20);
|
|
355
|
+
if (maxPredictedUPC > BigInt(0)) {
|
|
356
|
+
const maxSafeUPC = (maxPredictedUPC * BigInt(90)) / BigInt(100);
|
|
357
|
+
const gasReserve = utils_1.Utils.helpers.parseUnits('0.01', 18);
|
|
358
|
+
const maxFromDeposit = maxSafeUPC > gasReserve ? maxSafeUPC - gasReserve : BigInt(0);
|
|
359
|
+
const maxTransferable = funds + maxFromDeposit;
|
|
360
|
+
maxTransferableNote =
|
|
361
|
+
`Max transferable right now (at $1000 cap, pool-limited): ` +
|
|
362
|
+
`~${(0, formatters_1.formatPc)(maxTransferable, 4)} ` +
|
|
363
|
+
`(UEA balance ${(0, formatters_1.formatPc)(funds, 4)} + ` +
|
|
364
|
+
`pool-safe deposit ${(0, formatters_1.formatPc)(maxFromDeposit, 4)} - gas).`;
|
|
365
|
+
(0, context_1.printLog)(ctx, `Fee-lock capacity: ${maxTransferableNote}`);
|
|
369
366
|
}
|
|
370
|
-
throw new Error(`Insufficient deposit: the fee-lock will deposit ~${(0, formatters_1.formatPc)(safeUPC, 4)} ` +
|
|
371
|
-
`but the transaction requires ~${(0, formatters_1.formatPc)(requiredFunds, 4)} ` +
|
|
372
|
-
`(shortfall: ~${(0, formatters_1.formatPc)(shortfall, 4)}). ` +
|
|
373
|
-
`The fee-lock deposit is capped at $1000 USD. ` +
|
|
374
|
-
(maxTransferableNote ? maxTransferableNote + ' ' : '') +
|
|
375
|
-
`Reduce the transfer value or pre-fund the UEA (${UEA}) on Push Chain.`);
|
|
376
367
|
}
|
|
368
|
+
throw new Error(`Insufficient deposit: the fee-lock will deposit ~${(0, formatters_1.formatPc)(safeUPC, 4)} ` +
|
|
369
|
+
`but the transaction requires ~${(0, formatters_1.formatPc)(requiredFunds, 4)} ` +
|
|
370
|
+
`(shortfall: ~${(0, formatters_1.formatPc)(shortfall, 4)}). ` +
|
|
371
|
+
`The fee-lock deposit is capped at $1000 USD. ` +
|
|
372
|
+
(maxTransferableNote ? maxTransferableNote + ' ' : '') +
|
|
373
|
+
`Reduce the transfer value or pre-fund the UEA (${UEA}) on Push Chain.`);
|
|
377
374
|
}
|
|
378
375
|
}
|
|
379
376
|
}
|
|
380
|
-
catch (err) {
|
|
381
|
-
// If the error is our own insufficient-deposit error, rethrow it
|
|
382
|
-
if (err instanceof Error && err.message.startsWith('Insufficient deposit')) {
|
|
383
|
-
throw err;
|
|
384
|
-
}
|
|
385
|
-
// Otherwise quoter failed — log and continue (same fallback as route-handlers)
|
|
386
|
-
(0, context_1.printLog)(ctx, `Fee-lock pre-flight quote failed, proceeding without validation: ${err instanceof Error ? err.message : String(err)}`);
|
|
387
|
-
}
|
|
388
|
-
}
|
|
389
|
-
(0, context_1.fireProgressHook)(ctx, progress_hook_types_1.PROGRESS_HOOK.SEND_TX_104_01);
|
|
390
|
-
let feeLockTxHashBytes;
|
|
391
|
-
try {
|
|
392
|
-
feeLockTxHashBytes = yield (0, gateway_client_1.lockFee)(ctx, effectiveLockAmountInUSD, universalPayload, req);
|
|
393
377
|
}
|
|
394
378
|
catch (err) {
|
|
395
|
-
//
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
(0, context_1.fireProgressHook)(ctx, progress_hook_types_1.PROGRESS_HOOK.SEND_TX_104_04, errMsg);
|
|
399
|
-
ctx._routeTerminalEmitted = true;
|
|
400
|
-
throw new Error(errMsg);
|
|
401
|
-
}
|
|
402
|
-
feeLockTxHash = (0, viem_1.bytesToHex)(feeLockTxHashBytes);
|
|
403
|
-
verificationData = (0, viem_1.bytesToHex)(feeLockTxHashBytes);
|
|
404
|
-
const { vm } = chain_1.CHAIN_INFO[chain];
|
|
405
|
-
const feeLockTxHashDisplay = vm === enums_1.VM.SVM
|
|
406
|
-
? bs58_1.bs58.encode(Buffer.from(feeLockTxHashBytes))
|
|
407
|
-
: feeLockTxHash;
|
|
408
|
-
const originTx = yield (0, helpers_1.fetchOriginChainTransactionForProgress)(ctx, chain, feeLockTxHash, feeLockTxHashDisplay);
|
|
409
|
-
(0, context_1.fireProgressHook)(ctx, progress_hook_types_1.PROGRESS_HOOK.SEND_TX_105_01, feeLockTxHashDisplay, originTx);
|
|
410
|
-
yield (0, confirmation_1.waitForLockerFeeConfirmation)(ctx, feeLockTxHashBytes);
|
|
411
|
-
(0, context_1.fireProgressHook)(ctx, progress_hook_types_1.PROGRESS_HOOK.SEND_TX_105_02, feeLockTxHashDisplay);
|
|
412
|
-
const { defaultRPC, lockerContract } = chain_1.CHAIN_INFO[chain];
|
|
413
|
-
(0, context_1.fireProgressHook)(ctx, progress_hook_types_1.PROGRESS_HOOK.SEND_TX_107);
|
|
414
|
-
let response;
|
|
415
|
-
try {
|
|
416
|
-
const pushChainUniversalTx = yield (0, response_builder_1.queryUniversalTxStatusFromGatewayTx)(ctx, new evm_client_1.EvmClient({ rpcUrls: ctx.rpcUrls[chain] || defaultRPC }), lockerContract, feeLockTxHash, 'sendTxWithGas');
|
|
417
|
-
// extractPcTxAndTransform fires 199-02 itself on pcTx FAILED and throws
|
|
418
|
-
// PushChainExecutionError — don't double-emit. Anything else thrown
|
|
419
|
-
// here (gateway-tx lookup failure, RPC error) hasn't emitted 199-02
|
|
420
|
-
// yet, so the catch below surfaces it.
|
|
421
|
-
response = yield (0, push_chain_tx_1.extractPcTxAndTransform)(ctx, pushChainUniversalTx, feeLockTxHash, eventBuffer, 'sendTxWithGas', transformFn);
|
|
422
|
-
}
|
|
423
|
-
catch (err) {
|
|
424
|
-
if (!(err instanceof push_chain_tx_1.PushChainExecutionError)) {
|
|
425
|
-
const errMsg = (0, formatters_1.normalizePublicErrorMessage)(err);
|
|
426
|
-
(0, context_1.fireProgressHook)(ctx, progress_hook_types_1.PROGRESS_HOOK.SEND_TX_199_02, errMsg);
|
|
427
|
-
throw new push_chain_tx_1.PushChainExecutionError(errMsg, { gatewayTxHash: feeLockTxHash });
|
|
379
|
+
// If the error is our own insufficient-deposit error, rethrow it
|
|
380
|
+
if (err instanceof Error && err.message.startsWith('Insufficient deposit')) {
|
|
381
|
+
throw err;
|
|
428
382
|
}
|
|
429
|
-
|
|
383
|
+
// Otherwise quoter failed — log and continue (same fallback as route-handlers)
|
|
384
|
+
(0, context_1.printLog)(ctx, `Fee-lock pre-flight quote failed, proceeding without validation: ${err instanceof Error ? err.message : String(err)}`);
|
|
430
385
|
}
|
|
431
|
-
(0, context_1.fireProgressHook)(ctx, progress_hook_types_1.PROGRESS_HOOK.SEND_TX_199_01, [response]);
|
|
432
|
-
return response;
|
|
433
386
|
}
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
// UEA-nonce race: the EIP-712 hash uses the UEA's live storage nonce
|
|
437
|
-
// (not payload.nonce), so if anything advances it between our read and
|
|
438
|
-
// Cosmos inclusion the tx reverts with InvalidEVMSignature(0xc7dbd31d).
|
|
439
|
-
const resignOnSigMismatch = () => tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
440
|
-
const freshNonce = yield (0, uea_manager_1.getUEANonce)(ctx, UEA);
|
|
441
|
-
const freshUeaVersion = yield (0, uea_manager_1.fetchUEAVersion)(ctx);
|
|
442
|
-
const freshPayload = JSON.parse(JSON.stringify(Object.assign(Object.assign({}, universalPayload), { nonce: freshNonce }), helpers_1.bigintReplacer));
|
|
443
|
-
const freshSig = yield (0, signing_1.signUniversalPayload)(ctx, freshPayload, UEA, freshUeaVersion);
|
|
444
|
-
return {
|
|
445
|
-
universalPayload: freshPayload,
|
|
446
|
-
verificationData: (0, viem_1.bytesToHex)(freshSig),
|
|
447
|
-
};
|
|
448
|
-
});
|
|
449
|
-
(0, context_1.fireProgressHook)(ctx, progress_hook_types_1.PROGRESS_HOOK.SEND_TX_107);
|
|
450
|
-
let transactions;
|
|
387
|
+
(0, context_1.fireProgressHook)(ctx, progress_hook_types_1.PROGRESS_HOOK.SEND_TX_104_01);
|
|
388
|
+
let feeLockTxHashBytes;
|
|
451
389
|
try {
|
|
452
|
-
|
|
390
|
+
feeLockTxHashBytes = await (0, gateway_client_1.lockFee)(ctx, effectiveLockAmountInUSD, universalPayload, req);
|
|
453
391
|
}
|
|
454
392
|
catch (err) {
|
|
455
|
-
//
|
|
456
|
-
//
|
|
457
|
-
// ends with the spec'd error hook. Typed PushChainExecutionError lets
|
|
458
|
-
// callers classify via instanceof without message sniffing.
|
|
393
|
+
// User declined the fee-lock tx submission or the origin-chain RPC
|
|
394
|
+
// rejected it — classifier picks decline vs generic signature failure.
|
|
459
395
|
const errMsg = (0, formatters_1.normalizePublicErrorMessage)(err);
|
|
460
|
-
(0, context_1.fireProgressHook)(ctx, progress_hook_types_1.PROGRESS_HOOK.
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
throw new push_chain_tx_1.PushChainExecutionError(errMsg);
|
|
396
|
+
(0, context_1.fireProgressHook)(ctx, progress_hook_types_1.PROGRESS_HOOK.SEND_TX_104_04, errMsg);
|
|
397
|
+
ctx._routeTerminalEmitted = true;
|
|
398
|
+
throw new Error(errMsg);
|
|
464
399
|
}
|
|
465
|
-
(0,
|
|
466
|
-
|
|
467
|
-
|
|
400
|
+
feeLockTxHash = (0, viem_1.bytesToHex)(feeLockTxHashBytes);
|
|
401
|
+
verificationData = (0, viem_1.bytesToHex)(feeLockTxHashBytes);
|
|
402
|
+
const { vm } = chain_1.CHAIN_INFO[chain];
|
|
403
|
+
const feeLockTxHashDisplay = vm === enums_1.VM.SVM
|
|
404
|
+
? bs58_1.bs58.encode(Buffer.from(feeLockTxHashBytes))
|
|
405
|
+
: feeLockTxHash;
|
|
406
|
+
const originTx = await (0, helpers_1.fetchOriginChainTransactionForProgress)(ctx, chain, feeLockTxHash, feeLockTxHashDisplay);
|
|
407
|
+
(0, context_1.fireProgressHook)(ctx, progress_hook_types_1.PROGRESS_HOOK.SEND_TX_105_01, feeLockTxHashDisplay, originTx);
|
|
408
|
+
await (0, confirmation_1.waitForLockerFeeConfirmation)(ctx, feeLockTxHashBytes);
|
|
409
|
+
(0, context_1.fireProgressHook)(ctx, progress_hook_types_1.PROGRESS_HOOK.SEND_TX_105_02, feeLockTxHashDisplay);
|
|
410
|
+
const { defaultRPC, lockerContract } = chain_1.CHAIN_INFO[chain];
|
|
411
|
+
(0, context_1.fireProgressHook)(ctx, progress_hook_types_1.PROGRESS_HOOK.SEND_TX_107);
|
|
412
|
+
let response;
|
|
413
|
+
try {
|
|
414
|
+
const pushChainUniversalTx = await (0, response_builder_1.queryUniversalTxStatusFromGatewayTx)(ctx, new evm_client_1.EvmClient({ rpcUrls: ctx.rpcUrls[chain] || defaultRPC }), lockerContract, feeLockTxHash, 'sendTxWithGas');
|
|
415
|
+
// extractPcTxAndTransform fires 199-02 itself on pcTx FAILED and throws
|
|
416
|
+
// PushChainExecutionError — don't double-emit. Anything else thrown
|
|
417
|
+
// here (gateway-tx lookup failure, RPC error) hasn't emitted 199-02
|
|
418
|
+
// yet, so the catch below surfaces it.
|
|
419
|
+
response = await (0, push_chain_tx_1.extractPcTxAndTransform)(ctx, pushChainUniversalTx, feeLockTxHash, eventBuffer, 'sendTxWithGas', transformFn);
|
|
420
|
+
}
|
|
421
|
+
catch (err) {
|
|
422
|
+
if (!(err instanceof push_chain_tx_1.PushChainExecutionError)) {
|
|
423
|
+
const errMsg = (0, formatters_1.normalizePublicErrorMessage)(err);
|
|
424
|
+
(0, context_1.fireProgressHook)(ctx, progress_hook_types_1.PROGRESS_HOOK.SEND_TX_199_02, errMsg);
|
|
425
|
+
throw new push_chain_tx_1.PushChainExecutionError(errMsg, { gatewayTxHash: feeLockTxHash });
|
|
426
|
+
}
|
|
427
|
+
throw err;
|
|
428
|
+
}
|
|
429
|
+
(0, context_1.fireProgressHook)(ctx, progress_hook_types_1.PROGRESS_HOOK.SEND_TX_199_01, [response]);
|
|
430
|
+
return response;
|
|
431
|
+
}
|
|
432
|
+
// Non-fee-locking path: Broadcasting Tx to PC via sendUniversalTx.
|
|
433
|
+
// Provide a resign callback so sendUniversalTx can recover from the
|
|
434
|
+
// UEA-nonce race: the EIP-712 hash uses the UEA's live storage nonce
|
|
435
|
+
// (not payload.nonce), so if anything advances it between our read and
|
|
436
|
+
// Cosmos inclusion the tx reverts with InvalidEVMSignature(0xc7dbd31d).
|
|
437
|
+
const resignOnSigMismatch = async () => {
|
|
438
|
+
const freshNonce = await (0, uea_manager_1.getUEANonce)(ctx, UEA);
|
|
439
|
+
const freshUeaVersion = await (0, uea_manager_1.fetchUEAVersion)(ctx);
|
|
440
|
+
const freshPayload = JSON.parse(JSON.stringify({ ...universalPayload, nonce: freshNonce }, helpers_1.bigintReplacer));
|
|
441
|
+
const freshSig = await (0, signing_1.signUniversalPayload)(ctx, freshPayload, UEA, freshUeaVersion);
|
|
442
|
+
return {
|
|
443
|
+
universalPayload: freshPayload,
|
|
444
|
+
verificationData: (0, viem_1.bytesToHex)(freshSig),
|
|
445
|
+
};
|
|
446
|
+
};
|
|
447
|
+
(0, context_1.fireProgressHook)(ctx, progress_hook_types_1.PROGRESS_HOOK.SEND_TX_107);
|
|
448
|
+
let transactions;
|
|
449
|
+
try {
|
|
450
|
+
transactions = await (0, push_chain_tx_1.sendUniversalTx)(ctx, isUEADeployed, feeLockTxHash, universalPayload, verificationData, eventBuffer, transformFn, resignOnSigMismatch);
|
|
451
|
+
}
|
|
452
|
+
catch (err) {
|
|
453
|
+
// Push Chain broadcast failed (Cosmos reject, UEA revert, nonce race
|
|
454
|
+
// exhaustion). Surface terminal 199-02 before re-throwing so the stream
|
|
455
|
+
// ends with the spec'd error hook. Typed PushChainExecutionError lets
|
|
456
|
+
// callers classify via instanceof without message sniffing.
|
|
457
|
+
const errMsg = (0, formatters_1.normalizePublicErrorMessage)(err);
|
|
458
|
+
(0, context_1.fireProgressHook)(ctx, progress_hook_types_1.PROGRESS_HOOK.SEND_TX_199_02, errMsg);
|
|
459
|
+
if (err instanceof push_chain_tx_1.PushChainExecutionError)
|
|
460
|
+
throw err;
|
|
461
|
+
throw new push_chain_tx_1.PushChainExecutionError(errMsg);
|
|
462
|
+
}
|
|
463
|
+
(0, context_1.fireProgressHook)(ctx, progress_hook_types_1.PROGRESS_HOOK.SEND_TX_199_01, transactions);
|
|
464
|
+
return transactions[transactions.length - 1];
|
|
468
465
|
}
|
|
469
466
|
//# sourceMappingURL=execute-standard.js.map
|