-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathmain.py
53 lines (41 loc) · 2.57 KB
/
main.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
import decimal
import json
from decimal import Decimal
from web3 import Web3
import discordWH
import twitter
cauldrons = json.loads(open("Cauldrons.json", 'r').read()) #Loads Cauldrons.json as a nested dic
settings = json.loads(open("Settings.json", 'r').read()) #Loads Chains Info
def checkTreshold(previous_amount, amount, treshold):
if amount - previous_amount > treshold: #check if the increase is > treshold
if previous_amount == 0: #if previousAmount is "pure" 0, we send message
return True
elif amount - previous_amount > Decimal(0.3) * previous_amount: #check wether the increase is at least a 30% increase
return True
else:
return False
for chain in settings.keys(): #Go though each chain
w3 = Web3(Web3.HTTPProvider(settings[chain]['RPC'])) #Network RPC
bb_address = w3.toChecksumAddress(settings[chain]['bentobox']) #BentoBox Contract Address
MIM_contract_address=w3.toChecksumAddress(settings[chain]['MIM']) #MIM Contract Address
bb_ABI = json.load(open('BentoBoxV1.json', 'r')) #BentoBox ABI load, from BentoBoxV1.json
bentobox = w3.eth.contract(address=bb_address, abi=bb_ABI)
def getMIMAmount(mim_address, cauldron):
mim_amount=bentobox.functions.balanceOf(mim_address, cauldron).call()
mim_amount=w3.fromWei(mim_amount, 'ether')
return mim_amount
for tokens in cauldrons.keys(): #Go through each Cauldron entry
if cauldrons[tokens]['chain'] == chain: #Check wether the Cauldron entry is on the chain we are working with
amount=getMIMAmount(MIM_contract_address, w3.toChecksumAddress(cauldrons[tokens]['address'])) #Gets MIM available for the cauldron
if checkTreshold(Decimal(cauldrons[tokens]['previous_amount']), Decimal(amount), Decimal(settings[chain]['threshold'])): #Compare amount with previous amount and check if above threshold, defined per chain
print("%s on %s:" %(tokens, chain))
print("Old amount : ", cauldrons[tokens]['previous_amount'])
print("New amount : ", amount)
print("-----")
try:
discordWH.sendMessage(tokens, amount, cauldrons, settings, chain) #Send discord msg
except:
print("error sending discord message")
twitter.tweet(tokens, amount, settings, chain)
cauldrons[tokens]['previous_amount']=str(amount) #Store amount as Previous_amount
json.dump(cauldrons, open("Cauldrons.json", 'w'), indent=4, sort_keys=True)