@logswap/sdk 0.5.90 → 0.5.92

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 +136 -31
  2. package/dist/actions.js +4 -3
  3. package/dist/admin.d.ts +96 -925
  4. package/dist/admin.js +113 -194
  5. package/dist/chains.d.ts +13 -4
  6. package/dist/chains.js +22 -9
  7. package/dist/claims.d.ts +1 -1
  8. package/dist/claims.js +11 -9
  9. package/dist/client.d.ts +42 -20
  10. package/dist/client.js +86 -26
  11. package/dist/fees.d.ts +1 -1
  12. package/dist/fees.js +5 -4
  13. package/dist/fpool.d.ts +327 -1120
  14. package/dist/fpool.js +408 -475
  15. package/dist/generated.d.ts +5017 -7631
  16. package/dist/generated.js +3040 -4879
  17. package/dist/history.js +12 -14
  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 +143 -249
  42. package/src/chains.ts +32 -13
  43. package/src/claims.ts +11 -10
  44. package/src/client.ts +111 -39
  45. package/src/fees.ts +6 -6
  46. package/src/fpool.ts +555 -648
  47. package/src/generated.ts +3063 -4904
  48. package/src/history.ts +11 -11
  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,24 @@
1
1
  /**
2
- * admin — the protocol's writes: the C swap-fee tax (decisions 060), the policies a pool may be
3
- * born with (the registry's), the policies' own numbers (the quote list, the fee tiers, a pad's
4
- * schedule, a POL's rules), and the two roles' two-step handovers (decision 066): the LOG Authority
5
- * (the registry's `authority`) administers everything here; the LOG Treasury (`treasury` on each
6
- * manager) only receives, and is replaced by the authority's `proposeTreasury`. Plain writes to the managers, the
7
- * registry and the policies; no router.
2
+ * admin — the protocol's writes: the policies a pool may be born under (the registry's list, its sunsets), the C manager's
3
+ * creation modes, the two roles' two-step handovers (decision 066): the LOG Authority (the registry's `logAuthority`)
4
+ * administers the registry and both managers; the LOG Treasury (`treasury` on each manager) only receives, and is replaced by
5
+ * the authority's `proposeTreasury`. Plain writes to the managers and the registry; no router.
8
6
  *
9
- * The mint fee has no cut to set since C version 6 / F version 24 (decisions 058): the whole fee
10
- * 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`.
7
+ * The policies are immutable and deployed by the LOG (decision 098; policy.md): a policy has no setter of its numbers — its fee
8
+ * mask, quotes, bases, buffer, tax and cap bound are constructor immutables — so there is no wrapper that writes one. A change is
9
+ * a new policy, approved ({@link registryApprove}); the old one is sunset ({@link registrySunset}) and its pools run to their next
10
+ * close. The key's policy is the pool's for life: the registry's `migrate` and `orphan` are gone (F 41). What remains here for the
11
+ * policies is reading their numbers; their per-pool settings are in `fpool.ts`.
12
+ *
13
+ * The mint fee has no cut to set since C version 6 / F version 24 (decisions 058): the whole fee is the protocol's on both
14
+ * managers. A harvest has no cut (056); the protocol's share of a harvest's income is the policy's `incomeTaxRate` on the
15
+ * payer's slice, capped by the manager at `INCOME_TAX_MAX`.
12
16
  */
17
+ import { poolId as keyId } from "./keys.js";
18
+ import { managerC, routerC } from "./client.js";
13
19
  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";
