@inversealtruism/cairnx-core 0.2.3 → 0.2.7
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/CHANGELOG.md +149 -0
- package/CONVENTION.md +655 -34
- package/MAKERS.md +8 -4
- package/README.md +108 -65
- package/dist/index.cjs +1112 -391
- package/dist/index.d.cts +275 -14
- package/dist/index.d.ts +275 -14
- package/dist/index.js +1085 -382
- package/package.json +3 -2
- package/test/vectors/cases-rules.json +446 -0
- package/test/vectors/codes.json +200 -0
- package/test/vectors/events.json +70 -0
- package/test/vectors/hashes.json +47 -0
package/MAKERS.md
CHANGED
|
@@ -37,7 +37,8 @@ Since v1.3 (`V13_HEIGHT = 31,100`) the CSD-priced market is an RFQ loop:
|
|
|
37
37
|
2. A maker answers with a taker-bound offer: `give` is X, `want` is N CSD, `taker` is the bidder, and the record
|
|
38
38
|
carries `bid: <bidId>`. Only that bidder can fill it, so there is no same-block fill race and a losing buyer can
|
|
39
39
|
never forfeit a payment.
|
|
40
|
-
3. The bidder fills it. One
|
|
40
|
+
3. The bidder fills it. One transaction pays the maker and records the fill; CairnX delivers X when the fill matches
|
|
41
|
+
the offer. A CSD-paid fill it refuses (expired, underpaid) keeps the payment, so the bidder's wallet checks first.
|
|
41
42
|
|
|
42
43
|
Open (non-taker-bound) CSD offers are rejected by consensus in `[v1.3, v1.7)`, which is why making is RFQ. From v1.7
|
|
43
44
|
(`V17_HEIGHT = 34,000`) open CSD asks are allowed again and are made race-safe a second way; see "Open asks and the
|
|
@@ -246,12 +247,13 @@ Amounts named "base" are base units (CSD has 8 decimals). Defaults are those of
|
|
|
246
247
|
| `MM_FEE_BUDGET` | `1000000000` | Base CSD per UTC day of fees that bought nothing back. Live and filled answers are not counted; answers that expired unfilled are. Past half of it, addresses with no prior fill on CairnX are answered only for bids of at least `MM_FRESH_MIN_CSD` (reason `budget-fresh-min`); past all of it the bot posts nothing of its own and answers returning buyers only (`budget-returning-only`). Answers to returning buyers are bounded by `MM_MAX_BID_ANSWERS` and `MM_MIN_FLOAT_HARD`, not by this budget. |
|
|
247
248
|
| `MM_FRESH_MIN_CSD`, `MM_FRESH_SLOTS` | `2000000000`, `16` | A bid below the minimum from an address with no prior fill is "fresh small" (in Sunrise the answer price is compared, not the bid). Such answers hold at most `MM_FRESH_SLOTS` of the `MM_MAX_BID_ANSWERS` slots (reason `fresh-slots`). |
|
|
248
249
|
| `MM_BID_MIN`, `MM_BID_MARGIN_BPS`, `MM_MAX_BID_ANSWERS` | `200000000`, `200`, `24` | Bid dust floor (2 CSD), accept margin over the reference, and outstanding-answer cap. |
|
|
250
|
+
| `MM_MAX_BALANCE_READS` | `20` | Bidder balances one answer pass reads from the node (each `/utxos` read walks the node's UTXO set). The checks that need no balance run first; a balance is cached per address and tip, and one read insolvent is not read again for 3 blocks. Returning bidders are read first, then addresses never read, then re-reads, each resuming where the last capped pass stopped; a bid whose turn is a later pass is skipped that pass as `balance-unknown`. At least 1. |
|
|
249
251
|
| `MM_LOCK_FRAC` | `2500` | Token locked in open answers is at most this many bps of inventory. |
|
|
250
252
|
| `MM_DAY_SELL_CAIRN`, `MM_DAY_SELL_CSD` | `3000000000000`, `50000000000` | Daily sell caps in base units (30,000 CAIRN at 8 decimals, 500 CSD): today's fills plus live answers. In Sunrise an answer whose taker can no longer pay for it is not reserved against them; `MM_LOCK_FRAC`, inventory and `MM_SUNRISE_E` still count every live answer. |
|
|
251
253
|
| `MM_EXCLUDE_ADDRS` | the CairnX treasury address | Comma list; excluded from the reference, from answers and from fills. |
|
|
252
254
|
| `MM_BID_SPREAD_BPS`, `MM_BID_SIZE`, `MM_MAX_OPEN_BIDS` | `800`, `2000000000`, `2` | Thin bid side (Reservoir only). The bid reference is collared at the ask reference so the book cannot cross. `MM_MAX_OPEN_BIDS=0` stops new posts only, not fills of existing bids. |
|
|
253
255
|
| `MM_BID_LEVELS` | `[]` | `[[spreadBps, sizeCsd],...]`; empty means a single `MM_BID_SPREAD_BPS` bid. |
|
|
254
|
-
| `MM_FILL_BIDS` | `
|
|
256
|
+
| `MM_FILL_BIDS` | `0` | `1` turns on fills of answers to the maker's bids and new bid posts; at `0` cancels still run, so a start without the setting buys nothing. With `1` and `MM_VERIFY_INCLUSION` off the bot starts, alerts at boot and publishes `build.fillsWithoutInclusion` in its health and quotes files: its fills would pay on what the indexer serves. The buy side runs only in the Reservoir: the Sunrise posts no bids. Must be 0 or 1. |
|
|
255
257
|
| `MM_DAY_BUY_CSD`, `MM_BID_EXPIRY` | `10000000000`, `24` | An absolute ceiling on the day's bid-side CSD (100 CSD); the buy-back guards below set the working limit. Bid life in epochs; bids are cancellable. |
|
|
256
258
|
| `MM_BUY_SALE_BPS` | `1000` | All-in buybacks over the trailing 7 days at most this share of the maker's 7-day sale proceeds. No recent sales, no buying. |
|
|
257
259
|
| `MM_BUY_LIFE_BPS` | `500` | Buybacks since the start tip at most this share of the sale proceeds since then. |
|
|
@@ -274,8 +276,10 @@ Amounts named "base" are base units (CSD has 8 decimals). Defaults are those of
|
|
|
274
276
|
| `MM_SUNRISE_E`, `MM_SUNRISE_DAY_QUOTA`, `MM_SUNRISE_MAX_EPOCHS` | `100000`, `5000`, `2160` | Scheduled emission (display units), per-UTC-day quota with no accrual, and the epoch cap after which the schedule graduates. |
|
|
275
277
|
| `MM_SUNRISE_MAX_ORDER` | `60000` | Largest single Sunrise answer in display units; the day quota caps it too. Published as `sunrise.maxOrder` in base units. |
|
|
276
278
|
| `MM_SUNRISE_BID_BUFFER_BPS` | `200` | Buffer a Swap UI adds to a Sunrise bid above the rung; the answer asks the maker's price, so this is the buyer's tolerance. At most 2000. |
|
|
279
|
+
| `MM_SUNRISE_START_TIP` | `0` | The tip a Sunrise record starts at when the bot creates one (`0`: the current tip). Pin it to the launch tip, so a state file lost with its marker re-derives the sale, its clock and its price from the chain since the pin instead of restarting at P0. A whole number. |
|
|
277
280
|
| `MM_SUNRISE_TARGET_DEPTH_BPS` | `500` | Part of the float target behind `sunrise.skimmable`: this many bps of the remaining Sunrise value. |
|
|
278
|
-
| `MM_ISSUER_ADDR`, `MM_SKIM_LEDGER` | empty, `~/.config/cairn/mm-skim.jsonl` |
|
|
281
|
+
| `MM_ISSUER_ADDR`, `MM_SKIM_LEDGER` | empty, `~/.config/cairn/mm-skim.jsonl` | The issuer address the quotes file publishes (`issuer`), and the skim ledger. The bot never sends CSD itself; see "Skimming CSD". |
|
|
282
|
+
| `MM_SKIM_TO` | empty | The one address a live skim may send to. The skim script refuses a live run without it or with another `--to`; the bot's loader parses it and no pass reads it. |
|
|
279
283
|
|
|
280
284
|
`MM_SUNRISE_PRICE_LOCK_BLOCKS` and `MM_SUNRISE_PRICE_LOCK_LOOKBACK` are not read any more.
|
|
281
285
|
|
|
@@ -372,7 +376,7 @@ if that is the floor you want. Graduation is not a claim that the market is liqu
|
|
|
372
376
|
### Skimming CSD
|
|
373
377
|
|
|
374
378
|
Excess CSD is moved out with an operator script (`scripts/mm-skim.mjs` in the reference repo). `--dry` is the default and
|
|
375
|
-
`--live` submits. It refuses amounts above the quotes file's `sunrise.skimmable`: the float above a target of `MM_SUNRISE_TARGET_DEPTH_BPS` of the remaining Sunrise value plus 30 days of `MM_FEE_BUDGET`, never less than twice `MM_MIN_FLOAT`, and only when the float exceeds 1.5 times that target. The
|
|
379
|
+
`--live` submits, only to `MM_SKIM_TO`, which `--to` must repeat. It refuses amounts above the quotes file's `sunrise.skimmable`: the float above a target of `MM_SUNRISE_TARGET_DEPTH_BPS` of the remaining Sunrise value plus 30 days of `MM_FEE_BUDGET`, never less than twice `MM_MIN_FLOAT`, and only when the float exceeds 1.5 times that target. The
|
|
376
380
|
ledger is `MM_SKIM_LEDGER` (mode 600).
|
|
377
381
|
|
|
378
382
|
## Honest limits
|
package/README.md
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
# @inversealtruism/cairnx-core
|
|
2
2
|
|
|
3
3
|
**CairnX** is the application layer of [Compute Substrate](https://cairn-substrate.com/docs) (CSD): an
|
|
4
|
-
on-chain **name service (CNS / `.csd`)**, **tokens**, and **
|
|
4
|
+
on-chain **name service (CNS / `.csd`)**, **tokens**, and **trades** (one transaction pays and records a fill; the replay decides delivery), implemented as a **pure deterministic convention** over the chain's native `Propose`/`Attest`
|
|
5
5
|
transactions. No fork, no smart contracts, no custodian. The same trust class as Bitcoin
|
|
6
6
|
Ordinals/Runes/BRC-20, stated plainly, and engineered to be byte-for-byte reproducible.
|
|
7
7
|
|
|
@@ -32,27 +32,29 @@ the operator's resolver does, and disagreement is detectable.
|
|
|
32
32
|
```
|
|
33
33
|
┌──────────────────────────────────────────────────────────────────────────────┐
|
|
34
34
|
│ APP SURFACES CNS UI (/names) · Market (/trade) · Cairn Wallet │
|
|
35
|
-
│ Explorer ·
|
|
35
|
+
│ Explorer · 3rd-party dApps │
|
|
36
36
|
└───────────────▲───────────────────────────────────────────────▲──────────────┘
|
|
37
37
|
│ read derived state │ build + sign records
|
|
38
38
|
┌───────────────┴───────────────────────────────────────────────┴──────────────┐
|
|
39
39
|
│ cairnX OVERLAY = resolve(events, tip) → state (THIS PACKAGE) │
|
|
40
40
|
│ every replayer runs the SAME pure function and gets the SAME bytes: │
|
|
41
|
-
│ wallet (SPV, in-browser) · reference resolver · clarvis
|
|
41
|
+
│ wallet (SPV, in-browser) · reference resolver · clarvis │
|
|
42
42
|
└───────────────▲────────────────────────────────────────────────────────────────┘
|
|
43
43
|
│ events (Propose/Attest) + block headers
|
|
44
44
|
┌───────────────┴────────────────────────────────────────────────────────────────┐
|
|
45
|
-
│ COMPUTE SUBSTRATE (base chain) PoW · records & orders txs ·
|
|
46
|
-
│
|
|
45
|
+
│ COMPUTE SUBSTRATE (base chain) PoW · records & orders txs · pays every output │
|
|
46
|
+
│ it mines, enforces expiry - decides NOTHING │
|
|
47
47
|
└──────────────────────────────────────────────────────────────────────────────────┘
|
|
48
48
|
```
|
|
49
49
|
|
|
50
50
|
**The safety consequence of "overlay":** CairnX names and tokens have **no native-CSD backing**. A bug,
|
|
51
51
|
an over-mint, or even a fully-lying indexer can only fork the *overlay view* of whoever trusts it, it
|
|
52
|
-
**cannot move CSD**. CSD moves *only* via real
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
52
|
+
**cannot move CSD**. CSD moves *only* via real payment outputs in the fill's own transaction. The chain pays them
|
|
53
|
+
whenever it mines the transaction; CairnX then decides delivery by replay, and a CSD-paid fill it refuses (an expired
|
|
54
|
+
offer, a wrong target, an underpaid leg, a denied reservation) keeps the payment. So a buyer's wallet and the site
|
|
55
|
+
check the fill against the offer's merkle-proven terms and the reservation before signing. An overlay bug can
|
|
56
|
+
therefore not create or move CSD on its own; it can make a fill a buyer signs deliver nothing, which those checks
|
|
57
|
+
exist to refuse.
|
|
56
58
|
|
|
57
59
|
```mermaid
|
|
58
60
|
flowchart TD
|
|
@@ -63,13 +65,12 @@ flowchart TD
|
|
|
63
65
|
W["Cairn Wallet<br/>in-browser SPV replayer"]
|
|
64
66
|
G["reference resolver svc :8794"]
|
|
65
67
|
CL["clarvis · 2nd source"]
|
|
66
|
-
CLI["cairn-cli"]
|
|
67
68
|
UIN["CNS UI /names"]
|
|
68
69
|
UIT["Market /trade"]
|
|
69
70
|
TX --> CORE
|
|
70
|
-
CORE --> W & G & CL
|
|
71
|
+
CORE --> W & G & CL
|
|
71
72
|
G --> UIN & UIT
|
|
72
|
-
W -. "self-verifies
|
|
73
|
+
W -. "self-verifies; an unprovable name shows the served address with a caution" .-> UIN
|
|
73
74
|
```
|
|
74
75
|
|
|
75
76
|
---
|
|
@@ -80,19 +81,22 @@ CNS is an **ENS-class** namespace native to Compute Substrate. A name like `alic
|
|
|
80
81
|
address, **leased** (not sold forever), points to an address, and carries an optional profile, all as
|
|
81
82
|
plain on-chain records, all resolvable by replay.
|
|
82
83
|
|
|
83
|
-
- **Names are lowercase-ASCII only** (`^[a-z0-9](?:[a-z0-9-]{0,30}[a-z0-9])?$`, 1–32 chars). This
|
|
84
|
-
the homograph
|
|
84
|
+
- **Names are lowercase-ASCII only** (`^[a-z0-9](?:[a-z0-9-]{0,30}[a-z0-9])?$`, 1–32 chars). This removes
|
|
85
|
+
the mixed-script homograph class: there is no Unicode look-alike surface. Look-alikes within ASCII remain
|
|
86
|
+
(`paypa1` and `paypal` are distinct, valid names), so an interface that shows a name should still warn on them.
|
|
85
87
|
- **The `.csd` suffix is presentation, not consensus.** The on-chain record stores the *bare* name
|
|
86
88
|
(`alice`); the UI renders `alice.csd`. The CNS rebrand and any display-suffix change are **UI-only**, they do not touch the resolver or chain history.
|
|
87
89
|
- **Reserved names** (`csd`, `treasury`, `admin`, `official`, `root`, `www`, `support`) can never be
|
|
88
|
-
registered, anti-impersonation
|
|
90
|
+
registered, anti-impersonation. The convention's parse rule refuses them (`isName`, `src/records.ts`), so every
|
|
91
|
+
replayer agrees; the chain itself does not read names.
|
|
89
92
|
|
|
90
93
|
### 2.1 · Lifecycle
|
|
91
94
|
|
|
92
95
|
```mermaid
|
|
93
96
|
stateDiagram-v2
|
|
94
97
|
[*] --> Committed: ncommit · hash(name+salt+owner)
|
|
95
|
-
Committed -->
|
|
98
|
+
Committed --> Reserved: name (reveal within 8 blocks, ~16 min) · payment-free reservation
|
|
99
|
+
Reserved --> Active: nfinalize (once the contest froze) · pays the fee, starts a 1-year lease
|
|
96
100
|
Active --> Active: nrenew · nset (point to addr) · nprofile (identity) · nxfer (transfer) · sell (offer/fill)
|
|
97
101
|
Active --> Grace: lease term ends (~1 year)
|
|
98
102
|
Grace --> Active: nrenew · OWNER ONLY, ~30-day window
|
|
@@ -101,10 +105,12 @@ stateDiagram-v2
|
|
|
101
105
|
Active --> [*]
|
|
102
106
|
```
|
|
103
107
|
|
|
104
|
-
1. **Commit → Reveal (registration
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
+
1. **Commit → Reveal → Finalize (registration, v2.5 sealed reservation, `CONVENTION.md` section 28).** You
|
|
109
|
+
first publish `ncommit`, a hash of `{name, salt, owner}`. Within 8 blocks (~16 min) you publish the `name`
|
|
110
|
+
record revealing the name; the reveal pays nothing and makes a reservation. The resolver **back-dates** it to
|
|
111
|
+
the commit height, so a front-runner who copies your reveal loses the race. Once the displacement contest has
|
|
112
|
+
frozen, the winner publishes `nfinalize`, which pays the fee and starts the lease; a reservation not finalized
|
|
113
|
+
in time lapses. Recapture of a lapsed name runs through the same machinery (v2.6, section 29).
|
|
108
114
|
2. **Active lease (~1 year).** You own the name: point it at an address (`nset`), set an identity profile
|
|
109
115
|
(`nprofile`), transfer it (`nxfer`), renew it (`nrenew`), or list it for sale.
|
|
110
116
|
3. **Grace (~30 days).** When the term ends, **only the current owner** may renew during a grace window, your name is never sniped out from under you while you still hold it.
|
|
@@ -118,7 +124,8 @@ stateDiagram-v2
|
|
|
118
124
|
| Record | What it does |
|
|
119
125
|
|---|---|
|
|
120
126
|
| `ncommit` | Commit to a name (hash of name+salt+owner), opens the front-run-safe reveal window |
|
|
121
|
-
| `name` | Reveal
|
|
127
|
+
| `name` | Reveal (registration): a payment-free reservation, back-dated to the commit |
|
|
128
|
+
| `nfinalize` | Finalize the reservation: pays the registration fee, starts the lease |
|
|
122
129
|
| `nrenew` | Extend the lease (owner-only in grace) |
|
|
123
130
|
| `nxfer` | Transfer ownership to another address |
|
|
124
131
|
| `nset` | Set the forward address record (`alice.csd → 0x…`) |
|
|
@@ -137,9 +144,9 @@ stateDiagram-v2
|
|
|
137
144
|
### 2.4 · How a name resolves, and what's actually *verified*
|
|
138
145
|
|
|
139
146
|
This is what makes CNS trust-minimized rather than "ask a server." When the wallet resolves `alice.csd`
|
|
140
|
-
to choose a send recipient, it does **not**
|
|
141
|
-
|
|
142
|
-
|
|
147
|
+
to choose a send recipient, it does **not** take the resolver's answer as the address: it SPV-verifies every
|
|
148
|
+
relevant record into the proof-of-work chain it built itself, replays them, and sends to the recomputed winner
|
|
149
|
+
when the replay proves one. When it cannot prove one, it says so and leaves the decision to the user.
|
|
143
150
|
|
|
144
151
|
```mermaid
|
|
145
152
|
sequenceDiagram
|
|
@@ -153,26 +160,31 @@ sequenceDiagram
|
|
|
153
160
|
Wallet->>SPV: merkle-verify each record into the PoW-verified headers
|
|
154
161
|
Note over Wallet,SPV: union of sources: a source can only ADD real,<br/>signer-authenticated, prevout-bound events (never fabricate)
|
|
155
162
|
Wallet->>Wallet: resolve() the verified events to a deterministic owner + addr
|
|
156
|
-
alt
|
|
157
|
-
Wallet-->>U: verified
|
|
158
|
-
else
|
|
159
|
-
Wallet-->>U:
|
|
163
|
+
alt the replay proves an address
|
|
164
|
+
Wallet-->>U: verified: send to the proven address (warn if a source stated another)
|
|
165
|
+
else nothing provable, or the sources prove different addresses
|
|
166
|
+
Wallet-->>U: not chain-verified: show the served address with a caution, the user decides
|
|
160
167
|
end
|
|
161
168
|
```
|
|
162
169
|
|
|
163
|
-
- **Forward resolution (`name → address`, the funds path) is SPV-verified and
|
|
164
|
-
treats the resolver as untrusted, merkle-binds each record to a PoW header
|
|
165
|
-
|
|
166
|
-
|
|
170
|
+
- **Forward resolution (`name → address`, the funds path) is SPV-verified, and a disagreement is a warning.**
|
|
171
|
+
The wallet treats the resolver as untrusted, merkle-binds each record to a PoW header and replays. When a
|
|
172
|
+
source states another address than the replay proves, the send goes to the proven address with a "sources
|
|
173
|
+
disagree" warning; when nothing can be proven, the name is shown as not chain-verified, with the served
|
|
174
|
+
address and a caution, and the user decides. Every `.csd` send carries the name-service caution. It refuses
|
|
175
|
+
a name that does not resolve or whose lease lapsed, and at signing it re-checks and refuses an address change
|
|
176
|
+
or a drop from verified to not verified. The wallet's `SECURITY.md` ("What happens when the sources
|
|
177
|
+
disagree") is the full list.
|
|
167
178
|
- **Reverse resolution (`address → primary name`, a display label) is server-trusted.** It is never a send
|
|
168
179
|
target, an identity badge only, so it is cheaper and clearly bounded as "unverified label."
|
|
169
180
|
- **Ownership has an unambiguous total order:** lowest `(effectiveHeight, position, ordinal-id)` wins, with
|
|
170
181
|
a paid market-fill (`viaFill`) immune to displacement. Exactly one owner per name at every height.
|
|
171
182
|
|
|
172
|
-
> **Note on
|
|
173
|
-
>
|
|
174
|
-
>
|
|
175
|
-
>
|
|
183
|
+
> **Note on names whose history reads other state:** a replay of one name's records alone cannot decide a
|
|
184
|
+
> name whose history touches a rule that reads other state (a name bought on the market can be one such
|
|
185
|
+
> case). The reference service's name-history read (`/cairnx/name-history/:name`) serves such a name with
|
|
186
|
+
> `scopedReplaySufficient: false`, and a per-name verifier should show it as unverified. A replay of the
|
|
187
|
+
> whole `cairnx:v1` domain decides every name exactly.
|
|
176
188
|
|
|
177
189
|
---
|
|
178
190
|
|
|
@@ -192,11 +204,14 @@ can never touch CSD.
|
|
|
192
204
|
|
|
193
205
|
---
|
|
194
206
|
|
|
195
|
-
## 4 ·
|
|
207
|
+
## 4 · Trades: one transaction pays and records the fill
|
|
196
208
|
|
|
197
|
-
Sell a token **or a name** for CSD or another token
|
|
198
|
-
|
|
199
|
-
|
|
209
|
+
Sell a token **or a name** for CSD or another token. The offer locks the give-side in the resolver; the fill is an
|
|
210
|
+
`Attest` whose **same transaction carries the payment outputs**, so the chain records the payment and the fill
|
|
211
|
+
together, and CairnX decides delivery by replay. A token-for-token fill is atomic: the replay moves both sides or
|
|
212
|
+
neither. A CSD-paid fill the replay refuses keeps the payment: CairnX rejecting the fill does not undo or refund
|
|
213
|
+
the transaction's CSD outputs (only a chain reorganization can drop the transaction), so the buyer's client checks the offer's proven terms, the reservation and the amount before signing
|
|
214
|
+
(`verifyFillSpv`, `fillEndorsement`). No escrow, no custodian.
|
|
200
215
|
|
|
201
216
|
```mermaid
|
|
202
217
|
sequenceDiagram
|
|
@@ -204,16 +219,16 @@ sequenceDiagram
|
|
|
204
219
|
participant Chain as Compute Substrate
|
|
205
220
|
participant Taker
|
|
206
221
|
Maker->>Chain: offer { give: alice.csd or token, want: 100 CSD, payto } (locks the give)
|
|
207
|
-
Note over Chain: open CSD
|
|
222
|
+
Note over Chain: an open CSD offer is reserved first (fclaim, v2.8):<br/>only the holder's fill delivers, no race
|
|
208
223
|
Taker->>Chain: fill (Attest) + SAME-TX outputs · 100 CSD to payto, fee to treasury, rebate to maker
|
|
209
|
-
Chain-->>Chain: resolve(): payment satisfies want? deliver give to taker, else
|
|
210
|
-
Note over Maker,Taker:
|
|
224
|
+
Chain-->>Chain: resolve(): payment satisfies want? deliver give to taker, else no delivery
|
|
225
|
+
Note over Maker,Taker: a refused CSD-paid fill keeps the payment · check before signing
|
|
211
226
|
```
|
|
212
227
|
|
|
213
228
|
Highlights: partial fills (pro-rata, maker-favoring), bids (RFQ buy-side intents), `ocancel` (maker's mass
|
|
214
|
-
kill-switch), a 1.5% taker fee + maker rebate on resting liquidity (v1.6), and the
|
|
215
|
-
|
|
216
|
-
payment. Listing duration is a **UI policy** (consensus places no cap as of v2.2), long-rester inventory
|
|
229
|
+
kill-switch), a 1.5% taker fee + maker rebate on resting liquidity (v1.6), and the reservation lane for open CSD
|
|
230
|
+
offers: a short-expiry `fclaim` proposal reserves an untaken offer and the fill attests it (v2.8, `CONVENTION.md`
|
|
231
|
+
section 31, which replaced v1.7's claim attest), so two buyers can't race into a refused payment. Listing duration is a **UI policy** (consensus places no cap as of v2.2), long-rester inventory
|
|
217
232
|
is bounded in the light client, not the chain.
|
|
218
233
|
|
|
219
234
|
---
|
|
@@ -232,18 +247,21 @@ is bounded in the light client, not the chain.
|
|
|
232
247
|
mixed-version fleet can't fork during a rollout.
|
|
233
248
|
- **The determinism contract is *enforced*, not asserted.** An independent Python reference
|
|
234
249
|
(`conformance/cairnx_ref.py`) runs the same corpus and a 1500-iteration JS↔Python differential fuzzer on
|
|
235
|
-
every CI run, plus
|
|
250
|
+
every CI run, plus the language-neutral vectors in `test/vectors/` and pinned live-chain replay hashes.
|
|
236
251
|
|
|
237
252
|
### Version history (activation heights are consensus-grade, never reinterpret history)
|
|
238
253
|
|
|
254
|
+
Each row's normative statement is its section of `CONVENTION.md` (v2.5 to v2.9 are sections 28 to 32); the heights
|
|
255
|
+
live in `src/types.ts`.
|
|
256
|
+
|
|
239
257
|
| Version | Height | What |
|
|
240
258
|
|---|---|---|
|
|
241
259
|
| v1.0 / 1.1 | 29 860 / 29 960 | tokens · **names (CNS)** + protocol fees |
|
|
242
260
|
| v1.2 | 30 300 | token⇄token swaps · partial fills · bids (RFQ) · `ocancel` |
|
|
243
|
-
| v1.3 / 1.4 | 31 100 / 31 400 | CSD-priced offers taker-bound · fill-before-cancel
|
|
261
|
+
| v1.3 / 1.4 | 31 100 / 31 400 | CSD-priced offers taker-bound · fill-before-cancel (a same-block fill beats a cancel) |
|
|
244
262
|
| v1.5 | 32 000 | **name leasing** (renew / grace / decaying-premium recapture) · `tmeta` |
|
|
245
263
|
| v1.6 | 33 600 | taker fee 1% → 1.5% + maker rebate on resting liquidity |
|
|
246
|
-
| v1.7 | 34 000 | claim-to-fill, race-safe open CSD offers |
|
|
264
|
+
| v1.7 | 34 000 | claim-to-fill, race-safe open CSD offers (claim attests rejected from v2.8) |
|
|
247
265
|
| v1.9 | 36 700 | `nprofile`, ENS-class identity on a name |
|
|
248
266
|
| v2.0 | 38 400 | bounded claim grace (the late-fill fix) |
|
|
249
267
|
| v1.8 | 40 000 | flat two-tier name fee (6.7 / 3 CSD) |
|
|
@@ -253,21 +271,24 @@ is bounded in the light client, not the chain.
|
|
|
253
271
|
| v2.5 | 46 440 | sealed-reservation registration: payment-free reveal, winner-only fee at `nfinalize` |
|
|
254
272
|
| v2.6 | 46 480 | sealed-reservation recapture (lapsed-name premium paid by the settled winner only) |
|
|
255
273
|
| v2.7 | 46 520 | young-name sale embargo shrinks 240 → 8 blocks |
|
|
256
|
-
| v2.3 | 52 000 | `nset` to the zero address CLEARS the pointer
|
|
274
|
+
| v2.3 | 52 000 | `nset` to the zero address CLEARS the pointer |
|
|
275
|
+
| v2.8 | 60 000 | `fclaim`: the open-lane reservation becomes a short-expiry proposal the fill attests |
|
|
276
|
+
| v2.9 | 88 000 | replay-feed de-duplication; the concurrent-claim cap counts open holds only |
|
|
257
277
|
|
|
258
278
|
v2.4–v2.7 were re-pinned 2026-07-03 from their originally published heights (49 200 / 51 000 / 51 200 /
|
|
259
279
|
52 500); see the re-pin history note in `CONVENTION.md` and `CONSENSUS_CHANGES.md` 0.1.33.
|
|
260
280
|
|
|
261
281
|
### Package layout
|
|
262
282
|
|
|
263
|
-
`src/resolve.ts` + `src/resolve/` (the ledger: the replay loop and its per-record handlers) · `src/
|
|
264
|
-
|
|
283
|
+
`src/resolve.ts` + `src/resolve/` (the ledger: the replay loop and its per-record handlers) · `src/events.ts` (the rule
|
|
284
|
+
from a block to events, CONVENTION §33) · `src/hashes.ts` (the state and events hashes, §34) · `src/records.ts` (the parse/validate gate) · `src/types.ts` (constants +
|
|
285
|
+
height-gated client selectors) · `src/client.ts` (the claim-burial depth a payer waits for, sized against a minority miner) · `src/preflight.ts`
|
|
265
286
|
(build-side helpers every host must compute identically: `requiredFillOutputs`, `previewFill`/`fillIsSafe`,
|
|
266
287
|
`buildFeeHeight` + `NAME_FEE_GATES`, `finalizeWinnerCheck`) · `src/primary.ts` (`pickPrimaryName` /
|
|
267
288
|
`primaryRankBefore`, the one primary-name selection every host must agree on) · `src/mm/` (the
|
|
268
289
|
`@inversealtruism/cairnx-core/mm` subpath: the market maker's bid sizer, fill notional, Sunrise spot curve and
|
|
269
290
|
order pricing, and the RFQ all-in sum; not consensus and not part of the root export) · `CONVENTION.md`
|
|
270
|
-
(normative spec, §1–§
|
|
291
|
+
(normative spec, §1–§39) · `test/vectors/` (portable conformance corpus).
|
|
271
292
|
|
|
272
293
|
### Use it
|
|
273
294
|
|
|
@@ -279,21 +300,45 @@ import { buildPropose } from "@inversealtruism/csd-tx";
|
|
|
279
300
|
const built = offer({ give: { ticker: "CAIRN", amount: "5000000000" },
|
|
280
301
|
want: { value: "100000000" }, min: "10000000", taker: buyerAddr });
|
|
281
302
|
|
|
282
|
-
// ANCHOR it (the record IS the uri; same
|
|
303
|
+
// ANCHOR it (the record IS the uri; outputs in the same tx pay fees and sellers)
|
|
283
304
|
const tx = buildPropose({ domain: DOMAIN, uri: built.uri, payloadHash: built.payloadHash,
|
|
284
305
|
expiresEpoch, fee: 25_000_000, utxos, priv });
|
|
285
306
|
|
|
286
|
-
// RESOLVE the chain
|
|
307
|
+
// RESOLVE the chain. CONVENTION §33 turns blocks into events: blockMembers(height, txs, sofar) names the txs
|
|
308
|
+
// that need an author, blockEvents(height, txs, sofar, authors) returns the block's events, and eventOfTx maps
|
|
309
|
+
// one tx. The author is an input: bind it with csd-crypto's authorOf(tx, scriptPubkey) over the coin the first
|
|
310
|
+
// input spends, read from its source tx. csd-light's bindBlockTxs checks a block's txs against a verified header.
|
|
287
311
|
const state = resolve(events, tipHeight);
|
|
288
312
|
console.log(state.names, state.tokens.CAIRN, state.balances.CAIRN);
|
|
289
313
|
```
|
|
290
314
|
|
|
315
|
+
### What a resolver result proves
|
|
316
|
+
|
|
317
|
+
- Display: an answer read from someone's API. It is worth the trust you place in that API.
|
|
318
|
+
- Record proof: one record is mined under valid proof of work and was written by the owner of the coin
|
|
319
|
+
its first input spends. It does not prove the record is the latest one, and it decides nothing for a name
|
|
320
|
+
whose history touches a cross-name rule.
|
|
321
|
+
- Replica: a replay of every `cairnx:v1` record. It is exact for names and tokens. What it proves depends
|
|
322
|
+
on where the records came from: one's own node, complete blocks checked against headers, or someone's
|
|
323
|
+
record feed, which is complete only on that feed's word.
|
|
324
|
+
|
|
325
|
+
Other applications, the profile-key registry with its byte budget, the three levels with their sources,
|
|
326
|
+
conformance and how the rules change are `CONVENTION.md` §35 to §39.
|
|
327
|
+
|
|
328
|
+
Why a record was applied or refused: each entry of `resolve(...).events` carries a stable `code` (`CONVENTION.md` §40,
|
|
329
|
+
`REASON_CODES`), and `explainRecord(uri, payloadHash)` names the rule a record breaks before it reaches the resolver.
|
|
330
|
+
Match the code, never the `note` text, which may change; a code your release does not know reads by the entry's `ok`.
|
|
331
|
+
|
|
291
332
|
### Write a conformant resolver in another language
|
|
292
333
|
|
|
293
|
-
1. Implement `CONVENTION.md` §1–§
|
|
294
|
-
the re-pinned v2.4–v2.7 heights), the canonical-state format, ordinal key ordering, data
|
|
295
|
-
|
|
296
|
-
|
|
334
|
+
1. Implement `CONVENTION.md` §1–§34 (the events of a block, apply order, every record type, the `V*_HEIGHT`
|
|
335
|
+
activations (using the re-pinned v2.4–v2.7 heights), the canonical-state format, ordinal key ordering, data
|
|
336
|
+
surface only).
|
|
337
|
+
2. Reproduce `test/vectors/events.json` (§33.7). Replay `test/vectors/cases.json`, `cases-v29.json` and
|
|
338
|
+
`cases-rules.json`: your canonical state must equal `expectedState` **byte-for-byte**.
|
|
339
|
+
3. Replay the live chain and compare the state hash (§34.1) against `test/vectors/replay-hashes.json`, and reproduce
|
|
340
|
+
`test/vectors/hashes.json` (§34.4).
|
|
341
|
+
4. Only if you publish reason codes (§40): reproduce `test/vectors/codes.json`.
|
|
297
342
|
|
|
298
343
|
---
|
|
299
344
|
|
|
@@ -310,7 +355,6 @@ is a silent chain fork, the exact bug class the shared-core de-dup (`cairn/docs/
|
|
|
310
355
|
| **cairnx svc** (`cairnx/`, the live resolver `:8794`) | npm pin → re-export shim | svc replay-hash conformance |
|
|
311
356
|
| **cairn /trade + /names UI** (browser) | `public/vendor/cairnx-core.js` (esbuild of this dist) | `vendor-cairnx-parity.test.mjs` + `check-vendor-fresh.mjs` |
|
|
312
357
|
| **cairn-wallet** (MV3, fund custody) | `src/vendor/cairnx-spv.js` (esbuild, `export *`) | `test/cairnx.ts` + `check-vendor-fresh.mjs` + `PROVENANCE.json` |
|
|
313
|
-
| **cairn-cli** | npm pin → imports regexes/limits | `test/cairnx.mjs` |
|
|
314
358
|
| **the Python oracle** `conformance/cairnx_ref.py` | INDEPENDENT re-implementation (the differential, **KEEP**) | `test:crosslang` (JS⇄Python) |
|
|
315
359
|
|
|
316
360
|
**To make a consensus change:** edit `src/` here **and** `conformance/cairnx_ref.py`; add a height-gated
|
|
@@ -331,11 +375,10 @@ light-client + `namespv.ts`, the wallet `core/csdtx.ts` tx-codec twin, the porta
|
|
|
331
375
|
2-source name union whose two defaults share one apex, strong against *fabrication* (every event is
|
|
332
376
|
SPV/signer/prevout-bound), weaker against *withholding* until a genuinely independent second source runs.
|
|
333
377
|
The 2nd-indexer canonical-hash comparator is designed but parked until that exists.
|
|
334
|
-
- **The indexer ships on SQLite by default.** A Postgres backend is fully built (`csd-indexer/src/db.ts`)
|
|
335
|
-
and is a documented env-flip + from-genesis-replay cutover (`RUNBOOK-HOST.md §8.3`), the scale path, not
|
|
336
|
-
yet the running default.
|
|
337
378
|
- **`verifyInclusion` (merkle-binding the indexer's decoded outputs) is OFF by default** and is a hard
|
|
338
|
-
prerequisite before any lane treats received CSD as spendable. The overlay model
|
|
339
|
-
|
|
379
|
+
prerequisite before any lane treats received CSD as spendable. The overlay model keeps an overlay bug from
|
|
380
|
+
creating or moving CSD by itself; it does not make every payment safe. A CSD-paid fill CairnX refuses keeps the
|
|
381
|
+
payment, `verifyFillSpv`'s "Known limits" (in `src/verifyfill.ts`) list when a buyer's client can still sign one,
|
|
382
|
+
and a `.csd` send to a name the wallet cannot prove goes to the served address after a caution (section 2.4).
|
|
340
383
|
|
|
341
384
|
MIT · the same trust class as Ordinals/Runes, engineered for byte-for-byte reproducible replay.
|