I'm working on a personal project which tracks data of BTC token pairs. I'd like to do the same with BNB and liquidity tokens but I'm very ignorant about this subject. I'd like to know what's a specific token liquidity so I'm able to track that data. Is there any source I can find this information?
3 Answers
Yes, you can track the liquidity of pairs on Binance Smart Chain(bsc) dexs. Since many of the bsc dexs like pancakeswap have very similar contracts as uniswap on ethereum you can follow along with the tutorial linked below to get a really good understanding of how pairs work in uniswap/pancakeswap contracts.
https://vomtom.at/how-to-use-uniswap-v2-as-a-developer/
The simplest way to get this all started is to use metamask, web3, geth or infura and some kind of IDE like Atom. You will have to change some settings on metamask to connect to BSC.The only real difference between tracking liquidity with uniswap versus many dexs on BSC are the addresses.
If you are able to understand the tutorial you will have enough knowledge to understand how you would track liquidity of BSC Pancake token pairs or Ethereum uniswap token pairs. By the way both have their own version of BNB tokens.
https://academy.binance.com/en/articles/how-to-get-started-with-binance-smart-chain-bsc
https://web3js.readthedocs.io/en/v1.2.11/getting-started.html
https://docs.binance.org/smart-chain/developer/fullnode.html
-
Thanks for the response Julian. I'm already using web3.py and I'm somewhat familiar with how to deploy smart contracts. Thank you for your response, I'll be reading the article once I get home, I'm assuming the calculation I've to do in order to get liquidity uses some of BNB, X (token) & Pancakeswap data? Sorry for my bad english! Commented Apr 30, 2021 at 16:30
-
1Thank you for your response, I learned so much from the article! Commented May 4, 2021 at 13:40
-
-
This answer does answer how to track liquidity. It just describes how to query data from blockchain. A helpful answer would provide examples of contracts that describe LP pairs, show how to query, how to get ratio in the pool, and how to determine value of each pool in ETH.– GajusCommented May 20, 2021 at 0:53
-
I am happy to contribute an answer too. Just stumbled upon this while looking for additional validation about polling liquidity.– GajusCommented May 20, 2021 at 0:54
This isn't a complete answer, since the final result does not match what I expect it to be, but the basic logic is as follows:
Let's use this contract as an example:
0x2A9718defF471f3Bb91FA0ECEAB14154F150a385
At the time of writing, BoggedFinance says that the liquidity of the token is $14,125,954. And the accompanying note states:
Liquidity includes both ElonGate and BNB value from LP total
As I type this, I discovered that BoggedFinance provides a detail breakdown of LP:
ElonGate - BNB LP PancakeSwap V1 One LP is worth $556.758 1,498,788,818.175 ElonGate + 0.890 BNB
Liquidity Pool Totals Pool adds $10,509,932.851 to total liquidity
ElonGate pooled: 28,292,667,705,973.550
BNB pooled: 16,803.212
Total LP Tokens: 18,877.021
ElonGate - BUSD LP PancakeSwap V1 One LP is worth $52.411 140,320,177.619 ElonGate + 26.206 BUSD
Liquidity Pool Totals Pool adds $88.507 to total liquidity
ElonGate pooled: 236,957,969.712
BUSD pooled: 44.253
Total LP Tokens: 1.689
ElonGate - BNB LP PancakeSwap V2 One LP is worth $4,711.863 12,878,292,502.135 ElonGate + 7.533 BNB
Liquidity Pool Totals Pool adds $3,684,693.138 to total liquidity
ElonGate pooled: 10,070,868,300,296.424
BNB pooled: 5,891.063
Total LP Tokens: 782.003
ElonGate - BUSD LP PancakeSwap V2 One LP is worth $43.974 94,155,951.896 ElonGate + 21.987 BUSD
Liquidity Pool Totals Pool adds $15.409 to total liquidity
ElonGate pooled: 32,993,962.665
BUSD pooled: 7.705
Total LP Tokens: 0.350
This helpful.
Let's break this down, starting with PancakeSwap V1:
ElonGate - BNB LP PancakeSwap V1 One LP is worth $556.758 1,498,788,818.175 ElonGate + 0.890 BNB
Liquidity Pool Totals Pool adds $10,509,932.851 to total liquidity
ElonGate pooled: 28,292,667,705,973.550
BNB pooled: 16,803.212
Total LP Tokens: 18,877.021
This says that LP is added from PancakeSwap pair that holds ElongGate/BNB.
As far as I understand, the way to find the pair is:
- find individual contract addresses (ElongGate, WBNB)
- calculate pair address
How does one do #2? Uniswap documentation describes a method using hash of two contract addresses. However, it is not clear how that works now that we have v1 and v2 pairs.
In this case, I figured out addresses by analyzing transactions using BoggedTools.
We are interested in v1, so let's stick with that.
I think we should be looking at the getReserves
values. In this case these are:
_reserve0 uint112, _reserve1 uint112, _blockTimestampLast uint32
_reserve0|uint112 : 28275429447945283354076
_reserve1|uint112 : 16813513482151690059189
_blockTimestampLast|uint32 : 1621474820
As far as I understand, these values represent how much liquidity has been added to the contract. In this case, _reserve0
represents ElonGate and _reserve1
represents WBNB. The ratio of these values represents tokens price, i.e.
(28275429447945283354076/10^9) / (16813513482151690059189/10^18)
= 1,681,708,554.13182609680802084772
A quick check back with BoggedTools confirms this:
ElonGate/BNB: 1681713503.587
The reserve in this case also represents liquidity, i.e. it says that this pool consists of:
- WBNB 16,814 (16813513482151690059189/10^18) (16,814 * 427.17 = USD ~7.4M)
- ElonGate 28T (28T*0.000000195156 = 5,518,119.70934320971824805586 = USD ~5.5)
The total therefore should be USD 12.9. This number does not entirely align with what BoggedFinance suggests though:
Pool adds $10,509,932.851 to total liquidity.
There is some logic problem in this, and I suspect it is in the last step. However, this should give a head start to whoever is just starting to analyze how DEX function.
Trading Strategy protocol (disclaimer: I'm affiliated with this site) provides historical APIs and real time APIs for tracking liquidity. Binance Smart Chain will be added soon.