@sodax/sdk 2.1.0-rc.3 → 2.1.0-rc.4
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/dist/index.cjs +347 -128
- package/dist/index.d.cts +203 -60
- package/dist/index.d.ts +203 -60
- package/dist/index.mjs +347 -128
- package/package.json +4 -4
package/dist/index.cjs
CHANGED
|
@@ -3365,7 +3365,7 @@ var spokeChainConfig = {
|
|
|
3365
3365
|
supportedTokens: suiSupportedTokens,
|
|
3366
3366
|
nativeToken: "0x0000000000000000000000000000000000000000000000000000000000000002::sui::SUI",
|
|
3367
3367
|
bnUSD: "0xff4de2b2b57dd7611d2812d231a467d007b702a101fd5c7ad3b278257cddb507::bnusd::BNUSD",
|
|
3368
|
-
rpc_url: "https://
|
|
3368
|
+
rpc_url: "https://sui-rpc.publicnode.com",
|
|
3369
3369
|
chain: baseChainInfo[ChainKeys.SUI_MAINNET],
|
|
3370
3370
|
pollingConfig: {
|
|
3371
3371
|
pollingIntervalMs: 500,
|
|
@@ -4456,7 +4456,13 @@ function isValidWalletProviderForChainKey(chainKey, walletProvider) {
|
|
|
4456
4456
|
}
|
|
4457
4457
|
|
|
4458
4458
|
// ../types/dist/index.js
|
|
4459
|
-
var CONFIG_VERSION =
|
|
4459
|
+
var CONFIG_VERSION = 224;
|
|
4460
|
+
|
|
4461
|
+
// src/shared/utils/resolveTimeoutMs.ts
|
|
4462
|
+
function resolveTimeoutMs(timeout, fallbackMs) {
|
|
4463
|
+
if (timeout === void 0 || !Number.isFinite(timeout)) return fallbackMs;
|
|
4464
|
+
return Math.max(0, timeout);
|
|
4465
|
+
}
|
|
4460
4466
|
function isEvmSpokeChainConfig(value) {
|
|
4461
4467
|
return typeof value === "object" && value !== null && value.chain.type === "EVM" && value.chain.key !== HUB_CHAIN_KEY;
|
|
4462
4468
|
}
|
|
@@ -4883,7 +4889,7 @@ async function pollForExecutedPacket(payload, deadline) {
|
|
|
4883
4889
|
}
|
|
4884
4890
|
async function waitUntilIntentExecuted(payload) {
|
|
4885
4891
|
try {
|
|
4886
|
-
const timeout = payload.timeout
|
|
4892
|
+
const timeout = resolveTimeoutMs(payload.timeout, DEFAULT_RELAY_TX_TIMEOUT);
|
|
4887
4893
|
const startTime = Date.now();
|
|
4888
4894
|
const deadline = startTime + timeout;
|
|
4889
4895
|
let lastPollingError;
|
|
@@ -4916,7 +4922,8 @@ async function waitUntilIntentExecuted(payload) {
|
|
|
4916
4922
|
}
|
|
4917
4923
|
async function relayTxAndWaitPacket(params) {
|
|
4918
4924
|
try {
|
|
4919
|
-
const { srcTxHash, data, chainKey, relayerApiEndpoint,
|
|
4925
|
+
const { srcTxHash, data, chainKey, relayerApiEndpoint, pollTxHash } = params;
|
|
4926
|
+
const timeout = resolveTimeoutMs(params.timeout, DEFAULT_RELAY_TX_TIMEOUT);
|
|
4920
4927
|
const intentRelayChainId = getIntentRelayChainId(chainKey).toString();
|
|
4921
4928
|
const isSplitTxChain = isSolanaChainKeyType(chainKey) || isBitcoinChainKeyType(chainKey);
|
|
4922
4929
|
invariant(!isSplitTxChain || data !== void 0, "Data is required for Solana and Bitcoin chain keys");
|
|
@@ -14324,6 +14331,17 @@ var ConfigService = class {
|
|
|
14324
14331
|
get leverageYieldPartnerFee() {
|
|
14325
14332
|
return this.leverageYield.partnerFee ?? this.fee;
|
|
14326
14333
|
}
|
|
14334
|
+
// Effective backend submit-tx toggle per feature. Read live off the same `swaps` / `bridge` slots as
|
|
14335
|
+
// `partnerFee` so an omitted flag resolves to the ON default here, in one place, instead of leaving
|
|
14336
|
+
// `config.swaps.useBackendSubmitTx === undefined` while the backend path is actually active.
|
|
14337
|
+
// The deprecated `swapsOptions` / `bridgeOptions` keys are still honoured as a second-precedence
|
|
14338
|
+
// fallback, so a pre-existing explicit opt-out keeps the client-side path instead of silently flipping.
|
|
14339
|
+
get swapUseBackendSubmitTx() {
|
|
14340
|
+
return this.swaps.useBackendSubmitTx ?? this.sodax.swapsOptions?.useBackendSubmitTx ?? true;
|
|
14341
|
+
}
|
|
14342
|
+
get bridgeUseBackendSubmitTx() {
|
|
14343
|
+
return this.bridge.useBackendSubmitTx ?? this.sodax.bridgeOptions?.useBackendSubmitTx ?? true;
|
|
14344
|
+
}
|
|
14327
14345
|
get dex() {
|
|
14328
14346
|
return this.sodax.dex;
|
|
14329
14347
|
}
|
|
@@ -26947,19 +26965,20 @@ var SolverApiService = class {
|
|
|
26947
26965
|
|
|
26948
26966
|
// src/backendApi/pollBackendSubmitTx.ts
|
|
26949
26967
|
async function pollBackendSubmitTx({
|
|
26950
|
-
|
|
26968
|
+
attempt,
|
|
26951
26969
|
terminalStatus,
|
|
26952
26970
|
getStatus,
|
|
26953
26971
|
onExecuted,
|
|
26954
26972
|
intervalMs = 1e3,
|
|
26955
26973
|
requestTimeoutMs
|
|
26956
26974
|
}) {
|
|
26957
|
-
|
|
26958
|
-
|
|
26959
|
-
|
|
26960
|
-
|
|
26961
|
-
const statusResult = await getStatus(
|
|
26975
|
+
let polls = 0;
|
|
26976
|
+
let lastStatusError;
|
|
26977
|
+
for (let requestTimeout = attempt.requestTimeout(requestTimeoutMs); requestTimeout !== null; requestTimeout = attempt.requestTimeout(requestTimeoutMs)) {
|
|
26978
|
+
polls += 1;
|
|
26979
|
+
const statusResult = await getStatus({ timeout: requestTimeout });
|
|
26962
26980
|
if (statusResult.ok) {
|
|
26981
|
+
lastStatusError = void 0;
|
|
26963
26982
|
const { status, result, failureReason, abandonedAt } = statusResult.value.data;
|
|
26964
26983
|
if (status === terminalStatus) {
|
|
26965
26984
|
const value = onExecuted(result);
|
|
@@ -26969,11 +26988,70 @@ async function pollBackendSubmitTx({
|
|
|
26969
26988
|
const reason = failureReason ? `: ${failureReason}` : "";
|
|
26970
26989
|
return { ok: false, cause: new Error(`backend submit-tx ${status}${reason}`) };
|
|
26971
26990
|
}
|
|
26991
|
+
} else {
|
|
26992
|
+
lastStatusError = statusResult.error;
|
|
26972
26993
|
}
|
|
26973
|
-
|
|
26994
|
+
if (attempt.remaining() <= intervalMs) break;
|
|
26995
|
+
await sleep(intervalMs);
|
|
26996
|
+
}
|
|
26997
|
+
if (polls === 0) {
|
|
26998
|
+
return { ok: false, cause: new Error("backend submit-tx submitted, but no budget was left to poll for status") };
|
|
26999
|
+
}
|
|
27000
|
+
if (lastStatusError !== void 0) {
|
|
27001
|
+
return {
|
|
27002
|
+
ok: false,
|
|
27003
|
+
cause: new Error(`backend submit-tx status polling failed before reaching ${terminalStatus}`, {
|
|
27004
|
+
cause: lastStatusError
|
|
27005
|
+
})
|
|
27006
|
+
};
|
|
26974
27007
|
}
|
|
26975
27008
|
return { ok: false, cause: new Error(`backend submit-tx polling timed out before reaching ${terminalStatus}`) };
|
|
26976
27009
|
}
|
|
27010
|
+
|
|
27011
|
+
// src/backendApi/submitTxAttempt.ts
|
|
27012
|
+
function noRequestBudgetCause(serviceTimeoutMs) {
|
|
27013
|
+
return serviceTimeoutMs > 0 ? new Error("backend submit-tx skipped: the caller timeout left no budget for the attempt") : new Error(`backend submit-tx skipped: api timeout must be a positive number, got ${serviceTimeoutMs}`);
|
|
27014
|
+
}
|
|
27015
|
+
function createSubmitTxAttempt(callerTimeoutMs) {
|
|
27016
|
+
const deadline = Date.now() + resolveTimeoutMs(callerTimeoutMs, 0);
|
|
27017
|
+
const remaining = () => Math.max(0, deadline - Date.now());
|
|
27018
|
+
return {
|
|
27019
|
+
remaining,
|
|
27020
|
+
requestTimeout: (serviceTimeoutMs) => {
|
|
27021
|
+
const timeout = Math.min(remaining(), serviceTimeoutMs);
|
|
27022
|
+
return timeout > 0 ? timeout : null;
|
|
27023
|
+
}
|
|
27024
|
+
};
|
|
27025
|
+
}
|
|
27026
|
+
|
|
27027
|
+
// src/backendApi/runBackendSubmitTx.ts
|
|
27028
|
+
async function runBackendSubmitTx({
|
|
27029
|
+
attempt,
|
|
27030
|
+
api,
|
|
27031
|
+
body,
|
|
27032
|
+
statusQuery,
|
|
27033
|
+
terminalStatus,
|
|
27034
|
+
onExecuted
|
|
27035
|
+
}) {
|
|
27036
|
+
const serviceTimeoutMs = api.getTimeout();
|
|
27037
|
+
const requestTimeout = attempt.requestTimeout(serviceTimeoutMs);
|
|
27038
|
+
if (requestTimeout === null) return { ok: false, cause: noRequestBudgetCause(serviceTimeoutMs) };
|
|
27039
|
+
const submitted = await api.submitTx(body, { timeout: requestTimeout });
|
|
27040
|
+
if (!submitted.ok) return { ok: false, cause: submitted.error };
|
|
27041
|
+
if (!submitted.value.success) {
|
|
27042
|
+
return { ok: false, cause: new Error(`backend submit-tx not accepted: ${submitted.value.data.message}`) };
|
|
27043
|
+
}
|
|
27044
|
+
const polled = await pollBackendSubmitTx({
|
|
27045
|
+
attempt,
|
|
27046
|
+
terminalStatus,
|
|
27047
|
+
getStatus: (override) => api.getSubmitTxStatus(statusQuery, override),
|
|
27048
|
+
onExecuted,
|
|
27049
|
+
// While this ceiling is the smaller bound the poll retries within the attempt; once the attempt's
|
|
27050
|
+
// remainder falls below it, one stalled request can spend the rest.
|
|
27051
|
+
requestTimeoutMs: serviceTimeoutMs
|
|
27052
|
+
});
|
|
27053
|
+
return polled.ok ? { ok: true, value: polled.value } : { ok: false, cause: polled.cause };
|
|
27054
|
+
}
|
|
26977
27055
|
function decodePacketIntentTarget(payload) {
|
|
26978
27056
|
try {
|
|
26979
27057
|
const hex = payload.startsWith("0x") ? payload.slice(2) : payload;
|
|
@@ -27024,20 +27102,33 @@ var SwapService = class {
|
|
|
27024
27102
|
spoke;
|
|
27025
27103
|
// swap config
|
|
27026
27104
|
solver;
|
|
27027
|
-
partnerFee;
|
|
27028
27105
|
relayerApiEndpoint;
|
|
27029
|
-
// backend swaps-API client
|
|
27106
|
+
// backend swaps-API client
|
|
27030
27107
|
backendApi;
|
|
27031
|
-
|
|
27032
|
-
|
|
27108
|
+
/**
|
|
27109
|
+
* Effective 2-step submit-tx flow (`swaps.useBackendSubmitTx`, default on). Read live off
|
|
27110
|
+
* `ConfigService`, like {@link SwapService.partnerFee}, so the config object and the behavior can
|
|
27111
|
+
* never disagree.
|
|
27112
|
+
*/
|
|
27113
|
+
get useBackendSubmitTx() {
|
|
27114
|
+
return this.config.swapUseBackendSubmitTx;
|
|
27115
|
+
}
|
|
27116
|
+
/**
|
|
27117
|
+
* Effective swap partner fee (`swaps.partnerFee`, else the global `fee`). Read live off
|
|
27118
|
+
* `ConfigService` rather than snapshotted in the constructor, so it cannot diverge from
|
|
27119
|
+
* `config.swapPartnerFee` if the config object is ever replaced (see `ConfigService.initialize`).
|
|
27120
|
+
* `BridgeService` and `LeverageYieldService` resolve their fees the same way.
|
|
27121
|
+
*/
|
|
27122
|
+
get partnerFee() {
|
|
27123
|
+
return this.config.swapPartnerFee;
|
|
27124
|
+
}
|
|
27125
|
+
constructor({ config, hubProvider, spoke, backendApi }) {
|
|
27033
27126
|
this.solver = config.solver;
|
|
27034
|
-
this.partnerFee = config.swapPartnerFee;
|
|
27035
27127
|
this.relayerApiEndpoint = config.relay.relayerApiEndpoint;
|
|
27036
27128
|
this.config = config;
|
|
27037
27129
|
this.hubProvider = hubProvider;
|
|
27038
27130
|
this.spoke = spoke;
|
|
27039
27131
|
this.backendApi = backendApi;
|
|
27040
|
-
this.useBackendSubmitTx = useBackendSubmitTx ?? false;
|
|
27041
27132
|
}
|
|
27042
27133
|
/**
|
|
27043
27134
|
* Estimates the gas cost for a raw (unsigned) transaction on a spoke chain.
|
|
@@ -27182,21 +27273,26 @@ var SwapService = class {
|
|
|
27182
27273
|
* Executes a full end-to-end cross-chain swap.
|
|
27183
27274
|
*
|
|
27184
27275
|
* Orchestrates the complete swap lifecycle. `createIntent` first submits the intent transaction on
|
|
27185
|
-
* the source spoke chain; completion then runs via one of two paths,
|
|
27186
|
-
*
|
|
27187
|
-
*
|
|
27188
|
-
* - **Client-side (
|
|
27189
|
-
* relays it to the hub (Sonic) and waits for the packet — skipped when
|
|
27190
|
-
* where the spoke tx already is the hub tx — then calls `postExecution` to
|
|
27191
|
-
* triggering it to fill the intent.
|
|
27192
|
-
* - **Backend 2-step (
|
|
27276
|
+
* the source spoke chain; completion then runs via one of two paths, each bounded by its own `timeout`
|
|
27277
|
+
* budget:
|
|
27278
|
+
*
|
|
27279
|
+
* - **Client-side (opt-out via `swaps.useBackendSubmitTx: false`), {@link fallbackSwapSteps}:** verifies
|
|
27280
|
+
* the spoke tx landed on-chain, relays it to the hub (Sonic) and waits for the packet — skipped when
|
|
27281
|
+
* `srcChainKey` is the hub, where the spoke tx already is the hub tx — then calls `postExecution` to
|
|
27282
|
+
* notify the solver, triggering it to fill the intent.
|
|
27283
|
+
* - **Backend 2-step (default via `swaps.useBackendSubmitTx`), {@link submitTx}:** hands the
|
|
27193
27284
|
* broadcast tx to the swaps API, which verifies, relays and post-executes server-side, then polls
|
|
27194
27285
|
* for completion. On ANY non-success it transparently falls back to the client-side path above —
|
|
27195
27286
|
* safe because re-relaying / re-posting an already-processed swap is idempotent (no double-fill).
|
|
27196
27287
|
*
|
|
27197
27288
|
* @param _params - Swap action params including intent parameters, wallet provider, and an optional
|
|
27198
|
-
* `timeout` —
|
|
27199
|
-
*
|
|
27289
|
+
* `timeout` — a PER-ATTEMPT budget, not an end-to-end one. The backend attempt (submit POST + status
|
|
27290
|
+
* poll) gets it, and if that attempt does not complete the client-side relay wait gets a fresh one
|
|
27291
|
+
* starting after verification, so neither a stalled backend nor a slow source-chain confirmation can
|
|
27292
|
+
* shorten it. Worst-case wall-clock is `createIntent + timeout + verification +
|
|
27293
|
+
* max(timeout, RELAY_FALLBACK_FLOOR_MS) + postExecution`, where verification is bounded by the source
|
|
27294
|
+
* chain's `pollingConfig.maxTimeoutMs` and the first and last terms are not bounded by `timeout` at
|
|
27295
|
+
* all. See `docs/SWAPS.md` § How `timeout` bounds each attempt.
|
|
27200
27296
|
* @returns A `Result<SwapResponse, SwapError>`. On success:
|
|
27201
27297
|
* - `solverExecutionResponse` — solver acknowledgement (`{ answer: 'OK', intent_hash }`).
|
|
27202
27298
|
* - `intent` — the on-chain intent object that was created.
|
|
@@ -27230,9 +27326,9 @@ var SwapService = class {
|
|
|
27230
27326
|
return { ok: false, error: createIntentResult.error };
|
|
27231
27327
|
}
|
|
27232
27328
|
const created = createIntentResult.value;
|
|
27233
|
-
const
|
|
27329
|
+
const timeoutMs = resolveTimeoutMs(_params.timeout, DEFAULT_RELAY_TX_TIMEOUT);
|
|
27234
27330
|
if (this.useBackendSubmitTx) {
|
|
27235
|
-
const submitted = await this.submitTx(_params, created,
|
|
27331
|
+
const submitted = await this.submitTx(_params, created, createSubmitTxAttempt(timeoutMs));
|
|
27236
27332
|
if (submitted.ok) return submitted;
|
|
27237
27333
|
this.config.logger.warn(
|
|
27238
27334
|
"[swap] backend submit-tx did not complete; falling back to the client-side relay",
|
|
@@ -27241,7 +27337,7 @@ var SwapService = class {
|
|
|
27241
27337
|
}
|
|
27242
27338
|
);
|
|
27243
27339
|
}
|
|
27244
|
-
return this.fallbackSwapSteps(_params, created,
|
|
27340
|
+
return this.fallbackSwapSteps(_params, created, timeoutMs);
|
|
27245
27341
|
} catch (error) {
|
|
27246
27342
|
if (isSwapError(error)) return { ok: false, error };
|
|
27247
27343
|
return {
|
|
@@ -27268,12 +27364,16 @@ var SwapService = class {
|
|
|
27268
27364
|
);
|
|
27269
27365
|
}
|
|
27270
27366
|
/**
|
|
27271
|
-
* Client-side swap completion (
|
|
27272
|
-
* use it directly when the source IS the hub — then notify the
|
|
27273
|
-
* build the {@link SwapResponse}. Extracted verbatim from `swap()` so the
|
|
27274
|
-
* path ({@link submitTx}) can fall back to it on any non-success.
|
|
27367
|
+
* Client-side swap completion (opt-out via `swaps.useBackendSubmitTx: false`): verify the broadcast intent
|
|
27368
|
+
* tx landed, then relay it to the hub — or use it directly when the source IS the hub — then notify the
|
|
27369
|
+
* solver via post-execution and build the {@link SwapResponse}. Extracted verbatim from `swap()` so the
|
|
27370
|
+
* backend 2-step path ({@link submitTx}) can fall back to it on any non-success.
|
|
27371
|
+
*
|
|
27372
|
+
* Verification belongs to THIS path only: the backend runs its own, so verifying before handing over
|
|
27373
|
+
* would delay every backend success by the source chain's confirmation wait and could fail a swap the
|
|
27374
|
+
* backend would have completed.
|
|
27275
27375
|
*/
|
|
27276
|
-
async fallbackSwapSteps(_params, created,
|
|
27376
|
+
async fallbackSwapSteps(_params, created, timeoutMs) {
|
|
27277
27377
|
const { params } = _params;
|
|
27278
27378
|
const srcChainKey = params.srcChainKey;
|
|
27279
27379
|
const baseCtx = { srcChainKey, dstChainKey: params.dstChainKey };
|
|
@@ -27294,9 +27394,12 @@ var SwapService = class {
|
|
|
27294
27394
|
data: relayData,
|
|
27295
27395
|
chainKey: srcChainKey,
|
|
27296
27396
|
relayerApiEndpoint: this.relayerApiEndpoint,
|
|
27297
|
-
//
|
|
27298
|
-
//
|
|
27299
|
-
|
|
27397
|
+
// The caller's full `timeout`, starting HERE — after verification, and whether this runs as the
|
|
27398
|
+
// only path or as the backend's fallback. Neither a stalled backend attempt nor a slow source-chain
|
|
27399
|
+
// confirmation may shorten the relay wait. The floor covers a sub-floor caller `timeout`:
|
|
27400
|
+
// `relayTxAndWaitPacket` SUBMITS before `timeout` bounds anything, so a zero budget would strand an
|
|
27401
|
+
// already-landed tx unrelayed. Re-relay is idempotent, so spending it is safe.
|
|
27402
|
+
timeout: Math.max(timeoutMs, RELAY_FALLBACK_FLOOR_MS)
|
|
27300
27403
|
});
|
|
27301
27404
|
if (!packet.ok) {
|
|
27302
27405
|
return { ok: false, error: mapRelayFailure(packet.error, { feature: "swap", action: "swap", ...baseCtx }) };
|
|
@@ -27326,7 +27429,7 @@ var SwapService = class {
|
|
|
27326
27429
|
};
|
|
27327
27430
|
}
|
|
27328
27431
|
/**
|
|
27329
|
-
* Backend 2-step swap path (
|
|
27432
|
+
* Backend 2-step swap path (default via `swaps.useBackendSubmitTx`): hand the broadcast
|
|
27330
27433
|
* intent tx to the swaps API (`POST /swaps/submit-tx`); the backend relays + post-executes
|
|
27331
27434
|
* server-side. Polls `getSubmitTxStatus` until `solved`, then reconstructs the same
|
|
27332
27435
|
* {@link SwapResponse} the client-side path returns (`result.dstIntentTxHash` → delivery info,
|
|
@@ -27337,32 +27440,36 @@ var SwapService = class {
|
|
|
27337
27440
|
*
|
|
27338
27441
|
* Falling back is safe: re-relaying / re-posting an already-processed swap is idempotent — the
|
|
27339
27442
|
* relay dedups and returns the existing `executed` packet, and the solver re-affirms the intent
|
|
27340
|
-
* (no double-fill). Verified live by `e2e-tests/e2e-relay.test.ts`.
|
|
27341
|
-
*
|
|
27443
|
+
* (no double-fill). Verified live by `e2e-tests/e2e-relay.test.ts`. It is also load-bearing rather
|
|
27444
|
+
* than belt-and-braces: the backend keeps processing after this attempt gives up, so the fallback's
|
|
27445
|
+
* relay can race the backend's own.
|
|
27446
|
+
*
|
|
27447
|
+
* The attempt itself — POST, budget clamps, status poll — is {@link runBackendSubmitTx}, shared with
|
|
27448
|
+
* bridge. What is swap-specific and lives here: the request body, the `solved` terminal status, the
|
|
27449
|
+
* mapping from a terminal result to a {@link SwapResponse}, and the swap error taxonomy.
|
|
27450
|
+
*
|
|
27451
|
+
* `attempt` bounds this attempt alone — the POST and every status request draw on it, and the
|
|
27452
|
+
* client-side fallback holds a separate fresh `timeout`.
|
|
27342
27453
|
*/
|
|
27343
|
-
async submitTx(_params, created,
|
|
27454
|
+
async submitTx(_params, created, attempt) {
|
|
27344
27455
|
const { params } = _params;
|
|
27345
27456
|
const srcChainKey = params.srcChainKey;
|
|
27346
27457
|
const baseCtx = { srcChainKey, dstChainKey: params.dstChainKey };
|
|
27347
27458
|
const { tx: spokeTxHash, intent, relayData } = created;
|
|
27348
|
-
const submitTxFailed = (cause) => ({
|
|
27349
|
-
ok: false,
|
|
27350
|
-
error: executionFailed("swap", cause, { ...baseCtx, action: "swap" })
|
|
27351
|
-
});
|
|
27352
27459
|
try {
|
|
27353
|
-
const
|
|
27354
|
-
|
|
27355
|
-
|
|
27356
|
-
|
|
27357
|
-
|
|
27358
|
-
|
|
27359
|
-
|
|
27360
|
-
|
|
27361
|
-
|
|
27362
|
-
|
|
27460
|
+
const outcome = await runBackendSubmitTx({
|
|
27461
|
+
attempt,
|
|
27462
|
+
api: this.backendApi.swaps,
|
|
27463
|
+
body: {
|
|
27464
|
+
txHash: spokeTxHash,
|
|
27465
|
+
srcChainKey,
|
|
27466
|
+
walletAddress: params.srcAddress,
|
|
27467
|
+
intent,
|
|
27468
|
+
relayData: relayData.payload
|
|
27469
|
+
},
|
|
27470
|
+
statusQuery: { txHash: spokeTxHash, srcChainKey },
|
|
27363
27471
|
// Swaps terminal success is `solved` (solver filled) — not the bridge `executed`.
|
|
27364
27472
|
terminalStatus: "solved",
|
|
27365
|
-
getStatus: () => this.backendApi.swaps.getSubmitTxStatus({ txHash: spokeTxHash, srcChainKey }),
|
|
27366
27473
|
onExecuted: (result) => result?.dstIntentTxHash && result.intent_hash ? {
|
|
27367
27474
|
// Backend serializes the hex intent_hash as a plain string; brand it at the boundary.
|
|
27368
27475
|
solverExecutionResponse: { answer: "OK", intent_hash: result.intent_hash },
|
|
@@ -27377,7 +27484,7 @@ var SwapService = class {
|
|
|
27377
27484
|
}
|
|
27378
27485
|
} : void 0
|
|
27379
27486
|
});
|
|
27380
|
-
return
|
|
27487
|
+
return outcome.ok ? { ok: true, value: outcome.value } : { ok: false, error: executionFailed("swap", outcome.cause, { ...baseCtx, action: "swap" }) };
|
|
27381
27488
|
} catch (error) {
|
|
27382
27489
|
return { ok: false, error: unknownFailed("swap", error, { ...baseCtx, action: "swap" }) };
|
|
27383
27490
|
}
|
|
@@ -30226,7 +30333,6 @@ async function makeRequest(params) {
|
|
|
30226
30333
|
body: config.body,
|
|
30227
30334
|
signal: controller.signal
|
|
30228
30335
|
});
|
|
30229
|
-
clearTimeout(timeoutId);
|
|
30230
30336
|
if (!response.ok) {
|
|
30231
30337
|
const errorText = await response.text();
|
|
30232
30338
|
throw new BackendHttpError(response.status, errorText);
|
|
@@ -30234,7 +30340,6 @@ async function makeRequest(params) {
|
|
|
30234
30340
|
const data = await response.json();
|
|
30235
30341
|
return data;
|
|
30236
30342
|
} catch (error) {
|
|
30237
|
-
clearTimeout(timeoutId);
|
|
30238
30343
|
if (error instanceof Error) {
|
|
30239
30344
|
if (error.name === "AbortError") {
|
|
30240
30345
|
throw new Error("REQUEST_TIMEOUT", { cause: new Error(`Request timeout after ${timeout}ms`) });
|
|
@@ -30244,6 +30349,8 @@ async function makeRequest(params) {
|
|
|
30244
30349
|
}
|
|
30245
30350
|
logger.error(`[${serviceLabel}] Unknown error`, error);
|
|
30246
30351
|
throw new Error("UNKNOWN_REQUEST_ERROR", { cause: error });
|
|
30352
|
+
} finally {
|
|
30353
|
+
clearTimeout(timeoutId);
|
|
30247
30354
|
}
|
|
30248
30355
|
}
|
|
30249
30356
|
function resolveRequestConfig(config, defaults) {
|
|
@@ -30448,7 +30555,9 @@ var SwapsApiService = class _SwapsApiService {
|
|
|
30448
30555
|
// ──────────────────────────────────────────────────────────────────────
|
|
30449
30556
|
// Submit-tx state machine
|
|
30450
30557
|
// ──────────────────────────────────────────────────────────────────────
|
|
30451
|
-
/** Submit a swap transaction to be processed (relay, post-execution, etc.). Idempotent on `(txHash, srcChainKey)`.
|
|
30558
|
+
/** Submit a swap transaction to be processed (relay, post-execution, etc.). Idempotent on `(txHash, srcChainKey)`.
|
|
30559
|
+
* Response is immediate after successful submission. Use getSubmitTxStatus to poll the status of the submission.
|
|
30560
|
+
*/
|
|
30452
30561
|
async submitTx(body, config) {
|
|
30453
30562
|
return this.toResult(
|
|
30454
30563
|
"/swaps/submit-tx",
|
|
@@ -30477,6 +30586,18 @@ var SwapsApiService = class _SwapsApiService {
|
|
|
30477
30586
|
getBaseURL() {
|
|
30478
30587
|
return this.config.baseURL;
|
|
30479
30588
|
}
|
|
30589
|
+
/**
|
|
30590
|
+
* Return the effective per-request timeout (ms) — the same value {@link buildClient} resolves, so
|
|
30591
|
+
* `SwapsApiConfig.timeout` being optional never leaks an `undefined` ceiling.
|
|
30592
|
+
*
|
|
30593
|
+
* Callers bounding a request tighter than this need it as the CEILING, because a
|
|
30594
|
+
* `RequestOverrideConfig.timeout` REPLACES the service value rather than lowering it: an override
|
|
30595
|
+
* derived from a caller budget alone would raise the bound whenever that budget is the larger of the
|
|
30596
|
+
* two. `SubmitTxAttempt.requestTimeout` clamps against both (`min(budget left in the attempt, this)`).
|
|
30597
|
+
*/
|
|
30598
|
+
getTimeout() {
|
|
30599
|
+
return this.config.timeout ?? DEFAULT_BACKEND_API_TIMEOUT;
|
|
30600
|
+
}
|
|
30480
30601
|
};
|
|
30481
30602
|
var StellarSponsorConfigSchema = v7__namespace.object({
|
|
30482
30603
|
sponsorAccount: v7__namespace.string(),
|
|
@@ -30963,9 +31084,12 @@ var BridgeApiService = class {
|
|
|
30963
31084
|
return this.config.baseURL;
|
|
30964
31085
|
}
|
|
30965
31086
|
/**
|
|
30966
|
-
* Return the effective per-request timeout (ms).
|
|
30967
|
-
*
|
|
30968
|
-
*
|
|
31087
|
+
* Return the effective per-request timeout (ms).
|
|
31088
|
+
*
|
|
31089
|
+
* Callers bounding a request tighter than this need it as the CEILING, because a
|
|
31090
|
+
* `RequestOverrideConfig.timeout` REPLACES the service value rather than lowering it: an override
|
|
31091
|
+
* derived from a caller budget alone would raise the bound whenever that budget is the larger of the
|
|
31092
|
+
* two. `SubmitTxAttempt.requestTimeout` clamps against both (`min(budget left in the attempt, this)`).
|
|
30969
31093
|
*/
|
|
30970
31094
|
getTimeout() {
|
|
30971
31095
|
return this.config.timeout;
|
|
@@ -31577,15 +31701,20 @@ var BridgeService = class {
|
|
|
31577
31701
|
hubProvider;
|
|
31578
31702
|
config;
|
|
31579
31703
|
spoke;
|
|
31580
|
-
// backend bridge-API client
|
|
31704
|
+
// backend bridge-API client
|
|
31581
31705
|
backendApi;
|
|
31582
|
-
|
|
31583
|
-
|
|
31706
|
+
/**
|
|
31707
|
+
* Effective backend submit-tx flow (`bridge.useBackendSubmitTx`, default on). Read live off
|
|
31708
|
+
* `ConfigService` like `bridgePartnerFee`, so the config object and the behavior can never disagree.
|
|
31709
|
+
*/
|
|
31710
|
+
get useBackendSubmitTx() {
|
|
31711
|
+
return this.config.bridgeUseBackendSubmitTx;
|
|
31712
|
+
}
|
|
31713
|
+
constructor({ hubProvider, config, spoke, backendApi }) {
|
|
31584
31714
|
this.config = config;
|
|
31585
31715
|
this.hubProvider = hubProvider;
|
|
31586
31716
|
this.spoke = spoke;
|
|
31587
31717
|
this.backendApi = backendApi;
|
|
31588
|
-
this.useBackendSubmitTx = useBackendSubmitTx ?? false;
|
|
31589
31718
|
}
|
|
31590
31719
|
/**
|
|
31591
31720
|
* Calculates the partner fee deducted from a given bridge input amount.
|
|
@@ -31750,15 +31879,27 @@ var BridgeService = class {
|
|
|
31750
31879
|
/**
|
|
31751
31880
|
* Executes a full end-to-end bridge transfer: spoke deposit → relay → hub settlement.
|
|
31752
31881
|
*
|
|
31753
|
-
* Internally calls `createBridgeIntent()` to submit the spoke-side deposit transaction,
|
|
31754
|
-
*
|
|
31755
|
-
*
|
|
31882
|
+
* Internally calls `createBridgeIntent()` to submit the spoke-side deposit transaction, then
|
|
31883
|
+
* completes the transfer via one of two paths. Use this method for the typical "fire and wait" UX.
|
|
31884
|
+
*
|
|
31885
|
+
* - **Backend submit-tx (default, `bridge.useBackendSubmitTx`), {@link submitTx}:** hands the deposit
|
|
31886
|
+
* to the bridge API, which relays server-side, and polls until `executed`. On ANY non-success it
|
|
31887
|
+
* falls back to the path below — safe because re-relaying is idempotent.
|
|
31888
|
+
* - **Client-side (opt-out with `useBackendSubmitTx: false`), {@link fallbackBridgeSteps}:** verifies
|
|
31889
|
+
* the deposit landed on-chain, then relays it and waits for the settlement packet. `verifyTxHash`
|
|
31890
|
+
* runs on this path only; the backend runs its own.
|
|
31756
31891
|
*
|
|
31757
31892
|
* For manual relay control (e.g. monitoring or batching), use `createBridgeIntent()` directly
|
|
31758
31893
|
* and handle the relay step yourself.
|
|
31759
31894
|
*
|
|
31760
31895
|
* @param _params - Bridge parameters including source/destination chain keys, token addresses,
|
|
31761
|
-
* amount, recipient address, wallet provider, and optional timeout
|
|
31896
|
+
* amount, recipient address, wallet provider, and an optional `timeout` — a PER-ATTEMPT budget,
|
|
31897
|
+
* not an end-to-end one. The backend attempt gets it, and if that attempt does not complete the
|
|
31898
|
+
* client-side relay wait gets a fresh one starting after verification, so neither a stalled backend
|
|
31899
|
+
* nor a slow source-chain confirmation can shorten it. Worst-case wall-clock is
|
|
31900
|
+
* `createBridgeIntent + timeout + verification + max(timeout, RELAY_FALLBACK_FLOOR_MS)`, where
|
|
31901
|
+
* verification is bounded by the source chain's `pollingConfig.maxTimeoutMs` and intent creation is
|
|
31902
|
+
* not bounded by `timeout` at all. See `docs/BRIDGE.md` § Completion paths and `timeout`.
|
|
31762
31903
|
* @returns `Result<TxHashPair>` — `{ srcChainTxHash, dstChainTxHash }` on success,
|
|
31763
31904
|
* where `srcChainTxHash` is the spoke deposit tx and `dstChainTxHash` is the hub settlement tx.
|
|
31764
31905
|
*
|
|
@@ -31792,16 +31933,16 @@ var BridgeService = class {
|
|
|
31792
31933
|
try {
|
|
31793
31934
|
const created = await this.createBridgeIntent(_params);
|
|
31794
31935
|
if (!created.ok) return { ok: false, error: created.error };
|
|
31795
|
-
const
|
|
31936
|
+
const timeoutMs = resolveTimeoutMs(_params.timeout, DEFAULT_RELAY_TX_TIMEOUT);
|
|
31796
31937
|
if (this.useBackendSubmitTx) {
|
|
31797
|
-
const submitted = await this.submitTx(_params, created.value,
|
|
31938
|
+
const submitted = await this.submitTx(_params, created.value, createSubmitTxAttempt(timeoutMs));
|
|
31798
31939
|
if (submitted.ok) return submitted;
|
|
31799
31940
|
this.config.logger.warn(
|
|
31800
31941
|
"[bridge] backend submit-tx did not complete; falling back to the client-side relay",
|
|
31801
31942
|
{ error: submitted.error }
|
|
31802
31943
|
);
|
|
31803
31944
|
}
|
|
31804
|
-
return this.fallbackBridgeSteps(_params, created.value,
|
|
31945
|
+
return this.fallbackBridgeSteps(_params, created.value, timeoutMs);
|
|
31805
31946
|
} catch (error) {
|
|
31806
31947
|
if (isBridgeOrchestrationError(error)) return { ok: false, error };
|
|
31807
31948
|
return {
|
|
@@ -31829,12 +31970,16 @@ var BridgeService = class {
|
|
|
31829
31970
|
);
|
|
31830
31971
|
}
|
|
31831
31972
|
/**
|
|
31832
|
-
* Client-side bridge completion (
|
|
31833
|
-
* relay it to the hub and wait for the settlement packet. Extracted verbatim from
|
|
31834
|
-
*
|
|
31835
|
-
* always relays — there is no hub-source short-circuit.
|
|
31973
|
+
* Client-side bridge completion (opt-out via `bridge.useBackendSubmitTx: false`): verify the broadcast
|
|
31974
|
+
* spoke-deposit tx, then relay it to the hub and wait for the settlement packet. Extracted verbatim from
|
|
31975
|
+
* `bridge()` so the backend submit-tx path ({@link submitTx}) can fall back to it on any non-success.
|
|
31976
|
+
* Bridge always relays — there is no hub-source short-circuit.
|
|
31977
|
+
*
|
|
31978
|
+
* Verification belongs to THIS path only: the backend runs its own, so verifying before handing over
|
|
31979
|
+
* would delay every backend success by the source chain's confirmation wait and could fail a bridge the
|
|
31980
|
+
* backend would have completed.
|
|
31836
31981
|
*/
|
|
31837
|
-
async fallbackBridgeSteps(_params, created,
|
|
31982
|
+
async fallbackBridgeSteps(_params, created, timeoutMs) {
|
|
31838
31983
|
const { params } = _params;
|
|
31839
31984
|
const baseCtx = { srcChainKey: params.srcChainKey, dstChainKey: params.dstChainKey };
|
|
31840
31985
|
const verifyTxHashResult = await this.spoke.verifyTxHash({
|
|
@@ -31849,13 +31994,13 @@ var BridgeService = class {
|
|
|
31849
31994
|
data: created.relayData,
|
|
31850
31995
|
chainKey: params.srcChainKey,
|
|
31851
31996
|
relayerApiEndpoint: this.config.relay.relayerApiEndpoint,
|
|
31852
|
-
//
|
|
31853
|
-
// or the
|
|
31854
|
-
//
|
|
31855
|
-
//
|
|
31856
|
-
//
|
|
31857
|
-
//
|
|
31858
|
-
timeout: Math.max(
|
|
31997
|
+
// The caller's full `timeout`, starting HERE — after verification, and whether this runs as the only
|
|
31998
|
+
// path or as the backend's fallback. Neither a stalled backend attempt nor a slow source-chain
|
|
31999
|
+
// confirmation (Stacks polls for up to its full 120s `maxTimeoutMs`) may shorten the relay wait. The
|
|
32000
|
+
// floor covers a sub-floor caller `timeout`: `relayTxAndWaitPacket` SUBMITS the tx to the relay
|
|
32001
|
+
// before `timeout` bounds anything, so a zero budget would strand an already-landed deposit
|
|
32002
|
+
// unrelayed. Re-relay is idempotent, so always spending the floor is safe.
|
|
32003
|
+
timeout: Math.max(timeoutMs, RELAY_FALLBACK_FLOOR_MS)
|
|
31859
32004
|
});
|
|
31860
32005
|
if (!packetResult.ok) {
|
|
31861
32006
|
return {
|
|
@@ -31874,7 +32019,7 @@ var BridgeService = class {
|
|
|
31874
32019
|
};
|
|
31875
32020
|
}
|
|
31876
32021
|
/**
|
|
31877
|
-
* Backend bridge path (
|
|
32022
|
+
* Backend bridge path (default via `bridge.useBackendSubmitTx`): hand the broadcast
|
|
31878
32023
|
* spoke-deposit tx to the bridge API (`POST /bridge/submit-tx`) with the FULL `relayData`
|
|
31879
32024
|
* envelope; the backend relays server-side. Polls `getSubmitTxStatus` until `executed`, then
|
|
31880
32025
|
* returns the same {@link TxHashPair} the client-side path returns (`result.dstIntentTxHash` →
|
|
@@ -31883,39 +32028,39 @@ var BridgeService = class {
|
|
|
31883
32028
|
* Never throws — returns `{ ok: false }` on any non-success (submit `!ok`, terminal `failed` /
|
|
31884
32029
|
* abandoned, or poll timeout) so `bridge()` falls back to {@link fallbackBridgeSteps}. Falling back
|
|
31885
32030
|
* is safe: re-relaying an already-relayed bridge tx is idempotent — the relay dedups and returns the
|
|
31886
|
-
* existing `executed` packet.
|
|
31887
|
-
*
|
|
32031
|
+
* existing `executed` packet. It is also load-bearing rather than belt-and-braces: the backend keeps
|
|
32032
|
+
* processing after this attempt gives up, so the fallback's relay can race the backend's own.
|
|
32033
|
+
*
|
|
32034
|
+
* The attempt itself — POST, budget clamps, status poll — is {@link runBackendSubmitTx}, shared with
|
|
32035
|
+
* swaps. What is bridge-specific and lives here: the request body (the FULL `relayData` envelope), the
|
|
32036
|
+
* `executed` terminal status, the mapping to a {@link TxHashPair}, and the bridge error taxonomy.
|
|
32037
|
+
*
|
|
32038
|
+
* `attempt` bounds this attempt alone — the POST and every status request draw on it, and the
|
|
32039
|
+
* client-side fallback holds a separate fresh `timeout`.
|
|
31888
32040
|
*/
|
|
31889
|
-
async submitTx(_params, created,
|
|
32041
|
+
async submitTx(_params, created, attempt) {
|
|
31890
32042
|
const { params } = _params;
|
|
31891
32043
|
const srcChainKey = params.srcChainKey;
|
|
31892
32044
|
const baseCtx = { srcChainKey, dstChainKey: params.dstChainKey };
|
|
31893
32045
|
const { tx: spokeTxHash, relayData } = created;
|
|
31894
|
-
const submitTxFailed = (cause) => ({
|
|
31895
|
-
ok: false,
|
|
31896
|
-
error: executionFailed("bridge", cause, { ...baseCtx, action: "bridge" })
|
|
31897
|
-
});
|
|
31898
32046
|
try {
|
|
31899
|
-
const
|
|
31900
|
-
|
|
31901
|
-
|
|
31902
|
-
|
|
31903
|
-
|
|
31904
|
-
|
|
31905
|
-
|
|
31906
|
-
|
|
31907
|
-
|
|
31908
|
-
|
|
31909
|
-
|
|
32047
|
+
const outcome = await runBackendSubmitTx({
|
|
32048
|
+
attempt,
|
|
32049
|
+
api: this.backendApi.bridge,
|
|
32050
|
+
body: {
|
|
32051
|
+
txHash: spokeTxHash,
|
|
32052
|
+
srcChainKey,
|
|
32053
|
+
walletAddress: params.srcAddress,
|
|
32054
|
+
// Send the FULL { address, payload } envelope — bridge has no intent.creator for the backend
|
|
32055
|
+
// to rebuild the relay address, so dropping it would break split-tx-chain relay.
|
|
32056
|
+
relayData
|
|
32057
|
+
},
|
|
32058
|
+
statusQuery: { txHash: spokeTxHash, srcChainKey },
|
|
31910
32059
|
// Bridge terminal success is `executed` (hub-settled) — not the swaps `solved`.
|
|
31911
32060
|
terminalStatus: "executed",
|
|
31912
|
-
|
|
31913
|
-
onExecuted: (result) => result?.dstIntentTxHash ? { srcChainTxHash: spokeTxHash, dstChainTxHash: result.dstIntentTxHash } : void 0,
|
|
31914
|
-
// Bound each status request by the poll cutoff, never above the service default — so a stalled
|
|
31915
|
-
// request can neither eat the fallback's reserve nor consume the window in one attempt.
|
|
31916
|
-
requestTimeoutMs: this.backendApi.bridge.getTimeout()
|
|
32061
|
+
onExecuted: (result) => result?.dstIntentTxHash ? { srcChainTxHash: spokeTxHash, dstChainTxHash: result.dstIntentTxHash } : void 0
|
|
31917
32062
|
});
|
|
31918
|
-
return
|
|
32063
|
+
return outcome.ok ? { ok: true, value: outcome.value } : { ok: false, error: executionFailed("bridge", outcome.cause, { ...baseCtx, action: "bridge" }) };
|
|
31919
32064
|
} catch (error) {
|
|
31920
32065
|
return { ok: false, error: unknownFailed("bridge", error, { ...baseCtx, action: "bridge" }) };
|
|
31921
32066
|
}
|
|
@@ -38089,15 +38234,25 @@ var MoneyMarketService = class _MoneyMarketService {
|
|
|
38089
38234
|
config;
|
|
38090
38235
|
spoke;
|
|
38091
38236
|
// money market config (hoisted from config for ergonomics, mirrors SwapService)
|
|
38092
|
-
partnerFee;
|
|
38093
38237
|
relayerApiEndpoint;
|
|
38094
38238
|
// sub-service
|
|
38095
38239
|
data;
|
|
38240
|
+
/**
|
|
38241
|
+
* Effective money-market partner fee (`moneyMarket.partnerFee`, else the global `fee`). Read live
|
|
38242
|
+
* off `ConfigService` rather than snapshotted in the constructor, so it cannot diverge from
|
|
38243
|
+
* `config.moneyMarketPartnerFee` if the config object is ever replaced. Mirrors
|
|
38244
|
+
* {@link SwapService.partnerFee}.
|
|
38245
|
+
*
|
|
38246
|
+
* Money market has no per-action override: unlike swap / bridge / leverage-yield, every flow here
|
|
38247
|
+
* charges this configured fee.
|
|
38248
|
+
*/
|
|
38249
|
+
get partnerFee() {
|
|
38250
|
+
return this.config.moneyMarketPartnerFee;
|
|
38251
|
+
}
|
|
38096
38252
|
constructor({ config, hubProvider, spoke }) {
|
|
38097
38253
|
this.config = config;
|
|
38098
38254
|
this.hubProvider = hubProvider;
|
|
38099
38255
|
this.spoke = spoke;
|
|
38100
|
-
this.partnerFee = config.moneyMarketPartnerFee;
|
|
38101
38256
|
this.relayerApiEndpoint = config.relay.relayerApiEndpoint;
|
|
38102
38257
|
this.data = new MoneyMarketDataService({ hubProvider, config });
|
|
38103
38258
|
}
|
|
@@ -40410,6 +40565,68 @@ var LeverageYieldService = class {
|
|
|
40410
40565
|
return { ok: false, error: lookupFailed("leverageYield", "resolveDeadline", error, { srcChainKey }) };
|
|
40411
40566
|
}
|
|
40412
40567
|
}
|
|
40568
|
+
/**
|
|
40569
|
+
* Quotes a vault deposit or withdraw. Vault shares are solver-tradeable, so this is the
|
|
40570
|
+
* generic solver quote with one difference that matters: the fee deducted before quoting is
|
|
40571
|
+
* the effective **leverage-yield** fee, matching what {@link LeverageYieldService.createVaultIntent}
|
|
40572
|
+
* will charge. `sodax.swaps.getQuote` deducts the effective *swap* fee instead, so quoting a
|
|
40573
|
+
* vault flow through it makes the quote and the intent disagree whenever the two feature fees
|
|
40574
|
+
* differ. Quoting a vault flow through the swap service can be made to agree — pass the same fee
|
|
40575
|
+
* explicitly, using a zero fee (`{ address, percentage: 0 }`) where the effective leverage-yield
|
|
40576
|
+
* fee is `undefined`, since an explicit `undefined` there falls back to the swap fee — but this
|
|
40577
|
+
* method resolves it for you and is the canonical way to quote a vault flow.
|
|
40578
|
+
*
|
|
40579
|
+
* Pass the vault address as `token_dst` to quote a deposit, or as `token_src` to quote a
|
|
40580
|
+
* withdraw; subtract your slippage tolerance from `quoted_amount` to get `minOutputAmount`.
|
|
40581
|
+
* When overriding the fee per intent, pass the same `partnerFee` here and to whichever builder
|
|
40582
|
+
* you use ({@link LeverageYieldService.deposit}, {@link LeverageYieldService.withdraw}) or
|
|
40583
|
+
* directly to {@link LeverageYieldService.vaultSwap} — omitting it everywhere is equally safe,
|
|
40584
|
+
* since each side then resolves the same effective leverage-yield fee. Both directions are
|
|
40585
|
+
* charged, so this applies to withdrawals as much as deposits.
|
|
40586
|
+
*
|
|
40587
|
+
* @returns `SolverIntentQuoteResponse` on success. On failure `result.error` is either the
|
|
40588
|
+
* solver's own `SolverErrorResponse` (no path, insufficient liquidity, …) or a SodaxError
|
|
40589
|
+
* with `VALIDATION_FAILED` (bad `amount`, or a partner fee that leaves nothing to quote),
|
|
40590
|
+
* `LOOKUP_FAILED` (unsupported token — the solver payload could not be assembled) or
|
|
40591
|
+
* `UNKNOWN`. Discriminate with `isSodaxError(error)`.
|
|
40592
|
+
*/
|
|
40593
|
+
async getQuote(payload) {
|
|
40594
|
+
const { partnerFee = this.config.leverageYieldPartnerFee, ...request } = payload;
|
|
40595
|
+
const baseCtx = {
|
|
40596
|
+
method: "getQuote",
|
|
40597
|
+
tokenSrcChainKey: request.token_src_blockchain_id,
|
|
40598
|
+
tokenDstChainKey: request.token_dst_blockchain_id
|
|
40599
|
+
};
|
|
40600
|
+
try {
|
|
40601
|
+
leverageYieldInvariant(request.amount > 0n, "amount must be greater than 0", {
|
|
40602
|
+
...baseCtx,
|
|
40603
|
+
field: "amount"
|
|
40604
|
+
});
|
|
40605
|
+
if (isPartnerFeeAmount(partnerFee)) {
|
|
40606
|
+
leverageYieldInvariant(
|
|
40607
|
+
partnerFee.amount < request.amount,
|
|
40608
|
+
`partnerFee amount (${partnerFee.amount}) must be less than the quote amount (${request.amount})`,
|
|
40609
|
+
{ ...baseCtx, field: "partnerFee" }
|
|
40610
|
+
);
|
|
40611
|
+
} else if (isPartnerFeePercentage(partnerFee)) {
|
|
40612
|
+
leverageYieldInvariant(
|
|
40613
|
+
Number.isInteger(partnerFee.percentage) && partnerFee.percentage >= 0 && partnerFee.percentage <= Number(FEE_PERCENTAGE_SCALE),
|
|
40614
|
+
`partnerFee percentage must be a whole number of basis points between 0 and ${FEE_PERCENTAGE_SCALE} (got ${partnerFee.percentage})`,
|
|
40615
|
+
{ ...baseCtx, field: "partnerFee" }
|
|
40616
|
+
);
|
|
40617
|
+
}
|
|
40618
|
+
const netAmount = adjustAmountByFee(request.amount, partnerFee, request.quote_type);
|
|
40619
|
+
leverageYieldInvariant(netAmount > 0n, "amount net of the partner fee must be greater than 0", {
|
|
40620
|
+
...baseCtx,
|
|
40621
|
+
field: "partnerFee"
|
|
40622
|
+
});
|
|
40623
|
+
const adjustedPayload = { ...request, amount: netAmount };
|
|
40624
|
+
return await SolverApiService.getQuote(adjustedPayload, this.config.solver, this.config);
|
|
40625
|
+
} catch (error) {
|
|
40626
|
+
if (isLeverageYieldLookupError(error)) return { ok: false, error };
|
|
40627
|
+
return { ok: false, error: lookupFailed("leverageYield", "getQuote", error, baseCtx) };
|
|
40628
|
+
}
|
|
40629
|
+
}
|
|
40413
40630
|
/**
|
|
40414
40631
|
* Builds the {@link LeverageYieldSwapPayload} for a leverage-yield deposit (any token → lsoda*).
|
|
40415
40632
|
* The lsoda* output is delivered to the user's hub wallet on Sonic so a later
|
|
@@ -40417,9 +40634,8 @@ var LeverageYieldService = class {
|
|
|
40417
40634
|
* {@link LeverageYieldService.vaultSwap}: `vaultSwap({ ...payload, walletProvider })`.
|
|
40418
40635
|
* An optional `partnerFee` is forwarded on the payload as the per-intent fee override.
|
|
40419
40636
|
*
|
|
40420
|
-
* For `minOutputAmount`, quote via
|
|
40421
|
-
* destination token (`token_dst`)
|
|
40422
|
-
* quote applies; then subtract your slippage tolerance.
|
|
40637
|
+
* For `minOutputAmount`, quote via {@link LeverageYieldService.getQuote} with the vault
|
|
40638
|
+
* address as the destination token (`token_dst`), then subtract your slippage tolerance.
|
|
40423
40639
|
*/
|
|
40424
40640
|
async deposit(params) {
|
|
40425
40641
|
const baseCtx = { srcChainKey: params.srcChainKey, action: "deposit" };
|
|
@@ -40472,9 +40688,13 @@ var LeverageYieldService = class {
|
|
|
40472
40688
|
* a call shape uniform with {@link LeverageYieldService.deposit}; async because the default
|
|
40473
40689
|
* `deadline` is read from the hub block timestamp.
|
|
40474
40690
|
*
|
|
40475
|
-
*
|
|
40476
|
-
*
|
|
40477
|
-
*
|
|
40691
|
+
* An optional `partnerFee` is forwarded on the payload as the per-intent fee override; omit it
|
|
40692
|
+
* and the configured leverage-yield fee applies. Withdrawals **are** charged — the fee comes out
|
|
40693
|
+
* of `inputAmount`, which for a withdraw is the vault's own shares, so the receiver accrues
|
|
40694
|
+
* lsoda\* rather than the output token.
|
|
40695
|
+
*
|
|
40696
|
+
* For `minOutputAmount`, quote via {@link LeverageYieldService.getQuote} with the vault
|
|
40697
|
+
* address as the source token (`token_src`), then subtract your slippage tolerance.
|
|
40478
40698
|
*/
|
|
40479
40699
|
async withdraw(params) {
|
|
40480
40700
|
const baseCtx = { srcChainKey: params.srcChainKey, action: "withdraw" };
|
|
@@ -40508,7 +40728,10 @@ var LeverageYieldService = class {
|
|
|
40508
40728
|
solver: params.solver ?? ANY_SOLVER_ADDRESS,
|
|
40509
40729
|
data: "0x"
|
|
40510
40730
|
},
|
|
40511
|
-
hubWalletSwap: true
|
|
40731
|
+
hubWalletSwap: true,
|
|
40732
|
+
// Per-intent fee override — only included when the caller supplies one, so the
|
|
40733
|
+
// payload stays free of undefined-valued keys (mirrors `deposit`).
|
|
40734
|
+
...params.partnerFee !== void 0 && { partnerFee: params.partnerFee }
|
|
40512
40735
|
}
|
|
40513
40736
|
};
|
|
40514
40737
|
} catch (error) {
|
|
@@ -40541,7 +40764,7 @@ var LeverageYieldService = class {
|
|
|
40541
40764
|
* `UNKNOWN` (defensive fallback).
|
|
40542
40765
|
*/
|
|
40543
40766
|
async createVaultIntent(_params) {
|
|
40544
|
-
const { params, skipSimulation, hubWalletSwap, partnerFee = this.config.
|
|
40767
|
+
const { params, skipSimulation, hubWalletSwap, partnerFee = this.config.leverageYieldPartnerFee } = _params;
|
|
40545
40768
|
const baseCtx = { srcChainKey: params.srcChainKey, dstChainKey: params.dstChainKey };
|
|
40546
40769
|
try {
|
|
40547
40770
|
leverageYieldInvariant(
|
|
@@ -41771,8 +41994,6 @@ var Sodax = class {
|
|
|
41771
41994
|
const analytics = resolveAnalytics(options?.analytics);
|
|
41772
41995
|
const fee = options?.fee;
|
|
41773
41996
|
const radfiSigner = options?.radfi?.signRequest;
|
|
41774
|
-
const useBackendSubmitTx = options?.swapsOptions?.useBackendSubmitTx ?? false;
|
|
41775
|
-
const bridgeUseBackendSubmitTx = options?.bridgeOptions?.useBackendSubmitTx ?? false;
|
|
41776
41997
|
this.instanceConfig = options ? mergeSodaxConfig(sodaxConfig, options) : sodaxConfig;
|
|
41777
41998
|
this.backendApi = new BackendApiService(this.instanceConfig.api, logger);
|
|
41778
41999
|
this.api = this.backendApi;
|
|
@@ -41791,8 +42012,7 @@ var Sodax = class {
|
|
|
41791
42012
|
config: this.config,
|
|
41792
42013
|
hubProvider: this.hubProvider,
|
|
41793
42014
|
spoke: this.spoke,
|
|
41794
|
-
backendApi: this.backendApi
|
|
41795
|
-
useBackendSubmitTx
|
|
42015
|
+
backendApi: this.backendApi
|
|
41796
42016
|
});
|
|
41797
42017
|
this.moneyMarket = new MoneyMarketService({
|
|
41798
42018
|
config: this.config,
|
|
@@ -41813,8 +42033,7 @@ var Sodax = class {
|
|
|
41813
42033
|
hubProvider: this.hubProvider,
|
|
41814
42034
|
config: this.config,
|
|
41815
42035
|
spoke: this.spoke,
|
|
41816
|
-
backendApi: this.backendApi
|
|
41817
|
-
useBackendSubmitTx: bridgeUseBackendSubmitTx
|
|
42036
|
+
backendApi: this.backendApi
|
|
41818
42037
|
});
|
|
41819
42038
|
this.staking = new StakingService({ hubProvider: this.hubProvider, config: this.config, spoke: this.spoke });
|
|
41820
42039
|
this.partners = new PartnerService({
|