@logswap/sdk 0.5.102 → 0.5.104

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.
Files changed (64) hide show
  1. package/README.md +14 -418
  2. package/dist/actions.d.ts +0 -39
  3. package/dist/actions.js +0 -39
  4. package/dist/admin.d.ts +0 -106
  5. package/dist/admin.js +1 -96
  6. package/dist/chains.d.ts +0 -49
  7. package/dist/chains.js +0 -30
  8. package/dist/claims.d.ts +0 -32
  9. package/dist/claims.js +0 -30
  10. package/dist/client.d.ts +0 -116
  11. package/dist/client.js +1 -231
  12. package/dist/fees.d.ts +1 -45
  13. package/dist/fees.js +0 -44
  14. package/dist/fpool.d.ts +4 -612
  15. package/dist/fpool.js +14 -490
  16. package/dist/generated.js +0 -30
  17. package/dist/history.d.ts +0 -61
  18. package/dist/history.js +5 -74
  19. package/dist/ids.d.ts +0 -30
  20. package/dist/ids.js +0 -31
  21. package/dist/index.d.ts +0 -7
  22. package/dist/index.js +0 -7
  23. package/dist/indexer.d.ts +0 -68
  24. package/dist/indexer.js +1 -77
  25. package/dist/keys.d.ts +0 -50
  26. package/dist/keys.js +0 -35
  27. package/dist/liquidity.d.ts +0 -128
  28. package/dist/liquidity.js +1 -107
  29. package/dist/onboard.d.ts +0 -52
  30. package/dist/onboard.js +1 -59
  31. package/dist/pools.d.ts +3 -157
  32. package/dist/pools.js +1 -164
  33. package/dist/positions.d.ts +0 -102
  34. package/dist/positions.js +1 -90
  35. package/dist/quote.d.ts +0 -14
  36. package/dist/quote.js +0 -14
  37. package/dist/swap.d.ts +0 -31
  38. package/dist/swap.js +5 -37
  39. package/dist/tokencache.d.ts +0 -48
  40. package/dist/tokencache.js +1 -73
  41. package/dist/write.d.ts +1 -87
  42. package/dist/write.js +1 -87
  43. package/package.json +3 -8
  44. package/src/actions.ts +0 -208
  45. package/src/admin.ts +0 -350
  46. package/src/chains.ts +0 -278
  47. package/src/claims.ts +0 -111
  48. package/src/client.ts +0 -436
  49. package/src/fees.ts +0 -138
  50. package/src/fpool.ts +0 -2049
  51. package/src/generated.ts +0 -4345
  52. package/src/history.ts +0 -383
  53. package/src/ids.ts +0 -78
  54. package/src/index.ts +0 -26
  55. package/src/indexer.ts +0 -264
  56. package/src/keys.ts +0 -138
  57. package/src/liquidity.ts +0 -456
  58. package/src/onboard.ts +0 -253
  59. package/src/pools.ts +0 -465
  60. package/src/positions.ts +0 -297
  61. package/src/quote.ts +0 -36
  62. package/src/swap.ts +0 -181
  63. package/src/tokencache.ts +0 -178
  64. package/src/write.ts +0 -236
