🟧JS SDK Types

Symbiosis JS SDK Types

Checklist to do before deploying to production (Mainnet)

If any of these checks fail, you put the assets of your users at risk. Therefore, you must not go to Mainnet with real assets and real users. This could result in the loss of your users' assets.

  1. You approve users’ ERC20 tokens only for one contract, and this contract is metaRouterGateway on each blockchain. You can check the addresses of the contracts for all blockchains supported by Symbiosis protocol V2 in this configuration.

  2. All contracts you use in your software exist on the corresponding blockchains, and their addresses on each blockchain correspond to the addresses in this configuration.

  3. You do not modify, reuse, or cash the calldata you get by calling methods of the Symbiosis SDKs and API.

  4. After deployment to Mainnet, run at least one transaction.

Please do these checks for the initial deployment AND each software update.

Types

Symbiosis JS SDK defines the following types:

TypeUse

ChainId

The type lists identifiers of supported blockchains.

ChainConfig

The type defines the network configuration to build cross-chain routes.

OmniPoolConfig

The type defines a liquidity pool consisting of a stablecoins and an sTokens.

AdvisorConfig and Config

The types define details of Microservice Advisor. For more information on Advisor, please check Gas Fees for Cross-chain Operations via Symbiosis

TokenConstructor

The type defines a set of parameters used to create an instance of Token class.

PendingRequestState and PendingRequest

The types are used for reverting stuck cross-chain operations.

ChainId type

ChainId type lists named constants with the integer identifiers of supported blockchains.

export enum ChainId {
    ETH_MAINNET = 1,
    ETH_RINKEBY = 4,
    ETH_GOERLI = 5,
    ETH_KOVAN = 42,
    BSC_MAINNET = 56,
    BSC_TESTNET = 97,
    MATIC_MAINNET = 137,
    MATIC_MUMBAI = 80001,
    AVAX_MAINNET = 43114,
    AVAX_TESTNET = 43113,
    HECO_MAINNET = 128,
    HECO_TESTNET = 256,
    OKEX_MAINNET = 66,
    OKEX_TESTNET = 65,
    BOBA_MAINNET = 288,
    BOBA_BNB = 56288,
    BOBA_AVALANCHE = 43288,
    BOBA_RINKEBY = 28,
    MILKOMEDA_MAINNET = 2001,
    MILKOMEDA_DEVNET = 200101,
    BTC_MAINNET = 5555,
    BTC_TESTNET = 55555,
    AURORA_MAINNET = 1313161554,
    AURORA_TESTNET = 1313161555,
    TELOS_MAINNET = 40,
    TELOS_TESTNET = 41,
}

ChainConfig type

ChainConfig type defines the network configuration used to build cross-chain routes.

export type ChainConfig = {
    id: ChainId
    rpc: string
    dexFee: number
    filterBlockOffset: number
    stables: TokenConstructor[]
    metaRouter: string
    metaRouterGateway: string
    multicallRouter: string
    router: string
    bridge: string
    synthesis: string
    portal: string
    fabric: string
    waitForBlocksCount: number
}
PropertyDescription

id

The blockchain identifier

rpc

The HTTP RPC of the blockchain. Used to retrieve information about liquidity pools' reserves for this blockchain.

dexFee

The liquidity provider fee for the chosen DEX. It's an integer value (for example, 30 that equals 0.3%)

filterBlockOffset

The range of blocks within which to get log from the blockchain. Used:

  1. To get stuck transactions,

  2. To get a status of the current swap/bridging/revering operation.

stables

The list of stablecoins used to build cross-chain routes. This list should contain one stablecoin of this blockchain and N sToken that connect this blockchain to other blockchains.

router

The address of a DEX router for this blockchain. For example, it can be UniSwap for Ethereum.

metaRouter

The address of the Metarouter contract. ------------------ IMPORTANT The metaRouter contract can work only with ERC20 tokens that have been approved for the metaRouterGateway contract. ERC20 tokens shouldn't be approved for metaRouter. ------------------ For more information on the contracts and the reason why it works this way, please refer to Symbiosis Routing Contracts

metaRouterGateway

The address of the MetarouterGateway contract.

multicallRouterGateway

The address of the MulticallRouter contract.

bridge

The address of the BridgeV2 contract. ------------------ For more information on the contracts and the reason why it works this way, please refer to Symbiosis Routing Contracts

synthesis

The address of the Synthesis contract. ------------------ For more information on the contracts and the reason why it works this way, please refer to Symbiosis Routing Contracts

portal

The address of the Portal contract. ------------------ For more information on the contracts and the reason why it works this way, please refer to Symbiosis Routing Contracts

fabric

The address of the Fabric contract that stores a list of an sToken and a stablecoin pairs.

waitForBlocksCount

The number of blocks for the destination blockchain to wait for a transaction to be mined.

OmniPoolConfig type

OmniPoolConfig type defines a liquidity pool containing stablecoins and sTokens.

export type OmniPoolConfig = {
    chainId: ChainId
    address: string
    oracle: string
}

AdvisorConfig and Config types

AdvisorConfig and Config types define details of the Advisor service.

For more information on Advisor, please check Gas Fees for Cross-chain Operations via Symbiosis

AdvisorConfig type

This type contains the address of the Advisor service.

export type AdvisorConfig = {
    url: string
}

Config type

This type defines the configuration for the Advisor service.

export type Config = {
    advisor: AdvisorConfig
    chains: ChainConfig[]
    minSwapAmountInUsd: number
    maxSwapAmountInUsd: number
    omniPool: OmniPoolConfig
}
PropertyDescription

advisor

The configuration to access the Advisor service.

chains

A list of networks' configurations.

minSwapAmountInUsd

The minimum sum of cross-chain swap in the USD equivalent.

maxSwapAmountInUsd

The maximal sum of cross-chain swap in the USD equivalent.

omniPool

Config of liquidity pool consisting of a stablecoins and an sTokens

TokenConstructor type

TokenConstructor type defines a set of parameters used to create an instance of Token class.

export type TokenConstructor = {
    name?: string
    symbol?: string
    address: string
    decimals: number
    chainId: ChainId
    isNative?: boolean
    isStable?: boolean
    chainFromId?: ChainId
    icons?: Icons
    userToken?: boolean
}
PropertyDescription

name

The cryptocurrency name

symbols

The cryptocurrency ticker symbol

address

The cryptocurrency address

decimals

The decimals for the cryptocurrency

isNative

A flag indicating that the cryptocurrency is a native cryptocurrency or an ЕРС20 token

isStable

A flag indicating that the cryptocurrency is a stablecoin used in cross-chain swaps.

chainFromId

The network identifier the sToken was received from

icons

A list of icons for the cryptocurrency

userToken

A flag indicating that the cryptocurrency was added manually by a user.

export class Token {
   ....

    /**
     * Constructs an instance of the base class `Token`.
     * @param params TokenConstructor
     */
    constructor(params: TokenConstructor) {
        validateSolidityTypeInstance(JSBI.BigInt(params.decimals), SolidityType.uint8)

        this.decimals = params.decimals
        this.symbol = params.symbol
        this.name = params.name
        this.chainId = params.chainId
        this.address = validateAndParseAddress(params.address)
        this.isNative = !!params.isNative
        this.icons = params.icons
        this.chainFromId = params.chainFromId
        this.isStable = params.isStable
        this.userToken = params.userToken
    }
    ...
}
export class TokenAmount extends Fraction {

    ...

    public constructor(token: Token, amount: BigintIsh) {
        const parsedAmount = parseBigintIsh(amount)
        validateSolidityTypeInstance(parsedAmount, SolidityType.uint256)

        super(parsedAmount, JSBI.exponentiate(TEN, JSBI.BigInt(token.decimals)))
        this.token = token

    }

    ...
}

PendingRequestState and PendingRequest types

PendingRequestState and PendingRequest types are used for reverting stuck cross-chain operations.

An explanation of reverting cross-chain operations: Symbiosis & Emergencies

enum PendingRequestState {
    Default = 0,
    Reverted,
}

export type PendingRequestType = 'burn' | 'synthesize'

export interface PendingRequest {
    fromTokenAmount: TokenAmount
    transactionHash: string
    state: PendingRequestState
    internalId: string
    externalId: string
    type: PendingRequestType
    from: string
    to: string
    revertableAddress: string
    chainIdFrom: ChainId
    chainIdTo: ChainId
    revertChainId: ChainId
}
PropertyDescription

fromTokenAmount

The amount of tokens that were in the stuck cross-chain operation.

transactionHash

The hash of the stuck transaction

state

The state of the revert:

  1. Default means there was no attempt to revert the operation,

  2. Reverted means there was an attempt to revert the operation.

internalId

The internal identifier of the cross-chain operation. The identifier of the minting/burning request is calculated without the destination network id, the recipient contract address (Portal or Synthesis), and the address that can perform a revert.

internalID = keccak256(
                abi.encodePacked(this, requestCount, block.chainid)
            );

externalId

The external identifier of the cross-chain operation. The identifier is derived from the internalId and calculated together with the destination network id, the destination contract address, and the address that can perform a revert.

externalID = keccak256(abi.encodePacked(internalID, _receiveSide, _revertableAddress, _chainID)

type

The type of the operation:

  1. burn means that the operation burns sTokens,

  2. synthesize means that the operation mints sTokens.

from

The sender's address

to

The recipient's address

revertableAddress

The address which can revert the operation

chainIdFrom

The identifier of the source blockchain

chainIdTo

The identifier of the destination blockchain

revertChainId

The identifier of the blockchain to send revert transaction

Last updated