@inversealtruism/cairnx-core 0.1.35 → 0.1.36

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/CONVENTION.md CHANGED
@@ -5,12 +5,17 @@
5
5
  **Version ladder** (each gate non-retroactive — below it, behavior + canonical hashes are byte-identical to history):
6
6
  v1.1 @ 29 960 · v1.2 @ 30 300 · v1.3 @ 31 100 · v1.4 @ 31 400 · v1.5 @ 32 000 · v1.6 @ 33 600 (§19) ·
7
7
  v1.7 @ 34 000 (§20) · v1.9 @ 36 700 (§22) · v2.0 @ 38 400 (§23) · v1.8 @ 40 000 (§21) · v2.1 @ 40 100 (§24) ·
8
- v2.2 @ 41 300 (§25) · v2.4 @ 49 200 (§27) · v2.5 @ 51 000 (§28) · v2.6 @ 51 200 (§29) · v2.3 @ 52 000 (§26) ·
9
- v2.7 @ 52 500 (§30).
8
+ v2.2 @ 41 300 (§25) · v2.4 @ 46 400 (§27) · v2.5 @ 46 440 (§28) · v2.6 @ 46 480 (§29) · v2.7 @ 46 520 (§30) ·
9
+ v2.3 @ 52 000 (§26).
10
10
  Sections §19–§30 are the normative semantics for v1.6–v2.7; §5.1 is the byte-level canonical-JSON contract that binds all of them.
11
- Activation order is by HEIGHT, not by version number (v1.8 activated after v2.0; v2.3 activates after v2.6): a
11
+ Activation order is by HEIGHT, not by version number (v1.8 activated after v2.0; v2.3 activates after v2.4–v2.7): a
12
12
  replayer gates each rule on its own height constant, never on "version X implies version Y is active".
13
13
 
14
+ > **Height re-pin history (2026-07-03).** v2.4–v2.7 originally published as 49 200 / 51 000 / 51 200 / 52 500
15
+ > and were RE-PINNED to 46 400 / 46 440 / 46 480 / 46 520 (`CONSENSUS_CHANGES.md` 0.1.33): an operator-approved,
16
+ > coordinated same-day re-pin of every verifier while the tip (~46 071) was still below every new height, so all
17
+ > recorded history replays byte-identically. Replayers built from this spec MUST use the re-pinned heights above.
18
+
14
19
  > **Canonical copy.** This spec ships in the published `@inversealtruism/cairnx-core` package; the source of
15
20
  > truth is `csd-sdk/packages/cairnx/CONVENTION.md`. Any in-repo mirror (e.g. the `cairnx` app repo) MUST be
16
21
  > kept **byte-identical** to it on every change — a third-party implementer fetches the *published* copy, so
@@ -869,14 +874,15 @@ The §24 lifetime cap proved to be an infrastructure symptom, not a market need,
869
874
 
870
875
  # CairnX Convention v2.4 (length-graded registration fee increase)
871
876
 
