Skip to content

Commit

Permalink
refactor: keep support for anti spam tax and treasury address
Browse files Browse the repository at this point in the history
  • Loading branch information
bucurdavid committed Feb 26, 2024
1 parent a7fa7bb commit ecf1eb0
Show file tree
Hide file tree
Showing 4 changed files with 136 additions and 18 deletions.
86 changes: 84 additions & 2 deletions src/abis/datanftmint.abi.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,21 @@
"name": "token_ticker",
"type": "bytes"
},
{
"name": "anti_spam_tax_token",
"type": "EgldOrEsdtTokenIdentifier"
},
{
"name": "anti_spam_tax_value",
"type": "BigUint"
},
{
"name": "mint_time_limit",
"type": "u64"
},
{
"name": "treasury_address",
"type": "Address"
}
],
"outputs": []
Expand Down Expand Up @@ -125,6 +137,18 @@
"inputs": [],
"outputs": []
},
{
"name": "setTreasuryAddress",
"onlyOwner": true,
"mutability": "mutable",
"inputs": [
{
"name": "address",
"type": "Address"
}
],
"outputs": []
},
{
"name": "setIsPaused",
"mutability": "mutable",
Expand All @@ -147,6 +171,21 @@
],
"outputs": []
},
{
"name": "setAntiSpamTax",
"mutability": "mutable",
"inputs": [
{
"name": "token_id",
"type": "EgldOrEsdtTokenIdentifier"
},
{
"name": "tax",
"type": "BigUint"
}
],
"outputs": []
},
{
"name": "setWhiteListSpots",
"mutability": "mutable",
Expand Down Expand Up @@ -273,6 +312,16 @@
}
]
},
{
"name": "getTreasuryAddress",
"mutability": "readonly",
"inputs": [],
"outputs": [
{
"type": "Address"
}
]
},
{
"name": "getWithdrawalAddress",
"mutability": "readonly",
Expand All @@ -293,6 +342,21 @@
}
]
},
{
"name": "getAntiSpamTax",
"mutability": "readonly",
"inputs": [
{
"name": "token",
"type": "EgldOrEsdtTokenIdentifier"
}
],
"outputs": [
{
"type": "BigUint"
}
]
},
{
"name": "getIsPaused",
"mutability": "readonly",
Expand Down Expand Up @@ -447,7 +511,7 @@
]
},
{
"name": "getBondContractAddress",
"name": "getAdministrator",
"mutability": "readonly",
"inputs": [],
"outputs": [
Expand All @@ -457,7 +521,7 @@
]
},
{
"name": "getAdministrator",
"name": "getBondContractAddress",
"mutability": "readonly",
"inputs": [],
"outputs": [
Expand All @@ -473,6 +537,10 @@
{
"name": "address",
"type": "Address"
},
{
"name": "tax_token",
"type": "EgldOrEsdtTokenIdentifier"
}
],
"outputs": [
Expand Down Expand Up @@ -866,6 +934,16 @@
}
]
},
{
"identifier": "setBondContractAddress",
"inputs": [
{
"name": "address",
"type": "Address",
"indexed": true
}
]
},
{
"identifier": "withdrawTokens",
"inputs": [
Expand Down Expand Up @@ -926,6 +1004,10 @@
"UserDataOut": {
"type": "struct",
"fields": [
{
"name": "anti_spam_tax_value",
"type": "BigUint"
},
{
"name": "is_paused",
"type": "bool"
Expand Down
1 change: 1 addition & 0 deletions src/interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ export interface MarketplaceRequirements {
}

export interface SftMinterRequirements {
antiSpamTaxValue: number;
addressFrozen: boolean;
frozenNonces: number[];
contractPaused: boolean;
Expand Down
49 changes: 42 additions & 7 deletions src/sft-minter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,12 @@ export class SftMinter extends Minter {
* @param taxToken the tax token to be used for the minting (default = `ITHEUM` token identifier based on the {@link EnvironmentsEnum})
*/
async viewMinterRequirements(
address: IAddress
address: IAddress,
taxToken = itheumTokenIdentifier[this.env as EnvironmentsEnum]
): Promise<SftMinterRequirements> {
const interaction = this.contract.methodsExplicit.getUserDataOut([
new AddressValue(address)
new AddressValue(address),
new TokenIdentifierValue(taxToken)
]);
const query = interaction.buildQuery();
const queryResponse = await this.networkProvider.queryContract(query);
Expand All @@ -68,6 +70,7 @@ export class SftMinter extends Minter {
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(),
Expand Down Expand Up @@ -124,21 +127,30 @@ export class SftMinter extends Minter {
* @param senderAddress The address of the sender, must be the admin of the contract
* @param collectionName The name of the NFT collection
* @param tokenTicker The ticker of the NFT collection
* @param antiSpamTaxTokenIdentifier The token identifier of the anti spam token
* @param antiSpamTaxTokenAmount The amount of anti spam token to be used for minting as tax
* @param mintLimit(seconds)- The mint limit between mints
* @param treasury_address The address of the treasury to collect the anti spam tax
*/
initializeContract(
senderAddress: IAddress,
collectionName: string,
tokenTicker: string,
mintLimit: number
antiSpamTaxTokenIdentifier: string,
antiSpamTaxTokenAmount: BigNumber.Value,
mintLimit: number,
treasury_address: IAddress
): Transaction {
const initializeContractTx = new Transaction({
value: 0,
data: new ContractCallPayloadBuilder()
.setFunction(new ContractFunction('initializeContract'))
.addArg(new StringValue(collectionName))
.addArg(new StringValue(tokenTicker))
.addArg(new TokenIdentifierValue(antiSpamTaxTokenIdentifier))
.addArg(new BigUIntValue(antiSpamTaxTokenAmount))
.addArg(new U64Value(mintLimit))
.addArg(new AddressValue(treasury_address))
.build(),
receiver: this.contract.getAddress(),
gasLimit: 10000000,
Expand All @@ -149,7 +161,30 @@ export class SftMinter extends Minter {
}

/**
*
* Creates a `setTreasuryAddress` transaction
* @param senderAddress The address of the sender, must be the admin of the contract
* @param treasuryAddress The address of the treasury to collect the anti spam tax
*/
setTreasuryAddress(
senderAddress: IAddress,
treasuryAddress: IAddress
): Transaction {
const setTreasuryAddressTx = new Transaction({
value: 0,
data: new ContractCallPayloadBuilder()
.setFunction(new ContractFunction('setTreasuryAddress'))
.addArg(new AddressValue(treasuryAddress))
.build(),
receiver: this.contract.getAddress(),
gasLimit: 10000000,
sender: senderAddress,
chainID: this.chainID
});
return setTreasuryAddressTx;
}

/**
* Creates a `setAntiSpamTax` transaction
* @param senderAddress The address of the sender, must be the admin of the contract
* @param maxSupply The maximum supply that can be minted
*/
Expand Down Expand Up @@ -190,7 +225,7 @@ export class SftMinter extends Minter {
* @param datasetTitle the title of the dataset. Between 10 and 60 alphanumeric characters.
* @param datasetDescription the description of the dataset. Between 10 and 400 alphanumeric characters.
* @param lockPeriod the lock period for the bond in days
* @param bondAmount the amount of the bond
* @param amountToSend the amount of the bond + anti spam tax (if anti spam tax > 0) to be sent
* @param options [optional] below parameters are optional or required based on use case
* - imageUrl: the URL of the image for the Data NFT
* - traitsUrl: the URL of the traits for the Data NFT
Expand All @@ -208,7 +243,7 @@ export class SftMinter extends Minter {
datasetTitle: string,
datasetDescription: string,
lockPeriod: number,
bondAmount: number,
amountToSend: number,
options?: {
imageUrl?: string;
traitsUrl?: string;
Expand Down Expand Up @@ -302,7 +337,7 @@ export class SftMinter extends Minter {
itheumTokenIdentifier[this.env as EnvironmentsEnum]
)
)
.addArg(new BigUIntValue(bondAmount))
.addArg(new BigUIntValue(amountToSend))
.addArg(new StringValue('mint'))
.addArg(new StringValue(tokenName))
.addArg(new StringValue(imageOnIpfsUrl))
Expand Down
18 changes: 9 additions & 9 deletions tests/sftminter.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,16 @@ import { Address, Transaction } from '@multiversx/sdk-core/out';
import { SftMinter, Minter, SftMinterRequirements } from '../src';

describe('Data Nft Minter Test', () => {
// test('#viewMinterRequirements', async () => {
// const dataNftMarket = new SftMinter('devnet');
test('#viewMinterRequirements', async () => {
const dataNftMarket = new SftMinter('devnet');

// const result = await dataNftMarket.viewMinterRequirements(
// new Address(
// 'erd10uavg8hd92620mfll2lt4jdmrg6xlf60awjp9ze5gthqjjhactvswfwuv8'
// )
// );
// expect(result).toBeInstanceOf(Object as unknown as SftMinterRequirements);
// });
const result = await dataNftMarket.viewMinterRequirements(
new Address(
'erd10uavg8hd92620mfll2lt4jdmrg6xlf60awjp9ze5gthqjjhactvswfwuv8'
)
);
expect(result).toBeInstanceOf(Object as unknown as SftMinterRequirements);
});

test('#burn', async () => {
const dataNftMarket = new SftMinter('devnet');
Expand Down

0 comments on commit ecf1eb0

Please sign in to comment.