Skip to content

Commit

Permalink
fix: nft minter requirements update
Browse files Browse the repository at this point in the history
  • Loading branch information
bucurdavid committed Nov 16, 2023
1 parent ef85fe4 commit 7d25c10
Show file tree
Hide file tree
Showing 4 changed files with 117 additions and 49 deletions.
17 changes: 16 additions & 1 deletion src/interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ export interface MarketplaceRequirements {
sellerTaxPercentage: number;
}

export interface MinterRequirements {
export interface SftMinterRequirements {
antiSpamTaxValue: number;
addressFrozen: boolean;
frozenNonces: number[];
Expand All @@ -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;
Expand Down
47 changes: 1 addition & 46 deletions src/minter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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<MinterRequirements> {
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
Expand Down
52 changes: 51 additions & 1 deletion src/nft-minter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
/**
Expand Down Expand Up @@ -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<NftMinterRequirements> {
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()
);
}
}
}
50 changes: 49 additions & 1 deletion src/sft-minter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
ContractCallPayloadBuilder,
ContractFunction,
IAddress,
ResultsParser,
StringValue,
TokenIdentifierValue,
Transaction,
Expand All @@ -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 {
/**
Expand All @@ -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<SftMinterRequirements> {
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
Expand Down

0 comments on commit 7d25c10

Please sign in to comment.