Last active
June 24, 2021 16:35
-
-
Save AlecSchneider/106c71f59b826923d21b66981cf8112b to your computer and use it in GitHub Desktop.
Get your AVAX and PNG balance in YieldYak AVAX-PNG Pair
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from web3 import Web3 | |
import requests | |
YOUR_C_CHAIN_ADDRESS = "" | |
# Get the ABI from somewhere like here: https://cchain.explorer.avax.network/address/0xA544b965C2a05b97C44f3126cec916332aFb3175/contracts | |
YAK_ABI = "" | |
ERC20_ABI = "" | |
w3 = Web3(Web3.HTTPProvider("https://api.avax.network/ext/bc/C/rpc")) | |
# YAK YIELD: https://cchain.explorer.avax.network/address/0xA544b965C2a05b97C44f3126cec916332aFb3175/transactions | |
token_address = "0xA544b965C2a05b97C44f3126cec916332aFb3175" | |
token = w3.eth.contract(address=token_address, abi=YAK_ABI) | |
token_balance = token.functions.balanceOf(YOUR_C_CHAIN_ADDRESS).call() | |
totalDeposits = token.functions.totalDeposits().call() | |
totalSupply = token.functions.totalSupply().call() | |
liquidity_tokens = (token_balance / 10**18) * \ | |
totalDeposits / totalSupply | |
liquidity_token_address = token.functions.depositToken().call() | |
token = w3.eth.contract(address=liquidity_token_address, abi=LIQUIDITY_ABI) | |
totalSupply = token.functions.totalSupply().call() | |
token0 = token.functions.token0().call() | |
token1 = token.functions.token1().call() | |
token = w3.eth.contract(address=token0, abi=ERC20_ABI) | |
token0_balance = token.functions.balanceOf( | |
liquidity_token_address | |
).call() | |
token = w3.eth.contract(address=token1, abi=ERC20_ABI) | |
token1_balance = token.functions.balanceOf( | |
liquidity_token_address | |
).call() | |
png_amount = liquidity_tokens * token0_balance / totalSupply | |
avax_amount = liquidity_tokens * token1_balance / totalSupply | |
print(png_amount, avax_amount) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment