-
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
Showing
25 changed files
with
565 additions
and
59 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
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
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
45 changes: 45 additions & 0 deletions
45
contracts/rates/controllers/proto/ionic/IonicRateController.sol
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,45 @@ | ||
// SPDX-License-Identifier: BUSL-1.1 | ||
pragma solidity =0.8.13; | ||
|
||
import "../../../ManagedRateController.sol"; | ||
import "../../../../vendor/ionic/IComptroller.sol"; | ||
import "../../../../vendor/ionic/ICToken.sol"; | ||
|
||
contract IonicRateController is ManagedRateController { | ||
IComptroller public immutable comptroller; | ||
|
||
error CTokenNotFound(address token); | ||
|
||
error FailedToAccrueInterest(address token, address cToken, uint256 errorCode); | ||
|
||
constructor( | ||
IComptroller comptroller_, | ||
bool computeAhead_, | ||
uint32 period_, | ||
uint8 initialBufferCardinality_, | ||
bool updatersMustBeEoa_ | ||
) ManagedRateController(computeAhead_, period_, initialBufferCardinality_, updatersMustBeEoa_) { | ||
comptroller = comptroller_; | ||
} | ||
|
||
/// @dev Overridden to accrue interest for the prior rate before pushing the new rate. | ||
function push(address token, RateLibrary.Rate memory rate) internal virtual override { | ||
// Try and accrue interest if we have a prior rate | ||
if (rateBufferMetadata[token].size > 0) { | ||
address cToken = comptroller.cTokensByUnderlying(token); | ||
if (cToken == address(0)) { | ||
// Note that this check is not applied for the first rate to allow for the initial rate to be set | ||
// before the cToken is added to the comptroller. | ||
revert CTokenNotFound(token); | ||
} | ||
|
||
// Accrue interest for the prior rate before pushing the new rate | ||
uint256 accrueCode = ICToken(cToken).accrueInterest(); | ||
if (accrueCode != 0) { | ||
revert FailedToAccrueInterest(token, cToken, accrueCode); | ||
} | ||
} | ||
|
||
super.push(token, rate); | ||
} | ||
} |
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
Oops, something went wrong.