mirror of
https://github.com/Instadapp/aave-protocol-v2.git
synced 2024-07-29 21:47:30 +00:00
60 lines
2.0 KiB
Solidity
60 lines
2.0 KiB
Solidity
|
// SPDX-License-Identifier: agpl-3.0
|
||
|
pragma solidity 0.6.12;
|
||
|
pragma experimental ABIEncoderV2;
|
||
|
|
||
|
import {IParaSwapAugustus} from '../../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 _tokenTransferProxy;
|
||
|
bool _expectingSwap;
|
||
|
address _expectedFromToken;
|
||
|
address _expectedToToken;
|
||
|
uint256 _expectedFromAmountMin;
|
||
|
uint256 _expectedFromAmountMax;
|
||
|
uint256 _receivedAmount;
|
||
|
|
||
|
constructor() public {
|
||
|
_tokenTransferProxy = new MockParaSwapTokenTransferProxy();
|
||
|
}
|
||
|
|
||
|
function getTokenTransferProxy() external view override returns (address) {
|
||
|
return address(_tokenTransferProxy);
|
||
|
}
|
||
|
|
||
|
function expectSwap(
|
||
|
address fromToken,
|
||
|
address toToken,
|
||
|
uint256 fromAmountMin,
|
||
|
uint256 fromAmountMax,
|
||
|
uint256 receivedAmount
|
||
|
) external {
|
||
|
_expectingSwap = true;
|
||
|
_expectedFromToken = fromToken;
|
||
|
_expectedToToken = toToken;
|
||
|
_expectedFromAmountMin = fromAmountMin;
|
||
|
_expectedFromAmountMax = fromAmountMax;
|
||
|
_receivedAmount = receivedAmount;
|
||
|
}
|
||
|
|
||
|
function swap(
|
||
|
address fromToken,
|
||
|
address toToken,
|
||
|
uint256 fromAmount,
|
||
|
uint256 toAmount
|
||
|
) external returns (uint256) {
|
||
|
require(_expectingSwap, 'Not expecting swap');
|
||
|
require(fromToken == _expectedFromToken, 'Unexpected from token');
|
||
|
require(toToken == _expectedToToken, 'Unexpected to token');
|
||
|
require(fromAmount >= _expectedFromAmountMin && fromAmount <= _expectedFromAmountMax, 'From amount out of range');
|
||
|
require(_receivedAmount >= toAmount, 'Received amount of tokens are less than expected');
|
||
|
_tokenTransferProxy.transferFrom(fromToken, msg.sender, address(this), fromAmount);
|
||
|
MintableERC20(toToken).mint(_receivedAmount);
|
||
|
IERC20(toToken).transfer(msg.sender, _receivedAmount);
|
||
|
_expectingSwap = false;
|
||
|
return _receivedAmount;
|
||
|
}
|
||
|
}
|