@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,7 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.Orchestrator = void 0;
4
- const tslib_1 = require("tslib");
5
4
  const chain_1 = require("../constants/chain");
6
5
  const enums_1 = require("../constants/enums");
7
6
  const progress_hook_types_1 = require("../progress-hook/progress-hook.types");
@@ -10,13 +9,29 @@ const formatters_1 = require("../formatters");
10
9
  const route_detector_1 = require("./route-detector");
11
10
  const data_utils_1 = require("./data-utils");
12
11
  const internals_1 = require("./internals");
12
+ const gate_1 = require("./internals/pc20/gate");
13
13
  class Orchestrator {
14
+ universalSigner;
15
+ pushNetwork;
16
+ rpcUrls;
17
+ printTraces;
18
+ progressHook;
19
+ // These fields are accessed via `this.ctx` (OrchestratorContext cast) by internal modules
20
+ _pushClient = null;
21
+ _pushClientOptions = null;
14
22
  /* @internal */ get pushClient() {
15
23
  if (!this._pushClient) {
16
24
  this._pushClient = new push_client_1.PushClient(this._pushClientOptions);
17
25
  }
18
26
  return this._pushClient;
19
27
  }
28
+ /* @internal */ accountStatusCache = null;
29
+ /* @internal */ accountStatusReadyPromise;
30
+ /**
31
+ * @internal Mirrors `OrchestratorContext.currentRoute` — set at the top of
32
+ * execute()/trackTransaction() so emission sites pick the right ID range.
33
+ */
34
+ /* @internal */ currentRoute;
20
35
  get ctx() { return this; }
21
36
  _getResponseCallbacks() {
22
37
  return {
@@ -42,10 +57,6 @@ class Orchestrator {
42
57
  this.rpcUrls = rpcUrls;
43
58
  this.printTraces = printTraces;
44
59
  this.progressHook = progressHook;
45
- // These fields are accessed via `this.ctx` (OrchestratorContext cast) by internal modules
46
- this._pushClient = null;
47
- this._pushClientOptions = null;
48
- /* @internal */ this.accountStatusCache = null;
49
60
  let pushChain;
50
61
  if (pushNetwork === enums_1.PUSH_NETWORK.MAINNET) {
51
62
  pushChain = enums_1.CHAIN.PUSH_MAINNET;
@@ -85,20 +96,16 @@ class Orchestrator {
85
96
  * Fetches account status including UEA deployment state and version info.
86
97
  * Results are cached — pass forceRefresh to bypass cache.
87
98
  */
88
- getAccountStatus(options) {
89
- return tslib_1.__awaiter(this, void 0, void 0, function* () {
90
- return (0, internals_1.getAccountStatus)(this.ctx, options);
91
- });
99
+ async getAccountStatus(options) {
100
+ return (0, internals_1.getAccountStatus)(this.ctx, options);
92
101
  }
93
102
  /**
94
103
  * Upgrades the UEA to the latest implementation version.
95
104
  * Sends MsgMigrateUEA Cosmos message with EIP-712 signed MigrationPayload.
96
105
  * The UEA contract delegates to the UEAMigration contract to update implementation.
97
106
  */
98
- upgradeAccount(options) {
99
- return tslib_1.__awaiter(this, void 0, void 0, function* () {
100
- return (0, internals_1.upgradeAccount)(this.ctx, options);
101
- });
107
+ async upgradeAccount(options) {
108
+ return (0, internals_1.upgradeAccount)(this.ctx, options);
102
109
  }
103
110
  /**
104
111
  * Migrate the CEA contract on an external chain to the latest version.
@@ -107,10 +114,8 @@ class Orchestrator {
107
114
  * @param chain - The external chain where the CEA should be migrated
108
115
  * @returns Transaction response
109
116
  */
110
- migrateCEA(chain) {
111
- return tslib_1.__awaiter(this, void 0, void 0, function* () {
112
- return (0, internals_1.migrateCEA)(this.ctx, chain, this.execute.bind(this));
113
- });
117
+ async migrateCEA(chain) {
118
+ return (0, internals_1.migrateCEA)(this.ctx, chain, this.execute.bind(this));
114
119
  }
115
120
  /**
116
121
  * Rescue stuck funds on a source chain.
@@ -121,180 +126,200 @@ class Orchestrator {
121
126
  * @param params - RescueFundsParams with universalTxId and prc20 token
122
127
  * @returns Transaction response
123
128
  */
124
- rescueFunds(params) {
125
- return tslib_1.__awaiter(this, void 0, void 0, function* () {
126
- return (0, internals_1.rescueFunds)(this.ctx, params, this.execute.bind(this));
127
- });
129
+ async rescueFunds(params) {
130
+ return (0, internals_1.rescueFunds)(this.ctx, params, this.execute.bind(this));
128
131
  }
129
132
  /**
130
133
  * Executes a transaction with automatic route detection.
131
134
  * Routes 2-4 (multi-chain) delegate to prepareTransaction().send().
132
135
  * Route 1 (Push Chain) dispatches to extracted sub-flow modules.
133
136
  */
134
- execute(params, options) {
135
- return tslib_1.__awaiter(this, void 0, void 0, function* () {
136
- var _a, _b, _c, _d, _e;
137
- const inlineProgressHook = params.progressHook;
138
- if (options || inlineProgressHook) {
139
- params = Object.assign(Object.assign({}, params), { options: Object.assign(Object.assign(Object.assign({}, params.options), (inlineProgressHook ? { progressHook: inlineProgressHook } : {})), options) });
140
- }
141
- const perCallHook = (_a = params.options) === null || _a === void 0 ? void 0 : _a.progressHook;
142
- const originalExecuteHook = this.progressHook;
143
- const currentHook = this.progressHook;
144
- const shouldWrapPerCallHook = !!perCallHook &&
145
- perCallHook !== currentHook &&
146
- (currentHook === null || currentHook === void 0 ? void 0 : currentHook.__pushPerCallHook) !== perCallHook;
147
- const attachPerCallHookForWait = (response) => {
148
- if (perCallHook && response._setProgressHookNoReplay) {
149
- response._setProgressHookNoReplay(perCallHook);
150
- }
151
- return response;
137
+ async execute(params, options) {
138
+ const inlineProgressHook = params.progressHook;
139
+ if (options || inlineProgressHook) {
140
+ params = {
141
+ ...params,
142
+ options: {
143
+ ...params.options,
144
+ ...(inlineProgressHook ? { progressHook: inlineProgressHook } : {}),
145
+ ...options,
146
+ },
152
147
  };
153
- if (shouldWrapPerCallHook) {
154
- const baseHook = this.progressHook;
155
- const wrappedHook = ((event) => {
156
- if (baseHook && baseHook !== perCallHook) {
157
- baseHook(event);
158
- }
159
- perCallHook(event);
160
- });
161
- wrappedHook.__pushPerCallHook = perCallHook;
162
- this.progressHook = wrappedHook;
163
- }
164
- // Snapshot the caller's active route — `executeMultiChain` recurses into
165
- // this same method for R2/R3's inner Push-side execution, and without
166
- // snapshot/restore the recursive `detectRoute(params)` would clobber the
167
- // outer R2/R3 route with UOA_TO_PUSH (the inner `to` is a string, no
168
- // `from`), defeating R1-suppression in fireProgressHook.
169
- const previousRoute = this.currentRoute;
170
- const isRecursiveInnerCall = previousRoute !== undefined;
171
- let detectedRoute;
172
- try {
173
- detectedRoute = (0, route_detector_1.detectRoute)(params);
174
- }
175
- catch (_f) {
176
- detectedRoute = route_detector_1.TransactionRoute.UOA_TO_PUSH;
148
+ }
149
+ const perCallHook = params.options?.progressHook;
150
+ const originalExecuteHook = this.progressHook;
151
+ const currentHook = this.progressHook;
152
+ const shouldWrapPerCallHook = !!perCallHook &&
153
+ perCallHook !== currentHook &&
154
+ currentHook?.__pushPerCallHook !== perCallHook;
155
+ const attachPerCallHookForWait = (response) => {
156
+ if (perCallHook && response._setProgressHookNoReplay) {
157
+ response._setProgressHookNoReplay(perCallHook);
177
158
  }
178
- // Don't downgrade an outer R2/R3/R4 route when the recursive inner call
179
- // resolves to R1 — keep the outer perspective so emission stays consistent.
180
- const shouldPreserveOuter = isRecursiveInnerCall &&
181
- previousRoute !== route_detector_1.TransactionRoute.UOA_TO_PUSH &&
182
- detectedRoute === route_detector_1.TransactionRoute.UOA_TO_PUSH;
183
- this.currentRoute = shouldPreserveOuter ? previousRoute : detectedRoute;
184
- // Reset the terminal-emitted flag at the start of each execute call so
185
- // the outer catch below can tell whether a route handler already fired
186
- // a terminal-ish error hook (104-04 / 204-04 / 304-04 / 199-02) and
187
- // should suppress the second terminal (199-02 / 299-02 / 399-02).
188
- this.ctx._routeTerminalEmitted = false;
159
+ return response;
160
+ };
161
+ if (shouldWrapPerCallHook) {
162
+ const baseHook = this.progressHook;
163
+ const wrappedHook = ((event) => {
164
+ if (baseHook && baseHook !== perCallHook) {
165
+ baseHook(event);
166
+ }
167
+ perCallHook(event);
168
+ });
169
+ wrappedHook.__pushPerCallHook = perCallHook;
170
+ this.progressHook = wrappedHook;
171
+ }
172
+ // Snapshot the caller's active route — `executeMultiChain` recurses into
173
+ // this same method for R2/R3's inner Push-side execution, and without
174
+ // snapshot/restore the recursive `detectRoute(params)` would clobber the
175
+ // outer R2/R3 route with UOA_TO_PUSH (the inner `to` is a string, no
176
+ // `from`), defeating R1-suppression in fireProgressHook.
177
+ const previousRoute = this.currentRoute;
178
+ const isRecursiveInnerCall = previousRoute !== undefined;
179
+ let detectedRoute;
180
+ try {
181
+ detectedRoute = (0, route_detector_1.detectRoute)(params);
182
+ }
183
+ catch {
184
+ detectedRoute = route_detector_1.TransactionRoute.UOA_TO_PUSH;
185
+ }
186
+ // Don't downgrade an outer R2/R3/R4 route when the recursive inner call
187
+ // resolves to R1 — keep the outer perspective so emission stays consistent.
188
+ const shouldPreserveOuter = isRecursiveInnerCall &&
189
+ previousRoute !== route_detector_1.TransactionRoute.UOA_TO_PUSH &&
190
+ detectedRoute === route_detector_1.TransactionRoute.UOA_TO_PUSH;
191
+ this.currentRoute = shouldPreserveOuter ? previousRoute : detectedRoute;
192
+ // Reset the terminal-emitted flag at the start of each execute call so
193
+ // the outer catch below can tell whether a route handler already fired
194
+ // a terminal-ish error hook (104-04 / 204-04 / 304-04 / 199-02) and
195
+ // should suppress the second terminal (199-02 / 299-02 / 399-02).
196
+ this.ctx._routeTerminalEmitted = false;
197
+ try {
198
+ // Lazy UEA upgrade check
189
199
  try {
190
- // Lazy UEA upgrade check
191
- try {
192
- if (!this.accountStatusCache || !this.accountStatusCache.uea.loaded) {
193
- yield ((_b = this.accountStatusReadyPromise) !== null && _b !== void 0 ? _b : this.getAccountStatus());
194
- }
195
- // If background resolved but cache still empty (timeout/error), fetch fresh
196
- if (!this.accountStatusCache || !this.accountStatusCache.uea.loaded) {
197
- yield this.getAccountStatus();
198
- }
199
- if (((_c = this.accountStatusCache) === null || _c === void 0 ? void 0 : _c.uea.deployed) &&
200
- ((_d = this.accountStatusCache) === null || _d === void 0 ? void 0 : _d.uea.requiresUpgrade)) {
201
- yield this.upgradeAccount({ progressHook: this.progressHook });
202
- }
200
+ if (!this.accountStatusCache || !this.accountStatusCache.uea.loaded) {
201
+ await (this.accountStatusReadyPromise ?? this.getAccountStatus());
203
202
  }
204
- catch (err) {
205
- (0, internals_1.printLog)(this.ctx, `Lazy UEA upgrade check failed: ${err instanceof Error ? err.message : String(err)}. Proceeding with transaction.`);
203
+ // If background resolved but cache still empty (timeout/error), fetch fresh
204
+ if (!this.accountStatusCache || !this.accountStatusCache.uea.loaded) {
205
+ await this.getAccountStatus();
206
206
  }
207
- // Check if this is a multi-chain request (has ChainTarget or from.chain)
208
- const isMultiChain = (0, route_detector_1.isChainTarget)(params.to) || ('from' in params && ((_e = params.from) === null || _e === void 0 ? void 0 : _e.chain));
209
- if (isMultiChain) {
210
- try {
211
- return attachPerCallHookForWait(yield (0, internals_1.executeMultiChain)(this.ctx, params, this.execute.bind(this)));
212
- }
213
- catch (err) {
214
- // R2/R3/R4 outer catch — fires the route-correct terminal failure
215
- // hook (299-02 / 399-02) when an inner route handler throws BEFORE
216
- // its own try/catch around executeFn (e.g. pre-flight balance
217
- // check throws). Without this, the hook stream ends mid-flight and
218
- // consumers have no terminal close-out marker.
219
- if (!isRecursiveInnerCall && !this.ctx._routeTerminalEmitted) {
220
- const errMessage = (0, formatters_1.normalizePublicErrorMessage)(err);
221
- // Lift any structured `decodedError` off the typed error so the
222
- // formatter's optional payload field gets populated.
223
- const decodedError = err instanceof Error && err.decodedError
224
- ? err.decodedError
225
- : undefined;
226
- if (this.currentRoute === route_detector_1.TransactionRoute.CEA_TO_PUSH) {
227
- (0, internals_1.fireProgressHook)(this.ctx, progress_hook_types_1.PROGRESS_HOOK.SEND_TX_399_02, errMessage, 'push', undefined, decodedError);
228
- }
229
- else if (this.currentRoute === route_detector_1.TransactionRoute.UOA_TO_CEA) {
230
- // 299-02 needs the target chain — pull it off ChainTarget.
231
- const targetChain = (0, route_detector_1.isChainTarget)(params.to) && params.to ? params.to.chain : 'unknown';
232
- (0, internals_1.fireProgressHook)(this.ctx, progress_hook_types_1.PROGRESS_HOOK.SEND_TX_299_02, targetChain, errMessage, decodedError);
233
- }
234
- else {
235
- (0, internals_1.fireProgressHook)(this.ctx, progress_hook_types_1.PROGRESS_HOOK.SEND_TX_199_02, errMessage, decodedError);
236
- }
237
- }
238
- throw err;
239
- }
207
+ if (this.accountStatusCache?.uea.deployed &&
208
+ this.accountStatusCache?.uea.requiresUpgrade) {
209
+ await this.upgradeAccount({ progressHook: this.progressHook });
240
210
  }
241
- // Standard Push Chain execution (Route 1)
242
- const execute = params;
243
- const hasData = (0, data_utils_1.hasExecutablePayloadData)(execute.data);
244
- const eventBuffer = [];
245
- const originalHook = this.progressHook;
246
- this.progressHook = (event) => {
247
- eventBuffer.push(event);
248
- if (originalHook)
249
- originalHook(event);
250
- };
211
+ }
212
+ catch (err) {
213
+ (0, internals_1.printLog)(this.ctx, `Lazy UEA upgrade check failed: ${err instanceof Error ? err.message : String(err)}. Proceeding with transaction.`);
214
+ }
215
+ // Check if this is a multi-chain request (has ChainTarget or from.chain)
216
+ const isMultiChain = (0, route_detector_1.isChainTarget)(params.to) || ('from' in params && params.from?.chain);
217
+ if (isMultiChain) {
251
218
  try {
252
- const rcb = () => this._getResponseCallbacks();
253
- if (execute.funds) {
254
- return attachPerCallHookForWait(!hasData
255
- ? yield (0, internals_1.executeFundsOnly)(this.ctx, execute, eventBuffer, rcb)
256
- : yield (0, internals_1.executeFundsWithPayload)(this.ctx, execute, eventBuffer, rcb));
257
- }
258
- return attachPerCallHookForWait(yield (0, internals_1.executeStandardPayload)(this.ctx, execute, eventBuffer, rcb));
219
+ // PC20 gate for the multi-chain routes. Resolves and validates before
220
+ // the route handlers quote gas or approve anything — a chain/address
221
+ // mismatch must cost the caller nothing.
222
+ const gatedParams = (await (0, gate_1.gateFunds)(this.ctx, params));
223
+ return attachPerCallHookForWait(await (0, internals_1.executeMultiChain)(this.ctx, gatedParams, this.execute.bind(this)));
259
224
  }
260
225
  catch (err) {
261
- const errMessage = (0, formatters_1.normalizePublicErrorMessage)(err);
262
- // Only the outermost frame emits the terminal error hook, and it picks
263
- // the route-correct ID. Recursive inner frames just re-throw so the
264
- // outer catch drives emission — avoids double-firing 199/299/399 events.
265
- // Additionally, if an inner route handler already fired a terminal-ish
266
- // error (104-04/204-04/304-04/199-02 via execute-standard), the flag is
267
- // set on ctx and we skip emitting a second terminal here.
226
+ // R2/R3/R4 outer catch — fires the route-correct terminal failure
227
+ // hook (299-02 / 399-02) when an inner route handler throws BEFORE
228
+ // its own try/catch around executeFn (e.g. pre-flight balance
229
+ // check throws). Without this, the hook stream ends mid-flight and
230
+ // consumers have no terminal close-out marker.
268
231
  if (!isRecursiveInnerCall && !this.ctx._routeTerminalEmitted) {
269
- // For R3, the failure surfaced during execute-phase (pre-wait) is a
270
- // Push-chain-side failure — tag phase='push' so 399-02 renders the
271
- // correct "Push Chain Tx Failed" title instead of the inbound copy.
232
+ const errMessage = (0, formatters_1.normalizePublicErrorMessage)(err);
233
+ // Lift any structured `decodedError` off the typed error so the
234
+ // formatter's optional payload field gets populated.
235
+ const decodedError = err instanceof Error && err.decodedError
236
+ ? err.decodedError
237
+ : undefined;
272
238
  if (this.currentRoute === route_detector_1.TransactionRoute.CEA_TO_PUSH) {
273
- (0, internals_1.fireProgressHook)(this.ctx, progress_hook_types_1.PROGRESS_HOOK.SEND_TX_399_02, errMessage, 'push');
239
+ (0, internals_1.fireProgressHook)(this.ctx, progress_hook_types_1.PROGRESS_HOOK.SEND_TX_399_02, errMessage, 'push', undefined, decodedError);
240
+ }
241
+ else if (this.currentRoute === route_detector_1.TransactionRoute.UOA_TO_CEA) {
242
+ // 299-02 needs the target chain — pull it off ChainTarget.
243
+ const targetChain = (0, route_detector_1.isChainTarget)(params.to) && params.to ? params.to.chain : 'unknown';
244
+ (0, internals_1.fireProgressHook)(this.ctx, progress_hook_types_1.PROGRESS_HOOK.SEND_TX_299_02, targetChain, errMessage, decodedError);
274
245
  }
275
246
  else {
276
- const terminalId = this.currentRoute === route_detector_1.TransactionRoute.UOA_TO_CEA
277
- ? progress_hook_types_1.PROGRESS_HOOK.SEND_TX_299_02
278
- : progress_hook_types_1.PROGRESS_HOOK.SEND_TX_199_02;
279
- (0, internals_1.fireProgressHook)(this.ctx, terminalId, errMessage);
247
+ (0, internals_1.fireProgressHook)(this.ctx, progress_hook_types_1.PROGRESS_HOOK.SEND_TX_199_02, errMessage, decodedError);
280
248
  }
281
249
  }
282
250
  throw err;
283
251
  }
284
- finally {
285
- // Restore original progressHook
286
- this.progressHook = originalHook;
252
+ }
253
+ // Standard Push Chain execution (Route 1)
254
+ const execute = params;
255
+ const hasData = (0, data_utils_1.hasExecutablePayloadData)(execute.data);
256
+ const eventBuffer = [];
257
+ const originalHook = this.progressHook;
258
+ this.progressHook = (event) => {
259
+ eventBuffer.push(event);
260
+ if (originalHook)
261
+ originalHook(event);
262
+ };
263
+ try {
264
+ const rcb = () => this._getResponseCallbacks();
265
+ if (execute.funds) {
266
+ // Single PC20 gate. Downstream builders only ever see the legacy
267
+ // PRC20/native shape; the PC20 branch is added here in Phase 2.
268
+ const legacy = await (0, gate_1.gateFunds)(this.ctx, execute);
269
+ // SVM PC20 imports never take the raw funds-only path: the Solana
270
+ // gateway prepends the PC20 selector to the (empty) payload and
271
+ // classifies the RESULT as FUNDS_AND_PAYLOAD, and the chain's
272
+ // inbound decode hard-fails on that selector-only payload with no
273
+ // revert — the wrapper is already burned (same "0x" vs "" guard as
274
+ // the R3 brick). The payload path always carries a real forward
275
+ // payload (UEA multicall transfer to `to`), which classifies and
276
+ // decodes legitimately — the same always-forward mitigation R3
277
+ // ships on both VMs.
278
+ const svmPc20Import = legacy._pc20?.direction === 'import' &&
279
+ chain_1.CHAIN_INFO[this.ctx.universalSigner.account.chain].vm === enums_1.VM.SVM;
280
+ return attachPerCallHookForWait(!hasData && !svmPc20Import
281
+ ? await (0, internals_1.executeFundsOnly)(this.ctx, legacy, eventBuffer, rcb)
282
+ : await (0, internals_1.executeFundsWithPayload)(this.ctx, legacy, eventBuffer, rcb));
287
283
  }
284
+ return attachPerCallHookForWait(await (0, internals_1.executeStandardPayload)(this.ctx, execute, eventBuffer, rcb));
288
285
  }
289
- finally {
290
- if (shouldWrapPerCallHook) {
291
- this.progressHook = originalExecuteHook;
286
+ catch (err) {
287
+ const errMessage = (0, formatters_1.normalizePublicErrorMessage)(err);
288
+ // Only the outermost frame emits the terminal error hook, and it picks
289
+ // the route-correct ID. Recursive inner frames just re-throw so the
290
+ // outer catch drives emission — avoids double-firing 199/299/399 events.
291
+ // Additionally, if an inner route handler already fired a terminal-ish
292
+ // error (104-04/204-04/304-04/199-02 via execute-standard), the flag is
293
+ // set on ctx and we skip emitting a second terminal here.
294
+ if (!isRecursiveInnerCall && !this.ctx._routeTerminalEmitted) {
295
+ // For R3, the failure surfaced during execute-phase (pre-wait) is a
296
+ // Push-chain-side failure — tag phase='push' so 399-02 renders the
297
+ // correct "Push Chain Tx Failed" title instead of the inbound copy.
298
+ if (this.currentRoute === route_detector_1.TransactionRoute.CEA_TO_PUSH) {
299
+ (0, internals_1.fireProgressHook)(this.ctx, progress_hook_types_1.PROGRESS_HOOK.SEND_TX_399_02, errMessage, 'push');
300
+ }
301
+ else {
302
+ const terminalId = this.currentRoute === route_detector_1.TransactionRoute.UOA_TO_CEA
303
+ ? progress_hook_types_1.PROGRESS_HOOK.SEND_TX_299_02
304
+ : progress_hook_types_1.PROGRESS_HOOK.SEND_TX_199_02;
305
+ (0, internals_1.fireProgressHook)(this.ctx, terminalId, errMessage);
306
+ }
292
307
  }
293
- // Restore the caller's route so a recursive inner R1 execute doesn't
294
- // leak its UOA_TO_PUSH route back to the outer R2/R3 frame.
295
- this.currentRoute = previousRoute;
308
+ throw err;
309
+ }
310
+ finally {
311
+ // Restore original progressHook
312
+ this.progressHook = originalHook;
313
+ }
314
+ }
315
+ finally {
316
+ if (shouldWrapPerCallHook) {
317
+ this.progressHook = originalExecuteHook;
296
318
  }
297
- });
319
+ // Restore the caller's route so a recursive inner R1 execute doesn't
320
+ // leak its UOA_TO_PUSH route back to the outer R2/R3 frame.
321
+ this.currentRoute = previousRoute;
322
+ }
298
323
  }
299
324
  /**
300
325
  * Prepare a universal transaction without executing it.
@@ -304,13 +329,17 @@ class Orchestrator {
304
329
  * @param options - Optional transaction behavior switches.
305
330
  * @returns PreparedUniversalTx with chaining capabilities
306
331
  */
307
- prepareTransaction(params, options) {
308
- return tslib_1.__awaiter(this, void 0, void 0, function* () {
309
- if (options) {
310
- params = Object.assign(Object.assign({}, params), { options: Object.assign(Object.assign({}, params.options), options) });
311
- }
312
- return (0, internals_1.prepareTransaction)(this.ctx, params, this._getCascadeCallbacks());
313
- });
332
+ async prepareTransaction(params, options) {
333
+ if (options) {
334
+ params = {
335
+ ...params,
336
+ options: {
337
+ ...params.options,
338
+ ...options,
339
+ },
340
+ };
341
+ }
342
+ return (0, internals_1.prepareTransaction)(this.ctx, params, this._getCascadeCallbacks());
314
343
  }
315
344
  /**
316
345
  * Creates a cascaded transaction builder for nested multi-chain execution.
@@ -324,8 +353,8 @@ class Orchestrator {
324
353
  * @returns Object with send() method
325
354
  */
326
355
  createCascadedBuilder(preparedTxs, options) {
327
- const perCallHook = options === null || options === void 0 ? void 0 : options.progressHook;
328
- const cascadeOptions = (options === null || options === void 0 ? void 0 : options.enforceGasCheck) === true
356
+ const perCallHook = options?.progressHook;
357
+ const cascadeOptions = options?.enforceGasCheck === true
329
358
  ? { enforceGasCheck: true }
330
359
  : undefined;
331
360
  if (!perCallHook) {
@@ -344,7 +373,7 @@ class Orchestrator {
344
373
  // reference-dedup.
345
374
  const innerBuilder = (0, internals_1.createCascadedBuilder)(this.ctx, preparedTxs, this._getCascadeCallbacks(), perCallHook, cascadeOptions);
346
375
  return {
347
- send: () => tslib_1.__awaiter(this, void 0, void 0, function* () {
376
+ send: async () => {
348
377
  const originalHook = this.progressHook;
349
378
  const wrapped = (event) => {
350
379
  if (originalHook && originalHook !== perCallHook) {
@@ -354,37 +383,31 @@ class Orchestrator {
354
383
  };
355
384
  this.progressHook = wrapped;
356
385
  try {
357
- return yield innerBuilder.send();
386
+ return await innerBuilder.send();
358
387
  }
359
388
  finally {
360
389
  this.progressHook = originalHook;
361
390
  }
362
- }),
391
+ },
363
392
  };
364
393
  }
365
394
  /**
366
395
  * Queries gas fee for an outbound transaction from the UniversalCore contract.
367
396
  */
368
- queryOutboundGasFee(prc20Token, gasLimit, destinationChain) {
369
- return tslib_1.__awaiter(this, void 0, void 0, function* () {
370
- return (0, internals_1.queryOutboundGasFee)(this.ctx, prc20Token, gasLimit, destinationChain);
371
- });
397
+ async queryOutboundGasFee(prc20Token, gasLimit, destinationChain) {
398
+ return (0, internals_1.queryOutboundGasFee)(this.ctx, prc20Token, gasLimit, destinationChain);
372
399
  }
373
400
  /**
374
401
  * Extracts the first universal sub-tx ID from a Push Chain transaction's Cosmos events.
375
402
  */
376
- extractUniversalSubTxIdFromTx(pushChainTxHash) {
377
- return tslib_1.__awaiter(this, void 0, void 0, function* () {
378
- return (0, internals_1.extractUniversalSubTxIdFromTx)(this.ctx, pushChainTxHash);
379
- });
403
+ async extractUniversalSubTxIdFromTx(pushChainTxHash) {
404
+ return (0, internals_1.extractUniversalSubTxIdFromTx)(this.ctx, pushChainTxHash);
380
405
  }
381
406
  /**
382
407
  * Extracts all universal sub-tx IDs from a cascaded Push Chain transaction.
383
408
  */
384
- extractAllUniversalSubTxIds(pushChainTxHash) {
385
- return tslib_1.__awaiter(this, void 0, void 0, function* () {
386
- return (0, internals_1.extractAllUniversalSubTxIds)(this.ctx, pushChainTxHash);
387
- });
409
+ async extractAllUniversalSubTxIds(pushChainTxHash) {
410
+ return (0, internals_1.extractAllUniversalSubTxIds)(this.ctx, pushChainTxHash);
388
411
  }
389
412
  /**
390
413
  * Tracks a transaction by hash on Push Chain and returns UniversalTxResponse.
@@ -399,10 +422,8 @@ class Orchestrator {
399
422
  * @throws If `options.chain` is provided but is not a supported chain (not present in CHAIN_INFO)
400
423
  * @throws If a source-leg hash cannot be resolved to a universal transaction on Push Chain
401
424
  */
402
- trackTransaction(txHash, options) {
403
- return tslib_1.__awaiter(this, void 0, void 0, function* () {
404
- return (0, internals_1.trackTransaction)(this.ctx, txHash, options, this._getResponseCallbacks());
405
- });
425
+ async trackTransaction(txHash, options) {
426
+ return (0, internals_1.trackTransaction)(this.ctx, txHash, options, this._getResponseCallbacks());
406
427
  }
407
428
  /**
408
429
  * Computes UEA for given UniversalAccount
@@ -410,10 +431,8 @@ class Orchestrator {
410
431
  * @dev - Don't use this fn in production - only used for testing
411
432
  * @returns UEA Address with Deployment Status
412
433
  */
413
- computeUEA() {
414
- return tslib_1.__awaiter(this, void 0, void 0, function* () {
415
- return (0, internals_1.computeUEA)(this.ctx);
416
- });
434
+ async computeUEA() {
435
+ return (0, internals_1.computeUEA)(this.ctx);
417
436
  }
418
437
  computeUEAOffchain() {
419
438
  return (0, internals_1.computeUEAOffchain)(this.ctx);
@@ -429,10 +448,8 @@ class Orchestrator {
429
448
  * Quotes exact-output on Uniswap V3 for EVM origin chains using QuoterV2.
430
449
  * Returns the minimum required input (amountIn) to receive the target amountOut.
431
450
  */
432
- _quoteExactOutput(amountOut_1, _a) {
433
- return tslib_1.__awaiter(this, arguments, void 0, function* (amountOut, { from, to, }) {
434
- return (0, internals_1.quoteExactOutput)(this.ctx, amountOut, { from, to });
435
- });
451
+ async _quoteExactOutput(amountOut, { from, to, }) {
452
+ return (0, internals_1.quoteExactOutput)(this.ctx, amountOut, { from, to });
436
453
  }
437
454
  }
438
455
  exports.Orchestrator = Orchestrator;