@logswap/sdk 0.5.79 → 0.5.81

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/src/history.ts CHANGED
@@ -103,17 +103,16 @@ function contractName(c: LogswapClient, address: Address, event: string): string
103
103
  }
104
104
 
105
105
  /**
106
- * A policy's name in the indexer for one of its events: `Policy`, or the kind's own contract for the
107
- * two-signature `Listed`. Pass it as {@link EventLogsQuery.contract} for a policy outside the artifact.
106
+ * A policy's name in the indexer for one of its events: `Policy`. Pass it as {@link EventLogsQuery.contract} for a policy outside the artifact.
108
107
  */
109
108
  export function indexedContractOf(kind: FPoolKind, event: string): string {
110
- if (event === "Listed") return kind === "private" ? "PrivatePolicy" : "PublicPolicy";
109
+ void kind; // `Listed` was the public and the private policy's since 064; the public policy dropped its asset list in F 33 (073), so it is unshared
111
110
  return "Policy";
112
111
  }
113
112
 
114
113
  /** Events whose name two indexed contracts share: postgraphile prefixes their tables. */
115
114
  // `CollectorProposed` / `CollectorAccepted` are C 7 / F 26 and older; `TreasuryProposed` / `TreasuryAccepted` replace them (066).
116
- const SHARED = new Set(["Swap", "Transfer", "Approval", "OperatorSet", "CollectorProposed", "CollectorAccepted", "TreasuryProposed", "TreasuryAccepted", "Approved", "Listed"]);
115
+ const SHARED = new Set(["Swap", "Transfer", "Approval", "OperatorSet", "CollectorProposed", "CollectorAccepted", "TreasuryProposed", "TreasuryAccepted", "Approved"]);
117
116
 
118
117
  const plural = (n: string) => (/(s|x|ch|sh)$/.test(n) ? `${n}es` : `${n}s`);
119
118
  /** A column's GraphQL name: postgraphile camelCases the snake_case rindexer writes (`F` → `f`). */
package/src/indexer.ts CHANGED
@@ -178,22 +178,24 @@ export async function indexerHealthy(url: string, signal?: AbortSignal): Promise
178
178
  * the more durable path and should be preferred wherever an indexer is configured, with the log
179
179
  * scan as the fallback for when it is not.
180
180
  *
181
- * `MarketCreated` carries every field of the `PoolKey`, so the key is rebuilt exactly and `poolId` is
181
+ * `MarketCreated` carries every field of the `PoolKey` (`mintFee` included since C 12), so the key is rebuilt exactly and `poolId` is
182
182
  * recomputed locally rather than trusted from the row — the same offline derivation the SDK uses
183
183
  * everywhere else, so a wrong id fails loudly instead of addressing the wrong pool.
184
184
  */
