Class TokenAPI

Represents a class for handling Token operations related to the subgraph.

Hierarchy

  • BaseAPI
    • TokenAPI

Constructors

Properties

premia: Premia

Methods

  • Fetches the current spot price of a given token in USD.

    This function retrieves the spot price for a given token from the underlying data source. If the token's USD price is not available, an error is thrown. This function is cached for a minute to prevent frequent API calls.

    Throws

    An error if the USD price for the token is not found.

    Parameters

    • address: string

      The address of the token for which to fetch the spot price.

    Returns Promise<bigint>

    A promise that resolves to the spot price of the token in USD.

  • Fetches information of a given token from subgraph, coingecko, or token contract.

    Throws

    Will throw an error if the token information cannot be fetched from either the subgraph, coingecko, or token contract.

    Parameters

    • address: string

      The address of the token for which to fetch the detailed information.

    Returns Promise<Token>

    A promise that resolves to an object containing the token's name, symbol, decimals, whether it's native or wrapped native, price in ETH and USD, address, and chain ID.

  • Fetches extended information of a given token from the subgraph.

    Parameters

    • address: string

      The address of the token for which to fetch the extended information.

    Returns Promise<TokenExtended>

    A promise that resolves to an object containing the extended information of the token.

  • Retrieves the information for a list of tokens given their details.

    This function fetches information for multiple tokens specified by an array of token information objects. If subgraph querying is not skipped and fails, the function resorts to fetching token details directly.

    Throws

    Will throw an error if the subgraph fails to load.

    Parameters

    • tokenList: TokenInfo[]

      An array of token information objects for which to fetch the token data.

    Returns Promise<Token[]>

    A promise that resolves to an array containing the information of the specified tokens.

  • Retrieves the extended information for a list of tokens given their details.

    This function fetches extended information for multiple tokens specified by an array of token information objects.

    Parameters

    • tokenList: TokenInfo[]

      An array of token information objects for which to fetch the token data.

    Returns Promise<TokenExtended[]>

    A promise that resolves to an array containing the extended information of the specified tokens.

  • Fetches minimal information of a given token including its symbol and decimals.

    Parameters

    • address: string

      The address of the token for which to fetch the minimal information.

    Returns Promise<TokenMinimal>

    A promise that resolves to an object containing the token's address, symbol, and decimals.

  • Fetches information for multiple tokens given their addresses.

    This function retrieves information for multiple tokens specified by an array of addresses. It uses caching with an hourly time to live to prevent frequent calls to the subgraph. If subgraph call fails, it switches to skip the subgraph and fetches the tokens' information directly.

    Parameters

    • tokens: string[]

      An array of token addresses for which to fetch the information.

    Returns Promise<Token[]>

    A promise that resolves to an array containing the information of the tokens.

  • Retrieves extended information of multiple tokens given their addresses.

    Parameters

    • tokens: string[]

      An array of token addresses for which to fetch the extended information.

    Returns Promise<TokenExtended[]>

    A promise that resolves to an array containing the extended information of the specified tokens.

  • Checks if the given address corresponds to the native token on the current chain.

    Parameters

    • address: string

      The address to check.

    Returns boolean

    True if the address corresponds to the native token; otherwise false.

  • Checks if the given address corresponds to the wrapped native token on the current chain.

    Parameters

    • address: string

      The address to check.

    Returns boolean

    True if the address corresponds to the wrapped native token; otherwise false.

Generated using TypeDoc