Skip to content

Commit

Permalink
Extracted erc1155 errors to an interface, and importing that into pre…
Browse files Browse the repository at this point in the history
…mint contract (#170)
  • Loading branch information
oveddan committed Sep 20, 2023
1 parent d3a8f64 commit be87f52
Show file tree
Hide file tree
Showing 16 changed files with 67 additions and 51 deletions.
28 changes: 2 additions & 26 deletions src/interfaces/IZoraCreator1155.sol
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ pragma solidity 0.8.17;
import {IERC165Upgradeable} from "@zoralabs/openzeppelin-contracts-upgradeable/contracts/interfaces/IERC165Upgradeable.sol";
import {IERC1155MetadataURIUpgradeable} from "@zoralabs/openzeppelin-contracts-upgradeable/contracts/interfaces/IERC1155MetadataURIUpgradeable.sol";
import {IZoraCreator1155TypesV1} from "../nft/IZoraCreator1155TypesV1.sol";
import {IZoraCreator1155Errors} from "./IZoraCreator1155Errors.sol";
import {IRenderer1155} from "../interfaces/IRenderer1155.sol";
import {IMinter1155} from "../interfaces/IMinter1155.sol";
import {IOwnable} from "../interfaces/IOwnable.sol";
Expand Down Expand Up @@ -35,7 +36,7 @@ import {PremintConfig} from "../premint/ZoraCreator1155Attribution.sol";

/// @notice Main interface for the ZoraCreator1155 contract
/// @author @iainnash / @tbtstl
interface IZoraCreator1155 is IZoraCreator1155TypesV1, IVersionedContract, IOwnable, IERC1155MetadataURIUpgradeable {
interface IZoraCreator1155 is IZoraCreator1155TypesV1, IZoraCreator1155Errors, IVersionedContract, IOwnable, IERC1155MetadataURIUpgradeable {
function PERMISSION_BIT_ADMIN() external returns (uint256);

function PERMISSION_BIT_MINTER() external returns (uint256);
Expand All @@ -62,31 +63,6 @@ interface IZoraCreator1155 is IZoraCreator1155TypesV1, IVersionedContract, IOwna
event Purchased(address indexed sender, address indexed minter, uint256 indexed tokenId, uint256 quantity, uint256 value);
event CreatorAttribution(bytes32 structHash, string domainName, string version, address creator, bytes signature);

error TokenIdMismatch(uint256 expected, uint256 actual);
error UserMissingRoleForToken(address user, uint256 tokenId, uint256 role);

error Config_TransferHookNotSupported(address proposedAddress);

error Mint_InsolventSaleTransfer();
error Mint_ValueTransferFail();
error Mint_TokenIDMintNotAllowed();
error Mint_UnknownCommand();

error Burn_NotOwnerOrApproved(address operator, address user);

error NewOwnerNeedsToBeAdmin();

error Sale_CannotCallNonSalesContract(address targetContract);

error CallFailed(bytes reason);
error Renderer_NotValidRendererContract();

error ETHWithdrawFailed(address recipient, uint256 amount);
error FundsWithdrawInsolvent(uint256 amount, uint256 contractValue);
error ProtocolRewardsWithdrawFailed(address caller, address recipient, uint256 amount);

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

/// @notice Only allow minting one token id at time
/// @dev Mint contract function that calls the underlying sales function for commands
/// @param minter Address for the minter
Expand Down
29 changes: 29 additions & 0 deletions src/interfaces/IZoraCreator1155Errors.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// SPDX-License-Identifier: MIT
pragma solidity 0.8.17;

interface IZoraCreator1155Errors {
error TokenIdMismatch(uint256 expected, uint256 actual);
error UserMissingRoleForToken(address user, uint256 tokenId, uint256 role);

error Config_TransferHookNotSupported(address proposedAddress);

error Mint_InsolventSaleTransfer();
error Mint_ValueTransferFail();
error Mint_TokenIDMintNotAllowed();
error Mint_UnknownCommand();

error Burn_NotOwnerOrApproved(address operator, address user);

error NewOwnerNeedsToBeAdmin();

error Sale_CannotCallNonSalesContract(address targetContract);

error CallFailed(bytes reason);
error Renderer_NotValidRendererContract();

error ETHWithdrawFailed(address recipient, uint256 amount);
error FundsWithdrawInsolvent(uint256 amount, uint256 contractValue);
error ProtocolRewardsWithdrawFailed(address caller, address recipient, uint256 amount);

error CannotMintMoreTokens(uint256 tokenId, uint256 quantity, uint256 totalMinted, uint256 maxSupply);
}
3 changes: 2 additions & 1 deletion src/premint/ZoraCreator1155PremintExecutor.sol
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {UUPSUpgradeable} from "@zoralabs/openzeppelin-contracts-upgradeable/cont
import {Ownable2StepUpgradeable} from "../utils/ownable/Ownable2StepUpgradeable.sol";
import {IHasContractName} from "../interfaces/IContractMetadata.sol";
import {IZoraCreator1155} from "../interfaces/IZoraCreator1155.sol";
import {IZoraCreator1155Errors} from "../interfaces/IZoraCreator1155Errors.sol";
import {IZoraCreator1155Factory} from "../interfaces/IZoraCreator1155Factory.sol";
import {SharedBaseConstants} from "../shared/SharedBaseConstants.sol";
import {ZoraCreatorFixedPriceSaleStrategy} from "../minters/fixed-price/ZoraCreatorFixedPriceSaleStrategy.sol";
Expand All @@ -16,7 +17,7 @@ import {PremintConfig, ContractCreationConfig, TokenCreationConfig, ZoraCreator1
/// 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 ZoraCreator1155PremintExecutor is Ownable2StepUpgradeable, UUPSUpgradeable, IHasContractName {
contract ZoraCreator1155PremintExecutor is Ownable2StepUpgradeable, UUPSUpgradeable, IHasContractName, IZoraCreator1155Errors {
IZoraCreator1155Factory public immutable zora1155Factory;

/// @notice copied from SharedBaseConstants
Expand Down
1 change: 1 addition & 0 deletions test/factory/ZoraCreator1155Factory.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {ZoraCreator1155Impl} from "../../src/nft/ZoraCreator1155Impl.sol";
import {Zora1155Factory} from "../../src/proxies/Zora1155Factory.sol";
import {IZoraCreator1155Factory} from "../../src/interfaces/IZoraCreator1155Factory.sol";
import {IZoraCreator1155} from "../../src/interfaces/IZoraCreator1155.sol";
import {IZoraCreator1155Errors} from "../../src/interfaces/IZoraCreator1155Errors.sol";
import {IMinter1155} from "../../src/interfaces/IMinter1155.sol";
import {ICreatorRoyaltiesControl} from "../../src/interfaces/ICreatorRoyaltiesControl.sol";
import {Zora1155} from "../../src/proxies/Zora1155.sol";
Expand Down
1 change: 1 addition & 0 deletions test/factory/ZoraCreator1155Factory_Fork.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ pragma solidity 0.8.17;

import "forge-std/Test.sol";
import {IZoraCreator1155Factory} from "../../src/interfaces/IZoraCreator1155Factory.sol";
import {IZoraCreator1155Errors} from "../../src/interfaces/IZoraCreator1155Errors.sol";
import {IZoraCreator1155} from "../../src/interfaces/IZoraCreator1155.sol";
import {ZoraCreator1155Impl} from "../../src/nft/ZoraCreator1155Impl.sol";
import {IMinter1155} from "../../src/interfaces/IMinter1155.sol";
Expand Down
1 change: 1 addition & 0 deletions test/fixtures/Zora1155FactoryFixtures.sol
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ pragma solidity 0.8.17;

import {ZoraCreator1155Impl} from "../../src/nft/ZoraCreator1155Impl.sol";
import {ZoraCreatorFixedPriceSaleStrategy} from "../../src/minters/fixed-price/ZoraCreatorFixedPriceSaleStrategy.sol";
import {IZoraCreator1155Errors} from "../../src/interfaces/IZoraCreator1155Errors.sol";
import {IZoraCreator1155} from "../../src/interfaces/IZoraCreator1155.sol";
import {IMinter1155} from "../../src/interfaces/IMinter1155.sol";
import {Zora1155Factory} from "../../src/proxies/Zora1155Factory.sol";
Expand Down
2 changes: 1 addition & 1 deletion test/fixtures/Zora1155PremintFixtures.sol
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ pragma solidity 0.8.17;

import {ZoraCreator1155Impl} from "../../src/nft/ZoraCreator1155Impl.sol";
import {ZoraCreatorFixedPriceSaleStrategy} from "../../src/minters/fixed-price/ZoraCreatorFixedPriceSaleStrategy.sol";
import {IZoraCreator1155} from "../../src/interfaces/IZoraCreator1155.sol";
import {IZoraCreator1155Errors} from "../../src/interfaces/IZoraCreator1155Errors.sol";
import {IMinter1155} from "../../src/interfaces/IMinter1155.sol";
import {ICreatorRoyaltiesControl} from "../../src/interfaces/ICreatorRoyaltiesControl.sol";
import {Zora1155Factory} from "../../src/proxies/Zora1155Factory.sol";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import "forge-std/Test.sol";
import {ProtocolRewards} from "@zoralabs/protocol-rewards/src/ProtocolRewards.sol";
import {ZoraCreator1155Impl} from "../../../src/nft/ZoraCreator1155Impl.sol";
import {Zora1155} from "../../../src/proxies/Zora1155.sol";
import {IZoraCreator1155} from "../../../src/interfaces/IZoraCreator1155.sol";
import {IZoraCreator1155Errors} from "../../../src/interfaces/IZoraCreator1155Errors.sol";
import {IMinter1155} from "../../../src/interfaces/IMinter1155.sol";
import {ICreatorRoyaltiesControl} from "../../../src/interfaces/ICreatorRoyaltiesControl.sol";
import {IZoraCreator1155Factory} from "../../../src/interfaces/IZoraCreator1155Factory.sol";
Expand Down
2 changes: 1 addition & 1 deletion test/minters/merkle/ZoraCreatorMerkleMinterStrategy.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import "forge-std/Test.sol";
import {ProtocolRewards} from "@zoralabs/protocol-rewards/src/ProtocolRewards.sol";
import {ZoraCreator1155Impl} from "../../../src/nft/ZoraCreator1155Impl.sol";
import {Zora1155} from "../../../src/proxies/Zora1155.sol";
import {IZoraCreator1155} from "../../../src/interfaces/IZoraCreator1155.sol";
import {IZoraCreator1155Errors} from "../../../src/interfaces/IZoraCreator1155Errors.sol";
import {IRenderer1155} from "../../../src/interfaces/IRenderer1155.sol";
import {ICreatorRoyaltiesControl} from "../../../src/interfaces/ICreatorRoyaltiesControl.sol";
import {ILimitedMintPerAddress} from "../../../src/interfaces/ILimitedMintPerAddress.sol";
Expand Down
2 changes: 1 addition & 1 deletion test/minters/redeem/ZoraCreatorRedeemMinterFactory.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {ProtocolRewards} from "@zoralabs/protocol-rewards/src/ProtocolRewards.so
import {ZoraCreator1155Impl} from "../../../src/nft/ZoraCreator1155Impl.sol";
import {Zora1155} from "../../../src/proxies/Zora1155.sol";
import {IMinter1155} from "../../../src/interfaces/IMinter1155.sol";
import {IZoraCreator1155} from "../../../src/interfaces/IZoraCreator1155.sol";
import {IZoraCreator1155Errors} from "../../../src/interfaces/IZoraCreator1155Errors.sol";
import {IRenderer1155} from "../../../src/interfaces/IRenderer1155.sol";
import {ICreatorRoyaltiesControl} from "../../../src/interfaces/ICreatorRoyaltiesControl.sol";
import {IZoraCreator1155Factory} from "../../../src/interfaces/IZoraCreator1155Factory.sol";
Expand Down
2 changes: 1 addition & 1 deletion test/minters/redeem/ZoraCreatorRedeemMinterStrategy.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {ERC1155PresetMinterPauser} from "@openzeppelin/contracts/token/ERC1155/p
import {ProtocolRewards} from "@zoralabs/protocol-rewards/src/ProtocolRewards.sol";
import {ZoraCreator1155Impl} from "../../../src/nft/ZoraCreator1155Impl.sol";
import {Zora1155} from "../../../src/proxies/Zora1155.sol";
import {IZoraCreator1155} from "../../../src/interfaces/IZoraCreator1155.sol";
import {IZoraCreator1155Errors} from "../../../src/interfaces/IZoraCreator1155Errors.sol";
import {IRenderer1155} from "../../../src/interfaces/IRenderer1155.sol";
import {ICreatorRoyaltiesControl} from "../../../src/interfaces/ICreatorRoyaltiesControl.sol";
import {IZoraCreator1155Factory} from "../../../src/interfaces/IZoraCreator1155Factory.sol";
Expand Down
33 changes: 19 additions & 14 deletions test/nft/ZoraCreator1155.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {ZoraCreator1155Impl} from "../../src/nft/ZoraCreator1155Impl.sol";
import {Zora1155} from "../../src/proxies/Zora1155.sol";
import {ZoraCreatorFixedPriceSaleStrategy} from "../../src/minters/fixed-price/ZoraCreatorFixedPriceSaleStrategy.sol";

import {IZoraCreator1155Errors} from "../../src/interfaces/IZoraCreator1155Errors.sol";
import {IZoraCreator1155} from "../../src/interfaces/IZoraCreator1155.sol";
import {IRenderer1155} from "../../src/interfaces/IRenderer1155.sol";
import {IZoraCreator1155TypesV1} from "../../src/nft/IZoraCreator1155TypesV1.sol";
Expand Down Expand Up @@ -215,7 +216,7 @@ contract ZoraCreator1155Test is Test {
function test_setupNewToken_revertOnlyAdminOrRole() external {
init();

vm.expectRevert(abi.encodeWithSelector(IZoraCreator1155.UserMissingRoleForToken.selector, address(this), 0, target.PERMISSION_BIT_MINTER()));
vm.expectRevert(abi.encodeWithSelector(IZoraCreator1155Errors.UserMissingRoleForToken.selector, address(this), 0, target.PERMISSION_BIT_MINTER()));
target.setupNewToken("test", 1);
}

Expand Down Expand Up @@ -260,7 +261,7 @@ contract ZoraCreator1155Test is Test {
function test_setTokenMetadataRenderer_revertOnlyAdminOrRole() external {
init();

vm.expectRevert(abi.encodeWithSelector(IZoraCreator1155.UserMissingRoleForToken.selector, address(this), 0, target.PERMISSION_BIT_METADATA()));
vm.expectRevert(abi.encodeWithSelector(IZoraCreator1155Errors.UserMissingRoleForToken.selector, address(this), 0, target.PERMISSION_BIT_METADATA()));
target.setTokenMetadataRenderer(0, IRenderer1155(address(0)));
}

Expand All @@ -281,7 +282,7 @@ contract ZoraCreator1155Test is Test {
vm.assume(tokenId != 0);
init();

vm.expectRevert(abi.encodeWithSelector(IZoraCreator1155.UserMissingRoleForToken.selector, recipient, tokenId, adminRole));
vm.expectRevert(abi.encodeWithSelector(IZoraCreator1155Errors.UserMissingRoleForToken.selector, recipient, tokenId, adminRole));
vm.prank(recipient);
target.addPermission(tokenId, recipient, adminRole);
}
Expand Down Expand Up @@ -332,7 +333,7 @@ contract ZoraCreator1155Test is Test {
vm.assume(tokenId != 0);
init();

vm.expectRevert(abi.encodeWithSelector(IZoraCreator1155.UserMissingRoleForToken.selector, recipient, tokenId, adminRole));
vm.expectRevert(abi.encodeWithSelector(IZoraCreator1155Errors.UserMissingRoleForToken.selector, recipient, tokenId, adminRole));
vm.prank(recipient);
target.removePermission(tokenId, address(0), adminRole);
}
Expand Down Expand Up @@ -413,7 +414,9 @@ contract ZoraCreator1155Test is Test {
vm.prank(admin);
uint256 tokenId = target.setupNewToken("test", 1000);

vm.expectRevert(abi.encodeWithSelector(IZoraCreator1155.UserMissingRoleForToken.selector, address(this), tokenId, target.PERMISSION_BIT_MINTER()));
vm.expectRevert(
abi.encodeWithSelector(IZoraCreator1155Errors.UserMissingRoleForToken.selector, address(this), tokenId, target.PERMISSION_BIT_MINTER())
);
target.adminMint(address(0), tokenId, 0, "");
}

Expand All @@ -424,7 +427,7 @@ contract ZoraCreator1155Test is Test {
vm.prank(admin);
uint256 tokenId = target.setupNewToken("test", quantity - 1);

vm.expectRevert(abi.encodeWithSelector(IZoraCreator1155.CannotMintMoreTokens.selector, tokenId, quantity, 0, quantity - 1));
vm.expectRevert(abi.encodeWithSelector(IZoraCreator1155Errors.CannotMintMoreTokens.selector, tokenId, quantity, 0, quantity - 1));
vm.prank(admin);
target.adminMint(recipient, tokenId, quantity, "");
}
Expand Down Expand Up @@ -540,7 +543,9 @@ contract ZoraCreator1155Test is Test {
tokenIds[0] = tokenId;
quantities[0] = 0;

vm.expectRevert(abi.encodeWithSelector(IZoraCreator1155.UserMissingRoleForToken.selector, address(this), tokenId, target.PERMISSION_BIT_MINTER()));
vm.expectRevert(
abi.encodeWithSelector(IZoraCreator1155Errors.UserMissingRoleForToken.selector, address(this), tokenId, target.PERMISSION_BIT_MINTER())
);
target.adminMintBatch(address(0), tokenIds, quantities, "");
}

Expand All @@ -556,7 +561,7 @@ contract ZoraCreator1155Test is Test {
tokenIds[0] = tokenId;
quantities[0] = quantity;

vm.expectRevert(abi.encodeWithSelector(IZoraCreator1155.CannotMintMoreTokens.selector, tokenId, quantity, 0, quantity - 1));
vm.expectRevert(abi.encodeWithSelector(IZoraCreator1155Errors.CannotMintMoreTokens.selector, tokenId, quantity, 0, quantity - 1));
vm.prank(admin);
target.adminMintBatch(recipient, tokenIds, quantities, "");
}
Expand Down Expand Up @@ -605,7 +610,7 @@ contract ZoraCreator1155Test is Test {
vm.prank(admin);
uint256 tokenId = target.setupNewToken("test", 1000);

vm.expectRevert(abi.encodeWithSelector(IZoraCreator1155.UserMissingRoleForToken.selector, address(0), tokenId, target.PERMISSION_BIT_MINTER()));
vm.expectRevert(abi.encodeWithSelector(IZoraCreator1155Errors.UserMissingRoleForToken.selector, address(0), tokenId, target.PERMISSION_BIT_MINTER()));
target.mint(SimpleMinter(payable(address(0))), tokenId, 0, "");
}

Expand All @@ -621,7 +626,7 @@ contract ZoraCreator1155Test is Test {

target.addPermission(tokenId, address(simpleMinter), adminRole);

vm.expectRevert(abi.encodeWithSelector(IZoraCreator1155.CannotMintMoreTokens.selector, tokenId, 1001, 0, 1000));
vm.expectRevert(abi.encodeWithSelector(IZoraCreator1155Errors.CannotMintMoreTokens.selector, tokenId, 1001, 0, 1000));
target.mint{value: totalReward}(simpleMinter, tokenId, 1001, abi.encode(recipient));

vm.stopPrank();
Expand Down Expand Up @@ -1071,7 +1076,7 @@ contract ZoraCreator1155Test is Test {
target.callSale(tokenId, simpleMinter, abi.encodeWithSignature("setNum(uint256)", 1));
assertEq(simpleMinter.num(), 1);

vm.expectRevert(abi.encodeWithSelector(IZoraCreator1155.CallFailed.selector, ""));
vm.expectRevert(abi.encodeWithSelector(IZoraCreator1155Errors.CallFailed.selector, ""));
target.callSale(tokenId, simpleMinter, abi.encodeWithSignature("setNum(uint256)", 0));

vm.stopPrank();
Expand All @@ -1093,7 +1098,7 @@ contract ZoraCreator1155Test is Test {
target.callRenderer(tokenId, abi.encodeWithSelector(SimpleRenderer.setup.selector, "callRender successful"));
assertEq(target.uri(tokenId), "callRender successful");

vm.expectRevert(abi.encodeWithSelector(IZoraCreator1155.CallFailed.selector, ""));
vm.expectRevert(abi.encodeWithSelector(IZoraCreator1155Errors.CallFailed.selector, ""));
target.callRenderer(tokenId, abi.encodeWithSelector(SimpleRenderer.setup.selector, ""));

vm.stopPrank();
Expand Down Expand Up @@ -1148,7 +1153,7 @@ contract ZoraCreator1155Test is Test {
uint256 tokenId = target.setupNewToken("", 1);
target.setTokenMetadataRenderer(tokenId, renderer);

vm.expectRevert(abi.encodeWithSelector(IZoraCreator1155.CallFailed.selector, ""));
vm.expectRevert(abi.encodeWithSelector(IZoraCreator1155Errors.CallFailed.selector, ""));
target.callRenderer(tokenId, "0xfoobar");
}

Expand Down Expand Up @@ -1268,7 +1273,7 @@ contract ZoraCreator1155Test is Test {
vm.prank(admin);
target.mint{value: totalValue}(simpleMinter, tokenId, 1000, abi.encode(recipient));

vm.expectRevert(abi.encodeWithSelector(IZoraCreator1155.ETHWithdrawFailed.selector, simpleMinter, 1 ether));
vm.expectRevert(abi.encodeWithSelector(IZoraCreator1155Errors.ETHWithdrawFailed.selector, simpleMinter, 1 ether));
vm.prank(address(simpleMinter));
target.withdraw();
}
Expand Down
2 changes: 1 addition & 1 deletion test/nft/ZoraCreator1155AccessControlGeneralTest.sol
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import "forge-std/Test.sol";
import {ProtocolRewards} from "@zoralabs/protocol-rewards/src/ProtocolRewards.sol";
import {ZoraCreator1155Impl} from "../../src/nft/ZoraCreator1155Impl.sol";
import {Zora1155} from "../../src/proxies/Zora1155.sol";
import {IZoraCreator1155} from "../../src/interfaces/IZoraCreator1155.sol";
import {IZoraCreator1155Errors} from "../../src/interfaces/IZoraCreator1155Errors.sol";
import {IRenderer1155} from "../../src/interfaces/IRenderer1155.sol";
import {IMinter1155} from "../../src/interfaces/IMinter1155.sol";
import {IZoraCreator1155TypesV1} from "../../src/nft/IZoraCreator1155TypesV1.sol";
Expand Down
Loading

0 comments on commit be87f52

Please sign in to comment.