@algorandfoundation/algokit-utils 9.2.0-beta.9 → 9.2.1-beta.1

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 (340) hide show
  1. package/_virtual/_rolldown/runtime.js +33 -0
  2. package/_virtual/_rolldown/runtime.mjs +13 -0
  3. package/account/account.d.ts +25 -30
  4. package/account/account.js +151 -146
  5. package/account/account.js.map +1 -1
  6. package/account/account.mjs +149 -144
  7. package/account/account.mjs.map +1 -1
  8. package/account/get-account-config-from-environment.d.ts +7 -2
  9. package/account/get-account-config-from-environment.js +19 -21
  10. package/account/get-account-config-from-environment.js.map +1 -1
  11. package/account/get-account-config-from-environment.mjs +19 -19
  12. package/account/get-account-config-from-environment.mjs.map +1 -1
  13. package/account/get-account.d.ts +14 -12
  14. package/account/get-account.js +56 -59
  15. package/account/get-account.js.map +1 -1
  16. package/account/get-account.mjs +56 -57
  17. package/account/get-account.mjs.map +1 -1
  18. package/account/get-dispenser-account.d.ts +9 -5
  19. package/account/get-dispenser-account.js +20 -18
  20. package/account/get-dispenser-account.js.map +1 -1
  21. package/account/get-dispenser-account.mjs +20 -16
  22. package/account/get-dispenser-account.mjs.map +1 -1
  23. package/account/mnemonic-account.d.ts +7 -3
  24. package/account/mnemonic-account.js +17 -17
  25. package/account/mnemonic-account.js.map +1 -1
  26. package/account/mnemonic-account.mjs +15 -15
  27. package/account/mnemonic-account.mjs.map +1 -1
  28. package/amount.d.ts +40 -35
  29. package/amount.js +33 -34
  30. package/amount.js.map +1 -1
  31. package/amount.mjs +33 -32
  32. package/amount.mjs.map +1 -1
  33. package/app-client.d.ts +10 -6
  34. package/app-client.js +91 -86
  35. package/app-client.js.map +1 -1
  36. package/app-client.mjs +91 -84
  37. package/app-client.mjs.map +1 -1
  38. package/app-deploy.d.ts +26 -24
  39. package/app-deploy.js +235 -253
  40. package/app-deploy.js.map +1 -1
  41. package/app-deploy.mjs +233 -251
  42. package/app-deploy.mjs.map +1 -1
  43. package/app.d.ts +45 -46
  44. package/app.js +253 -271
  45. package/app.js.map +1 -1
  46. package/app.mjs +249 -267
  47. package/app.mjs.map +1 -1
  48. package/asset.d.ts +16 -12
  49. package/asset.js +116 -122
  50. package/asset.js.map +1 -1
  51. package/asset.mjs +116 -120
  52. package/asset.mjs.map +1 -1
  53. package/config.d.ts +7 -2
  54. package/config.js +5 -7
  55. package/config.js.map +1 -1
  56. package/config.mjs +5 -4
  57. package/config.mjs.map +1 -1
  58. package/debugging/debugging.d.ts +5 -1
  59. package/debugging/debugging.js +11 -11
  60. package/debugging/debugging.js.map +1 -1
  61. package/debugging/debugging.mjs +11 -9
  62. package/debugging/debugging.mjs.map +1 -1
  63. package/dispenser-client.d.ts +7 -2
  64. package/dispenser-client.js +23 -24
  65. package/dispenser-client.js.map +1 -1
  66. package/dispenser-client.mjs +23 -22
  67. package/dispenser-client.mjs.map +1 -1
  68. package/index.d.ts +27 -18
  69. package/index.js +140 -143
  70. package/index.mjs +27 -29
  71. package/indexer-lookup.d.ts +18 -11
  72. package/indexer-lookup.js +112 -120
  73. package/indexer-lookup.js.map +1 -1
  74. package/indexer-lookup.mjs +105 -118
  75. package/indexer-lookup.mjs.map +1 -1
  76. package/localnet/get-kmd-wallet-account.d.ts +9 -7
  77. package/localnet/get-kmd-wallet-account.js +28 -26
  78. package/localnet/get-kmd-wallet-account.js.map +1 -1
  79. package/localnet/get-kmd-wallet-account.mjs +28 -24
  80. package/localnet/get-kmd-wallet-account.mjs.map +1 -1
  81. package/localnet/get-localnet-dispenser-account.d.ts +7 -5
  82. package/localnet/get-localnet-dispenser-account.js +17 -15
  83. package/localnet/get-localnet-dispenser-account.js.map +1 -1
  84. package/localnet/get-localnet-dispenser-account.mjs +17 -13
  85. package/localnet/get-localnet-dispenser-account.mjs.map +1 -1
  86. package/localnet/get-or-create-kmd-wallet-account.d.ts +10 -8
  87. package/localnet/get-or-create-kmd-wallet-account.js +28 -26
  88. package/localnet/get-or-create-kmd-wallet-account.js.map +1 -1
  89. package/localnet/get-or-create-kmd-wallet-account.mjs +28 -24
  90. package/localnet/get-or-create-kmd-wallet-account.mjs.map +1 -1
  91. package/localnet/is-localnet.d.ts +7 -3
  92. package/localnet/is-localnet.js +9 -10
  93. package/localnet/is-localnet.js.map +1 -1
  94. package/localnet/is-localnet.mjs +9 -8
  95. package/localnet/is-localnet.mjs.map +1 -1
  96. package/network-client.d.ts +17 -15
  97. package/network-client.js +115 -116
  98. package/network-client.js.map +1 -1
  99. package/network-client.mjs +115 -114
  100. package/network-client.mjs.map +1 -1
  101. package/package.json +12 -3
  102. package/testing/account.d.ts +11 -9
  103. package/testing/account.js +31 -33
  104. package/testing/account.js.map +1 -1
  105. package/testing/account.mjs +29 -31
  106. package/testing/account.mjs.map +1 -1
  107. package/testing/fixtures/algokit-log-capture-fixture.d.ts +7 -2
  108. package/testing/fixtures/algokit-log-capture-fixture.js +36 -41
  109. package/testing/fixtures/algokit-log-capture-fixture.js.map +1 -1
  110. package/testing/fixtures/algokit-log-capture-fixture.mjs +36 -39
  111. package/testing/fixtures/algokit-log-capture-fixture.mjs.map +1 -1
  112. package/testing/fixtures/algorand-fixture.d.ts +9 -4
  113. package/testing/fixtures/algorand-fixture.js +67 -62
  114. package/testing/fixtures/algorand-fixture.js.map +1 -1
  115. package/testing/fixtures/algorand-fixture.mjs +66 -59
  116. package/testing/fixtures/algorand-fixture.mjs.map +1 -1
  117. package/testing/index.d.ts +7 -5
  118. package/testing/index.js +13 -18
  119. package/testing/index.mjs +7 -7
  120. package/testing/indexer.d.ts +5 -1
  121. package/testing/indexer.js +28 -37
  122. package/testing/indexer.js.map +1 -1
  123. package/testing/indexer.mjs +28 -35
  124. package/testing/indexer.mjs.map +1 -1
  125. package/testing/test-logger.d.ts +41 -36
  126. package/testing/test-logger.js +71 -76
  127. package/testing/test-logger.js.map +1 -1
  128. package/testing/test-logger.mjs +71 -74
  129. package/testing/test-logger.mjs.map +1 -1
  130. package/testing/transaction-logger.d.ts +30 -27
  131. package/testing/transaction-logger.js +77 -93
  132. package/testing/transaction-logger.js.map +1 -1
  133. package/testing/transaction-logger.mjs +74 -90
  134. package/testing/transaction-logger.mjs.map +1 -1
  135. package/transaction/legacy-bridge.js +100 -111
  136. package/transaction/legacy-bridge.js.map +1 -1
  137. package/transaction/legacy-bridge.mjs +97 -108
  138. package/transaction/legacy-bridge.mjs.map +1 -1
  139. package/transaction/perform-atomic-transaction-composer-simulate.d.ts +7 -5
  140. package/transaction/perform-atomic-transaction-composer-simulate.js +31 -36
  141. package/transaction/perform-atomic-transaction-composer-simulate.js.map +1 -1
  142. package/transaction/perform-atomic-transaction-composer-simulate.mjs +28 -33
  143. package/transaction/perform-atomic-transaction-composer-simulate.mjs.map +1 -1
  144. package/transaction/transaction.d.ts +34 -35
  145. package/transaction/transaction.js +716 -914
  146. package/transaction/transaction.js.map +1 -1
  147. package/transaction/transaction.mjs +713 -911
  148. package/transaction/transaction.mjs.map +1 -1
  149. package/transfer/transfer-algos.d.ts +9 -5
  150. package/transfer/transfer-algos.js +26 -27
  151. package/transfer/transfer-algos.js.map +1 -1
  152. package/transfer/transfer-algos.mjs +26 -25
  153. package/transfer/transfer-algos.mjs.map +1 -1
  154. package/transfer/transfer.d.ts +11 -8
  155. package/transfer/transfer.js +94 -100
  156. package/transfer/transfer.js.map +1 -1
  157. package/transfer/transfer.mjs +94 -98
  158. package/transfer/transfer.mjs.map +1 -1
  159. package/types/account-manager.d.ts +432 -429
  160. package/types/account-manager.js +591 -602
  161. package/types/account-manager.js.map +1 -1
  162. package/types/account-manager.mjs +587 -599
  163. package/types/account-manager.mjs.map +1 -1
  164. package/types/account.d.ts +192 -202
  165. package/types/account.js +91 -88
  166. package/types/account.js.map +1 -1
  167. package/types/account.mjs +88 -86
  168. package/types/account.mjs.map +1 -1
  169. package/types/algo-http-client-with-retry.d.ts +15 -10
  170. package/types/algo-http-client-with-retry.js +70 -92
  171. package/types/algo-http-client-with-retry.js.map +1 -1
  172. package/types/algo-http-client-with-retry.mjs +69 -90
  173. package/types/algo-http-client-with-retry.mjs.map +1 -1
  174. package/types/algorand-client-transaction-creator.d.ts +778 -761
  175. package/types/algorand-client-transaction-creator.js +733 -724
  176. package/types/algorand-client-transaction-creator.js.map +1 -1
  177. package/types/algorand-client-transaction-creator.mjs +732 -722
  178. package/types/algorand-client-transaction-creator.mjs.map +1 -1
  179. package/types/algorand-client-transaction-sender.d.ts +1090 -1268
  180. package/types/algorand-client-transaction-sender.js +930 -953
  181. package/types/algorand-client-transaction-sender.js.map +1 -1
  182. package/types/algorand-client-transaction-sender.mjs +927 -951
  183. package/types/algorand-client-transaction-sender.mjs.map +1 -1
  184. package/types/algorand-client.d.ts +239 -236
  185. package/types/algorand-client.js +322 -320
  186. package/types/algorand-client.js.map +1 -1
  187. package/types/algorand-client.mjs +321 -318
  188. package/types/algorand-client.mjs.map +1 -1
  189. package/types/amount.d.ts +47 -43
  190. package/types/amount.js +66 -70
  191. package/types/amount.js.map +1 -1
  192. package/types/amount.mjs +63 -68
  193. package/types/amount.mjs.map +1 -1
  194. package/types/app-arc56.d.ts +235 -272
  195. package/types/app-arc56.js +124 -170
  196. package/types/app-arc56.js.map +1 -1
  197. package/types/app-arc56.mjs +121 -168
  198. package/types/app-arc56.mjs.map +1 -1
  199. package/types/app-client.d.ts +1128 -1972
  200. package/types/app-client.js +1633 -1791
  201. package/types/app-client.js.map +1 -1
  202. package/types/app-client.mjs +1624 -1783
  203. package/types/app-client.mjs.map +1 -1
  204. package/types/app-deployer.d.ts +139 -141
  205. package/types/app-deployer.js +344 -384
  206. package/types/app-deployer.js.map +1 -1
  207. package/types/app-deployer.mjs +341 -382
  208. package/types/app-deployer.mjs.map +1 -1
  209. package/types/app-factory.d.ts +762 -914
  210. package/types/app-factory.js +496 -488
  211. package/types/app-factory.js.map +1 -1
  212. package/types/app-factory.mjs +491 -484
  213. package/types/app-factory.mjs.map +1 -1
  214. package/types/app-manager.d.ts +307 -311
  215. package/types/app-manager.js +422 -474
  216. package/types/app-manager.js.map +1 -1
  217. package/types/app-manager.mjs +419 -472
  218. package/types/app-manager.mjs.map +1 -1
  219. package/types/app-spec.d.ts +118 -117
  220. package/types/app-spec.js +125 -135
  221. package/types/app-spec.js.map +1 -1
  222. package/types/app-spec.mjs +121 -132
  223. package/types/app-spec.mjs.map +1 -1
  224. package/types/app.d.ts +229 -241
  225. package/types/app.js +36 -28
  226. package/types/app.js.map +1 -1
  227. package/types/app.mjs +33 -26
  228. package/types/app.mjs.map +1 -1
  229. package/types/asset-manager.d.ts +204 -199
  230. package/types/asset-manager.js +165 -174
  231. package/types/asset-manager.js.map +1 -1
  232. package/types/asset-manager.mjs +164 -172
  233. package/types/asset-manager.mjs.map +1 -1
  234. package/types/asset.d.ts +95 -91
  235. package/types/asset.js +0 -3
  236. package/types/asset.mjs +0 -2
  237. package/types/async-event-emitter.d.ts +18 -13
  238. package/types/async-event-emitter.js +37 -49
  239. package/types/async-event-emitter.js.map +1 -1
  240. package/types/async-event-emitter.mjs +36 -47
  241. package/types/async-event-emitter.mjs.map +1 -1
  242. package/types/client-manager.d.ts +453 -451
  243. package/types/client-manager.js +602 -598
  244. package/types/client-manager.js.map +1 -1
  245. package/types/client-manager.mjs +597 -594
  246. package/types/client-manager.mjs.map +1 -1
  247. package/types/composer.d.ts +1211 -1248
  248. package/types/composer.js +1436 -1487
  249. package/types/composer.js.map +1 -1
  250. package/types/composer.mjs +1430 -1482
  251. package/types/composer.mjs.map +1 -1
  252. package/types/config.d.ts +53 -48
  253. package/types/config.js +78 -77
  254. package/types/config.js.map +1 -1
  255. package/types/config.mjs +77 -75
  256. package/types/config.mjs.map +1 -1
  257. package/types/debugging.d.ts +25 -23
  258. package/types/debugging.js +9 -11
  259. package/types/debugging.js.map +1 -1
  260. package/types/debugging.mjs +8 -9
  261. package/types/debugging.mjs.map +1 -1
  262. package/types/dispenser-client.d.ts +57 -52
  263. package/types/dispenser-client.js +120 -141
  264. package/types/dispenser-client.js.map +1 -1
  265. package/types/dispenser-client.mjs +119 -139
  266. package/types/dispenser-client.mjs.map +1 -1
  267. package/types/expand.d.ts +5 -3
  268. package/types/expand.js +0 -3
  269. package/types/expand.mjs +0 -2
  270. package/types/indexer.d.ts +104 -100
  271. package/types/indexer.js +36 -31
  272. package/types/indexer.js.map +1 -1
  273. package/types/indexer.mjs +32 -30
  274. package/types/indexer.mjs.map +1 -1
  275. package/types/instance-of.d.ts +5 -3
  276. package/types/instance-of.js +0 -3
  277. package/types/instance-of.mjs +0 -2
  278. package/types/kmd-account-manager.d.ts +75 -70
  279. package/types/kmd-account-manager.js +150 -184
  280. package/types/kmd-account-manager.js.map +1 -1
  281. package/types/kmd-account-manager.mjs +147 -182
  282. package/types/kmd-account-manager.mjs.map +1 -1
  283. package/types/lifecycle-events.d.ts +13 -8
  284. package/types/lifecycle-events.js +10 -7
  285. package/types/lifecycle-events.js.map +1 -1
  286. package/types/lifecycle-events.mjs +9 -7
  287. package/types/lifecycle-events.mjs.map +1 -1
  288. package/types/logging.d.ts +15 -11
  289. package/types/logging.js +30 -31
  290. package/types/logging.js.map +1 -1
  291. package/types/logging.mjs +29 -29
  292. package/types/logging.mjs.map +1 -1
  293. package/types/logic-error.d.ts +33 -29
  294. package/types/logic-error.js +50 -49
  295. package/types/logic-error.js.map +1 -1
  296. package/types/logic-error.mjs +49 -47
  297. package/types/logic-error.mjs.map +1 -1
  298. package/types/network-client.d.ts +32 -27
  299. package/types/network-client.js +10 -9
  300. package/types/network-client.js.map +1 -1
  301. package/types/network-client.mjs +9 -7
  302. package/types/network-client.mjs.map +1 -1
  303. package/types/testing.d.ts +131 -132
  304. package/types/testing.js +0 -3
  305. package/types/testing.mjs +0 -2
  306. package/types/transaction.d.ts +110 -110
  307. package/types/transaction.js +0 -3
  308. package/types/transaction.mjs +0 -2
  309. package/types/transfer.d.ts +70 -66
  310. package/types/transfer.js +0 -3
  311. package/types/transfer.mjs +0 -2
  312. package/util.js +73 -118
  313. package/util.js.map +1 -1
  314. package/util.mjs +73 -116
  315. package/util.mjs.map +1 -1
  316. package/account/index.d.ts +0 -5
  317. package/debugging/index.d.ts +0 -1
  318. package/index.js.map +0 -1
  319. package/index.mjs.map +0 -1
  320. package/localnet/index.d.ts +0 -4
  321. package/testing/_asset.d.ts +0 -3
  322. package/testing/fixtures/index.d.ts +0 -2
  323. package/testing/index.js.map +0 -1
  324. package/testing/index.mjs.map +0 -1
  325. package/transaction/index.d.ts +0 -2
  326. package/transaction/legacy-bridge.d.ts +0 -35
  327. package/transfer/index.d.ts +0 -2
  328. package/types/asset.js.map +0 -1
  329. package/types/asset.mjs.map +0 -1
  330. package/types/expand.js.map +0 -1
  331. package/types/expand.mjs.map +0 -1
  332. package/types/instance-of.js.map +0 -1
  333. package/types/instance-of.mjs.map +0 -1
  334. package/types/testing.js.map +0 -1
  335. package/types/testing.mjs.map +0 -1
  336. package/types/transaction.js.map +0 -1
  337. package/types/transaction.mjs.map +0 -1
  338. package/types/transfer.js.map +0 -1
  339. package/types/transfer.mjs.map +0 -1
  340. package/util.d.ts +0 -48
