Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Seperate upgrade gate new contract #204

Merged
merged 6 commits into from
Sep 27, 2023
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion script/ZoraDeployerBase.sol
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import {ZoraCreator1155PremintExecutor} from "../src/delegation/ZoraCreator1155P
import {IMinter1155} from "../src/interfaces/IMinter1155.sol";

/// @notice Deployment drops for base where
abstract contract ZoraDeployerBase is ScriptDeploymentConfig, Script {
abstract contract ZoraDeployerBase is ScriptDeploymentConfig {
using stdJson for string;

/// @notice File used for demo metadata on verification test mint
Expand Down
3 changes: 2 additions & 1 deletion src/deployment/DeploymentConfig.sol
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ pragma solidity 0.8.17;
import "forge-std/Test.sol";
import {CommonBase} from "forge-std/Base.sol";
import {Strings} from "@openzeppelin/contracts/utils/Strings.sol";
import {Script} from "forge-std/Script.sol";

/// @notice Chain configuration for constants set manually during deploy. Does not get written to after deploys.
struct ChainConfig {
Expand Down Expand Up @@ -37,7 +38,7 @@ struct Deployment {
address preminter;
}

abstract contract DeploymentConfig is CommonBase {
abstract contract DeploymentConfig is Script {
using stdJson for string;

/// @notice ChainID convenience getter
Expand Down
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, Ownable2StepUpgradeable, ContractVersionBase, 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,10 @@
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 Event emitted when upgrade gate is emitted
event UpgradeGateSetup();

/// @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
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,25 +1,41 @@
// 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 Constructor for deployment pathway
constructor(address _defaultOwner) initializer {
__Ownable_init(_defaultOwner);
emit UpgradeGateSetup();
}

/// @notice The URI of the upgrade grate contract
function contractURI() external pure returns (string memory) {
return "https://github.com/ourzora/zora-1155-contracts/";
}

/// @notice The name of the upgrade gate contract
function contractName() external pure returns (string memory) {
return "ZORA 1155 Factory Managed Upgrade Gate";
}

/// ///
/// CREATOR TOKEN UPGRADES ///
/// CREATOR TOKEN UPGRADES ///
/// ///

/// @notice If an implementation is registered by the Builder DAO as an optional upgrade
/// @notice If an implementation is registered as an optional upgrade
/// @param baseImpl The base implementation address
/// @param upgradeImpl The upgrade implementation address
function isRegisteredUpgradePath(address baseImpl, address upgradeImpl) public view returns (bool) {
return isAllowedUpgrade[baseImpl][upgradeImpl];
}

/// @notice Called by the Builder DAO to offer implementation upgrades for created DAOs
/// @notice Registers optional upgrades
/// @param baseImpls The base implementation addresses
/// @param upgradeImpl The upgrade implementation address
function registerUpgradePath(address[] memory baseImpls, address upgradeImpl) public onlyOwner {
Expand All @@ -31,7 +47,7 @@ abstract contract FactoryManagedUpgradeGate is IFactoryManagedUpgradeGate, Ownab
}
}

/// @notice Called by the Builder DAO to remove an upgrade
/// @notice Removes an upgrade
/// @param baseImpl The base implementation address
/// @param upgradeImpl The upgrade implementation address
function removeUpgradePath(address baseImpl, address upgradeImpl) public onlyOwner {
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
8 changes: 6 additions & 2 deletions test/factory/ZoraCreator1155Factory.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {IZoraCreator1155Errors} from "../../src/interfaces/IZoraCreator1155Error
import {IMinter1155} from "../../src/interfaces/IMinter1155.sol";
import {ICreatorRoyaltiesControl} from "../../src/interfaces/ICreatorRoyaltiesControl.sol";
import {Zora1155} from "../../src/proxies/Zora1155.sol";
import {UpgradeGate} from "../../src/upgrades/UpgradeGate.sol";
import {MockContractMetadata} from "../mock/MockContractMetadata.sol";
import {ProxyShim} from "../../src/utils/ProxyShim.sol";

Expand All @@ -21,16 +22,19 @@ contract ZoraCreator1155FactoryTest is Test {

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

function setUp() external {
zora = makeAddr("zora");
mintFeeAmount = 0.000777 ether;

upgradeGate = new UpgradeGate(zora);

address factoryShimAddress = address(new ProxyShim(zora));
Zora1155Factory factoryProxy = new Zora1155Factory(factoryShimAddress, "");

ProtocolRewards protocolRewards = new ProtocolRewards();
ZoraCreator1155Impl zoraCreator1155Impl = new ZoraCreator1155Impl(mintFeeAmount, zora, address(factoryProxy), address(protocolRewards));
ZoraCreator1155Impl zoraCreator1155Impl = new ZoraCreator1155Impl(mintFeeAmount, zora, address(upgradeGate), address(protocolRewards));

factoryImpl = new ZoraCreator1155FactoryImpl(zoraCreator1155Impl, IMinter1155(address(1)), IMinter1155(address(2)), IMinter1155(address(3)));
factory = ZoraCreator1155FactoryImpl(address(factoryProxy));
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
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.

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

import {IZoraCreator1155Errors} from "../../src/interfaces/IZoraCreator1155Errors.sol";
import {IZoraCreator1155} from "../../src/interfaces/IZoraCreator1155.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,16 +55,16 @@ contract ZoraCreator1155Test is Test {
createReferral = makeAddr("createReferral");
zora = makeAddr("zora");

admin = payable(vm.addr(0x1));
recipient = vm.addr(0x2);

protocolRewards = new ProtocolRewards();
upgradeGate = new MockUpgradeGate();
upgradeGate.initialize(admin);
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();

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();
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
Loading