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 9, 2023
1 parent fdf504a commit bc8f57c
Show file tree
Hide file tree
Showing 8 changed files with 414 additions and 535 deletions.
90 changes: 0 additions & 90 deletions script/EstimatePreminterGas.s.sol

This file was deleted.

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 @@ -104,6 +105,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
64 changes: 64 additions & 0 deletions src/nft/ZoraCreator1155Impl.sol
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,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 @@ -722,4 +723,67 @@ 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();
error PremintDeleted();

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

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

if (premintConfig.deleted) {
// if the signature says to be deleted, then dont execute any further minting logic;
// return 0
revert PremintDeleted();
}

bytes32 hashedPremintConfig = ZoraCreator1155Attribution.hashPremint(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), block.chainid);

// require that the signer can create new tokens (is a valid creator)
_requireAdminOrRole(recoveredSigner, CONTRACT_BASE_ID, PERMISSION_BIT_MINTER);

// temporarily grant msg sender admin permission to create new tokens
_addPermission(CONTRACT_BASE_ID, msg.sender, PERMISSION_BIT_MINTER);

// get the new token id - it will fail if the recovered signer does not have PERMISSION_BIT_MINTER permission
newTokenId = setupNewToken(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);
// grant the token creator as admin of the newly created token
_addPermission(newTokenId, recoveredSigner, PERMISSION_BIT_ADMIN);
}
}
106 changes: 0 additions & 106 deletions src/premint/EIP712UpgradeableWithChainId.sol

This file was deleted.

Loading

0 comments on commit bc8f57c

Please sign in to comment.