Skip to content

Commit

Permalink
Expose a get token id method from the contract.
Browse files Browse the repository at this point in the history
Secure with non-reentrant
  • Loading branch information
oveddan committed Aug 16, 2023
1 parent 82e95b0 commit 364af09
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 10 deletions.
18 changes: 9 additions & 9 deletions src/nft/ZoraCreator1155Impl.sol
Original file line number Diff line number Diff line change
Expand Up @@ -729,22 +729,15 @@ contract ZoraCreator1155Impl is
bytes32 private constant _HASHED_VERSION = keccak256(bytes("1"));
bytes32 private constant _TYPE_HASH = keccak256("EIP712Domain(string name,string version,uint256 chainId,address verifyingContract)");

mapping(uint32 => bool) public uidUsed;
mapping(uint32 => uint256) public delegatedTokenId;

event CreatorAttribution(bytes32 structHash, bytes32 domainName, bytes32 version, bytes signature);

error PremintAlreadyExecuted();

function delegateSetupNewToken(PremintConfig calldata premintConfig, bytes calldata signature) public returns (uint256 newTokenId) {
function delegateSetupNewToken(PremintConfig calldata premintConfig, bytes calldata signature) public nonReentrant returns (uint256 newTokenId) {
bytes32 hashedPremintConfig = ZoraCreator1155Attribution.validateAndHashPremint(premintConfig);

// check that uid hasn't been used
if (uidUsed[premintConfig.uid]) {
revert PremintAlreadyExecuted();
} else {
uidUsed[premintConfig.uid] = true;
}

// this is what attributes this token to have been created by the original creator
emit CreatorAttribution(hashedPremintConfig, ZoraCreator1155Attribution.HASHED_NAME, ZoraCreator1155Attribution.HASHED_VERSION, signature);

Expand All @@ -754,9 +747,16 @@ contract ZoraCreator1155Impl is
// require that the signer can create new tokens (is a valid creator)
_requireAdminOrRole(recoveredSigner, CONTRACT_BASE_ID, PERMISSION_BIT_MINTER);

// check that uid hasn't been used
if (delegatedTokenId[premintConfig.uid] != 0) {
revert PremintAlreadyExecuted();
}

// create the new token; msg sender will have PERMISSION_BIT_ADMIN on the new token
newTokenId = _setupNewTokenAndPermission(premintConfig.tokenConfig.tokenURI, premintConfig.tokenConfig.maxSupply, msg.sender, PERMISSION_BIT_ADMIN);

delegatedTokenId[premintConfig.uid] = newTokenId;

// invoke setup actions for new token, to save contract size, first get them from an external lib
bytes[] memory tokenSetupActions = PremintTokenSetup.makeSetupNewTokenCalls(newTokenId, recoveredSigner, premintConfig.tokenConfig);

Expand Down
11 changes: 10 additions & 1 deletion src/premint/ZoraCreator1155PremintExecutor.sol
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {IZoraCreator1155Factory} from "../interfaces/IZoraCreator1155Factory.sol
import {SharedBaseConstants} from "../shared/SharedBaseConstants.sol";
import {ZoraCreatorFixedPriceSaleStrategy} from "../minters/fixed-price/ZoraCreatorFixedPriceSaleStrategy.sol";
import {IMinter1155} from "../interfaces/IMinter1155.sol";
import {PremintConfig, ContractCreationConfig, TokenCreationConfig} from "./ZoraCreator1155Attribution.sol";
import {PremintConfig, ContractCreationConfig, TokenCreationConfig, ZoraCreator1155Attribution} from "./ZoraCreator1155Attribution.sol";

/// @title Enables a creator to signal intent to create a Zora erc1155 contract or new token on that
/// contract by signing a transaction but not paying gas, and have a third party/collector pay the gas
Expand Down Expand Up @@ -122,4 +122,13 @@ contract ZoraCreator1155PremintExecutor {
function getContractAddress(ContractCreationConfig calldata contractConfig) public view returns (address) {
return factory.deterministicContractAddress(address(this), contractConfig.contractURI, contractConfig.contractName, contractConfig.contractAdmin);
}

function recoverSigner(
PremintConfig calldata premintConfig,
address zor1155Address,
bytes calldata signature,
uint256 chainId
) public pure returns (address) {
return ZoraCreator1155Attribution.recoverSigner(premintConfig, signature, zor1155Address, chainId);
}
}

0 comments on commit 364af09

Please sign in to comment.