@logswap/sdk 0.5.77 → 0.5.79

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/history.ts CHANGED
@@ -90,7 +90,7 @@ function contractName(c: LogswapClient, address: Address, event: string): string
90
90
  const a = address.toLowerCase();
91
91
  const is = (x?: Address) => x !== undefined && a === x.toLowerCase();
92
92
  const { addresses: d } = c;
93
- if (is(d.cPoolManager)) return "LogswapManager";
93
+ if (is(d.cPoolManager)) return "CPoolManager";
94
94
  if (is(d.fPoolManager)) return "FPoolManager";
95
95
  if (is(d.router)) return "LogswapRouter";
96
96
  if (is(d.policyRegistry)) return "PolicyRegistry";
@@ -113,7 +113,7 @@ export function indexedContractOf(kind: FPoolKind, event: string): string {
113
113
 
114
114
  /** Events whose name two indexed contracts share: postgraphile prefixes their tables. */
115
115
  // `CollectorProposed` / `CollectorAccepted` are C 7 / F 26 and older; `TreasuryProposed` / `TreasuryAccepted` replace them (066).
116
- const SHARED = new Set(["Transfer", "Approval", "OperatorSet", "CollectorProposed", "CollectorAccepted", "TreasuryProposed", "TreasuryAccepted", "Approved", "Listed"]);
116
+ const SHARED = new Set(["Swap", "Transfer", "Approval", "OperatorSet", "CollectorProposed", "CollectorAccepted", "TreasuryProposed", "TreasuryAccepted", "Approved", "Listed"]);
117
117
 
118
118
  const plural = (n: string) => (/(s|x|ch|sh)$/.test(n) ? `${n}es` : `${n}s`);
119
119
  /** A column's GraphQL name: postgraphile camelCases the snake_case rindexer writes (`F` → `f`). */
package/src/indexer.ts CHANGED
@@ -3,7 +3,7 @@
3
3
  *
4
4
  * The division of labour matters and is not arbitrary: **the indexer enumerates, the chain
5
5
  * values.** ERC-6909 has no enumeration, so there is no way to ask a node "which positions exist in
6
- * this pool" — only the `IdRegistered` log knows. But an indexed row is a historical fact, and `L`
6
+ * this pool" — only the `ClassRegistered` log knows. But an indexed row is a historical fact, and `L`
7
7
  * changes with every mint, burn and harvest afterwards. So ids come from here and the current `L`
8
8
  * is read on-chain, rather than trusting a number that was true at index time.
9
9
  */
@@ -108,7 +108,7 @@ export interface RegisteredId {
108
108
 
109
109
  /** Every position class ever registered in a pool. Historical — some may since have burnt to zero. */
110
110
  export async function registeredIds(url: string, poolId: Hex, signal?: AbortSignal): Promise<RegisteredId[]> {
111
- const nodes = await gqlAll<{ id: string; floor: string; cap: string; capped: boolean }>(url, "allIdRegistereds", "id floor cap capped", {
111
+ const nodes = await gqlAll<{ id: string; floor: string; cap: string; capped: boolean }>(url, "allClassRegistereds", "id floor cap capped", {
112
112
  vars: { pool: { type: "String!", value: bytea(poolId) } },
113
113
  condition: "{poolId: $pool}",
114
114
  signal,
@@ -168,7 +168,7 @@ export async function indexerHealthy(url: string, signal?: AbortSignal): Promise
168
168
  /**
169
169
  * Markets, from the indexer rather than a log scan.
170
170
  *
171
- * `discoverMarkets` reads `Initialize` logs straight from the node, which is correct until the node
171
+ * `discoverMarkets` reads `MarketCreated` logs straight from the node, which is correct until the node
172
172
  * stops keeping them. anvil's `--prune-history` drops historical transactions and receipts beyond a
173
173
  * window, so on a devnet that mines steadily the deployment's own logs age out and a scan from
174
174
  * block 0 returns nothing — while the contracts remain perfectly alive. Any real chain has the same
@@ -178,7 +178,7 @@ export async function indexerHealthy(url: string, signal?: AbortSignal): Promise
178
178
  * the more durable path and should be preferred wherever an indexer is configured, with the log
179
179
  * scan as the fallback for when it is not.
180
180
  *
181
- * `Initialize` carries every field of the `PoolKey`, so the key is rebuilt exactly and `poolId` is
181
+ * `MarketCreated` carries every field of the `PoolKey`, so the key is rebuilt exactly and `poolId` is
182
182
  * recomputed locally rather than trusted from the row — the same offline derivation the SDK uses
183
183
  * everywhere else, so a wrong id fails loudly instead of addressing the wrong pool.
184
184
  */
@@ -187,7 +187,7 @@ export async function discoverMarketsIndexed(url: string, signal?: AbortSignal):
187
187
  poolId: Hex; base: Hex; quote: Hex; tickSpacing: string; swapFee: string;
188
188
  x0: string; blockNumber: string; txHash: Hex; contractAddress: Hex;
189
189
  };
190
- const nodes = await gqlAll<Row>(url, "allInitializes", "poolId base quote tickSpacing swapFee x0 blockNumber txHash contractAddress", { signal });
190
+ const nodes = await gqlAll<Row>(url, "allMarketCreateds", "poolId base quote tickSpacing swapFee x0 blockNumber txHash contractAddress", { signal });
191
191
  return nodes.map((n) => {
192
192
  const key: PoolKey = {
193
193
  base: n.base as Address,
@@ -238,7 +238,7 @@ export async function discoverMarketsBest(
238
238
  /**
239
239
  * The UNCAPPED position classes of a pool, from the CHAIN alone: the lens enumerates live floors
240
240
  * (one bitmap bit each), and an uncapped id is a pure function of (key, floor). No indexer.
241
- * Capped classes need `IdRegistered` replay and are absent here — callers that also want those
241
+ * Capped classes need `ClassRegistered` replay and are absent here — callers that also want those
242
242
  * use the indexed `poolPositions` and fall back to this when the indexer is missing or stale.
243
243
  */
244
244
  export async function poolPositionsFromChain(c: LogswapClient, key: PoolKey, x: bigint): Promise<PoolPosition[]> {
package/src/pools.ts CHANGED
@@ -3,7 +3,7 @@
3
3
  *
4
4
  * Two things worth knowing before reading further.
5
5
  *
6
- * **Markets are discovered from logs, not configuration.** `Initialize` carries the ENTIRE
6
+ * **Markets are discovered from logs, not configuration.** `MarketCreated` carries the ENTIRE
7
7
  * `PoolKey` in the clear, so a client can reconstruct any market's key — and therefore call any
8
8
  * keyed function — having never been told the market exists. There is no registry to maintain.
9
9
  *
@@ -144,7 +144,7 @@ export function lpEdge(state: Pick<PoolState, "F" | "bigSigma">): bigint {
144
144
  return state.F - state.bigSigma / 2n;
145
145
  }
146
146
 
147
- /** A market discovered from an `Initialize` log — the full key, plus where it was created. */
147
+ /** A market discovered from a `MarketCreated` log — the full key, plus where it was created. */
148
148
  export interface DiscoveredMarket {
149
149
  key: PoolKey;
150
150
  poolId: Hex;
@@ -152,12 +152,12 @@ export interface DiscoveredMarket {
152
152
  x0: bigint;
153
153
  blockNumber: bigint;
154
154
  transactionHash: Hex;
155
- /** The manager that emitted the `Initialize` — set when the row came from the indexer. */
155
+ /** The manager that emitted the `MarketCreated` — set when the row came from the indexer. */
156
156
  manager?: Address;
157
157
  }
158
158
 
159
159
  /**
160
- * Enumerate markets from `Initialize` logs.
160
+ * Enumerate markets from `MarketCreated` logs.
161
161
  *
162
162
  * This is the whole market registry: the event carries every key field rather than just the id,
163
163
  * deliberately, so nothing downstream needs a configured list. The scan starts at the client's
@@ -165,13 +165,13 @@ export interface DiscoveredMarket {
165
165
  */
166
166
  export async function discoverMarkets(
167
167
  c: LogswapClient,
168
- opts: { fromBlock?: bigint; toBlock?: bigint; base?: Address; quote?: Address; /** The rindexer GraphQL endpoint: `Initialize` from there, the node otherwise. */ indexer?: string } = {},
168
+ opts: { fromBlock?: bigint; toBlock?: bigint; base?: Address; quote?: Address; /** The rindexer GraphQL endpoint: `MarketCreated` from there, the node otherwise. */ indexer?: string } = {},
169
169
  ): Promise<DiscoveredMarket[]> {
170
- // Narrow the const ABI to the Initialize entry while KEEPING its literal type, so viem can infer
170
+ // Narrow the const ABI to the MarketCreated entry while KEEPING its literal type, so viem can infer
171
171
  // the log shape. `as never` would compile but collapse every arg to `never` at the call site.
172
- type Ev = Extract<(typeof cPoolManagerAbi)[number], { type: "event"; name: "Initialize" }>;
173
- const ev = cPoolManagerAbi.find((x): x is Ev => x.type === "event" && x.name === "Initialize");
174
- if (!ev) throw new Error("logswap: Initialize event missing from the generated ABI");
172
+ type Ev = Extract<(typeof cPoolManagerAbi)[number], { type: "event"; name: "MarketCreated" }>;
173
+ const ev = cPoolManagerAbi.find((x): x is Ev => x.type === "event" && x.name === "MarketCreated");
174
+ if (!ev) throw new Error("logswap: MarketCreated event missing from the generated ABI");
175
175
 
176
176
  const args: Record<string, unknown> = {};
177
177
  if (opts.base) args.base = opts.base;
package/src/positions.ts CHANGED
@@ -121,7 +121,7 @@ export async function getHolderPosition(
121
121
  * Resolve an id the manager already knows back to its (pool, floor, cap).
122
122
  *
123
123
  * The inverse direction — id to class — needs the registry, because the id is a HASH: it cannot be
124
- * unpacked offline the way `positionId` can be computed offline. `IdRegistered` carries the same
124
+ * unpacked offline the way `positionId` can be computed offline. `ClassRegistered` carries the same
125
125
  * information in the clear, so an indexer never needs this call.
126
126
  *
127
127
  * **Units.** The lens is inconsistent here and this wrapper hides it: `unpack` returns tick
@@ -170,7 +170,7 @@ export function partitionIds(ids: readonly bigint[]): { positions: bigint[]; cla
170
170
  return { positions, claims };
171
171
  }
172
172
 
173
- /** Decode a class's floor and cap from its packed field (as carried by `IdRegistered`). */
173
+ /** Decode a class's floor and cap from its packed field (as carried by `ClassRegistered`). */
174
174
  export function describePacked(tickSpacing: bigint, packed: bigint) {
175
175
  return unpackFloorCap(tickSpacing, packed);
176
176
  }
@@ -237,7 +237,7 @@ export function mintFee(
237
237
  * Every UNCAPPED position `owner` holds in a market, enumerated fully on-chain by the lens — a
238
238
  * bitmap walk plus a balance check per live floor. No indexer, no log scan. Capped classes are
239
239
  * not listed here by contract (their candidate set is quadratic in live ticks); they come from
240
- * `IdRegistered` replay when an indexer exists.
240
+ * `ClassRegistered` replay when an indexer exists.
241
241
  */
242
242
  export interface HeldPositionRow {
243
243
  id: bigint;
@@ -262,7 +262,7 @@ export async function positionsOf(c: LogswapClient, key: PoolKey, owner: Address
262
262
  return rows.map((r) => ({ id: r.id, floor: r.floor, cap: NO_CAP, capped: false, shares: r.shares, L: r.L, fees: r.fees }));
263
263
  }
264
264
 
265
- const ID_REGISTERED = parseAbiItem("event IdRegistered(uint256 indexed id, bytes32 indexed poolId, int256 floor, int256 cap, bool capped)");
265
+ const ID_REGISTERED = parseAbiItem("event ClassRegistered(uint256 indexed id, bytes32 indexed poolId, int256 floor, int256 cap, bool capped)");
266
266
 
267
267
  /** The class ids `owner` holds in `pool`, from the indexer's `pool_holder` view; null when the indexer cannot answer. */
268
268
  async function heldIdsFromView(c: LogswapClient, indexer: string, pool: Hex, owner: Address): Promise<bigint[] | null> {
@@ -270,11 +270,11 @@ async function heldIdsFromView(c: LogswapClient, indexer: string, pool: Hex, own
270
270
  const rows = await poolHolders(indexer, { condition: { side: "C", poolId: pool.toLowerCase(), holder: owner.toLowerCase(), manager: c.addresses.cPoolManager.toLowerCase() } });
271
271
  return rows.filter((r) => r.balance > 0n && !r.isBackstop).map((r) => r.id);
272
272
  } catch {
273
- return null; // the view is a cache: the IdRegistered replay below answers the same
273
+ return null; // the view is a cache: the ClassRegistered replay below answers the same
274
274
  }
275
275
  }
276
276
 
277
- /** Every class id ever registered in `pool` (`IdRegistered`), from the indexer's table or the node. */
277
+ /** Every class id ever registered in `pool` (`ClassRegistered`), from the indexer's table or the node. */
278
278
  async function registeredIds(c: LogswapClient, pool: Hex, fromBlock?: bigint, indexer?: string): Promise<bigint[]> {
279
279
  const { logs } = await getEventLogs<{ id?: bigint }>(c, { indexer, address: c.addresses.cPoolManager, event: ID_REGISTERED, args: { poolId: pool }, fromBlock });
280
280
  return logs.map((l) => l.args.id ?? 0n).filter((id) => id !== 0n);
@@ -285,7 +285,7 @@ async function registeredIds(c: LogswapClient, pool: Hex, fromBlock?: bigint, in
285
285
  *
286
286
  * `positionsOf` (the lens) enumerates the uncapped book from the ladder bitmap in one call and
287
287
  * cannot list capped classes: a capped id is a (floor, cap) pair, quadratic in live ticks. This
288
- * replays `IdRegistered` — every class is registered once, on first mint, with its floor and
288
+ * replays `ClassRegistered` — every class is registered once, on first mint, with its floor and
289
289
  * cap — then checks the owner's ERC-6909 balance on each and reads the class for its L, so the
290
290
  * holder's slice is L · shares_owner / shares_class, and fees from the lens. One log query plus
291
291
  * a read per registered class; fine for a pool's lifetime of classes.