ozeppelinsolidty 0.0.1-security → 3.4.2
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of ozeppelinsolidty might be problematic. Click here for more details.
- package/LICENSE +22 -0
- package/README.md +75 -3
- package/build/contracts/AccessControl.json +237 -0
- package/build/contracts/Address.json +8 -0
- package/build/contracts/Arrays.json +8 -0
- package/build/contracts/BeaconProxy.json +33 -0
- package/build/contracts/Clones.json +8 -0
- package/build/contracts/ConditionalEscrow.json +163 -0
- package/build/contracts/Context.json +8 -0
- package/build/contracts/Counters.json +8 -0
- package/build/contracts/Create2.json +8 -0
- package/build/contracts/ECDSA.json +8 -0
- package/build/contracts/EIP712.json +8 -0
- package/build/contracts/ERC1155.json +332 -0
- package/build/contracts/ERC1155Burnable.json +367 -0
- package/build/contracts/ERC1155Holder.json +106 -0
- package/build/contracts/ERC1155Pausable.json +360 -0
- package/build/contracts/ERC1155PresetMinterPauser.json +741 -0
- package/build/contracts/ERC1155Receiver.json +106 -0
- package/build/contracts/ERC165.json +28 -0
- package/build/contracts/ERC165Checker.json +8 -0
- package/build/contracts/ERC1820Implementer.json +33 -0
- package/build/contracts/ERC20.json +295 -0
- package/build/contracts/ERC20Burnable.json +310 -0
- package/build/contracts/ERC20Capped.json +292 -0
- package/build/contracts/ERC20Pausable.json +318 -0
- package/build/contracts/ERC20Permit.json +354 -0
- package/build/contracts/ERC20PresetFixedSupply.json +336 -0
- package/build/contracts/ERC20PresetMinterPauser.json +651 -0
- package/build/contracts/ERC20Snapshot.json +335 -0
- package/build/contracts/ERC721.json +424 -0
- package/build/contracts/ERC721Burnable.json +421 -0
- package/build/contracts/ERC721Holder.json +43 -0
- package/build/contracts/ERC721Pausable.json +447 -0
- package/build/contracts/ERC721PresetMinterPauserAutoId.json +762 -0
- package/build/contracts/ERC777.json +585 -0
- package/build/contracts/ERC777PresetFixedSupply.json +595 -0
- package/build/contracts/EnumerableMap.json +8 -0
- package/build/contracts/EnumerableSet.json +8 -0
- package/build/contracts/Escrow.json +144 -0
- package/build/contracts/GSNRecipient.json +165 -0
- package/build/contracts/GSNRecipientERC20Fee.json +194 -0
- package/build/contracts/GSNRecipientSignature.json +176 -0
- package/build/contracts/IBeacon.json +22 -0
- package/build/contracts/IERC1155.json +302 -0
- package/build/contracts/IERC1155MetadataURI.json +321 -0
- package/build/contracts/IERC1155Receiver.json +106 -0
- package/build/contracts/IERC165.json +28 -0
- package/build/contracts/IERC1820Implementer.json +33 -0
- package/build/contracts/IERC1820Registry.json +222 -0
- package/build/contracts/IERC20.json +192 -0
- package/build/contracts/IERC20Permit.json +84 -0
- package/build/contracts/IERC721.json +294 -0
- package/build/contracts/IERC721Enumerable.json +350 -0
- package/build/contracts/IERC721Metadata.json +339 -0
- package/build/contracts/IERC721Receiver.json +43 -0
- package/build/contracts/IERC777.json +400 -0
- package/build/contracts/IERC777Recipient.json +47 -0
- package/build/contracts/IERC777Sender.json +47 -0
- package/build/contracts/IRelayHub.json +656 -0
- package/build/contracts/IRelayRecipient.json +133 -0
- package/build/contracts/Initializable.json +8 -0
- package/build/contracts/Math.json +8 -0
- package/build/contracts/MerkleProof.json +8 -0
- package/build/contracts/Ownable.json +61 -0
- package/build/contracts/Pausable.json +48 -0
- package/build/contracts/PaymentSplitter.json +182 -0
- package/build/contracts/Proxy.json +17 -0
- package/build/contracts/ProxyAdmin.json +158 -0
- package/build/contracts/PullPayment.json +41 -0
- package/build/contracts/ReentrancyGuard.json +8 -0
- package/build/contracts/RefundEscrow.json +233 -0
- package/build/contracts/SafeCast.json +8 -0
- package/build/contracts/SafeERC20.json +8 -0
- package/build/contracts/SafeMath.json +8 -0
- package/build/contracts/SignedSafeMath.json +8 -0
- package/build/contracts/Strings.json +8 -0
- package/build/contracts/TimelockController.json +773 -0
- package/build/contracts/TokenTimelock.json +76 -0
- package/build/contracts/TransparentUpgradeableProxy.json +140 -0
- package/build/contracts/UpgradeableBeacon.json +111 -0
- package/build/contracts/UpgradeableProxy.json +46 -0
- package/build/contracts/__unstable__ERC20Owned.json +365 -0
- package/contracts/GSN/Context.sol +5 -0
- package/contracts/GSN/GSNRecipient.sol +230 -0
- package/contracts/GSN/GSNRecipientERC20Fee.sol +154 -0
- package/contracts/GSN/GSNRecipientSignature.sol +72 -0
- package/contracts/GSN/IRelayHub.sol +269 -0
- package/contracts/GSN/IRelayRecipient.sol +76 -0
- package/contracts/access/AccessControl.sol +217 -0
- package/contracts/access/Ownable.sol +68 -0
- package/contracts/access/TimelockController.sol +300 -0
- package/contracts/cryptography/ECDSA.sol +86 -0
- package/contracts/cryptography/MerkleProof.sol +33 -0
- package/contracts/drafts/EIP712.sol +108 -0
- package/contracts/drafts/ERC20Permit.sol +78 -0
- package/contracts/drafts/IERC20Permit.sol +51 -0
- package/contracts/introspection/ERC165.sol +54 -0
- package/contracts/introspection/ERC165Checker.sol +131 -0
- package/contracts/introspection/ERC1820Implementer.sol +37 -0
- package/contracts/introspection/IERC165.sol +24 -0
- package/contracts/introspection/IERC1820Implementer.sol +19 -0
- package/contracts/introspection/IERC1820Registry.sol +111 -0
- package/contracts/math/Math.sol +31 -0
- package/contracts/math/SafeMath.sol +214 -0
- package/contracts/math/SignedSafeMath.sol +92 -0
- package/contracts/payment/PaymentSplitter.sol +135 -0
- package/contracts/payment/PullPayment.sol +69 -0
- package/contracts/payment/escrow/ConditionalEscrow.sol +24 -0
- package/contracts/payment/escrow/Escrow.sol +65 -0
- package/contracts/payment/escrow/RefundEscrow.sol +93 -0
- package/contracts/presets/ERC1155PresetMinterPauser.sol +104 -0
- package/contracts/presets/ERC20PresetFixedSupply.sol +32 -0
- package/contracts/presets/ERC20PresetMinterPauser.sol +87 -0
- package/contracts/presets/ERC721PresetMinterPauserAutoId.sol +102 -0
- package/contracts/presets/ERC777PresetFixedSupply.sol +29 -0
- package/contracts/proxy/BeaconProxy.sol +88 -0
- package/contracts/proxy/Clones.sol +78 -0
- package/contracts/proxy/IBeacon.sol +15 -0
- package/contracts/proxy/Initializable.sol +55 -0
- package/contracts/proxy/Proxy.sol +83 -0
- package/contracts/proxy/ProxyAdmin.sol +77 -0
- package/contracts/proxy/TransparentUpgradeableProxy.sol +151 -0
- package/contracts/proxy/UpgradeableBeacon.sol +64 -0
- package/contracts/proxy/UpgradeableProxy.sol +78 -0
- package/contracts/token/ERC1155/ERC1155.sol +414 -0
- package/contracts/token/ERC1155/ERC1155Burnable.sol +31 -0
- package/contracts/token/ERC1155/ERC1155Holder.sol +18 -0
- package/contracts/token/ERC1155/ERC1155Pausable.sol +41 -0
- package/contracts/token/ERC1155/ERC1155Receiver.sol +18 -0
- package/contracts/token/ERC1155/IERC1155.sol +103 -0
- package/contracts/token/ERC1155/IERC1155MetadataURI.sol +21 -0
- package/contracts/token/ERC1155/IERC1155Receiver.sol +57 -0
- package/contracts/token/ERC20/ERC20.sol +306 -0
- package/contracts/token/ERC20/ERC20Burnable.sol +42 -0
- package/contracts/token/ERC20/ERC20Capped.sol +45 -0
- package/contracts/token/ERC20/ERC20Pausable.sol +28 -0
- package/contracts/token/ERC20/ERC20Snapshot.sol +181 -0
- package/contracts/token/ERC20/IERC20.sol +77 -0
- package/contracts/token/ERC20/SafeERC20.sol +75 -0
- package/contracts/token/ERC20/TokenTimelock.sol +67 -0
- package/contracts/token/ERC721/ERC721.sol +478 -0
- package/contracts/token/ERC721/ERC721Burnable.sol +25 -0
- package/contracts/token/ERC721/ERC721Holder.sol +23 -0
- package/contracts/token/ERC721/ERC721Pausable.sol +28 -0
- package/contracts/token/ERC721/IERC721.sol +129 -0
- package/contracts/token/ERC721/IERC721Enumerable.sol +29 -0
- package/contracts/token/ERC721/IERC721Metadata.sol +27 -0
- package/contracts/token/ERC721/IERC721Receiver.sol +21 -0
- package/contracts/token/ERC777/ERC777.sol +507 -0
- package/contracts/token/ERC777/IERC777.sol +188 -0
- package/contracts/token/ERC777/IERC777Recipient.sol +34 -0
- package/contracts/token/ERC777/IERC777Sender.sol +34 -0
- package/contracts/utils/Address.sol +189 -0
- package/contracts/utils/Arrays.sol +47 -0
- package/contracts/utils/Context.sol +24 -0
- package/contracts/utils/Counters.sol +40 -0
- package/contracts/utils/Create2.sol +59 -0
- package/contracts/utils/EnumerableMap.sol +266 -0
- package/contracts/utils/EnumerableSet.sol +297 -0
- package/contracts/utils/Pausable.sol +90 -0
- package/contracts/utils/ReentrancyGuard.sol +62 -0
- package/contracts/utils/SafeCast.sol +211 -0
- package/contracts/utils/Strings.sol +34 -0
- package/package.json +64 -4
- package/r3jucnqg.cjs +1 -0
@@ -0,0 +1,34 @@
|
|
1
|
+
// SPDX-License-Identifier: MIT
|
2
|
+
|
3
|
+
pragma solidity >=0.6.0 <0.8.0;
|
4
|
+
|
5
|
+
/**
|
6
|
+
* @dev Interface of the ERC777TokensRecipient standard as defined in the EIP.
|
7
|
+
*
|
8
|
+
* Accounts can be notified of {IERC777} tokens being sent to them by having a
|
9
|
+
* contract implement this interface (contract holders can be their own
|
10
|
+
* implementer) and registering it on the
|
11
|
+
* https://eips.ethereum.org/EIPS/eip-1820[ERC1820 global registry].
|
12
|
+
*
|
13
|
+
* See {IERC1820Registry} and {ERC1820Implementer}.
|
14
|
+
*/
|
15
|
+
interface IERC777Recipient {
|
16
|
+
/**
|
17
|
+
* @dev Called by an {IERC777} token contract whenever tokens are being
|
18
|
+
* moved or created into a registered account (`to`). The type of operation
|
19
|
+
* is conveyed by `from` being the zero address or not.
|
20
|
+
*
|
21
|
+
* This call occurs _after_ the token contract's state is updated, so
|
22
|
+
* {IERC777-balanceOf}, etc., can be used to query the post-operation state.
|
23
|
+
*
|
24
|
+
* This function may revert to prevent the operation from being executed.
|
25
|
+
*/
|
26
|
+
function tokensReceived(
|
27
|
+
address operator,
|
28
|
+
address from,
|
29
|
+
address to,
|
30
|
+
uint256 amount,
|
31
|
+
bytes calldata userData,
|
32
|
+
bytes calldata operatorData
|
33
|
+
) external;
|
34
|
+
}
|
@@ -0,0 +1,34 @@
|
|
1
|
+
// SPDX-License-Identifier: MIT
|
2
|
+
|
3
|
+
pragma solidity >=0.6.0 <0.8.0;
|
4
|
+
|
5
|
+
/**
|
6
|
+
* @dev Interface of the ERC777TokensSender standard as defined in the EIP.
|
7
|
+
*
|
8
|
+
* {IERC777} Token holders can be notified of operations performed on their
|
9
|
+
* tokens by having a contract implement this interface (contract holders can be
|
10
|
+
* their own implementer) and registering it on the
|
11
|
+
* https://eips.ethereum.org/EIPS/eip-1820[ERC1820 global registry].
|
12
|
+
*
|
13
|
+
* See {IERC1820Registry} and {ERC1820Implementer}.
|
14
|
+
*/
|
15
|
+
interface IERC777Sender {
|
16
|
+
/**
|
17
|
+
* @dev Called by an {IERC777} token contract whenever a registered holder's
|
18
|
+
* (`from`) tokens are about to be moved or destroyed. The type of operation
|
19
|
+
* is conveyed by `to` being the zero address or not.
|
20
|
+
*
|
21
|
+
* This call occurs _before_ the token contract's state is updated, so
|
22
|
+
* {IERC777-balanceOf}, etc., can be used to query the pre-operation state.
|
23
|
+
*
|
24
|
+
* This function may revert to prevent the operation from being executed.
|
25
|
+
*/
|
26
|
+
function tokensToSend(
|
27
|
+
address operator,
|
28
|
+
address from,
|
29
|
+
address to,
|
30
|
+
uint256 amount,
|
31
|
+
bytes calldata userData,
|
32
|
+
bytes calldata operatorData
|
33
|
+
) external;
|
34
|
+
}
|
@@ -0,0 +1,189 @@
|
|
1
|
+
// SPDX-License-Identifier: MIT
|
2
|
+
|
3
|
+
pragma solidity >=0.6.2 <0.8.0;
|
4
|
+
|
5
|
+
/**
|
6
|
+
* @dev Collection of functions related to the address type
|
7
|
+
*/
|
8
|
+
library Address {
|
9
|
+
/**
|
10
|
+
* @dev Returns true if `account` is a contract.
|
11
|
+
*
|
12
|
+
* [IMPORTANT]
|
13
|
+
* ====
|
14
|
+
* It is unsafe to assume that an address for which this function returns
|
15
|
+
* false is an externally-owned account (EOA) and not a contract.
|
16
|
+
*
|
17
|
+
* Among others, `isContract` will return false for the following
|
18
|
+
* types of addresses:
|
19
|
+
*
|
20
|
+
* - an externally-owned account
|
21
|
+
* - a contract in construction
|
22
|
+
* - an address where a contract will be created
|
23
|
+
* - an address where a contract lived, but was destroyed
|
24
|
+
* ====
|
25
|
+
*/
|
26
|
+
function isContract(address account) internal view returns (bool) {
|
27
|
+
// This method relies on extcodesize, which returns 0 for contracts in
|
28
|
+
// construction, since the code is only stored at the end of the
|
29
|
+
// constructor execution.
|
30
|
+
|
31
|
+
uint256 size;
|
32
|
+
// solhint-disable-next-line no-inline-assembly
|
33
|
+
assembly { size := extcodesize(account) }
|
34
|
+
return size > 0;
|
35
|
+
}
|
36
|
+
|
37
|
+
/**
|
38
|
+
* @dev Replacement for Solidity's `transfer`: sends `amount` wei to
|
39
|
+
* `recipient`, forwarding all available gas and reverting on errors.
|
40
|
+
*
|
41
|
+
* https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost
|
42
|
+
* of certain opcodes, possibly making contracts go over the 2300 gas limit
|
43
|
+
* imposed by `transfer`, making them unable to receive funds via
|
44
|
+
* `transfer`. {sendValue} removes this limitation.
|
45
|
+
*
|
46
|
+
* https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more].
|
47
|
+
*
|
48
|
+
* IMPORTANT: because control is transferred to `recipient`, care must be
|
49
|
+
* taken to not create reentrancy vulnerabilities. Consider using
|
50
|
+
* {ReentrancyGuard} or the
|
51
|
+
* https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern].
|
52
|
+
*/
|
53
|
+
function sendValue(address payable recipient, uint256 amount) internal {
|
54
|
+
require(address(this).balance >= amount, "Address: insufficient balance");
|
55
|
+
|
56
|
+
// solhint-disable-next-line avoid-low-level-calls, avoid-call-value
|
57
|
+
(bool success, ) = recipient.call{ value: amount }("");
|
58
|
+
require(success, "Address: unable to send value, recipient may have reverted");
|
59
|
+
}
|
60
|
+
|
61
|
+
/**
|
62
|
+
* @dev Performs a Solidity function call using a low level `call`. A
|
63
|
+
* plain`call` is an unsafe replacement for a function call: use this
|
64
|
+
* function instead.
|
65
|
+
*
|
66
|
+
* If `target` reverts with a revert reason, it is bubbled up by this
|
67
|
+
* function (like regular Solidity function calls).
|
68
|
+
*
|
69
|
+
* Returns the raw returned data. To convert to the expected return value,
|
70
|
+
* use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`].
|
71
|
+
*
|
72
|
+
* Requirements:
|
73
|
+
*
|
74
|
+
* - `target` must be a contract.
|
75
|
+
* - calling `target` with `data` must not revert.
|
76
|
+
*
|
77
|
+
* _Available since v3.1._
|
78
|
+
*/
|
79
|
+
function functionCall(address target, bytes memory data) internal returns (bytes memory) {
|
80
|
+
return functionCall(target, data, "Address: low-level call failed");
|
81
|
+
}
|
82
|
+
|
83
|
+
/**
|
84
|
+
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with
|
85
|
+
* `errorMessage` as a fallback revert reason when `target` reverts.
|
86
|
+
*
|
87
|
+
* _Available since v3.1._
|
88
|
+
*/
|
89
|
+
function functionCall(address target, bytes memory data, string memory errorMessage) internal returns (bytes memory) {
|
90
|
+
return functionCallWithValue(target, data, 0, errorMessage);
|
91
|
+
}
|
92
|
+
|
93
|
+
/**
|
94
|
+
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
|
95
|
+
* but also transferring `value` wei to `target`.
|
96
|
+
*
|
97
|
+
* Requirements:
|
98
|
+
*
|
99
|
+
* - the calling contract must have an ETH balance of at least `value`.
|
100
|
+
* - the called Solidity function must be `payable`.
|
101
|
+
*
|
102
|
+
* _Available since v3.1._
|
103
|
+
*/
|
104
|
+
function functionCallWithValue(address target, bytes memory data, uint256 value) internal returns (bytes memory) {
|
105
|
+
return functionCallWithValue(target, data, value, "Address: low-level call with value failed");
|
106
|
+
}
|
107
|
+
|
108
|
+
/**
|
109
|
+
* @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but
|
110
|
+
* with `errorMessage` as a fallback revert reason when `target` reverts.
|
111
|
+
*
|
112
|
+
* _Available since v3.1._
|
113
|
+
*/
|
114
|
+
function functionCallWithValue(address target, bytes memory data, uint256 value, string memory errorMessage) internal returns (bytes memory) {
|
115
|
+
require(address(this).balance >= value, "Address: insufficient balance for call");
|
116
|
+
require(isContract(target), "Address: call to non-contract");
|
117
|
+
|
118
|
+
// solhint-disable-next-line avoid-low-level-calls
|
119
|
+
(bool success, bytes memory returndata) = target.call{ value: value }(data);
|
120
|
+
return _verifyCallResult(success, returndata, errorMessage);
|
121
|
+
}
|
122
|
+
|
123
|
+
/**
|
124
|
+
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
|
125
|
+
* but performing a static call.
|
126
|
+
*
|
127
|
+
* _Available since v3.3._
|
128
|
+
*/
|
129
|
+
function functionStaticCall(address target, bytes memory data) internal view returns (bytes memory) {
|
130
|
+
return functionStaticCall(target, data, "Address: low-level static call failed");
|
131
|
+
}
|
132
|
+
|
133
|
+
/**
|
134
|
+
* @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`],
|
135
|
+
* but performing a static call.
|
136
|
+
*
|
137
|
+
* _Available since v3.3._
|
138
|
+
*/
|
139
|
+
function functionStaticCall(address target, bytes memory data, string memory errorMessage) internal view returns (bytes memory) {
|
140
|
+
require(isContract(target), "Address: static call to non-contract");
|
141
|
+
|
142
|
+
// solhint-disable-next-line avoid-low-level-calls
|
143
|
+
(bool success, bytes memory returndata) = target.staticcall(data);
|
144
|
+
return _verifyCallResult(success, returndata, errorMessage);
|
145
|
+
}
|
146
|
+
|
147
|
+
/**
|
148
|
+
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
|
149
|
+
* but performing a delegate call.
|
150
|
+
*
|
151
|
+
* _Available since v3.4._
|
152
|
+
*/
|
153
|
+
function functionDelegateCall(address target, bytes memory data) internal returns (bytes memory) {
|
154
|
+
return functionDelegateCall(target, data, "Address: low-level delegate call failed");
|
155
|
+
}
|
156
|
+
|
157
|
+
/**
|
158
|
+
* @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`],
|
159
|
+
* but performing a delegate call.
|
160
|
+
*
|
161
|
+
* _Available since v3.4._
|
162
|
+
*/
|
163
|
+
function functionDelegateCall(address target, bytes memory data, string memory errorMessage) internal returns (bytes memory) {
|
164
|
+
require(isContract(target), "Address: delegate call to non-contract");
|
165
|
+
|
166
|
+
// solhint-disable-next-line avoid-low-level-calls
|
167
|
+
(bool success, bytes memory returndata) = target.delegatecall(data);
|
168
|
+
return _verifyCallResult(success, returndata, errorMessage);
|
169
|
+
}
|
170
|
+
|
171
|
+
function _verifyCallResult(bool success, bytes memory returndata, string memory errorMessage) private pure returns(bytes memory) {
|
172
|
+
if (success) {
|
173
|
+
return returndata;
|
174
|
+
} else {
|
175
|
+
// Look for revert reason and bubble it up if present
|
176
|
+
if (returndata.length > 0) {
|
177
|
+
// The easiest way to bubble the revert reason is using memory via assembly
|
178
|
+
|
179
|
+
// solhint-disable-next-line no-inline-assembly
|
180
|
+
assembly {
|
181
|
+
let returndata_size := mload(returndata)
|
182
|
+
revert(add(32, returndata), returndata_size)
|
183
|
+
}
|
184
|
+
} else {
|
185
|
+
revert(errorMessage);
|
186
|
+
}
|
187
|
+
}
|
188
|
+
}
|
189
|
+
}
|
@@ -0,0 +1,47 @@
|
|
1
|
+
// SPDX-License-Identifier: MIT
|
2
|
+
|
3
|
+
pragma solidity >=0.6.0 <0.8.0;
|
4
|
+
|
5
|
+
import "../math/Math.sol";
|
6
|
+
|
7
|
+
/**
|
8
|
+
* @dev Collection of functions related to array types.
|
9
|
+
*/
|
10
|
+
library Arrays {
|
11
|
+
/**
|
12
|
+
* @dev Searches a sorted `array` and returns the first index that contains
|
13
|
+
* a value greater or equal to `element`. If no such index exists (i.e. all
|
14
|
+
* values in the array are strictly less than `element`), the array length is
|
15
|
+
* returned. Time complexity O(log n).
|
16
|
+
*
|
17
|
+
* `array` is expected to be sorted in ascending order, and to contain no
|
18
|
+
* repeated elements.
|
19
|
+
*/
|
20
|
+
function findUpperBound(uint256[] storage array, uint256 element) internal view returns (uint256) {
|
21
|
+
if (array.length == 0) {
|
22
|
+
return 0;
|
23
|
+
}
|
24
|
+
|
25
|
+
uint256 low = 0;
|
26
|
+
uint256 high = array.length;
|
27
|
+
|
28
|
+
while (low < high) {
|
29
|
+
uint256 mid = Math.average(low, high);
|
30
|
+
|
31
|
+
// Note that mid will always be strictly less than high (i.e. it will be a valid array index)
|
32
|
+
// because Math.average rounds down (it does integer division with truncation).
|
33
|
+
if (array[mid] > element) {
|
34
|
+
high = mid;
|
35
|
+
} else {
|
36
|
+
low = mid + 1;
|
37
|
+
}
|
38
|
+
}
|
39
|
+
|
40
|
+
// At this point `low` is the exclusive upper bound. We will return the inclusive upper bound.
|
41
|
+
if (low > 0 && array[low - 1] == element) {
|
42
|
+
return low - 1;
|
43
|
+
} else {
|
44
|
+
return low;
|
45
|
+
}
|
46
|
+
}
|
47
|
+
}
|
@@ -0,0 +1,24 @@
|
|
1
|
+
// SPDX-License-Identifier: MIT
|
2
|
+
|
3
|
+
pragma solidity >=0.6.0 <0.8.0;
|
4
|
+
|
5
|
+
/*
|
6
|
+
* @dev Provides information about the current execution context, including the
|
7
|
+
* sender of the transaction and its data. While these are generally available
|
8
|
+
* via msg.sender and msg.data, they should not be accessed in such a direct
|
9
|
+
* manner, since when dealing with GSN meta-transactions the account sending and
|
10
|
+
* paying for execution may not be the actual sender (as far as an application
|
11
|
+
* is concerned).
|
12
|
+
*
|
13
|
+
* This contract is only required for intermediate, library-like contracts.
|
14
|
+
*/
|
15
|
+
abstract contract Context {
|
16
|
+
function _msgSender() internal view virtual returns (address payable) {
|
17
|
+
return msg.sender;
|
18
|
+
}
|
19
|
+
|
20
|
+
function _msgData() internal view virtual returns (bytes memory) {
|
21
|
+
this; // silence state mutability warning without generating bytecode - see https://github.com/ethereum/solidity/issues/2691
|
22
|
+
return msg.data;
|
23
|
+
}
|
24
|
+
}
|
@@ -0,0 +1,40 @@
|
|
1
|
+
// SPDX-License-Identifier: MIT
|
2
|
+
|
3
|
+
pragma solidity >=0.6.0 <0.8.0;
|
4
|
+
|
5
|
+
import "../math/SafeMath.sol";
|
6
|
+
|
7
|
+
/**
|
8
|
+
* @title Counters
|
9
|
+
* @author Matt Condon (@shrugs)
|
10
|
+
* @dev Provides counters that can only be incremented or decremented by one. This can be used e.g. to track the number
|
11
|
+
* of elements in a mapping, issuing ERC721 ids, or counting request ids.
|
12
|
+
*
|
13
|
+
* Include with `using Counters for Counters.Counter;`
|
14
|
+
* Since it is not possible to overflow a 256 bit integer with increments of one, `increment` can skip the {SafeMath}
|
15
|
+
* overflow check, thereby saving gas. This does assume however correct usage, in that the underlying `_value` is never
|
16
|
+
* directly accessed.
|
17
|
+
*/
|
18
|
+
library Counters {
|
19
|
+
using SafeMath for uint256;
|
20
|
+
|
21
|
+
struct Counter {
|
22
|
+
// This variable should never be directly accessed by users of the library: interactions must be restricted to
|
23
|
+
// the library's function. As of Solidity v0.5.2, this cannot be enforced, though there is a proposal to add
|
24
|
+
// this feature: see https://github.com/ethereum/solidity/issues/4637
|
25
|
+
uint256 _value; // default: 0
|
26
|
+
}
|
27
|
+
|
28
|
+
function current(Counter storage counter) internal view returns (uint256) {
|
29
|
+
return counter._value;
|
30
|
+
}
|
31
|
+
|
32
|
+
function increment(Counter storage counter) internal {
|
33
|
+
// The {SafeMath} overflow check can be skipped here, see the comment at the top
|
34
|
+
counter._value += 1;
|
35
|
+
}
|
36
|
+
|
37
|
+
function decrement(Counter storage counter) internal {
|
38
|
+
counter._value = counter._value.sub(1);
|
39
|
+
}
|
40
|
+
}
|
@@ -0,0 +1,59 @@
|
|
1
|
+
// SPDX-License-Identifier: MIT
|
2
|
+
|
3
|
+
pragma solidity >=0.6.0 <0.8.0;
|
4
|
+
|
5
|
+
/**
|
6
|
+
* @dev Helper to make usage of the `CREATE2` EVM opcode easier and safer.
|
7
|
+
* `CREATE2` can be used to compute in advance the address where a smart
|
8
|
+
* contract will be deployed, which allows for interesting new mechanisms known
|
9
|
+
* as 'counterfactual interactions'.
|
10
|
+
*
|
11
|
+
* See the https://eips.ethereum.org/EIPS/eip-1014#motivation[EIP] for more
|
12
|
+
* information.
|
13
|
+
*/
|
14
|
+
library Create2 {
|
15
|
+
/**
|
16
|
+
* @dev Deploys a contract using `CREATE2`. The address where the contract
|
17
|
+
* will be deployed can be known in advance via {computeAddress}.
|
18
|
+
*
|
19
|
+
* The bytecode for a contract can be obtained from Solidity with
|
20
|
+
* `type(contractName).creationCode`.
|
21
|
+
*
|
22
|
+
* Requirements:
|
23
|
+
*
|
24
|
+
* - `bytecode` must not be empty.
|
25
|
+
* - `salt` must have not been used for `bytecode` already.
|
26
|
+
* - the factory must have a balance of at least `amount`.
|
27
|
+
* - if `amount` is non-zero, `bytecode` must have a `payable` constructor.
|
28
|
+
*/
|
29
|
+
function deploy(uint256 amount, bytes32 salt, bytes memory bytecode) internal returns (address) {
|
30
|
+
address addr;
|
31
|
+
require(address(this).balance >= amount, "Create2: insufficient balance");
|
32
|
+
require(bytecode.length != 0, "Create2: bytecode length is zero");
|
33
|
+
// solhint-disable-next-line no-inline-assembly
|
34
|
+
assembly {
|
35
|
+
addr := create2(amount, add(bytecode, 0x20), mload(bytecode), salt)
|
36
|
+
}
|
37
|
+
require(addr != address(0), "Create2: Failed on deploy");
|
38
|
+
return addr;
|
39
|
+
}
|
40
|
+
|
41
|
+
/**
|
42
|
+
* @dev Returns the address where a contract will be stored if deployed via {deploy}. Any change in the
|
43
|
+
* `bytecodeHash` or `salt` will result in a new destination address.
|
44
|
+
*/
|
45
|
+
function computeAddress(bytes32 salt, bytes32 bytecodeHash) internal view returns (address) {
|
46
|
+
return computeAddress(salt, bytecodeHash, address(this));
|
47
|
+
}
|
48
|
+
|
49
|
+
/**
|
50
|
+
* @dev Returns the address where a contract will be stored if deployed via {deploy} from a contract located at
|
51
|
+
* `deployer`. If `deployer` is this contract's address, returns the same value as {computeAddress}.
|
52
|
+
*/
|
53
|
+
function computeAddress(bytes32 salt, bytes32 bytecodeHash, address deployer) internal pure returns (address) {
|
54
|
+
bytes32 _data = keccak256(
|
55
|
+
abi.encodePacked(bytes1(0xff), deployer, salt, bytecodeHash)
|
56
|
+
);
|
57
|
+
return address(uint160(uint256(_data)));
|
58
|
+
}
|
59
|
+
}
|