feat(oracle): add exchange rate oracle for real-time fiat value conversion#278
Merged
0xDeon merged 1 commit intoSuncrest-Labs:mainfrom Apr 23, 2026
Conversation
…rsion (Suncrest-Labs#211) New oracle package (apps/api/internal/oracle/) with: - In-memory TTL cache (30s crypto / 5min fiat) with stale-while-serve fallback - Stellar Horizon order book provider for XLM/USD mid-market rate - DeFiLlama fallback for XLM/USD when Horizon is unavailable - open.er-api.com (key-free) forex provider for USD→NGN/GHS/KES/USD - RateService that chains providers with priority fallback and serves stale cached data (Stale: true) when all live sources fail New endpoint: GET /api/v1/rates?base=USDC"e=NGN Supported pairs: USDC→NGN, USDC→GHS, USDC→KES, USDC→USD, XLM→USD 14 unit tests covering cache freshness, stale fallback, provider fallback chain, cache hit bypass, and all supported pair types.
|
@Salmatcre8 Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits. You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #211
Summary
apps/api/internal/oracle/package with five files:rate.go(types/errors),cache.go(TTL cache),stellar.go(Horizon order book),defillama.go(DeFiLlama fallback),fiat.go(open.er-api.com forex),service.go(aggregation + fallback)GET /api/v1/rates?base=USDC"e=NGNreturning{ base, quote, rate, source, fetched_at, expires_at, stale? }USDC→NGN,USDC→GHS,USDC→KES,USDC→USD(fixed 1.0),XLM→USDCaching / resilience
stale: truestale: trueProvider priority for XLM/USD: Stellar Horizon → DeFiLlama. No API key is required for any source.
Test plan
cache_test.go): miss, store/retrieve, freshness before/after expiry, overwrite, independent keysservice_test.go): fixed USDC/USD, unsupported pair error, XLM fallback chain, stale serve on all-fail, no-cache error path, fiat provider, fiat stale fallback, cache-hit skips providersGOOS=linux go build ./...— clean buildResponse shape
{ "success": true, "data": { "base": "USDC", "quote": "NGN", "rate": 1647.50, "source": "forex", "fetched_at": "2026-04-23T12:00:00Z", "expires_at": "2026-04-23T12:05:00Z" } }