S Price: $0.416167 (+1.37%)

Contract Diff Checker

Contract Name:
InterestRateModelV2Config

Contract Source Code:

// SPDX-License-Identifier: BUSL-1.1
pragma solidity 0.8.28;

import {IInterestRateModelV2Config} from "../interfaces/IInterestRateModelV2Config.sol";
import {IInterestRateModelV2} from "../interfaces/IInterestRateModelV2.sol";

/// @title InterestRateModelV2Config
/// @notice Please never deploy config manually, always use factory, because factory does necessary checks.
contract InterestRateModelV2Config is IInterestRateModelV2Config {
    // uopt ∈ (0, 1) – optimal utilization;
    int256 internal immutable _UOPT;
    // ucrit ∈ (uopt, 1) – threshold of large utilization;
    int256 internal immutable _UCRIT;
    // ulow ∈ (0, uopt) – threshold of low utilization
    int256 internal immutable _ULOW;
    // ki > 0 – integrator gain
    int256 internal immutable _KI;
    // kcrit > 0 – proportional gain for large utilization
    int256 internal immutable _KCRIT;
    // klow ≥ 0 – proportional gain for low utilization
    int256 internal immutable _KLOW;
    // klin ≥ 0 – coefficient of the lower linear bound
    int256 internal immutable _KLIN;
    // beta ≥ 0 - a scaling factor
    int256 internal immutable _BETA;

    // initial value for ri, ri ≥ 0 – initial value of the integrator
    int112 internal immutable _RI;
    // initial value for Tcrit, Tcrit ≥ 0 - the time during which the utilization exceeds the critical value
    int112 internal immutable _TCRIT;

    constructor(IInterestRateModelV2.Config memory _config) {
        _UOPT = _config.uopt;
        _UCRIT = _config.ucrit;
        _ULOW = _config.ulow;
        _KI = _config.ki;
        _KCRIT = _config.kcrit;
        _KLOW = _config.klow;
        _KLIN = _config.klin;
        _BETA = _config.beta;

        _RI = _config.ri;
        _TCRIT = _config.Tcrit;
    }

    /// @inheritdoc IInterestRateModelV2Config
    function getConfig() external view virtual returns (IInterestRateModelV2.Config memory config) {
        config.uopt = _UOPT;
        config.ucrit = _UCRIT;
        config.ulow = _ULOW;
        config.ki = _KI;
        config.kcrit = _KCRIT;
        config.klow = _KLOW;
        config.klin = _KLIN;
        config.beta = _BETA;

        config.ri = _RI;
        config.Tcrit = _TCRIT;
    }
}

// SPDX-License-Identifier: MIT
pragma solidity >=0.5.0;

import {IInterestRateModelV2} from "./IInterestRateModelV2.sol";

interface IInterestRateModelV2Config {
    /// @return config returns immutable IRM configuration that is present in contract
    function getConfig() external view returns (IInterestRateModelV2.Config memory config);
}

// SPDX-License-Identifier: MIT
pragma solidity >=0.5.0;

import {IInterestRateModelV2Config} from "./IInterestRateModelV2Config.sol";

interface IInterestRateModelV2 {
    struct Config {
        // uopt ∈ (0, 1) – optimal utilization;
        int256 uopt;
        // ucrit ∈ (uopt, 1) – threshold of large utilization;
        int256 ucrit;
        // ulow ∈ (0, uopt) – threshold of low utilization
        int256 ulow;
        // ki > 0 – integrator gain
        int256 ki;
        // kcrit > 0 – proportional gain for large utilization
        int256 kcrit;
        // klow ≥ 0 – proportional gain for low utilization
        int256 klow;
        // klin ≥ 0 – coefficient of the lower linear bound
        int256 klin;
        // beta ≥ 0 - a scaling factor
        int256 beta;
        // ri ≥ 0 – initial value of the integrator
        int112 ri;
        // Tcrit ≥ 0 - initial value of the time during which the utilization exceeds the critical value
        int112 Tcrit;
    }

    struct Setup {
        // ri ≥ 0 – the integrator
        int112 ri;
        // Tcrit ≥ 0 - the time during which the utilization exceeds the critical value
        int112 Tcrit;
        // flag that informs if setup is initialized
        bool initialized;
    }
    /* solhint-enable */

    error AddressZero();
    error DeployConfigFirst();
    error AlreadyInitialized();

    error InvalidBeta();
    error InvalidKcrit();
    error InvalidKi();
    error InvalidKlin();
    error InvalidKlow();
    error InvalidTcrit();
    error InvalidTimestamps();
    error InvalidUcrit();
    error InvalidUlow();
    error InvalidUopt();
    error InvalidRi();

    /// @dev Get config for given asset in a Silo.
    /// @param _silo Silo address for which config should be set
    /// @return Config struct for asset in Silo
    function getConfig(address _silo) external view returns (Config memory);

    /// @notice get the flag to detect rcomp restriction (zero current interest) due to overflow
    /// overflow boolean flag to detect rcomp restriction
    function overflowDetected(address _silo, uint256 _blockTimestamp)
        external
        view
        returns (bool overflow);

    /// @dev pure function that calculates current annual interest rate
    /// @param _c configuration object, IInterestRateModel.Config
    /// @param _totalBorrowAmount current total borrows for asset
    /// @param _totalDeposits current total deposits for asset
    /// @param _interestRateTimestamp timestamp of last interest rate update
    /// @param _blockTimestamp current block timestamp
    /// @return rcur current annual interest rate (1e18 == 100%)
    function calculateCurrentInterestRate(
        Config calldata _c,
        uint256 _totalDeposits,
        uint256 _totalBorrowAmount,
        uint256 _interestRateTimestamp,
        uint256 _blockTimestamp
    ) external pure returns (uint256 rcur);

    /// @dev pure function that calculates interest rate based on raw input data
    /// @param _c configuration object, IInterestRateModel.Config
    /// @param _totalBorrowAmount current total borrows for asset
    /// @param _totalDeposits current total deposits for asset
    /// @param _interestRateTimestamp timestamp of last interest rate update
    /// @param _blockTimestamp current block timestamp
    /// @return rcomp compounded interest rate from last update until now (1e18 == 100%)
    /// @return ri current integral part of the rate
    /// @return Tcrit time during which the utilization exceeds the critical value
    /// @return overflow boolean flag to detect rcomp restriction
    function calculateCompoundInterestRateWithOverflowDetection(
        Config memory _c,
        uint256 _totalDeposits,
        uint256 _totalBorrowAmount,
        uint256 _interestRateTimestamp,
        uint256 _blockTimestamp
    )
        external
        pure
        returns (
            uint256 rcomp,
            int256 ri,
            int256 Tcrit,
            bool overflow
        );

    /// @dev pure function that calculates interest rate based on raw input data
    /// @param _c configuration object, IInterestRateModel.Config
    /// @param _totalBorrowAmount current total borrows for asset
    /// @param _totalDeposits current total deposits for asset
    /// @param _interestRateTimestamp timestamp of last interest rate update
    /// @param _blockTimestamp current block timestamp
    /// @return rcomp compounded interest rate from last update until now (1e18 == 100%)
    /// @return ri current integral part of the rate
    /// @return Tcrit time during which the utilization exceeds the critical value
    function calculateCompoundInterestRate(
        Config memory _c,
        uint256 _totalDeposits,
        uint256 _totalBorrowAmount,
        uint256 _interestRateTimestamp,
        uint256 _blockTimestamp
    ) external pure returns (uint256 rcomp, int256 ri, int256 Tcrit);
}

Please enter a contract address above to load the contract details and source code.

Context size (optional):