20
+ import { managerCAbi, managerFAbi, policyFAbi, policyRegistryAbi, sponsorPolicyCAbi } from "./generated.js";
21
+ import { bytes32ToText, fFeeListed, fPoolKindOfPolicy, fPolicyTermsOf, textToBytes32 } from "./fpool.js";
16
22
  function wallet(c) {
17
23
  if (!c.wallet)
18
24
  throw new Error("a wallet client is required");
@@ -22,15 +28,19 @@ function write(c, address, abi, functionName, args) {
22
28
  return wallet(c).writeContract({ address, abi, functionName, args, chain: c.wallet.chain, account: c.wallet.account });
23
29
  }
24
30
  /**
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.
31
+ * The C swap-fee tax (decisions 060, 066, 098): the protocol's share of every swap fee a C position is
32
+ * paid (claims and the burn's auto-claim), WAD. `tax` is the level a market born under `policy` (default: the deployment's
33
+ * `publicPolicyC`) is given — the policy's immutable `swapFeeTax`; each market keeps the level of its birth for
34
+ * life — read it with {@link cMarketSwapFeeTax} or `getPool(key).swapFeeTax`. A different level is a different policy.
35
+ * `max` is the manager's bound.
29
36
  */
30
- export async function cSwapFeeTax(c) {
37
+ export async function cSwapFeeTax(c, policy) {
38
+ const address = policy ?? c.addresses.publicPolicyC;
39
+ if (!address)
40
+ throw new Error("logswap: this deployment carries no C sponsored policy (addresses.publicPolicyC); pass one");
31
41
  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" }),
42
+ c.public.readContract({ address, abi: sponsorPolicyCAbi, functionName: "swapFeeTax" }),
43
+ c.public.readContract({ address: managerC(c), abi: managerCAbi, functionName: "SWAP_FEE_TAX_MAX" }),
34
44
  ]);
35
45
  return { tax, max };
36
46
  }
