@inversealtruism/cairnx-core 0.1.8 → 0.1.9

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/MAKERS.md ADDED
@@ -0,0 +1,143 @@
1
+ # Run a CairnX market maker
2
+
3
+ CairnX has **no AMM and no escrow** — native CSD can't be pooled (CONVENTION §6). Liquidity is whoever
4
+ runs a *maker loop*. This guide is everything you need to join as a market maker, end to end. Anyone
5
+ may run one, against any token, with their own key. It builds only on the public package
6
+ [`@inversealtruism/cairnx-core`](https://www.npmjs.com/package/@inversealtruism/cairnx-core).
7
+
8
+ ## How the market works (RFQ)
9
+
10
+ Post-v1.3 the CSD-priced market **is** an RFQ loop (CONVENTION §13/§15):
11
+
12
+ 1. A buyer anchors a **bid** — "I'll pay *N* CSD for *X*" (public, on-chain).
13
+ 2. A **maker** (you) answers with a **taker-bound offer**: you give *X*, want *N* CSD, `taker` = the
14
+ bidder, tagged `bid: <bidId>`. Only that bidder can fill it — so there is **no same-block fill race**
15
+ and a losing buyer can never forfeit a payment.
16
+ 3. The bidder **fills** it: one atomic transaction pays you and delivers *X*, or nothing happens.
17
+
18
+ Open (non-taker-bound) CSD offers are rejected by consensus in `[v1.3, v1.7)` — that race-safety is *why*
19
+ making is RFQ. **v1.7** (`V17_HEIGHT`) re-allows open CSD asks but makes them race-safe a second way —
20
+ see *Claim-to-fill* below.
21
+
22
+ ## Why make a market (v1.6 maker rebate)
23
+
24
+ From **v1.6** (`V16_HEIGHT`), every **bid-answered whole fill** pays the maker a **rebate**, taker-funded,
25
+ routed to you (`o.seller`):
26
+
27
+ ```
28
+ maker rebate = 0.25 CSD + 0.5% of the trade value # flat reimburses your 0.25 CSD posting cost
29
+ ```
30
+
31
+ The taker also pays **1.5%** to the protocol treasury (separate). So on a 1 CSD fill you receive the
32
+ 1 CSD price **+ 0.255 CSD rebate**. Net maker economics:
33
+
34
+ ```
35
+ net = Σ rebates earned − Σ anchor (propose) fees spent # 0.25 CSD per offer/cancel you post
36
+ ```
37
+
38
+ Each *filled* answer reimburses its own posting cost; the 0.5% margin covers answers that don't fill.
39
+ Fund a key once and a healthy market funds itself — that's the whole point of v1.6. Live maker P&L for
40
+ the reference bot is published at `/cairnx/mm-health` (and shown on the **Makers** tab at `/trade`).
41
+
42
+ ## Claim-to-fill (v1.7) — open CSD asks, race-safe
43
+
44
+ From **v1.7** (`V17_HEIGHT`) a maker may post an **open** CSD ask (no `taker`) again. Anyone can buy it,
45
+ but a fill is gated on a **claim** — a payment-free `SCORE_CLAIM` attest that reserves the offer for the
46
+ first claimer (by consensus order) for a short window (`CLAIM_WINDOW_BLOCKS` ≈ 30 min). Only the live
47
+ claimer may then fill, so two buyers never race a payment: a losing same-block claim is a no-op costing
48
+ only the 0.05 CSD attest fee. The **maker rebate extends to open-ask fills** — an open ask filled at/after
49
+ v1.7 pays you the same `0.25 CSD + 0.5%`, taker-funded.
50
+
51
+ ⚠ **Buyer safety — claim before you fill.** A fill tx on an open offer you do **not** hold a live claim on
52
+ is **rejected as a fill by consensus, but your payment outputs are still spent** (you paid for nothing).
53
+ Always, in order:
54
+
55
+ ```js
56
+ import { buildClaimTx, buildFillTx, fillPayments } from "cairnx/txbuild"; // reference builders
57
+
58
+ // 1. CLAIM — payment-free attest; reserves the open offer for you.
59
+ const claim = buildClaimTx({ offerId, utxos, priv });
60
+ // submit, then wait for confirmation and re-read state:
61
+ // the offer must show claimedBy == yourAddr && tip < claimUntilHeight
62
+ // 2. FILL — only once your claim is live. Pay price + treasury fee + the maker rebate to o.seller:
63
+ const payments = fillPayments(offer.want.payto, offer.want.value,
64
+ { feeBps: offer.feeBps, rebate: true, seller: offer.seller }); // seller REQUIRED when rebate:true
65
+ const fill = buildFillTx({ offerId, utxos, priv, payments });
66
+ ```
67
+
68
+ `fillPayments({rebate:true})` throws if you omit `seller` — the rebate must route to `o.seller` or the
69
+ resolver no-ops the unmatched output and the fill is lost. A claim is for **CSD-priced open offers only**;
70
+ taker-bound offers (the RFQ path above) fill directly with no claim. Grief bounds: an address holds at most
71
+ `MAX_ACTIVE_CLAIMS` live claims and cannot re-grab a just-lapsed offer for `CLAIM_COOLDOWN_BLOCKS`.
72
+
73
+ ## Quickstart
74
+
75
+ ```bash
76
+ npm i @inversealtruism/cairnx-core @inversealtruism/csd-client
77
+ ```
78
+
79
+ **1. Create a dedicated maker key** (never reuse your main key):
80
+
81
+ ```bash
82
+ # any CSD wallet/CLI; you need its 32-byte privkey + 20-byte addr20
83
+ ```
84
+
85
+ **2. Fund it** with the token inventory you'll sell + a little CSD for anchor fees (0.25 CSD per
86
+ quote). The reference bot halts loudly below a configurable CSD float so it never silently fails.
87
+
88
+ **3. Answer bids.** Each pass: read open bids, compute a robust reference price, and for each bid that
89
+ clears `ref + your margin`, anchor a taker-bound offer:
90
+
91
+ ```js
92
+ import { offer } from "@inversealtruism/cairnx-core";
93
+ import { CsdClient } from "@inversealtruism/csd-client";
94
+
95
+ const client = new CsdClient({ baseUrl: "https://<node-or-proxy>/api/rpc" });
96
+ const bids = await fetch("https://<host>/cairnx/bids?status=open").then(r => r.json());
97
+
98
+ for (const b of bids) {
99
+ if (!worthAnswering(b)) continue; // your pricing: only answer ≥ ref + margin
100
+ const rec = offer({
101
+ give: b.want, // the token/amount the bidder wants
102
+ want: { value: b.give.value }, // the CSD they offered (or less, to compete)
103
+ taker: b.bidder, // bind it to the bidder → race-free
104
+ bid: b.id, // link it (resolvers/UIs + the rebate)
105
+ });
106
+ // anchor `rec.uri` / `rec.payloadHash` as a Propose tx (fee ≥ 0.25 CSD), then submit.
107
+ // when the bidder fills, you receive: price + (0.25 + 0.5%) rebate; treasury gets 1.5%.
108
+ }
109
+ ```
110
+
111
+ `offer()` returns `{ record, uri, payloadHash }` — the canonical bytes to anchor. Build the Propose tx
112
+ with your CSD tx tooling (e.g. `@inversealtruism/csd-tx` `buildPropose`, or the reference
113
+ `buildAnchorTx`), sign with your maker key, and submit to the node `/tx/submit`.
114
+
115
+ ## Safety rails the reference bot ships (and you should keep)
116
+
117
+ - **Robust reference price** — a volume-weighted median over a trailing window, excluding self-fills /
118
+ dust, with a per-pass move clamp and an optional absolute band. A poisoned print can't teleport your
119
+ quotes; a suspicious reference *halts the pass loudly* instead of quoting a bad number.
120
+ - **Per-UTC-day anchor budget** — a forced quote/cancel storm runs out of fuel, loudly.
121
+ - **Min-float halt** — below a CSD threshold the maker stops and surfaces "underfunded" rather than
122
+ silently failing submits.
123
+ - **Short answer expiry + outstanding-answer cap** — a dead maker degrades gracefully; one wave of bids
124
+ can't lock your whole book. Answers expire (consensus-enforced) and release their inventory lock.
125
+ - **One anchor per pass, persisted in-flight state** — the substrate has no child-pays-for-parent, so
126
+ never chain a second anchor off an unconfirmed change output; a restart can't double-post.
127
+ - **Skip on a stale view** — never act when your indexer trails the node tip.
128
+
129
+ ## Honest limits
130
+
131
+ - CSD has no liquid USD price; "value" math is in base units. CSD↔token is RFQ (2 signatures over a few
132
+ blocks), never one-click — that's the no-escrow tradeoff, not a bug.
133
+ - Competition is on price and latency: answer under the bid, answer first. The only money a *losing*
134
+ maker spends is its own anchor fee — the cost of quoting.
135
+ - Self-dealing the rebate is net-negative (you'd still owe the treasury fee + network fee), so it's not
136
+ an exploit.
137
+
138
+ ## Reference
139
+
140
+ - **Protocol:** [`CONVENTION.md`](https://github.com/InverseAltruism/csd-sdk/blob/master/packages/cairnx/CONVENTION.md) — §13 RFQ, §15 taker-binding, §8/§10 fees, §6 no-escrow.
141
+ - **Resolver + record builders:** [`@inversealtruism/cairnx-core`](https://github.com/InverseAltruism/csd-sdk/tree/master/packages/cairnx) (this package) — `offer`, `bid`, `deploy`, `mint`, `parseRecord`, `resolve`, `canonicalState`.
142
+ - **Read endpoints:** `/cairnx/bids`, `/cairnx/offers`, `/cairnx/quotes` (indicative ladder), `/cairnx/mm-health` (live maker P&L), `/cairnx/state` (byte-canonical state).
143
+ - **Determinism:** the resolver is byte-deterministic and cross-language co-signed (see `conformance/`); two honest resolvers converge — that's the trust model.
package/dist/index.cjs CHANGED
@@ -23,13 +23,17 @@ __export(index_exports, {
23
23
  ACTIVATION_HEIGHT: () => ACTIVATION_HEIGHT,
24
24
  ADDR_RE: () => ADDR_RE,
25
25
  AMOUNT_RE: () => AMOUNT_RE,
26
+ CLAIM_COOLDOWN_BLOCKS: () => CLAIM_COOLDOWN_BLOCKS,
27
+ CLAIM_WINDOW_BLOCKS: () => CLAIM_WINDOW_BLOCKS,
26
28
  COMMIT_MAX_BLOCKS: () => COMMIT_MAX_BLOCKS,
27
29
  CONF_TOKEN_FILL: () => CONF_TOKEN_FILL,
28
30
  DEPLOY_FEE: () => DEPLOY_FEE,
29
31
  DOMAIN: () => DOMAIN,
30
32
  EPOCH_LEN: () => EPOCH_LEN,
31
33
  FEE_BPS: () => FEE_BPS,
34
+ FEE_BPS_V16: () => FEE_BPS_V16,
32
35
  HASH_RE: () => HASH_RE,
36
+ MAX_ACTIVE_CLAIMS: () => MAX_ACTIVE_CLAIMS,
33
37
  MAX_AMOUNT: () => MAX_AMOUNT,
34
38
  MAX_RECORD_BYTES: () => MAX_RECORD_BYTES,
35
39
  NAME_GRACE_EPOCHS: () => NAME_GRACE_EPOCHS,
@@ -37,8 +41,11 @@ __export(index_exports, {
37
41
  NAME_PREMIUM_START: () => NAME_PREMIUM_START,
38
42
  NAME_RE: () => NAME_RE,
39
43
  NAME_TERM_EPOCHS: () => NAME_TERM_EPOCHS,
44
+ REBATE_BPS: () => REBATE_BPS,
45
+ REBATE_FLAT: () => REBATE_FLAT,
40
46
  RESERVED_NAMES: () => RESERVED_NAMES,
41
47
  SCORE_CANCEL: () => SCORE_CANCEL,
48
+ SCORE_CLAIM: () => SCORE_CLAIM,
42
49
  SCORE_FILL: () => SCORE_FILL,
43
50
  TICKER_RE: () => TICKER_RE,
44
51
  TREASURY_ADDR: () => TREASURY_ADDR,
@@ -47,6 +54,8 @@ __export(index_exports, {
47
54
  V13_HEIGHT: () => V13_HEIGHT,
48
55
  V14_HEIGHT: () => V14_HEIGHT,
49
56
  V15_HEIGHT: () => V15_HEIGHT,
57
+ V16_HEIGHT: () => V16_HEIGHT,
58
+ V17_HEIGHT: () => V17_HEIGHT,
50
59
  bid: () => bid,
51
60
  buildRecord: () => buildRecord,
52
61
  canonicalState: () => canonicalState,
@@ -56,6 +65,7 @@ __export(index_exports, {
56
65
  isName: () => isName,
57
66
  isNameGive: () => isNameGive,
58
67
  isTokenWant: () => isTokenWant,
68
+ makerRebate: () => makerRebate,
59
69
  mint: () => mint,
60
70
  nameClaim: () => nameClaim,
61
71
  nameCommit: () => nameCommit,
@@ -83,6 +93,8 @@ var V12_HEIGHT = 30300;
83
93
  var V13_HEIGHT = 31100;
84
94
  var V14_HEIGHT = 31400;
85
95
  var V15_HEIGHT = 32e3;
96
+ var V16_HEIGHT = 33600;
97
+ var V17_HEIGHT = 34e3;
86
98
  var EPOCH_LEN = 30;
87
99
  var NAME_TERM_EPOCHS = 8760;
88
100
  var NAME_GRACE_EPOCHS = 720;
@@ -99,9 +111,16 @@ var MAX_RECORD_BYTES = 512;
99
111
  var MAX_AMOUNT = (1n << 96n) - 1n;
100
112
  var SCORE_FILL = 100;
101
113
  var SCORE_CANCEL = 0;
114
+ var SCORE_CLAIM = 50;
115
+ var CLAIM_WINDOW_BLOCKS = 15;
116
+ var MAX_ACTIVE_CLAIMS = 3;
117
+ var CLAIM_COOLDOWN_BLOCKS = 15;
102
118
  var CONF_TOKEN_FILL = 1e6;
103
119
  var TREASURY_ADDR = "0x6b09ce74e6070ebc982ab0fb793a211c4d24f016";
104
120
  var FEE_BPS = 100;
121
+ var FEE_BPS_V16 = 150;
122
+ var REBATE_FLAT = 25000000n;
123
+ var REBATE_BPS = 50;
105
124
  var DEPLOY_FEE = 1e8;
106
125
  function nameRegFee(name) {
107
126
  const n = name.length;
@@ -111,7 +130,8 @@ function nameRegFee(name) {
111
130
  if (n <= 9) return 50000000n;
112
131
  return 10000000n;
113
132
  }
114
- var tradeFee = (want) => (want * BigInt(FEE_BPS) + 9999n) / 10000n;
133
+ var tradeFee = (want, bps = FEE_BPS) => (want * BigInt(bps) + 9999n) / 10000n;
134
+ var makerRebate = (value) => REBATE_FLAT + (value * BigInt(REBATE_BPS) + 9999n) / 10000n;
115
135
  var TICKER_RE = /^[A-Z][A-Z0-9]{2,11}$/;
116
136
  var ADDR_RE = /^0x[0-9a-f]{40}$/;
117
137
  var AMOUNT_RE = /^(0|[1-9][0-9]*)$/;
@@ -398,6 +418,7 @@ function resolve(events, tipHeight) {
398
418
  const b = bids.get(o.bid);
399
419
  if (b && b.status === "open" && b.bidder === buyer) b.status = "done";
400
420
  };
421
+ const liveClaim = (o, height) => o.claimedBy !== void 0 && o.claimUntilHeight !== void 0 && height < o.claimUntilHeight;
401
422
  for (const ev of ordered) {
402
423
  if (ev.height < ACTIVATION_HEIGHT) continue;
403
424
  if (ev.height !== pendingBlock) {
@@ -408,6 +429,7 @@ function resolve(events, tipHeight) {
408
429
  const v11 = ev.height >= V11_HEIGHT;
409
430
  const v12 = ev.height >= V12_HEIGHT;
410
431
  const v15 = ev.height >= V15_HEIGHT;
432
+ const v16 = ev.height >= V16_HEIGHT;
411
433
  const feeToTreasury = ev.kind === "propose" ? BigInt((ev.paidTo ?? {})[TREASURY_ADDR] ?? "0") : 0n;
412
434
  if (ev.kind === "propose") {
413
435
  const rec = parseRecord(ev.uri, ev.payloadHash);
@@ -582,7 +604,7 @@ function resolve(events, tipHeight) {
582
604
  note(ev, ev.id, "offer", false, "v1.2 offer shape before activation");
583
605
  continue;
584
606
  }
585
- if (ev.height >= V13_HEIGHT && !wantIsToken && rec.taker === void 0) {
607
+ if (ev.height >= V13_HEIGHT && ev.height < V17_HEIGHT && !wantIsToken && rec.taker === void 0) {
586
608
  note(ev, ev.id, "offer", false, "v1.3: CSD-priced offers must be taker-bound (use bid/RFQ)");
587
609
  continue;
588
610
  }
@@ -649,7 +671,7 @@ function resolve(events, tipHeight) {
649
671
  status: "open",
650
672
  expiresEpoch: ev.expiresEpoch,
651
673
  height: ev.height,
652
- feeBps: v11 ? FEE_BPS : 0
674
+ feeBps: v11 ? v16 ? FEE_BPS_V16 : FEE_BPS : 0
653
675
  };
654
676
  offers.set(ev.id, o);
655
677
  const linked = rec.bid !== void 0 ? bids.get(rec.bid) : void 0;
@@ -806,7 +828,7 @@ function resolve(events, tipHeight) {
806
828
  continue;
807
829
  }
808
830
  const amt = BigInt(o.want.amount);
809
- const fee = o.feeBps ? tradeFee(amt) : 0n;
831
+ const fee = o.feeBps ? tradeFee(amt, o.feeBps) : 0n;
810
832
  const buyer = bal(o.want.ticker, who);
811
833
  if (buyer.available < amt + fee) {
812
834
  note(ev, ev.txid, "fill", false, "insufficient want-token balance");
@@ -855,8 +877,14 @@ function resolve(events, tipHeight) {
855
877
  continue;
856
878
  }
857
879
  if (ev.height >= V13_HEIGHT && !o.taker) {
858
- note(ev, ev.txid, "fill", false, "v1.3: open CSD-quoted fills disabled (offer must be taker-bound)");
859
- continue;
880
+ if (ev.height < V17_HEIGHT) {
881
+ note(ev, ev.txid, "fill", false, "v1.3: open CSD-quoted fills disabled (offer must be taker-bound)");
882
+ continue;
883
+ }
884
+ if (!(liveClaim(o, ev.height) && who === o.claimedBy)) {
885
+ note(ev, ev.txid, "fill", false, "v1.7: open offer \u2014 claim it first (no live claim by you)");
886
+ continue;
887
+ }
860
888
  }
861
889
  const pt = ev.paidTo ?? {};
862
890
  const want = BigInt(o.want.value);
@@ -870,7 +898,7 @@ function resolve(events, tipHeight) {
870
898
  continue;
871
899
  }
872
900
  const x = X < remaining ? X : remaining;
873
- const fee = o.feeBps ? tradeFee(x) : 0n;
901
+ const fee = o.feeBps ? tradeFee(x, o.feeBps) : 0n;
874
902
  if (BigInt(pt[TREASURY_ADDR] ?? "0") < fee) {
875
903
  note(ev, ev.txid, "fill", false, "protocol fee unpaid");
876
904
  continue;
@@ -914,22 +942,35 @@ function resolve(events, tipHeight) {
914
942
  continue;
915
943
  }
916
944
  if (ev.height >= V13_HEIGHT && !o.taker) {
917
- note(ev, ev.txid, "fill", false, "v1.3: open CSD-quoted fills disabled (offer must be taker-bound)");
918
- continue;
945
+ if (ev.height < V17_HEIGHT) {
946
+ note(ev, ev.txid, "fill", false, "v1.3: open CSD-quoted fills disabled (offer must be taker-bound)");
947
+ continue;
948
+ }
949
+ if (!(liveClaim(o, ev.height) && who === o.claimedBy)) {
950
+ note(ev, ev.txid, "fill", false, "v1.7: open offer \u2014 claim it first (no live claim by you)");
951
+ continue;
952
+ }
919
953
  }
920
954
  const pt = ev.paidTo ?? {};
921
955
  const want = BigInt(o.want.value);
922
- const paid = BigInt(pt[o.want.payto] ?? "0");
923
- if (paid < want) {
924
- note(ev, ev.txid, "fill", false, "payment below want.value");
925
- continue;
926
- }
927
- const fee = o.feeBps ? tradeFee(want) : 0n;
928
- const feeGot = BigInt(pt[TREASURY_ADDR] ?? "0");
929
- if (feeGot < fee) {
930
- note(ev, ev.txid, "fill", false, "protocol fee unpaid");
956
+ const fee = o.feeBps ? tradeFee(want, o.feeBps) : 0n;
957
+ const restingLiquidity = o.taker !== void 0 && o.bid !== void 0 || o.height >= V17_HEIGHT && o.taker === void 0;
958
+ const rebate = o.height >= V16_HEIGHT && restingLiquidity ? makerRebate(want) : 0n;
959
+ const need = /* @__PURE__ */ new Map();
960
+ const addNeed = (a, v) => need.set(a, (need.get(a) ?? 0n) + v);
961
+ addNeed(o.want.payto, want);
962
+ addNeed(TREASURY_ADDR, fee);
963
+ if (rebate > 0n) addNeed(o.seller, rebate);
964
+ let unpaid;
965
+ for (const [addr, amt] of need) if (BigInt(pt[addr] ?? "0") < amt) {
966
+ unpaid = addr === TREASURY_ADDR ? "protocol fee unpaid" : rebate > 0n && addr === o.seller ? "maker rebate unpaid (v1.6)" : "payment below want.value";
967
+ break;
968
+ }
969
+ if (unpaid) {
970
+ note(ev, ev.txid, "fill", false, unpaid);
931
971
  continue;
932
972
  }
973
+ const paid = BigInt(pt[o.want.payto] ?? "0");
933
974
  if (isNameGive(o.give)) {
934
975
  const n = names.get(o.give.name);
935
976
  if (!n) {
@@ -961,6 +1002,36 @@ function resolve(events, tipHeight) {
961
1002
  o.fill = { buyer: who, txid: ev.txid, height: ev.height, paid: paid.toString(), fee: fee.toString() };
962
1003
  markBidDone(o, who);
963
1004
  note(ev, ev.txid, "fill", true);
1005
+ } else if (ev.height >= V17_HEIGHT && ev.score === SCORE_CLAIM) {
1006
+ if (o.status !== "open") {
1007
+ note(ev, ev.txid, "claim", false, `offer ${o.status}`);
1008
+ continue;
1009
+ }
1010
+ if (o.taker) {
1011
+ note(ev, ev.txid, "claim", false, "taker-bound offer needs no claim");
1012
+ continue;
1013
+ }
1014
+ if (isTokenWant(o.want)) {
1015
+ note(ev, ev.txid, "claim", false, "claims are for CSD-priced offers (token offers are no-op-safe)");
1016
+ continue;
1017
+ }
1018
+ if (liveClaim(o, ev.height)) {
1019
+ note(ev, ev.txid, "claim", false, "offer already claimed (window live)");
1020
+ continue;
1021
+ }
1022
+ if (o.claimedBy === who && o.claimUntilHeight !== void 0 && ev.height < o.claimUntilHeight + CLAIM_COOLDOWN_BLOCKS) {
1023
+ note(ev, ev.txid, "claim", false, "claim cooldown (you just held this offer)");
1024
+ continue;
1025
+ }
1026
+ let liveN = 0;
1027
+ for (const x of offers.values()) if (x.claimedBy === who && x.claimUntilHeight !== void 0 && ev.height < x.claimUntilHeight) liveN++;
1028
+ if (liveN >= MAX_ACTIVE_CLAIMS) {
1029
+ note(ev, ev.txid, "claim", false, `max ${MAX_ACTIVE_CLAIMS} live claims per address`);
1030
+ continue;
1031
+ }
1032
+ o.claimedBy = who;
1033
+ o.claimUntilHeight = ev.height + CLAIM_WINDOW_BLOCKS;
1034
+ note(ev, ev.txid, "claim", true);
964
1035
  }
965
1036
  }
966
1037
  }
@@ -1016,13 +1087,17 @@ function canonicalState(s) {
1016
1087
  ACTIVATION_HEIGHT,
1017
1088
  ADDR_RE,
1018
1089
  AMOUNT_RE,
1090
+ CLAIM_COOLDOWN_BLOCKS,
1091
+ CLAIM_WINDOW_BLOCKS,
1019
1092
  COMMIT_MAX_BLOCKS,
1020
1093
  CONF_TOKEN_FILL,
1021
1094
  DEPLOY_FEE,
1022
1095
  DOMAIN,
1023
1096
  EPOCH_LEN,
1024
1097
  FEE_BPS,
1098
+ FEE_BPS_V16,
1025
1099
  HASH_RE,
1100
+ MAX_ACTIVE_CLAIMS,
1026
1101
  MAX_AMOUNT,
1027
1102
  MAX_RECORD_BYTES,
1028
1103
  NAME_GRACE_EPOCHS,
@@ -1030,8 +1105,11 @@ function canonicalState(s) {
1030
1105
  NAME_PREMIUM_START,
1031
1106
  NAME_RE,
1032
1107
  NAME_TERM_EPOCHS,
1108
+ REBATE_BPS,
1109
+ REBATE_FLAT,
1033
1110
  RESERVED_NAMES,
1034
1111
  SCORE_CANCEL,
1112
+ SCORE_CLAIM,
1035
1113
  SCORE_FILL,
1036
1114
  TICKER_RE,
1037
1115
  TREASURY_ADDR,
@@ -1040,6 +1118,8 @@ function canonicalState(s) {
1040
1118
  V13_HEIGHT,
1041
1119
  V14_HEIGHT,
1042
1120
  V15_HEIGHT,
1121
+ V16_HEIGHT,
1122
+ V17_HEIGHT,
1043
1123
  bid,
1044
1124
  buildRecord,
1045
1125
  canonicalState,
@@ -1049,6 +1129,7 @@ function canonicalState(s) {
1049
1129
  isName,
1050
1130
  isNameGive,
1051
1131
  isTokenWant,
1132
+ makerRebate,
1052
1133
  mint,
1053
1134
  nameClaim,
1054
1135
  nameCommit,
package/dist/index.d.cts CHANGED
@@ -5,6 +5,8 @@ declare const V12_HEIGHT = 30300;
5
5
  declare const V13_HEIGHT = 31100;
6
6
  declare const V14_HEIGHT = 31400;
7
7
  declare const V15_HEIGHT = 32000;
8
+ declare const V16_HEIGHT = 33600;
9
+ declare const V17_HEIGHT = 34000;
8
10
  declare const EPOCH_LEN = 30;
9
11
  declare const NAME_TERM_EPOCHS = 8760;
10
12
  declare const NAME_GRACE_EPOCHS = 720;
@@ -17,12 +19,20 @@ declare const MAX_RECORD_BYTES = 512;
17
19
  declare const MAX_AMOUNT: bigint;
18
20
  declare const SCORE_FILL = 100;
19
21
  declare const SCORE_CANCEL = 0;
22
+ declare const SCORE_CLAIM = 50;
23
+ declare const CLAIM_WINDOW_BLOCKS = 15;
24
+ declare const MAX_ACTIVE_CLAIMS = 3;
25
+ declare const CLAIM_COOLDOWN_BLOCKS = 15;
20
26
  declare const CONF_TOKEN_FILL = 1000000;
21
27
  declare const TREASURY_ADDR = "0x6b09ce74e6070ebc982ab0fb793a211c4d24f016";
22
28
  declare const FEE_BPS = 100;
29
+ declare const FEE_BPS_V16 = 150;
30
+ declare const REBATE_FLAT = 25000000n;
31
+ declare const REBATE_BPS = 50;
23
32
  declare const DEPLOY_FEE = 100000000;
24
33
  declare function nameRegFee(name: string): bigint;
25
- declare const tradeFee: (want: bigint) => bigint;
34
+ declare const tradeFee: (want: bigint, bps?: number) => bigint;
35
+ declare const makerRebate: (value: bigint) => bigint;
26
36
  declare const TICKER_RE: RegExp;
27
37
  declare const ADDR_RE: RegExp;
28
38
  declare const AMOUNT_RE: RegExp;
@@ -230,6 +240,10 @@ interface OfferState {
230
240
  fills?: FillEntry[];
231
241
  /** v1.2: the bid this offer responds to */
232
242
  bid?: string;
243
+ /** v1.7 claim-to-fill: the current exclusive claimer + the height their window ends. Lazy lapse —
244
+ * a past claimUntilHeight just means no live claim (the fields persist as the last-claim record). */
245
+ claimedBy?: string;
246
+ claimUntilHeight?: number;
233
247
  fill?: FillEntry;
234
248
  }
235
249
  type BidStatus = "open" | "cancelled" | "expired" | "done";
@@ -322,4 +336,4 @@ declare function resolve(events: ChainEvent[], tipHeight: number): CairnXState;
322
336
  * history.) Keys sort in ordinal (code-unit) order at every depth. */
323
337
  declare function canonicalState(s: CairnXState): string;
324
338
 
325
- export { ACTIVATION_HEIGHT, ADDR_RE, AMOUNT_RE, type AppliedEvent, type AttestEvent, type BalanceState, type BidRecord, type BidState, type BidStatus, type BuiltRecord, COMMIT_MAX_BLOCKS, CONF_TOKEN_FILL, type CairnXRecord, type CairnXState, type ChainEvent, DEPLOY_FEE, DOMAIN, type DeployRecord, EPOCH_LEN, FEE_BPS, type FillEntry, type Give, HASH_RE, MAX_AMOUNT, MAX_RECORD_BYTES, type MintRecord, NAME_GRACE_EPOCHS, NAME_PREMIUM_DECAY_EPOCHS, NAME_PREMIUM_START, NAME_RE, NAME_TERM_EPOCHS, type NameCommitRecord, type NameRecord, type NameRenewRecord, type NameSetRecord, type NameState, type NameXferRecord, type OfferCancelAllRecord, type OfferRecord, type OfferState, type OfferStatus, type ProposeEvent, RESERVED_NAMES, SCORE_CANCEL, SCORE_FILL, TICKER_RE, TREASURY_ADDR, type TokenMetaRecord, type TokenState, type TransferRecord, V11_HEIGHT, V12_HEIGHT, V13_HEIGHT, V14_HEIGHT, V15_HEIGHT, type Want, bid, buildRecord, canonicalState, deploy, epochOf, expiredClaimFee, isName, isNameGive, isTokenWant, mint, nameClaim, nameCommit, nameCommitRecord, nameRegFee, nameRenew, nameSet, nameXfer, offer, offerCancelAll, parseAmount, parseRecord, resolve, tokenMeta, tradeFee, transfer };
339
+ export { ACTIVATION_HEIGHT, ADDR_RE, AMOUNT_RE, type AppliedEvent, type AttestEvent, type BalanceState, type BidRecord, type BidState, type BidStatus, type BuiltRecord, CLAIM_COOLDOWN_BLOCKS, CLAIM_WINDOW_BLOCKS, COMMIT_MAX_BLOCKS, CONF_TOKEN_FILL, type CairnXRecord, type CairnXState, type ChainEvent, DEPLOY_FEE, DOMAIN, type DeployRecord, EPOCH_LEN, FEE_BPS, FEE_BPS_V16, type FillEntry, type Give, HASH_RE, MAX_ACTIVE_CLAIMS, MAX_AMOUNT, MAX_RECORD_BYTES, type MintRecord, NAME_GRACE_EPOCHS, NAME_PREMIUM_DECAY_EPOCHS, NAME_PREMIUM_START, NAME_RE, NAME_TERM_EPOCHS, type NameCommitRecord, type NameRecord, type NameRenewRecord, type NameSetRecord, type NameState, type NameXferRecord, type OfferCancelAllRecord, type OfferRecord, type OfferState, type OfferStatus, type ProposeEvent, REBATE_BPS, REBATE_FLAT, RESERVED_NAMES, SCORE_CANCEL, SCORE_CLAIM, SCORE_FILL, TICKER_RE, TREASURY_ADDR, type TokenMetaRecord, type TokenState, type TransferRecord, V11_HEIGHT, V12_HEIGHT, V13_HEIGHT, V14_HEIGHT, V15_HEIGHT, V16_HEIGHT, V17_HEIGHT, type Want, bid, buildRecord, canonicalState, deploy, epochOf, expiredClaimFee, isName, isNameGive, isTokenWant, makerRebate, mint, nameClaim, nameCommit, nameCommitRecord, nameRegFee, nameRenew, nameSet, nameXfer, offer, offerCancelAll, parseAmount, parseRecord, resolve, tokenMeta, tradeFee, transfer };
package/dist/index.d.ts CHANGED
@@ -5,6 +5,8 @@ declare const V12_HEIGHT = 30300;
5
5
  declare const V13_HEIGHT = 31100;
6
6
  declare const V14_HEIGHT = 31400;
7
7
  declare const V15_HEIGHT = 32000;
8
+ declare const V16_HEIGHT = 33600;
9
+ declare const V17_HEIGHT = 34000;
8
10
  declare const EPOCH_LEN = 30;
9
11
  declare const NAME_TERM_EPOCHS = 8760;
10
12
  declare const NAME_GRACE_EPOCHS = 720;
@@ -17,12 +19,20 @@ declare const MAX_RECORD_BYTES = 512;
17
19
  declare const MAX_AMOUNT: bigint;
18
20
  declare const SCORE_FILL = 100;
19
21
  declare const SCORE_CANCEL = 0;
22
+ declare const SCORE_CLAIM = 50;
23
+ declare const CLAIM_WINDOW_BLOCKS = 15;
24
+ declare const MAX_ACTIVE_CLAIMS = 3;
25
+ declare const CLAIM_COOLDOWN_BLOCKS = 15;
20
26
  declare const CONF_TOKEN_FILL = 1000000;
21
27
  declare const TREASURY_ADDR = "0x6b09ce74e6070ebc982ab0fb793a211c4d24f016";
22
28
  declare const FEE_BPS = 100;
29
+ declare const FEE_BPS_V16 = 150;
30
+ declare const REBATE_FLAT = 25000000n;
31
+ declare const REBATE_BPS = 50;
23
32
  declare const DEPLOY_FEE = 100000000;
24
33
  declare function nameRegFee(name: string): bigint;
25
- declare const tradeFee: (want: bigint) => bigint;
34
+ declare const tradeFee: (want: bigint, bps?: number) => bigint;
35
+ declare const makerRebate: (value: bigint) => bigint;
26
36
  declare const TICKER_RE: RegExp;
27
37
  declare const ADDR_RE: RegExp;
28
38
  declare const AMOUNT_RE: RegExp;
@@ -230,6 +240,10 @@ interface OfferState {
230
240
  fills?: FillEntry[];
231
241
  /** v1.2: the bid this offer responds to */
232
242
  bid?: string;
243
+ /** v1.7 claim-to-fill: the current exclusive claimer + the height their window ends. Lazy lapse —
244
+ * a past claimUntilHeight just means no live claim (the fields persist as the last-claim record). */
245
+ claimedBy?: string;
246
+ claimUntilHeight?: number;
233
247
  fill?: FillEntry;
234
248
  }
235
249
  type BidStatus = "open" | "cancelled" | "expired" | "done";
@@ -322,4 +336,4 @@ declare function resolve(events: ChainEvent[], tipHeight: number): CairnXState;
322
336
  * history.) Keys sort in ordinal (code-unit) order at every depth. */
323
337
  declare function canonicalState(s: CairnXState): string;
324
338
 
325
- export { ACTIVATION_HEIGHT, ADDR_RE, AMOUNT_RE, type AppliedEvent, type AttestEvent, type BalanceState, type BidRecord, type BidState, type BidStatus, type BuiltRecord, COMMIT_MAX_BLOCKS, CONF_TOKEN_FILL, type CairnXRecord, type CairnXState, type ChainEvent, DEPLOY_FEE, DOMAIN, type DeployRecord, EPOCH_LEN, FEE_BPS, type FillEntry, type Give, HASH_RE, MAX_AMOUNT, MAX_RECORD_BYTES, type MintRecord, NAME_GRACE_EPOCHS, NAME_PREMIUM_DECAY_EPOCHS, NAME_PREMIUM_START, NAME_RE, NAME_TERM_EPOCHS, type NameCommitRecord, type NameRecord, type NameRenewRecord, type NameSetRecord, type NameState, type NameXferRecord, type OfferCancelAllRecord, type OfferRecord, type OfferState, type OfferStatus, type ProposeEvent, RESERVED_NAMES, SCORE_CANCEL, SCORE_FILL, TICKER_RE, TREASURY_ADDR, type TokenMetaRecord, type TokenState, type TransferRecord, V11_HEIGHT, V12_HEIGHT, V13_HEIGHT, V14_HEIGHT, V15_HEIGHT, type Want, bid, buildRecord, canonicalState, deploy, epochOf, expiredClaimFee, isName, isNameGive, isTokenWant, mint, nameClaim, nameCommit, nameCommitRecord, nameRegFee, nameRenew, nameSet, nameXfer, offer, offerCancelAll, parseAmount, parseRecord, resolve, tokenMeta, tradeFee, transfer };
339
+ export { ACTIVATION_HEIGHT, ADDR_RE, AMOUNT_RE, type AppliedEvent, type AttestEvent, type BalanceState, type BidRecord, type BidState, type BidStatus, type BuiltRecord, CLAIM_COOLDOWN_BLOCKS, CLAIM_WINDOW_BLOCKS, COMMIT_MAX_BLOCKS, CONF_TOKEN_FILL, type CairnXRecord, type CairnXState, type ChainEvent, DEPLOY_FEE, DOMAIN, type DeployRecord, EPOCH_LEN, FEE_BPS, FEE_BPS_V16, type FillEntry, type Give, HASH_RE, MAX_ACTIVE_CLAIMS, MAX_AMOUNT, MAX_RECORD_BYTES, type MintRecord, NAME_GRACE_EPOCHS, NAME_PREMIUM_DECAY_EPOCHS, NAME_PREMIUM_START, NAME_RE, NAME_TERM_EPOCHS, type NameCommitRecord, type NameRecord, type NameRenewRecord, type NameSetRecord, type NameState, type NameXferRecord, type OfferCancelAllRecord, type OfferRecord, type OfferState, type OfferStatus, type ProposeEvent, REBATE_BPS, REBATE_FLAT, RESERVED_NAMES, SCORE_CANCEL, SCORE_CLAIM, SCORE_FILL, TICKER_RE, TREASURY_ADDR, type TokenMetaRecord, type TokenState, type TransferRecord, V11_HEIGHT, V12_HEIGHT, V13_HEIGHT, V14_HEIGHT, V15_HEIGHT, V16_HEIGHT, V17_HEIGHT, type Want, bid, buildRecord, canonicalState, deploy, epochOf, expiredClaimFee, isName, isNameGive, isTokenWant, makerRebate, mint, nameClaim, nameCommit, nameCommitRecord, nameRegFee, nameRenew, nameSet, nameXfer, offer, offerCancelAll, parseAmount, parseRecord, resolve, tokenMeta, tradeFee, transfer };