Skip to content

Commit

Permalink
docs: add uups upgrade example (#499)
Browse files Browse the repository at this point in the history
* add uups upgrade example

* fix readme

* update lock file + remove unused config

* Update examples/upgrade-contract-uups/README.md

Co-authored-by: Nami <[email protected]>

* Update examples/upgrade-contract-uups/README.md

Co-authored-by: Nami <[email protected]>

---------

Co-authored-by: Nami <[email protected]>
  • Loading branch information
MCarlomagno and shahnami authored Aug 2, 2024
1 parent cb0ee8e commit 56a9c24
Show file tree
Hide file tree
Showing 5 changed files with 293 additions and 0 deletions.
22 changes: 22 additions & 0 deletions examples/upgrade-contract-uups/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
## Defender SDK upgrade

This example showcases a simple contract upgrade using UUPS + ownable.

### Steps to run this example

1. Create a deployment environment for the sepolia network, (https://docs.openzeppelin.com/defender/v2/tutorial/deploy#environment_setup)[see how]
2. Go to https://wizard.openzeppelin.com/#custom
3. Select Ownable + UUPS upgradeablity.
4. Deploy the contract AND the proxy.
5. Use the deployed contract addresses as follows:

```js
const upgrade = await client.deploy.upgradeContract({
proxyAddress: '0x3a...ad7', // erc1967 proxy address
newImplementationAddress: '0x484...99', // address of the new implementation contract
newImplementationABI: JSON.stringify(uupsOwnableAbi), // The ABI of the new implementation (must implement UUPS standard)
network: 'sepolia',
});
```

6. Go to your Defender dashboard to see the status of your upgrade.
222 changes: 222 additions & 0 deletions examples/upgrade-contract-uups/abis/UUPSOwnable.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,222 @@
[
{
"inputs": [],
"stateMutability": "nonpayable",
"type": "constructor"
},
{
"inputs": [
{
"internalType": "address",
"name": "target",
"type": "address"
}
],
"name": "AddressEmptyCode",
"type": "error"
},
{
"inputs": [
{
"internalType": "address",
"name": "implementation",
"type": "address"
}
],
"name": "ERC1967InvalidImplementation",
"type": "error"
},
{
"inputs": [],
"name": "ERC1967NonPayable",
"type": "error"
},
{
"inputs": [],
"name": "FailedInnerCall",
"type": "error"
},
{
"inputs": [
{
"internalType": "address",
"name": "initialOwner",
"type": "address"
}
],
"name": "initialize",
"outputs": [],
"stateMutability": "nonpayable",
"type": "function"
},
{
"inputs": [],
"name": "InvalidInitialization",
"type": "error"
},
{
"inputs": [],
"name": "NotInitializing",
"type": "error"
},
{
"inputs": [
{
"internalType": "address",
"name": "owner",
"type": "address"
}
],
"name": "OwnableInvalidOwner",
"type": "error"
},
{
"inputs": [
{
"internalType": "address",
"name": "account",
"type": "address"
}
],
"name": "OwnableUnauthorizedAccount",
"type": "error"
},
{
"inputs": [
{
"internalType": "address",
"name": "newImplementation",
"type": "address"
},
{
"internalType": "bytes",
"name": "data",
"type": "bytes"
}
],
"name": "upgradeToAndCall",
"outputs": [],
"stateMutability": "payable",
"type": "function"
},
{
"inputs": [],
"name": "UUPSUnauthorizedCallContext",
"type": "error"
},
{
"inputs": [
{
"internalType": "bytes32",
"name": "slot",
"type": "bytes32"
}
],
"name": "UUPSUnsupportedProxiableUUID",
"type": "error"
},
{
"anonymous": false,
"inputs": [
{
"indexed": false,
"internalType": "uint64",
"name": "version",
"type": "uint64"
}
],
"name": "Initialized",
"type": "event"
},
{
"anonymous": false,
"inputs": [
{
"indexed": true,
"internalType": "address",
"name": "previousOwner",
"type": "address"
},
{
"indexed": true,
"internalType": "address",
"name": "newOwner",
"type": "address"
}
],
"name": "OwnershipTransferred",
"type": "event"
},
{
"inputs": [],
"name": "renounceOwnership",
"outputs": [],
"stateMutability": "nonpayable",
"type": "function"
},
{
"inputs": [
{
"internalType": "address",
"name": "newOwner",
"type": "address"
}
],
"name": "transferOwnership",
"outputs": [],
"stateMutability": "nonpayable",
"type": "function"
},
{
"anonymous": false,
"inputs": [
{
"indexed": true,
"internalType": "address",
"name": "implementation",
"type": "address"
}
],
"name": "Upgraded",
"type": "event"
},
{
"inputs": [],
"name": "owner",
"outputs": [
{
"internalType": "address",
"name": "",
"type": "address"
}
],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [],
"name": "proxiableUUID",
"outputs": [
{
"internalType": "bytes32",
"name": "",
"type": "bytes32"
}
],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [],
"name": "UPGRADE_INTERFACE_VERSION",
"outputs": [
{
"internalType": "string",
"name": "",
"type": "string"
}
],
"stateMutability": "view",
"type": "function"
}
]
25 changes: 25 additions & 0 deletions examples/upgrade-contract-uups/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
require('dotenv').config();

const { Defender } = require('@openzeppelin/defender-sdk');

const uupsOwnableAbi = require('./abis/UUPSOwnable.json');

async function main() {
const client = new Defender({
apiKey: process.env.API_KEY,
apiSecret: process.env.API_SECRET,
});

const upgrade = await client.deploy.upgradeContract({
proxyAddress: '0x3a...d7',
newImplementationAddress: '0x48...99',
newImplementationABI: JSON.stringify(uupsOwnableAbi),
network: 'sepolia',
});

console.log(upgrade);
}

if (require.main === module) {
main().catch(console.error);
}
15 changes: 15 additions & 0 deletions examples/upgrade-contract-uups/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"name": "@openzeppelin/defender-sdk-example-upgrade-contract-uups",
"version": "1.14.2",
"private": true,
"main": "index.js",
"author": "Openzeppelin Defender <[email protected]>",
"license": "MIT",
"scripts": {
"start": "node index.js"
},
"dependencies": {
"@openzeppelin/defender-sdk": "1.14.2",
"dotenv": "^16.3.1"
}
}
9 changes: 9 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 56a9c24

Please sign in to comment.