2020-09-08 13:05:53 +00:00
|
|
|
// SPDX-License-Identifier: agpl-3.0
|
|
|
|
pragma solidity ^0.6.8;
|
|
|
|
|
|
|
|
import {MintableERC20} from '../tokens/MintableERC20.sol';
|
|
|
|
import {ILendingPoolAddressesProvider} from '../../interfaces/ILendingPoolAddressesProvider.sol';
|
|
|
|
import {ISwapAdapter} from '../../interfaces/ISwapAdapter.sol';
|
2020-09-09 11:06:46 +00:00
|
|
|
import {ILendingPool} from "../../interfaces/ILendingPool.sol";
|
2020-09-08 13:05:53 +00:00
|
|
|
import {IERC20} from '@openzeppelin/contracts/token/ERC20/IERC20.sol';
|
|
|
|
|
|
|
|
contract MockSwapAdapter is ISwapAdapter {
|
|
|
|
|
2020-09-09 11:06:46 +00:00
|
|
|
uint256 internal _amountToReturn;
|
|
|
|
bool internal _tryReentrancy;
|
2020-09-08 13:05:53 +00:00
|
|
|
ILendingPoolAddressesProvider public addressesProvider;
|
|
|
|
|
|
|
|
event Swapped(address fromAsset, address toAsset, uint256 fromAmount, uint256 receivedAmount);
|
|
|
|
|
|
|
|
constructor(ILendingPoolAddressesProvider provider) public {
|
|
|
|
addressesProvider = provider;
|
|
|
|
}
|
|
|
|
|
|
|
|
function setAmountToReturn(uint256 amount) public {
|
2020-09-09 11:06:46 +00:00
|
|
|
_amountToReturn = amount;
|
|
|
|
}
|
|
|
|
|
|
|
|
function setTryReentrancy(bool tryReentrancy) public {
|
|
|
|
_tryReentrancy = tryReentrancy;
|
2020-09-08 13:05:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function executeOperation(
|
|
|
|
address assetToSwapFrom,
|
|
|
|
address assetToSwapTo,
|
|
|
|
uint256 amountToSwap,
|
|
|
|
address fundsDestination,
|
|
|
|
bytes calldata params
|
|
|
|
) external override {
|
|
|
|
params;
|
|
|
|
IERC20(assetToSwapFrom).transfer(address(1), amountToSwap); // We don't want to keep funds here
|
2020-09-09 11:06:46 +00:00
|
|
|
MintableERC20(assetToSwapTo).mint(_amountToReturn);
|
|
|
|
IERC20(assetToSwapTo).approve(fundsDestination, _amountToReturn);
|
2020-09-08 13:05:53 +00:00
|
|
|
|
2020-09-09 11:06:46 +00:00
|
|
|
if (_tryReentrancy) {
|
|
|
|
ILendingPool(fundsDestination).repayWithCollateral(
|
|
|
|
assetToSwapFrom,
|
|
|
|
assetToSwapTo,
|
|
|
|
address(1), // Doesn't matter, we just want to test the reentrancy
|
|
|
|
1 ether, // Same
|
|
|
|
address(1), // Same
|
|
|
|
"0x"
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
emit Swapped(assetToSwapFrom, assetToSwapTo, amountToSwap, _amountToReturn);
|
2020-09-08 13:05:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function burnAsset(IERC20 asset, uint256 amount) public {
|
|
|
|
uint256 amountToBurn = (amount == type(uint256).max) ? asset.balanceOf(address(this)) : amount;
|
|
|
|
asset.transfer(address(0), amountToBurn);
|
|
|
|
}
|
|
|
|
}
|