From 20cb7778b2dba31c4b237b4e671b1077fd437ec3 Mon Sep 17 00:00:00 2001 From: Rares <6453351+raress96@users.noreply.github.com> Date: Tue, 1 Oct 2024 10:12:23 +0300 Subject: [PATCH] Take into account esdt issue cost as fee in case of its execute. --- .../approvals.processor.service.ts | 1 + .../cross-chain-transaction.processor.service.ts | 8 +++++++- .../cross-chain-transaction.processor.spec.ts | 3 +++ .../processors/gateway.processor.spec.ts | 14 +++++++------- .../processors/gateway.processor.ts | 14 ++++++++++++-- 5 files changed, 30 insertions(+), 10 deletions(-) diff --git a/apps/axelar-event-processor/src/approvals-processor/approvals.processor.service.ts b/apps/axelar-event-processor/src/approvals-processor/approvals.processor.service.ts index 8635798..fabc74c 100644 --- a/apps/axelar-event-processor/src/approvals-processor/approvals.processor.service.ts +++ b/apps/axelar-event-processor/src/approvals-processor/approvals.processor.service.ts @@ -209,6 +209,7 @@ export class ApprovalsProcessorService { } private async processExecuteTask(response: ExecuteTask, taskItemId: string) { + // TODO: Should we also save response.availableGasBalance and check if enough gas was payed before executing? const messageApproved = await this.messageApprovedRepository.create({ sourceChain: response.message.sourceChain, messageId: response.message.messageID, diff --git a/apps/mvx-event-processor/src/cross-chain-transaction-processor/cross-chain-transaction.processor.service.ts b/apps/mvx-event-processor/src/cross-chain-transaction-processor/cross-chain-transaction.processor.service.ts index 92f1915..f9063a4 100644 --- a/apps/mvx-event-processor/src/cross-chain-transaction-processor/cross-chain-transaction.processor.service.ts +++ b/apps/mvx-event-processor/src/cross-chain-transaction-processor/cross-chain-transaction.processor.service.ts @@ -67,7 +67,13 @@ export class CrossChainTransactionProcessorService { const address = rawEvent.address.bech32(); if (address === this.contractGateway) { - const event = await this.gatewayProcessor.handleGatewayEvent(rawEvent, transaction, index, fee); + const event = await this.gatewayProcessor.handleGatewayEvent( + rawEvent, + transaction, + index, + fee, + transaction.value, + ); if (event) { eventsToSend.push(event); diff --git a/apps/mvx-event-processor/src/cross-chain-transaction-processor/cross-chain-transaction.processor.spec.ts b/apps/mvx-event-processor/src/cross-chain-transaction-processor/cross-chain-transaction.processor.spec.ts index c593b99..534c910 100644 --- a/apps/mvx-event-processor/src/cross-chain-transaction-processor/cross-chain-transaction.processor.spec.ts +++ b/apps/mvx-event-processor/src/cross-chain-transaction-processor/cross-chain-transaction.processor.spec.ts @@ -171,6 +171,7 @@ describe('CrossChainTransactionProcessor', () => { transaction.txHash = 'txHash'; transaction.status = 'success'; transaction.fee = '1000'; + transaction.value = '0'; it('Should handle multiple events', async () => { // @ts-ignore @@ -195,6 +196,7 @@ describe('CrossChainTransactionProcessor', () => { expect.any(TransactionOnNetwork), 1, '1000', + '0', ); expect(axelarGmpApi.postEvents).toHaveBeenCalledTimes(1); @@ -237,6 +239,7 @@ describe('CrossChainTransactionProcessor', () => { expect.any(TransactionOnNetwork), 1, '1000', + '0' ); expect(axelarGmpApi.postEvents).toHaveBeenCalledTimes(1); diff --git a/apps/mvx-event-processor/src/cross-chain-transaction-processor/processors/gateway.processor.spec.ts b/apps/mvx-event-processor/src/cross-chain-transaction-processor/processors/gateway.processor.spec.ts index 1f9c8b5..3111db3 100644 --- a/apps/mvx-event-processor/src/cross-chain-transaction-processor/processors/gateway.processor.spec.ts +++ b/apps/mvx-event-processor/src/cross-chain-transaction-processor/processors/gateway.processor.spec.ts @@ -93,7 +93,7 @@ describe('GatewayProcessor', () => { topics: [BinaryUtils.base64Encode(Events.NATIVE_GAS_PAID_FOR_CONTRACT_CALL_EVENT)], }); - const result = await service.handleGatewayEvent(rawEvent, createMock(), 0, '100'); + const result = await service.handleGatewayEvent(rawEvent, createMock(), 0, '100', '0'); expect(result).toBeUndefined(); expect(gatewayContract.decodeContractCallEvent).not.toHaveBeenCalled(); @@ -124,7 +124,7 @@ describe('GatewayProcessor', () => { const transaction = createMock(); transaction.hash = 'txHash'; - const result = await service.handleGatewayEvent(rawEvent, transaction, 0, '100'); + const result = await service.handleGatewayEvent(rawEvent, transaction, 0, '100', '0'); expect(gatewayContract.decodeContractCallEvent).toBeCalledTimes(1); @@ -175,7 +175,7 @@ describe('GatewayProcessor', () => { transaction.hash = 'txHash'; transaction.sender = Address.newFromBech32('erd1qqqqqqqqqqqqqpgqzqvm5ywqqf524efwrhr039tjs29w0qltkklsa05pk7'); - const result = await service.handleGatewayEvent(rawEvent, transaction, 0, '100'); + const result = await service.handleGatewayEvent(rawEvent, transaction, 0, '100', '0'); expect(gatewayContract.decodeMessageApprovedEvent).toHaveBeenCalledTimes(1); @@ -237,7 +237,7 @@ describe('GatewayProcessor', () => { messageApprovedRepository.findBySourceChainAndMessageId.mockReturnValueOnce(Promise.resolve(messageApproved)); - const result = await service.handleGatewayEvent(rawEvent, transaction, 0, '100'); + const result = await service.handleGatewayEvent(rawEvent, transaction, 0, '100', '0'); expect(gatewayContract.decodeMessageExecutedEvent).toHaveBeenCalledTimes(1); @@ -271,7 +271,7 @@ describe('GatewayProcessor', () => { it('Should handle event no contract call approved', async () => { messageApprovedRepository.findBySourceChainAndMessageId.mockReturnValueOnce(Promise.resolve(null)); - const result = await service.handleGatewayEvent(rawEvent, transaction, 0, '100'); + const result = await service.handleGatewayEvent(rawEvent, transaction, 0, '100', '20'); expect(gatewayContract.decodeMessageExecutedEvent).toHaveBeenCalledTimes(1); @@ -288,7 +288,7 @@ describe('GatewayProcessor', () => { expect(event.messageID).toBe('messageId'); expect(event.sourceChain).toBe('ethereum'); expect(event.cost).toEqual({ - amount: '100', + amount: '120', }); expect(event.meta).toEqual({ txID: 'txHash', @@ -316,7 +316,7 @@ describe('GatewayProcessor', () => { it('Should handle event', async () => { gatewayContract.decodeSignersRotatedEvent.mockReturnValueOnce(weightedSigners); - const result = await service.handleGatewayEvent(rawEvent, createMock(), 0, '100'); + const result = await service.handleGatewayEvent(rawEvent, createMock(), 0, '100', '0'); expect(gatewayContract.decodeSignersRotatedEvent).toHaveBeenCalledTimes(1); diff --git a/apps/mvx-event-processor/src/cross-chain-transaction-processor/processors/gateway.processor.ts b/apps/mvx-event-processor/src/cross-chain-transaction-processor/processors/gateway.processor.ts index baab616..5db522b 100644 --- a/apps/mvx-event-processor/src/cross-chain-transaction-processor/processors/gateway.processor.ts +++ b/apps/mvx-event-processor/src/cross-chain-transaction-processor/processors/gateway.processor.ts @@ -13,6 +13,7 @@ import CallEvent = Components.Schemas.CallEvent; import MessageApprovedEvent = Components.Schemas.MessageApprovedEvent; import Event = Components.Schemas.Event; import MessageExecutedEvent = Components.Schemas.MessageExecutedEvent; +import BigNumber from 'bignumber.js'; @Injectable() export class GatewayProcessor { @@ -30,6 +31,7 @@ export class GatewayProcessor { transaction: TransactionOnNetwork, index: number, fee: string, + transactionValue: string, ): Promise { const eventName = rawEvent.topics?.[0]?.toString(); @@ -42,7 +44,14 @@ export class GatewayProcessor { } if (rawEvent.identifier === EventIdentifiers.VALIDATE_MESSAGE && eventName === Events.MESSAGE_EXECUTED_EVENT) { - return await this.handleMessageExecutedEvent(rawEvent, transaction.sender.bech32(), transaction.hash, index, fee); + return await this.handleMessageExecutedEvent( + rawEvent, + transaction.sender.bech32(), + transaction.hash, + index, + fee, + transactionValue, + ); } if (rawEvent.identifier === EventIdentifiers.ROTATE_SIGNERS && eventName === Events.SIGNERS_ROTATED_EVENT) { @@ -128,6 +137,7 @@ export class GatewayProcessor { txHash: string, index: number, fee: string, + transactionValue: string, ): Promise { const messageExecutedEvent = this.gatewayContract.decodeMessageExecutedEvent(rawEvent); @@ -152,7 +162,7 @@ export class GatewayProcessor { messageID: messageExecutedEvent.messageId, sourceChain: messageExecutedEvent.sourceChain, cost: { - amount: fee, + amount: new BigNumber(fee).plus(transactionValue, 10).toFixed(), // Also add transaction value to fee, i.e in case of ITS execute with ESDT issue cost }, meta: { txID: txHash,