2021-03-18 15:44:52 +00:00
|
|
|
// 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 {
|
2021-05-20 22:25:51 +00:00
|
|
|
MockParaSwapTokenTransferProxy immutable TOKEN_TRANSFER_PROXY;
|
2021-03-18 15:44:52 +00:00
|
|
|
bool _expectingSwap;
|
|
|
|
address _expectedFromToken;
|
|
|
|
address _expectedToToken;
|
|
|
|
uint256 _expectedFromAmountMin;
|
|
|
|
uint256 _expectedFromAmountMax;
|
|
|
|
uint256 _receivedAmount;
|
|
|
|
|
|
|
|
constructor() public {
|
2021-05-20 22:25:51 +00:00
|
|
|
TOKEN_TRANSFER_PROXY = new MockParaSwapTokenTransferProxy();
|
2021-03-18 15:44:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function getTokenTransferProxy() external view override returns (address) {
|
2021-05-20 22:25:51 +00:00
|
|
|
return address(TOKEN_TRANSFER_PROXY);
|
2021-03-18 15:44:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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');
|
2021-05-20 22:25:51 +00:00
|
|
|
TOKEN_TRANSFER_PROXY.transferFrom(fromToken, msg.sender, address(this), fromAmount);
|
2021-03-18 15:44:52 +00:00
|
|
|
MintableERC20(toToken).mint(_receivedAmount);
|
|
|
|
IERC20(toToken).transfer(msg.sender, _receivedAmount);
|
|
|
|
_expectingSwap = false;
|
|
|
|
return _receivedAmount;
|
|
|
|
}
|
|
|
|
}
|