-
Notifications
You must be signed in to change notification settings - Fork 15
/
WildcatMarketConfig.sol
194 lines (169 loc) Β· 7.24 KB
/
WildcatMarketConfig.sol
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
// SPDX-License-Identifier: MIT
pragma solidity >=0.8.20;
import '../interfaces/IWildcatSanctionsSentinel.sol';
import '../libraries/FeeMath.sol';
import '../libraries/SafeCastLib.sol';
import './WildcatMarketBase.sol';
contract WildcatMarketConfig is WildcatMarketBase {
using SafeCastLib for uint256;
using BoolUtils for bool;
// ===================================================================== //
// External Config Getters //
// ===================================================================== //
/**
* @dev Returns the maximum amount of underlying asset that can
* currently be deposited to the market.
*/
function maximumDeposit() external view returns (uint256) {
MarketState memory state = currentState();
return state.maximumDeposit();
}
/**
* @dev Returns the maximum supply the market can reach via
* deposits (does not apply to interest accrual).
*/
function maxTotalSupply() external view returns (uint256) {
return _state.maxTotalSupply;
}
/**
* @dev Returns the annual interest rate earned by lenders
* in bips.
*/
function annualInterestBips() external view returns (uint256) {
return _state.annualInterestBips;
}
function reserveRatioBips() external view returns (uint256) {
return _state.reserveRatioBips;
}
/* -------------------------------------------------------------------------- */
/* Sanctions */
/* -------------------------------------------------------------------------- */
/// @dev Block a sanctioned account from interacting with the market
/// and transfer its balance to an escrow contract.
// ******************************************************************
// * |\**/| * * *
// * \ == / * * *
// * | b| * * *
// * | y| * * *
// * \ e/ * * *
// * \/ * * *
// * * * *
// * * * *
// * * |\**/| * *
// * * \ == / * _.-^^---....,,-- *
// * * | b| * _-- --_ *
// * * | y| * < >) *
// * * \ e/ * | O-FAC! | *
// * * \/ * \._ _./ *
// * * * ```--. . , ; .--''' *
// * * * πΈ | | | *
// * * * .-=|| | |=-. πΈ *
// π°π€π° * π
* π * πΈ `-=#$%&%$#=-' *
// \|/ * /|\ * /|\ * πͺ | ; :| πͺ *
// /\ * π°/\ π° * π°/\ π° * _____.,-#%&$@%#&#~,._____ *
// ******************************************************************
function nukeFromOrbit(address accountAddress) external nonReentrant {
if (!IWildcatSanctionsSentinel(sentinel).isSanctioned(borrower, accountAddress)) {
revert BadLaunchCode();
}
MarketState memory state = _getUpdatedState();
_blockAccount(state, accountAddress);
_writeState(state);
}
/**
* @dev Unblock an account that was previously sanctioned and blocked
* and has since been removed from the sanctions list or had
* their sanctioned status overridden by the borrower.
*/
function stunningReversal(address accountAddress) external nonReentrant {
Account memory account = _accounts[accountAddress];
if (account.approval != AuthRole.Blocked) {
revert AccountNotBlocked();
}
if (IWildcatSanctionsSentinel(sentinel).isSanctioned(borrower, accountAddress)) {
revert NotReversedOrStunning();
}
account.approval = AuthRole.Null;
emit AuthorizationStatusUpdated(accountAddress, account.approval);
_accounts[accountAddress] = account;
}
/* -------------------------------------------------------------------------- */
/* External Config Setters */
/* -------------------------------------------------------------------------- */
/**
* @dev Updates an account's authorization status based on whether the controller
* has it marked as approved.
*/
function updateAccountAuthorization(
address _account,
bool _isAuthorized
) external onlyController nonReentrant {
MarketState memory state = _getUpdatedState();
Account memory account = _getAccount(_account);
if (_isAuthorized) {
account.approval = AuthRole.DepositAndWithdraw;
} else {
account.approval = AuthRole.WithdrawOnly;
}
_accounts[_account] = account;
_writeState(state);
emit AuthorizationStatusUpdated(_account, account.approval);
}
/**
* @dev Sets the maximum total supply - this only limits deposits and
* does not affect interest accrual.
*
* Can not be set lower than current total supply.
*/
function setMaxTotalSupply(uint256 _maxTotalSupply) external onlyController nonReentrant {
MarketState memory state = _getUpdatedState();
if (_maxTotalSupply < state.totalSupply()) {
revert NewMaxSupplyTooLow();
}
state.maxTotalSupply = _maxTotalSupply.toUint128();
_writeState(state);
emit MaxTotalSupplyUpdated(_maxTotalSupply);
}
/**
* @dev Sets the annual interest rate earned by lenders in bips.
*/
function setAnnualInterestBips(uint16 _annualInterestBips) public onlyController nonReentrant {
MarketState memory state = _getUpdatedState();
if (_annualInterestBips > BIP) {
revert InterestRateTooHigh();
}
state.annualInterestBips = _annualInterestBips;
_writeState(state);
emit AnnualInterestBipsUpdated(_annualInterestBips);
}
/**
* @dev Adjust the market's reserve ratio.
*
* If the new ratio is lower than the old ratio,
* asserts that the market is not currently delinquent.
*
* If the new ratio is higher than the old ratio,
* asserts that the market will not become delinquent
* because of the change.
*/
function setReserveRatioBips(uint16 _reserveRatioBips) public onlyController nonReentrant {
if (_reserveRatioBips > BIP) {
revert ReserveRatioBipsTooHigh();
}
MarketState memory state = _getUpdatedState();
uint256 initialReserveRatioBips = state.reserveRatioBips;
if (_reserveRatioBips < initialReserveRatioBips) {
if (state.liquidityRequired() > totalAssets()) {
revert InsufficientReservesForOldLiquidityRatio();
}
}
state.reserveRatioBips = _reserveRatioBips;
if (_reserveRatioBips > initialReserveRatioBips) {
if (state.liquidityRequired() > totalAssets()) {
revert InsufficientReservesForNewLiquidityRatio();
}
}
_writeState(state);
emit ReserveRatioBipsUpdated(_reserveRatioBips);
}
}