@@ -1,487 +1,435 @@
1
- 'use strict';
2
-
3
- var algosdk = require('algosdk');
4
- var transaction = require('../transaction/transaction.js');
5
- var types_app = require('./app.js');
6
-
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
+ const require_runtime = require("../_virtual/_rolldown/runtime.js");
3
+ const require_app = require("./app.js");
4
+ const require_transaction = require("../transaction/transaction.js");
5
+ let algosdk = require("algosdk");
6
+ algosdk = require_runtime.__toESM(algosdk);
7
+ //#region src/types/app-manager.ts
7
8
  /** Allows management of application information. */
8
- class AppManager {
9
- /**
10
- * Creates an `AppManager`
11
- * @param algod An algod instance
12
- */
13
- constructor(algod) {
14
- this._compilationResults = {};
15
- this._algod = algod;
16
- }
17
- /**
18
- * Compiles the given TEAL using algod and returns the result, including source map.
19
- *
20
- * The result of this compilation is also cached keyed by the TEAL
21
- * code so it can be retrieved via `getCompilationResult`.
22
- *
23
- * This function is re-entrant; it will only compile the same code once.
24
- *
25
- * @param tealCode The TEAL code
26
- * @returns The information about the compiled file
27
- * @example
28
- * ```typescript
29
- * const compiled = await appManager.compileTeal(tealProgram)
30
- * ```
31
- */
32
- async compileTeal(tealCode) {
33
- if (this._compilationResults[tealCode]) {
34
- return this._compilationResults[tealCode];
35
- }
36
- const compiled = await this._algod.compile(tealCode).sourcemap(true).do();
37
- const result = {
38
- teal: tealCode,
39
- compiled: compiled.result,
40
- compiledHash: compiled.hash,
41
- compiledBase64ToBytes: new Uint8Array(Buffer.from(compiled.result, 'base64')),
42
- sourceMap: new algosdk.ProgramSourceMap(JSON.parse(algosdk.encodeJSON(compiled.sourcemap))),
43
- };
44
- this._compilationResults[tealCode] = result;
45
- return result;
46
- }
47
- /**
48
- * Performs template substitution of a teal template and compiles it, returning the compiled result.
49
- *
50
- * Looks for `TMPL_{parameter}` for template replacements and replaces AlgoKit deploy-time control parameters
51
- * if deployment metadata is specified.
52
- *
53
- * * `TMPL_UPDATABLE` for updatability / immutability control
54
- * * `TMPL_DELETABLE` for deletability / permanence control
55
- *
56
- * @param tealTemplateCode The TEAL logic to compile
57
- * @param templateParams Any parameters to replace in the .teal file before compiling
58
- * @param deploymentMetadata The deployment metadata the app will be deployed with
59
- * @returns The information about the compiled code
60
- * @example
61
- * ```typescript
62
- * const compiled = await appManager.compileTealTemplate(tealTemplate, { TMPL_APP_ID: 12345n }, { updatable: true, deletable: false })
63
- * ```
64
- */
65
- async compileTealTemplate(tealTemplateCode, templateParams, deploymentMetadata) {
66
- let tealCode = AppManager.stripTealComments(tealTemplateCode);
67
- tealCode = AppManager.replaceTealTemplateParams(tealCode, templateParams);
68
- if (deploymentMetadata) {
69
- tealCode = AppManager.replaceTealTemplateDeployTimeControlParams(tealCode, deploymentMetadata);
70
- }
71
- return await this.compileTeal(tealCode);
72
- }
73
- /**
74
- * Returns a previous compilation result.
75
- * @param tealCode The TEAL code
76
- * @returns The information about the previously compiled file
77
- * or `undefined` if that TEAL code wasn't previously compiled
78
- * @example
79
- * ```typescript
80
- * const compiled = appManager.getCompilationResult(tealProgram)
81
- * ```
82
- */
83
- getCompilationResult(tealCode) {
84
- return this._compilationResults[tealCode];
85
- }
86
- /**
87
- * Returns the current app information for the app with the given ID.
88
- *
89
- * @example
90
- * ```typescript
91
- * const appInfo = await appManager.getById(12353n);
92
- * ```
93
- *
94
- * @param appId The ID of the app
95
- * @returns The app information
96
- */
97
- async getById(appId) {
98
- const app = await this._algod.getApplicationByID(Number(appId)).do();
99
- return {
100
- appId: BigInt(app.id),
101
- appAddress: algosdk.getApplicationAddress(app.id),
102
- approvalProgram: app.params.approvalProgram,
103
- clearStateProgram: app.params.clearStateProgram,
104
- creator: app.params.creator,
105
- localInts: Number(app.params.localStateSchema?.numUint ?? 0),
106
- localByteSlices: Number(app.params.localStateSchema?.numByteSlice ?? 0),
107
- globalInts: Number(app.params.globalStateSchema?.numUint ?? 0),
108
- globalByteSlices: Number(app.params.globalStateSchema?.numByteSlice ?? 0),
109
- extraProgramPages: Number(app.params.extraProgramPages ?? 0),
110
- globalState: AppManager.decodeAppState(app.params.globalState ?? []),
111
- };
112
- }
113
- /**
114
- * Returns the current global state values for the given app ID and account address
115
- *
116
- * @param appId The ID of the app to return global state for
117
- * @returns The current global state for the given app
118
- * @example
119
- * ```typescript
120
- * const globalState = await appManager.getGlobalState(12353n);
121
- * ```
122
- */
123
- async getGlobalState(appId) {
124
- return (await this.getById(appId)).globalState;
125
- }
126
- /**
127
- * Returns the current local state values for the given app ID and account address
128
- *
129
- * @param appId The ID of the app to return local state for
130
- * @param address The string address of the account to get local state for the given app
131
- * @returns The current local state for the given (app, account) combination
132
- * @example
133
- * ```typescript
134
- * const localState = await appManager.getLocalState(12353n, 'ACCOUNTADDRESS');
135
- * ```
136
- */
137
- async getLocalState(appId, address) {
138
- const appInfo = await this._algod.accountApplicationInformation(address, appId).do();
139
- if (!appInfo.appLocalState?.keyValue) {
140
- throw new Error("Couldn't find local state");
141
- }
142
- return AppManager.decodeAppState(appInfo.appLocalState.keyValue);
143
- }
144
- /**
145
- * Returns the names of the current boxes for the given app.
146
- * @param appId The ID of the app return box names for
147
- * @returns The current box names
148
- * @example
149
- * ```typescript
150
- * const boxNames = await appManager.getBoxNames(12353n);
151
- * ```
152
- */
153
- async getBoxNames(appId) {
154
- const boxResult = await this._algod.getApplicationBoxes(appId).do();
155
- return boxResult.boxes.map((b) => {
156
- return {
157
- nameRaw: b.name,
158
- nameBase64: Buffer.from(b.name).toString('base64'),
159
- name: Buffer.from(b.name).toString('utf-8'),
160
- };
161
- });
162
- }
163
- /**
164
- * Returns the value of the given box name for the given app.
165
- * @param appId The ID of the app return box names for
166
- * @param boxName The name of the box to return either as a string, binary array or `BoxName`
167
- * @returns The current box value as a byte array
168
- * @example
169
- * ```typescript
170
- * const boxValue = await appManager.getBoxValue(12353n, 'boxName');
171
- * ```
172
- */
173
- async getBoxValue(appId, boxName) {
174
- const boxId = typeof boxName === 'object' && 'nameRaw' in boxName ? boxName.nameRaw : boxName;
175
- const name = AppManager.getBoxReference(boxId).name;
176
- const boxResult = await this._algod.getApplicationBoxByName(Number(appId), name).do();
177
- return boxResult.value;
178
- }
179
- /**
180
- * Returns the value of the given box names for the given app.
181
- * @param appId The ID of the app return box names for
182
- * @param boxNames The names of the boxes to return either as a string, binary array or `BoxName`
183
- * @returns The current box values as a byte array in the same order as the passed in box names
184
- * @example
185
- * ```typescript
186
- * const boxValues = await appManager.getBoxValues(12353n, ['boxName1', 'boxName2']);
187
- * ```
188
- */
189
- async getBoxValues(appId, boxNames) {
190
- return await Promise.all(boxNames.map(async (boxName) => await this.getBoxValue(appId, boxName)));
191
- }
192
- /**
193
- * Returns the value of the given box name for the given app decoded based on the given ABI type.
194
- * @param request The parameters for the box value request
195
- * @returns The current box value as an ABI value
196
- * @example
197
- * ```typescript
198
- * const boxValue = await appManager.getBoxValueFromABIType({ appId: 12353n, boxName: 'boxName', type: new ABIUintType(32) });
199
- * ```
200
- */
201
- async getBoxValueFromABIType(request) {
202
- const { appId, boxName, type } = request;
203
- const value = await this.getBoxValue(appId, boxName);
204
- return type.decode(value);
205
- }
206
- /**
207
- * Returns the value of the given box names for the given app decoded based on the given ABI type.
208
- * @param request The parameters for the box value request
209
- * @returns The current box values as an ABI value in the same order as the passed in box names
210
- * @example
211
- * ```typescript
212
- * const boxValues = await appManager.getBoxValuesFromABIType({ appId: 12353n, boxNames: ['boxName1', 'boxName2'], type: new ABIUintType(32) });
213
- * ```
214
- */
215
- async getBoxValuesFromABIType(request) {
216
- const { appId, boxNames, type } = request;
217
- return await Promise.all(boxNames.map(async (boxName) => await this.getBoxValueFromABIType({ appId, boxName, type })));
218
- }
219
- /**
220
- * Returns a `algosdk.BoxReference` given a `BoxIdentifier` or `BoxReference`.
221
- * @param boxId The box to return a reference for
222
- * @returns The box reference ready to pass into a `algosdk.Transaction`
223
- * @example
224
- * ```typescript
225
- * const boxRef = AppManager.getBoxReference('boxName');
226
- * ```
227
- */
228
- static getBoxReference(boxId) {
229
- const ref = typeof boxId === 'object' && 'appId' in boxId ? boxId : { appId: 0n, name: boxId };
230
- return {
231
- appIndex: ref.appId,
232
- name: typeof ref.name === 'string' ? new TextEncoder().encode(ref.name) : 'length' in ref.name ? ref.name : ref.name.addr.publicKey,
233
- };
234
- }
235
- /**
236
- * Converts an array of global/local state values from the algod api to a more friendly
237
- * generic object keyed by the UTF-8 value of the key.
238
- * @param state A `global-state`, `local-state`, `global-state-deltas` or `local-state-deltas`
239
- * @returns An object keyeed by the UTF-8 representation of the key with various parsings of the values
240
- * @example
241
- * ```typescript
242
- * const stateValues = AppManager.decodeAppState(state);
243
- * ```
244
- */
245
- static decodeAppState(state) {
246
- const stateValues = {};
247
- // Start with empty set
248
- for (const stateVal of state) {
249
- const keyBase64 = Buffer.from(stateVal.key).toString('base64');
250
- const keyRaw = stateVal.key;
251
- const key = Buffer.from(stateVal.key).toString('utf-8');
252
- const tealValue = stateVal.value;
253
- const dataTypeFlag = 'action' in tealValue ? tealValue.action : tealValue.type;
254
- let valueBase64;
255
- let valueRaw;
256
- switch (dataTypeFlag) {
257
- case 1:
258
- valueBase64 =
259
- typeof tealValue.bytes === 'string' ? tealValue.bytes : tealValue.bytes ? Buffer.from(tealValue.bytes).toString('base64') : '';
260
- valueRaw = Buffer.from(valueBase64, 'base64');
261
- stateValues[key] = {
262
- keyRaw,
263
- keyBase64,
264
- valueRaw: new Uint8Array(valueRaw),
265
- valueBase64: valueBase64,
266
- value: valueRaw.toString('utf-8'),
267
- };
268
- break;
269
- case 2: {
270
- const value = tealValue.uint ?? 0;
271
- stateValues[key] = {
272
- keyRaw,
273
- keyBase64,
274
- value: BigInt(value),
275
- };
276
- break;
277
- }
278
- default:
279
- throw new Error(`Received unknown state data type of ${dataTypeFlag}`);
280
- }
281
- }
282
- return stateValues;
283
- }
284
- /**
285
- * Returns any ABI return values for the given app call arguments and transaction confirmation.
286
- * @param confirmation The transaction confirmation from algod
287
- * @param method The ABI method
288
- * @returns The return value for the method call
289
- * @example
290
- * ```typescript
291
- * const returnValue = AppManager.getABIReturn(confirmation, ABIMethod.fromSignature('hello(string)void'));
292
- * ```
293
- */
294
- static getABIReturn(confirmation, method) {
295
- if (!method || !confirmation || method.returns.type === 'void') {
296
- return undefined;
297
- }
298
- // The parseMethodResponse method mutates the second parameter :(
299
- const resultDummy = {
300
- txID: '',
301
- method,
302
- rawReturnValue: new Uint8Array(),
303
- };
304
- return transaction.getABIReturnValue(algosdk.AtomicTransactionComposer.parseMethodResponse(method, resultDummy, confirmation), method.returns.type);
305
- }
306
- /**
307
- * Replaces AlgoKit deploy-time deployment control parameters within the given TEAL template code.
308
- *
309
- * * `TMPL_UPDATABLE` for updatability / immutability control
310
- * * `TMPL_DELETABLE` for deletability / permanence control
311
- *
312
- * Note: If these values are defined, but the corresponding `TMPL_*` value
313
- * isn't in the teal code it will throw an exception.
314
- *
315
- * @param tealTemplateCode The TEAL template code to substitute
316
- * @param params The deploy-time deployment control parameter value to replace
317
- * @returns The replaced TEAL code
318
- * @example
319
- * ```typescript
320
- * const tealCode = AppManager.replaceTealTemplateDeployTimeControlParams(tealTemplate, { updatable: true, deletable: false });
321
- * ```
322
- */
323
- static replaceTealTemplateDeployTimeControlParams(tealTemplateCode, params) {
324
- if (params.updatable !== undefined) {
325
- if (!tealTemplateCode.includes(types_app.UPDATABLE_TEMPLATE_NAME)) {
326
- throw new Error(`Deploy-time updatability control requested for app deployment, but ${types_app.UPDATABLE_TEMPLATE_NAME} not present in TEAL code`);
327
- }
328
- tealTemplateCode = replaceTemplateVariable(tealTemplateCode, types_app.UPDATABLE_TEMPLATE_NAME, (params.updatable ? 1 : 0).toString());
329
- }
330
- if (params.deletable !== undefined) {
331
- if (!tealTemplateCode.includes(types_app.DELETABLE_TEMPLATE_NAME)) {
332
- throw new Error(`Deploy-time deletability control requested for app deployment, but ${types_app.DELETABLE_TEMPLATE_NAME} not present in TEAL code`);
333
- }
334
- tealTemplateCode = replaceTemplateVariable(tealTemplateCode, types_app.DELETABLE_TEMPLATE_NAME, (params.deletable ? 1 : 0).toString());
335
- }
336
- return tealTemplateCode;
337
- }
338
- /**
339
- * Performs template substitution of a teal file.
340
- *
341
- * Looks for `TMPL_{parameter}` for template replacements.
342
- *
343
- * @param tealTemplateCode The TEAL template code to make parameter replacements in
344
- * @param templateParams Any parameters to replace in the teal code
345
- * @returns The TEAL code with replacements
346
- * @example
347
- * ```typescript
348
- * const tealCode = AppManager.replaceTealTemplateParams(tealTemplate, { TMPL_APP_ID: 12345n });
349
- * ```
350
- */
351
- static replaceTealTemplateParams(tealTemplateCode, templateParams) {
352
- if (templateParams !== undefined) {
353
- for (const key in templateParams) {
354
- const value = templateParams[key];
355
- const token = `TMPL_${key.replace(/^TMPL_/, '')}`;
356
- // If this is a number, first replace any byte representations of the number
357
- // These may appear in the TEAL in order to circumvent int compression and preserve PC values
358
- if (typeof value === 'number' || typeof value === 'bigint') {
359
- tealTemplateCode = tealTemplateCode.replace(new RegExp(`(?<=bytes )${token}`, 'g'), `0x${value.toString(16).padStart(16, '0')}`);
360
- // We could probably return here since mixing pushint and pushbytes is likely not going to happen, but might as well do both
361
- }
362
- tealTemplateCode = replaceTemplateVariable(tealTemplateCode, token, typeof value === 'string'
363
- ? `0x${Buffer.from(value, 'utf-8').toString('hex')}`
364
- : ArrayBuffer.isView(value)
365
- ? `0x${Buffer.from(value).toString('hex')}`
366
- : value.toString());
367
- }
368
- }
369
- return tealTemplateCode;
370
- }
371
- /**
372
- * Remove comments from TEAL code (useful to reduce code size before compilation).
373
- *
374
- * @param tealCode The TEAL logic to strip
375
- * @returns The TEAL without comments
376
- * @example
377
- * ```typescript
378
- * const stripped = AppManager.stripTealComments(tealProgram);
379
- * ```
380
- */
381
- static stripTealComments(tealCode) {
382
- const stripCommentFromLine = (line) => {
383
- const commentIndex = findUnquotedString(line, '//');
384
- if (commentIndex === undefined) {
385
- return line;
386
- }
387
- return line.slice(0, commentIndex).trimEnd();
388
- };
389
- return tealCode
390
- .split('\n')
391
- .map((line) => stripCommentFromLine(line))
392
- .join('\n');
393
- }
394
- }
9
+ var AppManager = class AppManager {
10
+ _algod;
11
+ _compilationResults = {};
12
+ /**
13
+ * Creates an `AppManager`
14
+ * @param algod An algod instance
15
+ */
16
+ constructor(algod) {
17
+ this._algod = algod;
18
+ }
19
+ /**
20
+ * Compiles the given TEAL using algod and returns the result, including source map.
21
+ *
22
+ * The result of this compilation is also cached keyed by the TEAL
23
+ * code so it can be retrieved via `getCompilationResult`.
24
+ *
25
+ * This function is re-entrant; it will only compile the same code once.
26
+ *
27
+ * @param tealCode The TEAL code
28
+ * @returns The information about the compiled file
29
+ * @example
30
+ * ```typescript
31
+ * const compiled = await appManager.compileTeal(tealProgram)
32
+ * ```
33
+ */
34
+ async compileTeal(tealCode) {
35
+ if (this._compilationResults[tealCode]) return this._compilationResults[tealCode];
36
+ const compiled = await this._algod.compile(tealCode).sourcemap(true).do();
37
+ const result = {
38
+ teal: tealCode,
39
+ compiled: compiled.result,
40
+ compiledHash: compiled.hash,
41
+ compiledBase64ToBytes: new Uint8Array(Buffer.from(compiled.result, "base64")),
42
+ sourceMap: new algosdk.ProgramSourceMap(JSON.parse(algosdk.default.encodeJSON(compiled.sourcemap)))
43
+ };
44
+ this._compilationResults[tealCode] = result;
45
+ return result;
46
+ }
47
+ /**
48
+ * Performs template substitution of a teal template and compiles it, returning the compiled result.
49
+ *
50
+ * Looks for `TMPL_{parameter}` for template replacements and replaces AlgoKit deploy-time control parameters
51
+ * if deployment metadata is specified.
52
+ *
53
+ * * `TMPL_UPDATABLE` for updatability / immutability control
54
+ * * `TMPL_DELETABLE` for deletability / permanence control
55
+ *
56
+ * @param tealTemplateCode The TEAL logic to compile
57
+ * @param templateParams Any parameters to replace in the .teal file before compiling
58
+ * @param deploymentMetadata The deployment metadata the app will be deployed with
59
+ * @returns The information about the compiled code
60
+ * @example
61
+ * ```typescript
62
+ * const compiled = await appManager.compileTealTemplate(tealTemplate, { TMPL_APP_ID: 12345n }, { updatable: true, deletable: false })
63
+ * ```
64
+ */
65
+ async compileTealTemplate(tealTemplateCode, templateParams, deploymentMetadata) {
66
+ let tealCode = AppManager.stripTealComments(tealTemplateCode);
67
+ tealCode = AppManager.replaceTealTemplateParams(tealCode, templateParams);
68
+ if (deploymentMetadata) tealCode = AppManager.replaceTealTemplateDeployTimeControlParams(tealCode, deploymentMetadata);
69
+ return await this.compileTeal(tealCode);
70
+ }
71
+ /**
72
+ * Returns a previous compilation result.
73
+ * @param tealCode The TEAL code
74
+ * @returns The information about the previously compiled file
75
+ * or `undefined` if that TEAL code wasn't previously compiled
76
+ * @example
77
+ * ```typescript
78
+ * const compiled = appManager.getCompilationResult(tealProgram)
79
+ * ```
80
+ */
81
+ getCompilationResult(tealCode) {
82
+ return this._compilationResults[tealCode];
83
+ }
84
+ /**
85
+ * Returns the current app information for the app with the given ID.
86
+ *
87
+ * @example
88
+ * ```typescript
89
+ * const appInfo = await appManager.getById(12353n);
90
+ * ```
91
+ *
92
+ * @param appId The ID of the app
93
+ * @returns The app information
94
+ */
95
+ async getById(appId) {
96
+ const app = await this._algod.getApplicationByID(Number(appId)).do();
97
+ const params = app.params;
98
+ return {
99
+ appId: BigInt(app.id),
100
+ appAddress: algosdk.default.getApplicationAddress(app.id),
101
+ approvalProgram: params.approvalProgram,
102
+ clearStateProgram: params.clearStateProgram,
103
+ creator: params.creator,
104
+ localInts: Number(params.localStateSchema?.numUint ?? 0),
105
+ localByteSlices: Number(params.localStateSchema?.numByteSlice ?? 0),
106
+ globalInts: Number(params.globalStateSchema?.numUint ?? 0),
107
+ globalByteSlices: Number(params.globalStateSchema?.numByteSlice ?? 0),
108
+ extraProgramPages: Number(params.extraProgramPages ?? 0),
109
+ globalState: AppManager.decodeAppState(params.globalState ?? []),
110
+ version: params.version
111
+ };
112
+ }
113
+ /**
114
+ * Returns the current global state values for the given app ID and account address
115
+ *
116
+ * @param appId The ID of the app to return global state for
117
+ * @returns The current global state for the given app
118
+ * @example
119
+ * ```typescript
120
+ * const globalState = await appManager.getGlobalState(12353n);
121
+ * ```
122
+ */
123
+ async getGlobalState(appId) {
124
+ return (await this.getById(appId)).globalState;
125
+ }
126
+ /**
127
+ * Returns the current local state values for the given app ID and account address
128
+ *
129
+ * @param appId The ID of the app to return local state for
130
+ * @param address The string address of the account to get local state for the given app
131
+ * @returns The current local state for the given (app, account) combination
132
+ * @example
133
+ * ```typescript
134
+ * const localState = await appManager.getLocalState(12353n, 'ACCOUNTADDRESS');
135
+ * ```
136
+ */
137
+ async getLocalState(appId, address) {
138
+ const appInfo = await this._algod.accountApplicationInformation(address, appId).do();
139
+ if (!appInfo.appLocalState?.keyValue) throw new Error("Couldn't find local state");
140
+ return AppManager.decodeAppState(appInfo.appLocalState.keyValue);
141
+ }
142
+ /**
143
+ * Returns the names of the current boxes for the given app.
144
+ * @param appId The ID of the app return box names for
145
+ * @returns The current box names
146
+ * @example
147
+ * ```typescript
148
+ * const boxNames = await appManager.getBoxNames(12353n);
149
+ * ```
150
+ */
151
+ async getBoxNames(appId) {
152
+ return (await this._algod.getApplicationBoxes(appId).do()).boxes.map((b) => {
153
+ return {
154
+ nameRaw: b.name,
155
+ nameBase64: Buffer.from(b.name).toString("base64"),
156
+ name: Buffer.from(b.name).toString("utf-8")
157
+ };
158
+ });
159
+ }
160
+ /**
161
+ * Returns the value of the given box name for the given app.
162
+ * @param appId The ID of the app return box names for
163
+ * @param boxName The name of the box to return either as a string, binary array or `BoxName`
164
+ * @returns The current box value as a byte array
165
+ * @example
166
+ * ```typescript
167
+ * const boxValue = await appManager.getBoxValue(12353n, 'boxName');
168
+ * ```
169
+ */
170
+ async getBoxValue(appId, boxName) {
171
+ const boxId = typeof boxName === "object" && "nameRaw" in boxName ? boxName.nameRaw : boxName;
172
+ const name = AppManager.getBoxReference(boxId).name;
173
+ return (await this._algod.getApplicationBoxByName(Number(appId), name).do()).value;
174
+ }
175
+ /**
176
+ * Returns the value of the given box names for the given app.
177
+ * @param appId The ID of the app return box names for
178
+ * @param boxNames The names of the boxes to return either as a string, binary array or `BoxName`
179
+ * @returns The current box values as a byte array in the same order as the passed in box names
180
+ * @example
181
+ * ```typescript
182
+ * const boxValues = await appManager.getBoxValues(12353n, ['boxName1', 'boxName2']);
183
+ * ```
184
+ */
185
+ async getBoxValues(appId, boxNames) {
186
+ return await Promise.all(boxNames.map(async (boxName) => await this.getBoxValue(appId, boxName)));
187
+ }
188
+ /**
189
+ * Returns the value of the given box name for the given app decoded based on the given ABI type.
190
+ * @param request The parameters for the box value request
191
+ * @returns The current box value as an ABI value
192
+ * @example
193
+ * ```typescript
194
+ * const boxValue = await appManager.getBoxValueFromABIType({ appId: 12353n, boxName: 'boxName', type: new ABIUintType(32) });
195
+ * ```
196
+ */
197
+ async getBoxValueFromABIType(request) {
198
+ const { appId, boxName, type } = request;
199
+ const value = await this.getBoxValue(appId, boxName);
200
+ return type.decode(value);
201
+ }
202
+ /**
203
+ * Returns the value of the given box names for the given app decoded based on the given ABI type.
204
+ * @param request The parameters for the box value request
205
+ * @returns The current box values as an ABI value in the same order as the passed in box names
206
+ * @example
207
+ * ```typescript
208
+ * const boxValues = await appManager.getBoxValuesFromABIType({ appId: 12353n, boxNames: ['boxName1', 'boxName2'], type: new ABIUintType(32) });
209
+ * ```
210
+ */
211
+ async getBoxValuesFromABIType(request) {
212
+ const { appId, boxNames, type } = request;
213
+ return await Promise.all(boxNames.map(async (boxName) => await this.getBoxValueFromABIType({
214
+ appId,
215
+ boxName,
216
+ type
217
+ })));
218
+ }
219
+ /**
220
+ * Returns a `algosdk.BoxReference` given a `BoxIdentifier` or `BoxReference`.
221
+ * @param boxId The box to return a reference for
222
+ * @returns The box reference ready to pass into a `algosdk.Transaction`
223
+ * @example
224
+ * ```typescript
225
+ * const boxRef = AppManager.getBoxReference('boxName');
226
+ * ```
227
+ */
228
+ static getBoxReference(boxId) {
229
+ const ref = typeof boxId === "object" && "appId" in boxId ? boxId : {
230
+ appId: 0n,
231
+ name: boxId
232
+ };
233
+ return {
234
+ appIndex: ref.appId,
235
+ name: typeof ref.name === "string" ? new TextEncoder().encode(ref.name) : "length" in ref.name ? ref.name : ref.name.addr.publicKey
236
+ };
237
+ }
238
+ /**
239
+ * Converts an array of global/local state values from the algod api to a more friendly
240
+ * generic object keyed by the UTF-8 value of the key.
241
+ * @param state A `global-state`, `local-state`, `global-state-deltas` or `local-state-deltas`
242
+ * @returns An object keyeed by the UTF-8 representation of the key with various parsings of the values
243
+ * @example
244
+ * ```typescript
245
+ * const stateValues = AppManager.decodeAppState(state);
246
+ * ```
247
+ */
248
+ static decodeAppState(state) {
249
+ const stateValues = {};
250
+ for (const stateVal of state) {
251
+ const keyBase64 = Buffer.from(stateVal.key).toString("base64");
252
+ const keyRaw = stateVal.key;
253
+ const key = Buffer.from(stateVal.key).toString("utf-8");
254
+ const tealValue = stateVal.value;
255
+ const dataTypeFlag = "action" in tealValue ? tealValue.action : tealValue.type;
256
+ let valueBase64;
257
+ let valueRaw;
258
+ switch (dataTypeFlag) {
259
+ case 1:
260
+ valueBase64 = typeof tealValue.bytes === "string" ? tealValue.bytes : tealValue.bytes ? Buffer.from(tealValue.bytes).toString("base64") : "";
261
+ valueRaw = Buffer.from(valueBase64, "base64");
262
+ stateValues[key] = {
263
+ keyRaw,
264
+ keyBase64,
265
+ valueRaw: new Uint8Array(valueRaw),
266
+ valueBase64,
267
+ value: valueRaw.toString("utf-8")
268
+ };
269
+ break;
270
+ case 2:
271
+ stateValues[key] = {
272
+ keyRaw,
273
+ keyBase64,
274
+ value: BigInt(tealValue.uint ?? 0)
275
+ };
276
+ break;
277
+ default: throw new Error(`Received unknown state data type of ${dataTypeFlag}`);
278
+ }
279
+ }
280
+ return stateValues;
281
+ }
282
+ /**
283
+ * Returns any ABI return values for the given app call arguments and transaction confirmation.
284
+ * @param confirmation The transaction confirmation from algod
285
+ * @param method The ABI method
286
+ * @returns The return value for the method call
287
+ * @example
288
+ * ```typescript
289
+ * const returnValue = AppManager.getABIReturn(confirmation, ABIMethod.fromSignature('hello(string)void'));
290
+ * ```
291
+ */
292
+ static getABIReturn(confirmation, method) {
293
+ if (!method || !confirmation || method.returns.type === "void") return;
294
+ return require_transaction.getABIReturnValue(algosdk.default.AtomicTransactionComposer.parseMethodResponse(method, {
295
+ txID: "",
296
+ method,
297
+ rawReturnValue: /* @__PURE__ */ new Uint8Array()
298
+ }, confirmation), method.returns.type);
299
+ }
300
+ /**
301
+ * Replaces AlgoKit deploy-time deployment control parameters within the given TEAL template code.
302
+ *
303
+ * * `TMPL_UPDATABLE` for updatability / immutability control
304
+ * * `TMPL_DELETABLE` for deletability / permanence control
305
+ *
306
+ * Note: If these values are defined, but the corresponding `TMPL_*` value
307
+ * isn't in the teal code it will throw an exception.
308
+ *
309
+ * @param tealTemplateCode The TEAL template code to substitute
310
+ * @param params The deploy-time deployment control parameter value to replace
311
+ * @returns The replaced TEAL code
312
+ * @example
313
+ * ```typescript
314
+ * const tealCode = AppManager.replaceTealTemplateDeployTimeControlParams(tealTemplate, { updatable: true, deletable: false });
315
+ * ```
316
+ */
317
+ static replaceTealTemplateDeployTimeControlParams(tealTemplateCode, params) {
318
+ if (params.updatable !== void 0) {
319
+ if (!tealTemplateCode.includes("TMPL_UPDATABLE")) throw new Error(`Deploy-time updatability control requested for app deployment, but ${require_app.UPDATABLE_TEMPLATE_NAME} not present in TEAL code`);
320
+ tealTemplateCode = replaceTemplateVariable(tealTemplateCode, require_app.UPDATABLE_TEMPLATE_NAME, (params.updatable ? 1 : 0).toString());
321
+ }
322
+ if (params.deletable !== void 0) {
323
+ if (!tealTemplateCode.includes("TMPL_DELETABLE")) throw new Error(`Deploy-time deletability control requested for app deployment, but ${require_app.DELETABLE_TEMPLATE_NAME} not present in TEAL code`);
324
+ tealTemplateCode = replaceTemplateVariable(tealTemplateCode, require_app.DELETABLE_TEMPLATE_NAME, (params.deletable ? 1 : 0).toString());
325
+ }
326
+ return tealTemplateCode;
327
+ }
328
+ /**
329
+ * Performs template substitution of a teal file.
330
+ *
331
+ * Looks for `TMPL_{parameter}` for template replacements.
332
+ *
333
+ * @param tealTemplateCode The TEAL template code to make parameter replacements in
334
+ * @param templateParams Any parameters to replace in the teal code
335
+ * @returns The TEAL code with replacements
336
+ * @example
337
+ * ```typescript
338
+ * const tealCode = AppManager.replaceTealTemplateParams(tealTemplate, { TMPL_APP_ID: 12345n });
339
+ * ```
340
+ */
341
+ static replaceTealTemplateParams(tealTemplateCode, templateParams) {
342
+ if (templateParams !== void 0) for (const key in templateParams) {
343
+ const value = templateParams[key];
344
+ const token = `TMPL_${key.replace(/^TMPL_/, "")}`;
345
+ if (typeof value === "number" || typeof value === "bigint") tealTemplateCode = tealTemplateCode.replace(new RegExp(`(?<=bytes )${token}`, "g"), `0x${value.toString(16).padStart(16, "0")}`);
346
+ tealTemplateCode = replaceTemplateVariable(tealTemplateCode, token, typeof value === "string" ? `0x${Buffer.from(value, "utf-8").toString("hex")}` : ArrayBuffer.isView(value) ? `0x${Buffer.from(value).toString("hex")}` : value.toString());
347
+ }
348
+ return tealTemplateCode;
349
+ }
350
+ /**
351
+ * Remove comments from TEAL code (useful to reduce code size before compilation).
352
+ *
353
+ * @param tealCode The TEAL logic to strip
354
+ * @returns The TEAL without comments
355
+ * @example
356
+ * ```typescript
357
+ * const stripped = AppManager.stripTealComments(tealProgram);
358
+ * ```
359
+ */
360
+ static stripTealComments(tealCode) {
361
+ const stripCommentFromLine = (line) => {
362
+ const commentIndex = findUnquotedString(line, "//");
363
+ if (commentIndex === void 0) return line;
364
+ return line.slice(0, commentIndex).trimEnd();
365
+ };
366
+ return tealCode.split("\n").map((line) => stripCommentFromLine(line)).join("\n");
367
+ }
368
+ };
395
369
  /**
396
- * Find the first string within a line of TEAL. Only matches outside of quotes and base64 are returned.
397
- * Returns undefined if not found
398
- */
370
+ * Find the first string within a line of TEAL. Only matches outside of quotes and base64 are returned.
371
+ * Returns undefined if not found
372
+ */
399
373
  const findUnquotedString = (line, token, startIndex = 0, _endIndex) => {
400
- const endIndex = _endIndex === undefined ? line.length : _endIndex;
401
- let index = startIndex;
402
- let inQuotes = false;
403
- let inBase64 = false;
404
- while (index < endIndex) {
405
- const currentChar = line[index];
406
- if ((currentChar === ' ' || currentChar === '(') && !inQuotes && lastTokenBase64(line, index)) {
407
- // enter base64
408
- inBase64 = true;
409
- }
410
- else if ((currentChar === ' ' || currentChar === ')') && !inQuotes && inBase64) {
411
- // exit base64
412
- inBase64 = false;
413
- }
414
- else if (currentChar === '\\' && inQuotes) {
415
- // escaped char, skip next character
416
- index += 1;
417
- }
418
- else if (currentChar === '"') {
419
- // quote boundary
420
- inQuotes = !inQuotes;
421
- }
422
- else if (!inQuotes && !inBase64 && line.startsWith(token, index)) {
423
- // can test for match
424
- return index;
425
- }
426
- index += 1;
427
- }
428
- return undefined;
374
+ const endIndex = _endIndex === void 0 ? line.length : _endIndex;
375
+ let index = startIndex;
376
+ let inQuotes = false;
377
+ let inBase64 = false;
378
+ while (index < endIndex) {
379
+ const currentChar = line[index];
380
+ if ((currentChar === " " || currentChar === "(") && !inQuotes && lastTokenBase64(line, index)) inBase64 = true;
381
+ else if ((currentChar === " " || currentChar === ")") && !inQuotes && inBase64) inBase64 = false;
382
+ else if (currentChar === "\\" && inQuotes) index += 1;
383
+ else if (currentChar === "\"") inQuotes = !inQuotes;
384
+ else if (!inQuotes && !inBase64 && line.startsWith(token, index)) return index;
385
+ index += 1;
386
+ }
429
387
  };
430
388
  const lastTokenBase64 = (line, index) => {
431
- try {
432
- const tokens = line.slice(0, index).split(/\s+/);
433
- const last = tokens[tokens.length - 1];
434
- return ['base64', 'b64'].includes(last);
435
- }
436
- catch {
437
- return false;
438
- }
389
+ try {
390
+ const tokens = line.slice(0, index).split(/\s+/);
391
+ const last = tokens[tokens.length - 1];
392
+ return ["base64", "b64"].includes(last);
393
+ } catch {
394
+ return false;
395
+ }
439
396
  };
440
397
  function replaceTemplateVariable(program, token, replacement) {
441
- const result = [];
442
- const tokenIndexOffset = replacement.length - token.length;
443
- const programLines = program.split('\n');
444
- for (const line of programLines) {
445
- const _commentIndex = findUnquotedString(line, '//');
446
- const commentIndex = _commentIndex === undefined ? line.length : _commentIndex;
447
- let code = line.substring(0, commentIndex);
448
- const comment = line.substring(commentIndex);
449
- let trailingIndex = 0;
450
- while (true) {
451
- const tokenIndex = findTemplateToken(code, token, trailingIndex);
452
- if (tokenIndex === undefined) {
453
- break;
454
- }
455
- trailingIndex = tokenIndex + token.length;
456
- const prefix = code.substring(0, tokenIndex);
457
- const suffix = code.substring(trailingIndex);
458
- code = `${prefix}${replacement}${suffix}`;
459
- trailingIndex += tokenIndexOffset;
460
- }
461
- result.push(code + comment);
462
- }
463
- return result.join('\n');
398
+ const result = [];
399
+ const tokenIndexOffset = replacement.length - token.length;
400
+ const programLines = program.split("\n");
401
+ for (const line of programLines) {
402
+ const _commentIndex = findUnquotedString(line, "//");
403
+ const commentIndex = _commentIndex === void 0 ? line.length : _commentIndex;
404
+ let code = line.substring(0, commentIndex);
405
+ const comment = line.substring(commentIndex);
406
+ let trailingIndex = 0;
407
+ while (true) {
408
+ const tokenIndex = findTemplateToken(code, token, trailingIndex);
409
+ if (tokenIndex === void 0) break;
410
+ trailingIndex = tokenIndex + token.length;
411
+ code = `${code.substring(0, tokenIndex)}${replacement}${code.substring(trailingIndex)}`;
412
+ trailingIndex += tokenIndexOffset;
413
+ }
414
+ result.push(code + comment);
415
+ }
416
+ return result.join("\n");
464
417
  }
