Skip to content

Commit

Permalink
Supported premint signature version returns an array
Browse files Browse the repository at this point in the history
  • Loading branch information
oveddan committed Oct 31, 2023
1 parent 8947227 commit 8e74a7e
Show file tree
Hide file tree
Showing 8 changed files with 62 additions and 12 deletions.
5 changes: 5 additions & 0 deletions .changeset/serious-goats-exist.md
Original file line number Diff line number Diff line change
@@ -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.
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*/
Expand Down Expand Up @@ -416,6 +422,10 @@ library DelegatedTokenCreation {
}
}

function supportedPremintSignatureVersions() external pure returns (string[] memory versions) {
return ZoraCreator1155Attribution.allVersions();
}

function _recoverCreatorAttribution(
string memory version,
bytes32 structHash,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -214,21 +214,28 @@ 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();
}

// 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);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
4 changes: 2 additions & 2 deletions packages/1155-contracts/src/nft/ZoraCreator1155Impl.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -780,7 +780,33 @@ contract ZoraCreator1155PreminterTest is ForkDeploymentConfig, 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 {
Expand Down

0 comments on commit 8e74a7e

Please sign in to comment.