tokens
This module provides comprehensive token configuration and utilities for the GMX protocol across different blockchain networks. It includes token definitions, mappings, and helper functions for working with tokens in both V1 and V2 versions of the protocol.
Constants
NATIVE_TOKEN_ADDRESS: string- The zero address used to represent native tokens (ETH, AVAX, etc.)
import { NATIVE_TOKEN_ADDRESS } from "@gmx-ui/sdk/configs/tokens";
console.log(NATIVE_TOKEN_ADDRESS); // "0x0000000000000000000000000000000000000000"
TOKENS: { [chainId: number]: Token[] }- Complete token configurations for each supported chain
import { TOKENS, ARBITRUM } from "@gmx-ui/sdk/configs/tokens";
const arbitrumTokens = TOKENS[ARBITRUM];
console.log(arbitrumTokens[0].symbol); // "ETH"
TOKEN_COLOR_MAP: { [symbol: string]: string }- Color mappings for token symbols used in UI components
import { TOKEN_COLOR_MAP } from "@gmx-ui/sdk/configs/tokens";
console.log(TOKEN_COLOR_MAP.ETH); // "#6062a6"
console.log(TOKEN_COLOR_MAP.BTC); // "#F7931A"
Methods
getSyntheticTokens
getSyntheticTokens(chainId: number): Token[]
Returns all synthetic tokens available on the specified chain.
import { getSyntheticTokens, ARBITRUM } from "@gmx-ui/sdk/configs/tokens";
const syntheticTokens = getSyntheticTokens(ARBITRUM);
console.log(syntheticTokens.map(token => token.symbol)); // ["BTC", "DOGE", "LTC", ...]
getWrappedToken
getWrappedToken(chainId: number): Token
Returns the wrapped native token for the specified chain.
import { getWrappedToken, ARBITRUM } from "@gmx-ui/sdk/configs/tokens";
const wrappedToken = getWrappedToken(ARBITRUM);
console.log(wrappedToken.symbol); // "WETH"
getNativeToken
getNativeToken(chainId: number): Token
Returns the native token for the specified chain.
import { getNativeToken, ARBITRUM } from "@gmx-ui/sdk/configs/tokens";
const nativeToken = getNativeToken(ARBITRUM);
console.log(nativeToken.symbol); // "ETH"
getTokens
getTokens(chainId: number): Token[]
Returns all tokens available on the specified chain.
import { getTokens, ARBITRUM } from "@gmx-ui/sdk/configs/tokens";
const allTokens = getTokens(ARBITRUM);
console.log(allTokens.length); // Total number of tokens on Arbitrum
getV1Tokens
getV1Tokens(chainId: number): Token[]
Returns tokens available in GMX V1 on the specified chain.
import { getV1Tokens, ARBITRUM } from "@gmx-ui/sdk/configs/tokens";
const v1Tokens = getV1Tokens(ARBITRUM);
console.log(v1Tokens.filter(token => token.isV1Available).length);
getV2Tokens
getV2Tokens(chainId: number): Token[]
Returns tokens available in GMX V2 on the specified chain.
import { getV2Tokens, ARBITRUM } from "@gmx-ui/sdk/configs/tokens";
const v2Tokens = getV2Tokens(ARBITRUM);
console.log(v2Tokens.length);
getTokensMap
getTokensMap(chainId: number): { [address: string]: Token }
Returns a mapping of token addresses to token objects for the specified chain.
import { getTokensMap, ARBITRUM } from "@gmx-ui/sdk/configs/tokens";
const tokensMap = getTokensMap(ARBITRUM);
const ethToken = tokensMap["0x0000000000000000000000000000000000000000"];
console.log(ethToken.symbol); // "ETH"
getWhitelistedV1Tokens
getWhitelistedV1Tokens(chainId: number): Token[]
Returns whitelisted tokens for GMX V1 on the specified chain.
import { getWhitelistedV1Tokens, ARBITRUM } from "@gmx-ui/sdk/configs/tokens";
const whitelistedTokens = getWhitelistedV1Tokens(ARBITRUM);
console.log(whitelistedTokens.length);
getVisibleV1Tokens
getVisibleV1Tokens(chainId: number): Token[]
Returns visible V1 tokens (excluding wrapped tokens) for the specified chain.
import { getVisibleV1Tokens, ARBITRUM } from "@gmx-ui/sdk/configs/tokens";
const visibleTokens = getVisibleV1Tokens(ARBITRUM);
console.log(visibleTokens.filter(token => !token.isWrapped).length);
isValidToken
isValidToken(chainId: number, address: string): boolean
Validates if a token address exists on the specified chain. Throws an error if the chain is invalid or token doesn't exist.
import { isValidToken, ARBITRUM } from "@gmx-ui/sdk/configs/tokens";
const isValid = isValidToken(ARBITRUM, "0x82aF49447D8a07e3bd95BD0d56f35241523fBab1");
console.log(isValid); // true
isValidTokenSafe
isValidTokenSafe(chainId: number, address: string): boolean
Safely validates if a token address exists on the specified chain without throwing errors.
import { isValidTokenSafe, ARBITRUM } from "@gmx-ui/sdk/configs/tokens";
const isValid = isValidTokenSafe(ARBITRUM, "0x82aF49447D8a07e3bd95BD0d56f35241523fBab1");
console.log(isValid); // true
const isInvalid = isValidTokenSafe(ARBITRUM, "0xinvalidaddress");
console.log(isInvalid); // false
getToken
getToken(chainId: number, address: string): Token
Returns the token object for the specified address on the given chain.
import { getToken, ARBITRUM } from "@gmx-ui/sdk/configs/tokens";
const wethToken = getToken(ARBITRUM, "0x82aF49447D8a07e3bd95BD0d56f35241523fBab1");
console.log(wethToken.symbol); // "WETH"
getTokenBySymbol
getTokenBySymbol(chainId: number, symbol: string, options?: { isSynthetic?: boolean; version?: "v1" | "v2"; symbolType?: "symbol" | "baseSymbol" }): Token
Parameters
options: object- Optional configuration objectisSynthetic?: boolean- Filter by synthetic token statusversion?: "v1" | "v2"- Filter by protocol versionsymbolType?: "symbol" | "baseSymbol"- Type of symbol to match against
Returns the token object for the specified symbol on the given chain.
import { getTokenBySymbol, ARBITRUM } from "@gmx-ui/sdk/configs/tokens";
const ethToken = getTokenBySymbol(ARBITRUM, "ETH");
console.log(ethToken.address); // "0x0000000000000000000000000000000000000000"
const syntheticBTC = getTokenBySymbol(ARBITRUM, "BTC", { isSynthetic: true });
console.log(syntheticBTC.isSynthetic); // true
convertTokenAddress
convertTokenAddress<T extends keyof TokenAddressTypesMap, R extends TokenAddressTypesMap[T]>(chainId: number, address: string, convertTo?: T): R
Parameters
convertTo?: T- Target address type ("wrapped" | "native")
Converts between native and wrapped token addresses.
import { convertTokenAddress, NATIVE_TOKEN_ADDRESS, ARBITRUM } from "@gmx-ui/sdk/configs/tokens";
const wrappedAddress = convertTokenAddress(ARBITRUM, NATIVE_TOKEN_ADDRESS, "wrapped");
console.log(wrappedAddress); // "0x82aF49447D8a07e3bd95BD0d56f35241523fBab1"
const nativeAddress = convertTokenAddress(ARBITRUM, "0x82aF49447D8a07e3bd95BD0d56f35241523fBab1", "native");
console.log(nativeAddress); // "0x0000000000000000000000000000000000000000"
getNormalizedTokenSymbol
getNormalizedTokenSymbol(tokenSymbol: string): string
Normalizes token symbols by removing prefixes and suffixes.
import { getNormalizedTokenSymbol } from "@gmx-ui/sdk/configs/tokens";
console.log(getNormalizedTokenSymbol("WETH")); // "ETH"
console.log(getNormalizedTokenSymbol("USDC.E")); // "USDC"
console.log(getNormalizedTokenSymbol("PBTC")); // "BTC"
isChartAvailableForToken
isChartAvailableForToken(chainId: number, tokenSymbol: string): boolean
Checks if chart data is available for the specified token.
import { isChartAvailableForToken, ARBITRUM } from "@gmx-ui/sdk/configs/tokens";
const hasChart = isChartAvailableForToken(ARBITRUM, "ETH");
console.log(hasChart); // true
getPriceDecimals
getPriceDecimals(chainId: number, tokenSymbol?: string): number
Returns the number of decimal places to display for token prices.
import { getPriceDecimals, ARBITRUM } from "@gmx-ui/sdk/configs/tokens";
const decimals = getPriceDecimals(ARBITRUM, "ETH");
console.log(decimals); // 2
const defaultDecimals = getPriceDecimals(ARBITRUM);
console.log(defaultDecimals); // 2
getTokenBySymbolSafe
getTokenBySymbolSafe(chainId: number, symbol: string, params?: Parameters<typeof getTokenBySymbol>[2]): Token | undefined
Parameters
params?: object- Same options as getTokenBySymbol
Safely returns a token by symbol without throwing errors.
import { getTokenBySymbolSafe, ARBITRUM } from "@gmx-ui/sdk/configs/tokens";
const token = getTokenBySymbolSafe(ARBITRUM, "ETH");
console.log(token?.symbol); // "ETH"
const invalidToken = getTokenBySymbolSafe(ARBITRUM, "INVALID");
console.log(invalidToken); // undefined
isTokenInList
isTokenInList(token: Token, tokenList: Token[]): boolean
Parameters
token: Token- Token to check fortokenList: Token[]- List of tokens to search in
Checks if a token exists in a given token list.
import { isTokenInList, getV1Tokens, getTokenBySymbol, ARBITRUM } from "@gmx-ui/sdk/configs/tokens";
const ethToken = getTokenBySymbol(ARBITRUM, "ETH");
const v1Tokens = getV1Tokens(ARBITRUM);
const isInV1 = isTokenInList(ethToken, v1Tokens);
console.log(isInV1); // true
isSimilarToken
isSimilarToken(tokenA: Token, tokenB: Token): boolean
Parameters
tokenA: Token- First token to comparetokenB: Token- Second token to compare
Checks if two tokens are similar based on address or symbol matching.
import { isSimilarToken, getTokenBySymbol, ARBITRUM } from "@gmx-ui/sdk/configs/tokens";
const ethToken = getTokenBySymbol(ARBITRUM, "ETH");
const wethToken = getTokenBySymbol(ARBITRUM, "WETH");
const areSimilar = isSimilarToken(ethToken, wethToken);
console.log(areSimilar); // true
getTokenVisualMultiplier
getTokenVisualMultiplier(token: Token): string
Parameters
token: Token- Token to get visual multiplier for
Returns the visual multiplier string for display purposes.
import { getTokenVisualMultiplier, getTokenBySymbol, ARBITRUM } from "@gmx-ui/sdk/configs/tokens";
const pepeToken = getTokenBySymbol(ARBITRUM, "PEPE");
const multiplier = getTokenVisualMultiplier(pepeToken);
console.log(multiplier); // "k"
getStableTokens
getStableTokens(chainId: number): Token[]
Returns all stable tokens available on the specified chain.
import { getStableTokens, ARBITRUM } from "@gmx-ui/sdk/configs/tokens";
const stableTokens = getStableTokens(ARBITRUM);
console.log(stableTokens.map(token => token.symbol)); // ["USDC.E", "USDC", "USDT", "DAI", ...]
getCategoryTokenAddresses
getCategoryTokenAddresses(chainId: number, category: TokenCategory): string[]
Parameters
category: TokenCategory- Token category to filter by
Returns addresses of tokens belonging to the specified category.
import { getCategoryTokenAddresses, ARBITRUM } from "@gmx-ui/sdk/configs/tokens";
const layer1Addresses = getCategoryTokenAddresses(ARBITRUM, "layer1");
console.log(layer1Addresses); // Array of addresses for layer1 tokens
createTokensMap
createTokensMap(tokens: Token[]): Record<string, Token>
Parameters
tokens: Token[]- Array of tokens to create map from
Creates a mapping of token addresses to token objects.
import { createTokensMap, getV1Tokens, ARBITRUM } from "@gmx-ui/sdk/configs/tokens";
const v1Tokens = getV1Tokens(ARBITRUM);
const tokensMap = createTokensMap(v1Tokens);
console.log(Object.keys(tokensMap).length); // Number of V1 tokens