@inversealtruism/cairnx-core 0.1.34 → 0.1.36
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/CONVENTION.md +29 -20
- package/MAKERS.md +5 -1
- package/README.md +17 -6
- package/dist/index.cjs +57 -1
- package/dist/index.d.cts +49 -8
- package/dist/index.d.ts +49 -8
- package/dist/index.js +52 -1
- package/package.json +2 -2
package/CONVENTION.md
CHANGED
|
@@ -5,12 +5,17 @@
|
|
|
5
5
|
**Version ladder** (each gate non-retroactive — below it, behavior + canonical hashes are byte-identical to history):
|
|
6
6
|
v1.1 @ 29 960 · v1.2 @ 30 300 · v1.3 @ 31 100 · v1.4 @ 31 400 · v1.5 @ 32 000 · v1.6 @ 33 600 (§19) ·
|
|
7
7
|
v1.7 @ 34 000 (§20) · v1.9 @ 36 700 (§22) · v2.0 @ 38 400 (§23) · v1.8 @ 40 000 (§21) · v2.1 @ 40 100 (§24) ·
|
|
8
|
-
v2.2 @ 41 300 (§25) · v2.4 @
|
|
9
|
-
v2.
|
|
8
|
+
v2.2 @ 41 300 (§25) · v2.4 @ 46 400 (§27) · v2.5 @ 46 440 (§28) · v2.6 @ 46 480 (§29) · v2.7 @ 46 520 (§30) ·
|
|
9
|
+
v2.3 @ 52 000 (§26).
|
|
10
10
|
Sections §19–§30 are the normative semantics for v1.6–v2.7; §5.1 is the byte-level canonical-JSON contract that binds all of them.
|
|
11
|
-
Activation order is by HEIGHT, not by version number (v1.8 activated after v2.0; v2.3 activates after v2.
|
|
11
|
+
Activation order is by HEIGHT, not by version number (v1.8 activated after v2.0; v2.3 activates after v2.4–v2.7): a
|
|
12
12
|
replayer gates each rule on its own height constant, never on "version X implies version Y is active".
|
|
13
13
|
|
|
14
|
+
> **Height re-pin history (2026-07-03).** v2.4–v2.7 originally published as 49 200 / 51 000 / 51 200 / 52 500
|
|
15
|
+
> and were RE-PINNED to 46 400 / 46 440 / 46 480 / 46 520 (`CONSENSUS_CHANGES.md` 0.1.33): an operator-approved,
|
|
16
|
+
> coordinated same-day re-pin of every verifier while the tip (~46 071) was still below every new height, so all
|
|
17
|
+
> recorded history replays byte-identically. Replayers built from this spec MUST use the re-pinned heights above.
|
|
18
|
+
|
|
14
19
|
> **Canonical copy.** This spec ships in the published `@inversealtruism/cairnx-core` package; the source of
|
|
15
20
|
> truth is `csd-sdk/packages/cairnx/CONVENTION.md`. Any in-repo mirror (e.g. the `cairnx` app repo) MUST be
|
|
16
21
|
> kept **byte-identical** to it on every change — a third-party implementer fetches the *published* copy, so
|
|
@@ -869,14 +874,15 @@ The §24 lifetime cap proved to be an infrastructure symptom, not a market need,
|
|
|
869
874
|
|
|
870
875
|
# CairnX Convention v2.4 (length-graded registration fee increase)
|
|
871
876
|
|
|
872
|
-
**Activation height:
|
|
877
|
+
**Activation height: 46 400** (`V24_HEIGHT`; non-retroactive; keyed on the FEE-BEARING event's height;
|
|
878
|
+
re-pinned 2026-07-03 from the originally published 49 200 — see the height re-pin history note at the top).
|
|
873
879
|
|
|
874
880
|
## 27. The fee curve
|
|
875
881
|
|
|
876
882
|
`nameRegFee(name, height)` selects the regime by the height of the event that carries the fee: the `name`
|
|
877
883
|
reveal below v2.5, the winner's `nfinalize` at/after v2.5 (§28), and every renewal at its own event height.
|
|
878
884
|
|
|
879
|
-
| name length | < 40 000 | ≥ 40 000 (v1.8) | ≥
|
|
885
|
+
| name length | < 40 000 | ≥ 40 000 (v1.8) | ≥ 46 400 (v2.4) |
|
|
880
886
|
|---|---|---|---|
|
|
881
887
|
| ≤ 3 chars | 5 CSD | 6.7 CSD | 15 CSD |
|
|
882
888
|
| 4 chars | 2 CSD | 6.7 CSD | 10 CSD |
|
|
@@ -886,16 +892,17 @@ reveal below v2.5, the winner's `nfinalize` at/after v2.5 (§28), and every rene
|
|
|
886
892
|
|
|
887
893
|
- Underpayment is a **no-op** (`name registration fee unpaid`), and the §10 warning applies with force:
|
|
888
894
|
the attached payment outputs still settle on-chain. An underpaid registration or renewal is a burn.
|
|
889
|
-
- **Adoption note (BOTH directions are hard):** a stale replayer ACCEPTS an underpaid post-
|
|
895
|
+
- **Adoption note (BOTH directions are hard):** a stale replayer ACCEPTS an underpaid post-46 400
|
|
890
896
|
registration the chain rejects (it shows a phantom owner), and a stale wallet ATTACHES the old fee and
|
|
891
897
|
burns it. Every replayer and every fee-quoting client must run the v2.4 core before the tip crosses
|
|
892
|
-
|
|
898
|
+
46 400.
|
|
893
899
|
|
|
894
900
|
---
|
|
895
901
|
|
|
896
902
|
# CairnX Convention v2.5 (sealed-reservation registration)
|
|
897
903
|
|
|
898
|
-
**Activation height:
|
|
904
|
+
**Activation height: 46 440** (`V25_HEIGHT`; non-retroactive; keyed on the reveal event height;
|
|
905
|
+
re-pinned 2026-07-03 from the originally published 51 000 — see the height re-pin history note at the top).
|
|
899
906
|
|
|
900
907
|
Root fix for the reveal fee-burn: pre-v2.5, every losing racer in a §9 commit-reveal race paid the FULL
|
|
901
908
|
registration fee for nothing (payment-without-delivery). At/after v2.5 the reveal is payment-free; only
|
|
@@ -910,7 +917,7 @@ the settled winner ever pays.
|
|
|
910
917
|
freeze, so no back-dated challenger can appear after the freeze has passed. Direct no-salt registration
|
|
911
918
|
is rejected at/after v2.5 (`v2.5: registration requires a commit-reveal (salt)`): an unsealed
|
|
912
919
|
registration could not be finalized.
|
|
913
|
-
- **Reveal (`name` record, height ≥
|
|
920
|
+
- **Reveal (`name` record, height ≥ 46 440):** carries NO registration fee. Creates a PENDING reservation,
|
|
914
921
|
materialized in canonical state as the name with `pending: true` and
|
|
915
922
|
`finalizeBy = effHeight + 8 + 20` (`REG_COMMIT_MAX_BLOCKS + REG_FINALIZE_GRACE_BLOCKS`).
|
|
916
923
|
- **Contest while pending:** a rival reveal with a strictly earlier `(effHeight, pos, id)` (numeric on
|
|
@@ -934,22 +941,23 @@ the settled winner ever pays.
|
|
|
934
941
|
- **Client timing rule** (`FINALIZE_TIP_MARGIN = 2`, client-side only): sign the finalize at
|
|
935
942
|
`effHeight + 8 + 2` or later so one reorg cannot un-freeze the contest under a fee-bearing tx. The
|
|
936
943
|
20-block grace exists so a slow inclusion still lands before `finalizeBy`.
|
|
937
|
-
- **Adoption note (hard gate):** a stale (pre-v2.5) wallet crossing
|
|
944
|
+
- **Adoption note (hard gate):** a stale (pre-v2.5) wallet crossing 46 440 attaches the registration fee
|
|
938
945
|
to what is now a payment-free reveal; the resolver ignores the fee and the payment burns. Every
|
|
939
|
-
replayer AND every fee-attaching client must run the v2.5 core before the tip crosses
|
|
946
|
+
replayer AND every fee-attaching client must run the v2.5 core before the tip crosses 46 440.
|
|
940
947
|
|
|
941
948
|
---
|
|
942
949
|
|
|
943
950
|
# CairnX Convention v2.6 (sealed-reservation recapture)
|
|
944
951
|
|
|
945
|
-
**Activation height:
|
|
952
|
+
**Activation height: 46 480** (`V26_HEIGHT`; non-retroactive; keyed on the reveal event height;
|
|
953
|
+
re-pinned 2026-07-03 from the originally published 51 200 — see the height re-pin history note at the top).
|
|
946
954
|
|
|
947
955
|
The §28 cure applied to LAPSED-name recapture (§17), whose losing racer previously forfeited the full
|
|
948
956
|
decaying premium (up to hundreds of CSD).
|
|
949
957
|
|
|
950
958
|
## 29. Recapture through the same sealed machinery
|
|
951
959
|
|
|
952
|
-
- **Reveal on a lapsed name (height ≥
|
|
960
|
+
- **Reveal on a lapsed name (height ≥ 46 480):** payment-free. Creates a recapture reservation in an
|
|
953
961
|
INTERNAL `recaptures` map. The reservation is NOT materialized in canonical state, and the lapsed
|
|
954
962
|
record in `names` is left untouched (it is the premium basis; an abandoned reservation can never
|
|
955
963
|
bypass the premium). Below v2.6, recapture stays pay-now at reveal (§17, byte-identical).
|
|
@@ -965,13 +973,14 @@ decaying premium (up to hundreds of CSD).
|
|
|
965
973
|
which later `nfinalize` succeeds. The map is defined by this section plus the reference resolver and
|
|
966
974
|
its Python mirror; the v2.6 conformance vectors pin it.
|
|
967
975
|
- **Adoption note (hard gate):** same shape as §28. A stale wallet attaches the premium to a
|
|
968
|
-
payment-free recapture reveal and burns it. All replayers and clients on the v2.6 core before
|
|
976
|
+
payment-free recapture reveal and burns it. All replayers and clients on the v2.6 core before 46 480.
|
|
969
977
|
|
|
970
978
|
---
|
|
971
979
|
|
|
972
980
|
# CairnX Convention v2.7 (young-name sale embargo shrinks)
|
|
973
981
|
|
|
974
|
-
**Activation height:
|
|
982
|
+
**Activation height: 46 520** (`V27_HEIGHT`; non-retroactive; keyed on the OFFER event height;
|
|
983
|
+
re-pinned 2026-07-03 from the originally published 52 500 — see the height re-pin history note at the top).
|
|
975
984
|
|
|
976
985
|
## 30. Sale embargo: 240 blocks becomes 8
|
|
977
986
|
|
|
@@ -979,12 +988,12 @@ A name `offer` (§17 sale path) whose event height `H` satisfies `H − effHeigh
|
|
|
979
988
|
(`name too young to sell (must out-age the reveal window)`), where `effHeight` is the name's effective
|
|
980
989
|
anchor. `viaFill` names were never embargoed.
|
|
981
990
|
|
|
982
|
-
- **`H` <
|
|
991
|
+
- **`H` < 46 520:** `embargo = COMMIT_MAX_BLOCKS` (240 blocks, ≈ 8 h). The pre-sealed rule: a fresh name
|
|
983
992
|
had to out-age every lurking back-dated reveal before it could be sold.
|
|
984
|
-
- **`H` ≥
|
|
993
|
+
- **`H` ≥ 46 520:** `embargo = REG_COMMIT_MAX_BLOCKS` (8 blocks, ≈ 16 min). Under §28/§29 a finalized
|
|
985
994
|
name is displacement-immune the moment its freeze passes, so out-aging the old 240-block window is
|
|
986
995
|
redundant; 8 matches the freeze itself.
|
|
987
|
-
- The gate keys on the OFFER's height, so the same young name can be unsellable at
|
|
988
|
-
at
|
|
996
|
+
- The gate keys on the OFFER's height, so the same young name can be unsellable at 46 519 and sellable
|
|
997
|
+
at 46 521. Deterministic for every replayer; no name-age era bookkeeping is needed.
|
|
989
998
|
- **Adoption note:** a relaxation (fresh cores accept a sale a stale core no-ops), so every replayer must
|
|
990
|
-
run the v2.7 core before the tip crosses
|
|
999
|
+
run the v2.7 core before the tip crosses 46 520.
|
package/MAKERS.md
CHANGED
|
@@ -1,10 +1,14 @@
|
|
|
1
1
|
# Run a CairnX market maker
|
|
2
2
|
|
|
3
|
-
CairnX has **no AMM and no escrow
|
|
3
|
+
CairnX has **no AMM and no escrow**; native CSD can't be pooled (CONVENTION §6). Liquidity is whoever
|
|
4
4
|
runs a *maker loop*. This guide is everything you need to join as a market maker, end to end. Anyone
|
|
5
5
|
may run one, against any token, with their own key. It builds only on the public package
|
|
6
6
|
[`@inversealtruism/cairnx-core`](https://www.npmjs.com/package/@inversealtruism/cairnx-core).
|
|
7
7
|
|
|
8
|
+
> Sibling doc: the `cairnx` app repo ships a repo-centric **Maker Kit** (`cairnx/MAKERS.md`) covering
|
|
9
|
+
> the reference `mm-bot` implementation, its config, and ops runbook. The two are different documents
|
|
10
|
+
> for different audiences by design, not drifted copies of one file.
|
|
11
|
+
|
|
8
12
|
## How the market works (RFQ)
|
|
9
13
|
|
|
10
14
|
Post-v1.3 the CSD-priced market **is** an RFQ loop (CONVENTION §13/§15):
|
package/README.md
CHANGED
|
@@ -131,8 +131,8 @@ stateDiagram-v2
|
|
|
131
131
|
| Lease term | ~1 year (`NAME_TERM_EPOCHS = 8760`) | 1 epoch ≈ 1 h (30 blocks) |
|
|
132
132
|
| Grace window | ~30 days (`NAME_GRACE_EPOCHS = 720`) | owner-only renewal |
|
|
133
133
|
| Recapture premium | **20× → 1×** over ~30 days | decaying Dutch auction on lapsed names |
|
|
134
|
-
| Reveal window | ~
|
|
135
|
-
| Registration fee | **
|
|
134
|
+
| Reveal window | ~16 min (`REG_COMMIT_MAX_BLOCKS = 8`, v2.5+; was 240 blocks below v2.5) | commit-reveal deadline; doubles as the displacement freeze |
|
|
135
|
+
| Registration fee | **15 / 10 / 5 / 3 CSD** by length (≤3 / 4 / 5-9 / ≥10 chars, v2.4) | length-graded (was flat 6.7 / 3 CSD under v1.8); paid to the treasury at finalize (v2.5+) |
|
|
136
136
|
|
|
137
137
|
### 2.4 · How a name resolves, and what's actually *verified*
|
|
138
138
|
|
|
@@ -249,12 +249,23 @@ is bounded in the light client, not the chain.
|
|
|
249
249
|
| v1.8 | 40 000 | flat two-tier name fee (6.7 / 3 CSD) |
|
|
250
250
|
| v2.1 | 40 100 | offer/bid duration cap (`MAX_OFFER_EPOCHS = 168`), *superseded by v2.2* |
|
|
251
251
|
| v2.2 | 41 300 | duration cap **removed from consensus** → UI policy; bound moves to the light client |
|
|
252
|
+
| v2.4 | 46 400 | length-graded registration fee (15 / 10 / 5 / 3 CSD by name length) |
|
|
253
|
+
| v2.5 | 46 440 | sealed-reservation registration: payment-free reveal, winner-only fee at `nfinalize` |
|
|
254
|
+
| v2.6 | 46 480 | sealed-reservation recapture (lapsed-name premium paid by the settled winner only) |
|
|
255
|
+
| v2.7 | 46 520 | young-name sale embargo shrinks 240 → 8 blocks |
|
|
256
|
+
| v2.3 | 52 000 | `nset` to the zero address CLEARS the pointer (*still pending as of 2026-07-06, tip ~48 300*) |
|
|
257
|
+
|
|
258
|
+
v2.4–v2.7 were re-pinned 2026-07-03 from their originally published heights (49 200 / 51 000 / 51 200 /
|
|
259
|
+
52 500) — see the re-pin history note in `CONVENTION.md` and `CONSENSUS_CHANGES.md` 0.1.33.
|
|
252
260
|
|
|
253
261
|
### Package layout
|
|
254
262
|
|
|
255
263
|
`src/resolve.ts` (the ledger) · `src/records.ts` (the parse/validate gate) · `src/types.ts` (constants +
|
|
256
|
-
height-gated client selectors) · `src/client.ts` (reorg-safety helpers a payer applies) · `
|
|
257
|
-
(
|
|
264
|
+
height-gated client selectors) · `src/client.ts` (reorg-safety helpers a payer applies) · `src/preflight.ts`
|
|
265
|
+
(build-side helpers every host must compute identically: `requiredFillOutputs`, `previewFill`/`fillIsSafe`,
|
|
266
|
+
`buildFeeHeight` + `NAME_FEE_GATES`, `finalizeWinnerCheck`) · `src/primary.ts` (`pickPrimaryName` /
|
|
267
|
+
`primaryRankBefore`, the one primary-name selection every host must agree on) · `CONVENTION.md`
|
|
268
|
+
(normative spec, §1–§30) · `test/vectors/` (portable conformance corpus).
|
|
258
269
|
|
|
259
270
|
### Use it
|
|
260
271
|
|
|
@@ -277,8 +288,8 @@ console.log(state.names, state.tokens.CAIRN, state.balances.CAIRN);
|
|
|
277
288
|
|
|
278
289
|
### Write a conformant resolver in another language
|
|
279
290
|
|
|
280
|
-
1. Implement `CONVENTION.md` §1–§
|
|
281
|
-
canonical-state format, ordinal key ordering, data surface only).
|
|
291
|
+
1. Implement `CONVENTION.md` §1–§30 (apply order, every record type, the `V*_HEIGHT` activations — using
|
|
292
|
+
the re-pinned v2.4–v2.7 heights — the canonical-state format, ordinal key ordering, data surface only).
|
|
282
293
|
2. Replay `test/vectors/cases.json`: your canonical state must equal `expectedState` **byte-for-byte**.
|
|
283
294
|
3. Replay the live chain and compare `sha256(canonicalState)` against `test/vectors/replay-hashes.json`.
|
|
284
295
|
|
package/dist/index.cjs
CHANGED
|
@@ -39,6 +39,7 @@ __export(index_exports, {
|
|
|
39
39
|
EPOCH_LEN: () => import_csd_codec4.EPOCH_LEN,
|
|
40
40
|
FEE_BPS: () => FEE_BPS,
|
|
41
41
|
FEE_BPS_V16: () => FEE_BPS_V16,
|
|
42
|
+
FEE_GATE_MARGIN_BLOCKS: () => FEE_GATE_MARGIN_BLOCKS,
|
|
42
43
|
FINALIZE_TIP_MARGIN: () => FINALIZE_TIP_MARGIN,
|
|
43
44
|
HALVING_INTERVAL: () => import_csd_codec4.HALVING_INTERVAL,
|
|
44
45
|
HASH_RE: () => HASH_RE,
|
|
@@ -101,6 +102,7 @@ __export(index_exports, {
|
|
|
101
102
|
ZERO_ADDR: () => ZERO_ADDR,
|
|
102
103
|
bid: () => bid,
|
|
103
104
|
blockReward: () => import_csd_codec4.blockReward,
|
|
105
|
+
buildFeeHeight: () => buildFeeHeight,
|
|
104
106
|
buildRecord: () => buildRecord,
|
|
105
107
|
canonicalJson: () => import_csd_codec4.canonicalJson,
|
|
106
108
|
canonicalState: () => canonicalState,
|
|
@@ -135,8 +137,11 @@ __export(index_exports, {
|
|
|
135
137
|
parseAmount: () => parseAmount,
|
|
136
138
|
parseRecord: () => parseRecord,
|
|
137
139
|
payloadHash: () => import_csd_codec4.payloadHash,
|
|
140
|
+
pickPrimaryName: () => pickPrimaryName,
|
|
138
141
|
previewFill: () => previewFill,
|
|
142
|
+
primaryRankBefore: () => primaryRankBefore,
|
|
139
143
|
requiredClaimDepth: () => requiredClaimDepth,
|
|
144
|
+
requiredFillOutputs: () => requiredFillOutputs,
|
|
140
145
|
resolve: () => resolve,
|
|
141
146
|
tokenMeta: () => tokenMeta,
|
|
142
147
|
tradeFee: () => tradeFee,
|
|
@@ -1438,6 +1443,29 @@ function previewFill(offer2, payRaw) {
|
|
|
1438
1443
|
const got = isNameGive(offer2.give) ? 1n : BigInt(offer2.give.amount);
|
|
1439
1444
|
return { deliverable: true, reason: "ok", got, pay: want, fee, rebate };
|
|
1440
1445
|
}
|
|
1446
|
+
function requiredFillOutputs(offer2, payRaw) {
|
|
1447
|
+
if (isTokenWant(offer2.want)) return [];
|
|
1448
|
+
const p = previewFill(offer2, payRaw);
|
|
1449
|
+
if (!p.deliverable) return null;
|
|
1450
|
+
const need = /* @__PURE__ */ new Map();
|
|
1451
|
+
const add = (a, v) => {
|
|
1452
|
+
if (v > 0n) {
|
|
1453
|
+
const k = a.toLowerCase();
|
|
1454
|
+
need.set(k, (need.get(k) ?? 0n) + v);
|
|
1455
|
+
}
|
|
1456
|
+
};
|
|
1457
|
+
add(offer2.want.payto, p.pay);
|
|
1458
|
+
add(TREASURY_ADDR, p.fee);
|
|
1459
|
+
add(offer2.seller, p.rebate);
|
|
1460
|
+
return [...need].map(([to, value]) => ({ to, value }));
|
|
1461
|
+
}
|
|
1462
|
+
var FEE_GATE_MARGIN_BLOCKS = 5;
|
|
1463
|
+
var NAME_FEE_GATES = [V18_HEIGHT, V24_HEIGHT];
|
|
1464
|
+
var buildFeeHeight = (tip) => {
|
|
1465
|
+
const t = Number(tip);
|
|
1466
|
+
for (const g of NAME_FEE_GATES) if (t < g && t >= g - FEE_GATE_MARGIN_BLOCKS) return g;
|
|
1467
|
+
return t;
|
|
1468
|
+
};
|
|
1441
1469
|
function isOpenClaimLane(offer2, tip) {
|
|
1442
1470
|
return tip >= V13_HEIGHT && offer2.taker === void 0 && !isTokenWant(offer2.want);
|
|
1443
1471
|
}
|
|
@@ -1462,16 +1490,39 @@ function fillIsSafe(offer2, me, pay, tip) {
|
|
|
1462
1490
|
}
|
|
1463
1491
|
return { safe: true, reason: "ok", preview };
|
|
1464
1492
|
}
|
|
1465
|
-
function finalizeWinnerCheck(nameState, me, commitHeight) {
|
|
1493
|
+
function finalizeWinnerCheck(nameState, me, commitHeight, tip) {
|
|
1466
1494
|
const m = me.toLowerCase();
|
|
1467
1495
|
if (!nameState) return { safe: false, reason: "no reservation on-chain (displaced, swept, or never accepted) \u2014 a finalize now would burn the fee" };
|
|
1468
1496
|
if (nameState.owner?.toLowerCase() !== m) return { safe: false, reason: "an earlier committer won this name \u2014 you were outbid" };
|
|
1469
1497
|
if (nameState.pending !== true) return { safe: false, reason: "already registered to you \u2014 no second finalize fee is needed" };
|
|
1470
1498
|
if (Number(nameState.effectiveHeight) !== Number(commitHeight))
|
|
1471
1499
|
return { safe: false, reason: "your reservation was displaced (effective height changed) \u2014 a finalize now would burn the fee" };
|
|
1500
|
+
if (tip !== void 0 && tip !== null && Number.isFinite(Number(tip))) {
|
|
1501
|
+
const t = Number(tip);
|
|
1502
|
+
const eff = Number(nameState.effectiveHeight);
|
|
1503
|
+
const freezeEnd = eff + REG_COMMIT_MAX_BLOCKS;
|
|
1504
|
+
const closeAt = eff + REG_COMMIT_MAX_BLOCKS + REG_FINALIZE_GRACE_BLOCKS - FINALIZE_TIP_MARGIN;
|
|
1505
|
+
if (t <= freezeEnd + FINALIZE_TIP_MARGIN)
|
|
1506
|
+
return { safe: false, reason: `too early \u2014 the displacement contest is not frozen yet (finalizable after block ${freezeEnd + FINALIZE_TIP_MARGIN}, chain tip ${t}); the resolver would reject the finalize after the fee moved, burning it` };
|
|
1507
|
+
if (t > closeAt)
|
|
1508
|
+
return { safe: false, reason: `this reservation's finalize window has closed (safe until block ${closeAt}, chain tip ${t}); a finalize now would mine past the deadline and burn the fee` };
|
|
1509
|
+
}
|
|
1472
1510
|
return { safe: true, reason: "ok" };
|
|
1473
1511
|
}
|
|
1474
1512
|
|
|
1513
|
+
// src/primary.ts
|
|
1514
|
+
var primaryRankBefore = (a, b) => a.effectiveHeight < b.effectiveHeight || a.effectiveHeight === b.effectiveHeight && a.claimId < b.claimId;
|
|
1515
|
+
function pickPrimaryName(names, a) {
|
|
1516
|
+
const q = String(a).toLowerCase();
|
|
1517
|
+
let best = null;
|
|
1518
|
+
for (const n of names) {
|
|
1519
|
+
if (n.owner !== q || n.addr !== q) continue;
|
|
1520
|
+
if (n.expired === true || n.locked) continue;
|
|
1521
|
+
if (!best || primaryRankBefore(n, best)) best = n;
|
|
1522
|
+
}
|
|
1523
|
+
return best ? best.name : null;
|
|
1524
|
+
}
|
|
1525
|
+
|
|
1475
1526
|
// src/paidto.ts
|
|
1476
1527
|
function paidToFromOutputs(outputs) {
|
|
1477
1528
|
const m = /* @__PURE__ */ Object.create(null);
|
|
@@ -1505,6 +1556,7 @@ var import_csd_codec4 = require("@inversealtruism/csd-codec");
|
|
|
1505
1556
|
EPOCH_LEN,
|
|
1506
1557
|
FEE_BPS,
|
|
1507
1558
|
FEE_BPS_V16,
|
|
1559
|
+
FEE_GATE_MARGIN_BLOCKS,
|
|
1508
1560
|
FINALIZE_TIP_MARGIN,
|
|
1509
1561
|
HALVING_INTERVAL,
|
|
1510
1562
|
HASH_RE,
|
|
@@ -1567,6 +1619,7 @@ var import_csd_codec4 = require("@inversealtruism/csd-codec");
|
|
|
1567
1619
|
ZERO_ADDR,
|
|
1568
1620
|
bid,
|
|
1569
1621
|
blockReward,
|
|
1622
|
+
buildFeeHeight,
|
|
1570
1623
|
buildRecord,
|
|
1571
1624
|
canonicalJson,
|
|
1572
1625
|
canonicalState,
|
|
@@ -1601,8 +1654,11 @@ var import_csd_codec4 = require("@inversealtruism/csd-codec");
|
|
|
1601
1654
|
parseAmount,
|
|
1602
1655
|
parseRecord,
|
|
1603
1656
|
payloadHash,
|
|
1657
|
+
pickPrimaryName,
|
|
1604
1658
|
previewFill,
|
|
1659
|
+
primaryRankBefore,
|
|
1605
1660
|
requiredClaimDepth,
|
|
1661
|
+
requiredFillOutputs,
|
|
1606
1662
|
resolve,
|
|
1607
1663
|
tokenMeta,
|
|
1608
1664
|
tradeFee,
|
package/dist/index.d.cts
CHANGED
|
@@ -448,6 +448,32 @@ interface FillPreview {
|
|
|
448
448
|
}
|
|
449
449
|
/** Preview a fill of `offer` paying `payRaw` CSD base units to the seller. Pure; no I/O. */
|
|
450
450
|
declare function previewFill(offer: OfferState, payRaw: bigint | string | number): FillPreview;
|
|
451
|
+
/** The exact CSD outputs a fill of `offer` paying `payRaw` must carry to clear the resolver's value
|
|
452
|
+
* gate — the addr→sum map of resolve.ts:699-712 (whole: payto + treasury fee + maker rebate) and
|
|
453
|
+
* :643-649 (partial: clamped payment + fee on the clamped amount, NO rebate), as a build-ready output
|
|
454
|
+
* list. Amounts are ACCUMULATED per address (payto === seller is the common case; the resolver checks
|
|
455
|
+
* the per-address SUM, so two merged entries must merge here too), insertion order payto → treasury →
|
|
456
|
+
* seller, zero-value entries omitted (a 0 output is unbuildable and the resolver requires nothing).
|
|
457
|
+
*
|
|
458
|
+
* Returns [] for a token-priced offer (a token⇄token fill carries NO CSD outputs) and null when the
|
|
459
|
+
* payment is undeliverable — gate with fillIsSafe FIRST; this sizes outputs, it does not re-judge
|
|
460
|
+
* claims/takers. Until 2026-07-06 this map was hand-mirrored in the wallet's fillOffer, the cairnx
|
|
461
|
+
* service txbuild, and TWICE in the cairn trade UI — four copies of fund-loss-class math with no
|
|
462
|
+
* cross-repo lock. This is now the only place it lives; test/preflight.test.ts pins it against the
|
|
463
|
+
* real resolver (outputs accepted; any single-unit per-address underpayment refused). */
|
|
464
|
+
declare function requiredFillOutputs(offer: OfferState, payRaw: bigint | string | number): {
|
|
465
|
+
to: string;
|
|
466
|
+
value: bigint;
|
|
467
|
+
}[] | null;
|
|
468
|
+
/** Name-fee build heuristic (app-side, NOT a resolver rule): a name-fee OUTPUT built just below a fee
|
|
469
|
+
* gate but mined at/after it underpays the new tier → resolver rejects → the treasury-fee UTXO is
|
|
470
|
+
* forfeit. Within FEE_GATE_MARGIN_BLOCKS below ANY upcoming fee gate, price the BUILD at that gate:
|
|
471
|
+
* overpay is always accepted (the resolver gate is strict `<`), so this only ever PREVENTS a forfeit,
|
|
472
|
+
* never causes one. Display paths must pass the SAME buildFeeHeight(tip) so the quoted price matches
|
|
473
|
+
* what gets signed. Owns the gate list: a future fee tier (V28+) is added HERE, once — the wallet and
|
|
474
|
+
* the trade UI import this (they each hand-carried a copy of this function + list until 2026-07-06). */
|
|
475
|
+
declare const FEE_GATE_MARGIN_BLOCKS = 5;
|
|
476
|
+
declare const buildFeeHeight: (tip: number) => number;
|
|
451
477
|
/** Is the offer an OPEN (untaken) CSD-priced offer subject to the v1.7 claim-to-fill gate at `tip`?
|
|
452
478
|
* Such an offer may be filled ONLY by the holder of a LIVE claim (resolve.ts openFillReject:166-171). */
|
|
453
479
|
declare function isOpenClaimLane(offer: OfferState, tip: number): boolean;
|
|
@@ -466,20 +492,35 @@ interface FillSafety {
|
|
|
466
492
|
}
|
|
467
493
|
declare function fillIsSafe(offer: OfferState, me: string, pay: bigint | string | number, tip: number): FillSafety;
|
|
468
494
|
/** C1: may `me` safely sign the fee-bearing registration `nfinalize` for `nameState` committed at
|
|
469
|
-
* `commitHeight`? The reg fee rides nfinalize; a finalize on a reservation that was displaced
|
|
470
|
-
* expired is REJECTED after the fee moved (a burn).
|
|
471
|
-
* for `tip > effectiveHeight + REG_COMMIT_MAX_BLOCKS`
|
|
472
|
-
* new displacer can appear, so a re-fetch showing "still my live pending reservation at my commit
|
|
473
|
-
* guarantees the finalize lands. Pass the AUTHORITATIVE (freshly re-fetched) name record — never
|
|
474
|
-
* one — as `nameState` (undefined = the resolver returns 404 / unregistered,
|
|
475
|
-
|
|
495
|
+
* `commitHeight`? The reg fee rides nfinalize; a finalize on a reservation that was displaced, has
|
|
496
|
+
* expired, OR is raised before the displacement contest froze is REJECTED after the fee moved (a burn).
|
|
497
|
+
* Sound by the freeze arithmetic: once a client waits for `tip > effectiveHeight + REG_COMMIT_MAX_BLOCKS`
|
|
498
|
+
* no new displacer can appear, so a re-fetch showing "still my live pending reservation at my commit
|
|
499
|
+
* height" guarantees the finalize lands. Pass the AUTHORITATIVE (freshly re-fetched) name record — never
|
|
500
|
+
* a cached one — as `nameState` (undefined = the resolver returns 404 / unregistered, a definitive loss).
|
|
501
|
+
*
|
|
502
|
+
* Pass `tip` (the freshest chain tip you have) to ALSO gate the finalize WINDOW, both sides, mirroring
|
|
503
|
+
* the resolver's authoritative checks (resolve.ts nfinalize: rejects unless
|
|
504
|
+
* `ev.height > effHeight + REG_COMMIT_MAX_BLOCKS`, and rejects when `ev.height > finalizeBy`) with the
|
|
505
|
+
* client-side FINALIZE_TIP_MARGIN band the site's finalizeReady applies: the tx signs at `tip` but mines
|
|
506
|
+
* at tip+1 or later, so the margin keeps a boundary-signed finalize from mining outside the window (too
|
|
507
|
+
* early: rejected as unfrozen; too late: past the deadline — either way the fee burned). `tip` is
|
|
508
|
+
* optional so callers without a tip keep the winner-only semantics; N-2 closes only when it is passed. */
|
|
509
|
+
declare function finalizeWinnerCheck(nameState: NameState | null | undefined, me: string, commitHeight: number, tip?: number | null): {
|
|
476
510
|
safe: boolean;
|
|
477
511
|
reason: string;
|
|
478
512
|
};
|
|
479
513
|
|
|
514
|
+
/** The resolver's total order over primary-name candidates: does `a` outrank `b`?
|
|
515
|
+
* Lowest effectiveHeight wins; ties break by ordinal (code-unit) claimId. Exported separately because
|
|
516
|
+
* the trade UI's primary-SWITCH planner needs the comparator against a target, not the selection. */
|
|
517
|
+
declare const primaryRankBefore: (a: NameState, b: NameState) => boolean;
|
|
518
|
+
/** The primary .csd name for address `a`, or null. Pure; no I/O. `a` may be any case. */
|
|
519
|
+
declare function pickPrimaryName(names: Iterable<NameState>, a: string): string | null;
|
|
520
|
+
|
|
480
521
|
declare function paidToFromOutputs(outputs: readonly {
|
|
481
522
|
addr: string;
|
|
482
523
|
value: number;
|
|
483
524
|
}[]): Record<string, string>;
|
|
484
525
|
|
|
485
|
-
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 FillPreview, type FillSafety, 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, V27_HEIGHT, type Want, ZERO_ADDR, bid, buildRecord, canonicalState, claimGraceOf, claimWindowAt, claimWindowOf, deploy, epochOf, expiredClaimFee, fillIsSafe, finalizeWinnerCheck, hasLiveClaim, isName, isNameGive, isOpenClaimLane, isTokenWant, makerRebate, mint, nameClaim, nameCommit, nameCommitRecord, nameFinalize, nameProfile, nameRegFee, nameRenew, nameSet, nameXfer, offer, offerCancelAll, offerExpiryHeightOf, paidToFromOutputs, parseAmount, parseRecord, previewFill, requiredClaimDepth, resolve, tokenMeta, tradeFee, transfer };
|
|
526
|
+
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, FEE_GATE_MARGIN_BLOCKS, FINALIZE_TIP_MARGIN, type FillEntry, type FillPreview, type FillSafety, 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, V27_HEIGHT, type Want, ZERO_ADDR, bid, buildFeeHeight, buildRecord, canonicalState, claimGraceOf, claimWindowAt, claimWindowOf, deploy, epochOf, expiredClaimFee, fillIsSafe, finalizeWinnerCheck, hasLiveClaim, isName, isNameGive, isOpenClaimLane, isTokenWant, makerRebate, mint, nameClaim, nameCommit, nameCommitRecord, nameFinalize, nameProfile, nameRegFee, nameRenew, nameSet, nameXfer, offer, offerCancelAll, offerExpiryHeightOf, paidToFromOutputs, parseAmount, parseRecord, pickPrimaryName, previewFill, primaryRankBefore, requiredClaimDepth, requiredFillOutputs, resolve, tokenMeta, tradeFee, transfer };
|
package/dist/index.d.ts
CHANGED
|
@@ -448,6 +448,32 @@ interface FillPreview {
|
|
|
448
448
|
}
|
|
449
449
|
/** Preview a fill of `offer` paying `payRaw` CSD base units to the seller. Pure; no I/O. */
|
|
450
450
|
declare function previewFill(offer: OfferState, payRaw: bigint | string | number): FillPreview;
|
|
451
|
+
/** The exact CSD outputs a fill of `offer` paying `payRaw` must carry to clear the resolver's value
|
|
452
|
+
* gate — the addr→sum map of resolve.ts:699-712 (whole: payto + treasury fee + maker rebate) and
|
|
453
|
+
* :643-649 (partial: clamped payment + fee on the clamped amount, NO rebate), as a build-ready output
|
|
454
|
+
* list. Amounts are ACCUMULATED per address (payto === seller is the common case; the resolver checks
|
|
455
|
+
* the per-address SUM, so two merged entries must merge here too), insertion order payto → treasury →
|
|
456
|
+
* seller, zero-value entries omitted (a 0 output is unbuildable and the resolver requires nothing).
|
|
457
|
+
*
|
|
458
|
+
* Returns [] for a token-priced offer (a token⇄token fill carries NO CSD outputs) and null when the
|
|
459
|
+
* payment is undeliverable — gate with fillIsSafe FIRST; this sizes outputs, it does not re-judge
|
|
460
|
+
* claims/takers. Until 2026-07-06 this map was hand-mirrored in the wallet's fillOffer, the cairnx
|
|
461
|
+
* service txbuild, and TWICE in the cairn trade UI — four copies of fund-loss-class math with no
|
|
462
|
+
* cross-repo lock. This is now the only place it lives; test/preflight.test.ts pins it against the
|
|
463
|
+
* real resolver (outputs accepted; any single-unit per-address underpayment refused). */
|
|
464
|
+
declare function requiredFillOutputs(offer: OfferState, payRaw: bigint | string | number): {
|
|
465
|
+
to: string;
|
|
466
|
+
value: bigint;
|
|
467
|
+
}[] | null;
|
|
468
|
+
/** Name-fee build heuristic (app-side, NOT a resolver rule): a name-fee OUTPUT built just below a fee
|
|
469
|
+
* gate but mined at/after it underpays the new tier → resolver rejects → the treasury-fee UTXO is
|
|
470
|
+
* forfeit. Within FEE_GATE_MARGIN_BLOCKS below ANY upcoming fee gate, price the BUILD at that gate:
|
|
471
|
+
* overpay is always accepted (the resolver gate is strict `<`), so this only ever PREVENTS a forfeit,
|
|
472
|
+
* never causes one. Display paths must pass the SAME buildFeeHeight(tip) so the quoted price matches
|
|
473
|
+
* what gets signed. Owns the gate list: a future fee tier (V28+) is added HERE, once — the wallet and
|
|
474
|
+
* the trade UI import this (they each hand-carried a copy of this function + list until 2026-07-06). */
|
|
475
|
+
declare const FEE_GATE_MARGIN_BLOCKS = 5;
|
|
476
|
+
declare const buildFeeHeight: (tip: number) => number;
|
|
451
477
|
/** Is the offer an OPEN (untaken) CSD-priced offer subject to the v1.7 claim-to-fill gate at `tip`?
|
|
452
478
|
* Such an offer may be filled ONLY by the holder of a LIVE claim (resolve.ts openFillReject:166-171). */
|
|
453
479
|
declare function isOpenClaimLane(offer: OfferState, tip: number): boolean;
|
|
@@ -466,20 +492,35 @@ interface FillSafety {
|
|
|
466
492
|
}
|
|
467
493
|
declare function fillIsSafe(offer: OfferState, me: string, pay: bigint | string | number, tip: number): FillSafety;
|
|
468
494
|
/** C1: may `me` safely sign the fee-bearing registration `nfinalize` for `nameState` committed at
|
|
469
|
-
* `commitHeight`? The reg fee rides nfinalize; a finalize on a reservation that was displaced
|
|
470
|
-
* expired is REJECTED after the fee moved (a burn).
|
|
471
|
-
* for `tip > effectiveHeight + REG_COMMIT_MAX_BLOCKS`
|
|
472
|
-
* new displacer can appear, so a re-fetch showing "still my live pending reservation at my commit
|
|
473
|
-
* guarantees the finalize lands. Pass the AUTHORITATIVE (freshly re-fetched) name record — never
|
|
474
|
-
* one — as `nameState` (undefined = the resolver returns 404 / unregistered,
|
|
475
|
-
|
|
495
|
+
* `commitHeight`? The reg fee rides nfinalize; a finalize on a reservation that was displaced, has
|
|
496
|
+
* expired, OR is raised before the displacement contest froze is REJECTED after the fee moved (a burn).
|
|
497
|
+
* Sound by the freeze arithmetic: once a client waits for `tip > effectiveHeight + REG_COMMIT_MAX_BLOCKS`
|
|
498
|
+
* no new displacer can appear, so a re-fetch showing "still my live pending reservation at my commit
|
|
499
|
+
* height" guarantees the finalize lands. Pass the AUTHORITATIVE (freshly re-fetched) name record — never
|
|
500
|
+
* a cached one — as `nameState` (undefined = the resolver returns 404 / unregistered, a definitive loss).
|
|
501
|
+
*
|
|
502
|
+
* Pass `tip` (the freshest chain tip you have) to ALSO gate the finalize WINDOW, both sides, mirroring
|
|
503
|
+
* the resolver's authoritative checks (resolve.ts nfinalize: rejects unless
|
|
504
|
+
* `ev.height > effHeight + REG_COMMIT_MAX_BLOCKS`, and rejects when `ev.height > finalizeBy`) with the
|
|
505
|
+
* client-side FINALIZE_TIP_MARGIN band the site's finalizeReady applies: the tx signs at `tip` but mines
|
|
506
|
+
* at tip+1 or later, so the margin keeps a boundary-signed finalize from mining outside the window (too
|
|
507
|
+
* early: rejected as unfrozen; too late: past the deadline — either way the fee burned). `tip` is
|
|
508
|
+
* optional so callers without a tip keep the winner-only semantics; N-2 closes only when it is passed. */
|
|
509
|
+
declare function finalizeWinnerCheck(nameState: NameState | null | undefined, me: string, commitHeight: number, tip?: number | null): {
|
|
476
510
|
safe: boolean;
|
|
477
511
|
reason: string;
|
|
478
512
|
};
|
|
479
513
|
|
|
514
|
+
/** The resolver's total order over primary-name candidates: does `a` outrank `b`?
|
|
515
|
+
* Lowest effectiveHeight wins; ties break by ordinal (code-unit) claimId. Exported separately because
|
|
516
|
+
* the trade UI's primary-SWITCH planner needs the comparator against a target, not the selection. */
|
|
517
|
+
declare const primaryRankBefore: (a: NameState, b: NameState) => boolean;
|
|
518
|
+
/** The primary .csd name for address `a`, or null. Pure; no I/O. `a` may be any case. */
|
|
519
|
+
declare function pickPrimaryName(names: Iterable<NameState>, a: string): string | null;
|
|
520
|
+
|
|
480
521
|
declare function paidToFromOutputs(outputs: readonly {
|
|
481
522
|
addr: string;
|
|
482
523
|
value: number;
|
|
483
524
|
}[]): Record<string, string>;
|
|
484
525
|
|
|
485
|
-
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 FillPreview, type FillSafety, 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, V27_HEIGHT, type Want, ZERO_ADDR, bid, buildRecord, canonicalState, claimGraceOf, claimWindowAt, claimWindowOf, deploy, epochOf, expiredClaimFee, fillIsSafe, finalizeWinnerCheck, hasLiveClaim, isName, isNameGive, isOpenClaimLane, isTokenWant, makerRebate, mint, nameClaim, nameCommit, nameCommitRecord, nameFinalize, nameProfile, nameRegFee, nameRenew, nameSet, nameXfer, offer, offerCancelAll, offerExpiryHeightOf, paidToFromOutputs, parseAmount, parseRecord, previewFill, requiredClaimDepth, resolve, tokenMeta, tradeFee, transfer };
|
|
526
|
+
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, FEE_GATE_MARGIN_BLOCKS, FINALIZE_TIP_MARGIN, type FillEntry, type FillPreview, type FillSafety, 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, V27_HEIGHT, type Want, ZERO_ADDR, bid, buildFeeHeight, buildRecord, canonicalState, claimGraceOf, claimWindowAt, claimWindowOf, deploy, epochOf, expiredClaimFee, fillIsSafe, finalizeWinnerCheck, hasLiveClaim, isName, isNameGive, isOpenClaimLane, isTokenWant, makerRebate, mint, nameClaim, nameCommit, nameCommitRecord, nameFinalize, nameProfile, nameRegFee, nameRenew, nameSet, nameXfer, offer, offerCancelAll, offerExpiryHeightOf, paidToFromOutputs, parseAmount, parseRecord, pickPrimaryName, previewFill, primaryRankBefore, requiredClaimDepth, requiredFillOutputs, resolve, tokenMeta, tradeFee, transfer };
|
package/dist/index.js
CHANGED
|
@@ -1292,6 +1292,29 @@ function previewFill(offer2, payRaw) {
|
|
|
1292
1292
|
const got = isNameGive(offer2.give) ? 1n : BigInt(offer2.give.amount);
|
|
1293
1293
|
return { deliverable: true, reason: "ok", got, pay: want, fee, rebate };
|
|
1294
1294
|
}
|
|
1295
|
+
function requiredFillOutputs(offer2, payRaw) {
|
|
1296
|
+
if (isTokenWant(offer2.want)) return [];
|
|
1297
|
+
const p = previewFill(offer2, payRaw);
|
|
1298
|
+
if (!p.deliverable) return null;
|
|
1299
|
+
const need = /* @__PURE__ */ new Map();
|
|
1300
|
+
const add = (a, v) => {
|
|
1301
|
+
if (v > 0n) {
|
|
1302
|
+
const k = a.toLowerCase();
|
|
1303
|
+
need.set(k, (need.get(k) ?? 0n) + v);
|
|
1304
|
+
}
|
|
1305
|
+
};
|
|
1306
|
+
add(offer2.want.payto, p.pay);
|
|
1307
|
+
add(TREASURY_ADDR, p.fee);
|
|
1308
|
+
add(offer2.seller, p.rebate);
|
|
1309
|
+
return [...need].map(([to, value]) => ({ to, value }));
|
|
1310
|
+
}
|
|
1311
|
+
var FEE_GATE_MARGIN_BLOCKS = 5;
|
|
1312
|
+
var NAME_FEE_GATES = [V18_HEIGHT, V24_HEIGHT];
|
|
1313
|
+
var buildFeeHeight = (tip) => {
|
|
1314
|
+
const t = Number(tip);
|
|
1315
|
+
for (const g of NAME_FEE_GATES) if (t < g && t >= g - FEE_GATE_MARGIN_BLOCKS) return g;
|
|
1316
|
+
return t;
|
|
1317
|
+
};
|
|
1295
1318
|
function isOpenClaimLane(offer2, tip) {
|
|
1296
1319
|
return tip >= V13_HEIGHT && offer2.taker === void 0 && !isTokenWant(offer2.want);
|
|
1297
1320
|
}
|
|
@@ -1316,16 +1339,39 @@ function fillIsSafe(offer2, me, pay, tip) {
|
|
|
1316
1339
|
}
|
|
1317
1340
|
return { safe: true, reason: "ok", preview };
|
|
1318
1341
|
}
|
|
1319
|
-
function finalizeWinnerCheck(nameState, me, commitHeight) {
|
|
1342
|
+
function finalizeWinnerCheck(nameState, me, commitHeight, tip) {
|
|
1320
1343
|
const m = me.toLowerCase();
|
|
1321
1344
|
if (!nameState) return { safe: false, reason: "no reservation on-chain (displaced, swept, or never accepted) \u2014 a finalize now would burn the fee" };
|
|
1322
1345
|
if (nameState.owner?.toLowerCase() !== m) return { safe: false, reason: "an earlier committer won this name \u2014 you were outbid" };
|
|
1323
1346
|
if (nameState.pending !== true) return { safe: false, reason: "already registered to you \u2014 no second finalize fee is needed" };
|
|
1324
1347
|
if (Number(nameState.effectiveHeight) !== Number(commitHeight))
|
|
1325
1348
|
return { safe: false, reason: "your reservation was displaced (effective height changed) \u2014 a finalize now would burn the fee" };
|
|
1349
|
+
if (tip !== void 0 && tip !== null && Number.isFinite(Number(tip))) {
|
|
1350
|
+
const t = Number(tip);
|
|
1351
|
+
const eff = Number(nameState.effectiveHeight);
|
|
1352
|
+
const freezeEnd = eff + REG_COMMIT_MAX_BLOCKS;
|
|
1353
|
+
const closeAt = eff + REG_COMMIT_MAX_BLOCKS + REG_FINALIZE_GRACE_BLOCKS - FINALIZE_TIP_MARGIN;
|
|
1354
|
+
if (t <= freezeEnd + FINALIZE_TIP_MARGIN)
|
|
1355
|
+
return { safe: false, reason: `too early \u2014 the displacement contest is not frozen yet (finalizable after block ${freezeEnd + FINALIZE_TIP_MARGIN}, chain tip ${t}); the resolver would reject the finalize after the fee moved, burning it` };
|
|
1356
|
+
if (t > closeAt)
|
|
1357
|
+
return { safe: false, reason: `this reservation's finalize window has closed (safe until block ${closeAt}, chain tip ${t}); a finalize now would mine past the deadline and burn the fee` };
|
|
1358
|
+
}
|
|
1326
1359
|
return { safe: true, reason: "ok" };
|
|
1327
1360
|
}
|
|
1328
1361
|
|
|
1362
|
+
// src/primary.ts
|
|
1363
|
+
var primaryRankBefore = (a, b) => a.effectiveHeight < b.effectiveHeight || a.effectiveHeight === b.effectiveHeight && a.claimId < b.claimId;
|
|
1364
|
+
function pickPrimaryName(names, a) {
|
|
1365
|
+
const q = String(a).toLowerCase();
|
|
1366
|
+
let best = null;
|
|
1367
|
+
for (const n of names) {
|
|
1368
|
+
if (n.owner !== q || n.addr !== q) continue;
|
|
1369
|
+
if (n.expired === true || n.locked) continue;
|
|
1370
|
+
if (!best || primaryRankBefore(n, best)) best = n;
|
|
1371
|
+
}
|
|
1372
|
+
return best ? best.name : null;
|
|
1373
|
+
}
|
|
1374
|
+
|
|
1329
1375
|
// src/paidto.ts
|
|
1330
1376
|
function paidToFromOutputs(outputs) {
|
|
1331
1377
|
const m = /* @__PURE__ */ Object.create(null);
|
|
@@ -1367,6 +1413,7 @@ export {
|
|
|
1367
1413
|
EPOCH_LEN2 as EPOCH_LEN,
|
|
1368
1414
|
FEE_BPS,
|
|
1369
1415
|
FEE_BPS_V16,
|
|
1416
|
+
FEE_GATE_MARGIN_BLOCKS,
|
|
1370
1417
|
FINALIZE_TIP_MARGIN,
|
|
1371
1418
|
HALVING_INTERVAL,
|
|
1372
1419
|
HASH_RE,
|
|
@@ -1429,6 +1476,7 @@ export {
|
|
|
1429
1476
|
ZERO_ADDR,
|
|
1430
1477
|
bid,
|
|
1431
1478
|
blockReward2 as blockReward,
|
|
1479
|
+
buildFeeHeight,
|
|
1432
1480
|
buildRecord,
|
|
1433
1481
|
canonicalJson2 as canonicalJson,
|
|
1434
1482
|
canonicalState,
|
|
@@ -1463,8 +1511,11 @@ export {
|
|
|
1463
1511
|
parseAmount,
|
|
1464
1512
|
parseRecord,
|
|
1465
1513
|
payloadHash2 as payloadHash,
|
|
1514
|
+
pickPrimaryName,
|
|
1466
1515
|
previewFill,
|
|
1516
|
+
primaryRankBefore,
|
|
1467
1517
|
requiredClaimDepth,
|
|
1518
|
+
requiredFillOutputs,
|
|
1468
1519
|
resolve,
|
|
1469
1520
|
tokenMeta,
|
|
1470
1521
|
tradeFee,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@inversealtruism/cairnx-core",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.36",
|
|
4
4
|
"engines": {
|
|
5
5
|
"node": ">=18"
|
|
6
6
|
},
|
|
@@ -45,6 +45,6 @@
|
|
|
45
45
|
"homepage": "https://cairn-substrate.com/trade",
|
|
46
46
|
"scripts": {
|
|
47
47
|
"build": "tsup src/index.ts --format esm,cjs --dts --clean",
|
|
48
|
-
"test": "tsx test/vectors.test.ts && tsx test/name-decoy.test.ts && tsx test/client-helpers.test.ts && tsx test/paidto.test.ts && tsx test/preflight.test.ts"
|
|
48
|
+
"test": "tsx test/vectors.test.ts && tsx test/name-decoy.test.ts && tsx test/client-helpers.test.ts && tsx test/paidto.test.ts && tsx test/preflight.test.ts && tsx test/primary.test.ts"
|
|
49
49
|
}
|
|
50
50
|
}
|