@logswap/sdk 0.5.89 → 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 +80 -13
  2. package/dist/actions.js +6 -5
  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 +5753 -6227
  16. package/dist/generated.js +3097 -3664
  17. package/dist/history.js +13 -11
  18. package/dist/index.d.ts +5 -5
  19. package/dist/index.js +5 -5
  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 +6 -5
  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 +3110 -3671
  48. package/src/history.ts +11 -9
  49. package/src/index.ts +5 -5
  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/README.md CHANGED
@@ -1,8 +1,9 @@
1
1
  # logswap-sdk
2
2
 
3
3
  TypeScript SDK for [Logswap](https://logswap.org), the liquidity
4
- primitive introducing the **logarithmic invariant** — typed wrappers over the `CPoolManager` /
5
- `FPoolManager` / `LogswapRouter` / `LogswapLens` surface.
4
+ primitive introducing the **logarithmic invariant** — typed wrappers over the `ManagerF` / `ManagerC`,
5
+ `RouterF` / `RouterC` and `LensF` / `LensC` surface (decision 096: one router and one lens per manager; the letter is
6
+ a suffix on the contract and never a prefix on a function or an event).
6
7
 
7
8
  **Status: identity, reads and writes for both singletons.** Indexer next.
8
9
 
@@ -37,15 +38,76 @@ Both are computed **offline** — no RPC, no deployment needed to address a mark
37
38
  - F side: `discoverFPools(c)` (shape, and the `block` the pool was initialized in), `getFPool`,
38
39
  `fPoolShareBalance`, `fPoolShareValue`; `previewZapIn` reads the **lens** (the router's F flows
39
40
  live in a facet, its previews moved to the lens). Since F version 25 every F state read goes
40
- through the lens (`fPool`, `getFPools`, `fBundleOf`, `fDividendOf`, `fLienOf`): the manager's
41
+ through the lens (`pool`, `getPools`, `bundleOf`, `dividendOf`, `lienOf`): the manager's
41
42
  typed views are behind `extsload` (decisions 062), and the lens decodes them with the contracts'
42
43
  `FPoolState`, so the SDK never hard-codes the storage layout.
43
44
  - F pool state names (F version 25): `swapFee` (was `phi`), `logFloor` θ — the log of the current
44
45
  floor price (was `theta`), `refLogFloor` θ₀ — the reference floor income counts from (was
45
46
  `theta0`), `cap` (d in 1e-6 log units, 0 uncapped), and per leg `virtualReserves` and `kappa`.
46
47
 
48
+ ## C 16 / F 40 (decision 098): immutable, LOG-deployed policies; one sponsored policy per manager
49
+
50
+ Follows contracts `99827f8`. This is a breaking release: the policy surface is replaced.
51
+
52
+ - **Kinds.** `PublicPolicy` and `PrivatePolicy` are gone. A policy says it is `"sponsor"` (`SponsorPolicyF` / `SponsorPolicyC`: the LOG's own
53
+ instances, the open canonical one and a gated one, and a third party's deployed by the LOG), `"pol"`, `"pad"` or `"orphan"` (`OrphanPolicyF`).
54
+ `FPoolKind` is `"sponsor" | "pol" | "pad" | "orphan"`. `fPoolPolicyFor(c, slot)` and `FPoolCreateArgs.kind` take a deployment *slot*
55
+ (`FPolicySlot`: `"public"`, `"private"`, `"pol"`, `"pad"`, the artifact's keys: `publicPolicy` / `privatePolicy` are the LOG's open and gated
56
+ `SponsorPolicyF` instances). New optional addresses: `publicPolicyC` (the open `SponsorPolicyC`) and `orphanPolicy`.
57
+ `sponsorPolicyFAbi`, `sponsorPolicyCAbi` and `orphanPolicyFAbi` replace `publicPolicyAbi` / `privatePolicyAbi`.
58
+ - **A policy has no setter.** Its numbers (fee tiers as masks over the family's table, quotes, the C spacings, the swap-fee tax, `canonical`,
59
+ `gatesAvailable`, `bornGated`, a pad's schedule and income tax rate, a POL's reserve ratio) are constructor immutables: a change is a new policy,
60
+ which the LOG approves (`registryApprove`) and moves pools to (`fPoolMigrate`). The wrappers for the old setters are removed
61
+ (`padSetSchedule`, `padSetThresholdBase`, `padSetIncomeTaxRate`, `polSetMinQuoteRatio`, `polSetIncomeTaxRate`, `policySetQuoteListed`,
62
+ `policySetQuoteCurated`, `policySetFeeListed`, `policySetFeeCurated`, `gateSetPairListed`, `gateSetPairCurated`, `gateSetSpacingListed`,
63
+ `policySetSpacingListed`, `policySetSpacingCurated`, `setCSwapFeeTax`, `setCGate`, `registrySetInitializerListed`). Readers remain:
64
+ `policyQuoteAllowed`, `policyFeeAllowed(c, policy, fee, "swap" | "mint")`, `policySpacingAllowed`, `cSwapFeeTax(c, policy?)`, `padScheduleOf`,
65
+ `padThresholdBases`, `padThresholdOf`, `padThreshold`, and `getFPoolRules` (which now returns the sponsored policy's immutables).
66
+ - **Authority and operator.** The authority is `key.creator` for life: no handover (`fPoolProposeAuthority` / `fPoolAcceptAuthority` are removed;
67
+ `FPoolRoles` loses `creator`, `pendingAuthority` and `swapExecutor`). The authority appoints a per-pool operator (`fPoolAppointOperator`, was
68
+ `fPoolSetPoolOperator`), sets the swap mode (`fPoolSetSwapMode`: `"open" | "operator" | "listed"`, no executor), the mint gate
69
+ (`fPoolSetMintGate`) and the whitelist (`fPoolSetListed(who, listed)` and `fPoolIsListed`; the minter and taker lists are gone). The same
70
+ functions exist on `SponsorPolicyC`: pass `policy: key.policy` for a C market. `fPoolDeskOpening` is now the one mint-gate write.
71
+ - **Gates.** `Pool.asks` is `Pool.flags` (`FPoolState.flags`; `GATE_SWAP` 1, `GATE_MINT` 2, `GATES` 3, `SEED_TO_DEAD` 4; `ASK_SWAP` / `ASK_MINT` are
72
+ gone) and `FPoolState.operator` is the operator the manager caches (admitted by a gated swap or mint with no policy call). `setPermissions` /
73
+ `PermissionsSet` are `setGates(poolId, gates, operator)` / `GatesSet` on both managers; the indexer's shared table is `GatesSet`.
74
+ - **Registry.** `CreationMode` is `"open" | "sponsorOnly"` (`Restricted`, the initializer list and `InitializerNotListed` are gone; the initializer
75
+ must be `key.creator`, `NotCreator`). `fPoolMigrate(c, { key, to, permissions? })` installs the new policy's swap mode, operator, mint gate and
76
+ whitelist in the same transaction (`MigrationPermissions`; `migratePrivate` is gone). New: `fPoolOrphan` (`PolicyRegistry.orphan`, final),
77
+ `registryOrphanPolicyOf`, `registrySetOrphanPolicy`.
78
+ - **C gate.** `cGateRules` reads the sponsored C policy: `pairOk` is gone, `mintFeeOk` is new, `saltOk` binds only a canonical policy;
79
+ `gateErrorAbi` carries `FeeNotListed`, `MintFeeNotListed`, `QuoteNotListed`, `GatesUnavailable`, `NotCanonical`.
80
+ - **Versions.** `EXPECTED_VERSION` is 16 (C) and `EXPECTED_F_VERSION` is 40. No pool id moved.
81
+
82
+ ## C 15 / F 39 (decisions 096, 097): a router and a lens per manager, and a C market has a creator and a salt
83
+
84
+ (The policy parts of this section are superseded by the one above.)
85
+
86
+ Follows contracts `f3164de` (096 + #112 + #113 + #115 + #116). What changes for a consumer:
87
+
88
+ - **Addresses.** `LogswapAddresses` is `managerF`, `routerF`, `lensF` (required) and `managerC`, `routerC`, `lensC` (optional:
89
+ F ships first, so a chain may have no C stack; the artifact then carries `address(0)` and `cVersion` 0). `managerC(c)`,
90
+ `routerC(c)`, `lensC(c)` throw where the stack is absent, and `hasC(c)` says whether it is there. The artifact's keys are the same names.
91
+ - **ABIs.** `managerCAbi` / `managerFAbi`, `routerCAbi` / `routerFAbi`, `lensCAbi` / `lensFAbi`, `routerActionsAbi`. Each router is its
92
+ own Permit2 spender: `approveToken`, `approvePermit2ForRouter`, `onboardToken`, `checkTokenReadiness`, `spenderFor` and
93
+ `permit2SigCalls` take the side (`"C"` or `"F"`) after the client, and `sendRouterWrite*` take `side` in their arguments.
94
+ - **Names.** The 095 `c`-prefixed C functions are back to the plain 096 names (`getPool`, `discoverMarkets`, `swapExactIn`, ...); the event
95
+ `PoolCreated`, `Swap` and `SwapState` are the same on both managers (declared once in `ManagerBase`). `TickCrossed`, `BackstopSeeded` and
96
+ `Stamped` are gone from the ABIs.
97
+ - **A C key has a creator and a salt** (decision 097): `PoolKey = { base, quote, tickSpacing, policy, creator, salt, swapFee, mintFee }`,
98
+ so every C pool id is new. Only the creator may `initialize` and make the first mint (the backstop seed; `NotCreator`), and `initializeMarket`
99
+ refuses an account that is not `key.creator` before sending. `PoolCreated` carries a trailing `salt`; the indexer rows carry `creator` and `salt`.
100
+ A malformed policy answer is `BadTerms` (#115). The public policy is canonical per exact key (`salt` 0, `NotCanonical`); `marketOf` and
101
+ `MarketExists` are gone, and `cGateRules` reads `getPool(key).initialized` for `exists` and adds `saltOk`.
102
+ - **Registry and policies.** `registryUserOf(c, caller)` reads `PolicyRegistry.userOf` (the account a routed caller acts for);
103
+ `policySpacingAllowed` reads the tick-spacing list (since 098 only on `SponsorPolicyC`, and read-only).
104
+ - **Versions.** `EXPECTED_VERSION` is 15 (C) and `EXPECTED_F_VERSION` is 39; `assertVersion` checks C only where the deployment has it, and
105
+ `assertWiring` checks each router and lens against its own manager.
106
+
47
107
  ## C 13 (decisions 088–090): a C market is addressed by its pool id
48
108
 
109
+ (The router and lens naming in this section is superseded by the one above.)
110
+
49
111
  The consumer API still takes a `PoolKey`; the SDK hashes it (`poolId(key)`) and calls the contracts with the id.
50
112
  What changes for a consumer:
51
113
 
@@ -58,10 +120,15 @@ What changes for a consumer:
58
120
  longer an indexed topic, so `discoverMarkets({ base })` filters it client-side. Both managers emit `PoolCreated`, so an
59
121
  indexer table is prefixed by its contract (`allCPoolManagerPoolCreateds`, `allFPoolManagerPoolCreateds`).
60
122
  - **Router.** The named entries pass the tokens the caller expects (`WrongToken` on a mismatch); `execute` batches
61
- carry the pool id in each action. `facetF()` is `facetC()`.
123
+ carry the pool id in each action. `LogswapRouter` is `Router` and `LogswapLens` is `Lens` (the ABI exports are `routerAbi` / `lensAbi`;
124
+ the `logswap*` names stay as deprecated aliases for one minor). The router runs the trade path inline (swap, mint, zap-in, quote);
125
+ the management of an existing position (burn, claim, update, move, createMarket, F zap-out and roll-in) is `LiquidityFacet`, reached
126
+ by `fallback` at the same router address, so `routerAbi` is the merge and Permit2 still has one spender. `facetC()` is
127
+ `liquidityFacet()`; the `encode*` helpers left the contract for the ABI-only `routerActionsAbi`. Prefer the managers directly when
128
+ you need no recipient, deadline or Permit2 (decision 091).
62
129
  - **Layout.** F `getPool` has `swapFee` / `mintFee` as `uint56`; the `extsload` words are in the contracts' `FPoolState`.
63
130
 
64
- ## Who may create what: the gate, the menus (C version 7, F version 26)
131
+ ## Who may create what: the gate, the menus (C version 7, F version 26; superseded by decision 098 above)
65
132
 
66
133
  Since logswap-contract #60 (decisions 064–065) creation is curated at launch, on both managers:
67
134
 
@@ -84,16 +151,16 @@ Since logswap-contract #60 (decisions 064–065) creation is curated at launch,
84
151
  own fee for an initialized market.
85
152
  - **C reads**: `getPool` reads the lens's `getPools`; `getPositionClass` reads the class through
86
153
  `extsload` at `CPoolState`'s slot (the manager's typed views are gone).
87
- - **Creators are curated on every kind** at launch (onboarding under a service agreement); the
88
- LOG Authority's helpers: `policySetCreatorListed`, `gateSetPairListed`,
89
- `gateSetSpacingListed`, `gateSetForwarderTrusted`, `setCGate`.
154
+ - **Creation** (098): the registry's creation mode per policy (`open`, or `sponsorOnly`: the policy's own immutable sponsor creates);
155
+ `registrySetCreationMode` and `registrySetForwarderTrusted` are the LOG Authority's helpers. The creator list, the pair list and
156
+ the policy setters are gone.
90
157
  - **Two roles (decision 066, C 8 / F 27).** `logAuthority()` reads the LOG Authority (the
91
158
  registry's `logAuthority`; `proposeLogAuthority` / `acceptLogAuthority`), which administers the
92
159
  registry, both managers and every policy. `logTreasury(side)` reads a manager's treasury, which
93
160
  only receives; `proposeTreasury` is the authority's, `acceptTreasury` the incoming treasury's own
94
161
  call. `collectCProtocolFees(key)` may be sent by anyone and pays the treasury. The C swap-fee tax is each
95
- market's from birth (`getPool(key).swapFeeTax`, `cMarketSwapFeeTax`); `setCSwapFeeTax` sets the
96
- gate's level for markets born after it; the C gate is fixed (`setCGate` throws). `registryOwner`,
162
+ market's from birth (`getPool(key).swapFeeTax`, `cMarketSwapFeeTax`); since 098 the level is the policy's
163
+ immutable (`cSwapFeeTax(c, policy?)` reads it; a different level is a different policy). `registryOwner`,
97
164
  `registryProposeOwner` / `registryAcceptOwner` and `proposeCollector` / `acceptCollector` remain
98
165
  as deprecated aliases.
99
166
 
@@ -141,8 +208,8 @@ as the fallback, with the same answer on the same data:
141
208
  - `fPoolShareHolders`: the holders from `pool_holder`;
142
209
  - `swapFees`: the window from `swap_flow`.
143
210
 
144
- What stays a live read: a C position's value and every unclaimed fee or dividend (the lens: `legsOf`,
145
- `heldByIds`, `fDividendOf`). They accrue without events, so no view holds them.
211
+ What stays a live read: a C position's value and every unclaimed fee or dividend (the lens: `cLegsOf`,
212
+ `cHeldByIds`, `dividendOf`). They accrue without events, so no view holds them.
146
213
 
147
214
  ## The F pool's life: four calls (F 38)
148
215
 
@@ -168,7 +235,7 @@ What stays a live read: a C position's value and every unclaimed fee or dividend
168
235
  `fPoolBookWeights` and `fPoolBookL` derive the allocation and the liquidity from it. A regeneration emits no
169
236
  such event; the freeze-out is read from `GenerationRetired` and `IncomeReleased`.
170
237
  - **Income and income tax** (decision 085): the dead shares' dividend and the share of it the treasury takes are
171
- the income and the income tax (`IncomeReleased`, `incomeHeld`, `incomeTax`, `padSetIncomeTaxRate`).
238
+ the income and the income tax (`IncomeReleased`, `incomeHeld`, `incomeTax`; the rate is the policy's `incomeTaxRate`, an immutable since 098).
172
239
 
173
240
  - **The lien** (decisions 063): a lending contract locks an owner's shares in place.
174
241
  `fPoolApproveShares` (the owner's per-id allowance), `fPoolLock` / `fPoolUnlock` (the locker's;
package/dist/actions.js CHANGED
@@ -18,7 +18,7 @@
18
18
  * hand-written and a struct change is a `tsc`/vector failure, not a runtime surprise.
19
19
  */
20
20
  import { encodeAbiParameters } from "viem";
21
- import { logswapRouterAbi } from "./generated.js";
21
+ import { routerCAbi, routerActionsAbi } from "./generated.js";
22
22
  import { poolId as keyId } from "./keys.js";
23
23
  import { NO_CAP } from "./ids.js";
24
24
  import { resolveDeadline, resolveRecipient, sendRouterWriteWithPermits, simulateRouterWrite } from "./write.js";
@@ -39,9 +39,9 @@ export var Op;
39
39
  })(Op || (Op = {}));
40
40
  /* payload encoding ========================================================== */
41
41
  function payloadType(encoder) {
42
- const f = logswapRouterAbi.find((x) => x.type === "function" && x.name === encoder);
42
+ const f = routerActionsAbi.find((x) => x.type === "function" && x.name === encoder);
43
43
  if (!f?.inputs)
44
- throw new Error(`logswap: the router ABI has no ${encoder} — SDK and contracts disagree`);
44
+ throw new Error(`logswap: RouterActions has no ${encoder} — SDK and contracts disagree`);
45
45
  return f.inputs;
46
46
  }
47
47
  const enc = (encoder, value) => encodeAbiParameters(payloadType(encoder), [value]);
@@ -126,13 +126,14 @@ export function settleOnly(key, recipient, side, b = {}) {
126
126
  export async function execute(c, a) {
127
127
  const settle = { ...a.settle, recipient: a.settle.recipient ?? resolveRecipient(c, a) };
128
128
  const pull = a.pullTokens ?? settle.tokens.filter((_, i) => settle.maxIn[i] > 0n);
129
- return sendRouterWriteWithPermits(c, { abi: logswapRouterAbi, functionName: "execute", args: [a.actions, settle, resolveDeadline(a)] }, [...pull]);
129
+ return sendRouterWriteWithPermits(c, { side: "C", abi: routerCAbi, functionName: "execute", args: [a.actions, settle, resolveDeadline(a)] }, [...pull]);
130
130
  }
131
131
  /** Simulate a batch: the per-action returns and the signed flows (+ = paid in), without sending. */
132
132
  export async function simulateExecute(c, a) {
133
133
  const settle = { ...a.settle, recipient: a.settle.recipient ?? a.account ?? resolveRecipient(c, a) };
134
134
  const [results, flows] = await simulateRouterWrite(c, {
135
- abi: logswapRouterAbi,
135
+ side: "C",
136
+ abi: routerCAbi,
136
137
  functionName: "execute",
137
138
  args: [a.actions, settle, resolveDeadline(a)],
138
139
  account: a.account,