@logswap/sdk 0.5.79 → 0.5.81

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/src/fpool.ts CHANGED
@@ -52,6 +52,7 @@ import { fallBackUnlessRejected, signerFor } from "./write.js";
52
52
  import { getEventLogs } from "./history.js";
53
53
  import { poolHolders } from "./views.js";
54
54
  import { presetMintFee } from "./positions.js";
55
+ import { isValidMintFee, MINT_FEE_MAX } from "./keys.js";
55
56
 
56
57
  const WAD = 10n ** 18n;
57
58
  const ZERO_ADDRESS = "0x0000000000000000000000000000000000000000" as const;
@@ -76,7 +77,7 @@ export interface FPoolState {
76
77
  L: bigint;
77
78
  /** The swap fee, WAD (`phi` before F version 25, decisions 059). 0 is no fee (F version 26, decisions 065), admitted only if the policy lists it. */
78
79
  swapFee: bigint;
79
- /** The pool's mint fee, WAD of newly-minted L: proposed at birth, the policy's answer from its menu (F version 26, decisions 065). */
80
+ /** The pool's mint fee, WAD of newly-minted L: the creator-selected key field, fixed for life (F 38, decision 078): `2 * swapFee <= mintFee <= MINT_FEE_MAX`. */
80
81
  mintFee: bigint;
81
82
  /** θ₀, the reference log floor: where the floor stood at the seed (re-based by a capital harvest and at each step); income is counted from it. `theta0` before F version 25. */
82
83
  refLogFloor: bigint;
@@ -87,13 +88,13 @@ export interface FPoolState {
87
88
  /** This generation's income still in the pool, quote: L·(θ₀ − θ). */
88
89
  unharvested: bigint;
89
90
  /**
90
- * The common cap as a log distance (decisions 061): ln(cap price / floor price) in 1e-6 log units,
91
- * the key's `lnCapOverFloor`; 0 is uncapped (cap ∞). Leverage at the floor is 1/(1 − e^{−value}):
92
- * {@link fPoolLeverageOfCap}.
91
+ * The pool's one cap as a log ratio (decisions 061, 075): ln(cap price / seed price) in 1e-6 log units, set by the
92
+ * generation's `deployLiquidity`; each asset's maximum price is its own seed price times it. 0 is uncapped (cap ∞).
93
+ * The liquidity per unit of base value is 1/(1 − e^{−value}): {@link fPoolLeverageOfCap}.
93
94
  */
94
- lnCapOverFloor: number;
95
+ lnCapOverSeed: number;
95
96
  /** Σ = ∫ Σ_j w_j (dx_j)², accrued even though the fee is fixed — the kernel stays calculable. */
96
- bigSigma: bigint;
97
+ realizedVariance: bigint;
97
98
  /**
98
99
  * The pool's policy: the contract the key names, holding the pool's roles
99
100
  * and answering every question the manager does not decide itself. Read its roles with
@@ -108,12 +109,13 @@ export interface FPoolState {
108
109
  restructureTime: number;
109
110
  /** What the pool is — its POLICY's self-description; see {@link FPoolKind}. */
110
111
  kind: FPoolKind;
111
- /** False before the first seed — and between a retire and the next one. */
112
+ /** False before the first `deployLiquidity` — and between a `close` and the next one. */
112
113
  seeded: boolean;
113
114
  /**
114
- * The live GENERATION. Every retire freezes one into a bundle its shares redeem
115
- * ({@link fPoolRedeem}) and opens the next; since F version 21 so does every `regenerate`
116
- * (the generation step, {@link fPoolRegenerate}): the carried holder and the dead shares go on
115
+ * The live GENERATION. Every `close` freezes one into a bundle its shares redeem
116
+ * ({@link fPoolRedeem}) and opens the next; so does every `regenerate`
117
+ * (the generation step, {@link fPoolRegenerate}) and every live-pool `deployLiquidity`
118
+ * ({@link fPoolDeploy}): the carried holder and the dead shares go on
117
119
  * as `gen + 1`, every other holder of `gen` is frozen out into its bundle. The share id carries
118
120
  * it ({@link fPoolShareId}), so generations `0 … gen-1` are claims ({@link fPoolClaimsOf}) and
119
121
  * `gen` is the pool. On a pad, `gen` is the graduation count — the rung.
@@ -162,9 +164,9 @@ export async function getFPool(c: LogswapClient, poolId: Hex): Promise<FPoolStat
162
164
  return {
163
165
  poolId,
164
166
  quote: p.quote,
165
- bases: v.legs.map((l) => l.base),
166
- weights: v.legs.map((l) => l.weight),
167
- x: v.legs.map((l) => l.x), // derived by the manager: x_j = ln(w_j·L / R̃_j)
167
+ bases: v.baseLegs.map((l) => l.base),
168
+ weights: v.baseLegs.map((l) => l.weight),
169
+ x: v.baseLegs.map((l) => l.x), // derived by the manager: x_j = ln(w_j·L / R̃_j)
168
170
  Q: p.Q,
169
171
  L: p.L,
170
172
  swapFee: p.swapFee,
@@ -173,8 +175,8 @@ export async function getFPool(c: LogswapClient, poolId: Hex): Promise<FPoolStat
173
175
  logFloor: v.logFloor,
174
176
  compositeX: v.compositeX,
175
177
  unharvested: v.unharvested,
176
- lnCapOverFloor: Number(p.lnCapOverFloor),
177
- bigSigma: p.bigSigma,
178
+ lnCapOverSeed: Number(p.lnCapOverSeed),
179
+ realizedVariance: p.realizedVariance,
178
180
  policy: p.policy,
179
181
  asks: Number(p.asks),
180
182
  name,
@@ -183,9 +185,9 @@ export async function getFPool(c: LogswapClient, poolId: Hex): Promise<FPoolStat
183
185
  seeded: p.seeded,
184
186
  gen: Number(p.gen),
185
187
  totalSupply: p.shares,
186
- reserves: v.legs.map((l) => l.reserve), // the state
187
- virtualReserves: v.legs.map((l) => l.virtualReserve),
188
- kappa: v.legs.map((l) => l.kappa),
188
+ reserves: v.baseLegs.map((l) => l.reserve), // the state
189
+ virtualReserves: v.baseLegs.map((l) => l.virtualReserve),
190
+ kappa: v.baseLegs.map((l) => l.kappa),
189
191
  };
190
192
  }
191
193
 
@@ -260,14 +262,21 @@ export interface FPoolRoles {
260
262
  authority: Address;
261
263
  /** The proposed next authority, until it accepts — zero when nothing is pending. */
262
264
  pendingAuthority: Address;
265
+ /** The desk's optional pool operator (decision 073): one delegate besides the authority, zero when none. */
263
266
  operator: Address;
264
- pendingOperator: Address;
265
267
  gateMint: boolean;
266
- gateSwap: boolean;
268
+ /** The desk's swap admission (decision 073): open to all, listed takers/minters only, or one cached executor. */
269
+ swapMode: FPoolSwapMode;
270
+ /** The executor in `executor` mode, zero otherwise. */
271
+ swapExecutor: Address;
267
272
  /** The policy's own ceiling on a harvest now — the bid ({@link FPoolDescription.harvestable}) narrowed by the policy's rule. */
268
273
  maxHarvest: bigint;
269
274
  }
270
275
 
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"];
279
+
271
280
  /** Read a pool's roles from its policy. `state` saves the `getPool` round trip when already in hand. */
272
281
  export async function getFPoolRoles(c: LogswapClient, poolId: Hex, state?: Pick<FPoolState, "policy" | "kind">): Promise<FPoolRoles> {
273
282
  const s = state ?? (await getFPool(c, poolId));
@@ -280,15 +289,11 @@ export async function getFPoolRoles(c: LogswapClient, poolId: Hex, state?: Pick<
280
289
  rdPolicy<bigint>(fPolicyBaseAbi, "maxHarvest"),
281
290
  ]);
282
291
  const desk = s.kind === "private";
283
- const [operator, pendingOperator, gateMint, gateSwap] = desk
284
- ? await Promise.all([
285
- rdPolicy<Address>(privatePolicyAbi, "operator"),
286
- rdPolicy<Address>(privatePolicyAbi, "pendingOperator"),
287
- rdPolicy<boolean>(privatePolicyAbi, "gateMint"),
288
- rdPolicy<boolean>(privatePolicyAbi, "gateSwap"),
289
- ])
290
- : [ZERO_ADDRESS, ZERO_ADDRESS, false, false];
291
- return { policy: s.policy, creator, authority, pendingAuthority, operator, pendingOperator, gateMint, gateSwap, maxHarvest };
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 };
292
297
  }
293
298
 
294
299
  /** 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. */
@@ -309,27 +314,27 @@ export interface FPoolDescription {
309
314
  /**
310
315
  * The most a harvest may take now by the MANAGER's rule: the bid, `Q` once seeded (0 before).
311
316
  * The manager's `harvestable()` getter was cut in F version 21; this is the same number, read
312
- * off `getPool`. The policy may allow less (a pad: the income; a POL: above `keepQuote`) —
317
+ * off `getPool`. The policy may allow less (a pad: the income; a POL: above `minQuoteRatio`·L) —
313
318
  * {@link FPoolRoles.maxHarvest}.
314
319
  */
315
320
  harvestable: bigint;
316
- /** The dead shares' banked dividend — a pad's pot, the creator's income until a rung is climbed. */
317
- pot: bigint;
321
+ /** The dead shares' banked dividend — a pad's income, the creator's until a rung is climbed (decision 085: formerly the pot). */
322
+ income: bigint;
318
323
  }
319
324
 
320
325
  export async function describeFPool(c: LogswapClient, s: FPoolState): Promise<FPoolDescription> {
321
- // an unseeded pool has no L: nothing earned, nothing to harvest, no pot. The bid is the
326
+ // an unfunded pool has no L: nothing earned, nothing to harvest, no income. The bid is the
322
327
  // manager's ceiling (`harvestable()` until F version 21, which cut the getter): Q once seeded.
323
328
  const harvestable = s.L > 0n ? s.Q : 0n;
324
329
  const unharvested = s.L > 0n ? s.unharvested : 0n;
325
- const pot = s.L > 0n ? await fPoolDividendOf(c, s.poolId, DEAD_ADDRESS, s.gen) : 0n;
330
+ const income = s.L > 0n ? await fPoolDividendOf(c, s.poolId, DEAD_ADDRESS, s.gen) : 0n;
326
331
  return {
327
332
  shape: s.kind === "pad" ? "launch": "basket", // the kind, not n = 1
328
333
  legs: s.bases.length,
329
334
  atFloor: s.Q === 0n,
330
335
  unharvested,
331
336
  harvestable,
332
- pot,
337
+ income,
333
338
  };
334
339
  }
335
340
 
@@ -346,7 +351,7 @@ export function fPoolPriceOf(x: bigint, scale = 1): number {
346
351
  export function fPoolShareValue(s: FPoolState): bigint {
347
352
  if (s.totalSupply === 0n) return 0n;
348
353
  let v = s.L + s.Q;
349
- if (s.lnCapOverFloor !== 0) {
354
+ if (s.lnCapOverSeed !== 0) {
350
355
  v = s.Q;
351
356
  for (let j = 0; j < s.reserves.length; j++) {
352
357
  const rv = s.virtualReserves[j]!;
@@ -597,7 +602,7 @@ export async function fPoolPreviewRollIn(
597
602
 
598
603
  /**
599
604
  * Remove quote, lifting θ — price-neutral, no base moves, and a DIVIDEND to
600
- * every share: the amount goes into the pool's pot and each holder's slice is settled lazily on
605
+ * every share: the amount goes into the pool's held income and each holder's slice is settled lazily on
601
606
  * their next transfer, mint or burn, or pulled with {@link fPoolClaim}. The sponsor's own slice —
602
607
  * its shares' and the locked seed's at 0xdead — is pushed to `to` at once. On a pad
603
608
  * the lift stops at the seed floor θ₀ (income only); nothing else bounds it — an
@@ -670,7 +675,7 @@ export async function fPoolLienOf(c: LogswapClient, poolId: Hex, owner: Address,
670
675
  */
671
676
  export async function fPoolLock(c: LogswapClient, a: { poolId: Hex; owner: Address; amount: bigint; gen?: bigint | number; account: Address }) {
672
677
  const g = a.gen ?? (await fPoolGen(c, a.poolId));
673
- return writeFPool0(c, "lock", [fPoolShareId(a.poolId, g), a.owner, a.amount], a.account);
678
+ return writeFPool0(c, "lienLock", [fPoolShareId(a.poolId, g), a.owner, a.amount], a.account);
674
679
  }
675
680
 
676
681
  /**
@@ -683,7 +688,7 @@ export async function fPoolUnlock(
683
688
  a: { poolId: Hex; owner: Address; amount: bigint; to: Address; gen?: bigint | number; account: Address },
684
689
  ) {
685
690
  const g = a.gen ?? (await fPoolGen(c, a.poolId));
686
- return writeFPool0(c, "unlock", [fPoolShareId(a.poolId, g), a.owner, a.amount, a.to], a.account);
691
+ return writeFPool0(c, "lienUnlock", [fPoolShareId(a.poolId, g), a.owner, a.amount, a.to], a.account);
687
692
  }
688
693
 
689
694
  /** Bank the owner's pending into the lien now — `unlock(id, owner, 0, owner)`: dividends bank lazily. The locker's. */
@@ -997,28 +1002,16 @@ function findQuoteResult(err: unknown): bigint | null {
997
1002
 
998
1003
  export interface FPoolCreateArgs {
999
1004
  quote: Address;
1000
- /** Legs in any order; sorted (with weights and marks kept aligned) before the call. */
1005
+ /** The pool's assets, in any order; sorted into the key's canonical order before the call. The set is fixed for the pool's life. */
1001
1006
  bases: Address[];
1002
- /** WAD each; must sum to 1e18 — validated here so the revert is readable. */
1003
- weights: bigint[];
1004
- /** The swap fee, WAD (`phi` before F version 25). The base-for-base fee is pinned at 2φ on-chain. A curated policy admits only its listed tiers (decisions 059). */
1007
+ /** The swap fee, WAD. The base-for-base fee is pinned at 2φ on-chain. A curated policy admits only its listed tiers (decisions 059). */
1005
1008
  swapFee: bigint;
1006
1009
  /**
1007
- * The pool's mint fee, WAD of newly-minted L — the creator's pick from the policy's menu (F version
1008
- * 26, decisions 065; a curated menu refuses anything else with `MintFeeNotListed`). Defaults to
1009
- * {@link presetMintFee}: twice the swap fee, capped at `FEE_MAX`.
1010
+ * The pool's mint fee, WAD of newly-minted L — the creator's pick, a key field fixed for life (F 38, decision
1011
+ * 078): `2 * swapFee <= mintFee <= MINT_FEE_MAX`, checked by the manager (`BadParam`). Defaults to
1012
+ * {@link presetMintFee}: twice the swap fee.
1010
1013
  */
1011
1014
  mintFee?: bigint;
1012
- /**
1013
- * The common cap as a log distance (decisions 061): ln(cap price / floor price) in 1e-6 log units,
1014
- * the key's `lnCapOverFloor`; 0 or absent is uncapped (cap ∞). Pass `lnCapOverFloor` or `leverage`, not both.
1015
- */
1016
- lnCapOverFloor?: number;
1017
- /**
1018
- * The leverage at the floor λ (decisions 061), converted to `lnCapOverFloor` by {@link fPoolCapOfLeverage}:
1019
- * 1 is uncapped (cap ∞, `lnCapOverFloor` 0), 2 puts the cap at twice the floor price.
1020
- */
1021
- leverage?: number;
1022
1015
  /**
1023
1016
  * Which of the protocol's four the pool is — see {@link FPoolKind}. NOT a key field (decisions
1024
1017
  * 049: the manager knows no kind): it selects the deployment's policy of that kind when `policy`
@@ -1066,25 +1059,23 @@ export function sortFPoolLegs<T>(bases: Address[], ...companions: T[][]): { base
1066
1059
  return { bases: idx.map((i) => bases[i]!), companions: companions.map((arr) => idx.map((i) => arr[i]!)) };
1067
1060
  }
1068
1061
 
1069
- /** The key as the manager hashes it: legs sorted, the kind's policy filled in when none is named; no kind in it (049). */
1070
1062
  /**
1071
1063
  * The tuple an F pool's id hashes — `src/types/FPoolKey.sol`, field order load-bearing (it is
1072
1064
  * the ABI encoding order). Stored by the manager at `initialize` and never in calldata again,
1073
- * except `PolicyRegistry.migrate` (F version 20), which is handed it to check against the id.
1065
+ * except `PolicyRegistry.migrate`, which is handed it to check against the id. Since F 38 it holds no weights and no
1066
+ * cap: those belong to a generation's `deployLiquidity` (decision 075), and the mint fee is part of identity (078).
1074
1067
  */
1075
1068
  export interface FPoolKey {
1076
1069
  quote: Address;
1077
- /** Sorted ascending, unique. */
1070
+ /** Sorted ascending, unique; fixed for the pool's life. */
1078
1071
  bases: Address[];
1079
- /** WAD, aligned with `bases`, summing to 1e18. */
1080
- weights: bigint[];
1081
1072
  swapFee: bigint;
1082
1073
  /** The policy AT BIRTH — not the live one after a move. */
1083
1074
  policy: Address;
1084
1075
  creator: Address;
1085
1076
  salt: Hex;
1086
- /** The common cap as ln(cap price / floor price), in 1e-6 log units; 0 uncapped, cap ∞ (decisions 061). Appended in F version 25 as `cap`; renamed in F version 27 (no id moved). */
1087
- lnCapOverFloor: number;
1077
+ /** The creator-selected mint fee, WAD, fixed for life: `2 * swapFee <= mintFee <= MINT_FEE_MAX`. */
1078
+ mintFee: bigint;
1088
1079
  }
1089
1080
 
1090
1081
  const F_POOL_KEY_ABI = [
@@ -1093,12 +1084,11 @@ const F_POOL_KEY_ABI = [
1093
1084
  components: [
1094
1085
  { name: "quote", type: "address" },
1095
1086
  { name: "bases", type: "address[]" },
1096
- { name: "weights", type: "uint256[]" },
1097
1087
  { name: "swapFee", type: "uint256" },
1098
1088
  { name: "policy", type: "address" },
1099
1089
  { name: "creator", type: "address" },
1100
1090
  { name: "salt", type: "bytes32" },
1101
- { name: "lnCapOverFloor", type: "uint24" },
1091
+ { name: "mintFee", type: "uint256" },
1102
1092
  ],
1103
1093
  },
1104
1094
  ] as const;
@@ -1107,37 +1097,38 @@ const F_POOL_KEY_ABI = [
1107
1097
  * An F pool's id: `keccak256(abi.encode(key))`, offline — what `initialize` computes inline. The
1108
1098
  * manager's `idOf(FPoolKey)` getter was cut in F version 21; this is the same hash (checked
1109
1099
  * against Foundry's encoder and the local deployment's pools in the tests). The key must be the
1110
- * one the pool was initialized with: legs sorted ({@link fPoolKeyOf} sorts them), the birth policy.
1100
+ * one the pool was initialized with: bases sorted ({@link fPoolKeyOf} sorts them), the birth policy.
1111
1101
  */
1112
1102
  export function fPoolIdOfKey(key: FPoolKey): Hex {
1113
1103
  return keccak256(encodeAbiParameters(F_POOL_KEY_ABI, [key]));
1114
1104
  }
1115
1105
 
1106
+ /** The key as the manager hashes it: bases sorted, the kind's policy filled in when none is named, the mint fee preset when none is given. No kind in it (049). */
1116
1107
  export function fPoolKeyOf(c: LogswapClient, a: Omit<FPoolCreateArgs, "account">): FPoolKey {
1117
- const { bases, companions } = sortFPoolLegs(a.bases, a.weights);
1108
+ const { bases } = sortFPoolLegs(a.bases);
1118
1109
  return {
1119
1110
  quote: a.quote,
1120
1111
  bases,
1121
- weights: companions[0]!,
1122
1112
  swapFee: a.swapFee,
1123
1113
  policy: a.policy ?? fPoolPolicyFor(c, a.kind),
1124
1114
  creator: a.creator,
1125
1115
  salt: a.salt ?? ZERO_SALT,
1126
- lnCapOverFloor: fPoolCapOfArgs(a),
1116
+ mintFee: a.mintFee ?? presetMintFee(a.swapFee),
1127
1117
  };
1128
1118
  }
1129
1119
 
1130
- /** Create the pool (no funds move — `seed` arms it). Returns the tx hash; read the id with `fPoolIdOf`. */
1120
+ /** Create the pool (no funds move — `deployLiquidity` funds it). Returns the tx hash; read the id with `fPoolIdOf`. */
1131
1121
  export async function fPoolInitialize(c: LogswapClient, a: FPoolCreateArgs) {
1132
- const sum = a.weights.reduce((x, y) => x + y, 0n);
1133
- if (sum !== 10n ** 18n) throw new Error(`logswap: weights sum to ${sum}, expected 1e18`);
1134
1122
  const key = fPoolKeyOf(c, a);
1123
+ if (!isValidMintFee(key.swapFee, key.mintFee)) {
1124
+ throw new Error(`logswap: mint fee ${key.mintFee} is outside 2 × the swap fee (${2n * key.swapFee}) … ${MINT_FEE_MAX}`);
1125
+ }
1135
1126
  const wallet = requireWallet(c);
1136
1127
  const { request } = await c.public.simulateContract({
1137
1128
  address: c.addresses.fPoolManager!,
1138
1129
  abi: fPoolManagerAbi,
1139
1130
  functionName: "initialize",
1140
- args: [key, a.mintFee ?? presetMintFee(a.swapFee)],
1131
+ args: [key],
1141
1132
  account: wallet.account,
1142
1133
  } as never);
1143
1134
  return c.wallet!.writeContract(request as never);
@@ -1164,21 +1155,20 @@ export async function fPoolKeyOfPool(c: LogswapClient, poolId: Hex, opts: { salt
1164
1155
  const { logs } = await getEventLogs(c, { indexer: opts.indexer, address: c.addresses.fPoolManager!, event: ev as never, args: { poolId }, fromBlock: opts.fromBlock });
1165
1156
  const l = logs[0];
1166
1157
  if (!l) throw new Error(`logswap: no PoolCreated for F pool ${poolId}`);
1167
- const a = l.args as unknown as { quote: Address; creator: Address; bases: readonly Address[]; weights: readonly bigint[]; swapFee: bigint; policy: Address; lnCapOverFloor?: number | bigint; cap?: number | bigint };
1158
+ const a = l.args as unknown as { quote: Address; creator: Address; bases: readonly Address[]; swapFee: bigint; policy: Address; mintFee: bigint };
1168
1159
  const key: FPoolKey = {
1169
1160
  quote: a.quote,
1170
1161
  bases: [...a.bases],
1171
- weights: [...a.weights],
1172
1162
  swapFee: a.swapFee,
1173
1163
  policy: a.policy,
1174
1164
  creator: a.creator,
1175
1165
  salt: opts.salt ?? ZERO_SALT,
1176
- lnCapOverFloor: Number(a.lnCapOverFloor ?? a.cap ?? 0), // `cap` before F version 27
1166
+ mintFee: a.mintFee,
1177
1167
  };
1178
1168
  if (fPoolIdOfKey(key).toLowerCase() !== poolId.toLowerCase() && opts.salt === undefined) {
1179
1169
  // a pad's salt carries its split (decisions 056): rebuild it from the policy's record with the default nonce
1180
1170
  try {
1181
- const [creatorShare] = (await c.public.readContract({ address: a.policy, abi: padPolicyAbi, functionName: "splitOf", args: [poolId] } as never)) as readonly [bigint, bigint];
1171
+ const creatorShare = BigInt((await c.public.readContract({ address: a.policy, abi: padPolicyAbi, functionName: "creatorShareOf", args: [poolId] } as never)) as bigint | number);
1182
1172
  const padKey = { ...key, salt: padSalt({ creatorShare }) };
1183
1173
  if (fPoolIdOfKey(padKey).toLowerCase() === poolId.toLowerCase()) return padKey;
1184
1174
  } catch {
@@ -1192,35 +1182,32 @@ export async function fPoolKeyOfPool(c: LogswapClient, poolId: Hex, opts: { salt
1192
1182
  }
1193
1183
 
1194
1184
  /**
1195
- * The reserve a leg holds at a mark: `R = Lj·e^{−x}`, WAD math. The seed names RESERVES —
1196
- * the sponsor states holdings and the price follows, `p = Lj / R` — so this is
1197
- * the one conversion from a price to what the pool will hold, done here, on the way in. Float
1198
- * precision (~1e-16 relative) is what a seed needs: any reserve is a legal seed, and the mark
1185
+ * The reserve a leg holds at a mark: `R = Lj·e^{−x}`, WAD math. A deployment names the TOTAL base
1186
+ * reserve and the price that values it, and the price follows from the pair, `p = Lj / R` — so this is
1187
+ * the one conversion from a wanted mark to what the pool will hold, done here, on the way in. Float
1188
+ * precision (~1e-16 relative) is what a deployment needs: any reserve is legal, and the mark
1199
1189
  * the pool derives from it is the one the sponsor meant to within that.
1200
1190
  */
1201
1191
  export function fPoolReserveAt(Lj: bigint, x: bigint, k = 0): bigint {
1202
- // on a capped pool (decisions 061) the mark reads the virtual reserve R̃ = R + c, and the seed
1203
- // puts c = R·k/(1 − k): so the REAL reserve for a mark is L_j·e^{−x}·(1 − k)
1192
+ // on a capped pool (decisions 061) the mark reads the virtual reserve R̃ = R + c, and the
1193
+ // deployment puts c = R·k/(1 − k): so the REAL reserve for a mark is L_j·e^{−x}·(1 − k)
1204
1194
  const e = Math.exp(-Number(x) / 1e18) * (1 - k);
1205
1195
  return (Lj * BigInt(Math.round(e * 1e18))) / 10n ** 18n;
1206
1196
  }
1207
1197
 
1208
1198
  /**
1209
- * The seed's cap constant k = e^{Q0/L0 − d} (decisions 061): every leg's phantom is c_j = r_j·k/(1 − k).
1210
- * 0 on an uncapped pool. Throws when the seed would be priced at or above its cap (Q0/L0 ≥ d), which
1211
- * the manager refuses.
1199
+ * The cap constant k = e^{−lnCapOverSeed} (decisions 061, 075): every leg's phantom is c_j = r_j·k/(1 − k), and the
1200
+ * generation's liquidity is its base value over 1 − k. 0 on an uncapped pool. It no longer depends on the bid:
1201
+ * the cap is a ratio of the cap price to each asset's own seed price.
1212
1202
  */
1213
- export function fPoolCapK(lnCapOverFloor: number, Q0: bigint, L0: bigint): number {
1214
- if (lnCapOverFloor === 0) return 0;
1215
- const e = Number((Q0 * WAD) / L0) / 1e18 - lnCapOverFloor / 1e6;
1216
- if (e >= 0) throw new Error(`logswap: a seed with Q0/L0 = ${Number((Q0 * WAD) / L0) / 1e18} is at or above its cap, ln(cap/floor) = ${lnCapOverFloor / 1e6}`);
1217
- return Math.exp(e);
1203
+ export function fPoolCapK(lnCapOverSeed: number): number {
1204
+ return lnCapOverSeed === 0 ? 0 : Math.exp(-lnCapOverSeed / 1e6);
1218
1205
  }
1219
1206
 
1220
1207
  /**
1221
- * The key's `lnCapOverFloor` = ln(cap/floor) (1e-6 log units) for a leverage λ at the floor: ln(λ/(λ − 1))
1222
- * (decisions 061), so λ = 1/(1 − floor/cap) and the cap sits λ/(λ − 1) × the floor — λ = 2 puts it at twice.
1223
- * **λ = 1 is uncapped**: cap ∞, `lnCapOverFloor` 0. A λ under 1, or one so close to
1208
+ * The pool's `lnCapOverSeed` = ln(cap price / seed price) (1e-6 log units) for a leverage λ: ln(λ/(λ − 1))
1209
+ * (decisions 061), so λ = 1/(1 − seed/cap) = L / (base value) and the cap sits λ/(λ − 1) × the seed price — λ = 2
1210
+ * puts it at twice. **λ = 1 is uncapped**: cap ∞, `lnCapOverSeed` 0. A λ under 1, or one so close to
1224
1211
  * 1 (or so large) that d leaves a uint24 of 1e-6 units, is refused.
1225
1212
  */
1226
1213
  export function fPoolCapOfLeverage(lambda: number): number {
@@ -1231,102 +1218,182 @@ export function fPoolCapOfLeverage(lambda: number): number {
1231
1218
  return d;
1232
1219
  }
1233
1220
 
1234
- /** The leverage at the floor λ = 1/(1 − e^{−x}) for x = `lnCapOverFloor` (1e-6 log units); 1 for an uncapped pool (cap ∞). */
1235
- export function fPoolLeverageOfCap(lnCapOverFloor: number): number {
1236
- return lnCapOverFloor === 0 ? 1 : 1 / (1 - Math.exp(-lnCapOverFloor / 1e6));
1221
+ /** The leverage λ = 1/(1 − e^{−x}) for x = `lnCapOverSeed` (1e-6 log units); 1 for an uncapped pool (cap ∞). */
1222
+ export function fPoolLeverageOfCap(lnCapOverSeed: number): number {
1223
+ return lnCapOverSeed === 0 ? 1 : 1 / (1 - Math.exp(-lnCapOverSeed / 1e6));
1237
1224
  }
1238
1225
 
1239
- /** A pool's leverage, ready to tag: `capped` false and `capOverFloor` Infinity for an uncapped pool. */
1226
+ /** A pool's leverage, ready to tag: `capped` false and `capOverSeed` Infinity for an uncapped pool. */
1240
1227
  export interface FPoolLeverage {
1241
- /** λ at the floor; exactly 1 when uncapped. */
1228
+ /** λ at the seed; exactly 1 when uncapped. */
1242
1229
  lambda: number;
1243
1230
  capped: boolean;
1244
- /** The cap's price over the floor's, e^d = λ/(λ − 1): 2 at λ = 2; Infinity when uncapped. */
1245
- capOverFloor: number;
1231
+ /** The cap's price over the seed's, e^d = λ/(λ − 1): 2 at λ = 2; Infinity when uncapped. */
1232
+ capOverSeed: number;
1246
1233
  /** "1×" uncapped; otherwise λ to two decimals, trailing zeros dropped ("2×", "1.5×"), never "1×" for a capped pool ("1.01×" at least shown as "≈1×"). */
1247
1234
  label: string;
1248
1235
  }
1249
1236
 
1250
1237
  /**
1251
- * The leverage tag of a pool from its key's `lnCapOverFloor` (decisions 061): `1×` means no cap — the only way a tag
1238
+ * The leverage tag of a pool from its `lnCapOverSeed` (decisions 061): `1×` means no cap — the only way a tag
1252
1239
  * reads 1× — and a capped pool always reads above it, so the two can never be confused on screen.
1253
1240
  */
1254
- export function fPoolLeverage(lnCapOverFloor: number): FPoolLeverage {
1255
- if (lnCapOverFloor === 0) return { lambda: 1, capped: false, capOverFloor: Infinity, label: "1×" };
1256
- const lambda = fPoolLeverageOfCap(lnCapOverFloor);
1241
+ export function fPoolLeverage(lnCapOverSeed: number): FPoolLeverage {
1242
+ if (lnCapOverSeed === 0) return { lambda: 1, capped: false, capOverSeed: Infinity, label: "1×" };
1243
+ const lambda = fPoolLeverageOfCap(lnCapOverSeed);
1257
1244
  const rounded = Math.round(lambda * 100) / 100;
1258
1245
  const label = rounded <= 1 ? "≈1×" : `${String(rounded)}×`;
1259
- return { lambda, capped: true, capOverFloor: Math.exp(lnCapOverFloor / 1e6), label };
1246
+ return { lambda, capped: true, capOverSeed: Math.exp(lnCapOverSeed / 1e6), label };
1260
1247
  }
1261
1248
 
1262
- /** The key's `lnCapOverFloor` from creation args: as given, else from `leverage`, else 0 (uncapped, cap ∞). Both given and disagreeing is refused. */
1263
- export function fPoolCapOfArgs(a: { lnCapOverFloor?: number; leverage?: number }): number {
1249
+ /** The `lnCapOverSeed` from deployment args: as given, else from `leverage`, else 0 (uncapped, cap ∞). Both given and disagreeing is refused. */
1250
+ export function fPoolCapOfArgs(a: { lnCapOverSeed?: number; leverage?: number }): number {
1264
1251
  const fromLeverage = a.leverage === undefined ? undefined : fPoolCapOfLeverage(a.leverage);
1265
- if (a.lnCapOverFloor !== undefined && fromLeverage !== undefined && a.lnCapOverFloor !== fromLeverage)
1266
- throw new Error(`logswap: lnCapOverFloor ${a.lnCapOverFloor} and leverage ${a.leverage} (${fromLeverage}) disagree — pass one`);
1267
- return a.lnCapOverFloor ?? fromLeverage ?? 0;
1252
+ if (a.lnCapOverSeed !== undefined && fromLeverage !== undefined && a.lnCapOverSeed !== fromLeverage)
1253
+ throw new Error(`logswap: lnCapOverSeed ${a.lnCapOverSeed} and leverage ${a.leverage} (${fromLeverage}) disagree — pass one`);
1254
+ return a.lnCapOverSeed ?? fromLeverage ?? 0;
1268
1255
  }
1269
1256
 
1270
1257
  /**
1271
- * Arm the pool: deposit `r0[j]` of each base plus `Q0` of quote against exposure `L0`. Pass either
1272
- * the reserves outright (`r0`) or the marks the pool should open at (`x0`, converted here with
1273
- * {@link fPoolReserveAt} against the key's weights). Authority-only on-chain (an open seed lets
1274
- * anyone front-run the creator for the strike). Arrays align with the SORTED bases — use
1275
- * {@link sortFPoolLegs} on (bases, weights, x0) together when building forms.
1258
+ * One entry of `deployLiquidity`'s input (F 38, decision 084): the TOTAL base reserve the asset has after the call
1259
+ * (0 leaves it out) and the price that values it, quote atomic units per base atomic unit, 1e36-scaled.
1276
1260
  */
1277
- export async function fPoolSeed(
1261
+ export interface BaseAsset {
1262
+ base: Address;
1263
+ amount: bigint;
1264
+ priceX36: bigint;
1265
+ }
1266
+
1267
+ /** The book a deployment names, from the sponsor's terms: weights, total liquidity `L0`, and either the wanted marks `x0` or the reserves `r0`. */
1268
+ export type FPoolBookSpec = {
1269
+ /** The pool's assets, in any order; the result is sorted into the key's order. */
1270
+ bases: Address[];
1271
+ /** WAD, one per asset, summing to 1e18; 0 leaves the asset out (not in generation 0). `L_j = w_j · L0`. */
1272
+ weights: bigint[];
1273
+ /** The book's total liquidity, quote units. */
1274
+ L0: bigint;
1275
+ /** The pool's one cap, or the leverage it stands for; absent is uncapped. */
1276
+ lnCapOverSeed?: number;
1277
+ leverage?: number;
1278
+ } & ({ x0: bigint[] } | { r0: bigint[] });
1279
+
1280
+ /**
1281
+ * The `baseAssets` (and cap) a deployment sends for a wanted book — what the old seed did with reserves and
1282
+ * marks, as the amounts and prices the manager takes now. Per asset: the reserve `r_j` (given as `r0`, or
1283
+ * {@link fPoolReserveAt} the wanted mark `x0`) and the price that makes its value `L_j · (1 − k)`:
1284
+ * `priceX36 = ceil(L_j(1 − k) · 1e36 / r_j)`. A zero weight is an asset left out. Sorted by base address, the
1285
+ * key's order, with the companions carried along.
1286
+ */
1287
+ export function fPoolBook(a: FPoolBookSpec): { baseAssets: BaseAsset[]; lnCapOverSeed: number } {
1288
+ const sum = a.weights.reduce((x, y) => x + y, 0n);
1289
+ if (sum !== WAD) throw new Error(`logswap: weights sum to ${sum}, expected 1e18`);
1290
+ if (a.weights.length !== a.bases.length) throw new Error(`logswap: ${a.weights.length} weights for ${a.bases.length} assets`);
1291
+ const lnCapOverSeed = fPoolCapOfArgs(a);
1292
+ const k = fPoolCapK(lnCapOverSeed);
1293
+ const oneMinusK = BigInt(Math.round((1 - k) * 1e18));
1294
+ const rows = a.bases.map((base, j): BaseAsset => {
1295
+ const w = a.weights[j]!;
1296
+ if (w === 0n) return { base, amount: 0n, priceX36: 0n };
1297
+ const Lj = (w * a.L0) / WAD;
1298
+ const amount = "r0" in a ? a.r0[j]! : fPoolReserveAt(Lj, a.x0[j]!, k);
1299
+ if (amount === 0n) throw new Error(`logswap: asset ${base} has weight ${w} but a zero reserve`);
1300
+ const value = (Lj * oneMinusK) / WAD;
1301
+ return { base, amount, priceX36: (value * 10n ** 36n + amount - 1n) / amount };
1302
+ });
1303
+ const { companions } = sortFPoolLegs(a.bases, rows);
1304
+ return { baseAssets: companions[0]!, lnCapOverSeed };
1305
+ }
1306
+
1307
+ /**
1308
+ * The allocation a `deployLiquidity` book implies: asset `j`'s value `amount_j · priceX36_j / 1e36` over the sum,
1309
+ * normalized as the manager does it (cumulative shares, floored), so the weights sum to exactly 1e18. A zero-value
1310
+ * book has no allocation (`[]`). What an indexer derives from `LiquidityDeployed` instead of reading the weights.
1311
+ */
1312
+ export function fPoolBookWeights(baseAssets: readonly BaseAsset[]): bigint[] {
1313
+ const values = baseAssets.map((x) => (x.amount * x.priceX36) / 10n ** 36n);
1314
+ const total = values.reduce((x, y) => x + y, 0n);
1315
+ if (total === 0n) return [];
1316
+ let cumulative = 0n;
1317
+ let previous = 0n;
1318
+ return values.map((v) => {
1319
+ cumulative += v;
1320
+ const next = (cumulative * WAD) / total;
1321
+ const w = next - previous;
1322
+ previous = next;
1323
+ return w;
1324
+ });
1325
+ }
1326
+
1327
+ /**
1328
+ * The book's total liquidity `L` from a `LiquidityDeployed` input: the values' sum over `1 − k`, `k = e^{−cap}`.
1329
+ * Exact when uncapped; with a cap it carries the float error of `k` (~1e-16 relative) — read the pool for the wei.
1330
+ */
1331
+ export function fPoolBookL(baseAssets: readonly BaseAsset[], lnCapOverSeed: number): bigint {
1332
+ const total = baseAssets.reduce((x, a) => x + (a.amount * a.priceX36) / 10n ** 36n, 0n);
1333
+ if (lnCapOverSeed === 0) return total;
1334
+ const oneMinusK = BigInt(Math.round((1 - fPoolCapK(lnCapOverSeed)) * 1e18));
1335
+ return (total * WAD) / oneMinusK;
1336
+ }
1337
+
1338
+ /**
1339
+ * Put liquidity into the pool, the authority's: `deployLiquidity` (F 38, decisions 083, 084). It SETS THE BOOK:
1340
+ * `baseAssets[j].amount` is the total base reserve of asset `j` after the call (0 removes it), `quoteAmount` the
1341
+ * total bid, and the manager settles each figure against what the pool holds — a larger total is pulled from the
1342
+ * caller, a smaller one pushed to `to` — so one call can replace an asset by another. Pass the book outright
1343
+ * (`baseAssets`, `lnCapOverSeed`) or the sponsor's terms ({@link fPoolBook}: `weights`, `L0` and marks `x0` or
1344
+ * reserves `r0`, in any order). On an UNFUNDED pool (new, or after {@link fPoolClose}) it funds the first or the next
1345
+ * generation. On a LIVE pool it is a regeneration that sets the book: income settles to `to`, the policy picks the
1346
+ * carried holder, every other holder is frozen into the closing generation's bundle ({@link fPoolRedeem}), and the
1347
+ * carried book becomes the one named, at the supplied prices. A pad is forward-only ({@link fPoolRegenerate}).
1348
+ */
1349
+ export async function fPoolDeploy(
1278
1350
  c: LogswapClient,
1279
- a: { poolId: Hex; L0: bigint; Q0: bigint; account: Address } & ({ r0: bigint[] } | { x0: bigint[]; weights: bigint[] }),
1351
+ a: { poolId: Hex; quoteAmount: bigint; to?: Address; account: Address } & (
1352
+ | { baseAssets: BaseAsset[]; lnCapOverSeed: number }
1353
+ | FPoolBookSpec
1354
+ ),
1280
1355
  ) {
1281
- let r0: bigint[];
1282
- if ("r0" in a) r0 = a.r0;
1283
- else {
1284
- const k = fPoolCapK(Number((await rawFPool(c, a.poolId)).lnCapOverFloor), a.Q0, a.L0);
1285
- r0 = a.x0.map((x, j) => fPoolReserveAt((a.weights[j]! * a.L0) / 10n ** 18n, x, k));
1286
- }
1287
- return writeFPool(c, a.poolId, "seed", [a.L0, r0, a.Q0], a.account);
1356
+ const { baseAssets, lnCapOverSeed } = "baseAssets" in a ? a : fPoolBook(a);
1357
+ return writeFPool(c, a.poolId, "deployLiquidity", [baseAssets, a.quoteAmount, lnCapOverSeed, a.to ?? a.account], a.account);
1288
1358
  }
1289
1359
 
1290
1360
  /**
1291
- * Retire the live generation — the raw entry (`dissolve` before F
1292
- * version 14). Allowed only at an empty bid, Q ≤ L/1e9, on every pool: the market took it, or the
1293
- * operator harvested it out first ({@link fPoolRetire} does both in one transaction). The live
1294
- * (S, Q, R_j) become a frozen bundle every share of this generation redeems ({@link fPoolRedeem})
1295
- * or rolls ({@link fPoolRollIn}), forever; the pool is unseeded until the next {@link fPoolSeed},
1296
- * which opens generation `gen + 1` under the same id, policy, roles, gates and lists.
1361
+ * Close the pool — the raw entry (`retire` before F 38). Allowed only at an empty bid, Q ≤ L/1e9, on every pool but a
1362
+ * pad: the market took it, or the operator harvested it out first ({@link fPoolClose} does both in one transaction).
1363
+ * Income settles to `to` first. The live (S, Q, R_j) become a frozen bundle every share of this generation redeems
1364
+ * ({@link fPoolRedeem}), forever; the pool is unfunded until the next {@link fPoolDeploy}, which opens generation
1365
+ * `gen + 1` under the same id, policy, roles, gates and lists. Whoever runs the pool.
1297
1366
  */
1298
- export async function fPoolRetireRaw(c: LogswapClient, a: { poolId: Hex; account: Address }) {
1299
- return writeFPool(c, a.poolId, "retire", [], a.account);
1367
+ export async function fPoolCloseRaw(c: LogswapClient, a: { poolId: Hex; to?: Address; account: Address }) {
1368
+ return writeFPool(c, a.poolId, "close", [a.to ?? a.account], a.account);
1300
1369
  }
1301
1370
 
1302
1371
  /**
1303
- * Retire the live generation as ONE transaction: the harvest that empties the bid
1372
+ * Close the pool as ONE transaction: the harvest that empties the bid
1304
1373
  * ({@link fPoolEmptyingHarvests} — a dividend to every share; none when it is already empty),
1305
- * then `retire` — the manager's `multicall`, the operator as sender. What a sponsor's
1306
- * "retire" button should call. Throws before sending on a pad: a pad never retires (F version 21).
1374
+ * then `close` — the manager's `multicall`, the operator as sender. What a sponsor's "close" button
1375
+ * should call. Throws before sending on a pad: a pad never closes.
1307
1376
  */
1308
- export async function fPoolRetire(c: LogswapClient, a: { poolId: Hex; account: Address }) {
1377
+ export async function fPoolClose(c: LogswapClient, a: { poolId: Hex; to?: Address; account: Address }) {
1309
1378
  const harvests = await fPoolEmptyingHarvests(c, a.poolId);
1310
- if (harvests.length === 0) return fPoolRetireRaw(c, a);
1379
+ if (harvests.length === 0) return fPoolCloseRaw(c, a);
1311
1380
  const enc = (functionName: string, args: unknown[]) =>
1312
1381
  encodeFunctionData({ abi: fPoolManagerAbi, functionName, args } as never) as Hex;
1313
- const calls: Hex[] = [...harvests.map((amount) => enc("harvest", [a.poolId, amount, a.account])), enc("retire", [a.poolId])];
1382
+ const calls: Hex[] = [...harvests.map((amount) => enc("harvest", [a.poolId, amount, a.account])), enc("close", [a.poolId, a.to ?? a.account])];
1314
1383
  return writeFPool0(c, "multicall", [calls], a.account);
1315
1384
  }
1316
1385
 
1317
1386
  /**
1318
- * The harvests that empty an unlocked pool's bid, in order — what a relaunch sends before its
1319
- * `retire` (a retire needs an empty bid on every pool). Since F version 14 one
1320
- * `harvest(Q)` does it: the protocol's cut leaves the pool with the amount (with no treasury
1321
- * there is no cut). `[]` when the bid is already empty. Throws on a pad (F version 21: a pad
1322
- * never retires, whatever its bid), and when the pool's policy keeps a floor on the bid
1323
- * (`PolPolicy.keepQuote`): a `retire` under that policy waits for the market.
1387
+ * The harvests that empty an unlocked pool's bid, in order — what a close sends before its
1388
+ * `close` (a close needs an empty bid on every pool). One `harvest(Q)` does it: the income tax leaves the pool with
1389
+ * the income part (with no treasury there is none). `[]` when the bid is already empty. Throws on a pad (a pad
1390
+ * never closes, whatever its bid), and when the pool's policy keeps a floor on the bid
1391
+ * (`PolPolicy.minQuoteRatio`): a `close` under that policy waits for the market.
1324
1392
  */
1325
1393
  export async function fPoolEmptyingHarvests(c: LogswapClient, poolId: Hex): Promise<bigint[]> {
1326
1394
  const s = await getFPool(c, poolId);
1327
- // F version 21: `PadPolicy` refuses `retire` at any bid — a pad graduates (regenerate), it
1328
- // never closes; a fresh start is a new pad with a new id
1329
- if (s.kind === "pad") throw new Error("logswap: a pad never retires (F version 21) — it graduates by regenerate; a fresh start is a new pad");
1395
+ // `PadPolicy` refuses `close` at any bid — a pad graduates (regenerate), it never closes; a fresh start is a new pad
1396
+ if (s.kind === "pad") throw new Error("logswap: a pad never closes — it graduates by regenerate; a fresh start is a new pad");
1330
1397
  if (s.Q === 0n) return [];
1331
1398
  const { maxHarvest } = await getFPoolRoles(c, poolId, s);
1332
1399
  if (maxHarvest < s.Q) throw new Error("logswap: the pool's policy keeps a floor on the bid — it cannot be harvested empty");
@@ -1334,72 +1401,28 @@ export async function fPoolEmptyingHarvests(c: LogswapClient, poolId: Hex): Prom
1334
1401
  }
1335
1402
 
1336
1403
  /**
1337
- * The GENERATION STEP (F version 21) — on a pad, its graduation. The manager harvests the
1338
- * generation's income first, releases the dead shares' pot, and asks the policy
1404
+ * The GENERATION STEP — on a pad, its graduation (F 38: `deployLiquidity` with nothing changed). The manager
1405
+ * harvests the generation's income first, releases the dead shares' income, and asks the policy
1339
1406
  * (`onRegenerate`), whose {@link FPolicyTerms} name a `carried` holder. Then, for live
1340
1407
  * generation `g`:
1341
1408
  *
1342
1409
  * - the carried holder's and the dead shares' `g` shares are re-minted 1:1 as `g + 1`: they go on
1343
1410
  * as the pool;
1344
- * - every OTHER holder of `g` is frozen out pro rata into generation `g`'s bundle (`Retired(g, …)`)
1411
+ * - every OTHER holder of `g` is frozen out pro rata into generation `g`'s bundle (`GenerationRetired`)
1345
1412
  * and redeems it with {@link fPoolRedeem} / rolls it with {@link fPoolRollIn} (`gen: g`); their
1346
1413
  * dividends on `g` stay claimable ({@link fPoolClaim} with `gen: g`). {@link fPoolClaimsOf}
1347
1414
  * lists them;
1348
- * - the pot, all in quote (decisions 057): `toPayee` to the payee, `protocolCut` to the treasury,
1349
- * `burn` spent buying base at the curve and burning it (the price up, the floor held), and the
1350
- * rest into the bid (the floor down). No share is minted; L does not move.
1415
+ * - the income released (`IncomeReleased`), all in quote: `toPayee` to the payee and the rest into the bid
1416
+ * (the floor down). No share is minted; L does not move. The book keeps its reserves, marks and cap.
1351
1417
  *
1352
1418
  * A pad's gate is `threshold(poolId, gen)`, in its quote (`PadPolicy.NotGraduated` below it); POL and private carry the
1353
- * authority and send it the whole pot; a public pool refuses (`Refused`). A carried holder with no
1354
- * share is `BadTerms`. Whoever runs the pool.
1419
+ * authority and send it the whole income; a public pool refuses (`Refused`). A carried holder with no
1420
+ * share is `BadTerms`. Whoever runs the pool. To change the book (reserves, prices, cap) use {@link fPoolDeploy}.
1355
1421
  */
1356
1422
  export async function fPoolRegenerate(c: LogswapClient, a: { poolId: Hex; to?: Address; account: Address }) {
1357
1423
  return writeFPool(c, a.poolId, "regenerate", [a.to ?? a.account], a.account);
1358
1424
  }
1359
1425
 
1360
- /**
1361
- * The relaunch as ONE transaction: `harvest` the bid out — a
1362
- * dividend to every share, {@link fPoolEmptyingHarvests} — `retire` the live generation at the
1363
- * empty bid, `redeem` the caller's own shares of it (when `shares` > 0), optionally `setLegs` the
1364
- * next generation's composition (`legs`: a private pool's reshape — retire, admit, reweight), and
1365
- * `seed` it with what came back — the manager's `multicall`, one sender throughout, the same
1366
- * pool. The operator's when one is appointed and the seed's inventory is its own; by default the
1367
- * authority's. The policy, its roles, gates, allowlist and the name carry over; anything else goes
1368
- * in `extra`, pre-encoded against {@link fPoolManagerAbi}. The seed names reserves (decisions
1369
- * 029): `r0` outright — one per leg of the NEXT table, 0 for a retired leg — or `x0` marks
1370
- * against the next table's `weights`.
1371
- */
1372
- export async function fPoolRelaunch(
1373
- c: LogswapClient,
1374
- a: {
1375
- poolId: Hex;
1376
- /** the caller's shares of the retiring generation to redeem inside the batch — its whole balance, usually; 0 to keep the claim */
1377
- shares: bigint;
1378
- L0: bigint;
1379
- Q0: bigint;
1380
- /** the next generation's composition: one weight per existing leg (0 retires it), then one per new base */
1381
- legs?: { weights: bigint[]; newBases?: Address[] };
1382
- extra?: Hex[];
1383
- account: Address;
1384
- } & ({ r0: bigint[] } | { x0: bigint[]; weights: bigint[] }),
1385
- ) {
1386
- const [raw, harvests] = await Promise.all([rawFPool(c, a.poolId), fPoolEmptyingHarvests(c, a.poolId)]);
1387
- const gen = Number(raw.gen);
1388
- const k = "r0" in a ? 0 : fPoolCapK(Number(raw.lnCapOverFloor), a.Q0, a.L0);
1389
- const r0 = "r0" in a ? a.r0 : a.x0.map((x, j) => (a.weights[j]! === 0n ? 0n : fPoolReserveAt((a.weights[j]! * a.L0) / WAD, x, k)));
1390
- const enc = (functionName: string, args: unknown[]) =>
1391
- encodeFunctionData({ abi: fPoolManagerAbi, functionName, args } as never) as Hex;
1392
- const calls: Hex[] = [
1393
- ...harvests.map((amount) => enc("harvest", [a.poolId, amount, a.account])),
1394
- enc("retire", [a.poolId]),
1395
- ...(a.shares > 0n ? [enc("redeem", [a.poolId, BigInt(gen), a.account, a.shares])] : []),
1396
- ...(a.legs ? [enc("setLegs", [a.poolId, a.legs.weights, a.legs.newBases ?? []])] : []),
1397
- enc("seed", [a.poolId, a.L0, r0, a.Q0]),
1398
- ...(a.extra ?? []),
1399
- ];
1400
- return writeFPool0(c, "multicall", [calls], a.account);
1401
- }
1402
-
1403
1426
  /** Where a pad's seed lives: `seed` mints every share of a pad here itself. */
1404
1427
  export const DEAD_ADDRESS: Address = "0x000000000000000000000000000000000000dEaD";
1405
1428
  /** The manager's `MIN_SHARES`: the seed mints this much to 0xdead on every pool, the rest to the seeder — or, on a pad, to 0xdead too. */
@@ -1429,9 +1452,15 @@ export interface FPoolGenesisTransfer {
1429
1452
  }
1430
1453
 
1431
1454
  export interface FPoolLaunchArgs extends Omit<FPoolCreateArgs, "account"> {
1455
+ /** WAD, one per asset (in `bases` order), summing to 1e18; `L_j = w_j · L0`. The generation's allocation (F 38: not in the key). */
1456
+ weights: bigint[];
1457
+ /** The generation's total liquidity, quote units. */
1432
1458
  L0: bigint;
1433
- /** Quote the seed pulls. A pad seeds at 0 — pure float, a resting ask, nothing raised. */
1434
- Q0: bigint;
1459
+ /** The pool's one cap as ln(cap price / seed price), 1e-6 log units, or the leverage it stands for; absent is uncapped. A pad is always uncapped (`PadUncapped`). */
1460
+ lnCapOverSeed?: number;
1461
+ leverage?: number;
1462
+ /** The bid the deployment pulls (`quoteAmount`). A pad deploys at 0 — pure float, a resting ask, nothing raised. */
1463
+ quoteAmount: bigint;
1435
1464
  /**
1436
1465
  * An opening buy of leg `j` (an index into `bases` AS GIVEN) for `amountIn` of quote, ON THE
1437
1466
  * MANAGER — the same sender, a plain allowance to the manager, the router nowhere near it. A
@@ -1475,21 +1504,25 @@ export function fPoolLaunchCalls(
1475
1504
  poolId: Hex,
1476
1505
  a: FPoolLaunchArgs & ({ r0: bigint[] } | { x0: bigint[] }),
1477
1506
  ): Hex[] {
1478
- const sum = a.weights.reduce((x, y) => x + y, 0n);
1479
- if (sum !== WAD) throw new Error(`logswap: weights sum to ${sum}, expected 1e18`);
1480
- const k = "r0" in a ? 0 : fPoolCapK(fPoolCapOfArgs(a), a.Q0, a.L0);
1481
- const given = "r0" in a ? a.r0 : a.x0.map((x, j) => fPoolReserveAt((a.weights[j]! * a.L0) / WAD, x, k));
1482
- if (given.length !== a.bases.length) throw new Error(`logswap: ${given.length} reserves for ${a.bases.length} legs`);
1483
- const { bases, companions } = sortFPoolLegs(a.bases, a.weights, given);
1484
1507
  if (!a.policy) throw new Error("logswap: fPoolLaunchCalls needs the key's policy — fPoolLaunch fills it from the deployment");
1485
- const key = { quote: a.quote, bases, weights: companions[0]!, swapFee: a.swapFee, policy: a.policy, creator: a.creator, salt: a.salt ?? ZERO_SALT, lnCapOverFloor: fPoolCapOfArgs(a) };
1508
+ const { baseAssets, lnCapOverSeed } = fPoolBook(a);
1509
+ const bases = baseAssets.map((x) => x.base);
1510
+ const key: FPoolKey = {
1511
+ quote: a.quote,
1512
+ bases,
1513
+ swapFee: a.swapFee,
1514
+ policy: a.policy,
1515
+ creator: a.creator,
1516
+ salt: a.salt ?? ZERO_SALT,
1517
+ mintFee: a.mintFee ?? presetMintFee(a.swapFee),
1518
+ };
1486
1519
  const enc = (functionName: string, args: unknown[]) =>
1487
1520
  encodeFunctionData({ abi: fPoolManagerAbi, functionName, args } as never) as Hex;
1488
1521
  const calls: Hex[] = [];
1489
- if (!a.initialized) calls.push(enc("initialize", [key, a.mintFee ?? presetMintFee(a.swapFee)]));
1490
- calls.push(enc("seed", [poolId, a.L0, companions[1]!, a.Q0]));
1491
- // gen 0 by construction: a launch is the pool's FIRST seed — a relaunch is `fPoolRelaunch`.
1492
- // No transfer to 0xdead: on a pad `seed` mints every share there itself.
1522
+ if (!a.initialized) calls.push(enc("initialize", [key]));
1523
+ calls.push(enc("deployLiquidity", [poolId, baseAssets, a.quoteAmount, lnCapOverSeed, a.account]));
1524
+ // gen 0 by construction: a launch is the pool's FIRST deployment — a later one is `fPoolDeploy` on the live pool.
1525
+ // No transfer to 0xdead: on a pad `deployLiquidity` mints every share there itself.
1493
1526
  for (const row of fPoolGenesisRows(a)) {
1494
1527
  const j = bases.indexOf(a.bases[row.j]!);
1495
1528
  if (j < 0) throw new Error(`logswap: genesis row j = ${row.j} is not a leg`);
@@ -1529,7 +1562,7 @@ export async function fPoolGenesisOutputs(
1529
1562
  account: signerFor(c, a.account),
1530
1563
  } as never);
1531
1564
  const results = result as readonly Hex[];
1532
- const first = (a.initialized ? 0 : 1) + 1; // [initialize] · seed · rows
1565
+ const first = (a.initialized ? 0 : 1) + 1; // [initialize] · deployLiquidity · rows
1533
1566
  return rows.map((_, i) => decodeAbiParameters([{ type: "uint256" }], results[first + i]!)[0] as bigint);
1534
1567
  }
1535
1568
 
@@ -1591,7 +1624,7 @@ export async function fPoolWalletBatchesAtomically(c: LogswapClient, account: Ad
1591
1624
  export async function fPoolDeskOpening(c: LogswapClient, a: { poolId: Hex; account: Address; policy?: Address }): Promise<Hash[]> {
1592
1625
  const policy = a.policy ?? fPoolPolicyFor(c, "private");
1593
1626
  return [
1594
- await fPoolSetGates(c, { poolId: a.poolId, gateMint: true, gateSwap: false, account: a.account, policy }),
1627
+ await fPoolSetMintGate(c, { poolId: a.poolId, gated: true, account: a.account, policy }),
1595
1628
  await fPoolSetMinters(c, { poolId: a.poolId, who: [a.account], allowed: true, account: a.account, policy }),
1596
1629
  ];
1597
1630
  }
@@ -1693,12 +1726,21 @@ export async function fPoolAcceptAuthority(c: LogswapClient, a: { poolId: Hex; a
1693
1726
 
1694
1727
  // ─── the desk's controls (PrivatePolicy) ───────────────────────────────
1695
1728
 
1696
- /** Turn the mint / swap gates on or off (the authority, on the desk's policy). `burn` is never gated. */
1697
- export async function fPoolSetGates(
1729
+ /**
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.
1733
+ */
1734
+ export async function fPoolSetSwapMode(
1698
1735
  c: LogswapClient,
1699
- a: { poolId: Hex; gateMint: boolean; gateSwap: boolean; account: Address; policy?: Address },
1736
+ a: { poolId: Hex; mode: FPoolSwapMode; executor?: Address; account: Address; policy?: Address },
1700
1737
  ) {
1701
- return writePolicy(c, privatePolicyAbi, a, "setGates", [a.gateMint, a.gateSwap]);
1738
+ return writePolicy(c, privatePolicyAbi, a, "setSwapMode", [SWAP_MODES.indexOf(a.mode), a.executor ?? ZERO_ADDRESS]);
1739
+ }
1740
+
1741
+ /** Turn mint admission on or off (the authority, on the desk's policy), preserving the swap mode and its executor. */
1742
+ export async function fPoolSetMintGate(c: LogswapClient, a: { poolId: Hex; gated: boolean; account: Address; policy?: Address }) {
1743
+ return writePolicy(c, privatePolicyAbi, a, "setMintGate", [a.gated]);
1702
1744
  }
1703
1745
 
1704
1746
  /**
@@ -1785,38 +1827,18 @@ async function registryAddress(c: LogswapClient): Promise<Address> {
1785
1827
  return registry;
1786
1828
  }
1787
1829
 
1788
- /** Who runs the pool: the appointed operator, or the authority until one is. */
1789
- export function fPoolOperatorOf(s: Pick<FPoolRoles, "authority" | "operator">): Address {
1790
- return s.operator === ZERO_ADDRESS ? s.authority : s.operator;
1830
+ /** Who may run the pool (decision 073): the authority always, and the optional delegate. */
1831
+ export function fPoolRunners(s: Pick<FPoolRoles, "authority" | "operator">): Address[] {
1832
+ return s.operator === ZERO_ADDRESS ? [s.authority] : [s.authority, s.operator];
1791
1833
  }
1792
1834
 
1793
1835
  /**
1794
- * Propose the operator (the authority, on the desk's policy) — the hot key that runs the pool:
1795
- * `harvest`, `retire`, `regenerate`, `setLegs`. Two-step: the proposed address takes the role with
1796
- * {@link fPoolAcceptOperator}. The zero address clears at once — the role returns to the authority.
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.
1797
1839
  */
1798
- export async function fPoolAppointOperator(c: LogswapClient, a: { poolId: Hex; operator: Address; account: Address; policy?: Address }) {
1799
- return writePolicy(c, privatePolicyAbi, a, "appointOperator", [a.operator]);
1800
- }
1801
-
1802
- /** The proposed operator takes the role. */
1803
- export async function fPoolAcceptOperator(c: LogswapClient, a: { poolId: Hex; account: Address; policy?: Address }) {
1804
- return writePolicy(c, privatePolicyAbi, a, "acceptOperator", []);
1805
- }
1806
-
1807
- /**
1808
- * The next generation's composition (operator; private pools only; ONLY while the pool is
1809
- * unseeded — between a retire and the seed that prices it). `weights` has one
1810
- * entry per leg the pool has ever had, in index order (0 retires a leg; indices are never reused),
1811
- * then one per base in `newBases`, appended; they sum to 1e18 exactly. No value moves: the
1812
- * following {@link fPoolSeed} names every reserve. A live reshape is {@link fPoolRelaunch} with
1813
- * `legs` set.
1814
- */
1815
- export async function fPoolSetLegs(
1816
- c: LogswapClient,
1817
- a: { poolId: Hex; weights: bigint[]; newBases?: Address[]; account: Address },
1818
- ) {
1819
- return writeFPool(c, a.poolId, "setLegs", [a.weights, a.newBases ?? []], a.account);
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]);
1820
1842
  }
1821
1843
 
1822
1844
  /**
@@ -1846,10 +1868,13 @@ export interface DiscoveredFPool {
1846
1868
  poolId: Hex;
1847
1869
  quote: Address;
1848
1870
  bases: Address[];
1871
+ /** The generation-0 allocation, from the pool's first `LiquidityDeployed` ({@link fPoolBookWeights}); `[]` until it is deployed — F 38 keeps no weights in the key. */
1849
1872
  weights: bigint[];
1850
1873
  swapFee: bigint;
1851
- /** The common cap as ln(cap price / floor price), in 1e-6 log units; 0 uncapped, cap ∞ (decisions 061). */
1852
- lnCapOverFloor: number;
1874
+ /** The creator-selected mint fee, fixed for life (F 38, decision 078). */
1875
+ mintFee: bigint;
1876
+ /** The generation-0 cap as ln(cap price / seed price), in 1e-6 log units; 0 uncapped, cap ∞ (decisions 061); 0 until deployed. */
1877
+ lnCapOverSeed: number;
1853
1878
  kind: FPoolKind;
1854
1879
  /** 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`). */
1855
1880
  policy: Address;
@@ -1857,7 +1882,7 @@ export interface DiscoveredFPool {
1857
1882
  creator: Address;
1858
1883
  /** The block the pool was initialized in — its age, for annualising realized income. */
1859
1884
  block: bigint;
1860
- /** Whether `seed` has run; an unseeded pool has no floor and no float, so nothing to show. */
1885
+ /** Whether `deployLiquidity` has run; an unfunded pool has no floor and no float, so nothing to show. */
1861
1886
  seeded: boolean;
1862
1887
  /** The quote the pool was born with. Zero is the launchpad's signature. */
1863
1888
  q0: bigint;
@@ -1872,8 +1897,8 @@ export interface DiscoveredFPool {
1872
1897
 
1873
1898
  /**
1874
1899
  * Every F pool ever created, from `PoolCreated` logs alone — plus one `kind()` read per distinct
1875
- * policy, cached. Possible only because the event carries the full key preimage (bases,
1876
- * weights, swapFee, policy, lnCapOverFloor) — the poolId is a hash and could never be inverted; contracts PR #17
1900
+ * policy, cached. Possible only because the event carries the full key preimage (quote, creator, bases,
1901
+ * swapFee, policy, mintFee) — the poolId is a hash and could never be inverted; contracts PR #17
1877
1902
  * exists for exactly this call. With `indexer`, the logs come from it (the node when it fails):
1878
1903
  * a scan from block 0 per call is what made the first load wait on the node.
1879
1904
  */
@@ -1884,39 +1909,42 @@ export async function discoverFPools(
1884
1909
  type Ev = Extract<(typeof fPoolManagerAbi)[number], { type: "event"; name: "PoolCreated" }>;
1885
1910
  const ev = fPoolManagerAbi.find((x): x is Ev => x.type === "event" && x.name === "PoolCreated");
1886
1911
  if (!ev) throw new Error("logswap: F PoolCreated event missing from the generated ABI");
1887
- type SeedEv = Extract<(typeof fPoolManagerAbi)[number], { type: "event"; name: "GenerationSeeded" }>;
1888
- const seedEv = fPoolManagerAbi.find((x): x is SeedEv => x.type === "event" && x.name === "GenerationSeeded");
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");
1889
1914
  const range = { indexer: opts.indexer, address: c.addresses.fPoolManager!, fromBlock: opts.fromBlock, toBlock: opts.toBlock };
1890
- const [{ logs }, { logs: seeds }] = await Promise.all([
1915
+ const [{ logs }, { logs: deploys }] = await Promise.all([
1891
1916
  getEventLogs(c, { ...range, event: ev }),
1892
- seedEv ? getEventLogs(c, { ...range, event: seedEv }) : Promise.resolve({ logs: [] }),
1917
+ deployEv ? getEventLogs(c, { ...range, event: deployEv }) : Promise.resolve({ logs: [] }),
1893
1918
  ]);
1894
- const q0Of = new Map<string, bigint>();
1895
- for (const l of seeds) {
1896
- const a = l.args as { poolId: Hex; Q0: bigint };
1897
- q0Of.set(a.poolId.toLowerCase(), a.Q0);
1919
+ // the pool's first deployment (generation 0) names its allocation, cap and opening bid
1920
+ const first = new Map<string, { weights: bigint[]; lnCapOverSeed: number; q0: bigint }>();
1921
+ for (const l of deploys) {
1922
+ const a = l.args as { poolId: Hex; gen: bigint | number; quoteAmount: bigint; baseAssets: readonly BaseAsset[]; lnCapOverSeed: number | bigint };
1923
+ if (BigInt(a.gen) !== 0n) continue;
1924
+ first.set(a.poolId.toLowerCase(), { weights: fPoolBookWeights(a.baseAssets), lnCapOverSeed: Number(a.lnCapOverSeed), q0: a.quoteAmount });
1898
1925
  }
1899
1926
  return Promise.all(
1900
1927
  logs.map(async (l) => {
1901
1928
  const a = l.args as {
1902
1929
  poolId: Hex; quote: Address; creator: Address; bases: readonly Address[];
1903
- weights: readonly bigint[]; swapFee: bigint; policy: Address; lnCapOverFloor?: number; cap?: number;
1930
+ swapFee: bigint; policy: Address; mintFee: bigint;
1904
1931
  };
1905
- const q0 = q0Of.get(a.poolId.toLowerCase());
1932
+ const g0 = first.get(a.poolId.toLowerCase());
1906
1933
  const kind = await fPoolKindOfPolicy(c, a.policy); // one read per distinct policy, cached
1907
1934
  return {
1908
1935
  poolId: a.poolId,
1909
1936
  quote: a.quote,
1910
1937
  bases: [...a.bases],
1911
- weights: [...a.weights],
1938
+ weights: g0?.weights ?? [],
1912
1939
  swapFee: a.swapFee,
1913
- lnCapOverFloor: Number(a.lnCapOverFloor ?? a.cap ?? 0), // `cap` before F version 27
1940
+ mintFee: a.mintFee,
1941
+ lnCapOverSeed: g0?.lnCapOverSeed ?? 0,
1914
1942
  kind,
1915
1943
  policy: a.policy,
1916
1944
  creator: a.creator,
1917
1945
  block: l.blockNumber,
1918
- seeded: q0 !== undefined,
1919
- q0: q0 ?? 0n,
1946
+ seeded: g0 !== undefined,
1947
+ q0: g0?.q0 ?? 0n,
1920
1948
  shape: kind === "pad" ? "launch": "basket", // the policy's word, not n = 1: a mono POL is a pool
1921
1949
  };
1922
1950
  }),
@@ -1946,23 +1974,23 @@ export type FPoolRules =
1946
1974
  gen: number;
1947
1975
  /** @deprecated Equal to {@link gen} since F version 21, kept for callers; read `gen`. */
1948
1976
  rung: number;
1949
- /** The pot the next graduation needs, in the pad's quote: `PadPolicy.threshold(poolId, gen)` (T(0) is per quote, decision 070). */
1977
+ /** The income the next graduation needs, in the pad's quote: `PadPolicy.threshold(poolId, gen)` (T(0) is per quote, decision 070). */
1950
1978
  threshold: bigint;
1951
- pot: bigint;
1952
- /** This pad's split, recorded at its birth from the key's salt and never changed (decisions 056, 057, 067): the creator's cut of the pot and the protocol's, fractions of the pot. The rest deepens the bid; nothing is bought or burnt (067). */
1979
+ /** The dead shares' income held for the next graduation, in the pad's quote. */
1980
+ income: bigint;
1981
+ /** This pad's creator share, recorded at its birth from the key's salt and never changed (decisions 056, 057, 067): a fraction of the income released. The rest deepens the bid; nothing is bought or burnt (067). */
1953
1982
  creatorShare: bigint;
1954
- protocolShare: bigint;
1983
+ /** The income tax the dead shares pay on their own new income dividend (decisions 073, 085), WAD. */
1984
+ incomeTaxRate: bigint;
1955
1985
  /** The ranges the LOG Authority set on the policy NOW for the pads born after this read: what a new creator may choose. */
1956
1986
  ranges: PadRanges;
1957
1987
  }
1958
- | { kind: "pol"; keepQuote: bigint; minQuoteAtSeed: bigint }
1959
- | { kind: "public"; curated: boolean }
1960
- | { kind: "private"; gateMint: boolean; gateSwap: boolean; operator: Address };
1988
+ | { 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 };
1961
1991
 
1962
- /** The LOG Authority's range on a pad's creator choice (`PadPolicy`, decisions 056, 067), WAD fractions of the pot. */
1992
+ /** The LOG Authority's range on a pad's creator choice (`PadPolicy`, decisions 056, 067), WAD fractions of the income released. */
1963
1993
  export interface PadRanges {
1964
- /** The protocol's share of the pot, recorded into each pad at birth. */
1965
- protocolShare: bigint;
1966
1994
  creatorShareMin: bigint;
1967
1995
  /** At most the F manager's `PAYEE_CUT_MAX` (50%), which bounds a pad's payee whatever the policy (067). */
1968
1996
  creatorShareMax: bigint;
@@ -1973,7 +2001,7 @@ const MAX_U128 = (1n << 128n) - 1n;
1973
2001
 
1974
2002
  /**
1975
2003
  * The salt that carries a pad's split (`PadPolicy.pack(creatorShare, nonce)`, decisions 056, 067): `creatorShare` in the top 64
1976
- * bits (a WAD fraction of the pot), zero in the next 64 — the burn share's place before F version 28, refused by the policy if
2004
+ * bits (a WAD fraction of the income), zero in the next 64 — the burn share's place before F version 28, refused by the policy if
1977
2005
  * set — and a nonce in the low 128 that tells two otherwise identical pads apart. It is part of the pool's identity, so it is
1978
2006
  * chosen at launch (`FPoolLaunchArgs.salt`) and never changes; the policy refuses a cut outside its range.
1979
2007
  */
@@ -1999,29 +2027,27 @@ export async function getFPoolRules(c: LogswapClient, s: Pick<FPoolState, "poolI
1999
2027
  case "pad": {
2000
2028
  // the rung is the manager's generation (F version 21): a move carries it, nothing to ask the policy
2001
2029
  const gen = s.gen;
2002
- const [split, pot, threshold, protocolNow, creatorShareMin, creatorShareMax] = await Promise.all([
2003
- rd<readonly [bigint, bigint]>(padPolicyAbi, "splitOf", [s.poolId]),
2030
+ const [creatorShare, income, threshold, incomeTaxRate, creatorShareMin, creatorShareMax] = await Promise.all([
2031
+ rd<bigint | number>(padPolicyAbi, "creatorShareOf", [s.poolId]).then(BigInt),
2004
2032
  fPoolDividendOf(c, s.poolId, DEAD_ADDRESS, gen),
2005
2033
  rd<bigint>(padPolicyAbi, "threshold", [s.poolId, BigInt(gen)]),
2006
- rd<bigint>(padPolicyAbi, "protocolShare"),
2034
+ rd<bigint>(padPolicyAbi, "incomeTaxRate"),
2007
2035
  rd<bigint>(padPolicyAbi, "creatorShareMin"),
2008
2036
  rd<bigint>(padPolicyAbi, "creatorShareMax"),
2009
2037
  ]);
2010
- const [creatorShare, protocolShare] = split;
2011
- const ranges: PadRanges = { protocolShare: protocolNow, creatorShareMin, creatorShareMax };
2012
- return { kind: "pad", gen, rung: gen, threshold, pot, creatorShare, protocolShare, ranges };
2038
+ const ranges: PadRanges = { creatorShareMin, creatorShareMax };
2039
+ return { kind: "pad", gen, rung: gen, threshold, income, creatorShare, incomeTaxRate, ranges };
2013
2040
  }
2014
2041
  case "pol": {
2015
- const [keepQuote, minQuoteAtSeed] = await Promise.all([rd<bigint>(polPolicyAbi, "keepQuote"), rd<bigint>(polPolicyAbi, "minQuoteAtSeed")]);
2016
- return { kind: "pol", keepQuote, minQuoteAtSeed };
2042
+ const [minQuoteRatio, incomeTaxRate] = await Promise.all([rd<bigint>(polPolicyAbi, "minQuoteRatio"), rd<bigint>(polPolicyAbi, "incomeTaxRate")]);
2043
+ return { kind: "pol", minQuoteRatio, incomeTaxRate };
2017
2044
  }
2018
2045
  case "public": {
2019
- const curated = await rd<boolean>(publicPolicyAbi, "curated");
2020
- return { kind: "public", curated };
2046
+ return { kind: "public" };
2021
2047
  }
2022
2048
  case "private": {
2023
2049
  const r = roles ?? (await getFPoolRoles(c, s.poolId, s));
2024
- return { kind: "private", gateMint: r.gateMint, gateSwap: r.gateSwap, operator: fPoolOperatorOf(r) };
2050
+ return { kind: "private", gateMint: r.gateMint, swapMode: r.swapMode, swapExecutor: r.swapExecutor, operator: r.operator };
2025
2051
  }
2026
2052
  }
2027
2053
  }
@@ -2101,7 +2127,7 @@ export async function fPoolShareHolders(
2101
2127
  /**
2102
2128
  * What a policy answers `onRegenerate` with: `IFPolicy.Terms` — four words, exactly 128 bytes since F version 28 (decision 067
2103
2129
  * removed `burn`). `carried` is the holder the next generation carries beside the dead shares; on a pad the manager requires
2104
- * `0xdead` and caps `toPayee` at `PAYEE_CUT_MAX` of the pot.
2130
+ * `0xdead` and caps `toPayee` at `PAYEE_CUT_MAX` of the income.
2105
2131
  */
2106
2132
  export interface FPolicyTerms {
2107
2133
  payee: Address;
@@ -2110,7 +2136,7 @@ export interface FPolicyTerms {
2110
2136
  carried: Address;
2111
2137
  }
2112
2138
 
2113
- /** Every F pool's raw state in one lens call (the manager's `Pool` struct: quote, swapFee, policy, seeded, gen, n, restructureTime, asks, lnCapOverFloor, Q, bigSigma, L, shares, refLogFloor). */
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). */
2114
2140
  export async function getFPoolsRaw(c: LogswapClient, poolIds: Hex[]): Promise<readonly unknown[]> {
2115
2141
  const { logswapLensAbi } = await import("./generated.js");
2116
2142
  return (await c.public.readContract({ address: c.addresses.lens, abi: logswapLensAbi, functionName: "getFPools", args: [poolIds] } as never)) as readonly unknown[];