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

[ENHANCE] Fetch USD prices for FTs #42

Closed
6 tasks done
lachlanglen opened this issue Jul 16, 2024 · 0 comments · Fixed by #43
Closed
6 tasks done

[ENHANCE] Fetch USD prices for FTs #42

lachlanglen opened this issue Jul 16, 2024 · 0 comments · Fixed by #43
Assignees
Labels
enhancement small enhancement / improvement from existing feature

Comments

@lachlanglen
Copy link
Contributor

lachlanglen commented Jul 16, 2024

Summary

Currently, we only fetch and save historical token prices for NEAR native token. We need to expand this to include FTs.

To-do:

  • Add nullable coingecko_id field to Token model
  • When a new Token is created (e.g. in save() override when it's a new record - see this example), call Coingecko /coins/list API with include_platform=true, and find the Coingecko ID for this token if it exists (you'll have to check the platforms property of each Coingecko record for a near-protocol key and a value that matches the FT's address - see example response below)
  • If it exists on Coingecko, save Coingecko ID on Token record
  • Refactor Donation.fetch_usd_prices and PotPayout.fetch_usd_prices to share a single util method (e.g. tokens.utils.fetch_usd_prices_common) that takes a token, an amount, and a timestamp and returns the amount_usd that can be saved to the Donation or PotPayout record. This common method should probably also save the historical token price.
  • When fetching usd prices, use Token.coingecko_id in the request URL instead of Token.id.id. Skip the coingecko request if Token.coingecko_id is None.
  • Add "near" as coingecko_id for existing NEAR native token record (do this together with Lachlan on the EC2 instance)

Motivation

[More detailed explanation of the motivation for the enhancement, including any benefits it would provide]

Description

Here is an example Coingecko response:

[
  {
    "id": "1inch",
    "symbol": "1inch",
    "name": "1inch",
    "platforms": {
      "ethereum": "0x111111111117dc0aa78b770fa6a738034120c302",
      "harmony-shard-0": "0x58f1b044d8308812881a1433d9bbeff99975e70c",
      "avalanche": "0xd501281565bf7789224523144fe5d98e8b28f267",
      "binance-smart-chain": "0x111111111117dc0aa78b770fa6a738034120c302",
      "near-protocol": "111111111117dc0aa78b770fa6a738034120c302.factory.bridge.near",
      "polygon-pos": "0x9c2c5fd7b07e95ee044ddeba0e97a665f142394f",
      "energi": "0xdda6205dc3f47e5280eb726613b27374eee9d130"
    }
  },
  ...
]

Alternatives

Coingecko tokens could alternatively be fetched and added in a recurring job, but this would create many more tokens than are actually used in PotLock, and additionally token metadata would need to be fetched for each token to get its decimals etc. I think a Token.save() method override is a simpler and more targeted solution at this point.

Risks

[Identification and mitigation of any potential risks associated with the enhancement]

Acceptance Criteria

[List of criteria that must be met for the enhancement to be considered accepted]

Additional Information

[Any other relevant information, such as links to related issues or pull requests]

@lachlanglen lachlanglen added the enhancement small enhancement / improvement from existing feature label Jul 16, 2024
@lachlanglen lachlanglen linked a pull request Jul 18, 2024 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement small enhancement / improvement from existing feature
Projects
Status: Done
Development

Successfully merging a pull request may close this issue.

2 participants