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

implement getNativeAssetPrice #3666

Closed
wants to merge 4 commits into from
Closed

implement getNativeAssetPrice #3666

wants to merge 4 commits into from

Conversation

p0mvn
Copy link
Member

@p0mvn p0mvn commented Aug 3, 2024

This PR implements getNativeAssetPrice, which retrieves prices from the sidecar with no other fallbacks.

This use case helps decouple 90% of the native chain pricing needs while retaining the original abstraction for bridging needs.

Testing

Upon approval, I will request QA.

Copy link

vercel bot commented Aug 3, 2024

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

Name Status Preview Comments Updated (UTC)
osmosis-frontend ✅ Ready (Inspect) Visit Preview 💬 Add feedback Aug 3, 2024 11:03pm
4 Skipped Deployments
Name Status Preview Comments Updated (UTC)
osmosis-frontend-datadog ⬜️ Ignored (Inspect) Aug 3, 2024 11:03pm
osmosis-frontend-dev ⬜️ Ignored (Inspect) Aug 3, 2024 11:03pm
osmosis-frontend-edgenet ⬜️ Ignored (Inspect) Aug 3, 2024 11:03pm
osmosis-testnet ⬜️ Ignored (Inspect) Aug 3, 2024 11:03pm

Comment on lines +19 to +35
/** Finds the fiat value of a single unit of a given asset denominated in USDC.
* Assets can be identified either by `coinMinimalDenom`.
* @throws if the coinMinimalDenom is not given or fails to fetch the price from data source */
export async function getNativeAssetPrice(
coinMinimalDenom: string
): Promise<Dec> {
if (!coinMinimalDenom) {
throw new Error("coinDenom is required");
}

return cachified({
key: `asset-price-nat-${coinMinimalDenom}`,
cache: pricesCache,
ttl: 1000 * 10, // 10 seconds
getFreshValue: () => getPriceFromSidecar(coinMinimalDenom),
});
}
Copy link
Member Author

@p0mvn p0mvn Aug 3, 2024

Choose a reason for hiding this comment

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

@jonator instead of doing the factory pattern that we discussed, I simply introduced another helper that handles native pricing to decouple the logic and simplify the majority of the chain use-cases while keeping the abstraction necessary for bridging.

Base automatically changed from roman/remove-source-denom to roman/remove-pools-prices August 5, 2024 06:12
Base automatically changed from roman/remove-pools-prices to stage August 18, 2024 01:22
@jonator jonator closed this Oct 8, 2024
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.

2 participants