@inversealtruism/cairnx-core 0.1.18 → 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.cjs CHANGED
@@ -23,29 +23,42 @@ __export(index_exports, {
23
23
  ACTIVATION_HEIGHT: () => ACTIVATION_HEIGHT,
24
24
  ADDR_RE: () => ADDR_RE,
25
25
  AMOUNT_RE: () => AMOUNT_RE,
26
+ BID_KEYS: () => BID_KEYS,
27
+ CLAIM_ATTACKER_Q: () => CLAIM_ATTACKER_Q,
26
28
  CLAIM_COOLDOWN_BLOCKS: () => CLAIM_COOLDOWN_BLOCKS,
27
29
  CLAIM_FILL_GRACE_BLOCKS: () => CLAIM_FILL_GRACE_BLOCKS,
30
+ CLAIM_MIN_DEPTH: () => CLAIM_MIN_DEPTH,
28
31
  CLAIM_WINDOW_BLOCKS: () => CLAIM_WINDOW_BLOCKS,
29
32
  CLAIM_WINDOW_BLOCKS_V20: () => CLAIM_WINDOW_BLOCKS_V20,
30
33
  COMMIT_MAX_BLOCKS: () => COMMIT_MAX_BLOCKS,
34
+ COMMIT_REVEAL_MIN_DEPTH: () => COMMIT_REVEAL_MIN_DEPTH,
31
35
  CONF_TOKEN_FILL: () => CONF_TOKEN_FILL,
32
36
  DEPLOY_FEE: () => DEPLOY_FEE,
37
+ DEPLOY_KEYS: () => DEPLOY_KEYS,
33
38
  DOMAIN: () => DOMAIN,
34
- EPOCH_LEN: () => import_csd_codec.EPOCH_LEN,
39
+ EPOCH_LEN: () => import_csd_codec4.EPOCH_LEN,
35
40
  FEE_BPS: () => FEE_BPS,
36
41
  FEE_BPS_V16: () => FEE_BPS_V16,
42
+ HALVING_INTERVAL: () => import_csd_codec4.HALVING_INTERVAL,
37
43
  HASH_RE: () => HASH_RE,
44
+ INITIAL_REWARD: () => import_csd_codec4.INITIAL_REWARD,
38
45
  MAX_ACTIVE_CLAIMS: () => MAX_ACTIVE_CLAIMS,
39
46
  MAX_AMOUNT: () => MAX_AMOUNT,
40
47
  MAX_OFFER_EPOCHS: () => MAX_OFFER_EPOCHS,
41
48
  MAX_RECORD_BYTES: () => MAX_RECORD_BYTES,
49
+ MINT_KEYS: () => MINT_KEYS,
50
+ MIN_FEE_ATTEST: () => import_csd_codec4.MIN_FEE_ATTEST,
51
+ MIN_FEE_PROPOSE: () => import_csd_codec4.MIN_FEE_PROPOSE,
42
52
  NAME_FEE_SHORT_V18: () => NAME_FEE_SHORT_V18,
43
53
  NAME_FEE_V18: () => NAME_FEE_V18,
44
54
  NAME_GRACE_EPOCHS: () => NAME_GRACE_EPOCHS,
55
+ NAME_KEYS: () => NAME_KEYS,
45
56
  NAME_PREMIUM_DECAY_EPOCHS: () => NAME_PREMIUM_DECAY_EPOCHS,
46
57
  NAME_PREMIUM_START: () => NAME_PREMIUM_START,
47
58
  NAME_RE: () => NAME_RE,
48
59
  NAME_TERM_EPOCHS: () => NAME_TERM_EPOCHS,
60
+ NPROFILE_KEYS: () => NPROFILE_KEYS,
61
+ OFFER_KEYS: () => OFFER_KEYS,
49
62
  PKEY: () => PKEY,
50
63
  PROFILE_MAX_KEYS: () => PROFILE_MAX_KEYS,
51
64
  PROFILE_MAX_VALUE_BYTES: () => PROFILE_MAX_VALUE_BYTES,
@@ -57,6 +70,7 @@ __export(index_exports, {
57
70
  SCORE_CLAIM: () => SCORE_CLAIM,
58
71
  SCORE_FILL: () => SCORE_FILL,
59
72
  TICKER_RE: () => TICKER_RE,
73
+ TRANSFER_KEYS: () => TRANSFER_KEYS,
60
74
  TREASURY_ADDR: () => TREASURY_ADDR,
61
75
  V11_HEIGHT: () => V11_HEIGHT,
62
76
  V12_HEIGHT: () => V12_HEIGHT,
@@ -70,8 +84,13 @@ __export(index_exports, {
70
84
  V20_HEIGHT: () => V20_HEIGHT,
71
85
  V21_HEIGHT: () => V21_HEIGHT,
72
86
  bid: () => bid,
87
+ blockReward: () => import_csd_codec4.blockReward,
73
88
  buildRecord: () => buildRecord,
89
+ canonicalJson: () => import_csd_codec4.canonicalJson,
74
90
  canonicalState: () => canonicalState,
91
+ claimGraceOf: () => claimGraceOf,
92
+ claimWindowAt: () => claimWindowAt,
93
+ claimWindowOf: () => claimWindowOf,
75
94
  deploy: () => deploy,
76
95
  epochOf: () => epochOf,
77
96
  expiredClaimFee: () => expiredClaimFee,
@@ -90,8 +109,11 @@ __export(index_exports, {
90
109
  nameXfer: () => nameXfer,
91
110
  offer: () => offer,
92
111
  offerCancelAll: () => offerCancelAll,
112
+ offerExpiryHeightOf: () => offerExpiryHeightOf,
93
113
  parseAmount: () => parseAmount,
94
114
  parseRecord: () => parseRecord,
115
+ payloadHash: () => import_csd_codec4.payloadHash,
116
+ requiredClaimDepth: () => requiredClaimDepth,
95
117
  resolve: () => resolve,
96
118
  tokenMeta: () => tokenMeta,
97
119
  tradeFee: () => tradeFee,
@@ -168,6 +190,14 @@ var SALT_RE = /^[0-9a-fA-F]{16,128}$/;
168
190
  var RESERVED_NAMES = /* @__PURE__ */ new Set(["csd", "treasury", "admin", "official", "root", "www", "support"]);
169
191
  var COMMIT_MAX_BLOCKS = 8 * import_csd_codec.EPOCH_LEN;
170
192
  var epochOf = (height) => Math.floor(height / import_csd_codec.EPOCH_LEN);
193
+ var claimWindowAt = (height) => height >= V20_HEIGHT ? CLAIM_WINDOW_BLOCKS_V20 : CLAIM_WINDOW_BLOCKS;
194
+ var claimWindowOf = (claimUntilHeight) => claimUntilHeight - CLAIM_WINDOW_BLOCKS_V20 >= V20_HEIGHT ? CLAIM_WINDOW_BLOCKS_V20 : CLAIM_WINDOW_BLOCKS;
195
+ var claimGraceOf = (claimUntilHeight) => claimUntilHeight - CLAIM_WINDOW_BLOCKS_V20 >= V20_HEIGHT ? CLAIM_FILL_GRACE_BLOCKS : 0;
196
+ var offerExpiryHeightOf = (expiresEpoch, anchorHeight) => {
197
+ const raw = (Number(expiresEpoch ?? 0) + 1) * import_csd_codec.EPOCH_LEN;
198
+ const capped = (epochOf(anchorHeight) + MAX_OFFER_EPOCHS + 1) * import_csd_codec.EPOCH_LEN;
199
+ return Math.min(raw, Math.max(V21_HEIGHT, capped));
200
+ };
171
201
  var isNameGive = (g) => typeof g.name === "string";
172
202
  var isTokenWant = (w) => typeof w.ticker === "string";
173
203
 
@@ -464,9 +494,8 @@ function resolve(events, tipHeight) {
464
494
  const b = bids.get(o.bid);
465
495
  if (b && b.status === "open" && b.bidder === buyer) b.status = "done";
466
496
  };
467
- const claimGrace = (o) => o.claimUntilHeight !== void 0 && o.claimUntilHeight - CLAIM_WINDOW_BLOCKS_V20 >= V20_HEIGHT ? CLAIM_FILL_GRACE_BLOCKS : 0;
497
+ const claimGrace = (o) => o.claimUntilHeight !== void 0 ? claimGraceOf(o.claimUntilHeight) : 0;
468
498
  const claimHeld = (o, height) => o.claimedBy !== void 0 && o.claimUntilHeight !== void 0 && height < o.claimUntilHeight + claimGrace(o);
469
- const claimWindowAt = (height) => height >= V20_HEIGHT ? CLAIM_WINDOW_BLOCKS_V20 : CLAIM_WINDOW_BLOCKS;
470
499
  const openFillReject = (o, height, who) => {
471
500
  if (!(height >= V13_HEIGHT && !o.taker)) return void 0;
472
501
  if (height < V17_HEIGHT) return "v1.3: open CSD-quoted fills disabled (offer must be taker-bound)";
@@ -1150,34 +1179,66 @@ function canonicalState(s) {
1150
1179
  const { events: _events, ...data } = s;
1151
1180
  return JSON.stringify(sortKeys(data));
1152
1181
  }
1182
+
1183
+ // src/client.ts
1184
+ var import_csd_codec3 = require("@inversealtruism/csd-codec");
1185
+ var CLAIM_ATTACKER_Q = 0.2;
1186
+ var CLAIM_MIN_DEPTH = 3;
1187
+ var COMMIT_REVEAL_MIN_DEPTH = 3;
1188
+ function requiredClaimDepth(valueSats, height) {
1189
+ const r = CLAIM_ATTACKER_Q / (1 - CLAIM_ATTACKER_Q);
1190
+ const V = Number(valueSats);
1191
+ const R = (0, import_csd_codec3.blockReward)(height) || import_csd_codec3.INITIAL_REWARD;
1192
+ const max = claimWindowAt(height) - 5;
1193
+ for (let D = CLAIM_MIN_DEPTH; D <= max; D++) {
1194
+ if (Math.pow(r, D) * V <= D * R) return { depth: D, reversalPct: Math.pow(r, D) * 100, capped: false };
1195
+ }
1196
+ return { depth: max, reversalPct: Math.pow(r, max) * 100, capped: true };
1197
+ }
1198
+
1199
+ // src/index.ts
1200
+ var import_csd_codec4 = require("@inversealtruism/csd-codec");
1153
1201
  // Annotate the CommonJS export names for ESM import in node:
1154
1202
  0 && (module.exports = {
1155
1203
  ACTIVATION_HEIGHT,
1156
1204
  ADDR_RE,
1157
1205
  AMOUNT_RE,
1206
+ BID_KEYS,
1207
+ CLAIM_ATTACKER_Q,
1158
1208
  CLAIM_COOLDOWN_BLOCKS,
1159
1209
  CLAIM_FILL_GRACE_BLOCKS,
1210
+ CLAIM_MIN_DEPTH,
1160
1211
  CLAIM_WINDOW_BLOCKS,
1161
1212
  CLAIM_WINDOW_BLOCKS_V20,
1162
1213
  COMMIT_MAX_BLOCKS,
1214
+ COMMIT_REVEAL_MIN_DEPTH,
1163
1215
  CONF_TOKEN_FILL,
1164
1216
  DEPLOY_FEE,
1217
+ DEPLOY_KEYS,
1165
1218
  DOMAIN,
1166
1219
  EPOCH_LEN,
1167
1220
  FEE_BPS,
1168
1221
  FEE_BPS_V16,
1222
+ HALVING_INTERVAL,
1169
1223
  HASH_RE,
1224
+ INITIAL_REWARD,
1170
1225
  MAX_ACTIVE_CLAIMS,
1171
1226
  MAX_AMOUNT,
1172
1227
  MAX_OFFER_EPOCHS,
1173
1228
  MAX_RECORD_BYTES,
1229
+ MINT_KEYS,
1230
+ MIN_FEE_ATTEST,
1231
+ MIN_FEE_PROPOSE,
1174
1232
  NAME_FEE_SHORT_V18,
1175
1233
  NAME_FEE_V18,
1176
1234
  NAME_GRACE_EPOCHS,
1235
+ NAME_KEYS,
1177
1236
  NAME_PREMIUM_DECAY_EPOCHS,
1178
1237
  NAME_PREMIUM_START,
1179
1238
  NAME_RE,
1180
1239
  NAME_TERM_EPOCHS,
1240
+ NPROFILE_KEYS,
1241
+ OFFER_KEYS,
1181
1242
  PKEY,
1182
1243
  PROFILE_MAX_KEYS,
1183
1244
  PROFILE_MAX_VALUE_BYTES,
@@ -1189,6 +1250,7 @@ function canonicalState(s) {
1189
1250
  SCORE_CLAIM,
1190
1251
  SCORE_FILL,
1191
1252
  TICKER_RE,
1253
+ TRANSFER_KEYS,
1192
1254
  TREASURY_ADDR,
1193
1255
  V11_HEIGHT,
1194
1256
  V12_HEIGHT,
@@ -1202,8 +1264,13 @@ function canonicalState(s) {
1202
1264
  V20_HEIGHT,
1203
1265
  V21_HEIGHT,
1204
1266
  bid,
1267
+ blockReward,
1205
1268
  buildRecord,
1269
+ canonicalJson,
1206
1270
  canonicalState,
1271
+ claimGraceOf,
1272
+ claimWindowAt,
1273
+ claimWindowOf,
1207
1274
  deploy,
1208
1275
  epochOf,
1209
1276
  expiredClaimFee,
@@ -1222,8 +1289,11 @@ function canonicalState(s) {
1222
1289
  nameXfer,
1223
1290
  offer,
1224
1291
  offerCancelAll,
1292
+ offerExpiryHeightOf,
1225
1293
  parseAmount,
1226
1294
  parseRecord,
1295
+ payloadHash,
1296
+ requiredClaimDepth,
1227
1297
  resolve,
1228
1298
  tokenMeta,
1229
1299
  tradeFee,
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,8 @@ 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;
369
376
  const openFillReject = (o, height, who) => {
370
377
  if (!(height >= V13_HEIGHT && !o.taker)) return void 0;
371
378
  if (height < V17_HEIGHT) return "v1.3: open CSD-quoted fills disabled (offer must be taker-bound)";
@@ -1049,33 +1056,74 @@ function canonicalState(s) {
1049
1056
  const { events: _events, ...data } = s;
1050
1057
  return JSON.stringify(sortKeys(data));
1051
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";
1052
1087
  export {
1053
1088
  ACTIVATION_HEIGHT,
1054
1089
  ADDR_RE,
1055
1090
  AMOUNT_RE,
1091
+ BID_KEYS,
1092
+ CLAIM_ATTACKER_Q,
1056
1093
  CLAIM_COOLDOWN_BLOCKS,
1057
1094
  CLAIM_FILL_GRACE_BLOCKS,
1095
+ CLAIM_MIN_DEPTH,
1058
1096
  CLAIM_WINDOW_BLOCKS,
1059
1097
  CLAIM_WINDOW_BLOCKS_V20,
1060
1098
  COMMIT_MAX_BLOCKS,
1099
+ COMMIT_REVEAL_MIN_DEPTH,
1061
1100
  CONF_TOKEN_FILL,
1062
1101
  DEPLOY_FEE,
1102
+ DEPLOY_KEYS,
1063
1103
  DOMAIN,
1064
- EPOCH_LEN,
1104
+ EPOCH_LEN2 as EPOCH_LEN,
1065
1105
  FEE_BPS,
1066
1106
  FEE_BPS_V16,
1107
+ HALVING_INTERVAL,
1067
1108
  HASH_RE,
1109
+ INITIAL_REWARD2 as INITIAL_REWARD,
1068
1110
  MAX_ACTIVE_CLAIMS,
1069
1111
  MAX_AMOUNT,
1070
1112
  MAX_OFFER_EPOCHS,
1071
1113
  MAX_RECORD_BYTES,
1114
+ MINT_KEYS,
1115
+ MIN_FEE_ATTEST,
1116
+ MIN_FEE_PROPOSE,
1072
1117
  NAME_FEE_SHORT_V18,
1073
1118
  NAME_FEE_V18,
1074
1119
  NAME_GRACE_EPOCHS,
1120
+ NAME_KEYS,
1075
1121
  NAME_PREMIUM_DECAY_EPOCHS,
1076
1122
  NAME_PREMIUM_START,
1077
1123
  NAME_RE,
1078
1124
  NAME_TERM_EPOCHS,
1125
+ NPROFILE_KEYS,
1126
+ OFFER_KEYS,
1079
1127
  PKEY,
1080
1128
  PROFILE_MAX_KEYS,
1081
1129
  PROFILE_MAX_VALUE_BYTES,
@@ -1087,6 +1135,7 @@ export {
1087
1135
  SCORE_CLAIM,
1088
1136
  SCORE_FILL,
1089
1137
  TICKER_RE,
1138
+ TRANSFER_KEYS,
1090
1139
  TREASURY_ADDR,
1091
1140
  V11_HEIGHT,
1092
1141
  V12_HEIGHT,
@@ -1100,8 +1149,13 @@ export {
1100
1149
  V20_HEIGHT,
1101
1150
  V21_HEIGHT,
1102
1151
  bid,
1152
+ blockReward2 as blockReward,
1103
1153
  buildRecord,
1154
+ canonicalJson2 as canonicalJson,
1104
1155
  canonicalState,
1156
+ claimGraceOf,
1157
+ claimWindowAt,
1158
+ claimWindowOf,
1105
1159
  deploy,
1106
1160
  epochOf,
1107
1161
  expiredClaimFee,
@@ -1120,8 +1174,11 @@ export {
1120
1174
  nameXfer,
1121
1175
  offer,
1122
1176
  offerCancelAll,
1177
+ offerExpiryHeightOf,
1123
1178
  parseAmount,
1124
1179
  parseRecord,
1180
+ payloadHash2 as payloadHash,
1181
+ requiredClaimDepth,
1125
1182
  resolve,
1126
1183
  tokenMeta,
1127
1184
  tradeFee,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@inversealtruism/cairnx-core",
3
- "version": "0.1.18",
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
  }