@inversealtruism/cairnx-core 0.1.14 → 0.1.16

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
@@ -24,7 +24,9 @@ __export(index_exports, {
24
24
  ADDR_RE: () => ADDR_RE,
25
25
  AMOUNT_RE: () => AMOUNT_RE,
26
26
  CLAIM_COOLDOWN_BLOCKS: () => CLAIM_COOLDOWN_BLOCKS,
27
+ CLAIM_FILL_GRACE_BLOCKS: () => CLAIM_FILL_GRACE_BLOCKS,
27
28
  CLAIM_WINDOW_BLOCKS: () => CLAIM_WINDOW_BLOCKS,
29
+ CLAIM_WINDOW_BLOCKS_V20: () => CLAIM_WINDOW_BLOCKS_V20,
28
30
  COMMIT_MAX_BLOCKS: () => COMMIT_MAX_BLOCKS,
29
31
  CONF_TOKEN_FILL: () => CONF_TOKEN_FILL,
30
32
  DEPLOY_FEE: () => DEPLOY_FEE,
@@ -35,6 +37,7 @@ __export(index_exports, {
35
37
  HASH_RE: () => HASH_RE,
36
38
  MAX_ACTIVE_CLAIMS: () => MAX_ACTIVE_CLAIMS,
37
39
  MAX_AMOUNT: () => MAX_AMOUNT,
40
+ MAX_OFFER_EPOCHS: () => MAX_OFFER_EPOCHS,
38
41
  MAX_RECORD_BYTES: () => MAX_RECORD_BYTES,
39
42
  NAME_FEE_SHORT_V18: () => NAME_FEE_SHORT_V18,
40
43
  NAME_FEE_V18: () => NAME_FEE_V18,
@@ -64,6 +67,8 @@ __export(index_exports, {
64
67
  V17_HEIGHT: () => V17_HEIGHT,
65
68
  V18_HEIGHT: () => V18_HEIGHT,
66
69
  V19_HEIGHT: () => V19_HEIGHT,
70
+ V20_HEIGHT: () => V20_HEIGHT,
71
+ V21_HEIGHT: () => V21_HEIGHT,
67
72
  bid: () => bid,
68
73
  buildRecord: () => buildRecord,
69
74
  canonicalState: () => canonicalState,
@@ -122,6 +127,8 @@ var SCORE_FILL = 100;
122
127
  var SCORE_CANCEL = 0;
123
128
  var SCORE_CLAIM = 50;
124
129
  var CLAIM_WINDOW_BLOCKS = 15;
130
+ var CLAIM_WINDOW_BLOCKS_V20 = 40;
131
+ var CLAIM_FILL_GRACE_BLOCKS = 5;
125
132
  var MAX_ACTIVE_CLAIMS = 3;
126
133
  var CLAIM_COOLDOWN_BLOCKS = 15;
127
134
  var CONF_TOKEN_FILL = 1e6;
@@ -135,6 +142,9 @@ var V18_HEIGHT = 4e4;
135
142
  var NAME_FEE_SHORT_V18 = 670000000n;
136
143
  var NAME_FEE_V18 = 300000000n;
137
144
  var V19_HEIGHT = 36700;
145
+ var V20_HEIGHT = 38400;
146
+ var V21_HEIGHT = 42e3;
147
+ var MAX_OFFER_EPOCHS = 168;
138
148
  var PKEY = /^[a-z0-9](?:[a-z0-9.-]{0,30}[a-z0-9])?$/;
139
149
  var PROFILE_MAX_KEYS = 16;
140
150
  var PROFILE_MAX_VALUE_BYTES = 256;
@@ -432,16 +442,17 @@ function resolve(events, tipHeight) {
432
442
  b.available += amt;
433
443
  }
434
444
  };
445
+ const effExpiry = (e, height) => height >= V21_HEIGHT ? Math.min(e.expiresEpoch, epochOf(e.height) + MAX_OFFER_EPOCHS) : e.expiresEpoch;
435
446
  const sweepExpired = (height) => {
436
447
  const ep = epochOf(height);
437
448
  for (const o of offers.values()) {
438
- if (o.status === "open" && ep > o.expiresEpoch) {
449
+ if (o.status === "open" && ep > effExpiry(o, height)) {
439
450
  releaseGive(o);
440
451
  o.status = "expired";
441
452
  }
442
453
  }
443
454
  for (const b of bids.values()) {
444
- if (b.status === "open" && ep > b.expiresEpoch) b.status = "expired";
455
+ if (b.status === "open" && ep > effExpiry(b, height)) b.status = "expired";
445
456
  }
446
457
  };
447
458
  const V15_EPOCH = epochOf(V15_HEIGHT);
@@ -453,7 +464,9 @@ function resolve(events, tipHeight) {
453
464
  const b = bids.get(o.bid);
454
465
  if (b && b.status === "open" && b.bidder === buyer) b.status = "done";
455
466
  };
456
- const liveClaim = (o, height) => o.claimedBy !== void 0 && o.claimUntilHeight !== void 0 && height < o.claimUntilHeight;
467
+ const claimGrace = (o) => o.claimUntilHeight !== void 0 && o.claimUntilHeight - CLAIM_WINDOW_BLOCKS_V20 >= V20_HEIGHT ? CLAIM_FILL_GRACE_BLOCKS : 0;
468
+ 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;
457
470
  for (const ev of ordered) {
458
471
  if (ev.height < ACTIVATION_HEIGHT) continue;
459
472
  if (ev.height !== pendingBlock) {
@@ -674,6 +687,10 @@ function resolve(events, tipHeight) {
674
687
  note(ev, ev.id, "offer", false, "already expired at anchor");
675
688
  continue;
676
689
  }
690
+ if (ev.height >= V21_HEIGHT && ev.expiresEpoch - epochOf(ev.height) > MAX_OFFER_EPOCHS) {
691
+ note(ev, ev.id, "offer", false, "v2.1: offer duration exceeds the max");
692
+ continue;
693
+ }
677
694
  const give = rec.give;
678
695
  if (isNameGive(give)) {
679
696
  if (!v11) {
@@ -743,6 +760,10 @@ function resolve(events, tipHeight) {
743
760
  note(ev, ev.id, "bid", false, "already expired at anchor");
744
761
  continue;
745
762
  }
763
+ if (ev.height >= V21_HEIGHT && ev.expiresEpoch - epochOf(ev.height) > MAX_OFFER_EPOCHS) {
764
+ note(ev, ev.id, "bid", false, "v2.1: bid duration exceeds the max");
765
+ continue;
766
+ }
746
767
  bids.set(ev.id, {
747
768
  id: ev.id,
748
769
  bidder: who,
@@ -935,7 +956,7 @@ function resolve(events, tipHeight) {
935
956
  note(ev, ev.txid, "fill", false, "v1.3: open CSD-quoted fills disabled (offer must be taker-bound)");
936
957
  continue;
937
958
  }
938
- if (!(liveClaim(o, ev.height) && who === o.claimedBy)) {
959
+ if (!(claimHeld(o, ev.height) && who === o.claimedBy)) {
939
960
  note(ev, ev.txid, "fill", false, "v1.7: open offer \u2014 claim it first (no live claim by you)");
940
961
  continue;
941
962
  }
@@ -1000,7 +1021,7 @@ function resolve(events, tipHeight) {
1000
1021
  note(ev, ev.txid, "fill", false, "v1.3: open CSD-quoted fills disabled (offer must be taker-bound)");
1001
1022
  continue;
1002
1023
  }
1003
- if (!(liveClaim(o, ev.height) && who === o.claimedBy)) {
1024
+ if (!(claimHeld(o, ev.height) && who === o.claimedBy)) {
1004
1025
  note(ev, ev.txid, "fill", false, "v1.7: open offer \u2014 claim it first (no live claim by you)");
1005
1026
  continue;
1006
1027
  }
@@ -1070,22 +1091,22 @@ function resolve(events, tipHeight) {
1070
1091
  note(ev, ev.txid, "claim", false, "claims are for CSD-priced offers (token offers are no-op-safe)");
1071
1092
  continue;
1072
1093
  }
1073
- if (liveClaim(o, ev.height)) {
1074
- note(ev, ev.txid, "claim", false, "offer already claimed (window live)");
1094
+ if (claimHeld(o, ev.height)) {
1095
+ note(ev, ev.txid, "claim", false, "offer already claimed (hold live)");
1075
1096
  continue;
1076
1097
  }
1077
- if (o.claimedBy === who && o.claimUntilHeight !== void 0 && ev.height < o.claimUntilHeight + CLAIM_COOLDOWN_BLOCKS) {
1098
+ if (o.claimedBy === who && o.claimUntilHeight !== void 0 && ev.height < o.claimUntilHeight + claimGrace(o) + CLAIM_COOLDOWN_BLOCKS) {
1078
1099
  note(ev, ev.txid, "claim", false, "claim cooldown (you just held this offer)");
1079
1100
  continue;
1080
1101
  }
1081
1102
  let liveN = 0;
1082
- for (const x of offers.values()) if (x.claimedBy === who && x.claimUntilHeight !== void 0 && ev.height < x.claimUntilHeight) liveN++;
1103
+ for (const x of offers.values()) if (x.claimedBy === who && claimHeld(x, ev.height)) liveN++;
1083
1104
  if (liveN >= MAX_ACTIVE_CLAIMS) {
1084
1105
  note(ev, ev.txid, "claim", false, `max ${MAX_ACTIVE_CLAIMS} live claims per address`);
1085
1106
  continue;
1086
1107
  }
1087
1108
  o.claimedBy = who;
1088
- o.claimUntilHeight = ev.height + CLAIM_WINDOW_BLOCKS;
1109
+ o.claimUntilHeight = ev.height + claimWindowAt(ev.height);
1089
1110
  note(ev, ev.txid, "claim", true);
1090
1111
  }
1091
1112
  }
@@ -1147,7 +1168,9 @@ function canonicalState(s) {
1147
1168
  ADDR_RE,
1148
1169
  AMOUNT_RE,
1149
1170
  CLAIM_COOLDOWN_BLOCKS,
1171
+ CLAIM_FILL_GRACE_BLOCKS,
1150
1172
  CLAIM_WINDOW_BLOCKS,
1173
+ CLAIM_WINDOW_BLOCKS_V20,
1151
1174
  COMMIT_MAX_BLOCKS,
1152
1175
  CONF_TOKEN_FILL,
1153
1176
  DEPLOY_FEE,
@@ -1158,6 +1181,7 @@ function canonicalState(s) {
1158
1181
  HASH_RE,
1159
1182
  MAX_ACTIVE_CLAIMS,
1160
1183
  MAX_AMOUNT,
1184
+ MAX_OFFER_EPOCHS,
1161
1185
  MAX_RECORD_BYTES,
1162
1186
  NAME_FEE_SHORT_V18,
1163
1187
  NAME_FEE_V18,
@@ -1187,6 +1211,8 @@ function canonicalState(s) {
1187
1211
  V17_HEIGHT,
1188
1212
  V18_HEIGHT,
1189
1213
  V19_HEIGHT,
1214
+ V20_HEIGHT,
1215
+ V21_HEIGHT,
1190
1216
  bid,
1191
1217
  buildRecord,
1192
1218
  canonicalState,
package/dist/index.d.cts CHANGED
@@ -23,6 +23,8 @@ declare const SCORE_FILL = 100;
23
23
  declare const SCORE_CANCEL = 0;
24
24
  declare const SCORE_CLAIM = 50;
25
25
  declare const CLAIM_WINDOW_BLOCKS = 15;
26
+ declare const CLAIM_WINDOW_BLOCKS_V20 = 40;
27
+ declare const CLAIM_FILL_GRACE_BLOCKS = 5;
26
28
  declare const MAX_ACTIVE_CLAIMS = 3;
27
29
  declare const CLAIM_COOLDOWN_BLOCKS = 15;
28
30
  declare const CONF_TOKEN_FILL = 1000000;
@@ -36,6 +38,9 @@ declare const V18_HEIGHT = 40000;
36
38
  declare const NAME_FEE_SHORT_V18 = 670000000n;
37
39
  declare const NAME_FEE_V18 = 300000000n;
38
40
  declare const V19_HEIGHT = 36700;
41
+ declare const V20_HEIGHT = 38400;
42
+ declare const V21_HEIGHT = 42000;
43
+ declare const MAX_OFFER_EPOCHS = 168;
39
44
  declare const PKEY: RegExp;
40
45
  declare const PROFILE_MAX_KEYS = 16;
41
46
  declare const PROFILE_MAX_VALUE_BYTES = 256;
@@ -357,4 +362,4 @@ declare function resolve(events: ChainEvent[], tipHeight: number): CairnXState;
357
362
  * history.) Keys sort in ordinal (code-unit) order at every depth. */
358
363
  declare function canonicalState(s: CairnXState): string;
359
364
 
360
- 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_WINDOW_BLOCKS, 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_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, 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 };
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 };
package/dist/index.d.ts CHANGED
@@ -23,6 +23,8 @@ declare const SCORE_FILL = 100;
23
23
  declare const SCORE_CANCEL = 0;
24
24
  declare const SCORE_CLAIM = 50;
25
25
  declare const CLAIM_WINDOW_BLOCKS = 15;
26
+ declare const CLAIM_WINDOW_BLOCKS_V20 = 40;
27
+ declare const CLAIM_FILL_GRACE_BLOCKS = 5;
26
28
  declare const MAX_ACTIVE_CLAIMS = 3;
27
29
  declare const CLAIM_COOLDOWN_BLOCKS = 15;
28
30
  declare const CONF_TOKEN_FILL = 1000000;
@@ -36,6 +38,9 @@ declare const V18_HEIGHT = 40000;
36
38
  declare const NAME_FEE_SHORT_V18 = 670000000n;
37
39
  declare const NAME_FEE_V18 = 300000000n;
38
40
  declare const V19_HEIGHT = 36700;
41
+ declare const V20_HEIGHT = 38400;
42
+ declare const V21_HEIGHT = 42000;
43
+ declare const MAX_OFFER_EPOCHS = 168;
39
44
  declare const PKEY: RegExp;
40
45
  declare const PROFILE_MAX_KEYS = 16;
41
46
  declare const PROFILE_MAX_VALUE_BYTES = 256;
@@ -357,4 +362,4 @@ declare function resolve(events: ChainEvent[], tipHeight: number): CairnXState;
357
362
  * history.) Keys sort in ordinal (code-unit) order at every depth. */
358
363
  declare function canonicalState(s: CairnXState): string;
359
364
 
360
- 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_WINDOW_BLOCKS, 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_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, 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 };
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 };
package/dist/index.js CHANGED
@@ -26,6 +26,8 @@ var SCORE_FILL = 100;
26
26
  var SCORE_CANCEL = 0;
27
27
  var SCORE_CLAIM = 50;
28
28
  var CLAIM_WINDOW_BLOCKS = 15;
29
+ var CLAIM_WINDOW_BLOCKS_V20 = 40;
30
+ var CLAIM_FILL_GRACE_BLOCKS = 5;
29
31
  var MAX_ACTIVE_CLAIMS = 3;
30
32
  var CLAIM_COOLDOWN_BLOCKS = 15;
31
33
  var CONF_TOKEN_FILL = 1e6;
@@ -39,6 +41,9 @@ var V18_HEIGHT = 4e4;
39
41
  var NAME_FEE_SHORT_V18 = 670000000n;
40
42
  var NAME_FEE_V18 = 300000000n;
41
43
  var V19_HEIGHT = 36700;
44
+ var V20_HEIGHT = 38400;
45
+ var V21_HEIGHT = 42e3;
46
+ var MAX_OFFER_EPOCHS = 168;
42
47
  var PKEY = /^[a-z0-9](?:[a-z0-9.-]{0,30}[a-z0-9])?$/;
43
48
  var PROFILE_MAX_KEYS = 16;
44
49
  var PROFILE_MAX_VALUE_BYTES = 256;
@@ -336,16 +341,17 @@ function resolve(events, tipHeight) {
336
341
  b.available += amt;
337
342
  }
338
343
  };
344
+ const effExpiry = (e, height) => height >= V21_HEIGHT ? Math.min(e.expiresEpoch, epochOf(e.height) + MAX_OFFER_EPOCHS) : e.expiresEpoch;
339
345
  const sweepExpired = (height) => {
340
346
  const ep = epochOf(height);
341
347
  for (const o of offers.values()) {
342
- if (o.status === "open" && ep > o.expiresEpoch) {
348
+ if (o.status === "open" && ep > effExpiry(o, height)) {
343
349
  releaseGive(o);
344
350
  o.status = "expired";
345
351
  }
346
352
  }
347
353
  for (const b of bids.values()) {
348
- if (b.status === "open" && ep > b.expiresEpoch) b.status = "expired";
354
+ if (b.status === "open" && ep > effExpiry(b, height)) b.status = "expired";
349
355
  }
350
356
  };
351
357
  const V15_EPOCH = epochOf(V15_HEIGHT);
@@ -357,7 +363,9 @@ function resolve(events, tipHeight) {
357
363
  const b = bids.get(o.bid);
358
364
  if (b && b.status === "open" && b.bidder === buyer) b.status = "done";
359
365
  };
360
- const liveClaim = (o, height) => o.claimedBy !== void 0 && o.claimUntilHeight !== void 0 && height < o.claimUntilHeight;
366
+ const claimGrace = (o) => o.claimUntilHeight !== void 0 && o.claimUntilHeight - CLAIM_WINDOW_BLOCKS_V20 >= V20_HEIGHT ? CLAIM_FILL_GRACE_BLOCKS : 0;
367
+ 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;
361
369
  for (const ev of ordered) {
362
370
  if (ev.height < ACTIVATION_HEIGHT) continue;
363
371
  if (ev.height !== pendingBlock) {
@@ -578,6 +586,10 @@ function resolve(events, tipHeight) {
578
586
  note(ev, ev.id, "offer", false, "already expired at anchor");
579
587
  continue;
580
588
  }
589
+ if (ev.height >= V21_HEIGHT && ev.expiresEpoch - epochOf(ev.height) > MAX_OFFER_EPOCHS) {
590
+ note(ev, ev.id, "offer", false, "v2.1: offer duration exceeds the max");
591
+ continue;
592
+ }
581
593
  const give = rec.give;
582
594
  if (isNameGive(give)) {
583
595
  if (!v11) {
@@ -647,6 +659,10 @@ function resolve(events, tipHeight) {
647
659
  note(ev, ev.id, "bid", false, "already expired at anchor");
648
660
  continue;
649
661
  }
662
+ if (ev.height >= V21_HEIGHT && ev.expiresEpoch - epochOf(ev.height) > MAX_OFFER_EPOCHS) {
663
+ note(ev, ev.id, "bid", false, "v2.1: bid duration exceeds the max");
664
+ continue;
665
+ }
650
666
  bids.set(ev.id, {
651
667
  id: ev.id,
652
668
  bidder: who,
@@ -839,7 +855,7 @@ function resolve(events, tipHeight) {
839
855
  note(ev, ev.txid, "fill", false, "v1.3: open CSD-quoted fills disabled (offer must be taker-bound)");
840
856
  continue;
841
857
  }
842
- if (!(liveClaim(o, ev.height) && who === o.claimedBy)) {
858
+ if (!(claimHeld(o, ev.height) && who === o.claimedBy)) {
843
859
  note(ev, ev.txid, "fill", false, "v1.7: open offer \u2014 claim it first (no live claim by you)");
844
860
  continue;
845
861
  }
@@ -904,7 +920,7 @@ function resolve(events, tipHeight) {
904
920
  note(ev, ev.txid, "fill", false, "v1.3: open CSD-quoted fills disabled (offer must be taker-bound)");
905
921
  continue;
906
922
  }
907
- if (!(liveClaim(o, ev.height) && who === o.claimedBy)) {
923
+ if (!(claimHeld(o, ev.height) && who === o.claimedBy)) {
908
924
  note(ev, ev.txid, "fill", false, "v1.7: open offer \u2014 claim it first (no live claim by you)");
909
925
  continue;
910
926
  }
@@ -974,22 +990,22 @@ function resolve(events, tipHeight) {
974
990
  note(ev, ev.txid, "claim", false, "claims are for CSD-priced offers (token offers are no-op-safe)");
975
991
  continue;
976
992
  }
977
- if (liveClaim(o, ev.height)) {
978
- note(ev, ev.txid, "claim", false, "offer already claimed (window live)");
993
+ if (claimHeld(o, ev.height)) {
994
+ note(ev, ev.txid, "claim", false, "offer already claimed (hold live)");
979
995
  continue;
980
996
  }
981
- if (o.claimedBy === who && o.claimUntilHeight !== void 0 && ev.height < o.claimUntilHeight + CLAIM_COOLDOWN_BLOCKS) {
997
+ if (o.claimedBy === who && o.claimUntilHeight !== void 0 && ev.height < o.claimUntilHeight + claimGrace(o) + CLAIM_COOLDOWN_BLOCKS) {
982
998
  note(ev, ev.txid, "claim", false, "claim cooldown (you just held this offer)");
983
999
  continue;
984
1000
  }
985
1001
  let liveN = 0;
986
- for (const x of offers.values()) if (x.claimedBy === who && x.claimUntilHeight !== void 0 && ev.height < x.claimUntilHeight) liveN++;
1002
+ for (const x of offers.values()) if (x.claimedBy === who && claimHeld(x, ev.height)) liveN++;
987
1003
  if (liveN >= MAX_ACTIVE_CLAIMS) {
988
1004
  note(ev, ev.txid, "claim", false, `max ${MAX_ACTIVE_CLAIMS} live claims per address`);
989
1005
  continue;
990
1006
  }
991
1007
  o.claimedBy = who;
992
- o.claimUntilHeight = ev.height + CLAIM_WINDOW_BLOCKS;
1008
+ o.claimUntilHeight = ev.height + claimWindowAt(ev.height);
993
1009
  note(ev, ev.txid, "claim", true);
994
1010
  }
995
1011
  }
@@ -1050,7 +1066,9 @@ export {
1050
1066
  ADDR_RE,
1051
1067
  AMOUNT_RE,
1052
1068
  CLAIM_COOLDOWN_BLOCKS,
1069
+ CLAIM_FILL_GRACE_BLOCKS,
1053
1070
  CLAIM_WINDOW_BLOCKS,
1071
+ CLAIM_WINDOW_BLOCKS_V20,
1054
1072
  COMMIT_MAX_BLOCKS,
1055
1073
  CONF_TOKEN_FILL,
1056
1074
  DEPLOY_FEE,
@@ -1061,6 +1079,7 @@ export {
1061
1079
  HASH_RE,
1062
1080
  MAX_ACTIVE_CLAIMS,
1063
1081
  MAX_AMOUNT,
1082
+ MAX_OFFER_EPOCHS,
1064
1083
  MAX_RECORD_BYTES,
1065
1084
  NAME_FEE_SHORT_V18,
1066
1085
  NAME_FEE_V18,
@@ -1090,6 +1109,8 @@ export {
1090
1109
  V17_HEIGHT,
1091
1110
  V18_HEIGHT,
1092
1111
  V19_HEIGHT,
1112
+ V20_HEIGHT,
1113
+ V21_HEIGHT,
1093
1114
  bid,
1094
1115
  buildRecord,
1095
1116
  canonicalState,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@inversealtruism/cairnx-core",
3
- "version": "0.1.14",
3
+ "version": "0.1.16",
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",