@gala-chain/gswap-sdk 2.0.0-rc.2 → 2.0.0-rc.3
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/README.md +1 -1
- package/dist/browser/classes/gswap.js.map +1 -1
- package/dist/browser/utils/validation.js +1 -1
- package/dist/browser/utils/validation.js.map +1 -1
- package/dist/index.cjs +13 -7
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +15 -9
- package/dist/index.d.ts +15 -9
- package/dist/index.mjs +13 -7
- package/dist/index.mjs.map +1 -1
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -11,7 +11,7 @@ Gateway. Swap requests are queued for later application.
|
|
|
11
11
|
npm install @gala-chain/gswap-sdk@next @gala-chain/gala-core-sdk@next
|
|
12
12
|
```
|
|
13
13
|
|
|
14
|
-
`@gala-chain/gala-core-sdk` is a peer dependency (range `>=1.0.0-rc.
|
|
14
|
+
`@gala-chain/gala-core-sdk` is a peer dependency (range `>=1.0.0-rc.7 <2`):
|
|
15
15
|
install it next to the SDK. 2.0 is a release candidate under the `next`
|
|
16
16
|
dist-tag; `latest` is still 1.2.0, so an install without `@next` gets 1.x.
|
|
17
17
|
Pin exact versions for a wallet or app build.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"gswap.js","names":["_defineProperty","GSwap","environment","GSWAP_ENVIRONMENTS","options","trimTrailingSlash","userRef","httpClient","HttpClient","ChainGateway","lenient","Symbols","resolver","CanonicalSymbols","Quoting","Pools","keyOptions","Positions","Swaps","Assets","Market","Leaderboard","Onramper","DexFees","GdexStreamService","value"],"sources":["../../../src/classes/gswap.ts"],"sourcesContent":["import { Assets } from './assets.js';\nimport { DexFees } from './dex_fees.js';\nimport { ChainGateway } from './gateway.js';\nimport { GdexStreamService } from './gdex_stream.js';\nimport { HttpClient } from './http_client.js';\nimport { Leaderboard } from './leaderboard.js';\nimport { Market } from './market.js';\nimport { Onramper } from './onramper.js';\nimport { Pools } from './pools.js';\nimport { Positions } from './positions.js';\nimport { Quoting } from './quoting.js';\nimport type { GalaChainSigner, HttpRequestor, WireOptions } from '@gala-chain/gala-core-sdk';\nimport { CanonicalSymbols, Symbols } from './symbols.js';\nimport type { InvalidEntryHandler } from '../utils/lenient.js';\nimport { userRef } from '../utils/validation.js';\nimport { Swaps } from './swaps.js';\nimport type { GSwapEnv } from '../types/env.js';\nimport { GSWAP_ENVIRONMENTS } from '../types/env.js';\n\n/** Options for constructing a backend-routed SDK client. */\nexport interface GSwapOptions {\n /** Signs every write. Without one, reads work and any write throws `NO_SIGNER`. */\n signer?: GalaChainSigner | undefined;\n /**\n * The selected account, sent as `X-Wallet-Address` on writes (attribution only; the chain\n * recovers the signer from the signature). Required for shadow writes. Any spelling of an\n * Ethereum account (`eth|<40 hex>` in any casing, `eth|0x...`, `0x...`, bare hex) is sent as\n * `eth|<EIP-55>`, `client|<id>` as written; a mixed-case spelling that is not the checksum is\n * refused at construction (`INVALID_WALLET_ADDRESS`).\n */\n walletAddress?: string | undefined;\n /** `'stage'` or `'prod'` swap backend preset; defaults to `'prod'`. */\n env?: GSwapEnv | undefined;\n /** Overrides the preset's swap backend base URL (a test or private deployment). */\n dexBackendBaseUrl?: string | undefined;\n /** HTTP transport for every request; defaults to the global `fetch`. */\n httpRequestor?: HttpRequestor | undefined;\n /** Request timeout in milliseconds (default 30 000); `Infinity` arms no timer. */\n chainCallTimeoutMs?: number | undefined;\n /** Query encoding and `User-Agent` of the read requests (see {@link WireOptions}). */\n wire?: WireOptions | undefined;\n /**\n * How tokens are turned into trading symbols. `'registry'` (default) reads the symbol registry\n * once (`GET /v2/trade/symbols`, cached) and accepts symbols or class keys. `'canonical'` makes\n * no registry request: the caller passes the backend's canonical trading symbols (from a quote,\n * an estimate or a position), reads send tokens and ticks exactly as given (composite keys\n * included) and the backend orients the pair; see {@link CanonicalSymbols}.\n */\n symbolResolution?: 'registry' | 'canonical' | undefined;\n /**\n * Told about every row of a pool, symbol, position, price, price-series, season or leaderboard\n * answer that was skipped as unusable (see {@link InvalidEntryHandler}); without it such rows are\n * skipped silently.\n */\n onInvalidEntry?: InvalidEntryHandler | undefined;\n /** Realtime stream endpoint. Defaults to the environment's, or is derived from `dexBackendBaseUrl`. */\n dexBackendWsUrl?: string | undefined;\n /** WebSocket constructor for the realtime stream; required on Node.js older than 22. */\n webSocketImpl?: unknown;\n /**\n * `x-api-key` for the privileged stream view; server-side only, and it requires `webSocketImpl`\n * (see `GdexStreamConfig.apiKey`).\n */\n streamApiKey?: string | undefined;\n /**\n * Prefix of every write's `uniqueKey` (`<prefix><uuid>`). Defaults to `galaswap-operation-`,\n * what frontend_v2 and wallet_extension send; defi-backend does not depend on it.\n */\n uniqueKeyPrefix?: string | undefined;\n}\n\n/**\n * Main entry point for the current GalaChainDex SDK: one client bundling the services that read\n * and write through the swap backend (`quoting`, `swaps`, `pools`, `positions`, `assets`,\n * `market`, `leaderboard`, `onramper`, `symbols`, `fees`, `stream`). See {@link GSwapOptions} for\n * configuration.\n */\nexport class GSwap {\n /** The swap backend base URL every request goes to, without a trailing slash. */\n public readonly dexBackendBaseUrl: string;\n /** The request timeout in milliseconds (default 30 000; `Infinity` arms no timer). */\n public readonly chainCallTimeoutMs: number;\n /** The signer given at construction, if any. */\n public readonly signer: GalaChainSigner | undefined;\n /**\n * The account given at construction, if any, in the gateway's spelling (`eth|<EIP-55>`;\n * `client|<id>` as given).\n */\n public readonly walletAddress: string | undefined;\n /** The chain-gateway client every other service reads and writes through. */\n public readonly gateway: ChainGateway;\n /** The trading-symbol registry. */\n public readonly symbols: Symbols;\n /** Read-only exact-input and exact-output quotes. */\n public readonly quoting: Quoting;\n /** Pool, slot0 and composite-pool reads. */\n public readonly pools: Pools;\n /** Position reads, liquidity estimates and liquidity / pool-creation writes. */\n public readonly positions: Positions;\n /** Queued swaps (`RequestTrade`), dark swaps and swap confirmation. */\n public readonly swaps: Swaps;\n /** User token balances. */\n public readonly assets: Assets;\n /** USD prices, price series and the platform volume totals. */\n public readonly market: Market;\n /** Trading-competition seasons and rankings. */\n public readonly leaderboard: Leaderboard;\n /** The Onramper (fiat on-ramp) widget URL. */\n public readonly onramper: Onramper;\n /** Network-fee quotes (DryRun) signed with this client's signer. */\n public readonly fees: DexFees;\n /** The realtime stream endpoint {@link GSwap.stream} connects to. */\n public readonly dexBackendWsUrl: string;\n private readonly webSocketImpl: unknown;\n private readonly streamApiKey: string | undefined;\n private streamClient: GdexStreamService | undefined;\n\n /**\n * Create an SDK client for prod (the default) or stage, or for a `dexBackendBaseUrl` of your own.\n *\n * @example\n * ```typescript\n * const gSwap = new GSwap({ env: 'stage' });\n * const symbols = await gSwap.symbols.list();\n * ```\n */\n constructor(options?: GSwapOptions) {\n const environment = GSWAP_ENVIRONMENTS[options?.env ?? 'prod'];\n this.dexBackendBaseUrl = trimTrailingSlash(\n options?.dexBackendBaseUrl ?? environment.dexBackendBaseUrl,\n );\n this.chainCallTimeoutMs = options?.chainCallTimeoutMs ?? 30_000;\n this.signer = options?.signer;\n this.walletAddress =\n options?.walletAddress === undefined\n ? undefined\n : userRef(options.walletAddress, 'walletAddress');\n\n const httpClient = new HttpClient(\n options?.httpRequestor,\n this.chainCallTimeoutMs,\n options?.wire,\n );\n this.gateway = new ChainGateway({\n dexBackendBaseUrl: this.dexBackendBaseUrl,\n chainCallTimeoutMs: this.chainCallTimeoutMs,\n ...(options?.wire === undefined ? {} : { wire: options.wire }),\n ...(options?.httpRequestor === undefined ? {} : { httpRequestor: options.httpRequestor }),\n ...(this.walletAddress === undefined ? {} : { walletAddress: this.walletAddress }),\n });\n const lenient = { onInvalidEntry: options?.onInvalidEntry };\n this.symbols = new Symbols(this.gateway, lenient);\n // The services resolve tokens through the registry by default; the offline resolver sends the\n // caller's canonical symbols and keys as they are and never reads the registry.\n const resolver =\n options?.symbolResolution === 'canonical' ? new CanonicalSymbols() : this.symbols;\n this.quoting = new Quoting(this.gateway, resolver);\n this.pools = new Pools(this.gateway, resolver, lenient);\n const keyOptions = { uniqueKeyPrefix: options?.uniqueKeyPrefix, ...lenient };\n this.positions = new Positions(\n this.gateway,\n resolver,\n this.signer,\n this.walletAddress,\n keyOptions,\n );\n this.swaps = new Swaps(this.gateway, resolver, this.signer, this.walletAddress, keyOptions);\n this.assets = new Assets(this.dexBackendBaseUrl, httpClient);\n this.market = new Market(this.dexBackendBaseUrl, httpClient, lenient);\n this.leaderboard = new Leaderboard(this.dexBackendBaseUrl, httpClient, lenient);\n this.onramper = new Onramper(this.dexBackendBaseUrl, httpClient);\n this.fees = new DexFees(this.gateway, this.signer);\n this.dexBackendWsUrl =\n options?.dexBackendWsUrl ??\n (options?.dexBackendBaseUrl === undefined\n ? environment.dexBackendWsUrl\n : `${this.dexBackendBaseUrl.replace(/^http/u, 'ws')}/ws`);\n this.webSocketImpl = options?.webSocketImpl;\n this.streamApiKey = options?.streamApiKey;\n }\n\n /**\n * The realtime stream client for this environment (created on first use, not connected until you\n * call `connect()`).\n *\n * @example\n * ```typescript\n * const gSwap = new GSwap({ env: 'stage' });\n * await gSwap.stream.connect();\n * await gSwap.stream.subscribeLiquidity((event) => console.log(event.action, event.amount0));\n * ```\n */\n get stream(): GdexStreamService {\n this.streamClient ??= new GdexStreamService({\n url: this.dexBackendWsUrl,\n ...(this.webSocketImpl === undefined ? {} : { webSocketImpl: this.webSocketImpl }),\n ...(this.streamApiKey === undefined ? {} : { apiKey: this.streamApiKey }),\n });\n return this.streamClient;\n }\n}\n\nfunction trimTrailingSlash(value: string): string {\n return value.replace(/\\/$/u, '');\n}\n"],"mappings":"2uBA6EA,IAAaC,EAAb,KAAmB,CAiDjB,YAAY,EAAwB,CA/CpBD,EAAA,KAAA,oBAAA,IAAA,EAAA,EAEAA,EAAA,KAAA,qBAAA,IAAA,EAAA,EAEAA,EAAA,KAAA,SAAA,IAAA,EAAA,EAKAA,EAAA,KAAA,gBAAA,IAAA,EAAA,EAEAA,EAAA,KAAA,UAAA,IAAA,EAAA,EAEAA,EAAA,KAAA,U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"gswap.js","names":["_defineProperty","GSwap","environment","GSWAP_ENVIRONMENTS","options","trimTrailingSlash","userRef","httpClient","HttpClient","ChainGateway","lenient","Symbols","resolver","CanonicalSymbols","Quoting","Pools","keyOptions","Positions","Swaps","Assets","Market","Leaderboard","Onramper","DexFees","GdexStreamService","value"],"sources":["../../../src/classes/gswap.ts"],"sourcesContent":["import { Assets } from './assets.js';\nimport { DexFees } from './dex_fees.js';\nimport { ChainGateway } from './gateway.js';\nimport { GdexStreamService } from './gdex_stream.js';\nimport { HttpClient } from './http_client.js';\nimport { Leaderboard } from './leaderboard.js';\nimport { Market } from './market.js';\nimport { Onramper } from './onramper.js';\nimport { Pools } from './pools.js';\nimport { Positions } from './positions.js';\nimport { Quoting } from './quoting.js';\nimport type { GalaChainSigner, HttpRequestor, WireOptions } from '@gala-chain/gala-core-sdk';\nimport { CanonicalSymbols, Symbols } from './symbols.js';\nimport type { InvalidEntryHandler } from '../utils/lenient.js';\nimport { userRef } from '../utils/validation.js';\nimport { Swaps } from './swaps.js';\nimport type { GSwapEnv } from '../types/env.js';\nimport { GSWAP_ENVIRONMENTS } from '../types/env.js';\n\n/** Options for constructing a backend-routed SDK client. */\nexport interface GSwapOptions {\n /** Signs every write. Without one, reads work and any write throws `NO_SIGNER`. */\n signer?: GalaChainSigner | undefined;\n /**\n * The selected account, sent as `X-Wallet-Address` on writes (attribution only; the chain\n * recovers the signer from the signature). Required for shadow writes. Any spelling of an\n * Ethereum account (`eth|<40 hex>` in any casing, `0x...`, bare hex) is sent as `eth|<EIP-55>`,\n * `client|<id>` as written; a mixed-case spelling that is not the checksum is refused at\n * construction (`INVALID_WALLET_ADDRESS`), and `eth|0x...` (not an address form) is refused as\n * core's `INVALID_ETH_USER_REF_PREFIX`.\n */\n walletAddress?: string | undefined;\n /** `'stage'` or `'prod'` swap backend preset; defaults to `'prod'`. */\n env?: GSwapEnv | undefined;\n /** Overrides the preset's swap backend base URL (a test or private deployment). */\n dexBackendBaseUrl?: string | undefined;\n /** HTTP transport for every request; defaults to the global `fetch`. */\n httpRequestor?: HttpRequestor | undefined;\n /** Request timeout in milliseconds (default 30 000); `Infinity` arms no timer. */\n chainCallTimeoutMs?: number | undefined;\n /** Query encoding and `User-Agent` of the read requests (see {@link WireOptions}). */\n wire?: WireOptions | undefined;\n /**\n * How tokens are turned into trading symbols. `'registry'` (default) reads the symbol registry\n * once (`GET /v2/trade/symbols`, cached) and accepts symbols or class keys. `'canonical'` makes\n * no registry request: the caller passes the backend's canonical trading symbols (from a quote,\n * an estimate or a position), reads send tokens and ticks exactly as given (composite keys\n * included) and the backend orients the pair; see {@link CanonicalSymbols}.\n */\n symbolResolution?: 'registry' | 'canonical' | undefined;\n /**\n * Told about every row of a pool, symbol, position, price, price-series, season or leaderboard\n * answer that was skipped as unusable (see {@link InvalidEntryHandler}); without it such rows are\n * skipped silently.\n */\n onInvalidEntry?: InvalidEntryHandler | undefined;\n /** Realtime stream endpoint. Defaults to the environment's, or is derived from `dexBackendBaseUrl`. */\n dexBackendWsUrl?: string | undefined;\n /** WebSocket constructor for the realtime stream; required on Node.js older than 22. */\n webSocketImpl?: unknown;\n /**\n * `x-api-key` for the privileged stream view; server-side only, and it requires `webSocketImpl`\n * (see `GdexStreamConfig.apiKey`).\n */\n streamApiKey?: string | undefined;\n /**\n * Prefix of every write's `uniqueKey` (`<prefix><uuid>`). Defaults to `galaswap-operation-`,\n * what frontend_v2 and wallet_extension send; defi-backend does not depend on it.\n */\n uniqueKeyPrefix?: string | undefined;\n}\n\n/**\n * Main entry point for the current GalaChainDex SDK: one client bundling the services that read\n * and write through the swap backend (`quoting`, `swaps`, `pools`, `positions`, `assets`,\n * `market`, `leaderboard`, `onramper`, `symbols`, `fees`, `stream`). See {@link GSwapOptions} for\n * configuration.\n */\nexport class GSwap {\n /** The swap backend base URL every request goes to, without a trailing slash. */\n public readonly dexBackendBaseUrl: string;\n /** The request timeout in milliseconds (default 30 000; `Infinity` arms no timer). */\n public readonly chainCallTimeoutMs: number;\n /** The signer given at construction, if any. */\n public readonly signer: GalaChainSigner | undefined;\n /**\n * The account given at construction, if any, in the gateway's spelling (`eth|<EIP-55>`;\n * `client|<id>` as given).\n */\n public readonly walletAddress: string | undefined;\n /** The chain-gateway client every other service reads and writes through. */\n public readonly gateway: ChainGateway;\n /** The trading-symbol registry. */\n public readonly symbols: Symbols;\n /** Read-only exact-input and exact-output quotes. */\n public readonly quoting: Quoting;\n /** Pool, slot0 and composite-pool reads. */\n public readonly pools: Pools;\n /** Position reads, liquidity estimates and liquidity / pool-creation writes. */\n public readonly positions: Positions;\n /** Queued swaps (`RequestTrade`), dark swaps and swap confirmation. */\n public readonly swaps: Swaps;\n /** User token balances. */\n public readonly assets: Assets;\n /** USD prices, price series and the platform volume totals. */\n public readonly market: Market;\n /** Trading-competition seasons and rankings. */\n public readonly leaderboard: Leaderboard;\n /** The Onramper (fiat on-ramp) widget URL. */\n public readonly onramper: Onramper;\n /** Network-fee quotes (DryRun) signed with this client's signer. */\n public readonly fees: DexFees;\n /** The realtime stream endpoint {@link GSwap.stream} connects to. */\n public readonly dexBackendWsUrl: string;\n private readonly webSocketImpl: unknown;\n private readonly streamApiKey: string | undefined;\n private streamClient: GdexStreamService | undefined;\n\n /**\n * Create an SDK client for prod (the default) or stage, or for a `dexBackendBaseUrl` of your own.\n *\n * @example\n * ```typescript\n * const gSwap = new GSwap({ env: 'stage' });\n * const symbols = await gSwap.symbols.list();\n * ```\n */\n constructor(options?: GSwapOptions) {\n const environment = GSWAP_ENVIRONMENTS[options?.env ?? 'prod'];\n this.dexBackendBaseUrl = trimTrailingSlash(\n options?.dexBackendBaseUrl ?? environment.dexBackendBaseUrl,\n );\n this.chainCallTimeoutMs = options?.chainCallTimeoutMs ?? 30_000;\n this.signer = options?.signer;\n this.walletAddress =\n options?.walletAddress === undefined\n ? undefined\n : userRef(options.walletAddress, 'walletAddress');\n\n const httpClient = new HttpClient(\n options?.httpRequestor,\n this.chainCallTimeoutMs,\n options?.wire,\n );\n this.gateway = new ChainGateway({\n dexBackendBaseUrl: this.dexBackendBaseUrl,\n chainCallTimeoutMs: this.chainCallTimeoutMs,\n ...(options?.wire === undefined ? {} : { wire: options.wire }),\n ...(options?.httpRequestor === undefined ? {} : { httpRequestor: options.httpRequestor }),\n ...(this.walletAddress === undefined ? {} : { walletAddress: this.walletAddress }),\n });\n const lenient = { onInvalidEntry: options?.onInvalidEntry };\n this.symbols = new Symbols(this.gateway, lenient);\n // The services resolve tokens through the registry by default; the offline resolver sends the\n // caller's canonical symbols and keys as they are and never reads the registry.\n const resolver =\n options?.symbolResolution === 'canonical' ? new CanonicalSymbols() : this.symbols;\n this.quoting = new Quoting(this.gateway, resolver);\n this.pools = new Pools(this.gateway, resolver, lenient);\n const keyOptions = { uniqueKeyPrefix: options?.uniqueKeyPrefix, ...lenient };\n this.positions = new Positions(\n this.gateway,\n resolver,\n this.signer,\n this.walletAddress,\n keyOptions,\n );\n this.swaps = new Swaps(this.gateway, resolver, this.signer, this.walletAddress, keyOptions);\n this.assets = new Assets(this.dexBackendBaseUrl, httpClient);\n this.market = new Market(this.dexBackendBaseUrl, httpClient, lenient);\n this.leaderboard = new Leaderboard(this.dexBackendBaseUrl, httpClient, lenient);\n this.onramper = new Onramper(this.dexBackendBaseUrl, httpClient);\n this.fees = new DexFees(this.gateway, this.signer);\n this.dexBackendWsUrl =\n options?.dexBackendWsUrl ??\n (options?.dexBackendBaseUrl === undefined\n ? environment.dexBackendWsUrl\n : `${this.dexBackendBaseUrl.replace(/^http/u, 'ws')}/ws`);\n this.webSocketImpl = options?.webSocketImpl;\n this.streamApiKey = options?.streamApiKey;\n }\n\n /**\n * The realtime stream client for this environment (created on first use, not connected until you\n * call `connect()`).\n *\n * @example\n * ```typescript\n * const gSwap = new GSwap({ env: 'stage' });\n * await gSwap.stream.connect();\n * await gSwap.stream.subscribeLiquidity((event) => console.log(event.action, event.amount0));\n * ```\n */\n get stream(): GdexStreamService {\n this.streamClient ??= new GdexStreamService({\n url: this.dexBackendWsUrl,\n ...(this.webSocketImpl === undefined ? {} : { webSocketImpl: this.webSocketImpl }),\n ...(this.streamApiKey === undefined ? {} : { apiKey: this.streamApiKey }),\n });\n return this.streamClient;\n }\n}\n\nfunction trimTrailingSlash(value: string): string {\n return value.replace(/\\/$/u, '');\n}\n"],"mappings":"2uBA8EA,IAAaC,EAAb,KAAmB,CAiDjB,YAAY,EAAwB,CA/CpBD,EAAA,KAAA,oBAAA,IAAA,EAAA,EAEAA,EAAA,KAAA,qBAAA,IAAA,EAAA,EAEAA,EAAA,KAAA,SAAA,IAAA,EAAA,EAKAA,EAAA,KAAA,gBAAA,IAAA,EAAA,EAEAA,EAAA,KAAA,UAAA,IAAA,EAAA,EAEAA,EAAA,KAAA,UAAA,IAAA,EAAA,EAEAA,EAAA,KAAA,UAAA,IAAA,EAAA,EAEAA,EAAA,KAAA,QAAA,IAAA,EAAA,EAEAA,EAAA,KAAA,YAAA,IAAA,EAAA,EAEAA,EAAA,KAAA,QAAA,IAAA,EAAA,EAEAA,EAAA,KAAA,SAAA,IAAA,EAAA,EAEAA,EAAA,KAAA,SAAA,IAAA,EAAA,EAEAA,EAAA,KAAA,cAAA,IAAA,EAAA,EAEAA,EAAA,KAAA,WAAA,IAAA,EAAA,EAEAA,EAAA,KAAA,OAAA,IAAA,EAAA,EAEAA,EAAA,KAAA,kBAAA,IAAA,EAAA,EACCA,EAAA,KAAA,gBAAA,IAAA,EAAA,EACAA,EAAA,KAAA,eAAA,IAAA,EAAA,EACTA,EAAA,KAAA,eAAA,IAAA,EAAA,EAYN,IAAME,EAAcC,EAAmBC,GAAS,KAAO,QACvD,KAAK,kBAAoBC,EACvBD,GAAS,mBAAqBF,EAAY,iBAC5C,EACA,KAAK,mBAAqBE,GAAS,oBAAsB,IACzD,KAAK,OAASA,GAAS,OACvB,KAAK,cACHA,GAAS,gBAAkB,IAAA,GACvB,IAAA,GACAE,EAAQF,EAAQ,cAAe,eAAe,EAEpD,IAAMG,EAAa,IAAIC,EAC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B,QAAQ,SAAU,IAAI,EAAE,MACxD,KAAK,cAAgBE,GAAS,cAC9B,KAAK,aAAeA,GAAS,YAC/B,CAaA,IAAI,QAA4B,CAM9B,OALA,KAAK,eAAL,KAAK,aAAiB,IAAIoB,EAAkB,CAC1C,IAAK,KAAK,gBACV,GAAI,KAAK,gBAAkB,IAAA,GAAY,CAAC,EAAI,CAAE,cAAe,KAAK,aAAc,EAChF,GAAI,KAAK,eAAiB,IAAA,GAAY,CAAC,EAAI,CAAE,OAAQ,KAAK,YAAa,CACzE,CAAC,GACM,KAAK,YACd,CACF,EAEA,SAASnB,EAAkB,EAAuB,CAChD,OAAOoB,EAAM,QAAQ,OAAQ,EAAE,CACjC"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{ALLOWED_FEE_TIERS_TEXT as e}from"../classes/gswap_error_catalog.js";import{GSwapSDKError as t}from"../classes/gswap_sdk_error.js";import{ALL_FEE_TIERS as n}from"../types/fees.js";import{GC_MAX_TICK as r,GC_MIN_TICK as i}from"./tick_math.js";import{galaChainUserRef as a}from"@gala-chain/gala-core-sdk";import
|
|
1
|
+
import{ALLOWED_FEE_TIERS_TEXT as e}from"../classes/gswap_error_catalog.js";import{GSwapSDKError as t}from"../classes/gswap_sdk_error.js";import{ALL_FEE_TIERS as n}from"../types/fees.js";import{GC_MAX_TICK as r,GC_MIN_TICK as i}from"./tick_math.js";import{galaChainUserRef as a,isGalaError as o}from"@gala-chain/gala-core-sdk";import s from"bignumber.js";function c(e,n,r=!1){if(typeof e==`number`)throw new t(`AMOUNT_IS_JS_NUMBER`,{field:n});let i;try{i=s(e)}catch{i=s(NaN)}if(!i.isFinite())throw new t(`AMOUNT_NOT_FINITE`,{field:n,value:String(e)});if(!r&&i.isZero())throw new t(`AMOUNT_NOT_POSITIVE`,{field:n,value:String(e)});if(i.isNegative())throw new t(`AMOUNT_NEGATIVE`,{field:n,value:String(e)})}function l(e,n,r){if([e,n,r].some(e=>typeof e==`number`))throw new t(`PRICE_VALUES_IS_JS_NUMBER`,{});let i=e=>{try{return s(e)}catch{return s(NaN)}},a=i(e),o=i(n),c=i(r);if(c=c.isFinite()?c:s(0xde0b6b3a7640000),!a.isFinite()||!o.isFinite()||!c.isFinite()||!a.isPositive()||!o.isPositive()||!c.isPositive())throw new t(`INVALID_PRICE_VALUES`,{spotPrice:String(e),lowerPrice:String(n),upperPrice:String(r)});if(o.isGreaterThan(c))throw new t(`INVALID_PRICE_RANGE`,{lowerPrice:String(n),upperPrice:String(r)})}function u(e,n){if(e<0||!Number.isInteger(e))throw new t(`INVALID_TOKEN_DECIMALS`,{field:n,value:e})}function d(e,n){if(!Number.isInteger(e)||!Number.isInteger(n))throw new t(`TICKS_NOT_INTEGERS`,{tickLower:e,tickUpper:n});if(e>=n)throw new t(`INVALID_TICK_RANGE`,{tickLower:e,tickUpper:n});if(e<-887272||n>887272)throw new t(`TICKS_OUT_OF_BOUNDS`,{tickLower:e,tickUpper:n,minTick:i,maxTick:r})}function f(r){if(!n.some(e=>Number(e)===r))throw new t(`INVALID_FEE`,{field:`fee`,value:r,allowed:e})}function p(e){if(!Number.isInteger(e)||e<=0)throw new t(`INVALID_TICK_SPACING`,{value:e})}function m(e,n){try{return a(e,n)}catch(r){throw o(r)&&r.code===`INVALID_ETH_USER_REF_PREFIX`?r:new t(`INVALID_WALLET_ADDRESS`,{field:n,value:String(e)})}}function h(e,n){if(e===void 0)throw new t(`MISSING_WALLET_ADDRESS`,{});return m(e,n)}const g=/* @__PURE__ */ new Set([`Token`,`Unit`,`none`]),_=/^[A-Za-z0-9]+$/u;function v(e){return _.test(e)&&e.length<=32&&!g.has(e)}function y(e,n){if(!(e<n))throw new t(`NON_CANONICAL_PAIR`,{token0:e,token1:n})}export{y as assertCanonicalPair,v as isProposableTradingSymbol,h as requireUserRef,m as userRef,f as validateFee,c as validateNumericAmount,l as validatePriceValues,d as validateTickRange,p as validateTickSpacing,u as validateTokenDecimals};
|
|
2
2
|
//# sourceMappingURL=validation.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"validation.js","names":["BigNumber","validateNumericAmount","amount","GSwapSDKError","parameterName","bnAmount","allowZero","validatePriceValues","spotPrice","lowerPrice","upperPrice","value","parse","bnSpotPrice","bnLowerPrice","bnUpperPrice","validateTokenDecimals","decimals","validateTickRange","tickLower","tickUpper","GC_MIN_TICK","GC_MAX_TICK","validateFee","ALL_FEE_TIERS","tier","fee","ALLOWED_FEE_TIERS_TEXT","validateTickSpacing","tickSpacing","userRef","galaChainUserRef","field","requireUserRef","address","RESERVED_TRADING_SYMBOLS","TRADING_SYMBOL_PATTERN","isProposableTradingSymbol","symbol","assertCanonicalPair","token0","token1"],"sources":["../../../src/utils/validation.ts"],"sourcesContent":["import { galaChainUserRef } from '@gala-chain/gala-core-sdk';\nimport BigNumber from 'bignumber.js';\nimport { ALLOWED_FEE_TIERS_TEXT } from '../classes/gswap_error_catalog.js';\nimport { GSwapSDKError } from '../classes/gswap_sdk_error.js';\nimport type { NumericAmount } from '../types/amounts.js';\nimport { ALL_FEE_TIERS } from '../types/fees.js';\nimport type { FEE_TIER } from '../types/fees.js';\nimport { GC_MAX_TICK, GC_MIN_TICK } from './tick_math.js';\n\n/**\n * Validates a decimal amount: a string or `BigNumber`, never a JavaScript number.\n *\n * @param amount - The amount to check.\n * @param parameterName - The field name reported in the error's `params.field`.\n * @param allowZero - Accept zero (default `false`).\n * @throws GSwapSDKError `AMOUNT_IS_JS_NUMBER`, `AMOUNT_NOT_FINITE`, `AMOUNT_NOT_POSITIVE` (zero\n * when `allowZero` is false) or `AMOUNT_NEGATIVE`.\n */\nexport function validateNumericAmount(\n amount: NumericAmount,\n parameterName: string,\n allowZero = false,\n): void {\n if (typeof amount === 'number') {\n throw new GSwapSDKError('AMOUNT_IS_JS_NUMBER', { field: parameterName });\n }\n // bignumber.js 11+ throws on an unparseable value instead of constructing a NaN\n // instance — substitute an explicit NaN so the isFinite() check below still catches\n // it and raises the same typed error, instead of a raw exception escaping.\n let bnAmount: BigNumber;\n try {\n bnAmount = BigNumber(amount);\n } catch {\n bnAmount = BigNumber(NaN);\n }\n\n if (!bnAmount.isFinite()) {\n throw new GSwapSDKError('AMOUNT_NOT_FINITE', {\n field: parameterName,\n value: String(amount),\n });\n }\n\n if (!allowZero && bnAmount.isZero()) {\n throw new GSwapSDKError('AMOUNT_NOT_POSITIVE', {\n field: parameterName,\n value: String(amount),\n });\n }\n\n if (bnAmount.isNegative()) {\n throw new GSwapSDKError('AMOUNT_NEGATIVE', { field: parameterName, value: String(amount) });\n }\n}\n\n/**\n * Validates a spot price and a lower/upper price range: none a JavaScript number, all positive and\n * finite (a non-finite upper bound counts as an unbounded `1e18`), and `lowerPrice <= upperPrice`.\n *\n * @throws GSwapSDKError `PRICE_VALUES_IS_JS_NUMBER`, `INVALID_PRICE_VALUES` or `INVALID_PRICE_RANGE`.\n */\nexport function validatePriceValues(\n spotPrice: NumericAmount,\n lowerPrice: NumericAmount,\n upperPrice: NumericAmount,\n): void {\n if ([spotPrice, lowerPrice, upperPrice].some((value) => typeof value === 'number')) {\n throw new GSwapSDKError('PRICE_VALUES_IS_JS_NUMBER', {});\n }\n // bignumber.js 11+ throws on an unparseable value instead of constructing a NaN\n // instance — substitute an explicit NaN so the isFinite()/isPositive() checks below\n // still catch it and raise the same typed error, instead of a raw exception escaping.\n const parse = (value: NumericAmount): BigNumber => {\n try {\n return BigNumber(value);\n } catch {\n return BigNumber(NaN);\n }\n };\n const bnSpotPrice = parse(spotPrice);\n const bnLowerPrice = parse(lowerPrice);\n let bnUpperPrice = parse(upperPrice);\n\n bnUpperPrice = bnUpperPrice.isFinite() ? bnUpperPrice : BigNumber(1e18);\n\n if (\n !bnSpotPrice.isFinite() ||\n !bnLowerPrice.isFinite() ||\n !bnUpperPrice.isFinite() ||\n !bnSpotPrice.isPositive() ||\n !bnLowerPrice.isPositive() ||\n !bnUpperPrice.isPositive()\n ) {\n throw new GSwapSDKError('INVALID_PRICE_VALUES', {\n spotPrice: String(spotPrice),\n lowerPrice: String(lowerPrice),\n upperPrice: String(upperPrice),\n });\n }\n\n if (bnLowerPrice.isGreaterThan(bnUpperPrice)) {\n throw new GSwapSDKError('INVALID_PRICE_RANGE', {\n lowerPrice: String(lowerPrice),\n upperPrice: String(upperPrice),\n });\n }\n}\n\n/**\n * Validates a token's decimals: a non-negative integer.\n *\n * @throws GSwapSDKError `INVALID_TOKEN_DECIMALS` (`params.field` is `parameterName`).\n */\nexport function validateTokenDecimals(decimals: number, parameterName: string): void {\n if (decimals < 0 || !Number.isInteger(decimals)) {\n throw new GSwapSDKError('INVALID_TOKEN_DECIMALS', { field: parameterName, value: decimals });\n }\n}\n\n/**\n * Validates a position's tick range: two integers with `tickLower < tickUpper`, both within\n * `GC_MIN_TICK`..`GC_MAX_TICK`. It does not check alignment to a fee tier's spacing (see\n * `assertTickRange`).\n *\n * @throws GSwapSDKError `TICKS_NOT_INTEGERS`, `INVALID_TICK_RANGE` or `TICKS_OUT_OF_BOUNDS`.\n */\nexport function validateTickRange(tickLower: number, tickUpper: number): void {\n if (!Number.isInteger(tickLower) || !Number.isInteger(tickUpper)) {\n throw new GSwapSDKError('TICKS_NOT_INTEGERS', { tickLower, tickUpper });\n }\n\n if (tickLower >= tickUpper) {\n throw new GSwapSDKError('INVALID_TICK_RANGE', { tickLower, tickUpper });\n }\n\n if (tickLower < GC_MIN_TICK || tickUpper > GC_MAX_TICK) {\n throw new GSwapSDKError('TICKS_OUT_OF_BOUNDS', {\n tickLower,\n tickUpper,\n minTick: GC_MIN_TICK,\n maxTick: GC_MAX_TICK,\n });\n }\n}\n\n/**\n * Asserts that `fee` is one of the fee tiers in `ALL_FEE_TIERS` (`0`, `500`, `3000`, `10000`).\n *\n * @throws GSwapSDKError `INVALID_FEE` (`params.field` `'fee'`, `params.allowed` the tiers).\n */\nexport function validateFee(fee: number): asserts fee is FEE_TIER {\n if (!ALL_FEE_TIERS.some((tier) => Number(tier) === fee)) {\n throw new GSwapSDKError('INVALID_FEE', {\n field: 'fee',\n value: fee,\n allowed: ALLOWED_FEE_TIERS_TEXT,\n });\n }\n}\n\n/**\n * Validates a tick spacing: a positive integer.\n *\n * @throws GSwapSDKError `INVALID_TICK_SPACING`.\n */\nexport function validateTickSpacing(tickSpacing: number): void {\n if (!Number.isInteger(tickSpacing) || tickSpacing <= 0) {\n throw new GSwapSDKError('INVALID_TICK_SPACING', { value: tickSpacing });\n }\n}\n\n/**\n * The GalaChain user reference an owner, user or wallet address names, in the one spelling the\n * gateway and the swap backend accept: `eth|<EIP-55 checksummed digits>` for an Ethereum account\n * (given as `eth|<40 hex>` in any casing, `eth|0x<40 hex>`, `0x<40 hex>` or bare hex), `client|<id>`\n * as written. This is `galaChainUserRef` of `@gala-chain/gala-core-sdk`, the one implementation;\n * only the error is this package's. Every place this SDK puts a user identity on the wire goes\n * through it, so what is signed, sent and compared on the backend (`owner === position.owner`,\n * strict) is always the chain's own spelling.\n *\n * @param value - The identity the caller gave.\n * @param field - The field name reported in the error's `params.field`.\n * @throws GSwapSDKError `INVALID_WALLET_ADDRESS` for anything else, a mixed-case spelling whose\n * casing is not the EIP-55 checksum included (a typo); nothing is signed or sent.\n */\nexport function userRef(value: unknown, field: string): string {\n try {\n return galaChainUserRef(value, field);\n } catch {\n throw new GSwapSDKError('INVALID_WALLET_ADDRESS', { field, value: String(value) });\n }\n}\n\n/**\n * {@link userRef} of an address that must be there.\n *\n * @throws GSwapSDKError `MISSING_WALLET_ADDRESS` (undefined) or `INVALID_WALLET_ADDRESS`.\n */\nexport function requireUserRef(address: string | undefined, field: string): string {\n if (address === undefined) {\n throw new GSwapSDKError('MISSING_WALLET_ADDRESS', {});\n }\n return userRef(address, field);\n}\n\n/** Words the chain gateway refuses as a trading symbol. */\nconst RESERVED_TRADING_SYMBOLS = new Set(['Token', 'Unit', 'none']);\nconst TRADING_SYMBOL_PATTERN = /^[A-Za-z0-9]+$/u;\nconst MAX_TRADING_SYMBOL_LENGTH = 32;\n\n/**\n * True when `symbol` is acceptable to propose into the trading-symbol registry: ASCII letters and\n * digits only, 1 to 32 characters, and not a reserved word (`Token`, `Unit`, `none`) — the rules\n * the chain gateway enforces on a CreatePool symbol.\n */\nexport function isProposableTradingSymbol(symbol: string): boolean {\n return (\n TRADING_SYMBOL_PATTERN.test(symbol) &&\n symbol.length <= MAX_TRADING_SYMBOL_LENGTH &&\n !RESERVED_TRADING_SYMBOLS.has(symbol)\n );\n}\n\n/**\n * Asserts that a pair is in the contract's canonical order (`token0 < token1` by plain string\n * comparison), which every write DTO requires. A pair a caller took from a stale quote or\n * position can be reversed; signing it would sign something other than what was priced.\n *\n * @throws GSwapSDKError `NON_CANONICAL_PAIR` (`params.token0`, `params.token1`) otherwise.\n */\nexport function assertCanonicalPair(token0: string, token1: string): void {\n if (!(token0 < token1)) {\n throw new GSwapSDKError('NON_CANONICAL_PAIR', { token0, token1 });\n }\n}\n"],"mappings":"iVAkBA,SAAgBC,EACd,EACA,EACA,EAAY,GACN,CACN,GAAI,OAAOC,GAAW,SACpB,MAAM,IAAIC,EAAc,sBAAuB,CAAE,MAAOC,CAAc,CAAC,EAKzE,IAAIC,EACJ,GAAI,CACF,EAAWL,EAAUE,CAAM,CAC7B,MAAQ,CACN,EAAWF,EAAU,GAAG,CAC1B,CAEA,GAAI,CAACK,EAAS,SAAS,EACrB,MAAM,IAAIF,EAAc,oBAAqB,CAC3C,MAAOC,EACP,MAAO,OAAOF,CAAM,CACtB,CAAC,EAGH,GAAI,CAACI,GAAaD,EAAS,OAAO,EAChC,MAAM,IAAIF,EAAc,sBAAuB,CAC7C,MAAOC,EACP,MAAO,OAAOF,CAAM,CACtB,CAAC,EAGH,GAAIG,EAAS,WAAW,EACtB,MAAM,IAAIF,EAAc,kBAAmB,CAAE,MAAOC,EAAe,MAAO,OAAOF,CAAM,CAAE,CAAC,CAE9F,CAQA,SAAgBK,EACd,EACA,EACA,EACM,CACN,GAAI,CAACC,EAAWC,EAAYC,CAAU,CAAC,CAAC,KAAM,GAA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ACA,YACA,QAASkB,EACT,QAASC,CACX,CAAC,CAEL,CAOA,SAAgBC,EAAY,EAAsC,CAChE,GAAI,CAACC,EAAc,KAAM,GAAS,OAAOC,CAAI,IAAMC,CAAG,EACpD,MAAM,IAAIvB,EAAc,cAAe,CACrC,MAAO,MACP,MAAOuB,EACP,QAASC,CACX,CAAC,CAEL,CAOA,SAAgBC,EAAoB,EAA2B,CAC7D,GAAI,CAAC,OAAO,UAAUC,CAAW,GAAKA,GAAe,EACnD,MAAM,IAAI1B,EAAc,uBAAwB,CAAE,MAAO0B,CAAY,CAAC,CAE1E,CAgBA,SAAgBC,EAAQ,EAAgB,EAAuB,CAC7D,GAAI,CACF,OAAOC,EAAiBpB,EAAOqB,CAAK,CACtC,MAAQ,CACN,MAAM,IAAI7B,EAAc,yBAA0B,CAAE,QAAO,MAAO,OAAOQ,CAAK,CAAE,CAAC,CACnF,CACF,CAOA,SAAgBsB,EAAe,EAA6B,EAAuB,CACjF,GAAIC,IAAY,IAAA,GACd,MAAM,IAAI/B,EAAc,yBAA0B,CAAC,CAAC,EAEtD,OAAO2B,EAAQI,EAASF,CAAK,CAC/B,CAGA,MAAMG,kBAA2B,IAAI,IAAI,CAAC,QAAS,OAAQ,MAAM,CAAC,EAC5DC,EAAyB,kBAQ/B,SAAgBC,EAA0B,EAAyB,CACjE,OACED,EAAuB,KAAKE,CAAM,GAClCA,EAAO,QAAU,IACjB,CAACH,EAAyB,IAAIG,CAAM,CAExC,CASA,SAAgBC,EAAoB,EAAgB,EAAsB,CACxE,GAAI,EAAEC,EAASC,GACb,MAAM,IAAItC,EAAc,qBAAsB,CAAE,SAAQ,QAAO,CAAC,CAEpE"}
|
|
1
|
+
{"version":3,"file":"validation.js","names":["BigNumber","validateNumericAmount","amount","GSwapSDKError","parameterName","bnAmount","allowZero","validatePriceValues","spotPrice","lowerPrice","upperPrice","value","parse","bnSpotPrice","bnLowerPrice","bnUpperPrice","validateTokenDecimals","decimals","validateTickRange","tickLower","tickUpper","GC_MIN_TICK","GC_MAX_TICK","validateFee","ALL_FEE_TIERS","tier","fee","ALLOWED_FEE_TIERS_TEXT","validateTickSpacing","tickSpacing","userRef","galaChainUserRef","field","cause","isGalaError","requireUserRef","address","RESERVED_TRADING_SYMBOLS","TRADING_SYMBOL_PATTERN","isProposableTradingSymbol","symbol","assertCanonicalPair","token0","token1"],"sources":["../../../src/utils/validation.ts"],"sourcesContent":["import { galaChainUserRef, isGalaError } from '@gala-chain/gala-core-sdk';\nimport BigNumber from 'bignumber.js';\nimport { ALLOWED_FEE_TIERS_TEXT } from '../classes/gswap_error_catalog.js';\nimport { GSwapSDKError } from '../classes/gswap_sdk_error.js';\nimport type { NumericAmount } from '../types/amounts.js';\nimport { ALL_FEE_TIERS } from '../types/fees.js';\nimport type { FEE_TIER } from '../types/fees.js';\nimport { GC_MAX_TICK, GC_MIN_TICK } from './tick_math.js';\n\n/**\n * Validates a decimal amount: a string or `BigNumber`, never a JavaScript number.\n *\n * @param amount - The amount to check.\n * @param parameterName - The field name reported in the error's `params.field`.\n * @param allowZero - Accept zero (default `false`).\n * @throws GSwapSDKError `AMOUNT_IS_JS_NUMBER`, `AMOUNT_NOT_FINITE`, `AMOUNT_NOT_POSITIVE` (zero\n * when `allowZero` is false) or `AMOUNT_NEGATIVE`.\n */\nexport function validateNumericAmount(\n amount: NumericAmount,\n parameterName: string,\n allowZero = false,\n): void {\n if (typeof amount === 'number') {\n throw new GSwapSDKError('AMOUNT_IS_JS_NUMBER', { field: parameterName });\n }\n // bignumber.js 11+ throws on an unparseable value instead of constructing a NaN\n // instance — substitute an explicit NaN so the isFinite() check below still catches\n // it and raises the same typed error, instead of a raw exception escaping.\n let bnAmount: BigNumber;\n try {\n bnAmount = BigNumber(amount);\n } catch {\n bnAmount = BigNumber(NaN);\n }\n\n if (!bnAmount.isFinite()) {\n throw new GSwapSDKError('AMOUNT_NOT_FINITE', {\n field: parameterName,\n value: String(amount),\n });\n }\n\n if (!allowZero && bnAmount.isZero()) {\n throw new GSwapSDKError('AMOUNT_NOT_POSITIVE', {\n field: parameterName,\n value: String(amount),\n });\n }\n\n if (bnAmount.isNegative()) {\n throw new GSwapSDKError('AMOUNT_NEGATIVE', { field: parameterName, value: String(amount) });\n }\n}\n\n/**\n * Validates a spot price and a lower/upper price range: none a JavaScript number, all positive and\n * finite (a non-finite upper bound counts as an unbounded `1e18`), and `lowerPrice <= upperPrice`.\n *\n * @throws GSwapSDKError `PRICE_VALUES_IS_JS_NUMBER`, `INVALID_PRICE_VALUES` or `INVALID_PRICE_RANGE`.\n */\nexport function validatePriceValues(\n spotPrice: NumericAmount,\n lowerPrice: NumericAmount,\n upperPrice: NumericAmount,\n): void {\n if ([spotPrice, lowerPrice, upperPrice].some((value) => typeof value === 'number')) {\n throw new GSwapSDKError('PRICE_VALUES_IS_JS_NUMBER', {});\n }\n // bignumber.js 11+ throws on an unparseable value instead of constructing a NaN\n // instance — substitute an explicit NaN so the isFinite()/isPositive() checks below\n // still catch it and raise the same typed error, instead of a raw exception escaping.\n const parse = (value: NumericAmount): BigNumber => {\n try {\n return BigNumber(value);\n } catch {\n return BigNumber(NaN);\n }\n };\n const bnSpotPrice = parse(spotPrice);\n const bnLowerPrice = parse(lowerPrice);\n let bnUpperPrice = parse(upperPrice);\n\n bnUpperPrice = bnUpperPrice.isFinite() ? bnUpperPrice : BigNumber(1e18);\n\n if (\n !bnSpotPrice.isFinite() ||\n !bnLowerPrice.isFinite() ||\n !bnUpperPrice.isFinite() ||\n !bnSpotPrice.isPositive() ||\n !bnLowerPrice.isPositive() ||\n !bnUpperPrice.isPositive()\n ) {\n throw new GSwapSDKError('INVALID_PRICE_VALUES', {\n spotPrice: String(spotPrice),\n lowerPrice: String(lowerPrice),\n upperPrice: String(upperPrice),\n });\n }\n\n if (bnLowerPrice.isGreaterThan(bnUpperPrice)) {\n throw new GSwapSDKError('INVALID_PRICE_RANGE', {\n lowerPrice: String(lowerPrice),\n upperPrice: String(upperPrice),\n });\n }\n}\n\n/**\n * Validates a token's decimals: a non-negative integer.\n *\n * @throws GSwapSDKError `INVALID_TOKEN_DECIMALS` (`params.field` is `parameterName`).\n */\nexport function validateTokenDecimals(decimals: number, parameterName: string): void {\n if (decimals < 0 || !Number.isInteger(decimals)) {\n throw new GSwapSDKError('INVALID_TOKEN_DECIMALS', { field: parameterName, value: decimals });\n }\n}\n\n/**\n * Validates a position's tick range: two integers with `tickLower < tickUpper`, both within\n * `GC_MIN_TICK`..`GC_MAX_TICK`. It does not check alignment to a fee tier's spacing (see\n * `assertTickRange`).\n *\n * @throws GSwapSDKError `TICKS_NOT_INTEGERS`, `INVALID_TICK_RANGE` or `TICKS_OUT_OF_BOUNDS`.\n */\nexport function validateTickRange(tickLower: number, tickUpper: number): void {\n if (!Number.isInteger(tickLower) || !Number.isInteger(tickUpper)) {\n throw new GSwapSDKError('TICKS_NOT_INTEGERS', { tickLower, tickUpper });\n }\n\n if (tickLower >= tickUpper) {\n throw new GSwapSDKError('INVALID_TICK_RANGE', { tickLower, tickUpper });\n }\n\n if (tickLower < GC_MIN_TICK || tickUpper > GC_MAX_TICK) {\n throw new GSwapSDKError('TICKS_OUT_OF_BOUNDS', {\n tickLower,\n tickUpper,\n minTick: GC_MIN_TICK,\n maxTick: GC_MAX_TICK,\n });\n }\n}\n\n/**\n * Asserts that `fee` is one of the fee tiers in `ALL_FEE_TIERS` (`0`, `500`, `3000`, `10000`).\n *\n * @throws GSwapSDKError `INVALID_FEE` (`params.field` `'fee'`, `params.allowed` the tiers).\n */\nexport function validateFee(fee: number): asserts fee is FEE_TIER {\n if (!ALL_FEE_TIERS.some((tier) => Number(tier) === fee)) {\n throw new GSwapSDKError('INVALID_FEE', {\n field: 'fee',\n value: fee,\n allowed: ALLOWED_FEE_TIERS_TEXT,\n });\n }\n}\n\n/**\n * Validates a tick spacing: a positive integer.\n *\n * @throws GSwapSDKError `INVALID_TICK_SPACING`.\n */\nexport function validateTickSpacing(tickSpacing: number): void {\n if (!Number.isInteger(tickSpacing) || tickSpacing <= 0) {\n throw new GSwapSDKError('INVALID_TICK_SPACING', { value: tickSpacing });\n }\n}\n\n/**\n * The GalaChain user reference an owner, user or wallet address names, in the one spelling the\n * gateway and the swap backend accept: `eth|<EIP-55 checksummed digits>` for an Ethereum account\n * (given as `eth|<40 hex>` in any casing, `0x<40 hex>` or bare hex), `client|<id>` as written.\n * `eth|0x<hex>` is not an address form. This is `galaChainUserRef` of\n * `@gala-chain/gala-core-sdk`, the one implementation; only the error for a spelling that is no\n * address at all is this package's. Every place this SDK puts a user identity on the wire goes\n * through it, so what is signed, sent and compared on the backend (`owner === position.owner`,\n * strict) is always the chain's own spelling.\n *\n * @param value - The identity the caller gave.\n * @param field - The field name reported in the error's `params.field`.\n * @throws GalaSDKError core's `INVALID_ETH_USER_REF_PREFIX` (passed through as it is: its message\n * says an `eth|` reference takes the 40 hex digits with no `0x` and names the correct spelling,\n * `params.expected`) for `eth|0x...`; GSwapSDKError `INVALID_WALLET_ADDRESS` for anything else, a\n * mixed-case spelling whose casing is not the EIP-55 checksum included (a typo); nothing is\n * signed or sent.\n */\nexport function userRef(value: unknown, field: string): string {\n try {\n return galaChainUserRef(value, field);\n } catch (cause: unknown) {\n if (isGalaError(cause) && cause.code === 'INVALID_ETH_USER_REF_PREFIX') throw cause;\n throw new GSwapSDKError('INVALID_WALLET_ADDRESS', { field, value: String(value) });\n }\n}\n\n/**\n * {@link userRef} of an address that must be there.\n *\n * @throws GSwapSDKError `MISSING_WALLET_ADDRESS` (undefined) or `INVALID_WALLET_ADDRESS`; core's\n * `INVALID_ETH_USER_REF_PREFIX` for `eth|0x...` (see {@link userRef}).\n */\nexport function requireUserRef(address: string | undefined, field: string): string {\n if (address === undefined) {\n throw new GSwapSDKError('MISSING_WALLET_ADDRESS', {});\n }\n return userRef(address, field);\n}\n\n/** Words the chain gateway refuses as a trading symbol. */\nconst RESERVED_TRADING_SYMBOLS = new Set(['Token', 'Unit', 'none']);\nconst TRADING_SYMBOL_PATTERN = /^[A-Za-z0-9]+$/u;\nconst MAX_TRADING_SYMBOL_LENGTH = 32;\n\n/**\n * True when `symbol` is acceptable to propose into the trading-symbol registry: ASCII letters and\n * digits only, 1 to 32 characters, and not a reserved word (`Token`, `Unit`, `none`) — the rules\n * the chain gateway enforces on a CreatePool symbol.\n */\nexport function isProposableTradingSymbol(symbol: string): boolean {\n return (\n TRADING_SYMBOL_PATTERN.test(symbol) &&\n symbol.length <= MAX_TRADING_SYMBOL_LENGTH &&\n !RESERVED_TRADING_SYMBOLS.has(symbol)\n );\n}\n\n/**\n * Asserts that a pair is in the contract's canonical order (`token0 < token1` by plain string\n * comparison), which every write DTO requires. A pair a caller took from a stale quote or\n * position can be reversed; signing it would sign something other than what was priced.\n *\n * @throws GSwapSDKError `NON_CANONICAL_PAIR` (`params.token0`, `params.token1`) otherwise.\n */\nexport function assertCanonicalPair(token0: string, token1: string): void {\n if (!(token0 < token1)) {\n throw new GSwapSDKError('NON_CANONICAL_PAIR', { token0, token1 });\n }\n}\n"],"mappings":"kWAkBA,SAAgBC,EACd,EACA,EACA,EAAY,GACN,CACN,GAAI,OAAOC,GAAW,SACpB,MAAM,IAAIC,EAAc,sBAAuB,CAAE,MAAOC,CAAc,CAAC,EAKzE,IAAIC,EACJ,GAAI,CACF,EAAWL,EAAUE,CAAM,CAC7B,MAAQ,CACN,EAAWF,EAAU,GAAG,CAC1B,CAEA,GAAI,CAACK,EAAS,SAAS,EACrB,MAAM,IAAIF,EAAc,oBAAqB,CAC3C,MAAOC,EACP,MAAO,OAAOF,CAAM,CACtB,CAAC,EAGH,GAAI,CAACI,GAAaD,EAAS,OAAO,EAChC,MAAM,IAAIF,EAAc,sBAAuB,CAC7C,MAAOC,EACP,MAAO,OAAOF,CAAM,CACtB,CAAC,EAGH,GAAIG,EAAS,WAAW,EACtB,MAAM,IAAIF,EAAc,kBAAmB,CAAE,MAAOC,EAAe,MAAO,OAAOF,CAAM,CAAE,CAAC,CAE9F,CAQA,SAAgBK,EACd,EACA,EACA,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
|
1569
1569
|
/**
|
|
1570
1570
|
* The GalaChain user reference an owner, user or wallet address names, in the one spelling the
|
|
1571
1571
|
* gateway and the swap backend accept: `eth|<EIP-55 checksummed digits>` for an Ethereum account
|
|
1572
|
-
* (given as `eth|<40 hex>` in any casing, `
|
|
1573
|
-
*
|
|
1574
|
-
*
|
|
1572
|
+
* (given as `eth|<40 hex>` in any casing, `0x<40 hex>` or bare hex), `client|<id>` as written.
|
|
1573
|
+
* `eth|0x<hex>` is not an address form. This is `galaChainUserRef` of
|
|
1574
|
+
* `@gala-chain/gala-core-sdk`, the one implementation; only the error for a spelling that is no
|
|
1575
|
+
* address at all is this package's. Every place this SDK puts a user identity on the wire goes
|
|
1575
1576
|
* through it, so what is signed, sent and compared on the backend (`owner === position.owner`,
|
|
1576
1577
|
* strict) is always the chain's own spelling.
|
|
1577
1578
|
*
|
|
1578
1579
|
* @param value - The identity the caller gave.
|
|
1579
1580
|
* @param field - The field name reported in the error's `params.field`.
|
|
1580
|
-
* @throws
|
|
1581
|
-
*
|
|
1581
|
+
* @throws GalaSDKError core's `INVALID_ETH_USER_REF_PREFIX` (passed through as it is: its message
|
|
1582
|
+
* says an `eth|` reference takes the 40 hex digits with no `0x` and names the correct spelling,
|
|
1583
|
+
* `params.expected`) for `eth|0x...`; GSwapSDKError `INVALID_WALLET_ADDRESS` for anything else, a
|
|
1584
|
+
* mixed-case spelling whose casing is not the EIP-55 checksum included (a typo); nothing is
|
|
1585
|
+
* signed or sent.
|
|
1582
1586
|
*/
|
|
1583
1587
|
function userRef(value, field) {
|
|
1584
1588
|
try {
|
|
1585
1589
|
return (0, _gala_chain_gala_core_sdk.galaChainUserRef)(value, field);
|
|
1586
|
-
} catch {
|
|
1590
|
+
} catch (cause) {
|
|
1591
|
+
if ((0, _gala_chain_gala_core_sdk.isGalaError)(cause) && cause.code === "INVALID_ETH_USER_REF_PREFIX") throw cause;
|
|
1587
1592
|
throw new GSwapSDKError("INVALID_WALLET_ADDRESS", {
|
|
1588
1593
|
field,
|
|
1589
1594
|
value: String(value)
|
|
@@ -1593,7 +1598,8 @@ function userRef(value, field) {
|
|
|
1593
1598
|
/**
|
|
1594
1599
|
* {@link userRef} of an address that must be there.
|
|
1595
1600
|
*
|
|
1596
|
-
* @throws GSwapSDKError `MISSING_WALLET_ADDRESS` (undefined) or `INVALID_WALLET_ADDRESS
|
|
1601
|
+
* @throws GSwapSDKError `MISSING_WALLET_ADDRESS` (undefined) or `INVALID_WALLET_ADDRESS`; core's
|
|
1602
|
+
* `INVALID_ETH_USER_REF_PREFIX` for `eth|0x...` (see {@link userRef}).
|
|
1597
1603
|
*/
|
|
1598
1604
|
function requireUserRef(address, field) {
|
|
1599
1605
|
if (address === void 0) throw new GSwapSDKError("MISSING_WALLET_ADDRESS", {});
|