Skip to content

Instantly share code, notes, and snippets.

@kx9x
Last active November 5, 2020 16:18
Show Gist options
  • Save kx9x/1d99fd2ad97b17f3d099b3be14486055 to your computer and use it in GitHub Desktop.
Save kx9x/1d99fd2ad97b17f3d099b3be14486055 to your computer and use it in GitHub Desktop.
Some quick example scripts that show how one can script against yearn vaults using eth-brownie
import settings
from web3.auto.infura import w3
from brownie import Contract, network
import datetime
import time
from win10toast import ToastNotifier
# This script will show pending Crv to be harvested in the crvBusd vault
# It will also show your share of the pending award if you supply your address in
# the 'me' variable below
if not w3.isConnected():
print("w3 is not connected... uh oh")
exit()
network.connect('mainnet')
print(network.is_connected())
print(network.show_active())
busd_crv_gauge = Contract.from_explorer('0x69fb7c45726cfe2badee8317005d3f94be838840')
busd_crv_vault = Contract.from_explorer('0x2994529c0652d127b7842094103715ec5299bbed')
voter = Contract.from_explorer('0xF147b8125d2ef93FB6965Db97D6746952a133934')
toaster = ToastNotifier()
toaster.show_toast(settings.ARB_BOT_TOAST_NAME, "bot started")
# This is your address where you hold yCrvBusd
me = ''
if (me == ''):
toaster.show_toast('Warning: set your address in the script if you want to see your share')
last_crv_pending = 0
my_last_share_of_crv = 0
my_last_ratio = 0
while(True):
busd_crv_in_vault = busd_crv_vault.balance().to('ether')
my_balance = 0 if me == '' else busd_crv_vault.balanceOf(me).to('ether')
crv_pending = busd_crv_gauge.claimable_tokens.call(voter).to('ether')
ratio = my_balance / busd_crv_in_vault
crv_share = ratio * crv_pending
if (crv_pending < last_crv_pending):
toaster.show_toast(settings.ARB_BOT_TOAST_NAME, "crbBusd harvested {0} crv!".format(last_crv_pending))
if (ratio.real < float(my_last_ratio) * 0.99):
toaster.show_toast(settings.ARB_BOT_TOAST_NAME, "Ratio went down to {0}!".format(ratio))
if (crv_share.real < float(my_last_share_of_crv.real) * 0.99):
toaster.show_toast(settings.ARB_BOT_TOAST_NAME, "Crv share went down to {0}!".format(crv_share))
last_crv_pending = crv_pending
my_last_share_of_crv = crv_share
my_last_ratio = ratio
print(datetime.datetime.now())
print("\tPending crv: {0}".format(crv_pending))
print("\t\tMy share of vault: {0}".format(ratio))
print("\t\tMy share of crv: {0}".format(ratio * crv_pending))
time.sleep(60)

Use python 3.8 on Windows

Download all these files to the same directoy on your machine

Go to settings.py and follow the instructions to get an Etherscan API key and an Infura project set up. Brownie requires an infura project to access an Ethereum node for the latest blockchain data. Brownie also requires an etherscan API to download smart contracts when calling Contract.from_explorer(contract_address).

Install and run instructions pip install -r requirements.txt python sbtc_withdraw.py

