From 4deabf56e8fe4ee08fd1d395097ca083df06f5b2 Mon Sep 17 00:00:00 2001 From: Dan Oved Date: Thu, 17 Aug 2023 14:14:53 -0700 Subject: [PATCH] undo changes to js sdk --- package/preminter.test.ts | 167 +++++++++++++++----------------------- package/preminter.ts | 17 ++-- 2 files changed, 75 insertions(+), 109 deletions(-) diff --git a/package/preminter.test.ts b/package/preminter.test.ts index 4251ae839..e7d765c73 100644 --- a/package/preminter.test.ts +++ b/package/preminter.test.ts @@ -4,17 +4,14 @@ import { createWalletClient, createPublicClient, } from "viem"; -import { foundry, zoraTestnet } from "viem/chains"; +import { foundry } from "viem/chains"; import { describe, it, beforeEach, expect } from "vitest"; import { parseEther } from "viem"; import { - zoraCreator1155PremintExecutorABI as preminterAbi, + zoraCreator1155PreminterABI as preminterAbi, zoraCreator1155ImplABI, - zoraCreator1155PremintExecutorAddress, - zoraCreator1155FactoryImplAddress, } from "./wagmiGenerated"; -import ZoraCreator1155Attribution from "../out/ZoraCreator1155Attribution.sol/ZoraCreator1155Attribution.json"; -import zoraCreator1155PremintExecutor from "../out/ZoraCreator1155PremintExecutor.sol/ZoraCreator1155PremintExecutor.json"; +import preminter from "../out/ZoraCreator1155Preminter.sol/ZoraCreator1155Preminter.json"; import zoraCreator1155Impl from "../out/ZoraCreator1155Impl.sol/ZoraCreator1155Impl.json"; import zoraCreator1155FactoryImpl from "../out/ZoraCreator1155FactoryImpl.sol/ZoraCreator1155FactoryImpl.json"; import zoraCreatorFixedPriceSaleStrategy from "../out/ZoraCreatorFixedPriceSaleStrategy.sol/ZoraCreatorFixedPriceSaleStrategy.json"; @@ -61,10 +58,8 @@ const [ type TestContext = { preminterAddress: `0x${string}`; - forkedChainId: keyof typeof zoraCreator1155FactoryImplAddress; anvilChainId: number; zoraMintFee: bigint; - fixedPriceMinterAddress: Address; }; const deployContractAndGetAddress = async ( @@ -79,7 +74,6 @@ const deployContractAndGetAddress = async ( }; export const deployFactoryProxy = async () => { - console.log("deploying protocol rewards"); const protocolRewardsAddress = await deployContractAndGetAddress({ abi: protocolRewards.abi, bytecode: protocolRewards.bytecode.object as `0x${string}`, @@ -87,16 +81,13 @@ export const deployFactoryProxy = async () => { args: [], }); - console.log("deploying attribution lib"); - const attributionAddress = await deployContractAndGetAddress({ - abi: ZoraCreator1155Attribution.abi, - bytecode: ZoraCreator1155Attribution.bytecode.object as `0x${string}`, - account: deployerAccount, - }); - - console.log("attribution address is ", attributionAddress); + // const mockUpgradeGateAddress = await deployContractAndGetAddress({ + // abi: mockUpgradeGate.abi, + // bytecode: mockUpgradeGate.bytecode.object as `0x${string}`, + // account: deployerAccount, + // args: [] + // }); - console.log("deploying 1155"); const zora1155Address = await deployContractAndGetAddress({ abi: zoraCreator1155Impl.abi, bytecode: zoraCreator1155Impl.bytecode.object as `0x${string}`, @@ -104,7 +95,6 @@ export const deployFactoryProxy = async () => { args: [0n, mintFeeRecipientAccount, zeroAddress, protocolRewardsAddress], }); - console.log("deploying fixed priced minter"); const fixedPriceMinterAddress = await deployContractAndGetAddress({ abi: zoraCreatorFixedPriceSaleStrategy.abi, bytecode: zoraCreatorFixedPriceSaleStrategy.bytecode @@ -112,7 +102,6 @@ export const deployFactoryProxy = async () => { account: deployerAccount, }); - console.log("deploying factory impl"); const factoryImplAddress = await deployContractAndGetAddress({ abi: zoraCreator1155FactoryImpl.abi, bytecode: zoraCreator1155FactoryImpl.bytecode.object as `0x${string}`, @@ -122,17 +111,16 @@ export const deployFactoryProxy = async () => { const factoryProxyAddress = factoryImplAddress!; - return { factoryProxyAddress, zora1155Address, fixedPriceMinterAddress }; + return { factoryProxyAddress, zora1155Address: zora1155Address! }; }; export const deployPreminterContract = async () => { - const factoryProxyAddress = (await deployFactoryProxy()).factoryProxyAddress; + const { factoryProxyAddress, zora1155Address } = await deployFactoryProxy(); const deployPreminterHash = await walletClient.deployContract({ - abi: zoraCreator1155PremintExecutor.abi, - bytecode: zoraCreator1155PremintExecutor.bytecode.object as `0x${string}`, + abi: preminter.abi, + bytecode: preminter.bytecode.object as `0x${string}`, account: deployerAccount, - args: [factoryProxyAddress], }); const receipt = await publicClient.waitForTransactionReceipt({ @@ -141,7 +129,17 @@ export const deployPreminterContract = async () => { const preminterAddress = receipt.contractAddress!; - return { preminterAddress, factoryProxyAddress }; + const initializeHash = await walletClient.writeContract({ + abi: preminterAbi, + address: preminterAddress, + functionName: "initialize", + account: deployerAccount, + args: [factoryProxyAddress], + }); + + await publicClient.waitForTransactionReceipt({ hash: initializeHash }); + + return { preminterAddress, factoryProxyAddress, zora1155Address }; }; // create token and contract creation config: @@ -151,9 +149,7 @@ const defaultContractConfig = (): ContractCreationConfig => ({ contractName: "My fun NFT", }); -const defaultTokenConfig = ( - fixedPriceMinterAddress: Address -): TokenCreationConfig => ({ +const defaultTokenConfig = (): TokenCreationConfig => ({ tokenURI: "ipfs://tokenIpfsId0", maxSupply: 100n, maxTokensPerAddress: 10n, @@ -163,17 +159,17 @@ const defaultTokenConfig = ( royaltyMintSchedule: 30, royaltyBPS: 200, royaltyRecipient: creatorAccount, - fixedPriceMinter: fixedPriceMinterAddress, }); -const defaultPremintConfig = (fixedPriceMinter: Address): PremintConfig => ({ - tokenConfig: defaultTokenConfig(fixedPriceMinter), +const defaultPremintConfig = (): PremintConfig => ({ + contractConfig: defaultContractConfig(), + tokenConfig: defaultTokenConfig(), deleted: false, uid: 105, version: 0, }); -const useForkContract = true; +// const useForkContract = true; describe("ZoraCreator1155Preminter", () => { beforeEach(async (ctx) => { @@ -183,40 +179,34 @@ describe("ZoraCreator1155Preminter", () => { value: parseEther("10"), }); - ctx.forkedChainId = zoraTestnet.id; + // ctx.forkedChainId = zoraTestnet.id; ctx.anvilChainId = foundry.id; let preminterAddress: Address; + let zora1155Address: Address; + + const deployed = await deployPreminterContract(); - if (useForkContract) { - preminterAddress = - zoraCreator1155PremintExecutorAddress[ctx.forkedChainId]; - } else { - const deployed = await deployPreminterContract(); - preminterAddress = deployed.preminterAddress; - } + preminterAddress = deployed.preminterAddress; + zora1155Address = deployed.zora1155Address; - ctx.zoraMintFee = parseEther("0.000777"); + ctx.zoraMintFee = await publicClient.readContract({ + abi: zoraCreator1155ImplABI, + address: zora1155Address, + functionName: "mintFee", + }); ctx.preminterAddress = preminterAddress; }, 20 * 1000); it( "can sign for another chain", - async ({ preminterAddress: preminterAddress, fixedPriceMinterAddress }) => { - const premintConfig = defaultPremintConfig(fixedPriceMinterAddress); - const contractConfig = defaultContractConfig(); - - const contractAddress = await publicClient.readContract({ - abi: preminterAbi, - address: preminterAddress, - functionName: "getContractAddress", - args: [contractConfig], - }); + async ({ preminterAddress: preminterAddress }) => { + const premintConfig = defaultPremintConfig(); const signedMessage = await walletClient.signTypedData({ ...preminterTypedDataDefinition({ - verifyingContract: contractAddress, + verifyingContract: preminterAddress, chainId: 999, premintConfig, }), @@ -239,25 +229,17 @@ describe("ZoraCreator1155Preminter", () => { ); it( "can sign and recover a signature", - async ({ - preminterAddress: preminterAddress, - anvilChainId, - fixedPriceMinterAddress, - }) => { - const premintConfig = defaultPremintConfig(fixedPriceMinterAddress); - const contractConfig = defaultContractConfig(); + async ({ preminterAddress: preminterAddress, anvilChainId }) => { + const premintConfig = defaultPremintConfig(); - const contractAddress = await publicClient.readContract({ - abi: preminterAbi, - address: preminterAddress, - functionName: "getContractAddress", - args: [contractConfig], + console.log({ + defaultMind: defaultPremintConfig(), }); // sign message containing contract and token creation config and uid const signedMessage = await walletClient.signTypedData({ ...preminterTypedDataDefinition({ - verifyingContract: contractAddress, + verifyingContract: preminterAddress, // we need to sign here for the anvil chain, cause thats where it is run on chainId: anvilChainId, premintConfig, @@ -270,12 +252,7 @@ describe("ZoraCreator1155Preminter", () => { abi: preminterAbi, address: preminterAddress, functionName: "recoverSigner", - args: [ - premintConfig, - contractAddress, - signedMessage, - BigInt(anvilChainId), - ], + args: [premintConfig, signedMessage], }); expect(recoveredAddress).to.equal(creatorAccount); @@ -290,11 +267,9 @@ describe("ZoraCreator1155Preminter", () => { zoraMintFee, anvilChainId, preminterAddress: preminterAddress, - fixedPriceMinterAddress, }) => { // setup contract and token creation parameters - const premintConfig = defaultPremintConfig(fixedPriceMinterAddress); - const contractConfig = defaultContractConfig(); + const premintConfig = defaultPremintConfig(); // lets make it a random number to not break the existing tests that expect fresh data premintConfig.uid = Math.round(Math.random() * 1000000); @@ -303,7 +278,7 @@ describe("ZoraCreator1155Preminter", () => { abi: preminterAbi, address: preminterAddress, functionName: "getContractAddress", - args: [contractConfig], + args: [premintConfig.contractConfig], }); // have creator sign the message to create the contract @@ -333,10 +308,10 @@ describe("ZoraCreator1155Preminter", () => { // get the premint status - it should not be minted let tokenId = await publicClient.readContract({ - abi: zoraCreator1155ImplABI, - address: contractAddress, - functionName: "delegatedTokenId", - args: [premintConfig.uid], + abi: preminterAbi, + address: preminterAddress, + functionName: "getPremintedTokenId", + args: [premintConfig.contractConfig, premintConfig.uid], }); expect(tokenId).toBe(0n); @@ -352,13 +327,7 @@ describe("ZoraCreator1155Preminter", () => { functionName: "premint", account: collectorAccount, address: preminterAddress, - args: [ - contractConfig, - premintConfig, - signedMessage, - quantityToMint, - comment, - ], + args: [premintConfig, signedMessage, quantityToMint, comment], value: valueToSend, }); @@ -371,10 +340,10 @@ describe("ZoraCreator1155Preminter", () => { // fetch the premint token id let newTokenId = await publicClient.readContract({ - abi: zoraCreator1155ImplABI, - address: contractAddress, - functionName: "delegatedTokenId", - args: [premintConfig.uid], + abi: preminterAbi, + address: preminterAddress, + functionName: "getPremintedTokenId", + args: [premintConfig.contractConfig, premintConfig.uid], }); expect(newTokenId).not.toBe(0n); @@ -423,13 +392,7 @@ describe("ZoraCreator1155Preminter", () => { functionName: "premint", account: collectorAccount, address: preminterAddress, - args: [ - contractConfig, - premintConfig2, - signedMessage2, - quantityToMint2, - comment, - ], + args: [premintConfig2, signedMessage2, quantityToMint2, comment], value: valueToSend2, }); @@ -440,10 +403,10 @@ describe("ZoraCreator1155Preminter", () => { // now premint status for the second mint, it should be minted tokenId = await publicClient.readContract({ - abi: zoraCreator1155ImplABI, - address: contractAddress, - functionName: "delegatedTokenId", - args: [premintConfig2.uid], + abi: preminterAbi, + address: preminterAddress, + functionName: "getPremintedTokenId", + args: [premintConfig2.contractConfig, premintConfig2.uid], }); expect(tokenId).not.toBe(0n); diff --git a/package/preminter.ts b/package/preminter.ts index ba125babe..d4a35255f 100644 --- a/package/preminter.ts +++ b/package/preminter.ts @@ -1,17 +1,18 @@ import { Address } from "abitype"; import { ExtractAbiFunction, AbiParametersToPrimitiveTypes } from "abitype"; -import { zoraCreator1155PremintExecutorABI as preminterAbi } from "./wagmiGenerated"; +import { zoraCreator1155PreminterABI as preminterAbi } from "./wagmiGenerated"; import { TypedDataDefinition } from "viem"; -type PremintInputs = ExtractAbiFunction< +type PreminterHashInputs = ExtractAbiFunction< typeof preminterAbi, - "premint" + "premintHashData" >["inputs"]; -type PreminterHashDataTypes = AbiParametersToPrimitiveTypes; +type PreminterHashDataTypes = + AbiParametersToPrimitiveTypes; -export type ContractCreationConfig = PreminterHashDataTypes[0]; -export type PremintConfig = PreminterHashDataTypes[1]; +export type PremintConfig = PreminterHashDataTypes[0]; +export type ContractCreationConfig = PremintConfig["contractConfig"]; export type TokenCreationConfig = PremintConfig["tokenConfig"]; // Convenience method to create the structured typed data @@ -25,9 +26,10 @@ export const preminterTypedDataDefinition = ({ premintConfig: PremintConfig; chainId: number; }) => { - const { tokenConfig, uid, version, deleted } = premintConfig; + const { contractConfig, tokenConfig, uid, version, deleted } = premintConfig; const types = { Premint: [ + { name: "contractConfig", type: "ContractCreationConfig" }, { name: "tokenConfig", type: "TokenCreationConfig" }, { name: "uid", type: "uint32" }, { name: "version", type: "uint32" }, @@ -60,6 +62,7 @@ export const preminterTypedDataDefinition = ({ }, types, message: { + contractConfig, tokenConfig, uid, version,