@logswap/sdk 0.5.80 → 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/indexer.ts CHANGED
@@ -178,16 +178,16 @@ 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; policy: Hex;
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 policy 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,
@@ -195,6 +195,7 @@ export async function discoverMarketsIndexed(url: string, signal?: AbortSignal):
195
195
  tickSpacing: BigInt(n.tickSpacing),
196
196
  policy: n.policy as Address,
197
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
198
199
  };
199
200
  return {
200
201
  key,
package/src/keys.ts CHANGED
@@ -25,9 +25,26 @@ 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;
@@ -49,6 +66,12 @@ export interface PoolKey {
49
66
  * is not part of the encoding: no pool id changed with it.
50
67
  */
51
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;
52
75
  }
53
76
 
54
77
  const POOL_KEY_ABI = [
@@ -60,6 +83,7 @@ const POOL_KEY_ABI = [
60
83
  { name: "tickSpacing", type: "int256" },
61
84
  { name: "policy", type: "address" },
62
85
  { name: "swapFee", type: "uint256" },
86
+ { name: "mintFee", type: "uint256" },
63
87
  ],
64
88
  },
65
89
  ] as const;
@@ -80,6 +104,7 @@ export function poolId(key: PoolKey): Hex {
80
104
  tickSpacing: key.tickSpacing,
81
105
  policy: key.policy,
82
106
  swapFee: key.swapFee,
107
+ mintFee: key.mintFee,
83
108
  },
84
109
  ]),
85
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
  /**
@@ -42,8 +41,6 @@ export interface PoolState {
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
  }
@@ -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; policy: Address; 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,
@@ -193,6 +190,7 @@ export async function discoverMarkets(
193
190
  tickSpacing: a.tickSpacing,
194
191
  policy: a.policy,
195
192
  swapFee: a.swapFee,
193
+ mintFee: a.mintFee,
196
194
  };
197
195
  return {
198
196
  key,
@@ -428,18 +426,18 @@ export async function marketOpenedAt(c: LogswapClient, m: DiscoveredMarket): Pro
428
426
  }
429
427
 
430
428
  /**
431
- * Create a C market: `initialize(key, x0, mintFee)` on the manager — a call, not a deployment, and
432
- * no funds move. The mint fee is the creator's pick from the gate's menu (065), preset at twice the
433
- * swap fee ({@link presetMintFee}). Under a curated gate the CALLER must be a listed creator; the
434
- * canonical path is the router's {@link createMarket}, which forwards its user to the gate and
435
- * 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).
436
434
  */
437
- 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 }) {
438
436
  const { request } = await c.public.simulateContract({
439
437
  address: c.addresses.cPoolManager,
440
438
  abi: cPoolManagerAbi,
441
439
  functionName: "initialize",
442
- args: [a.key, a.x0, a.mintFee ?? presetMintFee(a.key.swapFee)],
440
+ args: [a.key, a.x0],
443
441
  account: signerFor(c, a.account),
444
442
  } as never);
445
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
  */