-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathComptrollerMock.py
More file actions
166 lines (130 loc) · 5.28 KB
/
Copy pathComptrollerMock.py
File metadata and controls
166 lines (130 loc) · 5.28 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
import smartpy as sp
CTI = sp.io.import_script_from_url("file:contracts/interfaces/CTokenInterface.py")
CMPTInterface = sp.io.import_script_from_url("file:contracts/interfaces/ComptrollerInterface.py")
class ComptrollerMock(CMPTInterface.ComptrollerInterface):
def __init__(self, **extra_storage):
self.init(
mint_allowed = sp.bool(True),
borrow_allowed = sp.bool(True),
redeem_allowed = sp.bool(True),
repay_borrow_allowed = sp.bool(True),
markets = sp.set(t=sp.TAddress),
loans=sp.big_map(l={}, tkey=sp.TAddress,
tvalue=sp.TSet(sp.TAddress)),
**extra_storage
)
@sp.entry_point
def enterMarkets(self, params):
sp.set_type(params, sp.TAddress)
self.data.markets.add(params)
@sp.entry_point
def exitMarket(self, params):
sp.set_type(params, sp.TUnit)
@sp.entry_point
def mintAllowed(self, params):
sp.set_type(params, CMPTInterface.TMintAllowedParams)
sp.verify(self.data.mint_allowed)
@sp.entry_point
def setMintAllowed(self, params):
self.data.mint_allowed = params
@sp.entry_point
def redeemAllowed(self, params):
sp.set_type(params, CMPTInterface.TRedeemAllowedParams)
sp.verify(self.data.redeem_allowed)
@sp.entry_point
def setRedeemAllowed(self, params):
self.data.redeem_allowed = params
@sp.entry_point
def borrowAllowed(self, params):
sp.set_type(params, CMPTInterface.TBorrowAllowedParams)
sp.verify(self.data.borrow_allowed)
sp.if ~ self.data.loans.contains(params.borrower):
# only cTokens may call borrowAllowed if borrower not in market
sp.verify(sp.sender == params.cToken,
"Invalid sender for borrowAllowed")
sp.if sp.sender == params.cToken:
sp.if self.data.loans.contains(params.borrower):
self.data.loans[params.borrower].add(params.cToken)
sp.else:
self.data.loans[params.borrower] = sp.set([params.cToken])
@sp.entry_point
def setBorrowAllowed(self, params):
self.data.borrow_allowed = params
@sp.entry_point
def repayBorrowAllowed(self, params):
sp.set_type(params, CMPTInterface.TRepayBorrowAllowedParams)
sp.verify(self.data.repay_borrow_allowed)
@sp.entry_point
def liquidateBorrowAllowed(self, params):
sp.set_type(params, CMPTInterface.TLiquidateBorrowAllowed)
@sp.onchain_view()
def liquidateCalculateSeizeTokens(self, params):
sp.set_type(params, CMPTInterface.TLiquidateCalculateSeizeTokens)
# The exact collateral valuation is not relevant to cash movement in
# these tests; one cToken is enough to complete the liquidation path.
sp.result(sp.pair(sp.nat(1), sp.nat(0)))
@sp.onchain_view()
def seizeAllowed(self, params):
sp.set_type(params, sp.TRecord(cTokenCollateral=sp.TAddress, cTokenBorrowed=sp.TAddress))
sp.result(sp.bool(True))
@sp.entry_point
def setRepayBorrowAllowed(self, params):
self.data.repay_borrow_allowed = params
@sp.entry_point
def transferAllowed(self, params):
sp.set_type(params, CMPTInterface.TTransferAllowedParams)
@sp.entry_point
def updateAssetPrice(self, asset):
sp.set_type(asset, sp.TAddress)
@sp.entry_point
def updateAccountLiquidity(self, account):
sp.set_type(account, sp.TAddress)
@sp.entry_point
def getHypoAccountLiquidity(self, params):
sp.set_type(params, sp.TUnit)
# Admin functions
@sp.entry_point
def setPricePeriodRelevance(self, blockNumber):
sp.set_type(blockNumber, sp.TNat)
@sp.entry_point
def setLiquidityPeriodRelevance(self, blockNumber):
sp.set_type(blockNumber, sp.TNat)
@sp.entry_point
def setPendingGovernance(self, pendingAdminAddress):
sp.set_type(pendingAdminAddress, sp.TAddress)
@sp.entry_point(lazify=True)
def removeFromLoans(self, borrower):
sp.set_type(borrower, sp.TAddress)
@sp.entry_point
def acceptGovernance(self, unusedArg):
sp.set_type(unusedArg, sp.TAddress)
@sp.entry_point
def setPriceOracleAndTimeDiff(self, params):
sp.set_type(params, sp.TUnit)
@sp.entry_point
def setCloseFactor(self, params):
sp.set_type(params, sp.TUnit)
@sp.entry_point
def setCollateralFactor(self, params):
sp.set_type(params, sp.TUnit)
@sp.entry_point
def setLiquidationIncentive(self, params):
sp.set_type(params, sp.TUnit)
@sp.entry_point
def supportMarket(self, params):
sp.set_type(params, sp.TUnit)
@sp.entry_point
def disableMarket(self, params):
sp.set_type(params, sp.TUnit)
@sp.entry_point
def setMintPaused(self, params):
sp.set_type(params, sp.TUnit)
@sp.entry_point
def setBorrowPaused(self, params):
sp.set_type(params, sp.TUnit)
@sp.entry_point
def setRedeemPaused(self, params):
sp.set_type(params, sp.TUnit)
@sp.entry_point
def setTransferPaused(self, params):
sp.set_type(params, sp.TUnit)