Skip to content

Commit

Permalink
Premint - move premint state to its own contract
Browse files Browse the repository at this point in the history
Renamed Premint folder to delegated mint
  • Loading branch information
oveddan committed Sep 19, 2023
1 parent 3468815 commit 35fdf4e
Show file tree
Hide file tree
Showing 12 changed files with 44 additions and 39 deletions.
5 changes: 5 additions & 0 deletions .changeset/popular-cows-grin.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@zoralabs/zora-1155-contracts": patch
---

Move delegated token creation state to its own contract
2 changes: 1 addition & 1 deletion script/ZoraDeployerBase.sol
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import {ScriptDeploymentConfig, Deployment, ChainConfig} from "../src/deployment
import {ProxyShim} from "../src/utils/ProxyShim.sol";
import {ZoraCreator1155FactoryImpl} from "../src/factory/ZoraCreator1155FactoryImpl.sol";
import {Zora1155PremintExecutorProxy} from "../src/proxies/Zora1155PremintExecutorProxy.sol";
import {ZoraCreator1155PremintExecutor} from "../src/premint/ZoraCreator1155PremintExecutor.sol";
import {ZoraCreator1155PremintExecutor} from "../src/delegation/ZoraCreator1155PremintExecutor.sol";
import {IMinter1155} from "../src/interfaces/IMinter1155.sol";

/// @notice Deployment drops for base where
Expand Down
6 changes: 6 additions & 0 deletions src/delegation/ERC1155DelegationStorageV1.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
// SPDX-License-Identifier: MIT
pragma solidity 0.8.17;

contract ERC1155DelegationStorageV1 {
mapping(uint32 => uint256) public delegatedTokenId;
}
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -156,24 +156,6 @@ library ZoraCreator1155Attribution {
function _stringHash(string calldata value) private pure returns (bytes32) {
return keccak256(bytes(value));
}

// todo: move to its own contract
error MintNotYetStarted();
error PremintDeleted();

function validateAndHashPremint(PremintConfig calldata premintConfig) external view returns (bytes32) {
if (premintConfig.tokenConfig.mintStart != 0 && premintConfig.tokenConfig.mintStart > block.timestamp) {
// if the mint start is in the future, then revert
revert MintNotYetStarted();
}
if (premintConfig.deleted) {
// if the signature says to be deleted, then dont execute any further minting logic;
// return 0
revert PremintDeleted();
}

return hashPremint(premintConfig);
}
}

// todo: make it consistent.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {IZoraCreator1155Factory} from "../interfaces/IZoraCreator1155Factory.sol
import {SharedBaseConstants} from "../shared/SharedBaseConstants.sol";
import {ZoraCreatorFixedPriceSaleStrategy} from "../minters/fixed-price/ZoraCreatorFixedPriceSaleStrategy.sol";
import {IMinter1155} from "../interfaces/IMinter1155.sol";
import {ERC1155DelegationStorageV1} from "../delegation/ERC1155DelegationStorageV1.sol";
import {PremintConfig, ContractCreationConfig, TokenCreationConfig, ZoraCreator1155Attribution} from "./ZoraCreator1155Attribution.sol";

/// @title Enables creation of and minting tokens on Zora1155 contracts transactions using eip-712 signatures.
Expand All @@ -25,9 +26,6 @@ contract ZoraCreator1155PremintExecutor is Ownable2StepUpgradeable, UUPSUpgradea
/// @dev copied from ZoraCreator1155Impl
uint256 constant PERMISSION_BIT_MINTER = 2 ** 2;

error MintNotYetStarted();
error InvalidSignature();

constructor(IZoraCreator1155Factory _factory) {
zora1155Factory = _factory;
}
Expand Down Expand Up @@ -142,7 +140,7 @@ contract ZoraCreator1155PremintExecutor is Ownable2StepUpgradeable, UUPSUpgradea
if (contractAddress.code.length == 0) {
return (false, 0);
}
return (true, IZoraCreator1155(contractAddress).delegatedTokenId(uid));
return (true, ERC1155DelegationStorageV1(contractAddress).delegatedTokenId(uid));
}

/// @notice Utility function to check if the signature is valid; i.e. the signature can be used to
Expand Down
4 changes: 1 addition & 3 deletions src/interfaces/IZoraCreator1155.sol
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {IMinter1155} from "../interfaces/IMinter1155.sol";
import {IOwnable} from "../interfaces/IOwnable.sol";
import {IVersionedContract} from "./IVersionedContract.sol";
import {ICreatorRoyaltiesControl} from "../interfaces/ICreatorRoyaltiesControl.sol";
import {PremintConfig} from "../premint/ZoraCreator1155Attribution.sol";
import {PremintConfig} from "../delegation/ZoraCreator1155Attribution.sol";

