Created
August 4, 2025 11:29
-
-
Save masihtehrani/c367e6f7d5d9b4f259160510e35daad8 to your computer and use it in GitHub Desktop.
Created using remix-ide: Realtime Ethereum Contract Compiler and Runtime. Load this file by pasting this gists URL or ID at https://remix.ethereum.org/#version=soljson-v0.8.30+commit.73712a01.js&optimize=true&runs=200&gist=
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // SPDX-License-Identifier: MIT | |
| pragma solidity ^0.8.20; | |
| import "@openzeppelin/contracts/proxy/beacon/IBeacon.sol"; | |
| import "@openzeppelin/contracts/access/Ownable.sol"; | |
| /** | |
| * @title UpgradeableBeacon | |
| * @author Your Name (adapted from OpenZeppelin) | |
| * @notice A contract that holds the address of an implementation contract, allowing for upgrades. | |
| */ | |
| contract UpgradeableBeacon is IBeacon, Ownable { | |
| // The address of the master logic (implementation) contract. | |
| address private _implementation; | |
| /** | |
| * @notice Emitted when the implementation address is successfully upgraded. | |
| */ | |
| event Upgraded(address indexed implementation); | |
| /** | |
| * @notice Sets the initial implementation contract address upon deployment. | |
| * @param implementation_ The address of the `RwaToken` logic contract. | |
| * @dev Function Owner: The deployer of this beacon contract. | |
| */ | |
| constructor(address implementation_) Ownable(msg.sender) { | |
| _setImplementation(implementation_); | |
| } | |
| /** | |
| * @notice Returns the current implementation address. | |
| * @dev Function Owner: Anyone can call this public view function. | |
| */ | |
| function implementation() public view virtual override returns (address) { | |
| return _implementation; | |
| } | |
| /** | |
| * @notice Upgrades the implementation address for all proxies pointing to this beacon. | |
| * @param newImplementation The address of the new `RwaToken` implementation contract. | |
| * @dev Function Owner: `onlyOwner` (the deployer of this beacon). | |
| * @dev Scenario: A bug is found or a new feature is added. The owner deploys the new version and | |
| * calls this function to upgrade the logic for all existing tokens. | |
| * @dev Example: `upgradeTo("0xNewRwaTokenV2Address")`. | |
| */ | |
| function upgradeTo(address newImplementation) public virtual onlyOwner { | |
| _setImplementation(newImplementation); | |
| emit Upgraded(newImplementation); | |
| } | |
| /** | |
| * @dev Internal function to set the implementation address. | |
| */ | |
| function _setImplementation(address newImplementation) private { | |
| require(newImplementation.code.length > 0, "Beacon: implementation is not a contract"); | |
| _implementation = newImplementation; | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment