@inversealtruism/cairnx-core 0.2.1 → 0.2.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,42 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.2.2
4
+
5
+ - `verifyFillSpv` fails closed when any id `offerEventIds` returns cannot be proven: `provenEvent` throws,
6
+ returns null, or returns an event under another id. It used to drop that event from the grant replay, so a
7
+ seller cancel whose block read failed replayed the offer as open. New refusal text: "an event on this offer
8
+ could not be merkle-proven (<id>) - refusing, the replay would miss it"; the offer and fclaim keep their
9
+ existing texts. The site's and the wallet's io return only ids they proved, so their honest fills do not move.
10
+ - New root export `countOtherHoldsAtGrant(candidates, target, me, closed?)`: the buyer's live holds on other
11
+ offers at an fclaim's grant, the `myLiveHoldsAtGrant` count for `verifyFillSpv`. It counts only fclaims applied
12
+ before the target (height, then position in the block), distinct offers, holds live at the grant height, and
13
+ skips the `closed` set. The site and the wallet counted later fclaims too, so a buyer's fourth reservation
14
+ (denied on the cap) made every earlier granted hold unfillable. An earlier fclaim the resolver denied is still
15
+ counted (an over-count, which only refuses). It returns `HoldCount` (`{ ok: true, count }` or
16
+ `{ ok: false, reason }`, which a caller treats as unsafe). Its domain is grants at or above
17
+ `LEGACY_HOLD_SUNSET_HEIGHT` (exported, 60,044: the last legacy claim at V28 - 1 plus its window and grace);
18
+ below it a legacy SCORE_CLAIM hold can still count against the cap and the counter does not read those, so it
19
+ refuses ("this reservation was granted at <h>, before block 60044, while claims made before V28 could still
20
+ count against the cap; it cannot be checked here").
21
+ - `finalizeWinnerCheck` refuses a supplied `tip` that is not a non-negative safe integer ("the chain tip given
22
+ (<tip>) is not a block height, so the finalize window cannot be checked"). A NaN, Infinity or fractional tip
23
+ used to skip or pass both window comparisons and return safe. An omitted or null tip keeps the winner-only check.
24
+ - New root export `provenOfferRefusal(rec, { domain, height, expiresEpoch, seller })`: the admission check for a
25
+ merkle-proven offer Propose. It refuses a domain other than `cairnx:v1` ("not a cairnx:v1 Propose (domain
26
+ "<domain>")") and then returns the resolver's own creation note for every rule that needs no chain state
27
+ (v1.2 shape before activation, the V13 to V17 open CSD offer ban, a treasury payee, an expiry outside the safe
28
+ integer range or already past at the anchor, the V21 to V22 duration cap). `applyOffer` now reads those rules
29
+ from the same function (`offerEnvelopeRefusal` in `src/resolve/market.ts`), in the same order with the same
30
+ notes. The give's backing is chain state and is not checked.
31
+ - `bindOfferTerms`'s wantType leg (on by default) also binds a token want's price: for a proven token want the
32
+ served `want.ticker` and `want.amount` must equal the record's, verbatim. `provenOfferTerms` carries them as
33
+ `wantTicker` and `wantAmount`. Before, a token-priced offer served with another ticker or amount passed, and
34
+ each caller (the site, cairn-sdk `preverifyOffer`) compared the price itself. Callers opting out with
35
+ `{ give: false, wantType: false }` keep the earlier verdict.
36
+ - New root export `MAX_TOKEN_DECIMALS` (8), the bound `parseRecord` applies to a deploy's `decimals`; the parser
37
+ reads it, so a consumer validating a served token's decimals uses the same number.
38
+ - `resolve()` and canonical state are byte-identical to 0.2.1.
39
+
3
40
  ## 0.2.1
4
41
 
5
42
  - Internal split, no behaviour change: `src/resolve.ts` keeps the replay loop and dispatches each record to
package/dist/index.cjs CHANGED
@@ -49,12 +49,14 @@ __export(index_exports, {
49
49
  HALVING_INTERVAL: () => import_csd_codec5.HALVING_INTERVAL,
50
50
  HASH_RE: () => HASH_RE,
51
51
  INITIAL_REWARD: () => import_csd_codec5.INITIAL_REWARD,
52
+ LEGACY_HOLD_SUNSET_HEIGHT: () => LEGACY_HOLD_SUNSET_HEIGHT,
52
53
  MAX_ACTIVE_CLAIMS: () => MAX_ACTIVE_CLAIMS,
53
54
  MAX_AMOUNT: () => MAX_AMOUNT,
54
55
  MAX_OFFER_EPOCHS: () => MAX_OFFER_EPOCHS,
55
56
  MAX_PENDING_REG: () => MAX_PENDING_REG,
56
57
  MAX_RECORD_BYTES: () => MAX_RECORD_BYTES,
57
58
  MAX_SCAN: () => MAX_SCAN,
59
+ MAX_TOKEN_DECIMALS: () => MAX_TOKEN_DECIMALS,
58
60
  MINT_KEYS: () => MINT_KEYS,
59
61
  MIN_FEE_ATTEST: () => import_csd_codec5.MIN_FEE_ATTEST,
60
62
  MIN_FEE_PROPOSE: () => import_csd_codec5.MIN_FEE_PROPOSE,
@@ -121,6 +123,7 @@ __export(index_exports, {
121
123
  claimGraceOf: () => claimGraceOf,
122
124
  claimWindowAt: () => claimWindowAt,
123
125
  claimWindowOf: () => claimWindowOf,
126
+ countOtherHoldsAtGrant: () => countOtherHoldsAtGrant,
124
127
  deploy: () => deploy,
125
128
  epochOf: () => import_csd_codec.epochOf,
126
129
  expiredClaimFee: () => expiredClaimFee,
@@ -160,6 +163,7 @@ __export(index_exports, {
160
163
  pickPrimaryName: () => pickPrimaryName,
161
164
  previewFill: () => previewFill,
162
165
  primaryRankBefore: () => primaryRankBefore,
166
+ provenOfferRefusal: () => provenOfferRefusal,
163
167
  provenOfferTerms: () => provenOfferTerms,
164
168
  ptAmt: () => ptAmt,
165
169
  replayLiveHold: () => replayLiveHold,
@@ -198,6 +202,7 @@ function expiredClaimFee(name, epochsPastGraceEnd, height) {
198
202
  }
199
203
  var MAX_RECORD_BYTES = import_csd_codec.MAX_URI_BYTES;
200
204
  var MAX_AMOUNT = (1n << 96n) - 1n;
205
+ var MAX_TOKEN_DECIMALS = 8;
201
206
  var SCORE_FILL = 100;
202
207
  var SCORE_CANCEL = 0;
203
208
  var SCORE_CLAIM = 50;
@@ -346,7 +351,7 @@ function parseRecord(uri, payloadHashHex) {
346
351
  if (!onlyKeys(r, DEPLOY_KEYS)) return null;
347
352
  if (!isTicker(r.ticker)) return null;
348
353
  if (r.name !== void 0 && (typeof r.name !== "string" || r.name.length > 32)) return null;
349
- if (typeof r.decimals !== "number" || !Number.isInteger(r.decimals) || r.decimals < 0 || r.decimals > 8) return null;
354
+ if (typeof r.decimals !== "number" || !Number.isInteger(r.decimals) || r.decimals < 0 || r.decimals > MAX_TOKEN_DECIMALS) return null;
350
355
  if (parseAmount(r.supply) === null) return null;
351
356
  if (r.mint !== "open" && r.mint !== "issuer") return null;
352
357
  if (r.mint === "open" && parseAmount(r.mintLimit) === null) return null;
@@ -1251,35 +1256,15 @@ function applyNrenew(c, ev, rec, who, feeToTreasury) {
1251
1256
  function applyOffer(c, ev, rec, who) {
1252
1257
  const { tokens, names, offers, offerLock, openOffers, bids, bal, note } = c;
1253
1258
  const v11 = ev.height >= V11_HEIGHT;
1254
- const v12 = ev.height >= V12_HEIGHT;
1255
1259
  const v15 = ev.height >= V15_HEIGHT;
1256
1260
  const v16 = ev.height >= V16_HEIGHT;
1257
1261
  const wantIsToken = isTokenWant(rec.want);
1258
- if ((wantIsToken || rec.min !== void 0 || rec.bid !== void 0) && !v12) {
1259
- note(ev, ev.id, "offer", false, "v1.2 offer shape before activation");
1260
- return;
1261
- }
1262
- if (ev.height >= V13_HEIGHT && ev.height < V17_HEIGHT && !wantIsToken && rec.taker === void 0) {
1263
- note(ev, ev.id, "offer", false, "v1.3: CSD-priced offers must be taker-bound (use bid/RFQ)");
1262
+ const refusal = offerEnvelopeRefusal(rec, who, ev.height, ev.expiresEpoch);
1263
+ if (refusal !== null) {
1264
+ note(ev, ev.id, "offer", false, refusal);
1264
1265
  return;
1265
1266
  }
1266
1267
  const payto = (rec.want.payto ?? who).toLowerCase();
1267
- if (payto === TREASURY_ADDR) {
1268
- note(ev, ev.id, "offer", false, "payto cannot be the protocol treasury");
1269
- return;
1270
- }
1271
- if (!Number.isSafeInteger(ev.expiresEpoch)) {
1272
- note(ev, ev.id, "offer", false, "expiresEpoch out of safe-integer range");
1273
- return;
1274
- }
1275
- if ((0, import_csd_codec.epochOf)(ev.height) > ev.expiresEpoch) {
1276
- note(ev, ev.id, "offer", false, "already expired at anchor");
1277
- return;
1278
- }
1279
- if (ev.height >= V21_HEIGHT && ev.height < V22_HEIGHT && ev.expiresEpoch - (0, import_csd_codec.epochOf)(ev.height) > MAX_OFFER_EPOCHS) {
1280
- note(ev, ev.id, "offer", false, "v2.1: offer duration exceeds the max");
1281
- return;
1282
- }
1283
1268
  const give = rec.give;
1284
1269
  if (isNameGive(give)) {
1285
1270
  if (!v11) {
@@ -1473,6 +1458,16 @@ function applyFclaim(c, ev, rec, who) {
1473
1458
  fclaims.set(ev.id, { offer: rec.offer, proposer: who, expiresEpoch: E, height: ev.height, granted: true });
1474
1459
  note(ev, ev.id, "fclaim", true);
1475
1460
  }
1461
+ function offerEnvelopeRefusal(rec, who, height, expiresEpoch) {
1462
+ const wantIsToken = isTokenWant(rec.want);
1463
+ if ((wantIsToken || rec.min !== void 0 || rec.bid !== void 0) && height < V12_HEIGHT) return "v1.2 offer shape before activation";
1464
+ if (height >= V13_HEIGHT && height < V17_HEIGHT && !wantIsToken && rec.taker === void 0) return "v1.3: CSD-priced offers must be taker-bound (use bid/RFQ)";
1465
+ if ((rec.want.payto ?? who).toLowerCase() === TREASURY_ADDR) return "payto cannot be the protocol treasury";
1466
+ if (!Number.isSafeInteger(expiresEpoch)) return "expiresEpoch out of safe-integer range";
1467
+ if ((0, import_csd_codec.epochOf)(height) > expiresEpoch) return "already expired at anchor";
1468
+ if (height >= V21_HEIGHT && height < V22_HEIGHT && expiresEpoch - (0, import_csd_codec.epochOf)(height) > MAX_OFFER_EPOCHS) return "v2.1: offer duration exceeds the max";
1469
+ return null;
1470
+ }
1476
1471
 
1477
1472
  // src/resolve/tokens.ts
1478
1473
  function applyDeploy(c, ev, rec, who, feeToTreasury) {
@@ -1859,8 +1854,9 @@ function finalizeWinnerCheck(nameState, me, commitHeight, tip) {
1859
1854
  if (nameState.pending !== true) return { safe: false, reason: "already registered to you \u2014 no second finalize fee is needed" };
1860
1855
  if (Number(nameState.effectiveHeight) !== Number(commitHeight))
1861
1856
  return { safe: false, reason: "your reservation was displaced (effective height changed) \u2014 a finalize now would burn the fee" };
1862
- if (tip !== void 0 && tip !== null && Number.isFinite(Number(tip))) {
1863
- const t = Number(tip);
1857
+ if (tip !== void 0 && tip !== null) {
1858
+ if (!Number.isSafeInteger(tip) || tip < 0) return { safe: false, reason: `the chain tip given (${String(tip)}) is not a block height, so the finalize window cannot be checked` };
1859
+ const t = tip;
1864
1860
  const eff = Number(nameState.effectiveHeight);
1865
1861
  const freezeEnd = eff + REG_COMMIT_MAX_BLOCKS;
1866
1862
  const closeAt = eff + REG_COMMIT_MAX_BLOCKS + REG_FINALIZE_GRACE_BLOCKS - FINALIZE_TIP_MARGIN;
@@ -1922,15 +1918,17 @@ async function verifyFillSpv(offerId, fclaimTxid, me, io, opts) {
1922
1918
  return no("could not enumerate the offer's events");
1923
1919
  }
1924
1920
  const want = /* @__PURE__ */ new Set([offerId.toLowerCase(), fclaimTxid.toLowerCase(), ...(hintIds ?? []).map((x) => String(x).toLowerCase())]);
1921
+ const unproven = (wid) => wid === offerId.toLowerCase() ? no("offer not merkle-proven (no PoW-verified offer Propose)") : wid === fclaimTxid.toLowerCase() ? no("fclaim not merkle-proven (no PoW-verified fclaim Propose)") : no(`an event on this offer could not be merkle-proven (${wid}) - refusing, the replay would miss it`);
1925
1922
  const proven = [];
1926
1923
  for (const wid of want) {
1927
1924
  let ev;
1928
1925
  try {
1929
1926
  ev = await io.provenEvent(wid);
1930
1927
  } catch {
1931
- ev = null;
1928
+ return unproven(wid);
1932
1929
  }
1933
- if (ev && (ev.kind === "propose" ? ev.id : ev.txid).toLowerCase() === wid) proven.push(ev);
1930
+ if (!ev || (ev.kind === "propose" ? ev.id : ev.txid).toLowerCase() !== wid) return unproven(wid);
1931
+ proven.push(ev);
1934
1932
  }
1935
1933
  const isProp = (e) => e.kind === "propose";
1936
1934
  const offerEv = proven.find((e) => isProp(e) && e.id.toLowerCase() === offerId.toLowerCase());
@@ -2009,7 +2007,9 @@ function provenOfferTerms(offerRec, provenHeight) {
2009
2007
  giveTicker: g.ticker !== void 0 ? String(g.ticker) : void 0,
2010
2008
  giveAmount: g.amount !== void 0 ? String(g.amount) : void 0,
2011
2009
  giveName: g.name !== void 0 ? String(g.name) : void 0,
2012
- wantType: isTokenWant(offerRec.want) ? "token" : "csd"
2010
+ wantType: isTokenWant(offerRec.want) ? "token" : "csd",
2011
+ wantTicker: isTokenWant(offerRec.want) ? String(w.ticker) : void 0,
2012
+ wantAmount: isTokenWant(offerRec.want) ? String(w.amount) : void 0
2013
2013
  };
2014
2014
  }
2015
2015
  function bindOfferTerms(servedOffer, t, opts) {
@@ -2024,7 +2024,8 @@ function bindOfferTerms(servedOffer, t, opts) {
2024
2024
  if ((om !== void 0 && om !== null) !== (t.min !== void 0)) return true;
2025
2025
  if (t.min !== void 0 && String(om) !== t.min) return true;
2026
2026
  if (opts?.wantType !== false) {
2027
- if (t.wantType === void 0 || typeof o?.want?.ticker === "string" !== (t.wantType === "token")) return true;
2027
+ if (t.wantType === void 0) return true;
2028
+ if (t.wantType === "token" ? String(o?.want?.ticker) !== t.wantTicker || String(o?.want?.amount) !== t.wantAmount : typeof o?.want?.ticker === "string") return true;
2028
2029
  }
2029
2030
  if (opts?.give !== false) {
2030
2031
  const g = o?.give;
@@ -2098,6 +2099,34 @@ function myProvenFillClosedOffer(fill, fclaim2, offerEv, me, grantHeight) {
2098
2099
  return need.every((leg) => ptAmt(fill.paidTo?.[lc(leg.to)]) >= leg.value);
2099
2100
  }
2100
2101
 
2102
+ // src/holdcount.ts
2103
+ var lastLegacyClaimEnd = V28_HEIGHT - 1 + claimWindowAt(V28_HEIGHT - 1);
2104
+ var LEGACY_HOLD_SUNSET_HEIGHT = lastLegacyClaimEnd + claimGraceOf(lastLegacyClaimEnd);
2105
+ function countOtherHoldsAtGrant(candidates, target, me, closed = /* @__PURE__ */ new Set()) {
2106
+ if (!(Number.isSafeInteger(target.height) && target.height >= LEGACY_HOLD_SUNSET_HEIGHT))
2107
+ return { ok: false, reason: `this reservation was granted at ${target.height}, before block ${LEGACY_HOLD_SUNSET_HEIGHT}, while claims made before V28 could still count against the cap; it cannot be checked here` };
2108
+ const meL = String(me).toLowerCase(), tid = String(target.id).toLowerCase(), toffer = String(target.offer).toLowerCase();
2109
+ const offers = /* @__PURE__ */ new Set();
2110
+ for (const c of candidates) {
2111
+ const cid = String(c.id).toLowerCase();
2112
+ if (cid === tid || closed.has(cid) || String(c.proposer).toLowerCase() !== meL) continue;
2113
+ if (!(c.height < target.height || c.height === target.height && c.pos < target.pos)) continue;
2114
+ if (!(fclaimHoldEnd(Number(c.expiresEpoch)) >= target.height)) continue;
2115
+ const rec = parseRecord(String(c.uri), String(c.payloadHash));
2116
+ if (!rec || rec.t !== "fclaim") continue;
2117
+ const offer2 = String(rec.offer).toLowerCase();
2118
+ if (offer2 !== toffer) offers.add(offer2);
2119
+ }
2120
+ return { ok: true, count: offers.size };
2121
+ }
2122
+
2123
+ // src/admission.ts
2124
+ function provenOfferRefusal(rec, tx) {
2125
+ if (tx.domain !== DOMAIN) return `not a ${DOMAIN} Propose (domain ${JSON.stringify(String(tx.domain))})`;
2126
+ const ee = typeof tx.expiresEpoch === "bigint" ? Number(tx.expiresEpoch) : tx.expiresEpoch;
2127
+ return offerEnvelopeRefusal(rec, String(tx.seller).toLowerCase(), tx.height, ee);
2128
+ }
2129
+
2101
2130
  // src/index.ts
2102
2131
  var import_csd_codec5 = require("@inversealtruism/csd-codec");
2103
2132
  // Annotate the CommonJS export names for ESM import in node:
@@ -2131,12 +2160,14 @@ var import_csd_codec5 = require("@inversealtruism/csd-codec");
2131
2160
  HALVING_INTERVAL,
2132
2161
  HASH_RE,
2133
2162
  INITIAL_REWARD,
2163
+ LEGACY_HOLD_SUNSET_HEIGHT,
2134
2164
  MAX_ACTIVE_CLAIMS,
2135
2165
  MAX_AMOUNT,
2136
2166
  MAX_OFFER_EPOCHS,
2137
2167
  MAX_PENDING_REG,
2138
2168
  MAX_RECORD_BYTES,
2139
2169
  MAX_SCAN,
2170
+ MAX_TOKEN_DECIMALS,
2140
2171
  MINT_KEYS,
2141
2172
  MIN_FEE_ATTEST,
2142
2173
  MIN_FEE_PROPOSE,
@@ -2203,6 +2234,7 @@ var import_csd_codec5 = require("@inversealtruism/csd-codec");
2203
2234
  claimGraceOf,
2204
2235
  claimWindowAt,
2205
2236
  claimWindowOf,
2237
+ countOtherHoldsAtGrant,
2206
2238
  deploy,
2207
2239
  epochOf,
2208
2240
  expiredClaimFee,
@@ -2242,6 +2274,7 @@ var import_csd_codec5 = require("@inversealtruism/csd-codec");
2242
2274
  pickPrimaryName,
2243
2275
  previewFill,
2244
2276
  primaryRankBefore,
2277
+ provenOfferRefusal,
2245
2278
  provenOfferTerms,
2246
2279
  ptAmt,
2247
2280
  replayLiveHold,
package/dist/index.d.cts CHANGED
@@ -19,6 +19,8 @@ declare const NAME_PREMIUM_DECAY_EPOCHS = 720;
19
19
  declare function expiredClaimFee(name: string, epochsPastGraceEnd: number, height: number): bigint;
20
20
  declare const MAX_RECORD_BYTES = 512;
21
21
  declare const MAX_AMOUNT: bigint;
22
+ /** The most decimals a token deploy may declare (parseRecord refuses a deploy above it). */
23
+ declare const MAX_TOKEN_DECIMALS = 8;
22
24
  declare const SCORE_FILL = 100;
23
25
  declare const SCORE_CANCEL = 0;
24
26
  declare const SCORE_CLAIM = 50;
@@ -635,7 +637,8 @@ declare function fillEndorsement(offer: OfferState, me: string, pay: bigint | st
635
637
  * mining outside the window (too early: rejected as unfrozen; too late: past the deadline — either way the
636
638
  * fee burns). The window is derived purely from `eff` (never the resolver's `finalizeBy`), so a lying
637
639
  * `finalizeBy` cannot widen it — but per the trust scope above, a lying `eff` still can for a caller that
638
- * does not supply an independent `commitHeight`. `tip` is optional; without it the winner-only path runs. */
640
+ * does not supply an independent `commitHeight`. `tip` is optional; without it the winner-only path runs. A
641
+ * supplied `tip` that is not a non-negative safe integer is refused. */
639
642
  declare function finalizeWinnerCheck(nameState: NameState | null | undefined, me: string, commitHeight: number, tip?: number | null): {
640
643
  safe: boolean;
641
644
  reason: string;
@@ -685,7 +688,7 @@ interface FillVerdict {
685
688
  * not-mine hold, a below-depth signing, a zero-delivery fill, a stranded past-deadline broadcast).
686
689
  *
687
690
  * `opts.myLiveHoldsAtGrant` (REQUIRED) is the buyer's count of OTHER live fclaim/legacy holds at the moment
688
- * THIS fclaim was granted, asserted by the authoring client (which signed its own claims). The lane-scoped
691
+ * THIS fclaim was granted, asserted by the authoring client (countOtherHoldsAtGrant computes it). The lane-scoped
689
692
  * replay cannot see the buyer's other-offer holds, and MAX_ACTIVE_CLAIMS is the one grant clause counted
690
693
  * across offers, so without this the surface would false-accept a cap-denied fclaim. `opts.pay` overrides the
691
694
  * payment (base units to want.payto) for a PARTIAL tail-fill; defaults to the offer's full want.value.
@@ -718,6 +721,8 @@ interface ProvenOfferTerms {
718
721
  giveAmount?: string;
719
722
  giveName?: string;
720
723
  wantType?: "csd" | "token";
724
+ wantTicker?: string;
725
+ wantAmount?: string;
721
726
  }
722
727
  declare const PROVEN_TERMS_MINT: unique symbol;
723
728
  type MintedProvenOfferTerms = ProvenOfferTerms & {
@@ -754,7 +759,8 @@ declare function provenOfferTerms(offerRec: OfferRecord, provenHeight: number):
754
759
  * wantType - the SYMMETRIC want-type refusal: the served offer's want type (token iff want.ticker is
755
760
  * a string, the isTokenWant pivot) must equal the proven type. The value leg already
756
761
  * catches proven-CSD-served-as-token (String(undefined) mismatches t.value); this closes
757
- * the reverse, proven-token-served-as-CSD.
762
+ * the reverse, proven-token-served-as-CSD. For a proven token want the served want.ticker
763
+ * and want.amount must also equal the proven price, verbatim.
758
764
  */
759
765
  interface BindTermsOpts {
760
766
  give?: boolean;
@@ -800,4 +806,53 @@ declare function myProvenFillClosedOffer(fill: ProvenEvent | null, fclaim: {
800
806
  offer: string;
801
807
  }, offerEv: ProvenEvent | null, me: string, grantHeight: number): boolean;
802
808
 
803
- 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, type LegacyBindOpts, 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, burnedPayment, canonicalState, claimGraceOf, claimWindowAt, claimWindowOf, deploy, expiredClaimFee, fclaim, fclaimEpochFor, fclaimHoldEnd, feeBpsAt, fillEndorsement, fillIsSafe, fillOutputPlan, fillTargetId, finalizeWinnerCheck, hasLiveClaim, isName, isNameGive, isOpenClaimLane, isTokenWant, makerRebate, mint, myProvenFillClosedOffer, nameClaim, nameCommit, nameCommitRecord, nameFinalize, nameProfile, nameRegFee, nameRenew, nameSet, nameXfer, offer, offerCancelAll, offerExpiryHeightOf, paidToFromOutputs, parseAmount, parseRecord, pickPrimaryName, previewFill, primaryRankBefore, provenOfferTerms, ptAmt, replayLiveHold, requiredClaimDepth, requiredFillOutputs, resolve, tokenMeta, tradeFee, transfer, unsafeMintProvenOfferTerms, verifyFillSpv };
809
+ declare const LEGACY_HOLD_SUNSET_HEIGHT: number;
810
+ /** The count, or a refusal the caller must treat as unsafe (fail closed). */
811
+ type HoldCount = {
812
+ ok: true;
813
+ count: number;
814
+ } | {
815
+ ok: false;
816
+ reason: string;
817
+ };
818
+ /** An fclaim Propose the buyer may hold, read from a merkle-bound block. `proposer` is the prevout-bound author,
819
+ * or the buyer when it cannot be bound (over-counting only refuses a fill; under-counting can burn one). */
820
+ interface HoldCandidate {
821
+ id: string;
822
+ height: number;
823
+ pos: number;
824
+ proposer: string;
825
+ uri: string;
826
+ payloadHash: string;
827
+ expiresEpoch: number;
828
+ }
829
+ /** The fclaim being filled: its id, its proven block height and position, and the offer it reserves. */
830
+ interface HoldTarget {
831
+ id: string;
832
+ height: number;
833
+ pos: number;
834
+ offer: string;
835
+ }
836
+ /**
837
+ * An upper bound of the buyer's live holds on other offers when `target` was granted: distinct other offers with
838
+ * an fclaim by `me` applied before the target (height, then position in the block) whose hold is still live at the
839
+ * target's height. `closed` names fclaims whose offer the buyer's own proven fill closed (myProvenFillClosedOffer);
840
+ * they are skipped. An earlier fclaim the resolver denied is still counted: its denial is not visible here.
841
+ * Domain: grants at or above LEGACY_HOLD_SUNSET_HEIGHT. Below it a legacy SCORE_CLAIM hold from before V28 can
842
+ * still be live and count against the cap, so the result is a refusal.
843
+ */
844
+ declare function countOtherHoldsAtGrant(candidates: readonly HoldCandidate[], target: HoldTarget, me: string, closed?: ReadonlySet<string>): HoldCount;
845
+
846
+ /** Fields of the merkle-proven Propose: its app domain and expires_epoch, its inclusion height, and its author
847
+ * (csd-crypto authorOf). */
848
+ interface ProvenOfferTx {
849
+ domain: string;
850
+ height: number;
851
+ expiresEpoch: number | bigint;
852
+ seller: string;
853
+ }
854
+ /** Why the proven offer Propose is not an offer the resolver admits (the resolver's own note for the record
855
+ * rules), or null when it passes. */
856
+ declare function provenOfferRefusal(rec: OfferRecord, tx: ProvenOfferTx): string | null;
857
+
858
+ 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 HoldCandidate, type HoldCount, type HoldReplay, type HoldTarget, LEGACY_HOLD_SUNSET_HEIGHT, type LegacyBindOpts, MAX_ACTIVE_CLAIMS, MAX_AMOUNT, MAX_OFFER_EPOCHS, MAX_PENDING_REG, MAX_RECORD_BYTES, MAX_SCAN, MAX_TOKEN_DECIMALS, 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 ProvenOfferTx, 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, burnedPayment, canonicalState, claimGraceOf, claimWindowAt, claimWindowOf, countOtherHoldsAtGrant, deploy, expiredClaimFee, fclaim, fclaimEpochFor, fclaimHoldEnd, feeBpsAt, fillEndorsement, fillIsSafe, fillOutputPlan, fillTargetId, finalizeWinnerCheck, hasLiveClaim, isName, isNameGive, isOpenClaimLane, isTokenWant, makerRebate, mint, myProvenFillClosedOffer, nameClaim, nameCommit, nameCommitRecord, nameFinalize, nameProfile, nameRegFee, nameRenew, nameSet, nameXfer, offer, offerCancelAll, offerExpiryHeightOf, paidToFromOutputs, parseAmount, parseRecord, pickPrimaryName, previewFill, primaryRankBefore, provenOfferRefusal, provenOfferTerms, ptAmt, replayLiveHold, requiredClaimDepth, requiredFillOutputs, resolve, tokenMeta, tradeFee, transfer, unsafeMintProvenOfferTerms, verifyFillSpv };
package/dist/index.d.ts CHANGED
@@ -19,6 +19,8 @@ declare const NAME_PREMIUM_DECAY_EPOCHS = 720;
19
19
  declare function expiredClaimFee(name: string, epochsPastGraceEnd: number, height: number): bigint;
20
20
  declare const MAX_RECORD_BYTES = 512;
21
21
  declare const MAX_AMOUNT: bigint;
22
+ /** The most decimals a token deploy may declare (parseRecord refuses a deploy above it). */
23
+ declare const MAX_TOKEN_DECIMALS = 8;
22
24
  declare const SCORE_FILL = 100;
23
25
  declare const SCORE_CANCEL = 0;
24
26
  declare const SCORE_CLAIM = 50;
@@ -635,7 +637,8 @@ declare function fillEndorsement(offer: OfferState, me: string, pay: bigint | st
635
637
  * mining outside the window (too early: rejected as unfrozen; too late: past the deadline — either way the
636
638
  * fee burns). The window is derived purely from `eff` (never the resolver's `finalizeBy`), so a lying
637
639
  * `finalizeBy` cannot widen it — but per the trust scope above, a lying `eff` still can for a caller that
638
- * does not supply an independent `commitHeight`. `tip` is optional; without it the winner-only path runs. */
640
+ * does not supply an independent `commitHeight`. `tip` is optional; without it the winner-only path runs. A
641
+ * supplied `tip` that is not a non-negative safe integer is refused. */
639
642
  declare function finalizeWinnerCheck(nameState: NameState | null | undefined, me: string, commitHeight: number, tip?: number | null): {
640
643
  safe: boolean;
641
644
  reason: string;
@@ -685,7 +688,7 @@ interface FillVerdict {
685
688
  * not-mine hold, a below-depth signing, a zero-delivery fill, a stranded past-deadline broadcast).
686
689
  *
687
690
  * `opts.myLiveHoldsAtGrant` (REQUIRED) is the buyer's count of OTHER live fclaim/legacy holds at the moment
688
- * THIS fclaim was granted, asserted by the authoring client (which signed its own claims). The lane-scoped
691
+ * THIS fclaim was granted, asserted by the authoring client (countOtherHoldsAtGrant computes it). The lane-scoped
689
692
  * replay cannot see the buyer's other-offer holds, and MAX_ACTIVE_CLAIMS is the one grant clause counted
690
693
  * across offers, so without this the surface would false-accept a cap-denied fclaim. `opts.pay` overrides the
691
694
  * payment (base units to want.payto) for a PARTIAL tail-fill; defaults to the offer's full want.value.
@@ -718,6 +721,8 @@ interface ProvenOfferTerms {
718
721
  giveAmount?: string;
719
722
  giveName?: string;
720
723
  wantType?: "csd" | "token";
724
+ wantTicker?: string;
725
+ wantAmount?: string;
721
726
  }
722
727
  declare const PROVEN_TERMS_MINT: unique symbol;
723
728
  type MintedProvenOfferTerms = ProvenOfferTerms & {
@@ -754,7 +759,8 @@ declare function provenOfferTerms(offerRec: OfferRecord, provenHeight: number):
754
759
  * wantType - the SYMMETRIC want-type refusal: the served offer's want type (token iff want.ticker is
755
760
  * a string, the isTokenWant pivot) must equal the proven type. The value leg already
756
761
  * catches proven-CSD-served-as-token (String(undefined) mismatches t.value); this closes
757
- * the reverse, proven-token-served-as-CSD.
762
+ * the reverse, proven-token-served-as-CSD. For a proven token want the served want.ticker
763
+ * and want.amount must also equal the proven price, verbatim.
758
764
  */
759
765
  interface BindTermsOpts {
760
766
  give?: boolean;
@@ -800,4 +806,53 @@ declare function myProvenFillClosedOffer(fill: ProvenEvent | null, fclaim: {
800
806
  offer: string;
801
807
  }, offerEv: ProvenEvent | null, me: string, grantHeight: number): boolean;
802
808
 
803
- 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, type LegacyBindOpts, 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, burnedPayment, canonicalState, claimGraceOf, claimWindowAt, claimWindowOf, deploy, expiredClaimFee, fclaim, fclaimEpochFor, fclaimHoldEnd, feeBpsAt, fillEndorsement, fillIsSafe, fillOutputPlan, fillTargetId, finalizeWinnerCheck, hasLiveClaim, isName, isNameGive, isOpenClaimLane, isTokenWant, makerRebate, mint, myProvenFillClosedOffer, nameClaim, nameCommit, nameCommitRecord, nameFinalize, nameProfile, nameRegFee, nameRenew, nameSet, nameXfer, offer, offerCancelAll, offerExpiryHeightOf, paidToFromOutputs, parseAmount, parseRecord, pickPrimaryName, previewFill, primaryRankBefore, provenOfferTerms, ptAmt, replayLiveHold, requiredClaimDepth, requiredFillOutputs, resolve, tokenMeta, tradeFee, transfer, unsafeMintProvenOfferTerms, verifyFillSpv };
809
+ declare const LEGACY_HOLD_SUNSET_HEIGHT: number;
810
+ /** The count, or a refusal the caller must treat as unsafe (fail closed). */
811
+ type HoldCount = {
812
+ ok: true;
813
+ count: number;
814
+ } | {
815
+ ok: false;
816
+ reason: string;
817
+ };
818
+ /** An fclaim Propose the buyer may hold, read from a merkle-bound block. `proposer` is the prevout-bound author,
819
+ * or the buyer when it cannot be bound (over-counting only refuses a fill; under-counting can burn one). */
820
+ interface HoldCandidate {
821
+ id: string;
822
+ height: number;
823
+ pos: number;
824
+ proposer: string;
825
+ uri: string;
826
+ payloadHash: string;
827
+ expiresEpoch: number;
828
+ }
829
+ /** The fclaim being filled: its id, its proven block height and position, and the offer it reserves. */
830
+ interface HoldTarget {
831
+ id: string;
832
+ height: number;
833
+ pos: number;
834
+ offer: string;
835
+ }
836
+ /**
837
+ * An upper bound of the buyer's live holds on other offers when `target` was granted: distinct other offers with
838
+ * an fclaim by `me` applied before the target (height, then position in the block) whose hold is still live at the
839
+ * target's height. `closed` names fclaims whose offer the buyer's own proven fill closed (myProvenFillClosedOffer);
840
+ * they are skipped. An earlier fclaim the resolver denied is still counted: its denial is not visible here.
841
+ * Domain: grants at or above LEGACY_HOLD_SUNSET_HEIGHT. Below it a legacy SCORE_CLAIM hold from before V28 can
842
+ * still be live and count against the cap, so the result is a refusal.
843
+ */
844
+ declare function countOtherHoldsAtGrant(candidates: readonly HoldCandidate[], target: HoldTarget, me: string, closed?: ReadonlySet<string>): HoldCount;
845
+
846
+ /** Fields of the merkle-proven Propose: its app domain and expires_epoch, its inclusion height, and its author
847
+ * (csd-crypto authorOf). */
848
+ interface ProvenOfferTx {
849
+ domain: string;
850
+ height: number;
851
+ expiresEpoch: number | bigint;
852
+ seller: string;
853
+ }
854
+ /** Why the proven offer Propose is not an offer the resolver admits (the resolver's own note for the record
855
+ * rules), or null when it passes. */
856
+ declare function provenOfferRefusal(rec: OfferRecord, tx: ProvenOfferTx): string | null;
857
+
858
+ 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 HoldCandidate, type HoldCount, type HoldReplay, type HoldTarget, LEGACY_HOLD_SUNSET_HEIGHT, type LegacyBindOpts, MAX_ACTIVE_CLAIMS, MAX_AMOUNT, MAX_OFFER_EPOCHS, MAX_PENDING_REG, MAX_RECORD_BYTES, MAX_SCAN, MAX_TOKEN_DECIMALS, 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 ProvenOfferTx, 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, burnedPayment, canonicalState, claimGraceOf, claimWindowAt, claimWindowOf, countOtherHoldsAtGrant, deploy, expiredClaimFee, fclaim, fclaimEpochFor, fclaimHoldEnd, feeBpsAt, fillEndorsement, fillIsSafe, fillOutputPlan, fillTargetId, finalizeWinnerCheck, hasLiveClaim, isName, isNameGive, isOpenClaimLane, isTokenWant, makerRebate, mint, myProvenFillClosedOffer, nameClaim, nameCommit, nameCommitRecord, nameFinalize, nameProfile, nameRegFee, nameRenew, nameSet, nameXfer, offer, offerCancelAll, offerExpiryHeightOf, paidToFromOutputs, parseAmount, parseRecord, pickPrimaryName, previewFill, primaryRankBefore, provenOfferRefusal, provenOfferTerms, ptAmt, replayLiveHold, requiredClaimDepth, requiredFillOutputs, resolve, tokenMeta, tradeFee, transfer, unsafeMintProvenOfferTerms, verifyFillSpv };
package/dist/index.js CHANGED
@@ -22,6 +22,7 @@ function expiredClaimFee(name, epochsPastGraceEnd, height) {
22
22
  }
23
23
  var MAX_RECORD_BYTES = MAX_URI_BYTES;
24
24
  var MAX_AMOUNT = (1n << 96n) - 1n;
25
+ var MAX_TOKEN_DECIMALS = 8;
25
26
  var SCORE_FILL = 100;
26
27
  var SCORE_CANCEL = 0;
27
28
  var SCORE_CLAIM = 50;
@@ -170,7 +171,7 @@ function parseRecord(uri, payloadHashHex) {
170
171
  if (!onlyKeys(r, DEPLOY_KEYS)) return null;
171
172
  if (!isTicker(r.ticker)) return null;
172
173
  if (r.name !== void 0 && (typeof r.name !== "string" || r.name.length > 32)) return null;
173
- if (typeof r.decimals !== "number" || !Number.isInteger(r.decimals) || r.decimals < 0 || r.decimals > 8) return null;
174
+ if (typeof r.decimals !== "number" || !Number.isInteger(r.decimals) || r.decimals < 0 || r.decimals > MAX_TOKEN_DECIMALS) return null;
174
175
  if (parseAmount(r.supply) === null) return null;
175
176
  if (r.mint !== "open" && r.mint !== "issuer") return null;
176
177
  if (r.mint === "open" && parseAmount(r.mintLimit) === null) return null;
@@ -1075,35 +1076,15 @@ function applyNrenew(c, ev, rec, who, feeToTreasury) {
1075
1076
  function applyOffer(c, ev, rec, who) {
1076
1077
  const { tokens, names, offers, offerLock, openOffers, bids, bal, note } = c;
1077
1078
  const v11 = ev.height >= V11_HEIGHT;
1078
- const v12 = ev.height >= V12_HEIGHT;
1079
1079
  const v15 = ev.height >= V15_HEIGHT;
1080
1080
  const v16 = ev.height >= V16_HEIGHT;
1081
1081
  const wantIsToken = isTokenWant(rec.want);
1082
- if ((wantIsToken || rec.min !== void 0 || rec.bid !== void 0) && !v12) {
1083
- note(ev, ev.id, "offer", false, "v1.2 offer shape before activation");
1084
- return;
1085
- }
1086
- if (ev.height >= V13_HEIGHT && ev.height < V17_HEIGHT && !wantIsToken && rec.taker === void 0) {
1087
- note(ev, ev.id, "offer", false, "v1.3: CSD-priced offers must be taker-bound (use bid/RFQ)");
1082
+ const refusal = offerEnvelopeRefusal(rec, who, ev.height, ev.expiresEpoch);
1083
+ if (refusal !== null) {
1084
+ note(ev, ev.id, "offer", false, refusal);
1088
1085
  return;
1089
1086
  }
1090
1087
  const payto = (rec.want.payto ?? who).toLowerCase();
1091
- if (payto === TREASURY_ADDR) {
1092
- note(ev, ev.id, "offer", false, "payto cannot be the protocol treasury");
1093
- return;
1094
- }
1095
- if (!Number.isSafeInteger(ev.expiresEpoch)) {
1096
- note(ev, ev.id, "offer", false, "expiresEpoch out of safe-integer range");
1097
- return;
1098
- }
1099
- if (epochOf(ev.height) > ev.expiresEpoch) {
1100
- note(ev, ev.id, "offer", false, "already expired at anchor");
1101
- return;
1102
- }
1103
- if (ev.height >= V21_HEIGHT && ev.height < V22_HEIGHT && ev.expiresEpoch - epochOf(ev.height) > MAX_OFFER_EPOCHS) {
1104
- note(ev, ev.id, "offer", false, "v2.1: offer duration exceeds the max");
1105
- return;
1106
- }
1107
1088
  const give = rec.give;
1108
1089
  if (isNameGive(give)) {
1109
1090
  if (!v11) {
@@ -1297,6 +1278,16 @@ function applyFclaim(c, ev, rec, who) {
1297
1278
  fclaims.set(ev.id, { offer: rec.offer, proposer: who, expiresEpoch: E, height: ev.height, granted: true });
1298
1279
  note(ev, ev.id, "fclaim", true);
1299
1280
  }
1281
+ function offerEnvelopeRefusal(rec, who, height, expiresEpoch) {
1282
+ const wantIsToken = isTokenWant(rec.want);
1283
+ if ((wantIsToken || rec.min !== void 0 || rec.bid !== void 0) && height < V12_HEIGHT) return "v1.2 offer shape before activation";
1284
+ if (height >= V13_HEIGHT && height < V17_HEIGHT && !wantIsToken && rec.taker === void 0) return "v1.3: CSD-priced offers must be taker-bound (use bid/RFQ)";
1285
+ if ((rec.want.payto ?? who).toLowerCase() === TREASURY_ADDR) return "payto cannot be the protocol treasury";
1286
+ if (!Number.isSafeInteger(expiresEpoch)) return "expiresEpoch out of safe-integer range";
1287
+ if (epochOf(height) > expiresEpoch) return "already expired at anchor";
1288
+ if (height >= V21_HEIGHT && height < V22_HEIGHT && expiresEpoch - epochOf(height) > MAX_OFFER_EPOCHS) return "v2.1: offer duration exceeds the max";
1289
+ return null;
1290
+ }
1300
1291
 
1301
1292
  // src/resolve/tokens.ts
1302
1293
  function applyDeploy(c, ev, rec, who, feeToTreasury) {
@@ -1683,8 +1674,9 @@ function finalizeWinnerCheck(nameState, me, commitHeight, tip) {
1683
1674
  if (nameState.pending !== true) return { safe: false, reason: "already registered to you \u2014 no second finalize fee is needed" };
1684
1675
  if (Number(nameState.effectiveHeight) !== Number(commitHeight))
1685
1676
  return { safe: false, reason: "your reservation was displaced (effective height changed) \u2014 a finalize now would burn the fee" };
1686
- if (tip !== void 0 && tip !== null && Number.isFinite(Number(tip))) {
1687
- const t = Number(tip);
1677
+ if (tip !== void 0 && tip !== null) {
1678
+ if (!Number.isSafeInteger(tip) || tip < 0) return { safe: false, reason: `the chain tip given (${String(tip)}) is not a block height, so the finalize window cannot be checked` };
1679
+ const t = tip;
1688
1680
  const eff = Number(nameState.effectiveHeight);
1689
1681
  const freezeEnd = eff + REG_COMMIT_MAX_BLOCKS;
1690
1682
  const closeAt = eff + REG_COMMIT_MAX_BLOCKS + REG_FINALIZE_GRACE_BLOCKS - FINALIZE_TIP_MARGIN;
@@ -1746,15 +1738,17 @@ async function verifyFillSpv(offerId, fclaimTxid, me, io, opts) {
1746
1738
  return no("could not enumerate the offer's events");
1747
1739
  }
1748
1740
  const want = /* @__PURE__ */ new Set([offerId.toLowerCase(), fclaimTxid.toLowerCase(), ...(hintIds ?? []).map((x) => String(x).toLowerCase())]);
1741
+ const unproven = (wid) => wid === offerId.toLowerCase() ? no("offer not merkle-proven (no PoW-verified offer Propose)") : wid === fclaimTxid.toLowerCase() ? no("fclaim not merkle-proven (no PoW-verified fclaim Propose)") : no(`an event on this offer could not be merkle-proven (${wid}) - refusing, the replay would miss it`);
1749
1742
  const proven = [];
1750
1743
  for (const wid of want) {
1751
1744
  let ev;
1752
1745
  try {
1753
1746
  ev = await io.provenEvent(wid);
1754
1747
  } catch {
1755
- ev = null;
1748
+ return unproven(wid);
1756
1749
  }
1757
- if (ev && (ev.kind === "propose" ? ev.id : ev.txid).toLowerCase() === wid) proven.push(ev);
1750
+ if (!ev || (ev.kind === "propose" ? ev.id : ev.txid).toLowerCase() !== wid) return unproven(wid);
1751
+ proven.push(ev);
1758
1752
  }
1759
1753
  const isProp = (e) => e.kind === "propose";
1760
1754
  const offerEv = proven.find((e) => isProp(e) && e.id.toLowerCase() === offerId.toLowerCase());
@@ -1833,7 +1827,9 @@ function provenOfferTerms(offerRec, provenHeight) {
1833
1827
  giveTicker: g.ticker !== void 0 ? String(g.ticker) : void 0,
1834
1828
  giveAmount: g.amount !== void 0 ? String(g.amount) : void 0,
1835
1829
  giveName: g.name !== void 0 ? String(g.name) : void 0,
1836
- wantType: isTokenWant(offerRec.want) ? "token" : "csd"
1830
+ wantType: isTokenWant(offerRec.want) ? "token" : "csd",
1831
+ wantTicker: isTokenWant(offerRec.want) ? String(w.ticker) : void 0,
1832
+ wantAmount: isTokenWant(offerRec.want) ? String(w.amount) : void 0
1837
1833
  };
1838
1834
  }
1839
1835
  function bindOfferTerms(servedOffer, t, opts) {
@@ -1848,7 +1844,8 @@ function bindOfferTerms(servedOffer, t, opts) {
1848
1844
  if ((om !== void 0 && om !== null) !== (t.min !== void 0)) return true;
1849
1845
  if (t.min !== void 0 && String(om) !== t.min) return true;
1850
1846
  if (opts?.wantType !== false) {
1851
- if (t.wantType === void 0 || typeof o?.want?.ticker === "string" !== (t.wantType === "token")) return true;
1847
+ if (t.wantType === void 0) return true;
1848
+ if (t.wantType === "token" ? String(o?.want?.ticker) !== t.wantTicker || String(o?.want?.amount) !== t.wantAmount : typeof o?.want?.ticker === "string") return true;
1852
1849
  }
1853
1850
  if (opts?.give !== false) {
1854
1851
  const g = o?.give;
@@ -1922,6 +1919,34 @@ function myProvenFillClosedOffer(fill, fclaim2, offerEv, me, grantHeight) {
1922
1919
  return need.every((leg) => ptAmt(fill.paidTo?.[lc(leg.to)]) >= leg.value);
1923
1920
  }
1924
1921
 
1922
+ // src/holdcount.ts
1923
+ var lastLegacyClaimEnd = V28_HEIGHT - 1 + claimWindowAt(V28_HEIGHT - 1);
1924
+ var LEGACY_HOLD_SUNSET_HEIGHT = lastLegacyClaimEnd + claimGraceOf(lastLegacyClaimEnd);
1925
+ function countOtherHoldsAtGrant(candidates, target, me, closed = /* @__PURE__ */ new Set()) {
1926
+ if (!(Number.isSafeInteger(target.height) && target.height >= LEGACY_HOLD_SUNSET_HEIGHT))
1927
+ return { ok: false, reason: `this reservation was granted at ${target.height}, before block ${LEGACY_HOLD_SUNSET_HEIGHT}, while claims made before V28 could still count against the cap; it cannot be checked here` };
1928
+ const meL = String(me).toLowerCase(), tid = String(target.id).toLowerCase(), toffer = String(target.offer).toLowerCase();
1929
+ const offers = /* @__PURE__ */ new Set();
1930
+ for (const c of candidates) {
1931
+ const cid = String(c.id).toLowerCase();
1932
+ if (cid === tid || closed.has(cid) || String(c.proposer).toLowerCase() !== meL) continue;
1933
+ if (!(c.height < target.height || c.height === target.height && c.pos < target.pos)) continue;
1934
+ if (!(fclaimHoldEnd(Number(c.expiresEpoch)) >= target.height)) continue;
1935
+ const rec = parseRecord(String(c.uri), String(c.payloadHash));
1936
+ if (!rec || rec.t !== "fclaim") continue;
1937
+ const offer2 = String(rec.offer).toLowerCase();
1938
+ if (offer2 !== toffer) offers.add(offer2);
1939
+ }
1940
+ return { ok: true, count: offers.size };
1941
+ }
1942
+
1943
+ // src/admission.ts
1944
+ function provenOfferRefusal(rec, tx) {
1945
+ if (tx.domain !== DOMAIN) return `not a ${DOMAIN} Propose (domain ${JSON.stringify(String(tx.domain))})`;
1946
+ const ee = typeof tx.expiresEpoch === "bigint" ? Number(tx.expiresEpoch) : tx.expiresEpoch;
1947
+ return offerEnvelopeRefusal(rec, String(tx.seller).toLowerCase(), tx.height, ee);
1948
+ }
1949
+
1925
1950
  // src/index.ts
1926
1951
  import {
1927
1952
  canonicalJson as canonicalJson2,
@@ -1963,12 +1988,14 @@ export {
1963
1988
  HALVING_INTERVAL,
1964
1989
  HASH_RE,
1965
1990
  INITIAL_REWARD2 as INITIAL_REWARD,
1991
+ LEGACY_HOLD_SUNSET_HEIGHT,
1966
1992
  MAX_ACTIVE_CLAIMS,
1967
1993
  MAX_AMOUNT,
1968
1994
  MAX_OFFER_EPOCHS,
1969
1995
  MAX_PENDING_REG,
1970
1996
  MAX_RECORD_BYTES,
1971
1997
  MAX_SCAN,
1998
+ MAX_TOKEN_DECIMALS,
1972
1999
  MINT_KEYS,
1973
2000
  MIN_FEE_ATTEST,
1974
2001
  MIN_FEE_PROPOSE,
@@ -2035,6 +2062,7 @@ export {
2035
2062
  claimGraceOf,
2036
2063
  claimWindowAt,
2037
2064
  claimWindowOf,
2065
+ countOtherHoldsAtGrant,
2038
2066
  deploy,
2039
2067
  epochOf,
2040
2068
  expiredClaimFee,
@@ -2074,6 +2102,7 @@ export {
2074
2102
  pickPrimaryName,
2075
2103
  previewFill,
2076
2104
  primaryRankBefore,
2105
+ provenOfferRefusal,
2077
2106
  provenOfferTerms,
2078
2107
  ptAmt,
2079
2108
  replayLiveHold,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@inversealtruism/cairnx-core",
3
- "version": "0.2.1",
3
+ "version": "0.2.2",
4
4
  "engines": {
5
5
  "node": ">=18"
6
6
  },