@logswap/sdk 0.5.90 → 0.5.92

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.
Files changed (59) hide show
  1. package/README.md +136 -31
  2. package/dist/actions.js +4 -3
  3. package/dist/admin.d.ts +96 -925
  4. package/dist/admin.js +113 -194
  5. package/dist/chains.d.ts +13 -4
  6. package/dist/chains.js +22 -9
  7. package/dist/claims.d.ts +1 -1
  8. package/dist/claims.js +11 -9
  9. package/dist/client.d.ts +42 -20
  10. package/dist/client.js +86 -26
  11. package/dist/fees.d.ts +1 -1
  12. package/dist/fees.js +5 -4
  13. package/dist/fpool.d.ts +327 -1120
  14. package/dist/fpool.js +408 -475
  15. package/dist/generated.d.ts +5017 -7631
  16. package/dist/generated.js +3040 -4879
  17. package/dist/history.js +12 -14
  18. package/dist/index.d.ts +5 -7
  19. package/dist/index.js +5 -7
  20. package/dist/indexer.d.ts +2 -2
  21. package/dist/indexer.js +12 -9
  22. package/dist/keys.d.ts +15 -3
  23. package/dist/keys.js +5 -1
  24. package/dist/liquidity.d.ts +1 -1
  25. package/dist/liquidity.js +16 -9
  26. package/dist/onboard.d.ts +16 -11
  27. package/dist/onboard.js +27 -21
  28. package/dist/pools.d.ts +2 -0
  29. package/dist/pools.js +21 -13
  30. package/dist/positions.d.ts +1 -1
  31. package/dist/positions.js +18 -17
  32. package/dist/quote.d.ts +15 -0
  33. package/dist/quote.js +36 -0
  34. package/dist/swap.d.ts +7 -9
  35. package/dist/swap.js +40 -25
  36. package/dist/views.d.ts +1 -1
  37. package/dist/write.d.ts +7 -2
  38. package/dist/write.js +10 -7
  39. package/package.json +3 -3
  40. package/src/actions.ts +4 -3
  41. package/src/admin.ts +143 -249
  42. package/src/chains.ts +32 -13
  43. package/src/claims.ts +11 -10
  44. package/src/client.ts +111 -39
  45. package/src/fees.ts +6 -6
  46. package/src/fpool.ts +555 -648
  47. package/src/generated.ts +3063 -4904
  48. package/src/history.ts +11 -11
  49. package/src/index.ts +5 -7
  50. package/src/indexer.ts +13 -11
  51. package/src/keys.ts +19 -3
  52. package/src/liquidity.ts +16 -10
  53. package/src/onboard.ts +29 -21
  54. package/src/pools.ts +23 -15
  55. package/src/positions.ts +18 -18
  56. package/src/quote.ts +36 -0
  57. package/src/swap.ts +46 -25
  58. package/src/views.ts +1 -2
  59. package/src/write.ts +11 -10
package/src/chains.ts CHANGED
@@ -7,7 +7,7 @@
7
7
  * together with a chain id; every cache and every indexer URL in this SDK is per chain.
8
8
  */
9
9
 
10
- import { defineChain, getAddress, isAddress, type Address, type Chain } from "viem";
10
+ import { defineChain, getAddress, isAddress, zeroAddress, type Address, type Chain } from "viem";
11
11
  import { arbitrum, base, foundry, mainnet, robinhood, robinhoodTestnet } from "viem/chains";
12
12
  import type { LogswapAddresses } from "./client.js";
13
13
 
