-
Notifications
You must be signed in to change notification settings - Fork 3
/
main.py
257 lines (223 loc) · 11.4 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
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
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
from flask import Flask, jsonify, request
from flask_restful import Resource, Api, reqparse
from flask_cors import CORS
import json
from dotenv import load_dotenv
from models.disputable_voting import DisputableVotingModel
from models.token_lockup import TokenLockupModel
from models.augmented_bonding_curve import BondingCurveHandler
from models.issue_generator import IssueGeneratorModel
from models.conviction_voting import ConvictionVotingModel
import models.import_params as import_params
app = Flask(__name__)
api = Api(app)
CORS(app)
load_dotenv()
class status(Resource):
def get(self):
try:
return {'data': 'Api running'}
except (error):
return {'data': error}
class TokenLockup(Resource):
def post(self):
parser = reqparse.RequestParser()
parser.add_argument('openingPrice', type=float)
parser.add_argument('tokenFreeze', type=float)
parser.add_argument('tokenThaw', type=float)
parameters = parser.parse_args()
opening_price = parameters['openingPrice']
token_freeze_period = parameters['tokenFreeze']
token_thaw_period = parameters['tokenThaw']
token_lockup_model = TokenLockupModel(opening_price=opening_price,
token_freeze_period=token_freeze_period,
token_thaw_period=token_thaw_period)
return jsonify(token_lockup_model.get_data())
class DisputableVoting(Resource):
def post(self):
parser = reqparse.RequestParser()
parser.add_argument('supportRequired', type=float)
parser.add_argument('minimumQuorum', type=float)
parser.add_argument('voteDuration', type=float)
parser.add_argument('delegatedVotingPeriod', type=float)
parser.add_argument('quietEndingPeriod', type=float)
parser.add_argument('quietEndingExtension', type=float)
parser.add_argument('executionDelay', type=float)
parameters = parser.parse_args()
support_required = parameters['supportRequired']
minimum_quorum = parameters['minimumQuorum']
vote_duration = parameters['voteDuration']
delegated_voting_period = parameters['delegatedVotingPeriod']
quiet_ending_period = parameters['quietEndingPeriod']
quiet_ending_extension = parameters['quietEndingExtension']
execution_delay = parameters['executionDelay']
disputable_voting_model = DisputableVotingModel(support_required=support_required,
minimum_quorum=minimum_quorum,
vote_duration=vote_duration,
delegated_voting_period=delegated_voting_period,
quiet_ending_period=quiet_ending_period,
quiet_ending_extension=quiet_ending_extension,
execution_delay=execution_delay)
return jsonify(disputable_voting_model.get_data())
class AugmentedBondingCurve(Resource):
def post(self):
parser = reqparse.RequestParser()
parser.add_argument('commonsTribute', type=str)
parser.add_argument('openingPrice', type=str)
parser.add_argument('entryTribute', type=str)
parser.add_argument('exitTribute', type=str)
parser.add_argument('ragequitAmount', type=str)
parser.add_argument('initialBuy', type=str)
parser.add_argument('stepList', action='append')
parser.add_argument('virtualSupply', type=str)
parser.add_argument('virtualBalance', type=str)
parser.add_argument('zoomGraph', type=str)
parser.add_argument('includeMilestones', type=str)
parser.add_argument('totalHatchFunding', type=str)
parser.add_argument('totalInitialTechSupply', type=str)
parser.add_argument('hatchFinalTechPrice', type=str)
parameters = parser.parse_args()
commons_percentage = float(
parameters['commonsTribute']) if parameters['commonsTribute'] is not None else 0.05
opening_price = float(
parameters['openingPrice']) if parameters['openingPrice'] is not None else 1.50
entry_tribute = float(
parameters['entryTribute']) if parameters['entryTribute'] is not None else 0.05
exit_tribute = float(
parameters['exitTribute']) if parameters['exitTribute'] is not None else 0.05
ragequit_amount = float(
parameters['ragequitAmount']) if parameters['ragequitAmount'] is not None else 0
initial_buy = float(
parameters['initialBuy']) if parameters['initialBuy'] is not None else 0
steplist = parameters['stepList'] if parameters['stepList'] is not None else [
]
virtual_supply = float(
parameters['virtualSupply']) if parameters['virtualSupply'] is not None else 1
virtual_balance = float(
parameters['virtualBalance']) if parameters['virtualBalance'] is not None else 1
zoom_graph = int(
parameters['zoomGraph']) if parameters['zoomGraph'] is not None else 0
include_milestones = int(
parameters['includeMilestones']) if parameters['includeMilestones'] is not None else 0
total_hatch_funding = float(
parameters['totalHatchFunding']) if parameters['totalHatchFunding'] is not None else 1571.22357
total_initial_tech_supply = float(
parameters['totalInitialTechSupply']) if parameters['totalInitialTechSupply'] is not None else 2041.86358
hatch_final_tech_price = float(
parameters['hatchFinalTechPrice']) if parameters['hatchFinalTechPrice'] is not None else 0.754743
# add default steps
steplist.insert(0, "[100, 'wxDAI']")
try:
augmented_bonding_curve_model = BondingCurveHandler(
commons_percentage=commons_percentage,
ragequit_amount=ragequit_amount,
opening_price=opening_price,
entry_tribute=entry_tribute,
exit_tribute=exit_tribute,
initial_buy=initial_buy,
virtual_supply=virtual_supply,
virtual_balance=virtual_balance,
steplist=steplist,
zoom_graph=zoom_graph,
include_milestones=include_milestones,
total_hatch_funding=total_hatch_funding,
total_initial_tech_supply=total_initial_tech_supply,
hatch_final_tech_price=hatch_final_tech_price,
)
except ValueError as ve:
return jsonify(str(ve))
return jsonify(augmented_bonding_curve_model.get_data())
class IssueGenerator(Resource):
def post(self):
parser = reqparse.RequestParser()
parser.add_argument('title', type=str)
parser.add_argument('overallStrategy', type=str)
parser.add_argument('tokenLockup', type=dict)
parser.add_argument('augmentedBondingCurve', type=dict)
parser.add_argument('taoVoting', type=dict)
parser.add_argument('convictionVoting', type=dict)
parser.add_argument('advancedSettings', type=dict)
parameters = json.loads(request.form.get('body'))
image_files = request.files
title = parameters['title']
overall_strategy = parameters['overallStrategy']
token_lockup = parameters['tokenLockup']
abc = parameters['augmentedBondingCurve']
tao_voting = parameters['taoVoting']
conviction_voting = parameters['convictionVoting']
advanced_settings = parameters['advancedSettings']
abc['commonsTribute'] = float(
abc['commonsTribute']) if abc['commonsTribute'] is not None else 0.05
abc['openingPrice'] = float(
abc['openingPrice']) if abc['openingPrice'] is not None else 1.50
abc['entryTribute'] = float(
abc['entryTribute']) if abc['entryTribute'] is not None else 0.05
abc['exitTribute'] = float(
abc['exitTribute']) if abc['exitTribute'] is not None else 0.05
abc['ragequitAmount'] = float(
abc['ragequitAmount']) if abc['ragequitAmount'] is not None else 0
abc['initialBuy'] = float(
abc['initialBuy']) if abc['initialBuy'] is not None else 0
# removed this line following the feature cut 25/11/21
# abc['reserveBalance'] = float(abc['reserveBalance']) if abc['reserveBalance'] is not None else (1571223.57 - abc.initial_buy - abc.ragequit_amount)*(1-abc.commons_percentage)
# change to account for new default steps
abc['stepList'] = abc['stepList'] if abc['stepList'] is not abc else []
abc['stepList'].insert(0, "[100, 'wxDAI']")
abc['virtualSupply'] = float(
abc['virtualSupply']) if abc['virtualSupply'] is not None else 1
abc['virtualBalance'] = float(
abc['virtualBalance']) if abc['virtualBalance'] is not None else 1
abc['zoomGraph'] = int(
abc['zoomGraph']) if abc['zoomGraph'] is not None else 0
# added the milestone generation for the issue generator
abc['includeMilestones'] = int(1)
issue_generator = IssueGeneratorModel(
raw_body=parameters,
title=title,
token_lockup=token_lockup,
abc=abc,
tao_voting=tao_voting,
conviction_voting=conviction_voting,
advanced_settings=advanced_settings,
overall_strategy=overall_strategy,
image_files=image_files
)
return jsonify(issue_generator.generate_output())
class ConvictionVoting(Resource):
def post(self):
parser = reqparse.RequestParser()
parser.add_argument('spendingLimit', type=float)
parser.add_argument('minimumConviction', type=float)
parser.add_argument('convictionGrowth', type=int)
parser.add_argument('convictionVotingPeriodDays', type=float)
parser.add_argument('tableScenarios', type=list, action='append')
parameters = parser.parse_args()
spending_limit = parameters['spendingLimit']
minimum_conviction = parameters['minimumConviction']
conviction_growth = parameters['convictionGrowth']
voting_period_days = parameters['convictionVotingPeriodDays']
table_scenarios = parameters['tableScenarios']
conviction_voting_model = ConvictionVotingModel(
spending_limit=spending_limit,
minimum_conviction=minimum_conviction,
conviction_growth=conviction_growth,
voting_period_days=voting_period_days,
table_scenarios=table_scenarios
)
return jsonify(conviction_voting_model.get_data())
class ImportParams(Resource):
def get(self):
parser = reqparse.RequestParser()
parser.add_argument('issueNumber', type=int)
parameters = parser.parse_args()
issue_number = parameters.get('issueNumber', '')
return jsonify(import_params.get_data(issue_number))
api.add_resource(status, '/')
api.add_resource(ImportParams, '/import-parameters/')
api.add_resource(TokenLockup, '/token-lockup/')
api.add_resource(DisputableVoting, '/disputable-voting/')
api.add_resource(AugmentedBondingCurve, '/augmented-bonding-curve/')
api.add_resource(IssueGenerator, '/issue-generator/')
api.add_resource(ConvictionVoting, '/conviction-voting/')
if __name__ == '__main__':
app.run(debug=True)