@inversealtruism/cairnx-core 0.2.3 → 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/CHANGELOG.md +62 -0
- package/CONVENTION.md +15 -10
- package/MAKERS.md +8 -4
- package/README.md +73 -56
- package/dist/index.cjs +7 -1
- package/dist/index.d.cts +49 -12
- package/dist/index.d.ts +49 -12
- package/dist/index.js +5 -1
- package/package.json +2 -2
- package/test/vectors/cases-rules.json +446 -0
package/dist/index.d.cts
CHANGED
|
@@ -85,6 +85,7 @@ declare const claimGraceOf: (claimUntilHeight: number, claimTxid?: string) => nu
|
|
|
85
85
|
declare const fclaimEpochFor: (tipHeight: number, offerExpiresEpoch: number) => number;
|
|
86
86
|
declare const fclaimHoldEnd: (expiresEpoch: number) => number;
|
|
87
87
|
declare const offerExpiryHeightOf: (expiresEpoch: number, anchorHeight: number) => number;
|
|
88
|
+
declare const offerFillTooLate: (expiresAt: number, tip: number) => boolean;
|
|
88
89
|
interface DeployRecord {
|
|
89
90
|
v: 1;
|
|
90
91
|
t: "deploy";
|
|
@@ -447,15 +448,21 @@ declare const CLAIM_MIN_DEPTH = 3;
|
|
|
447
448
|
declare const COMMIT_REVEAL_MIN_DEPTH = 3;
|
|
448
449
|
/**
|
|
449
450
|
* Confirmations the CLAIM must have before a payment-bearing fill on an open V17 offer worth `valueSats`
|
|
450
|
-
* (anchored at `height`)
|
|
451
|
-
*
|
|
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).
|
|
452
454
|
*
|
|
453
|
-
*
|
|
454
|
-
*
|
|
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,
|
|
455
457
|
* Nakamoto §11). That is logarithmic in value → ~3 conf for nearly every trade, 4 for a whale. Everything is
|
|
456
458
|
* in CSD (block reward), so no USD price is needed. The required depth is capped at `claimWindow − 5` so a
|
|
457
459
|
* capped/whale value stays fillable for a usable multi-block span rather than a 1-block knife-edge (only
|
|
458
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.
|
|
459
466
|
*/
|
|
460
467
|
declare function requiredClaimDepth(valueSats: number | bigint, height: number): {
|
|
461
468
|
depth: number;
|
|
@@ -653,6 +660,7 @@ declare const primaryRankBefore: (a: NameState, b: NameState) => boolean;
|
|
|
653
660
|
/** The primary .csd name for address `a`, or null. Pure; no I/O. `a` may be any case. */
|
|
654
661
|
declare function pickPrimaryName(names: Iterable<NameState>, a: string): string | null;
|
|
655
662
|
|
|
663
|
+
declare const FCLAIM_MAX_HOLD_SPAN: number;
|
|
656
664
|
declare const GAP_NEEDED: number;
|
|
657
665
|
declare const SCAN_MARGIN = 30;
|
|
658
666
|
declare const MAX_SCAN: number;
|
|
@@ -685,9 +693,13 @@ interface FillVerdict {
|
|
|
685
693
|
* MERKLE-PROVEN and bound to their on-chain commitment (A1), both (and any earlier fill-basis) buried
|
|
686
694
|
* `>= requiredClaimDepth`, the grant REPLAYED to a live hold that is mine and routes to THIS fclaim, the
|
|
687
695
|
* fill delivering `>= 1` unit, and a FILL_TIP_MARGIN deadline cushion. Fails CLOSED on any unmet condition.
|
|
688
|
-
*
|
|
689
|
-
*
|
|
690
|
-
*
|
|
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.
|
|
691
703
|
*
|
|
692
704
|
* `opts.myLiveHoldsAtGrant` (REQUIRED) is the buyer's count of OTHER live fclaim/legacy holds at the moment
|
|
693
705
|
* THIS fclaim was granted, asserted by the authoring client (countOtherHoldsAtGrant computes it). The lane-scoped
|
|
@@ -699,13 +711,38 @@ interface FillVerdict {
|
|
|
699
711
|
* without it there is nothing to bind. A caller that omits it keeps the overpay exposure described next.
|
|
700
712
|
* `opts.sums` (OPT-IN, B6a / REBIND W3; default OFF = byte-identical verdicts for existing callers) binds the
|
|
701
713
|
* caller's PLANNED per-address CSD payment sums to the PROVEN offer state: requiredFillOutputs is re-run over
|
|
702
|
-
* the merkle-proven, replayed offer
|
|
703
|
-
*
|
|
704
|
-
*
|
|
705
|
-
*
|
|
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
|
|
706
719
|
* shape: payto + treasury fee + maker rebate, MERGED per address - `payto === seller` merges the rebate leg).
|
|
707
720
|
* DELIBERATELY NOT the scalar `dp.pay !== pay` form: that refuses honest fills on both live callers (the
|
|
708
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.
|
|
709
746
|
*/
|
|
710
747
|
declare function verifyFillSpv(offerId: string, fclaimTxid: string, me: string, io: FillSpvIo, opts: {
|
|
711
748
|
myLiveHoldsAtGrant: number;
|
|
@@ -857,4 +894,4 @@ interface ProvenOfferTx {
|
|
|
857
894
|
* rules; the resolver writes no note below activation), or null when it passes. */
|
|
858
895
|
declare function provenOfferRefusal(rec: OfferRecord, tx: ProvenOfferTx): string | null;
|
|
859
896
|
|
|
860
|
-
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, 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, 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
|
@@ -85,6 +85,7 @@ declare const claimGraceOf: (claimUntilHeight: number, claimTxid?: string) => nu
|
|
|
85
85
|
declare const fclaimEpochFor: (tipHeight: number, offerExpiresEpoch: number) => number;
|
|
86
86
|
declare const fclaimHoldEnd: (expiresEpoch: number) => number;
|
|
87
87
|
declare const offerExpiryHeightOf: (expiresEpoch: number, anchorHeight: number) => number;
|
|
88
|
+
declare const offerFillTooLate: (expiresAt: number, tip: number) => boolean;
|
|
88
89
|
interface DeployRecord {
|
|
89
90
|
v: 1;
|
|
90
91
|
t: "deploy";
|
|
@@ -447,15 +448,21 @@ declare const CLAIM_MIN_DEPTH = 3;
|
|
|
447
448
|
declare const COMMIT_REVEAL_MIN_DEPTH = 3;
|
|
448
449
|
/**
|
|
449
450
|
* Confirmations the CLAIM must have before a payment-bearing fill on an open V17 offer worth `valueSats`
|
|
450
|
-
* (anchored at `height`)
|
|
451
|
-
*
|
|
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).
|
|
452
454
|
*
|
|
453
|
-
*
|
|
454
|
-
*
|
|
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,
|
|
455
457
|
* Nakamoto §11). That is logarithmic in value → ~3 conf for nearly every trade, 4 for a whale. Everything is
|
|
456
458
|
* in CSD (block reward), so no USD price is needed. The required depth is capped at `claimWindow − 5` so a
|
|
457
459
|
* capped/whale value stays fillable for a usable multi-block span rather than a 1-block knife-edge (only
|
|
458
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.
|
|
459
466
|
*/
|
|
460
467
|
declare function requiredClaimDepth(valueSats: number | bigint, height: number): {
|
|
461
468
|
depth: number;
|
|
@@ -653,6 +660,7 @@ declare const primaryRankBefore: (a: NameState, b: NameState) => boolean;
|
|
|
653
660
|
/** The primary .csd name for address `a`, or null. Pure; no I/O. `a` may be any case. */
|
|
654
661
|
declare function pickPrimaryName(names: Iterable<NameState>, a: string): string | null;
|
|
655
662
|
|
|
663
|
+
declare const FCLAIM_MAX_HOLD_SPAN: number;
|
|
656
664
|
declare const GAP_NEEDED: number;
|
|
657
665
|
declare const SCAN_MARGIN = 30;
|
|
658
666
|
declare const MAX_SCAN: number;
|
|
@@ -685,9 +693,13 @@ interface FillVerdict {
|
|
|
685
693
|
* MERKLE-PROVEN and bound to their on-chain commitment (A1), both (and any earlier fill-basis) buried
|
|
686
694
|
* `>= requiredClaimDepth`, the grant REPLAYED to a live hold that is mine and routes to THIS fclaim, the
|
|
687
695
|
* fill delivering `>= 1` unit, and a FILL_TIP_MARGIN deadline cushion. Fails CLOSED on any unmet condition.
|
|
688
|
-
*
|
|
689
|
-
*
|
|
690
|
-
*
|
|
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.
|
|
691
703
|
*
|
|
692
704
|
* `opts.myLiveHoldsAtGrant` (REQUIRED) is the buyer's count of OTHER live fclaim/legacy holds at the moment
|
|
693
705
|
* THIS fclaim was granted, asserted by the authoring client (countOtherHoldsAtGrant computes it). The lane-scoped
|
|
@@ -699,13 +711,38 @@ interface FillVerdict {
|
|
|
699
711
|
* without it there is nothing to bind. A caller that omits it keeps the overpay exposure described next.
|
|
700
712
|
* `opts.sums` (OPT-IN, B6a / REBIND W3; default OFF = byte-identical verdicts for existing callers) binds the
|
|
701
713
|
* caller's PLANNED per-address CSD payment sums to the PROVEN offer state: requiredFillOutputs is re-run over
|
|
702
|
-
* the merkle-proven, replayed offer
|
|
703
|
-
*
|
|
704
|
-
*
|
|
705
|
-
*
|
|
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
|
|
706
719
|
* shape: payto + treasury fee + maker rebate, MERGED per address - `payto === seller` merges the rebate leg).
|
|
707
720
|
* DELIBERATELY NOT the scalar `dp.pay !== pay` form: that refuses honest fills on both live callers (the
|
|
708
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.
|
|
709
746
|
*/
|
|
710
747
|
declare function verifyFillSpv(offerId: string, fclaimTxid: string, me: string, io: FillSpvIo, opts: {
|
|
711
748
|
myLiveHoldsAtGrant: number;
|
|
@@ -857,4 +894,4 @@ interface ProvenOfferTx {
|
|
|
857
894
|
* rules; the resolver writes no note below activation), or null when it passes. */
|
|
858
895
|
declare function provenOfferRefusal(rec: OfferRecord, tx: ProvenOfferTx): string | null;
|
|
859
896
|
|
|
860
|
-
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, 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, 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
|
@@ -109,6 +109,7 @@ var offerExpiryHeightOf = (expiresEpoch, anchorHeight) => {
|
|
|
109
109
|
const capped = (epochOf(anchorHeight) + MAX_OFFER_EPOCHS + 1) * EPOCH_LEN;
|
|
110
110
|
return Math.min(raw, Math.max(V21_HEIGHT, capped));
|
|
111
111
|
};
|
|
112
|
+
var offerFillTooLate = (expiresAt, tip) => expiresAt - 1 < tip + FILL_TIP_MARGIN;
|
|
112
113
|
var isNameGive = (g) => typeof g.name === "string";
|
|
113
114
|
var isTokenWant = (w) => typeof w.ticker === "string";
|
|
114
115
|
|
|
@@ -1701,7 +1702,8 @@ function pickPrimaryName(names, a) {
|
|
|
1701
1702
|
|
|
1702
1703
|
// src/verifyfill.ts
|
|
1703
1704
|
import { payloadHash as payloadHash2 } from "@inversealtruism/csd-codec";
|
|
1704
|
-
var
|
|
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;
|
|
1705
1707
|
var SCAN_MARGIN = EPOCH_LEN;
|
|
1706
1708
|
var MAX_SCAN = GAP_NEEDED + SCAN_MARGIN;
|
|
1707
1709
|
function bindRecord(ev) {
|
|
@@ -1977,6 +1979,7 @@ export {
|
|
|
1977
1979
|
EPOCH_LEN2 as EPOCH_LEN,
|
|
1978
1980
|
FCLAIM_KEYS,
|
|
1979
1981
|
FCLAIM_MAX_EPOCH_AHEAD,
|
|
1982
|
+
FCLAIM_MAX_HOLD_SPAN,
|
|
1980
1983
|
FCLAIM_WINDOW_MIN,
|
|
1981
1984
|
FEE_BPS,
|
|
1982
1985
|
FEE_BPS_V16,
|
|
@@ -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.
|
|
3
|
+
"version": "0.2.4",
|
|
4
4
|
"engines": {
|
|
5
5
|
"node": ">=18"
|
|
6
6
|
},
|
|
7
|
-
"description": "CairnX: tokens,
|
|
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",
|