@inversealtruism/cairnx-core 0.1.36 → 0.1.38

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.d.cts CHANGED
@@ -27,6 +27,8 @@ declare const CLAIM_WINDOW_BLOCKS_V20 = 40;
27
27
  declare const CLAIM_FILL_GRACE_BLOCKS = 5;
28
28
  declare const MAX_ACTIVE_CLAIMS = 3;
29
29
  declare const CLAIM_COOLDOWN_BLOCKS = 15;
30
+ declare const FCLAIM_MAX_EPOCH_AHEAD = 2;
31
+ declare const FILL_TIP_MARGIN = 4;
30
32
  declare const CONF_TOKEN_FILL = 1000000;
31
33
  declare const TREASURY_ADDR = "0x6b09ce74e6070ebc982ab0fb793a211c4d24f016";
32
34
  declare const FEE_BPS = 100;
@@ -70,10 +72,13 @@ declare const MAX_PENDING_REG = 3;
70
72
  declare const FINALIZE_TIP_MARGIN = 2;
71
73
  declare const V26_HEIGHT = 46480;
72
74
  declare const V27_HEIGHT = 46520;
75
+ declare const V28_HEIGHT = 60000;
73
76
  declare const epochOf: (height: number) => number;
74
77
  declare const claimWindowAt: (height: number) => number;
75
78
  declare const claimWindowOf: (claimUntilHeight: number) => number;
76
- declare const claimGraceOf: (claimUntilHeight: number) => number;
79
+ declare const claimGraceOf: (claimUntilHeight: number, claimTxid?: string) => number;
80
+ declare const fclaimEpochFor: (tipHeight: number, offerExpiresEpoch: number) => number;
81
+ declare const fclaimHoldEnd: (expiresEpoch: number) => number;
77
82
  declare const offerExpiryHeightOf: (expiresEpoch: number, anchorHeight: number) => number;
