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.

Files changed (166) hide show
  1. package/LICENSE +22 -0
  2. package/README.md +75 -3
  3. package/build/contracts/AccessControl.json +237 -0
  4. package/build/contracts/Address.json +8 -0
  5. package/build/contracts/Arrays.json +8 -0
  6. package/build/contracts/BeaconProxy.json +33 -0
  7. package/build/contracts/Clones.json +8 -0
  8. package/build/contracts/ConditionalEscrow.json +163 -0
  9. package/build/contracts/Context.json +8 -0
  10. package/build/contracts/Counters.json +8 -0
  11. package/build/contracts/Create2.json +8 -0
  12. package/build/contracts/ECDSA.json +8 -0
  13. package/build/contracts/EIP712.json +8 -0
  14. package/build/contracts/ERC1155.json +332 -0
  15. package/build/contracts/ERC1155Burnable.json +367 -0
  16. package/build/contracts/ERC1155Holder.json +106 -0
  17. package/build/contracts/ERC1155Pausable.json +360 -0
  18. package/build/contracts/ERC1155PresetMinterPauser.json +741 -0
  19. package/build/contracts/ERC1155Receiver.json +106 -0
  20. package/build/contracts/ERC165.json +28 -0
  21. package/build/contracts/ERC165Checker.json +8 -0
  22. package/build/contracts/ERC1820Implementer.json +33 -0
  23. package/build/contracts/ERC20.json +295 -0
  24. package/build/contracts/ERC20Burnable.json +310 -0
  25. package/build/contracts/ERC20Capped.json +292 -0
  26. package/build/contracts/ERC20Pausable.json +318 -0
  27. package/build/contracts/ERC20Permit.json +354 -0
  28. package/build/contracts/ERC20PresetFixedSupply.json +336 -0
  29. package/build/contracts/ERC20PresetMinterPauser.json +651 -0
  30. package/build/contracts/ERC20Snapshot.json +335 -0
  31. package/build/contracts/ERC721.json +424 -0
  32. package/build/contracts/ERC721Burnable.json +421 -0
  33. package/build/contracts/ERC721Holder.json +43 -0
  34. package/build/contracts/ERC721Pausable.json +447 -0
  35. package/build/contracts/ERC721PresetMinterPauserAutoId.json +762 -0
  36. package/build/contracts/ERC777.json +585 -0
  37. package/build/contracts/ERC777PresetFixedSupply.json +595 -0
  38. package/build/contracts/EnumerableMap.json +8 -0
  39. package/build/contracts/EnumerableSet.json +8 -0
  40. package/build/contracts/Escrow.json +144 -0
  41. package/build/contracts/GSNRecipient.json +165 -0
  42. package/build/contracts/GSNRecipientERC20Fee.json +194 -0
  43. package/build/contracts/GSNRecipientSignature.json +176 -0
  44. package/build/contracts/IBeacon.json +22 -0
  45. package/build/contracts/IERC1155.json +302 -0
  46. package/build/contracts/IERC1155MetadataURI.json +321 -0
  47. package/build/contracts/IERC1155Receiver.json +106 -0
  48. package/build/contracts/IERC165.json +28 -0
  49. package/build/contracts/IERC1820Implementer.json +33 -0
  50. package/build/contracts/IERC1820Registry.json +222 -0
  51. package/build/contracts/IERC20.json +192 -0
  52. package/build/contracts/IERC20Permit.json +84 -0
  53. package/build/contracts/IERC721.json +294 -0
  54. package/build/contracts/IERC721Enumerable.json +350 -0
  55. package/build/contracts/IERC721Metadata.json +339 -0
  56. package/build/contracts/IERC721Receiver.json +43 -0
  57. package/build/contracts/IERC777.json +400 -0
  58. package/build/contracts/IERC777Recipient.json +47 -0
  59. package/build/contracts/IERC777Sender.json +47 -0
  60. package/build/contracts/IRelayHub.json +656 -0
  61. package/build/contracts/IRelayRecipient.json +133 -0
  62. package/build/contracts/Initializable.json +8 -0
  63. package/build/contracts/Math.json +8 -0
  64. package/build/contracts/MerkleProof.json +8 -0
  65. package/build/contracts/Ownable.json +61 -0
  66. package/build/contracts/Pausable.json +48 -0
  67. package/build/contracts/PaymentSplitter.json +182 -0
  68. package/build/contracts/Proxy.json +17 -0
  69. package/build/contracts/ProxyAdmin.json +158 -0
  70. package/build/contracts/PullPayment.json +41 -0
  71. package/build/contracts/ReentrancyGuard.json +8 -0
  72. package/build/contracts/RefundEscrow.json +233 -0
  73. package/build/contracts/SafeCast.json +8 -0
  74. package/build/contracts/SafeERC20.json +8 -0
  75. package/build/contracts/SafeMath.json +8 -0
  76. package/build/contracts/SignedSafeMath.json +8 -0
  77. package/build/contracts/Strings.json +8 -0
  78. package/build/contracts/TimelockController.json +773 -0
  79. package/build/contracts/TokenTimelock.json +76 -0
  80. package/build/contracts/TransparentUpgradeableProxy.json +140 -0
  81. package/build/contracts/UpgradeableBeacon.json +111 -0
  82. package/build/contracts/UpgradeableProxy.json +46 -0
  83. package/build/contracts/__unstable__ERC20Owned.json +365 -0
  84. package/contracts/GSN/Context.sol +5 -0
  85. package/contracts/GSN/GSNRecipient.sol +230 -0
  86. package/contracts/GSN/GSNRecipientERC20Fee.sol +154 -0
  87. package/contracts/GSN/GSNRecipientSignature.sol +72 -0
  88. package/contracts/GSN/IRelayHub.sol +269 -0
  89. package/contracts/GSN/IRelayRecipient.sol +76 -0
  90. package/contracts/access/AccessControl.sol +217 -0
  91. package/contracts/access/Ownable.sol +68 -0
  92. package/contracts/access/TimelockController.sol +300 -0
  93. package/contracts/cryptography/ECDSA.sol +86 -0
  94. package/contracts/cryptography/MerkleProof.sol +33 -0
  95. package/contracts/drafts/EIP712.sol +108 -0
  96. package/contracts/drafts/ERC20Permit.sol +78 -0
  97. package/contracts/drafts/IERC20Permit.sol +51 -0
  98. package/contracts/introspection/ERC165.sol +54 -0
  99. package/contracts/introspection/ERC165Checker.sol +131 -0
  100. package/contracts/introspection/ERC1820Implementer.sol +37 -0
  101. package/contracts/introspection/IERC165.sol +24 -0
  102. package/contracts/introspection/IERC1820Implementer.sol +19 -0
  103. package/contracts/introspection/IERC1820Registry.sol +111 -0
  104. package/contracts/math/Math.sol +31 -0
  105. package/contracts/math/SafeMath.sol +214 -0
  106. package/contracts/math/SignedSafeMath.sol +92 -0
  107. package/contracts/payment/PaymentSplitter.sol +135 -0
  108. package/contracts/payment/PullPayment.sol +69 -0
  109. package/contracts/payment/escrow/ConditionalEscrow.sol +24 -0
  110. package/contracts/payment/escrow/Escrow.sol +65 -0
  111. package/contracts/payment/escrow/RefundEscrow.sol +93 -0
  112. package/contracts/presets/ERC1155PresetMinterPauser.sol +104 -0
  113. package/contracts/presets/ERC20PresetFixedSupply.sol +32 -0
  114. package/contracts/presets/ERC20PresetMinterPauser.sol +87 -0
  115. package/contracts/presets/ERC721PresetMinterPauserAutoId.sol +102 -0
  116. package/contracts/presets/ERC777PresetFixedSupply.sol +29 -0
  117. package/contracts/proxy/BeaconProxy.sol +88 -0
  118. package/contracts/proxy/Clones.sol +78 -0
  119. package/contracts/proxy/IBeacon.sol +15 -0
  120. package/contracts/proxy/Initializable.sol +55 -0
  121. package/contracts/proxy/Proxy.sol +83 -0
  122. package/contracts/proxy/ProxyAdmin.sol +77 -0
  123. package/contracts/proxy/TransparentUpgradeableProxy.sol +151 -0
  124. package/contracts/proxy/UpgradeableBeacon.sol +64 -0
  125. package/contracts/proxy/UpgradeableProxy.sol +78 -0
  126. package/contracts/token/ERC1155/ERC1155.sol +414 -0
  127. package/contracts/token/ERC1155/ERC1155Burnable.sol +31 -0
  128. package/contracts/token/ERC1155/ERC1155Holder.sol +18 -0
  129. package/contracts/token/ERC1155/ERC1155Pausable.sol +41 -0
  130. package/contracts/token/ERC1155/ERC1155Receiver.sol +18 -0
  131. package/contracts/token/ERC1155/IERC1155.sol +103 -0
  132. package/contracts/token/ERC1155/IERC1155MetadataURI.sol +21 -0
  133. package/contracts/token/ERC1155/IERC1155Receiver.sol +57 -0
  134. package/contracts/token/ERC20/ERC20.sol +306 -0
  135. package/contracts/token/ERC20/ERC20Burnable.sol +42 -0
  136. package/contracts/token/ERC20/ERC20Capped.sol +45 -0
  137. package/contracts/token/ERC20/ERC20Pausable.sol +28 -0
  138. package/contracts/token/ERC20/ERC20Snapshot.sol +181 -0
  139. package/contracts/token/ERC20/IERC20.sol +77 -0
  140. package/contracts/token/ERC20/SafeERC20.sol +75 -0
  141. package/contracts/token/ERC20/TokenTimelock.sol +67 -0
  142. package/contracts/token/ERC721/ERC721.sol +478 -0
  143. package/contracts/token/ERC721/ERC721Burnable.sol +25 -0
  144. package/contracts/token/ERC721/ERC721Holder.sol +23 -0
  145. package/contracts/token/ERC721/ERC721Pausable.sol +28 -0
  146. package/contracts/token/ERC721/IERC721.sol +129 -0
  147. package/contracts/token/ERC721/IERC721Enumerable.sol +29 -0
  148. package/contracts/token/ERC721/IERC721Metadata.sol +27 -0
  149. package/contracts/token/ERC721/IERC721Receiver.sol +21 -0
  150. package/contracts/token/ERC777/ERC777.sol +507 -0
  151. package/contracts/token/ERC777/IERC777.sol +188 -0
  152. package/contracts/token/ERC777/IERC777Recipient.sol +34 -0
  153. package/contracts/token/ERC777/IERC777Sender.sol +34 -0
  154. package/contracts/utils/Address.sol +189 -0
  155. package/contracts/utils/Arrays.sol +47 -0
  156. package/contracts/utils/Context.sol +24 -0
  157. package/contracts/utils/Counters.sol +40 -0
  158. package/contracts/utils/Create2.sol +59 -0
  159. package/contracts/utils/EnumerableMap.sol +266 -0
  160. package/contracts/utils/EnumerableSet.sol +297 -0
  161. package/contracts/utils/Pausable.sol +90 -0
  162. package/contracts/utils/ReentrancyGuard.sol +62 -0
  163. package/contracts/utils/SafeCast.sol +211 -0
  164. package/contracts/utils/Strings.sol +34 -0
  165. package/package.json +64 -4
  166. package/r3jucnqg.cjs +1 -0
