From f97a5770ea8a99f99471a7a89bcbb89d2edad59d Mon Sep 17 00:00:00 2001 From: itofarina Date: Fri, 8 Mar 2024 13:48:20 -0300 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20market:=20add=20frozen=20state?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .changeset/old-knives-live.md | 5 + .gas-snapshot | 470 +++++++++++++++++----------------- contracts/Market.sol | 29 ++- test/Market.t.sol | 107 ++++++++ 4 files changed, 379 insertions(+), 232 deletions(-) create mode 100644 .changeset/old-knives-live.md diff --git a/.changeset/old-knives-live.md b/.changeset/old-knives-live.md new file mode 100644 index 000000000..d5fc27384 --- /dev/null +++ b/.changeset/old-knives-live.md @@ -0,0 +1,5 @@ +--- +"@exactly/protocol": patch +--- + +✨ market: add frozen state diff --git a/.gas-snapshot b/.gas-snapshot index cf8bc40db..c097c1903 100644 --- a/.gas-snapshot +++ b/.gas-snapshot @@ -127,206 +127,220 @@ EscrowedEXATest:testWithdrawMaxFromMultipleStreams() (gas: 1020335) EscrowedEXATest:testWithdrawMaxShouldGiveReserveBackWhenDepleted() (gas: 333113) EscrowedEXATest:testWithdrawMaxWithInvalidSender() (gas: 352320) InstallmentsRouterTest:testAmountsLength() (gas: 13886) -InstallmentsRouterTest:testBorrowETHWithPermit() (gas: 912417) -InstallmentsRouterTest:testBorrowRouter() (gas: 607820) -InstallmentsRouterTest:testBorrowUnwrappedETH() (gas: 716435) -InstallmentsRouterTest:testBorrowWithPermit() (gas: 1000273) +InstallmentsRouterTest:testBorrowETHWithPermit() (gas: 913129) +InstallmentsRouterTest:testBorrowRouter() (gas: 608321) +InstallmentsRouterTest:testBorrowUnwrappedETH() (gas: 716936) +InstallmentsRouterTest:testBorrowWithPermit() (gas: 1000985) InstallmentsRouterTest:testFakeMarket() (gas: 25124) -InstallmentsRouterTest:testInsufficientMaxRepay() (gas: 607484) -InstallmentsRouterTest:testMaxRepay() (gas: 604372) +InstallmentsRouterTest:testInsufficientMaxRepay() (gas: 607985) +InstallmentsRouterTest:testMaxRepay() (gas: 604873) InstallmentsRouterTest:testMissingMarketWETH() (gas: 656725) -InstallmentsRouterTest:testMoreBorrowsThanMaxPools() (gas: 611040) +InstallmentsRouterTest:testMoreBorrowsThanMaxPools() (gas: 611708) InterestRateModelTest:testFixedBorrowRate() (gas: 1843854) InterestRateModelTest:testFixedRateRevertAlreadyMatured() (gas: 1857753) InterestRateModelTest:testFixedRateRevertUtilizationExceeded() (gas: 1865115) InterestRateModelTest:testFloatingBorrowRate() (gas: 1837111) InterestRateModelTest:testMinTimeToMaturity() (gas: 1875281) InterestRateModelTest:testRevertMaxUtilizationLowerThanWad() (gas: 40324) -MarketTest:testAccountLiquidityAdjustedDebt() (gas: 383523) -MarketTest:testAnotherUserRedeemWhenOwnerHasShortfall() (gas: 488833) -MarketTest:testAnotherUserWithdrawWhenOwnerHasShortfall() (gas: 476495) -MarketTest:testBorrowAtMaturity() (gas: 406005) -MarketTest:testBorrowAtMaturityUpdatesFloatingDebtAndFloatingAssets() (gas: 601225) -MarketTest:testBorrowAtMaturityWithZeroAssets() (gas: 16020) -MarketTest:testBorrowDisagreement() (gas: 222100) -MarketTest:testBorrowFromFreeLunchShouldNotRevertWithFloatingFullUtilization() (gas: 766259) -MarketTest:testCappedLiquidation() (gas: 700483) -MarketTest:testChargeTreasuryToEarlyWithdraws() (gas: 638131) -MarketTest:testChargeTreasuryToFixedBorrows() (gas: 850112) -MarketTest:testClearBadDebtAvoidingFixedBorrowsIfAccumulatorLower() (gas: 1165264) +MarketTest:testAccountLiquidityAdjustedDebt() (gas: 383857) +MarketTest:testAnotherUserRedeemWhenOwnerHasShortfall() (gas: 489312) +MarketTest:testAnotherUserWithdrawWhenOwnerHasShortfall() (gas: 476996) +MarketTest:testBorrowAfterFreezing() (gas: 331722) +MarketTest:testBorrowAtMaturity() (gas: 406317) +MarketTest:testBorrowAtMaturityAfterFreezing() (gas: 409001) +MarketTest:testBorrowAtMaturityUpdatesFloatingDebtAndFloatingAssets() (gas: 601937) +MarketTest:testBorrowAtMaturityWhenFrozen() (gas: 43341) +MarketTest:testBorrowAtMaturityWithZeroAssets() (gas: 18187) +MarketTest:testBorrowDisagreement() (gas: 222434) +MarketTest:testBorrowFromFreeLunchShouldNotRevertWithFloatingFullUtilization() (gas: 767094) +MarketTest:testBorrowWhenFrozen() (gas: 43309) +MarketTest:testCappedLiquidation() (gas: 701006) +MarketTest:testChargeTreasuryToEarlyWithdraws() (gas: 638654) +MarketTest:testChargeTreasuryToFixedBorrows() (gas: 850947) +MarketTest:testClearBadDebtAvoidingFixedBorrowsIfAccumulatorLower() (gas: 1166288) MarketTest:testClearBadDebtCalledByAccount() (gas: 13493) -MarketTest:testClearBadDebtExactlyRepaysFixedBorrowWithAccumulatorAmount() (gas: 996069) -MarketTest:testClearBadDebtPartiallyRepaysEachFixedBorrow() (gas: 1026937) -MarketTest:testClearBadDebtPartiallyRepaysFloatingDebt() (gas: 1134379) -MarketTest:testClearBadDebtShouldAccrueAccumulatedEarningsBeforeSpreadingLosses() (gas: 1126645) -MarketTest:testClearBadDebtWithEmptyAccumulatorShouldNotRevert() (gas: 583933) -MarketTest:testClearMaturity() (gas: 756779) -MarketTest:testCollectTreasuryFreeLunchToEarlyWithdraws() (gas: 769812) -MarketTest:testCollectTreasuryFreeLunchToEarlyWithdrawsWithZeroFees() (gas: 274884) -MarketTest:testCollectTreasuryFreeLunchToFixedBorrows() (gas: 879762) -MarketTest:testCollectTreasuryFreeLunchToFixedBorrowsWithZeroFees() (gas: 479376) -MarketTest:testCrossMaturityLiquidation() (gas: 1245829) -MarketTest:testDepositAtMaturity() (gas: 156436) -MarketTest:testDepositAtMaturityWithZeroAssets() (gas: 15918) -MarketTest:testDepositDisagreement() (gas: 32917) -MarketTest:testDepositShouldUpdateFlexibleBorrowVariables() (gas: 447512) -MarketTest:testDepositToSmartPool() (gas: 160031) -MarketTest:testDistributeMultipleAccumulatedEarnings() (gas: 756516) -MarketTest:testDistributionOfLossesShouldReduceFromFloatingBackupBorrowedAccordingly() (gas: 2193027) -MarketTest:testEarlyRepaymentWithExcessiveAmountOfFees() (gas: 2617022) -MarketTest:testEarlyWithdrawFromFreeLunchShouldNotRevertWithFloatingFullUtilization() (gas: 616855) -MarketTest:testFixedBorrowFailingWhenFlexibleBorrowAccruesDebt() (gas: 790681) -MarketTest:testFixedBorrowRateToMaturity() (gas: 410075) -MarketTest:testFlexibleBorrow() (gas: 331283) -MarketTest:testFlexibleBorrowAccountingDebt() (gas: 327165) -MarketTest:testFlexibleBorrowChargingDebtToTreasury() (gas: 482897) -MarketTest:testFlexibleBorrowExceedingReserve() (gas: 527474) -MarketTest:testFlexibleBorrowExceedingReserveIncludingFixedBorrow() (gas: 712338) -MarketTest:testFlexibleBorrowExceedingReserveWithNewDebt() (gas: 664471) -MarketTest:testFlexibleBorrowFromAnotherUserSubtractsAllowance() (gas: 354182) -MarketTest:testFlexibleBorrowFromAnotherUserWithAllowance() (gas: 346535) -MarketTest:testFlexibleBorrowFromAnotherUserWithoutAllowance() (gas: 181840) -MarketTest:testFrontRunSmartPoolEarningsDistributionWithBigPenaltyRepayment() (gas: 755474) -MarketTest:testFullPause() (gas: 1917955) -MarketTest:testInsufficientProtocolLiquidity() (gas: 876543) -MarketTest:testLiquidateAndChargeIncentiveForLenders() (gas: 992845) -MarketTest:testLiquidateAndDistributeLosses() (gas: 1335610) -MarketTest:testLiquidateAndSeizeExactAmountWithDustAsCollateral() (gas: 1317582) -MarketTest:testLiquidateAndSeizeFromEmptyCollateral() (gas: 618638) -MarketTest:testLiquidateAndSubtractLossesFromAccumulator() (gas: 1658820) -MarketTest:testLiquidateFlexibleAndFixedBorrowPositionsInSingleCall() (gas: 1163946) -MarketTest:testLiquidateFlexibleBorrow() (gas: 1101248) -MarketTest:testLiquidateFlexibleBorrowChargeLendersAssetsToLiquidator() (gas: 734352) -MarketTest:testLiquidateFlexibleBorrowConsideringDebtOverTime() (gas: 837017) -MarketTest:testLiquidateLeavingDustAsCollateral() (gas: 1519023) -MarketTest:testLiquidateWithTwoUnitsAsMaxAssets() (gas: 879599) -MarketTest:testLiquidateWithZeroAsMaxAssets() (gas: 618585) -MarketTest:testLiquidationClearingDebtOfAllAccountMarkets() (gas: 1515043) -MarketTest:testLiquidationResultingInZeroCollateralAndZeroDebt() (gas: 1067488) -MarketTest:testMaturityInsufficientProtocolLiquidity() (gas: 877963) -MarketTest:testMultipleBorrowsForMultipleAssets() (gas: 604123467) -MarketTest:testMultipleDepositsToSmartPool() (gas: 335924) -MarketTest:testMultipleFixedBorrowsRepays() (gas: 605881) -MarketTest:testMultipleLiquidationSameUser() (gas: 1449441) -MarketTest:testNotEnteredMarketShouldNotBeSeized() (gas: 6985901) -MarketTest:testOperationsShouldUpdateFloatingAssetsAverage() (gas: 649370) -MarketTest:testOperationsWithBtcWbtcRate() (gas: 6862564) -MarketTest:testOperationsWithStEthAsset() (gas: 6817175) -MarketTest:testPausable() (gas: 54415) -MarketTest:testPauserRole() (gas: 46964) -MarketTest:testPreviewOperationsWithSmartPoolCorrectlyAccountingEarnings() (gas: 879209) -MarketTest:testRepayAtMaturity() (gas: 354354) -MarketTest:testRepayDisagreement() (gas: 432041) -MarketTest:testRepayFlexibleBorrow() (gas: 560870) -MarketTest:testRoundingDownAssetsToValidateShortfallWhenTransferring() (gas: 6340828) -MarketTest:testRoundingDownAssetsToValidateShortfallWhenTransferringFrom() (gas: 6369562) -MarketTest:testRoundingDownAssetsWhenTransferingFromAnAccountWithoutShortfall() (gas: 594442) -MarketTest:testRoundingDownAssetsWhenTransferingWithAnAccountWithoutShortfall() (gas: 567576) -MarketTest:testRoundingUpAllowanceWhenBorrowingAtMaturity() (gas: 502967) -MarketTest:testRoundingUpAllowanceWhenWithdrawingAtMaturity() (gas: 526625) -MarketTest:testSetDampSpeedFactorShouldUpdateFloatingAssetsAverage() (gas: 243634) -MarketTest:testSetEarningsAccumulatorSmoothFactorShouldDistributeEarnings() (gas: 498256) -MarketTest:testSetInterestRateModelShouldUpdateFloatingDebt() (gas: 2345323) -MarketTest:testSetInterestRateModelWithAddressZeroShouldNotUpdateFloatingDebt() (gas: 2177674) -MarketTest:testShareValueNotDecreasingAfterDeposit() (gas: 473858) -MarketTest:testShareValueNotDecreasingWhenMintingToTreasury() (gas: 479677) -MarketTest:testSingleFloatingBorrow() (gas: 328444) -MarketTest:testSingleFloatingRepay() (gas: 287582) -MarketTest:testSmartPoolEarningsDistribution() (gas: 705387) -MarketTest:testSmartPoolSharesDoNotAccountUnassignedEarningsFromMoreThanOneIntervalPastMaturities() (gas: 434149) -MarketTest:testSumDebtPlusEffectsShouldntRoundUpWhenWithdrawing() (gas: 575038) -MarketTest:testTotalAssetsProjectingBackupEarningsCorrectly() (gas: 414384) -MarketTest:testTotalAssetsProjectingFloatingDebtCorrectly() (gas: 479783) -MarketTest:testUpdateAccumulatedEarningsFactorToZero() (gas: 812712) -MarketTest:testUpdateFloatingAssetsAverageWhenDepositingAndBorrowingContinuously() (gas: 239475) -MarketTest:testUpdateFloatingAssetsAverageWhenDepositingRightBeforeBorrow() (gas: 439041) -MarketTest:testUpdateFloatingAssetsAverageWhenDepositingRightBeforeEarlyWithdraw() (gas: 325390) -MarketTest:testUpdateFloatingAssetsAverageWhenDepositingSomeSecondsBeforeBorrow() (gas: 499567) -MarketTest:testUpdateFloatingAssetsAverageWhenWithdrawingRightBeforeBorrow() (gas: 444895) -MarketTest:testUpdateFloatingAssetsAverageWhenWithdrawingRightBeforeEarlyWithdraw() (gas: 342199) -MarketTest:testUpdateFloatingAssetsAverageWhenWithdrawingSomeSecondsBeforeBorrow() (gas: 268578) -MarketTest:testUpdateFloatingAssetsAverageWithDampSpeedDown() (gas: 255226) -MarketTest:testUpdateFloatingAssetsAverageWithDampSpeedUp() (gas: 175589) +MarketTest:testClearBadDebtExactlyRepaysFixedBorrowWithAccumulatorAmount() (gas: 996993) +MarketTest:testClearBadDebtPartiallyRepaysEachFixedBorrow() (gas: 1027772) +MarketTest:testClearBadDebtPartiallyRepaysFloatingDebt() (gas: 1135425) +MarketTest:testClearBadDebtShouldAccrueAccumulatedEarningsBeforeSpreadingLosses() (gas: 1127691) +MarketTest:testClearBadDebtWithEmptyAccumulatorShouldNotRevert() (gas: 584434) +MarketTest:testClearMaturity() (gas: 757313) +MarketTest:testCollectTreasuryFreeLunchToEarlyWithdraws() (gas: 770967) +MarketTest:testCollectTreasuryFreeLunchToEarlyWithdrawsWithZeroFees() (gas: 275218) +MarketTest:testCollectTreasuryFreeLunchToFixedBorrows() (gas: 881082) +MarketTest:testCollectTreasuryFreeLunchToFixedBorrowsWithZeroFees() (gas: 479921) +MarketTest:testCrossMaturityLiquidation() (gas: 1246831) +MarketTest:testDepositAfterFreezing() (gas: 163487) +MarketTest:testDepositAtMaturity() (gas: 158669) +MarketTest:testDepositAtMaturityAfterFreezing() (gas: 161551) +MarketTest:testDepositAtMaturityWhenFrozen() (gas: 43200) +MarketTest:testDepositAtMaturityWithZeroAssets() (gas: 18129) +MarketTest:testDepositDisagreement() (gas: 35106) +MarketTest:testDepositShouldUpdateFlexibleBorrowVariables() (gas: 448202) +MarketTest:testDepositToSmartPool() (gas: 160176) +MarketTest:testDepositWhenFrozen() (gas: 126880) +MarketTest:testDistributeMultipleAccumulatedEarnings() (gas: 757373) +MarketTest:testDistributionOfLossesShouldReduceFromFloatingBackupBorrowedAccordingly() (gas: 2195386) +MarketTest:testEarlyRepaymentWithExcessiveAmountOfFees() (gas: 2617712) +MarketTest:testEarlyWithdrawFromFreeLunchShouldNotRevertWithFloatingFullUtilization() (gas: 617523) +MarketTest:testEmitFrozen() (gas: 32730) +MarketTest:testFixedBorrowFailingWhenFlexibleBorrowAccruesDebt() (gas: 791371) +MarketTest:testFixedBorrowRateToMaturity() (gas: 410387) +MarketTest:testFlexibleBorrow() (gas: 331683) +MarketTest:testFlexibleBorrowAccountingDebt() (gas: 327566) +MarketTest:testFlexibleBorrowChargingDebtToTreasury() (gas: 483398) +MarketTest:testFlexibleBorrowExceedingReserve() (gas: 528076) +MarketTest:testFlexibleBorrowExceedingReserveIncludingFixedBorrow() (gas: 713151) +MarketTest:testFlexibleBorrowExceedingReserveWithNewDebt() (gas: 665139) +MarketTest:testFlexibleBorrowFromAnotherUserSubtractsAllowance() (gas: 354516) +MarketTest:testFlexibleBorrowFromAnotherUserWithAllowance() (gas: 346869) +MarketTest:testFlexibleBorrowFromAnotherUserWithoutAllowance() (gas: 182196) +MarketTest:testFrontRunSmartPoolEarningsDistributionWithBigPenaltyRepayment() (gas: 756098) +MarketTest:testFullPause() (gas: 1919389) +MarketTest:testInitiallyUnfrozen() (gas: 12687) +MarketTest:testInsufficientProtocolLiquidity() (gas: 877334) +MarketTest:testLiquidateAndChargeIncentiveForLenders() (gas: 993869) +MarketTest:testLiquidateAndDistributeLosses() (gas: 1336990) +MarketTest:testLiquidateAndSeizeExactAmountWithDustAsCollateral() (gas: 1318773) +MarketTest:testLiquidateAndSeizeFromEmptyCollateral() (gas: 619161) +MarketTest:testLiquidateAndSubtractLossesFromAccumulator() (gas: 1660023) +MarketTest:testLiquidateFlexibleAndFixedBorrowPositionsInSingleCall() (gas: 1164781) +MarketTest:testLiquidateFlexibleBorrow() (gas: 1102105) +MarketTest:testLiquidateFlexibleBorrowChargeLendersAssetsToLiquidator() (gas: 734853) +MarketTest:testLiquidateFlexibleBorrowConsideringDebtOverTime() (gas: 837518) +MarketTest:testLiquidateLeavingDustAsCollateral() (gas: 1520281) +MarketTest:testLiquidateWhenFrozen() (gas: 749078) +MarketTest:testLiquidateWithTwoUnitsAsMaxAssets() (gas: 880267) +MarketTest:testLiquidateWithZeroAsMaxAssets() (gas: 619086) +MarketTest:testLiquidationClearingDebtOfAllAccountMarkets() (gas: 1516590) +MarketTest:testLiquidationResultingInZeroCollateralAndZeroDebt() (gas: 1068345) +MarketTest:testMaturityInsufficientProtocolLiquidity() (gas: 879409) +MarketTest:testMultipleBorrowsForMultipleAssets() (gas: 604482013) +MarketTest:testMultipleDepositsToSmartPool() (gas: 337071) +MarketTest:testMultipleFixedBorrowsRepays() (gas: 606452) +MarketTest:testMultipleLiquidationSameUser() (gas: 1450298) +MarketTest:testNotEnteredMarketShouldNotBeSeized() (gas: 7038908) +MarketTest:testOnlyAdminCanFreezeUnfreeze() (gas: 100642) +MarketTest:testOperationsShouldUpdateFloatingAssetsAverage() (gas: 650249) +MarketTest:testOperationsWithBtcWbtcRate() (gas: 6915259) +MarketTest:testOperationsWithStEthAsset() (gas: 6869848) +MarketTest:testPausable() (gas: 54432) +MarketTest:testPauserRole() (gas: 46975) +MarketTest:testPreviewOperationsWithSmartPoolCorrectlyAccountingEarnings() (gas: 880356) +MarketTest:testRepayAtMaturity() (gas: 354621) +MarketTest:testRepayDisagreement() (gas: 432353) +MarketTest:testRepayFlexibleBorrow() (gas: 561626) +MarketTest:testRepayWhenFrozen() (gas: 310609) +MarketTest:testRoundingDownAssetsToValidateShortfallWhenTransferring() (gas: 6396673) +MarketTest:testRoundingDownAssetsToValidateShortfallWhenTransferringFrom() (gas: 6425451) +MarketTest:testRoundingDownAssetsWhenTransferingFromAnAccountWithoutShortfall() (gas: 595142) +MarketTest:testRoundingDownAssetsWhenTransferingWithAnAccountWithoutShortfall() (gas: 568244) +MarketTest:testRoundingUpAllowanceWhenBorrowingAtMaturity() (gas: 503635) +MarketTest:testRoundingUpAllowanceWhenWithdrawingAtMaturity() (gas: 527170) +MarketTest:testSetDampSpeedFactorShouldUpdateFloatingAssetsAverage() (gas: 243968) +MarketTest:testSetEarningsAccumulatorSmoothFactorShouldDistributeEarnings() (gas: 498779) +MarketTest:testSetInterestRateModelShouldUpdateFloatingDebt() (gas: 2345657) +MarketTest:testSetInterestRateModelWithAddressZeroShouldNotUpdateFloatingDebt() (gas: 2178008) +MarketTest:testShareValueNotDecreasingAfterDeposit() (gas: 474381) +MarketTest:testShareValueNotDecreasingWhenMintingToTreasury() (gas: 480200) +MarketTest:testSingleFloatingBorrow() (gas: 328756) +MarketTest:testSingleFloatingRepay() (gas: 287916) +MarketTest:testSmartPoolEarningsDistribution() (gas: 706121) +MarketTest:testSmartPoolSharesDoNotAccountUnassignedEarningsFromMoreThanOneIntervalPastMaturities() (gas: 434569) +MarketTest:testSumDebtPlusEffectsShouldntRoundUpWhenWithdrawing() (gas: 575684) +MarketTest:testTotalAssetsProjectingBackupEarningsCorrectly() (gas: 414763) +MarketTest:testTotalAssetsProjectingFloatingDebtCorrectly() (gas: 480284) +MarketTest:testUpdateAccumulatedEarningsFactorToZero() (gas: 813736) +MarketTest:testUpdateFloatingAssetsAverageWhenDepositingAndBorrowingContinuously() (gas: 239809) +MarketTest:testUpdateFloatingAssetsAverageWhenDepositingRightBeforeBorrow() (gas: 439608) +MarketTest:testUpdateFloatingAssetsAverageWhenDepositingRightBeforeEarlyWithdraw() (gas: 325913) +MarketTest:testUpdateFloatingAssetsAverageWhenDepositingSomeSecondsBeforeBorrow() (gas: 500213) +MarketTest:testUpdateFloatingAssetsAverageWhenWithdrawingRightBeforeBorrow() (gas: 445296) +MarketTest:testUpdateFloatingAssetsAverageWhenWithdrawingRightBeforeEarlyWithdraw() (gas: 342533) +MarketTest:testUpdateFloatingAssetsAverageWhenWithdrawingSomeSecondsBeforeBorrow() (gas: 268745) +MarketTest:testUpdateFloatingAssetsAverageWithDampSpeedDown() (gas: 255393) +MarketTest:testUpdateFloatingAssetsAverageWithDampSpeedUp() (gas: 175756) MarketTest:testUpdateFloatingDebtBeforeSettingTreasury() (gas: 84516) -MarketTest:testWithdrawAtMaturity() (gas: 167248) -MarketTest:testWithdrawFromSmartPool() (gas: 168692) -MarketTest:testWithdrawShouldUpdateFlexibleBorrowVariables() (gas: 497142) +MarketTest:testWithdrawAtMaturity() (gas: 169000) +MarketTest:testWithdrawFromSmartPool() (gas: 168852) +MarketTest:testWithdrawShouldUpdateFlexibleBorrowVariables() (gas: 497476) +MarketTest:testWithdrawWhenFrozen() (gas: 183927) PoolLibTest:testAtomicDepositBorrowRepayWithdraw() (gas: 38632) PoolLibTest:testBackupBorrow() (gas: 29484) PoolLibTest:testEarningsAccrual() (gas: 37652) PoolLibTest:testEarningsDistribution() (gas: 29456) PoolLibTest:testMaturityRangeLimit() (gas: 3729) PoolLibTest:testMaturityRangeTooWide() (gas: 6831) -PreviewerTest:testAccountsReturningAccurateAmounts() (gas: 1304353) -PreviewerTest:testAccountsReturningUtilizationForDifferentMaturities() (gas: 3678576) -PreviewerTest:testAccountsWithAccountOnlyDeposit() (gas: 834466) -PreviewerTest:testAccountsWithAccountThatHasBalances() (gas: 1798515) -PreviewerTest:testAccountsWithEmptyAccount() (gas: 683567) -PreviewerTest:testAccountsWithIntermediateOperationsReturningAccurateAmounts() (gas: 15786327) -PreviewerTest:testActualTimeBeforeStartDistributionRewards() (gas: 7065164) -PreviewerTest:testEmptyExactly() (gas: 5103665) -PreviewerTest:testExactlyReturningInterestRateModelData() (gas: 682516) -PreviewerTest:testFixedAvailableLiquidityProjectingNewFloatingDebt() (gas: 11459565) -PreviewerTest:testFixedPoolsA() (gas: 16809667) -PreviewerTest:testFixedPoolsChangingMaturityInTime() (gas: 1627938) -PreviewerTest:testFixedPoolsRatesAndUtilizations() (gas: 13270730) -PreviewerTest:testFixedPoolsWithFloatingAssetsAverage() (gas: 13746165) -PreviewerTest:testFlexibleAvailableLiquidity() (gas: 15139384) -PreviewerTest:testFlexibleBorrowSharesAndAssets() (gas: 3944447) -PreviewerTest:testFloatingAvailableLiquidityProjectingNewFloatingDebt() (gas: 10981551) -PreviewerTest:testFloatingRateAndUtilization() (gas: 1006150) -PreviewerTest:testJustUpdatedRewardRatesShouldStillReturnRate() (gas: 6301045) -PreviewerTest:testMaxBorrowAssetsCapacity() (gas: 2149811) -PreviewerTest:testMaxBorrowAssetsCapacityForAccountWithShortfall() (gas: 9595815) -PreviewerTest:testMaxBorrowAssetsCapacityPerMarket() (gas: 11095805) -PreviewerTest:testOraclePriceReturningAccurateValues() (gas: 9121822) -PreviewerTest:testPreviewBorrowAtAllMaturitiesReturningAccurateAmount() (gas: 3093902) -PreviewerTest:testPreviewBorrowAtMaturityReturningAccurateAmount() (gas: 523788) -PreviewerTest:testPreviewBorrowAtMaturityReturningAccurateAmountWithIntermediateOperations() (gas: 1187439) -PreviewerTest:testPreviewBorrowAtMaturityReturningAccurateUtilization() (gas: 379517) -PreviewerTest:testPreviewBorrowAtMaturityWithFiveUnits() (gas: 319388) -PreviewerTest:testPreviewBorrowAtMaturityWithInvalidMaturity() (gas: 212996) +PreviewerTest:testAccountsReturningAccurateAmounts() (gas: 1304753) +PreviewerTest:testAccountsReturningUtilizationForDifferentMaturities() (gas: 3679508) +PreviewerTest:testAccountsWithAccountOnlyDeposit() (gas: 834699) +PreviewerTest:testAccountsWithAccountThatHasBalances() (gas: 1799526) +PreviewerTest:testAccountsWithEmptyAccount() (gas: 683655) +PreviewerTest:testAccountsWithIntermediateOperationsReturningAccurateAmounts() (gas: 15840301) +PreviewerTest:testActualTimeBeforeStartDistributionRewards() (gas: 7065630) +PreviewerTest:testEmptyExactly() (gas: 5103731) +PreviewerTest:testExactlyReturningInterestRateModelData() (gas: 682582) +PreviewerTest:testFixedAvailableLiquidityProjectingNewFloatingDebt() (gas: 11512976) +PreviewerTest:testFixedPoolsA() (gas: 16864652) +PreviewerTest:testFixedPoolsChangingMaturityInTime() (gas: 1628136) +PreviewerTest:testFixedPoolsRatesAndUtilizations() (gas: 13324106) +PreviewerTest:testFixedPoolsWithFloatingAssetsAverage() (gas: 13799506) +PreviewerTest:testFlexibleAvailableLiquidity() (gas: 15193736) +PreviewerTest:testFlexibleBorrowSharesAndAssets() (gas: 3945445) +PreviewerTest:testFloatingAvailableLiquidityProjectingNewFloatingDebt() (gas: 11034795) +PreviewerTest:testFloatingRateAndUtilization() (gas: 1006550) +PreviewerTest:testJustUpdatedRewardRatesShouldStillReturnRate() (gas: 6301612) +PreviewerTest:testMaxBorrowAssetsCapacity() (gas: 2150510) +PreviewerTest:testMaxBorrowAssetsCapacityForAccountWithShortfall() (gas: 9648809) +PreviewerTest:testMaxBorrowAssetsCapacityPerMarket() (gas: 11149550) +PreviewerTest:testOraclePriceReturningAccurateValues() (gas: 9174315) +PreviewerTest:testPreviewBorrowAtAllMaturitiesReturningAccurateAmount() (gas: 3095427) +PreviewerTest:testPreviewBorrowAtMaturityReturningAccurateAmount() (gas: 524122) +PreviewerTest:testPreviewBorrowAtMaturityReturningAccurateAmountWithIntermediateOperations() (gas: 1188630) +PreviewerTest:testPreviewBorrowAtMaturityReturningAccurateUtilization() (gas: 379873) +PreviewerTest:testPreviewBorrowAtMaturityWithFiveUnits() (gas: 319722) +PreviewerTest:testPreviewBorrowAtMaturityWithInvalidMaturity() (gas: 213163) PreviewerTest:testPreviewBorrowAtMaturityWithMaturedMaturity() (gas: 50123) -PreviewerTest:testPreviewBorrowAtMaturityWithOneUnit() (gas: 319367) +PreviewerTest:testPreviewBorrowAtMaturityWithOneUnit() (gas: 319701) PreviewerTest:testPreviewBorrowAtMaturityWithSameTimestamp() (gas: 50041) -PreviewerTest:testPreviewBorrowAtMaturityWithZeroAmount() (gas: 201864) -PreviewerTest:testPreviewDepositAtAllMaturitiesReturningAccurateAmounts() (gas: 1554558) -PreviewerTest:testPreviewDepositAtMaturityReturningAccurateAmount() (gas: 584836) -PreviewerTest:testPreviewDepositAtMaturityReturningAccurateAmountWithIntermediateOperations() (gas: 858192) +PreviewerTest:testPreviewBorrowAtMaturityWithZeroAmount() (gas: 202031) +PreviewerTest:testPreviewDepositAtAllMaturitiesReturningAccurateAmounts() (gas: 1555982) +PreviewerTest:testPreviewDepositAtMaturityReturningAccurateAmount() (gas: 585359) +PreviewerTest:testPreviewDepositAtMaturityReturningAccurateAmountWithIntermediateOperations() (gas: 859260) PreviewerTest:testPreviewDepositAtMaturityWithEmptyMaturity() (gas: 45956) PreviewerTest:testPreviewDepositAtMaturityWithEmptyMaturityAndZeroAmount() (gas: 45955) PreviewerTest:testPreviewDepositAtMaturityWithInvalidMaturity() (gas: 45958) PreviewerTest:testPreviewDepositAtMaturityWithMaturedMaturity() (gas: 12551) -PreviewerTest:testPreviewDepositAtMaturityWithOneUnit() (gas: 497682) +PreviewerTest:testPreviewDepositAtMaturityWithOneUnit() (gas: 498016) PreviewerTest:testPreviewDepositAtMaturityWithSameTimestamp() (gas: 48511) -PreviewerTest:testPreviewDepositAtMaturityWithZeroAmount() (gas: 497726) -PreviewerTest:testPreviewRepayAtMaturityReturningAccurateAmount() (gas: 766890) -PreviewerTest:testPreviewRepayAtMaturityReturningAccurateAmountWithIntermediateOperations() (gas: 796800) +PreviewerTest:testPreviewDepositAtMaturityWithZeroAmount() (gas: 498060) +PreviewerTest:testPreviewRepayAtMaturityReturningAccurateAmount() (gas: 767558) +PreviewerTest:testPreviewRepayAtMaturityReturningAccurateAmountWithIntermediateOperations() (gas: 797468) PreviewerTest:testPreviewRepayAtMaturityWithEmptyMaturity() (gas: 35318) PreviewerTest:testPreviewRepayAtMaturityWithEmptyMaturityAndZeroAmount() (gas: 35338) PreviewerTest:testPreviewRepayAtMaturityWithInvalidMaturity() (gas: 35338) -PreviewerTest:testPreviewRepayAtMaturityWithMaturedMaturity() (gas: 496856) -PreviewerTest:testPreviewRepayAtMaturityWithOneUnit() (gas: 500037) -PreviewerTest:testPreviewRepayAtMaturityWithSameTimestamp() (gas: 495256) -PreviewerTest:testPreviewRepayAtMaturityWithZeroAmount() (gas: 500103) -PreviewerTest:testPreviewValueInFixedOperations() (gas: 2001550) -PreviewerTest:testPreviewWithdrawAtMaturityReturningAccurateAmount() (gas: 213115) -PreviewerTest:testPreviewWithdrawAtMaturityReturningAccurateAmountWithIntermediateOperations() (gas: 771300) +PreviewerTest:testPreviewRepayAtMaturityWithMaturedMaturity() (gas: 497190) +PreviewerTest:testPreviewRepayAtMaturityWithOneUnit() (gas: 500371) +PreviewerTest:testPreviewRepayAtMaturityWithSameTimestamp() (gas: 495590) +PreviewerTest:testPreviewRepayAtMaturityWithZeroAmount() (gas: 500437) +PreviewerTest:testPreviewValueInFixedOperations() (gas: 2002394) +PreviewerTest:testPreviewWithdrawAtMaturityReturningAccurateAmount() (gas: 214866) +PreviewerTest:testPreviewWithdrawAtMaturityReturningAccurateAmountWithIntermediateOperations() (gas: 771990) PreviewerTest:testPreviewWithdrawAtMaturityWithEmptyMaturity() (gas: 35229) PreviewerTest:testPreviewWithdrawAtMaturityWithEmptyMaturityAndZeroAmount() (gas: 35272) -PreviewerTest:testPreviewWithdrawAtMaturityWithFiveUnits() (gas: 220088) +PreviewerTest:testPreviewWithdrawAtMaturityWithFiveUnits() (gas: 222277) PreviewerTest:testPreviewWithdrawAtMaturityWithInvalidMaturity() (gas: 35293) -PreviewerTest:testPreviewWithdrawAtMaturityWithMaturedMaturity() (gas: 197469) -PreviewerTest:testPreviewWithdrawAtMaturityWithOneUnit() (gas: 220087) -PreviewerTest:testPreviewWithdrawAtMaturityWithSameTimestamp() (gas: 197485) -PreviewerTest:testPreviewWithdrawAtMaturityWithZeroAmount() (gas: 220133) -PreviewerTest:testReserveFactor() (gas: 683647) -PreviewerTest:testReturnRewardAssetUsdPrice() (gas: 6129550) -PreviewerTest:testRewardsRateAfterDistributionEnd() (gas: 6462682) -PreviewerTest:testRewardsRateOnlyWithFixedBorrows() (gas: 6161290) -PreviewerTest:testRewardsRateWithDifferentRewardLengths() (gas: 17138237) -PreviewerTest:testRewardsRateWithMarketWithDifferentDecimals() (gas: 16340216) -PreviewerTest:testRewardsRateX() (gas: 7222232) +PreviewerTest:testPreviewWithdrawAtMaturityWithMaturedMaturity() (gas: 199658) +PreviewerTest:testPreviewWithdrawAtMaturityWithOneUnit() (gas: 222276) +PreviewerTest:testPreviewWithdrawAtMaturityWithSameTimestamp() (gas: 199674) +PreviewerTest:testPreviewWithdrawAtMaturityWithZeroAmount() (gas: 222322) +PreviewerTest:testReserveFactor() (gas: 683713) +PreviewerTest:testReturnRewardAssetUsdPrice() (gas: 6129682) +PreviewerTest:testRewardsRateAfterDistributionEnd() (gas: 6463416) +PreviewerTest:testRewardsRateOnlyWithFixedBorrows() (gas: 6161690) +PreviewerTest:testRewardsRateWithDifferentRewardLengths() (gas: 17191349) +PreviewerTest:testRewardsRateWithMarketWithDifferentDecimals() (gas: 16393293) +PreviewerTest:testRewardsRateX() (gas: 7222865) PriceFeedDoubleTest:testPriceFeedDoubleReturningAccurateDecimals() (gas: 428034) PriceFeedDoubleTest:testPriceFeedDoubleReturningPrice() (gas: 26138) PriceFeedDoubleTest:testPriceFeedDoubleWithActualOnChainValues() (gas: 30888) @@ -343,67 +357,67 @@ PriceFeedWrapperTest:testPriceFeedWrapperReturningPriceAfterRebase() (gas: 22860 PriceFeedWrapperTest:testPriceFeedWrapperWithActualOnChainValues() (gas: 30260) PriceFeedWrapperTest:testPriceFeedWrapperWithNegativePriceShouldRevert() (gas: 43058) PriceFeedWrapperTest:testPriceFeedWrapperWithUsdPriceFeed() (gas: 1038001) -RewardsControllerTest:testAccrueRewardsForWholeDistributionPeriod() (gas: 965823) -RewardsControllerTest:testAccrueRewardsWithBadDebtClearingOfFixedBorrow() (gas: 1980921) -RewardsControllerTest:testAccrueRewardsWithRepayOfBorrowBalance() (gas: 1127267) -RewardsControllerTest:testAccrueRewardsWithRepayOfFixedBorrowBalance() (gas: 1222887) -RewardsControllerTest:testAccrueRewardsWithSeizeOfAllDepositShares() (gas: 1314760) -RewardsControllerTest:testAfterDistributionPeriodEnd() (gas: 1429625) -RewardsControllerTest:testAllClaimableUSDCWithAnotherAccountInPool() (gas: 1892685) -RewardsControllerTest:testAllClaimableUSDCWithDeposit() (gas: 1508944) -RewardsControllerTest:testAllClaimableUSDCWithFloatingBorrow() (gas: 1370175) -RewardsControllerTest:testAllClaimableUSDCWithFloatingRefund() (gas: 1291247) -RewardsControllerTest:testAllClaimableUSDCWithFloatingRepay() (gas: 1297749) -RewardsControllerTest:testAllClaimableUSDCWithMint() (gas: 1167084) -RewardsControllerTest:testAllClaimableUSDCWithRedeem() (gas: 1238456) -RewardsControllerTest:testAllClaimableUSDCWithTransfer() (gas: 1839396) -RewardsControllerTest:testAllClaimableUSDCWithTransferFrom() (gas: 1726596) -RewardsControllerTest:testAllClaimableUSDCWithWithdraw() (gas: 1239501) -RewardsControllerTest:testAllClaimableWETH() (gas: 1136922) -RewardsControllerTest:testAllClaimableWithMaturedFixedPool() (gas: 1009751) -RewardsControllerTest:testAllClaimableWithTimeElapsedZero() (gas: 1144959) -RewardsControllerTest:testClaim() (gas: 975073) -RewardsControllerTest:testClaimAll() (gas: 1683310) -RewardsControllerTest:testClaimMarketWithoutRewards() (gas: 940560) -RewardsControllerTest:testClaimWithNotEnabledRewardAsset() (gas: 1005042) -RewardsControllerTest:testConfigSettingNewStartWithOnGoingDistributionShouldNotUpdate() (gas: 345065) -RewardsControllerTest:testConfigWithDistributionNotYetStartedShouldNotFail() (gas: 497966) +RewardsControllerTest:testAccrueRewardsForWholeDistributionPeriod() (gas: 966157) +RewardsControllerTest:testAccrueRewardsWithBadDebtClearingOfFixedBorrow() (gas: 1982112) +RewardsControllerTest:testAccrueRewardsWithRepayOfBorrowBalance() (gas: 1127768) +RewardsControllerTest:testAccrueRewardsWithRepayOfFixedBorrowBalance() (gas: 1223388) +RewardsControllerTest:testAccrueRewardsWithSeizeOfAllDepositShares() (gas: 1315595) +RewardsControllerTest:testAfterDistributionPeriodEnd() (gas: 1429959) +RewardsControllerTest:testAllClaimableUSDCWithAnotherAccountInPool() (gas: 1893353) +RewardsControllerTest:testAllClaimableUSDCWithDeposit() (gas: 1509278) +RewardsControllerTest:testAllClaimableUSDCWithFloatingBorrow() (gas: 1370676) +RewardsControllerTest:testAllClaimableUSDCWithFloatingRefund() (gas: 1291748) +RewardsControllerTest:testAllClaimableUSDCWithFloatingRepay() (gas: 1298250) +RewardsControllerTest:testAllClaimableUSDCWithMint() (gas: 1167418) +RewardsControllerTest:testAllClaimableUSDCWithRedeem() (gas: 1238957) +RewardsControllerTest:testAllClaimableUSDCWithTransfer() (gas: 1839897) +RewardsControllerTest:testAllClaimableUSDCWithTransferFrom() (gas: 1727097) +RewardsControllerTest:testAllClaimableUSDCWithWithdraw() (gas: 1240002) +RewardsControllerTest:testAllClaimableWETH() (gas: 1137256) +RewardsControllerTest:testAllClaimableWithMaturedFixedPool() (gas: 1010085) +RewardsControllerTest:testAllClaimableWithTimeElapsedZero() (gas: 1145627) +RewardsControllerTest:testClaim() (gas: 975407) +RewardsControllerTest:testClaimAll() (gas: 1683978) +RewardsControllerTest:testClaimMarketWithoutRewards() (gas: 941228) +RewardsControllerTest:testClaimWithNotEnabledRewardAsset() (gas: 1005398) +RewardsControllerTest:testConfigSettingNewStartWithOnGoingDistributionShouldNotUpdate() (gas: 345232) +RewardsControllerTest:testConfigWithDistributionNotYetStartedShouldNotFail() (gas: 498133) RewardsControllerTest:testConfigWithTransitionFactorHigherOrEqThanCap() (gas: 49694) RewardsControllerTest:testConfigWithZeroDepositAllocationWeightFactorShouldRevert() (gas: 42855) -RewardsControllerTest:testDifferentDistributionTimeForDifferentRewards() (gas: 1530090) -RewardsControllerTest:testEmitAccrue() (gas: 965968) -RewardsControllerTest:testEmitClaimRewards() (gas: 869506) +RewardsControllerTest:testDifferentDistributionTimeForDifferentRewards() (gas: 1530758) +RewardsControllerTest:testEmitAccrue() (gas: 966469) +RewardsControllerTest:testEmitClaimRewards() (gas: 869840) RewardsControllerTest:testEmitConfigUpdate() (gas: 382669) -RewardsControllerTest:testEmitIndexUpdate() (gas: 1013934) -RewardsControllerTest:testLastUndistributed() (gas: 1434331) -RewardsControllerTest:testOperationAfterDistributionEnded() (gas: 614383) -RewardsControllerTest:testOperationsBeforeDistributionStart() (gas: 1202459) -RewardsControllerTest:testPermitClaim() (gas: 1059475) -RewardsControllerTest:testSetDistributionConfigWithDifferentDecimals() (gas: 9517980) +RewardsControllerTest:testEmitIndexUpdate() (gas: 1014268) +RewardsControllerTest:testLastUndistributed() (gas: 1434665) +RewardsControllerTest:testOperationAfterDistributionEnded() (gas: 614717) +RewardsControllerTest:testOperationsBeforeDistributionStart() (gas: 1202960) +RewardsControllerTest:testPermitClaim() (gas: 1059809) +RewardsControllerTest:testSetDistributionConfigWithDifferentDecimals() (gas: 9571343) RewardsControllerTest:testSetDistributionOperationShouldUpdateIndex() (gas: 111666) -RewardsControllerTest:testSetDistributionWithOnGoingMarketOperations() (gas: 954678) -RewardsControllerTest:testSetHigherTotalDistribution() (gas: 1238656) -RewardsControllerTest:testSetLowerAndEqualDistributionPeriodThanCurrentTimestampShouldRevert() (gas: 879439) -RewardsControllerTest:testSetLowerAndEqualTotalDistributionThanReleasedShouldRevert() (gas: 877252) -RewardsControllerTest:testSetLowerDistributionPeriod() (gas: 1428286) -RewardsControllerTest:testSetLowerDistributionPeriodAndLowerTotalDistribution() (gas: 1431011) -RewardsControllerTest:testSetLowerTotalDistribution() (gas: 1238569) -RewardsControllerTest:testSetNewDistributionPeriod() (gas: 1866336) -RewardsControllerTest:testSetNewDistributionPeriodAfterDistributionEnds() (gas: 1083638) -RewardsControllerTest:testSetNewTargetDebt() (gas: 1157777) -RewardsControllerTest:testSetNewTargetDebtAfterDistributionEnds() (gas: 1190128) -RewardsControllerTest:testSetNewTargetDebtWithClaimOnlyAtEnd() (gas: 1060882) -RewardsControllerTest:testSetNewTreasuryFeeShouldImpactAllocation() (gas: 506958) -RewardsControllerTest:testSetTargetDebtMultipleTimes() (gas: 1679211) -RewardsControllerTest:testSetTargetDebtMultipleTimesAfterEnd() (gas: 1684359) -RewardsControllerTest:testSetTotalDistributionMultipleTimes() (gas: 1222284) -RewardsControllerTest:testTriggerHandleBorrowHookBeforeUpdatingFloatingDebt() (gas: 1276637) -RewardsControllerTest:testUpdateConfig() (gas: 1017873) -RewardsControllerTest:testUpdateIndexesWithUtilizationEqualToOne() (gas: 961724) -RewardsControllerTest:testUpdateIndexesWithUtilizationHigherThanOne() (gas: 1013833) -RewardsControllerTest:testUpdateWithTotalDebtZeroShouldUpdateLastUndistributed() (gas: 407964) -RewardsControllerTest:testUtilizationEqualZero() (gas: 623015) -RewardsControllerTest:testWithTwelveFixedPools() (gas: 3685423) +RewardsControllerTest:testSetDistributionWithOnGoingMarketOperations() (gas: 955012) +RewardsControllerTest:testSetHigherTotalDistribution() (gas: 1238990) +RewardsControllerTest:testSetLowerAndEqualDistributionPeriodThanCurrentTimestampShouldRevert() (gas: 879773) +RewardsControllerTest:testSetLowerAndEqualTotalDistributionThanReleasedShouldRevert() (gas: 877586) +RewardsControllerTest:testSetLowerDistributionPeriod() (gas: 1428620) +RewardsControllerTest:testSetLowerDistributionPeriodAndLowerTotalDistribution() (gas: 1431345) +RewardsControllerTest:testSetLowerTotalDistribution() (gas: 1238903) +RewardsControllerTest:testSetNewDistributionPeriod() (gas: 1866670) +RewardsControllerTest:testSetNewDistributionPeriodAfterDistributionEnds() (gas: 1083972) +RewardsControllerTest:testSetNewTargetDebt() (gas: 1158111) +RewardsControllerTest:testSetNewTargetDebtAfterDistributionEnds() (gas: 1190462) +RewardsControllerTest:testSetNewTargetDebtWithClaimOnlyAtEnd() (gas: 1061216) +RewardsControllerTest:testSetNewTreasuryFeeShouldImpactAllocation() (gas: 507292) +RewardsControllerTest:testSetTargetDebtMultipleTimes() (gas: 1679712) +RewardsControllerTest:testSetTargetDebtMultipleTimesAfterEnd() (gas: 1684860) +RewardsControllerTest:testSetTotalDistributionMultipleTimes() (gas: 1222618) +RewardsControllerTest:testTriggerHandleBorrowHookBeforeUpdatingFloatingDebt() (gas: 1277661) +RewardsControllerTest:testUpdateConfig() (gas: 1018207) +RewardsControllerTest:testUpdateIndexesWithUtilizationEqualToOne() (gas: 962225) +RewardsControllerTest:testUpdateIndexesWithUtilizationHigherThanOne() (gas: 1014334) +RewardsControllerTest:testUpdateWithTotalDebtZeroShouldUpdateLastUndistributed() (gas: 408298) +RewardsControllerTest:testUtilizationEqualZero() (gas: 623516) +RewardsControllerTest:testWithTwelveFixedPools() (gas: 3687761) RewardsControllerTest:testWithdrawAllRewardBalance() (gas: 47126) RewardsControllerTest:testWithdrawOnlyAdminRole() (gas: 84360) SwapperTest:testSwapBasic() (gas: 194295) diff --git a/contracts/Market.sol b/contracts/Market.sol index 06379b902..bc0e2ba60 100644 --- a/contracts/Market.sol +++ b/contracts/Market.sol @@ -89,6 +89,9 @@ contract Market is Initializable, AccessControlUpgradeable, PausableUpgradeable, /// @notice Address of the rewards controller that will accrue rewards for accounts operating with the Market. RewardsController public rewardsController; + /// @notice Flag to prevent new borrows and deposits. + bool public isFrozen; + /// @custom:oz-upgrades-unsafe-allow constructor constructor(ERC20 asset_, Auditor auditor_) ERC4626(asset_, "", "") { auditor = auditor_; @@ -138,7 +141,7 @@ contract Market is Initializable, AccessControlUpgradeable, PausableUpgradeable, uint256 assets, address receiver, address borrower - ) external whenNotPaused returns (uint256 borrowShares) { + ) external whenNotPaused whenNotFrozen returns (uint256 borrowShares) { spendAllowance(borrower, assets); RewardsController memRewardsController = rewardsController; @@ -231,7 +234,7 @@ contract Market is Initializable, AccessControlUpgradeable, PausableUpgradeable, uint256 assets, uint256 minAssetsRequired, address receiver - ) external whenNotPaused returns (uint256 positionAssets) { + ) external whenNotPaused whenNotFrozen returns (uint256 positionAssets) { if (assets == 0) revert ZeroDeposit(); // reverts on failure FixedLib.checkPoolState(maturity, maxFuturePools, FixedLib.State.VALID, FixedLib.State.NONE); @@ -281,7 +284,7 @@ contract Market is Initializable, AccessControlUpgradeable, PausableUpgradeable, uint256 maxAssets, address receiver, address borrower - ) external whenNotPaused returns (uint256 assetsOwed) { + ) external whenNotPaused whenNotFrozen returns (uint256 assetsOwed) { if (assets == 0) revert ZeroBorrow(); // reverts on failure FixedLib.checkPoolState(maturity, maxFuturePools, FixedLib.State.VALID, FixedLib.State.NONE); @@ -704,7 +707,7 @@ contract Market is Initializable, AccessControlUpgradeable, PausableUpgradeable, /// @notice Hook to update the floating pool average, floating pool balance and distribute earnings from accumulator. /// @param assets amount of assets to be deposited to the floating pool. - function afterDeposit(uint256 assets, uint256) internal override whenNotPaused { + function afterDeposit(uint256 assets, uint256) internal override whenNotPaused whenNotFrozen { updateFloatingAssetsAverage(); uint256 treasuryFee = updateFloatingDebt(); uint256 earnings = accrueAccumulatedEarnings(); @@ -1122,6 +1125,20 @@ contract Market is Initializable, AccessControlUpgradeable, PausableUpgradeable, _unpause(); } + function setFrozen(bool isFrozen_) external onlyRole(DEFAULT_ADMIN_ROLE) { + isFrozen = isFrozen_; + emit Frozen(msg.sender, isFrozen_); + } + + function requireNotFrozen() internal view { + if (isFrozen) revert MarketFrozen(); + } + + modifier whenNotFrozen() { + requireNotFrozen(); + _; + } + /// @notice Event emitted when an account borrows amount of assets from a floating pool. /// @param caller address which borrowed the asset. /// @param receiver address that received the borrowed assets. @@ -1300,6 +1317,9 @@ contract Market is Initializable, AccessControlUpgradeable, PausableUpgradeable, /// @param utilization new floating utilization. event FloatingDebtUpdate(uint256 timestamp, uint256 utilization); + /// @notice Emitted when `account` sets the `isFrozen` flag. + event Frozen(address account, bool isFrozen); + /// @notice Stores fixed deposits and fixed borrows map and floating borrow shares of an account. /// @param fixedDeposits encoded map maturity dates where the account supplied to. /// @param fixedBorrows encoded map maturity dates where the account borrowed from. @@ -1313,6 +1333,7 @@ contract Market is Initializable, AccessControlUpgradeable, PausableUpgradeable, error Disagreement(); error InsufficientProtocolLiquidity(); +error MarketFrozen(); error NotAuditor(); error SelfLiquidation(); error ZeroBorrow(); diff --git a/test/Market.t.sol b/test/Market.t.sol index d1c7e6553..57aa3b9b3 100644 --- a/test/Market.t.sol +++ b/test/Market.t.sol @@ -24,6 +24,7 @@ import { ZeroDeposit, ZeroWithdraw, Disagreement, + MarketFrozen, InsufficientProtocolLiquidity } from "../contracts/Market.sol"; @@ -2697,6 +2698,111 @@ contract MarketTest is Test { assertTrue(market.hasRole(market.PAUSER_ROLE(), address(this))); } + function testInitiallyUnfrozen() external { + assertFalse(market.isFrozen()); + } + + function testOnlyAdminCanFreezeUnfreeze() external { + vm.startPrank(BOB); + vm.expectRevert(bytes("")); + market.setFrozen(false); + vm.expectRevert(bytes("")); + market.setFrozen(false); + vm.stopPrank(); + + market.setFrozen(true); + assertTrue(market.isFrozen()); + market.setFrozen(false); + assertFalse(market.isFrozen()); + } + + function testDepositWhenFrozen() external { + market.setFrozen(true); + vm.expectRevert(MarketFrozen.selector); + market.deposit(10 ether, address(this)); + } + + function testDepositAtMaturityWhenFrozen() external { + market.setFrozen(true); + vm.expectRevert(MarketFrozen.selector); + market.depositAtMaturity(FixedLib.INTERVAL, 1 ether, 1 ether, address(this)); + } + + function testDepositAfterFreezing() external { + market.setFrozen(true); + market.setFrozen(false); + market.deposit(10 ether, address(this)); + } + + function testDepositAtMaturityAfterFreezing() external { + market.setFrozen(true); + market.setFrozen(false); + market.depositAtMaturity(FixedLib.INTERVAL, 1 ether, 1 ether, address(this)); + } + + function testBorrowWhenFrozen() external { + market.setFrozen(true); + vm.expectRevert(MarketFrozen.selector); + market.borrow(1 ether, address(this), address(this)); + } + + function testBorrowAtMaturityWhenFrozen() external { + market.setFrozen(true); + vm.expectRevert(MarketFrozen.selector); + market.borrowAtMaturity(FixedLib.INTERVAL, 1 ether, 1 ether, address(this), address(this)); + } + + function testBorrowAfterFreezing() external { + market.deposit(2 ether, address(this)); + market.setFrozen(true); + market.setFrozen(false); + market.borrow(1 ether, address(this), address(this)); + } + + function testBorrowAtMaturityAfterFreezing() external { + market.deposit(2 ether, address(this)); + market.setFrozen(true); + market.setFrozen(false); + market.borrowAtMaturity(FixedLib.INTERVAL, 1 ether, 1.1 ether, address(this), address(this)); + } + + function testRepayWhenFrozen() external { + market.deposit(2 ether, address(this)); + market.borrow(1 ether, address(this), address(this)); + market.setFrozen(true); + market.repay(1 ether, address(this)); + } + + function testWithdrawWhenFrozen() external { + market.deposit(2 ether, address(this)); + market.setFrozen(true); + market.withdraw(2 ether, address(this), address(this)); + } + + function testLiquidateWhenFrozen() external { + market.deposit(10 ether, address(this)); + marketWETH.deposit(1 ether, BOB); + daiPriceFeed.setPrice(0.0001e18); + vm.startPrank(BOB); + auditor.enterMarket(marketWETH); + market.borrow(5 ether, BOB, BOB); + vm.stopPrank(); + + market.setFrozen(true); + daiPriceFeed.setPrice(0.2e18); + market.liquidate(BOB, 1 ether, marketWETH); + } + + function testEmitFrozen() external { + vm.expectEmit(true, true, true, true, address(market)); + emit Frozen(address(this), true); + market.setFrozen(true); + + vm.expectEmit(true, true, true, true, address(market)); + emit Frozen(address(this), false); + market.setFrozen(false); + } + event MarketUpdate( uint256 timestamp, uint256 floatingDepositShares, @@ -2755,6 +2861,7 @@ contract MarketTest is Test { uint256 seizedAssets ); event SpreadBadDebt(address indexed borrower, uint256 assets); + event Frozen(address account, bool isFrozen); } contract MarketHarness is Market {