From db2f0fbf4d1bd55a019a79c7af2d87dbc5e2b1ea Mon Sep 17 00:00:00 2001 From: Raman Shekhawat Date: Mon, 24 Jun 2024 21:31:36 +0530 Subject: [PATCH] fix: IDXR-40 Do not update floor price when token is frozen or listing forbidden (#1139) do not update floor price when token is frozen or listing forbidden --- src/job-handlers/collection-stats.ts | 2 +- src/mappings/multiTokens/events/frozen.ts | 3 +++ src/mappings/multiTokens/events/thawed.ts | 3 +++ src/mappings/multiTokens/events/token_mutated.ts | 7 +++++-- 4 files changed, 12 insertions(+), 3 deletions(-) diff --git a/src/job-handlers/collection-stats.ts b/src/job-handlers/collection-stats.ts index adeb71bdc..06362acea 100644 --- a/src/job-handlers/collection-stats.ts +++ b/src/job-handlers/collection-stats.ts @@ -3,7 +3,7 @@ import { Collection, CollectionStats, Listing, ListingSale, ListingStatus, Token import { JobData } from '../jobs/collection-stats' import connection from '../connection' -const floorQuery = `SELECT MIN("listing"."highest_price") AS floor_price FROM "listing" AS "listing" INNER JOIN "token" "token" ON "token"."id" = "listing"."make_asset_id_id" INNER JOIN "collection" "collection" ON "collection"."id" = "token"."collection_id" WHERE "collection"."id" = $1 AND "listing"."is_active" = TRUE` +const floorQuery = `SELECT MIN("listing"."highest_price") AS floor_price FROM "listing" AS "listing" INNER JOIN "token" "token" ON "token"."id" = "listing"."make_asset_id_id" INNER JOIN "collection" "collection" ON "collection"."id" = "token"."collection_id" WHERE "collection"."id" = $1 AND "listing"."is_active" = TRUE AND "token"."is_frozen" = FALSE AND "token"."listing_forbidden" = FALSE;` export default async (job: Queue.Job, done: Queue.DoneCallback) => { if (!job.data.collectionId) { diff --git a/src/mappings/multiTokens/events/frozen.ts b/src/mappings/multiTokens/events/frozen.ts index 0484c627b..648fca826 100644 --- a/src/mappings/multiTokens/events/frozen.ts +++ b/src/mappings/multiTokens/events/frozen.ts @@ -14,6 +14,7 @@ import { import { CommonContext, BlockHeader, EventItem } from '../../types/contexts' import { isTokenFrozen } from './token_created' import { Sns } from '../../../common/sns' +import { syncCollectionStats } from '../../../jobs/collection-stats' function getEventData(event: EventItem) { if (events.multiTokens.frozen.matrixEnjinV603.is(event)) { @@ -169,5 +170,7 @@ export async function frozen( }) } + syncCollectionStats(data.collectionId.toString()) + return getEvent(item, data) } diff --git a/src/mappings/multiTokens/events/thawed.ts b/src/mappings/multiTokens/events/thawed.ts index df926b336..4ecb6062a 100644 --- a/src/mappings/multiTokens/events/thawed.ts +++ b/src/mappings/multiTokens/events/thawed.ts @@ -13,6 +13,7 @@ import { import { CommonContext, BlockHeader, EventItem } from '../../types/contexts' import { Sns } from '../../../common/sns' import { FreezeType_Token as FreezeTypeToken_v500 } from '../../../types/generated/v500' +import { syncCollectionStats } from '../../../jobs/collection-stats' function getEventData(event: EventItem) { if (events.multiTokens.thawed.matrixEnjinV603.is(event)) { @@ -150,5 +151,7 @@ export async function thawed( }) } + syncCollectionStats(data.collectionId.toString()) + return getEvent(item, data) } diff --git a/src/mappings/multiTokens/events/token_mutated.ts b/src/mappings/multiTokens/events/token_mutated.ts index 7ff929f89..24c46ae29 100644 --- a/src/mappings/multiTokens/events/token_mutated.ts +++ b/src/mappings/multiTokens/events/token_mutated.ts @@ -14,8 +14,9 @@ import { isNonFungible } from '../utils/helpers' import { CommonContext, BlockHeader, EventItem } from '../../types/contexts' import { getOrCreateAccount } from '../../util/entities' import { TokenMarketBehavior } from '../../../types/generated/v500' +import { syncCollectionStats } from '../../../jobs/collection-stats' -function getEventData(ctx: CommonContext, event: EventItem) { +function getEventData(event: EventItem) { if (events.multiTokens.tokenMutated.matrixEnjinV603.is(event)) { const { collectionId, tokenId, mutation } = events.multiTokens.tokenMutated.matrixEnjinV603.decode(event) return { @@ -66,7 +67,7 @@ export async function tokenMutated( item: EventItem, skipSave: boolean ): Promise { - const data = getEventData(ctx, item) + const data = getEventData(item) if (!data) return undefined if (skipSave) return getEvent(item, data) @@ -98,5 +99,7 @@ export async function tokenMutated( token.nonFungible = isNonFungible(token) await ctx.store.save(token) + syncCollectionStats(data.collectionId.toString()) + return getEvent(item, data) }