Skip to content

Commit

Permalink
move factory to a standalone contract
Browse files Browse the repository at this point in the history
  • Loading branch information
iainnash committed Sep 26, 2023
1 parent fd46a94 commit 3584ef6
Show file tree
Hide file tree
Showing 13 changed files with 49 additions and 58 deletions.
3 changes: 1 addition & 2 deletions src/factory/ZoraCreator1155FactoryImpl.sol
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import {ICreatorRoyaltiesControl} from "../interfaces/ICreatorRoyaltiesControl.s
import {IMinter1155} from "../interfaces/IMinter1155.sol";
import {IContractMetadata} from "../interfaces/IContractMetadata.sol";
import {Ownable2StepUpgradeable} from "../utils/ownable/Ownable2StepUpgradeable.sol";
import {FactoryManagedUpgradeGate} from "../upgrades/FactoryManagedUpgradeGate.sol";
import {Zora1155} from "../proxies/Zora1155.sol";
import {Create2Upgradeable} from "@zoralabs/openzeppelin-contracts-upgradeable/contracts/utils/Create2Upgradeable.sol";
import {CREATE3} from "solmate/src/utils/CREATE3.sol";
Expand All @@ -19,7 +18,7 @@ import {ContractVersionBase} from "../version/ContractVersionBase.sol";

/// @title ZoraCreator1155FactoryImpl
/// @notice Factory contract for creating new ZoraCreator1155 contracts
contract ZoraCreator1155FactoryImpl is IZoraCreator1155Factory, ContractVersionBase, FactoryManagedUpgradeGate, UUPSUpgradeable, IContractMetadata {
contract ZoraCreator1155FactoryImpl is IZoraCreator1155Factory, ContractVersionBase, Ownable2StepUpgradeable, UUPSUpgradeable, IContractMetadata {
IZoraCreator1155 public immutable implementation;

IMinter1155 public immutable merkleMinter;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
pragma solidity 0.8.17;

/// @notice Factory Upgrade Gate Admin Factory Implementation – Allows specific contract upgrades as a safety measure
interface IFactoryManagedUpgradeGate {
interface IUpgradeGate {
/// @notice If an implementation is registered by the Builder DAO as an optional upgrade
/// @param baseImpl The base implementation address
/// @param upgradeImpl The upgrade implementation address
Expand Down
1 change: 1 addition & 0 deletions src/interfaces/IZoraCreator1155Errors.sol
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ interface IZoraCreator1155Errors {
error UserMissingRoleForToken(address user, uint256 tokenId, uint256 role);

error Config_TransferHookNotSupported(address proposedAddress);
error Call_TokenIdMismatch();

error Mint_InsolventSaleTransfer();
error Mint_ValueTransferFail();
Expand Down
10 changes: 5 additions & 5 deletions src/nft/ZoraCreator1155Impl.sol
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import {ICreatorCommands} from "../interfaces/ICreatorCommands.sol";
import {IMinter1155} from "../interfaces/IMinter1155.sol";
import {IRenderer1155} from "../interfaces/IRenderer1155.sol";
import {ITransferHookReceiver} from "../interfaces/ITransferHookReceiver.sol";
import {IFactoryManagedUpgradeGate} from "../interfaces/IFactoryManagedUpgradeGate.sol";
import {IUpgradeGate} from "../interfaces/IUpgradeGate.sol";
import {IZoraCreator1155} from "../interfaces/IZoraCreator1155.sol";
import {LegacyNamingControl} from "../legacy-naming/LegacyNamingControl.sol";
import {PublicMulticall} from "../utils/PublicMulticall.sol";
Expand Down Expand Up @@ -67,15 +67,15 @@ contract ZoraCreator1155Impl is
/// @notice This user role allows for only withdrawing funds and setting funds withdraw address
uint256 public constant PERMISSION_BIT_FUNDS_MANAGER = 2 ** 5;
/// @notice Factory contract
IFactoryManagedUpgradeGate internal immutable factory;
IUpgradeGate internal immutable upgradeGate;

constructor(
uint256, // TODO remove
address _mintFeeRecipient,
address _factory,
address _upgradeGate,
address _protocolRewards
) ERC1155Rewards(_protocolRewards, _mintFeeRecipient) initializer {
factory = IFactoryManagedUpgradeGate(_factory);
upgradeGate = IUpgradeGate(_upgradeGate);
}

/// @notice Initializes the contract
Expand Down Expand Up @@ -771,7 +771,7 @@ contract ZoraCreator1155Impl is
/// @dev This function is called in `upgradeTo` & `upgradeToAndCall`
/// @param _newImpl The new implementation address
function _authorizeUpgrade(address _newImpl) internal view override onlyAdmin(CONTRACT_BASE_ID) {
if (!factory.isRegisteredUpgradePath(_getImplementation(), _newImpl)) {
if (!upgradeGate.isRegisteredUpgradePath(_getImplementation(), _newImpl)) {
revert();
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,19 @@
// SPDX-License-Identifier: MIT
pragma solidity 0.8.17;

import {IFactoryManagedUpgradeGate} from "../interfaces/IFactoryManagedUpgradeGate.sol";
import {IUpgradeGate} from "../interfaces/IUpgradeGate.sol";
import {Ownable2StepUpgradeable} from "../utils/ownable/Ownable2StepUpgradeable.sol";
import {FactoryManagedUpgradeGateStorageV1} from "./FactoryManagedUpgradeGateStorageV1.sol";
import {UpgradeGateStorageV1} from "./UpgradeGateStorageV1.sol";

/// @title FactoryManagedUpgradeGate
/// @title UpgradeGate
/// @notice Contract for managing upgrades and safe upgrade paths for 1155 contracts
abstract contract FactoryManagedUpgradeGate is IFactoryManagedUpgradeGate, Ownable2StepUpgradeable, FactoryManagedUpgradeGateStorageV1 {
contract UpgradeGate is IUpgradeGate, Ownable2StepUpgradeable, UpgradeGateStorageV1 {
/// @notice Singleton admin upgrade gate for token implementation upgrades
/// @param initialAdmin Initial administrator for the contract
constructor(address initialAdmin) {
__Ownable_init(initialAdmin);
}

/// ///
/// CREATOR TOKEN UPGRADES ///
/// ///
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// SPDX-License-Identifier: MIT
pragma solidity 0.8.17;

abstract contract FactoryManagedUpgradeGateStorageV1 {
abstract contract UpgradeGateStorageV1 {
mapping(address => mapping(address => bool)) public isAllowedUpgrade;

uint256[50] private __gap;
Expand Down
6 changes: 5 additions & 1 deletion test/factory/ZoraCreator1155Factory.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {ProtocolRewards} from "@zoralabs/protocol-rewards/src/ProtocolRewards.so
import {ZoraCreator1155FactoryImpl} from "../../src/factory/ZoraCreator1155FactoryImpl.sol";
import {ZoraCreator1155Impl} from "../../src/nft/ZoraCreator1155Impl.sol";
import {Zora1155Factory} from "../../src/proxies/Zora1155Factory.sol";
import {UpgradeGate} from "../../src/upgrades/UpgradeGate.sol";
import {IZoraCreator1155Factory} from "../../src/interfaces/IZoraCreator1155Factory.sol";
import {IZoraCreator1155} from "../../src/interfaces/IZoraCreator1155.sol";
import {IZoraCreator1155Errors} from "../../src/interfaces/IZoraCreator1155Errors.sol";
Expand All @@ -21,6 +22,7 @@ contract ZoraCreator1155FactoryTest is Test {

ZoraCreator1155FactoryImpl internal factoryImpl;
ZoraCreator1155FactoryImpl internal factory;
UpgradeGate internal upgradeGate;

function setUp() external {
zora = makeAddr("zora");
Expand All @@ -35,6 +37,8 @@ contract ZoraCreator1155FactoryTest is Test {
factoryImpl = new ZoraCreator1155FactoryImpl(zoraCreator1155Impl, IMinter1155(address(1)), IMinter1155(address(2)), IMinter1155(address(3)));
factory = ZoraCreator1155FactoryImpl(address(factoryProxy));

upgradeGate = new UpgradeGate(zora);

vm.startPrank(zora);
factory.upgradeTo(address(factoryImpl));
factory.initialize(zora);
Expand Down Expand Up @@ -253,7 +257,7 @@ contract ZoraCreator1155FactoryTest is Test {
baseImpls[0] = address(factory.implementation());

vm.prank(zora);
factory.registerUpgradePath(baseImpls, address(newZoraCreator));
upgradeGate.registerUpgradePath(baseImpls, address(newZoraCreator));

vm.prank(creatorProxy.owner());
creatorProxy.upgradeTo(address(newZoraCreator));
Expand Down
13 changes: 6 additions & 7 deletions test/factory/ZoraCreator1155Factory_Fork.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,8 @@ import {ZoraCreatorFixedPriceSaleStrategy} from "../../src/minters/fixed-price/Z
import {ForkDeploymentConfig} from "../../src/deployment/DeploymentConfig.sol";

contract ZoraCreator1155FactoryForkTest is ForkDeploymentConfig, Test {
uint96 constant tokenPrice = 1 ether;
uint256 constant quantityToMint = 3;
uint256 constant tokenMaxSupply = 100;
uint32 constant royaltyMintSchedule = 10;
uint32 constant royaltyBPS = 100;

address collector;
address creator;
Expand Down Expand Up @@ -70,8 +67,8 @@ contract ZoraCreator1155FactoryForkTest is ForkDeploymentConfig, Test {
// create the contract, with no toekns
bytes[] memory initSetup = new bytes[](0);

uint32 royaltyMintSchedule = 10;
uint32 royaltyBPS = 100;
uint32 thisTestRoyaltyMintSchedule = 10;
uint32 thisTestRoyaltyBPS = 100;

address admin = creator;
string memory contractURI = "ipfs://asdfasdf";
Expand All @@ -82,9 +79,9 @@ contract ZoraCreator1155FactoryForkTest is ForkDeploymentConfig, Test {
contractURI,
name,
ICreatorRoyaltiesControl.RoyaltyConfiguration({
royaltyBPS: royaltyBPS,
royaltyBPS: thisTestRoyaltyBPS,
royaltyRecipient: royaltyRecipient,
royaltyMintSchedule: royaltyMintSchedule
royaltyMintSchedule: thisTestRoyaltyMintSchedule
}),
payable(admin),
initSetup
Expand All @@ -98,6 +95,8 @@ contract ZoraCreator1155FactoryForkTest is ForkDeploymentConfig, Test {
function testTheFork(string memory chainName) private {
console.log("testing on fork: ", chainName);

uint96 tokenPrice = 1 ether;

// create and select the fork, which will be used for all subsequent calls
// it will also affect the current block chain id based on the rpc url returned
vm.createSelectFork(vm.rpcUrl(chainName));
Expand Down
8 changes: 6 additions & 2 deletions test/minters/redeem/ZoraCreatorRedeemMinterFactory.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -47,15 +47,19 @@ contract ZoraCreatorRedeemMinterFactoryTest is Test {
vm.startPrank(tokenAdmin);
target.addPermission(0, address(minterFactory), target.PERMISSION_BIT_MINTER());
address predictedAddress = minterFactory.predictMinterAddress(address(target));
vm.expectEmit(false, false, false, false);
emit RedeemMinterDeployed(address(target), predictedAddress);
// vm.expectEmit(false, false, false, false);
// emit RedeemMinterDeployed(address(target), predictedAddress);
target.callSale(0, minterFactory, abi.encodeWithSelector(ZoraCreatorRedeemMinterFactory.createMinterIfNoneExists.selector, 0));
vm.stopPrank();

ZoraCreatorRedeemMinterStrategy minter = ZoraCreatorRedeemMinterStrategy(predictedAddress);
assertTrue(address(minter).code.length > 0);
}

// function test_contractVersion() public {
// assertEq(minterFactory.contractVersion(), "1.0.1");
// }

function test_createMinterRequiresIZoraCreator1155Caller() public {
ERC1155PresetMinterPauser randomToken = new ERC1155PresetMinterPauser("https://uri.com");

Expand Down
10 changes: 0 additions & 10 deletions test/mock/MockUpgradeGate.sol

This file was deleted.

10 changes: 0 additions & 10 deletions test/mock/MockUpgradeGateBase.sol

This file was deleted.

19 changes: 9 additions & 10 deletions test/nft/ZoraCreator1155.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {RewardsSettings} from "@zoralabs/protocol-rewards/src/abstract/RewardSpl
import {MathUpgradeable} from "@zoralabs/openzeppelin-contracts-upgradeable/contracts/utils/math/MathUpgradeable.sol";
import {ZoraCreator1155Impl} from "../../src/nft/ZoraCreator1155Impl.sol";
import {Zora1155} from "../../src/proxies/Zora1155.sol";
import {UpgradeGate} from "../../src/upgrades/UpgradeGate.sol";
import {ZoraCreatorFixedPriceSaleStrategy} from "../../src/minters/fixed-price/ZoraCreatorFixedPriceSaleStrategy.sol";

import {IZoraCreator1155Errors} from "../../src/interfaces/IZoraCreator1155Errors.sol";
Expand All @@ -20,7 +21,6 @@ import {ICreatorRendererControl} from "../../src/interfaces/ICreatorRendererCont

import {SimpleMinter} from "../mock/SimpleMinter.sol";
import {SimpleRenderer} from "../mock/SimpleRenderer.sol";
import {MockUpgradeGate} from "../mock/MockUpgradeGate.sol";

contract ZoraCreator1155Test is Test {
using stdJson for string;
Expand All @@ -31,7 +31,7 @@ contract ZoraCreator1155Test is Test {

SimpleMinter simpleMinter;
ZoraCreatorFixedPriceSaleStrategy internal fixedPriceMinter;
MockUpgradeGate internal upgradeGate;
UpgradeGate internal upgradeGate;

address payable internal admin;
address internal recipient;
Expand All @@ -55,20 +55,19 @@ contract ZoraCreator1155Test is Test {
createReferral = makeAddr("createReferral");
zora = makeAddr("zora");

protocolRewards = new ProtocolRewards();
upgradeGate = new MockUpgradeGate();
upgradeGate.initialize(admin);
zoraCreator1155Impl = new ZoraCreator1155Impl(0, zora, address(upgradeGate), address(protocolRewards));
target = ZoraCreator1155Impl(address(new Zora1155(address(zoraCreator1155Impl))));
simpleMinter = new SimpleMinter();
fixedPriceMinter = new ZoraCreatorFixedPriceSaleStrategy();

admin = payable(vm.addr(0x1));
recipient = vm.addr(0x2);
adminRole = target.PERMISSION_BIT_ADMIN();
minterRole = target.PERMISSION_BIT_MINTER();
fundsManagerRole = target.PERMISSION_BIT_FUNDS_MANAGER();
metadataRole = target.PERMISSION_BIT_METADATA();

protocolRewards = new ProtocolRewards();
upgradeGate = new UpgradeGate(admin);
zoraCreator1155Impl = new ZoraCreator1155Impl(0, zora, address(upgradeGate), address(protocolRewards));
target = ZoraCreator1155Impl(address(new Zora1155(address(zoraCreator1155Impl))));
simpleMinter = new SimpleMinter();
fixedPriceMinter = new ZoraCreatorFixedPriceSaleStrategy();
}

function _emptyInitData() internal pure returns (bytes[] memory response) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,14 @@
pragma solidity 0.8.17;

import {Test} from "forge-std/Test.sol";
import {MockUpgradeGateBase} from "../mock/MockUpgradeGateBase.sol";
import {UpgradeGate} from "../../src/upgrades/UpgradeGate.sol";

contract FactoryManagedUpgradeGateTest is Test {
MockUpgradeGateBase upgradeGate;
contract UpgradeGateTest is Test {
UpgradeGate upgradeGate;
address constant admin = address(0x123);

function setUp() public {
upgradeGate = new MockUpgradeGateBase();
upgradeGate.setup(admin);
upgradeGate = new UpgradeGate(admin);
}

function test_AdminOnly() public {
Expand Down

0 comments on commit 3584ef6

Please sign in to comment.