Skip to content

Commit 8a63c4d

Browse files
committed
test: Fix tests
1 parent 2bcf88e commit 8a63c4d

File tree

11 files changed

+34
-81
lines changed

11 files changed

+34
-81
lines changed

src/contracts/extensions/paraswap-adapters/BaseParaSwapBuyAdapter.sol

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import {SafeMath} from '../../dependencies/openzeppelin/contracts/SafeMath.sol';
66
import {PercentageMath} from '../../protocol/libraries/math/PercentageMath.sol';
77
import {IPoolAddressesProvider} from '../../interfaces/IPoolAddressesProvider.sol';
88
import {IERC20Detailed} from '../../dependencies/openzeppelin/contracts/IERC20Detailed.sol';
9-
import {IParaSwapAugustus} from './interfaces/IParaSwapAugustus.sol';
109
import {IParaSwapAugustusRegistry} from './interfaces/IParaSwapAugustusRegistry.sol';
1110
import {BaseParaSwapAdapter} from './BaseParaSwapAdapter.sol';
1211

@@ -49,12 +48,9 @@ abstract contract BaseParaSwapBuyAdapter is BaseParaSwapAdapter {
4948
uint256 maxAmountToSwap,
5049
uint256 amountToReceive
5150
) internal returns (uint256 amountSold, uint256 amountBought) {
52-
(bytes memory buyCalldata, IParaSwapAugustus augustus) = abi.decode(
53-
paraswapData,
54-
(bytes, IParaSwapAugustus)
55-
);
51+
(bytes memory buyCalldata, address augustus) = abi.decode(paraswapData, (bytes, address));
5652

57-
require(AUGUSTUS_REGISTRY.isValidAugustus(address(augustus)), 'INVALID_AUGUSTUS');
53+
require(AUGUSTUS_REGISTRY.isValidAugustus(augustus), 'INVALID_AUGUSTUS');
5854

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

78-
assetToSwapFrom.safeApprove(address(augustus), maxAmountToSwap);
74+
assetToSwapFrom.safeApprove(augustus, maxAmountToSwap);
7975

8076
if (toAmountOffset != 0) {
8177
// Ensure 256 bit (32 bytes) toAmountOffset value is within bounds of the
@@ -91,7 +87,7 @@ abstract contract BaseParaSwapBuyAdapter is BaseParaSwapAdapter {
9187
mstore(add(buyCalldata, add(toAmountOffset, 32)), amountToReceive)
9288
}
9389
}
94-
(bool success, ) = address(augustus).call(buyCalldata);
90+
(bool success, ) = augustus.call(buyCalldata);
9591
if (!success) {
9692
// Copy revert reason from call
9793
assembly {
@@ -101,7 +97,7 @@ abstract contract BaseParaSwapBuyAdapter is BaseParaSwapAdapter {
10197
}
10298

10399
// Reset allowance
104-
assetToSwapFrom.safeApprove(address(augustus), 0);
100+
assetToSwapFrom.safeApprove(augustus, 0);
105101

106102
uint256 balanceAfterAssetFrom = assetToSwapFrom.balanceOf(address(this));
107103
amountSold = balanceBeforeAssetFrom - balanceAfterAssetFrom;

src/contracts/extensions/paraswap-adapters/BaseParaSwapSellAdapter.sol

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import {SafeMath} from '../../dependencies/openzeppelin/contracts/SafeMath.sol';
66
import {PercentageMath} from '../../protocol/libraries/math/PercentageMath.sol';
77
import {IPoolAddressesProvider} from '../../interfaces/IPoolAddressesProvider.sol';
88
import {IERC20Detailed} from '../../dependencies/openzeppelin/contracts/IERC20Detailed.sol';
9-
import {IParaSwapAugustus} from './interfaces/IParaSwapAugustus.sol';
109
import {IParaSwapAugustusRegistry} from './interfaces/IParaSwapAugustusRegistry.sol';
1110
import {BaseParaSwapAdapter} from './BaseParaSwapAdapter.sol';
1211

@@ -45,13 +44,13 @@ abstract contract BaseParaSwapSellAdapter is BaseParaSwapAdapter {
4544
function _sellOnParaSwap(
4645
uint256 fromAmountOffset,
4746
bytes memory swapCalldata,
48-
IParaSwapAugustus augustus,
47+
address augustus,
4948
IERC20Detailed assetToSwapFrom,
5049
IERC20Detailed assetToSwapTo,
5150
uint256 amountToSwap,
5251
uint256 minAmountToReceive
5352
) internal returns (uint256 amountReceived) {
54-
require(AUGUSTUS_REGISTRY.isValidAugustus(address(augustus)), 'INVALID_AUGUSTUS');
53+
require(AUGUSTUS_REGISTRY.isValidAugustus(augustus), 'INVALID_AUGUSTUS');
5554

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

75-
assetToSwapFrom.safeApprove(address(augustus), amountToSwap);
74+
assetToSwapFrom.safeApprove(augustus, amountToSwap);
7675

7776
if (fromAmountOffset != 0) {
7877
// Ensure 256 bit (32 bytes) fromAmount value is within bounds of the
@@ -88,7 +87,7 @@ abstract contract BaseParaSwapSellAdapter is BaseParaSwapAdapter {
8887
mstore(add(swapCalldata, add(fromAmountOffset, 32)), amountToSwap)
8988
}
9089
}
91-
(bool success, ) = address(augustus).call(swapCalldata);
90+
(bool success, ) = augustus.call(swapCalldata);
9291
if (!success) {
9392
// Copy revert reason from call
9493
assembly {
@@ -98,7 +97,7 @@ abstract contract BaseParaSwapSellAdapter is BaseParaSwapAdapter {
9897
}
9998

10099
// Reset allowance
101-
assetToSwapFrom.safeApprove(address(augustus), 0);
100+
assetToSwapFrom.safeApprove(augustus, 0);
102101

103102
require(
104103
assetToSwapFrom.balanceOf(address(this)) == balanceBeforeAssetFrom - amountToSwap,

src/contracts/extensions/paraswap-adapters/ParaSwapLiquiditySwapAdapter.sol

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import {SafeERC20} from '../../dependencies/openzeppelin/contracts/SafeERC20.sol
88
import {SafeMath} from '../../dependencies/openzeppelin/contracts/SafeMath.sol';
99
import {BaseParaSwapSellAdapter} from './BaseParaSwapSellAdapter.sol';
1010
import {IParaSwapAugustusRegistry} from './interfaces/IParaSwapAugustusRegistry.sol';
11-
import {IParaSwapAugustus} from './interfaces/IParaSwapAugustus.sol';
1211
import {ReentrancyGuard} from '../../dependencies/openzeppelin/ReentrancyGuard.sol';
1312

1413
/**
@@ -63,12 +62,9 @@ contract ParaSwapLiquiditySwapAdapter is BaseParaSwapSellAdapter, ReentrancyGuar
6362
uint256 minAmountToReceive,
6463
uint256 swapAllBalanceOffset,
6564
bytes memory swapCalldata,
66-
IParaSwapAugustus augustus,
65+
address augustus,
6766
PermitSignature memory permitParams
68-
) = abi.decode(
69-
params,
70-
(IERC20Detailed, uint256, uint256, bytes, IParaSwapAugustus, PermitSignature)
71-
);
67+
) = abi.decode(params, (IERC20Detailed, uint256, uint256, bytes, address, PermitSignature));
7268

7369
_swapLiquidity(
7470
swapAllBalanceOffset,
@@ -106,7 +102,7 @@ contract ParaSwapLiquiditySwapAdapter is BaseParaSwapSellAdapter, ReentrancyGuar
106102
uint256 minAmountToReceive,
107103
uint256 swapAllBalanceOffset,
108104
bytes calldata swapCalldata,
109-
IParaSwapAugustus augustus,
105+
address augustus,
110106
PermitSignature calldata permitParams
111107
) external nonReentrant {
112108
IERC20WithPermit aToken = IERC20WithPermit(
@@ -158,7 +154,7 @@ contract ParaSwapLiquiditySwapAdapter is BaseParaSwapSellAdapter, ReentrancyGuar
158154
function _swapLiquidity(
159155
uint256 swapAllBalanceOffset,
160156
bytes memory swapCalldata,
161-
IParaSwapAugustus augustus,
157+
address augustus,
162158
PermitSignature memory permitParams,
163159
uint256 flashLoanAmount,
164160
uint256 premium,

src/contracts/extensions/paraswap-adapters/ParaSwapRepayAdapter.sol

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import {SafeERC20} from '../../dependencies/openzeppelin/contracts/SafeERC20.sol
1010
import {SafeMath} from '../../dependencies/openzeppelin/contracts/SafeMath.sol';
1111
import {BaseParaSwapBuyAdapter} from './BaseParaSwapBuyAdapter.sol';
1212
import {IParaSwapAugustusRegistry} from './interfaces/IParaSwapAugustusRegistry.sol';
13-
import {IParaSwapAugustus} from './interfaces/IParaSwapAugustus.sol';
1413
import {ReentrancyGuard} from '../../dependencies/openzeppelin/ReentrancyGuard.sol';
1514

1615
/**
@@ -57,7 +56,7 @@ contract ParaSwapRepayAdapter is BaseParaSwapBuyAdapter, ReentrancyGuard {
5756
* uint256 debtRateMode Rate mode of the debt to be repaid
5857
* bytes paraswapData Paraswap Data
5958
* * bytes buyCallData Call data for augustus
60-
* * IParaSwapAugustus augustus Address of Augustus Swapper
59+
* * address augustus Address of Augustus Swapper
6160
* PermitSignature permitParams Struct containing the permit signatures, set to all zeroes if not used
6261
*/
6362
function executeOperation(

src/contracts/extensions/paraswap-adapters/ParaSwapWithdrawSwapAdapter.sol

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import {IPoolAddressesProvider} from '../../interfaces/IPoolAddressesProvider.so
77
import {BaseParaSwapSellAdapter} from './BaseParaSwapSellAdapter.sol';
88
import {IParaSwapAugustusRegistry} from './interfaces/IParaSwapAugustusRegistry.sol';
99
import {SafeERC20} from '../../dependencies/openzeppelin/contracts/SafeERC20.sol';
10-
import {IParaSwapAugustus} from './interfaces/IParaSwapAugustus.sol';
1110
import {ReentrancyGuard} from '../../dependencies/openzeppelin/ReentrancyGuard.sol';
1211

1312
contract ParaSwapWithdrawSwapAdapter is BaseParaSwapSellAdapter, ReentrancyGuard {
@@ -50,7 +49,7 @@ contract ParaSwapWithdrawSwapAdapter is BaseParaSwapSellAdapter, ReentrancyGuard
5049
uint256 minAmountToReceive,
5150
uint256 swapAllBalanceOffset,
5251
bytes calldata swapCalldata,
53-
IParaSwapAugustus augustus,
52+
address augustus,
5453
PermitSignature calldata permitParams
5554
) external nonReentrant {
5655
IERC20WithPermit aToken = IERC20WithPermit(

src/contracts/extensions/paraswap-adapters/interfaces/IFeeClaimer.sol

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ interface IFeeClaimer {
1919
* the call will fail if withdrawer have zero balance in the contract
2020
* @param _token address of the ERC20 token
2121
* @param _recipient address
22-
* @return true if the withdraw was successfull
22+
* @return true if the withdraw was successful
2323
*/
2424
function withdrawAllERC20(IERC20 _token, address _recipient) external returns (bool);
2525

@@ -29,7 +29,7 @@ interface IFeeClaimer {
2929
* the call will fail if withdrawer have zero balance in the contract
3030
* @param _tokens list of addresses of the ERC20 token
3131
* @param _recipient address of recipient
32-
* @return true if the withdraw was successfull
32+
* @return true if the withdraw was successful
3333
*/
3434
function batchWithdrawAllERC20(
3535
address[] calldata _tokens,
@@ -42,7 +42,7 @@ interface IFeeClaimer {
4242
* the call will fail if withdrawer have zero balance in the contract
4343
* @param _token address of the ERC20 token
4444
* @param _recipient address
45-
* @return true if the withdraw was successfull
45+
* @return true if the withdraw was successful
4646
*/
4747
function withdrawSomeERC20(
4848
IERC20 _token,
@@ -57,7 +57,7 @@ interface IFeeClaimer {
5757
* @param _tokens address of the ERC20 tokens
5858
* @param _tokenAmounts array of amounts
5959
* @param _recipient destination account addresses
60-
* @return true if the withdraw was successfull
60+
* @return true if the withdraw was successful
6161
*/
6262
function batchWithdrawSomeERC20(
6363
IERC20[] calldata _tokens,

src/contracts/extensions/paraswap-adapters/interfaces/IParaSwapAugustus.sol

Lines changed: 0 additions & 6 deletions
This file was deleted.

src/contracts/mocks/swap/MockParaSwapAugustus.sol

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,10 @@
11
// SPDX-License-Identifier: MIT
22
pragma solidity ^0.8.10;
33

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

9-
contract MockParaSwapAugustus is IParaSwapAugustus {
10-
MockParaSwapTokenTransferProxy immutable TOKEN_TRANSFER_PROXY;
7+
contract MockParaSwapAugustus {
118
bool _expectingSwap;
129
address _expectedFromToken;
1310
address _expectedToToken;
@@ -20,14 +17,6 @@ contract MockParaSwapAugustus is IParaSwapAugustus {
2017
uint256 _expectedToAmountMax;
2118
uint256 _expectedToAmountMin;
2219

23-
constructor() {
24-
TOKEN_TRANSFER_PROXY = new MockParaSwapTokenTransferProxy();
25-
}
26-
27-
function getTokenTransferProxy() external view override returns (address) {
28-
return address(TOKEN_TRANSFER_PROXY);
29-
}
30-
3120
function expectSwap(
3221
address fromToken,
3322
address toToken,
@@ -72,7 +61,7 @@ contract MockParaSwapAugustus is IParaSwapAugustus {
7261
'From amount out of range'
7362
);
7463
require(_receivedAmount >= toAmount, 'Received amount of tokens are less than expected');
75-
TOKEN_TRANSFER_PROXY.transferFrom(fromToken, msg.sender, address(this), fromAmount);
64+
_transferFrom(fromToken, msg.sender, address(this), fromAmount);
7665
MintableERC20(toToken).mint(_receivedAmount);
7766
IERC20(toToken).transfer(msg.sender, _receivedAmount);
7867
_expectingSwap = false;
@@ -93,9 +82,13 @@ contract MockParaSwapAugustus is IParaSwapAugustus {
9382
'To amount out of range'
9483
);
9584
require(_fromAmount <= fromAmount, 'From amount of tokens are higher than expected');
96-
TOKEN_TRANSFER_PROXY.transferFrom(fromToken, msg.sender, address(this), _fromAmount);
85+
_transferFrom(fromToken, msg.sender, address(this), _fromAmount);
9786
MintableERC20(toToken).mint(msg.sender, toAmount);
9887
_expectingSwap = false;
9988
return fromAmount;
10089
}
90+
91+
function _transferFrom(address token, address from, address to, uint256 amount) internal {
92+
IERC20(token).transferFrom(from, to, amount);
93+
}
10194
}

src/contracts/mocks/swap/MockParaSwapFeeClaimer.sol

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,12 @@
22
pragma solidity ^0.8.10;
33

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

98
contract MockParaSwapFeeClaimer is IFeeClaimer {
10-
MockParaSwapTokenTransferProxy immutable TOKEN_TRANSFER_PROXY;
11-
129
mapping(address => mapping(address => uint256)) internal _fees;
1310

14-
constructor() {
15-
TOKEN_TRANSFER_PROXY = new MockParaSwapTokenTransferProxy();
16-
}
17-
1811
function registerFee(address _account, IERC20 _token, uint256 _fee) external {
1912
_fees[_account][address(_token)] += _fee;
2013
}

src/contracts/mocks/swap/MockParaSwapTokenTransferProxy.sol

Lines changed: 0 additions & 16 deletions
This file was deleted.

0 commit comments

Comments
 (0)