Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hot Table resolver #43

Open
vikiival opened this issue Aug 7, 2023 · 0 comments
Open

Hot Table resolver #43

vikiival opened this issue Aug 7, 2023 · 0 comments

Comments

@vikiival
Copy link
Member

vikiival commented Aug 7, 2023

query hotNfts(
  $orderBy: [EventOrderByInput!] = timestamp_DESC
  $gte: DateTime!
) {
  result: events(
    where: { interaction_eq: BUY, timestamp_gte: $gte }
    orderBy: $orderBy
  ) {
    timestamp
    interaction
    nft {
      collection {
        name
        id
      }
    }
    meta
  }
}

data we calculate

  const collectionMap = groupBy(data, 'nft.collection.id')
   const sortOrder = [...new Set(data.map((e) => e.nft.collection.id))]
   const result = sortOrder.map((colId, idx) => {
     const collection = collectionMap[colId][0].nft.collection
     const nfts = sortBy(collectionMap[colId], 'timestamp').reverse()
     const totalVolume = toKSM(getVolume(nfts))
     const buys = nfts.length
     const latestSale = nfts[0]
     const medianIdx = Math.floor(buys / 2)
     return {
       id: idx + 1,
       collectionId: colId,
       name: collection.name,
       totalVolume,
       buys,
       latestSoldSize: toKSM(latestSale.meta),
       latestSoldTime: formatDistanceToNow(new Date(latestSale.timestamp)),
       medianDate: formatDistanceToNow(new Date(nfts[medianIdx].timestamp)),
       nfts,
     }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant