Skip to content

Commit

Permalink
wip on move premint to creator attribution style
Browse files Browse the repository at this point in the history
  • Loading branch information
oveddan committed Aug 3, 2023
1 parent 302ec51 commit 9270d18
Show file tree
Hide file tree
Showing 9 changed files with 355 additions and 489 deletions.
90 changes: 0 additions & 90 deletions script/EstimatePreminterGas.s.sol

This file was deleted.

9 changes: 0 additions & 9 deletions src/deployment/DeploymentConfig.sol
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,8 @@ struct Deployment {
address factoryImpl;
/// @notice Factory proxy contract that creates zora drops style NFT contracts
address factoryProxy;
<<<<<<< HEAD
=======
/// @notice Preminter contract address
address preminter;
>>>>>>> 9ec0422 (Premint)
}

abstract contract DeploymentConfig is CommonBase {
Expand All @@ -57,10 +54,7 @@ abstract contract DeploymentConfig is CommonBase {
string constant CONTRACT_1155_IMPL = "CONTRACT_1155_IMPL";
string constant FACTORY_IMPL = "FACTORY_IMPL";
string constant FACTORY_PROXY = "FACTORY_PROXY";
<<<<<<< HEAD
=======
string constant PREMINTER = "PREMINTER";
>>>>>>> 9ec0422 (Premint)

/// @notice Return a prefixed key for reading with a ".".
/// @param key key to prefix
Expand Down Expand Up @@ -88,10 +82,7 @@ abstract contract DeploymentConfig is CommonBase {
deployment.contract1155Impl = json.readAddress(getKeyPrefix(CONTRACT_1155_IMPL));
deployment.factoryImpl = json.readAddress(getKeyPrefix(FACTORY_IMPL));
deployment.factoryProxy = json.readAddress(getKeyPrefix(FACTORY_PROXY));
<<<<<<< HEAD
=======
deployment.preminter = json.readAddress(getKeyPrefix(PREMINTER));
>>>>>>> 9ec0422 (Premint)
}
}

Expand Down
3 changes: 3 additions & 0 deletions src/interfaces/IZoraCreator1155.sol
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,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/ZoraCreator1155Delegation.sol";

/*
Expand Down Expand Up @@ -103,6 +104,8 @@ interface IZoraCreator1155 is IZoraCreator1155TypesV1, IVersionedContract, IOwna
/// @param maxSupply maxSupply for the token, set to 0 for open edition
function setupNewToken(string memory tokenURI, uint256 maxSupply) external returns (uint256 tokenId);

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

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

function updateContractMetadata(string memory _newURI, string memory _newName) external;
Expand Down
81 changes: 77 additions & 4 deletions src/nft/ZoraCreator1155Impl.sol
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ 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, TokenSetup, PremintConfig} from "../premint/ZoraCreator1155Delegation.sol";

/// Imagine. Mint. Enjoy.
/// @title ZoraCreator1155Impl
Expand Down Expand Up @@ -206,6 +207,19 @@ contract ZoraCreator1155Impl is
_;
}

/// @notice Modifier checking if the user is an admin or has a role
/// @dev This reverts if the msg.sender is not an admin for the given token id or contract
/// @param tokenId tokenId to check
/// @param role role to check
modifier onlyAdminOrRoleInternal(
address msgSender,
uint256 tokenId,
uint256 role
) {
_requireAdminOrRole(msgSender, tokenId, role);
_;
}

/// @notice Modifier checking if the user is an admin
/// @dev This reverts if the msg.sender is not an admin for the given token id or contract
/// @param tokenId tokenId to check
Expand Down Expand Up @@ -247,18 +261,23 @@ contract ZoraCreator1155Impl is
/// @notice Set up a new token
/// @param newURI The URI for the token
/// @param maxSupply The maximum supply of the token
function setupNewToken(
function setupNewToken(string memory newURI, uint256 maxSupply) public nonReentrant returns (uint256) {
return _setupNewTokenInternal(msg.sender, newURI, maxSupply);
}

function _setupNewTokenInternal(
address msgSender,
string memory newURI,
uint256 maxSupply
) public onlyAdminOrRole(CONTRACT_BASE_ID, PERMISSION_BIT_MINTER) nonReentrant returns (uint256) {
) internal onlyAdminOrRoleInternal(msgSender, CONTRACT_BASE_ID, PERMISSION_BIT_MINTER) returns (uint256) {
uint256 tokenId = _setupNewToken(newURI, maxSupply);
// Allow the token creator to administrate this token
_addPermission(tokenId, msg.sender, PERMISSION_BIT_ADMIN);
_addPermission(tokenId, msgSender, PERMISSION_BIT_ADMIN);
if (bytes(newURI).length > 0) {
emit URI(newURI, tokenId);
}

emit SetupNewToken(tokenId, msg.sender, newURI, maxSupply);
emit SetupNewToken(tokenId, msgSender, newURI, maxSupply);

return tokenId;
}
Expand Down Expand Up @@ -635,4 +654,58 @@ contract ZoraCreator1155Impl is
revert();
}
}

/* start eip712 functionality */
bytes32 private constant _HASHED_NAME = keccak256(bytes("Preminter"));
bytes32 private constant _HASHED_VERSION = keccak256(bytes("1"));
bytes32 private constant _TYPE_HASH = keccak256("EIP712Domain(string name,string version,uint256 chainId,address verifyingContract)");

mapping(uint32 => bool) public uidUsed;

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

event CreatorAttribution(bytes32 structHash, bytes32 domainName, bytes32 version, bytes signature);

function delegateSetupNewToken(PremintConfig calldata premintConfig, bytes calldata signature) public returns (uint256 newTokenId) {
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;
}

// check that uid hasn't been used
if (uidUsed[premintConfig.uid]) {
revert PremintAlreadyExecuted();
} else {
uidUsed[premintConfig.uid] = true;
}

bytes32 hashedPremintConfig = ZoraCreator1155Attribution.hashPremintConfig(premintConfig);

// this is what attributes this token to have been created by the original creator
emit CreatorAttribution(hashedPremintConfig, ZoraCreator1155Attribution.HASHED_NAME, ZoraCreator1155Attribution.HASHED_VERSION, signature);

// recover the signer from the data
address recoveredSigner = ZoraCreator1155Attribution.recoverSignerHashed(hashedPremintConfig, signature, address(this));

// get the new token id - it will fail if the recovered signer does not have PERMISSION_BIT_MINTER permission
newTokenId = _setupNewTokenInternal(recoveredSigner, premintConfig.tokenConfig.tokenURI, premintConfig.tokenConfig.maxSupply);

// msg.sender should now have admin role on that token (lets make sure to remove it at the end of this call)

// invoke setup actions for new token, to save contract size, first get them from an external lib
bytes[] memory tokenSetupActions = TokenSetup.makeSetupNewTokenCalls(newTokenId, recoveredSigner, premintConfig.tokenConfig);

// then invoke them, calling account should be original msg.sender;
multicallInternal(tokenSetupActions);

// remove the token creator as admin of the newly created token:
_removePermission(newTokenId, msg.sender, PERMISSION_BIT_ADMIN);
}
}
106 changes: 0 additions & 106 deletions src/premint/EIP712UpgradeableWithChainId.sol

This file was deleted.

Loading

0 comments on commit 9270d18

Please sign in to comment.