@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/src/history.ts CHANGED
@@ -112,7 +112,7 @@ export function indexedContractOf(kind: FPoolKind, event: string): string {
112
112
 
113
113
  /** Events whose name two indexed contracts share: postgraphile prefixes their tables. */
114
114
  // `CollectorProposed` / `CollectorAccepted` are C 7 / F 26 and older; `TreasuryProposed` / `TreasuryAccepted` replace them (066).
115
- const SHARED = new Set(["Swap", "Transfer", "Approval", "OperatorSet", "CollectorProposed", "CollectorAccepted", "TreasuryProposed", "TreasuryAccepted", "Approved"]);
115
+ const SHARED = new Set(["PoolCreated", "Swap", "Transfer", "Approval", "OperatorSet", "CollectorProposed", "CollectorAccepted", "TreasuryProposed", "TreasuryAccepted", "Approved"]);
116
116
 
117
117
  const plural = (n: string) => (/(s|x|ch|sh)$/.test(n) ? `${n}es` : `${n}s`);
118
118
  /** A column's GraphQL name: postgraphile camelCases the snake_case rindexer writes (`F` → `f`). */
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` (`mintFee` included since C 12), so the key is rebuilt exactly and `poolId` is
181
+ * `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
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
187
  poolId: Hex; base: Hex; quote: Hex; tickSpacing: string; swapFee: string; mintFee: string; policy: Hex;
188
- x0: string; blockNumber: string; txHash: Hex; contractAddress: Hex;
188
+ initialLogPrice: string; blockNumber: string; txHash: Hex; contractAddress: Hex;
189
189
  };
