@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.
Files changed (112) hide show
  1. package/CHANGELOG.md +54 -0
  2. package/package.json +1 -1
  3. package/src/lib/cache/cache.js +2 -0
  4. package/src/lib/constants/abi/index.d.ts +1 -0
  5. package/src/lib/constants/abi/index.js +8 -1
  6. package/src/lib/constants/abi/pc20.evm.d.ts +217 -0
  7. package/src/lib/constants/abi/pc20.evm.js +150 -0
  8. package/src/lib/constants/abi/prc20.evm.d.ts +172 -0
  9. package/src/lib/constants/abi/prc20.evm.js +97 -0
  10. package/src/lib/constants/abi/universalGatewayV0.json +1 -1
  11. package/src/lib/constants/chain.js +38 -8
  12. package/src/lib/constants/selectors.js +2 -2
  13. package/src/lib/constants/tokens.js +4 -3
  14. package/src/lib/formatters.js +16 -6
  15. package/src/lib/generated/uexecutor/v1/query.js +2 -4
  16. package/src/lib/generated/uexecutor/v1/types.d.ts +14 -0
  17. package/src/lib/generated/uexecutor/v1/types.js +90 -47
  18. package/src/lib/generated/uexecutor/v2/query.js +2 -4
  19. package/src/lib/generated/uexecutor/v2/types.d.ts +20 -0
  20. package/src/lib/generated/uexecutor/v2/types.js +49 -33
  21. package/src/lib/generated/v1/tx.js +30 -37
  22. package/src/lib/index.d.ts +4 -1
  23. package/src/lib/index.js +21 -3
  24. package/src/lib/internal/buffer.js +1 -2
  25. package/src/lib/orchestrator/cea-utils.js +73 -83
  26. package/src/lib/orchestrator/internals/account-manager.js +130 -139
  27. package/src/lib/orchestrator/internals/cascade.d.ts +0 -6
  28. package/src/lib/orchestrator/internals/cascade.js +1184 -1059
  29. package/src/lib/orchestrator/internals/confirmation.js +138 -148
  30. package/src/lib/orchestrator/internals/error-decoder.js +1 -1
  31. package/src/lib/orchestrator/internals/errors.js +12 -3
  32. package/src/lib/orchestrator/internals/execute-funds-only.d.ts +2 -2
  33. package/src/lib/orchestrator/internals/execute-funds-only.js +297 -259
  34. package/src/lib/orchestrator/internals/execute-funds-payload.d.ts +2 -2
  35. package/src/lib/orchestrator/internals/execute-funds-payload.js +220 -220
  36. package/src/lib/orchestrator/internals/execute-standard.d.ts +0 -8
  37. package/src/lib/orchestrator/internals/execute-standard.js +339 -342
  38. package/src/lib/orchestrator/internals/gas-calculator.js +497 -520
  39. package/src/lib/orchestrator/internals/gas-usd-sizer.js +101 -110
  40. package/src/lib/orchestrator/internals/gateway-client.js +102 -103
  41. package/src/lib/orchestrator/internals/helpers.js +30 -27
  42. package/src/lib/orchestrator/internals/inbound-tracker.js +234 -238
  43. package/src/lib/orchestrator/internals/outbound-sync.js +463 -452
  44. package/src/lib/orchestrator/internals/outbound-tracker.js +27 -34
  45. package/src/lib/orchestrator/internals/payload-builder.d.ts +2 -2
  46. package/src/lib/orchestrator/internals/payload-builder.js +119 -100
  47. package/src/lib/orchestrator/internals/pc-usd-oracle.js +121 -129
  48. package/src/lib/orchestrator/internals/pc20/address-codec.d.ts +31 -0
  49. package/src/lib/orchestrator/internals/pc20/address-codec.js +124 -0
  50. package/src/lib/orchestrator/internals/pc20/chain-namespace.d.ts +68 -0
  51. package/src/lib/orchestrator/internals/pc20/chain-namespace.js +136 -0
  52. package/src/lib/orchestrator/internals/pc20/errors.d.ts +160 -0
  53. package/src/lib/orchestrator/internals/pc20/errors.js +236 -0
  54. package/src/lib/orchestrator/internals/pc20/export.d.ts +172 -0
  55. package/src/lib/orchestrator/internals/pc20/export.js +412 -0
  56. package/src/lib/orchestrator/internals/pc20/gate.d.ts +67 -0
  57. package/src/lib/orchestrator/internals/pc20/gate.js +184 -0
  58. package/src/lib/orchestrator/internals/pc20/resolver.d.ts +187 -0
  59. package/src/lib/orchestrator/internals/pc20/resolver.js +658 -0
  60. package/src/lib/orchestrator/internals/pc20/svm.d.ts +189 -0
  61. package/src/lib/orchestrator/internals/pc20/svm.js +286 -0
  62. package/src/lib/orchestrator/internals/pc20/tracking.d.ts +46 -0
  63. package/src/lib/orchestrator/internals/pc20/tracking.js +109 -0
  64. package/src/lib/orchestrator/internals/preflight.js +1 -1
  65. package/src/lib/orchestrator/internals/progress-route-hooks.js +2 -2
  66. package/src/lib/orchestrator/internals/push-chain-tx.js +319 -331
  67. package/src/lib/orchestrator/internals/quote.js +90 -94
  68. package/src/lib/orchestrator/internals/rescue.js +76 -79
  69. package/src/lib/orchestrator/internals/response-builder.d.ts +28 -1
  70. package/src/lib/orchestrator/internals/response-builder.js +817 -701
  71. package/src/lib/orchestrator/internals/route-handlers.d.ts +7 -15
  72. package/src/lib/orchestrator/internals/route-handlers.js +1512 -1178
  73. package/src/lib/orchestrator/internals/signing.js +78 -83
  74. package/src/lib/orchestrator/internals/svm-bridge.d.ts +2 -2
  75. package/src/lib/orchestrator/internals/svm-bridge.js +161 -93
  76. package/src/lib/orchestrator/internals/svm-helpers.d.ts +15 -1
  77. package/src/lib/orchestrator/internals/svm-helpers.js +68 -24
  78. package/src/lib/orchestrator/internals/svm-rent.d.ts +19 -1
  79. package/src/lib/orchestrator/internals/svm-rent.js +163 -141
  80. package/src/lib/orchestrator/internals/tx-transformer.js +26 -23
  81. package/src/lib/orchestrator/internals/uea-manager.js +89 -86
  82. package/src/lib/orchestrator/max-pc-for-gas.js +5 -6
  83. package/src/lib/orchestrator/orchestrator.js +217 -200
  84. package/src/lib/orchestrator/orchestrator.types.d.ts +121 -1
  85. package/src/lib/orchestrator/orchestrator.types.js +19 -0
  86. package/src/lib/orchestrator/payload-builders.d.ts +2 -2
  87. package/src/lib/orchestrator/payload-builders.js +26 -24
  88. package/src/lib/orchestrator/route-detector.js +26 -9
  89. package/src/lib/orchestrator/svm-idl/ix-encoder.js +1 -2
  90. package/src/lib/orchestrator/svm-idl/normalize-address.js +2 -2
  91. package/src/lib/orchestrator/svm-idl/resolve.js +1 -2
  92. package/src/lib/price-fetch/price-fetch.js +67 -68
  93. package/src/lib/progress-hook/progress-hook.js +124 -72
  94. package/src/lib/push-chain/push-chain.js +171 -153
  95. package/src/lib/push-client/push-client.js +223 -237
  96. package/src/lib/universal/account/account.js +349 -365
  97. package/src/lib/universal/signer/signer.d.ts +2 -1
  98. package/src/lib/universal/signer/signer.js +315 -299
  99. package/src/lib/universal-tx-detector/auto-detect.js +55 -60
  100. package/src/lib/universal-tx-detector/cascade.js +160 -172
  101. package/src/lib/universal-tx-detector/child-inbounds.js +67 -75
  102. package/src/lib/universal-tx-detector/classify.js +2 -3
  103. package/src/lib/universal-tx-detector/detector-svm.js +139 -147
  104. package/src/lib/universal-tx-detector/detector.js +145 -157
  105. package/src/lib/universal-tx-detector/normalize.js +7 -7
  106. package/src/lib/utils/external-tx-hash.js +1 -2
  107. package/src/lib/utils.d.ts +44 -0
  108. package/src/lib/utils.js +762 -683
  109. package/src/lib/vm-client/evm-client.js +186 -202
  110. package/src/lib/vm-client/svm-client.d.ts +1 -1
  111. package/src/lib/vm-client/svm-client.js +220 -224
  112. 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
