This repository was archived by the owner on Apr 26, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathethjobs.py
99 lines (75 loc) · 2.78 KB
/
ethjobs.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
#!/usr/bin/env python
import json
from pathlib import Path
import boto3
from web3 import Web3
import config
OSM_CONTRACT_ADDRESS = '0x81FE72B5A8d1A857d176C3E7d5Bd2679A9B85763'
POSITION_CUR = 3
POSITION_NXT = 4
YEARN_3CRV = '0x9cA85572E6A3EbF24dEDd195623F188735A5179f'
YEARN_3CRV_STRAT = '0xC59601F0CC49baa266891b7fc63d2D5FE097A79D'
def main():
w3 = Web3(Web3.HTTPProvider(config.LOCAL_ETH_NODE))
if not w3.isConnected():
print("Could not connect to local node")
w3 = Web3(Web3.HTTPProvider(
'https://mainnet.infura.io/v3/' + config.INFURA_ACCOUNT))
if not w3 or not w3.isConnected():
print('Could not connect to Infura')
msg = 'Could not check OSM ETH price'
print(msg)
sendAlert(msg)
exit(1)
if config.YEARN_3POOL_WITHDRAW_THRESHOLD:
withdraw3pool(w3)
if config.OSM_NEXT_ALERT_THRESHOLD:
osmNext(w3)
def withdraw3pool(w3):
basePath = Path(__file__).parent
with basePath.joinpath('abi', 'yVault.json').open() as json_file:
abi = json.load(json_file)
yVault = w3.eth.contract(
address=YEARN_3CRV,
abi=abi,
)
vaultBalance = w3.fromWei(yVault.functions.balance().call(), 'ether')
with basePath.joinpath('abi', 'StrategyCurve3CrvVoterProxy.json').open() as json_file:
abi = json.load(json_file)
yVaultStrat = w3.eth.contract(
address=YEARN_3CRV_STRAT,
abi=abi,
)
stratBalance = w3.fromWei(
yVaultStrat.functions.balanceOfPool().call(), 'ether')
availableWithdraw = vaultBalance-stratBalance
msg = f"3pool Vault balance: {vaultBalance}. Strat balance: {stratBalance}. Available: {availableWithdraw}."
print(msg)
if availableWithdraw > config.YEARN_3POOL_WITHDRAW_THRESHOLD:
sendAlert(msg)
def osmNext(w3):
curPrice = readPrice(w3, POSITION_CUR)
nxtPrice = readPrice(w3, POSITION_NXT)
msg = f"Current price: {curPrice}. Next price: {nxtPrice}."
print(msg)
if curPrice <= config.OSM_NEXT_ALERT_THRESHOLD or nxtPrice <= config.OSM_NEXT_ALERT_THRESHOLD:
sendAlert(msg)
def readPrice(w3, storagePosition):
price = w3.eth.getStorageAt(OSM_CONTRACT_ADDRESS, storagePosition)
return w3.fromWei(w3.toInt(price[16:]), 'ether')
def sendAlert(msg):
if config.AWS_ACCESS_KEY_ID:
snsClient = boto3.client(
'sns',
aws_access_key_id=config.AWS_ACCESS_KEY_ID,
aws_secret_access_key=config.AWS_SECRET_ACCESS_KEY
)
else:
session = boto3.Session(profile_name=config.AWS_PROFILE_NAME)
snsClient = session.client('sns')
snsClient.publish(
TopicArn=config.ALERT_TOPIC_ARN,
Message=f"Please alert Mathew: {msg}"
)
if __name__ == "__main__":
main()