@inversealtruism/cairnx-core 0.2.7 → 0.2.8
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/CHANGELOG.md +60 -0
- package/CONVENTION.md +259 -89
- package/README.md +20 -6
- package/dist/index.cjs +79 -11
- package/dist/index.d.cts +75 -1
- package/dist/index.d.ts +75 -1
- package/dist/index.js +75 -11
- package/package.json +1 -1
- package/test/vectors/cases-convention.json +2202 -0
- package/test/vectors/forward.json +16 -0
- package/test/vectors/moves.json +15 -0
package/dist/index.js
CHANGED
|
@@ -377,6 +377,7 @@ var fclaim = (r) => buildRecord({ v: 1, t: "fclaim", ...r });
|
|
|
377
377
|
function ptAmt(v) {
|
|
378
378
|
return typeof v === "string" && AMOUNT_RE.test(v) ? BigInt(v) : 0n;
|
|
379
379
|
}
|
|
380
|
+
var tokenMove = (leg, ticker, from, to, amount) => ({ leg, ticker, from, to, amount: amount.toString() });
|
|
380
381
|
var effExpiry = (e, height) => e.height >= V22_HEIGHT ? e.expiresEpoch : height >= V21_HEIGHT ? Math.min(e.expiresEpoch, epochOf(e.height) + MAX_OFFER_EPOCHS) : e.expiresEpoch;
|
|
381
382
|
var claimGrace = (o) => o.claimUntilHeight !== void 0 ? claimGraceOf(o.claimUntilHeight, o.claimTxid) : 0;
|
|
382
383
|
var claimHeld = (o, height) => o.claimedBy !== void 0 && o.claimUntilHeight !== void 0 && height < o.claimUntilHeight + claimGrace(o);
|
|
@@ -429,9 +430,13 @@ function createContext(store) {
|
|
|
429
430
|
bal(t, o.seller).locked -= amt;
|
|
430
431
|
bal(t, who).available += amt;
|
|
431
432
|
offerLock.delete(o.id);
|
|
433
|
+
return tokenMove("fill", t, o.seller, who, amt);
|
|
432
434
|
};
|
|
433
|
-
const entry = (e, id, kind, ok, code, why) =>
|
|
434
|
-
|
|
435
|
+
const entry = (e, id, kind, ok, code, why, moves) => {
|
|
436
|
+
const written = moves?.filter((m) => m.amount !== "0") ?? [];
|
|
437
|
+
log.push({ height: e.height, pos: e.pos, id, kind, ok, code, ...why ? { note: why } : {}, ...written.length ? { moves: written } : {} });
|
|
438
|
+
};
|
|
439
|
+
const applied = (e, id, kind, code, why, moves) => entry(e, id, kind, true, code, why, moves);
|
|
435
440
|
const refused = (e, id, kind, code, why) => entry(e, id, kind, false, code, why);
|
|
436
441
|
return {
|
|
437
442
|
tokens,
|
|
@@ -594,13 +599,17 @@ function applyTokenFill(c, ev, o, who) {
|
|
|
594
599
|
}
|
|
595
600
|
buyer.available -= amt + fee;
|
|
596
601
|
bal(o.want.ticker, o.want.payto).available += amt;
|
|
597
|
-
|
|
602
|
+
const moves = [tokenMove("sale", o.want.ticker, who, o.want.payto, amt)];
|
|
603
|
+
if (fee > 0n) {
|
|
604
|
+
bal(o.want.ticker, TREASURY_ADDR).available += fee;
|
|
605
|
+
moves.push(tokenMove("fee", o.want.ticker, who, TREASURY_ADDR, fee));
|
|
606
|
+
}
|
|
598
607
|
if (isNameGive(o.give)) deliverNameToBuyer(c, o.give.name, giveName, who, ev);
|
|
599
|
-
else releaseGiveLock(o, who, giveLock);
|
|
608
|
+
else moves.push(releaseGiveLock(o, who, giveLock));
|
|
600
609
|
setOfferStatus(o, "filled");
|
|
601
610
|
o.fill = { buyer: who, txid: ev.txid, height: ev.height, paid: amt.toString(), fee: fee.toString() };
|
|
602
611
|
markBidDone(o, who);
|
|
603
|
-
applied(ev, ev.txid, "fill", "FILL_APPLIED");
|
|
612
|
+
applied(ev, ev.txid, "fill", "FILL_APPLIED", void 0, moves);
|
|
604
613
|
}
|
|
605
614
|
function applyPartialFill(c, ev, o, who) {
|
|
606
615
|
const { offerLock, bal, applied, refused, setOfferStatus, markBidDone } = c;
|
|
@@ -650,6 +659,7 @@ function applyPartialFill(c, ev, o, who) {
|
|
|
650
659
|
}
|
|
651
660
|
bal(o.give.ticker, o.seller).locked -= out;
|
|
652
661
|
bal(o.give.ticker, who).available += out;
|
|
662
|
+
const moves = [tokenMove("fill", o.give.ticker, o.seller, who, out)];
|
|
653
663
|
offerLock.set(o.id, lock - out);
|
|
654
664
|
o.paid = newPaid.toString();
|
|
655
665
|
o.delivered = newDelivered.toString();
|
|
@@ -662,7 +672,7 @@ function applyPartialFill(c, ev, o, who) {
|
|
|
662
672
|
offerLock.delete(o.id);
|
|
663
673
|
markBidDone(o, who);
|
|
664
674
|
}
|
|
665
|
-
applied(ev, ev.txid, "fill", "FILL_PARTIAL", `partial ${x}/${want}
|
|
675
|
+
applied(ev, ev.txid, "fill", "FILL_PARTIAL", `partial ${x}/${want}`, moves);
|
|
666
676
|
}
|
|
667
677
|
function applyFill(c, ev, o, who) {
|
|
668
678
|
const { names, offerLock, applied, refused, setOfferStatus, markBidDone, releaseGiveLock } = c;
|
|
@@ -699,6 +709,7 @@ function applyFill(c, ev, o, who) {
|
|
|
699
709
|
return;
|
|
700
710
|
}
|
|
701
711
|
const paid = ptAmt(pt[o.want.payto]);
|
|
712
|
+
const moves = [];
|
|
702
713
|
if (isNameGive(o.give)) {
|
|
703
714
|
const n = names.get(o.give.name);
|
|
704
715
|
if (!n) {
|
|
@@ -712,13 +723,13 @@ function applyFill(c, ev, o, who) {
|
|
|
712
723
|
refused(ev, ev.txid, "fill", "INVARIANT_BROKEN", "offer lock missing");
|
|
713
724
|
return;
|
|
714
725
|
}
|
|
715
|
-
releaseGiveLock(o, who, amt);
|
|
726
|
+
moves.push(releaseGiveLock(o, who, amt));
|
|
716
727
|
}
|
|
717
728
|
c.feesPaid += fee;
|
|
718
729
|
setOfferStatus(o, "filled");
|
|
719
730
|
o.fill = { buyer: who, txid: ev.txid, height: ev.height, paid: paid.toString(), fee: fee.toString() };
|
|
720
731
|
markBidDone(o, who);
|
|
721
|
-
applied(ev, ev.txid, "fill", "FILL_APPLIED");
|
|
732
|
+
applied(ev, ev.txid, "fill", "FILL_APPLIED", void 0, moves);
|
|
722
733
|
}
|
|
723
734
|
function applyLegacyClaim(c, ev, o, who) {
|
|
724
735
|
const { applied, refused, store } = c;
|
|
@@ -1728,7 +1739,7 @@ function applyMint(c, ev, rec, who) {
|
|
|
1728
1739
|
}
|
|
1729
1740
|
tok.minted += credit;
|
|
1730
1741
|
bal(rec.ticker, who).available += credit;
|
|
1731
|
-
applied(ev, ev.id, "mint", "TOKEN_MINTED", credit.toString());
|
|
1742
|
+
applied(ev, ev.id, "mint", "TOKEN_MINTED", credit.toString(), [tokenMove("mint", rec.ticker, null, who, credit)]);
|
|
1732
1743
|
}
|
|
1733
1744
|
function applyTransfer(c, ev, rec, who) {
|
|
1734
1745
|
const { tokens, bal, applied, refused } = c;
|
|
@@ -1742,9 +1753,10 @@ function applyTransfer(c, ev, rec, who) {
|
|
|
1742
1753
|
refused(ev, ev.id, "transfer", "TOKEN_BALANCE_LOW", "insufficient available balance");
|
|
1743
1754
|
return;
|
|
1744
1755
|
}
|
|
1756
|
+
const to = rec.to.toLowerCase();
|
|
1745
1757
|
from.available -= amt;
|
|
1746
|
-
bal(rec.ticker,
|
|
1747
|
-
applied(ev, ev.id, "transfer", "TOKEN_TRANSFERRED");
|
|
1758
|
+
bal(rec.ticker, to).available += amt;
|
|
1759
|
+
applied(ev, ev.id, "transfer", "TOKEN_TRANSFERRED", void 0, [tokenMove("xfer", rec.ticker, who, to, amt)]);
|
|
1748
1760
|
}
|
|
1749
1761
|
function applyTmeta(c, ev, rec, who) {
|
|
1750
1762
|
const { tokens, applied, refused } = c;
|
|
@@ -2093,6 +2105,54 @@ function pickPrimaryName(names, a) {
|
|
|
2093
2105
|
return best ? best.name : null;
|
|
2094
2106
|
}
|
|
2095
2107
|
|
|
2108
|
+
// src/forward.ts
|
|
2109
|
+
function resolveNameIn(names, name) {
|
|
2110
|
+
if (!Object.hasOwn(names, name)) return null;
|
|
2111
|
+
const n = names[name];
|
|
2112
|
+
if (!n) return null;
|
|
2113
|
+
if (n.pending) return null;
|
|
2114
|
+
return { name, addr: n.addr ?? n.owner, via: n.addr ? "nset" : "owner", lapsed: n.expired === true, owner: n.owner };
|
|
2115
|
+
}
|
|
2116
|
+
function nameView(names, name) {
|
|
2117
|
+
if (typeof name !== "string" || !NAME_RE.test(name)) return null;
|
|
2118
|
+
const none = { owner: null, addr: null, profile: {}, paidThroughEpoch: null };
|
|
2119
|
+
if (RESERVED_NAMES.has(name)) return { name, state: "reserved", ...none };
|
|
2120
|
+
const n = Object.hasOwn(names, name) ? names[name] : void 0;
|
|
2121
|
+
if (!n) return { name, state: "free", ...none };
|
|
2122
|
+
const r = resolveNameIn(names, name);
|
|
2123
|
+
if (r === null) return { name, state: "pending", ...none, owner: n.owner };
|
|
2124
|
+
const paidThroughEpoch = n.paidThroughEpoch ?? null;
|
|
2125
|
+
if (r.lapsed) return { name, state: "lapsed", ...none, owner: n.owner, paidThroughEpoch };
|
|
2126
|
+
return { name, state: "held", owner: n.owner, addr: r.addr, profile: { ...n.profile }, paidThroughEpoch };
|
|
2127
|
+
}
|
|
2128
|
+
|
|
2129
|
+
// src/version.ts
|
|
2130
|
+
var CAIRNX_CORE_VERSION = "0.2.8";
|
|
2131
|
+
|
|
2132
|
+
// src/gates.ts
|
|
2133
|
+
var GATE_HEIGHTS = Object.freeze({
|
|
2134
|
+
ACTIVATION_HEIGHT,
|
|
2135
|
+
V11_HEIGHT,
|
|
2136
|
+
V12_HEIGHT,
|
|
2137
|
+
V13_HEIGHT,
|
|
2138
|
+
V14_HEIGHT,
|
|
2139
|
+
V15_HEIGHT,
|
|
2140
|
+
V16_HEIGHT,
|
|
2141
|
+
V17_HEIGHT,
|
|
2142
|
+
V18_HEIGHT,
|
|
2143
|
+
V19_HEIGHT,
|
|
2144
|
+
V20_HEIGHT,
|
|
2145
|
+
V21_HEIGHT,
|
|
2146
|
+
V22_HEIGHT,
|
|
2147
|
+
V23_HEIGHT,
|
|
2148
|
+
V24_HEIGHT,
|
|
2149
|
+
V25_HEIGHT,
|
|
2150
|
+
V26_HEIGHT,
|
|
2151
|
+
V27_HEIGHT,
|
|
2152
|
+
V28_HEIGHT,
|
|
2153
|
+
V29_HEIGHT
|
|
2154
|
+
});
|
|
2155
|
+
|
|
2096
2156
|
// src/verifyfill.ts
|
|
2097
2157
|
import { payloadHash as payloadHash2 } from "@inversealtruism/csd-codec";
|
|
2098
2158
|
var FCLAIM_MAX_HOLD_SPAN = EPOCH_LEN * (FCLAIM_MAX_EPOCH_AHEAD + 1) - 1;
|
|
@@ -2647,6 +2707,7 @@ export {
|
|
|
2647
2707
|
ADDR_RE,
|
|
2648
2708
|
AMOUNT_RE,
|
|
2649
2709
|
BID_KEYS,
|
|
2710
|
+
CAIRNX_CORE_VERSION,
|
|
2650
2711
|
CAIRNX_EVENT_RULE,
|
|
2651
2712
|
CAP_CODES,
|
|
2652
2713
|
CLAIM_ATTACKER_Q,
|
|
@@ -2674,6 +2735,7 @@ export {
|
|
|
2674
2735
|
FINALIZE_TIP_MARGIN,
|
|
2675
2736
|
FINAL_DEPTH,
|
|
2676
2737
|
GAP_NEEDED,
|
|
2738
|
+
GATE_HEIGHTS,
|
|
2677
2739
|
HALVING_INTERVAL,
|
|
2678
2740
|
HASH_RE,
|
|
2679
2741
|
INITIAL_REWARD2 as INITIAL_REWARD,
|
|
@@ -2792,6 +2854,7 @@ export {
|
|
|
2792
2854
|
nameRegFee,
|
|
2793
2855
|
nameRenew,
|
|
2794
2856
|
nameSet,
|
|
2857
|
+
nameView,
|
|
2795
2858
|
nameXfer,
|
|
2796
2859
|
offer,
|
|
2797
2860
|
offerCancelAll,
|
|
@@ -2811,6 +2874,7 @@ export {
|
|
|
2811
2874
|
requiredClaimDepth,
|
|
2812
2875
|
requiredFillOutputs,
|
|
2813
2876
|
resolve,
|
|
2877
|
+
resolveNameIn,
|
|
2814
2878
|
stateHash,
|
|
2815
2879
|
tokenMeta,
|
|
2816
2880
|
tradeFee,
|