MarketLens

Properties
Methods

Properties

sdk

The sdk instance used by the lens.

Type: MarketSDK

contract

The raw web3 contract instance for the lens.

Type: web3.eth.Contract

address

Contract address of the lens.

Type: string

Methods

getAllPoolsLength

Returns the number of pools in a directory.

Parameters:

  • directory: string - Address of the pool directory.

Returns: string

getPoolAssetsWithData

Returns the list of all assets in the pool.

Parameters:

  • comptroller: Comptroller | string - The comptroller contract of the pool.

  • tx?: NonPayableTx - The transaction info object for making the transaction with.

Returns: Promise<PoolAsset[]>

getPoolSummary

Returns summary of the pool.

Parameters:

  • comptroller: Comptroller | string - The comptroller contract of the pool.

  • tx?: NonPayableTx - The transaction info object for making the transaction with.

Returns: Promise<{ totalSupply: BN, totalBorrow: BN underlyingTokens: string[], underlyingSymbols:: string[] }>

getPoolUserSummary

Returns summary of a user of the given pool.

Parameters:

  • comptroller: Comptroller | string - The comptroller contract of the pool.

  • account: string - The user address to get the summary of.

  • tx?: NonPayableTx - The transaction info object for making the transaction with.

Returns: Promise<{ supplyBalance: BN, borrowBalance: BN }>

getPoolUsersWithData

Returns a list of all users with health under maxHealth for the given pool.

Parameters:

  • comptroller: Comptroller | string - The comptroller contract of the pool.

  • maxHealth:: number | string | BN - Max health of the users.

  • tx?: NonPayableTx - The transaction info object for making the transaction with.

Returns: Promise<[ PoolUser[], BN, BN, ]>

getPublicPoolsWithData

Returns a list of all public pools inside the directory.

Parameters:

  • directory: string - Pool directory of the pools.

  • tx?: NonPayableTx - The transaction info object for making the transaction with.

Returns: Promise<{ indexes: BN[]; pools: Pool[]; totalSupply: BN[]; totalBorrow: BN[]; underlyingTokens: string[][]; underlyingSymbols: string[][]; errored: boolean[]; }>

// Fetch the TVL for a network
import Web3 from "web3";
import { MarketSDK, MarketOptions } from "market-sdk";

function getTVL(sdk: MarketSDK){
  const lens = new MarketLens(sdk, sdk.options!.marketLens);

  const { totalSupply: totalSuppliedETH } =
    await lens.getPublicPoolsWithData(sdk.options!.poolDirectory, {
      gas: 1e18,
    });
  
  const tvlETH = 
    totalSuppliedETH
      .reduce((a: BN, b: BN) => a.add(b), Web3.utils.toBN(0))
  
  const ethPrice: number = await getEthUsdPrice();
  const tvl = (parseInt(tvlETH.toString()) / 1e18) * ethPrice;
  
  return tvl;
}

const options: MarketOptions = {
  poolDirectory: "SET_DIRECTORY_ADDRESS",
  marketLens: "SET_MARKET_LENS_ADDRESS"
};

const web3 = new Web3("SET_RPC_OR_PROVIDER");
const sdk = await MarketSDK.init(web3, options);
const tvl = await getTVL(sdk);

const chainId = await sdk.web3.eth.getChainId();
console.log(`TVL on network ${chainId}`, tvl);

wrappedNative

Returns the address of wrapped native token of the network.

Parameters:

  • tx?: NonPayableTx - The transaction info object for making the transaction with.

Returns: string

Last updated