-
Notifications
You must be signed in to change notification settings - Fork 47
/
Copy pathISovryn.sol
520 lines (402 loc) · 16.2 KB
/
ISovryn.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
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
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
/**
* Copyright 2017-2020, bZeroX, LLC. All Rights Reserved.
* Licensed under the Apache License, Version 2.0.
*/
pragma solidity >=0.5.0 <0.6.0;
pragma experimental ABIEncoderV2;
//TODO: stored in ./interfaces only while brownie isn't removed
//TODO: move to contracts/interfaces after with brownie is removed
import "../core/State.sol";
import "../events/ProtocolSettingsEvents.sol";
import "../events/LoanSettingsEvents.sol";
import "../events/LoanOpeningsEvents.sol";
import "../events/LoanMaintenanceEvents.sol";
import "../events/LoanClosingsEvents.sol";
import "../events/FeesEvents.sol";
import "../events/SwapsEvents.sol";
import "../events/AffiliatesEvents.sol";
import "../connectors/loantoken/lib/MarginTradeStructHelpers.sol";
contract ISovryn is
State,
ProtocolSettingsEvents,
LoanSettingsEvents,
LoanOpeningsEvents,
LoanMaintenanceEvents,
LoanClosingsEvents,
SwapsEvents,
AffiliatesEvents,
FeesEvents
{
/// Triggered whenever interest is paid to lender.
event PayInterestTransfer(
address indexed interestToken,
address indexed lender,
uint256 effectiveInterest
);
////// Protocol //////
function replaceContract(address target) external;
function setTargets(string[] calldata sigsArr, address[] calldata targetsArr) external;
function getTarget(string calldata sig) external view returns (address);
////// Protocol Settings //////
function setSovrynProtocolAddress(address newProtocolAddress) external;
function setSOVTokenAddress(address newSovTokenAddress) external;
function setLockedSOVAddress(address newSOVLockedAddress) external;
function setMinReferralsToPayoutAffiliates(uint256 newMinReferrals) external;
function setPriceFeedContract(address newContract) external;
function setSwapsImplContract(address newContract) external;
function setLoanPool(address[] calldata pools, address[] calldata assets) external;
function setSupportedTokens(address[] calldata addrs, bool[] calldata toggles) external;
function setLendingFeePercent(uint256 newValue) external;
function setTradingFeePercent(uint256 newValue) external;
function setBorrowingFeePercent(uint256 newValue) external;
function setSwapExternalFeePercent(uint256 newValue) external;
function setAffiliateFeePercent(uint256 newValue) external;
function setAffiliateTradingTokenFeePercent(uint256 newValue) external;
function setLiquidationIncentivePercent(uint256 newAmount) external;
function setMaxDisagreement(uint256 newAmount) external;
function setSourceBuffer(uint256 newAmount) external;
function setMaxSwapSize(uint256 newAmount) external;
function setFeesController(address newController) external;
function withdrawFees(
address[] calldata tokens,
address receiver
) external returns (uint256 totalWRBTCWithdrawn);
function withdrawLendingFees(
address token,
address receiver,
uint256 amount
) external returns (bool);
function withdrawTradingFees(
address token,
address receiver,
uint256 amount
) external returns (bool);
function withdrawBorrowingFees(
address token,
address receiver,
uint256 amount
) external returns (bool);
function withdrawProtocolToken(
address receiver,
uint256 amount
) external returns (address, bool);
function depositProtocolToken(uint256 amount) external;
function getLoanPoolsList(
uint256 start,
uint256 count
) external view returns (bytes32[] memory);
function isLoanPool(address loanPool) external view returns (bool);
function setWrbtcToken(address wrbtcTokenAddress) external;
function setSovrynSwapContractRegistryAddress(address registryAddress) external;
function setProtocolTokenAddress(address _protocolTokenAddress) external;
function setRolloverBaseReward(uint256 transactionCost) external;
function setRebatePercent(uint256 rebatePercent) external;
function setSpecialRebates(
address sourceToken,
address destToken,
uint256 specialRebatesPercent
) external;
function getSpecialRebates(
address sourceToken,
address destToken
) external view returns (uint256 specialRebatesPercent);
function togglePaused(bool paused) external;
function isProtocolPaused() external view returns (bool);
////// SwapsImplSovrynSwapModule //////
function getSovrynSwapNetworkContract(
address sovrynSwapRegistryAddress
) public view returns (address);
function getContractHexName(string calldata source) external pure returns (bytes32 result);
function swapsImplExpectedRate(
address sourceTokenAddress,
address destTokenAddress,
uint256 sourceTokenAmount
) external view returns (uint256);
function swapsImplExpectedReturn(
address sourceTokenAddress,
address destTokenAddress,
uint256 sourceTokenAmount
) external view returns (uint256 expectedReturn);
////// Loan Settings //////
function setupLoanParams(
LoanParams[] calldata loanParamsList
) external returns (bytes32[] memory loanParamsIdList);
// Deactivates LoanParams for future loans. Active loans using it are unaffected.
function disableLoanParams(bytes32[] calldata loanParamsIdList) external;
function getLoanParams(
bytes32[] calldata loanParamsIdList
) external view returns (LoanParams[] memory loanParamsList);
function getLoanParamsList(
address owner,
uint256 start,
uint256 count
) external view returns (bytes32[] memory loanParamsList);
function getTotalPrincipal(address lender, address loanToken) external view returns (uint256);
function minInitialMargin(bytes32 loanParamsId) external view returns (uint256);
////// Loan Openings //////
function borrowOrTradeFromPool(
bytes32 loanParamsId,
bytes32 loanId, // if 0, start a new loan
bool isTorqueLoan,
uint256 initialMargin,
MarginTradeStructHelpers.SentAddresses calldata sentAddresses,
// lender: must match loan if loanId provided
// borrower: must match loan if loanId provided
// receiver: receiver of funds (address(0) assumes borrower address)
// manager: delegated manager of loan unless address(0)
MarginTradeStructHelpers.SentAmounts calldata sentValues,
// newRate: new loan interest rate
// newPrincipal: new loan size (borrowAmount + any borrowed interest)
// torqueInterest: new amount of interest to escrow for Torque loan (determines initial loan length)
// loanTokenReceived: total loanToken deposit (amount not sent to borrower in the case of Torque loans)
// collateralTokenReceived: total collateralToken deposit
bytes calldata loanDataBytes
) external payable returns (uint256 newPrincipal, uint256 newCollateral);
function setDelegatedManager(bytes32 loanId, address delegated, bool toggle) external;
function getEstimatedMarginExposure(
address loanToken,
address collateralToken,
uint256 loanTokenSent,
uint256 collateralTokenSent,
uint256 interestRate,
uint256 newPrincipal
) external view returns (uint256);
function getRequiredCollateral(
address loanToken,
address collateralToken,
uint256 newPrincipal,
uint256 marginAmount,
bool isTorqueLoan
) external view returns (uint256 collateralAmountRequired);
function getBorrowAmount(
address loanToken,
address collateralToken,
uint256 collateralTokenAmount,
uint256 marginAmount,
bool isTorqueLoan
) external view returns (uint256 borrowAmount);
////// Loan Closings //////
function liquidate(
bytes32 loanId,
address receiver,
uint256 closeAmount // denominated in loanToken
)
external
payable
returns (uint256 loanCloseAmount, uint256 seizedAmount, address seizedToken);
function rollover(bytes32 loanId, bytes calldata loanDataBytes) external;
function closeWithDeposit(
bytes32 loanId,
address receiver,
uint256 depositAmount // denominated in loanToken
)
external
payable
returns (uint256 loanCloseAmount, uint256 withdrawAmount, address withdrawToken);
function closeWithSwap(
bytes32 loanId,
address receiver,
uint256 swapAmount, // denominated in collateralToken
bool returnTokenIsCollateral, // true: withdraws collateralToken, false: withdraws loanToken
bytes calldata loanDataBytes
) external returns (uint256 loanCloseAmount, uint256 withdrawAmount, address withdrawToken);
////// Loan Maintenance //////
function depositCollateral(
bytes32 loanId,
uint256 depositAmount // must match msg.value if ether is sent
) external payable;
function withdrawCollateral(
bytes32 loanId,
address receiver,
uint256 withdrawAmount
) external returns (uint256 actualWithdrawAmount);
function withdrawAccruedInterest(address loanToken) external;
function getLenderInterestData(
address lender,
address loanToken
)
external
view
returns (
uint256 interestPaid,
uint256 interestPaidDate,
uint256 interestOwedPerDay,
uint256 interestUnPaid,
uint256 interestFeePercent,
uint256 principalTotal
);
function getLoanInterestData(
bytes32 loanId
)
external
view
returns (
address loanToken,
uint256 interestOwedPerDay,
uint256 interestDepositTotal,
uint256 interestDepositRemaining
);
struct LoanReturnData {
bytes32 loanId;
address loanToken;
address collateralToken;
uint256 principal;
uint256 collateral;
uint256 interestOwedPerDay;
uint256 interestDepositRemaining;
uint256 startRate; // collateralToLoanRate
uint256 startMargin;
uint256 maintenanceMargin;
uint256 currentMargin;
uint256 maxLoanTerm;
uint256 endTimestamp;
uint256 maxLiquidatable;
uint256 maxSeizable;
}
struct LoanReturnDataV2 {
bytes32 loanId;
address loanToken;
address collateralToken;
address borrower;
uint256 principal;
uint256 collateral;
uint256 interestOwedPerDay;
uint256 interestDepositRemaining;
uint256 startRate; /// collateralToLoanRate
uint256 startMargin;
uint256 maintenanceMargin;
uint256 currentMargin;
uint256 maxLoanTerm;
uint256 endTimestamp;
uint256 maxLiquidatable;
uint256 maxSeizable;
uint256 creationTimestamp;
}
function getUserLoans(
address user,
uint256 start,
uint256 count,
uint256 loanType,
bool isLender,
bool unsafeOnly
) external view returns (LoanReturnData[] memory loansData);
function getUserLoansV2(
address user,
uint256 start,
uint256 count,
uint256 loanType,
bool isLender,
bool unsafeOnly
) external view returns (LoanReturnDataV2[] memory loansDataV2);
function getLoan(bytes32 loanId) external view returns (LoanReturnData memory loanData);
function getLoanV2(bytes32 loanId) external view returns (LoanReturnDataV2 memory loanDataV2);
function getActiveLoans(
uint256 start,
uint256 count,
bool unsafeOnly
) external view returns (LoanReturnData[] memory loansData);
function getActiveLoansV2(
uint256 start,
uint256 count,
bool unsafeOnly
) external view returns (LoanReturnDataV2[] memory loansDataV2);
function extendLoanDuration(
bytes32 loanId,
uint256 depositAmount,
bool useCollateral,
bytes calldata /// loanDataBytes, for future use.
) external returns (uint256 secondsExtended);
function reduceLoanDuration(
bytes32 loanId,
address receiver,
uint256 withdrawAmount
) external returns (uint256 secondsReduced);
////// Swaps External //////
function swapExternal(
address sourceToken,
address destToken,
address receiver,
address returnToSender,
uint256 sourceTokenAmount,
uint256 requiredDestTokenAmount,
uint256 minReturn,
bytes calldata swapData
) external returns (uint256 destTokenAmountReceived, uint256 sourceTokenAmountUsed);
function getSwapExpectedReturn(
address sourceToken,
address destToken,
uint256 sourceTokenAmount
) external view returns (uint256);
function checkPriceDivergence(
address sourceToken,
address destToken,
uint256 sourceTokenAmount,
uint256 minReturn
) public view;
////// Affiliates Module //////
function getUserNotFirstTradeFlag(address user) external view returns (bool);
function setUserNotFirstTradeFlag(address user) external;
function payTradingFeeToAffiliatesReferrer(
address referrer,
address trader,
address token,
uint256 tradingFeeTokenBaseAmount
) external returns (uint256 affiliatesBonusSOVAmount, uint256 affiliatesBonusTokenAmount);
function setAffiliatesReferrer(address user, address referrer) external; //onlyCallableByLoanPools
function getReferralsList(address referrer) external view returns (address[] memory refList);
function getAffiliatesReferrerBalances(
address referrer
)
external
view
returns (address[] memory referrerTokensList, uint256[] memory referrerTokensBalances);
function getAffiliatesReferrerTokensList(
address referrer
) external view returns (address[] memory tokensList);
function getAffiliatesReferrerTokenBalance(
address referrer,
address token
) external view returns (uint256);
function withdrawAffiliatesReferrerTokenFees(
address token,
address receiver,
uint256 amount
) external;
function withdrawAllAffiliatesReferrerTokenFees(address receiver) external;
function getProtocolAddress() external view returns (address);
function getSovTokenAddress() external view returns (address);
function getLockedSOVAddress() external view returns (address);
function getFeeRebatePercent() external view returns (uint256);
function getMinReferralsToPayout() external view returns (uint256);
function getAffiliatesUserReferrer(address user) external view returns (address referrer);
function getAffiliateRewardsHeld(address referrer) external view returns (uint256);
function getAffiliateTradingTokenFeePercent()
external
view
returns (uint256 affiliateTradingTokenFeePercent);
function getAffiliatesTokenRewardsValueInRbtc(
address referrer
) external view returns (uint256 rbtcTotalAmount);
function getSwapExternalFeePercent() external view returns (uint256 swapExternalFeePercent);
function setTradingRebateRewardsBasisPoint(uint256 newBasisPoint) external;
function getTradingRebateRewardsBasisPoint() external view returns (uint256);
function getDedicatedSOVRebate() external view returns (uint256);
function setRolloverFlexFeePercent(uint256 newRolloverFlexFeePercent) external;
function getDefaultPathConversion(
address sourceTokenAddress,
address destTokenAddress
) external view returns (IERC20[] memory);
function setDefaultPathConversion(IERC20[] calldata defaultPath) external;
function removeDefaultPathConversion(
address sourceTokenAddress,
address destTokenAddress
) external;
function checkCloseWithDepositIsTinyPosition(
bytes32 loanId,
uint256 depositAmount
) external view returns (bool isTinyPosition, uint256 tinyPositionAmount);
function setAdmin(address newAdmin) external;
function getAdmin() external view returns (address);
function setPauser(address newPauser) external;
function getPauser() external view returns (address);
}