-
Notifications
You must be signed in to change notification settings - Fork 2
/
WQBridgePool.sol
114 lines (98 loc) · 3.62 KB
/
WQBridgePool.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
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
import '@openzeppelin/contracts-upgradeable/access/AccessControlUpgradeable.sol';
import '@openzeppelin/contracts-upgradeable/token/ERC20/IERC20Upgradeable.sol';
import '@openzeppelin/contracts-upgradeable/token/ERC20/utils/SafeERC20Upgradeable.sol';
import '@openzeppelin/contracts-upgradeable/security/PausableUpgradeable.sol';
import '@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol';
import '@openzeppelin/contracts-upgradeable/utils/AddressUpgradeable.sol';
import '@openzeppelin/contracts-upgradeable/proxy/utils/UUPSUpgradeable.sol';
contract WQBridgePool is
Initializable,
AccessControlUpgradeable,
PausableUpgradeable,
UUPSUpgradeable
{
using SafeERC20Upgradeable for IERC20Upgradeable;
using AddressUpgradeable for address payable;
bytes32 public constant ADMIN_ROLE = keccak256('ADMIN_ROLE');
bytes32 public constant UPGRADER_ROLE = keccak256('UPGRADER_ROLE');
bytes32 public constant BRIDGE_ROLE = keccak256('BRIDGE_ROLE');
bool private initialized;
mapping(address => bool) public isBlockListed;
event AddedBlockList(address user);
event RemovedBlockList(address user);
event Transferred(address token, address recipient, uint256 amount);
event TransferredNative(address sender, uint256 amount);
/// @custom:oz-upgrades-unsafe-allow constructor
constructor() initializer {}
function initialize() external initializer {
__AccessControl_init();
__Pausable_init();
__UUPSUpgradeable_init();
_setupRole(DEFAULT_ADMIN_ROLE, msg.sender);
_setupRole(ADMIN_ROLE, msg.sender);
_setupRole(UPGRADER_ROLE, msg.sender);
_setRoleAdmin(UPGRADER_ROLE, ADMIN_ROLE);
_setRoleAdmin(BRIDGE_ROLE, ADMIN_ROLE);
}
function _authorizeUpgrade(address newImplementation)
internal
override
onlyRole(UPGRADER_ROLE)
{}
function transfer(
address payable recipient,
uint256 amount,
address token
) external onlyRole(BRIDGE_ROLE) whenNotPaused {
require(isBlockListed[recipient] == false, 'WQBridgePool: Recipient address is blocklisted');
if (token != address(0)) {
IERC20Upgradeable(token).safeTransfer(recipient, amount);
} else {
recipient.sendValue(amount);
}
emit Transferred(token, recipient, amount);
}
receive() external payable {
emit TransferredNative(msg.sender, msg.value);
}
function removeLiquidity(
address payable recipient,
uint256 amount,
address token
) external onlyRole(ADMIN_ROLE) {
require(recipient != payable(0), 'WQBridge: invalid recipient address');
if (token != address(0)) {
IERC20Upgradeable(token).safeTransfer(recipient, amount);
} else {
recipient.sendValue(amount);
}
emit Transferred(token, recipient, amount);
}
function pause() external onlyRole(ADMIN_ROLE) {
_pause();
}
function unpause() external onlyRole(ADMIN_ROLE) {
_unpause();
}
/**
* @dev Add user address to blocklist
*
* Requirements
*
* - `user` address of user.
*/
function addBlockList(address user) external onlyRole(ADMIN_ROLE) {
isBlockListed[user] = true;
emit AddedBlockList(user);
}
/**
* @notice Remove user address from blocklist
* @param user address of user.
*/
function removeBlockList(address user) external onlyRole(ADMIN_ROLE) {
isBlockListed[user] = false;
emit RemovedBlockList(user);
}
}