Skip to main content

preparedSwapData

This module provides pre-computed swap data structures for efficient token swapping operations across different chains. It contains adjacency graphs, swap paths, and reachable token mappings that are built at module initialization time from the static MARKETS configuration.

These constants are exported from @gmx-io/sdk/utils/swap (not as a separate sub-path).

Constants

Three pre-computed constants are available, each keyed by chain ID.

MARKETS_ADJACENCY_GRAPH

MARKETS_ADJACENCY_GRAPH: { [chainId: number]: MarketsGraph }

Pre-computed adjacency graph for each chain representing connections between tokens through shared markets. Built once at module load from MARKETS.

import { MARKETS_ADJACENCY_GRAPH } from "@gmx-io/sdk/utils/swap";

const arbitrumGraph = MARKETS_ADJACENCY_GRAPH[42161];
const wethConnections = arbitrumGraph["0x82aF49447D8a07e3bd95BD0d56f35241523fBab1"];

TOKEN_SWAP_PATHS

TOKEN_SWAP_PATHS: { [chainId: number]: SwapPaths }

Pre-computed swap paths between all reachable token pairs for each chain. Built once at module load from MARKETS_ADJACENCY_GRAPH.

import { TOKEN_SWAP_PATHS } from "@gmx-io/sdk/utils/swap";

const arbitrumSwapPaths = TOKEN_SWAP_PATHS[42161];
const wethAddress = "0x82aF49447D8a07e3bd95BD0d56f35241523fBab1";
const usdcAddress = "0xaf88d065e77c8cC2239327C5EDb3A432268e5831";
const swapPath = arbitrumSwapPaths[wethAddress]?.[usdcAddress];

REACHABLE_TOKENS

REACHABLE_TOKENS: { [chainId: number]: { [token: string]: string[] } }

Mapping of token addresses to all other tokens they can be reached from through swaps on each chain. Built once at module load.

import { REACHABLE_TOKENS } from "@gmx-io/sdk/utils/swap";

const reachableFromWeth = REACHABLE_TOKENS[42161]["0x82aF49447D8a07e3bd95BD0d56f35241523fBab1"];