@secretkeylabs/stacks-tools 0.4.0-80a0ce6 → 0.4.0-98de979
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.cjs +343 -270
- package/dist/index.d.cts +83 -54
- package/dist/index.d.ts +83 -54
- package/dist/index.js +343 -270
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -144,37 +144,86 @@ async function balances(opts) {
|
|
|
144
144
|
return success(validationResult.output);
|
|
145
145
|
}
|
|
146
146
|
|
|
147
|
-
// src/stacks-api/
|
|
147
|
+
// src/stacks-api/accounts/latest-nonce.ts
|
|
148
148
|
var v2 = __toESM(require("valibot"), 1);
|
|
149
|
-
var
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
149
|
+
var responseSchema2 = v2.object({
|
|
150
|
+
last_mempool_tx_nonce: v2.nullable(v2.number()),
|
|
151
|
+
last_executed_tx_nonce: v2.nullable(v2.number()),
|
|
152
|
+
possible_next_nonce: v2.number(),
|
|
153
|
+
detected_missing_nonces: v2.array(v2.number()),
|
|
154
|
+
detected_mempool_nonces: v2.array(v2.number())
|
|
154
155
|
});
|
|
156
|
+
async function latestNonce(opts) {
|
|
157
|
+
const init = {};
|
|
158
|
+
if (opts.apiKeyConfig) {
|
|
159
|
+
init.headers = {
|
|
160
|
+
[opts.apiKeyConfig.header]: opts.apiKeyConfig.key
|
|
161
|
+
};
|
|
162
|
+
}
|
|
163
|
+
const endpoint = `${opts.baseUrl}/extended/v1/address/${opts.principal}/nonces`;
|
|
164
|
+
const res = await fetch(endpoint, init);
|
|
165
|
+
if (!res.ok) {
|
|
166
|
+
return error({
|
|
167
|
+
name: "FetchLatestNonceError",
|
|
168
|
+
message: "Failed to fetch latest nonce.",
|
|
169
|
+
data: {
|
|
170
|
+
endpoint,
|
|
171
|
+
status: res.status,
|
|
172
|
+
statusText: res.statusText,
|
|
173
|
+
bodyParseResult: await safePromise(res.json())
|
|
174
|
+
}
|
|
175
|
+
});
|
|
176
|
+
}
|
|
177
|
+
const [jsonError, data] = await safePromise(res.json());
|
|
178
|
+
if (jsonError) {
|
|
179
|
+
return error({
|
|
180
|
+
name: "ParseBodyError",
|
|
181
|
+
message: "Failed to parse response body as JSON.",
|
|
182
|
+
data: jsonError
|
|
183
|
+
});
|
|
184
|
+
}
|
|
185
|
+
const validationResult = v2.safeParse(responseSchema2, data);
|
|
186
|
+
if (!validationResult.success) {
|
|
187
|
+
return error({
|
|
188
|
+
name: "ValidateDataError",
|
|
189
|
+
message: "Failed to validate data.",
|
|
190
|
+
data: validationResult
|
|
191
|
+
});
|
|
192
|
+
}
|
|
193
|
+
return success(validationResult.output);
|
|
194
|
+
}
|
|
155
195
|
|
|
156
|
-
// src/stacks-api/
|
|
196
|
+
// src/stacks-api/types.ts
|
|
157
197
|
var v3 = __toESM(require("valibot"), 1);
|
|
158
|
-
var
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
198
|
+
var baseListResponseSchema = v3.object({
|
|
199
|
+
limit: v3.number(),
|
|
200
|
+
offset: v3.number(),
|
|
201
|
+
total: v3.number(),
|
|
202
|
+
results: v3.array(v3.unknown())
|
|
203
|
+
});
|
|
204
|
+
|
|
205
|
+
// src/stacks-api/blocks/get-block.ts
|
|
206
|
+
var v4 = __toESM(require("valibot"), 1);
|
|
207
|
+
var responseSchema3 = v4.object({
|
|
208
|
+
canonical: v4.boolean(),
|
|
209
|
+
height: v4.number(),
|
|
210
|
+
hash: v4.string(),
|
|
211
|
+
block_time: v4.number(),
|
|
212
|
+
block_time_iso: v4.string(),
|
|
213
|
+
index_block_hash: v4.string(),
|
|
214
|
+
parent_block_hash: v4.string(),
|
|
215
|
+
parent_index_block_hash: v4.string(),
|
|
216
|
+
burn_block_time: v4.number(),
|
|
217
|
+
burn_block_time_iso: v4.string(),
|
|
218
|
+
burn_block_hash: v4.string(),
|
|
219
|
+
burn_block_height: v4.number(),
|
|
220
|
+
miner_txid: v4.string(),
|
|
221
|
+
tx_count: v4.number(),
|
|
222
|
+
execution_cost_read_count: v4.number(),
|
|
223
|
+
execution_cost_read_length: v4.number(),
|
|
224
|
+
execution_cost_runtime: v4.number(),
|
|
225
|
+
execution_cost_write_count: v4.number(),
|
|
226
|
+
execution_cost_write_length: v4.number()
|
|
178
227
|
});
|
|
179
228
|
async function getBlock(opts) {
|
|
180
229
|
const init = {};
|
|
@@ -206,7 +255,7 @@ async function getBlock(opts) {
|
|
|
206
255
|
data: jsonError
|
|
207
256
|
});
|
|
208
257
|
}
|
|
209
|
-
const validationResult =
|
|
258
|
+
const validationResult = v4.safeParse(responseSchema3, data);
|
|
210
259
|
if (!validationResult.success) {
|
|
211
260
|
return error({
|
|
212
261
|
name: "ValidateDataError",
|
|
@@ -218,21 +267,22 @@ async function getBlock(opts) {
|
|
|
218
267
|
}
|
|
219
268
|
|
|
220
269
|
// src/stacks-api/info/core-api.ts
|
|
221
|
-
var
|
|
222
|
-
var CoreApiResponseSchema =
|
|
223
|
-
peer_version:
|
|
224
|
-
pox_consensus:
|
|
225
|
-
burn_block_height:
|
|
226
|
-
stable_pox_consensus:
|
|
227
|
-
stable_burn_block_height:
|
|
228
|
-
server_version:
|
|
229
|
-
network_id:
|
|
230
|
-
parent_network_id:
|
|
231
|
-
stacks_tip_height:
|
|
232
|
-
stacks_tip:
|
|
233
|
-
stacks_tip_consensus_hash:
|
|
234
|
-
unanchored_tip:
|
|
235
|
-
|
|
270
|
+
var v5 = __toESM(require("valibot"), 1);
|
|
271
|
+
var CoreApiResponseSchema = v5.object({
|
|
272
|
+
peer_version: v5.number(),
|
|
273
|
+
pox_consensus: v5.string(),
|
|
274
|
+
burn_block_height: v5.number(),
|
|
275
|
+
stable_pox_consensus: v5.string(),
|
|
276
|
+
stable_burn_block_height: v5.number(),
|
|
277
|
+
server_version: v5.string(),
|
|
278
|
+
network_id: v5.number(),
|
|
279
|
+
parent_network_id: v5.number(),
|
|
280
|
+
stacks_tip_height: v5.number(),
|
|
281
|
+
stacks_tip: v5.string(),
|
|
282
|
+
stacks_tip_consensus_hash: v5.string(),
|
|
283
|
+
unanchored_tip: v5.nullable(v5.string()),
|
|
284
|
+
unanchored_seq: v5.nullable(v5.string()),
|
|
285
|
+
exit_at_block_height: v5.nullable(v5.number())
|
|
236
286
|
});
|
|
237
287
|
async function coreApi(apiOpts) {
|
|
238
288
|
const init = {};
|
|
@@ -261,7 +311,7 @@ async function coreApi(apiOpts) {
|
|
|
261
311
|
data: parseBodyError
|
|
262
312
|
});
|
|
263
313
|
}
|
|
264
|
-
const validationResult =
|
|
314
|
+
const validationResult = v5.safeParse(CoreApiResponseSchema, data);
|
|
265
315
|
if (!validationResult.success) {
|
|
266
316
|
return error({
|
|
267
317
|
name: "ValidateDataError",
|
|
@@ -273,60 +323,60 @@ async function coreApi(apiOpts) {
|
|
|
273
323
|
}
|
|
274
324
|
|
|
275
325
|
// src/stacks-api/info/pox-details.ts
|
|
276
|
-
var
|
|
277
|
-
var poxDetailsResponseSchema =
|
|
278
|
-
contract_id:
|
|
279
|
-
pox_activation_threshold_ustx:
|
|
280
|
-
first_burnchain_block_height:
|
|
281
|
-
current_burnchain_block_height:
|
|
282
|
-
prepare_phase_block_length:
|
|
283
|
-
reward_phase_block_length:
|
|
284
|
-
reward_slots:
|
|
285
|
-
rejection_fraction:
|
|
286
|
-
total_liquid_supply_ustx:
|
|
287
|
-
current_cycle:
|
|
288
|
-
id:
|
|
289
|
-
min_threshold_ustx:
|
|
290
|
-
stacked_ustx:
|
|
291
|
-
is_pox_active:
|
|
326
|
+
var v6 = __toESM(require("valibot"), 1);
|
|
327
|
+
var poxDetailsResponseSchema = v6.object({
|
|
328
|
+
contract_id: v6.string(),
|
|
329
|
+
pox_activation_threshold_ustx: v6.number(),
|
|
330
|
+
first_burnchain_block_height: v6.number(),
|
|
331
|
+
current_burnchain_block_height: v6.number(),
|
|
332
|
+
prepare_phase_block_length: v6.number(),
|
|
333
|
+
reward_phase_block_length: v6.number(),
|
|
334
|
+
reward_slots: v6.number(),
|
|
335
|
+
rejection_fraction: v6.null(),
|
|
336
|
+
total_liquid_supply_ustx: v6.number(),
|
|
337
|
+
current_cycle: v6.object({
|
|
338
|
+
id: v6.number(),
|
|
339
|
+
min_threshold_ustx: v6.number(),
|
|
340
|
+
stacked_ustx: v6.number(),
|
|
341
|
+
is_pox_active: v6.boolean()
|
|
292
342
|
}),
|
|
293
|
-
next_cycle:
|
|
294
|
-
id:
|
|
295
|
-
min_threshold_ustx:
|
|
296
|
-
min_increment_ustx:
|
|
297
|
-
stacked_ustx:
|
|
298
|
-
prepare_phase_start_block_height:
|
|
299
|
-
blocks_until_prepare_phase:
|
|
300
|
-
reward_phase_start_block_height:
|
|
301
|
-
blocks_until_reward_phase:
|
|
302
|
-
ustx_until_pox_rejection:
|
|
343
|
+
next_cycle: v6.object({
|
|
344
|
+
id: v6.number(),
|
|
345
|
+
min_threshold_ustx: v6.number(),
|
|
346
|
+
min_increment_ustx: v6.number(),
|
|
347
|
+
stacked_ustx: v6.number(),
|
|
348
|
+
prepare_phase_start_block_height: v6.number(),
|
|
349
|
+
blocks_until_prepare_phase: v6.number(),
|
|
350
|
+
reward_phase_start_block_height: v6.number(),
|
|
351
|
+
blocks_until_reward_phase: v6.number(),
|
|
352
|
+
ustx_until_pox_rejection: v6.null()
|
|
303
353
|
}),
|
|
304
|
-
epochs:
|
|
305
|
-
|
|
306
|
-
epoch_id:
|
|
307
|
-
start_height:
|
|
308
|
-
end_height:
|
|
309
|
-
block_limit:
|
|
310
|
-
write_length:
|
|
311
|
-
write_count:
|
|
312
|
-
read_length:
|
|
313
|
-
read_count:
|
|
314
|
-
runtime:
|
|
354
|
+
epochs: v6.array(
|
|
355
|
+
v6.object({
|
|
356
|
+
epoch_id: v6.string(),
|
|
357
|
+
start_height: v6.number(),
|
|
358
|
+
end_height: v6.number(),
|
|
359
|
+
block_limit: v6.object({
|
|
360
|
+
write_length: v6.number(),
|
|
361
|
+
write_count: v6.number(),
|
|
362
|
+
read_length: v6.number(),
|
|
363
|
+
read_count: v6.number(),
|
|
364
|
+
runtime: v6.number()
|
|
315
365
|
}),
|
|
316
|
-
network_epoch:
|
|
366
|
+
network_epoch: v6.number()
|
|
317
367
|
})
|
|
318
368
|
),
|
|
319
|
-
min_amount_ustx:
|
|
320
|
-
prepare_cycle_length:
|
|
321
|
-
reward_cycle_id:
|
|
322
|
-
reward_cycle_length:
|
|
323
|
-
rejection_votes_left_required:
|
|
324
|
-
next_reward_cycle_in:
|
|
325
|
-
contract_versions:
|
|
326
|
-
|
|
327
|
-
contract_id:
|
|
328
|
-
activation_burnchain_block_height:
|
|
329
|
-
first_reward_cycle_id:
|
|
369
|
+
min_amount_ustx: v6.number(),
|
|
370
|
+
prepare_cycle_length: v6.number(),
|
|
371
|
+
reward_cycle_id: v6.number(),
|
|
372
|
+
reward_cycle_length: v6.number(),
|
|
373
|
+
rejection_votes_left_required: v6.null(),
|
|
374
|
+
next_reward_cycle_in: v6.number(),
|
|
375
|
+
contract_versions: v6.array(
|
|
376
|
+
v6.object({
|
|
377
|
+
contract_id: v6.string(),
|
|
378
|
+
activation_burnchain_block_height: v6.number(),
|
|
379
|
+
first_reward_cycle_id: v6.number()
|
|
330
380
|
})
|
|
331
381
|
)
|
|
332
382
|
});
|
|
@@ -357,7 +407,7 @@ async function poxDetails(args) {
|
|
|
357
407
|
data: jsonParseError
|
|
358
408
|
});
|
|
359
409
|
}
|
|
360
|
-
const validationResult =
|
|
410
|
+
const validationResult = v6.safeParse(poxDetailsResponseSchema, data);
|
|
361
411
|
if (!validationResult.success) {
|
|
362
412
|
return error({
|
|
363
413
|
name: "ValidateDataError",
|
|
@@ -369,14 +419,14 @@ async function poxDetails(args) {
|
|
|
369
419
|
}
|
|
370
420
|
|
|
371
421
|
// src/stacks-api/proof-of-transfer/cycle.ts
|
|
372
|
-
var
|
|
373
|
-
var
|
|
374
|
-
block_height:
|
|
375
|
-
index_block_hash:
|
|
376
|
-
cycle_number:
|
|
377
|
-
total_weight:
|
|
378
|
-
total_stacked_amount:
|
|
379
|
-
total_signers:
|
|
422
|
+
var v7 = __toESM(require("valibot"), 1);
|
|
423
|
+
var responseSchema4 = v7.object({
|
|
424
|
+
block_height: v7.number(),
|
|
425
|
+
index_block_hash: v7.string(),
|
|
426
|
+
cycle_number: v7.number(),
|
|
427
|
+
total_weight: v7.number(),
|
|
428
|
+
total_stacked_amount: v7.string(),
|
|
429
|
+
total_signers: v7.number()
|
|
380
430
|
});
|
|
381
431
|
async function cycle(opts) {
|
|
382
432
|
const init = {};
|
|
@@ -407,7 +457,7 @@ async function cycle(opts) {
|
|
|
407
457
|
data: jsonError
|
|
408
458
|
});
|
|
409
459
|
}
|
|
410
|
-
const validationResult =
|
|
460
|
+
const validationResult = v7.safeParse(responseSchema4, data);
|
|
411
461
|
if (!validationResult.success) {
|
|
412
462
|
return error({
|
|
413
463
|
name: "ValidateDataError",
|
|
@@ -419,17 +469,17 @@ async function cycle(opts) {
|
|
|
419
469
|
}
|
|
420
470
|
|
|
421
471
|
// src/stacks-api/proof-of-transfer/cycles.ts
|
|
422
|
-
var
|
|
423
|
-
var cycleInfoSchema =
|
|
424
|
-
block_height:
|
|
425
|
-
index_block_hash:
|
|
426
|
-
cycle_number:
|
|
427
|
-
total_weight:
|
|
428
|
-
total_stacked_amount:
|
|
429
|
-
total_signers:
|
|
472
|
+
var v8 = __toESM(require("valibot"), 1);
|
|
473
|
+
var cycleInfoSchema = v8.object({
|
|
474
|
+
block_height: v8.number(),
|
|
475
|
+
index_block_hash: v8.string(),
|
|
476
|
+
cycle_number: v8.number(),
|
|
477
|
+
total_weight: v8.number(),
|
|
478
|
+
total_stacked_amount: v8.string(),
|
|
479
|
+
total_signers: v8.number()
|
|
430
480
|
});
|
|
431
|
-
var resultsSchema =
|
|
432
|
-
var cyclesResponseSchema =
|
|
481
|
+
var resultsSchema = v8.array(cycleInfoSchema);
|
|
482
|
+
var cyclesResponseSchema = v8.object({
|
|
433
483
|
...baseListResponseSchema.entries,
|
|
434
484
|
results: resultsSchema
|
|
435
485
|
});
|
|
@@ -465,7 +515,7 @@ async function cycles(args) {
|
|
|
465
515
|
data: jsonError
|
|
466
516
|
});
|
|
467
517
|
}
|
|
468
|
-
const validationResult =
|
|
518
|
+
const validationResult = v8.safeParse(cyclesResponseSchema, data);
|
|
469
519
|
if (!validationResult.success) {
|
|
470
520
|
return error({
|
|
471
521
|
name: "ValidateDataError",
|
|
@@ -477,16 +527,16 @@ async function cycles(args) {
|
|
|
477
527
|
}
|
|
478
528
|
|
|
479
529
|
// src/stacks-api/proof-of-transfer/signer-in-cycle.ts
|
|
480
|
-
var
|
|
481
|
-
var signerInCycleResponseSchema =
|
|
482
|
-
signing_key:
|
|
483
|
-
signer_address:
|
|
484
|
-
weight:
|
|
485
|
-
stacked_amount:
|
|
486
|
-
weight_percent:
|
|
487
|
-
stacked_amount_percent:
|
|
488
|
-
solo_stacker_count:
|
|
489
|
-
pooled_stacker_count:
|
|
530
|
+
var v9 = __toESM(require("valibot"), 1);
|
|
531
|
+
var signerInCycleResponseSchema = v9.object({
|
|
532
|
+
signing_key: v9.string(),
|
|
533
|
+
signer_address: v9.string(),
|
|
534
|
+
weight: v9.number(),
|
|
535
|
+
stacked_amount: v9.string(),
|
|
536
|
+
weight_percent: v9.number(),
|
|
537
|
+
stacked_amount_percent: v9.number(),
|
|
538
|
+
solo_stacker_count: v9.number(),
|
|
539
|
+
pooled_stacker_count: v9.number()
|
|
490
540
|
});
|
|
491
541
|
async function signerInCycle(args) {
|
|
492
542
|
const init = {};
|
|
@@ -522,7 +572,7 @@ async function signerInCycle(args) {
|
|
|
522
572
|
}
|
|
523
573
|
});
|
|
524
574
|
}
|
|
525
|
-
const validationResult =
|
|
575
|
+
const validationResult = v9.safeParse(signerInCycleResponseSchema, data);
|
|
526
576
|
if (!validationResult.success) {
|
|
527
577
|
return error({
|
|
528
578
|
name: "ValidateDataError",
|
|
@@ -534,19 +584,19 @@ async function signerInCycle(args) {
|
|
|
534
584
|
}
|
|
535
585
|
|
|
536
586
|
// src/stacks-api/proof-of-transfer/signers-in-cycle.ts
|
|
537
|
-
var
|
|
538
|
-
var signerSchema =
|
|
539
|
-
signing_key:
|
|
540
|
-
signer_address:
|
|
541
|
-
weight:
|
|
542
|
-
stacked_amount:
|
|
543
|
-
weight_percent:
|
|
544
|
-
stacked_amount_percent:
|
|
545
|
-
pooled_stacker_count:
|
|
546
|
-
solo_stacker_count:
|
|
587
|
+
var v10 = __toESM(require("valibot"), 1);
|
|
588
|
+
var signerSchema = v10.object({
|
|
589
|
+
signing_key: v10.string(),
|
|
590
|
+
signer_address: v10.string(),
|
|
591
|
+
weight: v10.number(),
|
|
592
|
+
stacked_amount: v10.string(),
|
|
593
|
+
weight_percent: v10.number(),
|
|
594
|
+
stacked_amount_percent: v10.number(),
|
|
595
|
+
pooled_stacker_count: v10.number(),
|
|
596
|
+
solo_stacker_count: v10.number()
|
|
547
597
|
});
|
|
548
|
-
var resultsSchema2 =
|
|
549
|
-
var signersResponseSchema =
|
|
598
|
+
var resultsSchema2 = v10.array(signerSchema);
|
|
599
|
+
var signersResponseSchema = v10.object({
|
|
550
600
|
...baseListResponseSchema.entries,
|
|
551
601
|
results: resultsSchema2
|
|
552
602
|
});
|
|
@@ -585,7 +635,7 @@ async function signersInCycle(args) {
|
|
|
585
635
|
}
|
|
586
636
|
});
|
|
587
637
|
}
|
|
588
|
-
const validationResult =
|
|
638
|
+
const validationResult = v10.safeParse(signersResponseSchema, data);
|
|
589
639
|
if (!validationResult.success) {
|
|
590
640
|
return error({
|
|
591
641
|
name: "ValidateDataError",
|
|
@@ -597,15 +647,15 @@ async function signersInCycle(args) {
|
|
|
597
647
|
}
|
|
598
648
|
|
|
599
649
|
// src/stacks-api/proof-of-transfer/stackers-for-signer-in-cycle.ts
|
|
600
|
-
var
|
|
601
|
-
var stackerInfoSchema =
|
|
602
|
-
stacker_address:
|
|
603
|
-
stacked_amount:
|
|
604
|
-
pox_address:
|
|
605
|
-
stacker_type:
|
|
650
|
+
var v11 = __toESM(require("valibot"), 1);
|
|
651
|
+
var stackerInfoSchema = v11.object({
|
|
652
|
+
stacker_address: v11.string(),
|
|
653
|
+
stacked_amount: v11.string(),
|
|
654
|
+
pox_address: v11.string(),
|
|
655
|
+
stacker_type: v11.union([v11.literal("pooled"), v11.literal("solo")])
|
|
606
656
|
});
|
|
607
|
-
var resultsSchema3 =
|
|
608
|
-
var stackersForSignerInCycleResponseSchema =
|
|
657
|
+
var resultsSchema3 = v11.array(stackerInfoSchema);
|
|
658
|
+
var stackersForSignerInCycleResponseSchema = v11.object({
|
|
609
659
|
...baseListResponseSchema.entries,
|
|
610
660
|
results: resultsSchema3
|
|
611
661
|
});
|
|
@@ -619,7 +669,8 @@ async function stackersForSignerInCycle(opts) {
|
|
|
619
669
|
[opts.apiKeyConfig.header]: opts.apiKeyConfig.key
|
|
620
670
|
};
|
|
621
671
|
}
|
|
622
|
-
const
|
|
672
|
+
const signerPublicKeyPathParam = opts.signerPublicKey.startsWith("0x") ? opts.signerPublicKey : `0x${opts.signerPublicKey}`;
|
|
673
|
+
const endpoint = `${opts.baseUrl}/extended/v2/pox/cycles/${opts.cycleNumber}/signers/${signerPublicKeyPathParam}/stackers?${search}`;
|
|
623
674
|
const res = await fetch(endpoint, init);
|
|
624
675
|
if (!res.ok) {
|
|
625
676
|
return error({
|
|
@@ -641,7 +692,7 @@ async function stackersForSignerInCycle(opts) {
|
|
|
641
692
|
data: jsonError
|
|
642
693
|
});
|
|
643
694
|
}
|
|
644
|
-
const validationResult =
|
|
695
|
+
const validationResult = v11.safeParse(
|
|
645
696
|
stackersForSignerInCycleResponseSchema,
|
|
646
697
|
data
|
|
647
698
|
);
|
|
@@ -656,28 +707,37 @@ async function stackersForSignerInCycle(opts) {
|
|
|
656
707
|
}
|
|
657
708
|
|
|
658
709
|
// src/stacks-api/smart-contracts/read-only.ts
|
|
659
|
-
var
|
|
660
|
-
var readOnlyResponseSchema =
|
|
661
|
-
|
|
662
|
-
okay:
|
|
663
|
-
|
|
710
|
+
var v12 = __toESM(require("valibot"), 1);
|
|
711
|
+
var readOnlyResponseSchema = v12.variant("okay", [
|
|
712
|
+
v12.object({
|
|
713
|
+
okay: v12.literal(true),
|
|
714
|
+
/**
|
|
715
|
+
* A Clarity value as a hex-encoded string.
|
|
716
|
+
*/
|
|
717
|
+
result: v12.string()
|
|
664
718
|
}),
|
|
665
|
-
|
|
666
|
-
okay:
|
|
667
|
-
cause:
|
|
719
|
+
v12.object({
|
|
720
|
+
okay: v12.literal(false),
|
|
721
|
+
cause: v12.unknown()
|
|
668
722
|
})
|
|
669
723
|
]);
|
|
670
|
-
async function readOnly(
|
|
671
|
-
const
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
724
|
+
async function readOnly(args) {
|
|
725
|
+
const headers = {
|
|
726
|
+
"Content-Type": "application/json"
|
|
727
|
+
};
|
|
728
|
+
if (args.apiKeyConfig) {
|
|
729
|
+
headers[args.apiKeyConfig.header] = args.apiKeyConfig.key;
|
|
676
730
|
}
|
|
677
|
-
const
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
731
|
+
const init = {
|
|
732
|
+
method: "POST",
|
|
733
|
+
body: JSON.stringify({
|
|
734
|
+
sender: args.sender,
|
|
735
|
+
arguments: args.arguments
|
|
736
|
+
}),
|
|
737
|
+
headers
|
|
738
|
+
};
|
|
739
|
+
const endpoint = `${args.baseUrl}/v2/contracts/call-read/${args.contractAddress}/${args.contractName}/${args.functionName}`;
|
|
740
|
+
const res = await fetch(endpoint, init);
|
|
681
741
|
if (!res.ok) {
|
|
682
742
|
return error({
|
|
683
743
|
name: "FetchReadOnlyError",
|
|
@@ -697,7 +757,7 @@ async function readOnly(opts, apiOpts) {
|
|
|
697
757
|
data: error
|
|
698
758
|
});
|
|
699
759
|
}
|
|
700
|
-
const validationResult =
|
|
760
|
+
const validationResult = v12.safeParse(readOnlyResponseSchema, data);
|
|
701
761
|
if (!validationResult.success) {
|
|
702
762
|
return error({
|
|
703
763
|
name: "ValidateDataError",
|
|
@@ -709,20 +769,20 @@ async function readOnly(opts, apiOpts) {
|
|
|
709
769
|
}
|
|
710
770
|
|
|
711
771
|
// src/stacks-api/stacking-pool/members.ts
|
|
712
|
-
var
|
|
713
|
-
var memberSchema =
|
|
714
|
-
stacker:
|
|
715
|
-
pox_addr:
|
|
716
|
-
amount_ustx:
|
|
717
|
-
burn_block_unlock_height:
|
|
718
|
-
block_height:
|
|
719
|
-
tx_id:
|
|
772
|
+
var v13 = __toESM(require("valibot"), 1);
|
|
773
|
+
var memberSchema = v13.object({
|
|
774
|
+
stacker: v13.string(),
|
|
775
|
+
pox_addr: v13.optional(v13.string()),
|
|
776
|
+
amount_ustx: v13.string(),
|
|
777
|
+
burn_block_unlock_height: v13.optional(v13.number()),
|
|
778
|
+
block_height: v13.number(),
|
|
779
|
+
tx_id: v13.string()
|
|
720
780
|
});
|
|
721
|
-
var membersResponseSchema =
|
|
722
|
-
limit:
|
|
723
|
-
offset:
|
|
724
|
-
total:
|
|
725
|
-
results:
|
|
781
|
+
var membersResponseSchema = v13.object({
|
|
782
|
+
limit: v13.number(),
|
|
783
|
+
offset: v13.number(),
|
|
784
|
+
total: v13.number(),
|
|
785
|
+
results: v13.array(memberSchema)
|
|
726
786
|
});
|
|
727
787
|
async function members(opts, apiOpts) {
|
|
728
788
|
const search = new URLSearchParams();
|
|
@@ -759,7 +819,7 @@ async function members(opts, apiOpts) {
|
|
|
759
819
|
data: jsonParseError
|
|
760
820
|
});
|
|
761
821
|
}
|
|
762
|
-
const validationResult =
|
|
822
|
+
const validationResult = v13.safeParse(membersResponseSchema, data);
|
|
763
823
|
if (!validationResult.success) {
|
|
764
824
|
return error({
|
|
765
825
|
name: "ValidateDataError",
|
|
@@ -771,116 +831,120 @@ async function members(opts, apiOpts) {
|
|
|
771
831
|
}
|
|
772
832
|
|
|
773
833
|
// src/stacks-api/transactions/schemas.ts
|
|
774
|
-
var
|
|
775
|
-
var baseTransactionSchema =
|
|
776
|
-
tx_id:
|
|
777
|
-
nonce:
|
|
778
|
-
fee_rate:
|
|
779
|
-
sender_address:
|
|
780
|
-
sponsored:
|
|
781
|
-
post_condition_mode:
|
|
782
|
-
post_conditions:
|
|
783
|
-
anchor_mode:
|
|
784
|
-
is_unanchored:
|
|
785
|
-
block_hash:
|
|
786
|
-
parent_block_hash:
|
|
787
|
-
block_height:
|
|
788
|
-
block_time:
|
|
789
|
-
block_time_iso:
|
|
790
|
-
burn_block_height:
|
|
791
|
-
burn_block_time:
|
|
792
|
-
burn_block_time_iso:
|
|
793
|
-
parent_burn_block_time:
|
|
794
|
-
parent_burn_block_time_iso:
|
|
795
|
-
canonical:
|
|
796
|
-
tx_index:
|
|
797
|
-
tx_status:
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
834
|
+
var v14 = __toESM(require("valibot"), 1);
|
|
835
|
+
var baseTransactionSchema = v14.object({
|
|
836
|
+
tx_id: v14.string(),
|
|
837
|
+
nonce: v14.number(),
|
|
838
|
+
fee_rate: v14.string(),
|
|
839
|
+
sender_address: v14.string(),
|
|
840
|
+
sponsored: v14.boolean(),
|
|
841
|
+
post_condition_mode: v14.string(),
|
|
842
|
+
post_conditions: v14.array(v14.unknown()),
|
|
843
|
+
anchor_mode: v14.string(),
|
|
844
|
+
is_unanchored: v14.boolean(),
|
|
845
|
+
block_hash: v14.string(),
|
|
846
|
+
parent_block_hash: v14.string(),
|
|
847
|
+
block_height: v14.number(),
|
|
848
|
+
block_time: v14.number(),
|
|
849
|
+
block_time_iso: v14.string(),
|
|
850
|
+
burn_block_height: v14.number(),
|
|
851
|
+
burn_block_time: v14.number(),
|
|
852
|
+
burn_block_time_iso: v14.string(),
|
|
853
|
+
parent_burn_block_time: v14.number(),
|
|
854
|
+
parent_burn_block_time_iso: v14.string(),
|
|
855
|
+
canonical: v14.boolean(),
|
|
856
|
+
tx_index: v14.number(),
|
|
857
|
+
tx_status: v14.union([
|
|
858
|
+
v14.literal("success"),
|
|
859
|
+
v14.literal("abort_by_response"),
|
|
860
|
+
v14.literal("abort_by_post_condition")
|
|
861
|
+
]),
|
|
862
|
+
tx_result: v14.object({
|
|
863
|
+
hex: v14.string(),
|
|
864
|
+
repr: v14.string()
|
|
801
865
|
}),
|
|
802
|
-
microblock_hash:
|
|
803
|
-
microblock_sequence:
|
|
804
|
-
microblock_canonical:
|
|
805
|
-
event_count:
|
|
806
|
-
events:
|
|
807
|
-
execution_cost_read_count:
|
|
808
|
-
execution_cost_read_length:
|
|
809
|
-
execution_cost_runtime:
|
|
810
|
-
execution_cost_write_count:
|
|
811
|
-
execution_cost_write_length:
|
|
866
|
+
microblock_hash: v14.string(),
|
|
867
|
+
microblock_sequence: v14.number(),
|
|
868
|
+
microblock_canonical: v14.boolean(),
|
|
869
|
+
event_count: v14.number(),
|
|
870
|
+
events: v14.array(v14.unknown()),
|
|
871
|
+
execution_cost_read_count: v14.number(),
|
|
872
|
+
execution_cost_read_length: v14.number(),
|
|
873
|
+
execution_cost_runtime: v14.number(),
|
|
874
|
+
execution_cost_write_count: v14.number(),
|
|
875
|
+
execution_cost_write_length: v14.number()
|
|
812
876
|
});
|
|
813
|
-
var contractCallTransactionSchema =
|
|
814
|
-
tx_type:
|
|
815
|
-
contract_call:
|
|
816
|
-
contract_id:
|
|
817
|
-
function_name:
|
|
818
|
-
function_signature:
|
|
819
|
-
function_args:
|
|
820
|
-
|
|
821
|
-
hex:
|
|
822
|
-
repr:
|
|
823
|
-
name:
|
|
824
|
-
type:
|
|
877
|
+
var contractCallTransactionSchema = v14.object({
|
|
878
|
+
tx_type: v14.literal("contract_call"),
|
|
879
|
+
contract_call: v14.object({
|
|
880
|
+
contract_id: v14.string(),
|
|
881
|
+
function_name: v14.string(),
|
|
882
|
+
function_signature: v14.string(),
|
|
883
|
+
function_args: v14.array(
|
|
884
|
+
v14.object({
|
|
885
|
+
hex: v14.string(),
|
|
886
|
+
repr: v14.string(),
|
|
887
|
+
name: v14.string(),
|
|
888
|
+
type: v14.string()
|
|
825
889
|
})
|
|
826
890
|
)
|
|
827
891
|
}),
|
|
828
892
|
...baseTransactionSchema.entries
|
|
829
893
|
});
|
|
830
|
-
var smartContractTransactionSchema =
|
|
831
|
-
tx_type:
|
|
832
|
-
smart_contract:
|
|
894
|
+
var smartContractTransactionSchema = v14.object({
|
|
895
|
+
tx_type: v14.literal("smart_contract"),
|
|
896
|
+
smart_contract: v14.object({
|
|
833
897
|
/**
|
|
834
898
|
* NOTE: The types may be wrong, not sure what type of value is used when
|
|
835
899
|
* the version is not `null`.
|
|
836
900
|
*/
|
|
837
|
-
clarity_version:
|
|
838
|
-
contract_id:
|
|
839
|
-
source_code:
|
|
901
|
+
clarity_version: v14.union([v14.null(), v14.number()]),
|
|
902
|
+
contract_id: v14.string(),
|
|
903
|
+
source_code: v14.string()
|
|
840
904
|
}),
|
|
841
905
|
...baseTransactionSchema.entries
|
|
842
906
|
});
|
|
843
|
-
var tokenTransferSchema =
|
|
844
|
-
tx_type:
|
|
845
|
-
token_transfer:
|
|
846
|
-
recipient_address:
|
|
847
|
-
amount:
|
|
848
|
-
memo:
|
|
907
|
+
var tokenTransferSchema = v14.object({
|
|
908
|
+
tx_type: v14.literal("token_transfer"),
|
|
909
|
+
token_transfer: v14.object({
|
|
910
|
+
recipient_address: v14.string(),
|
|
911
|
+
amount: v14.string(),
|
|
912
|
+
memo: v14.string()
|
|
849
913
|
}),
|
|
850
914
|
...baseTransactionSchema.entries
|
|
851
915
|
});
|
|
852
|
-
var transactionSchema =
|
|
916
|
+
var transactionSchema = v14.variant("tx_type", [
|
|
853
917
|
contractCallTransactionSchema,
|
|
854
918
|
smartContractTransactionSchema,
|
|
855
919
|
tokenTransferSchema
|
|
856
920
|
]);
|
|
857
921
|
|
|
858
922
|
// src/stacks-api/transactions/address-transactions.ts
|
|
859
|
-
var
|
|
860
|
-
var resultSchema =
|
|
923
|
+
var v15 = __toESM(require("valibot"), 1);
|
|
924
|
+
var resultSchema = v15.object({
|
|
861
925
|
tx: transactionSchema,
|
|
862
|
-
stx_sent:
|
|
863
|
-
stx_received:
|
|
864
|
-
events:
|
|
865
|
-
stx:
|
|
866
|
-
transfer:
|
|
867
|
-
mint:
|
|
868
|
-
burn:
|
|
926
|
+
stx_sent: v15.string(),
|
|
927
|
+
stx_received: v15.string(),
|
|
928
|
+
events: v15.object({
|
|
929
|
+
stx: v15.object({
|
|
930
|
+
transfer: v15.number(),
|
|
931
|
+
mint: v15.number(),
|
|
932
|
+
burn: v15.number()
|
|
869
933
|
}),
|
|
870
|
-
ft:
|
|
871
|
-
transfer:
|
|
872
|
-
mint:
|
|
873
|
-
burn:
|
|
934
|
+
ft: v15.object({
|
|
935
|
+
transfer: v15.number(),
|
|
936
|
+
mint: v15.number(),
|
|
937
|
+
burn: v15.number()
|
|
874
938
|
}),
|
|
875
|
-
nft:
|
|
876
|
-
transfer:
|
|
877
|
-
mint:
|
|
878
|
-
burn:
|
|
939
|
+
nft: v15.object({
|
|
940
|
+
transfer: v15.number(),
|
|
941
|
+
mint: v15.number(),
|
|
942
|
+
burn: v15.number()
|
|
879
943
|
})
|
|
880
944
|
})
|
|
881
945
|
});
|
|
882
|
-
var resultsSchema4 =
|
|
883
|
-
var addressTransactionsResponseSchema =
|
|
946
|
+
var resultsSchema4 = v15.array(resultSchema);
|
|
947
|
+
var addressTransactionsResponseSchema = v15.object({
|
|
884
948
|
...baseListResponseSchema.entries,
|
|
885
949
|
results: resultsSchema4
|
|
886
950
|
});
|
|
@@ -917,7 +981,7 @@ async function addressTransactions(args) {
|
|
|
917
981
|
data: jsonParseError
|
|
918
982
|
});
|
|
919
983
|
}
|
|
920
|
-
const validationResult =
|
|
984
|
+
const validationResult = v15.safeParse(addressTransactionsResponseSchema, data);
|
|
921
985
|
if (!validationResult.success) {
|
|
922
986
|
return error({
|
|
923
987
|
name: "ValidateDataError",
|
|
@@ -929,7 +993,7 @@ async function addressTransactions(args) {
|
|
|
929
993
|
}
|
|
930
994
|
|
|
931
995
|
// src/stacks-api/transactions/get-transaction.ts
|
|
932
|
-
var
|
|
996
|
+
var v16 = __toESM(require("valibot"), 1);
|
|
933
997
|
async function getTransaction(args) {
|
|
934
998
|
const init = {};
|
|
935
999
|
if (args.apiKeyConfig) {
|
|
@@ -958,7 +1022,7 @@ async function getTransaction(args) {
|
|
|
958
1022
|
error: jsonParseError
|
|
959
1023
|
});
|
|
960
1024
|
}
|
|
961
|
-
const validationResult =
|
|
1025
|
+
const validationResult = v16.safeParse(transactionSchema, data);
|
|
962
1026
|
if (!validationResult.success) {
|
|
963
1027
|
return error({
|
|
964
1028
|
name: "ValidateDataError",
|
|
@@ -970,7 +1034,7 @@ async function getTransaction(args) {
|
|
|
970
1034
|
}
|
|
971
1035
|
|
|
972
1036
|
// src/stacks-api/index.ts
|
|
973
|
-
var accounts = { balances };
|
|
1037
|
+
var accounts = { balances, latestNonce };
|
|
974
1038
|
var blocks = { getBlock };
|
|
975
1039
|
var info = { coreApi, poxDetails };
|
|
976
1040
|
var proofOfTransfer = {
|
|
@@ -996,10 +1060,19 @@ function callRateLimitedApi(fn, options) {
|
|
|
996
1060
|
}
|
|
997
1061
|
async function safeCallRateLimitedApi(fn, options) {
|
|
998
1062
|
try {
|
|
999
|
-
return await (0, import_exponential_backoff.backOff)(
|
|
1000
|
-
|
|
1001
|
-
|
|
1002
|
-
|
|
1063
|
+
return await (0, import_exponential_backoff.backOff)(
|
|
1064
|
+
async () => {
|
|
1065
|
+
const [error2, data] = await fn();
|
|
1066
|
+
if (error2) {
|
|
1067
|
+
throw error2;
|
|
1068
|
+
}
|
|
1069
|
+
return success(data);
|
|
1070
|
+
},
|
|
1071
|
+
{
|
|
1072
|
+
startingDelay: options?.startingDelay ?? 15e3,
|
|
1073
|
+
numOfAttempts: options?.numOfAttempts ?? 5
|
|
1074
|
+
}
|
|
1075
|
+
);
|
|
1003
1076
|
} catch (error2) {
|
|
1004
1077
|
return error({
|
|
1005
1078
|
name: "MaxRetriesExceeded",
|