DomainTreasury

interface DomainTreasury

The domain-scoped on-chain payment authority. Owns:

Lifecycle of a single operation:

  1. account(chainId).estimateFee(op) → est

  2. reserve(ctx, est) → Reservation (funds locked)

  3. plugin submits the tx → AnchorResult(fee, payerAddress)

  4. settle(reservation, result) → reservation closed — or cancel(reservation) on failure

Implementations must serialise reservations per ChainAccount (nonce management is the plugin's responsibility but the reservation queue prevents two writes from oversubscribing a tight balance).

Inheritors

Properties

Link copied to clipboard
abstract val domainId: DomainId

Functions

Link copied to clipboard
abstract suspend fun account(chainId: String): ChainAccount?
Link copied to clipboard
abstract suspend fun accounts(): List<ChainAccount>
Link copied to clipboard
abstract suspend fun cancel(reservation: Reservation)

Release the reservation in full. Used on submission errors before any fee is incurred, and by the TTL sweeper for expired reservations.

Link copied to clipboard
abstract fun ledger(): TreasuryLedger

Read view over the audit ledger.

Link copied to clipboard
abstract suspend fun policy(): SpendPolicy
Link copied to clipboard
abstract suspend fun reserve(ctx: PaymentContext, estimate: TokenAmount): Reservation

Lock estimate × safety margin against the ChainAccount for ctx.chainId. Throws org.trustweave.anchor.exceptions.TreasuryException subclasses on policy violation or insufficient funds — never on a recoverable mempool condition (that's the plugin's concern).

Link copied to clipboard
abstract suspend fun settle(reservation: Reservation, result: AnchorResult, success: Boolean = true)

Commit a reservation against the actual fee reported in result. Releases the (typically smaller) delta back to the available balance and appends the terminal SETTLED (or FAILED if success is false) entry to the ledger.