Skip to content

Commit

Permalink
🦺 irm: add max config value checks
Browse files Browse the repository at this point in the history
  • Loading branch information
santichez committed Apr 21, 2023
1 parent eef7f82 commit 83a1615
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 3 deletions.
5 changes: 5 additions & 0 deletions .changeset/healthy-spiders-leave.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@exactly-protocol/protocol": patch
---

🦺 irm: add max config value checks
8 changes: 5 additions & 3 deletions .gas-snapshot
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ AuditorTest:testExitMarketOwning() (gas: 177445)
InterestRateModelTest:testFixedBorrowRate() (gas: 8089)
InterestRateModelTest:testFloatingBorrowRate() (gas: 6236)
InterestRateModelTest:testMinFixedRate() (gas: 7610)
InterestRateModelTest:testRevertFixedMaxUtilizationLowerThanWad() (gas: 81593)
InterestRateModelTest:testRevertFloatingMaxUtilizationLowerThanWad() (gas: 81681)
LeveragerTest:testApproveMaliciousMarket() (gas: 24112)
LeveragerTest:testApproveMarket() (gas: 56669)
LeveragerTest:testCallReceiveFlashLoanFromAnyAddress() (gas: 11465)
Expand Down Expand Up @@ -54,7 +56,7 @@ MarketTest:testDepositShouldUpdateFlexibleBorrowVariables() (gas: 443236)
MarketTest:testDepositToSmartPool() (gas: 157676)
MarketTest:testDistributeMultipleAccumulatedEarnings() (gas: 585361)
MarketTest:testDistributionOfLossesShouldReduceFromFloatingBackupBorrowedAccordingly() (gas: 2041192)
MarketTest:testEarlyRepaymentWithExcessiveAmountOfFees() (gas: 1300232)
MarketTest:testEarlyRepaymentWithExcessiveAmountOfFees() (gas: 1300291)
MarketTest:testEarlyWithdrawFromFreeLunchShouldNotRevertWithFloatingFullUtilization() (gas: 611090)
MarketTest:testFixedBorrowFailingWhenFlexibleBorrowAccruesDebt() (gas: 773534)
MarketTest:testFlexibleBorrow() (gas: 329289)
Expand Down Expand Up @@ -103,8 +105,8 @@ MarketTest:testRoundingUpAllowanceWhenBorrowingAtMaturity() (gas: 489301)
MarketTest:testRoundingUpAllowanceWhenWithdrawingAtMaturity() (gas: 501981)
MarketTest:testSetDampSpeedFactorShouldUpdateFloatingAssetsAverage() (gas: 240216)
MarketTest:testSetEarningsAccumulatorSmoothFactorShouldDistributeEarnings() (gas: 495637)
MarketTest:testSetInterestRateModelShouldUpdateFloatingDebt() (gas: 988294)
MarketTest:testSetInterestRateModelWithAddressZeroShouldNotUpdateFloatingDebt() (gas: 870527)
MarketTest:testSetInterestRateModelShouldUpdateFloatingDebt() (gas: 988353)
MarketTest:testSetInterestRateModelWithAddressZeroShouldNotUpdateFloatingDebt() (gas: 870586)
MarketTest:testShareValueNotDecreasingAfterDeposit() (gas: 468612)
MarketTest:testShareValueNotDecreasingWhenMintingToTreasury() (gas: 473384)
MarketTest:testSingleFloatingBorrow() (gas: 326415)
Expand Down
3 changes: 3 additions & 0 deletions contracts/InterestRateModel.sol
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ contract InterestRateModel {
int256 floatingCurveB_,
uint256 floatingMaxUtilization_
) {
assert(fixedMaxUtilization_ > 1e18);
assert(floatingMaxUtilization_ > 1e18);

fixedCurveA = fixedCurveA_;
fixedCurveB = fixedCurveB_;
fixedMaxUtilization = fixedMaxUtilization_;
Expand Down
10 changes: 10 additions & 0 deletions test/solidity/InterestRateModel.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,16 @@ contract InterestRateModelTest is Test {
assertEq(rate, 41730769230769230);
}

function testRevertFixedMaxUtilizationLowerThanWad() external {
vm.expectRevert();
new InterestRateModelHarness(0.023e18, -0.0025e18, 1e18 - 1, 0.023e18, -0.0025e18, 1.02e18);
}

function testRevertFloatingMaxUtilizationLowerThanWad() external {
vm.expectRevert();
new InterestRateModelHarness(0.023e18, -0.0025e18, 1.02e18, 0.023e18, -0.0025e18, 1e18 - 1);
}

function testFuzzReferenceRate(uint256 v0, uint64 delta) external {
(uint256 rate, uint256 refRate) = irm.fixedRate(v0, delta);
assertApproxEqAbs(rate, refRate, 3e3);
Expand Down

0 comments on commit 83a1615

Please sign in to comment.