package/dist/generated.js CHANGED
@@ -1,6 +1,3 @@
1
- //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
2
- // LensC
3
- //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
4
1
  export const lensCAbi = [
5
2
  {
6
3
  type: 'constructor',
@@ -288,9 +285,6 @@ export const lensCAbi = [
288
285
  { type: 'error', inputs: [], name: 'UnknownId' },
289
286
  { type: 'error', inputs: [], name: 'WrongPool' },
290
287
  ];
291
- //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
292
- // LensF
293
- //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
294
288
  export const lensFAbi = [
295
289
  {
296
290
  type: 'constructor',
@@ -553,9 +547,6 @@ export const lensFAbi = [
553
547
  { type: 'error', inputs: [], name: 'BadParam' },
554
548
  { type: 'error', inputs: [], name: 'DrainsBase' },
555
549
  ];
556
- //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
557
- // ManagerC
558
- //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
559
550
  export const managerCAbi = [
560
551
  {
561
552
  type: 'constructor',
@@ -1541,9 +1532,6 @@ export const managerCAbi = [
1541
1532
  { type: 'error', inputs: [], name: 'ZeroAmount' },
1542
1533
  { type: 'error', inputs: [], name: 'ZeroExposure' },
1543
1534
  ];
1544
- //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
1545
- // ManagerF
1546
- //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
1547
1535
  export const managerFAbi = [
1548
1536
  {
1549
1537
  type: 'constructor',
@@ -2715,9 +2703,6 @@ export const managerFAbi = [
2715
2703
  { type: 'error', inputs: [], name: 'TransferShortfall' },
2716
2704
  { type: 'error', inputs: [], name: 'ZeroAmount' },
2717
2705
  ];
2718
- //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
2719
- // PolicyC
2720
- //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
2721
2706
  export const policyCAbi = [
2722
2707
  {
2723
2708
  type: 'constructor',
@@ -3053,9 +3038,6 @@ export const policyCAbi = [
3053
3038
  },
3054
3039
  { type: 'error', inputs: [], name: 'Refused' },
3055
3040
  ];
3056
- //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
3057
- // PolicyF
3058
- //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
3059
3041
  export const policyFAbi = [
3060
3042
  {
3061
3043
  type: 'constructor',
@@ -3470,9 +3452,6 @@ export const policyFAbi = [
3470
3452
  { type: 'error', inputs: [], name: 'Refused' },
3471
3453
  { type: 'error', inputs: [], name: 'TooManyLegs' },
3472
3454
  ];
3473
- //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
3474
- // PolicyRegistry
3475
- //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
3476
3455
  export const policyRegistryAbi = [
3477
3456
  {
3478
3457
  type: 'constructor',
@@ -3722,9 +3701,6 @@ export const policyRegistryAbi = [
3722
3701
  { type: 'error', inputs: [], name: 'NotListed' },
3723
3702
  { type: 'error', inputs: [], name: 'NotLogAuthority' },
3724
3703
  ];
3725
- //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
3726
- // RouterActions
3727
- //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
3728
3704
  export const routerActionsAbi = [
3729
3705
  {
3730
3706
  type: 'function',
@@ -3847,9 +3823,6 @@ export const routerActionsAbi = [
3847
3823
  stateMutability: 'pure',
3848
3824
  },
3849
3825
  ];
3850
- //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
3851
- // RouterC
3852
- //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
3853
3826
  export const routerCAbi = [
3854
3827
  {
3855
3828
  type: 'constructor',
@@ -4165,9 +4138,6 @@ export const routerCAbi = [
4165
4138
  { type: 'error', inputs: [], name: 'WrongToken' },
4166
4139
  { type: 'error', inputs: [], name: 'ZeroAmount' },
4167
4140
  ];
4168
- //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
4169
- // RouterF
4170
- //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
4171
4141
  export const routerFAbi = [
4172
4142
  {
4173
4143
  type: 'constructor',
package/dist/history.d.ts CHANGED
@@ -1,106 +1,50 @@
1
- /**
2
- * history.ts — event history from the indexer, shaped like viem's `getLogs`, with the chain as the
3
- * fallback.
4
- *
5
- * Every history read used to be a node `getLogs` from a pool's birth (or block 0) to the head: a
6
- * full re-download on every page load, seconds each against a distant node, and silently partial
7
- * once the node pruned its history. rindexer holds the same events with their block timestamps, so
8
- * a window is a filter rather than a block search and a scan is one paged query.
9
- *
10
- * `getEventLogs` takes the ABI event exactly as `getLogs` does and derives the rest from it: the
11
- * table (`all<Name>s`, or the manager-prefixed name where two contracts share an event name, as the
12
- * ERC-6909 `Transfer` does), the columns (the inputs' names, camelCased as postgraphile does), and
13
- * the decoding (the inputs' types — numbers as bigint, addresses checksummed, arrays from JSON).
14
- * With no indexer URL, or when the query fails, it asks the node and says so in `source`.
15
- */
16
1
  import { type AbiEvent, type Address, type Hex } from "viem";
17
2
  import type { LogswapClient } from "./client.js";
18
3
  import type { FPoolKind } from "./fpool.js";
19
- /** One event, as `getLogs` returns it plus its block's timestamp (unix seconds). */
20
4
  export interface HistoryLog<A = Record<string, unknown>> {
21
5
  address: Address;
22
6
  args: A;
23
7
  blockNumber: bigint;
24
- /** Unix seconds. Always set from the indexer; set on the chain path only when a window asked for it. */
25
8
  blockTimestamp?: number;
26
9
  transactionHash: Hex;
27
10
  logIndex: number;
28
11
  }
29
12
  export interface EventLogsQuery {
30
- /** The rindexer GraphQL endpoint; the client's `indexerUrl` when absent, the chain when neither is set. */
31
13
  indexer?: string;
32
- /** The emitter, or several: the four policies share one table per event (indexer phase 1). */
33
14
  address: Address | readonly Address[];
34
- /**
35
- * The emitter's name in the indexer's config, for an event two indexed contracts share — only
36
- * needed when the address is not in the client's artifact (a policy the registry approved later):
37
- * see {@link indexedContractOf}.
38
- */
39
15
  contract?: string;
40
16
  event: AbiEvent;
41
- /** Indexed arguments to match, as `getLogs` takes them; an array matches any of its values. */
42
17
  args?: Record<string, unknown>;
43
- /** The client's `deployBlock` when absent (block 0 without one), on the chain path. */
44
18
  fromBlock?: bigint;
45
19
  toBlock?: bigint;
46
- /** Unix seconds: only events at or after this time. On the chain path it becomes a block search. */
47
20
  since?: number;
48
- /**
49
- * Only the newest `latest` events (still returned oldest first) — a pool's tape, not its history.
50
- * On the chain path the node is asked for the last {@link LATEST_SCAN_BLOCKS} blocks only.
51
- */
52
21
  latest?: number;
53
- /** Only events from these transactions — e.g. the other events of a page of swaps. */
54
22
  transactionHashes?: Hex[];
55
23
  signal?: AbortSignal;
56
24
  }
57
- /**
58
- * The events, oldest first, and where they came from. `"indexer"` rows lag the head by the
59
- * indexer's own lag — a few blocks at most on the devnet (logswap-health checks it).
60
- */
61
25
  export declare function getEventLogs<A = Record<string, unknown>>(c: LogswapClient, q: EventLogsQuery): Promise<{
62
26
  logs: HistoryLog<A>[];
63
27
  source: "indexer" | "chain";
64
28
  }>;
65
- /**
66
- * A policy's name in the indexer for one of its events: `Policy`. Pass it as {@link EventLogsQuery.contract} for a policy outside the artifact.
67
- */
68
29
  export declare function indexedContractOf(kind: FPoolKind, event: string): string;
69
30
  export declare function tableFor(c: LogswapClient, address: Address, event: string, contract?: string): {
70
31
  field: string;
71
32
  type: string;
72
33
  };
73
- /** How far back the chain path looks for a `latest` tape: a tape is recent by definition. */
74
34
  export declare const LATEST_SCAN_BLOCKS = 5000n;
75
- /**
76
- * `eth_getLogs` over [fromBlock, toBlock] in spans of the client's `maxLogRange` blocks, results in
77
- * block order. Public endpoints refuse a wide range (or truncate it); a span this size they answer.
78
- * At most {@link LOG_SPANS_IN_FLIGHT} spans are asked at once.
79
- */
80
35
  export declare function getLogsChunked<L>(c: LogswapClient, params: Record<string, unknown>, fromBlock: bigint, toBlock: bigint): Promise<L[]>;
81
- /** `eth_getLogs` calls in flight at once in {@link getLogsChunked}. */
82
36
  export declare const LOG_SPANS_IN_FLIGHT = 4;
83
- /** A row of {@link getEventsLogs}: one of the asked events, named. */
84
37
  export interface NamedHistoryLog extends HistoryLog {
85
38
  eventName: string;
86
39
  }
87
- /**
88
- * Several events of one contract (or of several emitters sharing them), merged oldest first and
89
- * tagged with `eventName` — the shape of viem's multi-event `getLogs`, which is what the chain path
90
- * runs. One indexer table per event; if any of them cannot answer, the whole read goes to the node,
91
- * so a history is never half the indexer's and half the node's.
92
- */
93
40
  export declare function getEventsLogs(c: LogswapClient, q: Omit<EventLogsQuery, "event" | "args" | "latest" | "contract" | "transactionHashes"> & {
94
41
  events: readonly AbiEvent[];
95
- /** The emitters' policy kind, to name a shared event's table for a policy outside the artifact. */
96
42
  kind?: FPoolKind;
97
- /** The emitter's name in the indexer (e.g. `PolicyRegistry`), for a contract outside the artifact; `kind` wins for a policy. */
98
43
  contract?: string;
99
44
  }): Promise<{
100
45
  logs: NamedHistoryLog[];
101
46
  source: "indexer" | "chain";
102
47
  }>;
103
- /** The devnet's token factory event (`src/mocks/TokenFactory.sol`): provenance for every launchable token. */
104
48
  export declare const TOKEN_CREATED: {
105
49
  readonly name: "TokenCreated";
106
50
  readonly type: "event";
@@ -130,14 +74,9 @@ export interface CreatedToken {
130
74
  symbol: string;
131
75
  supply: bigint;
132
76
  blockNumber: bigint;
133
- /** Unix seconds; set when the indexer answered. */
134
77
  blockTimestamp?: number;
135
78
  transactionHash: Hex;
136
79
  }
137
- /**
138
- * Every token the deployment's factory created, oldest first — the token list's provenance (a token
139
- * named like a factory token but deployed elsewhere is not in it). Optionally one creator's.
140
- */
141
80
  export declare function tokensCreated(c: LogswapClient, q: {
142
81
  indexer?: string;
143
82
  creator?: Address;
package/dist/history.js CHANGED
@@ -1,26 +1,7 @@
1
- /**
2
- * history.ts — event history from the indexer, shaped like viem's `getLogs`, with the chain as the
3
- * fallback.
4
- *
5
- * Every history read used to be a node `getLogs` from a pool's birth (or block 0) to the head: a
6
- * full re-download on every page load, seconds each against a distant node, and silently partial
7
- * once the node pruned its history. rindexer holds the same events with their block timestamps, so
8
- * a window is a filter rather than a block search and a scan is one paged query.
9
- *
10
- * `getEventLogs` takes the ABI event exactly as `getLogs` does and derives the rest from it: the
11
- * table (`all<Name>s`, or the manager-prefixed name where two contracts share an event name, as the
12
- * ERC-6909 `Transfer` does), the columns (the inputs' names, camelCased as postgraphile does), and
13
- * the decoding (the inputs' types — numbers as bigint, addresses checksummed, arrays from JSON).
14
- * With no indexer URL, or when the query fails, it asks the node and says so in `source`.
15
- */
16
1
  import { getAddress, parseAbiItem } from "viem";
17
2
  import { DEFAULT_MAX_LOG_RANGE } from "./chains.js";
18
3
  import { bytea, gql } from "./indexer.js";
19
4
  import { blockAtOrAfter } from "./fees.js";
20
- /**
21
- * The events, oldest first, and where they came from. `"indexer"` rows lag the head by the
22
- * indexer's own lag — a few blocks at most on the devnet (logswap-health checks it).
23
- */
24
5
  export async function getEventLogs(c, q) {
25
6
  const indexer = q.indexer ?? c.indexerUrl;
26
7
  if (indexer) {
@@ -28,22 +9,14 @@ export async function getEventLogs(c, q) {
28
9
  return { logs: await fromIndexer(c, { ...q, indexer }), source: "indexer" };
29
10
  }
30
11
  catch {
31
- /* the indexer is a cache: when it cannot answer, the node can */
32
12
  }
33
13
  }
34
14
  return { logs: await fromChain(c, q), source: "chain" };
35
15
  }
36
- // ─── the indexer path ────────────────────────────────────────────────────────
37
- /**
38
- * What the rindexer deployment calls each contract — the prefix of a table two contracts share
39
- * (logswap-be `devnet/indexer/rindexer.yaml`). Every policy is one factory-tracked contract, `Policy`: the four F policies are
40
- * one contract (`PolicyF`, F 41) and share its events, so no policy event needs a prefix.
41
- */
42
16
  function contractName(c, address, event) {
43
17
  const a = address.toLowerCase();
44
18
  const is = (x) => x !== undefined && a === x.toLowerCase();
45
19
  const { addresses: d } = c;
46
- // the indexer's own labels for the contracts (its `rindexer.yaml`), not the contracts' names (decision 096): ManagerC / ManagerF / RouterC / RouterF
47
20
  if (is(d.managerC))
48
21
  return "CPoolManager";
49
22
  if (is(d.managerF))
@@ -60,19 +33,12 @@ function contractName(c, address, event) {
60
33
  return indexedContractOf("public", event);
61
34
  return null;
62
35
  }
63
- /**
64
- * A policy's name in the indexer for one of its events: `Policy`. Pass it as {@link EventLogsQuery.contract} for a policy outside the artifact.
65
- */
66
36
  export function indexedContractOf(kind, event) {
67
- void kind; // one contract serves every F kind (F 41) and `PolicyC` emits the same set (C 18): every policy event is unshared
37
+ void kind;
68
38
  return "Policy";
69
39
  }
70
- /** Events whose name two indexed contracts share: postgraphile prefixes their tables. */
71
- // `CollectorProposed` / `CollectorAccepted` are C 7 / F 26 and older; `TreasuryProposed` / `TreasuryAccepted` replace them (066).
72
- // `SwapState` (was `CSwapState` / `FSwapState`) and `GatesSet` (`PermissionsSet` before decision 098) are `ManagerBase`'s: declared once, emitted by both managers (decisions 096, #112).
73
40
  const SHARED = new Set(["PoolCreated", "Swap", "SwapState", "GatesSet", "Transfer", "Approval", "OperatorSet", "CollectorProposed", "CollectorAccepted", "TreasuryProposed", "TreasuryAccepted", "Approved"]);
74
41
  const plural = (n) => (/(s|x|ch|sh)$/.test(n) ? `${n}es` : `${n}s`);
75
- /** A column's GraphQL name: postgraphile camelCases the snake_case rindexer writes (`F` → `f`). */
76
42
  const column = (name) => name[0].toLowerCase() + name.slice(1);
77
43
  export function tableFor(c, address, event, contract) {
78
44
  const prefix = SHARED.has(event) ? (contract ?? contractName(c, address, event)) : "";
@@ -82,12 +48,6 @@ export function tableFor(c, address, event, contract) {
82
48
  return { field: `all${plural(type)}`, type };
83
49
  }
84
50
  const emitters = (q) => (Array.isArray(q.address) ? [...q.address] : [q.address]);
85
- /**
86
- * A column as the indexer serves it, typed by the ABI: numbers are strings, addresses lowercase, an
87
- * array a JSON array, and a tuple a JSON object keyed by component name with the same conventions
88
- * inside (`LiquidityDeployed.baseAssets`, F 38: `{base, amount, priceX36}[]` with string amounts).
89
- * Decoding recurses into the components, so a tuple's numbers come out as bigints like the node's.
90
- */
91
51
  function decode(p, v) {
92
52
  if (v === null || v === undefined)
93
53
  return v;
@@ -102,11 +62,10 @@ function decode(p, v) {
102
62
  return BigInt(v);
103
63
  if (type === "address")
104
64
  return getAddress(v);
105
- return v; // bool, bytes32 (hex string), string
65
+ return v;
106
66
  }
107
- const PAGE = 1000; // postgraphile's cap
67
+ const PAGE = 1000;
108
68
  const MAX_PAGES = 200;
109
- /** Pages in flight at once, after the first. */
110
69
  const PARALLEL_PAGES = 8;
111
70
  async function fromIndexer(c, q) {
112
71
  const all = emitters(q);
@@ -122,7 +81,6 @@ async function fromIndexer(c, q) {
122
81
  continue;
123
82
  const enc = (x) => (input.type === "bytes32" ? bytea(x) : typeof x === "string" ? x.toLowerCase() : String(x));
124
83
  if (Array.isArray(v)) {
125
- // postgraphile's filter cannot match a bytea column; an OR over one leaves this to the chain
126
84
  if (input.type === "bytes32")
127
85
  throw new Error("history: OR over a bytes32 argument");
128
86
  filter[column(k)] = { in: v.map(enc) };
@@ -142,11 +100,9 @@ async function fromIndexer(c, q) {
142
100
  filter.blockTimestamp = { greaterThanOrEqualTo: new Date(q.since * 1000).toISOString() };
143
101
  if (q.transactionHashes)
144
102
  filter.txHash = { in: q.transactionHashes.map((h) => h.toLowerCase()) };
145
- // a tape is one page from the head, newest first; history is every page from the start
146
103
  const pageSize = q.latest ?? PAGE;
147
104
  const order = q.latest !== undefined ? "[BLOCK_NUMBER_DESC, LOG_INDEX_DESC]" : "PRIMARY_KEY_ASC";
148
105
  const selection = [...inputs.map((i) => column(i.name)), "contractAddress", "blockNumber", "blockTimestamp", "txHash", "logIndex"].join(" ");
149
- // postgraphile refuses a null or an empty filter, so each argument appears only when it has content
150
106
  const hasCondition = Object.keys(condition).length > 0;
151
107
  const hasFilter = Object.keys(filter).length > 0;
152
108
  const decl = `$offset: Int${hasCondition ? `, $condition: ${type}Condition` : ""}${hasFilter ? `, $filter: ${type}Filter` : ""}`;
@@ -157,10 +113,6 @@ async function fromIndexer(c, q) {
157
113
  }
158
114
  }`;
159
115
  const page = async (offset) => (await gql(q.indexer, query, { offset, ...(hasCondition ? { condition } : {}), ...(hasFilter ? { filter } : {}) }, q.signal))[field];
160
- // The first page says how many rows there are; the rest are fetched in parallel by offset, not
161
- // one cursor after another: a day of a busy pool is a few pages, and a round trip to a distant
162
- // indexer costs more than the page. Ascending by key, rows that land meanwhile append at the end
163
- // and shift no earlier offset.
164
116
  const first = await page(0);
165
117
  const rows = [...first.nodes];
166
118
  if (q.latest === undefined && first.totalCount > first.nodes.length) {
@@ -174,7 +126,6 @@ async function fromIndexer(c, q) {
174
126
  rows.push(...g.nodes);
175
127
  }
176
128
  }
177
- // a table can hold a previous deployment's rows (an indexer not yet reset): keep this contract's
178
129
  const want = new Map(all.map((a) => [a.toLowerCase(), a]));
179
130
  return rows
180
131
  .filter((r) => want.has(String(r.contractAddress).toLowerCase()))
@@ -188,14 +139,7 @@ async function fromIndexer(c, q) {
188
139
  }))
189
140
  .sort((a, b) => (a.blockNumber === b.blockNumber ? a.logIndex - b.logIndex : a.blockNumber < b.blockNumber ? -1 : 1));
190
141
  }
191
- // ─── the chain path ──────────────────────────────────────────────────────────
192
- /** How far back the chain path looks for a `latest` tape: a tape is recent by definition. */
193
142
  export const LATEST_SCAN_BLOCKS = 5000n;
194
- /**
195
- * `eth_getLogs` over [fromBlock, toBlock] in spans of the client's `maxLogRange` blocks, results in
196
- * block order. Public endpoints refuse a wide range (or truncate it); a span this size they answer.
197
- * At most {@link LOG_SPANS_IN_FLIGHT} spans are asked at once.
198
- */
199
143
  export async function getLogsChunked(c, params, fromBlock, toBlock) {
200
144
  const span = c.maxLogRange ?? DEFAULT_MAX_LOG_RANGE;
201
145
  if (span <= 0n)
@@ -211,11 +155,10 @@ export async function getLogsChunked(c, params, fromBlock, toBlock) {
211
155
  }
212
156
  return out;
213
157
  }
214
- /** `eth_getLogs` calls in flight at once in {@link getLogsChunked}. */
215
158
  export const LOG_SPANS_IN_FLIGHT = 4;
216
159
  async function fromChain(c, q) {
217
160
  let fromBlock = q.fromBlock ?? c.deployBlock ?? 0n;
218
- const toBlock = q.toBlock ?? (await c.public.getBlockNumber({ cacheTime: 0 })); // uncached: viem caches the head, and a scan bounded by a stale one misses the block just mined
161
+ const toBlock = q.toBlock ?? (await c.public.getBlockNumber({ cacheTime: 0 }));
219
162
  if (q.since !== undefined)
220
163
  fromBlock = await blockAtOrAfter(c, BigInt(q.since), fromBlock, toBlock);
221
164
  if (q.latest !== undefined && toBlock - fromBlock > LATEST_SCAN_BLOCKS)
@@ -238,12 +181,6 @@ async function fromChain(c, q) {
238
181
  logIndex: l.logIndex,
239
182
  }));
240
183
  }
241
- /**
242
- * Several events of one contract (or of several emitters sharing them), merged oldest first and
243
- * tagged with `eventName` — the shape of viem's multi-event `getLogs`, which is what the chain path
244
- * runs. One indexer table per event; if any of them cannot answer, the whole read goes to the node,
245
- * so a history is never half the indexer's and half the node's.
246
- */
247
184
  export async function getEventsLogs(c, q) {
248
185
  const order = (a, b) => (a.blockNumber === b.blockNumber ? a.logIndex - b.logIndex : a.blockNumber < b.blockNumber ? -1 : 1);
249
186
  const indexer = q.indexer ?? c.indexerUrl;
@@ -256,14 +193,13 @@ export async function getEventsLogs(c, q) {
256
193
  return { logs: got.flat().sort(order), source: "indexer" };
257
194
  }
258
195
  catch {
259
- /* the indexer is a cache: the node holds the same events */
260
196
  }
261
197
  }
262
198
  const all = emitters(q);
263
199
  if (all.length === 0 || q.events.length === 0)
264
200
  return { logs: [], source: "chain" };
265
201
  let fromBlock = q.fromBlock ?? c.deployBlock ?? 0n;
266
- const toBlock = q.toBlock ?? (await c.public.getBlockNumber({ cacheTime: 0 })); // uncached: viem caches the head, and a scan bounded by a stale one misses the block just mined
202
+ const toBlock = q.toBlock ?? (await c.public.getBlockNumber({ cacheTime: 0 }));
267
203
  if (q.since !== undefined)
268
204
  fromBlock = await blockAtOrAfter(c, BigInt(q.since), fromBlock, toBlock);
269
205
  const logs = await getLogsChunked(c, { address: Array.isArray(q.address) ? all : q.address, events: q.events }, fromBlock, toBlock);
@@ -274,12 +210,7 @@ export async function getEventsLogs(c, q) {
274
210
  source: "chain",
275
211
  };
276
212
  }
277
- /** The devnet's token factory event (`src/mocks/TokenFactory.sol`): provenance for every launchable token. */
278
213
  export const TOKEN_CREATED = parseAbiItem("event TokenCreated(address indexed creator, address indexed token, string name, string symbol, uint256 supply)");
279
- /**
280
- * Every token the deployment's factory created, oldest first — the token list's provenance (a token
281
- * named like a factory token but deployed elsewhere is not in it). Optionally one creator's.
282
- */
283
214
  export async function tokensCreated(c, q) {
284
215
  const factory = c.addresses.tokenFactory;
285
216
  if (!factory)
package/dist/ids.d.ts CHANGED
@@ -1,42 +1,12 @@
1
- /**
2
- * ids.ts — the ERC-6909 id namespace, computed OFFLINE.
3
- *
4
- * Two kinds of id share one ERC-6909 space, split on **bit 255**:
5
- *
6
- * bit 255 SET a position class: (1 << 255) | (keccak256(poolId ‖ packed) >> 1)
7
- * bit 255 CLEAR a token claim: uint160(tokenAddress)
8
- *
9
- * Both are **tier-1 frozen** (docs/app.md). The namespace bit is what lets a wallet UI, a lender, or
10
- * an indexer tell an LP position from a bearer IOU — and an indexer that ignores it will report
11
- * phantom LP positions for market makers parking inventory.
12
- */
13
1
  import { type Address, type Hex } from "viem";
14
- /** Sentinel meaning "no cap" — `type(int256).min`. */
15
2
  export declare const NO_CAP: bigint;
16
- /**
17
- * `packed` — the class's (floor, cap) as two 32-bit fields: `kFloor + 2^31` in the low half,
18
- * `kCap + 2^31` in the high half, or zero there when uncapped.
19
- *
20
- * Throws on an off-grid floor or cap rather than producing an id the manager would reject, so a
21
- * client fails at the call site instead of at the transaction.
22
- */
23
3
  export declare function packFloorCap(tickSpacing: bigint, floor: bigint, cap?: bigint): bigint;
24
- /** Inverse of {@link packFloorCap}. `capped === false` means the cap field is unset. */
25
4
  export declare function unpackFloorCap(tickSpacing: bigint, packed: bigint): {
26
5
  floor: bigint;
27
6
  cap: bigint;
28
7
  capped: boolean;
29
8
  };
30
- /**
31
- * The position-class id: `(1 << 255) | (keccak256(poolId ‖ packed) >> 1)`.
32
- *
33
- * The `>> 1` is what frees bit 255 for the namespace flag, so the hash contributes 255 bits.
34
- * `abi.encodePacked(bytes32, uint64)` is 40 bytes — 32 for the pool id, 8 for `packed`.
35
- */
36
9
  export declare function positionId(poolId_: Hex, tickSpacing: bigint, floor: bigint, cap?: bigint): bigint;
37
- /** A token claim's id is just the token address. */
38
10
  export declare function claimId(token: Address): bigint;
39
- /** True for a position class, false for a token claim. Split every 6909 `Transfer` on this. */
40
11
  export declare function isPosition(id: bigint): boolean;
41
- /** The token an id refers to, or `null` if the id is a position rather than a claim. */
42
12
  export declare function claimToken(id: bigint): Address | null;
package/dist/ids.js CHANGED
@@ -1,28 +1,7 @@
1
- /**
2
- * ids.ts — the ERC-6909 id namespace, computed OFFLINE.
3
- *
4
- * Two kinds of id share one ERC-6909 space, split on **bit 255**:
5
- *
6
- * bit 255 SET a position class: (1 << 255) | (keccak256(poolId ‖ packed) >> 1)
7
- * bit 255 CLEAR a token claim: uint160(tokenAddress)
8
- *
9
- * Both are **tier-1 frozen** (docs/app.md). The namespace bit is what lets a wallet UI, a lender, or
10
- * an indexer tell an LP position from a bearer IOU — and an indexer that ignores it will report
11
- * phantom LP positions for market makers parking inventory.
12
- */
13
1
  import { concatHex, keccak256, pad, toHex } from "viem";
14
- /** Packing offset for the signed tick index `k`, so it fits an unsigned 32-bit field. */
15
2
  const ID_OFFSET = 1n << 31n;
16
- /** Sentinel meaning "no cap" — `type(int256).min`. */
17
3
  export const NO_CAP = -(2n ** 255n);
18
4
  const BIT_255 = 1n << 255n;
19
- /**
20
- * `packed` — the class's (floor, cap) as two 32-bit fields: `kFloor + 2^31` in the low half,
21
- * `kCap + 2^31` in the high half, or zero there when uncapped.
22
- *
23
- * Throws on an off-grid floor or cap rather than producing an id the manager would reject, so a
24
- * client fails at the call site instead of at the transaction.
25
- */
26
5
  export function packFloorCap(tickSpacing, floor, cap = NO_CAP) {
27
6
  if (tickSpacing <= 0n)
28
7
  throw new Error("tickSpacing must be positive");
@@ -38,33 +17,23 @@ export function packFloorCap(tickSpacing, floor, cap = NO_CAP) {
38
17
  }
39
18
  return packed;
40
19
  }
41
- /** Inverse of {@link packFloorCap}. `capped === false` means the cap field is unset. */
42
20
  export function unpackFloorCap(tickSpacing, packed) {
43
21
  const kf = (packed & 0xffffffffn) - ID_OFFSET;
44
22
  const hi = packed >> 32n;
45
23
  const capped = hi !== 0n;
46
24
  return { floor: kf * tickSpacing, cap: capped ? (hi - ID_OFFSET) * tickSpacing : NO_CAP, capped };
47
25
  }
48
- /**
49
- * The position-class id: `(1 << 255) | (keccak256(poolId ‖ packed) >> 1)`.
50
- *
51
- * The `>> 1` is what frees bit 255 for the namespace flag, so the hash contributes 255 bits.
52
- * `abi.encodePacked(bytes32, uint64)` is 40 bytes — 32 for the pool id, 8 for `packed`.
53
- */
54
26
  export function positionId(poolId_, tickSpacing, floor, cap = NO_CAP) {
55
27
  const packed = packFloorCap(tickSpacing, floor, cap);
56
28
  const h = BigInt(keccak256(concatHex([poolId_, pad(toHex(packed), { size: 8 })])));
57
29
  return BIT_255 | (h >> 1n);
58
30
  }
59
- /** A token claim's id is just the token address. */
60
31
  export function claimId(token) {
61
32
  return BigInt(token);
62
33
  }
63
- /** True for a position class, false for a token claim. Split every 6909 `Transfer` on this. */
64
34
  export function isPosition(id) {
65
35
  return (id & BIT_255) !== 0n;
66
36
  }
67
- /** The token an id refers to, or `null` if the id is a position rather than a claim. */
68
37
  export function claimToken(id) {
69
38
  if (isPosition(id))
70
39
  return null;
package/dist/index.d.ts CHANGED
@@ -1,10 +1,3 @@
1
- /**
2
- * log(swap) SDK — typed, offline-first helpers over the ManagerF / ManagerC, RouterF / RouterC and LensF / LensC surface.
3
- *
4
- * The manager/router/lens split is hidden here: callers address markets by `PoolKey` (C) and pool id (F) and
5
- * never choose a contract. What a caller does choose is the SIDE (`"F"` or `"C"`) where a router is the
6
- * spender (decision 096: one router per manager, each its own Permit2 spender) — see `onboard.ts`.
7
- */
8
1
  export * from "./keys.js";
9
2
  export * from "./ids.js";
10
3
  export * from "./client.js";
package/dist/index.js CHANGED
@@ -1,10 +1,3 @@
1
- /**
2
- * log(swap) SDK — typed, offline-first helpers over the ManagerF / ManagerC, RouterF / RouterC and LensF / LensC surface.
3
- *
4
- * The manager/router/lens split is hidden here: callers address markets by `PoolKey` (C) and pool id (F) and
5
- * never choose a contract. What a caller does choose is the SIDE (`"F"` or `"C"`) where a router is the
6
- * spender (decision 096: one router per manager, each its own Permit2 spender) — see `onboard.ts`.
7
- */
8
1
  export * from "./keys.js";
9
2
  export * from "./ids.js";
10
3
  export * from "./client.js";