diff --git a/contracts/adapters/paraswap/BaseParaSwapBuyAdapter.sol b/contracts/adapters/paraswap/BaseParaSwapBuyAdapter.sol index 4c47e836..1a8c2742 100644 --- a/contracts/adapters/paraswap/BaseParaSwapBuyAdapter.sol +++ b/contracts/adapters/paraswap/BaseParaSwapBuyAdapter.sol @@ -1,6 +1,7 @@ // SPDX-License-Identifier: AGPL-3.0 pragma solidity ^0.8.10; +import {SafeERC20} from '@aave/core-v3/contracts/dependencies/openzeppelin/contracts/SafeERC20.sol'; import {SafeMath} from '@aave/core-v3/contracts/dependencies/openzeppelin/contracts/SafeMath.sol'; import {PercentageMath} from '@aave/core-v3/contracts/protocol/libraries/math/PercentageMath.sol'; import {IPoolAddressesProvider} from '@aave/core-v3/contracts/interfaces/IPoolAddressesProvider.sol'; @@ -16,6 +17,7 @@ import {BaseParaSwapAdapter} from './BaseParaSwapAdapter.sol'; abstract contract BaseParaSwapBuyAdapter is BaseParaSwapAdapter { using PercentageMath for uint256; using SafeMath for uint256; + using SafeERC20 for IERC20Detailed; IParaSwapAugustusRegistry public immutable AUGUSTUS_REGISTRY; @@ -72,8 +74,8 @@ abstract contract BaseParaSwapBuyAdapter is BaseParaSwapAdapter { uint256 balanceBeforeAssetTo = assetToSwapTo.balanceOf(address(this)); address tokenTransferProxy = augustus.getTokenTransferProxy(); - assetToSwapFrom.approve(tokenTransferProxy, 0); - assetToSwapFrom.approve(tokenTransferProxy, maxAmountToSwap); + assetToSwapFrom.safeApprove(tokenTransferProxy, 0); + assetToSwapFrom.safeApprove(tokenTransferProxy, maxAmountToSwap); if (toAmountOffset != 0) { // Ensure 256 bit (32 bytes) toAmountOffset value is within bounds of the diff --git a/contracts/adapters/paraswap/BaseParaSwapSellAdapter.sol b/contracts/adapters/paraswap/BaseParaSwapSellAdapter.sol index 770d7fc2..697afb25 100644 --- a/contracts/adapters/paraswap/BaseParaSwapSellAdapter.sol +++ b/contracts/adapters/paraswap/BaseParaSwapSellAdapter.sol @@ -1,6 +1,7 @@ // SPDX-License-Identifier: AGPL-3.0 pragma solidity ^0.8.10; +import {SafeERC20} from '@aave/core-v3/contracts/dependencies/openzeppelin/contracts/SafeERC20.sol'; import {SafeMath} from '@aave/core-v3/contracts/dependencies/openzeppelin/contracts/SafeMath.sol'; import {PercentageMath} from '@aave/core-v3/contracts/protocol/libraries/math/PercentageMath.sol'; import {IPoolAddressesProvider} from '@aave/core-v3/contracts/interfaces/IPoolAddressesProvider.sol'; @@ -17,6 +18,7 @@ import {BaseParaSwapAdapter} from './BaseParaSwapAdapter.sol'; abstract contract BaseParaSwapSellAdapter is BaseParaSwapAdapter { using PercentageMath for uint256; using SafeMath for uint256; + using SafeERC20 for IERC20Detailed; IParaSwapAugustusRegistry public immutable AUGUSTUS_REGISTRY; @@ -70,8 +72,8 @@ abstract contract BaseParaSwapSellAdapter is BaseParaSwapAdapter { uint256 balanceBeforeAssetTo = assetToSwapTo.balanceOf(address(this)); address tokenTransferProxy = augustus.getTokenTransferProxy(); - assetToSwapFrom.approve(tokenTransferProxy, 0); - assetToSwapFrom.approve(tokenTransferProxy, amountToSwap); + assetToSwapFrom.safeApprove(tokenTransferProxy, 0); + assetToSwapFrom.safeApprove(tokenTransferProxy, amountToSwap); if (fromAmountOffset != 0) { // Ensure 256 bit (32 bytes) fromAmount value is within bounds of the diff --git a/contracts/adapters/paraswap/ParaSwapLiquiditySwapAdapter.sol b/contracts/adapters/paraswap/ParaSwapLiquiditySwapAdapter.sol index cd1bed57..0a5d0514 100644 --- a/contracts/adapters/paraswap/ParaSwapLiquiditySwapAdapter.sol +++ b/contracts/adapters/paraswap/ParaSwapLiquiditySwapAdapter.sol @@ -4,6 +4,7 @@ pragma solidity ^0.8.10; import {IERC20Detailed} from '@aave/core-v3/contracts/dependencies/openzeppelin/contracts/IERC20Detailed.sol'; import {IERC20WithPermit} from '@aave/core-v3/contracts/interfaces/IERC20WithPermit.sol'; import {IPoolAddressesProvider} from '@aave/core-v3/contracts/interfaces/IPoolAddressesProvider.sol'; +import {SafeERC20} from '@aave/core-v3/contracts/dependencies/openzeppelin/contracts/SafeERC20.sol'; import {SafeMath} from '@aave/core-v3/contracts/dependencies/openzeppelin/contracts/SafeMath.sol'; import {BaseParaSwapSellAdapter} from './BaseParaSwapSellAdapter.sol'; import {IParaSwapAugustusRegistry} from './interfaces/IParaSwapAugustusRegistry.sol'; @@ -17,6 +18,7 @@ import {ReentrancyGuard} from '../../dependencies/openzeppelin/ReentrancyGuard.s */ contract ParaSwapLiquiditySwapAdapter is BaseParaSwapSellAdapter, ReentrancyGuard { using SafeMath for uint256; + using SafeERC20 for IERC20Detailed; constructor( IPoolAddressesProvider addressesProvider, @@ -135,8 +137,8 @@ contract ParaSwapLiquiditySwapAdapter is BaseParaSwapSellAdapter, ReentrancyGuar minAmountToReceive ); - assetToSwapTo.approve(address(POOL), 0); - assetToSwapTo.approve(address(POOL), amountReceived); + assetToSwapTo.safeApprove(address(POOL), 0); + assetToSwapTo.safeApprove(address(POOL), amountReceived); POOL.deposit(address(assetToSwapTo), amountReceived, msg.sender, 0); } @@ -189,8 +191,8 @@ contract ParaSwapLiquiditySwapAdapter is BaseParaSwapSellAdapter, ReentrancyGuar minAmountToReceive ); - assetToSwapTo.approve(address(POOL), 0); - assetToSwapTo.approve(address(POOL), amountReceived); + assetToSwapTo.safeApprove(address(POOL), 0); + assetToSwapTo.safeApprove(address(POOL), amountReceived); POOL.deposit(address(assetToSwapTo), amountReceived, initiator, 0); _pullATokenAndWithdraw( @@ -202,7 +204,7 @@ contract ParaSwapLiquiditySwapAdapter is BaseParaSwapSellAdapter, ReentrancyGuar ); // Repay flash loan - assetToSwapFrom.approve(address(POOL), 0); - assetToSwapFrom.approve(address(POOL), flashLoanAmount.add(premium)); + assetToSwapFrom.safeApprove(address(POOL), 0); + assetToSwapFrom.safeApprove(address(POOL), flashLoanAmount.add(premium)); } } diff --git a/contracts/adapters/paraswap/ParaSwapRepayAdapter.sol b/contracts/adapters/paraswap/ParaSwapRepayAdapter.sol index 33cdf1bd..16039fcb 100644 --- a/contracts/adapters/paraswap/ParaSwapRepayAdapter.sol +++ b/contracts/adapters/paraswap/ParaSwapRepayAdapter.sol @@ -6,6 +6,7 @@ import {IERC20Detailed} from '@aave/core-v3/contracts/dependencies/openzeppelin/ import {IERC20} from '@aave/core-v3/contracts/dependencies/openzeppelin/contracts/IERC20.sol'; import {IERC20WithPermit} from '@aave/core-v3/contracts/interfaces/IERC20WithPermit.sol'; import {IPoolAddressesProvider} from '@aave/core-v3/contracts/interfaces/IPoolAddressesProvider.sol'; +import {SafeERC20} from '@aave/core-v3/contracts/dependencies/openzeppelin/contracts/SafeERC20.sol'; import {SafeMath} from '@aave/core-v3/contracts/dependencies/openzeppelin/contracts/SafeMath.sol'; import {BaseParaSwapBuyAdapter} from './BaseParaSwapBuyAdapter.sol'; import {IParaSwapAugustusRegistry} from './interfaces/IParaSwapAugustusRegistry.sol'; @@ -19,6 +20,7 @@ import {ReentrancyGuard} from '../../dependencies/openzeppelin/ReentrancyGuard.s **/ contract ParaSwapRepayAdapter is BaseParaSwapBuyAdapter, ReentrancyGuard { using SafeMath for uint256; + using SafeERC20 for IERC20; struct RepayParams { address collateralAsset; @@ -125,14 +127,14 @@ contract ParaSwapRepayAdapter is BaseParaSwapBuyAdapter, ReentrancyGuard { //deposit collateral back in the pool, if left after the swap(buy) if (collateralBalanceLeft > 0) { - IERC20(collateralAsset).approve(address(POOL), 0); - IERC20(collateralAsset).approve(address(POOL), collateralBalanceLeft); + IERC20(collateralAsset).safeApprove(address(POOL), 0); + IERC20(collateralAsset).safeApprove(address(POOL), collateralBalanceLeft); POOL.deposit(address(collateralAsset), collateralBalanceLeft, msg.sender, 0); } // Repay debt. Approves 0 first to comply with tokens that implement the anti frontrunning approval fix - IERC20(debtAsset).approve(address(POOL), 0); - IERC20(debtAsset).approve(address(POOL), debtRepayAmount); + IERC20(debtAsset).safeApprove(address(POOL), 0); + IERC20(debtAsset).safeApprove(address(POOL), debtRepayAmount); POOL.repay(address(debtAsset), debtRepayAmount, debtRateMode, msg.sender); } @@ -178,8 +180,8 @@ contract ParaSwapRepayAdapter is BaseParaSwapBuyAdapter, ReentrancyGuard { ); // Repay debt. Approves for 0 first to comply with tokens that implement the anti frontrunning approval fix. - IERC20(debtAsset).approve(address(POOL), 0); - IERC20(debtAsset).approve(address(POOL), debtRepayAmount); + IERC20(debtAsset).safeApprove(address(POOL), 0); + IERC20(debtAsset).safeApprove(address(POOL), debtRepayAmount); POOL.repay(address(debtAsset), debtRepayAmount, rateMode, initiator); uint256 neededForFlashLoanRepay = amountSold.add(premium); @@ -193,8 +195,8 @@ contract ParaSwapRepayAdapter is BaseParaSwapBuyAdapter, ReentrancyGuard { ); // Repay flashloan. Approves for 0 first to comply with tokens that implement the anti frontrunning approval fix. - IERC20(collateralAsset).approve(address(POOL), 0); - IERC20(collateralAsset).approve(address(POOL), collateralAmount.add(premium)); + IERC20(collateralAsset).safeApprove(address(POOL), 0); + IERC20(collateralAsset).safeApprove(address(POOL), collateralAmount.add(premium)); } function getDebtRepayAmount( diff --git a/package-lock.json b/package-lock.json index 0d210a62..99f31428 100644 --- a/package-lock.json +++ b/package-lock.json @@ -9,7 +9,7 @@ "version": "2.4.0", "license": "AGPLv3", "dependencies": { - "@aave/core-v3": "1.17.0" + "@aave/core-v3": "1.19.0" }, "devDependencies": { "@aave/deploy-v3": "1.50.1", @@ -58,9 +58,9 @@ } }, "node_modules/@aave/core-v3": { - "version": "1.17.0", - "resolved": "https://registry.npmjs.org/@aave/core-v3/-/core-v3-1.17.0.tgz", - "integrity": "sha512-vcGEPcoDILN1ZBXeqRsK+TXp1VGDvYxaiq/ZJ2XT2/134PbmXAlNlZIrGw1b4WIwIG4egNu8OW6whyWjp/aLlA==", + "version": "1.19.0", + "resolved": "https://registry.npmjs.org/@aave/core-v3/-/core-v3-1.19.0.tgz", + "integrity": "sha512-9Uw3FY8TFB2SWnKXtKT7b+HDt+ZV6qfXvuU/9gcNx0NiEH0Qz2IvHleHhLVhXllmkJPMAb/F324+riyvEcDWFw==", "engines": { "node": ">=16.0.0" } @@ -25368,9 +25368,9 @@ }, "dependencies": { "@aave/core-v3": { - "version": "1.17.0", - "resolved": "https://registry.npmjs.org/@aave/core-v3/-/core-v3-1.17.0.tgz", - "integrity": "sha512-vcGEPcoDILN1ZBXeqRsK+TXp1VGDvYxaiq/ZJ2XT2/134PbmXAlNlZIrGw1b4WIwIG4egNu8OW6whyWjp/aLlA==" + "version": "1.19.0", + "resolved": "https://registry.npmjs.org/@aave/core-v3/-/core-v3-1.19.0.tgz", + "integrity": "sha512-9Uw3FY8TFB2SWnKXtKT7b+HDt+ZV6qfXvuU/9gcNx0NiEH0Qz2IvHleHhLVhXllmkJPMAb/F324+riyvEcDWFw==" }, "@aave/deploy-v3": { "version": "1.50.1", diff --git a/package.json b/package.json index 32d3ff12..b6621637 100644 --- a/package.json +++ b/package.json @@ -85,6 +85,6 @@ "url": "git://github.com/aave/aave-v3-periphery" }, "dependencies": { - "@aave/core-v3": "1.17.0" + "@aave/core-v3": "1.19.0" } }