diff --git a/packages/protocol-sdk/src/mint/mint-client.ts b/packages/protocol-sdk/src/mint/mint-client.ts index 7cc4953b2..c116acef3 100644 --- a/packages/protocol-sdk/src/mint/mint-client.ts +++ b/packages/protocol-sdk/src/mint/mint-client.ts @@ -35,44 +35,7 @@ const zora721Abi = parseAbi([ "function zoraFeeForAmount(uint256 amount) public view returns (address, uint256)", ] as const); -export type MintContractType = "721" | "1155"; -export function getMintType( - mintable: MintableGetTokenResponse, -): MintContractType | undefined { - const mintContextType = mintable.mint_context?.mint_context_type; - - if (mintContextType === "zora_create") return "721"; - if (mintContextType === "zora_create_1155") return "1155"; - - return; -} - -function validateMintable(mintable: MintableGetTokenResponse | undefined) { - if (!mintable) { - throw new MintError("No mintable found"); - } - - if (!mintable.is_active) { - throw new MintInactiveError("Minting token is inactive"); - } - - if (!mintable.mint_context) { - throw new MintError("No minting context data from zora API"); - } - - if ( - !["zora_create", "zora_create_1155"].includes( - mintable.mint_context?.mint_context_type!, - ) - ) { - throw new MintError( - `Mintable type ${mintable.mint_context.mint_context_type} is currently unsupported.`, - ); - } - - return mintable.mint_context.mint_context_type; -} class MintClient extends ClientBase { apiClient: typeof MintAPIClient; @@ -112,7 +75,7 @@ class MintClient extends ClientBase { mintable: MintableGetTokenResponse; mintArguments: MintArguments; }): Promise { - const mintContextType = validateMintable(mintable); + const mintContextType = validateMintableAndGetContextType(mintable); const thisPublicClient = this.getPublicClient(publicClient); @@ -150,6 +113,31 @@ export function createMintClient({ }) { return new MintClient(chain, mintAPIClient); } +export function validateMintableAndGetContextType(mintable: MintableGetTokenResponse | undefined) { + if (!mintable) { + throw new MintError("No mintable found"); + } + + if (!mintable.is_active) { + throw new MintInactiveError("Minting token is inactive"); + } + + if (!mintable.mint_context) { + throw new MintError("No minting context data from zora API"); + } + + if ( + !["zora_create", "zora_create_1155"].includes( + mintable.mint_context?.mint_context_type!, + ) + ) { + throw new MintError( + `Mintable type ${mintable.mint_context.mint_context_type} is currently unsupported.`, + ); + } + + return mintable.mint_context.mint_context_type; +} async function makePrepareMint721TokenParams({ publicClient, @@ -160,7 +148,7 @@ async function makePrepareMint721TokenParams({ }: { publicClient: PublicClient; mintable: MintableGetTokenResponse; - mintContextType: ReturnType; + mintContextType: ReturnType; minterAccount: Address; mintArguments: MintArguments; }): Promise> { @@ -208,7 +196,7 @@ async function makePrepareMint1155TokenParams({ publicClient: PublicClient; apiClient: typeof MintAPIClient; mintable: MintableGetTokenResponse; - mintContextType: ReturnType; + mintContextType: ReturnType; minterAccount: Address; mintArguments: MintArguments; subgraphUrl: string;