@inversealtruism/cairnx-core 0.2.2 → 0.2.4

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
@@ -2,6 +2,8 @@ export { EPOCH_LEN, HALVING_INTERVAL, INITIAL_REWARD, MIN_FEE_ATTEST, MIN_FEE_PR
2
2
 
3
3
  declare const DOMAIN = "cairnx:v1";
4
4
  declare const ACTIVATION_HEIGHT = 29860;
5
+ /** True below ACTIVATION_HEIGHT, where resolve() skips every event without a note. */
6
+ declare const beforeActivation: (height: number) => boolean;
5
7
  declare const V11_HEIGHT = 29960;
6
8
  declare const V12_HEIGHT = 30300;
7
9
  declare const V13_HEIGHT = 31100;
@@ -83,6 +85,7 @@ declare const claimGraceOf: (claimUntilHeight: number, claimTxid?: string) => nu
83
85
  declare const fclaimEpochFor: (tipHeight: number, offerExpiresEpoch: number) => number;
84
86
  declare const fclaimHoldEnd: (expiresEpoch: number) => number;
85
87
  declare const offerExpiryHeightOf: (expiresEpoch: number, anchorHeight: number) => number;
88
+ declare const offerFillTooLate: (expiresAt: number, tip: number) => boolean;
86
89
  interface DeployRecord {
87
90
  v: 1;
88
91
  t: "deploy";
@@ -445,15 +448,21 @@ declare const CLAIM_MIN_DEPTH = 3;
445
448
  declare const COMMIT_REVEAL_MIN_DEPTH = 3;
446
449
  /**
447
450
  * Confirmations the CLAIM must have before a payment-bearing fill on an open V17 offer worth `valueSats`
448
- * (anchored at `height`) is reorg-safe. Returns `{ depth, reversalPct, capped }`; `capped=true` ⇒ the value
449
- * exceeds what one claim window can safely settle (the buyer should split the trade).
451
+ * (anchored at `height`), so that a minority miner undoing the claim is unlikely. Returns
452
+ * `{ depth, reversalPct, capped }`; `reversalPct` is that miner's chance of reversing `depth` blocks, positive at every depth;
453
+ * `capped=true` ⇒ the value exceeds what one claim window can settle (the buyer should split the trade).
450
454
  *
451
- * A MINORITY attacker (the dominant pool is trusted; a majority means the chain is already lost) only profits
452
- * if `P(reverse D)·V > the honest reward it forgoes`, with `P(reverse D) ≈ (q/(1−q))^D` (gambler's ruin,
455
+ * The model is a miner with `CLAIM_ATTACKER_Q` of the hashrate. It only profits if
456
+ * `P(reverse D)·V > the honest reward it forgoes`, with `P(reverse D) ≈ (q/(1−q))^D` (gambler's ruin,
453
457
  * Nakamoto §11). That is logarithmic in value → ~3 conf for nearly every trade, 4 for a whale. Everything is
454
458
  * in CSD (block reward), so no USD price is needed. The required depth is capped at `claimWindow − 5` so a
455
459
  * capped/whale value stays fillable for a usable multi-block span rather than a 1-block knife-edge (only
456
460
  * absurd > total-supply values ever reach the cap).
461
+ *
462
+ * The pool that produces most blocks is outside this model. It is an external party, not run by Cairn; no depth
463
+ * bounds a producer with more than half the hashrate (the reversal chance is 1 at q ≥ 0.5), and reordering recent
464
+ * blocks costs it almost nothing, since it re-mines them and keeps their rewards. The wait guards against smaller
465
+ * miners only.
457
466
  */
458
467
  declare function requiredClaimDepth(valueSats: number | bigint, height: number): {
459
468
  depth: number;
@@ -651,6 +660,7 @@ declare const primaryRankBefore: (a: NameState, b: NameState) => boolean;
651
660
  /** The primary .csd name for address `a`, or null. Pure; no I/O. `a` may be any case. */
652
661
  declare function pickPrimaryName(names: Iterable<NameState>, a: string): string | null;
653
662
 
663
+ declare const FCLAIM_MAX_HOLD_SPAN: number;
654
664
  declare const GAP_NEEDED: number;
655
665
  declare const SCAN_MARGIN = 30;
656
666
  declare const MAX_SCAN: number;
@@ -683,9 +693,13 @@ interface FillVerdict {
683
693
  * MERKLE-PROVEN and bound to their on-chain commitment (A1), both (and any earlier fill-basis) buried
684
694
  * `>= requiredClaimDepth`, the grant REPLAYED to a live hold that is mine and routes to THIS fclaim, the
685
695
  * fill delivering `>= 1` unit, and a FILL_TIP_MARGIN deadline cushion. Fails CLOSED on any unmet condition.
686
- * Accepts every honest fill (the holder, live hold, buried, offer+fclaim proven, delivery >= 1); it only
687
- * refuses the doomed/forged cases (a denied fclaim a lying resolver calls "granted", a cancelled/lapsed or
688
- * not-mine hold, a below-depth signing, a zero-delivery fill, a stranded past-deadline broadcast).
696
+ * Over a window that holds the offer's history it refuses the doomed/forged cases (a denied fclaim a lying
697
+ * resolver calls "granted", a cancelled/lapsed or not-mine hold, a below-depth signing, a zero-delivery fill, a
698
+ * stranded past-deadline broadcast) and one honest case on purpose: the cap count. `opts.myLiveHoldsAtGrant`, as
699
+ * countOtherHoldsAtGrant computes it, counts the buyer's earlier fclaims on other offers whether or not the chain
700
+ * granted them (a denial is not visible to it), so a buyer whose three such fclaims were all denied is refused a
701
+ * later fill the chain granted. Over-counting refuses; under-counting would let a cap-denied fill burn. Over a
702
+ * window that lacks part of the history, see "Known limits" below.
689
703
  *
690
704
  * `opts.myLiveHoldsAtGrant` (REQUIRED) is the buyer's count of OTHER live fclaim/legacy holds at the moment
691
705
  * THIS fclaim was granted, asserted by the authoring client (countOtherHoldsAtGrant computes it). The lane-scoped
@@ -697,13 +711,38 @@ interface FillVerdict {
697
711
  * without it there is nothing to bind. A caller that omits it keeps the overpay exposure described next.
698
712
  * `opts.sums` (OPT-IN, B6a / REBIND W3; default OFF = byte-identical verdicts for existing callers) binds the
699
713
  * caller's PLANNED per-address CSD payment sums to the PROVEN offer state: requiredFillOutputs is re-run over
700
- * the merkle-proven, replayed offer (so `paid`/`delivered` are the chain's, not a served lie) and the caller's
701
- * map must match it EXACTLY, address for address. This closes the W3 overpay: a resolver serving `paid:"0"`
702
- * for a 90%-filled partial made callers size the FULL want while the chain credits only the remainder - the
703
- * difference was permanently overpaid. Pass the SAME per-address sums you will build (the wallet's need-map
714
+ * the merkle-proven, replayed offer and the caller's map must match it EXACTLY, address for address. The
715
+ * replayed `paid`/`delivered` are the chain's only inside the window the seam read: a fill whose fclaim lies
716
+ * below it is not replayed. Inside the window this closes the W3 overpay: a resolver serving `paid:"0"` for a
717
+ * 90%-filled partial made callers size the FULL want while the chain credits only the remainder. Pass the SAME
718
+ * per-address sums you will build (the wallet's need-map
704
719
  * shape: payto + treasury fee + maker rebate, MERGED per address - `payto === seller` merges the rebate leg).
705
720
  * DELIBERATELY NOT the scalar `dp.pay !== pay` form: that refuses honest fills on both live callers (the
706
721
  * wallet's per-address sum includes the maker rebate when payto === seller; the site passes no pay at all).
722
+ *
723
+ * Known limits: the replay sees only the window the seam read, and reading the history below it is not
724
+ * implemented. verifyFillSpv takes no served offer and decides from the proven window alone, so each limit says
725
+ * first what holds for a caller that uses only verifyFillSpv (with an honest resolver unless stated), then what
726
+ * the checks of the site and the wallet add. A third-party caller has only the first unless it adds such checks.
727
+ * - The grant replay (step 5): an fclaim the window does not decide (the GAP_NEEDED note) can replay as
728
+ * granted. A hold chain that starts below the window can make verifyFillSpv grant the caller's own fclaim
729
+ * that the chain denied, and the whole fill burns, with an honest resolver. A caller closes it by signing only
730
+ * while the served offer names its own fclaim as the current hold: the site fills only when the served claim
731
+ * state is the buyer's, so for the site it needs a resolver that serves the false hold; the wallet refuses when
732
+ * its second-source offer read reports another reservation holding the offer through the buyer's hold. A third
733
+ * party's fclaim the cap denied can also replay as granted with its fill credited, raising the replayed
734
+ * `paid`: against sums sized from an honest served offer that only refuses, and it pays wrong only when the
735
+ * served `paid` matches the raised one.
736
+ * - Delivery (step 6), aged fills: a fill whose fclaim lies below the window is not replayed, so the replayed
737
+ * `paid` is too low, with an honest resolver. A tail below the offer's `min` replays as below-min and an honest
738
+ * buy is refused. For a coarse give (a payment worth less than one unit, `give * pay < want`) the delivery
739
+ * check can disagree with the chain's in either direction: it can refuse an honest buy, or accept a payment the
740
+ * chain refuses after it moved. A caller refuses a payment its served offer computes as undeliverable
741
+ * (previewFill) instead of relying on this check for it.
742
+ * - The sums bind (step 6b): it passes a payment sized from a served offer that omits such a fill and serves the
743
+ * matching lower `paid`, and the payment overpays. That needs the resolver the caller sizes from to omit the
744
+ * fill; for the site and the wallet that is the project's own resolver (host-only), and the wallet's
745
+ * second-source offer read bounds it.
707
746
  */
708
747
  declare function verifyFillSpv(offerId: string, fclaimTxid: string, me: string, io: FillSpvIo, opts: {
709
748
  myLiveHoldsAtGrant: number;
@@ -852,7 +891,7 @@ interface ProvenOfferTx {
852
891
  seller: string;
853
892
  }
854
893
  /** 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. */
894
+ * rules; the resolver writes no note below activation), or null when it passes. */
856
895
  declare function provenOfferRefusal(rec: OfferRecord, tx: ProvenOfferTx): string | null;
857
896
 
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 };
897
+ 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_MAX_HOLD_SPAN, 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, beforeActivation, 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, offerFillTooLate, paidToFromOutputs, parseAmount, parseRecord, pickPrimaryName, previewFill, primaryRankBefore, provenOfferRefusal, provenOfferTerms, ptAmt, replayLiveHold, requiredClaimDepth, requiredFillOutputs, resolve, tokenMeta, tradeFee, transfer, unsafeMintProvenOfferTerms, verifyFillSpv };
package/dist/index.d.ts CHANGED
@@ -2,6 +2,8 @@ export { EPOCH_LEN, HALVING_INTERVAL, INITIAL_REWARD, MIN_FEE_ATTEST, MIN_FEE_PR
2
2
 
3
3
  declare const DOMAIN = "cairnx:v1";
4
4
  declare const ACTIVATION_HEIGHT = 29860;
5
+ /** True below ACTIVATION_HEIGHT, where resolve() skips every event without a note. */
6
+ declare const beforeActivation: (height: number) => boolean;
5
7
  declare const V11_HEIGHT = 29960;
6
8
  declare const V12_HEIGHT = 30300;
7
9
  declare const V13_HEIGHT = 31100;
@@ -83,6 +85,7 @@ declare const claimGraceOf: (claimUntilHeight: number, claimTxid?: string) => nu
83
85
  declare const fclaimEpochFor: (tipHeight: number, offerExpiresEpoch: number) => number;
84
86
  declare const fclaimHoldEnd: (expiresEpoch: number) => number;
85
87
  declare const offerExpiryHeightOf: (expiresEpoch: number, anchorHeight: number) => number;
88
+ declare const offerFillTooLate: (expiresAt: number, tip: number) => boolean;
86
89
  interface DeployRecord {
87
90
  v: 1;
88
91
  t: "deploy";
@@ -445,15 +448,21 @@ declare const CLAIM_MIN_DEPTH = 3;
445
448
  declare const COMMIT_REVEAL_MIN_DEPTH = 3;
446
449
  /**
447
450
  * Confirmations the CLAIM must have before a payment-bearing fill on an open V17 offer worth `valueSats`
448
- * (anchored at `height`) is reorg-safe. Returns `{ depth, reversalPct, capped }`; `capped=true` ⇒ the value
449
- * exceeds what one claim window can safely settle (the buyer should split the trade).
451
+ * (anchored at `height`), so that a minority miner undoing the claim is unlikely. Returns
452
+ * `{ depth, reversalPct, capped }`; `reversalPct` is that miner's chance of reversing `depth` blocks, positive at every depth;
453
+ * `capped=true` ⇒ the value exceeds what one claim window can settle (the buyer should split the trade).
450
454
  *
451
- * A MINORITY attacker (the dominant pool is trusted; a majority means the chain is already lost) only profits
452
- * if `P(reverse D)·V > the honest reward it forgoes`, with `P(reverse D) ≈ (q/(1−q))^D` (gambler's ruin,
455
+ * The model is a miner with `CLAIM_ATTACKER_Q` of the hashrate. It only profits if
456
+ * `P(reverse D)·V > the honest reward it forgoes`, with `P(reverse D) ≈ (q/(1−q))^D` (gambler's ruin,
453
457
  * Nakamoto §11). That is logarithmic in value → ~3 conf for nearly every trade, 4 for a whale. Everything is
454
458
  * in CSD (block reward), so no USD price is needed. The required depth is capped at `claimWindow − 5` so a
455
459
  * capped/whale value stays fillable for a usable multi-block span rather than a 1-block knife-edge (only
456
460
  * absurd > total-supply values ever reach the cap).
461
+ *
462
+ * The pool that produces most blocks is outside this model. It is an external party, not run by Cairn; no depth
463
+ * bounds a producer with more than half the hashrate (the reversal chance is 1 at q ≥ 0.5), and reordering recent
464
+ * blocks costs it almost nothing, since it re-mines them and keeps their rewards. The wait guards against smaller
465
+ * miners only.
457
466
  */
458
467
  declare function requiredClaimDepth(valueSats: number | bigint, height: number): {
459
468
  depth: number;
@@ -651,6 +660,7 @@ declare const primaryRankBefore: (a: NameState, b: NameState) => boolean;
651
660
  /** The primary .csd name for address `a`, or null. Pure; no I/O. `a` may be any case. */
652
661
  declare function pickPrimaryName(names: Iterable<NameState>, a: string): string | null;
653
662
 
663
+ declare const FCLAIM_MAX_HOLD_SPAN: number;
654
664
  declare const GAP_NEEDED: number;
655
665
  declare const SCAN_MARGIN = 30;
656
666
  declare const MAX_SCAN: number;
@@ -683,9 +693,13 @@ interface FillVerdict {
683
693
  * MERKLE-PROVEN and bound to their on-chain commitment (A1), both (and any earlier fill-basis) buried
684
694
  * `>= requiredClaimDepth`, the grant REPLAYED to a live hold that is mine and routes to THIS fclaim, the
685
695
  * fill delivering `>= 1` unit, and a FILL_TIP_MARGIN deadline cushion. Fails CLOSED on any unmet condition.
686
- * Accepts every honest fill (the holder, live hold, buried, offer+fclaim proven, delivery >= 1); it only
687
- * refuses the doomed/forged cases (a denied fclaim a lying resolver calls "granted", a cancelled/lapsed or
688
- * not-mine hold, a below-depth signing, a zero-delivery fill, a stranded past-deadline broadcast).
696
+ * Over a window that holds the offer's history it refuses the doomed/forged cases (a denied fclaim a lying
697
+ * resolver calls "granted", a cancelled/lapsed or not-mine hold, a below-depth signing, a zero-delivery fill, a
698
+ * stranded past-deadline broadcast) and one honest case on purpose: the cap count. `opts.myLiveHoldsAtGrant`, as
699
+ * countOtherHoldsAtGrant computes it, counts the buyer's earlier fclaims on other offers whether or not the chain
700
+ * granted them (a denial is not visible to it), so a buyer whose three such fclaims were all denied is refused a
701
+ * later fill the chain granted. Over-counting refuses; under-counting would let a cap-denied fill burn. Over a
702
+ * window that lacks part of the history, see "Known limits" below.
689
703
  *
690
704
  * `opts.myLiveHoldsAtGrant` (REQUIRED) is the buyer's count of OTHER live fclaim/legacy holds at the moment
691
705
  * THIS fclaim was granted, asserted by the authoring client (countOtherHoldsAtGrant computes it). The lane-scoped
@@ -697,13 +711,38 @@ interface FillVerdict {
697
711
  * without it there is nothing to bind. A caller that omits it keeps the overpay exposure described next.
698
712
  * `opts.sums` (OPT-IN, B6a / REBIND W3; default OFF = byte-identical verdicts for existing callers) binds the
699
713
  * caller's PLANNED per-address CSD payment sums to the PROVEN offer state: requiredFillOutputs is re-run over
700
- * the merkle-proven, replayed offer (so `paid`/`delivered` are the chain's, not a served lie) and the caller's
701
- * map must match it EXACTLY, address for address. This closes the W3 overpay: a resolver serving `paid:"0"`
702
- * for a 90%-filled partial made callers size the FULL want while the chain credits only the remainder - the
703
- * difference was permanently overpaid. Pass the SAME per-address sums you will build (the wallet's need-map
714
+ * the merkle-proven, replayed offer and the caller's map must match it EXACTLY, address for address. The
715
+ * replayed `paid`/`delivered` are the chain's only inside the window the seam read: a fill whose fclaim lies
716
+ * below it is not replayed. Inside the window this closes the W3 overpay: a resolver serving `paid:"0"` for a
717
+ * 90%-filled partial made callers size the FULL want while the chain credits only the remainder. Pass the SAME
718
+ * per-address sums you will build (the wallet's need-map
704
719
  * shape: payto + treasury fee + maker rebate, MERGED per address - `payto === seller` merges the rebate leg).
705
720
  * DELIBERATELY NOT the scalar `dp.pay !== pay` form: that refuses honest fills on both live callers (the
706
721
  * wallet's per-address sum includes the maker rebate when payto === seller; the site passes no pay at all).
722
+ *
723
+ * Known limits: the replay sees only the window the seam read, and reading the history below it is not
724
+ * implemented. verifyFillSpv takes no served offer and decides from the proven window alone, so each limit says
725
+ * first what holds for a caller that uses only verifyFillSpv (with an honest resolver unless stated), then what
726
+ * the checks of the site and the wallet add. A third-party caller has only the first unless it adds such checks.
727
+ * - The grant replay (step 5): an fclaim the window does not decide (the GAP_NEEDED note) can replay as
728
+ * granted. A hold chain that starts below the window can make verifyFillSpv grant the caller's own fclaim
729
+ * that the chain denied, and the whole fill burns, with an honest resolver. A caller closes it by signing only
730
+ * while the served offer names its own fclaim as the current hold: the site fills only when the served claim
731
+ * state is the buyer's, so for the site it needs a resolver that serves the false hold; the wallet refuses when
732
+ * its second-source offer read reports another reservation holding the offer through the buyer's hold. A third
733
+ * party's fclaim the cap denied can also replay as granted with its fill credited, raising the replayed
734
+ * `paid`: against sums sized from an honest served offer that only refuses, and it pays wrong only when the
735
+ * served `paid` matches the raised one.
736
+ * - Delivery (step 6), aged fills: a fill whose fclaim lies below the window is not replayed, so the replayed
737
+ * `paid` is too low, with an honest resolver. A tail below the offer's `min` replays as below-min and an honest
738
+ * buy is refused. For a coarse give (a payment worth less than one unit, `give * pay < want`) the delivery
739
+ * check can disagree with the chain's in either direction: it can refuse an honest buy, or accept a payment the
740
+ * chain refuses after it moved. A caller refuses a payment its served offer computes as undeliverable
741
+ * (previewFill) instead of relying on this check for it.
742
+ * - The sums bind (step 6b): it passes a payment sized from a served offer that omits such a fill and serves the
743
+ * matching lower `paid`, and the payment overpays. That needs the resolver the caller sizes from to omit the
744
+ * fill; for the site and the wallet that is the project's own resolver (host-only), and the wallet's
745
+ * second-source offer read bounds it.
707
746
  */
708
747
  declare function verifyFillSpv(offerId: string, fclaimTxid: string, me: string, io: FillSpvIo, opts: {
709
748
  myLiveHoldsAtGrant: number;
@@ -852,7 +891,7 @@ interface ProvenOfferTx {
852
891
  seller: string;
853
892
  }
854
893
  /** 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. */
894
+ * rules; the resolver writes no note below activation), or null when it passes. */
856
895
  declare function provenOfferRefusal(rec: OfferRecord, tx: ProvenOfferTx): string | null;
857
896
 
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 };
897
+ 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_MAX_HOLD_SPAN, 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, beforeActivation, 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, offerFillTooLate, paidToFromOutputs, parseAmount, parseRecord, pickPrimaryName, previewFill, primaryRankBefore, provenOfferRefusal, provenOfferTerms, ptAmt, replayLiveHold, requiredClaimDepth, requiredFillOutputs, resolve, tokenMeta, tradeFee, transfer, unsafeMintProvenOfferTerms, verifyFillSpv };
package/dist/index.js CHANGED
@@ -2,6 +2,7 @@
2
2
  import { EPOCH_LEN, MAX_URI_BYTES, epochOf } from "@inversealtruism/csd-codec";
3
3
  var DOMAIN = "cairnx:v1";
4
4
  var ACTIVATION_HEIGHT = 29860;
5
+ var beforeActivation = (height) => height < ACTIVATION_HEIGHT;
5
6
  var V11_HEIGHT = 29960;
6
7
  var V12_HEIGHT = 30300;
7
8
  var V13_HEIGHT = 31100;
@@ -108,6 +109,7 @@ var offerExpiryHeightOf = (expiresEpoch, anchorHeight) => {
108
109
  const capped = (epochOf(anchorHeight) + MAX_OFFER_EPOCHS + 1) * EPOCH_LEN;
109
110
  return Math.min(raw, Math.max(V21_HEIGHT, capped));
110
111
  };
112
+ var offerFillTooLate = (expiresAt, tip) => expiresAt - 1 < tip + FILL_TIP_MARGIN;
111
113
  var isNameGive = (g) => typeof g.name === "string";
112
114
  var isTokenWant = (w) => typeof w.ticker === "string";
113
115
 
@@ -1087,10 +1089,6 @@ function applyOffer(c, ev, rec, who) {
1087
1089
  const payto = (rec.want.payto ?? who).toLowerCase();
1088
1090
  const give = rec.give;
1089
1091
  if (isNameGive(give)) {
1090
- if (!v11) {
1091
- note(ev, ev.id, "offer", false, "name offers need v1.1");
1092
- return;
1093
- }
1094
1092
  const n = names.get(give.name);
1095
1093
  if (!n || n.owner !== who) {
1096
1094
  note(ev, ev.id, "offer", false, "you don't own this name");
@@ -1286,6 +1284,7 @@ function offerEnvelopeRefusal(rec, who, height, expiresEpoch) {
1286
1284
  if (!Number.isSafeInteger(expiresEpoch)) return "expiresEpoch out of safe-integer range";
1287
1285
  if (epochOf(height) > expiresEpoch) return "already expired at anchor";
1288
1286
  if (height >= V21_HEIGHT && height < V22_HEIGHT && expiresEpoch - epochOf(height) > MAX_OFFER_EPOCHS) return "v2.1: offer duration exceeds the max";
1287
+ if (isNameGive(rec.give) && height < V11_HEIGHT) return "name offers need v1.1";
1289
1288
  return null;
1290
1289
  }
1291
1290
 
@@ -1409,7 +1408,7 @@ function resolve(events, tipHeight) {
1409
1408
  c.pendingCancels = [];
1410
1409
  };
1411
1410
  for (const ev of applied) {
1412
- if (ev.height < ACTIVATION_HEIGHT) continue;
1411
+ if (beforeActivation(ev.height)) continue;
1413
1412
  if (ev.height !== pendingBlock) {
1414
1413
  applyPendingCancels();
1415
1414
  pendingBlock = ev.height;
@@ -1703,7 +1702,8 @@ function pickPrimaryName(names, a) {
1703
1702
 
1704
1703
  // src/verifyfill.ts
1705
1704
  import { payloadHash as payloadHash2 } from "@inversealtruism/csd-codec";
1706
- var GAP_NEEDED = EPOCH_LEN * (FCLAIM_MAX_EPOCH_AHEAD + 1) - 1 + CLAIM_COOLDOWN_BLOCKS;
1705
+ var FCLAIM_MAX_HOLD_SPAN = EPOCH_LEN * (FCLAIM_MAX_EPOCH_AHEAD + 1) - 1;
1706
+ var GAP_NEEDED = FCLAIM_MAX_HOLD_SPAN + CLAIM_COOLDOWN_BLOCKS;
1707
1707
  var SCAN_MARGIN = EPOCH_LEN;
1708
1708
  var MAX_SCAN = GAP_NEEDED + SCAN_MARGIN;
1709
1709
  function bindRecord(ev) {
@@ -1943,6 +1943,7 @@ function countOtherHoldsAtGrant(candidates, target, me, closed = /* @__PURE__ */
1943
1943
  // src/admission.ts
1944
1944
  function provenOfferRefusal(rec, tx) {
1945
1945
  if (tx.domain !== DOMAIN) return `not a ${DOMAIN} Propose (domain ${JSON.stringify(String(tx.domain))})`;
1946
+ if (beforeActivation(tx.height)) return `anchored before CairnX activation (block ${ACTIVATION_HEIGHT})`;
1946
1947
  const ee = typeof tx.expiresEpoch === "bigint" ? Number(tx.expiresEpoch) : tx.expiresEpoch;
1947
1948
  return offerEnvelopeRefusal(rec, String(tx.seller).toLowerCase(), tx.height, ee);
1948
1949
  }
@@ -1978,6 +1979,7 @@ export {
1978
1979
  EPOCH_LEN2 as EPOCH_LEN,
1979
1980
  FCLAIM_KEYS,
1980
1981
  FCLAIM_MAX_EPOCH_AHEAD,
1982
+ FCLAIM_MAX_HOLD_SPAN,
1981
1983
  FCLAIM_WINDOW_MIN,
1982
1984
  FEE_BPS,
1983
1985
  FEE_BPS_V16,
@@ -2050,6 +2052,7 @@ export {
2050
2052
  V28_HEIGHT,
2051
2053
  V29_HEIGHT,
2052
2054
  ZERO_ADDR,
2055
+ beforeActivation,
2053
2056
  bid,
2054
2057
  bindOfferTerms,
2055
2058
  bindProvenOffer,
@@ -2095,6 +2098,7 @@ export {
2095
2098
  offer,
2096
2099
  offerCancelAll,
2097
2100
  offerExpiryHeightOf,
2101
+ offerFillTooLate,
2098
2102
  paidToFromOutputs,
2099
2103
  parseAmount,
2100
2104
  parseRecord,
package/package.json CHANGED
@@ -1,10 +1,10 @@
1
1
  {
2
2
  "name": "@inversealtruism/cairnx-core",
3
- "version": "0.2.2",
3
+ "version": "0.2.4",
4
4
  "engines": {
5
5
  "node": ">=18"
6
6
  },
7
- "description": "CairnX: tokens, atomic DvP trades and leased .csd names on Compute Substrate, as a pure deterministic convention library (Ordinals/Runes class). Ships the normative CONVENTION.md and the conformance vectors.",
7
+ "description": "CairnX: tokens, trades and leased .csd names on Compute Substrate, as a pure deterministic convention library (Ordinals/Runes class). Ships the normative CONVENTION.md and the conformance vectors.",
8
8
  "type": "module",
9
9
  "main": "./dist/index.cjs",
10
10
  "module": "./dist/index.js",