forked from neptune-mutual-blue/protocol
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathStoreBase.sol
118 lines (101 loc) · 4.36 KB
/
StoreBase.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
// Neptune Mutual Protocol (https://neptunemutual.com)
// SPDX-License-Identifier: BUSL-1.1
pragma solidity ^0.8.0;
import "../../interfaces/IStore.sol";
import "openzeppelin-solidity/contracts/security/Pausable.sol";
import "openzeppelin-solidity/contracts/access/Ownable.sol";
import "openzeppelin-solidity/contracts/token/ERC20/IERC20.sol";
import "openzeppelin-solidity/contracts/token/ERC20/utils/SafeERC20.sol";
abstract contract StoreBase is IStore, Pausable, Ownable {
using SafeERC20 for IERC20;
mapping(bytes32 => int256) public intStorage;
mapping(bytes32 => uint256) public uintStorage;
mapping(bytes32 => uint256[]) public uintsStorage;
mapping(bytes32 => address) public addressStorage;
mapping(bytes32 => mapping(address => bool)) public addressBooleanStorage;
mapping(bytes32 => string) public stringStorage;
mapping(bytes32 => bytes) public bytesStorage;
mapping(bytes32 => bytes32) public bytes32Storage;
mapping(bytes32 => bool) public boolStorage;
mapping(bytes32 => address[]) public addressArrayStorage;
mapping(bytes32 => mapping(address => uint256)) public addressArrayPositionMap;
mapping(bytes32 => bytes32[]) public bytes32ArrayStorage;
mapping(bytes32 => mapping(bytes32 => uint256)) public bytes32ArrayPositionMap;
mapping(address => bool) public pausers;
bytes32 private constant _NS_MEMBERS = "ns:members";
constructor() {
boolStorage[keccak256(abi.encodePacked(_NS_MEMBERS, msg.sender))] = true;
boolStorage[keccak256(abi.encodePacked(_NS_MEMBERS, address(this)))] = true;
}
/**
*
* @dev Accepts a list of accounts and their respective statuses for addition or removal as pausers.
*
* @custom:suppress-reentrancy Risk tolerable. Can only be called by the owner.
* @custom:suppress-address-trust-issue Risk tolerable.
*/
function setPausers(address[] calldata accounts, bool[] calldata statuses) external override onlyOwner whenNotPaused {
require(accounts.length > 0, "No pauser specified");
require(accounts.length == statuses.length, "Invalid args");
for (uint256 i = 0; i < accounts.length; i++) {
pausers[accounts[i]] = statuses[i];
}
emit PausersSet(msg.sender, accounts, statuses);
}
/**
* @dev Recover all Ether held by the contract.
* @custom:suppress-reentrancy Risk tolerable. Can only be called by the owner.
* @custom:suppress-pausable Risk tolerable. Can only be called by the owner.
*/
function recoverEther(address sendTo) external onlyOwner {
// slither-disable-next-line low-level-calls
(bool success, ) = payable(sendTo).call{value: address(this).balance}(""); // solhint-disable-line avoid-low-level-calls
require(success, "Recipient may have reverted");
}
/**
* @dev Recover all IERC-20 compatible tokens sent to this address.
*
* @custom:suppress-reentrancy Risk tolerable. Can only be called by the owner.
* @custom:suppress-pausable Risk tolerable. Can only be called by the owner.
* @custom:suppress-malicious-erc Risk tolerable. Although the token can't be trusted, the owner has to check the token code manually.
* @custom:suppress-address-trust-issue Risk tolerable. Although the token can't be trusted, the owner has to check the token code manually.
*
* @param token IERC-20 The address of the token contract
*/
function recoverToken(address token, address sendTo) external onlyOwner {
IERC20 erc20 = IERC20(token);
uint256 balance = erc20.balanceOf(address(this));
if (balance > 0) {
// slither-disable-next-line unchecked-transfer
erc20.safeTransfer(sendTo, balance);
}
}
/**
* @dev Pauses the store
*
* @custom:suppress-reentrancy Risk tolerable. Can only be called by a pauser.
*
*/
function pause() external {
require(pausers[msg.sender], "Forbidden");
super._pause();
}
/**
* @dev Unpauses the store
*
* @custom:suppress-reentrancy Risk tolerable. Can only be called by the owner.
*
*/
function unpause() external onlyOwner {
super._unpause();
}
function isProtocolMember(address contractAddress) public view returns (bool) {
return boolStorage[keccak256(abi.encodePacked(_NS_MEMBERS, contractAddress))];
}
function _throwIfPaused() internal view {
require(super.paused() == false, "Pausable: paused");
}
function _throwIfSenderNotProtocolMember() internal view {
require(isProtocolMember(msg.sender), "Forbidden");
}
}