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 from market configurations.

Constants

  • MARKETS_ADJACENCY_GRAPH: { [chainId: number]: MarketsGraph } - Pre-computed adjacency graph for each chain representing market connections between tokens
import { MARKETS_ADJACENCY_GRAPH } from "@gmx-ui/sdk/utils/swap/preparedSwapData";

// Get the adjacency graph for Arbitrum (chain ID 42161)
const arbitrumGraph = MARKETS_ADJACENCY_GRAPH[42161];

// Access connections for a specific token
const wethConnections = arbitrumGraph["0x82aF49447D8a07e3bd95BD0d56f35241523fBab1"];
  • TOKEN_SWAP_PATHS: { [chainId: number]: SwapPaths } - Pre-computed swap paths between all token pairs for each chain
import { TOKEN_SWAP_PATHS } from "@gmx-ui/sdk/utils/swap/preparedSwapData";

// Get swap paths for Arbitrum
const arbitrumSwapPaths = TOKEN_SWAP_PATHS[42161];

// Find swap path from WETH to USDC
const wethAddress = "0x82aF49447D8a07e3bd95BD0d56f35241523fBab1";
const usdcAddress = "0xaf88d065e77c8cC2239327C5EDb3A432268e5831";
const swapPath = arbitrumSwapPaths[wethAddress]?.[usdcAddress];
  • REACHABLE_TOKENS: { [chainId: number]: { [token: string]: string[] } } - Mapping of tokens to all other tokens they can be swapped to on each chain
import { REACHABLE_TOKENS } from "@gmx-ui/sdk/utils/swap/preparedSwapData";

// Get reachable tokens for Arbitrum
const arbitrumReachableTokens = REACHABLE_TOKENS[42161];

// Find all tokens reachable from WETH
const wethAddress = "0x82aF49447D8a07e3bd95BD0d56f35241523fBab1";
const reachableFromWeth = arbitrumReachableTokens[wethAddress];