/** * @pwngh/economy-lab * * Copyright (c) Preston Neal * * This source code is licensed under the MIT license found in the * LICENSE.md file in the root directory of this source tree. * * @license MIT */ import type { Amount } from '../money.js'; import type { Ctx, Operation, Outcome } from '../contract.js'; import type { Unit } from '../ports.js'; /** * How a payment splits across the buyer's two balances: promo (marketing-grant) first, remainder * from spendable. */ export type SpendPlan = { promoPart: Amount; spendablePart: Amount; }; /** * The pipeline's pre-claim probe, run before any lock or screen: a committed sale row is final * (sales are never deleted), so a replayed orderId rejects here without paying for the locks it * will never need. A miss falls through to the authoritative under-lock check in the handler. */ export declare function spendPreClaim(operation: Operation, unit: Unit): Promise; /** * Run a marketplace purchase: charge the buyer and pay the sellers as one balanced * ledger posting. Buyer pays from promo (marketing-grant) balance first, then spendable. A sale * summary is saved under `orderId` so a later refund can reverse exactly what posted, and the SKU * entitlement is granted in the same transaction so paying always confers ownership (to the buyer, * or to `giftTo` when present). A second request reusing an `orderId` already on file is refused * with `DUPLICATE_ORDER` so the buyer is never double-charged for one order. * * The submit pipeline has already authorized, deduplicated, checked affordability, and locked the * accounts; this only validates its own inputs and posts. Malformed input (bad price, shares that * don't sum) throws a fault, not a refusal. * * @see {@link https://economy-lab-docs.pages.dev/economy/reference/operations/spend/ Spend} for the * purchase flow, balance draw order, and split accounting this handler posts. */ export declare function spend(operation: Operation, unit: Unit, ctx: Ctx): Promise; /** * Split the price across balances: take as much as possible from promo first (capped at the * price), charge the remainder to spendable. The one implementation of the rule — the submit * pipeline's funds screen (economy.ts) and the subscribe handler import it, so the up-front check * and every posting agree on the split. */ export declare function planSpend(price: Amount, promoBalance: Amount): SpendPlan;