diff --git a/snapshots/BatchRepayBadDebtSteward.json b/snapshots/BatchRepayBadDebtSteward.json index 82a9710..6c0e96a 100644 --- a/snapshots/BatchRepayBadDebtSteward.json +++ b/snapshots/BatchRepayBadDebtSteward.json @@ -13,13 +13,13 @@ "function batchLiquidateWithMaxCap: with 4 users": "1475163", "function batchLiquidateWithMaxCap: with 5 users": "1788395", "function batchLiquidateWithMaxCap: with 6 users": "2000926", - "function batchRepayBadDebt: with 0 users": "70085", - "function batchRepayBadDebt: with 1 user": "222254", - "function batchRepayBadDebt: with 2 users": "284647", - "function batchRepayBadDebt: with 3 users": "347040", + "function batchRepayBadDebt: with 0 users": "70073", + "function batchRepayBadDebt: with 1 user": "222245", + "function batchRepayBadDebt: with 2 users": "284641", + "function batchRepayBadDebt: with 3 users": "347037", "function batchRepayBadDebt: with 4 users": "409432", - "function batchRepayBadDebt: with 5 users": "471825", - "function batchRepayBadDebt: with 6 users": "534218", + "function batchRepayBadDebt: with 5 users": "471828", + "function batchRepayBadDebt: with 6 users": "534224", "function getBadDebtAmount: with 0 users": "12830", "function getBadDebtAmount: with 1 user": "38636", "function getBadDebtAmount: with 2 users": "51390", diff --git a/src/maintenance/BatchRepayBadDebtSteward.sol b/src/maintenance/BatchRepayBadDebtSteward.sol index 3cd874f..54c4216 100644 --- a/src/maintenance/BatchRepayBadDebtSteward.sol +++ b/src/maintenance/BatchRepayBadDebtSteward.sol @@ -66,29 +66,25 @@ contract BatchRepayBadDebtSteward is /* EXTERNAL FUNCTIONS */ /// @inheritdoc IBatchRepayBadDebtSteward - function batchLiquidate(address debtAsset, address[] memory collateralAssets, address[] memory users) - external - override - { - (uint256 totalDebtAmount,) = getDebtAmount(debtAsset, users); + function batchLiquidate(address debtAsset, address collateralAsset, address[] memory users) external override { + (uint256 maxDebtAmount,) = getDebtAmount(debtAsset, users); - batchLiquidateWithMaxCap(debtAsset, collateralAssets, users, totalDebtAmount); + batchLiquidateWithMaxCap(debtAsset, collateralAsset, users, maxDebtAmount); } /// @inheritdoc IBatchRepayBadDebtSteward function batchLiquidateWithMaxCap( address debtAsset, - address[] memory collateralAssets, + address collateralAsset, address[] memory users, uint256 maxDebtTokenAmount ) public override onlyRole(CLEANUP) { ICollector(COLLECTOR).transfer(IERC20Col(debtAsset), address(this), maxDebtTokenAmount); IERC20(debtAsset).forceApprove(address(POOL), maxDebtTokenAmount); - uint256 length = users.length; - for (uint256 i = 0; i < length; i++) { + for (uint256 i = 0; i < users.length; i++) { POOL.liquidationCall({ - collateralAsset: collateralAssets[i], + collateralAsset: collateralAsset, debtAsset: debtAsset, user: users[i], debtToCover: type(uint256).max, @@ -101,6 +97,9 @@ contract BatchRepayBadDebtSteward is if (balanceAfter != 0) { IERC20(debtAsset).safeTransfer(COLLECTOR, balanceAfter); } + + // transfer back liquidated assets + IERC20(POOL.getReserveAToken(collateralAsset)).safeTransfer(COLLECTOR, type(uint256).max); } /// @inheritdoc IBatchRepayBadDebtSteward @@ -110,8 +109,7 @@ contract BatchRepayBadDebtSteward is ICollector(COLLECTOR).transfer(IERC20Col(asset), address(this), totalDebtAmount); IERC20(asset).forceApprove(address(POOL), totalDebtAmount); - uint256 length = users.length; - for (uint256 i = 0; i < length; i++) { + for (uint256 i = 0; i < users.length; i++) { POOL.repay({asset: asset, amount: debtAmounts[i], interestRateMode: 2, onBehalfOf: users[i]}); } diff --git a/src/maintenance/interfaces/IBatchRepayBadDebtSteward.sol b/src/maintenance/interfaces/IBatchRepayBadDebtSteward.sol index d3c71ba..8b28f9a 100644 --- a/src/maintenance/interfaces/IBatchRepayBadDebtSteward.sol +++ b/src/maintenance/interfaces/IBatchRepayBadDebtSteward.sol @@ -36,19 +36,19 @@ interface IBatchRepayBadDebtSteward is IRescuableBase, IWithGuardian, IAccessCon /// @notice Liquidates all the users /// @param debtAsset The address of the debt asset - /// @param collateralAssets The addresses of the collateral assets that will be liquidated + /// @param collateralAsset The address of the collateral asset that will be liquidated /// @param users The addresses of the users to liquidate - function batchLiquidate(address debtAsset, address[] memory collateralAssets, address[] memory users) external; + function batchLiquidate(address debtAsset, address collateralAsset, address[] memory users) external; /// @notice Liquidates all the users with a max debt amount to be liquidated /// @param debtAsset The address of the debt asset - /// @param collateralAssets The addresses of the collateral assets that will be liquidated + /// @param collateralAsset The address of the collateral asset that will be liquidated /// @param users The addresses of the users to liquidate /// @param maxDebtTokenAmount The maximum amount of debt tokens to be liquidated /// @dev this is the amount being pulled from the collector. The contract will send the surplus back to the collector. function batchLiquidateWithMaxCap( address debtAsset, - address[] memory collateralAssets, + address collateralAsset, address[] memory users, uint256 maxDebtTokenAmount ) external;