@@ -38,13 +48,6 @@ export async function cSwapFeeTax(c) {
38
48
  export async function cMarketSwapFeeTax(c, key) {
39
49
  return (await getPool(c, key)).swapFeeTax;
40
50
  }
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
51
  // ─── the registry: the LOG Authority's (046, 066) ───────────────────────────
49
52
  const ZERO = "0x0000000000000000000000000000000000000000";
50
53
  /**
@@ -55,7 +58,7 @@ const ZERO = "0x0000000000000000000000000000000000000000";
55
58
  export async function policyRegistryOf(c) {
56
59
  if (c.addresses.policyRegistry)
57
60
  return c.addresses.policyRegistry;
58
- return (await c.public.readContract({ address: c.addresses.fPoolManager, abi: fPoolManagerAbi, functionName: "registry" }));
61
+ return (await c.public.readContract({ address: c.addresses.managerF, abi: managerFAbi, functionName: "registry" }));
59
62
  }
60
63
  /** Whether `policy` is approved now — listed and not yet sunset. True everywhere on a deployment with no registry. */
61
64
  export async function policyApproved(c, policy) {
@@ -65,9 +68,9 @@ export async function policyApproved(c, policy) {
65
68
  return c.public.readContract({ address: registry, abi: policyRegistryAbi, functionName: "isApproved", args: [policy] });
66
69
  }
67
70
  /**
68
- * Every policy listed, sunset ones included — one flat list, each with the kind
69
- * it says it is; `kind` narrows it to one, which is what a create form's dropdown reads. Empty
70
- * with no registry.
71
+ * Every policy listed, sunset ones included — one flat list, each with the kind its terms spell; `kind` narrows it to one,
72
+ * which is what a create form's dropdown reads. The registry is one list for both managers: a C policy is on it with `kind`
73
+ * `null`. Empty with no registry.
71
74
  */
72
75
  export async function registryPolicies(c, kind) {
73
76
  const registry = await policyRegistryOf(c);
@@ -79,7 +82,7 @@ export async function registryPolicies(c, kind) {
79
82
  const all = await Promise.all(list.map(async (policy) => {
80
83
  const [[listed, until, , name], tag] = await Promise.all([
81
84
  c.public.readContract({ address: registry, abi: policyRegistryAbi, functionName: "entries", args: [policy] }),
82
- fPoolKindOfPolicy(c, policy),
85
+ fPoolKindOfPolicy(c, policy).catch(() => null), // a C policy answers no F terms
83
86
  ]);
84
87
  return { policy, kind: tag, name: bytes32ToText(name), until, approved: listed && (until === 0n || now < until) };
85
88
  }));
@@ -143,31 +146,12 @@ export const registryAcceptOwner = acceptLogAuthority;
143
146
  * {@link registryApprove} under the policy's own tag as its name, false is {@link registryRevoke}.
144
147
  */
145
148
  export async function setPolicyApproved(c, policy, approved) {
146
- return approved ? registryApprove(c, policy, await fPoolKindOfPolicy(c, policy)) : registryRevoke(c, policy);
147
- }
148
- /**
149
- * Move a pool to another approved policy of the same kind: the LOG Authority's alone, a forced move
150
- * (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.
158
- *
159
- * Pass the pool's `key` when in hand. Given only `poolId`, the key is rebuilt from the pool's
160
- * `PoolCreated` log ({@link fPoolKeyOfPool}) with `salt` (zero by default) and checked against
161
- * the id — the log does not carry the salt, so a salted pool needs it named.
162
- */
163
- export async function fPoolMigrate(c, a) {
164
- 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]);
149
+ return approved ? registryApprove(c, policy, await fPoolKindOfPolicy(c, policy).catch(() => "policy")) : registryRevoke(c, policy);
166
150
  }
167
151
  /**
168
- * The kind tag the registry recorded for `policy` at approval (`kindOf`, F version 20) — refreshed
169
- * on re-approval and kept after a revoke; what `migrate` compares, never the policy's live
170
- * answer. "" for a policy the registry never approved (or a deployment with no registry).
152
+ * The name the registry recorded for `policy` at approval (`kindOf`, F version 20: `approve(policy, name)`'s word) — refreshed
153
+ * on re-approval and kept after a revoke. The LOG's own instances are approved as `public`, `private`, `pol`, `pad`; what a
154
+ * policy IS is its terms ({@link fPolicyTermsOf}). "" for a policy the registry never approved (or a deployment with no registry).
171
155
  */
172
156
  export async function registryKindOf(c, policy) {
173
157
  const registry = await policyRegistryOf(c);
@@ -176,111 +160,55 @@ export async function registryKindOf(c, policy) {
176
160
  const word = (await c.public.readContract({ address: registry, abi: policyRegistryAbi, functionName: "kindOf", args: [policy] }));
177
161
  return bytes32ToText(word);
178
162
  }
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
- /** `PadPolicy.thresholdSet(quote)` and `thresholdBaseOf(quote)` for each quote asked (decision 070). */
201
- export async function padThresholdBases(c, policy, quotes) {
202
- const rd = (functionName, quote) => c.public.readContract({ address: policy, abi: padPolicyAbi, functionName, args: [quote] });
203
- return Promise.all(quotes.map(async (quote) => {
204
- const [set, base] = await Promise.all([rd("thresholdSet", quote), rd("thresholdBaseOf", quote)]);
205
- return { quote, set, base };
206
- }));
207
- }
208
- /** `PadPolicy.thresholdOf(quote, rung)` (decision 070): the income a pad quoted in `quote` must bank to climb `rung` (0 reads `T(0)`). */
209
- export async function padThresholdOf(c, policy, quote, rung = 0n) {
210
- return (await c.public.readContract({ address: policy, abi: padPolicyAbi, functionName: "thresholdOf", args: [quote, BigInt(rung)] }));
211
- }
212
- /** `PadPolicy.threshold(poolId, rung)` (decision 070): the income pad `poolId` must bank to climb `rung`, in its own quote. */
213
- export async function padThreshold(c, policy, poolId, rung) {
214
- return (await c.public.readContract({ address: policy, abi: padPolicyAbi, functionName: "threshold", args: [poolId, BigInt(rung)] }));
215
- }
216
- /** Read {@link PadSchedule} off a pad policy. */
217
- export async function padScheduleOf(c, policy) {
218
- const rd = (functionName) => c.public.readContract({ address: policy, abi: padPolicyAbi, functionName });
219
- const [thresholdGrowth, creatorShareMin, creatorShareMax] = await Promise.all([rd("thresholdGrowth"), rd("creatorShareMin"), rd("creatorShareMax")]);
220
- return { thresholdGrowth, creatorShareMin, creatorShareMax };
221
- }
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. */
163
+ // ─── the F policy's lists: immutable, so read-only here (policy.md §4.1) ─────
164
+ // The quotes a pool may be born on, the bases it may hold and the fee entries it may use are constructor values of the
165
+ // policy the LOG deploys. The whole set of numbers is `fPolicyTermsOf`; these answer one candidate.
166
+ /** Whether `quote` passes an F `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
167
  export async function policyQuoteAllowed(c, policy, quote) {
244
168
  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] }),
169
+ c.public.readContract({ address: policy, abi: policyFAbi, functionName: "quoteCurated" }),
170
+ c.public.readContract({ address: policy, abi: policyFAbi, functionName: "quoteListed", args: [quote] }),
247
171
  ]);
248
172
  return { curated, listed, allowed: !curated || listed };
249
173
  }
250
- /**
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.
254
- */
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) {
174
+ /** Whether `base` passes an F `policy`'s birth check now: it curates bases (`baseCurated`) and lists it, or it does not curate. */
175
+ export async function policyBaseAllowed(c, policy, base) {
264
176
  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] }),
177
+ c.public.readContract({ address: policy, abi: policyFAbi, functionName: "baseCurated" }),
178
+ c.public.readContract({ address: policy, abi: policyFAbi, functionName: "baseListed", args: [base] }),
267
179
  ]);
