Class: Pools
gSwap SDK 2.0.0-rc.4 / Pools
Class: Pools
Defined in: packages/gswap-sdk/dist/index.d.ts:2509
Read-only pool and current-price access for the current GalaChainDex contract.
Constructors
Constructor
new Pools(
gateway,symbols,options?):Pools
Defined in: packages/gswap-sdk/dist/index.d.ts:2522
Creates a pool service. options.onInvalidEntry is told about every pool row that was
skipped as unusable (see InvalidEntryHandler).
Parameters
gateway
PoolGateway
symbols
options?
onInvalidEntry?
Returns
Pools
Example
const pools = new Pools(gateway, symbols);
Methods
getCompositePool()
getCompositePool(
token0,token1,fee):Promise<CompositePool>
Defined in: packages/gswap-sdk/dist/index.d.ts:2587
Fetches the complete chain composite pool snapshot, in canonical symbol order.
Parameters
token0
token1
fee
Returns
Promise<CompositePool>
Example
const composite = await service.getCompositePool('GALA', 'GUSDC', 3000);
console.log(composite.positions?.length ?? 0);
getPool()
getPool(
token0,token1,fee):Promise<PoolInfo>
Defined in: packages/gswap-sdk/dist/index.d.ts:2567
Fetches one pool from the backend, preserving whether the request order was flipped.
Parameters
token0
token1
fee
Returns
Promise<PoolInfo>
Example
const pool = await service.getPool('GUSDC', 'GALA', 3000);
console.log(pool.flippedFromRequest);
getPools()
getPools(
options?):Promise<PoolListInfo[]>
Defined in: packages/gswap-sdk/dist/index.d.ts:2538
Fetches current-contract pools from the swap backend, optionally searched, sorted and paged
by the backend. A row that is not a usable pool is skipped and reported to onInvalidEntry
instead of failing the whole list; an answer that is not a list at all is
INVALID_CHAIN_RESPONSE.
Parameters
options?
Returns
Promise<PoolListInfo[]>
Example
const top = await service.getPools({ sortBy: 'tvl', sortOrder: 'desc', page: 1, limit: 8 });
console.log(top.length);
getSlot0()
getSlot0(
token0,token1,fee):Promise<Slot0>
Defined in: packages/gswap-sdk/dist/index.d.ts:2577
Fetches the current sqrt price, price, and tick for one pool.
Parameters
token0
token1
fee
Returns
Promise<Slot0>
Example
const slot0 = await service.getSlot0('GALA', 'GUSDC', 3000);
console.log(slot0.tick);
watchNewPools()
watchNewPools(
onPool,options?): () =>void
Defined in: packages/gswap-sdk/dist/index.d.ts:2557
Watches for pools created from now on, by polling Pools.getPools every intervalMs
(the polling alternative to the realtime stream's GSwap.stream.subscribePoolCreated, for a
client that cannot hold a WebSocket open). The first answer is the baseline: a pool that
existed then is never reported. Each later pool is judged once, when it first appears, against
minTvl and tokens. A poll never overlaps the previous one (a tick that finds one still in
flight is skipped), and nothing is reported after the returned function stops the watcher.
Parameters
onPool
(pool) => void
options?
Returns
() => void
Example
const stop = gSwap.pools.watchNewPools((pool) => console.log('new pool', pool.poolRef), {
intervalMs: 60_000,
tokens: ['GALA'],
});
// later
stop();