From c56a91262eeb06f12c7e1c2512a2a2dce373e946 Mon Sep 17 00:00:00 2001 From: bucurdavid Date: Mon, 11 Nov 2024 16:07:06 +0200 Subject: [PATCH 1/7] feat: bond contract upgrade with latest transaction builder --- package-lock.json | 6 +- package.json | 2 +- src/bond.ts | 674 +++++++++++++++++----------------------------- src/contract.ts | 11 +- 4 files changed, 261 insertions(+), 432 deletions(-) diff --git a/package-lock.json b/package-lock.json index 59e2d6d..8953bc2 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,15 +1,15 @@ { "name": "@itheum/sdk-mx-data-nft", - "version": "3.8.0-alpha.10", + "version": "3.8.0-alpha.11", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "@itheum/sdk-mx-data-nft", - "version": "3.8.0-alpha.10", + "version": "3.8.0-alpha.11", "license": "GPL-3.0-only", "dependencies": { - "@multiversx/sdk-core": "^13.14.1", + "@multiversx/sdk-core": "13.14.1", "bignumber.js": "9.1.2", "nft.storage": "7.2.0" }, diff --git a/package.json b/package.json index 5f1359b..5d647e2 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@itheum/sdk-mx-data-nft", - "version": "3.8.0-alpha.11", + "version": "3.8.0-alpha.12", "description": "SDK for Itheum's Data NFT Technology on MultiversX Blockchain", "main": "out/index.js", "types": "out/index.d.js", diff --git a/src/bond.ts b/src/bond.ts index f1e65a0..e4fccd1 100644 --- a/src/bond.ts +++ b/src/bond.ts @@ -7,7 +7,9 @@ import { IAddress, ResultsParser, StringValue, + Token, TokenIdentifierValue, + TokenTransfer, Transaction, TypedValue, U64Value, @@ -745,17 +747,14 @@ export class BondContract extends Contract { senderAddress: IAddress, newAdministrator: IAddress ): Transaction { - const setAdministratorTx = new Transaction({ - value: 0, - data: new ContractCallPayloadBuilder() - .setFunction('setAdministrator') - .addArg(new AddressValue(newAdministrator)) - .build(), - receiver: this.contract.getAddress(), - sender: senderAddress, - gasLimit: 10_000_000, - chainID: this.chainID - }); + const setAdministratorTx = + this.transactionFactory.createTransactionForExecute({ + function: 'setAdministrator', + arguments: [newAdministrator], + sender: senderAddress, + contract: this.contract.getAddress(), + gasLimit: 10_000_000n + }); return setAdministratorTx; } @@ -768,17 +767,14 @@ export class BondContract extends Contract { senderAddress: IAddress, address: IAddress ): Transaction { - const setTopUpAdministratorTx = new Transaction({ - value: 0, - data: new ContractCallPayloadBuilder() - .setFunction('setTopUpAdministrator') - .addArg(new AddressValue(address)) - .build(), - receiver: this.contract.getAddress(), - sender: senderAddress, - gasLimit: 10_000_000, - chainID: this.chainID - }); + const setTopUpAdministratorTx = + this.transactionFactory.createTransactionForExecute({ + function: 'setTopUpAdministrator', + arguments: [address], + sender: senderAddress, + contract: this.contract.getAddress(), + gasLimit: 10_000_000n + }); return setTopUpAdministratorTx; } @@ -797,33 +793,27 @@ export class BondContract extends Contract { penalty: PenaltyType, customPenalty?: number ): Transaction { - let data; + let sanctionTx; if (penalty === PenaltyType.Custom && customPenalty) { - data = new ContractCallPayloadBuilder() - .setFunction('sanction') - .addArg(new TokenIdentifierValue(tokenIdentifier)) - .addArg(new U64Value(nonce)) - .addArg(new U64Value(penalty)) - .addArg(new U64Value(customPenalty)) - .build(); + sanctionTx = this.transactionFactory.createTransactionForExecute({ + function: 'sanction', + arguments: [tokenIdentifier, nonce, penalty, customPenalty], + sender: senderAddress, + contract: this.contract.getAddress(), + gasLimit: 30_000_000n + }); + + return sanctionTx; } else { - data = new ContractCallPayloadBuilder() - .setFunction('sanction') - .addArg(new TokenIdentifierValue(tokenIdentifier)) - .addArg(new U64Value(nonce)) - .addArg(new U64Value(penalty)) - .build(); + sanctionTx = this.transactionFactory.createTransactionForExecute({ + function: 'sanction', + arguments: [tokenIdentifier, nonce, penalty], + sender: senderAddress, + contract: this.contract.getAddress(), + gasLimit: 30_000_000n + }); + return sanctionTx; } - - const sanctionTx = new Transaction({ - value: 0, - data, - receiver: this.contract.getAddress(), - sender: senderAddress, - gasLimit: 30_000_000, - chainID: this.chainID - }); - return sanctionTx; } /** @@ -837,18 +827,14 @@ export class BondContract extends Contract { tokenIdentifier: string, nonce: number ): Transaction { - const modifyBondTx = new Transaction({ - value: 0, - data: new ContractCallPayloadBuilder() - .setFunction('modifyBond') - .addArg(new TokenIdentifierValue(tokenIdentifier)) - .addArg(new U64Value(nonce)) - .build(), - receiver: this.contract.getAddress(), + const modifyBondTx = this.transactionFactory.createTransactionForExecute({ + function: 'modifyBond', + arguments: [tokenIdentifier, nonce], sender: senderAddress, - gasLimit: 10_000_000, - chainID: this.chainID + contract: this.contract.getAddress(), + gasLimit: 10_000_000n }); + return modifyBondTx; } @@ -858,25 +844,22 @@ export class BondContract extends Contract { * @param state state to set the contract to */ setContractState(senderAddress: IAddress, state: State): Transaction { - let data; + let setContractStateTx; if (state === State.Inactive) { - data = new ContractCallPayloadBuilder() - .setFunction('setContractStateInactive') - .build(); + setContractStateTx = this.transactionFactory.createTransactionForExecute({ + function: 'setContractStateInactive', + sender: senderAddress, + contract: this.contract.getAddress(), + gasLimit: 10_000_000n + }); } else { - data = new ContractCallPayloadBuilder() - .setFunction('setContractStateActive') - .build(); + setContractStateTx = this.transactionFactory.createTransactionForExecute({ + function: 'setContractStateActive', + sender: senderAddress, + contract: this.contract.getAddress(), + gasLimit: 10_000_000n + }); } - - const setContractStateTx = new Transaction({ - value: 0, - data: data, - receiver: this.contract.getAddress(), - sender: senderAddress, - gasLimit: 10_000_000, - chainID: this.chainID - }); return setContractStateTx; } @@ -889,18 +872,16 @@ export class BondContract extends Contract { const inputAddresses = addresses.map( (address) => new AddressValue(address) ); - const tx = new Transaction({ - value: 0, - data: new ContractCallPayloadBuilder() - .setFunction('setAcceptedCallers') - .setArgs(inputAddresses) - .build(), - receiver: this.contract.getAddress(), - sender: senderAddress, - gasLimit: 20_000_000, - chainID: this.chainID - }); - return tx; + const setAcceptedCallers = + this.transactionFactory.createTransactionForExecute({ + function: 'setAcceptedCallers', + arguments: inputAddresses, + sender: senderAddress, + contract: this.contract.getAddress(), + gasLimit: 20_000_000n + }); + + return setAcceptedCallers; } /** @@ -917,18 +898,16 @@ export class BondContract extends Contract { const inputAddresses = addresses.map( (address) => new AddressValue(address) ); - const tx = new Transaction({ - value: 0, - data: new ContractCallPayloadBuilder() - .setFunction('setBlacklist') - .setArgs([new U64Value(compensationId), ...inputAddresses]) - .build(), - receiver: this.contract.getAddress(), + + const setBlacklistTx = this.transactionFactory.createTransactionForExecute({ + function: 'setBlacklist', + arguments: [compensationId, ...inputAddresses], sender: senderAddress, - gasLimit: 20_000_000, - chainID: this.chainID + contract: this.contract.getAddress(), + gasLimit: 20_000_000n }); - return tx; + + return setBlacklistTx; } /** @@ -945,18 +924,16 @@ export class BondContract extends Contract { const toBeRemovedAddresses = addresses.map( (address) => new AddressValue(address) ); - const tx = new Transaction({ - value: 0, - data: new ContractCallPayloadBuilder() - .setFunction('removeBlacklist') - .setArgs([new U64Value(compensationId), ...toBeRemovedAddresses]) - .build(), - receiver: this.contract.getAddress(), - sender: senderAddress, - gasLimit: 20_000_000, - chainID: this.chainID - }); - return tx; + const removeBlacklistTx = + this.transactionFactory.createTransactionForExecute({ + function: 'removeBlacklist', + arguments: [compensationId, ...toBeRemovedAddresses], + sender: senderAddress, + contract: this.contract.getAddress(), + gasLimit: 20_000_000n + }); + + return removeBlacklistTx; } /** @@ -968,18 +945,17 @@ export class BondContract extends Contract { const inputAddresses = addresses.map( (address) => new AddressValue(address) ); - const tx = new Transaction({ - value: 0, - data: new ContractCallPayloadBuilder() - .setFunction('removeAcceptedCallers') - .setArgs(inputAddresses) - .build(), - receiver: this.contract.getAddress(), - sender: senderAddress, - gasLimit: 20_000_000, - chainID: this.chainID - }); - return tx; + + const removeAcceptedCallersTx = + this.transactionFactory.createTransactionForExecute({ + function: 'removeAcceptedCallers', + arguments: inputAddresses, + sender: senderAddress, + contract: this.contract.getAddress(), + gasLimit: 20_000_000n + }); + + return removeAcceptedCallersTx; } /** @@ -991,18 +967,15 @@ export class BondContract extends Contract { senderAddress: IAddress, tokenIdentifier = itheumTokenIdentifier[this.env as EnvironmentsEnum] ) { - const tx = new Transaction({ - value: 0, - data: new ContractCallPayloadBuilder() - .setFunction('setBondToken') - .addArg(new TokenIdentifierValue(tokenIdentifier)) - .build(), - receiver: this.contract.getAddress(), + const setBondTokenTx = this.transactionFactory.createTransactionForExecute({ + function: 'setBondToken', + arguments: [tokenIdentifier], sender: senderAddress, - gasLimit: 20_000_000, - chainID: this.chainID + contract: this.contract.getAddress(), + gasLimit: 20_000_000n }); - return tx; + + return setBondTokenTx; } /** @@ -1018,20 +991,15 @@ export class BondContract extends Contract { tokenIdentifier: string, nonce: number ): Transaction { - const tx = new Transaction({ - value: 0, - data: new ContractCallPayloadBuilder() - .setFunction('initiateBond') - .addArg(new AddressValue(address)) - .addArg(new TokenIdentifierValue(tokenIdentifier)) - .addArg(new U64Value(nonce)) - .build(), - receiver: this.contract.getAddress(), + const initiateBondTx = this.transactionFactory.createTransactionForExecute({ + function: 'initiateBond', + arguments: [address, tokenIdentifier, nonce], sender: senderAddress, - gasLimit: 20_000_000, - chainID: this.chainID + contract: this.contract.getAddress(), + gasLimit: 20_000_000n }); - return tx; + + return initiateBondTx; } /** @@ -1053,18 +1021,16 @@ export class BondContract extends Contract { combinedArray.push(new BigUIntValue(lockPeriodWithBond.amount)); }); - const tx = new Transaction({ - value: 0, - data: new ContractCallPayloadBuilder() - .setFunction('addPeriodsBonds') - .setArgs(combinedArray) - .build(), - receiver: this.contract.getAddress(), - sender: senderAddress, - gasLimit: 20_000_000, - chainID: this.chainID - }); - return tx; + const addPeriodsBondsTx = + this.transactionFactory.createTransactionForExecute({ + function: 'addPeriodsBonds', + arguments: combinedArray, + sender: senderAddress, + contract: this.contract.getAddress(), + gasLimit: 20_000_000n + }); + + return addPeriodsBondsTx; } /** @@ -1075,17 +1041,15 @@ export class BondContract extends Contract { removePeriodsBonds(senderAddress: IAddress, periods: number[]) { const inputPeriods = periods.map((period) => new U64Value(period)); - const removePeriodsBondsTx = new Transaction({ - value: 0, - data: new ContractCallPayloadBuilder() - .setFunction('removePeriodsBonds') - .setArgs(inputPeriods) - .build(), - receiver: this.contract.getAddress(), - sender: senderAddress, - gasLimit: 20_000_000, - chainID: this.chainID - }); + const removePeriodsBondsTx = + this.transactionFactory.createTransactionForExecute({ + function: 'removePeriodsBonds', + arguments: inputPeriods, + sender: senderAddress, + contract: this.contract.getAddress(), + gasLimit: 20_000_000n + }); + return removePeriodsBondsTx; } @@ -1095,18 +1059,16 @@ export class BondContract extends Contract { * @param penalty the minimum penalty value to be set */ setMinimumPenalty(senderAddress: IAddress, penalty: number) { - const tx = new Transaction({ - value: 0, - data: new ContractCallPayloadBuilder() - .setFunction('setMinimumPenalty') - .addArg(new U64Value(penalty)) - .build(), - receiver: this.contract.getAddress(), - sender: senderAddress, - gasLimit: 20_000_000, - chainID: this.chainID - }); - return tx; + const setMinimumPenaltyTx = + this.transactionFactory.createTransactionForExecute({ + function: 'setMinimumPenalty', + arguments: [penalty], + sender: senderAddress, + contract: this.contract.getAddress(), + gasLimit: 20_000_000n + }); + + return setMinimumPenaltyTx; } /** @@ -1115,18 +1077,16 @@ export class BondContract extends Contract { * @param penalty the maximum penalty value to be set */ setMaximumPenalty(senderAddress: IAddress, penalty: number) { - const tx = new Transaction({ - value: 0, - data: new ContractCallPayloadBuilder() - .setFunction('setMaximumPenalty') - .addArg(new U64Value(penalty)) - .build(), - receiver: this.contract.getAddress(), - sender: senderAddress, - gasLimit: 20_000_000, - chainID: this.chainID - }); - return tx; + const setMaximumPenaltyTx = + this.transactionFactory.createTransactionForExecute({ + function: 'setMaximumPenalty', + arguments: [penalty], + sender: senderAddress, + contract: this.contract.getAddress(), + gasLimit: 20_000_000n + }); + + return setMaximumPenaltyTx; } /** @@ -1135,18 +1095,16 @@ export class BondContract extends Contract { * @param penalty the withdraw penalty value to be set */ setWithdrawPenalty(senderAddress: IAddress, penalty: number) { - const tx = new Transaction({ - value: 0, - data: new ContractCallPayloadBuilder() - .setFunction('setWithdrawPenalty') - .addArg(new U64Value(penalty)) - .build(), - receiver: this.contract.getAddress(), - sender: senderAddress, - gasLimit: 20_000_000, - chainID: this.chainID - }); - return tx; + const setWithdrawPenaltyTx = + this.transactionFactory.createTransactionForExecute({ + function: 'setWithdrawPenalty', + arguments: [penalty], + sender: senderAddress, + contract: this.contract.getAddress(), + gasLimit: 20_000_000n + }); + + return setWithdrawPenaltyTx; } /** @@ -1162,19 +1120,14 @@ export class BondContract extends Contract { nonce: number, timestamp: number ) { - const refundTx = new Transaction({ - value: 0, - data: new ContractCallPayloadBuilder() - .setFunction('initiateRefund') - .addArg(new TokenIdentifierValue(tokenIdentifier)) - .addArg(new U64Value(nonce)) - .addArg(new U64Value(timestamp)) - .build(), - receiver: this.contract.getAddress(), + const refundTx = this.transactionFactory.createTransactionForExecute({ + function: 'initiateRefund', + arguments: [tokenIdentifier, nonce, timestamp], sender: senderAddress, - gasLimit: 20_000_000, - chainID: this.chainID + contract: this.contract.getAddress(), + gasLimit: 20_000_000n }); + return refundTx; } @@ -1198,24 +1151,21 @@ export class BondContract extends Contract { amount: BigNumber.Value; } ): Transaction { - const bondTx = new Transaction({ - value: 0, - data: new ContractCallPayloadBuilder() - .setFunction(new ContractFunction('ESDTTransfer')) - .addArg(new TokenIdentifierValue(payment.tokenIdentifier)) - .addArg(new BigUIntValue(payment.amount)) - .addArg(new StringValue('bond')) - .addArg(new AddressValue(originalCaller)) - .addArg(new TokenIdentifierValue(tokenIdentifier)) - .addArg(new U64Value(nonce)) - .addArg(new U64Value(lockPeriod)) - .build(), - receiver: this.contract.getAddress(), + const bondWithESDTTx = this.transactionFactory.createTransactionForExecute({ + function: 'bond', + arguments: [originalCaller, tokenIdentifier, nonce, lockPeriod], sender: senderAddress, - gasLimit: 40_000_000, - chainID: this.chainID + contract: this.contract.getAddress(), + gasLimit: 40_000_000n, + tokenTransfers: [ + new TokenTransfer({ + token: new Token({ identifier: payment.tokenIdentifier }), + amount: BigInt(payment.amount.toString()) + }) + ] }); - return bondTx; + + return bondWithESDTTx; } /** @@ -1234,22 +1184,22 @@ export class BondContract extends Contract { nonce: number, tokenIdentifier = dataNftTokenIdentifier[this.env as EnvironmentsEnum] ): Transaction { - const topUpVaultTx = new Transaction({ - value: 0, - data: new ContractCallPayloadBuilder() - .setFunction(new ContractFunction('ESDTTransfer')) - .addArg(new TokenIdentifierValue(payment.tokenIdentifier)) - .addArg(new BigUIntValue(payment.amount)) - .addArg(new StringValue('topUpVault')) - .addArg(new TokenIdentifierValue(tokenIdentifier)) - .addArg(new U64Value(nonce)) - .build(), - receiver: this.contract.getAddress(), - sender: senderAddress, - gasLimit: 40_000_000, - chainID: this.chainID - }); - return topUpVaultTx; + const topUpVaultWithEsdtTx = + this.transactionFactory.createTransactionForExecute({ + function: 'topUpVault', + arguments: [tokenIdentifier, nonce], + sender: senderAddress, + contract: this.contract.getAddress(), + gasLimit: 40_000_000n, + tokenTransfers: [ + new TokenTransfer({ + token: new Token({ identifier: payment.tokenIdentifier }), + amount: BigInt(payment.amount.toString()) + }) + ] + }); + + return topUpVaultWithEsdtTx; } /** * Builds a `topUpAddressVault` transaction @@ -1269,134 +1219,22 @@ export class BondContract extends Contract { nonce: number, tokenIdentifier = dataNftTokenIdentifier[this.env as EnvironmentsEnum] ): Transaction { - const topUpVaultTx = new Transaction({ - value: 0, - data: new ContractCallPayloadBuilder() - .setFunction(new ContractFunction('ESDTTransfer')) - .addArg(new TokenIdentifierValue(payment.tokenIdentifier)) - .addArg(new BigUIntValue(payment.amount)) - .addArg(new StringValue('topUpVault')) - .addArg(new AddressValue(address)) - .addArg(new TokenIdentifierValue(tokenIdentifier)) - .addArg(new U64Value(nonce)) - .build(), - receiver: this.contract.getAddress(), + const topUpVaultTx = this.transactionFactory.createTransactionForExecute({ + function: 'topUpVault', + arguments: [address, tokenIdentifier, nonce], sender: senderAddress, - gasLimit: 80_000_000, - chainID: this.chainID + contract: this.contract.getAddress(), + gasLimit: 80_000_000n, + tokenTransfers: [ + new TokenTransfer({ + token: new Token({ identifier: payment.tokenIdentifier }), + amount: BigInt(payment.amount.toString()) + }) + ] }); return topUpVaultTx; } - /** - * Builds a `bond` transaction with NFT/SFT transfer - * @param senderAddress the address of the sender - * @param originalCaller the address of the original caller - * @param tokenIdentifier the token identifier of the NFT/SFT - * @param nonce the token identifier nonce - * @param lockPeriod the lock period for the bond - * @param payment the payment for the bond (tokenIdentifier, nonce and amount) - */ - bondWithNFT( - senderAddress: IAddress, - originalCaller: IAddress, - tokenIdentifier: string, - nonce: number, - lockPeriod: number, - payment: { - tokenIdentifier: string; - nonce: number; - amount: BigNumber.Value; - } - ): Transaction { - const bondTx = new Transaction({ - value: 0, - data: new ContractCallPayloadBuilder() - .setFunction(new ContractFunction('ESDTNFTTransfer')) - .addArg(new TokenIdentifierValue(payment.tokenIdentifier)) - .addArg(new U64Value(payment.nonce)) - .addArg(new BigUIntValue(payment.amount)) - .addArg(new AddressValue(this.contract.getAddress())) - .addArg(new StringValue('bond')) - .addArg(new AddressValue(originalCaller)) - .addArg(new TokenIdentifierValue(tokenIdentifier)) - .addArg(new U64Value(nonce)) - .addArg(new U64Value(lockPeriod)) - .build(), - receiver: senderAddress, - sender: senderAddress, - gasLimit: 40_000_000, - chainID: this.chainID - }); - return bondTx; - } - - /** - * Builds a `bond` transaction with EGLD transfer - * @param senderAddress the address of the sender - * @param originalCaller the address of the original caller - * @param tokenIdentifier the token identifier of the NFT/SFT - * @param nonce the token identifier nonce - * @param lockPeriod the lock period for the bond - * @param payment the payment for the bond (tokenIdentifier, nonce and amount) - */ - bondWithEGLD( - senderAddress: IAddress, - originalCaller: IAddress, - tokenIdentifier: string, - nonce: number, - lockPeriod: number, - payment: BigNumber.Value - ): Transaction { - const bondTx = new Transaction({ - value: payment, - data: new ContractCallPayloadBuilder() - .setFunction('bond') - .addArg(new AddressValue(originalCaller)) - .addArg(new TokenIdentifierValue(tokenIdentifier)) - .addArg(new U64Value(nonce)) - .addArg(new U64Value(lockPeriod)) - .build(), - receiver: this.contract.getAddress(), - sender: senderAddress, - gasLimit: 40_000_000, - chainID: this.chainID - }); - return bondTx; - } - - /** - * Builds a `bond` transaction with no payment - * @param senderAddress the address of the sender - * @param originalCaller the address of the original caller - * @param tokenIdentifier the token identifier of the NFT/SFT - * @param nonce the token identifier nonce - * @param lockPeriod the lock period for the bond - */ - bondWithNoPayment( - senderAddress: IAddress, - originalCaller: IAddress, - tokenIdentifier: string, - nonce: number, - lockPeriod: number - ): Transaction { - const bondTx = new Transaction({ - value: 0, - data: new ContractCallPayloadBuilder() - .setFunction('bond') - .addArg(new AddressValue(originalCaller)) - .addArg(new TokenIdentifierValue(tokenIdentifier)) - .addArg(new U64Value(nonce)) - .addArg(new U64Value(lockPeriod)) - .build(), - receiver: this.contract.getAddress(), - sender: senderAddress, - gasLimit: 40_000_000, - chainID: this.chainID - }); - return bondTx; - } - /** * Builds a `withdraw` transaction * @param senderAddress address of the sender @@ -1408,18 +1246,14 @@ export class BondContract extends Contract { tokenIdentifier: string, nonce: number ): Transaction { - const withdrawTx = new Transaction({ - value: 0, - data: new ContractCallPayloadBuilder() - .setFunction('withdraw') - .addArg(new TokenIdentifierValue(tokenIdentifier)) - .addArg(new U64Value(nonce)) - .build(), - receiver: this.contract.getAddress(), + const withdrawTx = this.transactionFactory.createTransactionForExecute({ + function: 'withdraw', + arguments: [tokenIdentifier, nonce], sender: senderAddress, - gasLimit: 50_000_000, - chainID: this.chainID + contract: this.contract.getAddress(), + gasLimit: 50_000_000n }); + return withdrawTx; } @@ -1435,20 +1269,14 @@ export class BondContract extends Contract { tokenIdentifier: string, nonce: number ): Transaction { - const data = new ContractCallPayloadBuilder() - .setFunction('renew') - .addArg(new TokenIdentifierValue(tokenIdentifier)) - .addArg(new U64Value(nonce)) - .build(); - - const renewTx = new Transaction({ - value: 0, - data, - receiver: this.contract.getAddress(), + const renewTx = this.transactionFactory.createTransactionForExecute({ + function: 'renew', + arguments: [tokenIdentifier, nonce], sender: senderAddress, - gasLimit: 10_000_000, - chainID: this.chainID + contract: this.contract.getAddress(), + gasLimit: 10_000_000n }); + return renewTx; } @@ -1463,19 +1291,17 @@ export class BondContract extends Contract { nonce: number, tokenIdentifier = dataNftTokenIdentifier[this.env as EnvironmentsEnum] ): Transaction { - const tx = new Transaction({ - value: 0, - data: new ContractCallPayloadBuilder() - .setFunction('setVaultNonce') - .addArg(new TokenIdentifierValue(tokenIdentifier)) - .addArg(new U64Value(nonce)) - .build(), - receiver: this.contract.getAddress(), - sender: senderAddress, - gasLimit: 20_000_000, - chainID: this.chainID - }); - return tx; + const setVaultNonceTx = this.transactionFactory.createTransactionForExecute( + { + function: 'setVaultNonce', + arguments: [tokenIdentifier, nonce], + sender: senderAddress, + contract: this.contract.getAddress(), + gasLimit: 20_000_000n + } + ); + + return setVaultNonceTx; } /** @@ -1488,23 +1314,23 @@ export class BondContract extends Contract { senderAddress: IAddress, payment: { tokenIdentifier: string; nonce: number; amount: BigNumber.Value } ): Transaction { - const data = new ContractCallPayloadBuilder() - .setFunction(new ContractFunction('ESDTNFTTransfer')) - .addArg(new TokenIdentifierValue(payment.tokenIdentifier)) - .addArg(new U64Value(payment.nonce)) - .addArg(new BigUIntValue(payment.amount)) - .addArg(new AddressValue(this.contract.getAddress())) - .addArg(new StringValue('proof')) - .build(); - - const proofTx = new Transaction({ - value: 0, - data, - receiver: senderAddress, + const proofTx = this.transactionFactory.createTransactionForExecute({ + function: 'proof', + arguments: [], sender: senderAddress, - gasLimit: 40_000_000, - chainID: this.chainID + contract: this.contract.getAddress(), + gasLimit: 40_000_000n, + tokenTransfers: [ + new TokenTransfer({ + token: new Token({ + identifier: payment.tokenIdentifier, + nonce: BigInt(payment.nonce) + }), + amount: BigInt(payment.amount.toString()) + }) + ] }); + return proofTx; } @@ -1519,20 +1345,14 @@ export class BondContract extends Contract { tokenIdentifier: string, nonce: number ): Transaction { - const data = new ContractCallPayloadBuilder() - .setFunction('claimRefund') - .addArg(new TokenIdentifierValue(tokenIdentifier)) - .addArg(new U64Value(nonce)) - .build(); - - const claimRefundTx = new Transaction({ - value: 0, - data, - receiver: this.contract.getAddress(), + const claimRefundTx = this.transactionFactory.createTransactionForExecute({ + function: 'claimRefund', + arguments: [tokenIdentifier, nonce], sender: senderAddress, - gasLimit: 10_000_000, - chainID: this.chainID + contract: this.contract.getAddress(), + gasLimit: 10_000_000n }); + return claimRefundTx; } } diff --git a/src/contract.ts b/src/contract.ts index 4fdad4a..12db7a7 100644 --- a/src/contract.ts +++ b/src/contract.ts @@ -2,7 +2,9 @@ import { AbiRegistry, IAddress, SmartContract, - ApiNetworkProvider + ApiNetworkProvider, + SmartContractTransactionsFactory, + TransactionsFactoryConfig } from '@multiversx/sdk-core/out'; import { EnvironmentsEnum, networkConfiguration } from './config'; import { ErrContractAddressNotSet, ErrNetworkConfig } from './errors'; @@ -10,6 +12,7 @@ import { ErrContractAddressNotSet, ErrNetworkConfig } from './errors'; export abstract class Contract { readonly contract: SmartContract; readonly chainID: string; + readonly transactionFactory: SmartContractTransactionsFactory; readonly networkProvider: ApiNetworkProvider; readonly env: string; @@ -38,6 +41,12 @@ export abstract class Contract { clientName: 'ithuemDataNftSDK' } ); + + this.transactionFactory = new SmartContractTransactionsFactory({ + config: new TransactionsFactoryConfig({ chainID: this.chainID }), + abi: AbiRegistry.create(abiFile) + }); + this.contract = new SmartContract({ address: contractAddress, abi: AbiRegistry.create(abiFile) From c6efc7e5d9834915f07f6a47cd4c4d10e390ee08 Mon Sep 17 00:00:00 2001 From: bucurdavid Date: Mon, 11 Nov 2024 17:04:28 +0200 Subject: [PATCH 2/7] feat: support custm url provider --- src/contract.ts | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/contract.ts b/src/contract.ts index 12db7a7..c5fb8f2 100644 --- a/src/contract.ts +++ b/src/contract.ts @@ -20,7 +20,8 @@ export abstract class Contract { env: string, contractAddress: IAddress, abiFile: any, - timeout: number = 20000 + timeout: number = 20000, + customNetworkProviderUrl?: string ) { if (!(env in EnvironmentsEnum)) { throw new ErrNetworkConfig( @@ -35,7 +36,7 @@ export abstract class Contract { const networkConfig = networkConfiguration[env as EnvironmentsEnum]; this.chainID = networkConfig.chainID; this.networkProvider = new ApiNetworkProvider( - networkConfig.networkProvider, + customNetworkProviderUrl ?? networkConfig.networkProvider, { timeout: timeout, clientName: 'ithuemDataNftSDK' From d4e641ba85c785112f18b094e8aa72c1b97e3186 Mon Sep 17 00:00:00 2001 From: bucurdavid Date: Mon, 11 Nov 2024 17:04:59 +0200 Subject: [PATCH 3/7] refactor: remove redundant static param --- src/datanft.ts | 39 +++++++-------------------------------- tests/datanft.test.ts | 2 +- 2 files changed, 8 insertions(+), 33 deletions(-) diff --git a/src/datanft.ts b/src/datanft.ts index 7ecfb08..fb6440b 100644 --- a/src/datanft.ts +++ b/src/datanft.ts @@ -70,7 +70,6 @@ export class DataNft implements DataNftType { }[] = []; static networkConfiguration: Config; - static apiConfiguration: string; static env: string; /** @@ -108,34 +107,10 @@ export class DataNft implements DataNftType { } this.env = env; this.networkConfiguration = networkConfiguration[env as EnvironmentsEnum]; - this.apiConfiguration = apiConfiguration[env as EnvironmentsEnum]; - - console.log( - 'SDK debug: setNetworkConfig this.apiConfiguration B4 =', - this.apiConfiguration - ); - console.log( - 'SDK debug: setNetworkConfig this.networkConfiguration B4 =', - this.networkConfiguration - ); if (useSpecificApiEndpoint && useSpecificApiEndpoint.trim() !== '') { - this.apiConfiguration = useSpecificApiEndpoint.trim(); this.networkConfiguration.networkProvider = useSpecificApiEndpoint.trim(); } - - console.log( - 'SDK debug: setNetworkConfig useSpecificApiEndpoint A8 =', - useSpecificApiEndpoint - ); - console.log( - 'SDK debug: setNetworkConfig this.apiConfiguration A8 =', - this.apiConfiguration - ); - console.log( - 'SDK debug: setNetworkConfig this.networkConfiguration A8 =', - this.networkConfiguration - ); } /** @@ -156,7 +131,9 @@ export class DataNft implements DataNftType { token.nonce ); - const response = await fetch(`${this.apiConfiguration}/nfts/${identifier}`); + const response = await fetch( + `${this.networkConfiguration.networkProvider}/nfts/${identifier}` + ); checkStatus(response); @@ -199,10 +176,8 @@ export class DataNft implements DataNftType { return []; } - console.log('SDK debug: createManyFromApi api =', this.apiConfiguration); - const fetchUrl = `${ - this.apiConfiguration + this.networkConfiguration.networkProvider }/nfts?identifiers=${identifiers.join(',')}&withSupply=true&size=${ identifiers.length }`; @@ -304,7 +279,7 @@ export class DataNft implements DataNftType { dataNftTokenIdentifier[this.env as EnvironmentsEnum]; const res = await fetch( - `${this.apiConfiguration}/accounts/${address}/nfts?size=10000&collections=${identifiersMap}&withSupply=true` + `${this.networkConfiguration.networkProvider}/accounts/${address}/nfts?size=10000&collections=${identifiersMap}&withSupply=true` ); checkStatus(res); @@ -325,7 +300,7 @@ export class DataNft implements DataNftType { const identifier = createTokenIdentifier(this.tokenIdentifier, this.nonce); const response = await fetch( - `${DataNft.apiConfiguration}/nfts/${identifier}/accounts` + `${DataNft.networkConfiguration.networkProvider}/nfts/${identifier}/accounts` ); checkStatus(response); @@ -711,7 +686,7 @@ export class DataNft implements DataNftType { } private static ensureNetworkConfigSet() { - if (!this.env || !this.apiConfiguration) { + if (!this.env || !this.networkConfiguration) { throw new ErrNetworkConfig(); } } diff --git a/tests/datanft.test.ts b/tests/datanft.test.ts index fc4226b..f9babd1 100644 --- a/tests/datanft.test.ts +++ b/tests/datanft.test.ts @@ -86,7 +86,7 @@ describe('Data NFT test', () => { for (const item of dataNfts) { expect(item).toBeInstanceOf(Object as unknown as DataNft); } - }); + }, 10000); test('#create many data NFTs different token identifiers', async () => { DataNft.setNetworkConfig('devnet'); From 4b36a47aa98de1eabf6285defc76170bd80e78ea Mon Sep 17 00:00:00 2001 From: bucurdavid Date: Mon, 11 Nov 2024 17:55:14 +0200 Subject: [PATCH 4/7] feat: upgrade mvx transaction builder --- src/liveliness-stake.ts | 45 ++--- src/marketplace.ts | 244 ++++++++++++--------------- src/minter.ts | 364 ++++++++++++++++++---------------------- src/nft-minter.ts | 287 ++++++++++++++++--------------- src/sft-minter.ts | 168 +++++++++---------- 5 files changed, 520 insertions(+), 588 deletions(-) diff --git a/src/liveliness-stake.ts b/src/liveliness-stake.ts index 56fb9e7..d05f50d 100644 --- a/src/liveliness-stake.ts +++ b/src/liveliness-stake.ts @@ -30,15 +30,25 @@ import { parseUserData } from './common/utils'; import BigNumber from 'bignumber.js'; -import { Token } from 'nft.storage'; export class LivelinessStake extends Contract { - constructor(env: string, timeout: number = 20000) { + /** + * Creates a new instance of the LivelinessStake which can be used to interact with the liveliness staking smart contract + * @param env 'devnet' | 'mainnet' | 'testnet' + * @param timeout Timeout for the network provider (DEFAULT = 20000ms) + * @param customNetworkProviderUrl Custom network provider URL + */ + constructor( + env: string, + timeout: number = 20000, + customNetworkProviderUrl?: string + ) { super( env, new Address(livelinessStakeContractAddress[env as EnvironmentsEnum]), livelinessStakeAbi, - timeout + timeout, + customNetworkProviderUrl ); } @@ -197,16 +207,14 @@ export class LivelinessStake extends Contract { * @returns */ claimRewards(senderAddress: IAddress): Transaction { - const claimRewardsTx = new Transaction({ - value: 0, - data: new ContractCallPayloadBuilder() - .setFunction('claimRewards') - .build(), - receiver: this.contract.getAddress(), + const claimRewardsTx = this.transactionFactory.createTransactionForExecute({ + function: 'claimRewards', + arguments: [], sender: senderAddress, - gasLimit: 50_000_000, - chainID: this.chainID + contract: this.contract.getAddress(), + gasLimit: 50_000_000n }); + return claimRewardsTx; } @@ -219,17 +227,14 @@ export class LivelinessStake extends Contract { senderAddress: IAddress, tokenIdentifier = dataNftTokenIdentifier[this.env as EnvironmentsEnum] ): Transaction { - const stakeRewardsTx = new Transaction({ - value: 0, - data: new ContractCallPayloadBuilder() - .setFunction('stakeRewards') - .addArg(new TokenIdentifierValue(tokenIdentifier)) - .build(), - receiver: this.contract.getAddress(), + const stakeRewardsTx = this.transactionFactory.createTransactionForExecute({ + function: 'stakeRewards', + arguments: [tokenIdentifier], sender: senderAddress, - gasLimit: 90_000_000, - chainID: this.chainID + contract: this.contract.getAddress(), + gasLimit: 90_000_000n }); + return stakeRewardsTx; } } diff --git a/src/marketplace.ts b/src/marketplace.ts index fb9d627..c6b6019 100644 --- a/src/marketplace.ts +++ b/src/marketplace.ts @@ -15,7 +15,9 @@ import { U64Value, U8Value, VariadicValue, - ApiNetworkProvider + ApiNetworkProvider, + TokenTransfer, + Token } from '@multiversx/sdk-core/out'; import dataMarketAbi from './abis/data_market.abi.json'; import { parseOffer } from './common/utils'; @@ -28,41 +30,28 @@ import { import { ErrContractQuery, ErrNetworkConfig } from './errors'; import { MarketplaceRequirements, Offer } from './interfaces'; import BigNumber from 'bignumber.js'; +import { Contract } from './contract'; // import { ErrContractQuery } from './errors'; -export class DataNftMarket { - readonly contract: SmartContract; - readonly chainID: string; - readonly networkProvider: ApiNetworkProvider; - readonly env: string; - +export class DataNftMarket extends Contract { /** * Creates a new instance of the DataNftMarket which can be used to interact with the marketplace smart contract * @param env 'devnet' | 'mainnet' | 'testnet' * @param timeout Timeout for the network provider (DEFAULT = 20000ms) + * @param customNetworkProviderUrl Custom network provider URL */ - constructor(env: string, timeout: number = 20000) { - if (!(env in EnvironmentsEnum)) { - throw new ErrNetworkConfig( - `Invalid environment: ${env}, Expected: 'devnet' | 'mainnet' | 'testnet'` - ); - } - this.env = env; - const networkConfig = networkConfiguration[env as EnvironmentsEnum]; - this.chainID = networkConfig.chainID; - this.networkProvider = new ApiNetworkProvider( - networkConfig.networkProvider, - { - timeout: timeout, - clientName: 'ithuemDataNftSDK' - } + constructor( + env: string, + timeout: number = 20000, + customNetworkProviderUrl?: string + ) { + super( + env, + new Address(marketPlaceContractAddress[env as EnvironmentsEnum]), + dataMarketAbi, + timeout, + customNetworkProviderUrl ); - const contractAddress = marketPlaceContractAddress[env as EnvironmentsEnum]; - - this.contract = new SmartContract({ - address: new Address(contractAddress), - abi: AbiRegistry.create(dataMarketAbi) - }); } /** @@ -403,26 +392,28 @@ export class DataNftMarket { minimumPaymentTokenAmount = 0, maxQuantity: BigNumber.Value ): Transaction { - const addOfferTx = new Transaction({ - value: 0, - data: new ContractCallPayloadBuilder() - .setFunction(new ContractFunction('ESDTNFTTransfer')) - .addArg(new TokenIdentifierValue(dataNftIdentifier)) - .addArg(new U64Value(dataNftNonce)) - .addArg(new BigUIntValue(dataNftAmount)) - .addArg(new AddressValue(this.contract.getAddress())) - .addArg(new StringValue('addOffer')) - .addArg(new TokenIdentifierValue(paymentTokenIdentifier)) - .addArg(new U64Value(paymentTokenNonce)) - .addArg(new U64Value(paymentTokenAmount)) - .addArg(new U64Value(minimumPaymentTokenAmount)) - .addArg(new BigUIntValue(dataNftAmount)) - .addArg(new BigUIntValue(maxQuantity)) - .build(), - receiver: senderAddress, + const addOfferTx = this.transactionFactory.createTransactionForExecute({ + function: 'addOffer', + arguments: [ + paymentTokenIdentifier, + paymentTokenNonce, + paymentTokenAmount, + minimumPaymentTokenAmount, + dataNftAmount, + maxQuantity + ], sender: senderAddress, - gasLimit: 12000000, - chainID: this.chainID + contract: this.contract.getAddress(), + gasLimit: 12000000n, + tokenTransfers: [ + new TokenTransfer({ + token: new Token({ + identifier: dataNftIdentifier, + nonce: BigInt(dataNftNonce) + }), + amount: BigInt(dataNftAmount.toString()) + }) + ] }); return addOfferTx; @@ -443,25 +434,24 @@ export class DataNftMarket { price: BigNumber.Value, paymentTokenIdentifier = itheumTokenIdentifier[this.env as EnvironmentsEnum] ): Transaction { - const data = new ContractCallPayloadBuilder() - .setFunction(new ContractFunction('ESDTTransfer')) - .addArg(new TokenIdentifierValue(paymentTokenIdentifier)) - .addArg(new BigUIntValue(price)) - .addArg(new StringValue('acceptOffer')) - .addArg(new U64Value(offerId)) - .addArg(new BigUIntValue(amount)) - .build(); - - const acceptTx = new Transaction({ - value: 0, - data: data, - receiver: this.contract.getAddress(), - gasLimit: 20_000_000, + const acceptOfferTx = this.transactionFactory.createTransactionForExecute({ + function: 'acceptOffer', + arguments: [offerId, amount], sender: senderAddress, - chainID: this.chainID + contract: this.contract.getAddress(), + gasLimit: 12000000n, + tokenTransfers: [ + new TokenTransfer({ + token: new Token({ + identifier: paymentTokenIdentifier, + nonce: BigInt(0) + }), + amount: BigInt(price.toString()) + }) + ] }); - return acceptTx; + return acceptOfferTx; } /** @@ -482,24 +472,24 @@ export class DataNftMarket { nonce: number, paymentAmount: BigNumber.Value ): Transaction { - const offerEsdtTx = new Transaction({ - value: 0, - data: new ContractCallPayloadBuilder() - .setFunction(new ContractFunction('ESDTNFTTransfer')) - .addArg(new TokenIdentifierValue(tokenIdentifier)) - .addArg(new U64Value(nonce)) - .addArg(new BigUIntValue(paymentAmount)) - .addArg(new AddressValue(this.contract.getAddress())) - .addArg(new StringValue('acceptOffer')) - .addArg(new U64Value(offerId)) - .addArg(new BigUIntValue(amount)) - .build(), - receiver: senderAddress, + const acceptOfferTx = this.transactionFactory.createTransactionForExecute({ + function: 'acceptOffer', + arguments: [offerId, amount], sender: senderAddress, - gasLimit: 20_000_000, - chainID: this.chainID + contract: this.contract.getAddress(), + gasLimit: 12000000n, + tokenTransfers: [ + new TokenTransfer({ + token: new Token({ + identifier: tokenIdentifier, + nonce: BigInt(nonce) + }), + amount: BigInt(paymentAmount.toString()) + }) + ] }); - return offerEsdtTx; + + return acceptOfferTx; } /** @@ -515,22 +505,16 @@ export class DataNftMarket { amount: BigNumber.Value, price: BigNumber.Value ): Transaction { - const data = new ContractCallPayloadBuilder() - .setFunction(new ContractFunction('acceptOffer')) - .addArg(new U64Value(offerId)) - .addArg(new BigUIntValue(amount)) - .build(); - - const acceptTx = new Transaction({ - value: price, - data: data, - receiver: this.contract.getAddress(), - gasLimit: 20_000_000, + const acceptOfferTx = this.transactionFactory.createTransactionForExecute({ + function: 'acceptOffer', + arguments: [offerId, amount], sender: senderAddress, - chainID: this.chainID + contract: this.contract.getAddress(), + gasLimit: 12000000n, + nativeTransferAmount: BigInt(price.toString()) }); - return acceptTx; + return acceptOfferTx; } /** @@ -544,22 +528,15 @@ export class DataNftMarket { offerId: number, amount: BigNumber.Value ): Transaction { - const data = new ContractCallPayloadBuilder() - .setFunction(new ContractFunction('acceptOffer')) - .addArg(new U64Value(offerId)) - .addArg(new BigUIntValue(amount)) - .build(); - - const acceptTx = new Transaction({ - value: 0, - data: data, - receiver: this.contract.getAddress(), - gasLimit: 12000000, + const acceptOfferTx = this.transactionFactory.createTransactionForExecute({ + function: 'acceptOffer', + arguments: [offerId, amount], sender: senderAddress, - chainID: this.chainID + contract: this.contract.getAddress(), + gasLimit: 12000000n }); - return acceptTx; + return acceptOfferTx; } /** @@ -575,21 +552,15 @@ export class DataNftMarket { quantity: number, sendFundsBackToOwner = true ): Transaction { - const cancelTx = new Transaction({ - value: 0, - data: new ContractCallPayloadBuilder() - .setFunction(new ContractFunction('cancelOffer')) - .addArg(new U64Value(offerId)) - .addArg(new U64Value(quantity)) - .addArg(new BooleanValue(sendFundsBackToOwner)) - .build(), - receiver: this.contract.getAddress(), - gasLimit: 10000000, + const cancelOfferTx = this.transactionFactory.createTransactionForExecute({ + function: 'cancelOffer', + arguments: [offerId, quantity, sendFundsBackToOwner], sender: senderAddress, - chainID: this.chainID + contract: this.contract.getAddress(), + gasLimit: 10000000n }); - return cancelTx; + return cancelOfferTx; } /** @@ -605,21 +576,16 @@ export class DataNftMarket { newPrice: BigNumber.Value, newMinimumPaymentTokenAmount = 0 ): Transaction { - const changePriceTx = new Transaction({ - value: 0, - data: new ContractCallPayloadBuilder() - .setFunction(new ContractFunction('changeOfferPrice')) - .addArg(new U64Value(offerId)) - .addArg(new U64Value(newPrice)) - .addArg(new U64Value(newMinimumPaymentTokenAmount)) - .build(), - receiver: this.contract.getAddress(), - gasLimit: 10000000, - sender: senderAddress, - chainID: this.chainID - }); - - return changePriceTx; + const changeOfferPrice = + this.transactionFactory.createTransactionForExecute({ + function: 'changeOfferPrice', + arguments: [offerId, newPrice, newMinimumPaymentTokenAmount], + sender: senderAddress, + contract: this.contract.getAddress(), + gasLimit: 10000000n + }); + + return changeOfferPrice; } /** @@ -633,16 +599,12 @@ export class DataNftMarket { senderAddress: IAddress, offerId: number ): Transaction { - const withdrawTx = new Transaction({ - value: 0, - data: new ContractCallPayloadBuilder() - .setFunction(new ContractFunction('withdrawCancelledOffer')) - .addArg(new U64Value(offerId)) - .build(), - receiver: this.contract.getAddress(), - gasLimit: 12000000, + const withdrawTx = this.transactionFactory.createTransactionForExecute({ + function: 'withdrawCancelledOffer', + arguments: [offerId], sender: senderAddress, - chainID: this.chainID + contract: this.contract.getAddress(), + gasLimit: 12000000n }); return withdrawTx; diff --git a/src/minter.ts b/src/minter.ts index e82bb39..07faf46 100644 --- a/src/minter.ts +++ b/src/minter.ts @@ -13,7 +13,9 @@ import { TokenIdentifierValue, Transaction, U64Value, - ApiNetworkProvider + ApiNetworkProvider, + TokenTransfer, + Token } from '@multiversx/sdk-core/out'; import { EnvironmentsEnum, @@ -32,9 +34,10 @@ export abstract class Minter extends Contract { env: string, contractAddress: IAddress, abiFile: any, - timeout: number = 20000 + timeout: number = 20000, + customNetworkProviderUrl?: string ) { - super(env, contractAddress, abiFile, timeout); + super(env, contractAddress, abiFile, timeout, customNetworkProviderUrl); this.imageServiceUrl = imageService[env as EnvironmentsEnum]; } @@ -130,21 +133,23 @@ export abstract class Minter extends Contract { quantityToBurn: BigNumber.Value, dataNftIdentifier = dataNftTokenIdentifier[this.env as EnvironmentsEnum] ): Transaction { - const burnTx = new Transaction({ - value: 0, - data: new ContractCallPayloadBuilder() - .setFunction(new ContractFunction('ESDTNFTTransfer')) - .addArg(new TokenIdentifierValue(dataNftIdentifier)) - .addArg(new U64Value(dataNftNonce)) - .addArg(new BigUIntValue(quantityToBurn)) - .addArg(new AddressValue(this.contract.getAddress())) - .addArg(new StringValue('burn')) - .build(), - receiver: senderAddress, + const burnTx = this.transactionFactory.createTransactionForExecute({ + function: 'burn', + arguments: [], sender: senderAddress, - gasLimit: 12000000, - chainID: this.chainID + contract: this.contract.getAddress(), + gasLimit: 50_000_000n, + tokenTransfers: [ + new TokenTransfer({ + token: new Token({ + identifier: dataNftIdentifier, + nonce: BigInt(dataNftNonce) + }), + amount: BigInt(quantityToBurn.toString()) + }) + ] }); + return burnTx; } @@ -153,16 +158,16 @@ export abstract class Minter extends Contract { * @param senderAddress The address of the sender, must be the admin of the contract */ setLocalRoles(senderAddress: IAddress): Transaction { - const setLocalRolesTx = new Transaction({ - value: 0, - data: new ContractCallPayloadBuilder() - .setFunction(new ContractFunction('setLocalRoles')) - .build(), - receiver: this.contract.getAddress(), - gasLimit: 100000000, - sender: senderAddress, - chainID: this.chainID - }); + const setLocalRolesTx = this.transactionFactory.createTransactionForExecute( + { + function: 'setLocalRoles', + arguments: [], + sender: senderAddress, + contract: this.contract.getAddress(), + gasLimit: 100_000_000n + } + ); + return setLocalRolesTx; } @@ -170,17 +175,15 @@ export abstract class Minter extends Contract { * @param senderAddress The address of the sender, must be the admin of the contract */ pauseContract(senderAddress: IAddress): Transaction { - const pauseContractTx = new Transaction({ - value: 0, - data: new ContractCallPayloadBuilder() - .setFunction(new ContractFunction('setIsPaused')) - .addArg(new BooleanValue(true)) - .build(), - receiver: this.contract.getAddress(), - gasLimit: 6000000, - sender: senderAddress, - chainID: this.chainID - }); + const pauseContractTx = this.transactionFactory.createTransactionForExecute( + { + function: 'setIsPaused', + arguments: [new BooleanValue(true)], + sender: senderAddress, + contract: this.contract.getAddress(), + gasLimit: 6000000n + } + ); return pauseContractTx; } @@ -189,17 +192,14 @@ export abstract class Minter extends Contract { * @param senderAddress The address of the sender, must be the admin of the contract */ unpauseContract(senderAddress: IAddress): Transaction { - const unpauseContractTx = new Transaction({ - value: 0, - data: new ContractCallPayloadBuilder() - .setFunction(new ContractFunction('setIsPaused')) - .addArg(new BooleanValue(false)) - .build(), - receiver: this.contract.getAddress(), - gasLimit: 6000000, - sender: senderAddress, - chainID: this.chainID - }); + const unpauseContractTx = + this.transactionFactory.createTransactionForExecute({ + function: 'setIsPaused', + arguments: [new BooleanValue(false)], + sender: senderAddress, + contract: this.contract.getAddress(), + gasLimit: 6000000n + }); return unpauseContractTx; } @@ -217,18 +217,15 @@ export abstract class Minter extends Contract { minRoyalties: BigNumber.Value, maxRoyalties: BigNumber.Value ): Transaction { - const setRoyaltiesLimitsTx = new Transaction({ - value: 0, - data: new ContractCallPayloadBuilder() - .setFunction(new ContractFunction('setRoyaltiesLimits')) - .addArg(new BigUIntValue(minRoyalties)) - .addArg(new BigUIntValue(maxRoyalties)) - .build(), - receiver: this.contract.getAddress(), - gasLimit: 6000000, - sender: senderAddress, - chainID: this.chainID - }); + const setRoyaltiesLimitsTx = + this.transactionFactory.createTransactionForExecute({ + function: 'setRoyaltiesLimits', + arguments: [minRoyalties, maxRoyalties], + sender: senderAddress, + contract: this.contract.getAddress(), + gasLimit: 6000000n + }); + return setRoyaltiesLimitsTx; } @@ -240,17 +237,15 @@ export abstract class Minter extends Contract { senderAddress: IAddress, is_enabled: boolean ): Transaction { - const setWhitelistIsEnabledTx = new Transaction({ - value: 0, - data: new ContractCallPayloadBuilder() - .setFunction(new ContractFunction('setWhiteListEnabled')) - .addArg(new BooleanValue(is_enabled)) - .build(), - receiver: this.contract.getAddress(), - gasLimit: 6000000, - sender: senderAddress, - chainID: this.chainID - }); + const setWhitelistIsEnabledTx = + this.transactionFactory.createTransactionForExecute({ + function: 'setWhiteListEnabled', + arguments: [is_enabled], + sender: senderAddress, + contract: this.contract.getAddress(), + gasLimit: 6000000n + }); + return setWhitelistIsEnabledTx; } @@ -263,22 +258,18 @@ export abstract class Minter extends Contract { whitelist( senderAddress: IAddress, addresses: string[], - extraGas = 0 + extraGas = 0n ): Transaction { - const whitelistTx = new Transaction({ - value: 0, - data: new ContractCallPayloadBuilder() - .setFunction(new ContractFunction('setWhiteListSpots')) - .setArgs( - addresses.map((address) => new AddressValue(new Address(address))) - ) - .build(), - receiver: this.contract.getAddress(), - gasLimit: 50000000 + extraGas, - sender: senderAddress, - chainID: this.chainID - }); - return whitelistTx; + const setWhitelistSpotsTx = + this.transactionFactory.createTransactionForExecute({ + function: 'setWhiteListSpots', + arguments: [addresses], + sender: senderAddress, + contract: this.contract.getAddress(), + gasLimit: 6000000n + extraGas + }); + + return setWhitelistSpotsTx; } /** Creates a remove whitelist transaction for the contract @@ -289,22 +280,18 @@ export abstract class Minter extends Contract { removeWhitelist( senderAddress: IAddress, addresses: string[], - extraGas = 0 + extraGas = 0n ): Transaction { - const removeWhitelistTx = new Transaction({ - value: 0, - data: new ContractCallPayloadBuilder() - .setFunction(new ContractFunction('removeWhiteListSpots')) - .setArgs( - addresses.map((address) => new AddressValue(new Address(address))) - ) - .build(), - receiver: this.contract.getAddress(), - gasLimit: 50000000 + extraGas, - sender: senderAddress, - chainID: this.chainID - }); - return removeWhitelistTx; + const removeWhitelistSpotsTx = + this.transactionFactory.createTransactionForExecute({ + function: 'removeWhiteListSpots', + arguments: [addresses], + sender: senderAddress, + contract: this.contract.getAddress(), + gasLimit: 6000000n + extraGas + }); + + return removeWhitelistSpotsTx; } /** Creates a set mint time limit transaction for the contract @@ -312,17 +299,15 @@ export abstract class Minter extends Contract { * @param timeLimit(seconds) The time limit to set between mints */ setMintTimeLimit(senderAddress: IAddress, timeLimit: number): Transaction { - const setMintTimeLimitTx = new Transaction({ - value: 0, - data: new ContractCallPayloadBuilder() - .setFunction(new ContractFunction('setMintTimeLimit')) - .addArg(new U64Value(timeLimit)) - .build(), - receiver: this.contract.getAddress(), - gasLimit: 6000000, - sender: senderAddress, - chainID: this.chainID - }); + const setMintTimeLimitTx = + this.transactionFactory.createTransactionForExecute({ + function: 'setMintTimeLimit', + arguments: [timeLimit], + sender: senderAddress, + contract: this.contract.getAddress(), + gasLimit: 6000000n + }); + return setMintTimeLimitTx; } @@ -334,17 +319,15 @@ export abstract class Minter extends Contract { senderAddress: IAddress, newAdministrator: IAddress ): Transaction { - const setAdministratorTx = new Transaction({ - value: 0, - data: new ContractCallPayloadBuilder() - .setFunction(new ContractFunction('setAdministrator')) - .addArg(new AddressValue(newAdministrator)) - .build(), - receiver: this.contract.getAddress(), - gasLimit: 6000000, - sender: senderAddress, - chainID: this.chainID - }); + const setAdministratorTx = + this.transactionFactory.createTransactionForExecute({ + function: 'setAdministrator', + arguments: [newAdministrator], + sender: senderAddress, + contract: this.contract.getAddress(), + gasLimit: 6000000n + }); + return setAdministratorTx; } @@ -355,16 +338,15 @@ export abstract class Minter extends Contract { * @param senderAddress The address of the sender, must be the admin or owner of the contract */ pauseCollection(senderAddress: IAddress): Transaction { - const pauseCollectionTx = new Transaction({ - value: 0, - data: new ContractCallPayloadBuilder() - .setFunction(new ContractFunction('pause')) - .build(), - receiver: this.contract.getAddress(), - gasLimit: 100000000, - sender: senderAddress, - chainID: this.chainID - }); + const pauseCollectionTx = + this.transactionFactory.createTransactionForExecute({ + function: 'pause', + arguments: [], + sender: senderAddress, + contract: this.contract.getAddress(), + gasLimit: 100000000n + }); + return pauseCollectionTx; } @@ -373,16 +355,14 @@ export abstract class Minter extends Contract { * @param senderAddress The address of the sender, must be the admin or owner of the contract */ unpauseCollection(senderAddress: IAddress): Transaction { - const unpauseCollectionTx = new Transaction({ - value: 0, - data: new ContractCallPayloadBuilder() - .setFunction(new ContractFunction('unpause')) - .build(), - receiver: this.contract.getAddress(), - gasLimit: 100000000, - sender: senderAddress, - chainID: this.chainID - }); + const unpauseCollectionTx = + this.transactionFactory.createTransactionForExecute({ + function: 'unpause', + arguments: [], + sender: senderAddress, + contract: this.contract.getAddress(), + gasLimit: 100000000n + }); return unpauseCollectionTx; } @@ -392,16 +372,12 @@ export abstract class Minter extends Contract { * @param senderAddress The address of the sender, must be the admin or owner of the contract */ freeze(senderAddress: IAddress, freezeAddress: IAddress): Transaction { - const freezeTx = new Transaction({ - value: 0, - data: new ContractCallPayloadBuilder() - .setFunction(new ContractFunction('freeze')) - .addArg(new AddressValue(freezeAddress)) - .build(), - receiver: this.contract.getAddress(), - gasLimit: 100000000, + const freezeTx = this.transactionFactory.createTransactionForExecute({ + function: 'freeze', + arguments: [freezeAddress], sender: senderAddress, - chainID: this.chainID + contract: this.contract.getAddress(), + gasLimit: 100000000n }); return freezeTx; @@ -412,16 +388,12 @@ export abstract class Minter extends Contract { * @param senderAddress The address of the sender, must be the admin or owner of the contract */ unfreeze(senderAddress: IAddress, unfreezeAddress: IAddress): Transaction { - const unfreezeTx = new Transaction({ - value: 0, - data: new ContractCallPayloadBuilder() - .setFunction(new ContractFunction('unfreeze')) - .addArg(new AddressValue(unfreezeAddress)) - .build(), - receiver: this.contract.getAddress(), - gasLimit: 100000000, + const unfreezeTx = this.transactionFactory.createTransactionForExecute({ + function: 'unfreeze', + arguments: [unfreezeAddress], sender: senderAddress, - chainID: this.chainID + contract: this.contract.getAddress(), + gasLimit: 100000000n }); return unfreezeTx; @@ -438,19 +410,16 @@ export abstract class Minter extends Contract { nonce: number, freezeAddress: IAddress ): Transaction { - const freezeSingleNFTTx = new Transaction({ - value: 0, - data: new ContractCallPayloadBuilder() - .setFunction(new ContractFunction('freezeSingleNFT')) - .addArg(new U64Value(nonce)) - .addArg(new AddressValue(freezeAddress)) - .build(), - receiver: this.contract.getAddress(), - gasLimit: 100000000, - sender: senderAddress, - chainID: this.chainID - }); - return freezeSingleNFTTx; + const freezeSingleNftTx = + this.transactionFactory.createTransactionForExecute({ + function: 'freezeSingleNFT', + arguments: [nonce, freezeAddress], + sender: senderAddress, + contract: this.contract.getAddress(), + gasLimit: 100000000n + }); + + return freezeSingleNftTx; } /** @@ -464,19 +433,16 @@ export abstract class Minter extends Contract { nonce: number, unfreezeAddress: IAddress ): Transaction { - const unFreezeSingleNFTTx = new Transaction({ - value: 0, - data: new ContractCallPayloadBuilder() - .setFunction(new ContractFunction('unFreezeSingleNFT')) - .addArg(new U64Value(nonce)) - .addArg(new AddressValue(unfreezeAddress)) - .build(), - receiver: this.contract.getAddress(), - gasLimit: 100000000, - sender: senderAddress, - chainID: this.chainID - }); - return unFreezeSingleNFTTx; + const unfreezeSingleNftTx = + this.transactionFactory.createTransactionForExecute({ + function: 'unFreezeSingleNFT', + arguments: [nonce, unfreezeAddress], + sender: senderAddress, + contract: this.contract.getAddress(), + gasLimit: 100000000n + }); + + return unfreezeSingleNftTx; } /** @@ -492,18 +458,16 @@ export abstract class Minter extends Contract { nonce: number, wipeAddress: IAddress ): Transaction { - const wipeSingleNFTTx = new Transaction({ - value: 0, - data: new ContractCallPayloadBuilder() - .setFunction(new ContractFunction('wipeSingleNFT')) - .addArg(new U64Value(nonce)) - .addArg(new AddressValue(wipeAddress)) - .build(), - receiver: this.contract.getAddress(), - gasLimit: 100000000, - sender: senderAddress, - chainID: this.chainID - }); - return wipeSingleNFTTx; + const wipeSingleNftTx = this.transactionFactory.createTransactionForExecute( + { + function: 'wipeSingleNFT', + arguments: [nonce, wipeAddress], + sender: senderAddress, + contract: this.contract.getAddress(), + gasLimit: 100000000n + } + ); + + return wipeSingleNftTx; } } diff --git a/src/nft-minter.ts b/src/nft-minter.ts index 926c95e..82a97f3 100644 --- a/src/nft-minter.ts +++ b/src/nft-minter.ts @@ -7,7 +7,9 @@ import { IAddress, ResultsParser, StringValue, + Token, TokenIdentifierValue, + TokenTransfer, Transaction, U64Value } from '@multiversx/sdk-core/out'; @@ -30,9 +32,21 @@ export class NftMinter extends Minter { * @param env 'devnet' | 'mainnet' | 'testnet' * @param contractAddress The address of the factory generated smart contract * @param timeout Timeout for the network provider (DEFAULT = 20000ms) + * @param customNetworkProviderUrl Custom network provider URL */ - constructor(env: string, contractAddress: IAddress, timeout: number = 20000) { - super(env, contractAddress, dataNftLeaseAbi, timeout); + constructor( + env: string, + contractAddress: IAddress, + timeout: number = 20000, + customNetworkProviderUrl?: string + ) { + super( + env, + contractAddress, + dataNftLeaseAbi, + timeout, + customNetworkProviderUrl + ); } /** @@ -58,36 +72,41 @@ export class NftMinter extends Minter { ): Transaction { let data; if (requireMintTax && options) { - data = new ContractCallPayloadBuilder() - .setFunction(new ContractFunction('initializeContract')) - .addArg(new StringValue(collectionName)) - .addArg(new StringValue(tokenTicker)) - .addArg(new BigUIntValue(mintLimit)) - .addArg(new BooleanValue(requireMintTax)) - .addArg(new AddressValue(claimsAddress)) - .addArg(new TokenIdentifierValue(options.taxTokenIdentifier)) - .addArg(new BigUIntValue(options.taxTokenAmount)) - .build(); + const initializeContractTx = + this.transactionFactory.createTransactionForExecute({ + function: 'initializeContract', + arguments: [ + collectionName, + tokenTicker, + mintLimit, + requireMintTax, + claimsAddress, + options.taxTokenIdentifier, + options.taxTokenAmount + ], + sender: senderAddress, + contract: this.contract.getAddress(), + gasLimit: 100000000n + }); + + return initializeContractTx; } else { - data = new ContractCallPayloadBuilder() - .setFunction(new ContractFunction('initializeContract')) - .addArg(new StringValue(collectionName)) - .addArg(new StringValue(tokenTicker)) - .addArg(new BigUIntValue(mintLimit)) - .addArg(new BooleanValue(requireMintTax)) - .addArg(new AddressValue(claimsAddress)) - .build(); + const initializeContractTx = + this.transactionFactory.createTransactionForExecute({ + function: 'initializeContract', + arguments: [ + collectionName, + tokenTicker, + mintLimit, + requireMintTax, + claimsAddress + ], + sender: senderAddress, + contract: this.contract.getAddress(), + gasLimit: 100000000n + }); + return initializeContractTx; } - - const initializeContractTx = new Transaction({ - value: 50000000000000000, - data: data, - receiver: this.contract.getAddress(), - gasLimit: 100000000, - sender: senderAddress, - chainID: this.chainID - }); - return initializeContractTx; } /** @@ -112,27 +131,31 @@ export class NftMinter extends Minter { }, quantity = 1 ): Transaction { - const updateAttributesTx = new Transaction({ - value: 0, - data: new ContractCallPayloadBuilder() - .setFunction(new ContractFunction('ESDTNFTTransfer')) - .addArg(new TokenIdentifierValue(tokenIdentifier)) - .addArg(new U64Value(nonce)) - .addArg(new U64Value(quantity)) - .addArg(new AddressValue(this.contract.getAddress())) - .addArg(new StringValue('updateAttributes')) - .addArg(new StringValue(attributes.dataMarshalUrl)) - .addArg(new StringValue(attributes.dataStreamUrl)) - .addArg(new StringValue(attributes.dataPreviewUrl)) - .addArg(new AddressValue(attributes.creator)) - .addArg(new StringValue(attributes.title)) - .addArg(new StringValue(attributes.description)) - .build(), - receiver: senderAddress, - gasLimit: 12000000, - sender: senderAddress, - chainID: this.chainID - }); + const updateAttributesTx = + this.transactionFactory.createTransactionForExecute({ + function: 'updateAttributes', + arguments: [ + attributes.dataMarshalUrl, + attributes.dataStreamUrl, + attributes.dataPreviewUrl, + attributes.creator, + attributes.title, + attributes.description + ], + sender: senderAddress, + contract: this.contract.getAddress(), + gasLimit: 12000000n, + tokenTransfers: [ + new TokenTransfer({ + token: new Token({ + identifier: tokenIdentifier, + nonce: BigInt(nonce) + }), + amount: BigInt(quantity) + }) + ] + }); + return updateAttributesTx; } @@ -261,46 +284,46 @@ export class NftMinter extends Minter { metadataOnIpfsUrl = traitsUrl; } - let data; + let tokenTransfers: TokenTransfer[] = []; if ( antiSpamTax && antiSpamTokenIdentifier && antiSpamTokenIdentifier != 'EGLD' && antiSpamTax > BigNumber(0) ) { - data = new ContractCallPayloadBuilder() - .setFunction(new ContractFunction('ESDTTransfer')) - .addArg(new TokenIdentifierValue(antiSpamTokenIdentifier)) - .addArg(new BigUIntValue(antiSpamTax)) - .addArg(new StringValue('mint')); - } else { - data = new ContractCallPayloadBuilder().setFunction( - new ContractFunction('mint') + tokenTransfers.push( + new TokenTransfer({ + token: new Token({ identifier: antiSpamTokenIdentifier }), + amount: BigInt(antiSpamTax.toString()) + }) ); } - data - .addArg(new StringValue(tokenName)) - .addArg(new StringValue(imageOnIpfsUrl)) - .addArg(new StringValue(metadataOnIpfsUrl)) - .addArg(new StringValue(dataMarshalUrl)) - .addArg(new StringValue(dataNftStreamUrlEncrypted)) - .addArg(new StringValue(dataPreviewUrl)) - .addArg(new U64Value(royalties)) - .addArg(new StringValue(datasetTitle)) - .addArg(new StringValue(datasetDescription)); - - for (const extraAsset of extraAssets ?? []) { - data.addArg(new StringValue(extraAsset)); + let args = [ + tokenName, + imageOnIpfsUrl, + metadataOnIpfsUrl, + dataMarshalUrl, + dataNftStreamUrlEncrypted, + dataPreviewUrl, + royalties, + datasetTitle, + datasetDescription + ]; + + if (extraAssets && extraAssets?.length > 0) { + for (const asset of extraAssets) { + args.push(asset); + } } - const mintTx = new Transaction({ - value: antiSpamTokenIdentifier == 'EGLD' ? antiSpamTax : 0, - data: data.build(), + const mintTx = this.transactionFactory.createTransactionForExecute({ + function: 'mint', + arguments: args, sender: senderAddress, - receiver: this.contract.getAddress(), - gasLimit: 130_000_000, - chainID: this.chainID + contract: this.contract.getAddress(), + gasLimit: 130_000_000n, + tokenTransfers }); return mintTx; @@ -312,18 +335,16 @@ export class NftMinter extends Minter { * @param address The address to set the transfer roles */ setTransferRole(senderAddress: IAddress, address: IAddress): Transaction { - const setTransferRolesTx = new Transaction({ - value: 0, - data: new ContractCallPayloadBuilder() - .setFunction(new ContractFunction('setTransferRole')) - .addArg(new AddressValue(address)) - .build(), - receiver: this.contract.getAddress(), - gasLimit: 10000000, - sender: senderAddress, - chainID: this.chainID - }); - return setTransferRolesTx; + const setTransferRoleTx = + this.transactionFactory.createTransactionForExecute({ + function: 'setTransferRole', + arguments: [address], + sender: senderAddress, + contract: this.contract.getAddress(), + gasLimit: 10000000n + }); + + return setTransferRoleTx; } /** @@ -332,18 +353,16 @@ export class NftMinter extends Minter { * @param address The address to unset the transfer roles */ unsetTransferRole(senderAddress: IAddress, address: IAddress): Transaction { - const unsetTransferRolesTx = new Transaction({ - value: 0, - data: new ContractCallPayloadBuilder() - .setFunction(new ContractFunction('unsetTransferRole')) - .addArg(new AddressValue(address)) - .build(), - receiver: this.contract.getAddress(), - gasLimit: 10000000, - sender: senderAddress, - chainID: this.chainID - }); - return unsetTransferRolesTx; + const unsetTransferRoleTx = + this.transactionFactory.createTransactionForExecute({ + function: 'unsetTransferRole', + arguments: [address], + sender: senderAddress, + contract: this.contract.getAddress(), + gasLimit: 10000000n + }); + + return unsetTransferRoleTx; } /** Creates a set mint tax transaction for the contract @@ -354,17 +373,14 @@ export class NftMinter extends Minter { senderAddress: IAddress, is_required: boolean ): Transaction { - const setMintTaxIsRequiredTx = new Transaction({ - value: 0, - data: new ContractCallPayloadBuilder() - .setFunction(new ContractFunction('setTaxIsRequired')) - .addArg(new BooleanValue(is_required)) - .build(), - receiver: this.contract.getAddress(), - gasLimit: 10000000, - sender: senderAddress, - chainID: this.chainID - }); + const setMintTaxIsRequiredTx = + this.transactionFactory.createTransactionForExecute({ + function: 'setTaxIsRequired', + arguments: [is_required], + sender: senderAddress, + contract: this.contract.getAddress(), + gasLimit: 10000000n + }); return setMintTaxIsRequiredTx; } @@ -377,18 +393,16 @@ export class NftMinter extends Minter { senderAddress: IAddress, claimsAddress: IAddress ): Transaction { - const setClaimsAddressTx = new Transaction({ - value: 0, - data: new ContractCallPayloadBuilder() - .setFunction(new ContractFunction('setClaimsAddress')) - .addArg(new AddressValue(claimsAddress)) - .build(), - receiver: this.contract.getAddress(), - gasLimit: 10000000, - sender: senderAddress, - chainID: this.chainID - }); - return setClaimsAddressTx; + const setClaimAddressTx = + this.transactionFactory.createTransactionForExecute({ + function: 'setClaimsAddress', + arguments: [claimsAddress], + sender: senderAddress, + contract: this.contract.getAddress(), + gasLimit: 10000000n + }); + + return setClaimAddressTx; } /** Creates a claim royalties transaction for the contract @@ -401,18 +415,15 @@ export class NftMinter extends Minter { tokenIdentifier: string, nonce = 0 ): Transaction { - const claimRoyaltiesTx = new Transaction({ - value: 0, - data: new ContractCallPayloadBuilder() - .setFunction(new ContractFunction('claimRoyalties')) - .addArg(new TokenIdentifierValue(tokenIdentifier)) - .addArg(new BigUIntValue(nonce)) - .build(), - receiver: this.contract.getAddress(), - gasLimit: 10000000, - sender: senderAddress, - chainID: this.chainID - }); + const claimRoyaltiesTx = + this.transactionFactory.createTransactionForExecute({ + function: 'claimRoyalties', + arguments: [tokenIdentifier, nonce], + sender: senderAddress, + contract: this.contract.getAddress(), + gasLimit: 10000000n + }); + return claimRoyaltiesTx; } diff --git a/src/sft-minter.ts b/src/sft-minter.ts index 1eb2d35..159548a 100644 --- a/src/sft-minter.ts +++ b/src/sft-minter.ts @@ -38,13 +38,19 @@ export class SftMinter extends Minter { * Creates a new instance of the `SftMinter` class, which can be used to interact with the Data NFT-FT minter smart contract * @param env 'devnet' | 'mainnet' | 'testnet' * @param timeout Timeout for the network provider (DEFAULT = 20000ms) + * @param customNetworkProviderUrl Custom network provider URL */ - constructor(env: string, timeout: number = 20000) { + constructor( + env: string, + timeout: number = 20000, + customNetworkProviderUrl?: string + ) { super( env, new Address(minterContractAddress[env as EnvironmentsEnum]), dataNftMinterAbi, - timeout + timeout, + customNetworkProviderUrl ); } @@ -132,7 +138,7 @@ export class SftMinter extends Minter { * @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 + * @param treasuryAddress The address of the treasury to collect the anti spam tax */ initializeContract( senderAddress: IAddress, @@ -141,24 +147,24 @@ export class SftMinter extends Minter { antiSpamTaxTokenIdentifier: string, antiSpamTaxTokenAmount: BigNumber.Value, mintLimit: number, - treasury_address: IAddress + treasuryAddress: 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, - sender: senderAddress, - chainID: this.chainID - }); + const initializeContractTx = + this.transactionFactory.createTransactionForExecute({ + function: 'initializeContract', + arguments: [ + collectionName, + tokenTicker, + antiSpamTaxTokenIdentifier, + antiSpamTaxTokenAmount, + mintLimit, + treasuryAddress + ], + sender: senderAddress, + contract: this.contract.getAddress(), + gasLimit: 10000000n + }); + return initializeContractTx; } @@ -171,17 +177,15 @@ export class SftMinter extends Minter { 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 - }); + const setTreasuryAddressTx = + this.transactionFactory.createTransactionForExecute({ + function: 'setTreasuryAddress', + arguments: [treasuryAddress], + sender: senderAddress, + contract: this.contract.getAddress(), + gasLimit: 10000000n + }); + return setTreasuryAddressTx; } @@ -194,17 +198,15 @@ export class SftMinter extends Minter { senderAddress: IAddress, donationTreasuryAddress: IAddress ): Transaction { - const setDonationTreasuryAddressTx = new Transaction({ - value: 0, - data: new ContractCallPayloadBuilder() - .setFunction(new ContractFunction('setDonationTreasuryAddress')) - .addArg(new AddressValue(donationTreasuryAddress)) - .build(), - receiver: this.contract.getAddress(), - gasLimit: 10000000, - sender: senderAddress, - chainID: this.chainID - }); + const setDonationTreasuryAddressTx = + this.transactionFactory.createTransactionForExecute({ + function: 'setDonationTreasuryAddress', + arguments: [donationTreasuryAddress], + sender: senderAddress, + contract: this.contract.getAddress(), + gasLimit: 10000000n + }); + return setDonationTreasuryAddressTx; } @@ -217,17 +219,15 @@ export class SftMinter extends Minter { senderAddress: IAddress, maxDonationPercentage: BigNumber.Value ): Transaction { - const setMaxDonationPercentageTx = new Transaction({ - value: 0, - data: new ContractCallPayloadBuilder() - .setFunction(new ContractFunction('setMaxDonationPercentage')) - .addArg(new U64Value(maxDonationPercentage)) - .build(), - receiver: this.contract.getAddress(), - gasLimit: 10000000, - sender: senderAddress, - chainID: this.chainID - }); + const setMaxDonationPercentageTx = + this.transactionFactory.createTransactionForExecute({ + function: 'setMaxDonationPercentage', + arguments: [maxDonationPercentage], + sender: senderAddress, + contract: this.contract.getAddress(), + gasLimit: 10000000n + }); + return setMaxDonationPercentageTx; } @@ -240,17 +240,14 @@ export class SftMinter extends Minter { senderAddress: IAddress, maxSupply: BigNumber.Value ): Transaction { - const setMaxSupplyTx = new Transaction({ - value: 0, - data: new ContractCallPayloadBuilder() - .setFunction(new ContractFunction('setMaxSupply')) - .addArg(new BigUIntValue(maxSupply)) - .build(), - receiver: this.contract.getAddress(), - gasLimit: 10000000, + const setMaxSupplyTx = this.transactionFactory.createTransactionForExecute({ + function: 'setMaxSupply', + arguments: [maxSupply], sender: senderAddress, - chainID: this.chainID + contract: this.contract.getAddress(), + gasLimit: 10000000n }); + return setMaxSupplyTx; } @@ -419,42 +416,35 @@ export class SftMinter extends Minter { metadataOnIpfsUrl = traitsUrl; } - const data = new ContractCallPayloadBuilder() - .setFunction(new ContractFunction('ESDTTransfer')) - .addArg( - new TokenIdentifierValue( - itheumTokenIdentifier[this.env as EnvironmentsEnum] - ) - ) - .addArg(new BigUIntValue(amountToSend)) - .addArg(new StringValue('mint')) - .addArg(new StringValue(tokenName)) - .addArg(new StringValue(imageOnIpfsUrl)) - .addArg(new StringValue(metadataOnIpfsUrl)) - .addArg(new StringValue(dataMarshalUrl)) - .addArg(new StringValue(dataNftStreamUrlEncrypted)) - .addArg(new StringValue(dataPreviewUrl)) - .addArg(new U64Value(royalties)) - .addArg(new U64Value(supply)) - .addArg(new StringValue(datasetTitle)) - .addArg(new StringValue(datasetDescription)); + let args = [ + tokenName, + imageOnIpfsUrl, + metadataOnIpfsUrl, + dataMarshalUrl, + dataNftStreamUrlEncrypted, + dataPreviewUrl, + royalties, + supply, + datasetTitle, + datasetDescription + ]; if (lockPeriod) { - data.addArg(new U64Value(lockPeriod)); + args.push(lockPeriod); } - data.addArg(new U64Value(donationPercentage)); + args.push(donationPercentage); for (const extraAsset of extraAssets ?? []) { - data.addArg(new StringValue(extraAsset)); + args.push(extraAsset); } - const mintTx = new Transaction({ - data: data.build(), + const mintTx = this.transactionFactory.createTransactionForExecute({ + function: 'mint', + arguments: args, sender: senderAddress, - receiver: this.contract.getAddress(), - gasLimit: 130_000_000, - chainID: this.chainID + contract: this.contract.getAddress(), + gasLimit: 130_000_000n }); return { From e6e48e53e06c1a106d37917b71403632b8d0919c Mon Sep 17 00:00:00 2001 From: bucurdavid Date: Tue, 12 Nov 2024 14:41:53 +0200 Subject: [PATCH 5/7] chore: alpha version bump --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 5d647e2..a6e0a63 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@itheum/sdk-mx-data-nft", - "version": "3.8.0-alpha.12", + "version": "3.8.0-alpha.13", "description": "SDK for Itheum's Data NFT Technology on MultiversX Blockchain", "main": "out/index.js", "types": "out/index.d.js", From 08d456ebd7341fd56fc6021369d9bfa0c3e63099 Mon Sep 17 00:00:00 2001 From: bucurdavid Date: Tue, 12 Nov 2024 18:23:56 +0200 Subject: [PATCH 6/7] fix: mint tx --- src/sft-minter.ts | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/sft-minter.ts b/src/sft-minter.ts index 159548a..4fa087d 100644 --- a/src/sft-minter.ts +++ b/src/sft-minter.ts @@ -7,7 +7,9 @@ import { IAddress, ResultsParser, StringValue, + Token, TokenIdentifierValue, + TokenTransfer, Transaction, U64Value } from '@multiversx/sdk-core/out'; @@ -444,7 +446,15 @@ export class SftMinter extends Minter { arguments: args, sender: senderAddress, contract: this.contract.getAddress(), - gasLimit: 130_000_000n + gasLimit: 130_000_000n, + tokenTransfers: [ + new TokenTransfer({ + token: new Token({ + identifier: itheumTokenIdentifier[this.env as EnvironmentsEnum] + }), + amount: BigInt(amountToSend) + }) + ] }); return { From 2d631c86be1761d6ef6d1ec47425617189951c56 Mon Sep 17 00:00:00 2001 From: bucurdavid Date: Tue, 12 Nov 2024 18:24:21 +0200 Subject: [PATCH 7/7] chore: alpha version bump --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index a6e0a63..5558f9b 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@itheum/sdk-mx-data-nft", - "version": "3.8.0-alpha.13", + "version": "3.8.0-alpha.14", "description": "SDK for Itheum's Data NFT Technology on MultiversX Blockchain", "main": "out/index.js", "types": "out/index.d.js",