@@ -153,14 +153,23 @@ export interface LogswapDeployment {
153
153
  permit2: Address;
154
154
  multicall3: Address;
155
155
  policyRegistry: Address;
156
- fPoolManager: Address;
157
- cPoolManager: Address;
156
+ managerF: Address;
157
+ routerF: Address;
158
+ lensF: Address;
159
+ /** The C stack (decision 096): absent while the chain has not opted into C (the artifact carries `address(0)` and `cVersion` 0). */
160
+ managerC?: Address;
161
+ routerC?: Address;
162
+ lensC?: Address;
163
+ /** The LOG's open F policy (`PolicyF`, `open`: anyone creates at salt zero, no gate ever; policy.md). */
158
164
  publicPolicy: Address;
165
+ /** The LOG's desk on F (`PolicyF`, closed: the LOG creates, gates by pool). The artifact key predates 098 and is kept. */
159
166
  privatePolicy: Address;
167
+ /** The LOG's POL policy on F (`PolicyF`: one base, a bid buffer, an income tax). */
160
168
  polPolicy: Address;
169
+ /** The LOG's pad policy on F (`PolicyF`, `seedToDead`: income-only harvests, never closes). */
161
170
  padPolicy: Address;
162
- router: Address;
163
- lens: Address;
171
+ /** The LOG's open sponsored instance on C (`SponsorPolicyC`). Absent while the chain has no C stack. */
172
+ publicPolicyC?: Address;
164
173
  /** The devnet's token factory; local deployments only. */
165
174
  tokenFactory?: Address;
166
175
  }
@@ -183,16 +192,19 @@ const REQUIRED_ADDRESSES = [
183
192
  "permit2",
184
193
  "multicall3",
185
194
  "policyRegistry",
186
- "fPoolManager",
187
- "cPoolManager",
195
+ "managerF",
196
+ "routerF",
197
+ "lensF",
188
198
  "publicPolicy",
189
199
  "privatePolicy",
190
200
  "polPolicy",
191
201
  "padPolicy",
192
- "router",
193
- "lens",
194
202
  ] as const;
195
203
  const OPTIONAL_ADDRESSES = ["createX", "tokenFactory"] as const;
204
+ /** Policies an artifact may carry as `address(0)` (no C stack): zero is absent. An `orphanPolicy` key on an older artifact is ignored (F 41 has none). */
205
+ const OPTIONAL_POLICIES = ["publicPolicyC"] as const;
206
+ /** The C stack: all three, or none (`address(0)` — the chain has not opted into C yet). */
207
+ const C_STACK = ["managerC", "routerC", "lensC"] as const;
196
208
 
197
209
  function uint(o: Record<string, unknown>, k: string): bigint {
198
210
  const v = o[k];
@@ -238,20 +250,27 @@ export function deploymentFromArtifact(json: unknown, opts: { chainId?: number }
238
250
  }
239
251
  for (const k of REQUIRED_ADDRESSES) d[k] = address(o, k);
240
252
  for (const k of OPTIONAL_ADDRESSES) if (o[k] !== undefined) d[k] = address(o, k);
253
+ for (const k of OPTIONAL_POLICIES) if (o[k] !== undefined && address(o, k) !== zeroAddress) d[k] = address(o, k);
254
+ const present = C_STACK.filter((k) => o[k] !== undefined && address(o, k) !== zeroAddress);
255
+ if (present.length !== 0 && present.length !== C_STACK.length) {
256
+ throw new Error(`logswap: deployment artifact: the C stack is all or nothing, but only ${present.join(", ")} ${present.length === 1 ? "is" : "are"} set`);
257
+ }
258
+ for (const k of present) d[k] = address(o, k);
241
259
  return d as unknown as LogswapDeployment;
242
260
  }
243
261
 
244
262
  /** The client's address set from a deployment. */
