eth-brownie / brownie

A Python-based development and testing framework for smart contracts targeting the Ethereum Virtual Machine.
https://eth-brownie.readthedocs.io
MIT License
2.65k stars 552 forks source link

Upgrades built-in #1101

Open PatrickAlphaC opened 3 years ago

PatrickAlphaC commented 3 years ago

Overview

Provide a simple overview of what you wish to see added. Please include:

A built in API to feature Openzeppelin's upgradeable smart contracts. I'm thinking we could start with the transparent proxy. If it makes more sense for this to just be a mix first, I'm working on that too.

This will follow the Openzeppelin Proxy pattern heavily, ERC1967, and use the openzeppelin upgrade contracts.

Specification

Here's what I imagine that API look like:

from Brownie import ImplementationContract, accounts

def main():
    account = accounts[0]
    ImplementationContract.deployProxy(initializer="initializerFunction", 1, {"from": account})

Where deployProxy looks something like:

def deployProxy(initializer=None, *args):
    # pseudocode
    implementation = depolyImplementation()
    if initializer:
        call_initializer(*args)
    proxy = depolyProxy(implementation=implementation)
    admin = deployProxyAdmin()
    proxy.set_admin(admin)

And then we can call the upgrade like:

ImplementationContract.upgrade(new_implementation)

Or something of the like.

Dependencies

In your brownie-config.yaml

dependencies:
  - OpenZeppelin/openzeppelin-contracts@4.1.0
compiler:
  solc:
    remappings:
      - '@openzeppelin=OpenZeppelin/openzeppelin-contracts@4.1.0'
PatrickAlphaC commented 3 years ago

Inspiration from the openzeppelin plugins for truffle and hardhat: https://github.com/OpenZeppelin/openzeppelin-upgrades

Maybe we could even do something where this is a plugin for brownie.

jee-liqing commented 3 years ago

looking forward for this update!!

PatrickAlphaC commented 3 years ago

For now, you can check out the upgrades mix I worked on https://github.com/PatrickAlphaC/upgrades-mix

jee-liqing commented 3 years ago

wow!