diff --git a/packages/protocol-sdk/src/anvil.ts b/packages/protocol-sdk/src/anvil.ts index 516bd34b6..49160dbb0 100644 --- a/packages/protocol-sdk/src/anvil.ts +++ b/packages/protocol-sdk/src/anvil.ts @@ -31,7 +31,7 @@ async function waitForAnvilInit(anvil: any) { export type AnvilTestForkSettings = { forkUrl: string; forkBlockNumber: number; -} +}; export const makeAnvilTest = ({ forkUrl, @@ -56,7 +56,7 @@ export const makeAnvilTest = ({ { cwd: join(__dirname, ".."), killSignal: "SIGINT", - }, + } ); const anvilHost = `http://0.0.0.0:${port}`; await waitForAnvilInit(anvil); diff --git a/packages/protocol-sdk/src/apis/http-api-base.ts b/packages/protocol-sdk/src/apis/http-api-base.ts index bb2df588d..3e9e50639 100644 --- a/packages/protocol-sdk/src/apis/http-api-base.ts +++ b/packages/protocol-sdk/src/apis/http-api-base.ts @@ -33,7 +33,7 @@ export const get = async (url: string) => { throw new BadResponseError( `Invalid response, status ${response.status}`, response.status, - json, + json ); } return (await response.json()) as T; @@ -65,7 +65,7 @@ export const post = async (url: string, data: any) => { throw new BadResponseError( `Bad response: ${response.status}`, response.status, - json, + json ); } return (await response.json()) as T; @@ -75,7 +75,7 @@ export const retries = async ( tryFn: () => T, maxTries: number = 3, atTry: number = 1, - linearBackoffMS: number = 200, + linearBackoffMS: number = 200 ): Promise => { try { return await tryFn(); diff --git a/packages/protocol-sdk/src/create/1155-create-helper.test.ts b/packages/protocol-sdk/src/create/1155-create-helper.test.ts index a8ae366e1..874aa68f9 100644 --- a/packages/protocol-sdk/src/create/1155-create-helper.test.ts +++ b/packages/protocol-sdk/src/create/1155-create-helper.test.ts @@ -39,7 +39,7 @@ describe("create-helper", () => { expect(receipt.to).to.equal("0x777777c338d93e2c7adf08d102d45ca7cc4ed021"); expect(getTokenIdFromCreateReceipt(receipt)).to.be.equal(1n); }, - 20 * 1000, + 20 * 1000 ); anvilTest( "creates a new contract, than creates a new token on this existing contract", @@ -62,11 +62,12 @@ describe("create-helper", () => { mintToCreatorCount: 1, }); expect(contractAddress).to.be.equal( - "0xb1A8928dF830C21eD682949Aa8A83C1C215194d3", + "0xb1A8928dF830C21eD682949Aa8A83C1C215194d3" ); expect(contractExists).to.be.false; - const { request: simulateResponse } = - await publicClient.simulateContract(request); + const { request: simulateResponse } = await publicClient.simulateContract( + request + ); const hash = await walletClient.writeContract(simulateResponse); const receipt = await publicClient.waitForTransactionReceipt({ hash }); const firstTokenId = getTokenIdFromCreateReceipt(receipt); @@ -82,14 +83,14 @@ describe("create-helper", () => { tokenMetadataURI: demoTokenMetadataURI, account: creatorAccount, mintToCreatorCount: 1, - }, + } ); expect(newTokenOnExistingContract.contractAddress).to.be.equal( - "0xb1A8928dF830C21eD682949Aa8A83C1C215194d3", + "0xb1A8928dF830C21eD682949Aa8A83C1C215194d3" ); expect(newTokenOnExistingContract.contractExists).to.be.true; const { request: simulateRequest } = await publicClient.simulateContract( - newTokenOnExistingContract.request, + newTokenOnExistingContract.request ); const newHash = await walletClient.writeContract(simulateRequest); const newReceipt = await publicClient.waitForTransactionReceipt({ @@ -99,6 +100,6 @@ describe("create-helper", () => { expect(tokenId).to.be.equal(2n); expect(newReceipt).not.toBeNull(); }, - 20 * 1000, + 20 * 1000 ); }); diff --git a/packages/protocol-sdk/src/create/1155-create-helper.ts b/packages/protocol-sdk/src/create/1155-create-helper.ts index 84f9b276d..7c0f20008 100644 --- a/packages/protocol-sdk/src/create/1155-create-helper.ts +++ b/packages/protocol-sdk/src/create/1155-create-helper.ts @@ -143,7 +143,7 @@ export function create1155TokenSetupArgs({ abi: zoraCreator1155ImplABI, functionName: "adminMint", args: [account, nextTokenId, mintToCreatorCount, "0x"], - }), + }) ); } @@ -160,7 +160,7 @@ export function create1155TokenSetupArgs({ royaltyRecipient: royaltySettings?.royaltyRecipient || account, }, ], - }), + }) ); } @@ -168,7 +168,7 @@ export function create1155TokenSetupArgs({ } export const getTokenIdFromCreateReceipt = ( - receipt: TransactionReceipt, + receipt: TransactionReceipt ): bigint | undefined => { for (const data of receipt.logs) { try { @@ -188,7 +188,7 @@ async function getContractExists( publicClient: PublicClient, contract: ContractType, // Account that is the creator of the contract - account: Address, + account: Address ) { let contractAddress; let contractExists = false; @@ -266,7 +266,7 @@ export function create1155CreatorClient({ const { contractExists, contractAddress } = await getContractExists( publicClient, contract, - account, + account ); // Assume the next token id is the first token available for a new contract. diff --git a/packages/protocol-sdk/src/mint/mint-api-client.ts b/packages/protocol-sdk/src/mint/mint-api-client.ts index 3918ab3e2..110484269 100644 --- a/packages/protocol-sdk/src/mint/mint-api-client.ts +++ b/packages/protocol-sdk/src/mint/mint-api-client.ts @@ -17,13 +17,13 @@ function encodeQueryParameters(params: Record) { const getMintable = async ( path: MintableGetTokenPathParameters, - query: MintableGetTokenGetQueryParameters, + query: MintableGetTokenGetQueryParameters ): Promise => retries(() => { return get( `${ZORA_API_BASE}discover/mintables/${path.chain_name}/${ path.collection_address - }${query?.token_id ? `?${encodeQueryParameters(query)}` : ""}`, + }${query?.token_id ? `?${encodeQueryParameters(query)}` : ""}` ); }); diff --git a/packages/protocol-sdk/src/mint/mint-client.test.ts b/packages/protocol-sdk/src/mint/mint-client.test.ts index 696e5ac0a..f3c9adfd7 100644 --- a/packages/protocol-sdk/src/mint/mint-client.test.ts +++ b/packages/protocol-sdk/src/mint/mint-client.test.ts @@ -58,7 +58,7 @@ describe("mint-helper", () => { expect(oldBalance).to.be.equal(0n); expect(newBalance).to.be.equal(1n); }, - 12 * 1000, + 12 * 1000 ); anvilTest( @@ -112,6 +112,6 @@ describe("mint-helper", () => { expect(oldBalance).to.be.equal(0n); expect(newBalance).to.be.equal(1n); }, - 12 * 1000, + 12 * 1000 ); }); diff --git a/packages/protocol-sdk/src/mint/mint-client.ts b/packages/protocol-sdk/src/mint/mint-client.ts index c56b27fb4..6f72b2414 100644 --- a/packages/protocol-sdk/src/mint/mint-client.ts +++ b/packages/protocol-sdk/src/mint/mint-client.ts @@ -66,7 +66,7 @@ class MintClient extends ClientBase { chain_name: this.network.zoraBackendChainName, collection_address: tokenContract, }, - { token_id: tokenId?.toString() }, + { token_id: tokenId?.toString() } ); } @@ -95,11 +95,11 @@ class MintClient extends ClientBase { if ( !["zora_create", "zora_create_1155"].includes( - mintable.mint_context?.mint_context_type!, + mintable.mint_context?.mint_context_type! ) ) { throw new MintError( - `Mintable type ${mintable.mint_context.mint_context_type} is currently unsupported.`, + `Mintable type ${mintable.mint_context.mint_context_type} is currently unsupported.` ); } @@ -150,7 +150,7 @@ class MintClient extends ClientBase { contractAddress: mintable.contract_address, tokenId: mintable.token_id!, subgraphUrl: this.network.subgraphUrl, - }, + } ); const result: SimulateContractParameters< diff --git a/packages/protocol-sdk/src/premint/premint-api-client.ts b/packages/protocol-sdk/src/premint/premint-api-client.ts index c4be78df2..89c0e9a08 100644 --- a/packages/protocol-sdk/src/premint/premint-api-client.ts +++ b/packages/protocol-sdk/src/premint/premint-api-client.ts @@ -25,28 +25,28 @@ export type PremintSignatureGetResponse = export type BackendChainNames = components["schemas"]["ChainName"]; const postSignature = async ( - data: PremintSignatureRequestBody, + data: PremintSignatureRequestBody ): Promise => retries(() => - post(`${ZORA_API_BASE}premint/signature`, data), + post(`${ZORA_API_BASE}premint/signature`, data) ); const getNextUID = async ( - path: PremintNextUIDGetPathParameters, + path: PremintNextUIDGetPathParameters ): Promise => retries(() => get( - `${ZORA_API_BASE}premint/signature/${path.chain_name}/${path.collection_address}/next_uid`, - ), + `${ZORA_API_BASE}premint/signature/${path.chain_name}/${path.collection_address}/next_uid` + ) ); const getSignature = async ( - path: PremintSignatureGetPathParameters, + path: PremintSignatureGetPathParameters ): Promise => retries(() => get( - `${ZORA_API_BASE}premint/signature/${path.chain_name}/${path.collection_address}/${path.uid}`, - ), + `${ZORA_API_BASE}premint/signature/${path.chain_name}/${path.collection_address}/${path.uid}` + ) ); export const PremintAPIClient = { diff --git a/packages/protocol-sdk/src/premint/premint-client.test.ts b/packages/protocol-sdk/src/premint/premint-client.test.ts index 7a5a53fc3..791e411d4 100644 --- a/packages/protocol-sdk/src/premint/premint-client.test.ts +++ b/packages/protocol-sdk/src/premint/premint-client.test.ts @@ -68,7 +68,7 @@ describe("ZoraCreator1155Premint", () => { "0x588d19641de9ba1dade4d2bb5387c8dc96f4a990fef69787534b60caead759e6334975a6be10a796da948cd7d1d4f5580b3f84d49d9fa4e0b41c97759507975a1c", }); }, - 20 * 1000, + 20 * 1000 ); anvilTest.skip( @@ -112,7 +112,7 @@ describe("ZoraCreator1155Premint", () => { publicClient, }); expect(signatureValid.isValid).toBe(true); - }, + } ); anvilTest( @@ -163,8 +163,9 @@ describe("ZoraCreator1155Premint", () => { mintComment: "", }, }); - const { request: simulateRequest } = - await publicClient.simulateContract(request); + const { request: simulateRequest } = await publicClient.simulateContract( + request + ); const hash = await walletClient.writeContract(simulateRequest); const receipt = await publicClient.waitForTransactionReceipt({ hash }); const { premintedLog, urls } = @@ -207,6 +208,6 @@ describe("ZoraCreator1155Premint", () => { uid: 3, }); }, - 20 * 1000, + 20 * 1000 ); }); diff --git a/packages/protocol-sdk/src/premint/premint-client.ts b/packages/protocol-sdk/src/premint/premint-client.ts index 2c50cccb1..92da39c59 100644 --- a/packages/protocol-sdk/src/premint/premint-client.ts +++ b/packages/protocol-sdk/src/premint/premint-client.ts @@ -81,7 +81,7 @@ export const DefaultMintArguments = { * @returns Premint event arguments */ export function getPremintedLogFromReceipt( - receipt: TransactionReceipt, + receipt: TransactionReceipt ): PremintedLogType | undefined { for (const data of receipt.logs) { try { @@ -104,7 +104,7 @@ export function getPremintedLogFromReceipt( * @returns Viem type-compatible premint object */ export const convertPremint = ( - premint: PremintSignatureGetResponse["premint"], + premint: PremintSignatureGetResponse["premint"] ) => ({ ...premint, tokenConfig: { @@ -120,7 +120,7 @@ export const convertPremint = ( }); export const convertCollection = ( - collection: PremintSignatureGetResponse["collection"], + collection: PremintSignatureGetResponse["collection"] ) => ({ ...collection, contractAdmin: collection.contractAdmin as Address, @@ -160,11 +160,11 @@ export const encodePremintV2ForAPI = ({ mintDuration: tokenConfig.mintDuration.toString(), maxTokensPerAddress: tokenConfig.maxTokensPerAddress.toString(), }, -}) +}); export const encodePremintForAPI = ({ premintConfig, - premintConfigVersion + premintConfigVersion, }: PremintConfigAndVersion) => { if (premintConfigVersion === PremintConfigVersion.V1) { return encodePremintV1ForAPI(premintConfig); @@ -173,8 +173,7 @@ export const encodePremintForAPI = ({ return encodePremintV2ForAPI(premintConfig); } throw new Error(`Invalid premint config version ${premintConfigVersion}`); -} - +}; /** * Preminter API to access ZORA Premint functionality. @@ -285,7 +284,7 @@ class PremintClient extends ClientBase { contractAdmin: signerData.collection.contractAdmin as Address, }, premintConfig: signerData.premint, - premintConfigVersion: PremintConfigVersion.V1 + premintConfigVersion: PremintConfigVersion.V1, }); } @@ -340,7 +339,7 @@ class PremintClient extends ClientBase { uid: uid, collection: signerData.collection, premintConfig: signerData.premint, - premintConfigVersion: PremintConfigVersion.V1 + premintConfigVersion: PremintConfigVersion.V1, }); } @@ -391,14 +390,16 @@ class PremintClient extends ClientBase { originalContractAdmin: collection.contractAdmin as Address, ...premintConfigAndVersion, publicClient, - signature + signature, }); if (!isAuthorized) { throw new Error("Not authorized to create premint"); } } - if (premintConfigAndVersion.premintConfigVersion === PremintConfigVersion.V2) { + if ( + premintConfigAndVersion.premintConfigVersion === PremintConfigVersion.V2 + ) { throw new Error("premint config v2 not supported yet"); } diff --git a/packages/protocol-sdk/src/premint/preminter.test.ts b/packages/protocol-sdk/src/premint/preminter.test.ts index ddaa6ff30..537d2037e 100644 --- a/packages/protocol-sdk/src/premint/preminter.test.ts +++ b/packages/protocol-sdk/src/premint/preminter.test.ts @@ -1,7 +1,4 @@ -import { - Address, - zeroAddress, -} from "viem"; +import { Address, zeroAddress } from "viem"; import { foundry } from "viem/chains"; import { describe, expect } from "vitest"; import { parseEther } from "viem"; @@ -25,11 +22,7 @@ import { recoverCreatorFromCreatorAttribution, getPremintExecutorAddress, } from "./preminter"; -import { - AnvilViemClientsTest, - forkUrls, - makeAnvilTest, -} from "src/anvil"; +import { AnvilViemClientsTest, forkUrls, makeAnvilTest } from "src/anvil"; // create token and contract creation config: const defaultContractConfig = ({ @@ -44,7 +37,7 @@ const defaultContractConfig = ({ const defaultTokenConfigV1 = ( fixedPriceMinterAddress: Address, - creatorAccount: Address, + creatorAccount: Address ): TokenCreationConfigV1 => ({ tokenURI: "ipfs://tokenIpfsId0", maxSupply: 100n, @@ -72,21 +65,36 @@ const defaultTokenConfigV2 = ( royaltyBPS: 200, payoutRecipient: creatorAccount, fixedPriceMinter: fixedPriceMinterAddress, - createReferral + createReferral, }); -const defaultPremintConfigV1 = ( -{ fixedPriceMinter, creatorAccount }: { fixedPriceMinter: Address; creatorAccount: Address; }, -): PremintConfigV1 => ({ +const defaultPremintConfigV1 = ({ + fixedPriceMinter, + creatorAccount, +}: { + fixedPriceMinter: Address; + creatorAccount: Address; +}): PremintConfigV1 => ({ tokenConfig: defaultTokenConfigV1(fixedPriceMinter, creatorAccount), deleted: false, uid: 105, version: 0, }); -const defaultPremintConfigV2 = ( -{ fixedPriceMinter, creatorAccount, createReferral = zeroAddress }: { fixedPriceMinter: Address; creatorAccount: Address; createReferral?: Address; }): PremintConfigV2 => ({ - tokenConfig: defaultTokenConfigV2(fixedPriceMinter, creatorAccount, createReferral), +const defaultPremintConfigV2 = ({ + fixedPriceMinter, + creatorAccount, + createReferral = zeroAddress, +}: { + fixedPriceMinter: Address; + creatorAccount: Address; + createReferral?: Address; +}): PremintConfigV2 => ({ + tokenConfig: defaultTokenConfigV2( + fixedPriceMinter, + creatorAccount, + createReferral + ), deleted: false, uid: 106, version: 0, @@ -139,9 +147,10 @@ describe("ZoraCreator1155Preminter", () => { fixedPriceMinterAddress, accounts: { creatorAccount }, } = await setupContracts({ viemClients }); - const premintConfig = defaultPremintConfigV1( - { fixedPriceMinter: fixedPriceMinterAddress, creatorAccount }, - ); + const premintConfig = defaultPremintConfigV1({ + fixedPriceMinter: fixedPriceMinterAddress, + creatorAccount, + }); const contractConfig = defaultContractConfig({ contractAdmin: creatorAccount, }); @@ -160,7 +169,7 @@ describe("ZoraCreator1155Preminter", () => { verifyingContract: contractAddress, chainId: 999, premintConfig, - premintConfigVersion: PremintConfigVersion.V1 + premintConfigVersion: PremintConfigVersion.V1, }), account: creatorAccount, }); @@ -173,7 +182,7 @@ describe("ZoraCreator1155Preminter", () => { contractAddress, }); }, - 20 * 1000, + 20 * 1000 ); anvilTest( "can sign and recover a v1 premint config signature", @@ -183,9 +192,10 @@ describe("ZoraCreator1155Preminter", () => { accounts: { creatorAccount }, } = await setupContracts({ viemClients }); - const premintConfig = defaultPremintConfigV1( - { fixedPriceMinter: fixedPriceMinterAddress, creatorAccount }, - ); + const premintConfig = defaultPremintConfigV1({ + fixedPriceMinter: fixedPriceMinterAddress, + creatorAccount, + }); const contractConfig = defaultContractConfig({ contractAdmin: creatorAccount, }); @@ -204,7 +214,7 @@ describe("ZoraCreator1155Preminter", () => { // we need to sign here for the anvil chain, cause thats where it is run on chainId: foundry.id, premintConfig, - premintConfigVersion: PremintConfigVersion.V1 + premintConfigVersion: PremintConfigVersion.V1, }), account: creatorAccount, }); @@ -226,7 +236,7 @@ describe("ZoraCreator1155Preminter", () => { expect(recoveredAddress).to.equal(creatorAccount); }, - 20 * 1000, + 20 * 1000 ); makeAnvilTest({ forkUrl: forkUrls.zoraSepoli, @@ -239,13 +249,11 @@ describe("ZoraCreator1155Preminter", () => { accounts: { creatorAccount }, } = await setupContracts({ viemClients }); - const premintConfig = defaultPremintConfigV2( - { - creatorAccount, - fixedPriceMinter: fixedPriceMinterAddress, - createReferral: creatorAccount - } - ); + const premintConfig = defaultPremintConfigV2({ + creatorAccount, + fixedPriceMinter: fixedPriceMinterAddress, + createReferral: creatorAccount, + }); const contractConfig = defaultContractConfig({ contractAdmin: creatorAccount, }); @@ -264,7 +272,7 @@ describe("ZoraCreator1155Preminter", () => { // we need to sign here for the anvil chain, cause thats where it is run on chainId: foundry.id, premintConfig, - premintConfigVersion: PremintConfigVersion.V2 + premintConfigVersion: PremintConfigVersion.V2, }), account: creatorAccount, }); @@ -286,7 +294,7 @@ describe("ZoraCreator1155Preminter", () => { expect(recoveredAddress).to.equal(creatorAccount); }, - 20 * 1000, + 20 * 1000 ); anvilTest( "can sign and mint multiple tokens", @@ -296,9 +304,10 @@ describe("ZoraCreator1155Preminter", () => { accounts: { creatorAccount, collectorAccount }, } = await setupContracts({ viemClients }); // setup contract and token creation parameters - const premintConfig1 = defaultPremintConfigV1( - { fixedPriceMinter: fixedPriceMinterAddress, creatorAccount }, - ); + const premintConfig1 = defaultPremintConfigV1({ + fixedPriceMinter: fixedPriceMinterAddress, + creatorAccount, + }); const contractConfig = defaultContractConfig({ contractAdmin: creatorAccount, }); @@ -321,7 +330,7 @@ describe("ZoraCreator1155Preminter", () => { // we need to sign here for the anvil chain, cause thats where it is run on chainId: foundry.id, premintConfig: premintConfig1, - premintConfigVersion: PremintConfigVersion.V1 + premintConfigVersion: PremintConfigVersion.V1, }), account: creatorAccount, }); @@ -352,7 +361,7 @@ describe("ZoraCreator1155Preminter", () => { const mintArguments: MintArguments = { mintComment: "", mintRecipient: collectorAccount, - mintReferral: collectorAccount + mintReferral: collectorAccount, }; // now have the collector execute the first signed message; @@ -408,7 +417,7 @@ describe("ZoraCreator1155Preminter", () => { const premintConfig2 = defaultPremintConfigV2({ creatorAccount, fixedPriceMinter: fixedPriceMinterAddress, - createReferral: creatorAccount + createReferral: creatorAccount, }); // sign the message to create the second token @@ -417,7 +426,7 @@ describe("ZoraCreator1155Preminter", () => { verifyingContract: contractAddress, chainId: foundry.id, premintConfig: premintConfig2, - premintConfigVersion: PremintConfigVersion.V2 + premintConfigVersion: PremintConfigVersion.V2, }), account: creatorAccount, }); @@ -446,15 +455,16 @@ describe("ZoraCreator1155Preminter", () => { // now have the collector execute the second signed message. // it should create a new token against the existing contract - const mintHash2 = await viemClients.walletClient.writeContract(simulationResult.request); + const mintHash2 = await viemClients.walletClient.writeContract( + simulationResult.request + ); - const premintV2Receipt = await viemClients.publicClient.waitForTransactionReceipt({ - hash: mintHash2, - }); + const premintV2Receipt = + await viemClients.publicClient.waitForTransactionReceipt({ + hash: mintHash2, + }); - expect( - premintV2Receipt.status, - ).toBe("success"); + expect(premintV2Receipt.status).toBe("success"); // now premint status for the second mint, it should be minted [, tokenId] = await viemClients.publicClient.readContract({ @@ -477,7 +487,7 @@ describe("ZoraCreator1155Preminter", () => { expect(tokenBalance2).toBe(quantityToMint2); }, // 10 second timeout - 40 * 1000, + 40 * 1000 ); anvilTest( @@ -487,9 +497,10 @@ describe("ZoraCreator1155Preminter", () => { fixedPriceMinterAddress, accounts: { creatorAccount, collectorAccount }, } = await setupContracts({ viemClients }); - const premintConfig = defaultPremintConfigV2( - { fixedPriceMinter: fixedPriceMinterAddress, creatorAccount }, - ); + const premintConfig = defaultPremintConfigV2({ + fixedPriceMinter: fixedPriceMinterAddress, + creatorAccount, + }); const contractConfig = defaultContractConfig({ contractAdmin: creatorAccount, }); @@ -514,7 +525,7 @@ describe("ZoraCreator1155Preminter", () => { // we need to sign here for the anvil chain, cause thats where it is run on chainId: signingChainId, premintConfig, - premintConfigVersion: PremintConfigVersion.V2 + premintConfigVersion: PremintConfigVersion.V2, }), account: creatorAccount, }); @@ -549,8 +560,8 @@ describe("ZoraCreator1155Preminter", () => { { mintComment: "", mintRecipient: collectorAccount, - mintReferral: zeroAddress - } + mintReferral: zeroAddress, + }, ], value: valueToSend, }); @@ -573,17 +584,16 @@ describe("ZoraCreator1155Preminter", () => { const creatorAttributionEvent = topics[0]!; - const { creator: creatorFromEvent } = - creatorAttributionEvent.args; + const { creator: creatorFromEvent } = creatorAttributionEvent.args; const recoveredSigner = await recoverCreatorFromCreatorAttribution({ creatorAttribution: creatorAttributionEvent.args, chainId: signingChainId, - tokenContract: contractAddress - }) + tokenContract: contractAddress, + }); expect(creatorFromEvent).toBe(creatorAccount); expect(recoveredSigner).toBe(creatorFromEvent); - }, + } ); }); diff --git a/packages/protocol-sdk/src/premint/preminter.ts b/packages/protocol-sdk/src/premint/preminter.ts index a9ac72a87..d11239a03 100644 --- a/packages/protocol-sdk/src/premint/preminter.ts +++ b/packages/protocol-sdk/src/premint/preminter.ts @@ -101,16 +101,21 @@ export const PremintConfigVersion = { V2: "2", } as const; -type PremintConfigForVersion = T extends "1" ? PremintConfigV1 : PremintConfigV2; +type PremintConfigForVersion = T extends "1" + ? PremintConfigV1 + : PremintConfigV2; type PremintConfigWithVersion = { - premintConfig: PremintConfigForVersion, - premintConfigVersion: T -} + premintConfig: PremintConfigForVersion; + premintConfigVersion: T; +}; -export type PremintConfigAndVersion = PremintConfigWithVersion<"1"> | PremintConfigWithVersion<"2">; +export type PremintConfigAndVersion = + | PremintConfigWithVersion<"1"> + | PremintConfigWithVersion<"2">; -export const getPremintExecutorAddress = () => zoraCreator1155PremintExecutorImplAddress[999]; +export const getPremintExecutorAddress = () => + zoraCreator1155PremintExecutorImplAddress[999]; /** * Creates a typed data definition for a premint config. Works for all versions of the premint config by specifying the premintConfigVersion. @@ -119,7 +124,7 @@ export const getPremintExecutorAddress = () => zoraCreator1155PremintExecutorImp * @param params.chainId the chain id the premint is signed for * @param params.premintConfigVersion the version of the premint config * @param params.premintConfig the premint config - * @returns + * @returns */ export const premintTypedDataDefinition = ({ verifyingContract, @@ -162,15 +167,15 @@ export type IsValidSignatureReturn = { }; /** - * Checks if the provided signature is valid for the provided premint config. Is valid means that the signature is valid, and that the recovered signer is authorized to + * Checks if the provided signature is valid for the provided premint config. Is valid means that the signature is valid, and that the recovered signer is authorized to * create premints on the given contract. Works for all versions of the premint config by specifying the premintConfigVersion. - * + * * @param params validationProperties * @param params.tokenContract the address of the 1155 contract * @param params.originalContractAdmin the original contractAdmin on the ContractCreationConfig for the premint; this is usually the original creator of the premint * @param params.signature signature to validate * @param params.chainId the chain id of the current chain - * @param params.publicClient public rpc read-only client + * @param params.publicClient public rpc read-only client * @param params.premintConfigVersion the version of the premint config * @param params.premintConfig the premint config * @returns @@ -192,7 +197,7 @@ export async function isValidSignature({ const typedData = premintTypedDataDefinition({ verifyingContract: tokenContract, chainId, - ...premintConfigAndVersion + ...premintConfigAndVersion, }); return await recoverAndValidateSignature({ @@ -210,10 +215,10 @@ export async function isValidSignature({ * @param params validationProperties * @param params.typedData typed data definition for premint config * @param params.signature signature to validate - * @param params.publicClient public rpc read-only client + * @param params.publicClient public rpc read-only client * @param params.premintConfigContractAdmin the original contractAdmin on the ContractCreationConfig for the premint; this is usually the original creator of the premint * @param params.tokenContract the address of the 1155 contract - * @returns + * @returns */ export async function recoverAndValidateSignature({ typedData, @@ -246,11 +251,11 @@ export async function recoverAndValidateSignature({ let isAuthorized = false; if (recoveredAddress) isAuthorized = await publicClient.readContract({ - abi: preminterAbi, - address: getPremintExecutorAddress(), - functionName: "isAuthorizedToCreatePremint", - args: [recoveredAddress, premintConfigContractAdmin, tokenContract], - }); + abi: preminterAbi, + address: getPremintExecutorAddress(), + functionName: "isAuthorizedToCreatePremint", + args: [recoveredAddress, premintConfigContractAdmin, tokenContract], + }); return { isAuthorized, @@ -258,10 +263,9 @@ export async function recoverAndValidateSignature({ }; } - /** * Converts a premint config from v1 to v2 - * + * * @param premintConfig premint config to convert * @param createReferral address that referred the creator, that will receive create referral rewards for the created token */ @@ -289,8 +293,11 @@ export function migratePremintConfigToV2({ }; } -export type CreatorAttributionEventParams = GetEventArgs; - +export type CreatorAttributionEventParams = GetEventArgs< + typeof zoraCreator1155ImplABI, + "CreatorAttribution", + { EnableUnion: false } +>; /** * Recovers the address from a CreatorAttribution event emitted from a ZoraCreator1155 contract @@ -302,57 +309,64 @@ export type CreatorAttributionEventParams = GetEventArgs { + // hash the eip712 domain based on the parameters emitted from the event: + const hashedDomain = hashDomain({ + domain: { + chainId, + name: domainName, + verifyingContract: tokenContract, + version, + }, + types: { + EIP712Domain: [ + { name: "name", type: "string" }, + { name: "version", type: "string" }, + { + name: "chainId", + type: "uint256", + }, + { + name: "verifyingContract", + type: "address", + }, + ], + }, + }); - // hash the eip712 domain based on the parameters emitted from the event: - const hashedDomain = hashDomain({ - domain: { - chainId, - name: domainName, - verifyingContract: tokenContract, - version, - }, - types: { - EIP712Domain: [ - { name: "name", type: "string" }, - { name: "version", type: "string" }, - { - name: "chainId", - type: "uint256", - }, - { - name: "verifyingContract", - type: "address", - }, - ], - }, - }); - - // re-build the eip-712 typed data hash, consisting of the hashed domain and the structHash emitted from the event: - const parts: Hex[] = ["0x1901", hashedDomain, structHash!]; + // re-build the eip-712 typed data hash, consisting of the hashed domain and the structHash emitted from the event: + const parts: Hex[] = ["0x1901", hashedDomain, structHash!]; - const hashedTypedData = keccak256(concat(parts)); + const hashedTypedData = keccak256(concat(parts)); - return await recoverAddress({ - hash: hashedTypedData, - signature: signature!, - }); -} + return await recoverAddress({ + hash: hashedTypedData, + signature: signature!, + }); +}; /** - * Checks if the 1155 contract at that address supports the given version of the premint config. + * Checks if the 1155 contract at that address supports the given version of the premint config. */ -export const supportsPremintVersion = async (version: PremintConfigVersion, tokenContract: Address, publicClient: PublicClient) => { +export const supportsPremintVersion = async ( + version: PremintConfigVersion, + tokenContract: Address, + publicClient: PublicClient +) => { const supportedPremintSignatureVersions = await publicClient.readContract({ abi: preminterAbi, address: getPremintExecutorAddress(), functionName: "supportedPremintSignatureVersions", - args: [tokenContract] + args: [tokenContract], }); return supportedPremintSignatureVersions.includes(version); -} \ No newline at end of file +};