Skip to content

Commit

Permalink
refactor: 1:1 debt collateral relation
Browse files Browse the repository at this point in the history
  • Loading branch information
sakulstra committed Feb 6, 2025
1 parent 297fd84 commit 6b1865e
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 22 deletions.
12 changes: 6 additions & 6 deletions snapshots/BatchRepayBadDebtSteward.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
22 changes: 10 additions & 12 deletions src/maintenance/BatchRepayBadDebtSteward.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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
Expand All @@ -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]});
}

Expand Down
8 changes: 4 additions & 4 deletions src/maintenance/interfaces/IBatchRepayBadDebtSteward.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 6b1865e

Please sign in to comment.