@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/admin.ts CHANGED
@@ -7,7 +7,7 @@
7
7
  * registry and the policies; no router.
8
8
  *
9
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 pot
10
+ * is the protocol's on both managers. A harvest has no cut (056); a pad's protocol share of the income
11
11
  * is the policy's (`PadPolicy.setSchedule`), capped by the manager at `POT_CUT_MAX`.
12
12
  */
13
13
 
@@ -214,15 +214,15 @@ export async function registryKindOf(c: LogswapClient, policy: Address): Promise
214
214
  // ─── the policies' numbers (the LOG Authority's; each bounded where it reaches the manager) ─────
215
215
 
216
216
  /**
217
- * `PadPolicy.setSchedule` (decisions 056, 067, 070): the rung's growth, the protocol's share of the pot (≤ `POT_CUT_MAX`,
218
- * recorded into each pad at birth), and the RANGE a creator chooses his cut of the pot inside at creation (its top ≤ the F
219
- * manager's `PAYEE_CUT_MAX`). The creator's top plus the protocol's share is at most the pot; the rest deepens the bid — nothing
220
- * is bought or burnt since F version 28. A change to the split applies to pads born after it; the growth moves every pad at its
217
+ * `PadPolicy.setSchedule` (decisions 056, 067, 070, 073): the rung's growth and the RANGE inside which a creator chooses their cut of the income
218
+ * at creation (its top ≤ the F manager's `PAYEE_CUT_MAX`). The rest of the income deepens the bid — nothing is bought or
219
+ * burnt since F version 28, and the protocol takes no cut of the income since F version 33 (its revenue is the income tax,
220
+ * {@link padSetIncomeTaxRate}). A change to the range applies to pads born after it; the growth moves every pad at its
221
221
  * next rung. The rung is the pool's generation. `T(0)` is per quote since decision 070: {@link padSetThresholdBase}.
222
222
  */
223
223
  export async function padSetSchedule(c: LogswapClient, policy: Address, s: PadSchedule): Promise<Hash> {
224
224
  if ("thresholdBase" in s) throw new Error("logswap: T(0) is per quote since decision 070 — padSetThresholdBase(c, policy, quote, base)");
225
- return write(c, policy, padPolicyAbi, "setSchedule", [s.thresholdGrowth, s.protocolShare, s.creatorShareMin, s.creatorShareMax]);
225
+ return write(c, policy, padPolicyAbi, "setSchedule", [s.thresholdGrowth, s.creatorShareMin, s.creatorShareMax]);
226
226
  }
227
227
 
228
228
  /**
@@ -254,12 +254,12 @@ export async function padThresholdBases(c: LogswapClient, policy: Address, quote
254
254
  );
255
255
  }
256
256
 
257
- /** `PadPolicy.thresholdOf(quote, rung)` (decision 070): the pot a pad quoted in `quote` must bank to climb `rung` (0 reads `T(0)`). */
257
+ /** `PadPolicy.thresholdOf(quote, rung)` (decision 070): the income a pad quoted in `quote` must bank to climb `rung` (0 reads `T(0)`). */
258
258
  export async function padThresholdOf(c: LogswapClient, policy: Address, quote: Address, rung: bigint | number = 0n): Promise<bigint> {
259
259
  return (await c.public.readContract({ address: policy, abi: padPolicyAbi, functionName: "thresholdOf", args: [quote, BigInt(rung)] } as never)) as bigint;
260
260
  }
261
261
 
262
- /** `PadPolicy.threshold(poolId, rung)` (decision 070): the pot pad `poolId` must bank to climb `rung`, in its own quote. */
262
+ /** `PadPolicy.threshold(poolId, rung)` (decision 070): the income pad `poolId` must bank to climb `rung`, in its own quote. */
263
263
  export async function padThreshold(c: LogswapClient, policy: Address, poolId: Hex, rung: bigint | number): Promise<bigint> {
264
264
  return (await c.public.readContract({ address: policy, abi: padPolicyAbi, functionName: "threshold", args: [poolId, BigInt(rung)] } as never)) as bigint;
265
265
  }
