@inversealtruism/cairnx-core 0.2.1 → 0.2.3
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 +50 -0
- package/README.md +1 -1
- package/dist/index.cjs +69 -35
- package/dist/index.d.cts +61 -4
- package/dist/index.d.ts +61 -4
- package/dist/index.js +64 -35
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,55 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 0.2.3
|
|
4
|
+
|
|
5
|
+
- `provenOfferRefusal` refuses the two record-only activation gates it lacked. An offer anchored below
|
|
6
|
+
`ACTIVATION_HEIGHT` (29,860), where `resolve()` skips every event, is refused with "anchored before CairnX
|
|
7
|
+
activation (block 29860)"; a name offer anchored below `V11_HEIGHT` (29,960) with the resolver's own note "name
|
|
8
|
+
offers need v1.1". Before, a canonical name offer proven at 29,959 returned no refusal. Correction to 0.2.2: its
|
|
9
|
+
entry said `provenOfferRefusal` returns the resolver's note "for every rule that needs no chain state"; it covered
|
|
10
|
+
only the rules in `offerEnvelopeRefusal`, without these two.
|
|
11
|
+
- The name-offer v1.1 rule moved from `applyOffer` into `offerEnvelopeRefusal`, after the rules already there, which
|
|
12
|
+
is where `applyOffer` checked it. New root export `beforeActivation(height)`, which `resolve()` reads to skip
|
|
13
|
+
events below `ACTIVATION_HEIGHT` and `provenOfferRefusal` reads to refuse them.
|
|
14
|
+
- `resolve()` and canonical state are byte-identical to 0.2.2.
|
|
15
|
+
|
|
16
|
+
## 0.2.2
|
|
17
|
+
|
|
18
|
+
- `verifyFillSpv` fails closed when any id `offerEventIds` returns cannot be proven: `provenEvent` throws,
|
|
19
|
+
returns null, or returns an event under another id. It used to drop that event from the grant replay, so a
|
|
20
|
+
seller cancel whose block read failed replayed the offer as open. New refusal text: "an event on this offer
|
|
21
|
+
could not be merkle-proven (<id>) - refusing, the replay would miss it"; the offer and fclaim keep their
|
|
22
|
+
existing texts. The site's and the wallet's io return only ids they proved, so their honest fills do not move.
|
|
23
|
+
- New root export `countOtherHoldsAtGrant(candidates, target, me, closed?)`: the buyer's live holds on other
|
|
24
|
+
offers at an fclaim's grant, the `myLiveHoldsAtGrant` count for `verifyFillSpv`. It counts only fclaims applied
|
|
25
|
+
before the target (height, then position in the block), distinct offers, holds live at the grant height, and
|
|
26
|
+
skips the `closed` set. The site and the wallet counted later fclaims too, so a buyer's fourth reservation
|
|
27
|
+
(denied on the cap) made every earlier granted hold unfillable. An earlier fclaim the resolver denied is still
|
|
28
|
+
counted (an over-count, which only refuses). It returns `HoldCount` (`{ ok: true, count }` or
|
|
29
|
+
`{ ok: false, reason }`, which a caller treats as unsafe). Its domain is grants at or above
|
|
30
|
+
`LEGACY_HOLD_SUNSET_HEIGHT` (exported, 60,044: the last legacy claim at V28 - 1 plus its window and grace);
|
|
31
|
+
below it a legacy SCORE_CLAIM hold can still count against the cap and the counter does not read those, so it
|
|
32
|
+
refuses ("this reservation was granted at <h>, before block 60044, while claims made before V28 could still
|
|
33
|
+
count against the cap; it cannot be checked here").
|
|
34
|
+
- `finalizeWinnerCheck` refuses a supplied `tip` that is not a non-negative safe integer ("the chain tip given
|
|
35
|
+
(<tip>) is not a block height, so the finalize window cannot be checked"). A NaN, Infinity or fractional tip
|
|
36
|
+
used to skip or pass both window comparisons and return safe. An omitted or null tip keeps the winner-only check.
|
|
37
|
+
- New root export `provenOfferRefusal(rec, { domain, height, expiresEpoch, seller })`: the admission check for a
|
|
38
|
+
merkle-proven offer Propose. It refuses a domain other than `cairnx:v1` ("not a cairnx:v1 Propose (domain
|
|
39
|
+
"<domain>")") and then returns the resolver's own creation note for every rule that needs no chain state
|
|
40
|
+
(v1.2 shape before activation, the V13 to V17 open CSD offer ban, a treasury payee, an expiry outside the safe
|
|
41
|
+
integer range or already past at the anchor, the V21 to V22 duration cap). `applyOffer` now reads those rules
|
|
42
|
+
from the same function (`offerEnvelopeRefusal` in `src/resolve/market.ts`), in the same order with the same
|
|
43
|
+
notes. The give's backing is chain state and is not checked.
|
|
44
|
+
- `bindOfferTerms`'s wantType leg (on by default) also binds a token want's price: for a proven token want the
|
|
45
|
+
served `want.ticker` and `want.amount` must equal the record's, verbatim. `provenOfferTerms` carries them as
|
|
46
|
+
`wantTicker` and `wantAmount`. Before, a token-priced offer served with another ticker or amount passed, and
|
|
47
|
+
each caller (the site, cairn-sdk `preverifyOffer`) compared the price itself. Callers opting out with
|
|
48
|
+
`{ give: false, wantType: false }` keep the earlier verdict.
|
|
49
|
+
- New root export `MAX_TOKEN_DECIMALS` (8), the bound `parseRecord` applies to a deploy's `decimals`; the parser
|
|
50
|
+
reads it, so a consumer validating a served token's decimals uses the same number.
|
|
51
|
+
- `resolve()` and canonical state are byte-identical to 0.2.1.
|
|
52
|
+
|
|
3
53
|
## 0.2.1
|
|
4
54
|
|
|
5
55
|
- Internal split, no behaviour change: `src/resolve.ts` keeps the replay loop and dispatches each record to
|
package/README.md
CHANGED
|
@@ -316,7 +316,7 @@ is a silent chain fork, the exact bug class the shared-core de-dup (`cairn/docs/
|
|
|
316
316
|
**To make a consensus change:** edit `src/` here **and** `conformance/cairnx_ref.py`; add a height-gated
|
|
317
317
|
`V*_HEIGHT` (never reinterpret history) + a vector; `pnpm build && pnpm test && pnpm test:crosslang`
|
|
318
318
|
(all green); **bump the version** (`node scripts/check-lockstep.mjs` fails until you do: it compares the
|
|
319
|
-
published tarball of the current version with this build); `
|
|
319
|
+
published tarball of the current version with this build); the npm window (`node scripts/npm-window.mjs`); **rebuild + recommit
|
|
320
320
|
the two vendored bundles**; re-pin every consumer and deploy them **between** activation heights, not
|
|
321
321
|
across one (below the gate the output is byte-identical, so the rollout is fork-free).
|
|
322
322
|
|
package/dist/index.cjs
CHANGED
|
@@ -49,12 +49,14 @@ __export(index_exports, {
|
|
|
49
49
|
HALVING_INTERVAL: () => import_csd_codec5.HALVING_INTERVAL,
|
|
50
50
|
HASH_RE: () => HASH_RE,
|
|
51
51
|
INITIAL_REWARD: () => import_csd_codec5.INITIAL_REWARD,
|
|
52
|
+
LEGACY_HOLD_SUNSET_HEIGHT: () => LEGACY_HOLD_SUNSET_HEIGHT,
|
|
52
53
|
MAX_ACTIVE_CLAIMS: () => MAX_ACTIVE_CLAIMS,
|
|
53
54
|
MAX_AMOUNT: () => MAX_AMOUNT,
|
|
54
55
|
MAX_OFFER_EPOCHS: () => MAX_OFFER_EPOCHS,
|
|
55
56
|
MAX_PENDING_REG: () => MAX_PENDING_REG,
|
|
56
57
|
MAX_RECORD_BYTES: () => MAX_RECORD_BYTES,
|
|
57
58
|
MAX_SCAN: () => MAX_SCAN,
|
|
59
|
+
MAX_TOKEN_DECIMALS: () => MAX_TOKEN_DECIMALS,
|
|
58
60
|
MINT_KEYS: () => MINT_KEYS,
|
|
59
61
|
MIN_FEE_ATTEST: () => import_csd_codec5.MIN_FEE_ATTEST,
|
|
60
62
|
MIN_FEE_PROPOSE: () => import_csd_codec5.MIN_FEE_PROPOSE,
|
|
@@ -109,6 +111,7 @@ __export(index_exports, {
|
|
|
109
111
|
V28_HEIGHT: () => V28_HEIGHT,
|
|
110
112
|
V29_HEIGHT: () => V29_HEIGHT,
|
|
111
113
|
ZERO_ADDR: () => ZERO_ADDR,
|
|
114
|
+
beforeActivation: () => beforeActivation,
|
|
112
115
|
bid: () => bid,
|
|
113
116
|
bindOfferTerms: () => bindOfferTerms,
|
|
114
117
|
bindProvenOffer: () => bindProvenOffer,
|
|
@@ -121,6 +124,7 @@ __export(index_exports, {
|
|
|
121
124
|
claimGraceOf: () => claimGraceOf,
|
|
122
125
|
claimWindowAt: () => claimWindowAt,
|
|
123
126
|
claimWindowOf: () => claimWindowOf,
|
|
127
|
+
countOtherHoldsAtGrant: () => countOtherHoldsAtGrant,
|
|
124
128
|
deploy: () => deploy,
|
|
125
129
|
epochOf: () => import_csd_codec.epochOf,
|
|
126
130
|
expiredClaimFee: () => expiredClaimFee,
|
|
@@ -160,6 +164,7 @@ __export(index_exports, {
|
|
|
160
164
|
pickPrimaryName: () => pickPrimaryName,
|
|
161
165
|
previewFill: () => previewFill,
|
|
162
166
|
primaryRankBefore: () => primaryRankBefore,
|
|
167
|
+
provenOfferRefusal: () => provenOfferRefusal,
|
|
163
168
|
provenOfferTerms: () => provenOfferTerms,
|
|
164
169
|
ptAmt: () => ptAmt,
|
|
165
170
|
replayLiveHold: () => replayLiveHold,
|
|
@@ -178,6 +183,7 @@ module.exports = __toCommonJS(index_exports);
|
|
|
178
183
|
var import_csd_codec = require("@inversealtruism/csd-codec");
|
|
179
184
|
var DOMAIN = "cairnx:v1";
|
|
180
185
|
var ACTIVATION_HEIGHT = 29860;
|
|
186
|
+
var beforeActivation = (height) => height < ACTIVATION_HEIGHT;
|
|
181
187
|
var V11_HEIGHT = 29960;
|
|
182
188
|
var V12_HEIGHT = 30300;
|
|
183
189
|
var V13_HEIGHT = 31100;
|
|
@@ -198,6 +204,7 @@ function expiredClaimFee(name, epochsPastGraceEnd, height) {
|
|
|
198
204
|
}
|
|
199
205
|
var MAX_RECORD_BYTES = import_csd_codec.MAX_URI_BYTES;
|
|
200
206
|
var MAX_AMOUNT = (1n << 96n) - 1n;
|
|
207
|
+
var MAX_TOKEN_DECIMALS = 8;
|
|
201
208
|
var SCORE_FILL = 100;
|
|
202
209
|
var SCORE_CANCEL = 0;
|
|
203
210
|
var SCORE_CLAIM = 50;
|
|
@@ -346,7 +353,7 @@ function parseRecord(uri, payloadHashHex) {
|
|
|
346
353
|
if (!onlyKeys(r, DEPLOY_KEYS)) return null;
|
|
347
354
|
if (!isTicker(r.ticker)) return null;
|
|
348
355
|
if (r.name !== void 0 && (typeof r.name !== "string" || r.name.length > 32)) return null;
|
|
349
|
-
if (typeof r.decimals !== "number" || !Number.isInteger(r.decimals) || r.decimals < 0 || r.decimals >
|
|
356
|
+
if (typeof r.decimals !== "number" || !Number.isInteger(r.decimals) || r.decimals < 0 || r.decimals > MAX_TOKEN_DECIMALS) return null;
|
|
350
357
|
if (parseAmount(r.supply) === null) return null;
|
|
351
358
|
if (r.mint !== "open" && r.mint !== "issuer") return null;
|
|
352
359
|
if (r.mint === "open" && parseAmount(r.mintLimit) === null) return null;
|
|
@@ -1251,41 +1258,17 @@ function applyNrenew(c, ev, rec, who, feeToTreasury) {
|
|
|
1251
1258
|
function applyOffer(c, ev, rec, who) {
|
|
1252
1259
|
const { tokens, names, offers, offerLock, openOffers, bids, bal, note } = c;
|
|
1253
1260
|
const v11 = ev.height >= V11_HEIGHT;
|
|
1254
|
-
const v12 = ev.height >= V12_HEIGHT;
|
|
1255
1261
|
const v15 = ev.height >= V15_HEIGHT;
|
|
1256
1262
|
const v16 = ev.height >= V16_HEIGHT;
|
|
1257
1263
|
const wantIsToken = isTokenWant(rec.want);
|
|
1258
|
-
|
|
1259
|
-
|
|
1260
|
-
|
|
1261
|
-
}
|
|
1262
|
-
if (ev.height >= V13_HEIGHT && ev.height < V17_HEIGHT && !wantIsToken && rec.taker === void 0) {
|
|
1263
|
-
note(ev, ev.id, "offer", false, "v1.3: CSD-priced offers must be taker-bound (use bid/RFQ)");
|
|
1264
|
+
const refusal = offerEnvelopeRefusal(rec, who, ev.height, ev.expiresEpoch);
|
|
1265
|
+
if (refusal !== null) {
|
|
1266
|
+
note(ev, ev.id, "offer", false, refusal);
|
|
1264
1267
|
return;
|
|
1265
1268
|
}
|
|
1266
1269
|
const payto = (rec.want.payto ?? who).toLowerCase();
|
|
1267
|
-
if (payto === TREASURY_ADDR) {
|
|
1268
|
-
note(ev, ev.id, "offer", false, "payto cannot be the protocol treasury");
|
|
1269
|
-
return;
|
|
1270
|
-
}
|
|
1271
|
-
if (!Number.isSafeInteger(ev.expiresEpoch)) {
|
|
1272
|
-
note(ev, ev.id, "offer", false, "expiresEpoch out of safe-integer range");
|
|
1273
|
-
return;
|
|
1274
|
-
}
|
|
1275
|
-
if ((0, import_csd_codec.epochOf)(ev.height) > ev.expiresEpoch) {
|
|
1276
|
-
note(ev, ev.id, "offer", false, "already expired at anchor");
|
|
1277
|
-
return;
|
|
1278
|
-
}
|
|
1279
|
-
if (ev.height >= V21_HEIGHT && ev.height < V22_HEIGHT && ev.expiresEpoch - (0, import_csd_codec.epochOf)(ev.height) > MAX_OFFER_EPOCHS) {
|
|
1280
|
-
note(ev, ev.id, "offer", false, "v2.1: offer duration exceeds the max");
|
|
1281
|
-
return;
|
|
1282
|
-
}
|
|
1283
1270
|
const give = rec.give;
|
|
1284
1271
|
if (isNameGive(give)) {
|
|
1285
|
-
if (!v11) {
|
|
1286
|
-
note(ev, ev.id, "offer", false, "name offers need v1.1");
|
|
1287
|
-
return;
|
|
1288
|
-
}
|
|
1289
1272
|
const n = names.get(give.name);
|
|
1290
1273
|
if (!n || n.owner !== who) {
|
|
1291
1274
|
note(ev, ev.id, "offer", false, "you don't own this name");
|
|
@@ -1473,6 +1456,17 @@ function applyFclaim(c, ev, rec, who) {
|
|
|
1473
1456
|
fclaims.set(ev.id, { offer: rec.offer, proposer: who, expiresEpoch: E, height: ev.height, granted: true });
|
|
1474
1457
|
note(ev, ev.id, "fclaim", true);
|
|
1475
1458
|
}
|
|
1459
|
+
function offerEnvelopeRefusal(rec, who, height, expiresEpoch) {
|
|
1460
|
+
const wantIsToken = isTokenWant(rec.want);
|
|
1461
|
+
if ((wantIsToken || rec.min !== void 0 || rec.bid !== void 0) && height < V12_HEIGHT) return "v1.2 offer shape before activation";
|
|
1462
|
+
if (height >= V13_HEIGHT && height < V17_HEIGHT && !wantIsToken && rec.taker === void 0) return "v1.3: CSD-priced offers must be taker-bound (use bid/RFQ)";
|
|
1463
|
+
if ((rec.want.payto ?? who).toLowerCase() === TREASURY_ADDR) return "payto cannot be the protocol treasury";
|
|
1464
|
+
if (!Number.isSafeInteger(expiresEpoch)) return "expiresEpoch out of safe-integer range";
|
|
1465
|
+
if ((0, import_csd_codec.epochOf)(height) > expiresEpoch) return "already expired at anchor";
|
|
1466
|
+
if (height >= V21_HEIGHT && height < V22_HEIGHT && expiresEpoch - (0, import_csd_codec.epochOf)(height) > MAX_OFFER_EPOCHS) return "v2.1: offer duration exceeds the max";
|
|
1467
|
+
if (isNameGive(rec.give) && height < V11_HEIGHT) return "name offers need v1.1";
|
|
1468
|
+
return null;
|
|
1469
|
+
}
|
|
1476
1470
|
|
|
1477
1471
|
// src/resolve/tokens.ts
|
|
1478
1472
|
function applyDeploy(c, ev, rec, who, feeToTreasury) {
|
|
@@ -1594,7 +1588,7 @@ function resolve(events, tipHeight) {
|
|
|
1594
1588
|
c.pendingCancels = [];
|
|
1595
1589
|
};
|
|
1596
1590
|
for (const ev of applied) {
|
|
1597
|
-
if (ev.height
|
|
1591
|
+
if (beforeActivation(ev.height)) continue;
|
|
1598
1592
|
if (ev.height !== pendingBlock) {
|
|
1599
1593
|
applyPendingCancels();
|
|
1600
1594
|
pendingBlock = ev.height;
|
|
@@ -1859,8 +1853,9 @@ function finalizeWinnerCheck(nameState, me, commitHeight, tip) {
|
|
|
1859
1853
|
if (nameState.pending !== true) return { safe: false, reason: "already registered to you \u2014 no second finalize fee is needed" };
|
|
1860
1854
|
if (Number(nameState.effectiveHeight) !== Number(commitHeight))
|
|
1861
1855
|
return { safe: false, reason: "your reservation was displaced (effective height changed) \u2014 a finalize now would burn the fee" };
|
|
1862
|
-
if (tip !== void 0 && tip !== null
|
|
1863
|
-
|
|
1856
|
+
if (tip !== void 0 && tip !== null) {
|
|
1857
|
+
if (!Number.isSafeInteger(tip) || tip < 0) return { safe: false, reason: `the chain tip given (${String(tip)}) is not a block height, so the finalize window cannot be checked` };
|
|
1858
|
+
const t = tip;
|
|
1864
1859
|
const eff = Number(nameState.effectiveHeight);
|
|
1865
1860
|
const freezeEnd = eff + REG_COMMIT_MAX_BLOCKS;
|
|
1866
1861
|
const closeAt = eff + REG_COMMIT_MAX_BLOCKS + REG_FINALIZE_GRACE_BLOCKS - FINALIZE_TIP_MARGIN;
|
|
@@ -1922,15 +1917,17 @@ async function verifyFillSpv(offerId, fclaimTxid, me, io, opts) {
|
|
|
1922
1917
|
return no("could not enumerate the offer's events");
|
|
1923
1918
|
}
|
|
1924
1919
|
const want = /* @__PURE__ */ new Set([offerId.toLowerCase(), fclaimTxid.toLowerCase(), ...(hintIds ?? []).map((x) => String(x).toLowerCase())]);
|
|
1920
|
+
const unproven = (wid) => wid === offerId.toLowerCase() ? no("offer not merkle-proven (no PoW-verified offer Propose)") : wid === fclaimTxid.toLowerCase() ? no("fclaim not merkle-proven (no PoW-verified fclaim Propose)") : no(`an event on this offer could not be merkle-proven (${wid}) - refusing, the replay would miss it`);
|
|
1925
1921
|
const proven = [];
|
|
1926
1922
|
for (const wid of want) {
|
|
1927
1923
|
let ev;
|
|
1928
1924
|
try {
|
|
1929
1925
|
ev = await io.provenEvent(wid);
|
|
1930
1926
|
} catch {
|
|
1931
|
-
|
|
1927
|
+
return unproven(wid);
|
|
1932
1928
|
}
|
|
1933
|
-
if (ev
|
|
1929
|
+
if (!ev || (ev.kind === "propose" ? ev.id : ev.txid).toLowerCase() !== wid) return unproven(wid);
|
|
1930
|
+
proven.push(ev);
|
|
1934
1931
|
}
|
|
1935
1932
|
const isProp = (e) => e.kind === "propose";
|
|
1936
1933
|
const offerEv = proven.find((e) => isProp(e) && e.id.toLowerCase() === offerId.toLowerCase());
|
|
@@ -2009,7 +2006,9 @@ function provenOfferTerms(offerRec, provenHeight) {
|
|
|
2009
2006
|
giveTicker: g.ticker !== void 0 ? String(g.ticker) : void 0,
|
|
2010
2007
|
giveAmount: g.amount !== void 0 ? String(g.amount) : void 0,
|
|
2011
2008
|
giveName: g.name !== void 0 ? String(g.name) : void 0,
|
|
2012
|
-
wantType: isTokenWant(offerRec.want) ? "token" : "csd"
|
|
2009
|
+
wantType: isTokenWant(offerRec.want) ? "token" : "csd",
|
|
2010
|
+
wantTicker: isTokenWant(offerRec.want) ? String(w.ticker) : void 0,
|
|
2011
|
+
wantAmount: isTokenWant(offerRec.want) ? String(w.amount) : void 0
|
|
2013
2012
|
};
|
|
2014
2013
|
}
|
|
2015
2014
|
function bindOfferTerms(servedOffer, t, opts) {
|
|
@@ -2024,7 +2023,8 @@ function bindOfferTerms(servedOffer, t, opts) {
|
|
|
2024
2023
|
if ((om !== void 0 && om !== null) !== (t.min !== void 0)) return true;
|
|
2025
2024
|
if (t.min !== void 0 && String(om) !== t.min) return true;
|
|
2026
2025
|
if (opts?.wantType !== false) {
|
|
2027
|
-
if (t.wantType === void 0
|
|
2026
|
+
if (t.wantType === void 0) return true;
|
|
2027
|
+
if (t.wantType === "token" ? String(o?.want?.ticker) !== t.wantTicker || String(o?.want?.amount) !== t.wantAmount : typeof o?.want?.ticker === "string") return true;
|
|
2028
2028
|
}
|
|
2029
2029
|
if (opts?.give !== false) {
|
|
2030
2030
|
const g = o?.give;
|
|
@@ -2098,6 +2098,35 @@ function myProvenFillClosedOffer(fill, fclaim2, offerEv, me, grantHeight) {
|
|
|
2098
2098
|
return need.every((leg) => ptAmt(fill.paidTo?.[lc(leg.to)]) >= leg.value);
|
|
2099
2099
|
}
|
|
2100
2100
|
|
|
2101
|
+
// src/holdcount.ts
|
|
2102
|
+
var lastLegacyClaimEnd = V28_HEIGHT - 1 + claimWindowAt(V28_HEIGHT - 1);
|
|
2103
|
+
var LEGACY_HOLD_SUNSET_HEIGHT = lastLegacyClaimEnd + claimGraceOf(lastLegacyClaimEnd);
|
|
2104
|
+
function countOtherHoldsAtGrant(candidates, target, me, closed = /* @__PURE__ */ new Set()) {
|
|
2105
|
+
if (!(Number.isSafeInteger(target.height) && target.height >= LEGACY_HOLD_SUNSET_HEIGHT))
|
|
2106
|
+
return { ok: false, reason: `this reservation was granted at ${target.height}, before block ${LEGACY_HOLD_SUNSET_HEIGHT}, while claims made before V28 could still count against the cap; it cannot be checked here` };
|
|
2107
|
+
const meL = String(me).toLowerCase(), tid = String(target.id).toLowerCase(), toffer = String(target.offer).toLowerCase();
|
|
2108
|
+
const offers = /* @__PURE__ */ new Set();
|
|
2109
|
+
for (const c of candidates) {
|
|
2110
|
+
const cid = String(c.id).toLowerCase();
|
|
2111
|
+
if (cid === tid || closed.has(cid) || String(c.proposer).toLowerCase() !== meL) continue;
|
|
2112
|
+
if (!(c.height < target.height || c.height === target.height && c.pos < target.pos)) continue;
|
|
2113
|
+
if (!(fclaimHoldEnd(Number(c.expiresEpoch)) >= target.height)) continue;
|
|
2114
|
+
const rec = parseRecord(String(c.uri), String(c.payloadHash));
|
|
2115
|
+
if (!rec || rec.t !== "fclaim") continue;
|
|
2116
|
+
const offer2 = String(rec.offer).toLowerCase();
|
|
2117
|
+
if (offer2 !== toffer) offers.add(offer2);
|
|
2118
|
+
}
|
|
2119
|
+
return { ok: true, count: offers.size };
|
|
2120
|
+
}
|
|
2121
|
+
|
|
2122
|
+
// src/admission.ts
|
|
2123
|
+
function provenOfferRefusal(rec, tx) {
|
|
2124
|
+
if (tx.domain !== DOMAIN) return `not a ${DOMAIN} Propose (domain ${JSON.stringify(String(tx.domain))})`;
|
|
2125
|
+
if (beforeActivation(tx.height)) return `anchored before CairnX activation (block ${ACTIVATION_HEIGHT})`;
|
|
2126
|
+
const ee = typeof tx.expiresEpoch === "bigint" ? Number(tx.expiresEpoch) : tx.expiresEpoch;
|
|
2127
|
+
return offerEnvelopeRefusal(rec, String(tx.seller).toLowerCase(), tx.height, ee);
|
|
2128
|
+
}
|
|
2129
|
+
|
|
2101
2130
|
// src/index.ts
|
|
2102
2131
|
var import_csd_codec5 = require("@inversealtruism/csd-codec");
|
|
2103
2132
|
// Annotate the CommonJS export names for ESM import in node:
|
|
@@ -2131,12 +2160,14 @@ var import_csd_codec5 = require("@inversealtruism/csd-codec");
|
|
|
2131
2160
|
HALVING_INTERVAL,
|
|
2132
2161
|
HASH_RE,
|
|
2133
2162
|
INITIAL_REWARD,
|
|
2163
|
+
LEGACY_HOLD_SUNSET_HEIGHT,
|
|
2134
2164
|
MAX_ACTIVE_CLAIMS,
|
|
2135
2165
|
MAX_AMOUNT,
|
|
2136
2166
|
MAX_OFFER_EPOCHS,
|
|
2137
2167
|
MAX_PENDING_REG,
|
|
2138
2168
|
MAX_RECORD_BYTES,
|
|
2139
2169
|
MAX_SCAN,
|
|
2170
|
+
MAX_TOKEN_DECIMALS,
|
|
2140
2171
|
MINT_KEYS,
|
|
2141
2172
|
MIN_FEE_ATTEST,
|
|
2142
2173
|
MIN_FEE_PROPOSE,
|
|
@@ -2191,6 +2222,7 @@ var import_csd_codec5 = require("@inversealtruism/csd-codec");
|
|
|
2191
2222
|
V28_HEIGHT,
|
|
2192
2223
|
V29_HEIGHT,
|
|
2193
2224
|
ZERO_ADDR,
|
|
2225
|
+
beforeActivation,
|
|
2194
2226
|
bid,
|
|
2195
2227
|
bindOfferTerms,
|
|
2196
2228
|
bindProvenOffer,
|
|
@@ -2203,6 +2235,7 @@ var import_csd_codec5 = require("@inversealtruism/csd-codec");
|
|
|
2203
2235
|
claimGraceOf,
|
|
2204
2236
|
claimWindowAt,
|
|
2205
2237
|
claimWindowOf,
|
|
2238
|
+
countOtherHoldsAtGrant,
|
|
2206
2239
|
deploy,
|
|
2207
2240
|
epochOf,
|
|
2208
2241
|
expiredClaimFee,
|
|
@@ -2242,6 +2275,7 @@ var import_csd_codec5 = require("@inversealtruism/csd-codec");
|
|
|
2242
2275
|
pickPrimaryName,
|
|
2243
2276
|
previewFill,
|
|
2244
2277
|
primaryRankBefore,
|
|
2278
|
+
provenOfferRefusal,
|
|
2245
2279
|
provenOfferTerms,
|
|
2246
2280
|
ptAmt,
|
|
2247
2281
|
replayLiveHold,
|
package/dist/index.d.cts
CHANGED
|
@@ -2,6 +2,8 @@ export { EPOCH_LEN, HALVING_INTERVAL, INITIAL_REWARD, MIN_FEE_ATTEST, MIN_FEE_PR
|
|
|
2
2
|
|
|
3
3
|
declare const DOMAIN = "cairnx:v1";
|
|
4
4
|
declare const ACTIVATION_HEIGHT = 29860;
|
|
5
|
+
/** True below ACTIVATION_HEIGHT, where resolve() skips every event without a note. */
|
|
6
|
+
declare const beforeActivation: (height: number) => boolean;
|
|
5
7
|
declare const V11_HEIGHT = 29960;
|
|
6
8
|
declare const V12_HEIGHT = 30300;
|
|
7
9
|
declare const V13_HEIGHT = 31100;
|
|
@@ -19,6 +21,8 @@ declare const NAME_PREMIUM_DECAY_EPOCHS = 720;
|
|
|
19
21
|
declare function expiredClaimFee(name: string, epochsPastGraceEnd: number, height: number): bigint;
|
|
20
22
|
declare const MAX_RECORD_BYTES = 512;
|
|
21
23
|
declare const MAX_AMOUNT: bigint;
|
|
24
|
+
/** The most decimals a token deploy may declare (parseRecord refuses a deploy above it). */
|
|
25
|
+
declare const MAX_TOKEN_DECIMALS = 8;
|
|
22
26
|
declare const SCORE_FILL = 100;
|
|
23
27
|
declare const SCORE_CANCEL = 0;
|
|
24
28
|
declare const SCORE_CLAIM = 50;
|
|
@@ -635,7 +639,8 @@ declare function fillEndorsement(offer: OfferState, me: string, pay: bigint | st
|
|
|
635
639
|
* mining outside the window (too early: rejected as unfrozen; too late: past the deadline — either way the
|
|
636
640
|
* fee burns). The window is derived purely from `eff` (never the resolver's `finalizeBy`), so a lying
|
|
637
641
|
* `finalizeBy` cannot widen it — but per the trust scope above, a lying `eff` still can for a caller that
|
|
638
|
-
* does not supply an independent `commitHeight`. `tip` is optional; without it the winner-only path runs.
|
|
642
|
+
* does not supply an independent `commitHeight`. `tip` is optional; without it the winner-only path runs. A
|
|
643
|
+
* supplied `tip` that is not a non-negative safe integer is refused. */
|
|
639
644
|
declare function finalizeWinnerCheck(nameState: NameState | null | undefined, me: string, commitHeight: number, tip?: number | null): {
|
|
640
645
|
safe: boolean;
|
|
641
646
|
reason: string;
|
|
@@ -685,7 +690,7 @@ interface FillVerdict {
|
|
|
685
690
|
* not-mine hold, a below-depth signing, a zero-delivery fill, a stranded past-deadline broadcast).
|
|
686
691
|
*
|
|
687
692
|
* `opts.myLiveHoldsAtGrant` (REQUIRED) is the buyer's count of OTHER live fclaim/legacy holds at the moment
|
|
688
|
-
* THIS fclaim was granted, asserted by the authoring client (
|
|
693
|
+
* THIS fclaim was granted, asserted by the authoring client (countOtherHoldsAtGrant computes it). The lane-scoped
|
|
689
694
|
* replay cannot see the buyer's other-offer holds, and MAX_ACTIVE_CLAIMS is the one grant clause counted
|
|
690
695
|
* across offers, so without this the surface would false-accept a cap-denied fclaim. `opts.pay` overrides the
|
|
691
696
|
* payment (base units to want.payto) for a PARTIAL tail-fill; defaults to the offer's full want.value.
|
|
@@ -718,6 +723,8 @@ interface ProvenOfferTerms {
|
|
|
718
723
|
giveAmount?: string;
|
|
719
724
|
giveName?: string;
|
|
720
725
|
wantType?: "csd" | "token";
|
|
726
|
+
wantTicker?: string;
|
|
727
|
+
wantAmount?: string;
|
|
721
728
|
}
|
|
722
729
|
declare const PROVEN_TERMS_MINT: unique symbol;
|
|
723
730
|
type MintedProvenOfferTerms = ProvenOfferTerms & {
|
|
@@ -754,7 +761,8 @@ declare function provenOfferTerms(offerRec: OfferRecord, provenHeight: number):
|
|
|
754
761
|
* wantType - the SYMMETRIC want-type refusal: the served offer's want type (token iff want.ticker is
|
|
755
762
|
* a string, the isTokenWant pivot) must equal the proven type. The value leg already
|
|
756
763
|
* catches proven-CSD-served-as-token (String(undefined) mismatches t.value); this closes
|
|
757
|
-
* the reverse, proven-token-served-as-CSD.
|
|
764
|
+
* the reverse, proven-token-served-as-CSD. For a proven token want the served want.ticker
|
|
765
|
+
* and want.amount must also equal the proven price, verbatim.
|
|
758
766
|
*/
|
|
759
767
|
interface BindTermsOpts {
|
|
760
768
|
give?: boolean;
|
|
@@ -800,4 +808,53 @@ declare function myProvenFillClosedOffer(fill: ProvenEvent | null, fclaim: {
|
|
|
800
808
|
offer: string;
|
|
801
809
|
}, offerEv: ProvenEvent | null, me: string, grantHeight: number): boolean;
|
|
802
810
|
|
|
803
|
-
|
|
811
|
+
declare const LEGACY_HOLD_SUNSET_HEIGHT: number;
|
|
812
|
+
/** The count, or a refusal the caller must treat as unsafe (fail closed). */
|
|
813
|
+
type HoldCount = {
|
|
814
|
+
ok: true;
|
|
815
|
+
count: number;
|
|
816
|
+
} | {
|
|
817
|
+
ok: false;
|
|
818
|
+
reason: string;
|
|
819
|
+
};
|
|
820
|
+
/** An fclaim Propose the buyer may hold, read from a merkle-bound block. `proposer` is the prevout-bound author,
|
|
821
|
+
* or the buyer when it cannot be bound (over-counting only refuses a fill; under-counting can burn one). */
|
|
822
|
+
interface HoldCandidate {
|
|
823
|
+
id: string;
|
|
824
|
+
height: number;
|
|
825
|
+
pos: number;
|
|
826
|
+
proposer: string;
|
|
827
|
+
uri: string;
|
|
828
|
+
payloadHash: string;
|
|
829
|
+
expiresEpoch: number;
|
|
830
|
+
}
|
|
831
|
+
/** The fclaim being filled: its id, its proven block height and position, and the offer it reserves. */
|
|
832
|
+
interface HoldTarget {
|
|
833
|
+
id: string;
|
|
834
|
+
height: number;
|
|
835
|
+
pos: number;
|
|
836
|
+
offer: string;
|
|
837
|
+
}
|
|
838
|
+
/**
|
|
839
|
+
* An upper bound of the buyer's live holds on other offers when `target` was granted: distinct other offers with
|
|
840
|
+
* an fclaim by `me` applied before the target (height, then position in the block) whose hold is still live at the
|
|
841
|
+
* target's height. `closed` names fclaims whose offer the buyer's own proven fill closed (myProvenFillClosedOffer);
|
|
842
|
+
* they are skipped. An earlier fclaim the resolver denied is still counted: its denial is not visible here.
|
|
843
|
+
* Domain: grants at or above LEGACY_HOLD_SUNSET_HEIGHT. Below it a legacy SCORE_CLAIM hold from before V28 can
|
|
844
|
+
* still be live and count against the cap, so the result is a refusal.
|
|
845
|
+
*/
|
|
846
|
+
declare function countOtherHoldsAtGrant(candidates: readonly HoldCandidate[], target: HoldTarget, me: string, closed?: ReadonlySet<string>): HoldCount;
|
|
847
|
+
|
|
848
|
+
/** Fields of the merkle-proven Propose: its app domain and expires_epoch, its inclusion height, and its author
|
|
849
|
+
* (csd-crypto authorOf). */
|
|
850
|
+
interface ProvenOfferTx {
|
|
851
|
+
domain: string;
|
|
852
|
+
height: number;
|
|
853
|
+
expiresEpoch: number | bigint;
|
|
854
|
+
seller: string;
|
|
855
|
+
}
|
|
856
|
+
/** Why the proven offer Propose is not an offer the resolver admits (the resolver's own note for the record
|
|
857
|
+
* rules; the resolver writes no note below activation), or null when it passes. */
|
|
858
|
+
declare function provenOfferRefusal(rec: OfferRecord, tx: ProvenOfferTx): string | null;
|
|
859
|
+
|
|
860
|
+
export { ACTIVATION_HEIGHT, ADDR_RE, AMOUNT_RE, type AppliedEvent, type AttestEvent, BID_KEYS, type BalanceState, type BidRecord, type BidState, type BidStatus, type BindTermsOpts, 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, FCLAIM_KEYS, FCLAIM_MAX_EPOCH_AHEAD, FCLAIM_WINDOW_MIN, FEE_BPS, FEE_BPS_V16, FEE_GATE_MARGIN_BLOCKS, FILL_TIP_MARGIN, FINALIZE_TIP_MARGIN, type FclaimRecord, type FillEndorsement, type FillEntry, type FillOutputPlan, type FillPreview, type FillSafety, type FillSpvIo, type FillVerdict, GAP_NEEDED, type Give, HASH_RE, type HoldCandidate, type HoldCount, type HoldReplay, type HoldTarget, LEGACY_HOLD_SUNSET_HEIGHT, type LegacyBindOpts, MAX_ACTIVE_CLAIMS, MAX_AMOUNT, MAX_OFFER_EPOCHS, MAX_PENDING_REG, MAX_RECORD_BYTES, MAX_SCAN, MAX_TOKEN_DECIMALS, MINT_KEYS, type MintRecord, type MintedProvenOfferTerms, 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, type ProvenAttest, type ProvenEvent, type ProvenOfferTerms, type ProvenOfferTx, type ProvenPropose, REBATE_BPS, REBATE_FLAT, REG_COMMIT_MAX_BLOCKS, REG_FINALIZE_GRACE_BLOCKS, RESERVED_NAMES, SALT_RE, SCAN_MARGIN, 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, V27_HEIGHT, V28_HEIGHT, V29_HEIGHT, type Want, ZERO_ADDR, beforeActivation, bid, bindOfferTerms, bindProvenOffer, buildFeeHeight, buildRecord, burnedPayment, canonicalState, claimGraceOf, claimWindowAt, claimWindowOf, countOtherHoldsAtGrant, deploy, expiredClaimFee, fclaim, fclaimEpochFor, fclaimHoldEnd, feeBpsAt, fillEndorsement, fillIsSafe, fillOutputPlan, fillTargetId, finalizeWinnerCheck, hasLiveClaim, isName, isNameGive, isOpenClaimLane, isTokenWant, makerRebate, mint, myProvenFillClosedOffer, nameClaim, nameCommit, nameCommitRecord, nameFinalize, nameProfile, nameRegFee, nameRenew, nameSet, nameXfer, offer, offerCancelAll, offerExpiryHeightOf, paidToFromOutputs, parseAmount, parseRecord, pickPrimaryName, previewFill, primaryRankBefore, provenOfferRefusal, provenOfferTerms, ptAmt, replayLiveHold, requiredClaimDepth, requiredFillOutputs, resolve, tokenMeta, tradeFee, transfer, unsafeMintProvenOfferTerms, verifyFillSpv };
|
package/dist/index.d.ts
CHANGED
|
@@ -2,6 +2,8 @@ export { EPOCH_LEN, HALVING_INTERVAL, INITIAL_REWARD, MIN_FEE_ATTEST, MIN_FEE_PR
|
|
|
2
2
|
|
|
3
3
|
declare const DOMAIN = "cairnx:v1";
|
|
4
4
|
declare const ACTIVATION_HEIGHT = 29860;
|
|
5
|
+
/** True below ACTIVATION_HEIGHT, where resolve() skips every event without a note. */
|
|
6
|
+
declare const beforeActivation: (height: number) => boolean;
|
|
5
7
|
declare const V11_HEIGHT = 29960;
|
|
6
8
|
declare const V12_HEIGHT = 30300;
|
|
7
9
|
declare const V13_HEIGHT = 31100;
|
|
@@ -19,6 +21,8 @@ declare const NAME_PREMIUM_DECAY_EPOCHS = 720;
|
|
|
19
21
|
declare function expiredClaimFee(name: string, epochsPastGraceEnd: number, height: number): bigint;
|
|
20
22
|
declare const MAX_RECORD_BYTES = 512;
|
|
21
23
|
declare const MAX_AMOUNT: bigint;
|
|
24
|
+
/** The most decimals a token deploy may declare (parseRecord refuses a deploy above it). */
|
|
25
|
+
declare const MAX_TOKEN_DECIMALS = 8;
|
|
22
26
|
declare const SCORE_FILL = 100;
|
|
23
27
|
declare const SCORE_CANCEL = 0;
|
|
24
28
|
declare const SCORE_CLAIM = 50;
|
|
@@ -635,7 +639,8 @@ declare function fillEndorsement(offer: OfferState, me: string, pay: bigint | st
|
|
|
635
639
|
* mining outside the window (too early: rejected as unfrozen; too late: past the deadline — either way the
|
|
636
640
|
* fee burns). The window is derived purely from `eff` (never the resolver's `finalizeBy`), so a lying
|
|
637
641
|
* `finalizeBy` cannot widen it — but per the trust scope above, a lying `eff` still can for a caller that
|
|
638
|
-
* does not supply an independent `commitHeight`. `tip` is optional; without it the winner-only path runs.
|
|
642
|
+
* does not supply an independent `commitHeight`. `tip` is optional; without it the winner-only path runs. A
|
|
643
|
+
* supplied `tip` that is not a non-negative safe integer is refused. */
|
|
639
644
|
declare function finalizeWinnerCheck(nameState: NameState | null | undefined, me: string, commitHeight: number, tip?: number | null): {
|
|
640
645
|
safe: boolean;
|
|
641
646
|
reason: string;
|
|
@@ -685,7 +690,7 @@ interface FillVerdict {
|
|
|
685
690
|
* not-mine hold, a below-depth signing, a zero-delivery fill, a stranded past-deadline broadcast).
|
|
686
691
|
*
|
|
687
692
|
* `opts.myLiveHoldsAtGrant` (REQUIRED) is the buyer's count of OTHER live fclaim/legacy holds at the moment
|
|
688
|
-
* THIS fclaim was granted, asserted by the authoring client (
|
|
693
|
+
* THIS fclaim was granted, asserted by the authoring client (countOtherHoldsAtGrant computes it). The lane-scoped
|
|
689
694
|
* replay cannot see the buyer's other-offer holds, and MAX_ACTIVE_CLAIMS is the one grant clause counted
|
|
690
695
|
* across offers, so without this the surface would false-accept a cap-denied fclaim. `opts.pay` overrides the
|
|
691
696
|
* payment (base units to want.payto) for a PARTIAL tail-fill; defaults to the offer's full want.value.
|
|
@@ -718,6 +723,8 @@ interface ProvenOfferTerms {
|
|
|
718
723
|
giveAmount?: string;
|
|
719
724
|
giveName?: string;
|
|
720
725
|
wantType?: "csd" | "token";
|
|
726
|
+
wantTicker?: string;
|
|
727
|
+
wantAmount?: string;
|
|
721
728
|
}
|
|
722
729
|
declare const PROVEN_TERMS_MINT: unique symbol;
|
|
723
730
|
type MintedProvenOfferTerms = ProvenOfferTerms & {
|
|
@@ -754,7 +761,8 @@ declare function provenOfferTerms(offerRec: OfferRecord, provenHeight: number):
|
|
|
754
761
|
* wantType - the SYMMETRIC want-type refusal: the served offer's want type (token iff want.ticker is
|
|
755
762
|
* a string, the isTokenWant pivot) must equal the proven type. The value leg already
|
|
756
763
|
* catches proven-CSD-served-as-token (String(undefined) mismatches t.value); this closes
|
|
757
|
-
* the reverse, proven-token-served-as-CSD.
|
|
764
|
+
* the reverse, proven-token-served-as-CSD. For a proven token want the served want.ticker
|
|
765
|
+
* and want.amount must also equal the proven price, verbatim.
|
|
758
766
|
*/
|
|
759
767
|
interface BindTermsOpts {
|
|
760
768
|
give?: boolean;
|
|
@@ -800,4 +808,53 @@ declare function myProvenFillClosedOffer(fill: ProvenEvent | null, fclaim: {
|
|
|
800
808
|
offer: string;
|
|
801
809
|
}, offerEv: ProvenEvent | null, me: string, grantHeight: number): boolean;
|
|
802
810
|
|
|
803
|
-
|
|
811
|
+
declare const LEGACY_HOLD_SUNSET_HEIGHT: number;
|
|
812
|
+
/** The count, or a refusal the caller must treat as unsafe (fail closed). */
|
|
813
|
+
type HoldCount = {
|
|
814
|
+
ok: true;
|
|
815
|
+
count: number;
|
|
816
|
+
} | {
|
|
817
|
+
ok: false;
|
|
818
|
+
reason: string;
|
|
819
|
+
};
|
|
820
|
+
/** An fclaim Propose the buyer may hold, read from a merkle-bound block. `proposer` is the prevout-bound author,
|
|
821
|
+
* or the buyer when it cannot be bound (over-counting only refuses a fill; under-counting can burn one). */
|
|
822
|
+
interface HoldCandidate {
|
|
823
|
+
id: string;
|
|
824
|
+
height: number;
|
|
825
|
+
pos: number;
|
|
826
|
+
proposer: string;
|
|
827
|
+
uri: string;
|
|
828
|
+
payloadHash: string;
|
|
829
|
+
expiresEpoch: number;
|
|
830
|
+
}
|
|
831
|
+
/** The fclaim being filled: its id, its proven block height and position, and the offer it reserves. */
|
|
832
|
+
interface HoldTarget {
|
|
833
|
+
id: string;
|
|
834
|
+
height: number;
|
|
835
|
+
pos: number;
|
|
836
|
+
offer: string;
|
|
837
|
+
}
|
|
838
|
+
/**
|
|
839
|
+
* An upper bound of the buyer's live holds on other offers when `target` was granted: distinct other offers with
|
|
840
|
+
* an fclaim by `me` applied before the target (height, then position in the block) whose hold is still live at the
|
|
841
|
+
* target's height. `closed` names fclaims whose offer the buyer's own proven fill closed (myProvenFillClosedOffer);
|
|
842
|
+
* they are skipped. An earlier fclaim the resolver denied is still counted: its denial is not visible here.
|
|
843
|
+
* Domain: grants at or above LEGACY_HOLD_SUNSET_HEIGHT. Below it a legacy SCORE_CLAIM hold from before V28 can
|
|
844
|
+
* still be live and count against the cap, so the result is a refusal.
|
|
845
|
+
*/
|
|
846
|
+
declare function countOtherHoldsAtGrant(candidates: readonly HoldCandidate[], target: HoldTarget, me: string, closed?: ReadonlySet<string>): HoldCount;
|
|
847
|
+
|
|
848
|
+
/** Fields of the merkle-proven Propose: its app domain and expires_epoch, its inclusion height, and its author
|
|
849
|
+
* (csd-crypto authorOf). */
|
|
850
|
+
interface ProvenOfferTx {
|
|
851
|
+
domain: string;
|
|
852
|
+
height: number;
|
|
853
|
+
expiresEpoch: number | bigint;
|
|
854
|
+
seller: string;
|
|
855
|
+
}
|
|
856
|
+
/** Why the proven offer Propose is not an offer the resolver admits (the resolver's own note for the record
|
|
857
|
+
* rules; the resolver writes no note below activation), or null when it passes. */
|
|
858
|
+
declare function provenOfferRefusal(rec: OfferRecord, tx: ProvenOfferTx): string | null;
|
|
859
|
+
|
|
860
|
+
export { ACTIVATION_HEIGHT, ADDR_RE, AMOUNT_RE, type AppliedEvent, type AttestEvent, BID_KEYS, type BalanceState, type BidRecord, type BidState, type BidStatus, type BindTermsOpts, 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, FCLAIM_KEYS, FCLAIM_MAX_EPOCH_AHEAD, FCLAIM_WINDOW_MIN, FEE_BPS, FEE_BPS_V16, FEE_GATE_MARGIN_BLOCKS, FILL_TIP_MARGIN, FINALIZE_TIP_MARGIN, type FclaimRecord, type FillEndorsement, type FillEntry, type FillOutputPlan, type FillPreview, type FillSafety, type FillSpvIo, type FillVerdict, GAP_NEEDED, type Give, HASH_RE, type HoldCandidate, type HoldCount, type HoldReplay, type HoldTarget, LEGACY_HOLD_SUNSET_HEIGHT, type LegacyBindOpts, MAX_ACTIVE_CLAIMS, MAX_AMOUNT, MAX_OFFER_EPOCHS, MAX_PENDING_REG, MAX_RECORD_BYTES, MAX_SCAN, MAX_TOKEN_DECIMALS, MINT_KEYS, type MintRecord, type MintedProvenOfferTerms, 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, type ProvenAttest, type ProvenEvent, type ProvenOfferTerms, type ProvenOfferTx, type ProvenPropose, REBATE_BPS, REBATE_FLAT, REG_COMMIT_MAX_BLOCKS, REG_FINALIZE_GRACE_BLOCKS, RESERVED_NAMES, SALT_RE, SCAN_MARGIN, 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, V27_HEIGHT, V28_HEIGHT, V29_HEIGHT, type Want, ZERO_ADDR, beforeActivation, bid, bindOfferTerms, bindProvenOffer, buildFeeHeight, buildRecord, burnedPayment, canonicalState, claimGraceOf, claimWindowAt, claimWindowOf, countOtherHoldsAtGrant, deploy, expiredClaimFee, fclaim, fclaimEpochFor, fclaimHoldEnd, feeBpsAt, fillEndorsement, fillIsSafe, fillOutputPlan, fillTargetId, finalizeWinnerCheck, hasLiveClaim, isName, isNameGive, isOpenClaimLane, isTokenWant, makerRebate, mint, myProvenFillClosedOffer, nameClaim, nameCommit, nameCommitRecord, nameFinalize, nameProfile, nameRegFee, nameRenew, nameSet, nameXfer, offer, offerCancelAll, offerExpiryHeightOf, paidToFromOutputs, parseAmount, parseRecord, pickPrimaryName, previewFill, primaryRankBefore, provenOfferRefusal, provenOfferTerms, ptAmt, replayLiveHold, requiredClaimDepth, requiredFillOutputs, resolve, tokenMeta, tradeFee, transfer, unsafeMintProvenOfferTerms, verifyFillSpv };
|
package/dist/index.js
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
import { EPOCH_LEN, MAX_URI_BYTES, epochOf } from "@inversealtruism/csd-codec";
|
|
3
3
|
var DOMAIN = "cairnx:v1";
|
|
4
4
|
var ACTIVATION_HEIGHT = 29860;
|
|
5
|
+
var beforeActivation = (height) => height < ACTIVATION_HEIGHT;
|
|
5
6
|
var V11_HEIGHT = 29960;
|
|
6
7
|
var V12_HEIGHT = 30300;
|
|
7
8
|
var V13_HEIGHT = 31100;
|
|
@@ -22,6 +23,7 @@ function expiredClaimFee(name, epochsPastGraceEnd, height) {
|
|
|
22
23
|
}
|
|
23
24
|
var MAX_RECORD_BYTES = MAX_URI_BYTES;
|
|
24
25
|
var MAX_AMOUNT = (1n << 96n) - 1n;
|
|
26
|
+
var MAX_TOKEN_DECIMALS = 8;
|
|
25
27
|
var SCORE_FILL = 100;
|
|
26
28
|
var SCORE_CANCEL = 0;
|
|
27
29
|
var SCORE_CLAIM = 50;
|
|
@@ -170,7 +172,7 @@ function parseRecord(uri, payloadHashHex) {
|
|
|
170
172
|
if (!onlyKeys(r, DEPLOY_KEYS)) return null;
|
|
171
173
|
if (!isTicker(r.ticker)) return null;
|
|
172
174
|
if (r.name !== void 0 && (typeof r.name !== "string" || r.name.length > 32)) return null;
|
|
173
|
-
if (typeof r.decimals !== "number" || !Number.isInteger(r.decimals) || r.decimals < 0 || r.decimals >
|
|
175
|
+
if (typeof r.decimals !== "number" || !Number.isInteger(r.decimals) || r.decimals < 0 || r.decimals > MAX_TOKEN_DECIMALS) return null;
|
|
174
176
|
if (parseAmount(r.supply) === null) return null;
|
|
175
177
|
if (r.mint !== "open" && r.mint !== "issuer") return null;
|
|
176
178
|
if (r.mint === "open" && parseAmount(r.mintLimit) === null) return null;
|
|
@@ -1075,41 +1077,17 @@ function applyNrenew(c, ev, rec, who, feeToTreasury) {
|
|
|
1075
1077
|
function applyOffer(c, ev, rec, who) {
|
|
1076
1078
|
const { tokens, names, offers, offerLock, openOffers, bids, bal, note } = c;
|
|
1077
1079
|
const v11 = ev.height >= V11_HEIGHT;
|
|
1078
|
-
const v12 = ev.height >= V12_HEIGHT;
|
|
1079
1080
|
const v15 = ev.height >= V15_HEIGHT;
|
|
1080
1081
|
const v16 = ev.height >= V16_HEIGHT;
|
|
1081
1082
|
const wantIsToken = isTokenWant(rec.want);
|
|
1082
|
-
|
|
1083
|
-
|
|
1084
|
-
|
|
1085
|
-
}
|
|
1086
|
-
if (ev.height >= V13_HEIGHT && ev.height < V17_HEIGHT && !wantIsToken && rec.taker === void 0) {
|
|
1087
|
-
note(ev, ev.id, "offer", false, "v1.3: CSD-priced offers must be taker-bound (use bid/RFQ)");
|
|
1083
|
+
const refusal = offerEnvelopeRefusal(rec, who, ev.height, ev.expiresEpoch);
|
|
1084
|
+
if (refusal !== null) {
|
|
1085
|
+
note(ev, ev.id, "offer", false, refusal);
|
|
1088
1086
|
return;
|
|
1089
1087
|
}
|
|
1090
1088
|
const payto = (rec.want.payto ?? who).toLowerCase();
|
|
1091
|
-
if (payto === TREASURY_ADDR) {
|
|
1092
|
-
note(ev, ev.id, "offer", false, "payto cannot be the protocol treasury");
|
|
1093
|
-
return;
|
|
1094
|
-
}
|
|
1095
|
-
if (!Number.isSafeInteger(ev.expiresEpoch)) {
|
|
1096
|
-
note(ev, ev.id, "offer", false, "expiresEpoch out of safe-integer range");
|
|
1097
|
-
return;
|
|
1098
|
-
}
|
|
1099
|
-
if (epochOf(ev.height) > ev.expiresEpoch) {
|
|
1100
|
-
note(ev, ev.id, "offer", false, "already expired at anchor");
|
|
1101
|
-
return;
|
|
1102
|
-
}
|
|
1103
|
-
if (ev.height >= V21_HEIGHT && ev.height < V22_HEIGHT && ev.expiresEpoch - epochOf(ev.height) > MAX_OFFER_EPOCHS) {
|
|
1104
|
-
note(ev, ev.id, "offer", false, "v2.1: offer duration exceeds the max");
|
|
1105
|
-
return;
|
|
1106
|
-
}
|
|
1107
1089
|
const give = rec.give;
|
|
1108
1090
|
if (isNameGive(give)) {
|
|
1109
|
-
if (!v11) {
|
|
1110
|
-
note(ev, ev.id, "offer", false, "name offers need v1.1");
|
|
1111
|
-
return;
|
|
1112
|
-
}
|
|
1113
1091
|
const n = names.get(give.name);
|
|
1114
1092
|
if (!n || n.owner !== who) {
|
|
1115
1093
|
note(ev, ev.id, "offer", false, "you don't own this name");
|
|
@@ -1297,6 +1275,17 @@ function applyFclaim(c, ev, rec, who) {
|
|
|
1297
1275
|
fclaims.set(ev.id, { offer: rec.offer, proposer: who, expiresEpoch: E, height: ev.height, granted: true });
|
|
1298
1276
|
note(ev, ev.id, "fclaim", true);
|
|
1299
1277
|
}
|
|
1278
|
+
function offerEnvelopeRefusal(rec, who, height, expiresEpoch) {
|
|
1279
|
+
const wantIsToken = isTokenWant(rec.want);
|
|
1280
|
+
if ((wantIsToken || rec.min !== void 0 || rec.bid !== void 0) && height < V12_HEIGHT) return "v1.2 offer shape before activation";
|
|
1281
|
+
if (height >= V13_HEIGHT && height < V17_HEIGHT && !wantIsToken && rec.taker === void 0) return "v1.3: CSD-priced offers must be taker-bound (use bid/RFQ)";
|
|
1282
|
+
if ((rec.want.payto ?? who).toLowerCase() === TREASURY_ADDR) return "payto cannot be the protocol treasury";
|
|
1283
|
+
if (!Number.isSafeInteger(expiresEpoch)) return "expiresEpoch out of safe-integer range";
|
|
1284
|
+
if (epochOf(height) > expiresEpoch) return "already expired at anchor";
|
|
1285
|
+
if (height >= V21_HEIGHT && height < V22_HEIGHT && expiresEpoch - epochOf(height) > MAX_OFFER_EPOCHS) return "v2.1: offer duration exceeds the max";
|
|
1286
|
+
if (isNameGive(rec.give) && height < V11_HEIGHT) return "name offers need v1.1";
|
|
1287
|
+
return null;
|
|
1288
|
+
}
|
|
1300
1289
|
|
|
1301
1290
|
// src/resolve/tokens.ts
|
|
1302
1291
|
function applyDeploy(c, ev, rec, who, feeToTreasury) {
|
|
@@ -1418,7 +1407,7 @@ function resolve(events, tipHeight) {
|
|
|
1418
1407
|
c.pendingCancels = [];
|
|
1419
1408
|
};
|
|
1420
1409
|
for (const ev of applied) {
|
|
1421
|
-
if (ev.height
|
|
1410
|
+
if (beforeActivation(ev.height)) continue;
|
|
1422
1411
|
if (ev.height !== pendingBlock) {
|
|
1423
1412
|
applyPendingCancels();
|
|
1424
1413
|
pendingBlock = ev.height;
|
|
@@ -1683,8 +1672,9 @@ function finalizeWinnerCheck(nameState, me, commitHeight, tip) {
|
|
|
1683
1672
|
if (nameState.pending !== true) return { safe: false, reason: "already registered to you \u2014 no second finalize fee is needed" };
|
|
1684
1673
|
if (Number(nameState.effectiveHeight) !== Number(commitHeight))
|
|
1685
1674
|
return { safe: false, reason: "your reservation was displaced (effective height changed) \u2014 a finalize now would burn the fee" };
|
|
1686
|
-
if (tip !== void 0 && tip !== null
|
|
1687
|
-
|
|
1675
|
+
if (tip !== void 0 && tip !== null) {
|
|
1676
|
+
if (!Number.isSafeInteger(tip) || tip < 0) return { safe: false, reason: `the chain tip given (${String(tip)}) is not a block height, so the finalize window cannot be checked` };
|
|
1677
|
+
const t = tip;
|
|
1688
1678
|
const eff = Number(nameState.effectiveHeight);
|
|
1689
1679
|
const freezeEnd = eff + REG_COMMIT_MAX_BLOCKS;
|
|
1690
1680
|
const closeAt = eff + REG_COMMIT_MAX_BLOCKS + REG_FINALIZE_GRACE_BLOCKS - FINALIZE_TIP_MARGIN;
|
|
@@ -1746,15 +1736,17 @@ async function verifyFillSpv(offerId, fclaimTxid, me, io, opts) {
|
|
|
1746
1736
|
return no("could not enumerate the offer's events");
|
|
1747
1737
|
}
|
|
1748
1738
|
const want = /* @__PURE__ */ new Set([offerId.toLowerCase(), fclaimTxid.toLowerCase(), ...(hintIds ?? []).map((x) => String(x).toLowerCase())]);
|
|
1739
|
+
const unproven = (wid) => wid === offerId.toLowerCase() ? no("offer not merkle-proven (no PoW-verified offer Propose)") : wid === fclaimTxid.toLowerCase() ? no("fclaim not merkle-proven (no PoW-verified fclaim Propose)") : no(`an event on this offer could not be merkle-proven (${wid}) - refusing, the replay would miss it`);
|
|
1749
1740
|
const proven = [];
|
|
1750
1741
|
for (const wid of want) {
|
|
1751
1742
|
let ev;
|
|
1752
1743
|
try {
|
|
1753
1744
|
ev = await io.provenEvent(wid);
|
|
1754
1745
|
} catch {
|
|
1755
|
-
|
|
1746
|
+
return unproven(wid);
|
|
1756
1747
|
}
|
|
1757
|
-
if (ev
|
|
1748
|
+
if (!ev || (ev.kind === "propose" ? ev.id : ev.txid).toLowerCase() !== wid) return unproven(wid);
|
|
1749
|
+
proven.push(ev);
|
|
1758
1750
|
}
|
|
1759
1751
|
const isProp = (e) => e.kind === "propose";
|
|
1760
1752
|
const offerEv = proven.find((e) => isProp(e) && e.id.toLowerCase() === offerId.toLowerCase());
|
|
@@ -1833,7 +1825,9 @@ function provenOfferTerms(offerRec, provenHeight) {
|
|
|
1833
1825
|
giveTicker: g.ticker !== void 0 ? String(g.ticker) : void 0,
|
|
1834
1826
|
giveAmount: g.amount !== void 0 ? String(g.amount) : void 0,
|
|
1835
1827
|
giveName: g.name !== void 0 ? String(g.name) : void 0,
|
|
1836
|
-
wantType: isTokenWant(offerRec.want) ? "token" : "csd"
|
|
1828
|
+
wantType: isTokenWant(offerRec.want) ? "token" : "csd",
|
|
1829
|
+
wantTicker: isTokenWant(offerRec.want) ? String(w.ticker) : void 0,
|
|
1830
|
+
wantAmount: isTokenWant(offerRec.want) ? String(w.amount) : void 0
|
|
1837
1831
|
};
|
|
1838
1832
|
}
|
|
1839
1833
|
function bindOfferTerms(servedOffer, t, opts) {
|
|
@@ -1848,7 +1842,8 @@ function bindOfferTerms(servedOffer, t, opts) {
|
|
|
1848
1842
|
if ((om !== void 0 && om !== null) !== (t.min !== void 0)) return true;
|
|
1849
1843
|
if (t.min !== void 0 && String(om) !== t.min) return true;
|
|
1850
1844
|
if (opts?.wantType !== false) {
|
|
1851
|
-
if (t.wantType === void 0
|
|
1845
|
+
if (t.wantType === void 0) return true;
|
|
1846
|
+
if (t.wantType === "token" ? String(o?.want?.ticker) !== t.wantTicker || String(o?.want?.amount) !== t.wantAmount : typeof o?.want?.ticker === "string") return true;
|
|
1852
1847
|
}
|
|
1853
1848
|
if (opts?.give !== false) {
|
|
1854
1849
|
const g = o?.give;
|
|
@@ -1922,6 +1917,35 @@ function myProvenFillClosedOffer(fill, fclaim2, offerEv, me, grantHeight) {
|
|
|
1922
1917
|
return need.every((leg) => ptAmt(fill.paidTo?.[lc(leg.to)]) >= leg.value);
|
|
1923
1918
|
}
|
|
1924
1919
|
|
|
1920
|
+
// src/holdcount.ts
|
|
1921
|
+
var lastLegacyClaimEnd = V28_HEIGHT - 1 + claimWindowAt(V28_HEIGHT - 1);
|
|
1922
|
+
var LEGACY_HOLD_SUNSET_HEIGHT = lastLegacyClaimEnd + claimGraceOf(lastLegacyClaimEnd);
|
|
1923
|
+
function countOtherHoldsAtGrant(candidates, target, me, closed = /* @__PURE__ */ new Set()) {
|
|
1924
|
+
if (!(Number.isSafeInteger(target.height) && target.height >= LEGACY_HOLD_SUNSET_HEIGHT))
|
|
1925
|
+
return { ok: false, reason: `this reservation was granted at ${target.height}, before block ${LEGACY_HOLD_SUNSET_HEIGHT}, while claims made before V28 could still count against the cap; it cannot be checked here` };
|
|
1926
|
+
const meL = String(me).toLowerCase(), tid = String(target.id).toLowerCase(), toffer = String(target.offer).toLowerCase();
|
|
1927
|
+
const offers = /* @__PURE__ */ new Set();
|
|
1928
|
+
for (const c of candidates) {
|
|
1929
|
+
const cid = String(c.id).toLowerCase();
|
|
1930
|
+
if (cid === tid || closed.has(cid) || String(c.proposer).toLowerCase() !== meL) continue;
|
|
1931
|
+
if (!(c.height < target.height || c.height === target.height && c.pos < target.pos)) continue;
|
|
1932
|
+
if (!(fclaimHoldEnd(Number(c.expiresEpoch)) >= target.height)) continue;
|
|
1933
|
+
const rec = parseRecord(String(c.uri), String(c.payloadHash));
|
|
1934
|
+
if (!rec || rec.t !== "fclaim") continue;
|
|
1935
|
+
const offer2 = String(rec.offer).toLowerCase();
|
|
1936
|
+
if (offer2 !== toffer) offers.add(offer2);
|
|
1937
|
+
}
|
|
1938
|
+
return { ok: true, count: offers.size };
|
|
1939
|
+
}
|
|
1940
|
+
|
|
1941
|
+
// src/admission.ts
|
|
1942
|
+
function provenOfferRefusal(rec, tx) {
|
|
1943
|
+
if (tx.domain !== DOMAIN) return `not a ${DOMAIN} Propose (domain ${JSON.stringify(String(tx.domain))})`;
|
|
1944
|
+
if (beforeActivation(tx.height)) return `anchored before CairnX activation (block ${ACTIVATION_HEIGHT})`;
|
|
1945
|
+
const ee = typeof tx.expiresEpoch === "bigint" ? Number(tx.expiresEpoch) : tx.expiresEpoch;
|
|
1946
|
+
return offerEnvelopeRefusal(rec, String(tx.seller).toLowerCase(), tx.height, ee);
|
|
1947
|
+
}
|
|
1948
|
+
|
|
1925
1949
|
// src/index.ts
|
|
1926
1950
|
import {
|
|
1927
1951
|
canonicalJson as canonicalJson2,
|
|
@@ -1963,12 +1987,14 @@ export {
|
|
|
1963
1987
|
HALVING_INTERVAL,
|
|
1964
1988
|
HASH_RE,
|
|
1965
1989
|
INITIAL_REWARD2 as INITIAL_REWARD,
|
|
1990
|
+
LEGACY_HOLD_SUNSET_HEIGHT,
|
|
1966
1991
|
MAX_ACTIVE_CLAIMS,
|
|
1967
1992
|
MAX_AMOUNT,
|
|
1968
1993
|
MAX_OFFER_EPOCHS,
|
|
1969
1994
|
MAX_PENDING_REG,
|
|
1970
1995
|
MAX_RECORD_BYTES,
|
|
1971
1996
|
MAX_SCAN,
|
|
1997
|
+
MAX_TOKEN_DECIMALS,
|
|
1972
1998
|
MINT_KEYS,
|
|
1973
1999
|
MIN_FEE_ATTEST,
|
|
1974
2000
|
MIN_FEE_PROPOSE,
|
|
@@ -2023,6 +2049,7 @@ export {
|
|
|
2023
2049
|
V28_HEIGHT,
|
|
2024
2050
|
V29_HEIGHT,
|
|
2025
2051
|
ZERO_ADDR,
|
|
2052
|
+
beforeActivation,
|
|
2026
2053
|
bid,
|
|
2027
2054
|
bindOfferTerms,
|
|
2028
2055
|
bindProvenOffer,
|
|
@@ -2035,6 +2062,7 @@ export {
|
|
|
2035
2062
|
claimGraceOf,
|
|
2036
2063
|
claimWindowAt,
|
|
2037
2064
|
claimWindowOf,
|
|
2065
|
+
countOtherHoldsAtGrant,
|
|
2038
2066
|
deploy,
|
|
2039
2067
|
epochOf,
|
|
2040
2068
|
expiredClaimFee,
|
|
@@ -2074,6 +2102,7 @@ export {
|
|
|
2074
2102
|
pickPrimaryName,
|
|
2075
2103
|
previewFill,
|
|
2076
2104
|
primaryRankBefore,
|
|
2105
|
+
provenOfferRefusal,
|
|
2077
2106
|
provenOfferTerms,
|
|
2078
2107
|
ptAmt,
|
|
2079
2108
|
replayLiveHold,
|