Skip to content

Commit

Permalink
combine legacy into current contract. encode mint arguments as bytes
Browse files Browse the repository at this point in the history
  • Loading branch information
oveddan committed Oct 17, 2023
1 parent 6f3877a commit 1f16b4b
Show file tree
Hide file tree
Showing 8 changed files with 171 additions and 194 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ library ZoraCreator1155Attribution {

function hashPremintV1(PremintConfig calldata premintConfig) public pure returns (bytes32) {
return
keccak256(abi.encode(ATTRIBUTION_DOMAIN_V1, _hashTokenV1(premintConfig.tokenConfig), premintConfig.uid, premintConfig.version, premintConfig.deleted));
keccak256(abi.encode(ATTRIBUTION_DOMAIN_V1, _hashToken(premintConfig.tokenConfig), premintConfig.uid, premintConfig.version, premintConfig.deleted));
}

function hashPremint(PremintConfigV2 calldata premintConfig) public pure returns (bytes32) {
Expand All @@ -118,7 +118,7 @@ library ZoraCreator1155Attribution {
"TokenCreationConfig(string tokenURI,uint256 maxSupply,uint64 maxTokensPerAddress,uint96 pricePerToken,uint64 mintStart,uint64 mintDuration,uint32 royaltyMintSchedule,uint32 royaltyBPS,address royaltyRecipient,address fixedPriceMinter)"
);

function _hashTokenV1(TokenCreationConfig calldata tokenConfig) private pure returns (bytes32) {
function _hashToken(TokenCreationConfig calldata tokenConfig) private pure returns (bytes32) {
return
keccak256(
abi.encode(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,55 @@ import {ZoraCreatorFixedPriceSaleStrategy} from "../minters/fixed-price/ZoraCrea
import {IMinter1155} from "../interfaces/IMinter1155.sol";
import {ERC1155DelegationStorageV1} from "../delegation/ERC1155DelegationStorageV1.sol";
import {ZoraCreator1155PremintExecutorImplLib } from './ZoraCreator1155PremintExecutorImplLib.sol';
import {ZoraCreator1155Attribution, ContractCreationConfig, PremintConfigV2, TokenCreationConfigV2} from "./ZoraCreator1155Attribution.sol";
import {IZoraCreator1155PremintExecutorImplV1, ZoraCreator1155PremintExecutorImplDeprecated} from './v1/ZoraCreator1155PremintExecutorImplDeprecated.sol';
import {ZoraCreator1155Attribution, ContractCreationConfig, PremintConfig, PremintConfigV2, TokenCreationConfig, TokenCreationConfigV2} from "./ZoraCreator1155Attribution.sol";

interface IZoraCreator1155PremintV1Signatures {
function delegateSetupNewToken(
PremintConfig calldata premintConfig,
bytes calldata signature,
address sender
) external returns (uint256 newTokenId);
}

// interface for legacy v1 of premint executor methods
// maintained in order to not break existing calls
// to legacy api when this api is upgraded
interface ILegacyZoraCreator1155PremintExecutor {
event Preminted(
address indexed contractAddress,
uint256 indexed tokenId,
bool indexed createdNewContract,
uint32 uid,
ContractCreationConfig contractConfig,
TokenCreationConfig tokenConfig,
address minter,
uint256 quantityMinted
);

function premint(
ContractCreationConfig calldata contractConfig,
PremintConfig calldata premintConfig,
bytes calldata signature,
uint256 quantityToMint,
string calldata mintComment
) external payable returns (uint256 newTokenId);

/// @notice Deprecated
function isValidSignature(
ContractCreationConfig calldata contractConfig,
PremintConfig calldata premintConfig,
bytes calldata signature
) external view returns (bool isValid, address contractAddress, address recoveredSigner);
}

/// @title Enables creation of and minting tokens on Zora1155 contracts transactions using eip-712 signatures.
/// Signature must provided by the contract creator, or an account that's permitted to create new tokens on the contract.
/// Mints the first x tokens to the executor of the transaction.
/// @author @oveddan
contract ZoraCreator1155PremintExecutorImpl is ZoraCreator1155PremintExecutorImplDeprecated, Ownable2StepUpgradeable, UUPSUpgradeable, IHasContractName, IZoraCreator1155Errors {
contract ZoraCreator1155PremintExecutorImpl is ILegacyZoraCreator1155PremintExecutor, Ownable2StepUpgradeable, UUPSUpgradeable, IHasContractName, IZoraCreator1155Errors {
IZoraCreator1155Factory public immutable zora1155Factory;

constructor(IZoraCreator1155Factory _factory) ZoraCreator1155PremintExecutorImplDeprecated(_factory) {
constructor(IZoraCreator1155Factory _factory) {
zora1155Factory = _factory;
}

Expand All @@ -41,7 +79,7 @@ contract ZoraCreator1155PremintExecutorImpl is ZoraCreator1155PremintExecutorImp
TokenCreationConfigV2 tokenConfig,
address minter,
uint256 quantityMinted,
address mintReferral
bytes mintArgumets
);

/// Creates a new token on the given erc1155 contract on behalf of a creator, and mints x tokens to the executor of this transaction.
Expand All @@ -53,14 +91,13 @@ contract ZoraCreator1155PremintExecutorImpl is ZoraCreator1155PremintExecutorImp
/// @param premintConfig Parameters for creating the token, and minting the initial x tokens to the executor.
/// @param signature Signature of the creator of the token, which must match the signer of the premint config, or have permission to create new tokens on the erc1155 contract if it's already been created
/// @param quantityToMint How many tokens to mint to the executor of this transaction once the token is created
/// @param mintComment A comment to associate with the mint action
/// @param mintArguments Abi encoded additional mint arguments: including mintComment and mintReferral
function premint(
ContractCreationConfig calldata contractConfig,
PremintConfigV2 calldata premintConfig,
bytes calldata signature,
uint256 quantityToMint,
address mintReferral,
string calldata mintComment
bytes calldata mintArguments
) external payable returns (uint256 newTokenId) {
// get or create the contract with the given params
// contract address is deterministic.
Expand All @@ -71,17 +108,7 @@ contract ZoraCreator1155PremintExecutorImpl is ZoraCreator1155PremintExecutorImp
// and then create and setup the token using the given token config.
newTokenId = tokenContract.delegateSetupNewToken(premintConfig, signature, msg.sender);

// if the executor would also like to mint:
if (quantityToMint != 0) {
// mint the number of specified tokens to the executor
tokenContract.mintWithRewards{value: msg.value}(
IMinter1155(premintConfig.tokenConfig.fixedPriceMinter),
newTokenId,
quantityToMint,
abi.encode(msg.sender, mintComment),
mintReferral
);
}
ZoraCreator1155PremintExecutorImplLib.performMint(tokenContract, premintConfig.tokenConfig.fixedPriceMinter, newTokenId, quantityToMint, mintArguments);

// emit Preminted event
emit PremintedV2(
Expand All @@ -93,7 +120,46 @@ contract ZoraCreator1155PremintExecutorImpl is ZoraCreator1155PremintExecutorImp
premintConfig.tokenConfig,
msg.sender,
quantityToMint,
mintReferral
mintArguments
);
}

/// Creates a new token on the given erc1155 contract on behalf of a creator, and mints x tokens to the executor of this transaction.
/// If the erc1155 contract hasn't been created yet, it will be created with the given config within this same transaction.
/// The creator must sign the intent to create the token, and must have mint new token permission on the erc1155 contract,
/// or match the contract admin on the contract creation config if the contract hasn't been created yet.
/// Contract address of the created contract is deterministically generated from the contract config and this contract's address.
/// @param contractConfig Parameters for creating a new contract, if one doesn't exist yet. Used to resolve the deterministic contract address.
/// @param premintConfig Parameters for creating the token, and minting the initial x tokens to the executor.
/// @param signature Signature of the creator of the token, which must match the signer of the premint config, or have permission to create new tokens on the erc1155 contract if it's already been created
/// @param quantityToMint How many tokens to mint to the executor of this transaction once the token is created
/// @param mintArguments Abi encoded additional mint arguments: including mintComment and mintReferral
function premint(
ContractCreationConfig calldata contractConfig,
PremintConfig calldata premintConfig,
bytes calldata signature,
uint256 quantityToMint,
bytes memory mintArguments
) public payable returns (uint256 newTokenId) {
// get or create the contract with the given params
// contract address is deterministic.
(IZoraCreator1155 tokenContract, bool isNewContract) = ZoraCreator1155PremintExecutorImplLib.getOrCreateContract(zora1155Factory, contractConfig);

// assume contract has legacy interface expecting v1 signatures; call it.
newTokenId = IZoraCreator1155PremintV1Signatures(address(tokenContract)).delegateSetupNewToken(premintConfig, signature, msg.sender);

ZoraCreator1155PremintExecutorImplLib.performMint(tokenContract, premintConfig.tokenConfig.fixedPriceMinter, newTokenId, quantityToMint, mintArguments);

// emit legacy Preminted event
emit Preminted(
address(tokenContract),
newTokenId,
isNewContract,
premintConfig.uid,
contractConfig,
premintConfig.tokenConfig,
msg.sender,
quantityToMint
);
}

Expand Down Expand Up @@ -123,7 +189,6 @@ contract ZoraCreator1155PremintExecutorImpl is ZoraCreator1155PremintExecutorImp
}
return (true, ERC1155DelegationStorageV1(contractAddress).delegatedTokenId(uid));
}


// upgrade related functionality

Expand All @@ -147,4 +212,29 @@ contract ZoraCreator1155PremintExecutorImpl is ZoraCreator1155PremintExecutorImp
function _equals(string memory a, string memory b) internal pure returns (bool) {
return (keccak256(bytes(a)) == keccak256(bytes(b)));
}

// Deprecated functions:

/// @notice Deprecated
function premint(
ContractCreationConfig calldata contractConfig,
PremintConfig calldata premintConfig,
bytes calldata signature,
uint256 quantityToMint,
string calldata mintComment
) external payable returns (uint256 newTokenId) {
// encode legacy mint arguments to call current function:
bytes memory mintArguments = ZoraCreator1155PremintExecutorImplLib.encodeMintArguments(address(0), mintComment);

return premint(contractConfig, premintConfig, signature, quantityToMint, mintArguments);
}

/// @notice Deprecated
function isValidSignature(
ContractCreationConfig calldata contractConfig,
PremintConfig calldata premintConfig,
bytes calldata signature
) public view returns (bool isValid, address contractAddress, address recoveredSigner) {

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {ContractCreationConfig} from './ZoraCreator1155Attribution.sol';
import {IZoraCreator1155} from "../interfaces/IZoraCreator1155.sol";
import {IZoraCreator1155Factory} from "../interfaces/IZoraCreator1155Factory.sol";
import {ICreatorRoyaltiesControl} from "../interfaces/ICreatorRoyaltiesControl.sol";
import {IMinter1155} from "../interfaces/IMinter1155.sol";

library ZoraCreator1155PremintExecutorImplLib {
function getOrCreateContract(IZoraCreator1155Factory zora1155Factory, ContractCreationConfig calldata contractConfig) internal returns (IZoraCreator1155 tokenContract, bool isNewContract) {
Expand Down Expand Up @@ -43,4 +44,26 @@ library ZoraCreator1155PremintExecutorImplLib {
return
zora1155Factory.deterministicContractAddress(address(this), contractConfig.contractURI, contractConfig.contractName, contractConfig.contractAdmin);
}

function performMint(IZoraCreator1155 tokenContract, address fixedPriceMinter, uint256 tokenId, uint256 quantityToMint, bytes memory mintArguments) internal {
(address mintReferral, string memory mintComment) = decodeMintArguments(mintArguments);

if (quantityToMint != 0)
// mint the number of specified tokens to the executor
tokenContract.mintWithRewards{value: msg.value}(
IMinter1155(fixedPriceMinter),
tokenId,
quantityToMint,
abi.encode(msg.sender, mintComment),
mintReferral
);
}

function encodeMintArguments(address mintReferral, string memory mintComment) internal pure returns (bytes memory) {
return abi.encode(mintReferral, mintComment);
}

function decodeMintArguments(bytes memory mintArguments) internal pure returns (address mintReferral, string memory mintComment) {
return abi.decode(mintArguments, (address, string));
}
}
Loading

0 comments on commit 1f16b4b

Please sign in to comment.