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

feat: SyncActivityPrices command to update missing nft activity sales prices #249

Conversation

patricio0312rev
Copy link
Contributor

[nft activity] compute and sync total usd/native amount from the token price history

Summary

  • New activities:sync-prices command to update all the NFT activities from a Polygon collection in our DB.

Explanation of the command

This new command runs a transaction query that updates the 'nft_activity' table by calculating and setting the 'total_native' and 'total_usd' columns based on the values stored in the 'extra_attributes' column from the 'token_price_history' table and the price column in the token_price_history table. The command performs the following actions:

  1. For each record in 'nft_activity':

    • Extract the 'totalNative' value from the 'extra_attributes' JSON column and set it as 'total_native'.
    • Calculate 'total_usd' by multiplying 'total_native' with the 'ethereum' token price from 'token_price_history' for the time that activity happened.
  2. Update is limited to records in 'nft_activity' associated with collections having a 'network_id' of 1 (Polygon in our app).

  3. The command uses a transaction to ensure data consistency. It commits the changes after successful execution.

Steps to reproduce

  1. Run the migrations for the app.
  2. Make sure token_price_history table is empty.
  3. Index a handful of activities (just for Polygon collections).
  4. Index token price history for Matic (you can use php artisan marketdata:fetch-price-history).
  5. Run our new command: php artisan activities:sync-prices.
  6. Test that total_native and total_usd is now filled for all the entries that belong to a Polygon collection.

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

@patricio0312rev patricio0312rev marked this pull request as ready for review October 18, 2023 15:22
@ItsANameToo ItsANameToo added this to the 0.8.0 milestone Oct 18, 2023
Copy link
Contributor

@goga-m goga-m left a comment

Choose a reason for hiding this comment

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

🎉

oXtxNt9U
oXtxNt9U previously approved these changes Oct 19, 2023
@oXtxNt9U oXtxNt9U dismissed their stale review October 19, 2023 09:58

misclick

@ItsANameToo ItsANameToo mentioned this pull request Oct 19, 2023
5 tasks
Copy link
Contributor

@ItsANameToo ItsANameToo left a comment

Choose a reason for hiding this comment

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

needs checking how long this takes to run for x amount of records, as the initial reports would indicate it's too slow to run this on the production database

@ItsANameToo ItsANameToo marked this pull request as draft October 19, 2023 14:08
@ItsANameToo ItsANameToo marked this pull request as ready for review October 19, 2023 14:57
@ItsANameToo ItsANameToo marked this pull request as draft October 19, 2023 15:14
@patricio0312rev patricio0312rev marked this pull request as ready for review October 19, 2023 16:44
@ItsANameToo ItsANameToo changed the title feat: SyncActivityPrices command to update total_native and total_usd columns in nft_activity table feat: SyncActivityPrices command to update missing nft activity sales prices Oct 20, 2023
@ItsANameToo ItsANameToo merged commit af623b8 into rc-0.8.0 Oct 20, 2023
22 checks passed
@ItsANameToo ItsANameToo deleted the feat/sync-total-usd-and-total-native-from-token-price-history branch October 20, 2023 10:18
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