diff --git a/apps/api/src/endpoints/data-integration/data-integration.service.ts b/apps/api/src/endpoints/data-integration/data-integration.service.ts index 2c0c63b..408ddee 100644 --- a/apps/api/src/endpoints/data-integration/data-integration.service.ts +++ b/apps/api/src/endpoints/data-integration/data-integration.service.ts @@ -4,7 +4,7 @@ import { IndexerService, JoinExitEvent, LatestBlockResponse, MultiversXApiService, PairResponse, SwapEvent, XExchangeService, } from "@mvx-monorepo/common"; -import { OriginLogger } from "@multiversx/sdk-nestjs-common"; +import { AddressUtils, OriginLogger } from "@multiversx/sdk-nestjs-common"; import { IProviderService } from "@mvx-monorepo/common/providers/interface"; import { GeneralEvent } from "@mvx-monorepo/common/providers/entities/general.event"; import { OneDexService } from "@mvx-monorepo/common/providers"; @@ -83,6 +83,8 @@ export class DataIntegrationService { allEvents.push(...event); } + await this.updateEventsCaller(allEvents); + const sortedEvents = allEvents.sort((a, b) => { if (a.block.blockTimestamp !== b.block.blockTimestamp) { return a.block.blockTimestamp - b.block.blockTimestamp; @@ -136,4 +138,26 @@ export class DataIntegrationService { } return events; } + + private async updateEventsCaller(events: ({ block: Block } & (SwapEvent | JoinExitEvent))[]) { + const filteredEvents = events.filter(event => AddressUtils.isSmartContractAddress(event.maker)); + + const txHashes = filteredEvents.map(event => event.txnId) + + const transactions = await this.indexerService.getTxDetails(txHashes); + + const txToCallerMap = new Map( + transactions.map(transaction => [transaction.txHash, transaction.sender]) + ); + + for (const event of events) { + if (AddressUtils.isSmartContractAddress(event.maker)) { + const callerFromMap = txToCallerMap.get(event.txnId); + if (callerFromMap) { + event.maker = callerFromMap; + } + } + } + console.log(txToCallerMap) + } } diff --git a/libs/common/src/providers/xexchange/xexchange.service.ts b/libs/common/src/providers/xexchange/xexchange.service.ts index 8aeaa55..d440cb5 100644 --- a/libs/common/src/providers/xexchange/xexchange.service.ts +++ b/libs/common/src/providers/xexchange/xexchange.service.ts @@ -16,7 +16,7 @@ import { PairMetadata } from "../entities"; import { CacheService } from "@multiversx/sdk-nestjs-cache"; import BigNumber from "bignumber.js"; import { IndexerService } from "../../services/indexer"; -import { AddressUtils, BinaryUtils, OriginLogger } from "@multiversx/sdk-nestjs-common"; +import { BinaryUtils, OriginLogger } from "@multiversx/sdk-nestjs-common"; import { PAIR_EVENTS } from "@multiversx/sdk-exchange"; import { MultiversXApiService } from "../../services/multiversx.api"; import { PerformanceProfiler } from "@multiversx/sdk-nestjs-monitoring"; @@ -203,25 +203,6 @@ export class XExchangeService implements IProviderService { } - const filteredEvents = events.filter(event => AddressUtils.isSmartContractAddress(event.caller)); - - const txHashes = filteredEvents.map(event => event.txHash) - - const transactions = await this.indexerService.getTxDetails(txHashes); - - const txToCallerMap = new Map( - transactions.map(transaction => [transaction.txHash, transaction.sender]) - ); - - for (const event of events) { - if (AddressUtils.isSmartContractAddress(event.caller)) { - const callerFromMap = txToCallerMap.get(event.txHash); - if (callerFromMap) { - event.caller = callerFromMap; - } - } - } - return events; }