/
RainbowRouter.sol
150 lines (128 loc) Β· 9.71 KB
/
RainbowRouter.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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
/*
ββββ βββ
,β, ββ ,βββ, .ββ. ,β, βββ βββ βββ ,βββ, ,ββ ββ ,β
ββββββ ββββββββ ββββ βββββββββ βββββββββ βββββββββ`βββ ββββ βββ
βββ ββββββββ ββββ βββ ββββ βββ βββββββ βββ ββββββββββββ
βββ βββββββββ,ββββ βββ ββββ βββββββββ βββββββββ ββββΒ¬βββββ
βββ βββββββββ"ββ` βββ ββ" ββ`βββββ βββββ` βββ βββ
_," _ _"""βΏ=-, _
β _ __"=.__
ββ...... _ _ "=._
βββββββββββββββββ. "= _
ββ©β©β©β©β©β©Ξ΄ΟΟΟΟβββββββββββ >__
βββββββββ__ _ ββββ©ΟΟβββββββ ^=_
ββββββββββββββββ,β `ββ Οβββββββ βΏ
βββββββββββββββββββββ._ `βΓ
Οβββββ " _
ββ β β β β β β β¬β¬β¬ββΟββββββββββββ ββ βββββ "
βββββββββ¬β¬β¬β β’β¬β β¬β β¬βββββββββββ "βΟββββ Β½_
βββββββββββ;βββββ¬β β¬β β ββββββββββ_ βΟββββ "_
ββΟΟΟββββββββββββ-βββ¬β β β β¬ββββββββ `β βββββ ,
ββ¬β¬β¬β β β β¬β¬β¬β¬βΟβββββββββββ¬β¬β β¬βββββββ .ββ ββββ β₯
_ββββΞΞβββββ©β¬β β¬β ββββββββββ¬β¬β β¬βββββββ' β βββββ β₯
`ββΏβΏββΟββ 'ββββ¬β β¬βββββββββ¬β¬β β¬ββββββ β βββββ [
_βΞβ βββ β β¬β¬βββββββ¬β β β ββββββ β βββββ '_
_βΟβ'ββ β β¬ββββββββ β β ββββββ _β ββββ β_
_`Ο βββ¬β β βββββββ β β ββββββ.`β ββββ [
_βββ‘ββ β¬β¬ββββββ β β β¬ββββββ β βββββ β
_βββ‘ββ β β¬ββββ"ββ β β¬βββββ β β ββββ β‘_
β ββ β β β¬ββββββ β¬β β¬ββββ _β ββββ Ξ
βββββ β β ββββββ β β β¬βββββ β βββββ [
_β.ββ β β ββββββ¬β β β¬βββββ[β β¬ββββ β
_βΟββ β β β¬βββββ¬β¬β β¬β¬ββββ[β β¬ββββ ββ₯_
____ ____ __ _______ ____
/$$$$$$ /$$$$$$ /$$
/$$__ $$ /$$__ $$ | $$
| $$ \__/ /$$ /$$ /$$ /$$$$$$ /$$$$$$ | $$ \ $$ /$$$$$$ /$$$$$$ /$$$$$$ /$$$$$$ /$$$$$$ /$$$$$$ /$$$$$$ /$$$$$$ /$$$$$$
| $$$$$$ | $$ | $$ | $$ |____ $$ /$$__ $$ | $$$$$$$$ /$$__ $$ /$$__ $$ /$$__ $$ /$$__ $$ /$$__ $$ |____ $$|_ $$_/ /$$__ $$ /$$__ $$
\____ $$| $$ | $$ | $$ /$$$$$$$| $$ \ $$ | $$__ $$| $$ \ $$| $$ \ $$| $$ \__/| $$$$$$$$| $$ \ $$ /$$$$$$$ | $$ | $$ \ $$| $$ \__/
/$$ \ $$| $$ | $$ | $$ /$$__ $$| $$ | $$ | $$ | $$| $$ | $$| $$ | $$| $$ | $$_____/| $$ | $$ /$$__ $$ | $$ /$$| $$ | $$| $$
| $$$$$$/| $$$$$/$$$$/| $$$$$$$| $$$$$$$/ | $$ | $$| $$$$$$$| $$$$$$$| $$ | $$$$$$$| $$$$$$$| $$$$$$$ | $$$$/| $$$$$$/| $$
\______/ \_____/\___/ \_______/| $$____/ |__/ |__/ \____ $$ \____ $$|__/ \_______/ \____ $$ \_______/ \___/ \______/ |__/
| $$ /$$ \ $$ /$$ \ $$ /$$ \ $$
| $$ | $$$$$$/| $$$$$$/ | $$$$$$/
|__/ \______/ \______/ \______/
*/
//SPDX-License-Identifier: GPL-3.0
pragma solidity =0.8.11;
import "@rari-capital/solmate/src/utils/SafeTransferLib.sol";
import "@rari-capital/solmate/src/tokens/ERC20.sol";
import "./routers/BaseAggregator.sol";
/// @title Rainbow swap aggregator contract
contract RainbowRouter is BaseAggregator {
/// @dev The address that is the current owner of this contract
address public owner;
/// @dev Event emitted when the owner changes
event OwnerChanged(address indexed newOwner, address indexed oldOwner);
/// @dev Event emitted when a swap target gets added
event SwapTargetAdded(address indexed target);
/// @dev Event emitted when a swap target gets removed
event SwapTargetRemoved(address indexed target);
/// @dev Event emitted when token fees are withdrawn
event TokenWithdrawn(
address indexed token,
address indexed target,
uint256 amount
);
/// @dev Event emitted when ETH fees are withdrawn
event EthWithdrawn(address indexed target, uint256 amount);
/// @dev modifier that ensures only the owner is allowed to call a specific method
modifier onlyOwner() {
require(msg.sender == owner, "ONLY_OWNER");
_;
}
constructor() {
owner = msg.sender;
status = 1;
}
/// @dev We don't want to accept any ETH, except refunds from aggregators
/// or the owner (for testing purposes), which can also withdraw
/// This is done by evaluating the value of status, which is set to 2
/// only during swaps due to the "nonReentrant" modifier
receive() external payable {
require(status == 2 || msg.sender == owner, "NO_RECEIVE");
}
/// @dev method to add or remove swap targets from swapTargets
/// This is required so we only approve "trusted" swap targets
/// to transfer tokens out of this contract
/// @param target address of the swap target to add
/// @param add flag to add or remove the swap target
function updateSwapTargets(address target, bool add) external onlyOwner {
swapTargets[target] = add;
if (add) {
emit SwapTargetAdded(target);
} else {
emit SwapTargetRemoved(target);
}
}
/// @dev method to withdraw ERC20 tokens (from the fees)
/// @param token address of the token to withdraw
/// @param to address that's receiving the tokens
/// @param amount amount of tokens to withdraw
function withdrawToken(
address token,
address to,
uint256 amount
) external onlyOwner {
require(to != address(0), "ZERO_ADDRESS");
SafeTransferLib.safeTransfer(ERC20(token), to, amount);
emit TokenWithdrawn(token, to, amount);
}
/// @dev method to withdraw ETH (from the fees)
/// @param to address that's receiving the ETH
/// @param amount amount of ETH to withdraw
function withdrawEth(address to, uint256 amount) external onlyOwner {
require(to != address(0), "ZERO_ADDRESS");
SafeTransferLib.safeTransferETH(to, amount);
emit EthWithdrawn(to, amount);
}
/// @dev Transfers ownership of the contract to a new account (`newOwner`).
/// @param newOwner address of the new owner
/// Can only be called by the current owner.
function transferOwnership(address newOwner) external virtual onlyOwner {
require(newOwner != address(0), "ZERO_ADDRESS");
require(newOwner != owner, "SAME_OWNER");
address previousOwner = owner;
owner = newOwner;
emit OwnerChanged(newOwner, previousOwner);
}
}