From 139034164457400f432013e7254617494342da37 Mon Sep 17 00:00:00 2001 From: danielailie Date: Wed, 21 Feb 2024 14:07:54 +0200 Subject: [PATCH 01/18] Add notify endpoint --- src/modules/metrics/metrics.controller.ts | 12 +- src/modules/metrics/rabbitEvent.ts | 21 ++++ .../marketplace-events.service.ts | 105 ++++++++++++++++++ src/private.app.module.ts | 44 +++++++- 4 files changed, 179 insertions(+), 3 deletions(-) create mode 100644 src/modules/metrics/rabbitEvent.ts diff --git a/src/modules/metrics/metrics.controller.ts b/src/modules/metrics/metrics.controller.ts index e25f24eb1..197eb1733 100644 --- a/src/modules/metrics/metrics.controller.ts +++ b/src/modules/metrics/metrics.controller.ts @@ -1,8 +1,12 @@ -import { Controller, Get } from '@nestjs/common'; +import { Controller, Get, HttpStatus, Post } from '@nestjs/common'; import { MetricsCollector } from './metrics.collector'; +import { RabbitEvent } from './rabbitEvent'; +import { MarketplaceEventsService } from '../rabbitmq/blockchain-events/marketplace-events.service'; +import { MarketplaceTypeEnum } from '../marketplaces/models/MarketplaceType.enum'; @Controller() export class MetricsController { + constructor(private readonly marketplaceEvents: MarketplaceEventsService) {} @Get('/metrics') async getMetrics(): Promise { return await MetricsCollector.getMetrics(); @@ -12,4 +16,10 @@ export class MetricsController { async getHello(): Promise { return 'hello'; } + + @Post('/event') + async notify(payload: RabbitEvent): Promise { + await this.marketplaceEvents.handleNftEvents(payload.events, payload.hash, MarketplaceTypeEnum.External); + return HttpStatus.OK; + } } diff --git a/src/modules/metrics/rabbitEvent.ts b/src/modules/metrics/rabbitEvent.ts new file mode 100644 index 000000000..02c9a702c --- /dev/null +++ b/src/modules/metrics/rabbitEvent.ts @@ -0,0 +1,21 @@ +export class RabbitEvent { + hash!: string; + shardId!: number; + timestamp!: number; + events: RabbitEventLog[] = []; + constructor(init: Partial) { + Object.assign(this, init); + } +} + +export class RabbitEventLog { + address!: string; + identifier!: string; + topics: string[] = []; + data: string = ''; + txHash!: string; + additionalData: string[] = []; + constructor(init?: Partial) { + Object.assign(this, init); + } +} diff --git a/src/modules/rabbitmq/blockchain-events/marketplace-events.service.ts b/src/modules/rabbitmq/blockchain-events/marketplace-events.service.ts index 4b63dde53..6743cb452 100644 --- a/src/modules/rabbitmq/blockchain-events/marketplace-events.service.ts +++ b/src/modules/rabbitmq/blockchain-events/marketplace-events.service.ts @@ -124,4 +124,109 @@ export class MarketplaceEventsService { } } } + + public async handleNftEvents(auctionEvents: any[], hash: string, marketplaceType: MarketplaceTypeEnum) { + for (let event of auctionEvents) { + switch (event.identifier) { + case AuctionEventEnum.BidEvent: + case KroganSwapAuctionEventEnum.Bid: + // await this.bidEventHandler.handle(event, hash, marketplaceType); + console.log({ identifier: event.identifier }); + + break; + case AuctionEventEnum.BuySftEvent: + case ExternalAuctionEventEnum.Buy: + case ExternalAuctionEventEnum.BulkBuy: + case ExternalAuctionEventEnum.BuyFor: + case ExternalAuctionEventEnum.BuyNft: + case KroganSwapAuctionEventEnum.Purchase: + const eventName = Buffer.from(event.topics[0], 'base64').toString(); + if (eventName === ExternalAuctionEventEnum.UpdateOffer || eventName === KroganSwapAuctionEventEnum.UpdateListing) { + this.logger.log(`${eventName} event detected for hash '${hash}' for marketplace ${event.address}, ignore it for the moment`); + continue; + } + console.log({ identifier: event.identifier }); + // await this.buyEventHandler.handle(event, hash, marketplaceType); + break; + case AuctionEventEnum.WithdrawEvent: + case KroganSwapAuctionEventEnum.WithdrawSwap: + case ExternalAuctionEventEnum.ClaimBackNft: + case ExternalAuctionEventEnum.ReturnListing: + if (Buffer.from(event.topics[0], 'base64').toString() === ExternalAuctionEventEnum.UpdateOffer) { + this.logger.log( + `${event.topics[0]} event detected for hash '${hash}' for marketplace ${event.addreses}, ignore it for the moment`, + ); + continue; + } + console.log({ identifier: event.identifier }); + // await this.withdrawAuctionEventHandler.handle(event, hash, marketplaceType); + break; + case AuctionEventEnum.EndAuctionEvent: + console.log({ identifier: event.identifier }); + // await this.endAuctionEventHandler.handle(event, hash, marketplaceType); + break; + case AuctionEventEnum.AuctionTokenEvent: + case ExternalAuctionEventEnum.Listing: + case ExternalAuctionEventEnum.ListNftOnMarketplace: + case KroganSwapAuctionEventEnum.NftSwap: + console.log({ identifier: event.identifier }); + // await this.startAuctionEventHandler.handle(event, hash, marketplaceType); + break; + case ExternalAuctionEventEnum.ChangePrice: + case ExternalAuctionEventEnum.UpdatePrice: + console.log({ identifier: event.identifier }); + // await this.updatePriceEventHandler.handle(event, hash, marketplaceType); + break; + case ExternalAuctionEventEnum.UpdateListing: { + console.log({ identifier: event.identifier }); + // await this.updateListingEventHandler.handle(event, hash, marketplaceType); + break; + } + case ExternalAuctionEventEnum.AcceptOffer: + case ExternalAuctionEventEnum.AcceptOfferFromAuction: + const acceptOfferEventName = Buffer.from(event.topics[0], 'base64').toString(); + if (acceptOfferEventName === ExternalAuctionEventEnum.UserDeposit) { + continue; + } + + console.log({ identifier: event.identifier }); + // if (acceptOfferEventName === ExternalAuctionEventEnum.EndTokenEvent) { + // await this.withdrawAuctionEventHandler.handle(event, hash, marketplaceType); + // } else { + // await this.acceptOfferEventHandler.handle(event, hash, marketplaceType); + // } + + break; + case AuctionEventEnum.WithdrawAuctionAndAcceptOffer: + console.log({ identifier: event.identifier }); + // if (Buffer.from(event.topics[0], 'base64').toString() === AuctionEventEnum.Accept_offer_token_event) { + // await this.acceptOfferEventHandler.handle(event, hash, marketplaceType); + // } else { + // await this.withdrawAuctionEventHandler.handle(event, hash, marketplaceType); + // } + break; + case ExternalAuctionEventEnum.AcceptGlobalOffer: + console.log({ identifier: event.identifier }); + // await this.acceptGlobalOfferEventHandler.handle(event, hash, marketplaceType); + break; + case AuctionEventEnum.SendOffer: + console.log({ identifier: event.identifier }); + // await this.sendOfferEventHandler.handle(event, hash, marketplaceType); + break; + case AuctionEventEnum.WithdrawOffer: + console.log({ identifier: event.identifier }); + // await this.withdrawOfferEventHandler.handle(event, hash, marketplaceType); + break; + case KroganSwapAuctionEventEnum.NftSwapUpdate: + case KroganSwapAuctionEventEnum.NftSwapExtend: + console.log({ identifier: event.identifier }); + // await this.swapUpdateEventHandler.handle(event, hash, marketplaceType); + break; + case MarketplaceEventEnum.SCUpgrade: { + console.log({ identifier: event.identifier }); + // await this.slackReportService.sendScUpgradeNotification(event.address); + } + } + } + } } diff --git a/src/private.app.module.ts b/src/private.app.module.ts index aef270009..79e6051a3 100644 --- a/src/private.app.module.ts +++ b/src/private.app.module.ts @@ -1,4 +1,4 @@ -import { Logger, Module } from '@nestjs/common'; +import { Logger, Module, forwardRef } from '@nestjs/common'; import { TypeOrmModule } from '@nestjs/typeorm'; import { CommonModule } from './common.module'; import { CachingController } from './common/services/caching/caching.controller'; @@ -14,6 +14,24 @@ import { ScamModule } from './modules/scam/scam.module'; import { NftTraitsModule } from './modules/nft-traits/nft-traits.module'; import { CacheEventsPublisherModule } from './modules/rabbitmq/cache-invalidation/cache-invalidation-publisher/change-events-publisher.module'; import * as ormconfig from './ormconfig'; +import { MarketplaceEventsService } from './modules/rabbitmq/blockchain-events/marketplace-events.service'; +import { FeedEventsSenderService } from './modules/rabbitmq/blockchain-events/feed-events.service'; +import { AcceptGlobalOfferEventHandler } from './modules/rabbitmq/blockchain-events/handlers/acceptGlobalOffer-event.handler'; +import { AcceptOfferEventHandler } from './modules/rabbitmq/blockchain-events/handlers/acceptOffer-event.handler'; +import { BidEventHandler } from './modules/rabbitmq/blockchain-events/handlers/bid-event.handler'; +import { BuyEventHandler } from './modules/rabbitmq/blockchain-events/handlers/buy-event.handler'; +import { EndAuctionEventHandler } from './modules/rabbitmq/blockchain-events/handlers/endAuction-event.handler'; +import { SendOfferEventHandler } from './modules/rabbitmq/blockchain-events/handlers/sendOffer-event.handler'; +import { StartAuctionEventHandler } from './modules/rabbitmq/blockchain-events/handlers/startAuction-event.handler'; +import { SwapUpdateEventHandler } from './modules/rabbitmq/blockchain-events/handlers/swapUpdate-event.handler'; +import { UpdateListingEventHandler } from './modules/rabbitmq/blockchain-events/handlers/updateListing-event.handler'; +import { UpdatePriceEventHandler } from './modules/rabbitmq/blockchain-events/handlers/updatePrice-event.handler'; +import { WithdrawAuctionEventHandler } from './modules/rabbitmq/blockchain-events/handlers/withdrawAuction-event.handler'; +import { WithdrawOfferEventHandler } from './modules/rabbitmq/blockchain-events/handlers/withdrawOffer-event.handler'; +import { AuctionsModuleGraph } from './modules/auctions/auctions.module'; +import { NotificationsModuleGraph } from './modules/notifications/notifications.module'; +import { OffersModuleGraph } from './modules/offers/offers.module'; +import { OrdersModuleGraph } from './modules/orders/orders.module'; @Module({ imports: [ @@ -26,8 +44,30 @@ import * as ormconfig from './ormconfig'; NftTraitsModule, MarketplacesModuleGraph, AuthModule, + forwardRef(() => AuctionsModuleGraph), + forwardRef(() => OrdersModuleGraph), + forwardRef(() => NotificationsModuleGraph), + forwardRef(() => OffersModuleGraph), + ], + providers: [ + Logger, + NsfwUpdaterService, + RarityUpdaterService, + MarketplaceEventsService, + BuyEventHandler, + BidEventHandler, + StartAuctionEventHandler, + EndAuctionEventHandler, + WithdrawAuctionEventHandler, + AcceptGlobalOfferEventHandler, + SendOfferEventHandler, + AcceptOfferEventHandler, + WithdrawOfferEventHandler, + UpdatePriceEventHandler, + UpdateListingEventHandler, + SwapUpdateEventHandler, + FeedEventsSenderService, ], - providers: [Logger, NsfwUpdaterService, RarityUpdaterService], controllers: [MetricsController, ReindexController, CachingController], exports: [NsfwUpdaterService, RarityUpdaterService], }) From 899d74e2f18cd0ef5ba64339ab0217b0cea55043 Mon Sep 17 00:00:00 2001 From: danielailie Date: Wed, 21 Feb 2024 15:01:32 +0200 Subject: [PATCH 02/18] Add logging --- src/modules/metrics/metrics.controller.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/src/modules/metrics/metrics.controller.ts b/src/modules/metrics/metrics.controller.ts index 197eb1733..b1a807c1b 100644 --- a/src/modules/metrics/metrics.controller.ts +++ b/src/modules/metrics/metrics.controller.ts @@ -19,6 +19,7 @@ export class MetricsController { @Post('/event') async notify(payload: RabbitEvent): Promise { + console.log({ payload }); await this.marketplaceEvents.handleNftEvents(payload.events, payload.hash, MarketplaceTypeEnum.External); return HttpStatus.OK; } From 355db193312df9d9de557e8ec87e942fbc905c77 Mon Sep 17 00:00:00 2001 From: danielailie Date: Wed, 21 Feb 2024 15:38:08 +0200 Subject: [PATCH 03/18] Update event endpoint --- src/modules/metrics/metrics.controller.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/modules/metrics/metrics.controller.ts b/src/modules/metrics/metrics.controller.ts index b1a807c1b..c92e5bfff 100644 --- a/src/modules/metrics/metrics.controller.ts +++ b/src/modules/metrics/metrics.controller.ts @@ -18,9 +18,9 @@ export class MetricsController { } @Post('/event') - async notify(payload: RabbitEvent): Promise { - console.log({ payload }); - await this.marketplaceEvents.handleNftEvents(payload.events, payload.hash, MarketplaceTypeEnum.External); + async notify(data: RabbitEvent): Promise { + console.log({ data }); + await this.marketplaceEvents.handleNftEvents(data?.events, data?.hash, MarketplaceTypeEnum.External); return HttpStatus.OK; } } From 933b9148f1f28820d1518b5f13ed72774b0711f1 Mon Sep 17 00:00:00 2001 From: danielailie Date: Wed, 21 Feb 2024 16:13:44 +0200 Subject: [PATCH 04/18] Fix notify endpoint --- src/modules/metrics/metrics.controller.ts | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/modules/metrics/metrics.controller.ts b/src/modules/metrics/metrics.controller.ts index c92e5bfff..8ab08cd6b 100644 --- a/src/modules/metrics/metrics.controller.ts +++ b/src/modules/metrics/metrics.controller.ts @@ -1,4 +1,4 @@ -import { Controller, Get, HttpStatus, Post } from '@nestjs/common'; +import { Body, Controller, Get, HttpStatus, Post } from '@nestjs/common'; import { MetricsCollector } from './metrics.collector'; import { RabbitEvent } from './rabbitEvent'; import { MarketplaceEventsService } from '../rabbitmq/blockchain-events/marketplace-events.service'; @@ -18,9 +18,8 @@ export class MetricsController { } @Post('/event') - async notify(data: RabbitEvent): Promise { - console.log({ data }); - await this.marketplaceEvents.handleNftEvents(data?.events, data?.hash, MarketplaceTypeEnum.External); + async notify(@Body() payload: RabbitEvent): Promise { + await this.marketplaceEvents.handleNftEvents(payload?.events, payload?.hash, MarketplaceTypeEnum.External); return HttpStatus.OK; } } From 62ea369c9ded82e3f05edcbd84c472c9358d9c42 Mon Sep 17 00:00:00 2001 From: danielailie Date: Mon, 4 Mar 2024 13:44:50 +0200 Subject: [PATCH 05/18] Enable update for xoxno --- .../marketplace-events.service.ts | 44 +++++++++---------- 1 file changed, 22 insertions(+), 22 deletions(-) diff --git a/src/modules/rabbitmq/blockchain-events/marketplace-events.service.ts b/src/modules/rabbitmq/blockchain-events/marketplace-events.service.ts index 6743cb452..b5fb9f64d 100644 --- a/src/modules/rabbitmq/blockchain-events/marketplace-events.service.ts +++ b/src/modules/rabbitmq/blockchain-events/marketplace-events.service.ts @@ -130,7 +130,7 @@ export class MarketplaceEventsService { switch (event.identifier) { case AuctionEventEnum.BidEvent: case KroganSwapAuctionEventEnum.Bid: - // await this.bidEventHandler.handle(event, hash, marketplaceType); + await this.bidEventHandler.handle(event, hash, marketplaceType); console.log({ identifier: event.identifier }); break; @@ -146,7 +146,7 @@ export class MarketplaceEventsService { continue; } console.log({ identifier: event.identifier }); - // await this.buyEventHandler.handle(event, hash, marketplaceType); + await this.buyEventHandler.handle(event, hash, marketplaceType); break; case AuctionEventEnum.WithdrawEvent: case KroganSwapAuctionEventEnum.WithdrawSwap: @@ -159,27 +159,27 @@ export class MarketplaceEventsService { continue; } console.log({ identifier: event.identifier }); - // await this.withdrawAuctionEventHandler.handle(event, hash, marketplaceType); + await this.withdrawAuctionEventHandler.handle(event, hash, marketplaceType); break; case AuctionEventEnum.EndAuctionEvent: console.log({ identifier: event.identifier }); - // await this.endAuctionEventHandler.handle(event, hash, marketplaceType); + await this.endAuctionEventHandler.handle(event, hash, marketplaceType); break; case AuctionEventEnum.AuctionTokenEvent: case ExternalAuctionEventEnum.Listing: case ExternalAuctionEventEnum.ListNftOnMarketplace: case KroganSwapAuctionEventEnum.NftSwap: console.log({ identifier: event.identifier }); - // await this.startAuctionEventHandler.handle(event, hash, marketplaceType); + await this.startAuctionEventHandler.handle(event, hash, marketplaceType); break; case ExternalAuctionEventEnum.ChangePrice: case ExternalAuctionEventEnum.UpdatePrice: console.log({ identifier: event.identifier }); - // await this.updatePriceEventHandler.handle(event, hash, marketplaceType); + await this.updatePriceEventHandler.handle(event, hash, marketplaceType); break; case ExternalAuctionEventEnum.UpdateListing: { console.log({ identifier: event.identifier }); - // await this.updateListingEventHandler.handle(event, hash, marketplaceType); + await this.updateListingEventHandler.handle(event, hash, marketplaceType); break; } case ExternalAuctionEventEnum.AcceptOffer: @@ -190,41 +190,41 @@ export class MarketplaceEventsService { } console.log({ identifier: event.identifier }); - // if (acceptOfferEventName === ExternalAuctionEventEnum.EndTokenEvent) { - // await this.withdrawAuctionEventHandler.handle(event, hash, marketplaceType); - // } else { - // await this.acceptOfferEventHandler.handle(event, hash, marketplaceType); - // } + if (acceptOfferEventName === ExternalAuctionEventEnum.EndTokenEvent) { + await this.withdrawAuctionEventHandler.handle(event, hash, marketplaceType); + } else { + await this.acceptOfferEventHandler.handle(event, hash, marketplaceType); + } break; case AuctionEventEnum.WithdrawAuctionAndAcceptOffer: console.log({ identifier: event.identifier }); - // if (Buffer.from(event.topics[0], 'base64').toString() === AuctionEventEnum.Accept_offer_token_event) { - // await this.acceptOfferEventHandler.handle(event, hash, marketplaceType); - // } else { - // await this.withdrawAuctionEventHandler.handle(event, hash, marketplaceType); - // } + if (Buffer.from(event.topics[0], 'base64').toString() === AuctionEventEnum.Accept_offer_token_event) { + await this.acceptOfferEventHandler.handle(event, hash, marketplaceType); + } else { + await this.withdrawAuctionEventHandler.handle(event, hash, marketplaceType); + } break; case ExternalAuctionEventEnum.AcceptGlobalOffer: console.log({ identifier: event.identifier }); - // await this.acceptGlobalOfferEventHandler.handle(event, hash, marketplaceType); + await this.acceptGlobalOfferEventHandler.handle(event, hash, marketplaceType); break; case AuctionEventEnum.SendOffer: console.log({ identifier: event.identifier }); - // await this.sendOfferEventHandler.handle(event, hash, marketplaceType); + await this.sendOfferEventHandler.handle(event, hash, marketplaceType); break; case AuctionEventEnum.WithdrawOffer: console.log({ identifier: event.identifier }); - // await this.withdrawOfferEventHandler.handle(event, hash, marketplaceType); + await this.withdrawOfferEventHandler.handle(event, hash, marketplaceType); break; case KroganSwapAuctionEventEnum.NftSwapUpdate: case KroganSwapAuctionEventEnum.NftSwapExtend: console.log({ identifier: event.identifier }); - // await this.swapUpdateEventHandler.handle(event, hash, marketplaceType); + await this.swapUpdateEventHandler.handle(event, hash, marketplaceType); break; case MarketplaceEventEnum.SCUpgrade: { console.log({ identifier: event.identifier }); - // await this.slackReportService.sendScUpgradeNotification(event.address); + await this.slackReportService.sendScUpgradeNotification(event.address); } } } From 35301da3fce5023473f52549c7a2be127a1546cb Mon Sep 17 00:00:00 2001 From: danielailie Date: Mon, 4 Mar 2024 14:37:36 +0200 Subject: [PATCH 06/18] Add try cach --- .../handlers/startAuction-event.handler.ts | 32 +++++++++++-------- 1 file changed, 18 insertions(+), 14 deletions(-) diff --git a/src/modules/rabbitmq/blockchain-events/handlers/startAuction-event.handler.ts b/src/modules/rabbitmq/blockchain-events/handlers/startAuction-event.handler.ts index 270a9a345..89a839108 100644 --- a/src/modules/rabbitmq/blockchain-events/handlers/startAuction-event.handler.ts +++ b/src/modules/rabbitmq/blockchain-events/handlers/startAuction-event.handler.ts @@ -29,24 +29,28 @@ export class StartAuctionEventHandler { ) {} async handle(event: any, hash: string, marketplaceType: MarketplaceTypeEnum) { - const { auctionTokenEvent, topics } = this.getEventAndTopics(event); - if (!auctionTokenEvent && !topics) return; + try { + const { auctionTokenEvent, topics } = this.getEventAndTopics(event); + if (!auctionTokenEvent && !topics) return; - const marketplace = await this.marketplaceService.getMarketplaceByType( - auctionTokenEvent.getAddress(), - marketplaceType, - topics.collection, - ); + const marketplace = await this.marketplaceService.getMarketplaceByType( + auctionTokenEvent.getAddress(), + marketplaceType, + topics.collection, + ); - if (!marketplace) return; - this.logger.log( - `${auctionTokenEvent.getIdentifier()} listing event detected for hash '${hash}' and marketplace '${marketplace?.name}'`, - ); - const auction = await this.saveAuction(topics, marketplace, hash); + if (!marketplace) return; + this.logger.log( + `${auctionTokenEvent.getIdentifier()} listing event detected for hash '${hash}' and marketplace '${marketplace?.name}'`, + ); + const auction = await this.saveAuction(topics, marketplace, hash); - if (!auction) return; + if (!auction) return; - await this.feedEventsSenderService.sendStartAuctionEvent(topics, auction, marketplace); + await this.feedEventsSenderService.sendStartAuctionEvent(topics, auction, marketplace); + } catch (error) { + console.error(error); + } } private async saveAuction(topics: any, marketplace: Marketplace, hash: string) { From 26822b87e274bcc25a8c397fb5d7c34a23277107 Mon Sep 17 00:00:00 2001 From: danielailie Date: Mon, 4 Mar 2024 14:50:48 +0200 Subject: [PATCH 07/18] Add events logging --- .../rabbitmq/blockchain-events/marketplace-events.service.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/src/modules/rabbitmq/blockchain-events/marketplace-events.service.ts b/src/modules/rabbitmq/blockchain-events/marketplace-events.service.ts index b5fb9f64d..797a304d8 100644 --- a/src/modules/rabbitmq/blockchain-events/marketplace-events.service.ts +++ b/src/modules/rabbitmq/blockchain-events/marketplace-events.service.ts @@ -127,6 +127,7 @@ export class MarketplaceEventsService { public async handleNftEvents(auctionEvents: any[], hash: string, marketplaceType: MarketplaceTypeEnum) { for (let event of auctionEvents) { + console.log({ identifier: event.identifier }); switch (event.identifier) { case AuctionEventEnum.BidEvent: case KroganSwapAuctionEventEnum.Bid: From b3e96fb9df6e8c67bcf084474820475b682d0787 Mon Sep 17 00:00:00 2001 From: danielailie Date: Mon, 4 Mar 2024 15:38:32 +0200 Subject: [PATCH 08/18] logging --- src/modules/metrics/metrics.controller.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/modules/metrics/metrics.controller.ts b/src/modules/metrics/metrics.controller.ts index 8ab08cd6b..c75a60acd 100644 --- a/src/modules/metrics/metrics.controller.ts +++ b/src/modules/metrics/metrics.controller.ts @@ -19,7 +19,8 @@ export class MetricsController { @Post('/event') async notify(@Body() payload: RabbitEvent): Promise { - await this.marketplaceEvents.handleNftEvents(payload?.events, payload?.hash, MarketplaceTypeEnum.External); + const resp = await this.marketplaceEvents.handleNftEvents(payload?.events, payload?.hash, MarketplaceTypeEnum.External); + console.log('resp', resp); return HttpStatus.OK; } } From 0659f080dba54e6c5745c60615ffb21834a974bc Mon Sep 17 00:00:00 2001 From: danielailie Date: Tue, 5 Mar 2024 11:10:58 +0200 Subject: [PATCH 09/18] Add try catch block --- .../acceptGlobalOffer-event.handler.ts | 28 ++++--- .../handlers/acceptOffer-event.handler.ts | 84 ++++++++++--------- .../handlers/bid-event.handler.ts | 76 +++++++++-------- .../handlers/buy-event.handler.ts | 78 +++++++++-------- .../handlers/endAuction-event.handler.ts | 34 ++++---- .../handlers/sendOffer-event.handler.ts | 32 +++---- .../handlers/swapUpdate-event.handler.ts | 20 +++-- .../handlers/updateListing-event.handler.ts | 34 ++++---- .../handlers/updatePrice-event.handler.ts | 32 +++---- .../handlers/withdrawAuction-event.handler.ts | 34 ++++---- .../handlers/withdrawOffer-event.handler.ts | 48 ++++++----- 11 files changed, 272 insertions(+), 228 deletions(-) diff --git a/src/modules/rabbitmq/blockchain-events/handlers/acceptGlobalOffer-event.handler.ts b/src/modules/rabbitmq/blockchain-events/handlers/acceptGlobalOffer-event.handler.ts index 5f77c0013..de000a06b 100644 --- a/src/modules/rabbitmq/blockchain-events/handlers/acceptGlobalOffer-event.handler.ts +++ b/src/modules/rabbitmq/blockchain-events/handlers/acceptGlobalOffer-event.handler.ts @@ -18,19 +18,23 @@ export class AcceptGlobalOfferEventHandler { ) {} async handle(event: any, hash: string, marketplaceType: MarketplaceTypeEnum) { - const acceptGlobalOfferEvent = new AcceptGlobalOfferEvent(event); - const topics = acceptGlobalOfferEvent.getTopics(); - const marketplace = await this.marketplaceService.getMarketplaceByType(acceptGlobalOfferEvent.getAddress(), marketplaceType); - this.logger.log(`Accept Global Offer event detected for hash '${hash}' and marketplace '${marketplace?.name}'`); - if (marketplace.key !== XOXNO_KEY || topics.auctionId <= 0) { - return; - } + try { + const acceptGlobalOfferEvent = new AcceptGlobalOfferEvent(event); + const topics = acceptGlobalOfferEvent.getTopics(); + const marketplace = await this.marketplaceService.getMarketplaceByType(acceptGlobalOfferEvent.getAddress(), marketplaceType); + this.logger.log(`Accept Global Offer event detected for hash '${hash}' and marketplace '${marketplace?.name}'`); + if (marketplace.key !== XOXNO_KEY || topics.auctionId <= 0) { + return; + } - let auction = await this.auctionsGetterService.getAuctionByIdAndMarketplace(topics.auctionId, marketplace.key); + let auction = await this.auctionsGetterService.getAuctionByIdAndMarketplace(topics.auctionId, marketplace.key); - if (!auction) return; - auction.status = AuctionStatusEnum.Closed; - auction.modifiedDate = new Date(new Date().toUTCString()); - this.auctionsService.updateAuction(auction, ExternalAuctionEventEnum.AcceptGlobalOffer); + if (!auction) return; + auction.status = AuctionStatusEnum.Closed; + auction.modifiedDate = new Date(new Date().toUTCString()); + this.auctionsService.updateAuction(auction, ExternalAuctionEventEnum.AcceptGlobalOffer); + } catch (error) { + console.error('An errror occured while handling bid event', error); + } } } diff --git a/src/modules/rabbitmq/blockchain-events/handlers/acceptOffer-event.handler.ts b/src/modules/rabbitmq/blockchain-events/handlers/acceptOffer-event.handler.ts index 140be69b8..8c6fa3ca1 100644 --- a/src/modules/rabbitmq/blockchain-events/handlers/acceptOffer-event.handler.ts +++ b/src/modules/rabbitmq/blockchain-events/handlers/acceptOffer-event.handler.ts @@ -27,54 +27,58 @@ export class AcceptOfferEventHandler { ) {} async handle(event: any, hash: string, marketplaceType: MarketplaceTypeEnum) { - const generalMarketplace = await this.marketplaceService.getMarketplaceByType(event.address, marketplaceType); + try { + const generalMarketplace = await this.marketplaceService.getMarketplaceByType(event.address, marketplaceType); - if (generalMarketplace?.type === MarketplaceTypeEnum.External) { - let acceptOfferEvent = undefined; - let topics = undefined; - if (generalMarketplace.key === XOXNO_KEY) { - acceptOfferEvent = new AcceptOfferXoxnoEvent(event); - topics = acceptOfferEvent.getTopics(); - } - if (generalMarketplace.key === FRAMEIT_KEY) { - acceptOfferEvent = new AcceptOfferFrameitEvent(event); - topics = acceptOfferEvent.getTopics(); - } - if (!acceptOfferEvent) return; + if (generalMarketplace?.type === MarketplaceTypeEnum.External) { + let acceptOfferEvent = undefined; + let topics = undefined; + if (generalMarketplace.key === XOXNO_KEY) { + acceptOfferEvent = new AcceptOfferXoxnoEvent(event); + topics = acceptOfferEvent.getTopics(); + } + if (generalMarketplace.key === FRAMEIT_KEY) { + acceptOfferEvent = new AcceptOfferFrameitEvent(event); + topics = acceptOfferEvent.getTopics(); + } + if (!acceptOfferEvent) return; - this.logger.log( - `${acceptOfferEvent.getIdentifier()} event detected for hash '${hash}' and marketplace '${generalMarketplace?.name}'`, - ); + this.logger.log( + `${acceptOfferEvent.getIdentifier()} event detected for hash '${hash}' and marketplace '${generalMarketplace?.name}'`, + ); - if (topics.auctionId || topics.auctionId !== 0) { - let auction = await this.auctionsGetterService.getAuctionByIdAndMarketplace(topics.auctionId, generalMarketplace.key); - if (!auction) return; + if (topics.auctionId || topics.auctionId !== 0) { + let auction = await this.auctionsGetterService.getAuctionByIdAndMarketplace(topics.auctionId, generalMarketplace.key); + if (!auction) return; - auction.status = AuctionStatusEnum.Closed; - auction.modifiedDate = new Date(new Date().toUTCString()); - this.auctionsService.updateAuction(auction, ExternalAuctionEventEnum.AcceptOffer); + auction.status = AuctionStatusEnum.Closed; + auction.modifiedDate = new Date(new Date().toUTCString()); + this.auctionsService.updateAuction(auction, ExternalAuctionEventEnum.AcceptOffer); + } + return; } - return; - } - const acceptOfferEvent = new AcceptOfferEvent(event); - const topics = acceptOfferEvent.getTopics(); - const marketplace = await this.marketplaceService.getMarketplaceByType( - acceptOfferEvent.getAddress(), - marketplaceType, - topics.collection, - ); - this.logger.log(`Accept Offer event detected for hash '${hash}' and marketplace '${marketplace?.name}'`); + const acceptOfferEvent = new AcceptOfferEvent(event); + const topics = acceptOfferEvent.getTopics(); + const marketplace = await this.marketplaceService.getMarketplaceByType( + acceptOfferEvent.getAddress(), + marketplaceType, + topics.collection, + ); + this.logger.log(`Accept Offer event detected for hash '${hash}' and marketplace '${marketplace?.name}'`); - const offer = await this.offersService.getOfferByIdAndMarketplace(topics.offerId, marketplace.key); + const offer = await this.offersService.getOfferByIdAndMarketplace(topics.offerId, marketplace.key); - await this.offersService.saveOffer({ - ...offer, - status: OfferStatusEnum.Accepted, - modifiedDate: new Date(new Date().toUTCString()), - }); + await this.offersService.saveOffer({ + ...offer, + status: OfferStatusEnum.Accepted, + modifiedDate: new Date(new Date().toUTCString()), + }); - await this.feedEventsSenderService.sendAcceptOfferEvent(topics.nftOwner, offer); - await this.notificationsService.updateNotificationStatusForOffers([offer.identifier]); + await this.feedEventsSenderService.sendAcceptOfferEvent(topics.nftOwner, offer); + await this.notificationsService.updateNotificationStatusForOffers([offer.identifier]); + } catch (error) { + console.error('An errror occured while handling bid event', error); + } } } diff --git a/src/modules/rabbitmq/blockchain-events/handlers/bid-event.handler.ts b/src/modules/rabbitmq/blockchain-events/handlers/bid-event.handler.ts index 4b3f44979..a98d4659d 100644 --- a/src/modules/rabbitmq/blockchain-events/handlers/bid-event.handler.ts +++ b/src/modules/rabbitmq/blockchain-events/handlers/bid-event.handler.ts @@ -28,44 +28,48 @@ export class BidEventHandler { ) {} async handle(event: any, hash: string, marketplaceType: MarketplaceTypeEnum) { - let [bidEvent, topics] = [undefined, undefined]; - let marketplace: Marketplace; - if (marketplaceType === MarketplaceTypeEnum.External) { - marketplace = await this.marketplaceService.getMarketplaceByAddress(event.address); - [bidEvent, topics] = this.getEventAndTopics(event, marketplace.key); - } else { - [bidEvent, topics] = this.getEventAndTopics(event); - marketplace = await this.marketplaceService.getMarketplaceByType(bidEvent.getAddress(), marketplaceType, topics.collection); - } - if (!marketplace) return; - this.logger.log(`${bidEvent.getIdentifier()} event detected for hash '${hash}' and marketplace '${marketplace?.name}'`); - const auction = await this.auctionsGetterService.getAuctionByIdAndMarketplace(parseInt(topics.auctionId, 16), marketplace.key); - if (!auction) return; + try { + let [bidEvent, topics] = [undefined, undefined]; + let marketplace: Marketplace; + if (marketplaceType === MarketplaceTypeEnum.External) { + marketplace = await this.marketplaceService.getMarketplaceByAddress(event.address); + [bidEvent, topics] = this.getEventAndTopics(event, marketplace.key); + } else { + [bidEvent, topics] = this.getEventAndTopics(event); + marketplace = await this.marketplaceService.getMarketplaceByType(bidEvent.getAddress(), marketplaceType, topics.collection); + } + if (!marketplace) return; + this.logger.log(`${bidEvent.getIdentifier()} event detected for hash '${hash}' and marketplace '${marketplace?.name}'`); + const auction = await this.auctionsGetterService.getAuctionByIdAndMarketplace(parseInt(topics.auctionId, 16), marketplace.key); + if (!auction) return; - const activeOrder = await this.ordersService.getActiveOrderForAuction(auction.id); - if (activeOrder && activeOrder.priceAmount === topics.currentBid) { - return; - } + const activeOrder = await this.ordersService.getActiveOrderForAuction(auction.id); + if (activeOrder && activeOrder.priceAmount === topics.currentBid) { + return; + } - const order = await this.ordersService.updateAuctionOrders( - new CreateOrderArgs({ - ownerAddress: topics.currentWinner, - auctionId: auction.id, - priceToken: auction.paymentToken, - priceAmount: topics.currentBid, - priceNonce: auction.paymentNonce, - blockHash: hash, - status: OrderStatusEnum.Active, - marketplaceKey: marketplace.key, - }), - activeOrder, - ); - await this.feedEventsSenderService.sendBidEvent(auction, topics, order); - if (auction.maxBidDenominated === order.priceAmountDenominated) { - this.notificationsService.updateNotificationStatus([auction?.id]); - this.notificationsService.addNotifications(auction, order); - this.auctionsService.updateAuctionStatus(auction.id, AuctionStatusEnum.Ended, hash, event.identifier); - this.persistenceService.updateOrderWithStatus(order, OrderStatusEnum.Bought); + const order = await this.ordersService.updateAuctionOrders( + new CreateOrderArgs({ + ownerAddress: topics.currentWinner, + auctionId: auction.id, + priceToken: auction.paymentToken, + priceAmount: topics.currentBid, + priceNonce: auction.paymentNonce, + blockHash: hash, + status: OrderStatusEnum.Active, + marketplaceKey: marketplace.key, + }), + activeOrder, + ); + await this.feedEventsSenderService.sendBidEvent(auction, topics, order); + if (auction.maxBidDenominated === order.priceAmountDenominated) { + this.notificationsService.updateNotificationStatus([auction?.id]); + this.notificationsService.addNotifications(auction, order); + this.auctionsService.updateAuctionStatus(auction.id, AuctionStatusEnum.Ended, hash, event.identifier); + this.persistenceService.updateOrderWithStatus(order, OrderStatusEnum.Bought); + } + } catch (error) { + console.error('An errror occured while handling bid event', error); } } diff --git a/src/modules/rabbitmq/blockchain-events/handlers/buy-event.handler.ts b/src/modules/rabbitmq/blockchain-events/handlers/buy-event.handler.ts index 3a3ffc2ab..1b3ed6be7 100644 --- a/src/modules/rabbitmq/blockchain-events/handlers/buy-event.handler.ts +++ b/src/modules/rabbitmq/blockchain-events/handlers/buy-event.handler.ts @@ -25,48 +25,52 @@ export class BuyEventHandler { ) {} async handle(event: any, hash: string, marketplaceType: MarketplaceTypeEnum) { - const { buySftEvent, topics } = this.getEventAndTopics(event, hash); - let auction: AuctionEntity; + try { + const { buySftEvent, topics } = this.getEventAndTopics(event, hash); + let auction: AuctionEntity; - const marketplace = await this.marketplaceService.getMarketplaceByType(buySftEvent.getAddress(), marketplaceType, topics.collection); + const marketplace = await this.marketplaceService.getMarketplaceByType(buySftEvent.getAddress(), marketplaceType, topics.collection); - if (!marketplace) return; - this.logger.log(`${buySftEvent.getIdentifier()} event detected for hash '${hash}' and marketplace '${marketplace?.name}'`); + if (!marketplace) return; + this.logger.log(`${buySftEvent.getIdentifier()} event detected for hash '${hash}' and marketplace '${marketplace?.name}'`); - if (topics.auctionId) { - auction = await this.auctionsGetterService.getAuctionByIdAndMarketplace(parseInt(topics.auctionId, 16), marketplace.key); - } else { - const auctionIdentifier = `${topics.collection}-${topics.nonce}`; - auction = await this.auctionsGetterService.getAuctionByIdentifierAndMarketplace(auctionIdentifier, marketplace.key); - } - if (!auction) return; + if (topics.auctionId) { + auction = await this.auctionsGetterService.getAuctionByIdAndMarketplace(parseInt(topics.auctionId, 16), marketplace.key); + } else { + const auctionIdentifier = `${topics.collection}-${topics.nonce}`; + auction = await this.auctionsGetterService.getAuctionByIdentifierAndMarketplace(auctionIdentifier, marketplace.key); + } + if (!auction) return; - const result = await this.auctionsGetterService.getAvailableTokens(auction.id); - const totalRemaining = result ? result[0]?.availableTokens - parseFloat(topics.boughtTokens) : 0; - if (totalRemaining === 0) { - this.auctionsService.updateAuctionStatus(auction.id, AuctionStatusEnum.Ended, hash, AuctionStatusEnum.Ended); + const result = await this.auctionsGetterService.getAvailableTokens(auction.id); + const totalRemaining = result ? result[0]?.availableTokens - parseFloat(topics.boughtTokens) : 0; + if (totalRemaining === 0) { + this.auctionsService.updateAuctionStatus(auction.id, AuctionStatusEnum.Ended, hash, AuctionStatusEnum.Ended); + } + const orderSft = await this.ordersService.createOrderForSft( + new CreateOrderArgs({ + ownerAddress: topics.currentWinner, + auctionId: auction.id, + priceToken: auction.paymentToken, + priceAmount: auction.minBid, + priceNonce: auction.paymentNonce, + blockHash: hash, + status: OrderStatusEnum.Bought, + boughtTokens: topics.boughtTokens, + marketplaceKey: marketplace.key, + }), + ); + await this.feedEventsSenderService.sendBuyEvent( + topics.currentWinner, + auction.minBid, + topics.boughtTokens, + orderSft, + auction, + marketplace, + ); + } catch (error) { + console.error('An errror occured while handling bid event', error); } - const orderSft = await this.ordersService.createOrderForSft( - new CreateOrderArgs({ - ownerAddress: topics.currentWinner, - auctionId: auction.id, - priceToken: auction.paymentToken, - priceAmount: auction.minBid, - priceNonce: auction.paymentNonce, - blockHash: hash, - status: OrderStatusEnum.Bought, - boughtTokens: topics.boughtTokens, - marketplaceKey: marketplace.key, - }), - ); - await this.feedEventsSenderService.sendBuyEvent( - topics.currentWinner, - auction.minBid, - topics.boughtTokens, - orderSft, - auction, - marketplace, - ); } private getEventAndTopics(event: any, hash: string) { diff --git a/src/modules/rabbitmq/blockchain-events/handlers/endAuction-event.handler.ts b/src/modules/rabbitmq/blockchain-events/handlers/endAuction-event.handler.ts index 0f6f66ace..3b0fe0082 100644 --- a/src/modules/rabbitmq/blockchain-events/handlers/endAuction-event.handler.ts +++ b/src/modules/rabbitmq/blockchain-events/handlers/endAuction-event.handler.ts @@ -25,23 +25,27 @@ export class EndAuctionEventHandler { ) {} async handle(event: any, hash: string, marketplaceType: MarketplaceTypeEnum) { - const endAuctionEvent = new EndAuctionEvent(event); - const topics = endAuctionEvent.getTopics(); - const marketplace = await this.marketplaceService.getMarketplaceByType( - endAuctionEvent.getAddress(), - marketplaceType, - topics.collection, - ); + try { + const endAuctionEvent = new EndAuctionEvent(event); + const topics = endAuctionEvent.getTopics(); + const marketplace = await this.marketplaceService.getMarketplaceByType( + endAuctionEvent.getAddress(), + marketplaceType, + topics.collection, + ); - if (!marketplace) return; - this.logger.log(`End auction event detected for hash '${hash}' and marketplace '${marketplace?.name}'`); - const auction = await this.auctionsGetterService.getAuctionByIdAndMarketplace(parseInt(topics.auctionId, 16), marketplace.key); + if (!marketplace) return; + this.logger.log(`End auction event detected for hash '${hash}' and marketplace '${marketplace?.name}'`); + const auction = await this.auctionsGetterService.getAuctionByIdAndMarketplace(parseInt(topics.auctionId, 16), marketplace.key); - if (!auction) return; + if (!auction) return; - this.auctionsService.updateAuctionStatus(auction.id, AuctionStatusEnum.Ended, hash, AuctionEventEnum.EndAuctionEvent); - this.notificationsService.updateNotificationStatus([auction.id]); - this.ordersService.updateOrder(auction.id, OrderStatusEnum.Bought); - await this.feedEventsSenderService.sendWonAuctionEvent(topics, auction, marketplace); + this.auctionsService.updateAuctionStatus(auction.id, AuctionStatusEnum.Ended, hash, AuctionEventEnum.EndAuctionEvent); + this.notificationsService.updateNotificationStatus([auction.id]); + this.ordersService.updateOrder(auction.id, OrderStatusEnum.Bought); + await this.feedEventsSenderService.sendWonAuctionEvent(topics, auction, marketplace); + } catch (error) { + console.error('An errror occured while handling bid event', error); + } } } diff --git a/src/modules/rabbitmq/blockchain-events/handlers/sendOffer-event.handler.ts b/src/modules/rabbitmq/blockchain-events/handlers/sendOffer-event.handler.ts index 827684e31..a40e5df4c 100644 --- a/src/modules/rabbitmq/blockchain-events/handlers/sendOffer-event.handler.ts +++ b/src/modules/rabbitmq/blockchain-events/handlers/sendOffer-event.handler.ts @@ -20,23 +20,27 @@ export class SendOfferEventHandler { ) {} async handle(event: any, hash: string, marketplaceType: MarketplaceTypeEnum) { - if (marketplaceType === MarketplaceTypeEnum.External) { - return; - } - const sendOffer = new SendOfferEvent(event); - const topics = sendOffer.getTopics(); - const marketplace = await this.marketplaceService.getMarketplaceByType(sendOffer.getAddress(), marketplaceType, topics.collection); + try { + if (marketplaceType === MarketplaceTypeEnum.External) { + return; + } + const sendOffer = new SendOfferEvent(event); + const topics = sendOffer.getTopics(); + const marketplace = await this.marketplaceService.getMarketplaceByType(sendOffer.getAddress(), marketplaceType, topics.collection); - if (!marketplace || marketplace.type === MarketplaceTypeEnum.External) { - return; - } + if (!marketplace || marketplace.type === MarketplaceTypeEnum.External) { + return; + } - this.logger.log(`Send Offer event detected for hash '${hash}' and marketplace '${marketplace?.name}'`); + this.logger.log(`Send Offer event detected for hash '${hash}' and marketplace '${marketplace?.name}'`); - const offer = await this.offersService.saveOffer(OfferEntity.fromEventTopics(topics, hash, marketplace.key, OfferStatusEnum.Active)); + const offer = await this.offersService.saveOffer(OfferEntity.fromEventTopics(topics, hash, marketplace.key, OfferStatusEnum.Active)); - if (!offer) return; - await this.feedEventsSenderService.sendOfferEvent(offer); - await this.notificationsService.addNotificationForOffer(offer); + if (!offer) return; + await this.feedEventsSenderService.sendOfferEvent(offer); + await this.notificationsService.addNotificationForOffer(offer); + } catch (error) { + console.error('An errror occured while handling bid event', error); + } } } diff --git a/src/modules/rabbitmq/blockchain-events/handlers/swapUpdate-event.handler.ts b/src/modules/rabbitmq/blockchain-events/handlers/swapUpdate-event.handler.ts index 7e950fa98..d791174d2 100644 --- a/src/modules/rabbitmq/blockchain-events/handlers/swapUpdate-event.handler.ts +++ b/src/modules/rabbitmq/blockchain-events/handlers/swapUpdate-event.handler.ts @@ -21,15 +21,19 @@ export class SwapUpdateEventHandler { ) {} async handle(event: any, hash: string, marketplaceType: MarketplaceTypeEnum) { - const updateEvent = new ElrondSwapUpdateEvent(event); - const topics = updateEvent.getTopics(); - const marketplace = await this.marketplaceService.getMarketplaceByType(updateEvent.getAddress(), marketplaceType); - this.logger.log(`${updateEvent.getIdentifier()} auction event detected for hash '${hash}' and marketplace '${marketplace?.name}'`); - let auction = await this.auctionsGetterService.getAuctionByIdAndMarketplace(parseInt(topics.auctionId, 16), marketplace.key); + try { + const updateEvent = new ElrondSwapUpdateEvent(event); + const topics = updateEvent.getTopics(); + const marketplace = await this.marketplaceService.getMarketplaceByType(updateEvent.getAddress(), marketplaceType); + this.logger.log(`${updateEvent.getIdentifier()} auction event detected for hash '${hash}' and marketplace '${marketplace?.name}'`); + let auction = await this.auctionsGetterService.getAuctionByIdAndMarketplace(parseInt(topics.auctionId, 16), marketplace.key); - if (auction) { - await this.updateAuctionPrice(auction, topics, hash); - this.auctionsService.updateAuction(auction, KroganSwapAuctionEventEnum.NftSwapUpdate); + if (auction) { + await this.updateAuctionPrice(auction, topics, hash); + this.auctionsService.updateAuction(auction, KroganSwapAuctionEventEnum.NftSwapUpdate); + } + } catch (error) { + console.error('An errror occured while handling bid event', error); } } diff --git a/src/modules/rabbitmq/blockchain-events/handlers/updateListing-event.handler.ts b/src/modules/rabbitmq/blockchain-events/handlers/updateListing-event.handler.ts index e83c773a6..293824f93 100644 --- a/src/modules/rabbitmq/blockchain-events/handlers/updateListing-event.handler.ts +++ b/src/modules/rabbitmq/blockchain-events/handlers/updateListing-event.handler.ts @@ -22,24 +22,28 @@ export class UpdateListingEventHandler { ) {} async handle(event: any, hash: string, marketplaceType: MarketplaceTypeEnum) { - const updateListingEvent = new UpdateListingEvent(event); - const topics = updateListingEvent.getTopics(); - const marketplace = await this.marketplaceService.getMarketplaceByType( - updateListingEvent.getAddress(), - marketplaceType, - topics.collection, - ); - this.logger.log( - `${updateListingEvent.getIdentifier()} listing event detected for hash '${hash}' and marketplace '${marketplace?.name}'`, - ); - let auction = await this.auctionsGetterService.getAuctionByIdAndMarketplace(parseInt(topics.auctionId, 16), marketplace.key); + try { + const updateListingEvent = new UpdateListingEvent(event); + const topics = updateListingEvent.getTopics(); + const marketplace = await this.marketplaceService.getMarketplaceByType( + updateListingEvent.getAddress(), + marketplaceType, + topics.collection, + ); + this.logger.log( + `${updateListingEvent.getIdentifier()} listing event detected for hash '${hash}' and marketplace '${marketplace?.name}'`, + ); + let auction = await this.auctionsGetterService.getAuctionByIdAndMarketplace(parseInt(topics.auctionId, 16), marketplace.key); - if (auction && marketplace) { - const paymentToken = await this.usdPriceService.getToken(auction.paymentToken); + if (auction && marketplace) { + const paymentToken = await this.usdPriceService.getToken(auction.paymentToken); - this.updateAuctionListing(auction, updateListingEvent, paymentToken, hash); + this.updateAuctionListing(auction, updateListingEvent, paymentToken, hash); - this.auctionsService.updateAuction(auction, ExternalAuctionEventEnum.UpdateListing); + this.auctionsService.updateAuction(auction, ExternalAuctionEventEnum.UpdateListing); + } + } catch (error) { + console.error('An errror occured while handling bid event', error); } } diff --git a/src/modules/rabbitmq/blockchain-events/handlers/updatePrice-event.handler.ts b/src/modules/rabbitmq/blockchain-events/handlers/updatePrice-event.handler.ts index 377dd652e..fa39d341b 100644 --- a/src/modules/rabbitmq/blockchain-events/handlers/updatePrice-event.handler.ts +++ b/src/modules/rabbitmq/blockchain-events/handlers/updatePrice-event.handler.ts @@ -24,21 +24,25 @@ export class UpdatePriceEventHandler { ) {} async handle(event: any, hash: string, marketplaceType: MarketplaceTypeEnum) { - const updatePriceEvent = new UpdatePriceEvent(event); - const topics = updatePriceEvent.getTopics(); - const marketplace = await this.marketplaceService.getMarketplaceByType( - updatePriceEvent.getAddress(), - marketplaceType, - topics.collection, - ); - this.logger.log(`${updatePriceEvent.getIdentifier()} event detected for hash '${hash}' and marketplace '${marketplace?.name}'`); - let auction = await this.auctionsGetterService.getAuctionByIdAndMarketplace(parseInt(topics.auctionId, 16), marketplace.key); - let newPrice: string = await this.getNewPrice(marketplace, topics); - if (auction && newPrice) { - const paymentToken = await this.usdPriceService.getToken(auction.paymentToken); - this.updateAuctionPrice(auction, newPrice, hash, paymentToken?.decimals); + try { + const updatePriceEvent = new UpdatePriceEvent(event); + const topics = updatePriceEvent.getTopics(); + const marketplace = await this.marketplaceService.getMarketplaceByType( + updatePriceEvent.getAddress(), + marketplaceType, + topics.collection, + ); + this.logger.log(`${updatePriceEvent.getIdentifier()} event detected for hash '${hash}' and marketplace '${marketplace?.name}'`); + let auction = await this.auctionsGetterService.getAuctionByIdAndMarketplace(parseInt(topics.auctionId, 16), marketplace.key); + let newPrice: string = await this.getNewPrice(marketplace, topics); + if (auction && newPrice) { + const paymentToken = await this.usdPriceService.getToken(auction.paymentToken); + this.updateAuctionPrice(auction, newPrice, hash, paymentToken?.decimals); - this.auctionsService.updateAuction(auction, ExternalAuctionEventEnum.UpdatePrice); + this.auctionsService.updateAuction(auction, ExternalAuctionEventEnum.UpdatePrice); + } + } catch (error) { + console.error('An errror occured while handling bid event', error); } } diff --git a/src/modules/rabbitmq/blockchain-events/handlers/withdrawAuction-event.handler.ts b/src/modules/rabbitmq/blockchain-events/handlers/withdrawAuction-event.handler.ts index a67b5f5cf..dd3cb0c8d 100644 --- a/src/modules/rabbitmq/blockchain-events/handlers/withdrawAuction-event.handler.ts +++ b/src/modules/rabbitmq/blockchain-events/handlers/withdrawAuction-event.handler.ts @@ -20,22 +20,26 @@ export class WithdrawAuctionEventHandler { ) {} async handle(event: any, hash: string, marketplaceType: MarketplaceTypeEnum) { - const { withdraw, topics } = this.getEventAndTopics(event); - let auction: AuctionEntity; - const marketplace = await this.marketplaceService.getMarketplaceByType(withdraw.getAddress(), marketplaceType, topics.collection); - if (!marketplace) return; - - this.logger.log(`${withdraw.getIdentifier()} event detected for hash '${hash}' and marketplace '${marketplace?.name}'`); - if (topics.auctionId) { - auction = await this.auctionsGetterService.getAuctionByIdAndMarketplace(parseInt(topics.auctionId, 16), marketplace.key); - } else { - const auctionIdentifier = `${topics.collection}-${topics.nonce}`; - auction = await this.auctionsGetterService.getAuctionByIdentifierAndMarketplace(auctionIdentifier, marketplace.key); + try { + const { withdraw, topics } = this.getEventAndTopics(event); + let auction: AuctionEntity; + const marketplace = await this.marketplaceService.getMarketplaceByType(withdraw.getAddress(), marketplaceType, topics.collection); + if (!marketplace) return; + + this.logger.log(`${withdraw.getIdentifier()} event detected for hash '${hash}' and marketplace '${marketplace?.name}'`); + if (topics.auctionId) { + auction = await this.auctionsGetterService.getAuctionByIdAndMarketplace(parseInt(topics.auctionId, 16), marketplace.key); + } else { + const auctionIdentifier = `${topics.collection}-${topics.nonce}`; + auction = await this.auctionsGetterService.getAuctionByIdentifierAndMarketplace(auctionIdentifier, marketplace.key); + } + + if (!auction) return; + + this.auctionsService.updateAuctionStatus(auction.id, AuctionStatusEnum.Closed, hash, AuctionEventEnum.WithdrawEvent); + } catch (error) { + console.error('An errror occured while handling bid event', error); } - - if (!auction) return; - - this.auctionsService.updateAuctionStatus(auction.id, AuctionStatusEnum.Closed, hash, AuctionEventEnum.WithdrawEvent); } private getEventAndTopics(event: any) { diff --git a/src/modules/rabbitmq/blockchain-events/handlers/withdrawOffer-event.handler.ts b/src/modules/rabbitmq/blockchain-events/handlers/withdrawOffer-event.handler.ts index da7088582..c559e5c30 100644 --- a/src/modules/rabbitmq/blockchain-events/handlers/withdrawOffer-event.handler.ts +++ b/src/modules/rabbitmq/blockchain-events/handlers/withdrawOffer-event.handler.ts @@ -17,31 +17,35 @@ export class WithdrawOfferEventHandler { ) {} async handle(event: any, hash: string, marketplaceType: MarketplaceTypeEnum) { - if (marketplaceType === MarketplaceTypeEnum.External) { - return; - } - const withdrawOfferEvent = new WithdrawOfferEvent(event); - const topics = withdrawOfferEvent.getTopics(); - const marketplace = await this.marketplaceService.getMarketplaceByType( - withdrawOfferEvent.getAddress(), - marketplaceType, - topics.collection, - ); + try { + if (marketplaceType === MarketplaceTypeEnum.External) { + return; + } + const withdrawOfferEvent = new WithdrawOfferEvent(event); + const topics = withdrawOfferEvent.getTopics(); + const marketplace = await this.marketplaceService.getMarketplaceByType( + withdrawOfferEvent.getAddress(), + marketplaceType, + topics.collection, + ); - if (!marketplace) { - return; - } - this.logger.log(`Withdraw Offer event detected for hash '${hash}' and marketplace '${marketplace?.name}'`); + if (!marketplace) { + return; + } + this.logger.log(`Withdraw Offer event detected for hash '${hash}' and marketplace '${marketplace?.name}'`); - const withdrawOffer = await this.offersService.getOfferByIdAndMarketplace(topics.offerId, marketplace.key); + const withdrawOffer = await this.offersService.getOfferByIdAndMarketplace(topics.offerId, marketplace.key); - if (!withdrawOffer) return; - const offer = await this.offersService.saveOffer({ - ...withdrawOffer, - status: OfferStatusEnum.Closed, - modifiedDate: new Date(new Date().toUTCString()), - }); + if (!withdrawOffer) return; + const offer = await this.offersService.saveOffer({ + ...withdrawOffer, + status: OfferStatusEnum.Closed, + modifiedDate: new Date(new Date().toUTCString()), + }); - this.notificationsService.updateNotificationStatusForOffers([offer.identifier]); + this.notificationsService.updateNotificationStatusForOffers([offer.identifier]); + } catch (error) { + console.error('An errror occured while handling bid event', error); + } } } From b843e8656815d05fbe9823b66222d8ff3a78242a Mon Sep 17 00:00:00 2001 From: danielailie Date: Mon, 11 Mar 2024 10:39:31 +0200 Subject: [PATCH 10/18] Update notifiy endpoint --- src/db/auctions/auction.entity.ts | 50 +++++++++ src/modules/metrics/metrics.controller.ts | 3 +- .../handlers/startAuction-event.handler.ts | 10 +- .../marketplace-events.service.ts | 106 ------------------ .../auction/auctionToken.event.topics.ts | 12 +- 5 files changed, 65 insertions(+), 116 deletions(-) diff --git a/src/db/auctions/auction.entity.ts b/src/db/auctions/auction.entity.ts index be1783ec7..41b727cb2 100644 --- a/src/db/auctions/auction.entity.ts +++ b/src/db/auctions/auction.entity.ts @@ -160,6 +160,56 @@ export class AuctionEntity extends BaseEntity { }); } + static fromAuctionTopics( + topicsAuctionToken: { + collection: string; + nonce: string; + auctionId: string; + nrAuctionTokens: string; + originalOwner: string; + minBid: string; + maxBid: string; + startTime: number; + endTime: number; + paymentToken: string; + paymentNonce: number; + auctionType: string; + }, + tags: string, + hash: string, + marketplaceKey: string, + decimals: number = 18, + ) { + if (!topicsAuctionToken) { + return null; + } + console.log('topicsAuctionToken', topicsAuctionToken); + return new AuctionEntity({ + marketplaceAuctionId: parseInt(topicsAuctionToken.auctionId, 16), + collection: topicsAuctionToken.collection, + nonce: parseInt(topicsAuctionToken.nonce, 16), + nrAuctionedTokens: parseInt(topicsAuctionToken.nrAuctionTokens, 16), + status: AuctionStatusEnum.Running, + type: + topicsAuctionToken.auctionType === '' || parseInt(topicsAuctionToken.auctionType) === ElrondSwapAuctionTypeEnum.Auction + ? AuctionTypeEnum.Nft + : AuctionTypeEnum.SftOnePerPayment, + paymentToken: topicsAuctionToken.paymentToken, + paymentNonce: topicsAuctionToken.paymentNonce, + ownerAddress: topicsAuctionToken.originalOwner, + minBid: topicsAuctionToken.minBid, + minBidDenominated: BigNumberUtils.denominateAmount(topicsAuctionToken.minBid, decimals), + maxBid: topicsAuctionToken.maxBid ?? '0', + maxBidDenominated: BigNumberUtils.denominateAmount(topicsAuctionToken.maxBid ?? '0', decimals), + startDate: DateUtils.getCurrentTimestamp(), + endDate: topicsAuctionToken.endTime, + identifier: `${topicsAuctionToken.collection}-${topicsAuctionToken.nonce}`, + tags: tags ? `,${tags},` : '', + blockHash: hash, + marketplaceKey: marketplaceKey, + }); + } + static fromWithdrawTopics( topicsAuctionToken: { originalOwner: string; diff --git a/src/modules/metrics/metrics.controller.ts b/src/modules/metrics/metrics.controller.ts index c75a60acd..d011f7e76 100644 --- a/src/modules/metrics/metrics.controller.ts +++ b/src/modules/metrics/metrics.controller.ts @@ -19,8 +19,7 @@ export class MetricsController { @Post('/event') async notify(@Body() payload: RabbitEvent): Promise { - const resp = await this.marketplaceEvents.handleNftEvents(payload?.events, payload?.hash, MarketplaceTypeEnum.External); - console.log('resp', resp); + await this.marketplaceEvents.handleNftAuctionEvents(payload?.events, payload?.hash, MarketplaceTypeEnum.External); return HttpStatus.OK; } } diff --git a/src/modules/rabbitmq/blockchain-events/handlers/startAuction-event.handler.ts b/src/modules/rabbitmq/blockchain-events/handlers/startAuction-event.handler.ts index 89a839108..ddebe1411 100644 --- a/src/modules/rabbitmq/blockchain-events/handlers/startAuction-event.handler.ts +++ b/src/modules/rabbitmq/blockchain-events/handlers/startAuction-event.handler.ts @@ -9,7 +9,7 @@ import { MarketplacesService } from 'src/modules/marketplaces/marketplaces.servi import { Marketplace } from 'src/modules/marketplaces/models'; import { MarketplaceTypeEnum } from 'src/modules/marketplaces/models/MarketplaceType.enum'; import { UsdPriceService } from 'src/modules/usdPrice/usd-price.service'; -import { ELRONDNFTSWAP_KEY, ENEFTOR_KEY } from 'src/utils/constants'; +import { ELRONDNFTSWAP_KEY, ENEFTOR_KEY, XOXNO_KEY } from 'src/utils/constants'; import { AuctionTokenEvent } from '../../entities/auction'; import { ElrondSwapAuctionEvent } from '../../entities/auction/elrondnftswap/elrondswap-auction.event'; import { ListNftEvent } from '../../entities/auction/listNft.event'; @@ -55,7 +55,7 @@ export class StartAuctionEventHandler { private async saveAuction(topics: any, marketplace: Marketplace, hash: string) { const auctionIdentifier = `${topics.collection}-${topics.nonce}`; - if (marketplace.key === ELRONDNFTSWAP_KEY || marketplace.key === ENEFTOR_KEY) { + if (marketplace.key === ELRONDNFTSWAP_KEY || marketplace.key === ENEFTOR_KEY || marketplace.key === XOXNO_KEY) { if (topics.auctionId === '0') { let auctionId = await this.auctionsGetterService.getLastAuctionIdForMarketplace(marketplace.key); topics.auctionId = (auctionId && auctionId > 0 ? auctionId + 1 : 1).toString(16); @@ -78,6 +78,12 @@ export class StartAuctionEventHandler { const paymentToken = await this.usdPriceService.getToken(topics.paymentToken); decimals = paymentToken.decimals; } + if (auctionTokenEventMarketplace.key === XOXNO_KEY) { + return await this.auctionsSetterService.saveAuctionEntity( + AuctionEntity.fromAuctionTopics(topics, asset.tags?.toString(), hash, auctionTokenEventMarketplace.key, decimals), + asset.tags, + ); + } return await this.auctionsSetterService.saveAuctionEntity( AuctionEntity.fromWithdrawTopics(topics, asset.tags?.toString(), hash, auctionTokenEventMarketplace.key, decimals), asset.tags, diff --git a/src/modules/rabbitmq/blockchain-events/marketplace-events.service.ts b/src/modules/rabbitmq/blockchain-events/marketplace-events.service.ts index 797a304d8..4b63dde53 100644 --- a/src/modules/rabbitmq/blockchain-events/marketplace-events.service.ts +++ b/src/modules/rabbitmq/blockchain-events/marketplace-events.service.ts @@ -124,110 +124,4 @@ export class MarketplaceEventsService { } } } - - public async handleNftEvents(auctionEvents: any[], hash: string, marketplaceType: MarketplaceTypeEnum) { - for (let event of auctionEvents) { - console.log({ identifier: event.identifier }); - switch (event.identifier) { - case AuctionEventEnum.BidEvent: - case KroganSwapAuctionEventEnum.Bid: - await this.bidEventHandler.handle(event, hash, marketplaceType); - console.log({ identifier: event.identifier }); - - break; - case AuctionEventEnum.BuySftEvent: - case ExternalAuctionEventEnum.Buy: - case ExternalAuctionEventEnum.BulkBuy: - case ExternalAuctionEventEnum.BuyFor: - case ExternalAuctionEventEnum.BuyNft: - case KroganSwapAuctionEventEnum.Purchase: - const eventName = Buffer.from(event.topics[0], 'base64').toString(); - if (eventName === ExternalAuctionEventEnum.UpdateOffer || eventName === KroganSwapAuctionEventEnum.UpdateListing) { - this.logger.log(`${eventName} event detected for hash '${hash}' for marketplace ${event.address}, ignore it for the moment`); - continue; - } - console.log({ identifier: event.identifier }); - await this.buyEventHandler.handle(event, hash, marketplaceType); - break; - case AuctionEventEnum.WithdrawEvent: - case KroganSwapAuctionEventEnum.WithdrawSwap: - case ExternalAuctionEventEnum.ClaimBackNft: - case ExternalAuctionEventEnum.ReturnListing: - if (Buffer.from(event.topics[0], 'base64').toString() === ExternalAuctionEventEnum.UpdateOffer) { - this.logger.log( - `${event.topics[0]} event detected for hash '${hash}' for marketplace ${event.addreses}, ignore it for the moment`, - ); - continue; - } - console.log({ identifier: event.identifier }); - await this.withdrawAuctionEventHandler.handle(event, hash, marketplaceType); - break; - case AuctionEventEnum.EndAuctionEvent: - console.log({ identifier: event.identifier }); - await this.endAuctionEventHandler.handle(event, hash, marketplaceType); - break; - case AuctionEventEnum.AuctionTokenEvent: - case ExternalAuctionEventEnum.Listing: - case ExternalAuctionEventEnum.ListNftOnMarketplace: - case KroganSwapAuctionEventEnum.NftSwap: - console.log({ identifier: event.identifier }); - await this.startAuctionEventHandler.handle(event, hash, marketplaceType); - break; - case ExternalAuctionEventEnum.ChangePrice: - case ExternalAuctionEventEnum.UpdatePrice: - console.log({ identifier: event.identifier }); - await this.updatePriceEventHandler.handle(event, hash, marketplaceType); - break; - case ExternalAuctionEventEnum.UpdateListing: { - console.log({ identifier: event.identifier }); - await this.updateListingEventHandler.handle(event, hash, marketplaceType); - break; - } - case ExternalAuctionEventEnum.AcceptOffer: - case ExternalAuctionEventEnum.AcceptOfferFromAuction: - const acceptOfferEventName = Buffer.from(event.topics[0], 'base64').toString(); - if (acceptOfferEventName === ExternalAuctionEventEnum.UserDeposit) { - continue; - } - - console.log({ identifier: event.identifier }); - if (acceptOfferEventName === ExternalAuctionEventEnum.EndTokenEvent) { - await this.withdrawAuctionEventHandler.handle(event, hash, marketplaceType); - } else { - await this.acceptOfferEventHandler.handle(event, hash, marketplaceType); - } - - break; - case AuctionEventEnum.WithdrawAuctionAndAcceptOffer: - console.log({ identifier: event.identifier }); - if (Buffer.from(event.topics[0], 'base64').toString() === AuctionEventEnum.Accept_offer_token_event) { - await this.acceptOfferEventHandler.handle(event, hash, marketplaceType); - } else { - await this.withdrawAuctionEventHandler.handle(event, hash, marketplaceType); - } - break; - case ExternalAuctionEventEnum.AcceptGlobalOffer: - console.log({ identifier: event.identifier }); - await this.acceptGlobalOfferEventHandler.handle(event, hash, marketplaceType); - break; - case AuctionEventEnum.SendOffer: - console.log({ identifier: event.identifier }); - await this.sendOfferEventHandler.handle(event, hash, marketplaceType); - break; - case AuctionEventEnum.WithdrawOffer: - console.log({ identifier: event.identifier }); - await this.withdrawOfferEventHandler.handle(event, hash, marketplaceType); - break; - case KroganSwapAuctionEventEnum.NftSwapUpdate: - case KroganSwapAuctionEventEnum.NftSwapExtend: - console.log({ identifier: event.identifier }); - await this.swapUpdateEventHandler.handle(event, hash, marketplaceType); - break; - case MarketplaceEventEnum.SCUpgrade: { - console.log({ identifier: event.identifier }); - await this.slackReportService.sendScUpgradeNotification(event.address); - } - } - } - } } diff --git a/src/modules/rabbitmq/entities/auction/auctionToken.event.topics.ts b/src/modules/rabbitmq/entities/auction/auctionToken.event.topics.ts index f132ebc74..ddf7b0964 100644 --- a/src/modules/rabbitmq/entities/auction/auctionToken.event.topics.ts +++ b/src/modules/rabbitmq/entities/auction/auctionToken.event.topics.ts @@ -6,7 +6,7 @@ export class AuctionTokenEventsTopics { private nonce: string; private auctionId: string; private nrAuctionTokens: string; - private originalOwner: Address; + private originalOwner: string; private minBid: string; private maxBid: string; private startTime: number; @@ -20,14 +20,14 @@ export class AuctionTokenEventsTopics { this.nonce = Buffer.from(rawTopics[2], 'base64').toString('hex'); this.auctionId = Buffer.from(rawTopics[3], 'base64').toString('hex'); this.nrAuctionTokens = parseInt(Buffer.from(rawTopics[4], 'base64').toString('hex'), 16).toString(); - this.originalOwner = new Address(Buffer.from(rawTopics[5], 'base64')); + this.originalOwner = new Address(Buffer.from(rawTopics[5], 'base64')).bech32(); this.minBid = BinaryUtils.hexToNumber(BinaryUtils.base64ToHex(rawTopics[6])).toString(); - this.maxBid = BinaryUtils.hexToNumber(BinaryUtils.base64ToHex(rawTopics[7])).toString(); + this.maxBid = rawTopics[7] ? BinaryUtils.hexToNumber(BinaryUtils.base64ToHex(rawTopics[7])).toString() : '0'; this.startTime = BinaryUtils.hexToNumber(BinaryUtils.base64ToHex(rawTopics[8])); - this.endTime = BinaryUtils.hexToNumber(BinaryUtils.base64ToHex(rawTopics[9])); + this.endTime = rawTopics[9] ? parseInt(BinaryUtils.hexToNumber(BinaryUtils.base64ToHex(rawTopics[9])).toString()) : 0; this.paymentToken = BinaryUtils.base64Decode(rawTopics[10]); - this.paymentNonce = BinaryUtils.hexToNumber(BinaryUtils.base64ToHex(rawTopics[11])); + this.paymentNonce = rawTopics[11] ? parseInt(BinaryUtils.hexToNumber(rawTopics[11]).toString()) : 0; this.auctionType = BinaryUtils.hexToNumber(BinaryUtils.base64ToHex(rawTopics[12])).toString(); if (this.startTime.toString().length > 10) { @@ -40,7 +40,7 @@ export class AuctionTokenEventsTopics { toPlainObject() { return { - originalOwner: this.originalOwner.bech32(), + originalOwner: this.originalOwner, collection: this.collection, nonce: this.nonce, auctionId: this.auctionId, From e1935686cfae07b6044da58b91c3328010935320 Mon Sep 17 00:00:00 2001 From: danielailie Date: Wed, 22 May 2024 14:31:49 +0300 Subject: [PATCH 11/18] Add hendler for events from events logs indexer --- src/modules/metrics/metrics.controller.ts | 7 +- .../acceptGlobalOffer-event.handler.ts | 36 +++++ .../acceptOffer-event.handler.ts | 83 +++++++++++ .../handlers-reindex/bid-event.handler.ts | 84 ++++++++++++ .../handlers-reindex/buy-event.handler.ts | 98 +++++++++++++ .../endAuction-event.handler.ts | 50 +++++++ .../sendOffer-event.handler.ts | 47 +++++++ .../startAuction-event.handler.ts | 111 +++++++++++++++ .../swapUpdate-event.handler.ts | 59 ++++++++ .../updateListing-event.handler.ts | 67 +++++++++ .../updatePrice-event.handler.ts | 74 ++++++++++ .../withdrawAuction-event.handler.ts | 62 +++++++++ .../withdrawOffer-event.handler.ts | 51 +++++++ .../marketplace-events-processing.service.ts | 129 ++++++++++++++++++ .../blockchain-events/nft-events.module.ts | 2 +- .../acceptGlobalOffer.event.topics.ts | 15 ++ .../acceptGlobalOffer.event.ts | 15 ++ .../acceptOffer.event.topics.ts | 49 +++++++ .../auction-reindex/acceptOffer.event.ts | 15 ++ .../acceptOfferDeadrare.event.topics.ts | 50 +++++++ .../acceptOfferDeadrare.event.ts | 15 ++ .../acceptOfferFrameit.event.topics.ts | 46 +++++++ .../acceptOfferFrameit.event.ts | 15 ++ .../acceptOfferXoxno.event.topics.ts | 49 +++++++ .../auction-reindex/acceptOfferXoxno.event.ts | 15 ++ .../entities/auction-reindex/auction.types.ts | 42 ++++++ .../auctionToken.event.topics.ts | 58 ++++++++ .../auction-reindex/auctionToken.event.ts | 15 ++ .../auction-reindex/bid.event.topics.ts | 31 +++++ .../entities/auction-reindex/bid.event.ts | 15 ++ .../brandCreated.event.topics.ts | 15 ++ .../auction-reindex/brandCreated.event.ts | 15 ++ .../auction-reindex/burn.event.topics.ts | 19 +++ .../entities/auction-reindex/burn.event.ts | 15 ++ .../auction-reindex/buySft.event.topics.ts | 34 +++++ .../entities/auction-reindex/buySft.event.ts | 15 ++ .../auction-reindex/claim.event.topics.ts | 29 ++++ .../entities/auction-reindex/claim.event.ts | 15 ++ .../elrondswap-acceptOffer.event.topics.ts | 48 +++++++ .../elrondswap-acceptOffer.event.ts | 15 ++ .../elrondswap-auction.event.topics.ts | 55 ++++++++ .../elrondnftswap/elrondswap-auction.event.ts | 15 ++ .../elrondswap-bid.event.topics.ts | 30 ++++ .../elrondnftswap/elrondswap-bid.event.ts | 15 ++ .../elrondswap-buy.event.topics.ts | 32 +++++ .../elrondnftswap/elrondswap-buy.event.ts | 15 ++ .../elrondswap-updateAuction.event.topics.ts | 50 +++++++ .../elrondswap-updateAuction.event.ts | 15 ++ .../elrondswap-withdraw.event.topics.ts | 19 +++ .../elrondswap-withdraw.event.ts | 15 ++ .../endAuction.event.topics.ts | 31 +++++ .../auction-reindex/endAuction.event.ts | 15 ++ .../acceptOffer.event.topics.ts | 21 +++ .../externalEvents/acceptOffer.event.ts | 15 ++ .../entities/auction-reindex/index.ts | 11 ++ .../issue-collection.event.topics.ts | 16 +++ .../auction-reindex/issue-collection.event.ts | 15 ++ .../auction-reindex/listNft.event.topics.ts | 37 +++++ .../entities/auction-reindex/listNft.event.ts | 15 ++ .../auction-reindex/mint.event.topics.ts | 19 +++ .../entities/auction-reindex/mint.event.ts | 15 ++ .../auction-reindex/randomNft.event.topics.ts | 21 +++ .../auction-reindex/randomNft.event.ts | 19 +++ .../auction-reindex/sendOffer.event.topics.ts | 43 ++++++ .../auction-reindex/sendOffer.event.ts | 15 ++ .../auction-reindex/transfer.event.topics.ts | 49 +++++++ .../auction-reindex/transfer.event.ts | 28 ++++ .../update-attributes.event.topics.ts | 19 +++ .../update-attributes.event.ts | 15 ++ .../updateListing.event.topics.ts | 40 ++++++ .../auction-reindex/updateListing.event.ts | 15 ++ .../updatePrice.event.topics.ts | 22 +++ .../auction-reindex/updatePrice.event.ts | 15 ++ .../updatePriceDeadrare.event.topics.ts | 31 +++++ .../updatePriceDeadrare.event.ts | 15 ++ .../auction-reindex/withdraw.event.topics.ts | 27 ++++ .../auction-reindex/withdraw.event.ts | 15 ++ .../withdrawOffer.event.topics.ts | 19 +++ .../auction-reindex/withdrawOffer.event.ts | 15 ++ src/private.app.module.ts | 30 ++-- 80 files changed, 2529 insertions(+), 20 deletions(-) create mode 100644 src/modules/rabbitmq/blockchain-events/handlers-reindex/acceptGlobalOffer-event.handler.ts create mode 100644 src/modules/rabbitmq/blockchain-events/handlers-reindex/acceptOffer-event.handler.ts create mode 100644 src/modules/rabbitmq/blockchain-events/handlers-reindex/bid-event.handler.ts create mode 100644 src/modules/rabbitmq/blockchain-events/handlers-reindex/buy-event.handler.ts create mode 100644 src/modules/rabbitmq/blockchain-events/handlers-reindex/endAuction-event.handler.ts create mode 100644 src/modules/rabbitmq/blockchain-events/handlers-reindex/sendOffer-event.handler.ts create mode 100644 src/modules/rabbitmq/blockchain-events/handlers-reindex/startAuction-event.handler.ts create mode 100644 src/modules/rabbitmq/blockchain-events/handlers-reindex/swapUpdate-event.handler.ts create mode 100644 src/modules/rabbitmq/blockchain-events/handlers-reindex/updateListing-event.handler.ts create mode 100644 src/modules/rabbitmq/blockchain-events/handlers-reindex/updatePrice-event.handler.ts create mode 100644 src/modules/rabbitmq/blockchain-events/handlers-reindex/withdrawAuction-event.handler.ts create mode 100644 src/modules/rabbitmq/blockchain-events/handlers-reindex/withdrawOffer-event.handler.ts create mode 100644 src/modules/rabbitmq/blockchain-events/marketplace-events-processing.service.ts create mode 100644 src/modules/rabbitmq/entities/auction-reindex/acceptGlobalOffer.event.topics.ts create mode 100644 src/modules/rabbitmq/entities/auction-reindex/acceptGlobalOffer.event.ts create mode 100644 src/modules/rabbitmq/entities/auction-reindex/acceptOffer.event.topics.ts create mode 100644 src/modules/rabbitmq/entities/auction-reindex/acceptOffer.event.ts create mode 100644 src/modules/rabbitmq/entities/auction-reindex/acceptOfferDeadrare.event.topics.ts create mode 100644 src/modules/rabbitmq/entities/auction-reindex/acceptOfferDeadrare.event.ts create mode 100644 src/modules/rabbitmq/entities/auction-reindex/acceptOfferFrameit.event.topics.ts create mode 100644 src/modules/rabbitmq/entities/auction-reindex/acceptOfferFrameit.event.ts create mode 100644 src/modules/rabbitmq/entities/auction-reindex/acceptOfferXoxno.event.topics.ts create mode 100644 src/modules/rabbitmq/entities/auction-reindex/acceptOfferXoxno.event.ts create mode 100644 src/modules/rabbitmq/entities/auction-reindex/auction.types.ts create mode 100644 src/modules/rabbitmq/entities/auction-reindex/auctionToken.event.topics.ts create mode 100644 src/modules/rabbitmq/entities/auction-reindex/auctionToken.event.ts create mode 100644 src/modules/rabbitmq/entities/auction-reindex/bid.event.topics.ts create mode 100644 src/modules/rabbitmq/entities/auction-reindex/bid.event.ts create mode 100644 src/modules/rabbitmq/entities/auction-reindex/brandCreated.event.topics.ts create mode 100644 src/modules/rabbitmq/entities/auction-reindex/brandCreated.event.ts create mode 100644 src/modules/rabbitmq/entities/auction-reindex/burn.event.topics.ts create mode 100644 src/modules/rabbitmq/entities/auction-reindex/burn.event.ts create mode 100644 src/modules/rabbitmq/entities/auction-reindex/buySft.event.topics.ts create mode 100644 src/modules/rabbitmq/entities/auction-reindex/buySft.event.ts create mode 100644 src/modules/rabbitmq/entities/auction-reindex/claim.event.topics.ts create mode 100644 src/modules/rabbitmq/entities/auction-reindex/claim.event.ts create mode 100644 src/modules/rabbitmq/entities/auction-reindex/elrondnftswap/elrondswap-acceptOffer.event.topics.ts create mode 100644 src/modules/rabbitmq/entities/auction-reindex/elrondnftswap/elrondswap-acceptOffer.event.ts create mode 100644 src/modules/rabbitmq/entities/auction-reindex/elrondnftswap/elrondswap-auction.event.topics.ts create mode 100644 src/modules/rabbitmq/entities/auction-reindex/elrondnftswap/elrondswap-auction.event.ts create mode 100644 src/modules/rabbitmq/entities/auction-reindex/elrondnftswap/elrondswap-bid.event.topics.ts create mode 100644 src/modules/rabbitmq/entities/auction-reindex/elrondnftswap/elrondswap-bid.event.ts create mode 100644 src/modules/rabbitmq/entities/auction-reindex/elrondnftswap/elrondswap-buy.event.topics.ts create mode 100644 src/modules/rabbitmq/entities/auction-reindex/elrondnftswap/elrondswap-buy.event.ts create mode 100644 src/modules/rabbitmq/entities/auction-reindex/elrondnftswap/elrondswap-updateAuction.event.topics.ts create mode 100644 src/modules/rabbitmq/entities/auction-reindex/elrondnftswap/elrondswap-updateAuction.event.ts create mode 100644 src/modules/rabbitmq/entities/auction-reindex/elrondnftswap/elrondswap-withdraw.event.topics.ts create mode 100644 src/modules/rabbitmq/entities/auction-reindex/elrondnftswap/elrondswap-withdraw.event.ts create mode 100644 src/modules/rabbitmq/entities/auction-reindex/endAuction.event.topics.ts create mode 100644 src/modules/rabbitmq/entities/auction-reindex/endAuction.event.ts create mode 100644 src/modules/rabbitmq/entities/auction-reindex/externalEvents/acceptOffer.event.topics.ts create mode 100644 src/modules/rabbitmq/entities/auction-reindex/externalEvents/acceptOffer.event.ts create mode 100644 src/modules/rabbitmq/entities/auction-reindex/index.ts create mode 100644 src/modules/rabbitmq/entities/auction-reindex/issue-collection.event.topics.ts create mode 100644 src/modules/rabbitmq/entities/auction-reindex/issue-collection.event.ts create mode 100644 src/modules/rabbitmq/entities/auction-reindex/listNft.event.topics.ts create mode 100644 src/modules/rabbitmq/entities/auction-reindex/listNft.event.ts create mode 100644 src/modules/rabbitmq/entities/auction-reindex/mint.event.topics.ts create mode 100644 src/modules/rabbitmq/entities/auction-reindex/mint.event.ts create mode 100644 src/modules/rabbitmq/entities/auction-reindex/randomNft.event.topics.ts create mode 100644 src/modules/rabbitmq/entities/auction-reindex/randomNft.event.ts create mode 100644 src/modules/rabbitmq/entities/auction-reindex/sendOffer.event.topics.ts create mode 100644 src/modules/rabbitmq/entities/auction-reindex/sendOffer.event.ts create mode 100644 src/modules/rabbitmq/entities/auction-reindex/transfer.event.topics.ts create mode 100644 src/modules/rabbitmq/entities/auction-reindex/transfer.event.ts create mode 100644 src/modules/rabbitmq/entities/auction-reindex/update-attributes.event.topics.ts create mode 100644 src/modules/rabbitmq/entities/auction-reindex/update-attributes.event.ts create mode 100644 src/modules/rabbitmq/entities/auction-reindex/updateListing.event.topics.ts create mode 100644 src/modules/rabbitmq/entities/auction-reindex/updateListing.event.ts create mode 100644 src/modules/rabbitmq/entities/auction-reindex/updatePrice.event.topics.ts create mode 100644 src/modules/rabbitmq/entities/auction-reindex/updatePrice.event.ts create mode 100644 src/modules/rabbitmq/entities/auction-reindex/updatePriceDeadrare.event.topics.ts create mode 100644 src/modules/rabbitmq/entities/auction-reindex/updatePriceDeadrare.event.ts create mode 100644 src/modules/rabbitmq/entities/auction-reindex/withdraw.event.topics.ts create mode 100644 src/modules/rabbitmq/entities/auction-reindex/withdraw.event.ts create mode 100644 src/modules/rabbitmq/entities/auction-reindex/withdrawOffer.event.topics.ts create mode 100644 src/modules/rabbitmq/entities/auction-reindex/withdrawOffer.event.ts diff --git a/src/modules/metrics/metrics.controller.ts b/src/modules/metrics/metrics.controller.ts index d011f7e76..bdfaed233 100644 --- a/src/modules/metrics/metrics.controller.ts +++ b/src/modules/metrics/metrics.controller.ts @@ -1,12 +1,11 @@ import { Body, Controller, Get, HttpStatus, Post } from '@nestjs/common'; import { MetricsCollector } from './metrics.collector'; import { RabbitEvent } from './rabbitEvent'; -import { MarketplaceEventsService } from '../rabbitmq/blockchain-events/marketplace-events.service'; -import { MarketplaceTypeEnum } from '../marketplaces/models/MarketplaceType.enum'; +import { MarketplaceEventsProcessingService } from '../rabbitmq/blockchain-events/marketplace-events-processing.service'; @Controller() export class MetricsController { - constructor(private readonly marketplaceEvents: MarketplaceEventsService) {} + constructor(private readonly marketplaceEvents: MarketplaceEventsProcessingService) { } @Get('/metrics') async getMetrics(): Promise { return await MetricsCollector.getMetrics(); @@ -19,7 +18,7 @@ export class MetricsController { @Post('/event') async notify(@Body() payload: RabbitEvent): Promise { - await this.marketplaceEvents.handleNftAuctionEvents(payload?.events, payload?.hash, MarketplaceTypeEnum.External); + await this.marketplaceEvents.handleNftAuctionEvents(payload?.events, payload?.hash); return HttpStatus.OK; } } diff --git a/src/modules/rabbitmq/blockchain-events/handlers-reindex/acceptGlobalOffer-event.handler.ts b/src/modules/rabbitmq/blockchain-events/handlers-reindex/acceptGlobalOffer-event.handler.ts new file mode 100644 index 000000000..cd80dec0c --- /dev/null +++ b/src/modules/rabbitmq/blockchain-events/handlers-reindex/acceptGlobalOffer-event.handler.ts @@ -0,0 +1,36 @@ +import { Injectable, Logger } from '@nestjs/common'; +import { ExternalAuctionEventEnum } from 'src/modules/assets/models'; +import { AuctionsGetterService, AuctionsSetterService } from 'src/modules/auctions'; +import { AuctionStatusEnum } from 'src/modules/auctions/models'; +import { XOXNO_KEY } from 'src/utils/constants'; +import { AcceptGlobalOfferEvent } from '../../entities/auction-reindex/acceptGlobalOffer.event'; +import { Marketplace } from 'src/modules/marketplaces/models'; + +@Injectable() +export class AcceptGlobalOfferEventHandler { + private readonly logger = new Logger(AcceptGlobalOfferEventHandler.name); + constructor( + private auctionsGetterService: AuctionsGetterService, + private auctionsService: AuctionsSetterService, + ) { } + + async handle(event: any, hash: string, marketplace: Marketplace) { + try { + const acceptGlobalOfferEvent = new AcceptGlobalOfferEvent(event); + const topics = acceptGlobalOfferEvent.getTopics(); + this.logger.log(`Accept Global Offer event detected for hash '${hash}' and marketplace '${marketplace?.name}'`); + if (marketplace.key !== XOXNO_KEY || topics.auctionId <= 0) { + return; + } + + let auction = await this.auctionsGetterService.getAuctionByIdAndMarketplace(topics.auctionId, marketplace.key); + + if (!auction) return; + auction.status = AuctionStatusEnum.Closed; + auction.modifiedDate = new Date(new Date().toUTCString()); + this.auctionsService.updateAuction(auction, ExternalAuctionEventEnum.AcceptGlobalOffer); + } catch (error) { + console.error('An errror occured while handling bid event', error); + } + } +} diff --git a/src/modules/rabbitmq/blockchain-events/handlers-reindex/acceptOffer-event.handler.ts b/src/modules/rabbitmq/blockchain-events/handlers-reindex/acceptOffer-event.handler.ts new file mode 100644 index 000000000..bb3cb7c76 --- /dev/null +++ b/src/modules/rabbitmq/blockchain-events/handlers-reindex/acceptOffer-event.handler.ts @@ -0,0 +1,83 @@ +import { Inject, Injectable, Logger, forwardRef } from '@nestjs/common'; +import { ExternalAuctionEventEnum } from 'src/modules/assets/models'; +import { AuctionsGetterService, AuctionsSetterService } from 'src/modules/auctions'; +import { AuctionStatusEnum } from 'src/modules/auctions/models'; +import { MarketplacesService } from 'src/modules/marketplaces/marketplaces.service'; +import { MarketplaceTypeEnum } from 'src/modules/marketplaces/models/MarketplaceType.enum'; +import { NotificationsService } from 'src/modules/notifications/notifications.service'; +import { OfferStatusEnum } from 'src/modules/offers/models'; +import { OffersService } from 'src/modules/offers/offers.service'; +import { FRAMEIT_KEY, XOXNO_KEY } from 'src/utils/constants'; +import { AcceptOfferEvent } from '../../entities/auction-reindex/acceptOffer.event'; +import { AcceptOfferXoxnoEvent } from '../../entities/auction-reindex/acceptOfferXoxno.event'; +import { FeedEventsSenderService } from '../feed-events.service'; +import { AcceptOfferFrameitEvent } from '../../entities/auction-reindex/acceptOfferFrameit.event'; +import { Marketplace } from 'src/modules/marketplaces/models'; + +@Injectable() +export class AcceptOfferEventHandler { + private readonly logger = new Logger(AcceptOfferEventHandler.name); + constructor( + private readonly auctionsGetterService: AuctionsGetterService, + private readonly auctionsService: AuctionsSetterService, + private readonly offersService: OffersService, + @Inject(forwardRef(() => MarketplacesService)) + private readonly marketplaceService: MarketplacesService, + private readonly feedEventsSenderService: FeedEventsSenderService, + private readonly notificationsService: NotificationsService, + ) { } + + async handle(event: any, hash: string, marketplace: Marketplace) { + try { + if (marketplace?.type === MarketplaceTypeEnum.External) { + let acceptOfferEvent = undefined; + let topics = undefined; + if (marketplace.key === XOXNO_KEY) { + acceptOfferEvent = new AcceptOfferXoxnoEvent(event); + topics = acceptOfferEvent.getTopics(); + } + if (marketplace.key === FRAMEIT_KEY) { + acceptOfferEvent = new AcceptOfferFrameitEvent(event); + topics = acceptOfferEvent.getTopics(); + } + if (!acceptOfferEvent) return; + + this.logger.log( + `${acceptOfferEvent.getIdentifier()} event detected for hash '${hash}' and marketplace '${marketplace?.name}'`, + ); + + if (topics.auctionId || topics.auctionId !== 0) { + let auction = await this.auctionsGetterService.getAuctionByIdAndMarketplace(topics.auctionId, marketplace.key); + if (!auction) return; + + auction.status = AuctionStatusEnum.Closed; + auction.modifiedDate = new Date(new Date().toUTCString()); + this.auctionsService.updateAuction(auction, ExternalAuctionEventEnum.AcceptOffer); + } + return; + } + + const acceptOfferEvent = new AcceptOfferEvent(event); + const topics = acceptOfferEvent.getTopics(); + marketplace = await this.marketplaceService.getMarketplaceByType( + acceptOfferEvent.getAddress(), + marketplace.type, + topics.collection, + ); + this.logger.log(`Accept Offer event detected for hash '${hash}' and marketplace '${marketplace?.name}'`); + + const offer = await this.offersService.getOfferByIdAndMarketplace(topics.offerId, marketplace.key); + + await this.offersService.saveOffer({ + ...offer, + status: OfferStatusEnum.Accepted, + modifiedDate: new Date(new Date().toUTCString()), + }); + + await this.feedEventsSenderService.sendAcceptOfferEvent(topics.nftOwner, offer); + await this.notificationsService.updateNotificationStatusForOffers([offer.identifier]); + } catch (error) { + console.error('An errror occured while handling bid event', error); + } + } +} diff --git a/src/modules/rabbitmq/blockchain-events/handlers-reindex/bid-event.handler.ts b/src/modules/rabbitmq/blockchain-events/handlers-reindex/bid-event.handler.ts new file mode 100644 index 000000000..b9296a807 --- /dev/null +++ b/src/modules/rabbitmq/blockchain-events/handlers-reindex/bid-event.handler.ts @@ -0,0 +1,84 @@ +import { Inject, Injectable, Logger, forwardRef } from '@nestjs/common'; +import { PersistenceService } from 'src/common/persistence/persistence.service'; +import { AuctionsGetterService, AuctionsSetterService } from 'src/modules/auctions'; +import { AuctionStatusEnum } from 'src/modules/auctions/models'; +import { MarketplacesService } from 'src/modules/marketplaces/marketplaces.service'; +import { Marketplace } from 'src/modules/marketplaces/models'; +import { MarketplaceTypeEnum } from 'src/modules/marketplaces/models/MarketplaceType.enum'; +import { NotificationsService } from 'src/modules/notifications/notifications.service'; +import { CreateOrderArgs, OrderStatusEnum } from 'src/modules/orders/models'; +import { OrdersService } from 'src/modules/orders/order.service'; +import { ELRONDNFTSWAP_KEY } from 'src/utils/constants'; +import { BidEvent } from '../../entities/auction-reindex'; +import { ElrondSwapBidEvent } from '../../entities/auction-reindex/elrondnftswap/elrondswap-bid.event'; +import { FeedEventsSenderService } from '../feed-events.service'; + +@Injectable() +export class BidEventHandler { + private readonly logger = new Logger(BidEventHandler.name); + constructor( + private auctionsGetterService: AuctionsGetterService, + private auctionsService: AuctionsSetterService, + private ordersService: OrdersService, + private notificationsService: NotificationsService, + private feedEventsSenderService: FeedEventsSenderService, + @Inject(forwardRef(() => MarketplacesService)) + private readonly marketplaceService: MarketplacesService, + private readonly persistenceService: PersistenceService, + ) { } + + async handle(event: any, hash: string, marketplace: Marketplace) { + try { + let [bidEvent, topics] = [undefined, undefined]; + if (marketplace.type === MarketplaceTypeEnum.External) { + [bidEvent, topics] = this.getEventAndTopics(event, marketplace.key); + } else { + [bidEvent, topics] = this.getEventAndTopics(event); + marketplace = await this.marketplaceService.getMarketplaceByType(bidEvent.getAddress(), marketplace.type, topics.collection); + } + if (!marketplace) return; + this.logger.log(`${bidEvent.getIdentifier()} event detected for hash '${hash}' and marketplace '${marketplace?.name}'`); + const auction = await this.auctionsGetterService.getAuctionByIdAndMarketplace(parseInt(topics.auctionId, 16), marketplace.key); + if (!auction) return; + + const activeOrder = await this.ordersService.getActiveOrderForAuction(auction.id); + if (activeOrder && activeOrder.priceAmount === topics.currentBid) { + return; + } + + const order = await this.ordersService.updateAuctionOrders( + new CreateOrderArgs({ + ownerAddress: topics.currentWinner, + auctionId: auction.id, + priceToken: auction.paymentToken, + priceAmount: topics.currentBid, + priceNonce: auction.paymentNonce, + blockHash: hash, + status: OrderStatusEnum.Active, + marketplaceKey: marketplace.key, + }), + activeOrder, + ); + await this.feedEventsSenderService.sendBidEvent(auction, topics, order); + if (auction.maxBidDenominated === order.priceAmountDenominated) { + this.notificationsService.updateNotificationStatus([auction?.id]); + this.notificationsService.addNotifications(auction, order); + this.auctionsService.updateAuctionStatus(auction.id, AuctionStatusEnum.Ended, hash, event.identifier); + this.persistenceService.updateOrderWithStatus(order, OrderStatusEnum.Bought); + } + } catch (error) { + console.error('An errror occured while handling bid event', error); + } + } + + private getEventAndTopics(event: any, marketplaceKey?: string) { + if (marketplaceKey && marketplaceKey === ELRONDNFTSWAP_KEY) { + const bidEvent = new ElrondSwapBidEvent(event); + const topics = bidEvent.getTopics(); + return [bidEvent, topics]; + } + const bidEvent = new BidEvent(event); + const topics = bidEvent.getTopics(); + return [bidEvent, topics]; + } +} diff --git a/src/modules/rabbitmq/blockchain-events/handlers-reindex/buy-event.handler.ts b/src/modules/rabbitmq/blockchain-events/handlers-reindex/buy-event.handler.ts new file mode 100644 index 000000000..b7edc3483 --- /dev/null +++ b/src/modules/rabbitmq/blockchain-events/handlers-reindex/buy-event.handler.ts @@ -0,0 +1,98 @@ +import { Inject, Injectable, Logger, forwardRef } from '@nestjs/common'; +import { AuctionEntity } from 'src/db/auctions'; +import { KroganSwapAuctionEventEnum, ExternalAuctionEventEnum } from 'src/modules/assets/models'; +import { AuctionsGetterService, AuctionsSetterService } from 'src/modules/auctions'; +import { AuctionStatusEnum } from 'src/modules/auctions/models'; +import { MarketplacesService } from 'src/modules/marketplaces/marketplaces.service'; +import { CreateOrderArgs, OrderStatusEnum } from 'src/modules/orders/models'; +import { OrdersService } from 'src/modules/orders/order.service'; +import { BuySftEvent } from '../../entities/auction-reindex'; +import { ClaimEvent } from '../../entities/auction-reindex/claim.event'; +import { ElrondSwapBuyEvent } from '../../entities/auction-reindex/elrondnftswap/elrondswap-buy.event'; +import { FeedEventsSenderService } from '../feed-events.service'; +import { Marketplace } from 'src/modules/marketplaces/models'; + +@Injectable() +export class BuyEventHandler { + private readonly logger = new Logger(BuyEventHandler.name); + constructor( + private auctionsGetterService: AuctionsGetterService, + private auctionsService: AuctionsSetterService, + private ordersService: OrdersService, + private feedEventsSenderService: FeedEventsSenderService, + @Inject(forwardRef(() => MarketplacesService)) + private readonly marketplaceService: MarketplacesService, + ) { } + + async handle(event: any, hash: string, marketplace: Marketplace) { + try { + const { buySftEvent, topics } = this.getEventAndTopics(event, hash); + let auction: AuctionEntity; + + marketplace = await this.marketplaceService.getMarketplaceByType(buySftEvent.getAddress(), marketplace.type, topics.collection); + + if (!marketplace) return; + this.logger.log(`${buySftEvent.getIdentifier()} event detected for hash '${hash}' and marketplace '${marketplace?.name}'`); + + if (topics.auctionId) { + auction = await this.auctionsGetterService.getAuctionByIdAndMarketplace(parseInt(topics.auctionId, 16), marketplace.key); + } else { + const auctionIdentifier = `${topics.collection}-${topics.nonce}`; + auction = await this.auctionsGetterService.getAuctionByIdentifierAndMarketplace(auctionIdentifier, marketplace.key); + } + if (!auction) return; + + const result = await this.auctionsGetterService.getAvailableTokens(auction.id); + const totalRemaining = result ? result[0]?.availableTokens - parseFloat(topics.boughtTokens) : 0; + if (totalRemaining === 0) { + this.auctionsService.updateAuctionStatus(auction.id, AuctionStatusEnum.Ended, hash, AuctionStatusEnum.Ended); + } + const orderSft = await this.ordersService.createOrderForSft( + new CreateOrderArgs({ + ownerAddress: topics.currentWinner, + auctionId: auction.id, + priceToken: auction.paymentToken, + priceAmount: auction.minBid, + priceNonce: auction.paymentNonce, + blockHash: hash, + status: OrderStatusEnum.Bought, + boughtTokens: topics.boughtTokens, + marketplaceKey: marketplace.key, + }), + ); + await this.feedEventsSenderService.sendBuyEvent( + topics.currentWinner, + auction.minBid, + topics.boughtTokens, + orderSft, + auction, + marketplace, + ); + } catch (error) { + console.error('An errror occured while handling bid event', error); + } + } + + private getEventAndTopics(event: any, hash: string) { + if (event.identifier === KroganSwapAuctionEventEnum.Purchase) { + if (Buffer.from(event.topics[0], 'base64').toString() === KroganSwapAuctionEventEnum.UpdateListing) { + this.logger.log( + `Update Listing event detected for hash '${hash}' at Purchase external marketplace ${event.address}, ignore it for the moment`, + ); + return; + } + const buySftEvent = new ElrondSwapBuyEvent(event); + const topics = buySftEvent.getTopics(); + return { buySftEvent, topics }; + } + + if (event.identifier === ExternalAuctionEventEnum.BuyNft) { + const buySftEvent = new ClaimEvent(event); + const topics = buySftEvent.getTopics(); + return { buySftEvent, topics }; + } + const buySftEvent = new BuySftEvent(event); + const topics = buySftEvent.getTopics(); + return { buySftEvent, topics }; + } +} diff --git a/src/modules/rabbitmq/blockchain-events/handlers-reindex/endAuction-event.handler.ts b/src/modules/rabbitmq/blockchain-events/handlers-reindex/endAuction-event.handler.ts new file mode 100644 index 000000000..1adbb4a33 --- /dev/null +++ b/src/modules/rabbitmq/blockchain-events/handlers-reindex/endAuction-event.handler.ts @@ -0,0 +1,50 @@ +import { Inject, Injectable, Logger, forwardRef } from '@nestjs/common'; +import { AuctionEventEnum } from 'src/modules/assets/models'; +import { AuctionsGetterService, AuctionsSetterService } from 'src/modules/auctions'; +import { AuctionStatusEnum } from 'src/modules/auctions/models'; +import { MarketplacesService } from 'src/modules/marketplaces/marketplaces.service'; +import { Marketplace } from 'src/modules/marketplaces/models'; +import { NotificationsService } from 'src/modules/notifications/notifications.service'; +import { OrderStatusEnum } from 'src/modules/orders/models'; +import { OrdersService } from 'src/modules/orders/order.service'; +import { EndAuctionEvent } from '../../entities/auction-reindex'; +import { FeedEventsSenderService } from '../feed-events.service'; + +@Injectable() +export class EndAuctionEventHandler { + private readonly logger = new Logger(EndAuctionEventHandler.name); + constructor( + private auctionsGetterService: AuctionsGetterService, + private auctionsService: AuctionsSetterService, + private ordersService: OrdersService, + private feedEventsSenderService: FeedEventsSenderService, + @Inject(forwardRef(() => MarketplacesService)) + private readonly marketplaceService: MarketplacesService, + private notificationsService: NotificationsService, + ) { } + + async handle(event: any, hash: string, marketplace: Marketplace) { + try { + const endAuctionEvent = new EndAuctionEvent(event); + const topics = endAuctionEvent.getTopics(); + marketplace = await this.marketplaceService.getMarketplaceByType( + endAuctionEvent.getAddress(), + marketplace.type, + topics.collection, + ); + + if (!marketplace) return; + this.logger.log(`End auction event detected for hash '${hash}' and marketplace '${marketplace?.name}'`); + const auction = await this.auctionsGetterService.getAuctionByIdAndMarketplace(parseInt(topics.auctionId, 16), marketplace.key); + + if (!auction) return; + + this.auctionsService.updateAuctionStatus(auction.id, AuctionStatusEnum.Ended, hash, AuctionEventEnum.EndAuctionEvent); + this.notificationsService.updateNotificationStatus([auction.id]); + this.ordersService.updateOrder(auction.id, OrderStatusEnum.Bought); + await this.feedEventsSenderService.sendWonAuctionEvent(topics, auction, marketplace); + } catch (error) { + console.error('An errror occured while handling bid event', error); + } + } +} diff --git a/src/modules/rabbitmq/blockchain-events/handlers-reindex/sendOffer-event.handler.ts b/src/modules/rabbitmq/blockchain-events/handlers-reindex/sendOffer-event.handler.ts new file mode 100644 index 000000000..42ebb4c98 --- /dev/null +++ b/src/modules/rabbitmq/blockchain-events/handlers-reindex/sendOffer-event.handler.ts @@ -0,0 +1,47 @@ +import { Inject, Injectable, Logger, forwardRef } from '@nestjs/common'; +import { OfferEntity } from 'src/db/offers'; +import { MarketplacesService } from 'src/modules/marketplaces/marketplaces.service'; +import { MarketplaceTypeEnum } from 'src/modules/marketplaces/models/MarketplaceType.enum'; +import { NotificationsService } from 'src/modules/notifications/notifications.service'; +import { OfferStatusEnum } from 'src/modules/offers/models'; +import { OffersService } from 'src/modules/offers/offers.service'; +import { SendOfferEvent } from '../../entities/auction-reindex/sendOffer.event'; +import { FeedEventsSenderService } from '../feed-events.service'; +import { Marketplace } from 'src/modules/marketplaces/models'; + +@Injectable() +export class SendOfferEventHandler { + private readonly logger = new Logger(SendOfferEventHandler.name); + constructor( + private readonly offersService: OffersService, + private readonly feedEventsSenderService: FeedEventsSenderService, + private readonly notificationsService: NotificationsService, + @Inject(forwardRef(() => MarketplacesService)) + private readonly marketplaceService: MarketplacesService, + ) { } + + async handle(event: any, hash: string, marketplace: Marketplace) { + try { + if (marketplace.type === MarketplaceTypeEnum.External) { + return; + } + const sendOffer = new SendOfferEvent(event); + const topics = sendOffer.getTopics(); + marketplace = await this.marketplaceService.getMarketplaceByType(sendOffer.getAddress(), marketplace.type, topics.collection); + + if (!marketplace) { + return; + } + + this.logger.log(`Send Offer event detected for hash '${hash}' and marketplace '${marketplace?.name}'`); + + const offer = await this.offersService.saveOffer(OfferEntity.fromEventTopics(topics, hash, marketplace.key, OfferStatusEnum.Active)); + + if (!offer) return; + await this.feedEventsSenderService.sendOfferEvent(offer); + await this.notificationsService.addNotificationForOffer(offer); + } catch (error) { + console.error('An errror occured while handling bid event', error); + } + } +} diff --git a/src/modules/rabbitmq/blockchain-events/handlers-reindex/startAuction-event.handler.ts b/src/modules/rabbitmq/blockchain-events/handlers-reindex/startAuction-event.handler.ts new file mode 100644 index 000000000..03c25c52a --- /dev/null +++ b/src/modules/rabbitmq/blockchain-events/handlers-reindex/startAuction-event.handler.ts @@ -0,0 +1,111 @@ +import { Inject, Injectable, Logger, forwardRef } from '@nestjs/common'; +import { mxConfig } from 'src/config'; +import { AuctionEntity } from 'src/db/auctions'; +import { AssetByIdentifierService } from 'src/modules/assets'; +import { KroganSwapAuctionEventEnum, ExternalAuctionEventEnum } from 'src/modules/assets/models'; +import { AuctionsGetterService, AuctionsSetterService } from 'src/modules/auctions'; +import { ElrondSwapAuctionTypeEnum } from 'src/modules/auctions/models'; +import { MarketplacesService } from 'src/modules/marketplaces/marketplaces.service'; +import { Marketplace } from 'src/modules/marketplaces/models'; +import { UsdPriceService } from 'src/modules/usdPrice/usd-price.service'; +import { ELRONDNFTSWAP_KEY, ENEFTOR_KEY, XOXNO_KEY } from 'src/utils/constants'; +import { AuctionTokenEvent } from '../../entities/auction-reindex'; +import { ElrondSwapAuctionEvent } from '../../entities/auction-reindex/elrondnftswap/elrondswap-auction.event'; +import { ListNftEvent } from '../../entities/auction-reindex/listNft.event'; +import { FeedEventsSenderService } from '../feed-events.service'; + +@Injectable() +export class StartAuctionEventHandler { + private readonly logger = new Logger(StartAuctionEventHandler.name); + constructor( + private auctionsSetterService: AuctionsSetterService, + private auctionsGetterService: AuctionsGetterService, + private feedEventsSenderService: FeedEventsSenderService, + private assetByIdentifierService: AssetByIdentifierService, + private usdPriceService: UsdPriceService, + @Inject(forwardRef(() => MarketplacesService)) + private readonly marketplaceService: MarketplacesService, + ) { } + + async handle(event: any, hash: string, marketplace: Marketplace) { + try { + const { auctionTokenEvent, topics } = this.getEventAndTopics(event); + if (!auctionTokenEvent && !topics) return; + + marketplace = await this.marketplaceService.getMarketplaceByType( + auctionTokenEvent.getAddress(), + marketplace.type, + topics.collection, + ); + + if (!marketplace) return; + this.logger.log( + `${auctionTokenEvent.getIdentifier()} listing event detected for hash '${hash}' and marketplace '${marketplace?.name}'`, + ); + const auction = await this.saveAuction(topics, marketplace, hash); + + if (!auction) return; + + await this.feedEventsSenderService.sendStartAuctionEvent(topics, auction, marketplace); + } catch (error) { + console.error(error); + } + } + + private async saveAuction(topics: any, marketplace: Marketplace, hash: string) { + const auctionIdentifier = `${topics.collection}-${topics.nonce}`; + if (marketplace.key === ELRONDNFTSWAP_KEY || marketplace.key === ENEFTOR_KEY || marketplace.key === XOXNO_KEY) { + if (topics.auctionId === '0') { + let auctionId = await this.auctionsGetterService.getLastAuctionIdForMarketplace(marketplace.key); + topics.auctionId = (auctionId && auctionId > 0 ? auctionId + 1 : 1).toString(16); + } + return await this.handleSaveAuctionFromTopics(auctionIdentifier, topics, hash, marketplace); + } + + return await this.auctionsSetterService.saveAuction(parseInt(topics.auctionId, 16), auctionIdentifier, marketplace, hash); + } + + private async handleSaveAuctionFromTopics( + auctionIdentifier: string, + topics: any, + hash: string, + auctionTokenEventMarketplace: Marketplace, + ) { + let decimals = mxConfig.decimals; + const asset = await this.assetByIdentifierService.getAsset(auctionIdentifier); + if (topics.paymentToken !== mxConfig.egld) { + const paymentToken = await this.usdPriceService.getToken(topics.paymentToken); + decimals = paymentToken.decimals; + } + if (auctionTokenEventMarketplace.key === XOXNO_KEY) { + return await this.auctionsSetterService.saveAuctionEntity( + AuctionEntity.fromAuctionTopics(topics, asset.tags?.toString(), hash, auctionTokenEventMarketplace.key, decimals), + asset.tags, + ); + } + return await this.auctionsSetterService.saveAuctionEntity( + AuctionEntity.fromWithdrawTopics(topics, asset.tags?.toString(), hash, auctionTokenEventMarketplace.key, decimals), + asset.tags, + ); + } + + private getEventAndTopics(event: any) { + if (event.identifier === KroganSwapAuctionEventEnum.NftSwap) { + const auctionTokenEvent = new ElrondSwapAuctionEvent(event); + const topics = auctionTokenEvent.getTopics(); + if (parseInt(topics.auctionType) === ElrondSwapAuctionTypeEnum.Swap) { + return { auctionTokenEvent: null, topics: null }; + } + return { auctionTokenEvent, topics }; + } + + if (event.identifier === ExternalAuctionEventEnum.ListNftOnMarketplace) { + const auctionTokenEvent = new ListNftEvent(event); + const topics = auctionTokenEvent.getTopics(); + return { auctionTokenEvent, topics }; + } + const auctionTokenEvent = new AuctionTokenEvent(event); + const topics = auctionTokenEvent.getTopics(); + return { auctionTokenEvent, topics }; + } +} diff --git a/src/modules/rabbitmq/blockchain-events/handlers-reindex/swapUpdate-event.handler.ts b/src/modules/rabbitmq/blockchain-events/handlers-reindex/swapUpdate-event.handler.ts new file mode 100644 index 000000000..8f297800d --- /dev/null +++ b/src/modules/rabbitmq/blockchain-events/handlers-reindex/swapUpdate-event.handler.ts @@ -0,0 +1,59 @@ +import { Injectable, Logger } from '@nestjs/common'; +import { mxConfig } from 'src/config'; +import { AuctionEntity } from 'src/db/auctions'; +import { KroganSwapAuctionEventEnum } from 'src/modules/assets/models'; +import { AuctionsGetterService, AuctionsSetterService } from 'src/modules/auctions'; +import { UsdPriceService } from 'src/modules/usdPrice/usd-price.service'; +import { BigNumberUtils } from 'src/utils/bigNumber-utils'; +import { ElrondSwapUpdateEvent } from '../../entities/auction-reindex/elrondnftswap/elrondswap-updateAuction.event'; +import { Marketplace } from 'src/modules/marketplaces/models'; + +@Injectable() +export class SwapUpdateEventHandler { + private readonly logger = new Logger(SwapUpdateEventHandler.name); + constructor( + private auctionsGetterService: AuctionsGetterService, + private auctionsService: AuctionsSetterService, + private usdPriceService: UsdPriceService, + ) { } + + async handle(event: any, hash: string, marketplace: Marketplace) { + try { + const updateEvent = new ElrondSwapUpdateEvent(event); + const topics = updateEvent.getTopics(); + this.logger.log(`${updateEvent.getIdentifier()} auction event detected for hash '${hash}' and marketplace '${marketplace?.name}'`); + let auction = await this.auctionsGetterService.getAuctionByIdAndMarketplace(parseInt(topics.auctionId, 16), marketplace.key); + + if (auction) { + await this.updateAuctionPrice(auction, topics, hash); + this.auctionsService.updateAuction(auction, KroganSwapAuctionEventEnum.NftSwapUpdate); + } + } catch (error) { + console.error('An errror occured while handling bid event', error); + } + } + + private async updateAuctionPrice( + auction: AuctionEntity, + topics: { + seller: string; + collection: string; + nonce: string; + auctionId: string; + nrAuctionTokens: number; + price: string; + deadline: number; + }, + hash: string, + ) { + const paymentToken = await this.usdPriceService.getToken(auction.paymentToken); + const decimals = paymentToken?.decimals ?? mxConfig.decimals; + auction.minBid = topics.price; + auction.minBidDenominated = BigNumberUtils.denominateAmount(topics.price, decimals); + auction.maxBid = auction.minBid; + auction.maxBidDenominated = auction.minBidDenominated; + auction.endDate = topics.deadline; + auction.nrAuctionedTokens = topics.nrAuctionTokens; + auction.blockHash = hash; + } +} diff --git a/src/modules/rabbitmq/blockchain-events/handlers-reindex/updateListing-event.handler.ts b/src/modules/rabbitmq/blockchain-events/handlers-reindex/updateListing-event.handler.ts new file mode 100644 index 000000000..00fc801c2 --- /dev/null +++ b/src/modules/rabbitmq/blockchain-events/handlers-reindex/updateListing-event.handler.ts @@ -0,0 +1,67 @@ +import { BinaryUtils } from '@multiversx/sdk-nestjs-common'; +import { Inject, Injectable, Logger, forwardRef } from '@nestjs/common'; +import { AuctionEntity } from 'src/db/auctions'; +import { ExternalAuctionEventEnum } from 'src/modules/assets/models'; +import { AuctionsGetterService, AuctionsSetterService } from 'src/modules/auctions'; +import { MarketplacesService } from 'src/modules/marketplaces/marketplaces.service'; +import { Token } from 'src/modules/usdPrice/Token.model'; +import { UsdPriceService } from 'src/modules/usdPrice/usd-price.service'; +import { BigNumberUtils } from 'src/utils/bigNumber-utils'; +import { UpdateListingEvent } from '../../entities/auction-reindex/updateListing.event'; +import { Marketplace } from 'src/modules/marketplaces/models'; + +@Injectable() +export class UpdateListingEventHandler { + private readonly logger = new Logger(UpdateListingEventHandler.name); + constructor( + private auctionsGetterService: AuctionsGetterService, + private auctionsService: AuctionsSetterService, + @Inject(forwardRef(() => MarketplacesService)) + private readonly marketplaceService: MarketplacesService, + private usdPriceService: UsdPriceService, + ) { } + + async handle(event: any, hash: string, marketplace: Marketplace) { + try { + const updateListingEvent = new UpdateListingEvent(event); + const topics = updateListingEvent.getTopics(); + marketplace = await this.marketplaceService.getMarketplaceByType(updateListingEvent.getAddress(), marketplace.type, topics.collection); + this.logger.log( + `${updateListingEvent.getIdentifier()} listing event detected for hash '${hash}' and marketplace '${marketplace?.name}'`, + ); + let auction = await this.auctionsGetterService.getAuctionByIdAndMarketplace(parseInt(topics.auctionId, 16), marketplace.key); + + if (auction && marketplace) { + const paymentToken = await this.usdPriceService.getToken(auction.paymentToken); + + this.updateAuctionListing(auction, updateListingEvent, paymentToken, hash); + + this.auctionsService.updateAuction(auction, ExternalAuctionEventEnum.UpdateListing); + } + } catch (error) { + console.error('An errror occured while handling bid event', error); + } + } + + private updateAuctionListing(auction: AuctionEntity, event: UpdateListingEvent, paymentToken: Token, hash: string) { + const eventTopics = event.getTopics(); + + if (eventTopics.newBid) { + auction.minBid = eventTopics.newBid; + auction.minBidDenominated = BigNumberUtils.denominateAmount(eventTopics.newBid, paymentToken.decimals); + auction.maxBid = auction.minBid; + auction.maxBidDenominated = auction.minBidDenominated; + } + + if (eventTopics.deadline) { + auction.endDate = eventTopics.deadline; + } + + if (eventTopics.paymentToken) { + auction.paymentToken = eventTopics.paymentToken; + auction.paymentNonce = BinaryUtils.hexToNumber(eventTopics.paymentTokenNonce); + } + + auction.blockHash = hash; + } +} diff --git a/src/modules/rabbitmq/blockchain-events/handlers-reindex/updatePrice-event.handler.ts b/src/modules/rabbitmq/blockchain-events/handlers-reindex/updatePrice-event.handler.ts new file mode 100644 index 000000000..42fa505d0 --- /dev/null +++ b/src/modules/rabbitmq/blockchain-events/handlers-reindex/updatePrice-event.handler.ts @@ -0,0 +1,74 @@ +import { Inject, Injectable, Logger, forwardRef } from '@nestjs/common'; +import { mxConfig } from 'src/config'; +import { AuctionEntity } from 'src/db/auctions'; +import { ExternalAuctionEventEnum } from 'src/modules/assets/models'; +import { AuctionsGetterService, AuctionsSetterService, NftMarketplaceAbiService } from 'src/modules/auctions'; +import { MarketplacesService } from 'src/modules/marketplaces/marketplaces.service'; +import { Marketplace } from 'src/modules/marketplaces/models'; +import { UsdPriceService } from 'src/modules/usdPrice/usd-price.service'; +import { BigNumberUtils } from 'src/utils/bigNumber-utils'; +import { DEADRARE_KEY } from 'src/utils/constants'; +import { UpdatePriceEvent } from '../../entities/auction-reindex/updatePrice.event'; + +@Injectable() +export class UpdatePriceEventHandler { + private readonly logger = new Logger(UpdatePriceEventHandler.name); + constructor( + private auctionsGetterService: AuctionsGetterService, + private auctionsService: AuctionsSetterService, + @Inject(forwardRef(() => MarketplacesService)) + private readonly marketplaceService: MarketplacesService, + private usdPriceService: UsdPriceService, + private nftAbiService: NftMarketplaceAbiService, + ) { } + + async handle(event: any, hash: string, marketplace: Marketplace) { + try { + const updatePriceEvent = new UpdatePriceEvent(event); + const topics = updatePriceEvent.getTopics(); + marketplace = await this.marketplaceService.getMarketplaceByType( + updatePriceEvent.getAddress(), + marketplace.type, + topics.collection, + ); + this.logger.log(`${updatePriceEvent.getIdentifier()} event detected for hash '${hash}' and marketplace '${marketplace?.name}'`); + let auction = await this.auctionsGetterService.getAuctionByIdAndMarketplace(parseInt(topics.auctionId, 16), marketplace.key); + let newPrice: string = await this.getNewPrice(marketplace, topics); + if (auction && newPrice) { + const paymentToken = await this.usdPriceService.getToken(auction.paymentToken); + this.updateAuctionPrice(auction, newPrice, hash, paymentToken?.decimals); + + this.auctionsService.updateAuction(auction, ExternalAuctionEventEnum.UpdatePrice); + } + } catch (error) { + console.error('An errror occured while handling bid event', error); + } + } + + private async getNewPrice( + updatePriceMarketplace: Marketplace, + topicsUpdatePrice: { + collection: string; + nonce: string; + auctionId: string; + newBid: string; + }, + ) { + if (updatePriceMarketplace.key === DEADRARE_KEY) { + const auction = await this.nftAbiService.getAuctionQuery(parseInt(topicsUpdatePrice.auctionId, 16), updatePriceMarketplace); + if (auction) { + return auction.min_bid.valueOf().toString(); + } + } + + return topicsUpdatePrice.newBid; + } + + private updateAuctionPrice(updatedAuction: AuctionEntity, newBid: string, hash: string, decimals: number = mxConfig.decimals) { + updatedAuction.minBid = newBid; + updatedAuction.minBidDenominated = BigNumberUtils.denominateAmount(newBid, decimals); + updatedAuction.maxBid = newBid; + updatedAuction.maxBidDenominated = BigNumberUtils.denominateAmount(newBid, decimals); + updatedAuction.blockHash = hash; + } +} diff --git a/src/modules/rabbitmq/blockchain-events/handlers-reindex/withdrawAuction-event.handler.ts b/src/modules/rabbitmq/blockchain-events/handlers-reindex/withdrawAuction-event.handler.ts new file mode 100644 index 000000000..c5864a7e7 --- /dev/null +++ b/src/modules/rabbitmq/blockchain-events/handlers-reindex/withdrawAuction-event.handler.ts @@ -0,0 +1,62 @@ +import { Inject, Injectable, Logger, forwardRef } from '@nestjs/common'; +import { AuctionEntity } from 'src/db/auctions'; +import { AuctionEventEnum, KroganSwapAuctionEventEnum, ExternalAuctionEventEnum } from 'src/modules/assets/models'; +import { AuctionsGetterService, AuctionsSetterService } from 'src/modules/auctions'; +import { AuctionStatusEnum } from 'src/modules/auctions/models'; +import { MarketplacesService } from 'src/modules/marketplaces/marketplaces.service'; +import { WithdrawEvent } from '../../entities/auction-reindex'; +import { ClaimEvent } from '../../entities/auction-reindex/claim.event'; +import { ElrondSwapWithdrawEvent } from '../../entities/auction-reindex/elrondnftswap/elrondswap-withdraw.event'; +import { Marketplace } from 'src/modules/marketplaces/models'; + +@Injectable() +export class WithdrawAuctionEventHandler { + private readonly logger = new Logger(WithdrawAuctionEventHandler.name); + constructor( + private auctionsGetterService: AuctionsGetterService, + private auctionsService: AuctionsSetterService, + @Inject(forwardRef(() => MarketplacesService)) + private readonly marketplaceService: MarketplacesService, + ) { } + + async handle(event: any, hash: string, marketplace: Marketplace) { + try { + const { withdraw, topics } = this.getEventAndTopics(event); + let auction: AuctionEntity; + marketplace = await this.marketplaceService.getMarketplaceByType(withdraw.getAddress(), marketplace.type, topics.collection); + if (!marketplace) return; + + this.logger.log(`${withdraw.getIdentifier()} event detected for hash '${hash}' and marketplace '${marketplace?.name}'`); + if (topics.auctionId) { + auction = await this.auctionsGetterService.getAuctionByIdAndMarketplace(parseInt(topics.auctionId, 16), marketplace.key); + } else { + const auctionIdentifier = `${topics.collection}-${topics.nonce}`; + auction = await this.auctionsGetterService.getAuctionByIdentifierAndMarketplace(auctionIdentifier, marketplace.key); + } + + if (!auction) return; + + this.auctionsService.updateAuctionStatus(auction.id, AuctionStatusEnum.Closed, hash, AuctionEventEnum.WithdrawEvent); + } catch (error) { + console.error('An errror occured while handling bid event', error); + } + } + + private getEventAndTopics(event: any) { + if (event.identifier === KroganSwapAuctionEventEnum.WithdrawSwap) { + const withdraw = new ElrondSwapWithdrawEvent(event); + const topics = withdraw.getTopics(); + return { withdraw, topics }; + } + + if (event.identifier === ExternalAuctionEventEnum.ClaimBackNft) { + const withdraw = new ClaimEvent(event); + const topics = withdraw.getTopics(); + return { withdraw, topics }; + } + + const withdraw = new WithdrawEvent(event); + const topics = withdraw.getTopics(); + return { withdraw, topics }; + } +} diff --git a/src/modules/rabbitmq/blockchain-events/handlers-reindex/withdrawOffer-event.handler.ts b/src/modules/rabbitmq/blockchain-events/handlers-reindex/withdrawOffer-event.handler.ts new file mode 100644 index 000000000..2538a97a3 --- /dev/null +++ b/src/modules/rabbitmq/blockchain-events/handlers-reindex/withdrawOffer-event.handler.ts @@ -0,0 +1,51 @@ +import { Inject, Injectable, Logger, forwardRef } from '@nestjs/common'; +import { MarketplacesService } from 'src/modules/marketplaces/marketplaces.service'; +import { MarketplaceTypeEnum } from 'src/modules/marketplaces/models/MarketplaceType.enum'; +import { NotificationsService } from 'src/modules/notifications/notifications.service'; +import { OfferStatusEnum } from 'src/modules/offers/models'; +import { OffersService } from 'src/modules/offers/offers.service'; +import { WithdrawOfferEvent } from '../../entities/auction-reindex/withdrawOffer.event'; +import { Marketplace } from 'src/modules/marketplaces/models'; + +@Injectable() +export class WithdrawOfferEventHandler { + private readonly logger = new Logger(WithdrawOfferEventHandler.name); + constructor( + private readonly offersService: OffersService, + private readonly notificationsService: NotificationsService, + @Inject(forwardRef(() => MarketplacesService)) + private readonly marketplaceService: MarketplacesService, + ) { } + + async handle(event: any, hash: string, marketplace: Marketplace) { + try { + if (marketplace.type === MarketplaceTypeEnum.External) { + return; + } + const withdrawOfferEvent = new WithdrawOfferEvent(event); + const topics = withdrawOfferEvent.getTopics(); + marketplace = await this.marketplaceService.getMarketplaceByCollectionAndAddress( + withdrawOfferEvent.getAddress(), + topics.collection, + ); + + if (!marketplace) { + return; + } + this.logger.log(`Withdraw Offer event detected for hash '${hash}' and marketplace '${marketplace?.name}'`); + + const withdrawOffer = await this.offersService.getOfferByIdAndMarketplace(topics.offerId, marketplace.key); + + if (!withdrawOffer) return; + const offer = await this.offersService.saveOffer({ + ...withdrawOffer, + status: OfferStatusEnum.Closed, + modifiedDate: new Date(new Date().toUTCString()), + }); + + this.notificationsService.updateNotificationStatusForOffers([offer.identifier]); + } catch (error) { + console.error('An errror occured while handling bid event', error); + } + } +} diff --git a/src/modules/rabbitmq/blockchain-events/marketplace-events-processing.service.ts b/src/modules/rabbitmq/blockchain-events/marketplace-events-processing.service.ts new file mode 100644 index 000000000..00c0614d2 --- /dev/null +++ b/src/modules/rabbitmq/blockchain-events/marketplace-events-processing.service.ts @@ -0,0 +1,129 @@ +import { Injectable, Logger } from '@nestjs/common'; +import { AuctionEventEnum, KroganSwapAuctionEventEnum, ExternalAuctionEventEnum, MarketplaceEventEnum } from 'src/modules/assets/models'; +import { StartAuctionEventHandler } from './handlers-reindex/startAuction-event.handler'; +import { EndAuctionEventHandler } from './handlers-reindex/endAuction-event.handler'; +import { BidEventHandler } from './handlers-reindex/bid-event.handler'; +import { BuyEventHandler } from './handlers-reindex/buy-event.handler'; +import { WithdrawAuctionEventHandler } from './handlers-reindex/withdrawAuction-event.handler'; +import { UpdatePriceEventHandler } from './handlers-reindex/updatePrice-event.handler'; +import { SendOfferEventHandler } from './handlers-reindex/sendOffer-event.handler'; +import { AcceptGlobalOfferEventHandler } from './handlers-reindex/acceptGlobalOffer-event.handler'; +import { SwapUpdateEventHandler } from './handlers-reindex/swapUpdate-event.handler'; +import { SlackReportService } from 'src/common/services/mx-communication/slack-report.service'; +import { AcceptOfferEventHandler } from './handlers-reindex/acceptOffer-event.handler'; +import { WithdrawOfferEventHandler } from './handlers-reindex/withdrawOffer-event.handler'; +import { UpdateListingEventHandler } from './handlers-reindex/updateListing-event.handler'; +import { MarketplacesService } from 'src/modules/marketplaces/marketplaces.service'; + +@Injectable() +export class MarketplaceEventsProcessingService { + private readonly logger = new Logger(MarketplaceEventsProcessingService.name); + + constructor( + private startAuctionEventHandler: StartAuctionEventHandler, + private endAuctionEventHandler: EndAuctionEventHandler, + private withdrawAuctionEventHandler: WithdrawAuctionEventHandler, + private bidEventHandler: BidEventHandler, + private buyEventHandler: BuyEventHandler, + private updatePriceEventHandler: UpdatePriceEventHandler, + private acceptOfferEventHandler: AcceptOfferEventHandler, + private acceptGlobalOfferEventHandler: AcceptGlobalOfferEventHandler, + private swapUpdateEventHandler: SwapUpdateEventHandler, + private updateListingEventHandler: UpdateListingEventHandler, + private readonly slackReportService: SlackReportService, + private sendOfferEventHandler: SendOfferEventHandler, + private withdrawOfferEventHandler: WithdrawOfferEventHandler, + private marketplaceService: MarketplacesService, + ) { } + + public async handleNftAuctionEvents(auctionEvents: any[], hash: string) { + for (let event of auctionEvents) { + const marketplace = await this.marketplaceService.getMarketplaceByAddress(event.address); + switch (event.identifier) { + case AuctionEventEnum.BidEvent: + case KroganSwapAuctionEventEnum.Bid: + await this.bidEventHandler.handle(event, hash, marketplace); + + break; + case AuctionEventEnum.BuySftEvent: + case ExternalAuctionEventEnum.Buy: + case ExternalAuctionEventEnum.BulkBuy: + case ExternalAuctionEventEnum.BuyFor: + case ExternalAuctionEventEnum.BuyNft: + case KroganSwapAuctionEventEnum.Purchase: + const eventName = Buffer.from(event.topics[0], 'base64').toString(); + if (eventName === ExternalAuctionEventEnum.UpdateOffer || eventName === KroganSwapAuctionEventEnum.UpdateListing) { + this.logger.log(`${eventName} event detected for hash '${hash}' for marketplace ${event.address}, ignore it for the moment`); + continue; + } + await this.buyEventHandler.handle(event, hash, marketplace); + break; + case AuctionEventEnum.WithdrawEvent: + case KroganSwapAuctionEventEnum.WithdrawSwap: + case ExternalAuctionEventEnum.ClaimBackNft: + case ExternalAuctionEventEnum.ReturnListing: + if (Buffer.from(event.topics[0], 'base64').toString() === ExternalAuctionEventEnum.UpdateOffer) { + this.logger.log( + `${event.topics[0]} event detected for hash '${hash}' for marketplace ${event.addreses}, ignore it for the moment`, + ); + continue; + } + await this.withdrawAuctionEventHandler.handle(event, hash, marketplace); + break; + case AuctionEventEnum.EndAuctionEvent: + await this.endAuctionEventHandler.handle(event, hash, marketplace); + break; + case AuctionEventEnum.AuctionTokenEvent: + case ExternalAuctionEventEnum.Listing: + case ExternalAuctionEventEnum.ListNftOnMarketplace: + case KroganSwapAuctionEventEnum.NftSwap: + await this.startAuctionEventHandler.handle(event, hash, marketplace); + break; + case ExternalAuctionEventEnum.ChangePrice: + case ExternalAuctionEventEnum.UpdatePrice: + await this.updatePriceEventHandler.handle(event, hash, marketplace); + break; + case ExternalAuctionEventEnum.UpdateListing: { + await this.updateListingEventHandler.handle(event, hash, marketplace); + break; + } + case ExternalAuctionEventEnum.AcceptOffer: + case ExternalAuctionEventEnum.AcceptOfferFromAuction: + const acceptOfferEventName = Buffer.from(event.topics[0], 'base64').toString(); + if (acceptOfferEventName === ExternalAuctionEventEnum.UserDeposit) { + continue; + } + if (acceptOfferEventName === ExternalAuctionEventEnum.EndTokenEvent) { + await this.withdrawAuctionEventHandler.handle(event, hash, marketplace); + } else { + await this.acceptOfferEventHandler.handle(event, hash, marketplace); + } + + break; + case AuctionEventEnum.WithdrawAuctionAndAcceptOffer: + if (Buffer.from(event.topics[0], 'base64').toString() === AuctionEventEnum.Accept_offer_token_event) { + await this.acceptOfferEventHandler.handle(event, hash, marketplace); + } else { + await this.withdrawAuctionEventHandler.handle(event, hash, marketplace); + } + break; + case ExternalAuctionEventEnum.AcceptGlobalOffer: + await this.acceptGlobalOfferEventHandler.handle(event, hash, marketplace); + break; + case AuctionEventEnum.SendOffer: + await this.sendOfferEventHandler.handle(event, hash, marketplace); + break; + case AuctionEventEnum.WithdrawOffer: + await this.withdrawOfferEventHandler.handle(event, hash, marketplace); + break; + case KroganSwapAuctionEventEnum.NftSwapUpdate: + case KroganSwapAuctionEventEnum.NftSwapExtend: + await this.swapUpdateEventHandler.handle(event, hash, marketplace); + break; + case MarketplaceEventEnum.SCUpgrade: { + await this.slackReportService.sendScUpgradeNotification(event.address); + } + } + } + } +} diff --git a/src/modules/rabbitmq/blockchain-events/nft-events.module.ts b/src/modules/rabbitmq/blockchain-events/nft-events.module.ts index e9f4d5f50..ea3a19a23 100644 --- a/src/modules/rabbitmq/blockchain-events/nft-events.module.ts +++ b/src/modules/rabbitmq/blockchain-events/nft-events.module.ts @@ -102,4 +102,4 @@ import { DisabledMarketplaceEventsModule } from './disable-marketplace/disable-m ], exports: [NftEventsService, NftEventsConsumer], }) -export class NftEventsModule {} +export class NftEventsModule { } diff --git a/src/modules/rabbitmq/entities/auction-reindex/acceptGlobalOffer.event.topics.ts b/src/modules/rabbitmq/entities/auction-reindex/acceptGlobalOffer.event.topics.ts new file mode 100644 index 000000000..30083c67a --- /dev/null +++ b/src/modules/rabbitmq/entities/auction-reindex/acceptGlobalOffer.event.topics.ts @@ -0,0 +1,15 @@ +import { BinaryUtils } from '@multiversx/sdk-nestjs-common'; + +export class AcceptGlobalOfferEventsTopics { + private auctionId: number; + + constructor(rawTopics: string[]) { + this.auctionId = parseInt(BinaryUtils.hexToBigInt(rawTopics[5])?.toString() ?? '0'); + } + + toPlainObject() { + return { + auctionId: this.auctionId, + }; + } +} diff --git a/src/modules/rabbitmq/entities/auction-reindex/acceptGlobalOffer.event.ts b/src/modules/rabbitmq/entities/auction-reindex/acceptGlobalOffer.event.ts new file mode 100644 index 000000000..be1ed2cf7 --- /dev/null +++ b/src/modules/rabbitmq/entities/auction-reindex/acceptGlobalOffer.event.ts @@ -0,0 +1,15 @@ +import { GenericEvent } from '../generic.event'; +import { AcceptGlobalOfferEventsTopics } from './acceptGlobalOffer.event.topics'; + +export class AcceptGlobalOfferEvent extends GenericEvent { + private decodedTopics: AcceptGlobalOfferEventsTopics; + + constructor(init?: Partial) { + super(init); + this.decodedTopics = new AcceptGlobalOfferEventsTopics(this.topics); + } + + getTopics() { + return this.decodedTopics.toPlainObject(); + } +} diff --git a/src/modules/rabbitmq/entities/auction-reindex/acceptOffer.event.topics.ts b/src/modules/rabbitmq/entities/auction-reindex/acceptOffer.event.topics.ts new file mode 100644 index 000000000..43538bd84 --- /dev/null +++ b/src/modules/rabbitmq/entities/auction-reindex/acceptOffer.event.topics.ts @@ -0,0 +1,49 @@ +import { Address } from '@multiversx/sdk-core'; +import { BinaryUtils } from '@multiversx/sdk-nestjs-common'; + +export class AcceptOfferEventsTopics { + private offerId: number; + private collection: string; + private nonce: string; + private nrOfferTokens: number; + private offerOwner: Address; + private nftOwner: Address; + private paymentTokenIdentifier: string; + private paymentTokenNonce: number; + private paymentAmount: string; + private startdate: string; + private enddate: string; + private auctionId: number; + + constructor(rawTopics: string[]) { + this.offerId = parseInt(rawTopics[1], 16); + this.collection = rawTopics[2].toString(); + this.nonce = rawTopics[3]; + this.nrOfferTokens = parseInt(BinaryUtils.hexToBigInt(rawTopics[4])?.toString() ?? '1'); + this.paymentTokenIdentifier = rawTopics[5].toString(); + this.paymentTokenNonce = parseInt(BinaryUtils.hexToBigInt(rawTopics[6])?.toString() ?? '0'); + this.paymentAmount = rawTopics[7].hexBigNumberToString(); + this.offerOwner = new Address(Buffer.from(rawTopics[8], 'hex')); + this.nftOwner = new Address(Buffer.from(rawTopics[9], 'hex')); + this.startdate = parseInt(rawTopics[10]).toString(); + this.enddate = parseInt(rawTopics[11]).toString(); + this.auctionId = parseInt(BinaryUtils.hexToBigInt(rawTopics[14])?.toString() ?? '0'); + } + + toPlainObject() { + return { + offerOwner: this.offerOwner.bech32(), + nftOwner: this.nftOwner.bech32(), + collection: this.collection, + nonce: this.nonce, + offerId: this.offerId, + nrOfferTokens: this.nrOfferTokens, + paymentTokenIdentifier: this.paymentTokenIdentifier, + paymentTokenNonce: this.paymentTokenNonce, + paymentAmount: this.paymentAmount, + startdate: this.startdate, + enddate: this.enddate, + auctionId: this.auctionId, + }; + } +} diff --git a/src/modules/rabbitmq/entities/auction-reindex/acceptOffer.event.ts b/src/modules/rabbitmq/entities/auction-reindex/acceptOffer.event.ts new file mode 100644 index 000000000..2cc8c602f --- /dev/null +++ b/src/modules/rabbitmq/entities/auction-reindex/acceptOffer.event.ts @@ -0,0 +1,15 @@ +import { GenericEvent } from '../generic.event'; +import { AcceptOfferEventsTopics } from './acceptOffer.event.topics'; + +export class AcceptOfferEvent extends GenericEvent { + private decodedTopics: AcceptOfferEventsTopics; + + constructor(init?: Partial) { + super(init); + this.decodedTopics = new AcceptOfferEventsTopics(this.topics); + } + + getTopics() { + return this.decodedTopics.toPlainObject(); + } +} diff --git a/src/modules/rabbitmq/entities/auction-reindex/acceptOfferDeadrare.event.topics.ts b/src/modules/rabbitmq/entities/auction-reindex/acceptOfferDeadrare.event.topics.ts new file mode 100644 index 000000000..76acfd245 --- /dev/null +++ b/src/modules/rabbitmq/entities/auction-reindex/acceptOfferDeadrare.event.topics.ts @@ -0,0 +1,50 @@ +import { Address } from '@multiversx/sdk-core'; +import { BinaryUtils } from '@multiversx/sdk-nestjs-common'; + +export class AcceptOfferDeadrareEventsTopics { + private offerId: number; + private auctionId: number; + private collection: string; + private nonce: string; + private nrOfferTokens: number; + private offerOwner: Address; + private nftOwner: Address; + private paymentTokenIdentifier: string; + private paymentTokenNonce: number; + private paymentAmount: string; + private startdate: string; + private enddate: string; + + constructor(rawTopics: string[]) { + this.offerId = parseInt(rawTopics[1], 16); + this.auctionId = parseInt(rawTopics[2], 16); + this.collection = Buffer.from(rawTopics[3], 'hex').toString(); + this.nonce = rawTopics[4]; + this.paymentTokenIdentifier = Buffer.from(rawTopics[5], 'hex').toString(); + this.paymentTokenNonce = parseInt(BinaryUtils.tryBase64ToBigInt(rawTopics[6])?.toString() ?? '0'); + this.paymentAmount = rawTopics[7].hexBigNumberToString(); + this.nrOfferTokens = parseInt(BinaryUtils.hexToBigInt(rawTopics[9])?.toString() ?? '1'); + + this.startdate = parseInt(rawTopics[9], 16).toString(); + this.enddate = parseInt(rawTopics[8], 16).toString(); + this.offerOwner = new Address(Buffer.from(rawTopics[12], 'hex')); + this.nftOwner = new Address(Buffer.from(rawTopics[13], 'hex')); + } + + toPlainObject() { + return { + offerOwner: this.offerOwner.bech32(), + nftOwner: this.nftOwner.bech32(), + collection: this.collection, + nonce: this.nonce, + offerId: this.offerId, + nrOfferTokens: this.nrOfferTokens, + paymentTokenIdentifier: this.paymentTokenIdentifier, + paymentTokenNonce: this.paymentTokenNonce, + paymentAmount: this.paymentAmount, + startdate: this.startdate, + enddate: this.enddate, + auctionId: this.auctionId, + }; + } +} diff --git a/src/modules/rabbitmq/entities/auction-reindex/acceptOfferDeadrare.event.ts b/src/modules/rabbitmq/entities/auction-reindex/acceptOfferDeadrare.event.ts new file mode 100644 index 000000000..8d03cfcc0 --- /dev/null +++ b/src/modules/rabbitmq/entities/auction-reindex/acceptOfferDeadrare.event.ts @@ -0,0 +1,15 @@ +import { GenericEvent } from '../generic.event'; +import { AcceptOfferDeadrareEventsTopics } from './acceptOfferDeadrare.event.topics'; + +export class AcceptOfferDeadrareEvent extends GenericEvent { + private decodedTopics: AcceptOfferDeadrareEventsTopics; + + constructor(init?: Partial) { + super(init); + this.decodedTopics = new AcceptOfferDeadrareEventsTopics(this.topics); + } + + getTopics() { + return this.decodedTopics.toPlainObject(); + } +} diff --git a/src/modules/rabbitmq/entities/auction-reindex/acceptOfferFrameit.event.topics.ts b/src/modules/rabbitmq/entities/auction-reindex/acceptOfferFrameit.event.topics.ts new file mode 100644 index 000000000..ea0dfdbb3 --- /dev/null +++ b/src/modules/rabbitmq/entities/auction-reindex/acceptOfferFrameit.event.topics.ts @@ -0,0 +1,46 @@ +import { Address } from '@multiversx/sdk-core'; +import { BinaryUtils } from '@multiversx/sdk-nestjs-common'; +export class AcceptOfferFrameitEventsTopics { + private offerId: number; + private collection: string; + private nonce: string; + private nrOfferTokens: number; + private offerOwner: Address; + private paymentTokenIdentifier: string; + private paymentTokenNonce: number; + private paymentAmount: string; + private nftOwner: Address; + private auctionId: number; + + constructor(rawTopics: string[]) { + this.offerId = parseInt(rawTopics[1], 16); + this.collection = Buffer.from(rawTopics[2], 'hex').toString(); + this.nonce = rawTopics[3]; + this.nrOfferTokens = parseInt(BinaryUtils.hexToBigInt(rawTopics[4])?.toString() ?? '1'); + this.offerOwner = new Address(Buffer.from(rawTopics[5], 'hex')); + this.paymentTokenIdentifier = Buffer.from(rawTopics[6], 'hex').toString(); + this.paymentTokenNonce = parseInt(BinaryUtils.hexToBigInt(rawTopics[7])?.toString() ?? '0'); + this.paymentAmount = rawTopics[8].hexBigNumberToString(); + if (rawTopics.length > 10) { + this.nftOwner = new Address(Buffer.from(rawTopics[10], 'hex')); + } + if (rawTopics.length > 11) { + this.auctionId = parseInt(BinaryUtils.tryBase64ToBigInt(rawTopics[11])?.toString() ?? '0'); + } + } + + toPlainObject() { + return { + offerOwner: this.offerOwner.bech32(), + nftOwner: this.nftOwner?.bech32(), + collection: this.collection, + nonce: this.nonce, + offerId: this.offerId, + nrOfferTokens: this.nrOfferTokens, + paymentTokenIdentifier: this.paymentTokenIdentifier, + paymentTokenNonce: this.paymentTokenNonce, + paymentAmount: this.paymentAmount, + auctionId: this.auctionId, + }; + } +} diff --git a/src/modules/rabbitmq/entities/auction-reindex/acceptOfferFrameit.event.ts b/src/modules/rabbitmq/entities/auction-reindex/acceptOfferFrameit.event.ts new file mode 100644 index 000000000..9cf7300a1 --- /dev/null +++ b/src/modules/rabbitmq/entities/auction-reindex/acceptOfferFrameit.event.ts @@ -0,0 +1,15 @@ +import { GenericEvent } from '../generic.event'; +import { AcceptOfferFrameitEventsTopics } from './acceptOfferFrameit.event.topics'; + +export class AcceptOfferFrameitEvent extends GenericEvent { + private decodedTopics: AcceptOfferFrameitEventsTopics; + + constructor(init?: Partial) { + super(init); + this.decodedTopics = new AcceptOfferFrameitEventsTopics(this.topics); + } + + getTopics() { + return this.decodedTopics.toPlainObject(); + } +} diff --git a/src/modules/rabbitmq/entities/auction-reindex/acceptOfferXoxno.event.topics.ts b/src/modules/rabbitmq/entities/auction-reindex/acceptOfferXoxno.event.topics.ts new file mode 100644 index 000000000..f3962895e --- /dev/null +++ b/src/modules/rabbitmq/entities/auction-reindex/acceptOfferXoxno.event.topics.ts @@ -0,0 +1,49 @@ +import { Address } from '@multiversx/sdk-core'; +import { BinaryUtils } from '@multiversx/sdk-nestjs-common'; + +export class AcceptOfferXoxnoEventsTopics { + private offerId: number; + private collection: string; + private nonce: string; + private nrOfferTokens: number; + private offerOwner: Address; + private nftOwner: Address; + private paymentTokenIdentifier: string; + private paymentTokenNonce: number; + private paymentAmount: string; + private startdate: string; + private enddate: string; + private auctionId: number; + + constructor(rawTopics: string[]) { + this.collection = Buffer.from(rawTopics[1], 'base64').toString(); + this.nonce = rawTopics[2]; + this.nrOfferTokens = parseInt(BinaryUtils.hexToBigInt(rawTopics[3])?.toString() ?? '1'); + this.paymentTokenIdentifier = Buffer.from(rawTopics[5], 'hex').toString(); + this.paymentTokenNonce = parseInt(BinaryUtils.tryBase64ToBigInt(rawTopics[6])?.toString() ?? '0'); + this.paymentAmount = rawTopics[7].hexBigNumberToString(); + this.enddate = parseInt(rawTopics[8], 16).toString(); + this.startdate = parseInt(rawTopics[9], 16).toString(); + this.offerOwner = new Address(Buffer.from(rawTopics[10], 'hex')); + this.offerId = parseInt(rawTopics[12], 16); + this.nftOwner = new Address(Buffer.from(rawTopics[13], 'hex')); + this.auctionId = parseInt(BinaryUtils.hexToBigInt(rawTopics[14])?.toString() ?? '0'); + } + + toPlainObject() { + return { + offerOwner: this.offerOwner.bech32(), + nftOwner: this.nftOwner.bech32(), + collection: this.collection, + nonce: this.nonce, + offerId: this.offerId, + nrOfferTokens: this.nrOfferTokens, + paymentTokenIdentifier: this.paymentTokenIdentifier, + paymentTokenNonce: this.paymentTokenNonce, + paymentAmount: this.paymentAmount, + startdate: this.startdate, + enddate: this.enddate, + auctionId: this.auctionId, + }; + } +} diff --git a/src/modules/rabbitmq/entities/auction-reindex/acceptOfferXoxno.event.ts b/src/modules/rabbitmq/entities/auction-reindex/acceptOfferXoxno.event.ts new file mode 100644 index 000000000..21c7ddeff --- /dev/null +++ b/src/modules/rabbitmq/entities/auction-reindex/acceptOfferXoxno.event.ts @@ -0,0 +1,15 @@ +import { GenericEvent } from '../generic.event'; +import { AcceptOfferXoxnoEventsTopics } from './acceptOfferXoxno.event.topics'; + +export class AcceptOfferXoxnoEvent extends GenericEvent { + private decodedTopics: AcceptOfferXoxnoEventsTopics; + + constructor(init?: Partial) { + super(init); + this.decodedTopics = new AcceptOfferXoxnoEventsTopics(this.topics); + } + + getTopics() { + return this.decodedTopics.toPlainObject(); + } +} diff --git a/src/modules/rabbitmq/entities/auction-reindex/auction.types.ts b/src/modules/rabbitmq/entities/auction-reindex/auction.types.ts new file mode 100644 index 000000000..3f0ad9762 --- /dev/null +++ b/src/modules/rabbitmq/entities/auction-reindex/auction.types.ts @@ -0,0 +1,42 @@ +export type BidEventType = { + collection: string; + nonce: string; + auctionId: string; + nrAuctionTokens: string; + currentWinner: string; + currentBid: string; +}; + +export type BuySftEventType = { + collection: string; + nonce: string; + auctionId: string; + currentWinner: string; + currentBid: string; +}; + +export type WithdrawEventType = { + collection: string; + nonce: string; + auctionId: string; + nrAuctionTokens: string; + originalOwner: string; +}; + +export type EndAuctionEventType = { + collection: string; + nonce: string; + auctionId: string; + nrAuctionTokens: string; + currentWinner: string; + currentBid: string; +}; + +export type AuctionTokenEventType = { + collection: string; + nonce: string; + auctionId: string; + nrAuctionTokens: string; + currentWinner: string; + currentBid: string; +}; diff --git a/src/modules/rabbitmq/entities/auction-reindex/auctionToken.event.topics.ts b/src/modules/rabbitmq/entities/auction-reindex/auctionToken.event.topics.ts new file mode 100644 index 000000000..c848f89f8 --- /dev/null +++ b/src/modules/rabbitmq/entities/auction-reindex/auctionToken.event.topics.ts @@ -0,0 +1,58 @@ +import { Address } from '@multiversx/sdk-core/out'; +import { BinaryUtils } from '@multiversx/sdk-nestjs-common'; + +export class AuctionTokenEventsTopics { + private collection: string; + private nonce: string; + private auctionId: string; + private nrAuctionTokens: string; + private originalOwner: string; + private minBid: string; + private maxBid: string; + private startTime: number; + private endTime: number; + private paymentToken: string; + private paymentNonce: number; + private auctionType: string; + + constructor(rawTopics: string[]) { + this.collection = Buffer.from(rawTopics[1], 'hex').toString(); + this.nonce = rawTopics[2]; + this.auctionId = rawTopics[3]; + this.nrAuctionTokens = parseInt(rawTopics[4], 16).toString(); + this.originalOwner = new Address(Buffer.from(rawTopics[5], 'hex')).bech32(); + + this.minBid = BinaryUtils.hexToNumber(rawTopics[6]).toString(); + this.maxBid = rawTopics[7] ? BinaryUtils.hexToNumber(rawTopics[7]).toString() : '0'; + this.startTime = BinaryUtils.hexToNumber(rawTopics[8]); + this.endTime = rawTopics[9] ? parseInt(BinaryUtils.hexToNumber(rawTopics[9]).toString()) : 0; + this.paymentToken = rawTopics[10]; + this.paymentNonce = rawTopics[11] ? parseInt(BinaryUtils.hexToNumber(rawTopics[11]).toString()) : 0; + this.auctionType = BinaryUtils.hexToNumber(rawTopics[12]).toString(); + + if (this.startTime.toString().length > 10) { + this.startTime = parseInt(this.startTime.toString().substring(0, 10)); + } + if (this.endTime.toString().length > 10) { + this.endTime = parseInt(this.endTime.toString().substring(0, 10)); + } + } + + toPlainObject() { + return { + originalOwner: this.originalOwner, + collection: this.collection, + nonce: this.nonce, + auctionId: this.auctionId, + nrAuctionTokens: this.nrAuctionTokens, + minBid: this.minBid, + price: this.minBid, + maxBid: this.maxBid, + startTime: this.startTime, + endTime: this.endTime, + paymentToken: this.paymentToken, + paymentNonce: this.paymentNonce, + auctionType: this.auctionType, + }; + } +} diff --git a/src/modules/rabbitmq/entities/auction-reindex/auctionToken.event.ts b/src/modules/rabbitmq/entities/auction-reindex/auctionToken.event.ts new file mode 100644 index 000000000..6377b9d0d --- /dev/null +++ b/src/modules/rabbitmq/entities/auction-reindex/auctionToken.event.ts @@ -0,0 +1,15 @@ +import { GenericEvent } from '../generic.event'; +import { AuctionTokenEventsTopics } from './auctionToken.event.topics'; + +export class AuctionTokenEvent extends GenericEvent { + private decodedTopics: AuctionTokenEventsTopics; + + constructor(init?: Partial) { + super(init); + this.decodedTopics = new AuctionTokenEventsTopics(this.topics); + } + + getTopics() { + return this.decodedTopics.toPlainObject(); + } +} diff --git a/src/modules/rabbitmq/entities/auction-reindex/bid.event.topics.ts b/src/modules/rabbitmq/entities/auction-reindex/bid.event.topics.ts new file mode 100644 index 000000000..30bfedc68 --- /dev/null +++ b/src/modules/rabbitmq/entities/auction-reindex/bid.event.topics.ts @@ -0,0 +1,31 @@ +import { Address } from '@multiversx/sdk-core'; +import '../../../../utils/extensions'; + +export class BidEventsTopics { + private collection: string; + private nonce: string; + private auctionId: string; + private nrAuctionTokens: string; + private currentWinner: Address; + private currentBid: string; + + constructor(rawTopics: string[]) { + this.collection = Buffer.from(rawTopics[1], 'hex').toString(); + this.nonce = rawTopics[2]; + this.auctionId = rawTopics[3]; + this.nrAuctionTokens = parseInt(rawTopics[4], 16).toString(); + this.currentWinner = new Address(Buffer.from(rawTopics[5], 'hex')); + this.currentBid = rawTopics[6].hexBigNumberToString(); + } + + toPlainObject() { + return { + currentWinner: this.currentWinner.bech32(), + collection: this.collection, + nonce: this.nonce, + auctionId: this.auctionId, + nrAuctionTokens: this.nrAuctionTokens, + currentBid: this.currentBid, + }; + } +} diff --git a/src/modules/rabbitmq/entities/auction-reindex/bid.event.ts b/src/modules/rabbitmq/entities/auction-reindex/bid.event.ts new file mode 100644 index 000000000..408cee8b5 --- /dev/null +++ b/src/modules/rabbitmq/entities/auction-reindex/bid.event.ts @@ -0,0 +1,15 @@ +import { GenericEvent } from '../generic.event'; +import { BidEventsTopics } from './bid.event.topics'; + +export class BidEvent extends GenericEvent { + private decodedTopics: BidEventsTopics; + + constructor(init?: Partial) { + super(init); + this.decodedTopics = new BidEventsTopics(this.topics); + } + + getTopics() { + return this.decodedTopics.toPlainObject(); + } +} diff --git a/src/modules/rabbitmq/entities/auction-reindex/brandCreated.event.topics.ts b/src/modules/rabbitmq/entities/auction-reindex/brandCreated.event.topics.ts new file mode 100644 index 000000000..167e65443 --- /dev/null +++ b/src/modules/rabbitmq/entities/auction-reindex/brandCreated.event.topics.ts @@ -0,0 +1,15 @@ +import '../../../../utils/extensions'; + +export class BrandCreatedEventTopics { + private eventIdentifier: string; + + constructor(rawTopics: string[]) { + this.eventIdentifier = Buffer.from(rawTopics[0], 'base64').toString(); + } + + toPlainObject() { + return { + eventIdentifier: this.eventIdentifier, + }; + } +} diff --git a/src/modules/rabbitmq/entities/auction-reindex/brandCreated.event.ts b/src/modules/rabbitmq/entities/auction-reindex/brandCreated.event.ts new file mode 100644 index 000000000..4640320c9 --- /dev/null +++ b/src/modules/rabbitmq/entities/auction-reindex/brandCreated.event.ts @@ -0,0 +1,15 @@ +import { GenericEvent } from '../generic.event'; +import { BrandCreatedEventTopics } from './brandCreated.event.topics'; + +export class BrandCreatedEvent extends GenericEvent { + private decodedTopics: BrandCreatedEventTopics; + + constructor(init?: Partial) { + super(init); + this.decodedTopics = new BrandCreatedEventTopics(this.topics); + } + + getTopics() { + return this.decodedTopics.toPlainObject(); + } +} diff --git a/src/modules/rabbitmq/entities/auction-reindex/burn.event.topics.ts b/src/modules/rabbitmq/entities/auction-reindex/burn.event.topics.ts new file mode 100644 index 000000000..635f6f628 --- /dev/null +++ b/src/modules/rabbitmq/entities/auction-reindex/burn.event.topics.ts @@ -0,0 +1,19 @@ +import { BinaryUtils } from '@multiversx/sdk-nestjs-common'; +import '../../../../utils/extensions'; + +export class BurnEventsTopics { + private collection: string; + private nonce: string; + + constructor(rawTopics: string[]) { + this.collection = BinaryUtils.base64Decode(rawTopics[0]); + this.nonce = BinaryUtils.base64ToHex(rawTopics[1]); + } + + toPlainObject() { + return { + collection: this.collection, + nonce: this.nonce, + }; + } +} diff --git a/src/modules/rabbitmq/entities/auction-reindex/burn.event.ts b/src/modules/rabbitmq/entities/auction-reindex/burn.event.ts new file mode 100644 index 000000000..ec030dc63 --- /dev/null +++ b/src/modules/rabbitmq/entities/auction-reindex/burn.event.ts @@ -0,0 +1,15 @@ +import { GenericEvent } from '../generic.event'; +import { BurnEventsTopics } from './burn.event.topics'; + +export class BurnEvent extends GenericEvent { + private decodedTopics: BurnEventsTopics; + + constructor(init?: Partial) { + super(init); + this.decodedTopics = new BurnEventsTopics(this.topics); + } + + getTopics() { + return this.decodedTopics.toPlainObject(); + } +} diff --git a/src/modules/rabbitmq/entities/auction-reindex/buySft.event.topics.ts b/src/modules/rabbitmq/entities/auction-reindex/buySft.event.topics.ts new file mode 100644 index 000000000..0381328ee --- /dev/null +++ b/src/modules/rabbitmq/entities/auction-reindex/buySft.event.topics.ts @@ -0,0 +1,34 @@ +import { Address } from '@multiversx/sdk-core'; +import '../../../../utils/extensions'; + +export class BuySftEventsTopics { + private collection: string; + private nonce: string; + private auctionId: string; + private currentWinner: Address; + private bid: string; + private boughtTokens: string; + private paymentToken: string; + + constructor(rawTopics: string[]) { + this.collection = Buffer.from(rawTopics[1], 'hex').toString(); + this.nonce = rawTopics[2]; + this.auctionId = rawTopics[3]; + this.boughtTokens = rawTopics[4].hexBigNumberToString(); + this.currentWinner = new Address(Buffer.from(rawTopics[5], 'hex')); + this.bid = rawTopics[6].hexBigNumberToString(); + this.paymentToken = rawTopics[8]; + } + + toPlainObject() { + return { + currentWinner: this.currentWinner.bech32(), + collection: this.collection, + nonce: this.nonce, + auctionId: this.auctionId, + bid: this.bid, + boughtTokens: this.boughtTokens, + paymentToken: this.paymentToken, + }; + } +} diff --git a/src/modules/rabbitmq/entities/auction-reindex/buySft.event.ts b/src/modules/rabbitmq/entities/auction-reindex/buySft.event.ts new file mode 100644 index 000000000..b4245c176 --- /dev/null +++ b/src/modules/rabbitmq/entities/auction-reindex/buySft.event.ts @@ -0,0 +1,15 @@ +import { GenericEvent } from '../generic.event'; +import { BuySftEventsTopics } from './buySft.event.topics'; + +export class BuySftEvent extends GenericEvent { + private decodedTopics: BuySftEventsTopics; + + constructor(init?: Partial) { + super(init); + this.decodedTopics = new BuySftEventsTopics(this.topics); + } + + getTopics() { + return this.decodedTopics.toPlainObject(); + } +} diff --git a/src/modules/rabbitmq/entities/auction-reindex/claim.event.topics.ts b/src/modules/rabbitmq/entities/auction-reindex/claim.event.topics.ts new file mode 100644 index 000000000..cf194cb22 --- /dev/null +++ b/src/modules/rabbitmq/entities/auction-reindex/claim.event.topics.ts @@ -0,0 +1,29 @@ +import { Address } from '@multiversx/sdk-core'; + +export class ClaimEventsTopics { + private currentWinner: Address; + private collection: string; + private nonce: string; + private bid: string = '0'; + private auctionId: string; + private boughtTokens: string = '1'; + private paymentToken: string; + + constructor(rawTopics: string[]) { + this.currentWinner = new Address(Buffer.from(rawTopics[1], 'base64')); + this.collection = Buffer.from(rawTopics[2], 'base64').toString(); + this.nonce = Buffer.from(rawTopics[3], 'base64').toString('hex'); + } + + toPlainObject() { + return { + currentWinner: this.currentWinner.bech32(), + collection: this.collection, + nonce: this.nonce, + auctionId: this.auctionId, + boughtTokens: this.boughtTokens, + bid: this.bid, + paymentToken: this.paymentToken, + }; + } +} diff --git a/src/modules/rabbitmq/entities/auction-reindex/claim.event.ts b/src/modules/rabbitmq/entities/auction-reindex/claim.event.ts new file mode 100644 index 000000000..45e67713b --- /dev/null +++ b/src/modules/rabbitmq/entities/auction-reindex/claim.event.ts @@ -0,0 +1,15 @@ +import { GenericEvent } from '../generic.event'; +import { ClaimEventsTopics } from './claim.event.topics'; + +export class ClaimEvent extends GenericEvent { + private decodedTopics: ClaimEventsTopics; + + constructor(init?: Partial) { + super(init); + this.decodedTopics = new ClaimEventsTopics(this.topics); + } + + getTopics() { + return this.decodedTopics.toPlainObject(); + } +} diff --git a/src/modules/rabbitmq/entities/auction-reindex/elrondnftswap/elrondswap-acceptOffer.event.topics.ts b/src/modules/rabbitmq/entities/auction-reindex/elrondnftswap/elrondswap-acceptOffer.event.topics.ts new file mode 100644 index 000000000..808d1906c --- /dev/null +++ b/src/modules/rabbitmq/entities/auction-reindex/elrondnftswap/elrondswap-acceptOffer.event.topics.ts @@ -0,0 +1,48 @@ +import { Address, BinaryCodec, FieldDefinition, StructType, TokenIdentifierType, U64Type } from '@multiversx/sdk-core/out'; + +export class ElrondSwapAcceptOfferTopics { + private offerId: number; + private collection: string; + private nonce: string; + private nrOfferTokens: string; + private originalOwner: Address; + private paymentAmount: string; + private paymentToken: string; + private paymentTokenNonce: string; + + constructor(rawTopics: string[]) { + this.offerId = parseInt(Buffer.from(rawTopics[1], 'base64').toString('hex'), 16); + this.collection = Buffer.from(rawTopics[2], 'base64').toString(); + this.nonce = Buffer.from(rawTopics[3], 'base64').toString('hex'); + this.nrOfferTokens = parseInt(Buffer.from(rawTopics[4], 'base64').toString('hex'), 16).toString(); + this.originalOwner = new Address(Buffer.from(rawTopics[5], 'base64')); + this.paymentAmount = Buffer.from(rawTopics[6], 'base64').toString('hex').hexBigNumberToString(); + let token = decodeToken(Buffer.from(rawTopics[7], 'base64')); + this.paymentToken = token.token_type; + this.paymentTokenNonce = token.nonce; + } + + toPlainObject() { + return { + originalOwner: this.originalOwner.bech32(), + collection: this.collection, + nonce: this.nonce, + offerId: this.offerId, + nrOfferTokens: this.nrOfferTokens, + paymentAmount: this.paymentAmount, + paymentToken: this.paymentToken, + paymentTokenNonce: this.paymentTokenNonce, + }; + } +} + +function decodeToken(bufer: Buffer): any { + const codec = new BinaryCodec(); + const type = new StructType('EsdtToken', [ + new FieldDefinition('token_type', '', new TokenIdentifierType()), + new FieldDefinition('nonce', '', new U64Type()), + ]); + + const [decoded] = codec.decodeNested(bufer, type); + return decoded.valueOf(); +} diff --git a/src/modules/rabbitmq/entities/auction-reindex/elrondnftswap/elrondswap-acceptOffer.event.ts b/src/modules/rabbitmq/entities/auction-reindex/elrondnftswap/elrondswap-acceptOffer.event.ts new file mode 100644 index 000000000..072749119 --- /dev/null +++ b/src/modules/rabbitmq/entities/auction-reindex/elrondnftswap/elrondswap-acceptOffer.event.ts @@ -0,0 +1,15 @@ +import { GenericEvent } from '../../generic.event'; +import { ElrondSwapAcceptOfferTopics } from './elrondswap-acceptOffer.event.topics'; + +export class ElrondSwapAcceptOfferEvent extends GenericEvent { + private decodedTopics: ElrondSwapAcceptOfferTopics; + + constructor(init?: Partial) { + super(init); + this.decodedTopics = new ElrondSwapAcceptOfferTopics(this.topics); + } + + getTopics() { + return this.decodedTopics.toPlainObject(); + } +} diff --git a/src/modules/rabbitmq/entities/auction-reindex/elrondnftswap/elrondswap-auction.event.topics.ts b/src/modules/rabbitmq/entities/auction-reindex/elrondnftswap/elrondswap-auction.event.topics.ts new file mode 100644 index 000000000..e280f2863 --- /dev/null +++ b/src/modules/rabbitmq/entities/auction-reindex/elrondnftswap/elrondswap-auction.event.topics.ts @@ -0,0 +1,55 @@ +import { Address, BinaryCodec, FieldDefinition, StructType, TokenIdentifierType, U64Type } from '@multiversx/sdk-core'; +import { NumberUtils } from '@multiversx/sdk-nestjs-common'; + +export class ElrondSwapAuctionTopics { + private auctionId: string; + private collection: string; + private nonce: string; + private nrAuctionTokens: string; + private originalOwner: Address; + private price: string; + private paymentToken: string; + private paymentTokenNonce: string; + private auctionType: string; + private deadline: number; + + constructor(rawTopics: string[]) { + let token = decodeToken(Buffer.from(rawTopics[7], 'base64')); + this.auctionId = Buffer.from(rawTopics[1], 'base64').toString('hex'); + this.collection = Buffer.from(rawTopics[2], 'base64').toString(); + this.nonce = Buffer.from(rawTopics[3], 'base64').toString('hex'); + this.nrAuctionTokens = parseInt(Buffer.from(rawTopics[4], 'base64').toString('hex'), 16).toString(); + this.originalOwner = new Address(Buffer.from(rawTopics[5], 'base64')); + this.price = Buffer.from(rawTopics[6], 'base64').toString('hex').hexBigNumberToString(); + this.paymentToken = token.token_type; + this.paymentTokenNonce = token.nonce; + this.auctionType = Buffer.from(rawTopics[8], 'base64').toString('hex'); + this.deadline = parseInt(NumberUtils.numberDecode(rawTopics[9] ?? '00')); + } + + toPlainObject() { + return { + originalOwner: this.originalOwner.bech32(), + collection: this.collection, + nonce: this.nonce, + auctionId: this.auctionId, + nrAuctionTokens: this.nrAuctionTokens, + price: this.price, + paymentToken: this.paymentToken, + paymentTokenNonce: this.paymentTokenNonce, + auctionType: this.auctionType, + deadline: this.deadline, + }; + } +} + +function decodeToken(bufer: Buffer): any { + const codec = new BinaryCodec(); + const type = new StructType('EsdtToken', [ + new FieldDefinition('token_type', '', new TokenIdentifierType()), + new FieldDefinition('nonce', '', new U64Type()), + ]); + + const [decoded] = codec.decodeNested(bufer, type); + return decoded.valueOf(); +} diff --git a/src/modules/rabbitmq/entities/auction-reindex/elrondnftswap/elrondswap-auction.event.ts b/src/modules/rabbitmq/entities/auction-reindex/elrondnftswap/elrondswap-auction.event.ts new file mode 100644 index 000000000..ece09a2a7 --- /dev/null +++ b/src/modules/rabbitmq/entities/auction-reindex/elrondnftswap/elrondswap-auction.event.ts @@ -0,0 +1,15 @@ +import { GenericEvent } from '../../generic.event'; +import { ElrondSwapAuctionTopics } from './elrondswap-auction.event.topics'; + +export class ElrondSwapAuctionEvent extends GenericEvent { + private decodedTopics: ElrondSwapAuctionTopics; + + constructor(init?: Partial) { + super(init); + this.decodedTopics = new ElrondSwapAuctionTopics(this.topics); + } + + getTopics() { + return this.decodedTopics.toPlainObject(); + } +} diff --git a/src/modules/rabbitmq/entities/auction-reindex/elrondnftswap/elrondswap-bid.event.topics.ts b/src/modules/rabbitmq/entities/auction-reindex/elrondnftswap/elrondswap-bid.event.topics.ts new file mode 100644 index 000000000..724fb3abe --- /dev/null +++ b/src/modules/rabbitmq/entities/auction-reindex/elrondnftswap/elrondswap-bid.event.topics.ts @@ -0,0 +1,30 @@ +import { Address } from '@multiversx/sdk-core'; + +export class ElrondSwapBidEventsTopics { + private auctionId: string; + private collection: string; + private nonce: string; + private nrAuctionTokens: string; + private currentWinner: Address; + private currentBid: string; + + constructor(rawTopics: string[]) { + this.auctionId = Buffer.from(rawTopics[1], 'base64').toString('hex'); + this.collection = Buffer.from(rawTopics[2], 'base64').toString(); + this.nonce = Buffer.from(rawTopics[3], 'base64').toString('hex'); + this.nrAuctionTokens = parseInt(Buffer.from(rawTopics[4], 'base64').toString('hex'), 16).toString(); + this.currentWinner = new Address(Buffer.from(rawTopics[9], 'base64')); + this.currentBid = Buffer.from(rawTopics[10], 'base64').toString('hex').hexBigNumberToString(); + } + + toPlainObject() { + return { + currentWinner: this.currentWinner.bech32(), + collection: this.collection, + nonce: this.nonce, + auctionId: this.auctionId, + nrAuctionTokens: this.nrAuctionTokens, + currentBid: this.currentBid, + }; + } +} diff --git a/src/modules/rabbitmq/entities/auction-reindex/elrondnftswap/elrondswap-bid.event.ts b/src/modules/rabbitmq/entities/auction-reindex/elrondnftswap/elrondswap-bid.event.ts new file mode 100644 index 000000000..d0c765614 --- /dev/null +++ b/src/modules/rabbitmq/entities/auction-reindex/elrondnftswap/elrondswap-bid.event.ts @@ -0,0 +1,15 @@ +import { GenericEvent } from '../../generic.event'; +import { ElrondSwapBidEventsTopics } from './elrondswap-bid.event.topics'; + +export class ElrondSwapBidEvent extends GenericEvent { + private decodedTopics: ElrondSwapBidEventsTopics; + + constructor(init?: Partial) { + super(init); + this.decodedTopics = new ElrondSwapBidEventsTopics(this.topics); + } + + getTopics() { + return this.decodedTopics.toPlainObject(); + } +} diff --git a/src/modules/rabbitmq/entities/auction-reindex/elrondnftswap/elrondswap-buy.event.topics.ts b/src/modules/rabbitmq/entities/auction-reindex/elrondnftswap/elrondswap-buy.event.topics.ts new file mode 100644 index 000000000..f83a8f7cb --- /dev/null +++ b/src/modules/rabbitmq/entities/auction-reindex/elrondnftswap/elrondswap-buy.event.topics.ts @@ -0,0 +1,32 @@ +import { Address } from '@multiversx/sdk-core'; + +export class ElrondSwapBuyTopics { + private auctionId: string; + private collection: string; + private nonce: string; + private boughtTokens: string; + private currentWinner: Address; + private bid: string; + private paymentToken: string; + + constructor(rawTopics: string[]) { + this.auctionId = Buffer.from(rawTopics[1], 'base64').toString('hex'); + this.collection = Buffer.from(rawTopics[2], 'base64').toString(); + this.nonce = Buffer.from(rawTopics[3], 'base64').toString('hex'); + this.boughtTokens = parseInt(Buffer.from(rawTopics[4], 'base64').toString('hex'), 16).toString(); + this.bid = Buffer.from(rawTopics[6], 'base64').toString('hex').hexBigNumberToString(); + this.currentWinner = new Address(Buffer.from(rawTopics[9], 'base64')); + } + + toPlainObject() { + return { + currentWinner: this.currentWinner.bech32(), + collection: this.collection, + nonce: this.nonce, + auctionId: this.auctionId, + boughtTokens: this.boughtTokens, + bid: this.bid, + paymentToken: this.paymentToken, + }; + } +} diff --git a/src/modules/rabbitmq/entities/auction-reindex/elrondnftswap/elrondswap-buy.event.ts b/src/modules/rabbitmq/entities/auction-reindex/elrondnftswap/elrondswap-buy.event.ts new file mode 100644 index 000000000..ccb002bc5 --- /dev/null +++ b/src/modules/rabbitmq/entities/auction-reindex/elrondnftswap/elrondswap-buy.event.ts @@ -0,0 +1,15 @@ +import { GenericEvent } from '../../generic.event'; +import { ElrondSwapBuyTopics } from './elrondswap-buy.event.topics'; + +export class ElrondSwapBuyEvent extends GenericEvent { + private decodedTopics: ElrondSwapBuyTopics; + + constructor(init?: Partial) { + super(init); + this.decodedTopics = new ElrondSwapBuyTopics(this.topics); + } + + getTopics() { + return this.decodedTopics.toPlainObject(); + } +} diff --git a/src/modules/rabbitmq/entities/auction-reindex/elrondnftswap/elrondswap-updateAuction.event.topics.ts b/src/modules/rabbitmq/entities/auction-reindex/elrondnftswap/elrondswap-updateAuction.event.topics.ts new file mode 100644 index 000000000..88271df2a --- /dev/null +++ b/src/modules/rabbitmq/entities/auction-reindex/elrondnftswap/elrondswap-updateAuction.event.topics.ts @@ -0,0 +1,50 @@ +import { Address, BinaryCodec, FieldDefinition, StructType, TokenIdentifierType, U64Type } from '@multiversx/sdk-core/out'; +export class ElrondSwapUpdateTopics { + private auctionId: string; + private collection: string; + private nonce: string; + private nrAuctionTokens: number; + private seller: Address; + private price: string; + private deadline: number; + private paymentToken: string; + private paymentTokenNonce: string; + + constructor(rawTopics: string[]) { + this.auctionId = Buffer.from(rawTopics[1], 'base64').toString('hex'); + this.collection = Buffer.from(rawTopics[2], 'base64').toString(); + this.nonce = Buffer.from(rawTopics[3], 'base64').toString('hex'); + this.nrAuctionTokens = parseInt(Buffer.from(rawTopics[4], 'base64').toString('hex'), 16); + this.seller = new Address(Buffer.from(rawTopics[5], 'base64')); + this.price = Buffer.from(rawTopics[6], 'base64').toString('hex').hexBigNumberToString(); + this.deadline = parseInt(Buffer.from(rawTopics[9], 'base64').toString('hex'), 16); + let token = decodeToken(Buffer.from(rawTopics[7], 'base64')); + this.paymentToken = token.token_type; + this.paymentTokenNonce = token.nonce; + } + + toPlainObject() { + return { + seller: this.seller.bech32(), + collection: this.collection, + nonce: this.nonce, + auctionId: this.auctionId, + nrAuctionTokens: this.nrAuctionTokens, + price: this.price, + deadline: this.deadline, + paymentToken: this.paymentToken, + paymentTokenNonce: this.paymentTokenNonce, + }; + } +} + +function decodeToken(bufer: Buffer): any { + const codec = new BinaryCodec(); + const type = new StructType('EsdtToken', [ + new FieldDefinition('token_type', '', new TokenIdentifierType()), + new FieldDefinition('nonce', '', new U64Type()), + ]); + + const [decoded] = codec.decodeNested(bufer, type); + return decoded.valueOf(); +} diff --git a/src/modules/rabbitmq/entities/auction-reindex/elrondnftswap/elrondswap-updateAuction.event.ts b/src/modules/rabbitmq/entities/auction-reindex/elrondnftswap/elrondswap-updateAuction.event.ts new file mode 100644 index 000000000..830909699 --- /dev/null +++ b/src/modules/rabbitmq/entities/auction-reindex/elrondnftswap/elrondswap-updateAuction.event.ts @@ -0,0 +1,15 @@ +import { GenericEvent } from '../../generic.event'; +import { ElrondSwapUpdateTopics } from './elrondswap-updateAuction.event.topics'; + +export class ElrondSwapUpdateEvent extends GenericEvent { + private decodedTopics: ElrondSwapUpdateTopics; + + constructor(init?: Partial) { + super(init); + this.decodedTopics = new ElrondSwapUpdateTopics(this.topics); + } + + getTopics() { + return this.decodedTopics.toPlainObject(); + } +} diff --git a/src/modules/rabbitmq/entities/auction-reindex/elrondnftswap/elrondswap-withdraw.event.topics.ts b/src/modules/rabbitmq/entities/auction-reindex/elrondnftswap/elrondswap-withdraw.event.topics.ts new file mode 100644 index 000000000..44bac6dff --- /dev/null +++ b/src/modules/rabbitmq/entities/auction-reindex/elrondnftswap/elrondswap-withdraw.event.topics.ts @@ -0,0 +1,19 @@ +export class ElrondSwapWithdrawTopics { + private auctionId: string; + private collection: string; + private nonce: string; + + constructor(rawTopics: string[]) { + this.auctionId = Buffer.from(rawTopics[1], 'base64').toString('hex'); + this.collection = Buffer.from(rawTopics[2], 'base64').toString(); + this.nonce = Buffer.from(rawTopics[3], 'base64').toString('hex'); + } + + toPlainObject() { + return { + collection: this.collection, + nonce: this.nonce, + auctionId: this.auctionId, + }; + } +} diff --git a/src/modules/rabbitmq/entities/auction-reindex/elrondnftswap/elrondswap-withdraw.event.ts b/src/modules/rabbitmq/entities/auction-reindex/elrondnftswap/elrondswap-withdraw.event.ts new file mode 100644 index 000000000..70d953851 --- /dev/null +++ b/src/modules/rabbitmq/entities/auction-reindex/elrondnftswap/elrondswap-withdraw.event.ts @@ -0,0 +1,15 @@ +import { GenericEvent } from '../../generic.event'; +import { ElrondSwapWithdrawTopics } from './elrondswap-withdraw.event.topics'; + +export class ElrondSwapWithdrawEvent extends GenericEvent { + private decodedTopics: ElrondSwapWithdrawTopics; + + constructor(init?: Partial) { + super(init); + this.decodedTopics = new ElrondSwapWithdrawTopics(this.topics); + } + + getTopics() { + return this.decodedTopics.toPlainObject(); + } +} diff --git a/src/modules/rabbitmq/entities/auction-reindex/endAuction.event.topics.ts b/src/modules/rabbitmq/entities/auction-reindex/endAuction.event.topics.ts new file mode 100644 index 000000000..d2b556fb6 --- /dev/null +++ b/src/modules/rabbitmq/entities/auction-reindex/endAuction.event.topics.ts @@ -0,0 +1,31 @@ +import { Address } from '@multiversx/sdk-core'; +import '../../../../utils/extensions'; + +export class EndAuctionEventsTopics { + private collection: string; + private nonce: string; + private auctionId: string; + private nrAuctionTokens: string; + private currentWinner: Address; + private currentBid: string; + + constructor(rawTopics: string[]) { + this.collection = Buffer.from(rawTopics[1], 'hex').toString(); + this.nonce = rawTopics[2]; + this.auctionId = rawTopics[3]; + this.nrAuctionTokens = parseInt(rawTopics[4], 16).toString(); + this.currentWinner = new Address(Buffer.from(rawTopics[5], 'hex')); + this.currentBid = rawTopics[6].hexBigNumberToString(); + } + + toPlainObject() { + return { + currentWinner: this.currentWinner.bech32(), + collection: this.collection, + nonce: this.nonce, + auctionId: this.auctionId, + nrAuctionTokens: this.nrAuctionTokens, + currentBid: this.currentBid, + }; + } +} diff --git a/src/modules/rabbitmq/entities/auction-reindex/endAuction.event.ts b/src/modules/rabbitmq/entities/auction-reindex/endAuction.event.ts new file mode 100644 index 000000000..5f0608494 --- /dev/null +++ b/src/modules/rabbitmq/entities/auction-reindex/endAuction.event.ts @@ -0,0 +1,15 @@ +import { GenericEvent } from '../generic.event'; +import { EndAuctionEventsTopics } from './endAuction.event.topics'; + +export class EndAuctionEvent extends GenericEvent { + private decodedTopics: EndAuctionEventsTopics; + + constructor(init?: Partial) { + super(init); + this.decodedTopics = new EndAuctionEventsTopics(this.topics); + } + + getTopics() { + return this.decodedTopics.toPlainObject(); + } +} diff --git a/src/modules/rabbitmq/entities/auction-reindex/externalEvents/acceptOffer.event.topics.ts b/src/modules/rabbitmq/entities/auction-reindex/externalEvents/acceptOffer.event.topics.ts new file mode 100644 index 000000000..6b4d014e3 --- /dev/null +++ b/src/modules/rabbitmq/entities/auction-reindex/externalEvents/acceptOffer.event.topics.ts @@ -0,0 +1,21 @@ +import { BinaryUtils } from '@multiversx/sdk-nestjs-common'; + +export class AcceptOfferEventsTopics { + private collection: string; + private nonce: string; + private auctionId: number; + + constructor(rawTopics: string[]) { + this.collection = Buffer.from(rawTopics[1], 'base64').toString(); + this.nonce = Buffer.from(rawTopics[2], 'base64').toString('hex'); + this.auctionId = parseInt(BinaryUtils.tryBase64ToBigInt(rawTopics[14])?.toString() ?? '0'); + } + + toPlainObject() { + return { + collection: this.collection, + nonce: this.nonce, + auctionId: this.auctionId, + }; + } +} diff --git a/src/modules/rabbitmq/entities/auction-reindex/externalEvents/acceptOffer.event.ts b/src/modules/rabbitmq/entities/auction-reindex/externalEvents/acceptOffer.event.ts new file mode 100644 index 000000000..3a7e0f553 --- /dev/null +++ b/src/modules/rabbitmq/entities/auction-reindex/externalEvents/acceptOffer.event.ts @@ -0,0 +1,15 @@ +import { GenericEvent } from '../../generic.event'; +import { AcceptOfferEventsTopics } from './acceptOffer.event.topics'; + +export class AcceptOfferEvent extends GenericEvent { + private decodedTopics: AcceptOfferEventsTopics; + + constructor(init?: Partial) { + super(init); + this.decodedTopics = new AcceptOfferEventsTopics(this.topics); + } + + getTopics() { + return this.decodedTopics.toPlainObject(); + } +} diff --git a/src/modules/rabbitmq/entities/auction-reindex/index.ts b/src/modules/rabbitmq/entities/auction-reindex/index.ts new file mode 100644 index 000000000..ff1d39ae1 --- /dev/null +++ b/src/modules/rabbitmq/entities/auction-reindex/index.ts @@ -0,0 +1,11 @@ +export * from './auction.types'; +export * from './auctionToken.event'; +export * from './auctionToken.event.topics'; +export * from './bid.event'; +export * from './bid.event.topics'; +export * from './buySft.event'; +export * from './buySft.event.topics'; +export * from './endAuction.event'; +export * from './endAuction.event.topics'; +export * from './withdraw.event'; +export * from './withdraw.event.topics'; diff --git a/src/modules/rabbitmq/entities/auction-reindex/issue-collection.event.topics.ts b/src/modules/rabbitmq/entities/auction-reindex/issue-collection.event.topics.ts new file mode 100644 index 000000000..e210e0387 --- /dev/null +++ b/src/modules/rabbitmq/entities/auction-reindex/issue-collection.event.topics.ts @@ -0,0 +1,16 @@ +import { BinaryUtils } from '@multiversx/sdk-nestjs-common'; +import '../../../../utils/extensions'; + +export class IssueCollectionTopics { + private collection: string; + + constructor(rawTopics: string[]) { + this.collection = BinaryUtils.base64Decode(rawTopics[0]); + } + + toPlainObject() { + return { + collection: this.collection, + }; + } +} diff --git a/src/modules/rabbitmq/entities/auction-reindex/issue-collection.event.ts b/src/modules/rabbitmq/entities/auction-reindex/issue-collection.event.ts new file mode 100644 index 000000000..211b3c2b3 --- /dev/null +++ b/src/modules/rabbitmq/entities/auction-reindex/issue-collection.event.ts @@ -0,0 +1,15 @@ +import { GenericEvent } from '../generic.event'; +import { TransferEventsTopics } from './transfer.event.topics'; + +export class IssueCollectionEvent extends GenericEvent { + private decodedTopics: TransferEventsTopics; + + constructor(init?: Partial) { + super(init); + this.decodedTopics = new TransferEventsTopics(this.topics); + } + + getTopics() { + return this.decodedTopics.toPlainObject(); + } +} diff --git a/src/modules/rabbitmq/entities/auction-reindex/listNft.event.topics.ts b/src/modules/rabbitmq/entities/auction-reindex/listNft.event.topics.ts new file mode 100644 index 000000000..2e1fdf4dc --- /dev/null +++ b/src/modules/rabbitmq/entities/auction-reindex/listNft.event.topics.ts @@ -0,0 +1,37 @@ +import { Address } from '@multiversx/sdk-core'; +import { mxConfig } from 'src/config'; + +export class ListNftEventsTopics { + private collection: string; + private nonce: string; + private auctionId: string = '0'; + private nrAuctionTokens: string = '1'; + private originalOwner: Address; + private price: string; + private paymentToken: string = mxConfig.egld; + private paymentTokenNonce: string = '0'; + private auctionType: string = ''; + private deadline: number = 0; + + constructor(rawTopics: string[]) { + this.originalOwner = new Address(Buffer.from(rawTopics[1], 'hex')); + this.collection = Buffer.from(rawTopics[2], 'hex').toString(); + this.nonce = rawTopics[3]; + this.price = rawTopics[4].hexBigNumberToString(); + } + + toPlainObject() { + return { + originalOwner: this.originalOwner.bech32(), + collection: this.collection, + nonce: this.nonce, + auctionId: this.auctionId, + nrAuctionTokens: this.nrAuctionTokens, + price: this.price, + paymentToken: this.paymentToken, + paymentTokenNonce: this.paymentTokenNonce, + auctionType: this.auctionType, + deadline: this.deadline, + }; + } +} diff --git a/src/modules/rabbitmq/entities/auction-reindex/listNft.event.ts b/src/modules/rabbitmq/entities/auction-reindex/listNft.event.ts new file mode 100644 index 000000000..b0eb3dfb2 --- /dev/null +++ b/src/modules/rabbitmq/entities/auction-reindex/listNft.event.ts @@ -0,0 +1,15 @@ +import { GenericEvent } from '../generic.event'; +import { ListNftEventsTopics } from './listNft.event.topics'; + +export class ListNftEvent extends GenericEvent { + private decodedTopics: ListNftEventsTopics; + + constructor(init?: Partial) { + super(init); + this.decodedTopics = new ListNftEventsTopics(this.topics); + } + + getTopics() { + return this.decodedTopics.toPlainObject(); + } +} diff --git a/src/modules/rabbitmq/entities/auction-reindex/mint.event.topics.ts b/src/modules/rabbitmq/entities/auction-reindex/mint.event.topics.ts new file mode 100644 index 000000000..4f9d0730c --- /dev/null +++ b/src/modules/rabbitmq/entities/auction-reindex/mint.event.topics.ts @@ -0,0 +1,19 @@ +import { BinaryUtils } from '@multiversx/sdk-nestjs-common'; +import '../../../../utils/extensions'; + +export class MintEventsTopics { + private collection: string; + private nonce: string; + + constructor(rawTopics: string[]) { + this.collection = BinaryUtils.base64Decode(rawTopics[0]); + this.nonce = BinaryUtils.base64ToHex(rawTopics[1]); + } + + toPlainObject() { + return { + collection: this.collection, + nonce: this.nonce, + }; + } +} diff --git a/src/modules/rabbitmq/entities/auction-reindex/mint.event.ts b/src/modules/rabbitmq/entities/auction-reindex/mint.event.ts new file mode 100644 index 000000000..3584a08fa --- /dev/null +++ b/src/modules/rabbitmq/entities/auction-reindex/mint.event.ts @@ -0,0 +1,15 @@ +import { GenericEvent } from '../generic.event'; +import { MintEventsTopics } from './mint.event.topics'; + +export class MintEvent extends GenericEvent { + private decodedTopics: MintEventsTopics; + + constructor(init?: Partial) { + super(init); + this.decodedTopics = new MintEventsTopics(this.topics); + } + + getTopics() { + return this.decodedTopics.toPlainObject(); + } +} diff --git a/src/modules/rabbitmq/entities/auction-reindex/randomNft.event.topics.ts b/src/modules/rabbitmq/entities/auction-reindex/randomNft.event.topics.ts new file mode 100644 index 000000000..f1810b954 --- /dev/null +++ b/src/modules/rabbitmq/entities/auction-reindex/randomNft.event.topics.ts @@ -0,0 +1,21 @@ +import '../../../../utils/extensions'; + +export class RandomNftEventsTopics { + private campaignId: string; + private tier: string; + private boughtNfts: string; + + constructor(rawTopics: string[]) { + this.campaignId = Buffer.from(rawTopics[2], 'base64').toString(); + this.tier = Buffer.from(rawTopics[3], 'base64').toString(); + this.boughtNfts = rawTopics.length >= 5 ? Buffer.from(rawTopics[4], 'base64').toString('hex').hexBigNumberToString() : '1'; + } + + toPlainObject() { + return { + campaignId: this.campaignId, + tier: this.tier, + boughtNfts: this.boughtNfts, + }; + } +} diff --git a/src/modules/rabbitmq/entities/auction-reindex/randomNft.event.ts b/src/modules/rabbitmq/entities/auction-reindex/randomNft.event.ts new file mode 100644 index 000000000..ac2fd9f84 --- /dev/null +++ b/src/modules/rabbitmq/entities/auction-reindex/randomNft.event.ts @@ -0,0 +1,19 @@ +import { GenericEvent } from '../generic.event'; +import { RandomNftEventsTopics } from './randomNft.event.topics'; + +export class RandomNftEvent extends GenericEvent { + private decodedTopics: RandomNftEventsTopics; + + constructor(init?: Partial) { + super(init); + this.decodedTopics = new RandomNftEventsTopics(this.topics); + } + + getTopics() { + return this.decodedTopics.toPlainObject(); + } + + getData() { + return this.data !== '' ? parseInt(Buffer.from(this.data, 'base64').toString('hex'), 16).toString() : '1'; + } +} diff --git a/src/modules/rabbitmq/entities/auction-reindex/sendOffer.event.topics.ts b/src/modules/rabbitmq/entities/auction-reindex/sendOffer.event.topics.ts new file mode 100644 index 000000000..9d65d9e85 --- /dev/null +++ b/src/modules/rabbitmq/entities/auction-reindex/sendOffer.event.topics.ts @@ -0,0 +1,43 @@ +import { Address } from '@multiversx/sdk-core'; +import { BinaryUtils } from '@multiversx/sdk-nestjs-common'; + +export class SendOfferEventsTopics { + private offerId: number; + private collection: string; + private nonce: string; + private nrOfferTokens: number; + private offerOwner: Address; + private paymentTokenIdentifier: string; + private paymentTokenNonce: number; + private paymentAmount: string; + private startdate: string; + private enddate: string; + + constructor(rawTopics: string[]) { + this.offerId = parseInt(rawTopics[1], 16); + this.collection = Buffer.from(rawTopics[2], 'hex').toString(); + this.nonce = rawTopics[3]; + this.nrOfferTokens = parseInt(BinaryUtils.hexToBigInt(rawTopics[4])?.toString() ?? '1'); + this.paymentTokenIdentifier = Buffer.from(rawTopics[5], 'hex').toString(); + this.paymentTokenNonce = parseInt(BinaryUtils.hexToBigInt(rawTopics[6])?.toString() ?? '0'); + this.paymentAmount = rawTopics[7].hexBigNumberToString(); + this.offerOwner = new Address(Buffer.from(rawTopics[8], 'hex')); + this.startdate = parseInt(rawTopics[9], 16).toString(); + this.enddate = parseInt(rawTopics[10], 16).toString(); + } + + toPlainObject() { + return { + offerOwner: this.offerOwner.bech32(), + collection: this.collection, + nonce: this.nonce, + offerId: this.offerId, + nrOfferTokens: this.nrOfferTokens, + paymentTokenIdentifier: this.paymentTokenIdentifier, + paymentTokenNonce: this.paymentTokenNonce, + paymentAmount: this.paymentAmount, + startdate: this.startdate, + enddate: this.enddate, + }; + } +} diff --git a/src/modules/rabbitmq/entities/auction-reindex/sendOffer.event.ts b/src/modules/rabbitmq/entities/auction-reindex/sendOffer.event.ts new file mode 100644 index 000000000..942032284 --- /dev/null +++ b/src/modules/rabbitmq/entities/auction-reindex/sendOffer.event.ts @@ -0,0 +1,15 @@ +import { GenericEvent } from '../generic.event'; +import { SendOfferEventsTopics } from './sendOffer.event.topics'; + +export class SendOfferEvent extends GenericEvent { + private decodedTopics: SendOfferEventsTopics; + + constructor(init?: Partial) { + super(init); + this.decodedTopics = new SendOfferEventsTopics(this.topics); + } + + getTopics() { + return this.decodedTopics.toPlainObject(); + } +} diff --git a/src/modules/rabbitmq/entities/auction-reindex/transfer.event.topics.ts b/src/modules/rabbitmq/entities/auction-reindex/transfer.event.topics.ts new file mode 100644 index 000000000..032dc2214 --- /dev/null +++ b/src/modules/rabbitmq/entities/auction-reindex/transfer.event.topics.ts @@ -0,0 +1,49 @@ +import { BinaryUtils } from '@multiversx/sdk-nestjs-common'; +import { Address } from '@multiversx/sdk-core'; +import '../../../../utils/extensions'; + +export class TransferEventsTopics { + private collection: string; + private nonce: string; + private receiverAddress: Address; + + constructor(rawTopics: string[]) { + this.collection = BinaryUtils.base64Decode(rawTopics[0]); + this.nonce = BinaryUtils.base64ToHex(rawTopics[1]); + this.receiverAddress = new Address(Buffer.from(rawTopics[3], 'base64')); + } + + toPlainObject() { + return { + collection: this.collection, + nonce: this.nonce, + receiverAddress: this.receiverAddress, + }; + } +} + +export class MultiTransferEventsTopics { + private receiverAddress: Address; + private pairs: any[] = []; + + constructor(rawTopics: string[]) { + for (let index = 0; index < rawTopics.length - 1; index += 3) { + this.pairs.push({ + collection: BinaryUtils.base64Decode(rawTopics[index]), + nonce: BinaryUtils.base64ToHex(rawTopics[index + 1]), + value: Buffer.from(rawTopics[index + 2], 'base64') + .toString('hex') + .hexBigNumberToString(), + }); + } + + this.receiverAddress = new Address(Buffer.from(rawTopics[rawTopics.length - 1], 'base64')); + } + + toPlainObject() { + return { + pairs: this.pairs, + receiverAddress: this.receiverAddress, + }; + } +} diff --git a/src/modules/rabbitmq/entities/auction-reindex/transfer.event.ts b/src/modules/rabbitmq/entities/auction-reindex/transfer.event.ts new file mode 100644 index 000000000..18f26db6b --- /dev/null +++ b/src/modules/rabbitmq/entities/auction-reindex/transfer.event.ts @@ -0,0 +1,28 @@ +import { GenericEvent } from '../generic.event'; +import { MultiTransferEventsTopics as MultiTransferEventTopics, TransferEventsTopics } from './transfer.event.topics'; + +export class TransferEvent extends GenericEvent { + private decodedTopics: TransferEventsTopics; + + constructor(init?: Partial) { + super(init); + this.decodedTopics = new TransferEventsTopics(this.topics); + } + + getTopics() { + return this.decodedTopics.toPlainObject(); + } +} + +export class MultiTransferEvent extends GenericEvent { + private decodedTopics: MultiTransferEventTopics; + + constructor(init?: Partial) { + super(init); + this.decodedTopics = new MultiTransferEventTopics(this.topics); + } + + getTopics() { + return this.decodedTopics.toPlainObject(); + } +} diff --git a/src/modules/rabbitmq/entities/auction-reindex/update-attributes.event.topics.ts b/src/modules/rabbitmq/entities/auction-reindex/update-attributes.event.topics.ts new file mode 100644 index 000000000..e3ea41170 --- /dev/null +++ b/src/modules/rabbitmq/entities/auction-reindex/update-attributes.event.topics.ts @@ -0,0 +1,19 @@ +import { BinaryUtils } from '@multiversx/sdk-nestjs-common'; +import '../../../../utils/extensions'; + +export class UpdateAttributesEventsTopics { + private collection: string; + private nonce: string; + + constructor(rawTopics: string[]) { + this.collection = BinaryUtils.base64Decode(rawTopics[0]); + this.nonce = BinaryUtils.base64ToHex(rawTopics[1]); + } + + toPlainObject() { + return { + collection: this.collection, + nonce: this.nonce, + }; + } +} diff --git a/src/modules/rabbitmq/entities/auction-reindex/update-attributes.event.ts b/src/modules/rabbitmq/entities/auction-reindex/update-attributes.event.ts new file mode 100644 index 000000000..327a45599 --- /dev/null +++ b/src/modules/rabbitmq/entities/auction-reindex/update-attributes.event.ts @@ -0,0 +1,15 @@ +import { GenericEvent } from '../generic.event'; +import { UpdateAttributesEventsTopics } from './update-attributes.event.topics'; + +export class UpdateAttributesEvent extends GenericEvent { + private decodedTopics: UpdateAttributesEventsTopics; + + constructor(init?: Partial) { + super(init); + this.decodedTopics = new UpdateAttributesEventsTopics(this.topics); + } + + getTopics() { + return this.decodedTopics.toPlainObject(); + } +} diff --git a/src/modules/rabbitmq/entities/auction-reindex/updateListing.event.topics.ts b/src/modules/rabbitmq/entities/auction-reindex/updateListing.event.topics.ts new file mode 100644 index 000000000..72b524d2d --- /dev/null +++ b/src/modules/rabbitmq/entities/auction-reindex/updateListing.event.topics.ts @@ -0,0 +1,40 @@ +import { Address } from '@multiversx/sdk-core'; +import { BinaryUtils } from '@multiversx/sdk-nestjs-common'; + +export class UpdateListingEventsTopics { + private collection: string; + private nonce: string; + private auctionId: string; + private ownerAddress: Address; + private oldPrice: string; + private newBid: string; + private paymentToken: string; + private paymentTokenNonce: string; + private deadline: number = 0; + + constructor(rawTopics: string[]) { + this.collection = Buffer.from(rawTopics[1], 'base64').toString(); + this.nonce = rawTopics[2]; + this.auctionId = rawTopics[3]; + this.ownerAddress = new Address(Buffer.from(rawTopics[4], 'hex')); + this.oldPrice = rawTopics[5].hexBigNumberToString(); + this.newBid = rawTopics[6].hexBigNumberToString(); + this.paymentToken = BinaryUtils.base64Decode(rawTopics[7]); + this.paymentTokenNonce = BinaryUtils.hexToBigInt(rawTopics[8])?.toString() ?? '0'; + this.deadline = parseInt(rawTopics[9] ?? '0', 16); + } + + toPlainObject() { + return { + collection: this.collection, + nonce: this.nonce, + auctionId: this.auctionId, + ownerAddress: this.ownerAddress, + oldPrice: this.oldPrice, + newBid: this.newBid, + paymentToken: this.paymentToken, + paymentTokenNonce: this.paymentTokenNonce, + deadline: this.deadline, + }; + } +} diff --git a/src/modules/rabbitmq/entities/auction-reindex/updateListing.event.ts b/src/modules/rabbitmq/entities/auction-reindex/updateListing.event.ts new file mode 100644 index 000000000..d4ef778be --- /dev/null +++ b/src/modules/rabbitmq/entities/auction-reindex/updateListing.event.ts @@ -0,0 +1,15 @@ +import { GenericEvent } from '../generic.event'; +import { UpdateListingEventsTopics } from './updateListing.event.topics'; + +export class UpdateListingEvent extends GenericEvent { + private decodedTopics: UpdateListingEventsTopics; + + constructor(init?: Partial) { + super(init); + this.decodedTopics = new UpdateListingEventsTopics(this.topics); + } + + getTopics() { + return this.decodedTopics.toPlainObject(); + } +} diff --git a/src/modules/rabbitmq/entities/auction-reindex/updatePrice.event.topics.ts b/src/modules/rabbitmq/entities/auction-reindex/updatePrice.event.topics.ts new file mode 100644 index 000000000..1cce9c8c3 --- /dev/null +++ b/src/modules/rabbitmq/entities/auction-reindex/updatePrice.event.topics.ts @@ -0,0 +1,22 @@ +export class UpdatePriceEventsTopics { + private collection: string; + private nonce: string; + private auctionId: string; + private newBid: string; + + constructor(rawTopics: string[]) { + this.collection = Buffer.from(rawTopics[1], 'hex').toString(); + this.nonce = rawTopics[2]; + this.auctionId = rawTopics[3]; + this.newBid = rawTopics[6].hexBigNumberToString(); + } + + toPlainObject() { + return { + collection: this.collection, + nonce: this.nonce, + auctionId: this.auctionId, + newBid: this.newBid, + }; + } +} diff --git a/src/modules/rabbitmq/entities/auction-reindex/updatePrice.event.ts b/src/modules/rabbitmq/entities/auction-reindex/updatePrice.event.ts new file mode 100644 index 000000000..1538b5535 --- /dev/null +++ b/src/modules/rabbitmq/entities/auction-reindex/updatePrice.event.ts @@ -0,0 +1,15 @@ +import { GenericEvent } from '../generic.event'; +import { UpdatePriceEventsTopics } from './updatePrice.event.topics'; + +export class UpdatePriceEvent extends GenericEvent { + private decodedTopics: UpdatePriceEventsTopics; + + constructor(init?: Partial) { + super(init); + this.decodedTopics = new UpdatePriceEventsTopics(this.topics); + } + + getTopics() { + return this.decodedTopics.toPlainObject(); + } +} diff --git a/src/modules/rabbitmq/entities/auction-reindex/updatePriceDeadrare.event.topics.ts b/src/modules/rabbitmq/entities/auction-reindex/updatePriceDeadrare.event.topics.ts new file mode 100644 index 000000000..8229a11db --- /dev/null +++ b/src/modules/rabbitmq/entities/auction-reindex/updatePriceDeadrare.event.topics.ts @@ -0,0 +1,31 @@ +export class UpdatePriceDeadrareEventsTopics { + private collection: string; + private nonce: string; + private auctionId: string; + private minBid: string; + private maxBid: string; + private paymentToken: string; + private itemsCount: number; + + constructor(rawTopics: string[]) { + this.collection = Buffer.from(rawTopics[1], 'hex').toString(); + this.nonce = rawTopics[2]; + this.auctionId = rawTopics[3]; + this.itemsCount = parseInt(rawTopics[4], 16); + this.minBid = rawTopics[6].hexBigNumberToString(); + this.maxBid = rawTopics[7].hexBigNumberToString(); + this.paymentToken = Buffer.from(rawTopics[8], 'hex').toString(); + } + + toPlainObject() { + return { + collection: this.collection, + nonce: this.nonce, + auctionId: this.auctionId, + itemsCount: this.itemsCount, + minBid: this.minBid, + maxBid: this.maxBid, + paymentToken: this.paymentToken, + }; + } +} diff --git a/src/modules/rabbitmq/entities/auction-reindex/updatePriceDeadrare.event.ts b/src/modules/rabbitmq/entities/auction-reindex/updatePriceDeadrare.event.ts new file mode 100644 index 000000000..39a791d48 --- /dev/null +++ b/src/modules/rabbitmq/entities/auction-reindex/updatePriceDeadrare.event.ts @@ -0,0 +1,15 @@ +import { GenericEvent } from '../generic.event'; +import { UpdatePriceDeadrareEventsTopics } from './updatePriceDeadrare.event.topics'; + +export class UpdatePriceDeadrareEvent extends GenericEvent { + private decodedTopics: UpdatePriceDeadrareEventsTopics; + + constructor(init?: Partial) { + super(init); + this.decodedTopics = new UpdatePriceDeadrareEventsTopics(this.topics); + } + + getTopics() { + return this.decodedTopics.toPlainObject(); + } +} diff --git a/src/modules/rabbitmq/entities/auction-reindex/withdraw.event.topics.ts b/src/modules/rabbitmq/entities/auction-reindex/withdraw.event.topics.ts new file mode 100644 index 000000000..66eb12033 --- /dev/null +++ b/src/modules/rabbitmq/entities/auction-reindex/withdraw.event.topics.ts @@ -0,0 +1,27 @@ +import { Address } from '@multiversx/sdk-core'; + +export class WithdrawEventsTopics { + private collection: string; + private nonce: string; + private auctionId: string; + private nrAuctionTokens: string; + private originalOwner: Address; + + constructor(rawTopics: string[]) { + this.collection = Buffer.from(rawTopics[1], 'base64').toString(); + this.nonce = rawTopics[2]; + this.auctionId = rawTopics[3]; + this.nrAuctionTokens = parseInt(rawTopics[4], 16).toString(); + this.originalOwner = new Address(Buffer.from(rawTopics[5], 'hex')); + } + + toPlainObject() { + return { + originalOwner: this.originalOwner.bech32(), + collection: this.collection, + nonce: this.nonce, + auctionId: this.auctionId, + nrAuctionTokens: this.nrAuctionTokens, + }; + } +} diff --git a/src/modules/rabbitmq/entities/auction-reindex/withdraw.event.ts b/src/modules/rabbitmq/entities/auction-reindex/withdraw.event.ts new file mode 100644 index 000000000..c41f3f5b7 --- /dev/null +++ b/src/modules/rabbitmq/entities/auction-reindex/withdraw.event.ts @@ -0,0 +1,15 @@ +import { GenericEvent } from '../generic.event'; +import { WithdrawEventsTopics } from './withdraw.event.topics'; + +export class WithdrawEvent extends GenericEvent { + private decodedTopics: WithdrawEventsTopics; + + constructor(init?: Partial) { + super(init); + this.decodedTopics = new WithdrawEventsTopics(this.topics); + } + + getTopics() { + return this.decodedTopics.toPlainObject(); + } +} diff --git a/src/modules/rabbitmq/entities/auction-reindex/withdrawOffer.event.topics.ts b/src/modules/rabbitmq/entities/auction-reindex/withdrawOffer.event.topics.ts new file mode 100644 index 000000000..c24f22128 --- /dev/null +++ b/src/modules/rabbitmq/entities/auction-reindex/withdrawOffer.event.topics.ts @@ -0,0 +1,19 @@ +export class WithdrawOfferEventsTopics { + private offerId: number; + private collection: string; + private nonce: string; + + constructor(rawTopics: string[]) { + this.offerId = parseInt(rawTopics[1], 16); + this.collection = Buffer.from(rawTopics[2], 'hex').toString(); + this.nonce = rawTopics[3]; + } + + toPlainObject() { + return { + collection: this.collection, + nonce: this.nonce, + offerId: this.offerId, + }; + } +} diff --git a/src/modules/rabbitmq/entities/auction-reindex/withdrawOffer.event.ts b/src/modules/rabbitmq/entities/auction-reindex/withdrawOffer.event.ts new file mode 100644 index 000000000..39570c200 --- /dev/null +++ b/src/modules/rabbitmq/entities/auction-reindex/withdrawOffer.event.ts @@ -0,0 +1,15 @@ +import { GenericEvent } from '../generic.event'; +import { WithdrawOfferEventsTopics } from './withdrawOffer.event.topics'; + +export class WithdrawOfferEvent extends GenericEvent { + private decodedTopics: WithdrawOfferEventsTopics; + + constructor(init?: Partial) { + super(init); + this.decodedTopics = new WithdrawOfferEventsTopics(this.topics); + } + + getTopics() { + return this.decodedTopics.toPlainObject(); + } +} diff --git a/src/private.app.module.ts b/src/private.app.module.ts index 79e6051a3..2cc18f222 100644 --- a/src/private.app.module.ts +++ b/src/private.app.module.ts @@ -14,24 +14,24 @@ import { ScamModule } from './modules/scam/scam.module'; import { NftTraitsModule } from './modules/nft-traits/nft-traits.module'; import { CacheEventsPublisherModule } from './modules/rabbitmq/cache-invalidation/cache-invalidation-publisher/change-events-publisher.module'; import * as ormconfig from './ormconfig'; -import { MarketplaceEventsService } from './modules/rabbitmq/blockchain-events/marketplace-events.service'; import { FeedEventsSenderService } from './modules/rabbitmq/blockchain-events/feed-events.service'; -import { AcceptGlobalOfferEventHandler } from './modules/rabbitmq/blockchain-events/handlers/acceptGlobalOffer-event.handler'; -import { AcceptOfferEventHandler } from './modules/rabbitmq/blockchain-events/handlers/acceptOffer-event.handler'; -import { BidEventHandler } from './modules/rabbitmq/blockchain-events/handlers/bid-event.handler'; -import { BuyEventHandler } from './modules/rabbitmq/blockchain-events/handlers/buy-event.handler'; -import { EndAuctionEventHandler } from './modules/rabbitmq/blockchain-events/handlers/endAuction-event.handler'; -import { SendOfferEventHandler } from './modules/rabbitmq/blockchain-events/handlers/sendOffer-event.handler'; -import { StartAuctionEventHandler } from './modules/rabbitmq/blockchain-events/handlers/startAuction-event.handler'; -import { SwapUpdateEventHandler } from './modules/rabbitmq/blockchain-events/handlers/swapUpdate-event.handler'; -import { UpdateListingEventHandler } from './modules/rabbitmq/blockchain-events/handlers/updateListing-event.handler'; -import { UpdatePriceEventHandler } from './modules/rabbitmq/blockchain-events/handlers/updatePrice-event.handler'; -import { WithdrawAuctionEventHandler } from './modules/rabbitmq/blockchain-events/handlers/withdrawAuction-event.handler'; -import { WithdrawOfferEventHandler } from './modules/rabbitmq/blockchain-events/handlers/withdrawOffer-event.handler'; +import { AcceptGlobalOfferEventHandler } from './modules/rabbitmq/blockchain-events/handlers-reindex/acceptGlobalOffer-event.handler'; +import { AcceptOfferEventHandler } from './modules/rabbitmq/blockchain-events/handlers-reindex/acceptOffer-event.handler'; +import { BidEventHandler } from './modules/rabbitmq/blockchain-events/handlers-reindex/bid-event.handler'; +import { BuyEventHandler } from './modules/rabbitmq/blockchain-events/handlers-reindex/buy-event.handler'; +import { EndAuctionEventHandler } from './modules/rabbitmq/blockchain-events/handlers-reindex/endAuction-event.handler'; +import { SendOfferEventHandler } from './modules/rabbitmq/blockchain-events/handlers-reindex/sendOffer-event.handler'; +import { StartAuctionEventHandler } from './modules/rabbitmq/blockchain-events/handlers-reindex/startAuction-event.handler'; +import { SwapUpdateEventHandler } from './modules/rabbitmq/blockchain-events/handlers-reindex/swapUpdate-event.handler'; +import { UpdateListingEventHandler } from './modules/rabbitmq/blockchain-events/handlers-reindex/updateListing-event.handler'; +import { UpdatePriceEventHandler } from './modules/rabbitmq/blockchain-events/handlers-reindex/updatePrice-event.handler'; +import { WithdrawAuctionEventHandler } from './modules/rabbitmq/blockchain-events/handlers-reindex/withdrawAuction-event.handler'; +import { WithdrawOfferEventHandler } from './modules/rabbitmq/blockchain-events/handlers-reindex/withdrawOffer-event.handler'; import { AuctionsModuleGraph } from './modules/auctions/auctions.module'; import { NotificationsModuleGraph } from './modules/notifications/notifications.module'; import { OffersModuleGraph } from './modules/offers/offers.module'; import { OrdersModuleGraph } from './modules/orders/orders.module'; +import { MarketplaceEventsProcessingService } from './modules/rabbitmq/blockchain-events/marketplace-events-processing.service'; @Module({ imports: [ @@ -53,7 +53,7 @@ import { OrdersModuleGraph } from './modules/orders/orders.module'; Logger, NsfwUpdaterService, RarityUpdaterService, - MarketplaceEventsService, + MarketplaceEventsProcessingService, BuyEventHandler, BidEventHandler, StartAuctionEventHandler, @@ -71,4 +71,4 @@ import { OrdersModuleGraph } from './modules/orders/orders.module'; controllers: [MetricsController, ReindexController, CachingController], exports: [NsfwUpdaterService, RarityUpdaterService], }) -export class PrivateAppModule {} +export class PrivateAppModule { } From 3864858e946f97de1a087f9d762e107fe0547a40 Mon Sep 17 00:00:00 2001 From: danielailie Date: Wed, 22 May 2024 15:27:53 +0300 Subject: [PATCH 12/18] Update event logs model --- src/modules/metrics/metrics.controller.ts | 6 +-- src/modules/metrics/rabbitEvent.ts | 17 ++++++++ .../acceptGlobalOffer-event.handler.ts | 5 ++- .../acceptOffer-event.handler.ts | 9 ++-- .../handlers-reindex/bid-event.handler.ts | 9 ++-- .../handlers-reindex/buy-event.handler.ts | 15 +++---- .../endAuction-event.handler.ts | 8 ++-- .../sendOffer-event.handler.ts | 9 ++-- .../startAuction-event.handler.ts | 11 ++--- .../swapUpdate-event.handler.ts | 9 ++-- .../updateListing-event.handler.ts | 9 ++-- .../updatePrice-event.handler.ts | 9 ++-- .../withdrawAuction-event.handler.ts | 11 ++--- .../withdrawOffer-event.handler.ts | 7 ++-- .../marketplace-events-processing.service.ts | 41 ++++++++++--------- .../acceptGlobalOffer.event.ts | 6 +-- .../auction-reindex/acceptOffer.event.ts | 6 +-- .../acceptOfferDeadrare.event.ts | 6 +-- .../acceptOfferFrameit.event.ts | 6 +-- .../auction-reindex/acceptOfferXoxno.event.ts | 5 ++- .../auction-reindex/auctionToken.event.ts | 6 +-- .../entities/auction-reindex/bid.event.ts | 6 +-- .../entities/auction-reindex/buySft.event.ts | 6 +-- .../entities/auction-reindex/claim.event.ts | 6 +-- .../elrondnftswap/elrondswap-auction.event.ts | 6 +-- .../elrondnftswap/elrondswap-buy.event.ts | 5 ++- .../elrondswap-updateAuction.event.ts | 6 +-- .../elrondswap-withdraw.event.ts | 6 +-- .../auction-reindex/endAuction.event.ts | 6 +-- .../entities/auction-reindex/listNft.event.ts | 6 +-- .../auction-reindex/sendOffer.event.ts | 6 +-- .../auction-reindex/updateListing.event.ts | 6 +-- .../auction-reindex/updatePrice.event.ts | 6 +-- .../auction-reindex/withdraw.event.ts | 6 +-- .../auction-reindex/withdrawOffer.event.ts | 6 +-- 35 files changed, 161 insertions(+), 132 deletions(-) diff --git a/src/modules/metrics/metrics.controller.ts b/src/modules/metrics/metrics.controller.ts index bdfaed233..08c51458b 100644 --- a/src/modules/metrics/metrics.controller.ts +++ b/src/modules/metrics/metrics.controller.ts @@ -1,6 +1,6 @@ import { Body, Controller, Get, HttpStatus, Post } from '@nestjs/common'; import { MetricsCollector } from './metrics.collector'; -import { RabbitEvent } from './rabbitEvent'; +import { EventLog } from './rabbitEvent'; import { MarketplaceEventsProcessingService } from '../rabbitmq/blockchain-events/marketplace-events-processing.service'; @Controller() @@ -17,8 +17,8 @@ export class MetricsController { } @Post('/event') - async notify(@Body() payload: RabbitEvent): Promise { - await this.marketplaceEvents.handleNftAuctionEvents(payload?.events, payload?.hash); + async notify(@Body() payload: EventLog[]): Promise { + await this.marketplaceEvents.handleNftAuctionEvents(payload); return HttpStatus.OK; } } diff --git a/src/modules/metrics/rabbitEvent.ts b/src/modules/metrics/rabbitEvent.ts index 02c9a702c..79068e5a5 100644 --- a/src/modules/metrics/rabbitEvent.ts +++ b/src/modules/metrics/rabbitEvent.ts @@ -19,3 +19,20 @@ export class RabbitEventLog { Object.assign(this, init); } } + +export class EventLog { + eventId: string = ''; + txHash: string = ''; + shardId: number = 0; + timestamp: number = 0; + address: string = ''; + identifier: string = ''; + topics: string[] = []; + data: string = ''; + additionalData: string[] = []; + txOrder: number = 0; + eventOrder: number = 0; + constructor(init?: Partial) { + Object.assign(this, init); + } +} diff --git a/src/modules/rabbitmq/blockchain-events/handlers-reindex/acceptGlobalOffer-event.handler.ts b/src/modules/rabbitmq/blockchain-events/handlers-reindex/acceptGlobalOffer-event.handler.ts index cd80dec0c..ee52c8299 100644 --- a/src/modules/rabbitmq/blockchain-events/handlers-reindex/acceptGlobalOffer-event.handler.ts +++ b/src/modules/rabbitmq/blockchain-events/handlers-reindex/acceptGlobalOffer-event.handler.ts @@ -5,6 +5,7 @@ import { AuctionStatusEnum } from 'src/modules/auctions/models'; import { XOXNO_KEY } from 'src/utils/constants'; import { AcceptGlobalOfferEvent } from '../../entities/auction-reindex/acceptGlobalOffer.event'; import { Marketplace } from 'src/modules/marketplaces/models'; +import { EventLog } from 'src/modules/metrics/rabbitEvent'; @Injectable() export class AcceptGlobalOfferEventHandler { @@ -14,11 +15,11 @@ export class AcceptGlobalOfferEventHandler { private auctionsService: AuctionsSetterService, ) { } - async handle(event: any, hash: string, marketplace: Marketplace) { + async handle(event: EventLog, marketplace: Marketplace) { try { const acceptGlobalOfferEvent = new AcceptGlobalOfferEvent(event); const topics = acceptGlobalOfferEvent.getTopics(); - this.logger.log(`Accept Global Offer event detected for hash '${hash}' and marketplace '${marketplace?.name}'`); + this.logger.log(`Accept Global Offer event detected for marketplace '${marketplace?.name}'`); if (marketplace.key !== XOXNO_KEY || topics.auctionId <= 0) { return; } diff --git a/src/modules/rabbitmq/blockchain-events/handlers-reindex/acceptOffer-event.handler.ts b/src/modules/rabbitmq/blockchain-events/handlers-reindex/acceptOffer-event.handler.ts index bb3cb7c76..d54e8efc2 100644 --- a/src/modules/rabbitmq/blockchain-events/handlers-reindex/acceptOffer-event.handler.ts +++ b/src/modules/rabbitmq/blockchain-events/handlers-reindex/acceptOffer-event.handler.ts @@ -13,6 +13,7 @@ import { AcceptOfferXoxnoEvent } from '../../entities/auction-reindex/acceptOffe import { FeedEventsSenderService } from '../feed-events.service'; import { AcceptOfferFrameitEvent } from '../../entities/auction-reindex/acceptOfferFrameit.event'; import { Marketplace } from 'src/modules/marketplaces/models'; +import { EventLog } from 'src/modules/metrics/rabbitEvent'; @Injectable() export class AcceptOfferEventHandler { @@ -27,7 +28,7 @@ export class AcceptOfferEventHandler { private readonly notificationsService: NotificationsService, ) { } - async handle(event: any, hash: string, marketplace: Marketplace) { + async handle(event: EventLog, marketplace: Marketplace) { try { if (marketplace?.type === MarketplaceTypeEnum.External) { let acceptOfferEvent = undefined; @@ -43,7 +44,7 @@ export class AcceptOfferEventHandler { if (!acceptOfferEvent) return; this.logger.log( - `${acceptOfferEvent.getIdentifier()} event detected for hash '${hash}' and marketplace '${marketplace?.name}'`, + `${acceptOfferEvent.getIdentifier()} event detected for marketplace '${marketplace?.name}'`, ); if (topics.auctionId || topics.auctionId !== 0) { @@ -60,11 +61,11 @@ export class AcceptOfferEventHandler { const acceptOfferEvent = new AcceptOfferEvent(event); const topics = acceptOfferEvent.getTopics(); marketplace = await this.marketplaceService.getMarketplaceByType( - acceptOfferEvent.getAddress(), + acceptOfferEvent.address, marketplace.type, topics.collection, ); - this.logger.log(`Accept Offer event detected for hash '${hash}' and marketplace '${marketplace?.name}'`); + this.logger.log(`Accept Offer event detected for hash marketplace '${marketplace?.name}'`); const offer = await this.offersService.getOfferByIdAndMarketplace(topics.offerId, marketplace.key); diff --git a/src/modules/rabbitmq/blockchain-events/handlers-reindex/bid-event.handler.ts b/src/modules/rabbitmq/blockchain-events/handlers-reindex/bid-event.handler.ts index b9296a807..dd6418c7e 100644 --- a/src/modules/rabbitmq/blockchain-events/handlers-reindex/bid-event.handler.ts +++ b/src/modules/rabbitmq/blockchain-events/handlers-reindex/bid-event.handler.ts @@ -12,6 +12,7 @@ import { ELRONDNFTSWAP_KEY } from 'src/utils/constants'; import { BidEvent } from '../../entities/auction-reindex'; import { ElrondSwapBidEvent } from '../../entities/auction-reindex/elrondnftswap/elrondswap-bid.event'; import { FeedEventsSenderService } from '../feed-events.service'; +import { EventLog } from 'src/modules/metrics/rabbitEvent'; @Injectable() export class BidEventHandler { @@ -27,7 +28,7 @@ export class BidEventHandler { private readonly persistenceService: PersistenceService, ) { } - async handle(event: any, hash: string, marketplace: Marketplace) { + async handle(event: EventLog, marketplace: Marketplace) { try { let [bidEvent, topics] = [undefined, undefined]; if (marketplace.type === MarketplaceTypeEnum.External) { @@ -37,7 +38,7 @@ export class BidEventHandler { marketplace = await this.marketplaceService.getMarketplaceByType(bidEvent.getAddress(), marketplace.type, topics.collection); } if (!marketplace) return; - this.logger.log(`${bidEvent.getIdentifier()} event detected for hash '${hash}' and marketplace '${marketplace?.name}'`); + this.logger.log(`${bidEvent.getIdentifier()} event detected for marketplace '${marketplace?.name}'`); const auction = await this.auctionsGetterService.getAuctionByIdAndMarketplace(parseInt(topics.auctionId, 16), marketplace.key); if (!auction) return; @@ -53,7 +54,7 @@ export class BidEventHandler { priceToken: auction.paymentToken, priceAmount: topics.currentBid, priceNonce: auction.paymentNonce, - blockHash: hash, + blockHash: '', status: OrderStatusEnum.Active, marketplaceKey: marketplace.key, }), @@ -63,7 +64,7 @@ export class BidEventHandler { if (auction.maxBidDenominated === order.priceAmountDenominated) { this.notificationsService.updateNotificationStatus([auction?.id]); this.notificationsService.addNotifications(auction, order); - this.auctionsService.updateAuctionStatus(auction.id, AuctionStatusEnum.Ended, hash, event.identifier); + this.auctionsService.updateAuctionStatus(auction.id, AuctionStatusEnum.Ended, 'hash', event.identifier); this.persistenceService.updateOrderWithStatus(order, OrderStatusEnum.Bought); } } catch (error) { diff --git a/src/modules/rabbitmq/blockchain-events/handlers-reindex/buy-event.handler.ts b/src/modules/rabbitmq/blockchain-events/handlers-reindex/buy-event.handler.ts index b7edc3483..791dcafe4 100644 --- a/src/modules/rabbitmq/blockchain-events/handlers-reindex/buy-event.handler.ts +++ b/src/modules/rabbitmq/blockchain-events/handlers-reindex/buy-event.handler.ts @@ -11,6 +11,7 @@ import { ClaimEvent } from '../../entities/auction-reindex/claim.event'; import { ElrondSwapBuyEvent } from '../../entities/auction-reindex/elrondnftswap/elrondswap-buy.event'; import { FeedEventsSenderService } from '../feed-events.service'; import { Marketplace } from 'src/modules/marketplaces/models'; +import { EventLog } from 'src/modules/metrics/rabbitEvent'; @Injectable() export class BuyEventHandler { @@ -24,15 +25,15 @@ export class BuyEventHandler { private readonly marketplaceService: MarketplacesService, ) { } - async handle(event: any, hash: string, marketplace: Marketplace) { + async handle(event: any, marketplace: Marketplace) { try { - const { buySftEvent, topics } = this.getEventAndTopics(event, hash); + const { buySftEvent, topics } = this.getEventAndTopics(event, 'hash'); let auction: AuctionEntity; - marketplace = await this.marketplaceService.getMarketplaceByType(buySftEvent.getAddress(), marketplace.type, topics.collection); + marketplace = await this.marketplaceService.getMarketplaceByType(buySftEvent.address, marketplace.type, topics.collection); if (!marketplace) return; - this.logger.log(`${buySftEvent.getIdentifier()} event detected for hash '${hash}' and marketplace '${marketplace?.name}'`); + this.logger.log(`${buySftEvent.identifier} event detected for marketplace '${marketplace?.name}'`); if (topics.auctionId) { auction = await this.auctionsGetterService.getAuctionByIdAndMarketplace(parseInt(topics.auctionId, 16), marketplace.key); @@ -45,7 +46,7 @@ export class BuyEventHandler { const result = await this.auctionsGetterService.getAvailableTokens(auction.id); const totalRemaining = result ? result[0]?.availableTokens - parseFloat(topics.boughtTokens) : 0; if (totalRemaining === 0) { - this.auctionsService.updateAuctionStatus(auction.id, AuctionStatusEnum.Ended, hash, AuctionStatusEnum.Ended); + this.auctionsService.updateAuctionStatus(auction.id, AuctionStatusEnum.Ended, 'hash', AuctionStatusEnum.Ended); } const orderSft = await this.ordersService.createOrderForSft( new CreateOrderArgs({ @@ -54,7 +55,7 @@ export class BuyEventHandler { priceToken: auction.paymentToken, priceAmount: auction.minBid, priceNonce: auction.paymentNonce, - blockHash: hash, + blockHash: 'hash', status: OrderStatusEnum.Bought, boughtTokens: topics.boughtTokens, marketplaceKey: marketplace.key, @@ -73,7 +74,7 @@ export class BuyEventHandler { } } - private getEventAndTopics(event: any, hash: string) { + private getEventAndTopics(event: EventLog, hash: string) { if (event.identifier === KroganSwapAuctionEventEnum.Purchase) { if (Buffer.from(event.topics[0], 'base64').toString() === KroganSwapAuctionEventEnum.UpdateListing) { this.logger.log( diff --git a/src/modules/rabbitmq/blockchain-events/handlers-reindex/endAuction-event.handler.ts b/src/modules/rabbitmq/blockchain-events/handlers-reindex/endAuction-event.handler.ts index 1adbb4a33..09c5de699 100644 --- a/src/modules/rabbitmq/blockchain-events/handlers-reindex/endAuction-event.handler.ts +++ b/src/modules/rabbitmq/blockchain-events/handlers-reindex/endAuction-event.handler.ts @@ -23,23 +23,23 @@ export class EndAuctionEventHandler { private notificationsService: NotificationsService, ) { } - async handle(event: any, hash: string, marketplace: Marketplace) { + async handle(event: any, marketplace: Marketplace) { try { const endAuctionEvent = new EndAuctionEvent(event); const topics = endAuctionEvent.getTopics(); marketplace = await this.marketplaceService.getMarketplaceByType( - endAuctionEvent.getAddress(), + endAuctionEvent.address, marketplace.type, topics.collection, ); if (!marketplace) return; - this.logger.log(`End auction event detected for hash '${hash}' and marketplace '${marketplace?.name}'`); + this.logger.log(`End auction event detected for marketplace '${marketplace?.name}'`); const auction = await this.auctionsGetterService.getAuctionByIdAndMarketplace(parseInt(topics.auctionId, 16), marketplace.key); if (!auction) return; - this.auctionsService.updateAuctionStatus(auction.id, AuctionStatusEnum.Ended, hash, AuctionEventEnum.EndAuctionEvent); + this.auctionsService.updateAuctionStatus(auction.id, AuctionStatusEnum.Ended, 'hash', AuctionEventEnum.EndAuctionEvent); this.notificationsService.updateNotificationStatus([auction.id]); this.ordersService.updateOrder(auction.id, OrderStatusEnum.Bought); await this.feedEventsSenderService.sendWonAuctionEvent(topics, auction, marketplace); diff --git a/src/modules/rabbitmq/blockchain-events/handlers-reindex/sendOffer-event.handler.ts b/src/modules/rabbitmq/blockchain-events/handlers-reindex/sendOffer-event.handler.ts index 42ebb4c98..5619d5c51 100644 --- a/src/modules/rabbitmq/blockchain-events/handlers-reindex/sendOffer-event.handler.ts +++ b/src/modules/rabbitmq/blockchain-events/handlers-reindex/sendOffer-event.handler.ts @@ -8,6 +8,7 @@ import { OffersService } from 'src/modules/offers/offers.service'; import { SendOfferEvent } from '../../entities/auction-reindex/sendOffer.event'; import { FeedEventsSenderService } from '../feed-events.service'; import { Marketplace } from 'src/modules/marketplaces/models'; +import { EventLog } from 'src/modules/metrics/rabbitEvent'; @Injectable() export class SendOfferEventHandler { @@ -20,22 +21,22 @@ export class SendOfferEventHandler { private readonly marketplaceService: MarketplacesService, ) { } - async handle(event: any, hash: string, marketplace: Marketplace) { + async handle(event: EventLog, marketplace: Marketplace) { try { if (marketplace.type === MarketplaceTypeEnum.External) { return; } const sendOffer = new SendOfferEvent(event); const topics = sendOffer.getTopics(); - marketplace = await this.marketplaceService.getMarketplaceByType(sendOffer.getAddress(), marketplace.type, topics.collection); + marketplace = await this.marketplaceService.getMarketplaceByType(sendOffer.address, marketplace.type, topics.collection); if (!marketplace) { return; } - this.logger.log(`Send Offer event detected for hash '${hash}' and marketplace '${marketplace?.name}'`); + this.logger.log(`Send Offer event detected for marketplace '${marketplace?.name}'`); - const offer = await this.offersService.saveOffer(OfferEntity.fromEventTopics(topics, hash, marketplace.key, OfferStatusEnum.Active)); + const offer = await this.offersService.saveOffer(OfferEntity.fromEventTopics(topics, 'hash', marketplace.key, OfferStatusEnum.Active)); if (!offer) return; await this.feedEventsSenderService.sendOfferEvent(offer); diff --git a/src/modules/rabbitmq/blockchain-events/handlers-reindex/startAuction-event.handler.ts b/src/modules/rabbitmq/blockchain-events/handlers-reindex/startAuction-event.handler.ts index 03c25c52a..9710aa9ed 100644 --- a/src/modules/rabbitmq/blockchain-events/handlers-reindex/startAuction-event.handler.ts +++ b/src/modules/rabbitmq/blockchain-events/handlers-reindex/startAuction-event.handler.ts @@ -13,6 +13,7 @@ import { AuctionTokenEvent } from '../../entities/auction-reindex'; import { ElrondSwapAuctionEvent } from '../../entities/auction-reindex/elrondnftswap/elrondswap-auction.event'; import { ListNftEvent } from '../../entities/auction-reindex/listNft.event'; import { FeedEventsSenderService } from '../feed-events.service'; +import { EventLog } from 'src/modules/metrics/rabbitEvent'; @Injectable() export class StartAuctionEventHandler { @@ -27,22 +28,22 @@ export class StartAuctionEventHandler { private readonly marketplaceService: MarketplacesService, ) { } - async handle(event: any, hash: string, marketplace: Marketplace) { + async handle(event: any, marketplace: Marketplace) { try { const { auctionTokenEvent, topics } = this.getEventAndTopics(event); if (!auctionTokenEvent && !topics) return; marketplace = await this.marketplaceService.getMarketplaceByType( - auctionTokenEvent.getAddress(), + auctionTokenEvent.address, marketplace.type, topics.collection, ); if (!marketplace) return; this.logger.log( - `${auctionTokenEvent.getIdentifier()} listing event detected for hash '${hash}' and marketplace '${marketplace?.name}'`, + `${auctionTokenEvent.identifier} listing event detected for marketplace '${marketplace?.name}'`, ); - const auction = await this.saveAuction(topics, marketplace, hash); + const auction = await this.saveAuction(topics, marketplace, 'hash'); if (!auction) return; @@ -89,7 +90,7 @@ export class StartAuctionEventHandler { ); } - private getEventAndTopics(event: any) { + private getEventAndTopics(event: EventLog) { if (event.identifier === KroganSwapAuctionEventEnum.NftSwap) { const auctionTokenEvent = new ElrondSwapAuctionEvent(event); const topics = auctionTokenEvent.getTopics(); diff --git a/src/modules/rabbitmq/blockchain-events/handlers-reindex/swapUpdate-event.handler.ts b/src/modules/rabbitmq/blockchain-events/handlers-reindex/swapUpdate-event.handler.ts index 8f297800d..2c5b131ae 100644 --- a/src/modules/rabbitmq/blockchain-events/handlers-reindex/swapUpdate-event.handler.ts +++ b/src/modules/rabbitmq/blockchain-events/handlers-reindex/swapUpdate-event.handler.ts @@ -17,15 +17,15 @@ export class SwapUpdateEventHandler { private usdPriceService: UsdPriceService, ) { } - async handle(event: any, hash: string, marketplace: Marketplace) { + async handle(event: any, marketplace: Marketplace) { try { const updateEvent = new ElrondSwapUpdateEvent(event); const topics = updateEvent.getTopics(); - this.logger.log(`${updateEvent.getIdentifier()} auction event detected for hash '${hash}' and marketplace '${marketplace?.name}'`); + this.logger.log(`${updateEvent.identifier} auction event detected for marketplace '${marketplace?.name}'`); let auction = await this.auctionsGetterService.getAuctionByIdAndMarketplace(parseInt(topics.auctionId, 16), marketplace.key); if (auction) { - await this.updateAuctionPrice(auction, topics, hash); + await this.updateAuctionPrice(auction, topics); this.auctionsService.updateAuction(auction, KroganSwapAuctionEventEnum.NftSwapUpdate); } } catch (error) { @@ -44,7 +44,6 @@ export class SwapUpdateEventHandler { price: string; deadline: number; }, - hash: string, ) { const paymentToken = await this.usdPriceService.getToken(auction.paymentToken); const decimals = paymentToken?.decimals ?? mxConfig.decimals; @@ -54,6 +53,6 @@ export class SwapUpdateEventHandler { auction.maxBidDenominated = auction.minBidDenominated; auction.endDate = topics.deadline; auction.nrAuctionedTokens = topics.nrAuctionTokens; - auction.blockHash = hash; + auction.blockHash = 'hash'; } } diff --git a/src/modules/rabbitmq/blockchain-events/handlers-reindex/updateListing-event.handler.ts b/src/modules/rabbitmq/blockchain-events/handlers-reindex/updateListing-event.handler.ts index 00fc801c2..9d449b87c 100644 --- a/src/modules/rabbitmq/blockchain-events/handlers-reindex/updateListing-event.handler.ts +++ b/src/modules/rabbitmq/blockchain-events/handlers-reindex/updateListing-event.handler.ts @@ -9,6 +9,7 @@ import { UsdPriceService } from 'src/modules/usdPrice/usd-price.service'; import { BigNumberUtils } from 'src/utils/bigNumber-utils'; import { UpdateListingEvent } from '../../entities/auction-reindex/updateListing.event'; import { Marketplace } from 'src/modules/marketplaces/models'; +import { EventLog } from 'src/modules/metrics/rabbitEvent'; @Injectable() export class UpdateListingEventHandler { @@ -21,20 +22,20 @@ export class UpdateListingEventHandler { private usdPriceService: UsdPriceService, ) { } - async handle(event: any, hash: string, marketplace: Marketplace) { + async handle(event: EventLog, marketplace: Marketplace) { try { const updateListingEvent = new UpdateListingEvent(event); const topics = updateListingEvent.getTopics(); - marketplace = await this.marketplaceService.getMarketplaceByType(updateListingEvent.getAddress(), marketplace.type, topics.collection); + marketplace = await this.marketplaceService.getMarketplaceByType(updateListingEvent.address, marketplace.type, topics.collection); this.logger.log( - `${updateListingEvent.getIdentifier()} listing event detected for hash '${hash}' and marketplace '${marketplace?.name}'`, + `${updateListingEvent.identifier} listing event detected for marketplace '${marketplace?.name}'`, ); let auction = await this.auctionsGetterService.getAuctionByIdAndMarketplace(parseInt(topics.auctionId, 16), marketplace.key); if (auction && marketplace) { const paymentToken = await this.usdPriceService.getToken(auction.paymentToken); - this.updateAuctionListing(auction, updateListingEvent, paymentToken, hash); + this.updateAuctionListing(auction, updateListingEvent, paymentToken, 'hash'); this.auctionsService.updateAuction(auction, ExternalAuctionEventEnum.UpdateListing); } diff --git a/src/modules/rabbitmq/blockchain-events/handlers-reindex/updatePrice-event.handler.ts b/src/modules/rabbitmq/blockchain-events/handlers-reindex/updatePrice-event.handler.ts index 42fa505d0..90400aa55 100644 --- a/src/modules/rabbitmq/blockchain-events/handlers-reindex/updatePrice-event.handler.ts +++ b/src/modules/rabbitmq/blockchain-events/handlers-reindex/updatePrice-event.handler.ts @@ -9,6 +9,7 @@ import { UsdPriceService } from 'src/modules/usdPrice/usd-price.service'; import { BigNumberUtils } from 'src/utils/bigNumber-utils'; import { DEADRARE_KEY } from 'src/utils/constants'; import { UpdatePriceEvent } from '../../entities/auction-reindex/updatePrice.event'; +import { EventLog } from 'src/modules/metrics/rabbitEvent'; @Injectable() export class UpdatePriceEventHandler { @@ -22,21 +23,21 @@ export class UpdatePriceEventHandler { private nftAbiService: NftMarketplaceAbiService, ) { } - async handle(event: any, hash: string, marketplace: Marketplace) { + async handle(event: EventLog, marketplace: Marketplace) { try { const updatePriceEvent = new UpdatePriceEvent(event); const topics = updatePriceEvent.getTopics(); marketplace = await this.marketplaceService.getMarketplaceByType( - updatePriceEvent.getAddress(), + updatePriceEvent.address, marketplace.type, topics.collection, ); - this.logger.log(`${updatePriceEvent.getIdentifier()} event detected for hash '${hash}' and marketplace '${marketplace?.name}'`); + this.logger.log(`${updatePriceEvent.identifier} event detected for marketplace '${marketplace?.name}'`); let auction = await this.auctionsGetterService.getAuctionByIdAndMarketplace(parseInt(topics.auctionId, 16), marketplace.key); let newPrice: string = await this.getNewPrice(marketplace, topics); if (auction && newPrice) { const paymentToken = await this.usdPriceService.getToken(auction.paymentToken); - this.updateAuctionPrice(auction, newPrice, hash, paymentToken?.decimals); + this.updateAuctionPrice(auction, newPrice, 'hash', paymentToken?.decimals); this.auctionsService.updateAuction(auction, ExternalAuctionEventEnum.UpdatePrice); } diff --git a/src/modules/rabbitmq/blockchain-events/handlers-reindex/withdrawAuction-event.handler.ts b/src/modules/rabbitmq/blockchain-events/handlers-reindex/withdrawAuction-event.handler.ts index c5864a7e7..a68f1129d 100644 --- a/src/modules/rabbitmq/blockchain-events/handlers-reindex/withdrawAuction-event.handler.ts +++ b/src/modules/rabbitmq/blockchain-events/handlers-reindex/withdrawAuction-event.handler.ts @@ -8,6 +8,7 @@ import { WithdrawEvent } from '../../entities/auction-reindex'; import { ClaimEvent } from '../../entities/auction-reindex/claim.event'; import { ElrondSwapWithdrawEvent } from '../../entities/auction-reindex/elrondnftswap/elrondswap-withdraw.event'; import { Marketplace } from 'src/modules/marketplaces/models'; +import { EventLog } from 'src/modules/metrics/rabbitEvent'; @Injectable() export class WithdrawAuctionEventHandler { @@ -19,14 +20,14 @@ export class WithdrawAuctionEventHandler { private readonly marketplaceService: MarketplacesService, ) { } - async handle(event: any, hash: string, marketplace: Marketplace) { + async handle(event: EventLog, marketplace: Marketplace) { try { const { withdraw, topics } = this.getEventAndTopics(event); let auction: AuctionEntity; - marketplace = await this.marketplaceService.getMarketplaceByType(withdraw.getAddress(), marketplace.type, topics.collection); + marketplace = await this.marketplaceService.getMarketplaceByType(withdraw.address, marketplace.type, topics.collection); if (!marketplace) return; - this.logger.log(`${withdraw.getIdentifier()} event detected for hash '${hash}' and marketplace '${marketplace?.name}'`); + this.logger.log(`${withdraw.identifier} event detected for marketplace '${marketplace?.name}'`); if (topics.auctionId) { auction = await this.auctionsGetterService.getAuctionByIdAndMarketplace(parseInt(topics.auctionId, 16), marketplace.key); } else { @@ -36,13 +37,13 @@ export class WithdrawAuctionEventHandler { if (!auction) return; - this.auctionsService.updateAuctionStatus(auction.id, AuctionStatusEnum.Closed, hash, AuctionEventEnum.WithdrawEvent); + this.auctionsService.updateAuctionStatus(auction.id, AuctionStatusEnum.Closed, 'hash', AuctionEventEnum.WithdrawEvent); } catch (error) { console.error('An errror occured while handling bid event', error); } } - private getEventAndTopics(event: any) { + private getEventAndTopics(event: EventLog) { if (event.identifier === KroganSwapAuctionEventEnum.WithdrawSwap) { const withdraw = new ElrondSwapWithdrawEvent(event); const topics = withdraw.getTopics(); diff --git a/src/modules/rabbitmq/blockchain-events/handlers-reindex/withdrawOffer-event.handler.ts b/src/modules/rabbitmq/blockchain-events/handlers-reindex/withdrawOffer-event.handler.ts index 2538a97a3..7ecdd33fc 100644 --- a/src/modules/rabbitmq/blockchain-events/handlers-reindex/withdrawOffer-event.handler.ts +++ b/src/modules/rabbitmq/blockchain-events/handlers-reindex/withdrawOffer-event.handler.ts @@ -6,6 +6,7 @@ import { OfferStatusEnum } from 'src/modules/offers/models'; import { OffersService } from 'src/modules/offers/offers.service'; import { WithdrawOfferEvent } from '../../entities/auction-reindex/withdrawOffer.event'; import { Marketplace } from 'src/modules/marketplaces/models'; +import { EventLog } from 'src/modules/metrics/rabbitEvent'; @Injectable() export class WithdrawOfferEventHandler { @@ -17,7 +18,7 @@ export class WithdrawOfferEventHandler { private readonly marketplaceService: MarketplacesService, ) { } - async handle(event: any, hash: string, marketplace: Marketplace) { + async handle(event: EventLog, marketplace: Marketplace) { try { if (marketplace.type === MarketplaceTypeEnum.External) { return; @@ -25,14 +26,14 @@ export class WithdrawOfferEventHandler { const withdrawOfferEvent = new WithdrawOfferEvent(event); const topics = withdrawOfferEvent.getTopics(); marketplace = await this.marketplaceService.getMarketplaceByCollectionAndAddress( - withdrawOfferEvent.getAddress(), + withdrawOfferEvent.address, topics.collection, ); if (!marketplace) { return; } - this.logger.log(`Withdraw Offer event detected for hash '${hash}' and marketplace '${marketplace?.name}'`); + this.logger.log(`Withdraw Offer event detected for marketplace '${marketplace?.name}'`); const withdrawOffer = await this.offersService.getOfferByIdAndMarketplace(topics.offerId, marketplace.key); diff --git a/src/modules/rabbitmq/blockchain-events/marketplace-events-processing.service.ts b/src/modules/rabbitmq/blockchain-events/marketplace-events-processing.service.ts index 00c0614d2..75adb6c5a 100644 --- a/src/modules/rabbitmq/blockchain-events/marketplace-events-processing.service.ts +++ b/src/modules/rabbitmq/blockchain-events/marketplace-events-processing.service.ts @@ -14,6 +14,7 @@ import { AcceptOfferEventHandler } from './handlers-reindex/acceptOffer-event.ha import { WithdrawOfferEventHandler } from './handlers-reindex/withdrawOffer-event.handler'; import { UpdateListingEventHandler } from './handlers-reindex/updateListing-event.handler'; import { MarketplacesService } from 'src/modules/marketplaces/marketplaces.service'; +import { EventLog } from 'src/modules/metrics/rabbitEvent'; @Injectable() export class MarketplaceEventsProcessingService { @@ -36,13 +37,13 @@ export class MarketplaceEventsProcessingService { private marketplaceService: MarketplacesService, ) { } - public async handleNftAuctionEvents(auctionEvents: any[], hash: string) { + public async handleNftAuctionEvents(auctionEvents: EventLog[]) { for (let event of auctionEvents) { const marketplace = await this.marketplaceService.getMarketplaceByAddress(event.address); switch (event.identifier) { case AuctionEventEnum.BidEvent: case KroganSwapAuctionEventEnum.Bid: - await this.bidEventHandler.handle(event, hash, marketplace); + await this.bidEventHandler.handle(event, marketplace); break; case AuctionEventEnum.BuySftEvent: @@ -53,10 +54,10 @@ export class MarketplaceEventsProcessingService { case KroganSwapAuctionEventEnum.Purchase: const eventName = Buffer.from(event.topics[0], 'base64').toString(); if (eventName === ExternalAuctionEventEnum.UpdateOffer || eventName === KroganSwapAuctionEventEnum.UpdateListing) { - this.logger.log(`${eventName} event detected for hash '${hash}' for marketplace ${event.address}, ignore it for the moment`); + this.logger.log(`${eventName} event detected for marketplace ${event.address}, ignore it for the moment`); continue; } - await this.buyEventHandler.handle(event, hash, marketplace); + await this.buyEventHandler.handle(event, marketplace); break; case AuctionEventEnum.WithdrawEvent: case KroganSwapAuctionEventEnum.WithdrawSwap: @@ -64,61 +65,61 @@ export class MarketplaceEventsProcessingService { case ExternalAuctionEventEnum.ReturnListing: if (Buffer.from(event.topics[0], 'base64').toString() === ExternalAuctionEventEnum.UpdateOffer) { this.logger.log( - `${event.topics[0]} event detected for hash '${hash}' for marketplace ${event.addreses}, ignore it for the moment`, + `${event.topics[0]} event detected for marketplace ${event.address}, ignore it for the moment`, ); continue; } - await this.withdrawAuctionEventHandler.handle(event, hash, marketplace); + await this.withdrawAuctionEventHandler.handle(event, marketplace); break; case AuctionEventEnum.EndAuctionEvent: - await this.endAuctionEventHandler.handle(event, hash, marketplace); + await this.endAuctionEventHandler.handle(event, marketplace); break; case AuctionEventEnum.AuctionTokenEvent: case ExternalAuctionEventEnum.Listing: case ExternalAuctionEventEnum.ListNftOnMarketplace: case KroganSwapAuctionEventEnum.NftSwap: - await this.startAuctionEventHandler.handle(event, hash, marketplace); + await this.startAuctionEventHandler.handle(event, marketplace); break; case ExternalAuctionEventEnum.ChangePrice: case ExternalAuctionEventEnum.UpdatePrice: - await this.updatePriceEventHandler.handle(event, hash, marketplace); + await this.updatePriceEventHandler.handle(event, marketplace); break; case ExternalAuctionEventEnum.UpdateListing: { - await this.updateListingEventHandler.handle(event, hash, marketplace); + await this.updateListingEventHandler.handle(event, marketplace); break; } case ExternalAuctionEventEnum.AcceptOffer: case ExternalAuctionEventEnum.AcceptOfferFromAuction: - const acceptOfferEventName = Buffer.from(event.topics[0], 'base64').toString(); + const acceptOfferEventName = Buffer.from(event.topics[0], 'hex').toString(); if (acceptOfferEventName === ExternalAuctionEventEnum.UserDeposit) { continue; } if (acceptOfferEventName === ExternalAuctionEventEnum.EndTokenEvent) { - await this.withdrawAuctionEventHandler.handle(event, hash, marketplace); + await this.withdrawAuctionEventHandler.handle(event, marketplace); } else { - await this.acceptOfferEventHandler.handle(event, hash, marketplace); + await this.acceptOfferEventHandler.handle(event, marketplace); } break; case AuctionEventEnum.WithdrawAuctionAndAcceptOffer: - if (Buffer.from(event.topics[0], 'base64').toString() === AuctionEventEnum.Accept_offer_token_event) { - await this.acceptOfferEventHandler.handle(event, hash, marketplace); + if (Buffer.from(event.topics[0], 'hex').toString() === AuctionEventEnum.Accept_offer_token_event) { + await this.acceptOfferEventHandler.handle(event, marketplace); } else { - await this.withdrawAuctionEventHandler.handle(event, hash, marketplace); + await this.withdrawAuctionEventHandler.handle(event, marketplace); } break; case ExternalAuctionEventEnum.AcceptGlobalOffer: - await this.acceptGlobalOfferEventHandler.handle(event, hash, marketplace); + await this.acceptGlobalOfferEventHandler.handle(event, marketplace); break; case AuctionEventEnum.SendOffer: - await this.sendOfferEventHandler.handle(event, hash, marketplace); + await this.sendOfferEventHandler.handle(event, marketplace); break; case AuctionEventEnum.WithdrawOffer: - await this.withdrawOfferEventHandler.handle(event, hash, marketplace); + await this.withdrawOfferEventHandler.handle(event, marketplace); break; case KroganSwapAuctionEventEnum.NftSwapUpdate: case KroganSwapAuctionEventEnum.NftSwapExtend: - await this.swapUpdateEventHandler.handle(event, hash, marketplace); + await this.swapUpdateEventHandler.handle(event, marketplace); break; case MarketplaceEventEnum.SCUpgrade: { await this.slackReportService.sendScUpgradeNotification(event.address); diff --git a/src/modules/rabbitmq/entities/auction-reindex/acceptGlobalOffer.event.ts b/src/modules/rabbitmq/entities/auction-reindex/acceptGlobalOffer.event.ts index be1ed2cf7..e390dfa25 100644 --- a/src/modules/rabbitmq/entities/auction-reindex/acceptGlobalOffer.event.ts +++ b/src/modules/rabbitmq/entities/auction-reindex/acceptGlobalOffer.event.ts @@ -1,10 +1,10 @@ -import { GenericEvent } from '../generic.event'; +import { EventLog } from 'src/modules/metrics/rabbitEvent'; import { AcceptGlobalOfferEventsTopics } from './acceptGlobalOffer.event.topics'; -export class AcceptGlobalOfferEvent extends GenericEvent { +export class AcceptGlobalOfferEvent extends EventLog { private decodedTopics: AcceptGlobalOfferEventsTopics; - constructor(init?: Partial) { + constructor(init?: Partial) { super(init); this.decodedTopics = new AcceptGlobalOfferEventsTopics(this.topics); } diff --git a/src/modules/rabbitmq/entities/auction-reindex/acceptOffer.event.ts b/src/modules/rabbitmq/entities/auction-reindex/acceptOffer.event.ts index 2cc8c602f..b847e26e8 100644 --- a/src/modules/rabbitmq/entities/auction-reindex/acceptOffer.event.ts +++ b/src/modules/rabbitmq/entities/auction-reindex/acceptOffer.event.ts @@ -1,10 +1,10 @@ -import { GenericEvent } from '../generic.event'; +import { EventLog } from 'src/modules/metrics/rabbitEvent'; import { AcceptOfferEventsTopics } from './acceptOffer.event.topics'; -export class AcceptOfferEvent extends GenericEvent { +export class AcceptOfferEvent extends EventLog { private decodedTopics: AcceptOfferEventsTopics; - constructor(init?: Partial) { + constructor(init?: Partial) { super(init); this.decodedTopics = new AcceptOfferEventsTopics(this.topics); } diff --git a/src/modules/rabbitmq/entities/auction-reindex/acceptOfferDeadrare.event.ts b/src/modules/rabbitmq/entities/auction-reindex/acceptOfferDeadrare.event.ts index 8d03cfcc0..72a5e8cad 100644 --- a/src/modules/rabbitmq/entities/auction-reindex/acceptOfferDeadrare.event.ts +++ b/src/modules/rabbitmq/entities/auction-reindex/acceptOfferDeadrare.event.ts @@ -1,10 +1,10 @@ -import { GenericEvent } from '../generic.event'; +import { EventLog } from 'src/modules/metrics/rabbitEvent'; import { AcceptOfferDeadrareEventsTopics } from './acceptOfferDeadrare.event.topics'; -export class AcceptOfferDeadrareEvent extends GenericEvent { +export class AcceptOfferDeadrareEvent extends EventLog { private decodedTopics: AcceptOfferDeadrareEventsTopics; - constructor(init?: Partial) { + constructor(init?: Partial) { super(init); this.decodedTopics = new AcceptOfferDeadrareEventsTopics(this.topics); } diff --git a/src/modules/rabbitmq/entities/auction-reindex/acceptOfferFrameit.event.ts b/src/modules/rabbitmq/entities/auction-reindex/acceptOfferFrameit.event.ts index 9cf7300a1..6ce198b79 100644 --- a/src/modules/rabbitmq/entities/auction-reindex/acceptOfferFrameit.event.ts +++ b/src/modules/rabbitmq/entities/auction-reindex/acceptOfferFrameit.event.ts @@ -1,10 +1,10 @@ -import { GenericEvent } from '../generic.event'; +import { EventLog } from 'src/modules/metrics/rabbitEvent'; import { AcceptOfferFrameitEventsTopics } from './acceptOfferFrameit.event.topics'; -export class AcceptOfferFrameitEvent extends GenericEvent { +export class AcceptOfferFrameitEvent extends EventLog { private decodedTopics: AcceptOfferFrameitEventsTopics; - constructor(init?: Partial) { + constructor(init?: Partial) { super(init); this.decodedTopics = new AcceptOfferFrameitEventsTopics(this.topics); } diff --git a/src/modules/rabbitmq/entities/auction-reindex/acceptOfferXoxno.event.ts b/src/modules/rabbitmq/entities/auction-reindex/acceptOfferXoxno.event.ts index 21c7ddeff..3981bea49 100644 --- a/src/modules/rabbitmq/entities/auction-reindex/acceptOfferXoxno.event.ts +++ b/src/modules/rabbitmq/entities/auction-reindex/acceptOfferXoxno.event.ts @@ -1,10 +1,11 @@ +import { EventLog } from 'src/modules/metrics/rabbitEvent'; import { GenericEvent } from '../generic.event'; import { AcceptOfferXoxnoEventsTopics } from './acceptOfferXoxno.event.topics'; -export class AcceptOfferXoxnoEvent extends GenericEvent { +export class AcceptOfferXoxnoEvent extends EventLog { private decodedTopics: AcceptOfferXoxnoEventsTopics; - constructor(init?: Partial) { + constructor(init?: Partial) { super(init); this.decodedTopics = new AcceptOfferXoxnoEventsTopics(this.topics); } diff --git a/src/modules/rabbitmq/entities/auction-reindex/auctionToken.event.ts b/src/modules/rabbitmq/entities/auction-reindex/auctionToken.event.ts index 6377b9d0d..f4db9303a 100644 --- a/src/modules/rabbitmq/entities/auction-reindex/auctionToken.event.ts +++ b/src/modules/rabbitmq/entities/auction-reindex/auctionToken.event.ts @@ -1,10 +1,10 @@ -import { GenericEvent } from '../generic.event'; +import { EventLog } from 'src/modules/metrics/rabbitEvent'; import { AuctionTokenEventsTopics } from './auctionToken.event.topics'; -export class AuctionTokenEvent extends GenericEvent { +export class AuctionTokenEvent extends EventLog { private decodedTopics: AuctionTokenEventsTopics; - constructor(init?: Partial) { + constructor(init?: Partial) { super(init); this.decodedTopics = new AuctionTokenEventsTopics(this.topics); } diff --git a/src/modules/rabbitmq/entities/auction-reindex/bid.event.ts b/src/modules/rabbitmq/entities/auction-reindex/bid.event.ts index 408cee8b5..a163381a4 100644 --- a/src/modules/rabbitmq/entities/auction-reindex/bid.event.ts +++ b/src/modules/rabbitmq/entities/auction-reindex/bid.event.ts @@ -1,10 +1,10 @@ -import { GenericEvent } from '../generic.event'; +import { EventLog } from 'src/modules/metrics/rabbitEvent'; import { BidEventsTopics } from './bid.event.topics'; -export class BidEvent extends GenericEvent { +export class BidEvent extends EventLog { private decodedTopics: BidEventsTopics; - constructor(init?: Partial) { + constructor(init?: Partial) { super(init); this.decodedTopics = new BidEventsTopics(this.topics); } diff --git a/src/modules/rabbitmq/entities/auction-reindex/buySft.event.ts b/src/modules/rabbitmq/entities/auction-reindex/buySft.event.ts index b4245c176..13339a247 100644 --- a/src/modules/rabbitmq/entities/auction-reindex/buySft.event.ts +++ b/src/modules/rabbitmq/entities/auction-reindex/buySft.event.ts @@ -1,10 +1,10 @@ -import { GenericEvent } from '../generic.event'; +import { EventLog } from 'src/modules/metrics/rabbitEvent'; import { BuySftEventsTopics } from './buySft.event.topics'; -export class BuySftEvent extends GenericEvent { +export class BuySftEvent extends EventLog { private decodedTopics: BuySftEventsTopics; - constructor(init?: Partial) { + constructor(init?: Partial) { super(init); this.decodedTopics = new BuySftEventsTopics(this.topics); } diff --git a/src/modules/rabbitmq/entities/auction-reindex/claim.event.ts b/src/modules/rabbitmq/entities/auction-reindex/claim.event.ts index 45e67713b..1a604ba4a 100644 --- a/src/modules/rabbitmq/entities/auction-reindex/claim.event.ts +++ b/src/modules/rabbitmq/entities/auction-reindex/claim.event.ts @@ -1,10 +1,10 @@ -import { GenericEvent } from '../generic.event'; +import { EventLog } from 'src/modules/metrics/rabbitEvent'; import { ClaimEventsTopics } from './claim.event.topics'; -export class ClaimEvent extends GenericEvent { +export class ClaimEvent extends EventLog { private decodedTopics: ClaimEventsTopics; - constructor(init?: Partial) { + constructor(init?: Partial) { super(init); this.decodedTopics = new ClaimEventsTopics(this.topics); } diff --git a/src/modules/rabbitmq/entities/auction-reindex/elrondnftswap/elrondswap-auction.event.ts b/src/modules/rabbitmq/entities/auction-reindex/elrondnftswap/elrondswap-auction.event.ts index ece09a2a7..268ac5157 100644 --- a/src/modules/rabbitmq/entities/auction-reindex/elrondnftswap/elrondswap-auction.event.ts +++ b/src/modules/rabbitmq/entities/auction-reindex/elrondnftswap/elrondswap-auction.event.ts @@ -1,10 +1,10 @@ -import { GenericEvent } from '../../generic.event'; +import { EventLog } from 'src/modules/metrics/rabbitEvent'; import { ElrondSwapAuctionTopics } from './elrondswap-auction.event.topics'; -export class ElrondSwapAuctionEvent extends GenericEvent { +export class ElrondSwapAuctionEvent extends EventLog { private decodedTopics: ElrondSwapAuctionTopics; - constructor(init?: Partial) { + constructor(init?: Partial) { super(init); this.decodedTopics = new ElrondSwapAuctionTopics(this.topics); } diff --git a/src/modules/rabbitmq/entities/auction-reindex/elrondnftswap/elrondswap-buy.event.ts b/src/modules/rabbitmq/entities/auction-reindex/elrondnftswap/elrondswap-buy.event.ts index ccb002bc5..277467851 100644 --- a/src/modules/rabbitmq/entities/auction-reindex/elrondnftswap/elrondswap-buy.event.ts +++ b/src/modules/rabbitmq/entities/auction-reindex/elrondnftswap/elrondswap-buy.event.ts @@ -1,10 +1,11 @@ +import { EventLog } from 'src/modules/metrics/rabbitEvent'; import { GenericEvent } from '../../generic.event'; import { ElrondSwapBuyTopics } from './elrondswap-buy.event.topics'; -export class ElrondSwapBuyEvent extends GenericEvent { +export class ElrondSwapBuyEvent extends EventLog { private decodedTopics: ElrondSwapBuyTopics; - constructor(init?: Partial) { + constructor(init?: Partial) { super(init); this.decodedTopics = new ElrondSwapBuyTopics(this.topics); } diff --git a/src/modules/rabbitmq/entities/auction-reindex/elrondnftswap/elrondswap-updateAuction.event.ts b/src/modules/rabbitmq/entities/auction-reindex/elrondnftswap/elrondswap-updateAuction.event.ts index 830909699..149333353 100644 --- a/src/modules/rabbitmq/entities/auction-reindex/elrondnftswap/elrondswap-updateAuction.event.ts +++ b/src/modules/rabbitmq/entities/auction-reindex/elrondnftswap/elrondswap-updateAuction.event.ts @@ -1,10 +1,10 @@ -import { GenericEvent } from '../../generic.event'; +import { EventLog } from 'src/modules/metrics/rabbitEvent'; import { ElrondSwapUpdateTopics } from './elrondswap-updateAuction.event.topics'; -export class ElrondSwapUpdateEvent extends GenericEvent { +export class ElrondSwapUpdateEvent extends EventLog { private decodedTopics: ElrondSwapUpdateTopics; - constructor(init?: Partial) { + constructor(init?: Partial) { super(init); this.decodedTopics = new ElrondSwapUpdateTopics(this.topics); } diff --git a/src/modules/rabbitmq/entities/auction-reindex/elrondnftswap/elrondswap-withdraw.event.ts b/src/modules/rabbitmq/entities/auction-reindex/elrondnftswap/elrondswap-withdraw.event.ts index 70d953851..2f7b8a27c 100644 --- a/src/modules/rabbitmq/entities/auction-reindex/elrondnftswap/elrondswap-withdraw.event.ts +++ b/src/modules/rabbitmq/entities/auction-reindex/elrondnftswap/elrondswap-withdraw.event.ts @@ -1,10 +1,10 @@ -import { GenericEvent } from '../../generic.event'; +import { EventLog } from 'src/modules/metrics/rabbitEvent'; import { ElrondSwapWithdrawTopics } from './elrondswap-withdraw.event.topics'; -export class ElrondSwapWithdrawEvent extends GenericEvent { +export class ElrondSwapWithdrawEvent extends EventLog { private decodedTopics: ElrondSwapWithdrawTopics; - constructor(init?: Partial) { + constructor(init?: Partial) { super(init); this.decodedTopics = new ElrondSwapWithdrawTopics(this.topics); } diff --git a/src/modules/rabbitmq/entities/auction-reindex/endAuction.event.ts b/src/modules/rabbitmq/entities/auction-reindex/endAuction.event.ts index 5f0608494..fadee5e25 100644 --- a/src/modules/rabbitmq/entities/auction-reindex/endAuction.event.ts +++ b/src/modules/rabbitmq/entities/auction-reindex/endAuction.event.ts @@ -1,10 +1,10 @@ -import { GenericEvent } from '../generic.event'; +import { EventLog } from 'src/modules/metrics/rabbitEvent'; import { EndAuctionEventsTopics } from './endAuction.event.topics'; -export class EndAuctionEvent extends GenericEvent { +export class EndAuctionEvent extends EventLog { private decodedTopics: EndAuctionEventsTopics; - constructor(init?: Partial) { + constructor(init?: Partial) { super(init); this.decodedTopics = new EndAuctionEventsTopics(this.topics); } diff --git a/src/modules/rabbitmq/entities/auction-reindex/listNft.event.ts b/src/modules/rabbitmq/entities/auction-reindex/listNft.event.ts index b0eb3dfb2..0b34c1f96 100644 --- a/src/modules/rabbitmq/entities/auction-reindex/listNft.event.ts +++ b/src/modules/rabbitmq/entities/auction-reindex/listNft.event.ts @@ -1,10 +1,10 @@ -import { GenericEvent } from '../generic.event'; +import { EventLog } from 'src/modules/metrics/rabbitEvent'; import { ListNftEventsTopics } from './listNft.event.topics'; -export class ListNftEvent extends GenericEvent { +export class ListNftEvent extends EventLog { private decodedTopics: ListNftEventsTopics; - constructor(init?: Partial) { + constructor(init?: Partial) { super(init); this.decodedTopics = new ListNftEventsTopics(this.topics); } diff --git a/src/modules/rabbitmq/entities/auction-reindex/sendOffer.event.ts b/src/modules/rabbitmq/entities/auction-reindex/sendOffer.event.ts index 942032284..59601d177 100644 --- a/src/modules/rabbitmq/entities/auction-reindex/sendOffer.event.ts +++ b/src/modules/rabbitmq/entities/auction-reindex/sendOffer.event.ts @@ -1,10 +1,10 @@ -import { GenericEvent } from '../generic.event'; +import { EventLog } from 'src/modules/metrics/rabbitEvent'; import { SendOfferEventsTopics } from './sendOffer.event.topics'; -export class SendOfferEvent extends GenericEvent { +export class SendOfferEvent extends EventLog { private decodedTopics: SendOfferEventsTopics; - constructor(init?: Partial) { + constructor(init?: Partial) { super(init); this.decodedTopics = new SendOfferEventsTopics(this.topics); } diff --git a/src/modules/rabbitmq/entities/auction-reindex/updateListing.event.ts b/src/modules/rabbitmq/entities/auction-reindex/updateListing.event.ts index d4ef778be..24709d10a 100644 --- a/src/modules/rabbitmq/entities/auction-reindex/updateListing.event.ts +++ b/src/modules/rabbitmq/entities/auction-reindex/updateListing.event.ts @@ -1,10 +1,10 @@ -import { GenericEvent } from '../generic.event'; +import { EventLog } from 'src/modules/metrics/rabbitEvent'; import { UpdateListingEventsTopics } from './updateListing.event.topics'; -export class UpdateListingEvent extends GenericEvent { +export class UpdateListingEvent extends EventLog { private decodedTopics: UpdateListingEventsTopics; - constructor(init?: Partial) { + constructor(init?: Partial) { super(init); this.decodedTopics = new UpdateListingEventsTopics(this.topics); } diff --git a/src/modules/rabbitmq/entities/auction-reindex/updatePrice.event.ts b/src/modules/rabbitmq/entities/auction-reindex/updatePrice.event.ts index 1538b5535..94b5a265d 100644 --- a/src/modules/rabbitmq/entities/auction-reindex/updatePrice.event.ts +++ b/src/modules/rabbitmq/entities/auction-reindex/updatePrice.event.ts @@ -1,10 +1,10 @@ -import { GenericEvent } from '../generic.event'; +import { EventLog } from 'src/modules/metrics/rabbitEvent'; import { UpdatePriceEventsTopics } from './updatePrice.event.topics'; -export class UpdatePriceEvent extends GenericEvent { +export class UpdatePriceEvent extends EventLog { private decodedTopics: UpdatePriceEventsTopics; - constructor(init?: Partial) { + constructor(init?: Partial) { super(init); this.decodedTopics = new UpdatePriceEventsTopics(this.topics); } diff --git a/src/modules/rabbitmq/entities/auction-reindex/withdraw.event.ts b/src/modules/rabbitmq/entities/auction-reindex/withdraw.event.ts index c41f3f5b7..99a85c63f 100644 --- a/src/modules/rabbitmq/entities/auction-reindex/withdraw.event.ts +++ b/src/modules/rabbitmq/entities/auction-reindex/withdraw.event.ts @@ -1,10 +1,10 @@ -import { GenericEvent } from '../generic.event'; +import { EventLog } from 'src/modules/metrics/rabbitEvent'; import { WithdrawEventsTopics } from './withdraw.event.topics'; -export class WithdrawEvent extends GenericEvent { +export class WithdrawEvent extends EventLog { private decodedTopics: WithdrawEventsTopics; - constructor(init?: Partial) { + constructor(init?: Partial) { super(init); this.decodedTopics = new WithdrawEventsTopics(this.topics); } diff --git a/src/modules/rabbitmq/entities/auction-reindex/withdrawOffer.event.ts b/src/modules/rabbitmq/entities/auction-reindex/withdrawOffer.event.ts index 39570c200..258f45b4c 100644 --- a/src/modules/rabbitmq/entities/auction-reindex/withdrawOffer.event.ts +++ b/src/modules/rabbitmq/entities/auction-reindex/withdrawOffer.event.ts @@ -1,10 +1,10 @@ -import { GenericEvent } from '../generic.event'; +import { EventLog } from 'src/modules/metrics/rabbitEvent'; import { WithdrawOfferEventsTopics } from './withdrawOffer.event.topics'; -export class WithdrawOfferEvent extends GenericEvent { +export class WithdrawOfferEvent extends EventLog { private decodedTopics: WithdrawOfferEventsTopics; - constructor(init?: Partial) { + constructor(init?: Partial) { super(init); this.decodedTopics = new WithdrawOfferEventsTopics(this.topics); } From cab617d58d75a0e375902992357bcf26b47e103f Mon Sep 17 00:00:00 2001 From: danielailie Date: Mon, 3 Jun 2024 14:49:49 +0300 Subject: [PATCH 13/18] Add logging --- .../blockchain-events/marketplace-events-processing.service.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/src/modules/rabbitmq/blockchain-events/marketplace-events-processing.service.ts b/src/modules/rabbitmq/blockchain-events/marketplace-events-processing.service.ts index 75adb6c5a..e8ae3de18 100644 --- a/src/modules/rabbitmq/blockchain-events/marketplace-events-processing.service.ts +++ b/src/modules/rabbitmq/blockchain-events/marketplace-events-processing.service.ts @@ -39,6 +39,7 @@ export class MarketplaceEventsProcessingService { public async handleNftAuctionEvents(auctionEvents: EventLog[]) { for (let event of auctionEvents) { + console.log('Received events: ', event.identifier) const marketplace = await this.marketplaceService.getMarketplaceByAddress(event.address); switch (event.identifier) { case AuctionEventEnum.BidEvent: From 3d89834cf71849cf819475edf59c2458404097c3 Mon Sep 17 00:00:00 2001 From: danielailie Date: Mon, 3 Jun 2024 15:13:17 +0300 Subject: [PATCH 14/18] Extend logging --- .../blockchain-events/marketplace-events-processing.service.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/modules/rabbitmq/blockchain-events/marketplace-events-processing.service.ts b/src/modules/rabbitmq/blockchain-events/marketplace-events-processing.service.ts index e8ae3de18..a0096b1bb 100644 --- a/src/modules/rabbitmq/blockchain-events/marketplace-events-processing.service.ts +++ b/src/modules/rabbitmq/blockchain-events/marketplace-events-processing.service.ts @@ -39,8 +39,8 @@ export class MarketplaceEventsProcessingService { public async handleNftAuctionEvents(auctionEvents: EventLog[]) { for (let event of auctionEvents) { - console.log('Received events: ', event.identifier) const marketplace = await this.marketplaceService.getMarketplaceByAddress(event.address); + console.log('Received events: ', event.identifier, { marketplace }) switch (event.identifier) { case AuctionEventEnum.BidEvent: case KroganSwapAuctionEventEnum.Bid: From 0c4bafd0b1c47fb67befe46d45a3b8c060894e95 Mon Sep 17 00:00:00 2001 From: danielailie Date: Mon, 3 Jun 2024 15:38:22 +0300 Subject: [PATCH 15/18] More logging --- .../handlers-reindex/startAuction-event.handler.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/src/modules/rabbitmq/blockchain-events/handlers-reindex/startAuction-event.handler.ts b/src/modules/rabbitmq/blockchain-events/handlers-reindex/startAuction-event.handler.ts index 9710aa9ed..0de238bca 100644 --- a/src/modules/rabbitmq/blockchain-events/handlers-reindex/startAuction-event.handler.ts +++ b/src/modules/rabbitmq/blockchain-events/handlers-reindex/startAuction-event.handler.ts @@ -55,6 +55,7 @@ export class StartAuctionEventHandler { private async saveAuction(topics: any, marketplace: Marketplace, hash: string) { const auctionIdentifier = `${topics.collection}-${topics.nonce}`; + console.log({ auctionIdentifier, topics }) if (marketplace.key === ELRONDNFTSWAP_KEY || marketplace.key === ENEFTOR_KEY || marketplace.key === XOXNO_KEY) { if (topics.auctionId === '0') { let auctionId = await this.auctionsGetterService.getLastAuctionIdForMarketplace(marketplace.key); From 11e90a40dc3fb717e88b698c1fbf65de417541d8 Mon Sep 17 00:00:00 2001 From: danielailie Date: Mon, 3 Jun 2024 16:19:55 +0300 Subject: [PATCH 16/18] Fix Decodind --- .../entities/auction-reindex/auctionToken.event.topics.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/modules/rabbitmq/entities/auction-reindex/auctionToken.event.topics.ts b/src/modules/rabbitmq/entities/auction-reindex/auctionToken.event.topics.ts index c848f89f8..d74f669f8 100644 --- a/src/modules/rabbitmq/entities/auction-reindex/auctionToken.event.topics.ts +++ b/src/modules/rabbitmq/entities/auction-reindex/auctionToken.event.topics.ts @@ -26,7 +26,7 @@ export class AuctionTokenEventsTopics { this.maxBid = rawTopics[7] ? BinaryUtils.hexToNumber(rawTopics[7]).toString() : '0'; this.startTime = BinaryUtils.hexToNumber(rawTopics[8]); this.endTime = rawTopics[9] ? parseInt(BinaryUtils.hexToNumber(rawTopics[9]).toString()) : 0; - this.paymentToken = rawTopics[10]; + this.paymentToken = rawTopics[10].toString(); this.paymentNonce = rawTopics[11] ? parseInt(BinaryUtils.hexToNumber(rawTopics[11]).toString()) : 0; this.auctionType = BinaryUtils.hexToNumber(rawTopics[12]).toString(); From fbf15c31f24dbf1ffb5abfc0bf545c7af141a48f Mon Sep 17 00:00:00 2001 From: danielailie Date: Mon, 3 Jun 2024 16:31:30 +0300 Subject: [PATCH 17/18] Fix decoding --- .../entities/auction-reindex/auctionToken.event.topics.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/modules/rabbitmq/entities/auction-reindex/auctionToken.event.topics.ts b/src/modules/rabbitmq/entities/auction-reindex/auctionToken.event.topics.ts index d74f669f8..a1734cdad 100644 --- a/src/modules/rabbitmq/entities/auction-reindex/auctionToken.event.topics.ts +++ b/src/modules/rabbitmq/entities/auction-reindex/auctionToken.event.topics.ts @@ -26,7 +26,7 @@ export class AuctionTokenEventsTopics { this.maxBid = rawTopics[7] ? BinaryUtils.hexToNumber(rawTopics[7]).toString() : '0'; this.startTime = BinaryUtils.hexToNumber(rawTopics[8]); this.endTime = rawTopics[9] ? parseInt(BinaryUtils.hexToNumber(rawTopics[9]).toString()) : 0; - this.paymentToken = rawTopics[10].toString(); + this.paymentToken = rawTopics[10].hexToAscii(); this.paymentNonce = rawTopics[11] ? parseInt(BinaryUtils.hexToNumber(rawTopics[11]).toString()) : 0; this.auctionType = BinaryUtils.hexToNumber(rawTopics[12]).toString(); From 4cadf1a93cae92fe5175ba5e2263e16536db1fa6 Mon Sep 17 00:00:00 2001 From: danielailie Date: Tue, 4 Jun 2024 09:08:28 +0300 Subject: [PATCH 18/18] fix bid handler --- .../handlers-reindex/acceptOffer-event.handler.ts | 2 +- .../blockchain-events/handlers-reindex/bid-event.handler.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/modules/rabbitmq/blockchain-events/handlers-reindex/acceptOffer-event.handler.ts b/src/modules/rabbitmq/blockchain-events/handlers-reindex/acceptOffer-event.handler.ts index d54e8efc2..de126a1d0 100644 --- a/src/modules/rabbitmq/blockchain-events/handlers-reindex/acceptOffer-event.handler.ts +++ b/src/modules/rabbitmq/blockchain-events/handlers-reindex/acceptOffer-event.handler.ts @@ -44,7 +44,7 @@ export class AcceptOfferEventHandler { if (!acceptOfferEvent) return; this.logger.log( - `${acceptOfferEvent.getIdentifier()} event detected for marketplace '${marketplace?.name}'`, + `${acceptOfferEvent.identifier} event detected for marketplace '${marketplace?.name}'`, ); if (topics.auctionId || topics.auctionId !== 0) { diff --git a/src/modules/rabbitmq/blockchain-events/handlers-reindex/bid-event.handler.ts b/src/modules/rabbitmq/blockchain-events/handlers-reindex/bid-event.handler.ts index dd6418c7e..505372dbe 100644 --- a/src/modules/rabbitmq/blockchain-events/handlers-reindex/bid-event.handler.ts +++ b/src/modules/rabbitmq/blockchain-events/handlers-reindex/bid-event.handler.ts @@ -38,7 +38,7 @@ export class BidEventHandler { marketplace = await this.marketplaceService.getMarketplaceByType(bidEvent.getAddress(), marketplace.type, topics.collection); } if (!marketplace) return; - this.logger.log(`${bidEvent.getIdentifier()} event detected for marketplace '${marketplace?.name}'`); + this.logger.log(`${bidEvent.identifier} event detected for marketplace '${marketplace?.name}'`); const auction = await this.auctionsGetterService.getAuctionByIdAndMarketplace(parseInt(topics.auctionId, 16), marketplace.key); if (!auction) return;