@algorandfoundation/algorand-typescript-testing 1.0.0-beta.12 → 1.0.0-beta.14

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.
Files changed (52) hide show
  1. package/asset-params-CzUcFBcQ.js +844 -0
  2. package/asset-params-CzUcFBcQ.js.map +1 -0
  3. package/{runtime-helpers-C6O92q80.js → encoded-types-9PSWSstF.js} +691 -523
  4. package/encoded-types-9PSWSstF.js.map +1 -0
  5. package/impl/acct-params.d.ts +2 -3
  6. package/impl/app-global.d.ts +2 -2
  7. package/impl/app-local.d.ts +2 -2
  8. package/impl/app-params.d.ts +2 -2
  9. package/impl/asset-holding.d.ts +2 -2
  10. package/impl/asset-params.d.ts +2 -2
  11. package/impl/block.d.ts +2 -2
  12. package/impl/box.d.ts +2 -2
  13. package/impl/crypto.d.ts +9 -2
  14. package/impl/encoded-types.d.ts +2 -1
  15. package/impl/global.d.ts +2 -3
  16. package/impl/gtxn.d.ts +9 -2
  17. package/impl/itxn.d.ts +4 -4
  18. package/impl/online-stake.d.ts +2 -2
  19. package/impl/pure.d.ts +5 -1
  20. package/impl/scratch.d.ts +4 -4
  21. package/impl/txn.d.ts +2 -2
  22. package/impl/voter-params.d.ts +2 -2
  23. package/index.d.ts +1 -0
  24. package/index.mjs +126 -3500
  25. package/index.mjs.map +1 -1
  26. package/inner-transactions-CR-mVBgh.js +837 -0
  27. package/inner-transactions-CR-mVBgh.js.map +1 -0
  28. package/internal/arc4.mjs +10 -0
  29. package/internal/arc4.mjs.map +1 -1
  30. package/internal/op.mjs +13 -0
  31. package/internal/op.mjs.map +1 -1
  32. package/{internal-arc4-BPiMhb9a.js → internal-arc4-BL2mIZPS.js} +4 -2
  33. package/internal-arc4-BL2mIZPS.js.map +1 -0
  34. package/internal-arc4.d.ts +1 -0
  35. package/internal-op-BeEW2jMq.js +1812 -0
  36. package/internal-op-BeEW2jMq.js.map +1 -0
  37. package/internal-op.d.ts +18 -0
  38. package/internal.d.ts +22 -0
  39. package/internal.mjs +35 -6
  40. package/internal.mjs.map +1 -1
  41. package/package.json +3 -3
  42. package/runtime-helpers-Dv_gjCvF.js +436 -0
  43. package/runtime-helpers-Dv_gjCvF.js.map +1 -0
  44. package/runtime-helpers.mjs +4 -4
  45. package/set-up.d.ts +1 -1
  46. package/test-execution-context.d.ts +2 -1
  47. package/internal-arc4-BPiMhb9a.js.map +0 -1
  48. package/internal-op-BJR4Xrem.js +0 -23
  49. package/internal-op-BJR4Xrem.js.map +0 -1
  50. package/log-C5qsaKI5.js +0 -602
  51. package/log-C5qsaKI5.js.map +0 -1
  52. package/runtime-helpers-C6O92q80.js.map +0 -1
