/* eslint-disable eslint-comments/disable-enable-pair */ import type { SigningCosmWasmClient } from '@cosmjs/cosmwasm-stargate' import type { Coin } from '@cosmjs/proto-signing' import type { logs } from '@cosmjs/stargate' import { OPEN_EDITION_FACTORY_ADDRESS, OPEN_EDITION_UPDATABLE_FACTORY_ADDRESS } from 'utils/constants' export interface CreateOpenEditionMinterResponse { readonly openEditionMinterAddress: string readonly sg721Address: string readonly transactionHash: string readonly logs: readonly logs.Log[] } export interface OpenEditionFactoryInstance { readonly contractAddress: string //Query //Execute createOpenEditionMinter: ( senderAddress: string, msg: Record, funds: Coin[], updatable?: boolean, ) => Promise } export interface OpenEditionFactoryMessages { createOpenEditionMinter: ( msg: Record, funds: Coin[], updatable?: boolean, ) => CreateOpenEditionMinterMessage } export interface CreateOpenEditionMinterMessage { sender: string contract: string msg: Record funds: Coin[] } export interface OpenEditionFactoryContract { use: (contractAddress: string) => OpenEditionFactoryInstance messages: (contractAddress: string) => OpenEditionFactoryMessages } export const openEditionFactory = (client: SigningCosmWasmClient, txSigner: string): OpenEditionFactoryContract => { const use = (contractAddress: string): OpenEditionFactoryInstance => { //Query //Execute const createOpenEditionMinter = async ( senderAddress: string, msg: Record, funds: Coin[], updatable?: boolean, ): Promise => { const result = await client.execute( senderAddress, updatable ? OPEN_EDITION_UPDATABLE_FACTORY_ADDRESS : OPEN_EDITION_FACTORY_ADDRESS, msg, 'auto', '', funds, ) return { openEditionMinterAddress: result.logs[0].events[5].attributes[0].value, sg721Address: result.logs[0].events[5].attributes[2].value, transactionHash: result.transactionHash, logs: result.logs, } } return { contractAddress, createOpenEditionMinter, } } const messages = (contractAddress: string) => { const createOpenEditionMinter = ( msg: Record, funds: Coin[], updatable?: boolean, ): CreateOpenEditionMinterMessage => { return { sender: txSigner, contract: contractAddress, msg, funds, } } return { createOpenEditionMinter, } } return { use, messages } }