From 8035c57e461a7407b01e74a7abab2bf4e2535f7e Mon Sep 17 00:00:00 2001 From: danielailie Date: Wed, 5 Mar 2025 12:03:50 +0200 Subject: [PATCH 1/3] Token management fixes --- src/core/transactionsFactoryConfig.ts | 6 ++-- src/entrypoints/entrypoints.spec.ts | 3 +- src/smartContracts/resources.ts | 18 +++-------- ...tContractTransactionsOutcomeParser.spec.ts | 4 +-- .../smartContractTransactionsOutcomeParser.ts | 30 +++++-------------- src/tokenManagement/resources.ts | 9 +++++- .../tokenManagementTransactionsFactory.ts | 3 +- 7 files changed, 27 insertions(+), 46 deletions(-) diff --git a/src/core/transactionsFactoryConfig.ts b/src/core/transactionsFactoryConfig.ts index 1ad0007f1..117918813 100644 --- a/src/core/transactionsFactoryConfig.ts +++ b/src/core/transactionsFactoryConfig.ts @@ -62,9 +62,9 @@ export class TransactionsFactoryConfig { this.gasLimitFreezing = 60000000n; this.gasLimitWiping = 60000000n; this.gasLimitEsdtNftCreate = 3000000n; - this.gasLimitEsdtNftUpdateAttributes = 1000000n; - this.gasLimitEsdtNftAddQuantity = 1000000n; - this.gasLimitEsdtNftBurn = 1000000n; + this.gasLimitEsdtNftUpdateAttributes = 500000n; + this.gasLimitEsdtNftAddQuantity = 500000n; + this.gasLimitEsdtNftBurn = 500000n; this.gasLimitStorePerByte = 10000n; this.issueCost = 50000000000000000n; this.gasLimitEsdtModifyRoyalties = 60000000n; diff --git a/src/entrypoints/entrypoints.spec.ts b/src/entrypoints/entrypoints.spec.ts index cd37de76f..e06d617e8 100644 --- a/src/entrypoints/entrypoints.spec.ts +++ b/src/entrypoints/entrypoints.spec.ts @@ -2,7 +2,6 @@ import { assert } from "chai"; import { readFileSync } from "fs"; import path from "path"; import { Account } from "../accounts/account"; -import { Address } from "../core"; import { loadAbiRegistry } from "../testutils"; import { DevnetEntrypoint } from "./entrypoints"; @@ -82,7 +81,7 @@ describe("TestEntrypoint", function () { assert.equal(outcome.contracts.length, 1); - const contractAddress = Address.newFromBech32(outcome.contracts[0].address); + const contractAddress = outcome.contracts[0].address; const executeTransaction = await controller.createTransactionForExecute( sender, diff --git a/src/smartContracts/resources.ts b/src/smartContracts/resources.ts index f9008b85e..508aab388 100644 --- a/src/smartContracts/resources.ts +++ b/src/smartContracts/resources.ts @@ -34,18 +34,8 @@ export type ParsedSmartContractCallOutcome = { returnMessage: string; }; -export class DeployedSmartContract { - address: string; - ownerAddress: string; +export type DeployedSmartContract = { + address: Address; + ownerAddress: Address; codeHash: Uint8Array; - - constructor(address: string, ownerAddress: string, codeHash: Uint8Array) { - this.address = address; - this.ownerAddress = ownerAddress; - this.codeHash = codeHash; - } - - toString(): string { - return `DeployedSmartContract(address=${this.address}, ownerAddress=${this.ownerAddress}, codeHash=${Buffer.from(this.codeHash).toString("hex")})`; - } -} +}; diff --git a/src/smartContracts/smartContractTransactionsOutcomeParser.spec.ts b/src/smartContracts/smartContractTransactionsOutcomeParser.spec.ts index e4298cbc2..649d4b2a9 100644 --- a/src/smartContracts/smartContractTransactionsOutcomeParser.spec.ts +++ b/src/smartContracts/smartContractTransactionsOutcomeParser.spec.ts @@ -36,8 +36,8 @@ describe("test smart contract transactions outcome parser", () => { assert.equal(parsed.returnMessage, "ok"); assert.deepEqual(parsed.contracts, [ { - address: contract.toBech32(), - ownerAddress: deployer.toBech32(), + address: contract, + ownerAddress: deployer, codeHash: codeHash, }, ]); diff --git a/src/smartContracts/smartContractTransactionsOutcomeParser.ts b/src/smartContracts/smartContractTransactionsOutcomeParser.ts index fdb0d4588..aadfc484e 100644 --- a/src/smartContracts/smartContractTransactionsOutcomeParser.ts +++ b/src/smartContracts/smartContractTransactionsOutcomeParser.ts @@ -20,27 +20,13 @@ export class SmartContractTransactionsOutcomeParser { this.abi = options?.abi; } - parseDeploy(options: { transactionOnNetwork: TransactionOnNetwork }): { - returnCode: string; - returnMessage: string; - contracts: { - address: string; - ownerAddress: string; - codeHash: Uint8Array; - }[]; - } { + parseDeploy(options: { transactionOnNetwork: TransactionOnNetwork }): resources.SmartContractDeployOutcome { return this.parseDeployGivenTransactionOnNetwork(options.transactionOnNetwork); } - protected parseDeployGivenTransactionOnNetwork(transactionOnNetwork: TransactionOnNetwork): { - returnCode: string; - returnMessage: string; - contracts: { - address: string; - ownerAddress: string; - codeHash: Uint8Array; - }[]; - } { + protected parseDeployGivenTransactionOnNetwork( + transactionOnNetwork: TransactionOnNetwork, + ): resources.SmartContractDeployOutcome { const directCallOutcome = this.findDirectSmartContractCallOutcome(transactionOnNetwork); const events = transactionOnNetwork.logs.events @@ -61,15 +47,15 @@ export class SmartContractTransactionsOutcomeParser { } private parseScDeployEvent(event: { topics: Uint8Array[] }): { - address: string; - ownerAddress: string; + address: Address; + ownerAddress: Address; codeHash: Uint8Array; } { const topicForAddress = Buffer.from(event.topics[0]).toString("hex"); const topicForOwnerAddress = Buffer.from(event.topics[1]).toString("hex"); const topicForCodeHash = Buffer.from(event.topics[2]); - const address = topicForAddress?.length ? new Address(topicForAddress).toBech32() : ""; - const ownerAddress = topicForOwnerAddress?.length ? new Address(topicForOwnerAddress).toBech32() : ""; + const address = topicForAddress?.length ? new Address(topicForAddress) : Address.empty(); + const ownerAddress = topicForOwnerAddress?.length ? new Address(topicForOwnerAddress) : Address.empty(); const codeHash = topicForCodeHash; return { diff --git a/src/tokenManagement/resources.ts b/src/tokenManagement/resources.ts index bb3bf6c8b..d3f7e0fb2 100644 --- a/src/tokenManagement/resources.ts +++ b/src/tokenManagement/resources.ts @@ -25,7 +25,14 @@ export type FungibleSpecialRoleInput = { addRoleLocalBurn: boolean; addRoleESDTTransferRole: boolean; }; -export type SemiFungibleSpecialRoleInput = SpecialRoleInput & { addRoleNFTAddQuantity: boolean }; +export type SemiFungibleSpecialRoleInput = { + user: Address; + tokenIdentifier: string; + addRoleNFTCreate: boolean; + addRoleNFTBurn: boolean; + addRoleNFTAddQuantity: boolean; + addRoleESDTTransferRole: boolean; +}; export type SpecialRoleInput = { user: Address; diff --git a/src/tokenManagement/tokenManagementTransactionsFactory.ts b/src/tokenManagement/tokenManagementTransactionsFactory.ts index d6d14e5e4..e715a7748 100644 --- a/src/tokenManagement/tokenManagementTransactionsFactory.ts +++ b/src/tokenManagement/tokenManagementTransactionsFactory.ts @@ -292,7 +292,6 @@ export class TokenManagementTransactionsFactory { options.addRoleNFTBurn ? args.push(new StringValue("ESDTRoleNFTBurn")) : 0; options.addRoleNFTAddQuantity ? args.push(new StringValue("ESDTRoleNFTAddQuantity")) : 0; options.addRoleESDTTransferRole ? args.push(new StringValue("ESDTTransferRole")) : 0; - options.addRoleESDTModifyCreator ? args.push(new StringValue("ESDTRoleModifyCreator")) : 0; const dataParts = ["setSpecialRole", ...this.argSerializer.valuesToStrings(args)]; @@ -346,7 +345,7 @@ export class TokenManagementTransactionsFactory { "ESDTNFTCreate", ...this.argSerializer.valuesToStrings([ new StringValue(options.tokenIdentifier), - new BigUIntValue(options.initialQuantity), + new BigUIntValue(options.initialQuantity ?? 1n), new StringValue(options.name), new BigUIntValue(options.royalties), new StringValue(options.hash), From d06690056d4f92913faed5139b4a904548ecb200 Mon Sep 17 00:00:00 2001 From: danielailie Date: Wed, 5 Mar 2025 12:09:09 +0200 Subject: [PATCH 2/3] Fix devnet tests --- .../smartContractTransactionsOutcomeParser.dev.net.spec.ts | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/smartContracts/smartContractTransactionsOutcomeParser.dev.net.spec.ts b/src/smartContracts/smartContractTransactionsOutcomeParser.dev.net.spec.ts index a17bd3873..a76fe6b2c 100644 --- a/src/smartContracts/smartContractTransactionsOutcomeParser.dev.net.spec.ts +++ b/src/smartContracts/smartContractTransactionsOutcomeParser.dev.net.spec.ts @@ -1,4 +1,5 @@ import { assert } from "chai"; +import { Address } from "../core"; import { createDevnetProvider } from "../testutils/networkProviders"; import { SmartContractTransactionsOutcomeParser } from "./smartContractTransactionsOutcomeParser"; @@ -14,8 +15,8 @@ describe("test smart contract transactions outcome parser on devnet", () => { assert.equal(parsedGivenTransactionOnNetwork.returnCode, "ok"); assert.deepEqual(parsedGivenTransactionOnNetwork.contracts, [ { - address: "erd1qqqqqqqqqqqqqpgqpayq2es08gq8798xhnpr0kzgn7495qt5q6uqd7lpwf", - ownerAddress: "erd1tn62hjp72rznp8vq0lplva5csav6rccpqqdungpxtqz0g2hcq6uq9k4cc6", + address: Address.newFromBech32("erd1qqqqqqqqqqqqqpgqpayq2es08gq8798xhnpr0kzgn7495qt5q6uqd7lpwf"), + ownerAddress: Address.newFromBech32("erd1tn62hjp72rznp8vq0lplva5csav6rccpqqdungpxtqz0g2hcq6uq9k4cc6"), codeHash: Buffer.from("c876625ec34a04445cfd99067777ebe488afdbc6899cd958f4c1d36107ca02d9", "hex"), }, ]); From b5714cd5198e2c72e5c1e27560004d18c5170437 Mon Sep 17 00:00:00 2001 From: danielailie Date: Wed, 5 Mar 2025 12:23:19 +0200 Subject: [PATCH 3/3] Update gas limit --- src/core/transactionsFactoryConfig.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/core/transactionsFactoryConfig.ts b/src/core/transactionsFactoryConfig.ts index 117918813..d898fbb00 100644 --- a/src/core/transactionsFactoryConfig.ts +++ b/src/core/transactionsFactoryConfig.ts @@ -62,9 +62,9 @@ export class TransactionsFactoryConfig { this.gasLimitFreezing = 60000000n; this.gasLimitWiping = 60000000n; this.gasLimitEsdtNftCreate = 3000000n; - this.gasLimitEsdtNftUpdateAttributes = 500000n; - this.gasLimitEsdtNftAddQuantity = 500000n; - this.gasLimitEsdtNftBurn = 500000n; + this.gasLimitEsdtNftUpdateAttributes = 50000n; + this.gasLimitEsdtNftAddQuantity = 50000n; + this.gasLimitEsdtNftBurn = 50000n; this.gasLimitStorePerByte = 10000n; this.issueCost = 50000000000000000n; this.gasLimitEsdtModifyRoyalties = 60000000n;