185
185
  export async function discoverMarketsIndexed(url: string, signal?: AbortSignal): Promise<DiscoveredMarket[]> {
186
186
  type Row = {
187
- poolId: Hex; base: Hex; quote: Hex; tickSpacing: string; swapFee: string;
187
+ poolId: Hex; base: Hex; quote: Hex; tickSpacing: string; swapFee: string; mintFee: string; policy: Hex;
188
188
  x0: string; blockNumber: string; txHash: Hex; contractAddress: Hex;
189
189
  };
190
- const nodes = await gqlAll<Row>(url, "allMarketCreateds", "poolId base quote tickSpacing swapFee x0 blockNumber txHash contractAddress", { signal });
190
+ const nodes = await gqlAll<Row>(url, "allMarketCreateds", "poolId base quote tickSpacing swapFee mintFee policy x0 blockNumber txHash contractAddress", { signal });
191
191
  return nodes.map((n) => {
192
192
  const key: PoolKey = {
193
193
  base: n.base as Address,
194
194
  quote: n.quote as Address,
195
195
  tickSpacing: BigInt(n.tickSpacing),
196
+ policy: n.policy as Address,
196
197
  swapFee: BigInt(n.swapFee), // rindexer names the column after the event's field: `swapFee` since C version 6 (logswap-be #40)
198
+ mintFee: BigInt(n.mintFee), // a key field since C 12 (078): the event carries it
197
199
  };
198
200
  return {
199
201
  key,
package/src/keys.ts CHANGED
@@ -25,15 +25,38 @@ import { encodeAbiParameters, keccak256, type Address, type Hex } from "viem";
25
25
  export const FEE_MIN = 10n ** 14n;
26
26
  export const FEE_MAX = 10n ** 16n;
27
27
 
28
+ /**
29
+ * The most a pool's creator-selected mint fee may be, WAD (2%): `2 * swapFee <= mintFee <= MINT_FEE_MAX`
30
+ * (C 12 / F 38, decision 078). Both managers check it at `initialize` and revert `BadParam`; the mint fee is a
31
+ * key field, fixed for the life of the pool.
32
+ */
33
+ export const MINT_FEE_MAX = 2n * 10n ** 16n;
34
+
35
+ /** The least a pool's mint fee may be for this swap fee: twice it. */
36
+ export function minMintFee(swapFee: bigint): bigint {
37
+ return 2n * swapFee;
38
+ }
39
+
40
+ /** Is `mintFee` inside the domain for this `swapFee`? Pure; the managers enforce the same bound. */
41
+ export function isValidMintFee(swapFee: bigint, mintFee: bigint): boolean {
42
+ return mintFee <= MINT_FEE_MAX && swapFee <= mintFee / 2n;
43
+ }
44
+
28
45
  /**
29
46
  * The economic tuple that IS the market. Field order is load-bearing: it is the ABI encoding order,
30
- * so it must match `src/types/PoolKey.sol` exactly.
47
+ * so it must match `src/types/CPoolKey.sol` exactly.
31
48
  */
32
49
  export interface PoolKey {
33
50
  base: Address;
34
51
  quote: Address;
35
52
  /** Log-tick spacing, WAD. The LP-boundary ladder — position floors and caps. */
36
53
  tickSpacing: bigint;
54
+ /**
55
+ * The C policy that admits this market (C version 10, decision 073): `PoolKey.policy`, a registry-approved
56
+ * policy, fixed for the market's life. Part of the id: the same pair under two policies is two markets.
57
+ * `address(0)` is a bare deployment with no registry.
58
+ */
59
+ policy: Address;
37
60
  /**
38
61
  * The swap fee, WAD, fixed for the life of the market: {@link FEE_MIN} (1 bp) ≤ φ ≤ {@link FEE_MAX} (1%),
39
62
  * or `0n`, which since C version 7 is NO fee (decisions 065; `DEFAULT_FEE` is gone). The gate
@@ -43,6 +66,12 @@ export interface PoolKey {
43
66
  * is not part of the encoding: no pool id changed with it.
44
67
  */
45
68
  swapFee: bigint;
69
+ /**
70
+ * The mint fee, WAD, selected by the creator and fixed for the life of the market (C version 12, decision
71
+ * 078): `2 * swapFee <= mintFee <= {@link MINT_FEE_MAX}`. The fee on newly earning `L`; part of the id, so the
72
+ * same pair and swap fee at two mint fees is two markets. `initialize` takes no separate mint-fee argument.
73
+ */
74
+ mintFee: bigint;
46
75
  }
47
76
 
48
77
  const POOL_KEY_ABI = [
@@ -52,7 +81,9 @@ const POOL_KEY_ABI = [
52
81
  { name: "base", type: "address" },
53
82
  { name: "quote", type: "address" },
54
83
  { name: "tickSpacing", type: "int256" },
84
+ { name: "policy", type: "address" },
55
85
  { name: "swapFee", type: "uint256" },
86
+ { name: "mintFee", type: "uint256" },
56
87
  ],
57
88
  },
58
89
  ] as const;
@@ -71,7 +102,9 @@ export function poolId(key: PoolKey): Hex {
71
102
  base: key.base,
72
103
  quote: key.quote,
73
104
  tickSpacing: key.tickSpacing,
105
+ policy: key.policy,
74
106
  swapFee: key.swapFee,
107
+ mintFee: key.mintFee,
75
108
  },
76
109
  ]),
77
110
  );
package/src/liquidity.ts CHANGED
@@ -27,7 +27,7 @@ import { logswapLensAbi, logswapRouterAbi } from "./generated.js";
27
27
  import type { LogswapClient } from "./client.js";
