-
Notifications
You must be signed in to change notification settings - Fork 0
/
LibBaseAuth.sol
112 lines (98 loc) · 2.57 KB
/
LibBaseAuth.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
// SPDX-License-Identifier: MIT
pragma solidity =0.7.5;
import "LibRoles.sol";
import "LibIERC20.sol";
/**
* @dev Base auth.
*/
contract BaseAuth {
using Roles for Roles.Role;
Roles.Role private _agents;
event AgentAdded(address indexed account);
event AgentRemoved(address indexed account);
/**
* @dev Initializes the contract setting the deployer as the initial owner.
*/
constructor ()
{
_agents.add(msg.sender);
emit AgentAdded(msg.sender);
}
/**
* @dev Throws if called by account which is not an agent.
*/
modifier onlyAgent() {
require(isAgent(msg.sender), "AgentRole: caller does not have the Agent role");
_;
}
/**
* @dev Rescue compatible ERC20 Token
*
* Can only be called by an agent.
*/
function rescueToken(
address tokenAddr,
address recipient,
uint256 amount
)
external
onlyAgent
{
IERC20 _token = IERC20(tokenAddr);
require(recipient != address(0), "Rescue: recipient is the zero address");
uint256 balance = _token.balanceOf(address(this));
require(balance >= amount, "Rescue: amount exceeds balance");
_token.transfer(recipient, amount);
}
/**
* @dev Withdraw Ether
*
* Can only be called by an agent.
*/
function withdrawEther(
address payable recipient,
uint256 amount
)
external
onlyAgent
{
require(recipient != address(0), "Withdraw: recipient is the zero address");
uint256 balance = address(this).balance;
require(balance >= amount, "Withdraw: amount exceeds balance");
recipient.transfer(amount);
}
/**
* @dev Returns true if the `account` has the Agent role.
*/
function isAgent(address account)
public
view
returns (bool)
{
return _agents.has(account);
}
/**
* @dev Give an `account` access to the Agent role.
*
* Can only be called by an agent.
*/
function addAgent(address account)
public
onlyAgent
{
_agents.add(account);
emit AgentAdded(account);
}
/**
* @dev Remove an `account` access from the Agent role.
*
* Can only be called by an agent.
*/
function removeAgent(address account)
public
onlyAgent
{
_agents.remove(account);
emit AgentRemoved(account);
}
}