Settlement
Concepts

Settlement

Atomic two-step settlement engine guaranteeing simultaneous fund transfer.

Settlement is the atomic heart of SplitPay. In a single blockchain transaction, client funds are transferred into the contract and disbursed to each member in the exact proportions configured.

Atomic Settlement Mechanism

Atomicity means all-or-nothing: either all recipients receive their funds and all distribution receipts are persisted, or the entire transaction reverts and no tokens change hands.

Settlement Engine Steps

  1. Payer Authorization: payment.payer.require_auth() ensures only the designated payer (or authorized signer) can release funds.
  2. Total BPS Validation: Re-validates that total member shares equal exactly 10,000 BPS at the moment of settlement.
  3. Integer Split Calculation: Multiplies gross amount by member BPS and divides by 10,000, adding remainder to member 0.
  4. Token Inflow: Invokes token::Client::transfer from payer to contract address.
  5. Token Outflows: Dispatches transfers from contract address to each member address.
  6. Receipt Storage: Stores individual Distribution structs in persistent contract storage.
  7. Event Publication: Emits payment_settled and distribution_created events.

Reversion & Failure Handling

If the payer lacks sufficient balance or asset trustlines, or if any transfer fails, the Soroban runtime halts execution and rolls back all ledger footprint changes. Funds are never lost or partially stuck inside the contract.