-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathapp.py
181 lines (159 loc) · 5.34 KB
/
app.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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
import worker
import os
import datetime
from web3 import Web3
from flask import Flask, render_template, request, redirect, send_from_directory, abort
import settings
from data.cache import pool, tokens, price, protocols, sherlock, sherx, state
app = Flask(__name__, template_folder="templates")
@app.route('/favicon.png')
def favicon():
return send_from_directory(os.path.join(app.root_path, 'static'),
'favicon.png', mimetype='image/png')
@app.errorhandler(404)
def page_not_found(e):
return render_template('http-error.html',
env=env(),
data={
"error": "404 - Page not found",
"status": "404"
}
), 404
@app.errorhandler(500)
def page_not_found(e):
return render_template('http-error.html',
env=env(),
data={
"error": "500 - Internal server error",
"status": "500"
}
), 500
def env():
return {
"network": settings.NETWORK,
"chainid": settings.CHAINID,
"infura": settings.INFURA_TOKEN,
"pool_address": settings.SHERLOCK,
"git_hash": settings.GIT_HASH,
"docsBaseUrl": settings.DOCS_BASEURL,
"wallet": request.cookies.get('wallet', 'None'),
"endpoint": settings.ENDPOINT,
"state": state.get_state(),
"blocktime": 13325
}
@app.route('/')
def dashboard():
return render_template(
'dashboard.html',
title='Dashboard',
desc='dashboard',
tags=["dashboard"],
currentPage="dashboard",
env=env(),
data={
"sherx": sherx.get_underlying(),
"pool": pool.get_staking_pool_data(),
"cooldown_period": sherlock.get_cooldown_period(),
"unstake_window": sherlock.get_unstake_window(),
"network": settings.NETWORK
}
)
@app.route('/stake/<address>')
def deposit(address):
e = env()
if e["wallet"] == "None":
return redirect("/", code=302)
address = Web3.toChecksumAddress(address)
for entry in pool.get_staking_pool_data()["tokens"]:
if address == entry["token"]["address"]:
return render_template(
'deposit.html',
title='Deposit',
desc='deposit',
tags=["deposit"],
currentPage="deposit",
env=e,
data={
"token": entry["token"],
"stake": entry["stake"],
"xrate": entry["xrate"],
"xrate_str": entry["xrate_str"],
"usd": price.get_prices()[entry["token"]["address"]]
}
)
return "Not supported", 404
@app.route('/cooldown/<address>')
def withdraw(address):
e = env()
if e["wallet"] == "None":
return redirect("/", code=302)
address = Web3.toChecksumAddress(address)
for entry in pool.get_staking_pool_data()["tokens"]:
if address == entry["token"]["address"]:
return render_template(
'withdraw.html',
title='Withdraw',
desc='withdraw',
tags=["withdraw"],
currentPage="withdraw",
env=e,
data={
"token": entry["token"],
"stake": entry["stake"],
"xrate": entry["xrate"],
"xrate_str": entry["xrate_str"],
"usd": price.get_prices()[entry["token"]["address"]]
}
)
return "Not supported", 404
@app.route('/harvest/<address>')
def harvest(address):
e = env()
if e["wallet"] == "None":
return redirect("/", code=302)
address = Web3.toChecksumAddress(address)
for entry in pool.get_staking_pool_data()["tokens"]:
if address == entry["token"]["address"]:
return render_template(
'harvest.html',
title='Harvest',
desc='harvest',
tags=["harvest"],
currentPage="harvest",
env=e,
data={
"token": entry["token"],
"stake": entry["stake"],
"xrate": entry["xrate"],
"xrate_str": entry["xrate_str"],
"usd": price.get_prices()[entry["token"]["address"]]
}
)
return "Not supported", 404
@app.route('/breakdown')
def breakdown():
covered, usd_total = protocols.get_protocols_covered()
usd_total_format = '{:20,.0f}'.format(usd_total / 100000).strip()
return render_template(
'breakdown.html',
title='Breakdown',
desc='breakdown',
tags=["breakdown"],
currentPage="breakdown",
env=env(),
data={
"tokens": tokens.get_tokens(),
"protocols": protocols.get_protocols_premium(),
"protocols_covered": covered,
"protocol_meta": protocols.PROTOCOL_META,
"usd": price.get_prices(),
"total_covered_usd": usd_total,
"total_covered_usd_str": usd_total_format
}
)
if __name__ == '__main__':
if os.environ.get("FLASK_ENV") == "development":
import threading
x = threading.Thread(target=worker.loop, args=())
x.start()
app.run(host=settings.SERVER_HOST, port=settings.SERVER_PORT)