Skip to content

Built to solidify learning in the Section "Upgradeable Smart Contracts" of Advanced Foundry course offered by Cyfrin Updraft

License

Notifications You must be signed in to change notification settings

tohidul3417/foundry-upgrades

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Foundry Upgradeable Contracts

CI License: MIT

A Foundry-based implementation of upgradeable smart contracts using the UUPS (Universal Upgradeable Proxy Standard) proxy pattern. This project demonstrates how to deploy a V1 contract and then upgrade it to a V2 version while preserving the proxy's address and storage. This repository was completed as a part of the Advanced Foundry course (offered by Cyfrin Updraft) in the Upgradeable Smart Contracts section.


Architecture

The protocol consists of two main implementation contracts (BoxV1, BoxV2) and two deployment scripts that work in concert with OpenZeppelin's ERC1967Proxy.

  • BoxV1.sol: The initial version of the contract, which inherits from Initializable, UUPSUpgradeable, and OwnableUpgradeable. It contains a version() function that returns 1.
  • BoxV2.sol: The upgraded version of the contract, which inherits from UUPSUpgradeable. This contract adds a setNumber function and its version() function returns 2.
  • DeployBox.s.sol: A Foundry script that deploys the initial BoxV1 contract implementation and an ERC1967Proxy that points to it.
  • UpgradeBox.s.sol: A Foundry script that handles the logic for upgrading the ERC1967Proxy to point to the new BoxV2 implementation.

Getting Started

Prerequisites

Installation

  1. Clone the repository (including submodules):

    git clone --recurse-submodules https://github.com/tohidul3417/foundry-upgrades.git
    cd foundry-upgrades
  2. Build the project:

    forge build

Usage

Testing

The project includes a comprehensive test suite to verify the deployment and upgrade logic.

  • Run all tests:
    forge test
  • Run the tests with verbose output:
    forge test -vvv

The DeployAndUpgradeTest.t.sol test file includes a testUpgrades function that asserts the successful upgrade of the proxy to BoxV2 and checks that the new functions are available and the state is preserved.

Deployment

The script/ directory contains Foundry scripts for deploying and upgrading the contracts.

  • DeployBox.s.sol: Deploys the initial proxy and implementation contracts.
  • UpgradeBox.s.sol: Upgrades the deployed proxy to a new implementation.

⚠️ Security Disclaimer

This project was built for educational purposes and has not been audited. Do not use it in a production environment or with real funds. Always conduct a full, professional security audit before deploying any smart contracts.


License

This project is distributed under the MIT License. See LICENSE for more information.

About

Built to solidify learning in the Section "Upgradeable Smart Contracts" of Advanced Foundry course offered by Cyfrin Updraft

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published