Hi @frangio - I'm also trying to implement a factory for beacon proxies but must be doing something incorrectly.
Here is the problem:
I have a storage variable currentEditionId on the contract being proxied (Artist.sol) that increments each time the createEdition function is called. It starts from 1, and that works when I test Artist.sol by itself. However, when I test the proxied version of it deployed by ArtistCreator.sol, it is starting from zero.
My hunch is I'm making a common mistake? Here are the relevant parts of ArtistCreator.sol:
import '@openzeppelin/contracts/proxy/beacon/UpgradeableBeacon.sol';
import '@openzeppelin/contracts/proxy/beacon/BeaconProxy.sol';
import './Artist.sol';
contract ArtistCreator {
address immutable beaconAddress;
mapping(uint32 => address) private artists;
/// Emitted when an Artist is created reserving the corresponding artist ID.
/// @param artistId ID of newly created Artist
event CreatedArtist(uint256 indexed artistId);
/// Initializes implementation contract
constructor(address upgrader) {
UpgradeableBeacon _beacon = new UpgradeableBeacon(address(new Artist()));
_beacon.transferOwnership(upgrader);
beaconAddress = address(_beacon);
}
/// Creates a new artist proxy
/// @param _name Name of the artist contract
/// @param _baseURI Base URI of the artist contract (includes artist's id)
function createArtist(
string calldata _name,
uint32 _artistId,
string calldata _baseURI
) external returns (address) {
BeaconProxy proxy = new BeaconProxy(
beaconAddress,
abi.encodeWithSelector(Artist(address(0)).initialize.selector, tx.origin, _name, _baseURI)
);
artists[_artistId] = address(proxy);
emit CreatedArtist(_artistId);
return address(proxy);
}
I also forked the repo and stripped it down to demo the problem in case you want to install & run the tests: https://github.com/SoundCollective/factory-contract-help/blob/master/test/main.test.ts
Any info would be hugely appreciated!