@logswap/sdk 0.5.71 → 0.5.73
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 +21 -2
- package/dist/admin.d.ts +38 -16
- package/dist/admin.js +47 -18
- package/dist/client.d.ts +7 -2
- package/dist/client.js +15 -2
- package/dist/fees.d.ts +1 -1
- package/dist/fees.js +2 -2
- package/dist/fpool.d.ts +203 -26
- package/dist/fpool.js +186 -107
- package/dist/generated.d.ts +812 -446
- package/dist/generated.js +486 -246
- package/dist/indexer.js +2 -2
- package/dist/keys.d.ts +4 -3
- package/dist/keys.js +3 -3
- package/dist/pools.d.ts +5 -4
- package/dist/pools.js +7 -6
- package/dist/positions.d.ts +3 -2
- package/dist/positions.js +3 -2
- package/package.json +1 -1
- package/src/admin.ts +51 -18
- package/src/client.ts +15 -2
- package/src/fees.ts +2 -2
- package/src/fpool.ts +244 -146
- package/src/generated.ts +486 -246
- package/src/indexer.ts +3 -3
- package/src/keys.ts +6 -5
- package/src/pools.ts +7 -6
- package/src/positions.ts +3 -2
package/dist/indexer.js
CHANGED
|
@@ -138,13 +138,13 @@ export async function indexerHealthy(url, signal) {
|
|
|
138
138
|
* everywhere else, so a wrong id fails loudly instead of addressing the wrong pool.
|
|
139
139
|
*/
|
|
140
140
|
export async function discoverMarketsIndexed(url, signal) {
|
|
141
|
-
const nodes = await gqlAll(url, "allInitializes", "poolId base quote tickSpacing
|
|
141
|
+
const nodes = await gqlAll(url, "allInitializes", "poolId base quote tickSpacing swapFee x0 blockNumber txHash contractAddress", { signal });
|
|
142
142
|
return nodes.map((n) => {
|
|
143
143
|
const key = {
|
|
144
144
|
base: n.base,
|
|
145
145
|
quote: n.quote,
|
|
146
146
|
tickSpacing: BigInt(n.tickSpacing),
|
|
147
|
-
|
|
147
|
+
swapFee: BigInt(n.swapFee), // rindexer names the column after the event's field: `swapFee` since C version 6 (logswap-be #40)
|
|
148
148
|
};
|
|
149
149
|
return {
|
|
150
150
|
key,
|
package/dist/keys.d.ts
CHANGED
|
@@ -33,14 +33,15 @@ export interface PoolKey {
|
|
|
33
33
|
* The swap fee, WAD, fixed for the life of the market: {@link FEE_MIN} (1 bp) ≤ φ ≤ {@link FEE_MAX} (1%),
|
|
34
34
|
* or `0n`, which selects `DEFAULT_FEE` (2 bp) at read time. Four fields since C version 4
|
|
35
35
|
*: `kappa` and `alpha` left with the variance kernel, and `phiMin` — a floor with
|
|
36
|
-
* nothing above it — became `phi
|
|
36
|
+
* nothing above it — became `phi`, named `swapFee` since C version 6 (decisions 059). The name
|
|
37
|
+
* is not part of the encoding: no pool id changed with it.
|
|
37
38
|
*/
|
|
38
|
-
|
|
39
|
+
swapFee: bigint;
|
|
39
40
|
}
|
|
40
41
|
/**
|
|
41
42
|
* `poolId = keccak256(abi.encode(key))` — the primary key of the entire read model.
|
|
42
43
|
*
|
|
43
|
-
* Note the zero-vs-default caveat the Solidity type documents: a `
|
|
44
|
+
* Note the zero-vs-default caveat the Solidity type documents: a `swapFee` of `0` resolves to
|
|
44
45
|
* `DEFAULT_FEE` at READ time, so a key carrying `0n` and one carrying the resolved default are
|
|
45
46
|
* DIFFERENT markets with different ids, even though they behave identically. Always address a
|
|
46
47
|
* market by the key it was initialized with.
|
package/dist/keys.js
CHANGED
|
@@ -27,14 +27,14 @@ const POOL_KEY_ABI = [
|
|
|
27
27
|
{ name: "base", type: "address" },
|
|
28
28
|
{ name: "quote", type: "address" },
|
|
29
29
|
{ name: "tickSpacing", type: "int256" },
|
|
30
|
-
{ name: "
|
|
30
|
+
{ name: "swapFee", type: "uint256" },
|
|
31
31
|
],
|
|
32
32
|
},
|
|
33
33
|
];
|
|
34
34
|
/**
|
|
35
35
|
* `poolId = keccak256(abi.encode(key))` — the primary key of the entire read model.
|
|
36
36
|
*
|
|
37
|
-
* Note the zero-vs-default caveat the Solidity type documents: a `
|
|
37
|
+
* Note the zero-vs-default caveat the Solidity type documents: a `swapFee` of `0` resolves to
|
|
38
38
|
* `DEFAULT_FEE` at READ time, so a key carrying `0n` and one carrying the resolved default are
|
|
39
39
|
* DIFFERENT markets with different ids, even though they behave identically. Always address a
|
|
40
40
|
* market by the key it was initialized with.
|
|
@@ -45,7 +45,7 @@ export function poolId(key) {
|
|
|
45
45
|
base: key.base,
|
|
46
46
|
quote: key.quote,
|
|
47
47
|
tickSpacing: key.tickSpacing,
|
|
48
|
-
|
|
48
|
+
swapFee: key.swapFee,
|
|
49
49
|
},
|
|
50
50
|
]));
|
|
51
51
|
}
|
package/dist/pools.d.ts
CHANGED
|
@@ -36,11 +36,12 @@ export interface PoolState {
|
|
|
36
36
|
/** Read a market's full state by key. */
|
|
37
37
|
export declare function getPool(c: LogswapClient, key: PoolKey): Promise<PoolState>;
|
|
38
38
|
/**
|
|
39
|
-
* The market's fee: the key's `
|
|
40
|
-
*
|
|
41
|
-
*
|
|
39
|
+
* The market's swap fee: the key's `swapFee` with `0n` resolved to `DEFAULT_FEE` — the manager's
|
|
40
|
+
* `swapFeeOf` (`phiOf` before C version 6). Constant for the market's life (C version 4 — `phiEff`
|
|
41
|
+
* and the variance kernel before). Reverts for a key nobody initialized, which `discoverMarkets`
|
|
42
|
+
* relies on to drop a stale indexer's rows. (`swapFeeOf` in `fees.ts` is the fee one swap paid.)
|
|
42
43
|
*/
|
|
43
|
-
export declare function
|
|
44
|
+
export declare function marketSwapFee(c: LogswapClient, key: PoolKey): Promise<bigint>;
|
|
44
45
|
/**
|
|
45
46
|
* Price from the stored log-price. **Lossy** — `x` is exact and this is a float, so use it for
|
|
46
47
|
* display and never for arithmetic you intend to send back on-chain.
|
package/dist/pools.js
CHANGED
|
@@ -27,15 +27,16 @@ export async function getPool(c, key) {
|
|
|
27
27
|
return v;
|
|
28
28
|
}
|
|
29
29
|
/**
|
|
30
|
-
* The market's fee: the key's `
|
|
31
|
-
*
|
|
32
|
-
*
|
|
30
|
+
* The market's swap fee: the key's `swapFee` with `0n` resolved to `DEFAULT_FEE` — the manager's
|
|
31
|
+
* `swapFeeOf` (`phiOf` before C version 6). Constant for the market's life (C version 4 — `phiEff`
|
|
32
|
+
* and the variance kernel before). Reverts for a key nobody initialized, which `discoverMarkets`
|
|
33
|
+
* relies on to drop a stale indexer's rows. (`swapFeeOf` in `fees.ts` is the fee one swap paid.)
|
|
33
34
|
*/
|
|
34
|
-
export async function
|
|
35
|
+
export async function marketSwapFee(c, key) {
|
|
35
36
|
return c.public.readContract({
|
|
36
37
|
address: c.addresses.cPoolManager,
|
|
37
38
|
abi: cPoolManagerAbi,
|
|
38
|
-
functionName: "
|
|
39
|
+
functionName: "swapFeeOf",
|
|
39
40
|
args: [key],
|
|
40
41
|
});
|
|
41
42
|
}
|
|
@@ -124,7 +125,7 @@ export async function discoverMarkets(c, opts = {}) {
|
|
|
124
125
|
base: a.base,
|
|
125
126
|
quote: a.quote,
|
|
126
127
|
tickSpacing: a.tickSpacing,
|
|
127
|
-
|
|
128
|
+
swapFee: a.swapFee,
|
|
128
129
|
};
|
|
129
130
|
return {
|
|
130
131
|
key,
|
package/dist/positions.d.ts
CHANGED
|
@@ -110,8 +110,9 @@ export declare const MINT_FEE: bigint;
|
|
|
110
110
|
* the position's own legs, so a mint's total quote pull is `positionQuote(p, x) + mintFee(p, x)`.
|
|
111
111
|
*
|
|
112
112
|
* Mirrors the manager's exemption cases: a DORMANT mint pays nothing — floor above spot, or a
|
|
113
|
-
* capped class spot has already passed (`cap <= x`). Anything earning pays `MINT_FEE · L`,
|
|
114
|
-
*
|
|
113
|
+
* capped class spot has already passed (`cap <= x`). Anything earning pays `MINT_FEE · L`, all of
|
|
114
|
+
* it the protocol's since C version 6 (decisions 058); with no collector it goes through `F` to the
|
|
115
|
+
* LPs already earning, and with none earning it is not charged. This is NOT the swap fee:
|
|
115
116
|
* that one is charged per unit of |Δ log p| on swaps; this is a flat charge on L, once, at mint.
|
|
116
117
|
*
|
|
117
118
|
* One rung of imprecision: for a floor or cap exactly AT spot the contract consults its `currentK`
|
package/dist/positions.js
CHANGED
|
@@ -136,8 +136,9 @@ export const MINT_FEE = 2n * 10n ** 14n;
|
|
|
136
136
|
* the position's own legs, so a mint's total quote pull is `positionQuote(p, x) + mintFee(p, x)`.
|
|
137
137
|
*
|
|
138
138
|
* Mirrors the manager's exemption cases: a DORMANT mint pays nothing — floor above spot, or a
|
|
139
|
-
* capped class spot has already passed (`cap <= x`). Anything earning pays `MINT_FEE · L`,
|
|
140
|
-
*
|
|
139
|
+
* capped class spot has already passed (`cap <= x`). Anything earning pays `MINT_FEE · L`, all of
|
|
140
|
+
* it the protocol's since C version 6 (decisions 058); with no collector it goes through `F` to the
|
|
141
|
+
* LPs already earning, and with none earning it is not charged. This is NOT the swap fee:
|
|
141
142
|
* that one is charged per unit of |Δ log p| on swaps; this is a flat charge on L, once, at mint.
|
|
142
143
|
*
|
|
143
144
|
* One rung of imprecision: for a floor or cap exactly AT spot the contract consults its `currentK`
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@logswap/sdk",
|
|
3
|
-
"version": "0.5.
|
|
3
|
+
"version": "0.5.73",
|
|
4
4
|
"description": "TypeScript SDK for Logswap, the liquidity primitive introducing the logarithmic invariant — typed wrappers over the CPoolManager / FPoolManager / Router / Lens surface.",
|
|
5
5
|
"license": "GPL-2.0-or-later",
|
|
6
6
|
"type": "module",
|
package/src/admin.ts
CHANGED
|
@@ -1,14 +1,12 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* admin — the protocol's writes: the C
|
|
3
|
-
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
2
|
+
* admin — the protocol's writes: the C swap-fee tax (decisions 060), the policies a pool may be
|
|
3
|
+
* born with (the registry's), the policies' own numbers (the quote list, the fee tiers, a pad's
|
|
4
|
+
* schedule, a POL's rules), and the two-step collector handover. Plain writes to the managers, the
|
|
5
|
+
* registry and the policies; no router.
|
|
6
6
|
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
* policy (`PadPolicy.setSchedule`: the protocol's pot share and the ranges a creator chooses inside) and capped by the manager (`POT_CUT_MAX`, `BURN_MAX`; a harvest has no cut, decisions 056); the release's
|
|
11
|
-
* protocol share likewise (`POT_CUT_MAX`).
|
|
7
|
+
* The mint fee has no cut to set since C version 6 / F version 24 (decisions 058): the whole fee
|
|
8
|
+
* is the protocol's on both managers. A harvest has no cut (056); a pad's protocol share of the pot
|
|
9
|
+
* is the policy's (`PadPolicy.setSchedule`), capped by the manager at `POT_CUT_MAX`.
|
|
12
10
|
*/
|
|
13
11
|
|
|
14
12
|
import type { Address, Hash } from "viem";
|
|
@@ -25,13 +23,24 @@ function write(c: LogswapClient, address: Address, abi: readonly unknown[], func
|
|
|
25
23
|
return wallet(c).writeContract({ address, abi, functionName, args, chain: c.wallet!.chain, account: c.wallet!.account! } as never);
|
|
26
24
|
}
|
|
27
25
|
|
|
28
|
-
/**
|
|
29
|
-
|
|
30
|
-
|
|
26
|
+
/**
|
|
27
|
+
* The C manager's swap-fee tax (decisions 060): the protocol's share of every swap fee a C position
|
|
28
|
+
* is paid (claims and the burn's auto-claim), WAD. 0 at deployment.
|
|
29
|
+
*/
|
|
30
|
+
export async function cSwapFeeTax(c: LogswapClient): Promise<{ tax: bigint; max: bigint }> {
|
|
31
|
+
const [tax, max] = await Promise.all([
|
|
32
|
+
c.public.readContract({ address: c.addresses.cPoolManager, abi: cPoolManagerAbi, functionName: "swapFeeTax" }),
|
|
33
|
+
c.public.readContract({ address: c.addresses.cPoolManager, abi: cPoolManagerAbi, functionName: "SWAP_FEE_TAX_MAX" }),
|
|
34
|
+
]);
|
|
35
|
+
return { tax, max };
|
|
31
36
|
}
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* `CPoolManager.setSwapFeeTax`: the collector's, at most `SWAP_FEE_TAX_MAX` (25%). Read at payout,
|
|
40
|
+
* so a raise reaches fee income already earned and not yet claimed (decisions 060).
|
|
41
|
+
*/
|
|
42
|
+
export async function setCSwapFeeTax(c: LogswapClient, taxWad: bigint): Promise<Hash> {
|
|
43
|
+
return write(c, c.addresses.cPoolManager, cPoolManagerAbi, "setSwapFeeTax", [taxWad]);
|
|
35
44
|
}
|
|
36
45
|
|
|
37
46
|
// ─── the registry: the LOG authority's, not the collector's ─────────────────
|
|
@@ -173,9 +182,10 @@ export async function registryKindOf(c: LogswapClient, policy: Address): Promise
|
|
|
173
182
|
// ─── the policies' numbers (the collector's; each bounded where it reaches the manager) ─────
|
|
174
183
|
|
|
175
184
|
/**
|
|
176
|
-
* `PadPolicy.setSchedule` (decisions 056): `T(0)`, the rung's growth, the protocol's share of the pot (≤ `POT_CUT_MAX`,
|
|
177
|
-
* recorded into each pad at birth), and the RANGES a creator chooses inside at creation — his cut of the pot and the burn
|
|
178
|
-
*
|
|
185
|
+
* `PadPolicy.setSchedule` (decisions 056, 057): `T(0)`, the rung's growth, the protocol's share of the pot (≤ `POT_CUT_MAX`,
|
|
186
|
+
* recorded into each pad at birth), and the RANGES a creator chooses inside at creation — his cut of the pot and the burn, a
|
|
187
|
+
* fraction of the pot spent buying the token and burning it. The burn's top plus the protocol's share is at most the pot,
|
|
188
|
+
* and each pad's three shares together are. A change applies to pads born after it. The rung is the pool's generation.
|
|
179
189
|
*/
|
|
180
190
|
export async function padSetSchedule(
|
|
181
191
|
c: LogswapClient,
|
|
@@ -225,6 +235,29 @@ export async function policyQuoteAllowed(c: LogswapClient, policy: Address, quot
|
|
|
225
235
|
return { curated, listed, allowed: !curated || listed };
|
|
226
236
|
}
|
|
227
237
|
|
|
238
|
+
/**
|
|
239
|
+
* `setFeeListed` on any protocol policy (decisions 059): a swap-fee tier a pool of that kind may be
|
|
240
|
+
* born with while the policy curates fees. Within the family's domain (`FEE_MIN` ≤ fee ≤ `FEE_MAX`).
|
|
241
|
+
* The collector's.
|
|
242
|
+
*/
|
|
243
|
+
export async function policySetFeeListed(c: LogswapClient, policy: Address, fee: bigint, listed: boolean): Promise<Hash> {
|
|
244
|
+
return write(c, policy, fPolicyBaseAbi, "setFeeListed", [fee, listed]);
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
/** `setFeeCurated` on any protocol policy: on, a birth with an unlisted swap fee is refused (`FeeNotListed`). The collector's. */
|
|
248
|
+
export async function policySetFeeCurated(c: LogswapClient, policy: Address, curated: boolean): Promise<Hash> {
|
|
249
|
+
return write(c, policy, fPolicyBaseAbi, "setFeeCurated", [curated]);
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
/** Whether `fee` passes `policy`'s birth check now: listed, or the policy does not curate fees (the desk's never does). */
|
|
253
|
+
export async function policyFeeAllowed(c: LogswapClient, policy: Address, fee: bigint): Promise<{ curated: boolean; listed: boolean; allowed: boolean }> {
|
|
254
|
+
const [curated, listed] = await Promise.all([
|
|
255
|
+
c.public.readContract({ address: policy, abi: fPolicyBaseAbi, functionName: "feeCurated" } as never) as Promise<boolean>,
|
|
256
|
+
c.public.readContract({ address: policy, abi: fPolicyBaseAbi, functionName: "feeListed", args: [fee] } as never) as Promise<boolean>,
|
|
257
|
+
]);
|
|
258
|
+
return { curated, listed, allowed: !curated || listed };
|
|
259
|
+
}
|
|
260
|
+
|
|
228
261
|
/** `PublicPolicy.setListed`: an asset a curated seed may hold. */
|
|
229
262
|
export async function publicSetListed(c: LogswapClient, policy: Address, token: Address, listed: boolean): Promise<Hash> {
|
|
230
263
|
return write(c, policy, publicPolicyAbi, "setListed", [token, listed]);
|
package/src/client.ts
CHANGED
|
@@ -108,8 +108,13 @@ function guardChain(wallet: WalletClient, pub: PublicClient): WalletClient {
|
|
|
108
108
|
* the variance kernel and its two key fields are gone, so every pool id changed; `phiEff` is
|
|
109
109
|
* `phiOf`; `getPool` lost `sigma2Ema`; `Initialize` lost two fields; the cut is
|
|
110
110
|
* `MINT_FEE_PROTOCOL_CUT` / `setFeeParams`.
|
|
111
|
+
*
|
|
112
|
+
* **6** since 2026-10-09 (logswap-contract#58): the whole mint fee is the protocol's
|
|
113
|
+
* (`MINT_FEE_PROTOCOL_CUT` and `setFeeParams` are gone, decisions 058); the swap-fee tax at payout,
|
|
114
|
+
* `swapFeeTax` / `setSwapFeeTax` (060); `phi` is `swapFee` and `phiOf` `swapFeeOf` (059) — field
|
|
115
|
+
* names only, no pool id moved.
|
|
111
116
|
*/
|
|
112
|
-
export const EXPECTED_VERSION =
|
|
117
|
+
export const EXPECTED_VERSION = 6n;
|
|
113
118
|
/**
|
|
114
119
|
* The F manager's own tag (5 — the key's salt, pool names, the sponsor registry;
|
|
115
120
|
* 4 was the income-only harvest cut).
|
|
@@ -179,7 +184,15 @@ export const EXPECTED_VERSION = 5n;
|
|
|
179
184
|
// next threshold `threshold(gen)`. A pad never retires; a public pool refuses `regenerate`.
|
|
180
185
|
// 23: a harvest asks `may(Harvest)` and takes no terms and no cut (decisions 056): `onHarvest`, `HARVEST_CUT_MAX`,
|
|
181
186
|
// `harvestCut`, `setHarvestCut` are gone; a pad's split (creator's cut, token burn) rides in the key's salt.
|
|
182
|
-
|
|
187
|
+
// 24 (logswap-contract#58): the pot splits in quote — `Terms.burn` is quote spent on a buy-and-burn, the
|
|
188
|
+
// rest deepens the bid, no buy-in, `Regenerated` is (pot, payee, toPayee, cut, burnt, deepened), a pad's
|
|
189
|
+
// salt carries `burnShare` of the pot (057); the mint fee all to the collector (058); `phi` → `swapFee`,
|
|
190
|
+
// `MINT_FEE()` → `mintFee()`, the policies' fee tiers, a canonical public pool (059).
|
|
191
|
+
// 25 (logswap-contract#59): the views moved behind `extsload` (062) — this SDK reads them through the
|
|
192
|
+
// lens (`fPool`, `getFPools`, `fBundleOf`, `fDividendOf`, `fLienOf`); the capped F pool, `FPoolKey.cap`
|
|
193
|
+
// appended so every pool id moved (061); the lien, `lock` / `unlock` (063); θ is `logFloor`, θ₀ `refLogFloor`.
|
|
194
|
+
// A breaking bump: raised in the same change.
|
|
195
|
+
export const EXPECTED_F_VERSION = 25n;
|
|
183
196
|
|
|
184
197
|
export async function assertVersion(c: LogswapClient, expected = EXPECTED_VERSION): Promise<void> {
|
|
185
198
|
const { cPoolManagerAbi, fPoolManagerAbi } = await import("./generated.js");
|
package/src/fees.ts
CHANGED
|
@@ -24,8 +24,8 @@ const YEAR_SECONDS = 31_536_000;
|
|
|
24
24
|
* @deprecated The C `Swap` event carries its `fee` since C version 5 (decisions 050); read that.
|
|
25
25
|
* This reconstruction from φ rounds where the contract does not, and is kept for older logs.
|
|
26
26
|
*/
|
|
27
|
-
export function swapFeeOf(e: { baseIn: boolean; amountIn: bigint; amountOut: bigint },
|
|
28
|
-
return e.baseIn ? (e.amountOut *
|
|
27
|
+
export function swapFeeOf(e: { baseIn: boolean; amountIn: bigint; amountOut: bigint }, swapFee: bigint): bigint {
|
|
28
|
+
return e.baseIn ? (e.amountOut * swapFee) / (WAD - swapFee) : (e.amountIn * swapFee) / (WAD + swapFee);
|
|
29
29
|
}
|
|
30
30
|
|
|
31
31
|
/** Swap fees paid over a window, in the market's quote units. */
|