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/dist/index.d.ts CHANGED
@@ -1,8 +1,10 @@
1
1
  export * from './ast';
2
2
  export * from './batch-api';
3
+ export * from './bitcoin';
3
4
  export * from './clarity-api';
4
5
  export * from './constants';
5
6
  export * from './simulation';
6
7
  export * from './simulation-api';
7
8
  export * from './tip';
9
+ export * from './transaction';
8
10
  export * from './types';
@@ -4,7 +4,30 @@
4
4
  * These functions provide direct access to the stxer V2 simulation endpoints
5
5
  * for programmatic use cases where you need more control than SimulationBuilder provides.
6
6
  */
7
- import type { InstantSimulationRequest, InstantSimulationResponse, SimulationBatchReadsRequest, SimulationBatchReadsResponse, SimulationResult, SubmitSimulationStepsRequest, SubmitSimulationStepsResponse } from './types';
7
+ import type { InstantSimulationRequest, InstantSimulationResponse, SimulationBatchReadsRequest, SimulationBatchReadsResponse, SimulationResult, SimulationTipResponse, SubmitSimulationStepsRequest, SubmitSimulationStepsResponse, U64 } from './types';
8
+ /**
9
+ * Server-side error markers. `simulation_busy` ↔ HTTP 409,
10
+ * `simulation_outdated` ↔ HTTP 410. Other errors keep `marker = null`.
11
+ */
12
+ export type SimulationErrorMarker = 'simulation_busy' | 'simulation_outdated' | null;
13
+ /**
14
+ * Thrown by the simulation-api fetch wrappers when the API responds
15
+ * with a non-2xx status. `status` carries the wire HTTP code so
16
+ * callers can branch on 409 (busy) / 410 (outdated) without parsing
17
+ * the message string. `marker` is the server-side classification
18
+ * extracted from the body prefix (`simulation_busy:` /
19
+ * `simulation_outdated:`).
20
+ *
21
+ * Pre-0.8.0 SDKs threw a plain `Error` whose message embedded the body
22
+ * text; that lossy form is still used for the message field here so
23
+ * existing log scrapers keep working.
24
+ */
25
+ export declare class SimulationError extends Error {
26
+ readonly status: number;
27
+ readonly marker: SimulationErrorMarker;
28
+ readonly body: string;
29
+ constructor(operation: string, status: number, body: string);
30
+ }
8
31
  /**
9
32
  * Options for API calls
10
33
  */
