Commit dda49727 by github-actions

Transpile 32e498bb

parent 1e533d92
...@@ -28,6 +28,20 @@ ...@@ -28,6 +28,20 @@
* `GSN`: Deprecate GSNv1 support in favor of upcomming support for GSNv2. ([#2521](https://github.com/OpenZeppelin/openzeppelin-contracts/pull/2521)) * `GSN`: Deprecate GSNv1 support in favor of upcomming support for GSNv2. ([#2521](https://github.com/OpenZeppelin/openzeppelin-contracts/pull/2521))
* `ERC165`: Remove uses of storage in the base ERC165 implementation. ERC165 based contracts now use storage-less virtual functions. Old behaviour remains available in the `ERC165Storage` extension. ([#2505](https://github.com/OpenZeppelin/openzeppelin-contracts/pull/2505)) * `ERC165`: Remove uses of storage in the base ERC165 implementation. ERC165 based contracts now use storage-less virtual functions. Old behaviour remains available in the `ERC165Storage` extension. ([#2505](https://github.com/OpenZeppelin/openzeppelin-contracts/pull/2505))
* `Initializable`: Make initializer check stricter during construction. ([#2531](https://github.com/OpenZeppelin/openzeppelin-contracts/pull/2531)) * `Initializable`: Make initializer check stricter during construction. ([#2531](https://github.com/OpenZeppelin/openzeppelin-contracts/pull/2531))
* `ERC721`: remove enumerability of tokens from the base implementation. This feature is now provided separately through the `ERC721Enumerable` extension. ([#2511](https://github.com/OpenZeppelin/openzeppelin-contracts/pull/2511))
* `AccessControl`: removed enumerability by default for a more lightweight contract. It is now opt-in through `AccessControlEnumerable`. ([#2512](https://github.com/OpenZeppelin/openzeppelin-contracts/pull/2512))
* Meta Transactions: add `ERC2771Context` and a `MinimalForwarder` for meta-transactions. ([#2508](https://github.com/OpenZeppelin/openzeppelin-contracts/pull/2508))
* Overall reorganisation of the contract folder to improve clarity and discoverability. ([#2503](https://github.com/OpenZeppelin/openzeppelin-contracts/pull/2503))
### How to upgrade from 3.x
Since this version has moved a few contracts to different directories, users upgrading from a previous version will need to adjust their import statements. To make this easier, the package includes a script that will migrate import statements automatically. After upgrading to the latest version of the package, run:
```
npx openzeppelin-contracts-migrate-imports
```
Make sure you're using git or another version control system to be able to recover from any potential error in our script.
## 3.4.0 (2021-02-02) ## 3.4.0 (2021-02-02)
......
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
import "./AccessControlUpgradeable.sol";
import "../utils/structs/EnumerableSetUpgradeable.sol";
import "../utils/Initializable.sol";
/**
* @dev Extension of {AccessControl} that allows enumerating the members of each role.
*/
abstract contract AccessControlEnumerableUpgradeable is Initializable, AccessControlUpgradeable {
function __AccessControlEnumerable_init() internal initializer {
__Context_init_unchained();
__AccessControl_init_unchained();
__AccessControlEnumerable_init_unchained();
}
function __AccessControlEnumerable_init_unchained() internal initializer {
}
using EnumerableSetUpgradeable for EnumerableSetUpgradeable.AddressSet;
mapping (bytes32 => EnumerableSetUpgradeable.AddressSet) private _roleMembers;
/**
* @dev Returns one of the accounts that have `role`. `index` must be a
* value between 0 and {getRoleMemberCount}, non-inclusive.
*
* Role bearers are not sorted in any particular way, and their ordering may
* change at any point.
*
* WARNING: When using {getRoleMember} and {getRoleMemberCount}, make sure
* you perform all queries on the same block. See the following
* https://forum.openzeppelin.com/t/iterating-over-elements-on-enumerableset-in-openzeppelin-contracts/2296[forum post]
* for more information.
*/
function getRoleMember(bytes32 role, uint256 index) public view returns (address) {
return _roleMembers[role].at(index);
}
/**
* @dev Returns the number of accounts that have `role`. Can be used
* together with {getRoleMember} to enumerate all bearers of a role.
*/
function getRoleMemberCount(bytes32 role) public view returns (uint256) {
return _roleMembers[role].length();
}
/**
* @dev Overload {grantRole} to track enumerable memberships
*/
function grantRole(bytes32 role, address account) public virtual override {
super.grantRole(role, account);
_roleMembers[role].add(account);
}
/**
* @dev Overload {revokeRole} to track enumerable memberships
*/
function revokeRole(bytes32 role, address account) public virtual override {
super.revokeRole(role, account);
_roleMembers[role].remove(account);
}
/**
* @dev Overload {_setupRole} to track enumerable memberships
*/
function _setupRole(bytes32 role, address account) internal virtual override {
super._setupRole(role, account);
_roleMembers[role].add(account);
}
uint256[49] private __gap;
}
...@@ -2,14 +2,15 @@ ...@@ -2,14 +2,15 @@
pragma solidity ^0.8.0; pragma solidity ^0.8.0;
import "../utils/EnumerableSetUpgradeable.sol";
import "../utils/AddressUpgradeable.sol";
import "../utils/ContextUpgradeable.sol"; import "../utils/ContextUpgradeable.sol";
import "../proxy/Initializable.sol"; import "../utils/Initializable.sol";
/** /**
* @dev Contract module that allows children to implement role-based access * @dev Contract module that allows children to implement role-based access
* control mechanisms. * control mechanisms. This is a lightweight version that doesn't allow enumerating role
* members except through off-chain means by accessing the contract event logs. Some
* applications may benefit from on-chain enumerability, for those cases see
* {AccessControlEnumerable}.
* *
* Roles are referred to by their `bytes32` identifier. These should be exposed * Roles are referred to by their `bytes32` identifier. These should be exposed
* in the external API and be unique. The best way to achieve this is by * in the external API and be unique. The best way to achieve this is by
...@@ -50,11 +51,8 @@ abstract contract AccessControlUpgradeable is Initializable, ContextUpgradeable ...@@ -50,11 +51,8 @@ abstract contract AccessControlUpgradeable is Initializable, ContextUpgradeable
function __AccessControl_init_unchained() internal initializer { function __AccessControl_init_unchained() internal initializer {
} }
using EnumerableSetUpgradeable for EnumerableSetUpgradeable.AddressSet;
using AddressUpgradeable for address;
struct RoleData { struct RoleData {
EnumerableSetUpgradeable.AddressSet members; mapping (address => bool) members;
bytes32 adminRole; bytes32 adminRole;
} }
...@@ -93,31 +91,7 @@ abstract contract AccessControlUpgradeable is Initializable, ContextUpgradeable ...@@ -93,31 +91,7 @@ abstract contract AccessControlUpgradeable is Initializable, ContextUpgradeable
* @dev Returns `true` if `account` has been granted `role`. * @dev Returns `true` if `account` has been granted `role`.
*/ */
function hasRole(bytes32 role, address account) public view returns (bool) { function hasRole(bytes32 role, address account) public view returns (bool) {
return _roles[role].members.contains(account); return _roles[role].members[account];
}
/**
* @dev Returns the number of accounts that have `role`. Can be used
* together with {getRoleMember} to enumerate all bearers of a role.
*/
function getRoleMemberCount(bytes32 role) public view returns (uint256) {
return _roles[role].members.length();
}
/**
* @dev Returns one of the accounts that have `role`. `index` must be a
* value between 0 and {getRoleMemberCount}, non-inclusive.
*
* Role bearers are not sorted in any particular way, and their ordering may
* change at any point.
*
* WARNING: When using {getRoleMember} and {getRoleMemberCount}, make sure
* you perform all queries on the same block. See the following
* https://forum.openzeppelin.com/t/iterating-over-elements-on-enumerableset-in-openzeppelin-contracts/2296[forum post]
* for more information.
*/
function getRoleMember(bytes32 role, uint256 index) public view returns (address) {
return _roles[role].members.at(index);
} }
/** /**
...@@ -141,7 +115,7 @@ abstract contract AccessControlUpgradeable is Initializable, ContextUpgradeable ...@@ -141,7 +115,7 @@ abstract contract AccessControlUpgradeable is Initializable, ContextUpgradeable
* - the caller must have ``role``'s admin role. * - the caller must have ``role``'s admin role.
*/ */
function grantRole(bytes32 role, address account) public virtual { function grantRole(bytes32 role, address account) public virtual {
require(hasRole(_roles[role].adminRole, _msgSender()), "AccessControl: sender must be an admin to grant"); require(hasRole(getRoleAdmin(role), _msgSender()), "AccessControl: sender must be an admin to grant");
_grantRole(role, account); _grantRole(role, account);
} }
...@@ -156,7 +130,7 @@ abstract contract AccessControlUpgradeable is Initializable, ContextUpgradeable ...@@ -156,7 +130,7 @@ abstract contract AccessControlUpgradeable is Initializable, ContextUpgradeable
* - the caller must have ``role``'s admin role. * - the caller must have ``role``'s admin role.
*/ */
function revokeRole(bytes32 role, address account) public virtual { function revokeRole(bytes32 role, address account) public virtual {
require(hasRole(_roles[role].adminRole, _msgSender()), "AccessControl: sender must be an admin to revoke"); require(hasRole(getRoleAdmin(role), _msgSender()), "AccessControl: sender must be an admin to revoke");
_revokeRole(role, account); _revokeRole(role, account);
} }
...@@ -207,18 +181,20 @@ abstract contract AccessControlUpgradeable is Initializable, ContextUpgradeable ...@@ -207,18 +181,20 @@ abstract contract AccessControlUpgradeable is Initializable, ContextUpgradeable
* Emits a {RoleAdminChanged} event. * Emits a {RoleAdminChanged} event.
*/ */
function _setRoleAdmin(bytes32 role, bytes32 adminRole) internal virtual { function _setRoleAdmin(bytes32 role, bytes32 adminRole) internal virtual {
emit RoleAdminChanged(role, _roles[role].adminRole, adminRole); emit RoleAdminChanged(role, getRoleAdmin(role), adminRole);
_roles[role].adminRole = adminRole; _roles[role].adminRole = adminRole;
} }
function _grantRole(bytes32 role, address account) private { function _grantRole(bytes32 role, address account) private {
if (_roles[role].members.add(account)) { if (!hasRole(role, account)) {
_roles[role].members[account] = true;
emit RoleGranted(role, account, _msgSender()); emit RoleGranted(role, account, _msgSender());
} }
} }
function _revokeRole(bytes32 role, address account) private { function _revokeRole(bytes32 role, address account) private {
if (_roles[role].members.remove(account)) { if (hasRole(role, account)) {
_roles[role].members[account] = false;
emit RoleRevoked(role, account, _msgSender()); emit RoleRevoked(role, account, _msgSender());
} }
} }
......
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
pragma solidity ^0.8.0; pragma solidity ^0.8.0;
import "../utils/ContextUpgradeable.sol"; import "../utils/ContextUpgradeable.sol";
import "../proxy/Initializable.sol"; import "../utils/Initializable.sol";
/** /**
* @dev Contract module which provides a basic access control mechanism, where * @dev Contract module which provides a basic access control mechanism, where
* there is an account (an owner) that can be granted exclusive access to * there is an account (an owner) that can be granted exclusive access to
......
...@@ -7,7 +7,6 @@ This directory provides ways to restrict who can access the functions of a contr ...@@ -7,7 +7,6 @@ This directory provides ways to restrict who can access the functions of a contr
- {AccessControl} provides a general role based access control mechanism. Multiple hierarchical roles can be created and assigned each to multiple accounts. - {AccessControl} provides a general role based access control mechanism. Multiple hierarchical roles can be created and assigned each to multiple accounts.
- {Ownable} is a simpler mechanism with a single owner "role" that can be assigned to a single account. This simpler mechanism can be useful for quick tests but projects with production concerns are likely to outgrow it. - {Ownable} is a simpler mechanism with a single owner "role" that can be assigned to a single account. This simpler mechanism can be useful for quick tests but projects with production concerns are likely to outgrow it.
- {TimelockController} is used in combination with one of the above two mechanisms. By assigning a role to an instance of the `TimelockController` contract, the access to the functions controlled by that role will be delayed by some amount of time.
== Authorization == Authorization
...@@ -15,87 +14,4 @@ This directory provides ways to restrict who can access the functions of a contr ...@@ -15,87 +14,4 @@ This directory provides ways to restrict who can access the functions of a contr
{{AccessControl}} {{AccessControl}}
== Timelock {{AccessControlEnumerable}}
{{TimelockController}}
[[timelock-terminology]]
==== Terminology
* *Operation:* A transaction (or a set of transactions) that is the subject of the timelock. It has to be scheduled by a proposer and executed by an executor. The timelock enforces a minimum delay between the proposition and the execution (see xref:access-control.adoc#operation_lifecycle[operation lifecycle]). If the operation contains multiple transactions (batch mode), they are executed atomically. Operations are identified by the hash of their content.
* *Operation status:*
** *Unset:* An operation that is not part of the timelock mechanism.
** *Pending:* An operation that has been scheduled, before the timer expires.
** *Ready:* An operation that has been scheduled, after the timer expires.
** *Done:* An operation that has been executed.
* *Predecessor*: An (optional) dependency between operations. An operation can depend on another operation (its predecessor), forcing the execution order of these two operations.
* *Role*:
** *Proposer:* An address (smart contract or EOA) that is in charge of scheduling (and cancelling) operations.
** *Executor:* An address (smart contract or EOA) that is in charge of executing operations.
[[timelock-operation]]
==== Operation structure
Operation executed by the xref:api:access.adoc#TimelockController[`TimelockControler`] can contain one or multiple subsequent calls. Depending on whether you need to multiple calls to be executed atomically, you can either use simple or batched operations.
Both operations contain:
* *Target*, the address of the smart contract that the timelock should operate on.
* *Value*, in wei, that should be sent with the transaction. Most of the time this will be 0. Ether can be deposited before-end or passed along when executing the transaction.
* *Data*, containing the encoded function selector and parameters of the call. This can be produced using a number of tools. For example, a maintenance operation granting role `ROLE` to `ACCOUNT` can be encode using web3js as follows:
```javascript
const data = timelock.contract.methods.grantRole(ROLE, ACCOUNT).encodeABI()
```
* *Predecessor*, that specifies a dependency between operations. This dependency is optional. Use `bytes32(0)` if the operation does not have any dependency.
* *Salt*, used to disambiguate two otherwise identical operations. This can be any random value.
In the case of batched operations, `target`, `value` and `data` are specified as arrays, which must be of the same length.
[[timelock-operation-lifecycle]]
==== Operation lifecycle
Timelocked operations are identified by a unique id (their hash) and follow a specific lifecycle:
`Unset` -> `Pending` -> `Pending` + `Ready` -> `Done`
* By calling xref:api:access.adoc#TimelockController-schedule-address-uint256-bytes-bytes32-bytes32-uint256-[`schedule`] (or xref:api:access.adoc#TimelockController-scheduleBatch-address---uint256---bytes---bytes32-bytes32-uint256-[`scheduleBatch`]), a proposer moves the operation from the `Unset` to the `Pending` state. This starts a timer that must be longer than the minimum delay. The timer expires at a timestamp accessible through the xref:api:access.adoc#TimelockController-getTimestamp-bytes32-[`getTimestamp`] method.
* Once the timer expires, the operation automatically gets the `Ready` state. At this point, it can be executed.
* By calling xref:api:access.adoc#TimelockController-TimelockController-execute-address-uint256-bytes-bytes32-bytes32-[`execute`] (or xref:api:access.adoc#TimelockController-executeBatch-address---uint256---bytes---bytes32-bytes32-[`executeBatch`]), an executor triggers the operation's underlying transactions and moves it to the `Done` state. If the operation has a predecessor, it has to be in the `Done` state for this transition to succeed.
* xref:api:access.adoc#TimelockController-TimelockController-cancel-bytes32-[`cancel`] allows proposers to cancel any `Pending` operation. This resets the operation to the `Unset` state. It is thus possible for a proposer to re-schedule an operation that has been cancelled. In this case, the timer restarts when the operation is re-scheduled.
Operations status can be queried using the functions:
* xref:api:access.adoc#TimelockController-isOperationPending-bytes32-[`isOperationPending(bytes32)`]
* xref:api:access.adoc#TimelockController-isOperationReady-bytes32-[`isOperationReady(bytes32)`]
* xref:api:access.adoc#TimelockController-isOperationDone-bytes32-[`isOperationDone(bytes32)`]
[[timelock-roles]]
==== Roles
[[timelock-admin]]
===== Admin
The admins are in charge of managing proposers and executors. For the timelock to be self-governed, this role should only be given to the timelock itself. Upon deployment, both the timelock and the deployer have this role. After further configuration and testing, the deployer can renounce this role such that all further maintenance operations have to go through the timelock process.
This role is identified by the *TIMELOCK_ADMIN_ROLE* value: `0x5f58e3a2316349923ce3780f8d587db2d72378aed66a8261c916544fa6846ca5`
[[timelock-proposer]]
===== Proposer
The proposers are in charge of scheduling (and cancelling) operations. This is a critical role, that should be given to governing entities. This could be an EOA, a multisig, or a DAO.
WARNING: *Proposer fight:* Having multiple proposers, while providing redundancy in case one becomes unavailable, can be dangerous. As proposer have their say on all operations, they could cancel operations they disagree with, including operations to remove them for the proposers.
This role is identified by the *PROPOSER_ROLE* value: `0xb09aa5aeb3702cfd50b6b62bc4532604938f21248a27a1d5ca736082b6819cc1`
[[timelock-executor]]
===== Executor
The executors are in charge of executing the operations scheduled by the proposers once the timelock expires. Logic dictates that multisig or DAO that are proposers should also be executors in order to guarantee operations that have been scheduled will eventually be executed. However, having additional executor can reduce the cost (the executing transaction does not require validation by the multisig or DAO that proposed it), while ensuring whoever is in charge of execution cannot trigger actions that have not been scheduled by the proposers.
This role is identified by the *EXECUTOR_ROLE* value: `0xd8aa0f3194971a2a116679f7c2090f6939c8d4e01a2a8d7e41d55e5351469e63`
WARNING: A live contract without at least one proposer and one executor is locked. Make sure these roles are filled by reliable entities before the deployer renounces its administrative rights in favour of the timelock contract itself. See the {AccessControl} documentation to learn more about role management.
= Cryptography
[.readme-notice]
NOTE: This document is better viewed at https://docs.openzeppelin.com/contracts/api/cryptography
This collection of libraries provides simple and safe ways to use different cryptographic primitives.
The following related EIPs are in draft status and can be found in the drafts directory.
- {EIP712}
== Libraries
{{ECDSA}}
{{MerkleProof}}
= Draft EIPs
This directory contains implementations of EIPs that are still in Draft status.
Due to their nature as drafts, the details of these contracts may change and we cannot guarantee their xref:ROOT:releases-stability.adoc[stability]. Minor releases of OpenZeppelin Contracts may contain breaking changes for the contracts in this directory, which will be duly announced in the https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/CHANGELOG.md[changelog]. The EIPs included here are used by projects in production and this may make them less likely to change significantly.
== Cryptography
{{EIP712}}
== ERC 20
{{IERC20Permit}}
{{ERC20Permit}}
= Governance
[.readme-notice]
NOTE: This document is better viewed at https://docs.openzeppelin.com/contracts/api/access
This directory includes primitives for on-chain governance. We currently only offer the {TimelockController} contract, that can be used as a component in a governance systems to introduce a delay between a proposal and its execution.
== Timelock
{{TimelockController}}
[[timelock-terminology]]
==== Terminology
* *Operation:* A transaction (or a set of transactions) that is the subject of the timelock. It has to be scheduled by a proposer and executed by an executor. The timelock enforces a minimum delay between the proposition and the execution (see xref:access-control.adoc#operation_lifecycle[operation lifecycle]). If the operation contains multiple transactions (batch mode), they are executed atomically. Operations are identified by the hash of their content.
* *Operation status:*
** *Unset:* An operation that is not part of the timelock mechanism.
** *Pending:* An operation that has been scheduled, before the timer expires.
** *Ready:* An operation that has been scheduled, after the timer expires.
** *Done:* An operation that has been executed.
* *Predecessor*: An (optional) dependency between operations. An operation can depend on another operation (its predecessor), forcing the execution order of these two operations.
* *Role*:
** *Proposer:* An address (smart contract or EOA) that is in charge of scheduling (and cancelling) operations.
** *Executor:* An address (smart contract or EOA) that is in charge of executing operations.
[[timelock-operation]]
==== Operation structure
Operation executed by the xref:api:access.adoc#TimelockController[`TimelockControler`] can contain one or multiple subsequent calls. Depending on whether you need to multiple calls to be executed atomically, you can either use simple or batched operations.
Both operations contain:
* *Target*, the address of the smart contract that the timelock should operate on.
* *Value*, in wei, that should be sent with the transaction. Most of the time this will be 0. Ether can be deposited before-end or passed along when executing the transaction.
* *Data*, containing the encoded function selector and parameters of the call. This can be produced using a number of tools. For example, a maintenance operation granting role `ROLE` to `ACCOUNT` can be encode using web3js as follows:
```javascript
const data = timelock.contract.methods.grantRole(ROLE, ACCOUNT).encodeABI()
```
* *Predecessor*, that specifies a dependency between operations. This dependency is optional. Use `bytes32(0)` if the operation does not have any dependency.
* *Salt*, used to disambiguate two otherwise identical operations. This can be any random value.
In the case of batched operations, `target`, `value` and `data` are specified as arrays, which must be of the same length.
[[timelock-operation-lifecycle]]
==== Operation lifecycle
Timelocked operations are identified by a unique id (their hash) and follow a specific lifecycle:
`Unset` -> `Pending` -> `Pending` + `Ready` -> `Done`
* By calling xref:api:access.adoc#TimelockController-schedule-address-uint256-bytes-bytes32-bytes32-uint256-[`schedule`] (or xref:api:access.adoc#TimelockController-scheduleBatch-address---uint256---bytes---bytes32-bytes32-uint256-[`scheduleBatch`]), a proposer moves the operation from the `Unset` to the `Pending` state. This starts a timer that must be longer than the minimum delay. The timer expires at a timestamp accessible through the xref:api:access.adoc#TimelockController-getTimestamp-bytes32-[`getTimestamp`] method.
* Once the timer expires, the operation automatically gets the `Ready` state. At this point, it can be executed.
* By calling xref:api:access.adoc#TimelockController-TimelockController-execute-address-uint256-bytes-bytes32-bytes32-[`execute`] (or xref:api:access.adoc#TimelockController-executeBatch-address---uint256---bytes---bytes32-bytes32-[`executeBatch`]), an executor triggers the operation's underlying transactions and moves it to the `Done` state. If the operation has a predecessor, it has to be in the `Done` state for this transition to succeed.
* xref:api:access.adoc#TimelockController-TimelockController-cancel-bytes32-[`cancel`] allows proposers to cancel any `Pending` operation. This resets the operation to the `Unset` state. It is thus possible for a proposer to re-schedule an operation that has been cancelled. In this case, the timer restarts when the operation is re-scheduled.
Operations status can be queried using the functions:
* xref:api:access.adoc#TimelockController-isOperationPending-bytes32-[`isOperationPending(bytes32)`]
* xref:api:access.adoc#TimelockController-isOperationReady-bytes32-[`isOperationReady(bytes32)`]
* xref:api:access.adoc#TimelockController-isOperationDone-bytes32-[`isOperationDone(bytes32)`]
[[timelock-roles]]
==== Roles
[[timelock-admin]]
===== Admin
The admins are in charge of managing proposers and executors. For the timelock to be self-governed, this role should only be given to the timelock itself. Upon deployment, both the timelock and the deployer have this role. After further configuration and testing, the deployer can renounce this role such that all further maintenance operations have to go through the timelock process.
This role is identified by the *TIMELOCK_ADMIN_ROLE* value: `0x5f58e3a2316349923ce3780f8d587db2d72378aed66a8261c916544fa6846ca5`
[[timelock-proposer]]
===== Proposer
The proposers are in charge of scheduling (and cancelling) operations. This is a critical role, that should be given to governing entities. This could be an EOA, a multisig, or a DAO.
WARNING: *Proposer fight:* Having multiple proposers, while providing redundancy in case one becomes unavailable, can be dangerous. As proposer have their say on all operations, they could cancel operations they disagree with, including operations to remove them for the proposers.
This role is identified by the *PROPOSER_ROLE* value: `0xb09aa5aeb3702cfd50b6b62bc4532604938f21248a27a1d5ca736082b6819cc1`
[[timelock-executor]]
===== Executor
The executors are in charge of executing the operations scheduled by the proposers once the timelock expires. Logic dictates that multisig or DAO that are proposers should also be executors in order to guarantee operations that have been scheduled will eventually be executed. However, having additional executor can reduce the cost (the executing transaction does not require validation by the multisig or DAO that proposed it), while ensuring whoever is in charge of execution cannot trigger actions that have not been scheduled by the proposers.
This role is identified by the *EXECUTOR_ROLE* value: `0xd8aa0f3194971a2a116679f7c2090f6939c8d4e01a2a8d7e41d55e5351469e63`
WARNING: A live contract without at least one proposer and one executor is locked. Make sure these roles are filled by reliable entities before the deployer renounces its administrative rights in favour of the timelock contract itself. See the {AccessControl} documentation to learn more about role management.
...@@ -2,8 +2,8 @@ ...@@ -2,8 +2,8 @@
pragma solidity ^0.8.0; pragma solidity ^0.8.0;
import "./AccessControlUpgradeable.sol"; import "../access/AccessControlUpgradeable.sol";
import "../proxy/Initializable.sol"; import "../utils/Initializable.sol";
/** /**
* @dev Contract module which acts as a timelocked controller. When set as the * @dev Contract module which acts as a timelocked controller. When set as the
......
= Introspection
[.readme-notice]
NOTE: This document is better viewed at https://docs.openzeppelin.com/contracts/api/introspection
This set of interfaces and contracts deal with https://en.wikipedia.org/wiki/Type_introspection[type introspection] of contracts, that is, examining which functions can be called on them. This is usually referred to as a contract's _interface_.
Ethereum contracts have no native concept of an interface, so applications must usually simply trust they are not making an incorrect call. For trusted setups this is a non-issue, but often unknown and untrusted third-party addresses need to be interacted with. There may even not be any direct calls to them! (e.g. `ERC20` tokens may be sent to a contract that lacks a way to transfer them out of it, locking them forever). In these cases, a contract _declaring_ its interface can be very helpful in preventing errors.
There are two main ways to approach this.
* Locally, where a contract implements `IERC165` and declares an interface, and a second one queries it directly via `ERC165Checker`.
* Globally, where a global and unique registry (`IERC1820Registry`) is used to register implementers of a certain interface (`IERC1820Implementer`). It is then the registry that is queried, which allows for more complex setups, like contracts implementing interfaces for externally-owned accounts.
Note that, in all cases, accounts simply _declare_ their interfaces, but they are not required to actually implement them. This mechanism can therefore be used to both prevent errors and allow for complex interactions (see `ERC777`), but it must not be relied on for security.
== Local
{{IERC165}}
{{ERC165}}
{{ERC165Storage}}
{{ERC165Checker}}
== Global
{{IERC1820Registry}}
{{IERC1820Implementer}}
{{ERC1820Implementer}}
= Math
[.readme-notice]
NOTE: This document is better viewed at https://docs.openzeppelin.com/contracts/api/math
These are math-related utilities.
== Libraries
{{SafeMath}}
{{SignedSafeMath}}
{{Math}}
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
import "../utils/ContextUpgradeable.sol";
import "../utils/Initializable.sol";
/*
* @dev Context variant with ERC2771 support.
*/
abstract contract ERC2771ContextUpgradeable is Initializable, ContextUpgradeable {
address _trustedForwarder;
function __ERC2771Context_init(address trustedForwarder) internal initializer {
__Context_init_unchained();
__ERC2771Context_init_unchained(trustedForwarder);
}
function __ERC2771Context_init_unchained(address trustedForwarder) internal initializer {
_trustedForwarder = trustedForwarder;
}
function isTrustedForwarder(address forwarder) public view virtual returns(bool) {
return forwarder == _trustedForwarder;
}
function _msgSender() internal view virtual override returns (address sender) {
if (isTrustedForwarder(msg.sender)) {
// The assembly code is more direct than the Solidity version using `abi.decode`.
assembly { sender := shr(96, calldataload(sub(calldatasize(), 20))) }
} else {
return super._msgSender();
}
}
function _msgData() internal view virtual override returns (bytes calldata) {
if (isTrustedForwarder(msg.sender)) {
return msg.data[:msg.data.length-20];
} else {
return super._msgData();
}
}
uint256[50] private __gap;
}
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
import "../utils/cryptography/ECDSAUpgradeable.sol";
import "../utils/cryptography/draft-EIP712Upgradeable.sol";
import "../utils/Initializable.sol";
/*
* @dev Simple minimal forwarder to be used together with an ERC2771 compatible contract. See {ERC2771Context}.
*/
contract MinimalForwarderUpgradeable is Initializable, EIP712Upgradeable {
using ECDSAUpgradeable for bytes32;
struct ForwardRequest {
address from;
address to;
uint256 value;
uint256 gas;
uint256 nonce;
bytes data;
}
bytes32 private constant TYPEHASH = keccak256("ForwardRequest(address from,address to,uint256 value,uint256 gas,uint256 nonce,bytes data)");
mapping(address => uint256) private _nonces;
function __MinimalForwarder_init() internal initializer {
__EIP712_init_unchained("MinimalForwarder", "0.0.1");
__MinimalForwarder_init_unchained();
}
function __MinimalForwarder_init_unchained() internal initializer {}
function getNonce(address from) public view returns (uint256) {
return _nonces[from];
}
function verify(ForwardRequest calldata req, bytes calldata signature) public view returns (bool) {
address signer = _hashTypedDataV4(keccak256(abi.encode(
TYPEHASH,
req.from,
req.to,
req.value,
req.gas,
req.nonce,
keccak256(req.data)
))).recover(signature);
return _nonces[req.from] == req.nonce && signer == req.from;
}
function execute(ForwardRequest calldata req, bytes calldata signature) public payable returns (bool, bytes memory) {
require(verify(req, signature), "MinimalForwarder: signature does not match request");
_nonces[req.from] = req.nonce + 1;
// solhint-disable-next-line avoid-low-level-calls
(bool success, bytes memory returndata) = req.to.call{gas: req.gas, value: req.value}(abi.encodePacked(req.data, req.from));
// Validate that the relayer has sent enough gas for the call.
// See https://ronan.eth.link/blog/ethereum-gas-dangers/
assert(gasleft() > req.gas / 63);
return (success, returndata);
}
uint256[49] private __gap;
}
= Meta Transactions
[.readme-notice]
NOTE: This document is better viewed at https://docs.openzeppelin.com/contracts/api/metatx
== Core
{{ERC2771Context}}
== Utils
{{MinimalForwarder}}
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
import "../access/AccessControlEnumerableUpgradeable.sol";
import "../utils/Initializable.sol";
contract AccessControlEnumerableMockUpgradeable is Initializable, AccessControlEnumerableUpgradeable {
function __AccessControlEnumerableMock_init() internal initializer {
__Context_init_unchained();
__AccessControl_init_unchained();
__AccessControlEnumerable_init_unchained();
__AccessControlEnumerableMock_init_unchained();
}
function __AccessControlEnumerableMock_init_unchained() internal initializer {
_setupRole(DEFAULT_ADMIN_ROLE, _msgSender());
}
function setRoleAdmin(bytes32 roleId, bytes32 adminRoleId) public {
_setRoleAdmin(roleId, adminRoleId);
}
uint256[50] private __gap;
}
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
pragma solidity ^0.8.0; pragma solidity ^0.8.0;
import "../access/AccessControlUpgradeable.sol"; import "../access/AccessControlUpgradeable.sol";
import "../proxy/Initializable.sol"; import "../utils/Initializable.sol";
contract AccessControlMockUpgradeable is Initializable, AccessControlUpgradeable { contract AccessControlMockUpgradeable is Initializable, AccessControlUpgradeable {
function __AccessControlMock_init() internal initializer { function __AccessControlMock_init() internal initializer {
......
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
pragma solidity ^0.8.0; pragma solidity ^0.8.0;
import "../utils/AddressUpgradeable.sol"; import "../utils/AddressUpgradeable.sol";
import "../proxy/Initializable.sol"; import "../utils/Initializable.sol";
contract AddressImplUpgradeable is Initializable { contract AddressImplUpgradeable is Initializable {
function __AddressImpl_init() internal initializer { function __AddressImpl_init() internal initializer {
......
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
pragma solidity ^0.8.0; pragma solidity ^0.8.0;
import "../utils/ArraysUpgradeable.sol"; import "../utils/ArraysUpgradeable.sol";
import "../proxy/Initializable.sol"; import "../utils/Initializable.sol";
contract ArraysImplUpgradeable is Initializable { contract ArraysImplUpgradeable is Initializable {
using ArraysUpgradeable for uint256[]; using ArraysUpgradeable for uint256[];
......
// SPDX-License-Identifier: MIT // SPDX-License-Identifier: MIT
pragma solidity ^0.8.0; pragma solidity ^0.8.0;
import "../proxy/Initializable.sol"; import "../utils/Initializable.sol";
contract BadBeaconNoImplUpgradeable is Initializable { contract BadBeaconNoImplUpgradeable is Initializable {
function __BadBeaconNoImpl_init() internal initializer { function __BadBeaconNoImpl_init() internal initializer {
......
// SPDX-License-Identifier: MIT // SPDX-License-Identifier: MIT
pragma solidity ^0.8.0; pragma solidity ^0.8.0;
import "../proxy/Initializable.sol"; import "../utils/Initializable.sol";
contract CallReceiverMockUpgradeable is Initializable { contract CallReceiverMockUpgradeable is Initializable {
function __CallReceiverMock_init() internal initializer { function __CallReceiverMock_init() internal initializer {
......
// SPDX-License-Identifier: MIT // SPDX-License-Identifier: MIT
pragma solidity ^0.8.0; pragma solidity ^0.8.0;
import "../proxy/Initializable.sol"; import "../utils/Initializable.sol";
/** /**
......
...@@ -4,7 +4,7 @@ pragma solidity ^0.8.0; ...@@ -4,7 +4,7 @@ pragma solidity ^0.8.0;
import "../proxy/ClonesUpgradeable.sol"; import "../proxy/ClonesUpgradeable.sol";
import "../utils/AddressUpgradeable.sol"; import "../utils/AddressUpgradeable.sol";
import "../proxy/Initializable.sol"; import "../utils/Initializable.sol";
contract ClonesMockUpgradeable is Initializable { contract ClonesMockUpgradeable is Initializable {
function __ClonesMock_init() internal initializer { function __ClonesMock_init() internal initializer {
......
...@@ -2,8 +2,8 @@ ...@@ -2,8 +2,8 @@
pragma solidity ^0.8.0; pragma solidity ^0.8.0;
import "../payment/escrow/ConditionalEscrowUpgradeable.sol"; import "../utils/escrow/ConditionalEscrowUpgradeable.sol";
import "../proxy/Initializable.sol"; import "../utils/Initializable.sol";
// mock class using ConditionalEscrow // mock class using ConditionalEscrow
contract ConditionalEscrowMockUpgradeable is Initializable, ConditionalEscrowUpgradeable { contract ConditionalEscrowMockUpgradeable is Initializable, ConditionalEscrowUpgradeable {
......
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
pragma solidity ^0.8.0; pragma solidity ^0.8.0;
import "../utils/ContextUpgradeable.sol"; import "../utils/ContextUpgradeable.sol";
import "../proxy/Initializable.sol"; import "../utils/Initializable.sol";
contract ContextMockUpgradeable is Initializable, ContextUpgradeable { contract ContextMockUpgradeable is Initializable, ContextUpgradeable {
function __ContextMock_init() internal initializer { function __ContextMock_init() internal initializer {
......
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
pragma solidity ^0.8.0; pragma solidity ^0.8.0;
import "../utils/CountersUpgradeable.sol"; import "../utils/CountersUpgradeable.sol";
import "../proxy/Initializable.sol"; import "../utils/Initializable.sol";
contract CountersImplUpgradeable is Initializable { contract CountersImplUpgradeable is Initializable {
function __CountersImpl_init() internal initializer { function __CountersImpl_init() internal initializer {
......
...@@ -3,8 +3,8 @@ ...@@ -3,8 +3,8 @@
pragma solidity ^0.8.0; pragma solidity ^0.8.0;
import "../utils/Create2Upgradeable.sol"; import "../utils/Create2Upgradeable.sol";
import "../introspection/ERC1820ImplementerUpgradeable.sol"; import "../utils/introspection/ERC1820ImplementerUpgradeable.sol";
import "../proxy/Initializable.sol"; import "../utils/Initializable.sol";
contract Create2ImplUpgradeable is Initializable { contract Create2ImplUpgradeable is Initializable {
function __Create2Impl_init() internal initializer { function __Create2Impl_init() internal initializer {
......
// SPDX-License-Identifier: MIT // SPDX-License-Identifier: MIT
pragma solidity ^0.8.0; pragma solidity ^0.8.0;
import "../proxy/Initializable.sol"; import "../utils/Initializable.sol";
abstract contract ImplUpgradeable is Initializable { abstract contract ImplUpgradeable is Initializable {
function __Impl_init() internal initializer { function __Impl_init() internal initializer {
......
...@@ -2,8 +2,8 @@ ...@@ -2,8 +2,8 @@
pragma solidity ^0.8.0; pragma solidity ^0.8.0;
import "../cryptography/ECDSAUpgradeable.sol"; import "../utils/cryptography/ECDSAUpgradeable.sol";
import "../proxy/Initializable.sol"; import "../utils/Initializable.sol";
contract ECDSAMockUpgradeable is Initializable { contract ECDSAMockUpgradeable is Initializable {
function __ECDSAMock_init() internal initializer { function __ECDSAMock_init() internal initializer {
......
...@@ -2,9 +2,9 @@ ...@@ -2,9 +2,9 @@
pragma solidity ^0.8.0; pragma solidity ^0.8.0;
import "../drafts/EIP712Upgradeable.sol"; import "../utils/cryptography/draft-EIP712Upgradeable.sol";
import "../cryptography/ECDSAUpgradeable.sol"; import "../utils/cryptography/ECDSAUpgradeable.sol";
import "../proxy/Initializable.sol"; import "../utils/Initializable.sol";
contract EIP712ExternalUpgradeable is Initializable, EIP712Upgradeable { contract EIP712ExternalUpgradeable is Initializable, EIP712Upgradeable {
function __EIP712External_init(string memory name, string memory version) internal initializer { function __EIP712External_init(string memory name, string memory version) internal initializer {
......
...@@ -2,8 +2,8 @@ ...@@ -2,8 +2,8 @@
pragma solidity ^0.8.0; pragma solidity ^0.8.0;
import "../token/ERC1155/ERC1155BurnableUpgradeable.sol"; import "../token/ERC1155/extensions/ERC1155BurnableUpgradeable.sol";
import "../proxy/Initializable.sol"; import "../utils/Initializable.sol";
contract ERC1155BurnableMockUpgradeable is Initializable, ERC1155BurnableUpgradeable { contract ERC1155BurnableMockUpgradeable is Initializable, ERC1155BurnableUpgradeable {
function __ERC1155BurnableMock_init(string memory uri) internal initializer { function __ERC1155BurnableMock_init(string memory uri) internal initializer {
......
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
pragma solidity ^0.8.0; pragma solidity ^0.8.0;
import "../token/ERC1155/ERC1155Upgradeable.sol"; import "../token/ERC1155/ERC1155Upgradeable.sol";
import "../proxy/Initializable.sol"; import "../utils/Initializable.sol";
/** /**
* @title ERC1155Mock * @title ERC1155Mock
......
...@@ -3,8 +3,8 @@ ...@@ -3,8 +3,8 @@
pragma solidity ^0.8.0; pragma solidity ^0.8.0;
import "./ERC1155MockUpgradeable.sol"; import "./ERC1155MockUpgradeable.sol";
import "../token/ERC1155/ERC1155PausableUpgradeable.sol"; import "../token/ERC1155/extensions/ERC1155PausableUpgradeable.sol";
import "../proxy/Initializable.sol"; import "../utils/Initializable.sol";
contract ERC1155PausableMockUpgradeable is Initializable, ERC1155MockUpgradeable, ERC1155PausableUpgradeable { contract ERC1155PausableMockUpgradeable is Initializable, ERC1155MockUpgradeable, ERC1155PausableUpgradeable {
function __ERC1155PausableMock_init(string memory uri) internal initializer { function __ERC1155PausableMock_init(string memory uri) internal initializer {
......
...@@ -2,9 +2,9 @@ ...@@ -2,9 +2,9 @@
pragma solidity ^0.8.0; pragma solidity ^0.8.0;
import "../introspection/ERC165Upgradeable.sol";
import "../token/ERC1155/IERC1155ReceiverUpgradeable.sol"; import "../token/ERC1155/IERC1155ReceiverUpgradeable.sol";
import "../proxy/Initializable.sol"; import "../utils/introspection/ERC165Upgradeable.sol";
import "../utils/Initializable.sol";
contract ERC1155ReceiverMockUpgradeable is Initializable, IERC1155ReceiverUpgradeable, ERC165Upgradeable { contract ERC1155ReceiverMockUpgradeable is Initializable, IERC1155ReceiverUpgradeable, ERC165Upgradeable {
bytes4 private _recRetval; bytes4 private _recRetval;
......
...@@ -2,8 +2,8 @@ ...@@ -2,8 +2,8 @@
pragma solidity ^0.8.0; pragma solidity ^0.8.0;
import "../../introspection/IERC165Upgradeable.sol"; import "../../utils/introspection/IERC165Upgradeable.sol";
import "../../proxy/Initializable.sol"; import "../../utils/Initializable.sol";
/** /**
* https://eips.ethereum.org/EIPS/eip-214#specification * https://eips.ethereum.org/EIPS/eip-214#specification
......
// SPDX-License-Identifier: MIT // SPDX-License-Identifier: MIT
pragma solidity ^0.8.0; pragma solidity ^0.8.0;
import "../../proxy/Initializable.sol"; import "../../utils/Initializable.sol";
contract ERC165MissingDataUpgradeable is Initializable { contract ERC165MissingDataUpgradeable is Initializable {
function __ERC165MissingData_init() internal initializer { function __ERC165MissingData_init() internal initializer {
......
// SPDX-License-Identifier: MIT // SPDX-License-Identifier: MIT
pragma solidity ^0.8.0; pragma solidity ^0.8.0;
import "../../proxy/Initializable.sol"; import "../../utils/Initializable.sol";
contract ERC165NotSupportedUpgradeable is Initializable { function __ERC165NotSupported_init() internal initializer { contract ERC165NotSupportedUpgradeable is Initializable { function __ERC165NotSupported_init() internal initializer {
__ERC165NotSupported_init_unchained(); __ERC165NotSupported_init_unchained();
......
...@@ -2,8 +2,8 @@ ...@@ -2,8 +2,8 @@
pragma solidity ^0.8.0; pragma solidity ^0.8.0;
import "../introspection/ERC165CheckerUpgradeable.sol"; import "../utils/introspection/ERC165CheckerUpgradeable.sol";
import "../proxy/Initializable.sol"; import "../utils/Initializable.sol";
contract ERC165CheckerMockUpgradeable is Initializable { contract ERC165CheckerMockUpgradeable is Initializable {
function __ERC165CheckerMock_init() internal initializer { function __ERC165CheckerMock_init() internal initializer {
......
...@@ -2,8 +2,8 @@ ...@@ -2,8 +2,8 @@
pragma solidity ^0.8.0; pragma solidity ^0.8.0;
import "../introspection/ERC165Upgradeable.sol"; import "../utils/introspection/ERC165Upgradeable.sol";
import "../proxy/Initializable.sol"; import "../utils/Initializable.sol";
contract ERC165MockUpgradeable is Initializable, ERC165Upgradeable { contract ERC165MockUpgradeable is Initializable, ERC165Upgradeable {
function __ERC165Mock_init() internal initializer { function __ERC165Mock_init() internal initializer {
......
...@@ -2,8 +2,8 @@ ...@@ -2,8 +2,8 @@
pragma solidity ^0.8.0; pragma solidity ^0.8.0;
import "../introspection/ERC165StorageUpgradeable.sol"; import "../utils/introspection/ERC165StorageUpgradeable.sol";
import "../proxy/Initializable.sol"; import "../utils/Initializable.sol";
contract ERC165StorageMockUpgradeable is Initializable, ERC165StorageUpgradeable { contract ERC165StorageMockUpgradeable is Initializable, ERC165StorageUpgradeable {
function __ERC165StorageMock_init() internal initializer { function __ERC165StorageMock_init() internal initializer {
......
...@@ -2,8 +2,8 @@ ...@@ -2,8 +2,8 @@
pragma solidity ^0.8.0; pragma solidity ^0.8.0;
import "../introspection/ERC1820ImplementerUpgradeable.sol"; import "../utils/introspection/ERC1820ImplementerUpgradeable.sol";
import "../proxy/Initializable.sol"; import "../utils/Initializable.sol";
contract ERC1820ImplementerMockUpgradeable is Initializable, ERC1820ImplementerUpgradeable { contract ERC1820ImplementerMockUpgradeable is Initializable, ERC1820ImplementerUpgradeable {
function __ERC1820ImplementerMock_init() internal initializer { function __ERC1820ImplementerMock_init() internal initializer {
......
...@@ -2,8 +2,8 @@ ...@@ -2,8 +2,8 @@
pragma solidity ^0.8.0; pragma solidity ^0.8.0;
import "../token/ERC20/ERC20BurnableUpgradeable.sol"; import "../token/ERC20/extensions/ERC20BurnableUpgradeable.sol";
import "../proxy/Initializable.sol"; import "../utils/Initializable.sol";
contract ERC20BurnableMockUpgradeable is Initializable, ERC20BurnableUpgradeable { contract ERC20BurnableMockUpgradeable is Initializable, ERC20BurnableUpgradeable {
function __ERC20BurnableMock_init( function __ERC20BurnableMock_init(
......
...@@ -2,8 +2,8 @@ ...@@ -2,8 +2,8 @@
pragma solidity ^0.8.0; pragma solidity ^0.8.0;
import "../token/ERC20/ERC20CappedUpgradeable.sol"; import "../token/ERC20/extensions/ERC20CappedUpgradeable.sol";
import "../proxy/Initializable.sol"; import "../utils/Initializable.sol";
contract ERC20CappedMockUpgradeable is Initializable, ERC20CappedUpgradeable { contract ERC20CappedMockUpgradeable is Initializable, ERC20CappedUpgradeable {
function __ERC20CappedMock_init(string memory name, string memory symbol, uint256 cap) internal initializer { function __ERC20CappedMock_init(string memory name, string memory symbol, uint256 cap) internal initializer {
......
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
pragma solidity ^0.8.0; pragma solidity ^0.8.0;
import "../token/ERC20/ERC20Upgradeable.sol"; import "../token/ERC20/ERC20Upgradeable.sol";
import "../proxy/Initializable.sol"; import "../utils/Initializable.sol";
contract ERC20DecimalsMockUpgradeable is Initializable, ERC20Upgradeable { contract ERC20DecimalsMockUpgradeable is Initializable, ERC20Upgradeable {
uint8 private _decimals; uint8 private _decimals;
......
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
pragma solidity ^0.8.0; pragma solidity ^0.8.0;
import "../token/ERC20/ERC20Upgradeable.sol"; import "../token/ERC20/ERC20Upgradeable.sol";
import "../proxy/Initializable.sol"; import "../utils/Initializable.sol";
// mock class using ERC20 // mock class using ERC20
contract ERC20MockUpgradeable is Initializable, ERC20Upgradeable { contract ERC20MockUpgradeable is Initializable, ERC20Upgradeable {
......
...@@ -2,8 +2,8 @@ ...@@ -2,8 +2,8 @@
pragma solidity ^0.8.0; pragma solidity ^0.8.0;
import "../token/ERC20/ERC20PausableUpgradeable.sol"; import "../token/ERC20/extensions/ERC20PausableUpgradeable.sol";
import "../proxy/Initializable.sol"; import "../utils/Initializable.sol";
// mock class using ERC20Pausable // mock class using ERC20Pausable
contract ERC20PausableMockUpgradeable is Initializable, ERC20PausableUpgradeable { contract ERC20PausableMockUpgradeable is Initializable, ERC20PausableUpgradeable {
......
...@@ -2,8 +2,9 @@ ...@@ -2,8 +2,9 @@
pragma solidity ^0.8.0; pragma solidity ^0.8.0;
import "../drafts/ERC20PermitUpgradeable.sol";
import "../proxy/Initializable.sol"; import "../token/ERC20/extensions/draft-ERC20PermitUpgradeable.sol";
import "../utils/Initializable.sol";
contract ERC20PermitMockUpgradeable is Initializable, ERC20PermitUpgradeable { contract ERC20PermitMockUpgradeable is Initializable, ERC20PermitUpgradeable {
function __ERC20PermitMock_init( function __ERC20PermitMock_init(
......
...@@ -2,8 +2,8 @@ ...@@ -2,8 +2,8 @@
pragma solidity ^0.8.0; pragma solidity ^0.8.0;
import "../token/ERC20/ERC20SnapshotUpgradeable.sol"; import "../token/ERC20/extensions/ERC20SnapshotUpgradeable.sol";
import "../proxy/Initializable.sol"; import "../utils/Initializable.sol";
contract ERC20SnapshotMockUpgradeable is Initializable, ERC20SnapshotUpgradeable { contract ERC20SnapshotMockUpgradeable is Initializable, ERC20SnapshotUpgradeable {
......
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
import "./ContextMockUpgradeable.sol";
import "../metatx/ERC2771ContextUpgradeable.sol";
import "../utils/Initializable.sol";
// By inheriting from ERC2771Context, Context's internal functions are overridden automatically
contract ERC2771ContextMockUpgradeable is Initializable, ContextMockUpgradeable, ERC2771ContextUpgradeable {
function __ERC2771ContextMock_init(address trustedForwarder) internal initializer {
__Context_init_unchained();
__ContextMock_init_unchained();
__ERC2771Context_init_unchained(trustedForwarder);
__ERC2771ContextMock_init_unchained(trustedForwarder);
}
function __ERC2771ContextMock_init_unchained(address trustedForwarder) internal initializer {}
function _msgSender() internal override(ContextUpgradeable, ERC2771ContextUpgradeable) view virtual returns (address) {
return ERC2771ContextUpgradeable._msgSender();
}
function _msgData() internal override(ContextUpgradeable, ERC2771ContextUpgradeable) view virtual returns (bytes calldata) {
return ERC2771ContextUpgradeable._msgData();
}
uint256[50] private __gap;
}
...@@ -2,8 +2,8 @@ ...@@ -2,8 +2,8 @@
pragma solidity ^0.8.0; pragma solidity ^0.8.0;
import "../token/ERC721/ERC721BurnableUpgradeable.sol"; import "../token/ERC721/extensions/ERC721BurnableUpgradeable.sol";
import "../proxy/Initializable.sol"; import "../utils/Initializable.sol";
contract ERC721BurnableMockUpgradeable is Initializable, ERC721BurnableUpgradeable { contract ERC721BurnableMockUpgradeable is Initializable, ERC721BurnableUpgradeable {
function __ERC721BurnableMock_init(string memory name, string memory symbol) internal initializer { function __ERC721BurnableMock_init(string memory name, string memory symbol) internal initializer {
......
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
import "../token/ERC721/extensions/ERC721EnumerableUpgradeable.sol";
import "../utils/Initializable.sol";
/**
* @title ERC721Mock
* This mock just provides a public safeMint, mint, and burn functions for testing purposes
*/
contract ERC721EnumerableMockUpgradeable is Initializable, ERC721EnumerableUpgradeable {
string private _baseTokenURI;
function __ERC721EnumerableMock_init(string memory name, string memory symbol) internal initializer {
__Context_init_unchained();
__ERC165_init_unchained();
__ERC721_init_unchained(name, symbol);
__ERC721Enumerable_init_unchained();
__ERC721EnumerableMock_init_unchained(name, symbol);
}
function __ERC721EnumerableMock_init_unchained(string memory name, string memory symbol) internal initializer { }
function _baseURI() internal view virtual override returns (string memory) {
return _baseTokenURI;
}
function setBaseURI(string calldata newBaseTokenURI) public {
_baseTokenURI = newBaseTokenURI;
}
function baseURI() public view returns (string memory) {
return _baseURI();
}
function mint(address to, uint256 tokenId) public {
_mint(to, tokenId);
}
function safeMint(address to, uint256 tokenId) public {
_safeMint(to, tokenId);
}
function safeMint(address to, uint256 tokenId, bytes memory _data) public {
_safeMint(to, tokenId, _data);
}
function burn(uint256 tokenId) public {
_burn(tokenId);
}
uint256[49] private __gap;
}
...@@ -3,13 +3,15 @@ ...@@ -3,13 +3,15 @@
pragma solidity ^0.8.0; pragma solidity ^0.8.0;
import "../token/ERC721/ERC721Upgradeable.sol"; import "../token/ERC721/ERC721Upgradeable.sol";
import "../proxy/Initializable.sol"; import "../utils/Initializable.sol";
/** /**
* @title ERC721Mock * @title ERC721Mock
* This mock just provides a public safeMint, mint, and burn functions for testing purposes * This mock just provides a public safeMint, mint, and burn functions for testing purposes
*/ */
contract ERC721MockUpgradeable is Initializable, ERC721Upgradeable { contract ERC721MockUpgradeable is Initializable, ERC721Upgradeable {
string private _baseTokenURI;
function __ERC721Mock_init(string memory name, string memory symbol) internal initializer { function __ERC721Mock_init(string memory name, string memory symbol) internal initializer {
__Context_init_unchained(); __Context_init_unchained();
__ERC165_init_unchained(); __ERC165_init_unchained();
...@@ -19,16 +21,20 @@ contract ERC721MockUpgradeable is Initializable, ERC721Upgradeable { ...@@ -19,16 +21,20 @@ contract ERC721MockUpgradeable is Initializable, ERC721Upgradeable {
function __ERC721Mock_init_unchained(string memory name, string memory symbol) internal initializer { } function __ERC721Mock_init_unchained(string memory name, string memory symbol) internal initializer { }
function exists(uint256 tokenId) public view returns (bool) { function _baseURI() internal view virtual override returns (string memory) {
return _exists(tokenId); return _baseTokenURI;
} }
function setTokenURI(uint256 tokenId, string memory uri) public { function setBaseURI(string calldata newBaseTokenURI) public {
_setTokenURI(tokenId, uri); _baseTokenURI = newBaseTokenURI;
} }
function setBaseURI(string memory baseURI) public { function baseURI() public view returns (string memory) {
_setBaseURI(baseURI); return _baseURI();
}
function exists(uint256 tokenId) public view returns (bool) {
return _exists(tokenId);
} }
function mint(address to, uint256 tokenId) public { function mint(address to, uint256 tokenId) public {
...@@ -46,5 +52,5 @@ contract ERC721MockUpgradeable is Initializable, ERC721Upgradeable { ...@@ -46,5 +52,5 @@ contract ERC721MockUpgradeable is Initializable, ERC721Upgradeable {
function burn(uint256 tokenId) public { function burn(uint256 tokenId) public {
_burn(tokenId); _burn(tokenId);
} }
uint256[50] private __gap; uint256[49] private __gap;
} }
...@@ -2,8 +2,8 @@ ...@@ -2,8 +2,8 @@
pragma solidity ^0.8.0; pragma solidity ^0.8.0;
import "../token/ERC721/ERC721PausableUpgradeable.sol"; import "../token/ERC721/extensions/ERC721PausableUpgradeable.sol";
import "../proxy/Initializable.sol"; import "../utils/Initializable.sol";
/** /**
* @title ERC721PausableMock * @title ERC721PausableMock
......
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
pragma solidity ^0.8.0; pragma solidity ^0.8.0;
import "../token/ERC721/IERC721ReceiverUpgradeable.sol"; import "../token/ERC721/IERC721ReceiverUpgradeable.sol";
import "../proxy/Initializable.sol"; import "../utils/Initializable.sol";
contract ERC721ReceiverMockUpgradeable is Initializable, IERC721ReceiverUpgradeable { contract ERC721ReceiverMockUpgradeable is Initializable, IERC721ReceiverUpgradeable {
enum Error { enum Error {
......
...@@ -4,7 +4,7 @@ pragma solidity ^0.8.0; ...@@ -4,7 +4,7 @@ pragma solidity ^0.8.0;
import "../utils/ContextUpgradeable.sol"; import "../utils/ContextUpgradeable.sol";
import "../token/ERC777/ERC777Upgradeable.sol"; import "../token/ERC777/ERC777Upgradeable.sol";
import "../proxy/Initializable.sol"; import "../utils/Initializable.sol";
contract ERC777MockUpgradeable is Initializable, ContextUpgradeable, ERC777Upgradeable { contract ERC777MockUpgradeable is Initializable, ContextUpgradeable, ERC777Upgradeable {
event BeforeTokenTransfer(); event BeforeTokenTransfer();
......
...@@ -2,13 +2,13 @@ ...@@ -2,13 +2,13 @@
pragma solidity ^0.8.0; pragma solidity ^0.8.0;
import "../utils/ContextUpgradeable.sol";
import "../token/ERC777/IERC777Upgradeable.sol"; import "../token/ERC777/IERC777Upgradeable.sol";
import "../token/ERC777/IERC777SenderUpgradeable.sol"; import "../token/ERC777/IERC777SenderUpgradeable.sol";
import "../token/ERC777/IERC777RecipientUpgradeable.sol"; import "../token/ERC777/IERC777RecipientUpgradeable.sol";
import "../introspection/IERC1820RegistryUpgradeable.sol"; import "../utils/ContextUpgradeable.sol";
import "../introspection/ERC1820ImplementerUpgradeable.sol"; import "../utils/introspection/IERC1820RegistryUpgradeable.sol";
import "../proxy/Initializable.sol"; import "../utils/introspection/ERC1820ImplementerUpgradeable.sol";
import "../utils/Initializable.sol";
contract ERC777SenderRecipientMockUpgradeable is Initializable, ContextUpgradeable, IERC777SenderUpgradeable, IERC777RecipientUpgradeable, ERC1820ImplementerUpgradeable { contract ERC777SenderRecipientMockUpgradeable is Initializable, ContextUpgradeable, IERC777SenderUpgradeable, IERC777RecipientUpgradeable, ERC1820ImplementerUpgradeable {
function __ERC777SenderRecipientMock_init() internal initializer { function __ERC777SenderRecipientMock_init() internal initializer {
...@@ -161,4 +161,3 @@ contract ERC777SenderRecipientMockUpgradeable is Initializable, ContextUpgradeab ...@@ -161,4 +161,3 @@ contract ERC777SenderRecipientMockUpgradeable is Initializable, ContextUpgradeab
} }
uint256[49] private __gap; uint256[49] private __gap;
} }
...@@ -2,8 +2,8 @@ ...@@ -2,8 +2,8 @@
pragma solidity ^0.8.0; pragma solidity ^0.8.0;
import "../utils/EnumerableMapUpgradeable.sol"; import "../utils/structs/EnumerableMapUpgradeable.sol";
import "../proxy/Initializable.sol"; import "../utils/Initializable.sol";
contract EnumerableMapMockUpgradeable is Initializable { contract EnumerableMapMockUpgradeable is Initializable {
function __EnumerableMapMock_init() internal initializer { function __EnumerableMapMock_init() internal initializer {
......
...@@ -2,8 +2,8 @@ ...@@ -2,8 +2,8 @@
pragma solidity ^0.8.0; pragma solidity ^0.8.0;
import "../utils/EnumerableSetUpgradeable.sol"; import "../utils/structs/EnumerableSetUpgradeable.sol";
import "../proxy/Initializable.sol"; import "../utils/Initializable.sol";
// Bytes32Set // Bytes32Set
contract EnumerableBytes32SetMockUpgradeable is Initializable { contract EnumerableBytes32SetMockUpgradeable is Initializable {
......
// SPDX-License-Identifier: MIT // SPDX-License-Identifier: MIT
pragma solidity ^0.8.0; pragma solidity ^0.8.0;
import "../proxy/Initializable.sol"; import "../utils/Initializable.sol";
contract EtherReceiverMockUpgradeable is Initializable { contract EtherReceiverMockUpgradeable is Initializable {
function __EtherReceiverMock_init() internal initializer { function __EtherReceiverMock_init() internal initializer {
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
pragma solidity ^0.8.0; pragma solidity ^0.8.0;
import "../proxy/Initializable.sol"; import "../utils/Initializable.sol";
/** /**
* @title InitializableMock * @title InitializableMock
......
...@@ -2,8 +2,8 @@ ...@@ -2,8 +2,8 @@
pragma solidity ^0.8.0; pragma solidity ^0.8.0;
import "../math/MathUpgradeable.sol"; import "../utils/math/MathUpgradeable.sol";
import "../proxy/Initializable.sol"; import "../utils/Initializable.sol";
contract MathMockUpgradeable is Initializable { contract MathMockUpgradeable is Initializable {
function __MathMock_init() internal initializer { function __MathMock_init() internal initializer {
......
...@@ -2,8 +2,8 @@ ...@@ -2,8 +2,8 @@
pragma solidity ^0.8.0; pragma solidity ^0.8.0;
import { MerkleProofUpgradeable } from "../cryptography/MerkleProofUpgradeable.sol"; import "../utils/cryptography/MerkleProofUpgradeable.sol";
import "../proxy/Initializable.sol"; import "../utils/Initializable.sol";
contract MerkleProofWrapperUpgradeable is Initializable { contract MerkleProofWrapperUpgradeable is Initializable {
function __MerkleProofWrapper_init() internal initializer { function __MerkleProofWrapper_init() internal initializer {
......
...@@ -2,11 +2,11 @@ ...@@ -2,11 +2,11 @@
pragma solidity ^0.8.0; pragma solidity ^0.8.0;
import "../proxy/Initializable.sol"; import "../utils/Initializable.sol";
// Sample contracts showing upgradeability with multiple inheritance. // Sample contracts showing upgradeability with multiple inheritance.
// Child contract inherits from Father and Mother contracts, and Father extends from Gramps. // Child contract inherits from Father and Mother contracts, and Father extends from Gramps.
// //
// Human // Human
// / \ // / \
// | Gramps // | Gramps
......
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
pragma solidity ^0.8.0; pragma solidity ^0.8.0;
import "../access/OwnableUpgradeable.sol"; import "../access/OwnableUpgradeable.sol";
import "../proxy/Initializable.sol"; import "../utils/Initializable.sol";
contract OwnableMockUpgradeable is Initializable, OwnableUpgradeable { function __OwnableMock_init() internal initializer { contract OwnableMockUpgradeable is Initializable, OwnableUpgradeable { function __OwnableMock_init() internal initializer {
__Context_init_unchained(); __Context_init_unchained();
......
...@@ -2,8 +2,8 @@ ...@@ -2,8 +2,8 @@
pragma solidity ^0.8.0; pragma solidity ^0.8.0;
import "../utils/PausableUpgradeable.sol"; import "../security/PausableUpgradeable.sol";
import "../proxy/Initializable.sol"; import "../utils/Initializable.sol";
contract PausableMockUpgradeable is Initializable, PausableUpgradeable { contract PausableMockUpgradeable is Initializable, PausableUpgradeable {
bool public drasticMeasureTaken; bool public drasticMeasureTaken;
......
...@@ -2,8 +2,8 @@ ...@@ -2,8 +2,8 @@
pragma solidity ^0.8.0; pragma solidity ^0.8.0;
import "../payment/PullPaymentUpgradeable.sol"; import "../security/PullPaymentUpgradeable.sol";
import "../proxy/Initializable.sol"; import "../utils/Initializable.sol";
// mock class using PullPayment // mock class using PullPayment
contract PullPaymentMockUpgradeable is Initializable, PullPaymentUpgradeable { contract PullPaymentMockUpgradeable is Initializable, PullPaymentUpgradeable {
......
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
pragma solidity ^0.8.0; pragma solidity ^0.8.0;
import "../utils/ContextUpgradeable.sol"; import "../utils/ContextUpgradeable.sol";
import "../proxy/Initializable.sol"; import "../utils/Initializable.sol";
contract ReentrancyAttackUpgradeable is Initializable, ContextUpgradeable { contract ReentrancyAttackUpgradeable is Initializable, ContextUpgradeable {
function __ReentrancyAttack_init() internal initializer { function __ReentrancyAttack_init() internal initializer {
__Context_init_unchained(); __Context_init_unchained();
......
...@@ -2,9 +2,9 @@ ...@@ -2,9 +2,9 @@
pragma solidity ^0.8.0; pragma solidity ^0.8.0;
import "../utils/ReentrancyGuardUpgradeable.sol"; import "../security/ReentrancyGuardUpgradeable.sol";
import "./ReentrancyAttackUpgradeable.sol"; import "./ReentrancyAttackUpgradeable.sol";
import "../proxy/Initializable.sol"; import "../utils/Initializable.sol";
contract ReentrancyMockUpgradeable is Initializable, ReentrancyGuardUpgradeable { contract ReentrancyMockUpgradeable is Initializable, ReentrancyGuardUpgradeable {
uint256 public counter; uint256 public counter;
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
pragma solidity ^0.8.0; pragma solidity ^0.8.0;
import "../proxy/Initializable.sol"; import "../utils/Initializable.sol";
contract Implementation1 is Initializable { contract Implementation1 is Initializable {
uint internal _value; uint internal _value;
......
...@@ -2,8 +2,8 @@ ...@@ -2,8 +2,8 @@
pragma solidity ^0.8.0; pragma solidity ^0.8.0;
import "../utils/SafeCastUpgradeable.sol"; import "../utils/math/SafeCastUpgradeable.sol";
import "../proxy/Initializable.sol"; import "../utils/Initializable.sol";
contract SafeCastMockUpgradeable is Initializable { contract SafeCastMockUpgradeable is Initializable {
function __SafeCastMock_init() internal initializer { function __SafeCastMock_init() internal initializer {
......
...@@ -4,8 +4,8 @@ pragma solidity ^0.8.0; ...@@ -4,8 +4,8 @@ pragma solidity ^0.8.0;
import "../utils/ContextUpgradeable.sol"; import "../utils/ContextUpgradeable.sol";
import "../token/ERC20/IERC20Upgradeable.sol"; import "../token/ERC20/IERC20Upgradeable.sol";
import "../token/ERC20/SafeERC20Upgradeable.sol"; import "../token/ERC20/utils/SafeERC20Upgradeable.sol";
import "../proxy/Initializable.sol"; import "../utils/Initializable.sol";
contract ERC20ReturnFalseMockUpgradeable is Initializable, ContextUpgradeable { contract ERC20ReturnFalseMockUpgradeable is Initializable, ContextUpgradeable {
function __ERC20ReturnFalseMock_init() internal initializer { function __ERC20ReturnFalseMock_init() internal initializer {
......
...@@ -2,8 +2,8 @@ ...@@ -2,8 +2,8 @@
pragma solidity ^0.8.0; pragma solidity ^0.8.0;
import "../math/SafeMathUpgradeable.sol"; import "../utils/math/SafeMathUpgradeable.sol";
import "../proxy/Initializable.sol"; import "../utils/Initializable.sol";
contract SafeMathMockUpgradeable is Initializable { contract SafeMathMockUpgradeable is Initializable {
function __SafeMathMock_init() internal initializer { function __SafeMathMock_init() internal initializer {
......
...@@ -2,8 +2,8 @@ ...@@ -2,8 +2,8 @@
pragma solidity ^0.8.0; pragma solidity ^0.8.0;
import "../math/SignedSafeMathUpgradeable.sol"; import "../utils/math/SignedSafeMathUpgradeable.sol";
import "../proxy/Initializable.sol"; import "../utils/Initializable.sol";
contract SignedSafeMathMockUpgradeable is Initializable { contract SignedSafeMathMockUpgradeable is Initializable {
function __SignedSafeMathMock_init() internal initializer { function __SignedSafeMathMock_init() internal initializer {
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
pragma solidity ^0.8.0; pragma solidity ^0.8.0;
import "../proxy/Initializable.sol"; import "../utils/Initializable.sol";
/** /**
* @title MigratableMockV1 * @title MigratableMockV1
......
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
pragma solidity ^0.8.0; pragma solidity ^0.8.0;
import "../utils/StringsUpgradeable.sol"; import "../utils/StringsUpgradeable.sol";
import "../proxy/Initializable.sol"; import "../utils/Initializable.sol";
contract StringsMockUpgradeable is Initializable { contract StringsMockUpgradeable is Initializable {
function __StringsMock_init() internal initializer { function __StringsMock_init() internal initializer {
......
= Payment
[.readme-notice]
NOTE: This document is better viewed at https://docs.openzeppelin.com/contracts/api/payment
Utilities related to sending and receiving payments. Examples are {PullPayment}, which implements the best security practices when sending funds to third parties, and {PaymentSplitter} to receive incoming payments among a number of beneficiaries.
TIP: When transferring funds to and from untrusted third parties, there is always a security risk of reentrancy. If you would like to learn more about this and ways to protect against it, check out our blog post https://blog.openzeppelin.com/reentrancy-after-istanbul/[Reentrancy After Istanbul].
== Utilities
{{PaymentSplitter}}
{{PullPayment}}
== Escrow
{{Escrow}}
{{ConditionalEscrow}}
{{RefundEscrow}}
= Presets
[.readme-notice]
NOTE: This document is better viewed at https://docs.openzeppelin.com/contracts/api/presets
These contracts integrate different Ethereum standards (ERCs) with custom extensions and modules, showcasing common configurations that are ready to deploy **without having to write any Solidity code**.
They can be used as-is for quick prototyping and testing, but are **also suitable for production environments**.
TIP: Intermediate and advanced users can use these as starting points when writing their own contracts, extending them with custom functionality as they see fit.
== Tokens
{{ERC20PresetMinterPauser}}
{{ERC721PresetMinterPauserAutoId}}
{{ERC1155PresetMinterPauser}}
{{ERC20PresetFixedSupply}}
{{ERC777PresetFixedSupply}}
...@@ -21,8 +21,12 @@ CAUTION: Using upgradeable proxies correctly and securely is a difficult task th ...@@ -21,8 +21,12 @@ CAUTION: Using upgradeable proxies correctly and securely is a difficult task th
{{UpgradeableProxy}} {{UpgradeableProxy}}
== Transparent Proxy
{{TransparentUpgradeableProxy}} {{TransparentUpgradeableProxy}}
{{ProxyAdmin}}
== Beacon == Beacon
{{BeaconProxy}} {{BeaconProxy}}
...@@ -34,9 +38,3 @@ CAUTION: Using upgradeable proxies correctly and securely is a difficult task th ...@@ -34,9 +38,3 @@ CAUTION: Using upgradeable proxies correctly and securely is a difficult task th
== Minimal Clones == Minimal Clones
{{Clones}} {{Clones}}
== Utilities
{{Initializable}}
{{ProxyAdmin}}
...@@ -2,8 +2,8 @@ ...@@ -2,8 +2,8 @@
pragma solidity ^0.8.0; pragma solidity ^0.8.0;
import "./ContextUpgradeable.sol"; import "../utils/ContextUpgradeable.sol";
import "../proxy/Initializable.sol"; import "../utils/Initializable.sol";
/** /**
* @dev Contract module which allows children to implement an emergency stop * @dev Contract module which allows children to implement an emergency stop
......
...@@ -2,8 +2,8 @@ ...@@ -2,8 +2,8 @@
pragma solidity ^0.8.0; pragma solidity ^0.8.0;
import "./escrow/EscrowUpgradeable.sol"; import "../utils/escrow/EscrowUpgradeable.sol";
import "../proxy/Initializable.sol"; import "../utils/Initializable.sol";
/** /**
* @dev Simple implementation of a * @dev Simple implementation of a
......
= Security
[.readme-notice]
NOTE: This document is better viewed at https://docs.openzeppelin.com/contracts/api/security
These contracts aim to cover common security practices.
* {PullPayment}: A pattern that can be used to avoid reentrancy attacks.
* {ReentrancyGuard}: A modifier that can prevent reentrancy during certain functions.
* {Pausable}: A common emergency response mechanism that can pause functionality while a remediation is pending.
TIP: For an overview on reentrancy and the possible mechanisms to prevent it, read our article https://blog.openzeppelin.com/reentrancy-after-istanbul/[Reentrancy After Istanbul].
== Contracts
{{PullPayment}}
{{ReentrancyGuard}}
{{Pausable}}
// SPDX-License-Identifier: MIT // SPDX-License-Identifier: MIT
pragma solidity ^0.8.0; pragma solidity ^0.8.0;
import "../proxy/Initializable.sol"; import "../utils/Initializable.sol";
/** /**
* @dev Contract module that helps prevent reentrant calls to a function. * @dev Contract module that helps prevent reentrant calls to a function.
......
...@@ -3,12 +3,12 @@ ...@@ -3,12 +3,12 @@
pragma solidity ^0.8.0; pragma solidity ^0.8.0;
import "./IERC1155Upgradeable.sol"; import "./IERC1155Upgradeable.sol";
import "./IERC1155MetadataURIUpgradeable.sol";
import "./IERC1155ReceiverUpgradeable.sol"; import "./IERC1155ReceiverUpgradeable.sol";
import "../../utils/ContextUpgradeable.sol"; import "./extensions/IERC1155MetadataURIUpgradeable.sol";
import "../../introspection/ERC165Upgradeable.sol";
import "../../utils/AddressUpgradeable.sol"; import "../../utils/AddressUpgradeable.sol";
import "../../proxy/Initializable.sol"; import "../../utils/ContextUpgradeable.sol";
import "../../utils/introspection/ERC165Upgradeable.sol";
import "../../utils/Initializable.sol";
/** /**
* *
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
pragma solidity ^0.8.0; pragma solidity ^0.8.0;
import "../../introspection/IERC165Upgradeable.sol"; import "../../utils/introspection/IERC165Upgradeable.sol";
/** /**
* _Available since v3.1._ * _Available since v3.1._
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
pragma solidity ^0.8.0; pragma solidity ^0.8.0;
import "../../introspection/IERC165Upgradeable.sol"; import "../../utils/introspection/IERC165Upgradeable.sol";
/** /**
* @dev Required interface of an ERC1155 compliant contract, as defined in the * @dev Required interface of an ERC1155 compliant contract, as defined in the
......
...@@ -32,6 +32,12 @@ NOTE: This core set of contracts is designed to be unopinionated, allowing devel ...@@ -32,6 +32,12 @@ NOTE: This core set of contracts is designed to be unopinionated, allowing devel
{{ERC1155Burnable}} {{ERC1155Burnable}}
== Convenience == Presets
These contracts are preconfigured combinations of the above features. They can be used through inheritance or as models to copy and paste their source code.
{{ERC1155PresetMinterPauser}}
== Utilities
{{ERC1155Holder}} {{ERC1155Holder}}
...@@ -2,8 +2,8 @@ ...@@ -2,8 +2,8 @@
pragma solidity ^0.8.0; pragma solidity ^0.8.0;
import "./ERC1155Upgradeable.sol"; import "../ERC1155Upgradeable.sol";
import "../../proxy/Initializable.sol"; import "../../../utils/Initializable.sol";
/** /**
* @dev Extension of {ERC1155} that allows token holders to destroy both their * @dev Extension of {ERC1155} that allows token holders to destroy both their
......
...@@ -2,9 +2,9 @@ ...@@ -2,9 +2,9 @@
pragma solidity ^0.8.0; pragma solidity ^0.8.0;
import "./ERC1155Upgradeable.sol"; import "../ERC1155Upgradeable.sol";
import "../../utils/PausableUpgradeable.sol"; import "../../../security/PausableUpgradeable.sol";
import "../../proxy/Initializable.sol"; import "../../../utils/Initializable.sol";
/** /**
* @dev ERC1155 token with pausable token transfers, minting and burning. * @dev ERC1155 token with pausable token transfers, minting and burning.
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
pragma solidity ^0.8.0; pragma solidity ^0.8.0;
import "./IERC1155Upgradeable.sol"; import "../IERC1155Upgradeable.sol";
/** /**
* @dev Interface of the optional ERC1155MetadataExtension interface, as defined * @dev Interface of the optional ERC1155MetadataExtension interface, as defined
......
...@@ -2,12 +2,12 @@ ...@@ -2,12 +2,12 @@
pragma solidity ^0.8.0; pragma solidity ^0.8.0;
import "../access/AccessControlUpgradeable.sol"; import "../ERC1155Upgradeable.sol";
import "../utils/ContextUpgradeable.sol"; import "../extensions/ERC1155BurnableUpgradeable.sol";
import "../token/ERC1155/ERC1155Upgradeable.sol"; import "../extensions/ERC1155PausableUpgradeable.sol";
import "../token/ERC1155/ERC1155BurnableUpgradeable.sol"; import "../../../access/AccessControlEnumerableUpgradeable.sol";
import "../token/ERC1155/ERC1155PausableUpgradeable.sol"; import "../../../utils/ContextUpgradeable.sol";
import "../proxy/Initializable.sol"; import "../../../utils/Initializable.sol";
/** /**
* @dev {ERC1155} token, including: * @dev {ERC1155} token, including:
...@@ -23,10 +23,7 @@ import "../proxy/Initializable.sol"; ...@@ -23,10 +23,7 @@ import "../proxy/Initializable.sol";
* roles, as well as the default admin role, which will let it grant both minter * roles, as well as the default admin role, which will let it grant both minter
* and pauser roles to other accounts. * and pauser roles to other accounts.
*/ */
contract ERC1155PresetMinterPauserUpgradeable is Initializable, ContextUpgradeable, AccessControlUpgradeable, ERC1155BurnableUpgradeable, ERC1155PausableUpgradeable { contract ERC1155PresetMinterPauserUpgradeable is Initializable, ContextUpgradeable, AccessControlEnumerableUpgradeable, ERC1155BurnableUpgradeable, ERC1155PausableUpgradeable {
function initialize(string memory uri) public virtual initializer {
__ERC1155PresetMinterPauser_init(uri);
}
bytes32 public constant MINTER_ROLE = keccak256("MINTER_ROLE"); bytes32 public constant MINTER_ROLE = keccak256("MINTER_ROLE");
bytes32 public constant PAUSER_ROLE = keccak256("PAUSER_ROLE"); bytes32 public constant PAUSER_ROLE = keccak256("PAUSER_ROLE");
...@@ -37,6 +34,7 @@ contract ERC1155PresetMinterPauserUpgradeable is Initializable, ContextUpgradeab ...@@ -37,6 +34,7 @@ contract ERC1155PresetMinterPauserUpgradeable is Initializable, ContextUpgradeab
function __ERC1155PresetMinterPauser_init(string memory uri) internal initializer { function __ERC1155PresetMinterPauser_init(string memory uri) internal initializer {
__Context_init_unchained(); __Context_init_unchained();
__AccessControl_init_unchained(); __AccessControl_init_unchained();
__AccessControlEnumerable_init_unchained();
__ERC165_init_unchained(); __ERC165_init_unchained();
__ERC1155_init_unchained(uri); __ERC1155_init_unchained(uri);
__ERC1155Burnable_init_unchained(); __ERC1155Burnable_init_unchained();
......
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
pragma solidity ^0.8.0; pragma solidity ^0.8.0;
import "./ERC1155ReceiverUpgradeable.sol"; import "./ERC1155ReceiverUpgradeable.sol";
import "../../proxy/Initializable.sol"; import "../../../utils/Initializable.sol";
/** /**
* @dev _Available since v3.1._ * @dev _Available since v3.1._
......
...@@ -2,9 +2,9 @@ ...@@ -2,9 +2,9 @@
pragma solidity ^0.8.0; pragma solidity ^0.8.0;
import "./IERC1155ReceiverUpgradeable.sol"; import "../IERC1155ReceiverUpgradeable.sol";
import "../../introspection/ERC165Upgradeable.sol"; import "../../../utils/introspection/ERC165Upgradeable.sol";
import "../../proxy/Initializable.sol"; import "../../../utils/Initializable.sol";
/** /**
* @dev _Available since v3.1._ * @dev _Available since v3.1._
......
...@@ -2,9 +2,9 @@ ...@@ -2,9 +2,9 @@
pragma solidity ^0.8.0; pragma solidity ^0.8.0;
import "../../utils/ContextUpgradeable.sol";
import "./IERC20Upgradeable.sol"; import "./IERC20Upgradeable.sol";
import "../../proxy/Initializable.sol"; import "../../utils/ContextUpgradeable.sol";
import "../../utils/Initializable.sol";
/** /**
* @dev Implementation of the {IERC20} interface. * @dev Implementation of the {IERC20} interface.
......
...@@ -48,6 +48,22 @@ NOTE: This core set of contracts is designed to be unopinionated, allowing devel ...@@ -48,6 +48,22 @@ NOTE: This core set of contracts is designed to be unopinionated, allowing devel
{{ERC20Capped}} {{ERC20Capped}}
== Draft EIPs
The following EIPs are still in Draft status. Due to their nature as drafts, the details of these contracts may change and we cannot guarantee their xref:ROOT:releases-stability.adoc[stability]. Minor releases of OpenZeppelin Contracts may contain breaking changes for the contracts in this directory, which will be duly announced in the https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/CHANGELOG.md[changelog]. The EIPs included here are used by projects in production and this may make them less likely to change significantly.
{{IERC20Permit}}
{{ERC20Permit}}
== Presets
These contracts are preconfigured combinations of the above features. They can be used through inheritance or as models to copy and paste their source code.
{{ERC20PresetMinterPauser}}
{{ERC20PresetFixedSupply}}
== Utilities == Utilities
{{SafeERC20}} {{SafeERC20}}
......
...@@ -2,9 +2,9 @@ ...@@ -2,9 +2,9 @@
pragma solidity ^0.8.0; pragma solidity ^0.8.0;
import "../../utils/ContextUpgradeable.sol"; import "../ERC20Upgradeable.sol";
import "./ERC20Upgradeable.sol"; import "../../../utils/ContextUpgradeable.sol";
import "../../proxy/Initializable.sol"; import "../../../utils/Initializable.sol";
/** /**
* @dev Extension of {ERC20} that allows token holders to destroy both their own * @dev Extension of {ERC20} that allows token holders to destroy both their own
......
...@@ -2,8 +2,8 @@ ...@@ -2,8 +2,8 @@
pragma solidity ^0.8.0; pragma solidity ^0.8.0;
import "./ERC20Upgradeable.sol"; import "../ERC20Upgradeable.sol";
import "../../proxy/Initializable.sol"; import "../../../utils/Initializable.sol";
/** /**
* @dev Extension of {ERC20} that adds a cap to the supply of tokens. * @dev Extension of {ERC20} that adds a cap to the supply of tokens.
......
...@@ -2,9 +2,9 @@ ...@@ -2,9 +2,9 @@
pragma solidity ^0.8.0; pragma solidity ^0.8.0;
import "./ERC20Upgradeable.sol"; import "../ERC20Upgradeable.sol";
import "../../utils/PausableUpgradeable.sol"; import "../../../security/PausableUpgradeable.sol";
import "../../proxy/Initializable.sol"; import "../../../utils/Initializable.sol";
/** /**
* @dev ERC20 token with pausable token transfers, minting and burning. * @dev ERC20 token with pausable token transfers, minting and burning.
......
...@@ -2,10 +2,10 @@ ...@@ -2,10 +2,10 @@
pragma solidity ^0.8.0; pragma solidity ^0.8.0;
import "../../utils/ArraysUpgradeable.sol"; import "../ERC20Upgradeable.sol";
import "../../utils/CountersUpgradeable.sol"; import "../../../utils/ArraysUpgradeable.sol";
import "./ERC20Upgradeable.sol"; import "../../../utils/CountersUpgradeable.sol";
import "../../proxy/Initializable.sol"; import "../../../utils/Initializable.sol";
/** /**
* @dev This contract extends an ERC20 token with a snapshot mechanism. When a snapshot is created, the balances and * @dev This contract extends an ERC20 token with a snapshot mechanism. When a snapshot is created, the balances and
......
...@@ -2,12 +2,12 @@ ...@@ -2,12 +2,12 @@
pragma solidity ^0.8.0; pragma solidity ^0.8.0;
import "../token/ERC20/ERC20Upgradeable.sol"; import "./draft-IERC20PermitUpgradeable.sol";
import "./IERC20PermitUpgradeable.sol"; import "../ERC20Upgradeable.sol";
import "../cryptography/ECDSAUpgradeable.sol"; import "../../../utils/cryptography/draft-EIP712Upgradeable.sol";
import "../utils/CountersUpgradeable.sol"; import "../../../utils/cryptography/ECDSAUpgradeable.sol";
import "./EIP712Upgradeable.sol"; import "../../../utils/CountersUpgradeable.sol";
import "../proxy/Initializable.sol"; import "../../../utils/Initializable.sol";
/** /**
* @dev Implementation of the ERC20 Permit extension allowing approvals to be made via signatures, as defined in * @dev Implementation of the ERC20 Permit extension allowing approvals to be made via signatures, as defined in
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment