@secretkeylabs/stacks-tools 0.4.0-afcaa14 → 0.4.0-fdbbd5e
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 +342 -270
- package/dist/index.d.cts +271 -49
- package/dist/index.d.ts +271 -49
- package/dist/index.js +342 -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,21 @@ 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
|
-
exit_at_block_height:
|
|
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.string(),
|
|
284
|
+
exit_at_block_height: v5.number()
|
|
236
285
|
});
|
|
237
286
|
async function coreApi(apiOpts) {
|
|
238
287
|
const init = {};
|
|
@@ -261,7 +310,7 @@ async function coreApi(apiOpts) {
|
|
|
261
310
|
data: parseBodyError
|
|
262
311
|
});
|
|
263
312
|
}
|
|
264
|
-
const validationResult =
|
|
313
|
+
const validationResult = v5.safeParse(CoreApiResponseSchema, data);
|
|
265
314
|
if (!validationResult.success) {
|
|
266
315
|
return error({
|
|
267
316
|
name: "ValidateDataError",
|
|
@@ -273,60 +322,60 @@ async function coreApi(apiOpts) {
|
|
|
273
322
|
}
|
|
274
323
|
|
|
275
324
|
// 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:
|
|
325
|
+
var v6 = __toESM(require("valibot"), 1);
|
|
326
|
+
var poxDetailsResponseSchema = v6.object({
|
|
327
|
+
contract_id: v6.string(),
|
|
328
|
+
pox_activation_threshold_ustx: v6.number(),
|
|
329
|
+
first_burnchain_block_height: v6.number(),
|
|
330
|
+
current_burnchain_block_height: v6.number(),
|
|
331
|
+
prepare_phase_block_length: v6.number(),
|
|
332
|
+
reward_phase_block_length: v6.number(),
|
|
333
|
+
reward_slots: v6.number(),
|
|
334
|
+
rejection_fraction: v6.null(),
|
|
335
|
+
total_liquid_supply_ustx: v6.number(),
|
|
336
|
+
current_cycle: v6.object({
|
|
337
|
+
id: v6.number(),
|
|
338
|
+
min_threshold_ustx: v6.number(),
|
|
339
|
+
stacked_ustx: v6.number(),
|
|
340
|
+
is_pox_active: v6.boolean()
|
|
292
341
|
}),
|
|
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:
|
|
342
|
+
next_cycle: v6.object({
|
|
343
|
+
id: v6.number(),
|
|
344
|
+
min_threshold_ustx: v6.number(),
|
|
345
|
+
min_increment_ustx: v6.number(),
|
|
346
|
+
stacked_ustx: v6.number(),
|
|
347
|
+
prepare_phase_start_block_height: v6.number(),
|
|
348
|
+
blocks_until_prepare_phase: v6.number(),
|
|
349
|
+
reward_phase_start_block_height: v6.number(),
|
|
350
|
+
blocks_until_reward_phase: v6.number(),
|
|
351
|
+
ustx_until_pox_rejection: v6.null()
|
|
303
352
|
}),
|
|
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:
|
|
353
|
+
epochs: v6.array(
|
|
354
|
+
v6.object({
|
|
355
|
+
epoch_id: v6.string(),
|
|
356
|
+
start_height: v6.number(),
|
|
357
|
+
end_height: v6.number(),
|
|
358
|
+
block_limit: v6.object({
|
|
359
|
+
write_length: v6.number(),
|
|
360
|
+
write_count: v6.number(),
|
|
361
|
+
read_length: v6.number(),
|
|
362
|
+
read_count: v6.number(),
|
|
363
|
+
runtime: v6.number()
|
|
315
364
|
}),
|
|
316
|
-
network_epoch:
|
|
365
|
+
network_epoch: v6.number()
|
|
317
366
|
})
|
|
318
367
|
),
|
|
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:
|
|
368
|
+
min_amount_ustx: v6.number(),
|
|
369
|
+
prepare_cycle_length: v6.number(),
|
|
370
|
+
reward_cycle_id: v6.number(),
|
|
371
|
+
reward_cycle_length: v6.number(),
|
|
372
|
+
rejection_votes_left_required: v6.null(),
|
|
373
|
+
next_reward_cycle_in: v6.number(),
|
|
374
|
+
contract_versions: v6.array(
|
|
375
|
+
v6.object({
|
|
376
|
+
contract_id: v6.string(),
|
|
377
|
+
activation_burnchain_block_height: v6.number(),
|
|
378
|
+
first_reward_cycle_id: v6.number()
|
|
330
379
|
})
|
|
331
380
|
)
|
|
332
381
|
});
|
|
@@ -357,7 +406,7 @@ async function poxDetails(args) {
|
|
|
357
406
|
data: jsonParseError
|
|
358
407
|
});
|
|
359
408
|
}
|
|
360
|
-
const validationResult =
|
|
409
|
+
const validationResult = v6.safeParse(poxDetailsResponseSchema, data);
|
|
361
410
|
if (!validationResult.success) {
|
|
362
411
|
return error({
|
|
363
412
|
name: "ValidateDataError",
|
|
@@ -369,14 +418,14 @@ async function poxDetails(args) {
|
|
|
369
418
|
}
|
|
370
419
|
|
|
371
420
|
// 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:
|
|
421
|
+
var v7 = __toESM(require("valibot"), 1);
|
|
422
|
+
var responseSchema4 = v7.object({
|
|
423
|
+
block_height: v7.number(),
|
|
424
|
+
index_block_hash: v7.string(),
|
|
425
|
+
cycle_number: v7.number(),
|
|
426
|
+
total_weight: v7.number(),
|
|
427
|
+
total_stacked_amount: v7.string(),
|
|
428
|
+
total_signers: v7.number()
|
|
380
429
|
});
|
|
381
430
|
async function cycle(opts) {
|
|
382
431
|
const init = {};
|
|
@@ -407,7 +456,7 @@ async function cycle(opts) {
|
|
|
407
456
|
data: jsonError
|
|
408
457
|
});
|
|
409
458
|
}
|
|
410
|
-
const validationResult =
|
|
459
|
+
const validationResult = v7.safeParse(responseSchema4, data);
|
|
411
460
|
if (!validationResult.success) {
|
|
412
461
|
return error({
|
|
413
462
|
name: "ValidateDataError",
|
|
@@ -419,17 +468,17 @@ async function cycle(opts) {
|
|
|
419
468
|
}
|
|
420
469
|
|
|
421
470
|
// 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:
|
|
471
|
+
var v8 = __toESM(require("valibot"), 1);
|
|
472
|
+
var cycleInfoSchema = v8.object({
|
|
473
|
+
block_height: v8.number(),
|
|
474
|
+
index_block_hash: v8.string(),
|
|
475
|
+
cycle_number: v8.number(),
|
|
476
|
+
total_weight: v8.number(),
|
|
477
|
+
total_stacked_amount: v8.string(),
|
|
478
|
+
total_signers: v8.number()
|
|
430
479
|
});
|
|
431
|
-
var resultsSchema =
|
|
432
|
-
var cyclesResponseSchema =
|
|
480
|
+
var resultsSchema = v8.array(cycleInfoSchema);
|
|
481
|
+
var cyclesResponseSchema = v8.object({
|
|
433
482
|
...baseListResponseSchema.entries,
|
|
434
483
|
results: resultsSchema
|
|
435
484
|
});
|
|
@@ -465,7 +514,7 @@ async function cycles(args) {
|
|
|
465
514
|
data: jsonError
|
|
466
515
|
});
|
|
467
516
|
}
|
|
468
|
-
const validationResult =
|
|
517
|
+
const validationResult = v8.safeParse(cyclesResponseSchema, data);
|
|
469
518
|
if (!validationResult.success) {
|
|
470
519
|
return error({
|
|
471
520
|
name: "ValidateDataError",
|
|
@@ -477,16 +526,16 @@ async function cycles(args) {
|
|
|
477
526
|
}
|
|
478
527
|
|
|
479
528
|
// 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:
|
|
529
|
+
var v9 = __toESM(require("valibot"), 1);
|
|
530
|
+
var signerInCycleResponseSchema = v9.object({
|
|
531
|
+
signing_key: v9.string(),
|
|
532
|
+
signer_address: v9.string(),
|
|
533
|
+
weight: v9.number(),
|
|
534
|
+
stacked_amount: v9.string(),
|
|
535
|
+
weight_percent: v9.number(),
|
|
536
|
+
stacked_amount_percent: v9.number(),
|
|
537
|
+
solo_stacker_count: v9.number(),
|
|
538
|
+
pooled_stacker_count: v9.number()
|
|
490
539
|
});
|
|
491
540
|
async function signerInCycle(args) {
|
|
492
541
|
const init = {};
|
|
@@ -522,7 +571,7 @@ async function signerInCycle(args) {
|
|
|
522
571
|
}
|
|
523
572
|
});
|
|
524
573
|
}
|
|
525
|
-
const validationResult =
|
|
574
|
+
const validationResult = v9.safeParse(signerInCycleResponseSchema, data);
|
|
526
575
|
if (!validationResult.success) {
|
|
527
576
|
return error({
|
|
528
577
|
name: "ValidateDataError",
|
|
@@ -534,19 +583,19 @@ async function signerInCycle(args) {
|
|
|
534
583
|
}
|
|
535
584
|
|
|
536
585
|
// 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:
|
|
586
|
+
var v10 = __toESM(require("valibot"), 1);
|
|
587
|
+
var signerSchema = v10.object({
|
|
588
|
+
signing_key: v10.string(),
|
|
589
|
+
signer_address: v10.string(),
|
|
590
|
+
weight: v10.number(),
|
|
591
|
+
stacked_amount: v10.string(),
|
|
592
|
+
weight_percent: v10.number(),
|
|
593
|
+
stacked_amount_percent: v10.number(),
|
|
594
|
+
pooled_stacker_count: v10.number(),
|
|
595
|
+
solo_stacker_count: v10.number()
|
|
547
596
|
});
|
|
548
|
-
var resultsSchema2 =
|
|
549
|
-
var signersResponseSchema =
|
|
597
|
+
var resultsSchema2 = v10.array(signerSchema);
|
|
598
|
+
var signersResponseSchema = v10.object({
|
|
550
599
|
...baseListResponseSchema.entries,
|
|
551
600
|
results: resultsSchema2
|
|
552
601
|
});
|
|
@@ -585,7 +634,7 @@ async function signersInCycle(args) {
|
|
|
585
634
|
}
|
|
586
635
|
});
|
|
587
636
|
}
|
|
588
|
-
const validationResult =
|
|
637
|
+
const validationResult = v10.safeParse(signersResponseSchema, data);
|
|
589
638
|
if (!validationResult.success) {
|
|
590
639
|
return error({
|
|
591
640
|
name: "ValidateDataError",
|
|
@@ -597,15 +646,15 @@ async function signersInCycle(args) {
|
|
|
597
646
|
}
|
|
598
647
|
|
|
599
648
|
// 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:
|
|
649
|
+
var v11 = __toESM(require("valibot"), 1);
|
|
650
|
+
var stackerInfoSchema = v11.object({
|
|
651
|
+
stacker_address: v11.string(),
|
|
652
|
+
stacked_amount: v11.string(),
|
|
653
|
+
pox_address: v11.string(),
|
|
654
|
+
stacker_type: v11.union([v11.literal("pooled"), v11.literal("solo")])
|
|
606
655
|
});
|
|
607
|
-
var resultsSchema3 =
|
|
608
|
-
var stackersForSignerInCycleResponseSchema =
|
|
656
|
+
var resultsSchema3 = v11.array(stackerInfoSchema);
|
|
657
|
+
var stackersForSignerInCycleResponseSchema = v11.object({
|
|
609
658
|
...baseListResponseSchema.entries,
|
|
610
659
|
results: resultsSchema3
|
|
611
660
|
});
|
|
@@ -619,7 +668,8 @@ async function stackersForSignerInCycle(opts) {
|
|
|
619
668
|
[opts.apiKeyConfig.header]: opts.apiKeyConfig.key
|
|
620
669
|
};
|
|
621
670
|
}
|
|
622
|
-
const
|
|
671
|
+
const signerPublicKeyPathParam = opts.signerPublicKey.startsWith("0x") ? opts.signerPublicKey : `0x${opts.signerPublicKey}`;
|
|
672
|
+
const endpoint = `${opts.baseUrl}/extended/v2/pox/cycles/${opts.cycleNumber}/signers/${signerPublicKeyPathParam}/stackers?${search}`;
|
|
623
673
|
const res = await fetch(endpoint, init);
|
|
624
674
|
if (!res.ok) {
|
|
625
675
|
return error({
|
|
@@ -641,7 +691,7 @@ async function stackersForSignerInCycle(opts) {
|
|
|
641
691
|
data: jsonError
|
|
642
692
|
});
|
|
643
693
|
}
|
|
644
|
-
const validationResult =
|
|
694
|
+
const validationResult = v11.safeParse(
|
|
645
695
|
stackersForSignerInCycleResponseSchema,
|
|
646
696
|
data
|
|
647
697
|
);
|
|
@@ -656,28 +706,37 @@ async function stackersForSignerInCycle(opts) {
|
|
|
656
706
|
}
|
|
657
707
|
|
|
658
708
|
// src/stacks-api/smart-contracts/read-only.ts
|
|
659
|
-
var
|
|
660
|
-
var readOnlyResponseSchema =
|
|
661
|
-
|
|
662
|
-
okay:
|
|
663
|
-
|
|
709
|
+
var v12 = __toESM(require("valibot"), 1);
|
|
710
|
+
var readOnlyResponseSchema = v12.variant("okay", [
|
|
711
|
+
v12.object({
|
|
712
|
+
okay: v12.literal(true),
|
|
713
|
+
/**
|
|
714
|
+
* A Clarity value as a hex-encoded string.
|
|
715
|
+
*/
|
|
716
|
+
result: v12.string()
|
|
664
717
|
}),
|
|
665
|
-
|
|
666
|
-
okay:
|
|
667
|
-
cause:
|
|
718
|
+
v12.object({
|
|
719
|
+
okay: v12.literal(false),
|
|
720
|
+
cause: v12.unknown()
|
|
668
721
|
})
|
|
669
722
|
]);
|
|
670
|
-
async function readOnly(
|
|
671
|
-
const
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
723
|
+
async function readOnly(args) {
|
|
724
|
+
const headers = {
|
|
725
|
+
"Content-Type": "application/json"
|
|
726
|
+
};
|
|
727
|
+
if (args.apiKeyConfig) {
|
|
728
|
+
headers[args.apiKeyConfig.header] = args.apiKeyConfig.key;
|
|
676
729
|
}
|
|
677
|
-
const
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
730
|
+
const init = {
|
|
731
|
+
method: "POST",
|
|
732
|
+
body: JSON.stringify({
|
|
733
|
+
sender: args.sender,
|
|
734
|
+
arguments: args.arguments
|
|
735
|
+
}),
|
|
736
|
+
headers
|
|
737
|
+
};
|
|
738
|
+
const endpoint = `${args.baseUrl}/v2/contracts/call-read/${args.contractAddress}/${args.contractName}/${args.functionName}`;
|
|
739
|
+
const res = await fetch(endpoint, init);
|
|
681
740
|
if (!res.ok) {
|
|
682
741
|
return error({
|
|
683
742
|
name: "FetchReadOnlyError",
|
|
@@ -697,7 +756,7 @@ async function readOnly(opts, apiOpts) {
|
|
|
697
756
|
data: error
|
|
698
757
|
});
|
|
699
758
|
}
|
|
700
|
-
const validationResult =
|
|
759
|
+
const validationResult = v12.safeParse(readOnlyResponseSchema, data);
|
|
701
760
|
if (!validationResult.success) {
|
|
702
761
|
return error({
|
|
703
762
|
name: "ValidateDataError",
|
|
@@ -709,20 +768,20 @@ async function readOnly(opts, apiOpts) {
|
|
|
709
768
|
}
|
|
710
769
|
|
|
711
770
|
// 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:
|
|
771
|
+
var v13 = __toESM(require("valibot"), 1);
|
|
772
|
+
var memberSchema = v13.object({
|
|
773
|
+
stacker: v13.string(),
|
|
774
|
+
pox_addr: v13.optional(v13.string()),
|
|
775
|
+
amount_ustx: v13.string(),
|
|
776
|
+
burn_block_unlock_height: v13.optional(v13.number()),
|
|
777
|
+
block_height: v13.number(),
|
|
778
|
+
tx_id: v13.string()
|
|
720
779
|
});
|
|
721
|
-
var membersResponseSchema =
|
|
722
|
-
limit:
|
|
723
|
-
offset:
|
|
724
|
-
total:
|
|
725
|
-
results:
|
|
780
|
+
var membersResponseSchema = v13.object({
|
|
781
|
+
limit: v13.number(),
|
|
782
|
+
offset: v13.number(),
|
|
783
|
+
total: v13.number(),
|
|
784
|
+
results: v13.array(memberSchema)
|
|
726
785
|
});
|
|
727
786
|
async function members(opts, apiOpts) {
|
|
728
787
|
const search = new URLSearchParams();
|
|
@@ -759,7 +818,7 @@ async function members(opts, apiOpts) {
|
|
|
759
818
|
data: jsonParseError
|
|
760
819
|
});
|
|
761
820
|
}
|
|
762
|
-
const validationResult =
|
|
821
|
+
const validationResult = v13.safeParse(membersResponseSchema, data);
|
|
763
822
|
if (!validationResult.success) {
|
|
764
823
|
return error({
|
|
765
824
|
name: "ValidateDataError",
|
|
@@ -771,116 +830,120 @@ async function members(opts, apiOpts) {
|
|
|
771
830
|
}
|
|
772
831
|
|
|
773
832
|
// 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
|
-
|
|
833
|
+
var v14 = __toESM(require("valibot"), 1);
|
|
834
|
+
var baseTransactionSchema = v14.object({
|
|
835
|
+
tx_id: v14.string(),
|
|
836
|
+
nonce: v14.number(),
|
|
837
|
+
fee_rate: v14.string(),
|
|
838
|
+
sender_address: v14.string(),
|
|
839
|
+
sponsored: v14.boolean(),
|
|
840
|
+
post_condition_mode: v14.string(),
|
|
841
|
+
post_conditions: v14.array(v14.unknown()),
|
|
842
|
+
anchor_mode: v14.string(),
|
|
843
|
+
is_unanchored: v14.boolean(),
|
|
844
|
+
block_hash: v14.string(),
|
|
845
|
+
parent_block_hash: v14.string(),
|
|
846
|
+
block_height: v14.number(),
|
|
847
|
+
block_time: v14.number(),
|
|
848
|
+
block_time_iso: v14.string(),
|
|
849
|
+
burn_block_height: v14.number(),
|
|
850
|
+
burn_block_time: v14.number(),
|
|
851
|
+
burn_block_time_iso: v14.string(),
|
|
852
|
+
parent_burn_block_time: v14.number(),
|
|
853
|
+
parent_burn_block_time_iso: v14.string(),
|
|
854
|
+
canonical: v14.boolean(),
|
|
855
|
+
tx_index: v14.number(),
|
|
856
|
+
tx_status: v14.union([
|
|
857
|
+
v14.literal("success"),
|
|
858
|
+
v14.literal("abort_by_response"),
|
|
859
|
+
v14.literal("abort_by_post_condition")
|
|
860
|
+
]),
|
|
861
|
+
tx_result: v14.object({
|
|
862
|
+
hex: v14.string(),
|
|
863
|
+
repr: v14.string()
|
|
801
864
|
}),
|
|
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:
|
|
865
|
+
microblock_hash: v14.string(),
|
|
866
|
+
microblock_sequence: v14.number(),
|
|
867
|
+
microblock_canonical: v14.boolean(),
|
|
868
|
+
event_count: v14.number(),
|
|
869
|
+
events: v14.array(v14.unknown()),
|
|
870
|
+
execution_cost_read_count: v14.number(),
|
|
871
|
+
execution_cost_read_length: v14.number(),
|
|
872
|
+
execution_cost_runtime: v14.number(),
|
|
873
|
+
execution_cost_write_count: v14.number(),
|
|
874
|
+
execution_cost_write_length: v14.number()
|
|
812
875
|
});
|
|
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:
|
|
876
|
+
var contractCallTransactionSchema = v14.object({
|
|
877
|
+
tx_type: v14.literal("contract_call"),
|
|
878
|
+
contract_call: v14.object({
|
|
879
|
+
contract_id: v14.string(),
|
|
880
|
+
function_name: v14.string(),
|
|
881
|
+
function_signature: v14.string(),
|
|
882
|
+
function_args: v14.array(
|
|
883
|
+
v14.object({
|
|
884
|
+
hex: v14.string(),
|
|
885
|
+
repr: v14.string(),
|
|
886
|
+
name: v14.string(),
|
|
887
|
+
type: v14.string()
|
|
825
888
|
})
|
|
826
889
|
)
|
|
827
890
|
}),
|
|
828
891
|
...baseTransactionSchema.entries
|
|
829
892
|
});
|
|
830
|
-
var smartContractTransactionSchema =
|
|
831
|
-
tx_type:
|
|
832
|
-
smart_contract:
|
|
893
|
+
var smartContractTransactionSchema = v14.object({
|
|
894
|
+
tx_type: v14.literal("smart_contract"),
|
|
895
|
+
smart_contract: v14.object({
|
|
833
896
|
/**
|
|
834
897
|
* NOTE: The types may be wrong, not sure what type of value is used when
|
|
835
898
|
* the version is not `null`.
|
|
836
899
|
*/
|
|
837
|
-
clarity_version:
|
|
838
|
-
contract_id:
|
|
839
|
-
source_code:
|
|
900
|
+
clarity_version: v14.union([v14.null(), v14.number()]),
|
|
901
|
+
contract_id: v14.string(),
|
|
902
|
+
source_code: v14.string()
|
|
840
903
|
}),
|
|
841
904
|
...baseTransactionSchema.entries
|
|
842
905
|
});
|
|
843
|
-
var tokenTransferSchema =
|
|
844
|
-
tx_type:
|
|
845
|
-
token_transfer:
|
|
846
|
-
recipient_address:
|
|
847
|
-
amount:
|
|
848
|
-
memo:
|
|
906
|
+
var tokenTransferSchema = v14.object({
|
|
907
|
+
tx_type: v14.literal("token_transfer"),
|
|
908
|
+
token_transfer: v14.object({
|
|
909
|
+
recipient_address: v14.string(),
|
|
910
|
+
amount: v14.string(),
|
|
911
|
+
memo: v14.string()
|
|
849
912
|
}),
|
|
850
913
|
...baseTransactionSchema.entries
|
|
851
914
|
});
|
|
852
|
-
var transactionSchema =
|
|
915
|
+
var transactionSchema = v14.variant("tx_type", [
|
|
853
916
|
contractCallTransactionSchema,
|
|
854
917
|
smartContractTransactionSchema,
|
|
855
918
|
tokenTransferSchema
|
|
856
919
|
]);
|
|
857
920
|
|
|
858
921
|
// src/stacks-api/transactions/address-transactions.ts
|
|
859
|
-
var
|
|
860
|
-
var resultSchema =
|
|
922
|
+
var v15 = __toESM(require("valibot"), 1);
|
|
923
|
+
var resultSchema = v15.object({
|
|
861
924
|
tx: transactionSchema,
|
|
862
|
-
stx_sent:
|
|
863
|
-
stx_received:
|
|
864
|
-
events:
|
|
865
|
-
stx:
|
|
866
|
-
transfer:
|
|
867
|
-
mint:
|
|
868
|
-
burn:
|
|
925
|
+
stx_sent: v15.string(),
|
|
926
|
+
stx_received: v15.string(),
|
|
927
|
+
events: v15.object({
|
|
928
|
+
stx: v15.object({
|
|
929
|
+
transfer: v15.number(),
|
|
930
|
+
mint: v15.number(),
|
|
931
|
+
burn: v15.number()
|
|
869
932
|
}),
|
|
870
|
-
ft:
|
|
871
|
-
transfer:
|
|
872
|
-
mint:
|
|
873
|
-
burn:
|
|
933
|
+
ft: v15.object({
|
|
934
|
+
transfer: v15.number(),
|
|
935
|
+
mint: v15.number(),
|
|
936
|
+
burn: v15.number()
|
|
874
937
|
}),
|
|
875
|
-
nft:
|
|
876
|
-
transfer:
|
|
877
|
-
mint:
|
|
878
|
-
burn:
|
|
938
|
+
nft: v15.object({
|
|
939
|
+
transfer: v15.number(),
|
|
940
|
+
mint: v15.number(),
|
|
941
|
+
burn: v15.number()
|
|
879
942
|
})
|
|
880
943
|
})
|
|
881
944
|
});
|
|
882
|
-
var resultsSchema4 =
|
|
883
|
-
var addressTransactionsResponseSchema =
|
|
945
|
+
var resultsSchema4 = v15.array(resultSchema);
|
|
946
|
+
var addressTransactionsResponseSchema = v15.object({
|
|
884
947
|
...baseListResponseSchema.entries,
|
|
885
948
|
results: resultsSchema4
|
|
886
949
|
});
|
|
@@ -917,7 +980,7 @@ async function addressTransactions(args) {
|
|
|
917
980
|
data: jsonParseError
|
|
918
981
|
});
|
|
919
982
|
}
|
|
920
|
-
const validationResult =
|
|
983
|
+
const validationResult = v15.safeParse(addressTransactionsResponseSchema, data);
|
|
921
984
|
if (!validationResult.success) {
|
|
922
985
|
return error({
|
|
923
986
|
name: "ValidateDataError",
|
|
@@ -929,7 +992,7 @@ async function addressTransactions(args) {
|
|
|
929
992
|
}
|
|
930
993
|
|
|
931
994
|
// src/stacks-api/transactions/get-transaction.ts
|
|
932
|
-
var
|
|
995
|
+
var v16 = __toESM(require("valibot"), 1);
|
|
933
996
|
async function getTransaction(args) {
|
|
934
997
|
const init = {};
|
|
935
998
|
if (args.apiKeyConfig) {
|
|
@@ -958,7 +1021,7 @@ async function getTransaction(args) {
|
|
|
958
1021
|
error: jsonParseError
|
|
959
1022
|
});
|
|
960
1023
|
}
|
|
961
|
-
const validationResult =
|
|
1024
|
+
const validationResult = v16.safeParse(transactionSchema, data);
|
|
962
1025
|
if (!validationResult.success) {
|
|
963
1026
|
return error({
|
|
964
1027
|
name: "ValidateDataError",
|
|
@@ -970,7 +1033,7 @@ async function getTransaction(args) {
|
|
|
970
1033
|
}
|
|
971
1034
|
|
|
972
1035
|
// src/stacks-api/index.ts
|
|
973
|
-
var accounts = { balances };
|
|
1036
|
+
var accounts = { balances, latestNonce };
|
|
974
1037
|
var blocks = { getBlock };
|
|
975
1038
|
var info = { coreApi, poxDetails };
|
|
976
1039
|
var proofOfTransfer = {
|
|
@@ -996,10 +1059,19 @@ function callRateLimitedApi(fn, options) {
|
|
|
996
1059
|
}
|
|
997
1060
|
async function safeCallRateLimitedApi(fn, options) {
|
|
998
1061
|
try {
|
|
999
|
-
return await (0, import_exponential_backoff.backOff)(
|
|
1000
|
-
|
|
1001
|
-
|
|
1002
|
-
|
|
1062
|
+
return await (0, import_exponential_backoff.backOff)(
|
|
1063
|
+
async () => {
|
|
1064
|
+
const [error2, data] = await fn();
|
|
1065
|
+
if (error2) {
|
|
1066
|
+
throw error2;
|
|
1067
|
+
}
|
|
1068
|
+
return success(data);
|
|
1069
|
+
},
|
|
1070
|
+
{
|
|
1071
|
+
startingDelay: options?.startingDelay ?? 15e3,
|
|
1072
|
+
numOfAttempts: options?.numOfAttempts ?? 5
|
|
1073
|
+
}
|
|
1074
|
+
);
|
|
1003
1075
|
} catch (error2) {
|
|
1004
1076
|
return error({
|
|
1005
1077
|
name: "MaxRetriesExceeded",
|