@secondlayer/sdk 6.1.0 → 6.2.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.
- package/dist/index.d.ts +172 -129
- package/dist/index.js +142 -120
- package/dist/index.js.map +6 -5
- package/dist/subgraphs/index.d.ts +166 -0
- package/dist/subgraphs/index.js +141 -1
- package/dist/subgraphs/index.js.map +6 -4
- package/package.json +1 -1
|
@@ -105,6 +105,170 @@ declare class Subgraphs extends BaseClient {
|
|
|
105
105
|
private createTableClient;
|
|
106
106
|
}
|
|
107
107
|
import { InferSubgraphClient as InferSubgraphClient2 } from "@secondlayer/subgraphs";
|
|
108
|
+
/**
|
|
109
|
+
* Typed client for the contract-discovery API (`GET /v1/contracts`).
|
|
110
|
+
*
|
|
111
|
+
* "Find all contracts conforming to a trait" — backed by the contract registry:
|
|
112
|
+
* `declared` traits parsed from Clarity source, `inferred` standards from static
|
|
113
|
+
* ABI shape-matching. Anonymous public read. `trait` is required; the ABI blob is
|
|
114
|
+
* omitted unless `include: "abi"` is passed.
|
|
115
|
+
*/
|
|
116
|
+
/** Whether a trait match must be declared in source, inferred from ABI, or either. */
|
|
117
|
+
type ContractConformance = "declared" | "inferred" | "any";
|
|
118
|
+
interface ContractsListParams {
|
|
119
|
+
/** Required. Trait identifier to match (e.g. "sip-010", or a fully-qualified trait). */
|
|
120
|
+
trait: string;
|
|
121
|
+
/** Match source. Defaults to "any" server-side. */
|
|
122
|
+
conformance?: ContractConformance;
|
|
123
|
+
/** Set to "abi" to include the full ABI blob in each row. */
|
|
124
|
+
include?: "abi";
|
|
125
|
+
/** Page size, 1–500 (default 100 server-side). */
|
|
126
|
+
limit?: number;
|
|
127
|
+
/** Opaque cursor from a prior response's `next_cursor`. */
|
|
128
|
+
cursor?: string;
|
|
129
|
+
}
|
|
130
|
+
interface ContractSummary {
|
|
131
|
+
contract_id: string;
|
|
132
|
+
deployer: string;
|
|
133
|
+
block_height: number;
|
|
134
|
+
declared_traits: string[] | null;
|
|
135
|
+
inferred_standards: string[] | null;
|
|
136
|
+
abi_status: string;
|
|
137
|
+
/** Present only when `include: "abi"` was requested. */
|
|
138
|
+
abi?: unknown;
|
|
139
|
+
}
|
|
140
|
+
interface ContractsEnvelope {
|
|
141
|
+
contracts: ContractSummary[];
|
|
142
|
+
next_cursor: string | null;
|
|
143
|
+
}
|
|
144
|
+
declare class Contracts extends BaseClient {
|
|
145
|
+
constructor(options?: Partial<SecondLayerOptions>);
|
|
146
|
+
/** Find contracts conforming to `trait`. `trait` is required (server 400s without it). */
|
|
147
|
+
list(params: ContractsListParams): Promise<ContractsEnvelope>;
|
|
148
|
+
}
|
|
149
|
+
/**
|
|
150
|
+
* Typed client for the Foundation Datasets REST API (`/v1/datasets/*`).
|
|
151
|
+
*
|
|
152
|
+
* Most datasets are cursor-paginated event lists with a uniform `list`/`walk`
|
|
153
|
+
* surface; a few (bns names/namespaces/resolve, network-health) are
|
|
154
|
+
* offset/single-object/summary and get bespoke methods. Query params are typed
|
|
155
|
+
* per dataset; rows are `DatasetRow` (JSON) in v1 — per-dataset row interfaces
|
|
156
|
+
* are a fast-follow.
|
|
157
|
+
*/
|
|
158
|
+
/** A dataset row — flat JSON object. Per-dataset interfaces are a follow-up. */
|
|
159
|
+
type DatasetRow = Record<string, unknown>;
|
|
160
|
+
/** Filters shared by every cursor-paginated dataset. */
|
|
161
|
+
interface CursorListParams {
|
|
162
|
+
cursor?: string;
|
|
163
|
+
limit?: number;
|
|
164
|
+
fromBlock?: number;
|
|
165
|
+
toBlock?: number;
|
|
166
|
+
}
|
|
167
|
+
interface CursorEnvelope {
|
|
168
|
+
rows: DatasetRow[];
|
|
169
|
+
next_cursor: string | null;
|
|
170
|
+
tip?: {
|
|
171
|
+
block_height: number
|
|
172
|
+
};
|
|
173
|
+
}
|
|
174
|
+
type RangeFilters = CursorListParams;
|
|
175
|
+
type StxTransfersParams = RangeFilters & {
|
|
176
|
+
sender?: string
|
|
177
|
+
recipient?: string
|
|
178
|
+
};
|
|
179
|
+
type SbtcEventsParams = RangeFilters & {
|
|
180
|
+
topic?: string
|
|
181
|
+
address?: string
|
|
182
|
+
};
|
|
183
|
+
type SbtcTokenEventsParams = RangeFilters & {
|
|
184
|
+
eventType?: string
|
|
185
|
+
sender?: string
|
|
186
|
+
recipient?: string
|
|
187
|
+
};
|
|
188
|
+
type Pox4CallsParams = RangeFilters & {
|
|
189
|
+
functionName?: string
|
|
190
|
+
stacker?: string
|
|
191
|
+
delegateTo?: string
|
|
192
|
+
signerKey?: string
|
|
193
|
+
rewardCycle?: number
|
|
194
|
+
/** Any-role: matches caller OR stacker OR delegate_to. */
|
|
195
|
+
address?: string
|
|
196
|
+
};
|
|
197
|
+
type BurnchainRewardsParams = RangeFilters & {
|
|
198
|
+
/** Filter to one Bitcoin reward address. */
|
|
199
|
+
recipient?: string
|
|
200
|
+
};
|
|
201
|
+
type BurnchainRewardSlotsParams = RangeFilters & {
|
|
202
|
+
/** Filter to one reward-set Bitcoin address. */
|
|
203
|
+
holder?: string
|
|
204
|
+
};
|
|
205
|
+
type BnsEventsParams = RangeFilters & {
|
|
206
|
+
topic?: string
|
|
207
|
+
namespace?: string
|
|
208
|
+
name?: string
|
|
209
|
+
owner?: string
|
|
210
|
+
};
|
|
211
|
+
type BnsNamespaceEventsParams = RangeFilters & {
|
|
212
|
+
status?: string
|
|
213
|
+
namespace?: string
|
|
214
|
+
};
|
|
215
|
+
type BnsMarketplaceEventsParams = RangeFilters & {
|
|
216
|
+
action?: string
|
|
217
|
+
bnsId?: string
|
|
218
|
+
};
|
|
219
|
+
type CursorDataset<P> = {
|
|
220
|
+
list: (params?: P) => Promise<CursorEnvelope>
|
|
221
|
+
walk: (params?: P & {
|
|
222
|
+
batchSize?: number
|
|
223
|
+
signal?: AbortSignal
|
|
224
|
+
}) => AsyncIterable<DatasetRow>
|
|
225
|
+
};
|
|
226
|
+
declare class Datasets extends BaseClient {
|
|
227
|
+
constructor(options?: Partial<SecondLayerOptions>);
|
|
228
|
+
/** Dataset catalog + freshness (the discovery endpoint). */
|
|
229
|
+
listDatasets(): Promise<unknown>;
|
|
230
|
+
/**
|
|
231
|
+
* Generic cursor query by slug — used by the CLI. Params are passed through as
|
|
232
|
+
* REST query keys (snake_case), so callers can use the documented filter names
|
|
233
|
+
* directly. Throws for non-cursor (bespoke) datasets.
|
|
234
|
+
*/
|
|
235
|
+
query(slug: string, params?: Record<string, unknown>): Promise<CursorEnvelope>;
|
|
236
|
+
readonly stxTransfers: CursorDataset<StxTransfersParams>;
|
|
237
|
+
readonly sbtcEvents: CursorDataset<SbtcEventsParams>;
|
|
238
|
+
readonly sbtcTokenEvents: CursorDataset<SbtcTokenEventsParams>;
|
|
239
|
+
readonly pox4Calls: CursorDataset<Pox4CallsParams>;
|
|
240
|
+
readonly burnchainRewards: CursorDataset<BurnchainRewardsParams>;
|
|
241
|
+
readonly burnchainRewardSlots: CursorDataset<BurnchainRewardSlotsParams>;
|
|
242
|
+
readonly bnsEvents: CursorDataset<BnsEventsParams>;
|
|
243
|
+
readonly bnsNamespaceEvents: CursorDataset<BnsNamespaceEventsParams>;
|
|
244
|
+
readonly bnsMarketplaceEvents: CursorDataset<BnsMarketplaceEventsParams>;
|
|
245
|
+
/** BNS names — offset-paginated. */
|
|
246
|
+
bnsNames(params?: {
|
|
247
|
+
namespace?: string
|
|
248
|
+
owner?: string
|
|
249
|
+
limit?: number
|
|
250
|
+
offset?: number
|
|
251
|
+
}): Promise<{
|
|
252
|
+
names: DatasetRow[]
|
|
253
|
+
}>;
|
|
254
|
+
/** All BNS namespaces (no pagination). */
|
|
255
|
+
bnsNamespaces(): Promise<{
|
|
256
|
+
namespaces: DatasetRow[]
|
|
257
|
+
}>;
|
|
258
|
+
/** Resolve a fully-qualified BNS name → single record. */
|
|
259
|
+
bnsResolve(fqn: string): Promise<{
|
|
260
|
+
name: DatasetRow | null
|
|
261
|
+
}>;
|
|
262
|
+
/** Network health summary. */
|
|
263
|
+
networkHealth(): Promise<{
|
|
264
|
+
summary: DatasetRow
|
|
265
|
+
}>;
|
|
266
|
+
private get;
|
|
267
|
+
/** Map camelCase filter fields to snake_case query keys (dropping pagination
|
|
268
|
+
* controls) and build the canonical query suffix. */
|
|
269
|
+
private paramsToQuery;
|
|
270
|
+
private cursorDataset;
|
|
271
|
+
}
|
|
108
272
|
type IndexTip = {
|
|
109
273
|
block_height: number
|
|
110
274
|
lag_seconds: number
|
|
@@ -701,6 +865,8 @@ declare class Subscriptions extends BaseClient {
|
|
|
701
865
|
declare class SecondLayer extends BaseClient {
|
|
702
866
|
readonly streams: StreamsClient;
|
|
703
867
|
readonly index: Index;
|
|
868
|
+
readonly datasets: Datasets;
|
|
869
|
+
readonly contracts: Contracts;
|
|
704
870
|
readonly subgraphs: Subgraphs;
|
|
705
871
|
readonly subscriptions: Subscriptions;
|
|
706
872
|
constructor(options?: Partial<SecondLayerOptions>);
|
package/dist/subgraphs/index.js
CHANGED
|
@@ -324,6 +324,142 @@ class Subgraphs extends BaseClient {
|
|
|
324
324
|
};
|
|
325
325
|
}
|
|
326
326
|
}
|
|
327
|
+
// src/contracts/client.ts
|
|
328
|
+
class Contracts extends BaseClient {
|
|
329
|
+
constructor(options = {}) {
|
|
330
|
+
super(options);
|
|
331
|
+
}
|
|
332
|
+
list(params) {
|
|
333
|
+
return this.request("GET", `/v1/contracts${buildQuery({
|
|
334
|
+
trait: params.trait,
|
|
335
|
+
conformance: params.conformance,
|
|
336
|
+
include: params.include,
|
|
337
|
+
limit: params.limit,
|
|
338
|
+
cursor: params.cursor
|
|
339
|
+
})}`);
|
|
340
|
+
}
|
|
341
|
+
}
|
|
342
|
+
|
|
343
|
+
// src/datasets/client.ts
|
|
344
|
+
var PARAM_KEYS = {
|
|
345
|
+
fromBlock: "from_block",
|
|
346
|
+
toBlock: "to_block",
|
|
347
|
+
functionName: "function_name",
|
|
348
|
+
delegateTo: "delegate_to",
|
|
349
|
+
signerKey: "signer_key",
|
|
350
|
+
rewardCycle: "reward_cycle",
|
|
351
|
+
eventType: "event_type",
|
|
352
|
+
bnsId: "bns_id"
|
|
353
|
+
};
|
|
354
|
+
var CURSOR_SLUGS = {
|
|
355
|
+
"stx-transfers": { path: "stx-transfers", rowKey: "events" },
|
|
356
|
+
"sbtc-events": { path: "sbtc/events", rowKey: "events" },
|
|
357
|
+
"sbtc-token-events": { path: "sbtc/token-events", rowKey: "events" },
|
|
358
|
+
"pox-4-calls": { path: "pox-4/calls", rowKey: "calls" },
|
|
359
|
+
"burnchain-rewards": { path: "burnchain/rewards", rowKey: "rewards" },
|
|
360
|
+
"burnchain-reward-slots": {
|
|
361
|
+
path: "burnchain/reward-slots",
|
|
362
|
+
rowKey: "slots"
|
|
363
|
+
},
|
|
364
|
+
"bns-events": { path: "bns/events", rowKey: "events" },
|
|
365
|
+
"bns-namespace-events": { path: "bns/namespace-events", rowKey: "events" },
|
|
366
|
+
"bns-marketplace-events": {
|
|
367
|
+
path: "bns/marketplace-events",
|
|
368
|
+
rowKey: "events"
|
|
369
|
+
}
|
|
370
|
+
};
|
|
371
|
+
|
|
372
|
+
class Datasets extends BaseClient {
|
|
373
|
+
constructor(options = {}) {
|
|
374
|
+
super(options);
|
|
375
|
+
}
|
|
376
|
+
listDatasets() {
|
|
377
|
+
return this.request("GET", "/v1/datasets");
|
|
378
|
+
}
|
|
379
|
+
async query(slug, params = {}) {
|
|
380
|
+
const d = CURSOR_SLUGS[slug];
|
|
381
|
+
if (!d) {
|
|
382
|
+
throw new Error(`unknown cursor dataset "${slug}" (use one of: ${Object.keys(CURSOR_SLUGS).join(", ")})`);
|
|
383
|
+
}
|
|
384
|
+
const env = await this.get(d.path, this.paramsToQuery(params));
|
|
385
|
+
return {
|
|
386
|
+
rows: env[d.rowKey] ?? [],
|
|
387
|
+
next_cursor: env.next_cursor ?? null,
|
|
388
|
+
tip: env.tip
|
|
389
|
+
};
|
|
390
|
+
}
|
|
391
|
+
stxTransfers = this.cursorDataset("stx-transfers", "events");
|
|
392
|
+
sbtcEvents = this.cursorDataset("sbtc/events", "events");
|
|
393
|
+
sbtcTokenEvents = this.cursorDataset("sbtc/token-events", "events");
|
|
394
|
+
pox4Calls = this.cursorDataset("pox-4/calls", "calls");
|
|
395
|
+
burnchainRewards = this.cursorDataset("burnchain/rewards", "rewards");
|
|
396
|
+
burnchainRewardSlots = this.cursorDataset("burnchain/reward-slots", "slots");
|
|
397
|
+
bnsEvents = this.cursorDataset("bns/events", "events");
|
|
398
|
+
bnsNamespaceEvents = this.cursorDataset("bns/namespace-events", "events");
|
|
399
|
+
bnsMarketplaceEvents = this.cursorDataset("bns/marketplace-events", "events");
|
|
400
|
+
bnsNames(params = {}) {
|
|
401
|
+
return this.get("bns/names", buildQuery({
|
|
402
|
+
namespace: params.namespace,
|
|
403
|
+
owner: params.owner,
|
|
404
|
+
limit: params.limit,
|
|
405
|
+
offset: params.offset
|
|
406
|
+
}));
|
|
407
|
+
}
|
|
408
|
+
bnsNamespaces() {
|
|
409
|
+
return this.get("bns/namespaces", "");
|
|
410
|
+
}
|
|
411
|
+
bnsResolve(fqn) {
|
|
412
|
+
return this.get("bns/resolve", buildQuery({ fqn }));
|
|
413
|
+
}
|
|
414
|
+
networkHealth() {
|
|
415
|
+
return this.get("network-health/summary", "");
|
|
416
|
+
}
|
|
417
|
+
get(path, query) {
|
|
418
|
+
return this.request("GET", `/v1/datasets/${path}${query}`);
|
|
419
|
+
}
|
|
420
|
+
paramsToQuery(params) {
|
|
421
|
+
const mapped = {};
|
|
422
|
+
for (const [k, v] of Object.entries(params)) {
|
|
423
|
+
if (v === undefined || v === null || k === "batchSize" || k === "signal")
|
|
424
|
+
continue;
|
|
425
|
+
mapped[PARAM_KEYS[k] ?? k] = v;
|
|
426
|
+
}
|
|
427
|
+
return buildQuery(mapped);
|
|
428
|
+
}
|
|
429
|
+
cursorDataset(path, rowKey) {
|
|
430
|
+
const list = async (params = {}) => {
|
|
431
|
+
const envelope = await this.get(path, this.paramsToQuery(params));
|
|
432
|
+
return {
|
|
433
|
+
rows: envelope[rowKey] ?? [],
|
|
434
|
+
next_cursor: envelope.next_cursor ?? null,
|
|
435
|
+
tip: envelope.tip
|
|
436
|
+
};
|
|
437
|
+
};
|
|
438
|
+
const walk = async function* (params = {}) {
|
|
439
|
+
const batchSize = params.batchSize ?? 200;
|
|
440
|
+
let cursor = params.cursor ?? null;
|
|
441
|
+
let first = true;
|
|
442
|
+
while (!params.signal?.aborted) {
|
|
443
|
+
const env = await list({
|
|
444
|
+
...params,
|
|
445
|
+
limit: batchSize,
|
|
446
|
+
cursor: first ? params.cursor : cursor ?? undefined
|
|
447
|
+
});
|
|
448
|
+
for (const row of env.rows) {
|
|
449
|
+
if (params.signal?.aborted)
|
|
450
|
+
return;
|
|
451
|
+
yield row;
|
|
452
|
+
}
|
|
453
|
+
if (!env.next_cursor || env.next_cursor === cursor || env.rows.length < batchSize)
|
|
454
|
+
return;
|
|
455
|
+
cursor = env.next_cursor;
|
|
456
|
+
first = false;
|
|
457
|
+
}
|
|
458
|
+
}.bind(this);
|
|
459
|
+
return { list, walk };
|
|
460
|
+
}
|
|
461
|
+
}
|
|
462
|
+
|
|
327
463
|
// src/index-api/client.ts
|
|
328
464
|
function firstWalkFromHeight(params) {
|
|
329
465
|
if (params.fromHeight !== undefined)
|
|
@@ -1017,6 +1153,8 @@ class Subscriptions extends BaseClient {
|
|
|
1017
1153
|
class SecondLayer extends BaseClient {
|
|
1018
1154
|
streams;
|
|
1019
1155
|
index;
|
|
1156
|
+
datasets;
|
|
1157
|
+
contracts;
|
|
1020
1158
|
subgraphs;
|
|
1021
1159
|
subscriptions;
|
|
1022
1160
|
constructor(options = {}) {
|
|
@@ -1027,6 +1165,8 @@ class SecondLayer extends BaseClient {
|
|
|
1027
1165
|
fetchImpl: options.fetchImpl
|
|
1028
1166
|
});
|
|
1029
1167
|
this.index = new Index(options);
|
|
1168
|
+
this.datasets = new Datasets(options);
|
|
1169
|
+
this.contracts = new Contracts(options);
|
|
1030
1170
|
this.subgraphs = new Subgraphs(options);
|
|
1031
1171
|
this.subscriptions = new Subscriptions(options);
|
|
1032
1172
|
}
|
|
@@ -1047,5 +1187,5 @@ export {
|
|
|
1047
1187
|
Subgraphs
|
|
1048
1188
|
};
|
|
1049
1189
|
|
|
1050
|
-
//# debugId=
|
|
1190
|
+
//# debugId=9C60733D992A531964756E2164756E21
|
|
1051
1191
|
//# sourceMappingURL=index.js.map
|