/*
Expand Down Expand Up @@ -84,8 +84,6 @@ interface IZoraCreator1155 is IZoraCreator1155TypesV1, IZoraCreator1155Errors, I

function delegateSetupNewToken(PremintConfig calldata premintConfig, bytes calldata signature) external returns (uint256 newTokenId);

function delegatedTokenId(uint32 uid) external view returns (uint256 tokenId);

function updateTokenURI(uint256 tokenId, string memory _newURI) external;

function updateContractMetadata(string memory _newURI, string memory _newName) external;
Expand Down
3 changes: 3 additions & 0 deletions src/interfaces/IZoraCreator1155Errors.sol
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,7 @@ interface IZoraCreator1155Errors {
error ProtocolRewardsWithdrawFailed(address caller, address recipient, uint256 amount);

error CannotMintMoreTokens(uint256 tokenId, uint256 quantity, uint256 totalMinted, uint256 maxSupply);

error MintNotYetStarted();
error PremintDeleted();
}
25 changes: 19 additions & 6 deletions src/nft/ZoraCreator1155Impl.sol
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ import {PublicMulticall} from "../utils/PublicMulticall.sol";
import {SharedBaseConstants} from "../shared/SharedBaseConstants.sol";
import {TransferHelperUtils} from "../utils/TransferHelperUtils.sol";
import {ZoraCreator1155StorageV1} from "./ZoraCreator1155StorageV1.sol";
import {ZoraCreator1155Attribution, PremintTokenSetup, PremintConfig} from "../premint/ZoraCreator1155Attribution.sol";
import {ERC1155DelegationStorageV1} from "../delegation/ERC1155DelegationStorageV1.sol";
import {ZoraCreator1155Attribution, PremintTokenSetup, PremintConfig} from "../delegation/ZoraCreator1155Attribution.sol";

/// Imagine. Mint. Enjoy.
/// @title ZoraCreator1155Impl
Expand All @@ -50,7 +51,8 @@ contract ZoraCreator1155Impl is
CreatorPermissionControl,
CreatorRoyaltiesControl,
ERC1155Rewards,
ERC1155RewardsStorageV1
ERC1155RewardsStorageV1,
ERC1155DelegationStorageV1
{
/// @notice This user role allows for any action to be performed
uint256 public constant PERMISSION_BIT_ADMIN = 2 ** 1;
Expand Down Expand Up @@ -759,17 +761,16 @@ contract ZoraCreator1155Impl is
}
}

/* start eip712 functionality */
mapping(uint32 => uint256) public delegatedTokenId;

function delegateSetupNewToken(PremintConfig calldata premintConfig, bytes calldata signature) public nonReentrant returns (uint256 newTokenId) {
// if a token has already been created for a premint config with this uid:
if (delegatedTokenId[premintConfig.uid] != 0) {
// return its token id
return delegatedTokenId[premintConfig.uid];
}

bytes32 hashedPremintConfig = ZoraCreator1155Attribution.validateAndHashPremint(premintConfig);
validatePremint(premintConfig);

bytes32 hashedPremintConfig = ZoraCreator1155Attribution.hashPremint(premintConfig);

// recover the signer from the data
address creator = ZoraCreator1155Attribution.recoverSignerHashed(hashedPremintConfig, signature, address(this), block.chainid);
Expand Down Expand Up @@ -797,4 +798,16 @@ contract ZoraCreator1155Impl is
// grant the token creator as admin of the newly created token
_addPermission(newTokenId, creator, PERMISSION_BIT_ADMIN);
}

function validatePremint(PremintConfig calldata premintConfig) private view {
if (premintConfig.tokenConfig.mintStart != 0 && premintConfig.tokenConfig.mintStart > block.timestamp) {
// if the mint start is in the future, then revert
revert MintNotYetStarted();
}
if (premintConfig.deleted) {
// if the signature says to be deleted, then dont execute any further minting logic;
// return 0
revert PremintDeleted();
}
}
}
2 changes: 1 addition & 1 deletion test/fixtures/Zora1155PremintFixtures.sol
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {Zora1155Factory} from "../../src/proxies/Zora1155Factory.sol";
import {ZoraCreator1155FactoryImpl} from "../../src/factory/ZoraCreator1155FactoryImpl.sol";
import {ProtocolRewards} from "@zoralabs/protocol-rewards/src/ProtocolRewards.sol";
import {ProxyShim} from "../../src/utils/ProxyShim.sol";
import {ContractCreationConfig, TokenCreationConfig, PremintConfig} from "../../src/premint/ZoraCreator1155Attribution.sol";
import {ContractCreationConfig, TokenCreationConfig, PremintConfig} from "../../src/delegation/ZoraCreator1155Attribution.sol";

