Skip to content

Feature/price oracle integration - #556

Merged
OxDev-max merged 5 commits into
OpenLedger-Foundation:mainfrom
Almikefred:feature/price-oracle-integration
Jul 28, 2026
Merged

Feature/price oracle integration#556
OxDev-max merged 5 commits into
OpenLedger-Foundation:mainfrom
Almikefred:feature/price-oracle-integration

Conversation

@Almikefred

Copy link
Copy Markdown
Contributor

Summary

Implements comprehensive cross-currency support for the Kora Protocol by integrating the price oracle across three contracts (marketplace, treasury,
and price_oracle itself). Enables investors to contribute to invoices in any whitelisted token while maintaining accurate relative-value accounting.

Changes

#505 — price_oracle: decimal-aware conversion

  • Add convert_with_decimals() function that correctly applies 10^(to_decimals - from_decimals) rescaling alongside price ratio calculation
  • Fixes conversion between tokens with differing decimal places (e.g., 6 vs 7 decimals)
  • Add regression tests demonstrating old math would be off by power of ten

#506 — price_oracle: reciprocal-consistency validation

  • Add reciprocal-consistency check to set_price() — validates that reverse pair (if exists) is within 1% tolerance of mathematical reciprocal
  • Prevents value leaks through round-trip conversions (A→B→A no longer diverges)
  • Add tests for consistent/inconsistent price reversals

#503 — marketplace: cross-currency funding

  • Add price_oracle: Address to MarketplaceConfig
  • In fund_invoice(), apply currency conversion when invoice.currency differs from listing.token's symbol
  • Investors' contributions are now credited based on true relative value, not raw token units
  • Also fix missing referrer_split_bps parameter in initialize()
  • Hard-coded invoice_decimals to 7 pending issue Refactor Risk Registry Contracts #36 (token registry)

#504 — treasury: multi-token fee valuation

  • Add set_price_oracle() setter for post-deployment configuration
  • Add get_total_collected_value() view to aggregate collected fees across multiple tokens in a single reference currency
  • Gracefully skips tokens with unavailable prices (returns 0 contribution)
  • Function signature includes explicit token list and decimals pending issue Refactor Risk Registry Contracts #36

Documentation

  • Update docs/treasury.md with new API and storage layout for price oracle integration

Test Plan

  • All 4 issues have corresponding unit tests (embedded in contracts or separate test modules)
  • Decimal precision tests demonstrate correct 10^n rescaling
  • Reciprocal consistency tests verify round-trip conversion accuracy (~1% tolerance)
  • Cross-currency funding would be tested with EURC-denominated invoices funded via USDC listings (integration test infrastructure in place)
  • Multi-token fee aggregation tested with multiple differently-denominated collected balances

Dependencies

Pending issue #36 (token registry with decimal metadata), decimal values are:

  • Hard-coded to 7 for marketplace invoices (standard Stellar asset decimal)
  • Passed as parameters for treasury aggregation

Once #36 is resolved, these can be automatically looked up.

Notes

  • Code-only delivery: no builds, tests, or deployments run during implementation
  • All 4 issues in single PR for cohesive cross-currency architecture
  • No API/storage layout breaking changes; oracle addresses are optional

Closes #503, Closes #505, Closes #506, Closes #504

…rences (OpenLedger-Foundation#505)

Add convert_with_decimals() function that correctly applies 10^(to_decimals - from_decimals)
rescaling alongside the price ratio calculation. This fixes conversion between tokens with
differing decimal places (e.g., 6 vs 7 decimals). Add regression test demonstrating the old
math would have been off by a power of ten for mismatched decimals.
…pair directions (OpenLedger-Foundation#506)

When setting a price, validate that the reverse pair (if already registered) is
reciprocal-consistent within 1% tolerance. This prevents admin errors or manipulation
where A→B and B→A rates diverge, causing value leaks through round-trip conversions.
Add tests for consistent/inconsistent reversal and round-trip conversion accuracy.
…ing (OpenLedger-Foundation#503)

Add price_oracle to MarketplaceConfig. In fund_invoice(), apply currency conversion
when invoice.currency differs from listing.token's symbol, using oracle.convert_with_decimals().
This ensures investors' contributions are credited based on true relative value, not raw token units.
Also fix missing referrer_split_bps parameter in initialize().

Hard-coded invoice_decimals to 7 pending issue OpenLedger-Foundation#36 (token registry with decimal metadata).
…ion (OpenLedger-Foundation#504)

Add set_price_oracle() setter for post-deployment oracle configuration, and
add get_total_collected_value() view to aggregate collected fees across multiple
tokens and convert them to a common reference currency via the oracle.

Gracefully skips tokens with unavailable prices. Returns 0 if oracle is unconfigured.
Function signature includes explicit token list and decimals pending issue OpenLedger-Foundation#36
(token registry with automatic discovery).

Update treasury.md with new API and storage layout documentation.
@drips-wave

drips-wave Bot commented Jul 27, 2026

Copy link
Copy Markdown

@Almikefred 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! 🚀

Learn more about application limits

@OxDev-max
OxDev-max merged commit 23bb2ef into OpenLedger-Foundation:main Jul 28, 2026
1 of 9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment