Skip to content

Integrate on-chain price oracle for dynamic invoice funding targets #347

Description

@Kingsman-99

Overview

Add oracle-priced invoices where the funding target is determined at payment time by an external price oracle contract, not fixed at creation. Use case: invoice 100 USD worth of XLM where the XLM/USD rate is fetched from a Stellar oracle at payment time.

Requirements

  • Extend InvoiceOptions with oracle: Option<Address> and oracle_asset_pair: Option<(Symbol, Symbol)>
  • At payment time, if oracle is set, call the oracle contract's price(asset_pair) function via env.invoke_contract and compute the required token amount dynamically
  • Store the oracle address as part of invoice state
  • Emit OraclePriceFetched { invoice_id, rate, computed_amount } event on each payment
  • If the oracle call fails (stale/unavailable), panic with OracleUnavailable
  • Write tests using a mock oracle contract that returns configurable rates
  • Test: oracle price changes between payments; oracle unavailable; oracle returns zero

Acceptance Criteria

  • Oracle integration working end-to-end in tests
  • Mock oracle contract in tests/ used for all test scenarios
  • Oracle failure panics with OracleUnavailable, not a cryptic error
  • All existing tests pass
  • cargo test --workspace passes with zero failures
  • cargo clippy --all-targets -- -D warnings produces zero warnings

Definition of Done

All CI checks must pass before the PR is reviewed.

Metadata

Metadata

Labels

GrantFox OSSIssue tracked in GrantFox OSSMaybe RewardedIssue may be eligible for a GrantFox rewardOfficial CampaignCampaign: Official CampaignOfficial Campaign | FWC26Campaign: Official Campaign | FWC26complexity: highComplex feature requiring deep knowledge - 200 ptsfeatureNew contract feature or operationgrantfoxIssue for GrantFox program

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions