Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor chain references into enum #116

Merged
merged 6 commits into from
Nov 10, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions .deploy/base/flashbots_harvester.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@ spec:
- name: flashbots-harvester-keeper
image: IMAGE_NAME
imagePullPolicy: IfNotPresent
command: ["python", "scripts/harvest_cvx.py"]
#command: ["python", "scripts/one_time_harvests.py"]
command: ["python", "scripts/harvest_eth.py"]
env:
- name: LOG_LEVEL
value: "info"
Expand Down
2 changes: 1 addition & 1 deletion .deploy/base/general_harvester.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ spec:
- name: general-harvester-keeper
image: IMAGE_NAME
imagePullPolicy: IfNotPresent
command: ["python", "scripts/general_harvest.py"]
command: ["python", "scripts/poly_harvest.py"]
env:
- name: LOG_LEVEL
value: 'info'
Expand Down
2 changes: 1 addition & 1 deletion .deploy/base/rebalancer.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ spec:
# cron to run at 4pm EST every day "0 20 * * *"
schedule: "10-59/5 20,21 * * *"
startingDeadlineSeconds: 180
suspend: false
suspend: true
shuklaayush marked this conversation as resolved.
Show resolved Hide resolved
jobTemplate:
spec:
template:
Expand Down
Empty file added config/__init__.py
Empty file.
33 changes: 30 additions & 3 deletions config/constants.py
Original file line number Diff line number Diff line change
@@ -1,25 +1,35 @@
import os
import sys

sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(__file__), "./")))

from enums import Network, Currency


ETH_BVECVX_STRATEGY = "0x3ff634ce65cDb8CC0D569D6d1697c41aa666cEA9"
ETH_RETIRED_CVX_STRATEGY = "0x87fB47c2B9EB41d362BAb44F5Ec81514b6b1de13"
ETH_TRICRYPTO_STRATEGY = "0x05eC4356e1acd89CC2d16adC7415c8c95E736AC1"
ETH_HARVEST_STRATEGY = "0xaaE82E3c89e15E6F26F60724f115d5012363e030"
ETH_UNI_DIGG_STRATEGY = "0xadc8d7322f2E284c1d9254170dbe311E9D3356cf"
ETH_BBADGER_STRATEGY = "0x75b8E21BD623012Efb3b69E1B562465A68944eE6"


ETH_BVECVX_VAULT = "0xfd05D3C7fe2924020620A8bE4961bBaA747e6305"
ETH_YVWBTC_VAULT = "0x4b92d19c11435614CD49Af1b589001b7c08cD4D5"
ETH_TRICRYPTO_VAULT = "0x27E98fC7d05f54E544d16F58C194C2D7ba71e3B5"
ETH_BVECVX_CVX_LP_VAULT = "0x937B8E917d0F36eDEBBA8E459C5FB16F3b315551"

ARB_SWAPR_WETH_STRATEGY = "0x85386C3cE0679b035a9F8F17f531C076d0b35954"

