@tickwise/sdk 0.0.0-stage → 0.1.0

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 (72) hide show
  1. package/LICENSE +661 -0
  2. package/README.md +185 -2
  3. package/dist/cjs/api-promise.d.ts +22 -0
  4. package/dist/cjs/api-promise.js +43 -0
  5. package/dist/cjs/client.d.ts +64 -0
  6. package/dist/cjs/client.js +118 -0
  7. package/dist/cjs/csv.d.ts +37 -0
  8. package/dist/cjs/csv.js +69 -0
  9. package/dist/cjs/errors.d.ts +85 -0
  10. package/dist/cjs/errors.js +181 -0
  11. package/dist/cjs/generated/openapi.d.ts +1821 -0
  12. package/dist/cjs/generated/openapi.js +6 -0
  13. package/dist/cjs/index.d.ts +11 -0
  14. package/dist/cjs/index.js +30 -0
  15. package/dist/cjs/package.json +1 -0
  16. package/dist/cjs/resources/base.d.ts +21 -0
  17. package/dist/cjs/resources/base.js +81 -0
  18. package/dist/cjs/resources/hooks.d.ts +26 -0
  19. package/dist/cjs/resources/hooks.js +46 -0
  20. package/dist/cjs/resources/meta.d.ts +23 -0
  21. package/dist/cjs/resources/meta.js +35 -0
  22. package/dist/cjs/resources/pools.d.ts +21 -0
  23. package/dist/cjs/resources/pools.js +40 -0
  24. package/dist/cjs/resources/positions.d.ts +45 -0
  25. package/dist/cjs/resources/positions.js +133 -0
  26. package/dist/cjs/resources/tokens.d.ts +13 -0
  27. package/dist/cjs/resources/tokens.js +20 -0
  28. package/dist/cjs/resources/wallets.d.ts +11 -0
  29. package/dist/cjs/resources/wallets.js +14 -0
  30. package/dist/cjs/routes.d.ts +80 -0
  31. package/dist/cjs/routes.js +40 -0
  32. package/dist/cjs/transport.d.ts +91 -0
  33. package/dist/cjs/transport.js +310 -0
  34. package/dist/cjs/types.d.ts +99 -0
  35. package/dist/cjs/types.js +2 -0
  36. package/dist/cjs/version.d.ts +2 -0
  37. package/dist/cjs/version.js +5 -0
  38. package/dist/esm/api-promise.d.ts +22 -0
  39. package/dist/esm/api-promise.js +39 -0
  40. package/dist/esm/client.d.ts +64 -0
  41. package/dist/esm/client.js +114 -0
  42. package/dist/esm/csv.d.ts +37 -0
  43. package/dist/esm/csv.js +64 -0
  44. package/dist/esm/errors.d.ts +85 -0
  45. package/dist/esm/errors.js +163 -0
  46. package/dist/esm/generated/openapi.d.ts +1821 -0
  47. package/dist/esm/generated/openapi.js +5 -0
  48. package/dist/esm/index.d.ts +11 -0
  49. package/dist/esm/index.js +8 -0
  50. package/dist/esm/resources/base.d.ts +21 -0
  51. package/dist/esm/resources/base.js +73 -0
  52. package/dist/esm/resources/hooks.d.ts +26 -0
  53. package/dist/esm/resources/hooks.js +42 -0
  54. package/dist/esm/resources/meta.d.ts +23 -0
  55. package/dist/esm/resources/meta.js +30 -0
  56. package/dist/esm/resources/pools.d.ts +21 -0
  57. package/dist/esm/resources/pools.js +36 -0
  58. package/dist/esm/resources/positions.d.ts +45 -0
  59. package/dist/esm/resources/positions.js +129 -0
  60. package/dist/esm/resources/tokens.d.ts +13 -0
  61. package/dist/esm/resources/tokens.js +16 -0
  62. package/dist/esm/resources/wallets.d.ts +11 -0
  63. package/dist/esm/resources/wallets.js +10 -0
  64. package/dist/esm/routes.d.ts +80 -0
  65. package/dist/esm/routes.js +36 -0
  66. package/dist/esm/transport.d.ts +91 -0
  67. package/dist/esm/transport.js +299 -0
  68. package/dist/esm/types.d.ts +99 -0
  69. package/dist/esm/types.js +1 -0
  70. package/dist/esm/version.d.ts +2 -0
  71. package/dist/esm/version.js +2 -0
  72. package/package.json +64 -4