- return tslib_1.__awaiter(this, void 0, void 0, function* () {
88
- var _a, _b, _c;
89
- const transformFn = (tx, buf = []) => (0, response_builder_1.transformToUniversalTxResponse)(ctx, tx, buf, getResponseCallbacks());
90
- // Set default value for value if undefined
91
- if (execute.value === undefined) {
92
- execute.value = BigInt(0);
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
- const chain = ctx.universalSigner.account.chain;
95
- (0, context_1.fireProgressHook)(ctx, progress_hook_types_1.PROGRESS_HOOK.SEND_TX_101, chain, ctx.universalSigner.account.address);
96
- (0, helpers_1.validateMainnetConnection)(chain, ctx.pushClient.pushChainInfo.chainId);
97
- // Gas estimation fires for both Push-to-Push and external-origin flows so
98
- // reconstructProgressEvents (which always emits 102-01/02) and live execute
99
- // stay in lockstep. For the Push-to-Push shortcut we have no origin-chain
100
- // gas to estimate; surface the tx gas limit as the "cost" to match what
101
- // the reconstruction path does (it reads universalTxResponse.gasLimit).
102
- (0, context_1.fireProgressHook)(ctx, progress_hook_types_1.PROGRESS_HOOK.SEND_TX_102_01);
103
- // Push to Push Tx
104
- if ((0, helpers_1.isPushChain)(chain)) {
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
- (0, context_1.fireProgressHook)(ctx, progress_hook_types_1.PROGRESS_HOOK.SEND_TX_199_01, [tx]);
126
- return tx;
121
+ throw err;
127
122
  }
128
- // Fetch Gas details and estimate cost of execution
129
- const gasEstimate = execute.gasLimit || BigInt(1e7);
130
- const gasPrice = yield ctx.pushClient.getGasPrice();
131
- const requiredGasFee = gasEstimate * gasPrice;
132
- const requiredFunds = resolveRequiredFunds(requiredGasFee, execute.value, execute._requiredFundsOverride);
133
- // Fetch UEA Details (or use pre-fetched status if available)
134
- const UEA = (0, uea_manager_1.computeUEAOffchain)(ctx);
135
- let isUEADeployed;
136
- let nonce;
137
- let funds;
138
- (0, context_1.fireProgressHook)(ctx, progress_hook_types_1.PROGRESS_HOOK.SEND_TX_103_01);
139
- if (execute._ueaStatus) {
140
- isUEADeployed = execute._ueaStatus.isDeployed;
141
- nonce = execute._ueaStatus.nonce;
142
- funds = execute._ueaStatus.balance;
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
- // Skip getCode if accountStatusCache already confirmed deployment
146
- const deployedHint = (_c = (_b = ctx.accountStatusCache) === null || _b === void 0 ? void 0 : _b.uea) === null || _c === void 0 ? void 0 : _c.deployed;
147
- if (deployedHint) {
148
- const [balance, ueaNonce] = yield Promise.all([
149
- ctx.pushClient.getBalance(UEA),
150
- (0, uea_manager_1.getUEANonce)(ctx, UEA),
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
- (0, context_1.fireProgressHook)(ctx, progress_hook_types_1.PROGRESS_HOOK.SEND_TX_103_02, UEA, isUEADeployed);
167
- (0, context_1.fireProgressHook)(ctx, progress_hook_types_1.PROGRESS_HOOK.SEND_TX_103_03_04, requiredFunds, BigInt(0), chain);
168
- // Validate and decode feeLockTxHash
169
- let feeLockTxHash = execute.feeLockTxHash;
170
- if (feeLockTxHash) {
171
- (0, helpers_1.validateFeeLockTxHash)(feeLockTxHash);
172
- if (!feeLockTxHash.startsWith('0x')) {
173
- const decoded = bs58_1.bs58.decode(feeLockTxHash);
174
- feeLockTxHash = (0, viem_1.bytesToHex)(new Uint8Array(decoded));
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
- else {
204
- if (execute.to.toLowerCase() !== UEA.toLowerCase()) {
205
- if (execute.funds) {
206
- payloadTo = viem_1.zeroAddress;
207
- payloadData = (0, payload_builder_1.buildMulticallPayloadData)(ctx, execute.to, (0, payload_builders_1.buildExecuteMulticall)({ execute, ueaAddress: UEA }));
208
- req = (0, payload_builder_1.buildUniversalTxRequest)(ctx.universalSigner.account.address, {
209
- recipient: viem_1.zeroAddress, token: viem_1.zeroAddress, amount: BigInt(0), payload: payloadData,
210
- });
211
- }
212
- else {
213
- payloadTo = execute.to;
214
- payloadData = execute.data || '0x';
215
- const reqData = (0, payload_builder_1.buildMulticallPayloadData)(ctx, execute.to, (0, payload_builders_1.buildExecuteMulticall)({ execute, ueaAddress: UEA }));
216
- const universalPayloadOther = JSON.parse(JSON.stringify({
217
- to: viem_1.zeroAddress, value: execute.value,
218
- data: reqData,
219
- gasLimit: execute.gasLimit || BigInt(5e7),
220
- maxFeePerGas: execute.maxFeePerGas || BigInt(1e10),
221
- maxPriorityFeePerGas: execute.maxPriorityFeePerGas || BigInt(0),
222
- nonce, deadline: execute.deadline || BigInt(9999999999),
223
- vType: feeLockingRequired
224
- ? tx_1.VerificationType.universalTxVerification
225
- : tx_1.VerificationType.signedVerification,
226
- }, helpers_1.bigintReplacer));
227
- req = (0, payload_builder_1.buildUniversalTxRequest)(ctx.universalSigner.account.address, {
228
- recipient: viem_1.zeroAddress, token: viem_1.zeroAddress, amount: BigInt(0),
229
- payload: encodePayloadForOriginIfNeeded(ctx, universalPayloadOther, feeLockingRequired),
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 universalPayloadSelf = JSON.parse(JSON.stringify({
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, universalPayloadSelf, feeLockingRequired),
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
- // Fee Locking
287
- const fundDifference = requiredFunds - funds;
288
- const fixedPushAmount = utils_1.Utils.helpers.parseUnits('0.001', 18);
289
- const lockAmount = funds < requiredFunds ? fundDifference : fixedPushAmount;
290
- // Size the USD deposit against the REAL Uniswap pool rate (not the fixed
291
- // $0.10/PC SDK rate) for EVM origins. The pool typically prices PC much
292
- // higher than $0.10, so pushToUSDC under-provisions and the resulting
293
- // deposit gets clamped up to the $1 minimum, producing near-zero WPC.
294
- // When the quoted USD exceeds the $1000 cap the later clamp kicks in
295
- // (pool limit surfaces via the pre-flight capacity message).
296
- // Falls back to pushToUSDC if the quoter is unavailable.
297
- const { vm: sizingOriginVm } = chain_1.CHAIN_INFO[chain];
298
- let lockAmountInUSD = ctx.pushClient.pushToUSDC(lockAmount);
299
- if (sizingOriginVm === enums_1.VM.EVM && lockAmount > BigInt(0)) {
300
- // Target lockAmount × 1.2 so that the 10% slippage margin applied by
301
- // the pre-flight check (safeUPC = predictedUPC × 0.9) leaves enough
302
- // headroom even when Uniswap V3 exactOutput↔exactInput quotes aren't
303
- // perfectly symmetric (tick-math rounding).
304
- const targetWPC = (lockAmount * BigInt(12)) / BigInt(10);
305
- const originPrc20ForSizing = (0, helpers_2.getNativePRC20ForChain)(chain, ctx.pushNetwork);
306
- const requiredNative = yield (0, gas_calculator_1.estimateNativeForDesiredDeposit)(ctx, targetWPC, originPrc20ForSizing);
307
- if (requiredNative > BigInt(0)) {
308
- const ethPriceForSizing = yield new price_fetch_1.PriceFetch(ctx.rpcUrls).getPrice(chain);
309
- if (ethPriceForSizing > BigInt(0)) {
310
- // requiredNative (18-dec wei) × ethPrice (8-dec USD/ETH) / 1e18 = USD in 8-dec
311
- const poolBasedUsd = (requiredNative * ethPriceForSizing) / BigInt(1e18);
312
- (0, context_1.printLog)(ctx, `Fee-lock sizing: pushToUSDC=${lockAmountInUSD.toString()} (fixed $0.10/PC), ` +
313
- `poolBased=${poolBasedUsd.toString()} (pool quote for ${targetWPC.toString()} WPC) — using poolBased`);
314
- lockAmountInUSD = poolBasedUsd;
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
- // Apply minimum deposit override (e.g., Route 2 needs enough UPC for outbound swap)
319
- const effectiveLockAmountInUSD = execute._minimumDepositUsd && execute._minimumDepositUsd > lockAmountInUSD
320
- ? execute._minimumDepositUsd
321
- : lockAmountInUSD;
322
- // Pre-flight: predict the actual $PC the UEA will receive after the
323
- // on-chain pETH → WPC swap and validate it covers requiredFunds.
324
- // Uses the same Uniswap V3 quoter the chain uses (execute_inbound_gas.go).
325
- // Mirrors the pattern in route-handlers.ts (Route 2/3).
326
- const { vm: originVm } = chain_1.CHAIN_INFO[chain];
327
- if (originVm === enums_1.VM.EVM) {
328
- try {
329
- // Replicate lockFee's USD → native conversion (with its $1–$1000 clamp)
330
- const oneUsd = utils_1.Utils.helpers.parseUnits('1', 8);
331
- const maxUsd = utils_1.Utils.helpers.parseUnits('1000', 8);
332
- let depositUsd = effectiveLockAmountInUSD < oneUsd ? oneUsd : effectiveLockAmountInUSD;
333
- if (depositUsd > maxUsd)
334
- depositUsd = maxUsd;
335
- const ethPrice = yield new price_fetch_1.PriceFetch(ctx.rpcUrls).getPrice(chain);
336
- if (ethPrice > BigInt(0)) {
337
- const nativeAmountETH = (depositUsd * BigInt(1e18) + (ethPrice - BigInt(1))) / ethPrice + BigInt(1);
338
- const originPrc20 = (0, helpers_2.getNativePRC20ForChain)(chain, ctx.pushNetwork);
339
- const predictedUPC = yield (0, gas_calculator_1.estimateDepositFromLockedNative)(ctx, nativeAmountETH, originPrc20);
340
- if (predictedUPC > BigInt(0)) {
341
- // 10% slippage margin (same as route-handlers.ts)
342
- const safeUPC = (predictedUPC * BigInt(90)) / BigInt(100);
343
- const totalAvailable = safeUPC + funds;
344
- (0, context_1.printLog)(ctx, `Fee-lock pre-flight: deposit ${depositUsd.toString()} USD → ` +
345
- `~${nativeAmountETH.toString()} wei ETH → ~${predictedUPC.toString()} UPC ` +
346
- `(safe: ${safeUPC.toString()}), existing: ${funds.toString()}, ` +
347
- `total: ${totalAvailable.toString()}, required: ${requiredFunds.toString()}`);
348
- if (totalAvailable < requiredFunds) {
349
- const shortfall = requiredFunds - totalAvailable;
350
- // On failure only: probe pool capacity at the max cap so the
351
- // caller gets a readable "max transferable right now" number.
352
- // One extra quoter call — not run on the success path.
353
- let maxTransferableNote = '';
354
- if (depositUsd < maxUsd) {
355
- const maxNativeAmountETH = (maxUsd * BigInt(1e18) + (ethPrice - BigInt(1))) / ethPrice + BigInt(1);
356
- const maxPredictedUPC = yield (0, gas_calculator_1.estimateDepositFromLockedNative)(ctx, maxNativeAmountETH, originPrc20);
357
- if (maxPredictedUPC > BigInt(0)) {
358
- const maxSafeUPC = (maxPredictedUPC * BigInt(90)) / BigInt(100);
359
- const gasReserve = utils_1.Utils.helpers.parseUnits('0.01', 18);
360
- const maxFromDeposit = maxSafeUPC > gasReserve ? maxSafeUPC - gasReserve : BigInt(0);
361
- const maxTransferable = funds + maxFromDeposit;
362
- maxTransferableNote =
363
- `Max transferable right now (at $1000 cap, pool-limited): ` +
364
- `~${(0, formatters_1.formatPc)(maxTransferable, 4)} ` +
365
- `(UEA balance ${(0, formatters_1.formatPc)(funds, 4)} + ` +
366
- `pool-safe deposit ${(0, formatters_1.formatPc)(maxFromDeposit, 4)} - gas).`;
367
- (0, context_1.printLog)(ctx, `Fee-lock capacity: ${maxTransferableNote}`);
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
- // User declined the fee-lock tx submission or the origin-chain RPC
396
- // rejected it — classifier picks decline vs generic signature failure.
397
- const errMsg = (0, formatters_1.normalizePublicErrorMessage)(err);
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
- throw err;
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
- // Non-fee-locking path: Broadcasting Tx to PC via sendUniversalTx.
435
- // Provide a resign callback so sendUniversalTx can recover from the
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
- transactions = yield (0, push_chain_tx_1.sendUniversalTx)(ctx, isUEADeployed, feeLockTxHash, universalPayload, verificationData, eventBuffer, transformFn, resignOnSigMismatch);
390
+ feeLockTxHashBytes = await (0, gateway_client_1.lockFee)(ctx, effectiveLockAmountInUSD, universalPayload, req);
453
391
  }
454
392
  catch (err) {
455
- // Push Chain broadcast failed (Cosmos reject, UEA revert, nonce race
456
- // exhaustion). Surface terminal 199-02 before re-throwing so the stream
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.SEND_TX_199_02, errMsg);
461
- if (err instanceof push_chain_tx_1.PushChainExecutionError)
462
- throw err;
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, context_1.fireProgressHook)(ctx, progress_hook_types_1.PROGRESS_HOOK.SEND_TX_199_01, transactions);
466
- return transactions[transactions.length - 1];
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