Skip to content

Commit

Permalink
Some refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
oveddan committed Aug 11, 2023
1 parent 7362571 commit dc82896
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 36 deletions.
4 changes: 2 additions & 2 deletions script/DeployPreminter.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import {ProxyShim} from "../src/utils/ProxyShim.sol";
import {ZoraCreatorFixedPriceSaleStrategy} from "../src/minters/fixed-price/ZoraCreatorFixedPriceSaleStrategy.sol";
import {ZoraCreatorMerkleMinterStrategy} from "../src/minters/merkle/ZoraCreatorMerkleMinterStrategy.sol";
import {ZoraCreatorRedeemMinterFactory} from "../src/minters/redeem/ZoraCreatorRedeemMinterFactory.sol";
import {ZoraCreator1155Preminter} from "../src/premint/ZoraCreator1155Preminter.sol";
import {ZoraCreator1155PremintExecutor} from "../src/premint/ZoraCreator1155PremintExecutor.sol";

contract DeployPreminter is ZoraDeployerBase {
function run() public returns (string memory) {
Expand All @@ -30,7 +30,7 @@ contract DeployPreminter is ZoraDeployerBase {

vm.startBroadcast(deployerPrivateKey);

ZoraCreator1155Preminter preminter = new ZoraCreator1155Preminter();
ZoraCreator1155PremintExecutor preminter = new ZoraCreator1155PremintExecutor();
preminter.initialize(factory);

vm.stopBroadcast();
Expand Down
2 changes: 1 addition & 1 deletion src/interfaces/IZoraCreator1155.sol
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {IMinter1155} from "../interfaces/IMinter1155.sol";
import {IOwnable} from "../interfaces/IOwnable.sol";
import {IVersionedContract} from "./IVersionedContract.sol";
import {ICreatorRoyaltiesControl} from "../interfaces/ICreatorRoyaltiesControl.sol";
import {PremintConfig} from "../premint/ZoraCreator1155Delegation.sol";
import {PremintConfig} from "../premint/ZoraCreator1155Attribution.sol";

/*
Expand Down
35 changes: 9 additions & 26 deletions src/nft/ZoraCreator1155Impl.sol
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ import {PublicMulticall} from "../utils/PublicMulticall.sol";
import {SharedBaseConstants} from "../shared/SharedBaseConstants.sol";
import {TransferHelperUtils} from "../utils/TransferHelperUtils.sol";
import {ZoraCreator1155StorageV1} from "./ZoraCreator1155StorageV1.sol";
import {ZoraCreator1155Attribution, TokenSetup, PremintConfig} from "../premint/ZoraCreator1155Delegation.sol";
import {ZoraCreator1155Attribution, PremintTokenSetup, PremintConfig} from "../premint/ZoraCreator1155Attribution.sol";

/// Imagine. Mint. Enjoy.
/// @title ZoraCreator1155Impl
Expand Down Expand Up @@ -731,18 +731,12 @@ contract ZoraCreator1155Impl is

mapping(uint32 => bool) public uidUsed;

// todo: move to its own contract
error PremintAlreadyExecuted();
error MintNotYetStarted();
error PremintDeleted();

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

error PremintAlreadyExecuted();

function delegateSetupNewToken(PremintConfig calldata premintConfig, bytes calldata signature) public returns (uint256 newTokenId) {
if (premintConfig.tokenConfig.mintStart != 0 && premintConfig.tokenConfig.mintStart > block.timestamp) {
// if the mint start is in the future, then revert
revert MintNotYetStarted();
}
bytes32 hashedPremintConfig = ZoraCreator1155Attribution.validateAndHashPremint(premintConfig);

// check that uid hasn't been used
if (uidUsed[premintConfig.uid]) {
Expand All @@ -751,14 +745,6 @@ contract ZoraCreator1155Impl is
uidUsed[premintConfig.uid] = true;
}

if (premintConfig.deleted) {
// if the signature says to be deleted, then dont execute any further minting logic;
// return 0
revert PremintDeleted();
}

bytes32 hashedPremintConfig = ZoraCreator1155Attribution.hashPremint(premintConfig);

// 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 @@ -768,21 +754,18 @@ contract ZoraCreator1155Impl is
// require that the signer can create new tokens (is a valid creator)
_requireAdminOrRole(recoveredSigner, CONTRACT_BASE_ID, PERMISSION_BIT_MINTER);

// temporarily grant msg sender admin permission to create new tokens
_addPermission(CONTRACT_BASE_ID, msg.sender, PERMISSION_BIT_MINTER);

// get the new token id - it will fail if the recovered signer does not have PERMISSION_BIT_MINTER permission
newTokenId = setupNewToken(premintConfig.tokenConfig.tokenURI, premintConfig.tokenConfig.maxSupply);
// msg.sender should now have admin role on that token (lets make sure to remove it at the end of this call!!!)
// 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);

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

// then invoke them, calling account should be original msg.sender
// then invoke them, calling account should be original msg.sender, which has admin on the new token
_multicallInternal(tokenSetupActions);

// remove the token creator as admin of the newly created token:
_removePermission(newTokenId, msg.sender, PERMISSION_BIT_ADMIN);

// grant the token creator as admin of the newly created token
_addPermission(newTokenId, recoveredSigner, PERMISSION_BIT_ADMIN);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -173,9 +173,27 @@ library ZoraCreator1155Attribution {
function _stringHash(string calldata value) private pure returns (bytes32) {
return keccak256(bytes(value));
}

// todo: move to its own contract
error MintNotYetStarted();
error PremintDeleted();

function validateAndHashPremint(PremintConfig calldata premintConfig) external view returns (bytes32) {
if (premintConfig.tokenConfig.mintStart != 0 && premintConfig.tokenConfig.mintStart > block.timestamp) {
// if the mint start is in the future, then revert
revert MintNotYetStarted();
}
if (premintConfig.deleted) {
// if the signature says to be deleted, then dont execute any further minting logic;
// return 0
revert PremintDeleted();
}

return hashPremint(premintConfig);
}
}

library TokenSetup {
library PremintTokenSetup {
uint256 constant PERMISSION_BIT_MINTER = 2 ** 2;

function makeSetupNewTokenCalls(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@ 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 "./ZoraCreator1155Delegation.sol";
import {PremintConfig, ContractCreationConfig, TokenCreationConfig} 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
/// by executing the transaction. Incentivizes the third party to execute the transaction by offering
/// a reward in the form of minted tokens.
/// @author @oveddan
contract ZoraCreator1155Preminter {
contract ZoraCreator1155PremintExecutor {
IZoraCreator1155Factory factory;

/// @notice copied from SharedBaseConstants
Expand Down
8 changes: 4 additions & 4 deletions test/premint/ZoraCreator1155Preminter.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@ import {ILimitedMintPerAddress} from "../../src/interfaces/ILimitedMintPerAddres
import {ZoraCreatorFixedPriceSaleStrategy} from "../../src/minters/fixed-price/ZoraCreatorFixedPriceSaleStrategy.sol";
import {Zora1155Factory} from "../../src/proxies/Zora1155Factory.sol";
import {ZoraCreator1155FactoryImpl} from "../../src/factory/ZoraCreator1155FactoryImpl.sol";
import {ZoraCreator1155Preminter} from "../../src/premint/ZoraCreator1155Preminter.sol";
import {ZoraCreator1155PremintExecutor} from "../../src/premint/ZoraCreator1155PremintExecutor.sol";
import {IZoraCreator1155} from "../../src/interfaces/IZoraCreator1155.sol";
import {ZoraCreator1155Attribution, ContractCreationConfig, TokenCreationConfig, PremintConfig} from "../../src/premint/ZoraCreator1155Delegation.sol";
import {ZoraCreator1155Attribution, ContractCreationConfig, TokenCreationConfig, PremintConfig} from "../../src/premint/ZoraCreator1155Attribution.sol";

contract ZoraCreator1155PreminterTest is Test {
ZoraCreator1155Preminter internal preminter;
ZoraCreator1155PremintExecutor internal preminter;
ZoraCreator1155FactoryImpl internal factory;
// setup contract config
uint256 creatorPrivateKey = 0xA11CE;
Expand Down Expand Up @@ -55,7 +55,7 @@ contract ZoraCreator1155PreminterTest is Test {
royaltyMintSchedule: royaltyMintSchedule
});

preminter = new ZoraCreator1155Preminter();
preminter = new ZoraCreator1155PremintExecutor();
preminter.initialize(factory);

creatorPrivateKey = 0xA11CE;
Expand Down

0 comments on commit dc82896

Please sign in to comment.