@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/admin.ts CHANGED
@@ -1,22 +1,24 @@
1
1
  /**
2
- * admin — the protocol's writes: the C swap-fee tax (decisions 060), the policies a pool may be
3
- * born with (the registry's), the policies' own numbers (the quote list, the fee tiers, a pad's
4
- * schedule, a POL's rules), and the two roles' two-step handovers (decision 066): the LOG Authority
5
- * (the registry's `authority`) administers everything here; the LOG Treasury (`treasury` on each
6
- * manager) only receives, and is replaced by the authority's `proposeTreasury`. Plain writes to the managers, the
7
- * registry and the policies; no router.
2
+ * admin — the protocol's writes: the policies a pool may be born with and moved to (the registry's), the registry's
3
+ * creation modes and orphan move, the two roles' two-step handovers (decision 066): the LOG Authority (the registry's
4
+ * `logAuthority`) administers the registry and both managers; the LOG Treasury (`treasury` on each manager) only receives,
5
+ * and is replaced by the authority's `proposeTreasury`. Plain writes to the managers and the registry; no router.
6
+ *
7
+ * Since decision 098 the policies are immutable and the LOG's: a policy has no setter (its fee tiers, quotes, spacings, swap-fee tax, schedule and
8
+ * rates are constructor immutables), so there is no wrapper that writes one — a change is a new policy, approved ({@link registryApprove})
9
+ * and moved to ({@link fPoolMigrate}). What remains here for the policies is reading their numbers.
8
10
  *
9
11
  * The mint fee has no cut to set since C version 6 / F version 24 (decisions 058): the whole fee
10
12
  * is the protocol's on both managers. A harvest has no cut (056); a pad's protocol share of the income
11
- * is the policy's (`PadPolicy.setSchedule`), capped by the manager at `POT_CUT_MAX`.
13
+ * is the policy's `incomeTaxRate` (an immutable), capped by the manager at `INCOME_TAX_MAX`.
12
14
  */
13
15
 
14
16
  import type { Address, Hash, Hex } from "viem";
15
- import type { PoolKey } from "./keys.js";
16
- import type { LogswapClient } from "./client.js";
17
+ import { poolId as keyId, type PoolKey } from "./keys.js";
18
+ import { managerC, routerC, type LogswapClient, type Side } from "./client.js";
17
19
  import { getPool } from "./pools.js";
18
- import { cPoolManagerAbi, fPoolManagerAbi, padPolicyAbi, polPolicyAbi, policyRegistryAbi, publicPolicyAbi } from "./generated.js";
19
- import { bytes32ToText, fPolicyBaseAbi, fPoolKeyOfPool, fPoolKindOfPolicy, textToBytes32, type FPoolKey, type FPoolKind } from "./fpool.js";
20
+ import { managerCAbi, managerFAbi, padPolicyAbi, policyRegistryAbi, sponsorPolicyCAbi, sponsorPolicyFAbi } from "./generated.js";
21
+ import { bytes32ToText, fPoolKeyOfPool, fPoolKindOfPolicy, fPoolSwapModes, textToBytes32, type FPoolKey, type FPoolKind, type FPoolSwapMode } from "./fpool.js";
20
22
 
