@inversealtruism/cairnx-core 0.1.26 → 0.1.28

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.cjs CHANGED
@@ -96,6 +96,7 @@ __export(index_exports, {
96
96
  V23_HEIGHT: () => V23_HEIGHT,
97
97
  V24_HEIGHT: () => V24_HEIGHT,
98
98
  V25_HEIGHT: () => V25_HEIGHT,
99
+ V26_HEIGHT: () => V26_HEIGHT,
99
100
  ZERO_ADDR: () => ZERO_ADDR,
100
101
  bid: () => bid,
101
102
  blockReward: () => import_csd_codec4.blockReward,
@@ -224,6 +225,7 @@ var REG_COMMIT_MAX_BLOCKS = 8;
224
225
  var REG_FINALIZE_GRACE_BLOCKS = 20;
225
226
  var MAX_PENDING_REG = 3;
226
227
  var FINALIZE_TIP_MARGIN = 2;
228
+ var V26_HEIGHT = 1e7;
227
229
  var epochOf = (height) => Math.floor(height / import_csd_codec.EPOCH_LEN);
228
230
  var claimWindowAt = (height) => height >= V20_HEIGHT ? CLAIM_WINDOW_BLOCKS_V20 : CLAIM_WINDOW_BLOCKS;
229
231
  var claimWindowOf = (claimUntilHeight) => claimUntilHeight - CLAIM_WINDOW_BLOCKS_V20 >= V20_HEIGHT ? CLAIM_WINDOW_BLOCKS_V20 : CLAIM_WINDOW_BLOCKS;
@@ -483,6 +485,7 @@ function resolve(events, tipHeight) {
483
485
  const balances = /* @__PURE__ */ new Map();
484
486
  const names = /* @__PURE__ */ new Map();
485
487
  const commits = /* @__PURE__ */ new Map();
488
+ const recaptures = /* @__PURE__ */ new Map();
486
489
  const offers = /* @__PURE__ */ new Map();
487
490
  const offerLock = /* @__PURE__ */ new Map();
488
491
  const bids = /* @__PURE__ */ new Map();
@@ -535,6 +538,10 @@ function resolve(events, tipHeight) {
535
538
  const n = names.get(nm);
536
539
  if (n.pending && n.finalizeBy !== void 0 && height > n.finalizeBy) names.delete(nm);
537
540
  }
541
+ for (const nm of [...recaptures.keys()]) {
542
+ const r = recaptures.get(nm);
543
+ if (height > r.finalizeBy) recaptures.delete(nm);
544
+ }
538
545
  };
539
546
  const V15_EPOCH = epochOf(V15_HEIGHT);
540
547
  const paidThrough = (n) => n.paidThroughEpoch ?? V15_EPOCH + NAME_TERM_EPOCHS;
@@ -586,6 +593,7 @@ function resolve(events, tipHeight) {
586
593
  const v19 = ev.height >= V19_HEIGHT;
587
594
  const v23 = ev.height >= V23_HEIGHT;
588
595
  const v25 = ev.height >= V25_HEIGHT;
596
+ const v26 = ev.height >= V26_HEIGHT;
589
597
  const feeToTreasury = ev.kind === "propose" ? ptAmt((ev.paidTo ?? {})[TREASURY_ADDR]) : 0n;
590
598
  if (ev.kind === "propose") {
591
599
  const rec = parseRecord(ev.uri, ev.payloadHash);
@@ -671,7 +679,7 @@ function resolve(events, tipHeight) {
671
679
  note(ev, ev.id, "name", false, "before v1.1 activation");
672
680
  continue;
673
681
  }
674
- const regWindow = v25 ? REG_COMMIT_MAX_BLOCKS : COMMIT_MAX_BLOCKS;
682
+ const regWindow = v25 || v26 ? REG_COMMIT_MAX_BLOCKS : COMMIT_MAX_BLOCKS;
675
683
  let effHeight = ev.height;
676
684
  if (rec.salt !== void 0) {
677
685
  const ch = nameCommit(rec.name, rec.salt, who);
@@ -686,6 +694,28 @@ function resolve(events, tipHeight) {
686
694
  const epClaim = epochOf(ev.height);
687
695
  const curActive = cur && cur.pending && cur.finalizeBy !== void 0 && ev.height > cur.finalizeBy ? void 0 : cur;
688
696
  if (curActive && !curActive.pending && v15 && lapsed(curActive, epClaim)) {
697
+ if (v26) {
698
+ if (rec.salt === void 0) {
699
+ note(ev, ev.id, "name", false, "v2.6: recapture requires a commit-reveal (salt)");
700
+ continue;
701
+ }
702
+ const cr = recaptures.get(rec.name);
703
+ const crActive = cr && ev.height > cr.finalizeBy ? void 0 : cr;
704
+ const better2 = !crActive || (effHeight < crActive.effHeight || effHeight === crActive.effHeight && (ev.pos < crActive.pos || ev.pos === crActive.pos && ev.id < crActive.id));
705
+ if (!better2) {
706
+ note(ev, ev.id, "name", false, "recapture already reserved (earlier anchor wins)");
707
+ continue;
708
+ }
709
+ let myR = 0;
710
+ for (const [nm, r] of recaptures) if (r.owner === who && nm !== rec.name && ev.height <= r.finalizeBy) myR++;
711
+ if (myR >= MAX_PENDING_REG) {
712
+ note(ev, ev.id, "name", false, "too many pending recaptures (max reached)");
713
+ continue;
714
+ }
715
+ recaptures.set(rec.name, { owner: who, effHeight, pos: ev.pos, id: ev.id, height: ev.height, finalizeBy: effHeight + REG_COMMIT_MAX_BLOCKS + REG_FINALIZE_GRACE_BLOCKS });
716
+ note(ev, ev.id, "name", true, crActive ? "recapture reserved (displaced prior reservation)" : "recapture reserved (pending finalize)");
717
+ continue;
718
+ }
689
719
  const fee = expiredClaimFee(rec.name, epClaim - (paidThrough(curActive) + NAME_GRACE_EPOCHS), ev.height);
690
720
  if (feeToTreasury < fee) {
691
721
  note(ev, ev.id, "name", false, "lapsed-name claim fee unpaid (decaying premium)");
@@ -759,32 +789,69 @@ function resolve(events, tipHeight) {
759
789
  continue;
760
790
  }
761
791
  const n = names.get(rec.name);
762
- if (!n || !n.pending || n.owner !== who) {
763
- note(ev, ev.id, "nfinalize", false, "no matching pending reservation you own");
764
- continue;
765
- }
766
- const cH = commits.get(nameCommit(rec.name, rec.salt, who));
767
- if (cH === void 0 || cH !== n.effHeight) {
768
- note(ev, ev.id, "nfinalize", false, "salt does not match the reservation commit");
769
- continue;
770
- }
771
- if (!(ev.height > n.effHeight + REG_COMMIT_MAX_BLOCKS)) {
772
- note(ev, ev.id, "nfinalize", false, "too early \u2014 displacement contest not yet frozen");
773
- continue;
774
- }
775
- if (n.finalizeBy !== void 0 && ev.height > n.finalizeBy) {
776
- note(ev, ev.id, "nfinalize", false, "reservation expired");
777
- continue;
778
- }
779
- if (feeToTreasury < nameRegFee(rec.name, ev.height)) {
780
- note(ev, ev.id, "nfinalize", false, "name registration fee unpaid");
792
+ if (n && n.pending && n.owner === who) {
793
+ const cH = commits.get(nameCommit(rec.name, rec.salt, who));
794
+ if (cH === void 0 || cH !== n.effHeight) {
795
+ note(ev, ev.id, "nfinalize", false, "salt does not match the reservation commit");
796
+ continue;
797
+ }
798
+ if (!(ev.height > n.effHeight + REG_COMMIT_MAX_BLOCKS)) {
799
+ note(ev, ev.id, "nfinalize", false, "too early \u2014 displacement contest not yet frozen");
800
+ continue;
801
+ }
802
+ if (n.finalizeBy !== void 0 && ev.height > n.finalizeBy) {
803
+ note(ev, ev.id, "nfinalize", false, "reservation expired");
804
+ continue;
805
+ }
806
+ if (feeToTreasury < nameRegFee(rec.name, ev.height)) {
807
+ note(ev, ev.id, "nfinalize", false, "name registration fee unpaid");
808
+ continue;
809
+ }
810
+ n.pending = void 0;
811
+ n.finalizeBy = void 0;
812
+ n.paidThroughEpoch = epochOf(ev.height) + NAME_TERM_EPOCHS;
813
+ feesPaid += nameRegFee(rec.name, ev.height);
814
+ note(ev, ev.id, "nfinalize", true);
815
+ continue;
816
+ }
817
+ const r = v26 ? recaptures.get(rec.name) : void 0;
818
+ if (r && r.owner === who) {
819
+ const cH = commits.get(nameCommit(rec.name, rec.salt, who));
820
+ if (cH === void 0 || cH !== r.effHeight) {
821
+ note(ev, ev.id, "nfinalize", false, "salt does not match the recapture commit");
822
+ continue;
823
+ }
824
+ if (!(ev.height > r.effHeight + REG_COMMIT_MAX_BLOCKS)) {
825
+ note(ev, ev.id, "nfinalize", false, "too early \u2014 recapture contest not yet frozen");
826
+ continue;
827
+ }
828
+ if (ev.height > r.finalizeBy) {
829
+ note(ev, ev.id, "nfinalize", false, "recapture reservation expired");
830
+ continue;
831
+ }
832
+ const cur = names.get(rec.name);
833
+ const ep = epochOf(ev.height);
834
+ if (!cur || cur.pending || !lapsed(cur, ep)) {
835
+ recaptures.delete(rec.name);
836
+ note(ev, ev.id, "nfinalize", false, "name is no longer lapsed");
837
+ continue;
838
+ }
839
+ const fee = expiredClaimFee(rec.name, ep - (paidThrough(cur) + NAME_GRACE_EPOCHS), ev.height);
840
+ if (feeToTreasury < fee) {
841
+ note(ev, ev.id, "nfinalize", false, "recapture premium unpaid (decaying)");
842
+ continue;
843
+ }
844
+ for (const o of offers.values()) if (o.status === "open" && isNameGive(o.give) && o.give.name === rec.name) {
845
+ releaseGive(o);
846
+ o.status = "cancelled";
847
+ }
848
+ names.set(rec.name, { owner: who, effHeight: r.effHeight, pos: r.pos, id: r.id, height: r.height, locked: false, paidThroughEpoch: ep + NAME_TERM_EPOCHS });
849
+ recaptures.delete(rec.name);
850
+ feesPaid += fee;
851
+ note(ev, ev.id, "nfinalize", true, "recapture finalized (premium)");
781
852
  continue;
782
853
  }
783
- n.pending = void 0;
784
- n.finalizeBy = void 0;
785
- n.paidThroughEpoch = epochOf(ev.height) + NAME_TERM_EPOCHS;
786
- feesPaid += nameRegFee(rec.name, ev.height);
787
- note(ev, ev.id, "nfinalize", true);
854
+ note(ev, ev.id, "nfinalize", false, "no matching pending reservation you own");
788
855
  } else if (rec.t === "nxfer") {
789
856
  const n = names.get(rec.name);
790
857
  if (!n || n.owner !== who) {
@@ -1305,7 +1372,9 @@ function resolve(events, tipHeight) {
1305
1372
  for (const [id, o] of [...offers.entries()].sort(([a], [b]) => ord(a, b))) offersOut[id] = o;
1306
1373
  const bidsOut = {};
1307
1374
  for (const [id, b] of [...bids.entries()].sort(([a], [b2]) => ord(a, b2))) bidsOut[id] = b;
1308
- return { tipHeight, tokens: tokensOut, balances: balancesOut, names: namesOut, offers: offersOut, bids: bidsOut, events: log, feesPaid: feesPaid.toString() };
1375
+ const recapturesOut = {};
1376
+ for (const [nm, r] of [...recaptures.entries()].sort(([a], [b]) => ord(a, b))) recapturesOut[nm] = { owner: r.owner, effectiveHeight: r.effHeight, finalizeBy: r.finalizeBy };
1377
+ return { tipHeight, tokens: tokensOut, balances: balancesOut, names: namesOut, offers: offersOut, bids: bidsOut, recaptures: recapturesOut, events: log, feesPaid: feesPaid.toString() };
1309
1378
  }
1310
1379
  function canonicalState(s) {
1311
1380
  const sortKeys = (v) => {
@@ -1315,7 +1384,7 @@ function canonicalState(s) {
1315
1384
  }
1316
1385
  return v;
1317
1386
  };
1318
- const { events: _events, ...data } = s;
1387
+ const { events: _events, recaptures: _recaptures, ...data } = s;
1319
1388
  return JSON.stringify(sortKeys(data));
1320
1389
  }
1321
1390
 
@@ -1415,6 +1484,7 @@ var import_csd_codec4 = require("@inversealtruism/csd-codec");
1415
1484
  V23_HEIGHT,
1416
1485
  V24_HEIGHT,
1417
1486
  V25_HEIGHT,
1487
+ V26_HEIGHT,
1418
1488
  ZERO_ADDR,
1419
1489
  bid,
1420
1490
  blockReward,
package/dist/index.d.cts CHANGED
@@ -68,6 +68,7 @@ declare const REG_COMMIT_MAX_BLOCKS = 8;
68
68
  declare const REG_FINALIZE_GRACE_BLOCKS = 20;
69
69
  declare const MAX_PENDING_REG = 3;
70
70
  declare const FINALIZE_TIP_MARGIN = 2;
71
+ declare const V26_HEIGHT = 10000000;
71
72
  declare const epochOf: (height: number) => number;
72
73
  declare const claimWindowAt: (height: number) => number;
73
74
  declare const claimWindowOf: (claimUntilHeight: number) => number;
@@ -333,6 +334,13 @@ interface CairnXState {
333
334
  names: Record<string, NameState>;
334
335
  offers: Record<string, OfferState>;
335
336
  bids: Record<string, BidState>;
337
+ /** v2.6 pending recapture reservations (name → the current winner). DIAGNOSTIC, excluded from canonicalState
338
+ * (like `events`); exposed so a wallet/UI can confirm it is still the winner before paying the premium. */
339
+ recaptures: Record<string, {
340
+ owner: string;
341
+ effectiveHeight: number;
342
+ finalizeBy: number;
343
+ }>;
336
344
  events: AppliedEvent[];
337
345
  feesPaid: string;
338
346
  }
@@ -420,4 +428,4 @@ declare function requiredClaimDepth(valueSats: number | bigint, height: number):
420
428
  capped: boolean;
421
429
  };
422
430
 
423
- export { ACTIVATION_HEIGHT, ADDR_RE, AMOUNT_RE, type AppliedEvent, type AttestEvent, BID_KEYS, type BalanceState, type BidRecord, type BidState, type BidStatus, type BuiltRecord, CLAIM_ATTACKER_Q, CLAIM_COOLDOWN_BLOCKS, CLAIM_FILL_GRACE_BLOCKS, CLAIM_MIN_DEPTH, CLAIM_WINDOW_BLOCKS, CLAIM_WINDOW_BLOCKS_V20, COMMIT_MAX_BLOCKS, COMMIT_REVEAL_MIN_DEPTH, CONF_TOKEN_FILL, type CairnXRecord, type CairnXState, type ChainEvent, DEPLOY_FEE, DEPLOY_KEYS, DOMAIN, type DeployRecord, FEE_BPS, FEE_BPS_V16, FINALIZE_TIP_MARGIN, type FillEntry, type Give, HASH_RE, MAX_ACTIVE_CLAIMS, MAX_AMOUNT, MAX_OFFER_EPOCHS, MAX_PENDING_REG, MAX_RECORD_BYTES, MINT_KEYS, type MintRecord, NAME_FEE_LEN3_V24, NAME_FEE_LEN4_V24, NAME_FEE_LONG_V24, NAME_FEE_MID_V24, NAME_FEE_SHORT_V18, NAME_FEE_V18, NAME_GRACE_EPOCHS, NAME_KEYS, NAME_PREMIUM_DECAY_EPOCHS, NAME_PREMIUM_START, NAME_RE, NAME_TERM_EPOCHS, NFINALIZE_KEYS, NPROFILE_KEYS, type NameCommitRecord, type NameFinalizeRecord, type NameProfileRecord, type NameRecord, type NameRenewRecord, type NameSetRecord, type NameState, type NameXferRecord, OFFER_KEYS, type OfferCancelAllRecord, type OfferRecord, type OfferState, type OfferStatus, PKEY, PROFILE_MAX_KEYS, PROFILE_MAX_VALUE_BYTES, type ProposeEvent, REBATE_BPS, REBATE_FLAT, REG_COMMIT_MAX_BLOCKS, REG_FINALIZE_GRACE_BLOCKS, RESERVED_NAMES, SALT_RE, SCORE_CANCEL, SCORE_CLAIM, SCORE_FILL, TICKER_RE, TRANSFER_KEYS, TREASURY_ADDR, type TokenMetaRecord, type TokenState, type TransferRecord, V11_HEIGHT, V12_HEIGHT, V13_HEIGHT, V14_HEIGHT, V15_HEIGHT, V16_HEIGHT, V17_HEIGHT, V18_HEIGHT, V19_HEIGHT, V20_HEIGHT, V21_HEIGHT, V22_HEIGHT, V23_HEIGHT, V24_HEIGHT, V25_HEIGHT, type Want, ZERO_ADDR, bid, buildRecord, canonicalState, claimGraceOf, claimWindowAt, claimWindowOf, deploy, epochOf, expiredClaimFee, isName, isNameGive, isTokenWant, makerRebate, mint, nameClaim, nameCommit, nameCommitRecord, nameFinalize, nameProfile, nameRegFee, nameRenew, nameSet, nameXfer, offer, offerCancelAll, offerExpiryHeightOf, parseAmount, parseRecord, requiredClaimDepth, resolve, tokenMeta, tradeFee, transfer };
431
+ export { ACTIVATION_HEIGHT, ADDR_RE, AMOUNT_RE, type AppliedEvent, type AttestEvent, BID_KEYS, type BalanceState, type BidRecord, type BidState, type BidStatus, type BuiltRecord, CLAIM_ATTACKER_Q, CLAIM_COOLDOWN_BLOCKS, CLAIM_FILL_GRACE_BLOCKS, CLAIM_MIN_DEPTH, CLAIM_WINDOW_BLOCKS, CLAIM_WINDOW_BLOCKS_V20, COMMIT_MAX_BLOCKS, COMMIT_REVEAL_MIN_DEPTH, CONF_TOKEN_FILL, type CairnXRecord, type CairnXState, type ChainEvent, DEPLOY_FEE, DEPLOY_KEYS, DOMAIN, type DeployRecord, FEE_BPS, FEE_BPS_V16, FINALIZE_TIP_MARGIN, type FillEntry, type Give, HASH_RE, MAX_ACTIVE_CLAIMS, MAX_AMOUNT, MAX_OFFER_EPOCHS, MAX_PENDING_REG, MAX_RECORD_BYTES, MINT_KEYS, type MintRecord, NAME_FEE_LEN3_V24, NAME_FEE_LEN4_V24, NAME_FEE_LONG_V24, NAME_FEE_MID_V24, NAME_FEE_SHORT_V18, NAME_FEE_V18, NAME_GRACE_EPOCHS, NAME_KEYS, NAME_PREMIUM_DECAY_EPOCHS, NAME_PREMIUM_START, NAME_RE, NAME_TERM_EPOCHS, NFINALIZE_KEYS, NPROFILE_KEYS, type NameCommitRecord, type NameFinalizeRecord, type NameProfileRecord, type NameRecord, type NameRenewRecord, type NameSetRecord, type NameState, type NameXferRecord, OFFER_KEYS, type OfferCancelAllRecord, type OfferRecord, type OfferState, type OfferStatus, PKEY, PROFILE_MAX_KEYS, PROFILE_MAX_VALUE_BYTES, type ProposeEvent, REBATE_BPS, REBATE_FLAT, REG_COMMIT_MAX_BLOCKS, REG_FINALIZE_GRACE_BLOCKS, RESERVED_NAMES, SALT_RE, SCORE_CANCEL, SCORE_CLAIM, SCORE_FILL, TICKER_RE, TRANSFER_KEYS, TREASURY_ADDR, type TokenMetaRecord, type TokenState, type TransferRecord, V11_HEIGHT, V12_HEIGHT, V13_HEIGHT, V14_HEIGHT, V15_HEIGHT, V16_HEIGHT, V17_HEIGHT, V18_HEIGHT, V19_HEIGHT, V20_HEIGHT, V21_HEIGHT, V22_HEIGHT, V23_HEIGHT, V24_HEIGHT, V25_HEIGHT, V26_HEIGHT, type Want, ZERO_ADDR, bid, buildRecord, canonicalState, claimGraceOf, claimWindowAt, claimWindowOf, deploy, epochOf, expiredClaimFee, isName, isNameGive, isTokenWant, makerRebate, mint, nameClaim, nameCommit, nameCommitRecord, nameFinalize, nameProfile, nameRegFee, nameRenew, nameSet, nameXfer, offer, offerCancelAll, offerExpiryHeightOf, parseAmount, parseRecord, requiredClaimDepth, resolve, tokenMeta, tradeFee, transfer };
package/dist/index.d.ts CHANGED
@@ -68,6 +68,7 @@ declare const REG_COMMIT_MAX_BLOCKS = 8;
68
68
  declare const REG_FINALIZE_GRACE_BLOCKS = 20;
69
69
  declare const MAX_PENDING_REG = 3;
70
70
  declare const FINALIZE_TIP_MARGIN = 2;
71
+ declare const V26_HEIGHT = 10000000;
71
72
  declare const epochOf: (height: number) => number;
72
73
  declare const claimWindowAt: (height: number) => number;
73
74
  declare const claimWindowOf: (claimUntilHeight: number) => number;
@@ -333,6 +334,13 @@ interface CairnXState {
333
334
  names: Record<string, NameState>;
334
335
  offers: Record<string, OfferState>;
335
336
  bids: Record<string, BidState>;
337
+ /** v2.6 pending recapture reservations (name → the current winner). DIAGNOSTIC, excluded from canonicalState
338
+ * (like `events`); exposed so a wallet/UI can confirm it is still the winner before paying the premium. */
339
+ recaptures: Record<string, {
340
+ owner: string;
341
+ effectiveHeight: number;
342
+ finalizeBy: number;
343
+ }>;
336
344
  events: AppliedEvent[];
337
345
  feesPaid: string;
338
346
  }
@@ -420,4 +428,4 @@ declare function requiredClaimDepth(valueSats: number | bigint, height: number):
420
428
  capped: boolean;
421
429
  };
422
430
 
423
- export { ACTIVATION_HEIGHT, ADDR_RE, AMOUNT_RE, type AppliedEvent, type AttestEvent, BID_KEYS, type BalanceState, type BidRecord, type BidState, type BidStatus, type BuiltRecord, CLAIM_ATTACKER_Q, CLAIM_COOLDOWN_BLOCKS, CLAIM_FILL_GRACE_BLOCKS, CLAIM_MIN_DEPTH, CLAIM_WINDOW_BLOCKS, CLAIM_WINDOW_BLOCKS_V20, COMMIT_MAX_BLOCKS, COMMIT_REVEAL_MIN_DEPTH, CONF_TOKEN_FILL, type CairnXRecord, type CairnXState, type ChainEvent, DEPLOY_FEE, DEPLOY_KEYS, DOMAIN, type DeployRecord, FEE_BPS, FEE_BPS_V16, FINALIZE_TIP_MARGIN, type FillEntry, type Give, HASH_RE, MAX_ACTIVE_CLAIMS, MAX_AMOUNT, MAX_OFFER_EPOCHS, MAX_PENDING_REG, MAX_RECORD_BYTES, MINT_KEYS, type MintRecord, NAME_FEE_LEN3_V24, NAME_FEE_LEN4_V24, NAME_FEE_LONG_V24, NAME_FEE_MID_V24, NAME_FEE_SHORT_V18, NAME_FEE_V18, NAME_GRACE_EPOCHS, NAME_KEYS, NAME_PREMIUM_DECAY_EPOCHS, NAME_PREMIUM_START, NAME_RE, NAME_TERM_EPOCHS, NFINALIZE_KEYS, NPROFILE_KEYS, type NameCommitRecord, type NameFinalizeRecord, type NameProfileRecord, type NameRecord, type NameRenewRecord, type NameSetRecord, type NameState, type NameXferRecord, OFFER_KEYS, type OfferCancelAllRecord, type OfferRecord, type OfferState, type OfferStatus, PKEY, PROFILE_MAX_KEYS, PROFILE_MAX_VALUE_BYTES, type ProposeEvent, REBATE_BPS, REBATE_FLAT, REG_COMMIT_MAX_BLOCKS, REG_FINALIZE_GRACE_BLOCKS, RESERVED_NAMES, SALT_RE, SCORE_CANCEL, SCORE_CLAIM, SCORE_FILL, TICKER_RE, TRANSFER_KEYS, TREASURY_ADDR, type TokenMetaRecord, type TokenState, type TransferRecord, V11_HEIGHT, V12_HEIGHT, V13_HEIGHT, V14_HEIGHT, V15_HEIGHT, V16_HEIGHT, V17_HEIGHT, V18_HEIGHT, V19_HEIGHT, V20_HEIGHT, V21_HEIGHT, V22_HEIGHT, V23_HEIGHT, V24_HEIGHT, V25_HEIGHT, type Want, ZERO_ADDR, bid, buildRecord, canonicalState, claimGraceOf, claimWindowAt, claimWindowOf, deploy, epochOf, expiredClaimFee, isName, isNameGive, isTokenWant, makerRebate, mint, nameClaim, nameCommit, nameCommitRecord, nameFinalize, nameProfile, nameRegFee, nameRenew, nameSet, nameXfer, offer, offerCancelAll, offerExpiryHeightOf, parseAmount, parseRecord, requiredClaimDepth, resolve, tokenMeta, tradeFee, transfer };
431
+ export { ACTIVATION_HEIGHT, ADDR_RE, AMOUNT_RE, type AppliedEvent, type AttestEvent, BID_KEYS, type BalanceState, type BidRecord, type BidState, type BidStatus, type BuiltRecord, CLAIM_ATTACKER_Q, CLAIM_COOLDOWN_BLOCKS, CLAIM_FILL_GRACE_BLOCKS, CLAIM_MIN_DEPTH, CLAIM_WINDOW_BLOCKS, CLAIM_WINDOW_BLOCKS_V20, COMMIT_MAX_BLOCKS, COMMIT_REVEAL_MIN_DEPTH, CONF_TOKEN_FILL, type CairnXRecord, type CairnXState, type ChainEvent, DEPLOY_FEE, DEPLOY_KEYS, DOMAIN, type DeployRecord, FEE_BPS, FEE_BPS_V16, FINALIZE_TIP_MARGIN, type FillEntry, type Give, HASH_RE, MAX_ACTIVE_CLAIMS, MAX_AMOUNT, MAX_OFFER_EPOCHS, MAX_PENDING_REG, MAX_RECORD_BYTES, MINT_KEYS, type MintRecord, NAME_FEE_LEN3_V24, NAME_FEE_LEN4_V24, NAME_FEE_LONG_V24, NAME_FEE_MID_V24, NAME_FEE_SHORT_V18, NAME_FEE_V18, NAME_GRACE_EPOCHS, NAME_KEYS, NAME_PREMIUM_DECAY_EPOCHS, NAME_PREMIUM_START, NAME_RE, NAME_TERM_EPOCHS, NFINALIZE_KEYS, NPROFILE_KEYS, type NameCommitRecord, type NameFinalizeRecord, type NameProfileRecord, type NameRecord, type NameRenewRecord, type NameSetRecord, type NameState, type NameXferRecord, OFFER_KEYS, type OfferCancelAllRecord, type OfferRecord, type OfferState, type OfferStatus, PKEY, PROFILE_MAX_KEYS, PROFILE_MAX_VALUE_BYTES, type ProposeEvent, REBATE_BPS, REBATE_FLAT, REG_COMMIT_MAX_BLOCKS, REG_FINALIZE_GRACE_BLOCKS, RESERVED_NAMES, SALT_RE, SCORE_CANCEL, SCORE_CLAIM, SCORE_FILL, TICKER_RE, TRANSFER_KEYS, TREASURY_ADDR, type TokenMetaRecord, type TokenState, type TransferRecord, V11_HEIGHT, V12_HEIGHT, V13_HEIGHT, V14_HEIGHT, V15_HEIGHT, V16_HEIGHT, V17_HEIGHT, V18_HEIGHT, V19_HEIGHT, V20_HEIGHT, V21_HEIGHT, V22_HEIGHT, V23_HEIGHT, V24_HEIGHT, V25_HEIGHT, V26_HEIGHT, type Want, ZERO_ADDR, bid, buildRecord, canonicalState, claimGraceOf, claimWindowAt, claimWindowOf, deploy, epochOf, expiredClaimFee, isName, isNameGive, isTokenWant, makerRebate, mint, nameClaim, nameCommit, nameCommitRecord, nameFinalize, nameProfile, nameRegFee, nameRenew, nameSet, nameXfer, offer, offerCancelAll, offerExpiryHeightOf, parseAmount, parseRecord, requiredClaimDepth, resolve, tokenMeta, tradeFee, transfer };
package/dist/index.js CHANGED
@@ -86,6 +86,7 @@ var REG_COMMIT_MAX_BLOCKS = 8;
86
86
  var REG_FINALIZE_GRACE_BLOCKS = 20;
87
87
  var MAX_PENDING_REG = 3;
88
88
  var FINALIZE_TIP_MARGIN = 2;
89
+ var V26_HEIGHT = 1e7;
89
90
  var epochOf = (height) => Math.floor(height / EPOCH_LEN);
90
91
  var claimWindowAt = (height) => height >= V20_HEIGHT ? CLAIM_WINDOW_BLOCKS_V20 : CLAIM_WINDOW_BLOCKS;
91
92
  var claimWindowOf = (claimUntilHeight) => claimUntilHeight - CLAIM_WINDOW_BLOCKS_V20 >= V20_HEIGHT ? CLAIM_WINDOW_BLOCKS_V20 : CLAIM_WINDOW_BLOCKS;
@@ -345,6 +346,7 @@ function resolve(events, tipHeight) {
345
346
  const balances = /* @__PURE__ */ new Map();
346
347
  const names = /* @__PURE__ */ new Map();
347
348
  const commits = /* @__PURE__ */ new Map();
349
+ const recaptures = /* @__PURE__ */ new Map();
348
350
  const offers = /* @__PURE__ */ new Map();
349
351
  const offerLock = /* @__PURE__ */ new Map();
350
352
  const bids = /* @__PURE__ */ new Map();
@@ -397,6 +399,10 @@ function resolve(events, tipHeight) {
397
399
  const n = names.get(nm);
398
400
  if (n.pending && n.finalizeBy !== void 0 && height > n.finalizeBy) names.delete(nm);
399
401
  }
402
+ for (const nm of [...recaptures.keys()]) {
403
+ const r = recaptures.get(nm);
404
+ if (height > r.finalizeBy) recaptures.delete(nm);
405
+ }
400
406
  };
401
407
  const V15_EPOCH = epochOf(V15_HEIGHT);
402
408
  const paidThrough = (n) => n.paidThroughEpoch ?? V15_EPOCH + NAME_TERM_EPOCHS;
@@ -448,6 +454,7 @@ function resolve(events, tipHeight) {
448
454
  const v19 = ev.height >= V19_HEIGHT;
449
455
  const v23 = ev.height >= V23_HEIGHT;
450
456
  const v25 = ev.height >= V25_HEIGHT;
457
+ const v26 = ev.height >= V26_HEIGHT;
451
458
  const feeToTreasury = ev.kind === "propose" ? ptAmt((ev.paidTo ?? {})[TREASURY_ADDR]) : 0n;
452
459
  if (ev.kind === "propose") {
453
460
  const rec = parseRecord(ev.uri, ev.payloadHash);
@@ -533,7 +540,7 @@ function resolve(events, tipHeight) {
533
540
  note(ev, ev.id, "name", false, "before v1.1 activation");
534
541
  continue;
535
542
  }
536
- const regWindow = v25 ? REG_COMMIT_MAX_BLOCKS : COMMIT_MAX_BLOCKS;
543
+ const regWindow = v25 || v26 ? REG_COMMIT_MAX_BLOCKS : COMMIT_MAX_BLOCKS;
537
544
  let effHeight = ev.height;
538
545
  if (rec.salt !== void 0) {
539
546
  const ch = nameCommit(rec.name, rec.salt, who);
@@ -548,6 +555,28 @@ function resolve(events, tipHeight) {
548
555
  const epClaim = epochOf(ev.height);
549
556
  const curActive = cur && cur.pending && cur.finalizeBy !== void 0 && ev.height > cur.finalizeBy ? void 0 : cur;
550
557
  if (curActive && !curActive.pending && v15 && lapsed(curActive, epClaim)) {
558
+ if (v26) {
559
+ if (rec.salt === void 0) {
560
+ note(ev, ev.id, "name", false, "v2.6: recapture requires a commit-reveal (salt)");
561
+ continue;
562
+ }
563
+ const cr = recaptures.get(rec.name);
564
+ const crActive = cr && ev.height > cr.finalizeBy ? void 0 : cr;
565
+ const better2 = !crActive || (effHeight < crActive.effHeight || effHeight === crActive.effHeight && (ev.pos < crActive.pos || ev.pos === crActive.pos && ev.id < crActive.id));
566
+ if (!better2) {
567
+ note(ev, ev.id, "name", false, "recapture already reserved (earlier anchor wins)");
568
+ continue;
569
+ }
570
+ let myR = 0;
571
+ for (const [nm, r] of recaptures) if (r.owner === who && nm !== rec.name && ev.height <= r.finalizeBy) myR++;
572
+ if (myR >= MAX_PENDING_REG) {
573
+ note(ev, ev.id, "name", false, "too many pending recaptures (max reached)");
574
+ continue;
575
+ }
576
+ recaptures.set(rec.name, { owner: who, effHeight, pos: ev.pos, id: ev.id, height: ev.height, finalizeBy: effHeight + REG_COMMIT_MAX_BLOCKS + REG_FINALIZE_GRACE_BLOCKS });
577
+ note(ev, ev.id, "name", true, crActive ? "recapture reserved (displaced prior reservation)" : "recapture reserved (pending finalize)");
578
+ continue;
579
+ }
551
580
  const fee = expiredClaimFee(rec.name, epClaim - (paidThrough(curActive) + NAME_GRACE_EPOCHS), ev.height);
552
581
  if (feeToTreasury < fee) {
553
582
  note(ev, ev.id, "name", false, "lapsed-name claim fee unpaid (decaying premium)");
@@ -621,32 +650,69 @@ function resolve(events, tipHeight) {
621
650
  continue;
622
651
  }
623
652
  const n = names.get(rec.name);
624
- if (!n || !n.pending || n.owner !== who) {
625
- note(ev, ev.id, "nfinalize", false, "no matching pending reservation you own");
626
- continue;
627
- }
628
- const cH = commits.get(nameCommit(rec.name, rec.salt, who));
629
- if (cH === void 0 || cH !== n.effHeight) {
630
- note(ev, ev.id, "nfinalize", false, "salt does not match the reservation commit");
631
- continue;
632
- }
633
- if (!(ev.height > n.effHeight + REG_COMMIT_MAX_BLOCKS)) {
634
- note(ev, ev.id, "nfinalize", false, "too early \u2014 displacement contest not yet frozen");
635
- continue;
636
- }
637
- if (n.finalizeBy !== void 0 && ev.height > n.finalizeBy) {
638
- note(ev, ev.id, "nfinalize", false, "reservation expired");
639
- continue;
640
- }
641
- if (feeToTreasury < nameRegFee(rec.name, ev.height)) {
642
- note(ev, ev.id, "nfinalize", false, "name registration fee unpaid");
653
+ if (n && n.pending && n.owner === who) {
654
+ const cH = commits.get(nameCommit(rec.name, rec.salt, who));
655
+ if (cH === void 0 || cH !== n.effHeight) {
656
+ note(ev, ev.id, "nfinalize", false, "salt does not match the reservation commit");
657
+ continue;
658
+ }
659
+ if (!(ev.height > n.effHeight + REG_COMMIT_MAX_BLOCKS)) {
660
+ note(ev, ev.id, "nfinalize", false, "too early \u2014 displacement contest not yet frozen");
661
+ continue;
662
+ }
663
+ if (n.finalizeBy !== void 0 && ev.height > n.finalizeBy) {
664
+ note(ev, ev.id, "nfinalize", false, "reservation expired");
665
+ continue;
666
+ }
667
+ if (feeToTreasury < nameRegFee(rec.name, ev.height)) {
668
+ note(ev, ev.id, "nfinalize", false, "name registration fee unpaid");
669
+ continue;
670
+ }
671
+ n.pending = void 0;
672
+ n.finalizeBy = void 0;
673
+ n.paidThroughEpoch = epochOf(ev.height) + NAME_TERM_EPOCHS;
674
+ feesPaid += nameRegFee(rec.name, ev.height);
675
+ note(ev, ev.id, "nfinalize", true);
676
+ continue;
677
+ }
678
+ const r = v26 ? recaptures.get(rec.name) : void 0;
679
+ if (r && r.owner === who) {
680
+ const cH = commits.get(nameCommit(rec.name, rec.salt, who));
681
+ if (cH === void 0 || cH !== r.effHeight) {
682
+ note(ev, ev.id, "nfinalize", false, "salt does not match the recapture commit");
683
+ continue;
684
+ }
685
+ if (!(ev.height > r.effHeight + REG_COMMIT_MAX_BLOCKS)) {
686
+ note(ev, ev.id, "nfinalize", false, "too early \u2014 recapture contest not yet frozen");
687
+ continue;
688
+ }
689
+ if (ev.height > r.finalizeBy) {
690
+ note(ev, ev.id, "nfinalize", false, "recapture reservation expired");
691
+ continue;
692
+ }
693
+ const cur = names.get(rec.name);
694
+ const ep = epochOf(ev.height);
695
+ if (!cur || cur.pending || !lapsed(cur, ep)) {
696
+ recaptures.delete(rec.name);
697
+ note(ev, ev.id, "nfinalize", false, "name is no longer lapsed");
698
+ continue;
699
+ }
700
+ const fee = expiredClaimFee(rec.name, ep - (paidThrough(cur) + NAME_GRACE_EPOCHS), ev.height);
701
+ if (feeToTreasury < fee) {
702
+ note(ev, ev.id, "nfinalize", false, "recapture premium unpaid (decaying)");
703
+ continue;
704
+ }
705
+ for (const o of offers.values()) if (o.status === "open" && isNameGive(o.give) && o.give.name === rec.name) {
706
+ releaseGive(o);
707
+ o.status = "cancelled";
708
+ }
709
+ names.set(rec.name, { owner: who, effHeight: r.effHeight, pos: r.pos, id: r.id, height: r.height, locked: false, paidThroughEpoch: ep + NAME_TERM_EPOCHS });
710
+ recaptures.delete(rec.name);
711
+ feesPaid += fee;
712
+ note(ev, ev.id, "nfinalize", true, "recapture finalized (premium)");
643
713
  continue;
644
714
  }
645
- n.pending = void 0;
646
- n.finalizeBy = void 0;
647
- n.paidThroughEpoch = epochOf(ev.height) + NAME_TERM_EPOCHS;
648
- feesPaid += nameRegFee(rec.name, ev.height);
649
- note(ev, ev.id, "nfinalize", true);
715
+ note(ev, ev.id, "nfinalize", false, "no matching pending reservation you own");
650
716
  } else if (rec.t === "nxfer") {
651
717
  const n = names.get(rec.name);
652
718
  if (!n || n.owner !== who) {
@@ -1167,7 +1233,9 @@ function resolve(events, tipHeight) {
1167
1233
  for (const [id, o] of [...offers.entries()].sort(([a], [b]) => ord(a, b))) offersOut[id] = o;
1168
1234
  const bidsOut = {};
1169
1235
  for (const [id, b] of [...bids.entries()].sort(([a], [b2]) => ord(a, b2))) bidsOut[id] = b;
1170
- return { tipHeight, tokens: tokensOut, balances: balancesOut, names: namesOut, offers: offersOut, bids: bidsOut, events: log, feesPaid: feesPaid.toString() };
1236
+ const recapturesOut = {};
1237
+ for (const [nm, r] of [...recaptures.entries()].sort(([a], [b]) => ord(a, b))) recapturesOut[nm] = { owner: r.owner, effectiveHeight: r.effHeight, finalizeBy: r.finalizeBy };
1238
+ return { tipHeight, tokens: tokensOut, balances: balancesOut, names: namesOut, offers: offersOut, bids: bidsOut, recaptures: recapturesOut, events: log, feesPaid: feesPaid.toString() };
1171
1239
  }
1172
1240
  function canonicalState(s) {
1173
1241
  const sortKeys = (v) => {
@@ -1177,7 +1245,7 @@ function canonicalState(s) {
1177
1245
  }
1178
1246
  return v;
1179
1247
  };
1180
- const { events: _events, ...data } = s;
1248
+ const { events: _events, recaptures: _recaptures, ...data } = s;
1181
1249
  return JSON.stringify(sortKeys(data));
1182
1250
  }
1183
1251
 
@@ -1285,6 +1353,7 @@ export {
1285
1353
  V23_HEIGHT,
1286
1354
  V24_HEIGHT,
1287
1355
  V25_HEIGHT,
1356
+ V26_HEIGHT,
1288
1357
  ZERO_ADDR,
1289
1358
  bid,
1290
1359
  blockReward2 as blockReward,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@inversealtruism/cairnx-core",
3
- "version": "0.1.26",
3
+ "version": "0.1.28",
4
4
  "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.",
5
5
  "type": "module",
6
6
  "main": "./dist/index.cjs",