Getting the pool from the token

Function Signature

function getPoolFromToken(xfai: Xfai, token: Token): Pool

Description

The getPoolFromToken function takes in a Token object and returns a Pool object both are Address objects. The pool address return, doesn't necessarily mean that the pool exists, If the Token is the native chain token it returns the Wrapped native chain token Pool.

Parameters

  • xfai: The xfai class

  • token: The token object

Example Usage

import { Token, getPoolFromToken, getPoolState, Xfai} from '@xfai-labs/sdk';

// initialize the Xfai Object
const xfai = new Xfai(...);


// Get the pool that holds the usdc token
const pool = getPoolFromToken(xfai, Token('0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48'));

const poolAddress = pool.address;

// Get the state of the pool
try{
    const {
        reserve,
        ethReserve
    } = await getPoolState(xfai, pool);
}catch(){
    // Pool doesn't exist;
}

Last updated