stxer 0.1.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.
@@ -0,0 +1,740 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ var tsClarity = require('ts-clarity');
6
+ var network = require('@stacks/network');
7
+ var transactions = require('@stacks/transactions');
8
+ var c32check = require('c32check');
9
+
10
+ function _arrayLikeToArray(r, a) {
11
+ (null == a || a > r.length) && (a = r.length);
12
+ for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e];
13
+ return n;
14
+ }
15
+ function asyncGeneratorStep(n, t, e, r, o, a, c) {
16
+ try {
17
+ var i = n[a](c),
18
+ u = i.value;
19
+ } catch (n) {
20
+ return void e(n);
21
+ }
22
+ i.done ? t(u) : Promise.resolve(u).then(r, o);
23
+ }
24
+ function _asyncToGenerator(n) {
25
+ return function () {
26
+ var t = this,
27
+ e = arguments;
28
+ return new Promise(function (r, o) {
29
+ var a = n.apply(t, e);
30
+ function _next(n) {
31
+ asyncGeneratorStep(a, r, o, _next, _throw, "next", n);
32
+ }
33
+ function _throw(n) {
34
+ asyncGeneratorStep(a, r, o, _next, _throw, "throw", n);
35
+ }
36
+ _next(void 0);
37
+ });
38
+ };
39
+ }
40
+ function _createForOfIteratorHelperLoose(r, e) {
41
+ var t = "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"];
42
+ if (t) return (t = t.call(r)).next.bind(t);
43
+ if (Array.isArray(r) || (t = _unsupportedIterableToArray(r)) || e && r && "number" == typeof r.length) {
44
+ t && (r = t);
45
+ var o = 0;
46
+ return function () {
47
+ return o >= r.length ? {
48
+ done: !0
49
+ } : {
50
+ done: !1,
51
+ value: r[o++]
52
+ };
53
+ };
54
+ }
55
+ throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
56
+ }
57
+ function _extends() {
58
+ return _extends = Object.assign ? Object.assign.bind() : function (n) {
59
+ for (var e = 1; e < arguments.length; e++) {
60
+ var t = arguments[e];
61
+ for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]);
62
+ }
63
+ return n;
64
+ }, _extends.apply(null, arguments);
65
+ }
66
+ function _regeneratorRuntime() {
67
+ _regeneratorRuntime = function () {
68
+ return e;
69
+ };
70
+ var t,
71
+ e = {},
72
+ r = Object.prototype,
73
+ n = r.hasOwnProperty,
74
+ o = Object.defineProperty || function (t, e, r) {
75
+ t[e] = r.value;
76
+ },
77
+ i = "function" == typeof Symbol ? Symbol : {},
78
+ a = i.iterator || "@@iterator",
79
+ c = i.asyncIterator || "@@asyncIterator",
80
+ u = i.toStringTag || "@@toStringTag";
81
+ function define(t, e, r) {
82
+ return Object.defineProperty(t, e, {
83
+ value: r,
84
+ enumerable: !0,
85
+ configurable: !0,
86
+ writable: !0
87
+ }), t[e];
88
+ }
89
+ try {
90
+ define({}, "");
91
+ } catch (t) {
92
+ define = function (t, e, r) {
93
+ return t[e] = r;
94
+ };
95
+ }
96
+ function wrap(t, e, r, n) {
97
+ var i = e && e.prototype instanceof Generator ? e : Generator,
98
+ a = Object.create(i.prototype),
99
+ c = new Context(n || []);
100
+ return o(a, "_invoke", {
101
+ value: makeInvokeMethod(t, r, c)
102
+ }), a;
103
+ }
104
+ function tryCatch(t, e, r) {
105
+ try {
106
+ return {
107
+ type: "normal",
108
+ arg: t.call(e, r)
109
+ };
110
+ } catch (t) {
111
+ return {
112
+ type: "throw",
113
+ arg: t
114
+ };
115
+ }
116
+ }
117
+ e.wrap = wrap;
118
+ var h = "suspendedStart",
119
+ l = "suspendedYield",
120
+ f = "executing",
121
+ s = "completed",
122
+ y = {};
123
+ function Generator() {}
124
+ function GeneratorFunction() {}
125
+ function GeneratorFunctionPrototype() {}
126
+ var p = {};
127
+ define(p, a, function () {
128
+ return this;
129
+ });
130
+ var d = Object.getPrototypeOf,
131
+ v = d && d(d(values([])));
132
+ v && v !== r && n.call(v, a) && (p = v);
133
+ var g = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(p);
134
+ function defineIteratorMethods(t) {
135
+ ["next", "throw", "return"].forEach(function (e) {
136
+ define(t, e, function (t) {
137
+ return this._invoke(e, t);
138
+ });
139
+ });
140
+ }
141
+ function AsyncIterator(t, e) {
142
+ function invoke(r, o, i, a) {
143
+ var c = tryCatch(t[r], t, o);
144
+ if ("throw" !== c.type) {
145
+ var u = c.arg,
146
+ h = u.value;
147
+ return h && "object" == typeof h && n.call(h, "__await") ? e.resolve(h.__await).then(function (t) {
148
+ invoke("next", t, i, a);
149
+ }, function (t) {
150
+ invoke("throw", t, i, a);
151
+ }) : e.resolve(h).then(function (t) {
152
+ u.value = t, i(u);
153
+ }, function (t) {
154
+ return invoke("throw", t, i, a);
155
+ });
156
+ }
157
+ a(c.arg);
158
+ }
159
+ var r;
160
+ o(this, "_invoke", {
161
+ value: function (t, n) {
162
+ function callInvokeWithMethodAndArg() {
163
+ return new e(function (e, r) {
164
+ invoke(t, n, e, r);
165
+ });
166
+ }
167
+ return r = r ? r.then(callInvokeWithMethodAndArg, callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg();
168
+ }
169
+ });
170
+ }
171
+ function makeInvokeMethod(e, r, n) {
172
+ var o = h;
173
+ return function (i, a) {
174
+ if (o === f) throw Error("Generator is already running");
175
+ if (o === s) {
176
+ if ("throw" === i) throw a;
177
+ return {
178
+ value: t,
179
+ done: !0
180
+ };
181
+ }
182
+ for (n.method = i, n.arg = a;;) {
183
+ var c = n.delegate;
184
+ if (c) {
185
+ var u = maybeInvokeDelegate(c, n);
186
+ if (u) {
187
+ if (u === y) continue;
188
+ return u;
189
+ }
190
+ }
191
+ if ("next" === n.method) n.sent = n._sent = n.arg;else if ("throw" === n.method) {
192
+ if (o === h) throw o = s, n.arg;
193
+ n.dispatchException(n.arg);
194
+ } else "return" === n.method && n.abrupt("return", n.arg);
195
+ o = f;
196
+ var p = tryCatch(e, r, n);
197
+ if ("normal" === p.type) {
198
+ if (o = n.done ? s : l, p.arg === y) continue;
199
+ return {
200
+ value: p.arg,
201
+ done: n.done
202
+ };
203
+ }
204
+ "throw" === p.type && (o = s, n.method = "throw", n.arg = p.arg);
205
+ }
206
+ };
207
+ }
208
+ function maybeInvokeDelegate(e, r) {
209
+ var n = r.method,
210
+ o = e.iterator[n];
211
+ if (o === t) return r.delegate = null, "throw" === n && e.iterator.return && (r.method = "return", r.arg = t, maybeInvokeDelegate(e, r), "throw" === r.method) || "return" !== n && (r.method = "throw", r.arg = new TypeError("The iterator does not provide a '" + n + "' method")), y;
212
+ var i = tryCatch(o, e.iterator, r.arg);
213
+ if ("throw" === i.type) return r.method = "throw", r.arg = i.arg, r.delegate = null, y;
214
+ var a = i.arg;
215
+ return a ? a.done ? (r[e.resultName] = a.value, r.next = e.nextLoc, "return" !== r.method && (r.method = "next", r.arg = t), r.delegate = null, y) : a : (r.method = "throw", r.arg = new TypeError("iterator result is not an object"), r.delegate = null, y);
216
+ }
217
+ function pushTryEntry(t) {
218
+ var e = {
219
+ tryLoc: t[0]
220
+ };
221
+ 1 in t && (e.catchLoc = t[1]), 2 in t && (e.finallyLoc = t[2], e.afterLoc = t[3]), this.tryEntries.push(e);
222
+ }
223
+ function resetTryEntry(t) {
224
+ var e = t.completion || {};
225
+ e.type = "normal", delete e.arg, t.completion = e;
226
+ }
227
+ function Context(t) {
228
+ this.tryEntries = [{
229
+ tryLoc: "root"
230
+ }], t.forEach(pushTryEntry, this), this.reset(!0);
231
+ }
232
+ function values(e) {
233
+ if (e || "" === e) {
234
+ var r = e[a];
235
+ if (r) return r.call(e);
236
+ if ("function" == typeof e.next) return e;
237
+ if (!isNaN(e.length)) {
238
+ var o = -1,
239
+ i = function next() {
240
+ for (; ++o < e.length;) if (n.call(e, o)) return next.value = e[o], next.done = !1, next;
241
+ return next.value = t, next.done = !0, next;
242
+ };
243
+ return i.next = i;
244
+ }
245
+ }
246
+ throw new TypeError(typeof e + " is not iterable");
247
+ }
248
+ return GeneratorFunction.prototype = GeneratorFunctionPrototype, o(g, "constructor", {
249
+ value: GeneratorFunctionPrototype,
250
+ configurable: !0
251
+ }), o(GeneratorFunctionPrototype, "constructor", {
252
+ value: GeneratorFunction,
253
+ configurable: !0
254
+ }), GeneratorFunction.displayName = define(GeneratorFunctionPrototype, u, "GeneratorFunction"), e.isGeneratorFunction = function (t) {
255
+ var e = "function" == typeof t && t.constructor;
256
+ return !!e && (e === GeneratorFunction || "GeneratorFunction" === (e.displayName || e.name));
257
+ }, e.mark = function (t) {
258
+ return Object.setPrototypeOf ? Object.setPrototypeOf(t, GeneratorFunctionPrototype) : (t.__proto__ = GeneratorFunctionPrototype, define(t, u, "GeneratorFunction")), t.prototype = Object.create(g), t;
259
+ }, e.awrap = function (t) {
260
+ return {
261
+ __await: t
262
+ };
263
+ }, defineIteratorMethods(AsyncIterator.prototype), define(AsyncIterator.prototype, c, function () {
264
+ return this;
265
+ }), e.AsyncIterator = AsyncIterator, e.async = function (t, r, n, o, i) {
266
+ void 0 === i && (i = Promise);
267
+ var a = new AsyncIterator(wrap(t, r, n, o), i);
268
+ return e.isGeneratorFunction(r) ? a : a.next().then(function (t) {
269
+ return t.done ? t.value : a.next();
270
+ });
271
+ }, defineIteratorMethods(g), define(g, u, "Generator"), define(g, a, function () {
272
+ return this;
273
+ }), define(g, "toString", function () {
274
+ return "[object Generator]";
275
+ }), e.keys = function (t) {
276
+ var e = Object(t),
277
+ r = [];
278
+ for (var n in e) r.push(n);
279
+ return r.reverse(), function next() {
280
+ for (; r.length;) {
281
+ var t = r.pop();
282
+ if (t in e) return next.value = t, next.done = !1, next;
283
+ }
284
+ return next.done = !0, next;
285
+ };
286
+ }, e.values = values, Context.prototype = {
287
+ constructor: Context,
288
+ reset: function (e) {
289
+ if (this.prev = 0, this.next = 0, this.sent = this._sent = t, this.done = !1, this.delegate = null, this.method = "next", this.arg = t, this.tryEntries.forEach(resetTryEntry), !e) for (var r in this) "t" === r.charAt(0) && n.call(this, r) && !isNaN(+r.slice(1)) && (this[r] = t);
290
+ },
291
+ stop: function () {
292
+ this.done = !0;
293
+ var t = this.tryEntries[0].completion;
294
+ if ("throw" === t.type) throw t.arg;
295
+ return this.rval;
296
+ },
297
+ dispatchException: function (e) {
298
+ if (this.done) throw e;
299
+ var r = this;
300
+ function handle(n, o) {
301
+ return a.type = "throw", a.arg = e, r.next = n, o && (r.method = "next", r.arg = t), !!o;
302
+ }
303
+ for (var o = this.tryEntries.length - 1; o >= 0; --o) {
304
+ var i = this.tryEntries[o],
305
+ a = i.completion;
306
+ if ("root" === i.tryLoc) return handle("end");
307
+ if (i.tryLoc <= this.prev) {
308
+ var c = n.call(i, "catchLoc"),
309
+ u = n.call(i, "finallyLoc");
310
+ if (c && u) {
311
+ if (this.prev < i.catchLoc) return handle(i.catchLoc, !0);
312
+ if (this.prev < i.finallyLoc) return handle(i.finallyLoc);
313
+ } else if (c) {
314
+ if (this.prev < i.catchLoc) return handle(i.catchLoc, !0);
315
+ } else {
316
+ if (!u) throw Error("try statement without catch or finally");
317
+ if (this.prev < i.finallyLoc) return handle(i.finallyLoc);
318
+ }
319
+ }
320
+ }
321
+ },
322
+ abrupt: function (t, e) {
323
+ for (var r = this.tryEntries.length - 1; r >= 0; --r) {
324
+ var o = this.tryEntries[r];
325
+ if (o.tryLoc <= this.prev && n.call(o, "finallyLoc") && this.prev < o.finallyLoc) {
326
+ var i = o;
327
+ break;
328
+ }
329
+ }
330
+ i && ("break" === t || "continue" === t) && i.tryLoc <= e && e <= i.finallyLoc && (i = null);
331
+ var a = i ? i.completion : {};
332
+ return a.type = t, a.arg = e, i ? (this.method = "next", this.next = i.finallyLoc, y) : this.complete(a);
333
+ },
334
+ complete: function (t, e) {
335
+ if ("throw" === t.type) throw t.arg;
336
+ return "break" === t.type || "continue" === t.type ? this.next = t.arg : "return" === t.type ? (this.rval = this.arg = t.arg, this.method = "return", this.next = "end") : "normal" === t.type && e && (this.next = e), y;
337
+ },
338
+ finish: function (t) {
339
+ for (var e = this.tryEntries.length - 1; e >= 0; --e) {
340
+ var r = this.tryEntries[e];
341
+ if (r.finallyLoc === t) return this.complete(r.completion, r.afterLoc), resetTryEntry(r), y;
342
+ }
343
+ },
344
+ catch: function (t) {
345
+ for (var e = this.tryEntries.length - 1; e >= 0; --e) {
346
+ var r = this.tryEntries[e];
347
+ if (r.tryLoc === t) {
348
+ var n = r.completion;
349
+ if ("throw" === n.type) {
350
+ var o = n.arg;
351
+ resetTryEntry(r);
352
+ }
353
+ return o;
354
+ }
355
+ }
356
+ throw Error("illegal catch attempt");
357
+ },
358
+ delegateYield: function (e, r, n) {
359
+ return this.delegate = {
360
+ iterator: values(e),
361
+ resultName: r,
362
+ nextLoc: n
363
+ }, "next" === this.method && (this.arg = t), y;
364
+ }
365
+ }, e;
366
+ }
367
+ function _unsupportedIterableToArray(r, a) {
368
+ if (r) {
369
+ if ("string" == typeof r) return _arrayLikeToArray(r, a);
370
+ var t = {}.toString.call(r).slice(8, -1);
371
+ return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0;
372
+ }
373
+ }
374
+
375
+ // current beta api endpoint
376
+ var SIMULATION_API_ENDPOINT = 'https://api.stxer.xyz/simulations';
377
+ function runTx(tx) {
378
+ // type 0: run transaction
379
+ return transactions.tupleCV({
380
+ type: transactions.uintCV(0),
381
+ data: transactions.bufferCV(tx.serialize())
382
+ });
383
+ }
384
+ function runEval(_ref) {
385
+ var contract_id = _ref.contract_id,
386
+ code = _ref.code;
387
+ var _contract_id$split = contract_id.split('.'),
388
+ contract_address = _contract_id$split[0],
389
+ contract_name = _contract_id$split[1];
390
+ // type 1: eval arbitrary code inside a contract
391
+ return transactions.tupleCV({
392
+ type: transactions.uintCV(1),
393
+ data: transactions.bufferCV(transactions.serializeCV(transactions.tupleCV({
394
+ contract: transactions.contractPrincipalCV(contract_address, contract_name),
395
+ code: transactions.stringAsciiCV(code)
396
+ })))
397
+ });
398
+ }
399
+ function runSimulation(_x, _x2, _x3) {
400
+ return _runSimulation.apply(this, arguments);
401
+ }
402
+ function _runSimulation() {
403
+ _runSimulation = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee5(block_hash, block_height, txs) {
404
+ var body, rs;
405
+ return _regeneratorRuntime().wrap(function _callee5$(_context5) {
406
+ while (1) switch (_context5.prev = _context5.next) {
407
+ case 0:
408
+ body = Buffer.concat([Buffer.from('sim-v1'), Buffer.alloc(8), Buffer.from(block_hash.startsWith('0x') ? block_hash.substring(2) : block_hash, 'hex')].concat(txs.map(function (t) {
409
+ return 'contract_id' in t && 'code' in t ? runEval(t) : runTx(t);
410
+ }).map(function (t) {
411
+ return transactions.serializeCV(t);
412
+ })));
413
+ body.writeBigUInt64BE(BigInt(block_height), 6);
414
+ _context5.next = 4;
415
+ return fetch(SIMULATION_API_ENDPOINT, {
416
+ method: 'POST',
417
+ body: body
418
+ }).then(/*#__PURE__*/function () {
419
+ var _ref3 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee4(rs) {
420
+ var response;
421
+ return _regeneratorRuntime().wrap(function _callee4$(_context4) {
422
+ while (1) switch (_context4.prev = _context4.next) {
423
+ case 0:
424
+ _context4.next = 2;
425
+ return rs.text();
426
+ case 2:
427
+ response = _context4.sent;
428
+ if (response.startsWith('{')) {
429
+ _context4.next = 5;
430
+ break;
431
+ }
432
+ throw new Error("failed to submit simulation: " + response);
433
+ case 5:
434
+ return _context4.abrupt("return", JSON.parse(response));
435
+ case 6:
436
+ case "end":
437
+ return _context4.stop();
438
+ }
439
+ }, _callee4);
440
+ }));
441
+ return function (_x5) {
442
+ return _ref3.apply(this, arguments);
443
+ };
444
+ }());
445
+ case 4:
446
+ rs = _context5.sent;
447
+ return _context5.abrupt("return", rs.id);
448
+ case 6:
449
+ case "end":
450
+ return _context5.stop();
451
+ }
452
+ }, _callee5);
453
+ }));
454
+ return _runSimulation.apply(this, arguments);
455
+ }
456
+ var SimulationBuilder = /*#__PURE__*/function () {
457
+ function SimulationBuilder() {
458
+ // biome-ignore lint/style/useNumberNamespace: <explanation>
459
+ this.block = NaN;
460
+ this.sender = '';
461
+ this.steps = [];
462
+ }
463
+ SimulationBuilder["new"] = function _new() {
464
+ return new SimulationBuilder();
465
+ };
466
+ var _proto = SimulationBuilder.prototype;
467
+ _proto.useBlockHeight = function useBlockHeight(block) {
468
+ this.block = block;
469
+ return this;
470
+ };
471
+ _proto.withSender = function withSender(address) {
472
+ this.sender = address;
473
+ return this;
474
+ };
475
+ _proto.addSTXTransfer = function addSTXTransfer(params) {
476
+ var _params$sender, _params$fee;
477
+ if (params.sender == null && this.sender === '') {
478
+ throw new Error('Please specify a sender with useSender or adding a sender paramenter');
479
+ }
480
+ this.steps.push(_extends({}, params, {
481
+ sender: (_params$sender = params.sender) != null ? _params$sender : this.sender,
482
+ fee: (_params$fee = params.fee) != null ? _params$fee : 0
483
+ }));
484
+ return this;
485
+ };
486
+ _proto.addContractCall = function addContractCall(params) {
487
+ var _params$sender2, _params$fee2;
488
+ if (params.sender == null && this.sender === '') {
489
+ throw new Error('Please specify a sender with useSender or adding a sender paramenter');
490
+ }
491
+ this.steps.push(_extends({}, params, {
492
+ sender: (_params$sender2 = params.sender) != null ? _params$sender2 : this.sender,
493
+ fee: (_params$fee2 = params.fee) != null ? _params$fee2 : 0
494
+ }));
495
+ return this;
496
+ };
497
+ _proto.addContractDeploy = function addContractDeploy(params) {
498
+ var _params$deployer, _params$fee3;
499
+ if (params.deployer == null && this.sender === '') {
500
+ throw new Error('Please specify a deployer with useSender or adding a deployer paramenter');
501
+ }
502
+ this.steps.push(_extends({}, params, {
503
+ deployer: (_params$deployer = params.deployer) != null ? _params$deployer : this.sender,
504
+ fee: (_params$fee3 = params.fee) != null ? _params$fee3 : 0
505
+ }));
506
+ return this;
507
+ };
508
+ _proto.addEvalCode = function addEvalCode(inside_contract_id, code) {
509
+ this.steps.push({
510
+ contract_id: inside_contract_id,
511
+ code: code
512
+ });
513
+ return this;
514
+ };
515
+ _proto.addMapRead = function addMapRead(contract_id, map, key) {
516
+ this.steps.push({
517
+ contract_id: contract_id,
518
+ code: "(map-get " + map + " " + key + ")"
519
+ });
520
+ return this;
521
+ };
522
+ _proto.addVarRead = function addVarRead(contract_id, variable) {
523
+ this.steps.push({
524
+ contract_id: contract_id,
525
+ code: "(var-get " + variable + ")"
526
+ });
527
+ return this;
528
+ };
529
+ _proto.getBlockInfo = /*#__PURE__*/function () {
530
+ var _getBlockInfo = /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
531
+ var _yield$getNodeInfo, stacks_tip_height, info;
532
+ return _regeneratorRuntime().wrap(function _callee$(_context) {
533
+ while (1) switch (_context.prev = _context.next) {
534
+ case 0:
535
+ if (!Number.isNaN(this.block)) {
536
+ _context.next = 6;
537
+ break;
538
+ }
539
+ _context.next = 3;
540
+ return tsClarity.getNodeInfo();
541
+ case 3:
542
+ _yield$getNodeInfo = _context.sent;
543
+ stacks_tip_height = _yield$getNodeInfo.stacks_tip_height;
544
+ this.block = stacks_tip_height;
545
+ case 6:
546
+ _context.next = 8;
547
+ return tsClarity.richFetch("https://api.hiro.so/extended/v1/block/by_height/" + this.block + "?unanchored=true").then(function (r) {
548
+ return r.json();
549
+ });
550
+ case 8:
551
+ info = _context.sent;
552
+ if (!(info.height !== this.block || typeof info.hash !== 'string' || !info.hash.startsWith('0x'))) {
553
+ _context.next = 11;
554
+ break;
555
+ }
556
+ throw new Error("failed to get block info for block height " + this.block);
557
+ case 11:
558
+ return _context.abrupt("return", {
559
+ block_height: this.block,
560
+ block_hash: info.hash.substring(2),
561
+ index_block_hash: info.index_block_hash.substring(2)
562
+ });
563
+ case 12:
564
+ case "end":
565
+ return _context.stop();
566
+ }
567
+ }, _callee, this);
568
+ }));
569
+ function getBlockInfo() {
570
+ return _getBlockInfo.apply(this, arguments);
571
+ }
572
+ return getBlockInfo;
573
+ }();
574
+ _proto.run = /*#__PURE__*/function () {
575
+ var _run = /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee3() {
576
+ var block, txs, nonce_by_address, nextNonce, _iterator, _step, step, _step$function_args, nonce, _step$contract_id$spl, contractAddress, contractName, tx, _nonce, _tx, _nonce2, _tx2, id;
577
+ return _regeneratorRuntime().wrap(function _callee3$(_context3) {
578
+ while (1) switch (_context3.prev = _context3.next) {
579
+ case 0:
580
+ console.log("--------------------------------\nThis product can never exist without your support!\n\nWe receive sponsorship funds with:\nSP212Y5JKN59YP3GYG07K3S8W5SSGE4KH6B5STXER\n\nFeedbacks and feature requests are welcome.\nTo get in touch: contact@stxer.xyz\n--------------------------------");
581
+ _context3.next = 3;
582
+ return this.getBlockInfo();
583
+ case 3:
584
+ block = _context3.sent;
585
+ console.log("Using block height " + block.block_height + " hash 0x" + block.block_hash + " to run simulation.");
586
+ txs = [];
587
+ nonce_by_address = new Map();
588
+ nextNonce = /*#__PURE__*/function () {
589
+ var _ref2 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee2(sender) {
590
+ var nonce, url, account;
591
+ return _regeneratorRuntime().wrap(function _callee2$(_context2) {
592
+ while (1) switch (_context2.prev = _context2.next) {
593
+ case 0:
594
+ nonce = nonce_by_address.get(sender);
595
+ if (!(nonce == null)) {
596
+ _context2.next = 8;
597
+ break;
598
+ }
599
+ url = "https://api.hiro.so/v2/accounts/" + sender + "?proof=" + false + "&tip=" + block.index_block_hash;
600
+ _context2.next = 5;
601
+ return tsClarity.richFetch(url).then(function (r) {
602
+ return r.json();
603
+ });
604
+ case 5:
605
+ account = _context2.sent;
606
+ nonce_by_address.set(sender, account.nonce + 1);
607
+ return _context2.abrupt("return", account.nonce);
608
+ case 8:
609
+ nonce_by_address.set(sender, nonce + 1);
610
+ return _context2.abrupt("return", nonce);
611
+ case 10:
612
+ case "end":
613
+ return _context2.stop();
614
+ }
615
+ }, _callee2);
616
+ }));
617
+ return function nextNonce(_x4) {
618
+ return _ref2.apply(this, arguments);
619
+ };
620
+ }();
621
+ _iterator = _createForOfIteratorHelperLoose(this.steps);
622
+ case 9:
623
+ if ((_step = _iterator()).done) {
624
+ _context3.next = 48;
625
+ break;
626
+ }
627
+ step = _step.value;
628
+ if (!('sender' in step && 'function_name' in step)) {
629
+ _context3.next = 23;
630
+ break;
631
+ }
632
+ _context3.next = 14;
633
+ return nextNonce(step.sender);
634
+ case 14:
635
+ nonce = _context3.sent;
636
+ _step$contract_id$spl = step.contract_id.split('.'), contractAddress = _step$contract_id$spl[0], contractName = _step$contract_id$spl[1];
637
+ _context3.next = 18;
638
+ return transactions.makeUnsignedContractCall({
639
+ contractAddress: contractAddress,
640
+ contractName: contractName,
641
+ functionName: step.function_name,
642
+ functionArgs: (_step$function_args = step.function_args) != null ? _step$function_args : [],
643
+ nonce: nonce,
644
+ network: new network.StacksMainnet(),
645
+ publicKey: '',
646
+ postConditionMode: transactions.PostConditionMode.Allow,
647
+ anchorMode: transactions.AnchorMode.Any,
648
+ fee: step.fee
649
+ });
650
+ case 18:
651
+ tx = _context3.sent;
652
+ tx.auth.spendingCondition.signer = c32check.c32addressDecode(step.sender)[1];
653
+ txs.push(tx);
654
+ _context3.next = 46;
655
+ break;
656
+ case 23:
657
+ if (!('sender' in step && 'recipient' in step)) {
658
+ _context3.next = 34;
659
+ break;
660
+ }
661
+ _context3.next = 26;
662
+ return nextNonce(step.sender);
663
+ case 26:
664
+ _nonce = _context3.sent;
665
+ _context3.next = 29;
666
+ return transactions.makeUnsignedSTXTokenTransfer({
667
+ recipient: step.recipient,
668
+ amount: step.amount,
669
+ nonce: _nonce,
670
+ network: new network.StacksMainnet(),
671
+ publicKey: '',
672
+ anchorMode: transactions.AnchorMode.Any,
673
+ fee: step.fee
674
+ });
675
+ case 29:
676
+ _tx = _context3.sent;
677
+ _tx.auth.spendingCondition.signer = c32check.c32addressDecode(step.sender)[1];
678
+ txs.push(_tx);
679
+ _context3.next = 46;
680
+ break;
681
+ case 34:
682
+ if (!('deployer' in step)) {
683
+ _context3.next = 45;
684
+ break;
685
+ }
686
+ _context3.next = 37;
687
+ return nextNonce(step.deployer);
688
+ case 37:
689
+ _nonce2 = _context3.sent;
690
+ _context3.next = 40;
691
+ return transactions.makeUnsignedContractDeploy({
692
+ contractName: step.contract_name,
693
+ codeBody: step.source_code,
694
+ nonce: _nonce2,
695
+ network: new network.StacksMainnet(),
696
+ publicKey: '',
697
+ postConditionMode: transactions.PostConditionMode.Allow,
698
+ anchorMode: transactions.AnchorMode.Any,
699
+ fee: step.fee
700
+ });
701
+ case 40:
702
+ _tx2 = _context3.sent;
703
+ _tx2.auth.spendingCondition.signer = c32check.c32addressDecode(step.deployer)[1];
704
+ txs.push(_tx2);
705
+ _context3.next = 46;
706
+ break;
707
+ case 45:
708
+ if ('code' in step) {
709
+ txs.push(step);
710
+ } else {
711
+ console.log("Invalid simulation step:", step);
712
+ }
713
+ case 46:
714
+ _context3.next = 9;
715
+ break;
716
+ case 48:
717
+ _context3.next = 50;
718
+ return runSimulation(block.block_hash, block.block_height, txs);
719
+ case 50:
720
+ id = _context3.sent;
721
+ console.log("Simulation will be available at: https://stxer.xyz/simulations/mainnet/" + id);
722
+ return _context3.abrupt("return", id);
723
+ case 53:
724
+ case "end":
725
+ return _context3.stop();
726
+ }
727
+ }, _callee3, this);
728
+ }));
729
+ function run() {
730
+ return _run.apply(this, arguments);
731
+ }
732
+ return run;
733
+ }();
734
+ return SimulationBuilder;
735
+ }();
736
+
737
+ exports.SimulationBuilder = SimulationBuilder;
738
+ exports.runEval = runEval;
739
+ exports.runSimulation = runSimulation;
740
+ //# sourceMappingURL=stxer.cjs.development.js.map