Skip to content

Commit

Permalink
fix NFTIO-2881 last sale is invalid (#1462)
Browse files Browse the repository at this point in the history
* fix NFTIO-2881 last sale

* fix

* fix
  • Loading branch information
justraman authored Dec 16, 2024
1 parent e01b698 commit 1e9cb2d
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
13 changes: 10 additions & 3 deletions src/mappings/marketplace/events/listing_filled.ts
Original file line number Diff line number Diff line change
Expand Up @@ -134,16 +134,23 @@ export async function listingFilled(
id: `${listingId}-${item.id}`,
amount: data.amountFilled,
buyer: new Account({ id: data.buyer }),
price: listing.price,
price: 'price' in data ? (data.price as bigint) : listing.highestPrice,
listing,
createdAt: new Date(block.timestamp ?? 0),
})

listing.makeAssetId.lastSale = sale
if (listing.state.listingType === ListingType.Offer) {
listing.takeAssetId.lastSale = sale
} else {
listing.makeAssetId.lastSale = sale
}

await Promise.all([ctx.store.save(listing), ctx.store.save(sale)])

if (listing.data.listingType !== ListingType.Offer) {
if (listing.data.listingType === ListingType.Offer) {
await ctx.store.save(listing.takeAssetId)
syncCollectionStats(listing.takeAssetId.collection.id)
} else {
if (listing.makeAssetId.bestListing?.id === listing.id && data.amountRemaining === 0n) {
const bestListing = await getBestListing(ctx, listing.makeAssetId.id)
listing.makeAssetId.bestListing = null
Expand Down
1 change: 1 addition & 0 deletions src/server-extension/resolvers/token_sales_history.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ export class TokenSalesHistoryResolver {
.createQueryBuilder('listing_sale')
.leftJoinAndMapOne('listing_sale.listing', Listing, 'listing', 'listing_sale.listing_id = listing.id')
.where('listing.make_asset_id_id = :id', { id })
.orWhere('listing.take_asset_id_id = :id', { id })
.select('DATE(listing_sale.created_at) AS day')
.addSelect('COUNT(*) AS trades')
.addSelect('SUM(listing_sale.price) AS price')
Expand Down

0 comments on commit 1e9cb2d

Please sign in to comment.