@pwngh/economy-lab
    Preparing search index...

    Variable topUpConst

    topUp: (
        fields: FieldsOf<K>,
    ) => {
        actor: Principal;
        amount: Amount;
        idempotencyKey: string;
        kind: "topUp";
        source: string;
        userId: string;
    } = ...

    Builds a topUp operation: a buyer's cleared cash becomes spendable credit. On commit it credits the user's spendable account against STORED_VALUE, and a second posting books the backing USD into TRUST_CASH at par with the buy-vs-par spread recognized in REVENUE_USD — the USD paid is derived from the CREDIT-to-USD buy rate, never passed in. The source selects the new credits' maturity horizon; an unrecognized source falls back to the long default. With a purchase catalog configured, an off-catalog amount faults OP.MALFORMED. Restricted to a system or operator actor — an end user can never mint credit — and it rejects only with RISK_DENIED when the user's recent top-up volume crosses the velocity window. A retried submit under the same idempotencyKey returns the original transaction as duplicate.

    Type Declaration

      • (
            fields: FieldsOf<K>,
        ): {
            actor: Principal;
            amount: Amount;
            idempotencyKey: string;
            kind: "topUp";
            source: string;
            userId: string;
        }
      • Parameters

        • fields: FieldsOf<K>

        Returns {
            actor: Principal;
            amount: Amount;
            idempotencyKey: string;
            kind: "topUp";
            source: string;
            userId: string;
        }

    const outcome = await economy.submit(topUp({
    idempotencyKey: idempotencyKey('purchase', 'evt_5521'),
    actor: systemActor('payments'),
    userId: 'usr_buyer',
    amount: toAmount('CREDIT', 60_000n), // 600 credits
    source: 'card',
    }));