MarketLens
The sdk instance used by the lens.
The raw web3 contract instance for the lens.
Contract address of the lens.
Type:
string
Returns the number of pools in a directory.
Parameters:
directory: string
- Address of the pool directory.
Returns:
string
Returns the list of all assets in the pool.
Parameters:
Returns summary of the pool.
Parameters:
Returns:
Promise<{
totalSupply: BN,
totalBorrow: BN
underlyingTokens: string[],
underlyingSymbols:: string[]
}>
Returns summary of a user of the given pool.
Parameters:
account: string
- The user address to get the summary of.
Returns:
Promise<{
supplyBalance: BN,
borrowBalance: BN
}>
Returns a list of all users with health under
maxHealth
for the given pool.Parameters:
maxHealth:: number | string | BN
- Max health of the users.
Returns:
Promise<[
PoolUser[],
BN,
BN,
]>
Returns a list of all public pools inside the directory.
Parameters:
directory: string
- Pool directory of the pools.
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);
Returns the address of wrapped native token of the network.
Parameters:
Returns:
string
Last modified 1yr ago