465
418
  const findTemplateToken = (line, token, startIndex = 0, _endIndex) => {
466
- const endIndex = line.length ;
467
- let index = startIndex;
468
- while (index < endIndex) {
469
- const tokenIndex = findUnquotedString(line, token, index, endIndex);
470
- if (tokenIndex === undefined) {
471
- break;
472
- }
473
- const trailingIndex = tokenIndex + token.length;
474
- if ((tokenIndex === 0 || !isValidTokenCharacter(line[tokenIndex - 1])) &&
475
- (trailingIndex >= line.length || !isValidTokenCharacter(line[trailingIndex]))) {
476
- return tokenIndex;
477
- }
478
- index = trailingIndex;
479
- }
480
- return undefined;
419
+ const endIndex = _endIndex === void 0 ? line.length : _endIndex;
420
+ let index = startIndex;
421
+ while (index < endIndex) {
422
+ const tokenIndex = findUnquotedString(line, token, index, endIndex);
423
+ if (tokenIndex === void 0) break;
424
+ const trailingIndex = tokenIndex + token.length;
425
+ if ((tokenIndex === 0 || !isValidTokenCharacter(line[tokenIndex - 1])) && (trailingIndex >= line.length || !isValidTokenCharacter(line[trailingIndex]))) return tokenIndex;
426
+ index = trailingIndex;
427
+ }
481
428
  };
482
429
  function isValidTokenCharacter(char) {
483
- return char.length === 1 && (/\w/.test(char) || char === '_');
430
+ return char.length === 1 && (/\w/.test(char) || char === "_");
484
431
  }
485
-
432
+ //#endregion
486
433
  exports.AppManager = AppManager;
487
- //# sourceMappingURL=app-manager.js.map
434
+
435
+ //# sourceMappingURL=app-manager.js.map