Skip to content

XLM-to-Fiat Price Oracle Adapter #522

Description

@Kingsman-99

Description

Invoice amounts are typically denominated in fiat (USD, EUR, GBP), but Stellar payments use XLM or Stellar assets. The SDK has no standardised price oracle adapter, leaving each integrator to implement their own fiat-to-XLM conversion. A pluggable oracle adapter interface should define a standard PriceOracleAdapter contract and ship a default implementation backed by a configurable public price API.

Technical Context

Add src/priceOracle.ts. Define PriceOracleAdapter interface in src/types.ts with getPrice(base: string, quote: string): Promise<number>. Default implementation uses the CoinGecko /simple/price REST endpoint via fetch. Integrates with src/currencyConverter.ts and src/rateCache.ts. Config accepts a custom priceOracle implementation via StellarSplitConfig.

Acceptance Criteria

  • PriceOracleAdapter interface is exported from src/index.ts so callers can supply custom implementations
  • Default CoinGeckoPriceOracle fetches XLM/USD, XLM/EUR, and any base/quote pair dynamically
  • src/currencyConverter.ts uses the oracle adapter when computing fiat-to-asset amounts
  • Oracle adapter results are cached via src/rateCache.ts with a configurable TTL
  • Unit tests mock the fetch call and assert that: a successful response returns the correct rate, a 429 response throws RateLimitError from src/errors.ts
  • All CI checks (npm test, npm run build, ESLint/TypeScript) pass and the branch has no merge conflicts

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions