@logswap/sdk 0.5.90 → 0.5.91

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 +74 -12
  2. package/dist/actions.js +4 -3
  3. package/dist/admin.d.ts +213 -219
  4. package/dist/admin.js +118 -144
  5. package/dist/chains.d.ts +13 -4
  6. package/dist/chains.js +23 -9
  7. package/dist/claims.d.ts +1 -1
  8. package/dist/claims.js +11 -9
  9. package/dist/client.d.ts +43 -20
  10. package/dist/client.js +75 -26
  11. package/dist/fees.d.ts +1 -1
  12. package/dist/fees.js +5 -4
  13. package/dist/fpool.d.ts +170 -460
  14. package/dist/fpool.js +175 -218
  15. package/dist/generated.d.ts +5549 -6027
  16. package/dist/generated.js +2580 -3153
  17. package/dist/history.js +13 -11
  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 +168 -171
  42. package/src/chains.ts +33 -13
  43. package/src/claims.ts +11 -10
  44. package/src/client.ts +101 -39
  45. package/src/fees.ts +6 -6
  46. package/src/fpool.ts +240 -272
  47. package/src/generated.ts +2525 -3094
  48. package/src/history.ts +11 -9
  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/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,48 @@
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, and the pool's
36
+ * roles, gates and terms live on it. `publicPolicy` and `privatePolicy` are the LOG's two sponsored instances on F
37
+ * (`SponsorPolicyF`, kind `"sponsor"`: the open canonical one, and the gated one that is born gated); the artifact keys
38
+ * predate 098 and are kept. A deployment predating the policies carries none.
30
39
  */
31
40
  publicPolicy?: Address;
32
41
  privatePolicy?: Address;
33
42
  polPolicy?: Address;
34
43
  padPolicy?: Address;
44
+ /** The LOG's open sponsored instance on C (`SponsorPolicyC`): the policy of a public market. Absent with no C stack. */
45
+ publicPolicyC?: Address;
46
+ /** F's orphan policy (`OrphanPolicyF`, kind `"orphan"`): the policy `PolicyRegistry.orphan` moves a pool to. */
47
+ orphanPolicy?: Address;
35
48
  /**
36
49
  * The policy registry: what a pool of each kind may be born under, and the
37
50
  * owner that may move a pool between policies. Read from the F manager (`registry()`) when
@@ -40,10 +53,44 @@ export interface LogswapAddresses {
40
53
  policyRegistry?: Address;
41
54
  /** The devnet's token factory (`TokenFactory`, a mock): where launchable tokens come from. Optional. */
42
55
  tokenFactory?: Address;
43
- /** Optional — the router falls back to plain approvals when absent. */
56
+ /** Optional — each router falls back to plain approvals when absent. */
44
57
  permit2?: Address;
45
58
  }
46
59
 
