Skip to content

Commit

Permalink
feat: add interest model
Browse files Browse the repository at this point in the history
  • Loading branch information
alpanaca committed Mar 1, 2024
1 parent 65d22b2 commit c1b2f9a
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// SPDX-License-Identifier: BUSL
pragma solidity 0.8.19;

contract MMFlatSlopeModel3 {
/// @dev Return the interest rate per second, using 1e18 as denom.
function getInterestRate(
uint256, /*debt*/
uint256 /*floating*/
) external pure returns (uint256) {
// 8% flat rate = 8e16 / 365 days
return 2536783358;
}
}
25 changes: 25 additions & 0 deletions solidity/tests/money-market/interest-models/MMFlatSlope3.t.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// SPDX-License-Identifier: MIT
pragma solidity 0.8.19;

import { BaseTest, console } from "../../base/BaseTest.sol";

import { MMFlatSlopeModel3 } from "../../../contracts/money-market/interest-models/MMFlatSlopeModel3.sol";

// solhint-disable func-name-mixedcase
// solhint-disable contract-name-camelcase
contract MMFlatSlopeModel3_Test is BaseTest {
MMFlatSlopeModel3 private _flatSlopeModel3;

function setUp() external {
_flatSlopeModel3 = new MMFlatSlopeModel3();
}

function _findInterestPerYear(uint256 _interestPerSec) internal pure returns (uint256) {
return _interestPerSec * 365 days;
}

function testFuzz_getInterestRate(uint256 debt, uint256 floating) external {
// when utilization is whatever, interest will always be 7.99% ~ 8.00%
assertEq(_findInterestPerYear(_flatSlopeModel3.getInterestRate(debt, floating)), 0.079999999977888000 ether);
}
}

0 comments on commit c1b2f9a

Please sign in to comment.