@gala-chain/gswap-sdk 2.1.0-beta.3 → 2.1.0-beta.5
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/browser/classes/dex_fees.js +1 -1
- package/dist/browser/classes/dex_fees.js.map +1 -1
- package/dist/browser/index.js +1 -1
- package/dist/index.cjs +31 -7
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +26 -4
- package/dist/index.d.ts +26 -4
- package/dist/index.mjs +31 -8
- package/dist/index.mjs.map +1 -1
- package/package.json +2 -2
package/dist/index.d.cts
CHANGED
|
@@ -1195,9 +1195,22 @@ export interface DexFeeQuote {
|
|
|
1195
1195
|
}>;
|
|
1196
1196
|
source: 'dry-run' | 'default';
|
|
1197
1197
|
}
|
|
1198
|
+
/**
|
|
1199
|
+
* The backend root a fee quote is built on: `base` without trailing slashes and without a trailing
|
|
1200
|
+
* `/api/v1` (the wallet passes the versioned base, the SDK presets the host root). Idempotent.
|
|
1201
|
+
*
|
|
1202
|
+
* @example
|
|
1203
|
+
* ```typescript
|
|
1204
|
+
* dexBackendRoot('https://swap-backend.stage.defi.ovh.gala.com/api/v1/'); // 'https://swap-backend.stage.defi.ovh.gala.com'
|
|
1205
|
+
* ```
|
|
1206
|
+
*/
|
|
1207
|
+
export declare function dexBackendRoot(base: string): string;
|
|
1198
1208
|
/**
|
|
1199
1209
|
* Reduces an EIP-712 approval `message` to the DTO the chain actually receives: drops the signing
|
|
1200
|
-
* envelope (`signature`, `prefix`, `types`, `domain`)
|
|
1210
|
+
* envelope (`signature`, `prefix`, `types`, `domain`), the `dtoOperation` it was signed to call (a
|
|
1211
|
+
* DryRun runs the DTO inside a wrapper signed for `DryRun`; left inside, the chain refuses it:
|
|
1212
|
+
* "signed to call ...:RequestTrade, but the current operation is ...:DryRun") and transport
|
|
1213
|
+
* metadata (`trace`).
|
|
1201
1214
|
*/
|
|
1202
1215
|
export declare function toChainDto(message: Record<string, unknown>): Record<string, unknown>;
|
|
1203
1216
|
/**
|
|
@@ -1205,12 +1218,18 @@ export declare function toChainDto(message: Record<string, unknown>): Record<str
|
|
|
1205
1218
|
* `{ callerPublicKey, method, dto: <inner DTO object>, uniqueKey, signature }`. The inner DTO
|
|
1206
1219
|
* travels unsigned and as an object; no `signerPublicKey` is sent because the signature already
|
|
1207
1220
|
* recovers it (the gateway rejects it as REDUNDANT_SIGNER_PUBLIC_KEY). The wrapper carries its own
|
|
1208
|
-
* `uniqueKey`, distinct from the DTO's
|
|
1221
|
+
* `uniqueKey`, distinct from the DTO's, and its own `dtoOperation` (`<Contract>:DryRun`); the inner DTO
|
|
1222
|
+
* carries none of the signing envelope or the `dtoOperation` of the call it simulates (see
|
|
1223
|
+
* {@link toChainDto}), whatever the caller passes, so a signed DTO can be handed in as is.
|
|
1209
1224
|
*/
|
|
1210
1225
|
export declare function buildDryRunWrapper(signer: GalaChainSigner, callerPublicKey: string, method: string, dto: Record<string, unknown>, uniqueKeyPrefix?: string, contractPath?: ChainContractPath): Promise<Record<string, unknown>>;
|
|
1211
1226
|
/** The transport and backend a fee quote reads from. */
|
|
1212
1227
|
export interface DexFeesClient {
|
|
1213
|
-
/**
|
|
1228
|
+
/**
|
|
1229
|
+
* Swap backend origin, e.g. `https://dex-backend-prod1.defi.gala.com`. A base that already ends in
|
|
1230
|
+
* `/api/v1` (what the wallet passes) and trailing slashes are accepted: the request goes to the
|
|
1231
|
+
* same URL either way (see {@link dexBackendRoot}).
|
|
1232
|
+
*/
|
|
1214
1233
|
dexBackendBaseUrl: string;
|
|
1215
1234
|
/** Defaults to the global `fetch`. */
|
|
1216
1235
|
httpRequestor?: HttpRequestor | undefined;
|
|
@@ -1263,7 +1282,10 @@ export declare class DexFees {
|
|
|
1263
1282
|
* malformed body): a transport outcome, not a fee. Deciding what to charge when the chain is
|
|
1264
1283
|
* silent is the backend's job (it serves `source: 'default'`), so the client never substitutes
|
|
1265
1284
|
* a fee of its own, with ONE exception that mirrors the wallet: a `dex-contract` quote answered
|
|
1266
|
-
* 403
|
|
1285
|
+
* 403 means the contract has no fee route yet and resolves `{ source: 'default', '0' }`. A 404 is
|
|
1286
|
+
* a wrong path, not "no fee route": it resolves `null`, never a default. The request always goes
|
|
1287
|
+
* to `<root>/api/v1/wallet/connect/galachain/api/{channel}/{contract}/{method}/fee`, whether the
|
|
1288
|
+
* client's base URL is the host root or already ends in `/api/v1`.
|
|
1267
1289
|
* Never throws on transport, so a fee lookup cannot block or break a signing screen.
|
|
1268
1290
|
*
|
|
1269
1291
|
* @throws GSwapSDKError NO_SIGNER when constructed without a signer; `SIGNING_FAILED` or
|
package/dist/index.d.ts
CHANGED
|
@@ -1195,9 +1195,22 @@ export interface DexFeeQuote {
|
|
|
1195
1195
|
}>;
|
|
1196
1196
|
source: 'dry-run' | 'default';
|
|
1197
1197
|
}
|
|
1198
|
+
/**
|
|
1199
|
+
* The backend root a fee quote is built on: `base` without trailing slashes and without a trailing
|
|
1200
|
+
* `/api/v1` (the wallet passes the versioned base, the SDK presets the host root). Idempotent.
|
|
1201
|
+
*
|
|
1202
|
+
* @example
|
|
1203
|
+
* ```typescript
|
|
1204
|
+
* dexBackendRoot('https://swap-backend.stage.defi.ovh.gala.com/api/v1/'); // 'https://swap-backend.stage.defi.ovh.gala.com'
|
|
1205
|
+
* ```
|
|
1206
|
+
*/
|
|
1207
|
+
export declare function dexBackendRoot(base: string): string;
|
|
1198
1208
|
/**
|
|
1199
1209
|
* Reduces an EIP-712 approval `message` to the DTO the chain actually receives: drops the signing
|
|
1200
|
-
* envelope (`signature`, `prefix`, `types`, `domain`)
|
|
1210
|
+
* envelope (`signature`, `prefix`, `types`, `domain`), the `dtoOperation` it was signed to call (a
|
|
1211
|
+
* DryRun runs the DTO inside a wrapper signed for `DryRun`; left inside, the chain refuses it:
|
|
1212
|
+
* "signed to call ...:RequestTrade, but the current operation is ...:DryRun") and transport
|
|
1213
|
+
* metadata (`trace`).
|
|
1201
1214
|
*/
|
|
1202
1215
|
export declare function toChainDto(message: Record<string, unknown>): Record<string, unknown>;
|
|
1203
1216
|
/**
|
|
@@ -1205,12 +1218,18 @@ export declare function toChainDto(message: Record<string, unknown>): Record<str
|
|
|
1205
1218
|
* `{ callerPublicKey, method, dto: <inner DTO object>, uniqueKey, signature }`. The inner DTO
|
|
1206
1219
|
* travels unsigned and as an object; no `signerPublicKey` is sent because the signature already
|
|
1207
1220
|
* recovers it (the gateway rejects it as REDUNDANT_SIGNER_PUBLIC_KEY). The wrapper carries its own
|
|
1208
|
-
* `uniqueKey`, distinct from the DTO's
|
|
1221
|
+
* `uniqueKey`, distinct from the DTO's, and its own `dtoOperation` (`<Contract>:DryRun`); the inner DTO
|
|
1222
|
+
* carries none of the signing envelope or the `dtoOperation` of the call it simulates (see
|
|
1223
|
+
* {@link toChainDto}), whatever the caller passes, so a signed DTO can be handed in as is.
|
|
1209
1224
|
*/
|
|
1210
1225
|
export declare function buildDryRunWrapper(signer: GalaChainSigner, callerPublicKey: string, method: string, dto: Record<string, unknown>, uniqueKeyPrefix?: string, contractPath?: ChainContractPath): Promise<Record<string, unknown>>;
|
|
1211
1226
|
/** The transport and backend a fee quote reads from. */
|
|
1212
1227
|
export interface DexFeesClient {
|
|
1213
|
-
/**
|
|
1228
|
+
/**
|
|
1229
|
+
* Swap backend origin, e.g. `https://dex-backend-prod1.defi.gala.com`. A base that already ends in
|
|
1230
|
+
* `/api/v1` (what the wallet passes) and trailing slashes are accepted: the request goes to the
|
|
1231
|
+
* same URL either way (see {@link dexBackendRoot}).
|
|
1232
|
+
*/
|
|
1214
1233
|
dexBackendBaseUrl: string;
|
|
1215
1234
|
/** Defaults to the global `fetch`. */
|
|
1216
1235
|
httpRequestor?: HttpRequestor | undefined;
|
|
@@ -1263,7 +1282,10 @@ export declare class DexFees {
|
|
|
1263
1282
|
* malformed body): a transport outcome, not a fee. Deciding what to charge when the chain is
|
|
1264
1283
|
* silent is the backend's job (it serves `source: 'default'`), so the client never substitutes
|
|
1265
1284
|
* a fee of its own, with ONE exception that mirrors the wallet: a `dex-contract` quote answered
|
|
1266
|
-
* 403
|
|
1285
|
+
* 403 means the contract has no fee route yet and resolves `{ source: 'default', '0' }`. A 404 is
|
|
1286
|
+
* a wrong path, not "no fee route": it resolves `null`, never a default. The request always goes
|
|
1287
|
+
* to `<root>/api/v1/wallet/connect/galachain/api/{channel}/{contract}/{method}/fee`, whether the
|
|
1288
|
+
* client's base URL is the host root or already ends in `/api/v1`.
|
|
1267
1289
|
* Never throws on transport, so a fee lookup cannot block or break a signing screen.
|
|
1268
1290
|
*
|
|
1269
1291
|
* @throws GSwapSDKError NO_SIGNER when constructed without a signer; `SIGNING_FAILED` or
|
package/dist/index.mjs
CHANGED
|
@@ -1700,9 +1700,26 @@ function isDexFeeMethod(method) {
|
|
|
1700
1700
|
function isCurrentContractDexMessage(message, method) {
|
|
1701
1701
|
return isDexFeeMethod(method) && typeof (message === null || message === void 0 ? void 0 : message["token0"]) === "string" && typeof message["token1"] === "string";
|
|
1702
1702
|
}
|
|
1703
|
+
/** The wallet-connect proxy's fee route, below the backend root (stage, 2026-11-02: only this prefix exists). */
|
|
1704
|
+
const FEE_ROUTE_PREFIX = "/api/v1/wallet/connect/galachain/api";
|
|
1705
|
+
/**
|
|
1706
|
+
* The backend root a fee quote is built on: `base` without trailing slashes and without a trailing
|
|
1707
|
+
* `/api/v1` (the wallet passes the versioned base, the SDK presets the host root). Idempotent.
|
|
1708
|
+
*
|
|
1709
|
+
* @example
|
|
1710
|
+
* ```typescript
|
|
1711
|
+
* dexBackendRoot('https://swap-backend.stage.defi.ovh.gala.com/api/v1/'); // 'https://swap-backend.stage.defi.ovh.gala.com'
|
|
1712
|
+
* ```
|
|
1713
|
+
*/
|
|
1714
|
+
function dexBackendRoot(base) {
|
|
1715
|
+
return base.replace(/(?:\/+|\/api\/v1(?=\/|$))+$/u, "");
|
|
1716
|
+
}
|
|
1703
1717
|
/**
|
|
1704
1718
|
* Reduces an EIP-712 approval `message` to the DTO the chain actually receives: drops the signing
|
|
1705
|
-
* envelope (`signature`, `prefix`, `types`, `domain`)
|
|
1719
|
+
* envelope (`signature`, `prefix`, `types`, `domain`), the `dtoOperation` it was signed to call (a
|
|
1720
|
+
* DryRun runs the DTO inside a wrapper signed for `DryRun`; left inside, the chain refuses it:
|
|
1721
|
+
* "signed to call ...:RequestTrade, but the current operation is ...:DryRun") and transport
|
|
1722
|
+
* metadata (`trace`).
|
|
1706
1723
|
*/
|
|
1707
1724
|
function toChainDto(message) {
|
|
1708
1725
|
const chainDto = { ...message };
|
|
@@ -1711,6 +1728,7 @@ function toChainDto(message) {
|
|
|
1711
1728
|
"prefix",
|
|
1712
1729
|
"types",
|
|
1713
1730
|
"domain",
|
|
1731
|
+
"dtoOperation",
|
|
1714
1732
|
"trace"
|
|
1715
1733
|
]) delete chainDto[field];
|
|
1716
1734
|
return chainDto;
|
|
@@ -1720,13 +1738,15 @@ function toChainDto(message) {
|
|
|
1720
1738
|
* `{ callerPublicKey, method, dto: <inner DTO object>, uniqueKey, signature }`. The inner DTO
|
|
1721
1739
|
* travels unsigned and as an object; no `signerPublicKey` is sent because the signature already
|
|
1722
1740
|
* recovers it (the gateway rejects it as REDUNDANT_SIGNER_PUBLIC_KEY). The wrapper carries its own
|
|
1723
|
-
* `uniqueKey`, distinct from the DTO's
|
|
1741
|
+
* `uniqueKey`, distinct from the DTO's, and its own `dtoOperation` (`<Contract>:DryRun`); the inner DTO
|
|
1742
|
+
* carries none of the signing envelope or the `dtoOperation` of the call it simulates (see
|
|
1743
|
+
* {@link toChainDto}), whatever the caller passes, so a signed DTO can be handed in as is.
|
|
1724
1744
|
*/
|
|
1725
1745
|
function buildDryRunWrapper(signer, callerPublicKey, method, dto, uniqueKeyPrefix = DRY_RUN_UNIQUE_KEY_PREFIX, contractPath = "asset/dexv3-contract") {
|
|
1726
1746
|
return signPreSend(signer, contractPath, DRY_RUN_METHOD, {
|
|
1727
1747
|
callerPublicKey,
|
|
1728
1748
|
method,
|
|
1729
|
-
dto,
|
|
1749
|
+
dto: toChainDto(dto),
|
|
1730
1750
|
uniqueKey: createUniqueKey(uniqueKeyPrefix)
|
|
1731
1751
|
});
|
|
1732
1752
|
}
|
|
@@ -1755,7 +1775,7 @@ var DexFees = class {
|
|
|
1755
1775
|
constructor(client, signer) {
|
|
1756
1776
|
this.signer = signer;
|
|
1757
1777
|
this.requestor = client.httpRequestor ?? fetchRequestor;
|
|
1758
|
-
this.baseUrl = client.dexBackendBaseUrl
|
|
1778
|
+
this.baseUrl = dexBackendRoot(client.dexBackendBaseUrl);
|
|
1759
1779
|
this.requestTimeoutMs = client.requestTimeoutMs ?? 3e4;
|
|
1760
1780
|
this.wire = client.wire;
|
|
1761
1781
|
}
|
|
@@ -1767,7 +1787,10 @@ var DexFees = class {
|
|
|
1767
1787
|
* malformed body): a transport outcome, not a fee. Deciding what to charge when the chain is
|
|
1768
1788
|
* silent is the backend's job (it serves `source: 'default'`), so the client never substitutes
|
|
1769
1789
|
* a fee of its own, with ONE exception that mirrors the wallet: a `dex-contract` quote answered
|
|
1770
|
-
* 403
|
|
1790
|
+
* 403 means the contract has no fee route yet and resolves `{ source: 'default', '0' }`. A 404 is
|
|
1791
|
+
* a wrong path, not "no fee route": it resolves `null`, never a default. The request always goes
|
|
1792
|
+
* to `<root>/api/v1/wallet/connect/galachain/api/{channel}/{contract}/{method}/fee`, whether the
|
|
1793
|
+
* client's base URL is the host root or already ends in `/api/v1`.
|
|
1771
1794
|
* Never throws on transport, so a fee lookup cannot block or break a signing screen.
|
|
1772
1795
|
*
|
|
1773
1796
|
* @throws GSwapSDKError NO_SIGNER when constructed without a signer; `SIGNING_FAILED` or
|
|
@@ -1779,7 +1802,7 @@ var DexFees = class {
|
|
|
1779
1802
|
const channel = options.channel ?? "asset";
|
|
1780
1803
|
const contract = options.contract ?? "dexv3-contract";
|
|
1781
1804
|
const wrapper = await buildDryRunWrapper(this.signer, callerPublicKey, method, toChainDto(message), void 0, `asset/${contract}`);
|
|
1782
|
-
const url = `${this.baseUrl}
|
|
1805
|
+
const url = `${this.baseUrl}${FEE_ROUTE_PREFIX}/${encodeURIComponent(channel)}/${encodeURIComponent(contract)}/${encodeURIComponent(method)}/fee`;
|
|
1783
1806
|
let status;
|
|
1784
1807
|
let ok;
|
|
1785
1808
|
let body;
|
|
@@ -1799,7 +1822,7 @@ var DexFees = class {
|
|
|
1799
1822
|
return null;
|
|
1800
1823
|
}
|
|
1801
1824
|
if (!ok) {
|
|
1802
|
-
if (contract === "dex-contract" &&
|
|
1825
|
+
if (contract === "dex-contract" && status === 403) return {
|
|
1803
1826
|
source: "default",
|
|
1804
1827
|
fees: [{ feeInGala: "0" }]
|
|
1805
1828
|
};
|
|
@@ -6668,5 +6691,5 @@ function classifySubmitEnvelope(envelope) {
|
|
|
6668
6691
|
}
|
|
6669
6692
|
|
|
6670
6693
|
//#endregion
|
|
6671
|
-
export { ALL_FEE_TIERS, AppliedTradeError, Assets, CanonicalSymbols, ChainGateway, DEX_FEE_METHODS, DRY_RUN_METHOD, DRY_RUN_UNIQUE_KEY_PREFIX, DexFees, FEE_TIER, GC_MAX_TICK, GC_MIN_TICK, GSWAP_ENVIRONMENTS, GSWAP_ERROR_CATALOG, GSWAP_ERROR_PHASE_BY_CODE, GSwap, GSwapSDKError, GdexStreamError, GdexStreamService, Leaderboard, MARKET_PRICE_BATCH_LIMIT, MARKET_PRICE_QUERY_BYTES, Market, NOT_QUEUED_FINAL, ONRAMPER_MODES, Onramper, PENDING_SWAPS_STORAGE_KEY, PENDING_SWAP_EXPIRY_MS, PENDING_SWAP_FATES, PENDING_SWAP_PRUNE_REASONS, PRICE_SERIES_TIMEFRAMES, PendingSwapStore, Pools, Positions, Quoting, SHADOW_FAILURE_KINDS, SHADOW_SUBMIT_CODES, SUBMISSION_OUTCOME_UNKNOWN_REASONS, SubmittedTransaction, Swaps, Symbols, TICK_SPACING_BY_FEE, UPDATE_REQUIRED_STATUS, alignTickDown, alignTickDownOrNaN, alignTickUp, alignTickUpOrNaN, assertCanonicalPair, assertCanonicalV2Dto, assertTickRange, buildAddLiquidityDto, buildCollectPositionFeesDto, buildCreatePoolDto, buildDryRunWrapper, buildRemoveLiquidityDto, buildRequestTradeDto, chainErrorKeyOf, classification, classifyFailure, classifyShadowSubmitError, classifyShadowSubmitStatus, classifySubmitEnvelope, confirmAppliedTrade, confirmationStateOf, createOnramper, frameSlot0, getObjectProperty, getStringProperty, gswapErrorTemplates, isConfirmationAborted, isConfirmationTimeout, isCurrentContractDexMessage, isDexFeeMethod, isGSwapError, isGdexLiquidityEvent, isNoMarket, isPreSendError, isProposableTradingSymbol, isRelayableRefusal, isShadowError, isSqrtPriceInRange, isSubmitExecuted, isSubmitQueued, isSubmitRejected, isTickInRange, isUninterpretedAnswer, isUniqueKeyConsumed, isUnprovenAcknowledgement, mayHaveBeenQueued, notSentClassification, orderSymbols, parseTokenClassKey, pendingSwapFateFor, pendingSwapFateOfOutcome, priceBatches, queryTokenOf, rawTokenOf, readOrderedSymbols, readShadowSubmitOutcome, requireUserRef, sqrtPriceToTick, storageAdapterFromChromeStorage, swapRouteFromQuote, tickFromPrice, tickToPrice, tickToSqrtPrice, toChainDto, tradingSymbolOf, userRef, validateFee, validateNumericAmount, validatePriceValues, validateTickRange, validateTickSpacing, validateTokenDecimals, webStorageAdapter };
|
|
6694
|
+
export { ALL_FEE_TIERS, AppliedTradeError, Assets, CanonicalSymbols, ChainGateway, DEX_FEE_METHODS, DRY_RUN_METHOD, DRY_RUN_UNIQUE_KEY_PREFIX, DexFees, FEE_TIER, GC_MAX_TICK, GC_MIN_TICK, GSWAP_ENVIRONMENTS, GSWAP_ERROR_CATALOG, GSWAP_ERROR_PHASE_BY_CODE, GSwap, GSwapSDKError, GdexStreamError, GdexStreamService, Leaderboard, MARKET_PRICE_BATCH_LIMIT, MARKET_PRICE_QUERY_BYTES, Market, NOT_QUEUED_FINAL, ONRAMPER_MODES, Onramper, PENDING_SWAPS_STORAGE_KEY, PENDING_SWAP_EXPIRY_MS, PENDING_SWAP_FATES, PENDING_SWAP_PRUNE_REASONS, PRICE_SERIES_TIMEFRAMES, PendingSwapStore, Pools, Positions, Quoting, SHADOW_FAILURE_KINDS, SHADOW_SUBMIT_CODES, SUBMISSION_OUTCOME_UNKNOWN_REASONS, SubmittedTransaction, Swaps, Symbols, TICK_SPACING_BY_FEE, UPDATE_REQUIRED_STATUS, alignTickDown, alignTickDownOrNaN, alignTickUp, alignTickUpOrNaN, assertCanonicalPair, assertCanonicalV2Dto, assertTickRange, buildAddLiquidityDto, buildCollectPositionFeesDto, buildCreatePoolDto, buildDryRunWrapper, buildRemoveLiquidityDto, buildRequestTradeDto, chainErrorKeyOf, classification, classifyFailure, classifyShadowSubmitError, classifyShadowSubmitStatus, classifySubmitEnvelope, confirmAppliedTrade, confirmationStateOf, createOnramper, dexBackendRoot, frameSlot0, getObjectProperty, getStringProperty, gswapErrorTemplates, isConfirmationAborted, isConfirmationTimeout, isCurrentContractDexMessage, isDexFeeMethod, isGSwapError, isGdexLiquidityEvent, isNoMarket, isPreSendError, isProposableTradingSymbol, isRelayableRefusal, isShadowError, isSqrtPriceInRange, isSubmitExecuted, isSubmitQueued, isSubmitRejected, isTickInRange, isUninterpretedAnswer, isUniqueKeyConsumed, isUnprovenAcknowledgement, mayHaveBeenQueued, notSentClassification, orderSymbols, parseTokenClassKey, pendingSwapFateFor, pendingSwapFateOfOutcome, priceBatches, queryTokenOf, rawTokenOf, readOrderedSymbols, readShadowSubmitOutcome, requireUserRef, sqrtPriceToTick, storageAdapterFromChromeStorage, swapRouteFromQuote, tickFromPrice, tickToPrice, tickToSqrtPrice, toChainDto, tradingSymbolOf, userRef, validateFee, validateNumericAmount, validatePriceValues, validateTickRange, validateTickSpacing, validateTokenDecimals, webStorageAdapter };
|
|
6672
6695
|
//# sourceMappingURL=index.mjs.map
|