/** * @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 { FeePolicy, Recipient } from './contract.js'; /** * The built-in {@link FeePolicy}: a fixed fee rate for every sale, taken from `input.feeBps` * (the spend handler passes `config.platformFeeBps`). * * The policy returns the credit side of the sale only; the spend handler adds the buyer's * matching debit, which zeroes the posting. The fee comes off the top, rounded up to a whole * credit and capped at the price. The net divides among `recipients` by `shareBps`, each share * rounded down, and the platform revenue credit takes the fee plus the rounding leftover, so * the legs always sum to the full price and no minor unit of the sale is lost. Recipient * shares must sum to 10000 basis points; any other total throws MALFORMED_OPERATION. An empty * recipient list is allowed and sends the whole net to revenue. * * @example * const policy = flatFee(); * const legs = policy({ price: toAmount('CREDIT', 1000n), feeBps: 3000, * recipients: [{ sellerId: 'usr_seller', shareBps: 10000 }] }); * // Price 1000 with a 30% fee credits the seller 700 and revenue 300. Both are * // credits, stored negative, so the lines sum to -1000, the full price. * * @see {@link https://economy-lab-docs.pages.dev/economy/ports/pricing/ Pricing} for how fee * policies split a sale into ledger lines. */ export declare function flatFee(): FeePolicy; /** * Returns the platform's actual revenue from splitting `price` among `recipients` at `feeBps`. * That revenue is the fee plus the residual left by rounding each seller's share down, which is * exactly the amount splitLegs credits to REVENUE. spend.ts records this as `Sale.fee` rather * than the bare `feeForPrice`, so the recorded fee equals what REVENUE actually kept even on an * uneven split, where the residual is non-zero. On an even split the residual is zero, so the * result is just the fee and the simple case is unchanged. */ export declare function revenueForSplit(price: Amount, recipients: ReadonlyArray, feeBps: number): bigint; /** * Returns the platform fee for a price, in minor units, rounded up to a whole credit, then capped at * the price so the fee never exceeds what was paid (the cap only matters below one whole credit). The * leftover line in splitLegs absorbs the difference between the exact and rounded fee. * * This is the single source for the transaction fee, called by every charge that takes one (sale, * subscription first month, renewal), so no caller re-derives a floor that would disagree when the * raw fee is not a whole credit. */ export declare function feeForPrice(minor: bigint, bps: number): bigint;