Skip to content

Commit

Permalink
⚡️ market: transfer liquidator repayment first
Browse files Browse the repository at this point in the history
  • Loading branch information
santichez committed May 24, 2024
1 parent e484f5f commit 7e654d6
Show file tree
Hide file tree
Showing 4 changed files with 94 additions and 63 deletions.
5 changes: 5 additions & 0 deletions .changeset/slimy-numbers-reply.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@exactly/protocol": patch
---

⚡️ market: transfer liquidator repayment first
123 changes: 62 additions & 61 deletions .gas-snapshot
Original file line number Diff line number Diff line change
Expand Up @@ -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, μ: 6518309, ~: 6575002)
DebtManagerTest:testLateFixedRoll() (gas: 1310831)
DebtManagerTest:testLateFixedRollWithThreeLoops() (gas: 1897545)
DebtManagerTest:testLateFixedToFloatingRoll() (gas: 1273784)
Expand All @@ -58,11 +58,11 @@ DebtManagerTest:testLeverage() (gas: 624861)
DebtManagerTest:testLeverageIncremental() (gas: 1334229)
DebtManagerTest:testLeverageShouldFailWhenHealthFactorNearOne() (gas: 1328819)
DebtManagerTest:testLeverageWithAlreadyDepositedAmount() (gas: 812467)
DebtManagerTest:testLeverageWithInvalidBalancerVault() (gas: 3921027)
DebtManagerTest:testLeverageWithInvalidBalancerVault() (gas: 3921015)
DebtManagerTest:testLeverageWithMoreThanBalancerAvailableLiquidity() (gas: 1000405)
DebtManagerTest:testLeverageWithNegativePrincipal() (gas: 1255085)
DebtManagerTest:testLeverageWithPartialNegativePrincipal() (gas: 1424159)
DebtManagerTest:testMockBalancerVault() (gas: 6144490)
DebtManagerTest:testMockBalancerVault() (gas: 6144478)
DebtManagerTest:testPartialDeleverageWithWithdrawAndNewRatio() (gas: 1031475)
DebtManagerTest:testPartialDeleverageWithWithdrawKeepingRatio() (gas: 1031481)
DebtManagerTest:testPartialFixedRoll() (gas: 1200784)
Expand Down Expand Up @@ -143,7 +143,7 @@ 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, μ: 10012812, ~: 10176711)
InterestRateModelTest:testFuzzReferenceLegacyRateFixed(uint32,uint256,uint256[2],uint256[2],uint256,uint256,uint256) (runs: 256, μ: 10012632, ~: 10176531)
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)
Expand All @@ -155,13 +155,13 @@ MarketTest:testBorrowAfterFreezing() (gas: 491482)
MarketTest:testBorrowAtMaturity() (gas: 499544)
MarketTest:testBorrowAtMaturityAfterFreezing() (gas: 573160)
MarketTest:testBorrowAtMaturityUpdatesFloatingDebtAndFloatingAssets() (gas: 884694)
MarketTest:testBorrowAtMaturityWhenFrozen() (gas: 93718)
MarketTest:testBorrowAtMaturityWhenFrozen() (gas: 93696)
MarketTest:testBorrowAtMaturityWithZeroAssets() (gas: 40425)
MarketTest:testBorrowDisagreement() (gas: 295415)
MarketTest:testBorrowFromFreeLunchShouldNotRevertWithFloatingFullUtilization() (gas: 1294314)
MarketTest:testBorrowWhenFrozen() (gas: 93224)
MarketTest:testBorrowWithZeroAssets() (gas: 39771)
MarketTest:testCappedLiquidation() (gas: 1197518)
MarketTest:testCappedLiquidation() (gas: 1197582)
MarketTest:testChargeTreasuryToEarlyWithdraws() (gas: 1218518)
MarketTest:testChargeTreasuryToFixedBorrows() (gas: 1588154)
MarketTest:testClearBadDebtAvoidingFixedBorrowsIfAccumulatorLower() (gas: 2289133)
Expand All @@ -171,32 +171,32 @@ MarketTest:testClearBadDebtPartiallyRepaysEachFixedBorrow() (gas: 1967027)
MarketTest:testClearBadDebtPartiallyRepaysFloatingDebt() (gas: 2297233)
MarketTest:testClearBadDebtShouldAccrueAccumulatedEarningsBeforeSpreadingLosses() (gas: 2086994)
MarketTest:testClearBadDebtWithEmptyAccumulatorShouldNotRevert() (gas: 969888)
MarketTest:testClearMaturity() (gas: 1693560)
MarketTest:testClearMaturity() (gas: 1693538)
MarketTest:testCollectTreasuryFreeLunchToEarlyWithdraws() (gas: 1766265)
MarketTest:testCollectTreasuryFreeLunchToEarlyWithdrawsWithZeroFees() (gas: 559337)
MarketTest:testCollectTreasuryFreeLunchToFixedBorrows() (gas: 1820422)
MarketTest:testCollectTreasuryFreeLunchToFixedBorrowsWithZeroFees() (gas: 722718)
MarketTest:testCrossMaturityLiquidation() (gas: 2627137)
MarketTest:testDepositAfterFreezing() (gas: 256227)
MarketTest:testCollectTreasuryFreeLunchToFixedBorrowsWithZeroFees() (gas: 722696)
MarketTest:testCrossMaturityLiquidation() (gas: 2627134)
MarketTest:testDepositAfterFreezing() (gas: 256205)
MarketTest:testDepositAtMaturity() (gas: 193478)
MarketTest:testDepositAtMaturityAfterFreezing() (gas: 267449)
MarketTest:testDepositAtMaturityWhenFrozen() (gas: 93209)
MarketTest:testDepositAtMaturityWithZeroAssets() (gas: 39977)
MarketTest:testDepositDisagreement() (gas: 73882)
MarketTest:testDepositShouldUpdateFlexibleBorrowVariables() (gas: 716971)
MarketTest:testDepositShouldUpdateFlexibleBorrowVariables() (gas: 716949)
MarketTest:testDepositToSmartPool() (gas: 181849)
MarketTest:testDepositWhenFrozen() (gas: 176471)
MarketTest:testDistributeMultipleAccumulatedEarnings() (gas: 1382739)
MarketTest:testDistributionOfLossesShouldReduceFromFloatingBackupBorrowedAccordingly() (gas: 6413453)
MarketTest:testEarlyRepayLiquidationUnassignedEarnings() (gas: 2063718)
MarketTest:testDistributionOfLossesShouldReduceFromFloatingBackupBorrowedAccordingly() (gas: 6413447)
MarketTest:testEarlyRepayLiquidationUnassignedEarnings() (gas: 2063715)
MarketTest:testEarlyRepaymentWithExcessiveAmountOfFees() (gas: 3419104)
MarketTest:testEarlyWithdrawFromFreeLunchShouldNotRevertWithFloatingFullUtilization() (gas: 1050081)
MarketTest:testEmergencyAdminRole() (gas: 317196)
MarketTest:testEmitFrozen() (gas: 91114)
MarketTest:testFixedBorrowFailingWhenFlexibleBorrowAccruesDebt() (gas: 1530855)
MarketTest:testFixedBorrowFailingWhenFlexibleBorrowAccruesDebt() (gas: 1530833)
MarketTest:testFixedBorrowRateToMaturity() (gas: 562488)
MarketTest:testFixedOperationsUpdateFloatingDebt() (gas: 865363)
MarketTest:testFlexibleBorrow() (gas: 423656)
MarketTest:testFlexibleBorrow() (gas: 423743)
MarketTest:testFlexibleBorrowAccountingDebt() (gas: 607131)
MarketTest:testFlexibleBorrowChargingDebtToTreasury() (gas: 751177)
MarketTest:testFlexibleBorrowExceedingReserve() (gas: 878408)
Expand All @@ -206,44 +206,45 @@ MarketTest:testFlexibleBorrowFromAnotherUserSubtractsAllowance() (gas: 469265)
MarketTest:testFlexibleBorrowFromAnotherUserWithAllowance() (gas: 458659)
MarketTest:testFlexibleBorrowFromAnotherUserWithoutAllowance() (gas: 252359)
MarketTest:testFrontRunSmartPoolEarningsDistributionWithBigPenaltyRepayment() (gas: 1381929)
MarketTest:testFullPause() (gas: 5938463)
MarketTest:testFullPause() (gas: 5956320)
MarketTest:testInitiallyUnfrozen() (gas: 15614)
MarketTest:testInsufficientProtocolLiquidity() (gas: 1940379)
MarketTest:testLiquidateAndChargeIncentiveForLenders() (gas: 2431163)
MarketTest:testLiquidateAndDistributeLosses() (gas: 3239738)
MarketTest:testLiquidateAndSeizeExactAmountWithDustAsCollateral() (gas: 2807527)
MarketTest:testLiquidateAndChargeIncentiveForLenders() (gas: 2431160)
MarketTest:testLiquidateAndDistributeLosses() (gas: 3239735)
MarketTest:testLiquidateAndSeizeExactAmountWithDustAsCollateral() (gas: 2807502)
MarketTest:testLiquidateAndSeizeFromEmptyCollateral() (gas: 1039302)
MarketTest:testLiquidateAndSubtractLossesFromAccumulator() (gas: 3932663)
MarketTest:testLiquidateFlexibleAndFixedBorrowPositionsInSingleCall() (gas: 2631851)
MarketTest:testLiquidateFlexibleBorrow() (gas: 2156192)
MarketTest:testLiquidateFlexibleBorrowChargeLendersAssetsToLiquidator() (gas: 1150182)
MarketTest:testLiquidateFlexibleBorrowConsideringDebtOverTime() (gas: 1166273)
MarketTest:testLiquidateLeavingDustAsCollateral() (gas: 3622093)
MarketTest:testLiquidateUpdateFloatingDebt() (gas: 1901729)
MarketTest:testLiquidateWhenFrozen() (gas: 1230791)
MarketTest:testLiquidateWithTwoUnitsAsMaxAssets() (gas: 1576945)
MarketTest:testLiquidateWithZeroAsMaxAssets() (gas: 1039165)
MarketTest:testLiquidationClearingDebtOfAllAccountMarkets() (gas: 3105089)
MarketTest:testLiquidationResultingInZeroCollateralAndZeroDebt() (gas: 1980784)
MarketTest:testMaturityInsufficientProtocolLiquidity() (gas: 1464075)
MarketTest:testMultipleBorrowsForMultipleAssets() (gas: 2463506086)
MarketTest:testMultipleDepositsToSmartPool() (gas: 915573)
MarketTest:testLiquidateAndSubtractLossesFromAccumulator() (gas: 3932660)
MarketTest:testLiquidateFlexibleAndFixedBorrowPositionsInSingleCall() (gas: 2631842)
MarketTest:testLiquidateFlexibleBorrow() (gas: 2156186)
MarketTest:testLiquidateFlexibleBorrowChargeLendersAssetsToLiquidator() (gas: 1150179)
MarketTest:testLiquidateFlexibleBorrowConsideringDebtOverTime() (gas: 1166270)
MarketTest:testLiquidateLeavingDustAsCollateral() (gas: 3634350)
MarketTest:testLiquidateTransferRepayAssetsBeforeSeize() (gas: 1045448)
MarketTest:testLiquidateUpdateFloatingDebt() (gas: 1901726)
MarketTest:testLiquidateWhenFrozen() (gas: 1230788)
MarketTest:testLiquidateWithTwoUnitsAsMaxAssets() (gas: 1576942)
MarketTest:testLiquidateWithZeroAsMaxAssets() (gas: 1039143)
MarketTest:testLiquidationClearingDebtOfAllAccountMarkets() (gas: 3105086)
MarketTest:testLiquidationResultingInZeroCollateralAndZeroDebt() (gas: 1980781)
MarketTest:testMaturityInsufficientProtocolLiquidity() (gas: 1464163)
MarketTest:testMultipleBorrowsForMultipleAssets() (gas: 2463505363)
MarketTest:testMultipleDepositsToSmartPool() (gas: 915551)
MarketTest:testMultipleFixedBorrowsRepays() (gas: 1348303)
MarketTest:testMultipleLiquidationSameUser() (gas: 2958370)
MarketTest:testNotEnteredMarketShouldNotBeSeized() (gas: 8583570)
MarketTest:testOnlyAdminCanFreezeUnfreeze() (gas: 207703)
MarketTest:testMultipleLiquidationSameUser() (gas: 2958361)
MarketTest:testNotEnteredMarketShouldNotBeSeized() (gas: 8583365)
MarketTest:testOnlyAdminCanFreezeUnfreeze() (gas: 207681)
MarketTest:testOperationsShouldUpdateFloatingAssetsAverage() (gas: 1395020)
MarketTest:testOperationsWithBtcWbtcRate() (gas: 8284988)
MarketTest:testOperationsWithStEthAsset() (gas: 8160886)
MarketTest:testPausable() (gas: 158136)
MarketTest:testOperationsWithBtcWbtcRate() (gas: 8284808)
MarketTest:testOperationsWithStEthAsset() (gas: 8160706)
MarketTest:testPausable() (gas: 158114)
MarketTest:testPauserRole() (gas: 78206)
MarketTest:testPreviewOperationsWithSmartPoolCorrectlyAccountingEarnings() (gas: 1976217)
MarketTest:testRepayAtMaturity() (gas: 586699)
MarketTest:testRepayDisagreement() (gas: 594020)
MarketTest:testRepayFlexibleBorrow() (gas: 1076351)
MarketTest:testRepayWhenFrozen() (gas: 535304)
MarketTest:testRoundingDownAssetsToValidateShortfallWhenTransferring() (gas: 7543931)
MarketTest:testRoundingDownAssetsToValidateShortfallWhenTransferringFrom() (gas: 7599238)
MarketTest:testRoundingDownAssetsToValidateShortfallWhenTransferring() (gas: 7543739)
MarketTest:testRoundingDownAssetsToValidateShortfallWhenTransferringFrom() (gas: 7599046)
MarketTest:testRoundingDownAssetsWhenTransferingFromAnAccountWithoutShortfall() (gas: 1030122)
MarketTest:testRoundingDownAssetsWhenTransferingWithAnAccountWithoutShortfall() (gas: 974777)
MarketTest:testRoundingUpAllowanceWhenBorrowingAtMaturity() (gas: 845574)
Expand All @@ -266,7 +267,7 @@ MarketTest:testTotalAssetsProjectingFloatingDebtCorrectly() (gas: 713915)
MarketTest:testUpdateAccumulatedEarningsFactorToZero() (gas: 1482011)
MarketTest:testUpdateFloatingAssetsAverageWhenDepositingAndBorrowingContinuously() (gas: 344749)
MarketTest:testUpdateFloatingAssetsAverageWhenDepositingRightBeforeBorrow() (gas: 630288)
MarketTest:testUpdateFloatingAssetsAverageWhenDepositingRightBeforeEarlyWithdraw() (gas: 630543)
MarketTest:testUpdateFloatingAssetsAverageWhenDepositingRightBeforeEarlyWithdraw() (gas: 630610)
MarketTest:testUpdateFloatingAssetsAverageWhenDepositingSomeSecondsBeforeBorrow() (gas: 854932)
MarketTest:testUpdateFloatingAssetsAverageWhenWithdrawingRightBeforeBorrow() (gas: 643352)
MarketTest:testUpdateFloatingAssetsAverageWhenWithdrawingRightBeforeEarlyWithdraw() (gas: 643673)
Expand All @@ -277,7 +278,7 @@ MarketTest:testUpdateFloatingDebtBeforeSettingTreasury() (gas: 106395)
MarketTest:testWithdrawAtMaturity() (gas: 304303)
MarketTest:testWithdrawFromSmartPool() (gas: 279199)
MarketTest:testWithdrawShouldUpdateFlexibleBorrowVariables() (gas: 864003)
MarketTest:testWithdrawWhenFrozen() (gas: 325961)
MarketTest:testWithdrawWhenFrozen() (gas: 325939)
PoolLibTest:testAtomicDepositBorrowRepayWithdraw() (gas: 46018)
PoolLibTest:testBackupBorrow() (gas: 33676)
PoolLibTest:testEarningsAccrual() (gas: 38999)
Expand All @@ -290,24 +291,24 @@ PreviewerTest:testAccountsReturningUtilizationForDifferentMaturities() (gas: 418
PreviewerTest:testAccountsWithAccountOnlyDeposit() (gas: 862391)
PreviewerTest:testAccountsWithAccountThatHasBalances() (gas: 2265026)
PreviewerTest:testAccountsWithEmptyAccount() (gas: 690558)
PreviewerTest:testAccountsWithIntermediateOperationsReturningAccurateAmounts() (gas: 17646547)
PreviewerTest:testAccountsWithIntermediateOperationsReturningAccurateAmounts() (gas: 17646367)
PreviewerTest:testActualTimeBeforeStartDistributionRewards() (gas: 7788417)
PreviewerTest:testEmptyExactly() (gas: 5668798)
PreviewerTest:testExactlyReturningInterestRateModelData() (gas: 688149)
PreviewerTest:testFixedAvailableLiquidityProjectingNewFloatingDebt() (gas: 13330640)
PreviewerTest:testFixedPoolsA() (gas: 19347385)
PreviewerTest:testFixedAvailableLiquidityProjectingNewFloatingDebt() (gas: 13330460)
PreviewerTest:testFixedPoolsA() (gas: 19347205)
PreviewerTest:testFixedPoolsChangingMaturityInTime() (gas: 1627253)
PreviewerTest:testFixedPoolsRatesAndUtilizations() (gas: 14844128)
PreviewerTest:testFixedPoolsWithFloatingAssetsAverage() (gas: 15667352)
PreviewerTest:testFlexibleAvailableLiquidity() (gas: 17271481)
PreviewerTest:testFixedPoolsRatesAndUtilizations() (gas: 14843948)
PreviewerTest:testFixedPoolsWithFloatingAssetsAverage() (gas: 15667172)
PreviewerTest:testFlexibleAvailableLiquidity() (gas: 17271301)
PreviewerTest:testFlexibleBorrowSharesAndAssets() (gas: 4401038)
PreviewerTest:testFloatingAvailableLiquidityProjectingNewFloatingDebt() (gas: 12583378)
PreviewerTest:testFloatingAvailableLiquidityProjectingNewFloatingDebt() (gas: 12583198)
PreviewerTest:testFloatingRateAndUtilization() (gas: 1128246)
PreviewerTest:testJustUpdatedRewardRatesShouldStillReturnRate() (gas: 7198150)
PreviewerTest:testMaxBorrowAssetsCapacity() (gas: 2469700)
PreviewerTest:testMaxBorrowAssetsCapacityForAccountWithShortfall() (gas: 11020884)
PreviewerTest:testMaxBorrowAssetsCapacityPerMarket() (gas: 13211022)
PreviewerTest:testOraclePriceReturningAccurateValues() (gas: 10162724)
PreviewerTest:testMaxBorrowAssetsCapacityForAccountWithShortfall() (gas: 11020704)
PreviewerTest:testMaxBorrowAssetsCapacityPerMarket() (gas: 13210842)
PreviewerTest:testOraclePriceReturningAccurateValues() (gas: 10162544)
PreviewerTest:testPreviewBorrowAtAllMaturitiesReturningAccurateAmount() (gas: 4240988)
PreviewerTest:testPreviewBorrowAtMaturityReturningAccurateAmount() (gas: 623350)
PreviewerTest:testPreviewBorrowAtMaturityReturningAccurateAmountWithIntermediateOperations() (gas: 1954376)
Expand Down Expand Up @@ -353,8 +354,8 @@ PreviewerTest:testReserveFactor() (gas: 707280)
PreviewerTest:testReturnRewardAssetUsdPrice() (gas: 6732312)
PreviewerTest:testRewardsRateAfterDistributionEnd() (gas: 7504451)
PreviewerTest:testRewardsRateOnlyWithFixedBorrows() (gas: 6811626)
PreviewerTest:testRewardsRateWithDifferentRewardLengths() (gas: 19305087)
PreviewerTest:testRewardsRateWithMarketWithDifferentDecimals() (gas: 18436326)
PreviewerTest:testRewardsRateWithDifferentRewardLengths() (gas: 19304907)
PreviewerTest:testRewardsRateWithMarketWithDifferentDecimals() (gas: 18436146)
PreviewerTest:testRewardsRateX() (gas: 8150986)
PriceFeedDoubleTest:testPriceFeedDoubleReturningAccurateDecimals() (gas: 632562)
PriceFeedDoubleTest:testPriceFeedDoubleReturningPrice() (gas: 53190)
Expand All @@ -373,10 +374,10 @@ PriceFeedWrapperTest:testPriceFeedWrapperWithActualOnChainValues() (gas: 75210)
PriceFeedWrapperTest:testPriceFeedWrapperWithNegativePriceShouldRevert() (gas: 164216)
PriceFeedWrapperTest:testPriceFeedWrapperWithUsdPriceFeed() (gas: 1278197)
RewardsControllerTest:testAccrueRewardsForWholeDistributionPeriod() (gas: 1245256)
RewardsControllerTest:testAccrueRewardsWithBadDebtClearingOfFixedBorrow() (gas: 3338582)
RewardsControllerTest:testAccrueRewardsWithRepayOfBorrowBalance() (gas: 1602530)
RewardsControllerTest:testAccrueRewardsWithRepayOfFixedBorrowBalance() (gas: 1791604)
RewardsControllerTest:testAccrueRewardsWithSeizeOfAllDepositShares() (gas: 1991095)
RewardsControllerTest:testAccrueRewardsWithBadDebtClearingOfFixedBorrow() (gas: 3338579)
RewardsControllerTest:testAccrueRewardsWithRepayOfBorrowBalance() (gas: 1602527)
RewardsControllerTest:testAccrueRewardsWithRepayOfFixedBorrowBalance() (gas: 1791601)
RewardsControllerTest:testAccrueRewardsWithSeizeOfAllDepositShares() (gas: 1991092)
RewardsControllerTest:testAfterDistributionPeriodEnd() (gas: 1818279)
RewardsControllerTest:testAllClaimableUSDCWithAnotherAccountInPool() (gas: 2273354)
RewardsControllerTest:testAllClaimableUSDCWithDeposit() (gas: 1627706)
Expand Down Expand Up @@ -408,7 +409,7 @@ RewardsControllerTest:testLastUndistributed() (gas: 2189661)
RewardsControllerTest:testOperationAfterDistributionEnded() (gas: 722976)
RewardsControllerTest:testOperationsBeforeDistributionStart() (gas: 1674576)
RewardsControllerTest:testPermitClaim() (gas: 1275282)
RewardsControllerTest:testSetDistributionConfigWithDifferentDecimals() (gas: 11485553)
RewardsControllerTest:testSetDistributionConfigWithDifferentDecimals() (gas: 11485373)
RewardsControllerTest:testSetDistributionOperationShouldUpdateIndex() (gas: 136200)
RewardsControllerTest:testSetDistributionWithOnGoingMarketOperations() (gas: 1202358)
RewardsControllerTest:testSetHigherTotalDistribution() (gas: 1831201)
Expand Down
4 changes: 2 additions & 2 deletions contracts/Market.sol
Original file line number Diff line number Diff line change
Expand Up @@ -605,6 +605,8 @@ contract Market is Initializable, AccessControlUpgradeable, PausableUpgradeable,
(uint256 lendersAssets, uint256 seizeAssets) = auditor.calculateSeize(this, seizeMarket, borrower, repaidAssets);
earningsAccumulator += lendersAssets;

asset.safeTransferFrom(msg.sender, address(this), repaidAssets + lendersAssets);

if (address(seizeMarket) == address(this)) {
internalSeize(this, msg.sender, borrower, seizeAssets);
} else {
Expand All @@ -616,8 +618,6 @@ contract Market is Initializable, AccessControlUpgradeable, PausableUpgradeable,
emit Liquidate(msg.sender, borrower, repaidAssets, lendersAssets, seizeMarket, seizeAssets);

auditor.handleBadDebt(borrower);

asset.safeTransferFrom(msg.sender, address(this), repaidAssets + lendersAssets);
}

/// @notice Clears floating and fixed debt for an account spreading the losses to the `earningsAccumulator`.
Expand Down
Loading

0 comments on commit 7e654d6

Please sign in to comment.