@inversealtruism/cairnx-core 0.1.43 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  // src/types.ts
2
- import { EPOCH_LEN } from "@inversealtruism/csd-codec";
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
5
  var V11_HEIGHT = 29960;
@@ -20,7 +20,7 @@ function expiredClaimFee(name, epochsPastGraceEnd, height) {
20
20
  const mult = 1n + (NAME_PREMIUM_START - 1n) * left / BigInt(NAME_PREMIUM_DECAY_EPOCHS);
21
21
  return base * mult;
22
22
  }
23
- var MAX_RECORD_BYTES = 512;
23
+ var MAX_RECORD_BYTES = MAX_URI_BYTES;
24
24
  var MAX_AMOUNT = (1n << 96n) - 1n;
25
25
  var SCORE_FILL = 100;
26
26
  var SCORE_CANCEL = 0;
@@ -92,7 +92,6 @@ var V26_HEIGHT = 46480;
92
92
  var V27_HEIGHT = 46520;
93
93
  var V28_HEIGHT = 6e4;
94
94
  var V29_HEIGHT = 88e3;
95
- var epochOf = (height) => Math.floor(height / EPOCH_LEN);
96
95
  var claimWindowAt = (height) => height >= V20_HEIGHT ? CLAIM_WINDOW_BLOCKS_V20 : CLAIM_WINDOW_BLOCKS;
97
96
  var FCLAIM_WINDOW_MIN = CLAIM_WINDOW_BLOCKS_V20 + CLAIM_FILL_GRACE_BLOCKS + 1;
