@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/dist/admin.js CHANGED
@@ -1,18 +1,22 @@
1
1
  /**
2
- * admin — the protocol's writes: the C swap-fee tax (decisions 060), the policies a pool may be
3
- * born with (the registry's), the policies' own numbers (the quote list, the fee tiers, a pad's
4
- * schedule, a POL's rules), and the two roles' two-step handovers (decision 066): the LOG Authority
5
- * (the registry's `authority`) administers everything here; the LOG Treasury (`treasury` on each
6
- * manager) only receives, and is replaced by the authority's `proposeTreasury`. Plain writes to the managers, the
7
- * registry and the policies; no router.
2
+ * admin — the protocol's writes: the policies a pool may be born with and moved to (the registry's), the registry's
3
+ * creation modes and orphan move, the two roles' two-step handovers (decision 066): the LOG Authority (the registry's
4
+ * `logAuthority`) administers the registry and both managers; the LOG Treasury (`treasury` on each manager) only receives,
5
+ * and is replaced by the authority's `proposeTreasury`. Plain writes to the managers and the registry; no router.
6
+ *
7
+ * Since decision 098 the policies are immutable and the LOG's: a policy has no setter (its fee tiers, quotes, spacings, swap-fee tax, schedule and
8
+ * rates are constructor immutables), so there is no wrapper that writes one — a change is a new policy, approved ({@link registryApprove})
9
+ * and moved to ({@link fPoolMigrate}). What remains here for the policies is reading their numbers.
8
10
  *
9
11
  * The mint fee has no cut to set since C version 6 / F version 24 (decisions 058): the whole fee
10
12
  * is the protocol's on both managers. A harvest has no cut (056); a pad's protocol share of the income
11
- * is the policy's (`PadPolicy.setSchedule`), capped by the manager at `POT_CUT_MAX`.
13
+ * is the policy's `incomeTaxRate` (an immutable), capped by the manager at `INCOME_TAX_MAX`.
12
14
  */
15
+ import { poolId as keyId } from "./keys.js";
16
+ import { managerC, routerC } from "./client.js";
13
17
  import { getPool } from "./pools.js";