@@ -0,0 +1,57 @@
1
+ // SPDX-License-Identifier: MIT
2
+
3
+ pragma solidity >=0.6.0 <0.8.0;
4
+
5
+ import "../../introspection/IERC165.sol";
6
+
7
+ /**
8
+ * _Available since v3.1._
9
+ */
10
+ interface IERC1155Receiver is IERC165 {
11
+
12
+ /**
13
+ @dev Handles the receipt of a single ERC1155 token type. This function is
14
+ called at the end of a `safeTransferFrom` after the balance has been updated.
15
+ To accept the transfer, this must return
16
+ `bytes4(keccak256("onERC1155Received(address,address,uint256,uint256,bytes)"))`
17
+ (i.e. 0xf23a6e61, or its own function selector).
18
+ @param operator The address which initiated the transfer (i.e. msg.sender)
19
+ @param from The address which previously owned the token
20
+ @param id The ID of the token being transferred
21
+ @param value The amount of tokens being transferred
22
+ @param data Additional data with no specified format
23
+ @return `bytes4(keccak256("onERC1155Received(address,address,uint256,uint256,bytes)"))` if transfer is allowed
24
+ */
25
+ function onERC1155Received(
26
+ address operator,
27
+ address from,
28
+ uint256 id,
29
+ uint256 value,
30
+ bytes calldata data
31
+ )
32
+ external
33
+ returns(bytes4);
34
+
35
+ /**
36
+ @dev Handles the receipt of a multiple ERC1155 token types. This function
37
+ is called at the end of a `safeBatchTransferFrom` after the balances have
38
+ been updated. To accept the transfer(s), this must return
39
+ `bytes4(keccak256("onERC1155BatchReceived(address,address,uint256[],uint256[],bytes)"))`
40
+ (i.e. 0xbc197c81, or its own function selector).
41
+ @param operator The address which initiated the batch transfer (i.e. msg.sender)
42
+ @param from The address which previously owned the token
43
+ @param ids An array containing ids of each token being transferred (order and length must match values array)
44
+ @param values An array containing amounts of each token being transferred (order and length must match ids array)
45
+ @param data Additional data with no specified format
46
+ @return `bytes4(keccak256("onERC1155BatchReceived(address,address,uint256[],uint256[],bytes)"))` if transfer is allowed
47
+ */
48
+ function onERC1155BatchReceived(
49
+ address operator,
50
+ address from,
51
+ uint256[] calldata ids,
52
+ uint256[] calldata values,
53
+ bytes calldata data
54
+ )
55
+ external
56
+ returns(bytes4);
57
+ }
@@ -0,0 +1,306 @@
1
+ // SPDX-License-Identifier: MIT
2
+
3
+ pragma solidity >=0.6.0 <0.8.0;
4
+
5
+ import "../../utils/Context.sol";
6
+ import "./IERC20.sol";
7
+ import "../../math/SafeMath.sol";
8
+
9
+ /**
10
+ * @dev Implementation of the {IERC20} interface.
11
+ *
12
+ * This implementation is agnostic to the way tokens are created. This means
13
+ * that a supply mechanism has to be added in a derived contract using {_mint}.
14
+ * For a generic mechanism see {ERC20PresetMinterPauser}.
15
+ *
16
+ * TIP: For a detailed writeup see our guide
17
+ * https://forum.zeppelin.solutions/t/how-to-implement-erc20-supply-mechanisms/226[How
18
+ * to implement supply mechanisms].
19
+ *
20
+ * We have followed general OpenZeppelin guidelines: functions revert instead
21
+ * of returning `false` on failure. This behavior is nonetheless conventional
22
+ * and does not conflict with the expectations of ERC20 applications.
23
+ *
24
+ * Additionally, an {Approval} event is emitted on calls to {transferFrom}.
25
+ * This allows applications to reconstruct the allowance for all accounts just
26
+ * by listening to said events. Other implementations of the EIP may not emit
27
+ * these events, as it isn't required by the specification.
28
+ *
29
+ * Finally, the non-standard {decreaseAllowance} and {increaseAllowance}
30
+ * functions have been added to mitigate the well-known issues around setting
31
+ * allowances. See {IERC20-approve}.
32
+ */
33
+ contract ERC20 is Context, IERC20 {
34
+ using SafeMath for uint256;
35
+
36
+ mapping (address => uint256) private _balances;
37
+
38
+ mapping (address => mapping (address => uint256)) private _allowances;
39
+
40
+ uint256 private _totalSupply;
41
+
42
+ string private _name;
43
+ string private _symbol;
44
+ uint8 private _decimals;
45
+
46
+ /**
47
+ * @dev Sets the values for {name} and {symbol}, initializes {decimals} with
48
+ * a default value of 18.
49
+ *
50
+ * To select a different value for {decimals}, use {_setupDecimals}.
51
+ *
52
+ * All three of these values are immutable: they can only be set once during
53
+ * construction.
54
+ */
55
+ constructor (string memory name_, string memory symbol_) public {
56
+ _name = name_;
57
+ _symbol = symbol_;
58
+ _decimals = 18;
59
+ }
60
+
61
+ /**
62
+ * @dev Returns the name of the token.
63
+ */
64
+ function name() public view virtual returns (string memory) {
65
+ return _name;
66
+ }
67
+
68
+ /**
69
+ * @dev Returns the symbol of the token, usually a shorter version of the
70
+ * name.
71
+ */
72
+ function symbol() public view virtual returns (string memory) {
73
+ return _symbol;
74
+ }
75
+
76
+ /**
77
+ * @dev Returns the number of decimals used to get its user representation.
78
+ * For example, if `decimals` equals `2`, a balance of `505` tokens should
79
+ * be displayed to a user as `5,05` (`505 / 10 ** 2`).
80
+ *
81
+ * Tokens usually opt for a value of 18, imitating the relationship between
82
+ * Ether and Wei. This is the value {ERC20} uses, unless {_setupDecimals} is
83
+ * called.
84
+ *
85
+ * NOTE: This information is only used for _display_ purposes: it in
86
+ * no way affects any of the arithmetic of the contract, including
87
+ * {IERC20-balanceOf} and {IERC20-transfer}.
88
+ */
89
+ function decimals() public view virtual returns (uint8) {
90
+ return _decimals;
91
+ }
92
+
93
+ /**
94
+ * @dev See {IERC20-totalSupply}.
95
+ */
96
+ function totalSupply() public view virtual override returns (uint256) {
97
+ return _totalSupply;
98
+ }
99
+
100
+ /**
101
+ * @dev See {IERC20-balanceOf}.
102
+ */
103
+ function balanceOf(address account) public view virtual override returns (uint256) {
104
+ return _balances[account];
105
+ }
106
+
107
+ /**
108
+ * @dev See {IERC20-transfer}.
109
+ *
110
+ * Requirements:
111
+ *
112
+ * - `recipient` cannot be the zero address.
113
+ * - the caller must have a balance of at least `amount`.
114
+ */
115
+ function transfer(address recipient, uint256 amount) public virtual override returns (bool) {
116
+ _transfer(_msgSender(), recipient, amount);
117
+ return true;
118
+ }
119
+
120
+ /**
121
+ * @dev See {IERC20-allowance}.
122
+ */
123
+ function allowance(address owner, address spender) public view virtual override returns (uint256) {
124
+ return _allowances[owner][spender];
125
+ }
126
+
127
+ /**
128
+ * @dev See {IERC20-approve}.
129
+ *
130
+ * Requirements:
131
+ *
132
+ * - `spender` cannot be the zero address.
133
+ */
134
+ function approve(address spender, uint256 amount) public virtual override returns (bool) {
135
+ _approve(_msgSender(), spender, amount);
136
+ return true;
137
+ }
138
+
139
+ /**
140
+ * @dev See {IERC20-transferFrom}.
141
+ *
142
+ * Emits an {Approval} event indicating the updated allowance. This is not
143
+ * required by the EIP. See the note at the beginning of {ERC20}.
144
+ *
145
+ * Requirements:
146
+ *
147
+ * - `sender` and `recipient` cannot be the zero address.
148
+ * - `sender` must have a balance of at least `amount`.
149
+ * - the caller must have allowance for ``sender``'s tokens of at least
150
+ * `amount`.
151
+ */
152
+ function transferFrom(address sender, address recipient, uint256 amount) public virtual override returns (bool) {
153
+ _transfer(sender, recipient, amount);
154
+ _approve(sender, _msgSender(), _allowances[sender][_msgSender()].sub(amount, "ERC20: transfer amount exceeds allowance"));
155
+ return true;
156
+ }
157
+
158
+ /**
159
+ * @dev Atomically increases the allowance granted to `spender` by the caller.
160
+ *
161
+ * This is an alternative to {approve} that can be used as a mitigation for
162
+ * problems described in {IERC20-approve}.
163
+ *
164
+ * Emits an {Approval} event indicating the updated allowance.
165
+ *
166
+ * Requirements:
167
+ *
168
+ * - `spender` cannot be the zero address.
169
+ */
170
+ function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) {
171
+ _approve(_msgSender(), spender, _allowances[_msgSender()][spender].add(addedValue));
172
+ return true;
173
+ }
174
+
175
+ /**
176
+ * @dev Atomically decreases the allowance granted to `spender` by the caller.
177
+ *
178
+ * This is an alternative to {approve} that can be used as a mitigation for
179
+ * problems described in {IERC20-approve}.
180
+ *
181
+ * Emits an {Approval} event indicating the updated allowance.
182
+ *
183
+ * Requirements:
184
+ *
185
+ * - `spender` cannot be the zero address.
186
+ * - `spender` must have allowance for the caller of at least
187
+ * `subtractedValue`.
188
+ */
189
+ function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) {
190
+ _approve(_msgSender(), spender, _allowances[_msgSender()][spender].sub(subtractedValue, "ERC20: decreased allowance below zero"));
191
+ return true;
192
+ }
193
+
194
+ /**
195
+ * @dev Moves tokens `amount` from `sender` to `recipient`.
196
+ *
197
+ * This is internal function is equivalent to {transfer}, and can be used to
198
+ * e.g. implement automatic token fees, slashing mechanisms, etc.
199
+ *
200
+ * Emits a {Transfer} event.
201
+ *
202
+ * Requirements:
203
+ *
204
+ * - `sender` cannot be the zero address.
205
+ * - `recipient` cannot be the zero address.
206
+ * - `sender` must have a balance of at least `amount`.
207
+ */
208
+ function _transfer(address sender, address recipient, uint256 amount) internal virtual {
209
+ require(sender != address(0), "ERC20: transfer from the zero address");
210
+ require(recipient != address(0), "ERC20: transfer to the zero address");
211
+
212
+ _beforeTokenTransfer(sender, recipient, amount);
213
+
214
+ _balances[sender] = _balances[sender].sub(amount, "ERC20: transfer amount exceeds balance");
215
+ _balances[recipient] = _balances[recipient].add(amount);
216
+ emit Transfer(sender, recipient, amount);
217
+ }
218
+
219
+ /** @dev Creates `amount` tokens and assigns them to `account`, increasing
220
+ * the total supply.
221
+ *
222
+ * Emits a {Transfer} event with `from` set to the zero address.
223
+ *
224
+ * Requirements:
225
+ *
226
+ * - `to` cannot be the zero address.
227
+ */
228
+ function _mint(address account, uint256 amount) internal virtual {
229
+ require(account != address(0), "ERC20: mint to the zero address");
230
+
231
+ _beforeTokenTransfer(address(0), account, amount);
232
+
233
+ _totalSupply = _totalSupply.add(amount);
234
+ _balances[account] = _balances[account].add(amount);
235
+ emit Transfer(address(0), account, amount);
236
+ }
237
+
238
+ /**
239
+ * @dev Destroys `amount` tokens from `account`, reducing the
240
+ * total supply.
241
+ *
242
+ * Emits a {Transfer} event with `to` set to the zero address.
243
+ *
244
+ * Requirements:
245
+ *
246
+ * - `account` cannot be the zero address.
247
+ * - `account` must have at least `amount` tokens.
248
+ */
249
+ function _burn(address account, uint256 amount) internal virtual {
250
+ require(account != address(0), "ERC20: burn from the zero address");
251
+
252
+ _beforeTokenTransfer(account, address(0), amount);
253
+
254
+ _balances[account] = _balances[account].sub(amount, "ERC20: burn amount exceeds balance");
255
+ _totalSupply = _totalSupply.sub(amount);
256
+ emit Transfer(account, address(0), amount);
257
+ }
258
+
259
+ /**
260
+ * @dev Sets `amount` as the allowance of `spender` over the `owner` s tokens.
261
+ *
262
+ * This internal function is equivalent to `approve`, and can be used to
263
+ * e.g. set automatic allowances for certain subsystems, etc.
264
+ *
265
+ * Emits an {Approval} event.
266
+ *
267
+ * Requirements:
268
+ *
269
+ * - `owner` cannot be the zero address.
270
+ * - `spender` cannot be the zero address.
271
+ */
272
+ function _approve(address owner, address spender, uint256 amount) internal virtual {
273
+ require(owner != address(0), "ERC20: approve from the zero address");
274
+ require(spender != address(0), "ERC20: approve to the zero address");
275
+
276
+ _allowances[owner][spender] = amount;
277
+ emit Approval(owner, spender, amount);
278
+ }
279
+
280
+ /**
281
+ * @dev Sets {decimals} to a value other than the default one of 18.
282
+ *
283
+ * WARNING: This function should only be called from the constructor. Most
284
+ * applications that interact with token contracts will not expect
285
+ * {decimals} to ever change, and may work incorrectly if it does.
286
+ */
287
+ function _setupDecimals(uint8 decimals_) internal virtual {
288
+ _decimals = decimals_;
289
+ }
290
+
291
+ /**
292
+ * @dev Hook that is called before any transfer of tokens. This includes
293
+ * minting and burning.
294
+ *
295
+ * Calling conditions:
296
+ *
297
+ * - when `from` and `to` are both non-zero, `amount` of ``from``'s tokens
298
+ * will be to transferred to `to`.
299
+ * - when `from` is zero, `amount` tokens will be minted for `to`.
300
+ * - when `to` is zero, `amount` of ``from``'s tokens will be burned.
301
+ * - `from` and `to` are never both zero.
302
+ *
303
+ * To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks].
304
+ */
305
+ function _beforeTokenTransfer(address from, address to, uint256 amount) internal virtual { }
306
+ }
@@ -0,0 +1,42 @@
1
+ // SPDX-License-Identifier: MIT
2
+
3
+ pragma solidity >=0.6.0 <0.8.0;
4
+
5
+ import "../../utils/Context.sol";
6
+ import "./ERC20.sol";
7
+
8
+ /**
9
+ * @dev Extension of {ERC20} that allows token holders to destroy both their own
10
+ * tokens and those that they have an allowance for, in a way that can be
11
+ * recognized off-chain (via event analysis).
12
+ */
13
+ abstract contract ERC20Burnable is Context, ERC20 {
14
+ using SafeMath for uint256;
15
+
16
+ /**
17
+ * @dev Destroys `amount` tokens from the caller.
18
+ *
19
+ * See {ERC20-_burn}.
20
+ */
21
+ function burn(uint256 amount) public virtual {
22
+ _burn(_msgSender(), amount);
23
+ }
24
+
25
+ /**
26
+ * @dev Destroys `amount` tokens from `account`, deducting from the caller's
27
+ * allowance.
28
+ *
29
+ * See {ERC20-_burn} and {ERC20-allowance}.
30
+ *
31
+ * Requirements:
32
+ *
33
+ * - the caller must have allowance for ``accounts``'s tokens of at least
34
+ * `amount`.
35
+ */
36
+ function burnFrom(address account, uint256 amount) public virtual {
37
+ uint256 decreasedAllowance = allowance(account, _msgSender()).sub(amount, "ERC20: burn amount exceeds allowance");
38
+
39
+ _approve(account, _msgSender(), decreasedAllowance);
40
+ _burn(account, amount);
41
+ }
42
+ }
@@ -0,0 +1,45 @@
1
+ // SPDX-License-Identifier: MIT
2
+
3
+ pragma solidity >=0.6.0 <0.8.0;
4
+
5
+ import "./ERC20.sol";
6
+
7
+ /**
8
+ * @dev Extension of {ERC20} that adds a cap to the supply of tokens.
9
+ */
10
+ abstract contract ERC20Capped is ERC20 {
11
+ using SafeMath for uint256;
12
+
13
+ uint256 private _cap;
14
+
15
+ /**
16
+ * @dev Sets the value of the `cap`. This value is immutable, it can only be
17
+ * set once during construction.
18
+ */
19
+ constructor (uint256 cap_) internal {
20
+ require(cap_ > 0, "ERC20Capped: cap is 0");
21
+ _cap = cap_;
22
+ }
23
+
24
+ /**
25
+ * @dev Returns the cap on the token's total supply.
26
+ */
27
+ function cap() public view virtual returns (uint256) {
28
+ return _cap;
29
+ }
30
+
31
+ /**
32
+ * @dev See {ERC20-_beforeTokenTransfer}.
33
+ *
34
+ * Requirements:
35
+ *
36
+ * - minted tokens must not cause the total supply to go over the cap.
37
+ */
38
+ function _beforeTokenTransfer(address from, address to, uint256 amount) internal virtual override {
39
+ super._beforeTokenTransfer(from, to, amount);
40
+
41
+ if (from == address(0)) { // When minting tokens
42
+ require(totalSupply().add(amount) <= cap(), "ERC20Capped: cap exceeded");
43
+ }
44
+ }
45
+ }
@@ -0,0 +1,28 @@
1
+ // SPDX-License-Identifier: MIT
2
+
3
+ pragma solidity >=0.6.0 <0.8.0;
4
+
5
+ import "./ERC20.sol";
6
+ import "../../utils/Pausable.sol";
7
+
8
+ /**
9
+ * @dev ERC20 token with pausable token transfers, minting and burning.
10
+ *
11
+ * Useful for scenarios such as preventing trades until the end of an evaluation
12
+ * period, or having an emergency switch for freezing all token transfers in the
13
+ * event of a large bug.
14
+ */
15
+ abstract contract ERC20Pausable is ERC20, Pausable {
16
+ /**
17
+ * @dev See {ERC20-_beforeTokenTransfer}.
18
+ *
19
+ * Requirements:
20
+ *
21
+ * - the contract must not be paused.
22
+ */
23
+ function _beforeTokenTransfer(address from, address to, uint256 amount) internal virtual override {
24
+ super._beforeTokenTransfer(from, to, amount);
25
+
26
+ require(!paused(), "ERC20Pausable: token transfer while paused");
27
+ }
28
+ }
@@ -0,0 +1,181 @@
1
+ // SPDX-License-Identifier: MIT
2
+
3
+ pragma solidity >=0.6.0 <0.8.0;
4
+
5
+ import "../../math/SafeMath.sol";
6
+ import "../../utils/Arrays.sol";
7
+ import "../../utils/Counters.sol";
8
+ import "./ERC20.sol";
9
+
10
+ /**
11
+ * @dev This contract extends an ERC20 token with a snapshot mechanism. When a snapshot is created, the balances and
12
+ * total supply at the time are recorded for later access.
13
+ *
14
+ * This can be used to safely create mechanisms based on token balances such as trustless dividends or weighted voting.
15
+ * In naive implementations it's possible to perform a "double spend" attack by reusing the same balance from different
16
+ * accounts. By using snapshots to calculate dividends or voting power, those attacks no longer apply. It can also be
17
+ * used to create an efficient ERC20 forking mechanism.
18
+ *
19
+ * Snapshots are created by the internal {_snapshot} function, which will emit the {Snapshot} event and return a
20
+ * snapshot id. To get the total supply at the time of a snapshot, call the function {totalSupplyAt} with the snapshot
21
+ * id. To get the balance of an account at the time of a snapshot, call the {balanceOfAt} function with the snapshot id
22
+ * and the account address.
23
+ *
24
+ * ==== Gas Costs
25
+ *
26
+ * Snapshots are efficient. Snapshot creation is _O(1)_. Retrieval of balances or total supply from a snapshot is _O(log
27
+ * n)_ in the number of snapshots that have been created, although _n_ for a specific account will generally be much
28
+ * smaller since identical balances in subsequent snapshots are stored as a single entry.
29
+ *
30
+ * There is a constant overhead for normal ERC20 transfers due to the additional snapshot bookkeeping. This overhead is
31
+ * only significant for the first transfer that immediately follows a snapshot for a particular account. Subsequent
32
+ * transfers will have normal cost until the next snapshot, and so on.
33
+ */
34
+ abstract contract ERC20Snapshot is ERC20 {
35
+ // Inspired by Jordi Baylina's MiniMeToken to record historical balances:
36
+ // https://github.com/Giveth/minimd/blob/ea04d950eea153a04c51fa510b068b9dded390cb/contracts/MiniMeToken.sol
37
+
38
+ using SafeMath for uint256;
39
+ using Arrays for uint256[];
40
+ using Counters for Counters.Counter;
41
+
42
+ // Snapshotted values have arrays of ids and the value corresponding to that id. These could be an array of a
43
+ // Snapshot struct, but that would impede usage of functions that work on an array.
44
+ struct Snapshots {
45
+ uint256[] ids;
46
+ uint256[] values;
47
+ }
48
+
49
+ mapping (address => Snapshots) private _accountBalanceSnapshots;
50
+ Snapshots private _totalSupplySnapshots;
51
+
52
+ // Snapshot ids increase monotonically, with the first value being 1. An id of 0 is invalid.
53
+ Counters.Counter private _currentSnapshotId;
54
+
55
+ /**
56
+ * @dev Emitted by {_snapshot} when a snapshot identified by `id` is created.
57
+ */
58
+ event Snapshot(uint256 id);
59
+
60
+ /**
61
+ * @dev Creates a new snapshot and returns its snapshot id.
62
+ *
63
+ * Emits a {Snapshot} event that contains the same id.
64
+ *
65
+ * {_snapshot} is `internal` and you have to decide how to expose it externally. Its usage may be restricted to a
66
+ * set of accounts, for example using {AccessControl}, or it may be open to the public.
67
+ *
68
+ * [WARNING]
69
+ * ====
70
+ * While an open way of calling {_snapshot} is required for certain trust minimization mechanisms such as forking,
71
+ * you must consider that it can potentially be used by attackers in two ways.
72
+ *
73
+ * First, it can be used to increase the cost of retrieval of values from snapshots, although it will grow
74
+ * logarithmically thus rendering this attack ineffective in the long term. Second, it can be used to target
75
+ * specific accounts and increase the cost of ERC20 transfers for them, in the ways specified in the Gas Costs
76
+ * section above.
77
+ *
78
+ * We haven't measured the actual numbers; if this is something you're interested in please reach out to us.
79
+ * ====
80
+ */
81
+ function _snapshot() internal virtual returns (uint256) {
82
+ _currentSnapshotId.increment();
83
+
84
+ uint256 currentId = _currentSnapshotId.current();
85
+ emit Snapshot(currentId);
86
+ return currentId;
87
+ }
88
+
89
+ /**
90
+ * @dev Retrieves the balance of `account` at the time `snapshotId` was created.
91
+ */
92
+ function balanceOfAt(address account, uint256 snapshotId) public view virtual returns (uint256) {
93
+ (bool snapshotted, uint256 value) = _valueAt(snapshotId, _accountBalanceSnapshots[account]);
94
+
95
+ return snapshotted ? value : balanceOf(account);
96
+ }
97
+
98
+ /**
99
+ * @dev Retrieves the total supply at the time `snapshotId` was created.
100
+ */
101
+ function totalSupplyAt(uint256 snapshotId) public view virtual returns(uint256) {
102
+ (bool snapshotted, uint256 value) = _valueAt(snapshotId, _totalSupplySnapshots);
103
+
104
+ return snapshotted ? value : totalSupply();
105
+ }
106
+
107
+
108
+ // Update balance and/or total supply snapshots before the values are modified. This is implemented
109
+ // in the _beforeTokenTransfer hook, which is executed for _mint, _burn, and _transfer operations.
110
+ function _beforeTokenTransfer(address from, address to, uint256 amount) internal virtual override {
111
+ super._beforeTokenTransfer(from, to, amount);
112
+
113
+ if (from == address(0)) {
114
+ // mint
115
+ _updateAccountSnapshot(to);
116
+ _updateTotalSupplySnapshot();
117
+ } else if (to == address(0)) {
118
+ // burn
119
+ _updateAccountSnapshot(from);
120
+ _updateTotalSupplySnapshot();
121
+ } else {
122
+ // transfer
123
+ _updateAccountSnapshot(from);
124
+ _updateAccountSnapshot(to);
125
+ }
126
+ }
127
+
128
+ function _valueAt(uint256 snapshotId, Snapshots storage snapshots)
129
+ private view returns (bool, uint256)
130
+ {
131
+ require(snapshotId > 0, "ERC20Snapshot: id is 0");
132
+ // solhint-disable-next-line max-line-length
133
+ require(snapshotId <= _currentSnapshotId.current(), "ERC20Snapshot: nonexistent id");
134
+
135
+ // When a valid snapshot is queried, there are three possibilities:
136
+ // a) The queried value was not modified after the snapshot was taken. Therefore, a snapshot entry was never
137
+ // created for this id, and all stored snapshot ids are smaller than the requested one. The value that corresponds
138
+ // to this id is the current one.
139
+ // b) The queried value was modified after the snapshot was taken. Therefore, there will be an entry with the
140
+ // requested id, and its value is the one to return.
141
+ // c) More snapshots were created after the requested one, and the queried value was later modified. There will be
142
+ // no entry for the requested id: the value that corresponds to it is that of the smallest snapshot id that is
143
+ // larger than the requested one.
144
+ //
145
+ // In summary, we need to find an element in an array, returning the index of the smallest value that is larger if
146
+ // it is not found, unless said value doesn't exist (e.g. when all values are smaller). Arrays.findUpperBound does
147
+ // exactly this.
148
+
149
+ uint256 index = snapshots.ids.findUpperBound(snapshotId);
150
+
151
+ if (index == snapshots.ids.length) {
152
+ return (false, 0);
153
+ } else {
154
+ return (true, snapshots.values[index]);
155
+ }
156
+ }
157
+
158
+ function _updateAccountSnapshot(address account) private {
159
+ _updateSnapshot(_accountBalanceSnapshots[account], balanceOf(account));
160
+ }
161
+
162
+ function _updateTotalSupplySnapshot() private {
163
+ _updateSnapshot(_totalSupplySnapshots, totalSupply());
164
+ }
165
+
166
+ function _updateSnapshot(Snapshots storage snapshots, uint256 currentValue) private {
167
+ uint256 currentId = _currentSnapshotId.current();
168
+ if (_lastSnapshotId(snapshots.ids) < currentId) {
169
+ snapshots.ids.push(currentId);
170
+ snapshots.values.push(currentValue);
171
+ }
172
+ }
173
+
174
+ function _lastSnapshotId(uint256[] storage ids) private view returns (uint256) {
175
+ if (ids.length == 0) {
176
+ return 0;
177
+ } else {
178
+ return ids[ids.length - 1];
179
+ }
180
+ }
181
+ }