872
- **Activation height: 49 200** (`V24_HEIGHT`; non-retroactive; keyed on the FEE-BEARING event's height).
877
+ **Activation height: 46 400** (`V24_HEIGHT`; non-retroactive; keyed on the FEE-BEARING event's height;
878
+ re-pinned 2026-07-03 from the originally published 49 200 — see the height re-pin history note at the top).
873
879
 
874
880
  ## 27. The fee curve
875
881
 
876
882
  `nameRegFee(name, height)` selects the regime by the height of the event that carries the fee: the `name`
877
883
  reveal below v2.5, the winner's `nfinalize` at/after v2.5 (§28), and every renewal at its own event height.
878
884
 
879
- | name length | < 40 000 | ≥ 40 000 (v1.8) | ≥ 49 200 (v2.4) |
885
+ | name length | < 40 000 | ≥ 40 000 (v1.8) | ≥ 46 400 (v2.4) |
880
886
  |---|---|---|---|
881
887
  | ≤ 3 chars | 5 CSD | 6.7 CSD | 15 CSD |
882
888
  | 4 chars | 2 CSD | 6.7 CSD | 10 CSD |
@@ -886,16 +892,17 @@ reveal below v2.5, the winner's `nfinalize` at/after v2.5 (§28), and every rene
886
892
 
887
893
  - Underpayment is a **no-op** (`name registration fee unpaid`), and the §10 warning applies with force:
888
894
  the attached payment outputs still settle on-chain. An underpaid registration or renewal is a burn.
889
- - **Adoption note (BOTH directions are hard):** a stale replayer ACCEPTS an underpaid post-49 200
895
+ - **Adoption note (BOTH directions are hard):** a stale replayer ACCEPTS an underpaid post-46 400
890
896
  registration the chain rejects (it shows a phantom owner), and a stale wallet ATTACHES the old fee and
891
897
  burns it. Every replayer and every fee-quoting client must run the v2.4 core before the tip crosses
892
- 49 200.
898
+ 46 400.
893
899
 
894
900
  ---
895
901
 
896
902
  # CairnX Convention v2.5 (sealed-reservation registration)
897
903
 
898
- **Activation height: 51 000** (`V25_HEIGHT`; non-retroactive; keyed on the reveal event height).
904
+ **Activation height: 46 440** (`V25_HEIGHT`; non-retroactive; keyed on the reveal event height;
905
+ re-pinned 2026-07-03 from the originally published 51 000 — see the height re-pin history note at the top).
899
906
 
900
907
  Root fix for the reveal fee-burn: pre-v2.5, every losing racer in a §9 commit-reveal race paid the FULL
901
908
  registration fee for nothing (payment-without-delivery). At/after v2.5 the reveal is payment-free; only
@@ -910,7 +917,7 @@ the settled winner ever pays.
910
917
  freeze, so no back-dated challenger can appear after the freeze has passed. Direct no-salt registration
911
918
  is rejected at/after v2.5 (`v2.5: registration requires a commit-reveal (salt)`): an unsealed
912
919
  registration could not be finalized.
913
- - **Reveal (`name` record, height ≥ 51 000):** carries NO registration fee. Creates a PENDING reservation,
920
+ - **Reveal (`name` record, height ≥ 46 440):** carries NO registration fee. Creates a PENDING reservation,
914
921
  materialized in canonical state as the name with `pending: true` and
915
922
  `finalizeBy = effHeight + 8 + 20` (`REG_COMMIT_MAX_BLOCKS + REG_FINALIZE_GRACE_BLOCKS`).
916
923
  - **Contest while pending:** a rival reveal with a strictly earlier `(effHeight, pos, id)` (numeric on
@@ -934,22 +941,23 @@ the settled winner ever pays.
934
941
  - **Client timing rule** (`FINALIZE_TIP_MARGIN = 2`, client-side only): sign the finalize at
935
942
  `effHeight + 8 + 2` or later so one reorg cannot un-freeze the contest under a fee-bearing tx. The
936
943
  20-block grace exists so a slow inclusion still lands before `finalizeBy`.
937
- - **Adoption note (hard gate):** a stale (pre-v2.5) wallet crossing 51 000 attaches the registration fee
944
+ - **Adoption note (hard gate):** a stale (pre-v2.5) wallet crossing 46 440 attaches the registration fee
938
945
  to what is now a payment-free reveal; the resolver ignores the fee and the payment burns. Every
939
- replayer AND every fee-attaching client must run the v2.5 core before the tip crosses 51 000.
946
+ replayer AND every fee-attaching client must run the v2.5 core before the tip crosses 46 440.
940
947
 
941
948
  ---
942
949
 
943
950
  # CairnX Convention v2.6 (sealed-reservation recapture)
944
951
 
945
- **Activation height: 51 200** (`V26_HEIGHT`; non-retroactive; keyed on the reveal event height).
952
+ **Activation height: 46 480** (`V26_HEIGHT`; non-retroactive; keyed on the reveal event height;
953
+ re-pinned 2026-07-03 from the originally published 51 200 — see the height re-pin history note at the top).
946
954
 
947
955
  The §28 cure applied to LAPSED-name recapture (§17), whose losing racer previously forfeited the full
948
956
  decaying premium (up to hundreds of CSD).
949
957
 
950
958
  ## 29. Recapture through the same sealed machinery
951
959
 
952
- - **Reveal on a lapsed name (height ≥ 51 200):** payment-free. Creates a recapture reservation in an
960
+ - **Reveal on a lapsed name (height ≥ 46 480):** payment-free. Creates a recapture reservation in an
953
961
  INTERNAL `recaptures` map. The reservation is NOT materialized in canonical state, and the lapsed
954
962
  record in `names` is left untouched (it is the premium basis; an abandoned reservation can never
955
963
  bypass the premium). Below v2.6, recapture stays pay-now at reveal (§17, byte-identical).
@@ -965,13 +973,14 @@ decaying premium (up to hundreds of CSD).
965
973
  which later `nfinalize` succeeds. The map is defined by this section plus the reference resolver and
966
974
  its Python mirror; the v2.6 conformance vectors pin it.
967
975
  - **Adoption note (hard gate):** same shape as §28. A stale wallet attaches the premium to a
968
- payment-free recapture reveal and burns it. All replayers and clients on the v2.6 core before 51 200.
976
+ payment-free recapture reveal and burns it. All replayers and clients on the v2.6 core before 46 480.
969
977
 
970
978
  ---
971
979
 
972
980
  # CairnX Convention v2.7 (young-name sale embargo shrinks)
973
981
 
974
- **Activation height: 52 500** (`V27_HEIGHT`; non-retroactive; keyed on the OFFER event height).
982
+ **Activation height: 46 520** (`V27_HEIGHT`; non-retroactive; keyed on the OFFER event height;
983
+ re-pinned 2026-07-03 from the originally published 52 500 — see the height re-pin history note at the top).
975
984
 
976
985
  ## 30. Sale embargo: 240 blocks becomes 8
977
986
 
@@ -979,12 +988,12 @@ A name `offer` (§17 sale path) whose event height `H` satisfies `H − effHeigh
979
988
  (`name too young to sell (must out-age the reveal window)`), where `effHeight` is the name's effective
980
989
  anchor. `viaFill` names were never embargoed.
981
990
 
982
- - **`H` < 52 500:** `embargo = COMMIT_MAX_BLOCKS` (240 blocks, ≈ 8 h). The pre-sealed rule: a fresh name
991
+ - **`H` < 46 520:** `embargo = COMMIT_MAX_BLOCKS` (240 blocks, ≈ 8 h). The pre-sealed rule: a fresh name
983
992
  had to out-age every lurking back-dated reveal before it could be sold.
984
- - **`H` ≥ 52 500:** `embargo = REG_COMMIT_MAX_BLOCKS` (8 blocks, ≈ 16 min). Under §28/§29 a finalized
993
+ - **`H` ≥ 46 520:** `embargo = REG_COMMIT_MAX_BLOCKS` (8 blocks, ≈ 16 min). Under §28/§29 a finalized
985
994
  name is displacement-immune the moment its freeze passes, so out-aging the old 240-block window is
986
995
  redundant; 8 matches the freeze itself.
987
- - The gate keys on the OFFER's height, so the same young name can be unsellable at 52 499 and sellable
988
- at 52 501. Deterministic for every replayer; no name-age era bookkeeping is needed.
996
+ - The gate keys on the OFFER's height, so the same young name can be unsellable at 46 519 and sellable
997
+ at 46 521. Deterministic for every replayer; no name-age era bookkeeping is needed.
989
998
  - **Adoption note:** a relaxation (fresh cores accept a sale a stale core no-ops), so every replayer must
990
- run the v2.7 core before the tip crosses 52 500.
999
+ run the v2.7 core before the tip crosses 46 520.
package/MAKERS.md CHANGED
@@ -1,10 +1,14 @@
1
1
  # Run a CairnX market maker
2
2
 
3
- CairnX has **no AMM and no escrow** — native CSD can't be pooled (CONVENTION §6). Liquidity is whoever
3
+ CairnX has **no AMM and no escrow**; native CSD can't be pooled (CONVENTION §6). Liquidity is whoever
4
4
  runs a *maker loop*. This guide is everything you need to join as a market maker, end to end. Anyone
5
5
  may run one, against any token, with their own key. It builds only on the public package
6
6
  [`@inversealtruism/cairnx-core`](https://www.npmjs.com/package/@inversealtruism/cairnx-core).
7
7
 
8
+ > Sibling doc: the `cairnx` app repo ships a repo-centric **Maker Kit** (`cairnx/MAKERS.md`) covering
9
+ > the reference `mm-bot` implementation, its config, and ops runbook. The two are different documents
10
+ > for different audiences by design, not drifted copies of one file.
11
+
8
12
  ## How the market works (RFQ)
9
13
 
10
14
  Post-v1.3 the CSD-priced market **is** an RFQ loop (CONVENTION §13/§15):
package/README.md CHANGED
@@ -131,8 +131,8 @@ stateDiagram-v2
131
131
  | Lease term | ~1 year (`NAME_TERM_EPOCHS = 8760`) | 1 epoch ≈ 1 h (30 blocks) |
132
132
  | Grace window | ~30 days (`NAME_GRACE_EPOCHS = 720`) | owner-only renewal |
133
133
  | Recapture premium | **20× → 1×** over ~30 days | decaying Dutch auction on lapsed names |
134
- | Reveal window | ~8 h (`COMMIT_MAX_BLOCKS = 240`) | commit-reveal deadline |
135
- | Registration fee | **6.7 CSD** (≤4 chars) · **3 CSD** (≥5 chars) | flat 2-tier (v1.8); paid to the treasury |
134
+ | Reveal window | ~16 min (`REG_COMMIT_MAX_BLOCKS = 8`, v2.5+; was 240 blocks below v2.5) | commit-reveal deadline; doubles as the displacement freeze |
135
+ | Registration fee | **15 / 10 / 5 / 3 CSD** by length (≤3 / 4 / 5-9 / ≥10 chars, v2.4) | length-graded (was flat 6.7 / 3 CSD under v1.8); paid to the treasury at finalize (v2.5+) |
136
136
 
137
137
  ### 2.4 · How a name resolves, and what's actually *verified*
138
138
 
@@ -249,12 +249,23 @@ is bounded in the light client, not the chain.
249
249
  | v1.8 | 40 000 | flat two-tier name fee (6.7 / 3 CSD) |
250
250
  | v2.1 | 40 100 | offer/bid duration cap (`MAX_OFFER_EPOCHS = 168`), *superseded by v2.2* |
251
251
  | v2.2 | 41 300 | duration cap **removed from consensus** → UI policy; bound moves to the light client |
252
+ | v2.4 | 46 400 | length-graded registration fee (15 / 10 / 5 / 3 CSD by name length) |
253
+ | v2.5 | 46 440 | sealed-reservation registration: payment-free reveal, winner-only fee at `nfinalize` |
254
+ | v2.6 | 46 480 | sealed-reservation recapture (lapsed-name premium paid by the settled winner only) |
255
+ | v2.7 | 46 520 | young-name sale embargo shrinks 240 → 8 blocks |
256
+ | v2.3 | 52 000 | `nset` to the zero address CLEARS the pointer (*still pending as of 2026-07-06, tip ~48 300*) |
257
+
258
+ v2.4–v2.7 were re-pinned 2026-07-03 from their originally published heights (49 200 / 51 000 / 51 200 /
259
+ 52 500) — see the re-pin history note in `CONVENTION.md` and `CONSENSUS_CHANGES.md` 0.1.33.
252
260
 
253
261
  ### Package layout
254
262
 
255
263
  `src/resolve.ts` (the ledger) · `src/records.ts` (the parse/validate gate) · `src/types.ts` (constants +
256
- height-gated client selectors) · `src/client.ts` (reorg-safety helpers a payer applies) · `CONVENTION.md`
257
- (normative spec, §1–§24) · `test/vectors/` (portable conformance corpus).
264
+ height-gated client selectors) · `src/client.ts` (reorg-safety helpers a payer applies) · `src/preflight.ts`
265
+ (build-side helpers every host must compute identically: `requiredFillOutputs`, `previewFill`/`fillIsSafe`,
266
+ `buildFeeHeight` + `NAME_FEE_GATES`, `finalizeWinnerCheck`) · `src/primary.ts` (`pickPrimaryName` /
267
+ `primaryRankBefore`, the one primary-name selection every host must agree on) · `CONVENTION.md`
268
+ (normative spec, §1–§30) · `test/vectors/` (portable conformance corpus).
258
269
 
259
270
  ### Use it
260
271
 
@@ -277,8 +288,8 @@ console.log(state.names, state.tokens.CAIRN, state.balances.CAIRN);
277
288
 
278
289
  ### Write a conformant resolver in another language
279
290
 
280
- 1. Implement `CONVENTION.md` §1–§24 (apply order, every record type, the `V*_HEIGHT` activations, the
281
- canonical-state format, ordinal key ordering, data surface only).
291
+ 1. Implement `CONVENTION.md` §1–§30 (apply order, every record type, the `V*_HEIGHT` activations — using
292
+ the re-pinned v2.4–v2.7 heights — the canonical-state format, ordinal key ordering, data surface only).
282
293
  2. Replay `test/vectors/cases.json`: your canonical state must equal `expectedState` **byte-for-byte**.
283
294
  3. Replay the live chain and compare `sha256(canonicalState)` against `test/vectors/replay-hashes.json`.
284
295
 
package/dist/index.cjs CHANGED
@@ -1490,13 +1490,23 @@ function fillIsSafe(offer2, me, pay, tip) {
1490
1490
  }
1491
1491
  return { safe: true, reason: "ok", preview };
1492
1492
  }
1493
- function finalizeWinnerCheck(nameState, me, commitHeight) {
1493
+ function finalizeWinnerCheck(nameState, me, commitHeight, tip) {
1494
1494
  const m = me.toLowerCase();
1495
1495
  if (!nameState) return { safe: false, reason: "no reservation on-chain (displaced, swept, or never accepted) \u2014 a finalize now would burn the fee" };
1496
1496
  if (nameState.owner?.toLowerCase() !== m) return { safe: false, reason: "an earlier committer won this name \u2014 you were outbid" };
1497
1497
  if (nameState.pending !== true) return { safe: false, reason: "already registered to you \u2014 no second finalize fee is needed" };
1498
1498
  if (Number(nameState.effectiveHeight) !== Number(commitHeight))
1499
1499
  return { safe: false, reason: "your reservation was displaced (effective height changed) \u2014 a finalize now would burn the fee" };
1500
+ if (tip !== void 0 && tip !== null && Number.isFinite(Number(tip))) {
1501
+ const t = Number(tip);
1502
+ const eff = Number(nameState.effectiveHeight);
1503
+ const freezeEnd = eff + REG_COMMIT_MAX_BLOCKS;
1504
+ const closeAt = eff + REG_COMMIT_MAX_BLOCKS + REG_FINALIZE_GRACE_BLOCKS - FINALIZE_TIP_MARGIN;
1505
+ if (t <= freezeEnd + FINALIZE_TIP_MARGIN)
1506
+ return { safe: false, reason: `too early \u2014 the displacement contest is not frozen yet (finalizable after block ${freezeEnd + FINALIZE_TIP_MARGIN}, chain tip ${t}); the resolver would reject the finalize after the fee moved, burning it` };
1507
+ if (t > closeAt)
1508
+ return { safe: false, reason: `this reservation's finalize window has closed (safe until block ${closeAt}, chain tip ${t}); a finalize now would mine past the deadline and burn the fee` };
1509
+ }
1500
1510
  return { safe: true, reason: "ok" };
1501
1511
  }
