From c1b2f9a93ca719d98127e3ddf382d6e18ebb6f92 Mon Sep 17 00:00:00 2001 From: alpanaca Date: Fri, 1 Mar 2024 15:11:52 +0700 Subject: [PATCH] feat: add interest model --- .../interest-models/MMFlatSlopeModel3.sol | 13 ++++++++++ .../interest-models/MMFlatSlope3.t.sol | 25 +++++++++++++++++++ 2 files changed, 38 insertions(+) create mode 100644 solidity/contracts/money-market/interest-models/MMFlatSlopeModel3.sol create mode 100644 solidity/tests/money-market/interest-models/MMFlatSlope3.t.sol diff --git a/solidity/contracts/money-market/interest-models/MMFlatSlopeModel3.sol b/solidity/contracts/money-market/interest-models/MMFlatSlopeModel3.sol new file mode 100644 index 00000000..6e56bb09 --- /dev/null +++ b/solidity/contracts/money-market/interest-models/MMFlatSlopeModel3.sol @@ -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; + } +} diff --git a/solidity/tests/money-market/interest-models/MMFlatSlope3.t.sol b/solidity/tests/money-market/interest-models/MMFlatSlope3.t.sol new file mode 100644 index 00000000..2e293f09 --- /dev/null +++ b/solidity/tests/money-market/interest-models/MMFlatSlope3.t.sol @@ -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); + } +}