@@ -6,6 +6,7 @@ import {IERC20Detailed} from '@aave/core-v3/contracts/dependencies/openzeppelin/
66import {IERC20 } from '@aave/core-v3/contracts/dependencies/openzeppelin/contracts/IERC20.sol ' ;
77import {IERC20WithPermit } from '@aave/core-v3/contracts/interfaces/IERC20WithPermit.sol ' ;
88import {IPoolAddressesProvider} from '@aave/core-v3/contracts/interfaces/IPoolAddressesProvider.sol ' ;
9+ import {SafeERC20} from '@aave/core-v3/contracts/dependencies/openzeppelin/contracts/SafeERC20.sol ' ;
910import {SafeMath} from '@aave/core-v3/contracts/dependencies/openzeppelin/contracts/SafeMath.sol ' ;
1011import {BaseParaSwapBuyAdapter} from './BaseParaSwapBuyAdapter.sol ' ;
1112import {IParaSwapAugustusRegistry} from './interfaces/IParaSwapAugustusRegistry.sol ' ;
@@ -19,6 +20,7 @@ import {ReentrancyGuard} from '../../dependencies/openzeppelin/ReentrancyGuard.s
1920 **/
2021contract ParaSwapRepayAdapter is BaseParaSwapBuyAdapter , ReentrancyGuard {
2122 using SafeMath for uint256 ;
23+ using SafeERC20 for IERC20 ;
2224
2325 struct RepayParams {
2426 address collateralAsset;
@@ -125,14 +127,14 @@ contract ParaSwapRepayAdapter is BaseParaSwapBuyAdapter, ReentrancyGuard {
125127
126128 //deposit collateral back in the pool, if left after the swap(buy)
127129 if (collateralBalanceLeft > 0 ) {
128- IERC20 (collateralAsset).approve (address (POOL), 0 );
129- IERC20 (collateralAsset).approve (address (POOL), collateralBalanceLeft);
130+ IERC20 (collateralAsset).safeApprove (address (POOL), 0 );
131+ IERC20 (collateralAsset).safeApprove (address (POOL), collateralBalanceLeft);
130132 POOL.deposit (address (collateralAsset), collateralBalanceLeft, msg .sender , 0 );
131133 }
132134
133135 // Repay debt. Approves 0 first to comply with tokens that implement the anti frontrunning approval fix
134- IERC20 (debtAsset).approve (address (POOL), 0 );
135- IERC20 (debtAsset).approve (address (POOL), debtRepayAmount);
136+ IERC20 (debtAsset).safeApprove (address (POOL), 0 );
137+ IERC20 (debtAsset).safeApprove (address (POOL), debtRepayAmount);
136138 POOL.repay (address (debtAsset), debtRepayAmount, debtRateMode, msg .sender );
137139 }
138140
@@ -178,8 +180,8 @@ contract ParaSwapRepayAdapter is BaseParaSwapBuyAdapter, ReentrancyGuard {
178180 );
179181
180182 // Repay debt. Approves for 0 first to comply with tokens that implement the anti frontrunning approval fix.
181- IERC20 (debtAsset).approve (address (POOL), 0 );
182- IERC20 (debtAsset).approve (address (POOL), debtRepayAmount);
183+ IERC20 (debtAsset).safeApprove (address (POOL), 0 );
184+ IERC20 (debtAsset).safeApprove (address (POOL), debtRepayAmount);
183185 POOL.repay (address (debtAsset), debtRepayAmount, rateMode, initiator);
184186
185187 uint256 neededForFlashLoanRepay = amountSold.add (premium);
@@ -193,8 +195,8 @@ contract ParaSwapRepayAdapter is BaseParaSwapBuyAdapter, ReentrancyGuard {
193195 );
194196
195197 // Repay flashloan. Approves for 0 first to comply with tokens that implement the anti frontrunning approval fix.
196- IERC20 (collateralAsset).approve (address (POOL), 0 );
197- IERC20 (collateralAsset).approve (address (POOL), collateralAmount.add (premium));
198+ IERC20 (collateralAsset).safeApprove (address (POOL), 0 );
199+ IERC20 (collateralAsset).safeApprove (address (POOL), collateralAmount.add (premium));
198200 }
199201
200202 function getDebtRepayAmount (
0 commit comments