268
180
  return { curated, listed, allowed: !curated || listed };
269
181
  }
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`. */
182
+ /**
183
+ * Whether the swap fee at `swapFeeIdx` of the F fee list passes `policy`'s birth check now (`feeMask`, policy.md §6). `curated` is true
184
+ * when the policy masks the list (a non-zero mask); with none, every entry is allowed. The mint fee follows the swap fee and is not asked.
185
+ */
186
+ export async function policyFeeAllowed(c, policy, swapFeeIdx) {
187
+ const { feeMask } = await fPolicyTermsOf(c, policy);
188
+ const listed = fFeeListed(feeMask, swapFeeIdx);
189
+ return { curated: feeMask !== 0, listed, allowed: listed };
190
+ }
191
+ const CREATION_MODES = ["open", "sponsorOnly"];
192
+ /** `PolicyRegistry.setCreationMode(policy, mode)` (the LOG Authority). A sponsored policy is approved `sponsorOnly`. */
272
193
  export async function registrySetCreationMode(c, policy, mode) {
273
194
  return registryWrite(c, "setCreationMode", [policy, CREATION_MODES.indexOf(mode)]);
274
195
  }
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
196
  /** `PolicyRegistry.setForwarderTrusted` (the LOG Authority): a router whose `user()` names the creator. Moved off the public policy in F version 33. */
280
197
  export async function registrySetForwarderTrusted(c, forwarder, trusted) {
281
198
  return registryWrite(c, "setForwarderTrusted", [forwarder, trusted]);
282
199
  }
283
200
  /** `PolicyRegistry.creationMode(policy)`. */
201
+ /**
202
+ * `PolicyRegistry.userOf(caller)` (C 15, decision 097): the account a caller acts for — the user a trusted forwarder
203
+ * (a router) names, else the caller itself. The account the managers authenticate as a market's creator and as the
204
+ * first minter; what a create form compares to the key's `creator`.
205
+ */
206
+ export async function registryUserOf(c, caller) {
207
+ const registry = await policyRegistryOf(c);
208
+ if (registry === ZERO)
209
+ return caller;
210
+ return (await c.public.readContract({ address: registry, abi: policyRegistryAbi, functionName: "userOf", args: [caller] }));
211
+ }
284
212
  export async function registryCreationMode(c, policy) {
285
213
  const registry = await policyRegistryOf(c);
286
214
  if (registry === ZERO)
@@ -288,79 +216,70 @@ export async function registryCreationMode(c, policy) {
288
216
  const m = (await c.public.readContract({ address: registry, abi: policyRegistryAbi, functionName: "creationMode", args: [policy] }));
289
217
  return CREATION_MODES[Number(m)] ?? "open";
290
218
  }
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");
219
+ /** Whether `policy` (a `SponsorPolicyC`) admits C tick spacing `tickSpacing`: it curates spacings (`spacingCurated`) and lists it, or it does not curate. */
220
+ export async function policySpacingAllowed(c, policy, tickSpacing) {
221
+ const [curated, listed] = await Promise.all([
222
+ c.public.readContract({ address: policy, abi: sponsorPolicyCAbi, functionName: "spacingCurated" }),
223
+ c.public.readContract({ address: policy, abi: sponsorPolicyCAbi, functionName: "spacingListed", args: [tickSpacing] }),
224
+ ]);
225
+ return { curated, listed, allowed: !curated || listed };
309
226
  }
310
227
  /**
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.
228
+ * 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
229
+ * is asked (064, 073, 097, 098). The policy is `key.policy` (a `SponsorPolicyC`); the registry is asked `admit(policy, creator, creator)`: the
230
+ * 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
231
+ * trusted forwarder's `user()`). The policy's pair list is gone (098).
315
232
  */
316
233
  export async function cGateRules(c, a) {
317
234
  const g = a.gate ?? a.key.policy;
318
- const rd = (functionName, args = []) => c.public.readContract({ address: g, abi: publicPolicyAbi, functionName, args });
235
+ const rd = (functionName, args = []) => c.public.readContract({ address: g, abi: sponsorPolicyCAbi, functionName, args });
319
236
  const { key } = a;
237
+ const creator = a.creator ?? key.creator;
320
238
  const registry = await policyRegistryOf(c);
321
- const router = a.router ?? c.addresses.router;
239
+ const router = a.router ?? routerC(c);
322
240
  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([
241
+ const [quoteCurated, quoteListed, feeListed, mintFeeListed, spacingCurated, spacingListed, canonical, state, routerTrusted, creatorOk] = await Promise.all([
324
242
  rd("quoteCurated"),
325
243
  rd("quoteListed", [key.quote]),
326
- rd("pairCurated"),
327
- rd("pairListed", [key.base, key.quote]),
328
- rd("feeCurated"),
329
- rd("feeListed", [key.swapFee]),
244
+ rd("swapFeeListed", [key.swapFee]),
245
+ rd("mintFeeListed", [key.mintFee]),
246
+ rd("spacingCurated"),
330
247
  rd("spacingListed", [key.tickSpacing]),
331
- rd("cMarketOf", [key.base, key.quote, key.swapFee]),
248
+ rd("canonical"),
249
+ getPool(c, key),
332
250
  registry === ZERO ? Promise.resolve(false) : registryRd("forwarderTrusted", [router]),
333
251
  registry === ZERO
334
252
  ? Promise.resolve(true)
335
- : registryRd("admit", [g, a.creator, ZERO]).then(() => true, () => false),
253
+ : registryRd("admit", [g, creator, creator]).then((who) => who.toLowerCase() === creator.toLowerCase(), () => false),
336
254
  ]);
337
255
  const r = {
338
256
  creatorOk,
339
257
  quoteOk: !quoteCurated || quoteListed,
340
- pairOk: !pairCurated || pairListed,
341
- feeOk: !feeCurated || feeListed,
342
- spacingOk: spacingListed,
343
- exists: BigInt(market) !== 0n,
258
+ feeOk: feeListed,
259
+ mintFeeOk: mintFeeListed,
260
+ spacingOk: !spacingCurated || spacingListed,
261
+ saltOk: !canonical || key.salt === "0x0000000000000000000000000000000000000000000000000000000000000000",
262
+ exists: state.initialized,
344
263
  routerTrusted,
345
264
  };
346
- return { ...r, admitted: r.creatorOk && r.quoteOk && r.pairOk && r.feeOk && r.spacingOk && !r.exists };
347
- }
348
- /**
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)`
351
- * in the pad's quote, decision 070).
352
- */
353
- 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)),
357
- ...padPolicyAbi.filter((x) => x.type === "error" && (x.name === "PadExists" || x.name === "NoThreshold")),
358
- ];
265
+ return { ...r, admitted: r.creatorOk && r.quoteOk && r.feeOk && r.mintFeeOk && r.spacingOk && r.saltOk && !r.exists };
266
+ }
267
+ const isAbiError = (x) => x.type === "error";
268
+ export const gateErrorAbi = (() => {
269
+ const seen = new Set();
270
+ const sig = (x) => `${x.name}(${x.inputs.map((i) => i.type).join(",")})`;
271
+ const all = (abi) => abi.filter(isAbiError);
272
+ const errors = [
273
+ ...all(sponsorPolicyCAbi),
274
+ ...all(policyFAbi),
275
+ // creation admission is the registry's (F 33 / C 10, 073): a refusal there surfaces through the manager's birth
276
+ ...all(policyRegistryAbi).filter((x) => ["SponsorOnly", "InvalidForwardedUser", "NotListed"].includes(x.name)),
277
+ ];
278
+ return errors.filter((x) => (seen.has(sig(x)) ? false : (seen.add(sig(x)), true)));
279
+ })();
359
280
  // ─── the LOG Treasury (066): receives, administers nothing ───────────────────
