-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBaseRouter.sol
60 lines (45 loc) · 1.88 KB
/
BaseRouter.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
// SPDX-License-Identifier: GPL-3.0-only
pragma solidity >=0.8.18;
import {ITokenWhitelistRegistry} from "@src/interfaces/ITokenWhitelistRegistry.sol";
import {LibMulticaller} from "@vec-multicaller/LibMulticaller.sol";
import {BytesLib} from "@src/lib/BytesLib.sol";
import {IProtocolState} from "@src/interfaces/IProtocolState.sol";
import {IProtocolAddressRegistry} from "@src/interfaces/IProtocolAddressRegistry.sol";
abstract contract BaseRouter {
using BytesLib for bytes;
error InvalidRecipient();
error TokenNotWhitelisted();
modifier setCaller() {
if (caller == address(0)) caller = LibMulticaller.sender();
_;
caller = address(0);
}
modifier notPaused() {
IProtocolState(ADDRESS_REGISTRY.getProtocolState()).requireNotStopped();
_;
}
/// @notice this variable is transient
address internal caller;
IProtocolAddressRegistry internal immutable ADDRESS_REGISTRY;
constructor(IProtocolAddressRegistry _addressRegistry) {
ADDRESS_REGISTRY = _addressRegistry;
}
function isTokenWhitelisted(address user, address token) public view returns (bool) {
return ITokenWhitelistRegistry(ADDRESS_REGISTRY.getTokenWhitelistRegistry())
.isTokenWhitelisted(user, address(this), token);
}
function _checkTokenIsWhitelisted(address user, address token) internal view {
if (!isTokenWhitelisted(user, token)) revert TokenNotWhitelisted();
}
function _checkTokensAreWhitelisted(address user, bytes memory packedTokens) internal view {
address[] memory tokens = packedTokens.unpackAddresses();
uint256 length = tokens.length;
require(length > 0, "Router: length must be > 0");
for (uint256 i = 0; i < length;) {
_checkTokenIsWhitelisted(user, tokens[i]);
unchecked {
++i;
}
}
}
}