Skip to content

Commit

Permalink
update event caller address for all events
Browse files Browse the repository at this point in the history
  • Loading branch information
GuticaStefan committed Nov 22, 2024
1 parent b490f96 commit f8789d5
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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)

Check failure on line 145 in apps/api/src/endpoints/data-integration/data-integration.service.ts

View workflow job for this annotation

GitHub Actions / build (16.x)

Missing semicolon

const transactions = await this.indexerService.getTxDetails(txHashes);

const txToCallerMap = new Map<string, string>(
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)

Check failure on line 161 in apps/api/src/endpoints/data-integration/data-integration.service.ts

View workflow job for this annotation

GitHub Actions / build (16.x)

Missing semicolon
}
}
21 changes: 1 addition & 20 deletions libs/common/src/providers/xexchange/xexchange.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -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<string, string>(
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;
}

Expand Down

0 comments on commit f8789d5

Please sign in to comment.