360
281
  function manager(c, side) {
361
- return side === "C"
362
- ? { address: c.addresses.cPoolManager, abi: cPoolManagerAbi }
363
- : { address: c.addresses.fPoolManager, abi: fPoolManagerAbi };
282
+ return side === "C" ? { address: managerC(c), abi: managerCAbi } : { address: c.addresses.managerF, abi: managerFAbi };
364
283
  }
365
284
  /** A manager's treasury — where its protocol revenue goes — and the proposed next one. */
366
285
  export async function logTreasury(c, side) {
@@ -389,9 +308,9 @@ export const proposeCollector = proposeTreasury;
389
308
  /** @deprecated use {@link acceptTreasury}. */
390
309
  export const acceptCollector = acceptTreasury;
391
310
  /**
392
- * `CPoolManager.collectProtocolFees(key)`: pay one market's `protocolOwed` (mint fees and swap-fee
311
+ * `ManagerC.collectProtocolFees(poolId)`: pay one market's `protocolOwed` (mint fees and swap-fee
393
312
  * tax) to the treasury. Anyone may send it (066); the destination is fixed.
394
313
  */
395
314
  export async function collectCProtocolFees(c, key) {
396
- return write(c, c.addresses.cPoolManager, cPoolManagerAbi, "collectProtocolFees", [key]);
315
+ return write(c, managerC(c), managerCAbi, "collectProtocolFees", [keyId(key)]);
397
316
  }
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 F policy (`PolicyF`, `open`: anyone creates at salt zero, no gate ever; policy.md). */
129
135
  publicPolicy: Address;
136
+ /** The LOG's desk on F (`PolicyF`, closed: the LOG creates, gates by pool). The artifact key predates 098 and is kept. */
130
137
  privatePolicy: Address;
138
+ /** The LOG's POL policy on F (`PolicyF`: one base, a bid buffer, an income tax). */
131
139
  polPolicy: Address;
140
+ /** The LOG's pad policy on F (`PolicyF`, `seedToDead`: income-only harvests, never closes). */
132
141
  padPolicy: Address;
133
- router: Address;
134
- lens: Address;
142
+ /** The LOG's open sponsored instance on C (`SponsorPolicyC`). Absent while the chain has no C stack. */
143
+ publicPolicyC?: 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): zero is absent. An `orphanPolicy` key on an older artifact is ignored (F 41 has none). */
118
+ const OPTIONAL_POLICIES = ["publicPolicyC"];
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,29 @@ 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 } : {}),
182
195
  policyRegistry: d.policyRegistry,
183
196
  permit2: d.permit2,
184
197
  ...(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([