Skip to content

Instantly share code, notes, and snippets.

@masihtehrani
Created August 4, 2025 11:28
Show Gist options
  • Select an option

  • Save masihtehrani/6163173511327326e01424283e70e325 to your computer and use it in GitHub Desktop.

Select an option

Save masihtehrani/6163173511327326e01424283e70e325 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=
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;
import "@openzeppelin/contracts/proxy/beacon/BeaconProxy.sol";
import "@openzeppelin/contracts/proxy/beacon/IBeacon.sol";
import "@openzeppelin/contracts/access/Ownable.sol";
import "./RwaToken.sol";
/**
* @title RwaTokenFactory
* @author Your Name
* @notice A factory for deploying new RWA tokens as Beacon Proxies.
*/
contract RwaTokenFactory is Ownable {
/**
* @notice The immutable beacon contract that holds the implementation address.
*/
IBeacon public immutable beacon;
/**
* @notice Emitted when a new token proxy is successfully created.
*/
event TokenCreated(
string name,
string symbol,
address proxyAddress,
address creator
);
/**
* @notice The constructor sets the address of the beacon contract.
* @param _beaconAddress The address of the already-deployed `UpgradeableBeacon` contract.
* @dev Function Owner: The deployer of this factory contract.
*/
constructor(address _beaconAddress) Ownable(msg.sender) {
beacon = IBeacon(_beaconAddress);
}
/**
* @notice Creates and initializes a new RWA token proxy.
* @param params A struct of type `RwaTokenParams` containing all configuration for the new token.
* @return The address of the newly created token proxy.
* @dev Function Owner: `onlyOwner` (the deployer of this factory).
* @dev Scenario: The project owner calls this function with the token's parameters, including their
* own address as `initialOwner`, to launch a new token.
*/
function createRwaToken(
RwaTokenParams calldata params
) external onlyOwner returns (address) {
bytes memory data = abi.encodeWithSelector(
RwaToken.initialize.selector,
params
);
BeaconProxy proxy = new BeaconProxy(address(beacon), data);
emit TokenCreated(params.name, params.symbol, address(proxy), msg.sender);
return address(proxy);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment