简体   繁体   English

web3.py 查看流动性池余额

[英]Web3.py check liquidity pool balance

I'm trying to compute the balance of a lp address given the address of the token.我正在尝试计算给定令牌地址的 lp 地址的余额。 So I have this function:所以我有这个 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)

Only problem that this returns me 0... for every contract I tried.唯一的问题是,对于我尝试过的每份合同,这都会返回 0...。 I also manually checked on bsc scan the wbnb balance in the pool and is not 0. Can someone help me please?我还手动检查了 bsc 扫描池中的 wbnb 余额,但不是 0。有人可以帮我吗?

There is an example in Web3 Ethereum Defi package . 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

See full example . 请参阅完整示例

"That's how I ended up doing it yesterday. But I can't understand why web3.eth.get_balance() works fine with wallet addresses and not with LP addresses. " “我昨天就是这样做的。但我不明白为什么 web3.eth.get_balance() 可以很好地处理钱包地址而不是 LP 地址。”

Because the pair holds WETH not ETH.因为该货币对持有 WETH 而不是 ETH。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM