Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migrate to Paraswap V6 #67

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 1 addition & 4 deletions certora/stata/harness/pool/SymbolicLendingPool.sol
Original file line number Diff line number Diff line change
Expand Up @@ -93,10 +93,7 @@ contract SymbolicLendingPool {
return reserve.configuration;
}

function getVirtualUnderlyingBalance(
address asset
) external view virtual returns (uint128) {
function getVirtualUnderlyingBalance(address asset) external view virtual returns (uint128) {
return reserve.virtualUnderlyingBalance;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import {SafeMath} from '../../dependencies/openzeppelin/contracts/SafeMath.sol';
import {PercentageMath} from '../../protocol/libraries/math/PercentageMath.sol';
import {IPoolAddressesProvider} from '../../interfaces/IPoolAddressesProvider.sol';
import {IERC20Detailed} from '../../dependencies/openzeppelin/contracts/IERC20Detailed.sol';
import {IParaSwapAugustus} from './interfaces/IParaSwapAugustus.sol';
import {IParaSwapAugustusRegistry} from './interfaces/IParaSwapAugustusRegistry.sol';
import {BaseParaSwapAdapter} from './BaseParaSwapAdapter.sol';

Expand Down Expand Up @@ -49,12 +48,9 @@ abstract contract BaseParaSwapBuyAdapter is BaseParaSwapAdapter {
uint256 maxAmountToSwap,
uint256 amountToReceive
) internal returns (uint256 amountSold, uint256 amountBought) {
(bytes memory buyCalldata, IParaSwapAugustus augustus) = abi.decode(
paraswapData,
(bytes, IParaSwapAugustus)
);
(bytes memory buyCalldata, address augustus) = abi.decode(paraswapData, (bytes, address));

require(AUGUSTUS_REGISTRY.isValidAugustus(address(augustus)), 'INVALID_AUGUSTUS');
require(AUGUSTUS_REGISTRY.isValidAugustus(augustus), 'INVALID_AUGUSTUS');

{
uint256 fromAssetDecimals = _getDecimals(assetToSwapFrom);
Expand All @@ -75,8 +71,7 @@ abstract contract BaseParaSwapBuyAdapter is BaseParaSwapAdapter {
require(balanceBeforeAssetFrom >= maxAmountToSwap, 'INSUFFICIENT_BALANCE_BEFORE_SWAP');
uint256 balanceBeforeAssetTo = assetToSwapTo.balanceOf(address(this));

address tokenTransferProxy = augustus.getTokenTransferProxy();
assetToSwapFrom.safeApprove(tokenTransferProxy, maxAmountToSwap);
assetToSwapFrom.safeApprove(augustus, maxAmountToSwap);

if (toAmountOffset != 0) {
// Ensure 256 bit (32 bytes) toAmountOffset value is within bounds of the
Expand All @@ -92,7 +87,7 @@ abstract contract BaseParaSwapBuyAdapter is BaseParaSwapAdapter {
mstore(add(buyCalldata, add(toAmountOffset, 32)), amountToReceive)
}
}
(bool success, ) = address(augustus).call(buyCalldata);
(bool success, ) = augustus.call(buyCalldata);
if (!success) {
// Copy revert reason from call
assembly {
Expand All @@ -102,7 +97,7 @@ abstract contract BaseParaSwapBuyAdapter is BaseParaSwapAdapter {
}

// Reset allowance
assetToSwapFrom.safeApprove(tokenTransferProxy, 0);
assetToSwapFrom.safeApprove(augustus, 0);

uint256 balanceAfterAssetFrom = assetToSwapFrom.balanceOf(address(this));
amountSold = balanceBeforeAssetFrom - balanceAfterAssetFrom;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import {SafeMath} from '../../dependencies/openzeppelin/contracts/SafeMath.sol';
import {PercentageMath} from '../../protocol/libraries/math/PercentageMath.sol';
import {IPoolAddressesProvider} from '../../interfaces/IPoolAddressesProvider.sol';
import {IERC20Detailed} from '../../dependencies/openzeppelin/contracts/IERC20Detailed.sol';
import {IParaSwapAugustus} from './interfaces/IParaSwapAugustus.sol';
import {IParaSwapAugustusRegistry} from './interfaces/IParaSwapAugustusRegistry.sol';
import {BaseParaSwapAdapter} from './BaseParaSwapAdapter.sol';

Expand Down Expand Up @@ -45,13 +44,13 @@ abstract contract BaseParaSwapSellAdapter is BaseParaSwapAdapter {
function _sellOnParaSwap(
uint256 fromAmountOffset,
bytes memory swapCalldata,
IParaSwapAugustus augustus,
address augustus,
IERC20Detailed assetToSwapFrom,
IERC20Detailed assetToSwapTo,
uint256 amountToSwap,
uint256 minAmountToReceive
) internal returns (uint256 amountReceived) {
require(AUGUSTUS_REGISTRY.isValidAugustus(address(augustus)), 'INVALID_AUGUSTUS');
require(AUGUSTUS_REGISTRY.isValidAugustus(augustus), 'INVALID_AUGUSTUS');

{
uint256 fromAssetDecimals = _getDecimals(assetToSwapFrom);
Expand All @@ -72,9 +71,7 @@ abstract contract BaseParaSwapSellAdapter is BaseParaSwapAdapter {
require(balanceBeforeAssetFrom >= amountToSwap, 'INSUFFICIENT_BALANCE_BEFORE_SWAP');
uint256 balanceBeforeAssetTo = assetToSwapTo.balanceOf(address(this));

address tokenTransferProxy = augustus.getTokenTransferProxy();
assetToSwapFrom.safeApprove(tokenTransferProxy, 0);
assetToSwapFrom.safeApprove(tokenTransferProxy, amountToSwap);
assetToSwapFrom.safeApprove(augustus, amountToSwap);

if (fromAmountOffset != 0) {
// Ensure 256 bit (32 bytes) fromAmount value is within bounds of the
Expand All @@ -90,7 +87,7 @@ abstract contract BaseParaSwapSellAdapter is BaseParaSwapAdapter {
mstore(add(swapCalldata, add(fromAmountOffset, 32)), amountToSwap)
}
}
(bool success, ) = address(augustus).call(swapCalldata);
(bool success, ) = augustus.call(swapCalldata);
if (!success) {
// Copy revert reason from call
assembly {
Expand All @@ -99,6 +96,9 @@ abstract contract BaseParaSwapSellAdapter is BaseParaSwapAdapter {
}
}

// Reset allowance
assetToSwapFrom.safeApprove(augustus, 0);

require(
assetToSwapFrom.balanceOf(address(this)) == balanceBeforeAssetFrom - amountToSwap,
'WRONG_BALANCE_AFTER_SWAP'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import {SafeERC20} from '../../dependencies/openzeppelin/contracts/SafeERC20.sol
import {SafeMath} from '../../dependencies/openzeppelin/contracts/SafeMath.sol';
import {BaseParaSwapSellAdapter} from './BaseParaSwapSellAdapter.sol';
import {IParaSwapAugustusRegistry} from './interfaces/IParaSwapAugustusRegistry.sol';
import {IParaSwapAugustus} from './interfaces/IParaSwapAugustus.sol';
import {ReentrancyGuard} from '../../dependencies/openzeppelin/ReentrancyGuard.sol';

/**
Expand Down Expand Up @@ -63,12 +62,9 @@ contract ParaSwapLiquiditySwapAdapter is BaseParaSwapSellAdapter, ReentrancyGuar
uint256 minAmountToReceive,
uint256 swapAllBalanceOffset,
bytes memory swapCalldata,
IParaSwapAugustus augustus,
address augustus,
PermitSignature memory permitParams
) = abi.decode(
params,
(IERC20Detailed, uint256, uint256, bytes, IParaSwapAugustus, PermitSignature)
);
) = abi.decode(params, (IERC20Detailed, uint256, uint256, bytes, address, PermitSignature));

_swapLiquidity(
swapAllBalanceOffset,
Expand Down Expand Up @@ -106,7 +102,7 @@ contract ParaSwapLiquiditySwapAdapter is BaseParaSwapSellAdapter, ReentrancyGuar
uint256 minAmountToReceive,
uint256 swapAllBalanceOffset,
bytes calldata swapCalldata,
IParaSwapAugustus augustus,
address augustus,
PermitSignature calldata permitParams
) external nonReentrant {
IERC20WithPermit aToken = IERC20WithPermit(
Expand Down Expand Up @@ -158,7 +154,7 @@ contract ParaSwapLiquiditySwapAdapter is BaseParaSwapSellAdapter, ReentrancyGuar
function _swapLiquidity(
uint256 swapAllBalanceOffset,
bytes memory swapCalldata,
IParaSwapAugustus augustus,
address augustus,
PermitSignature memory permitParams,
uint256 flashLoanAmount,
uint256 premium,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import {SafeERC20} from '../../dependencies/openzeppelin/contracts/SafeERC20.sol
import {SafeMath} from '../../dependencies/openzeppelin/contracts/SafeMath.sol';
import {BaseParaSwapBuyAdapter} from './BaseParaSwapBuyAdapter.sol';
import {IParaSwapAugustusRegistry} from './interfaces/IParaSwapAugustusRegistry.sol';
import {IParaSwapAugustus} from './interfaces/IParaSwapAugustus.sol';
import {ReentrancyGuard} from '../../dependencies/openzeppelin/ReentrancyGuard.sol';

/**
Expand Down Expand Up @@ -57,7 +56,7 @@ contract ParaSwapRepayAdapter is BaseParaSwapBuyAdapter, ReentrancyGuard {
* uint256 debtRateMode Rate mode of the debt to be repaid
* bytes paraswapData Paraswap Data
* * bytes buyCallData Call data for augustus
* * IParaSwapAugustus augustus Address of Augustus Swapper
* * address augustus Address of Augustus Swapper
* PermitSignature permitParams Struct containing the permit signatures, set to all zeroes if not used
*/
function executeOperation(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import {IPoolAddressesProvider} from '../../interfaces/IPoolAddressesProvider.so
import {BaseParaSwapSellAdapter} from './BaseParaSwapSellAdapter.sol';
import {IParaSwapAugustusRegistry} from './interfaces/IParaSwapAugustusRegistry.sol';
import {SafeERC20} from '../../dependencies/openzeppelin/contracts/SafeERC20.sol';
import {IParaSwapAugustus} from './interfaces/IParaSwapAugustus.sol';
import {ReentrancyGuard} from '../../dependencies/openzeppelin/ReentrancyGuard.sol';

contract ParaSwapWithdrawSwapAdapter is BaseParaSwapSellAdapter, ReentrancyGuard {
Expand Down Expand Up @@ -50,7 +49,7 @@ contract ParaSwapWithdrawSwapAdapter is BaseParaSwapSellAdapter, ReentrancyGuard
uint256 minAmountToReceive,
uint256 swapAllBalanceOffset,
bytes calldata swapCalldata,
IParaSwapAugustus augustus,
address augustus,
PermitSignature calldata permitParams
) external nonReentrant {
IERC20WithPermit aToken = IERC20WithPermit(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ interface IFeeClaimer {
* the call will fail if withdrawer have zero balance in the contract
* @param _token address of the ERC20 token
* @param _recipient address
* @return true if the withdraw was successfull
* @return true if the withdraw was successful
*/
function withdrawAllERC20(IERC20 _token, address _recipient) external returns (bool);

Expand All @@ -29,7 +29,7 @@ interface IFeeClaimer {
* the call will fail if withdrawer have zero balance in the contract
* @param _tokens list of addresses of the ERC20 token
* @param _recipient address of recipient
* @return true if the withdraw was successfull
* @return true if the withdraw was successful
*/
function batchWithdrawAllERC20(
address[] calldata _tokens,
Expand All @@ -42,7 +42,7 @@ interface IFeeClaimer {
* the call will fail if withdrawer have zero balance in the contract
* @param _token address of the ERC20 token
* @param _recipient address
* @return true if the withdraw was successfull
* @return true if the withdraw was successful
*/
function withdrawSomeERC20(
IERC20 _token,
Expand All @@ -57,7 +57,7 @@ interface IFeeClaimer {
* @param _tokens address of the ERC20 tokens
* @param _tokenAmounts array of amounts
* @param _recipient destination account addresses
* @return true if the withdraw was successfull
* @return true if the withdraw was successful
*/
function batchWithdrawSomeERC20(
IERC20[] calldata _tokens,
Expand Down

This file was deleted.

21 changes: 7 additions & 14 deletions src/contracts/mocks/swap/MockParaSwapAugustus.sol
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.10;

import {IParaSwapAugustus} from '../../extensions/paraswap-adapters/interfaces/IParaSwapAugustus.sol';
import {MockParaSwapTokenTransferProxy} from './MockParaSwapTokenTransferProxy.sol';
import {IERC20} from '../../dependencies/openzeppelin/contracts/IERC20.sol';
import {MintableERC20} from '../tokens/MintableERC20.sol';

contract MockParaSwapAugustus is IParaSwapAugustus {
MockParaSwapTokenTransferProxy immutable TOKEN_TRANSFER_PROXY;
contract MockParaSwapAugustus {
bool _expectingSwap;
address _expectedFromToken;
address _expectedToToken;
Expand All @@ -20,14 +17,6 @@ contract MockParaSwapAugustus is IParaSwapAugustus {
uint256 _expectedToAmountMax;
uint256 _expectedToAmountMin;

constructor() {
TOKEN_TRANSFER_PROXY = new MockParaSwapTokenTransferProxy();
}

function getTokenTransferProxy() external view override returns (address) {
return address(TOKEN_TRANSFER_PROXY);
}

function expectSwap(
address fromToken,
address toToken,
Expand Down Expand Up @@ -72,7 +61,7 @@ contract MockParaSwapAugustus is IParaSwapAugustus {
'From amount out of range'
);
require(_receivedAmount >= toAmount, 'Received amount of tokens are less than expected');
TOKEN_TRANSFER_PROXY.transferFrom(fromToken, msg.sender, address(this), fromAmount);
_transferFrom(fromToken, msg.sender, address(this), fromAmount);
MintableERC20(toToken).mint(_receivedAmount);
IERC20(toToken).transfer(msg.sender, _receivedAmount);
_expectingSwap = false;
Expand All @@ -93,9 +82,13 @@ contract MockParaSwapAugustus is IParaSwapAugustus {
'To amount out of range'
);
require(_fromAmount <= fromAmount, 'From amount of tokens are higher than expected');
TOKEN_TRANSFER_PROXY.transferFrom(fromToken, msg.sender, address(this), _fromAmount);
_transferFrom(fromToken, msg.sender, address(this), _fromAmount);
MintableERC20(toToken).mint(msg.sender, toAmount);
_expectingSwap = false;
return fromAmount;
}

function _transferFrom(address token, address from, address to, uint256 amount) internal {
IERC20(token).transferFrom(from, to, amount);
}
}
7 changes: 0 additions & 7 deletions src/contracts/mocks/swap/MockParaSwapFeeClaimer.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,12 @@
pragma solidity ^0.8.10;

import {IFeeClaimer} from '../../extensions/paraswap-adapters/interfaces/IFeeClaimer.sol';
import {MockParaSwapTokenTransferProxy} from './MockParaSwapTokenTransferProxy.sol';
import {IERC20} from '../../dependencies/openzeppelin/contracts/IERC20.sol';
import {MintableERC20} from '../tokens/MintableERC20.sol';

contract MockParaSwapFeeClaimer is IFeeClaimer {
MockParaSwapTokenTransferProxy immutable TOKEN_TRANSFER_PROXY;

mapping(address => mapping(address => uint256)) internal _fees;

constructor() {
TOKEN_TRANSFER_PROXY = new MockParaSwapTokenTransferProxy();
}

function registerFee(address _account, IERC20 _token, uint256 _fee) external {
_fees[_account][address(_token)] += _fee;
}
Expand Down
16 changes: 0 additions & 16 deletions src/contracts/mocks/swap/MockParaSwapTokenTransferProxy.sol

This file was deleted.

14 changes: 7 additions & 7 deletions tests/extensions/paraswap-adapters/ParaswapAdapters.t.sol
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// SPDX-License-Identifier: BUSL-1.1
pragma solidity ^0.8.0;

import {ParaSwapLiquiditySwapAdapter, IParaSwapAugustus} from '../../../src/contracts/extensions/paraswap-adapters/ParaSwapLiquiditySwapAdapter.sol';
import {ParaSwapLiquiditySwapAdapter} from '../../../src/contracts/extensions/paraswap-adapters/ParaSwapLiquiditySwapAdapter.sol';
import {ParaSwapRepayAdapter, IParaSwapAugustusRegistry} from '../../../src/contracts/extensions/paraswap-adapters/ParaSwapRepayAdapter.sol';
import {ParaSwapWithdrawSwapAdapter} from '../../../src/contracts/extensions/paraswap-adapters/ParaSwapWithdrawSwapAdapter.sol';
import {AaveParaSwapFeeClaimer, IERC20} from '../../../src/contracts/extensions/paraswap-adapters/AaveParaSwapFeeClaimer.sol';
Expand Down Expand Up @@ -325,7 +325,7 @@ contract ParaswapAdaptersTest is TestnetProcedures {
expectedUsdxAmount,
0,
augustusInput,
IParaSwapAugustus(address(mockParaSwapAugustus)),
address(mockParaSwapAugustus),
emptyPermit
);
}
Expand Down Expand Up @@ -387,7 +387,7 @@ contract ParaswapAdaptersTest is TestnetProcedures {
expectedUsdxAmount,
0,
augustusInput,
IParaSwapAugustus(address(mockParaSwapAugustus)),
address(mockParaSwapAugustus),
permitInput
);
}
Expand Down Expand Up @@ -429,7 +429,7 @@ contract ParaswapAdaptersTest is TestnetProcedures {
expectedUsdxAmount,
amountToSwap,
augustusInput,
IParaSwapAugustus(address(mockParaSwapAugustus)),
address(mockParaSwapAugustus),
emptyPermit
);
}
Expand Down Expand Up @@ -809,7 +809,7 @@ contract ParaswapAdaptersTest is TestnetProcedures {
expectedUsdxAmount,
0,
augustusInput,
IParaSwapAugustus(address(mockParaSwapAugustus)),
address(mockParaSwapAugustus),
emptyPermit
);

Expand Down Expand Up @@ -871,7 +871,7 @@ contract ParaswapAdaptersTest is TestnetProcedures {
expectedUsdxAmount,
0,
augustusInput,
IParaSwapAugustus(address(mockParaSwapAugustus)),
address(mockParaSwapAugustus),
permitInput
);

Expand Down Expand Up @@ -914,7 +914,7 @@ contract ParaswapAdaptersTest is TestnetProcedures {
expectedUsdxAmount,
amountToSwap,
augustusInput,
IParaSwapAugustus(address(mockParaSwapAugustus)),
address(mockParaSwapAugustus),
emptyPermit
);

Expand Down
Loading