@secretkeylabs/stacks-tools 0.3.0-6dd40b1 → 0.3.0-9a0fdf3

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 CHANGED
@@ -31,7 +31,8 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
31
31
  var src_exports = {};
32
32
  __export(src_exports, {
33
33
  queries: () => queries,
34
- stacksApi: () => stacksApi
34
+ stacksApi: () => stacksApi,
35
+ stacksRpcApi: () => stacksRpcApi
35
36
  });
36
37
  module.exports = __toCommonJS(src_exports);
37
38
 
@@ -503,6 +504,8 @@ async function signerInCycle(args) {
503
504
  name: "FetchSignerInCycleError",
504
505
  message: "Failed to fetch signer in cycle.",
505
506
  data: {
507
+ ...args,
508
+ endpoint,
506
509
  status: res.status,
507
510
  statusText: res.statusText
508
511
  }
@@ -617,7 +620,8 @@ async function stackersForSignerInCycle(opts) {
617
620
  [opts.apiKeyConfig.header]: opts.apiKeyConfig.key
618
621
  };
619
622
  }
620
- const endpoint = `${opts.baseUrl}/extended/v2/pox/cycles/${opts.cycleNumber}/signers/${opts.signerPublicKey}/stackers?${search}`;
623
+ const signerPublicKey = opts.signerPublicKey.startsWith("0x") ? opts.signerPublicKey : `0x${opts.signerPublicKey}`;
624
+ const endpoint = `${opts.baseUrl}/extended/v2/pox/cycles/${opts.cycleNumber}/signers/${signerPublicKey}/stackers?${search}`;
621
625
  const res = await fetch(endpoint, init);