98
97
  var claimWindowOf = (claimUntilHeight, claimTxid) => {
@@ -112,7 +111,7 @@ var isNameGive = (g) => typeof g.name === "string";
112
111
  var isTokenWant = (w) => typeof w.ticker === "string";
113
112
 
114
113
  // src/records.ts
115
- import { canonicalJson, payloadHash } from "@inversealtruism/csd-codec";
114
+ import { canonicalJson, payloadHash, isWellFormedUtf16 } from "@inversealtruism/csd-codec";
116
115
  function parseAmount(s, opts = {}) {
117
116
  if (typeof s !== "string" || !AMOUNT_RE.test(s)) return null;
118
117
  const v = BigInt(s);
@@ -127,27 +126,12 @@ var isName = (n) => typeof n === "string" && NAME_RE.test(n) && !RESERVED_NAMES.
127
126
  function nameCommit(name, salt, owner) {
128
127
  return payloadHash({ t: "cairnx:name:commit:v1", name, salt, owner: owner.toLowerCase() });
129
128
  }
130
- function strWellFormed(s) {
131
- const wf = String.prototype.isWellFormed;
132
- if (typeof wf === "function") return wf.call(s);
133
- for (let i = 0; i < s.length; i++) {
134
- const c = s.charCodeAt(i);
135
- if (c >= 55296 && c <= 56319) {
136
- const n = s.charCodeAt(i + 1);
137
- if (!(n >= 56320 && n <= 57343)) return false;
138
- i++;
139
- } else if (c >= 56320 && c <= 57343) {
140
- return false;
141
- }
142
- }
143
- return true;
144
- }
145
129
  function isWellFormedDeep(v) {
146
- if (typeof v === "string") return strWellFormed(v);
130
+ if (typeof v === "string") return isWellFormedUtf16(v);
147
131
  if (Array.isArray(v)) return v.every(isWellFormedDeep);
148
132
  if (v && typeof v === "object") {
149
133
  for (const [k, val] of Object.entries(v)) {
150
- if (!strWellFormed(k)) return false;
134
+ if (!isWellFormedUtf16(k)) return false;
151
135
  if (!isWellFormedDeep(val)) return false;
152
136
  }
153
137
  }
@@ -1709,10 +1693,10 @@ function bindOfferTerms(servedOffer, t, opts) {
1709
1693
  const om = o?.min;
1710
1694
  if ((om !== void 0 && om !== null) !== (t.min !== void 0)) return true;
1711
1695
  if (t.min !== void 0 && String(om) !== t.min) return true;
1712
- if (opts?.wantType) {
1696
+ if (opts?.wantType !== false) {
1713
1697
  if (t.wantType === void 0 || typeof o?.want?.ticker === "string" !== (t.wantType === "token")) return true;
1714
1698
  }
1715
- if (opts?.give) {
1699
+ if (opts?.give !== false) {
1716
1700
  const g = o?.give;
1717
1701
  if ((g?.ticker !== void 0 && g?.ticker !== null) !== (t.giveTicker !== void 0) || t.giveTicker !== void 0 && String(g?.ticker) !== t.giveTicker) return true;
1718
1702
  if ((g?.amount !== void 0 && g?.amount !== null) !== (t.giveAmount !== void 0) || t.giveAmount !== void 0 && String(g?.amount) !== t.giveAmount) return true;
@@ -1738,6 +1722,51 @@ function paidToFromOutputs(outputs) {
1738
1722
  }
1739
1723
  return m;
1740
1724
  }
1725
+ function burnedPayment(paidTo, payer, offer2) {
1726
+ const read = (addr) => addr === payer ? 0n : ptAmt(paidTo?.[addr]);
1727
+ let counterparty = 0n;
1728
+ if (offer2) {
1729
+ for (const addr of /* @__PURE__ */ new Set([offer2.seller, offer2.want.payto])) if (addr !== TREASURY_ADDR) counterparty += read(addr);
1730
+ }
1731
+ return { treasury: read(TREASURY_ADDR), counterparty };
1732
+ }
1733
+
1734
+ // src/fillclosed.ts
1735
+ var lc = (v) => String(v).toLowerCase();
1736
+ function myProvenFillClosedOffer(fill, fclaim2, offerEv, me, grantHeight) {
1737
+ if (!(grantHeight >= V29_HEIGHT)) return false;
1738
+ if (!fill || fill.kind !== "attest" || fill.score !== SCORE_FILL) return false;
1739
+ if (lc(fill.attester) !== lc(me) || lc(fill.proposalId) !== lc(fclaim2.id)) return false;
1740
+ if (!(fill.height > fclaim2.height && fill.height < grantHeight)) return false;
1741
+ if (!offerEv || offerEv.kind !== "propose" || lc(offerEv.id) !== lc(fclaim2.offer)) return false;
1742
+ const bound = bindProvenOffer(offerEv);
1743
+ const value = bound?.terms.value;
1744
+ if (!bound || value === void 0) return false;
1745
+ const t = bound.terms;
1746
+ const state = {
1747
+ id: lc(offerEv.id),
1748
+ seller: bound.seller,
1749
+ give: t.giveName !== void 0 ? { name: t.giveName } : { ticker: String(t.giveTicker ?? ""), amount: String(t.giveAmount ?? "") },
1750
+ want: { value, payto: bound.payto },
1751
+ status: "open",
1752
+ expiresEpoch: offerEv.expiresEpoch,
1753
+ height: t.height,
1754
+ feeBps: t.feeBps,
1755
+ taker: t.taker,
1756
+ bid: t.bid,
1757
+ min: t.min,
1758
+ paid: "0",
1759
+ delivered: "0"
1760
+ };
1761
+ let need;
1762
+ try {
1763
+ need = requiredFillOutputs(state, BigInt(value));
1764
+ } catch {
1765
+ return false;
1766
+ }
1767
+ if (!need) return false;
1768
+ return need.every((leg) => ptAmt(fill.paidTo?.[lc(leg.to)]) >= leg.value);
1769
+ }
1741
1770
 
1742
1771
  // src/index.ts
1743
1772
  import {
@@ -1846,6 +1875,7 @@ export {
1846
1875
  blockReward2 as blockReward,
1847
1876
  buildFeeHeight,
1848
1877
  buildRecord,
1878
+ burnedPayment,
1849
1879
  canonicalJson2 as canonicalJson,
1850
1880
  canonicalState,
1851
1881
  claimGraceOf,
@@ -1870,6 +1900,7 @@ export {
1870
1900
  isTokenWant,
1871
1901
  makerRebate,
1872
1902
  mint,
1903
+ myProvenFillClosedOffer,
1873
1904
  nameClaim,
1874
1905
  nameCommit,
1875
1906
  nameCommitRecord,
@@ -1890,6 +1921,7 @@ export {
1890
1921
  previewFill,
1891
1922
  primaryRankBefore,
1892
1923
  provenOfferTerms,
1924
+ ptAmt,
1893
1925
  replayLiveHold,
1894
1926
  requiredClaimDepth,
1895
1927
  requiredFillOutputs,
package/dist/mm/index.cjs CHANGED
@@ -324,8 +324,8 @@ var COMMIT_MAX_BLOCKS = 8 * import_csd_codec.EPOCH_LEN;
324
324
  var FCLAIM_WINDOW_MIN = CLAIM_WINDOW_BLOCKS_V20 + CLAIM_FILL_GRACE_BLOCKS + 1;
325
325
 
326
326
  // src/mm/allin.ts
327
- function rfqFillAllIn(n) {
328
- return n + tradeFee(n, FEE_BPS_V16) + makerRebate(n) + BigInt(import_csd_codec2.MIN_FEE_ATTEST);
327
+ function rfqFillAllIn(n, feeBps) {
328
+ return n + tradeFee(n, feeBps ?? FEE_BPS_V16) + makerRebate(n) + BigInt(import_csd_codec2.MIN_FEE_ATTEST);
329
329
  }
330
330
  function rfqBuyAllIn(n) {
331
331
  return rfqFillAllIn(n) + BigInt(import_csd_codec2.MIN_FEE_PROPOSE);
@@ -128,8 +128,9 @@ declare function sunriseAnswerPrice(params: SunriseOrderParams, q: BigIntish, n:
128
128
  /** The largest n in [0, room] whose answer price is <= budget (the inverse of sunriseAnswerPrice). */
129
129
  declare function sunriseTokensFor(params: SunriseOrderParams, q: BigIntish, budget: BigIntish, epochsElapsed: BigIntish, marginBps: BigIntish, floorPerToken: BigIntish | null | undefined, room: BigIntish): bigint;
130
130
 
131
- /** What the taker pays to fill an answer worth n: the value, the 1.5% fee, the maker fee and the fill attest. */
132
- declare function rfqFillAllIn(n: bigint): bigint;
131
+ /** What the taker pays to fill an answer worth n: the value, the treasury fee at `feeBps` (the offer's
132
+ * `feeBps`; FEE_BPS_V16 when absent), the maker fee and the fill attest. */
133
+ declare function rfqFillAllIn(n: bigint, feeBps?: number | null): bigint;
133
134
  /** The buyer's total for a bid at value n: rfqFillAllIn(n) plus the propose that anchors the bid. */
134
135
  declare function rfqBuyAllIn(n: bigint): bigint;
135
136
 
@@ -128,8 +128,9 @@ declare function sunriseAnswerPrice(params: SunriseOrderParams, q: BigIntish, n:
128
128
  /** The largest n in [0, room] whose answer price is <= budget (the inverse of sunriseAnswerPrice). */
129
129
  declare function sunriseTokensFor(params: SunriseOrderParams, q: BigIntish, budget: BigIntish, epochsElapsed: BigIntish, marginBps: BigIntish, floorPerToken: BigIntish | null | undefined, room: BigIntish): bigint;
130
130
 
131
- /** What the taker pays to fill an answer worth n: the value, the 1.5% fee, the maker fee and the fill attest. */
132
- declare function rfqFillAllIn(n: bigint): bigint;
131
+ /** What the taker pays to fill an answer worth n: the value, the treasury fee at `feeBps` (the offer's
132
+ * `feeBps`; FEE_BPS_V16 when absent), the maker fee and the fill attest. */
133
+ declare function rfqFillAllIn(n: bigint, feeBps?: number | null): bigint;
133
134
  /** The buyer's total for a bid at value n: rfqFillAllIn(n) plus the propose that anchors the bid. */
134
135
  declare function rfqBuyAllIn(n: bigint): bigint;
135
136
 
package/dist/mm/index.js CHANGED
@@ -269,7 +269,7 @@ function sunriseTokensFor(params, q, budget, epochsElapsed, marginBps, floorPerT
269
269
  import { MIN_FEE_ATTEST, MIN_FEE_PROPOSE } from "@inversealtruism/csd-codec";
270
270
 
271
271
  // src/types.ts
272
- import { EPOCH_LEN } from "@inversealtruism/csd-codec";
272
+ import { EPOCH_LEN, MAX_URI_BYTES, epochOf } from "@inversealtruism/csd-codec";
273
273
  var MAX_AMOUNT = (1n << 96n) - 1n;
274
274
  var CLAIM_WINDOW_BLOCKS_V20 = 40;
275
275
  var CLAIM_FILL_GRACE_BLOCKS = 5;
@@ -284,8 +284,8 @@ var COMMIT_MAX_BLOCKS = 8 * EPOCH_LEN;
284
284
  var FCLAIM_WINDOW_MIN = CLAIM_WINDOW_BLOCKS_V20 + CLAIM_FILL_GRACE_BLOCKS + 1;
285
285
 
286
286
  // src/mm/allin.ts
287
- function rfqFillAllIn(n) {
288
- return n + tradeFee(n, FEE_BPS_V16) + makerRebate(n) + BigInt(MIN_FEE_ATTEST);
287
+ function rfqFillAllIn(n, feeBps) {
288
+ return n + tradeFee(n, feeBps ?? FEE_BPS_V16) + makerRebate(n) + BigInt(MIN_FEE_ATTEST);
289
289
  }
290
290
  function rfqBuyAllIn(n) {
291
291
  return rfqFillAllIn(n) + BigInt(MIN_FEE_PROPOSE);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@inversealtruism/cairnx-core",
3
- "version": "0.1.43",
3
+ "version": "0.2.0",
4
4
  "engines": {
5
5
  "node": ">=18"
6
6
  },
@@ -35,12 +35,13 @@
35
35
  "dist",
36
36
  "LICENSE",
37
37
  "README.md",
38
+ "CHANGELOG.md",
38
39
  "CONVENTION.md",
39
40
  "MAKERS.md",
40
41
  "test/vectors"
41
42
  ],
42
43
  "dependencies": {
43
- "@inversealtruism/csd-codec": "0.1.16"
44
+ "@inversealtruism/csd-codec": "0.1.18"
44
45
  },
45
46
  "license": "MIT",
46
47
  "sideEffects": false,