Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add function to prepare proxy upgrade #54

Merged
merged 2 commits into from
Aug 9, 2024

Conversation

nkuba
Copy link
Member

@nkuba nkuba commented Aug 9, 2024

Proxy upgrades of contracts are performed in two stages:

  1. Deploy a new implementation contract.
  2. Upgrade the version of implementation in the Proxy contract.

For upgradable contracts that were already deployed and ownership transferred to the governance, we cannot simply run upgradeProxy as the governance is a multi-sig.

Here we introduce a solution that will help us execute the upgrade in setup used across our projects:

  1. Deploy a new implementation contract.
  2. Prepare a transaction for the Governance to execute.

The solution is based on Open Zeppelin's upgradeProxy function, with the difference that the upgrade implementation transaction is prepared but not executed.

ProxyAdmin V4 vs V5

Implementation upgrade is executed through ProxyAdmin contract which can exist in two versions: V4 and V5.
Currently, our new contracts are deployed with version V5, but for older deployments we still support V4.
The difference between these two versions is in the upgrade function that is called on the ProxyAdmin.
In V4 there were two separate functions upgradeAndCall and upgrade which were called depending on if the callback should be executed.
In V5 there is just an upgradeAndCall function, which allows empty call data.

We introduced a switch statement to differentiate the flow based on Open Zeppelin's library.

Proxy upgrades of contracts are performed in two stages:
1. Deploy new implementation contract.
2. Upgrade version of implementation in the Proxy contract.

For upgradable contracts that were already deployed and ownership transferred
to the governance we cannot simply run `upgradeProxy` as the governance
is a multisig.

Here we introduce a solution that will help us execute the upgrade in
setup used across our projects:
1. Deploy new implementation contract.
2. Prepare transaction for the Governance to execute.

The solution is based on Open Zeppelin's [upgradeProxy](https://github.com/OpenZeppelin/openzeppelin-upgrades/blob/49e7ae93ee9be1d6f586517890a83634dea29ebc/packages/plugin-hardhat/src/upgrade-proxy.ts)
function, with the difference that the upgrade implementation transaction
is prepared but not executed.

Implementation upgrade is executed through ProxyAdmin contract which can
exist in two versions: V4 and V5. Currently our new contracts are deployed
with version V5, but for older deployments we still support V5.
The difference between these two version is in the upgrade function that
is called on the ProxyAdmin.
In V4 there were two separate functions `upgradeAndCall` and `upgrade` which
were called depending if the callback should be executed.
In V5 there is just `upgradeAndCall` function, which allows empty calldata.
This is based on https://github.com/OpenZeppelin/openzeppelin-upgrades/blob/49e7ae93ee9be1d6f586517890a83634dea29ebc/packages/plugin-hardhat/src/upgrade-proxy.ts#L62C45-L103
@nkuba nkuba self-assigned this Aug 9, 2024
nkuba added a commit to thesis/acre that referenced this pull request Aug 9, 2024
These are upgrade scripts for stBTC and MezoAllocator contracts that
will be executed on Sepolia and Mainnet.

The solution is using proxy upgrade helpers function that will
deploy implementation contract and prepare transaction that will be
executed by the governance to upgrade the implementation on the proxy
contract.

It requires changes from keep-network/hardhat-helpers#54
which branch is set in package.json as version of the package.
We need to update the version of `keep-network/hardhat-helpers` dependency
once it is released.
Copy link
Collaborator

@jagodarybacka jagodarybacka left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IMO looks good, if you have already tested on the fork I think we are good to merge? Or go we want to wait until we will attempt the upgrade on Sepolia?

@jagodarybacka jagodarybacka merged commit 07ee0d5 into main Aug 9, 2024
3 checks passed
@jagodarybacka jagodarybacka deleted the upgrades-prepare-proxy-upgrade branch August 9, 2024 11:11
nkuba added a commit to thesis/acre that referenced this pull request Aug 9, 2024
This is a version that includes the proxy upgrade preparation helpers
keep-network/hardhat-helpers#54
nkuba added a commit to thesis/acre that referenced this pull request Aug 9, 2024
These are upgrade scripts for stBTC and MezoAllocator contracts that
will be executed on Sepolia and Mainnet.

The solution is using proxy upgrade helpers function that will
deploy implementation contract and prepare transaction that will be
executed by the governance to upgrade the implementation on the proxy
contract.

It requires changes from keep-network/hardhat-helpers#54
which branch is set in package.json as version of the package.
We need to update the version of `keep-network/hardhat-helpers` dependency
once it is released.
nkuba added a commit to thesis/acre that referenced this pull request Aug 9, 2024
This is a version that includes the proxy upgrade preparation helpers
keep-network/hardhat-helpers#54
jagodarybacka added a commit to thesis/acre that referenced this pull request Aug 9, 2024
…698)

These are upgrade scripts for stBTC and MezoAllocator contracts that
will be executed on Sepolia and Mainnet.

The solution is using proxy upgrade helpers function that will deploy
implementation contract and prepare transaction that will be executed by
the governance to upgrade the implementation on the proxy contract.

It requires changes from
keep-network/hardhat-helpers#54 which branch is
set in package.json as version of the package. We need to update the
version of `keep-network/hardhat-helpers` dependency once it is
released.
@jagodarybacka jagodarybacka mentioned this pull request Aug 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants