@logswap/sdk 0.5.102 → 0.5.103
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/README.md +14 -418
- package/dist/actions.d.ts +0 -39
- package/dist/actions.js +0 -39
- package/dist/admin.d.ts +0 -106
- package/dist/admin.js +1 -96
- package/dist/chains.d.ts +0 -49
- package/dist/chains.js +0 -30
- package/dist/claims.d.ts +0 -32
- package/dist/claims.js +0 -30
- package/dist/client.d.ts +0 -116
- package/dist/client.js +1 -231
- package/dist/fees.d.ts +1 -45
- package/dist/fees.js +0 -44
- package/dist/fpool.d.ts +4 -612
- package/dist/fpool.js +14 -490
- package/dist/generated.js +0 -30
- package/dist/history.d.ts +0 -61
- package/dist/history.js +5 -74
- package/dist/ids.d.ts +0 -30
- package/dist/ids.js +0 -31
- package/dist/index.d.ts +0 -7
- package/dist/index.js +0 -7
- package/dist/indexer.d.ts +0 -68
- package/dist/indexer.js +1 -77
- package/dist/keys.d.ts +0 -50
- package/dist/keys.js +0 -35
- package/dist/liquidity.d.ts +0 -128
- package/dist/liquidity.js +1 -107
- package/dist/onboard.d.ts +0 -52
- package/dist/onboard.js +1 -59
- package/dist/pools.d.ts +3 -157
- package/dist/pools.js +1 -164
- package/dist/positions.d.ts +0 -102
- package/dist/positions.js +1 -90
- package/dist/quote.d.ts +0 -14
- package/dist/quote.js +0 -14
- package/dist/swap.d.ts +0 -31
- package/dist/swap.js +5 -37
- package/dist/tokencache.d.ts +0 -48
- package/dist/tokencache.js +1 -73
- package/dist/write.d.ts +1 -87
- package/dist/write.js +1 -87
- package/package.json +3 -8
- package/src/actions.ts +0 -208
- package/src/admin.ts +0 -350
- package/src/chains.ts +0 -278
- package/src/claims.ts +0 -111
- package/src/client.ts +0 -436
- package/src/fees.ts +0 -138
- package/src/fpool.ts +0 -2049
- package/src/generated.ts +0 -4345
- package/src/history.ts +0 -383
- package/src/ids.ts +0 -78
- package/src/index.ts +0 -26
- package/src/indexer.ts +0 -264
- package/src/keys.ts +0 -138
- package/src/liquidity.ts +0 -456
- package/src/onboard.ts +0 -253
- package/src/pools.ts +0 -465
- package/src/positions.ts +0 -297
- package/src/quote.ts +0 -36
- package/src/swap.ts +0 -181
- package/src/tokencache.ts +0 -178
- package/src/write.ts +0 -236
package/dist/client.js
CHANGED
|
@@ -1,44 +1,29 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* client.ts — the SDK handle: addresses + viem clients.
|
|
3
|
-
*
|
|
4
|
-
* Construct once and pass to every helper. `wallet` is optional: read helpers need only `public`.
|
|
5
|
-
*
|
|
6
|
-
* **One stack per manager, permanently** (decision 096): a manager, its router and its lens, for F and for
|
|
7
|
-
* C. Not per market — every market lives in the one manager of its side, and a market is an
|
|
8
|
-
* `initialize` call rather than a deployment. F ships first, so the C stack is optional: a chain
|
|
9
|
-
* that has not opted into C carries `address(0)` for it, and every C call throws a plain error there.
|
|
10
|
-
*/
|
|
11
1
|
import { addressesOfDeployment, DEFAULT_MAX_LOG_RANGE, logswapChain } from "./chains.js";
|
|
12
2
|
const ZERO_ADDRESS = "0x0000000000000000000000000000000000000000";
|
|
13
3
|
const NO_C = "logswap: this deployment has no C stack (managerC / routerC / lensC) — F ships first, C lands with its own deployment";
|
|
14
|
-
/** Whether the deployment carries the C stack. */
|
|
15
4
|
export function hasC(c) {
|
|
16
5
|
const a = c.addresses;
|
|
17
6
|
return has(a.managerC) && has(a.routerC) && has(a.lensC);
|
|
18
7
|
}
|
|
19
8
|
const has = (a) => !!a && a !== ZERO_ADDRESS;
|
|
20
|
-
/** The C manager; throws where the deployment has none. */
|
|
21
9
|
export function managerC(c) {
|
|
22
10
|
const a = c.addresses.managerC;
|
|
23
11
|
if (!has(a))
|
|
24
12
|
throw new Error(NO_C);
|
|
25
13
|
return a;
|
|
26
14
|
}
|
|
27
|
-
/** The C router; throws where the deployment has none. */
|
|
28
15
|
export function routerC(c) {
|
|
29
16
|
const a = c.addresses.routerC;
|
|
30
17
|
if (!has(a))
|
|
31
18
|
throw new Error(NO_C);
|
|
32
19
|
return a;
|
|
33
20
|
}
|
|
34
|
-
/** The C lens; throws where the deployment has none. */
|
|
35
21
|
export function lensC(c) {
|
|
36
22
|
const a = c.addresses.lensC;
|
|
37
23
|
if (!has(a))
|
|
38
24
|
throw new Error(NO_C);
|
|
39
25
|
return a;
|
|
40
26
|
}
|
|
41
|
-
/** The router of `side` — the contract that pulls the caller's tokens, and the spender to approve. */
|
|
42
27
|
export function routerOf(c, side) {
|
|
43
28
|
return side === "F" ? c.addresses.routerF : routerC(c);
|
|
44
29
|
}
|
|
@@ -66,21 +51,12 @@ export function createLogswapClient(args) {
|
|
|
66
51
|
...(args.indexerUrl ? { indexerUrl: args.indexerUrl } : {}),
|
|
67
52
|
};
|
|
68
53
|
}
|
|
69
|
-
/** The chain id the client reads: set at construction when known, else asked of the node. */
|
|
70
54
|
export async function clientChainId(c) {
|
|
71
55
|
return c.chainId ?? c.public.chain?.id ?? (await c.public.getChainId());
|
|
72
56
|
}
|
|
73
|
-
/**
|
|
74
|
-
* The wallet, with every signing call first checking that it is on the chain the reads come from.
|
|
75
|
-
*
|
|
76
|
-
* An injected wallet switched to another network would otherwise estimate and simulate against
|
|
77
|
-
* the public client's chain and then sign and send on its own — with deterministic deploy
|
|
78
|
-
* addresses, possibly into a different contract. Checked at each call, not once: a user can
|
|
79
|
-
* switch networks mid-session.
|
|
80
|
-
*/
|
|
81
57
|
function guardChain(wallet, pub) {
|
|
82
58
|
if (typeof wallet.getChainId !== "function")
|
|
83
|
-
return wallet;
|
|
59
|
+
return wallet;
|
|
84
60
|
let readChain = pub.chain?.id;
|
|
85
61
|
const check = async () => {
|
|
86
62
|
readChain ??= await pub.getChainId();
|
|
@@ -102,210 +78,12 @@ function guardChain(wallet, pub) {
|
|
|
102
78
|
},
|
|
103
79
|
});
|
|
104
80
|
}
|
|
105
|
-
/**
|
|
106
|
-
* Assert the deployment matches the ABI this build was generated against.
|
|
107
|
-
*
|
|
108
|
-
* Cheap insurance worth taking at construction: without it, a manager from a different deployment
|
|
109
|
-
* decodes into plausible-looking garbage rather than failing. `version` is bumped on any tier-1 or
|
|
110
|
-
* tier-2 change (docs/app.md).
|
|
111
|
-
*
|
|
112
|
-
* **2** since 2026-09-01. It sat at 1 across a read surface that changed underneath it — the nine
|
|
113
|
-
* `public constant` getters left the manager for `CParams`, `move` gained its settlement bounds,
|
|
114
|
-
* `createMarket` arrived — so a 1 answered for two incompatible ABIs and this check passed against
|
|
115
|
-
* a manager it should have rejected. Observed, not theorised: a local chain running a pre-trim
|
|
116
|
-
* manager sailed through `assertVersion` while `FEE_MAX()` still answered on it. Move this in the
|
|
117
|
-
* same change as `CParams.VERSION`, never after it.
|
|
118
|
-
*
|
|
119
|
-
* **3** since 2026-09-03: `burnById` and `update` take an `owner`, `update`
|
|
120
|
-
* mints to `to`, `positions()` returns `aps` as uint128 — and a returned quote flow now carries the
|
|
121
|
-
* swept fees, which is why `exit`'s settle-to-one-asset math changed with it.
|
|
122
|
-
*
|
|
123
|
-
* **4** since 2026-09-18: `PoolKey` is `(base, quote, tickSpacing, phi)` —
|
|
124
|
-
* the variance kernel and its two key fields are gone, so every pool id changed; `phiEff` is
|
|
125
|
-
* `phiOf`; `getPool` lost `sigma2Ema`; `Initialize` lost two fields; the cut is
|
|
126
|
-
* `MINT_FEE_PROTOCOL_CUT` / `setFeeParams`.
|
|
127
|
-
*
|
|
128
|
-
* **6** since 2026-10-09 (logswap-contract#58): the whole mint fee is the protocol's
|
|
129
|
-
* (`MINT_FEE_PROTOCOL_CUT` and `setFeeParams` are gone, decisions 058); the swap-fee tax at payout,
|
|
130
|
-
* `swapFeeTax` / `setSwapFeeTax` (060); `phi` is `swapFee` and `phiOf` `swapFeeOf` (059) — field
|
|
131
|
-
* names only, no pool id moved.
|
|
132
|
-
*
|
|
133
|
-
* **7** since 2026-10-12 (logswap-contract#60, decisions 064–065): the typed views (`getPool`,
|
|
134
|
-
* `ticks`, `tickBitmapWord`, `positions`, `feeAcct`, `idInfo`) are behind `extsload` — the pool
|
|
135
|
-
* reads through the lens's `getPools`, a class through `CPoolState`'s layout; a fee of 0 is no
|
|
136
|
-
* fee (`swapFeeOf` and `DEFAULT_FEE` are gone); the mint fee is the market's, proposed at
|
|
137
|
-
* `initialize` / `createMarket` and answered by the gate; the gate (`gate`, `setGate`) is the
|
|
138
|
-
* public policy, set at construction. No pool id moved.
|
|
139
|
-
*
|
|
140
|
-
* **8** since 2026-10-13 (logswap-contract decision 066): the collector is split into two roles —
|
|
141
|
-
* `feeCollector` / `proposeCollector` / `acceptCollector` are `treasury` / `proposeTreasury` (the
|
|
142
|
-
* LOG Authority's) / `acceptTreasury`; `setSwapFeeTax` and `setGate` leave the manager: the tax is
|
|
143
|
-
* each market's, answered by its policy at birth (`PolicyC.swapFeeTax`, an immutable; `SponsorPolicyC` before C 18) and
|
|
144
|
-
* read as `getPool(key).swapFeeTax`; the gate is fixed at construction; `collectProtocolFees(key)` is
|
|
145
|
-
* permissionless and pays the treasury. No pool id moved.
|
|
146
|
-
* 9 (decision 071): the events — one `Swap` on both managers (`taker`, `feeToken`), `CSwapState`, C's `swap`
|
|
147
|
-
* takes `SwapParams` (the router's ABI does not move), object-word event names (`MarketCreated`,
|
|
148
|
-
* `PositionMinted`, ...), `MarketCreated` carries creator, mintFee and swapFeeTax. No pool id moved.
|
|
149
|
-
*/
|
|
150
|
-
// 11 (decision 078): `mintFee` is a key field (the creator's pick, `2 * swapFee <= mintFee <= 2%`); `initialize(key, x0)`
|
|
151
|
-
// takes no separate mint fee, `createMarket` neither; `getPool` drops `mintFee` and the gates' mint-fee menus are gone.
|
|
152
|
-
// Every C pool id moved.
|
|
153
|
-
// 12 (decisions 079-081): `Action` ordinals, the key is `CPoolKey` (names only). No pool id moved.
|
|
154
|
-
// 13 (decisions 088-090): a C pool is addressed by its `bytes32 poolId` after `initialize` (the key rides in calldata at `initialize`
|
|
155
|
-
// only; no pool id moved), the router's named entries take the tokens the caller expects (`WrongToken`), `claimById` / `burnById` /
|
|
156
|
-
// `claimManyFor` are `claim` / `burn` / `claimMany`, `mint(poolId, to, floor, cap, L)`, `MarketCreated` is `PoolCreated` (in F's field
|
|
157
|
-
// order), `x0` is `initialLogPrice`, `PoolView.x` / `.F` are `logPrice` / `feeGrowth`, `swapFee` / `mintFee` are `uint56`.
|
|
158
|
-
// 14 (decision 092): the C quoter is the router's (`Router.quoteSwap(poolId, exactIn, baseSide, amount, taker)`); `CPoolManager.quoteSwap`
|
|
159
|
-
// and the Lens's `previewSwapExactIn` / `Out` / `InBatch` are gone. No pool id moved.
|
|
160
|
-
// 15 (decision 097): `PoolKeyC` is `(base, quote, tickSpacing, policy, creator, salt, swapFee, mintFee)` — every C pool id moved; the creator
|
|
161
|
-
// initializes and makes the first mint (`NotCreator`); `PoolCreated` carries the salt; the backstop is held by 0xdead; a malformed policy
|
|
162
|
-
// answer is `BadTerms`. The names are decision 096's (no `c` prefix on a function or an event; `SwapState`); a router and a lens per manager.
|
|
163
|
-
// 16 (decision 098): the policies are immutable and the LOG's — `SponsorPolicyC` replaces `PublicPolicy` / `PrivatePolicy`; `setPermissions` /
|
|
164
|
-
// `PermissionsSet` are `setGates(poolId, gates, operator)` / `GatesSet`; the birth answer is `(flags, tax, operator)`; the policy's
|
|
165
|
-
// numbers (tiers, quotes, spacings, tax) are constructor immutables; the swap and mint gates are one bit each (`GATE_SWAP`,
|
|
166
|
-
// `GATE_MINT`) and the cached operator passes with no policy call. No pool id moved.
|
|
167
|
-
// 17 (decision 107): every event names its actor and the routers emit none (`RouterCall` is gone). `mint(poolId, payer, to, floor, cap, L)`;
|
|
168
|
-
// `PositionMinted(poolId, to, id, sender, payer, shares, dBase, dQuote)`; `ProtocolFeesCollected(poolId, sender, to, amount)`;
|
|
169
|
-
// `ClassRegistered(poolId, id, floor, cap, capped)` (poolId first); the account acted on is `owner` on `PositionBurned` (was `from`),
|
|
170
|
-
// `PositionUpdated` and `FeesClaimed` (was `holder`); `RouterC`'s entries and `Settle` name the receiver `to` (was `recipient`). No pool id moved.
|
|
171
|
-
// 18 (decisions 099, 100): `PoolKeyC` is `(quote, base, swapFeeIdx, spacingIdx, policy, salt)` — every C pool id and position id moved; the
|
|
172
|
-
// fee is an index into the family's list (the mint fee the next entry) and the spacing an index into `[1e15, 1e16, 1e17]`; `initialize(key, x0)`
|
|
173
|
-
// mints the backstop in the call (the caller pays dust of both tokens by allowance to the manager) and `RouterC.createMarket` is gone;
|
|
174
|
-
// `PoolCreated` carries the two indices; `claim(poolId, id, owner, to)`; `PoolView` has no `backstopSeeded`; `LensC.params()` is
|
|
175
|
-
// `(spacingList, noCap, cVersion)`; `PolicyC` replaces `SponsorPolicyC` (F's gate surface plus `baseListed`, `swapFeeTax`, `mayInit`); the
|
|
176
|
-
// registry lost its creation modes (`admit`, `creationMode`, `setCreationMode`, `sponsorOf`). `SpacingZero`, `BackstopTooSmall`,
|
|
177
|
-
// `BackstopMustBeUncapped` and `NotCreator` are gone, `PolicyNotApproved` is new.
|
|
178
81
|
export const EXPECTED_VERSION = 20n;
|
|
179
|
-
/**
|
|
180
|
-
* The F manager's own tag (5 — the key's salt, pool names, the sponsor registry;
|
|
181
|
-
* 4 was the income-only harvest cut).
|
|
182
|
-
*
|
|
183
|
-
* A FLOOR, not an equality — unlike `EXPECTED_VERSION` above. The F primitive is iterating fast and
|
|
184
|
-
* its bumps are mostly additive (6 is `multicall`, which nothing this SDK calls goes near), so an
|
|
185
|
-
* exact match meant each one bricked every app on the deployment until the SDK was republished — a
|
|
186
|
-
* version wall in front of a change that broke nothing. The cost is that a genuinely breaking bump
|
|
187
|
-
* passes it; when one lands, raise this constant in the same change, which is the discipline
|
|
188
|
-
* `EXPECTED_VERSION` enforces mechanically and this one asks for.
|
|
189
|
-
*/
|
|
190
|
-
// 7 (2026-09-15): the reserves are the state and the marks derived, `lockStrike`, the dividend
|
|
191
|
-
// harvest, the relaunch (`dissolve(poolId, successor)`, `rollIn`), the reserve-named seed, the
|
|
192
|
-
// sponsor facet.
|
|
193
|
-
// 8 (2026-09-15): the relaunch is in place — every share id carries the
|
|
194
|
-
// generation (`fPoolShareId(poolId, gen)`), `dissolve(poolId)`, `redeem`, `claim` / `dividendOf`
|
|
195
|
-
// / `rollIn` / `previewRollIn` take the generation, `Pool.gen` replaces `dissolved` and
|
|
196
|
-
// `successor`. A 7 deployment's share ids do not even resolve with this SDK.
|
|
197
|
-
// 9 (2026-09-16): `deepen` is gone, `Pool.leverTheta` is `harvestedTheta`.
|
|
198
|
-
// 10 (2026-09-17): no floor guard — `Pool.minBuffer`, `raiseMinBuffer`, `LEVER_FLOOR` gone;
|
|
199
|
-
// `dissolve` needs an empty bid on every pool; the key bit is the CLASS, `pad`
|
|
200
|
-
// (036): `seed` mints a pad's shares to 0xdead, and the operator, the gates and the list are
|
|
201
|
-
// refused on it — `fPoolLaunch` no longer transfers the seed itself.
|
|
202
|
-
// 11 (2026-09-17): roles and entries — the operator runs the pool (`harvest`,
|
|
203
|
-
// `dissolve`, `setLegs`) and is the authority until appointed, two-step (`acceptOperator`,
|
|
204
|
-
// `Pool.pendingOperator`); `setLegL`/`admitLeg` are gone, `setLegs` edits the next generation's
|
|
205
|
-
// table while unseeded; `fPoolRelaunch` takes `legs`.
|
|
206
|
-
// `getPool` decodes one field fewer, so a 9 deployment's struct no longer matches this SDK.
|
|
207
|
-
// 12 (2026-09-17): one contract — the sponsor facet is folded back into the
|
|
208
|
-
// manager; `sponsor()` and the fallback are gone, every entry, error and event unchanged, so
|
|
209
|
-
// `fPoolManagerAbi` is the manager's own ABI and no longer a union. Layout unchanged.
|
|
210
|
-
// 13 (2026-09-18): one vocabulary — `HARVEST_FEE` is `HARVEST_PROTOCOL_CUT` (a
|
|
211
|
-
// cut of harvested income, not a fee on the harvest) and the exemption is `harvestCutExempt` /
|
|
212
|
-
// `setHarvestCutExempt`; `acceptAuthority` clears the operator, pending and accepted (a mandate
|
|
213
|
-
// is voided by the handover of the role that granted it); `setLegs` needs a generation to have
|
|
214
|
-
// lived (`gen > 0`); `initialize` refuses a codeless base and `mint` refuses `to = address(0)`
|
|
215
|
-
// on both managers. Layout unchanged.
|
|
216
|
-
// 14 (2026-09-20): the policy — `FPoolKey.policy`, every pool id moves; `dissolve` is
|
|
217
|
-
// `retire`, `regenerate` releases the dead shares' pot, `harvestable`/`unharvested` are the
|
|
218
|
-
// readouts; `feePerL`, `edgePerL`, `HARVEST_PROTOCOL_CUT`, `harvestCutExempt` are gone.
|
|
219
|
-
// 15 (2026-09-20): the policy answers every question — `FPoolKey.authority` is
|
|
220
|
-
// `creator` (every pool id moves again); the roles, gates and list are the pool's POLICY's
|
|
221
|
-
// (`FPolicyBase` / `PrivatePolicy`), not the manager's: `getPool` has `policy` and `asks` and no
|
|
222
|
-
// role; `proposeAuthority`, `appointOperator`, `setGates`, `setAllowed` (`setMinters` / `setTakers` since 17) are policy writes;
|
|
223
|
-
// `policyApproved(kind, policy)` / `setPolicyApproved(kind, policy, ok)`; `Regenerated` names the payee;
|
|
224
|
-
// `HARVEST_CUT_MAX` / `POT_CUT_MAX` cap what a policy may route to the protocol.
|
|
225
|
-
// 16 (2026-09-21): the word is POLICY — a rename, no pool id moves: `FPoolKey.policy`,
|
|
226
|
-
// `IFPolicy`, `FPolicyBase`, `PublicPolicy` … `PadPolicy`, `policyApproved` / `setPolicyApproved`,
|
|
227
|
-
// `PolicyApproved`; `PolPolicy.setPolicy` / `PolicySet` are `setRules` / `RulesSet`.
|
|
228
|
-
// 17 (2026-09-21): the registry, the move, the stamp, two lists, one base — no
|
|
229
|
-
// pool id moves: the F manager takes a `PolicyRegistry` at construction and asks it at a birth
|
|
230
|
-
// (`policyApproved` / `setPolicyApproved` left the manager: `registryApprove` …); the key's policy
|
|
231
|
-
// is the policy at birth, `migrate` moves a pool for the registry's owner; `stamp` / `setAsks` are
|
|
232
|
-
// the policy's; the desk's `setAllowed` / `isAllowed` are `setMinters` / `setTakers` / `isMinter` /
|
|
233
|
-
// `isTaker`; a pad and a POL hold one base (`OneBase`).
|
|
234
|
-
// 18–19: no role, no kind and no name on the manager (049); the events carry what a reader needs (050).
|
|
235
|
-
// 20 (2026-09-25, logswap-contract #53): policy isolation — `PolicyRegistry.migrate(manager, key, to)`
|
|
236
|
-
// takes the pool's KEY (was its id), `kindOf(policy)` is the tag recorded at approval, the
|
|
237
|
-
// registry emits `Migrated`; `IFPolicy.onMigrate` is brought the creator, authority and name;
|
|
238
|
-
// the desk's lists are keyed by `listEpoch`. The manager's ABI did not move.
|
|
239
|
-
// 21 (2026-09-26, #54): `regenerate` is the generation step — the policy's `Terms` name a
|
|
240
|
-
// `carried` holder (a fifth word, 160 B), every other holder is frozen out pro rata into
|
|
241
|
-
// generation g's bundle and redeems it (`fPoolRedeem` / `fPoolRollIn` with gen = g), and the
|
|
242
|
-
// pool goes on as g + 1. The manager lost `FEE_MIN` / `FEE_MAX` (see keys.ts), `harvestable`
|
|
243
|
-
// (the bid: `getPool().Q` when L > 0), `idOf(FPoolKey)` (hashed locally, `fPoolIdOfKey`) and
|
|
244
|
-
// `reserveOf` (`legOf`'s fourth word). `PadPolicy.rung` is gone: the pad's rung is `gen`, the
|
|
245
|
-
// next threshold `threshold(gen)`. A pad never retires; a public pool refuses `regenerate`.
|
|
246
|
-
// 23: a harvest asks `may(Harvest)` and takes no terms and no cut (decisions 056): `onHarvest`, `HARVEST_CUT_MAX`,
|
|
247
|
-
// `harvestCut`, `setHarvestCut` are gone; a pad's split (creator's cut, token burn) rides in the key's salt.
|
|
248
|
-
// 24 (logswap-contract#58): the pot splits in quote — `Terms.burn` is quote spent on a buy-and-burn, the
|
|
249
|
-
// rest deepens the bid, no buy-in, `Regenerated` is (pot, payee, toPayee, cut, burnt, deepened), a pad's
|
|
250
|
-
// salt carries `burnShare` of the pot (057); the mint fee all to the treasury (058, 066); `phi` → `swapFee`,
|
|
251
|
-
// `MINT_FEE()` → `mintFee()`, the policies' fee tiers, a canonical public pool (059).
|
|
252
|
-
// 25 (logswap-contract#59): the views moved behind `extsload` (062) — this SDK reads them through the
|
|
253
|
-
// lens (`fPool`, `getFPools`, `fBundleOf`, `fDividendOf`, `fLienOf`); the capped F pool, `FPoolKey.cap` (`lnCapOverFloor` since 27)
|
|
254
|
-
// appended so every pool id moved (061); the lien, `lock` / `unlock` (063); the floor is `logFloor`, its reference `refLogFloor`.
|
|
255
|
-
// 26 (logswap-contract#60): the mint fee is per pool, proposed at `initialize(key, mintFee)` and answered
|
|
256
|
-
// by the policy's `onInitialize` from its menu (065); `MINT_FEE` is gone; a fee of 0 is no fee; the
|
|
257
|
-
// policies curate creators, a public pool is uncapped, one pad per base (064). No pool id moved.
|
|
258
|
-
// 27 (decision 066): `FPoolKey.cap` → `lnCapOverFloor` (a name: no id moved); `feeCollector` → `treasury` (proposed by the LOG Authority, accepted by itself);
|
|
259
|
-
// the registry's `owner` → `logAuthority`, administering every policy's lists and numbers; a public pool
|
|
260
|
-
// is born to the LOG Authority. No pool id moved.
|
|
261
|
-
// 28 (decision 067): no buy-and-burn — `Terms` is four words, `Regenerated` loses `burnt`; on a pad the manager caps the
|
|
262
|
-
// payee at `PAYEE_CUT_MAX` and carries only the dead shares, and refuses `retire`; `PadPolicy.pack(creatorShare, nonce)`,
|
|
263
|
-
// `setSchedule` without a burn range, `splitOf` → (creatorShare, protocolShare). No pool id moved.
|
|
264
|
-
// 29 (decision 068): the restructure guard and the registry's sunset read `block.timestamp` —
|
|
265
|
-
// `Pool.restructureBlock` is `restructureTime` (unix seconds, same slot), `PolicyRegistry.sunset(policy, untilTime)`.
|
|
266
|
-
// Names only: no pool id moved.
|
|
267
|
-
// 30 (decision 071): the events — `FSwap` is the shared `Swap` plus `FSwapState`, object-word names
|
|
268
|
-
// (`PoolCreated`, `GenerationSeeded`, `SharesMinted`, ...), `PoolCreated` carries the mint fee.
|
|
269
|
-
// No pool id moved.
|
|
270
|
-
// 31 (decision 072): `DividendClaimed` names the generation (`gen`, indexed, after `poolId`); `lock` / `unlock` emit
|
|
271
|
-
// `LienLocked` / `LienUnlocked`. No selector, storage layout or pool id moved.
|
|
272
|
-
// 33 (decisions 073, 074): sponsor-bound policies, the income fee, registry admission.
|
|
273
|
-
// 34-38 (decisions 075-085): one liquidity routine. `FPoolKey` holds no weights and no cap and gains `mintFee` (every pool
|
|
274
|
-
// id moved); `initialize(key)`; `seed` / `retire` / `setLegs` are gone for `deployLiquidity(poolId, baseAssets,
|
|
275
|
-
// quoteAmount, lnCapOverSeed, to)` (it SETS THE BOOK on an unfunded or a live pool), `close(poolId, to)` and
|
|
276
|
-
// `regenerate(poolId, to)`; asset membership is fixed by the key; `LiquidityDeployed` echoes the input,
|
|
277
|
-
// `GenerationSeeded` / `LegsSet` are gone; the lens `fPool` field is `baseAssets` (`baseLegs` before decision 090), the cap `lnCapOverSeed`; the pot and the
|
|
278
|
-
// income fee are the income and the income tax (`IncomeReleased`, `incomeHeld`, `incomeTax`); a pad is uncapped.
|
|
279
|
-
// 39 (decision 087): `swapFeeB4B` is gone; base-for-base pays `swapFee` once, not 2·swapFee.
|
|
280
|
-
// A breaking bump: raised in the same change.
|
|
281
|
-
// 40 (decision 098): the policies are immutable and the LOG's — `SponsorPolicyF` replaces `PublicPolicy` / `PrivatePolicy`, `PolPolicy` /
|
|
282
|
-
// `PadPolicy` lose their setters (and the lists, the handover and `creator`: the authority is `key.creator` for life); `Pool.asks` is
|
|
283
|
-
// `Pool.flags` (`GATE_SWAP` 1, `GATE_MINT` 2, `SEED_TO_DEAD` 4) and `Pool.operator` caches the operator; `setPermissions` /
|
|
284
|
-
// `PermissionsSet` are `setGates` / `GatesSet`; the registry's `migrate(manager, key, to, permissions)` replaces `migratePrivate`,
|
|
285
|
-
// `orphan(manager, key)` moves a pool to `OrphanPolicyF`. No pool id moved.
|
|
286
|
-
// 41 (policy.md): one policy contract, `PolicyF`, whose kinds are parameter sets — `SponsorPolicyF`, `PolPolicy`, `PadPolicy` and
|
|
287
|
-
// `OrphanPolicyF` are gone. The AUTHORITY is the policy's (immutable) and appoints each pool's OPERATOR, who funds, harvests, closes
|
|
288
|
-
// and sets the modes and the name. `PoolKeyF` is `(quote, bases, swapFeeIdx, policy, salt)` — no creator, no mint fee: the swap fee is
|
|
289
|
-
// an index into `FEE_LIST` (1, 2, 5, 10, 20, 50, 100, 200 bp) and the mint fee the next entry — so EVERY POOL ID MOVED.
|
|
290
|
-
// `deployLiquidity(poolId, baseAssets, quoteAmount, lnCapOverSeed)` on an inactive pool only (no `to`: the operator holds the
|
|
291
|
-
// shares); `harvest(poolId, extra, to)` takes the income and `extra` capital; `close(poolId, to)` at any bid, harvesting first,
|
|
292
|
-
// refused on a pad; `regenerate` is gone (`multicall(close, redeem, deployLiquidity)`); the registry's `migrate`, `orphan` and
|
|
293
|
-
// `setOrphanPolicy` are gone, `sunset` also refuses `deployLiquidity`. `PoolCreated(poolId, quote, policy, bases, swapFeeIdx, salt)`;
|
|
294
|
-
// `IncomeHarvested(poolId, to, gen, income, capital, tax, toOperator, Q)`; `GenerationFrozen` from `close` alone; `IncomeReleased` and
|
|
295
|
-
// `PolicyMigrated` are gone. The policy's name is an event (`NameSet`), its lists are per policy (`setRights`, `RightsSet`), its
|
|
296
|
-
// modes per pool (`setSwapMode` / `setMintMode`, each Open < Listed < Operator with `mintMode ≥ swapMode`).
|
|
297
|
-
// 42 (decision 107): every event names its actor and the routers emit none (`RouterCall` is gone). `mint(poolId, payer, to, L, maxQuoteIn)`;
|
|
298
|
-
// `claim(poolId, gen, owner, to)` (the owner or its ERC-6909 operator); `SharesMinted(poolId, to, gen, sender, payer, L, shares, dQuote,
|
|
299
|
-
// poolL, supply)`; `SharesBurned` indexes `gen` and names `owner` (was `from`), `DividendClaimed` names `owner` (was `holder`);
|
|
300
|
-
// `PoolCreated(poolId, quote, creator, policy, bases, swapFeeIdx, salt)` (`creator` a topic, `policy` data); `LiquidityDeployed`,
|
|
301
|
-
// `IncomeHarvested` and `GenerationFrozen` carry `operator` as a topic; `RouterF.BadToken` is `WrongToken`. No pool id moved.
|
|
302
82
|
export const EXPECTED_F_VERSION = 44n;
|
|
303
83
|
export async function assertVersion(c, expected = EXPECTED_VERSION) {
|
|
304
84
|
const { managerCAbi, managerFAbi } = await import("./generated.js");
|
|
305
85
|
const withC = hasC(c);
|
|
306
|
-
// independent reads: one round trip, not one per manager
|
|
307
86
|
const [gotC, gotF, wiring] = await Promise.all([
|
|
308
|
-
// the C stack is optional (F ships first); asserted the same way when deployed
|
|
309
87
|
withC ? c.public.readContract({ address: c.addresses.managerC, abi: managerCAbi, functionName: "version" }) : Promise.resolve(null),
|
|
310
88
|
c.public.readContract({ address: c.addresses.managerF, abi: managerFAbi, functionName: "version" }),
|
|
311
89
|
assertWiring(c).then(() => null, (e) => e),
|
|
@@ -318,17 +96,9 @@ export async function assertVersion(c, expected = EXPECTED_VERSION) {
|
|
|
318
96
|
throw new Error(`logswap: F manager at ${c.addresses.managerF} reports version ${gotF}, but this SDK needs ` +
|
|
319
97
|
`at least F version ${EXPECTED_F_VERSION}. Upgrade the deployment or point at a newer one.`);
|
|
320
98
|
}
|
|
321
|
-
// the wiring's error is the less specific one, so a version mismatch is reported first
|
|
322
99
|
if (wiring)
|
|
323
100
|
throw wiring;
|
|
324
101
|
}
|
|
325
|
-
/**
|
|
326
|
-
* The versions say the managers are the right code; this says the rest of the addresses belong
|
|
327
|
-
* to THEM. A stale router or lens from a previous deployment passes every version check and then
|
|
328
|
-
* fails in the worst way: approvals go to a router that pulls for another manager, or every pull
|
|
329
|
-
* reverts because the router's Permit2 is not the one the user approved. Each side is checked on its
|
|
330
|
-
* own: the router and the lens name their manager (`mgr()`), and the router its Permit2.
|
|
331
|
-
*/
|
|
332
102
|
export async function assertWiring(c) {
|
|
333
103
|
const { routerCAbi, routerFAbi, lensCAbi, lensFAbi } = await import("./generated.js");
|
|
334
104
|
const rd = (address, abi, functionName) => c.public.readContract({ address, abi, functionName });
|
package/dist/fees.d.ts
CHANGED
|
@@ -1,68 +1,24 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* fees.ts — swap fees over a window, from `Swap` logs.
|
|
3
|
-
*
|
|
4
|
-
* `F` cannot answer "what did takers pay this week": it is per unit of L, it carries the mint-fee
|
|
5
|
-
* credits as well as swap fees, and it has no window. Each `Swap` event carries the quote leg and
|
|
6
|
-
* φ, and the fee is a fixed fraction of that leg, so the sum over a window is exact up to rounding:
|
|
7
|
-
*
|
|
8
|
-
* quote in (price up): the curve takes q/(1+φ), the fee is q·φ/(1+φ)
|
|
9
|
-
* quote out (price down): the curve releases q/(1−φ), the fee is q·φ/(1−φ)
|
|
10
|
-
*
|
|
11
|
-
* Both equal φ·L·|Δx| summed over the swap's segments — the same φ·|dx| per unit L that `F` books.
|
|
12
|
-
*/
|
|
13
1
|
import { type LogswapClient } from "./client.js";
|
|
14
2
|
import type { DiscoveredMarket } from "./pools.js";
|
|
15
|
-
/**
|
|
16
|
-
* The fee one swap paid, in quote, from its `Swap` event's fields.
|
|
17
|
-
*
|
|
18
|
-
* @deprecated The C `Swap` event carries its `fee` since C version 5 (decisions 050); read that.
|
|
19
|
-
* This reconstruction from φ rounds where the contract does not, and is kept for older logs.
|
|
20
|
-
*/
|
|
21
3
|
export declare function swapFeeOf(e: {
|
|
22
4
|
baseIn: boolean;
|
|
23
5
|
amountIn: bigint;
|
|
24
6
|
amountOut: bigint;
|
|
25
7
|
}, swapFee: bigint): bigint;
|
|
26
|
-
/** Swap fees paid over a window, in the market's quote units. */
|
|
27
8
|
export interface SwapFeeWindow {
|
|
28
9
|
fromBlock: bigint;
|
|
29
10
|
toBlock: bigint;
|
|
30
|
-
/** Window start, unix seconds — `since`, or the first block's timestamp, never before the market opened. */
|
|
31
11
|
from: bigint;
|
|
32
|
-
/** Window end, unix seconds — the last block's timestamp. */
|
|
33
12
|
to: bigint;
|
|
34
13
|
seconds: bigint;
|
|
35
14
|
swapFees: bigint;
|
|
36
15
|
swaps: number;
|
|
37
16
|
}
|
|
38
|
-
/**
|
|
39
|
-
* The first block with timestamp ≥ `t` in `[lo, hi]`; `hi` when none is earlier.
|
|
40
|
-
*
|
|
41
|
-
* A PARALLEL search: each round reads {@link PROBES} evenly spaced blocks at once and keeps the
|
|
42
|
-
* sixteenth of the bracket that holds the answer, so 64k blocks take 4 round trips. Bisection read
|
|
43
|
-
* one block per round trip — ~16 sequential `getBlock`s, seconds apiece against a distant node,
|
|
44
|
-
* before a fee figure could render. Interpolating on timestamps was tried and did no better: a
|
|
45
|
-
* devnet mines on demand plus a heartbeat, so its blocks are far from evenly spaced in time.
|
|
46
|
-
* Exact for monotonic timestamps; a chain restored from a snapshot can carry a genesis stamped
|
|
47
|
-
* after its later blocks, so callers bound `lo` by the block they care about (a pool's own).
|
|
48
|
-
*/
|
|
49
17
|
export declare function blockAtOrAfter(c: LogswapClient, t: bigint, lo: bigint, hi: bigint): Promise<bigint>;
|
|
50
|
-
/**
|
|
51
|
-
* Sum the swap fees of market `m` over a window: from `since` (unix seconds) or `fromBlock`, to
|
|
52
|
-
* `toBlock` (default latest). Either start is clamped to the market's opening, so a period longer
|
|
53
|
-
* than the market's life measures its whole life and `seconds` says how long that was.
|
|
54
|
-
*/
|
|
55
18
|
export declare function swapFees(c: LogswapClient, m: DiscoveredMarket, opts?: {
|
|
56
19
|
since?: bigint;
|
|
57
20
|
fromBlock?: bigint;
|
|
58
|
-
toBlock?: bigint;
|
|
21
|
+
toBlock?: bigint;
|
|
59
22
|
indexer?: string;
|
|
60
23
|
}): Promise<SwapFeeWindow>;
|
|
61
|
-
/**
|
|
62
|
-
* The window's swap fees over the market's CURRENT active L, annualised linearly over the window.
|
|
63
|
-
* A fraction: 0.12 is 12%. Linear: fees are paid out, so none compound.
|
|
64
|
-
*
|
|
65
|
-
* Per unit of L. An uncapped position is worth L·(x − ξ + 1), so its return on capital is this
|
|
66
|
-
* divided by (x − ξ + 1).
|
|
67
|
-
*/
|
|
68
24
|
export declare function swapFeeApy(w: Pick<SwapFeeWindow, "swapFees" | "seconds">, lActive: bigint): number;
|
package/dist/fees.js
CHANGED
|
@@ -1,49 +1,18 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* fees.ts — swap fees over a window, from `Swap` logs.
|
|
3
|
-
*
|
|
4
|
-
* `F` cannot answer "what did takers pay this week": it is per unit of L, it carries the mint-fee
|
|
5
|
-
* credits as well as swap fees, and it has no window. Each `Swap` event carries the quote leg and
|
|
6
|
-
* φ, and the fee is a fixed fraction of that leg, so the sum over a window is exact up to rounding:
|
|
7
|
-
*
|
|
8
|
-
* quote in (price up): the curve takes q/(1+φ), the fee is q·φ/(1+φ)
|
|
9
|
-
* quote out (price down): the curve releases q/(1−φ), the fee is q·φ/(1−φ)
|
|
10
|
-
*
|
|
11
|
-
* Both equal φ·L·|Δx| summed over the swap's segments — the same φ·|dx| per unit L that `F` books.
|
|
12
|
-
*/
|
|
13
1
|
import { managerC } from "./client.js";
|
|
14
2
|
import { managerCAbi } from "./generated.js";
|
|
15
3
|
import { getEventLogs } from "./history.js";
|
|
16
4
|
const WAD = 10n ** 18n;
|
|
17
5
|
const YEAR_SECONDS = 31_536_000;
|
|
18
|
-
/**
|
|
19
|
-
* The fee one swap paid, in quote, from its `Swap` event's fields.
|
|
20
|
-
*
|
|
21
|
-
* @deprecated The C `Swap` event carries its `fee` since C version 5 (decisions 050); read that.
|
|
22
|
-
* This reconstruction from φ rounds where the contract does not, and is kept for older logs.
|
|
23
|
-
*/
|
|
24
6
|
export function swapFeeOf(e, swapFee) {
|
|
25
7
|
return e.baseIn ? (e.amountOut * swapFee) / (WAD - swapFee) : (e.amountIn * swapFee) / (WAD + swapFee);
|
|
26
8
|
}
|
|
27
|
-
/** Probes per round of {@link blockAtOrAfter}: 15 splits the bracket 16 ways. */
|
|
28
9
|
const PROBES = 15n;
|
|
29
|
-
/**
|
|
30
|
-
* The first block with timestamp ≥ `t` in `[lo, hi]`; `hi` when none is earlier.
|
|
31
|
-
*
|
|
32
|
-
* A PARALLEL search: each round reads {@link PROBES} evenly spaced blocks at once and keeps the
|
|
33
|
-
* sixteenth of the bracket that holds the answer, so 64k blocks take 4 round trips. Bisection read
|
|
34
|
-
* one block per round trip — ~16 sequential `getBlock`s, seconds apiece against a distant node,
|
|
35
|
-
* before a fee figure could render. Interpolating on timestamps was tried and did no better: a
|
|
36
|
-
* devnet mines on demand plus a heartbeat, so its blocks are far from evenly spaced in time.
|
|
37
|
-
* Exact for monotonic timestamps; a chain restored from a snapshot can carry a genesis stamped
|
|
38
|
-
* after its later blocks, so callers bound `lo` by the block they care about (a pool's own).
|
|
39
|
-
*/
|
|
40
10
|
export async function blockAtOrAfter(c, t, lo, hi) {
|
|
41
11
|
if (lo >= hi)
|
|
42
12
|
return hi;
|
|
43
13
|
const stamp = async (n) => (await c.public.getBlock({ blockNumber: n })).timestamp;
|
|
44
14
|
if ((await stamp(lo)) >= t)
|
|
45
15
|
return lo;
|
|
46
|
-
// invariant from here: ts(lo) < t, and the answer is in (lo, hi]
|
|
47
16
|
while (hi - lo > 1n) {
|
|
48
17
|
const width = hi - lo;
|
|
49
18
|
const probes = [...new Set(Array.from({ length: Number(PROBES) }, (_, i) => lo + (width * BigInt(i + 1)) / (PROBES + 1n)))].filter((n) => n > lo && n < hi);
|
|
@@ -61,11 +30,6 @@ export async function blockAtOrAfter(c, t, lo, hi) {
|
|
|
61
30
|
}
|
|
62
31
|
return hi;
|
|
63
32
|
}
|
|
64
|
-
/**
|
|
65
|
-
* Sum the swap fees of market `m` over a window: from `since` (unix seconds) or `fromBlock`, to
|
|
66
|
-
* `toBlock` (default latest). Either start is clamped to the market's opening, so a period longer
|
|
67
|
-
* than the market's life measures its whole life and `seconds` says how long that was.
|
|
68
|
-
*/
|
|
69
33
|
export async function swapFees(c, m, opts = {}) {
|
|
70
34
|
const toBlock = opts.toBlock ?? (await c.public.getBlockNumber());
|
|
71
35
|
const [opened, last] = await Promise.all([
|
|
@@ -89,7 +53,6 @@ export async function swapFees(c, m, opts = {}) {
|
|
|
89
53
|
const ev = managerCAbi.find((x) => x.type === "event" && x.name === "Swap");
|
|
90
54
|
if (!ev)
|
|
91
55
|
throw new Error("logswap: Swap event missing from the generated ABI");
|
|
92
|
-
// the event carries the fee the swap charged (decisions 050), exactly — no re-derivation from φ
|
|
93
56
|
let fees = 0n;
|
|
94
57
|
let swaps = 0;
|
|
95
58
|
const indexer = opts.indexer ?? c.indexerUrl;
|
|
@@ -102,13 +65,6 @@ export async function swapFees(c, m, opts = {}) {
|
|
|
102
65
|
const to = last.timestamp;
|
|
103
66
|
return { fromBlock, toBlock, from, to, seconds: to > from ? to - from : 0n, swapFees: fees, swaps };
|
|
104
67
|
}
|
|
105
|
-
/**
|
|
106
|
-
* The window's swap fees over the market's CURRENT active L, annualised linearly over the window.
|
|
107
|
-
* A fraction: 0.12 is 12%. Linear: fees are paid out, so none compound.
|
|
108
|
-
*
|
|
109
|
-
* Per unit of L. An uncapped position is worth L·(x − ξ + 1), so its return on capital is this
|
|
110
|
-
* divided by (x − ξ + 1).
|
|
111
|
-
*/
|
|
112
68
|
export function swapFeeApy(w, lActive) {
|
|
113
69
|
if (w.seconds <= 0n || lActive <= 0n)
|
|
114
70
|
return 0;
|