From 9ef7f6db8725b8aee43af395efb1fe23ab9e0a20 Mon Sep 17 00:00:00 2001 From: Dan Oved Date: Wed, 25 Oct 2023 10:05:27 -0600 Subject: [PATCH] Added premitn version fetcher This reverts commit d57f2990d9046c7e9f7d29ec2105902b3bb59830. --- .changeset/thirty-dragons-pretend.md | 5 +++++ .../ZoraCreator1155PremintExecutorImpl.sol | 19 ++++++++++++++++ .../IZoraCreator1155DelegatedCreation.sol | 2 ++ .../IZoraCreator1155PremintExecutor.sol | 2 ++ .../src/nft/ZoraCreator1155Impl.sol | 4 ++++ .../Zora1155PremintExecutorProxy.t.sol | 3 +++ .../ZoraCreator1155PremintExecutor.t.sol | 22 +++++++++++++++++++ 7 files changed, 57 insertions(+) create mode 100644 .changeset/thirty-dragons-pretend.md diff --git a/.changeset/thirty-dragons-pretend.md b/.changeset/thirty-dragons-pretend.md new file mode 100644 index 000000000..058b8f7b8 --- /dev/null +++ b/.changeset/thirty-dragons-pretend.md @@ -0,0 +1,5 @@ +--- +"@zoralabs/zora-1155-contracts": patch +--- + +Added method `IZoraCreator1155PremintExecutor.supportedPremintSignatureVersion(contractAddress)` that tells what version of the premint signature the contract supports, and added corresponding method `ZoraCreator1155Impl.supportedPremintSignatureVersion()` to fetch supported version. If premint not supported, returns 0. \ No newline at end of file diff --git a/packages/1155-contracts/src/delegation/ZoraCreator1155PremintExecutorImpl.sol b/packages/1155-contracts/src/delegation/ZoraCreator1155PremintExecutorImpl.sol index f7dd19b3d..972fdb729 100644 --- a/packages/1155-contracts/src/delegation/ZoraCreator1155PremintExecutorImpl.sol +++ b/packages/1155-contracts/src/delegation/ZoraCreator1155PremintExecutorImpl.sol @@ -15,6 +15,7 @@ import {ERC1155DelegationStorageV1} from "../delegation/ERC1155DelegationStorage import {ZoraCreator1155PremintExecutorImplLib} from "./ZoraCreator1155PremintExecutorImplLib.sol"; import {PremintEncoding, ZoraCreator1155Attribution, ContractCreationConfig, PremintConfig, PremintConfigV2, TokenCreationConfig, TokenCreationConfigV2} from "./ZoraCreator1155Attribution.sol"; import {IZoraCreator1155PremintExecutor} from "../interfaces/IZoraCreator1155PremintExecutor.sol"; +import {IZoraCreator1155DelegatedCreation} from "../interfaces/IZoraCreator1155DelegatedCreation.sol"; struct MintArguments { // which account should receive the tokens minted. @@ -213,6 +214,24 @@ contract ZoraCreator1155PremintExecutorImpl is ); } + /// @notice Returns the version of the premint signature that the contract supports + /// @param contractAddress The address of the contract to check + /// @return The version of the premint signature that the contract supports. If it doesn't support premint + /// returns 0 + function supportedPremintSignatureVersion(address contractAddress) external view returns (string memory) { + IZoraCreator1155 creatorContract = IZoraCreator1155(contractAddress); + if (creatorContract.supportsInterface(type(IZoraCreator1155DelegatedCreation).interfaceId)) { + return IZoraCreator1155DelegatedCreation(contractAddress).supportedPremintSignatureVersion(); + } + + // try get token id for uid 0 - if call fails, we know this didn't support premint + try ERC1155DelegationStorageV1(contractAddress).delegatedTokenId(uint32(0)) returns (uint256) { + return "1"; + } catch { + return "0"; + } + } + // upgrade related functionality /// @notice The name of the contract for upgrade purposes diff --git a/packages/1155-contracts/src/interfaces/IZoraCreator1155DelegatedCreation.sol b/packages/1155-contracts/src/interfaces/IZoraCreator1155DelegatedCreation.sol index 85c49eaba..23c4a0535 100644 --- a/packages/1155-contracts/src/interfaces/IZoraCreator1155DelegatedCreation.sol +++ b/packages/1155-contracts/src/interfaces/IZoraCreator1155DelegatedCreation.sol @@ -4,6 +4,8 @@ pragma solidity 0.8.17; interface IZoraCreator1155DelegatedCreation { event CreatorAttribution(bytes32 structHash, string domainName, string version, address creator, bytes signature); + function supportedPremintSignatureVersion() external pure returns (string memory); + function delegateSetupNewToken( bytes memory premintConfigEncoded, bytes32 premintVersion, diff --git a/packages/1155-contracts/src/interfaces/IZoraCreator1155PremintExecutor.sol b/packages/1155-contracts/src/interfaces/IZoraCreator1155PremintExecutor.sol index fbc449ed0..cdbbc957d 100644 --- a/packages/1155-contracts/src/interfaces/IZoraCreator1155PremintExecutor.sol +++ b/packages/1155-contracts/src/interfaces/IZoraCreator1155PremintExecutor.sol @@ -93,4 +93,6 @@ interface IZoraCreator1155PremintExecutor is function zora1155Factory() external view returns (IZoraCreator1155Factory); function getContractAddress(ContractCreationConfig calldata contractConfig) external view returns (address); + + function supportedPremintSignatureVersion(address contractAddress) external view returns (string memory); } diff --git a/packages/1155-contracts/src/nft/ZoraCreator1155Impl.sol b/packages/1155-contracts/src/nft/ZoraCreator1155Impl.sol index 7ee7c4d3c..0b2619c2f 100644 --- a/packages/1155-contracts/src/nft/ZoraCreator1155Impl.sol +++ b/packages/1155-contracts/src/nft/ZoraCreator1155Impl.sol @@ -752,6 +752,10 @@ contract ZoraCreator1155Impl is return _getImplementation(); } + function supportedPremintSignatureVersion() external pure returns (string memory) { + return ZoraCreator1155Attribution.VERSION_2; + } + /// Sets up a new token using a token configuration and a signature created for the token creation parameters. /// The signature must be created by an account with the PERMISSION_BIT_MINTER role on the contract. /// @param premintConfig abi encoded configuration of token to be created diff --git a/packages/1155-contracts/test/premint/Zora1155PremintExecutorProxy.t.sol b/packages/1155-contracts/test/premint/Zora1155PremintExecutorProxy.t.sol index a9c02889c..bc88efadc 100644 --- a/packages/1155-contracts/test/premint/Zora1155PremintExecutorProxy.t.sol +++ b/packages/1155-contracts/test/premint/Zora1155PremintExecutorProxy.t.sol @@ -170,6 +170,9 @@ contract Zora1155PremintExecutorProxyTest is Test, ForkDeploymentConfig, IHasCon forkedPreminterProxy.upgradeTo(address(newImplementation)); // 3. create premint on old version of contract using new version of preminter + // verify the 1155 supports up to version 1 + assertEq(forkedPreminterProxy.supportedPremintSignatureVersion(deterministicAddress), "1"); + uint32 existingUid = premintConfig.uid; premintConfig = Zora1155PremintFixtures.makeDefaultV1PremintConfig(fixedPriceMinter, creator); premintConfig.uid = existingUid + 1; diff --git a/packages/1155-contracts/test/premint/ZoraCreator1155PremintExecutor.t.sol b/packages/1155-contracts/test/premint/ZoraCreator1155PremintExecutor.t.sol index ba4a5f4e7..02a051b91 100644 --- a/packages/1155-contracts/test/premint/ZoraCreator1155PremintExecutor.t.sol +++ b/packages/1155-contracts/test/premint/ZoraCreator1155PremintExecutor.t.sol @@ -723,6 +723,28 @@ contract ZoraCreator1155PreminterTest is Test { preminter.premintV2{value: mintCost}(contractConfig, premintConfig2, newCreatorSignature, quantityToMint, defaultMintArguments); } + function test_premintVersion_whenCreatedBeforePremint_returnsZero() external { + vm.createSelectFork("zora", 5_789_193); + + // create preminter on fork + vm.startPrank(zora); + (, , factoryProxy, ) = Zora1155FactoryFixtures.setup1155AndFactoryProxy(zora, zora); + vm.stopPrank(); + + factory = ZoraCreator1155FactoryImpl(address(factoryProxy)); + + preminter = new ZoraCreator1155PremintExecutorImpl(factory); + + // this is a known contract deployed from the legacy factory proxy on zora mainnet + // that does not support getting the uid or premint sig version (it is prior to version 2) + address erc1155BeforePremint = 0xcACBbee9C2C703274BE026B62860cF56361410f3; + assertFalse(erc1155BeforePremint.code.length == 0); + + // if contract is not a known 1155 contract that supports getting uid or premint sig version, + // this should return 0 + assertEq(preminter.supportedPremintSignatureVersion(erc1155BeforePremint), "0"); + } + function testPremintWithCreateReferral() public { address createReferral = makeAddr("createReferral");