245
263
  export function addressesOfDeployment(d: LogswapDeployment): LogswapAddresses {
246
264
  return {
247
- cPoolManager: d.cPoolManager,
248
- router: d.router,
249
- lens: d.lens,
250
- fPoolManager: d.fPoolManager,
265
+ managerF: d.managerF,
266
+ routerF: d.routerF,
267
+ lensF: d.lensF,
268
+ ...(d.managerC && d.routerC && d.lensC ? { managerC: d.managerC, routerC: d.routerC, lensC: d.lensC } : {}),
251
269
  publicPolicy: d.publicPolicy,
252
270
  privatePolicy: d.privatePolicy,
253
271
  polPolicy: d.polPolicy,
254
272
  padPolicy: d.padPolicy,
273
+ ...(d.publicPolicyC ? { publicPolicyC: d.publicPolicyC } : {}),
255
274
  policyRegistry: d.policyRegistry,
256
275
  permit2: d.permit2,
257
276
  ...(d.tokenFactory ? { tokenFactory: d.tokenFactory } : {}),
package/src/claims.ts CHANGED
@@ -7,8 +7,8 @@
7
7
  */
8
8
 
9
9
  import type { Address, Hash } from "viem";
10
- import { cPoolManagerAbi, routerAbi } from "./generated.js";
11
- import type { LogswapClient } from "./client.js";
10
+ import { managerCAbi, routerCAbi } from "./generated.js";
11
+ import { managerC, routerC, type LogswapClient } from "./client.js";
12
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";
@@ -36,7 +36,8 @@ export async function claimFees(c: LogswapClient, a: ClaimFeesArgs): Promise<Has
36
36
  }
37
37
  }
38
38
  return sendRouterWrite(c, {
39
- abi: routerAbi,
39
+ side: "C",
40
+ abi: routerCAbi,
40
41
  functionName: "claim",
41
42
  args: [keyId(a.key), a.key.quote, a.ids, resolveRecipient(c, a), resolveDeadline(a)],
42
43
  });
