Find Total liquidity for particular Pair in UniswapV2 Blockchain

Viewed 991

I am looking at UniswapV2 data for particular pair on their website and found total liquidity there, https://info.uniswap.org/pair/0xbb2b8038a1640196fbe3e38816f3e67cba72d940

under Pair Stats, now How this total liquidity is calculated for particular pair, Given that we have liquidity for pair for each day, also I tried it summing up all liquidity but that doesn't work. So I want a certain formula for how to calculate a particular pair total liquidity

2 Answers

Use getLiquidityValue from the uniswap SDK

getLiquidityValue(
  token: Token,
  totalSupply: TokenAmount,
  liquidity: TokenAmount,
  feeOn: boolean = false,
  kLast?: BigintIsh
): TokenAmount

Source

If you want total liquidity in USD. get the reserves from the pair contract by calling getpair(address1, address2) from the factory contract and then with the pair contract call getReserves().

If the pair is, for example WFTM/LUCHOW, you want to get the USD value of both and multiply them by their respective reserves. Then Add the two values.

ie: (Pseudo code)

pair = factory.getPair(WFTM, LUCHOW)
pair_contract = new ethers.contract(pair, abi, wallet)
reserves = pair_contract.getReserves()
total liquidity = (reserves[0] * usdtprice) + (reserves[1] * usdtprice)
Related