1502
1512
 
package/dist/index.d.cts CHANGED
@@ -492,13 +492,21 @@ interface FillSafety {
492
492
  }
493
493
  declare function fillIsSafe(offer: OfferState, me: string, pay: bigint | string | number, tip: number): FillSafety;
494
494
  /** C1: may `me` safely sign the fee-bearing registration `nfinalize` for `nameState` committed at
495
- * `commitHeight`? The reg fee rides nfinalize; a finalize on a reservation that was displaced or has
496
- * expired is REJECTED after the fee moved (a burn). Sound by the freeze arithmetic: once a client waits
497
- * for `tip > effectiveHeight + REG_COMMIT_MAX_BLOCKS` (which the UI's finalizeReady already enforces) no
498
- * new displacer can appear, so a re-fetch showing "still my live pending reservation at my commit height"
499
- * guarantees the finalize lands. Pass the AUTHORITATIVE (freshly re-fetched) name record — never a cached
500
- * one — as `nameState` (undefined = the resolver returns 404 / unregistered, which is a definitive loss). */
501
- declare function finalizeWinnerCheck(nameState: NameState | null | undefined, me: string, commitHeight: number): {
495
+ * `commitHeight`? The reg fee rides nfinalize; a finalize on a reservation that was displaced, has
496
+ * 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
+ *
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. */
509
+ declare function finalizeWinnerCheck(nameState: NameState | null | undefined, me: string, commitHeight: number, tip?: number | null): {
502
510
  safe: boolean;
503
511
  reason: string;
504
512
  };
package/dist/index.d.ts CHANGED
@@ -492,13 +492,21 @@ interface FillSafety {
492
492
  }
493
493
  declare function fillIsSafe(offer: OfferState, me: string, pay: bigint | string | number, tip: number): FillSafety;
494
494
  /** C1: may `me` safely sign the fee-bearing registration `nfinalize` for `nameState` committed at
495
- * `commitHeight`? The reg fee rides nfinalize; a finalize on a reservation that was displaced or has
496
- * expired is REJECTED after the fee moved (a burn). Sound by the freeze arithmetic: once a client waits
497
- * for `tip > effectiveHeight + REG_COMMIT_MAX_BLOCKS` (which the UI's finalizeReady already enforces) no
498
- * new displacer can appear, so a re-fetch showing "still my live pending reservation at my commit height"
499
- * guarantees the finalize lands. Pass the AUTHORITATIVE (freshly re-fetched) name record — never a cached
500
- * one — as `nameState` (undefined = the resolver returns 404 / unregistered, which is a definitive loss). */
501
- declare function finalizeWinnerCheck(nameState: NameState | null | undefined, me: string, commitHeight: number): {
495
+ * `commitHeight`? The reg fee rides nfinalize; a finalize on a reservation that was displaced, has
496
+ * 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
+ *
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. */
509
+ declare function finalizeWinnerCheck(nameState: NameState | null | undefined, me: string, commitHeight: number, tip?: number | null): {
502
510
  safe: boolean;
503
511
  reason: string;
504
512
  };
package/dist/index.js CHANGED
@@ -1339,13 +1339,23 @@ function fillIsSafe(offer2, me, pay, tip) {
1339
1339
  }
1340
1340
  return { safe: true, reason: "ok", preview };
1341
1341
  }
1342
- function finalizeWinnerCheck(nameState, me, commitHeight) {
1342
+ function finalizeWinnerCheck(nameState, me, commitHeight, tip) {
1343
1343
  const m = me.toLowerCase();
1344
1344
  if (!nameState) return { safe: false, reason: "no reservation on-chain (displaced, swept, or never accepted) \u2014 a finalize now would burn the fee" };
1345
1345
  if (nameState.owner?.toLowerCase() !== m) return { safe: false, reason: "an earlier committer won this name \u2014 you were outbid" };
1346
1346
  if (nameState.pending !== true) return { safe: false, reason: "already registered to you \u2014 no second finalize fee is needed" };
1347
1347
  if (Number(nameState.effectiveHeight) !== Number(commitHeight))
1348
1348
  return { safe: false, reason: "your reservation was displaced (effective height changed) \u2014 a finalize now would burn the fee" };
1349
+ if (tip !== void 0 && tip !== null && Number.isFinite(Number(tip))) {
1350
+ const t = Number(tip);
1351
+ const eff = Number(nameState.effectiveHeight);
1352
+ const freezeEnd = eff + REG_COMMIT_MAX_BLOCKS;
1353
+ const closeAt = eff + REG_COMMIT_MAX_BLOCKS + REG_FINALIZE_GRACE_BLOCKS - FINALIZE_TIP_MARGIN;
1354
+ if (t <= freezeEnd + FINALIZE_TIP_MARGIN)
1355
+ return { safe: false, reason: `too early \u2014 the displacement contest is not frozen yet (finalizable after block ${freezeEnd + FINALIZE_TIP_MARGIN}, chain tip ${t}); the resolver would reject the finalize after the fee moved, burning it` };
1356
+ if (t > closeAt)
1357
+ return { safe: false, reason: `this reservation's finalize window has closed (safe until block ${closeAt}, chain tip ${t}); a finalize now would mine past the deadline and burn the fee` };
1358
+ }
1349
1359
  return { safe: true, reason: "ok" };
1350
1360
  }
1351
1361
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@inversealtruism/cairnx-core",
3
- "version": "0.1.35",
3
+ "version": "0.1.36",
4
4
  "engines": {
5
5
  "node": ">=18"
6
6
  },