@@ -0,0 +1,6 @@
1
+ "use strict";
2
+ /**
3
+ * This file was auto-generated by openapi-typescript.
4
+ * Do not make direct changes to the file.
5
+ */
6
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,11 @@
1
+ export { Tickwise, type TickwiseOptions } from './client.js';
2
+ export { APIPromise, type WithMeta } from './api-promise.js';
3
+ export { APIError, AuthenticationError, BadRequestError, ConnectionError, NotFoundError, PermissionDeniedError, QuotaExceededError, RateLimitError, ServiceUnavailableError, TickwiseError, type TickwiseErrorKind, TimeoutError, TooManyRequestsError, } from './errors.js';
4
+ export type { CsvPage, CsvPagination } from './csv.js';
5
+ export { DEFAULT_BASE_URL, type LimitInfo, type RequestOptions, type ResponseMeta } from './transport.js';
6
+ export { POSITION_BATCH_MAX } from './resources/positions.js';
7
+ export { HOOKS_ALL_CHAINS_MAX_ROWS } from './resources/hooks.js';
8
+ export { ROUTES, type OperationId } from './routes.js';
9
+ export { VERSION } from './version.js';
10
+ export type * from './types.js';
11
+ export type { components, operations, paths } from './generated/openapi.js';
@@ -0,0 +1,30 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.VERSION = exports.ROUTES = exports.HOOKS_ALL_CHAINS_MAX_ROWS = exports.POSITION_BATCH_MAX = exports.DEFAULT_BASE_URL = exports.TooManyRequestsError = exports.TimeoutError = exports.TickwiseError = exports.ServiceUnavailableError = exports.RateLimitError = exports.QuotaExceededError = exports.PermissionDeniedError = exports.NotFoundError = exports.ConnectionError = exports.BadRequestError = exports.AuthenticationError = exports.APIError = exports.APIPromise = exports.Tickwise = void 0;
4
+ var client_js_1 = require("./client.js");
5
+ Object.defineProperty(exports, "Tickwise", { enumerable: true, get: function () { return client_js_1.Tickwise; } });
6
+ var api_promise_js_1 = require("./api-promise.js");
7
+ Object.defineProperty(exports, "APIPromise", { enumerable: true, get: function () { return api_promise_js_1.APIPromise; } });
8
+ var errors_js_1 = require("./errors.js");
9
+ Object.defineProperty(exports, "APIError", { enumerable: true, get: function () { return errors_js_1.APIError; } });
10
+ Object.defineProperty(exports, "AuthenticationError", { enumerable: true, get: function () { return errors_js_1.AuthenticationError; } });
11
+ Object.defineProperty(exports, "BadRequestError", { enumerable: true, get: function () { return errors_js_1.BadRequestError; } });
12
+ Object.defineProperty(exports, "ConnectionError", { enumerable: true, get: function () { return errors_js_1.ConnectionError; } });
13
+ Object.defineProperty(exports, "NotFoundError", { enumerable: true, get: function () { return errors_js_1.NotFoundError; } });
14
+ Object.defineProperty(exports, "PermissionDeniedError", { enumerable: true, get: function () { return errors_js_1.PermissionDeniedError; } });
15
+ Object.defineProperty(exports, "QuotaExceededError", { enumerable: true, get: function () { return errors_js_1.QuotaExceededError; } });
16
+ Object.defineProperty(exports, "RateLimitError", { enumerable: true, get: function () { return errors_js_1.RateLimitError; } });
17
+ Object.defineProperty(exports, "ServiceUnavailableError", { enumerable: true, get: function () { return errors_js_1.ServiceUnavailableError; } });
18
+ Object.defineProperty(exports, "TickwiseError", { enumerable: true, get: function () { return errors_js_1.TickwiseError; } });
19
+ Object.defineProperty(exports, "TimeoutError", { enumerable: true, get: function () { return errors_js_1.TimeoutError; } });
20
+ Object.defineProperty(exports, "TooManyRequestsError", { enumerable: true, get: function () { return errors_js_1.TooManyRequestsError; } });
21
+ var transport_js_1 = require("./transport.js");
22
+ Object.defineProperty(exports, "DEFAULT_BASE_URL", { enumerable: true, get: function () { return transport_js_1.DEFAULT_BASE_URL; } });
23
+ var positions_js_1 = require("./resources/positions.js");
24
+ Object.defineProperty(exports, "POSITION_BATCH_MAX", { enumerable: true, get: function () { return positions_js_1.POSITION_BATCH_MAX; } });
25
+ var hooks_js_1 = require("./resources/hooks.js");
26
+ Object.defineProperty(exports, "HOOKS_ALL_CHAINS_MAX_ROWS", { enumerable: true, get: function () { return hooks_js_1.HOOKS_ALL_CHAINS_MAX_ROWS; } });
27
+ var routes_js_1 = require("./routes.js");
28
+ Object.defineProperty(exports, "ROUTES", { enumerable: true, get: function () { return routes_js_1.ROUTES; } });
29
+ var version_js_1 = require("./version.js");
30
+ Object.defineProperty(exports, "VERSION", { enumerable: true, get: function () { return version_js_1.VERSION; } });
@@ -0,0 +1 @@
1
+ {"type":"commonjs"}
@@ -0,0 +1,21 @@
1
+ import { APIPromise } from '../api-promise.js';
2
+ import { type CsvPage } from '../csv.js';
3
+ import { type OperationId } from '../routes.js';
4
+ import type { Query, RequestOptions, Transport } from '../transport.js';
5
+ import type { PagingOptions } from '../types.js';
6
+ /** A query object from the caller, as sent: `format` is the SDK's to set, never the caller's. */
7
+ export declare function toQuery(q: object | undefined, extra?: Record<string, unknown>): Query;
8
+ export declare class Resource {
9
+ protected readonly transport: Transport;
10
+ constructor(transport: Transport);
11
+ protected call<T>(op: OperationId, pathParams: Record<string, string | number | bigint> | undefined, query: Query | undefined, options: RequestOptions | undefined): APIPromise<T>;
12
+ protected callCsv(op: OperationId, query: Query, options: RequestOptions | undefined): APIPromise<CsvPage>;
13
+ }
14
+ /**
15
+ * Pages of a `page` / `limit` list, fetched one at a time and only when asked for. Stops when the page says there
16
+ * is no more, when a page comes back empty (a guard against a server bug looping forever), or at `maxPages`.
17
+ */
18
+ export declare function pageIterator<P>(query: object | undefined, fetchPage: (page: number) => Promise<P>, hasMore: (p: P) => boolean, size: (p: P) => number, opts?: PagingOptions): AsyncGenerator<P, void, undefined>;
19
+ /** The rows of a page iterator, up to `maxItems`. */
20
+ export declare function rowIterator<P, R>(pages: AsyncGenerator<P, void, undefined>, rows: (p: P) => readonly R[], opts?: PagingOptions): AsyncGenerator<R, void, undefined>;
21
+ export declare function splitOptions<O extends RequestOptions & PagingOptions>(o: O | undefined): [RequestOptions, PagingOptions];
@@ -0,0 +1,81 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Resource = void 0;
4
+ exports.toQuery = toQuery;
5
+ exports.pageIterator = pageIterator;
6
+ exports.rowIterator = rowIterator;
7
+ exports.splitOptions = splitOptions;
8
+ const api_promise_js_1 = require("../api-promise.js");
9
+ const csv_js_1 = require("../csv.js");
10
+ const routes_js_1 = require("../routes.js");
11
+ /** A query object from the caller, as sent: `format` is the SDK's to set, never the caller's. */
12
+ function toQuery(q, extra = {}) {
13
+ const out = { ...(q ?? {}) };
14
+ delete out.format;
15
+ return { ...out, ...extra };
16
+ }
17
+ class Resource {
18
+ transport;
19
+ constructor(transport) {
20
+ this.transport = transport;
21
+ }
22
+ call(op, pathParams, query, options) {
23
+ let raw;
24
+ try {
25
+ raw = this.transport.request({ path: (0, routes_js_1.fillPath)(op, pathParams), query, metered: routes_js_1.ROUTES[op].metered, accept: 'json' }, options);
26
+ }
27
+ catch (e) {
28
+ raw = Promise.reject(e);
29
+ }
30
+ return new api_promise_js_1.APIPromise(raw.then((r) => ({ data: r.body, meta: r.meta })));
31
+ }
32
+ callCsv(op, query, options) {
33
+ const raw = this.transport.request({ path: (0, routes_js_1.fillPath)(op), query: { ...query, format: 'csv' }, metered: routes_js_1.ROUTES[op].metered, accept: 'csv' }, options);
34
+ return new api_promise_js_1.APIPromise(raw.then((r) => ({ data: (0, csv_js_1.csvPageOf)(r.body, r.meta.headers, r.meta.url), meta: r.meta })));
35
+ }
36
+ }
37
+ exports.Resource = Resource;
38
+ function startPage(q) {
39
+ const p = q?.page;
40
+ return typeof p === 'number' && Number.isInteger(p) && p >= 1 ? p : 1;
41
+ }
42
+ /**
43
+ * Pages of a `page` / `limit` list, fetched one at a time and only when asked for. Stops when the page says there
44
+ * is no more, when a page comes back empty (a guard against a server bug looping forever), or at `maxPages`.
45
+ */
46
+ async function* pageIterator(query, fetchPage, hasMore, size, opts = {}) {
47
+ let page = startPage(query);
48
+ for (let n = 0; opts.maxPages === undefined || n < opts.maxPages; n++, page++) {
49
+ const p = await fetchPage(page);
50
+ yield p;
51
+ if (!hasMore(p) || size(p) === 0)
52
+ return;
53
+ }
54
+ }
55
+ /** The rows of a page iterator, up to `maxItems`. */
56
+ async function* rowIterator(pages, rows, opts = {}) {
57
+ if (opts.maxItems !== undefined && opts.maxItems <= 0)
58
+ return;
59
+ let n = 0;
60
+ try {
61
+ for await (const p of pages) {
62
+ for (const r of rows(p)) {
63
+ yield r;
64
+ if (opts.maxItems !== undefined && ++n >= opts.maxItems)
65
+ return;
66
+ }
67
+ }
68
+ }
69
+ finally {
70
+ await pages.return(undefined);
71
+ }
72
+ }
73
+ function splitOptions(o) {
74
+ const { maxPages, maxItems, ...rest } = o ?? {};
75
+ const paging = {};
76
+ if (maxPages !== undefined)
77
+ paging.maxPages = maxPages;
78
+ if (maxItems !== undefined)
79
+ paging.maxItems = maxItems;
80
+ return [rest, paging];
81
+ }
@@ -0,0 +1,26 @@
1
+ import type { APIPromise } from '../api-promise.js';
2
+ import { type CsvPage } from '../csv.js';
3
+ import type { RequestOptions } from '../transport.js';
4
+ import type { Hook, HookList, HooksListQuery, PagingOptions } from '../types.js';
5
+ import { Resource } from './base.js';
6
+ /**
7
+ * Deepest row an all-chains hooks page may reach (`page` × `limit`). The API refuses a deeper page with a 400 and
8
+ * still says `hasMore: true` on the last page it allows, so the iterators stop at the cap. Pass `chainId` to page
9
+ * one chain further.
10
+ */
11
+ export declare const HOOKS_ALL_CHAINS_MAX_ROWS = 1000;
12
+ export declare class Hooks extends Resource {
13
+ /** `GET /v1/hooks`: Uniswap v4 hooks with the TVL, volume and fees of their pools. */
14
+ list(query?: HooksListQuery, options?: RequestOptions): APIPromise<HookList>;
15
+ /**
16
+ * Every page of `list`, fetched as you iterate. Without `chainId` it stops at `HOOKS_ALL_CHAINS_MAX_ROWS` (1,000
17
+ * rows deep), the most the API serves across all chains; pass `chainId` to page further.
18
+ */
19
+ pages(query?: HooksListQuery, options?: RequestOptions & PagingOptions): AsyncGenerator<HookList, void, undefined>;
20
+ /** Every row of `list`, across pages (at most 1,000 without `chainId`). Each page is a metered request; `break` stops fetching. */
21
+ iterate(query?: HooksListQuery, options?: RequestOptions & PagingOptions): AsyncGenerator<Hook, void, undefined>;
22
+ /** One page of `list` as CSV (`format=csv`): same filters, paging and unit cost as JSON. */
23
+ exportCsv(query?: HooksListQuery, options?: RequestOptions): APIPromise<CsvPage>;
24
+ /** Every page of `list` as CSV, each with its own header row (at most 1,000 rows without `chainId`). Each page is a metered request. */
25
+ exportCsvPages(query?: HooksListQuery, options?: RequestOptions & PagingOptions): AsyncGenerator<CsvPage, void, undefined>;
26
+ }
@@ -0,0 +1,46 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Hooks = exports.HOOKS_ALL_CHAINS_MAX_ROWS = void 0;
4
+ const csv_js_1 = require("../csv.js");
5
+ const base_js_1 = require("./base.js");
6
+ /**
7
+ * Deepest row an all-chains hooks page may reach (`page` × `limit`). The API refuses a deeper page with a 400 and
8
+ * still says `hasMore: true` on the last page it allows, so the iterators stop at the cap. Pass `chainId` to page
9
+ * one chain further.
10
+ */
11
+ exports.HOOKS_ALL_CHAINS_MAX_ROWS = 1_000;
12
+ /** More pages to fetch: the API says so and, across all chains, the next page stays within the cap. */
13
+ function hasMore(query) {
14
+ const allChains = query?.chainId === undefined || query?.chainId === null;
15
+ return (p) => p.pagination.hasMore && (!allChains || (p.pagination.page + 1) * p.pagination.limit <= exports.HOOKS_ALL_CHAINS_MAX_ROWS);
16
+ }
17
+ class Hooks extends base_js_1.Resource {
18
+ /** `GET /v1/hooks`: Uniswap v4 hooks with the TVL, volume and fees of their pools. */
19
+ list(query, options) {
20
+ return this.call('hooks.list', undefined, (0, base_js_1.toQuery)(query), options);
21
+ }
22
+ /**
23
+ * Every page of `list`, fetched as you iterate. Without `chainId` it stops at `HOOKS_ALL_CHAINS_MAX_ROWS` (1,000
24
+ * rows deep), the most the API serves across all chains; pass `chainId` to page further.
25
+ */
26
+ pages(query, options) {
27
+ const [req, paging] = (0, base_js_1.splitOptions)(options);
28
+ return (0, base_js_1.pageIterator)(query, (page) => this.list({ ...query, page }, req), hasMore(query), (p) => p.hooks.length, paging);
29
+ }
30
+ /** Every row of `list`, across pages (at most 1,000 without `chainId`). Each page is a metered request; `break` stops fetching. */
31
+ iterate(query, options) {
32
+ const [req, paging] = (0, base_js_1.splitOptions)(options);
33
+ const pages = this.pages(query, { ...req, ...(paging.maxPages === undefined ? {} : { maxPages: paging.maxPages }) });
34
+ return (0, base_js_1.rowIterator)(pages, (p) => p.hooks, paging);
35
+ }
36
+ /** One page of `list` as CSV (`format=csv`): same filters, paging and unit cost as JSON. */
37
+ exportCsv(query, options) {
38
+ return this.callCsv('hooks.list', (0, base_js_1.toQuery)(query), options);
39
+ }
40
+ /** Every page of `list` as CSV, each with its own header row (at most 1,000 rows without `chainId`). Each page is a metered request. */
41
+ exportCsvPages(query, options) {
42
+ const [req, paging] = (0, base_js_1.splitOptions)(options);
43
+ return (0, base_js_1.pageIterator)(query, (page) => this.exportCsv({ ...query, page }, req), hasMore(query), (p) => ((0, csv_js_1.csvHasRows)(p.csv) ? 1 : 0), paging);
44
+ }
45
+ }
46
+ exports.Hooks = Hooks;
@@ -0,0 +1,23 @@
1
+ import type { APIPromise } from '../api-promise.js';
2
+ import type { RequestOptions } from '../transport.js';
3
+ import type { Chain, PlanList, Protocol, Stats, UnitCostList } from '../types.js';
4
+ import { Resource } from './base.js';
5
+ /** The free, keyless routes. The key is never sent on them, even when the client has one. */
6
+ export declare class Meta extends Resource {
7
+ /** `GET /v1/chains`: the chains served right now, each with its protocols. The live list of valid `chainId`s. */
8
+ chains(options?: RequestOptions): APIPromise<Chain[]>;
9
+ /** `GET /v1/protocols`: the protocols served and the chains each is live on. */
10
+ protocols(options?: RequestOptions): APIPromise<Protocol[]>;
11
+ /** `GET /v1/plans`: the plans on sale, with monthly units, burst limit and prices. */
12
+ plans(options?: RequestOptions): APIPromise<PlanList>;
13
+ /** `GET /v1/stats`: headline counts of everything indexed. */
14
+ stats(options?: RequestOptions): APIPromise<Stats>;
15
+ }
16
+ /** `tw.pricing`: free, keyless. */
17
+ export declare class Pricing extends Resource {
18
+ /**
19
+ * `GET /v1/pricing/units`: what each metered route costs in units, live. Read prices from here; they can change,
20
+ * so the SDK never hard-codes them.
21
+ */
22
+ units(options?: RequestOptions): APIPromise<UnitCostList>;
23
+ }
@@ -0,0 +1,35 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Pricing = exports.Meta = void 0;
4
+ const base_js_1 = require("./base.js");
5
+ /** The free, keyless routes. The key is never sent on them, even when the client has one. */
6
+ class Meta extends base_js_1.Resource {
7
+ /** `GET /v1/chains`: the chains served right now, each with its protocols. The live list of valid `chainId`s. */
8
+ chains(options) {
9
+ return this.call('chains', undefined, undefined, options);
10
+ }
11
+ /** `GET /v1/protocols`: the protocols served and the chains each is live on. */
12
+ protocols(options) {
13
+ return this.call('protocols', undefined, undefined, options);
14
+ }
15
+ /** `GET /v1/plans`: the plans on sale, with monthly units, burst limit and prices. */
16
+ plans(options) {
17
+ return this.call('plans', undefined, undefined, options);
18
+ }
19
+ /** `GET /v1/stats`: headline counts of everything indexed. */
20
+ stats(options) {
21
+ return this.call('stats', undefined, undefined, options);
22
+ }
23
+ }
24
+ exports.Meta = Meta;
25
+ /** `tw.pricing`: free, keyless. */
26
+ class Pricing extends base_js_1.Resource {
27
+ /**
28
+ * `GET /v1/pricing/units`: what each metered route costs in units, live. Read prices from here; they can change,
29
+ * so the SDK never hard-codes them.
30
+ */
31
+ units(options) {
32
+ return this.call('pricing.units', undefined, undefined, options);
33
+ }
34
+ }
35
+ exports.Pricing = Pricing;
@@ -0,0 +1,21 @@
1
+ import type { APIPromise } from '../api-promise.js';
2
+ import { type CsvPage } from '../csv.js';
3
+ import type { RequestOptions } from '../transport.js';
4
+ import type { Charts, PagingOptions, Pool, PoolChartsQuery, PoolDetail, PoolDetailQuery, PoolList, PoolsListQuery, ProtocolKey, RowOf, Shaped, WithRows } from '../types.js';
5
+ import { Resource } from './base.js';
6
+ export declare class Pools extends Resource {
7
+ /** `GET /v1/pools`: a ranked, filtered page of pools. */
8
+ list<Q extends PoolsListQuery = PoolsListQuery>(query?: Q, options?: RequestOptions): APIPromise<WithRows<PoolList, 'pools', Q>>;
9
+ /** Every page of `list`, fetched as you iterate. Starts at `query.page` (default 1). */
10
+ pages<Q extends PoolsListQuery = PoolsListQuery>(query?: Q, options?: RequestOptions & PagingOptions): AsyncGenerator<WithRows<PoolList, 'pools', Q>, void, undefined>;
11
+ /** Every row of `list`, across pages. Each page is a metered request; `break` stops fetching. */
12
+ iterate<Q extends PoolsListQuery = PoolsListQuery>(query?: Q, options?: RequestOptions & PagingOptions): AsyncGenerator<RowOf<Pool, Q>, void, undefined>;
13
+ /** `GET /v1/pools/{chainId}/{protocol}/{poolId}`: one pool. */
14
+ get<Q extends PoolDetailQuery = PoolDetailQuery>(chainId: number, protocol: ProtocolKey, poolId: string, query?: Q, options?: RequestOptions): APIPromise<Shaped<PoolDetail, Q>>;
15
+ /** `GET .../charts`: the pool's time series (`range`: 30d, 60d, 90d, 180d, all). */
16
+ charts<Q extends PoolChartsQuery = PoolChartsQuery>(chainId: number, protocol: ProtocolKey, poolId: string, query?: Q, options?: RequestOptions): APIPromise<Shaped<Charts, Q>>;
17
+ /** One page of `list` as CSV (`format=csv`): same filters, paging and unit cost as JSON. */
18
+ exportCsv(query?: PoolsListQuery, options?: RequestOptions): APIPromise<CsvPage>;
19
+ /** Every page of `list` as CSV, each with its own header row. Each page is a metered request. */
20
+ exportCsvPages(query?: PoolsListQuery, options?: RequestOptions & PagingOptions): AsyncGenerator<CsvPage, void, undefined>;
21
+ }
@@ -0,0 +1,40 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Pools = void 0;
4
+ const csv_js_1 = require("../csv.js");
5
+ const base_js_1 = require("./base.js");
6
+ class Pools extends base_js_1.Resource {
7
+ /** `GET /v1/pools`: a ranked, filtered page of pools. */
8
+ list(query, options) {
9
+ return this.call('pools.list', undefined, (0, base_js_1.toQuery)(query), options);
10
+ }
11
+ /** Every page of `list`, fetched as you iterate. Starts at `query.page` (default 1). */
12
+ pages(query, options) {
13
+ const [req, paging] = (0, base_js_1.splitOptions)(options);
14
+ return (0, base_js_1.pageIterator)(query, (page) => this.list({ ...query, page }, req), (p) => p.pagination.hasMore, (p) => p.pools.length, paging);
15
+ }
16
+ /** Every row of `list`, across pages. Each page is a metered request; `break` stops fetching. */
17
+ iterate(query, options) {
18
+ const [req, paging] = (0, base_js_1.splitOptions)(options);
19
+ const pages = this.pages(query, { ...req, ...(paging.maxPages === undefined ? {} : { maxPages: paging.maxPages }) });
20
+ return (0, base_js_1.rowIterator)(pages, (p) => p.pools, paging);
21
+ }
22
+ /** `GET /v1/pools/{chainId}/{protocol}/{poolId}`: one pool. */
23
+ get(chainId, protocol, poolId, query, options) {
24
+ return this.call('pools.detail', { chainId, protocol, poolId }, (0, base_js_1.toQuery)(query), options);
25
+ }
26
+ /** `GET .../charts`: the pool's time series (`range`: 30d, 60d, 90d, 180d, all). */
27
+ charts(chainId, protocol, poolId, query, options) {
28
+ return this.call('pools.charts', { chainId, protocol, poolId }, (0, base_js_1.toQuery)(query), options);
29
+ }
30
+ /** One page of `list` as CSV (`format=csv`): same filters, paging and unit cost as JSON. */
31
+ exportCsv(query, options) {
32
+ return this.callCsv('pools.list', (0, base_js_1.toQuery)(query), options);
33
+ }
34
+ /** Every page of `list` as CSV, each with its own header row. Each page is a metered request. */
35
+ exportCsvPages(query, options) {
36
+ const [req, paging] = (0, base_js_1.splitOptions)(options);
37
+ return (0, base_js_1.pageIterator)(query, (page) => this.exportCsv({ ...query, page }, req), (p) => p.pagination.hasMore, (p) => ((0, csv_js_1.csvHasRows)(p.csv) ? 1 : 0), paging);
38
+ }
39
+ }
40
+ exports.Pools = Pools;
@@ -0,0 +1,45 @@
1
+ import { APIPromise } from '../api-promise.js';
2
+ import { type CsvPage } from '../csv.js';
3
+ import type { RequestOptions } from '../transport.js';
4
+ import type { PagingOptions, Position, PositionBatch, PositionChartsQuery, PositionDetail, PositionDetailQuery, PositionId, PositionList, PositionsBatchQuery, PositionsListQuery, PositionTransactionsQuery, ProtocolKey, RowOf, Shaped, Charts, Transaction, TransactionsPage, WithRows } from '../types.js';
5
+ import { Resource } from './base.js';
6
+ /** Most ids one `GET /v1/positions/batch` call takes. */
7
+ export declare const POSITION_BATCH_MAX = 100;
8
+ export declare class Positions extends Resource {
9
+ /**
10
+ * `GET /v1/positions`: a ranked, filtered page of positions. The defaults hide closed, risky and small-pool
11
+ * positions; for everything a wallet holds pass `{ owner, status: 'all', minValueUsd: 0, minPoolTvl: 0, includeRisky: true }`.
12
+ */
13
+ list<Q extends PositionsListQuery = PositionsListQuery>(query?: Q, options?: RequestOptions): APIPromise<WithRows<PositionList, 'positions', Q>>;
14
+ /** Every page of `list`, one request per page, fetched as you iterate. Starts at `query.page` (default 1). */
15
+ pages<Q extends PositionsListQuery = PositionsListQuery>(query?: Q, options?: RequestOptions & PagingOptions): AsyncGenerator<WithRows<PositionList, 'positions', Q>, void, undefined>;
16
+ /** Every row of `list`, across pages. Each page is a metered request; `break` stops fetching. */
17
+ iterate<Q extends PositionsListQuery = PositionsListQuery>(query?: Q, options?: RequestOptions & PagingOptions): AsyncGenerator<RowOf<Position, Q>, void, undefined>;
18
+ /**
19
+ * `GET /v1/positions/batch`: up to 100 positions of one chain and protocol in one call, in the order of `ids`
20
+ * (duplicates dropped); ids not found are listed in `missing`. Priced per position returned
21
+ * (`.withMeta()` → `meta.unitsCharged`).
22
+ */
23
+ batch<Q extends PositionsBatchQuery>(query: Q, options?: RequestOptions): APIPromise<WithRows<PositionBatch, 'positions', Q>>;
24
+ /**
25
+ * Any number of ids: `batch` calls of 100, one after another, merged in order. Costs exactly what the separate
26
+ * calls cost (the batch is priced per position). `.withMeta()` gives the last call's metadata with
27
+ * `unitsCharged` and `retries` summed over all calls.
28
+ */
29
+ batchAll<Q extends PositionsBatchQuery>(query: Q, options?: RequestOptions): APIPromise<WithRows<PositionBatch, 'positions', Q>>;
30
+ /** `GET /v1/positions/{chainId}/{protocol}/{positionId}`: one position, with its transactions. */
31
+ get<Q extends PositionDetailQuery = PositionDetailQuery>(chainId: number, protocol: ProtocolKey, positionId: PositionId, query?: Q, options?: RequestOptions): APIPromise<Shaped<PositionDetail, Q>>;
32
+ /** `GET .../transactions`: one page of a position's transactions, newest first. */
33
+ transactions<Q extends PositionTransactionsQuery = PositionTransactionsQuery>(chainId: number, protocol: ProtocolKey, positionId: PositionId, query?: Q, options?: RequestOptions): APIPromise<WithRows<TransactionsPage, 'transactions', Q>>;
34
+ /**
35
+ * Every transaction of a position, newest first, following the cursor (`transactionsNextCursor` → `before`).
36
+ * Each page is a metered request.
37
+ */
38
+ iterateTransactions<Q extends PositionTransactionsQuery = PositionTransactionsQuery>(chainId: number, protocol: ProtocolKey, positionId: PositionId, query?: Q, options?: RequestOptions & PagingOptions): AsyncGenerator<RowOf<Transaction, Q>, void, undefined>;
39
+ /** `GET .../charts`: the position's and its pool's time series (`range`: 30d, 60d, 90d, 180d, all). */
40
+ charts<Q extends PositionChartsQuery = PositionChartsQuery>(chainId: number, protocol: ProtocolKey, positionId: PositionId, query?: Q, options?: RequestOptions): APIPromise<Shaped<Charts, Q>>;
41
+ /** One page of `list` as CSV (`format=csv`): same filters, paging and unit cost as JSON. */
42
+ exportCsv(query?: PositionsListQuery, options?: RequestOptions): APIPromise<CsvPage>;
43
+ /** Every page of `list` as CSV, each with its own header row. Each page is a metered request. */
44
+ exportCsvPages(query?: PositionsListQuery, options?: RequestOptions & PagingOptions): AsyncGenerator<CsvPage, void, undefined>;
45
+ }
@@ -0,0 +1,133 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Positions = exports.POSITION_BATCH_MAX = void 0;
4
+ const api_promise_js_1 = require("../api-promise.js");
5
+ const csv_js_1 = require("../csv.js");
6
+ const base_js_1 = require("./base.js");
7
+ /** Most ids one `GET /v1/positions/batch` call takes. */
8
+ exports.POSITION_BATCH_MAX = 100;
9
+ function idList(ids) {
10
+ const raw = typeof ids === 'string' ? ids.split(',') : ids.map(String);
11
+ const seen = new Set();
12
+ const out = [];
13
+ for (const id of raw.map((s) => s.trim()).filter(Boolean)) {
14
+ if (!seen.has(id)) {
15
+ seen.add(id);
16
+ out.push(id);
17
+ }
18
+ }
19
+ return out;
20
+ }
21
+ class Positions extends base_js_1.Resource {
22
+ /**
23
+ * `GET /v1/positions`: a ranked, filtered page of positions. The defaults hide closed, risky and small-pool
24
+ * positions; for everything a wallet holds pass `{ owner, status: 'all', minValueUsd: 0, minPoolTvl: 0, includeRisky: true }`.
25
+ */
26
+ list(query, options) {
27
+ return this.call('positions.list', undefined, (0, base_js_1.toQuery)(query), options);
28
+ }
29
+ /** Every page of `list`, one request per page, fetched as you iterate. Starts at `query.page` (default 1). */
30
+ pages(query, options) {
31
+ const [req, paging] = (0, base_js_1.splitOptions)(options);
32
+ return (0, base_js_1.pageIterator)(query, (page) => this.list({ ...query, page }, req), (p) => p.pagination.hasMore, (p) => p.positions.length, paging);
33
+ }
34
+ /** Every row of `list`, across pages. Each page is a metered request; `break` stops fetching. */
35
+ iterate(query, options) {
36
+ const [req, paging] = (0, base_js_1.splitOptions)(options);
37
+ const pages = this.pages(query, { ...req, ...(paging.maxPages === undefined ? {} : { maxPages: paging.maxPages }) });
38
+ return (0, base_js_1.rowIterator)(pages, (p) => p.positions, paging);
39
+ }
40
+ /**
41
+ * `GET /v1/positions/batch`: up to 100 positions of one chain and protocol in one call, in the order of `ids`
42
+ * (duplicates dropped); ids not found are listed in `missing`. Priced per position returned
43
+ * (`.withMeta()` → `meta.unitsCharged`).
44
+ */
45
+ batch(query, options) {
46
+ const ids = idList(query.ids);
47
+ if (ids.length === 0)
48
+ return new api_promise_js_1.APIPromise(Promise.reject(new TypeError('positions.batch: `ids` is empty')));
49
+ return this.call('positions.batch', undefined, (0, base_js_1.toQuery)(query, { ids: ids.join(',') }), options);
50
+ }
51
+ /**
52
+ * Any number of ids: `batch` calls of 100, one after another, merged in order. Costs exactly what the separate
53
+ * calls cost (the batch is priced per position). `.withMeta()` gives the last call's metadata with
54
+ * `unitsCharged` and `retries` summed over all calls.
55
+ */
56
+ batchAll(query, options) {
57
+ const ids = idList(query.ids);
58
+ if (ids.length === 0)
59
+ return new api_promise_js_1.APIPromise(Promise.reject(new TypeError('positions.batchAll: `ids` is empty')));
60
+ const run = async () => {
61
+ let merged;
62
+ let meta;
63
+ let units = 0;
64
+ let unitsKnown = true;
65
+ let retries = 0;
66
+ for (let i = 0; i < ids.length; i += exports.POSITION_BATCH_MAX) {
67
+ const chunk = ids.slice(i, i + exports.POSITION_BATCH_MAX);
68
+ const r = await this.batch({ ...query, ids: chunk }, options).withMeta();
69
+ const data = r.data;
70
+ if (merged === undefined) {
71
+ merged = { ...data, positions: [...data.positions], missing: [...data.missing] };
72
+ }
73
+ else {
74
+ merged.positions.push(...data.positions);
75
+ merged.missing.push(...data.missing);
76
+ }
77
+ if (r.meta.unitsCharged === undefined)
78
+ unitsKnown = false;
79
+ else
80
+ units += r.meta.unitsCharged;
81
+ retries += r.meta.retries;
82
+ meta = r.meta;
83
+ }
84
+ return { data: merged, meta: { ...meta, unitsCharged: unitsKnown ? units : undefined, retries } };
85
+ };
86
+ return new api_promise_js_1.APIPromise(run());
87
+ }
88
+ /** `GET /v1/positions/{chainId}/{protocol}/{positionId}`: one position, with its transactions. */
89
+ get(chainId, protocol, positionId, query, options) {
90
+ return this.call('positions.detail', { chainId, protocol, positionId }, (0, base_js_1.toQuery)(query), options);
91
+ }
92
+ /** `GET .../transactions`: one page of a position's transactions, newest first. */
93
+ transactions(chainId, protocol, positionId, query, options) {
94
+ return this.call('positions.transactions', { chainId, protocol, positionId }, (0, base_js_1.toQuery)(query), options);
95
+ }
96
+ /**
97
+ * Every transaction of a position, newest first, following the cursor (`transactionsNextCursor` → `before`).
98
+ * Each page is a metered request.
99
+ */
100
+ async *iterateTransactions(chainId, protocol, positionId, query, options) {
101
+ const [req, paging] = (0, base_js_1.splitOptions)(options);
102
+ if (paging.maxItems !== undefined && paging.maxItems <= 0)
103
+ return;
104
+ let before = query?.before;
105
+ let items = 0;
106
+ for (let n = 0; paging.maxPages === undefined || n < paging.maxPages; n++) {
107
+ const page = (await this.transactions(chainId, protocol, positionId, { ...query, before }, req));
108
+ for (const t of page.transactions) {
109
+ yield t;
110
+ if (paging.maxItems !== undefined && ++items >= paging.maxItems)
111
+ return;
112
+ }
113
+ const next = page.transactionsNextCursor;
114
+ if (!next || page.transactions.length === 0 || next === before)
115
+ return;
116
+ before = next;
117
+ }
118
+ }
119
+ /** `GET .../charts`: the position's and its pool's time series (`range`: 30d, 60d, 90d, 180d, all). */
120
+ charts(chainId, protocol, positionId, query, options) {
121
+ return this.call('positions.charts', { chainId, protocol, positionId }, (0, base_js_1.toQuery)(query), options);
122
+ }
123
+ /** One page of `list` as CSV (`format=csv`): same filters, paging and unit cost as JSON. */
124
+ exportCsv(query, options) {
125
+ return this.callCsv('positions.list', (0, base_js_1.toQuery)(query), options);
126
+ }
127
+ /** Every page of `list` as CSV, each with its own header row. Each page is a metered request. */
128
+ exportCsvPages(query, options) {
129
+ const [req, paging] = (0, base_js_1.splitOptions)(options);
130
+ return (0, base_js_1.pageIterator)(query, (page) => this.exportCsv({ ...query, page }, req), (p) => p.pagination.hasMore, (p) => ((0, csv_js_1.csvHasRows)(p.csv) ? 1 : 0), paging);
131
+ }
132
+ }
133
+ exports.Positions = Positions;
@@ -0,0 +1,13 @@
1
+ import type { APIPromise } from '../api-promise.js';
2
+ import type { RequestOptions } from '../transport.js';
3
+ import type { PagingOptions, Pool, RowOf, TokenLookup, TokenQuery, WithRows } from '../types.js';
4
+ import { Resource } from './base.js';
5
+ export declare class Tokens extends Resource {
6
+ /**
7
+ * `GET /v1/tokens/{chainId}/{address}`: one token's USD price and where it came from, what the API knows about
8
+ * it, its risk flags, and a page of the pools holding it. The chain's native token is the zero address.
9
+ */
10
+ get<Q extends TokenQuery = TokenQuery>(chainId: number, address: string, query?: Q, options?: RequestOptions): APIPromise<WithRows<TokenLookup, 'pools', Q>>;
11
+ /** Every pool holding the token, across pages. Each page is a metered request; `break` stops fetching. */
12
+ iteratePools<Q extends TokenQuery = TokenQuery>(chainId: number, address: string, query?: Q, options?: RequestOptions & PagingOptions): AsyncGenerator<RowOf<Pool, Q>, void, undefined>;
13
+ }
@@ -0,0 +1,20 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Tokens = void 0;
4
+ const base_js_1 = require("./base.js");
5
+ class Tokens extends base_js_1.Resource {
6
+ /**
7
+ * `GET /v1/tokens/{chainId}/{address}`: one token's USD price and where it came from, what the API knows about
8
+ * it, its risk flags, and a page of the pools holding it. The chain's native token is the zero address.
9
+ */
10
+ get(chainId, address, query, options) {
11
+ return this.call('tokens.detail', { chainId, address }, (0, base_js_1.toQuery)(query), options);
12
+ }
13
+ /** Every pool holding the token, across pages. Each page is a metered request; `break` stops fetching. */
14
+ iteratePools(chainId, address, query, options) {
15
+ const [req, paging] = (0, base_js_1.splitOptions)(options);
16
+ const pages = (0, base_js_1.pageIterator)(query, (page) => this.get(chainId, address, { ...query, page }, req), (p) => p.pagination.hasMore, (p) => p.pools.length, paging.maxPages === undefined ? {} : { maxPages: paging.maxPages });
17
+ return (0, base_js_1.rowIterator)(pages, (p) => p.pools, paging);
18
+ }
19
+ }
20
+ exports.Tokens = Tokens;
@@ -0,0 +1,11 @@
1
+ import type { APIPromise } from '../api-promise.js';
2
+ import type { RequestOptions } from '../transport.js';
3
+ import type { WalletSummary, WalletSummaryQuery } from '../types.js';
4
+ import { Resource } from './base.js';
5
+ export declare class Wallets extends Resource {
6
+ /**
7
+ * `GET /v1/wallets/{address}`: one wallet's positions summed across every chain (or one `chainId`): value,
8
+ * uncollected fees, PnL and counts, in total and per chain. A wallet with no positions is zeros, not a 404.
9
+ */
10
+ summary(address: string, query?: WalletSummaryQuery, options?: RequestOptions): APIPromise<WalletSummary>;
11
+ }
@@ -0,0 +1,14 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Wallets = void 0;
4
+ const base_js_1 = require("./base.js");
5
+ class Wallets extends base_js_1.Resource {
6
+ /**
7
+ * `GET /v1/wallets/{address}`: one wallet's positions summed across every chain (or one `chainId`): value,
8
+ * uncollected fees, PnL and counts, in total and per chain. A wallet with no positions is zeros, not a 404.
9
+ */
10
+ summary(address, query, options) {
11
+ return this.call('wallets.summary', { address }, (0, base_js_1.toQuery)(query), options);
12
+ }
13
+ }
14
+ exports.Wallets = Wallets;