Skip to content

Commit

Permalink
fix: IDXR-40 Do not update floor price when token is frozen or listin…
Browse files Browse the repository at this point in the history
…g forbidden (#1139)

do not update floor price when token is frozen or listing forbidden
  • Loading branch information
justraman authored Jun 24, 2024
1 parent db08e07 commit db2f0fb
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/job-handlers/collection-stats.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<JobData>, done: Queue.DoneCallback) => {
if (!job.data.collectionId) {
Expand Down
3 changes: 3 additions & 0 deletions src/mappings/multiTokens/events/frozen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand Down Expand Up @@ -169,5 +170,7 @@ export async function frozen(
})
}

syncCollectionStats(data.collectionId.toString())

return getEvent(item, data)
}
3 changes: 3 additions & 0 deletions src/mappings/multiTokens/events/thawed.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand Down Expand Up @@ -150,5 +151,7 @@ export async function thawed(
})
}

syncCollectionStats(data.collectionId.toString())

return getEvent(item, data)
}
7 changes: 5 additions & 2 deletions src/mappings/multiTokens/events/token_mutated.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -66,7 +67,7 @@ export async function tokenMutated(
item: EventItem,
skipSave: boolean
): Promise<EventModel | undefined> {
const data = getEventData(ctx, item)
const data = getEventData(item)
if (!data) return undefined

if (skipSave) return getEvent(item, data)
Expand Down Expand Up @@ -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)
}

0 comments on commit db2f0fb

Please sign in to comment.