@@ -16,8 +39,11 @@ export interface SimulationApiOptions {
16
39
  * Create simulation session options
17
40
  */
18
41
  export interface CreateSessionOptions {
19
- /** Block height for simulation (optional, uses tip if not provided) */
20
- block_height?: number;
42
+ /**
43
+ * Block height for simulation (optional, uses tip if not provided).
44
+ * u64 — `number | string`; see {@link U64}.
45
+ */
46
+ block_height?: U64;
21
47
  /** Block hash corresponding to block_height */
22
48
  block_hash?: string;
23
49
  /** Skip debug tracing for faster simulations */
@@ -113,6 +139,29 @@ export declare function submitSimulationSteps(sessionId: string, request: Submit
113
139
  * ```
114
140
  */
115
141
  export declare function getSimulationResult(sessionId: string, options?: SimulationApiOptions): Promise<SimulationResult>;
142
+ /**
143
+ * Get the current tip of a simulation session.
144
+ *
145
+ * Returns the latest synthetic tip when at least one `AdvanceBlocks`
146
+ * step has run (`synthetic: true`, includes `vrf_seed` and
147
+ * `tenure_change`). Returns the parent metadata pinned at session
148
+ * start otherwise (`synthetic: false`, `vrf_seed` and `tenure_change`
149
+ * omitted).
150
+ *
151
+ * Backed by `GET /devtools/v2/simulations/{id}/tip`. Older simulator
152
+ * builds that predate this route respond 404.
153
+ *
154
+ * @example
155
+ * ```typescript
156
+ * import { getSimulationTip } from 'stxer';
157
+ *
158
+ * const tip = await getSimulationTip(sessionId);
159
+ * if (tip.synthetic) {
160
+ * console.log('synthetic tip vrf_seed:', tip.vrf_seed);
161
+ * }
162
+ * ```
163
+ */
164
+ export declare function getSimulationTip(sessionId: string, options?: SimulationApiOptions): Promise<SimulationTipResponse>;
116
165
  /**
117
166
  * Batch reads from a simulation session
118
167
  *
@@ -1,6 +1,8 @@
1
1
  import { type StacksNetworkName } from '@stacks/network';
2
- import { type ClarityValue, ClarityVersion } from '@stacks/transactions';
3
- import type { ReadStep } from './types';
2
+ import { type ClarityValue, ClarityVersion, PostConditionMode } from '@stacks/transactions';
3
+ import { type SimulationApiOptions } from './simulation-api';
4
+ import { type ContractCallTxArgs } from './transaction';
5
+ import type { AdvanceBlocksRequest, ReadStep, TenureExtendCause, TransactionReceipt } from './types';
4
6
  export interface SimulationEval {
5
7
  contract_id: string;
6
8
  code: string;
@@ -53,9 +55,74 @@ export declare class SimulationBuilder {
53
55
  clarity_version?: ClarityVersion;
54
56
  }): this;
55
57
  addReads(reads: ReadStep[]): this;
56
- addTenureExtend(): this;
58
+ /**
59
+ * Add a `TenureExtend` step. Defaults to `cause: 'Extended'` (full
60
+ * cost reset) — equivalent in server-side behavior to the legacy
61
+ * zero-arg call.
62
+ *
63
+ * Pass an explicit `TenureExtendCause` to reset only one SIP-034
64
+ * dimension (`ExtendedRuntime` / `ExtendedReadCount` / etc.).
65
+ *
66
+ * On the wire SDK 0.8.0 emits the modern `{ TenureExtend: { cause } }`
67
+ * shape. The server still parses the legacy `[]` shape for any
68
+ * caller emitting raw step objects.
69
+ */
70
+ addTenureExtend(cause?: TenureExtendCause): this;
71
+ /**
72
+ * Synthesize bitcoin and stacks blocks on top of the simulation's
73
+ * pinned parent tip. Used to model burn-block / tenure boundaries
74
+ * (bridge contracts, time-locked redemptions, locked-STX unlock).
75
+ *
76
+ * The simulator validates the request shape; older simulator builds
77
+ * that don't yet support `AdvanceBlocks` reject this variant with
78
+ * HTTP 400.
79
+ *
80
+ * @example
81
+ * ```typescript
82
+ * builder.addAdvanceBlocks({
83
+ * bitcoin_blocks: 1,
84
+ * stacks_blocks_per_bitcoin: 1,
85
+ * });
86
+ * ```
87
+ */
88
+ addAdvanceBlocks(request: AdvanceBlocksRequest): this;
57
89
  private getBlockInfo;
58
90
  run(): Promise<string>;
59
91
  pipe(transform: (builder: SimulationBuilder) => SimulationBuilder): SimulationBuilder;
60
92
  }
93
+ export interface CallContractResult {
94
+ /** Decoded Clarity result (e.g. `(ok true)`, `(err u100)`, `u5`). */
95
+ result: string;
96
+ /** Hex-encoded raw Clarity result (SIP-005). */
97
+ resultHex: string;
98
+ /** VM-level error message, if any (e.g. arithmetic overflow). */
99
+ vmError: string | null;
100
+ /** True when one or more post-conditions tripped. */
101
+ pcAborted: boolean;
102
+ /** Full upstream receipt for callers that need more detail. */
103
+ receipt: TransactionReceipt;
104
+ }
105
+ /**
106
+ * Build, submit, and decode a contract-call transaction. The caller
107
+ * supplies the principal to use as `tx-sender`; nonce is auto-fetched
108
+ * via {@link getNonce} unless `nonce` is explicitly provided.
109
+ */
110
+ export declare function callContract(sessionId: string, args: Omit<ContractCallTxArgs, 'nonce'> & {
111
+ nonce?: number;
112
+ postConditionMode?: PostConditionMode;
113
+ }, options?: SimulationApiOptions): Promise<CallContractResult>;
114
+ /**
115
+ * Read the SIP-010 / hBTC-style `(get-balance principal)` value.
116
+ * Returns 0n if the read returns `(err …)`. Throws on infra failures.
117
+ */
118
+ export declare function getFtBalance(sessionId: string, contractId: string, principal: string, options?: SimulationApiOptions): Promise<bigint>;
119
+ /** Read a principal's STX balance (uSTX) from a simulation session. */
120
+ export declare function getStxBalance(sessionId: string, principal: string, options?: SimulationApiOptions): Promise<bigint>;
121
+ /** Read a principal's current nonce. Returns 0n if never seen. */
122
+ export declare function getNonce(sessionId: string, principal: string, options?: SimulationApiOptions): Promise<bigint>;
123
+ /**
124
+ * Read a Clarity data variable. Returns the decoded `ClarityValue`,
125
+ * or throws if the read failed.
126
+ */
127
+ export declare function readDataVar(sessionId: string, contractId: string, varName: string, options?: SimulationApiOptions): Promise<ClarityValue>;
61
128
  export type { CreateSimulationRequest, ExecutionCost, InstantSimulationRequest, InstantSimulationResponse, ReadResult, ReadStep, SimulationMetadata, SimulationResult, SimulationStepInput, TransactionReceipt, } from './types';