@inversealtruism/cairnx-core 0.2.7 → 0.2.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CONVENTION.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # CairnX Convention v1
2
2
 
3
- **Status:** v2.9 (normative; v2.9 activated at `V29_HEIGHT` = 88 000, crossed 2026-08-31, see §32; v2.8 activated at 60 000, crossed 2026-07-23; supersedes the 2026-06-10 v1.0 draft; §33 to §40 carry no gate and move no state) · **Domain:** `cairnx:v1` · **Base activation:** 29 860
3
+ **Status:** v2.9 (normative; v2.9 activated at `V29_HEIGHT` = 88 000, crossed 2026-08-31, see §32; v2.8 activated at 60 000, crossed 2026-07-23; supersedes the 2026-06-10 v1.0 draft; §33 to §41 carry no gate and move no state) · **Domain:** `cairnx:v1` · **Base activation:** 29 860
4
4
 
5
5
  **Version ladder** (each gate non-retroactive: below it, behavior + canonical hashes are byte-identical to history):
6
6
  v1.1 @ 29 960 · v1.2 @ 30 300 · v1.3 @ 31 100 · v1.4 @ 31 400 · v1.5 @ 32 000 · v1.6 @ 33 600 (§19) ·
@@ -10,8 +10,8 @@ v2.3 @ 52 000 (§26) · v2.8 @ 60 000 (§31) · v2.9 @ 88 000 (§32; its replay
10
10
  Sections §19–§32 are the normative semantics for v1.6–v2.9; §5.1 is the byte-level canonical-JSON contract that binds all of them.
11
11
  §33 is the rule that turns the chain's blocks into the events every version replays; §34 defines the two hashes
12
12
  replicas compare. §35 and §36 are for other applications (their domains, the profile-key registry), §37 states what
13
- a result proves, §38 how a replica conforms, §39 how the rules change and §40 the reason codes of the applied log
14
- and of record validation; none of §33 to §40 has a gate.
13
+ a result proves, §38 how a replica conforms, §39 how the rules change, §40 the reason codes of the applied log
14
+ and of record validation and §41 the token moves of the applied log; none of §33 to §41 has a gate.
15
15
  Activation order is by HEIGHT, not by version number (v1.8 activated after v2.0; v2.3 activates after v2.4–v2.7): a
16
16
  replayer gates each rule on its own height constant, never on "version X implies version Y is active".
17
17
 
@@ -72,10 +72,13 @@ signatures in v1: anchoring *from your key* is the authorization.
72
72
 
73
73
  ## 3. Common rules
74
74
 
75
- - **Amounts** are strings of decimal integers in base units, `"1"` ≤ x < `2^96`. Resolvers use
76
- arbitrary-precision integers. `decimals` (0–8) is display-only.
75
+ - **Amounts** are strings of decimal integers in base units, `"1"` ≤ x < `2^96`, except an offer's price: its
76
+ `want.value` (§4.4) and its `want.amount` (§11) may be `"0"`. Resolvers use arbitrary-precision integers.
77
+ `decimals` (0–8) is display-only.
77
78
  - **Tickers** match `^[A-Z][A-Z0-9]{2,11}$`.
78
79
  - **Addresses** are `0x` + 40 lowercase hex.
80
+ - **Hashes and ids in records** (`ncommit`'s `commit`, `tmeta`'s `hash`, an offer's `bid`, an `fclaim`'s `offer`) are
81
+ `0x` + 64 lowercase hex (`HASH_RE`); any other form makes the record an invalid no-op (`RECORD_BAD_HASH`).
79
82
  - **Apply order:** events are replayed in consensus order: by block height; within a block,
80
83
  all `cairnx:v1` proposals in tx order (`pos`), then all attestations on CairnX proposals in tx
81
84
  order (the events of §33). (Mirrors the node’s propose/attest phases, C5.) Remaining ties (same height, phase, pos:
@@ -151,7 +154,7 @@ CairnX meaning for deploys. The **deployer** is the anchoring proposer.
151
154
  - `taker` (optional): if present, only this address can fill. **Taker-bound offers are the
152
155
  protected path** (see §6).
153
156
  - The anchoring proposal's **`expires_epoch` is the offer's validity window**: after it, the
154
- chain itself rejects fill attempts (C5), and the resolver releases the lock. Offers SHOULD
157
+ chain itself rejects fill attempts (C5), and the resolver releases the lock (the expiry sweep of §5). Offers SHOULD
155
158
  use short windows (e.g. tip-epoch + 24 ≈ 1 day).
156
159
  - An offer is identified by its **proposal id (txid)**.
157
160
  - `memo` (64 UTF-16 units max) and `ts` are optional free fields with the same rules as
@@ -190,18 +193,49 @@ extension shipped at v1.7 (height 34 000) and uses **`score = 50`** (`SCORE_CLAI
190
193
  ## 5. Resolver state (normative output)
191
194
 
192
195
  ```
193
- tokens: ticker → { deployId, deployer, name, decimals, supply, minted, mint, mintLimit, height }
196
+ tokens: ticker → { ticker, deployId, deployer, name?, decimals, supply, minted, mint, mintLimit?, height, tmeta? }
194
197
  balances: ticker → address → { available, locked }
195
- offers: offerId → { seller, give, want, taker?, status: open|filled|cancelled|expired,
196
- expiresEpoch, height, fill?: { buyer, txid, height, paid } }
197
- events: ordered log of applied/no-op decisions (for explorers & audit; INFORMATIONAL,
198
- excluded from the canonical surface; each entry's `code` is stable (§40), its `note` text a diagnostic)
198
+ names: name → { name, owner, claimId, height, effectiveHeight, locked, addr?, viaFill?, profile?,
199
+ paidThroughEpoch?, expired? }
200
+ or, for a pending reservation (§28):
201
+ name → { name, owner, claimId, height, effectiveHeight, locked, pending, finalizeBy }
202
+ offers: offerId → { id, seller, give, want: { value, payto } | { ticker, amount, payto }, taker?,
203
+ status: open|filled|cancelled|expired, expiresEpoch, height, feeBps,
204
+ min?, paid?, delivered?, fills?, bid?, claimedBy?, claimUntilHeight?, claimTxid?,
205
+ fill?: { buyer, txid, height, paid, fee, got? } }
206
+ bids: bidId → { id, bidder, want, give: { value }, status: open|cancelled|expired|done,
207
+ expiresEpoch, height, offers }
208
+ feesPaid: the protocol fees owed by applied records (§10), a decimal string
209
+ events: ordered log of applied/no-op decisions { height, pos, id, kind, ok, code, note?, moves? } (for explorers &
210
+ audit; INFORMATIONAL, excluded from the canonical surface; each entry's `code` is stable (§40), its `note`
211
+ text a diagnostic, and an applied record that moved tokens carries its `moves` (§41))
199
212
  ```
200
213
 
214
+ An address whose `available` and `locked` are both 0 is left out of `balances`, and so is a ticker with no address
215
+ remaining. `want.payto` is always present: the record's `payto`, or the seller when the record has none.
216
+
217
+ **Fill records.** A whole fill sets `fill` once. Its `paid` is what the fill's transaction pays to `want.payto` (the
218
+ `paidTo` sum of §33.4), overpayment included, and so the maker rebate as well when `payto` is the seller (§19); for a
219
+ token-priced fill it is `want.amount`. Its `fee` is the fee the fill owed (§10, §14, §19). A partial fill (§12) appends
220
+ `{buyer, txid, height, paid, fee, got}` to `fills`, with `paid` its effective payment `x` and `got` the give units it
221
+ delivered; the partial fill that completes the offer also sets `fill` to that same entry, `got` included.
222
+
223
+ **Expiry in the state.** Before each event at height h the resolver expires every open offer and bid whose effective
224
+ expiry epoch (§24, §25) is below `epochOf(h)`, releasing an offer's give, and deletes every reservation (§28) and
225
+ recapture reservation (§29) whose `finalizeBy` is below h. After the last event, and after the deferred cancels of its
226
+ block (§16), it runs the same sweep once more at `tipHeight + 1`. So the state at a tip shows an offer or bid whose
227
+ effective expiry epoch, as the sweep at `tipHeight + 1` computes it, is `epochOf(tipHeight)` as `expired` when
228
+ `tipHeight` is the last height of that epoch (`tipHeight mod 30 = 29`), and as `open` at every earlier tip of the
229
+ epoch. For an offer or bid anchored below V22 that sweep applies the §24 cap once `tipHeight + 1` reaches V21
230
+ (40 100), that is from tip 40 099 on. A name's `expired` (§17) is read at the tip's own epoch: it is present when
231
+ `epochOf(tipHeight) > paidThroughEpoch + NAME_GRACE_EPOCHS`.
232
+
201
233
  **Canonical state (format 2, normative):** the canonical surface is
202
234
  `{tipHeight, tokens, balances, names, offers, bids, feesPaid}`: the event log is excluded.
203
- Serialization is **canonical JSON**: object keys sorted in ordinal (code-unit) order at every
204
- depth, no insignificant whitespace, UTF-8, all amounts as decimal strings (no floats anywhere),
235
+ Serialization is **canonical JSON** in the state form of §5.1: object keys sorted in ordinal (code-unit) order at every
236
+ depth, except that keys which are array indices (the canonical decimal of an integer in [0, 2^32 − 2]: an all-digit
237
+ name, an all-digit profile key) come first in ascending numeric order (§5.1 A2); arrays keep their order (`fills` and a
238
+ bid's `offers` in apply order); no insignificant whitespace, UTF-8, all amounts as decimal strings (no floats anywhere),
205
239
  booleans/numbers in their shortest JS form. Two resolvers fed the events of §33 for the same chain prefix MUST produce
206
240
  byte-identical canonical state; `sha256(canonicalState)` at the activation heights is pinned in
207
241
  `test/vectors/replay-hashes.json`, and `test/vectors/cases.json` carries language-neutral replay
@@ -252,19 +286,24 @@ once a replay hash is pinned over data that exercises them, so they are stated h
252
286
  `_js_obj_key_order`/`_js_stringify` in `conformance/cairnx_ref.py`); a third impl MUST reproduce both.
253
287
  - **A3: Field types (bare number/boolean vs decimal string vs identity string).** Canonical state mixes
254
288
  raw JSON integers and booleans with decimal-string amounts and raw identity strings. Emit as **bare
255
- integers**: `decimals, height, effectiveHeight, expiresEpoch, feeBps, tipHeight, paidThroughEpoch`, and
256
- (v1.7) `claimUntilHeight` (all JS-safe, < 2^53). Emit as **bare booleans**: `locked, viaFill, expired`.
257
- Emit as **decimal strings**: `supply, minted, mintLimit, feesPaid`, every `balances.*.available`/`.locked`,
258
- `want.value`, `want.amount`, `min`, `paid`, `delivered`, and each fill's `paid`/`.fee` (plus `.got` ONLY on
259
- a partial `fills[]` entry; see the fill shapes below). Emit as **raw 0x-hex identity strings**: the offer
260
- `id` (32-byte txid), the name `claimId` (32-byte anchor txid, present on **every** name), and (v1.7) the
261
- offer `claimedBy` (20-byte addr). Emit as a nested **object**: the name `profile` (v1.9 nprofile: a flat
262
- string→string map). **Two distinct fill shapes (the `got`-presence rule):** a whole-offer fill is the
263
- singular object `fill` = `{buyer, txid, height, paid, fee}` and **OMITS `got`**; a partial-fillable (`min`)
264
- offer instead carries an **array** `fills`, each entry `{buyer, txid, height, paid, fee, got}` **WITH
265
- `got`** (`got` = the give-asset units delivered by that partial). An implementer who adds `got` to the
266
- singular `fill` (or drops it from a `fills[]` entry) forks `sha256(canonicalState)`. Never serialize an
267
- amount as a number or an `f64`; never stringify an integer field.
289
+ integers**: `decimals, height, effectiveHeight, expiresEpoch, feeBps, tipHeight, paidThroughEpoch, finalizeBy`,
290
+ and (v1.7) `claimUntilHeight` (all JS-safe, < 2^53). Emit as **bare booleans**: `locked, viaFill, expired,
291
+ pending`. Emit as **decimal strings**: `supply, minted, mintLimit, feesPaid`, every
292
+ `balances.*.available`/`.locked`, an offer's `give.amount`, `want.value`, `want.amount`, `min`, `paid` and
293
+ `delivered`, a bid's `want.amount` and `give.value`, and each fill entry's `paid`, `fee` and `got` (see the fill
294
+ shapes below). Emit as **raw 0x-hex identity strings**: the 32-byte ids, that is the offer and bid `id`, the token
295
+ `deployId`, the name `claimId` (the anchor txid, present on **every** name), a fill's `txid`, the offer `bid` and
296
+ (v2.8) `claimTxid`, and the token `tmeta` (a content hash); and the 20-byte addresses `deployer`, `owner`, `addr`,
297
+ `seller`, `taker`, `want.payto`, `bidder`, `buyer` and (v1.7) `claimedBy`. Emit as plain strings: `ticker`, the
298
+ token `name`, `mint`, a name's `name` (also `give.name` and a bid's `want.name`) and `status`. Emit as **arrays**:
299
+ an offer's `fills` and a bid's `offers` (offer ids), in apply order. Emit as a nested **object**: the name `profile`
300
+ (v1.9 nprofile: a flat string→string map). **Two fill shapes (the `got`-presence rule):** a whole fill (of an offer
301
+ without `min`) is the singular object `fill` = `{buyer, txid, height, paid, fee}` with **no** `got`; a
302
+ partial-fillable (`min`) offer carries an **array** `fills`, each entry `{buyer, txid, height, paid, fee, got}`
303
+ **with** `got` (`got` = the give-asset units delivered by that partial), and the partial fill that completes it also
304
+ sets the singular `fill` to that same entry, `got` included (§5). An implementer who adds `got` to a whole fill, or
305
+ drops it from a `fills[]` entry or from a completed partial offer's `fill`, forks `sha256(canonicalState)`. Never
306
+ serialize an amount as a number or an `f64`; never stringify an integer field.
268
307
  > **⚠ v1.7/v1.9 are part of this byte contract on every live tip past their gate** (`V17_HEIGHT=34000`
269
308
  > claims, `V19_HEIGHT=36700` profiles). A second-language resolver built to an earlier copy of this list
270
309
  > (omitting `claimedBy`/`claimUntilHeight`/`claimId`/`profile`/`fills`) **forks `sha256(canonicalState)`
@@ -272,11 +311,14 @@ once a replay hash is pinned over data that exercises them, so they are stated h
272
311
  > `replay-hashes.json` at **every activation height through V20**: incl. 34 000 claims, 36 700 profiles,
273
312
  > 38 400 grace; V18/V21 auto-pin once the chain tip crosses them. The static `cases.json` bar additionally
274
313
  > pins the V20/V21/nprofile/name-op/lapse byte-contract with no live node required.)
275
- - **A4: Optional fields are OMITTED, never `null`.** A key whose value is absent is dropped entirely
276
- (`addr, viaFill, min, bid, taker, paidThroughEpoch, expired`, token `name`/`mintLimit`/`tmeta`, and the
277
- v1.7/v1.9 optionals `claimedBy`/`claimUntilHeight` (omitted unless the offer is claimed), `fill`
278
- (omitted until first filled), `fills` (only on a `min` offer), `profile` (only when an nprofile is set)).
279
- Never emit `"addr":null`.
314
+ - **A4: Optional fields are OMITTED, never `null`.** A key whose value is absent is dropped entirely: the token
315
+ `name`, `mintLimit` and `tmeta`; the name `addr`, `viaFill`, `profile` (only when an nprofile is set, at v1.9+
316
+ tips), `paidThroughEpoch` (on every name at v1.5+ tips except a pending reservation), `expired`, and `pending` and
317
+ `finalizeBy` (only on a pending reservation, §28); the offer `taker`, `min`, `paid`, `delivered` and `fills` (only on
318
+ a `min` offer, from its creation), `bid`, `claimedBy` and `claimUntilHeight` (from the offer's first claim grant on,
319
+ and kept after the hold ends and after the offer closes, §20), `claimTxid` (from its first fclaim grant on, §31) and
320
+ `fill` (until a whole fill, or the partial fill that completes the offer); and a whole fill's `got`. A zero balance
321
+ is left out as §5 says. Never emit `"addr":null`.
280
322
  - **A5: The acceptance gate is a byte-exact round-trip (stronger than the hash check).** A record anchor
281
323
  is accepted iff **both** `canonicalJson(JSON.parse(uri)) === uri` (byte-for-byte) **and**
282
324
  `sha256(uri) === payload_hash`. The round-trip is what rejects duplicate keys, leading-zero amounts,
@@ -347,9 +389,10 @@ cap: ecosystem doc 16 §4; these are NOT in canonical state today.)*
347
389
  payment), so a losing claimer forfeits only the 0.05 CSD attest fee. On that basis v1.7 safely
348
390
  **re-opens** untaken CSD offers via claim-to-fill (§20), and v2.0/§23 bounds its late-fill edge.)
349
391
  - **No unconfirmed chaining (no CPFP).** The mempool only accepts txs whose inputs exist in the
350
- confirmed UTXO set: you cannot spend change that hasn't been mined. Sequential CairnX actions
351
- from one key require one confirmation between them; client software must serialize and surface
352
- this ("next action available after 1 conf").
392
+ confirmed UTXO set: you cannot spend change that hasn't been mined. A key's next action needs a
393
+ confirmed coin: with one coin, one confirmation between actions; a key holding several confirmed
394
+ coins can anchor several records in one block (§16). Client software that spends one coin must
395
+ serialize its actions and surface this ("next action available after 1 conf").
353
396
  - **No native-CSD pools.** CSD itself cannot be locked by convention (real UTXOs obey only
354
397
  keys). CairnX trades CSD↔token atomically per-trade; it does not and cannot pool CSD.
355
398
  - **Reorgs:** state is a pure function of the chain; resolvers recompute (or roll back) on
@@ -391,20 +434,27 @@ owned purely on-chain: register, hold, point it at an address, transfer, or sell
391
434
  Reserved: `csd treasury admin official root www support` (`cairn`/`cairnx` are deliberately
392
435
  NOT reserved: the operator registered them as ordinary, tradeable names).
393
436
  - **`name` (claim):** `{v:1,t:"name",name,salt?}`. Owner = anchoring proposer. **Lowest
394
- effective-anchor (height, pos, id) wins.** Requires the registration fee (§ below).
437
+ effective anchor (effHeight, pos, id) wins**, numeric on `effHeight` and `pos`, ordinal (code-unit) on `id`:
438
+ `effHeight` is the claim's own height, or a reveal's commit height (below); `pos` and `id` are always the claim or
439
+ reveal record's own position and transaction id, never the commit's. Requires the registration fee (§ below).
395
440
  - **Direct claim** (no `salt`): effective height = claim height. Simple, instant; front-runnable.
396
- - **Commit-reveal** (`salt` present): a prior `ncommit` of `sha256({t:"cairnx:name:commit:v1",
397
- name,salt,owner})` must exist at a strictly lower height within `COMMIT_MAX_BLOCKS` (8 epochs).
441
+ - **Commit-reveal** (`salt` present): `salt` is 16 to 128 hex digits in either case (`SALT_RE`,
442
+ `^[0-9a-fA-F]{16,128}$`); any other `salt` makes the record an invalid no-op (`RECORD_BAD_SALT`). A prior
443
+ `ncommit` of `sha256({t:"cairnx:name:commit:v1", name,salt,owner})` must exist at a strictly lower height within
444
+ `COMMIT_MAX_BLOCKS` (8 epochs): with the commit height the LOWEST height at which that commit hash was anchored,
445
+ the reveal is valid only when `0 < revealHeight − commitHeight ≤ COMMIT_MAX_BLOCKS` (`REG_COMMIT_MAX_BLOCKS = 8`
446
+ blocks from v2.5, §28). A later anchoring of the same commit hash leaves that height as it is, so it does not
447
+ reopen a window that has passed; a retry after the window needs a fresh salt.
398
448
  The reveal **back-dates** its effective height to the commit height, so a committer beats any
399
449
  direct-claim squatter who acts in between (the reveal **displaces** them). This is the
400
450
  front-run defense (ENS/Namecoin/Runes pattern adapted to a fee-ordered chain).
401
451
  - **`ncommit`:** `{v:1,t:"ncommit",commit}`: the commit hash (binds name+salt+owner, so it can't
402
452
  be reused by another address). Cheap; the reg fee is paid at reveal.
403
453
  - **`nxfer`:** `{v:1,t:"nxfer",name,to}`: owner gifts the name. Clears the resolver record. Fails
404
- while the name is locked by an open offer.
454
+ while the name is locked by an open offer, and on a pending reservation (§28).
405
455
  - **`nset`:** `{v:1,t:"nset",name,addr}`: owner points the name at an address (the resolver
406
- record). Reverse resolution (address → names owned) is computed by the resolver.
407
- - **Selling a name:** an `offer` with `give:{name}` (instead of `{ticker,amount}`). Anchoring it
456
+ record). Fails on a pending reservation (§28). Reverse resolution (address → names owned) is computed by the resolver.
457
+ - **Selling a name:** an `offer` with `give:{name}` (instead of `{ticker,amount}`), not on a pending reservation (§28). Anchoring it
408
458
  **locks** the name (can't transfer/re-offer); a `fill` transfers ownership to the buyer and pays
409
459
  the seller (+ protocol fee), atomically, in one tx; cancel/expiry release the lock.
410
460
  - **Honest limits (v1.1, superseded):** names were **perpetual** through v1.4 (the registration fee
@@ -427,8 +477,12 @@ bearing action is a **no-op unless its own transaction pays the fee to the treas
427
477
 
428
478
  Mint, transfer, name-xfer, name-set, offer, commit and cancel pay only the chain's own anchor fee
429
479
  (to miners), not a protocol fee. An offer's `want.payto` may not be the treasury (keeps the
430
- payment and fee output buckets distinct). The resolver tracks `feesPaid` (total observed to the
431
- treasury), recomputable by anyone, like all CairnX state.
480
+ payment and fee output buckets distinct); since `payto` defaults to the seller, an offer the treasury anchors names
481
+ another `payto`. The resolver tracks `feesPaid`, recomputable by anyone like all CairnX state: the sum of the fees
482
+ that applied fee-bearing records owed, not of what was paid to the treasury. Each applied deploy (from 29 960),
483
+ registration or finalize, renewal and recapture adds its fee or premium, and each applied CSD-priced fill, whole or
484
+ partial, adds its trade fee (§19); an overpayment, a treasury output on a record that owes no fee and the outputs of a
485
+ refused record add nothing, and the in-kind fee of a token-priced fill is not counted (§14).
432
486
 
433
487
  ---
434
488
 
@@ -449,6 +503,9 @@ An offer's `want` may now be a **token amount** instead of a CSD value:
449
503
  - `want.ticker` must exist at fill time (checked at apply, like every balance rule); a
450
504
  token-priced offer over an unknown ticker simply can never fill until that ticker exists.
451
505
  `give.ticker ≠ want.ticker`. `give` may also be a **name** (sell a name for tokens).
506
+ - `want.amount` may be `"0"` (§3), as `want.value` may (§4.4). Such an offer is filled for nothing: the fill debits
507
+ `0 + ceil(0)` = 0, so an attester holding none of `want.ticker` fills it (with the marker below, and as its taker
508
+ when it is taker-bound).
452
509
  - Anchoring locks `give` exactly as in v1 (§4.4). `want.payto` (default seller) receives the
453
510
  want-tokens; it may not be the treasury.
454
511
  - **Fill** = an `Attest` with `score = 100` **and `confidence = 1 000 000`** whose attester's
@@ -488,10 +545,13 @@ A CSD-priced **token** offer may opt into partial fills with `min`:
488
545
  `deliveredCum' = floor(give.amount × paidCum' / want.value)`: each fill delivers
489
546
  `deliveredCum' − deliveredCum`. The final fill (`paidCum' = want.value`) therefore delivers
490
547
  exactly the undelivered remainder; rounding dust never strands in the lock.
548
+ - A partial fill that would deliver nothing (`deliveredCum' = deliveredCum`) is a no-op (`FILL_ZERO_DELIVERY`): it is
549
+ not appended, `paid`, `delivered` and `feesPaid` do not move, and its payment stays with `payto` (§4.5).
491
550
  - `fee = ceil(1% × x)` to the treasury in the same tx, per fill.
492
551
  - The offer stays `open` until `paidCum = want.value` → `filled`. Cancel/expiry release the
493
552
  undelivered remainder to the seller; completed partial fills stand.
494
- - Each fill is appended to the offer's `fills[]` (buyer, txid, height, paid, got, fee).
553
+ - Each applied partial fill is appended to the offer's `fills[]` (buyer, txid, height, paid = `x`, got, fee); the one
554
+ that completes the offer is also its `fill` (§5).
495
555
  - Open partially-fillable offers race like v1 open offers (fee auction, §6), but losing a
496
556
  race now only costs the loser the *overlap*: their payment still buys whatever remained.
497
557
  Wallets must still warn on open-offer fills.
@@ -503,10 +563,16 @@ A CSD-priced **token** offer may opt into partial fills with `min`:
503
563
  ```
504
564
 
505
565
  Cancels **all of the proposer's open offers anchored strictly earlier in apply order**, releasing
506
- their locks, optionally filtered to one `give` asset (`ticker` or `name`, at most one). Without
566
+ their locks, optionally filtered to one `give` asset (`ticker` or `name`, at most one), except what §31 exempts: a
567
+ taker-bound offer anchored at V28 or above is not a target (Lane B), and from V28 the block-boundary flush skips a
568
+ target under a live fclaim hold (Correction 2). Without
507
569
  cheap mass-cancel a market maker cannot keep a ladder of quotes honest (per-offer cancel = one tx
508
- each: the 0x `minValidSalt` lesson). Anchor an `ocancel`, then re-post the fresh ladder, even in
509
- the same block (proposals apply in tx order, so a later-pos ladder survives an earlier-pos cancel).
570
+ each: the 0x `minValidSalt` lesson). Anchor an `ocancel`, then re-post the fresh ladder in a later block. From v1.4
571
+ (height 31 400, §16) an `ocancel`'s effect waits for the end of its block, so the give it releases stays locked for the
572
+ rest of that block: an offer of that give later in the same block is refused (`TOKEN_BALANCE_LOW` for tokens,
573
+ `NAME_LOCKED` for a name) and its anchor fee is spent for nothing. A same-block offer at a later position is not a
574
+ target of the `ocancel` (its targets are fixed when it applies), so it stands when the proposer's available balance
575
+ covers it without the released amount.
510
576
 
511
577
  **Self-fills** (attester == seller) are **valid** and pay the protocol fee like any fill: wash
512
578
  trading is self-punishing, and a no-op rule would just complicate determinism. **Fill races on
@@ -529,12 +595,17 @@ of the book is instead built from **bids**, on-chain discovery records:
529
595
  - `memo` (64 UTF-16 units max) and `ts` are optional free fields, same rules as 4.3; `ts` MUST
530
596
  be a JS-safe integer (A8).
531
597
  - **Fulfillment** is the two-step RFQ: the asset owner anchors a **taker-bound offer**
532
- (`taker = bidder`, price ≤ bid) optionally tagged `"bid":"<bidId>"`; the bidder's client
598
+ (`taker = bidder`, price ≤ bid) optionally tagged `"bid":"<bidId>"` (the bid's id, §3); the bidder's client
533
599
  detects the responding offer and fills it atomically. Two anchors + one fill: the
534
600
  scriptless ceiling for buy-side flow.
535
- - The resolver tracks `bids` (open/cancelled/expired) and links responding offers
536
- (`offer.bid` → `bid.offers[]`). A bid whose linked offer is **filled by the bidder** is
537
- marked `done` (purely informational).
601
+ - The resolver tracks `bids` (open/cancelled/expired/done). An applied offer whose `bid` names a bid in `bids` is
602
+ appended to that bid's `offers` (in apply order) whatever its taker, its price and the bid's status: taker = bidder
603
+ and price ≤ bid describe an honest answer, not a condition of the link. An offer whose `bid` names no bid when it
604
+ applies is created with its `bid` and is never added to a bid's `offers`, then or later. A fill that closes an offer
605
+ carrying `bid` (a whole fill, or the partial fill that completes it) looks that id up in `bids` at the fill, not
606
+ through `offers`, and marks the bid `done` when it exists, the buyer is its bidder and it is still `open`; a bid
607
+ already cancelled or expired keeps its status, and a bid anchored after the offer naming it can be `done` with empty
608
+ `offers` (purely informational).
538
609
  - No protocol fee on bids (the anchor fee to miners is the spam price; the trade fee is paid
539
610
  when the responding offer fills).
540
611
 
@@ -642,10 +713,10 @@ From height **31 400**:
642
713
  after the flush.
643
714
  - **Why deferral, not reordering:** moving cancels after fills in the sort would break the
644
715
  global ordered loop and the "offers settle before fills" invariant for every other record
645
- type. Deferring only the effect keeps apply order intact. The one non-physical edge (a
646
- same-key `ocancel`-then-relist in one block observing pre-flush lock state) **cannot occur
647
- on-chain**: anchor inputs must be confirmed (no CPFP), so one key cannot chain two anchors
648
- into a single block.
716
+ type. Deferring only the effect keeps apply order intact. A relist by the same key later in
717
+ the cancel's block sees the lock state before the flush, so a relist that needs the give the
718
+ cancel releases is refused (§12b). One key can anchor several records in one block, each spending
719
+ its own confirmed coin.
649
720
  - **Determinism:** the deferred-cancel list is built and flushed in apply order, so the state
650
721
  (and the event log) remains a pure function of the chain prefix. Non-retroactive: pre-v1.4
651
722
  blocks never defer, so all historical replay is byte-identical.
@@ -659,17 +730,23 @@ lose more than the anchor fee: not to another buyer (race), and not to the selle
659
730
  **once, forever**: squatting is free to carry, and lapsed projects strand names permanently.
660
731
  From height **32 000** every name is a **lease**:
661
732
 
662
- - **Term:** a claim (or premium re-claim) is paid through `claimEpoch + 8 760` epochs (≈ 1 year).
733
+ - **Term:** a claim (or premium re-claim) is paid through `claimEpoch + 8 760` epochs (≈ 1 year), with `claimEpoch`
734
+ the epoch of the claim or reveal record's own height, not of its back-dated effective height (from v2.5 the lease
735
+ starts at the finalize instead, §28, §29).
663
736
  Names claimed before v1.5 are **grandfathered** one full term from activation
664
737
  (`epochOf(32 000) + 8 760`), computed lazily, no state rewrite at the boundary.
665
738
  - **`nrenew` `{v:1,t:"nrenew",name}`:** extends the lease one term from its CURRENT end. Valid
666
739
  from **anyone** while the lease is live (third-party gifting, ENS-style) iff the same tx pays
667
- `nameRegFee(name)` to the treasury. A renewal never changes ownership.
740
+ `nameRegFee(name)` to the treasury. A renewal never changes ownership. A pending reservation (§28) holds no lease and
741
+ is not renewed, by anyone.
668
742
  - **Grace (720 epochs ≈ 30 days):** past `paidThroughEpoch`, only the **owner** may renew;
669
743
  otherwise a squatter could extend a lapsing name they intend to take.
670
744
  - **Lapse → decaying-premium recapture:** past grace the name is unowned again. Anyone may claim
671
- it by paying `expiredClaimFee(name, epochsPastGraceEnd)`: `nameRegFee × 20` linearly decaying
672
- to `× 1` over 720 epochs (pure integer function: deterministic everywhere). The re-claim is a
745
+ it by paying `expiredClaimFee(name, e) = nameRegFee(name) × m(e)`, priced at height `h` (the finalize from v2.6,
746
+ §29), where `e = epochOf(h) − (paidThroughEpoch + 720)` counts the epochs past the grace end (at least 1, since the
747
+ name has lapsed) and, in integer division, `m(e) = 1 + floor(19 × (720 − e) / 720)` for `e < 720` and `m(e) = 1`
748
+ from `e = 720` on. `m` is a staircase that steps down from 19 at `e = 1` to 1 from `e = 683` on.
749
+ The 20 of `NAME_PREMIUM_START` would apply only at `e = 0`, where the name has not lapsed. The re-claim is a
673
750
  **fresh basis**: prior `viaFill` immunity is void (immunity protects a *paid* basis; an unpaid
674
751
  lease is an abandoned one), and any still-open offer on the name is voided with its lock freed.
675
752
  - **Guards:** `nxfer`/`nset` on a lapsed lease are no-ops. A name **offer** is a no-op unless the
@@ -677,14 +754,14 @@ From height **32 000** every name is a **lease**:
677
754
  never hit a mid-window lapse; the alternative (a no-op'd CSD fill whose payment already
678
755
  confirmed to the seller) would be a fund-loss shape, so it is made unrepresentable. Offers
679
756
  anchored before v1.5 are exempt (their windows all end long before any grandfathered lease).
680
- - **State:** at v1.5+ tips `names[x]` carries `paidThroughEpoch` (and `expired: true` once
681
- lapsed; the record is kept for history until re-claimed). Pre-v1.5 canonical hashes are
757
+ - **State:** at v1.5+ tips every name except a pending reservation (§28) carries `paidThroughEpoch` (and
758
+ `expired: true` once lapsed at the tip's epoch, §5; the record is kept for history until re-claimed). Pre-v1.5 canonical hashes are
682
759
  unchanged: the fields exist only at v1.5+ tips.
683
760
 
684
761
  ## 18. `tmeta`: issuer token metadata via the content layer (v1.5)
685
762
 
686
763
  `{v:1,t:"tmeta",ticker,hash}`: **issuer-only**, last write wins, no fee beyond the anchor.
687
- `hash` is a CSD Content Convention v1 hash (0x + 64 hex; `payloadHash` in csd-codec) pointing at
764
+ `hash` is a CSD Content Convention v1 hash (0x + 64 lowercase hex, §3; `payloadHash` in csd-codec) pointing at
688
765
  the token's `{logo, description, links}` document: self-certifying content, so the record stays tiny
689
766
  (the 512-byte `uri` cap is untouched) and any copy of the document can be checked against the hash
690
767
  on read (`verifyContentBytes` in csd-codec). The csd-swarm content service this section was written
@@ -701,7 +778,8 @@ before v1.5 are no-ops.
701
778
 
702
779
  - **Fee bump.** The taker fee becomes `FEE_BPS_V16 = 150` (1.5%, `ceil`) instead of `FEE_BPS = 100` (1%).
703
780
  The rate is **captured per-offer at creation height** into `offers[id].feeBps` (a bare-int canonical field,
704
- §5.1-A3): an offer anchored ≥ 33 600 carries `feeBps = 150`, an earlier one keeps `100`. Every fill of that
781
+ §5.1-A3): an offer anchored ≥ 33 600 carries `feeBps = 150`, one anchored in [29 960, 33 600) carries `100`, and one
782
+ anchored below 29 960 (v1.1) carries `0` and owes no trade fee (§10). Every fill of that
705
783
  offer (whole, partial, token-priced) uses the offer's own `feeBps`, so pre-v1.6 offers are byte-identical
706
784
  forever. A third-party resolver MUST select the fee by **offer-creation height**, not by fill height.
707
785
  - **Maker rebate (whole CSD-priced fills only).** On a whole fill of a **resting-liquidity** CSD-priced offer,
@@ -736,7 +814,9 @@ the 0.05 CSD attest fee, never a payment.
736
814
  - **Claim** = an `Attest` on the offer with **`score = SCORE_CLAIM = 50`** (∉ {fill 100, cancel 0}, so it is an
737
815
  inert no-op below V17, non-retroactive). It grants the attester an **exclusive hold** of the offer for
738
816
  `CLAIM_WINDOW_BLOCKS = 15` blocks: on grant the resolver records `offers[id].claimedBy = attester` and
739
- `offers[id].claimUntilHeight = grantHeight + 15` (both canonical fields, §5.1-A3, present only while claimed).
817
+ `offers[id].claimUntilHeight = grantHeight + 15` (both canonical fields, §5.1-A3, written at each grant and kept
818
+ after the hold ends and after the offer closes: a hold's end is read from `claimUntilHeight`, not from the fields'
819
+ absence).
740
820
  - **Fill gate.** A `SCORE_FILL` fill on an **untaken** (`taker === undefined`) CSD-priced offer at height ≥ V17
741
821
  is valid **only if** the offer is currently held **and the filler is the holder**: `claimHeld(o, h) &&
742
822
  attester === o.claimedBy`, where `claimHeld(o, h) = (o.claimedBy !== undefined) && (h < o.claimUntilHeight)`
@@ -788,8 +868,8 @@ no-op that forfeits the treasury output.)
788
868
  - **Inert metadata.** `p` is a flat string→string map. It carries **no fee, no value, and is never a send
789
869
  target**: the address a name resolves to for payment stays in `nset` (`names[x].addr`). A resolver keeps
790
870
  no reserved keys; the app layer keeps send targets out of `p`.
791
- - **Owner-gated, last-write-wins.** Valid iff the proposer is the current name owner and the lease is not
792
- lapsed (§17). The new `p` **replaces** the prior profile; an **empty `p` (`{}`) clears it**.
871
+ - **Owner-gated, last-write-wins.** Valid iff the proposer is the current name owner, the lease is not
872
+ lapsed (§17) and the name is not a pending reservation (§28). The new `p` **replaces** the prior profile; an **empty `p` (`{}`) clears it**.
793
873
  - **Cleared on every ownership change**: `nxfer`, a name `fill`, and a lapsed-premium re-claim all clear
794
874
  `profile` exactly as they clear `addr`.
795
875
  - **Shape limits (deterministic):** keys match `PKEY = ^[a-z0-9](?:[a-z0-9.-]{0,30}[a-z0-9])?$` (ASCII only,
@@ -867,9 +947,11 @@ The §24 lifetime cap proved to be an infrastructure symptom, not a market need,
867
947
  - **Anchor in [40 100, 41 300):** the §24 rules apply to that offer/bid FOREVER (creation gate at its
868
948
  anchor, capped `effExpiry` in every later sweep). Era membership is fixed by the anchor, so every
869
949
  replayer ages the same record identically regardless of when it replays.
870
- - **Anchor < 40 100:** raw `expires_epoch` binds (pre-V21 history, unchanged).
871
- - **Client closed form:** for anchor ≥ V22, `offerExpiryHeight = (expires_epoch+1)·30`; for the [V21, V22)
872
- era use the §24 formula; below V21 use the raw form.
950
+ - **Anchor < 40 100:** no creation gate (the record predates it), but every sweep at a height ≥ V21 reads it with the
951
+ capped `effExpiry` of §24, so over-cap inventory from before V21 expires at the first such sweep past its cap; a
952
+ sweep below V21 reads the raw `expires_epoch`, so every pre-V21 state is unchanged.
953
+ - **Client closed form:** for anchor ≥ V22, `offerExpiryHeight = (expires_epoch+1)·30`; for every anchor below V22,
954
+ `min((expires_epoch+1)·30, max(40 100, (epochOf(anchor)+MAX_OFFER_EPOCHS+1)·30))` (`offerExpiryHeightOf`).
873
955
  - **Adoption note:** a relaxation. A v2.1-only replayer rejects (no-ops) a long-dated offer the chain
874
956
  accepts, so its book diverges from the canonical one from the first over-cap anchor onward. Every
875
957
  replayer must run the v2.2 core before the tip crosses 41 300 (already long past; stated for the record).
@@ -945,16 +1027,21 @@ the settled winner ever pays.
945
1027
  is rejected at/after v2.5 (`v2.5: registration requires a commit-reveal (salt)`): an unsealed
946
1028
  registration could not be finalized.
947
1029
  - **Reveal (`name` record, height ≥ 46 440):** carries NO registration fee. Creates a PENDING reservation,
948
- materialized in canonical state as the name with `pending: true` and
949
- `finalizeBy = effHeight + 8 + 20` (`REG_COMMIT_MAX_BLOCKS + REG_FINALIZE_GRACE_BLOCKS`).
1030
+ materialized in canonical state (at v2.5+ tips) as exactly `{name, owner, claimId, height, effectiveHeight, locked,
1031
+ pending: true, finalizeBy}`, with `finalizeBy = effHeight + 8 + 20` (`REG_COMMIT_MAX_BLOCKS + REG_FINALIZE_GRACE_BLOCKS`).
1032
+ It holds no lease, so it carries no `paidThroughEpoch` and no `expired`, and it carries no `addr`, `viaFill` or
1033
+ `profile`.
1034
+ - **While pending** the reservation gives its owner only the right to finalize it: `nxfer`, `nset`, `nprofile` and a
1035
+ name `offer` by the owner, and `nrenew` by anyone, are no-ops on it (`NAME_PENDING`). Only `nfinalize`, a displacing
1036
+ reveal (below) and the expiry sweep act on a reservation.
950
1037
  - **Contest while pending:** a rival reveal with a strictly earlier `(effHeight, pos, id)` (numeric on
951
- `effHeight` and `pos`, ordinal code-unit on `id`; earliest wins) DISPLACES the reservation; the displaced party has lost only its
1038
+ `effHeight` and `pos`, ordinal code-unit on `id`; `pos` and `id` the reveal's own, §9; earliest wins) DISPLACES the reservation; the displaced party has lost only its
952
1039
  ~0.25 CSD anchor. A FINALIZED name can never be displaced: any window-valid challenger has an
953
1040
  `effHeight` within 8 blocks of the current height, which is strictly later than a finalized name's
954
1041
  (its freeze has passed). Names owned `viaFill` are likewise never displaced.
955
1042
  - **Per-address cap:** at most `MAX_PENDING_REG = 3` concurrent un-finalized reservations per owner
956
1043
  (expired ones and a re-reveal of the same name do not count); excess reveals are no-ops.
957
- - **Finalize (`nfinalize` record):** `{v:1, t:"nfinalize", name, salt}`. Valid iff ALL of: the name is
1044
+ - **Finalize (`nfinalize` record):** `{v:1, t:"nfinalize", name, salt}`, `salt` in the form of §9. Valid iff ALL of: the name is
958
1045
  pending and owned by the sender; `salt` re-derives the SAME commit that anchored the reservation
959
1046
  (`sha256` per §9, binding name + salt + owner, and the commit's height must equal the reservation's
960
1047
  `effHeight`); the freeze has passed (`ev.height > effHeight + 8`); the reservation has not expired
@@ -962,9 +1049,10 @@ the settled winner ever pays.
962
1049
  (§27, priced at the FINALIZE height). On success the `pending`/`finalizeBy` keys become ABSENT, the
963
1050
  lease starts (`paidThroughEpoch = epochOf(ev.height) + NAME_TERM_EPOCHS`), and the name is NOT
964
1051
  `viaFill`.
965
- - **Reservation expiry (lazy):** past `finalizeBy` an un-finalized reservation is swept exactly like a
966
- lapsed lease (at each event height and at the tip+1 closing sweep): the name record is DELETED and the
967
- name reopens. The would-be winner has lost only anchors, never the registration fee.
1052
+ - **Reservation expiry (lazy):** past `finalizeBy` an un-finalized reservation is deleted by the expiry sweep of §5
1053
+ (before each event above `finalizeBy`, and at the closing sweep at `tipHeight + 1`, so it is gone from the state at
1054
+ a tip equal to `finalizeBy`, although an `nfinalize` mined at that height still applies), and the name reopens. The
1055
+ would-be winner has lost only anchors, never the registration fee.
968
1056
  - **Client timing rule** (`FINALIZE_TIP_MARGIN = 2`, client-side only): sign the finalize at
969
1057
  `effHeight + 8 + 2` or later so one reorg cannot un-freeze the contest under a fee-bearing tx. The
970
1058
  20-block grace exists so a slow inclusion still lands before `finalizeBy`.
@@ -989,12 +1077,15 @@ decaying premium (up to hundreds of CSD).
989
1077
  record in `names` is left untouched (it is the premium basis; an abandoned reservation can never
990
1078
  bypass the premium). Below v2.6, recapture stays pay-now at reveal (§17, byte-identical).
991
1079
  - **Same windows and contest:** reveal window and freeze are `REG_COMMIT_MAX_BLOCKS = 8`;
992
- `finalizeBy = effHeight + 8 + 20`; lowest `(effHeight, pos, id)` displaces among reservations; its own
1080
+ `finalizeBy = effHeight + 8 + 20`; lowest `(effHeight, pos, id)` (the reveal's own `pos` and `id`) displaces among reservations; its own
993
1081
  `MAX_PENDING_REG = 3` per-address cap; overdue reservations are lazily swept.
994
1082
  - **Finalize:** the same `nfinalize` record, salt-bound to the recapture commit. The winner pays the §17
995
1083
  decaying premium priced at the FINALIZE height (slightly more decayed than at reveal: rounding favors
996
1084
  the payer). On success the name becomes a normal fresh lease under the new owner, NOT `viaFill`
997
- (displacement-immune by the same freeze arithmetic as §28).
1085
+ (displacement-immune by the same freeze arithmetic as §28). The new record keeps the reveal's anchor: `claimId` is
1086
+ the reveal's transaction id, `height` the reveal's height and `effectiveHeight` its commit's height (the finalize's
1087
+ own id and height are not recorded), and `paidThroughEpoch = epochOf(finalize height) + NAME_TERM_EPOCHS`; it
1088
+ carries no `addr` or `profile`, and `locked` is false.
998
1089
  - **Replayer note:** because the reservation map is internal, pre-v2.6 canonical hashes are untouched,
999
1090
  but a third-party resolver MUST still replicate the map (reveal, displacement, expiry) to agree on
1000
1091
  which later `nfinalize` succeeds. The map is defined by this section plus the reference resolver and
@@ -1060,15 +1151,16 @@ gate a parsed fclaim is inert (nfinalize precedent, §28).
1060
1151
  stays at the 0.05 attest floor; only the claim rises to the 0.25 propose floor.
1061
1152
 
1062
1153
  **Grant (the propose handler, at height `h >= V28_HEIGHT`).** A well-formed fclaim grants a hold iff, in order:
1063
- the referenced offer exists AND is `open` AND untaken (`!taker`) AND CSD-priced; `E <= effExpiry(offer, h)`
1154
+ `E` is at most 2^53 − 1 (§33.4); the referenced offer exists AND is `open` AND untaken (`!taker`) AND CSD-priced; `E <= effExpiry(offer, h)`
1064
1155
  (§24 / §25, so the hold never outlives the offer); `E <= epochOf(h) + FCLAIM_MAX_EPOCH_AHEAD` (`= 2`, anti-squat,
1065
1156
  bounding a hold to `EPOCH_LEN*(2 + 1) - 1 = 89` blocks); `epochOf(h) <= E` (lower bound); the offer has no live
1066
1157
  hold (`!claimHeld`, unifying legacy and fclaim holds so one offer is never double-held); the same-offer cooldown
1067
1158
  has elapsed (`h >= o.claimUntilHeight + grace + CLAIM_COOLDOWN_BLOCKS` for the last holder, where `grace` is the
1068
1159
  prior hold's era grace per §20 / §23, i.e. 0 for a prior fclaim hold and `CLAIM_FILL_GRACE_BLOCKS` for a prior
1069
1160
  legacy hold; the cooldown runs from the END of the prior hold, so a straddling legacy hold and a fresh fclaim
1070
- never disagree); and the proposer holds fewer than `MAX_ACTIVE_CLAIMS` (`= 3`) live holds. This clause order is
1071
- normative (the from-spec oracle emits deny reasons in this order). On grant the resolver records `claimedBy = proposer`, `claimUntilHeight = (E + 1)*EPOCH_LEN`, and
1161
+ never disagree); and the proposer holds fewer than `MAX_ACTIVE_CLAIMS` (`= 3`) live holds. The grant is the
1162
+ conjunction of these clauses, so their order decides only the reason code of a denial: the code of the first clause
1163
+ broken (§40.1). The Python reference checks them in this order and writes no codes. On grant the resolver records `claimedBy = proposer`, `claimUntilHeight = (E + 1)*EPOCH_LEN`, and
1072
1164
  `claimTxid = fclaimTxid`.
1073
1165
 
1074
1166
  **Last-write-wins (fund-safety).** All three fields are last-write-wins: a later grant on the same offer (after
@@ -1179,7 +1271,12 @@ transaction can also be mined again: coinbase txids are not unique on this chain
1179
1271
  created again and the same spending transaction mined in a later block. Those copies sit in two blocks,
1180
1272
  possibly on both sides of the gate, and `resolve()` fed both drops the later copy only when both are at or
1181
1273
  above the gate. §33 keeps the first occurrence, so a feed built by its rule holds neither kind of duplicate;
1182
- the drop above stays the rule for a feed that is not built by it.
1274
+ the drop above stays the rule for a feed that is not built by it. A list holding one transaction id at two places (a
1275
+ later height, or another position in the same block) with the first copy below the gate is not a list §33 produces
1276
+ (§33.2), and no level of §38 covers `resolve()` over it; there the two reference implementations differ: from V14, an
1277
+ offer among its seller's `ocancel` targets, fed again after that `ocancel` in its block, stays open past its expiry in
1278
+ cairnx-core and expires in the Python reference. Two copies at one height and position below the gate both apply in
1279
+ both, as `cases-v29.json` pins.
1183
1280
 
1184
1281
  **M5: the concurrent-hold cap counts only OPEN holds (relaxation).** §20/§31 cap an address at
1185
1282
  `MAX_ACTIVE_CLAIMS` (= 3) live holds, counted as `claimedBy === who && claimHeld(o, h)`. A FILLED offer
@@ -1476,7 +1573,7 @@ the name's profile, the `nprofile` record of §22, under the keys of §36.
1476
1573
  its current value.
1477
1574
  - A reader ignores the profile of a name that is expired or pending. In the state of §5 these are a name with
1478
1575
  `expired: true` (its lease and grace have lapsed, §17) and a name with `pending: true` (a reservation of §28 not yet
1479
- finalized). An expired name keeps its last profile in state until the name is claimed again; that profile is
1576
+ finalized; `resolve()` materializes it without a profile). An expired name keeps its last profile in state until the name is claimed again; that profile is
1480
1577
  history, not the word of a current owner.
1481
1578
 
1482
1579
  Known limit: only the owner writes a profile (§22), and two writers for one owner (two applications, or two devices)
@@ -1484,6 +1581,36 @@ that read the same profile and both write within one block interval lose one wri
1484
1581
  replaces the map, and the keys only the earlier write carried are gone. The convention has no per-key write; a writer
1485
1582
  that needs its write kept reads the profile again once its record is mined.
1486
1583
 
1584
+ ### 35.4 Forward resolution: the address a name receives at
1585
+
1586
+ A payment to a name goes to its `addr` (set by `nset`, §9, §26), else to its owner, so a name receives before its owner
1587
+ sets an address. Read from `names` in the state of §5 at a tip:
1588
+
1589
+ | The name in `names` | Resolves to |
1590
+ |---|---|
1591
+ | held, with `addr` | `addr` (`via: "nset"`) |
1592
+ | held, without `addr` (not set, or cleared by an `nset` to the zero address from V23) | the owner (`via: "owner"`) |
1593
+ | held, with the zero address as `addr` (an `nset` to it below V23 stored it, §26) | the zero address (`via: "nset"`); a wallet refuses to pay it (§26) |
1594
+ | in grace (§17: past `paidThroughEpoch`, without `expired`) | as held |
1595
+ | with `expired: true` (§17) | the record's address, flagged `lapsed: true`; a sender refuses it |
1596
+ | with `pending: true` (§28) | nothing: a reservation confers no address |
1597
+ | absent | nothing |
1598
+
1599
+ A name an open offer locks (§9) resolves as held. A sale and an `nxfer` clear `addr`, so the new owner receives until
1600
+ it sets one. The profile is not read (§36.3). A reserved name (`RESERVED_NAMES`) is absent from `names`, since a record
1601
+ that claims it does not parse (§9), so it resolves to nothing. The name is looked up as `names` writes it: a reader
1602
+ lowercases its input, drops a `.csd` suffix and refuses a string that does not match `NAME_RE` before it asks. In
1603
+ JavaScript `names` is a plain object and `constructor` matches `NAME_RE`, so a reader tests for an own key: a bare index
1604
+ on an unregistered `constructor` reads `Object.prototype.constructor`.
1605
+
1606
+ cairnx-core exports the rule as `resolveNameIn(names, name)`, which answers `{name, addr, via, lapsed, owner}` or null,
1607
+ and `nameView(names, name)` for a reader that shows a name: its class (`held`, `pending`, `lapsed`, `free` when absent,
1608
+ `reserved`), its owner (the reserver of a pending name, the last owner of a lapsed one), its address and its profile (a
1609
+ held name's only, §35.3) and its `paidThroughEpoch`; null for a string that does not match `NAME_RE`.
1610
+ `test/vectors/forward.json` (`conformance/gen-forward-vectors.mjs`) holds the cases, one per line: the events, the tip,
1611
+ and for each name asked the answers of both functions over `resolve(events, tip).names`, written by hand. Neither
1612
+ function writes state, so this section has no gate.
1613
+
1487
1614
  ## 36. The profile-key registry
1488
1615
 
1489
1616
  This is the registry of profile keys, the first version. The resolver validates keys by their form alone and keeps no
@@ -1527,7 +1654,7 @@ does not control. They are registered as the editor writes them and are the only
1527
1654
  - An address that a name's profile publishes is that name owner's node. What is read through it is at most single
1528
1655
  records, each proven for inclusion with its author bound to the coin it spent (§33.5; the record proof of §37),
1529
1656
  never a complete history, and never what marks any name, that one or another, as verified.
1530
- - A profile is never a send target (§22): the address a name pays to is `addr`, set by `nset`.
1657
+ - A profile is never a send target (§22): the address a name pays to is `addr`, set by `nset`, else the owner (§35.4).
1531
1658
  - The profile of an expired or pending name is ignored (§35.3).
1532
1659
 
1533
1660
  ### 36.4 The byte budget
@@ -1591,7 +1718,7 @@ A result says which of three levels it is.
1591
1718
 
1592
1719
  A replica conforms at three levels.
1593
1720
 
1594
- 1. The vectors: `test/vectors/cases.json`, `cases-v29.json` and `cases-rules.json` (replay, §5), `events.json`
1721
+ 1. The vectors: `test/vectors/cases.json`, `cases-v29.json`, `cases-rules.json` and `cases-convention.json` (replay, §5), `events.json`
1595
1722
  (§33.7) and `hashes.json` (§34.4). A conformant implementation reproduces every case byte for byte.
1596
1723
  2. The pinned replay hashes: `test/vectors/replay-hashes.json`, the state hash (§34.1) of the live chain at each
1597
1724
  pinned height.
@@ -1609,13 +1736,14 @@ A form of the tuple recorded on chain is reserved under the reserved prefixes of
1609
1736
  version.
1610
1737
 
1611
1738
  `test/vectors/codes.json` (§40.7) is not a level: the reason codes move no state. A replica that publishes codes
1612
- reproduces it.
1739
+ reproduces it. `test/vectors/moves.json` (§41) is not a level: the token moves move no state. A replica that publishes
1740
+ moves reproduces it.
1613
1741
 
1614
1742
  ## 39. Rule changes
1615
1743
 
1616
1744
  - This specification is normative for the future. Pinned history stands: every height below a gate replays as it
1617
1745
  did, and the pinned replay hashes do not move. Behaviour changes only at a gate, an activation height in
1618
- `src/types.ts`; a section without a gate, such as §33 to §40, moves no state.
1746
+ `src/types.ts`; a section without a gate, such as §33 to §41, moves no state.
1619
1747
  - `CONSENSUS_CHANGES.md` in the csd-sdk repository is the ledger of every change. Each gate after v2.9 also has its
1620
1748
  own file, `docs/gates/<gate>.md`, written from `docs/gates/TEMPLATE.md` and linked from its ledger entry. It
1621
1749
  states the motivation, the rule text, the class of the change (reject-more: an input the earlier rule applied
@@ -1707,7 +1835,7 @@ NAME_NOT_LAPSED and INVARIANT_BROKEN (their rows say why).
1707
1835
  | TOKEN_SUPPLY_EXHAUSTED | refused | | nothing is left to mint |
1708
1836
  | TOKEN_MINT_AMOUNT_REQUIRED | refused | | an issuer mint without `amount` |
1709
1837
  | TOKEN_BALANCE_LOW | refused | | the available balance is short (a transfer, an offer's give, a token fill's price and fee) |
1710
- | TREASURY_FEE_UNPAID | refused | | the output to the treasury is below the fee or premium |
1838
+ | TREASURY_FEE_UNPAID | refused | | the output to the treasury is below the fee or premium (where the treasury is the seller on a rebate lane, below the fee plus the maker rebate, which sum on its output) |
1711
1839
  | NAME_NO_COMMIT | refused | | no commit for this reveal below its height and inside the window |
1712
1840
  | NAME_SALT_REQUIRED | refused | | a `name` without salt at V25 and above (registration) or V26 and above (recapture) |
1713
1841
  | NAME_TAKEN_EARLIER | refused | | an earlier (effective height, position, id) holds the name or its reservation |
@@ -1746,8 +1874,8 @@ NAME_NOT_LAPSED and INVARIANT_BROKEN (their rows say why).
1746
1874
  | FILL_NO_LIVE_CLAIM | refused | | an open CSD fill without the filler's live hold |
1747
1875
  | FILL_BELOW_MIN | refused | | a partial payment below the effective minimum |
1748
1876
  | FILL_ZERO_DELIVERY | refused | | the payment delivers no unit |
1749
- | FILL_UNDERPAID | refused | | the payment to payto is below want.value |
1750
- | FILL_REBATE_UNPAID | refused | | the maker rebate output is short |
1877
+ | FILL_UNDERPAID | refused | | the payment to payto is below want.value (where payto is the seller and a maker rebate applies, a shortfall there is FILL_REBATE_UNPAID) |
1878
+ | FILL_REBATE_UNPAID | refused | | the payment to the seller is below the maker rebate, or, where payto is the seller, below want.value plus the rebate |
1751
1879
  | CLAIM_TAKER_BOUND | refused | | a taker-bound offer takes no claim |
1752
1880
  | CLAIM_TOKEN_PRICED | refused | | claims are for CSD-priced offers |
1753
1881
  | CLAIM_HOLD_LIVE | refused | | a hold (window and grace) is live, whoever holds it |
@@ -1807,3 +1935,45 @@ resolve cases (the events, the tip and the expected entries as `[id, kind, ok, c
1807
1935
  cases (the uri, the payload hash and the expected code, or null for a record that parses), with every expectation
1808
1936
  written by hand in `conformance/gen-codes-vectors.mjs`. A replica that publishes codes reproduces it. The Python
1809
1937
  reference of `conformance/` writes no codes.
1938
+
1939
+ ---
1940
+
1941
+ # Token moves (no gate)
1942
+
1943
+ ## 41. Token moves
1944
+
1945
+ An applied entry of the log (§5) whose record moved tokens carries `moves`: the movements in the order the record
1946
+ applied them, each `{ leg, ticker, from, to, amount }`, that is `amount` base units of `ticker` from the address `from`
1947
+ to the address `to`. `amount` is a positive decimal string in the form of the state's balances (§5). The resolver
1948
+ writes each move where it applies the balance change, so a reader takes who received what from the log and does not
1949
+ restate the rules that decide the amounts (the mint caps, a whole fill's delivery, the partial fill's floor, the fee).
1950
+
1951
+ | leg | written by | from | to | amount |
1952
+ |---|---|---|---|---|
1953
+ | `mint` | an applied mint (§4.2) | null | the proposer | the credit: `min(amount, mintLimit, remaining)` for an open mint, `amount` defaulting to `mintLimit`; `min(amount, remaining)` for an issuer mint |
1954
+ | `xfer` | an applied transfer (§4.3) | the proposer | `to` | `amount` |
1955
+ | `sale` | an applied fill of a token-priced offer (§11) | the buyer | `want.payto` | `want.amount`, the fill's `paid` (§5) |
1956
+ | `fee` | the same fill | the buyer | the treasury (§10) | the fill's `fee` |
1957
+ | `fill` | an applied fill of an offer whose give is a token (§4.5, §11, §12) | the seller | the buyer | `give.amount` on a whole fill, the `got` of its `fills` entry on a partial one (§12) |
1958
+
1959
+ - A token-priced fill writes its sale, then its fee, then its give. A zero amount writes no move: the sale of a token
1960
+ priced at `"0"` (§11) and its fee of 0.
1961
+ - An offer, a cancel, an `ocancel` and an expiry move tokens between one address's `available` and `locked` and write
1962
+ no move; nor does a fill that moves no token (a name sold for CSD), nor any other record. A refused entry carries no
1963
+ moves. An entry with no move has no `moves` key, and `moves` is its last key.
1964
+ - In one result a ticker names one token: the first anchored deploy of a ticker wins and a later one is refused (§4.1),
1965
+ and no record removes a token. A replay of another chain, after a reorganisation below the deploy, can bind the
1966
+ ticker to another deploy. So a move carries no deploy id; `tokens[ticker].deployId` of the same result gives it.
1967
+ - The identity the moves meet: for every ticker and address, the amounts the address received less the amounts it
1968
+ sent, over every move of the log, equal its `available` plus `locked` in `balances`, an address left out of
1969
+ `balances` holding 0; and the mint moves of a ticker sum to its `minted`.
1970
+ - The log is outside canonical state (§5), so moves change no state hash, and a replica that writes no moves conforms
1971
+ at every level of §38. A replica that publishes moves reproduces `test/vectors/moves.json`.
1972
+
1973
+ `TokenMove` (`src/types.ts`) is the type; `src/resolve/tokens.ts` and `src/resolve/attest.ts` write the moves.
1974
+ `test/vectors/moves.json` holds 13 cases (the events, the tip, and the entries that carry moves with their moves, in
1975
+ log order), every expectation written by hand in `conformance/gen-moves-vectors.mjs`. `conformance/moves-check.mjs`
1976
+ checks a result's moves against its input events and its state by the rules above, each transfer's and mint's move
1977
+ against its own record; the cairnx-core tests run it over the replay corpus at
1978
+ every pinned height and over every case file, and the seal over every input of its differential. The Python reference
1979
+ of `conformance/` writes no moves.