Awesome
Upgrades Mix
<br/> <p align="center"> <a href="https://blog.openzeppelin.com/proxy-patterns/" target="_blank"> <img src="https://raw.githubusercontent.com/PatrickAlphaC/upgrades-mix/main/img/proxy-pattern.png" width="400" alt="OpenZeppelin Proxy logo"> </a> </p> <br/>This repo shows users how to use the Transparent Proxy pattern for upgrading smart contracts. It uses most of the code from openzeppelin's repo, and adds brownie scripts on top.
Prerequisites
Please install or have installed the following:
Installation
- Install Brownie, if you haven't already. Here is a simple way to install brownie.
pip install eth-brownie
Or, if that doesn't work, via pipx
pip install --user pipx
pipx ensurepath
# restart your terminal
pipx install eth-brownie
- For local testing install ganache-cli Skip if you only want to use testnets
npm install -g ganache-cli
or
yarn add global ganache-cli
- Download the mix and install dependancies.
brownie bake upgrades-mix
cd upgrades
Or, you can clone from source:
git clone https://github.com/PatrickAlphaC/upgrades-mix
cd upgrades-mix
Environment Variables
If you want to be able to deploy to testnets or work with mainnet-fork, do the following.
- Set your
WEB3_INFURA_PROJECT_ID
, andPRIVATE_KEY
environment variables.
You can get a WEB3_INFURA_PROJECT_ID
by getting a free trial of Infura. At the moment, it does need to be infura with brownie. If you get lost, you can follow this guide to getting a project key. You can find your PRIVATE_KEY
from your ethereum wallet like metamask.
You'll also need testnet Sepolia ETH and LINK. You can get LINK and ETH into your wallet by using the sepolia faucets located here and the link token faucet here. If you're new to this, watch this video.
You can add your environment variables to the .env
file:
export WEB3_INFURA_PROJECT_ID=<PROJECT_ID>
export PRIVATE_KEY=<PRIVATE_KEY>
AND THEN RUN source .env
TO ACTIVATE THE ENV VARIABLES
(You'll need to do this everytime you open a new terminal, or learn how to set them easier).
DO NOT SEND YOUR PRIVATE KEY WITH FUNDS IN IT ONTO GITHUB
Otherwise, you can build, test, and deploy on your local environment.
Useage
Scripts
brownie run scripts/01_deploy_box.py
brownie run scripts/02_upgrade_box.py
This will:
- Deploy a
Box
implementation contract - Deploy a
ProxyAdmin
contract to be the admin of the proxy - Deploy a
TransparentUpgradeableProxy
to be the proxy for the implementations
Then, the upgrade script will:
- Deploy a new Box implementation
BoxV2
- Upgrade the proxy to point to the new implementation contract, essentially upgrading your infrastructure.
- Then it will call a function only
BoxV2
can call
Test
brownie test
Linting
pip install black
pip install autoflake
autoflake --in-place --remove-unused-variables -r .
black .
Resources
To get started with Brownie:
- Check out the other Brownie mixes that can be used as a starting point for your own contracts. They also provide example code to help you get started.
- "Getting Started with Brownie" is a good tutorial to help you familiarize yourself with Brownie.
- For more in-depth information, read the Brownie documentation.
- Or watch any of the Brownie YouTube tutorials or articles
Any questions? Join our Discord
License
This project is licensed under the MIT license.