all files / contracts/ BaseIRMLinearKink.sol

100% Statements 10/10
100% Branches 2/2
100% Functions 2/2
100% Lines 10/10
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                            129× 129× 129× 129×       367×   367× 358×       367×      
// SPDX-License-Identifier: GPL-2.0-or-later
 
pragma solidity ^0.8.0;
 
import "./BaseIRM.sol";
 
 
contract BaseIRMLinearKink is BaseIRM {
    uint public immutable baseRate;
    uint public immutable slope1;
    uint public immutable slope2;
    uint public immutable kink;
 
    constructor(uint moduleId_, bytes32 moduleGitCommit_, uint baseRate_, uint slope1_, uint slope2_, uint kink_) BaseIRM(moduleId_, moduleGitCommit_) {
        baseRate = baseRate_;
        slope1 = slope1_;
        slope2 = slope2_;
        kink = kink_;
    }
 
    function computeInterestRateImpl(address, uint32 utilisation) internal override view returns (int96) {
        uint ir = baseRate;
 
        if (utilisation <= kink) {
            ir += utilisation * slope1;
        } else {
            ir += kink * slope1;
            ir += slope2 * (utilisation - kink);
        }
 
        return int96(int(ir));
    }
}