Upgrading
Upgrading the Aavegotchi Diamond
As per EIP-2535 Diamond Standard upgrades are done by calling the diamondCut
function to add/replace/remove any number of functions and facets in a single transaction.
Upgrading can be done safely and easily as long as some important rules are followed.
Rules
Make sure that an upgrade is atomic, meaning that all changes are done in a single transaction to ensure the diamond does not get into an inconsistent state. This is done by calling
diamondCut
once with all functions to add/replace/remove.The diamond and all the facets share the same contract storage address space. Do not corrupt state variables by sticking new state variables in the middle of structs. Do not change the bit size of an existing state variable if that overlaps with an existing state variable.
New state variables can be added to the end of structs.
Existing state variables can have their name changed.
More info on upgrade rules found here: https://eip2535diamonds.substack.com/p/diamond-upgrades?s=w
Upgrade Procedure
Modify the existing source code of the diamond and its facets.
Write an upgrade script that calls the
diamondCut
function to add/replace/remove functions.Write any new tests and run tests to make sure they pass.
Commit and push changes to git.
Get any needed code review or code audit.
Execute the upgrade script.
Immediately tag the source code with the transaction hash that made the upgrade. Commit and push the tag to git. This records and associates the diamond and facet source code with the upgrade.
Use the hardhat etherscan plugin to verify the source code of any new facets that were used to add/replace functions.
Example upgrade command: npx hardhat run scripts/upgrade.js --network kovan
Last updated