@logswap/sdk 0.5.44 → 0.5.46

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/src/index.ts CHANGED
@@ -19,5 +19,5 @@ export * from "./onboard.js";
19
19
  export * from "./indexer.js";
20
20
  export * from "./tokencache.js";
21
21
  export * from "./fpool.js";
22
- export { cPoolManagerAbi, fPoolManagerAbi, logswapLensAbi, logswapRouterAbi } from "./generated.js";
22
+ export { cPoolManagerAbi, fPoolManagerAbi, logswapLensAbi, logswapRouterAbi, padHookAbi, polHookAbi, privateHookAbi, publicHookAbi } from "./generated.js";
23
23
  export * from "./admin.js";
package/src/indexer.ts CHANGED
@@ -143,11 +143,11 @@ export async function indexerHealthy(url: string, signal?: AbortSignal): Promise
143
143
  */
144
144
  export async function discoverMarketsIndexed(url: string, signal?: AbortSignal): Promise<DiscoveredMarket[]> {
145
145
  const q = `{ allInitializes(first: 1000) { nodes {
146
- poolId base quote tickSpacing phiMin kappa alpha x0 blockNumber txHash
146
+ poolId base quote tickSpacing phi x0 blockNumber txHash
147
147
  } } }`;
148
148
  type Row = {
149
- poolId: Hex; base: Hex; quote: Hex; tickSpacing: string; phiMin: string;
150
- kappa: string; alpha: string; x0: string; blockNumber: string; txHash: Hex;
149
+ poolId: Hex; base: Hex; quote: Hex; tickSpacing: string; phi: string;
150
+ x0: string; blockNumber: string; txHash: Hex;
151
151
  };
152
152
  const d = await gql<{ allInitializes: { nodes: Row[] } }>(url, q, undefined, signal);
153
153
  return d.allInitializes.nodes.map((n) => {
@@ -155,9 +155,7 @@ export async function discoverMarketsIndexed(url: string, signal?: AbortSignal):
155
155
  base: n.base as Address,
156
156
  quote: n.quote as Address,
157
157
  tickSpacing: BigInt(n.tickSpacing),
158
- phiMin: BigInt(n.phiMin),
159
- kappa: BigInt(n.kappa),
160
- alpha: BigInt(n.alpha),
158
+ phi: BigInt(n.phi),
161
159
  };
162
160
  return {
163
161
  key,
@@ -196,7 +194,7 @@ export async function discoverMarketsBest(
196
194
  await c.public.readContract({
197
195
  address: c.addresses.cPoolManager,
198
196
  abi: cPoolManagerAbi,
199
- functionName: "phiEff",
197
+ functionName: "phiOf",
200
198
  args: [m.key],
201
199
  } as never);
202
200
  return m;
package/src/keys.ts CHANGED
@@ -22,12 +22,13 @@ export interface PoolKey {
22
22
  quote: Address;
23
23
  /** Log-tick spacing, WAD. The LP-boundary ladder — position floors and caps. */
24
24
  tickSpacing: bigint;
25
- /** Fee floor, WAD. `0n` selects `DEFAULT_FEE_MIN` (2 bp) at read time. */
26
- phiMin: bigint;
27
- /** Variance-fee coefficient, WAD. `0n` disables the dynamic fee. */
28
- kappa: bigint;
29
- /** EMA decay, WAD. `0n` selects `DEFAULT_ALPHA` (1/2) at read time. */
30
- alpha: bigint;
25
+ /**
26
+ * The swap fee, WAD, fixed for the life of the market: `FEE_MIN` (1 bp) ≤ φ ≤ `FEE_MAX` (25%),
27
+ * or `0n`, which selects `DEFAULT_FEE` (2 bp) at read time. Four fields since C version 4
28
+ * (decisions 042): `kappa` and `alpha` left with the variance kernel, and `phiMin` — a floor with
29
+ * nothing above it — became `phi`. Every pool id changed with the shape.
30
+ */
31
+ phi: bigint;
31
32
  }
32
33
 
33
34
  const POOL_KEY_ABI = [
@@ -37,9 +38,7 @@ const POOL_KEY_ABI = [
37
38
  { name: "base", type: "address" },
38
39
  { name: "quote", type: "address" },
39
40
  { name: "tickSpacing", type: "int256" },
40
- { name: "phiMin", type: "uint256" },
41
- { name: "kappa", type: "uint256" },
42
- { name: "alpha", type: "uint256" },
41
+ { name: "phi", type: "uint256" },
43
42
  ],
44
43
  },
45
44
  ] as const;
@@ -47,8 +46,8 @@ const POOL_KEY_ABI = [
47
46
  /**
48
47
  * `poolId = keccak256(abi.encode(key))` — the primary key of the entire read model.
49
48
  *
50
- * Note the zero-vs-default caveat the Solidity type documents: `phiMin` and `alpha` of `0` resolve
51
- * to their defaults at READ time, so a key carrying `0n` and one carrying the resolved default are
49
+ * Note the zero-vs-default caveat the Solidity type documents: a `phi` of `0` resolves to
50
+ * `DEFAULT_FEE` at READ time, so a key carrying `0n` and one carrying the resolved default are
52
51
  * DIFFERENT markets with different ids, even though they behave identically. Always address a
53
52
  * market by the key it was initialized with.
54
53
  */
@@ -59,9 +58,7 @@ export function poolId(key: PoolKey): Hex {
59
58
  base: key.base,
60
59
  quote: key.quote,
61
60
  tickSpacing: key.tickSpacing,
62
- phiMin: key.phiMin,
63
- kappa: key.kappa,
64
- alpha: key.alpha,
61
+ phi: key.phi,
65
62
  },
66
63
  ]),
67
64
  );
package/src/liquidity.ts CHANGED
@@ -133,6 +133,8 @@ export interface ZapArgs extends WriteOptions {
133
133
  /** Fund entirely from base (true) or entirely from quote (false). */
134
134
  fundWithBase: boolean;
135
135
  amountIn: bigint;
136
+ /** The least the swap leg may return (contracts 7c82eed, decisions 043): the zap's own slippage bound, as `swapExactIn`'s. 0 = unbounded. */
137
+ minSwapOut?: bigint;
136
138
  targetFloor: bigint;
137
139
  cap?: bigint;
138
140
  L: bigint;
@@ -155,6 +157,7 @@ export async function zapIn(c: LogswapClient, a: ZapArgs): Promise<Hash> {
155
157
  a.key,
156
158
  a.fundWithBase,
157
159
  a.amountIn,
160
+ a.minSwapOut ?? 0n,
158
161
  a.targetFloor,
159
162
  a.cap ?? NO_CAP,
160
163
  a.L,
package/src/pools.ts CHANGED
@@ -30,9 +30,8 @@ export interface PoolState {
30
30
  reserveQuote: bigint;
31
31
  /** Fee-per-unit-L accumulator: $\phi \cdot \mathrm{TV}(\log p)$. */
32
32
  F: bigint;
33
- /** Quadratic variation of log-price, $\Sigma = \int (dx)^2$. */
33
+ /** Quadratic variation of log-price, $\Sigma = \sum_{\text{swaps}} (\Delta x_{\text{swap}})^2$ — one term per swap (decisions 042). */
34
34
  bigSigma: bigint;
35
- sigma2Ema: bigint;
36
35
  currentK: bigint;
37
36
  protocolOwed: bigint;
38
37
  minBackstopL: bigint;
@@ -50,12 +49,16 @@ export async function getPool(c: LogswapClient, key: PoolKey): Promise<PoolState
50
49
  return v as unknown as PoolState;
51
50
  }
52
51
 
53
- /** The effective fee right now: $\max(\phi_{\min}, \kappa\sqrt{\sigma^2_{\text{ema}}})$, capped. */
54
- export async function phiEff(c: LogswapClient, key: PoolKey): Promise<bigint> {
52
+ /**
53
+ * The market's fee: the key's `phi` with `0n` resolved to `DEFAULT_FEE`. Constant for the market's
54
+ * life (C version 4, decisions 042 — `phiEff` and the variance kernel before). Reverts for a key
55
+ * nobody initialized, which `discoverMarkets` relies on to drop a stale indexer's rows.
56
+ */
57
+ export async function phiOf(c: LogswapClient, key: PoolKey): Promise<bigint> {
55
58
  return c.public.readContract({
56
59
  address: c.addresses.cPoolManager,
57
60
  abi: cPoolManagerAbi,
58
- functionName: "phiEff",
61
+ functionName: "phiOf",
59
62
  args: [key],
60
63
  }) as Promise<bigint>;
61
64
  }
@@ -134,9 +137,7 @@ export async function discoverMarkets(
134
137
  base: a.base!,
135
138
  quote: a.quote!,
136
139
  tickSpacing: a.tickSpacing!,
137
- phiMin: a.phiMin!,
138
- kappa: a.kappa!,
139
- alpha: a.alpha!,
140
+ phi: a.phi!,
140
141
  };
141
142
  return {
142
143
  key,