Skip to content

Instantly share code, notes, and snippets.

@transferAndCall
Last active October 7, 2020 19:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save transferAndCall/6069874218d6da36e90cd3442e9e8f4c to your computer and use it in GitHub Desktop.
Save transferAndCall/6069874218d6da36e90cd3442e9e8f4c to your computer and use it in GitHub Desktop.
Get information on the yaLINK vault

yaLINK Vault Info

Setup

virtualenv venv
source venv/bin/activate
pip install web3

read.py

Set the environment variable RPC_URL to a mainnet JSONRPC provider URL

Run the following command, replacing "youraddress" with your actual address

The script can also be ran without a "youraddress"

python read.py youraddress

harvest.py

Run ganache-cli with a fork of mainnet, unlocking the Yearn: Deployer's address

Replace PROJECT_ID with your Infura project ID

ganache-cli --fork https://mainnet.infura.io/v3/PROJECT_ID --unlock 0x2d407ddb06311396fe14d4b49da5f0471447d45c

Then run the following command

python harvest.py
import os
import json
import sys
from web3 import Web3
yearn_deployer = '0x2D407dDb06311396fE14D4b49da5F0471447d45C'
yalink_vault_address = '0x29E240CFD7946BA20895a7a02eDb25C210f9f324'
yalink_vault_abi = [ { "constant": "true", "inputs": [], "name": "balance", "outputs": [ { "internalType": "uint256", "name": "", "type": "uint256" } ], "payable": "false", "stateMutability": "view", "type": "function" }, { "constant": "true", "inputs": [ { "internalType": "address", "name": "account", "type": "address" } ], "name": "balanceOf", "outputs": [ { "internalType": "uint256", "name": "", "type": "uint256" } ], "payable": "false", "stateMutability": "view", "type": "function" }, { "constant": "true", "inputs": [], "name": "getPricePerFullShare", "outputs": [ { "internalType": "uint256", "name": "", "type": "uint256" } ], "payable": "false", "stateMutability": "view", "type": "function" }, { "constant": "true", "inputs": [], "name": "locked", "outputs": [ { "internalType": "uint256", "name": "", "type": "uint256" } ], "payable": "false", "stateMutability": "view", "type": "function" }, { "constant": "true", "inputs": [ { "internalType": "address", "name": "account", "type": "address" } ], "name": "maxWithdrawal", "outputs": [ { "internalType": "uint256", "name": "", "type": "uint256" } ], "payable": "false", "stateMutability": "view", "type": "function" }, { "constant": "true", "inputs": [], "name": "totalSupply", "outputs": [ { "internalType": "uint256", "name": "", "type": "uint256" } ], "payable": "false", "stateMutability": "view", "type": "function" } ]
delegated_controller_address = '0x2be5D998C95DE70D9A38b3d78e49751F10F9E88b'
delegated_controller_abi = [ { "constant": "true", "inputs": [ { "internalType": "address", "name": "_vault", "type": "address" } ], "name": "want", "outputs": [ { "internalType": "address", "name": "", "type": "address" } ], "payable": "false", "stateMutability": "view", "type": "function" }, { "constant": "false", "inputs": [ { "internalType": "address", "name": "_strategy", "type": "address" }, { "internalType": "uint256", "name": "parts", "type": "uint256" } ], "name": "delegatedHarvest", "outputs": [], "payable": "false", "stateMutability": "nonpayable", "type": "function" } ]
controller_address = '0x9E65Ad11b299CA0Abefc2799dDB6314Ef2d91080'
controller_abi = [ { "constant": "false", "inputs": [ { "internalType": "address", "name": "_strategy", "type": "address" }, { "internalType": "address", "name": "_token", "type": "address" }, { "internalType": "uint256", "name": "parts", "type": "uint256" } ], "name": "yearn", "outputs": [], "payable": "false", "stateMutability": "nonpayable", "type": "function" } ]
usdc_strategy_address = '0xA30d1D98C502378ad61Fe71BcDc3a808CF60b897'
usdc_strategy_abi = [ { "constant": "false", "inputs": [], "name": "harvest", "outputs": [], "payable": "false", "stateMutability": "nonpayable", "type": "function" }, ]
w3 = Web3(Web3.HTTPProvider('http://localhost:8545'))
def load_controller():
return w3.eth.contract(abi=controller_abi, address=controller_address)
def load_delegated_controller():
return w3.eth.contract(abi=delegated_controller_abi, address=delegated_controller_address)
def load_yalink_vault():
return w3.eth.contract(abi=yalink_vault_abi, address=yalink_vault_address)
def load_usdc_strategy():
return w3.eth.contract(abi=usdc_strategy_abi, address=usdc_strategy_address)
def main():
w3.eth.defaultAccount = yearn_deployer
print('Harvesting crops...')
usdc_strategy_contract = load_usdc_strategy()
controller_contract = load_controller()
delegated_controller_contract = load_delegated_controller()
yalink_vault_contract = load_yalink_vault()
rate_before = yalink_vault_contract.functions.getPricePerFullShare().call()
print('Calling harvest on the USDC strategy...')
txhash_harvest_usdc = usdc_strategy_contract.functions.harvest().transact()
w3.eth.waitForTransactionReceipt(txhash_harvest_usdc)
print('Calling yearn on the controller...')
txhash_yearn = controller_contract.functions.yearn('0xA30d1D98C502378ad61Fe71BcDc3a808CF60b897', '0x1f9840a85d5aF5bf1D1762F925BDADdC4201F984', 1).transact()
w3.eth.waitForTransactionReceipt(txhash_yearn)
print('Calling delegatedHarvest on the yaLINK vault...')
txhash_harvest = delegated_controller_contract.functions.delegatedHarvest('0x25fAcA21dd2Ad7eDB3a027d543e617496820d8d6', 1).transact()
w3.eth.waitForTransactionReceipt(txhash_harvest)
rate_after = yalink_vault_contract.functions.getPricePerFullShare().call()
print(f'Rate Before:\t{rate_before}')
print(f'Rate After:\t{rate_after}')
increase = rate_after - rate_before
percent = increase / rate_before * 100
print(f'Increase:\t{percent:.18f}%')
if __name__ == '__main__':
main()
import os
import json
import sys
from web3 import Web3
vault_address = '0x29E240CFD7946BA20895a7a02eDb25C210f9f324'
vault_abi = [ { "constant": "true", "inputs": [], "name": "balance", "outputs": [ { "internalType": "uint256", "name": "", "type": "uint256" } ], "payable": "false", "stateMutability": "view", "type": "function" }, { "constant": "true", "inputs": [ { "internalType": "address", "name": "account", "type": "address" } ], "name": "balanceOf", "outputs": [ { "internalType": "uint256", "name": "", "type": "uint256" } ], "payable": "false", "stateMutability": "view", "type": "function" }, { "constant": "true", "inputs": [], "name": "getPricePerFullShare", "outputs": [ { "internalType": "uint256", "name": "", "type": "uint256" } ], "payable": "false", "stateMutability": "view", "type": "function" }, { "constant": "true", "inputs": [], "name": "locked", "outputs": [ { "internalType": "uint256", "name": "", "type": "uint256" } ], "payable": "false", "stateMutability": "view", "type": "function" }, { "constant": "true", "inputs": [ { "internalType": "address", "name": "account", "type": "address" } ], "name": "maxWithdrawal", "outputs": [ { "internalType": "uint256", "name": "", "type": "uint256" } ], "payable": "false", "stateMutability": "view", "type": "function" }, { "constant": "true", "inputs": [], "name": "totalSupply", "outputs": [ { "internalType": "uint256", "name": "", "type": "uint256" } ], "payable": "false", "stateMutability": "view", "type": "function" } ]
controller_address = '0x2be5D998C95DE70D9A38b3d78e49751F10F9E88b'
controller_abi = [ { "constant": "true", "inputs": [ { "internalType": "address", "name": "_vault", "type": "address" } ], "name": "want", "outputs": [ { "internalType": "address", "name": "", "type": "address" } ], "payable": "false", "stateMutability": "view", "type": "function" } ]
aave_address = '0x24a42fD28C976A61Df5D00D0599C34c4f90748c8'
aave_abi = [ { "constant": "true", "inputs": [], "name": "getLendingPool", "outputs": [ { "internalType": "address", "name": "", "type": "address" } ], "payable": "false", "stateMutability": "view", "type": "function" } ]
lending_pool_abi = [ { "constant": "true", "inputs": [ { "internalType": "address", "name": "_user", "type": "address" } ], "name": "getUserAccountData", "outputs": [ { "internalType": "uint256", "name": "totalLiquidityETH", "type": "uint256" }, { "internalType": "uint256", "name": "totalCollateralETH", "type": "uint256" }, { "internalType": "uint256", "name": "totalBorrowsETH", "type": "uint256" }, { "internalType": "uint256", "name": "totalFeesETH", "type": "uint256" }, { "internalType": "uint256", "name": "availableBorrowsETH", "type": "uint256" }, { "internalType": "uint256", "name": "currentLiquidationThreshold", "type": "uint256" }, { "internalType": "uint256", "name": "ltv", "type": "uint256" }, { "internalType": "uint256", "name": "healthFactor", "type": "uint256" } ], "payable": "false", "stateMutability": "view", "type": "function" } ]
one = 1e18
RPC_URL = os.getenv('RPC_URL')
w3 = Web3(Web3.HTTPProvider(RPC_URL))
def load_controller():
return w3.eth.contract(abi=controller_abi, address=controller_address)
def load_aave():
return w3.eth.contract(abi=aave_abi, address=aave_address)
def load_lending_pool(lending_pool):
return w3.eth.contract(abi=lending_pool_abi, address=lending_pool)
def load_vault():
return w3.eth.contract(abi=vault_abi, address=vault_address)
def main():
controller_contract = load_controller()
want = controller_contract.functions.want(vault_address).call()
aave_contract = load_aave()
lending_pool = aave_contract.functions.getLendingPool().call()
lending_pool_contract = load_lending_pool(lending_pool)
account_data = lending_pool_contract.functions.getUserAccountData(vault_address).call()
print(f'Health factor:\t\t{account_data[7] / one}')
vault_contract = load_vault()
vault_balance = vault_contract.functions.balance().call()
print(f'Vault balance:\t\t{vault_balance / one}')
total_supply = vault_contract.functions.totalSupply().call()
print(f'Vault supply:\t\t{total_supply / one}')
rate = vault_contract.functions.getPricePerFullShare().call()
locked = vault_contract.functions.locked().call()
print(f'Percent locked:\t\t{locked / one}')
print(f'Current yaLINK rate:\t{rate / one}')
if (len(sys.argv) > 1):
my_balance = vault_contract.functions.balanceOf(str(sys.argv[1])).call()
print(f'My balance (yaLINK):\t{my_balance / one}')
can_withdraw = rate / one * my_balance / one
can_withdraw_yalink = vault_contract.functions.maxWithdrawal(str(sys.argv[1])).call()
print(f'Can withdraw (yaLINK):\t{can_withdraw_yalink / one}')
print(f'Can withdraw (aLINK):\t{can_withdraw}')
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment