stxer 0.7.0 → 0.8.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/src/types.ts CHANGED
@@ -7,26 +7,42 @@
7
7
  // Sidecar Tip Types
8
8
  // =============================================================================
9
9
 
10
+ /**
11
+ * Rust `u64` / `u128` fields serialize as JSON numbers but can exceed JS
12
+ * `Number.MAX_SAFE_INTEGER` (2^53 - 1). Accept either form: numbers are
13
+ * convenient for small values, decimal strings preserve full precision
14
+ * for large ones. Mirrors how `pox_addrs[k].payout` (u128) is typed.
15
+ *
16
+ * In practice nearly all values fit in `Number` — this typing exists so
17
+ * code that *might* see a large value (post-genesis cumulative cost
18
+ * counters, accumulated stx_burned in long simulations) cannot silently
19
+ * lose precision. Use `BigInt(x)` to normalize before arithmetic when in
20
+ * doubt.
21
+ */
22
+ export type U64 = number | string;
23
+ /** Rust `u128`. See {@link U64} for usage notes. */
24
+ export type U128 = number | string;
25
+
10
26
  export interface TenureCost {
11
- read_count: number;
12
- read_length: number;
13
- write_count: number;
14
- write_length: number;
15
- runtime: number;
27
+ read_count: U64;
28
+ read_length: U64;
29
+ write_count: U64;
30
+ write_length: U64;
31
+ runtime: U64;
16
32
  }
17
33
 
18
34
  export interface SidecarTip {
19
35
  bitcoin_height: number;
20
36
  block_hash: string;
21
- block_height: number;
22
- block_time: number;
37
+ block_height: U64;
38
+ block_time: U64;
23
39
  burn_block_height: number;
24
- burn_block_time: number;
40
+ burn_block_time: U64;
25
41
  consensus_hash: string;
26
42
  index_block_hash: string;
27
43
  is_nakamoto: boolean;
28
44
  tenure_cost: TenureCost;
29
- tenure_height: number;
45
+ tenure_height: U64;
30
46
  sortition_id: string;
31
47
  epoch_id: string;
32
48
  }
@@ -110,7 +126,32 @@ export type ClarityEpoch =
110
126
  | 'Epoch34'
111
127
  | 'Epoch35';
112
128
 
113
- export type ClarityVersion = 'Clarity1' | 'Clarity2' | 'Clarity3' | 'Clarity4';
129
+ /**
130
+ * Wire-format Clarity version name as emitted by the stxer AST parser
131
+ * (`/contracts:parse-ast`). Used in {@link ClarityAbi.clarity_version}.
132
+ *
133
+ * **Distinct from the numeric `ClarityVersion` enum re-exported by
134
+ * `@stacks/transactions`** (1..5), which is what the SDK builder
135
+ * methods (`addContractDeploy`, `makeUnsignedContractDeploy`, etc.)
136
+ * accept. To build transactions:
137
+ *
138
+ * import { ClarityVersion } from '@stacks/transactions';
139
+ * // ClarityVersion.Clarity5 -> 5
140
+ *
141
+ * To check an AST response:
142
+ *
143
+ * import type { ClarityVersionName } from 'stxer';
144
+ * if (abi.clarity_version === 'Clarity5') { ... }
145
+ */
146
+ export type ClarityVersionName =
147
+ | 'Clarity1'
148
+ | 'Clarity2'
149
+ | 'Clarity3'
150
+ | 'Clarity4'
151
+ | 'Clarity5';
152
+
153
+ /** @deprecated Renamed to {@link ClarityVersionName} in 0.8.0 to avoid collision with `@stacks/transactions`'s numeric `ClarityVersion` enum. Re-exported for back-compat — will be removed in a future major. */
154
+ export type ClarityVersion = ClarityVersionName;
114
155
 