@@ -267,7 +267,6 @@ export async function padThreshold(c: LogswapClient, policy: Address, poolId: He
267
267
  /** A pad policy's schedule (decision 070: without `T(0)`, which is per quote — {@link padThresholdBases}). WAD numbers. */
268
268
  export interface PadSchedule {
269
269
  thresholdGrowth: bigint;
270
- protocolShare: bigint;
271
270
  creatorShareMin: bigint;
272
271
  creatorShareMax: bigint;
273
272
  }
@@ -275,18 +274,23 @@ export interface PadSchedule {
275
274
  /** Read {@link PadSchedule} off a pad policy. */
276
275
  export async function padScheduleOf(c: LogswapClient, policy: Address): Promise<PadSchedule> {
277
276
  const rd = (functionName: string) => c.public.readContract({ address: policy, abi: padPolicyAbi, functionName } as never) as Promise<bigint>;
278
- const [thresholdGrowth, protocolShare, creatorShareMin, creatorShareMax] = await Promise.all([
279
- rd("thresholdGrowth"),
280
- rd("protocolShare"),
281
- rd("creatorShareMin"),
282
- rd("creatorShareMax"),
283
- ]);
284
- return { thresholdGrowth, protocolShare, creatorShareMin, creatorShareMax };
277
+ const [thresholdGrowth, creatorShareMin, creatorShareMax] = await Promise.all([rd("thresholdGrowth"), rd("creatorShareMin"), rd("creatorShareMax")]);
278
+ return { thresholdGrowth, creatorShareMin, creatorShareMax };
279
+ }
280
+
281
+ /** `PolPolicy.setMinQuoteRatio` (decision 073): the reserve a harvest must leave in the bid (`may(Harvest)` refuses less) and a relaunch's seed must bring, a multiple of the pool's L in WAD (at most 100e18). The policy sponsor's. */
282
+ export async function polSetMinQuoteRatio(c: LogswapClient, policy: Address, ratio: bigint): Promise<Hash> {
283
+ return write(c, policy, polPolicyAbi, "setMinQuoteRatio", [ratio]);
284
+ }
285
+
286
+ /** `PadPolicy.setIncomeTaxRate` (decision 073): the share of its new income dividend the dead shares pay LOG Treasury as income tax, WAD, at most 50%. The policy sponsor's. */
287
+ export async function padSetIncomeTaxRate(c: LogswapClient, policy: Address, rate: bigint): Promise<Hash> {
288
+ return write(c, policy, padPolicyAbi, "setIncomeTaxRate", [rate]);
285
289
  }
286
290
 
287
- /** `PolPolicy.setRules`: the reserve a harvest must leave in the bid (`may(Harvest)` refuses less) and what a relaunch's seed must bring, WAD fractions of the pool's L. */
288
- export async function polSetRules(c: LogswapClient, policy: Address, s: { keepQuote: bigint; minQuoteAtSeed: bigint }): Promise<Hash> {
289
- return write(c, policy, polPolicyAbi, "setRules", [s.keepQuote, s.minQuoteAtSeed]);
291
+ /** `PolPolicy.setIncomeTaxRate` (decision 073): the share of its new income dividend the pool's authority pays LOG Treasury, WAD, at most 50%. Paid on the authority's own shares only: an authority that holds through another address pays nothing. The policy sponsor's. */
292
+ export async function polSetIncomeTaxRate(c: LogswapClient, policy: Address, rate: bigint): Promise<Hash> {
293
+ return write(c, policy, polPolicyAbi, "setIncomeTaxRate", [rate]);
290
294
  }
291
295
 
292
296
  /** `setQuoteListed` on any protocol policy: a quote a pool of that kind may be born against while it curates quotes. The LOG Authority's. */
@@ -331,36 +335,31 @@ export async function policyFeeAllowed(c: LogswapClient, policy: Address, fee: b
331
335
  return { curated, listed, allowed: !curated || listed };
332
336
  }
333
337
 
334
- /** `setMintFeeListed` on any protocol policy (065): an entry of its mint-fee menu. The LOG Authority's. */
335
- export async function policySetMintFeeListed(c: LogswapClient, policy: Address, mintFee: bigint, listed: boolean): Promise<Hash> {
336
- return write(c, policy, fPolicyBaseAbi, "setMintFeeListed", [mintFee, listed]);
337
- }
338
+ /** `PolicyRegistry.CreationMode` (decision 073): who may create under a policy. Open = 0, Restricted = 1 (the initializer list), SponsorOnly = 2 (bound to a sponsor, permanent). */
339
+ export type CreationMode = "open" | "restricted" | "sponsorOnly";
340
+ const CREATION_MODES: readonly CreationMode[] = ["open", "restricted", "sponsorOnly"];
338
341
 
339
- /** `setMintFeeCurated` on any protocol policy: on, a birth proposing an unlisted mint fee is refused (`MintFeeNotListed`). */
340
- export async function policySetMintFeeCurated(c: LogswapClient, policy: Address, curated: boolean): Promise<Hash> {
341
- return write(c, policy, fPolicyBaseAbi, "setMintFeeCurated", [curated]);
342
+ /** `PolicyRegistry.setCreationMode(policy, mode)` (the LOG Authority): replaces the per-policy creator lists (064). A sponsor-bound policy cannot leave `sponsorOnly`. */
343
+ export async function registrySetCreationMode(c: LogswapClient, policy: Address, mode: CreationMode): Promise<Hash> {
344
+ return registryWrite(c, "setCreationMode", [policy, CREATION_MODES.indexOf(mode)]);
342
345
  }
343
346
 
344
- /**
345
- * A policy's mint-fee menu, for a create form (065): which of `candidates` it lists, and whether it
346
- * curates at all (uncurated, any fee in the domain is accepted — the desk's policy never curates).
347
- * The candidates are the app's — typically {@link presetMintFee} of each listed swap tier.
348
- */
349
- export async function policyMintFeeMenu(c: LogswapClient, policy: Address, candidates: readonly bigint[]): Promise<{ curated: boolean; listed: bigint[] }> {
350
- const rd = (functionName: string, args: readonly unknown[] = []) =>
351
- c.public.readContract({ address: policy, abi: fPolicyBaseAbi, functionName, args } as never) as Promise<boolean>;
352
- const [curated, ...flags] = await Promise.all([rd("mintFeeCurated"), ...candidates.map((m) => rd("mintFeeListed", [m]))]);
353
- return { curated, listed: candidates.filter((_, i) => flags[i]) };
347
+ /** `PolicyRegistry.setInitializerListed(policy, who, allowed)` (the LOG Authority): who may create under a `restricted` policy, authenticated as the caller or a trusted forwarder's user. */
348
+ export async function registrySetInitializerListed(c: LogswapClient, policy: Address, who: Address, allowed: boolean): Promise<Hash> {
349
+ return registryWrite(c, "setInitializerListed", [policy, who, allowed]);
354
350
  }
355
351
 
356
- /** `setCreatorListed` on any protocol policy (064): a creator onboarded under a service agreement. */
357
- export async function policySetCreatorListed(c: LogswapClient, policy: Address, who: Address, listed: boolean): Promise<Hash> {
358
- return write(c, policy, fPolicyBaseAbi, "setCreatorListed", [who, listed]);
352
+ /** `PolicyRegistry.setForwarderTrusted` (the LOG Authority): a router whose `user()` names the creator. Moved off the public policy in F version 33. */
353
+ export async function registrySetForwarderTrusted(c: LogswapClient, forwarder: Address, trusted: boolean): Promise<Hash> {
354
+ return registryWrite(c, "setForwarderTrusted", [forwarder, trusted]);
359
355
  }
360
356
 
361
- /** `setCreatorCurated` on any protocol policy: on, only listed creators may create on that kind (C: the caller; F: `key.creator`). */
362
- export async function policySetCreatorCurated(c: LogswapClient, policy: Address, curated: boolean): Promise<Hash> {
363
- return write(c, policy, fPolicyBaseAbi, "setCreatorCurated", [curated]);
357
+ /** `PolicyRegistry.creationMode(policy)`. */
358
+ export async function registryCreationMode(c: LogswapClient, policy: Address): Promise<CreationMode> {
359
+ const registry = await policyRegistryOf(c);
360
+ if (registry === ZERO) return "open";
361
+ const m = (await c.public.readContract({ address: registry, abi: policyRegistryAbi, functionName: "creationMode", args: [policy] } as never)) as number;
362
+ return CREATION_MODES[Number(m)] ?? "open";
364
363
  }
365
364
 
366
365
  /** `PublicPolicy.setPairListed` (064): a C pair a market may be born on while pairs are curated. Directional (base, quote). */
@@ -378,52 +377,46 @@ export async function gateSetSpacingListed(c: LogswapClient, policy: Address, ti
378
377
  return write(c, policy, publicPolicyAbi, "setSpacingListed", [tickSpacing, listed]);
379
378
  }
380
379
 
381
- /** `PublicPolicy.setForwarderTrusted` (064): a router whose `user()` the gate takes as the creator. */
382
- export async function gateSetForwarderTrusted(c: LogswapClient, policy: Address, forwarder: Address, trusted: boolean): Promise<Hash> {
383
- return write(c, policy, publicPolicyAbi, "setForwarderTrusted", [forwarder, trusted]);
384
- }
385
-
386
380
  /**
387
381
  * @deprecated C version 8 fixes the gate at construction (066): there is no `setGate`. Open or close
388
- * C through the gate's lists (`policySetCreatorCurated`, `gateSetPairCurated`, `gateSetSpacingListed`, …).
382
+ * C through the gate's lists (`registrySetCreationMode`, `gateSetPairCurated`, `gateSetSpacingListed`, …).
389
383
  */
390
384
  export async function setCGate(_c: LogswapClient, _gate: Address): Promise<Hash> {
391
385
  throw new Error("logswap: the C gate is fixed at construction since C version 8 (decision 066); change its lists instead");
392
386
  }
393
387
 
394
- /** The C manager's gate (`address(0)`: permissionless, a fee-free market then refused). */
395
- export async function cGate(c: LogswapClient): Promise<Address> {
396
- return c.public.readContract({ address: c.addresses.cPoolManager, abi: cPoolManagerAbi, functionName: "gate" } as never) as Promise<Address>;
397
- }
398
-
399
388
  export interface CGateRules {
389
+ /** The registry admits `creator` to create under `key.policy` (creation mode, initializer list, sponsor binding; decision 073). */
400
390
  creatorOk: boolean;
401
391
  quoteOk: boolean;
402
392
  pairOk: boolean;
403
393
  feeOk: boolean;
404
394
  spacingOk: boolean;
405
- /** A market on (base, quote, fee) already exists, whatever its spacing: the gate refuses another (064 (b)). */
395
+ /** A market on (base, quote, fee) already exists, whatever its spacing: the policy refuses another (064 (b)). */
406
396
  exists: boolean;
407
- /** Whether `router` is a trusted forwarder — `createMarket` through it is then checked against `creator`. */
397
+ /** Whether `router` is a trusted forwarder on the registry — `createMarket` through it is then checked against `creator`. */
408
398
  routerTrusted: boolean;
409
- /** Every check passes: the gate would admit this market from this creator (the mint fee aside — see {@link policyMintFeeMenu}). */
399
+ /** Every check passes: the policy would admit this market from this creator (the mint fee is a key field, checked by the manager). */
410
400
  admitted: boolean;
411
401
  }
412
402
 
413
403
  /**
414
404
  * The public policy's C checks for one candidate market and creator, in one round of reads — what
415
- * the create form shows before a wallet is asked (064). `router` is the router the form will go
416
- * through (`c.addresses.router` by default).
405
+ * the create form shows before a wallet is asked (064, 073). The policy is `key.policy`; the registry
406
+ * is asked `admit(policy, caller, 0)`, with the caller being the router when it is a trusted forwarder
407
+ * (it then names `creator` itself) and `creator` otherwise.
417
408
  */
418
409
  export async function cGateRules(c: LogswapClient, a: { key: PoolKey; creator: Address; router?: Address; gate?: Address }): Promise<CGateRules> {
419
- const g = a.gate ?? (c.addresses.publicPolicy as Address);
410
+ const g = a.gate ?? (a.key.policy as Address);
420
411
  const rd = <T>(functionName: string, args: readonly unknown[] = []) =>
421
412
  c.public.readContract({ address: g, abi: publicPolicyAbi, functionName, args } as never) as Promise<T>;
422
413
  const { key } = a;
423
- const [creatorCurated, creatorListed, quoteCurated, quoteListed, pairCurated, pairListed, feeCurated, feeListed, spacingListed, market, routerTrusted] =
414
+ const registry = await policyRegistryOf(c);
415
+ const router = a.router ?? c.addresses.router;
416
+ const registryRd = <T>(functionName: string, args: readonly unknown[]) =>
417
+ c.public.readContract({ address: registry, abi: policyRegistryAbi, functionName, args } as never) as Promise<T>;
418
+ const [quoteCurated, quoteListed, pairCurated, pairListed, feeCurated, feeListed, spacingListed, market, routerTrusted, creatorOk] =
424
419
  await Promise.all([
425
- rd<boolean>("creatorCurated"),
426
- rd<boolean>("creatorListed", [a.creator]),
427
420
  rd<boolean>("quoteCurated"),
428
421
  rd<boolean>("quoteListed", [key.quote]),
429
422
  rd<boolean>("pairCurated"),
@@ -432,10 +425,13 @@ export async function cGateRules(c: LogswapClient, a: { key: PoolKey; creator: A
432
425
  rd<boolean>("feeListed", [key.swapFee]),
433
426
  rd<boolean>("spacingListed", [key.tickSpacing]),
434
427
  rd<Hex>("cMarketOf", [key.base, key.quote, key.swapFee]),
435
- rd<boolean>("forwarderTrusted", [a.router ?? c.addresses.router]),
428
+ registry === ZERO ? Promise.resolve(false) : registryRd<boolean>("forwarderTrusted", [router]),
429
+ registry === ZERO
430
+ ? Promise.resolve(true)
431
+ : registryRd<Address>("admit", [g, a.creator, ZERO]).then(() => true, () => false),
436
432
  ]);
437
433
  const r = {
438
- creatorOk: !creatorCurated || creatorListed,
434
+ creatorOk,
439
435
  quoteOk: !quoteCurated || quoteListed,
440
436
  pairOk: !pairCurated || pairListed,
441
437
  feeOk: !feeCurated || feeListed,
@@ -453,19 +449,11 @@ export async function cGateRules(c: LogswapClient, a: { key: PoolKey; creator: A
453
449
  */
454
450
  export const gateErrorAbi = [
455
451
  ...publicPolicyAbi.filter((x) => x.type === "error"),
452
+ // creation admission moved to the registry in F 33 / C 10 (073): a refusal there surfaces through the manager's birth
453
+ ...policyRegistryAbi.filter((x) => x.type === "error" && ["SponsorOnly", "InitializerNotListed", "InvalidForwardedUser", "NotListed"].includes(x.name)),
456
454
  ...padPolicyAbi.filter((x) => x.type === "error" && (x.name === "PadExists" || x.name === "NoThreshold")),
457
455
  ] as const;
458
456
 
459
- /** `PublicPolicy.setListed`: an asset a curated seed may hold. */
460
- export async function publicSetListed(c: LogswapClient, policy: Address, token: Address, listed: boolean): Promise<Hash> {
461
- return write(c, policy, publicPolicyAbi, "setListed", [token, listed]);
462
- }
463
-
464
- /** `PublicPolicy.setCurated`: whether every public seed is checked against the list. */
465
- export async function publicSetCurated(c: LogswapClient, policy: Address, curated: boolean): Promise<Hash> {
466
- return write(c, policy, publicPolicyAbi, "setCurated", [curated]);
467
- }
468
-
469
457
  // ─── the LOG Treasury (066): receives, administers nothing ───────────────────
470
458
 
471
459
  function manager(c: LogswapClient, side: "C" | "F"): { address: Address; abi: readonly unknown[] } {
package/src/client.ts CHANGED
@@ -180,7 +180,11 @@ function guardChain(wallet: WalletClient, pub: PublicClient): WalletClient {
180
180
  * takes `SwapParams` (the router's ABI does not move), object-word event names (`MarketCreated`,
181
181
  * `PositionMinted`, ...), `MarketCreated` carries creator, mintFee and swapFeeTax. No pool id moved.
182
182
  */
183
- export const EXPECTED_VERSION = 9n;
183
+ // 11 (decision 078): `mintFee` is a key field (the creator's pick, `2 * swapFee <= mintFee <= 2%`); `initialize(key, x0)`
184
+ // takes no separate mint fee, `createMarket` neither; `getPool` drops `mintFee` and the gates' mint-fee menus are gone.
185
+ // Every C pool id moved.
186
+ // 12 (decisions 079-081): `Action` ordinals, the key is `CPoolKey` (names only). No pool id moved.
187
+ export const EXPECTED_VERSION = 12n;
184
188
  /**
185
189
  * The F manager's own tag (5 — the key's salt, pool names, the sponsor registry;
186
190
  * 4 was the income-only harvest cut).
@@ -274,8 +278,15 @@ export const EXPECTED_VERSION = 9n;
274
278
  // No pool id moved.
275
279
  // 31 (decision 072): `DividendClaimed` names the generation (`gen`, indexed, after `poolId`); `lock` / `unlock` emit
276
280
  // `LienLocked` / `LienUnlocked`. No selector, storage layout or pool id moved.
281
+ // 33 (decisions 073, 074): sponsor-bound policies, the income fee, registry admission.
282
+ // 34-38 (decisions 075-085): one liquidity routine. `FPoolKey` holds no weights and no cap and gains `mintFee` (every pool
283
+ // id moved); `initialize(key)`; `seed` / `retire` / `setLegs` are gone for `deployLiquidity(poolId, baseAssets,
284
+ // quoteAmount, lnCapOverSeed, to)` (it SETS THE BOOK on an unfunded or a live pool), `close(poolId, to)` and
285
+ // `regenerate(poolId, to)`; asset membership is fixed by the key; `LiquidityDeployed` echoes the input,
286
+ // `GenerationSeeded` / `LegsSet` are gone; the lens `fPool` field is `baseLegs`, the cap `lnCapOverSeed`; the pot and the
287
+ // income fee are the income and the income tax (`IncomeReleased`, `incomeHeld`, `incomeTax`); a pad is uncapped.
277
288
  // A breaking bump: raised in the same change.
278
- export const EXPECTED_F_VERSION = 31n;
289
+ export const EXPECTED_F_VERSION = 38n;
279
290
 
280
291
  export async function assertVersion(c: LogswapClient, expected = EXPECTED_VERSION): Promise<void> {
281
292
  const { cPoolManagerAbi, fPoolManagerAbi } = await import("./generated.js");