-
Notifications
You must be signed in to change notification settings - Fork 33
/
Copy pathSyncSwapper.sol
61 lines (52 loc) · 1.78 KB
/
SyncSwapper.sol
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
// SPDX-License-Identifier: MIT
pragma solidity >=0.8.4 <0.9.0;
import '../Swapper.sol';
interface ISyncSwapper is ISwapper {
// solhint-disable-next-line func-name-mixedcase
function SLIPPAGE_PRECISION() external view returns (uint256);
function swap(
address _receiver,
address _tokenIn,
address _tokenOut,
uint256 _amountIn,
uint256 _maxSlippage,
bytes calldata _data
) external;
}
abstract contract SyncSwapper is ISyncSwapper, Swapper {
// solhint-disable-next-line var-name-mixedcase
uint256 public immutable override SLIPPAGE_PRECISION = 10000; // 1 is 0.0001%, 1_000 is 0.1%
// solhint-disable-next-line var-name-mixedcase
SwapperType public constant override SWAPPER_TYPE = SwapperType.SYNC;
constructor(address _governor, address _tradeFactory) Governable(_governor) Swapper(_tradeFactory) {}
function _assertPreSwap(
address _receiver,
address _tokenIn,
address _tokenOut,
uint256 _amountIn,
uint256 _maxSlippage
) internal pure {
if (_receiver == address(0) || _tokenIn == address(0) || _tokenOut == address(0)) revert CommonErrors.ZeroAddress();
if (_amountIn == 0) revert CommonErrors.ZeroAmount();
if (_maxSlippage == 0) revert CommonErrors.ZeroSlippage();
}
function _executeSwap(
address _receiver,
address _tokenIn,
address _tokenOut,
uint256 _amountIn,
uint256 _maxSlippage,
bytes calldata _data
) internal virtual;
function swap(
address _receiver,
address _tokenIn,
address _tokenOut,
uint256 _amountIn,
uint256 _maxSlippage,
bytes calldata _data
) external virtual override onlyTradeFactory {
_assertPreSwap(_receiver, _tokenIn, _tokenOut, _amountIn, _maxSlippage);
_executeSwap(_receiver, _tokenIn, _tokenOut, _amountIn, _maxSlippage, _data);
}
}