Repository navigation
Expand file tree
/
Copy pathworker_initial.py
More file actions
69 lines (53 loc) · 1.9 KB
/
Copy pathworker_initial.py
File metadata and controls
69 lines (53 loc) · 1.9 KB
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
import os
import json
from settings import NETWORK, SHERLOCK_HTTP, ERC20_ABI, INFURA_HTTP, COINGECKO_IDS, WORKER_ROOT
INDENT = None
SORT_KEYS = False
if os.environ.get("FLASK_ENV") == "development":
INDENT = 4
# Keep false otherwise order of tokens changes on dashboard
SORT_KEYS = False
def get_tokens():
tokens = {}
address = []
_tokens = SHERLOCK_HTTP.functions.getTokensStaker().call()
_sherx = SHERLOCK_HTTP.functions.getTokensSherX().call()
_tokens.extend(x for x in _sherx if x not in _tokens)
for token in _tokens:
w = INFURA_HTTP.eth.contract(address=token, abi=ERC20_ABI)
token_decimals = w.functions.decimals().call()
symbol = w.functions.symbol().call()
tokens[symbol] = {
"address": token,
"name": w.functions.name().call(),
"decimals": token_decimals,
"divider": float("1" + "0" * token_decimals),
"coingecko": COINGECKO_IDS.get(symbol, symbol.lower())
}
address.append(token)
return tokens, address
def get_lock(address):
lock = {}
for add in address:
stake = SHERLOCK_HTTP.functions.getLockToken(add).call()
if stake == "0x0000000000000000000000000000000000000000":
continue
STAKE = INFURA_HTTP.eth.contract(address=stake, abi=ERC20_ABI)
lock[add] = {
"address": stake,
"name": STAKE.functions.name().call(),
"symbol": STAKE.functions.symbol().call().lower(),
"decimals": STAKE.functions.decimals().call(),
}
return lock
def index():
token, address = get_tokens()
locked = get_lock(address)
path = os.path.join(WORKER_ROOT, "%s.json" % NETWORK)
with open(path, "w") as f:
json.dump({
"token": token,
"lock": locked
}, f, indent=INDENT, sort_keys=SORT_KEYS)
if __name__ == "__main__":
index()