|
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() |