Wakeless

Relationship terms

Status: experimental, devnet alpha, unaudited. Behind RELATIONSHIP_TERMS=false by default; with the flag off the vendor middleware is byte-for-byte what it was before this layer existed.

This file is generated by pnpm terms:doc from packages/vendor/src/terms/doc.ts on 2026-11-08; every number in the worked table comes from running terms(). Edit the generator, not the file.

What it is

The vendor middleware quotes each buyer from the vendor's own private history with that buyer. Same route, same job, two buyers, two sets of terms; the ledger sees neither. The layer sets the two terms x402 already carries: the price (amount in the accepts[] entry) and the funding requirement (extra.minDeposit). Reputation isn't a number here. It's a price.

Identity

The buyer is the channel's buyer address, channelConfig.buyer. A fresh address is an unknown buyer and gets standard terms. Nothing in the layer may make an unknown buyer's terms better than standard, so rotating addresses can never buy a discount; it can only forfeit relationship capital. A property test (packages/vendor/test/terms/terms.test.ts, "an unknown buyer is never better than standard") holds this over random histories.

History, per vendor, private

A clean period is a redeemed period with nothing left owed: relationship capital grows by 250 bps per clean period up to 2500 bps. Two incidents exist: close_with_unpaid (a channel closed or idle-closed while something was owed after the grace period, 2000 bps) and repeated_exceeds_deposit (three or more corrective 402s for a cumulative above the deposit in one period, 1000 bps). Incidents stay active in v1; there is no rehabilitation and no retirement ledger. The funding requirement is 20 calls' worth of the price for an unknown buyer, falls by one call per 125 bps of capital to a floor of 5, and is 50 calls with any active incident.

The store (packages/vendor/src/terms/history.ts) is keyed by buyer address and lives with the vendor, in memory or in one JSON file ({version, buyers}, mode 0600, written atomically). It is fed by three things the vendor already sees: its own middleware's /verify outcomes (corrective 402s for invalid_batch_settlement_svm_cumulative_exceeds_deposit, counted per period), the facilitator receipts the vendor reads (GET /receipts/:channelId with GET /admin/channels, task 7.3) and a close or idle-close that left something owed after the grace period. The facilitator does not compute, store or see terms: the entry forwarded to /verify and /settle has the terms receipt stripped. Other vendors never see it. Nothing of it is written to chain or to clientRefId.

Policy terms@1

const CAPITAL_PER_CLEAN_PERIOD = 250;   // bps
const CAPITAL_CAP = 2500;               // bps
const PREMIUM_BPS = { close_with_unpaid: 2000, repeated_exceeds_deposit: 1000 };
const FUNDING_CALLS = { standard: 20, floor: 5, incident: 50 };

function terms(standardPrice: bigint, active: Incident[], capitalBps: number): Terms {
  const premiumBps = active.reduce((a, i) => a + PREMIUM_BPS[i.kind], 0);
  const price = standardPrice
              + standardPrice * BigInt(premiumBps) / 10000n
              - standardPrice * BigInt(capitalBps) / 10000n;
  const fundingCalls = active.length
    ? FUNDING_CALLS.incident
    : Math.max(FUNDING_CALLS.floor, FUNDING_CALLS.standard - Math.floor(capitalBps / 125));
  return { price, minDeposit: price * BigInt(fundingCalls), fundingCalls, premiumBps, capitalBps, policy: "terms@1" };
}

A pure function with table-driven tests; no model touches a number. The policy id never shares a number with a document revision.

Worked table, standard price 0.010000 USDC

HistoryRelationship capital (bps)Risk premium (bps)Price (USDC)Funding requirement (calls)minDeposit (USDC)
unknown buyer (or a rotated address)000.010000200.200000
one clean period25000.009750180.175500
three clean periods75000.009250140.129500
seven clean periods175000.00825060.049500
ten clean periods (the cap)250000.00750050.037500
twenty clean periods (still the cap)250000.00750050.037500
one close_with_unpaid020000.012000500.600000
one repeated_exceeds_deposit010000.011000500.550000
seven clean periods, then one close_with_unpaid175020000.010250500.512500
both incidents, no clean period030000.013000500.650000

The terms receipt

With the flag on, the shielded accepts[] entry carries the buyer's price as amount, the funding requirement as extra.minDeposit, and extra.termsReceipt:

{ standardPrice, adjustments: [{ label, bps, amount, evidence }], price, minDeposit, fundingCalls, policy: "terms@1", inputsDigest, vendorSignature }

label is one of risk premium and relationship capital; inputsDigest is 0x + sha256 of the canonical JSON of the inputs (buyer, standard price, clean periods, incidents, policy), so the buyer can reproduce the quote; vendorSignature is Ed25519 by the vendor's payTo key over 0x54 0x01 || sha256(canonical JSON of the unsigned receipt). The buyer keeps it; a vendor cannot later claim it quoted differently. Relationship capital appears only as a line on this receipt, with its evidence, at the moment it changes a term: never as a standing balance, badge or tier.

How the terms reach the buyer

The first request of an x402 exchange carries no payment and so no buyer, and the 402 that answers it quotes the standard terms with a receipt for an unknown buyer. The buyer is known from its first PAYMENT-SIGNATURE (channelConfig.buyer). When that buyer's terms differ from what it paid against, the middleware answers 402 shielded_terms_quoted with the buyer's entry and its signed receipt, and asks no facilitator; the buyer pays once more against that entry. A buyer whose terms are standard pays on the first try, as before.

The plan said the client wrapper already honoured minDeposit and needed no change. Half true: wrapFetchWithWakeless honoured extra.minDeposit from a corrective 402 but kept the price from the first 402, and the first 402 cannot carry a buyer's terms because the first request carries no buyer. The wrapper therefore changed in two places (packages/client/src/wrap.ts, docs/DEVIATIONS.md): it pays against the terms this vendor last quoted when its channel record carries a terms receipt and the fresh 402's entry differs only in price and funding requirement, and on 402 shielded_terms_quoted it adopts the quoted entry's amount, minDeposit and receipt, runs the beforePayment spend policy again at the quoted price, and pays once more, never a third time. With the flag off no entry carries a receipt and no vendor answers that code, so the wrapper behaves as before; pnpm e2e and the client tests are unchanged.

Briefing question 13: does a per-buyer amount break a stock client?

No. Checked against vendor/x402/typescript/packages/core/src/client/x402Client.ts (checkout e208bd3): createPaymentPayload selects from the accepts[] of each 402 as it arrives (selectPaymentRequirements, line 545) and the client keeps no price per route between requests; the HTTP client re-reads every 402. x402 prices are per response, so a per-buyer amount is a shape the stock client already handles. A stock client cannot pay a batch-settlement-shielded entry in any case (it registers no scheme for it), so the question is about the shape, and the shape is the specification's. The one client that did cache was Wakeless's own wrapper, which read the price from the first 402 and kept it through the corrective 402; the task changed it (below).

Honest limits

A buyer can abandon a bad history by rotating to a new address and paying standard terms; the layer prices risk, it does not prevent exit. Relationship capital is not portable between vendors by design. The vendor could always have set terms arbitrarily; the layer makes the policy explicit, evidenced and reproducible. In v1 the facilitator sees every voucher, so the facilitator could reconstruct a vendor's buyer history from amounts and timing; the privacy claim remains against the public ledger (three operators see inside in v1: the facilitator, MagicBlock's enclave and NEAR's private shard), and the terms layer inherits that boundary. Incidents never retire in v1. The vocabulary is locked (docs/VOCABULARY.md) and a test fails the build on the words it forbids.

On this page