Environment
Hardhat
Details
I’m having trouble understanding how to use the UpgradeableBeacon and BeaconProxy contracts, as well as the Hardhat Upgrades Plugin to achieve my desired use case
- I have an implementation contract that defines functions for a bonding curve token
- I want to be able to deploy proxy contracts that each represent their own token (so each has its own name, symbol, etc.) but delegate all function calls to the implementation contract
The reason I’m attracted to the Beacon proxy model is that I would be able to upgrade the implementation contract over time and all proxies would be upgraded with a single transaction.
However, I’m confused as to how I would implement this. So far, I have this structure for my implementation contract. *note that the tokens are not ERC20 tokens, so that’s why the ERC20 standard isn’t being inherited here.
Implementation contract
// SPDX-License-Identifier: GPL-3.0-or-later
pragma solidity ^0.8.4;
import "@openzeppelin/contracts/proxy/beacon/BeaconProxy.sol";
import "@openzeppelin/contracts/proxy/beacon/UpgradeableBeacon.sol";
contract MarketFactory {
// ======== Structs ========
struct Parameters {
string name;
string symbol;
}
// ======== Immutable storage ========
// address for the logic contract
address immutable logic;
// ======== Mutable storage ========
Parameters public parameters;
// ======== Constructor ========
// the constructor deploys an initial version that will act as a template
constructor(address _logic) {
logic = _logic;
}
// ======== Deploy contract ========
function createMarket(string calldata _name, string calldata _symbol)
external
returns (address)
{
parameters = Parameters({name: _name, symbol: _symbol});
BeaconProxy proxy = new BeaconProxy(
UpgradeableBeacon(logic),
parameters
);
delete parameters;
return address(proxy);
}
}
I’m confused as to whether this is the correct way to implement a factory that deploys beacon proxies. Could someone give me some guidance on whether I am on the right track? Because with this method, I am unclear as to how I would change the implementation contract (do I have to create a separate setter function that allows the owner to change the logic address?)
Any help would be appreciated.