From 5e0227bbc9849c63c6d6d7c7776f659f4a7147e1 Mon Sep 17 00:00:00 2001 From: miguelmtzinf Date: Sat, 7 Sep 2024 12:51:51 +0200 Subject: [PATCH] fix: Reset allowance after Aave interaction --- contracts/adapters/paraswap/ParaSwapRepayAdapter.sol | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/contracts/adapters/paraswap/ParaSwapRepayAdapter.sol b/contracts/adapters/paraswap/ParaSwapRepayAdapter.sol index dca990b..1e6a156 100644 --- a/contracts/adapters/paraswap/ParaSwapRepayAdapter.sol +++ b/contracts/adapters/paraswap/ParaSwapRepayAdapter.sol @@ -127,15 +127,15 @@ contract ParaSwapRepayAdapter is BaseParaSwapBuyAdapter, ReentrancyGuard { //deposit collateral back in the pool, if left after the swap(buy) if (collateralBalanceLeft > 0) { - IERC20(collateralAsset).safeApprove(address(POOL), 0); IERC20(collateralAsset).safeApprove(address(POOL), collateralBalanceLeft); POOL.deposit(address(collateralAsset), collateralBalanceLeft, msg.sender, 0); + IERC20(collateralAsset).safeApprove(address(POOL), 0); } // Repay debt. Approves 0 first to comply with tokens that implement the anti frontrunning approval fix - IERC20(debtAsset).safeApprove(address(POOL), 0); IERC20(debtAsset).safeApprove(address(POOL), debtRepayAmount); POOL.repay(address(debtAsset), debtRepayAmount, debtRateMode, msg.sender); + IERC20(debtAsset).safeApprove(address(POOL), 0); { //transfer excess of debtAsset back to the user, if any @@ -188,9 +188,9 @@ contract ParaSwapRepayAdapter is BaseParaSwapBuyAdapter, ReentrancyGuard { ); // Repay debt. Approves for 0 first to comply with tokens that implement the anti frontrunning approval fix. - IERC20(debtAsset).safeApprove(address(POOL), 0); IERC20(debtAsset).safeApprove(address(POOL), debtRepayAmount); POOL.repay(address(debtAsset), debtRepayAmount, rateMode, initiator); + IERC20(debtAsset).safeApprove(address(POOL), 0); uint256 neededForFlashLoanRepay = amountSold.add(premium);