簡體   English   中英

web3.py 查看流動性池余額

[英]Web3.py check liquidity pool balance

我正在嘗試計算給定令牌地址的 lp 地址的余額。 所以我有這個 function:

web3 = Web3(Web3.HTTPProvider("https://bsc-dataseed.binance.org/"))

def CheckLiquidity(TokenAddress, web3):
   LPAddress = GetLiquidityAddress(TokenAddress) #returns the web3.toChecksumAddress()
   balance = web3.eth.get_balance(LPAddress)
   bnbBalance = web3.fromWei(balance, 'ether)

唯一的問題是,對於我嘗試過的每份合同,這都會返回 0...。 我還手動檢查了 bsc 掃描池中的 wbnb 余額,但不是 0。有人可以幫我嗎?

Web3 Ethereum Defi package中有一個例子。

    pair = get_deployed_contract(web3, "UniswapV2Pair.json", pair_address)
    token_a, token_b, timestamp = pair.functions.getReserves().call()

    # Check we got the liquidity
    assert token_a == 10 * 10**18
    assert token_b == 17_000 * 10**18

請參閱完整示例

“我昨天就是這樣做的。但我不明白為什么 web3.eth.get_balance() 可以很好地處理錢包地址而不是 LP 地址。”

因為該貨幣對持有 WETH 而不是 ETH。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM