@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/fpool.ts CHANGED
@@ -1,8 +1,8 @@
1
1
  /**
2
- * fpool.ts — the `FPoolManager` surface: n bases, one quote, one shared floor.
2
+ * fpool.ts — the `ManagerF` surface: n bases, one quote, one shared floor.
3
3
  *
4
- * The other primitive. `CPoolManager` gives every position its own floor on a tick ladder;
5
- * `FPoolManager` gives every share the SAME floor and deletes the ladder, the accumulators and the
4
+ * The other primitive. `ManagerC` gives every position its own floor on a tick ladder;
5
+ * `ManagerF` gives every share the SAME floor and deletes the ladder, the accumulators and the
6
6
  * per-position accounting with it. Reading the two side by side is the fastest way to understand
7
7
  * either.
8
8
  *
@@ -19,35 +19,39 @@
19
19
  * which shape a given pool is, because a UI has to decide what to render.
20
20
  *
21
21
  * **The roles are the policy's, not the manager's** (F version 15). The manager holds no
22
- * authority, operator, gate or list: it asks the pool's policy `may(who, action)` and acts on the
23
- * answer. So `getFPool` carries the policy and what it declared, {@link getFPoolRoles} reads the
24
- * roles FROM the policy, and every role write — the handover, the operator, the gates, the list —
25
- * is a write to the policy ({@link fPoolProposeAuthority}, {@link fPoolSetGates}, …).
22
+ * authority, gate or list: it asks the pool's policy `may(who, action)` and acts on the answer (the
23
+ * one thing it caches is the operator the gates admit with no call, F 40). So `getFPool` carries the
24
+ * policy and what it declared (`flags`), {@link getFPoolRoles} reads the roles FROM the policy, and
25
+ * every setting — the operator, the gate modes, the whitelist — is a write to the policy
26
+ * ({@link fPoolAppointOperator}, {@link fPoolSetSwapMode}, {@link fPoolSetListed}, …). Since decision 098
27
+ * the authority is `key.creator` for life (no handover) and a policy has no setter of its own: its numbers
28
+ * are constructor immutables, and a change is a new policy the LOG moves a pool to ({@link fPoolMigrate}).
26
29
  *
27
- * **Zaps live on the ROUTER, not here.** Permit2 is AllowanceTransfer mode, whose standing
28
- * allowance is keyed by spender, so a second router would cost the user an allowance per token
29
- * twice, forever. One router is one spender — see `fPoolZapIn`/`fPoolZapOut` below, which target
30
- * `addresses.router`.
30
+ * **Zaps live on the ROUTER, not here.** `RouterF` is F's own router and its own Permit2 spender (decision 096: one
31
+ * router per manager; a second spender is a second signature, not a second on-chain approval). See
32
+ * `fPoolZapIn`/`fPoolZapOut` below, which target `addresses.routerF`; a wallet's Permit2 allowance for it is
33
+ * `onboardToken(c, "F", token, need)`.
31
34
  */
32
35
 
33
36
  import { decodeAbiParameters, encodeAbiParameters, encodeFunctionData, erc20Abi, keccak256, toFunctionSelector, type Address, type Hash, type Hex } from "viem";
34
- import { fPoolManagerAbi, lensAbi, routerAbi, padPolicyAbi, polPolicyAbi, policyRegistryAbi, privatePolicyAbi, publicPolicyAbi } from "./generated.js";
37
+ import { managerFAbi, lensFAbi, routerFAbi, orphanPolicyFAbi, padPolicyAbi, polPolicyAbi, policyRegistryAbi, sponsorPolicyFAbi } from "./generated.js";
35
38
 
36
39
  /**
37
- * One contract, one ABI (F version 12): `harvest`, `claim`, `retire`, `regenerate`,
38
- * `setLegs`, the names, the fee parameters are `FPoolManager`'s own code. The roles left it for
39
- * the policies in F version 15: {@link fPolicyBaseAbi} is what every policy shares,
40
- * {@link privatePolicyAbi} the desk's, {@link padPolicyAbi} / {@link polPolicyAbi} / {@link publicPolicyAbi}
41
- * the kinds'.
40
+ * One contract, one ABI (F version 12): `harvest`, `claim`, `regenerate`, `close`, `deployLiquidity`,
41
+ * the fee parameters are `ManagerF`'s own code. The roles left it for the policies in F version 15:
42
+ * {@link fPolicyBaseAbi} is what the policies share, {@link sponsorPolicyFAbi} the sponsored one (kind
43
+ * `"sponsor"`, decision 098), {@link padPolicyAbi} / {@link polPolicyAbi} the other kinds', and
44
+ * {@link orphanPolicyFAbi} the neutral policy of a pool the LOG orphaned.
42
45
  */
43
- export { fPoolManagerAbi, padPolicyAbi, polPolicyAbi, privatePolicyAbi, publicPolicyAbi };
46
+ export { managerFAbi, orphanPolicyFAbi, padPolicyAbi, polPolicyAbi, sponsorPolicyFAbi };
44
47
  /**
45
- * What every protocol policy shares (`FPolicyBase`): the roles and their handover and the
46
- * `maxHarvest` readout (a harvest has no cut, decisions 056). `polPolicyAbi` is a superset of it and carries nothing that collides, so it stands
47
- * in for the base — a call through it to any of the four policies decodes the base's functions.
48
+ * What the protocol's policies share: `authority`, `nameOf` / `setName`, `kind`, `maxHarvest`
49
+ * (a harvest has no cut, decisions 056). `polPolicyAbi` is a superset of it, so it stands in for the base: a call
50
+ * through it to any F policy decodes the base's functions (`maxHarvest` is absent on the orphan policy, which refuses every harvest).
48
51
  */
49
52
  export const fPolicyBaseAbi = polPolicyAbi;
50
53
  import { clientChainId, type LogswapClient } from "./client.js";
54
+ import { findQuoteResult } from "./quote.js";
51
55
  import { fallBackUnlessRejected, signerFor } from "./write.js";
52
56
  import { getEventLogs } from "./history.js";
53
57
  import { poolHolders } from "./views.js";
@@ -57,9 +61,14 @@ import { isValidMintFee, MINT_FEE_MAX } from "./keys.js";
57
61
  const WAD = 10n ** 18n;
58
62
  const ZERO_ADDRESS = "0x0000000000000000000000000000000000000000" as const;
59
63
 
60
- /** The optional questions a policy declared at birth, as bits of `Pool.asks`. */
61
- export const ASK_SWAP = 1;
62
- export const ASK_MINT = 2;
64
+ /**
65
+ * The bits a policy declares at birth, in `Pool.flags` (decision 098; `ASK_SWAP` / `ASK_MINT` before): with a gate bit off nothing is
66
+ * asked; with it on the manager admits the cached operator with no policy call and asks the policy about everyone else.
67
+ */
68
+ export const GATE_SWAP = 1;
69
+ export const GATE_MINT = 2;
70
+ /** `GATE_SWAP | GATE_MINT`: the bits `setGates` carries (`SEED_TO_DEAD` is the birth's alone). */
71
+ export const GATES = GATE_SWAP | GATE_MINT;
63
72
 
64
73
  /** Everything scalar about a basket pool, in one round trip's worth of reads. */
65
74
  export interface FPoolState {
@@ -101,8 +110,13 @@ export interface FPoolState {
101
110
  * {@link getFPoolRoles}; one of the deployment's four ({@link fPoolPolicyFor}) on every protocol pool.
102
111
  */
103
112
  policy: Address;
104
- /** Whether the policy asked to be consulted on swaps ({@link ASK_SWAP}) and mints ({@link ASK_MINT}) — the desk's policy does, no other. */
105
- asks: number;
113
+ /**
114
+ * What the policy declared for the pool (`Pool.flags`, decision 098): the gate bits {@link GATE_SWAP} and {@link GATE_MINT} (changed
115
+ * later by the policy's `setGates`) and the birth bit {@link SEED_TO_DEAD} (a pad's, the pool's for life).
116
+ */
117
+ flags: number;
118
+ /** The operator the manager caches for the gates (`Pool.operator`): admitted by a gated swap or mint with no policy call. Zero with no gate on. */
119
+ operator: Address;
106
120
  /** The sponsor's own label for this pool — the policy's word, mutable and never identity. "" when unnamed. */
107
121
  name: string;
108
122
  /** The time (unix seconds) of the last harvest / composition action: no swap runs at that timestamp (F version 29; a block number before). */
@@ -136,21 +150,21 @@ export interface FPoolState {
136
150
  */
137
151
  async function rawFPool(c: LogswapClient, poolId: Hex) {
138
152
  const [p] = await c.public.readContract({
139
- address: c.addresses.lens,
140
- abi: lensAbi,
141
- functionName: "getFPools",
153
+ address: c.addresses.lensF,
154
+ abi: lensFAbi,
155
+ functionName: "getPools",
142
156
  args: [[poolId]],
143
157
  });
144
158
  if (!p || /^0x0{40}$/i.test(p.quote)) throw new Error(`logswap: no F pool with id ${poolId}`);
145
159
  return p;
146
160
  }
147
161
 
148
- /** Read a basket pool whole: one lens call (`fPool`, F version 25) plus the policy's kind and name. */
162
+ /** Read a basket pool whole: one lens call (`pool`, F version 25) plus the policy's kind and name. */
149
163
  export async function getFPool(c: LogswapClient, poolId: Hex): Promise<FPoolState> {
150
164
  const v = await c.public.readContract({
151
- address: c.addresses.lens,
152
- abi: lensAbi,
153
- functionName: "fPool",
165
+ address: c.addresses.lensF,
166
+ abi: lensFAbi,
167
+ functionName: "pool",
154
168
  args: [poolId],
155
169
  });
156
170
  const p = v.pool;
@@ -178,7 +192,8 @@ export async function getFPool(c: LogswapClient, poolId: Hex): Promise<FPoolStat
178
192
  lnCapOverSeed: Number(p.lnCapOverSeed),
179
193
  realizedVariance: p.realizedVariance,
180
194
  policy: p.policy,
181
- asks: Number(p.asks),
195
+ flags: Number(p.flags),
196
+ operator: p.operator,
182
197
  name,
183
198
  restructureTime: Number(p.restructureTime),
184
199
  kind,
@@ -193,17 +208,17 @@ export async function getFPool(c: LogswapClient, poolId: Hex): Promise<FPoolStat
193
208
 
194
209
  /**
195
210
  * The kind of pool — the POLICY's self-description (the manager knows no kind; the
196
- * policy the key names is the kind, and what it promises is its code). `public`: the protocol's
197
- * own pool — its policy requires the LOG Authority as creator; no gate, no operator. `private`, the
198
- * desk: the one whose policy may gate swaps and mints, with an operator that reshapes the legs
199
- * between generations. `pol`, a treasury's pool, one base: composition and access fixed at
200
- * birth. `pad`, a launch, one base: its policy answers income only at every harvest and declared
201
- * its seed the pool's at birth (`SEED_TO_DEAD`) — open to all. private → pol → pad is the ladder
202
- * of rigidity; public is a pol held by the protocol. Every rate, role and gate is the policy's.
203
- */
204
- export type FPoolKind = "public" | "private" | "pol" | "pad";
205
- const F_KIND_NAMES: readonly FPoolKind[] = ["public", "private", "pol", "pad"];
206
- /** The policy's birth-time declaration that the seed's shares are the pool's (a pad's), in `asks`. */
211
+ * policy the key names is the kind, and what it promises is its code). `sponsor`: the sponsored policy (decision 098),
212
+ * one kind for the LOG's own instances (sponsor = the LOG: the open canonical one, or one with gates) and a third party's
213
+ * (the sponsor creates under it): its authority is `key.creator`, an optional operator, and the gate modes where the
214
+ * policy offers them. `pol`, a treasury's pool, one base: composition and access fixed at birth. `pad`, a launch,
215
+ * one base: its policy answers income only at every harvest and declared its seed the pool's at birth
216
+ * (`SEED_TO_DEAD`) — open to all. `orphan`: the pool the LOG moved off a rogue or lost sponsor, no owner and no
217
+ * setting (`PolicyRegistry.orphan`): swap and mint stay open, holders burn, claim and redeem. Every rate, role and gate is the policy's.
218
+ */
219
+ export type FPoolKind = "sponsor" | "pol" | "pad" | "orphan";
220
+ const F_KIND_NAMES: readonly FPoolKind[] = ["sponsor", "pol", "pad", "orphan"];
221
+ /** The policy's birth-time declaration that the seed's shares are the pool's (a pad's), in `flags`. */
207
222
  export const SEED_TO_DEAD = 4;
208
223
 
209
224
  const kindCache = new Map<string, Promise<FPoolKind>>();
@@ -236,11 +251,17 @@ export async function fPoolNameOf(c: LogswapClient, poolId: Hex, policy?: Addres
236
251
  return bytes32ToText(word);
237
252
  }
238
253
 
239
- /** The deployment's policy for a kind: the protocol's policy that IS that kind. */
240
- export function fPoolPolicyFor(c: LogswapClient, kind: FPoolKind): Address {
254
+ /**
255
+ * The deployment's named policies (its artifact keys): the LOG's open sponsored instance (`public`: canonical, no gate available),
256
+ * its gated sponsored instance (`private`: gates available, born gated), `pol`, `pad`. The first two are both of kind `"sponsor"`.
257
+ */
258
+ export type FPolicySlot = "public" | "private" | "pol" | "pad";
259
+
260
+ /** The deployment's policy for a slot — the one a key names when no `policy` is given. */
261
+ export function fPoolPolicyFor(c: LogswapClient, slot: FPolicySlot): Address {
241
262
  const a = c.addresses;
242
- const policy = kind === "public" ? a.publicPolicy : kind === "private" ? a.privatePolicy : kind === "pol" ? a.polPolicy : a.padPolicy;
243
- if (!policy) throw new Error(`logswap: this deployment carries no ${kind} policy`);
263
+ const policy = slot === "public" ? a.publicPolicy : slot === "private" ? a.privatePolicy : slot === "pol" ? a.polPolicy : a.padPolicy;
264
+ if (!policy) throw new Error(`logswap: this deployment carries no ${slot} policy`);
244
265
  return policy;
245
266
  }
246
267
 
@@ -250,50 +271,45 @@ export async function fPoolPolicyOf(c: LogswapClient, poolId: Hex): Promise<Addr
250
271
  }
251
272
 
252
273
  /**
253
- * A pool's roles, as its POLICY holds them. `creator` is immutable identity —
254
- * who was born holding the pool; `authority` is the cold key that owns it now, the creator until
255
- * a two-step handover; on the desk's kind the `operator` runs it (zero = the authority itself,
256
- * {@link fPoolOperatorOf}) and the two gates and the list are its. Every other kind has no
257
- * operator and no gate: those fields read zero / false.
274
+ * A pool's roles, as its POLICY holds them (decision 098). `authority` is the pool's `key.creator` for life — no handover — and zero on an
275
+ * orphaned pool. A sponsored policy also holds the pool's `operator` (appointed by the authority, admitted by the gates with no call and a runner
276
+ * of the pool), its two gates and its whitelist; every other kind has none of them: those fields read zero / false / `"open"`.
258
277
  */
259
278
  export interface FPoolRoles {
260
279
  policy: Address;
261
- creator: Address;
262
280
  authority: Address;
263
- /** The proposed next authority, until it accepts — zero when nothing is pending. */
264
- pendingAuthority: Address;
265
- /** The desk's optional pool operator (decision 073): one delegate besides the authority, zero when none. */
281
+ /** The sponsored policy's per-pool operator (`appointOperator`): zero when none, and on every other kind. */
266
282
  operator: Address;
283
+ /** The mint gate (sponsored policies, where gates are available): on, only the authority and the operator mint. */
267
284
  gateMint: boolean;
268
- /** The desk's swap admission (decision 073): open to all, listed takers/minters only, or one cached executor. */
285
+ /** Swap admission (sponsored policies, where gates are available): everyone, the operator only, or the whitelist (the operator always passes). */
269
286
  swapMode: FPoolSwapMode;
270
- /** The executor in `executor` mode, zero otherwise. */
271
- swapExecutor: Address;
272
- /** The policy's own ceiling on a harvest now — the bid ({@link FPoolDescription.harvestable}) narrowed by the policy's rule. */
287
+ /** The policy's own ceiling on a harvest now — the bid ({@link FPoolDescription.harvestable}) narrowed by the policy's rule. Zero on an orphaned pool. */
273
288
  maxHarvest: bigint;
274
289
  }
275
290
 
276
- /** `PrivatePolicy.SwapMode`: Open = 0, Listed = 1, Executor = 2. */
277
- export type FPoolSwapMode = "open" | "listed" | "executor";
278
- const SWAP_MODES: readonly FPoolSwapMode[] = ["open", "listed", "executor"];
291
+ /** `SponsorPolicyBase.SwapMode`: Open = 0, Operator = 1, Listed = 2. */
292
+ export type FPoolSwapMode = "open" | "operator" | "listed";
293
+ const SWAP_MODES: readonly FPoolSwapMode[] = ["open", "operator", "listed"];
294
+ /** The swap modes in `SponsorPolicyBase.SwapMode` order — the index is the on-chain ordinal. */
295
+ export const fPoolSwapModes: readonly FPoolSwapMode[] = SWAP_MODES;
279
296
 
280
297
  /** Read a pool's roles from its policy. `state` saves the `getPool` round trip when already in hand. */
281
298
  export async function getFPoolRoles(c: LogswapClient, poolId: Hex, state?: Pick<FPoolState, "policy" | "kind">): Promise<FPoolRoles> {
282
299
  const s = state ?? (await getFPool(c, poolId));
283
300
  const rdPolicy = <T>(abi: readonly unknown[], functionName: string) =>
284
301
  c.public.readContract({ address: s.policy, abi, functionName, args: [poolId] } as never) as Promise<T>;
285
- const [creator, authority, pendingAuthority, maxHarvest] = await Promise.all([
286
- rdPolicy<Address>(fPolicyBaseAbi, "creator"),
302
+ const [authority, maxHarvest] = await Promise.all([
287
303
  rdPolicy<Address>(fPolicyBaseAbi, "authority"),
288
- rdPolicy<Address>(fPolicyBaseAbi, "pendingAuthority"),
289
- rdPolicy<bigint>(fPolicyBaseAbi, "maxHarvest"),
304
+ s.kind === "orphan" ? Promise.resolve(0n) : rdPolicy<bigint>(fPolicyBaseAbi, "maxHarvest"),
305
+ ]);
306
+ if (s.kind !== "sponsor") return { policy: s.policy, authority, operator: ZERO_ADDRESS, gateMint: false, swapMode: "open", maxHarvest };
307
+ const [operator, gateMint, mode] = await Promise.all([
308
+ rdPolicy<Address>(sponsorPolicyFAbi, "operator"),
309
+ rdPolicy<boolean>(sponsorPolicyFAbi, "gateMint"),
310
+ rdPolicy<number>(sponsorPolicyFAbi, "swapMode"),
290
311
  ]);
291
- const desk = s.kind === "private";
292
- const permissions = desk
293
- ? ((await c.public.readContract({ address: s.policy, abi: privatePolicyAbi, functionName: "permissionsOf", args: [poolId] } as never)) as readonly [number, Address, boolean, Address, Address])
294
- : undefined;
295
- const [mode, swapExecutor, gateMint, , operator] = permissions ?? [0, ZERO_ADDRESS, false, ZERO_ADDRESS, ZERO_ADDRESS];
296
- return { policy: s.policy, creator, authority, pendingAuthority, operator, gateMint, swapMode: SWAP_MODES[Number(mode)] ?? "open", swapExecutor, maxHarvest };
312
+ return { policy: s.policy, authority, operator, gateMint, swapMode: SWAP_MODES[Number(mode)] ?? "open", maxHarvest };
297
313
  }
298
314
 
299
315
  /** Which of the two products a pool is configured as — a pad is a launch, anything else a basket/pool. A UI has to choose what to render. */
@@ -467,11 +483,11 @@ export function fPoolPreviewMintQuote(st: Pick<FPoolState, "Q" | "L">, dL: bigin
467
483
  * and expect change back — do not treat it as exact.
468
484
  */
469
485
  export async function fPoolPreviewZapIn(c: LogswapClient, poolId: Hex, dL: bigint): Promise<bigint> {
470
- // read-only lives on the LENS (the router's F flows moved to a facet; its previews came here)
471
- const { lensAbi } = await import("./generated.js");
486
+ // read-only lives on the LENS (LensF: the previews)
487
+ const { lensFAbi } = await import("./generated.js");
472
488
  return c.public.readContract({
473
- address: c.addresses.lens,
474
- abi: lensAbi,
489
+ address: c.addresses.lensF,
490
+ abi: lensFAbi,
475
491
  functionName: "previewZapIn",
476
492
  args: [poolId, dL],
477
493
  } as never) as Promise<bigint>;
@@ -531,8 +547,8 @@ export async function fPoolPreviewZapOut(
531
547
  a: { poolId: Hex; shares: bigint; tokenOut: Address; account: Address },
532
548
  ): Promise<bigint> {
533
549
  const { result } = await c.public.simulateContract({
534
- address: c.addresses.router,
535
- abi: routerAbi,
550
+ address: c.addresses.routerF,
551
+ abi: routerFAbi,
536
552
  functionName: "zapOut",
537
553
  args: [a.poolId, a.shares, a.tokenOut, 0n, a.account, defaultDeadline()],
538
554
  account: a.account,
@@ -588,10 +604,10 @@ export async function fPoolPreviewRollIn(
588
604
  holder: Address,
589
605
  shares: bigint,
590
606
  ): Promise<{ dL: bigint; quoteShort: bigint; quoteExcess: bigint }> {
591
- const { lensAbi } = await import("./generated.js");
607
+ const { lensFAbi } = await import("./generated.js");
592
608
  const [dL, quoteShort, quoteExcess] = (await c.public.readContract({
593
- address: c.addresses.lens,
594
- abi: lensAbi,
609
+ address: c.addresses.lensF,
610
+ abi: lensFAbi,
595
611
  functionName: "previewRollIn",
596
612
  args: [poolId, BigInt(gen), holder, shares],
597
613
  } as never)) as readonly [bigint, bigint, bigint];
@@ -630,9 +646,9 @@ export async function fPoolClaim(c: LogswapClient, a: { poolId: Hex; gen?: bigin
630
646
  export async function fPoolDividendOf(c: LogswapClient, poolId: Hex, holder: Address, gen?: bigint | number): Promise<bigint> {
631
647
  const g = gen ?? (await fPoolGen(c, poolId));
632
648
  return c.public.readContract({
633
- address: c.addresses.lens,
634
- abi: lensAbi,
635
- functionName: "fDividendOf",
649
+ address: c.addresses.lensF,
650
+ abi: lensFAbi,
651
+ functionName: "dividendOf",
636
652
  args: [poolId, BigInt(g), holder],
637
653
  });
638
654
  }
@@ -659,9 +675,9 @@ export interface FPoolLien {
659
675
  export async function fPoolLienOf(c: LogswapClient, poolId: Hex, owner: Address, gen?: bigint | number): Promise<FPoolLien> {
660
676
  const g = gen ?? (await fPoolGen(c, poolId));
661
677
  const [locker, amount, owed] = await c.public.readContract({
662
- address: c.addresses.lens,
663
- abi: lensAbi,
664
- functionName: "fLienOf",
678
+ address: c.addresses.lensF,
679
+ abi: lensFAbi,
680
+ functionName: "lienOf",
665
681
  args: [fPoolShareId(poolId, g), owner],
666
682
  });
667
683
  return { locker, amount, owed };
@@ -716,8 +732,8 @@ function requireWallet(c: LogswapClient) {
716
732
  async function writeFPool(c: LogswapClient, poolId: Hex, functionName: string, args: unknown[], account: Address) {
717
733
  const wallet = requireWallet(c);
718
734
  const { request } = await c.public.simulateContract({
719
- address: c.addresses.fPoolManager!,
720
- abi: fPoolManagerAbi,
735
+ address: c.addresses.managerF,
736
+ abi: managerFAbi,
721
737
  functionName,
722
738
  // Every manager write is keyed by poolId as its FIRST parameter; prepending it here, in the
723
739
  // one place all seven helpers share, is what keeps a caller from ever omitting it. The `as
@@ -732,8 +748,8 @@ async function writeFPool(c: LogswapClient, poolId: Hex, functionName: string, a
732
748
  async function writeFPool0(c: LogswapClient, functionName: string, args: unknown[], account: Address) {
733
749
  const wallet = requireWallet(c);
734
750
  const { request } = await c.public.simulateContract({
735
- address: c.addresses.fPoolManager!,
736
- abi: fPoolManagerAbi,
751
+ address: c.addresses.managerF,
752
+ abi: managerFAbi,
737
753
  functionName,
738
754
  args,
739
755
  account: signerFor(c, account),
@@ -754,17 +770,17 @@ async function writeRouter(
754
770
  let sendArgs: unknown[] = args;
755
771
  if (pullTokens.length) {
756
772
  const { permit2SigCalls } = await import("./onboard.js");
757
- const sigCalls = await permit2SigCalls(c, pullTokens).catch(fallBackUnlessRejected);
773
+ const sigCalls = await permit2SigCalls(c, "F", pullTokens).catch(fallBackUnlessRejected);
758
774
  if (sigCalls.length) {
759
775
  const { encodeFunctionData } = await import("viem");
760
- const inner = encodeFunctionData({ abi: routerAbi, functionName, args } as never);
776
+ const inner = encodeFunctionData({ abi: routerFAbi, functionName, args } as never);
761
777
  fn = "multicall";
762
778
  sendArgs = [[...sigCalls, inner]];
763
779
  }
764
780
  }
765
781
  const { request } = await c.public.simulateContract({
766
- address: c.addresses.router,
767
- abi: routerAbi,
782
+ address: c.addresses.routerF,
783
+ abi: routerFAbi,
768
784
  functionName: fn,
769
785
  args: sendArgs,
770
786
  account: signerFor(c, account),
@@ -787,7 +803,7 @@ export async function approveTokenForFPoolManager(c: LogswapClient, token: Addre
787
803
  address: token,
788
804
  abi: [{ type: "function", name: "approve", stateMutability: "nonpayable", inputs: [{ name: "s", type: "address" }, { name: "a", type: "uint256" }], outputs: [{ type: "bool" }] }],
789
805
  functionName: "approve",
790
- args: [c.addresses.fPoolManager!, (1n << 256n) - 1n],
806
+ args: [c.addresses.managerF, (1n << 256n) - 1n],
791
807
  account: wallet.account,
792
808
  chain: c.wallet!.chain,
793
809
  } as never);
@@ -799,7 +815,7 @@ export async function fPoolManagerAllowanceOk(c: LogswapClient, token: Address,
799
815
  address: token,
800
816
  abi: [{ type: "function", name: "allowance", stateMutability: "view", inputs: [{ name: "o", type: "address" }, { name: "s", type: "address" }], outputs: [{ type: "uint256" }] }],
801
817
  functionName: "allowance",
802
- args: [owner, c.addresses.fPoolManager!],
818
+ args: [owner, c.addresses.managerF],
803
819
  } as never)) as bigint;
804
820
  return allowance >= need;
805
821
  }
@@ -813,10 +829,10 @@ export async function fPoolManagerAllowanceOk(c: LogswapClient, token: Address,
813
829
 
814
830
  export async function isRouterOperatorForFPool(c: LogswapClient, owner: Address): Promise<boolean> {
815
831
  return c.public.readContract({
816
- address: c.addresses.fPoolManager!,
817
- abi: fPoolManagerAbi,
832
+ address: c.addresses.managerF,
833
+ abi: managerFAbi,
818
834
  functionName: "isOperator",
819
- args: [owner, c.addresses.router],
835
+ args: [owner, c.addresses.routerF],
820
836
  } as never) as Promise<boolean>;
821
837
  }
822
838
 
@@ -824,10 +840,10 @@ export async function isRouterOperatorForFPool(c: LogswapClient, owner: Address)
824
840
  export async function approveRouterForFPool(c: LogswapClient, account: Address) {
825
841
  const wallet = requireWallet(c);
826
842
  const { request } = await c.public.simulateContract({
827
- address: c.addresses.fPoolManager!,
828
- abi: fPoolManagerAbi,
843
+ address: c.addresses.managerF,
844
+ abi: managerFAbi,
829
845
  functionName: "setOperator",
830
- args: [c.addresses.router, true],
846
+ args: [c.addresses.routerF, true],
831
847
  account: signerFor(c, account),
832
848
  } as never);
833
849
  return wallet.writeContract(request as never);
@@ -867,8 +883,8 @@ export function fPoolClaimId(token: Address): bigint {
867
883
  export async function fPoolShareBalance(c: LogswapClient, poolId: Hex, owner: Address, gen?: bigint | number): Promise<bigint> {
868
884
  const g = gen ?? (await fPoolGen(c, poolId));
869
885
  return c.public.readContract({
870
- address: c.addresses.fPoolManager!,
871
- abi: fPoolManagerAbi,
886
+ address: c.addresses.managerF,
887
+ abi: managerFAbi,
872
888
  functionName: "balanceOf",
873
889
  args: [owner, fPoolShareId(poolId, g)],
874
890
  } as never) as Promise<bigint>;
@@ -881,9 +897,9 @@ export async function fPoolBundleOf(
881
897
  gen: bigint | number,
882
898
  ): Promise<{ supply: bigint; quote: bigint; base: bigint[] }> {
883
899
  const [supply, quote, base] = await c.public.readContract({
884
- address: c.addresses.lens,
885
- abi: lensAbi,
886
- functionName: "fBundleOf",
900
+ address: c.addresses.lensF,
901
+ abi: lensFAbi,
902
+ functionName: "bundleOf",
887
903
  args: [poolId, BigInt(gen)],
888
904
  });
889
905
  return { supply, quote, base: [...base] };
@@ -900,11 +916,11 @@ export interface FPoolClaimRow {
900
916
 
901
917
  /** A holder's claims on a pool's retired generations — one row per generation still held. */
902
918
  export async function fPoolClaimsOf(c: LogswapClient, poolId: Hex, owner: Address): Promise<FPoolClaimRow[]> {
903
- const { lensAbi } = await import("./generated.js");
919
+ const { lensFAbi } = await import("./generated.js");
904
920
  const rows = (await c.public.readContract({
905
- address: c.addresses.lens,
906
- abi: lensAbi,
907
- functionName: "fClaimsOf",
921
+ address: c.addresses.lensF,
922
+ abi: lensFAbi,
923
+ functionName: "claimsOf",
908
924
  args: [poolId, owner],
909
925
  } as never)) as readonly { gen: bigint; shares: bigint; base: readonly bigint[]; quote: bigint; dividend: bigint }[];
910
926
  return rows.map((r) => ({ gen: Number(r.gen), shares: r.shares, base: [...r.base], quote: r.quote, dividend: r.dividend }));
@@ -924,8 +940,8 @@ export async function fPoolRedeem(
924
940
 
925
941
  export async function fPoolClaimBalance(c: LogswapClient, token: Address, owner: Address): Promise<bigint> {
926
942
  return c.public.readContract({
927
- address: c.addresses.fPoolManager!,
928
- abi: fPoolManagerAbi,
943
+ address: c.addresses.managerF,
944
+ abi: managerFAbi,
929
945
  functionName: "balanceOf",
930
946
  args: [owner, fPoolClaimId(token)],
931
947
  } as never) as Promise<bigint>;
@@ -953,8 +969,8 @@ export async function fPoolQuoteSwap(
953
969
  ): Promise<bigint> {
954
970
  try {
955
971
  await c.public.simulateContract({
956
- address: c.addresses.router,
957
- abi: routerAbi,
972
+ address: c.addresses.routerF,
973
+ abi: routerFAbi,
958
974
  functionName: "quoteSwap",
959
975
  // the taker matters only on a gated pool: the connected account, or the zero address
960
976
  args: [a.poolId, a.kind, BigInt(a.j), BigInt(a.k ?? 0), a.amountIn, a.taker ?? c.wallet?.account?.address ?? ZERO_ADDRESS],
@@ -967,32 +983,6 @@ export async function fPoolQuoteSwap(
967
983
  throw new Error("logswap: quoteSwap returned without reverting, which it must never do");
968
984
  }
969
985
 
970
- /**
971
- * `QuoteResult(uint256)` — selector then one word. viem nests the revert data several layers deep
972
- * depending on the transport, so walk for it rather than guessing the shape.
973
- *
974
- * The selector is DERIVED, not written down. A hardcoded one is wrong silently: the decode simply
975
- * never matches and every quote rethrows as if the swap had failed.
976
- */
977
- function findQuoteResult(err: unknown): bigint | null {
978
- const SELECTOR = toFunctionSelector("QuoteResult(uint256)");
979
- const seen = new Set<unknown>();
980
- const walk = (e: unknown): bigint | null => {
981
- if (!e || typeof e !== "object" || seen.has(e)) return null;
982
- seen.add(e);
983
- const anyE = e as Record<string, unknown>;
984
- const data = anyE.data;
985
- if (typeof data === "string" && data.startsWith(SELECTOR) && data.length >= 10 + 64) {
986
- return BigInt("0x" + data.slice(10, 10 + 64));
987
- }
988
- for (const k of ["cause", "walk", "error", "details"]) {
989
- const found = walk(anyE[k]);
990
- if (found !== null) return found;
991
- }
992
- return null;
993
- };
994
- return walk(err);
995
- }
996
986
 
997
987
  // ─── the pool lifecycle (creation to dissolution) ─────────────────────────────
998
988
  //
@@ -1013,18 +1003,17 @@ export interface FPoolCreateArgs {
1013
1003
  */
1014
1004
  mintFee?: bigint;
1015
1005
  /**
1016
- * Which of the protocol's four the pool is — see {@link FPoolKind}. NOT a key field (decisions
1017
- * 049: the manager knows no kind): it selects the deployment's policy of that kind when `policy`
1018
- * is not named ({@link fPoolPolicyFor}), and it is what the policy will say it is.
1006
+ * Which of the deployment's policies the key names when `policy` is not given ({@link fPoolPolicyFor}). NOT a key
1007
+ * field (decisions 049: the manager knows no kind): the policy is, and it says what it is ({@link FPoolKind}).
1019
1008
  */
1020
- kind: FPoolKind;
1009
+ kind: FPolicySlot;
1021
1010
  /**
1022
- * The pool's policy: the contract the key names, approved by the
1023
- * registry, and the pool's kind. Defaults to the deployment's policy for `kind`
1024
- * ({@link fPoolPolicyFor}) — the one every protocol pool names.
1011
+ * The pool's policy: the contract the key names, approved by the registry — the pool's kind. Defaults to the
1012
+ * deployment's policy for `kind` ({@link fPoolPolicyFor}). A sponsored policy admits creation by its sponsor only
1013
+ * (`SponsorOnly`), and the initializer must be `creator` (`NotCreator`).
1025
1014
  */
1026
1015
  policy?: Address;
1027
- /** Who is born holding the pool: immutable identity, the pool's first authority (the policy records it). */
1016
+ /** Who is born holding the pool: immutable identity, the pool's authority for life (the policy records it) and the initializer (`NotCreator`). */
1028
1017
  creator: Address;
1029
1018
  /**
1030
1019
  * The differentiator, and nothing else. Identity is the key's hash, so one sponsor cannot run
@@ -1125,8 +1114,8 @@ export async function fPoolInitialize(c: LogswapClient, a: FPoolCreateArgs) {
1125
1114
  }
1126
1115
  const wallet = requireWallet(c);
1127
1116
  const { request } = await c.public.simulateContract({
1128
- address: c.addresses.fPoolManager!,
1129
- abi: fPoolManagerAbi,
1117
+ address: c.addresses.managerF,
1118
+ abi: managerFAbi,
1130
1119
  functionName: "initialize",
1131
1120
  args: [key],
1132
1121
  account: wallet.account,
@@ -1150,9 +1139,9 @@ export async function fPoolIdOf(c: LogswapClient, a: Omit<FPoolCreateArgs, "acco
1150
1139
  * returning a key that names another pool. What {@link fPoolMigrate} needs when handed an id.
1151
1140
  */
1152
1141
  export async function fPoolKeyOfPool(c: LogswapClient, poolId: Hex, opts: { salt?: Hex; fromBlock?: bigint; /** The rindexer GraphQL endpoint: `PoolCreated` from there, the node otherwise. The salt is in neither (the event does not carry it). */ indexer?: string } = {}): Promise<FPoolKey> {
1153
- type Ev = Extract<(typeof fPoolManagerAbi)[number], { type: "event"; name: "PoolCreated" }>;
1154
- const ev = fPoolManagerAbi.find((x): x is Ev => x.type === "event" && x.name === "PoolCreated")!;
1155
- const { logs } = await getEventLogs(c, { indexer: opts.indexer, address: c.addresses.fPoolManager!, event: ev as never, args: { poolId }, fromBlock: opts.fromBlock });
1142
+ type Ev = Extract<(typeof managerFAbi)[number], { type: "event"; name: "PoolCreated" }>;
1143
+ const ev = managerFAbi.find((x): x is Ev => x.type === "event" && x.name === "PoolCreated")!;
1144
+ const { logs } = await getEventLogs(c, { indexer: opts.indexer, address: c.addresses.managerF, event: ev as never, args: { poolId }, fromBlock: opts.fromBlock });
1156
1145
  const l = logs[0];
1157
1146
  if (!l) throw new Error(`logswap: no PoolCreated for F pool ${poolId}`);
1158
1147
  const a = l.args as unknown as { quote: Address; creator: Address; bases: readonly Address[]; swapFee: bigint; policy: Address; mintFee: bigint };
@@ -1378,7 +1367,7 @@ export async function fPoolClose(c: LogswapClient, a: { poolId: Hex; to?: Addres
1378
1367
  const harvests = await fPoolEmptyingHarvests(c, a.poolId);
1379
1368
  if (harvests.length === 0) return fPoolCloseRaw(c, a);
1380
1369
  const enc = (functionName: string, args: unknown[]) =>
1381
- encodeFunctionData({ abi: fPoolManagerAbi, functionName, args } as never) as Hex;
1370
+ encodeFunctionData({ abi: managerFAbi, functionName, args } as never) as Hex;
1382
1371
  const calls: Hex[] = [...harvests.map((amount) => enc("harvest", [a.poolId, amount, a.account])), enc("close", [a.poolId, a.to ?? a.account])];
1383
1372
  return writeFPool0(c, "multicall", [calls], a.account);
1384
1373
  }
@@ -1415,8 +1404,8 @@ export async function fPoolEmptyingHarvests(c: LogswapClient, poolId: Hex): Prom
1415
1404
  * - the income released (`IncomeReleased`), all in quote: `toPayee` to the payee and the rest into the bid
1416
1405
  * (the floor down). No share is minted; L does not move. The book keeps its reserves, marks and cap.
1417
1406
  *
1418
- * A pad's gate is `threshold(poolId, gen)`, in its quote (`PadPolicy.NotGraduated` below it); POL and private carry the
1419
- * authority and send it the whole income; a public pool refuses (`Refused`). A carried holder with no
1407
+ * A pad's gate is `threshold(poolId, gen)`, in its quote (`PadPolicy.NotGraduated` below it); POL and a non-canonical sponsored pool carry the
1408
+ * authority and send it the whole income; a canonical sponsored pool (the LOG's open instance) refuses (`Refused`). A carried holder with no
1420
1409
  * share is `BadTerms`. Whoever runs the pool. To change the book (reserves, prices, cap) use {@link fPoolDeploy}.
1421
1410
  */
1422
1411
  export async function fPoolRegenerate(c: LogswapClient, a: { poolId: Hex; to?: Address; account: Address }) {
@@ -1489,7 +1478,7 @@ export interface FPoolLaunchArgs extends Omit<FPoolCreateArgs, "account"> {
1489
1478
  * out: the key is a pure function of the arguments and a second `initialize` can only revert.
1490
1479
  */
1491
1480
  initialized?: boolean;
1492
- /** Anything else, pre-encoded against {@link fPoolManagerAbi}, appended after the above. */
1481
+ /** Anything else, pre-encoded against {@link managerFAbi}, appended after the above. */
1493
1482
  extra?: Hex[];
1494
1483
  account: Address;
1495
1484
  }
@@ -1517,7 +1506,7 @@ export function fPoolLaunchCalls(
1517
1506
  mintFee: a.mintFee ?? presetMintFee(a.swapFee),
1518
1507
  };
1519
1508
  const enc = (functionName: string, args: unknown[]) =>
1520
- encodeFunctionData({ abi: fPoolManagerAbi, functionName, args } as never) as Hex;
1509
+ encodeFunctionData({ abi: managerFAbi, functionName, args } as never) as Hex;
1521
1510
  const calls: Hex[] = [];
1522
1511
  if (!a.initialized) calls.push(enc("initialize", [key]));
1523
1512
  calls.push(enc("deployLiquidity", [poolId, baseAssets, a.quoteAmount, lnCapOverSeed, a.account]));
@@ -1528,7 +1517,7 @@ export function fPoolLaunchCalls(
1528
1517
  if (j < 0) throw new Error(`logswap: genesis row j = ${row.j} is not a leg`);
1529
1518
  calls.push(enc(row.side === "buy" ? "swapQuoteIn" : "swapBaseIn", [poolId, BigInt(j), row.amountIn, row.minOut ?? 0n, a.account]));
1530
1519
  }
1531
- // the name, the desk's gates and its list are the POLICY's, not the
1520
+ // the name, a sponsored policy's gates and its whitelist are the POLICY's, not the
1532
1521
  // manager's: they cannot ride in this batch — `fPoolLaunch` and `fPoolDeskOpening` send them
1533
1522
  // right after, as the same creator
1534
1523
  calls.push(...(a.extra ?? []));
@@ -1555,8 +1544,8 @@ export async function fPoolGenesisOutputs(
1555
1544
  if (rows.length === 0) return [];
1556
1545
  const calls = fPoolLaunchCalls(poolId, a);
1557
1546
  const { result } = await c.public.simulateContract({
1558
- address: c.addresses.fPoolManager!,
1559
- abi: fPoolManagerAbi,
1547
+ address: c.addresses.managerF,
1548
+ abi: managerFAbi,
1560
1549
  functionName: "multicall",
1561
1550
  args: [calls],
1562
1551
  account: signerFor(c, a.account),
@@ -1617,27 +1606,23 @@ export async function fPoolWalletBatchesAtomically(c: LogswapClient, account: Ad
1617
1606
  }
1618
1607
 
1619
1608
  /**
1620
- * The desk's opening posture, on its policy: gated minting, the creator a
1621
- * minter. No appointment: the authority is the operator until one is appointed.
1622
- * Two writes to `PrivatePolicy`; the launch batch cannot carry them (they are not manager calls).
1609
+ * The desk's opening posture, on its sponsored policy: gated minting (only the authority and the operator mint). The swap gate is
1610
+ * the policy's own birth (the gated instance is born with `GATE_SWAP` and the creator its operator, decision 098); this is the one write
1611
+ * that cannot ride in the launch batch (it is not a manager call).
1623
1612
  */
1624
1613
  export async function fPoolDeskOpening(c: LogswapClient, a: { poolId: Hex; account: Address; policy?: Address }): Promise<Hash[]> {
1625
1614
  const policy = a.policy ?? fPoolPolicyFor(c, "private");
1626
- return [
1627
- await fPoolSetMintGate(c, { poolId: a.poolId, gated: true, account: a.account, policy }),
1628
- await fPoolSetMinters(c, { poolId: a.poolId, who: [a.account], allowed: true, account: a.account, policy }),
1629
- ];
1615
+ return [await fPoolSetMintGate(c, { poolId: a.poolId, gated: true, account: a.account, policy })];
1630
1616
  }
1631
1617
 
1632
1618
  /**
1633
1619
  * Create a pool as ONE transaction: `initialize`, `seed`, the seed lock, the opening buy, the
1634
- * name, the private-pool gates — the manager's `multicall`, the creator as sender throughout.
1620
+ * name — the manager's `multicall`, the creator as sender throughout (the creator is the initializer, `NotCreator`).
1635
1621
  * Either every call lands or none does; there is no half-built pool to resume.
1636
1622
  *
1637
1623
  * Why the manager and not the router: every one of these entries authenticates by `msg.sender`
1638
1624
  * (`seed` is authority-only, so is everything after it). Routed, the router would be the sender
1639
- * — the authority, the holder of the seed shares — and the handover back is two-step, so it
1640
- * could not even close in the same transaction. `multicall` is delegatecall-to-self, so the
1625
+ * — the authority, the holder of the seed shares — and `initialize` would refuse it (`NotCreator`). `multicall` is delegatecall-to-self, so the
1641
1626
  * sender survives, which is what the manager's own doc says a router cannot do.
1642
1627
  *
1643
1628
  * What the batch PULLS, by plain allowance to the manager (never Permit2): `r0[j]` of each base,
@@ -1671,7 +1656,7 @@ export async function fPoolLaunch(
1671
1656
  account: signerFor(c, a.account),
1672
1657
  forceAtomic: true,
1673
1658
  calls: [
1674
- { to: c.addresses.fPoolManager!, data: encodeFunctionData({ abi: fPoolManagerAbi, functionName: "multicall", args: [calls] } as never) },
1659
+ { to: c.addresses.managerF, data: encodeFunctionData({ abi: managerFAbi, functionName: "multicall", args: [calls] } as never) },
1675
1660
  ...transfers.map((t) => ({ to: t.token, data: encodeFunctionData({ abi: erc20Abi, functionName: "transfer", args: [t.to, t.amount] }) })),
1676
1661
  ],
1677
1662
  } as never);
@@ -1706,82 +1691,48 @@ async function writePolicy(c: LogswapClient, abi: readonly unknown[], a: { poolI
1706
1691
  return wallet.writeContract(request as never);
1707
1692
  }
1708
1693
 
1709
- /**
1710
- * Propose the next authority — step one of two, on the pool's policy. Nothing moves
1711
- * until `next` accepts; proposing again (the zero address included) cancels a pending proposal.
1712
- * Indexed on-chain via the policy's AuthorityProposed.
1713
- */
1714
- export async function fPoolProposeAuthority(c: LogswapClient, a: { poolId: Hex; next: Address; account: Address; policy?: Address }) {
1715
- return writePolicy(c, fPolicyBaseAbi, a, "proposeAuthority", [a.next]);
1716
- }
1694
+ // ─── a sponsored policy's per-pool settings (the authority's; decision 098) ───────────────
1695
+ //
1696
+ // `SponsorPolicyF` and `SponsorPolicyC` share these functions, so one ABI writes both: for a C market pass `policy: key.policy`
1697
+ // (the default policy lookup reads F's lens). Where the policy offers no gates (`gatesAvailable` false: the LOG's open
1698
+ // instance) the mode, gate and list writes revert with `GatesUnavailable`.
1717
1699
 
1718
1700
  /**
1719
- * Accept a pending proposal — step two; only the proposed address can. Indexed via the policy's
1720
- * AuthoritySet. On the desk's policy this clears the operator (pending and accepted) and voids the
1721
- * seller's list.
1701
+ * Appoint the pool's operator (the authority's; zero revokes, refused in `operator` swap mode): admitted by the gates with no policy call and a
1702
+ * runner of the pool; it may be a contract (an executor). Immediate, with no acceptance step, so check the address. Stamps the block.
1722
1703
  */
1723
- export async function fPoolAcceptAuthority(c: LogswapClient, a: { poolId: Hex; account: Address; policy?: Address }) {
1724
- return writePolicy(c, fPolicyBaseAbi, a, "acceptAuthority", []);
1704
+ export async function fPoolAppointOperator(c: LogswapClient, a: { poolId: Hex; operator: Address; account: Address; policy?: Address }) {
1705
+ return writePolicy(c, sponsorPolicyFAbi, a, "appointOperator", [a.operator]);
1725
1706
  }
1726
1707
 
1727
- // ─── the desk's controls (PrivatePolicy) ───────────────────────────────
1728
-
1729
1708
  /**
1730
- * Set the desk's swap admission (the authority, on the desk's policy; decision 073): `open`, `listed` (the minters and takers
1731
- * lists) or `executor` (one address, cached on the manager, no policy call per swap). `executor` is required in `executor` mode
1732
- * and must be omitted otherwise. Preserves mint admission. `burn` is never gated.
1709
+ * Set swap admission (the authority's, where the policy offers gates): `open`, `operator` (only the operator swaps — needs one appointed) or
1710
+ * `listed` (the whitelist, {@link fPoolSetListed}; the operator always passes). `burn` is never gated.
1733
1711
  */
1734
- export async function fPoolSetSwapMode(
1735
- c: LogswapClient,
1736
- a: { poolId: Hex; mode: FPoolSwapMode; executor?: Address; account: Address; policy?: Address },
1737
- ) {
1738
- return writePolicy(c, privatePolicyAbi, a, "setSwapMode", [SWAP_MODES.indexOf(a.mode), a.executor ?? ZERO_ADDRESS]);
1712
+ export async function fPoolSetSwapMode(c: LogswapClient, a: { poolId: Hex; mode: FPoolSwapMode; account: Address; policy?: Address }) {
1713
+ return writePolicy(c, sponsorPolicyFAbi, a, "setSwapMode", [SWAP_MODES.indexOf(a.mode)]);
1739
1714
  }
1740
1715
 
1741
- /** Turn mint admission on or off (the authority, on the desk's policy), preserving the swap mode and its executor. */
1716
+ /** Turn the mint gate on or off (the authority's, where the policy offers gates): on, only the authority and the operator mint. */
1742
1717
  export async function fPoolSetMintGate(c: LogswapClient, a: { poolId: Hex; gated: boolean; account: Address; policy?: Address }) {
1743
- return writePolicy(c, privatePolicyAbi, a, "setMintGate", [a.gated]);
1718
+ return writePolicy(c, sponsorPolicyFAbi, a, "setMintGate", [a.gated]);
1744
1719
  }
1745
1720
 
1746
1721
  /**
1747
- * Add to or remove from the pool's MINTERS — who may mint, and swap (a zap in is both under one
1748
- * lock) — in one call (the authority, on the desk's policy). The list is keyed by
1749
- * the authority that granted it: a handover starts the buyer with an empty one. Stamps the
1750
- * block: no swap lands in it (047).
1722
+ * Add to or remove from the pool's swap WHITELIST in one call (the authority's, where the policy offers gates; consulted in `listed` mode).
1723
+ * The one list: the free-form minter and taker lists are gone. Stamps the block: no swap lands in it (047).
1751
1724
  */
1752
- export async function fPoolSetMinters(
1725
+ export async function fPoolSetListed(
1753
1726
  c: LogswapClient,
1754
- a: { poolId: Hex; who: readonly Address[]; allowed: boolean; account: Address; policy?: Address },
1727
+ a: { poolId: Hex; who: readonly Address[]; listed: boolean; account: Address; policy?: Address },
1755
1728
  ) {
1756
- return writePolicy(c, privatePolicyAbi, a, "setMinters", [a.who, a.allowed]);
1729
+ return writePolicy(c, sponsorPolicyFAbi, a, "setListed", [a.who, a.listed]);
1757
1730
  }
1758
1731
 
1759
- /** Add to or remove from the pool's TAKERS — who may swap only — in one call (the authority). Stamps the block. */
1760
- export async function fPoolSetTakers(
1761
- c: LogswapClient,
1762
- a: { poolId: Hex; who: readonly Address[]; allowed: boolean; account: Address; policy?: Address },
1763
- ) {
1764
- return writePolicy(c, privatePolicyAbi, a, "setTakers", [a.who, a.allowed]);
1765
- }
1766
-
1767
- async function readDesk<T>(c: LogswapClient, poolId: Hex, who: Address, functionName: string, policy?: Address): Promise<T> {
1732
+ /** On the pool's swap whitelist now (the sponsored policy's `listed`). */
1733
+ export async function fPoolIsListed(c: LogswapClient, poolId: Hex, who: Address, policy?: Address): Promise<boolean> {
1768
1734
  const address = policy ?? (await fPoolPolicyOf(c, poolId));
1769
- return (await c.public.readContract({ address, abi: privatePolicyAbi, functionName, args: [poolId, who] } as never)) as T;
1770
- }
1771
-
1772
- /** On the pool's minters under its current authority: may mint, and swap. */
1773
- export async function fPoolIsMinter(c: LogswapClient, poolId: Hex, who: Address, policy?: Address): Promise<boolean> {
1774
- return readDesk<boolean>(c, poolId, who, "isMinter", policy);
1775
- }
1776
-
1777
- /** On the pool's takers under its current authority: may swap only. */
1778
- export async function fPoolIsTaker(c: LogswapClient, poolId: Hex, who: Address, policy?: Address): Promise<boolean> {
1779
- return readDesk<boolean>(c, poolId, who, "isTaker", policy);
1780
- }
1781
-
1782
- /** May swap: a minter or a taker (consulted only while the swap gate is on). */
1783
- export async function fPoolIsAllowed(c: LogswapClient, poolId: Hex, who: Address, policy?: Address): Promise<boolean> {
1784
- return readDesk<boolean>(c, poolId, who, "isAllowed", policy);
1735
+ return (await c.public.readContract({ address, abi: sponsorPolicyFAbi, functionName: "listed", args: [poolId, who] } as never)) as boolean;
1785
1736
  }
1786
1737
 
1787
1738
  /** Label the pool — the authority's own words on the pool's POLICY, mutable, never identity. At most 31 bytes of UTF-8. */
@@ -1818,7 +1769,7 @@ export async function fPoolSponsorName(c: LogswapClient, who: Address): Promise<
1818
1769
  /** The registry the manager asks at every birth — `addresses.policyRegistry`, else the manager's word; zero on a bare deployment. */
1819
1770
  export async function fPoolRegistryOf(c: LogswapClient): Promise<Address> {
1820
1771
  if (c.addresses.policyRegistry) return c.addresses.policyRegistry;
1821
- return (await c.public.readContract({ address: c.addresses.fPoolManager!, abi: fPoolManagerAbi, functionName: "registry" } as never)) as Address;
1772
+ return (await c.public.readContract({ address: c.addresses.managerF, abi: managerFAbi, functionName: "registry" } as never)) as Address;
1822
1773
  }
1823
1774
 
1824
1775
  async function registryAddress(c: LogswapClient): Promise<Address> {
@@ -1832,15 +1783,6 @@ export function fPoolRunners(s: Pick<FPoolRoles, "authority" | "operator">): Add
1832
1783
  return s.operator === ZERO_ADDRESS ? [s.authority] : [s.authority, s.operator];
1833
1784
  }
1834
1785
 
1835
- /**
1836
- * Grant, replace or revoke the pool operator (the authority, on the desk's policy; decision 073): one optional delegate who may
1837
- * `harvest`, `retire`, `regenerate` and `setLegs` besides the authority. Immediate, with no acceptance step, so check the
1838
- * address; the zero address revokes. A handover or a policy move clears it.
1839
- */
1840
- export async function fPoolSetPoolOperator(c: LogswapClient, a: { poolId: Hex; operator: Address; account: Address; policy?: Address }) {
1841
- return writePolicy(c, privatePolicyAbi, a, "setPoolOperator", [a.operator]);
1842
- }
1843
-
1844
1786
  /**
1845
1787
  * Move shares (ERC-6909 `transfer`) — to another holder, or to `0xdead` to lock them for good.
1846
1788
  * Burning to the dead address is a sponsor's way to make its liquidity permanent: the shares can
@@ -1853,8 +1795,8 @@ export async function fPoolTransferShares(
1853
1795
  const wallet = requireWallet(c);
1854
1796
  const gen = a.gen ?? (await fPoolGen(c, a.poolId));
1855
1797
  const { request } = await c.public.simulateContract({
1856
- address: c.addresses.fPoolManager!,
1857
- abi: fPoolManagerAbi,
1798
+ address: c.addresses.managerF,
1799
+ abi: managerFAbi,
1858
1800
  functionName: "transfer",
1859
1801
  args: [a.to, fPoolShareId(a.poolId, gen), a.shares],
1860
1802
  account: signerFor(c, a.account),
@@ -1878,7 +1820,7 @@ export interface DiscoveredFPool {
1878
1820
  kind: FPoolKind;
1879
1821
  /** The pool's policy AT BIRTH — the contract the key names. The LIVE one is {@link getFPool}'s `policy`: the registry's owner may have moved the pool (046, `PolicyMigrated`). */
1880
1822
  policy: Address;
1881
- /** Who was born holding the pool (immutable). The LIVE authority is the policy's — {@link getFPoolRoles}. */
1823
+ /** Who was born holding the pool: the key's creator, its authority for life (098) unless the LOG orphans it ({@link getFPoolRoles}). */
1882
1824
  creator: Address;
1883
1825
  /** The block the pool was initialized in — its age, for annualising realized income. */
1884
1826
  block: bigint;
@@ -1906,12 +1848,12 @@ export async function discoverFPools(
1906
1848
  c: LogswapClient,
1907
1849
  opts: { fromBlock?: bigint; toBlock?: bigint; indexer?: string } = {},
1908
1850
  ): Promise<DiscoveredFPool[]> {
1909
- type Ev = Extract<(typeof fPoolManagerAbi)[number], { type: "event"; name: "PoolCreated" }>;
1910
- const ev = fPoolManagerAbi.find((x): x is Ev => x.type === "event" && x.name === "PoolCreated");
1851
+ type Ev = Extract<(typeof managerFAbi)[number], { type: "event"; name: "PoolCreated" }>;
1852
+ const ev = managerFAbi.find((x): x is Ev => x.type === "event" && x.name === "PoolCreated");
1911
1853
  if (!ev) throw new Error("logswap: F PoolCreated event missing from the generated ABI");
1912
- type DeployEv = Extract<(typeof fPoolManagerAbi)[number], { type: "event"; name: "LiquidityDeployed" }>;
1913
- const deployEv = fPoolManagerAbi.find((x): x is DeployEv => x.type === "event" && x.name === "LiquidityDeployed");
1914
- const range = { indexer: opts.indexer, address: c.addresses.fPoolManager!, fromBlock: opts.fromBlock, toBlock: opts.toBlock };
1854
+ type DeployEv = Extract<(typeof managerFAbi)[number], { type: "event"; name: "LiquidityDeployed" }>;
1855
+ const deployEv = managerFAbi.find((x): x is DeployEv => x.type === "event" && x.name === "LiquidityDeployed");
1856
+ const range = { indexer: opts.indexer, address: c.addresses.managerF, fromBlock: opts.fromBlock, toBlock: opts.toBlock };
1915
1857
  const [{ logs }, { logs: deploys }] = await Promise.all([
1916
1858
  getEventLogs(c, { ...range, event: ev }),
1917
1859
  deployEv ? getEventLogs(c, { ...range, event: deployEv }) : Promise.resolve({ logs: [] }),
@@ -1962,7 +1904,7 @@ export interface FPoolControlled {
1962
1904
  pool: DiscoveredFPool;
1963
1905
  roles: FPoolRoles;
1964
1906
  state: FPoolState;
1965
- /** The policy's numbers for this pool's kind — a pad's gen (its rung) and threshold, a POL's floors, the desk's list flags. */
1907
+ /** The policy's numbers for this pool's kind — a pad's gen (its rung) and threshold, a POL's floors, a sponsored policy's immutables and the pool's gates. */
1966
1908
  rules: FPoolRules;
1967
1909
  }
1968
1910
 
@@ -1986,8 +1928,26 @@ export type FPoolRules =
1986
1928
  ranges: PadRanges;
1987
1929
  }
1988
1930
  | { kind: "pol"; /** The reserve a harvest leaves in the bid and a redeployment must keep, a multiple of L (WAD). */ minQuoteRatio: bigint; /** The income tax the pool's authority pays on its own new income dividend (decisions 073, 085), WAD. */ incomeTaxRate: bigint }
1989
- | { kind: "public" }
1990
- | { kind: "private"; gateMint: boolean; swapMode: FPoolSwapMode; swapExecutor: Address; operator: Address };
1931
+ | {
1932
+ kind: "sponsor";
1933
+ /** The sponsor (`sponsor()`): the account allowed to create under the policy (the LOG's own instances: the LOG Authority of the day). */
1934
+ sponsor: Address;
1935
+ /** `salt` must be zero and the book uncapped (`NotCanonical`): the LOG's open instance. */
1936
+ canonical: boolean;
1937
+ /** The authority may gate swaps and mints (false on the open instance: a public pool can never be gated). */
1938
+ gatesAvailable: boolean;
1939
+ /** The pool is born with `GATE_SWAP` and its creator as operator. */
1940
+ bornGated: boolean;
1941
+ /** The swap-fee tiers a pool may be born with, a mask over the family's table (0: any fee in the manager's domain). */
1942
+ swapTiers: bigint;
1943
+ /** The mint-fee tiers, the same (0: any). */
1944
+ mintTiers: bigint;
1945
+ /** The pool's own state: the mint gate, the swap mode and the operator. */
1946
+ gateMint: boolean;
1947
+ swapMode: FPoolSwapMode;
1948
+ operator: Address;
1949
+ }
1950
+ | { kind: "orphan" };
1991
1951
 
1992
1952
  /** The LOG Authority's range on a pad's creator choice (`PadPolicy`, decisions 056, 067), WAD fractions of the income released. */
1993
1953
  export interface PadRanges {
@@ -2042,20 +2002,28 @@ export async function getFPoolRules(c: LogswapClient, s: Pick<FPoolState, "poolI
2042
2002
  const [minQuoteRatio, incomeTaxRate] = await Promise.all([rd<bigint>(polPolicyAbi, "minQuoteRatio"), rd<bigint>(polPolicyAbi, "incomeTaxRate")]);
2043
2003
  return { kind: "pol", minQuoteRatio, incomeTaxRate };
2044
2004
  }
2045
- case "public": {
2046
- return { kind: "public" };
2047
- }
2048
- case "private": {
2005
+ case "sponsor": {
2049
2006
  const r = roles ?? (await getFPoolRoles(c, s.poolId, s));
2050
- return { kind: "private", gateMint: r.gateMint, swapMode: r.swapMode, swapExecutor: r.swapExecutor, operator: r.operator };
2007
+ const [sponsor, canonical, gatesAvailable, bornGated, swapTiers, mintTiers] = await Promise.all([
2008
+ rd<Address>(sponsorPolicyFAbi, "sponsor"),
2009
+ rd<boolean>(sponsorPolicyFAbi, "canonical"),
2010
+ rd<boolean>(sponsorPolicyFAbi, "gatesAvailable"),
2011
+ rd<boolean>(sponsorPolicyFAbi, "bornGated"),
2012
+ rd<bigint>(sponsorPolicyFAbi, "swapTiers"),
2013
+ rd<bigint>(sponsorPolicyFAbi, "mintTiers"),
2014
+ ]);
2015
+ return { kind: "sponsor", sponsor, canonical, gatesAvailable, bornGated, swapTiers, mintTiers, gateMint: r.gateMint, swapMode: r.swapMode, operator: r.operator };
2016
+ }
2017
+ case "orphan": {
2018
+ return { kind: "orphan" };
2051
2019
  }
2052
2020
  }
2053
2021
  }
2054
2022
 
2055
2023
  /**
2056
- * Every F pool `who` is the AUTHORITY of, across the four policies — the policy page's list. Pools
2057
- * `who` created and handed over are not here (the buyer's page shows them); pools handed TO
2058
- * `who` are. `pools` may be passed (from the indexer, say) to skip the log scan.
2024
+ * Every F pool `who` is the AUTHORITY of, across the policies — the policy page's list. The authority is `key.creator` for
2025
+ * life (decision 098), so these are the pools `who` created, minus any the LOG orphaned. `pools` may be passed (from the
2026
+ * indexer, say) to skip the log scan.
2059
2027
  */
2060
2028
  export async function fPoolsControlledBy(
2061
2029
  c: LogswapClient,
@@ -2094,14 +2062,14 @@ export async function fPoolShareHolders(
2094
2062
  poolIdHex: Hex,
2095
2063
  opts: { fromBlock?: bigint; gen?: bigint | number; indexer?: string } = {},
2096
2064
  ): Promise<Array<{ holder: Address; shares: bigint }>> {
2097
- type Ev = Extract<(typeof fPoolManagerAbi)[number], { type: "event"; name: "Transfer" }>;
2098
- const ev = fPoolManagerAbi.find((x): x is Ev => x.type === "event" && x.name === "Transfer");
2065
+ type Ev = Extract<(typeof managerFAbi)[number], { type: "event"; name: "Transfer" }>;
2066
+ const ev = managerFAbi.find((x): x is Ev => x.type === "event" && x.name === "Transfer");
2099
2067
  if (!ev) throw new Error("logswap: 6909 Transfer event missing from the generated ABI");
2100
2068
  const gen = opts.gen ?? (await fPoolGen(c, poolIdHex));
2101
2069
  const indexer = opts.indexer ?? c.indexerUrl;
2102
2070
  if (indexer) {
2103
2071
  try {
2104
- const rows = await poolHolders(indexer, { condition: { side: "F", poolId: poolIdHex.toLowerCase(), gen: Number(gen), manager: c.addresses.fPoolManager!.toLowerCase() } });
2072
+ const rows = await poolHolders(indexer, { condition: { side: "F", poolId: poolIdHex.toLowerCase(), gen: Number(gen), manager: c.addresses.managerF.toLowerCase() } });
2105
2073
  return rows
2106
2074
  .filter((r) => r.balance > 0n)
2107
2075
  .map((r) => ({ holder: r.holder, shares: r.balance }))
@@ -2111,7 +2079,7 @@ export async function fPoolShareHolders(
2111
2079
  }
2112
2080
  }
2113
2081
  const id = fPoolShareId(poolIdHex, gen);
2114
- const { logs } = await getEventLogs(c, { indexer: opts.indexer, address: c.addresses.fPoolManager!, event: ev, args: { id }, fromBlock: opts.fromBlock });
2082
+ const { logs } = await getEventLogs(c, { indexer: opts.indexer, address: c.addresses.managerF, event: ev, args: { id }, fromBlock: opts.fromBlock });
2115
2083
  const bal = new Map<string, bigint>();
2116
2084
  for (const l of logs) {
2117
2085
  const a = l.args as { from: Address; to: Address; amount: bigint };
@@ -2136,14 +2104,14 @@ export interface FPolicyTerms {
2136
2104
  carried: Address;
2137
2105
  }
2138
2106
 
2139
- /** Every F pool's raw state in one lens call (the manager's `Pool` struct: quote, swapFee, policy, seeded, gen, n, restructureTime, asks, lnCapOverSeed, Q, realizedVariance, L, shares, refLogFloor). */
2107
+ /** Every F pool's raw state in one lens call (the manager's `Pool` struct: quote, swapFee, restructureTime, flags, policy, seeded, gen, n, lnCapOverSeed, Q, realizedVariance, L, shares, refLogFloor, operator, mintFee). */
2140
2108
  export async function getFPoolsRaw(c: LogswapClient, poolIds: Hex[]): Promise<readonly unknown[]> {
2141
- const { lensAbi } = await import("./generated.js");
2142
- return (await c.public.readContract({ address: c.addresses.lens, abi: lensAbi, functionName: "getFPools", args: [poolIds] } as never)) as readonly unknown[];
2109
+ const { lensFAbi } = await import("./generated.js");
2110
+ return (await c.public.readContract({ address: c.addresses.lensF, abi: lensFAbi, functionName: "getPools", args: [poolIds] } as never)) as readonly unknown[];
2143
2111
  }
2144
2112
 
2145
2113
  /** Share value from the lens — (L + Q)/shares, WAD per share — the same figure as `fPoolShareValue`, from one source. */
2146
2114
  export async function shareValueOnChain(c: LogswapClient, poolId: Hex): Promise<bigint> {
2147
- const { lensAbi } = await import("./generated.js");
2148
- return (await c.public.readContract({ address: c.addresses.lens, abi: lensAbi, functionName: "shareValue", args: [poolId] } as never)) as bigint;
2115
+ const { lensFAbi } = await import("./generated.js");
2116
+ return (await c.public.readContract({ address: c.addresses.lensF, abi: lensFAbi, functionName: "shareValue", args: [poolId] } as never)) as bigint;
2149
2117
  }