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