Skip to content

Commit

Permalink
for premint executor, wrap failed erc1155 calls and their data
Browse files Browse the repository at this point in the history
  • Loading branch information
oveddan committed Sep 13, 2023
1 parent c122146 commit 2b8f57d
Show file tree
Hide file tree
Showing 2 changed files with 79 additions and 10 deletions.
36 changes: 29 additions & 7 deletions src/premint/ZoraCreator1155PremintExecutor.sol
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ contract ZoraCreator1155PremintExecutor is Ownable2StepUpgradeable, UUPSUpgradea
error MintNotYetStarted();
error InvalidSignature();

error Erc1155CallReverted(bytes errorReverted);

constructor(IZoraCreator1155Factory _factory) {
zora1155Factory = _factory;
}
Expand Down Expand Up @@ -70,16 +72,36 @@ contract ZoraCreator1155PremintExecutor is Ownable2StepUpgradeable, UUPSUpgradea

// pass the signature and the premint config to the token contract to create the token.
// The token contract will verify the signature and that the signer has permission to create a new token.
// and then create and setup the token using the given token config.
newTokenId = tokenContract.delegateSetupNewToken(premintConfig, signature);
// and then create and setup token using the given token config.
(bool success, bytes memory data) = address(tokenContract).call(
abi.encodeWithSelector(IZoraCreator1155.delegateSetupNewToken.selector, premintConfig, signature)
);

tokenContract.mint{value: msg.value}(
IMinter1155(premintConfig.tokenConfig.fixedPriceMinter),
newTokenId,
quantityToMint,
abi.encode(msg.sender, mintComment)
if (!success) {
// revert with original error that can be decoded later
revert Erc1155CallReverted(data);
}

// decode new token id from the token contract call
newTokenId = abi.decode(data, (uint256));

// now execute mint
(success, data) = address(tokenContract).call{value: msg.value}(
abi.encodeWithSelector(
IZoraCreator1155.mint.selector,
IMinter1155(premintConfig.tokenConfig.fixedPriceMinter),
newTokenId,
quantityToMint,
abi.encode(msg.sender, mintComment)
)
);

// if failed to call erc1155, revert with original error
if (!success) {
// revert with original error that can be decoded later
revert Erc1155CallReverted(data);
}

// emit Preminted event
emit Preminted(
address(tokenContract),
Expand Down
53 changes: 50 additions & 3 deletions test/premint/ZoraCreator1155PremintExecutor.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -337,7 +337,12 @@ 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(
abi.encodeWithSelector(
ZoraCreator1155PremintExecutor.Erc1155CallReverted.selector,
abi.encodeWithSelector(ZoraCreator1155Attribution.PremintDeleted.selector)
)
);
vm.prank(premintExecutor);
uint256 newTokenId = preminter.premint(contractConfig, premintConfig, signature, quantityToMint, comment);

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

if (shouldRevert) {
vm.expectRevert(ZoraCreator1155Attribution.MintNotYetStarted.selector);
vm.expectRevert(
abi.encodeWithSelector(
ZoraCreator1155PremintExecutor.Erc1155CallReverted.selector,
abi.encodeWithSelector(ZoraCreator1155Attribution.MintNotYetStarted.selector)
)
);
}

uint256 mintCost = mintFeeAmount * quantityToMint;
Expand Down Expand Up @@ -631,7 +641,12 @@ contract ZoraCreator1155PreminterTest is ForkDeploymentConfig, Test {
vm.deal(premintExecutor, mintCost);

// try to mint, it should revert
vm.expectRevert(abi.encodeWithSelector(IZoraCreator1155.UserMissingRoleForToken.selector, newCreator, CONTRACT_BASE_ID, PERMISSION_BIT_MINTER));
vm.expectRevert(
abi.encodeWithSelector(
ZoraCreator1155PremintExecutor.Erc1155CallReverted.selector,
abi.encodeWithSelector(IZoraCreator1155.UserMissingRoleForToken.selector, newCreator, CONTRACT_BASE_ID, PERMISSION_BIT_MINTER)
)
);
vm.prank(premintExecutor);
preminter.premint{value: mintCost}(contractConfig, premintConfig2, newCreatorSignature, quantityToMint, "yo");

Expand All @@ -650,6 +665,38 @@ contract ZoraCreator1155PreminterTest is ForkDeploymentConfig, Test {
preminter.premint{value: mintCost}(contractConfig, premintConfig2, newCreatorSignature, quantityToMint, "yo");
}

function test_premint_mintCallFails_revertsWithOriginalErrorInMessage() external {
ContractCreationConfig memory contractConfig = makeDefaultContractCreationConfig();
PremintConfig memory premintConfig = makeDefaultPremintConfig();

// how many tokens are minted to the executor
uint256 quantityToMint = 4;
uint256 chainId = block.chainid;
string memory comment = "hi";

// get contract hash, which is unique per contract creation config, and can be used
// retreive the address created for a contract
address contractAddress = preminter.getContractAddress(contractConfig);

bytes memory signature = _signPremint(contractAddress, premintConfig, creatorPrivateKey, chainId);

uint256 mintCost = mintFeeAmount * quantityToMint;

uint256 valueToSend = mintCost + 1 ether;
vm.deal(premintExecutor, valueToSend);

// execute premint
vm.prank(premintExecutor);
// it should revert with ZoraCreatorFixedPriceSaleStrategy.WrongValueSent error in the data field of the wrapped error
vm.expectRevert(
abi.encodeWithSelector(
ZoraCreator1155PremintExecutor.Erc1155CallReverted.selector,
abi.encodeWithSelector(ZoraCreatorFixedPriceSaleStrategy.WrongValueSent.selector)
)
);
preminter.premint{value: valueToSend}(contractConfig, premintConfig, signature, quantityToMint, comment);
}

function _signAndExecutePremint(
ContractCreationConfig memory contractConfig,
PremintConfig memory premintConfig,
Expand Down

0 comments on commit 2b8f57d

Please sign in to comment.