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