@logswap/sdk 0.5.87 → 0.5.89

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 CHANGED
@@ -16,7 +16,7 @@ wrong is silent:
16
16
  | `src/keys.ts` | `PoolKey` and `poolId = keccak256(abi.encode(key))` — market identity |
17
17
  | `src/ids.ts` | the ERC-6909 id namespace: position-class ids, token-claim ids, floor/cap packing |
18
18
  | `src/client.ts` | the handle, plus `assertVersion` — refuse a deployment the ABI was not built for |
19
- | `src/pools.ts` | market discovery from `MarketCreated` logs, pool state, `lpEdge` = F − Σ/2 |
19
+ | `src/pools.ts` | market discovery from the C manager's `PoolCreated` logs, pool state, `lpEdge` = `feeGrowth` − Σ/2 |
20
20
  | `src/positions.ts` | classes, balances, claimable fees, the bit-255 position/claim split |
21
21
  | `src/swap.ts` | exact-in/out, multi-hop, and exact quotes via the revert-quoter |
22
22
  | `src/liquidity.ts` | mint, blended mint, zap, update, move, **harvest**, burn |
@@ -44,6 +44,23 @@ Both are computed **offline** — no RPC, no deployment needed to address a mark
44
44
  floor price (was `theta`), `refLogFloor` θ₀ — the reference floor income counts from (was
45
45
  `theta0`), `cap` (d in 1e-6 log units, 0 uncapped), and per leg `virtualReserves` and `kappa`.
46
46
 
