diff --git a/test/IntegrationAdaptativeCurveIrmTest.sol b/test/IntegrationAdaptativeCurveIrmTest.sol index 68ff03de..aa43ff8e 100644 --- a/test/IntegrationAdaptativeCurveIrmTest.sol +++ b/test/IntegrationAdaptativeCurveIrmTest.sol @@ -3,7 +3,7 @@ pragma solidity ^0.8.0; import "../src/SpeedJumpIrm.sol"; import "../lib/forge-std/src/Test.sol"; -import {BaseTest,IrmMock,IMorpho,MorphoLib} from "../lib/morpho-blue/test/forge/BaseTest.sol"; +import {BaseTest, IrmMock, IMorpho, MorphoLib} from "../lib/morpho-blue/test/forge/BaseTest.sol"; contract IntegrationAdaptativeCurveIrmTest is BaseTest { using MarketParamsLib for MarketParams; @@ -16,11 +16,13 @@ contract IntegrationAdaptativeCurveIrmTest is BaseTest { AdaptativeCurveIrm aIrm; - function _freshMarket(uint supply, uint borrow) internal returns (MarketParams memory) { + function _freshMarket(uint256 supply, uint256 borrow) internal returns (MarketParams memory) { aIrm = new AdaptativeCurveIrm(address(morpho), uint256(CURVE_STEEPNESS), uint256(ADJUSTMENT_SPEED), uint256(TARGET_UTILIZATION), INITIAL_RATE_AT_TARGET); - marketParams = MarketParams(address(loanToken), address(collateralToken), address(oracle), address(aIrm), DEFAULT_TEST_LLTV); + marketParams = MarketParams( + address(loanToken), address(collateralToken), address(oracle), address(aIrm), DEFAULT_TEST_LLTV + ); id = marketParams.id(); vm.startPrank(OWNER); @@ -30,52 +32,63 @@ contract IntegrationAdaptativeCurveIrmTest is BaseTest { // Existing market - loanToken.setBalance(SUPPLIER,supply); + loanToken.setBalance(SUPPLIER, supply); vm.prank(SUPPLIER); morpho.supply(marketParams, supply, 0, SUPPLIER, hex""); - - collateralToken.setBalance(BORROWER,1e30); + collateralToken.setBalance(BORROWER, 1e30); vm.prank(BORROWER); morpho.supplyCollateral(marketParams, 1e30, BORROWER, hex""); vm.prank(BORROWER); - morpho.borrow(marketParams,borrow,0,BORROWER,BORROWER); + morpho.borrow(marketParams, borrow, 0, BORROWER, BORROWER); return marketParams; } // Make stepped accrual fail // Will revert due to overflow for a long enough duration - // Overflow occurs in _accrueInterest when interests are added do supply/borrow assets + // Overflow occurs in _accrueInterest when interests are added to supply/borrow assets function testSteppedAccrual() public { _freshMarket({supply: 1e18, borrow: 0.9e18}); - uint duration = 13 weeks; - uint period = 1000 seconds; - for (uint i=0;i 2 * refRate) { + // `(i - refI) * 1000` is the time elapsed to double the rate + console.log(((i - refI) * 1000 * 100) / (1 days)); + refRate = rate; + refI = i; + } } } // Compare stepped accrual (1 accrual per period over duration) vs. leap accrual (1 accrual at end of duration) function testCompareAccrualMethods() public { // Setup - uint duration = 9 weeks; - uint period = 1000 seconds; - duration = duration-(duration%period); // exact loop iterations for step market + uint256 duration = 9 weeks; + uint256 period = 1000 seconds; + duration = duration - (duration % period); // exact loop iterations for step market - MarketParams memory stepMarketParams = _freshMarket({supply:1e18, borrow: 0.9e18}); - MarketParams memory leapMarketParams = _freshMarket({supply:1e18, borrow: 0.9e18}); + MarketParams memory stepMarketParams = _freshMarket({supply: 1e18, borrow: 0.9e18}); + MarketParams memory leapMarketParams = _freshMarket({supply: 1e18, borrow: 0.9e18}); _forward(1); morpho.accrueInterest(stepMarketParams); morpho.accrueInterest(leapMarketParams); // Same initial borrow for both - uint initialBorrow = morpho.totalBorrowAssets(stepMarketParams.id()); + uint256 initialBorrow = morpho.totalBorrowAssets(stepMarketParams.id()); // Accrue step market - for (uint i=0;i