Skip to content

feat(hermes): Add ignore_invalid_price_ids flag to Hermes v2 REST APIs #2091

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

Merged
merged 14 commits into from
Nov 6, 2024

Conversation

tejasbadadare
Copy link
Contributor

@tejasbadadare tejasbadadare commented Nov 4, 2024

Purpose

Today when a user requests latest price updates with a list of price_ids, the request returns an error if any of those IDs is non-existent. Since price feeds come and go, some protocols want different behavior to avoid 404s when a price feed is delisted. The fix is to provide a ignore_invalid_price_ids flag (default false) to the v2 APIs that ignores invalid provided price IDs and only returns data for the valid ones. This only applies to the v2 REST APIs (not websockets), which will continue to reject a subscription request that contains invalid price IDs.

Implementation details

  • The price ID validation is currently done by the rest::verify_price_ids_exist(state, price_ids) function, which is used by both deprecated v1 APIs and v2 APIs.

  • This PR modifies the function to something like validate_price_ids(state, price_ids, remove_invalid) -> valid_price_ids. Now the function returns a Vec of valid IDs that the caller can operate on.

    • If remove_invalid is true (sourced from params.ignore_invalid_price_ids for v2 APIs, and always false for v1 APIs), then the resulting Vec won't contain any invalid price IDs.
    • If remove_invalid is false and there are invalid IDs in the passed in price_ids, then an Error will be returned, just like the original function would.
  • I took this approach to minimize disruption to the existing codebase, since the APIs are written in a way that expects the code to return early if verify_price_ids_exist returns an Error. With the new validate_price_ids function, downstream code can always operate on the resulting list without worrying about invalid IDs, like before.

  • Updated HermesClient.ts to reflect the new param.

  • Misc: Fixed some small gotchas I encountered following the setup guide in the README

Testing

Created unit tests for validate_price_ids

Copy link

vercel bot commented Nov 4, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
api-reference ✅ Ready (Inspect) Visit Preview 💬 Add feedback Nov 6, 2024 6:18pm
proposals ❌ Failed (Inspect) Nov 6, 2024 6:18pm
staking ✅ Ready (Inspect) Visit Preview 💬 Add feedback Nov 6, 2024 6:18pm
2 Skipped Deployments
Name Status Preview Comments Updated (UTC)
component-library ⬜️ Ignored (Inspect) Visit Preview Nov 6, 2024 6:18pm
insights ⬜️ Ignored (Inspect) Visit Preview Nov 6, 2024 6:18pm

@tejasbadadare tejasbadadare changed the title Add ignore_invalid_price_ids flag to Hermes v2 APIs Add ignore_invalid_price_ids flag to Hermes v2 HTTP APIs Nov 4, 2024
@tejasbadadare tejasbadadare changed the title Add ignore_invalid_price_ids flag to Hermes v2 HTTP APIs Add ignore_invalid_price_ids flag to Hermes v2 REST APIs Nov 4, 2024
@tejasbadadare tejasbadadare changed the title Add ignore_invalid_price_ids flag to Hermes v2 REST APIs feat(hermes): Add ignore_invalid_price_ids flag to Hermes v2 REST APIs Nov 6, 2024
Copy link
Contributor

@cctdaniel cctdaniel left a comment

Choose a reason for hiding this comment

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

you need to bump the version here otherwise when you release a new version it will fail

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

Successfully merging this pull request may close these issues.

4 participants