Skip to content

feat: add oracle-priced invoices with payment-time dynamic funding ta…#357

Merged
Kingsman-99 merged 3 commits into
Stellar-split:mainfrom
lemarjohnny781:feat/oracle-priced-invoices
Jul 24, 2026
Merged

feat: add oracle-priced invoices with payment-time dynamic funding ta…#357
Kingsman-99 merged 3 commits into
Stellar-split:mainfrom
lemarjohnny781:feat/oracle-priced-invoices

Conversation

@lemarjohnny781

@lemarjohnny781 lemarjohnny781 commented Jul 24, 2026

Copy link
Copy Markdown

Summary
Implemented oracle-priced invoices across contracts/split/src/{types.rs, error.rs, events.rs, lib.rs, test.rs}:

InvoiceOptions: added oracle: Option
and oracle_asset_pair: Option<(Symbol, Symbol)>.
Invoice state: added the same two fields to InvoiceExt2/Invoice, threaded through split()/assemble()/from_legacy(), all 8 _create_invoice_inner call sites, the clone-invoice path, and all 5 storage-fallback constructors.
Pricing logic (_pay): when oracle is set, amounts is treated as the fixed USD-cents funding target (e.g. "$100 worth of XLM"). Each payment calls the oracle's price(asset_pair) via env.try_invoke_contract (not the panicking invoke_contract, so a trap/error is caught rather than propagating a raw host error), recomputes total = usd_cents_target * ORACLE_RATE_SCALE / rate, and emits OraclePriceFetched. A non-positive or unreachable rate panics with "OracleUnavailable".
Validation: create_invoice rejects oracle without oracle_asset_pair, and rejects setting both oracle and the pre-existing price_oracle together.
Error taxonomy: added ContractError::OracleUnavailable (discriminant 21) for documentation parity, though the actual panic uses the string-message convention this codebase uses everywhere else (no code path here uses ContractError directly).
Tests (contracts/split/src/test.rs): a MockConfigurableOracle (settable rate, defaults to 0) and MockTrapOracle (always panics), covering: oracle address stored on the invoice, missing-asset-pair validation, price changing between two payments (rate doubles, target halves, second payment now completes the invoice), the OraclePriceFetched event firing, oracle-unavailable panic, and zero-rate panic.

closes #348

Olisachukwuma1 and others added 3 commits July 24, 2026 01:55
…rget

Adds InvoiceOptions.oracle / oracle_asset_pair so an invoice's funding
target (e.g. "$100 worth of XLM") is computed at payment time from a
live oracle price rather than fixed at creation. Each pay() call fetches
the rate via try_invoke_contract (so a stale/unreachable oracle panics
with a clean "OracleUnavailable" instead of a raw host error) and emits
OraclePriceFetched. Covered by mock-oracle tests for changing prices
between payments, oracle unavailability, and a zero rate.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Extends the existing issue Stellar-split#23 graduated-release Tranche infrastructure
with release_tranche(invoice_id, tranche_index), which lets any caller
trigger a single tranche once its timestamp is reached, gated on the
invoice being fully funded and the tranche not already released (tracked
via a per-invoice released-index bitmask). Shares the released_bps
counter with the existing bulk release() path so the two release
mechanisms can't double-pay the same invoice. Emits TrancheReleased.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
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.

Implement multi-tranche release schedule with configurable cliff period

3 participants