MULTICHAIN_CONFIG = {
"poly": {
Network.Polygon: {
"gas_oracle": "0xAB594600376Ec9fD91F8e885dADF0CE036862dE0",
"keeper_acl": "0x46fa8817624eea8052093eab8e3fdf0e2e0443b2",
"vault_owner": ["0xeE8b29AA52dD5fF2559da2C50b1887ADee257556"],
"registry": "0xFda7eB6f8b7a9e9fCFd348042ae675d1d652454f",
"earn": {"invalid_strategies": []},
},
"arbitrum": {
Network.Arbitrum: {
"gas_oracle": "0x639Fe6ab55C921f74e7fac1ee960C0B6293ba612",
"keeper_acl": "0x265820F3779f652f2a9857133fDEAf115b87db4B",
"vault_owner": [
Expand All @@ -33,7 +43,7 @@
"earn": {"invalid_strategies": []},
"harvest": {"invalid_strategies": []},
},
"eth": {
Network.Ethereum: {
"gas_oracle": "0x5f4eC3Df9cbd43714FE2740f5E3616155c5b8419",
"keeper_acl": "0x711A339c002386f9db409cA55b6A35a604aB6cF6",
"vault_owner": ["0xeE8b29AA52dD5fF2559da2C50b1887ADee257556"],
Expand All @@ -52,6 +62,23 @@
},
}

NODE_URL_SECRET_NAMES = {
Network.Ethereum: {"name": "quiknode/eth-node-url", "key": "NODE_URL"},
Network.Polygon: {"name": "quiknode/poly-node-url", "key": "NODE_URL"},
}

ABI_DIRS = {
Network.Ethereum: "eth",
Network.Polygon: "poly",
Network.Arbitrum: "arb",
}

BASE_CURRENCIES = {
Network.Ethereum: Currency.Eth,
Network.Arbitrum: Currency.Eth,
Network.Polygon: Currency.Matic,
}

EARN_PCT_THRESHOLD = 0.01
EARN_OVERRIDE_THRESHOLD = 10
SECONDS_IN_A_DAY = 60 * 60 * 24
Expand Down
10 changes: 10 additions & 0 deletions config/enums.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,13 @@ class Network(str, Enum):

def __str__(self):
return self.value


class Currency(str, Enum):
Eth = "eth"
Matic = "matic"
Usd = "usd"
Btc = "btc"

def __str__(self):
return self.value
10 changes: 3 additions & 7 deletions scripts/arbitrum_earn.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,9 @@
)

from earner import Earner
from utils import get_secret, get_strategies_and_vaults
from utils import get_secret, get_strategies_and_vaults, get_abi
from constants import MULTICHAIN_CONFIG
from enums import Network

logging.basicConfig(level=logging.INFO)
logger = logging.getLogger("script")
Expand All @@ -27,13 +28,8 @@ def safe_earn(earner, vault, strategy):
logger.error(f"Error running earn: {e}")


def get_abi(chain: str, contract_id: str):
with open(f"./abi/{chain}/{contract_id}.json") as f:
return json.load(f)


if __name__ == "__main__":
for chain in ["arbitrum"]:
for chain in [Network.Arbitrum]:
# node_url = get_secret("alchemy/arbitrum-node-url", "ARBITRUM_NODE_URL")
node_url = "https://arb1.arbitrum.io/rpc"
node = Web3(Web3.HTTPProvider(node_url))
Expand Down
11 changes: 6 additions & 5 deletions scripts/arbitrum_harvest.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
0, os.path.abspath(os.path.join(os.path.dirname(__file__), "../config"))
)

from enums import Network
from general_harvester import GeneralHarvester
from utils import get_abi, get_secret, get_strategies_from_registry
from constants import MULTICHAIN_CONFIG
Expand Down Expand Up @@ -60,21 +61,21 @@ def safe_harvest(harvester, strategy) -> str:

harvester = GeneralHarvester(
web3=web3,
chain="arbitrum",
keeper_acl=MULTICHAIN_CONFIG["arbitrum"]["keeper_acl"],
chain=Network.Arbitrum,
keeper_acl=MULTICHAIN_CONFIG[Network.Arbitrum]["keeper_acl"],
keeper_address=keeper_address,
keeper_key=keeper_key,
base_oracle_address=MULTICHAIN_CONFIG["arbitrum"]["gas_oracle"],
base_oracle_address=MULTICHAIN_CONFIG[Network.Arbitrum]["gas_oracle"],
use_flashbots=False,
discord_url=discord_url,
)

strategies = get_strategies_from_registry(web3, "arbitrum")
strategies = get_strategies_from_registry(web3, Network.Arbitrum)

for strategy in strategies:
if (
strategy.address
not in MULTICHAIN_CONFIG["arbitrum"]["harvest"]["invalid_strategies"]
not in MULTICHAIN_CONFIG[Network.Arbitrum]["harvest"]["invalid_strategies"]
):
safe_harvest(harvester, strategy)

Expand Down
11 changes: 6 additions & 5 deletions scripts/arbitrum_manual_harvest.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,9 @@
0, os.path.abspath(os.path.join(os.path.dirname(__file__), "../config"))
)

from enums import Network
from general_harvester import GeneralHarvester
from utils import get_abi, get_secret
from utils import get_abi, get_secret, get_node_url
from constants import MULTICHAIN_CONFIG

logging.basicConfig(level=logging.INFO)
Expand All @@ -36,7 +37,7 @@ def safe_harvest(harvester, strategy_name, strategy) -> str:
# Load secrets
keeper_key = get_secret("keepers/rebaser/keeper-pk", "KEEPER_KEY")
keeper_address = get_secret("keepers/rebaser/keeper-address", "KEEPER_ADDRESS")
node_url = get_secret("alchemy/arbitrum-node-url", "ARBITRUM_NODE_URL")
node_url = get_node_url(Network.Arbitrum)
discord_url = get_secret(
"keepers/harvester/arbitrum/info-webhook", "DISCORD_WEBHOOK_URL"
)
Expand All @@ -45,18 +46,18 @@ def safe_harvest(harvester, strategy_name, strategy) -> str:

harvester = GeneralHarvester(
web3=web3,
keeper_acl=MULTICHAIN_CONFIG["arbitrum"]["keeper_acl"],
keeper_acl=MULTICHAIN_CONFIG[Network.Arbitrum]["keeper_acl"],
keeper_address=keeper_address,
keeper_key=keeper_key,
base_oracle_address=MULTICHAIN_CONFIG["arbitrum"]["gas_oracle"],
base_oracle_address=MULTICHAIN_CONFIG[Network.Arbitrum]["gas_oracle"],
use_flashbots=False,
discord_url=discord_url,
)

for strategy_address in strategies:
strategy = web3.eth.contract(
address=web3.toChecksumAddress(strategy_address),
abi=get_abi("arbitrum", "strategy"),
abi=get_abi(Network.Arbitrum, "strategy"),
)
strategy_name = strategy.functions.getName().call()

Expand Down
36 changes: 10 additions & 26 deletions scripts/earn.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,29 +6,18 @@
from web3 import Web3, contract

sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(__file__), "../src")))
sys.path.insert(
0, os.path.abspath(os.path.join(os.path.dirname(__file__), "../config"))
)

from constants import MULTICHAIN_CONFIG
from earner import Earner
from utils import get_secret, get_strategies_and_vaults
from enums import Network
from utils import get_secret, get_strategies_and_vaults, get_node_url

logging.basicConfig(level=logging.INFO)
logger = logging.getLogger("script")

CONFIG = {
"poly": {
"gas_oracle": "0xAB594600376Ec9fD91F8e885dADF0CE036862dE0",
"keeper_acl": "0x46fa8817624eea8052093eab8e3fdf0e2e0443b2",
# TODO: may need to make vault owner a list eventually
"vault_owner": "0xeE8b29AA52dD5fF2559da2C50b1887ADee257556",
"registry": "0xFda7eB6f8b7a9e9fCFd348042ae675d1d652454f",
},
# "eth": {
# "gas_oracle": "eth",
# "keeper_acl": "eth",
# "vault_owner": "eth",
# "registry": "eth"
# }
}

INVALID_STRATS = ["0xDb0C3118ef1acA6125200139BEaCc5D675F37c9C"]


Expand All @@ -39,14 +28,9 @@ def safe_earn(earner, sett_name, vault, strategy):
logger.error(f"Error running {sett_name} earn: {e}")


def get_abi(chain: str, contract_id: str):
with open(f"./abi/{chain}/{contract_id}.json") as f:
return json.load(f)


if __name__ == "__main__":
for chain in CONFIG.keys():
node_url = get_secret(f"quiknode/{chain}-node-url", "NODE_URL")
for chain in [Network.Polygon]:
node_url = get_node_url(chain)
node = Web3(Web3.HTTPProvider(node_url))

strategies, vaults = get_strategies_and_vaults(node, chain)
Expand All @@ -56,11 +40,11 @@ def get_abi(chain: str, contract_id: str):

earner = Earner(
chain=chain,
keeper_acl=CONFIG.get(chain).get("keeper_acl"),
keeper_acl=MULTICHAIN_CONFIG.get(chain).get("keeper_acl"),
keeper_address=keeper_address,
keeper_key=keeper_key,
web3=node,
base_oracle_address=CONFIG.get(chain).get("gas_oracle"),
base_oracle_address=MULTICHAIN_CONFIG[chain]["gas_oracle"],
)

for strategy, vault in zip(strategies, vaults):
Expand Down
20 changes: 11 additions & 9 deletions scripts/earn_locked_cvx.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,22 @@
0, os.path.abspath(os.path.join(os.path.dirname(__file__), "../config"))
)

from enums import Network
from earner import Earner
from utils import get_secret, get_strategies_and_vaults, get_abi
from constants import MULTICHAIN_CONFIG
from utils import get_secret, get_abi, get_node_url
from constants import (
MULTICHAIN_CONFIG,
ETH_BVECVX_STRATEGY,
ETH_BVECVX_VAULT,
)

logging.basicConfig(level=logging.INFO)
logger = logging.getLogger("script")

LOCKED_CVX_STRATEGY = "0x3ff634ce65cDb8CC0D569D6d1697c41aa666cEA9"
LOCKED_CVX_VAULT = "0xfd05D3C7fe2924020620A8bE4961bBaA747e6305"


if __name__ == "__main__":
chain = "eth"
node_url = get_secret(f"quiknode/{chain}-node-url", "NODE_URL")
chain = Network.Ethereum
node_url = get_node_url(chain)
node = Web3(Web3.HTTPProvider(node_url))

keeper_key = get_secret("keepers/rebaser/keeper-pk", "KEEPER_KEY")
Expand All @@ -39,9 +41,9 @@
)

strategy = node.eth.contract(
address=LOCKED_CVX_STRATEGY, abi=get_abi(chain, "strategy")
address=ETH_BVECVX_STRATEGY, abi=get_abi(chain, "strategy")
)
vault = node.eth.contract(address=LOCKED_CVX_VAULT, abi=get_abi(chain, "vault"))
vault = node.eth.contract(address=ETH_BVECVX_VAULT, abi=get_abi(chain, "vault"))

strat_name = "Badger Vested Escrow Convex Token"

Expand Down
12 changes: 4 additions & 8 deletions scripts/eth_earn.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,14 @@
)

from earner import Earner
from utils import get_secret, get_strategies_and_vaults, get_strategy_from_vault
from utils import get_secret, get_strategy_from_vault, get_abi, get_node_url
from constants import (
MULTICHAIN_CONFIG,
ETH_YVWBTC_VAULT,
ETH_TRICRYPTO_VAULT,
ETH_BVECVX_CVX_LP_VAULT,
)
from enums import Network

logging.basicConfig(level=logging.INFO)
logger = logging.getLogger("script")
Expand All @@ -32,14 +33,9 @@ def safe_earn(earner, sett_name, vault, strategy):
logger.error(f"Error running {sett_name} earn: {e}")


def get_abi(chain: str, contract_id: str):
with open(f"./abi/{chain}/{contract_id}.json") as f:
return json.load(f)


if __name__ == "__main__":
for chain in ["eth"]:
node_url = get_secret(f"quiknode/{chain}-node-url", "NODE_URL")
for chain in [Network.Ethereum]:
node_url = get_node_url(chain)
node = Web3(Web3.HTTPProvider(node_url))

registry = node.eth.contract(
Expand Down
10 changes: 7 additions & 3 deletions scripts/eth_tend.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,13 @@
from web3 import Web3

sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(__file__), "../src")))
sys.path.insert(
0, os.path.abspath(os.path.join(os.path.dirname(__file__), "../config"))
)

from general_harvester import GeneralHarvester
from utils import get_abi, get_secret
from utils import get_abi, get_secret, get_node_url
from enums import Network

logging.basicConfig(level=logging.INFO)
logger = logging.getLogger(Path(__file__).name)
Expand Down Expand Up @@ -44,7 +48,7 @@ def safe_tend(harvester, strategy_name, strategy) -> str:
# Load secrets
keeper_key = get_secret("keepers/rebaser/keeper-pk", "KEEPER_KEY")
keeper_address = get_secret("keepers/rebaser/keeper-address", "KEEPER_ADDRESS")
node_url = get_secret("quiknode/eth-node-url", "NODE_URL")
node_url = get_node_url(Network.Ethereum)

web3 = Web3(Web3.HTTPProvider(node_url))

Expand All @@ -60,7 +64,7 @@ def safe_tend(harvester, strategy_name, strategy) -> str:
for strategy_address in STRATEGIES.values():
strategy = web3.eth.contract(
address=web3.toChecksumAddress(strategy_address),
abi=get_abi("eth", "strategy"),
abi=get_abi(Network.Ethereum, "strategy"),
)

if strategy.functions.isTendable().call():
Expand Down
Loading