@inversealtruism/cairnx-core 0.1.17 → 0.1.19

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.cts CHANGED
@@ -1,4 +1,4 @@
1
- export { EPOCH_LEN } from '@inversealtruism/csd-codec';
1
+ export { EPOCH_LEN, HALVING_INTERVAL, INITIAL_REWARD, MIN_FEE_ATTEST, MIN_FEE_PROPOSE, blockReward, canonicalJson, payloadHash } from '@inversealtruism/csd-codec';
2
2
 
3
3
  declare const DOMAIN = "cairnx:v1";
4
4
  declare const ACTIVATION_HEIGHT = 29860;
@@ -56,6 +56,10 @@ declare const SALT_RE: RegExp;
56
56
  declare const RESERVED_NAMES: Set<string>;
57
57
  declare const COMMIT_MAX_BLOCKS: number;
58
58
  declare const epochOf: (height: number) => number;
59
+ declare const claimWindowAt: (height: number) => number;
60
+ declare const claimWindowOf: (claimUntilHeight: number) => number;
61
+ declare const claimGraceOf: (claimUntilHeight: number) => number;
62
+ declare const offerExpiryHeightOf: (expiresEpoch: number, anchorHeight: number) => number;
59
63
  interface DeployRecord {
60
64
  v: 1;
61
65
  t: "deploy";
@@ -329,6 +333,13 @@ declare function parseAmount(s: unknown, opts?: {
329
333
  declare const isName: (n: unknown) => n is string;
330
334
  /** Deterministic commit hash for front-run-proof name registration (commit-reveal). */
331
335
  declare function nameCommit(name: string, salt: string, owner: string): string;
336
+ declare const DEPLOY_KEYS: Set<string>;
337
+ declare const MINT_KEYS: Set<string>;
338
+ declare const TRANSFER_KEYS: Set<string>;
339
+ declare const OFFER_KEYS: Set<string>;
340
+ declare const BID_KEYS: Set<string>;
341
+ declare const NAME_KEYS: Set<string>;
342
+ declare const NPROFILE_KEYS: Set<string>;
332
343
  /**
333
344
  * Parse + validate a record from an anchored `uri`. Returns null for anything invalid —
334
345
  * per CONVENTION §3, invalid is a no-op, never an error that poisons the replay.
@@ -362,4 +373,25 @@ declare function resolve(events: ChainEvent[], tipHeight: number): CairnXState;
362
373
  * history.) Keys sort in ordinal (code-unit) order at every depth. */
363
374
  declare function canonicalState(s: CairnXState): string;
364
375
 
365
- export { ACTIVATION_HEIGHT, ADDR_RE, AMOUNT_RE, type AppliedEvent, type AttestEvent, type BalanceState, type BidRecord, type BidState, type BidStatus, type BuiltRecord, CLAIM_COOLDOWN_BLOCKS, CLAIM_FILL_GRACE_BLOCKS, CLAIM_WINDOW_BLOCKS, CLAIM_WINDOW_BLOCKS_V20, COMMIT_MAX_BLOCKS, CONF_TOKEN_FILL, type CairnXRecord, type CairnXState, type ChainEvent, DEPLOY_FEE, DOMAIN, type DeployRecord, FEE_BPS, FEE_BPS_V16, type FillEntry, type Give, HASH_RE, MAX_ACTIVE_CLAIMS, MAX_AMOUNT, MAX_OFFER_EPOCHS, MAX_RECORD_BYTES, type MintRecord, NAME_FEE_SHORT_V18, NAME_FEE_V18, NAME_GRACE_EPOCHS, NAME_PREMIUM_DECAY_EPOCHS, NAME_PREMIUM_START, NAME_RE, NAME_TERM_EPOCHS, type NameCommitRecord, type NameProfileRecord, type NameRecord, type NameRenewRecord, type NameSetRecord, type NameState, type NameXferRecord, type OfferCancelAllRecord, type OfferRecord, type OfferState, type OfferStatus, PKEY, PROFILE_MAX_KEYS, PROFILE_MAX_VALUE_BYTES, type ProposeEvent, REBATE_BPS, REBATE_FLAT, RESERVED_NAMES, SALT_RE, SCORE_CANCEL, SCORE_CLAIM, SCORE_FILL, TICKER_RE, 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, type Want, bid, buildRecord, canonicalState, deploy, epochOf, expiredClaimFee, isName, isNameGive, isTokenWant, makerRebate, mint, nameClaim, nameCommit, nameCommitRecord, nameProfile, nameRegFee, nameRenew, nameSet, nameXfer, offer, offerCancelAll, parseAmount, parseRecord, resolve, tokenMeta, tradeFee, transfer };
376
+ declare const CLAIM_ATTACKER_Q = 0.2;
377
+ declare const CLAIM_MIN_DEPTH = 3;
378
+ declare const COMMIT_REVEAL_MIN_DEPTH = 3;
379
+ /**
380
+ * Confirmations the CLAIM must have before a payment-bearing fill on an open V17 offer worth `valueSats`
381
+ * (anchored at `height`) is reorg-safe. Returns `{ depth, reversalPct, capped }`; `capped=true` ⇒ the value
382
+ * exceeds what one claim window can safely settle (the buyer should split the trade).
383
+ *
384
+ * A MINORITY attacker (the dominant pool is trusted; a majority means the chain is already lost) only profits
385
+ * if `P(reverse D)·V > the honest reward it forgoes`, with `P(reverse D) ≈ (q/(1−q))^D` (gambler's ruin,
386
+ * Nakamoto §11). That is logarithmic in value → ~3 conf for nearly every trade, 4 for a whale. Everything is
387
+ * in CSD (block reward), so no USD price is needed. The required depth is capped at `claimWindow − 5` so a
388
+ * capped/whale value stays fillable for a usable multi-block span rather than a 1-block knife-edge (only
389
+ * absurd > total-supply values ever reach the cap).
390
+ */
391
+ declare function requiredClaimDepth(valueSats: number | bigint, height: number): {
392
+ depth: number;
393
+ reversalPct: number;
394
+ capped: boolean;
395
+ };
396
+
397
+ 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, type FillEntry, type Give, HASH_RE, MAX_ACTIVE_CLAIMS, MAX_AMOUNT, MAX_OFFER_EPOCHS, MAX_RECORD_BYTES, MINT_KEYS, type MintRecord, NAME_FEE_SHORT_V18, NAME_FEE_V18, NAME_GRACE_EPOCHS, NAME_KEYS, NAME_PREMIUM_DECAY_EPOCHS, NAME_PREMIUM_START, NAME_RE, NAME_TERM_EPOCHS, NPROFILE_KEYS, type NameCommitRecord, 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, 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, type Want, bid, buildRecord, canonicalState, claimGraceOf, claimWindowAt, claimWindowOf, deploy, epochOf, expiredClaimFee, isName, isNameGive, isTokenWant, makerRebate, mint, nameClaim, nameCommit, nameCommitRecord, nameProfile, nameRegFee, nameRenew, nameSet, nameXfer, offer, offerCancelAll, offerExpiryHeightOf, parseAmount, parseRecord, requiredClaimDepth, resolve, tokenMeta, tradeFee, transfer };
package/dist/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- export { EPOCH_LEN } from '@inversealtruism/csd-codec';
1
+ export { EPOCH_LEN, HALVING_INTERVAL, INITIAL_REWARD, MIN_FEE_ATTEST, MIN_FEE_PROPOSE, blockReward, canonicalJson, payloadHash } from '@inversealtruism/csd-codec';
2
2
 
3
3
  declare const DOMAIN = "cairnx:v1";
4
4
  declare const ACTIVATION_HEIGHT = 29860;
@@ -56,6 +56,10 @@ declare const SALT_RE: RegExp;
56
56
  declare const RESERVED_NAMES: Set<string>;
57
57
  declare const COMMIT_MAX_BLOCKS: number;
58
58
  declare const epochOf: (height: number) => number;
59
+ declare const claimWindowAt: (height: number) => number;
60
+ declare const claimWindowOf: (claimUntilHeight: number) => number;
61
+ declare const claimGraceOf: (claimUntilHeight: number) => number;
62
+ declare const offerExpiryHeightOf: (expiresEpoch: number, anchorHeight: number) => number;
59
63
  interface DeployRecord {
60
64
  v: 1;
61
65
  t: "deploy";
@@ -329,6 +333,13 @@ declare function parseAmount(s: unknown, opts?: {
329
333
  declare const isName: (n: unknown) => n is string;
330
334
  /** Deterministic commit hash for front-run-proof name registration (commit-reveal). */
331
335
  declare function nameCommit(name: string, salt: string, owner: string): string;
336
+ declare const DEPLOY_KEYS: Set<string>;
337
+ declare const MINT_KEYS: Set<string>;
338
+ declare const TRANSFER_KEYS: Set<string>;
339
+ declare const OFFER_KEYS: Set<string>;
340
+ declare const BID_KEYS: Set<string>;
341
+ declare const NAME_KEYS: Set<string>;
342
+ declare const NPROFILE_KEYS: Set<string>;
332
343
  /**
333
344
  * Parse + validate a record from an anchored `uri`. Returns null for anything invalid —
334
345
  * per CONVENTION §3, invalid is a no-op, never an error that poisons the replay.
@@ -362,4 +373,25 @@ declare function resolve(events: ChainEvent[], tipHeight: number): CairnXState;
362
373
  * history.) Keys sort in ordinal (code-unit) order at every depth. */
363
374
  declare function canonicalState(s: CairnXState): string;
364
375
 
365
- export { ACTIVATION_HEIGHT, ADDR_RE, AMOUNT_RE, type AppliedEvent, type AttestEvent, type BalanceState, type BidRecord, type BidState, type BidStatus, type BuiltRecord, CLAIM_COOLDOWN_BLOCKS, CLAIM_FILL_GRACE_BLOCKS, CLAIM_WINDOW_BLOCKS, CLAIM_WINDOW_BLOCKS_V20, COMMIT_MAX_BLOCKS, CONF_TOKEN_FILL, type CairnXRecord, type CairnXState, type ChainEvent, DEPLOY_FEE, DOMAIN, type DeployRecord, FEE_BPS, FEE_BPS_V16, type FillEntry, type Give, HASH_RE, MAX_ACTIVE_CLAIMS, MAX_AMOUNT, MAX_OFFER_EPOCHS, MAX_RECORD_BYTES, type MintRecord, NAME_FEE_SHORT_V18, NAME_FEE_V18, NAME_GRACE_EPOCHS, NAME_PREMIUM_DECAY_EPOCHS, NAME_PREMIUM_START, NAME_RE, NAME_TERM_EPOCHS, type NameCommitRecord, type NameProfileRecord, type NameRecord, type NameRenewRecord, type NameSetRecord, type NameState, type NameXferRecord, type OfferCancelAllRecord, type OfferRecord, type OfferState, type OfferStatus, PKEY, PROFILE_MAX_KEYS, PROFILE_MAX_VALUE_BYTES, type ProposeEvent, REBATE_BPS, REBATE_FLAT, RESERVED_NAMES, SALT_RE, SCORE_CANCEL, SCORE_CLAIM, SCORE_FILL, TICKER_RE, 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, type Want, bid, buildRecord, canonicalState, deploy, epochOf, expiredClaimFee, isName, isNameGive, isTokenWant, makerRebate, mint, nameClaim, nameCommit, nameCommitRecord, nameProfile, nameRegFee, nameRenew, nameSet, nameXfer, offer, offerCancelAll, parseAmount, parseRecord, resolve, tokenMeta, tradeFee, transfer };
376
+ declare const CLAIM_ATTACKER_Q = 0.2;
377
+ declare const CLAIM_MIN_DEPTH = 3;
378
+ declare const COMMIT_REVEAL_MIN_DEPTH = 3;
379
+ /**
380
+ * Confirmations the CLAIM must have before a payment-bearing fill on an open V17 offer worth `valueSats`
381
+ * (anchored at `height`) is reorg-safe. Returns `{ depth, reversalPct, capped }`; `capped=true` ⇒ the value
382
+ * exceeds what one claim window can safely settle (the buyer should split the trade).
383
+ *
384
+ * A MINORITY attacker (the dominant pool is trusted; a majority means the chain is already lost) only profits
385
+ * if `P(reverse D)·V > the honest reward it forgoes`, with `P(reverse D) ≈ (q/(1−q))^D` (gambler's ruin,
386
+ * Nakamoto §11). That is logarithmic in value → ~3 conf for nearly every trade, 4 for a whale. Everything is
387
+ * in CSD (block reward), so no USD price is needed. The required depth is capped at `claimWindow − 5` so a
388
+ * capped/whale value stays fillable for a usable multi-block span rather than a 1-block knife-edge (only
389
+ * absurd > total-supply values ever reach the cap).
390
+ */
391
+ declare function requiredClaimDepth(valueSats: number | bigint, height: number): {
392
+ depth: number;
393
+ reversalPct: number;
394
+ capped: boolean;
395
+ };
396
+
397
+ 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, type FillEntry, type Give, HASH_RE, MAX_ACTIVE_CLAIMS, MAX_AMOUNT, MAX_OFFER_EPOCHS, MAX_RECORD_BYTES, MINT_KEYS, type MintRecord, NAME_FEE_SHORT_V18, NAME_FEE_V18, NAME_GRACE_EPOCHS, NAME_KEYS, NAME_PREMIUM_DECAY_EPOCHS, NAME_PREMIUM_START, NAME_RE, NAME_TERM_EPOCHS, NPROFILE_KEYS, type NameCommitRecord, 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, 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, type Want, bid, buildRecord, canonicalState, claimGraceOf, claimWindowAt, claimWindowOf, deploy, epochOf, expiredClaimFee, isName, isNameGive, isTokenWant, makerRebate, mint, nameClaim, nameCommit, nameCommitRecord, nameProfile, nameRegFee, nameRenew, nameSet, nameXfer, offer, offerCancelAll, offerExpiryHeightOf, parseAmount, parseRecord, requiredClaimDepth, resolve, tokenMeta, tradeFee, transfer };
package/dist/index.js CHANGED
@@ -67,6 +67,14 @@ var SALT_RE = /^[0-9a-fA-F]{16,128}$/;
67
67
  var RESERVED_NAMES = /* @__PURE__ */ new Set(["csd", "treasury", "admin", "official", "root", "www", "support"]);
68
68
  var COMMIT_MAX_BLOCKS = 8 * EPOCH_LEN;
69
69
  var epochOf = (height) => Math.floor(height / EPOCH_LEN);
70
+ var claimWindowAt = (height) => height >= V20_HEIGHT ? CLAIM_WINDOW_BLOCKS_V20 : CLAIM_WINDOW_BLOCKS;
71
+ var claimWindowOf = (claimUntilHeight) => claimUntilHeight - CLAIM_WINDOW_BLOCKS_V20 >= V20_HEIGHT ? CLAIM_WINDOW_BLOCKS_V20 : CLAIM_WINDOW_BLOCKS;
72
+ var claimGraceOf = (claimUntilHeight) => claimUntilHeight - CLAIM_WINDOW_BLOCKS_V20 >= V20_HEIGHT ? CLAIM_FILL_GRACE_BLOCKS : 0;
73
+ var offerExpiryHeightOf = (expiresEpoch, anchorHeight) => {
74
+ const raw = (Number(expiresEpoch ?? 0) + 1) * EPOCH_LEN;
75
+ const capped = (epochOf(anchorHeight) + MAX_OFFER_EPOCHS + 1) * EPOCH_LEN;
76
+ return Math.min(raw, Math.max(V21_HEIGHT, capped));
77
+ };
70
78
  var isNameGive = (g) => typeof g.name === "string";
71
79
  var isTokenWant = (w) => typeof w.ticker === "string";
72
80
 
@@ -363,9 +371,33 @@ function resolve(events, tipHeight) {
363
371
  const b = bids.get(o.bid);
364
372
  if (b && b.status === "open" && b.bidder === buyer) b.status = "done";
365
373
  };
366
- const claimGrace = (o) => o.claimUntilHeight !== void 0 && o.claimUntilHeight - CLAIM_WINDOW_BLOCKS_V20 >= V20_HEIGHT ? CLAIM_FILL_GRACE_BLOCKS : 0;
374
+ const claimGrace = (o) => o.claimUntilHeight !== void 0 ? claimGraceOf(o.claimUntilHeight) : 0;
367
375
  const claimHeld = (o, height) => o.claimedBy !== void 0 && o.claimUntilHeight !== void 0 && height < o.claimUntilHeight + claimGrace(o);
368
- const claimWindowAt = (height) => height >= V20_HEIGHT ? CLAIM_WINDOW_BLOCKS_V20 : CLAIM_WINDOW_BLOCKS;
376
+ const openFillReject = (o, height, who) => {
377
+ if (!(height >= V13_HEIGHT && !o.taker)) return void 0;
378
+ if (height < V17_HEIGHT) return "v1.3: open CSD-quoted fills disabled (offer must be taker-bound)";
379
+ if (!(claimHeld(o, height) && who === o.claimedBy)) return "v1.7: open offer \u2014 claim it first (no live claim by you)";
380
+ return void 0;
381
+ };
382
+ const deliverNameToBuyer = (n, who, ev) => {
383
+ n.owner = who;
384
+ n.locked = false;
385
+ n.addr = void 0;
386
+ n.profile = void 0;
387
+ if (ev.height >= V13_HEIGHT) {
388
+ n.effHeight = ev.height;
389
+ n.pos = ev.pos;
390
+ n.id = ev.txid;
391
+ n.height = ev.height;
392
+ n.viaFill = true;
393
+ }
394
+ };
395
+ const releaseGiveLock = (o, who, amt) => {
396
+ const t = o.give.ticker;
397
+ bal(t, o.seller).locked -= amt;
398
+ bal(t, who).available += amt;
399
+ offerLock.delete(o.id);
400
+ };
369
401
  for (const ev of ordered) {
370
402
  if (ev.height < ACTIVATION_HEIGHT) continue;
371
403
  if (ev.height !== pendingBlock) {
@@ -820,23 +852,8 @@ function resolve(events, tipHeight) {
820
852
  buyer.available -= amt + fee;
821
853
  bal(o.want.ticker, o.want.payto).available += amt;
822
854
  if (fee > 0n) bal(o.want.ticker, TREASURY_ADDR).available += fee;
823
- if (isNameGive(o.give)) {
824
- giveName.owner = who;
825
- giveName.locked = false;
826
- giveName.addr = void 0;
827
- giveName.profile = void 0;
828
- if (ev.height >= V13_HEIGHT) {
829
- giveName.effHeight = ev.height;
830
- giveName.pos = ev.pos;
831
- giveName.id = ev.txid;
832
- giveName.height = ev.height;
833
- giveName.viaFill = true;
834
- }
835
- } else {
836
- bal(o.give.ticker, o.seller).locked -= giveLock;
837
- bal(o.give.ticker, who).available += giveLock;
838
- offerLock.delete(o.id);
839
- }
855
+ if (isNameGive(o.give)) deliverNameToBuyer(giveName, who, ev);
856
+ else releaseGiveLock(o, who, giveLock);
840
857
  o.status = "filled";
841
858
  o.fill = { buyer: who, txid: ev.txid, height: ev.height, paid: amt.toString(), fee: fee.toString() };
842
859
  markBidDone(o, who);
@@ -850,15 +867,10 @@ function resolve(events, tipHeight) {
850
867
  note(ev, ev.txid, "fill", false, "taker-bound offer");
851
868
  continue;
852
869
  }
853
- if (ev.height >= V13_HEIGHT && !o.taker) {
854
- if (ev.height < V17_HEIGHT) {
855
- note(ev, ev.txid, "fill", false, "v1.3: open CSD-quoted fills disabled (offer must be taker-bound)");
856
- continue;
857
- }
858
- if (!(claimHeld(o, ev.height) && who === o.claimedBy)) {
859
- note(ev, ev.txid, "fill", false, "v1.7: open offer \u2014 claim it first (no live claim by you)");
860
- continue;
861
- }
870
+ const blk = openFillReject(o, ev.height, who);
871
+ if (blk) {
872
+ note(ev, ev.txid, "fill", false, blk);
873
+ continue;
862
874
  }
863
875
  const pt = ev.paidTo ?? {};
864
876
  const want = BigInt(o.want.value);
@@ -915,15 +927,10 @@ function resolve(events, tipHeight) {
915
927
  note(ev, ev.txid, "fill", false, "taker-bound offer");
916
928
  continue;
917
929
  }
918
- if (ev.height >= V13_HEIGHT && !o.taker) {
919
- if (ev.height < V17_HEIGHT) {
920
- note(ev, ev.txid, "fill", false, "v1.3: open CSD-quoted fills disabled (offer must be taker-bound)");
921
- continue;
922
- }
923
- if (!(claimHeld(o, ev.height) && who === o.claimedBy)) {
924
- note(ev, ev.txid, "fill", false, "v1.7: open offer \u2014 claim it first (no live claim by you)");
925
- continue;
926
- }
930
+ const blk = openFillReject(o, ev.height, who);
931
+ if (blk) {
932
+ note(ev, ev.txid, "fill", false, blk);
933
+ continue;
927
934
  }
928
935
  const pt = ev.paidTo ?? {};
929
936
  const want = BigInt(o.want.value);
@@ -951,26 +958,14 @@ function resolve(events, tipHeight) {
951
958
  note(ev, ev.txid, "fill", false, "name vanished (consensus violation)");
952
959
  continue;
953
960
  }
954
- n.owner = who;
955
- n.locked = false;
956
- n.addr = void 0;
957
- n.profile = void 0;
958
- if (ev.height >= V13_HEIGHT) {
959
- n.effHeight = ev.height;
960
- n.pos = ev.pos;
961
- n.id = ev.txid;
962
- n.height = ev.height;
963
- n.viaFill = true;
964
- }
961
+ deliverNameToBuyer(n, who, ev);
965
962
  } else {
966
963
  const amt = offerLock.get(o.id);
967
964
  if (amt === void 0) {
968
965
  note(ev, ev.txid, "fill", false, "offer lock missing");
969
966
  continue;
970
967
  }
971
- bal(o.give.ticker, o.seller).locked -= amt;
972
- bal(o.give.ticker, who).available += amt;
973
- offerLock.delete(o.id);
968
+ releaseGiveLock(o, who, amt);
974
969
  }
975
970
  feesPaid += fee;
976
971
  o.status = "filled";
@@ -1061,33 +1056,74 @@ function canonicalState(s) {
1061
1056
  const { events: _events, ...data } = s;
1062
1057
  return JSON.stringify(sortKeys(data));
1063
1058
  }
1059
+
1060
+ // src/client.ts
1061
+ import { blockReward, INITIAL_REWARD } from "@inversealtruism/csd-codec";
1062
+ var CLAIM_ATTACKER_Q = 0.2;
1063
+ var CLAIM_MIN_DEPTH = 3;
1064
+ var COMMIT_REVEAL_MIN_DEPTH = 3;
1065
+ function requiredClaimDepth(valueSats, height) {
1066
+ const r = CLAIM_ATTACKER_Q / (1 - CLAIM_ATTACKER_Q);
1067
+ const V = Number(valueSats);
1068
+ const R = blockReward(height) || INITIAL_REWARD;
1069
+ const max = claimWindowAt(height) - 5;
1070
+ for (let D = CLAIM_MIN_DEPTH; D <= max; D++) {
1071
+ if (Math.pow(r, D) * V <= D * R) return { depth: D, reversalPct: Math.pow(r, D) * 100, capped: false };
1072
+ }
1073
+ return { depth: max, reversalPct: Math.pow(r, max) * 100, capped: true };
1074
+ }
1075
+
1076
+ // src/index.ts
1077
+ import {
1078
+ canonicalJson as canonicalJson2,
1079
+ payloadHash as payloadHash2,
1080
+ blockReward as blockReward2,
1081
+ INITIAL_REWARD as INITIAL_REWARD2,
1082
+ HALVING_INTERVAL,
1083
+ MIN_FEE_PROPOSE,
1084
+ MIN_FEE_ATTEST,
1085
+ EPOCH_LEN as EPOCH_LEN2
1086
+ } from "@inversealtruism/csd-codec";
1064
1087
  export {
1065
1088
  ACTIVATION_HEIGHT,
1066
1089
  ADDR_RE,
1067
1090
  AMOUNT_RE,
1091
+ BID_KEYS,
1092
+ CLAIM_ATTACKER_Q,
1068
1093
  CLAIM_COOLDOWN_BLOCKS,
1069
1094
  CLAIM_FILL_GRACE_BLOCKS,
1095
+ CLAIM_MIN_DEPTH,
1070
1096
  CLAIM_WINDOW_BLOCKS,
1071
1097
  CLAIM_WINDOW_BLOCKS_V20,
1072
1098
  COMMIT_MAX_BLOCKS,
1099
+ COMMIT_REVEAL_MIN_DEPTH,
1073
1100
  CONF_TOKEN_FILL,
1074
1101
  DEPLOY_FEE,
1102
+ DEPLOY_KEYS,
1075
1103
  DOMAIN,
1076
- EPOCH_LEN,
1104
+ EPOCH_LEN2 as EPOCH_LEN,
1077
1105
  FEE_BPS,
1078
1106
  FEE_BPS_V16,
1107
+ HALVING_INTERVAL,
1079
1108
  HASH_RE,
1109
+ INITIAL_REWARD2 as INITIAL_REWARD,
1080
1110
  MAX_ACTIVE_CLAIMS,
1081
1111
  MAX_AMOUNT,
1082
1112
  MAX_OFFER_EPOCHS,
1083
1113
  MAX_RECORD_BYTES,
1114
+ MINT_KEYS,
1115
+ MIN_FEE_ATTEST,
1116
+ MIN_FEE_PROPOSE,
1084
1117
  NAME_FEE_SHORT_V18,
1085
1118
  NAME_FEE_V18,
1086
1119
  NAME_GRACE_EPOCHS,
1120
+ NAME_KEYS,
1087
1121
  NAME_PREMIUM_DECAY_EPOCHS,
1088
1122
  NAME_PREMIUM_START,
1089
1123
  NAME_RE,
1090
1124
  NAME_TERM_EPOCHS,
1125
+ NPROFILE_KEYS,
1126
+ OFFER_KEYS,
1091
1127
  PKEY,
1092
1128
  PROFILE_MAX_KEYS,
1093
1129
  PROFILE_MAX_VALUE_BYTES,
@@ -1099,6 +1135,7 @@ export {
1099
1135
  SCORE_CLAIM,
1100
1136
  SCORE_FILL,
1101
1137
  TICKER_RE,
1138
+ TRANSFER_KEYS,
1102
1139
  TREASURY_ADDR,
1103
1140
  V11_HEIGHT,
1104
1141
  V12_HEIGHT,
@@ -1112,8 +1149,13 @@ export {
1112
1149
  V20_HEIGHT,
1113
1150
  V21_HEIGHT,
1114
1151
  bid,
1152
+ blockReward2 as blockReward,
1115
1153
  buildRecord,
1154
+ canonicalJson2 as canonicalJson,
1116
1155
  canonicalState,
1156
+ claimGraceOf,
1157
+ claimWindowAt,
1158
+ claimWindowOf,
1117
1159
  deploy,
1118
1160
  epochOf,
1119
1161
  expiredClaimFee,
@@ -1132,8 +1174,11 @@ export {
1132
1174
  nameXfer,
1133
1175
  offer,
1134
1176
  offerCancelAll,
1177
+ offerExpiryHeightOf,
1135
1178
  parseAmount,
1136
1179
  parseRecord,
1180
+ payloadHash2 as payloadHash,
1181
+ requiredClaimDepth,
1137
1182
  resolve,
1138
1183
  tokenMeta,
1139
1184
  tradeFee,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@inversealtruism/cairnx-core",
3
- "version": "0.1.17",
3
+ "version": "0.1.19",
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",
@@ -37,6 +37,6 @@
37
37
  "homepage": "https://cairn-substrate.com/trade",
38
38
  "scripts": {
39
39
  "build": "tsup src/index.ts --format esm,cjs --dts --clean",
40
- "test": "tsx test/vectors.test.ts && tsx test/name-decoy.test.ts"
40
+ "test": "tsx test/vectors.test.ts && tsx test/name-decoy.test.ts && tsx test/client-helpers.test.ts"
41
41
  }
42
42
  }
@@ -3,13 +3,23 @@
3
3
  **`cases.json`** — language-neutral replay vectors: `{name, events, tipHeight, expectedState}`.
4
4
  A third-party resolver is conformant iff, for every case, replaying `events` (already
5
5
  consensus-normalized: height/pos/proposer/attester/paidTo as the chain provides them) at
6
- `tipHeight` produces a canonical state JSON-equal to `expectedState`. Regenerate from the
7
- reference implementation: `npx tsx test/vectors/gen.ts`. Run: `npx tsx test/vectors.test.ts`.
6
+ `tipHeight` produces a canonical state JSON-equal to `expectedState`. This is the CI-enforced
7
+ bar (no live node needed): `test/vectors.test.ts` asserts JS==expectedState, and
8
+ `conformance/crosscheck-resolve.mjs` asserts JS==Python==expectedState. Coverage spans v1.0–v2.1
9
+ incl. nprofile, the V20 claim grace/late-fill, the V21 offer-cap, name ops, lapsed-premium reclaim,
10
+ and rejection paths. Regenerate the height-gated families from the SHIPPING resolver with the
11
+ generators in `conformance/`: `node conformance/gen-v18-vectors.mjs` (v1.8 name fee) and
12
+ `node conformance/gen-post-v18-vectors.mjs` (v1.9–v2.1) — each derives `expectedState` from the
13
+ built `dist/` and rewrites only its own `*-` prefixed cases. Run all: `npx tsx test/vectors.test.ts`.
8
14
 
9
- **`replay-hashes.json`** — sha256 of the canonical state of the REAL chain at each activation
10
- height (+ a dated tip, informational). Any resolver refactor must reproduce these bit-for-bit:
11
- `node scripts/conformance.mjs` verifies against the live indexer; `--update` re-pins (only
12
- legitimate after an intentional canonical-format change, with the change documented here).
15
+ **`replay-hashes.json`** — sha256 of the canonical state of the **REAL chain** at each activation
16
+ height (+ a dated tip, informational). This file (csd-sdk copy) is the published/static anchor;
17
+ the operator-maintained copy with the current pin set lives in the `cairnx` repo
18
+ (`cairnx/test/vectors/replay-hashes.json`) and is what the real-chain co-sign verifies. The
19
+ real-chain tools require a live indexer (CI has none → they skip): in the `cairnx` repo run
20
+ `tsx scripts/conformance.mjs` to verify the resolver against the live chain (`--update` re-pins —
21
+ only legitimate after an intentional canonical-format change, documented below), and
22
+ `tsx scripts/conformance-crosslang.mjs` for the JS⇄Python⇄pinned-hash co-sign over real on-chain data.
13
23
 
14
24
  | format | what changed |
15
25
  |---|---|