From 73468cb9738d32c04dcf2a126cdc0e2385d8c085 Mon Sep 17 00:00:00 2001 From: Dan Oved Date: Thu, 26 Oct 2023 12:30:08 -0600 Subject: [PATCH 1/4] wip on getting list of versions instead --- .../src/delegation/ZoraCreator1155PremintExecutorImpl.sol | 4 ++-- .../src/interfaces/IZoraCreator1155DelegatedCreation.sol | 2 +- .../src/interfaces/IZoraCreator1155PremintExecutor.sol | 2 +- packages/1155-contracts/src/nft/ZoraCreator1155Impl.sol | 2 +- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/packages/1155-contracts/src/delegation/ZoraCreator1155PremintExecutorImpl.sol b/packages/1155-contracts/src/delegation/ZoraCreator1155PremintExecutorImpl.sol index 972fdb729..f22f2f9e8 100644 --- a/packages/1155-contracts/src/delegation/ZoraCreator1155PremintExecutorImpl.sol +++ b/packages/1155-contracts/src/delegation/ZoraCreator1155PremintExecutorImpl.sol @@ -218,10 +218,10 @@ contract ZoraCreator1155PremintExecutorImpl is /// @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) { + function supportedPremintSignatureVersions(address contractAddress) external view returns (string memory) { IZoraCreator1155 creatorContract = IZoraCreator1155(contractAddress); if (creatorContract.supportsInterface(type(IZoraCreator1155DelegatedCreation).interfaceId)) { - return IZoraCreator1155DelegatedCreation(contractAddress).supportedPremintSignatureVersion(); + return IZoraCreator1155DelegatedCreation(contractAddress).supportedPremintSignatureVersions(); } // try get token id for uid 0 - if call fails, we know this didn't support premint diff --git a/packages/1155-contracts/src/interfaces/IZoraCreator1155DelegatedCreation.sol b/packages/1155-contracts/src/interfaces/IZoraCreator1155DelegatedCreation.sol index 23c4a0535..58cb19f25 100644 --- a/packages/1155-contracts/src/interfaces/IZoraCreator1155DelegatedCreation.sol +++ b/packages/1155-contracts/src/interfaces/IZoraCreator1155DelegatedCreation.sol @@ -4,7 +4,7 @@ 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 supportedPremintSignatureVersions() external pure returns (string memory); function delegateSetupNewToken( bytes memory premintConfigEncoded, diff --git a/packages/1155-contracts/src/interfaces/IZoraCreator1155PremintExecutor.sol b/packages/1155-contracts/src/interfaces/IZoraCreator1155PremintExecutor.sol index cdbbc957d..f1fc56fec 100644 --- a/packages/1155-contracts/src/interfaces/IZoraCreator1155PremintExecutor.sol +++ b/packages/1155-contracts/src/interfaces/IZoraCreator1155PremintExecutor.sol @@ -94,5 +94,5 @@ interface IZoraCreator1155PremintExecutor is function getContractAddress(ContractCreationConfig calldata contractConfig) external view returns (address); - function supportedPremintSignatureVersion(address contractAddress) external view returns (string memory); + function supportedPremintSignatureVersions(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 0b2619c2f..fb9c632f5 100644 --- a/packages/1155-contracts/src/nft/ZoraCreator1155Impl.sol +++ b/packages/1155-contracts/src/nft/ZoraCreator1155Impl.sol @@ -752,7 +752,7 @@ contract ZoraCreator1155Impl is return _getImplementation(); } - function supportedPremintSignatureVersion() external pure returns (string memory) { + function supportedPremintSignatureVersions() external pure returns (string memory) { return ZoraCreator1155Attribution.VERSION_2; } From b1c44c166cd9e043b4b282e077f0dce3f39b9434 Mon Sep 17 00:00:00 2001 From: Dan Oved Date: Mon, 30 Oct 2023 16:49:10 -0600 Subject: [PATCH 2/4] Supported premint signature version returns an array --- .changeset/serious-goats-exist.md | 5 ++++ .../delegation/ZoraCreator1155Attribution.sol | 10 +++++++ .../ZoraCreator1155PremintExecutorImpl.sol | 19 +++++++++---- .../IZoraCreator1155DelegatedCreation.sol | 2 +- .../IZoraCreator1155PremintExecutor.sol | 2 +- .../src/nft/ZoraCreator1155Impl.sol | 4 +-- .../Zora1155PremintExecutorProxy.t.sol | 4 ++- .../ZoraCreator1155PremintExecutor.t.sol | 28 ++++++++++++++++++- 8 files changed, 62 insertions(+), 12 deletions(-) create mode 100644 .changeset/serious-goats-exist.md diff --git a/.changeset/serious-goats-exist.md b/.changeset/serious-goats-exist.md new file mode 100644 index 000000000..59c9550b9 --- /dev/null +++ b/.changeset/serious-goats-exist.md @@ -0,0 +1,5 @@ +--- +"@zoralabs/zora-1155-contracts": patch +--- + +Premint - added method getSupportedPremintSignatureVersions(contractAddress) that returns an array of the premint signature versions an 1155 contract supports. If the contract hasn't been created yet, assumes that when it will be created it will support the latest versions of the signatures, so the function returns all versions. diff --git a/packages/1155-contracts/src/delegation/ZoraCreator1155Attribution.sol b/packages/1155-contracts/src/delegation/ZoraCreator1155Attribution.sol index 94c49eee1..d45d98c3f 100644 --- a/packages/1155-contracts/src/delegation/ZoraCreator1155Attribution.sol +++ b/packages/1155-contracts/src/delegation/ZoraCreator1155Attribution.sol @@ -95,6 +95,12 @@ library ZoraCreator1155Attribution { string internal constant VERSION_2 = "2"; bytes32 internal constant HASHED_VERSION_2 = keccak256(bytes(VERSION_2)); + function allVersions() internal pure returns (string[] memory versions) { + versions = new string[](2); + versions[0] = VERSION_1; + versions[1] = VERSION_2; + } + /** * @dev Returns the domain separator for the specified chain. */ @@ -416,6 +422,10 @@ library DelegatedTokenCreation { revert IZoraCreator1155Errors.InvalidSignatureVersion(); } + function supportedPremintSignatureVersions() external pure returns (string[] memory versions) { + return ZoraCreator1155Attribution.allVersions(); + } + function _recoverCreatorAttribution( string memory version, bytes32 structHash, diff --git a/packages/1155-contracts/src/delegation/ZoraCreator1155PremintExecutorImpl.sol b/packages/1155-contracts/src/delegation/ZoraCreator1155PremintExecutorImpl.sol index f22f2f9e8..f18c2769d 100644 --- a/packages/1155-contracts/src/delegation/ZoraCreator1155PremintExecutorImpl.sol +++ b/packages/1155-contracts/src/delegation/ZoraCreator1155PremintExecutorImpl.sol @@ -214,11 +214,17 @@ contract ZoraCreator1155PremintExecutorImpl is ); } - /// @notice Returns the version of the premint signature that the contract supports + /// @notice Returns the versions 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 supportedPremintSignatureVersions(address contractAddress) external view returns (string memory) { + /// @return versions The versions of the premint signature that the contract supports. If contract hasn't been created yet, + /// assumes that when it will be created it will support the latest versions of the signatures, so the function returns all versions. + function supportedPremintSignatureVersions(address contractAddress) external view returns (string[] memory versions) { + // if contract hasn't been created yet, assume it will be created with the latest version + // and thus supports all versions of the signature + if (contractAddress.code.length == 0) { + return ZoraCreator1155Attribution.allVersions(); + } + IZoraCreator1155 creatorContract = IZoraCreator1155(contractAddress); if (creatorContract.supportsInterface(type(IZoraCreator1155DelegatedCreation).interfaceId)) { return IZoraCreator1155DelegatedCreation(contractAddress).supportedPremintSignatureVersions(); @@ -226,9 +232,10 @@ contract ZoraCreator1155PremintExecutorImpl is // 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"; + versions = new string[](1); + versions[0] = ZoraCreator1155Attribution.VERSION_1; } catch { - return "0"; + versions = new string[](0); } } diff --git a/packages/1155-contracts/src/interfaces/IZoraCreator1155DelegatedCreation.sol b/packages/1155-contracts/src/interfaces/IZoraCreator1155DelegatedCreation.sol index 58cb19f25..f33602a39 100644 --- a/packages/1155-contracts/src/interfaces/IZoraCreator1155DelegatedCreation.sol +++ b/packages/1155-contracts/src/interfaces/IZoraCreator1155DelegatedCreation.sol @@ -4,7 +4,7 @@ pragma solidity 0.8.17; interface IZoraCreator1155DelegatedCreation { event CreatorAttribution(bytes32 structHash, string domainName, string version, address creator, bytes signature); - function supportedPremintSignatureVersions() external pure returns (string memory); + function supportedPremintSignatureVersions() external pure returns (string[] memory); function delegateSetupNewToken( bytes memory premintConfigEncoded, diff --git a/packages/1155-contracts/src/interfaces/IZoraCreator1155PremintExecutor.sol b/packages/1155-contracts/src/interfaces/IZoraCreator1155PremintExecutor.sol index f1fc56fec..8c4c92ef8 100644 --- a/packages/1155-contracts/src/interfaces/IZoraCreator1155PremintExecutor.sol +++ b/packages/1155-contracts/src/interfaces/IZoraCreator1155PremintExecutor.sol @@ -94,5 +94,5 @@ interface IZoraCreator1155PremintExecutor is function getContractAddress(ContractCreationConfig calldata contractConfig) external view returns (address); - function supportedPremintSignatureVersions(address contractAddress) external view returns (string memory); + function supportedPremintSignatureVersions(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 fb9c632f5..a1a4c4cc9 100644 --- a/packages/1155-contracts/src/nft/ZoraCreator1155Impl.sol +++ b/packages/1155-contracts/src/nft/ZoraCreator1155Impl.sol @@ -752,8 +752,8 @@ contract ZoraCreator1155Impl is return _getImplementation(); } - function supportedPremintSignatureVersions() external pure returns (string memory) { - return ZoraCreator1155Attribution.VERSION_2; + function supportedPremintSignatureVersions() external pure returns (string[] memory) { + return DelegatedTokenCreation.supportedPremintSignatureVersions(); } /// Sets up a new token using a token configuration and a signature created for the token creation parameters. diff --git a/packages/1155-contracts/test/premint/Zora1155PremintExecutorProxy.t.sol b/packages/1155-contracts/test/premint/Zora1155PremintExecutorProxy.t.sol index bc88efadc..0f868795a 100644 --- a/packages/1155-contracts/test/premint/Zora1155PremintExecutorProxy.t.sol +++ b/packages/1155-contracts/test/premint/Zora1155PremintExecutorProxy.t.sol @@ -171,7 +171,9 @@ contract Zora1155PremintExecutorProxyTest is Test, ForkDeploymentConfig, IHasCon // 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"); + string[] memory supportedVersions = forkedPreminterProxy.supportedPremintSignatureVersions(deterministicAddress); + assertEq(supportedVersions.length, 1); + assertEq(supportedVersions[0], "1"); uint32 existingUid = premintConfig.uid; premintConfig = Zora1155PremintFixtures.makeDefaultV1PremintConfig(fixedPriceMinter, creator); diff --git a/packages/1155-contracts/test/premint/ZoraCreator1155PremintExecutor.t.sol b/packages/1155-contracts/test/premint/ZoraCreator1155PremintExecutor.t.sol index 02a051b91..7c8019e7c 100644 --- a/packages/1155-contracts/test/premint/ZoraCreator1155PremintExecutor.t.sol +++ b/packages/1155-contracts/test/premint/ZoraCreator1155PremintExecutor.t.sol @@ -742,7 +742,33 @@ contract ZoraCreator1155PreminterTest is Test { // 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"); + assertEq(preminter.supportedPremintSignatureVersions(erc1155BeforePremint).length, 0); + } + + function test_premintVersion_beforeCreated_returnsAllVersion() external { + // build a premint + string[] memory supportedVersions = preminter.supportedPremintSignatureVersions(makeAddr("randomContract")); + + assertEq(supportedVersions.length, 2); + assertEq(supportedVersions[0], "1"); + assertEq(supportedVersions[1], "2"); + } + + function test_premintVersion_whenCreated_returnsAllVersion() external { + // build a premint + ContractCreationConfig memory contractConfig = makeDefaultContractCreationConfig(); + PremintConfigV2 memory premintConfig = makeDefaultPremintConfig(); + + // sign and execute premint + address deterministicAddress = preminter.getContractAddress(contractConfig); + + _signAndExecutePremint(contractConfig, premintConfig, creatorPrivateKey, block.chainid, premintExecutor, 1, "hi"); + + string[] memory supportedVersions = preminter.supportedPremintSignatureVersions(deterministicAddress); + + assertEq(supportedVersions.length, 2); + assertEq(supportedVersions[0], "1"); + assertEq(supportedVersions[1], "2"); } function testPremintWithCreateReferral() public { From b22d42226c508bedc877891132ef5985493e0541 Mon Sep 17 00:00:00 2001 From: Dan Oved Date: Fri, 3 Nov 2023 15:42:04 -0600 Subject: [PATCH 3/4] moved to delegated token creation lib --- .../src/delegation/ZoraCreator1155Attribution.sol | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/packages/1155-contracts/src/delegation/ZoraCreator1155Attribution.sol b/packages/1155-contracts/src/delegation/ZoraCreator1155Attribution.sol index d45d98c3f..0b2dff200 100644 --- a/packages/1155-contracts/src/delegation/ZoraCreator1155Attribution.sol +++ b/packages/1155-contracts/src/delegation/ZoraCreator1155Attribution.sol @@ -95,12 +95,6 @@ library ZoraCreator1155Attribution { string internal constant VERSION_2 = "2"; bytes32 internal constant HASHED_VERSION_2 = keccak256(bytes(VERSION_2)); - function allVersions() internal pure returns (string[] memory versions) { - versions = new string[](2); - versions[0] = VERSION_1; - versions[1] = VERSION_2; - } - /** * @dev Returns the domain separator for the specified chain. */ @@ -423,7 +417,9 @@ library DelegatedTokenCreation { } function supportedPremintSignatureVersions() external pure returns (string[] memory versions) { - return ZoraCreator1155Attribution.allVersions(); + versions = new string[](2); + versions[0] = ZoraCreator1155Attribution.VERSION_1; + versions[1] = ZoraCreator1155Attribution.VERSION_2; } function _recoverCreatorAttribution( From 7320243159ef1709daea167c36f589496f4e6181 Mon Sep 17 00:00:00 2001 From: Dan Oved Date: Fri, 3 Nov 2023 16:00:28 -0600 Subject: [PATCH 4/4] updated changeset --- .changeset/thirty-dragons-pretend.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.changeset/thirty-dragons-pretend.md b/.changeset/thirty-dragons-pretend.md index 058b8f7b8..38b73d97b 100644 --- a/.changeset/thirty-dragons-pretend.md +++ b/.changeset/thirty-dragons-pretend.md @@ -2,4 +2,4 @@ "@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 +Added method `IZoraCreator1155PremintExecutor.supportedPremintSignatureVersions(contractAddress)` that tells what version of the premint signature the contract supports, and added corresponding method `ZoraCreator1155Impl.supportedPremintSignatureVersions()` to fetch supported version. If premint not supported, returns an empty array. \ No newline at end of file