@inversealtruism/cairnx-core 0.1.38 → 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,6 +107,7 @@ __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,
111
113
  bindOfferTerms: () => bindOfferTerms,
@@ -125,7 +127,9 @@ __export(index_exports, {
125
127
  fclaimEpochFor: () => fclaimEpochFor,
126
128
  fclaimHoldEnd: () => fclaimHoldEnd,
127
129
  feeBpsAt: () => feeBpsAt,
130
+ fillEndorsement: () => fillEndorsement,
128
131
  fillIsSafe: () => fillIsSafe,
132
+ fillOutputPlan: () => fillOutputPlan,
129
133
  fillTargetId: () => fillTargetId,
130
134
  finalizeWinnerCheck: () => finalizeWinnerCheck,
131
135
  hasLiveClaim: () => hasLiveClaim,
@@ -162,6 +166,7 @@ __export(index_exports, {
162
166
  tokenMeta: () => tokenMeta,
163
167
  tradeFee: () => tradeFee,
164
168
  transfer: () => transfer,
169
+ unsafeMintProvenOfferTerms: () => unsafeMintProvenOfferTerms,
165
170
  verifyFillSpv: () => verifyFillSpv
166
171
  });
167
172
  module.exports = __toCommonJS(index_exports);
@@ -259,9 +264,14 @@ var FINALIZE_TIP_MARGIN = 2;
259
264
  var V26_HEIGHT = 46480;
260
265
  var V27_HEIGHT = 46520;
261
266
  var V28_HEIGHT = 6e4;
267
+ var V29_HEIGHT = 88e3;
262
268
  var epochOf = (height) => Math.floor(height / import_csd_codec.EPOCH_LEN);
263
269
  var claimWindowAt = (height) => height >= V20_HEIGHT ? CLAIM_WINDOW_BLOCKS_V20 : CLAIM_WINDOW_BLOCKS;
264
- 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
+ };
265
275
  var claimGraceOf = (claimUntilHeight, claimTxid) => claimTxid !== void 0 ? 0 : claimUntilHeight - CLAIM_WINDOW_BLOCKS_V20 >= V20_HEIGHT ? CLAIM_FILL_GRACE_BLOCKS : 0;
266
276
  var fclaimEpochFor = (tipHeight, offerExpiresEpoch) => Math.min(epochOf(tipHeight + CLAIM_WINDOW_BLOCKS_V20 + CLAIM_FILL_GRACE_BLOCKS), offerExpiresEpoch);
267
277
  var fclaimHoldEnd = (expiresEpoch) => (expiresEpoch + 1) * import_csd_codec.EPOCH_LEN - 1;
@@ -523,6 +533,17 @@ function resolve(events, tipHeight) {
523
533
  b.kind === "propose" ? b.id : b.txid
524
534
  )
525
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
+ }
526
547
  const tokens = /* @__PURE__ */ new Map();
527
548
  const balances = /* @__PURE__ */ new Map();
528
549
  const names = /* @__PURE__ */ new Map();
@@ -631,7 +652,7 @@ function resolve(events, tipHeight) {
631
652
  bal(t, who).available += amt;
632
653
  offerLock.delete(o.id);
633
654
  };
