@inversealtruism/cairnx-core 0.1.37 → 0.1.40

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/dist/index.cjs CHANGED
@@ -39,6 +39,7 @@ __export(index_exports, {
39
39
  EPOCH_LEN: () => import_csd_codec5.EPOCH_LEN,
40
40
  FCLAIM_KEYS: () => FCLAIM_KEYS,
41
41
  FCLAIM_MAX_EPOCH_AHEAD: () => FCLAIM_MAX_EPOCH_AHEAD,
42
+ FCLAIM_WINDOW_MIN: () => FCLAIM_WINDOW_MIN,
42
43
  FEE_BPS: () => FEE_BPS,
43
44
  FEE_BPS_V16: () => FEE_BPS_V16,
44
45
  FEE_GATE_MARGIN_BLOCKS: () => FEE_GATE_MARGIN_BLOCKS,
@@ -106,8 +107,11 @@ __export(index_exports, {
106
107
  V26_HEIGHT: () => V26_HEIGHT,
107
108
  V27_HEIGHT: () => V27_HEIGHT,
108
109
  V28_HEIGHT: () => V28_HEIGHT,
110
+ V29_HEIGHT: () => V29_HEIGHT,
109
111
  ZERO_ADDR: () => ZERO_ADDR,
110
112
  bid: () => bid,
113
+ bindOfferTerms: () => bindOfferTerms,
114
+ bindProvenOffer: () => bindProvenOffer,
111
115
  blockReward: () => import_csd_codec5.blockReward,
112
116
  buildFeeHeight: () => buildFeeHeight,
113
117
  buildRecord: () => buildRecord,
@@ -122,7 +126,10 @@ __export(index_exports, {
122
126
  fclaim: () => fclaim,
123
127
  fclaimEpochFor: () => fclaimEpochFor,
124
128
  fclaimHoldEnd: () => fclaimHoldEnd,
129
+ feeBpsAt: () => feeBpsAt,
130
+ fillEndorsement: () => fillEndorsement,
125
131
  fillIsSafe: () => fillIsSafe,
132
+ fillOutputPlan: () => fillOutputPlan,
126
133
  fillTargetId: () => fillTargetId,
127
134
  finalizeWinnerCheck: () => finalizeWinnerCheck,
128
135
  hasLiveClaim: () => hasLiveClaim,
@@ -151,6 +158,7 @@ __export(index_exports, {
151
158
  pickPrimaryName: () => pickPrimaryName,
152
159
  previewFill: () => previewFill,
153
160
  primaryRankBefore: () => primaryRankBefore,
161
+ provenOfferTerms: () => provenOfferTerms,
154
162
  replayLiveHold: () => replayLiveHold,
155
163
  requiredClaimDepth: () => requiredClaimDepth,
156
164
  requiredFillOutputs: () => requiredFillOutputs,
@@ -158,6 +166,7 @@ __export(index_exports, {
158
166
  tokenMeta: () => tokenMeta,
159
167
  tradeFee: () => tradeFee,
160
168
  transfer: () => transfer,
169
+ unsafeMintProvenOfferTerms: () => unsafeMintProvenOfferTerms,
161
170
  verifyFillSpv: () => verifyFillSpv
162
171
  });
163
172
  module.exports = __toCommonJS(index_exports);
@@ -195,7 +204,7 @@ var CLAIM_FILL_GRACE_BLOCKS = 5;
195
204
  var MAX_ACTIVE_CLAIMS = 3;
196
205
  var CLAIM_COOLDOWN_BLOCKS = 15;
197
206
  var FCLAIM_MAX_EPOCH_AHEAD = 2;
198
- var FILL_TIP_MARGIN = 2;
207
+ var FILL_TIP_MARGIN = 4;
199
208
  var CONF_TOKEN_FILL = 1e6;
200
209
  var TREASURY_ADDR = "0x6b09ce74e6070ebc982ab0fb793a211c4d24f016";
201
210
  var FEE_BPS = 100;
@@ -255,9 +264,14 @@ var FINALIZE_TIP_MARGIN = 2;
255
264
  var V26_HEIGHT = 46480;
256
265
  var V27_HEIGHT = 46520;
257
266
  var V28_HEIGHT = 6e4;
267
+ var V29_HEIGHT = 88e3;
258
268
  var epochOf = (height) => Math.floor(height / import_csd_codec.EPOCH_LEN);
259
269
  var claimWindowAt = (height) => height >= V20_HEIGHT ? CLAIM_WINDOW_BLOCKS_V20 : CLAIM_WINDOW_BLOCKS;
260
- var claimWindowOf = (claimUntilHeight) => claimUntilHeight - CLAIM_WINDOW_BLOCKS_V20 >= V20_HEIGHT ? CLAIM_WINDOW_BLOCKS_V20 : CLAIM_WINDOW_BLOCKS;
270
+ var FCLAIM_WINDOW_MIN = CLAIM_WINDOW_BLOCKS_V20 + CLAIM_FILL_GRACE_BLOCKS + 1;
271
+ var claimWindowOf = (claimUntilHeight, claimTxid) => {
272
+ if (claimTxid !== void 0) return FCLAIM_WINDOW_MIN;
273
+ return claimUntilHeight - CLAIM_WINDOW_BLOCKS_V20 >= V20_HEIGHT ? CLAIM_WINDOW_BLOCKS_V20 : CLAIM_WINDOW_BLOCKS;
274
+ };
261
275
  var claimGraceOf = (claimUntilHeight, claimTxid) => claimTxid !== void 0 ? 0 : claimUntilHeight - CLAIM_WINDOW_BLOCKS_V20 >= V20_HEIGHT ? CLAIM_FILL_GRACE_BLOCKS : 0;
262
276
  var fclaimEpochFor = (tipHeight, offerExpiresEpoch) => Math.min(epochOf(tipHeight + CLAIM_WINDOW_BLOCKS_V20 + CLAIM_FILL_GRACE_BLOCKS), offerExpiresEpoch);
263
277
  var fclaimHoldEnd = (expiresEpoch) => (expiresEpoch + 1) * import_csd_codec.EPOCH_LEN - 1;
@@ -519,6 +533,17 @@ function resolve(events, tipHeight) {
519
533
  b.kind === "propose" ? b.id : b.txid
520
534
  )
521
535
  );
536
+ const eid = (e) => e.kind === "propose" ? e.id : e.txid;
537
+ const seenIds = /* @__PURE__ */ new Set();
538
+ const applied = [];
539
+ for (const e of ordered) {
540
+ if (e.height >= V29_HEIGHT) {
541
+ const k = eid(e);
542
+ if (seenIds.has(k)) continue;
543
+ seenIds.add(k);
544
+ }
545
+ applied.push(e);
546
+ }
522
547
  const tokens = /* @__PURE__ */ new Map();
523
548
  const balances = /* @__PURE__ */ new Map();
524
549
  const names = /* @__PURE__ */ new Map();
@@ -627,7 +652,7 @@ function resolve(events, tipHeight) {
627
652
  bal(t, who).available += amt;
628
653
  offerLock.delete(o.id);
629
654
  };
630
- for (const ev of ordered) {
655
+ for (const ev of applied) {
631
656
  if (ev.height < ACTIVATION_HEIGHT) continue;
632
657
  if (ev.height !== pendingBlock) {
633
658
  applyPendingCancels();
@@ -1186,7 +1211,7 @@ function resolve(events, tipHeight) {
1186
1211
  continue;
1187
1212
  }
1188
1213
  let liveN = 0;
1189
- for (const x of offers.values()) if (x.claimedBy === who && claimHeld(x, ev.height)) liveN++;
1214
+ for (const x of offers.values()) if (x.claimedBy === who && claimHeld(x, ev.height) && (ev.height < V29_HEIGHT || x.status === "open")) liveN++;
1190
1215
  if (liveN >= MAX_ACTIVE_CLAIMS) {
1191
1216
  deny(`max ${MAX_ACTIVE_CLAIMS} live claims per address`);
1192
1217
  continue;
@@ -1440,7 +1465,7 @@ function resolve(events, tipHeight) {
1440
1465
  continue;
1441
1466
  }
1442
1467
  let liveN = 0;
1443
- for (const x of offers.values()) if (x.claimedBy === who && claimHeld(x, ev.height)) liveN++;
1468
+ for (const x of offers.values()) if (x.claimedBy === who && claimHeld(x, ev.height) && (ev.height < V29_HEIGHT || x.status === "open")) liveN++;
1444
1469
  if (liveN >= MAX_ACTIVE_CLAIMS) {
1445
1470
  note(ev, ev.txid, "claim", false, `max ${MAX_ACTIVE_CLAIMS} live claims per address`);
1446
1471
  continue;
@@ -1574,6 +1599,17 @@ function requiredFillOutputs(offer2, payRaw) {
1574
1599
  add(offer2.seller, p.rebate);
1575
1600
  return [...need].map(([to, value]) => ({ to, value }));
1576
1601
  }
1602
+ function fillOutputPlan(offer2, payRaw) {
1603
+ const preview = previewFill(offer2, payRaw);
1604
+ if (isTokenWant(offer2.want)) {
1605
+ if (offer2.status !== "open") return { kind: "undeliverable", reason: "not-open", preview };
1606
+ return { kind: "token-settled", outputs: [], confidence: CONF_TOKEN_FILL, preview };
1607
+ }
1608
+ if (!preview.deliverable) return { kind: "undeliverable", reason: preview.reason === "not-open" || preview.reason === "below-min" ? preview.reason : "zero-delivery", preview };
1609
+ const outputs = requiredFillOutputs(offer2, payRaw);
1610
+ if (outputs === null) return { kind: "undeliverable", reason: "zero-delivery", preview };
1611
+ return { kind: "csd-outputs", outputs, preview };
1612
+ }
1577
1613
  var FEE_GATE_MARGIN_BLOCKS = 5;
1578
1614
  var NAME_FEE_GATES = [V18_HEIGHT, V24_HEIGHT];
1579
1615
  var buildFeeHeight = (tip) => {
@@ -1609,6 +1645,29 @@ function fillIsSafe(offer2, me, pay, tip) {
1609
1645
  }
1610
1646
  return { safe: true, reason: "ok", preview };
1611
1647
  }
1648
+ function fillEndorsement(offer2, me, pay, tip, opts) {
1649
+ const preview = previewFill(offer2, pay);
1650
+ const refuse = (reason) => ({ verdict: "refused", reason, preview });
1651
+ if (offer2.status !== "open") return refuse(`offer is ${offer2.status}`);
1652
+ if (offer2.taker !== void 0 && offer2.taker.toLowerCase() !== me.toLowerCase())
1653
+ return refuse("taker-bound offer - not bound to you");
1654
+ if (isOpenClaimLane(offer2, tip) && !hasLiveClaim(offer2, me, tip))
1655
+ return refuse("open CSD offer - claim it first and fill while your claim is live");
1656
+ const expected = fillTargetId(offer2, tip);
1657
+ const holdRouted = expected.toLowerCase() !== offer2.id.toLowerCase();
1658
+ if (opts?.fillTargetId !== void 0) {
1659
+ if (String(opts.fillTargetId).toLowerCase() !== expected.toLowerCase()) return refuse(holdRouted ? "v2.8: a live fclaim hold routes this fill - the attest must target the fclaim txid, not the offer id (an offer-txid fill is chain-rejected after the payment moved)" : "the attested fill target does not match this offer's routing (attest the offer id)");
1660
+ } else if (holdRouted) {
1661
+ return refuse("v2.8: a live fclaim hold routes this fill - pass opts.fillTargetId (use fillTargetId(offer, tip)) so the endorsement can verify what your attest targets");
1662
+ }
1663
+ if (isTokenWant(offer2.want))
1664
+ return { verdict: "not-endorsable", reason: "token-priced want - deliverability is the attester's token balance, which a pure record predicate cannot see; NOT an endorsement and NOT a refusal (verify your token balance + proven terms, then proceed)", preview };
1665
+ if (!preview.deliverable) {
1666
+ if (preview.reason === "below-min") return refuse("payment is below the offer minimum");
1667
+ return refuse("this payment would deliver 0 tokens - refusing (the CSD would be lost)");
1668
+ }
1669
+ return { verdict: "endorsed", reason: "ok", preview };
1670
+ }
1612
1671
  function finalizeWinnerCheck(nameState, me, commitHeight, tip) {
1613
1672
  const m = me.toLowerCase();
1614
1673
  if (!nameState) return { safe: false, reason: "no reservation on-chain (displaced, swept, or never accepted) \u2014 a finalize now would burn the fee" };
@@ -1731,10 +1790,74 @@ async function verifyFillSpv(offerId, fclaimTxid, me, io, opts) {
1731
1790
  }
1732
1791
  const dp = previewFill({ ...r.offer, status: "open" }, pay);
1733
1792
  if (!dp.deliverable || dp.got < 1n) return no("this fill would deliver 0 units - refusing (the CSD would be lost)");
1793
+ if (opts.sums !== void 0) {
1794
+ const req = requiredFillOutputs({ ...r.offer, status: "open" }, pay);
1795
+ if (req === null) return no("the proven offer state cannot size this payment - refusing");
1796
+ const proven2 = new Map(req.map((o) => [o.to, o.value]));
1797
+ const planned = /* @__PURE__ */ new Map();
1798
+ try {
1799
+ for (const [a, v] of Object.entries(opts.sums)) {
1800
+ const k = String(a).toLowerCase();
1801
+ planned.set(k, (planned.get(k) ?? 0n) + BigInt(v));
1802
+ }
1803
+ } catch {
1804
+ return no("invalid sums (amounts must be base-unit integers)");
1805
+ }
1806
+ const sumsKeys = /* @__PURE__ */ new Set([...proven2.keys(), ...planned.keys()]);
1807
+ for (const k of sumsKeys) if ((proven2.get(k) ?? 0n) !== (planned.get(k) ?? 0n)) return no(`payment does not match the proven fill progress (${k}: planned ${(planned.get(k) ?? 0n).toString()}, proven state requires ${(proven2.get(k) ?? 0n).toString()}) - refusing (an overpay past the real remainder is unrecoverable)`);
1808
+ }
1734
1809
  const holdEnd = fclaimHoldEnd(E);
1735
1810
  if (holdEnd < tip + FILL_TIP_MARGIN) return no(`too close to the hold deadline (holdEnd ${holdEnd}, tip ${tip}) - would strand`);
1736
1811
  return { safe: true, reason: "ok" };
1737
1812
  }
1813
+ var unsafeMintProvenOfferTerms = (t) => t;
1814
+ var feeBpsAt = (height) => height >= V11_HEIGHT ? height >= V16_HEIGHT ? FEE_BPS_V16 : FEE_BPS : 0;
1815
+ function provenOfferTerms(offerRec, provenHeight) {
1816
+ const w = offerRec.want;
1817
+ const g = offerRec.give;
1818
+ return {
1819
+ height: Number(provenHeight),
1820
+ feeBps: feeBpsAt(Number(provenHeight)),
1821
+ value: w.value !== void 0 ? String(w.value) : void 0,
1822
+ taker: offerRec.taker !== void 0 ? String(offerRec.taker).toLowerCase() : void 0,
1823
+ bid: offerRec.bid !== void 0 ? String(offerRec.bid).toLowerCase() : void 0,
1824
+ min: offerRec.min !== void 0 ? String(offerRec.min) : void 0,
1825
+ giveTicker: g.ticker !== void 0 ? String(g.ticker) : void 0,
1826
+ giveAmount: g.amount !== void 0 ? String(g.amount) : void 0,
1827
+ giveName: g.name !== void 0 ? String(g.name) : void 0,
1828
+ wantType: isTokenWant(offerRec.want) ? "token" : "csd"
1829
+ };
1830
+ }
1831
+ function bindOfferTerms(servedOffer, t, opts) {
1832
+ const o = servedOffer;
1833
+ const s = (v) => v === void 0 || v === null ? "" : String(v).toLowerCase();
1834
+ if (Number(o?.height) !== t.height) return true;
1835
+ if (Number(o?.feeBps) !== t.feeBps) return true;
1836
+ if (t.value !== void 0 && String(o?.want?.value) !== t.value) return true;
1837
+ if (s(o?.taker) !== s(t.taker)) return true;
1838
+ if (s(o?.bid) !== s(t.bid)) return true;
1839
+ const om = o?.min;
1840
+ if ((om !== void 0 && om !== null) !== (t.min !== void 0)) return true;
1841
+ if (t.min !== void 0 && String(om) !== t.min) return true;
1842
+ if (opts?.wantType) {
1843
+ if (t.wantType === void 0 || typeof o?.want?.ticker === "string" !== (t.wantType === "token")) return true;
1844
+ }
1845
+ if (opts?.give) {
1846
+ const g = o?.give;
1847
+ if ((g?.ticker !== void 0 && g?.ticker !== null) !== (t.giveTicker !== void 0) || t.giveTicker !== void 0 && String(g?.ticker) !== t.giveTicker) return true;
1848
+ if ((g?.amount !== void 0 && g?.amount !== null) !== (t.giveAmount !== void 0) || t.giveAmount !== void 0 && String(g?.amount) !== t.giveAmount) return true;
1849
+ if ((g?.name !== void 0 && g?.name !== null) !== (t.giveName !== void 0) || t.giveName !== void 0 && String(g?.name) !== t.giveName) return true;
1850
+ }
1851
+ return false;
1852
+ }
1853
+ function bindProvenOffer(offerEv) {
1854
+ const rec = bindRecord(offerEv);
1855
+ if (!rec || rec.t !== "offer") return null;
1856
+ const seller = String(offerEv.proposer).toLowerCase();
1857
+ const w = rec.want;
1858
+ const payto = w.payto && ADDR_RE.test(String(w.payto).toLowerCase()) ? String(w.payto).toLowerCase() : seller;
1859
+ return { payto, seller, terms: provenOfferTerms(rec, offerEv.height) };
1860
+ }
1738
1861
 
1739
1862
  // src/paidto.ts
1740
1863
  function paidToFromOutputs(outputs) {
@@ -1769,6 +1892,7 @@ var import_csd_codec5 = require("@inversealtruism/csd-codec");
1769
1892
  EPOCH_LEN,
1770
1893
  FCLAIM_KEYS,
1771
1894
  FCLAIM_MAX_EPOCH_AHEAD,
1895
+ FCLAIM_WINDOW_MIN,
1772
1896
  FEE_BPS,
1773
1897
  FEE_BPS_V16,
1774
1898
  FEE_GATE_MARGIN_BLOCKS,
@@ -1836,8 +1960,11 @@ var import_csd_codec5 = require("@inversealtruism/csd-codec");
1836
1960
  V26_HEIGHT,
1837
1961
  V27_HEIGHT,
1838
1962
  V28_HEIGHT,
1963
+ V29_HEIGHT,
1839
1964
  ZERO_ADDR,
1840
1965
  bid,
1966
+ bindOfferTerms,
1967
+ bindProvenOffer,
1841
1968
  blockReward,
1842
1969
  buildFeeHeight,
1843
1970
  buildRecord,
@@ -1852,7 +1979,10 @@ var import_csd_codec5 = require("@inversealtruism/csd-codec");
1852
1979
  fclaim,
1853
1980
  fclaimEpochFor,
1854
1981
  fclaimHoldEnd,
1982
+ feeBpsAt,
1983
+ fillEndorsement,
1855
1984
  fillIsSafe,
1985
+ fillOutputPlan,
1856
1986
  fillTargetId,
1857
1987
  finalizeWinnerCheck,
1858
1988
  hasLiveClaim,
@@ -1881,6 +2011,7 @@ var import_csd_codec5 = require("@inversealtruism/csd-codec");
1881
2011
  pickPrimaryName,
1882
2012
  previewFill,
1883
2013
  primaryRankBefore,
2014
+ provenOfferTerms,
1884
2015
  replayLiveHold,
1885
2016
  requiredClaimDepth,
1886
2017
  requiredFillOutputs,
@@ -1888,5 +2019,6 @@ var import_csd_codec5 = require("@inversealtruism/csd-codec");
1888
2019
  tokenMeta,
1889
2020
  tradeFee,
1890
2021
  transfer,
2022
+ unsafeMintProvenOfferTerms,
1891
2023
  verifyFillSpv
1892
2024
  });
package/dist/index.d.cts CHANGED
@@ -28,7 +28,7 @@ declare const CLAIM_FILL_GRACE_BLOCKS = 5;
28
28
  declare const MAX_ACTIVE_CLAIMS = 3;
29
29
  declare const CLAIM_COOLDOWN_BLOCKS = 15;
30
30
  declare const FCLAIM_MAX_EPOCH_AHEAD = 2;
31
- declare const FILL_TIP_MARGIN = 2;
31
+ declare const FILL_TIP_MARGIN = 4;
32
32
  declare const CONF_TOKEN_FILL = 1000000;
33
33
  declare const TREASURY_ADDR = "0x6b09ce74e6070ebc982ab0fb793a211c4d24f016";
34
34
  declare const FEE_BPS = 100;
@@ -73,9 +73,11 @@ declare const FINALIZE_TIP_MARGIN = 2;
73
73
  declare const V26_HEIGHT = 46480;
74
74
  declare const V27_HEIGHT = 46520;
75
75
  declare const V28_HEIGHT = 60000;
76
+ declare const V29_HEIGHT = 88000;
76
77
  declare const epochOf: (height: number) => number;
77
78
  declare const claimWindowAt: (height: number) => number;
78
- declare const claimWindowOf: (claimUntilHeight: number) => number;
79
+ declare const FCLAIM_WINDOW_MIN: number;
80
+ declare const claimWindowOf: (claimUntilHeight: number, claimTxid?: string) => number;
79
81
  declare const claimGraceOf: (claimUntilHeight: number, claimTxid?: string) => number;
80
82
  declare const fclaimEpochFor: (tipHeight: number, offerExpiresEpoch: number) => number;
81
83
  declare const fclaimHoldEnd: (expiresEpoch: number) => number;
@@ -486,11 +488,53 @@ declare function previewFill(offer: OfferState, payRaw: bigint | string | number
486
488
  * claims/takers. Until 2026-07-06 this map was hand-mirrored in the wallet's fillOffer, the cairnx
487
489
  * service txbuild, and TWICE in the cairn trade UI — four copies of fund-loss-class math with no
488
490
  * cross-repo lock. This is now the only place it lives; test/preflight.test.ts pins it against the
489
- * real resolver (outputs accepted; any single-unit per-address underpayment refused). */
491
+ * real resolver (outputs accepted; any single-unit per-address underpayment refused).
492
+ *
493
+ * DOC CORRECTION (B6b / REBIND M1) - the `[]` vs `null` asymmetry is a live hazard, not a convenience:
494
+ * `[]` (token want) means "no CSD outputs are required", it does NOT mean "this fill is checked". Every
495
+ * caller whose safety loop is `for (const o of outs) ...` iterates ZERO times on a token fill and passes
496
+ * silently, while the undeliverable-CSD case (`null`) is explicitly refused. That asymmetry is the
497
+ * mechanical reason the token-fill hole (W1) propagated to every consumer. The token side of a fill is
498
+ * settled from the ATTESTER's token balance and carries the CONF_TOKEN_FILL confidence marker; nothing
499
+ * in this return value verifies any of that.
500
+ * @deprecated Use `fillOutputPlan` - it returns the same math behind a DISCRIMINATED result, so the
501
+ * token-want case cannot be silently conflated with "nothing to check". This function's behavior is
502
+ * FROZEN (published npm API; `[]` is load-bearing in downstream builders and tests) and it will keep
503
+ * working; new callers should not add to the need-map-loop hazard. */
490
504
  declare function requiredFillOutputs(offer: OfferState, payRaw: bigint | string | number): {
491
505
  to: string;
492
506
  value: bigint;
493
507
  }[] | null;
508
+ /** B6b (REBIND M1): the DISCRIMINATED successor to requiredFillOutputs. Same math (it calls
509
+ * requiredFillOutputs - the addr->sum map still lives in exactly one place); the difference is that the
510
+ * three outcomes a caller must treat differently are now three distinct kinds instead of `[] | null`:
511
+ * "csd-outputs" - build EXACTLY these CSD outputs (payto + treasury fee + maker rebate, merged per
512
+ * address). The normal CSD-priced case.
513
+ * "token-settled" - a token-priced offer: there are NO CSD outputs to build, and that is NOT the same
514
+ * as "checked". The fill debits the ATTESTER's want-token balance and the attest MUST
515
+ * carry `confidence` (= CONF_TOKEN_FILL, resolve.ts requires the explicit marker).
516
+ * Verify your token balance and terms yourself before signing.
517
+ * "undeliverable" - the resolver would reject this payment AFTER the CSD moved; do not sign.
518
+ * ADDITIVE and default-safe: requiredFillOutputs is unchanged in behavior (its `[]` is load-bearing in
519
+ * published consumers); this wrapper only makes the pivot impossible to fall through silently. */
520
+ type FillOutputPlan = {
521
+ kind: "csd-outputs";
522
+ outputs: {
523
+ to: string;
524
+ value: bigint;
525
+ }[];
526
+ preview: FillPreview;
527
+ } | {
528
+ kind: "token-settled";
529
+ outputs: [];
530
+ confidence: number;
531
+ preview: FillPreview;
532
+ } | {
533
+ kind: "undeliverable";
534
+ reason: "not-open" | "not-csd-priced" | "below-min" | "zero-delivery";
535
+ preview: FillPreview;
536
+ };
537
+ declare function fillOutputPlan(offer: OfferState, payRaw: bigint | string | number): FillOutputPlan;
494
538
  /** Name-fee build heuristic (app-side, NOT a resolver rule): a name-fee OUTPUT built just below a fee
495
539
  * gate but mined at/after it underpays the new tier → resolver rejects → the treasury-fee UTXO is
496
540
  * forfeit. Within FEE_GATE_MARGIN_BLOCKS below ANY upcoming fee gate, price the BUILD at that gate:
@@ -514,15 +558,59 @@ declare function hasLiveClaim(offer: OfferState, me: string, tip: number): boole
514
558
  declare function fillTargetId(offer: OfferState, tip: number): string;
515
559
  /** The union verdict a client must clear BEFORE signing a fill of `offer` paying `pay`, as `me`, at `tip`.
516
560
  * Closes C2/C3/C4: status open, deliverability >= 1 token, live-claim holdership for the open-CSD lane,
517
- * and taker match. `safe:true` ⇒ the fill is guaranteed to be accepted by the deterministic gates a
518
- * payer can verify at signing time (the irreducible timing residual — CLAIM_FILL_GRACE_BLOCKS late mine
519
- * — is documented, not closable by a preflight). Returns the preview so the caller can size outputs. */
561
+ * and taker match. Returns the preview so the caller can size outputs.
562
+ *
563
+ * DOC CORRECTION (B6b / REBIND W10) - the historical claim that `safe:true` means "the fill is guaranteed
564
+ * to be accepted by the deterministic gates a payer can verify at signing time" OVER-STATES this predicate
565
+ * on two counts, both live:
566
+ * 1. For a TOKEN-priced want it returns `safe:true` unconditionally ("deliverability is the buyer's
567
+ * balance"). That is an honest statement of what it cannot see, but as a boolean it reads as an
568
+ * ENDORSEMENT of the un-verifiable path - the never-over-claim rule this codebase holds elsewhere.
569
+ * 2. It never receives the FILL TARGET id, so it cannot implement the v2.8 Correction-1 clause: during
570
+ * a live fclaim hold the chain rejects an attest on the OFFER txid (the payment must attest the
571
+ * FCLAIM txid), and this predicate says `safe:true` for exactly that doomed fill.
572
+ * @deprecated Use `fillEndorsement` - a discriminated verdict ("endorsed" / "refused" / "not-endorsable")
573
+ * plus the `fillTargetId` parameter that closes both gaps. This function's verdicts are FROZEN (published
574
+ * npm API; flipping them could hard-refuse honest fills in unknowable third-party dApps) and it keeps
575
+ * working; it must not be "hardened" in place. */
520
576
  interface FillSafety {
521
577
  safe: boolean;
522
578
  reason: string;
523
579
  preview: FillPreview;
524
580
  }
525
581
  declare function fillIsSafe(offer: OfferState, me: string, pay: bigint | string | number, tip: number): FillSafety;
582
+ /** B6b (REBIND W10): the DISCRIMINATED successor to fillIsSafe. Three verdicts, and consuming them
583
+ * correctly is part of the contract:
584
+ * "endorsed" - every deterministic gate a payer can verify at signing time passes (status, taker,
585
+ * open-lane holdership, deliverability, and - NEW - the v2.8 fill-target routing).
586
+ * "refused" - the chain WILL reject this fill after the payment moved. Do not sign.
587
+ * "not-endorsable" - a TOKEN-priced want: deliverability is the attester's token balance, which this
588
+ * pure predicate cannot see. This is HONEST NON-ENDORSEMENT, not refusal: proceed
589
+ * with your own token-balance and proven-terms checks (a consumer that treats this
590
+ * as "refuse" hard-blocks every honest token fill - the named B7f trap).
591
+ *
592
+ * `opts.fillTargetId` is the proposal txid your attest will actually target. Pass it whenever you have
593
+ * it (= `fillTargetId(offer, tip)` for an honest builder). The v2.8 Correction-1 clause (resolve.ts
594
+ * openFillReject): during a live fclaim hold an attest on the OFFER txid is rejected while the payment
595
+ * still moves - the exact doomed fill the deprecated fillIsSafe endorses. If the offer carries a live
596
+ * fclaim-hold routing and no target is supplied, the endorsement fails CLOSED with instructions rather
597
+ * than guessing what your builder will attest. */
598
+ type FillEndorsement = {
599
+ verdict: "endorsed";
600
+ reason: "ok";
601
+ preview: FillPreview;
602
+ } | {
603
+ verdict: "refused";
604
+ reason: string;
605
+ preview: FillPreview;
606
+ } | {
607
+ verdict: "not-endorsable";
608
+ reason: string;
609
+ preview: FillPreview;
610
+ };
611
+ declare function fillEndorsement(offer: OfferState, me: string, pay: bigint | string | number, tip: number, opts?: {
612
+ fillTargetId?: string;
613
+ }): FillEndorsement;
526
614
  /** C1: may `me` safely sign the fee-bearing registration `nfinalize` for `nameState` committed at
527
615
  * `commitHeight`? The reg fee rides nfinalize; a finalize on a reservation that was displaced, has
528
616
  * expired, OR is raised before the displacement contest froze is REJECTED after the fee moved (a burn).
@@ -599,15 +687,85 @@ interface FillVerdict {
599
687
  * replay cannot see the buyer's other-offer holds, and MAX_ACTIVE_CLAIMS is the one grant clause counted
600
688
  * across offers, so without this the surface would false-accept a cap-denied fclaim. `opts.pay` overrides the
601
689
  * payment (base units to want.payto) for a PARTIAL tail-fill; defaults to the offer's full want.value.
690
+ *
691
+ * `opts.sums` (OPT-IN, B6a / REBIND W3; default OFF = byte-identical verdicts for existing callers) binds the
692
+ * caller's PLANNED per-address CSD payment sums to the PROVEN offer state: requiredFillOutputs is re-run over
693
+ * the merkle-proven, replayed offer (so `paid`/`delivered` are the chain's, not a served lie) and the caller's
694
+ * map must match it EXACTLY, address for address. This closes the W3 overpay: a resolver serving `paid:"0"`
695
+ * for a 90%-filled partial made callers size the FULL want while the chain credits only the remainder - the
696
+ * difference was permanently overpaid. Pass the SAME per-address sums you will build (the wallet's need-map
697
+ * shape: payto + treasury fee + maker rebate, MERGED per address - `payto === seller` merges the rebate leg).
698
+ * DELIBERATELY NOT the scalar `dp.pay !== pay` form: that refuses honest fills on both live callers (the
699
+ * wallet's per-address sum includes the maker rebate when payto === seller; the site passes no pay at all).
602
700
  */
603
701
  declare function verifyFillSpv(offerId: string, fclaimTxid: string, me: string, io: FillSpvIo, opts: {
604
702
  myLiveHoldsAtGrant: number;
605
703
  pay?: bigint | string | number;
704
+ sums?: Record<string, bigint | string | number>;
606
705
  }): Promise<FillVerdict>;
706
+ interface ProvenOfferTerms {
707
+ height: number;
708
+ feeBps: number;
709
+ value?: string;
710
+ taker?: string;
711
+ bid?: string;
712
+ min?: string;
713
+ giveTicker?: string;
714
+ giveAmount?: string;
715
+ giveName?: string;
716
+ wantType?: "csd" | "token";
717
+ }
718
+ declare const PROVEN_TERMS_MINT: unique symbol;
719
+ type MintedProvenOfferTerms = ProvenOfferTerms & {
720
+ readonly [PROVEN_TERMS_MINT]: "cairnx-core/provenOfferTerms";
721
+ };
722
+ /** UNSAFE escape hatch, TESTS ONLY: brand a hand-built terms object. Production code must never call this -
723
+ * hand-built terms are exactly the W2 defect class the brand exists to make unrepresentable. */
724
+ declare const unsafeMintProvenOfferTerms: (t: ProvenOfferTerms) => MintedProvenOfferTerms;
725
+ declare const feeBpsAt: (height: number) => number;
726
+ declare function provenOfferTerms(offerRec: OfferRecord, provenHeight: number): MintedProvenOfferTerms;
727
+ /**
728
+ * The fill-boundary TERM-MISMATCH verdict: `true` iff any fee/rebate/partial-sizing field of the resolver-
729
+ * SERVED offer diverges from the merkle-proven terms `t`. FAIL-CLOSED semantics (any divergence => true =>
730
+ * the caller refuses). Byte-identical in behaviour to the wallet's old provenTermsMismatch and the site's
731
+ * old inline amount-leg bind (they were reconciled to be one predicate here):
732
+ * - height (offer.height vs t.height)
733
+ * - feeBps (offer.feeBps vs t.feeBps = feeBpsAt(creation height))
734
+ * - value (offer.want.value vs t.value, only when the proven offer is CSD-priced)
735
+ * - taker (offer.taker vs t.taker, case-insensitive, undefined/null == "")
736
+ * - bid (offer.bid vs t.bid, same normalization)
737
+ * - min presence AND value: an ADDED spurious min (whole->partial rebate-drop burn) OR a deflated min
738
+ * both mismatch. EXPLICIT presence (a served min="" must not slip past a proven-absent min).
739
+ * `value` is bound only when `t.value` is defined so a token<->token offer (no CSD value) is not spuriously
740
+ * refused; a caller that binds want.value separately (the site does) may still pass it here (redundant-safe).
741
+ *
742
+ * B6a (REBIND W2 legs + W7) OPT-IN legs, via the third argument (default OFF: a 2-arg call is byte-identical
743
+ * to the pre-B6 predicate on every input). The 3-arg overload requires MINTED terms (the brand), so a caller
744
+ * adopting the new legs cannot feed them a hand-built terms object that leaves the new fields undefined -
745
+ * that shape would false-refuse every honest fill (the W2 trap this file documents).
746
+ * opts.give - bind give.ticker / give.amount / give.name: EXPLICIT PRESENCE (a served give growing or
747
+ * losing a field mismatches) AND verbatim string equality. Closes the W7 shortchange (a
748
+ * genuine offer served with give.amount inflated a millionfold passes every legacy leg).
749
+ * opts.wantType - the SYMMETRIC want-type refusal: the served offer's want type (token iff want.ticker is
750
+ * a string, the isTokenWant pivot) must equal the proven type. The legacy value leg already
751
+ * catches proven-CSD-served-as-token (String(undefined) mismatches t.value); this closes
752
+ * the reverse, proven-token-served-as-CSD, which today only wallet.ts catches one-sidedly.
753
+ */
754
+ interface BindTermsOpts {
755
+ give?: boolean;
756
+ wantType?: boolean;
757
+ }
758
+ declare function bindOfferTerms(servedOffer: unknown, t: ProvenOfferTerms): boolean;
759
+ declare function bindOfferTerms(servedOffer: unknown, t: MintedProvenOfferTerms, opts: BindTermsOpts): boolean;
760
+ declare function bindProvenOffer(offerEv: ProvenPropose): {
761
+ payto: string;
762
+ seller: string;
763
+ terms: MintedProvenOfferTerms;
764
+ } | null;
607
765
 
608
766
  declare function paidToFromOutputs(outputs: readonly {
609
767
  addr: string;
610
768
  value: number;
611
769
  }[]): Record<string, string>;
612
770
 
613
- export { ACTIVATION_HEIGHT, ADDR_RE, AMOUNT_RE, type AppliedEvent, type AttestEvent, BID_KEYS, type BalanceState, type BidRecord, type BidState, type BidStatus, type BuiltRecord, CLAIM_ATTACKER_Q, CLAIM_COOLDOWN_BLOCKS, CLAIM_FILL_GRACE_BLOCKS, CLAIM_MIN_DEPTH, CLAIM_WINDOW_BLOCKS, CLAIM_WINDOW_BLOCKS_V20, COMMIT_MAX_BLOCKS, COMMIT_REVEAL_MIN_DEPTH, CONF_TOKEN_FILL, type CairnXRecord, type CairnXState, type ChainEvent, DEPLOY_FEE, DEPLOY_KEYS, DOMAIN, type DeployRecord, FCLAIM_KEYS, FCLAIM_MAX_EPOCH_AHEAD, FEE_BPS, FEE_BPS_V16, FEE_GATE_MARGIN_BLOCKS, FILL_TIP_MARGIN, FINALIZE_TIP_MARGIN, type FclaimRecord, type FillEntry, type FillPreview, type FillSafety, type FillSpvIo, type FillVerdict, GAP_NEEDED, type Give, HASH_RE, type HoldReplay, MAX_ACTIVE_CLAIMS, MAX_AMOUNT, MAX_OFFER_EPOCHS, MAX_PENDING_REG, MAX_RECORD_BYTES, MAX_SCAN, MINT_KEYS, type MintRecord, NAME_FEE_LEN3_V24, NAME_FEE_LEN4_V24, NAME_FEE_LONG_V24, NAME_FEE_MID_V24, NAME_FEE_SHORT_V18, NAME_FEE_V18, NAME_GRACE_EPOCHS, NAME_KEYS, NAME_PREMIUM_DECAY_EPOCHS, NAME_PREMIUM_START, NAME_RE, NAME_TERM_EPOCHS, NFINALIZE_KEYS, NPROFILE_KEYS, type NameCommitRecord, type NameFinalizeRecord, type NameProfileRecord, type NameRecord, type NameRenewRecord, type NameSetRecord, type NameState, type NameXferRecord, OFFER_KEYS, type OfferCancelAllRecord, type OfferRecord, type OfferState, type OfferStatus, PKEY, PROFILE_MAX_KEYS, PROFILE_MAX_VALUE_BYTES, type ProposeEvent, type ProvenAttest, type ProvenEvent, type ProvenPropose, REBATE_BPS, REBATE_FLAT, REG_COMMIT_MAX_BLOCKS, REG_FINALIZE_GRACE_BLOCKS, RESERVED_NAMES, SALT_RE, SCAN_MARGIN, SCORE_CANCEL, SCORE_CLAIM, SCORE_FILL, TICKER_RE, TRANSFER_KEYS, TREASURY_ADDR, type TokenMetaRecord, type TokenState, type TransferRecord, V11_HEIGHT, V12_HEIGHT, V13_HEIGHT, V14_HEIGHT, V15_HEIGHT, V16_HEIGHT, V17_HEIGHT, V18_HEIGHT, V19_HEIGHT, V20_HEIGHT, V21_HEIGHT, V22_HEIGHT, V23_HEIGHT, V24_HEIGHT, V25_HEIGHT, V26_HEIGHT, V27_HEIGHT, V28_HEIGHT, type Want, ZERO_ADDR, bid, buildFeeHeight, buildRecord, canonicalState, claimGraceOf, claimWindowAt, claimWindowOf, deploy, epochOf, expiredClaimFee, fclaim, fclaimEpochFor, fclaimHoldEnd, fillIsSafe, fillTargetId, finalizeWinnerCheck, hasLiveClaim, isName, isNameGive, isOpenClaimLane, isTokenWant, makerRebate, mint, nameClaim, nameCommit, nameCommitRecord, nameFinalize, nameProfile, nameRegFee, nameRenew, nameSet, nameXfer, offer, offerCancelAll, offerExpiryHeightOf, paidToFromOutputs, parseAmount, parseRecord, pickPrimaryName, previewFill, primaryRankBefore, replayLiveHold, requiredClaimDepth, requiredFillOutputs, resolve, tokenMeta, tradeFee, transfer, verifyFillSpv };
771
+ export { ACTIVATION_HEIGHT, ADDR_RE, AMOUNT_RE, type AppliedEvent, type AttestEvent, BID_KEYS, type BalanceState, type BidRecord, type BidState, type BidStatus, type BindTermsOpts, type BuiltRecord, CLAIM_ATTACKER_Q, CLAIM_COOLDOWN_BLOCKS, CLAIM_FILL_GRACE_BLOCKS, CLAIM_MIN_DEPTH, CLAIM_WINDOW_BLOCKS, CLAIM_WINDOW_BLOCKS_V20, COMMIT_MAX_BLOCKS, COMMIT_REVEAL_MIN_DEPTH, CONF_TOKEN_FILL, type CairnXRecord, type CairnXState, type ChainEvent, DEPLOY_FEE, DEPLOY_KEYS, DOMAIN, type DeployRecord, FCLAIM_KEYS, FCLAIM_MAX_EPOCH_AHEAD, FCLAIM_WINDOW_MIN, FEE_BPS, FEE_BPS_V16, FEE_GATE_MARGIN_BLOCKS, FILL_TIP_MARGIN, FINALIZE_TIP_MARGIN, type FclaimRecord, type FillEndorsement, type FillEntry, type FillOutputPlan, type FillPreview, type FillSafety, type FillSpvIo, type FillVerdict, GAP_NEEDED, type Give, HASH_RE, type HoldReplay, MAX_ACTIVE_CLAIMS, MAX_AMOUNT, MAX_OFFER_EPOCHS, MAX_PENDING_REG, MAX_RECORD_BYTES, MAX_SCAN, MINT_KEYS, type MintRecord, type MintedProvenOfferTerms, NAME_FEE_LEN3_V24, NAME_FEE_LEN4_V24, NAME_FEE_LONG_V24, NAME_FEE_MID_V24, NAME_FEE_SHORT_V18, NAME_FEE_V18, NAME_GRACE_EPOCHS, NAME_KEYS, NAME_PREMIUM_DECAY_EPOCHS, NAME_PREMIUM_START, NAME_RE, NAME_TERM_EPOCHS, NFINALIZE_KEYS, NPROFILE_KEYS, type NameCommitRecord, type NameFinalizeRecord, type NameProfileRecord, type NameRecord, type NameRenewRecord, type NameSetRecord, type NameState, type NameXferRecord, OFFER_KEYS, type OfferCancelAllRecord, type OfferRecord, type OfferState, type OfferStatus, PKEY, PROFILE_MAX_KEYS, PROFILE_MAX_VALUE_BYTES, type ProposeEvent, type ProvenAttest, type ProvenEvent, type ProvenOfferTerms, type ProvenPropose, REBATE_BPS, REBATE_FLAT, REG_COMMIT_MAX_BLOCKS, REG_FINALIZE_GRACE_BLOCKS, RESERVED_NAMES, SALT_RE, SCAN_MARGIN, SCORE_CANCEL, SCORE_CLAIM, SCORE_FILL, TICKER_RE, TRANSFER_KEYS, TREASURY_ADDR, type TokenMetaRecord, type TokenState, type TransferRecord, V11_HEIGHT, V12_HEIGHT, V13_HEIGHT, V14_HEIGHT, V15_HEIGHT, V16_HEIGHT, V17_HEIGHT, V18_HEIGHT, V19_HEIGHT, V20_HEIGHT, V21_HEIGHT, V22_HEIGHT, V23_HEIGHT, V24_HEIGHT, V25_HEIGHT, V26_HEIGHT, V27_HEIGHT, V28_HEIGHT, V29_HEIGHT, type Want, ZERO_ADDR, bid, bindOfferTerms, bindProvenOffer, buildFeeHeight, buildRecord, canonicalState, claimGraceOf, claimWindowAt, claimWindowOf, deploy, epochOf, expiredClaimFee, fclaim, fclaimEpochFor, fclaimHoldEnd, feeBpsAt, fillEndorsement, fillIsSafe, fillOutputPlan, fillTargetId, finalizeWinnerCheck, hasLiveClaim, isName, isNameGive, isOpenClaimLane, isTokenWant, makerRebate, mint, nameClaim, nameCommit, nameCommitRecord, nameFinalize, nameProfile, nameRegFee, nameRenew, nameSet, nameXfer, offer, offerCancelAll, offerExpiryHeightOf, paidToFromOutputs, parseAmount, parseRecord, pickPrimaryName, previewFill, primaryRankBefore, provenOfferTerms, replayLiveHold, requiredClaimDepth, requiredFillOutputs, resolve, tokenMeta, tradeFee, transfer, unsafeMintProvenOfferTerms, verifyFillSpv };