47
+ ## C 13 (decisions 088–090): a C market is addressed by its pool id
48
+
49
+ The consumer API still takes a `PoolKey`; the SDK hashes it (`poolId(key)`) and calls the contracts with the id.
50
+ What changes for a consumer:
51
+
52
+ - **Names.** `PoolState.x` is `logPrice`, `PoolState.F` is `feeGrowth` (`lpEdge`, `feesQuote`, `edgeQuote`, `priceOf`,
53
+ `floorDistance` follow). `DiscoveredMarket.x0` and `createMarket` / `initializeMarket`'s `x0` are `initialLogPrice`.
54
+ `FPoolState.weights` is `liquidityWeights` (each base asset's derived fraction of `L`; the sponsor's `weights`
55
+ inputs to `fPoolBook` keep their name).
56
+ - **Events and discovery.** The C manager's `MarketCreated` is `PoolCreated`, in the F manager's field order
57
+ (`poolId, quote, creator, base, swapFee, policy, mintFee, tickSpacing, initialLogPrice, swapFeeTax`). `base` is no
58
+ longer an indexed topic, so `discoverMarkets({ base })` filters it client-side. Both managers emit `PoolCreated`, so an
59
+ indexer table is prefixed by its contract (`allCPoolManagerPoolCreateds`, `allFPoolManagerPoolCreateds`).
60
+ - **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()`.
62
+ - **Layout.** F `getPool` has `swapFee` / `mintFee` as `uint56`; the `extsload` words are in the contracts' `FPoolState`.
63
+
47
64
  ## Who may create what: the gate, the menus (C version 7, F version 26)
48
65
 
49
66
  Since logswap-contract #60 (decisions 064–065) creation is curated at launch, on both managers:
package/dist/actions.d.ts CHANGED
@@ -19,7 +19,7 @@
19
19
  */
20
20
  import { type Address, type Hash, type Hex } from "viem";
21
21
  import type { LogswapClient } from "./client.js";
22
- import type { PoolKey } from "./keys.js";
22
+ import { type PoolKey } from "./keys.js";
23
23
  import type { Hop } from "./swap.js";
24
24
  import { type WriteOptions } from "./write.js";
25
25
  /** "The router's open delta of that token" — the swap-amount sentinel. `type(uint256).max`. */
package/dist/actions.js CHANGED
@@ -19,6 +19,7 @@
19
19
  */
20
20
  import { encodeAbiParameters } from "viem";
21
21
  import { logswapRouterAbi } from "./generated.js";
22
+ import { poolId as keyId } from "./keys.js";
22
23
  import { NO_CAP } from "./ids.js";
23
24
  import { resolveDeadline, resolveRecipient, sendRouterWriteWithPermits, simulateRouterWrite } from "./write.js";
24
25
  /** "The router's open delta of that token" — the swap-amount sentinel. `type(uint256).max`. */
@@ -46,35 +47,35 @@ function payloadType(encoder) {
46
47
  const enc = (encoder, value) => encodeAbiParameters(payloadType(encoder), [value]);
47
48
  /** Mint exposure `L` at `targetFloor` (off-grid blends the two adjacent rungs), `cap` optional. */
48
49
  export function mintAction(a) {
49
- return { op: Op.MintBlended, data: enc("encodeMint", { key: a.key, targetFloor: a.targetFloor, cap: a.cap ?? NO_CAP, L: a.L }) };
50
+ return { op: Op.MintBlended, data: enc("encodeMint", { poolId: keyId(a.key), targetFloor: a.targetFloor, cap: a.cap ?? NO_CAP, L: a.L }) };
50
51
  }
51
52
  /** Burn `shares[i]` of `ids[i]`; accrued fees are swept into the same batch. Needs the operator grant. */
52
53
  export function burnAction(a) {
53
54
  if (a.ids.length !== a.shares.length)
54
55
  throw new Error("logswap: ids and shares length mismatch");
55
- return { op: Op.Burn, data: enc("encodeBurn", { key: a.key, ids: a.ids, shares: a.shares }) };
56
+ return { op: Op.Burn, data: enc("encodeBurn", { poolId: keyId(a.key), ids: a.ids, shares: a.shares }) };
56
57
  }
57
58
  /** Exact-in swap. `amountIn` may be `OPEN_DELTA`: the input an earlier action left the router holding. */
58
59
  export function swapExactInAction(a) {
59
- return { op: Op.SwapExactIn, data: enc("encodeSwap", { key: a.key, baseSide: a.baseIn, amount: a.amountIn, limit: a.minOut ?? 0n }) };
60
+ return { op: Op.SwapExactIn, data: enc("encodeSwap", { poolId: keyId(a.key), baseSide: a.baseIn, amount: a.amountIn, limit: a.minOut ?? 0n }) };
60
61
  }
61
62
  /** Exact-out swap. `amountOut` may be `OPEN_DELTA`: the output an earlier action left the router owing. */
62
63
  export function swapExactOutAction(a) {
63
64
  return {
64
65
  op: Op.SwapExactOut,
65
- data: enc("encodeSwap", { key: a.key, baseSide: a.baseOut, amount: a.amountOut, limit: a.maxIn ?? UNBOUNDED }),
66
+ data: enc("encodeSwap", { poolId: keyId(a.key), baseSide: a.baseOut, amount: a.amountOut, limit: a.maxIn ?? UNBOUNDED }),
66
67
  };
67
68
  }
68
69
  /** Collect the caller's fees on `ids`; positions untouched. */
69
70
  export function claimAction(a) {
70
- return { op: Op.Claim, data: enc("encodeClaim", { key: a.key, ids: a.ids }) };
71
+ return { op: Op.Claim, data: enc("encodeClaim", { poolId: keyId(a.key), ids: a.ids }) };
71
72
  }
72
73
  /** The general edit — set `shares` of `fromId` to (`toFloor`, `toCap`, `newL`); `newL = 0` exits. */
73
74
  export function updateAction(a) {
74
75
  return {
75
76
  op: Op.Update,
76
77
  data: enc("encodeUpdate", {
77
- key: a.key,
78
+ poolId: keyId(a.key),
78
79
  fromId: a.fromId,
79
80
  shares: a.shares,
80
81
  toFloor: a.toFloor,
@@ -87,7 +88,7 @@ export function updateAction(a) {
87
88
  export function pathAction(a) {
88
89
  if (a.hops.length === 0)
89
90
  throw new Error("logswap: empty path");
90
- return { op: Op.Path, data: enc("encodePath", { hops: a.hops, amountIn: a.amountIn, minOut: a.minOut ?? 0n }) };
91
+ return { op: Op.Path, data: enc("encodePath", { hops: a.hops.map((h) => ({ poolId: keyId(h.key), baseIn: h.baseIn })), amountIn: a.amountIn, minOut: a.minOut ?? 0n }) };
91
92
  }
92
93
  /* settlement builders ======================================================= */
93
94
  /** A settlement over explicit tokens; missing bounds default to unbounded in, zero out. */
package/dist/claims.d.ts CHANGED
@@ -7,7 +7,7 @@
7
7
  */
8
8
  import type { Address, Hash } from "viem";
9
9
  import type { LogswapClient } from "./client.js";
10
- import type { PoolKey } from "./keys.js";
10
+ import { type PoolKey } from "./keys.js";
11
11
  import { type WriteOptions } from "./write.js";
12
12
  export interface ClaimFeesArgs extends WriteOptions {
13
13
  key: PoolKey;
package/dist/claims.js CHANGED
@@ -6,6 +6,7 @@
6
6
  * - a TOKEN claim — a bearer IOU (bit-255-clear id) for inventory parked inside the manager
7
7
  */
8
8
  import { cPoolManagerAbi, logswapRouterAbi } from "./generated.js";
9
+ import { poolId as keyId } from "./keys.js";
9
10
  import { isPosition } from "./ids.js";
10
11
  import { requireWallet, resolveDeadline, resolveRecipient, sendRouterWrite } from "./write.js";
11
12
  /**
@@ -26,7 +27,7 @@ export async function claimFees(c, a) {
26
27
  return sendRouterWrite(c, {
27
28
  abi: logswapRouterAbi,
28
29
  functionName: "claim",
29
- args: [a.key, a.ids, resolveRecipient(c, a), resolveDeadline(a)],
30
+ args: [keyId(a.key), a.key.quote, a.ids, resolveRecipient(c, a), resolveDeadline(a)],
30
31
  });
31
32
  }
32
33
  /**
package/dist/client.d.ts CHANGED
@@ -119,7 +119,7 @@ export declare function clientChainId(c: LogswapClient): Promise<number>;
119
119
  * takes `SwapParams` (the router's ABI does not move), object-word event names (`MarketCreated`,
120
120
  * `PositionMinted`, ...), `MarketCreated` carries creator, mintFee and swapFeeTax. No pool id moved.
121
121
  */
122
- export declare const EXPECTED_VERSION = 12n;
122
+ export declare const EXPECTED_VERSION = 13n;
123
123
  /**
124
124
  * The F manager's own tag (5 — the key's salt, pool names, the sponsor registry;
125
125
  * 4 was the income-only harvest cut).
@@ -131,7 +131,7 @@ export declare const EXPECTED_VERSION = 12n;
131
131
  * passes it; when one lands, raise this constant in the same change, which is the discipline
132
132
  * `EXPECTED_VERSION` enforces mechanically and this one asks for.
133
133
  */
134
- export declare const EXPECTED_F_VERSION = 38n;
134
+ export declare const EXPECTED_F_VERSION = 39n;
135
135
  export declare function assertVersion(c: LogswapClient, expected?: bigint): Promise<void>;
136
136
  /**
137
137
  * The versions say the managers are the right code; this says the rest of the addresses belong
package/dist/client.js CHANGED
@@ -117,7 +117,11 @@ function guardChain(wallet, pub) {
117
117
  // takes no separate mint fee, `createMarket` neither; `getPool` drops `mintFee` and the gates' mint-fee menus are gone.
118
118
  // Every C pool id moved.
119
119
  // 12 (decisions 079-081): `Action` ordinals, the key is `CPoolKey` (names only). No pool id moved.
120
- export const EXPECTED_VERSION = 12n;
120
+ // 13 (decisions 088-090): a C pool is addressed by its `bytes32 poolId` after `initialize` (the key rides in calldata at `initialize`
121
+ // only; no pool id moved), the router's named entries take the tokens the caller expects (`WrongToken`), `claimById` / `burnById` /
122
+ // `claimManyFor` are `claim` / `burn` / `claimMany`, `mint(poolId, to, floor, cap, L)`, `MarketCreated` is `PoolCreated` (in F's field
123
+ // order), `x0` is `initialLogPrice`, `PoolView.x` / `.F` are `logPrice` / `feeGrowth`, `swapFee` / `mintFee` are `uint56`.
124
+ export const EXPECTED_VERSION = 13n;
121
125
  /**
122
126
  * The F manager's own tag (5 — the key's salt, pool names, the sponsor registry;
123
127
  * 4 was the income-only harvest cut).
@@ -216,10 +220,11 @@ export const EXPECTED_VERSION = 12n;
216
220
  // id moved); `initialize(key)`; `seed` / `retire` / `setLegs` are gone for `deployLiquidity(poolId, baseAssets,
217
221
  // quoteAmount, lnCapOverSeed, to)` (it SETS THE BOOK on an unfunded or a live pool), `close(poolId, to)` and
218
222
  // `regenerate(poolId, to)`; asset membership is fixed by the key; `LiquidityDeployed` echoes the input,
219
- // `GenerationSeeded` / `LegsSet` are gone; the lens `fPool` field is `baseLegs`, the cap `lnCapOverSeed`; the pot and the
223
+ // `GenerationSeeded` / `LegsSet` are gone; the lens `fPool` field is `baseAssets` (`baseLegs` before decision 090), the cap `lnCapOverSeed`; the pot and the
220
224
  // income fee are the income and the income tax (`IncomeReleased`, `incomeHeld`, `incomeTax`); a pad is uncapped.
225
+ // 39 (decision 087): `swapFeeB4B` is gone; base-for-base pays `swapFee` once, not 2·swapFee.
221
226
  // A breaking bump: raised in the same change.
222
- export const EXPECTED_F_VERSION = 38n;
227
+ export const EXPECTED_F_VERSION = 39n;
223
228
  export async function assertVersion(c, expected = EXPECTED_VERSION) {
224
229
  const { cPoolManagerAbi, fPoolManagerAbi } = await import("./generated.js");
225
230
  // three independent reads: one round trip, not three in a row
package/dist/fpool.d.ts CHANGED
@@ -827,8 +827,8 @@ export interface FPoolState {
827
827
  poolId: Hex;
828
828
  quote: Address;
829
829
  bases: Address[];
830
- /** WAD weights, summing to WAD. `L_j = w_j · L`. */
831
- weights: bigint[];
830
+ /** Each base asset's fraction of the pool's `L`, WAD, summing to WAD, derived at each deployment (`weights` before decision 090). `L_j = liquidityWeight_j · L`. */
831
+ liquidityWeights: bigint[];
832
832
  /** Per-asset log prices, WAD. Price is derived; `x` is the state. */
833
833
  x: bigint[];
834
834
  /** Quote reserve. The one leg a base→quote swap can exhaust. */
@@ -1285,7 +1285,7 @@ export interface FPoolCreateArgs {
1285
1285
  quote: Address;
1286
1286
  /** The pool's assets, in any order; sorted into the key's canonical order before the call. The set is fixed for the pool's life. */
1287
1287
  bases: Address[];
1288
- /** The swap fee, WAD. The base-for-base fee is pinned at 2φ on-chain. A curated policy admits only its listed tiers (decisions 059). */
1288
+ /** The swap fee, WAD. Base-for-base pays it once, like any swap (F 39). A curated policy admits only its listed tiers (decisions 059). */
1289
1289
  swapFee: bigint;
1290
1290
  /**
1291
1291
  * The pool's mint fee, WAD of newly-minted L — the creator's pick, a key field fixed for life (F 38, decision
package/dist/fpool.js CHANGED
@@ -91,9 +91,9 @@ export async function getFPool(c, poolId) {
91
91
  return {
92
92
  poolId,
93
93
  quote: p.quote,
94
- bases: v.baseLegs.map((l) => l.base),
95
- weights: v.baseLegs.map((l) => l.weight),
96
- x: v.baseLegs.map((l) => l.x), // derived by the manager: x_j = ln(w_j·L / R̃_j)
94
+ bases: v.baseAssets.map((l) => l.base),
95
+ liquidityWeights: v.baseAssets.map((l) => l.liquidityWeight),
96
+ x: v.baseAssets.map((l) => l.x), // derived by the manager: x_j = ln(w_j·L / R̃_j)
97
97
  Q: p.Q,
98
98
  L: p.L,
99
99
  swapFee: p.swapFee,
@@ -112,9 +112,9 @@ export async function getFPool(c, poolId) {
112
112
  seeded: p.seeded,
113
113
  gen: Number(p.gen),
114
114
  totalSupply: p.shares,
115
- reserves: v.baseLegs.map((l) => l.reserve), // the state
116
- virtualReserves: v.baseLegs.map((l) => l.virtualReserve),
117
- kappa: v.baseLegs.map((l) => l.kappa),
115
+ reserves: v.baseAssets.map((l) => l.reserve), // the state
116
+ virtualReserves: v.baseAssets.map((l) => l.virtualReserve),
117
+ kappa: v.baseAssets.map((l) => l.kappa),
118
118
  };
119
119
  }
120
120
  const F_KIND_NAMES = ["public", "private", "pol", "pad"];
@@ -211,7 +211,7 @@ export function fPoolShareValue(s) {
211
211
  for (let j = 0; j < s.reserves.length; j++) {
212
212
  const rv = s.virtualReserves[j];
213
213
  if (rv !== 0n)
214
- v += (((s.weights[j] * s.L) / WAD) * s.reserves[j]) / rv;
214
+ v += (((s.liquidityWeights[j] * s.L) / WAD) * s.reserves[j]) / rv;
215
215
  }
216
216
  }
217
217
  return (v * WAD) / s.totalSupply;