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

refactor: calculate the trait rarity based on the collection supply #679

Merged
merged 6 commits into from
Mar 7, 2024

Conversation

crnkovic
Copy link
Contributor

@crnkovic crnkovic commented Feb 21, 2024

Summary

https://app.clickup.com/t/86drbrvby

After a lot of experimentation on what works and what doesn't, we settled on calculating the trait rarity based on the data from our own database. So, we'll calculate the trait rarity by taking the number of NFTs in a collection that have this exact same trait and dividing it by the total supply of the collection.

Of course, we are unable to do this for collections that do not have the supply or have a supply > 50k, as we don't index NFTs for those collections.

When do we calculate these traits?

Depending on the number of traits, it can take a while to recalculate the rarity. For example, if collection has 10k of traits it can take up to 30 seconds to recalculate the rarity. Because of that, we don't want to run this on some schedule. Not only that, but it doesn't make sense to keep running it as rarity only changes once there are new traits and NFTs in the database. So, this job will only run for a collection once we store all of the collection's NFTs. We schedule a job to fetch NFTs (php artisan collections:fetch-nfts), and when there are no more NFTs to fetch, we recalculate the rarities.

Backfilling missing data

To retroactively update the data, you can run php artisan collections:calculate-trait-rarities. It will dispatch a series of jobs for every collection and calculate the traits.

Comparisons (us vs Rarible)

So far it seems to be pretty reliable, aside from some minor differences (10.1% compared to 10% or 10.3%, etc)

https://rarible.com/token/0x7f4ac7c9f7015178248ad6729523f0d5f628b933:3?tab=properties
Screenshot 2024-02-22 at 16 11 23
https://rarible.com/token/0x6fecaa110f74c8181e4a90285b1065be32596c9d:9?tab=properties
Screenshot 2024-02-22 at 16 11 56
https://rarible.com/token/0xc5a6afbe82eb9a119ac0d15392ca43b683ae8136:6?tab=properties
Screenshot 2024-02-22 at 16 12 31
https://rarible.com/token/0xc5a6afbe82eb9a119ac0d15392ca43b683ae8136:1?tab=properties
Screenshot 2024-02-22 at 16 13 21

Testing

For this to work properly, you need to index all of NFTs for a collection. You can do this with php artisan collections:fetch-nfts --collection-id=. When this job finishes, rarities will be recalculated automatically.

Checklist

  • I checked my UI changes against the design and there are no notable differences
  • I checked my UI changes for any responsiveness issues
  • I checked my (code) changes for obvious issues, debug statements and commented code
  • I opened a corresponding card on Clickup for any remaining TODOs in my code
  • I added a short description on how to test this PR (if necessary)
  • I added a storybook entry for the component that was added (if necessary)
  • Documentation (if necessary)
  • Tests (if necessary)
  • Ready to be merged

@crnkovic crnkovic marked this pull request as ready for review February 22, 2024 15:15
@goga-m goga-m merged commit 019b5c7 into develop Mar 7, 2024
12 checks passed
@goga-m goga-m deleted the refactor/trait-rarity branch March 7, 2024 09:46
@ItsANameToo ItsANameToo added this to the 0.14.0 milestone Mar 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants