feat: add oracle-priced invoices with payment-time dynamic funding ta…#357
Merged
Kingsman-99 merged 3 commits intoJul 24, 2026
Merged
Conversation
…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>
7 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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