Skip to content

Commit ff197f7

Browse files
ericglauernestognw
andauthored
Remove Truffle, add placeholders for Foundry documentation (#956)
Co-authored-by: Ernesto García <[email protected]>
1 parent 848983a commit ff197f7

File tree

129 files changed

+128
-9300
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

129 files changed

+128
-9300
lines changed

README.md

+20-82
Original file line numberDiff line numberDiff line change
@@ -3,124 +3,62 @@
33
[![Docs](https://img.shields.io/badge/docs-%F0%9F%93%84-blue)](https://docs.openzeppelin.com/upgrades-plugins)
44
[![Coverage Status](https://codecov.io/gh/OpenZeppelin/openzeppelin-upgrades/graph/badge.svg)](https://codecov.io/gh/OpenZeppelin/openzeppelin-upgrades)
55

6-
**Integrate upgrades into your existing workflow.** Plugins for [Hardhat](https://hardhat.org/) and [Truffle](https://www.trufflesuite.com/truffle) to deploy and manage upgradeable contracts on Ethereum.
6+
**Integrate upgrades into your existing workflow.** Plugins for [Hardhat](https://hardhat.org/) and [Foundry](https://book.getfoundry.sh/) to deploy and manage upgradeable contracts on Ethereum.
77

88
- Deploy upgradeable contracts.
99
- Upgrade deployed contracts.
1010
- Manage proxy admin rights.
1111
- Easily use in tests.
1212

13-
## Installation
13+
## Installation and Usage
1414

15-
### Hardhat
15+
See the documentation for each plugin:
1616

17-
```
18-
npm install --save-dev @openzeppelin/hardhat-upgrades
19-
npm install --save-dev @nomicfoundation/hardhat-ethers ethers # peer dependencies
20-
```
21-
22-
```js
23-
// hardhat.config.js
24-
require('@openzeppelin/hardhat-upgrades');
25-
```
26-
27-
### Truffle
28-
29-
```
30-
npm install --save-dev @openzeppelin/truffle-upgrades
31-
```
32-
33-
## Usage
34-
35-
See the documentation for each plugin, or take a look at the sample code snippets below.
36-
37-
| [<img src="assets/hardhat.svg" height="20px" width="30px" alt="">Hardhat](./packages/plugin-hardhat/README.md)| [<img src="assets/truffle.svg" height="20px" width="30px" alt="">Truffle](./packages/plugin-truffle/README.md) |
17+
| [<img src="assets/hardhat.svg" height="20px" width="30px" alt="">Hardhat](./packages/plugin-hardhat/README.md)| [<img src="https://avatars.githubusercontent.com/u/99892494?s=20&v=4" height="20px" width="20px" alt=""> Foundry](https://github.com/OpenZeppelin/openzeppelin-foundry-upgrades) |
3818
|-|-|
3919

40-
Hardhat users will be able to write [scripts](https://hardhat.org/guides/scripts.html) that use the plugin to deploy or upgrade a contract, and manage proxy admin rights.
41-
42-
```js
43-
const { ethers, upgrades } = require("hardhat");
44-
45-
async function main() {
46-
// Deploying
47-
const Box = await ethers.getContractFactory("Box");
48-
const instance = await upgrades.deployProxy(Box, [42]);
49-
await instance.waitForDeployment();
50-
51-
// Upgrading
52-
const BoxV2 = await ethers.getContractFactory("BoxV2");
53-
const upgraded = await upgrades.upgradeProxy(await instance.getAddress(), BoxV2);
54-
}
55-
56-
main();
57-
```
58-
59-
Truffle users will be able to write [migrations](https://www.trufflesuite.com/docs/truffle/getting-started/running-migrations) that use the plugin to deploy or upgrade a contract, or manage proxy admin rights.
60-
61-
```js
62-
const { deployProxy, upgradeProxy } = require('@openzeppelin/truffle-upgrades');
63-
64-
const Box = artifacts.require('Box');
65-
const BoxV2 = artifacts.require('BoxV2');
66-
67-
module.exports = async function (deployer) {
68-
const instance = await deployProxy(Box, [42], { deployer });
69-
const upgraded = await upgradeProxy(instance.address, BoxV2, { deployer });
70-
}
71-
```
72-
73-
Whether you're using Hardhat or Truffle, you can use the plugin in your tests to ensure everything works as expected.
74-
75-
```js
76-
it('works before and after upgrading', async function () {
77-
const instance = await upgrades.deployProxy(Box, [42]);
78-
assert.strictEqual(await instance.retrieve(), 42);
79-
80-
await upgrades.upgradeProxy(instance, BoxV2);
81-
assert.strictEqual(await instance.retrieve(), 42);
82-
});
83-
```
84-
8520
## How do the plugins work?
8621

8722
The plugins provide functions which take care of managing upgradeable deployments of your contracts.
8823

8924
For example, `deployProxy` does the following:
9025

91-
1. Validate that the implementation is [upgrade safe](https://docs.openzeppelin.com/upgrades-plugins/faq#what-does-it-mean-for-a-contract-to-be-upgrade-safe)
26+
1. Validates that the implementation is [upgrade safe](https://docs.openzeppelin.com/upgrades-plugins/faq#what-does-it-mean-for-a-contract-to-be-upgrade-safe).
9227

93-
2. Check if there is an [implementation contract](https://docs.openzeppelin.com/upgrades-plugins/faq#what-is-an-implementation-contract) deployed with the same bytecode, and deploy one if not
28+
2. Deploys the [implementation contract](https://docs.openzeppelin.com/upgrades-plugins/faq#what-is-an-implementation-contract). Note that the Hardhat plugin first checks if there is an implementation contract deployed with the same bytecode, and skips this step if one is already deployed.
9429

95-
3. Create and initialize the proxy contract, along with a [proxy admin](https://docs.openzeppelin.com/upgrades-plugins/faq#what-is-a-proxy-admin) (if needed)
30+
3. Creates and initializes the proxy contract, along with a [proxy admin](https://docs.openzeppelin.com/upgrades-plugins/faq#what-is-a-proxy-admin) (if needed).
9631

9732
And when you call `upgradeProxy`:
9833

99-
1. Validate that the new implementation is [upgrade safe](https://docs.openzeppelin.com/upgrades-plugins/faq#what-does-it-mean-for-a-contract-to-be-upgrade-safe) and is [compatible](https://docs.openzeppelin.com/upgrades-plugins/faq#what-does-it-mean-for-an-implementation-to-be-compatible) with the previous one
34+
1. Validates that the new implementation is [upgrade safe](https://docs.openzeppelin.com/upgrades-plugins/faq#what-does-it-mean-for-a-contract-to-be-upgrade-safe) and is [compatible](https://docs.openzeppelin.com/upgrades-plugins/faq#what-does-it-mean-for-an-implementation-to-be-compatible) with the previous one.
10035

101-
2. Check if there is an [implementation contract](https://docs.openzeppelin.com/upgrades-plugins/faq#what-is-an-implementation-contract) deployed with the same bytecode, and deploy one if not
36+
2. Deploys the new [implementation contract](https://docs.openzeppelin.com/upgrades-plugins/faq#what-is-an-implementation-contract). Note that the Hardhat plugin first checks if there is an implementation contract deployed with the same bytecode, and skips this step if one is already deployed.
10237

103-
3. Upgrade the proxy to use the new implementation contract
38+
3. Upgrades the proxy to use the new implementation contract.
10439

105-
The plugins will keep track of all the implementation contracts you have deployed in an `.openzeppelin` folder in the project root. 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`).
40+
The Hardhat plugin keeps track of all the implementation contracts you have deployed in an `.openzeppelin` folder in the project root. 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`).
10641

107-
> Note: the format of the files within the `.openzeppelin` folder is not compatible with those of the [OpenZeppelin CLI](https://docs.openzeppelin.com/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.
42+
The Foundry plugin does not keep track of implementation contracts, but requires you to [define reference contracts](https://github.com/OpenZeppelin/openzeppelin-foundry-upgrades?tab=readme-ov-file#before-running) in order to validate new versions of implementations for upgrade safety.
10843

10944
## Proxy patterns
11045

111-
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](https://docs.openzeppelin.com/contracts/4.x/api/proxy).
46+
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](https://docs.openzeppelin.com/contracts/api/proxy).
11247

113-
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](./packages/plugin-hardhat/README.md) and [Truffle Upgrades](./packages/plugin-truffle/README.md) for examples.
48+
For UUPS and transparent proxies, use `deployProxy` and `upgradeProxy`. For beacon proxies, use `deployBeacon`, `deployBeaconProxy`, and `upgradeBeacon`. See the documentation for [Hardhat Upgrades](./packages/plugin-hardhat/README.md) and [Foundry Upgrades](https://github.com/OpenZeppelin/openzeppelin-foundry-upgrades) for examples.
11449

11550
## Managing ownership
11651

11752
Transparent proxies have an _admin_ address which has the rights to upgrade them. By default, the admin is a [proxy admin contract](https://docs.openzeppelin.com/upgrades-plugins/faq#what-is-a-proxy-admin) deployed behind the scenes. Keep in mind that the _admin_ of a proxy can only upgrade it, but not interact with the implementation contract. Read [here](https://docs.openzeppelin.com/upgrades-plugins/proxies#transparent-proxies-and-function-clashes) for more info on this restriction.
11853

119-
The proxy admin contract also defines an _owner_ address which has the rights to operate it. By default, this address is the `initialOwner` address used during deployment of the transparent proxy if provided, otherwise it is the externally owned account used during deployment. You can change the proxy admin owner by calling the `admin.transferProxyAdminOwnership` function in the plugin. Refer to each plugin documentation for more details on the `admin` functions.
54+
The proxy admin contract also defines an _owner_ address which has the rights to operate it. By default, the proxy admin's owner is the `initialOwner` address used during deployment of the transparent proxy if provided, otherwise it is the externally owned account used during deployment. You can change the proxy admin owner by calling the `admin.transferProxyAdminOwnership` function in the Hardhat plugin, or the `transferOwnership` function of the proxy admin contract if using Foundry.
55+
56+
> [!WARNING]
57+
> Do not reuse an already deployed `ProxyAdmin`. Before `@openzeppelin/contracts` version 5.x, the address provided to transparent proxies was an `initialAdmin` as opposed to an `initialOwner` of a newly deployed `ProxyAdmin`. Reusing a `ProxyAdmin` will disable upgradeability in your contract.
12058
121-
UUPS and beacon proxies do not use admin addresses. UUPS proxies rely on an [`_authorizeUpgrade`](https://docs.openzeppelin.com/contracts/4.x/api/proxy#UUPSUpgradeable-_authorizeUpgrade-address-) 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.
59+
UUPS and beacon proxies do not use admin addresses. UUPS proxies rely on an [`_authorizeUpgrade`](https://docs.openzeppelin.com/contracts/api/proxy#UUPSUpgradeable-_authorizeUpgrade-address-) 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.
12260

123-
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](https://docs.openzeppelin.com/defender/admin).
61+
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 `defender.proposeUpgrade` or `defender.proposeUpgradeWithApproval` functions to automatically set up the upgrade in [OpenZeppelin Defender](https://docs.openzeppelin.com/defender/).
12462

12563
## Community
12664

assets/truffle.svg

-1
This file was deleted.

docs/modules/ROOT/nav.adoc

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
* xref:index.adoc[Overview]
22
* xref:hardhat-upgrades.adoc[Using with Hardhat]
33
** xref:defender-deploy.adoc[OpenZeppelin Defender integration]
4-
* xref:truffle-upgrades.adoc[Using with Truffle]
4+
** xref:network-files.adoc[Network Files]
5+
* xref:foundry-upgrades.adoc[Using with Foundry]
56
* xref:writing-upgradeable.adoc[Writing Upgradeable Contracts]
67
* xref:proxies.adoc[Proxy Upgrade Pattern]
7-
* xref:network-files.adoc[Network Files]
88
* xref:faq.adoc[Frequently Asked Questions]
99
1010
.API Reference
1111
* xref:api-hardhat-upgrades.adoc[Hardhat Upgrades]
12-
* xref:api-truffle-upgrades.adoc[Truffle Upgrades]
12+
* xref:api-foundry-upgrades.adoc[Foundry Upgrades]
1313
* xref:api-core.adoc[Upgrades Core & CLI]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
= OpenZeppelin Foundry Upgrades API
2+
3+
See function documentation in https://github.com/OpenZeppelin/openzeppelin-foundry-upgrades/blob/main/src/Upgrades.sol[Upgrades.sol] from the https://github.com/OpenZeppelin/openzeppelin-foundry-upgrades[OpenZeppelin Foundry Upgrades] repository for API reference.

docs/modules/ROOT/pages/api-hardhat-upgrades.adoc

+1-1
Original file line numberDiff line numberDiff line change
@@ -712,7 +712,7 @@ Silences all subsequent warnings about the use of unsafe flags. Prints a last wa
712712
[[verify]]
713713
== verify
714714

715-
Extends https://hardhat.org/hardhat-runner/plugins/nomicfoundation-hardhat-verify[hardhat-verify]'s `verify` task to completely verify a proxy on Etherscan. This supports verifying proxy contracts that were deployed by the Hardhat Upgrades or Truffle Upgrades plugin.
715+
Extends https://hardhat.org/hardhat-runner/plugins/nomicfoundation-hardhat-verify[hardhat-verify]'s `verify` task to completely verify a proxy on Etherscan. This supports verifying proxy contracts that were deployed by the Hardhat Upgrades plugin.
716716

717717
The arguments are the same as for hardhat-verify's `verify` task. If the provided address is a proxy, this task will verify the proxy's implementation contract, the proxy itself and any proxy-related contracts, as well as link the proxy to the implementation contract's ABI on Etherscan. If the provided address is not a proxy, the regular `verify` task from hardhat-verify will be run on the address instead.
718718

docs/modules/ROOT/pages/faq.adoc

-7
Original file line numberDiff line numberDiff line change
@@ -210,13 +210,6 @@ Past versions of the plugins did not support upgradeable contracts that used cus
210210

211211
Some users who have already deployed proxies with structs and/or enums and who need to upgrade those proxies may need to use the override flag `unsafeAllowCustomTypes` for their next upgrade, after which it will no longer be necessary. If the project contains the source code for the implementation currently in use by the proxy, the plugin will attempt to recover the metadata that it needs before the upgrade, falling back to the override flag if this is not possible.
212212

213-
[[why-do-i-have-to-recompile-all-contracts-for-truffle]]
214-
== Why do I have to recompile all contracts for Truffle?
215-
216-
Truffle artifacts (the JSON files in `build/contracts`) contain the AST (abstract syntax tree) for each of your contracts. Our plugin uses this information to validate that your contracts are <<what-does-it-mean-for-a-contract-to-be-upgrade-safe, upgrade safe>>.
217-
218-
Truffle sometimes partially recompiles only the contracts that have changed. We will ask you to trigger a full recompilation either using `truffle compile --all` or deleting the `build/contracts` directory when this happens. The technical reason is that since Solidity does not produce deterministic ASTs, the plugins are unable to resolve references correctly if they are not from the same compiler run.
219-
220213
[[how-to-rename]]
221214
== How can I rename a variable, or change its type?
222215

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
= Using with Foundry
2+
3+
See the https://github.com/OpenZeppelin/openzeppelin-foundry-upgrades[OpenZeppelin Foundry Upgrades] repository for usage information.

0 commit comments

Comments
 (0)