stxer 0.6.1 → 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/CHANGELOG.md +118 -0
- package/README.md +300 -55
- package/dist/ast.d.ts +1 -1
- package/dist/batch-api.d.ts +2 -1
- package/dist/bitcoin.d.ts +121 -0
- package/dist/index.d.ts +3 -1
- package/dist/simulation-api.d.ts +52 -3
- package/dist/simulation.d.ts +70 -3
- package/dist/stxer.cjs.development.js +917 -104
- 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 +897 -107
- package/dist/stxer.esm.js.map +1 -1
- package/dist/transaction.d.ts +71 -0
- package/dist/types.d.ts +547 -54
- package/package.json +17 -10
- package/src/ast.ts +1 -1
- package/src/batch-api.ts +9 -8
- package/src/bitcoin.ts +391 -0
- package/src/index.ts +7 -10
- package/src/simulation-api.ts +110 -13
- package/src/simulation.ts +245 -46
- package/src/transaction.ts +141 -0
- package/src/types.ts +594 -59
package/dist/types.d.ts
CHANGED
|
@@ -2,25 +2,40 @@
|
|
|
2
2
|
* Type definitions for stxer-api V2 endpoints
|
|
3
3
|
* Hand-written types based on OpenAPI spec at https://api.stxer.xyz/openapi.json
|
|
4
4
|
*/
|
|
5
|
+
/**
|
|
6
|
+
* Rust `u64` / `u128` fields serialize as JSON numbers but can exceed JS
|
|
7
|
+
* `Number.MAX_SAFE_INTEGER` (2^53 - 1). Accept either form: numbers are
|
|
8
|
+
* convenient for small values, decimal strings preserve full precision
|
|
9
|
+
* for large ones. Mirrors how `pox_addrs[k].payout` (u128) is typed.
|
|
10
|
+
*
|
|
11
|
+
* In practice nearly all values fit in `Number` — this typing exists so
|
|
12
|
+
* code that *might* see a large value (post-genesis cumulative cost
|
|
13
|
+
* counters, accumulated stx_burned in long simulations) cannot silently
|
|
14
|
+
* lose precision. Use `BigInt(x)` to normalize before arithmetic when in
|
|
15
|
+
* doubt.
|
|
16
|
+
*/
|
|
17
|
+
export type U64 = number | string;
|
|
18
|
+
/** Rust `u128`. See {@link U64} for usage notes. */
|
|
19
|
+
export type U128 = number | string;
|
|
5
20
|
export interface TenureCost {
|
|
6
|
-
read_count:
|
|
7
|
-
read_length:
|
|
8
|
-
write_count:
|
|
9
|
-
write_length:
|
|
10
|
-
runtime:
|
|
21
|
+
read_count: U64;
|
|
22
|
+
read_length: U64;
|
|
23
|
+
write_count: U64;
|
|
24
|
+
write_length: U64;
|
|
25
|
+
runtime: U64;
|
|
11
26
|
}
|
|
12
27
|
export interface SidecarTip {
|
|
13
28
|
bitcoin_height: number;
|
|
14
29
|
block_hash: string;
|
|
15
|
-
block_height:
|
|
16
|
-
block_time:
|
|
30
|
+
block_height: U64;
|
|
31
|
+
block_time: U64;
|
|
17
32
|
burn_block_height: number;
|
|
18
|
-
burn_block_time:
|
|
33
|
+
burn_block_time: U64;
|
|
19
34
|
consensus_hash: string;
|
|
20
35
|
index_block_hash: string;
|
|
21
36
|
is_nakamoto: boolean;
|
|
22
37
|
tenure_cost: TenureCost;
|
|
23
|
-
tenure_height:
|
|
38
|
+
tenure_height: U64;
|
|
24
39
|
sortition_id: string;
|
|
25
40
|
epoch_id: string;
|
|
26
41
|
}
|
|
@@ -94,7 +109,26 @@ export interface ClarityAbiNonFungibleToken {
|
|
|
94
109
|
type: ClarityAbiType;
|
|
95
110
|
}
|
|
96
111
|
export type ClarityEpoch = 'Epoch10' | 'Epoch20' | 'Epoch2_05' | 'Epoch21' | 'Epoch22' | 'Epoch23' | 'Epoch24' | 'Epoch25' | 'Epoch30' | 'Epoch31' | 'Epoch32' | 'Epoch33' | 'Epoch34' | 'Epoch35';
|
|
97
|
-
|
|
112
|
+
/**
|
|
113
|
+
* Wire-format Clarity version name as emitted by the stxer AST parser
|
|
114
|
+
* (`/contracts:parse-ast`). Used in {@link ClarityAbi.clarity_version}.
|
|
115
|
+
*
|
|
116
|
+
* **Distinct from the numeric `ClarityVersion` enum re-exported by
|
|
117
|
+
* `@stacks/transactions`** (1..5), which is what the SDK builder
|
|
118
|
+
* methods (`addContractDeploy`, `makeUnsignedContractDeploy`, etc.)
|
|
119
|
+
* accept. To build transactions:
|
|
120
|
+
*
|
|
121
|
+
* import { ClarityVersion } from '@stacks/transactions';
|
|
122
|
+
* // ClarityVersion.Clarity5 -> 5
|
|
123
|
+
*
|
|
124
|
+
* To check an AST response:
|
|
125
|
+
*
|
|
126
|
+
* import type { ClarityVersionName } from 'stxer';
|
|
127
|
+
* if (abi.clarity_version === 'Clarity5') { ... }
|
|
128
|
+
*/
|
|
129
|
+
export type ClarityVersionName = 'Clarity1' | 'Clarity2' | 'Clarity3' | 'Clarity4' | 'Clarity5';
|
|
130
|
+
/** @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. */
|
|
131
|
+
export type ClarityVersion = ClarityVersionName;
|
|
98
132
|
export interface ClarityAbi {
|
|
99
133
|
functions: ClarityAbiFunction[];
|
|
100
134
|
variables: ClarityAbiVariable[];
|
|
@@ -102,7 +136,7 @@ export interface ClarityAbi {
|
|
|
102
136
|
fungible_tokens: ClarityAbiFungibleToken[];
|
|
103
137
|
non_fungible_tokens: ClarityAbiNonFungibleToken[];
|
|
104
138
|
epoch: ClarityEpoch;
|
|
105
|
-
clarity_version:
|
|
139
|
+
clarity_version: ClarityVersionName;
|
|
106
140
|
}
|
|
107
141
|
export interface SymbolicExpressionField {
|
|
108
142
|
field: string;
|
|
@@ -157,20 +191,72 @@ export interface ContractAST {
|
|
|
157
191
|
abi?: ClarityAbi;
|
|
158
192
|
}
|
|
159
193
|
export interface ExecutionCost {
|
|
160
|
-
read_count:
|
|
161
|
-
read_length:
|
|
162
|
-
write_count:
|
|
163
|
-
write_length:
|
|
164
|
-
runtime:
|
|
194
|
+
read_count: U64;
|
|
195
|
+
read_length: U64;
|
|
196
|
+
write_count: U64;
|
|
197
|
+
write_length: U64;
|
|
198
|
+
runtime: U64;
|
|
165
199
|
}
|
|
200
|
+
/**
|
|
201
|
+
* Receipt for a transaction that the engine executed to completion.
|
|
202
|
+
*
|
|
203
|
+
* "Successful execution" does NOT imply contract-level success. Four
|
|
204
|
+
* failure signals to check, in this order:
|
|
205
|
+
* 1. Outer `Err` on `Result.Transaction` — engine could not run the tx
|
|
206
|
+
* at all (deserialization failure etc.); no receipt is produced.
|
|
207
|
+
* 2. `post_condition_aborted: true` — execution ran, post-condition
|
|
208
|
+
* tripped, state was rolled back.
|
|
209
|
+
* 3. `vm_error: string` (without `post_condition_aborted`) — Clarity
|
|
210
|
+
* VM raised a runtime error or static analysis failed.
|
|
211
|
+
* 4. `(err uX)` inside `result` — contract returned a Clarity error
|
|
212
|
+
* response. Application-level; NOT signalled by any field above.
|
|
213
|
+
* Decode `result` to detect.
|
|
214
|
+
*
|
|
215
|
+
* `post_condition_aborted` and `vm_error` are NOT independent: when a
|
|
216
|
+
* PC trips the upstream sets `post_condition_aborted: true` AND writes
|
|
217
|
+
* the PC abort reason into `vm_error` as a side effect. The reverse is
|
|
218
|
+
* not true — `vm_error` alone (with `post_condition_aborted: false`)
|
|
219
|
+
* means a VM / analysis failure that is not a PC abort.
|
|
220
|
+
*/
|
|
166
221
|
export interface TransactionReceipt {
|
|
222
|
+
/**
|
|
223
|
+
* Clarity return value, SIP-005 hex-serialized. For contract-call txs
|
|
224
|
+
* this includes the `(ok ...)` / `(err ...)` response wrapper —
|
|
225
|
+
* Clarity-level `(err uX)` lives here, NOT on `vm_error` or the outer
|
|
226
|
+
* `Err`.
|
|
227
|
+
*/
|
|
167
228
|
result: string;
|
|
168
|
-
|
|
229
|
+
/**
|
|
230
|
+
* STX (in micro-STX) burned by this transaction. u128 — accept as
|
|
231
|
+
* `number | string` to preserve precision above 2^53.
|
|
232
|
+
*/
|
|
233
|
+
stx_burned: U128;
|
|
169
234
|
tx_index: number;
|
|
235
|
+
/**
|
|
236
|
+
* Error message from the upstream Clarity VM. `null` when the tx had
|
|
237
|
+
* no VM-level issue. When `post_condition_aborted` is `true` this
|
|
238
|
+
* field is also populated with the PC abort reason — check
|
|
239
|
+
* `post_condition_aborted` first to disambiguate.
|
|
240
|
+
*/
|
|
170
241
|
vm_error: string | null;
|
|
242
|
+
/**
|
|
243
|
+
* `true` when one or more post-conditions failed and the tx was
|
|
244
|
+
* aborted. Implies `vm_error` is also set (to the abort reason); the
|
|
245
|
+
* reverse does not hold.
|
|
246
|
+
*/
|
|
171
247
|
post_condition_aborted: boolean;
|
|
248
|
+
/** Wall-clock simulation time in milliseconds. */
|
|
172
249
|
costs: number;
|
|
173
250
|
execution_cost: ExecutionCost;
|
|
251
|
+
/**
|
|
252
|
+
* Events emitted during execution (contract logs, STX transfers,
|
|
253
|
+
* FT/NFT events, etc.). Each entry is a JSON-encoded **string** —
|
|
254
|
+
* call `JSON.parse(events[i])` to get the event object. Items are
|
|
255
|
+
* NOT JSON objects in the array.
|
|
256
|
+
*
|
|
257
|
+
* For typed access, use {@link parseSimulationEvent} or cast:
|
|
258
|
+
* `JSON.parse(events[i]) as SimulationEvent`.
|
|
259
|
+
*/
|
|
174
260
|
events: string[];
|
|
175
261
|
}
|
|
176
262
|
export interface TransactionOkResult {
|
|
@@ -179,25 +265,200 @@ export interface TransactionOkResult {
|
|
|
179
265
|
export interface TransactionErrResult {
|
|
180
266
|
Err: string;
|
|
181
267
|
}
|
|
268
|
+
/** Common envelope present on every event variant. */
|
|
269
|
+
interface SimulationEventBase {
|
|
270
|
+
/** Hex txid with leading `0x`. */
|
|
271
|
+
txid: string;
|
|
272
|
+
event_index: number;
|
|
273
|
+
/**
|
|
274
|
+
* `true` when the event was emitted from successfully committed code.
|
|
275
|
+
* `false` when the tx was rolled back (post-condition abort, vm_error).
|
|
276
|
+
* Tracks rust `tx_receipt.vm_error.is_none() && !post_condition_aborted`.
|
|
277
|
+
*/
|
|
278
|
+
committed: boolean;
|
|
279
|
+
}
|
|
280
|
+
/** Payload for `print` events and other contract-emitted events. */
|
|
281
|
+
export interface SmartContractEventData {
|
|
282
|
+
/** `<address>.<contract_name>` of the contract that emitted the event. */
|
|
283
|
+
contract_identifier: string;
|
|
284
|
+
/** Topic key — `"print"` for `(print …)` calls. */
|
|
285
|
+
topic: string;
|
|
286
|
+
/**
|
|
287
|
+
* Structured Clarity Value JSON (the rust `Value` enum's serde output).
|
|
288
|
+
* The shape is complex and varies by Clarity type; prefer `raw_value`
|
|
289
|
+
* for typed decoding.
|
|
290
|
+
*/
|
|
291
|
+
value: unknown;
|
|
292
|
+
/**
|
|
293
|
+
* SIP-005 hex of the value, with leading `0x`. Pass to
|
|
294
|
+
* `deserializeCV()` from `@stacks/transactions` for typed decoding.
|
|
295
|
+
*/
|
|
296
|
+
raw_value: string;
|
|
297
|
+
}
|
|
298
|
+
export interface StxTransferEventData {
|
|
299
|
+
sender: string;
|
|
300
|
+
recipient: string;
|
|
301
|
+
/** uSTX amount as a decimal string (rust serializes u128 via Display). */
|
|
302
|
+
amount: string;
|
|
303
|
+
/** Hex memo, possibly empty. */
|
|
304
|
+
memo: string;
|
|
305
|
+
}
|
|
306
|
+
export interface StxMintEventData {
|
|
307
|
+
recipient: string;
|
|
308
|
+
amount: string;
|
|
309
|
+
}
|
|
310
|
+
export interface StxBurnEventData {
|
|
311
|
+
sender: string;
|
|
312
|
+
amount: string;
|
|
313
|
+
}
|
|
314
|
+
export interface StxLockEventData {
|
|
315
|
+
locked_amount: string;
|
|
316
|
+
/** Decimal string (rust serializes u64 via Display). */
|
|
317
|
+
unlock_height: string;
|
|
318
|
+
locked_address: string;
|
|
319
|
+
contract_identifier: string;
|
|
320
|
+
}
|
|
321
|
+
export interface NftTransferEventData {
|
|
322
|
+
/** `<contract_id>::<asset_name>`. */
|
|
323
|
+
asset_identifier: string;
|
|
324
|
+
sender: string;
|
|
325
|
+
recipient: string;
|
|
326
|
+
value: unknown;
|
|
327
|
+
raw_value: string;
|
|
328
|
+
}
|
|
329
|
+
export interface NftMintEventData {
|
|
330
|
+
asset_identifier: string;
|
|
331
|
+
recipient: string;
|
|
332
|
+
value: unknown;
|
|
333
|
+
raw_value: string;
|
|
334
|
+
}
|
|
335
|
+
export interface NftBurnEventData {
|
|
336
|
+
asset_identifier: string;
|
|
337
|
+
sender: string;
|
|
338
|
+
value: unknown;
|
|
339
|
+
raw_value: string;
|
|
340
|
+
}
|
|
341
|
+
export interface FtTransferEventData {
|
|
342
|
+
asset_identifier: string;
|
|
343
|
+
sender: string;
|
|
344
|
+
recipient: string;
|
|
345
|
+
amount: string;
|
|
346
|
+
}
|
|
347
|
+
export interface FtMintEventData {
|
|
348
|
+
asset_identifier: string;
|
|
349
|
+
recipient: string;
|
|
350
|
+
amount: string;
|
|
351
|
+
}
|
|
352
|
+
export interface FtBurnEventData {
|
|
353
|
+
asset_identifier: string;
|
|
354
|
+
sender: string;
|
|
355
|
+
amount: string;
|
|
356
|
+
}
|
|
357
|
+
/**
|
|
358
|
+
* Discriminated union of every event variant the simulator emits.
|
|
359
|
+
* The `type` discriminator names the per-variant payload key — e.g.
|
|
360
|
+
* `type: 'contract_event'` carries the payload at `event.contract_event`.
|
|
361
|
+
*
|
|
362
|
+
* ```ts
|
|
363
|
+
* const event = parseSimulationEvent(receipt.events[0]);
|
|
364
|
+
* if (event.type === 'contract_event') {
|
|
365
|
+
* // event.contract_event.{contract_identifier, topic, raw_value, value}
|
|
366
|
+
* }
|
|
367
|
+
* ```
|
|
368
|
+
*/
|
|
369
|
+
export type SimulationEvent = (SimulationEventBase & {
|
|
370
|
+
type: 'contract_event';
|
|
371
|
+
contract_event: SmartContractEventData;
|
|
372
|
+
}) | (SimulationEventBase & {
|
|
373
|
+
type: 'stx_transfer_event';
|
|
374
|
+
stx_transfer_event: StxTransferEventData;
|
|
375
|
+
}) | (SimulationEventBase & {
|
|
376
|
+
type: 'stx_mint_event';
|
|
377
|
+
stx_mint_event: StxMintEventData;
|
|
378
|
+
}) | (SimulationEventBase & {
|
|
379
|
+
type: 'stx_burn_event';
|
|
380
|
+
stx_burn_event: StxBurnEventData;
|
|
381
|
+
}) | (SimulationEventBase & {
|
|
382
|
+
type: 'stx_lock_event';
|
|
383
|
+
stx_lock_event: StxLockEventData;
|
|
384
|
+
}) | (SimulationEventBase & {
|
|
385
|
+
type: 'nft_transfer_event';
|
|
386
|
+
nft_transfer_event: NftTransferEventData;
|
|
387
|
+
}) | (SimulationEventBase & {
|
|
388
|
+
type: 'nft_mint_event';
|
|
389
|
+
nft_mint_event: NftMintEventData;
|
|
390
|
+
}) | (SimulationEventBase & {
|
|
391
|
+
type: 'nft_burn_event';
|
|
392
|
+
nft_burn_event: NftBurnEventData;
|
|
393
|
+
}) | (SimulationEventBase & {
|
|
394
|
+
type: 'ft_transfer_event';
|
|
395
|
+
ft_transfer_event: FtTransferEventData;
|
|
396
|
+
}) | (SimulationEventBase & {
|
|
397
|
+
type: 'ft_mint_event';
|
|
398
|
+
ft_mint_event: FtMintEventData;
|
|
399
|
+
}) | (SimulationEventBase & {
|
|
400
|
+
type: 'ft_burn_event';
|
|
401
|
+
ft_burn_event: FtBurnEventData;
|
|
402
|
+
});
|
|
403
|
+
/** Convenience parser for `TransactionReceipt.events[i]`. */
|
|
404
|
+
export declare function parseSimulationEvent(raw: string): SimulationEvent;
|
|
182
405
|
export interface MapEntryStep {
|
|
183
|
-
MapEntry: [string, string, string];
|
|
406
|
+
MapEntry: [contract_id: string, map_name: string, key_hex: string];
|
|
184
407
|
}
|
|
185
408
|
export interface DataVarStep {
|
|
186
|
-
DataVar: [string, string];
|
|
409
|
+
DataVar: [contract_id: string, variable_name: string];
|
|
187
410
|
}
|
|
411
|
+
/**
|
|
412
|
+
* Evaluate an arbitrary read-only Clarity expression in the context of
|
|
413
|
+
* `sender` (and optional `sponsor`). The Clarity analyzer rejects any
|
|
414
|
+
* expression that would mutate state, so this is a pure projection.
|
|
415
|
+
*
|
|
416
|
+
* Use when a plain `DataVar` / `MapEntry` read isn't enough — read-only
|
|
417
|
+
* `contract-call?` projections, custom expressions, or anything that
|
|
418
|
+
* needs a specific sender principal in scope. Cheaper than `Eval` (no
|
|
419
|
+
* write access, no step slot) and the only sender-context read shape.
|
|
420
|
+
*
|
|
421
|
+
* Choosing between read variants:
|
|
422
|
+
* - `DataVar` / `MapEntry` — direct storage reads, no Clarity
|
|
423
|
+
* evaluation; cheapest.
|
|
424
|
+
* - `EvalReadonly` — arbitrary read-only Clarity in sender/sponsor
|
|
425
|
+
* context; analyzer-enforced no writes.
|
|
426
|
+
* - `Eval` (top-level step variant on {@link SimulationStepInput},
|
|
427
|
+
* NOT a Reads sub-type) — arbitrary Clarity with **write access**.
|
|
428
|
+
* Use only when you need to mutate state.
|
|
429
|
+
* - `Transaction` — real Stacks tx with receipt, events,
|
|
430
|
+
* post-conditions, fee, nonce.
|
|
431
|
+
*
|
|
432
|
+
* @example
|
|
433
|
+
* { EvalReadonly: ['SP...sender', '', 'SP...contract', '(get-counter)'] }
|
|
434
|
+
* { EvalReadonly: ['SP...sender', '', 'SP...oracle', "(contract-call? .oracle get-value 'STX-USD)"] }
|
|
435
|
+
*/
|
|
188
436
|
export interface EvalReadonlyStep {
|
|
189
|
-
|
|
437
|
+
/** `sponsor` is `""` (empty string) when there is no sponsor. */
|
|
438
|
+
EvalReadonly: [
|
|
439
|
+
sender: string,
|
|
440
|
+
sponsor: string,
|
|
441
|
+
contract_id: string,
|
|
442
|
+
code: string
|
|
443
|
+
];
|
|
190
444
|
}
|
|
191
445
|
export interface StxBalanceStep {
|
|
446
|
+
/** Principal whose STX balance to read. */
|
|
192
447
|
StxBalance: string;
|
|
193
448
|
}
|
|
194
449
|
export interface FtBalanceStep {
|
|
195
|
-
|
|
450
|
+
/**
|
|
451
|
+
* Reads the FT balance via three separate parameters. Note: the batch
|
|
452
|
+
* `ft_balance` field on `SimulationBatchReadsRequest` uses a different
|
|
453
|
+
* `<contract_id>::<token_name>` combined identifier shape.
|
|
454
|
+
*/
|
|
455
|
+
FtBalance: [contract_id: string, token_name: string, principal: string];
|
|
196
456
|
}
|
|
197
457
|
export interface FtSupplyStep {
|
|
198
|
-
FtSupply: [string, string];
|
|
458
|
+
FtSupply: [contract_id: string, token_name: string];
|
|
199
459
|
}
|
|
200
460
|
export interface NonceStep {
|
|
461
|
+
/** Principal whose nonce to read. */
|
|
201
462
|
Nonce: string;
|
|
202
463
|
}
|
|
203
464
|
export type ReadStep = MapEntryStep | DataVarStep | EvalReadonlyStep | StxBalanceStep | FtBalanceStep | FtSupplyStep | NonceStep;
|
|
@@ -208,8 +469,124 @@ export interface ReadErrResult {
|
|
|
208
469
|
Err: string;
|
|
209
470
|
}
|
|
210
471
|
export type ReadResult = ReadOkResult | ReadErrResult;
|
|
472
|
+
/**
|
|
473
|
+
* Tenure-extend cause. `Extended` resets all cost dimensions; the
|
|
474
|
+
* SIP-034 variants reset a single dimension only.
|
|
475
|
+
*/
|
|
476
|
+
export type TenureExtendCause = 'Extended' | 'ExtendedRuntime' | 'ExtendedReadCount' | 'ExtendedReadLength' | 'ExtendedWriteCount' | 'ExtendedWriteLength';
|
|
477
|
+
/** PoX address used inside `AdvanceBlocksRequest.pox_addrs`. */
|
|
478
|
+
export interface PoxAddrInput {
|
|
479
|
+
/** Address version byte (0..255). */
|
|
480
|
+
version: number;
|
|
481
|
+
/** Address hashbytes as hex (no `0x` prefix). */
|
|
482
|
+
hashbytes: string;
|
|
483
|
+
}
|
|
484
|
+
/**
|
|
485
|
+
* Request payload for the `AdvanceBlocks` step variant. Synthesizes
|
|
486
|
+
* bitcoin and stacks blocks on top of the simulation's pinned parent
|
|
487
|
+
* tip. Hex strings for 32-byte hashes / VRF seeds; PoX address
|
|
488
|
+
* overrides use the tuple form `[addrs, payout_ustx]` on the wire.
|
|
489
|
+
*/
|
|
490
|
+
export interface AdvanceBlocksRequest {
|
|
491
|
+
bitcoin_blocks: number;
|
|
492
|
+
stacks_blocks_per_bitcoin: number;
|
|
493
|
+
/** Defaults to 600 (mainnet target) upstream when omitted. */
|
|
494
|
+
bitcoin_interval_secs?: U64;
|
|
495
|
+
/**
|
|
496
|
+
* Per-burn-index burn-header-hash overrides, keyed by 0-based burn
|
|
497
|
+
* index within this batch. Hex strings (32 bytes, with or without
|
|
498
|
+
* `0x` prefix).
|
|
499
|
+
*/
|
|
500
|
+
burn_header_hashes?: Record<string, string>;
|
|
501
|
+
/**
|
|
502
|
+
* Per-burn-index PoX address overrides as `[addrs, payout_ustx]`.
|
|
503
|
+
* `payout_ustx` is `u128` upstream — see {@link U128}.
|
|
504
|
+
*/
|
|
505
|
+
pox_addrs?: Record<string, [PoxAddrInput[], U128]>;
|
|
506
|
+
/** Per-burn-index VRF-seed overrides as 32-byte hex strings. */
|
|
507
|
+
vrf_seeds?: Record<string, string>;
|
|
508
|
+
}
|
|
509
|
+
/**
|
|
510
|
+
* One synthesized block produced by an `AdvanceBlocks` step. Returned
|
|
511
|
+
* inside `SimulationStepResult.AdvanceBlocks.Ok` and as the `tip`
|
|
512
|
+
* fields when synthetic.
|
|
513
|
+
*/
|
|
514
|
+
export interface AdvancedBlockSummary {
|
|
515
|
+
stacks_height: U64;
|
|
516
|
+
burn_height: number;
|
|
517
|
+
coinbase_height: number;
|
|
518
|
+
index_block_hash: string;
|
|
519
|
+
burn_header_hash: string;
|
|
520
|
+
vrf_seed: string;
|
|
521
|
+
block_time: U64;
|
|
522
|
+
burn_block_time: U64;
|
|
523
|
+
/**
|
|
524
|
+
* `true` when this synthetic block is the first stacks block in a
|
|
525
|
+
* new tenure (i.e. follows a synthesized bitcoin block).
|
|
526
|
+
*/
|
|
527
|
+
tenure_change: boolean;
|
|
528
|
+
}
|
|
529
|
+
/**
|
|
530
|
+
* Response shape for `GET /devtools/v2/simulations/{id}/tip`. When
|
|
531
|
+
* `synthetic` is `false`, fields mirror the parent metadata pinned at
|
|
532
|
+
* session start; `vrf_seed` and `tenure_change` are omitted in that
|
|
533
|
+
* case.
|
|
534
|
+
*/
|
|
535
|
+
export interface SimulationTipResponse {
|
|
536
|
+
synthetic: boolean;
|
|
537
|
+
stacks_height: U64;
|
|
538
|
+
burn_height: number;
|
|
539
|
+
coinbase_height: number;
|
|
540
|
+
block_time: U64;
|
|
541
|
+
burn_block_time: U64;
|
|
542
|
+
index_block_hash: string;
|
|
543
|
+
consensus_hash: string;
|
|
544
|
+
burn_header_hash: string;
|
|
545
|
+
sortition_id: string;
|
|
546
|
+
epoch: string;
|
|
547
|
+
/** Only present when `synthetic` is `true`. */
|
|
548
|
+
vrf_seed?: string;
|
|
549
|
+
/** Only present when `synthetic` is `true`. */
|
|
550
|
+
tenure_change?: boolean;
|
|
551
|
+
}
|
|
552
|
+
/**
|
|
553
|
+
* Per-step result returned by `POST /devtools/v2/simulations/{id}` (the
|
|
554
|
+
* "submit steps" endpoint). Externally tagged — exactly one variant key
|
|
555
|
+
* is present per object.
|
|
556
|
+
*
|
|
557
|
+
* Distinct from `SimulationStepSummary`, which is what
|
|
558
|
+
* `GET /devtools/v2/simulations/{id}` returns and includes the original
|
|
559
|
+
* step input alongside the result.
|
|
560
|
+
*/
|
|
561
|
+
export type SimulationStepResult = {
|
|
562
|
+
Transaction: TransactionOkResult | TransactionErrResult;
|
|
563
|
+
} | {
|
|
564
|
+
Eval: {
|
|
565
|
+
Ok: string;
|
|
566
|
+
} | {
|
|
567
|
+
Err: string;
|
|
568
|
+
};
|
|
569
|
+
} | {
|
|
570
|
+
SetContractCode: {
|
|
571
|
+
Ok: null;
|
|
572
|
+
} | {
|
|
573
|
+
Err: string;
|
|
574
|
+
};
|
|
575
|
+
} | {
|
|
576
|
+
Reads: ReadResult[];
|
|
577
|
+
} | {
|
|
578
|
+
TenureExtend: ExecutionCost;
|
|
579
|
+
} | {
|
|
580
|
+
AdvanceBlocks: {
|
|
581
|
+
Ok: AdvancedBlockSummary[];
|
|
582
|
+
} | {
|
|
583
|
+
Err: string;
|
|
584
|
+
};
|
|
585
|
+
};
|
|
211
586
|
export interface TransactionStepSummary {
|
|
587
|
+
/** Transaction serialized to hex. */
|
|
212
588
|
Transaction: string;
|
|
589
|
+
/** Hex-encoded txid. Empty string `""` when the tx failed engine-level. */
|
|
213
590
|
TxId: string;
|
|
214
591
|
Result: {
|
|
215
592
|
Transaction: TransactionOkResult | TransactionErrResult;
|
|
@@ -223,7 +600,7 @@ export interface ReadsStepSummary {
|
|
|
223
600
|
};
|
|
224
601
|
}
|
|
225
602
|
export interface SetContractCodeStepSummary {
|
|
226
|
-
SetContractCode: [string, string, number];
|
|
603
|
+
SetContractCode: [contract_id: string, code: string, clarity_version: number];
|
|
227
604
|
Result: {
|
|
228
605
|
SetContractCode: {
|
|
229
606
|
Ok: null;
|
|
@@ -233,7 +610,8 @@ export interface SetContractCodeStepSummary {
|
|
|
233
610
|
};
|
|
234
611
|
}
|
|
235
612
|
export interface EvalStepSummary {
|
|
236
|
-
|
|
613
|
+
/** `sponsor` is `""` (empty string) when there is no sponsor. */
|
|
614
|
+
Eval: [sender: string, sponsor: string, contract_id: string, code: string];
|
|
237
615
|
Result: {
|
|
238
616
|
Eval: {
|
|
239
617
|
Ok: string;
|
|
@@ -242,15 +620,50 @@ export interface EvalStepSummary {
|
|
|
242
620
|
};
|
|
243
621
|
};
|
|
244
622
|
}
|
|
623
|
+
/**
|
|
624
|
+
* Echoed `AdvanceBlocks` input as serialized in the summary response.
|
|
625
|
+
* Differs from the request shape ({@link AdvanceBlocksRequest}) in two
|
|
626
|
+
* places: `bitcoin_interval_secs` is nullable (serde `Option`); each
|
|
627
|
+
* `pox_addrs` value is the `{addrs, payout}` object form (vs. the
|
|
628
|
+
* request's tuple form).
|
|
629
|
+
*/
|
|
630
|
+
export interface AdvanceBlocksStepEcho {
|
|
631
|
+
bitcoin_blocks: number;
|
|
632
|
+
stacks_blocks_per_bitcoin: number;
|
|
633
|
+
bitcoin_interval_secs: U64 | null;
|
|
634
|
+
burn_header_hashes: Record<string, string>;
|
|
635
|
+
pox_addrs: Record<string, {
|
|
636
|
+
addrs: PoxAddrInput[];
|
|
637
|
+
payout: U128;
|
|
638
|
+
}>;
|
|
639
|
+
vrf_seeds: Record<string, string>;
|
|
640
|
+
}
|
|
245
641
|
export interface TenureExtendStepSummary {
|
|
642
|
+
/**
|
|
643
|
+
* Echoed input shape. The server normalizes legacy `{TenureExtend: []}`
|
|
644
|
+
* inputs to `{cause: 'Extended'}` at parse time, so the summary always
|
|
645
|
+
* carries the modern form regardless of how the step was submitted.
|
|
646
|
+
*/
|
|
647
|
+
TenureExtend: {
|
|
648
|
+
cause: TenureExtendCause;
|
|
649
|
+
};
|
|
246
650
|
Result: {
|
|
247
651
|
TenureExtend: ExecutionCost;
|
|
248
652
|
};
|
|
249
653
|
}
|
|
250
|
-
export
|
|
654
|
+
export interface AdvanceBlocksStepSummary {
|
|
655
|
+
AdvanceBlocks: AdvanceBlocksStepEcho;
|
|
656
|
+
Result: {
|
|
657
|
+
AdvanceBlocks: {
|
|
658
|
+
Ok: AdvancedBlockSummary[];
|
|
659
|
+
} | {
|
|
660
|
+
Err: string;
|
|
661
|
+
};
|
|
662
|
+
};
|
|
663
|
+
}
|
|
664
|
+
export type SimulationStepSummary = TransactionStepSummary | ReadsStepSummary | SetContractCodeStepSummary | EvalStepSummary | TenureExtendStepSummary | AdvanceBlocksStepSummary;
|
|
251
665
|
export interface SimulationMetadata {
|
|
252
|
-
|
|
253
|
-
block_height: number;
|
|
666
|
+
block_height: U64;
|
|
254
667
|
block_hash: string;
|
|
255
668
|
burn_block_height: number;
|
|
256
669
|
burn_block_hash: string;
|
|
@@ -265,63 +678,143 @@ export interface SimulationResult {
|
|
|
265
678
|
steps: SimulationStepSummary[];
|
|
266
679
|
}
|
|
267
680
|
export interface CreateSimulationRequest {
|
|
268
|
-
block_height?:
|
|
681
|
+
block_height?: U64;
|
|
269
682
|
block_hash?: string;
|
|
270
683
|
skip_tracing?: boolean;
|
|
271
684
|
}
|
|
272
685
|
export interface CreateSimulationResponse {
|
|
273
686
|
id: string;
|
|
274
687
|
}
|
|
688
|
+
/**
|
|
689
|
+
* One step submitted to `POST /devtools/v2/simulations/{id}`. Tagged
|
|
690
|
+
* union — exactly one variant key per object.
|
|
691
|
+
*
|
|
692
|
+
* **Picking the right Clarity-execution shape** — `Transaction` /
|
|
693
|
+
* `Eval` / `Reads` differ on side-effects, cost, and what they emit:
|
|
694
|
+
*
|
|
695
|
+
* - `Transaction` — full Stacks tx mechanics. Generates a
|
|
696
|
+
* `TransactionReceipt` (events, vm_error, post_condition_aborted,
|
|
697
|
+
* execution_cost), consumes nonce, charges fee, enforces
|
|
698
|
+
* post-conditions. The only variant that emits a receipt. Use when
|
|
699
|
+
* simulating a real user action.
|
|
700
|
+
* - `Eval` — arbitrary Clarity with **write access** to contract
|
|
701
|
+
* storage; no fee, no nonce, no post-conditions, no receipt — just
|
|
702
|
+
* the resulting Clarity value or err. Use to stub state mid-session
|
|
703
|
+
* (`var-set`, `map-set`, …) or run code with side-effects without
|
|
704
|
+
* tx ceremony.
|
|
705
|
+
* - `Reads` (batch of {@link ReadStep}, including `EvalReadonly`) —
|
|
706
|
+
* pure projection, no state changes, cheapest. Use when you only
|
|
707
|
+
* need to read derived data; `EvalReadonly` provides the
|
|
708
|
+
* sender/sponsor context that `DataVar` / `MapEntry` cannot.
|
|
709
|
+
*
|
|
710
|
+
* `SetContractCode` replaces a contract's code (write side-effects, no
|
|
711
|
+
* fee/nonce/receipt — like `Eval` but at the contract level).
|
|
712
|
+
* `TenureExtend` resets cost dimensions. `AdvanceBlocks` synthesizes
|
|
713
|
+
* burn/stacks blocks (see {@link AdvanceBlocksRequest}).
|
|
714
|
+
*
|
|
715
|
+
* `TenureExtend` accepts both legacy `[]` (treated server-side as
|
|
716
|
+
* `cause: 'Extended'`) and modern `{ cause }` shapes. SDK 0.8.0 emits
|
|
717
|
+
* the modern form via {@link SimulationBuilder.addTenureExtend}; the
|
|
718
|
+
* legacy shape stays in this union so consumers passing literal step
|
|
719
|
+
* objects (not via the builder) still type-check.
|
|
720
|
+
*/
|
|
275
721
|
export type SimulationStepInput = {
|
|
276
722
|
Transaction: string;
|
|
277
723
|
} | {
|
|
278
|
-
|
|
724
|
+
/** `sponsor` is `""` when there is no sponsor. */
|
|
725
|
+
Eval: [
|
|
726
|
+
sender: string,
|
|
727
|
+
sponsor: string,
|
|
728
|
+
contract_id: string,
|
|
729
|
+
code: string
|
|
730
|
+
];
|
|
279
731
|
} | {
|
|
280
|
-
SetContractCode: [
|
|
732
|
+
SetContractCode: [
|
|
733
|
+
contract_id: string,
|
|
734
|
+
code: string,
|
|
735
|
+
clarity_version: number
|
|
736
|
+
];
|
|
281
737
|
} | {
|
|
282
738
|
Reads: ReadStep[];
|
|
283
739
|
} | {
|
|
284
|
-
TenureExtend: []
|
|
740
|
+
TenureExtend: [] | {
|
|
741
|
+
cause: TenureExtendCause;
|
|
742
|
+
};
|
|
743
|
+
} | {
|
|
744
|
+
AdvanceBlocks: AdvanceBlocksRequest;
|
|
285
745
|
};
|
|
286
746
|
export interface SubmitSimulationStepsRequest {
|
|
287
747
|
steps: SimulationStepInput[];
|
|
288
748
|
}
|
|
289
749
|
export interface SubmitSimulationStepsResponse {
|
|
290
|
-
steps:
|
|
750
|
+
steps: SimulationStepResult[];
|
|
291
751
|
}
|
|
292
752
|
export interface SimulationBatchReadsRequest {
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
753
|
+
/** `[contract_id, variable_name]` per entry. */
|
|
754
|
+
vars?: [contract_id: string, variable_name: string][];
|
|
755
|
+
/** `[contract_id, map_name, key_hex]` per entry. */
|
|
756
|
+
maps?: [contract_id: string, map_name: string, key_hex: string][];
|
|
757
|
+
/**
|
|
758
|
+
* `[contract_id, function_name, ...arg_hex]` per entry. The first two
|
|
759
|
+
* positions are fixed; remaining elements are hex-encoded Clarity
|
|
760
|
+
* values, one per function argument (so the length matches the
|
|
761
|
+
* function's arity, not arbitrary).
|
|
762
|
+
*/
|
|
763
|
+
readonly?: [
|
|
764
|
+
contract_id: string,
|
|
765
|
+
function_name: string,
|
|
766
|
+
...args_hex: string[]
|
|
767
|
+
][];
|
|
768
|
+
/**
|
|
769
|
+
* `[sender, sponsor, contract_id, function_name, ...arg_hex]` per
|
|
770
|
+
* entry. The first four positions are fixed (`sponsor` is `""` when
|
|
771
|
+
* there is no sponsor); remaining elements are hex-encoded Clarity
|
|
772
|
+
* values, one per function argument.
|
|
773
|
+
*/
|
|
774
|
+
readonly_with_sender?: [
|
|
775
|
+
sender: string,
|
|
776
|
+
sponsor: string,
|
|
777
|
+
contract_id: string,
|
|
778
|
+
function_name: string,
|
|
779
|
+
...args_hex: string[]
|
|
780
|
+
][];
|
|
781
|
+
/** Principals to read STX balances for. */
|
|
303
782
|
stx?: string[];
|
|
783
|
+
/** Principals to read nonces for. */
|
|
304
784
|
nonces?: string[];
|
|
305
|
-
|
|
306
|
-
|
|
785
|
+
/** `[<contract_id>::<token_name>, principal]` per entry. */
|
|
786
|
+
ft_balance?: [token_identifier: string, principal: string][];
|
|
787
|
+
/**
|
|
788
|
+
* Flat array of FT identifiers in `<contract_id>::<token_name>` form,
|
|
789
|
+
* one entry per token to look up. Any length.
|
|
790
|
+
*/
|
|
791
|
+
ft_supply?: string[];
|
|
307
792
|
}
|
|
793
|
+
/**
|
|
794
|
+
* Each category is omitted from the JSON response when the corresponding
|
|
795
|
+
* request field was empty/absent (rust uses
|
|
796
|
+
* `serde(skip_serializing_if = "Vec::is_empty")` per field).
|
|
797
|
+
*/
|
|
308
798
|
export interface SimulationBatchReadsResponse {
|
|
309
|
-
vars
|
|
310
|
-
maps
|
|
311
|
-
readonly
|
|
312
|
-
readonly_with_sender
|
|
313
|
-
stx
|
|
314
|
-
nonces
|
|
315
|
-
ft_balance
|
|
316
|
-
ft_supply
|
|
799
|
+
vars?: ReadResult[];
|
|
800
|
+
maps?: ReadResult[];
|
|
801
|
+
readonly?: ReadResult[];
|
|
802
|
+
readonly_with_sender?: ReadResult[];
|
|
803
|
+
stx?: ReadResult[];
|
|
804
|
+
nonces?: ReadResult[];
|
|
805
|
+
ft_balance?: ReadResult[];
|
|
806
|
+
ft_supply?: ReadResult[];
|
|
317
807
|
}
|
|
318
808
|
export interface InstantSimulationRequest {
|
|
809
|
+
/** Transaction serialized to hex. */
|
|
319
810
|
transaction: string;
|
|
320
|
-
block_height?:
|
|
811
|
+
block_height?: U64;
|
|
321
812
|
block_hash?: string;
|
|
322
813
|
reads?: ReadStep[];
|
|
323
814
|
}
|
|
324
815
|
export interface InstantSimulationResponse {
|
|
325
|
-
|
|
816
|
+
/** Always present (may be `[]`). Aligned positionally with the request `reads`. */
|
|
817
|
+
reads: ReadResult[];
|
|
326
818
|
receipt: TransactionReceipt;
|
|
327
819
|
}
|
|
820
|
+
export {};
|