@gala-chain/gswap-sdk 1.0.0 → 1.1.0
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 +13 -0
- package/dist/browser/index.js +3 -3
- package/dist/browser/index.js.map +1 -1
- package/dist/index.cjs +444 -9
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +220 -1
- package/dist/index.d.ts +220 -1
- package/dist/index.mjs +442 -10
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.d.cts
CHANGED
|
@@ -374,6 +374,204 @@ export declare class ChainGateway {
|
|
|
374
374
|
get httpRequestor(): HttpRequestor;
|
|
375
375
|
}
|
|
376
376
|
//#endregion
|
|
377
|
+
//#region src/classes/gdex_stream.d.ts
|
|
378
|
+
/** Options for {@link GdexStreamService}. */
|
|
379
|
+
export interface GdexStreamConfig {
|
|
380
|
+
/** Stream endpoint. Defaults to production (`wss://dex-backend-prod1.defi.gala.com/ws`). */
|
|
381
|
+
url?: string | undefined;
|
|
382
|
+
/** Reconnect attempts after an unexpected close. Default 5. */
|
|
383
|
+
reconnectAttempts?: number | undefined;
|
|
384
|
+
/** Delay before the first reconnect attempt; doubles each attempt. Default 2000 ms. */
|
|
385
|
+
reconnectDelayMs?: number | undefined;
|
|
386
|
+
/** How long a request waits for its response. Default 15000 ms. */
|
|
387
|
+
requestTimeoutMs?: number | undefined;
|
|
388
|
+
/**
|
|
389
|
+
* A standards-compatible WebSocket constructor. Required on Node.js older than 22, which has no
|
|
390
|
+
* global `WebSocket` (pass the one from the `ws` package).
|
|
391
|
+
*/
|
|
392
|
+
webSocketImpl?: unknown;
|
|
393
|
+
}
|
|
394
|
+
/** The channels of the realtime stream. */
|
|
395
|
+
export type GdexChannel = 'pool' | 'balance' | 'poolCreated' | 'swap' | 'liquidity' | 'blocks';
|
|
396
|
+
/** A pool named by its two token class keys (pipe form) and fee tier. */
|
|
397
|
+
export interface GdexPoolKey {
|
|
398
|
+
token0ClassKey: string;
|
|
399
|
+
token1ClassKey: string;
|
|
400
|
+
fee: number;
|
|
401
|
+
}
|
|
402
|
+
/** A pool named either by its key or by its hash (`v2:<poolRef>` for a v2 pool). */
|
|
403
|
+
export type GdexPoolSelector = {
|
|
404
|
+
pool: GdexPoolKey;
|
|
405
|
+
} | {
|
|
406
|
+
poolHash: string;
|
|
407
|
+
};
|
|
408
|
+
/** Options common to every subscription. */
|
|
409
|
+
export interface GdexSubscribeOptions {
|
|
410
|
+
/** Send the current state right after the subscribe response. */
|
|
411
|
+
snapshot?: boolean | undefined;
|
|
412
|
+
/** Trim each event to these fields; identity and envelope fields always stay. */
|
|
413
|
+
fields?: string[] | undefined;
|
|
414
|
+
}
|
|
415
|
+
/** Filters for {@link GdexStreamService.subscribeLiquidity}; all optional. */
|
|
416
|
+
export interface GdexLiquidityFilter {
|
|
417
|
+
/** Only this pool, named by its key. */
|
|
418
|
+
pool?: GdexPoolKey | undefined;
|
|
419
|
+
/** Only this pool, named by its hash (`v2:<poolRef>` for a v2 pool). */
|
|
420
|
+
poolHash?: string | undefined;
|
|
421
|
+
/** Only events for this LP wallet (the position's owner). */
|
|
422
|
+
owner?: string | undefined;
|
|
423
|
+
/** Only this transaction. */
|
|
424
|
+
transactionId?: string | undefined;
|
|
425
|
+
/** Contract version filter. */
|
|
426
|
+
version?: 'v1' | 'v2' | 'all' | undefined;
|
|
427
|
+
}
|
|
428
|
+
/** One committed add, remove or collect, as the `liquidity` channel reports it. */
|
|
429
|
+
export interface GdexLiquidityEvent {
|
|
430
|
+
version: 'v1' | 'v2';
|
|
431
|
+
pool: GdexPoolKey;
|
|
432
|
+
poolHash: string;
|
|
433
|
+
transactionId: string;
|
|
434
|
+
/** `add`, `remove` or `collect`. */
|
|
435
|
+
action: 'add' | 'remove' | 'collect';
|
|
436
|
+
/** The position's owner (the LP wallet). */
|
|
437
|
+
owner: string;
|
|
438
|
+
/** v1: the position id. v2: the chain position key `<pool>|<tickLow>|<tickHigh>|<owner>`. */
|
|
439
|
+
positionId?: string;
|
|
440
|
+
tickLower?: number;
|
|
441
|
+
tickUpper?: number;
|
|
442
|
+
/** v2 only: the position's liquidity after the operation; `"0"` means it is closed. */
|
|
443
|
+
liquidityAfter?: string;
|
|
444
|
+
/** Principal moved: deposited by an add, withdrawn by a remove, `"0"` for a collect. */
|
|
445
|
+
amount0: string;
|
|
446
|
+
amount1: string;
|
|
447
|
+
/** Fees paid out. v2: always present (`"0"` for an add). v1: present on a collect only. */
|
|
448
|
+
fees0?: string;
|
|
449
|
+
fees1?: string;
|
|
450
|
+
/** v2 only. */
|
|
451
|
+
token0Symbol?: string;
|
|
452
|
+
token1Symbol?: string;
|
|
453
|
+
blockNumber: number;
|
|
454
|
+
timestamp: string;
|
|
455
|
+
}
|
|
456
|
+
/** Whether a stream payload carries every field of a {@link GdexLiquidityEvent}. */
|
|
457
|
+
export declare function isGdexLiquidityEvent(value: Record<string, unknown>): value is Record<string, unknown> & GdexLiquidityEvent;
|
|
458
|
+
/** A live subscription. */
|
|
459
|
+
export interface GdexSubscription {
|
|
460
|
+
subscriptionId: string;
|
|
461
|
+
unsubscribe(): Promise<void>;
|
|
462
|
+
}
|
|
463
|
+
/** A JSON-RPC error answered by the stream. */
|
|
464
|
+
export declare class GdexStreamError extends Error {
|
|
465
|
+
readonly code: number;
|
|
466
|
+
readonly data?: unknown;
|
|
467
|
+
constructor(code: number, message: string, data?: unknown);
|
|
468
|
+
}
|
|
469
|
+
/**
|
|
470
|
+
* Client for the gSwap realtime stream (gdex WebSocket Protocol v1): JSON-RPC 2.0 over one raw
|
|
471
|
+
* WebSocket, with automatic reconnect and resubscribe.
|
|
472
|
+
*
|
|
473
|
+
* @example
|
|
474
|
+
* ```typescript
|
|
475
|
+
* const stream = new GdexStreamService();
|
|
476
|
+
* await stream.connect();
|
|
477
|
+
* await stream.subscribeLiquidity(event => console.log(event.action, event.owner), {
|
|
478
|
+
* owner: 'client|618ae395c1c653111d3315be',
|
|
479
|
+
* });
|
|
480
|
+
* ```
|
|
481
|
+
*/
|
|
482
|
+
export declare class GdexStreamService {
|
|
483
|
+
private readonly url;
|
|
484
|
+
private readonly requestTimeoutMs;
|
|
485
|
+
private readonly webSocketConstructor;
|
|
486
|
+
private readonly backoff;
|
|
487
|
+
private socket;
|
|
488
|
+
private connectPromise;
|
|
489
|
+
private nextRequestId;
|
|
490
|
+
private readonly pending;
|
|
491
|
+
private readonly subscriptionsByServerId;
|
|
492
|
+
private readonly activeSubscriptions;
|
|
493
|
+
private intentionalClose;
|
|
494
|
+
private reconnecting;
|
|
495
|
+
private reconnectTimer;
|
|
496
|
+
private reconnectDelayResolve;
|
|
497
|
+
constructor(config?: GdexStreamConfig);
|
|
498
|
+
/** Open the connection. Resolves at once when already connected. */
|
|
499
|
+
connect(): Promise<void>;
|
|
500
|
+
/** Close the connection and stop reconnecting. */
|
|
501
|
+
disconnect(): void;
|
|
502
|
+
isConnected(): boolean;
|
|
503
|
+
/** Raw JSON-RPC escape hatch. */
|
|
504
|
+
request<T = unknown>(method: string, params?: Record<string, unknown>): Promise<T>;
|
|
505
|
+
serverInfo(): Promise<Record<string, unknown>>;
|
|
506
|
+
ping(): Promise<{
|
|
507
|
+
pong: boolean;
|
|
508
|
+
serverTime: string;
|
|
509
|
+
}>;
|
|
510
|
+
getPool(selector: GdexPoolSelector): Promise<Record<string, unknown>>;
|
|
511
|
+
getBalance(owner: string, tokenClassKey?: string): Promise<Record<string, unknown>>;
|
|
512
|
+
getPositions(opts: {
|
|
513
|
+
owner: string;
|
|
514
|
+
pool?: GdexPoolKey;
|
|
515
|
+
poolHash?: string;
|
|
516
|
+
limit?: number;
|
|
517
|
+
bookmark?: string;
|
|
518
|
+
}): Promise<{
|
|
519
|
+
positions: Record<string, unknown>[];
|
|
520
|
+
bookmark: string;
|
|
521
|
+
}>;
|
|
522
|
+
getBlockHeight(): Promise<{
|
|
523
|
+
blockNumber: number;
|
|
524
|
+
timestamp: string;
|
|
525
|
+
}>;
|
|
526
|
+
quote(params: {
|
|
527
|
+
tokenIn: string;
|
|
528
|
+
tokenOut: string;
|
|
529
|
+
fee?: number;
|
|
530
|
+
amountIn?: string;
|
|
531
|
+
amountOut?: string;
|
|
532
|
+
}): Promise<Record<string, unknown>>;
|
|
533
|
+
getToken(tokenClassKey: string): Promise<Record<string, unknown>>;
|
|
534
|
+
/** One event per committed swap. Omit the pool to receive every pool's swaps. */
|
|
535
|
+
subscribeSwaps(cb: (event: Record<string, unknown>) => void, opts?: GdexSubscribeOptions & {
|
|
536
|
+
pool?: GdexPoolKey;
|
|
537
|
+
poolHash?: string;
|
|
538
|
+
transactionId?: string;
|
|
539
|
+
}): Promise<GdexSubscription>;
|
|
540
|
+
/** State changes of one pool. */
|
|
541
|
+
subscribePool(selector: GdexPoolSelector, cb: (event: Record<string, unknown>) => void, opts?: GdexSubscribeOptions): Promise<GdexSubscription>;
|
|
542
|
+
/** Balance changes of one wallet. */
|
|
543
|
+
subscribeBalances(owner: string, cb: (event: Record<string, unknown>) => void, opts?: GdexSubscribeOptions & {
|
|
544
|
+
tokenClassKey?: string;
|
|
545
|
+
}): Promise<GdexSubscription>;
|
|
546
|
+
/** Each newly created pool. */
|
|
547
|
+
subscribePoolCreated(cb: (event: Record<string, unknown>) => void, opts?: GdexSubscribeOptions & {
|
|
548
|
+
tokenClassKey?: string;
|
|
549
|
+
}): Promise<GdexSubscription>;
|
|
550
|
+
/**
|
|
551
|
+
* One event per committed AddLiquidity, RemoveLiquidity and CollectPositionFees, on both contract
|
|
552
|
+
* versions. Every filter is optional; with none, every liquidity event arrives. These events never
|
|
553
|
+
* appear on {@link subscribeSwaps}. There is no snapshot: read positions with {@link getPositions}.
|
|
554
|
+
* Deduplicate by `transactionId` plus `positionId`: a v1 BatchSubmit can hold several operations
|
|
555
|
+
* under one transaction id.
|
|
556
|
+
*/
|
|
557
|
+
subscribeLiquidity(cb: (event: GdexLiquidityEvent) => void, opts?: GdexSubscribeOptions & GdexLiquidityFilter): Promise<GdexSubscription>;
|
|
558
|
+
/** Each block-height advance. */
|
|
559
|
+
subscribeBlocks(cb: (event: Record<string, unknown>) => void, opts?: GdexSubscribeOptions): Promise<GdexSubscription>;
|
|
560
|
+
private openSocket;
|
|
561
|
+
private handleMessage;
|
|
562
|
+
private subscribe;
|
|
563
|
+
private unsubscribe;
|
|
564
|
+
private startReconnectLoop;
|
|
565
|
+
private reconnectLoop;
|
|
566
|
+
private resubscribeAll;
|
|
567
|
+
private resubscribeWithRateLimitRetry;
|
|
568
|
+
private waitForReconnectDelay;
|
|
569
|
+
private clearReconnectTimer;
|
|
570
|
+
private rejectPending;
|
|
571
|
+
private readRetryAfterMs;
|
|
572
|
+
private isRecord;
|
|
573
|
+
}
|
|
574
|
+
//#endregion
|
|
377
575
|
//#region src/types/fees.d.ts
|
|
378
576
|
/**
|
|
379
577
|
* Fee tiers for pools.
|
|
@@ -1071,9 +1269,11 @@ export declare class Swaps {
|
|
|
1071
1269
|
//#region src/types/env.d.ts
|
|
1072
1270
|
/** SDK deployment environment. */
|
|
1073
1271
|
export type GSwapEnv = 'prod' | 'stage';
|
|
1074
|
-
/** Backend
|
|
1272
|
+
/** Backend URLs used by one SDK deployment environment. */
|
|
1075
1273
|
export interface GSwapEnvironmentConfig {
|
|
1076
1274
|
dexBackendBaseUrl: string;
|
|
1275
|
+
/** The realtime stream endpoint (raw WebSocket, JSON-RPC 2.0). */
|
|
1276
|
+
dexBackendWsUrl: string;
|
|
1077
1277
|
}
|
|
1078
1278
|
/** Built-in GalaSwap deployment environments. */
|
|
1079
1279
|
export declare const GSWAP_ENVIRONMENTS: Readonly<Record<GSwapEnv, GSwapEnvironmentConfig>>;
|
|
@@ -1087,6 +1287,10 @@ export interface GSwapOptions {
|
|
|
1087
1287
|
dexBackendBaseUrl?: string | undefined;
|
|
1088
1288
|
httpRequestor?: HttpRequestor | undefined;
|
|
1089
1289
|
chainCallTimeoutMs?: number | undefined;
|
|
1290
|
+
/** Realtime stream endpoint. Defaults to the environment's, or is derived from `dexBackendBaseUrl`. */
|
|
1291
|
+
dexBackendWsUrl?: string | undefined;
|
|
1292
|
+
/** WebSocket constructor for the realtime stream; required on Node.js older than 22. */
|
|
1293
|
+
webSocketImpl?: unknown;
|
|
1090
1294
|
}
|
|
1091
1295
|
/** Main entry point for the current GalaChainDex SDK. */
|
|
1092
1296
|
export declare class GSwap {
|
|
@@ -1101,6 +1305,9 @@ export declare class GSwap {
|
|
|
1101
1305
|
readonly positions: Positions;
|
|
1102
1306
|
readonly swaps: Swaps;
|
|
1103
1307
|
readonly assets: Assets;
|
|
1308
|
+
readonly dexBackendWsUrl: string;
|
|
1309
|
+
private readonly webSocketImpl;
|
|
1310
|
+
private streamClient;
|
|
1104
1311
|
/**
|
|
1105
1312
|
* Create an SDK client for prod or stage.
|
|
1106
1313
|
*
|
|
@@ -1111,6 +1318,18 @@ export declare class GSwap {
|
|
|
1111
1318
|
* ```
|
|
1112
1319
|
*/
|
|
1113
1320
|
constructor(options?: GSwapOptions);
|
|
1321
|
+
/**
|
|
1322
|
+
* The realtime stream client for this environment (created on first use, not connected until you
|
|
1323
|
+
* call `connect()`).
|
|
1324
|
+
*
|
|
1325
|
+
* @example
|
|
1326
|
+
* ```typescript
|
|
1327
|
+
* const gSwap = new GSwap({ env: 'stage' });
|
|
1328
|
+
* await gSwap.stream.connect();
|
|
1329
|
+
* await gSwap.stream.subscribeLiquidity((event) => console.log(event.action, event.amount0));
|
|
1330
|
+
* ```
|
|
1331
|
+
*/
|
|
1332
|
+
get stream(): GdexStreamService;
|
|
1114
1333
|
}
|
|
1115
1334
|
//#endregion
|
|
1116
1335
|
//#region src/classes/gswap_sdk_error.d.ts
|
package/dist/index.d.ts
CHANGED
|
@@ -374,6 +374,204 @@ export declare class ChainGateway {
|
|
|
374
374
|
get httpRequestor(): HttpRequestor;
|
|
375
375
|
}
|
|
376
376
|
//#endregion
|
|
377
|
+
//#region src/classes/gdex_stream.d.ts
|
|
378
|
+
/** Options for {@link GdexStreamService}. */
|
|
379
|
+
export interface GdexStreamConfig {
|
|
380
|
+
/** Stream endpoint. Defaults to production (`wss://dex-backend-prod1.defi.gala.com/ws`). */
|
|
381
|
+
url?: string | undefined;
|
|
382
|
+
/** Reconnect attempts after an unexpected close. Default 5. */
|
|
383
|
+
reconnectAttempts?: number | undefined;
|
|
384
|
+
/** Delay before the first reconnect attempt; doubles each attempt. Default 2000 ms. */
|
|
385
|
+
reconnectDelayMs?: number | undefined;
|
|
386
|
+
/** How long a request waits for its response. Default 15000 ms. */
|
|
387
|
+
requestTimeoutMs?: number | undefined;
|
|
388
|
+
/**
|
|
389
|
+
* A standards-compatible WebSocket constructor. Required on Node.js older than 22, which has no
|
|
390
|
+
* global `WebSocket` (pass the one from the `ws` package).
|
|
391
|
+
*/
|
|
392
|
+
webSocketImpl?: unknown;
|
|
393
|
+
}
|
|
394
|
+
/** The channels of the realtime stream. */
|
|
395
|
+
export type GdexChannel = 'pool' | 'balance' | 'poolCreated' | 'swap' | 'liquidity' | 'blocks';
|
|
396
|
+
/** A pool named by its two token class keys (pipe form) and fee tier. */
|
|
397
|
+
export interface GdexPoolKey {
|
|
398
|
+
token0ClassKey: string;
|
|
399
|
+
token1ClassKey: string;
|
|
400
|
+
fee: number;
|
|
401
|
+
}
|
|
402
|
+
/** A pool named either by its key or by its hash (`v2:<poolRef>` for a v2 pool). */
|
|
403
|
+
export type GdexPoolSelector = {
|
|
404
|
+
pool: GdexPoolKey;
|
|
405
|
+
} | {
|
|
406
|
+
poolHash: string;
|
|
407
|
+
};
|
|
408
|
+
/** Options common to every subscription. */
|
|
409
|
+
export interface GdexSubscribeOptions {
|
|
410
|
+
/** Send the current state right after the subscribe response. */
|
|
411
|
+
snapshot?: boolean | undefined;
|
|
412
|
+
/** Trim each event to these fields; identity and envelope fields always stay. */
|
|
413
|
+
fields?: string[] | undefined;
|
|
414
|
+
}
|
|
415
|
+
/** Filters for {@link GdexStreamService.subscribeLiquidity}; all optional. */
|
|
416
|
+
export interface GdexLiquidityFilter {
|
|
417
|
+
/** Only this pool, named by its key. */
|
|
418
|
+
pool?: GdexPoolKey | undefined;
|
|
419
|
+
/** Only this pool, named by its hash (`v2:<poolRef>` for a v2 pool). */
|
|
420
|
+
poolHash?: string | undefined;
|
|
421
|
+
/** Only events for this LP wallet (the position's owner). */
|
|
422
|
+
owner?: string | undefined;
|
|
423
|
+
/** Only this transaction. */
|
|
424
|
+
transactionId?: string | undefined;
|
|
425
|
+
/** Contract version filter. */
|
|
426
|
+
version?: 'v1' | 'v2' | 'all' | undefined;
|
|
427
|
+
}
|
|
428
|
+
/** One committed add, remove or collect, as the `liquidity` channel reports it. */
|
|
429
|
+
export interface GdexLiquidityEvent {
|
|
430
|
+
version: 'v1' | 'v2';
|
|
431
|
+
pool: GdexPoolKey;
|
|
432
|
+
poolHash: string;
|
|
433
|
+
transactionId: string;
|
|
434
|
+
/** `add`, `remove` or `collect`. */
|
|
435
|
+
action: 'add' | 'remove' | 'collect';
|
|
436
|
+
/** The position's owner (the LP wallet). */
|
|
437
|
+
owner: string;
|
|
438
|
+
/** v1: the position id. v2: the chain position key `<pool>|<tickLow>|<tickHigh>|<owner>`. */
|
|
439
|
+
positionId?: string;
|
|
440
|
+
tickLower?: number;
|
|
441
|
+
tickUpper?: number;
|
|
442
|
+
/** v2 only: the position's liquidity after the operation; `"0"` means it is closed. */
|
|
443
|
+
liquidityAfter?: string;
|
|
444
|
+
/** Principal moved: deposited by an add, withdrawn by a remove, `"0"` for a collect. */
|
|
445
|
+
amount0: string;
|
|
446
|
+
amount1: string;
|
|
447
|
+
/** Fees paid out. v2: always present (`"0"` for an add). v1: present on a collect only. */
|
|
448
|
+
fees0?: string;
|
|
449
|
+
fees1?: string;
|
|
450
|
+
/** v2 only. */
|
|
451
|
+
token0Symbol?: string;
|
|
452
|
+
token1Symbol?: string;
|
|
453
|
+
blockNumber: number;
|
|
454
|
+
timestamp: string;
|
|
455
|
+
}
|
|
456
|
+
/** Whether a stream payload carries every field of a {@link GdexLiquidityEvent}. */
|
|
457
|
+
export declare function isGdexLiquidityEvent(value: Record<string, unknown>): value is Record<string, unknown> & GdexLiquidityEvent;
|
|
458
|
+
/** A live subscription. */
|
|
459
|
+
export interface GdexSubscription {
|
|
460
|
+
subscriptionId: string;
|
|
461
|
+
unsubscribe(): Promise<void>;
|
|
462
|
+
}
|
|
463
|
+
/** A JSON-RPC error answered by the stream. */
|
|
464
|
+
export declare class GdexStreamError extends Error {
|
|
465
|
+
readonly code: number;
|
|
466
|
+
readonly data?: unknown;
|
|
467
|
+
constructor(code: number, message: string, data?: unknown);
|
|
468
|
+
}
|
|
469
|
+
/**
|
|
470
|
+
* Client for the gSwap realtime stream (gdex WebSocket Protocol v1): JSON-RPC 2.0 over one raw
|
|
471
|
+
* WebSocket, with automatic reconnect and resubscribe.
|
|
472
|
+
*
|
|
473
|
+
* @example
|
|
474
|
+
* ```typescript
|
|
475
|
+
* const stream = new GdexStreamService();
|
|
476
|
+
* await stream.connect();
|
|
477
|
+
* await stream.subscribeLiquidity(event => console.log(event.action, event.owner), {
|
|
478
|
+
* owner: 'client|618ae395c1c653111d3315be',
|
|
479
|
+
* });
|
|
480
|
+
* ```
|
|
481
|
+
*/
|
|
482
|
+
export declare class GdexStreamService {
|
|
483
|
+
private readonly url;
|
|
484
|
+
private readonly requestTimeoutMs;
|
|
485
|
+
private readonly webSocketConstructor;
|
|
486
|
+
private readonly backoff;
|
|
487
|
+
private socket;
|
|
488
|
+
private connectPromise;
|
|
489
|
+
private nextRequestId;
|
|
490
|
+
private readonly pending;
|
|
491
|
+
private readonly subscriptionsByServerId;
|
|
492
|
+
private readonly activeSubscriptions;
|
|
493
|
+
private intentionalClose;
|
|
494
|
+
private reconnecting;
|
|
495
|
+
private reconnectTimer;
|
|
496
|
+
private reconnectDelayResolve;
|
|
497
|
+
constructor(config?: GdexStreamConfig);
|
|
498
|
+
/** Open the connection. Resolves at once when already connected. */
|
|
499
|
+
connect(): Promise<void>;
|
|
500
|
+
/** Close the connection and stop reconnecting. */
|
|
501
|
+
disconnect(): void;
|
|
502
|
+
isConnected(): boolean;
|
|
503
|
+
/** Raw JSON-RPC escape hatch. */
|
|
504
|
+
request<T = unknown>(method: string, params?: Record<string, unknown>): Promise<T>;
|
|
505
|
+
serverInfo(): Promise<Record<string, unknown>>;
|
|
506
|
+
ping(): Promise<{
|
|
507
|
+
pong: boolean;
|
|
508
|
+
serverTime: string;
|
|
509
|
+
}>;
|
|
510
|
+
getPool(selector: GdexPoolSelector): Promise<Record<string, unknown>>;
|
|
511
|
+
getBalance(owner: string, tokenClassKey?: string): Promise<Record<string, unknown>>;
|
|
512
|
+
getPositions(opts: {
|
|
513
|
+
owner: string;
|
|
514
|
+
pool?: GdexPoolKey;
|
|
515
|
+
poolHash?: string;
|
|
516
|
+
limit?: number;
|
|
517
|
+
bookmark?: string;
|
|
518
|
+
}): Promise<{
|
|
519
|
+
positions: Record<string, unknown>[];
|
|
520
|
+
bookmark: string;
|
|
521
|
+
}>;
|
|
522
|
+
getBlockHeight(): Promise<{
|
|
523
|
+
blockNumber: number;
|
|
524
|
+
timestamp: string;
|
|
525
|
+
}>;
|
|
526
|
+
quote(params: {
|
|
527
|
+
tokenIn: string;
|
|
528
|
+
tokenOut: string;
|
|
529
|
+
fee?: number;
|
|
530
|
+
amountIn?: string;
|
|
531
|
+
amountOut?: string;
|
|
532
|
+
}): Promise<Record<string, unknown>>;
|
|
533
|
+
getToken(tokenClassKey: string): Promise<Record<string, unknown>>;
|
|
534
|
+
/** One event per committed swap. Omit the pool to receive every pool's swaps. */
|
|
535
|
+
subscribeSwaps(cb: (event: Record<string, unknown>) => void, opts?: GdexSubscribeOptions & {
|
|
536
|
+
pool?: GdexPoolKey;
|
|
537
|
+
poolHash?: string;
|
|
538
|
+
transactionId?: string;
|
|
539
|
+
}): Promise<GdexSubscription>;
|
|
540
|
+
/** State changes of one pool. */
|
|
541
|
+
subscribePool(selector: GdexPoolSelector, cb: (event: Record<string, unknown>) => void, opts?: GdexSubscribeOptions): Promise<GdexSubscription>;
|
|
542
|
+
/** Balance changes of one wallet. */
|
|
543
|
+
subscribeBalances(owner: string, cb: (event: Record<string, unknown>) => void, opts?: GdexSubscribeOptions & {
|
|
544
|
+
tokenClassKey?: string;
|
|
545
|
+
}): Promise<GdexSubscription>;
|
|
546
|
+
/** Each newly created pool. */
|
|
547
|
+
subscribePoolCreated(cb: (event: Record<string, unknown>) => void, opts?: GdexSubscribeOptions & {
|
|
548
|
+
tokenClassKey?: string;
|
|
549
|
+
}): Promise<GdexSubscription>;
|
|
550
|
+
/**
|
|
551
|
+
* One event per committed AddLiquidity, RemoveLiquidity and CollectPositionFees, on both contract
|
|
552
|
+
* versions. Every filter is optional; with none, every liquidity event arrives. These events never
|
|
553
|
+
* appear on {@link subscribeSwaps}. There is no snapshot: read positions with {@link getPositions}.
|
|
554
|
+
* Deduplicate by `transactionId` plus `positionId`: a v1 BatchSubmit can hold several operations
|
|
555
|
+
* under one transaction id.
|
|
556
|
+
*/
|
|
557
|
+
subscribeLiquidity(cb: (event: GdexLiquidityEvent) => void, opts?: GdexSubscribeOptions & GdexLiquidityFilter): Promise<GdexSubscription>;
|
|
558
|
+
/** Each block-height advance. */
|
|
559
|
+
subscribeBlocks(cb: (event: Record<string, unknown>) => void, opts?: GdexSubscribeOptions): Promise<GdexSubscription>;
|
|
560
|
+
private openSocket;
|
|
561
|
+
private handleMessage;
|
|
562
|
+
private subscribe;
|
|
563
|
+
private unsubscribe;
|
|
564
|
+
private startReconnectLoop;
|
|
565
|
+
private reconnectLoop;
|
|
566
|
+
private resubscribeAll;
|
|
567
|
+
private resubscribeWithRateLimitRetry;
|
|
568
|
+
private waitForReconnectDelay;
|
|
569
|
+
private clearReconnectTimer;
|
|
570
|
+
private rejectPending;
|
|
571
|
+
private readRetryAfterMs;
|
|
572
|
+
private isRecord;
|
|
573
|
+
}
|
|
574
|
+
//#endregion
|
|
377
575
|
//#region src/types/fees.d.ts
|
|
378
576
|
/**
|
|
379
577
|
* Fee tiers for pools.
|
|
@@ -1071,9 +1269,11 @@ export declare class Swaps {
|
|
|
1071
1269
|
//#region src/types/env.d.ts
|
|
1072
1270
|
/** SDK deployment environment. */
|
|
1073
1271
|
export type GSwapEnv = 'prod' | 'stage';
|
|
1074
|
-
/** Backend
|
|
1272
|
+
/** Backend URLs used by one SDK deployment environment. */
|
|
1075
1273
|
export interface GSwapEnvironmentConfig {
|
|
1076
1274
|
dexBackendBaseUrl: string;
|
|
1275
|
+
/** The realtime stream endpoint (raw WebSocket, JSON-RPC 2.0). */
|
|
1276
|
+
dexBackendWsUrl: string;
|
|
1077
1277
|
}
|
|
1078
1278
|
/** Built-in GalaSwap deployment environments. */
|
|
1079
1279
|
export declare const GSWAP_ENVIRONMENTS: Readonly<Record<GSwapEnv, GSwapEnvironmentConfig>>;
|
|
@@ -1087,6 +1287,10 @@ export interface GSwapOptions {
|
|
|
1087
1287
|
dexBackendBaseUrl?: string | undefined;
|
|
1088
1288
|
httpRequestor?: HttpRequestor | undefined;
|
|
1089
1289
|
chainCallTimeoutMs?: number | undefined;
|
|
1290
|
+
/** Realtime stream endpoint. Defaults to the environment's, or is derived from `dexBackendBaseUrl`. */
|
|
1291
|
+
dexBackendWsUrl?: string | undefined;
|
|
1292
|
+
/** WebSocket constructor for the realtime stream; required on Node.js older than 22. */
|
|
1293
|
+
webSocketImpl?: unknown;
|
|
1090
1294
|
}
|
|
1091
1295
|
/** Main entry point for the current GalaChainDex SDK. */
|
|
1092
1296
|
export declare class GSwap {
|
|
@@ -1101,6 +1305,9 @@ export declare class GSwap {
|
|
|
1101
1305
|
readonly positions: Positions;
|
|
1102
1306
|
readonly swaps: Swaps;
|
|
1103
1307
|
readonly assets: Assets;
|
|
1308
|
+
readonly dexBackendWsUrl: string;
|
|
1309
|
+
private readonly webSocketImpl;
|
|
1310
|
+
private streamClient;
|
|
1104
1311
|
/**
|
|
1105
1312
|
* Create an SDK client for prod or stage.
|
|
1106
1313
|
*
|
|
@@ -1111,6 +1318,18 @@ export declare class GSwap {
|
|
|
1111
1318
|
* ```
|
|
1112
1319
|
*/
|
|
1113
1320
|
constructor(options?: GSwapOptions);
|
|
1321
|
+
/**
|
|
1322
|
+
* The realtime stream client for this environment (created on first use, not connected until you
|
|
1323
|
+
* call `connect()`).
|
|
1324
|
+
*
|
|
1325
|
+
* @example
|
|
1326
|
+
* ```typescript
|
|
1327
|
+
* const gSwap = new GSwap({ env: 'stage' });
|
|
1328
|
+
* await gSwap.stream.connect();
|
|
1329
|
+
* await gSwap.stream.subscribeLiquidity((event) => console.log(event.action, event.amount0));
|
|
1330
|
+
* ```
|
|
1331
|
+
*/
|
|
1332
|
+
get stream(): GdexStreamService;
|
|
1114
1333
|
}
|
|
1115
1334
|
//#endregion
|
|
1116
1335
|
//#region src/classes/gswap_sdk_error.d.ts
|