14
- import { cPoolManagerAbi, fPoolManagerAbi, padPolicyAbi, polPolicyAbi, policyRegistryAbi, publicPolicyAbi } from "./generated.js";
15
- import { bytes32ToText, fPolicyBaseAbi, fPoolKeyOfPool, fPoolKindOfPolicy, textToBytes32 } from "./fpool.js";
18
+ import { managerCAbi, managerFAbi, padPolicyAbi, policyRegistryAbi, sponsorPolicyCAbi, sponsorPolicyFAbi } from "./generated.js";
19
+ import { bytes32ToText, fPoolKeyOfPool, fPoolKindOfPolicy, fPoolSwapModes, textToBytes32 } from "./fpool.js";
16
20
  function wallet(c) {
17
21
  if (!c.wallet)
18
22
  throw new Error("a wallet client is required");
@@ -22,15 +26,19 @@ function write(c, address, abi, functionName, args) {
22
26
  return wallet(c).writeContract({ address, abi, functionName, args, chain: c.wallet.chain, account: c.wallet.account });
23
27
  }
24
28
  /**
25
- * The C swap-fee tax (decisions 060, 066): the protocol's share of every swap fee a C position is
26
- * paid (claims and the burn's auto-claim), WAD. `tax` is the level the gate (`PublicPolicy`) gives a
27
- * market born NOW; each market keeps the level of its birth for life — read it with
28
- * {@link cMarketSwapFeeTax} or `getPool(key).swapFeeTax`. `max` is the manager's bound.
29
+ * The C swap-fee tax (decisions 060, 066, 098): the protocol's share of every swap fee a C position is
30
+ * paid (claims and the burn's auto-claim), WAD. `tax` is the level a market born under `policy` (default: the deployment's
31
+ * `publicPolicyC`) is given — the policy's immutable `swapFeeTax`; each market keeps the level of its birth for
32
+ * life — read it with {@link cMarketSwapFeeTax} or `getPool(key).swapFeeTax`. A different level is a different policy.
33
+ * `max` is the manager's bound.
29
34
  */
30
- export async function cSwapFeeTax(c) {
35
+ export async function cSwapFeeTax(c, policy) {
36
+ const address = policy ?? c.addresses.publicPolicyC;
37
+ if (!address)
38
+ throw new Error("logswap: this deployment carries no C sponsored policy (addresses.publicPolicyC); pass one");
31
39
  const [tax, max] = await Promise.all([
32
- c.public.readContract({ address: c.addresses.publicPolicy, abi: publicPolicyAbi, functionName: "swapFeeTax" }),
33
- c.public.readContract({ address: c.addresses.cPoolManager, abi: cPoolManagerAbi, functionName: "SWAP_FEE_TAX_MAX" }),
40
+ c.public.readContract({ address, abi: sponsorPolicyCAbi, functionName: "swapFeeTax" }),
41
+ c.public.readContract({ address: managerC(c), abi: managerCAbi, functionName: "SWAP_FEE_TAX_MAX" }),
34
42
  ]);
35
43
  return { tax, max };
36
44
  }
@@ -38,13 +46,6 @@ export async function cSwapFeeTax(c) {
38
46
  export async function cMarketSwapFeeTax(c, key) {
39
47
  return (await getPool(c, key)).swapFeeTax;
40
48
  }
41
- /**
42
- * `PublicPolicy.setSwapFeeTax`: the level a C market born after it is given (066), at most
43
- * `SWAP_FEE_TAX_MAX` (25%). The LOG Authority's. A live market keeps the level of its birth.
44
- */
45
- export async function setCSwapFeeTax(c, taxWad) {
46
- return write(c, c.addresses.publicPolicy, publicPolicyAbi, "setSwapFeeTax", [taxWad]);
47
- }
48
49
  // ─── the registry: the LOG Authority's (046, 066) ───────────────────────────
49
50
  const ZERO = "0x0000000000000000000000000000000000000000";
50
51
  /**
@@ -55,7 +56,7 @@ const ZERO = "0x0000000000000000000000000000000000000000";
55
56
  export async function policyRegistryOf(c) {
56
57
  if (c.addresses.policyRegistry)
57
58
  return c.addresses.policyRegistry;
58
- return (await c.public.readContract({ address: c.addresses.fPoolManager, abi: fPoolManagerAbi, functionName: "registry" }));
59
+ return (await c.public.readContract({ address: c.addresses.managerF, abi: managerFAbi, functionName: "registry" }));
59
60
  }
60
61
  /** Whether `policy` is approved now — listed and not yet sunset. True everywhere on a deployment with no registry. */
61
62
  export async function policyApproved(c, policy) {
@@ -145,16 +146,20 @@ export const registryAcceptOwner = acceptLogAuthority;
145
146
  export async function setPolicyApproved(c, policy, approved) {
146
147
  return approved ? registryApprove(c, policy, await fPoolKindOfPolicy(c, policy)) : registryRevoke(c, policy);
147
148
  }
149
+ function permissionsArg(p = {}) {
150
+ return { swapMode: fPoolSwapModes.indexOf(p.swapMode ?? "open"), operator: p.operator ?? ZERO, mintGated: p.mintGated ?? false, listed: p.listed ?? [] };
151
+ }
148
152
  /**
149
153
  * Move a pool to another approved policy of the same kind: the LOG Authority's alone, a forced move
150
154
  * (adoption at regeneration by the pool authority's consent is specified, not built — logswap-docs
151
- * `specs/governance/policy-adoption.md`),
152
- * orchestrated on the registry — `migrate(manager, key, to)` since F version 20 (it took the
153
- * pool's id before). The registry checks the key against the manager (`NoPool`), checks the
154
- * manager is its own (`WrongManager`), and compares the two policies' tags recorded at approval
155
- * ({@link registryKindOf}). The new policy is brought the creator (the key's), the authority and
156
- * the name (read off the old policy defensively, the key's creator standing in when it cannot
157
- * answer); the operator and the lists void; no swap lands in the block.
155
+ * `specs/governance/policy-adoption.md`), orchestrated on the registry — `migrate(manager, key, to, permissions)`
156
+ * (decision 098; `migratePrivate` is gone). The registry checks the key against the manager (`NoPool`), the manager is its
157
+ * own (`WrongManager`), the two policies' tags recorded at approval ({@link registryKindOf}; every sponsored policy shares
158
+ * `"sponsor"`), the creation mode against the pool's authority (`SponsorOnly`: a sponsor's pool moves only under a policy of
159
+ * the same sponsor, or one open to anyone) and that the pool never held the target (`AlreadyHeld`). The new policy is
160
+ * brought the authority and the name (read off the old policy defensively, the key's creator standing in when it cannot
161
+ * answer); `permissions` installs the pool's swap mode, operator, mint gate and whitelist under it in the same transaction ({@link MigrationPermissions});
162
+ * the key, its fees and its id are untouched; no swap lands in the block. F only until C ships a `setPolicy`.
158
163
  *
159
164
  * Pass the pool's `key` when in hand. Given only `poolId`, the key is rebuilt from the pool's
160
165
  * `PoolCreated` log ({@link fPoolKeyOfPool}) with `salt` (zero by default) and checked against
@@ -162,7 +167,30 @@ export async function setPolicyApproved(c, policy, approved) {
162
167
  */
163
168
  export async function fPoolMigrate(c, a) {
164
169
  const key = "key" in a ? a.key : await fPoolKeyOfPool(c, a.poolId, { salt: a.salt, fromBlock: a.fromBlock });
165
- return registryWrite(c, "migrate", [c.addresses.fPoolManager, key, a.to]);
170
+ return registryWrite(c, "migrate", [c.addresses.managerF, key, a.to, permissionsArg(a.permissions)]);
171
+ }
172
+ /**
173
+ * `PolicyRegistry.orphan(manager, key)` (decision 098): move a pool whose sponsor went rogue or lost its key to the manager's orphan policy
174
+ * ({@link registryOrphanPolicyOf}) — no owner and no setting; swap and mint open; `deployLiquidity`, `harvest`, `close` and the generation
175
+ * step refused; income tax zero. The LOG Authority's alone, needing no consent, and FINAL: a pool never leaves the orphan policy (`Orphaned`).
176
+ * `key` as in {@link fPoolMigrate}.
177
+ */
178
+ export async function fPoolOrphan(c, a) {
179
+ const key = "key" in a ? a.key : await fPoolKeyOfPool(c, a.poolId, { salt: a.salt, fromBlock: a.fromBlock });
180
+ return registryWrite(c, "orphan", [c.addresses.managerF, key]);
181
+ }
182
+ /** The orphan policy registered for a manager (`orphanPolicy(manager)`): F's by default; zero when none is registered or the deployment has no registry. */
183
+ export async function registryOrphanPolicyOf(c, side = "F") {
184
+ const registry = await policyRegistryOf(c);
185
+ if (registry === ZERO)
186
+ return ZERO;
187
+ const mgr = side === "C" ? managerC(c) : c.addresses.managerF;
188
+ return (await c.public.readContract({ address: registry, abi: policyRegistryAbi, functionName: "orphanPolicy", args: [mgr] }));
189
+ }
190
+ /** `PolicyRegistry.setOrphanPolicy(manager, policy)`: register the approved policy tagged `"orphan"` that answers `manager` (F's by default). The LOG Authority's. */
191
+ export async function registrySetOrphanPolicy(c, policy, side = "F") {
192
+ const mgr = side === "C" ? managerC(c) : c.addresses.managerF;
193
+ return registryWrite(c, "setOrphanPolicy", [mgr, policy]);
166
194
  }
167
195
  /**
168
196
  * The kind tag the registry recorded for `policy` at approval (`kindOf`, F version 20) — refreshed
@@ -176,27 +204,6 @@ export async function registryKindOf(c, policy) {
176
204
  const word = (await c.public.readContract({ address: registry, abi: policyRegistryAbi, functionName: "kindOf", args: [policy] }));
177
205
  return bytes32ToText(word);
178
206
  }
179
- // ─── the policies' numbers (the LOG Authority's; each bounded where it reaches the manager) ─────
180
- /**
181
- * `PadPolicy.setSchedule` (decisions 056, 067, 070, 073): the rung's growth and the RANGE inside which a creator chooses their cut of the income
182
- * at creation (its top ≤ the F manager's `PAYEE_CUT_MAX`). The rest of the income deepens the bid — nothing is bought or
183
- * burnt since F version 28, and the protocol takes no cut of the income since F version 33 (its revenue is the income tax,
184
- * {@link padSetIncomeTaxRate}). A change to the range applies to pads born after it; the growth moves every pad at its
185
- * next rung. The rung is the pool's generation. `T(0)` is per quote since decision 070: {@link padSetThresholdBase}.
186
- */
187
- export async function padSetSchedule(c, policy, s) {
188
- if ("thresholdBase" in s)
189
- throw new Error("logswap: T(0) is per quote since decision 070 — padSetThresholdBase(c, policy, quote, base)");
190
- return write(c, policy, padPolicyAbi, "setSchedule", [s.thresholdGrowth, s.creatorShareMin, s.creatorShareMax]);
191
- }
192
- /**
193
- * `PadPolicy.setThresholdBase(quote, base)` (decision 070): `T(0)` for pads quoted in `quote`, in that quote's units. A pad is
194
- * born (or moved in) only on a quote that has one (`NoThreshold`). It moves every pad in that quote at its next rung. The LOG
195
- * Authority's.
196
- */
197
- export async function padSetThresholdBase(c, policy, quote, base) {
198
- return write(c, policy, padPolicyAbi, "setThresholdBase", [quote, base]);
199
- }
200
207
  /** `PadPolicy.thresholdSet(quote)` and `thresholdBaseOf(quote)` for each quote asked (decision 070). */
201
208
  export async function padThresholdBases(c, policy, quotes) {
202
209
  const rd = (functionName, quote) => c.public.readContract({ address: policy, abi: padPolicyAbi, functionName, args: [quote] });
@@ -219,68 +226,46 @@ export async function padScheduleOf(c, policy) {
219
226
  const [thresholdGrowth, creatorShareMin, creatorShareMax] = await Promise.all([rd("thresholdGrowth"), rd("creatorShareMin"), rd("creatorShareMax")]);
220
227
  return { thresholdGrowth, creatorShareMin, creatorShareMax };
221
228
  }
222
- /** `PolPolicy.setMinQuoteRatio` (decision 073): the reserve a harvest must leave in the bid (`may(Harvest)` refuses less) and a relaunch's seed must bring, a multiple of the pool's L in WAD (at most 100e18). The policy sponsor's. */
223
- export async function polSetMinQuoteRatio(c, policy, ratio) {
224
- return write(c, policy, polPolicyAbi, "setMinQuoteRatio", [ratio]);
225
- }
226
- /** `PadPolicy.setIncomeTaxRate` (decision 073): the share of its new income dividend the dead shares pay LOG Treasury as income tax, WAD, at most 50%. The policy sponsor's. */
227
- export async function padSetIncomeTaxRate(c, policy, rate) {
228
- return write(c, policy, padPolicyAbi, "setIncomeTaxRate", [rate]);
229
- }
230
- /** `PolPolicy.setIncomeTaxRate` (decision 073): the share of its new income dividend the pool's authority pays LOG Treasury, WAD, at most 50%. Paid on the authority's own shares only: an authority that holds through another address pays nothing. The policy sponsor's. */
231
- export async function polSetIncomeTaxRate(c, policy, rate) {
232
- return write(c, policy, polPolicyAbi, "setIncomeTaxRate", [rate]);
233
- }
234
- /** `setQuoteListed` on any protocol policy: a quote a pool of that kind may be born against while it curates quotes. The LOG Authority's. */
235
- export async function policySetQuoteListed(c, policy, quote, listed) {
236
- return write(c, policy, fPolicyBaseAbi, "setQuoteListed", [quote, listed]);
237
- }
238
- /** `setQuoteCurated` on any protocol policy: on, a birth against an unlisted quote is refused. The LOG Authority's. */
239
- export async function policySetQuoteCurated(c, policy, curated) {
240
- return write(c, policy, fPolicyBaseAbi, "setQuoteCurated", [curated]);
241
- }
242
- /** Whether `quote` passes `policy`'s birth check now: listed, or the policy does not curate quotes. */
229
+ /** Whether `quote` passes a sponsored `policy`'s birth check now: it curates quotes (`quoteCurated`, a non-empty list set in the constructor) and lists it, or it does not curate. */
243
230
  export async function policyQuoteAllowed(c, policy, quote) {
244
231
  const [curated, listed] = await Promise.all([
245
- c.public.readContract({ address: policy, abi: fPolicyBaseAbi, functionName: "quoteCurated" }),
246
- c.public.readContract({ address: policy, abi: fPolicyBaseAbi, functionName: "quoteListed", args: [quote] }),
232
+ c.public.readContract({ address: policy, abi: sponsorPolicyFAbi, functionName: "quoteCurated" }),
233
+ c.public.readContract({ address: policy, abi: sponsorPolicyFAbi, functionName: "quoteListed", args: [quote] }),
247
234
  ]);
248
235
  return { curated, listed, allowed: !curated || listed };
249
236
  }
250
237
  /**
251
- * `setFeeListed` on any protocol policy (decisions 059): a swap-fee tier a pool of that kind may be
252
- * born with while the policy curates fees. Within the family's domain (`FEE_MIN` ≤ fee ≤ `FEE_MAX`).
253
- * The LOG Authority's.
238
+ * Whether `fee` passes a sponsored `policy`'s birth check now: on its swap tiers (`swapFeeListed`) or, with `kind: "mint"`, its mint tiers
239
+ * (`mintFeeListed`). `curated` is true when the policy lists tiers (a non-zero mask); with none, any fee in the manager's domain is allowed.
254
240
  */
255
- export async function policySetFeeListed(c, policy, fee, listed) {
256
- return write(c, policy, fPolicyBaseAbi, "setFeeListed", [fee, listed]);
257
- }
258
- /** `setFeeCurated` on any protocol policy: on, a birth with an unlisted swap fee is refused (`FeeNotListed`). The LOG Authority's. */
259
- export async function policySetFeeCurated(c, policy, curated) {
260
- return write(c, policy, fPolicyBaseAbi, "setFeeCurated", [curated]);
261
- }
262
- /** Whether `fee` passes `policy`'s birth check now: listed, or the policy does not curate fees (the desk's never does). */
263
- export async function policyFeeAllowed(c, policy, fee) {
264
- const [curated, listed] = await Promise.all([
265
- c.public.readContract({ address: policy, abi: fPolicyBaseAbi, functionName: "feeCurated" }),
266
- c.public.readContract({ address: policy, abi: fPolicyBaseAbi, functionName: "feeListed", args: [fee] }),
241
+ export async function policyFeeAllowed(c, policy, fee, kind = "swap") {
242
+ const [tiers, listed] = await Promise.all([
243
+ c.public.readContract({ address: policy, abi: sponsorPolicyFAbi, functionName: kind === "swap" ? "swapTiers" : "mintTiers" }),
244
+ c.public.readContract({ address: policy, abi: sponsorPolicyFAbi, functionName: kind === "swap" ? "swapFeeListed" : "mintFeeListed", args: [fee] }),
267
245
  ]);
268
- return { curated, listed, allowed: !curated || listed };
246
+ return { curated: tiers !== 0n, listed, allowed: listed };
269
247
  }
270
- const CREATION_MODES = ["open", "restricted", "sponsorOnly"];
271
- /** `PolicyRegistry.setCreationMode(policy, mode)` (the LOG Authority): replaces the per-policy creator lists (064). A sponsor-bound policy cannot leave `sponsorOnly`. */
248
+ const CREATION_MODES = ["open", "sponsorOnly"];
249
+ /** `PolicyRegistry.setCreationMode(policy, mode)` (the LOG Authority). A sponsored policy is approved `sponsorOnly`. */
272
250
  export async function registrySetCreationMode(c, policy, mode) {
273
251
  return registryWrite(c, "setCreationMode", [policy, CREATION_MODES.indexOf(mode)]);
274
252
  }
275
- /** `PolicyRegistry.setInitializerListed(policy, who, allowed)` (the LOG Authority): who may create under a `restricted` policy, authenticated as the caller or a trusted forwarder's user. */
276
- export async function registrySetInitializerListed(c, policy, who, allowed) {
277
- return registryWrite(c, "setInitializerListed", [policy, who, allowed]);
278
- }
279
253
  /** `PolicyRegistry.setForwarderTrusted` (the LOG Authority): a router whose `user()` names the creator. Moved off the public policy in F version 33. */
280
254
  export async function registrySetForwarderTrusted(c, forwarder, trusted) {
281
255
  return registryWrite(c, "setForwarderTrusted", [forwarder, trusted]);
282
256
  }
283
257
  /** `PolicyRegistry.creationMode(policy)`. */
258
+ /**
259
+ * `PolicyRegistry.userOf(caller)` (C 15, decision 097): the account a caller acts for — the user a trusted forwarder
260
+ * (a router) names, else the caller itself. The account the managers authenticate as a market's creator and as the
261
+ * first minter; what a create form compares to the key's `creator`.
262
+ */
263
+ export async function registryUserOf(c, caller) {
264
+ const registry = await policyRegistryOf(c);
265
+ if (registry === ZERO)
266
+ return caller;
267
+ return (await c.public.readContract({ address: registry, abi: policyRegistryAbi, functionName: "userOf", args: [caller] }));
268
+ }
284
269
  export async function registryCreationMode(c, policy) {
285
270
  const registry = await policyRegistryOf(c);
286
271
  if (registry === ZERO)
@@ -288,79 +273,68 @@ export async function registryCreationMode(c, policy) {
288
273
  const m = (await c.public.readContract({ address: registry, abi: policyRegistryAbi, functionName: "creationMode", args: [policy] }));
289
274
  return CREATION_MODES[Number(m)] ?? "open";
290
275
  }
291
- /** `PublicPolicy.setPairListed` (064): a C pair a market may be born on while pairs are curated. Directional (base, quote). */
292
- export async function gateSetPairListed(c, policy, base, quote, listed) {
293
- return write(c, policy, publicPolicyAbi, "setPairListed", [base, quote, listed]);
294
- }
295
- /** `PublicPolicy.setPairCurated` (064). */
296
- export async function gateSetPairCurated(c, policy, curated) {
297
- return write(c, policy, publicPolicyAbi, "setPairCurated", [curated]);
298
- }
299
- /** `PublicPolicy.setSpacingListed` (064): a C tick spacing, WAD (10 bp = 1e15, 100 bp = 1e16). Always consulted. */
300
- export async function gateSetSpacingListed(c, policy, tickSpacing, listed) {
301
- return write(c, policy, publicPolicyAbi, "setSpacingListed", [tickSpacing, listed]);
302
- }
303
- /**
304
- * @deprecated C version 8 fixes the gate at construction (066): there is no `setGate`. Open or close
305
- * C through the gate's lists (`registrySetCreationMode`, `gateSetPairCurated`, `gateSetSpacingListed`, …).
306
- */
307
- export async function setCGate(_c, _gate) {
308
- throw new Error("logswap: the C gate is fixed at construction since C version 8 (decision 066); change its lists instead");
276
+ /** Whether `policy` (a `SponsorPolicyC`) admits C tick spacing `tickSpacing`: it curates spacings (`spacingCurated`) and lists it, or it does not curate. */
277
+ export async function policySpacingAllowed(c, policy, tickSpacing) {
278
+ const [curated, listed] = await Promise.all([
279
+ c.public.readContract({ address: policy, abi: sponsorPolicyCAbi, functionName: "spacingCurated" }),
280
+ c.public.readContract({ address: policy, abi: sponsorPolicyCAbi, functionName: "spacingListed", args: [tickSpacing] }),
281
+ ]);
282
+ return { curated, listed, allowed: !curated || listed };
309
283
  }
310
284
  /**
311
- * The public policy's C checks for one candidate market and creator, in one round of reads — what
312
- * the create form shows before a wallet is asked (064, 073). The policy is `key.policy`; the registry
313
- * is asked `admit(policy, caller, 0)`, with the caller being the router when it is a trusted forwarder
314
- * (it then names `creator` itself) and `creator` otherwise.
285
+ * A sponsored C policy's checks for one candidate market and creator, in one round of reads — what the create form shows before a wallet
286
+ * is asked (064, 073, 097, 098). The policy is `key.policy` (a `SponsorPolicyC`); the registry is asked `admit(policy, creator, creator)`: the
287
+ * account that starts a market is its creator, so the key's `creator` is the connected account (a router call resolves to it through the
288
+ * trusted forwarder's `user()`). The policy's pair list is gone (098).
315
289
  */
316
290
  export async function cGateRules(c, a) {
317
291
  const g = a.gate ?? a.key.policy;
318
- const rd = (functionName, args = []) => c.public.readContract({ address: g, abi: publicPolicyAbi, functionName, args });
292
+ const rd = (functionName, args = []) => c.public.readContract({ address: g, abi: sponsorPolicyCAbi, functionName, args });
319
293
  const { key } = a;
294
+ const creator = a.creator ?? key.creator;
320
295
  const registry = await policyRegistryOf(c);
321
- const router = a.router ?? c.addresses.router;
296
+ const router = a.router ?? routerC(c);
322
297
  const registryRd = (functionName, args) => c.public.readContract({ address: registry, abi: policyRegistryAbi, functionName, args });
323
- const [quoteCurated, quoteListed, pairCurated, pairListed, feeCurated, feeListed, spacingListed, market, routerTrusted, creatorOk] = await Promise.all([
298
+ const [quoteCurated, quoteListed, feeListed, mintFeeListed, spacingCurated, spacingListed, canonical, state, routerTrusted, creatorOk] = await Promise.all([
324
299
  rd("quoteCurated"),
325
300
  rd("quoteListed", [key.quote]),
326
- rd("pairCurated"),
327
- rd("pairListed", [key.base, key.quote]),
328
- rd("feeCurated"),
329
- rd("feeListed", [key.swapFee]),
301
+ rd("swapFeeListed", [key.swapFee]),
302
+ rd("mintFeeListed", [key.mintFee]),
303
+ rd("spacingCurated"),
330
304
  rd("spacingListed", [key.tickSpacing]),
331
- rd("cMarketOf", [key.base, key.quote, key.swapFee]),
305
+ rd("canonical"),
306
+ getPool(c, key),
332
307
  registry === ZERO ? Promise.resolve(false) : registryRd("forwarderTrusted", [router]),
333
308
  registry === ZERO
334
309
  ? Promise.resolve(true)
335
- : registryRd("admit", [g, a.creator, ZERO]).then(() => true, () => false),
310
+ : registryRd("admit", [g, creator, creator]).then((who) => who.toLowerCase() === creator.toLowerCase(), () => false),
336
311
  ]);
337
312
  const r = {
338
313
  creatorOk,
339
314
  quoteOk: !quoteCurated || quoteListed,
340
- pairOk: !pairCurated || pairListed,
341
- feeOk: !feeCurated || feeListed,
342
- spacingOk: spacingListed,
343
- exists: BigInt(market) !== 0n,
315
+ feeOk: feeListed,
316
+ mintFeeOk: mintFeeListed,
317
+ spacingOk: !spacingCurated || spacingListed,
318
+ saltOk: !canonical || key.salt === "0x0000000000000000000000000000000000000000000000000000000000000000",
319
+ exists: state.initialized,
344
320
  routerTrusted,
345
321
  };
346
- return { ...r, admitted: r.creatorOk && r.quoteOk && r.pairOk && r.feeOk && r.spacingOk && !r.exists };
322
+ return { ...r, admitted: r.creatorOk && r.quoteOk && r.feeOk && r.mintFeeOk && r.spacingOk && r.saltOk && !r.exists };
347
323
  }
348
324
  /**
349
- * Every refusal a birth can meet at the gate or a policy (064, 065), for `decodeErrorResult` on a
350
- * failed simulation: the public policy's errors plus the pad's `PadExists` (one pad per base) and `NoThreshold` (no `T(0)`
325
+ * Every refusal a birth can meet at a sponsored policy or the registry (064, 065, 098), for `decodeErrorResult` on a
326
+ * failed simulation: the sponsored C policy's errors (a superset of F's) plus the pad's `PadExists` (one pad per base) and `NoThreshold` (no `T(0)`
351
327
  * in the pad's quote, decision 070).
352
328
  */
353
329
  export const gateErrorAbi = [
354
- ...publicPolicyAbi.filter((x) => x.type === "error"),
355
- // creation admission moved to the registry in F 33 / C 10 (073): a refusal there surfaces through the manager's birth
356
- ...policyRegistryAbi.filter((x) => x.type === "error" && ["SponsorOnly", "InitializerNotListed", "InvalidForwardedUser", "NotListed"].includes(x.name)),
330
+ ...sponsorPolicyCAbi.filter((x) => x.type === "error"),
331
+ // creation admission is the registry's (F 33 / C 10, 073): a refusal there surfaces through the manager's birth
332
+ ...policyRegistryAbi.filter((x) => x.type === "error" && ["SponsorOnly", "InvalidForwardedUser", "NotListed"].includes(x.name)),
357
333
  ...padPolicyAbi.filter((x) => x.type === "error" && (x.name === "PadExists" || x.name === "NoThreshold")),
358
334
  ];
359
335
  // ─── the LOG Treasury (066): receives, administers nothing ───────────────────
360
336
  function manager(c, side) {
361
- return side === "C"
362
- ? { address: c.addresses.cPoolManager, abi: cPoolManagerAbi }
363
- : { address: c.addresses.fPoolManager, abi: fPoolManagerAbi };
337
+ return side === "C" ? { address: managerC(c), abi: managerCAbi } : { address: c.addresses.managerF, abi: managerFAbi };
364
338
  }
365
339
  /** A manager's treasury — where its protocol revenue goes — and the proposed next one. */
366
340
  export async function logTreasury(c, side) {
@@ -389,9 +363,9 @@ export const proposeCollector = proposeTreasury;
389
363
  /** @deprecated use {@link acceptTreasury}. */
390
364
  export const acceptCollector = acceptTreasury;
391
365
  /**
392
- * `CPoolManager.collectProtocolFees(key)`: pay one market's `protocolOwed` (mint fees and swap-fee
366
+ * `ManagerC.collectProtocolFees(poolId)`: pay one market's `protocolOwed` (mint fees and swap-fee
393
367
  * tax) to the treasury. Anyone may send it (066); the destination is fixed.
394
368
  */
395
369
  export async function collectCProtocolFees(c, key) {
396
- return write(c, c.addresses.cPoolManager, cPoolManagerAbi, "collectProtocolFees", [key]);
370
+ return write(c, managerC(c), managerCAbi, "collectProtocolFees", [keyId(key)]);
397
371
  }
package/dist/chains.d.ts CHANGED
@@ -124,14 +124,23 @@ export interface LogswapDeployment {
124
124
  permit2: Address;
125
125
  multicall3: Address;
126
126
  policyRegistry: Address;
127
- fPoolManager: Address;
128
- cPoolManager: Address;
127
+ managerF: Address;
128
+ routerF: Address;
129
+ lensF: Address;
130
+ /** The C stack (decision 096): absent while the chain has not opted into C (the artifact carries `address(0)` and `cVersion` 0). */
131
+ managerC?: Address;
132
+ routerC?: Address;
133
+ lensC?: Address;
134
+ /** The LOG's open sponsored instance on F (`SponsorPolicyF`, sponsor = the LOG, canonical, no gate available; decision 098). */
129
135
  publicPolicy: Address;
136
+ /** The LOG's gated sponsored instance on F (`SponsorPolicyF`: gates available, born gated). The artifact key predates 098 and is kept. */
130
137
  privatePolicy: Address;
131
138
  polPolicy: Address;
132
139
  padPolicy: Address;
133
- router: Address;
134
- lens: Address;
140
+ /** The LOG's open sponsored instance on C (`SponsorPolicyC`). Absent while the chain has no C stack. */
141
+ publicPolicyC?: Address;
142
+ /** F's orphan policy (`OrphanPolicyF`, decision 098): where `PolicyRegistry.orphan` moves a pool. Absent on an artifact that predates it. */
143
+ orphanPolicy?: Address;
135
144
  /** The devnet's token factory; local deployments only. */
136
145
  tokenFactory?: Address;
137
146
  }
package/dist/chains.js CHANGED
@@ -6,7 +6,7 @@
6
6
  * block, the quote tokens, the explorer and the indexer. An address therefore names a contract only
7
7
  * together with a chain id; every cache and every indexer URL in this SDK is per chain.
8
8
  */
9
- import { defineChain, getAddress, isAddress } from "viem";
9
+ import { defineChain, getAddress, isAddress, zeroAddress } from "viem";
10
10
  import { arbitrum, base, foundry, mainnet, robinhood, robinhoodTestnet } from "viem/chains";
11
11
  /** The logswap devnet (anvil, persisted with `--state`). No public RPC. */
12
12
  export const logswapDevnet = defineChain({
@@ -105,16 +105,19 @@ const REQUIRED_ADDRESSES = [
105
105
  "permit2",
106
106
  "multicall3",
107
107
  "policyRegistry",
108
- "fPoolManager",
109
- "cPoolManager",
108
+ "managerF",
109
+ "routerF",
110
+ "lensF",
110
111
  "publicPolicy",
111
112
  "privatePolicy",
112
113
  "polPolicy",
113
114
  "padPolicy",
114
- "router",
115
- "lens",
116
115
  ];
117
116
  const OPTIONAL_ADDRESSES = ["createX", "tokenFactory"];
117
+ /** Policies an artifact may carry as `address(0)` (no C stack, no orphan policy deployed): zero is absent. */
118
+ const OPTIONAL_POLICIES = ["publicPolicyC", "orphanPolicy"];
119
+ /** The C stack: all three, or none (`address(0)` — the chain has not opted into C yet). */
120
+ const C_STACK = ["managerC", "routerC", "lensC"];
118
121
  function uint(o, k) {
119
122
  const v = o[k];
120
123
  if (typeof v === "bigint" && v >= 0n)
@@ -166,19 +169,30 @@ export function deploymentFromArtifact(json, opts = {}) {
166
169
  for (const k of OPTIONAL_ADDRESSES)
167
170
  if (o[k] !== undefined)
168
171
  d[k] = address(o, k);
172
+ for (const k of OPTIONAL_POLICIES)
173
+ if (o[k] !== undefined && address(o, k) !== zeroAddress)
174
+ d[k] = address(o, k);
175
+ const present = C_STACK.filter((k) => o[k] !== undefined && address(o, k) !== zeroAddress);
176
+ if (present.length !== 0 && present.length !== C_STACK.length) {
177
+ throw new Error(`logswap: deployment artifact: the C stack is all or nothing, but only ${present.join(", ")} ${present.length === 1 ? "is" : "are"} set`);
178
+ }
179
+ for (const k of present)
180
+ d[k] = address(o, k);
169
181
  return d;
170
182
  }
171
183
  /** The client's address set from a deployment. */
172
184
  export function addressesOfDeployment(d) {
173
185
  return {
174
- cPoolManager: d.cPoolManager,
175
- router: d.router,
176
- lens: d.lens,
177
- fPoolManager: d.fPoolManager,
186
+ managerF: d.managerF,
187
+ routerF: d.routerF,
188
+ lensF: d.lensF,
189
+ ...(d.managerC && d.routerC && d.lensC ? { managerC: d.managerC, routerC: d.routerC, lensC: d.lensC } : {}),
178
190
  publicPolicy: d.publicPolicy,
179
191
  privatePolicy: d.privatePolicy,
180
192
  polPolicy: d.polPolicy,
181
193
  padPolicy: d.padPolicy,
194
+ ...(d.publicPolicyC ? { publicPolicyC: d.publicPolicyC } : {}),
195
+ ...(d.orphanPolicy ? { orphanPolicy: d.orphanPolicy } : {}),
182
196
  policyRegistry: d.policyRegistry,
183
197
  permit2: d.permit2,
184
198
  ...(d.tokenFactory ? { tokenFactory: d.tokenFactory } : {}),
package/dist/claims.d.ts CHANGED
@@ -6,7 +6,7 @@
6
6
  * - a TOKEN claim — a bearer IOU (bit-255-clear id) for inventory parked inside the manager
7
7
  */
8
8
  import type { Address, Hash } from "viem";
9
- import type { LogswapClient } from "./client.js";
9
+ import { type LogswapClient } from "./client.js";
10
10
  import { type PoolKey } from "./keys.js";
11
11
  import { type WriteOptions } from "./write.js";
12
12
  export interface ClaimFeesArgs extends WriteOptions {
package/dist/claims.js CHANGED
@@ -5,7 +5,8 @@
5
5
  * - a FEE claim — `claimFees`, withdrawing accrued quote while the position stays whole
6
6
  * - a TOKEN claim — a bearer IOU (bit-255-clear id) for inventory parked inside the manager
7
7
  */
8
- import { cPoolManagerAbi, routerAbi } from "./generated.js";
8
+ import { managerCAbi, routerCAbi } from "./generated.js";
9
+ import { managerC, routerC } from "./client.js";
9
10
  import { poolId as keyId } from "./keys.js";
10
11
  import { isPosition } from "./ids.js";
11
12
  import { requireWallet, resolveDeadline, resolveRecipient, sendRouterWrite } from "./write.js";
@@ -25,7 +26,8 @@ export async function claimFees(c, a) {
25
26
  }
26
27
  }
27
28
  return sendRouterWrite(c, {
28
- abi: routerAbi,
29
+ side: "C",
30
+ abi: routerCAbi,
29
31
  functionName: "claim",
30
32
  args: [keyId(a.key), a.key.quote, a.ids, resolveRecipient(c, a), resolveDeadline(a)],
31
33
  });
@@ -42,10 +44,10 @@ export async function claimFees(c, a) {
42
44
  export async function approveRouterAsOperator(c, approved = true) {
43
45
  const { account } = requireWallet(c);
44
46
  return c.wallet.writeContract({
45
- address: c.addresses.cPoolManager,
46
- abi: cPoolManagerAbi,
47
+ address: managerC(c),
48
+ abi: managerCAbi,
47
49
  functionName: "setOperator",
48
- args: [c.addresses.router, approved],
50
+ args: [routerC(c), approved],
49
51
  account,
50
52
  chain: c.wallet.chain,
51
53
  });
@@ -53,10 +55,10 @@ export async function approveRouterAsOperator(c, approved = true) {
53
55
  /** Is the router already an operator for `owner`? Check before prompting for a signature. */
54
56
  export async function isRouterApproved(c, owner) {
55
57
  return c.public.readContract({
56
- address: c.addresses.cPoolManager,
57
- abi: cPoolManagerAbi,
58
+ address: managerC(c),
59
+ abi: managerCAbi,
58
60
  functionName: "isOperator",
59
- args: [owner, c.addresses.router],
61
+ args: [owner, routerC(c)],
60
62
  });
61
63
  }
62
64
  export async function checkReadiness(c, key, owner, need = {}) {
@@ -68,7 +70,7 @@ export async function checkReadiness(c, key, owner, need = {}) {
68
70
  const ready = async (token, amount) => {
69
71
  if (amount === undefined)
70
72
  return true;
71
- const r = await checkTokenReadiness(c, token, owner, amount);
73
+ const r = await checkTokenReadiness(c, "C", token, owner, amount);
72
74
  return !r.needsTokenApproval && !r.needsPermit2Approval;
73
75
  };
74
76
  const [operator, baseOk, quoteOk] = await Promise.all([