Skip to content

Commit

Permalink
test(irm): add ping tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Rubilmax committed Nov 15, 2023
1 parent 77ed9c1 commit 087536c
Showing 1 changed file with 42 additions and 0 deletions.
42 changes: 42 additions & 0 deletions test/SpeedJumpIrmTest.sol
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,48 @@ contract AdaptativeCurveIrmTest is Test {
assertApproxEqRel(irm.borrowRateView(marketParams, market), uint256(0.00057 ether) / 365 days, 0.1 ether);
}

function testRateAfter60DaysNoPing() public {
Market memory market;
market.totalSupplyAssets = 10 ether;
market.totalBorrowAssets = 9 ether;
assertEq(irm.borrowRate(marketParams, market), uint256(INITIAL_RATE_AT_TARGET));
assertEq(irm.rateAtTarget(marketParams.id()), INITIAL_RATE_AT_TARGET);

market.lastUpdate = uint128(block.timestamp);
vm.warp(block.timestamp + 60 days);

market.totalBorrowAssets = 9.5 ether;
irm.borrowRate(marketParams, market);

assertApproxEqRel(irm.rateAtTarget(marketParams.id()), int256(0.6092 ether) / 365 days, 0.0001 ether);
}

function testRateAfter60DaysPingEveryDay() public {
Market memory market;
market.totalSupplyAssets = 10 ether;
market.totalBorrowAssets = 9 ether;
assertEq(irm.borrowRate(marketParams, market), uint256(INITIAL_RATE_AT_TARGET));
assertEq(irm.rateAtTarget(marketParams.id()), INITIAL_RATE_AT_TARGET);

market.totalBorrowAssets = 9.5 ether;

for (uint256 i; i < 60; ++i) {
market.lastUpdate = uint128(block.timestamp);
vm.warp(block.timestamp + 1 days);

uint256 avgBorrowRate = irm.borrowRate(marketParams, market);
uint256 interest = market.totalBorrowAssets.wMulDown(avgBorrowRate.wTaylorCompounded(1 days));
market.totalSupplyAssets += uint128(interest);
market.totalBorrowAssets += uint128(interest);

// Utilization starts to grow significantly (0.5%) due to each ping.
assertApproxEqRel(market.totalBorrowAssets.wDivDown(market.totalSupplyAssets), 0.95 ether, 0.005 ether);
}

// End rate at target is significantly greater than expected (5%).
assertApproxEqRel(irm.rateAtTarget(marketParams.id()), int256(0.6092 ether) / 365 days, 0.05 ether);
}

function testFirstBorrowRate(Market memory market) public {
vm.assume(market.totalBorrowAssets > 0);
vm.assume(market.totalSupplyAssets >= market.totalBorrowAssets);
Expand Down

0 comments on commit 087536c

Please # to comment.