60
+ const ZERO_ADDRESS = "0x0000000000000000000000000000000000000000" as const;
61
+ const NO_C = "logswap: this deployment has no C stack (managerC / routerC / lensC) — F ships first, C lands with its own deployment";
62
+
63
+ /** Whether the deployment carries the C stack. */
64
+ export function hasC(c: LogswapClient): boolean {
65
+ const a = c.addresses;
66
+ return has(a.managerC) && has(a.routerC) && has(a.lensC);
67
+ }
68
+
69
+ const has = (a?: Address): a is Address => !!a && a !== ZERO_ADDRESS;
70
+
71
+ /** The C manager; throws where the deployment has none. */
72
+ export function managerC(c: LogswapClient): Address {
73
+ const a = c.addresses.managerC;
74
+ if (!has(a)) throw new Error(NO_C);
75
+ return a;
76
+ }
77
+ /** The C router; throws where the deployment has none. */
78
+ export function routerC(c: LogswapClient): Address {
79
+ const a = c.addresses.routerC;
80
+ if (!has(a)) throw new Error(NO_C);
81
+ return a;
82
+ }
83
+ /** The C lens; throws where the deployment has none. */
84
+ export function lensC(c: LogswapClient): Address {
85
+ const a = c.addresses.lensC;
86
+ if (!has(a)) throw new Error(NO_C);
87
+ return a;
88
+ }
89
+ /** The router of `side` — the contract that pulls the caller's tokens, and the spender to approve. */
90
+ export function routerOf(c: LogswapClient, side: Side): Address {
91
+ return side === "F" ? c.addresses.routerF : routerC(c);
92
+ }
93
+
47
94
  export interface LogswapClient {
48
95
  public: PublicClient;
49
96
  wallet?: WalletClient;
@@ -173,7 +220,7 @@ function guardChain(wallet: WalletClient, pub: PublicClient): WalletClient {
173
220
  * **8** since 2026-10-13 (logswap-contract decision 066): the collector is split into two roles —
174
221
  * `feeCollector` / `proposeCollector` / `acceptCollector` are `treasury` / `proposeTreasury` (the
175
222
  * 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
223
+ * each market's, answered by its policy at birth (since 098, `SponsorPolicyC.swapFeeTax`, an immutable) and
177
224
  * read as `getPool(key).swapFeeTax`; the gate is fixed at construction; `collectProtocolFees(key)` is
178
225
  * permissionless and pays the treasury. No pool id moved.
179
226
  * 9 (decision 071): the events — one `Swap` on both managers (`taker`, `feeToken`), `CSwapState`, C's `swap`
@@ -188,7 +235,16 @@ function guardChain(wallet: WalletClient, pub: PublicClient): WalletClient {
188
235
  // only; no pool id moved), the router's named entries take the tokens the caller expects (`WrongToken`), `claimById` / `burnById` /
189
236
  // `claimManyFor` are `claim` / `burn` / `claimMany`, `mint(poolId, to, floor, cap, L)`, `MarketCreated` is `PoolCreated` (in F's field
190
237
  // order), `x0` is `initialLogPrice`, `PoolView.x` / `.F` are `logPrice` / `feeGrowth`, `swapFee` / `mintFee` are `uint56`.
191
- export const EXPECTED_VERSION = 13n;
238
+ // 14 (decision 092): the C quoter is the router's (`Router.quoteSwap(poolId, exactIn, baseSide, amount, taker)`); `CPoolManager.quoteSwap`
239
+ // and the Lens's `previewSwapExactIn` / `Out` / `InBatch` are gone. No pool id moved.
240
+ // 15 (decision 097): `PoolKeyC` is `(base, quote, tickSpacing, policy, creator, salt, swapFee, mintFee)` — every C pool id moved; the creator
241
+ // initializes and makes the first mint (`NotCreator`); `PoolCreated` carries the salt; the backstop is held by 0xdead; a malformed policy
242
+ // 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.
243
+ // 16 (decision 098): the policies are immutable and the LOG's — `SponsorPolicyC` replaces `PublicPolicy` / `PrivatePolicy`; `setPermissions` /
244
+ // `PermissionsSet` are `setGates(poolId, gates, operator)` / `GatesSet`; the birth answer is `(flags, tax, operator)`; the policy's
245
+ // numbers (tiers, quotes, spacings, tax) are constructor immutables; the swap and mint gates are one bit each (`GATE_SWAP`,
246
+ // `GATE_MINT`) and the cached operator passes with no policy call. No pool id moved.
247
+ export const EXPECTED_VERSION = 16n;
192
248
  /**
193
249
  * The F manager's own tag (5 — the key's salt, pool names, the sponsor registry;
194
250
  * 4 was the income-only harvest cut).
@@ -291,28 +347,32 @@ export const EXPECTED_VERSION = 13n;
291
347
  // income fee are the income and the income tax (`IncomeReleased`, `incomeHeld`, `incomeTax`); a pad is uncapped.
292
348
  // 39 (decision 087): `swapFeeB4B` is gone; base-for-base pays `swapFee` once, not 2·swapFee.
293
349
  // A breaking bump: raised in the same change.
294
- export const EXPECTED_F_VERSION = 39n;
350
+ // 40 (decision 098): the policies are immutable and the LOG's — `SponsorPolicyF` replaces `PublicPolicy` / `PrivatePolicy`, `PolPolicy` /
351
+ // `PadPolicy` lose their setters (and the lists, the handover and `creator`: the authority is `key.creator` for life); `Pool.asks` is
352
+ // `Pool.flags` (`GATE_SWAP` 1, `GATE_MINT` 2, `SEED_TO_DEAD` 4) and `Pool.operator` caches the operator; `setPermissions` /
353
+ // `PermissionsSet` are `setGates` / `GatesSet`; the registry's `migrate(manager, key, to, permissions)` replaces `migratePrivate`,
354
+ // `orphan(manager, key)` moves a pool to `OrphanPolicyF`. No pool id moved.
355
+ export const EXPECTED_F_VERSION = 40n;
295
356
 
296
357
  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),
358
+ const { managerCAbi, managerFAbi } = await import("./generated.js");
359
+ const withC = hasC(c);
360
+ // independent reads: one round trip, not one per manager
361
+ const [gotC, gotF, wiring] = await Promise.all([
362
+ // the C stack is optional (F ships first); asserted the same way when deployed
363
+ withC ? c.public.readContract({ address: c.addresses.managerC!, abi: managerCAbi, functionName: "version" }) : Promise.resolve(null),
364
+ c.public.readContract({ address: c.addresses.managerF, abi: managerFAbi, functionName: "version" }),
305
365
  assertWiring(c).then(() => null, (e: unknown) => e),
306
366
  ]);
307
- if (got !== expected) {
367
+ if (gotC !== null && gotC !== expected) {
308
368
  throw new Error(
309
- `logswap: manager at ${c.addresses.cPoolManager} reports version ${got}, but this SDK was built ` +
369
+ `logswap: C manager at ${c.addresses.managerC} reports version ${gotC}, but this SDK was built ` +
310
370
  `against version ${expected}. Upgrade the SDK or point at the matching deployment.`,
311
371
  );
312
372
  }
313
- if (gotF !== null && gotF < EXPECTED_F_VERSION) {
373
+ if (gotF < EXPECTED_F_VERSION) {
314
374
  throw new Error(
315
- `logswap: F manager at ${c.addresses.fPoolManager} reports version ${gotF}, but this SDK needs ` +
375
+ `logswap: F manager at ${c.addresses.managerF} reports version ${gotF}, but this SDK needs ` +
316
376
  `at least F version ${EXPECTED_F_VERSION}. Upgrade the deployment or point at a newer one.`,
317
377
  );
318
378
  }
@@ -324,21 +384,23 @@ export async function assertVersion(c: LogswapClient, expected = EXPECTED_VERSIO
324
384
  * The versions say the managers are the right code; this says the rest of the addresses belong
325
385
  * to THEM. A stale router or lens from a previous deployment passes every version check and then
326
386
  * 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.
387
+ * reverts because the router's Permit2 is not the one the user approved. Each side is checked on its
388
+ * own: the router and the lens name their manager (`mgr()`), and the router its Permit2.
328
389
  */
329
390
  export async function assertWiring(c: LogswapClient): Promise<void> {
330
- const { routerAbi, lensAbi } = await import("./generated.js");
391
+ const { routerCAbi, routerFAbi, lensCAbi, lensFAbi } = await import("./generated.js");
331
392
  const rd = (address: Address, abi: readonly unknown[], functionName: string) =>
332
393
  c.public.readContract({ address, abi, functionName } as never) as Promise<Address>;
333
394
  const ZERO = "0x0000000000000000000000000000000000000000";
334
395
  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],
396
+ ["routerF.mgr()", rd(c.addresses.routerF, routerFAbi, "mgr"), c.addresses.managerF],
397
+ ["routerF.permit2()", rd(c.addresses.routerF, routerFAbi, "permit2"), c.addresses.permit2 ?? ZERO],
398
+ ["lensF.mgr()", rd(c.addresses.lensF, lensFAbi, "mgr"), c.addresses.managerF],
338
399
  ];
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]);
400
+ if (hasC(c)) {
401
+ want.push(["routerC.mgr()", rd(c.addresses.routerC!, routerCAbi, "mgr"), c.addresses.managerC!]);
402
+ want.push(["routerC.permit2()", rd(c.addresses.routerC!, routerCAbi, "permit2"), c.addresses.permit2 ?? ZERO]);
403
+ want.push(["lensC.mgr()", rd(c.addresses.lensC!, lensCAbi, "mgr"), c.addresses.managerC!]);
342
404
  }
343
405
  const got = await Promise.all(want.map((w) => w[1]));
344
406
  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
  }