LRTOracle

Erstellt Diff läuft nie ab
15 Entfernungen
316 Zeilen
50 Hinzufügungen
351 Zeilen
// SPDX-License-Identifier: BUSL-1.1
// SPDX-License-Identifier: BUSL-1.1
pragma solidity 0.8.27;
pragma solidity 0.8.27;


import { UtilLib } from "./utils/UtilLib.sol";
import { UtilLib } from "./utils/UtilLib.sol";
import { LRTConstants } from "./utils/LRTConstants.sol";
import { LRTConstants } from "./utils/LRTConstants.sol";
import { LRTConfigRoleChecker, ILRTConfig } from "./utils/LRTConfigRoleChecker.sol";
import { LRTConfigRoleChecker, ILRTConfig } from "./utils/LRTConfigRoleChecker.sol";
import { WadMath } from "./utils/WadMath.sol";
import { WadMath } from "./utils/WadMath.sol";


import { IRSETH } from "./interfaces/IRSETH.sol";
import { IRSETH } from "./interfaces/IRSETH.sol";
import { IPriceFetcher } from "./interfaces/IPriceFetcher.sol";
import { IPriceFetcher } from "./interfaces/IPriceFetcher.sol";
import { ILRTOracle } from "./interfaces/ILRTOracle.sol";
import { ILRTOracle } from "./interfaces/ILRTOracle.sol";
import { ILRTDepositPool } from "./interfaces/ILRTDepositPool.sol";
import { ILRTDepositPool } from "./interfaces/ILRTDepositPool.sol";
import { IAccessControl } from "@openzeppelin/contracts/access/IAccessControl.sol";
import { IAccessControl } from "@openzeppelin/contracts/access/IAccessControl.sol";
import { Initializable } from "@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol";
import { Initializable } from "@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol";


interface IPausable {
interface IPausable {
function pause() external;
function pause() external;
function paused() external view returns (bool);
function paused() external view returns (bool);
}
}


/// @title LRTOracle Contract
/// @title LRTOracle Contract
/// @notice oracle contract that calculates the exchange rate of assets
/// @notice oracle contract that calculates the exchange rate of assets
contract LRTOracle is ILRTOracle, LRTConfigRoleChecker, Initializable {
contract LRTOracle is ILRTOracle, LRTConfigRoleChecker, Initializable {
using WadMath for uint256;
using WadMath for uint256;


mapping(address asset => address priceOracle) public override assetPriceOracle;
mapping(address asset => address priceOracle) public override assetPriceOracle;


uint256 public override rsETHPrice;
uint256 public override rsETHPrice;
uint256 public pricePercentageLimit;
uint256 public pricePercentageLimit;
uint256 public highestRsethPrice;
uint256 public highestRsethPrice;


// Daily fee minting limit variables
// Daily fee minting limit variables
uint256 public currentPeriodMintedFeeAmount;
uint256 public currentPeriodMintedFeeAmount;
uint256 public feePeriodStartTime;
uint256 public feePeriodStartTime;
uint256 public maxFeeMintAmountPerDay;
uint256 public maxFeeMintAmountPerDay;


/// @notice New variable added for pausable functionality
/// @notice New variable added for pausable functionality
bool public paused;
bool public paused;


modifier onlySupportedOracle(address asset) {
modifier onlySupportedOracle(address asset) {
if (assetPriceOracle[asset] == address(0)) {
if (assetPriceOracle[asset] == address(0)) {
revert AssetOracleNotSupported();
revert AssetOracleNotSupported();
}
}
_;
_;
}
}


modifier whenNotPaused() {
modifier whenNotPaused() {
if (paused) revert ContractPaused();
if (paused) revert ContractPaused();
_;
_;
}
}


modifier whenPaused() {
modifier whenPaused() {
if (!paused) revert ContractNotPaused();
if (!paused) revert ContractNotPaused();
_;
_;
}
}


/// @custom:oz-upgrades-unsafe-allow constructor
/// @custom:oz-upgrades-unsafe-allow constructor
constructor() {
constructor() {
_disableInitializers();
_disableInitializers();
}
}


/// @dev Initializes the contract
/// @dev Initializes the contract
/// @param lrtConfigAddr LRT config address
/// @param lrtConfigAddr LRT config address
function initialize(address lrtConfigAddr) external initializer {
function initialize(address lrtConfigAddr) external initializer {
UtilLib.checkNonZeroAddress(lrtConfigAddr);
UtilLib.checkNonZeroAddress(lrtConfigAddr);
lrtConfig = ILRTConfig(lrtConfigAddr);
lrtConfig = ILRTConfig(lrtConfigAddr);
emit UpdatedLRTConfig(lrtConfigAddr);
emit UpdatedLRTConfig(lrtConfigAddr);
}
}


/// @notice Initializes the contract with a fee period start time
/// @param _feePeriodStartTime The start time of the fee period
function reinitialize(uint256 _feePeriodStartTime) external reinitializer(2) onlyLRTManager {
if (_feePeriodStartTime > block.timestamp || _feePeriodStartTime <= block.timestamp - 1 days) {
revert PeriodStartTimeShouldBeWithin24Hours();
}

feePeriodStartTime = _feePeriodStartTime;
emit FeePeriodStartTimeSet(_feePeriodStartTime);
}

/*//////////////////////////////////////////////////////////////
/*//////////////////////////////////////////////////////////////
write functions
write functions
//////////////////////////////////////////////////////////////*/
//////////////////////////////////////////////////////////////*/


/// @notice updates RSETH/ETH exchange rate
/// @notice updates RSETH/ETH exchange rate
/// @dev calculates rsETH price based on stakedAsset value received from EigenLayer
/// @dev calculates rsETH price based on stakedAsset value received from EigenLayer
function updateRSETHPrice() public whenNotPaused {
function updateRSETHPrice() public whenNotPaused {
_updateRsETHPrice();
_updateRsETHPrice();
}
}


/// @dev update rsETH price as an manager account
/// @dev update rsETH price as an manager account
/// @dev main benefit is to be able to update the price in case of the price going above the threshold
/// @dev main benefit is to be able to update the price in case of the price going above the threshold
/// @dev only LRT manager is allowed to call this function
/// @dev only LRT manager is allowed to call this function
function updateRSETHPriceAsManager() external onlyLRTManager {
function updateRSETHPriceAsManager() external onlyLRTManager {
_updateRsETHPrice();
_updateRsETHPrice();
}
}


/// @dev add/update the price oracle of any asset
/// @dev add/update the price oracle of any asset
/// @dev only onlyLRTAdmin is allowed
/// @dev only onlyLRTAdmin is allowed
/// @param asset asset address for which oracle price needs to be added/updated
/// @param asset asset address for which oracle price needs to be added/updated
function updatePriceOracleForValidated(address asset, address priceOracle) external onlyLRTAdmin {
function updatePriceOracleForValidated(address asset, address priceOracle) external onlyLRTAdmin {
// Sanity check: oracle price must have precision between 1e16 and 1e19
// Sanity check: oracle price must have precision between 1e16 and 1e19
uint256 price = IPriceFetcher(priceOracle).getAssetPrice(asset);
uint256 price = IPriceFetcher(priceOracle).getAssetPrice(asset);
if (price > 1e19 || price < 1e16) {
if (price > 1e19 || price < 1e16) {
revert InvalidPriceOracle();
revert InvalidPriceOracle();
}
}
updatePriceOracleFor(asset, priceOracle);
updatePriceOracleFor(asset, priceOracle);
}
}


/// @dev add/update the price oracle of any asset
/// @dev add/update the price oracle of any asset