@logswap/sdk 0.5.87 → 0.5.89

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/history.js CHANGED
@@ -72,7 +72,7 @@ export function indexedContractOf(kind, event) {
72
72
  }
73
73
  /** Events whose name two indexed contracts share: postgraphile prefixes their tables. */
74
74
  // `CollectorProposed` / `CollectorAccepted` are C 7 / F 26 and older; `TreasuryProposed` / `TreasuryAccepted` replace them (066).
75
- const SHARED = new Set(["Swap", "Transfer", "Approval", "OperatorSet", "CollectorProposed", "CollectorAccepted", "TreasuryProposed", "TreasuryAccepted", "Approved"]);
75
+ const SHARED = new Set(["PoolCreated", "Swap", "Transfer", "Approval", "OperatorSet", "CollectorProposed", "CollectorAccepted", "TreasuryProposed", "TreasuryAccepted", "Approved"]);
76
76
  const plural = (n) => (/(s|x|ch|sh)$/.test(n) ? `${n}es` : `${n}s`);
77
77
  /** A column's GraphQL name: postgraphile camelCases the snake_case rindexer writes (`F` → `f`). */
78
78
  const column = (name) => name[0].toLowerCase() + name.slice(1);
package/dist/indexer.d.ts CHANGED
@@ -82,7 +82,7 @@ export declare function indexerHealthy(url: string, signal?: AbortSignal): Promi
82
82
  * the more durable path and should be preferred wherever an indexer is configured, with the log
83
83
  * scan as the fallback for when it is not.
84
84
  *
85
- * `MarketCreated` carries every field of the `PoolKey` (`mintFee` included since C 12), so the key is rebuilt exactly and `poolId` is
85
+ * `PoolCreated` (the C manager's) carries every field of the `PoolKey` (`mintFee` included since C 12), so the key is rebuilt exactly and `poolId` is
86
86
  * recomputed locally rather than trusted from the row — the same offline derivation the SDK uses
87
87
  * everywhere else, so a wrong id fails loudly instead of addressing the wrong pool.
88
88
  */
package/dist/indexer.js CHANGED
@@ -133,12 +133,12 @@ export async function indexerHealthy(url, signal) {
133
133
  * the more durable path and should be preferred wherever an indexer is configured, with the log
134
134
  * scan as the fallback for when it is not.
135
135
  *
136
- * `MarketCreated` carries every field of the `PoolKey` (`mintFee` included since C 12), so the key is rebuilt exactly and `poolId` is
136
+ * `PoolCreated` (the C manager's) carries every field of the `PoolKey` (`mintFee` included since C 12), so the key is rebuilt exactly and `poolId` is
137
137
  * recomputed locally rather than trusted from the row — the same offline derivation the SDK uses
138
138
  * everywhere else, so a wrong id fails loudly instead of addressing the wrong pool.
139
139
  */
140
140
  export async function discoverMarketsIndexed(url, signal) {
141
- const nodes = await gqlAll(url, "allMarketCreateds", "poolId base quote tickSpacing swapFee mintFee policy x0 blockNumber txHash contractAddress", { signal });
141
+ const nodes = await gqlAll(url, "allCPoolManagerPoolCreateds", "poolId base quote tickSpacing swapFee mintFee policy initialLogPrice blockNumber txHash contractAddress", { signal });
142
142
  return nodes.map((n) => {
143
143
  const key = {
144
144
  base: n.base,
@@ -151,7 +151,7 @@ export async function discoverMarketsIndexed(url, signal) {
151
151
  return {
152
152
  key,
153
153
  poolId: poolId(key),
154
- x0: BigInt(n.x0),
154
+ initialLogPrice: BigInt(n.initialLogPrice),
155
155
  blockNumber: BigInt(n.blockNumber),
156
156
  transactionHash: n.txHash,
157
157
  manager: n.contractAddress,
@@ -196,7 +196,7 @@ export async function poolPositionsFromChain(c, key, x) {
196
196
  address: c.addresses.lens,
197
197
  abi: logswapLensAbi,
198
198
  functionName: "liveTicks",
199
- args: [key],
199
+ args: [poolId(key)],
200
200
  }));
201
201
  const pool = poolId(key);
202
202
  const rows = await Promise.all([...floors].map(async (floor) => {
@@ -204,7 +204,7 @@ export async function poolPositionsFromChain(c, key, x) {
204
204
  address: c.addresses.cPoolManager,
205
205
  abi: cPoolManagerAbi,
206
206
  functionName: "idOf",
207
- args: [key, floor],
207
+ args: [pool, floor],
208
208
  }));
209
209
  const { L, shares } = await getPositionClass(c, id); // through extsload (C version 7)
210
210
  if (L === 0n)
@@ -23,7 +23,7 @@
23
23
  */
24
24
  import type { Address, Hash } from "viem";
25
25
  import type { LogswapClient } from "./client.js";
26
- import type { PoolKey } from "./keys.js";
26
+ import { type PoolKey } from "./keys.js";
27
27
  import { type PairBounds } from "./actions.js";
28
28
  import { type WriteOptions } from "./write.js";
29
29
  export interface MintArgs extends WriteOptions {
@@ -56,17 +56,17 @@ export declare function mint(c: LogswapClient, a: MintArgs): Promise<Hash>;
56
56
  export interface CreateMarketArgs extends WriteOptions {
57
57
  key: PoolKey;
58
58
  /** Launch log-price. Bounded by the manager to ±46 (the price domain). */
59
- x0: bigint;
59
+ initialLogPrice: bigint;
60
60
  /** The backstop's floor — the first mint's rung, permanent for the pool's life. */
61
61
  targetFloor: bigint;
62
62
  /** The founding exposure; must exceed the manager's `minBackstopL` lock. */
63
63
  L: bigint;
64
- /** 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. */
64
+ /** Required, as on {@link mint}. Creation is atomic at `initialLogPrice`, so the flows are fixed by the arguments; {@link UNBOUNDED} is safe here only for that reason. */
65
65
  maxBaseIn: bigint;
66
66
  maxQuoteIn: bigint;
67
67
  }
68
68
  /**
69
- * Create a market ATOMICALLY: `initialize` at `x0` plus the backstop-establishing first mint in
69
+ * Create a market ATOMICALLY: `initialize` at `initialLogPrice` plus the backstop-establishing first mint in
70
70
  * one transaction — the canonical creation path. Under the C gate (064) the router is a trusted
71
71
  * forwarder: the gate checks the router's `user()` — the wallet sending this — against the
72
72
  * creator list, so a listed creator opens and funds a market in this one call. The
package/dist/liquidity.js CHANGED
@@ -22,6 +22,7 @@
22
22
  * apply.
23
23
  */
24
24
  import { logswapLensAbi, logswapRouterAbi } from "./generated.js";
25
+ import { poolId as keyId } from "./keys.js";
25
26
  import { NO_CAP } from "./ids.js";
26
27
  import { describeId, getPositionClass } from "./positions.js";
27
28
  import { execute, OPEN_DELTA, settleInKind, settleOnly, swapExactInAction, swapExactOutAction, updateAction, } from "./actions.js";
@@ -42,7 +43,9 @@ export async function mint(c, a) {
42
43
  abi: logswapRouterAbi,
43
44
  functionName: "mintBlended",
44
45
  args: [
45
- a.key,
46
+ keyId(a.key),
47
+ a.key.base,
48
+ a.key.quote,
46
49
  a.targetFloor,
47
50
  a.cap ?? NO_CAP,
48
51
  a.L,
@@ -54,7 +57,7 @@ export async function mint(c, a) {
54
57
  }, [a.key.base, a.key.quote]);
55
58
  }
56
59
  /**
57
- * Create a market ATOMICALLY: `initialize` at `x0` plus the backstop-establishing first mint in
60
+ * Create a market ATOMICALLY: `initialize` at `initialLogPrice` plus the backstop-establishing first mint in
58
61
  * one transaction — the canonical creation path. Under the C gate (064) the router is a trusted
59
62
  * forwarder: the gate checks the router's `user()` — the wallet sending this — against the
60
63
  * creator list, so a listed creator opens and funds a market in this one call. The
@@ -69,7 +72,7 @@ export async function createMarket(c, a) {
69
72
  functionName: "createMarket",
70
73
  args: [
71
74
  a.key,
72
- a.x0,
75
+ a.initialLogPrice,
73
76
  a.targetFloor,
74
77
  a.L,
75
78
  a.maxBaseIn,
@@ -92,7 +95,9 @@ export async function zapIn(c, a) {
92
95
  abi: logswapRouterAbi,
93
96
  functionName: "zapIn",
94
97
  args: [
95
- a.key,
98
+ keyId(a.key),
99
+ a.key.base,
100
+ a.key.quote,
96
101
  a.fundWithBase,
97
102
  a.amountIn,
98
103
  a.minSwapOut,
@@ -111,7 +116,9 @@ export async function update(c, a) {
111
116
  abi: logswapRouterAbi,
112
117
  functionName: "update",
113
118
  args: [
114
- a.key,
119
+ keyId(a.key),
120
+ a.key.base,
121
+ a.key.quote,
115
122
  a.fromId,
116
123
  a.shares,
117
124
  a.toFloor,
@@ -136,7 +143,9 @@ export async function move(c, a) {
136
143
  abi: logswapRouterAbi,
137
144
  functionName: "move",
138
145
  args: [
139
- a.key,
146
+ keyId(a.key),
147
+ a.key.base,
148
+ a.key.quote,
140
149
  a.fromId,
141
150
  a.shares,
142
151
  a.toFloor,
@@ -155,7 +164,7 @@ export async function previewEdit(c, a) {
155
164
  address: c.addresses.lens,
156
165
  abi: logswapLensAbi,
157
166
  functionName: "previewUpdate",
158
- args: [a.key, a.fromId, holder, a.shares, a.toFloor, a.toCap ?? NO_CAP, a.newL],
167
+ args: [keyId(a.key), a.fromId, holder, a.shares, a.toFloor, a.toCap ?? NO_CAP, a.newL],
159
168
  }));
160
169
  return { dBase: r[0], dQuote: r[1], fees: r[2] };
161
170
  }
@@ -317,7 +326,9 @@ export async function burn(c, a) {
317
326
  abi: logswapRouterAbi,
318
327
  functionName: "burn",
319
328
  args: [
320
- a.key,
329
+ keyId(a.key),
330
+ a.key.base,
331
+ a.key.quote,
321
332
  a.ids,
322
333
  a.shares,
323
334
  a.minBaseOut,
package/dist/pools.d.ts CHANGED
@@ -21,14 +21,14 @@ import { type PoolKey } from "./keys.js";
21
21
  export interface PoolState {
22
22
  initialized: boolean;
23
23
  backstopSeeded: boolean;
24
- /** $x = \log p$, WAD — the stored state. */
25
- x: bigint;
24
+ /** $x = \log p$, WAD — the stored state (`logPrice`; `x` before C 13). */
25
+ logPrice: bigint;
26
26
  /** Exposure currently earning. Steps only when a floor or cap is crossed. */
27
27
  lActive: bigint;
28
28
  reserveBase: bigint;
29
29
  reserveQuote: bigint;
30
- /** Fee-per-unit-L accumulator: $\phi \cdot \mathrm{TV}(\log p)$. */
31
- F: bigint;
30
+ /** Fee-per-unit-L accumulator $F = \phi \cdot \mathrm{TV}(\log p)$ (`feeGrowth`; `F` before C 13). */
31
+ feeGrowth: bigint;
32
32
  /** Quadratic variation of log-price, $\Sigma = \sum_{\text{swaps}} (\Delta x_{\text{swap}})^2$ — one term per swap. */
33
33
  realizedVariance: bigint;
34
34
  currentK: bigint;
@@ -51,7 +51,7 @@ export declare function marketSwapFee(c: LogswapClient, key: PoolKey): Promise<b
51
51
  * Price from the stored log-price. **Lossy** — `x` is exact and this is a float, so use it for
52
52
  * display and never for arithmetic you intend to send back on-chain.
53
53
  */
54
- export declare function priceOf(state: Pick<PoolState, "x">, scale?: number): number;
54
+ export declare function priceOf(state: Pick<PoolState, "logPrice">, scale?: number): number;
55
55
  /**
56
56
  * The factor between the chain's price and the human one. The chain's log-price is of the WEI
57
57
  * ratio, so with a 6-dec USDC quote and an 18-dec base the human price is `e^x · 10^12`. Pass
@@ -96,20 +96,20 @@ export declare function cListable(price: number, baseDecimals: number, quoteDeci
96
96
  *
97
97
  * Signed: negative means variation has outrun fee income over the pool's life.
98
98
  */
99
- export declare function lpEdge(state: Pick<PoolState, "F" | "realizedVariance">): bigint;
100
- /** A market discovered from a `MarketCreated` log — the full key, plus where it was created. */
99
+ export declare function lpEdge(state: Pick<PoolState, "feeGrowth" | "realizedVariance">): bigint;
100
+ /** A market discovered from a `PoolCreated` log — the full key, plus where it was created. */
101
101
  export interface DiscoveredMarket {
102
102
  key: PoolKey;
103
103
  poolId: Hex;
104
- /** The market's opening log-price. */
105
- x0: bigint;
104
+ /** The market's opening log-price (`x0` before C 13). */
105
+ initialLogPrice: bigint;
106
106
  blockNumber: bigint;
107
107
  transactionHash: Hex;
108
- /** The manager that emitted the `MarketCreated` — set when the row came from the indexer. */
108
+ /** The manager that emitted the `PoolCreated` — set when the row came from the indexer. */
109
109
  manager?: Address;
110
110
  }
111
111
  /**
112
- * Enumerate markets from `MarketCreated` logs.
112
+ * Enumerate markets from the C manager's `PoolCreated` logs.
113
113
  *
114
114
  * This is the whole market registry: the event carries every key field rather than just the id,
115
115
  * deliberately, so nothing downstream needs a configured list. The scan starts at the client's
@@ -119,7 +119,7 @@ export declare function discoverMarkets(c: LogswapClient, opts?: {
119
119
  fromBlock?: bigint;
120
120
  toBlock?: bigint;
121
121
  base?: Address;
122
- quote?: Address; /** The rindexer GraphQL endpoint: `MarketCreated` from there, the node otherwise. */
122
+ quote?: Address; /** The rindexer GraphQL endpoint: `PoolCreated` from there, the node otherwise. */
123
123
  indexer?: string;
124
124
  }): Promise<DiscoveredMarket[]>;
125
125
  /**
@@ -176,13 +176,13 @@ export declare function marketTokens(c: LogswapClient, key: PoolKey): Promise<{
176
176
  /** Format a quote-denominated amount for display, given the quote's decimals. */
177
177
  export declare function formatQuote(amount: bigint, quoteDecimals: number): string;
178
178
  /** Fees the pool has accrued over its life, in QUOTE units: $F \cdot L$. */
179
- export declare function feesQuote(state: Pick<PoolState, "F" | "lActive">): bigint;
179
+ export declare function feesQuote(state: Pick<PoolState, "feeGrowth" | "lActive">): bigint;
180
180
  /** The LP edge in QUOTE units: $(F - \tfrac12\Sigma) \cdot L$. Signed. */
181
- export declare function edgeQuote(state: Pick<PoolState, "F" | "realizedVariance" | "lActive">): bigint;
181
+ export declare function edgeQuote(state: Pick<PoolState, "feeGrowth" | "realizedVariance" | "lActive">): bigint;
182
182
  /** The pool floor as a price. **Lossy** — display only, like {@link priceOf}. */
183
183
  export declare function floorPrice(state: Pick<PoolState, "backstopFloor">, scale?: number): number;
184
184
  /** $\log(p / p_{\text{floor}}) = x - \xi$ — how far spot sits above the floor, in log units (WAD). */
185
- export declare function floorDistance(state: Pick<PoolState, "x" | "backstopFloor">): bigint;
185
+ export declare function floorDistance(state: Pick<PoolState, "logPrice" | "backstopFloor">): bigint;
186
186
  /**
187
187
  * $-\log(p/p_{\text{floor}})$ as a fraction: the log-drawdown from spot down to the floor.
188
188
  *
@@ -193,9 +193,9 @@ export declare function floorDistance(state: Pick<PoolState, "x" | "backstopFloo
193
193
  * $e^{-\Delta} - 1$, which differs materially once the distance is large (a log distance of 0.7
194
194
  * is a 50% price fall, not 70%).
195
195
  */
196
- export declare function floorDrawdown(state: Pick<PoolState, "x" | "backstopFloor">): number;
196
+ export declare function floorDrawdown(state: Pick<PoolState, "logPrice" | "backstopFloor">): number;
197
197
  /** The arithmetic price drawdown to the floor, $p_{\text{floor}}/p - 1$. Negative above the floor. */
198
- export declare function floorDrawdownPrice(state: Pick<PoolState, "x" | "backstopFloor">): number;
198
+ export declare function floorDrawdownPrice(state: Pick<PoolState, "logPrice" | "backstopFloor">): number;
199
199
  /**
200
200
  * Annualise a per-unit-L WAD rate over the window it accrued in.
201
201
  *
@@ -209,7 +209,7 @@ export declare function annualise(perUnitL: bigint, elapsedSeconds: bigint): num
209
209
  /** When a market was created, as a unix timestamp — the denominator for {@link annualise}. */
210
210
  export declare function marketOpenedAt(c: LogswapClient, m: DiscoveredMarket): Promise<bigint>;
211
211
  /**
212
- * Create a C market: `initialize(key, x0)` on the manager — a call, not a deployment, and no funds move. The
212
+ * Create a C market: `initialize(key, initialLogPrice)` on the manager — a call, not a deployment, and no funds move. The
213
213
  * creator-selected mint fee is part of the key (C 12, decision 078: `2 * swapFee <= mintFee <= MINT_FEE_MAX`,
214
214
  * preset at twice the swap fee by {@link presetMintFee}); there is no separate argument. Under a curated gate the
215
215
  * CALLER must be a listed creator; the canonical path is the router's {@link createMarket}, which forwards its
@@ -217,6 +217,6 @@ export declare function marketOpenedAt(c: LogswapClient, m: DiscoveredMarket): P
217
217
  */
218
218
  export declare function initializeMarket(c: LogswapClient, a: {
219
219
  key: PoolKey;
220
- x0: bigint;
220
+ initialLogPrice: bigint;
221
221
  account: Address;
222
222
  }): Promise<`0x${string}`>;
package/dist/pools.js CHANGED
@@ -45,7 +45,7 @@ export async function marketSwapFee(c, key) {
45
45
  * display and never for arithmetic you intend to send back on-chain.
46
46
  */
47
47
  export function priceOf(state, scale = 1) {
48
- return Math.exp(Number(state.x) / 1e18) * scale;
48
+ return Math.exp(Number(state.logPrice) / 1e18) * scale;
49
49
  }
50
50
  /**
51
51
  * The factor between the chain's price and the human one. The chain's log-price is of the WEI
@@ -99,22 +99,21 @@ export function cListable(price, baseDecimals, quoteDecimals) {
99
99
  * Signed: negative means variation has outrun fee income over the pool's life.
100
100
  */
101
101
  export function lpEdge(state) {
102
- return state.F - state.realizedVariance / 2n;
102
+ return state.feeGrowth - state.realizedVariance / 2n;
103
103
  }
104
104
  /**
105
- * Enumerate markets from `MarketCreated` logs.
105
+ * Enumerate markets from the C manager's `PoolCreated` logs.
106
106
  *
107
107
  * This is the whole market registry: the event carries every key field rather than just the id,
108
108
  * deliberately, so nothing downstream needs a configured list. The scan starts at the client's
109
109
  * `deployBlock` unless `fromBlock` says otherwise.
110
110
  */
111
111
  export async function discoverMarkets(c, opts = {}) {
112
- const ev = cPoolManagerAbi.find((x) => x.type === "event" && x.name === "MarketCreated");
112
+ const ev = cPoolManagerAbi.find((x) => x.type === "event" && x.name === "PoolCreated");
113
113
  if (!ev)
114
- throw new Error("logswap: MarketCreated event missing from the generated ABI");
114
+ throw new Error("logswap: PoolCreated event missing from the generated ABI");
115
115
  const args = {};
116
- if (opts.base)
117
- args.base = opts.base;
116
+ // `quote` is an indexed topic (C 13: `PoolCreated(poolId, quote, creator, base, …)`); `base` no longer is, so it filters below
118
117
  if (opts.quote)
119
118
  args.quote = opts.quote;
120
119
  const { logs } = await getEventLogs(c, {
@@ -125,7 +124,8 @@ export async function discoverMarkets(c, opts = {}) {
125
124
  fromBlock: opts.fromBlock, // the client's deployBlock when absent
126
125
  toBlock: opts.toBlock,
127
126
  });
128
- return logs.map((l) => {
127
+ const wantBase = opts.base?.toLowerCase();
128
+ return logs.filter((l) => wantBase === undefined || l.args.base.toLowerCase() === wantBase).map((l) => {
129
129
  const a = l.args;
130
130
  const key = {
131
131
  base: a.base,
@@ -138,7 +138,7 @@ export async function discoverMarkets(c, opts = {}) {
138
138
  return {
139
139
  key,
140
140
  poolId: poolId(key),
141
- x0: a.x0,
141
+ initialLogPrice: a.initialLogPrice,
142
142
  blockNumber: l.blockNumber,
143
143
  transactionHash: l.transactionHash,
144
144
  };
@@ -157,7 +157,7 @@ export async function liveFloors(c, key) {
157
157
  address: c.addresses.lens,
158
158
  abi: logswapLensAbi,
159
159
  functionName: "liveTicks",
160
- args: [key],
160
+ args: [poolId(key)],
161
161
  });
162
162
  }
163
163
  /** Is this floor on the market's grid, and inside `MAX_ABS_FLOOR`? Pure — no RPC on the manager. */
@@ -166,7 +166,7 @@ export async function isValidFloor(c, key, floor) {
166
166
  address: c.addresses.lens,
167
167
  abi: logswapLensAbi,
168
168
  functionName: "isValidFloor",
169
- args: [key, floor],
169
+ args: [poolId(key), floor],
170
170
  });
171
171
  }
172
172
  /**
@@ -289,7 +289,7 @@ const WAD = 10n ** 18n;
289
289
  const YEAR_SECONDS = 31536000n;
290
290
  /** Fees the pool has accrued over its life, in QUOTE units: $F \cdot L$. */
291
291
  export function feesQuote(state) {
292
- return (state.F * state.lActive) / WAD;
292
+ return (state.feeGrowth * state.lActive) / WAD;
293
293
  }
294
294
  /** The LP edge in QUOTE units: $(F - \tfrac12\Sigma) \cdot L$. Signed. */
295
295
  export function edgeQuote(state) {
@@ -301,7 +301,7 @@ export function floorPrice(state, scale = 1) {
301
301
  }
302
302
  /** $\log(p / p_{\text{floor}}) = x - \xi$ — how far spot sits above the floor, in log units (WAD). */
303
303
  export function floorDistance(state) {
304
- return state.x - state.backstopFloor;
304
+ return state.logPrice - state.backstopFloor;
305
305
  }
306
306
  /**
307
307
  * $-\log(p/p_{\text{floor}})$ as a fraction: the log-drawdown from spot down to the floor.
@@ -340,7 +340,7 @@ export async function marketOpenedAt(c, m) {
340
340
  return b.timestamp;
341
341
  }
342
342
  /**
343
- * Create a C market: `initialize(key, x0)` on the manager — a call, not a deployment, and no funds move. The
343
+ * Create a C market: `initialize(key, initialLogPrice)` on the manager — a call, not a deployment, and no funds move. The
344
344
  * creator-selected mint fee is part of the key (C 12, decision 078: `2 * swapFee <= mintFee <= MINT_FEE_MAX`,
345
345
  * preset at twice the swap fee by {@link presetMintFee}); there is no separate argument. Under a curated gate the
346
346
  * CALLER must be a listed creator; the canonical path is the router's {@link createMarket}, which forwards its
@@ -351,7 +351,7 @@ export async function initializeMarket(c, a) {
351
351
  address: c.addresses.cPoolManager,
352
352
  abi: cPoolManagerAbi,
353
353
  functionName: "initialize",
354
- args: [a.key, a.x0],
354
+ args: [a.key, a.initialLogPrice],
355
355
  account: signerFor(c, a.account),
356
356
  });
357
357
  return c.wallet.writeContract(request);
package/dist/positions.js CHANGED
@@ -177,7 +177,7 @@ export async function positionsOf(c, key, owner) {
177
177
  address: c.addresses.lens,
178
178
  abi: logswapLensAbi,
179
179
  functionName: "positionsOf",
180
- args: [key, owner],
180
+ args: [poolId(key), owner],
181
181
  }));
182
182
  return rows.map((r) => ({ id: r.id, floor: r.floor, cap: NO_CAP, capped: false, shares: r.shares, L: r.L, fees: r.fees }));
183
183
  }
@@ -218,7 +218,7 @@ export async function holdingsOf(c, key, owner, fromBlock, opts = {}) {
218
218
  address: c.addresses.lens,
219
219
  abi: logswapLensAbi,
220
220
  functionName: "heldByIds",
221
- args: [key, owner, ids],
221
+ args: [poolId(key), owner, ids],
222
222
  }));
223
223
  return rows.map((r) => ({ id: r.id, floor: r.floor, cap: r.capped ? r.cap : NO_CAP, capped: r.capped, shares: r.shares, L: r.L, fees: r.fees }));
224
224
  }
@@ -229,7 +229,7 @@ export async function legsOf(c, key, id, holder) {
229
229
  address: c.addresses.lens,
230
230
  abi: logswapLensAbi,
231
231
  functionName: "legsOf",
232
- args: [key, id, holder],
232
+ args: [poolId(key), id, holder],
233
233
  }));
234
234
  return { base, quote, fees, value };
235
235
  }
package/dist/swap.d.ts CHANGED
@@ -7,7 +7,7 @@
7
7
  */
8
8
  import type { Address, Hash } from "viem";
9
9
  import type { LogswapClient } from "./client.js";
10
- import type { PoolKey } from "./keys.js";
10
+ import { type PoolKey } from "./keys.js";
11
11
  import { type WriteOptions } from "./write.js";
12
12
  /**
13
13
  * Quote an exact-in swap. Exact, not approximate — the lens is a revert-quoter that runs the real
package/dist/swap.js CHANGED
@@ -6,6 +6,7 @@
6
6
  * is deliberately not exposed here — callers say `swapExactOut`.
7
7
  */
8
8
  import { logswapLensAbi, logswapRouterAbi } from "./generated.js";
9
+ import { poolId as keyId } from "./keys.js";
9
10
  import { resolveDeadline, resolveRecipient, sendRouterWrite, sendRouterWriteWithPermits } from "./write.js";
10
11
  /**
11
12
  * Quote an exact-in swap. Exact, not approximate — the lens is a revert-quoter that runs the real
@@ -19,7 +20,7 @@ export async function quoteExactIn(c, key, baseIn, amountIn) {
19
20
  address: c.addresses.lens,
20
21
  abi: logswapLensAbi,
21
22
  functionName: "previewSwapExactIn",
22
- args: [key, baseIn, amountIn],
23
+ args: [keyId(key), baseIn, amountIn],
23
24
  });
24
25
  return result;
25
26
  }
@@ -29,7 +30,7 @@ export async function quoteExactOut(c, key, baseOut, amountOut) {
29
30
  address: c.addresses.lens,
30
31
  abi: logswapLensAbi,
31
32
  functionName: "previewSwapExactOut",
32
- args: [key, baseOut, amountOut],
33
+ args: [keyId(key), baseOut, amountOut],
33
34
  });
34
35
  return result;
35
36
  }
@@ -37,14 +38,32 @@ export async function swapExactIn(c, a) {
37
38
  return sendRouterWriteWithPermits(c, {
38
39
  abi: logswapRouterAbi,
39
40
  functionName: "swapExactIn",
40
- args: [a.key, a.baseIn, a.amountIn, a.minOut, resolveRecipient(c, a), resolveDeadline(a)],
41
+ args: [
42
+ keyId(a.key),
43
+ a.baseIn ? a.key.base : a.key.quote, // tokenIn: the router checks the tokens the caller names against the pool's
44
+ a.baseIn ? a.key.quote : a.key.base, // tokenOut
45
+ a.baseIn,
46
+ a.amountIn,
47
+ a.minOut,
48
+ resolveRecipient(c, a),
49
+ resolveDeadline(a),
50
+ ],
41
51
  }, [a.baseIn ? a.key.base : a.key.quote]);
42
52
  }
43
53
  export async function swapExactOut(c, a) {
44
54
  return sendRouterWriteWithPermits(c, {
45
55
  abi: logswapRouterAbi,
46
56
  functionName: "swapExactOut",
47
- args: [a.key, a.baseOut, a.amountOut, a.maxIn, resolveRecipient(c, a), resolveDeadline(a)],
57
+ args: [
58
+ keyId(a.key),
59
+ a.baseOut ? a.key.quote : a.key.base, // tokenIn
60
+ a.baseOut ? a.key.base : a.key.quote, // tokenOut
61
+ a.baseOut,
62
+ a.amountOut,
63
+ a.maxIn,
64
+ resolveRecipient(c, a),
65
+ resolveDeadline(a),
66
+ ],
48
67
  }, [a.baseOut ? a.key.quote : a.key.base]);
49
68
  }
50
69
  /**
@@ -62,7 +81,9 @@ export async function swapExactInPath(c, a) {
62
81
  abi: logswapRouterAbi,
63
82
  functionName: "swapExactInPath",
64
83
  args: [
65
- a.hops.map((h) => ({ key: h.key, baseIn: h.baseIn })),
84
+ a.hops.map((h) => ({ poolId: keyId(h.key), baseIn: h.baseIn })),
85
+ hopTokens(a.hops[0]).tokenIn,
86
+ hopTokens(a.hops[a.hops.length - 1]).tokenOut,
66
87
  a.amountIn,
67
88
  a.minOut,
68
89
  resolveRecipient(c, a),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@logswap/sdk",
3
- "version": "0.5.87",
3
+ "version": "0.5.89",
4
4
  "description": "TypeScript SDK for Logswap, the liquidity primitive introducing the logarithmic invariant — typed wrappers over the CPoolManager / FPoolManager / Router / Lens surface.",
5
5
  "license": "GPL-2.0-or-later",
6
6
  "type": "module",
package/src/actions.ts CHANGED
@@ -21,7 +21,7 @@
21
21
  import { encodeAbiParameters, type Address, type Hash, type Hex } from "viem";
22
22
  import { logswapRouterAbi } from "./generated.js";
23
23
  import type { LogswapClient } from "./client.js";
24
- import type { PoolKey } from "./keys.js";
24
+ import { poolId as keyId, type PoolKey } from "./keys.js";
25
25
  import { NO_CAP } from "./ids.js";
26
26
  import type { Hop } from "./swap.js";
27
27
  import { resolveDeadline, resolveRecipient, sendRouterWriteWithPermits, simulateRouterWrite, type WriteOptions } from "./write.js";
@@ -69,31 +69,31 @@ const enc = (encoder: string, value: unknown): Hex => encodeAbiParameters(payloa
69
69
 
70
70
  /** Mint exposure `L` at `targetFloor` (off-grid blends the two adjacent rungs), `cap` optional. */
71
71
  export function mintAction(a: { key: PoolKey; targetFloor: bigint; cap?: bigint; L: bigint }): Action {
72
- return { op: Op.MintBlended, data: enc("encodeMint", { key: a.key, targetFloor: a.targetFloor, cap: a.cap ?? NO_CAP, L: a.L }) };
72
+ return { op: Op.MintBlended, data: enc("encodeMint", { poolId: keyId(a.key), targetFloor: a.targetFloor, cap: a.cap ?? NO_CAP, L: a.L }) };
73
73
  }
74
74
 
75
75
  /** Burn `shares[i]` of `ids[i]`; accrued fees are swept into the same batch. Needs the operator grant. */
76
76
  export function burnAction(a: { key: PoolKey; ids: readonly bigint[]; shares: readonly bigint[] }): Action {
77
77
  if (a.ids.length !== a.shares.length) throw new Error("logswap: ids and shares length mismatch");
78
- return { op: Op.Burn, data: enc("encodeBurn", { key: a.key, ids: a.ids, shares: a.shares }) };
78
+ return { op: Op.Burn, data: enc("encodeBurn", { poolId: keyId(a.key), ids: a.ids, shares: a.shares }) };
79
79
  }
80
80
 
81
81
  /** Exact-in swap. `amountIn` may be `OPEN_DELTA`: the input an earlier action left the router holding. */
82
82
  export function swapExactInAction(a: { key: PoolKey; baseIn: boolean; amountIn: bigint; minOut?: bigint }): Action {
83
- return { op: Op.SwapExactIn, data: enc("encodeSwap", { key: a.key, baseSide: a.baseIn, amount: a.amountIn, limit: a.minOut ?? 0n }) };
83
+ return { op: Op.SwapExactIn, data: enc("encodeSwap", { poolId: keyId(a.key), baseSide: a.baseIn, amount: a.amountIn, limit: a.minOut ?? 0n }) };
84
84
  }
85
85
 
86
86
  /** Exact-out swap. `amountOut` may be `OPEN_DELTA`: the output an earlier action left the router owing. */
87
87
  export function swapExactOutAction(a: { key: PoolKey; baseOut: boolean; amountOut: bigint; maxIn?: bigint }): Action {
88
88
  return {
89
89
  op: Op.SwapExactOut,
90
- data: enc("encodeSwap", { key: a.key, baseSide: a.baseOut, amount: a.amountOut, limit: a.maxIn ?? UNBOUNDED }),
90
+ data: enc("encodeSwap", { poolId: keyId(a.key), baseSide: a.baseOut, amount: a.amountOut, limit: a.maxIn ?? UNBOUNDED }),
91
91
  };
92
92
  }
93
93
 
94
94
  /** Collect the caller's fees on `ids`; positions untouched. */
95
95
  export function claimAction(a: { key: PoolKey; ids: readonly bigint[] }): Action {
96
- return { op: Op.Claim, data: enc("encodeClaim", { key: a.key, ids: a.ids }) };
96
+ return { op: Op.Claim, data: enc("encodeClaim", { poolId: keyId(a.key), ids: a.ids }) };
97
97
  }
98
98
 
99
99
  /** The general edit — set `shares` of `fromId` to (`toFloor`, `toCap`, `newL`); `newL = 0` exits. */
@@ -108,7 +108,7 @@ export function updateAction(a: {
108
108
  return {
109
109
  op: Op.Update,
110
110
  data: enc("encodeUpdate", {
111
- key: a.key,
111
+ poolId: keyId(a.key),
112
112
  fromId: a.fromId,
113
113
  shares: a.shares,
114
114
  toFloor: a.toFloor,
@@ -121,7 +121,7 @@ export function updateAction(a: {
121
121
  /** Multi-hop exact-in route; `amountIn` may be `OPEN_DELTA`. Intermediate tokens never move. */
122
122
  export function pathAction(a: { hops: readonly Hop[]; amountIn: bigint; minOut?: bigint }): Action {
123
123
  if (a.hops.length === 0) throw new Error("logswap: empty path");
124
- return { op: Op.Path, data: enc("encodePath", { hops: a.hops, amountIn: a.amountIn, minOut: a.minOut ?? 0n }) };
124
+ return { op: Op.Path, data: enc("encodePath", { hops: a.hops.map((h) => ({ poolId: keyId(h.key), baseIn: h.baseIn })), amountIn: a.amountIn, minOut: a.minOut ?? 0n }) };
125
125
  }
126
126
 
127
127
  /* settlement builders ======================================================= */
package/src/claims.ts CHANGED
@@ -9,7 +9,7 @@
9
9
  import type { Address, Hash } from "viem";
10
10
  import { cPoolManagerAbi, logswapRouterAbi } from "./generated.js";
11
11
  import type { LogswapClient } from "./client.js";
12
- import type { PoolKey } from "./keys.js";
12
+ import { poolId as keyId, type PoolKey } from "./keys.js";
13
13
  import { isPosition } from "./ids.js";
14
14
  import { requireWallet, resolveDeadline, resolveRecipient, sendRouterWrite, type WriteOptions } from "./write.js";
15
15
 
@@ -38,7 +38,7 @@ export async function claimFees(c: LogswapClient, a: ClaimFeesArgs): Promise<Has
38
38
  return sendRouterWrite(c, {
39
39
  abi: logswapRouterAbi,
40
40
  functionName: "claim",
41
- args: [a.key, a.ids, resolveRecipient(c, a), resolveDeadline(a)],
41
+ args: [keyId(a.key), a.key.quote, a.ids, resolveRecipient(c, a), resolveDeadline(a)],
42
42
  });
43
43
  }
44
44
 
package/src/client.ts CHANGED
@@ -184,7 +184,11 @@ function guardChain(wallet: WalletClient, pub: PublicClient): WalletClient {
184
184
  // takes no separate mint fee, `createMarket` neither; `getPool` drops `mintFee` and the gates' mint-fee menus are gone.
185
185
  // Every C pool id moved.
186
186
  // 12 (decisions 079-081): `Action` ordinals, the key is `CPoolKey` (names only). No pool id moved.
187
- export const EXPECTED_VERSION = 12n;
187
+ // 13 (decisions 088-090): a C pool is addressed by its `bytes32 poolId` after `initialize` (the key rides in calldata at `initialize`
188
+ // only; no pool id moved), the router's named entries take the tokens the caller expects (`WrongToken`), `claimById` / `burnById` /
189
+ // `claimManyFor` are `claim` / `burn` / `claimMany`, `mint(poolId, to, floor, cap, L)`, `MarketCreated` is `PoolCreated` (in F's field
190
+ // order), `x0` is `initialLogPrice`, `PoolView.x` / `.F` are `logPrice` / `feeGrowth`, `swapFee` / `mintFee` are `uint56`.
191
+ export const EXPECTED_VERSION = 13n;
188
192
  /**
189
193
  * The F manager's own tag (5 — the key's salt, pool names, the sponsor registry;
190
194
  * 4 was the income-only harvest cut).
@@ -283,10 +287,11 @@ export const EXPECTED_VERSION = 12n;
283
287
  // id moved); `initialize(key)`; `seed` / `retire` / `setLegs` are gone for `deployLiquidity(poolId, baseAssets,
284
288
  // quoteAmount, lnCapOverSeed, to)` (it SETS THE BOOK on an unfunded or a live pool), `close(poolId, to)` and
285
289
  // `regenerate(poolId, to)`; asset membership is fixed by the key; `LiquidityDeployed` echoes the input,
286
- // `GenerationSeeded` / `LegsSet` are gone; the lens `fPool` field is `baseLegs`, the cap `lnCapOverSeed`; the pot and the
290
+ // `GenerationSeeded` / `LegsSet` are gone; the lens `fPool` field is `baseAssets` (`baseLegs` before decision 090), the cap `lnCapOverSeed`; the pot and the
287
291
  // income fee are the income and the income tax (`IncomeReleased`, `incomeHeld`, `incomeTax`); a pad is uncapped.
292
+ // 39 (decision 087): `swapFeeB4B` is gone; base-for-base pays `swapFee` once, not 2·swapFee.
288
293
  // A breaking bump: raised in the same change.
289
- export const EXPECTED_F_VERSION = 38n;
294
+ export const EXPECTED_F_VERSION = 39n;
290
295
 
291
296
  export async function assertVersion(c: LogswapClient, expected = EXPECTED_VERSION): Promise<void> {
292
297
  const { cPoolManagerAbi, fPoolManagerAbi } = await import("./generated.js");