@inversealtruism/cairnx-core 0.1.30 → 0.1.32

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
@@ -215,6 +215,20 @@ once a replay hash is pinned over data that exercises them, so they are stated h
215
215
  `str::cmp` / Go `<` on `string` compare by UTF-8 bytes = codepoint order and are therefore WRONG** for
216
216
  a non-BMP key — implementers MUST compare UTF-16 code units (JS `localeCompare` is also wrong; use the
217
217
  default `<`/`>` on the JS string, i.e. code-unit order, which is what the resolver's `ord()` does).
218
+ **The numeric-key trap, and it points in OPPOSITE directions for the two hashes we compute, so read
219
+ carefully.** Nprofile maps (and all-digit names) can carry numeric-looking keys like `"2"`/`"10"`:
220
+ - **payloadHash / the record `uri` (`canonicalJson`)** sorts keys by pure code unit: `canonicalJson` is
221
+ `Object.keys(o).sort()`, and although JS's native `Object.keys` enumerates integer-index keys ascending-
222
+ NUMERIC (`"1","2","10"`), the trailing `.sort()` overrides that to code-unit order (`"1","10","2"`). So
223
+ for the record hash, `"10"` sorts BEFORE `"2"`. Do NOT special-case numeric keys here.
224
+ - **`sha256(canonicalState)` (the STATE hash)** is a DIFFERENT serializer (`sortKeys` + `JSON.stringify`,
225
+ not `canonicalJson`), and it INHERITS `JSON.stringify`'s native enumeration: ECMAScript array-index keys
226
+ (the canonical decimal of an integer in `[0, 2^32-2]`) are emitted FIRST in ascending-NUMERIC order,
227
+ THEN the remaining keys in code-unit order, regardless of the intermediate `.sort()`. So for the state
228
+ hash, `"2"` sorts BEFORE `"10"`. An implementer who applies the record-hash's pure-code-unit rule here
229
+ (or who ignores the integer-first enumeration) forks `sha256(canonicalState)` the first time a profile
230
+ carries two numeric keys. The reference Python mirror encodes exactly this split (`canonicalJson` vs
231
+ `_js_obj_key_order`/`_js_stringify` in `conformance/cairnx_ref.py`); a third impl MUST reproduce both.
218
232
  - **A3 — Field types (bare number/boolean vs decimal string vs identity string).** Canonical state mixes
219
233
  raw JSON integers and booleans with decimal-string amounts and raw identity strings. Emit as **bare
220
234
  integers**: `decimals, height, effectiveHeight, expiresEpoch, feeBps, tipHeight, paidThroughEpoch`, and
package/dist/index.cjs CHANGED
@@ -97,6 +97,7 @@ __export(index_exports, {
97
97
  V24_HEIGHT: () => V24_HEIGHT,
98
98
  V25_HEIGHT: () => V25_HEIGHT,
99
99
  V26_HEIGHT: () => V26_HEIGHT,
100
+ V27_HEIGHT: () => V27_HEIGHT,
100
101
  ZERO_ADDR: () => ZERO_ADDR,
101
102
  bid: () => bid,
102
103
  blockReward: () => import_csd_codec4.blockReward,
@@ -126,6 +127,7 @@ __export(index_exports, {
126
127
  offer: () => offer,
127
128
  offerCancelAll: () => offerCancelAll,
128
129
  offerExpiryHeightOf: () => offerExpiryHeightOf,
130
+ paidToFromOutputs: () => paidToFromOutputs,
129
131
  parseAmount: () => parseAmount,
130
132
  parseRecord: () => parseRecord,
131
133
  payloadHash: () => import_csd_codec4.payloadHash,
@@ -226,6 +228,7 @@ var REG_FINALIZE_GRACE_BLOCKS = 20;
226
228
  var MAX_PENDING_REG = 3;
227
229
  var FINALIZE_TIP_MARGIN = 2;
228
230
  var V26_HEIGHT = 51200;
231
+ var V27_HEIGHT = 52500;
229
232
  var epochOf = (height) => Math.floor(height / import_csd_codec.EPOCH_LEN);
230
233
  var claimWindowAt = (height) => height >= V20_HEIGHT ? CLAIM_WINDOW_BLOCKS_V20 : CLAIM_WINDOW_BLOCKS;
231
234
  var claimWindowOf = (claimUntilHeight) => claimUntilHeight - CLAIM_WINDOW_BLOCKS_V20 >= V20_HEIGHT ? CLAIM_WINDOW_BLOCKS_V20 : CLAIM_WINDOW_BLOCKS;
@@ -552,6 +555,13 @@ function resolve(events, tipHeight) {
552
555
  const b = bids.get(o.bid);
553
556
  if (b && b.status === "open" && b.bidder === buyer) b.status = "done";
554
557
  };
558
+ const voidOpenNameOffers = (name) => {
559
+ for (const o of offers.values()) if (o.status === "open" && isNameGive(o.give) && o.give.name === name) {
560
+ releaseGive(o);
561
+ o.status = "cancelled";
562
+ }
563
+ };
564
+ const earlierAnchor = (effHeight, pos, id, inc) => effHeight < inc.effHeight || effHeight === inc.effHeight && (pos < inc.pos || pos === inc.pos && id < inc.id);
555
565
  const claimGrace = (o) => o.claimUntilHeight !== void 0 ? claimGraceOf(o.claimUntilHeight) : 0;
556
566
  const claimHeld = (o, height) => o.claimedBy !== void 0 && o.claimUntilHeight !== void 0 && height < o.claimUntilHeight + claimGrace(o);
557
567
  const openFillReject = (o, height, who) => {
@@ -701,7 +711,7 @@ function resolve(events, tipHeight) {
701
711
  }
702
712
  const cr = recaptures.get(rec.name);
703
713
  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));
714
+ const better2 = !crActive || earlierAnchor(effHeight, ev.pos, ev.id, crActive);
705
715
  if (!better2) {
706
716
  note(ev, ev.id, "name", false, "recapture already reserved (earlier anchor wins)");
707
717
  continue;
@@ -721,10 +731,7 @@ function resolve(events, tipHeight) {
721
731
  note(ev, ev.id, "name", false, "lapsed-name claim fee unpaid (decaying premium)");
722
732
  continue;
723
733
  }
724
- for (const o of offers.values()) if (o.status === "open" && isNameGive(o.give) && o.give.name === rec.name) {
725
- releaseGive(o);
726
- o.status = "cancelled";
727
- }
734
+ voidOpenNameOffers(rec.name);
728
735
  names.set(rec.name, { owner: who, effHeight, pos: ev.pos, id: ev.id, height: ev.height, locked: false, viaFill: true, paidThroughEpoch: epClaim + NAME_TERM_EPOCHS });
729
736
  feesPaid += fee;
730
737
  note(ev, ev.id, "name", true, "lapsed lease re-claimed (premium)");
@@ -735,7 +742,7 @@ function resolve(events, tipHeight) {
735
742
  note(ev, ev.id, "name", false, "v2.5: registration requires a commit-reveal (salt)");
736
743
  continue;
737
744
  }
738
- const better2 = !curActive || !curActive.viaFill && (effHeight < curActive.effHeight || effHeight === curActive.effHeight && (ev.pos < curActive.pos || ev.pos === curActive.pos && ev.id < curActive.id));
745
+ const better2 = !curActive || !curActive.viaFill && earlierAnchor(effHeight, ev.pos, ev.id, curActive);
739
746
  if (!better2) {
740
747
  note(ev, ev.id, "name", false, curActive?.viaFill ? "name taken (purchased \u2014 not displaceable)" : "name taken (earlier anchor wins)");
741
748
  continue;
@@ -747,10 +754,7 @@ function resolve(events, tipHeight) {
747
754
  continue;
748
755
  }
749
756
  if (curActive) {
750
- for (const o of offers.values()) if (o.status === "open" && isNameGive(o.give) && o.give.name === rec.name) {
751
- releaseGive(o);
752
- o.status = "cancelled";
753
- }
757
+ voidOpenNameOffers(rec.name);
754
758
  }
755
759
  names.set(rec.name, { owner: who, effHeight, pos: ev.pos, id: ev.id, height: ev.height, locked: false, pending: true, finalizeBy: effHeight + REG_COMMIT_MAX_BLOCKS + REG_FINALIZE_GRACE_BLOCKS });
756
760
  note(ev, ev.id, "name", true, curActive ? "reserved (displaced prior reservation)" : "reserved (pending finalize)");
@@ -769,16 +773,13 @@ function resolve(events, tipHeight) {
769
773
  locked: false,
770
774
  ...v15 ? { paidThroughEpoch: epClaim + NAME_TERM_EPOCHS } : {}
771
775
  };
772
- const better = !curActive || !curActive.viaFill && (effHeight < curActive.effHeight || effHeight === curActive.effHeight && (ev.pos < curActive.pos || ev.pos === curActive.pos && ev.id < curActive.id));
776
+ const better = !curActive || !curActive.viaFill && earlierAnchor(effHeight, ev.pos, ev.id, curActive);
773
777
  if (!better) {
774
778
  note(ev, ev.id, "name", false, curActive?.viaFill ? "name taken (purchased \u2014 not displaceable)" : "name taken (earlier anchor wins)");
775
779
  continue;
776
780
  }
777
781
  if (curActive) {
778
- for (const o of offers.values()) if (o.status === "open" && isNameGive(o.give) && o.give.name === rec.name) {
779
- releaseGive(o);
780
- o.status = "cancelled";
781
- }
782
+ voidOpenNameOffers(rec.name);
782
783
  }
783
784
  names.set(rec.name, cand);
784
785
  feesPaid += nameRegFee(rec.name, ev.height);
@@ -807,8 +808,8 @@ function resolve(events, tipHeight) {
807
808
  note(ev, ev.id, "nfinalize", false, "name registration fee unpaid");
808
809
  continue;
809
810
  }
810
- n.pending = void 0;
811
- n.finalizeBy = void 0;
811
+ delete n.pending;
812
+ delete n.finalizeBy;
812
813
  n.paidThroughEpoch = epochOf(ev.height) + NAME_TERM_EPOCHS;
813
814
  feesPaid += nameRegFee(rec.name, ev.height);
814
815
  note(ev, ev.id, "nfinalize", true);
@@ -841,10 +842,7 @@ function resolve(events, tipHeight) {
841
842
  note(ev, ev.id, "nfinalize", false, "recapture premium unpaid (decaying)");
842
843
  continue;
843
844
  }
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
- }
845
+ voidOpenNameOffers(rec.name);
848
846
  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
847
  recaptures.delete(rec.name);
850
848
  feesPaid += fee;
@@ -957,8 +955,9 @@ function resolve(events, tipHeight) {
957
955
  note(ev, ev.id, "offer", false, "name already locked by another offer");
958
956
  continue;
959
957
  }
960
- if (ev.height >= V13_HEIGHT && !n.viaFill && ev.height - n.effHeight <= COMMIT_MAX_BLOCKS) {
961
- note(ev, ev.id, "offer", false, "v1.3: name too young to sell (claim must out-age the commit window)");
958
+ const saleEmbargo = ev.height >= V27_HEIGHT ? REG_COMMIT_MAX_BLOCKS : COMMIT_MAX_BLOCKS;
959
+ if (ev.height >= V13_HEIGHT && !n.viaFill && ev.height - n.effHeight <= saleEmbargo) {
960
+ note(ev, ev.id, "offer", false, "name too young to sell (must out-age the reveal window)");
962
961
  continue;
963
962
  }
964
963
  if (v15 && paidThrough(n) < ev.expiresEpoch) {
@@ -1404,6 +1403,16 @@ function requiredClaimDepth(valueSats, height) {
1404
1403
  return { depth: max, reversalPct: Math.pow(r, max) * 100, capped: true };
1405
1404
  }
1406
1405
 
1406
+ // src/paidto.ts
1407
+ function paidToFromOutputs(outputs) {
1408
+ const m = /* @__PURE__ */ Object.create(null);
1409
+ for (const o of outputs) {
1410
+ if (typeof o.value !== "number" || !Number.isSafeInteger(o.value) || o.value < 0) continue;
1411
+ m[o.addr] = (BigInt(m[o.addr] ?? "0") + BigInt(o.value)).toString();
1412
+ }
1413
+ return m;
1414
+ }
1415
+
1407
1416
  // src/index.ts
1408
1417
  var import_csd_codec4 = require("@inversealtruism/csd-codec");
1409
1418
  // Annotate the CommonJS export names for ESM import in node:
@@ -1485,6 +1494,7 @@ var import_csd_codec4 = require("@inversealtruism/csd-codec");
1485
1494
  V24_HEIGHT,
1486
1495
  V25_HEIGHT,
1487
1496
  V26_HEIGHT,
1497
+ V27_HEIGHT,
1488
1498
  ZERO_ADDR,
1489
1499
  bid,
1490
1500
  blockReward,
@@ -1514,6 +1524,7 @@ var import_csd_codec4 = require("@inversealtruism/csd-codec");
1514
1524
  offer,
1515
1525
  offerCancelAll,
1516
1526
  offerExpiryHeightOf,
1527
+ paidToFromOutputs,
1517
1528
  parseAmount,
1518
1529
  parseRecord,
1519
1530
  payloadHash,
package/dist/index.d.cts CHANGED
@@ -69,6 +69,7 @@ declare const REG_FINALIZE_GRACE_BLOCKS = 20;
69
69
  declare const MAX_PENDING_REG = 3;
70
70
  declare const FINALIZE_TIP_MARGIN = 2;
71
71
  declare const V26_HEIGHT = 51200;
72
+ declare const V27_HEIGHT = 52500;
72
73
  declare const epochOf: (height: number) => number;
73
74
  declare const claimWindowAt: (height: number) => number;
74
75
  declare const claimWindowOf: (claimUntilHeight: number) => number;
@@ -429,4 +430,9 @@ declare function requiredClaimDepth(valueSats: number | bigint, height: number):
429
430
  capped: boolean;
430
431
  };
431
432
 
432
- 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 };
433
+ declare function paidToFromOutputs(outputs: readonly {
434
+ addr: string;
435
+ value: number;
436
+ }[]): Record<string, string>;
437
+
438
+ 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, V27_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, paidToFromOutputs, parseAmount, parseRecord, requiredClaimDepth, resolve, tokenMeta, tradeFee, transfer };
package/dist/index.d.ts CHANGED
@@ -69,6 +69,7 @@ declare const REG_FINALIZE_GRACE_BLOCKS = 20;
69
69
  declare const MAX_PENDING_REG = 3;
70
70
  declare const FINALIZE_TIP_MARGIN = 2;
71
71
  declare const V26_HEIGHT = 51200;
72
+ declare const V27_HEIGHT = 52500;
72
73
  declare const epochOf: (height: number) => number;
73
74
  declare const claimWindowAt: (height: number) => number;
74
75
  declare const claimWindowOf: (claimUntilHeight: number) => number;
@@ -429,4 +430,9 @@ declare function requiredClaimDepth(valueSats: number | bigint, height: number):
429
430
  capped: boolean;
430
431
  };
431
432
 
432
- 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 };
433
+ declare function paidToFromOutputs(outputs: readonly {
434
+ addr: string;
435
+ value: number;
436
+ }[]): Record<string, string>;
437
+
438
+ 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, V27_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, paidToFromOutputs, parseAmount, parseRecord, requiredClaimDepth, resolve, tokenMeta, tradeFee, transfer };
package/dist/index.js CHANGED
@@ -87,6 +87,7 @@ var REG_FINALIZE_GRACE_BLOCKS = 20;
87
87
  var MAX_PENDING_REG = 3;
88
88
  var FINALIZE_TIP_MARGIN = 2;
89
89
  var V26_HEIGHT = 51200;
90
+ var V27_HEIGHT = 52500;
90
91
  var epochOf = (height) => Math.floor(height / EPOCH_LEN);
91
92
  var claimWindowAt = (height) => height >= V20_HEIGHT ? CLAIM_WINDOW_BLOCKS_V20 : CLAIM_WINDOW_BLOCKS;
92
93
  var claimWindowOf = (claimUntilHeight) => claimUntilHeight - CLAIM_WINDOW_BLOCKS_V20 >= V20_HEIGHT ? CLAIM_WINDOW_BLOCKS_V20 : CLAIM_WINDOW_BLOCKS;
@@ -413,6 +414,13 @@ function resolve(events, tipHeight) {
413
414
  const b = bids.get(o.bid);
414
415
  if (b && b.status === "open" && b.bidder === buyer) b.status = "done";
415
416
  };
417
+ const voidOpenNameOffers = (name) => {
418
+ for (const o of offers.values()) if (o.status === "open" && isNameGive(o.give) && o.give.name === name) {
419
+ releaseGive(o);
420
+ o.status = "cancelled";
421
+ }
422
+ };
423
+ const earlierAnchor = (effHeight, pos, id, inc) => effHeight < inc.effHeight || effHeight === inc.effHeight && (pos < inc.pos || pos === inc.pos && id < inc.id);
416
424
  const claimGrace = (o) => o.claimUntilHeight !== void 0 ? claimGraceOf(o.claimUntilHeight) : 0;
417
425
  const claimHeld = (o, height) => o.claimedBy !== void 0 && o.claimUntilHeight !== void 0 && height < o.claimUntilHeight + claimGrace(o);
418
426
  const openFillReject = (o, height, who) => {
@@ -562,7 +570,7 @@ function resolve(events, tipHeight) {
562
570
  }
563
571
  const cr = recaptures.get(rec.name);
564
572
  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));
