-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b676e76
commit a6e88d1
Showing
16 changed files
with
327 additions
and
207 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
{ | ||
"fixedLeg": "0xe7FD3ee1d1c70c87234ec57C2B036Ad8c0Fd0173", | ||
"floatLeg": "0x6ae11ef30f1eC6e641E9B43725b20a172b0F090E", | ||
"swap": "0x748b032161b2070C6DFeEe3a05C622ad61A71900", | ||
"timelock": "0x205C15322d223E4DC66976F7E0f62fC2Fc3D0a86" | ||
"fixedLeg": "0xEdaE78BbaB80eE01dC4C703e40b795a77e18D7fc", | ||
"floatLeg": "0x758B1FF29c5eba7A07bA7B3564A0416E6FF8e98e", | ||
"swap": "0x6719f470ae32b505e12c3F46DfC8998Da07E7e50", | ||
"timelock": "0x5e7E4584973305B901B950E66249D90C8099858F" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
{ | ||
"fixedLeg": "0xe7FD3ee1d1c70c87234ec57C2B036Ad8c0Fd0173", | ||
"floatLeg": "0x6ae11ef30f1eC6e641E9B43725b20a172b0F090E", | ||
"swap": "0x748b032161b2070C6DFeEe3a05C622ad61A71900", | ||
"timelock": "0x205C15322d223E4DC66976F7E0f62fC2Fc3D0a86" | ||
"fixedLeg": "0x130947FE7a04921faD22D9c3400ecf7e16AEbE98", | ||
"floatLeg": "0xEdaE78BbaB80eE01dC4C703e40b795a77e18D7fc", | ||
"swap": "0x92785E3144218F1e7b755a2D090B0c2AC1FdD5aD", | ||
"timelock": "0x5e7E4584973305B901B950E66249D90C8099858F" | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
pragma solidity >=0.4.22 <0.9.0; | ||
|
||
interface IInterest { | ||
function rate() external view returns (uint); | ||
function accrewedMul() external view returns (uint); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
pragma solidity ^0.8.11; | ||
|
||
import "./IInterest.sol"; | ||
import "./Math.sol"; | ||
import "./IModel.sol"; | ||
import "@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol"; | ||
|
||
/// @notice Tracks accrewed interest | ||
contract Interest is IInterest, Initializable { | ||
using Math for uint; | ||
|
||
uint constant ONE = 10**18; | ||
uint constant ONE_26 = 10**26; | ||
uint constant ONE_8 = 10**8; | ||
uint constant COMPOUNDING_PERIOD = 3600; // 1 hour | ||
|
||
/// @notice 1 + hourly interest rate. < 1 represents a negative rate | ||
/// @dev 18-decimal fixed-point | ||
uint public rate; | ||
|
||
/// @notice Timestamp of when interest began accrewing | ||
/// @dev start at a perfect multiple of COMPOUNDING_PERIOD so all contracts are synced | ||
uint internal startTime; | ||
|
||
/// @notice Value of accumulated interest multiplier when interest began accrewing | ||
/// @dev 26-decimal fixed-point | ||
uint internal startValue; | ||
|
||
function initialize() internal onlyInitializing { | ||
rate = ONE; | ||
startTime = (block.timestamp / COMPOUNDING_PERIOD) * COMPOUNDING_PERIOD; | ||
startValue = ONE_26; | ||
} | ||
|
||
/// @notice Accrewed interest multiplier. Nominal value of 1 fixedLeg token in denominating currency | ||
/// @return Target currency-fixed exchange rate, expressed as denominating currency per fixed. 26-decimal fixed-point | ||
function accrewedMul() public view returns (uint) { | ||
unchecked { | ||
return startValue * (rate*ONE_8).pow((block.timestamp - startTime) / COMPOUNDING_PERIOD) / ONE_26; | ||
} | ||
} | ||
|
||
/// @notice Update interest rate according to model | ||
function _updateRate(IModel model, uint potValue, uint fixedTV, uint _accrewedMul) internal { | ||
uint _rate = uint(int(ONE) + model.getInterestRate(potValue, fixedTV)); | ||
if (_rate != rate) { | ||
_setRate(_rate, _accrewedMul); | ||
} | ||
} | ||
|
||
/// @notice Change the hourly interest rate. May represent a negative rate. | ||
/// @param _rate 18-decimal fixed-point. 1 + hourly interest rate. | ||
function _setRate(uint _rate, uint _accrewedMul) internal { | ||
startValue = _accrewedMul; | ||
startTime = startTime + (((block.timestamp - startTime) / COMPOUNDING_PERIOD) * COMPOUNDING_PERIOD); | ||
rate = _rate; | ||
} | ||
} |
Oops, something went wrong.