Skip to content

Commit

Permalink
wip on move premint to creator attribution style
Browse files Browse the repository at this point in the history
  • Loading branch information
oveddan committed Aug 21, 2023
1 parent f01b352 commit 361cc48
Show file tree
Hide file tree
Showing 13 changed files with 669 additions and 677 deletions.
5 changes: 5 additions & 0 deletions .changeset/twelve-comics-sniff.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@zoralabs/zora-1155-contracts": minor
---

Premint with Delegated Minting
2 changes: 1 addition & 1 deletion .env.anvil
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
FORK_RPC_URL="https://testnet.rpc.zora.co/"
FORK_BLOCK_NUMBER=700700
FORK_BLOCK_NUMBER=906028
46 changes: 42 additions & 4 deletions script/DeployPreminter.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -18,20 +18,58 @@ 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) {
Deployment memory deployment = getDeployment();

uint256 deployerPrivateKey = vm.envUint("DEPLOYER_PRIVATE_KEY");

ZoraCreator1155FactoryImpl factory = ZoraCreator1155FactoryImpl(deployment.factoryProxy);
// bool deployFactory = vm.envBool("DEPLOY_FACTORY");
bool deployFactory = vm.envBool("DEPLOY_FACTORY");

IZoraCreator1155Factory factoryProxy;
vm.startBroadcast(deployerPrivateKey);

ZoraCreator1155Preminter preminter = new ZoraCreator1155Preminter();
preminter.initialize(factory);
if (deployFactory) {
address deployer = vm.envAddress("DEPLOYER");
address factoryShimAddress = address(new ProxyShim(deployer));
ChainConfig memory chainConfig = getChainConfig();

factoryProxy = IZoraCreator1155Factory(address(new Zora1155Factory(factoryShimAddress, "")));

deployment.factoryProxy = address(factoryProxy);

ZoraCreator1155Impl creatorImpl = new ZoraCreator1155Impl(
chainConfig.mintFeeAmount,
chainConfig.mintFeeRecipient,
address(factoryProxy),
chainConfig.protocolRewards
);

deployment.contract1155Impl = address(creatorImpl);

ZoraCreator1155FactoryImpl factoryImpl = new ZoraCreator1155FactoryImpl({
_implementation: creatorImpl,
_merkleMinter: IMinter1155(deployment.merkleMintSaleStrategy),
_redeemMinterFactory: IMinter1155(deployment.redeemMinterFactory),
_fixedPriceMinter: IMinter1155(deployment.fixedPriceSaleStrategy)
});

// Upgrade to "real" factory address
ZoraCreator1155FactoryImpl(address(factoryProxy)).upgradeTo(address(factoryImpl));
ZoraCreator1155FactoryImpl(address(factoryProxy)).initialize(chainConfig.factoryOwner);

deployment.factoryImpl = address(factoryImpl);
} else {
factoryProxy = ZoraCreator1155FactoryImpl(deployment.factoryProxy);
}

console.log("!!!factory proxy!!!");
// console.log(factoryProxy);

ZoraCreator1155PremintExecutor preminter = new ZoraCreator1155PremintExecutor(factoryProxy);

vm.stopBroadcast();

Expand Down
90 changes: 0 additions & 90 deletions script/EstimatePreminterGas.s.sol

This file was deleted.

3 changes: 3 additions & 0 deletions src/interfaces/IZoraCreator1155.sol
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +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/ZoraCreator1155Attribution.sol";

/*
Expand Down Expand Up @@ -104,6 +105,8 @@ interface IZoraCreator1155 is IZoraCreator1155TypesV1, IVersionedContract, IOwna
/// @param maxSupply maxSupply for the token, set to 0 for open edition
function setupNewToken(string memory tokenURI, uint256 maxSupply) external returns (uint256 tokenId);

function delegateSetupNewToken(PremintConfig calldata premintConfig, bytes calldata signature) external returns (uint256 newTokenId);

function updateTokenURI(uint256 tokenId, string memory _newURI) external;

function updateContractMetadata(string memory _newURI, string memory _newName) external;
Expand Down
43 changes: 43 additions & 0 deletions src/nft/ZoraCreator1155Impl.sol
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +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, PremintTokenSetup, PremintConfig} from "../premint/ZoraCreator1155Attribution.sol";

/// Imagine. Mint. Enjoy.
/// @title ZoraCreator1155Impl
Expand Down Expand Up @@ -722,4 +723,46 @@ contract ZoraCreator1155Impl is
revert();
}
}

/* start eip712 functionality */
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 nonReentrant returns (uint256 newTokenId) {
bytes32 hashedPremintConfig = ZoraCreator1155Attribution.validateAndHashPremint(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);

// recover the signer from the data
address recoveredSigner = ZoraCreator1155Attribution.recoverSignerHashed(hashedPremintConfig, signature, address(this), block.chainid);

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

// 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);
}
}
106 changes: 0 additions & 106 deletions src/premint/EIP712UpgradeableWithChainId.sol

This file was deleted.

Loading

0 comments on commit 361cc48

Please sign in to comment.