-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathGovernance.py
More file actions
380 lines (326 loc) · 15 KB
/
Governance.py
File metadata and controls
380 lines (326 loc) · 15 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
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
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
import smartpy as sp
GOVErrors = sp.io.import_script_from_url(
"file:contracts/errors/GovernanceErrors.py")
EC = GOVErrors.ErrorCodes
GOVI = sp.io.import_script_from_url(
"file:contracts/interfaces/GovernanceInterface.py")
SweepTokens = sp.io.import_script_from_url(
"file:contracts/utils/SweepTokens.py")
CToken = sp.io.import_script_from_url("file:contracts/CToken.py")
class Governance(GOVI.GovernanceInterface, SweepTokens.SweepTokens):
def __init__(self, administrator_):
self.init(administrator=administrator_, pendingAdministrator=sp.none)
@sp.entry_point(lazify=True)
def receive(self, unused):
sp.set_type(unused, sp.TUnit)
"""
Sets a new pending governance for the governor
dev: Governance function to set a new governance
params: TAddress - The address of the new pending governance
"""
@sp.entry_point(lazify=True)
def setPendingGovernance(self, pendingAdminAddress):
sp.set_type(pendingAdminAddress, sp.TAddress)
self.verifyAdministrator()
self.data.pendingAdministrator = sp.some(pendingAdminAddress)
"""
Accept a new governance for the Governor
params: TUnit
"""
@sp.entry_point(lazify=True)
def acceptGovernance(self, unusedArg):
sp.set_type(unusedArg, sp.TUnit)
sp.verify(sp.sender == self.data.pendingAdministrator.open_some(
EC.GOV_NOT_SET_PENDING_ADMIN), EC.GOV_NOT_PENDING_ADMIN)
self.data.administrator = self.data.pendingAdministrator.open_some()
self.data.pendingAdministrator = sp.none
"""
Sets a new pending governance for the specified Comptroller or CToken address
params: TRecord
contractAddress: TAddress - The address of Comptroller or CToken contract
governance: TAddress - The address of the new Governance contract
"""
@sp.entry_point
def setContractGovernance(self, params):
self.verifyAdministrator()
sp.set_type(params, sp.TRecord(
contractAddress=sp.TAddress, governance=sp.TAddress))
contract = sp.contract(
sp.TAddress, params.contractAddress, "setPendingGovernance").open_some()
sp.transfer(params.governance, sp.mutez(0), contract)
"""
Accept a new governance for the specified Comptroller or CToken address
contractAddress: TAddress - The address of Comptroller or CToken contract
"""
@sp.entry_point
def acceptContractGovernance(self, contractAddress):
self.verifyAdministrator()
sp.set_type(contractAddress, sp.TAddress)
contract = sp.contract(sp.TUnit, contractAddress,
"acceptGovernance").open_some()
sp.transfer(sp.unit, sp.mutez(0), contract)
"""
# Set the number of blocks since the last accrue interest update is valid
params: TRecord
cToken: TAddress - The address of CToken contract
blockNumber: TNat
"""
@sp.entry_point
def setAccrualIntPeriodRelevance(self, params):
self.verifyAdministrator()
sp.set_type(params, sp.TRecord(
cToken=sp.TAddress, blockNumber=sp.TNat))
contract = sp.contract(sp.TNat, params.cToken,
"setAccrualIntPeriodRelevance").open_some()
sp.transfer(params.blockNumber, sp.mutez(0), contract)
"""
# Set the number of blocks since the last update until the price is considered valid
params: TRecord
comptroller: TAddress - The address of comptroller contract
blockNumber: TNat
"""
@sp.entry_point
def setPricePeriodRelevance(self, params):
self.verifyAdministrator()
sp.set_type(params, sp.TRecord(
comptroller=sp.TAddress, blockNumber=sp.TNat))
contract = sp.contract(sp.TNat, params.comptroller,
"setPricePeriodRelevance").open_some()
sp.transfer(params.blockNumber, sp.mutez(0), contract)
"""
# Set the number of blocks since the last update until the liquidity is considered valid
params: TRecord
comptroller: TAddress - The address of comptroller contract
blockNumber: TNat
"""
@sp.entry_point
def setLiquidityPeriodRelevance(self, params):
self.verifyAdministrator()
sp.set_type(params, sp.TRecord(
comptroller=sp.TAddress, blockNumber=sp.TNat))
contract = sp.contract(sp.TNat, params.comptroller,
"setLiquidityPeriodRelevance").open_some()
sp.transfer(params.blockNumber, sp.mutez(0), contract)
# CToken functions
"""
Sets a new comptroller for the market
params: TRecord
cToken: TAddress - The address of CToken contract
comptroller: TAddress - The address of the new comptroller contract
"""
@sp.entry_point
def setComptroller(self, params):
self.verifyAdministrator()
sp.set_type(params, sp.TRecord(
cToken=sp.TAddress, comptroller=sp.TAddress))
contract = sp.contract(sp.TAddress, params.cToken,
"setComptroller").open_some()
sp.transfer(params.comptroller, sp.mutez(0), contract)
"""
Accrues interest and updates the interest rate model
params: TRecord
cToken: TAddress - The address of CToken contract
interestRateModel: TAddress - The address of the new interest rate model contract
"""
@sp.entry_point
def setInterestRateModel(self, params):
self.verifyAdministrator()
sp.set_type(params, sp.TRecord(
cToken=sp.TAddress, interestRateModel=sp.TAddress))
contract = sp.contract(sp.TAddress, params.cToken,
"setInterestRateModel").open_some()
sp.transfer(params.interestRateModel, sp.mutez(0), contract)
"""
accrues interest and sets a new reserve factor for the protocol
params: TRecord
cToken: TAddress - The address of CToken contract
newReserveFactor: TNat - New reserve factor value
"""
@sp.entry_point
def setReserveFactor(self, params):
self.verifyAdministrator()
sp.set_type(params, sp.TRecord(
cToken=sp.TAddress, newReserveFactor=sp.TNat))
contract = sp.contract(sp.TNat, params.cToken,
"setReserveFactor").open_some()
sp.transfer(params.newReserveFactor, sp.mutez(0), contract)
"""
Accrues interest and reduces reserves by transferring to admin
params: TRecord
cToken: TAddress - The address of CToken contract
amount: TNat - Amount of reduction to reserves
"""
@sp.entry_point
def reduceReserves(self, params):
self.verifyAdministrator()
sp.set_type(params, sp.TRecord(cToken=sp.TAddress, amount=sp.TNat))
contract = sp.contract(sp.TNat, params.cToken,
"reduceReserves").open_some()
sp.transfer(params.amount, sp.mutez(0), contract)
"""
Updates the contract metadata of the cToken at specified key with specified value
params: TRecord
cToken: TAddress - The address of CToken contract
key: TString - The key of the metadata to update
value: TBytes - The value to update the metadata with
"""
@sp.entry_point
def updateMetadata(self, params):
self.verifyAdministrator()
sp.set_type(params, sp.TRecord(cToken=sp.TAddress,
key=sp.TString, value=sp.TBytes))
contract = sp.contract(sp.TRecord(
key=sp.TString, value=sp.TBytes), params.cToken, "updateMetadata").open_some()
sp.transfer(sp.record(key=params.key, value=params.value),
sp.mutez(0), contract)
# Comptroller functions
"""
Sets a new price oracle and time diff for the comptroller
params: TAddress, TInt - The address of the new price oracle contract and max time diff
"""
@sp.entry_point(lazify=True)
def setPriceOracleAndTimeDiff(self, params):
self.verifyAdministrator()
sp.set_type(params, sp.TRecord(
comptroller=sp.TAddress, priceOracle=sp.TAddress, timeDiff=sp.TInt))
contract = sp.contract(
sp.TRecord(priceOracle=sp.TAddress, timeDiff=sp.TInt), params.comptroller, "setPriceOracleAndTimeDiff").open_some()
sp.transfer(sp.record(priceOracle=params.priceOracle,timeDiff=params.timeDiff), sp.mutez(0), contract)
"""
Sets the closeFactor used when liquidating borrows
params: TRecord
comptroller: TAddress - The address of Comptroller contract
closeFactor: TNat - New close factor, scaled by 1e18
"""
@sp.entry_point
def setCloseFactor(self, params):
self.verifyAdministrator()
sp.set_type(params, sp.TRecord(
comptroller=sp.TAddress, closeFactor=sp.TNat))
contract = sp.contract(sp.TNat, params.comptroller,
"setCloseFactor").open_some()
sp.transfer(params.closeFactor, sp.mutez(0), contract)
"""
Sets the collateralFactor for a market
params: TRecord
comptroller: TAddress - The address of Comptroller contract
collateralFactor: TRecord
cToken: TAddress - The market to set the factor on
newCollateralFactor: TNat - The new collateral factor, scaled by 1e18
"""
@sp.entry_point
def setCollateralFactor(self, params):
self.verifyAdministrator()
sp.set_type(params, sp.TRecord(comptroller=sp.TAddress, collateralFactor=sp.TRecord(
cToken=sp.TAddress, newCollateralFactor=sp.TNat)))
contract = sp.contract(sp.TRecord(cToken=sp.TAddress, newCollateralFactor=sp.TNat),
params.comptroller, "setCollateralFactor").open_some()
sp.transfer(params.collateralFactor, sp.mutez(0), contract)
"""
Sets liquidationIncentive
params: TRecord
comptroller: TAddress - The address of Comptroller contract
liquidationIncentive: TNat - New liquidationIncentive scaled by 1e18
"""
@sp.entry_point
def setLiquidationIncentive(self, params):
self.verifyAdministrator()
sp.set_type(params, sp.TRecord(
comptroller=sp.TAddress, liquidationIncentive=sp.TNat))
contract = sp.contract(sp.TNat, params.comptroller,
"setLiquidationIncentive").open_some()
sp.transfer(params.liquidationIncentive, sp.mutez(0), contract)
"""
Add the market to the markets mapping and set it as listed
params: TRecord
comptroller: TAddress - The address of Comptroller contract
market: TRecord
cToken: TAddress - The address of the market (token) to list
name: TString - The market name in price oracle
priceExp: TNat - exponent needed to normalize the token prices to 10^18 (eth:0, btc: 10, usd: 12)
"""
@sp.entry_point
def supportMarket(self, params):
self.verifyAdministrator()
sp.set_type(params, sp.TRecord(comptroller=sp.TAddress, market=sp.TRecord(
cToken=sp.TAddress, name=sp.TString, priceExp=sp.TNat)))
contract = sp.contract(sp.TRecord(cToken=sp.TAddress, name=sp.TString,
priceExp=sp.TNat), params.comptroller, "supportMarket").open_some()
sp.transfer(params.market, sp.mutez(0), contract)
"""
Disable the supported market
params: TRecord
comptroller: TAddress - The address of Comptroller contract
cToken: TAddress - The address of the market (token) to disable
"""
@sp.entry_point
def disableMarket(self, params):
self.verifyAdministrator()
sp.set_type(params, sp.TRecord(
comptroller=sp.TAddress, cToken=sp.TAddress))
contract = sp.contract(
sp.TAddress, params.comptroller, "disableMarket").open_some()
sp.transfer(params.cToken, sp.mutez(0), contract)
"""
Set the maximum number of unique assets a user can hold
params: TRecord
comptroller: TAddress - The address of Comptroller contract
maxAssets: TNat - The maximum number of assets a user can hold
"""
@sp.entry_point
def setMaxAssetsPerUser(self, params):
self.verifyAdministrator()
sp.set_type(params, sp.TRecord(
comptroller=sp.TAddress, maxAssets=sp.TNat))
contract = sp.contract(sp.TNat, params.comptroller,
"setMaxAssetsPerUser").open_some()
sp.transfer(params.maxAssets, sp.mutez(0), contract)
"""
Pause or activate the mint of given CToken
params: TRecord
comptroller: TAddress - The address of Comptroller contract
tokenState: TRecord
cToken: TAddress - The address of the market to change the mint pause state
state: TBool - state, where True - pause, False - activate
"""
@sp.entry_point
def setMintPaused(self, params):
self.verifyAdministrator()
sp.set_type(params, sp.TRecord(comptroller=sp.TAddress,
tokenState=sp.TRecord(cToken=sp.TAddress, state=sp.TBool)))
contract = sp.contract(sp.TRecord(
cToken=sp.TAddress, state=sp.TBool), params.comptroller, "setMintPaused").open_some()
sp.transfer(params.tokenState, sp.mutez(0), contract)
"""
Pause or activate the borrow of given CToken
params: TRecord
comptroller: TAddress - The address of Comptroller contract
tokenState: TRecord
cToken: TAddress - The address of the market to change the borrow pause state
state: TBool - state, where True - pause, False - activate
"""
@sp.entry_point
def setBorrowPaused(self, params):
self.verifyAdministrator()
sp.set_type(params, sp.TRecord(comptroller=sp.TAddress,
tokenState=sp.TRecord(cToken=sp.TAddress, state=sp.TBool)))
contract = sp.contract(sp.TRecord(
cToken=sp.TAddress, state=sp.TBool), params.comptroller, "setBorrowPaused").open_some()
sp.transfer(params.tokenState, sp.mutez(0), contract)
"""
Pause or activate the transfer of CTokens
params: TRecord
comptroller: TAddress - The address of Comptroller contract
state: TBool - state, where True - pause, False - activate
"""
@sp.entry_point
def setTransferPaused(self, params):
self.verifyAdministrator()
sp.set_type(params, sp.TRecord(
comptroller=sp.TAddress, state=sp.TBool))
contract = sp.contract(sp.TBool, params.comptroller,
"setTransferPaused").open_some()
sp.transfer(params.state, sp.mutez(0), contract)
# Helpers
def verifyAdministrator(self):
sp.verify(sp.sender == self.data.administrator, EC.GOV_NOT_ADMIN)