diff --git a/src/interfaces.ts b/src/interfaces.ts index 6b8bb2c..d62a520 100644 --- a/src/interfaces.ts +++ b/src/interfaces.ts @@ -59,7 +59,7 @@ export interface MarketplaceRequirements { sellerTaxPercentage: number; } -export interface MinterRequirements { +export interface SftMinterRequirements { antiSpamTaxValue: number; addressFrozen: boolean; frozenNonces: number[]; @@ -75,6 +75,21 @@ export interface MinterRequirements { contractWhitelistEnabled: boolean; } +export interface NftMinterRequirements { + antiSpamTaxValue: number; + addressFrozen: boolean; + frozenNonces: number[]; + contractPaused: boolean; + userWhitelistedForMint: boolean; + lastUserMintTime: number; + maxRoyalties: number; + minRoyalties: number; + mintTimeLimit: number; + numberOfMintsForUser: number; + totalNumberOfMints: number; + contractWhitelistEnabled: boolean; +} + export interface Offer { index: number; owner: string; diff --git a/src/minter.ts b/src/minter.ts index b2efbfc..cbc57c9 100644 --- a/src/minter.ts +++ b/src/minter.ts @@ -22,7 +22,7 @@ import { itheumTokenIdentifier, networkConfiguration } from './config'; -import { MinterRequirements } from './interfaces'; +import { SftMinterRequirements } from './interfaces'; import { ErrContractQuery, ErrNetworkConfig } from './errors'; export abstract class Minter { @@ -88,51 +88,6 @@ export abstract class Minter { ); } } - /** - * Retrieves the minter smart contract requirements for the given user - * @param address the address of the user - * @param taxToken the tax token to be used for the minting (default = `ITHEUM` token identifier based on the {@link EnvironmentsEnum}) - */ - async viewMinterRequirements( - address: IAddress, - taxToken = itheumTokenIdentifier[this.env as EnvironmentsEnum] - ): Promise { - const interaction = this.contract.methodsExplicit.getUserDataOut([ - new AddressValue(address), - new TokenIdentifierValue(taxToken) - ]); - const query = interaction.buildQuery(); - const queryResponse = await this.networkProvider.queryContract(query); - const endpointDefinition = interaction.getEndpoint(); - const { firstValue, returnCode } = new ResultsParser().parseQueryResponse( - queryResponse, - endpointDefinition - ); - if (returnCode.isSuccess()) { - const returnValue = firstValue?.valueOf(); - const requirements: MinterRequirements = { - antiSpamTaxValue: returnValue.anti_spam_tax_value.toNumber(), - contractPaused: returnValue.is_paused, - maxRoyalties: returnValue.max_royalties.toNumber(), - minRoyalties: returnValue.min_royalties.toNumber(), - maxSupply: returnValue.max_supply.toNumber(), - mintTimeLimit: returnValue.mint_time_limit.toNumber(), - lastUserMintTime: returnValue.last_mint_time, - userWhitelistedForMint: returnValue.is_whitelisted, - contractWhitelistEnabled: returnValue.whitelist_enabled, - numberOfMintsForUser: returnValue.minted_per_user.toNumber(), - totalNumberOfMints: returnValue.total_minted.toNumber(), - addressFrozen: returnValue.frozen, - frozenNonces: returnValue.frozen_nonces.map((v: any) => v.toNumber()) - }; - return requirements; - } else { - throw new ErrContractQuery( - 'viewMinterRequirements', - returnCode.toString() - ); - } - } /** * Retrieves the minter whitelist diff --git a/src/nft-minter.ts b/src/nft-minter.ts index 949d549..edd8444 100644 --- a/src/nft-minter.ts +++ b/src/nft-minter.ts @@ -24,12 +24,17 @@ import { dataNFTDataStreamAdvertise, storeToIpfs } from './common/mint-utils'; -import { ContractConfiguration } from './interfaces'; +import { + ContractConfiguration, + NftMinterRequirements, + SftMinterRequirements +} from './interfaces'; import { ErrArgumentNotSet, ErrAttributeNotSet, ErrContractQuery } from './errors'; +import { EnvironmentsEnum, itheumTokenIdentifier } from './config'; export class NftMinter extends Minter { /** @@ -515,4 +520,49 @@ export class NftMinter extends Minter { ); } } + + /** + * Retrieves the minter smart contract requirements for the given user + * @param address the address of the user + * @param taxToken the tax token to be used for the minting (default = `ITHEUM` token identifier based on the {@link EnvironmentsEnum}) + */ + async viewMinterRequirements( + address: IAddress, + taxToken = itheumTokenIdentifier[this.env as EnvironmentsEnum] + ): Promise { + const interaction = this.contract.methodsExplicit.getUserDataOut([ + new AddressValue(address), + new TokenIdentifierValue(taxToken) + ]); + const query = interaction.buildQuery(); + const queryResponse = await this.networkProvider.queryContract(query); + const endpointDefinition = interaction.getEndpoint(); + const { firstValue, returnCode } = new ResultsParser().parseQueryResponse( + queryResponse, + endpointDefinition + ); + if (returnCode.isSuccess()) { + const returnValue = firstValue?.valueOf(); + const requirements: NftMinterRequirements = { + antiSpamTaxValue: returnValue.anti_spam_tax_value.toNumber(), + contractPaused: returnValue.is_paused, + maxRoyalties: returnValue.max_royalties.toNumber(), + minRoyalties: returnValue.min_royalties.toNumber(), + mintTimeLimit: returnValue.mint_time_limit.toNumber(), + lastUserMintTime: returnValue.last_mint_time, + userWhitelistedForMint: returnValue.is_whitelisted, + contractWhitelistEnabled: returnValue.whitelist_enabled, + numberOfMintsForUser: returnValue.minted_per_user.toNumber(), + totalNumberOfMints: returnValue.total_minted.toNumber(), + addressFrozen: returnValue.frozen, + frozenNonces: returnValue.frozen_nonces.map((v: any) => v.toNumber()) + }; + return requirements; + } else { + throw new ErrContractQuery( + 'viewMinterRequirements', + returnCode.toString() + ); + } + } } diff --git a/src/sft-minter.ts b/src/sft-minter.ts index 0567d99..17e60e2 100644 --- a/src/sft-minter.ts +++ b/src/sft-minter.ts @@ -5,6 +5,7 @@ import { ContractCallPayloadBuilder, ContractFunction, IAddress, + ResultsParser, StringValue, TokenIdentifierValue, Transaction, @@ -27,7 +28,8 @@ import { dataNFTDataStreamAdvertise, storeToIpfs } from './common/mint-utils'; -import { ErrArgumentNotSet } from './errors'; +import { ErrArgumentNotSet, ErrContractQuery } from './errors'; +import { SftMinterRequirements } from './interfaces'; export class SftMinter extends Minter { /** @@ -44,6 +46,52 @@ export class SftMinter extends Minter { ); } + /** + * Retrieves the minter smart contract requirements for the given user + * @param address the address of the user + * @param taxToken the tax token to be used for the minting (default = `ITHEUM` token identifier based on the {@link EnvironmentsEnum}) + */ + async viewMinterRequirements( + address: IAddress, + taxToken = itheumTokenIdentifier[this.env as EnvironmentsEnum] + ): Promise { + const interaction = this.contract.methodsExplicit.getUserDataOut([ + new AddressValue(address), + new TokenIdentifierValue(taxToken) + ]); + const query = interaction.buildQuery(); + const queryResponse = await this.networkProvider.queryContract(query); + const endpointDefinition = interaction.getEndpoint(); + const { firstValue, returnCode } = new ResultsParser().parseQueryResponse( + queryResponse, + endpointDefinition + ); + if (returnCode.isSuccess()) { + const returnValue = firstValue?.valueOf(); + const requirements: SftMinterRequirements = { + antiSpamTaxValue: returnValue.anti_spam_tax_value.toNumber(), + contractPaused: returnValue.is_paused, + maxRoyalties: returnValue.max_royalties.toNumber(), + minRoyalties: returnValue.min_royalties.toNumber(), + maxSupply: returnValue.max_supply.toNumber(), + mintTimeLimit: returnValue.mint_time_limit.toNumber(), + lastUserMintTime: returnValue.last_mint_time, + userWhitelistedForMint: returnValue.is_whitelisted, + contractWhitelistEnabled: returnValue.whitelist_enabled, + numberOfMintsForUser: returnValue.minted_per_user.toNumber(), + totalNumberOfMints: returnValue.total_minted.toNumber(), + addressFrozen: returnValue.frozen, + frozenNonces: returnValue.frozen_nonces.map((v: any) => v.toNumber()) + }; + return requirements; + } else { + throw new ErrContractQuery( + 'viewMinterRequirements', + returnCode.toString() + ); + } + } + /** * Creates an initialize contract transaction for the contract * @param senderAddress The address of the sender, must be the admin of the contract