• Stars
    star
    596
  • Rank 72,719 (Top 2 %)
  • Language
    TypeScript
  • License
    MIT License
  • Created almost 4 years ago
  • Updated 14 days ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Plugins for Hardhat and Foundry to deploy and manage upgradeable contracts on Ethereum.

OpenZeppelin Upgrades

Docs Coverage Status

Integrate upgrades into your existing workflow. Plugins for Hardhat and Truffle to deploy and manage upgradeable contracts on Ethereum.

  • Deploy upgradeable contracts.
  • Upgrade deployed contracts.
  • Manage proxy admin rights.
  • Easily use in tests.

Installation

Hardhat

npm install --save-dev @openzeppelin/hardhat-upgrades
npm install --save-dev @nomicfoundation/hardhat-ethers ethers # peer dependencies
// hardhat.config.js
require('@openzeppelin/hardhat-upgrades');

Truffle

npm install --save-dev @openzeppelin/truffle-upgrades

Usage

See the documentation for each plugin, or take a look at the sample code snippets below.

Hardhat Truffle

Hardhat users will be able to write scripts that use the plugin to deploy or upgrade a contract, and manage proxy admin rights.

const { ethers, upgrades } = require("hardhat");

async function main() {
  // Deploying
  const Box = await ethers.getContractFactory("Box");
  const instance = await upgrades.deployProxy(Box, [42]);
  await instance.waitForDeployment();

  // Upgrading
  const BoxV2 = await ethers.getContractFactory("BoxV2");
  const upgraded = await upgrades.upgradeProxy(await instance.getAddress(), BoxV2);
}

main();

Truffle users will be able to write migrations that use the plugin to deploy or upgrade a contract, or manage proxy admin rights.

const { deployProxy, upgradeProxy } = require('@openzeppelin/truffle-upgrades');

const Box = artifacts.require('Box');
const BoxV2 = artifacts.require('BoxV2');

module.exports = async function (deployer) {
  const instance = await deployProxy(Box, [42], { deployer });
  const upgraded = await upgradeProxy(instance.address, BoxV2, { deployer });
}

Whether you're using Hardhat or Truffle, you can use the plugin in your tests to ensure everything works as expected.

it('works before and after upgrading', async function () {
  const instance = await upgrades.deployProxy(Box, [42]);
  assert.strictEqual(await instance.retrieve(), 42);
  
  await upgrades.upgradeProxy(instance, BoxV2);
  assert.strictEqual(await instance.retrieve(), 42);
});

How do the plugins work?

Both plugins provide functions which take care of managing upgradeable deployments of your contracts.

For example, deployProxy does the following:

  1. Validate that the implementation is upgrade safe

  2. Deploy a proxy admin for your project (if needed)

  3. Check if there is an implementation contract deployed with the same bytecode, and deploy one if not

  4. Create and initialize the proxy contract

And when you call upgradeProxy:

  1. Validate that the new implementation is upgrade safe and is compatible with the previous one

  2. Check if there is an implementation contract deployed with the same bytecode, and deploy one if not

  3. Upgrade the proxy to use the new implementation contract

The plugins will keep track of all the implementation contracts you have deployed in an .openzeppelin folder in the project root, as well as the proxy admin. You will find one file per network there. It is advised that you commit to source control the files for all networks except the development ones (you may see them as .openzeppelin/unknown-*.json).

Note: the format of the files within the .openzeppelin folder is not compatible with those of the OpenZeppelin CLI. If you want to use these plugins for an existing OpenZeppelin CLI project, we will be sharing soon a guide on how to migrate.

Proxy patterns

The plugins support the UUPS, transparent, and beacon proxy patterns. UUPS and transparent proxies are upgraded individually, whereas any number of beacon proxies can be upgraded atomically at the same time by upgrading the beacon that they point to. For more details on the different proxy patterns available, see the documentation for Proxies.

For UUPS and transparent proxies, use deployProxy and upgradeProxy as shown above. For beacon proxies, use deployBeacon, deployBeaconProxy, and upgradeBeacon. See the documentation for Hardhat Upgrades and Truffle Upgrades for examples.

Managing ownership

Transparent proxies define an admin address which has the rights to upgrade them. By default, the admin is a proxy admin contract deployed behind the scenes. You can change the admin of a proxy by calling the admin.changeProxyAdmin function in the plugin. Keep in mind that the admin of a proxy can only upgrade it, but not interact with the implementation contract. Read here for more info on this restriction.

The proxy admin contract also defines an owner address which has the rights to operate it. By default, this address is the externally owned account used during deployment. You can change the proxy admin owner by calling the admin.transferProxyAdminOwnership function in the plugin. Note that changing the proxy admin owner effectively transfers the power to upgrade any proxy in your whole project to the new owner, so use with care. Refer to each plugin documentation for more details on the admin functions.

