From 78c8ca722255ce75bd558bb28a090055f2d8f7c5 Mon Sep 17 00:00:00 2001 From: Santiago Sanchez Avalos Date: Tue, 21 May 2024 13:50:18 -0300 Subject: [PATCH] =?UTF-8?q?=F0=9F=A9=B9=20market:=20round=20up=20fixed=20b?= =?UTF-8?q?orrow=20fee?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .changeset/soft-toys-breathe.md | 5 + .gas-snapshot | 254 +++++++++++++++--------------- contracts/Market.sol | 2 +- contracts/periphery/Previewer.sol | 2 +- test/Market.t.sol | 12 +- test/Previewer.t.sol | 4 +- 6 files changed, 142 insertions(+), 137 deletions(-) create mode 100644 .changeset/soft-toys-breathe.md diff --git a/.changeset/soft-toys-breathe.md b/.changeset/soft-toys-breathe.md new file mode 100644 index 000000000..a03a8869a --- /dev/null +++ b/.changeset/soft-toys-breathe.md @@ -0,0 +1,5 @@ +--- +"@exactly/protocol": patch +--- + +🩹 market: round up fixed borrow fee diff --git a/.gas-snapshot b/.gas-snapshot index 162007778..bde562b43 100644 --- a/.gas-snapshot +++ b/.gas-snapshot @@ -49,7 +49,7 @@ DebtManagerTest:testFloatingToFixedRollHigherThanAvailableLiquidityWithSlippage( DebtManagerTest:testFloatingToFixedRollHigherThanAvailableLiquidityWithSlippageWithThreePools() (gas: 2787984) DebtManagerTest:testFloatingToFixedRollWithAccurateSlippage() (gas: 1687218) DebtManagerTest:testFloatingToFixedRollWithAccurateSlippageWithPreviousPosition() (gas: 1924341) -DebtManagerTest:testFuzzRolls(uint8[4],uint8[4],uint256[4],uint40[4],uint8[4]) (runs: 256, μ: 6515515, ~: 6559863) +DebtManagerTest:testFuzzRolls(uint8[4],uint8[4],uint256[4],uint40[4],uint8[4]) (runs: 256, μ: 6526945, ~: 6552300) DebtManagerTest:testLateFixedRoll() (gas: 1310831) DebtManagerTest:testLateFixedRollWithThreeLoops() (gas: 1897545) DebtManagerTest:testLateFixedToFloatingRoll() (gas: 1273784) @@ -128,56 +128,56 @@ EscrowedEXATest:testWithdrawMaxFromMultipleStreams() (gas: 1556686) EscrowedEXATest:testWithdrawMaxShouldGiveReserveBackWhenDepleted() (gas: 548053) EscrowedEXATest:testWithdrawMaxWithInvalidSender() (gas: 500137) InstallmentsRouterTest:testAmountsLength() (gas: 36269) -InstallmentsRouterTest:testBorrowETHWithPermit() (gas: 1114828) -InstallmentsRouterTest:testBorrowRouter() (gas: 638593) -InstallmentsRouterTest:testBorrowUnwrappedETH() (gas: 722281) -InstallmentsRouterTest:testBorrowWithPermit() (gas: 1217763) +InstallmentsRouterTest:testBorrowETHWithPermit() (gas: 1114945) +InstallmentsRouterTest:testBorrowRouter() (gas: 638710) +InstallmentsRouterTest:testBorrowUnwrappedETH() (gas: 722398) +InstallmentsRouterTest:testBorrowWithPermit() (gas: 1217880) InstallmentsRouterTest:testFakeMarket() (gas: 47507) -InstallmentsRouterTest:testInsufficientMaxRepay() (gas: 630316) -InstallmentsRouterTest:testMaxRepay() (gas: 630303) +InstallmentsRouterTest:testInsufficientMaxRepay() (gas: 630433) +InstallmentsRouterTest:testMaxRepay() (gas: 630420) InstallmentsRouterTest:testMissingMarketWETH() (gas: 776941) -InstallmentsRouterTest:testMoreBorrowsThanMaxPools() (gas: 634155) +InstallmentsRouterTest:testMoreBorrowsThanMaxPools() (gas: 634272) InterestRateModelTest:testFixedBorrowRate() (gas: 2063720) InterestRateModelTest:testFixedRateRevertAlreadyMatured() (gas: 2057902) InterestRateModelTest:testFixedRateRevertUtilizationExceeded() (gas: 2065065) InterestRateModelTest:testFloatingBorrowRate() (gas: 2057206) InterestRateModelTest:testFuzzFixedRateGrowth(uint256,uint256,uint256,uint256) (runs: 256, μ: 2078572, ~: 2075498) InterestRateModelTest:testFuzzFixedRateTimeSensitivity(uint256,uint256,uint256) (runs: 256, μ: 2084820, ~: 2084876) -InterestRateModelTest:testFuzzReferenceLegacyRateFixed(uint32,uint256,uint256[2],uint256[2],uint256,uint256,uint256) (runs: 256, μ: 10029992, ~: 10193891) +InterestRateModelTest:testFuzzReferenceLegacyRateFixed(uint32,uint256,uint256[2],uint256[2],uint256,uint256,uint256) (runs: 256, μ: 10050378, ~: 10219232) InterestRateModelTest:testFuzzReferenceRateFixed(uint256,uint256,uint256,uint256,uint256,uint256,(uint256,uint256,uint256,uint256,uint256,uint256,uint256,uint256,int256,uint256,uint256)) (runs: 256, μ: 2349132, ~: 2351637) InterestRateModelTest:testFuzzReferenceRateFloating(uint256,uint256,(uint256,uint256,uint256,uint256,uint256,uint256,uint256)) (runs: 256, μ: 2287270, ~: 2288122) InterestRateModelTest:testMinTimeToMaturity() (gas: 2075220) InterestRateModelTest:testRevertMaxUtilizationLowerThanWad() (gas: 267545) -MarketTest:testAccountLiquidityAdjustedDebt() (gas: 499440) -MarketTest:testAnotherUserRedeemWhenOwnerHasShortfall() (gas: 819075) -MarketTest:testAnotherUserWithdrawWhenOwnerHasShortfall() (gas: 806834) +MarketTest:testAccountLiquidityAdjustedDebt() (gas: 499479) +MarketTest:testAnotherUserRedeemWhenOwnerHasShortfall() (gas: 819114) +MarketTest:testAnotherUserWithdrawWhenOwnerHasShortfall() (gas: 806873) MarketTest:testBorrowAfterFreezing() (gas: 491482) -MarketTest:testBorrowAtMaturity() (gas: 499544) -MarketTest:testBorrowAtMaturityAfterFreezing() (gas: 573160) +MarketTest:testBorrowAtMaturity() (gas: 499583) +MarketTest:testBorrowAtMaturityAfterFreezing() (gas: 573199) MarketTest:testBorrowAtMaturityUpdatesFloatingDebtAndFloatingAssets() (gas: 884672) MarketTest:testBorrowAtMaturityWhenFrozen() (gas: 93696) MarketTest:testBorrowAtMaturityWithZeroAssets() (gas: 40403) -MarketTest:testBorrowDisagreement() (gas: 295415) -MarketTest:testBorrowFromFreeLunchShouldNotRevertWithFloatingFullUtilization() (gas: 1294292) +MarketTest:testBorrowDisagreement() (gas: 295454) +MarketTest:testBorrowFromFreeLunchShouldNotRevertWithFloatingFullUtilization() (gas: 1294331) MarketTest:testBorrowWhenFrozen() (gas: 93202) MarketTest:testBorrowWithZeroAssets() (gas: 39749) -MarketTest:testCappedLiquidation() (gas: 1197582) -MarketTest:testChargeTreasuryToEarlyWithdraws() (gas: 1218518) -MarketTest:testChargeTreasuryToFixedBorrows() (gas: 1588154) -MarketTest:testClearBadDebtAvoidingFixedBorrowsIfAccumulatorLower() (gas: 2289111) -MarketTest:testClearBadDebtBeforeMaturity() (gas: 2347464) +MarketTest:testCappedLiquidation() (gas: 1197621) +MarketTest:testChargeTreasuryToEarlyWithdraws() (gas: 1218557) +MarketTest:testChargeTreasuryToFixedBorrows() (gas: 1588271) +MarketTest:testClearBadDebtAvoidingFixedBorrowsIfAccumulatorLower() (gas: 2289189) +MarketTest:testClearBadDebtBeforeMaturity() (gas: 2347581) MarketTest:testClearBadDebtCalledByAccount() (gas: 35021) -MarketTest:testClearBadDebtExactlyRepaysFixedBorrowWithAccumulatorAmount() (gas: 2020219) -MarketTest:testClearBadDebtPartiallyRepaysEachFixedBorrow() (gas: 1967555) -MarketTest:testClearBadDebtPartiallyRepaysFloatingDebt() (gas: 2307365) -MarketTest:testClearBadDebtShouldAccrueAccumulatedEarningsBeforeSpreadingLosses() (gas: 2086994) +MarketTest:testClearBadDebtExactlyRepaysFixedBorrowWithAccumulatorAmount() (gas: 2020258) +MarketTest:testClearBadDebtPartiallyRepaysEachFixedBorrow() (gas: 1967633) +MarketTest:testClearBadDebtPartiallyRepaysFloatingDebt() (gas: 2307443) +MarketTest:testClearBadDebtShouldAccrueAccumulatedEarningsBeforeSpreadingLosses() (gas: 2087072) MarketTest:testClearBadDebtWithEmptyAccumulatorShouldNotRevert() (gas: 969888) -MarketTest:testClearMaturity() (gas: 1693538) -MarketTest:testCollectTreasuryFreeLunchToEarlyWithdraws() (gas: 1766243) +MarketTest:testClearMaturity() (gas: 1693655) +MarketTest:testCollectTreasuryFreeLunchToEarlyWithdraws() (gas: 1766321) MarketTest:testCollectTreasuryFreeLunchToEarlyWithdrawsWithZeroFees() (gas: 559337) -MarketTest:testCollectTreasuryFreeLunchToFixedBorrows() (gas: 1820422) -MarketTest:testCollectTreasuryFreeLunchToFixedBorrowsWithZeroFees() (gas: 722696) -MarketTest:testCrossMaturityLiquidation() (gas: 2627134) +MarketTest:testCollectTreasuryFreeLunchToFixedBorrows() (gas: 1820539) +MarketTest:testCollectTreasuryFreeLunchToFixedBorrowsWithZeroFees() (gas: 722735) +MarketTest:testCrossMaturityLiquidation() (gas: 2627290) MarketTest:testDepositAfterFreezing() (gas: 256205) MarketTest:testDepositAtMaturity() (gas: 193456) MarketTest:testDepositAtMaturityAfterFreezing() (gas: 267449) @@ -187,90 +187,90 @@ MarketTest:testDepositDisagreement() (gas: 73882) MarketTest:testDepositShouldUpdateFlexibleBorrowVariables() (gas: 716949) MarketTest:testDepositToSmartPool() (gas: 181827) MarketTest:testDepositWhenFrozen() (gas: 176471) -MarketTest:testDistributeMultipleAccumulatedEarnings() (gas: 1382717) -MarketTest:testDistributionOfLossesShouldReduceFromFloatingBackupBorrowedAccordingly() (gas: 6415331) -MarketTest:testEarlyRepayLiquidationUnassignedEarnings() (gas: 2063693) -MarketTest:testEarlyRepaymentWithExcessiveAmountOfFees() (gas: 3419104) +MarketTest:testDistributeMultipleAccumulatedEarnings() (gas: 1382756) +MarketTest:testDistributionOfLossesShouldReduceFromFloatingBackupBorrowedAccordingly() (gas: 6415682) +MarketTest:testEarlyRepayLiquidationUnassignedEarnings() (gas: 2116976) +MarketTest:testEarlyRepaymentWithExcessiveAmountOfFees() (gas: 3435387) MarketTest:testEarlyWithdrawFromFreeLunchShouldNotRevertWithFloatingFullUtilization() (gas: 1050081) MarketTest:testEmergencyAdminRole() (gas: 317263) MarketTest:testEmitFrozen() (gas: 91114) -MarketTest:testFixedBorrowFailingWhenFlexibleBorrowAccruesDebt() (gas: 1530833) -MarketTest:testFixedBorrowRateToMaturity() (gas: 562488) -MarketTest:testFixedOperationsUpdateFloatingDebt() (gas: 865363) +MarketTest:testFixedBorrowFailingWhenFlexibleBorrowAccruesDebt() (gas: 1530872) +MarketTest:testFixedBorrowRateToMaturity() (gas: 562527) +MarketTest:testFixedOperationsUpdateFloatingDebt() (gas: 865402) MarketTest:testFlexibleBorrow() (gas: 423743) MarketTest:testFlexibleBorrowAccountingDebt() (gas: 607131) MarketTest:testFlexibleBorrowChargingDebtToTreasury() (gas: 751155) MarketTest:testFlexibleBorrowExceedingReserve() (gas: 878408) -MarketTest:testFlexibleBorrowExceedingReserveIncludingFixedBorrow() (gas: 1267534) +MarketTest:testFlexibleBorrowExceedingReserveIncludingFixedBorrow() (gas: 1267573) MarketTest:testFlexibleBorrowExceedingReserveWithNewDebt() (gas: 1001187) MarketTest:testFlexibleBorrowFromAnotherUserSubtractsAllowance() (gas: 469265) MarketTest:testFlexibleBorrowFromAnotherUserWithAllowance() (gas: 458659) MarketTest:testFlexibleBorrowFromAnotherUserWithoutAllowance() (gas: 252359) -MarketTest:testFrontRunSmartPoolEarningsDistributionWithBigPenaltyRepayment() (gas: 1381996) -MarketTest:testFullPause() (gas: 5956298) +MarketTest:testFrontRunSmartPoolEarningsDistributionWithBigPenaltyRepayment() (gas: 1382035) +MarketTest:testFullPause() (gas: 5956376) MarketTest:testInitiallyUnfrozen() (gas: 15592) -MarketTest:testInsufficientProtocolLiquidity() (gas: 1940357) -MarketTest:testLiquidateAndChargeIncentiveForLenders() (gas: 2431160) -MarketTest:testLiquidateAndDistributeLosses() (gas: 3240655) -MarketTest:testLiquidateAndSeizeExactAmountWithDustAsCollateral() (gas: 2807790) -MarketTest:testLiquidateAndSeizeFromEmptyCollateral() (gas: 1039302) -MarketTest:testLiquidateAndSubtractLossesFromAccumulator() (gas: 3915530) -MarketTest:testLiquidateFlexibleAndFixedBorrowPositionsInSingleCall() (gas: 2631820) -MarketTest:testLiquidateFlexibleBorrow() (gas: 2156253) +MarketTest:testInsufficientProtocolLiquidity() (gas: 1940396) +MarketTest:testLiquidateAndChargeIncentiveForLenders() (gas: 2431316) +MarketTest:testLiquidateAndDistributeLosses() (gas: 3240850) +MarketTest:testLiquidateAndSeizeExactAmountWithDustAsCollateral() (gas: 2807946) +MarketTest:testLiquidateAndSeizeFromEmptyCollateral() (gas: 1039341) +MarketTest:testLiquidateAndSubtractLossesFromAccumulator() (gas: 3915764) +MarketTest:testLiquidateFlexibleAndFixedBorrowPositionsInSingleCall() (gas: 2631898) +MarketTest:testLiquidateFlexibleBorrow() (gas: 2156292) MarketTest:testLiquidateFlexibleBorrowChargeLendersAssetsToLiquidator() (gas: 1150267) MarketTest:testLiquidateFlexibleBorrowConsideringDebtOverTime() (gas: 1166248) -MarketTest:testLiquidateLeavingDustAsCollateral() (gas: 3634638) +MarketTest:testLiquidateLeavingDustAsCollateral() (gas: 3634794) MarketTest:testLiquidateTransferRepayAssetsBeforeSeize() (gas: 1045448) -MarketTest:testLiquidateUpdateFloatingDebt() (gas: 1901726) +MarketTest:testLiquidateUpdateFloatingDebt() (gas: 1901804) MarketTest:testLiquidateWhenFrozen() (gas: 1230766) -MarketTest:testLiquidateWithTwoUnitsAsMaxAssets() (gas: 1576920) -MarketTest:testLiquidateWithZeroAsMaxAssets() (gas: 1039143) -MarketTest:testLiquidationClearingDebtOfAllAccountMarkets() (gas: 3105086) -MarketTest:testLiquidationResultingInZeroCollateralAndZeroDebt() (gas: 1981047) -MarketTest:testMaturityInsufficientProtocolLiquidity() (gas: 1464163) -MarketTest:testMultipleBorrowsForMultipleAssets() (gas: 2463574733) +MarketTest:testLiquidateWithTwoUnitsAsMaxAssets() (gas: 1576998) +MarketTest:testLiquidateWithZeroAsMaxAssets() (gas: 1039182) +MarketTest:testLiquidationClearingDebtOfAllAccountMarkets() (gas: 3105164) +MarketTest:testLiquidationResultingInZeroCollateralAndZeroDebt() (gas: 1981125) +MarketTest:testMaturityInsufficientProtocolLiquidity() (gas: 1464202) +MarketTest:testMultipleBorrowsForMultipleAssets() (gas: 2463626652) MarketTest:testMultipleDepositsToSmartPool() (gas: 915551) -MarketTest:testMultipleFixedBorrowsRepays() (gas: 1348281) -MarketTest:testMultipleLiquidationSameUser() (gas: 2958649) -MarketTest:testNotEnteredMarketShouldNotBeSeized() (gas: 8600726) +MarketTest:testMultipleFixedBorrowsRepays() (gas: 1348398) +MarketTest:testMultipleLiquidationSameUser() (gas: 2958727) +MarketTest:testNotEnteredMarketShouldNotBeSeized() (gas: 8605044) MarketTest:testOnlyAdminCanFreezeUnfreeze() (gas: 207681) -MarketTest:testOperationsShouldUpdateFloatingAssetsAverage() (gas: 1395087) -MarketTest:testOperationsWithBtcWbtcRate() (gas: 8302169) -MarketTest:testOperationsWithStEthAsset() (gas: 8178067) +MarketTest:testOperationsShouldUpdateFloatingAssetsAverage() (gas: 1445531) +MarketTest:testOperationsWithBtcWbtcRate() (gas: 8306487) +MarketTest:testOperationsWithStEthAsset() (gas: 8182385) MarketTest:testPausable() (gas: 158114) MarketTest:testPauserRole() (gas: 78206) -MarketTest:testPreviewOperationsWithSmartPoolCorrectlyAccountingEarnings() (gas: 1976217) -MarketTest:testRepayAtMaturity() (gas: 586677) -MarketTest:testRepayDisagreement() (gas: 593998) +MarketTest:testPreviewOperationsWithSmartPoolCorrectlyAccountingEarnings() (gas: 1976295) +MarketTest:testRepayAtMaturity() (gas: 586716) +MarketTest:testRepayDisagreement() (gas: 594037) MarketTest:testRepayFlexibleBorrow() (gas: 1076329) MarketTest:testRepayWhenFrozen() (gas: 535304) -MarketTest:testRoundingDownAssetsToValidateShortfallWhenTransferring() (gas: 7561032) -MarketTest:testRoundingDownAssetsToValidateShortfallWhenTransferringFrom() (gas: 7616361) -MarketTest:testRoundingDownAssetsWhenTransferingFromAnAccountWithoutShortfall() (gas: 1030122) -MarketTest:testRoundingDownAssetsWhenTransferingWithAnAccountWithoutShortfall() (gas: 974777) -MarketTest:testRoundingUpAllowanceWhenBorrowingAtMaturity() (gas: 845552) -MarketTest:testRoundingUpAllowanceWhenWithdrawingAtMaturity() (gas: 791671) +MarketTest:testRoundingDownAssetsToValidateShortfallWhenTransferring() (gas: 7565414) +MarketTest:testRoundingDownAssetsToValidateShortfallWhenTransferringFrom() (gas: 7620743) +MarketTest:testRoundingDownAssetsWhenTransferingFromAnAccountWithoutShortfall() (gas: 1030161) +MarketTest:testRoundingDownAssetsWhenTransferingWithAnAccountWithoutShortfall() (gas: 974816) +MarketTest:testRoundingUpAllowanceWhenBorrowingAtMaturity() (gas: 845669) +MarketTest:testRoundingUpAllowanceWhenWithdrawingAtMaturity() (gas: 791710) MarketTest:testSetAssetSymbol() (gas: 54991) MarketTest:testSetAssetSymbolNotAdmin() (gas: 66288) MarketTest:testSetDampSpeedFactorShouldUpdateFloatingAssetsAverage() (gas: 386872) -MarketTest:testSetEarningsAccumulatorSmoothFactorShouldDistributeEarnings() (gas: 722371) +MarketTest:testSetEarningsAccumulatorSmoothFactorShouldDistributeEarnings() (gas: 722410) MarketTest:testSetInterestRateModelShouldUpdateFloatingDebt() (gas: 2821264) MarketTest:testSetInterestRateModelWithAddressZeroShouldNotUpdateFloatingDebt() (gas: 2582220) MarketTest:testShareValueNotDecreasingAfterDeposit() (gas: 707842) MarketTest:testShareValueNotDecreasingWhenMintingToTreasury() (gas: 763178) MarketTest:testSingleFloatingBorrow() (gas: 417405) MarketTest:testSingleFloatingRepay() (gas: 484627) -MarketTest:testSmartPoolEarningsDistribution() (gas: 1104528) -MarketTest:testSmartPoolSharesDoNotAccountUnassignedEarningsFromMoreThanOneIntervalPastMaturities() (gas: 528510) -MarketTest:testSumDebtPlusEffectsShouldntRoundUpWhenWithdrawing() (gas: 1005524) -MarketTest:testTotalAssetsProjectingBackupEarningsCorrectly() (gas: 508219) +MarketTest:testSmartPoolEarningsDistribution() (gas: 1104567) +MarketTest:testSmartPoolSharesDoNotAccountUnassignedEarningsFromMoreThanOneIntervalPastMaturities() (gas: 528549) +MarketTest:testSumDebtPlusEffectsShouldntRoundUpWhenWithdrawing() (gas: 1005563) +MarketTest:testTotalAssetsProjectingBackupEarningsCorrectly() (gas: 508258) MarketTest:testTotalAssetsProjectingFloatingDebtCorrectly() (gas: 713915) -MarketTest:testUpdateAccumulatedEarningsFactorToZero() (gas: 1482098) +MarketTest:testUpdateAccumulatedEarningsFactorToZero() (gas: 1482137) MarketTest:testUpdateFloatingAssetsAverageWhenDepositingAndBorrowingContinuously() (gas: 344727) -MarketTest:testUpdateFloatingAssetsAverageWhenDepositingRightBeforeBorrow() (gas: 630288) +MarketTest:testUpdateFloatingAssetsAverageWhenDepositingRightBeforeBorrow() (gas: 670432) MarketTest:testUpdateFloatingAssetsAverageWhenDepositingRightBeforeEarlyWithdraw() (gas: 630610) -MarketTest:testUpdateFloatingAssetsAverageWhenDepositingSomeSecondsBeforeBorrow() (gas: 854932) -MarketTest:testUpdateFloatingAssetsAverageWhenWithdrawingRightBeforeBorrow() (gas: 643419) +MarketTest:testUpdateFloatingAssetsAverageWhenDepositingSomeSecondsBeforeBorrow() (gas: 901020) +MarketTest:testUpdateFloatingAssetsAverageWhenWithdrawingRightBeforeBorrow() (gas: 683563) MarketTest:testUpdateFloatingAssetsAverageWhenWithdrawingRightBeforeEarlyWithdraw() (gas: 643760) MarketTest:testUpdateFloatingAssetsAverageWhenWithdrawingSomeSecondsBeforeBorrow() (gas: 373112) MarketTest:testUpdateFloatingAssetsAverageWithDampSpeedDown() (gas: 358048) @@ -287,62 +287,62 @@ PoolLibTest:testEarningsDistribution() (gas: 32640) PoolLibTest:testFuzzAddRemoveAll(uint8[12]) (runs: 256, μ: 54793, ~: 54113) PoolLibTest:testMaturityRangeLimit() (gas: 7873) PoolLibTest:testMaturityRangeTooWide() (gas: 6831) -PreviewerTest:testAccountsReturningAccurateAmounts() (gas: 1393698) -PreviewerTest:testAccountsReturningUtilizationForDifferentMaturities() (gas: 4187253) +PreviewerTest:testAccountsReturningAccurateAmounts() (gas: 1393737) +PreviewerTest:testAccountsReturningUtilizationForDifferentMaturities() (gas: 4187370) PreviewerTest:testAccountsWithAccountOnlyDeposit() (gas: 862391) -PreviewerTest:testAccountsWithAccountThatHasBalances() (gas: 2265026) +PreviewerTest:testAccountsWithAccountThatHasBalances() (gas: 2265104) PreviewerTest:testAccountsWithEmptyAccount() (gas: 690558) -PreviewerTest:testAccountsWithIntermediateOperationsReturningAccurateAmounts() (gas: 17663715) +PreviewerTest:testAccountsWithIntermediateOperationsReturningAccurateAmounts() (gas: 17668144) PreviewerTest:testActualTimeBeforeStartDistributionRewards() (gas: 7809786) PreviewerTest:testEmptyExactly() (gas: 5690096) PreviewerTest:testExactlyReturningInterestRateModelData() (gas: 688149) -PreviewerTest:testFixedAvailableLiquidityProjectingNewFloatingDebt() (gas: 13347808) -PreviewerTest:testFixedPoolsA() (gas: 19364553) +PreviewerTest:testFixedAvailableLiquidityProjectingNewFloatingDebt() (gas: 13352198) +PreviewerTest:testFixedPoolsA() (gas: 19368943) PreviewerTest:testFixedPoolsChangingMaturityInTime() (gas: 1627253) -PreviewerTest:testFixedPoolsRatesAndUtilizations() (gas: 14861296) -PreviewerTest:testFixedPoolsWithFloatingAssetsAverage() (gas: 15684520) -PreviewerTest:testFlexibleAvailableLiquidity() (gas: 17288649) +PreviewerTest:testFixedPoolsRatesAndUtilizations() (gas: 14865686) +PreviewerTest:testFixedPoolsWithFloatingAssetsAverage() (gas: 15688871) +PreviewerTest:testFlexibleAvailableLiquidity() (gas: 17293000) PreviewerTest:testFlexibleBorrowSharesAndAssets() (gas: 4401038) -PreviewerTest:testFloatingAvailableLiquidityProjectingNewFloatingDebt() (gas: 12600546) +PreviewerTest:testFloatingAvailableLiquidityProjectingNewFloatingDebt() (gas: 12604858) PreviewerTest:testFloatingRateAndUtilization() (gas: 1128246) PreviewerTest:testJustUpdatedRewardRatesShouldStillReturnRate() (gas: 7219492) PreviewerTest:testMaxBorrowAssetsCapacity() (gas: 2469700) -PreviewerTest:testMaxBorrowAssetsCapacityForAccountWithShortfall() (gas: 11038065) -PreviewerTest:testMaxBorrowAssetsCapacityPerMarket() (gas: 13228190) -PreviewerTest:testOraclePriceReturningAccurateValues() (gas: 10179905) -PreviewerTest:testPreviewBorrowAtAllMaturitiesReturningAccurateAmount() (gas: 4240988) -PreviewerTest:testPreviewBorrowAtMaturityReturningAccurateAmount() (gas: 623350) -PreviewerTest:testPreviewBorrowAtMaturityReturningAccurateAmountWithIntermediateOperations() (gas: 1954376) -PreviewerTest:testPreviewBorrowAtMaturityReturningAccurateUtilization() (gas: 486616) -PreviewerTest:testPreviewBorrowAtMaturityWithFiveUnits() (gas: 423500) -PreviewerTest:testPreviewBorrowAtMaturityWithInvalidMaturity() (gas: 235094) +PreviewerTest:testMaxBorrowAssetsCapacityForAccountWithShortfall() (gas: 11042383) +PreviewerTest:testMaxBorrowAssetsCapacityPerMarket() (gas: 13232502) +PreviewerTest:testOraclePriceReturningAccurateValues() (gas: 10184223) +PreviewerTest:testPreviewBorrowAtAllMaturitiesReturningAccurateAmount() (gas: 4242626) +PreviewerTest:testPreviewBorrowAtMaturityReturningAccurateAmount() (gas: 623428) +PreviewerTest:testPreviewBorrowAtMaturityReturningAccurateAmountWithIntermediateOperations() (gas: 1954610) +PreviewerTest:testPreviewBorrowAtMaturityReturningAccurateUtilization() (gas: 486694) +PreviewerTest:testPreviewBorrowAtMaturityWithFiveUnits() (gas: 423539) +PreviewerTest:testPreviewBorrowAtMaturityWithInvalidMaturity() (gas: 235133) PreviewerTest:testPreviewBorrowAtMaturityWithMaturedMaturity() (gas: 50170) -PreviewerTest:testPreviewBorrowAtMaturityWithOneUnit() (gas: 423567) +PreviewerTest:testPreviewBorrowAtMaturityWithOneUnit() (gas: 423606) PreviewerTest:testPreviewBorrowAtMaturityWithSameTimestamp() (gas: 50088) -PreviewerTest:testPreviewBorrowAtMaturityWithZeroAmount() (gas: 224183) -PreviewerTest:testPreviewDepositAtAllMaturitiesReturningAccurateAmounts() (gas: 2416643) -PreviewerTest:testPreviewDepositAtMaturityReturningAccurateAmount() (gas: 798810) -PreviewerTest:testPreviewDepositAtMaturityReturningAccurateAmountWithIntermediateOperations() (gas: 1466561) +PreviewerTest:testPreviewBorrowAtMaturityWithZeroAmount() (gas: 224222) +PreviewerTest:testPreviewDepositAtAllMaturitiesReturningAccurateAmounts() (gas: 2416760) +PreviewerTest:testPreviewDepositAtMaturityReturningAccurateAmount() (gas: 798849) +PreviewerTest:testPreviewDepositAtMaturityReturningAccurateAmountWithIntermediateOperations() (gas: 1466639) PreviewerTest:testPreviewDepositAtMaturityWithEmptyMaturity() (gas: 48940) PreviewerTest:testPreviewDepositAtMaturityWithEmptyMaturityAndZeroAmount() (gas: 48917) PreviewerTest:testPreviewDepositAtMaturityWithInvalidMaturity() (gas: 48920) PreviewerTest:testPreviewDepositAtMaturityWithMaturedMaturity() (gas: 12565) -PreviewerTest:testPreviewDepositAtMaturityWithOneUnit() (gas: 589396) +PreviewerTest:testPreviewDepositAtMaturityWithOneUnit() (gas: 589435) PreviewerTest:testPreviewDepositAtMaturityWithSameTimestamp() (gas: 48970) -PreviewerTest:testPreviewDepositAtMaturityWithZeroAmount() (gas: 589418) -PreviewerTest:testPreviewRepayAtMaturityLastAccrualIsMaturity() (gas: 1436768) -PreviewerTest:testPreviewRepayAtMaturityReturningAccurateAmount() (gas: 1249676) -PreviewerTest:testPreviewRepayAtMaturityReturningAccurateAmountWithIntermediateOperations() (gas: 1553558) +PreviewerTest:testPreviewDepositAtMaturityWithZeroAmount() (gas: 589457) +PreviewerTest:testPreviewRepayAtMaturityLastAccrualIsMaturity() (gas: 1436846) +PreviewerTest:testPreviewRepayAtMaturityReturningAccurateAmount() (gas: 1249754) +PreviewerTest:testPreviewRepayAtMaturityReturningAccurateAmountWithIntermediateOperations() (gas: 1553636) PreviewerTest:testPreviewRepayAtMaturityWithEmptyMaturity() (gas: 35313) PreviewerTest:testPreviewRepayAtMaturityWithEmptyMaturityAndZeroAmount() (gas: 35355) PreviewerTest:testPreviewRepayAtMaturityWithInvalidMaturity() (gas: 35355) -PreviewerTest:testPreviewRepayAtMaturityWithMaturedMaturity() (gas: 588608) -PreviewerTest:testPreviewRepayAtMaturityWithOneUnit() (gas: 591831) -PreviewerTest:testPreviewRepayAtMaturityWithSameTimestamp() (gas: 586929) -PreviewerTest:testPreviewRepayAtMaturityWithZeroAmount() (gas: 591786) -PreviewerTest:testPreviewValueInFixedOperations() (gas: 2272969) +PreviewerTest:testPreviewRepayAtMaturityWithMaturedMaturity() (gas: 588647) +PreviewerTest:testPreviewRepayAtMaturityWithOneUnit() (gas: 591870) +PreviewerTest:testPreviewRepayAtMaturityWithSameTimestamp() (gas: 586968) +PreviewerTest:testPreviewRepayAtMaturityWithZeroAmount() (gas: 591825) +PreviewerTest:testPreviewValueInFixedOperations() (gas: 2273008) PreviewerTest:testPreviewWithdrawAtMaturityReturningAccurateAmount() (gas: 370901) -PreviewerTest:testPreviewWithdrawAtMaturityReturningAccurateAmountWithIntermediateOperations() (gas: 1404442) +PreviewerTest:testPreviewWithdrawAtMaturityReturningAccurateAmountWithIntermediateOperations() (gas: 1404481) PreviewerTest:testPreviewWithdrawAtMaturityWithEmptyMaturity() (gas: 35224) PreviewerTest:testPreviewWithdrawAtMaturityWithEmptyMaturityAndZeroAmount() (gas: 35267) PreviewerTest:testPreviewWithdrawAtMaturityWithFiveUnits() (gas: 251719) @@ -354,10 +354,10 @@ PreviewerTest:testPreviewWithdrawAtMaturityWithZeroAmount() (gas: 251675) PreviewerTest:testReserveFactor() (gas: 707280) PreviewerTest:testReturnRewardAssetUsdPrice() (gas: 6753659) PreviewerTest:testRewardsRateAfterDistributionEnd() (gas: 7525793) -PreviewerTest:testRewardsRateOnlyWithFixedBorrows() (gas: 6832946) -PreviewerTest:testRewardsRateWithDifferentRewardLengths() (gas: 19343622) -PreviewerTest:testRewardsRateWithMarketWithDifferentDecimals() (gas: 18474907) -PreviewerTest:testRewardsRateX() (gas: 8172399) +PreviewerTest:testRewardsRateOnlyWithFixedBorrows() (gas: 6832985) +PreviewerTest:testRewardsRateWithDifferentRewardLengths() (gas: 19347934) +PreviewerTest:testRewardsRateWithMarketWithDifferentDecimals() (gas: 18479258) +PreviewerTest:testRewardsRateX() (gas: 8172438) PriceFeedDoubleTest:testPriceFeedDoubleReturningAccurateDecimals() (gas: 632562) PriceFeedDoubleTest:testPriceFeedDoubleReturningPrice() (gas: 53190) PriceFeedDoubleTest:testPriceFeedDoubleWithActualOnChainValues() (gas: 76310) @@ -375,9 +375,9 @@ PriceFeedWrapperTest:testPriceFeedWrapperWithActualOnChainValues() (gas: 75210) PriceFeedWrapperTest:testPriceFeedWrapperWithNegativePriceShouldRevert() (gas: 164216) PriceFeedWrapperTest:testPriceFeedWrapperWithUsdPriceFeed() (gas: 1278197) RewardsControllerTest:testAccrueRewardsForWholeDistributionPeriod() (gas: 1245322) -RewardsControllerTest:testAccrueRewardsWithBadDebtClearingOfFixedBorrow() (gas: 3338667) +RewardsControllerTest:testAccrueRewardsWithBadDebtClearingOfFixedBorrow() (gas: 3338784) RewardsControllerTest:testAccrueRewardsWithRepayOfBorrowBalance() (gas: 1602615) -RewardsControllerTest:testAccrueRewardsWithRepayOfFixedBorrowBalance() (gas: 1791645) +RewardsControllerTest:testAccrueRewardsWithRepayOfFixedBorrowBalance() (gas: 1791684) RewardsControllerTest:testAccrueRewardsWithSeizeOfAllDepositShares() (gas: 1991114) RewardsControllerTest:testAfterDistributionPeriodEnd() (gas: 1818322) RewardsControllerTest:testAllClaimableUSDCWithAnotherAccountInPool() (gas: 2274252) @@ -391,17 +391,17 @@ RewardsControllerTest:testAllClaimableUSDCWithTransfer() (gas: 2221471) RewardsControllerTest:testAllClaimableUSDCWithTransferFrom() (gas: 2136365) RewardsControllerTest:testAllClaimableUSDCWithWithdraw() (gas: 1641850) RewardsControllerTest:testAllClaimableWETH() (gas: 1248402) -RewardsControllerTest:testAllClaimableWithMaturedFixedPool() (gas: 1128007) +RewardsControllerTest:testAllClaimableWithMaturedFixedPool() (gas: 1128046) RewardsControllerTest:testAllClaimableWithTimeElapsedZero() (gas: 1624747) RewardsControllerTest:testClaim() (gas: 1192249) RewardsControllerTest:testClaimAll() (gas: 2188892) -RewardsControllerTest:testClaimMarketWithoutRewards() (gas: 1241017) +RewardsControllerTest:testClaimMarketWithoutRewards() (gas: 1241095) RewardsControllerTest:testClaimWithNotEnabledRewardAsset() (gas: 1222725) RewardsControllerTest:testConfigSettingNewStartWithOnGoingDistributionShouldNotUpdate() (gas: 430252) RewardsControllerTest:testConfigWithDistributionNotYetStartedShouldNotFail() (gas: 613248) RewardsControllerTest:testConfigWithTransitionFactorHigherOrEqThanCap() (gas: 107077) RewardsControllerTest:testConfigWithZeroDepositAllocationWeightFactorShouldRevert() (gas: 71475) -RewardsControllerTest:testDifferentDistributionTimeForDifferentRewards() (gas: 2025778) +RewardsControllerTest:testDifferentDistributionTimeForDifferentRewards() (gas: 2025856) RewardsControllerTest:testEmitAccrue() (gas: 1317982) RewardsControllerTest:testEmitClaimRewards() (gas: 1112419) RewardsControllerTest:testEmitConfigUpdate() (gas: 439411) @@ -410,7 +410,7 @@ RewardsControllerTest:testLastUndistributed() (gas: 2189926) RewardsControllerTest:testOperationAfterDistributionEnded() (gas: 723020) RewardsControllerTest:testOperationsBeforeDistributionStart() (gas: 1674553) RewardsControllerTest:testPermitClaim() (gas: 1275326) -RewardsControllerTest:testSetDistributionConfigWithDifferentDecimals() (gas: 11502865) +RewardsControllerTest:testSetDistributionConfigWithDifferentDecimals() (gas: 11507183) RewardsControllerTest:testSetDistributionOperationShouldUpdateIndex() (gas: 136066) RewardsControllerTest:testSetDistributionWithOnGoingMarketOperations() (gas: 1202335) RewardsControllerTest:testSetHigherTotalDistribution() (gas: 1831337) @@ -428,14 +428,14 @@ RewardsControllerTest:testSetNewTreasuryFeeShouldImpactAllocation() (gas: 658948 RewardsControllerTest:testSetTargetDebtMultipleTimes() (gas: 2719552) RewardsControllerTest:testSetTargetDebtMultipleTimesAfterEnd() (gas: 2756047) RewardsControllerTest:testSetTotalDistributionMultipleTimes() (gas: 1838384) -RewardsControllerTest:testTriggerHandleBorrowHookBeforeUpdatingFloatingDebt() (gas: 1879494) +RewardsControllerTest:testTriggerHandleBorrowHookBeforeUpdatingFloatingDebt() (gas: 1879533) RewardsControllerTest:testUpdateConfig() (gas: 1328946) RewardsControllerTest:testUpdateConfigIncreaseRewardDistribution() (gas: 405501) RewardsControllerTest:testUpdateIndexesWithUtilizationEqualToOne() (gas: 1257815) RewardsControllerTest:testUpdateIndexesWithUtilizationHigherThanOne() (gas: 1352623) RewardsControllerTest:testUpdateWithTotalDebtZeroShouldUpdateLastUndistributed() (gas: 575527) RewardsControllerTest:testUtilizationEqualZero() (gas: 921840) -RewardsControllerTest:testWithTwelveFixedPools() (gas: 8055310) +RewardsControllerTest:testWithTwelveFixedPools() (gas: 8055817) RewardsControllerTest:testWithdrawAllRewardBalance() (gas: 71913) RewardsControllerTest:testWithdrawOnlyAdminRole() (gas: 122331) SwapperTest:testSwapBasic() (gas: 216831) diff --git a/contracts/Market.sol b/contracts/Market.sol index ebd194cf2..b22d5e384 100644 --- a/contracts/Market.sol +++ b/contracts/Market.sol @@ -319,7 +319,7 @@ contract Market is Initializable, AccessControlUpgradeable, PausableUpgradeable, floatingUtilization(memFloatingAssetsAverage, memFloatingDebt), globalUtilization(memFloatingAssetsAverage, memFloatingDebt, floatingBackupBorrowed) ); - fee = assets.mulWadDown(fixedRate.mulDivDown(maturity - block.timestamp, 365 days)); + fee = assets.mulWadUp(fixedRate.mulDivDown(maturity - block.timestamp, 365 days)); } assetsOwed = assets + fee; diff --git a/contracts/periphery/Previewer.sol b/contracts/periphery/Previewer.sol index d4dba29fd..885095f90 100644 --- a/contracts/periphery/Previewer.sol +++ b/contracts/periphery/Previewer.sol @@ -256,7 +256,7 @@ contract Previewer { : pool.unassignedEarnings ); - uint256 fees = assets.mulWadDown( + uint256 fees = assets.mulWadUp( market.interestRateModel().fixedBorrowRate( maturity, assets, diff --git a/test/Market.t.sol b/test/Market.t.sol index c5f763c28..be940476c 100644 --- a/test/Market.t.sol +++ b/test/Market.t.sol @@ -878,7 +878,7 @@ contract MarketTest is Test { // ATTACKER deposits just 1 at maturity, claiming all the unassigned earnings // by only providing 1 principal uint256 positionAssets = market.depositAtMaturity(maturity, 1, 0, attacker); - assertEq(positionAssets, 1); + assertEq(positionAssets, 2); } function testBorrowFromFreeLunchShouldNotRevertWithFloatingFullUtilization() external { @@ -1862,7 +1862,7 @@ contract MarketTest is Test { vm.warp(2000); market.deposit(100 ether, address(this)); - market.borrowAtMaturity(FixedLib.INTERVAL, 1, 1, address(this), address(this)); + market.borrowAtMaturity(FixedLib.INTERVAL, 1, 2, address(this), address(this)); assertApproxEqRel(market.floatingAssetsAverage(), initialBalance, 1e15); assertEq(market.floatingAssets(), 100 ether + initialBalance); } @@ -1876,7 +1876,7 @@ contract MarketTest is Test { uint256 lastFloatingAssetsAverage = market.floatingAssetsAverage(); vm.warp(250); - market.borrowAtMaturity(FixedLib.INTERVAL, 1, 1, address(this), address(this)); + market.borrowAtMaturity(FixedLib.INTERVAL, 1, 2, address(this), address(this)); uint256 supplyAverageFactor = uint256(1e18 - FixedPointMathLib.expWad(-int256(market.dampSpeedUp() * (250 - 218)))); assertEq( market.previewFloatingAssetsAverage(), @@ -1886,7 +1886,7 @@ contract MarketTest is Test { assertEq(market.previewFloatingAssetsAverage(), 20.521498717652997528 ether); vm.warp(9541); - market.borrowAtMaturity(FixedLib.INTERVAL, 1, 1, address(this), address(this)); + market.borrowAtMaturity(FixedLib.INTERVAL, 1, 2, address(this), address(this)); assertEq(market.previewFloatingAssetsAverage(), market.floatingAssets()); } @@ -1917,7 +1917,7 @@ contract MarketTest is Test { vm.warp(2000); market.withdraw(5 ether, address(this), address(this)); - market.borrowAtMaturity(FixedLib.INTERVAL, 1, 1, address(this), address(this)); + market.borrowAtMaturity(FixedLib.INTERVAL, 1, 2, address(this), address(this)); assertApproxEqRel(market.previewFloatingAssetsAverage(), initialBalance, 1e15); assertEq(market.floatingAssets(), initialBalance - 5 ether); } @@ -2584,7 +2584,7 @@ contract MarketTest is Test { // contract can cover all debt by repaying less than initial amount borrowed (93 < 100) (uint256 principal, uint256 fee) = market.fixedBorrowPositions(FixedLib.INTERVAL, address(this)); - market.repayAtMaturity(FixedLib.INTERVAL, principal + fee, 93, address(this)); + market.repayAtMaturity(FixedLib.INTERVAL, principal + fee, 94, address(this)); } function testClearMaturity() external { diff --git a/test/Previewer.t.sol b/test/Previewer.t.sol index 60b7bff35..a3a4d3920 100644 --- a/test/Previewer.t.sol +++ b/test/Previewer.t.sol @@ -294,7 +294,7 @@ contract PreviewerTest is Test { vm.warp(100 seconds); market.deposit(5 ether, address(this)); Previewer.FixedPreview memory preview = previewer.previewBorrowAtMaturity(market, FixedLib.INTERVAL, 1); - assertEq(preview.assets, 1); + assertEq(preview.assets, 2); } function testPreviewBorrowAtMaturityWithFiveUnits() external { @@ -302,7 +302,7 @@ contract PreviewerTest is Test { vm.warp(100 seconds); market.deposit(5 ether, address(this)); Previewer.FixedPreview memory preview = previewer.previewBorrowAtMaturity(market, FixedLib.INTERVAL, 5); - assertEq(preview.assets, 5); + assertEq(preview.assets, 6); } function testPreviewBorrowAtMaturityReturningAccurateAmountWithIntermediateOperations() external {