28
28
  import type { PoolKey } from "./keys.js";
29
29
  import { NO_CAP } from "./ids.js";
30
- import { describeId, getPositionClass, presetMintFee } from "./positions.js";
30
+ import { describeId, getPositionClass } from "./positions.js";
31
31
  import {
32
32
  execute,
33
33
  OPEN_DELTA,
@@ -105,11 +105,6 @@ export interface CreateMarketArgs extends WriteOptions {
105
105
  targetFloor: bigint;
106
106
  /** The founding exposure; must exceed the manager's `minBackstopL` lock. */
107
107
  L: bigint;
108
- /**
109
- * The market's mint fee, WAD of newly-earning L — the creator's pick from the gate's menu
110
- * (decisions 065). Defaults to {@link presetMintFee}: twice the swap fee, capped at `FEE_MAX`.
111
- */
112
- mintFee?: bigint;
113
108
  /** Required, as on {@link mint}. Creation is atomic at `x0`, so the flows are fixed by the arguments; {@link UNBOUNDED} is safe here only for that reason. */
114
109
  maxBaseIn: bigint;
115
110
  maxQuoteIn: bigint;
@@ -132,7 +127,6 @@ export async function createMarket(c: LogswapClient, a: CreateMarketArgs): Promi
132
127
  args: [
133
128
  a.key,
134
129
  a.x0,
135
- a.mintFee ?? presetMintFee(a.key.swapFee),
136
130
  a.targetFloor,
137
131
  a.L,
138
132
  a.maxBaseIn,
package/src/pools.ts CHANGED
@@ -18,7 +18,6 @@ import { clientChainId, type LogswapClient } from "./client.js";
18
18
  import { signerFor } from "./write.js";
19
19
  import { readCachedToken, registerCacheClear, writeCachedToken } from "./tokencache.js";
20
20
  import { poolId, type PoolKey } from "./keys.js";
21
- import { presetMintFee } from "./positions.js";
22
21
  import { getEventLogs } from "./history.js";
23
22
 
24
23
  /**
@@ -37,13 +36,11 @@ export interface PoolState {
37
36
  /** Fee-per-unit-L accumulator: $\phi \cdot \mathrm{TV}(\log p)$. */
38
37
  F: bigint;
39
38
  /** Quadratic variation of log-price, $\Sigma = \sum_{\text{swaps}} (\Delta x_{\text{swap}})^2$ — one term per swap. */
40
- bigSigma: bigint;
39
+ realizedVariance: bigint;
41
40
  currentK: bigint;
42
41
  protocolOwed: bigint;
43
42
  minBackstopL: bigint;
44
43
  backstopFloor: bigint;
45
- /** The market's mint fee, WAD of newly-earning L: proposed at birth, the gate's answer (065). */
46
- mintFee: bigint;
47
44
  /** The market's swap-fee tax, WAD of every fee paid out: the gate's answer at birth, fixed for life (066). */
48
45
  swapFeeTax: bigint;
49
46
  }
@@ -140,8 +137,8 @@ export function cListable(price: number, baseDecimals: number, quoteDecimals: nu
140
137
  *
141
138
  * Signed: negative means variation has outrun fee income over the pool's life.
142
139
  */
143
- export function lpEdge(state: Pick<PoolState, "F" | "bigSigma">): bigint {
144
- return state.F - state.bigSigma / 2n;
140
+ export function lpEdge(state: Pick<PoolState, "F" | "realizedVariance">): bigint {
141
+ return state.F - state.realizedVariance / 2n;
145
142
  }
146
143
 
147
144
  /** A market discovered from a `MarketCreated` log — the full key, plus where it was created. */
@@ -176,7 +173,7 @@ export async function discoverMarkets(
176
173
  const args: Record<string, unknown> = {};
177
174
  if (opts.base) args.base = opts.base;
178
175
  if (opts.quote) args.quote = opts.quote;
179
- const { logs } = await getEventLogs<{ base: Address; quote: Address; tickSpacing: bigint; swapFee: bigint; x0: bigint }>(c, {
176
+ const { logs } = await getEventLogs<{ base: Address; quote: Address; tickSpacing: bigint; policy: Address; swapFee: bigint; mintFee: bigint; x0: bigint }>(c, {
180
177
  indexer: opts.indexer,
181
178
  address: c.addresses.cPoolManager,
182
179
  event: ev,
@@ -191,7 +188,9 @@ export async function discoverMarkets(
191
188
  base: a.base,
192
189
  quote: a.quote,
193
190
  tickSpacing: a.tickSpacing,
191
+ policy: a.policy,
194
192
  swapFee: a.swapFee,
193
+ mintFee: a.mintFee,
195
194
  };
196
195
  return {
197
196
  key,
@@ -373,7 +372,7 @@ export function feesQuote(state: Pick<PoolState, "F" | "lActive">): bigint {
373
372
  }
374
373
 
375
374
  /** The LP edge in QUOTE units: $(F - \tfrac12\Sigma) \cdot L$. Signed. */
376
- export function edgeQuote(state: Pick<PoolState, "F" | "bigSigma" | "lActive">): bigint {
375
+ export function edgeQuote(state: Pick<PoolState, "F" | "realizedVariance" | "lActive">): bigint {
377
376
  return (lpEdge(state) * state.lActive) / WAD;
378
377
  }
379
378
 
@@ -427,18 +426,18 @@ export async function marketOpenedAt(c: LogswapClient, m: DiscoveredMarket): Pro
427
426
  }
428
427
 
429
428
  /**
430
- * Create a C market: `initialize(key, x0, mintFee)` on the manager — a call, not a deployment, and
431
- * no funds move. The mint fee is the creator's pick from the gate's menu (065), preset at twice the
432
- * swap fee ({@link presetMintFee}). Under a curated gate the CALLER must be a listed creator; the
433
- * canonical path is the router's {@link createMarket}, which forwards its user to the gate and
434
- * mints the backstop in the same transaction (064).
429
+ * Create a C market: `initialize(key, x0)` on the manager — a call, not a deployment, and no funds move. The
430
+ * creator-selected mint fee is part of the key (C 12, decision 078: `2 * swapFee <= mintFee <= MINT_FEE_MAX`,
431
+ * preset at twice the swap fee by {@link presetMintFee}); there is no separate argument. Under a curated gate the
432
+ * CALLER must be a listed creator; the canonical path is the router's {@link createMarket}, which forwards its
433
+ * user to the gate and mints the backstop in the same transaction (064).
435
434
  */
436
- export async function initializeMarket(c: LogswapClient, a: { key: PoolKey; x0: bigint; mintFee?: bigint; account: Address }) {
435
+ export async function initializeMarket(c: LogswapClient, a: { key: PoolKey; x0: bigint; account: Address }) {
437
436
  const { request } = await c.public.simulateContract({
438
437
  address: c.addresses.cPoolManager,
439
438
  abi: cPoolManagerAbi,
440
439
  functionName: "initialize",
441
- args: [a.key, a.x0, a.mintFee ?? presetMintFee(a.key.swapFee)],
440
+ args: [a.key, a.x0],
442
441
  account: signerFor(c, a.account),
443
442
  } as never);
444
443
  return c.wallet!.writeContract(request as never);
package/src/positions.ts CHANGED
@@ -10,7 +10,7 @@ import { encodeAbiParameters, keccak256, parseAbiItem } from "viem";
10
10
  import type { Address, Hex } from "viem";
11
11
  import { logswapLensAbi, cPoolManagerAbi } from "./generated.js";
12
12
  import type { LogswapClient } from "./client.js";
13
- import { FEE_MAX, poolId, type PoolKey } from "./keys.js";
13
+ import { MINT_FEE_MAX, poolId, type PoolKey } from "./keys.js";
14
14
 
15
15
  /** `CPoolState.POSITIONS_SLOT`: the manager's `positions` mapping (`forge inspect CPoolManager storageLayout`). */
16
16
  const C_POSITIONS_SLOT = 4n;
@@ -199,20 +199,19 @@ export function positionQuote(
199
199
  }
200
200
 
201
201
  /**
202
- * The mint fee a create form presets: twice the swap fee, capped at {@link FEE_MAX} (decisions 064
203
- * (f): guidance, not a contract rule). The creator picks from the gate's or the policy's menu
204
- * (065); a listed entry is what the chain accepts — read it with `policyMintFeeMenu`.
202
+ * The mint fee a create form presets: the least the managers accept, twice the swap fee (C 12 / F 38, decision
203
+ * 078: `2 * swapFee <= mintFee <= {@link MINT_FEE_MAX}`). The creator selects it in the key; there is no menu.
205
204
  */
206
205
  export function presetMintFee(swapFee: bigint): bigint {
207
206
  const m = 2n * swapFee;
208
- return m > FEE_MAX ? FEE_MAX : m;
207
+ return m > MINT_FEE_MAX ? MINT_FEE_MAX : m;
209
208
  }
210
209
 
211
210
  /**
212
211
  * The one-time mint fee at log-price `x`, in quote units — the amount `_mintCore` pulls ON TOP of
213
212
  * the position's own legs, so a mint's total quote pull is `positionQuote(p, x) + mintFee(p, x, rate)`.
214
- * `rate` is the MARKET's mint fee (`getPool(...).mintFee`, WAD of L): per market since C version 7,
215
- * the gate's answer at birth (065); there is no global `MINT_FEE` any more.
213
+ * `rate` is the MARKET's mint fee (`key.mintFee`, WAD of L): the creator-selected key field since C 12 (078),
214
+ * fixed for life; there is no global `MINT_FEE`.
216
215
  *
217
216
  * Mirrors the manager's exemption cases: a DORMANT mint pays nothing — floor above spot, or a
218
217
  * capped class spot has already passed (`cap <= x`). Anything earning pays `rate · L`, all of it
package/src/views.ts CHANGED
@@ -391,17 +391,15 @@ export async function poolSummaries(url: string, q: ViewQuery = {}): Promise<Poo
391
391
 
392
392
  // ─── generation_step, pad_status ─────────────────────────────────────────────
393
393
 
394
- /** A `regenerate` step: the pot and its split (payee, the protocol's cut, the burn, the rest deepening the bid); a pad's `rung` from `Graduated`. */
394
+ /** A generation step (`regenerate` or a live-pool `deployLiquidity`): the income released and its split (the payee, the rest deepening the bid); a pad's `rung` from `Graduated`. */
395
395
  export interface GenerationStepRow {
396
396
  kind: string | null;
397
397
  poolId: Hex;
398
398
  /** The pool's generation after this step. */
399
399
  genAfter: number;
400
- pot: bigint;
400
+ income: bigint;
401
401
  payee: Address;
402
402
  toPayee: bigint;
403
- cut: bigint;
404
- burnt: bigint;
405
403
  deepened: bigint;
406
404
  rung: number | null;
407
405
  txHash: Hex;
@@ -409,15 +407,15 @@ export interface GenerationStepRow {
409
407
  blockTimestamp: number;
410
408
  }
411
409
  export async function generationSteps(url: string, q: ViewQuery = {}): Promise<GenerationStepRow[]> {
412
- const rows = await viewRows(url, "allGenerationSteps", "GenerationStep", "kind poolId genAfter pot payee toPayee cut burnt deepened rung txHash blockNumber blockTimestamp", q);
410
+ const rows = await viewRows(url, "allGenerationSteps", "GenerationStep", "kind poolId genAfter income payee toPayee deepened rung txHash blockNumber blockTimestamp", q);
413
411
  return rows.map((r) => ({
414
- kind: r.kind == null ? null : String(r.kind), poolId: hex(r.poolId), genAfter: num(r.genAfter), pot: big(r.pot), payee: addr(r.payee),
415
- toPayee: big(r.toPayee), cut: big(r.cut), burnt: big(r.burnt), deepened: big(r.deepened), rung: intOr(r.rung),
412
+ kind: r.kind == null ? null : String(r.kind), poolId: hex(r.poolId), genAfter: num(r.genAfter), income: big(r.income), payee: addr(r.payee),
413
+ toPayee: big(r.toPayee), deepened: big(r.deepened), rung: intOr(r.rung),
416
414
  txHash: hex(r.txHash), blockNumber: big(r.blockNumber), blockTimestamp: secs(r.blockTimestamp),
417
415
  }));
418
416
  }
419
417
 
420
- /** Every pad and POL now: the latest snapshot's state, the next graduation's threshold (pads) and the pot's progress to it, and the steps so far. */
418
+ /** Every pad and POL now: the latest snapshot's state, the next graduation's threshold (pads) and the income's progress to it, and the steps so far. */
421
419
  export interface PadStatusRow {
422
420
  kind: string;
423
421
  poolId: Hex;
@@ -426,20 +424,18 @@ export interface PadStatusRow {
426
424
  creator: Address | null;
427
425
  birthTime: number;
428
426
  gen: number | null;
429
- pot: bigint | null;
427
+ income: bigint | null;
430
428
  unharvested: bigint | null;
431
429
  l: bigint | null;
432
430
  q: bigint | null;
433
431
  tvlQuote: bigint | null;
434
432
  shareValue: bigint | null;
435
433
  threshold: bigint | null;
436
- /** pot / threshold, a fraction; null without a threshold. */
434
+ /** income / threshold, a fraction; null without a threshold. */
437
435
  progress: number | null;
438
436
  stateBlock: bigint | null;
439
437
  stateTime: number | null;
440
438
  steps: number;
441
- burntTotal: bigint;
442
- cutTotal: bigint;
443
439
  paidTotal: bigint;
444
440
  deepenedTotal: bigint;
445
441
  lastStep: number | null;
@@ -447,14 +443,14 @@ export interface PadStatusRow {
447
443
  export async function padStatuses(url: string, q: ViewQuery = {}): Promise<PadStatusRow[]> {
448
444
  const rows = await viewRows(
449
445
  url, "allPadStatuses", "PadStatus",
450
- "kind poolId quote bases creator birthTime gen pot unharvested l q tvlQuote shareValue threshold progress stateBlock stateTime steps burntTotal cutTotal paidTotal deepenedTotal lastStep",
446
+ "kind poolId quote bases creator birthTime gen income unharvested l q tvlQuote shareValue threshold progress stateBlock stateTime steps paidTotal deepenedTotal lastStep",
451
447
  q,
452
448
  );
453
449
  return rows.map((r) => ({
454
450
  kind: String(r.kind), poolId: hex(r.poolId), quote: addr(r.quote), bases: addrs(r.bases), creator: addrOr(r.creator), birthTime: secs(r.birthTime),
455
- gen: intOr(r.gen), pot: bigOr(r.pot), unharvested: bigOr(r.unharvested), l: bigOr(r.l), q: bigOr(r.q), tvlQuote: bigOr(r.tvlQuote),
451
+ gen: intOr(r.gen), income: bigOr(r.income), unharvested: bigOr(r.unharvested), l: bigOr(r.l), q: bigOr(r.q), tvlQuote: bigOr(r.tvlQuote),
456
452
  shareValue: bigOr(r.shareValue), threshold: bigOr(r.threshold), progress: numOr(r.progress), stateBlock: bigOr(r.stateBlock), stateTime: secsOr(r.stateTime),
457
- steps: num(r.steps), burntTotal: big(r.burntTotal), cutTotal: big(r.cutTotal), paidTotal: big(r.paidTotal), deepenedTotal: big(r.deepenedTotal), lastStep: secsOr(r.lastStep),
453
+ steps: num(r.steps), paidTotal: big(r.paidTotal), deepenedTotal: big(r.deepenedTotal), lastStep: secsOr(r.lastStep),
458
454
  }));
459
455
  }
460
456
 
@@ -462,7 +458,7 @@ export async function padStatuses(url: string, q: ViewQuery = {}): Promise<PadSt
462
458
 
463
459
  /**
464
460
  * Protocol revenue per UTC day, side, source and token. Sources: F `mint_fee` (shares minted to the
465
- * treasury, valued at the share value) and `pot_cut`; C `accrued` (the swap-fee tax and the mint fee
461
+ * treasury, valued at the share value) and `income_tax` (the income tax taken at harvest); C `accrued` (the swap-fee tax and the mint fee
466
462
  * together, from the snapshots) and `collected` — basis `collected`, cash moved, not revenue on top
467
463
  * of `accrued`.
468
464
  */