-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathIBorrowerOperations.sol
274 lines (247 loc) · 13.9 KB
/
IBorrowerOperations.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
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
// SPDX-License-Identifier: MIT
pragma solidity 0.6.11;
pragma experimental ABIEncoderV2;
import "../Dependencies/Mynt/IMassetManager.sol";
import { IPermit2, ISignatureTransfer } from "./IPermit2.sol";
/// Common interface for the Trove Manager.
interface IBorrowerOperations {
// --- Events ---
event FeeDistributorAddressChanged(address _feeDistributorAddress);
event TroveManagerAddressChanged(address _newTroveManagerAddress);
event ActivePoolAddressChanged(address _activePoolAddress);
event DefaultPoolAddressChanged(address _defaultPoolAddress);
event StabilityPoolAddressChanged(address _stabilityPoolAddress);
event GasPoolAddressChanged(address _gasPoolAddress);
event CollSurplusPoolAddressChanged(address _collSurplusPoolAddress);
event PriceFeedAddressChanged(address _newPriceFeedAddress);
event SortedTrovesAddressChanged(address _sortedTrovesAddress);
event ZUSDTokenAddressChanged(address _zusdTokenAddress);
event ZEROStakingAddressChanged(address _zeroStakingAddress);
event TroveCreated(address indexed _borrower, uint256 arrayIndex);
event TroveUpdated(
address indexed _borrower,
uint256 _debt,
uint256 _coll,
uint256 stake,
uint8 operation
);
event ZUSDBorrowingFeePaid(address indexed _borrower, uint256 _ZUSDFee);
// --- Functions ---
/**
* @notice Called only once on init, to set addresses of other Zero contracts. Callable only by owner
* @dev initializer function, checks addresses are contracts
* @param _feeDistributorAddress feeDistributor contract address
* @param _liquityBaseParamsAddress LiquidityBaseParams contract address
* @param _troveManagerAddress TroveManager contract address
* @param _activePoolAddress ActivePool contract address
* @param _defaultPoolAddress DefaultPool contract address
* @param _stabilityPoolAddress StabilityPool contract address
* @param _gasPoolAddress GasPool contract address
* @param _collSurplusPoolAddress CollSurplusPool contract address
* @param _priceFeedAddress PrideFeed contract address
* @param _sortedTrovesAddress SortedTroves contract address
* @param _zusdTokenAddress ZUSDToken contract address
* @param _zeroStakingAddress ZEROStaking contract address
*/
function setAddresses(
address _feeDistributorAddress,
address _liquityBaseParamsAddress,
address _troveManagerAddress,
address _activePoolAddress,
address _defaultPoolAddress,
address _stabilityPoolAddress,
address _gasPoolAddress,
address _collSurplusPoolAddress,
address _priceFeedAddress,
address _sortedTrovesAddress,
address _zusdTokenAddress,
address _zeroStakingAddress
) external;
/**
* @notice payable function that creates a Trove for the caller with the requested debt, and the Ether received as collateral.
* Successful execution is conditional mainly on the resulting collateralization ratio which must exceed the minimum (110% in Normal Mode, 150% in Recovery Mode).
* In addition to the requested debt, extra debt is issued to pay the issuance fee, and cover the gas compensation.
* The borrower has to provide a `_maxFeePercentage` that he/she is willing to accept in case of a fee slippage, i.e. when a redemption transaction is processed first, driving up the issuance fee.
* @param _maxFee max fee percentage to acept in case of a fee slippage
* @param _ZUSDAmount ZUSD requested debt
* @param _upperHint upper trove id hint
* @param _lowerHint lower trove id hint
*/
function openTrove(
uint256 _maxFee,
uint256 _ZUSDAmount,
address _upperHint,
address _lowerHint
) external payable;
/**
* @notice payable function that creates a Trove for the caller with the requested debt, and the Ether received as collateral.
* Successful execution is conditional mainly on the resulting collateralization ratio which must exceed the minimum (110% in Normal Mode, 150% in Recovery Mode).
* In addition to the requested debt, extra debt is issued to pay the issuance fee, and cover the gas compensation.
* The borrower has to provide a `_maxFeePercentage` that he/she is willing to accept in case of a fee slippage, i.e. when a redemption transaction is processed first, driving up the issuance fee.
* This method is identical to `openTrove()`, but operates on NUE tokens instead of ZUSD.
* @param _maxFee max fee percentage to acept in case of a fee slippage
* @param _ZUSDAmount ZUSD requested debt
* @param _upperHint upper trove id hint
* @param _lowerHint lower trove id hint
*/
function openNueTrove(
uint256 _maxFee,
uint256 _ZUSDAmount,
address _upperHint,
address _lowerHint
) external payable;
/// @notice payable function that adds the received Ether to the caller's active Trove.
/// @param _upperHint upper trove id hint
/// @param _lowerHint lower trove id hint
function addColl(address _upperHint, address _lowerHint) external payable;
/// @notice send ETH as collateral to a trove. Called by only the Stability Pool.
/// @param _user user trove address
/// @param _upperHint upper trove id hint
/// @param _lowerHint lower trove id hint
function moveETHGainToTrove(
address _user,
address _upperHint,
address _lowerHint
) external payable;
/**
* @notice withdraws `_amount` of collateral from the caller’s Trove.
* Executes only if the user has an active Trove, the withdrawal would not pull the user’s Trove below the minimum collateralization ratio,
* and the resulting total collateralization ratio of the system is above 150%.
* @param _amount collateral amount to withdraw
* @param _upperHint upper trove id hint
* @param _lowerHint lower trove id hint
*/
function withdrawColl(uint256 _amount, address _upperHint, address _lowerHint) external;
/**
* @notice issues `_amount` of ZUSD from the caller’s Trove to the caller.
* Executes only if the Trove's collateralization ratio would remain above the minimum, and the resulting total collateralization ratio is above 150%.
* The borrower has to provide a `_maxFeePercentage` that he/she is willing to accept in case of a fee slippage, i.e. when a redemption transaction is processed first, driving up the issuance fee.
* @param _maxFee max fee percentage to acept in case of a fee slippage
* @param _amount ZUSD amount to withdraw
* @param _upperHint upper trove id hint
* @param _lowerHint lower trove id hint
*/
function withdrawZUSD(
uint256 _maxFee,
uint256 _amount,
address _upperHint,
address _lowerHint
) external;
/// Borrow (withdraw) ZUSD tokens from a trove: mint new ZUSD tokens to the owner and convert it to DLLR in one transaction
function withdrawZusdAndConvertToDLLR(
uint256 _maxFeePercentage,
uint256 _ZUSDAmount,
address _upperHint,
address _lowerHint
) external returns (uint256);
/// @notice repay `_amount` of ZUSD to the caller’s Trove, subject to leaving 50 debt in the Trove (which corresponds to the 50 ZUSD gas compensation).
/// @param _amount ZUSD amount to repay
/// @param _upperHint upper trove id hint
/// @param _lowerHint lower trove id hint
function repayZUSD(uint256 _amount, address _upperHint, address _lowerHint) external;
/// Repay ZUSD tokens to a Trove: Burn the repaid ZUSD tokens, and reduce the trove's debt accordingly
function repayZusdFromDLLR(
uint256 _dllrAmount,
address _upperHint,
address _lowerHint,
IMassetManager.PermitParams calldata _permitParams
) external;
/// Repay ZUSD tokens to a Trove: Burn the repaid ZUSD tokens, and reduce the trove's debt accordingly
function repayZusdFromDLLRWithPermit2(
uint256 _dllrAmount,
address _upperHint,
address _lowerHint,
ISignatureTransfer.PermitTransferFrom memory _permit,
bytes calldata _signature
) external;
/**
* @notice allows a borrower to repay all debt, withdraw all their collateral, and close their Trove.
* Requires the borrower have a ZUSD balance sufficient to repay their trove's debt, excluding gas compensation - i.e. `(debt - 50)` ZUSD.
*/
function closeTrove() external;
/**
* @notice allows a borrower to repay all debt, withdraw all their collateral, and close their Trove.
* Requires the borrower have a NUE balance sufficient to repay their trove's debt, excluding gas compensation - i.e. `(debt - 50)` NUE.
* This method is identical to `closeTrove()`, but operates on NUE tokens instead of ZUSD.
*/
function closeNueTrove(IMassetManager.PermitParams calldata _permitParams) external;
/**
* @notice allows a borrower to repay all debt, withdraw all their collateral, and close their Trove.
* Requires the borrower have a NUE balance sufficient to repay their trove's debt, excluding gas compensation - i.e. `(debt - 50)` NUE.
* This method is identical to `closeTrove()`, but operates on NUE tokens instead of ZUSD.
*/
function closeNueTroveWithPermit2(ISignatureTransfer.PermitTransferFrom memory _permit, bytes calldata _signature) external;
/**
* @notice enables a borrower to simultaneously change both their collateral and debt, subject to all the restrictions that apply to individual increases/decreases of each quantity with the following particularity:
* if the adjustment reduces the collateralization ratio of the Trove, the function only executes if the resulting total collateralization ratio is above 150%.
* The borrower has to provide a `_maxFeePercentage` that he/she is willing to accept in case of a fee slippage, i.e. when a redemption transaction is processed first, driving up the issuance fee.
* The parameter is ignored if the debt is not increased with the transaction.
* @param _maxFee max fee percentage to acept in case of a fee slippage
* @param _collWithdrawal collateral amount to withdraw
* @param _debtChange ZUSD amount to change
* @param isDebtIncrease indicates if increases debt
* @param _upperHint upper trove id hint
* @param _lowerHint lower trove id hint
*/
function adjustTrove(
uint256 _maxFee,
uint256 _collWithdrawal,
uint256 _debtChange,
bool isDebtIncrease,
address _upperHint,
address _lowerHint
) external payable;
/**
* @notice enables a borrower to simultaneously change both their collateral and debt, subject to all the restrictions that apply to individual increases/decreases of each quantity with the following particularity:
* if the adjustment reduces the collateralization ratio of the Trove, the function only executes if the resulting total collateralization ratio is above 150%.
* The borrower has to provide a `_maxFeePercentage` that he/she is willing to accept in case of a fee slippage, i.e. when a redemption transaction is processed first, driving up the issuance fee.
* The parameter is ignored if the debt is not increased with the transaction.
* This method is identical to `adjustTrove()`, but operates on NUE tokens instead of ZUSD.
* @param _maxFee max fee percentage to acept in case of a fee slippage
* @param _collWithdrawal collateral amount to withdraw
* @param _debtChange ZUSD amount to change
* @param isDebtIncrease indicates if increases debt
* @param _upperHint upper trove id hint
* @param _lowerHint lower trove id hint
*/
function adjustNueTrove(
uint256 _maxFee,
uint256 _collWithdrawal,
uint256 _debtChange,
bool isDebtIncrease,
address _upperHint,
address _lowerHint,
IMassetManager.PermitParams calldata _permitParams
) external payable;
/**
* @notice enables a borrower to simultaneously change both their collateral and debt, subject to all the restrictions that apply to individual increases/decreases of each quantity with the following particularity:
* if the adjustment reduces the collateralization ratio of the Trove, the function only executes if the resulting total collateralization ratio is above 150%.
* The borrower has to provide a `_maxFeePercentage` that he/she is willing to accept in case of a fee slippage, i.e. when a redemption transaction is processed first, driving up the issuance fee.
* The parameter is ignored if the debt is not increased with the transaction.
* This method is identical to `adjustTrove()`, but operates on NUE tokens instead of ZUSD.
* @param _maxFee max fee percentage to acept in case of a fee slippage
* @param _collWithdrawal collateral amount to withdraw
* @param _debtChange ZUSD amount to change
* @param isDebtIncrease indicates if increases debt
* @param _upperHint upper trove id hint
* @param _lowerHint lower trove id hint
*/
function adjustNueTroveWithPermit2(
uint256 _maxFee,
uint256 _collWithdrawal,
uint256 _debtChange,
bool isDebtIncrease,
address _upperHint,
address _lowerHint,
ISignatureTransfer.PermitTransferFrom memory _permit,
bytes calldata _signature
) external payable;
/**
* @notice when a borrower’s Trove has been fully redeemed from and closed, or liquidated in Recovery Mode with a collateralization ratio above 110%,
* this function allows the borrower to claim their ETH collateral surplus that remains in the system (collateral - debt upon redemption; collateral - 110% of the debt upon liquidation).
*/
function claimCollateral() external;
function getCompositeDebt(uint256 _debt) external view returns (uint256);
function BORROWING_FEE_FLOOR() external view returns (uint256);
function getMassetManager() external view returns (IMassetManager);
}