UUPS and beacon proxies do not use admin addresses. UUPS proxies rely on an _authorizeUpgrade function to be overridden to include access restriction to the upgrade mechanism, whereas beacon proxies are upgradable only by the owner of their corresponding beacon.

Once you have transferred the rights to upgrade a proxy or beacon to another address, you can still use your local setup to validate and deploy the implementation contract. The plugins include a prepareUpgrade function that will validate that the new implementation is upgrade-safe and compatible with the previous one, and deploy it using your local Ethereum account. You can then execute the upgrade itself from the admin or owner address. You can also use the proposeUpgrade function to automatically set up the upgrade in Defender Admin.

Community

Join the OpenZeppelin forum to ask questions or discuss about these plugins, smart contracts upgrades, or anything related to Ethereum development!

License

OpenZeppelin Upgrade plugins are released under the MIT License.

More Repositories

1

openzeppelin-contracts

OpenZeppelin Contracts is a library for secure smart contract development.
JavaScript
24,223
star
2

ethernaut

Web3/Solidity based wargame
Solidity
1,910
star
3

openzeppelin-contracts-upgradeable

Upgradeable variant of OpenZeppelin Contracts, meant for use in upgradeable contracts.
JavaScript
947
star
4

cairo-contracts

OpenZeppelin Contracts written in Cairo for Starknet, a decentralized ZK Rollup
Rust
781
star
5

awesome-openzeppelin

Blockchain educational resources curated by the OpenZeppelin team
741
star
6

damn-vulnerable-defi

Solidity
644
star
7

openzeppelin-sdk

OpenZeppelin SDK repository for CLI and upgrades.js. No longer actively developed.
JavaScript
433
star
8

solidity-docgen

Documentation generator for Solidity projects
TypeScript
428
star
9

workshops

Code and slides for OpenZeppelin Workshops
JavaScript
422
star
10

openzeppelin-test-helpers

Assertion library for Ethereum smart contract testing
JavaScript
415
star
11

merkle-tree

A JavaScript library to generate merkle trees and merkle proofs.
TypeScript
407
star
12

openzeppelin-labs

A space for the community to interact and exchange ideas on the OpenZeppelin platform. Do not use in production!
JavaScript
374
star
13

nile

CLI tool to develop StarkNet projects written in Cairo
Python
323
star
14

contracts-wizard

Interactive smart contract generator based on OpenZeppelin Contracts.
TypeScript
233
star
15

exploit-uniswap

Exploiting a Uniswap exchange that uses an ERC777 token by leveraging the reentrant microtrading attack vector
JavaScript
172
star
16

openzeppelin-subgraphs

Subgraph schema and templates to index the activity of OpenZeppelin Contracts.
TypeScript
140
star
17

openzeppelin-foundry-upgrades

Foundry library for deploying and managing upgradeable contracts
Solidity
132
star
18

solidity-jwt

Experiments with Solidity JWT. Do not use in production.
Solidity
131
star
19

starter-kit

An OpenZeppelin starter kit containing React, OpenZeppelin SDK & OpenZeppelin Contracts.
JavaScript
122
star
20

token-vesting-ui

UI for TokenVesting contract from OpenZeppelin. No longer maintained
JavaScript
97
star
21

openzeppelin-test-environment

[Not actively maintained] One-line setup for blazing-fast smart contracts tests
Solidity
90
star
22

solidity-ast

TypeScript types and a JSON Schema for the Solidity AST
JavaScript
88
star
23

ctf-2024

⚑️ Ethernaut CTF 2024 Challenges & Solutions
Solidity
72
star
24

contract-bots-gang

TypeScript
69
star
25

sample-crowdsale-starter

Empty sample starter truffle project for using zeppelin-solidity for a crowdsale
JavaScript
67
star
26

nile-rs

CLI tool to develop Starknet projects written in Cairo
Rust
56
star
27

defender-client

Monorepo for all defender-client npm packages
TypeScript
56
star
28

defender-autotask-examples

Example snippets for Defender Autotasks
JavaScript
48
star
29

crafty

A collectibles crafting game. Built using the OpenZeppelin SDK.
JavaScript
48
star
30

polkadot-runtime-templates

A generic template for Substrate Runtime
Rust
45
star
31

openzeppelin-network.js

An easy to use and reliable library that provides one line access to Web3 API.
TypeScript
44
star
32

docs.openzeppelin.com

Source for the OpenZeppelin documentation site
SCSS
43
star
33

starter-kit-gsn

An OpenZeppelin starter kit focused on GSN.
JavaScript
40
star
34

openzeppelin-gsn-provider

Web3 provider for the Gas Station Network
JavaScript
39
star
35

starter-kit-tutorial

An OpenZeppelin starter kit tutorial containing React, OpenZeppelin SDK & OpenZeppelin Contracts.
JavaScript
38
star
36

defender-docs

Security Management to Protect the Open Economy
31
star
37

openzeppelin.org

Source code for OpenZeppelin website
23
star
38

compound-monitoring

JavaScript
22
star
39

defender-templates

Templates for using OpenZeppelin Defender using Serverless configurations
JavaScript
22
star
40

openzeppelin-gsn-helpers

Test and development helper methods and scripts for GSN
JavaScript
21
star
41

upgrades-safe-app

TypeScript
20
star
42

gsn-sample-chat_app

OpenZeppelin starter-kit based GSN tutorial for a Chat App
JavaScript
20
star
43

openzeppelin-transpiler

TypeScript
20
star
44

defender-serverless

Configure a Defender environment via code
TypeScript
20
star
45

gnosis-multisig

Allows multiple parties to agree on transactions before execution. Forked from Gnosis multisig repository.
CSS
20
star
46

configs

Code style guidelines and rules for OpenZeppelin projects
JavaScript
19
star
47

openzeppelin-contracts-docs

OpenZeppelin documentation site configuration
JavaScript
19
star
48

defender-example-metatx-relay

Example meta-tx relay built using Defender
JavaScript
16
star
49

accesscontrol-explorer

Work in progress explorer for AccessControl roles
Svelte
15
star
50

openzeppelin-contract-loader

Load contract ABIs from built artifacts and return contract objects
JavaScript
15
star
51

sample-crosschain-env

Test environments for crosschain operations
Shell
15
star
52

openzeppelin-whitepaper

LaTeX sources for the OpenZeppelin Platform Whitepaper
Makefile
14
star
53

erc20-onboarding

ERC20 token on-boarding on the OpenZeppelin SDK platform
JavaScript
14
star
54

openzeppelin.com

Main website of OpenZeppelin
HTML
13
star
55

defender-sdk

Defender SDK
TypeScript
12
star
56

ethernaut-leaderboard

JavaScript
11
star
57

openzeppelin-team-nft

NFT for OpenZeppelin Team
JavaScript
11
star
58

solidity-loader

Solidity Hot Loader for Starter Kits. Not currently maintained
JavaScript
11
star
59

proxy-explorer

πŸ‘· Under construction!
TypeScript
11
star
60

gsn-site

The Ethereum Gas Station Network Alliance Landing Page and Tools
JavaScript
11
star
61

openzeppelin-nile-upgrades

Plugin for Nile to deploy and manage upgradeable contracts on StarkNet.
Python
10
star
62

proposal143

Solidity
10
star
63

compound-re-enable-dsr-proposal

Foundry simulation for Compound Proposal for re-enabling MakerDAO DSR
Solidity
10
star
64

highlightjs-cairo

JavaScript
8
star
65

gsn-relayer

GSN relayer server, forked from openeth-dev/gsn
Go
8
star
66

web3-gsn-faucet-provider

JavaScript
8
star
67

token-vouching

Vouching contracts and scripts for the OpenZeppelin SDK token
JavaScript
7
star
68

compound-governance-proposal-behavior

Set of tests to reflect the proposal lifecycle behavior
Solidity
7
star
69

defender-as-code

TypeScript
7
star
70

zeppelin.solutions

Institutional website
6
star
71

research-cryptography

OpenZeppelin Research group working repository
Jupyter Notebook
6
star
72

openzeppelin-token-registry

OpenZeppelin Ethereum Packages registry
JavaScript
5
star
73

access-manager-explorer

TypeScript
5
star
74

compound-assets-listing

Template repo to define assets listing on Compound
4
star
75

compound-security-policies

Security roles and responsibilities for Compound
4
star
76

fuzzy-import-parser

TypeScript
4
star
77

gsn-tools

Set of tools to manage the GSN
JavaScript
4
star
78

docs-utils

Scripts used for docs previews in pull requests across OpenZeppelin projects
JavaScript
4
star
79

secure-development-cookbook

The essential blueprint for crafting secure protocols
JavaScript
4
star
80

discourse-highlightjs-langs

HTML
3
star
81

openzeppelin-upgrades-migration-example

3
star
82

governor-quorum-bot

Forta detection bot to alert about changes in quorum quantity in a Governor contract
TypeScript
3
star
83

polkadot-evm-runtime-template

EVM runtime template for Polkadot parachains
Rust
3
star
84

defender-serverless-workshop

JavaScript
2
star
85

futureswap-artifacts

Compiled bytecode related to our FutureSwap audits for public viewing
2
star
86

cto.openzeppelin.com

Description of the CTO job opening at OpenZeppelin
HTML
2
star
87

ctf-infra

🧱 Infrastructure for Ethernaut CTF 2024
Python
2
star
88

tech-coaching

A place to keep study materials associated with the tech coaching
HTML
2
star
89

slack.openzeppelin.org

https://openzeppelin-slack.netlify.com/ Source for https://slack.openzeppelin.org/
1
star
90

sgp

Solidity ANTLR4 grammar Python parser
Python
1
star
91

netlify-redirects

Redirection rules for various old websites
1
star
92

defender-subgraphs

Access Control subgraph toolkit for Defender
TypeScript
1
star