Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions src/mappings/nfts/claimSwap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { CollectionEntity as CE, Offer, Swap, TradeStatus } from '../../model'
import { unwrap } from '../utils/extract'
import { debug, pending, success } from '../utils/logger'
import { Context, createTokenId, isOffer } from '../utils/types'
import { calculateCollectionFloor, calculateCollectionOwnerCountAndDistribution } from '../utils/helper'
import { getSwapClaimedEvent } from './getters'

const OPERATION = TradeStatus.ACCEPTED
Expand Down Expand Up @@ -35,6 +36,18 @@ export async function handleClaimSwap(context: Context): Promise<void> {
}
}

const { floor } = await calculateCollectionFloor(context.store, collection.id, id)
const { ownerCount, distribution } = await calculateCollectionOwnerCountAndDistribution(
context.store,
collection.id,
event.currentOwner,
event.sent.owner
)
collection.floor = floor
collection.ownerCount = ownerCount
collection.distribution = distribution
Comment on lines +39 to +48
Copy link

Copilot AI Nov 10, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A swap involves two collections, but only the received collection's statistics are being updated. The sent collection (event.sent.collectionId) should also have its floor, ownerCount, and distribution recalculated and updated, as it loses an NFT owner and potentially gains a new one. This is inconsistent with how similar operations work - for example, in a swap, both NFTs change owners across potentially different collections.

Copilot uses AI. Check for mistakes.
collection.updatedAt = event.timestamp
Copy link

Copilot AI Nov 10, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The updatedAt field is set twice: once on line 30 and again on line 49. The first assignment on line 30 is redundant since it gets overwritten. Consider removing the duplicate assignment on line 30.

Copilot uses AI. Check for mistakes.

success(OPERATION, `${id} by ${event.caller}`)

await context.store.save(entity)
Expand Down
Loading