Skip to content

Commit

Permalink
feat: add condition to support same asset repay with collateral
Browse files Browse the repository at this point in the history
  • Loading branch information
defispartan committed Oct 10, 2022
1 parent a7f0b8f commit d725ec8
Showing 1 changed file with 16 additions and 20 deletions.
36 changes: 16 additions & 20 deletions contracts/adapters/ParaSwapRepayAdapter.sol
Original file line number Diff line number Diff line change
Expand Up @@ -71,16 +71,10 @@ contract ParaSwapRepayAdapter is BaseParaSwapBuyAdapter, ReentrancyGuard {
uint256 collateralAmount = amounts[0];
uint256 premium = premiums[0];
address initiatorLocal = initiator;

IERC20Detailed collateralAsset = IERC20Detailed(assets[0]);

_swapAndRepay(
params,
premium,
initiatorLocal,
collateralAsset,
collateralAmount
);

_swapAndRepay(params, premium, initiatorLocal, collateralAsset, collateralAmount);

return true;
}
Expand Down Expand Up @@ -110,7 +104,6 @@ contract ParaSwapRepayAdapter is BaseParaSwapBuyAdapter, ReentrancyGuard {
bytes calldata paraswapData,
PermitSignature calldata permitSignature
) external nonReentrant {

debtRepayAmount = getDebtRepayAmount(
debtAsset,
debtRateMode,
Expand Down Expand Up @@ -162,7 +155,6 @@ contract ParaSwapRepayAdapter is BaseParaSwapBuyAdapter, ReentrancyGuard {
IERC20Detailed collateralAsset,
uint256 collateralAmount
) private {

(
IERC20Detailed debtAsset,
uint256 debtRepayAmount,
Expand All @@ -180,15 +172,19 @@ contract ParaSwapRepayAdapter is BaseParaSwapBuyAdapter, ReentrancyGuard {
initiator
);

uint256 amountSold =
_buyOnParaSwap(
buyAllBalanceOffset,
paraswapData,
collateralAsset,
debtAsset,
collateralAmount,
debtRepayAmount
);
uint256 amountSold = debtRepayAmount;

if (collateralAsset != debtAsset) {
uint256 amountSold =

This comment has been minimized.

Copy link
@kartojal

kartojal Oct 17, 2022

Contributor

Hey @defispartan ! There is a shadow declaration of the variable amountSold, which makes tests with different debt and collateral to fail due is passing the borrow amount as the collateral amount at L197.

You just need to delete the "uint256" part at line 178 to pass the paraswap repay tests.

Did you add a new test case for this new feature?

_buyOnParaSwap(
buyAllBalanceOffset,
paraswapData,
collateralAsset,
debtAsset,
collateralAmount,
debtRepayAmount
);
}

// Repay debt. Approves for 0 first to comply with tokens that implement the anti frontrunning approval fix.
IERC20(debtAsset).safeApprove(address(LENDING_POOL), 0);
Expand Down

0 comments on commit d725ec8

Please sign in to comment.