21
23
  function wallet(c: LogswapClient) {
22
24
  if (!c.wallet) throw new Error("a wallet client is required");
@@ -28,15 +30,18 @@ function write(c: LogswapClient, address: Address, abi: readonly unknown[], func
28
30
  }
29
31
 
30
32
  /**
31
- * The C swap-fee tax (decisions 060, 066): the protocol's share of every swap fee a C position is
32
- * paid (claims and the burn's auto-claim), WAD. `tax` is the level the gate (`PublicPolicy`) gives a
33
- * market born NOW; each market keeps the level of its birth for life — read it with
34
- * {@link cMarketSwapFeeTax} or `getPool(key).swapFeeTax`. `max` is the manager's bound.
33
+ * The C swap-fee tax (decisions 060, 066, 098): the protocol's share of every swap fee a C position is
34
+ * paid (claims and the burn's auto-claim), WAD. `tax` is the level a market born under `policy` (default: the deployment's
35
+ * `publicPolicyC`) is given — the policy's immutable `swapFeeTax`; each market keeps the level of its birth for
36
+ * life — read it with {@link cMarketSwapFeeTax} or `getPool(key).swapFeeTax`. A different level is a different policy.
37
+ * `max` is the manager's bound.
35
38
  */
36
- export async function cSwapFeeTax(c: LogswapClient): Promise<{ tax: bigint; max: bigint }> {
39
+ export async function cSwapFeeTax(c: LogswapClient, policy?: Address): Promise<{ tax: bigint; max: bigint }> {
40
+ const address = policy ?? c.addresses.publicPolicyC;
41
+ if (!address) throw new Error("logswap: this deployment carries no C sponsored policy (addresses.publicPolicyC); pass one");
37
42
  const [tax, max] = await Promise.all([
38
- c.public.readContract({ address: c.addresses.publicPolicy as Address, abi: publicPolicyAbi, functionName: "swapFeeTax" } as never) as Promise<bigint>,
39
- c.public.readContract({ address: c.addresses.cPoolManager, abi: cPoolManagerAbi, functionName: "SWAP_FEE_TAX_MAX" }),
43
+ c.public.readContract({ address, abi: sponsorPolicyCAbi, functionName: "swapFeeTax" } as never) as Promise<bigint>,
44
+ c.public.readContract({ address: managerC(c), abi: managerCAbi, functionName: "SWAP_FEE_TAX_MAX" }),
40
45
  ]);
41
46
  return { tax, max };
42
47
  }
@@ -46,14 +51,6 @@ export async function cMarketSwapFeeTax(c: LogswapClient, key: PoolKey): Promise
46
51
  return (await getPool(c, key)).swapFeeTax;
47
52
  }
48
53
 
49
- /**
50
- * `PublicPolicy.setSwapFeeTax`: the level a C market born after it is given (066), at most
51
- * `SWAP_FEE_TAX_MAX` (25%). The LOG Authority's. A live market keeps the level of its birth.
52
- */
53
- export async function setCSwapFeeTax(c: LogswapClient, taxWad: bigint): Promise<Hash> {
54
- return write(c, c.addresses.publicPolicy as Address, publicPolicyAbi, "setSwapFeeTax", [taxWad]);
55
- }
56
-
57
54
  // ─── the registry: the LOG Authority's (046, 066) ───────────────────────────
58
55
 
59
56
  const ZERO = "0x0000000000000000000000000000000000000000" as const;
@@ -65,7 +62,7 @@ const ZERO = "0x0000000000000000000000000000000000000000" as const;
65
62
  */
66
63
  export async function policyRegistryOf(c: LogswapClient): Promise<Address> {
67
64
  if (c.addresses.policyRegistry) return c.addresses.policyRegistry;
68
- return (await c.public.readContract({ address: c.addresses.fPoolManager as Address, abi: fPoolManagerAbi, functionName: "registry" } as never)) as Address;
65
+ return (await c.public.readContract({ address: c.addresses.managerF, abi: managerFAbi, functionName: "registry" } as never)) as Address;
69
66
  }
70
67
 
71
68
  /** Whether `policy` is approved now — listed and not yet sunset. True everywhere on a deployment with no registry. */
@@ -176,16 +173,36 @@ export async function setPolicyApproved(c: LogswapClient, policy: Address, appro
176
173
  return approved ? registryApprove(c, policy, await fPoolKindOfPolicy(c, policy)) : registryRevoke(c, policy);
177
174
  }
178
175
 
176
+ /**
177
+ * What the LOG installs for a pool in the same transaction as its move to a SPONSORED policy (decision 098): the old policy's gates, operator and whitelist never
178
+ * carry, so a gated pool never passes through an open block. Every field defaults to the open, ungated, operator-less pool. The target
179
+ * policy must offer gates (`gatesAvailable`) for anything but the default; a move onto a pad or a POL carries none (`PermissionsNotApplicable`).
180
+ */
181
+ export interface MigrationPermissions {
182
+ swapMode?: FPoolSwapMode;
183
+ /** The pool's operator under the new policy; zero (the default) appoints none. Required for `operator` mode. */
184
+ operator?: Address;
185
+ /** The mint gate: only the authority and the operator mint. */
186
+ mintGated?: boolean;
187
+ /** Accounts added to the swap whitelist. */
188
+ listed?: readonly Address[];
189
+ }
190
+
191
+ function permissionsArg(p: MigrationPermissions = {}) {
192
+ return { swapMode: fPoolSwapModes.indexOf(p.swapMode ?? "open"), operator: p.operator ?? ZERO, mintGated: p.mintGated ?? false, listed: p.listed ?? [] };
193
+ }
194
+
179
195
  /**
180
196
  * Move a pool to another approved policy of the same kind: the LOG Authority's alone, a forced move
181
197
  * (adoption at regeneration by the pool authority's consent is specified, not built — logswap-docs
182
- * `specs/governance/policy-adoption.md`),
183
- * orchestrated on the registry — `migrate(manager, key, to)` since F version 20 (it took the
184
- * pool's id before). The registry checks the key against the manager (`NoPool`), checks the
185
- * manager is its own (`WrongManager`), and compares the two policies' tags recorded at approval
186
- * ({@link registryKindOf}). The new policy is brought the creator (the key's), the authority and
187
- * the name (read off the old policy defensively, the key's creator standing in when it cannot
188
- * answer); the operator and the lists void; no swap lands in the block.
198
+ * `specs/governance/policy-adoption.md`), orchestrated on the registry — `migrate(manager, key, to, permissions)`
199
+ * (decision 098; `migratePrivate` is gone). The registry checks the key against the manager (`NoPool`), the manager is its
200
+ * own (`WrongManager`), the two policies' tags recorded at approval ({@link registryKindOf}; every sponsored policy shares
201
+ * `"sponsor"`), the creation mode against the pool's authority (`SponsorOnly`: a sponsor's pool moves only under a policy of
202
+ * the same sponsor, or one open to anyone) and that the pool never held the target (`AlreadyHeld`). The new policy is
203
+ * brought the authority and the name (read off the old policy defensively, the key's creator standing in when it cannot
204
+ * answer); `permissions` installs the pool's swap mode, operator, mint gate and whitelist under it in the same transaction ({@link MigrationPermissions});
205
+ * the key, its fees and its id are untouched; no swap lands in the block. F only until C ships a `setPolicy`.
189
206
  *
190
207
  * Pass the pool's `key` when in hand. Given only `poolId`, the key is rebuilt from the pool's
191
208
  * `PoolCreated` log ({@link fPoolKeyOfPool}) with `salt` (zero by default) and checked against
@@ -193,10 +210,38 @@ export async function setPolicyApproved(c: LogswapClient, policy: Address, appro
193
210
  */
194
211
  export async function fPoolMigrate(
195
212
  c: LogswapClient,
196
- a: { to: Address } & ({ key: FPoolKey } | { poolId: `0x${string}`; salt?: `0x${string}`; fromBlock?: bigint }),
213
+ a: { to: Address; permissions?: MigrationPermissions } & ({ key: FPoolKey } | { poolId: `0x${string}`; salt?: `0x${string}`; fromBlock?: bigint }),
197
214
  ): Promise<Hash> {
198
215
  const key = "key" in a ? a.key : await fPoolKeyOfPool(c, a.poolId, { salt: a.salt, fromBlock: a.fromBlock });
199
- return registryWrite(c, "migrate", [c.addresses.fPoolManager as Address, key, a.to]);
216
+ return registryWrite(c, "migrate", [c.addresses.managerF, key, a.to, permissionsArg(a.permissions)]);
217
+ }
218
+
219
+ /**
220
+ * `PolicyRegistry.orphan(manager, key)` (decision 098): move a pool whose sponsor went rogue or lost its key to the manager's orphan policy
221
+ * ({@link registryOrphanPolicyOf}) — no owner and no setting; swap and mint open; `deployLiquidity`, `harvest`, `close` and the generation
222
+ * step refused; income tax zero. The LOG Authority's alone, needing no consent, and FINAL: a pool never leaves the orphan policy (`Orphaned`).
223
+ * `key` as in {@link fPoolMigrate}.
224
+ */
225
+ export async function fPoolOrphan(
226
+ c: LogswapClient,
227
+ a: { key: FPoolKey } | { poolId: `0x${string}`; salt?: `0x${string}`; fromBlock?: bigint },
228
+ ): Promise<Hash> {
229
+ const key = "key" in a ? a.key : await fPoolKeyOfPool(c, a.poolId, { salt: a.salt, fromBlock: a.fromBlock });
230
+ return registryWrite(c, "orphan", [c.addresses.managerF, key]);
231
+ }
232
+
233
+ /** The orphan policy registered for a manager (`orphanPolicy(manager)`): F's by default; zero when none is registered or the deployment has no registry. */
234
+ export async function registryOrphanPolicyOf(c: LogswapClient, side: Side = "F"): Promise<Address> {
235
+ const registry = await policyRegistryOf(c);
236
+ if (registry === ZERO) return ZERO;
237
+ const mgr = side === "C" ? managerC(c) : c.addresses.managerF;
238
+ return (await c.public.readContract({ address: registry, abi: policyRegistryAbi, functionName: "orphanPolicy", args: [mgr] } as never)) as Address;
239
+ }
240
+
241
+ /** `PolicyRegistry.setOrphanPolicy(manager, policy)`: register the approved policy tagged `"orphan"` that answers `manager` (F's by default). The LOG Authority's. */
242
+ export async function registrySetOrphanPolicy(c: LogswapClient, policy: Address, side: Side = "F"): Promise<Hash> {
243
+ const mgr = side === "C" ? managerC(c) : c.addresses.managerF;
244
+ return registryWrite(c, "setOrphanPolicy", [mgr, policy]);
200
245
  }
201
246
 
202
247
  /**
@@ -211,28 +256,10 @@ export async function registryKindOf(c: LogswapClient, policy: Address): Promise
211
256
  return bytes32ToText(word) as FPoolKind | "";
212
257
  }
213
258
 
214
- // ─── the policies' numbers (the LOG Authority's; each bounded where it reaches the manager) ─────
215
-
216
- /**
217
- * `PadPolicy.setSchedule` (decisions 056, 067, 070, 073): the rung's growth and the RANGE inside which a creator chooses their cut of the income
218
- * at creation (its top ≤ the F manager's `PAYEE_CUT_MAX`). The rest of the income deepens the bid — nothing is bought or
219
- * burnt since F version 28, and the protocol takes no cut of the income since F version 33 (its revenue is the income tax,
220
- * {@link padSetIncomeTaxRate}). A change to the range applies to pads born after it; the growth moves every pad at its
221
- * next rung. The rung is the pool's generation. `T(0)` is per quote since decision 070: {@link padSetThresholdBase}.
222
- */
223
- export async function padSetSchedule(c: LogswapClient, policy: Address, s: PadSchedule): Promise<Hash> {
224
- if ("thresholdBase" in s) throw new Error("logswap: T(0) is per quote since decision 070 — padSetThresholdBase(c, policy, quote, base)");
225
- return write(c, policy, padPolicyAbi, "setSchedule", [s.thresholdGrowth, s.creatorShareMin, s.creatorShareMax]);
226
- }
227
-
228
- /**
229
- * `PadPolicy.setThresholdBase(quote, base)` (decision 070): `T(0)` for pads quoted in `quote`, in that quote's units. A pad is
230
- * born (or moved in) only on a quote that has one (`NoThreshold`). It moves every pad in that quote at its next rung. The LOG
231
- * Authority's.
232
- */
233
- export async function padSetThresholdBase(c: LogswapClient, policy: Address, quote: Address, base: bigint): Promise<Hash> {
234
- return write(c, policy, padPolicyAbi, "setThresholdBase", [quote, base]);
235
- }
259
+ // ─── the policies' numbers: immutable since decision 098, so read-only here ─────
260
+ // A pad's schedule, its income tax rate, a POL's reserve ratio and a sponsored policy's tiers, quotes, spacings and tax are
261
+ // constructor immutables of the policy the LOG deploys; the setters (`setSchedule`, `setThresholdBase`, `setIncomeTaxRate`,
262
+ // `setMinQuoteRatio`, `setQuoteListed`, `setFeeListed`, `setSwapFeeTax`, …) and their wrappers are gone.
236
263
 
237
264
  /** A pad policy's `T(0)` in one quote (decision 070): `set` false means no pad can be born on that quote. */
238
265
  export interface PadThresholdBase {
@@ -278,83 +305,58 @@ export async function padScheduleOf(c: LogswapClient, policy: Address): Promise<
278
305
  return { thresholdGrowth, creatorShareMin, creatorShareMax };
279
306
  }
280
307
 
281
- /** `PolPolicy.setMinQuoteRatio` (decision 073): the reserve a harvest must leave in the bid (`may(Harvest)` refuses less) and a relaunch's seed must bring, a multiple of the pool's L in WAD (at most 100e18). The policy sponsor's. */
282
- export async function polSetMinQuoteRatio(c: LogswapClient, policy: Address, ratio: bigint): Promise<Hash> {
283
- return write(c, policy, polPolicyAbi, "setMinQuoteRatio", [ratio]);
284
- }
285
-
286
- /** `PadPolicy.setIncomeTaxRate` (decision 073): the share of its new income dividend the dead shares pay LOG Treasury as income tax, WAD, at most 50%. The policy sponsor's. */
287
- export async function padSetIncomeTaxRate(c: LogswapClient, policy: Address, rate: bigint): Promise<Hash> {
288
- return write(c, policy, padPolicyAbi, "setIncomeTaxRate", [rate]);
289
- }
290
-
291
- /** `PolPolicy.setIncomeTaxRate` (decision 073): the share of its new income dividend the pool's authority pays LOG Treasury, WAD, at most 50%. Paid on the authority's own shares only: an authority that holds through another address pays nothing. The policy sponsor's. */
292
- export async function polSetIncomeTaxRate(c: LogswapClient, policy: Address, rate: bigint): Promise<Hash> {
293
- return write(c, policy, polPolicyAbi, "setIncomeTaxRate", [rate]);
294
- }
295
-
296
- /** `setQuoteListed` on any protocol policy: a quote a pool of that kind may be born against while it curates quotes. The LOG Authority's. */
297
- export async function policySetQuoteListed(c: LogswapClient, policy: Address, quote: Address, listed: boolean): Promise<Hash> {
298
- return write(c, policy, fPolicyBaseAbi, "setQuoteListed", [quote, listed]);
299
- }
300
-
301
- /** `setQuoteCurated` on any protocol policy: on, a birth against an unlisted quote is refused. The LOG Authority's. */
302
- export async function policySetQuoteCurated(c: LogswapClient, policy: Address, curated: boolean): Promise<Hash> {
303
- return write(c, policy, fPolicyBaseAbi, "setQuoteCurated", [curated]);
304
- }
305
-
306
- /** Whether `quote` passes `policy`'s birth check now: listed, or the policy does not curate quotes. */
308
+ /** Whether `quote` passes a sponsored `policy`'s birth check now: it curates quotes (`quoteCurated`, a non-empty list set in the constructor) and lists it, or it does not curate. */
307
309
  export async function policyQuoteAllowed(c: LogswapClient, policy: Address, quote: Address): Promise<{ curated: boolean; listed: boolean; allowed: boolean }> {
308
310
  const [curated, listed] = await Promise.all([
309
- c.public.readContract({ address: policy, abi: fPolicyBaseAbi, functionName: "quoteCurated" } as never) as Promise<boolean>,
310
- c.public.readContract({ address: policy, abi: fPolicyBaseAbi, functionName: "quoteListed", args: [quote] } as never) as Promise<boolean>,
311
+ c.public.readContract({ address: policy, abi: sponsorPolicyFAbi, functionName: "quoteCurated" } as never) as Promise<boolean>,
312
+ c.public.readContract({ address: policy, abi: sponsorPolicyFAbi, functionName: "quoteListed", args: [quote] } as never) as Promise<boolean>,
311
313
  ]);
312
314
  return { curated, listed, allowed: !curated || listed };
313
315
  }
314
316
 
315
317
  /**
316
- * `setFeeListed` on any protocol policy (decisions 059): a swap-fee tier a pool of that kind may be
317
- * born with while the policy curates fees. Within the family's domain (`FEE_MIN` ≤ fee ≤ `FEE_MAX`).
318
- * The LOG Authority's.
318
+ * Whether `fee` passes a sponsored `policy`'s birth check now: on its swap tiers (`swapFeeListed`) or, with `kind: "mint"`, its mint tiers
319
+ * (`mintFeeListed`). `curated` is true when the policy lists tiers (a non-zero mask); with none, any fee in the manager's domain is allowed.
319
320
  */
320
- export async function policySetFeeListed(c: LogswapClient, policy: Address, fee: bigint, listed: boolean): Promise<Hash> {
321
- return write(c, policy, fPolicyBaseAbi, "setFeeListed", [fee, listed]);
322
- }
323
-
324
- /** `setFeeCurated` on any protocol policy: on, a birth with an unlisted swap fee is refused (`FeeNotListed`). The LOG Authority's. */
325
- export async function policySetFeeCurated(c: LogswapClient, policy: Address, curated: boolean): Promise<Hash> {
326
- return write(c, policy, fPolicyBaseAbi, "setFeeCurated", [curated]);
327
- }
328
-
329
- /** Whether `fee` passes `policy`'s birth check now: listed, or the policy does not curate fees (the desk's never does). */
330
- export async function policyFeeAllowed(c: LogswapClient, policy: Address, fee: bigint): Promise<{ curated: boolean; listed: boolean; allowed: boolean }> {
331
- const [curated, listed] = await Promise.all([
332
- c.public.readContract({ address: policy, abi: fPolicyBaseAbi, functionName: "feeCurated" } as never) as Promise<boolean>,
333
- c.public.readContract({ address: policy, abi: fPolicyBaseAbi, functionName: "feeListed", args: [fee] } as never) as Promise<boolean>,
321
+ export async function policyFeeAllowed(
322
+ c: LogswapClient,
323
+ policy: Address,
324
+ fee: bigint,
325
+ kind: "swap" | "mint" = "swap",
326
+ ): Promise<{ curated: boolean; listed: boolean; allowed: boolean }> {
327
+ const [tiers, listed] = await Promise.all([
328
+ c.public.readContract({ address: policy, abi: sponsorPolicyFAbi, functionName: kind === "swap" ? "swapTiers" : "mintTiers" } as never) as Promise<bigint>,
329
+ c.public.readContract({ address: policy, abi: sponsorPolicyFAbi, functionName: kind === "swap" ? "swapFeeListed" : "mintFeeListed", args: [fee] } as never) as Promise<boolean>,
334
330
  ]);
335
- return { curated, listed, allowed: !curated || listed };
331
+ return { curated: tiers !== 0n, listed, allowed: listed };
336
332
  }
337
333
 
338
- /** `PolicyRegistry.CreationMode` (decision 073): who may create under a policy. Open = 0, Restricted = 1 (the initializer list), SponsorOnly = 2 (bound to a sponsor, permanent). */
339
- export type CreationMode = "open" | "restricted" | "sponsorOnly";
340
- const CREATION_MODES: readonly CreationMode[] = ["open", "restricted", "sponsorOnly"];
334
+ /** `PolicyRegistry.CreationMode` (decisions 073, 098): who may create under a policy. Open = 0, SponsorOnly = 1 (the policy's own immutable sponsor, who must also be the key's creator). `Restricted` and the initializer list are gone. */
335
+ export type CreationMode = "open" | "sponsorOnly";
336
+ const CREATION_MODES: readonly CreationMode[] = ["open", "sponsorOnly"];
341
337
 
342
- /** `PolicyRegistry.setCreationMode(policy, mode)` (the LOG Authority): replaces the per-policy creator lists (064). A sponsor-bound policy cannot leave `sponsorOnly`. */
338
+ /** `PolicyRegistry.setCreationMode(policy, mode)` (the LOG Authority). A sponsored policy is approved `sponsorOnly`. */
343
339
  export async function registrySetCreationMode(c: LogswapClient, policy: Address, mode: CreationMode): Promise<Hash> {
344
340
  return registryWrite(c, "setCreationMode", [policy, CREATION_MODES.indexOf(mode)]);
345
341
  }
346
342
 
347
- /** `PolicyRegistry.setInitializerListed(policy, who, allowed)` (the LOG Authority): who may create under a `restricted` policy, authenticated as the caller or a trusted forwarder's user. */
348
- export async function registrySetInitializerListed(c: LogswapClient, policy: Address, who: Address, allowed: boolean): Promise<Hash> {
349
- return registryWrite(c, "setInitializerListed", [policy, who, allowed]);
350
- }
351
-
352
343
  /** `PolicyRegistry.setForwarderTrusted` (the LOG Authority): a router whose `user()` names the creator. Moved off the public policy in F version 33. */
353
344
  export async function registrySetForwarderTrusted(c: LogswapClient, forwarder: Address, trusted: boolean): Promise<Hash> {
354
345
  return registryWrite(c, "setForwarderTrusted", [forwarder, trusted]);
355
346
  }
356
347
 
357
348
  /** `PolicyRegistry.creationMode(policy)`. */
349
+ /**
350
+ * `PolicyRegistry.userOf(caller)` (C 15, decision 097): the account a caller acts for — the user a trusted forwarder
351
+ * (a router) names, else the caller itself. The account the managers authenticate as a market's creator and as the
352
+ * first minter; what a create form compares to the key's `creator`.
353
+ */
354
+ export async function registryUserOf(c: LogswapClient, caller: Address): Promise<Address> {
355
+ const registry = await policyRegistryOf(c);
356
+ if (registry === ZERO) return caller;
357
+ return (await c.public.readContract({ address: registry, abi: policyRegistryAbi, functionName: "userOf", args: [caller] } as never)) as Address;
358
+ }
359
+
358
360
  export async function registryCreationMode(c: LogswapClient, policy: Address): Promise<CreationMode> {
359
361
  const registry = await policyRegistryOf(c);
360
362
  if (registry === ZERO) return "open";
@@ -362,108 +364,103 @@ export async function registryCreationMode(c: LogswapClient, policy: Address): P
362
364
  return CREATION_MODES[Number(m)] ?? "open";
363
365
  }
364
366
 
365
- /** `PublicPolicy.setPairListed` (064): a C pair a market may be born on while pairs are curated. Directional (base, quote). */
366
- export async function gateSetPairListed(c: LogswapClient, policy: Address, base: Address, quote: Address, listed: boolean): Promise<Hash> {
367
- return write(c, policy, publicPolicyAbi, "setPairListed", [base, quote, listed]);
368
- }
369
-
370
- /** `PublicPolicy.setPairCurated` (064). */
371
- export async function gateSetPairCurated(c: LogswapClient, policy: Address, curated: boolean): Promise<Hash> {
372
- return write(c, policy, publicPolicyAbi, "setPairCurated", [curated]);
373
- }
374
-
375
- /** `PublicPolicy.setSpacingListed` (064): a C tick spacing, WAD (10 bp = 1e15, 100 bp = 1e16). Always consulted. */
376
- export async function gateSetSpacingListed(c: LogswapClient, policy: Address, tickSpacing: bigint, listed: boolean): Promise<Hash> {
377
- return write(c, policy, publicPolicyAbi, "setSpacingListed", [tickSpacing, listed]);
378
- }
379
-
380
- /**
381
- * @deprecated C version 8 fixes the gate at construction (066): there is no `setGate`. Open or close
382
- * C through the gate's lists (`registrySetCreationMode`, `gateSetPairCurated`, `gateSetSpacingListed`, …).
383
- */
384
- export async function setCGate(_c: LogswapClient, _gate: Address): Promise<Hash> {
385
- throw new Error("logswap: the C gate is fixed at construction since C version 8 (decision 066); change its lists instead");
367
+ /** Whether `policy` (a `SponsorPolicyC`) admits C tick spacing `tickSpacing`: it curates spacings (`spacingCurated`) and lists it, or it does not curate. */
368
+ export async function policySpacingAllowed(c: LogswapClient, policy: Address, tickSpacing: bigint): Promise<{ curated: boolean; listed: boolean; allowed: boolean }> {
369
+ const [curated, listed] = await Promise.all([
370
+ c.public.readContract({ address: policy, abi: sponsorPolicyCAbi, functionName: "spacingCurated" } as never) as Promise<boolean>,
371
+ c.public.readContract({ address: policy, abi: sponsorPolicyCAbi, functionName: "spacingListed", args: [tickSpacing] } as never) as Promise<boolean>,
372
+ ]);
373
+ return { curated, listed, allowed: !curated || listed };
386
374
  }
387
375
 
388
376
  export interface CGateRules {
389
- /** The registry admits `creator` to create under `key.policy` (creation mode, initializer list, sponsor binding; decision 073). */
377
+ /**
378
+ * The registry admits `creator` to create under `key.policy` (creation mode and sponsor binding; decisions 073, 097, 098):
379
+ * `admit(policy, creator, creator)` resolves to `creator`. Both managers then require the initializer to BE the key's creator (`NotCreator`).
380
+ */
390
381
  creatorOk: boolean;
382
+ /** The quote is on the policy's list, or the policy lists none (`quoteCurated`). */
391
383
  quoteOk: boolean;
392
- pairOk: boolean;
384
+ /** The swap fee is on the policy's swap tiers, or it lists none. */
393
385
  feeOk: boolean;
386
+ /** The mint fee is on the policy's mint tiers, or it lists none. */
387
+ mintFeeOk: boolean;
388
+ /** The tick spacing is on the policy's list, or it lists none (`spacingCurated`). */
394
389
  spacingOk: boolean;
395
- /** A market on (base, quote, fee) already exists, whatever its spacing: the policy refuses another (064 (b)). */
390
+ /** A canonical policy (the LOG's open instance) needs `salt` zero (`NotCanonical`); a desk's may run several markets of one shape. */
391
+ saltOk: boolean;
392
+ /** This exact market (the key's id) is already initialized: another is a different key. */
396
393
  exists: boolean;
397
394
  /** Whether `router` is a trusted forwarder on the registry — `createMarket` through it is then checked against `creator`. */
398
395
  routerTrusted: boolean;
399
- /** Every check passes: the policy would admit this market from this creator (the mint fee is a key field, checked by the manager). */
396
+ /** Every check passes: the policy would admit this market from this creator (the manager checks the fee domain, `BadParam`). */
400
397
  admitted: boolean;
401
398
  }
402
399
 
403
400
  /**
404
- * The public policy's C checks for one candidate market and creator, in one round of reads — what
405
- * the create form shows before a wallet is asked (064, 073). The policy is `key.policy`; the registry
406
- * is asked `admit(policy, caller, 0)`, with the caller being the router when it is a trusted forwarder
407
- * (it then names `creator` itself) and `creator` otherwise.
401
+ * A sponsored C policy's checks for one candidate market and creator, in one round of reads — what the create form shows before a wallet
402
+ * is asked (064, 073, 097, 098). The policy is `key.policy` (a `SponsorPolicyC`); the registry is asked `admit(policy, creator, creator)`: the
403
+ * account that starts a market is its creator, so the key's `creator` is the connected account (a router call resolves to it through the
404
+ * trusted forwarder's `user()`). The policy's pair list is gone (098).
408
405
  */
409
- export async function cGateRules(c: LogswapClient, a: { key: PoolKey; creator: Address; router?: Address; gate?: Address }): Promise<CGateRules> {
406
+ export async function cGateRules(c: LogswapClient, a: { key: PoolKey; creator?: Address; router?: Address; gate?: Address }): Promise<CGateRules> {
410
407
  const g = a.gate ?? (a.key.policy as Address);
411
408
  const rd = <T>(functionName: string, args: readonly unknown[] = []) =>
412
- c.public.readContract({ address: g, abi: publicPolicyAbi, functionName, args } as never) as Promise<T>;
409
+ c.public.readContract({ address: g, abi: sponsorPolicyCAbi, functionName, args } as never) as Promise<T>;
413
410
  const { key } = a;
411
+ const creator = a.creator ?? key.creator;
414
412
  const registry = await policyRegistryOf(c);
415
- const router = a.router ?? c.addresses.router;
413
+ const router = a.router ?? routerC(c);
416
414
  const registryRd = <T>(functionName: string, args: readonly unknown[]) =>
417
415
  c.public.readContract({ address: registry, abi: policyRegistryAbi, functionName, args } as never) as Promise<T>;
418
- const [quoteCurated, quoteListed, pairCurated, pairListed, feeCurated, feeListed, spacingListed, market, routerTrusted, creatorOk] =
416
+ const [quoteCurated, quoteListed, feeListed, mintFeeListed, spacingCurated, spacingListed, canonical, state, routerTrusted, creatorOk] =
419
417
  await Promise.all([
420
418
  rd<boolean>("quoteCurated"),
421
419
  rd<boolean>("quoteListed", [key.quote]),
422
- rd<boolean>("pairCurated"),
423
- rd<boolean>("pairListed", [key.base, key.quote]),
424
- rd<boolean>("feeCurated"),
425
- rd<boolean>("feeListed", [key.swapFee]),
420
+ rd<boolean>("swapFeeListed", [key.swapFee]),
421
+ rd<boolean>("mintFeeListed", [key.mintFee]),
422
+ rd<boolean>("spacingCurated"),
426
423
  rd<boolean>("spacingListed", [key.tickSpacing]),
427
- rd<Hex>("cMarketOf", [key.base, key.quote, key.swapFee]),
424
+ rd<boolean>("canonical"),
425
+ getPool(c, key),
428
426
  registry === ZERO ? Promise.resolve(false) : registryRd<boolean>("forwarderTrusted", [router]),
429
427
  registry === ZERO
430
428
  ? Promise.resolve(true)
431
- : registryRd<Address>("admit", [g, a.creator, ZERO]).then(() => true, () => false),
429
+ : registryRd<Address>("admit", [g, creator, creator]).then((who) => who.toLowerCase() === creator.toLowerCase(), () => false),
432
430
  ]);
433
431
  const r = {
434
432
  creatorOk,
435
433
  quoteOk: !quoteCurated || quoteListed,
436
- pairOk: !pairCurated || pairListed,
437
- feeOk: !feeCurated || feeListed,
438
- spacingOk: spacingListed,
439
- exists: BigInt(market) !== 0n,
434
+ feeOk: feeListed,
435
+ mintFeeOk: mintFeeListed,
436
+ spacingOk: !spacingCurated || spacingListed,
437
+ saltOk: !canonical || key.salt === "0x0000000000000000000000000000000000000000000000000000000000000000",
438
+ exists: state.initialized,
440
439
  routerTrusted,
441
440
  };
442
- return { ...r, admitted: r.creatorOk && r.quoteOk && r.pairOk && r.feeOk && r.spacingOk && !r.exists };
441
+ return { ...r, admitted: r.creatorOk && r.quoteOk && r.feeOk && r.mintFeeOk && r.spacingOk && r.saltOk && !r.exists };
443
442
  }
444
443
 
445
444
  /**
446
- * Every refusal a birth can meet at the gate or a policy (064, 065), for `decodeErrorResult` on a
447
- * failed simulation: the public policy's errors plus the pad's `PadExists` (one pad per base) and `NoThreshold` (no `T(0)`
445
+ * Every refusal a birth can meet at a sponsored policy or the registry (064, 065, 098), for `decodeErrorResult` on a
446
+ * failed simulation: the sponsored C policy's errors (a superset of F's) plus the pad's `PadExists` (one pad per base) and `NoThreshold` (no `T(0)`
448
447
  * in the pad's quote, decision 070).
449
448
  */
450
449
  export const gateErrorAbi = [
451
- ...publicPolicyAbi.filter((x) => x.type === "error"),
452
- // creation admission moved to the registry in F 33 / C 10 (073): a refusal there surfaces through the manager's birth
453
- ...policyRegistryAbi.filter((x) => x.type === "error" && ["SponsorOnly", "InitializerNotListed", "InvalidForwardedUser", "NotListed"].includes(x.name)),
450
+ ...sponsorPolicyCAbi.filter((x) => x.type === "error"),
451
+ // creation admission is the registry's (F 33 / C 10, 073): a refusal there surfaces through the manager's birth
452
+ ...policyRegistryAbi.filter((x) => x.type === "error" && ["SponsorOnly", "InvalidForwardedUser", "NotListed"].includes(x.name)),
454
453
  ...padPolicyAbi.filter((x) => x.type === "error" && (x.name === "PadExists" || x.name === "NoThreshold")),
455
454
  ] as const;
456
455
 
457
456
  // ─── the LOG Treasury (066): receives, administers nothing ───────────────────
458
457
 
459
- function manager(c: LogswapClient, side: "C" | "F"): { address: Address; abi: readonly unknown[] } {
460
- return side === "C"
461
- ? { address: c.addresses.cPoolManager, abi: cPoolManagerAbi }
462
- : { address: c.addresses.fPoolManager as Address, abi: fPoolManagerAbi };
458
+ function manager(c: LogswapClient, side: Side): { address: Address; abi: readonly unknown[] } {
459
+ return side === "C" ? { address: managerC(c), abi: managerCAbi } : { address: c.addresses.managerF, abi: managerFAbi };
463
460
  }
464
461
 
465
462
  /** A manager's treasury — where its protocol revenue goes — and the proposed next one. */
466
- export async function logTreasury(c: LogswapClient, side: "C" | "F"): Promise<{ treasury: Address; pending: Address }> {
463
+ export async function logTreasury(c: LogswapClient, side: Side): Promise<{ treasury: Address; pending: Address }> {
467
464
  const m = manager(c, side);
468
465
  const [treasury, pending] = await Promise.all([
469
466
  c.public.readContract({ ...m, functionName: "treasury" } as never) as Promise<Address>,
@@ -476,12 +473,12 @@ export async function logTreasury(c: LogswapClient, side: "C" | "F"): Promise<{
476
473
  * Propose a manager's next treasury: the LOG Authority's call, never the treasury's own, so a
477
474
  * treasury that can no longer act is replaced without it. Nothing the old treasury holds moves.
478
475
  */
479
- export async function proposeTreasury(c: LogswapClient, side: "C" | "F", next: Address): Promise<Hash> {
476
+ export async function proposeTreasury(c: LogswapClient, side: Side, next: Address): Promise<Hash> {
480
477
  const m = manager(c, side);
481
478
  return write(c, m.address, m.abi, "proposeTreasury", [next]);
482
479
  }
483
480
  /** The proposed treasury takes the role, sending from its own address. */
484
- export async function acceptTreasury(c: LogswapClient, side: "C" | "F"): Promise<Hash> {
481
+ export async function acceptTreasury(c: LogswapClient, side: Side): Promise<Hash> {
485
482
  const m = manager(c, side);
486
483
  return write(c, m.address, m.abi, "acceptTreasury", []);
487
484
  }
@@ -491,9 +488,9 @@ export const proposeCollector = proposeTreasury;
491
488
  export const acceptCollector = acceptTreasury;
492
489
 
493
490
  /**
494
- * `CPoolManager.collectProtocolFees(key)`: pay one market's `protocolOwed` (mint fees and swap-fee
491
+ * `ManagerC.collectProtocolFees(poolId)`: pay one market's `protocolOwed` (mint fees and swap-fee
495
492
  * tax) to the treasury. Anyone may send it (066); the destination is fixed.
496
493
  */
497
494
  export async function collectCProtocolFees(c: LogswapClient, key: PoolKey): Promise<Hash> {
498
- return write(c, c.addresses.cPoolManager, cPoolManagerAbi, "collectProtocolFees", [key]);
495
+ return write(c, managerC(c), managerCAbi, "collectProtocolFees", [keyId(key)]);
499
496
  }
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 sponsored instance on F (`SponsorPolicyF`, sponsor = the LOG, canonical, no gate available; decision 098). */
158
164
  publicPolicy: Address;
165
+ /** The LOG's gated sponsored instance on F (`SponsorPolicyF`: gates available, born gated). The artifact key predates 098 and is kept. */
159
166
  privatePolicy: Address;
160
167
  polPolicy: Address;
161
168
  padPolicy: Address;
162
- router: Address;
163
- lens: Address;
169
+ /** The LOG's open sponsored instance on C (`SponsorPolicyC`). Absent while the chain has no C stack. */
170
+ publicPolicyC?: Address;
171
+ /** F's orphan policy (`OrphanPolicyF`, decision 098): where `PolicyRegistry.orphan` moves a pool. Absent on an artifact that predates it. */
172
+ orphanPolicy?: 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, no orphan policy deployed): zero is absent. */
205
+ const OPTIONAL_POLICIES = ["publicPolicyC", "orphanPolicy"] 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,28 @@ 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 } : {}),
274
+ ...(d.orphanPolicy ? { orphanPolicy: d.orphanPolicy } : {}),
255
275
  policyRegistry: d.policyRegistry,
256
276
  permit2: d.permit2,
257
277
  ...(d.tokenFactory ? { tokenFactory: d.tokenFactory } : {}),