library Zora1155PremintFixtures {
function makeDefaultContractCreationConfig(address contractAdmin) internal pure returns (ContractCreationConfig memory) {
Expand Down
4 changes: 2 additions & 2 deletions test/premint/Zora1155PremintExecutorProxy.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ import {Zora1155PremintFixtures} from "../fixtures/Zora1155PremintFixtures.sol";
import {ZoraCreator1155FactoryImpl} from "../../src/factory/ZoraCreator1155FactoryImpl.sol";
import {Zora1155PremintExecutorProxy} from "../../src/proxies/Zora1155PremintExecutorProxy.sol";
import {ZoraCreator1155Impl} from "../../src/nft/ZoraCreator1155Impl.sol";
import {ZoraCreator1155PremintExecutor} from "../../src/premint/ZoraCreator1155PremintExecutor.sol";
import {ZoraCreator1155PremintExecutor} from "../../src/delegation/ZoraCreator1155PremintExecutor.sol";
import {Zora1155Factory} from "../../src/proxies/Zora1155Factory.sol";
import {IMinter1155} from "../../src/interfaces/IMinter1155.sol";
import {ProxyShim} from "../../src/utils/ProxyShim.sol";
import {ZoraCreator1155Attribution, ContractCreationConfig, TokenCreationConfig, PremintConfig} from "../../src/premint/ZoraCreator1155Attribution.sol";
import {ZoraCreator1155Attribution, ContractCreationConfig, TokenCreationConfig, PremintConfig} from "../../src/delegation/ZoraCreator1155Attribution.sol";
import {IOwnable2StepUpgradeable} from "../../src/utils/ownable/IOwnable2StepUpgradeable.sol";
import {IHasContractName} from "../../src/interfaces/IContractMetadata.sol";

Expand Down
8 changes: 4 additions & 4 deletions test/premint/ZoraCreator1155PremintExecutor.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ import {ICreatorRoyaltiesControl} from "../../src/interfaces/ICreatorRoyaltiesCo
import {ZoraCreatorFixedPriceSaleStrategy} from "../../src/minters/fixed-price/ZoraCreatorFixedPriceSaleStrategy.sol";
import {Zora1155Factory} from "../../src/proxies/Zora1155Factory.sol";
import {ZoraCreator1155FactoryImpl} from "../../src/factory/ZoraCreator1155FactoryImpl.sol";
import {ZoraCreator1155PremintExecutor} from "../../src/premint/ZoraCreator1155PremintExecutor.sol";
import {ZoraCreator1155Attribution, ContractCreationConfig, TokenCreationConfig, PremintConfig} from "../../src/premint/ZoraCreator1155Attribution.sol";
import {ZoraCreator1155PremintExecutor} from "../../src/delegation/ZoraCreator1155PremintExecutor.sol";
import {ZoraCreator1155Attribution, ContractCreationConfig, TokenCreationConfig, PremintConfig} from "../../src/delegation/ZoraCreator1155Attribution.sol";
import {ForkDeploymentConfig} from "../../src/deployment/DeploymentConfig.sol";
import {ProxyShim} from "../../src/utils/ProxyShim.sol";

Expand Down Expand Up @@ -338,7 +338,7 @@ contract ZoraCreator1155PreminterTest is ForkDeploymentConfig, Test {
bytes memory signature = _signPremint(contractAddress, premintConfig, creatorPrivateKey, chainId);

// now call the premint function, using the same config that was used to generate the digest, and the signature
vm.expectRevert(ZoraCreator1155Attribution.PremintDeleted.selector);
vm.expectRevert(IZoraCreator1155Errors.PremintDeleted.selector);
vm.prank(premintExecutor);
uint256 newTokenId = preminter.premint(contractConfig, premintConfig, signature, quantityToMint, comment);

Expand Down Expand Up @@ -510,7 +510,7 @@ contract ZoraCreator1155PreminterTest is ForkDeploymentConfig, Test {
bytes memory signature = _signPremint(preminter.getContractAddress(contractConfig), premintConfig, creatorPrivateKey, chainId);

if (shouldRevert) {
vm.expectRevert(ZoraCreator1155Attribution.MintNotYetStarted.selector);
vm.expectRevert(IZoraCreator1155Errors.MintNotYetStarted.selector);
}

uint256 mintCost = mintFeeAmount * quantityToMint;
Expand Down

0 comments on commit 35fdf4e

Please sign in to comment.