@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/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` / `Router` / `Lens` 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
 
@@ -66,7 +128,7 @@ What changes for a consumer:
66
128
  you need no recipient, deadline or Permit2 (decision 091).
67
129
  - **Layout.** F `getPool` has `swapFee` / `mintFee` as `uint56`; the `extsload` words are in the contracts' `FPoolState`.
68
130
 
69
- ## 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)
70
132
 
71
133
  Since logswap-contract #60 (decisions 064–065) creation is curated at launch, on both managers:
72
134
 
@@ -89,16 +151,16 @@ Since logswap-contract #60 (decisions 064–065) creation is curated at launch,
89
151
  own fee for an initialized market.
90
152
  - **C reads**: `getPool` reads the lens's `getPools`; `getPositionClass` reads the class through
91
153
  `extsload` at `CPoolState`'s slot (the manager's typed views are gone).
92
- - **Creators are curated on every kind** at launch (onboarding under a service agreement); the
93
- LOG Authority's helpers: `policySetCreatorListed`, `gateSetPairListed`,
94
- `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.
95
157
  - **Two roles (decision 066, C 8 / F 27).** `logAuthority()` reads the LOG Authority (the
96
158
  registry's `logAuthority`; `proposeLogAuthority` / `acceptLogAuthority`), which administers the
97
159
  registry, both managers and every policy. `logTreasury(side)` reads a manager's treasury, which
98
160
  only receives; `proposeTreasury` is the authority's, `acceptTreasury` the incoming treasury's own
99
161
  call. `collectCProtocolFees(key)` may be sent by anyone and pays the treasury. The C swap-fee tax is each
100
- market's from birth (`getPool(key).swapFeeTax`, `cMarketSwapFeeTax`); `setCSwapFeeTax` sets the
101
- 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`,
102
164
  `registryProposeOwner` / `registryAcceptOwner` and `proposeCollector` / `acceptCollector` remain
103
165
  as deprecated aliases.
104
166
 
@@ -146,8 +208,8 @@ as the fallback, with the same answer on the same data:
146
208
  - `fPoolShareHolders`: the holders from `pool_holder`;
147
209
  - `swapFees`: the window from `swap_flow`.
148
210
 
149
- What stays a live read: a C position's value and every unclaimed fee or dividend (the lens: `legsOf`,
150
- `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.
151
213
 
152
214
  ## The F pool's life: four calls (F 38)
153
215
 
@@ -173,7 +235,7 @@ What stays a live read: a C position's value and every unclaimed fee or dividend
173
235
  `fPoolBookWeights` and `fPoolBookL` derive the allocation and the liquidity from it. A regeneration emits no
174
236
  such event; the freeze-out is read from `GenerationRetired` and `IncomeReleased`.
175
237
  - **Income and income tax** (decision 085): the dead shares' dividend and the share of it the treasury takes are
176
- 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).
177
239
 
178
240
  - **The lien** (decisions 063): a lending contract locks an owner's shares in place.
179
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 { routerAbi, routerActionsAbi } 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";
@@ -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: routerAbi, 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: routerAbi,
135
+ side: "C",
136
+ abi: routerCAbi,
136
137
  functionName: "execute",
137
138
  args: [a.actions, settle, resolveDeadline(a)],
138
139
  account: a.account,