573
+ const better2 = !crActive || earlierAnchor(effHeight, ev.pos, ev.id, crActive);
566
574
  if (!better2) {
567
575
  note(ev, ev.id, "name", false, "recapture already reserved (earlier anchor wins)");
568
576
  continue;
@@ -582,10 +590,7 @@ function resolve(events, tipHeight) {
582
590
  note(ev, ev.id, "name", false, "lapsed-name claim fee unpaid (decaying premium)");
583
591
  continue;
584
592
  }
585
- for (const o of offers.values()) if (o.status === "open" && isNameGive(o.give) && o.give.name === rec.name) {
586
- releaseGive(o);
587
- o.status = "cancelled";
588
- }
593
+ voidOpenNameOffers(rec.name);
589
594
  names.set(rec.name, { owner: who, effHeight, pos: ev.pos, id: ev.id, height: ev.height, locked: false, viaFill: true, paidThroughEpoch: epClaim + NAME_TERM_EPOCHS });
590
595
  feesPaid += fee;
591
596
  note(ev, ev.id, "name", true, "lapsed lease re-claimed (premium)");
@@ -596,7 +601,7 @@ function resolve(events, tipHeight) {
596
601
  note(ev, ev.id, "name", false, "v2.5: registration requires a commit-reveal (salt)");
597
602
  continue;
598
603
  }
599
- const better2 = !curActive || !curActive.viaFill && (effHeight < curActive.effHeight || effHeight === curActive.effHeight && (ev.pos < curActive.pos || ev.pos === curActive.pos && ev.id < curActive.id));
604
+ const better2 = !curActive || !curActive.viaFill && earlierAnchor(effHeight, ev.pos, ev.id, curActive);
600
605
  if (!better2) {
601
606
  note(ev, ev.id, "name", false, curActive?.viaFill ? "name taken (purchased \u2014 not displaceable)" : "name taken (earlier anchor wins)");
602
607
  continue;
@@ -608,10 +613,7 @@ function resolve(events, tipHeight) {
608
613
  continue;
609
614
  }
610
615
  if (curActive) {
611
- for (const o of offers.values()) if (o.status === "open" && isNameGive(o.give) && o.give.name === rec.name) {
612
- releaseGive(o);
613
- o.status = "cancelled";
614
- }
616
+ voidOpenNameOffers(rec.name);
615
617
  }
616
618
  names.set(rec.name, { owner: who, effHeight, pos: ev.pos, id: ev.id, height: ev.height, locked: false, pending: true, finalizeBy: effHeight + REG_COMMIT_MAX_BLOCKS + REG_FINALIZE_GRACE_BLOCKS });
617
619
  note(ev, ev.id, "name", true, curActive ? "reserved (displaced prior reservation)" : "reserved (pending finalize)");
@@ -630,16 +632,13 @@ function resolve(events, tipHeight) {
630
632
  locked: false,
631
633
  ...v15 ? { paidThroughEpoch: epClaim + NAME_TERM_EPOCHS } : {}
632
634
  };
633
- const better = !curActive || !curActive.viaFill && (effHeight < curActive.effHeight || effHeight === curActive.effHeight && (ev.pos < curActive.pos || ev.pos === curActive.pos && ev.id < curActive.id));
635
+ const better = !curActive || !curActive.viaFill && earlierAnchor(effHeight, ev.pos, ev.id, curActive);
634
636
  if (!better) {
635
637
  note(ev, ev.id, "name", false, curActive?.viaFill ? "name taken (purchased \u2014 not displaceable)" : "name taken (earlier anchor wins)");
636
638
  continue;
637
639
  }
638
640
  if (curActive) {
639
- for (const o of offers.values()) if (o.status === "open" && isNameGive(o.give) && o.give.name === rec.name) {
640
- releaseGive(o);
641
- o.status = "cancelled";
642
- }
641
+ voidOpenNameOffers(rec.name);
643
642
  }
644
643
  names.set(rec.name, cand);
645
644
  feesPaid += nameRegFee(rec.name, ev.height);
@@ -668,8 +667,8 @@ function resolve(events, tipHeight) {
668
667
  note(ev, ev.id, "nfinalize", false, "name registration fee unpaid");
669
668
  continue;
670
669
  }
671
- n.pending = void 0;
672
- n.finalizeBy = void 0;
670
+ delete n.pending;
671
+ delete n.finalizeBy;
673
672
  n.paidThroughEpoch = epochOf(ev.height) + NAME_TERM_EPOCHS;
674
673
  feesPaid += nameRegFee(rec.name, ev.height);
675
674
  note(ev, ev.id, "nfinalize", true);
@@ -702,10 +701,7 @@ function resolve(events, tipHeight) {
702
701
  note(ev, ev.id, "nfinalize", false, "recapture premium unpaid (decaying)");
703
702
  continue;
704
703
  }
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
- }
704
+ voidOpenNameOffers(rec.name);
709
705
  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
706
  recaptures.delete(rec.name);
711
707
  feesPaid += fee;
@@ -818,8 +814,9 @@ function resolve(events, tipHeight) {
818
814
  note(ev, ev.id, "offer", false, "name already locked by another offer");
819
815
  continue;
820
816
  }
821
- if (ev.height >= V13_HEIGHT && !n.viaFill && ev.height - n.effHeight <= COMMIT_MAX_BLOCKS) {
822
- note(ev, ev.id, "offer", false, "v1.3: name too young to sell (claim must out-age the commit window)");
817
+ const saleEmbargo = ev.height >= V27_HEIGHT ? REG_COMMIT_MAX_BLOCKS : COMMIT_MAX_BLOCKS;
818
+ if (ev.height >= V13_HEIGHT && !n.viaFill && ev.height - n.effHeight <= saleEmbargo) {
819
+ note(ev, ev.id, "offer", false, "name too young to sell (must out-age the reveal window)");
823
820
  continue;
824
821
  }
825
822
  if (v15 && paidThrough(n) < ev.expiresEpoch) {
@@ -1265,6 +1262,16 @@ function requiredClaimDepth(valueSats, height) {
1265
1262
  return { depth: max, reversalPct: Math.pow(r, max) * 100, capped: true };
1266
1263
  }
1267
1264
 
1265
+ // src/paidto.ts
1266
+ function paidToFromOutputs(outputs) {
1267
+ const m = /* @__PURE__ */ Object.create(null);
1268
+ for (const o of outputs) {
1269
+ if (typeof o.value !== "number" || !Number.isSafeInteger(o.value) || o.value < 0) continue;
1270
+ m[o.addr] = (BigInt(m[o.addr] ?? "0") + BigInt(o.value)).toString();
1271
+ }
1272
+ return m;
1273
+ }
1274
+
1268
1275
  // src/index.ts
1269
1276
  import {
1270
1277
  canonicalJson as canonicalJson2,
@@ -1354,6 +1361,7 @@ export {
1354
1361
  V24_HEIGHT,
1355
1362
  V25_HEIGHT,
1356
1363
  V26_HEIGHT,
1364
+ V27_HEIGHT,
1357
1365
  ZERO_ADDR,
1358
1366
  bid,
1359
1367
  blockReward2 as blockReward,
@@ -1383,6 +1391,7 @@ export {
1383
1391
  offer,
1384
1392
  offerCancelAll,
1385
1393
  offerExpiryHeightOf,
1394
+ paidToFromOutputs,
1386
1395
  parseAmount,
1387
1396
  parseRecord,
1388
1397
  payloadHash2 as payloadHash,
package/package.json CHANGED
@@ -1,6 +1,9 @@
1
1
  {
2
2
  "name": "@inversealtruism/cairnx-core",
3
- "version": "0.1.30",
3
+ "version": "0.1.32",
4
+ "engines": {
5
+ "node": ">=18"
6
+ },
4
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.",
5
8
  "type": "module",
6
9
  "main": "./dist/index.cjs",
@@ -8,9 +11,14 @@
8
11
  "types": "./dist/index.d.ts",
9
12
  "exports": {
10
13
  ".": {
11
- "types": "./dist/index.d.ts",
12
- "import": "./dist/index.js",
13
- "require": "./dist/index.cjs"
14
+ "import": {
15
+ "types": "./dist/index.d.ts",
16
+ "default": "./dist/index.js"
17
+ },
18
+ "require": {
19
+ "types": "./dist/index.d.cts",
20
+ "default": "./dist/index.cjs"
21
+ }
14
22
  }
15
23
  },
16
24
  "files": [
@@ -22,7 +30,7 @@
22
30
  "test/vectors"
23
31
  ],
24
32
  "dependencies": {
25
- "@inversealtruism/csd-codec": "0.1.14"
33
+ "@inversealtruism/csd-codec": "0.1.15"
26
34
  },
27
35
  "license": "MIT",
28
36
  "sideEffects": false,
@@ -37,6 +45,6 @@
37
45
  "homepage": "https://cairn-substrate.com/trade",
38
46
  "scripts": {
39
47
  "build": "tsup src/index.ts --format esm,cjs --dts --clean",
40
- "test": "tsx test/vectors.test.ts && tsx test/name-decoy.test.ts && tsx test/client-helpers.test.ts"
48
+ "test": "tsx test/vectors.test.ts && tsx test/name-decoy.test.ts && tsx test/client-helpers.test.ts && tsx test/paidto.test.ts"
41
49
  }
42
50
  }