Commit 7fbc597b by github-actions

Transpile bcb1f11d

parent 0983717d
# <img src="logo.svg" alt="OpenZeppelin" height="40px">
# <img src="icon.svg" alt="OpenZeppelin" height="40px" align="left"> OpenZeppelin Contracts Upgrade Safe
[![Docs](https://img.shields.io/badge/docs-%F0%9F%93%84-blue)](https://docs.openzeppelin.com/contracts)
[![NPM Package](https://img.shields.io/npm/v/@openzeppelin/contracts.svg)](https://www.npmjs.org/package/@openzeppelin/contracts)
[![Coverage Status](https://codecov.io/gh/OpenZeppelin/openzeppelin-contracts/graph/badge.svg)](https://codecov.io/gh/OpenZeppelin/openzeppelin-contracts)
[![Docs](https://img.shields.io/badge/docs-%F0%9F%93%84-blue)](https://docs.openzeppelin.com/contracts/upgrade-safe)
[![NPM Package](https://img.shields.io/npm/v/@openzeppelin/contracts-upgrade-safe.svg)](https://www.npmjs.org/package/@openzeppelin/contracts-upgrade-safe)
**A library for secure smart contract development.** Build on a solid foundation of community-vetted code.
This repository hosts the Upgrade Safe variant of [OpenZeppelin Contracts], meant for use in upgradeable contracts. This variant is available as separate package called `@openzeppelin/contracts-upgrade-safe`.
* Implementations of standards like [ERC20](https://docs.openzeppelin.com/contracts/erc20) and [ERC721](https://docs.openzeppelin.com/contracts/erc721).
* Flexible [role-based permissioning](https://docs.openzeppelin.com/contracts/access-control) scheme.
* Reusable [Solidity components](https://docs.openzeppelin.com/contracts/utilities) to build custom contracts and complex decentralized systems.
* First-class integration with the [Gas Station Network](https://docs.openzeppelin.com/contracts/gsn) for systems with no gas fees!
* [Audited](https://github.com/OpenZeppelin/openzeppelin-contracts/tree/master/audit) by leading security firms (_last full audit on v2.0.0_).
[OpenZeppelin Contracts]: https://github.com/OpenZeppelin/openzeppelin-contracts
It follows all of the rules for xref:upgrades-plugins::writing-upgradeable.adoc[Writing Upgradeable Contracts]: constructors are replaced by initializer functions, state variables are initialized in initializer functions, and we additionally check for storage incompatibilities across minor versions.
[Writing Upgradeable Contracts]: https://docs.openzeppelin.com/upgrades-plugins/writing-upgradeable
## Overview
### Installation
```console
$ npm install @openzeppelin/contracts
$ npm install @openzeppelin/contracts-upgrade-safe
```
OpenZeppelin Contracts features a [stable API](https://docs.openzeppelin.com/contracts/releases-stability#api-stability), which means your contracts won't break unexpectedly when upgrading to a newer minor version.
### Usage
Once installed, you can use the contracts in the library by importing them:
The package replicates the structure of the main OpenZeppelin Contracts package, but every file and contract has the suffix `UpgradeSafe`.
```solidity
pragma solidity ^0.6.0;
```diff
-import "@openzeppelin/contracts/token/ERC721/ERC721.sol";
+import "@openzeppelin/contracts-upgrade-safe/token/ERC721/ERC721UpgradeSafe.sol";
import "@openzeppelin/contracts/token/ERC721/ERC721.sol";
-contract MyCollectible is ERC721 {
+contract MyCollectible is ERC721UpgradeSafe {
```
Constructors are replaced by internal initializer functions following the naming convention `__{ContractName}_init`. Since these are internal, you must always define your own public initializer function and call the parent initializer of the contract you extend.
contract MyCollectible is ERC721 {
constructor() ERC721("MyCollectible", "MCO") public {
```diff
- constructor() ERC721("MyCollectible", "MCO") public {
+ function initialize() initializer public {
+ __ERC721_init("MyCollectible", "MCO");
}
}
```
> **Caution**
>
> Use with multiple inheritance requires special care. Initializer functions are not linearized by the compiler like constructors. Because of this, each `__{ContractName}_init` function embeds the linearized calls to all parent initializers. As a consequence, calling two of these `init` functions can potentially initialize the same contract twice.
>
> The function `__{ContractName}_init_unchained` found in every contract is the initializer function minus the calls to parent initializers, and can be used to avoid the double initialization problem, but doing this manually is not recommended. We hope to be able to implement safety checks for this in future versions of the Upgrades Plugins.
_If you're new to smart contract development, head to [Developing Smart Contracts](https://docs.openzeppelin.com/learn/developing-smart-contracts) to learn about creating a new project and compiling your contracts._
To keep your system secure, you should **always** use the installed code as-is, and neither copy-paste it from online sources, nor modify it yourself. The library is designed so that only the contracts and functions you use are deployed, so you don't need to worry about it needlessly increasing gas costs.
......
......@@ -123,7 +123,7 @@ contract GSNRecipientERC20FeeUpgradeSafe is Initializable, GSNRecipientUpgradeSa
*/
// solhint-disable-next-line contract-name-camelcase
contract __unstable__ERC20OwnedUpgradeSafe is Initializable, ERC20UpgradeSafe, OwnableUpgradeSafe {
function initialize(string memory name, string memory symbol) external initializer {
function initialize(string memory name, string memory symbol) public virtual initializer {
____unstable__ERC20Owned_init(name, symbol);
}
uint256 private constant _UINT256_MAX = 2**256 - 1;
......
......@@ -21,7 +21,7 @@ import "../../proxy/Initializable.sol";
* to the escrow's deposit and withdraw.
*/
contract EscrowUpgradeSafe is Initializable, OwnableUpgradeSafe {
function initialize() external initializer {
function initialize() public virtual initializer {
__Escrow_init();
}
function __Escrow_init() internal initializer {
......
......@@ -24,6 +24,9 @@ import "../proxy/Initializable.sol";
* and pauser roles to other accounts.
*/
contract ERC1155PresetMinterPauserUpgradeSafe is Initializable, ContextUpgradeSafe, AccessControlUpgradeSafe, ERC1155BurnableUpgradeSafe, ERC1155PausableUpgradeSafe {
function initialize(string memory uri) public virtual initializer {
__ERC1155PresetMinterPauser_init(uri);
}
bytes32 public constant MINTER_ROLE = keccak256("MINTER_ROLE");
bytes32 public constant PAUSER_ROLE = keccak256("PAUSER_ROLE");
......
......@@ -24,6 +24,9 @@ import "../proxy/Initializable.sol";
* and pauser roles to other accounts.
*/
contract ERC20PresetMinterPauserUpgradeSafe is Initializable, ContextUpgradeSafe, AccessControlUpgradeSafe, ERC20BurnableUpgradeSafe, ERC20PausableUpgradeSafe {
function initialize(string memory name, string memory symbol) public virtual initializer {
__ERC20PresetMinterPauser_init(name, symbol);
}
bytes32 public constant MINTER_ROLE = keccak256("MINTER_ROLE");
bytes32 public constant PAUSER_ROLE = keccak256("PAUSER_ROLE");
......
......@@ -26,6 +26,9 @@ import "../proxy/Initializable.sol";
* and pauser roles to other accounts.
*/
contract ERC721PresetMinterPauserAutoIdUpgradeSafe is Initializable, ContextUpgradeSafe, AccessControlUpgradeSafe, ERC721BurnableUpgradeSafe, ERC721PausableUpgradeSafe {
function initialize(string memory name, string memory symbol, string memory baseURI) public virtual initializer {
__ERC721PresetMinterPauserAutoId_init(name, symbol, baseURI);
}
using CountersUpgradeSafe for CountersUpgradeSafe.Counter;
bytes32 public constant MINTER_ROLE = keccak256("MINTER_ROLE");
......
<?xml version="1.0" encoding="UTF-8"?>
<svg width="180px" height="200px" viewBox="0 0 180 200" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
<!-- Generator: Sketch 53.2 (72643) - https://sketchapp.com -->
<title>OZ_icon_color</title>
<desc>Created with Sketch.</desc>
<g id="presentación" stroke="none" stroke-width="1" fill="none" fill-rule="evenodd">
<g id="OZ_icon_color">
<path d="M179.670444,199.932333 L179.670444,147.932333 L123.270887,147.932333 C107.93329,147.932333 93.7259335,156.016333 85.8704806,169.214333 L67.5860074,199.932333 L179.670444,199.932333 Z" id="Stroke-1" fill="#63D2F9"></path>
<polygon id="Stroke-3" fill="#4E5EE4" points="0.166292052 0.1667 0.166292052 52.1667 148.717863 52.1667 179.670543 0.1667"></polygon>
<path d="M71.2615009,81.4347667 L0.329855823,199.932433 L60.7619445,199.932433 L145.583534,58.1667667 L112.212665,58.1667667 C95.4274159,58.1667667 79.8768799,67.0024333 71.2615009,81.4347667 Z" id="Stroke-5" fill="#63B0F9"></path>
</g>
</g>
</svg>
\ No newline at end of file
......@@ -7,4 +7,8 @@ npm run compile
# -D: delete original and excluded files
# -i: use included Initializable
# -x: exclude all proxy contracts
npx @openzeppelin/upgrade-safe-transpiler -D -i contracts/proxy/Initializable.sol -x 'contracts/proxy/**/*'
# -p: emit public initializer
npx @openzeppelin/upgrade-safe-transpiler -D \
-i contracts/proxy/Initializable.sol \
-x 'contracts/proxy/**/*' \
-p 'contracts/presets/**/*'
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