190
- const nodes = await gqlAll<Row>(url, "allMarketCreateds", "poolId base quote tickSpacing swapFee mintFee policy x0 blockNumber txHash contractAddress", { signal });
190
+ const nodes = await gqlAll<Row>(url, "allCPoolManagerPoolCreateds", "poolId base quote tickSpacing swapFee mintFee policy initialLogPrice blockNumber txHash contractAddress", { signal });
191
191
  return nodes.map((n) => {
192
192
  const key: PoolKey = {
193
193
  base: n.base as Address,
@@ -200,7 +200,7 @@ export async function discoverMarketsIndexed(url: string, signal?: AbortSignal):
200
200
  return {
201
201
  key,
202
202
  poolId: poolId(key),
203
- x0: BigInt(n.x0),
203
+ initialLogPrice: BigInt(n.initialLogPrice),
204
204
  blockNumber: BigInt(n.blockNumber),
205
205
  transactionHash: n.txHash,
206
206
  manager: n.contractAddress,
@@ -249,7 +249,7 @@ export async function poolPositionsFromChain(c: LogswapClient, key: PoolKey, x:
249
249
  address: c.addresses.lens,
250
250
  abi: logswapLensAbi,
251
251
  functionName: "liveTicks",
252
- args: [key],
252
+ args: [poolId(key)],
253
253
  } as never)) as readonly bigint[];
254
254
  const pool = poolId(key);
255
255
  const rows = await Promise.all(
@@ -258,7 +258,7 @@ export async function poolPositionsFromChain(c: LogswapClient, key: PoolKey, x:
258
258
  address: c.addresses.cPoolManager,
259
259
  abi: cPoolManagerAbi,
260
260
  functionName: "idOf",
261
- args: [key, floor],
261
+ args: [pool, floor],
262
262
  } as never)) as bigint;
263
263
  const { L, shares } = await getPositionClass(c, id); // through extsload (C version 7)
264
264
  if (L === 0n) return null;
package/src/liquidity.ts CHANGED
@@ -25,7 +25,7 @@
25
25
  import type { Address, Hash } from "viem";
26
26
  import { logswapLensAbi, logswapRouterAbi } from "./generated.js";
27
27
  import type { LogswapClient } from "./client.js";
28
- import type { PoolKey } from "./keys.js";
28
+ import { poolId as keyId, type PoolKey } from "./keys.js";
29
29
  import { NO_CAP } from "./ids.js";
30
30
  import { describeId, getPositionClass } from "./positions.js";
31
31
  import {
@@ -85,7 +85,9 @@ export async function mint(c: LogswapClient, a: MintArgs): Promise<Hash> {
85
85
  abi: logswapRouterAbi,
86
86
  functionName: "mintBlended",
87
87
  args: [
88
- a.key,
88
+ keyId(a.key),
89
+ a.key.base,
90
+ a.key.quote,
89
91
  a.targetFloor,
90
92
  a.cap ?? NO_CAP,
91
93
  a.L,
@@ -100,18 +102,18 @@ export async function mint(c: LogswapClient, a: MintArgs): Promise<Hash> {
100
102
  export interface CreateMarketArgs extends WriteOptions {
101
103
  key: PoolKey;
102
104
  /** Launch log-price. Bounded by the manager to ±46 (the price domain). */
103
- x0: bigint;
105
+ initialLogPrice: bigint;
104
106
  /** The backstop's floor — the first mint's rung, permanent for the pool's life. */
105
107
  targetFloor: bigint;
106
108
  /** The founding exposure; must exceed the manager's `minBackstopL` lock. */
107
109
  L: bigint;
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. */
110
+ /** 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. */
109
111
  maxBaseIn: bigint;
110
112
  maxQuoteIn: bigint;
111
113
  }
112
114
 
113
115
  /**
114
- * Create a market ATOMICALLY: `initialize` at `x0` plus the backstop-establishing first mint in
116
+ * Create a market ATOMICALLY: `initialize` at `initialLogPrice` plus the backstop-establishing first mint in
115
117
  * one transaction — the canonical creation path. Under the C gate (064) the router is a trusted
116
118
  * forwarder: the gate checks the router's `user()` — the wallet sending this — against the
117
119
  * creator list, so a listed creator opens and funds a market in this one call. The
@@ -126,7 +128,7 @@ export async function createMarket(c: LogswapClient, a: CreateMarketArgs): Promi
126
128
  functionName: "createMarket",
127
129
  args: [
128
130
  a.key,
129
- a.x0,
131
+ a.initialLogPrice,
130
132
  a.targetFloor,
131
133
  a.L,
132
134
  a.maxBaseIn,
@@ -164,7 +166,9 @@ export async function zapIn(c: LogswapClient, a: ZapArgs): Promise<Hash> {
164
166
  abi: logswapRouterAbi,
165
167
  functionName: "zapIn",
166
168
  args: [
167
- a.key,
169
+ keyId(a.key),
170
+ a.key.base,
171
+ a.key.quote,
168
172
  a.fundWithBase,
169
173
  a.amountIn,
170
174
  a.minSwapOut,
@@ -199,7 +203,9 @@ export async function update(c: LogswapClient, a: UpdateArgs): Promise<Hash> {
199
203
  abi: logswapRouterAbi,
200
204
  functionName: "update",
201
205
  args: [
202
- a.key,
206
+ keyId(a.key),
207
+ a.key.base,
208
+ a.key.quote,
203
209
  a.fromId,
204
210
  a.shares,
205
211
  a.toFloor,
@@ -236,7 +242,9 @@ export async function move(c: LogswapClient, a: MoveArgs): Promise<Hash> {
236
242
  abi: logswapRouterAbi,
237
243
  functionName: "move",
238
244
  args: [
239
- a.key,
245
+ keyId(a.key),
246
+ a.key.base,
247
+ a.key.quote,
240
248
  a.fromId,
241
249
  a.shares,
242
250
  a.toFloor,
@@ -288,7 +296,7 @@ export async function previewEdit(
288
296
  address: c.addresses.lens,
289
297
  abi: logswapLensAbi,
290
298
  functionName: "previewUpdate",
291
- args: [a.key, a.fromId, holder, a.shares, a.toFloor, a.toCap ?? NO_CAP, a.newL],
299
+ args: [keyId(a.key), a.fromId, holder, a.shares, a.toFloor, a.toCap ?? NO_CAP, a.newL],
292
300
  })) as readonly [bigint, bigint, bigint];
293
301
  return { dBase: r[0], dQuote: r[1], fees: r[2] };
294
302
  }
@@ -468,7 +476,9 @@ export async function burn(c: LogswapClient, a: BurnArgs): Promise<Hash> {
468
476
  abi: logswapRouterAbi,
469
477
  functionName: "burn",
470
478
  args: [
471
- a.key,
479
+ keyId(a.key),
480
+ a.key.base,
481
+ a.key.quote,
472
482
  a.ids,
473
483
  a.shares,
474
484
  a.minBaseOut,
package/src/pools.ts CHANGED
@@ -27,14 +27,14 @@ import { getEventLogs } from "./history.js";
27
27
  export interface PoolState {
28
28
  initialized: boolean;
29
29
  backstopSeeded: boolean;
30
- /** $x = \log p$, WAD — the stored state. */
31
- x: bigint;
30
+ /** $x = \log p$, WAD — the stored state (`logPrice`; `x` before C 13). */
31
+ logPrice: bigint;
32
32
  /** Exposure currently earning. Steps only when a floor or cap is crossed. */
33
33
  lActive: bigint;
34
34
  reserveBase: bigint;
35
35
  reserveQuote: bigint;
36
- /** Fee-per-unit-L accumulator: $\phi \cdot \mathrm{TV}(\log p)$. */
37
- F: bigint;
36
+ /** Fee-per-unit-L accumulator $F = \phi \cdot \mathrm{TV}(\log p)$ (`feeGrowth`; `F` before C 13). */
37
+ feeGrowth: bigint;
38
38
  /** Quadratic variation of log-price, $\Sigma = \sum_{\text{swaps}} (\Delta x_{\text{swap}})^2$ — one term per swap. */
39
39
  realizedVariance: bigint;
40
40
  currentK: bigint;
@@ -72,8 +72,8 @@ export async function marketSwapFee(c: LogswapClient, key: PoolKey): Promise<big
72
72
  * Price from the stored log-price. **Lossy** — `x` is exact and this is a float, so use it for
73
73
  * display and never for arithmetic you intend to send back on-chain.
74
74
  */
75
- export function priceOf(state: Pick<PoolState, "x">, scale = 1): number {
76
- return Math.exp(Number(state.x) / 1e18) * scale;
75
+ export function priceOf(state: Pick<PoolState, "logPrice">, scale = 1): number {
76
+ return Math.exp(Number(state.logPrice) / 1e18) * scale;
77
77
  }
78
78
 
79
79
  /**
@@ -137,24 +137,24 @@ export function cListable(price: number, baseDecimals: number, quoteDecimals: nu
137
137
  *
138
138
  * Signed: negative means variation has outrun fee income over the pool's life.
139
139
  */
140
- export function lpEdge(state: Pick<PoolState, "F" | "realizedVariance">): bigint {
141
- return state.F - state.realizedVariance / 2n;
140
+ export function lpEdge(state: Pick<PoolState, "feeGrowth" | "realizedVariance">): bigint {
141
+ return state.feeGrowth - state.realizedVariance / 2n;
142
142
  }
143
143
 
144
- /** A market discovered from a `MarketCreated` log — the full key, plus where it was created. */
144
+ /** A market discovered from a `PoolCreated` log — the full key, plus where it was created. */
145
145
  export interface DiscoveredMarket {
146
146
  key: PoolKey;
147
147
  poolId: Hex;
148
- /** The market's opening log-price. */
149
- x0: bigint;
148
+ /** The market's opening log-price (`x0` before C 13). */
149
+ initialLogPrice: bigint;
150
150
  blockNumber: bigint;
151
151
  transactionHash: Hex;
152
- /** The manager that emitted the `MarketCreated` — set when the row came from the indexer. */
152
+ /** The manager that emitted the `PoolCreated` — set when the row came from the indexer. */
153
153
  manager?: Address;
154
154
  }
155
155
 
156
156
  /**
157
- * Enumerate markets from `MarketCreated` logs.
157
+ * Enumerate markets from the C manager's `PoolCreated` logs.
158
158
  *
159
159
  * This is the whole market registry: the event carries every key field rather than just the id,
160
160
  * deliberately, so nothing downstream needs a configured list. The scan starts at the client's
@@ -162,18 +162,18 @@ export interface DiscoveredMarket {
162
162
  */
163
163
  export async function discoverMarkets(
164
164
  c: LogswapClient,
165
- opts: { fromBlock?: bigint; toBlock?: bigint; base?: Address; quote?: Address; /** The rindexer GraphQL endpoint: `MarketCreated` from there, the node otherwise. */ indexer?: string } = {},
165
+ opts: { fromBlock?: bigint; toBlock?: bigint; base?: Address; quote?: Address; /** The rindexer GraphQL endpoint: `PoolCreated` from there, the node otherwise. */ indexer?: string } = {},
166
166
  ): Promise<DiscoveredMarket[]> {
167
- // Narrow the const ABI to the MarketCreated entry while KEEPING its literal type, so viem can infer
167
+ // Narrow the const ABI to the PoolCreated entry while KEEPING its literal type, so viem can infer
168
168
  // the log shape. `as never` would compile but collapse every arg to `never` at the call site.
169
- type Ev = Extract<(typeof cPoolManagerAbi)[number], { type: "event"; name: "MarketCreated" }>;
170
- const ev = cPoolManagerAbi.find((x): x is Ev => x.type === "event" && x.name === "MarketCreated");
171
- if (!ev) throw new Error("logswap: MarketCreated event missing from the generated ABI");
169
+ type Ev = Extract<(typeof cPoolManagerAbi)[number], { type: "event"; name: "PoolCreated" }>;
170
+ const ev = cPoolManagerAbi.find((x): x is Ev => x.type === "event" && x.name === "PoolCreated");
171
+ if (!ev) throw new Error("logswap: PoolCreated event missing from the generated ABI");
172
172
 
173
173
  const args: Record<string, unknown> = {};
174
- if (opts.base) args.base = opts.base;
174
+ // `quote` is an indexed topic (C 13: `PoolCreated(poolId, quote, creator, base, …)`); `base` no longer is, so it filters below
175
175
  if (opts.quote) args.quote = opts.quote;
176
- const { logs } = await getEventLogs<{ base: Address; quote: Address; tickSpacing: bigint; policy: Address; swapFee: bigint; mintFee: bigint; x0: bigint }>(c, {
176
+ const { logs } = await getEventLogs<{ base: Address; quote: Address; tickSpacing: bigint; policy: Address; swapFee: bigint; mintFee: bigint; initialLogPrice: bigint }>(c, {
177
177
  indexer: opts.indexer,
178
178
  address: c.addresses.cPoolManager,
179
179
  event: ev,
@@ -182,7 +182,8 @@ export async function discoverMarkets(
182
182
  toBlock: opts.toBlock,
183
183
  });
184
184
 
185
- return logs.map((l) => {
185
+ const wantBase = opts.base?.toLowerCase();
186
+ return logs.filter((l) => wantBase === undefined || l.args.base.toLowerCase() === wantBase).map((l) => {
186
187
  const a = l.args;
187
188
  const key: PoolKey = {
188
189
  base: a.base,
@@ -195,7 +196,7 @@ export async function discoverMarkets(
195
196
  return {
196
197
  key,
197
198
  poolId: poolId(key),
198
- x0: a.x0,
199
+ initialLogPrice: a.initialLogPrice,
199
200
  blockNumber: l.blockNumber,
200
201
  transactionHash: l.transactionHash,
201
202
  };
@@ -215,7 +216,7 @@ export async function liveFloors(c: LogswapClient, key: PoolKey): Promise<readon
215
216
  address: c.addresses.lens,
216
217
  abi: logswapLensAbi,
217
218
  functionName: "liveTicks",
218
- args: [key],
219
+ args: [poolId(key)],
219
220
  }) as Promise<readonly bigint[]>;
220
221
  }
221
222
 
@@ -225,7 +226,7 @@ export async function isValidFloor(c: LogswapClient, key: PoolKey, floor: bigint
225
226
  address: c.addresses.lens,
226
227
  abi: logswapLensAbi,
227
228
  functionName: "isValidFloor",
228
- args: [key, floor],
229
+ args: [poolId(key), floor],
229
230
  }) as Promise<boolean>;
230
231
  }
231
232
 
@@ -367,12 +368,12 @@ const WAD = 10n ** 18n;
367
368
  const YEAR_SECONDS = 31_536_000n;
368
369
 
369
370
  /** Fees the pool has accrued over its life, in QUOTE units: $F \cdot L$. */
370
- export function feesQuote(state: Pick<PoolState, "F" | "lActive">): bigint {
371
- return (state.F * state.lActive) / WAD;
371
+ export function feesQuote(state: Pick<PoolState, "feeGrowth" | "lActive">): bigint {
372
+ return (state.feeGrowth * state.lActive) / WAD;
372
373
  }
373
374
 
374
375
  /** The LP edge in QUOTE units: $(F - \tfrac12\Sigma) \cdot L$. Signed. */
375
- export function edgeQuote(state: Pick<PoolState, "F" | "realizedVariance" | "lActive">): bigint {
376
+ export function edgeQuote(state: Pick<PoolState, "feeGrowth" | "realizedVariance" | "lActive">): bigint {
376
377
  return (lpEdge(state) * state.lActive) / WAD;
377
378
  }
378
379
 
@@ -382,8 +383,8 @@ export function floorPrice(state: Pick<PoolState, "backstopFloor">, scale = 1):
382
383
  }
383
384
 
384
385
  /** $\log(p / p_{\text{floor}}) = x - \xi$ — how far spot sits above the floor, in log units (WAD). */
385
- export function floorDistance(state: Pick<PoolState, "x" | "backstopFloor">): bigint {
386
- return state.x - state.backstopFloor;
386
+ export function floorDistance(state: Pick<PoolState, "logPrice" | "backstopFloor">): bigint {
387
+ return state.logPrice - state.backstopFloor;
387
388
  }
388
389
 
389
390
  /**
@@ -396,12 +397,12 @@ export function floorDistance(state: Pick<PoolState, "x" | "backstopFloor">): bi
396
397
  * $e^{-\Delta} - 1$, which differs materially once the distance is large (a log distance of 0.7
397
398
  * is a 50% price fall, not 70%).
398
399
  */
399
- export function floorDrawdown(state: Pick<PoolState, "x" | "backstopFloor">): number {
400
+ export function floorDrawdown(state: Pick<PoolState, "logPrice" | "backstopFloor">): number {
400
401
  return -Number(floorDistance(state)) / 1e18;
401
402
  }
402
403
 
403
404
  /** The arithmetic price drawdown to the floor, $p_{\text{floor}}/p - 1$. Negative above the floor. */
404
- export function floorDrawdownPrice(state: Pick<PoolState, "x" | "backstopFloor">): number {
405
+ export function floorDrawdownPrice(state: Pick<PoolState, "logPrice" | "backstopFloor">): number {
405
406
  return Math.exp(-Number(floorDistance(state)) / 1e18) - 1;
406
407
  }
407
408
 
@@ -426,18 +427,18 @@ export async function marketOpenedAt(c: LogswapClient, m: DiscoveredMarket): Pro
426
427
  }
427
428
 
428
429
  /**
429
- * Create a C market: `initialize(key, x0)` on the manager — a call, not a deployment, and no funds move. The
430
+ * Create a C market: `initialize(key, initialLogPrice)` on the manager — a call, not a deployment, and no funds move. The
430
431
  * creator-selected mint fee is part of the key (C 12, decision 078: `2 * swapFee <= mintFee <= MINT_FEE_MAX`,
431
432
  * preset at twice the swap fee by {@link presetMintFee}); there is no separate argument. Under a curated gate the
432
433
  * CALLER must be a listed creator; the canonical path is the router's {@link createMarket}, which forwards its
433
434
  * user to the gate and mints the backstop in the same transaction (064).
434
435
  */
435
- export async function initializeMarket(c: LogswapClient, a: { key: PoolKey; x0: bigint; account: Address }) {
436
+ export async function initializeMarket(c: LogswapClient, a: { key: PoolKey; initialLogPrice: bigint; account: Address }) {
436
437
  const { request } = await c.public.simulateContract({
437
438
  address: c.addresses.cPoolManager,
438
439
  abi: cPoolManagerAbi,
439
440
  functionName: "initialize",
440
- args: [a.key, a.x0],
441
+ args: [a.key, a.initialLogPrice],
441
442
  account: signerFor(c, a.account),
442
443
  } as never);
443
444
  return c.wallet!.writeContract(request as never);
package/src/positions.ts CHANGED
@@ -256,7 +256,7 @@ export async function positionsOf(c: LogswapClient, key: PoolKey, owner: Address
256
256
  address: c.addresses.lens,
257
257
  abi: logswapLensAbi,
258
258
  functionName: "positionsOf",
259
- args: [key, owner],
259
+ args: [poolId(key), owner],
260
260
  } as never)) as readonly { id: bigint; floor: bigint; shares: bigint; L: bigint; fees: bigint }[];
261
261
  return rows.map((r) => ({ id: r.id, floor: r.floor, cap: NO_CAP, capped: false, shares: r.shares, L: r.L, fees: r.fees }));
262
262
  }
@@ -299,7 +299,7 @@ export async function holdingsOf(c: LogswapClient, key: PoolKey, owner: Address,
299
299
  address: c.addresses.lens,
300
300
  abi: logswapLensAbi,
301
301
  functionName: "heldByIds",
302
- args: [key, owner, ids],
302
+ args: [poolId(key), owner, ids],
303
303
  } as never)) as readonly { id: bigint; floor: bigint; cap: bigint; capped: boolean; shares: bigint; L: bigint; fees: bigint }[];
304
304
  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 }));
305
305
  }
@@ -311,7 +311,7 @@ export async function legsOf(c: LogswapClient, key: PoolKey, id: bigint, holder:
311
311
  address: c.addresses.lens,
312
312
  abi: logswapLensAbi,
313
313
  functionName: "legsOf",
314
- args: [key, id, holder],
314
+ args: [poolId(key), id, holder],
315
315
  } as never)) as readonly [bigint, bigint, bigint, bigint];
316
316
  return { base, quote, fees, value };
317
317
  }
package/src/swap.ts CHANGED
@@ -9,7 +9,7 @@
9
9
  import type { Address, Hash } from "viem";
10
10
  import { logswapLensAbi, 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 { resolveDeadline, resolveRecipient, sendRouterWrite, type WriteOptions , sendRouterWriteWithPermits } from "./write.js";
14
14
 
15
15
  /**
@@ -29,7 +29,7 @@ export async function quoteExactIn(
29
29
  address: c.addresses.lens,
30
30
  abi: logswapLensAbi,
31
31
  functionName: "previewSwapExactIn",
32
- args: [key, baseIn, amountIn],
32
+ args: [keyId(key), baseIn, amountIn],
33
33
  });
34
34
  return result as bigint;
35
35
  }
@@ -45,7 +45,7 @@ export async function quoteExactOut(
45
45
  address: c.addresses.lens,
46
46
  abi: logswapLensAbi,
47
47
  functionName: "previewSwapExactOut",
48
- args: [key, baseOut, amountOut],
48
+ args: [keyId(key), baseOut, amountOut],
49
49
  });
50
50
  return result as bigint;
51
51
  }
@@ -63,7 +63,16 @@ export async function swapExactIn(c: LogswapClient, a: SwapExactInArgs): Promise
63
63
  return sendRouterWriteWithPermits(c, {
64
64
  abi: logswapRouterAbi,
65
65
  functionName: "swapExactIn",
66
- args: [a.key, a.baseIn, a.amountIn, a.minOut, resolveRecipient(c, a), resolveDeadline(a)],
66
+ args: [
67
+ keyId(a.key),
68
+ a.baseIn ? a.key.base : a.key.quote, // tokenIn: the router checks the tokens the caller names against the pool's
69
+ a.baseIn ? a.key.quote : a.key.base, // tokenOut
70
+ a.baseIn,
71
+ a.amountIn,
72
+ a.minOut,
73
+ resolveRecipient(c, a),
74
+ resolveDeadline(a),
75
+ ],
67
76
  }, [a.baseIn ? a.key.base : a.key.quote]);
68
77
  }
69
78
 
@@ -80,7 +89,16 @@ export async function swapExactOut(c: LogswapClient, a: SwapExactOutArgs): Promi
80
89
  return sendRouterWriteWithPermits(c, {
81
90
  abi: logswapRouterAbi,
82
91
  functionName: "swapExactOut",
83
- args: [a.key, a.baseOut, a.amountOut, a.maxIn, resolveRecipient(c, a), resolveDeadline(a)],
92
+ args: [
93
+ keyId(a.key),
94
+ a.baseOut ? a.key.quote : a.key.base, // tokenIn
95
+ a.baseOut ? a.key.base : a.key.quote, // tokenOut
96
+ a.baseOut,
97
+ a.amountOut,
98
+ a.maxIn,
99
+ resolveRecipient(c, a),
100
+ resolveDeadline(a),
101
+ ],
84
102
  }, [a.baseOut ? a.key.quote : a.key.base]);
85
103
  }
86
104
 
@@ -110,7 +128,9 @@ export async function swapExactInPath(c: LogswapClient, a: SwapPathArgs): Promis
110
128
  abi: logswapRouterAbi,
111
129
  functionName: "swapExactInPath",
112
130
  args: [
113
- a.hops.map((h) => ({ key: h.key, baseIn: h.baseIn })),
131
+ a.hops.map((h) => ({ poolId: keyId(h.key), baseIn: h.baseIn })),
132
+ hopTokens(a.hops[0]!).tokenIn,
133
+ hopTokens(a.hops[a.hops.length - 1]!).tokenOut,
114
134
  a.amountIn,
115
135
  a.minOut,
116
136
  resolveRecipient(c, a),