-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathCTokenInterface.py
More file actions
361 lines (272 loc) · 10.8 KB
/
Copy pathCTokenInterface.py
File metadata and controls
361 lines (272 loc) · 10.8 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
# CToken Interface
# Money market of underlying asset. Can be treated as FA1.2 token
import smartpy as sp
"""
TBorrowSnapshot: Container for borrow balance information
principal: Total balance (with accrued interest), after applying the most recent balance-changing action
interestIndex: Global borrowIndex as of the most recent balance-changing action
"""
TBorrowSnapshot = sp.TRecord(principal=sp.TNat, interestIndex=sp.TNat)
"""
TAccountSnapshot: Container for account balance information
account: account address
cTokenBalance: Token balance of the account
borrowBalance: Borrow balance of the account
exchangeRateMantissa: Exchange rate mantissa
"""
TAccountSnapshot = sp.TRecord(account=sp.TAddress, cTokenBalance=sp.TNat,
borrowBalance=sp.TNat, exchangeRateMantissa=sp.TNat)
TSeize = sp.TRecord(liquidator=sp.TAddress,
borrower=sp.TAddress, seizeTokens=sp.TNat)
TLiquidate = sp.TRecord(borrower=sp.TAddress,
repayAmount=sp.TNat, cTokenCollateral=sp.TAddress)
TValidateRepayParams = sp.TRecord(repayAmount=sp.TNat, closeFactorMantissa=sp.TNat, account=sp.TAddress).layout(
("repayAmount", ("closeFactorMantissa", "account")))
class CTokenInterface(sp.Contract):
"""
Sender supplies assets into the market and receives cTokens in exchange
dev: Accrues interest if the operation succeeds, unless reverted
params: TNat - The amount of the underlying asset to supply
requirements:
accrueInterest() should be executed within the same block prior to this call
"""
@sp.entry_point
def mint(self, params):
pass
"""
Sender redeems cTokens in exchange for the underlying asset
dev: Accrues interest if the operation succeeds, unless reverted
params: TNat - The number of cTokens to redeem into underlying
requirements:
CToken:
accrueInterest() should be executed within the same block prior to this call
comptroller:
updateAssetPrice() should be executed within the same block prior to this call, for all markets entered by the user
updateAccountLiquidity() should be executed within the same block prior to this call
"""
@sp.entry_point
def redeem(self, params):
pass
"""
Sender redeems cTokens in exchange for a specified amount of underlying asset
dev: Accrues interest if the operation succeeds, unless reverted
params: TNat - The amount of underlying to redeem
requirements:
CToken:
accrueInterest() should be executed within the same block prior to this call
comptroller:
updateAssetPrice() should be executed within the same block prior to this call, for all markets entered by the user
updateAccountLiquidity() should be executed within the same block prior to this call
"""
@sp.entry_point
def redeemUnderlying(self, params):
pass
"""
Sender borrows assets from the protocol to their own address
params: TNat - The amount of the underlying asset to borrow
requirements:
cToken:
accrueInterest() should be executed within the same block prior to this call
comptroller:
updateAssetPrice() should be executed within the same block prior to this call, for all markets entered by the user
updateAccountLiquidity() should be executed within the same block prior to this call
"""
@sp.entry_point
def borrow(self, params):
pass
"""
Sender repays their own borrow
params: TNat - The amount to repay
requirements:
accrueInterest() should be executed within the same block prior to this call
"""
@sp.entry_point
def repayBorrow(self, params):
pass
"""
Sender repays a borrow belonging to borrower
params: TRecord
borrower: TAddress - The account with the debt being payed off
repayAmount: TNat - The amount to repay
requirements:
accrueInterest() should be executed within the same block prior to this call
"""
@sp.entry_point
def repayBorrowBehalf(self, params):
pass
"""
Transfer `value` tokens from `from_` to `to_`
params: TRecord
from_: TAddress - The address of the source account
to_: TAddress - The address of the destination account
value: TNat - The number of tokens to transfer
requirements:
comptroller:
updateAssetPrice() should be executed within the same block prior to this call, for all markets entered by the user
updateAccountLiquidity() should be executed within the same block prior to this call
"""
@sp.entry_point
def transfer(self, params):
pass
"""
Approve `spender` to transfer up to `amount` from `sp.sender`
params: TRecord
spender: TAddress - The address of the account which may transfer tokens
value: TNat - The number of tokens that are approved
"""
@sp.entry_point
def approve(self, params):
pass
"""
Updates the contract metadata at specified key
params:
key: TString - The key to update
value: TBytes - The value to update with
requirements:
Can be called only by the contract administrator
"""
@sp.entry_point
def updateMetadata(self, params):
pass
"""
Get the current allowance from `owner` for `spender`
params: TRecord
owner: TAddress - The address of the account which owns the tokens to be spent
spender: TAddress - The address of the account which may transfer tokens
return: The number of tokens allowed to be spent
"""
@sp.utils.view(sp.TNat)
def getAllowance(self, params):
pass
"""
Get the CToken balance of the account specified in `params`
params: TAddress - The address of the account to query
return: The number of tokens owned by `params`
"""
@sp.utils.view(sp.TNat)
def getBalance(self, params):
pass
"""
Get the underlying balance of the account specified in `params`
dev: This function does not accrue interest before calculating the balance
dev: Do accrueInterest() before this function to get the up-to-date balance
params: TAddress - The address of the account to query
return: The amount of underlying owned by `params`
"""
@sp.utils.view(sp.TNat)
def getBalanceOfUnderlying(self, params):
pass
"""
Get total supply of the CToken
params: TUnit
return: The total supply of the CToken
"""
@sp.utils.view(sp.TPair(sp.TNat, sp.TNat))
def getTotalSupply(self, params):
pass
"""
Get a snapshot of the account's balances, and the cached exchange rate
dev: This is used by comptroller to more efficiently perform liquidity checks.
params: TAddress - The address of the account to snapshot
return: TAccountSnapshot - account balance information
"""
@sp.utils.view(TAccountSnapshot)
def getAccountSnapshot(self, params):
pass
"""
Return the borrow balance of account based on stored data
params: TAddress - The address whose balance should be calculated
return: The calculated balance
"""
@sp.utils.view(sp.TNat)
def borrowBalanceStored(self, params):
pass
"""
Calculates the exchange rate from the underlying to the CToken
dev: This function does not accrue interest before calculating the exchange rate
dev: Do accrueInterest() before this function to get the up-to-date exchange rate
params: TUnit
return: Calculated exchange rate scaled by 1e18
"""
@sp.utils.view(sp.TPair(sp.TNat, sp.TNat))
def exchangeRateStored(self, params):
pass
"""
Get cash balance of this cToken in the underlying asset
params: TUnit
return: The quantity of underlying asset owned by this contract
"""
@sp.utils.view(sp.TPair(sp.TNat, sp.TNat))
def getCash(self, params):
pass
"""
Applies accrued interest to total borrows and reserves.
dev: This calculates interest accrued from the last checkpointed block
up to the current block and writes new checkpoint to storage.
params: TUnit
"""
@sp.entry_point
def accrueInterest(self, params):
pass
"""
Sets a new pending governance for the market
dev: Governance function to set a new governance
params: TAddress - The address of the new pending governance contract
"""
@sp.entry_point
def setPendingGovernance(self, pendingAdminAddress):
pass
"""
Accept a new governance for the market
dev: Governance function to set a new governance
unusedArg: TUnit
"""
@sp.entry_point
def acceptGovernance(self, unusedArg):
pass
"""
Remove pending governance for the market
dev: Governance function to set a remove pending governance
unusedArg: TUnit
"""
@sp.entry_point
def removePendingGovernance(self, unusedArg):
pass
"""
Sets a new comptroller for the market
dev: Governance function to set a new comptroller
comptrollerAddress: TAddress - The address of the new comptroller contract
"""
@sp.entry_point
def setComptroller(self, comptrollerAddress):
pass
"""
Accrues interest and updates the interest rate model using _setInterestRateModelFresh
dev: Governance function to accrue interest and update the interest rate model
interestRateModelAddress: TAddress - The address of the new interest rate model contract
"""
@sp.entry_point
def setInterestRateModel(self, interestRateModelAddress):
pass
"""
accrues interest and sets a new reserve factor for the protocol
dev: Governance function to accrue interest and set a new reserve factor
newReserveFactor: TNat - New reserve factor value
"""
@sp.entry_point
def setReserveFactor(self, newReserveFactor):
pass
"""
Accrues interest and adds reserves by transferring from admin
amount: TNat - Amount of reserves to add
"""
@sp.entry_point
def addReserves(self, amount):
pass
"""
Accrues interest and reduces reserves by transferring to admin
amount: TNat - Amount of reduction to reserves
"""
@sp.entry_point
def reduceReserves(self, amount):
pass