78
83
  interface DeployRecord {
79
84
  v: 1;
@@ -194,7 +199,12 @@ interface NameProfileRecord {
194
199
  name: string;
195
200
  p: Record<string, string>;
196
201
  }
197
- type CairnXRecord = DeployRecord | MintRecord | TransferRecord | OfferRecord | BidRecord | OfferCancelAllRecord | NameCommitRecord | NameRecord | NameFinalizeRecord | NameXferRecord | NameSetRecord | NameRenewRecord | TokenMetaRecord | NameProfileRecord;
202
+ interface FclaimRecord {
203
+ v: 1;
204
+ t: "fclaim";
205
+ offer: string;
206
+ }
207
+ type CairnXRecord = DeployRecord | MintRecord | TransferRecord | OfferRecord | BidRecord | OfferCancelAllRecord | NameCommitRecord | NameRecord | NameFinalizeRecord | NameXferRecord | NameSetRecord | NameRenewRecord | TokenMetaRecord | NameProfileRecord | FclaimRecord;
198
208
  interface ProposeEvent {
199
209
  kind: "propose";
200
210
  id: string;
@@ -299,6 +309,10 @@ interface OfferState {
299
309
  * a past claimUntilHeight just means no live claim (the fields persist as the last-claim record). */
300
310
  claimedBy?: string;
301
311
  claimUntilHeight?: number;
312
+ /** v2.8 fclaim (§31, V28+): the txid of the granting fclaim Propose. LAST-WRITE-WINS (re-assigned on every
313
+ * grant, never set-once, never cleared), so fill-routing (claimTxid === fclaimTxid) tracks the CURRENT holder.
314
+ * Present only once granted at V28+; a canonical offer field (§5.1). */
315
+ claimTxid?: string;
302
316
  fill?: FillEntry;
303
317
  }
304
318
  type BidStatus = "open" | "cancelled" | "expired" | "done";
@@ -343,6 +357,16 @@ interface CairnXState {
343
357
  effectiveHeight: number;
344
358
  finalizeBy: number;
345
359
  }>;
360
+ /** v2.8 fclaim (§31): GRANTED fclaims (fclaimTxid → linked offer + proposer + expiry epoch + grant height),
361
+ * for the wallet/UI and the cairnx service D2 alias. DIAGNOSTIC, excluded from canonicalState (like
362
+ * `recaptures`/`events`); resolve() always returns it, and the one initial-state literal (cairnx service)
363
+ * constructs an empty {}. */
364
+ fclaims: Record<string, {
365
+ offer: string;
366
+ proposer: string;
367
+ expiresEpoch: number;
368
+ height: number;
369
+ }>;
346
370
  events: AppliedEvent[];
347
371
  feesPaid: string;
348
372
  }
@@ -375,6 +399,7 @@ declare const BID_KEYS: Set<string>;
375
399
  declare const NAME_KEYS: Set<string>;
376
400
  declare const NFINALIZE_KEYS: Set<string>;
377
401
  declare const NPROFILE_KEYS: Set<string>;
402
+ declare const FCLAIM_KEYS: Set<string>;
378
403
  /**
379
404
  * Parse + validate a record from an anchored `uri`. Returns null for anything invalid —
380
405
  * per CONVENTION §3, invalid is a no-op, never an error that poisons the replay.
@@ -398,6 +423,7 @@ declare const nameSet: (r: Omit<NameSetRecord, "v" | "t">) => BuiltRecord;
398
423
  declare const nameRenew: (r: Omit<NameRenewRecord, "v" | "t">) => BuiltRecord;
399
424
  declare const tokenMeta: (r: Omit<TokenMetaRecord, "v" | "t">) => BuiltRecord;
400
425
  declare const nameProfile: (r: Omit<NameProfileRecord, "v" | "t">) => BuiltRecord;
426
+ declare const fclaim: (r: Omit<FclaimRecord, "v" | "t">) => BuiltRecord;
401
427
 
402
428
  declare function resolve(events: ChainEvent[], tipHeight: number): CairnXState;
403
429
  /** Canonical serialization of state (FORMAT 2) — byte-identical across honest resolvers.
@@ -480,6 +506,12 @@ declare function isOpenClaimLane(offer: OfferState, tip: number): boolean;
480
506
  /** Does `me` currently hold a LIVE claim on `offer` at `tip`? Mirrors resolve.ts claimHeld + the
481
507
  * who===claimedBy check (:160-169). For a pre-V17 open offer, open fills are banned entirely. */
482
508
  declare function hasLiveClaim(offer: OfferState, me: string, tip: number): boolean;
509
+ /** v2.8 Correction 1 mirror (§31): the proposal txid a fill of `offer` MUST attest at `tip`. During a live
510
+ * fclaim hold (V28+) the payment must target the FCLAIM txid, not the offer id (an offer-txid fill is
511
+ * resolver-rejected while a hold is live, `openFillReject`). Below V28, or with no live fclaim hold, the
512
+ * target is the offer id (legacy). A client builds the fill against this id so it never signs a doomed
513
+ * offer-txid fill during a hold. */
514
+ declare function fillTargetId(offer: OfferState, tip: number): string;
483
515
  /** The union verdict a client must clear BEFORE signing a fill of `offer` paying `pay`, as `me`, at `tip`.
484
516
  * Closes C2/C3/C4: status open, deliverability >= 1 token, live-claim holdership for the open-CSD lane,
485
517
  * and taker match. `safe:true` ⇒ the fill is guaranteed to be accepted by the deterministic gates a
@@ -494,18 +526,26 @@ declare function fillIsSafe(offer: OfferState, me: string, pay: bigint | string
494
526
  /** C1: may `me` safely sign the fee-bearing registration `nfinalize` for `nameState` committed at
495
527
  * `commitHeight`? The reg fee rides nfinalize; a finalize on a reservation that was displaced, has
496
528
  * expired, OR is raised before the displacement contest froze is REJECTED after the fee moved (a burn).
497
- * Sound by the freeze arithmetic: once a client waits for `tip > effectiveHeight + REG_COMMIT_MAX_BLOCKS`
498
- * no new displacer can appear, so a re-fetch showing "still my live pending reservation at my commit
499
- * height" guarantees the finalize lands. Pass the AUTHORITATIVE (freshly re-fetched) name record — never
500
- * a cached one — as `nameState` (undefined = the resolver returns 404 / unregistered, a definitive loss).
501
529
  *
502
- * Pass `tip` (the freshest chain tip you have) to ALSO gate the finalize WINDOW, both sides, mirroring
503
- * the resolver's authoritative checks (resolve.ts nfinalize: rejects unless
504
- * `ev.height > effHeight + REG_COMMIT_MAX_BLOCKS`, and rejects when `ev.height > finalizeBy`) with the
505
- * client-side FINALIZE_TIP_MARGIN band the site's finalizeReady applies: the tx signs at `tip` but mines
506
- * at tip+1 or later, so the margin keeps a boundary-signed finalize from mining outside the window (too
507
- * early: rejected as unfrozen; too late: past the deadline — either way the fee burned). `tip` is
508
- * optional so callers without a tip keep the winner-only semantics; N-2 closes only when it is passed. */
530
+ * TRUST SCOPE (read before relying on this): this is a STALE-STATE and displacement-race guard under an
531
+ * HONEST resolver, NOT a Byzantine-resolver defense. Its safety rests on `commitHeight` coming from a
532
+ * source INDEPENDENT of `nameState` — then `effectiveHeight !== commitHeight` genuinely detects a
533
+ * displaced/forged reservation. A caller that passes `nameState.effectiveHeight` AS `commitHeight` makes
534
+ * that guard a tautology (`X !== X`), so `eff` becomes resolver-controlled and this helper gives
535
+ * window-SHAPE correctness only, not protection against a resolver that lies about `effectiveHeight`.
536
+ * No field arithmetic here can defeat a resolver that forges the whole record (owner/pending/eff at once);
537
+ * that closure is registration-state SPV (roadmapped), the same posture the fill path documents (a
538
+ * coherently lying resolver is the fill-SPV item, not this guard). Pass the AUTHORITATIVE (freshly
539
+ * re-fetched) name record — never a cached one — as `nameState` (undefined = 404 / unregistered = loss).
540
+ *
541
+ * Pass `tip` to ALSO gate the finalize WINDOW, both sides, mirroring the resolver's authoritative checks
542
+ * (resolve.ts nfinalize rejects unless `ev.height > effHeight + REG_COMMIT_MAX_BLOCKS`, and rejects when
543
+ * `ev.height > finalizeBy`) with the client-side FINALIZE_TIP_MARGIN band the site's finalizeReady applies:
544
+ * the tx signs at `tip` but mines at tip+1 or later, so the margin keeps a boundary-signed finalize from
545
+ * mining outside the window (too early: rejected as unfrozen; too late: past the deadline — either way the
546
+ * fee burns). The window is derived purely from `eff` (never the resolver's `finalizeBy`), so a lying
547
+ * `finalizeBy` cannot widen it — but per the trust scope above, a lying `eff` still can for a caller that
548
+ * does not supply an independent `commitHeight`. `tip` is optional; without it the winner-only path runs. */
509
549
  declare function finalizeWinnerCheck(nameState: NameState | null | undefined, me: string, commitHeight: number, tip?: number | null): {
510
550
  safe: boolean;
511
551
  reason: string;
@@ -518,9 +558,87 @@ declare const primaryRankBefore: (a: NameState, b: NameState) => boolean;
518
558
  /** The primary .csd name for address `a`, or null. Pure; no I/O. `a` may be any case. */
519
559
  declare function pickPrimaryName(names: Iterable<NameState>, a: string): string | null;
520
560
 
561
+ declare const GAP_NEEDED: number;
562
+ declare const SCAN_MARGIN = 30;
563
+ declare const MAX_SCAN: number;
564
+ type ProvenPropose = ProposeEvent & {
565
+ depth: number;
566
+ };
567
+ type ProvenAttest = AttestEvent & {
568
+ depth: number;
569
+ };
570
+ type ProvenEvent = ProvenPropose | ProvenAttest;
571
+ interface FillSpvIo {
572
+ tip(): Promise<number>;
573
+ offerEventIds(offerId: string, fclaimTxid: string): Promise<string[]>;
574
+ provenEvent(id: string): Promise<ProvenEvent | null>;
575
+ }
576
+ interface HoldReplay {
577
+ state: CairnXState;
578
+ offer?: OfferState;
579
+ granted: boolean;
580
+ routed: boolean;
581
+ heldByMe: boolean;
582
+ }
583
+ declare function replayLiveHold(proven: ProvenEvent[], offerId: string, fclaimTxid: string, me: string, evalHeight: number): HoldReplay;
584
+ interface FillVerdict {
585
+ safe: boolean;
586
+ reason: string;
587
+ }
588
+ /**
589
+ * The union verdict a client MUST clear before signing an open-lane fclaim fill: offer + fclaim
590
+ * MERKLE-PROVEN and bound to their on-chain commitment (A1), both (and any earlier fill-basis) buried
591
+ * `>= requiredClaimDepth`, the grant REPLAYED to a live hold that is mine and routes to THIS fclaim, the
592
+ * fill delivering `>= 1` unit, and a FILL_TIP_MARGIN deadline cushion. Fails CLOSED on any unmet condition.
593
+ * Accepts every honest fill (the holder, live hold, buried, offer+fclaim proven, delivery >= 1); it only
594
+ * refuses the doomed/forged cases (a denied fclaim a lying resolver calls "granted", a cancelled/lapsed or
595
+ * not-mine hold, a below-depth signing, a zero-delivery fill, a stranded past-deadline broadcast).
596
+ *
597
+ * `opts.myLiveHoldsAtGrant` (REQUIRED) is the buyer's count of OTHER live fclaim/legacy holds at the moment
598
+ * THIS fclaim was granted, asserted by the authoring client (which signed its own claims). The lane-scoped
599
+ * replay cannot see the buyer's other-offer holds, and MAX_ACTIVE_CLAIMS is the one grant clause counted
600
+ * across offers, so without this the surface would false-accept a cap-denied fclaim. `opts.pay` overrides the
601
+ * payment (base units to want.payto) for a PARTIAL tail-fill; defaults to the offer's full want.value.
602
+ */
603
+ declare function verifyFillSpv(offerId: string, fclaimTxid: string, me: string, io: FillSpvIo, opts: {
604
+ myLiveHoldsAtGrant: number;
605
+ pay?: bigint | string | number;
606
+ }): Promise<FillVerdict>;
607
+ interface ProvenOfferTerms {
608
+ height: number;
609
+ feeBps: number;
610
+ value?: string;
611
+ taker?: string;
612
+ bid?: string;
613
+ min?: string;
614
+ }
615
+ declare const feeBpsAt: (height: number) => number;
616
+ declare function provenOfferTerms(offerRec: OfferRecord, provenHeight: number): ProvenOfferTerms;
617
+ /**
618
+ * The fill-boundary TERM-MISMATCH verdict: `true` iff any fee/rebate/partial-sizing field of the resolver-
619
+ * SERVED offer diverges from the merkle-proven terms `t`. FAIL-CLOSED semantics (any divergence => true =>
620
+ * the caller refuses). Byte-identical in behaviour to the wallet's old provenTermsMismatch and the site's
621
+ * old inline amount-leg bind (they were reconciled to be one predicate here):
622
+ * - height (offer.height vs t.height)
623
+ * - feeBps (offer.feeBps vs t.feeBps = feeBpsAt(creation height))
624
+ * - value (offer.want.value vs t.value, only when the proven offer is CSD-priced)
625
+ * - taker (offer.taker vs t.taker, case-insensitive, undefined/null == "")
626
+ * - bid (offer.bid vs t.bid, same normalization)
627
+ * - min presence AND value: an ADDED spurious min (whole->partial rebate-drop burn) OR a deflated min
628
+ * both mismatch. EXPLICIT presence (a served min="" must not slip past a proven-absent min).
629
+ * `value` is bound only when `t.value` is defined so a token<->token offer (no CSD value) is not spuriously
630
+ * refused; a caller that binds want.value separately (the site does) may still pass it here (redundant-safe).
631
+ */
632
+ declare function bindOfferTerms(servedOffer: unknown, t: ProvenOfferTerms): boolean;
633
+ declare function bindProvenOffer(offerEv: ProvenPropose): {
634
+ payto: string;
635
+ seller: string;
636
+ terms: ProvenOfferTerms;
637
+ } | null;
638
+
521
639
  declare function paidToFromOutputs(outputs: readonly {
522
640
  addr: string;
523
641
  value: number;
524
642
  }[]): Record<string, string>;
525
643
 
526
- 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, FEE_BPS, FEE_BPS_V16, FEE_GATE_MARGIN_BLOCKS, FINALIZE_TIP_MARGIN, type FillEntry, type FillPreview, type FillSafety, type Give, HASH_RE, MAX_ACTIVE_CLAIMS, MAX_AMOUNT, MAX_OFFER_EPOCHS, MAX_PENDING_REG, MAX_RECORD_BYTES, 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, REBATE_BPS, REBATE_FLAT, REG_COMMIT_MAX_BLOCKS, REG_FINALIZE_GRACE_BLOCKS, RESERVED_NAMES, SALT_RE, 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, type Want, ZERO_ADDR, bid, buildFeeHeight, buildRecord, canonicalState, claimGraceOf, claimWindowAt, claimWindowOf, deploy, epochOf, expiredClaimFee, fillIsSafe, 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, requiredClaimDepth, requiredFillOutputs, resolve, tokenMeta, tradeFee, transfer };
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 };
package/dist/index.d.ts CHANGED
@@ -27,6 +27,8 @@ declare const CLAIM_WINDOW_BLOCKS_V20 = 40;
27
27
  declare const CLAIM_FILL_GRACE_BLOCKS = 5;
28
28
  declare const MAX_ACTIVE_CLAIMS = 3;
29
29
  declare const CLAIM_COOLDOWN_BLOCKS = 15;
30
+ declare const FCLAIM_MAX_EPOCH_AHEAD = 2;
31
+ declare const FILL_TIP_MARGIN = 4;
30
32
  declare const CONF_TOKEN_FILL = 1000000;
31
33
  declare const TREASURY_ADDR = "0x6b09ce74e6070ebc982ab0fb793a211c4d24f016";
32
34
  declare const FEE_BPS = 100;
@@ -70,10 +72,13 @@ declare const MAX_PENDING_REG = 3;
70
72
  declare const FINALIZE_TIP_MARGIN = 2;
71
73
  declare const V26_HEIGHT = 46480;
72
74
  declare const V27_HEIGHT = 46520;
75
+ declare const V28_HEIGHT = 60000;
73
76
  declare const epochOf: (height: number) => number;
74
77
  declare const claimWindowAt: (height: number) => number;
75
78
  declare const claimWindowOf: (claimUntilHeight: number) => number;
76
- declare const claimGraceOf: (claimUntilHeight: number) => number;
79
+ declare const claimGraceOf: (claimUntilHeight: number, claimTxid?: string) => number;
80
+ declare const fclaimEpochFor: (tipHeight: number, offerExpiresEpoch: number) => number;
81
+ declare const fclaimHoldEnd: (expiresEpoch: number) => number;
77
82
  declare const offerExpiryHeightOf: (expiresEpoch: number, anchorHeight: number) => number;
78
83
  interface DeployRecord {
79
84
  v: 1;
@@ -194,7 +199,12 @@ interface NameProfileRecord {
194
199
  name: string;
195
200
  p: Record<string, string>;
196
201
  }
197
- type CairnXRecord = DeployRecord | MintRecord | TransferRecord | OfferRecord | BidRecord | OfferCancelAllRecord | NameCommitRecord | NameRecord | NameFinalizeRecord | NameXferRecord | NameSetRecord | NameRenewRecord | TokenMetaRecord | NameProfileRecord;
202
+ interface FclaimRecord {
203
+ v: 1;
204
+ t: "fclaim";
205
+ offer: string;
206
+ }
207
+ type CairnXRecord = DeployRecord | MintRecord | TransferRecord | OfferRecord | BidRecord | OfferCancelAllRecord | NameCommitRecord | NameRecord | NameFinalizeRecord | NameXferRecord | NameSetRecord | NameRenewRecord | TokenMetaRecord | NameProfileRecord | FclaimRecord;
198
208
  interface ProposeEvent {
199
209
  kind: "propose";
200
210
  id: string;
@@ -299,6 +309,10 @@ interface OfferState {
299
309
  * a past claimUntilHeight just means no live claim (the fields persist as the last-claim record). */
300
310
  claimedBy?: string;
301
311
  claimUntilHeight?: number;
312
+ /** v2.8 fclaim (§31, V28+): the txid of the granting fclaim Propose. LAST-WRITE-WINS (re-assigned on every
313
+ * grant, never set-once, never cleared), so fill-routing (claimTxid === fclaimTxid) tracks the CURRENT holder.
314
+ * Present only once granted at V28+; a canonical offer field (§5.1). */
315
+ claimTxid?: string;
302
316
  fill?: FillEntry;
303
317
  }
304
318
  type BidStatus = "open" | "cancelled" | "expired" | "done";
@@ -343,6 +357,16 @@ interface CairnXState {
343
357
  effectiveHeight: number;
344
358
  finalizeBy: number;
345
359
  }>;
360
+ /** v2.8 fclaim (§31): GRANTED fclaims (fclaimTxid → linked offer + proposer + expiry epoch + grant height),
361
+ * for the wallet/UI and the cairnx service D2 alias. DIAGNOSTIC, excluded from canonicalState (like
362
+ * `recaptures`/`events`); resolve() always returns it, and the one initial-state literal (cairnx service)
363
+ * constructs an empty {}. */
364
+ fclaims: Record<string, {
365
+ offer: string;
366
+ proposer: string;
367
+ expiresEpoch: number;
368
+ height: number;
369
+ }>;
346
370
  events: AppliedEvent[];
347
371
  feesPaid: string;
348
372
  }
@@ -375,6 +399,7 @@ declare const BID_KEYS: Set<string>;
375
399
  declare const NAME_KEYS: Set<string>;
376
400
  declare const NFINALIZE_KEYS: Set<string>;
377
401
  declare const NPROFILE_KEYS: Set<string>;
402
+ declare const FCLAIM_KEYS: Set<string>;
378
403
  /**
379
404
  * Parse + validate a record from an anchored `uri`. Returns null for anything invalid —
380
405
  * per CONVENTION §3, invalid is a no-op, never an error that poisons the replay.
@@ -398,6 +423,7 @@ declare const nameSet: (r: Omit<NameSetRecord, "v" | "t">) => BuiltRecord;
398
423
  declare const nameRenew: (r: Omit<NameRenewRecord, "v" | "t">) => BuiltRecord;
399
424
  declare const tokenMeta: (r: Omit<TokenMetaRecord, "v" | "t">) => BuiltRecord;
400
425
  declare const nameProfile: (r: Omit<NameProfileRecord, "v" | "t">) => BuiltRecord;
426
+ declare const fclaim: (r: Omit<FclaimRecord, "v" | "t">) => BuiltRecord;
401
427
 
402
428
  declare function resolve(events: ChainEvent[], tipHeight: number): CairnXState;
403
429
  /** Canonical serialization of state (FORMAT 2) — byte-identical across honest resolvers.
@@ -480,6 +506,12 @@ declare function isOpenClaimLane(offer: OfferState, tip: number): boolean;
480
506
  /** Does `me` currently hold a LIVE claim on `offer` at `tip`? Mirrors resolve.ts claimHeld + the
481
507
  * who===claimedBy check (:160-169). For a pre-V17 open offer, open fills are banned entirely. */
482
508
  declare function hasLiveClaim(offer: OfferState, me: string, tip: number): boolean;
509
+ /** v2.8 Correction 1 mirror (§31): the proposal txid a fill of `offer` MUST attest at `tip`. During a live
510
+ * fclaim hold (V28+) the payment must target the FCLAIM txid, not the offer id (an offer-txid fill is
511
+ * resolver-rejected while a hold is live, `openFillReject`). Below V28, or with no live fclaim hold, the
512
+ * target is the offer id (legacy). A client builds the fill against this id so it never signs a doomed
513
+ * offer-txid fill during a hold. */
514
+ declare function fillTargetId(offer: OfferState, tip: number): string;
483
515
  /** The union verdict a client must clear BEFORE signing a fill of `offer` paying `pay`, as `me`, at `tip`.
484
516
  * Closes C2/C3/C4: status open, deliverability >= 1 token, live-claim holdership for the open-CSD lane,
485
517
  * and taker match. `safe:true` ⇒ the fill is guaranteed to be accepted by the deterministic gates a
@@ -494,18 +526,26 @@ declare function fillIsSafe(offer: OfferState, me: string, pay: bigint | string
494
526
  /** C1: may `me` safely sign the fee-bearing registration `nfinalize` for `nameState` committed at
495
527
  * `commitHeight`? The reg fee rides nfinalize; a finalize on a reservation that was displaced, has
496
528
  * expired, OR is raised before the displacement contest froze is REJECTED after the fee moved (a burn).
497
- * Sound by the freeze arithmetic: once a client waits for `tip > effectiveHeight + REG_COMMIT_MAX_BLOCKS`
498
- * no new displacer can appear, so a re-fetch showing "still my live pending reservation at my commit
499
- * height" guarantees the finalize lands. Pass the AUTHORITATIVE (freshly re-fetched) name record — never
500
- * a cached one — as `nameState` (undefined = the resolver returns 404 / unregistered, a definitive loss).
501
529
  *
502
- * Pass `tip` (the freshest chain tip you have) to ALSO gate the finalize WINDOW, both sides, mirroring
503
- * the resolver's authoritative checks (resolve.ts nfinalize: rejects unless
504
- * `ev.height > effHeight + REG_COMMIT_MAX_BLOCKS`, and rejects when `ev.height > finalizeBy`) with the
505
- * client-side FINALIZE_TIP_MARGIN band the site's finalizeReady applies: the tx signs at `tip` but mines
506
- * at tip+1 or later, so the margin keeps a boundary-signed finalize from mining outside the window (too
507
- * early: rejected as unfrozen; too late: past the deadline — either way the fee burned). `tip` is
508
- * optional so callers without a tip keep the winner-only semantics; N-2 closes only when it is passed. */
530
+ * TRUST SCOPE (read before relying on this): this is a STALE-STATE and displacement-race guard under an
531
+ * HONEST resolver, NOT a Byzantine-resolver defense. Its safety rests on `commitHeight` coming from a
532
+ * source INDEPENDENT of `nameState` — then `effectiveHeight !== commitHeight` genuinely detects a
533
+ * displaced/forged reservation. A caller that passes `nameState.effectiveHeight` AS `commitHeight` makes
534
+ * that guard a tautology (`X !== X`), so `eff` becomes resolver-controlled and this helper gives
535
+ * window-SHAPE correctness only, not protection against a resolver that lies about `effectiveHeight`.
536
+ * No field arithmetic here can defeat a resolver that forges the whole record (owner/pending/eff at once);
537
+ * that closure is registration-state SPV (roadmapped), the same posture the fill path documents (a
538
+ * coherently lying resolver is the fill-SPV item, not this guard). Pass the AUTHORITATIVE (freshly
539
+ * re-fetched) name record — never a cached one — as `nameState` (undefined = 404 / unregistered = loss).
540
+ *
541
+ * Pass `tip` to ALSO gate the finalize WINDOW, both sides, mirroring the resolver's authoritative checks
542
+ * (resolve.ts nfinalize rejects unless `ev.height > effHeight + REG_COMMIT_MAX_BLOCKS`, and rejects when
543
+ * `ev.height > finalizeBy`) with the client-side FINALIZE_TIP_MARGIN band the site's finalizeReady applies:
544
+ * the tx signs at `tip` but mines at tip+1 or later, so the margin keeps a boundary-signed finalize from
545
+ * mining outside the window (too early: rejected as unfrozen; too late: past the deadline — either way the
546
+ * fee burns). The window is derived purely from `eff` (never the resolver's `finalizeBy`), so a lying
547
+ * `finalizeBy` cannot widen it — but per the trust scope above, a lying `eff` still can for a caller that
548
+ * does not supply an independent `commitHeight`. `tip` is optional; without it the winner-only path runs. */
509
549
  declare function finalizeWinnerCheck(nameState: NameState | null | undefined, me: string, commitHeight: number, tip?: number | null): {
510
550
  safe: boolean;
511
551
  reason: string;
@@ -518,9 +558,87 @@ declare const primaryRankBefore: (a: NameState, b: NameState) => boolean;
518
558
  /** The primary .csd name for address `a`, or null. Pure; no I/O. `a` may be any case. */
519
559
  declare function pickPrimaryName(names: Iterable<NameState>, a: string): string | null;
520
560
 
561
+ declare const GAP_NEEDED: number;
562
+ declare const SCAN_MARGIN = 30;
563
+ declare const MAX_SCAN: number;
564
+ type ProvenPropose = ProposeEvent & {
565
+ depth: number;
566
+ };
567
+ type ProvenAttest = AttestEvent & {
568
+ depth: number;
569
+ };
570
+ type ProvenEvent = ProvenPropose | ProvenAttest;
571
+ interface FillSpvIo {
572
+ tip(): Promise<number>;
573
+ offerEventIds(offerId: string, fclaimTxid: string): Promise<string[]>;
574
+ provenEvent(id: string): Promise<ProvenEvent | null>;
575
+ }
576
+ interface HoldReplay {
577
+ state: CairnXState;
578
+ offer?: OfferState;
579
+ granted: boolean;
580
+ routed: boolean;
581
+ heldByMe: boolean;
582
+ }
583
+ declare function replayLiveHold(proven: ProvenEvent[], offerId: string, fclaimTxid: string, me: string, evalHeight: number): HoldReplay;
584
+ interface FillVerdict {
585
+ safe: boolean;
586
+ reason: string;
587
+ }
588
+ /**
589
+ * The union verdict a client MUST clear before signing an open-lane fclaim fill: offer + fclaim
590
+ * MERKLE-PROVEN and bound to their on-chain commitment (A1), both (and any earlier fill-basis) buried
591
+ * `>= requiredClaimDepth`, the grant REPLAYED to a live hold that is mine and routes to THIS fclaim, the
592
+ * fill delivering `>= 1` unit, and a FILL_TIP_MARGIN deadline cushion. Fails CLOSED on any unmet condition.
593
+ * Accepts every honest fill (the holder, live hold, buried, offer+fclaim proven, delivery >= 1); it only
594
+ * refuses the doomed/forged cases (a denied fclaim a lying resolver calls "granted", a cancelled/lapsed or
595
+ * not-mine hold, a below-depth signing, a zero-delivery fill, a stranded past-deadline broadcast).
596
+ *
597
+ * `opts.myLiveHoldsAtGrant` (REQUIRED) is the buyer's count of OTHER live fclaim/legacy holds at the moment
598
+ * THIS fclaim was granted, asserted by the authoring client (which signed its own claims). The lane-scoped
599
+ * replay cannot see the buyer's other-offer holds, and MAX_ACTIVE_CLAIMS is the one grant clause counted
600
+ * across offers, so without this the surface would false-accept a cap-denied fclaim. `opts.pay` overrides the
601
+ * payment (base units to want.payto) for a PARTIAL tail-fill; defaults to the offer's full want.value.
602
+ */
603
+ declare function verifyFillSpv(offerId: string, fclaimTxid: string, me: string, io: FillSpvIo, opts: {
604
+ myLiveHoldsAtGrant: number;
605
+ pay?: bigint | string | number;
606
+ }): Promise<FillVerdict>;
607
+ interface ProvenOfferTerms {
608
+ height: number;
609
+ feeBps: number;
610
+ value?: string;
611
+ taker?: string;
612
+ bid?: string;
613
+ min?: string;
614
+ }
615
+ declare const feeBpsAt: (height: number) => number;
616
+ declare function provenOfferTerms(offerRec: OfferRecord, provenHeight: number): ProvenOfferTerms;
617
+ /**
618
+ * The fill-boundary TERM-MISMATCH verdict: `true` iff any fee/rebate/partial-sizing field of the resolver-
619
+ * SERVED offer diverges from the merkle-proven terms `t`. FAIL-CLOSED semantics (any divergence => true =>
620
+ * the caller refuses). Byte-identical in behaviour to the wallet's old provenTermsMismatch and the site's
621
+ * old inline amount-leg bind (they were reconciled to be one predicate here):
622
+ * - height (offer.height vs t.height)
623
+ * - feeBps (offer.feeBps vs t.feeBps = feeBpsAt(creation height))
624
+ * - value (offer.want.value vs t.value, only when the proven offer is CSD-priced)
625
+ * - taker (offer.taker vs t.taker, case-insensitive, undefined/null == "")
626
+ * - bid (offer.bid vs t.bid, same normalization)
627
+ * - min presence AND value: an ADDED spurious min (whole->partial rebate-drop burn) OR a deflated min
628
+ * both mismatch. EXPLICIT presence (a served min="" must not slip past a proven-absent min).
629
+ * `value` is bound only when `t.value` is defined so a token<->token offer (no CSD value) is not spuriously
630
+ * refused; a caller that binds want.value separately (the site does) may still pass it here (redundant-safe).
631
+ */
632
+ declare function bindOfferTerms(servedOffer: unknown, t: ProvenOfferTerms): boolean;
633
+ declare function bindProvenOffer(offerEv: ProvenPropose): {
634
+ payto: string;
635
+ seller: string;
636
+ terms: ProvenOfferTerms;
637
+ } | null;
638
+
521
639
  declare function paidToFromOutputs(outputs: readonly {
522
640
  addr: string;
523
641
  value: number;
524
642
  }[]): Record<string, string>;
525
643
 
526
- 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, FEE_BPS, FEE_BPS_V16, FEE_GATE_MARGIN_BLOCKS, FINALIZE_TIP_MARGIN, type FillEntry, type FillPreview, type FillSafety, type Give, HASH_RE, MAX_ACTIVE_CLAIMS, MAX_AMOUNT, MAX_OFFER_EPOCHS, MAX_PENDING_REG, MAX_RECORD_BYTES, 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, REBATE_BPS, REBATE_FLAT, REG_COMMIT_MAX_BLOCKS, REG_FINALIZE_GRACE_BLOCKS, RESERVED_NAMES, SALT_RE, 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, type Want, ZERO_ADDR, bid, buildFeeHeight, buildRecord, canonicalState, claimGraceOf, claimWindowAt, claimWindowOf, deploy, epochOf, expiredClaimFee, fillIsSafe, 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, requiredClaimDepth, requiredFillOutputs, resolve, tokenMeta, tradeFee, transfer };
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 };