-
Notifications
You must be signed in to change notification settings - Fork 33
/
Copy pathSwapper.sol
57 lines (43 loc) · 1.54 KB
/
Swapper.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
// SPDX-License-Identifier: MIT
pragma solidity >=0.8.4 <0.9.0;
import '@openzeppelin/contracts/token/ERC20/IERC20.sol';
import '@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol';
import '@yearn/contract-utils/contracts/utils/Governable.sol';
import '@yearn/contract-utils/contracts/utils/CollectableDust.sol';
import '../libraries/CommonErrors.sol';
interface ISwapper {
event TradeFactorySet(address _tradeFactory);
enum SwapperType {
ASYNC,
SYNC
}
// solhint-disable-next-line func-name-mixedcase
function SWAPPER_TYPE() external view returns (SwapperType);
function tradeFactory() external view returns (address);
function setTradeFactory(address _tradeFactory) external;
}
abstract contract Swapper is ISwapper, Governable, CollectableDust {
using SafeERC20 for IERC20;
// solhint-disable-next-line var-name-mixedcase
address public override tradeFactory;
constructor(address _tradeFactory) {
if (_tradeFactory == address(0)) revert CommonErrors.ZeroAddress();
tradeFactory = _tradeFactory;
}
function setTradeFactory(address _tradeFactory) external override onlyGovernor {
if (_tradeFactory == address(0)) revert CommonErrors.ZeroAddress();
tradeFactory = _tradeFactory;
emit TradeFactorySet(_tradeFactory);
}
modifier onlyTradeFactory() {
if (msg.sender != tradeFactory) revert CommonErrors.NotAuthorized();
_;
}
function sendDust(
address _to,
address _token,
uint256 _amount
) external virtual override onlyGovernor {
_sendDust(_to, _token, _amount);
}
}