From c0e95f364e653db713ca371d989d79b06a56761e Mon Sep 17 00:00:00 2001 From: hschiau Date: Thu, 26 Sep 2024 17:35:04 +0300 Subject: [PATCH 1/2] SERVICES-2621: update farm SC transaction generation methods --- .../services/farm.transaction.service.ts | 266 ++++++++++-------- src/modules/farm/farm.transaction.resolver.ts | 31 +- .../services/farm.v1.2.transaction.service.ts | 226 +++++++-------- .../services/farm.v1.3.transaction.service.ts | 143 +++++----- .../services/farm.v2.transaction.service.ts | 129 ++++----- .../mx.proxy.service.ts | 22 ++ 6 files changed, 450 insertions(+), 367 deletions(-) diff --git a/src/modules/farm/base-module/services/farm.transaction.service.ts b/src/modules/farm/base-module/services/farm.transaction.service.ts index fee4d3bc9..6f6d513a6 100644 --- a/src/modules/farm/base-module/services/farm.transaction.service.ts +++ b/src/modules/farm/base-module/services/farm.transaction.service.ts @@ -1,10 +1,9 @@ import { TransactionModel } from '../../../../models/transaction.model'; -import { BytesValue } from '@multiversx/sdk-core/out/smartcontracts/typesystem/bytes'; import { - Address, BigUIntValue, + BytesValue, + Token, TokenTransfer, - TypedValue, } from '@multiversx/sdk-core'; import { mxConfig, gasConfig } from '../../../../config'; import { BigNumber } from 'bignumber.js'; @@ -20,6 +19,7 @@ import { FarmRewardType, FarmVersion } from '../../models/farm.model'; import { PairService } from 'src/modules/pair/services/pair.service'; import { PairAbiService } from 'src/modules/pair/services/pair.abi.service'; import { FarmAbiService } from './farm.abi.service'; +import { TransactionOptions } from 'src/modules/common/transaction.options'; export abstract class TransactionsFarmService { constructor( @@ -114,145 +114,187 @@ export abstract class TransactionsFarmService { return gasLimit + lockedAssetCreateGas; } - async endProduceRewards(farmAddress: string): Promise { - const contract = await this.mxProxy.getFarmSmartContract(farmAddress); - return contract.methodsExplicit - .end_produce_rewards() - .withGasLimit(gasConfig.farms.admin.end_produce_rewards) - .withChainID(mxConfig.chainID) - .buildTransaction() - .toPlainObject(); + async endProduceRewards( + sender: string, + farmAddress: string, + ): Promise { + return await this.mxProxy.getFarmSmartContractTransaction( + farmAddress, + new TransactionOptions({ + sender: sender, + chainID: mxConfig.chainID, + gasLimit: gasConfig.farms.admin.end_produce_rewards, + function: 'end_produce_rewards', + }), + ); } - async startProduceRewards(farmAddress: string): Promise { - const contract = await this.mxProxy.getFarmSmartContract(farmAddress); - return contract.methodsExplicit - .start_produce_rewards() - .withGasLimit(gasConfig.farms.admin.start_produce_rewards) - .withChainID(mxConfig.chainID) - .buildTransaction() - .toPlainObject(); + async startProduceRewards( + sender: string, + farmAddress: string, + ): Promise { + return await this.mxProxy.getFarmSmartContractTransaction( + farmAddress, + new TransactionOptions({ + sender: sender, + chainID: mxConfig.chainID, + gasLimit: gasConfig.farms.admin.start_produce_rewards, + function: 'start_produce_rewards', + }), + ); } async setPerBlockRewardAmount( + sender: string, farmAddress: string, amount: string, ): Promise { - const contract = await this.mxProxy.getFarmSmartContract(farmAddress); - return contract.methodsExplicit - .setPerBlockRewardAmount([new BigUIntValue(new BigNumber(amount))]) - .withGasLimit(gasConfig.farms.admin.setPerBlockRewardAmount) - .withChainID(mxConfig.chainID) - .buildTransaction() - .toPlainObject(); + return await this.mxProxy.getFarmSmartContractTransaction( + farmAddress, + new TransactionOptions({ + sender: sender, + chainID: mxConfig.chainID, + gasLimit: gasConfig.farms.admin.setPerBlockRewardAmount, + function: 'setPerBlockRewardAmount', + arguments: [new BigUIntValue(new BigNumber(amount))], + }), + ); } async setPenaltyPercent( + sender: string, farmAddress: string, percent: number, ): Promise { - const contract = await this.mxProxy.getFarmSmartContract(farmAddress); - return contract.methodsExplicit - .set_penalty_percent([new BigUIntValue(new BigNumber(percent))]) - .withGasLimit(gasConfig.farms.admin.set_penalty_percent) - .withChainID(mxConfig.chainID) - .buildTransaction() - .toPlainObject(); + return await this.mxProxy.getFarmSmartContractTransaction( + farmAddress, + new TransactionOptions({ + sender: sender, + chainID: mxConfig.chainID, + gasLimit: gasConfig.farms.admin.set_penalty_percent, + function: 'set_penalty_percent', + arguments: [new BigUIntValue(new BigNumber(percent))], + }), + ); } async setMinimumFarmingEpochs( + sender: string, farmAddress: string, epochs: number, ): Promise { - const contract = await this.mxProxy.getFarmSmartContract(farmAddress); - return contract.methodsExplicit - .set_minimum_farming_epochs([ - new BigUIntValue(new BigNumber(epochs)), - ]) - .withGasLimit(gasConfig.farms.admin.set_minimum_farming_epochs) - .withChainID(mxConfig.chainID) - .buildTransaction() - .toPlainObject(); + return await this.mxProxy.getFarmSmartContractTransaction( + farmAddress, + new TransactionOptions({ + sender: sender, + chainID: mxConfig.chainID, + gasLimit: gasConfig.farms.admin.set_minimum_farming_epochs, + function: 'set_minimum_farming_epochs', + arguments: [new BigUIntValue(new BigNumber(epochs))], + }), + ); } async setTransferExecGasLimit( + sender: string, farmAddress: string, gasLimit: number, ): Promise { - const contract = await this.mxProxy.getFarmSmartContract(farmAddress); - return contract.methodsExplicit - .set_transfer_exec_gas_limit([ - new BigUIntValue(new BigNumber(gasLimit)), - ]) - .withGasLimit(gasConfig.farms.admin.set_transfer_exec_gas_limit) - .withChainID(mxConfig.chainID) - .buildTransaction() - .toPlainObject(); + return await this.mxProxy.getFarmSmartContractTransaction( + farmAddress, + new TransactionOptions({ + sender: sender, + chainID: mxConfig.chainID, + gasLimit: gasConfig.farms.admin.set_transfer_exec_gas_limit, + function: 'set_transfer_exec_gas_limit', + arguments: [new BigUIntValue(new BigNumber(gasLimit))], + }), + ); } async setBurnGasLimit( + sender: string, farmAddress: string, gasLimit: number, ): Promise { - const contract = await this.mxProxy.getFarmSmartContract(farmAddress); - return contract.methodsExplicit - .set_burn_gas_limit([new BigUIntValue(new BigNumber(gasLimit))]) - .withGasLimit(gasConfig.farms.admin.set_burn_gas_limit) - .withChainID(mxConfig.chainID) - .buildTransaction() - .toPlainObject(); + return await this.mxProxy.getFarmSmartContractTransaction( + farmAddress, + new TransactionOptions({ + sender: sender, + chainID: mxConfig.chainID, + gasLimit: gasConfig.farms.admin.set_burn_gas_limit, + function: 'set_burn_gas_limit', + arguments: [new BigUIntValue(new BigNumber(gasLimit))], + }), + ); } - async pause(farmAddress: string): Promise { - const contract = await this.mxProxy.getFarmSmartContract(farmAddress); - return contract.methodsExplicit - .pause() - .withGasLimit(gasConfig.farms.admin.pause) - .withChainID(mxConfig.chainID) - .buildTransaction() - .toPlainObject(); + async pause( + sender: string, + farmAddress: string, + ): Promise { + return await this.mxProxy.getFarmSmartContractTransaction( + farmAddress, + new TransactionOptions({ + sender: sender, + chainID: mxConfig.chainID, + gasLimit: gasConfig.farms.admin.pause, + function: 'pause', + }), + ); } - async resume(farmAddress: string): Promise { - const contract = await this.mxProxy.getFarmSmartContract(farmAddress); - return contract.methodsExplicit - .resume() - .withGasLimit(gasConfig.farms.admin.resume) - .withChainID(mxConfig.chainID) - .buildTransaction() - .toPlainObject(); + async resume( + sender: string, + farmAddress: string, + ): Promise { + return await this.mxProxy.getFarmSmartContractTransaction( + farmAddress, + new TransactionOptions({ + sender: sender, + chainID: mxConfig.chainID, + gasLimit: gasConfig.farms.admin.resume, + function: 'resume', + }), + ); } async registerFarmToken( + sender: string, farmAddress: string, tokenName: string, tokenTicker: string, decimals: number, ): Promise { - const contract = await this.mxProxy.getFarmSmartContract(farmAddress); - const transactionArgs: TypedValue[] = [ - BytesValue.fromUTF8(tokenName), - BytesValue.fromUTF8(tokenTicker), - new BigUIntValue(new BigNumber(decimals)), - ]; - return contract.methodsExplicit - .registerFarmToken(transactionArgs) - .withGasLimit(gasConfig.farms.admin.registerFarmToken) - .withChainID(mxConfig.chainID) - .buildTransaction() - .toPlainObject(); + return await this.mxProxy.getFarmSmartContractTransaction( + farmAddress, + new TransactionOptions({ + sender: sender, + chainID: mxConfig.chainID, + gasLimit: gasConfig.farms.admin.registerFarmToken, + function: 'registerFarmToken', + arguments: [ + BytesValue.fromUTF8(tokenName), + BytesValue.fromUTF8(tokenTicker), + new BigUIntValue(new BigNumber(decimals)), + ], + }), + ); } async setLocalRolesFarmToken( + sender: string, farmAddress: string, ): Promise { - const contract = await this.mxProxy.getFarmSmartContract(farmAddress); - return contract.methodsExplicit - .setLocalRolesFarmToken() - .withGasLimit(gasConfig.farms.admin.setLocalRolesFarmToken) - .withChainID(mxConfig.chainID) - .buildTransaction() - .toPlainObject(); + return await this.mxProxy.getFarmSmartContractTransaction( + farmAddress, + new TransactionOptions({ + sender: sender, + chainID: mxConfig.chainID, + gasLimit: gasConfig.farms.admin.setLocalRolesFarmToken, + function: 'setLocalRolesFarmToken', + }), + ); } async mergeFarmTokens( @@ -260,24 +302,26 @@ export abstract class TransactionsFarmService { farmAddress: string, payments: InputTokenModel[], ): Promise { - const contract = await this.mxProxy.getFarmSmartContract(farmAddress); - const mappedPayments = payments.map((tokenPayment) => - TokenTransfer.metaEsdtFromBigInteger( - tokenPayment.tokenID, - tokenPayment.nonce, - new BigNumber(tokenPayment.amount), - ), - ); - return contract.methodsExplicit - .mergeFarmTokens() - .withMultiESDTNFTTransfer(mappedPayments) - .withSender(Address.fromString(sender)) - .withGasLimit( - gasConfig.farms['v1.3'].mergeFarmTokensMultiplier * + return await this.mxProxy.getFarmSmartContractTransaction( + farmAddress, + new TransactionOptions({ + sender: sender, + chainID: mxConfig.chainID, + gasLimit: + gasConfig.farms['v1.3'].mergeFarmTokensMultiplier * payments.length, - ) - .withChainID(mxConfig.chainID) - .buildTransaction() - .toPlainObject(); + function: 'mergeFarmTokens', + tokenTransfers: payments.map( + (tokenPayment) => + new TokenTransfer({ + token: new Token({ + identifier: tokenPayment.tokenID, + nonce: BigInt(tokenPayment.nonce), + }), + amount: BigInt(tokenPayment.amount), + }), + ), + }), + ); } } diff --git a/src/modules/farm/farm.transaction.resolver.ts b/src/modules/farm/farm.transaction.resolver.ts index 55bc1050b..8ee303bc9 100644 --- a/src/modules/farm/farm.transaction.resolver.ts +++ b/src/modules/farm/farm.transaction.resolver.ts @@ -49,7 +49,7 @@ export class FarmTransactionResolver { .requireOwner(farmAddress, user.address); return this.transactionFactory .useTransaction(farmAddress) - .endProduceRewards(farmAddress); + .endProduceRewards(user.address, farmAddress); } @UseGuards(JwtOrNativeAdminGuard) @@ -64,7 +64,7 @@ export class FarmTransactionResolver { .requireOwner(farmAddress, user.address); return this.transactionFactory .useTransaction(farmAddress) - .setPerBlockRewardAmount(farmAddress, amount); + .setPerBlockRewardAmount(user.address, farmAddress, amount); } @UseGuards(JwtOrNativeAdminGuard) @@ -78,7 +78,7 @@ export class FarmTransactionResolver { .requireOwner(farmAddress, user.address); return this.transactionFactory .useTransaction(farmAddress) - .startProduceRewards(farmAddress); + .startProduceRewards(user.address, farmAddress); } @UseGuards(JwtOrNativeAdminGuard) @@ -93,7 +93,7 @@ export class FarmTransactionResolver { .requireOwner(farmAddress, user.address); return this.transactionFactory .useTransaction(farmAddress) - .setPenaltyPercent(farmAddress, percent); + .setPenaltyPercent(user.address, farmAddress, percent); } @UseGuards(JwtOrNativeAdminGuard) @@ -108,7 +108,7 @@ export class FarmTransactionResolver { .requireOwner(farmAddress, user.address); return this.transactionFactory .useTransaction(farmAddress) - .setMinimumFarmingEpochs(farmAddress, epochs); + .setMinimumFarmingEpochs(user.address, farmAddress, epochs); } @UseGuards(JwtOrNativeAdminGuard) @@ -123,7 +123,7 @@ export class FarmTransactionResolver { .requireOwner(farmAddress, user.address); return this.transactionFactory .useTransaction(farmAddress) - .setTransferExecGasLimit(farmAddress, gasLimit); + .setTransferExecGasLimit(user.address, farmAddress, gasLimit); } @UseGuards(JwtOrNativeAdminGuard) @@ -138,7 +138,7 @@ export class FarmTransactionResolver { .requireOwner(farmAddress, user.address); return this.transactionFactory .useTransaction(farmAddress) - .setBurnGasLimit(farmAddress, gasLimit); + .setBurnGasLimit(user.address, farmAddress, gasLimit); } @UseGuards(JwtOrNativeAdminGuard) @@ -152,7 +152,7 @@ export class FarmTransactionResolver { .requireOwner(farmAddress, user.address); return this.transactionFactory .useTransaction(farmAddress) - .pause(farmAddress); + .pause(user.address, farmAddress); } @UseGuards(JwtOrNativeAdminGuard) @@ -166,7 +166,7 @@ export class FarmTransactionResolver { .requireOwner(farmAddress, user.address); return this.transactionFactory .useTransaction(farmAddress) - .resume(farmAddress); + .resume(user.address, farmAddress); } @UseGuards(JwtOrNativeAdminGuard) @@ -184,6 +184,7 @@ export class FarmTransactionResolver { return this.transactionFactory .useTransaction(farmAddress) .registerFarmToken( + user.address, farmAddress, tokenDisplayName, tokenTicker, @@ -202,7 +203,7 @@ export class FarmTransactionResolver { .requireOwner(farmAddress, user.address); return this.transactionFactory .useTransaction(farmAddress) - .setLocalRolesFarmToken(farmAddress); + .setLocalRolesFarmToken(user.address, farmAddress); } @UseGuards(JwtOrNativeAuthGuard) @@ -273,7 +274,10 @@ export class FarmTransactionResolver { await this.farmFactory .useService(args.oldFarmAddress) .requireOwner(args.oldFarmAddress, user.address); - return this.farmTransactionV1_2.setFarmMigrationConfig(args); + return this.farmTransactionV1_2.setFarmMigrationConfig( + user.address, + args, + ); } @UseGuards(JwtOrNativeAdminGuard) @@ -288,6 +292,9 @@ export class FarmTransactionResolver { await this.farmFactory .useService(farmAddress) .requireOwner(farmAddress, user.address); - return this.farmTransactionV1_2.stopRewardsAndMigrateRps(farmAddress); + return this.farmTransactionV1_2.stopRewardsAndMigrateRps( + user.address, + farmAddress, + ); } } diff --git a/src/modules/farm/v1.2/services/farm.v1.2.transaction.service.ts b/src/modules/farm/v1.2/services/farm.v1.2.transaction.service.ts index fe6cbb0a0..9a52b6a12 100644 --- a/src/modules/farm/v1.2/services/farm.v1.2.transaction.service.ts +++ b/src/modules/farm/v1.2/services/farm.v1.2.transaction.service.ts @@ -2,10 +2,10 @@ import { Address, AddressValue, BytesValue, + Token, TokenTransfer, } from '@multiversx/sdk-core'; import { Injectable } from '@nestjs/common'; -import BigNumber from 'bignumber.js'; import { mxConfig, gasConfig } from 'src/config'; import { TransactionModel } from 'src/models/transaction.model'; import { PairService } from 'src/modules/pair/services/pair.service'; @@ -23,6 +23,7 @@ import { farmVersion } from 'src/utils/farm.utils'; import { PairAbiService } from 'src/modules/pair/services/pair.abi.service'; import { FarmAbiServiceV1_2 } from './farm.v1.2.abi.service'; import { ErrorLoggerAsync } from '@multiversx/sdk-nestjs-common'; +import { TransactionOptions } from 'src/modules/common/transaction.options'; @Injectable() export class FarmTransactionServiceV1_2 extends TransactionsFarmService { @@ -44,33 +45,32 @@ export class FarmTransactionServiceV1_2 extends TransactionsFarmService { ): Promise { await this.validateInputTokens(args.farmAddress, args.tokens); - const contract = await this.mxProxy.getFarmSmartContract( - args.farmAddress, - ); - - const interaction = args.lockRewards - ? contract.methodsExplicit.enterFarmAndLockRewards([]) - : contract.methodsExplicit.enterFarm([]); const gasLimit = args.tokens.length > 1 ? gasConfig.farms[FarmVersion.V1_2].enterFarm.withTokenMerge : gasConfig.farms[FarmVersion.V1_2].enterFarm.default; - const mappedPayments = args.tokens.map((tokenPayment) => - TokenTransfer.metaEsdtFromBigInteger( - tokenPayment.tokenID, - tokenPayment.nonce, - new BigNumber(tokenPayment.amount), - ), + return await this.mxProxy.getFarmSmartContractTransaction( + args.farmAddress, + new TransactionOptions({ + sender: sender, + chainID: mxConfig.chainID, + gasLimit: gasLimit, + function: args.lockRewards + ? 'enterFarmAndLockRewards' + : 'enterFarm', + tokenTransfers: args.tokens.map( + (tokenPayment) => + new TokenTransfer({ + token: new Token({ + identifier: tokenPayment.tokenID, + nonce: BigInt(tokenPayment.nonce), + }), + amount: BigInt(tokenPayment.amount), + }), + ), + }), ); - - return interaction - .withMultiESDTNFTTransfer(mappedPayments) - .withSender(Address.fromString(sender)) - .withGasLimit(gasLimit) - .withChainID(mxConfig.chainID) - .buildTransaction() - .toPlainObject(); } async exitFarm( @@ -81,29 +81,30 @@ export class FarmTransactionServiceV1_2 extends TransactionsFarmService { ? FarmRewardType.LOCKED_REWARDS : FarmRewardType.UNLOCKED_REWARDS; - const contract = await this.mxProxy.getFarmSmartContract( - args.farmAddress, - ); const gasLimit = await this.getExitFarmGasLimit( args, farmVersion(args.farmAddress), type, ); - return contract.methodsExplicit - .exitFarm() - .withSingleESDTNFTTransfer( - TokenTransfer.metaEsdtFromBigInteger( - args.farmTokenID, - args.farmTokenNonce, - new BigNumber(args.amount), - ), - ) - .withSender(Address.fromString(sender)) - .withGasLimit(gasLimit) - .withChainID(mxConfig.chainID) - .buildTransaction() - .toPlainObject(); + return await this.mxProxy.getFarmSmartContractTransaction( + args.farmAddress, + new TransactionOptions({ + sender: sender, + chainID: mxConfig.chainID, + gasLimit: gasLimit, + function: 'exitFarm', + tokenTransfers: [ + new TokenTransfer({ + token: new Token({ + identifier: args.farmTokenID, + nonce: BigInt(args.farmTokenNonce), + }), + amount: BigInt(args.amount), + }), + ], + }), + ); } async claimRewards( @@ -122,31 +123,30 @@ export class FarmTransactionServiceV1_2 extends TransactionsFarmService { gasConfig.farms[FarmVersion.V1_2][type].claimRewards + lockedAssetCreateGas; - const contract = await this.mxProxy.getFarmSmartContract( + return await this.mxProxy.getFarmSmartContractTransaction( args.farmAddress, + new TransactionOptions({ + sender: sender, + chainID: mxConfig.chainID, + gasLimit: gasLimit, + function: 'claimRewards', + tokenTransfers: [ + new TokenTransfer({ + token: new Token({ + identifier: args.farmTokenID, + nonce: BigInt(args.farmTokenNonce), + }), + amount: BigInt(args.amount), + }), + ], + }), ); - - return contract.methodsExplicit - .claimRewards() - .withSingleESDTNFTTransfer( - TokenTransfer.metaEsdtFromBigInteger( - args.farmTokenID, - args.farmTokenNonce, - new BigNumber(args.amount), - ), - ) - .withSender(Address.fromString(sender)) - .withGasLimit(gasLimit) - .withChainID(mxConfig.chainID) - .buildTransaction() - .toPlainObject(); } async compoundRewards( sender: string, args: CompoundRewardsArgs, ): Promise { - const gasLimit = gasConfig.farms[FarmVersion.V1_2].compoundRewards; const [farmedTokenID, farmingTokenID] = await Promise.all([ this.farmAbi.farmedTokenID(args.farmAddress), this.farmAbi.farmingTokenID(args.farmAddress), @@ -155,81 +155,87 @@ export class FarmTransactionServiceV1_2 extends TransactionsFarmService { if (farmedTokenID !== farmingTokenID) { throw new Error('failed to compound different tokens'); } - const contract = await this.mxProxy.getFarmSmartContract( + + return await this.mxProxy.getFarmSmartContractTransaction( args.farmAddress, + new TransactionOptions({ + sender: sender, + chainID: mxConfig.chainID, + gasLimit: gasConfig.farms[FarmVersion.V1_2].compoundRewards, + function: 'compoundRewards', + tokenTransfers: [ + new TokenTransfer({ + token: new Token({ + identifier: args.farmTokenID, + nonce: BigInt(args.farmTokenNonce), + }), + amount: BigInt(args.amount), + }), + ], + }), ); - - return contract.methodsExplicit - .compoundRewards() - .withSingleESDTNFTTransfer( - TokenTransfer.metaEsdtFromBigInteger( - args.farmTokenID, - args.farmTokenNonce, - new BigNumber(args.amount), - ), - ) - .withSender(Address.fromString(sender)) - .withGasLimit(gasLimit) - .withChainID(mxConfig.chainID) - .buildTransaction() - .toPlainObject(); } async migrateToNewFarm( sender: string, args: ExitFarmArgs, ): Promise { - const contract = await this.mxProxy.getFarmSmartContract( + return await this.mxProxy.getFarmSmartContractTransaction( args.farmAddress, + new TransactionOptions({ + sender: sender, + chainID: mxConfig.chainID, + gasLimit: gasConfig.farms[FarmVersion.V1_2].migrateToNewFarm, + function: 'migrateToNewFarm', + arguments: [new AddressValue(Address.newFromBech32(sender))], + tokenTransfers: [ + new TokenTransfer({ + token: new Token({ + identifier: args.farmTokenID, + nonce: BigInt(args.farmTokenNonce), + }), + amount: BigInt(args.amount), + }), + ], + }), ); - const gasLimit = gasConfig.farms[FarmVersion.V1_2].migrateToNewFarm; - return contract.methodsExplicit - .migrateToNewFarm([new AddressValue(Address.fromString(sender))]) - .withSingleESDTNFTTransfer( - TokenTransfer.metaEsdtFromBigInteger( - args.farmTokenID, - args.farmTokenNonce, - new BigNumber(args.amount), - ), - ) - .withSender(Address.fromString(sender)) - .withGasLimit(gasLimit) - .withChainID(mxConfig.chainID) - .buildTransaction() - .toPlainObject(); } async stopRewardsAndMigrateRps( + sender: string, farmAddress: string, ): Promise { - const contract = await this.mxProxy.getFarmSmartContract(farmAddress); - return contract.methodsExplicit - .stopRewardsAndMigrateRps() - .withGasLimit(gasConfig.farms[FarmVersion.V1_2].stopRewards) - .withChainID(mxConfig.chainID) - .buildTransaction() - .toPlainObject(); + return await this.mxProxy.getFarmSmartContractTransaction( + farmAddress, + new TransactionOptions({ + sender: sender, + chainID: mxConfig.chainID, + gasLimit: gasConfig.farms[FarmVersion.V1_2].stopRewards, + function: 'stopRewardsAndMigrateRps', + }), + ); } async setFarmMigrationConfig( + sender: string, args: FarmMigrationConfigArgs, ): Promise { - const contract = await this.mxProxy.getFarmSmartContract( + return await this.mxProxy.getFarmSmartContractTransaction( args.oldFarmAddress, + new TransactionOptions({ + sender: sender, + chainID: mxConfig.chainID, + gasLimit: gasConfig.farms.admin.setFarmMigrationConfig, + function: 'setFarmMigrationConfig', + arguments: [ + new AddressValue(Address.fromString(args.oldFarmAddress)), + BytesValue.fromUTF8(args.oldFarmTokenID), + new AddressValue(Address.fromString(args.newFarmAddress)), + BytesValue.fromHex( + Address.fromString(args.newLockedFarmAddress).hex(), + ), + ], + }), ); - const transactionArgs = [ - new AddressValue(Address.fromString(args.oldFarmAddress)), - BytesValue.fromUTF8(args.oldFarmTokenID), - new AddressValue(Address.fromString(args.newFarmAddress)), - BytesValue.fromHex( - Address.fromString(args.newLockedFarmAddress).hex(), - ), - ]; - return contract.methodsExplicit - .setFarmMigrationConfig(transactionArgs) - .withGasLimit(gasConfig.farms.admin.setFarmMigrationConfig) - .withChainID(mxConfig.chainID) - .buildTransaction() - .toPlainObject(); } } diff --git a/src/modules/farm/v1.3/services/farm.v1.3.transaction.service.ts b/src/modules/farm/v1.3/services/farm.v1.3.transaction.service.ts index 1f29dc176..421357aa4 100644 --- a/src/modules/farm/v1.3/services/farm.v1.3.transaction.service.ts +++ b/src/modules/farm/v1.3/services/farm.v1.3.transaction.service.ts @@ -12,11 +12,11 @@ import { } from '../../models/farm.args'; import { FarmRewardType, FarmVersion } from '../../models/farm.model'; import { TransactionsFarmService } from '../../base-module/services/farm.transaction.service'; -import { Address, TokenTransfer } from '@multiversx/sdk-core'; -import BigNumber from 'bignumber.js'; +import { Token, TokenTransfer } from '@multiversx/sdk-core'; import { PairAbiService } from 'src/modules/pair/services/pair.abi.service'; import { FarmAbiServiceV1_3 } from './farm.v1.3.abi.service'; import { ErrorLoggerAsync } from '@multiversx/sdk-nestjs-common'; +import { TransactionOptions } from 'src/modules/common/transaction.options'; @Injectable() export class FarmTransactionServiceV1_3 extends TransactionsFarmService { @@ -36,62 +36,62 @@ export class FarmTransactionServiceV1_3 extends TransactionsFarmService { sender: string, args: EnterFarmArgs, ): Promise { - const contract = await this.mxProxy.getFarmSmartContract( - args.farmAddress, - ); + await this.validateInputTokens(args.farmAddress, args.tokens); const gasLimit = args.tokens.length > 1 ? gasConfig.farms[FarmVersion.V1_3].enterFarm.withTokenMerge : gasConfig.farms[FarmVersion.V1_3].enterFarm.default; - await this.validateInputTokens(args.farmAddress, args.tokens); - - const mappedPayments = args.tokens.map((tokenPayment) => - TokenTransfer.metaEsdtFromBigInteger( - tokenPayment.tokenID, - tokenPayment.nonce, - new BigNumber(tokenPayment.amount), - ), + return await this.mxProxy.getFarmSmartContractTransaction( + args.farmAddress, + new TransactionOptions({ + sender: sender, + chainID: mxConfig.chainID, + gasLimit: gasLimit, + function: 'enterFarm', + tokenTransfers: args.tokens.map( + (tokenPayment) => + new TokenTransfer({ + token: new Token({ + identifier: tokenPayment.tokenID, + nonce: BigInt(tokenPayment.nonce), + }), + amount: BigInt(tokenPayment.amount), + }), + ), + }), ); - - return contract.methodsExplicit - .enterFarm() - .withMultiESDTNFTTransfer(mappedPayments) - .withSender(Address.fromString(sender)) - .withGasLimit(gasLimit) - .withChainID(mxConfig.chainID) - .buildTransaction() - .toPlainObject(); } async exitFarm( sender: string, args: ExitFarmArgs, ): Promise { - const contract = await this.mxProxy.getFarmSmartContract( - args.farmAddress, - ); const gasLimit = await this.getExitFarmGasLimit( args, FarmVersion.V1_3, farmType(args.farmAddress), ); - return contract.methodsExplicit - .exitFarm() - .withSingleESDTNFTTransfer( - TokenTransfer.metaEsdtFromBigInteger( - args.farmTokenID, - args.farmTokenNonce, - new BigNumber(args.amount), - ), - ) - .withSender(Address.fromString(sender)) - .withGasLimit(gasLimit) - .withChainID(mxConfig.chainID) - .buildTransaction() - .toPlainObject(); + return await this.mxProxy.getFarmSmartContractTransaction( + args.farmAddress, + new TransactionOptions({ + sender: sender, + chainID: mxConfig.chainID, + gasLimit: gasLimit, + function: 'exitFarm', + tokenTransfers: [ + new TokenTransfer({ + token: new Token({ + identifier: args.farmTokenID, + nonce: BigInt(args.farmTokenNonce), + }), + amount: BigInt(args.amount), + }), + ], + }), + ); } async claimRewards( @@ -108,24 +108,24 @@ export class FarmTransactionServiceV1_3 extends TransactionsFarmService { gasConfig.farms[FarmVersion.V1_3][type].claimRewards + lockedAssetCreateGas; - const contract = await this.mxProxy.getFarmSmartContract( + return await this.mxProxy.getFarmSmartContractTransaction( args.farmAddress, + new TransactionOptions({ + sender: sender, + chainID: mxConfig.chainID, + gasLimit: gasLimit, + function: 'claimRewards', + tokenTransfers: [ + new TokenTransfer({ + token: new Token({ + identifier: args.farmTokenID, + nonce: BigInt(args.farmTokenNonce), + }), + amount: BigInt(args.amount), + }), + ], + }), ); - - return contract.methodsExplicit - .claimRewards() - .withSingleESDTNFTTransfer( - TokenTransfer.metaEsdtFromBigInteger( - args.farmTokenID, - args.farmTokenNonce, - new BigNumber(args.amount), - ), - ) - .withSender(Address.fromString(sender)) - .withGasLimit(gasLimit) - .withChainID(mxConfig.chainID) - .buildTransaction() - .toPlainObject(); } async compoundRewards( @@ -141,23 +141,24 @@ export class FarmTransactionServiceV1_3 extends TransactionsFarmService { if (farmedTokenID !== farmingTokenID) { throw new Error('failed to compound different tokens'); } - const contract = await this.mxProxy.getFarmSmartContract( + + return await this.mxProxy.getFarmSmartContractTransaction( args.farmAddress, + new TransactionOptions({ + sender: sender, + chainID: mxConfig.chainID, + gasLimit: gasLimit, + function: 'compoundRewards', + tokenTransfers: [ + new TokenTransfer({ + token: new Token({ + identifier: args.farmTokenID, + nonce: BigInt(args.farmTokenNonce), + }), + amount: BigInt(args.amount), + }), + ], + }), ); - - return contract.methodsExplicit - .compoundRewards() - .withSingleESDTNFTTransfer( - TokenTransfer.metaEsdtFromBigInteger( - args.farmTokenID, - args.farmTokenNonce, - new BigNumber(args.amount), - ), - ) - .withSender(Address.fromString(sender)) - .withGasLimit(gasLimit) - .withChainID(mxConfig.chainID) - .buildTransaction() - .toPlainObject(); } } diff --git a/src/modules/farm/v2/services/farm.v2.transaction.service.ts b/src/modules/farm/v2/services/farm.v2.transaction.service.ts index b267da25e..02e5f5db0 100644 --- a/src/modules/farm/v2/services/farm.v2.transaction.service.ts +++ b/src/modules/farm/v2/services/farm.v2.transaction.service.ts @@ -1,4 +1,4 @@ -import { Address, TokenTransfer } from '@multiversx/sdk-core'; +import { Token, TokenTransfer } from '@multiversx/sdk-core'; import { Injectable } from '@nestjs/common'; import BigNumber from 'bignumber.js'; import { mxConfig, gasConfig } from 'src/config'; @@ -19,6 +19,7 @@ import { PairService } from 'src/modules/pair/services/pair.service'; import { PairAbiService } from 'src/modules/pair/services/pair.abi.service'; import { MXApiService } from 'src/services/multiversx-communication/mx.api.service'; import { ContextGetterService } from 'src/services/context/context.getter.service'; +import { TransactionOptions } from 'src/modules/common/transaction.options'; @Injectable() export class FarmTransactionServiceV2 extends TransactionsFarmService { @@ -40,33 +41,32 @@ export class FarmTransactionServiceV2 extends TransactionsFarmService { sender: string, args: EnterFarmArgs, ): Promise { - const contract = await this.mxProxy.getFarmSmartContract( - args.farmAddress, - ); + await this.validateInputTokens(args.farmAddress, args.tokens); const gasLimit = args.tokens.length > 1 ? gasConfig.farms[FarmVersion.V2].enterFarm.withTokenMerge : gasConfig.farms[FarmVersion.V2].enterFarm.default; - await this.validateInputTokens(args.farmAddress, args.tokens); - - const mappedPayments = args.tokens.map((tokenPayment) => - TokenTransfer.metaEsdtFromBigInteger( - tokenPayment.tokenID, - tokenPayment.nonce, - new BigNumber(tokenPayment.amount), - ), + return await this.mxProxy.getFarmSmartContractTransaction( + args.farmAddress, + new TransactionOptions({ + sender: sender, + chainID: mxConfig.chainID, + gasLimit: gasLimit, + function: 'enterFarm', + tokenTransfers: args.tokens.map( + (tokenPayment) => + new TokenTransfer({ + token: new Token({ + identifier: tokenPayment.tokenID, + nonce: BigInt(tokenPayment.nonce), + }), + amount: BigInt(tokenPayment.amount), + }), + ), + }), ); - - return contract.methodsExplicit - .enterFarm() - .withMultiESDTNFTTransfer(mappedPayments) - .withSender(Address.fromString(sender)) - .withGasLimit(gasLimit) - .withChainID(mxConfig.chainID) - .buildTransaction() - .toPlainObject(); } async exitFarm( @@ -76,30 +76,33 @@ export class FarmTransactionServiceV2 extends TransactionsFarmService { if (!args.exitAmount && !new BigNumber(args.exitAmount).isPositive()) { throw new Error('Invalid exit amount'); } - const contract = await this.mxProxy.getFarmSmartContract( - args.farmAddress, - ); + const gasLimit = await this.getExitFarmGasLimit( args, FarmVersion.V2, farmType(args.farmAddress), ); - return contract.methodsExplicit - .exitFarm() - .withSingleESDTNFTTransfer( - TokenTransfer.metaEsdtFromBigInteger( - args.farmTokenID, - args.farmTokenNonce, - new BigNumber(args.amount), - ), - ) - .withSender(Address.fromString(sender)) - .withGasLimit(gasLimit) - .withChainID(mxConfig.chainID) - .buildTransaction() - .toPlainObject(); + return await this.mxProxy.getFarmSmartContractTransaction( + args.farmAddress, + new TransactionOptions({ + sender: sender, + chainID: mxConfig.chainID, + gasLimit: gasLimit, + function: 'exitFarm', + tokenTransfers: [ + new TokenTransfer({ + token: new Token({ + identifier: args.farmTokenID, + nonce: BigInt(args.farmTokenNonce), + }), + amount: BigInt(args.amount), + }), + ], + }), + ); } + async claimRewards( sender: string, args: ClaimRewardsArgs, @@ -114,39 +117,39 @@ export class FarmTransactionServiceV2 extends TransactionsFarmService { gasConfig.farms[FarmVersion.V2][type].claimRewards + lockedAssetCreateGas; - const contract = await this.mxProxy.getFarmSmartContract( + return await this.mxProxy.getFarmSmartContractTransaction( args.farmAddress, + new TransactionOptions({ + sender: sender, + chainID: mxConfig.chainID, + gasLimit: gasLimit, + function: 'claimRewards', + tokenTransfers: [ + new TokenTransfer({ + token: new Token({ + identifier: args.farmTokenID, + nonce: BigInt(args.farmTokenNonce), + }), + amount: BigInt(args.amount), + }), + ], + }), ); - - return contract.methodsExplicit - .claimRewards() - .withSingleESDTNFTTransfer( - TokenTransfer.metaEsdtFromBigInteger( - args.farmTokenID, - args.farmTokenNonce, - new BigNumber(args.amount), - ), - ) - .withSender(Address.fromString(sender)) - .withGasLimit(gasLimit) - .withChainID(mxConfig.chainID) - .buildTransaction() - .toPlainObject(); } async claimBoostedRewards( sender: string, farmAddress: string, ): Promise { - const contract = await this.mxProxy.getFarmSmartContract(farmAddress); - - return contract.methodsExplicit - .claimBoostedRewards() - .withSender(Address.fromString(sender)) - .withChainID(mxConfig.chainID) - .withGasLimit(gasConfig.farms[FarmVersion.V2].claimBoostedRewards) - .buildTransaction() - .toPlainObject(); + return await this.mxProxy.getFarmSmartContractTransaction( + farmAddress, + new TransactionOptions({ + sender: sender, + chainID: mxConfig.chainID, + gasLimit: gasConfig.farms[FarmVersion.V2].claimBoostedRewards, + function: 'claimBoostedRewards', + }), + ); } compoundRewards( diff --git a/src/services/multiversx-communication/mx.proxy.service.ts b/src/services/multiversx-communication/mx.proxy.service.ts index 2ea153bf4..2cdb71cf3 100644 --- a/src/services/multiversx-communication/mx.proxy.service.ts +++ b/src/services/multiversx-communication/mx.proxy.service.ts @@ -133,6 +133,28 @@ export class MXProxyService { return await this.getSmartContract(farmAddress, abiPath, 'Farm'); } + async getFarmSmartContractTransaction( + farmAddress: string, + options: TransactionOptions, + ): Promise { + const version = farmVersion(farmAddress); + const type = farmType(farmAddress); + let abiPath = abiConfig.farm[version]; + let contractInterface = `Farm_${version}`; + + if (type !== undefined) { + abiPath = abiConfig.farm[version][type]; + contractInterface = `Farm_${version}_${type}`; + } + + return this.getSmartContractTransaction( + farmAddress, + abiPath, + contractInterface, + options, + ); + } + async getStakingSmartContract( stakeAddress: string, ): Promise { From 0ec66dfc1ddfa1740c20c4e0e76b07e02136c941 Mon Sep 17 00:00:00 2001 From: hschiau Date: Thu, 26 Sep 2024 17:35:47 +0300 Subject: [PATCH 2/2] SERVICES-2621: fix unit tests --- .../specs/farm.transactions.service.spec.ts | 69 +++++++++++++------ 1 file changed, 49 insertions(+), 20 deletions(-) diff --git a/src/modules/farm/specs/farm.transactions.service.spec.ts b/src/modules/farm/specs/farm.transactions.service.spec.ts index 1e938dd26..e7a964ded 100644 --- a/src/modules/farm/specs/farm.transactions.service.spec.ts +++ b/src/modules/farm/specs/farm.transactions.service.spec.ts @@ -25,6 +25,9 @@ import { ElasticSearchModule } from 'src/services/elastic-search/elastic.search. describe('FarmService', () => { let module: TestingModule; + const senderAddress = Address.newFromHex( + '0000000000000000000000000000000000000000000000000000000000000001', + ).toBech32(); beforeAll(async () => { module = await Test.createTestingModule({ @@ -237,19 +240,22 @@ describe('FarmService', () => { FarmTransactionServiceV1_2, ); - const transaction = await transactionV1_2.setFarmMigrationConfig({ - oldFarmAddress: - 'erd1qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqssfuwnk5', - oldFarmTokenID: 'EGLDMEXFL-abcdef', - newFarmAddress: Address.Zero().bech32(), - newLockedFarmAddress: Address.Zero().bech32(), - }); + const transaction = await transactionV1_2.setFarmMigrationConfig( + senderAddress, + { + oldFarmAddress: + 'erd1qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqssfuwnk5', + oldFarmTokenID: 'EGLDMEXFL-abcdef', + newFarmAddress: Address.Zero().bech32(), + newLockedFarmAddress: Address.Zero().bech32(), + }, + ); expect(transaction).toEqual({ nonce: 0, value: '0', receiver: 'erd1qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqssfuwnk5', - sender: '', + sender: senderAddress, receiverUsername: undefined, senderUsername: undefined, gasPrice: 1000000000, @@ -272,6 +278,7 @@ describe('FarmService', () => { ); const transaction = await transactionV1_2.stopRewardsAndMigrateRps( + senderAddress, 'erd1qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqssfuwnk5', ); expect(transaction).toEqual({ @@ -279,7 +286,7 @@ describe('FarmService', () => { value: '0', receiver: 'erd1qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqssfuwnk5', - sender: '', + sender: senderAddress, receiverUsername: undefined, senderUsername: undefined, gasPrice: 1000000000, @@ -302,6 +309,7 @@ describe('FarmService', () => { let error = null; try { await transactionV1_2.endProduceRewards( + senderAddress, 'erd1qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqssfuwnk5', ); } catch (e) { @@ -310,6 +318,7 @@ describe('FarmService', () => { expect(error).toBeDefined(); const transaction = await transactionV1_2.endProduceRewards( + senderAddress, 'erd1qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqcs2zduud', ); expect(transaction).toEqual({ @@ -317,7 +326,7 @@ describe('FarmService', () => { value: '0', receiver: 'erd1qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqcs2zduud', - sender: '', + sender: senderAddress, receiverUsername: undefined, senderUsername: undefined, gasPrice: 1000000000, @@ -340,6 +349,7 @@ describe('FarmService', () => { let error = null; try { await transactionV1_2.startProduceRewards( + senderAddress, 'erd1qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqssfuwnk5', ); } catch (e) { @@ -348,6 +358,7 @@ describe('FarmService', () => { expect(error).toBeDefined(); const transaction = await transactionV1_2.startProduceRewards( + senderAddress, 'erd1qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqssfuwnk5', ); expect(transaction).toEqual({ @@ -355,7 +366,7 @@ describe('FarmService', () => { value: '0', receiver: 'erd1qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqssfuwnk5', - sender: '', + sender: senderAddress, receiverUsername: undefined, senderUsername: undefined, gasPrice: 1000000000, @@ -378,6 +389,7 @@ describe('FarmService', () => { let error = null; try { await transactionV1_2.setPerBlockRewardAmount( + senderAddress, 'erd1qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqssfuwnk5', '1000000000000', ); @@ -387,6 +399,7 @@ describe('FarmService', () => { expect(error).toBeDefined(); const transaction = await transactionV1_2.setPerBlockRewardAmount( + senderAddress, 'erd1qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqssfuwnk5', '1000000000000', ); @@ -395,7 +408,7 @@ describe('FarmService', () => { value: '0', receiver: 'erd1qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqssfuwnk5', - sender: '', + sender: senderAddress, receiverUsername: undefined, senderUsername: undefined, gasPrice: 1000000000, @@ -420,6 +433,7 @@ describe('FarmService', () => { let error = null; try { await transactionV1_2.setPenaltyPercent( + senderAddress, 'erd1qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqssfuwnk5', 5, ); @@ -429,6 +443,7 @@ describe('FarmService', () => { expect(error).toBeDefined(); const transaction = await transactionV1_2.setPenaltyPercent( + senderAddress, 'erd1qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqssfuwnk5', 5, ); @@ -437,7 +452,7 @@ describe('FarmService', () => { value: '0', receiver: 'erd1qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqssfuwnk5', - sender: '', + sender: senderAddress, receiverUsername: undefined, senderUsername: undefined, gasPrice: 1000000000, @@ -460,6 +475,7 @@ describe('FarmService', () => { let error = null; try { await transactionV1_2.setMinimumFarmingEpochs( + senderAddress, 'erd1qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqssfuwnk5', 10, ); @@ -469,6 +485,7 @@ describe('FarmService', () => { expect(error).toBeDefined(); const transaction = await transactionV1_2.setMinimumFarmingEpochs( + senderAddress, 'erd1qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqssfuwnk5', 10, ); @@ -477,7 +494,7 @@ describe('FarmService', () => { value: '0', receiver: 'erd1qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqssfuwnk5', - sender: '', + sender: senderAddress, receiverUsername: undefined, senderUsername: undefined, gasPrice: 1000000000, @@ -500,6 +517,7 @@ describe('FarmService', () => { let error = null; try { await transactionV1_2.setTransferExecGasLimit( + senderAddress, 'erd1qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqssfuwnk5', 100000000, ); @@ -509,6 +527,7 @@ describe('FarmService', () => { expect(error).toBeDefined(); const transaction = await transactionV1_2.setTransferExecGasLimit( + senderAddress, 'erd1qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqssfuwnk5', 100000000, ); @@ -517,7 +536,7 @@ describe('FarmService', () => { value: '0', receiver: 'erd1qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqssfuwnk5', - sender: '', + sender: senderAddress, receiverUsername: undefined, senderUsername: undefined, gasPrice: 1000000000, @@ -542,6 +561,7 @@ describe('FarmService', () => { let error = null; try { await transactionV1_2.setBurnGasLimit( + senderAddress, 'erd1qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqssfuwnk5', 100000000, ); @@ -551,6 +571,7 @@ describe('FarmService', () => { expect(error).toBeDefined(); const transaction = await transactionV1_2.setBurnGasLimit( + senderAddress, 'erd1qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqcs2zduud', 100000000, ); @@ -559,7 +580,7 @@ describe('FarmService', () => { value: '0', receiver: 'erd1qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqcs2zduud', - sender: '', + sender: senderAddress, receiverUsername: undefined, senderUsername: undefined, gasPrice: 1000000000, @@ -582,6 +603,7 @@ describe('FarmService', () => { let error = null; try { await transactionV1_2.pause( + senderAddress, 'erd1qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqssfuwnk5', ); } catch (e) { @@ -590,6 +612,7 @@ describe('FarmService', () => { expect(error).toBeDefined(); const transaction = await transactionV1_2.pause( + senderAddress, 'erd1qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqssfuwnk5', ); expect(transaction).toEqual({ @@ -597,7 +620,7 @@ describe('FarmService', () => { value: '0', receiver: 'erd1qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqssfuwnk5', - sender: '', + sender: senderAddress, receiverUsername: undefined, senderUsername: undefined, gasPrice: 1000000000, @@ -620,6 +643,7 @@ describe('FarmService', () => { let error = null; try { await transactionV1_2.resume( + senderAddress, 'erd1qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqssfuwnk5', ); } catch (e) { @@ -628,6 +652,7 @@ describe('FarmService', () => { expect(error).toBeDefined(); const transaction = await transactionV1_2.resume( + senderAddress, 'erd1qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqssfuwnk5', ); expect(transaction).toEqual({ @@ -635,7 +660,7 @@ describe('FarmService', () => { value: '0', receiver: 'erd1qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqssfuwnk5', - sender: '', + sender: senderAddress, receiverUsername: undefined, senderUsername: undefined, gasPrice: 1000000000, @@ -658,6 +683,7 @@ describe('FarmService', () => { let error = null; try { await transactionV1_2.registerFarmToken( + senderAddress, 'erd1qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqssfuwnk5', 'FarmingToken12', 'T1T2-1234', @@ -669,6 +695,7 @@ describe('FarmService', () => { expect(error).toBeDefined(); const transaction = await transactionV1_2.registerFarmToken( + senderAddress, 'erd1qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqssfuwnk5', 'FarmingToken12', 'T1T2-1234', @@ -679,7 +706,7 @@ describe('FarmService', () => { value: '0', receiver: 'erd1qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqssfuwnk5', - sender: '', + sender: senderAddress, receiverUsername: undefined, senderUsername: undefined, gasPrice: 1000000000, @@ -704,6 +731,7 @@ describe('FarmService', () => { let error = null; try { await transactionV1_2.setLocalRolesFarmToken( + senderAddress, 'erd1qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqssfuwnk5', ); } catch (e) { @@ -712,6 +740,7 @@ describe('FarmService', () => { expect(error).toBeDefined(); const transaction = await transactionV1_2.setLocalRolesFarmToken( + senderAddress, 'erd1qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqssfuwnk5', ); expect(transaction).toEqual({ @@ -719,7 +748,7 @@ describe('FarmService', () => { value: '0', receiver: 'erd1qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqssfuwnk5', - sender: '', + sender: senderAddress, receiverUsername: undefined, senderUsername: undefined, gasPrice: 1000000000,