622
626
  if (!res.ok) {
623
627
  return error({
@@ -674,15 +678,15 @@ var readOnlyResponseSchema = v11.variant("okay", [
674
678
  cause: v11.unknown()
675
679
  })
676
680
  ]);
677
- async function readOnly(opts, apiOpts) {
681
+ async function readOnly(args) {
678
682
  const init = {};
679
- if (apiOpts.apiKeyConfig) {
683
+ if (args.apiKeyConfig) {
680
684
  init.headers = {
681
- [apiOpts.apiKeyConfig.header]: apiOpts.apiKeyConfig.key
685
+ [args.apiKeyConfig.header]: args.apiKeyConfig.key
682
686
  };
683
687
  }
684
688
  const res = await fetch(
685
- `${apiOpts.baseUrl}/v2/contracts/call-read/${opts.contractAddress}/${opts.contractName}/${opts.functionName}`,
689
+ `${args.baseUrl}/v2/contracts/call-read/${args.contractAddress}/${args.contractName}/${args.functionName}`,
686
690
  init
687
691
  );
688
692
  if (!res.ok) {
@@ -736,22 +740,20 @@ var membersResponseSchema = v12.object({
736
740
  total: v12.number(),
737
741
  results: v12.array(memberSchema)
738
742
  });
739
- async function members(opts, apiOpts) {
743
+ async function members(args) {
740
744
  const search = new URLSearchParams();
741
- if (opts.afterBlock) search.append("after_block", opts.afterBlock.toString());
742
- if (opts.unanchored) search.append("unanchored", "true");
743
- if (opts.limit) search.append("limit", opts.limit.toString());
744
- if (opts.offset) search.append("offset", opts.offset.toString());
745
+ if (args.afterBlock) search.append("after_block", args.afterBlock.toString());
746
+ if (args.unanchored) search.append("unanchored", "true");
747
+ if (args.limit) search.append("limit", args.limit.toString());
748
+ if (args.offset) search.append("offset", args.offset.toString());
745
749
  const init = {};
746
- if (apiOpts.apiKeyConfig) {
750
+ if (args.apiKeyConfig) {
747
751
  init.headers = {
748
- [apiOpts.apiKeyConfig.header]: apiOpts.apiKeyConfig.key
752
+ [args.apiKeyConfig.header]: args.apiKeyConfig.key
749
753
  };
750
754
  }
751
- const res = await fetch(
752
- `${apiOpts.baseUrl}/extended/beta/stacking/${opts.poolPrincipal}/delegations?${search}`,
753
- init
754
- );
755
+ const endpoint = `${args.baseUrl}/extended/v1/pox4/${args.poolPrincipal}/delegations?${search}`;
756
+ const res = await fetch(endpoint, init);
755
757
  if (!res.ok) {
756
758
  return error({
757
759
  name: "FetchMembersError",
@@ -992,10 +994,52 @@ var transactions = {
992
994
  getTransaction
993
995
  };
994
996
 
997
+ // src/stacks-api/faucets/stx.ts
998
+ async function stx(opts) {
999
+ const search = new URLSearchParams();
1000
+ search.append("address", opts.address);
1001
+ if (opts.stacking) search.append("stacking", "true");
1002
+ const init = {};
1003
+ if (opts.apiKeyConfig) {
1004
+ init.headers = {
1005
+ [opts.apiKeyConfig.header]: opts.apiKeyConfig.key
1006
+ };
1007
+ }
1008
+ init.method = "POST";
1009
+ const endpoint = `${opts.baseUrl}/extended/v1/faucets/stx?${search}`;
1010
+ const res = await fetch(endpoint, init);
1011
+ if (!res.ok) {
1012
+ return error({
1013
+ name: "FetchStxError",
1014
+ message: "Failed to fetch STX.",
1015
+ data: {
1016
+ status: res.status,
1017
+ statusText: res.statusText,
1018
+ bodyParseResult: await safePromise(res.json())
1019
+ }
1020
+ });
1021
+ }
1022
+ const [jsonError, data] = await safePromise(res.json());
1023
+ if (jsonError) {
1024
+ return error({
1025
+ name: "ParseBodyError",
1026
+ message: "Failed to parse response body as JSON.",
1027
+ data: jsonError
1028
+ });
1029
+ }
1030
+ return success(data);
1031
+ }
1032
+
1033
+ // src/stacks-api/faucets/index.ts
1034
+ var faucets = {
1035
+ stx
1036
+ };
1037
+
995
1038
  // src/stacks-api/index.ts
996
1039
  var stacksApi = {
997
1040
  accounts,
998
1041
  blocks,
1042
+ faucets,
999
1043
  info,
1000
1044
  proofOfTransfer,
1001
1045
  smartContracts,
@@ -1003,6 +1047,72 @@ var stacksApi = {
1003
1047
  transactions
1004
1048
  };
1005
1049
 
1050
+ // src/stacks-rpc-api/smart-contracts/map-entry.ts
1051
+ var v16 = __toESM(require("valibot"), 1);
1052
+ var mapEntryResponseSchema = v16.object({
1053
+ /**
1054
+ * Hex-encoded string of clarity value. It is always an optional tuple.
1055
+ */
1056
+ data: v16.string(),
1057
+ /**
1058
+ * Hex-encoded string of the MARF proof for the data
1059
+ */
1060
+ proof: v16.optional(v16.string())
1061
+ });
1062
+ async function mapEntry(args) {
1063
+ const search = new URLSearchParams();
1064
+ if (args.proof === 0) search.append("proof", "0");
1065
+ if (args.tip) search.append("tip", args.tip);
1066
+ const init = {};
1067
+ if (args.apiKeyConfig) {
1068
+ init.headers = {
1069
+ [args.apiKeyConfig.header]: args.apiKeyConfig.key
1070
+ };
1071
+ }
1072
+ init.method = "POST";
1073
+ init.body = args.mapKey;
1074
+ const endpoint = `${args.baseUrl}/v2/map_entry/${args.contractAddress}/${args.contractName}/${args.mapName}?${search}`;
1075
+ const res = await fetch(endpoint, init);
1076
+ if (!res.ok) {
1077
+ return error({
1078
+ name: "FetchMapEntryError",
1079
+ message: "Failed to fetch map entry.",
1080
+ data: {
1081
+ status: res.status,
1082
+ statusText: res.statusText,
1083
+ bodyParseResult: await safePromise(res.json())
1084
+ }
1085
+ });
1086
+ }
1087
+ const [jsonError, data] = await safePromise(res.json());
1088
+ if (jsonError) {
1089
+ return error({
1090
+ name: "ParseBodyError",
1091
+ message: "Failed to parse response body as JSON.",
1092
+ data: jsonError
1093
+ });
1094
+ }
1095
+ const validationResult = v16.safeParse(mapEntryResponseSchema, data);
1096
+ if (!validationResult.success) {
1097
+ return error({
1098
+ name: "ValidateDataError",
1099
+ message: "Failed to validate response data.",
1100
+ data: validationResult
1101
+ });
1102
+ }
1103
+ return success(validationResult.output);
1104
+ }
1105
+
1106
+ // src/stacks-rpc-api/smart-contracts/index.ts
1107
+ var smartContracts2 = {
1108
+ mapEntry
1109
+ };
1110
+
1111
+ // src/stacks-rpc-api/index.ts
1112
+ var stacksRpcApi = {
1113
+ smartContracts: smartContracts2
1114
+ };
1115
+
1006
1116
  // src/utils/call-rate-limited-api.ts
1007
1117
  var import_exponential_backoff = require("exponential-backoff");
1008
1118
  async function safeCallRateLimitedApi(fn, options) {
@@ -1084,5 +1194,6 @@ var queries = {
1084
1194
  // Annotate the CommonJS export names for ESM import in node:
1085
1195
  0 && (module.exports = {
1086
1196
  queries,
1087
- stacksApi
1197
+ stacksApi,
1198
+ stacksRpcApi
1088
1199
  });
package/dist/index.d.cts CHANGED
@@ -15,6 +15,13 @@ type ApiRequestOptions = {
15
15
  baseUrl: string;
16
16
  apiKeyConfig?: ApiKeyConfig;
17
17
  };
18
+ type ProofAndTip = {
19
+ /**
20
+ * Returns object without the proof field when set to 0.
21
+ */
22
+ proof?: number;
23
+ tip?: "latest" | string;
24
+ };
18
25
  type ApiPaginationOptions = {
19
26
  /**
20
27
  * The number of items to return. Each endpoint has its own maximum allowed
@@ -171,12 +178,12 @@ declare const transactionSchema: v.VariantSchema<"tx_type", [v.ObjectSchema<{
171
178
  }, undefined>], undefined>;
172
179
  type Transaction = v.InferOutput<typeof transactionSchema>;
173
180
 
174
- type Args$a = {
181
+ type Args$e = {
175
182
  transactionId: string;
176
183
  } & ApiRequestOptions;
177
- declare function getTransaction(args: Args$a): Promise<Result<Transaction>>;
184
+ declare function getTransaction(args: Args$e): Promise<Result<Transaction>>;
178
185
 
179
- type Args$9 = {
186
+ type Args$d = {
180
187
  address: string;
181
188
  } & ApiRequestOptions & ApiPaginationOptions;
182
189
  declare const addressTransactionsResponseSchema: v.ObjectSchema<{
@@ -342,15 +349,15 @@ declare const addressTransactionsResponseSchema: v.ObjectSchema<{
342
349
  readonly total: v.NumberSchema<undefined>;
343
350
  }, undefined>;
344
351
  type AddressTransactionsResponse = v.InferOutput<typeof addressTransactionsResponseSchema>;
345
- declare function addressTransactions(args: Args$9): Promise<Result<AddressTransactionsResponse, SafeError<"FetchAddressTransactionsError" | "ParseBodyError" | "ValidateDataError">>>;
352
+ declare function addressTransactions(args: Args$d): Promise<Result<AddressTransactionsResponse, SafeError<"FetchAddressTransactionsError" | "ParseBodyError" | "ValidateDataError">>>;
346
353
 
347
- type Options$1 = {
354
+ type Args$c = {
348
355
  poolPrincipal: string;
349
356
  afterBlock?: number;
350
357
  unanchored?: boolean;
351
358
  limit?: number;
352
359
  offset?: number;
353
- };
360
+ } & ApiRequestOptions & ApiPaginationOptions;
354
361
  declare const membersResponseSchema: v.ObjectSchema<{
355
362
  readonly limit: v.NumberSchema<undefined>;
356
363
  readonly offset: v.NumberSchema<undefined>;
@@ -365,15 +372,15 @@ declare const membersResponseSchema: v.ObjectSchema<{
365
372
  }, undefined>, undefined>;
366
373
  }, undefined>;
367
374
  type MembersResponse = v.InferOutput<typeof membersResponseSchema>;
368
- declare function members(opts: Options$1, apiOpts: ApiRequestOptions): Promise<Result<MembersResponse>>;
375
+ declare function members(args: Args$c): Promise<Result<MembersResponse>>;
369
376
 
370
- type Options = {
377
+ type Args$b = {
371
378
  sender: string;
372
379
  arguments: string[];
373
380
  contractAddress: string;
374
381
  contractName: string;
375
382
  functionName: string;
376
- };
383
+ } & ApiRequestOptions;
377
384
  declare const readOnlyResponseSchema: v.VariantSchema<"okay", [v.ObjectSchema<{
378
385
  readonly okay: v.LiteralSchema<true, undefined>;
379
386
  readonly result: v.StringSchema<undefined>;
@@ -382,9 +389,9 @@ declare const readOnlyResponseSchema: v.VariantSchema<"okay", [v.ObjectSchema<{
382
389
  readonly cause: v.UnknownSchema;
383
390
  }, undefined>], undefined>;
384
391
  type ReadOnlyResponse = v.InferOutput<typeof readOnlyResponseSchema>;
385
- declare function readOnly(opts: Options, apiOpts: ApiRequestOptions): Promise<Result<ReadOnlyResponse>>;
392
+ declare function readOnly(args: Args$b): Promise<Result<ReadOnlyResponse>>;
386
393
 
387
- type Args$8 = {
394
+ type Args$a = {
388
395
  cycleNumber: number;
389
396
  signerPublicKey: string;
390
397
  } & ApiRequestOptions & ApiPaginationOptions;
@@ -400,9 +407,9 @@ declare const stackersForSignerInCycleResponseSchema: v.ObjectSchema<{
400
407
  readonly total: v.NumberSchema<undefined>;
401
408
  }, undefined>;
402
409
  type StackersForSignerInCycleResponse = v.InferOutput<typeof stackersForSignerInCycleResponseSchema>;
403
- declare function stackersForSignerInCycle(opts: Args$8): Promise<Result<StackersForSignerInCycleResponse, SafeError<"FetchStackersForSignerInCycleError" | "ParseBodyError" | "ValidateDataError">>>;
410
+ declare function stackersForSignerInCycle(opts: Args$a): Promise<Result<StackersForSignerInCycleResponse, SafeError<"FetchStackersForSignerInCycleError" | "ParseBodyError" | "ValidateDataError">>>;
404
411
 
405
- type Args$7 = {
412
+ type Args$9 = {
406
413
  cycleNumber: number;
407
414
  } & ApiRequestOptions & ApiPaginationOptions;
408
415
  declare const signersResponseSchema: v.ObjectSchema<{
@@ -421,9 +428,9 @@ declare const signersResponseSchema: v.ObjectSchema<{
421
428
  readonly total: v.NumberSchema<undefined>;
422
429
  }, undefined>;
423
430
  type SignersResponse = v.InferOutput<typeof signersResponseSchema>;
424
- declare function signersInCycle(args: Args$7): Promise<Result<SignersResponse, SafeError<"FetchSignersError" | "ParseBodyError" | "ValidateDataError">>>;
431
+ declare function signersInCycle(args: Args$9): Promise<Result<SignersResponse, SafeError<"FetchSignersError" | "ParseBodyError" | "ValidateDataError">>>;
425
432
 
426
- type Args$6 = {
433
+ type Args$8 = {
427
434
  /**
428
435
  * The signers public key as a hex string, with or without a '0x' prefix.
429
436
  */
@@ -441,9 +448,9 @@ declare const signerInCycleResponseSchema: v.ObjectSchema<{
441
448
  readonly pooled_stacker_count: v.NumberSchema<undefined>;
442
449
  }, undefined>;
443
450
  type SignerInCycleResponse = v.InferOutput<typeof signerInCycleResponseSchema>;
444
- declare function signerInCycle(args: Args$6): Promise<Result<SignerInCycleResponse>>;
451
+ declare function signerInCycle(args: Args$8): Promise<Result<SignerInCycleResponse>>;
445
452
 
446
- type Args$5 = ApiRequestOptions & ApiPaginationOptions;
453
+ type Args$7 = ApiRequestOptions & ApiPaginationOptions;
447
454
  declare const cyclesResponseSchema: v.ObjectSchema<{
448
455
  readonly results: v.ArraySchema<v.ObjectSchema<{
449
456
  readonly block_height: v.NumberSchema<undefined>;
@@ -458,9 +465,9 @@ declare const cyclesResponseSchema: v.ObjectSchema<{
458
465
  readonly total: v.NumberSchema<undefined>;
459
466
  }, undefined>;
460
467
  type CyclesResponse = v.InferOutput<typeof cyclesResponseSchema>;
461
- declare function cycles(args: Args$5): Promise<Result<CyclesResponse>>;
468
+ declare function cycles(args: Args$7): Promise<Result<CyclesResponse>>;
462
469
 
463
- type Args$4 = {
470
+ type Args$6 = {
464
471
  cycleNumber: number;
465
472
  } & ApiRequestOptions;
466
473
  declare const responseSchema$2: v.ObjectSchema<{
@@ -472,9 +479,9 @@ declare const responseSchema$2: v.ObjectSchema<{
472
479
  readonly total_signers: v.NumberSchema<undefined>;
473
480
  }, undefined>;
474
481
  type Response$2 = v.InferOutput<typeof responseSchema$2>;
475
- declare function cycle(opts: Args$4): Promise<Result<Response$2, SafeError<"FetchCycleError" | "ParseBodyError" | "ValidateDataError">>>;
482
+ declare function cycle(opts: Args$6): Promise<Result<Response$2, SafeError<"FetchCycleError" | "ParseBodyError" | "ValidateDataError">>>;
476
483
 
477
- type Args$3 = ApiRequestOptions;
484
+ type Args$5 = ApiRequestOptions;
478
485
  declare const poxDetailsResponseSchema: v.ObjectSchema<{
479
486
  readonly contract_id: v.StringSchema<undefined>;
480
487
  readonly pox_activation_threshold_ustx: v.NumberSchema<undefined>;
@@ -528,7 +535,7 @@ declare const poxDetailsResponseSchema: v.ObjectSchema<{
528
535
  }, undefined>, undefined>;
529
536
  }, undefined>;
530
537
  type PoxDetailsResponse = v.InferOutput<typeof poxDetailsResponseSchema>;
531
- declare function poxDetails(args: Args$3): Promise<Result<PoxDetailsResponse>>;
538
+ declare function poxDetails(args: Args$5): Promise<Result<PoxDetailsResponse>>;
532
539
 
533
540
  declare const CoreApiResponseSchema: v.ObjectSchema<{
534
541
  readonly peer_version: v.NumberSchema<undefined>;
@@ -548,7 +555,18 @@ declare const CoreApiResponseSchema: v.ObjectSchema<{
548
555
  type CoreApiResponse = v.InferOutput<typeof CoreApiResponseSchema>;
549
556
  declare function coreApi(apiOpts: ApiRequestOptions): Promise<Result<CoreApiResponse>>;
550
557
 
551
- type Args$2 = {
558
+ type Args$4 = {
559
+ address: string;
560
+ stacking?: boolean;
561
+ } & ApiRequestOptions;
562
+ declare function stx(opts: Args$4): Promise<Result<any>>;
563
+
564
+ declare const stx$1_stx: typeof stx;
565
+ declare namespace stx$1 {
566
+ export { type Args$4 as Args, stx$1_stx as stx };
567
+ }
568
+
569
+ type Args$3 = {
552
570
  heightOrHash: string | number;
553
571
  } & ApiRequestOptions;
554
572
  declare const responseSchema$1: v.ObjectSchema<{
@@ -573,9 +591,9 @@ declare const responseSchema$1: v.ObjectSchema<{
573
591
  readonly execution_cost_write_length: v.NumberSchema<undefined>;
574
592
  }, undefined>;
575
593
  type Response$1 = v.InferOutput<typeof responseSchema$1>;
576
- declare function getBlock(opts: Args$2): Promise<Result<Response$1, SafeError<"FetchBlockError" | "ParseBodyError" | "ValidateDataError">>>;
594
+ declare function getBlock(opts: Args$3): Promise<Result<Response$1, SafeError<"FetchBlockError" | "ParseBodyError" | "ValidateDataError">>>;
577
595
 
578
- type Args$1 = {
596
+ type Args$2 = {
579
597
  principal: string;
580
598
  unanchored?: boolean;
581
599
  untilBlock?: number;
@@ -605,7 +623,16 @@ declare const responseSchema: v.ObjectSchema<{
605
623
  }, undefined>, undefined>;
606
624
  }, undefined>;
607
625
  type Response = v.InferOutput<typeof responseSchema>;
608
- declare function balances(opts: Args$1): Promise<Result<Response, SafeError<"FetchBalancesError" | "ParseBodyError" | "ValidateDataError">>>;
626
+ declare function balances(opts: Args$2): Promise<Result<Response, SafeError<"FetchBalancesError" | "ParseBodyError" | "ValidateDataError">>>;
627
+
628
+ declare const faucets: {
629
+ stx: typeof stx;
630
+ };
631
+
632
+ declare const index$1_faucets: typeof faucets;
633
+ declare namespace index$1 {
634
+ export { stx$1 as Stx, index$1_faucets as faucets };
635
+ }
609
636
 
610
637
  declare const stacksApi: {
611
638
  accounts: {
@@ -614,6 +641,9 @@ declare const stacksApi: {
614
641
  blocks: {
615
642
  getBlock: typeof getBlock;
616
643
  };
644
+ faucets: {
645
+ stx: typeof stx;
646
+ };
617
647
  info: {
618
648
  coreApi: typeof coreApi;
619
649
  poxDetails: typeof poxDetails;
@@ -637,6 +667,36 @@ declare const stacksApi: {
637
667
  };
638
668
  };
639
669
 
670
+ declare const index_stacksApi: typeof stacksApi;
671
+ declare namespace index {
672
+ export { index$1 as Faucets, index_stacksApi as stacksApi };
673
+ }
674
+
675
+ type Args$1 = {
676
+ contractAddress: string;
677
+ contractName: string;
678
+ mapName: string;
679
+ mapKey: string;
680
+ } & ApiRequestOptions & ProofAndTip;
681
+ declare const mapEntryResponseSchema: v.ObjectSchema<{
682
+ /**
683
+ * Hex-encoded string of clarity value. It is always an optional tuple.
684
+ */
685
+ readonly data: v.StringSchema<undefined>;
686
+ /**
687
+ * Hex-encoded string of the MARF proof for the data
688
+ */
689
+ readonly proof: v.OptionalSchema<v.StringSchema<undefined>, never>;
690
+ }, undefined>;
691
+ type MapEntryResponse = v.InferOutput<typeof mapEntryResponseSchema>;
692
+ declare function mapEntry(args: Args$1): Promise<Result<MapEntryResponse>>;
693
+
694
+ declare const stacksRpcApi: {
695
+ smartContracts: {
696
+ mapEntry: typeof mapEntry;
697
+ };
698
+ };
699
+
640
700
  type Identifier = {
641
701
  type: "address";
642
702
  signerAddress: string;
@@ -658,4 +718,4 @@ declare const queries: {
658
718
  getSignerStackedAmount: typeof getSignerStackedAmount;
659
719
  };
660
720
 
661
- export { queries, stacksApi };
721
+ export { index as StacksApi, queries, stacksApi, stacksRpcApi };
package/dist/index.d.ts CHANGED
@@ -15,6 +15,13 @@ type ApiRequestOptions = {
15
15
  baseUrl: string;
16
16
  apiKeyConfig?: ApiKeyConfig;
17
17
  };
18
+ type ProofAndTip = {
19
+ /**
20
+ * Returns object without the proof field when set to 0.
21
+ */
22
+ proof?: number;
23
+ tip?: "latest" | string;
24
+ };
18
25
  type ApiPaginationOptions = {
19
26
  /**
20
27
  * The number of items to return. Each endpoint has its own maximum allowed
@@ -171,12 +178,12 @@ declare const transactionSchema: v.VariantSchema<"tx_type", [v.ObjectSchema<{
171
178
  }, undefined>], undefined>;
172
179
  type Transaction = v.InferOutput<typeof transactionSchema>;
173
180
 
174
- type Args$a = {
181
+ type Args$e = {
175
182
  transactionId: string;
176
183
  } & ApiRequestOptions;
177
- declare function getTransaction(args: Args$a): Promise<Result<Transaction>>;
184
+ declare function getTransaction(args: Args$e): Promise<Result<Transaction>>;
178
185
 
179
- type Args$9 = {
186
+ type Args$d = {
180
187
  address: string;
181
188
  } & ApiRequestOptions & ApiPaginationOptions;
182
189
  declare const addressTransactionsResponseSchema: v.ObjectSchema<{
@@ -342,15 +349,15 @@ declare const addressTransactionsResponseSchema: v.ObjectSchema<{
342
349
  readonly total: v.NumberSchema<undefined>;
343
350
  }, undefined>;
344
351
  type AddressTransactionsResponse = v.InferOutput<typeof addressTransactionsResponseSchema>;
345
- declare function addressTransactions(args: Args$9): Promise<Result<AddressTransactionsResponse, SafeError<"FetchAddressTransactionsError" | "ParseBodyError" | "ValidateDataError">>>;
352
+ declare function addressTransactions(args: Args$d): Promise<Result<AddressTransactionsResponse, SafeError<"FetchAddressTransactionsError" | "ParseBodyError" | "ValidateDataError">>>;
346
353
 
347
- type Options$1 = {
354
+ type Args$c = {
348
355
  poolPrincipal: string;
349
356
  afterBlock?: number;
350
357
  unanchored?: boolean;
351
358
  limit?: number;
352
359
  offset?: number;
353
- };
360
+ } & ApiRequestOptions & ApiPaginationOptions;
354
361
  declare const membersResponseSchema: v.ObjectSchema<{
355
362
  readonly limit: v.NumberSchema<undefined>;
356
363
  readonly offset: v.NumberSchema<undefined>;
@@ -365,15 +372,15 @@ declare const membersResponseSchema: v.ObjectSchema<{
365
372
  }, undefined>, undefined>;
366
373
  }, undefined>;
367
374
  type MembersResponse = v.InferOutput<typeof membersResponseSchema>;
368
- declare function members(opts: Options$1, apiOpts: ApiRequestOptions): Promise<Result<MembersResponse>>;
375
+ declare function members(args: Args$c): Promise<Result<MembersResponse>>;
369
376
 
370
- type Options = {
377
+ type Args$b = {
371
378
  sender: string;
372
379
  arguments: string[];
373
380
  contractAddress: string;
374
381
  contractName: string;
375
382
  functionName: string;
376
- };
383
+ } & ApiRequestOptions;
377
384
  declare const readOnlyResponseSchema: v.VariantSchema<"okay", [v.ObjectSchema<{
378
385
  readonly okay: v.LiteralSchema<true, undefined>;
379
386
  readonly result: v.StringSchema<undefined>;
@@ -382,9 +389,9 @@ declare const readOnlyResponseSchema: v.VariantSchema<"okay", [v.ObjectSchema<{
382
389
  readonly cause: v.UnknownSchema;
383
390
  }, undefined>], undefined>;
384
391
  type ReadOnlyResponse = v.InferOutput<typeof readOnlyResponseSchema>;
385
- declare function readOnly(opts: Options, apiOpts: ApiRequestOptions): Promise<Result<ReadOnlyResponse>>;
392
+ declare function readOnly(args: Args$b): Promise<Result<ReadOnlyResponse>>;
386
393
 
387
- type Args$8 = {
394
+ type Args$a = {
388
395
  cycleNumber: number;
389
396
  signerPublicKey: string;
390
397
  } & ApiRequestOptions & ApiPaginationOptions;
@@ -400,9 +407,9 @@ declare const stackersForSignerInCycleResponseSchema: v.ObjectSchema<{
400
407
  readonly total: v.NumberSchema<undefined>;
401
408
  }, undefined>;
402
409
  type StackersForSignerInCycleResponse = v.InferOutput<typeof stackersForSignerInCycleResponseSchema>;
403
- declare function stackersForSignerInCycle(opts: Args$8): Promise<Result<StackersForSignerInCycleResponse, SafeError<"FetchStackersForSignerInCycleError" | "ParseBodyError" | "ValidateDataError">>>;
410
+ declare function stackersForSignerInCycle(opts: Args$a): Promise<Result<StackersForSignerInCycleResponse, SafeError<"FetchStackersForSignerInCycleError" | "ParseBodyError" | "ValidateDataError">>>;
404
411
 
405
- type Args$7 = {
412
+ type Args$9 = {
406
413
  cycleNumber: number;
407
414
  } & ApiRequestOptions & ApiPaginationOptions;
408
415
  declare const signersResponseSchema: v.ObjectSchema<{
@@ -421,9 +428,9 @@ declare const signersResponseSchema: v.ObjectSchema<{
421
428
  readonly total: v.NumberSchema<undefined>;
422
429
  }, undefined>;
423
430
  type SignersResponse = v.InferOutput<typeof signersResponseSchema>;
424
- declare function signersInCycle(args: Args$7): Promise<Result<SignersResponse, SafeError<"FetchSignersError" | "ParseBodyError" | "ValidateDataError">>>;
431
+ declare function signersInCycle(args: Args$9): Promise<Result<SignersResponse, SafeError<"FetchSignersError" | "ParseBodyError" | "ValidateDataError">>>;
425
432
 
426
- type Args$6 = {
433
+ type Args$8 = {
427
434
  /**
428
435
  * The signers public key as a hex string, with or without a '0x' prefix.
429
436
  */
@@ -441,9 +448,9 @@ declare const signerInCycleResponseSchema: v.ObjectSchema<{
441
448
  readonly pooled_stacker_count: v.NumberSchema<undefined>;
442
449
  }, undefined>;
443
450
  type SignerInCycleResponse = v.InferOutput<typeof signerInCycleResponseSchema>;
444
- declare function signerInCycle(args: Args$6): Promise<Result<SignerInCycleResponse>>;
451
+ declare function signerInCycle(args: Args$8): Promise<Result<SignerInCycleResponse>>;
445
452
 
446
- type Args$5 = ApiRequestOptions & ApiPaginationOptions;
453
+ type Args$7 = ApiRequestOptions & ApiPaginationOptions;
447
454
  declare const cyclesResponseSchema: v.ObjectSchema<{
448
455
  readonly results: v.ArraySchema<v.ObjectSchema<{
449
456
  readonly block_height: v.NumberSchema<undefined>;
@@ -458,9 +465,9 @@ declare const cyclesResponseSchema: v.ObjectSchema<{
458
465
  readonly total: v.NumberSchema<undefined>;
459
466
  }, undefined>;
460
467
  type CyclesResponse = v.InferOutput<typeof cyclesResponseSchema>;
461
- declare function cycles(args: Args$5): Promise<Result<CyclesResponse>>;
468
+ declare function cycles(args: Args$7): Promise<Result<CyclesResponse>>;
462
469
 
463
- type Args$4 = {
470
+ type Args$6 = {
464
471
  cycleNumber: number;
465
472
  } & ApiRequestOptions;
466
473
  declare const responseSchema$2: v.ObjectSchema<{
@@ -472,9 +479,9 @@ declare const responseSchema$2: v.ObjectSchema<{
472
479
  readonly total_signers: v.NumberSchema<undefined>;
473
480
  }, undefined>;
474
481
  type Response$2 = v.InferOutput<typeof responseSchema$2>;
475
- declare function cycle(opts: Args$4): Promise<Result<Response$2, SafeError<"FetchCycleError" | "ParseBodyError" | "ValidateDataError">>>;
482
+ declare function cycle(opts: Args$6): Promise<Result<Response$2, SafeError<"FetchCycleError" | "ParseBodyError" | "ValidateDataError">>>;
476
483
 
477
- type Args$3 = ApiRequestOptions;
484
+ type Args$5 = ApiRequestOptions;
478
485
  declare const poxDetailsResponseSchema: v.ObjectSchema<{
479
486
  readonly contract_id: v.StringSchema<undefined>;
480
487
  readonly pox_activation_threshold_ustx: v.NumberSchema<undefined>;
@@ -528,7 +535,7 @@ declare const poxDetailsResponseSchema: v.ObjectSchema<{
528
535
  }, undefined>, undefined>;
529
536
  }, undefined>;
530
537
  type PoxDetailsResponse = v.InferOutput<typeof poxDetailsResponseSchema>;
531
- declare function poxDetails(args: Args$3): Promise<Result<PoxDetailsResponse>>;
538
+ declare function poxDetails(args: Args$5): Promise<Result<PoxDetailsResponse>>;
532
539
 
533
540
  declare const CoreApiResponseSchema: v.ObjectSchema<{
534
541
  readonly peer_version: v.NumberSchema<undefined>;
@@ -548,7 +555,18 @@ declare const CoreApiResponseSchema: v.ObjectSchema<{
548
555
  type CoreApiResponse = v.InferOutput<typeof CoreApiResponseSchema>;
549
556
  declare function coreApi(apiOpts: ApiRequestOptions): Promise<Result<CoreApiResponse>>;
550
557
 
551
- type Args$2 = {
558
+ type Args$4 = {
559
+ address: string;
560
+ stacking?: boolean;
561
+ } & ApiRequestOptions;
562
+ declare function stx(opts: Args$4): Promise<Result<any>>;
563
+
564
+ declare const stx$1_stx: typeof stx;
565
+ declare namespace stx$1 {
566
+ export { type Args$4 as Args, stx$1_stx as stx };
567
+ }
568
+
569
+ type Args$3 = {
552
570
  heightOrHash: string | number;
553
571
  } & ApiRequestOptions;
554
572
  declare const responseSchema$1: v.ObjectSchema<{
@@ -573,9 +591,9 @@ declare const responseSchema$1: v.ObjectSchema<{
573
591
  readonly execution_cost_write_length: v.NumberSchema<undefined>;
574
592
  }, undefined>;
575
593
  type Response$1 = v.InferOutput<typeof responseSchema$1>;
576
- declare function getBlock(opts: Args$2): Promise<Result<Response$1, SafeError<"FetchBlockError" | "ParseBodyError" | "ValidateDataError">>>;
594
+ declare function getBlock(opts: Args$3): Promise<Result<Response$1, SafeError<"FetchBlockError" | "ParseBodyError" | "ValidateDataError">>>;
577
595
 
578
- type Args$1 = {
596
+ type Args$2 = {
579
597
  principal: string;
580
598
  unanchored?: boolean;
581
599
  untilBlock?: number;
@@ -605,7 +623,16 @@ declare const responseSchema: v.ObjectSchema<{
605
623
  }, undefined>, undefined>;
606
624
  }, undefined>;
607
625
  type Response = v.InferOutput<typeof responseSchema>;
608
- declare function balances(opts: Args$1): Promise<Result<Response, SafeError<"FetchBalancesError" | "ParseBodyError" | "ValidateDataError">>>;
626
+ declare function balances(opts: Args$2): Promise<Result<Response, SafeError<"FetchBalancesError" | "ParseBodyError" | "ValidateDataError">>>;
627
+
628
+ declare const faucets: {
629
+ stx: typeof stx;
630
+ };
631
+
632
+ declare const index$1_faucets: typeof faucets;
633
+ declare namespace index$1 {
634
+ export { stx$1 as Stx, index$1_faucets as faucets };
635
+ }
609
636
 
610
637
  declare const stacksApi: {
611
638
  accounts: {
@@ -614,6 +641,9 @@ declare const stacksApi: {
614
641
  blocks: {
615
642
  getBlock: typeof getBlock;
616
643
  };
644
+ faucets: {
645
+ stx: typeof stx;
646
+ };
617
647
  info: {
618
648
  coreApi: typeof coreApi;
619
649
  poxDetails: typeof poxDetails;
@@ -637,6 +667,36 @@ declare const stacksApi: {
637
667
  };
638
668
  };
639
669
 
670
+ declare const index_stacksApi: typeof stacksApi;
671
+ declare namespace index {
672
+ export { index$1 as Faucets, index_stacksApi as stacksApi };
673
+ }
674
+
675
+ type Args$1 = {
676
+ contractAddress: string;
677
+ contractName: string;
678
+ mapName: string;
679
+ mapKey: string;
680
+ } & ApiRequestOptions & ProofAndTip;
681
+ declare const mapEntryResponseSchema: v.ObjectSchema<{
682
+ /**
683
+ * Hex-encoded string of clarity value. It is always an optional tuple.
684
+ */
685
+ readonly data: v.StringSchema<undefined>;
686
+ /**
687
+ * Hex-encoded string of the MARF proof for the data
688
+ */
689
+ readonly proof: v.OptionalSchema<v.StringSchema<undefined>, never>;
690
+ }, undefined>;
691
+ type MapEntryResponse = v.InferOutput<typeof mapEntryResponseSchema>;
692
+ declare function mapEntry(args: Args$1): Promise<Result<MapEntryResponse>>;
693
+
694
+ declare const stacksRpcApi: {
695
+ smartContracts: {
696
+ mapEntry: typeof mapEntry;
697
+ };
698
+ };
699
+
640
700
  type Identifier = {
641
701
  type: "address";
642
702
  signerAddress: string;
@@ -658,4 +718,4 @@ declare const queries: {
658
718
  getSignerStackedAmount: typeof getSignerStackedAmount;
659
719
  };
660
720
 
661
- export { queries, stacksApi };
721
+ export { index as StacksApi, queries, stacksApi, stacksRpcApi };
package/dist/index.js CHANGED
@@ -466,6 +466,8 @@ async function signerInCycle(args) {
466
466
  name: "FetchSignerInCycleError",
467
467
  message: "Failed to fetch signer in cycle.",
468
468
  data: {
469
+ ...args,
470
+ endpoint,
469
471
  status: res.status,
470
472
  statusText: res.statusText
471
473
  }
@@ -580,7 +582,8 @@ async function stackersForSignerInCycle(opts) {
580
582
  [opts.apiKeyConfig.header]: opts.apiKeyConfig.key
581
583
  };
582
584
  }
583
- const endpoint = `${opts.baseUrl}/extended/v2/pox/cycles/${opts.cycleNumber}/signers/${opts.signerPublicKey}/stackers?${search}`;
585
+ const signerPublicKey = opts.signerPublicKey.startsWith("0x") ? opts.signerPublicKey : `0x${opts.signerPublicKey}`;
586
+ const endpoint = `${opts.baseUrl}/extended/v2/pox/cycles/${opts.cycleNumber}/signers/${signerPublicKey}/stackers?${search}`;
584
587
  const res = await fetch(endpoint, init);
585
588
  if (!res.ok) {
586
589
  return error({
@@ -637,15 +640,15 @@ var readOnlyResponseSchema = v11.variant("okay", [
637
640
  cause: v11.unknown()
638
641
  })
639
642
  ]);
640
- async function readOnly(opts, apiOpts) {
643
+ async function readOnly(args) {
641
644
  const init = {};
642
- if (apiOpts.apiKeyConfig) {
645
+ if (args.apiKeyConfig) {
643
646
  init.headers = {
644
- [apiOpts.apiKeyConfig.header]: apiOpts.apiKeyConfig.key
647
+ [args.apiKeyConfig.header]: args.apiKeyConfig.key
645
648
  };
646
649
  }
647
650
  const res = await fetch(
648
- `${apiOpts.baseUrl}/v2/contracts/call-read/${opts.contractAddress}/${opts.contractName}/${opts.functionName}`,
651
+ `${args.baseUrl}/v2/contracts/call-read/${args.contractAddress}/${args.contractName}/${args.functionName}`,
649
652
  init
650
653
  );
651
654
  if (!res.ok) {
@@ -699,22 +702,20 @@ var membersResponseSchema = v12.object({
699
702
  total: v12.number(),
700
703
  results: v12.array(memberSchema)
701
704
  });
702
- async function members(opts, apiOpts) {
705
+ async function members(args) {
703
706
  const search = new URLSearchParams();
704
- if (opts.afterBlock) search.append("after_block", opts.afterBlock.toString());
705
- if (opts.unanchored) search.append("unanchored", "true");
706
- if (opts.limit) search.append("limit", opts.limit.toString());
707
- if (opts.offset) search.append("offset", opts.offset.toString());
707
+ if (args.afterBlock) search.append("after_block", args.afterBlock.toString());
708
+ if (args.unanchored) search.append("unanchored", "true");
709
+ if (args.limit) search.append("limit", args.limit.toString());
710
+ if (args.offset) search.append("offset", args.offset.toString());
708
711
  const init = {};
709
- if (apiOpts.apiKeyConfig) {
712
+ if (args.apiKeyConfig) {
710
713
  init.headers = {
711
- [apiOpts.apiKeyConfig.header]: apiOpts.apiKeyConfig.key
714
+ [args.apiKeyConfig.header]: args.apiKeyConfig.key
712
715
  };
713
716
  }
714
- const res = await fetch(
715
- `${apiOpts.baseUrl}/extended/beta/stacking/${opts.poolPrincipal}/delegations?${search}`,
716
- init
717
- );
717
+ const endpoint = `${args.baseUrl}/extended/v1/pox4/${args.poolPrincipal}/delegations?${search}`;
718
+ const res = await fetch(endpoint, init);
718
719
  if (!res.ok) {
719
720
  return error({
720
721
  name: "FetchMembersError",
@@ -955,10 +956,52 @@ var transactions = {
955
956
  getTransaction
956
957
  };
957
958
 
959
+ // src/stacks-api/faucets/stx.ts
960
+ async function stx(opts) {
961
+ const search = new URLSearchParams();
962
+ search.append("address", opts.address);
963
+ if (opts.stacking) search.append("stacking", "true");
964
+ const init = {};
965
+ if (opts.apiKeyConfig) {
966
+ init.headers = {
967
+ [opts.apiKeyConfig.header]: opts.apiKeyConfig.key
968
+ };
969
+ }
970
+ init.method = "POST";
971
+ const endpoint = `${opts.baseUrl}/extended/v1/faucets/stx?${search}`;
972
+ const res = await fetch(endpoint, init);
973
+ if (!res.ok) {
974
+ return error({
975
+ name: "FetchStxError",
976
+ message: "Failed to fetch STX.",
977
+ data: {
978
+ status: res.status,
979
+ statusText: res.statusText,
980
+ bodyParseResult: await safePromise(res.json())
981
+ }
982
+ });
983
+ }
984
+ const [jsonError, data] = await safePromise(res.json());
985
+ if (jsonError) {
986
+ return error({
987
+ name: "ParseBodyError",
988
+ message: "Failed to parse response body as JSON.",
989
+ data: jsonError
990
+ });
991
+ }
992
+ return success(data);
993
+ }
994
+
995
+ // src/stacks-api/faucets/index.ts
996
+ var faucets = {
997
+ stx
998
+ };
999
+
958
1000
  // src/stacks-api/index.ts
959
1001
  var stacksApi = {
960
1002
  accounts,
961
1003
  blocks,
1004
+ faucets,
962
1005
  info,
963
1006
  proofOfTransfer,
964
1007
  smartContracts,
@@ -966,6 +1009,72 @@ var stacksApi = {
966
1009
  transactions
967
1010
  };
968
1011
 
1012
+ // src/stacks-rpc-api/smart-contracts/map-entry.ts
1013
+ import * as v16 from "valibot";
1014
+ var mapEntryResponseSchema = v16.object({
1015
+ /**
1016
+ * Hex-encoded string of clarity value. It is always an optional tuple.
1017
+ */
1018
+ data: v16.string(),
1019
+ /**
1020
+ * Hex-encoded string of the MARF proof for the data
1021
+ */
1022
+ proof: v16.optional(v16.string())
1023
+ });
1024
+ async function mapEntry(args) {
1025
+ const search = new URLSearchParams();
1026
+ if (args.proof === 0) search.append("proof", "0");
1027
+ if (args.tip) search.append("tip", args.tip);
1028
+ const init = {};
1029
+ if (args.apiKeyConfig) {
1030
+ init.headers = {
1031
+ [args.apiKeyConfig.header]: args.apiKeyConfig.key
1032
+ };
1033
+ }
1034
+ init.method = "POST";
1035
+ init.body = args.mapKey;
1036
+ const endpoint = `${args.baseUrl}/v2/map_entry/${args.contractAddress}/${args.contractName}/${args.mapName}?${search}`;
1037
+ const res = await fetch(endpoint, init);
1038
+ if (!res.ok) {
1039
+ return error({
1040
+ name: "FetchMapEntryError",
1041
+ message: "Failed to fetch map entry.",
1042
+ data: {
1043
+ status: res.status,
1044
+ statusText: res.statusText,
1045
+ bodyParseResult: await safePromise(res.json())
1046
+ }
1047
+ });
1048
+ }
1049
+ const [jsonError, data] = await safePromise(res.json());
1050
+ if (jsonError) {
1051
+ return error({
1052
+ name: "ParseBodyError",
1053
+ message: "Failed to parse response body as JSON.",
1054
+ data: jsonError
1055
+ });
1056
+ }
1057
+ const validationResult = v16.safeParse(mapEntryResponseSchema, data);
1058
+ if (!validationResult.success) {
1059
+ return error({
1060
+ name: "ValidateDataError",
1061
+ message: "Failed to validate response data.",
1062
+ data: validationResult
1063
+ });
1064
+ }
1065
+ return success(validationResult.output);
1066
+ }
1067
+
1068
+ // src/stacks-rpc-api/smart-contracts/index.ts
1069
+ var smartContracts2 = {
1070
+ mapEntry
1071
+ };
1072
+
1073
+ // src/stacks-rpc-api/index.ts
1074
+ var stacksRpcApi = {
1075
+ smartContracts: smartContracts2
1076
+ };
1077
+
969
1078
  // src/utils/call-rate-limited-api.ts
970
1079
  import { backOff } from "exponential-backoff";
971
1080
  async function safeCallRateLimitedApi(fn, options) {
@@ -1046,5 +1155,6 @@ var queries = {
1046
1155
  };
1047
1156
  export {
1048
1157
  queries,
1049
- stacksApi
1158
+ stacksApi,
1159
+ stacksRpcApi
1050
1160
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@secretkeylabs/stacks-tools",
3
- "version": "0.3.0-6dd40b1",
3
+ "version": "0.3.0-9a0fdf3",
4
4
  "type": "module",
5
5
  "files": [
6
6
  "dist"