634
- for (const ev of ordered) {
655
+ for (const ev of applied) {
635
656
  if (ev.height < ACTIVATION_HEIGHT) continue;
636
657
  if (ev.height !== pendingBlock) {
637
658
  applyPendingCancels();
@@ -1190,7 +1211,7 @@ function resolve(events, tipHeight) {
1190
1211
  continue;
1191
1212
  }
1192
1213
  let liveN = 0;
1193
- 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++;
1194
1215
  if (liveN >= MAX_ACTIVE_CLAIMS) {
1195
1216
  deny(`max ${MAX_ACTIVE_CLAIMS} live claims per address`);
1196
1217
  continue;
@@ -1444,7 +1465,7 @@ function resolve(events, tipHeight) {
1444
1465
  continue;
1445
1466
  }
1446
1467
  let liveN = 0;
1447
- 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++;
1448
1469
  if (liveN >= MAX_ACTIVE_CLAIMS) {
1449
1470
  note(ev, ev.txid, "claim", false, `max ${MAX_ACTIVE_CLAIMS} live claims per address`);
1450
1471
  continue;
@@ -1578,6 +1599,17 @@ function requiredFillOutputs(offer2, payRaw) {
1578
1599
  add(offer2.seller, p.rebate);
1579
1600
  return [...need].map(([to, value]) => ({ to, value }));
1580
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
+ }
1581
1613
  var FEE_GATE_MARGIN_BLOCKS = 5;
1582
1614
  var NAME_FEE_GATES = [V18_HEIGHT, V24_HEIGHT];
1583
1615
  var buildFeeHeight = (tip) => {
@@ -1613,6 +1645,29 @@ function fillIsSafe(offer2, me, pay, tip) {
1613
1645
  }
1614
1646
  return { safe: true, reason: "ok", preview };
1615
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
+ }
1616
1671
  function finalizeWinnerCheck(nameState, me, commitHeight, tip) {
1617
1672
  const m = me.toLowerCase();
1618
1673
  if (!nameState) return { safe: false, reason: "no reservation on-chain (displaced, swept, or never accepted) \u2014 a finalize now would burn the fee" };
@@ -1735,23 +1790,45 @@ async function verifyFillSpv(offerId, fclaimTxid, me, io, opts) {
1735
1790
  }
1736
1791
  const dp = previewFill({ ...r.offer, status: "open" }, pay);
1737
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
+ }
1738
1809
  const holdEnd = fclaimHoldEnd(E);
1739
1810
  if (holdEnd < tip + FILL_TIP_MARGIN) return no(`too close to the hold deadline (holdEnd ${holdEnd}, tip ${tip}) - would strand`);
1740
1811
  return { safe: true, reason: "ok" };
1741
1812
  }
1813
+ var unsafeMintProvenOfferTerms = (t) => t;
1742
1814
  var feeBpsAt = (height) => height >= V11_HEIGHT ? height >= V16_HEIGHT ? FEE_BPS_V16 : FEE_BPS : 0;
1743
1815
  function provenOfferTerms(offerRec, provenHeight) {
1744
1816
  const w = offerRec.want;
1817
+ const g = offerRec.give;
1745
1818
  return {
1746
1819
  height: Number(provenHeight),
1747
1820
  feeBps: feeBpsAt(Number(provenHeight)),
1748
1821
  value: w.value !== void 0 ? String(w.value) : void 0,
1749
1822
  taker: offerRec.taker !== void 0 ? String(offerRec.taker).toLowerCase() : void 0,
1750
1823
  bid: offerRec.bid !== void 0 ? String(offerRec.bid).toLowerCase() : void 0,
1751
- min: offerRec.min !== void 0 ? String(offerRec.min) : 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"
1752
1829
  };
1753
1830
  }
1754
- function bindOfferTerms(servedOffer, t) {
1831
+ function bindOfferTerms(servedOffer, t, opts) {
1755
1832
  const o = servedOffer;
1756
1833
  const s = (v) => v === void 0 || v === null ? "" : String(v).toLowerCase();
1757
1834
  if (Number(o?.height) !== t.height) return true;
@@ -1762,6 +1839,15 @@ function bindOfferTerms(servedOffer, t) {
1762
1839
  const om = o?.min;
1763
1840
  if ((om !== void 0 && om !== null) !== (t.min !== void 0)) return true;
1764
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
+ }
1765
1851
  return false;
1766
1852
  }
1767
1853
  function bindProvenOffer(offerEv) {
@@ -1806,6 +1892,7 @@ var import_csd_codec5 = require("@inversealtruism/csd-codec");
1806
1892
  EPOCH_LEN,
1807
1893
  FCLAIM_KEYS,
1808
1894
  FCLAIM_MAX_EPOCH_AHEAD,
1895
+ FCLAIM_WINDOW_MIN,
1809
1896
  FEE_BPS,
1810
1897
  FEE_BPS_V16,
1811
1898
  FEE_GATE_MARGIN_BLOCKS,
@@ -1873,6 +1960,7 @@ var import_csd_codec5 = require("@inversealtruism/csd-codec");
1873
1960
  V26_HEIGHT,
1874
1961
  V27_HEIGHT,
1875
1962
  V28_HEIGHT,
1963
+ V29_HEIGHT,
1876
1964
  ZERO_ADDR,
1877
1965
  bid,
1878
1966
  bindOfferTerms,
@@ -1892,7 +1980,9 @@ var import_csd_codec5 = require("@inversealtruism/csd-codec");
1892
1980
  fclaimEpochFor,
1893
1981
  fclaimHoldEnd,
1894
1982
  feeBpsAt,
1983
+ fillEndorsement,
1895
1984
  fillIsSafe,
1985
+ fillOutputPlan,
1896
1986
  fillTargetId,
1897
1987
  finalizeWinnerCheck,
1898
1988
  hasLiveClaim,
@@ -1929,5 +2019,6 @@ var import_csd_codec5 = require("@inversealtruism/csd-codec");
1929
2019
  tokenMeta,
1930
2020
  tradeFee,
1931
2021
  transfer,
2022
+ unsafeMintProvenOfferTerms,
1932
2023
  verifyFillSpv
1933
2024
  });
package/dist/index.d.cts CHANGED
@@ -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,10 +687,21 @@ 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>;
607
706
  interface ProvenOfferTerms {
608
707
  height: number;
@@ -611,9 +710,20 @@ interface ProvenOfferTerms {
611
710
  taker?: string;
612
711
  bid?: string;
613
712
  min?: string;
614
- }
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;
615
725
  declare const feeBpsAt: (height: number) => number;
616
- declare function provenOfferTerms(offerRec: OfferRecord, provenHeight: number): ProvenOfferTerms;
726
+ declare function provenOfferTerms(offerRec: OfferRecord, provenHeight: number): MintedProvenOfferTerms;
617
727
  /**
618
728
  * The fill-boundary TERM-MISMATCH verdict: `true` iff any fee/rebate/partial-sizing field of the resolver-
619
729
  * SERVED offer diverges from the merkle-proven terms `t`. FAIL-CLOSED semantics (any divergence => true =>
@@ -628,12 +738,29 @@ declare function provenOfferTerms(offerRec: OfferRecord, provenHeight: number):
628
738
  * both mismatch. EXPLICIT presence (a served min="" must not slip past a proven-absent min).
629
739
  * `value` is bound only when `t.value` is defined so a token<->token offer (no CSD value) is not spuriously
630
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.
631
753
  */
754
+ interface BindTermsOpts {
755
+ give?: boolean;
756
+ wantType?: boolean;
757
+ }
632
758
  declare function bindOfferTerms(servedOffer: unknown, t: ProvenOfferTerms): boolean;
759
+ declare function bindOfferTerms(servedOffer: unknown, t: MintedProvenOfferTerms, opts: BindTermsOpts): boolean;
633
760
  declare function bindProvenOffer(offerEv: ProvenPropose): {
634
761
  payto: string;
635
762
  seller: string;
636
- terms: ProvenOfferTerms;
763
+ terms: MintedProvenOfferTerms;
637
764
  } | null;
638
765
 
639
766
  declare function paidToFromOutputs(outputs: readonly {
@@ -641,4 +768,4 @@ declare function paidToFromOutputs(outputs: readonly {
641
768
  value: number;
642
769
  }[]): Record<string, string>;
643
770
 
644
- 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 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, type Want, ZERO_ADDR, bid, bindOfferTerms, bindProvenOffer, buildFeeHeight, buildRecord, canonicalState, claimGraceOf, claimWindowAt, claimWindowOf, deploy, epochOf, expiredClaimFee, fclaim, fclaimEpochFor, fclaimHoldEnd, feeBpsAt, 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, provenOfferTerms, 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 };