@secondlayer/sdk 6.26.1 → 6.27.1
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 +281 -1
- package/dist/index.js +190 -44
- package/dist/index.js.map +5 -5
- package/dist/streams/index.js +10 -1
- package/dist/streams/index.js.map +3 -3
- package/dist/subgraphs/index.d.ts +280 -0
- package/dist/subgraphs/index.js +190 -44
- package/dist/subgraphs/index.js.map +5 -5
- package/package.json +2 -4
package/dist/subgraphs/index.js
CHANGED
|
@@ -80,6 +80,15 @@ class BaseClient {
|
|
|
80
80
|
}
|
|
81
81
|
return response.json();
|
|
82
82
|
}
|
|
83
|
+
async requestOrNull(method, path, body) {
|
|
84
|
+
try {
|
|
85
|
+
return await this.request(method, path, body);
|
|
86
|
+
} catch (err) {
|
|
87
|
+
if (err instanceof ApiError && err.status === 404)
|
|
88
|
+
return null;
|
|
89
|
+
throw err;
|
|
90
|
+
}
|
|
91
|
+
}
|
|
83
92
|
async requestText(method, path, body) {
|
|
84
93
|
const response = await this.fetchResponse(method, path, body);
|
|
85
94
|
return response.text();
|
|
@@ -424,14 +433,8 @@ class Contracts extends BaseClient {
|
|
|
424
433
|
})}`);
|
|
425
434
|
}
|
|
426
435
|
async get(contractId, opts = {}) {
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
return contract;
|
|
430
|
-
} catch (err) {
|
|
431
|
-
if (err instanceof ApiError && err.status === 404)
|
|
432
|
-
return null;
|
|
433
|
-
throw err;
|
|
434
|
-
}
|
|
436
|
+
const result = await this.requestOrNull("GET", `/v1/contracts/${encodeURIComponent(contractId)}${opts.includeAbi ? "?include=abi" : ""}`);
|
|
437
|
+
return result?.contract ?? null;
|
|
435
438
|
}
|
|
436
439
|
}
|
|
437
440
|
|
|
@@ -732,13 +735,7 @@ class Index extends BaseClient {
|
|
|
732
735
|
return this.request("GET", "/v1/index");
|
|
733
736
|
}
|
|
734
737
|
async printSchema(contractId) {
|
|
735
|
-
|
|
736
|
-
return await this.request("GET", `/v1/index/contracts/${encodeURIComponent(contractId)}/print-schema`);
|
|
737
|
-
} catch (err) {
|
|
738
|
-
if (err instanceof ApiError && err.status === 404)
|
|
739
|
-
return null;
|
|
740
|
-
throw err;
|
|
741
|
-
}
|
|
738
|
+
return this.requestOrNull("GET", `/v1/index/contracts/${encodeURIComponent(contractId)}/print-schema`);
|
|
742
739
|
}
|
|
743
740
|
ftTransfers = Object.assign((params = {}) => this.listFtTransfers(params), {
|
|
744
741
|
list: (params = {}) => this.listFtTransfers(params),
|
|
@@ -811,6 +808,30 @@ class Index extends BaseClient {
|
|
|
811
808
|
walk: (params = {}) => this.walkMempool(params),
|
|
812
809
|
get: (txId) => this.getMempoolTx(txId)
|
|
813
810
|
};
|
|
811
|
+
sbtc = {
|
|
812
|
+
deposits: {
|
|
813
|
+
list: (params = {}) => this.listSbtcDeposits(params),
|
|
814
|
+
walk: (params = {}) => this.walkSbtcDeposits(params),
|
|
815
|
+
get: (bitcoinTxid) => this.getSbtcDeposit(bitcoinTxid)
|
|
816
|
+
},
|
|
817
|
+
withdrawals: {
|
|
818
|
+
list: (params = {}) => this.listSbtcWithdrawals(params),
|
|
819
|
+
walk: (params = {}) => this.walkSbtcWithdrawals(params),
|
|
820
|
+
get: (requestId) => this.getSbtcWithdrawal(requestId)
|
|
821
|
+
},
|
|
822
|
+
events: {
|
|
823
|
+
list: (params = {}) => this.listSbtcEvents(params),
|
|
824
|
+
walk: (params = {}) => this.walkSbtcEvents(params)
|
|
825
|
+
},
|
|
826
|
+
summary: () => this.getSbtcSummary()
|
|
827
|
+
};
|
|
828
|
+
pox = {
|
|
829
|
+
cycles: {
|
|
830
|
+
list: (params = {}) => this.listPoxCycles(params),
|
|
831
|
+
walk: (params = {}) => this.walkPoxCycles(params),
|
|
832
|
+
get: (rewardCycle) => this.getPoxCycle(rewardCycle)
|
|
833
|
+
}
|
|
834
|
+
};
|
|
814
835
|
async listFtTransfers(params = {}) {
|
|
815
836
|
return this.request("GET", `/v1/index/ft-transfers${buildQuery({
|
|
816
837
|
cursor: params.cursor,
|
|
@@ -1009,13 +1030,7 @@ class Index extends BaseClient {
|
|
|
1009
1030
|
})}`);
|
|
1010
1031
|
}
|
|
1011
1032
|
async getBlock(ref) {
|
|
1012
|
-
|
|
1013
|
-
return await this.request("GET", `/v1/index/blocks/${encodeURIComponent(String(ref))}`);
|
|
1014
|
-
} catch (err) {
|
|
1015
|
-
if (err instanceof ApiError && err.status === 404)
|
|
1016
|
-
return null;
|
|
1017
|
-
throw err;
|
|
1018
|
-
}
|
|
1033
|
+
return this.requestOrNull("GET", `/v1/index/blocks/${encodeURIComponent(String(ref))}`);
|
|
1019
1034
|
}
|
|
1020
1035
|
async* walkBlocks(params = {}) {
|
|
1021
1036
|
const batchSize = params.batchSize ?? 200;
|
|
@@ -1055,22 +1070,10 @@ class Index extends BaseClient {
|
|
|
1055
1070
|
})}`);
|
|
1056
1071
|
}
|
|
1057
1072
|
async getTransaction(txId) {
|
|
1058
|
-
|
|
1059
|
-
return await this.request("GET", `/v1/index/transactions/${encodeURIComponent(txId)}`);
|
|
1060
|
-
} catch (err) {
|
|
1061
|
-
if (err instanceof ApiError && err.status === 404)
|
|
1062
|
-
return null;
|
|
1063
|
-
throw err;
|
|
1064
|
-
}
|
|
1073
|
+
return this.requestOrNull("GET", `/v1/index/transactions/${encodeURIComponent(txId)}`);
|
|
1065
1074
|
}
|
|
1066
1075
|
async getTransactionProof(txId) {
|
|
1067
|
-
|
|
1068
|
-
return await this.request("GET", `/v1/index/transactions/${encodeURIComponent(txId)}/proof`);
|
|
1069
|
-
} catch (err) {
|
|
1070
|
-
if (err instanceof ApiError && err.status === 404)
|
|
1071
|
-
return null;
|
|
1072
|
-
throw err;
|
|
1073
|
-
}
|
|
1076
|
+
return this.requestOrNull("GET", `/v1/index/transactions/${encodeURIComponent(txId)}/proof`);
|
|
1074
1077
|
}
|
|
1075
1078
|
async* walkTransactions(params = {}) {
|
|
1076
1079
|
const batchSize = params.batchSize ?? 200;
|
|
@@ -1145,13 +1148,7 @@ class Index extends BaseClient {
|
|
|
1145
1148
|
})}`);
|
|
1146
1149
|
}
|
|
1147
1150
|
async getMempoolTx(txId) {
|
|
1148
|
-
|
|
1149
|
-
return await this.request("GET", `/v1/index/mempool/${encodeURIComponent(txId)}`);
|
|
1150
|
-
} catch (err) {
|
|
1151
|
-
if (err instanceof ApiError && err.status === 404)
|
|
1152
|
-
return null;
|
|
1153
|
-
throw err;
|
|
1154
|
-
}
|
|
1151
|
+
return this.requestOrNull("GET", `/v1/index/mempool/${encodeURIComponent(txId)}`);
|
|
1155
1152
|
}
|
|
1156
1153
|
async* walkMempool(params = {}) {
|
|
1157
1154
|
const batchSize = params.batchSize ?? 200;
|
|
@@ -1177,6 +1174,155 @@ class Index extends BaseClient {
|
|
|
1177
1174
|
firstPage = false;
|
|
1178
1175
|
}
|
|
1179
1176
|
}
|
|
1177
|
+
async listSbtcDeposits(params = {}) {
|
|
1178
|
+
return this.request("GET", `/v1/index/sbtc/deposits${buildQuery({
|
|
1179
|
+
cursor: params.cursor,
|
|
1180
|
+
from_cursor: params.fromCursor,
|
|
1181
|
+
limit: params.limit,
|
|
1182
|
+
confirmed: params.confirmed,
|
|
1183
|
+
sender: params.sender,
|
|
1184
|
+
bitcoin_txid: params.bitcoinTxid,
|
|
1185
|
+
from_height: params.fromHeight,
|
|
1186
|
+
to_height: params.toHeight
|
|
1187
|
+
})}`);
|
|
1188
|
+
}
|
|
1189
|
+
async* walkSbtcDeposits(params = {}) {
|
|
1190
|
+
const batchSize = params.batchSize ?? 200;
|
|
1191
|
+
let cursor = params.cursor ?? params.fromCursor ?? null;
|
|
1192
|
+
let firstPage = true;
|
|
1193
|
+
while (!params.signal?.aborted) {
|
|
1194
|
+
const envelope = await this.listSbtcDeposits({
|
|
1195
|
+
...params,
|
|
1196
|
+
limit: batchSize,
|
|
1197
|
+
cursor: firstPage ? params.cursor : cursor,
|
|
1198
|
+
fromCursor: firstPage ? params.fromCursor : undefined,
|
|
1199
|
+
fromHeight: firstPage ? firstWalkFromHeight(params) : undefined
|
|
1200
|
+
});
|
|
1201
|
+
for (const deposit of envelope.deposits) {
|
|
1202
|
+
if (params.signal?.aborted)
|
|
1203
|
+
return;
|
|
1204
|
+
yield deposit;
|
|
1205
|
+
}
|
|
1206
|
+
const nextCursor = envelope.next_cursor;
|
|
1207
|
+
if (!nextCursor || nextCursor === cursor || envelope.deposits.length < batchSize) {
|
|
1208
|
+
return;
|
|
1209
|
+
}
|
|
1210
|
+
cursor = nextCursor;
|
|
1211
|
+
firstPage = false;
|
|
1212
|
+
}
|
|
1213
|
+
}
|
|
1214
|
+
async getSbtcDeposit(bitcoinTxid) {
|
|
1215
|
+
return this.requestOrNull("GET", `/v1/index/sbtc/deposits/${encodeURIComponent(bitcoinTxid)}`);
|
|
1216
|
+
}
|
|
1217
|
+
async listSbtcWithdrawals(params = {}) {
|
|
1218
|
+
return this.request("GET", `/v1/index/sbtc/withdrawals${buildQuery({
|
|
1219
|
+
cursor: params.cursor,
|
|
1220
|
+
from_cursor: params.fromCursor,
|
|
1221
|
+
limit: params.limit,
|
|
1222
|
+
confirmed: params.confirmed,
|
|
1223
|
+
status: params.status,
|
|
1224
|
+
sender: params.sender,
|
|
1225
|
+
request_id: params.requestId,
|
|
1226
|
+
from_height: params.fromHeight,
|
|
1227
|
+
to_height: params.toHeight
|
|
1228
|
+
})}`);
|
|
1229
|
+
}
|
|
1230
|
+
async* walkSbtcWithdrawals(params = {}) {
|
|
1231
|
+
const batchSize = params.batchSize ?? 200;
|
|
1232
|
+
let cursor = params.cursor ?? params.fromCursor ?? null;
|
|
1233
|
+
let firstPage = true;
|
|
1234
|
+
while (!params.signal?.aborted) {
|
|
1235
|
+
const envelope = await this.listSbtcWithdrawals({
|
|
1236
|
+
...params,
|
|
1237
|
+
limit: batchSize,
|
|
1238
|
+
cursor: firstPage ? params.cursor : cursor,
|
|
1239
|
+
fromCursor: firstPage ? params.fromCursor : undefined,
|
|
1240
|
+
fromHeight: firstPage ? firstWalkFromHeight(params) : undefined
|
|
1241
|
+
});
|
|
1242
|
+
for (const withdrawal of envelope.withdrawals) {
|
|
1243
|
+
if (params.signal?.aborted)
|
|
1244
|
+
return;
|
|
1245
|
+
yield withdrawal;
|
|
1246
|
+
}
|
|
1247
|
+
const nextCursor = envelope.next_cursor;
|
|
1248
|
+
if (!nextCursor || nextCursor === cursor || envelope.withdrawals.length < batchSize) {
|
|
1249
|
+
return;
|
|
1250
|
+
}
|
|
1251
|
+
cursor = nextCursor;
|
|
1252
|
+
firstPage = false;
|
|
1253
|
+
}
|
|
1254
|
+
}
|
|
1255
|
+
async getSbtcWithdrawal(requestId) {
|
|
1256
|
+
return this.requestOrNull("GET", `/v1/index/sbtc/withdrawals/${requestId}`);
|
|
1257
|
+
}
|
|
1258
|
+
async listSbtcEvents(params = {}) {
|
|
1259
|
+
return this.request("GET", `/v1/index/sbtc/events${buildQuery({
|
|
1260
|
+
cursor: params.cursor,
|
|
1261
|
+
from_cursor: params.fromCursor,
|
|
1262
|
+
limit: params.limit,
|
|
1263
|
+
confirmed: params.confirmed,
|
|
1264
|
+
topic: params.topic,
|
|
1265
|
+
sender: params.sender,
|
|
1266
|
+
request_id: params.requestId,
|
|
1267
|
+
bitcoin_txid: params.bitcoinTxid,
|
|
1268
|
+
from_height: params.fromHeight,
|
|
1269
|
+
to_height: params.toHeight
|
|
1270
|
+
})}`);
|
|
1271
|
+
}
|
|
1272
|
+
async* walkSbtcEvents(params = {}) {
|
|
1273
|
+
const batchSize = params.batchSize ?? 200;
|
|
1274
|
+
let cursor = params.cursor ?? params.fromCursor ?? null;
|
|
1275
|
+
let firstPage = true;
|
|
1276
|
+
while (!params.signal?.aborted) {
|
|
1277
|
+
const envelope = await this.listSbtcEvents({
|
|
1278
|
+
...params,
|
|
1279
|
+
limit: batchSize,
|
|
1280
|
+
cursor: firstPage ? params.cursor : cursor,
|
|
1281
|
+
fromCursor: firstPage ? params.fromCursor : undefined,
|
|
1282
|
+
fromHeight: firstPage ? firstWalkFromHeight(params) : undefined
|
|
1283
|
+
});
|
|
1284
|
+
for (const event of envelope.events) {
|
|
1285
|
+
if (params.signal?.aborted)
|
|
1286
|
+
return;
|
|
1287
|
+
yield event;
|
|
1288
|
+
}
|
|
1289
|
+
const nextCursor = envelope.next_cursor;
|
|
1290
|
+
if (!nextCursor || nextCursor === cursor || envelope.events.length < batchSize) {
|
|
1291
|
+
return;
|
|
1292
|
+
}
|
|
1293
|
+
cursor = nextCursor;
|
|
1294
|
+
firstPage = false;
|
|
1295
|
+
}
|
|
1296
|
+
}
|
|
1297
|
+
async getSbtcSummary() {
|
|
1298
|
+
return this.request("GET", "/v1/index/sbtc/summary");
|
|
1299
|
+
}
|
|
1300
|
+
async listPoxCycles(params = {}) {
|
|
1301
|
+
return this.request("GET", `/v1/index/pox/cycles${buildQuery({
|
|
1302
|
+
cursor: params.cursor,
|
|
1303
|
+
limit: params.limit
|
|
1304
|
+
})}`);
|
|
1305
|
+
}
|
|
1306
|
+
async* walkPoxCycles(params = {}) {
|
|
1307
|
+
const batchSize = params.batchSize ?? 100;
|
|
1308
|
+
let cursor = params.cursor ?? null;
|
|
1309
|
+
while (!params.signal?.aborted) {
|
|
1310
|
+
const envelope = await this.listPoxCycles({ cursor, limit: batchSize });
|
|
1311
|
+
for (const cycle of envelope.cycles) {
|
|
1312
|
+
if (params.signal?.aborted)
|
|
1313
|
+
return;
|
|
1314
|
+
yield cycle;
|
|
1315
|
+
}
|
|
1316
|
+
const nextCursor = envelope.next_cursor;
|
|
1317
|
+
if (nextCursor === null || nextCursor === cursor || envelope.cycles.length < batchSize) {
|
|
1318
|
+
return;
|
|
1319
|
+
}
|
|
1320
|
+
cursor = nextCursor;
|
|
1321
|
+
}
|
|
1322
|
+
}
|
|
1323
|
+
async getPoxCycle(rewardCycle) {
|
|
1324
|
+
return this.requestOrNull("GET", `/v1/index/pox/cycles/${rewardCycle}`);
|
|
1325
|
+
}
|
|
1180
1326
|
}
|
|
1181
1327
|
|
|
1182
1328
|
// src/projects/client.ts
|
|
@@ -1833,5 +1979,5 @@ export {
|
|
|
1833
1979
|
Subgraphs
|
|
1834
1980
|
};
|
|
1835
1981
|
|
|
1836
|
-
//# debugId=
|
|
1982
|
+
//# debugId=31BD90E12F7B1B3B64756E2164756E21
|
|
1837
1983
|
//# sourceMappingURL=index.js.map
|