Skip to content

Instantly share code, notes, and snippets.

@AlecSchneider
Last active June 24, 2021 16:35
Show Gist options
  • Save AlecSchneider/106c71f59b826923d21b66981cf8112b to your computer and use it in GitHub Desktop.
Save AlecSchneider/106c71f59b826923d21b66981cf8112b to your computer and use it in GitHub Desktop.
Get your AVAX and PNG balance in YieldYak AVAX-PNG Pair
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