Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

v2.4.0 - fix: nft minter requirements update #78

Merged
merged 6 commits into from
Nov 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@itheum/sdk-mx-data-nft",
"version": "2.3.0",
"version": "2.4.0",
"description": "SDK for Itheum's Data NFT Technology on MultiversX Blockchain",
"main": "out/index.js",
"types": "out/index.d.js",
Expand Down
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
4 changes: 2 additions & 2 deletions tests/sftminter.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Address, Transaction } from '@multiversx/sdk-core/out';
import { SftMinter, Minter, MinterRequirements } from '../src';
import { SftMinter, Minter, SftMinterRequirements } from '../src';

describe('Data Nft Minter Test', () => {
test('#getAddress', async () => {
Expand All @@ -18,7 +18,7 @@ describe('Data Nft Minter Test', () => {
'erd10uavg8hd92620mfll2lt4jdmrg6xlf60awjp9ze5gthqjjhactvswfwuv8'
)
);
expect(result).toBeInstanceOf(Object as unknown as MinterRequirements);
expect(result).toBeInstanceOf(Object as unknown as SftMinterRequirements);
});

test('#burn', async () => {
Expand Down