@@ -0,0 +1,844 @@
1
+ import { internal, BigUint, Uint64, Bytes, Base64 } from '@algorandfoundation/algorand-typescript';
2
+ import { ARC4Encoded } from '@algorandfoundation/algorand-typescript/arc4';
3
+ import { h as asMaybeUint64Cls, o as asMaybeBytesCls, O as asMaybeBigUintCls, L as BytesBackedCls, N as Uint64BackedCls, j as asUint64Cls, a2 as encodeArc4Impl, _ as nameOfType, ad as getArc4Encoder, A as AccountCls, a as ApplicationCls, b as AssetCls, ac as arc4Encoders, R as asUint8Array, K as asBytes, l as lazyContext, u as getRandomBytes, f as asUint64, d as Account, aq as getObjectReference, an as sha256, ar as getApplicationAddress, as as MIN_TXN_FEE, at as DEFAULT_ACCOUNT_MIN_BALANCE, au as DEFAULT_MAX_TXN_LIFE, Z as ZERO_ADDRESS, av as DEFAULT_ASSET_CREATE_MIN_BALANCE, aw as DEFAULT_ASSET_OPT_IN_MIN_BALANCE, ax as DEFAULT_GLOBAL_GENESIS_HASH, ay as asBigUint, I as BITS_IN_BYTE, s as MAX_BYTES_SIZE, V as asBytesCls, t as testInvariant, z as MAX_UINT8, az as binaryStringToBytes, aA as UINT64_SIZE, aB as notImplementedError, M as MAX_UINT64 } from './encoded-types-9PSWSstF.js';
4
+
5
+ const booleanFromBytes = (val) => {
6
+ return internal.encodingUtil.uint8ArrayToBigInt(asUint8Array(val)) > 0n;
7
+ };
8
+ const bigUintFromBytes = (val) => {
9
+ return BigUint(internal.encodingUtil.uint8ArrayToBigInt(asUint8Array(val)));
10
+ };
11
+ const bytesFromBytes = (val) => {
12
+ return asBytes(val);
13
+ };
14
+ const stringFromBytes = (val) => {
15
+ return asBytes(val).toString();
16
+ };
17
+ const uint64FromBytes = (val) => {
18
+ return Uint64(internal.encodingUtil.uint8ArrayToBigInt(asUint8Array(val)));
19
+ };
20
+ const onCompletionFromBytes = (val) => {
21
+ return Uint64(internal.encodingUtil.uint8ArrayToBigInt(asUint8Array(val)));
22
+ };
23
+ const transactionTypeFromBytes = (val) => {
24
+ return Uint64(internal.encodingUtil.uint8ArrayToBigInt(asUint8Array(val)));
25
+ };
26
+ const encoders = {
27
+ account: AccountCls.fromBytes,
28
+ application: ApplicationCls.fromBytes,
29
+ asset: AssetCls.fromBytes,
30
+ boolean: booleanFromBytes,
31
+ biguint: bigUintFromBytes,
32
+ bytes: bytesFromBytes,
33
+ string: stringFromBytes,
34
+ uint64: uint64FromBytes,
35
+ OnCompleteAction: onCompletionFromBytes,
36
+ TransactionType: transactionTypeFromBytes,
37
+ ...arc4Encoders,
38
+ };
39
+ const getEncoder = (typeInfo) => {
40
+ return getArc4Encoder(typeInfo, encoders);
41
+ };
42
+ const toBytes = (val) => {
43
+ const uint64Val = asMaybeUint64Cls(val);
44
+ if (uint64Val !== undefined) {
45
+ return uint64Val.toBytes().asAlgoTs();
46
+ }
47
+ const bytesVal = asMaybeBytesCls(val);
48
+ if (bytesVal !== undefined) {
49
+ return bytesVal.asAlgoTs();
50
+ }
51
+ const bigUintVal = asMaybeBigUintCls(val);
52
+ if (bigUintVal !== undefined) {
53
+ return bigUintVal.toBytes().asAlgoTs();
54
+ }
55
+ if (val instanceof BytesBackedCls) {
56
+ return val.bytes;
57
+ }
58
+ if (val instanceof Uint64BackedCls) {
59
+ return asUint64Cls(val.uint64).toBytes().asAlgoTs();
60
+ }
61
+ if (val instanceof ARC4Encoded) {
62
+ return val.bytes;
63
+ }
64
+ if (Array.isArray(val) || typeof val === 'object') {
65
+ return encodeArc4Impl('', val);
66
+ }
67
+ internal.errors.internalError(`Invalid type for bytes: ${nameOfType(val)}`);
68
+ };
69
+
70
+ class BlockData {
71
+ seed;
72
+ timestamp;
73
+ proposer;
74
+ feesCollected;
75
+ bonus;
76
+ branch;
77
+ feeSink;
78
+ protocol;
79
+ txnCounter;
80
+ proposerPayout;
81
+ constructor() {
82
+ this.seed = getRandomBytes(32).asAlgoTs();
83
+ this.timestamp = asUint64(Date.now());
84
+ this.proposer = Account();
85
+ this.feesCollected = Uint64(0);
86
+ this.bonus = Uint64(0);
87
+ this.branch = getRandomBytes(32).asAlgoTs();
88
+ this.feeSink = Account();
89
+ this.protocol = getRandomBytes(32).asAlgoTs();
90
+ this.txnCounter = Uint64(0);
91
+ this.proposerPayout = Uint64(0);
92
+ }
93
+ }
94
+ const Block = {
95
+ blkSeed: function (a) {
96
+ return lazyContext.ledger.getBlockData(a).seed;
97
+ },
98
+ blkTimestamp: function (a) {
99
+ return lazyContext.ledger.getBlockData(a).timestamp;
100
+ },
101
+ blkProposer: function (a) {
102
+ return lazyContext.ledger.getBlockData(a).proposer;
103
+ },
104
+ blkFeesCollected: function (a) {
105
+ return lazyContext.ledger.getBlockData(a).feesCollected;
106
+ },
107
+ blkBonus: function (a) {
108
+ return lazyContext.ledger.getBlockData(a).bonus;
109
+ },
110
+ blkBranch: function (a) {
111
+ return lazyContext.ledger.getBlockData(a).branch;
112
+ },
113
+ blkFeeSink: function (a) {
114
+ return lazyContext.ledger.getBlockData(a).feeSink;
115
+ },
116
+ blkProtocol: function (a) {
117
+ return lazyContext.ledger.getBlockData(a).protocol;
118
+ },
119
+ blkTxnCounter: function (a) {
120
+ return lazyContext.ledger.getBlockData(a).txnCounter;
121
+ },
122
+ blkProposerPayout: function (a) {
123
+ return lazyContext.ledger.getBlockData(a).proposerPayout;
124
+ },
125
+ };
126
+
127
+ class GlobalData {
128
+ minTxnFee;
129
+ minBalance;
130
+ maxTxnLife;
131
+ zeroAddress;
132
+ logicSigVersion;
133
+ round;
134
+ latestTimestamp;
135
+ groupId;
136
+ callerApplicationId;
137
+ assetCreateMinBalance;
138
+ assetOptInMinBalance;
139
+ genesisHash;
140
+ opcodeBudget;
141
+ payoutsEnabled;
142
+ payoutsGoOnlineFee;
143
+ payoutsPercent;
144
+ payoutsMinBalance;
145
+ constructor() {
146
+ this.minTxnFee = Uint64(MIN_TXN_FEE);
147
+ this.minBalance = Uint64(DEFAULT_ACCOUNT_MIN_BALANCE);
148
+ this.maxTxnLife = Uint64(DEFAULT_MAX_TXN_LIFE);
149
+ this.zeroAddress = Account(ZERO_ADDRESS);
150
+ this.callerApplicationId = Uint64(0);
151
+ this.assetCreateMinBalance = Uint64(DEFAULT_ASSET_CREATE_MIN_BALANCE);
152
+ this.assetOptInMinBalance = Uint64(DEFAULT_ASSET_OPT_IN_MIN_BALANCE);
153
+ this.genesisHash = DEFAULT_GLOBAL_GENESIS_HASH;
154
+ this.payoutsEnabled = false;
155
+ this.payoutsGoOnlineFee = Uint64(0);
156
+ this.payoutsPercent = Uint64(0);
157
+ this.payoutsMinBalance = Uint64(0);
158
+ }
159
+ }
160
+ const getGlobalData = () => {
161
+ return lazyContext.ledger.globalData;
162
+ };
163
+ const getMissingValueErrorMessage = (name) => `'Global' object has no value set for attribute named '${name}'. Use \`context.ledger.patchGlobalData({${name}: your_value})\` to set the value in your test setup."`;
164
+ const Global = {
165
+ /**
166
+ * microalgos
167
+ */
168
+ get minTxnFee() {
169
+ return getGlobalData().minTxnFee;
170
+ },
171
+ /**
172
+ * microalgos
173
+ */
174
+ get minBalance() {
175
+ return getGlobalData().minBalance;
176
+ },
177
+ /**
178
+ * rounds
179
+ */
180
+ get maxTxnLife() {
181
+ return getGlobalData().maxTxnLife;
182
+ },
183
+ /**
184
+ * 32 byte address of all zero bytes
185
+ */
186
+ get zeroAddress() {
187
+ return getGlobalData().zeroAddress;
188
+ },
189
+ /**
190
+ * Number of transactions in this atomic transaction group. At least 1
191
+ */
192
+ get groupSize() {
193
+ const currentTransactionGroup = lazyContext.activeGroup.transactions;
194
+ return Uint64(currentTransactionGroup.length);
195
+ },
196
+ /**
197
+ * Maximum supported version
198
+ */
199
+ get logicSigVersion() {
200
+ const data = getGlobalData();
201
+ if (data.logicSigVersion !== undefined)
202
+ return data.logicSigVersion;
203
+ throw new internal.errors.InternalError(getMissingValueErrorMessage('logicSigVersion'));
204
+ },
205
+ /**
206
+ * Current round number. ApplicationType mode only.
207
+ */
208
+ get round() {
209
+ const data = getGlobalData();
210
+ if (data.round !== undefined)
211
+ return data.round;
212
+ return Uint64(lazyContext.txn.groups.length + 1);
213
+ },
214
+ /**
215
+ * Last confirmed block UNIX timestamp. Fails if negative. ApplicationType mode only.
216
+ */
217
+ get latestTimestamp() {
218
+ const data = getGlobalData();
219
+ if (data.latestTimestamp !== undefined)
220
+ return data.latestTimestamp;
221
+ return Uint64(lazyContext.activeGroup.latestTimestamp);
222
+ },
223
+ /**
224
+ * ID of current application executing. ApplicationType mode only.
225
+ */
226
+ get currentApplicationId() {
227
+ return lazyContext.activeApplication;
228
+ },
229
+ /**
230
+ * Address of the creator of the current application. ApplicationType mode only.
231
+ */
232
+ get creatorAddress() {
233
+ const app = lazyContext.activeApplication;
234
+ return app.creator;
235
+ },
236
+ /**
237
+ * Address that the current application controls. ApplicationType mode only.
238
+ */
239
+ get currentApplicationAddress() {
240
+ return this.currentApplicationId.address;
241
+ },
242
+ /**
243
+ * ID of the transaction group. 32 zero bytes if the transaction is not part of a group.
244
+ */
245
+ get groupId() {
246
+ const data = getGlobalData();
247
+ if (data.groupId !== undefined)
248
+ return data.groupId;
249
+ const reference = getObjectReference(lazyContext.activeGroup);
250
+ const referenceBytes = Bytes(internal.encodingUtil.bigIntToUint8Array(reference));
251
+ return sha256(referenceBytes);
252
+ },
253
+ /**
254
+ * The remaining cost that can be spent by opcodes in this program.
255
+ */
256
+ get opcodeBudget() {
257
+ const data = getGlobalData();
258
+ if (data.opcodeBudget !== undefined)
259
+ return data.opcodeBudget;
260
+ throw new internal.errors.InternalError(getMissingValueErrorMessage('opcodeBudget'));
261
+ },
262
+ /**
263
+ * The application ID of the application that called this application. 0 if this application is at the top-level. ApplicationType mode only.
264
+ */
265
+ get callerApplicationId() {
266
+ return getGlobalData().callerApplicationId;
267
+ },
268
+ /**
269
+ * The application address of the application that called this application. ZeroAddress if this application is at the top-level. ApplicationType mode only.
270
+ */
271
+ get callerApplicationAddress() {
272
+ return getApplicationAddress(this.callerApplicationId);
273
+ },
274
+ /**
275
+ * The additional minimum balance required to create (and opt-in to) an asset.
276
+ */
277
+ get assetCreateMinBalance() {
278
+ return getGlobalData().assetCreateMinBalance;
279
+ },
280
+ /**
281
+ * The additional minimum balance required to opt-in to an asset.
282
+ */
283
+ get assetOptInMinBalance() {
284
+ return getGlobalData().assetOptInMinBalance;
285
+ },
286
+ /**
287
+ * The Genesis Hash for the network.
288
+ */
289
+ get genesisHash() {
290
+ return getGlobalData().genesisHash;
291
+ },
292
+ /**
293
+ * Whether block proposal payouts are enabled.
294
+ * Min AVM version: 11
295
+ */
296
+ get payoutsEnabled() {
297
+ return getGlobalData().payoutsEnabled;
298
+ },
299
+ /**
300
+ * The fee required in a keyreg transaction to make an account incentive eligible.
301
+ * Min AVM version: 11
302
+ */
303
+ get payoutsGoOnlineFee() {
304
+ return getGlobalData().payoutsGoOnlineFee;
305
+ },
306
+ /**
307
+ * The percentage of transaction fees in a block that can be paid to the block proposer.
308
+ * Min AVM version: 11
309
+ */
310
+ get payoutsPercent() {
311
+ return getGlobalData().payoutsPercent;
312
+ },
313
+ /**
314
+ * The minimum algo balance an account must have in the agreement round to receive block payouts in the proposal round.
315
+ * Min AVM version: 11
316
+ */
317
+ get payoutsMinBalance() {
318
+ return getGlobalData().payoutsMinBalance;
319
+ },
320
+ /**
321
+ * The maximum algo balance an account can have in the agreement round to receive block payouts in the proposal round.
322
+ * Min AVM version: 11
323
+ */
324
+ get payoutsMaxBalance() {
325
+ return getGlobalData().payoutsMinBalance;
326
+ },
327
+ };
328
+
329
+ const resolveAppIndex = (appIdOrIndex) => {
330
+ const input = asUint64(appIdOrIndex);
331
+ if (input >= 1001) {
332
+ return input;
333
+ }
334
+ const txn = lazyContext.activeGroup.activeTransaction;
335
+ return txn.apps(input).id;
336
+ };
337
+ const getApp = (app) => {
338
+ try {
339
+ const appId = asMaybeUint64Cls(app);
340
+ if (appId !== undefined) {
341
+ return lazyContext.ledger.getApplication(resolveAppIndex(appId));
342
+ }
343
+ return app;
344
+ }
345
+ catch {
346
+ return undefined;
347
+ }
348
+ };
349
+ const AppParams = {
350
+ appApprovalProgram(a) {
351
+ const app = getApp(a);
352
+ return app === undefined ? [Bytes(), false] : [app.approvalProgram, true];
353
+ },
354
+ appClearStateProgram(a) {
355
+ const app = getApp(a);
356
+ return app === undefined ? [Bytes(), false] : [app.clearStateProgram, true];
357
+ },
358
+ appGlobalNumUint(a) {
359
+ const app = getApp(a);
360
+ return app === undefined ? [Uint64(0), false] : [app.globalNumUint, true];
361
+ },
362
+ appGlobalNumByteSlice(a) {
363
+ const app = getApp(a);
364
+ return app === undefined ? [Uint64(0), false] : [app.globalNumBytes, true];
365
+ },
366
+ appLocalNumUint(a) {
367
+ const app = getApp(a);
368
+ return app === undefined ? [Uint64(0), false] : [app.localNumUint, true];
369
+ },
370
+ appLocalNumByteSlice(a) {
371
+ const app = getApp(a);
372
+ return app === undefined ? [Uint64(0), false] : [app.localNumBytes, true];
373
+ },
374
+ appExtraProgramPages(a) {
375
+ const app = getApp(a);
376
+ return app === undefined ? [Uint64(0), false] : [app.extraProgramPages, true];
377
+ },
378
+ appCreator(a) {
379
+ const app = getApp(a);
380
+ return app === undefined ? [Account(), false] : [app.creator, true];
381
+ },
382
+ appAddress(a) {
383
+ const app = getApp(a);
384
+ return app === undefined ? [Account(), false] : [app.address, true];
385
+ },
386
+ };
387
+
388
+ const getAccount = (acct) => {
389
+ const acctId = asMaybeUint64Cls(acct);
390
+ if (acctId !== undefined) {
391
+ const activeTxn = lazyContext.activeGroup.activeTransaction;
392
+ return activeTxn.accounts(acctId.asAlgoTs());
393
+ }
394
+ return acct;
395
+ };
396
+ const balance = (a) => {
397
+ const acct = getAccount(a);
398
+ return acct.balance;
399
+ };
400
+ const minBalance = (a) => {
401
+ const acct = getAccount(a);
402
+ return acct.minBalance;
403
+ };
404
+ const appOptedIn = (a, b) => {
405
+ const account = getAccount(a);
406
+ const app = getApp(b);
407
+ if (account === undefined || app === undefined) {
408
+ return false;
409
+ }
410
+ return account.isOptedIn(app);
411
+ };
412
+ const AcctParams = {
413
+ acctBalance(a) {
414
+ const acct = getAccount(a);
415
+ return [acct.balance, acct.balance !== 0];
416
+ },
417
+ acctMinBalance(a) {
418
+ const acct = getAccount(a);
419
+ return [acct.minBalance, acct.balance !== 0];
420
+ },
421
+ acctAuthAddr(a) {
422
+ const acct = getAccount(a);
423
+ return [acct.authAddress, acct.balance !== 0];
424
+ },
425
+ acctTotalNumUint(a) {
426
+ const acct = getAccount(a);
427
+ return [acct.totalNumUint, acct.balance !== 0];
428
+ },
429
+ acctTotalNumByteSlice(a) {
430
+ const acct = getAccount(a);
431
+ return [acct.totalNumByteSlice, acct.balance !== 0];
432
+ },
433
+ acctTotalExtraAppPages(a) {
434
+ const acct = getAccount(a);
435
+ return [acct.totalExtraAppPages, acct.balance !== 0];
436
+ },
437
+ acctTotalAppsCreated(a) {
438
+ const acct = getAccount(a);
439
+ return [acct.totalAppsCreated, acct.balance !== 0];
440
+ },
441
+ acctTotalAppsOptedIn(a) {
442
+ const acct = getAccount(a);
443
+ return [acct.totalAppsOptedIn, acct.balance !== 0];
444
+ },
445
+ acctTotalAssetsCreated(a) {
446
+ const acct = getAccount(a);
447
+ return [acct.totalAssetsCreated, acct.balance !== 0];
448
+ },
449
+ acctTotalAssets(a) {
450
+ const acct = getAccount(a);
451
+ return [acct.totalAssets, acct.balance !== 0];
452
+ },
453
+ acctTotalBoxes(a) {
454
+ const acct = getAccount(a);
455
+ return [acct.totalBoxes, acct.balance !== 0];
456
+ },
457
+ acctTotalBoxBytes(a) {
458
+ const acct = getAccount(a);
459
+ return [acct.totalBoxBytes, acct.balance !== 0];
460
+ },
461
+ acctIncentiveEligible: function (a) {
462
+ const acct = getAccount(a);
463
+ const accountData = lazyContext.ledger.accountDataMap.get(acct);
464
+ return [accountData?.incentiveEligible ?? false, acct.balance !== 0];
465
+ },
466
+ acctLastProposed: function (a) {
467
+ const acct = getAccount(a);
468
+ const accountData = lazyContext.ledger.accountDataMap.get(acct);
469
+ return [accountData?.lastProposed ?? Global.round, acct.balance !== 0];
470
+ },
471
+ acctLastHeartbeat: function (a) {
472
+ const acct = getAccount(a);
473
+ const accountData = lazyContext.ledger.accountDataMap.get(acct);
474
+ return [accountData?.lastHeartbeat ?? Global.round, acct.balance !== 0];
475
+ },
476
+ };
477
+
478
+ class VoterData {
479
+ balance;
480
+ incentiveEligible;
481
+ constructor() {
482
+ this.balance = 0;
483
+ this.incentiveEligible = false;
484
+ }
485
+ }
486
+ const getVoterData = (a) => {
487
+ const acct = getAccount(a);
488
+ return lazyContext.getVoterData(acct);
489
+ };
490
+ const VoterParams = {
491
+ voterBalance: function (a) {
492
+ const data = getVoterData(a);
493
+ return [data.balance, data.balance !== 0];
494
+ },
495
+ voterIncentiveEligible: function (a) {
496
+ const data = getVoterData(a);
497
+ return [data.incentiveEligible, data.balance !== 0];
498
+ },
499
+ };
500
+
501
+ const addw = (a, b) => {
502
+ const uint64A = internal.primitives.Uint64Cls.fromCompat(a);
503
+ const uint64B = internal.primitives.Uint64Cls.fromCompat(b);
504
+ const sum = uint64A.asBigInt() + uint64B.asBigInt();
505
+ return toUint128(sum);
506
+ };
507
+ const base64Decode = (e, a) => {
508
+ const encoding = e === Base64.StdEncoding ? 'base64' : 'base64url';
509
+ const bytesValue = internal.primitives.BytesCls.fromCompat(a);
510
+ const stringValue = bytesValue.toString();
511
+ const bufferResult = Buffer.from(stringValue, encoding);
512
+ if (bufferResult.toString(encoding) !== stringValue) {
513
+ internal.errors.avmError('illegal base64 data');
514
+ }
515
+ const uint8ArrayResult = new Uint8Array(bufferResult);
516
+ return Bytes(uint8ArrayResult);
517
+ };
518
+ const bitLength = (a) => {
519
+ const uint64Cls = asMaybeUint64Cls(a);
520
+ const bigUintCls = asMaybeBytesCls(a)?.toBigUint();
521
+ const bigIntValue = (uint64Cls?.asBigInt() ?? bigUintCls?.asBigInt());
522
+ const binaryValue = bigIntValue === 0n ? '' : bigIntValue.toString(2);
523
+ return Uint64(binaryValue.length);
524
+ };
525
+ const bsqrt = (a) => {
526
+ const bigUintClsValue = internal.primitives.BigUintCls.fromCompat(a);
527
+ const bigintValue = internal.primitives.checkBigUint(bigUintClsValue.asBigInt());
528
+ const sqrtValue = squareroot(bigintValue);
529
+ return asBigUint(sqrtValue);
530
+ };
531
+ const btoi = (a) => {
532
+ const bytesValue = internal.primitives.BytesCls.fromCompat(a);
533
+ if (bytesValue.length.asAlgoTs() > BITS_IN_BYTE) {
534
+ internal.errors.avmError(`btoi arg too long, got [${bytesValue.length.valueOf()}]bytes`);
535
+ }
536
+ return bytesValue.toUint64().asAlgoTs();
537
+ };
538
+ const bzero = (a) => {
539
+ const size = internal.primitives.Uint64Cls.fromCompat(a).asBigInt();
540
+ if (size > MAX_BYTES_SIZE) {
541
+ internal.errors.avmError('bzero attempted to create a too large string');
542
+ }
543
+ return Bytes(new Uint8Array(Number(size)));
544
+ };
545
+ const concat = (a, b) => {
546
+ const bytesA = internal.primitives.BytesCls.fromCompat(a);
547
+ const bytesB = internal.primitives.BytesCls.fromCompat(b);
548
+ return bytesA.concat(bytesB).asAlgoTs();
549
+ };
550
+ const divmodw = (a, b, c, d) => {
551
+ const i = uint128ToBigInt(a, b);
552
+ const j = uint128ToBigInt(c, d);
553
+ const div = i / j;
554
+ const mod = i % j;
555
+ return [...toUint128(div), ...toUint128(mod)];
556
+ };
557
+ const divw = (a, b, c) => {
558
+ const i = uint128ToBigInt(a, b);
559
+ const j = internal.primitives.Uint64Cls.fromCompat(c).asBigInt();
560
+ return Uint64(i / j);
561
+ };
562
+ const exp = (a, b) => {
563
+ const base = internal.primitives.Uint64Cls.fromCompat(a).asBigInt();
564
+ const exponent = internal.primitives.Uint64Cls.fromCompat(b).asBigInt();
565
+ if (base === 0n && exponent === 0n) {
566
+ throw internal.errors.codeError('0 ** 0 is undefined');
567
+ }
568
+ return Uint64(base ** exponent);
569
+ };
570
+ const expw = (a, b) => {
571
+ const base = internal.primitives.Uint64Cls.fromCompat(a).asBigInt();
572
+ const exponent = internal.primitives.Uint64Cls.fromCompat(b).asBigInt();
573
+ if (base === 0n && exponent === 0n) {
574
+ throw internal.errors.codeError('0 ** 0 is undefined');
575
+ }
576
+ return toUint128(base ** exponent);
577
+ };
578
+ const extract = ((a, b, c) => {
579
+ const bytesValue = internal.primitives.BytesCls.fromCompat(a);
580
+ const bytesLength = bytesValue.length.asBigInt();
581
+ const start = internal.primitives.Uint64Cls.fromCompat(b).asBigInt();
582
+ const length = c !== undefined ? internal.primitives.Uint64Cls.fromCompat(c).asBigInt() : undefined;
583
+ const end = length !== undefined ? start + length : undefined;
584
+ if (start > bytesLength) {
585
+ internal.errors.codeError(`extraction start ${start} is beyond length`);
586
+ }
587
+ if (end !== undefined && end > bytesLength) {
588
+ internal.errors.codeError(`extraction end ${end} is beyond length`);
589
+ }
590
+ return bytesValue.slice(start, end).asAlgoTs();
591
+ });
592
+ const extractUint16 = (a, b) => {
593
+ const result = extract(a, b, 2);
594
+ const bytesResult = internal.primitives.BytesCls.fromCompat(result);
595
+ return bytesResult.toUint64().asAlgoTs();
596
+ };
597
+ const extractUint32 = (a, b) => {
598
+ const result = extract(a, b, 4);
599
+ const bytesResult = internal.primitives.BytesCls.fromCompat(result);
600
+ return bytesResult.toUint64().asAlgoTs();
601
+ };
602
+ const extractUint64 = (a, b) => {
603
+ const result = extract(a, b, 8);
604
+ const bytesResult = internal.primitives.BytesCls.fromCompat(result);
605
+ return bytesResult.toUint64().asAlgoTs();
606
+ };
607
+ const getBit = (a, b) => {
608
+ const binaryString = toBinaryString(internal.primitives.isUint64(a) ? asUint64Cls(a).toBytes().asAlgoTs() : asBytes(a));
609
+ const index = internal.primitives.Uint64Cls.fromCompat(b).asNumber();
610
+ const adjustedIndex = asMaybeUint64Cls(a) ? binaryString.length - index - 1 : index;
611
+ if (adjustedIndex < 0 || adjustedIndex >= binaryString.length) {
612
+ internal.errors.codeError(`getBit index ${index} is beyond length`);
613
+ }
614
+ return binaryString[adjustedIndex] === '1' ? Uint64(1) : Uint64(0);
615
+ };
616
+ const getByte = (a, b) => {
617
+ const bytesValue = internal.primitives.BytesCls.fromCompat(a);
618
+ const index = internal.primitives.Uint64Cls.fromCompat(b).asNumber();
619
+ if (index >= bytesValue.length.asNumber()) {
620
+ internal.errors.codeError(`getBytes index ${index} is beyond length`);
621
+ }
622
+ return bytesValue.at(index).toUint64().asAlgoTs();
623
+ };
624
+ const itob = (a) => {
625
+ return asUint64Cls(a).toBytes().asAlgoTs();
626
+ };
627
+ const len = (a) => {
628
+ return asBytesCls(a).length.asAlgoTs();
629
+ };
630
+ const mulw = (a, b) => {
631
+ const uint64A = internal.primitives.Uint64Cls.fromCompat(a);
632
+ const uint64B = internal.primitives.Uint64Cls.fromCompat(b);
633
+ const product = uint64A.asBigInt() * uint64B.asBigInt();
634
+ return toUint128(product);
635
+ };
636
+ const replace = (a, b, c) => {
637
+ const bytesValue = internal.primitives.BytesCls.fromCompat(a);
638
+ const index = internal.primitives.Uint64Cls.fromCompat(b).asNumber();
639
+ const replacement = internal.primitives.BytesCls.fromCompat(c);
640
+ const valueLength = bytesValue.length.asNumber();
641
+ const replacementLength = replacement.length.asNumber();
642
+ if (index + replacementLength > valueLength) {
643
+ internal.errors.codeError(`expected value <= ${valueLength}, got: ${index + replacementLength}`);
644
+ }
645
+ return bytesValue
646
+ .slice(0, index)
647
+ .concat(replacement)
648
+ .concat(bytesValue.slice(index + replacementLength, valueLength))
649
+ .asAlgoTs();
650
+ };
651
+ const select = ((a, b, c) => {
652
+ const uint64A = asMaybeUint64Cls(a);
653
+ const uint64B = asMaybeUint64Cls(b);
654
+ const bytesA = asMaybeBytesCls(a);
655
+ const bytesB = asMaybeBytesCls(b);
656
+ const bigIntC = internal.primitives.Uint64Cls.fromCompat(c).asBigInt();
657
+ return (bigIntC !== 0n ? (uint64B ?? bytesB) : (uint64A ?? bytesA)).asAlgoTs();
658
+ });
659
+ const setBit = ((a, b, c) => {
660
+ const uint64Cls = asMaybeUint64Cls(a);
661
+ const indexParam = internal.primitives.Uint64Cls.fromCompat(b).asNumber();
662
+ const bit = internal.primitives.Uint64Cls.fromCompat(c).asNumber();
663
+ if (uint64Cls) {
664
+ const binaryString = toBinaryString(uint64Cls?.toBytes().asAlgoTs());
665
+ const index = binaryString.length - indexParam - 1;
666
+ const newBytes = doSetBit(binaryString, index, bit);
667
+ return newBytes.toUint64().asAlgoTs();
668
+ }
669
+ else {
670
+ const bytesCls = asMaybeBytesCls(a);
671
+ testInvariant(bytesCls, 'a must be uint64 or bytes');
672
+ const binaryString = toBinaryString(bytesCls.asAlgoTs());
673
+ const newBytes = doSetBit(binaryString, indexParam, bit);
674
+ return newBytes.asAlgoTs();
675
+ }
676
+ });
677
+ const setByte = (a, b, c) => {
678
+ const binaryString = toBinaryString(internal.primitives.BytesCls.fromCompat(a).asAlgoTs());
679
+ const byteIndex = internal.primitives.Uint64Cls.fromCompat(b).asNumber();
680
+ const bitIndex = byteIndex * BITS_IN_BYTE;
681
+ const replacementNumber = internal.primitives.Uint64Cls.fromCompat(c);
682
+ const replacement = toBinaryString(replacementNumber.toBytes().at(-1).asAlgoTs());
683
+ if (bitIndex >= binaryString.length) {
684
+ internal.errors.codeError(`setByte index ${byteIndex} is beyond length`);
685
+ }
686
+ if (replacementNumber.valueOf() > MAX_UINT8) {
687
+ internal.errors.codeError(`setByte value ${replacementNumber.asNumber()} > ${MAX_UINT8}`);
688
+ }
689
+ const updatedString = binaryString.slice(0, bitIndex) + replacement + binaryString.slice(bitIndex + replacement.length);
690
+ const updatedBytes = binaryStringToBytes(updatedString);
691
+ return updatedBytes.asAlgoTs();
692
+ };
693
+ const shl = (a, b) => {
694
+ const uint64A = internal.primitives.Uint64Cls.fromCompat(a);
695
+ const uint64B = internal.primitives.Uint64Cls.fromCompat(b);
696
+ const bigIntA = uint64A.asBigInt();
697
+ const bigIntB = uint64B.asBigInt();
698
+ if (bigIntB >= UINT64_SIZE) {
699
+ internal.errors.codeError(`shl value ${bigIntB} >= ${UINT64_SIZE}`);
700
+ }
701
+ const shifted = (bigIntA * 2n ** bigIntB) % 2n ** BigInt(UINT64_SIZE);
702
+ return Uint64(shifted);
703
+ };
704
+ const shr = (a, b) => {
705
+ const uint64A = internal.primitives.Uint64Cls.fromCompat(a);
706
+ const uint64B = internal.primitives.Uint64Cls.fromCompat(b);
707
+ const bigIntA = uint64A.asBigInt();
708
+ const bigIntB = uint64B.asBigInt();
709
+ if (bigIntB >= UINT64_SIZE) {
710
+ internal.errors.codeError(`shr value ${bigIntB} >= ${UINT64_SIZE}`);
711
+ }
712
+ const shifted = bigIntA / 2n ** bigIntB;
713
+ return Uint64(shifted);
714
+ };
715
+ const sqrt = (a) => {
716
+ const bigIntValue = internal.primitives.Uint64Cls.fromCompat(a).asBigInt();
717
+ const sqrtValue = squareroot(bigIntValue);
718
+ return Uint64(sqrtValue);
719
+ };
720
+ const substring = (a, b, c) => {
721
+ const bytesValue = internal.primitives.BytesCls.fromCompat(a);
722
+ const start = internal.primitives.Uint64Cls.fromCompat(b).asBigInt();
723
+ const end = internal.primitives.Uint64Cls.fromCompat(c).asBigInt();
724
+ if (start > end) {
725
+ internal.errors.codeError('substring end before start');
726
+ }
727
+ if (end > bytesValue.length.asNumber()) {
728
+ internal.errors.codeError('substring range beyond length of string');
729
+ }
730
+ return bytesValue.slice(start, end).asAlgoTs();
731
+ };
732
+ const JsonRef = new Proxy({}, {
733
+ get: (_target, prop) => {
734
+ notImplementedError(`JsonRef.${prop.toString()}`);
735
+ },
736
+ });
737
+ const squareroot = (x) => {
738
+ let lo = 0n, hi = x;
739
+ while (lo <= hi) {
740
+ const mid = (lo + hi) / 2n;
741
+ if (mid * mid > x)
742
+ hi = mid - 1n;
743
+ else
744
+ lo = mid + 1n;
745
+ }
746
+ return hi;
747
+ };
748
+ const toUint128 = (value) => {
749
+ const cf = value >> 64n;
750
+ const rest = value & MAX_UINT64;
751
+ return [Uint64(cf), Uint64(rest)];
752
+ };
753
+ const uint128ToBigInt = (a, b) => {
754
+ const bigIntA = internal.primitives.Uint64Cls.fromCompat(a).asBigInt();
755
+ const bigIntB = internal.primitives.Uint64Cls.fromCompat(b).asBigInt();
756
+ return (bigIntA << 64n) + bigIntB;
757
+ };
758
+ const toBinaryString = (a) => {
759
+ return [...internal.primitives.BytesCls.fromCompat(a).asUint8Array()].map((x) => x.toString(2).padStart(BITS_IN_BYTE, '0')).join('');
760
+ };
761
+ const doSetBit = (binaryString, index, bit) => {
762
+ if (index < 0 || index >= binaryString.length) {
763
+ internal.errors.codeError(`setBit index ${index < 0 ? binaryString.length - index : index} is beyond length`);
764
+ }
765
+ if (bit !== 0 && bit !== 1) {
766
+ internal.errors.codeError(`setBit value > 1`);
767
+ }
768
+ const updatedString = binaryString.slice(0, index) + bit.toString() + binaryString.slice(index + 1);
769
+ return binaryStringToBytes(updatedString);
770
+ };
771
+
772
+ const resolveAssetIndex = (assetIdOrIndex) => {
773
+ const input = asUint64(assetIdOrIndex);
774
+ if (input >= 1001) {
775
+ return input;
776
+ }
777
+ const txn = lazyContext.activeGroup.activeTransaction;
778
+ return txn.assets(input).id;
779
+ };
780
+ const getAsset = (asset) => {
781
+ try {
782
+ const assetId = asMaybeUint64Cls(asset);
783
+ if (assetId !== undefined) {
784
+ return lazyContext.ledger.getAsset(resolveAssetIndex(assetId));
785
+ }
786
+ return asset;
787
+ }
788
+ catch {
789
+ return undefined;
790
+ }
791
+ };
792
+ const AssetParams = {
793
+ assetTotal(a) {
794
+ const asset = getAsset(a);
795
+ return asset === undefined ? [Uint64(0), false] : [asset.total, true];
796
+ },
797
+ assetDecimals(a) {
798
+ const asset = getAsset(a);
799
+ return asset === undefined ? [Uint64(0), false] : [asset.decimals, true];
800
+ },
801
+ assetDefaultFrozen(a) {
802
+ const asset = getAsset(a);
803
+ return asset === undefined ? [false, false] : [asset.defaultFrozen, true];
804
+ },
805
+ assetUnitName(a) {
806
+ const asset = getAsset(a);
807
+ return asset === undefined ? [Bytes(), false] : [asset.unitName, true];
808
+ },
809
+ assetName(a) {
810
+ const asset = getAsset(a);
811
+ return asset === undefined ? [Bytes(), false] : [asset.name, true];
812
+ },
813
+ assetUrl(a) {
814
+ const asset = getAsset(a);
815
+ return asset === undefined ? [Bytes(), false] : [asset.url, true];
816
+ },
817
+ assetMetadataHash(a) {
818
+ const asset = getAsset(a);
819
+ return asset === undefined ? [Bytes(), false] : [asset.metadataHash, true];
820
+ },
821
+ assetManager(a) {
822
+ const asset = getAsset(a);
823
+ return asset === undefined ? [Account(), false] : [asset.manager, true];
824
+ },
825
+ assetReserve(a) {
826
+ const asset = getAsset(a);
827
+ return asset === undefined ? [Account(), false] : [asset.reserve, true];
828
+ },
829
+ assetFreeze(a) {
830
+ const asset = getAsset(a);
831
+ return asset === undefined ? [Account(), false] : [asset.freeze, true];
832
+ },
833
+ assetClawback(a) {
834
+ const asset = getAsset(a);
835
+ return asset === undefined ? [Account(), false] : [asset.clawback, true];
836
+ },
837
+ assetCreator(a) {
838
+ const asset = getAsset(a);
839
+ return asset === undefined ? [Account(), false] : [asset.creator, true];
840
+ },
841
+ };
842
+
843
+ export { AcctParams as A, BlockData as B, extractUint64 as C, getBit as D, getByte as E, itob as F, GlobalData as G, len as H, minBalance as I, JsonRef as J, mulw as K, replace as L, select as M, setBit as N, setByte as O, shl as P, shr as Q, sqrt as R, substring as S, VoterData as V, Global as a, btoi as b, getAsset as c, getApp as d, getAccount as e, AppParams as f, getEncoder as g, AssetParams as h, Block as i, VoterParams as j, addw as k, appOptedIn as l, balance as m, base64Decode as n, bitLength as o, bsqrt as p, bzero as q, concat as r, divmodw as s, toBytes as t, divw as u, exp as v, expw as w, extract as x, extractUint16 as y, extractUint32 as z };
844
+ //# sourceMappingURL=asset-params-CzUcFBcQ.js.map