{"id":35158674,"url":"https://github.com/aditya-alchemist/upgradeable-smart-contracts","last_synced_at":"2026-05-12T16:36:26.326Z","repository":{"id":286492742,"uuid":"961139325","full_name":"Aditya-alchemist/Upgradeable-smart-contracts","owner":"Aditya-alchemist","description":"This project demonstrates a modular and upgradeable smart contract architecture using the UUPS (Universal Upgradeable Proxy Standard) pattern. It leverages Foundry for fast development and scripting, and OpenZeppelin's upgradeable contracts for secure and efficient upgrade logic.","archived":false,"fork":false,"pushed_at":"2025-04-06T19:29:05.000Z","size":12,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-12-31T03:53:29.504Z","etag":null,"topics":["erc1967","foundry","openzeppelin","proxy","proxy-contract","uups-proxy-pattern","uups-upgradeable-contract"],"latest_commit_sha":null,"homepage":"","language":"Solidity","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Aditya-alchemist.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2025-04-05T20:52:36.000Z","updated_at":"2025-04-06T19:29:08.000Z","dependencies_parsed_at":"2025-04-06T20:39:12.500Z","dependency_job_id":null,"html_url":"https://github.com/Aditya-alchemist/Upgradeable-smart-contracts","commit_stats":null,"previous_names":["aditya-alchemist/upgradeable-smart-contracts"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/Aditya-alchemist/Upgradeable-smart-contracts","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Aditya-alchemist%2FUpgradeable-smart-contracts","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Aditya-alchemist%2FUpgradeable-smart-contracts/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Aditya-alchemist%2FUpgradeable-smart-contracts/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Aditya-alchemist%2FUpgradeable-smart-contracts/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Aditya-alchemist","download_url":"https://codeload.github.com/Aditya-alchemist/Upgradeable-smart-contracts/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Aditya-alchemist%2FUpgradeable-smart-contracts/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":32947985,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-12T09:19:52.626Z","status":"ssl_error","status_checked_at":"2026-05-12T09:17:33.438Z","response_time":102,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.6:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["erc1967","foundry","openzeppelin","proxy","proxy-contract","uups-proxy-pattern","uups-upgradeable-contract"],"created_at":"2025-12-28T17:13:56.433Z","updated_at":"2026-05-12T16:36:26.322Z","avatar_url":"https://github.com/Aditya-alchemist.png","language":"Solidity","funding_links":[],"categories":[],"sub_categories":[],"readme":"\n# 🔄 Upgradeable Smart Contract System\n\nThis project showcases a modular and upgrade-friendly smart contract architecture using the **UUPS (Universal Upgradeable Proxy Standard)** pattern—one of the most gas-efficient and secure proxy upgrade mechanisms. Instead of redeploying contracts and losing state, UUPS proxies allow us to **retain state in a proxy contract** while pointing to different versions of logic (implementation) contracts over time.\n\nThis architecture is essential in decentralized applications where contracts must evolve post-deployment (e.g., to fix bugs or add features) **without losing data or requiring users to switch contracts**.\n\nWe use:\n- **Foundry** for efficient contract development and scripting,\n- **OpenZeppelin's upgradeable contracts library** for battle-tested upgrade logic and storage handling,\n- The `UUPSUpgradeable` pattern for minimal upgrade overhead.\n\nThis pattern ensures:\n- 🔄 **Upgradeability**: Swap logic contracts at any time while maintaining the same proxy address.\n- 💾 **Storage Preservation**: The proxy stores all variables; logic contracts only define behavior.\n- 🔐 **Security**: Upgrades are restricted to the contract owner (or an upgrade manager), preventing unauthorized changes.\n\n---\n\n## 🧠 Contract Structure\n\n```solidity\n// BoxV1.sol\n- Stores a uint256 number.\n- Includes version() to identify logic version.\n- Inherits from Initializable, OwnableUpgradeable, and UUPSUpgradeable.\n\n// BoxV2.sol\n- Adds setValue and getValue functionality.\n- Implements _authorizeUpgrade with onlyOwner modifier.\n```\n\n---\n\n## 🗂️ Directory Structure\n\n```\n.\n├── src/\n│   ├── BoxV1.sol\n│   └── BoxV2.sol\n│\n├── script/\n│   ├── DeployBox.s.sol        // Deploys proxy with BoxV1\n│   └── UpgradeBox.s.sol       // Upgrades proxy to BoxV2\n│\n├── test/\n│   └── BoxTest.t.sol\n│\n├── foundry.toml\n└── README.md\n```\n\n---\n\n## 🚀 Deployment Workflow\n\n### 1. Deploy Initial Logic \u0026 Proxy\n```bash\nforge script script/DeployBox.s.sol --broadcast --rpc-url \u003cRPC_URL\u003e\n```\n- Deploys `BoxV1`\n- Deploys `ERC1967Proxy` pointing to BoxV1\n- Initializes via `initialize()` in BoxV1\n\n### 2. Upgrade to New Logic (BoxV2)\n```bash\nforge script script/UpgradeBox.s.sol --broadcast --rpc-url \u003cRPC_URL\u003e\n```\n- Deploys `BoxV2`\n- Uses `upgradeToAndCall()` via UUPS pattern\n\n---\n\n## 🔧 Proxy Upgrade Flow (Mermaid Diagram)\n\n```mermaid\ngraph TD\n    A[Deploy_BoxV1_Implementation] --\u003e B[Deploy_ERC1967Proxy_pointing_to_BoxV1]\n    B --\u003e C[Initialize_Proxy_with_BoxV1]\n    C --\u003e D[User_Interacts_with_Proxy]\n    D --\u003e E[Develop_New_BoxV2_Logic]\n    E --\u003e F[Deploy_BoxV2_Implementation]\n    F --\u003e G[Call_upgradeTo_via_Admin_Script]\n    G --\u003e H[Proxy_Now_Uses_BoxV2_Logic]\n    H --\u003e I[User_Interacts_with_Proxy_Again]\n\n```\n\n---\n\n## 📜 Sample Code\n\n### BoxV1\n```solidity\nfunction initialize() public initializer {\n    __Ownable_init(msg.sender);\n    __UUPSUpgradeable_init();\n}\nfunction _authorizeUpgrade(address newImpl) internal override onlyOwner {}\n```\n\n### BoxV2\n```solidity\nfunction setValue(uint256 newValue) public {\n    value = newValue;\n}\nfunction version() public pure returns (uint256) {\n    return 2;\n}\n```\n\n---\n\n## ⚠️ Security Considerations\n\n- Always restrict `_authorizeUpgrade` to a trusted authority using `onlyOwner`.\n- Avoid storage collisions by preserving storage layout during upgrades.\n- Use `@custom:oz-upgrades-unsafe-allow constructor` for upgradeable constructors.\n\n---\n\n## 🛠️ Requirements\n\n- [Foundry](https://book.getfoundry.sh/)\n- OpenZeppelin Contracts Upgradeable:  \n  ```\n  forge install OpenZeppelin/openzeppelin-contracts-upgradeable\n  ```\n- Set your private key and RPC URL in `.env` or use `--private-key` and `--rpc-url` flags.\n\n---\n\n## 📬 Contact\n\nIf you're experimenting or building advanced upgradeable patterns, feel free to reach out or contribute ideas. Built with ❤️ by **Aditya**.\n\n---\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Faditya-alchemist%2Fupgradeable-smart-contracts","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Faditya-alchemist%2Fupgradeable-smart-contracts","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Faditya-alchemist%2Fupgradeable-smart-contracts/lists"}