import * as Markets from "./markets.js"; import type { PublicClient } from "viem"; import type { Address } from "viem"; import type { Market } from "./markets.js"; /** * Resolve a market by its pool address (one query; no live watch), as the * discriminated {@link Market} union — null if no market rests on that pool. * For spot/perp the pool address IS the market id, but binary markets are keyed * by bytes32 marketId, so this looks them up by the `poolAddress` column. * * RECYCLE CAVEAT (settlement-extraction v2): a binary pool serves SUCCESSIVE * markets, so several binary rows can share one `poolAddress`. This returns the * NEWEST (the pool's current/latest binding). To address a specific past market * of a recycled pool, key by `marketId` (or match `nonce`) instead. */ export declare function getMarketByPool(pool: string, indexerUrl: string): Promise; /** * Every market a pool has hosted, newest first — one row for a SPOT/PERP pool, * the full recycle history for a BINARY pool (which is REUSED across successive * markets, nonce++ each time). The first row is the pool's current market. */ export declare function listMarketsByPool(pool: string, opts: { limit?: number; } | undefined, indexerUrl: string): Promise; /** * One interval in a pool's life during which it was bound 1:1 to a single * market (indexer `PoolBinding`; id = `${pool}_${nonce}`). `MarketCreated` * OPENS a binding; `PoolReleased` or the next `MarketCreated` on the same pool * CLOSES it. An open binding (`toBlock` null) is the pool's current market. * * @category pools */ export interface PoolBindingRecord { /** `${poolAddress}_${nonce}` */ id: string; /** Lowercased pool address. */ poolAddress: string; /** Lowercased bytes32 marketId this binding served. */ marketId: string; /** Pool market nonce for this binding (decimal string). */ nonce: string; /** Block the binding opened in (the MarketCreated; decimal string). */ fromBlock: string; /** Log index of the opening event within its block. */ fromLogIndex: number; /** Timestamp (unix seconds) the binding opened. */ fromTimestamp: string; /** Null while the binding is open (the pool's current market). */ toBlock: string | null; /** Log index of the closing event; null while the binding is open. */ toLogIndex: number | null; /** Timestamp (unix seconds) the binding closed; null while open. */ toTimestamp: string | null; /** * How the binding closed: `"Released"` (PoolReleased) | `"Rotated"` (the next * MarketCreated recycled the pool onward); null while open. */ closedBy: "Released" | "Rotated" | null; } /** * A pool's full binding history, newest (highest nonce) first — every market * the pool has served. The first row with `toBlock === null` is the current * binding; a fully-released pool has no open row. */ export declare function getPoolBindings(pool: string, indexerUrl: string): Promise; /** * The indexer's per-pool aggregate (`Pool`; id = lowercased pool address) — the * long-lived BinaryPool contract that outlives any single market. * * @category pools */ export interface IndexedPool { /** Lowercased pool address (== address). */ id: string; /** Lowercased pool address (== id). */ address: string; /** Collateral token the pool is bound to for its whole life (lowercased). */ collateral: string | null; /** * The pool's creator — its first-deploy market creator, the only party that * can reuse it (lowercased). */ creator: string | null; /** * marketId of the pool's CURRENT binding; null when finalized + released and * awaiting reuse. */ currentMarketId: string | null; /** Pool market nonce of the current binding (decimal string). */ currentNonce: string | null; /** Number of markets this pool has served (== the latest nonce). */ generationCount: number; /** Timestamp (unix seconds) of the pool's first MarketCreated. */ createdAtTimestamp: string; /** Timestamp (unix seconds) of the last binding change. */ updatedAtTimestamp: string; } /** * One pool's aggregate row by address — null if the indexer has never seen a * MarketCreated on it. */ export declare function getPool(address: string, indexerUrl: string): Promise; /** * A creator's free (finalized + released, reusable) pools for `collateral`, * LIFO order (the LAST entry is popped first on the creator's next * createMarket). Pure chain read (no signer). */ export declare function getFreePools(creator: Address, collateral: Address, module: Address, client: PublicClient): Promise; /** * Drop every memoized pool set and pool type. Tests use it so one file's stubbed * registry cannot leak into the next test through the TTL. */ export declare function clearPoolSets(): void; /** * Every pool currently hosting a market of `type`, lowercased. SPOT and PERP are a * handful of addresses; BINARY is thousands and is not what you want — use * {@link poolScope}, which expresses binary as the complement. */ export declare function poolsOfType(type: Markets.MarketType, indexerUrl: string): Promise; /** * The Hasura comparison that scopes a `pool` / `market_id` column to one market type: * `{ _in }` over the type's pools for SPOT and PERP, `{ _nin }` over spot ∪ perp for * BINARY. Drop-in for the `market: { marketType }` relationship predicate, minus the * correlated EXISTS — see the section header. */ export declare function poolScope(type: Markets.MarketType, indexerUrl: string): Promise<{ _in: string[]; } | { _nin: string[]; }>; /** * The `where` fragment that scopes an Order / StopOrder read by pool and/or type — the * one place the two compose, replacing `market: { marketType, poolAddress }`. * * Both constraints always narrow. A pool that is not of the requested type matches * NOTHING, exactly as the relationship form it replaces did: passing a spot pool to a * perp read must not return spot rows, whose `orderIdRaw` addresses a different * registry. A pool of a known SPOT / PERP type is its own market id, a direct `_eq` on * the indexed column; a known BINARY pool keeps the relationship form (see the section * header). A pool the indexer has no market row for yet falls back to that same * relationship form, carrying whichever constraints were asked for — correct for any * type, and merely costlier on a path that only exists until the pool is indexed. * Neither scope returns `undefined`, so the caller adds no predicate. */ export declare function marketScope(opts: { pool?: string; marketType?: Markets.MarketType; }, indexerUrl: string): Promise | undefined>;