holaplex / indexer

Index Solana data using a Geyser plugin (downstream service cluster)
https://holaplex.com
GNU Affero General Public License v3.0
167 stars 39 forks source link

NFTS Owned by a Wallet Belonging to a Collection #663

Closed kespinola closed 2 years ago

kespinola commented 2 years ago
wallet(address: "") {
  collectedCollections: [CollectedCollection] {
     ownedNfts
     collection {
       nft {
         name
       }
       floorPrice
       nftCount
     }
   }
   createdCollections: [Collection] {
     nft {
       name
     }
     floorPrice
     nftCount
   }
}

Database Table

New table to track how many NFTs a person owns from a collection.

collection_owners
-------------------------
collection_address
wallet_address
nfts_owned

Trigger to recompute counts for the previous and current owner based on INSERTS or UPDATES to current_metadata_owners

current_metadata_owners
-----------------------------------
wallet_address
metadata_address

For both the previous and the current owner lookup the collection associated to the metadata and count how many other NFTs the user owns that are also apart of the collection. Write in the nfts_owned column on collections owners for the previous and current owner.

SELECT COUNT(*) FROM collection_metadata_keys 
  INNER JOIN metadatas on (metadatas.address = collection_metadata_keys.metadata_address)
  INNER JOIN current_metadata_owners on (current_metadata_owners.metadata_address = metadatas.address)
  WHERE current_metadata_owners = NEW.wallet_address 
  AND collection_metadata_keys  = (SELECT collection_address FROM collection_metadata_keys WHERE metadata_address = NEW.metadata_address)

Query to find how many NFTs a wallet owns that belong to the same collection as the one they just received or lost ownership of.

** Double check which of these is a metadata address and which is a mint address

The postgres hook is on current_metdata_owners

milorue commented 2 years ago

May eventually want to have a historical record stored of the floor price to support the price change UI the new profile designs have but not necessary for this pass

kespinola commented 2 years ago

https://github.com/holaplex/indexer/pull/681

completes collected collections.

kespinola commented 2 years ago

https://github.com/holaplex/indexer/pull/701