Skip to content

fix: implement Reflector oracle as primary price source with CoinGecko fallback#26

Merged
Uchechukwu-Ekezie merged 1 commit into
grantFoxin:mainfrom
balisdev:fix/reflector-oracle-integration
Jun 28, 2026
Merged

fix: implement Reflector oracle as primary price source with CoinGecko fallback#26
Uchechukwu-Ekezie merged 1 commit into
grantFoxin:mainfrom
balisdev:fix/reflector-oracle-integration

Conversation

@balisdev

Copy link
Copy Markdown
Contributor

Summary

  • Implements the advertised Reflector oracle integration in ReflectorService — previously the SorobanRpc import was unused and all prices came exclusively from CoinGecko
  • Adds fetchPricesFromReflector() which uses SorobanRpc.Server.simulateTransaction to call lastprice() on the Reflector contract for each asset and parses the i128 / 10^7-scaled PriceData response
  • Price resolution order is now: Reflector (on-chain) → CoinGecko (fallback for missing assets) → hardcoded fallback
  • Reads REFLECTOR_CONTRACT_ID and SOROBAN_RPC_URL from env; logs a warning on startup if the contract ID is absent so operators know the oracle is inactive
  • Adds both variables (with testnet defaults) to backend/.env.example

Test plan

  • Set REFLECTOR_CONTRACT_ID and SOROBAN_RPC_URL in .env; confirm price responses include "source": "reflector" for assets the oracle returns
  • Unset REFLECTOR_CONTRACT_ID; confirm service falls back to CoinGecko and startup logs the warning
  • Simulate Reflector returning prices for only some assets; confirm CoinGecko fills the rest and the merged response contains all four assets
  • Verify existing CoinGecko rate-limit and hardcoded-fallback paths are unaffected

Closes #8

…o fallback

Resolves the gap between the advertised Reflector oracle integration and
the actual backend behaviour. Previously ReflectorService fetched all
prices exclusively from CoinGecko, leaving the SorobanRpc import unused.

Price resolution order is now:
  Reflector contract (on-chain, via Soroban simulation)
    → CoinGecko (for any assets the oracle did not return)
      → hardcoded fallback (existing behaviour)

Changes:
- Add fetchPricesFromReflector() which uses SorobanRpc.Server to
  simulate a lastprice() call against the Reflector contract for each
  asset and parses the i128/10^7-scaled PriceData response
- Update getFreshPrices() to call Reflector first and only hit CoinGecko
  for assets missing from the oracle response
- Read REFLECTOR_CONTRACT_ID and SOROBAN_RPC_URL from env in constructor
- Add both variables (with testnet defaults) to backend/.env.example

Closes grantFoxin#8
@balisdev balisdev force-pushed the fix/reflector-oracle-integration branch from c1926d9 to 0cfaa73 Compare June 25, 2026 15:07
@Uchechukwu-Ekezie

Copy link
Copy Markdown
Contributor

LGTM

@Uchechukwu-Ekezie Uchechukwu-Ekezie merged commit fdc107c into grantFoxin:main Jun 28, 2026
3 checks passed
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.

bug: ReflectorService fetches prices from CoinGecko only — advertised Reflector oracle integration is not implemented

2 participants