115
156
  export interface ClarityAbi {
116
157
  functions: ClarityAbiFunction[];
@@ -119,7 +160,7 @@ export interface ClarityAbi {
119
160
  fungible_tokens: ClarityAbiFungibleToken[];
120
161
  non_fungible_tokens: ClarityAbiNonFungibleToken[];
121
162
  epoch: ClarityEpoch;
122
- clarity_version: ClarityVersion;
163
+ clarity_version: ClarityVersionName;
123
164
  }
124
165
 
125
166
  export interface SymbolicExpressionField {
@@ -187,11 +228,11 @@ export interface ContractAST {
187
228
  // =============================================================================
188
229
 
189
230
  export interface ExecutionCost {
190
- read_count: number;
191
- read_length: number;
192
- write_count: number;
193
- write_length: number;
194
- runtime: number;
231
+ read_count: U64;
232
+ read_length: U64;
233
+ write_count: U64;
234
+ write_length: U64;
235
+ runtime: U64;
195
236
  }
196
237
 
197
238
  /**
@@ -223,7 +264,11 @@ export interface TransactionReceipt {
223
264
  * `Err`.
224
265
  */
225
266
  result: string;
226
- stx_burned: number;
267
+ /**
268
+ * STX (in micro-STX) burned by this transaction. u128 — accept as
269
+ * `number | string` to preserve precision above 2^53.
270
+ */
271
+ stx_burned: U128;
227
272
  tx_index: number;
228
273
  /**
229
274
  * Error message from the upstream Clarity VM. `null` when the tx had
@@ -450,6 +495,31 @@ export interface DataVarStep {
450
495
  DataVar: [contract_id: string, variable_name: string];
451
496
  }
452
497
 
498
+ /**
499
+ * Evaluate an arbitrary read-only Clarity expression in the context of
500
+ * `sender` (and optional `sponsor`). The Clarity analyzer rejects any
501
+ * expression that would mutate state, so this is a pure projection.
502
+ *
503
+ * Use when a plain `DataVar` / `MapEntry` read isn't enough — read-only
504
+ * `contract-call?` projections, custom expressions, or anything that
505
+ * needs a specific sender principal in scope. Cheaper than `Eval` (no
506
+ * write access, no step slot) and the only sender-context read shape.
507
+ *
508
+ * Choosing between read variants:
509
+ * - `DataVar` / `MapEntry` — direct storage reads, no Clarity
510
+ * evaluation; cheapest.
511
+ * - `EvalReadonly` — arbitrary read-only Clarity in sender/sponsor
512
+ * context; analyzer-enforced no writes.
513
+ * - `Eval` (top-level step variant on {@link SimulationStepInput},
514
+ * NOT a Reads sub-type) — arbitrary Clarity with **write access**.
515
+ * Use only when you need to mutate state.
516
+ * - `Transaction` — real Stacks tx with receipt, events,
517
+ * post-conditions, fee, nonce.
518
+ *
519
+ * @example
520
+ * { EvalReadonly: ['SP...sender', '', 'SP...contract', '(get-counter)'] }
521
+ * { EvalReadonly: ['SP...sender', '', 'SP...oracle', "(contract-call? .oracle get-value 'STX-USD)"] }
522
+ */
453
523
  export interface EvalReadonlyStep {
454
524
  /** `sponsor` is `""` (empty string) when there is no sponsor. */
455
525
  EvalReadonly: [
@@ -502,10 +572,101 @@ export interface ReadErrResult {
502
572
 
503
573
  export type ReadResult = ReadOkResult | ReadErrResult;
504
574
 
575
+ /**
576
+ * Tenure-extend cause. `Extended` resets all cost dimensions; the
577
+ * SIP-034 variants reset a single dimension only.
578
+ */
579
+ export type TenureExtendCause =
580
+ | 'Extended'
581
+ | 'ExtendedRuntime'
582
+ | 'ExtendedReadCount'
583
+ | 'ExtendedReadLength'
584
+ | 'ExtendedWriteCount'
585
+ | 'ExtendedWriteLength';
586
+
587
+ /** PoX address used inside `AdvanceBlocksRequest.pox_addrs`. */
588
+ export interface PoxAddrInput {
589
+ /** Address version byte (0..255). */
590
+ version: number;
591
+ /** Address hashbytes as hex (no `0x` prefix). */
592
+ hashbytes: string;
593
+ }
594
+
595
+ /**
596
+ * Request payload for the `AdvanceBlocks` step variant. Synthesizes
597
+ * bitcoin and stacks blocks on top of the simulation's pinned parent
598
+ * tip. Hex strings for 32-byte hashes / VRF seeds; PoX address
599
+ * overrides use the tuple form `[addrs, payout_ustx]` on the wire.
600
+ */
601
+ export interface AdvanceBlocksRequest {
602
+ bitcoin_blocks: number;
603
+ stacks_blocks_per_bitcoin: number;
604
+ /** Defaults to 600 (mainnet target) upstream when omitted. */
605
+ bitcoin_interval_secs?: U64;
606
+ /**
607
+ * Per-burn-index burn-header-hash overrides, keyed by 0-based burn
608
+ * index within this batch. Hex strings (32 bytes, with or without
609
+ * `0x` prefix).
610
+ */
611
+ burn_header_hashes?: Record<string, string>;
612
+ /**
613
+ * Per-burn-index PoX address overrides as `[addrs, payout_ustx]`.
614
+ * `payout_ustx` is `u128` upstream — see {@link U128}.
615
+ */
616
+ pox_addrs?: Record<string, [PoxAddrInput[], U128]>;
617
+ /** Per-burn-index VRF-seed overrides as 32-byte hex strings. */
618
+ vrf_seeds?: Record<string, string>;
619
+ }
620
+
621
+ /**
622
+ * One synthesized block produced by an `AdvanceBlocks` step. Returned
623
+ * inside `SimulationStepResult.AdvanceBlocks.Ok` and as the `tip`
624
+ * fields when synthetic.
625
+ */
626
+ export interface AdvancedBlockSummary {
627
+ stacks_height: U64;
628
+ burn_height: number;
629
+ coinbase_height: number;
630
+ index_block_hash: string;
631
+ burn_header_hash: string;
632
+ vrf_seed: string;
633
+ block_time: U64;
634
+ burn_block_time: U64;
635
+ /**
636
+ * `true` when this synthetic block is the first stacks block in a
637
+ * new tenure (i.e. follows a synthesized bitcoin block).
638
+ */
639
+ tenure_change: boolean;
640
+ }
641
+
642
+ /**
643
+ * Response shape for `GET /devtools/v2/simulations/{id}/tip`. When
644
+ * `synthetic` is `false`, fields mirror the parent metadata pinned at
645
+ * session start; `vrf_seed` and `tenure_change` are omitted in that
646
+ * case.
647
+ */
648
+ export interface SimulationTipResponse {
649
+ synthetic: boolean;
650
+ stacks_height: U64;
651
+ burn_height: number;
652
+ coinbase_height: number;
653
+ block_time: U64;
654
+ burn_block_time: U64;
655
+ index_block_hash: string;
656
+ consensus_hash: string;
657
+ burn_header_hash: string;
658
+ sortition_id: string;
659
+ epoch: string;
660
+ /** Only present when `synthetic` is `true`. */
661
+ vrf_seed?: string;
662
+ /** Only present when `synthetic` is `true`. */
663
+ tenure_change?: boolean;
664
+ }
665
+
505
666
  /**
506
667
  * Per-step result returned by `POST /devtools/v2/simulations/{id}` (the
507
- * "submit steps" endpoint). Mirrors the rust `RunSimulationStepResult`
508
- * enum externally tagged, exactly one variant key present.
668
+ * "submit steps" endpoint). Externally tagged exactly one variant key
669
+ * is present per object.
509
670
  *
510
671
  * Distinct from `SimulationStepSummary`, which is what
511
672
  * `GET /devtools/v2/simulations/{id}` returns and includes the original
@@ -516,7 +677,10 @@ export type SimulationStepResult =
516
677
  | { Eval: { Ok: string } | { Err: string } }
517
678
  | { SetContractCode: { Ok: null } | { Err: string } }
518
679
  | { Reads: ReadResult[] }
519
- | { TenureExtend: ExecutionCost };
680
+ | { TenureExtend: ExecutionCost }
681
+ | {
682
+ AdvanceBlocks: { Ok: AdvancedBlockSummary[] } | { Err: string };
683
+ };
520
684
 
521
685
  // Simulation step types (summary format from GET /devtools/v2/simulations/{id})
522
686
  export interface TransactionStepSummary {
@@ -552,22 +716,52 @@ export interface EvalStepSummary {
552
716
  };
553
717
  }
554
718
 
719
+ /**
720
+ * Echoed `AdvanceBlocks` input as serialized in the summary response.
721
+ * Differs from the request shape ({@link AdvanceBlocksRequest}) in two
722
+ * places: `bitcoin_interval_secs` is nullable (serde `Option`); each
723
+ * `pox_addrs` value is the `{addrs, payout}` object form (vs. the
724
+ * request's tuple form).
725
+ */
726
+ export interface AdvanceBlocksStepEcho {
727
+ bitcoin_blocks: number;
728
+ stacks_blocks_per_bitcoin: number;
729
+ bitcoin_interval_secs: U64 | null;
730
+ burn_header_hashes: Record<string, string>;
731
+ pox_addrs: Record<string, { addrs: PoxAddrInput[]; payout: U128 }>;
732
+ vrf_seeds: Record<string, string>;
733
+ }
734
+
555
735
  export interface TenureExtendStepSummary {
736
+ /**
737
+ * Echoed input shape. The server normalizes legacy `{TenureExtend: []}`
738
+ * inputs to `{cause: 'Extended'}` at parse time, so the summary always
739
+ * carries the modern form regardless of how the step was submitted.
740
+ */
741
+ TenureExtend: { cause: TenureExtendCause };
556
742
  Result: {
557
743
  TenureExtend: ExecutionCost;
558
744
  };
559
745
  }
560
746
 
747
+ export interface AdvanceBlocksStepSummary {
748
+ AdvanceBlocks: AdvanceBlocksStepEcho;
749
+ Result: {
750
+ AdvanceBlocks: { Ok: AdvancedBlockSummary[] } | { Err: string };
751
+ };
752
+ }
753
+
561
754
  export type SimulationStepSummary =
562
755
  | TransactionStepSummary
563
756
  | ReadsStepSummary
564
757
  | SetContractCodeStepSummary
565
758
  | EvalStepSummary
566
- | TenureExtendStepSummary;
759
+ | TenureExtendStepSummary
760
+ | AdvanceBlocksStepSummary;
567
761
 
568
762
  // Simulation metadata
569
763
  export interface SimulationMetadata {
570
- block_height: number;
764
+ block_height: U64;
571
765
  block_hash: string;
572
766
  burn_block_height: number;
573
767
  burn_block_hash: string;
@@ -586,7 +780,7 @@ export interface SimulationResult {
586
780
 
587
781
  // Create session request
588
782
  export interface CreateSimulationRequest {
589
- block_height?: number;
783
+ block_height?: U64;
590
784
  block_hash?: string;
591
785
  skip_tracing?: boolean;
592
786
  }
@@ -595,7 +789,39 @@ export interface CreateSimulationResponse {
595
789
  id: string;
596
790
  }
597
791
 
598
- // Submit steps request
792
+ /**
793
+ * One step submitted to `POST /devtools/v2/simulations/{id}`. Tagged
794
+ * union — exactly one variant key per object.
795
+ *
796
+ * **Picking the right Clarity-execution shape** — `Transaction` /
797
+ * `Eval` / `Reads` differ on side-effects, cost, and what they emit:
798
+ *
799
+ * - `Transaction` — full Stacks tx mechanics. Generates a
800
+ * `TransactionReceipt` (events, vm_error, post_condition_aborted,
801
+ * execution_cost), consumes nonce, charges fee, enforces
802
+ * post-conditions. The only variant that emits a receipt. Use when
803
+ * simulating a real user action.
804
+ * - `Eval` — arbitrary Clarity with **write access** to contract
805
+ * storage; no fee, no nonce, no post-conditions, no receipt — just
806
+ * the resulting Clarity value or err. Use to stub state mid-session
807
+ * (`var-set`, `map-set`, …) or run code with side-effects without
808
+ * tx ceremony.
809
+ * - `Reads` (batch of {@link ReadStep}, including `EvalReadonly`) —
810
+ * pure projection, no state changes, cheapest. Use when you only
811
+ * need to read derived data; `EvalReadonly` provides the
812
+ * sender/sponsor context that `DataVar` / `MapEntry` cannot.
813
+ *
814
+ * `SetContractCode` replaces a contract's code (write side-effects, no
815
+ * fee/nonce/receipt — like `Eval` but at the contract level).
816
+ * `TenureExtend` resets cost dimensions. `AdvanceBlocks` synthesizes
817
+ * burn/stacks blocks (see {@link AdvanceBlocksRequest}).
818
+ *
819
+ * `TenureExtend` accepts both legacy `[]` (treated server-side as
820
+ * `cause: 'Extended'`) and modern `{ cause }` shapes. SDK 0.8.0 emits
821
+ * the modern form via {@link SimulationBuilder.addTenureExtend}; the
822
+ * legacy shape stays in this union so consumers passing literal step
823
+ * objects (not via the builder) still type-check.
824
+ */
599
825
  export type SimulationStepInput =
600
826
  | { Transaction: string }
601
827
  | {
@@ -615,7 +841,8 @@ export type SimulationStepInput =
615
841
  ];
616
842
  }
617
843
  | { Reads: ReadStep[] }
618
- | { TenureExtend: [] };
844
+ | { TenureExtend: [] | { cause: TenureExtendCause } }
845
+ | { AdvanceBlocks: AdvanceBlocksRequest };
619
846
 
620
847
  export interface SubmitSimulationStepsRequest {
621
848
  steps: SimulationStepInput[];
@@ -688,7 +915,7 @@ export interface SimulationBatchReadsResponse {
688
915
  export interface InstantSimulationRequest {
689
916
  /** Transaction serialized to hex. */
690
917
  transaction: string;
691
- block_height?: number;
918
+ block_height?: U64;
692
919
  block_hash?: string;
693
920
  reads?: ReadStep[];
694
921
  }