Skip to content
This repository has been archived by the owner on Apr 18, 2024. It is now read-only.

Types: Token

Bleaker edited this page Feb 22, 2022 · 3 revisions

Token is a class which can represent any ERC20-compatible token on any given network, and is a data class.

The Synapse Protocol SDK provides pre-defined Token instances for all tokens supported by the Synapse Protocol on all supported networks in the Tokens namespace, which is easily imported like so:

import {Tokens, ChainId} from "@synapseprotocol/sdk";

console.log(Tokens.USDC.address(ChainId.BSC));

You should not expect to ever have to instantiate a Token manually, and using a manually instantiated Token with various functions in the SDK will likely cause undefined behavior.

Instance variables

Unless otherwise specified, all instance variables are read only and set by the constructor.

  • name (string) - The "official" name of the token. Example: "USD Circle" (for USDC)
  • symbol (string) - Symbol the token is known by both on and off-chain. Examples: "USDT" (Tether's USD stablecoin), "DOGE" (for Dogecoin)
  • addresses ({ [chainId: number] => string }) - This field is similarly shaped to decimals, in that it is a mapping with shape chain id => address for chain (string), containing the on-chain addresses of this token for respective Chain ID values.

Functions

  • address
    • Returns the on-chain address of this token respective to the passed Chain ID.
    • Params:
      • chainId: number
        • Chain ID of the chain for which you want this token's on-chain address.
    • Returns:
      • string
        • The on-chain address of this token respective to network, or null if the token is not supported by the Synapse Protocol on the given network.
  • decimals
    • Returns the on-chain decimals value of this token respective to the passed ChainID.
    • Params:
      • chainId: number
        • Chain ID of the chain for which you want this token's on-chain decimals.
    • Returns:
      • number
        • The on-chain decimals value of this token respective to network, or null if the token is not supported by the Synapse Protocol on the given network.
  • valueToWei
    • Given an amount of a token in Ether, returns that value represented in units of Wei using the correct decimal precision for the passed Chain Id.
    • Params:
      • ether: BigNumberish
        • Some amount of a given token in units of Ether
      • chainId: number
        • Chain ID is required to ensure proper arithmatic. This is especially important when retrieving the Wei representation of an Ether amount for a token which has different decimal values on different chains, such as USDC and USDT.
    • Returns:
      • BigNumber
        • Wei units representation of the passed amount based on its on-chain decimals value for the passed chainId.
Clone this wiki locally