8000 GitHub - TheOnma/upgradeable-smart-contract-boxv1
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

TheOnma/upgradeable-smart-contract-boxv1

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

20 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Upgradeable Smart Contract: Box

This project demonstrates how to create, deploy, and upgrade smart contracts using the UUPS (Universal Upgradeable Proxy Standard) pattern with OpenZeppelin's upgradeable contracts library and Foundry.

Overview

The project consists of:

  • BoxV1: Initial implementation with ability to store and retrieve a number
  • BoxV2: Upgraded implementation that adds functionality to modify the stored number
  • Deployment Scripts: Foundry scripts for deployment and upgrade operations
  • Tests: To verify the functionality of both versions and the upgrade process

Features

  • UUPS proxy pattern for upgradeability
  • OpenZeppelin upgradeable contracts
  • Foundry for development, testing, and deployment
  • Comprehensive test coverage
  • Access control with Ownable pattern

Prerequisites

  • Foundry
  • Basic understanding of Solidity and proxy patterns

Installation

  1. Clone the repository:

    git clone https://github.com/yourusername/upgradeable-smart-contract-boxv1.git
    cd upgradeable-smart-contract-boxv1
  2. Install dependencies:

    forge install

Usage

Build

forge build

Test

forge test

Deploy BoxV1

Deploy the initial implementation and proxy:

forge script script/DeployBox.s.sol:DeployBox --rpc-url <your_rpc_url> --private-key <your_private_key> --broadcast

Upgrade to BoxV2

Upgrade the implementation to BoxV2:

forge script script/UpgradeBox.s.sol:UpgradeBox --rpc-url <your_rpc_url> --private-key <your_private_key> --broadcast

Contract Details

BoxV1

< 6B87 ul dir="auto">
  • Simple storage contract with getter
  • Version indicator
  • Upgradeable via UUPS
  • BoxV2

    • Adds setter functionality
    • Maintains compatibility with BoxV1 storage layout
    • Improves upgrade authorization with onlyOwner

    Project Structure

    ├── src/                  # Smart contracts
    │   ├── BoxV1.sol         # Initial implementation
    │   └── BoxV2.sol         # Upgraded implementation
    ├── script/               # Deployment scripts
    │   ├── DeployBox.s.sol   # Initial deployment script
    │   └── UpgradeBox.s.sol  # Upgrade script
    ├── test/                 # Test files
    │   └── DeployAndUpgradeTest.t.sol
    └── foundry.toml          # Foundry configuration
    

    Security Considerations

    • The upgrade mechanism is protected by the onlyOwner modifier in BoxV2
    • Storage layout is carefully preserved between versions
    • BoxV1 uses _disableInitializers() in the constructor to prevent initialization attacks

    License

    This project is licensed under the MIT License - see the LICENSE file for details.

    Acknowledgements

    About

    No description, website, or topics provided.

    Resources

    Stars

    Watchers

    Forks

    Releases

    No releases published

    Packages

    No packages published
    0