@@ -54,10 +55,10 @@ export async function claimFees(c: LogswapClient, a: ClaimFeesArgs): Promise<Has
54
55
  export async function approveRouterAsOperator(c: LogswapClient, approved = true): Promise<Hash> {
55
56
  const { account } = requireWallet(c);
56
57
  return c.wallet!.writeContract({
57
- address: c.addresses.cPoolManager,
58
- abi: cPoolManagerAbi,
58
+ address: managerC(c),
59
+ abi: managerCAbi,
59
60
  functionName: "setOperator",
60
- args: [c.addresses.router, approved],
61
+ args: [routerC(c), approved],
61
62
  account,
62
63
  chain: c.wallet!.chain,
63
64
  } as never);
@@ -66,10 +67,10 @@ export async function approveRouterAsOperator(c: LogswapClient, approved = true)
66
67
  /** Is the router already an operator for `owner`? Check before prompting for a signature. */
67
68
  export async function isRouterApproved(c: LogswapClient, owner: Address): Promise<boolean> {
68
69
  return c.public.readContract({
69
- address: c.addresses.cPoolManager,
70
- abi: cPoolManagerAbi,
70
+ address: managerC(c),
71
+ abi: managerCAbi,
71
72
  functionName: "isOperator",
72
- args: [owner, c.addresses.router],
73
+ args: [owner, routerC(c)],
73
74
  }) as Promise<boolean>;
74
75
  }
75
76
 
@@ -98,7 +99,7 @@ export async function checkReadiness(
98
99
  const { checkTokenReadiness } = await import("./onboard.js");
99
100
  const ready = async (token: Address, amount?: bigint) => {
100
101
  if (amount === undefined) return true;
101
- const r = await checkTokenReadiness(c, token, owner, amount);
102
+ const r = await checkTokenReadiness(c, "C", token, owner, amount);
102
103
  return !r.needsTokenApproval && !r.needsPermit2Approval;
103
104
  };
104
105
  const [operator, baseOk, quoteOk] = await Promise.all([
package/src/client.ts CHANGED
@@ -3,35 +3,47 @@
3
3
  *
4
4
  * Construct once and pass to every helper. `wallet` is optional: read helpers need only `public`.
5
5
  *
6
- * **Three addresses, permanently.** Not three per market — every market lives in the one manager,
7
- * and a market is an `initialize(key, x0)` call rather than a deployment. So this is a constant of
8
- * the protocol, not configuration that grows.
6
+ * **One stack per manager, permanently** (decision 096): a manager, its router and its lens, for F and for
7
+ * C. Not per market — every market lives in the one manager of its side, and a market is an
8
+ * `initialize` call rather than a deployment. F ships first, so the C stack is optional: a chain
9
+ * that has not opted into C carries `address(0)` for it, and every C call throws a plain error there.
9
10
  */
10
11
 
11
12
  import type { Address, PublicClient, WalletClient } from "viem";
12
13
  import { addressesOfDeployment, DEFAULT_MAX_LOG_RANGE, logswapChain, type LogswapChain, type LogswapDeployment } from "./chains.js";
13
14
 
15
+ /** The two singletons: `C` is the concentrated one (a floor per position, a tick ladder), `F` the fungible one. */
16
+ export type Side = "C" | "F";
17
+
14
18
  export interface LogswapAddresses {
15
- /** The C singleton — a floor per position, on a tick ladder. ERC-6909 positions and token
16
- * claims live here. */
17
- cPoolManager: Address;
18
- /** User entry for every market: multicall, blended mint, zap, routes, Permit2. */
19
- router: Address;
20
- /** Read-only: ladder derivations and revert-quoter previews. */
21
- lens: Address;
19
+ /** The F singleton — fungible claims, one shared floor, n bases. ERC-6909 shares and token claims live here. */
20
+ managerF: Address;
21
+ /** F's user entry: swaps, zaps, roll-in, Permit2. Its own Permit2 spender. */
22
+ routerF: Address;
23
+ /** F's read-only lens: pool views and previews. */
24
+ lensF: Address;
22
25
  /**
23
- * The F-pool singleton — fungible claims, one shared floor, n bases. Optional only because a
24
- * deployment predating it will not carry the address; every F-pool call needs it.
26
+ * The C singleton — a floor per position, on a tick ladder. ERC-6909 positions and token claims live here.
27
+ * The C stack is optional: F ships first, and a chain that has not opted into C carries none.
25
28
  */
26
- fPoolManager?: Address;
29
+ managerC?: Address;
30
+ /** C's user entry: the batch, the named one-action entries, `createMarket`, Permit2. Its own Permit2 spender. */
31
+ routerC?: Address;
32
+ /** C's read-only lens: ladder derivations and views. */
33
+ lensC?: Address;
27
34
  /**
28
- * The protocol's four F policies, one per kind: every F pool names one in its key,
29
- * and the pool's roles, gates and terms live on it. A deployment predating them carries none.
35
+ * The LOG's policies (decision 098: immutable, deployed by the LOG): every pool names one in its key for life, and the pool's
36
+ * roles, gates and terms live on it. On F the four are instances of one contract, `PolicyF` (F 41, policy.md), told apart by
37
+ * their immutables: `publicPolicy` is the open one (anyone creates at salt zero, no gate ever), `privatePolicy` the LOG's desk
38
+ * (closed, gates by pool), `polPolicy` and `padPolicy` the treasury's and the launch's. The artifact keys predate 098 and are
39
+ * kept. A deployment predating the policies carries none.
30
40
  */
31
41
  publicPolicy?: Address;
32
42
  privatePolicy?: Address;
33
43
  polPolicy?: Address;
34
44
  padPolicy?: Address;
45
+ /** The LOG's open sponsored instance on C (`SponsorPolicyC`): the policy of a public market. Absent with no C stack. */
46
+ publicPolicyC?: Address;
35
47
  /**
36
48
  * The policy registry: what a pool of each kind may be born under, and the
37
49
  * owner that may move a pool between policies. Read from the F manager (`registry()`) when
@@ -40,10 +52,44 @@ export interface LogswapAddresses {
40
52
  policyRegistry?: Address;
41
53
  /** The devnet's token factory (`TokenFactory`, a mock): where launchable tokens come from. Optional. */
42
54
  tokenFactory?: Address;
43
- /** Optional — the router falls back to plain approvals when absent. */
55
+ /** Optional — each router falls back to plain approvals when absent. */
44
56
  permit2?: Address;
45
57
  }
46
58
 
59
+ const ZERO_ADDRESS = "0x0000000000000000000000000000000000000000" as const;
60
+ const NO_C = "logswap: this deployment has no C stack (managerC / routerC / lensC) — F ships first, C lands with its own deployment";
61
+
62
+ /** Whether the deployment carries the C stack. */
63
+ export function hasC(c: LogswapClient): boolean {
64
+ const a = c.addresses;
65
+ return has(a.managerC) && has(a.routerC) && has(a.lensC);
66
+ }
67
+
68
+ const has = (a?: Address): a is Address => !!a && a !== ZERO_ADDRESS;
69
+
70
+ /** The C manager; throws where the deployment has none. */
71
+ export function managerC(c: LogswapClient): Address {
72
+ const a = c.addresses.managerC;
73
+ if (!has(a)) throw new Error(NO_C);
74
+ return a;
75
+ }
76
+ /** The C router; throws where the deployment has none. */
77
+ export function routerC(c: LogswapClient): Address {
78
+ const a = c.addresses.routerC;
79
+ if (!has(a)) throw new Error(NO_C);
80
+ return a;
81
+ }
82
+ /** The C lens; throws where the deployment has none. */
83
+ export function lensC(c: LogswapClient): Address {
84
+ const a = c.addresses.lensC;
85
+ if (!has(a)) throw new Error(NO_C);
86
+ return a;
87
+ }
88
+ /** The router of `side` — the contract that pulls the caller's tokens, and the spender to approve. */
89
+ export function routerOf(c: LogswapClient, side: Side): Address {
90
+ return side === "F" ? c.addresses.routerF : routerC(c);
91
+ }
92
+
47
93
  export interface LogswapClient {
48
94
  public: PublicClient;
49
95
  wallet?: WalletClient;
@@ -173,7 +219,7 @@ function guardChain(wallet: WalletClient, pub: PublicClient): WalletClient {
173
219
  * **8** since 2026-10-13 (logswap-contract decision 066): the collector is split into two roles —
174
220
  * `feeCollector` / `proposeCollector` / `acceptCollector` are `treasury` / `proposeTreasury` (the
175
221
  * LOG Authority's) / `acceptTreasury`; `setSwapFeeTax` and `setGate` leave the manager: the tax is
176
- * each market's, answered by the gate (`PublicPolicy.swapFeeTax`, the LOG Authority's) at birth and
222
+ * each market's, answered by its policy at birth (since 098, `SponsorPolicyC.swapFeeTax`, an immutable) and
177
223
  * read as `getPool(key).swapFeeTax`; the gate is fixed at construction; `collectProtocolFees(key)` is
178
224
  * permissionless and pays the treasury. No pool id moved.
179
225
  * 9 (decision 071): the events — one `Swap` on both managers (`taker`, `feeToken`), `CSwapState`, C's `swap`
@@ -188,7 +234,16 @@ function guardChain(wallet: WalletClient, pub: PublicClient): WalletClient {
188
234
  // only; no pool id moved), the router's named entries take the tokens the caller expects (`WrongToken`), `claimById` / `burnById` /
189
235
  // `claimManyFor` are `claim` / `burn` / `claimMany`, `mint(poolId, to, floor, cap, L)`, `MarketCreated` is `PoolCreated` (in F's field
190
236
  // order), `x0` is `initialLogPrice`, `PoolView.x` / `.F` are `logPrice` / `feeGrowth`, `swapFee` / `mintFee` are `uint56`.
191
- export const EXPECTED_VERSION = 13n;
237
+ // 14 (decision 092): the C quoter is the router's (`Router.quoteSwap(poolId, exactIn, baseSide, amount, taker)`); `CPoolManager.quoteSwap`
238
+ // and the Lens's `previewSwapExactIn` / `Out` / `InBatch` are gone. No pool id moved.
239
+ // 15 (decision 097): `PoolKeyC` is `(base, quote, tickSpacing, policy, creator, salt, swapFee, mintFee)` — every C pool id moved; the creator
240
+ // initializes and makes the first mint (`NotCreator`); `PoolCreated` carries the salt; the backstop is held by 0xdead; a malformed policy
241
+ // answer is `BadTerms`. The names are decision 096's (no `c` prefix on a function or an event; `SwapState`); a router and a lens per manager.
242
+ // 16 (decision 098): the policies are immutable and the LOG's — `SponsorPolicyC` replaces `PublicPolicy` / `PrivatePolicy`; `setPermissions` /
243
+ // `PermissionsSet` are `setGates(poolId, gates, operator)` / `GatesSet`; the birth answer is `(flags, tax, operator)`; the policy's
244
+ // numbers (tiers, quotes, spacings, tax) are constructor immutables; the swap and mint gates are one bit each (`GATE_SWAP`,
245
+ // `GATE_MINT`) and the cached operator passes with no policy call. No pool id moved.
246
+ export const EXPECTED_VERSION = 16n;
192
247
  /**
193
248
  * The F manager's own tag (5 — the key's salt, pool names, the sponsor registry;
194
249
  * 4 was the income-only harvest cut).
@@ -291,28 +346,43 @@ export const EXPECTED_VERSION = 13n;
291
346
  // income fee are the income and the income tax (`IncomeReleased`, `incomeHeld`, `incomeTax`); a pad is uncapped.
292
347
  // 39 (decision 087): `swapFeeB4B` is gone; base-for-base pays `swapFee` once, not 2·swapFee.
293
348
  // A breaking bump: raised in the same change.
294
- export const EXPECTED_F_VERSION = 39n;
349
+ // 40 (decision 098): the policies are immutable and the LOG's — `SponsorPolicyF` replaces `PublicPolicy` / `PrivatePolicy`, `PolPolicy` /
350
+ // `PadPolicy` lose their setters (and the lists, the handover and `creator`: the authority is `key.creator` for life); `Pool.asks` is
351
+ // `Pool.flags` (`GATE_SWAP` 1, `GATE_MINT` 2, `SEED_TO_DEAD` 4) and `Pool.operator` caches the operator; `setPermissions` /
352
+ // `PermissionsSet` are `setGates` / `GatesSet`; the registry's `migrate(manager, key, to, permissions)` replaces `migratePrivate`,
353
+ // `orphan(manager, key)` moves a pool to `OrphanPolicyF`. No pool id moved.
354
+ // 41 (policy.md): one policy contract, `PolicyF`, whose kinds are parameter sets — `SponsorPolicyF`, `PolPolicy`, `PadPolicy` and
355
+ // `OrphanPolicyF` are gone. The AUTHORITY is the policy's (immutable) and appoints each pool's OPERATOR, who funds, harvests, closes
356
+ // and sets the modes and the name. `PoolKeyF` is `(quote, bases, swapFeeIdx, policy, salt)` — no creator, no mint fee: the swap fee is
357
+ // an index into `FEE_LIST` (1, 2, 5, 10, 20, 50, 100, 200 bp) and the mint fee the next entry — so EVERY POOL ID MOVED.
358
+ // `deployLiquidity(poolId, baseAssets, quoteAmount, lnCapOverSeed)` on an inactive pool only (no `to`: the operator holds the
359
+ // shares); `harvest(poolId, extra, to)` takes the income and `extra` capital; `close(poolId, to)` at any bid, harvesting first,
360
+ // refused on a pad; `regenerate` is gone (`multicall(close, redeem, deployLiquidity)`); the registry's `migrate`, `orphan` and
361
+ // `setOrphanPolicy` are gone, `sunset` also refuses `deployLiquidity`. `PoolCreated(poolId, quote, policy, bases, swapFeeIdx, salt)`;
362
+ // `IncomeHarvested(poolId, to, gen, income, capital, tax, toOperator, Q)`; `GenerationFrozen` from `close` alone; `IncomeReleased` and
363
+ // `PolicyMigrated` are gone. The policy's name is an event (`NameSet`), its lists are per policy (`setRights`, `RightsSet`), its
364
+ // modes per pool (`setSwapMode` / `setMintMode`, each Open < Listed < Operator with `mintMode ≥ swapMode`).
365
+ export const EXPECTED_F_VERSION = 41n;
295
366
 
296
367
  export async function assertVersion(c: LogswapClient, expected = EXPECTED_VERSION): Promise<void> {
297
- const { cPoolManagerAbi, fPoolManagerAbi } = await import("./generated.js");
298
- // three independent reads: one round trip, not three in a row
299
- const [got, gotF, wiring] = await Promise.all([
300
- c.public.readContract({ address: c.addresses.cPoolManager, abi: cPoolManagerAbi, functionName: "version" }),
301
- // the F manager carries its own tag; assert it the same way when deployed
302
- c.addresses.fPoolManager
303
- ? c.public.readContract({ address: c.addresses.fPoolManager, abi: fPoolManagerAbi, functionName: "version" })
304
- : Promise.resolve(null),
368
+ const { managerCAbi, managerFAbi } = await import("./generated.js");
369
+ const withC = hasC(c);
370
+ // independent reads: one round trip, not one per manager
371
+ const [gotC, gotF, wiring] = await Promise.all([
372
+ // the C stack is optional (F ships first); asserted the same way when deployed
373
+ withC ? c.public.readContract({ address: c.addresses.managerC!, abi: managerCAbi, functionName: "version" }) : Promise.resolve(null),
374
+ c.public.readContract({ address: c.addresses.managerF, abi: managerFAbi, functionName: "version" }),
305
375
  assertWiring(c).then(() => null, (e: unknown) => e),
306
376
  ]);
307
- if (got !== expected) {
377
+ if (gotC !== null && gotC !== expected) {
308
378
  throw new Error(
309
- `logswap: manager at ${c.addresses.cPoolManager} reports version ${got}, but this SDK was built ` +
379
+ `logswap: C manager at ${c.addresses.managerC} reports version ${gotC}, but this SDK was built ` +
310
380
  `against version ${expected}. Upgrade the SDK or point at the matching deployment.`,
311
381
  );
312
382
  }
313
- if (gotF !== null && gotF < EXPECTED_F_VERSION) {
383
+ if (gotF < EXPECTED_F_VERSION) {
314
384
  throw new Error(
315
- `logswap: F manager at ${c.addresses.fPoolManager} reports version ${gotF}, but this SDK needs ` +
385
+ `logswap: F manager at ${c.addresses.managerF} reports version ${gotF}, but this SDK needs ` +
316
386
  `at least F version ${EXPECTED_F_VERSION}. Upgrade the deployment or point at a newer one.`,
317
387
  );
318
388
  }
@@ -324,21 +394,23 @@ export async function assertVersion(c: LogswapClient, expected = EXPECTED_VERSIO
324
394
  * The versions say the managers are the right code; this says the rest of the addresses belong
325
395
  * to THEM. A stale router or lens from a previous deployment passes every version check and then
326
396
  * fails in the worst way: approvals go to a router that pulls for another manager, or every pull
327
- * reverts because the router's Permit2 is not the one the user approved.
397
+ * reverts because the router's Permit2 is not the one the user approved. Each side is checked on its
398
+ * own: the router and the lens name their manager (`mgr()`), and the router its Permit2.
328
399
  */
329
400
  export async function assertWiring(c: LogswapClient): Promise<void> {
330
- const { routerAbi, lensAbi } = await import("./generated.js");
401
+ const { routerCAbi, routerFAbi, lensCAbi, lensFAbi } = await import("./generated.js");
331
402
  const rd = (address: Address, abi: readonly unknown[], functionName: string) =>
332
403
  c.public.readContract({ address, abi, functionName } as never) as Promise<Address>;
333
404
  const ZERO = "0x0000000000000000000000000000000000000000";
334
405
  const want: Array<[string, Promise<Address>, Address]> = [
335
- ["router.mgr()", rd(c.addresses.router, routerAbi, "mgr"), c.addresses.cPoolManager],
336
- ["router.permit2()", rd(c.addresses.router, routerAbi, "permit2"), c.addresses.permit2 ?? ZERO],
337
- ["lens.mgr()", rd(c.addresses.lens, lensAbi, "mgr"), c.addresses.cPoolManager],
406
+ ["routerF.mgr()", rd(c.addresses.routerF, routerFAbi, "mgr"), c.addresses.managerF],
407
+ ["routerF.permit2()", rd(c.addresses.routerF, routerFAbi, "permit2"), c.addresses.permit2 ?? ZERO],
408
+ ["lensF.mgr()", rd(c.addresses.lensF, lensFAbi, "mgr"), c.addresses.managerF],
338
409
  ];
339
- if (c.addresses.fPoolManager) {
340
- want.push(["router.fmgr()", rd(c.addresses.router, routerAbi, "fmgr"), c.addresses.fPoolManager]);
341
- want.push(["lens.fmgr()", rd(c.addresses.lens, lensAbi, "fmgr"), c.addresses.fPoolManager]);
410
+ if (hasC(c)) {
411
+ want.push(["routerC.mgr()", rd(c.addresses.routerC!, routerCAbi, "mgr"), c.addresses.managerC!]);
412
+ want.push(["routerC.permit2()", rd(c.addresses.routerC!, routerCAbi, "permit2"), c.addresses.permit2 ?? ZERO]);
413
+ want.push(["lensC.mgr()", rd(c.addresses.lensC!, lensCAbi, "mgr"), c.addresses.managerC!]);
342
414
  }
343
415
  const got = await Promise.all(want.map((w) => w[1]));
344
416
  const bad = want.flatMap(([what, , expected], i) =>
package/src/fees.ts CHANGED
@@ -11,8 +11,8 @@
11
11
  * Both equal φ·L·|Δx| summed over the swap's segments — the same φ·|dx| per unit L that `F` books.
12
12
  */
13
13
 
14
- import type { LogswapClient } from "./client.js";
15
- import { cPoolManagerAbi } from "./generated.js";
14
+ import { managerC, type LogswapClient } from "./client.js";
15
+ import { managerCAbi } from "./generated.js";
16
16
  import type { DiscoveredMarket } from "./pools.js";
17
17
  import { getEventLogs } from "./history.js";
18
18
  import { swapFlows } from "./views.js";
@@ -21,7 +21,7 @@ import { swapFlows } from "./views.js";
21
21
  async function windowFromView(c: LogswapClient, indexer: string, poolId: string, fromBlock: bigint, toBlock: bigint): Promise<{ fees: bigint; swaps: number } | null> {
22
22
  try {
23
23
  const rows = await swapFlows(indexer, {
24
- condition: { side: "C", poolId: poolId.toLowerCase(), manager: c.addresses.cPoolManager.toLowerCase() },
24
+ condition: { side: "C", poolId: poolId.toLowerCase(), manager: managerC(c).toLowerCase() },
25
25
  filter: { blockNumber: { greaterThanOrEqualTo: fromBlock.toString(), lessThanOrEqualTo: toBlock.toString() } },
26
26
  });
27
27
  let fees = 0n;
@@ -123,8 +123,8 @@ export async function swapFees(
123
123
  from = opened.timestamp;
124
124
  }
125
125
 
126
- type Ev = Extract<(typeof cPoolManagerAbi)[number], { type: "event"; name: "Swap" }>;
127
- const ev = cPoolManagerAbi.find((x): x is Ev => x.type === "event" && x.name === "Swap");
126
+ type Ev = Extract<(typeof managerCAbi)[number], { type: "event"; name: "Swap" }>;
127
+ const ev = managerCAbi.find((x): x is Ev => x.type === "event" && x.name === "Swap");
128
128
  if (!ev) throw new Error("logswap: Swap event missing from the generated ABI");
129
129
 
130
130
  // the event carries the fee the swap charged (decisions 050), exactly — no re-derivation from φ;
@@ -136,7 +136,7 @@ export async function swapFees(
136
136
  if (viewed) {
137
137
  ({ fees, swaps } = viewed);
138
138
  } else if (fromBlock <= toBlock) {
139
- const { logs } = await getEventLogs<{ fee: bigint }>(c, { indexer, address: c.addresses.cPoolManager, event: ev, args: { poolId: m.poolId }, fromBlock, toBlock });
139
+ const { logs } = await getEventLogs<{ fee: bigint }>(c, { indexer, address: managerC(c), event: ev, args: { poolId: m.poolId }, fromBlock, toBlock });
140
140
  for (const l of logs) fees += l.args.fee;
141
141
  swaps = logs.length;
142
142
  }