Copyright 2020 Jesse Liston
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
apipkg==1.5
appdirs==1.4.4
argcomplete==1.12.1
atomicwrites==1.4.0
attrs==20.2.0
base58==2.0.1
bitarray==1.2.2
black==19.10b0
certifi==2020.6.20
chardet==3.0.4
click==7.1.2
colorama==0.4.3
cytoolz==0.11.0
eth-abi==2.1.1
eth-account==0.5.2
eth-brownie==1.11.7
eth-event==1.2.0
eth-hash==0.2.0
eth-keyfile==0.5.1
eth-keys==0.3.3
eth-rlp==0.2.0
eth-typing==2.2.2
eth-utils==1.9.5
execnet==1.7.1
hexbytes==0.2.1
hypothesis==5.35.0
idna==2.10
inflection==0.5.0
iniconfig==1.0.1
ipfshttpclient==0.6.1
jsonschema==3.2.0
lru-dict==1.1.6
more-itertools==8.5.0
multiaddr==0.0.9
mythx-models==1.9.1
netaddr==0.8.0
packaging==20.4
parsimonious==0.8.1
pathspec==0.8.0
pipx==0.15.5.1
pluggy==0.13.1
prompt-toolkit==3.0.7
protobuf==3.13.0
psutil==5.7.2
py==1.9.0
py-solc-ast==1.2.5
py-solc-x==1.0.0
pycryptodome==3.9.8
Pygments==2.6.1
pygments-lexer-solidity==0.5.1
PyJWT==1.7.1
pyparsing==2.4.7
pypiwin32==223
pyrsistent==0.17.3
pytest==6.0.1
pytest-forked==1.3.0
pytest-xdist==1.34.0
python-dateutil==2.8.1
pythx==1.6.1
pywin32==228
PyYAML==5.3.1
regex==2020.9.27
requests==2.24.0
rlp==1.2.0
rusty-rlp==0.1.15
semantic-version==2.8.5
six==1.15.0
sortedcontainers==2.2.2
toml==0.10.1
toolz==0.11.1
tqdm==4.48.2
typed-ast==1.4.1
urllib3==1.25.10
userpath==1.4.1
varint==1.0.2
vvm==0.0.2
wcwidth==0.2.5
web3==5.11.1
websockets==8.1
win10toast==0.9
import settings
from web3.auto.infura import w3
from brownie import Contract, network
import time
import datetime
from win10toast import ToastNotifier
# This script will send a windows 10 notification if
# the sbtc vault gets any sbtc that can be withdrawn for free
if not w3.isConnected():
print("w3 is not connected... uh oh")
exit()
network.connect('mainnet')
print(network.is_connected())
print(network.show_active())
sbtc_strat = Contract.from_explorer('0x6D6c1AD13A5000148Aa087E7CbFb53D402c81341')
sbtc_vault = Contract.from_explorer('0x7Ff566E1d69DEfF32a7b244aE7276b9f90e9D0f6')
toaster = ToastNotifier()
toaster.show_toast(settings.ARB_BOT_TOAST_NAME, "bot started")
last_sbtc_not_deposited = 0
while(True):
sbtc_in_vault = sbtc_vault.balance().to('ether')
sbtc_in_strat = sbtc_strat.balanceOf().to('ether')
sbtc_not_deposited = sbtc_in_vault - sbtc_in_strat
if (sbtc_not_deposited != last_sbtc_not_deposited):
toaster.show_toast(settings.ARB_BOT_TOAST_NAME, "sbtc to withdraw for free {0}!".format(sbtc_not_deposited))
last_sbtc_not_deposited = sbtc_not_deposited
print(datetime.datetime.now())
print("\tsbtc in vault: {:.4f}".format(sbtc_in_vault))
print("\tsbtc in strat: {:.4f}".format(sbtc_in_strat))
print("\t\t withdraw {:.4f} for free".format(sbtc_not_deposited))
print()
time.sleep(60)
import os
ARB_BOT_TOAST_NAME = "Your bot name here"
# You need to get an etherscan api token and a infura secret project id
# For the etherscan token: https://etherscan.io/apis
# For the infura project: https://infura.io/
# Sign up for both and fill in the relevant details below
settings_dict = { 'ETHERSCAN_TOKEN': '', 'WEB3_INFURA_API_SECRET': '', 'WEB3_INFURA_PROJECT_ID': '' }
# Eth brownie needs some environment variables, so this settings file will create those for you,
# just supply the values in the dictionary above
for setting in settings_dict.keys():
if setting not in os.environ:
os.environ[setting] = settings_dict[setting]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment