@pushchain/core 6.0.20 → 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 +48 -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 +3 -0
- 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 -329
- 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.js +306 -294
- 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,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
|
|
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
|
|
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
|
|
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
|
|
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
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
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
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
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
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
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
|
-
|
|
191
|
-
|
|
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
|
-
|
|
205
|
-
|
|
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
|
-
|
|
208
|
-
|
|
209
|
-
|
|
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
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
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
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
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
|
-
|
|
262
|
-
//
|
|
263
|
-
//
|
|
264
|
-
//
|
|
265
|
-
//
|
|
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
|
-
|
|
270
|
-
//
|
|
271
|
-
//
|
|
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
|
-
|
|
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
|
-
|
|
285
|
-
|
|
286
|
-
|
|
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
|
-
|
|
290
|
-
|
|
291
|
-
|
|
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
|
-
|
|
294
|
-
|
|
295
|
-
|
|
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
|
-
|
|
309
|
-
|
|
310
|
-
params
|
|
311
|
-
|
|
312
|
-
|
|
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
|
|
328
|
-
const cascadeOptions =
|
|
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: () =>
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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(
|
|
433
|
-
return
|
|
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;
|