-
Notifications
You must be signed in to change notification settings - Fork 423
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
Conversation
The latest updates on your projects. Learn more about Vercel for Git ↗︎
4 Skipped Deployments
|
/** 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), | ||
}); | ||
} |
There was a problem hiding this comment.
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.
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.