@algorandfoundation/algokit-utils 9.2.0 → 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 -771
  175. package/types/algorand-client-transaction-creator.js +733 -732
  176. package/types/algorand-client-transaction-creator.js.map +1 -1
  177. package/types/algorand-client-transaction-creator.mjs +732 -730
  178. package/types/algorand-client-transaction-creator.mjs.map +1 -1
  179. package/types/algorand-client-transaction-sender.d.ts +1090 -1360
  180. package/types/algorand-client-transaction-sender.js +930 -961
  181. package/types/algorand-client-transaction-sender.js.map +1 -1
  182. package/types/algorand-client-transaction-sender.mjs +927 -959
  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 -2009
  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 -932
  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 +304 -310
  215. package/types/app-manager.js +422 -475
  216. package/types/app-manager.js.map +1 -1
  217. package/types/app-manager.mjs +419 -473
  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 -1258
  248. package/types/composer.js +1436 -1498
  249. package/types/composer.js.map +1 -1
  250. package/types/composer.mjs +1430 -1493
  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
package/types/composer.js CHANGED
@@ -1,1511 +1,1449 @@
1
- 'use strict';
2
-
3
- var algosdk = require('algosdk');
4
- var config = require('../config.js');
5
- var transaction = require('../transaction/transaction.js');
6
- var util = require('../util.js');
7
- var types_appManager = require('./app-manager.js');
8
- var types_lifecycleEvents = require('./lifecycle-events.js');
9
- var types_networkClient = require('./network-client.js');
10
-
11
- var AtomicTransactionComposer = algosdk.AtomicTransactionComposer;
12
- var isTransactionWithSigner = algosdk.isTransactionWithSigner;
13
- var modelsv2 = algosdk.modelsv2;
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
+ const require_runtime = require("../_virtual/_rolldown/runtime.js");
3
+ const require_config = require("../config.js");
4
+ require("./lifecycle-events.js");
5
+ const require_util = require("../util.js");
6
+ const require_transaction = require("../transaction/transaction.js");
7
+ const require_app_manager = require("./app-manager.js");
8
+ const require_network_client = require("./network-client.js");
9
+ let algosdk = require("algosdk");
10
+ algosdk = require_runtime.__toESM(algosdk);
11
+ //#region src/types/composer.ts
12
+ var AtomicTransactionComposer = algosdk.default.AtomicTransactionComposer;
13
+ var isTransactionWithSigner = algosdk.default.isTransactionWithSigner;
14
+ var modelsv2 = algosdk.default.modelsv2;
14
15
  const address = (address) => {
15
- return typeof address === 'string' ? algosdk.Address.fromString(address) : address;
16
+ return typeof address === "string" ? algosdk.Address.fromString(address) : address;
16
17
  };
17
18
  const MAX_TRANSACTION_GROUP_SIZE = 16;
18
- class InvalidErrorTransformerValue extends Error {
19
- constructor(originalError, value) {
20
- super(`An error transformer returned a non-error value: ${value}. The original error before any transformation: ${originalError}`);
21
- }
22
- }
23
- class ErrorTransformerError extends Error {
24
- constructor(originalError, cause) {
25
- super(`An error transformer threw an error: ${cause}. The original error before any transformation: ${originalError} `, { cause });
26
- }
27
- }
19
+ var InvalidErrorTransformerValue = class extends Error {
20
+ constructor(originalError, value) {
21
+ super(`An error transformer returned a non-error value: ${value}. The original error before any transformation: ${originalError}`);
22
+ }
23
+ };
24
+ var ErrorTransformerError = class extends Error {
25
+ constructor(originalError, cause) {
26
+ super(`An error transformer threw an error: ${cause}. The original error before any transformation: ${originalError} `, { cause });
27
+ }
28
+ };
28
29
  /** TransactionComposer helps you compose and execute transactions as a transaction group. */
29
- class TransactionComposer {
30
- async transformError(originalError) {
31
- // Transformers only work with Error instances, so immediately return anything else
32
- if (!(originalError instanceof Error)) {
33
- return originalError;
34
- }
35
- let transformedError = originalError;
36
- for (const transformer of this.errorTransformers) {
37
- try {
38
- transformedError = await transformer(transformedError);
39
- if (!(transformedError instanceof Error)) {
40
- return new InvalidErrorTransformerValue(originalError, transformedError);
41
- }
42
- }
43
- catch (errorFromTransformer) {
44
- return new ErrorTransformerError(originalError, errorFromTransformer);
45
- }
46
- }
47
- return transformedError;
48
- }
49
- /**
50
- * Create a `TransactionComposer`.
51
- * @param params The configuration for this composer
52
- * @returns The `TransactionComposer` instance
53
- */
54
- constructor(params) {
55
- /** The ATC used to compose the group */
56
- this.atc = new algosdk.AtomicTransactionComposer();
57
- /** Map of transaction index in the atc to a max logical fee.
58
- * This is set using the value of either maxFee or staticFee.
59
- */
60
- this.txnMaxFees = new Map();
61
- /** Transactions that have not yet been composed */
62
- this.txns = [];
63
- /** The default transaction validity window */
64
- this.defaultValidityWindow = 10n;
65
- /** Whether the validity window was explicitly set on construction */
66
- this.defaultValidityWindowIsExplicit = false;
67
- this.algod = params.algod;
68
- const defaultGetSuggestedParams = () => params.algod.getTransactionParams().do();
69
- this.getSuggestedParams = params.getSuggestedParams ?? defaultGetSuggestedParams;
70
- this.getSigner = params.getSigner;
71
- this.defaultValidityWindow = params.defaultValidityWindow ?? this.defaultValidityWindow;
72
- this.defaultValidityWindowIsExplicit = params.defaultValidityWindow !== undefined;
73
- this.appManager = params.appManager ?? new types_appManager.AppManager(params.algod);
74
- this.errorTransformers = params.errorTransformers ?? [];
75
- }
76
- /**
77
- * Register a function that will be used to transform an error caught when simulating or executing
78
- *
79
- * @returns The composer so you can chain method calls
80
- */
81
- registerErrorTransformer(transformer) {
82
- this.errorTransformers.push(transformer);
83
- return this;
84
- }
85
- /**
86
- * Add a pre-built transaction to the transaction group.
87
- * @param transaction The pre-built transaction
88
- * @param signer Optional signer override for the transaction
89
- * @returns The composer so you can chain method calls
90
- * @example
91
- * ```typescript
92
- * composer.addTransaction(txn)
93
- * ```
94
- */
95
- addTransaction(transaction, signer) {
96
- this.txns.push({
97
- txn: transaction,
98
- signer: signer ?? this.getSigner(transaction.sender),
99
- type: 'txnWithSigner',
100
- });
101
- return this;
102
- }
103
- /**
104
- * Add a payment transaction to the transaction group.
105
- * @param params The payment transaction parameters
106
- * @returns The composer so you can chain method calls
107
- * @example Basic example
108
- * ```typescript
109
- * composer.addPayment({
110
- * sender: 'SENDERADDRESS',
111
- * receiver: 'RECEIVERADDRESS',
112
- * amount: (4).algo(),
113
- * })
114
- * ```
115
- * @example Advanced example
116
- * ```typescript
117
- * composer.addPayment({
118
- * amount: (4).algo(),
119
- * receiver: 'RECEIVERADDRESS',
120
- * sender: 'SENDERADDRESS',
121
- * closeRemainderTo: 'CLOSEREMAINDERTOADDRESS',
122
- * lease: 'lease',
123
- * note: 'note',
124
- * // Use this with caution, it's generally better to use algorand.account.rekeyAccount
125
- * rekeyTo: 'REKEYTOADDRESS',
126
- * // You wouldn't normally set this field
127
- * firstValidRound: 1000n,
128
- * validityWindow: 10,
129
- * extraFee: (1000).microAlgo(),
130
- * staticFee: (1000).microAlgo(),
131
- * // Max fee doesn't make sense with extraFee AND staticFee
132
- * // already specified, but here for completeness
133
- * maxFee: (3000).microAlgo(),
134
- * })
135
- */
136
- addPayment(params) {
137
- this.txns.push({ ...params, type: 'pay' });
138
- return this;
139
- }
140
- /**
141
- * Add an asset create transaction to the transaction group.
142
- * @param params The asset create transaction parameters
143
- * @returns The composer so you can chain method calls
144
- * @example Basic example
145
- * ```typescript
146
- * composer.addAssetCreate({ sender: "CREATORADDRESS", total: 100n})
147
- * ```
148
- * @example Advanced example
149
- * ```typescript
150
- * composer.addAssetCreate({
151
- * sender: 'CREATORADDRESS',
152
- * total: 100n,
153
- * decimals: 2,
154
- * assetName: 'asset',
155
- * unitName: 'unit',
156
- * url: 'url',
157
- * metadataHash: 'metadataHash',
158
- * defaultFrozen: false,
159
- * manager: 'MANAGERADDRESS',
160
- * reserve: 'RESERVEADDRESS',
161
- * freeze: 'FREEZEADDRESS',
162
- * clawback: 'CLAWBACKADDRESS',
163
- * lease: 'lease',
164
- * note: 'note',
165
- * // You wouldn't normally set this field
166
- * firstValidRound: 1000n,
167
- * validityWindow: 10,
168
- * extraFee: (1000).microAlgo(),
169
- * staticFee: (1000).microAlgo(),
170
- * // Max fee doesn't make sense with extraFee AND staticFee
171
- * // already specified, but here for completeness
172
- * maxFee: (3000).microAlgo(),
173
- * })
174
- */
175
- addAssetCreate(params) {
176
- this.txns.push({ ...params, type: 'assetCreate' });
177
- return this;
178
- }
179
- /**
180
- * Add an asset config transaction to the transaction group.
181
- * @param params The asset config transaction parameters
182
- * @returns The composer so you can chain method calls
183
- * @example Basic example
184
- * ```typescript
185
- * composer.addAssetConfig({ sender: "MANAGERADDRESS", assetId: 123456n, manager: "MANAGERADDRESS" })
186
- * ```
187
- * @example Advanced example
188
- * ```typescript
189
- * composer.addAssetConfig({
190
- * sender: 'MANAGERADDRESS',
191
- * assetId: 123456n,
192
- * manager: 'MANAGERADDRESS',
193
- * reserve: 'RESERVEADDRESS',
194
- * freeze: 'FREEZEADDRESS',
195
- * clawback: 'CLAWBACKADDRESS',
196
- * lease: 'lease',
197
- * note: 'note',
198
- * // You wouldn't normally set this field
199
- * firstValidRound: 1000n,
200
- * validityWindow: 10,
201
- * extraFee: (1000).microAlgo(),
202
- * staticFee: (1000).microAlgo(),
203
- * // Max fee doesn't make sense with extraFee AND staticFee
204
- * // already specified, but here for completeness
205
- * maxFee: (3000).microAlgo(),
206
- * })
207
- */
208
- addAssetConfig(params) {
209
- this.txns.push({ ...params, type: 'assetConfig' });
210
- return this;
211
- }
212
- /**
213
- * Add an asset freeze transaction to the transaction group.
214
- * @param params The asset freeze transaction parameters
215
- * @returns The composer so you can chain method calls
216
- * @example Basic example
217
- * ```typescript
218
- * composer.addAssetFreeze({ sender: "MANAGERADDRESS", assetId: 123456n, account: "ACCOUNTADDRESS", frozen: true })
219
- * ```
220
- * @example Advanced example
221
- * ```typescript
222
- * composer.addAssetFreeze({
223
- * sender: 'MANAGERADDRESS',
224
- * assetId: 123456n,
225
- * account: 'ACCOUNTADDRESS',
226
- * frozen: true,
227
- * lease: 'lease',
228
- * note: 'note',
229
- * // You wouldn't normally set this field
230
- * firstValidRound: 1000n,
231
- * validityWindow: 10,
232
- * extraFee: (1000).microAlgo(),
233
- * staticFee: (1000).microAlgo(),
234
- * // Max fee doesn't make sense with extraFee AND staticFee
235
- * // already specified, but here for completeness
236
- * maxFee: (3000).microAlgo(),
237
- * })
238
- * ```
239
- */
240
- addAssetFreeze(params) {
241
- this.txns.push({ ...params, type: 'assetFreeze' });
242
- return this;
243
- }
244
- /**
245
- * Add an asset destroy transaction to the transaction group.
246
- * @param params The asset destroy transaction parameters
247
- * @returns The composer so you can chain method calls
248
- * @example Basic example
249
- * ```typescript
250
- * composer.addAssetDestroy({ sender: "MANAGERADDRESS", assetId: 123456n })
251
- * ```
252
- * @example Advanced example
253
- * ```typescript
254
- * composer.addAssetDestroy({
255
- * sender: 'MANAGERADDRESS',
256
- * assetId: 123456n,
257
- * lease: 'lease',
258
- * note: 'note',
259
- * // You wouldn't normally set this field
260
- * firstValidRound: 1000n,
261
- * validityWindow: 10,
262
- * extraFee: (1000).microAlgo(),
263
- * staticFee: (1000).microAlgo(),
264
- * // Max fee doesn't make sense with extraFee AND staticFee
265
- * // already specified, but here for completeness
266
- * maxFee: (3000).microAlgo(),
267
- * })
268
- * ```
269
- */
270
- addAssetDestroy(params) {
271
- this.txns.push({ ...params, type: 'assetDestroy' });
272
- return this;
273
- }
274
- /**
275
- * Add an asset transfer transaction to the transaction group.
276
- * @param params The asset transfer transaction parameters
277
- * @returns The composer so you can chain method calls
278
- * @example Basic example
279
- * ```typescript
280
- * composer.addAssetTransfer({ sender: "HOLDERADDRESS", assetId: 123456n, amount: 1n, receiver: "RECEIVERADDRESS" })
281
- * ```
282
- * @example Advanced example (with clawback)
283
- * ```typescript
284
- * composer.addAssetTransfer({
285
- * sender: 'CLAWBACKADDRESS',
286
- * assetId: 123456n,
287
- * amount: 1n,
288
- * receiver: 'RECEIVERADDRESS',
289
- * clawbackTarget: 'HOLDERADDRESS',
290
- * // This field needs to be used with caution
291
- * closeAssetTo: 'ADDRESSTOCLOSETO'
292
- * lease: 'lease',
293
- * note: 'note',
294
- * // You wouldn't normally set this field
295
- * firstValidRound: 1000n,
296
- * validityWindow: 10,
297
- * extraFee: (1000).microAlgo(),
298
- * staticFee: (1000).microAlgo(),
299
- * // Max fee doesn't make sense with extraFee AND staticFee
300
- * // already specified, but here for completeness
301
- * maxFee: (3000).microAlgo(),
302
- * })
303
- * ```
304
- */
305
- addAssetTransfer(params) {
306
- this.txns.push({ ...params, type: 'assetTransfer' });
307
- return this;
308
- }
309
- /**
310
- * Add an asset opt-in transaction to the transaction group.
311
- * @param params The asset opt-in transaction parameters
312
- * @returns The composer so you can chain method calls
313
- * @example Basic example
314
- * ```typescript
315
- * composer.addAssetOptIn({ sender: "SENDERADDRESS", assetId: 123456n })
316
- * ```
317
- * @example Advanced example
318
- * ```typescript
319
- * composer.addAssetOptIn({
320
- * sender: 'SENDERADDRESS',
321
- * assetId: 123456n,
322
- * lease: 'lease',
323
- * note: 'note',
324
- * // You wouldn't normally set this field
325
- * firstValidRound: 1000n,
326
- * validityWindow: 10,
327
- * extraFee: (1000).microAlgo(),
328
- * staticFee: (1000).microAlgo(),
329
- * // Max fee doesn't make sense with extraFee AND staticFee
330
- * // already specified, but here for completeness
331
- * maxFee: (3000).microAlgo(),
332
- * })
333
- * ```
334
- */
335
- addAssetOptIn(params) {
336
- this.txns.push({ ...params, type: 'assetOptIn' });
337
- return this;
338
- }
339
- /**
340
- * Add an asset opt-out transaction to the transaction group.
341
- * @param params The asset opt-out transaction parameters
342
- * @returns The composer so you can chain method calls
343
- * @example Basic example (without creator, will be retrieved from algod)
344
- * ```typescript
345
- * composer.addAssetOptOut({ sender: "SENDERADDRESS", assetId: 123456n, ensureZeroBalance: true })
346
- * ```
347
- * @example Basic example (with creator)
348
- * ```typescript
349
- * composer.addAssetOptOut({ sender: "SENDERADDRESS", creator: "CREATORADDRESS", assetId: 123456n, ensureZeroBalance: true })
350
- * ```
351
- * @example Advanced example
352
- * ```typescript
353
- * composer.addAssetOptOut({
354
- * sender: 'SENDERADDRESS',
355
- * assetId: 123456n,
356
- * creator: 'CREATORADDRESS',
357
- * ensureZeroBalance: true,
358
- * lease: 'lease',
359
- * note: 'note',
360
- * // You wouldn't normally set this field
361
- * firstValidRound: 1000n,
362
- * validityWindow: 10,
363
- * extraFee: (1000).microAlgo(),
364
- * staticFee: (1000).microAlgo(),
365
- * // Max fee doesn't make sense with extraFee AND staticFee
366
- * // already specified, but here for completeness
367
- * maxFee: (3000).microAlgo(),
368
- * })
369
- * ```
370
- */
371
- addAssetOptOut(params) {
372
- this.txns.push({ ...params, type: 'assetOptOut' });
373
- return this;
374
- }
375
- /**
376
- * Add an application create transaction to the transaction group.
377
- *
378
- * Note: we recommend using app clients to make it easier to make app calls.
379
- * @param params The application create transaction parameters
380
- * @returns The composer so you can chain method calls
381
- * @example Basic example
382
- * ```typescript
383
- * composer.addAppCreate({ sender: 'CREATORADDRESS', approvalProgram: 'TEALCODE', clearStateProgram: 'TEALCODE' })
384
- * ```
385
- * @example Advanced example
386
- * ```typescript
387
- * composer.addAppCreate({
388
- * sender: 'CREATORADDRESS',
389
- * approvalProgram: "TEALCODE",
390
- * clearStateProgram: "TEALCODE",
391
- * schema: {
392
- * globalInts: 1,
393
- * globalByteSlices: 2,
394
- * localInts: 3,
395
- * localByteSlices: 4
396
- * },
397
- * extraProgramPages: 1,
398
- * onComplete: algosdk.OnApplicationComplete.OptInOC,
399
- * args: [new Uint8Array(1, 2, 3, 4)]
400
- * accountReferences: ["ACCOUNT_1"]
401
- * appReferences: [123n, 1234n]
402
- * assetReferences: [12345n]
403
- * boxReferences: ["box1", {appId: 1234n, name: "box2"}]
404
- * accessReferences: [{ appId: 1234n }]
405
- * lease: 'lease',
406
- * note: 'note',
407
- * // You wouldn't normally set this field
408
- * firstValidRound: 1000n,
409
- * validityWindow: 10,
410
- * extraFee: (1000).microAlgo(),
411
- * staticFee: (1000).microAlgo(),
412
- * // Max fee doesn't make sense with extraFee AND staticFee
413
- * // already specified, but here for completeness
414
- * maxFee: (3000).microAlgo(),
415
- * rejectVersion: 1,
416
- * // Signer only needed if you want to provide one,
417
- * // generally you'd register it with AlgorandClient
418
- * // against the sender and not need to pass it in
419
- * signer: transactionSigner,
420
- * maxRoundsToWaitForConfirmation: 5,
421
- * suppressLog: true,
422
- *})
423
- * ```
424
- */
425
- addAppCreate(params) {
426
- this.txns.push({ ...params, type: 'appCall' });
427
- return this;
428
- }
429
- /**
430
- * Add an application update transaction to the transaction group.
431
- *
432
- * Note: we recommend using app clients to make it easier to make app calls.
433
- * @param params The application update transaction parameters
434
- * @returns The composer so you can chain method calls
435
- * @example Basic example
436
- * ```typescript
437
- * composer.addAppUpdate({ sender: 'CREATORADDRESS', approvalProgram: 'TEALCODE', clearStateProgram: 'TEALCODE' })
438
- * ```
439
- * @example Advanced example
440
- * ```typescript
441
- * composer.addAppUpdate({
442
- * sender: 'CREATORADDRESS',
443
- * approvalProgram: "TEALCODE",
444
- * clearStateProgram: "TEALCODE",
445
- * onComplete: algosdk.OnApplicationComplete.UpdateApplicationOC,
446
- * args: [new Uint8Array(1, 2, 3, 4)]
447
- * accountReferences: ["ACCOUNT_1"]
448
- * appReferences: [123n, 1234n]
449
- * assetReferences: [12345n]
450
- * boxReferences: ["box1", {appId: 1234n, name: "box2"}]
451
- * accessReferences: [{ appId: 1234n }]
452
- * lease: 'lease',
453
- * note: 'note',
454
- * // You wouldn't normally set this field
455
- * firstValidRound: 1000n,
456
- * validityWindow: 10,
457
- * extraFee: (1000).microAlgo(),
458
- * staticFee: (1000).microAlgo(),
459
- * // Max fee doesn't make sense with extraFee AND staticFee
460
- * // already specified, but here for completeness
461
- * maxFee: (3000).microAlgo(),
462
- * rejectVersion: 1,
463
- *})
464
- * ```
465
- */
466
- addAppUpdate(params) {
467
- this.txns.push({ ...params, type: 'appCall', onComplete: algosdk.OnApplicationComplete.UpdateApplicationOC });
468
- return this;
469
- }
470
- /**
471
- * Add an application delete transaction to the transaction group.
472
- *
473
- * Note: we recommend using app clients to make it easier to make app calls.
474
- * @param params The application delete transaction parameters
475
- * @returns The composer so you can chain method calls
476
- * @example Basic example
477
- * ```typescript
478
- * composer.addAppDelete({ sender: 'CREATORADDRESS' })
479
- * ```
480
- * @example Advanced example
481
- * ```typescript
482
- * composer.addAppDelete({
483
- * sender: 'CREATORADDRESS',
484
- * onComplete: algosdk.OnApplicationComplete.DeleteApplicationOC,
485
- * args: [new Uint8Array(1, 2, 3, 4)]
486
- * accountReferences: ["ACCOUNT_1"]
487
- * appReferences: [123n, 1234n]
488
- * assetReferences: [12345n]
489
- * boxReferences: ["box1", {appId: 1234n, name: "box2"}]
490
- * accessReferences: [{ appId: 1234n }]
491
- * lease: 'lease',
492
- * note: 'note',
493
- * // You wouldn't normally set this field
494
- * firstValidRound: 1000n,
495
- * validityWindow: 10,
496
- * extraFee: (1000).microAlgo(),
497
- * staticFee: (1000).microAlgo(),
498
- * // Max fee doesn't make sense with extraFee AND staticFee
499
- * // already specified, but here for completeness
500
- * maxFee: (3000).microAlgo(),
501
- * rejectVersion: 1,
502
- *})
503
- * ```
504
- */
505
- addAppDelete(params) {
506
- this.txns.push({ ...params, type: 'appCall', onComplete: algosdk.OnApplicationComplete.DeleteApplicationOC });
507
- return this;
508
- }
509
- /**
510
- * Add an application call transaction to the transaction group.
511
- *
512
- * If you want to create or update an app use `addAppCreate` or `addAppUpdate`.
513
- *
514
- * Note: we recommend using app clients to make it easier to make app calls.
515
- * @param params The application call transaction parameters
516
- * @returns The composer so you can chain method calls
517
- * @example Basic example
518
- * ```typescript
519
- * composer.addAppCall({ sender: 'CREATORADDRESS' })
520
- * ```
521
- * @example Advanced example
522
- * ```typescript
523
- * composer.addAppCall({
524
- * sender: 'CREATORADDRESS',
525
- * onComplete: algosdk.OnApplicationComplete.OptInOC,
526
- * args: [new Uint8Array(1, 2, 3, 4)]
527
- * accountReferences: ["ACCOUNT_1"]
528
- * appReferences: [123n, 1234n]
529
- * assetReferences: [12345n]
530
- * boxReferences: ["box1", {appId: 1234n, name: "box2"}]
531
- * accessReferences: [{ appId: 1234n }]
532
- * lease: 'lease',
533
- * note: 'note',
534
- * // You wouldn't normally set this field
535
- * firstValidRound: 1000n,
536
- * validityWindow: 10,
537
- * extraFee: (1000).microAlgo(),
538
- * staticFee: (1000).microAlgo(),
539
- * // Max fee doesn't make sense with extraFee AND staticFee
540
- * // already specified, but here for completeness
541
- * maxFee: (3000).microAlgo(),
542
- * rejectVersion: 1,
543
- *})
544
- * ```
545
- */
546
- addAppCall(params) {
547
- this.txns.push({ ...params, type: 'appCall' });
548
- return this;
549
- }
550
- /**
551
- * Add an ABI method create application call transaction to the transaction group.
552
- *
553
- * Note: we recommend using app clients to make it easier to make app calls.
554
- * @param params The ABI create method application call transaction parameters
555
- * @returns The composer so you can chain method calls
556
- * @example Basic example
557
- * ```typescript
558
- * const method = new ABIMethod({
559
- * name: 'method',
560
- * args: [{ name: 'arg1', type: 'string' }],
561
- * returns: { type: 'string' },
562
- * })
563
- * composer.addAppCreateMethodCall({ sender: 'CREATORADDRESS', approvalProgram: 'TEALCODE', clearStateProgram: 'TEALCODE', method: method, args: ["arg1_value"] })
564
- * ```
565
- * @example Advanced example
566
- * ```typescript
567
- * const method = new ABIMethod({
568
- * name: 'method',
569
- * args: [{ name: 'arg1', type: 'string' }],
570
- * returns: { type: 'string' },
571
- * })
572
- * composer.addAppCreateMethodCall({
573
- * sender: 'CREATORADDRESS',
574
- * method: method,
575
- * args: ["arg1_value"],
576
- * approvalProgram: "TEALCODE",
577
- * clearStateProgram: "TEALCODE",
578
- * schema: {
579
- * globalInts: 1,
580
- * globalByteSlices: 2,
581
- * localInts: 3,
582
- * localByteSlices: 4
583
- * },
584
- * extraProgramPages: 1,
585
- * onComplete: algosdk.OnApplicationComplete.OptInOC,
586
- * args: [new Uint8Array(1, 2, 3, 4)]
587
- * accountReferences: ["ACCOUNT_1"]
588
- * appReferences: [123n, 1234n]
589
- * assetReferences: [12345n]
590
- * boxReferences: ["box1", {appId: 1234n, name: "box2"}]
591
- * accessReferences: [{ appId: 1234n }]
592
- * lease: 'lease',
593
- * note: 'note',
594
- * // You wouldn't normally set this field
595
- * firstValidRound: 1000n,
596
- * validityWindow: 10,
597
- * extraFee: (1000).microAlgo(),
598
- * staticFee: (1000).microAlgo(),
599
- * // Max fee doesn't make sense with extraFee AND staticFee
600
- * // already specified, but here for completeness
601
- * maxFee: (3000).microAlgo(),
602
- * rejectVersion: 1,
603
- *})
604
- * ```
605
- */
606
- addAppCreateMethodCall(params) {
607
- this.txns.push({ ...params, type: 'methodCall' });
608
- return this;
609
- }
610
- /**
611
- * Add an ABI method update application call transaction to the transaction group.
612
- *
613
- * Note: we recommend using app clients to make it easier to make app calls.
614
- * @param params The ABI update method application call transaction parameters
615
- * @returns The composer so you can chain method calls
616
- * @example Basic example
617
- * ```typescript
618
- * const method = new ABIMethod({
619
- * name: 'method',
620
- * args: [{ name: 'arg1', type: 'string' }],
621
- * returns: { type: 'string' },
622
- * })
623
- * composer.addAppUpdateMethodCall({ sender: 'CREATORADDRESS', approvalProgram: 'TEALCODE', clearStateProgram: 'TEALCODE', method: method, args: ["arg1_value"] })
624
- * ```
625
- * @example Advanced example
626
- * ```typescript
627
- * const method = new ABIMethod({
628
- * name: 'method',
629
- * args: [{ name: 'arg1', type: 'string' }],
630
- * returns: { type: 'string' },
631
- * })
632
- * composer.addAppUpdateMethodCall({
633
- * sender: 'CREATORADDRESS',
634
- * method: method,
635
- * args: ["arg1_value"],
636
- * approvalProgram: "TEALCODE",
637
- * clearStateProgram: "TEALCODE",
638
- * onComplete: algosdk.OnApplicationComplete.UpdateApplicationOC,
639
- * args: [new Uint8Array(1, 2, 3, 4)]
640
- * accountReferences: ["ACCOUNT_1"]
641
- * appReferences: [123n, 1234n]
642
- * assetReferences: [12345n]
643
- * boxReferences: ["box1", {appId: 1234n, name: "box2"}]
644
- * accessReferences: [{ appId: 1234n }]
645
- * lease: 'lease',
646
- * note: 'note',
647
- * // You wouldn't normally set this field
648
- * firstValidRound: 1000n,
649
- * validityWindow: 10,
650
- * extraFee: (1000).microAlgo(),
651
- * staticFee: (1000).microAlgo(),
652
- * // Max fee doesn't make sense with extraFee AND staticFee
653
- * // already specified, but here for completeness
654
- * maxFee: (3000).microAlgo(),
655
- * rejectVersion: 1,
656
- *})
657
- * ```
658
- */
659
- addAppUpdateMethodCall(params) {
660
- this.txns.push({ ...params, type: 'methodCall', onComplete: algosdk.OnApplicationComplete.UpdateApplicationOC });
661
- return this;
662
- }
663
- /**
664
- * Add an ABI method delete application call transaction to the transaction group.
665
- *
666
- * Note: we recommend using app clients to make it easier to make app calls.
667
- * @param params The ABI delete method application call transaction parameters
668
- * @returns The composer so you can chain method calls
669
- * @example Basic example
670
- * ```typescript
671
- * const method = new ABIMethod({
672
- * name: 'method',
673
- * args: [{ name: 'arg1', type: 'string' }],
674
- * returns: { type: 'string' },
675
- * })
676
- * composer.addAppDeleteMethodCall({ sender: 'CREATORADDRESS', method: method, args: ["arg1_value"] })
677
- * ```
678
- * @example Advanced example
679
- * ```typescript
680
- * const method = new ABIMethod({
681
- * name: 'method',
682
- * args: [{ name: 'arg1', type: 'string' }],
683
- * returns: { type: 'string' },
684
- * })
685
- * composer.addAppDeleteMethodCall({
686
- * sender: 'CREATORADDRESS',
687
- * method: method,
688
- * args: ["arg1_value"],
689
- * onComplete: algosdk.OnApplicationComplete.DeleteApplicationOC,
690
- * args: [new Uint8Array(1, 2, 3, 4)]
691
- * accountReferences: ["ACCOUNT_1"]
692
- * appReferences: [123n, 1234n]
693
- * assetReferences: [12345n]
694
- * boxReferences: ["box1", {appId: 1234n, name: "box2"}]
695
- * accessReferences: [{ appId: 1234n }]
696
- * lease: 'lease',
697
- * note: 'note',
698
- * // You wouldn't normally set this field
699
- * firstValidRound: 1000n,
700
- * validityWindow: 10,
701
- * extraFee: (1000).microAlgo(),
702
- * staticFee: (1000).microAlgo(),
703
- * // Max fee doesn't make sense with extraFee AND staticFee
704
- * // already specified, but here for completeness
705
- * maxFee: (3000).microAlgo(),
706
- * rejectVersion: 1,
707
- *})
708
- * ```
709
- */
710
- addAppDeleteMethodCall(params) {
711
- this.txns.push({ ...params, type: 'methodCall', onComplete: algosdk.OnApplicationComplete.DeleteApplicationOC });
712
- return this;
713
- }
714
- /**
715
- * Add a non-create/non-update ABI method application call transaction to the transaction group.
716
- *
717
- * Note: we recommend using app clients to make it easier to make app calls.
718
- * @param params The ABI method application call transaction parameters
719
- * @returns The composer so you can chain method calls
720
- * @example Basic example
721
- * ```typescript
722
- * const method = new ABIMethod({
723
- * name: 'method',
724
- * args: [{ name: 'arg1', type: 'string' }],
725
- * returns: { type: 'string' },
726
- * })
727
- * composer.addAppCallMethodCall({ sender: 'CREATORADDRESS', method: method, args: ["arg1_value"] })
728
- * ```
729
- * @example Advanced example
730
- * ```typescript
731
- * const method = new ABIMethod({
732
- * name: 'method',
733
- * args: [{ name: 'arg1', type: 'string' }],
734
- * returns: { type: 'string' },
735
- * })
736
- * composer.addAppCallMethodCall({
737
- * sender: 'CREATORADDRESS',
738
- * method: method,
739
- * args: ["arg1_value"],
740
- * onComplete: algosdk.OnApplicationComplete.OptInOC,
741
- * args: [new Uint8Array(1, 2, 3, 4)]
742
- * accountReferences: ["ACCOUNT_1"]
743
- * appReferences: [123n, 1234n]
744
- * assetReferences: [12345n]
745
- * boxReferences: ["box1", {appId: 1234n, name: "box2"}]
746
- * accessReferences: [{ appId: 1234n }]
747
- * lease: 'lease',
748
- * note: 'note',
749
- * // You wouldn't normally set this field
750
- * firstValidRound: 1000n,
751
- * validityWindow: 10,
752
- * extraFee: (1000).microAlgo(),
753
- * staticFee: (1000).microAlgo(),
754
- * // Max fee doesn't make sense with extraFee AND staticFee
755
- * // already specified, but here for completeness
756
- * maxFee: (3000).microAlgo(),
757
- * rejectVersion: 1,
758
- *})
759
- * ```
760
- */
761
- addAppCallMethodCall(params) {
762
- this.txns.push({ ...params, type: 'methodCall' });
763
- return this;
764
- }
765
- /**
766
- * Add an online key registration transaction to the transaction group.
767
- * @param params The online key registration transaction parameters
768
- * @returns The composer so you can chain method calls
769
- * @example Basic example
770
- * ```typescript
771
- * composer.addOnlineKeyRegistration({
772
- * sender: 'SENDERADDRESS',
773
- * voteKey: Uint8Array.from(Buffer.from("voteKeyBase64", 'base64')),
774
- * selectionKey: Uint8Array.from(Buffer.from("selectionKeyBase64", 'base64')),
775
- * stateProofKey: Uint8Array.from(Buffer.from("stateProofKeyBase64", 'base64')),
776
- * voteFirst: 1n,
777
- * voteLast: 1000n,
778
- * voteKeyDilution: 1n,
779
- * })
780
- * ```
781
- * @example Advanced example
782
- * ```typescript
783
- * composer.addOnlineKeyRegistration({
784
- * sender: 'SENDERADDRESS',
785
- * voteKey: Uint8Array.from(Buffer.from("voteKeyBase64", 'base64')),
786
- * selectionKey: Uint8Array.from(Buffer.from("selectionKeyBase64", 'base64')),
787
- * stateProofKey: Uint8Array.from(Buffer.from("stateProofKeyBase64", 'base64')),
788
- * voteFirst: 1n,
789
- * voteLast: 1000n,
790
- * voteKeyDilution: 1n,
791
- * lease: 'lease',
792
- * note: 'note',
793
- * // Use this with caution, it's generally better to use algorand.account.rekeyAccount
794
- * rekeyTo: 'REKEYTOADDRESS',
795
- * // You wouldn't normally set this field
796
- * firstValidRound: 1000n,
797
- * validityWindow: 10,
798
- * extraFee: (1000).microAlgo(),
799
- * staticFee: (1000).microAlgo(),
800
- * // Max fee doesn't make sense with extraFee AND staticFee
801
- * // already specified, but here for completeness
802
- * maxFee: (3000).microAlgo(),
803
- * })
804
- * ```
805
- */
806
- addOnlineKeyRegistration(params) {
807
- this.txns.push({ ...params, type: 'keyReg' });
808
- return this;
809
- }
810
- /**
811
- * Add an offline key registration transaction to the transaction group.
812
- * @param params The offline key registration transaction parameters
813
- * @returns The composer so you can chain method calls
814
- * @example Basic example
815
- * ```typescript
816
- * composer.addOfflineKeyRegistration({
817
- * sender: 'SENDERADDRESS',
818
- * })
819
- * ```
820
- * @example Advanced example
821
- * ```typescript
822
- * composer.addOfflineKeyRegistration({
823
- * sender: 'SENDERADDRESS',
824
- * lease: 'lease',
825
- * note: 'note',
826
- * // Use this with caution, it's generally better to use algorand.account.rekeyAccount
827
- * rekeyTo: 'REKEYTOADDRESS',
828
- * // You wouldn't normally set this field
829
- * firstValidRound: 1000n,
830
- * validityWindow: 10,
831
- * extraFee: (1000).microAlgo(),
832
- * staticFee: (1000).microAlgo(),
833
- * // Max fee doesn't make sense with extraFee AND staticFee
834
- * // already specified, but here for completeness
835
- * maxFee: (3000).microAlgo(),
836
- * })
837
- * ```
838
- */
839
- addOfflineKeyRegistration(params) {
840
- this.txns.push({ ...params, type: 'keyReg' });
841
- return this;
842
- }
843
- /**
844
- * Add the transactions within an `AtomicTransactionComposer` to the transaction group.
845
- * @param atc The `AtomicTransactionComposer` to build transactions from and add to the group
846
- * @returns The composer so you can chain method calls
847
- * @example
848
- * ```typescript
849
- * const atc = new AtomicTransactionComposer()
850
- * .addPayment({ sender: 'SENDERADDRESS', receiver: 'RECEIVERADDRESS', amount: 1000n })
851
- * composer.addAtc(atc)
852
- * ```
853
- */
854
- addAtc(atc) {
855
- this.txns.push({ atc, type: 'atc' });
856
- return this;
857
- }
858
- /** Build an ATC and return transactions ready to be incorporated into a broader set of transactions this composer is composing */
859
- buildAtc(atc) {
860
- const group = atc.buildGroup();
861
- const txnWithSigners = group.map((ts, idx) => {
862
- // Remove underlying group ID from the transaction since it will be re-grouped when this TransactionComposer is built
863
- ts.txn.group = undefined;
864
- // If this was a method call return the ABIMethod for later
865
- if (atc['methodCalls'].get(idx)) {
866
- return {
867
- ...ts,
868
- context: { abiMethod: atc['methodCalls'].get(idx) },
869
- };
870
- }
871
- return {
872
- ...ts,
873
- context: {},
874
- };
875
- });
876
- return txnWithSigners;
877
- }
878
- commonTxnBuildStep(buildTxn, params, txnParams) {
879
- // We are going to mutate suggested params, let's create a clone first
880
- txnParams.suggestedParams = { ...txnParams.suggestedParams };
881
- if (params.lease)
882
- txnParams.lease = transaction.encodeLease(params.lease);
883
- if (params.rekeyTo)
884
- txnParams.rekeyTo = address(params.rekeyTo);
885
- const encoder = new TextEncoder();
886
- if (params.note)
887
- txnParams.note = (typeof params.note === 'string' ? encoder.encode(params.note) : params.note);
888
- if (params.firstValidRound) {
889
- txnParams.suggestedParams.firstValid = params.firstValidRound;
890
- }
891
- if (params.lastValidRound) {
892
- txnParams.suggestedParams.lastValid = params.lastValidRound;
893
- }
894
- else {
895
- // If the validity window isn't set in this transaction or by default and we are pointing at
896
- // LocalNet set a bigger window to avoid dead transactions
897
- const window = params.validityWindow
898
- ? BigInt(params.validityWindow)
899
- : !this.defaultValidityWindowIsExplicit && types_networkClient.genesisIdIsLocalNet(txnParams.suggestedParams.genesisID ?? 'unknown')
900
- ? 1000n
901
- : this.defaultValidityWindow;
902
- txnParams.suggestedParams.lastValid = BigInt(txnParams.suggestedParams.firstValid) + window;
903
- }
904
- if (params.staticFee !== undefined && params.extraFee !== undefined) {
905
- throw Error('Cannot set both staticFee and extraFee');
906
- }
907
- if (params.staticFee !== undefined) {
908
- txnParams.suggestedParams.fee = params.staticFee.microAlgo;
909
- txnParams.suggestedParams.flatFee = true;
910
- }
911
- const txn = buildTxn(txnParams);
912
- if (params.extraFee)
913
- txn.fee += params.extraFee.microAlgo;
914
- if (params.maxFee !== undefined && txn.fee > params.maxFee.microAlgo) {
915
- throw Error(`Transaction fee ${txn.fee} µALGO is greater than maxFee ${params.maxFee}`);
916
- }
917
- const logicalMaxFee = params.maxFee !== undefined && params.maxFee.microAlgo > (params.staticFee?.microAlgo ?? 0n) ? params.maxFee : params.staticFee;
918
- return { txn, context: { maxFee: logicalMaxFee } };
919
- }
920
- /**
921
- * Builds an ABI method call transaction and any other associated transactions represented in the ABI args.
922
- * @param includeSigner Whether to include the actual signer for the transactions.
923
- * If you are just building transactions without signers yet then set this to `false`.
924
- */
925
- async buildMethodCall(params, suggestedParams, includeSigner) {
926
- const methodArgs = [];
927
- const transactionsForGroup = [];
928
- const isAbiValue = (x) => {
929
- if (Array.isArray(x))
930
- return x.length == 0 || x.every(isAbiValue);
931
- return (typeof x === 'bigint' ||
932
- typeof x === 'boolean' ||
933
- typeof x === 'number' ||
934
- typeof x === 'string' ||
935
- x instanceof Uint8Array ||
936
- x instanceof algosdk.Address);
937
- };
938
- for (let i = (params.args ?? []).length - 1; i >= 0; i--) {
939
- const arg = params.args[i];
940
- if (arg === undefined) {
941
- // An undefined transaction argument signals that the value will be supplied by a method call argument
942
- if (algosdk.abiTypeIsTransaction(params.method.args[i].type) && transactionsForGroup.length > 0) {
943
- // Move the last transaction from the group to the method call arguments to appease algosdk
944
- const placeholderTransaction = transactionsForGroup.splice(-1, 1)[0];
945
- methodArgs.push(placeholderTransaction);
946
- continue;
947
- }
948
- throw Error(`No value provided for argument ${i + 1} within call to ${params.method.name}`);
949
- }
950
- if (isAbiValue(arg)) {
951
- methodArgs.push(arg);
952
- continue;
953
- }
954
- if (isTransactionWithSigner(arg)) {
955
- methodArgs.push(arg);
956
- continue;
957
- }
958
- if ('method' in arg) {
959
- const tempTxnWithSigners = await this.buildMethodCall(arg, suggestedParams, includeSigner);
960
- // If there is any transaction args, add to the atc
961
- // Everything else should be added as method args
962
- methodArgs.push(...tempTxnWithSigners.slice(-1)); // Add the method call itself as a method arg
963
- transactionsForGroup.push(...tempTxnWithSigners.slice(0, -1).reverse()); // Add any transaction arguments to the atc
964
- continue;
965
- }
966
- const txn = await arg;
967
- methodArgs.push({
968
- txn,
969
- signer: includeSigner
970
- ? params.signer
971
- ? 'signer' in params.signer
972
- ? params.signer.signer
973
- : params.signer
974
- : this.getSigner(txn.sender)
975
- : TransactionComposer.NULL_SIGNER,
976
- });
977
- }
978
- const methodAtc = new algosdk.AtomicTransactionComposer();
979
- const maxFees = new Map();
980
- transactionsForGroup.reverse().forEach(({ context, ...txnWithSigner }) => {
981
- methodAtc.addTransaction(txnWithSigner);
982
- const atcIndex = methodAtc.count() - 1;
983
- if (context.abiMethod) {
984
- methodAtc['methodCalls'].set(atcIndex, context.abiMethod);
985
- }
986
- if (context.maxFee !== undefined) {
987
- maxFees.set(atcIndex, context.maxFee);
988
- }
989
- });
990
- // If any of the args are method call transactions, add that info to the methodAtc
991
- methodArgs
992
- .filter((arg) => {
993
- if (typeof arg === 'object' && 'context' in arg) {
994
- const { context, ...txnWithSigner } = arg;
995
- return isTransactionWithSigner(txnWithSigner);
996
- }
997
- return isTransactionWithSigner(arg);
998
- })
999
- .reverse()
1000
- .forEach((arg, idx) => {
1001
- if (typeof arg === 'object' && 'context' in arg && arg.context) {
1002
- const atcIndex = methodAtc.count() + idx;
1003
- if (arg.context.abiMethod) {
1004
- methodAtc['methodCalls'].set(atcIndex, arg.context.abiMethod);
1005
- }
1006
- if (arg.context.maxFee !== undefined) {
1007
- maxFees.set(atcIndex, arg.context.maxFee);
1008
- }
1009
- }
1010
- });
1011
- const appId = Number('appId' in params ? params.appId : 0n);
1012
- const approvalProgram = 'approvalProgram' in params
1013
- ? typeof params.approvalProgram === 'string'
1014
- ? (await this.appManager.compileTeal(params.approvalProgram)).compiledBase64ToBytes
1015
- : params.approvalProgram
1016
- : undefined;
1017
- const clearStateProgram = 'clearStateProgram' in params
1018
- ? typeof params.clearStateProgram === 'string'
1019
- ? (await this.appManager.compileTeal(params.clearStateProgram)).compiledBase64ToBytes
1020
- : params.clearStateProgram
1021
- : undefined;
1022
- const txnParams = {
1023
- appID: appId,
1024
- sender: params.sender,
1025
- suggestedParams,
1026
- onComplete: params.onComplete ?? algosdk.OnApplicationComplete.NoOpOC,
1027
- appAccounts: params.accountReferences,
1028
- appForeignApps: params.appReferences?.map((x) => Number(x)),
1029
- appForeignAssets: params.assetReferences?.map((x) => Number(x)),
1030
- boxes: params.boxReferences?.map(types_appManager.AppManager.getBoxReference),
1031
- access: params.accessReferences?.map(getResourceReference),
1032
- approvalProgram,
1033
- clearProgram: clearStateProgram,
1034
- extraPages: appId === 0
1035
- ? 'extraProgramPages' in params && params.extraProgramPages !== undefined
1036
- ? params.extraProgramPages
1037
- : approvalProgram
1038
- ? util.calculateExtraProgramPages(approvalProgram, clearStateProgram)
1039
- : 0
1040
- : undefined,
1041
- numLocalInts: appId === 0 ? ('schema' in params ? (params.schema?.localInts ?? 0) : 0) : undefined,
1042
- numLocalByteSlices: appId === 0 ? ('schema' in params ? (params.schema?.localByteSlices ?? 0) : 0) : undefined,
1043
- numGlobalInts: appId === 0 ? ('schema' in params ? (params.schema?.globalInts ?? 0) : 0) : undefined,
1044
- numGlobalByteSlices: appId === 0 ? ('schema' in params ? (params.schema?.globalByteSlices ?? 0) : 0) : undefined,
1045
- method: params.method,
1046
- signer: includeSigner
1047
- ? params.signer
1048
- ? 'signer' in params.signer
1049
- ? params.signer.signer
1050
- : params.signer
1051
- : this.getSigner(params.sender)
1052
- : TransactionComposer.NULL_SIGNER,
1053
- methodArgs: methodArgs
1054
- .map((arg) => {
1055
- if (typeof arg === 'object' && 'context' in arg) {
1056
- const { context, ...txnWithSigner } = arg;
1057
- return txnWithSigner;
1058
- }
1059
- return arg;
1060
- })
1061
- .reverse(),
1062
- rejectVersion: params.rejectVersion,
1063
- // note, lease, and rekeyTo are set in the common build step
1064
- note: undefined,
1065
- lease: undefined,
1066
- rekeyTo: undefined,
1067
- };
1068
- // Build the transaction
1069
- const result = this.commonTxnBuildStep((txnParams) => {
1070
- methodAtc.addMethodCall(txnParams);
1071
- return methodAtc.buildGroup()[methodAtc.count() - 1].txn;
1072
- }, params, txnParams);
1073
- // Process the ATC to get a set of transactions ready for broader grouping
1074
- return this.buildAtc(methodAtc).map(({ context: _context, ...txnWithSigner }, idx) => {
1075
- const maxFee = idx === methodAtc.count() - 1 ? result.context.maxFee : maxFees.get(idx);
1076
- const context = {
1077
- ..._context, // Adds method context info
1078
- maxFee,
1079
- };
1080
- return {
1081
- ...txnWithSigner,
1082
- context,
1083
- };
1084
- });
1085
- }
1086
- buildPayment(params, suggestedParams) {
1087
- return this.commonTxnBuildStep(algosdk.makePaymentTxnWithSuggestedParamsFromObject, params, {
1088
- sender: params.sender,
1089
- receiver: params.receiver,
1090
- amount: params.amount.microAlgo,
1091
- closeRemainderTo: params.closeRemainderTo,
1092
- suggestedParams,
1093
- });
1094
- }
1095
- buildAssetCreate(params, suggestedParams) {
1096
- return this.commonTxnBuildStep(algosdk.makeAssetCreateTxnWithSuggestedParamsFromObject, params, {
1097
- sender: params.sender,
1098
- total: params.total,
1099
- decimals: params.decimals ?? 0,
1100
- assetName: params.assetName,
1101
- unitName: params.unitName,
1102
- assetURL: params.url,
1103
- defaultFrozen: params.defaultFrozen ?? false,
1104
- assetMetadataHash: typeof params.metadataHash === 'string' ? Buffer.from(params.metadataHash, 'utf-8') : params.metadataHash,
1105
- manager: params.manager,
1106
- reserve: params.reserve,
1107
- freeze: params.freeze,
1108
- clawback: params.clawback,
1109
- suggestedParams,
1110
- });
1111
- }
1112
- buildAssetConfig(params, suggestedParams) {
1113
- return this.commonTxnBuildStep(algosdk.makeAssetConfigTxnWithSuggestedParamsFromObject, params, {
1114
- sender: params.sender,
1115
- assetIndex: params.assetId,
1116
- suggestedParams,
1117
- manager: params.manager,
1118
- reserve: params.reserve,
1119
- freeze: params.freeze,
1120
- clawback: params.clawback,
1121
- strictEmptyAddressChecking: false,
1122
- });
1123
- }
1124
- buildAssetDestroy(params, suggestedParams) {
1125
- return this.commonTxnBuildStep(algosdk.makeAssetDestroyTxnWithSuggestedParamsFromObject, params, {
1126
- sender: params.sender,
1127
- assetIndex: params.assetId,
1128
- suggestedParams,
1129
- });
1130
- }
1131
- buildAssetFreeze(params, suggestedParams) {
1132
- return this.commonTxnBuildStep(algosdk.makeAssetFreezeTxnWithSuggestedParamsFromObject, params, {
1133
- sender: params.sender,
1134
- assetIndex: params.assetId,
1135
- freezeTarget: params.account,
1136
- frozen: params.frozen,
1137
- suggestedParams,
1138
- });
1139
- }
1140
- buildAssetTransfer(params, suggestedParams) {
1141
- return this.commonTxnBuildStep(algosdk.makeAssetTransferTxnWithSuggestedParamsFromObject, params, {
1142
- sender: params.sender,
1143
- receiver: params.receiver,
1144
- assetIndex: params.assetId,
1145
- amount: params.amount,
1146
- suggestedParams,
1147
- closeRemainderTo: params.closeAssetTo,
1148
- assetSender: params.clawbackTarget,
1149
- });
1150
- }
1151
- async buildAppCall(params, suggestedParams) {
1152
- const appId = 'appId' in params ? params.appId : 0n;
1153
- const approvalProgram = 'approvalProgram' in params
1154
- ? typeof params.approvalProgram === 'string'
1155
- ? (await this.appManager.compileTeal(params.approvalProgram)).compiledBase64ToBytes
1156
- : params.approvalProgram
1157
- : undefined;
1158
- const clearStateProgram = 'clearStateProgram' in params
1159
- ? typeof params.clearStateProgram === 'string'
1160
- ? (await this.appManager.compileTeal(params.clearStateProgram)).compiledBase64ToBytes
1161
- : params.clearStateProgram
1162
- : undefined;
1163
- const sdkParams = {
1164
- sender: params.sender,
1165
- suggestedParams,
1166
- appArgs: params.args,
1167
- onComplete: params.onComplete ?? algosdk.OnApplicationComplete.NoOpOC,
1168
- accounts: params.accountReferences,
1169
- foreignApps: params.appReferences?.map((x) => Number(x)),
1170
- foreignAssets: params.assetReferences?.map((x) => Number(x)),
1171
- boxes: params.boxReferences?.map(types_appManager.AppManager.getBoxReference),
1172
- access: params.accessReferences?.map(getResourceReference),
1173
- approvalProgram,
1174
- clearProgram: clearStateProgram,
1175
- rejectVersion: params.rejectVersion,
1176
- };
1177
- if (appId === 0n) {
1178
- if (sdkParams.approvalProgram === undefined || sdkParams.clearProgram === undefined) {
1179
- throw new Error('approvalProgram and clearStateProgram are required for application creation');
1180
- }
1181
- return this.commonTxnBuildStep(algosdk.makeApplicationCreateTxnFromObject, params, {
1182
- ...sdkParams,
1183
- extraPages: 'extraProgramPages' in params && params.extraProgramPages !== undefined
1184
- ? params.extraProgramPages
1185
- : util.calculateExtraProgramPages(approvalProgram, clearStateProgram),
1186
- numLocalInts: 'schema' in params ? (params.schema?.localInts ?? 0) : 0,
1187
- numLocalByteSlices: 'schema' in params ? (params.schema?.localByteSlices ?? 0) : 0,
1188
- numGlobalInts: 'schema' in params ? (params.schema?.globalInts ?? 0) : 0,
1189
- numGlobalByteSlices: 'schema' in params ? (params.schema?.globalByteSlices ?? 0) : 0,
1190
- approvalProgram: approvalProgram,
1191
- clearProgram: clearStateProgram,
1192
- });
1193
- }
1194
- else {
1195
- return this.commonTxnBuildStep(algosdk.makeApplicationCallTxnFromObject, params, { ...sdkParams, appIndex: appId });
1196
- }
1197
- }
1198
- buildKeyReg(params, suggestedParams) {
1199
- if ('voteKey' in params) {
1200
- return this.commonTxnBuildStep(algosdk.makeKeyRegistrationTxnWithSuggestedParamsFromObject, params, {
1201
- sender: params.sender,
1202
- voteKey: params.voteKey,
1203
- selectionKey: params.selectionKey,
1204
- voteFirst: params.voteFirst,
1205
- voteLast: params.voteLast,
1206
- voteKeyDilution: params.voteKeyDilution,
1207
- suggestedParams,
1208
- nonParticipation: false,
1209
- stateProofKey: params.stateProofKey,
1210
- });
1211
- }
1212
- return this.commonTxnBuildStep(algosdk.makeKeyRegistrationTxnWithSuggestedParamsFromObject, params, {
1213
- sender: params.sender,
1214
- suggestedParams,
1215
- nonParticipation: params.preventAccountFromEverParticipatingAgain,
1216
- });
1217
- }
1218
- /** Builds all transaction types apart from `txnWithSigner`, `atc` and `methodCall` since those ones can have custom signers that need to be retrieved. */
1219
- async buildTxn(txn, suggestedParams) {
1220
- switch (txn.type) {
1221
- case 'pay':
1222
- return [this.buildPayment(txn, suggestedParams)];
1223
- case 'assetCreate':
1224
- return [this.buildAssetCreate(txn, suggestedParams)];
1225
- case 'appCall':
1226
- return [await this.buildAppCall(txn, suggestedParams)];
1227
- case 'assetConfig':
1228
- return [this.buildAssetConfig(txn, suggestedParams)];
1229
- case 'assetDestroy':
1230
- return [this.buildAssetDestroy(txn, suggestedParams)];
1231
- case 'assetFreeze':
1232
- return [this.buildAssetFreeze(txn, suggestedParams)];
1233
- case 'assetTransfer':
1234
- return [this.buildAssetTransfer(txn, suggestedParams)];
1235
- case 'assetOptIn':
1236
- return [this.buildAssetTransfer({ ...txn, receiver: txn.sender, amount: 0n }, suggestedParams)];
1237
- case 'assetOptOut':
1238
- return [this.buildAssetTransfer({ ...txn, receiver: txn.sender, amount: 0n, closeAssetTo: txn.creator }, suggestedParams)];
1239
- case 'keyReg':
1240
- return [this.buildKeyReg(txn, suggestedParams)];
1241
- default:
1242
- throw Error(`Unsupported txn type`);
1243
- }
1244
- }
1245
- async buildTxnWithSigner(txn, suggestedParams) {
1246
- if (txn.type === 'txnWithSigner') {
1247
- return [
1248
- {
1249
- ...txn,
1250
- context: {},
1251
- },
1252
- ];
1253
- }
1254
- if (txn.type === 'atc') {
1255
- return this.buildAtc(txn.atc);
1256
- }
1257
- if (txn.type === 'methodCall') {
1258
- return await this.buildMethodCall(txn, suggestedParams, true);
1259
- }
1260
- const signer = txn.signer ? ('signer' in txn.signer ? txn.signer.signer : txn.signer) : this.getSigner(txn.sender);
1261
- return (await this.buildTxn(txn, suggestedParams)).map(({ txn, context }) => ({ txn, signer, context }));
1262
- }
1263
- /**
1264
- * Compose all of the transactions without signers and return the transaction objects directly along with any ABI method calls.
1265
- *
1266
- * @returns The array of built transactions and any corresponding method calls
1267
- * @example
1268
- * ```typescript
1269
- * const { transactions, methodCalls, signers } = await composer.buildTransactions()
1270
- * ```
1271
- */
1272
- async buildTransactions() {
1273
- const suggestedParams = await this.getSuggestedParams();
1274
- const transactions = [];
1275
- const methodCalls = new Map();
1276
- const signers = new Map();
1277
- for (const txn of this.txns) {
1278
- if (!['txnWithSigner', 'atc', 'methodCall'].includes(txn.type)) {
1279
- transactions.push(...(await this.buildTxn(txn, suggestedParams)).map((txn) => txn.txn));
1280
- }
1281
- else {
1282
- const transactionsWithSigner = txn.type === 'txnWithSigner'
1283
- ? [txn]
1284
- : txn.type === 'atc'
1285
- ? this.buildAtc(txn.atc)
1286
- : txn.type === 'methodCall'
1287
- ? await this.buildMethodCall(txn, suggestedParams, false)
1288
- : [];
1289
- transactionsWithSigner.forEach((ts) => {
1290
- transactions.push(ts.txn);
1291
- const groupIdx = transactions.length - 1;
1292
- if (ts.signer && ts.signer !== TransactionComposer.NULL_SIGNER) {
1293
- signers.set(groupIdx, ts.signer);
1294
- }
1295
- if ('context' in ts && ts.context.abiMethod) {
1296
- methodCalls.set(groupIdx, ts.context.abiMethod);
1297
- }
1298
- });
1299
- }
1300
- }
1301
- return { transactions, methodCalls, signers };
1302
- }
1303
- /**
1304
- * Get the number of transactions currently added to this composer.
1305
- * @returns The number of transactions currently added to this composer
1306
- */
1307
- async count() {
1308
- return (await this.buildTransactions()).transactions.length;
1309
- }
1310
- /**
1311
- * Compose all of the transactions in a single atomic transaction group and an atomic transaction composer.
1312
- *
1313
- * You can then use the transactions standalone, or use the composer to execute or simulate the transactions.
1314
- *
1315
- * Once this method is called, no further transactions will be able to be added.
1316
- * You can safely call this method multiple times to get the same result.
1317
- * @returns The built atomic transaction composer, the transactions and any corresponding method calls
1318
- * @example
1319
- * ```typescript
1320
- * const { atc, transactions, methodCalls } = await composer.build()
1321
- * ```
1322
- */
1323
- async build() {
1324
- if (this.atc.getStatus() === algosdk.AtomicTransactionComposerStatus.BUILDING) {
1325
- const suggestedParams = await this.getSuggestedParams();
1326
- // Build all of the transactions
1327
- const txnWithSigners = [];
1328
- for (const txn of this.txns) {
1329
- txnWithSigners.push(...(await this.buildTxnWithSigner(txn, suggestedParams)));
1330
- }
1331
- // Add all of the transactions to the underlying ATC
1332
- const methodCalls = new Map();
1333
- txnWithSigners.forEach(({ context, ...ts }, idx) => {
1334
- this.atc.addTransaction(ts);
1335
- // Populate consolidated set of all ABI method calls
1336
- if (context.abiMethod) {
1337
- methodCalls.set(idx, context.abiMethod);
1338
- }
1339
- if (context.maxFee !== undefined) {
1340
- this.txnMaxFees.set(idx, context.maxFee);
1341
- }
1342
- });
1343
- this.atc['methodCalls'] = methodCalls;
1344
- }
1345
- const transactions = this.atc.buildGroup();
1346
- return { atc: this.atc, transactions, methodCalls: this.atc['methodCalls'] };
1347
- }
1348
- /**
1349
- * Rebuild the group, discarding any previously built transactions.
1350
- * This will potentially cause new signers and suggested params to be used if the callbacks return a new value compared to the first build.
1351
- * @returns The newly built atomic transaction composer and the transactions
1352
- * @example
1353
- * ```typescript
1354
- * const { atc, transactions, methodCalls } = await composer.rebuild()
1355
- * ```
1356
- */
1357
- async rebuild() {
1358
- this.atc = new algosdk.AtomicTransactionComposer();
1359
- return await this.build();
1360
- }
1361
- /**
1362
- * Compose the atomic transaction group and send it to the network.
1363
- * @param params The parameters to control execution with
1364
- * @returns The execution result
1365
- * @example
1366
- * ```typescript
1367
- * const result = await composer.send()
1368
- * ```
1369
- */
1370
- async send(params) {
1371
- const group = (await this.build()).transactions;
1372
- let waitRounds = params?.maxRoundsToWaitForConfirmation;
1373
- const suggestedParams = waitRounds === undefined || params?.coverAppCallInnerTransactionFees ? await this.getSuggestedParams() : undefined;
1374
- if (waitRounds === undefined) {
1375
- const lastRound = group.reduce((max, txn) => (txn.txn.lastValid > max ? txn.txn.lastValid : BigInt(max)), 0n);
1376
- const { firstValid: firstRound } = suggestedParams;
1377
- waitRounds = Number(BigInt(lastRound) - BigInt(firstRound)) + 1;
1378
- }
1379
- try {
1380
- return await transaction.sendAtomicTransactionComposer({
1381
- atc: this.atc,
1382
- suppressLog: params?.suppressLog,
1383
- maxRoundsToWaitForConfirmation: waitRounds,
1384
- populateAppCallResources: params?.populateAppCallResources,
1385
- coverAppCallInnerTransactionFees: params?.coverAppCallInnerTransactionFees,
1386
- additionalAtcContext: params?.coverAppCallInnerTransactionFees
1387
- ? {
1388
- maxFees: this.txnMaxFees,
1389
- suggestedParams: suggestedParams,
1390
- }
1391
- : undefined,
1392
- }, this.algod);
1393
- }
1394
- catch (originalError) {
1395
- throw await this.transformError(originalError);
1396
- }
1397
- }
1398
- /**
1399
- * @deprecated Use `send` instead.
1400
- *
1401
- * Compose the atomic transaction group and send it to the network
1402
- *
1403
- * An alias for `composer.send(params)`.
1404
- * @param params The parameters to control execution with
1405
- * @returns The execution result
1406
- */
1407
- async execute(params) {
1408
- return this.send(params);
1409
- }
1410
- async simulate(options) {
1411
- const { skipSignatures = false, ...rawOptions } = options ?? {};
1412
- const atc = skipSignatures ? new AtomicTransactionComposer() : this.atc;
1413
- // Build the transactions
1414
- if (skipSignatures) {
1415
- rawOptions.allowEmptySignatures = true;
1416
- rawOptions.fixSigners = true;
1417
- // Build transactions uses empty signers
1418
- const transactions = await this.buildTransactions();
1419
- for (const txn of transactions.transactions) {
1420
- atc.addTransaction({ txn, signer: TransactionComposer.NULL_SIGNER });
1421
- }
1422
- atc['methodCalls'] = transactions.methodCalls;
1423
- }
1424
- else {
1425
- // Build creates real signatures
1426
- await this.build();
1427
- }
1428
- const { methodResults, simulateResponse } = await atc.simulate(this.algod, new modelsv2.SimulateRequest({
1429
- txnGroups: [],
1430
- ...rawOptions,
1431
- ...(config.Config.debug
1432
- ? {
1433
- allowEmptySignatures: true,
1434
- fixSigners: true,
1435
- allowMoreLogging: true,
1436
- execTraceConfig: new modelsv2.SimulateTraceConfig({
1437
- enable: true,
1438
- scratchChange: true,
1439
- stackChange: true,
1440
- stateChange: true,
1441
- }),
1442
- }
1443
- : undefined),
1444
- }));
1445
- const failedGroup = simulateResponse?.txnGroups[0];
1446
- if (failedGroup?.failureMessage) {
1447
- const errorMessage = `Transaction failed at transaction(s) ${failedGroup.failedAt?.join(', ') || 'unknown'} in the group. ${failedGroup.failureMessage}`;
1448
- const error = new Error(errorMessage);
1449
- if (config.Config.debug) {
1450
- await config.Config.events.emitAsync(types_lifecycleEvents.EventType.TxnGroupSimulated, { simulateResponse });
1451
- }
1452
- throw await this.transformError(error);
1453
- }
1454
- if (config.Config.debug && config.Config.traceAll) {
1455
- await config.Config.events.emitAsync(types_lifecycleEvents.EventType.TxnGroupSimulated, { simulateResponse });
1456
- }
1457
- const transactions = atc.buildGroup().map((t) => t.txn);
1458
- const methodCalls = [...atc['methodCalls'].values()];
1459
- return {
1460
- confirmations: simulateResponse.txnGroups[0].txnResults.map((t) => t.txnResult),
1461
- transactions: transactions,
1462
- txIds: transactions.map((t) => t.txID()),
1463
- groupId: Buffer.from(transactions[0].group ?? new Uint8Array()).toString('base64'),
1464
- simulateResponse,
1465
- returns: methodResults.map((r, i) => transaction.getABIReturnValue(r, methodCalls[i].returns.type)),
1466
- };
1467
- }
1468
- /**
1469
- * Create an encoded transaction note that follows the ARC-2 spec.
1470
- *
1471
- * https://github.com/algorandfoundation/ARCs/blob/main/ARCs/arc-0002.md
1472
- * @param note The ARC-2 transaction note data
1473
- * @returns The binary encoded transaction note
1474
- */
1475
- static arc2Note(note) {
1476
- const arc2Payload = `${note.dAppName}:${note.format}${typeof note.data === 'string' ? note.data : util.asJson(note.data)}`;
1477
- const encoder = new TextEncoder();
1478
- return encoder.encode(arc2Payload);
1479
- }
1480
- }
1481
- /** Signer used to represent a lack of signer */
1482
- TransactionComposer.NULL_SIGNER = algosdk.makeEmptyTransactionSigner();
30
+ var TransactionComposer = class TransactionComposer {
31
+ /** Signer used to represent a lack of signer */
32
+ static NULL_SIGNER = algosdk.default.makeEmptyTransactionSigner();
33
+ /** The ATC used to compose the group */
34
+ atc = new algosdk.default.AtomicTransactionComposer();
35
+ /** Map of transaction index in the atc to a max logical fee.
36
+ * This is set using the value of either maxFee or staticFee.
37
+ */
38
+ txnMaxFees = /* @__PURE__ */ new Map();
39
+ /** Transactions that have not yet been composed */
40
+ txns = [];
41
+ /** The algod client used by the composer. */
42
+ algod;
43
+ /** An async function that will return suggested params for the transaction. */
44
+ getSuggestedParams;
45
+ /** A function that takes in an address and return a signer function for that address. */
46
+ getSigner;
47
+ /** The default transaction validity window */
48
+ defaultValidityWindow = 10n;
49
+ /** Whether the validity window was explicitly set on construction */
50
+ defaultValidityWindowIsExplicit = false;
51
+ appManager;
52
+ errorTransformers;
53
+ async transformError(originalError) {
54
+ if (!(originalError instanceof Error)) return originalError;
55
+ let transformedError = originalError;
56
+ for (const transformer of this.errorTransformers) try {
57
+ transformedError = await transformer(transformedError);
58
+ if (!(transformedError instanceof Error)) return new InvalidErrorTransformerValue(originalError, transformedError);
59
+ } catch (errorFromTransformer) {
60
+ return new ErrorTransformerError(originalError, errorFromTransformer);
61
+ }
62
+ return transformedError;
63
+ }
64
+ /**
65
+ * Create a `TransactionComposer`.
66
+ * @param params The configuration for this composer
67
+ * @returns The `TransactionComposer` instance
68
+ */
69
+ constructor(params) {
70
+ this.algod = params.algod;
71
+ const defaultGetSuggestedParams = () => params.algod.getTransactionParams().do();
72
+ this.getSuggestedParams = params.getSuggestedParams ?? defaultGetSuggestedParams;
73
+ this.getSigner = params.getSigner;
74
+ this.defaultValidityWindow = params.defaultValidityWindow ?? this.defaultValidityWindow;
75
+ this.defaultValidityWindowIsExplicit = params.defaultValidityWindow !== void 0;
76
+ this.appManager = params.appManager ?? new require_app_manager.AppManager(params.algod);
77
+ this.errorTransformers = params.errorTransformers ?? [];
78
+ }
79
+ /**
80
+ * Register a function that will be used to transform an error caught when simulating or executing
81
+ *
82
+ * @returns The composer so you can chain method calls
83
+ */
84
+ registerErrorTransformer(transformer) {
85
+ this.errorTransformers.push(transformer);
86
+ return this;
87
+ }
88
+ /**
89
+ * Add a pre-built transaction to the transaction group.
90
+ * @param transaction The pre-built transaction
91
+ * @param signer Optional signer override for the transaction
92
+ * @returns The composer so you can chain method calls
93
+ * @example
94
+ * ```typescript
95
+ * composer.addTransaction(txn)
96
+ * ```
97
+ */
98
+ addTransaction(transaction, signer) {
99
+ this.txns.push({
100
+ txn: transaction,
101
+ signer: signer ?? this.getSigner(transaction.sender),
102
+ type: "txnWithSigner"
103
+ });
104
+ return this;
105
+ }
106
+ /**
107
+ * Add a payment transaction to the transaction group.
108
+ * @param params The payment transaction parameters
109
+ * @returns The composer so you can chain method calls
110
+ * @example Basic example
111
+ * ```typescript
112
+ * composer.addPayment({
113
+ * sender: 'SENDERADDRESS',
114
+ * receiver: 'RECEIVERADDRESS',
115
+ * amount: (4).algo(),
116
+ * })
117
+ * ```
118
+ * @example Advanced example
119
+ * ```typescript
120
+ * composer.addPayment({
121
+ * amount: (4).algo(),
122
+ * receiver: 'RECEIVERADDRESS',
123
+ * sender: 'SENDERADDRESS',
124
+ * closeRemainderTo: 'CLOSEREMAINDERTOADDRESS',
125
+ * lease: 'lease',
126
+ * note: 'note',
127
+ * // Use this with caution, it's generally better to use algorand.account.rekeyAccount
128
+ * rekeyTo: 'REKEYTOADDRESS',
129
+ * // You wouldn't normally set this field
130
+ * firstValidRound: 1000n,
131
+ * validityWindow: 10,
132
+ * extraFee: (1000).microAlgo(),
133
+ * staticFee: (1000).microAlgo(),
134
+ * // Max fee doesn't make sense with extraFee AND staticFee
135
+ * // already specified, but here for completeness
136
+ * maxFee: (3000).microAlgo(),
137
+ * })
138
+ */
139
+ addPayment(params) {
140
+ this.txns.push({
141
+ ...params,
142
+ type: "pay"
143
+ });
144
+ return this;
145
+ }
146
+ /**
147
+ * Add an asset create transaction to the transaction group.
148
+ * @param params The asset create transaction parameters
149
+ * @returns The composer so you can chain method calls
150
+ * @example Basic example
151
+ * ```typescript
152
+ * composer.addAssetCreate({ sender: "CREATORADDRESS", total: 100n})
153
+ * ```
154
+ * @example Advanced example
155
+ * ```typescript
156
+ * composer.addAssetCreate({
157
+ * sender: 'CREATORADDRESS',
158
+ * total: 100n,
159
+ * decimals: 2,
160
+ * assetName: 'asset',
161
+ * unitName: 'unit',
162
+ * url: 'url',
163
+ * metadataHash: 'metadataHash',
164
+ * defaultFrozen: false,
165
+ * manager: 'MANAGERADDRESS',
166
+ * reserve: 'RESERVEADDRESS',
167
+ * freeze: 'FREEZEADDRESS',
168
+ * clawback: 'CLAWBACKADDRESS',
169
+ * lease: 'lease',
170
+ * note: 'note',
171
+ * // You wouldn't normally set this field
172
+ * firstValidRound: 1000n,
173
+ * validityWindow: 10,
174
+ * extraFee: (1000).microAlgo(),
175
+ * staticFee: (1000).microAlgo(),
176
+ * // Max fee doesn't make sense with extraFee AND staticFee
177
+ * // already specified, but here for completeness
178
+ * maxFee: (3000).microAlgo(),
179
+ * })
180
+ */
181
+ addAssetCreate(params) {
182
+ this.txns.push({
183
+ ...params,
184
+ type: "assetCreate"
185
+ });
186
+ return this;
187
+ }
188
+ /**
189
+ * Add an asset config transaction to the transaction group.
190
+ * @param params The asset config transaction parameters
191
+ * @returns The composer so you can chain method calls
192
+ * @example Basic example
193
+ * ```typescript
194
+ * composer.addAssetConfig({ sender: "MANAGERADDRESS", assetId: 123456n, manager: "MANAGERADDRESS" })
195
+ * ```
196
+ * @example Advanced example
197
+ * ```typescript
198
+ * composer.addAssetConfig({
199
+ * sender: 'MANAGERADDRESS',
200
+ * assetId: 123456n,
201
+ * manager: 'MANAGERADDRESS',
202
+ * reserve: 'RESERVEADDRESS',
203
+ * freeze: 'FREEZEADDRESS',
204
+ * clawback: 'CLAWBACKADDRESS',
205
+ * lease: 'lease',
206
+ * note: 'note',
207
+ * // You wouldn't normally set this field
208
+ * firstValidRound: 1000n,
209
+ * validityWindow: 10,
210
+ * extraFee: (1000).microAlgo(),
211
+ * staticFee: (1000).microAlgo(),
212
+ * // Max fee doesn't make sense with extraFee AND staticFee
213
+ * // already specified, but here for completeness
214
+ * maxFee: (3000).microAlgo(),
215
+ * })
216
+ */
217
+ addAssetConfig(params) {
218
+ this.txns.push({
219
+ ...params,
220
+ type: "assetConfig"
221
+ });
222
+ return this;
223
+ }
224
+ /**
225
+ * Add an asset freeze transaction to the transaction group.
226
+ * @param params The asset freeze transaction parameters
227
+ * @returns The composer so you can chain method calls
228
+ * @example Basic example
229
+ * ```typescript
230
+ * composer.addAssetFreeze({ sender: "MANAGERADDRESS", assetId: 123456n, account: "ACCOUNTADDRESS", frozen: true })
231
+ * ```
232
+ * @example Advanced example
233
+ * ```typescript
234
+ * composer.addAssetFreeze({
235
+ * sender: 'MANAGERADDRESS',
236
+ * assetId: 123456n,
237
+ * account: 'ACCOUNTADDRESS',
238
+ * frozen: true,
239
+ * lease: 'lease',
240
+ * note: 'note',
241
+ * // You wouldn't normally set this field
242
+ * firstValidRound: 1000n,
243
+ * validityWindow: 10,
244
+ * extraFee: (1000).microAlgo(),
245
+ * staticFee: (1000).microAlgo(),
246
+ * // Max fee doesn't make sense with extraFee AND staticFee
247
+ * // already specified, but here for completeness
248
+ * maxFee: (3000).microAlgo(),
249
+ * })
250
+ * ```
251
+ */
252
+ addAssetFreeze(params) {
253
+ this.txns.push({
254
+ ...params,
255
+ type: "assetFreeze"
256
+ });
257
+ return this;
258
+ }
259
+ /**
260
+ * Add an asset destroy transaction to the transaction group.
261
+ * @param params The asset destroy transaction parameters
262
+ * @returns The composer so you can chain method calls
263
+ * @example Basic example
264
+ * ```typescript
265
+ * composer.addAssetDestroy({ sender: "MANAGERADDRESS", assetId: 123456n })
266
+ * ```
267
+ * @example Advanced example
268
+ * ```typescript
269
+ * composer.addAssetDestroy({
270
+ * sender: 'MANAGERADDRESS',
271
+ * assetId: 123456n,
272
+ * lease: 'lease',
273
+ * note: 'note',
274
+ * // You wouldn't normally set this field
275
+ * firstValidRound: 1000n,
276
+ * validityWindow: 10,
277
+ * extraFee: (1000).microAlgo(),
278
+ * staticFee: (1000).microAlgo(),
279
+ * // Max fee doesn't make sense with extraFee AND staticFee
280
+ * // already specified, but here for completeness
281
+ * maxFee: (3000).microAlgo(),
282
+ * })
283
+ * ```
284
+ */
285
+ addAssetDestroy(params) {
286
+ this.txns.push({
287
+ ...params,
288
+ type: "assetDestroy"
289
+ });
290
+ return this;
291
+ }
292
+ /**
293
+ * Add an asset transfer transaction to the transaction group.
294
+ * @param params The asset transfer transaction parameters
295
+ * @returns The composer so you can chain method calls
296
+ * @example Basic example
297
+ * ```typescript
298
+ * composer.addAssetTransfer({ sender: "HOLDERADDRESS", assetId: 123456n, amount: 1n, receiver: "RECEIVERADDRESS" })
299
+ * ```
300
+ * @example Advanced example (with clawback)
301
+ * ```typescript
302
+ * composer.addAssetTransfer({
303
+ * sender: 'CLAWBACKADDRESS',
304
+ * assetId: 123456n,
305
+ * amount: 1n,
306
+ * receiver: 'RECEIVERADDRESS',
307
+ * clawbackTarget: 'HOLDERADDRESS',
308
+ * // This field needs to be used with caution
309
+ * closeAssetTo: 'ADDRESSTOCLOSETO'
310
+ * lease: 'lease',
311
+ * note: 'note',
312
+ * // You wouldn't normally set this field
313
+ * firstValidRound: 1000n,
314
+ * validityWindow: 10,
315
+ * extraFee: (1000).microAlgo(),
316
+ * staticFee: (1000).microAlgo(),
317
+ * // Max fee doesn't make sense with extraFee AND staticFee
318
+ * // already specified, but here for completeness
319
+ * maxFee: (3000).microAlgo(),
320
+ * })
321
+ * ```
322
+ */
323
+ addAssetTransfer(params) {
324
+ this.txns.push({
325
+ ...params,
326
+ type: "assetTransfer"
327
+ });
328
+ return this;
329
+ }
330
+ /**
331
+ * Add an asset opt-in transaction to the transaction group.
332
+ * @param params The asset opt-in transaction parameters
333
+ * @returns The composer so you can chain method calls
334
+ * @example Basic example
335
+ * ```typescript
336
+ * composer.addAssetOptIn({ sender: "SENDERADDRESS", assetId: 123456n })
337
+ * ```
338
+ * @example Advanced example
339
+ * ```typescript
340
+ * composer.addAssetOptIn({
341
+ * sender: 'SENDERADDRESS',
342
+ * assetId: 123456n,
343
+ * lease: 'lease',
344
+ * note: 'note',
345
+ * // You wouldn't normally set this field
346
+ * firstValidRound: 1000n,
347
+ * validityWindow: 10,
348
+ * extraFee: (1000).microAlgo(),
349
+ * staticFee: (1000).microAlgo(),
350
+ * // Max fee doesn't make sense with extraFee AND staticFee
351
+ * // already specified, but here for completeness
352
+ * maxFee: (3000).microAlgo(),
353
+ * })
354
+ * ```
355
+ */
356
+ addAssetOptIn(params) {
357
+ this.txns.push({
358
+ ...params,
359
+ type: "assetOptIn"
360
+ });
361
+ return this;
362
+ }
363
+ /**
364
+ * Add an asset opt-out transaction to the transaction group.
365
+ * @param params The asset opt-out transaction parameters
366
+ * @returns The composer so you can chain method calls
367
+ * @example Basic example (without creator, will be retrieved from algod)
368
+ * ```typescript
369
+ * composer.addAssetOptOut({ sender: "SENDERADDRESS", assetId: 123456n, ensureZeroBalance: true })
370
+ * ```
371
+ * @example Basic example (with creator)
372
+ * ```typescript
373
+ * composer.addAssetOptOut({ sender: "SENDERADDRESS", creator: "CREATORADDRESS", assetId: 123456n, ensureZeroBalance: true })
374
+ * ```
375
+ * @example Advanced example
376
+ * ```typescript
377
+ * composer.addAssetOptOut({
378
+ * sender: 'SENDERADDRESS',
379
+ * assetId: 123456n,
380
+ * creator: 'CREATORADDRESS',
381
+ * ensureZeroBalance: true,
382
+ * lease: 'lease',
383
+ * note: 'note',
384
+ * // You wouldn't normally set this field
385
+ * firstValidRound: 1000n,
386
+ * validityWindow: 10,
387
+ * extraFee: (1000).microAlgo(),
388
+ * staticFee: (1000).microAlgo(),
389
+ * // Max fee doesn't make sense with extraFee AND staticFee
390
+ * // already specified, but here for completeness
391
+ * maxFee: (3000).microAlgo(),
392
+ * })
393
+ * ```
394
+ */
395
+ addAssetOptOut(params) {
396
+ this.txns.push({
397
+ ...params,
398
+ type: "assetOptOut"
399
+ });
400
+ return this;
401
+ }
402
+ /**
403
+ * Add an application create transaction to the transaction group.
404
+ *
405
+ * Note: we recommend using app clients to make it easier to make app calls.
406
+ * @param params The application create transaction parameters
407
+ * @returns The composer so you can chain method calls
408
+ * @example Basic example
409
+ * ```typescript
410
+ * composer.addAppCreate({ sender: 'CREATORADDRESS', approvalProgram: 'TEALCODE', clearStateProgram: 'TEALCODE' })
411
+ * ```
412
+ * @example Advanced example
413
+ * ```typescript
414
+ * composer.addAppCreate({
415
+ * sender: 'CREATORADDRESS',
416
+ * approvalProgram: "TEALCODE",
417
+ * clearStateProgram: "TEALCODE",
418
+ * schema: {
419
+ * globalInts: 1,
420
+ * globalByteSlices: 2,
421
+ * localInts: 3,
422
+ * localByteSlices: 4
423
+ * },
424
+ * extraProgramPages: 1,
425
+ * onComplete: algosdk.OnApplicationComplete.OptInOC,
426
+ * args: [new Uint8Array(1, 2, 3, 4)]
427
+ * accountReferences: ["ACCOUNT_1"]
428
+ * appReferences: [123n, 1234n]
429
+ * assetReferences: [12345n]
430
+ * boxReferences: ["box1", {appId: 1234n, name: "box2"}]
431
+ * accessReferences: [{ appId: 1234n }]
432
+ * lease: 'lease',
433
+ * note: 'note',
434
+ * // You wouldn't normally set this field
435
+ * firstValidRound: 1000n,
436
+ * validityWindow: 10,
437
+ * extraFee: (1000).microAlgo(),
438
+ * staticFee: (1000).microAlgo(),
439
+ * // Max fee doesn't make sense with extraFee AND staticFee
440
+ * // already specified, but here for completeness
441
+ * maxFee: (3000).microAlgo(),
442
+ * rejectVersion: 1,
443
+ * // Signer only needed if you want to provide one,
444
+ * // generally you'd register it with AlgorandClient
445
+ * // against the sender and not need to pass it in
446
+ * signer: transactionSigner,
447
+ * maxRoundsToWaitForConfirmation: 5,
448
+ * suppressLog: true,
449
+ *})
450
+ * ```
451
+ */
452
+ addAppCreate(params) {
453
+ this.txns.push({
454
+ ...params,
455
+ type: "appCall"
456
+ });
457
+ return this;
458
+ }
459
+ /**
460
+ * Add an application update transaction to the transaction group.
461
+ *
462
+ * Note: we recommend using app clients to make it easier to make app calls.
463
+ * @param params The application update transaction parameters
464
+ * @returns The composer so you can chain method calls
465
+ * @example Basic example
466
+ * ```typescript
467
+ * composer.addAppUpdate({ sender: 'CREATORADDRESS', approvalProgram: 'TEALCODE', clearStateProgram: 'TEALCODE' })
468
+ * ```
469
+ * @example Advanced example
470
+ * ```typescript
471
+ * composer.addAppUpdate({
472
+ * sender: 'CREATORADDRESS',
473
+ * approvalProgram: "TEALCODE",
474
+ * clearStateProgram: "TEALCODE",
475
+ * onComplete: algosdk.OnApplicationComplete.UpdateApplicationOC,
476
+ * args: [new Uint8Array(1, 2, 3, 4)]
477
+ * accountReferences: ["ACCOUNT_1"]
478
+ * appReferences: [123n, 1234n]
479
+ * assetReferences: [12345n]
480
+ * boxReferences: ["box1", {appId: 1234n, name: "box2"}]
481
+ * accessReferences: [{ appId: 1234n }]
482
+ * lease: 'lease',
483
+ * note: 'note',
484
+ * // You wouldn't normally set this field
485
+ * firstValidRound: 1000n,
486
+ * validityWindow: 10,
487
+ * extraFee: (1000).microAlgo(),
488
+ * staticFee: (1000).microAlgo(),
489
+ * // Max fee doesn't make sense with extraFee AND staticFee
490
+ * // already specified, but here for completeness
491
+ * maxFee: (3000).microAlgo(),
492
+ * rejectVersion: 1,
493
+ *})
494
+ * ```
495
+ */
496
+ addAppUpdate(params) {
497
+ this.txns.push({
498
+ ...params,
499
+ type: "appCall",
500
+ onComplete: algosdk.default.OnApplicationComplete.UpdateApplicationOC
501
+ });
502
+ return this;
503
+ }
504
+ /**
505
+ * Add an application delete transaction to the transaction group.
506
+ *
507
+ * Note: we recommend using app clients to make it easier to make app calls.
508
+ * @param params The application delete transaction parameters
509
+ * @returns The composer so you can chain method calls
510
+ * @example Basic example
511
+ * ```typescript
512
+ * composer.addAppDelete({ sender: 'CREATORADDRESS' })
513
+ * ```
514
+ * @example Advanced example
515
+ * ```typescript
516
+ * composer.addAppDelete({
517
+ * sender: 'CREATORADDRESS',
518
+ * onComplete: algosdk.OnApplicationComplete.DeleteApplicationOC,
519
+ * args: [new Uint8Array(1, 2, 3, 4)]
520
+ * accountReferences: ["ACCOUNT_1"]
521
+ * appReferences: [123n, 1234n]
522
+ * assetReferences: [12345n]
523
+ * boxReferences: ["box1", {appId: 1234n, name: "box2"}]
524
+ * accessReferences: [{ appId: 1234n }]
525
+ * lease: 'lease',
526
+ * note: 'note',
527
+ * // You wouldn't normally set this field
528
+ * firstValidRound: 1000n,
529
+ * validityWindow: 10,
530
+ * extraFee: (1000).microAlgo(),
531
+ * staticFee: (1000).microAlgo(),
532
+ * // Max fee doesn't make sense with extraFee AND staticFee
533
+ * // already specified, but here for completeness
534
+ * maxFee: (3000).microAlgo(),
535
+ * rejectVersion: 1,
536
+ *})
537
+ * ```
538
+ */
539
+ addAppDelete(params) {
540
+ this.txns.push({
541
+ ...params,
542
+ type: "appCall",
543
+ onComplete: algosdk.default.OnApplicationComplete.DeleteApplicationOC
544
+ });
545
+ return this;
546
+ }
547
+ /**
548
+ * Add an application call transaction to the transaction group.
549
+ *
550
+ * If you want to create or update an app use `addAppCreate` or `addAppUpdate`.
551
+ *
552
+ * Note: we recommend using app clients to make it easier to make app calls.
553
+ * @param params The application call transaction parameters
554
+ * @returns The composer so you can chain method calls
555
+ * @example Basic example
556
+ * ```typescript
557
+ * composer.addAppCall({ sender: 'CREATORADDRESS' })
558
+ * ```
559
+ * @example Advanced example
560
+ * ```typescript
561
+ * composer.addAppCall({
562
+ * sender: 'CREATORADDRESS',
563
+ * onComplete: algosdk.OnApplicationComplete.OptInOC,
564
+ * args: [new Uint8Array(1, 2, 3, 4)]
565
+ * accountReferences: ["ACCOUNT_1"]
566
+ * appReferences: [123n, 1234n]
567
+ * assetReferences: [12345n]
568
+ * boxReferences: ["box1", {appId: 1234n, name: "box2"}]
569
+ * accessReferences: [{ appId: 1234n }]
570
+ * lease: 'lease',
571
+ * note: 'note',
572
+ * // You wouldn't normally set this field
573
+ * firstValidRound: 1000n,
574
+ * validityWindow: 10,
575
+ * extraFee: (1000).microAlgo(),
576
+ * staticFee: (1000).microAlgo(),
577
+ * // Max fee doesn't make sense with extraFee AND staticFee
578
+ * // already specified, but here for completeness
579
+ * maxFee: (3000).microAlgo(),
580
+ * rejectVersion: 1,
581
+ *})
582
+ * ```
583
+ */
584
+ addAppCall(params) {
585
+ this.txns.push({
586
+ ...params,
587
+ type: "appCall"
588
+ });
589
+ return this;
590
+ }
591
+ /**
592
+ * Add an ABI method create application call transaction to the transaction group.
593
+ *
594
+ * Note: we recommend using app clients to make it easier to make app calls.
595
+ * @param params The ABI create method application call transaction parameters
596
+ * @returns The composer so you can chain method calls
597
+ * @example Basic example
598
+ * ```typescript
599
+ * const method = new ABIMethod({
600
+ * name: 'method',
601
+ * args: [{ name: 'arg1', type: 'string' }],
602
+ * returns: { type: 'string' },
603
+ * })
604
+ * composer.addAppCreateMethodCall({ sender: 'CREATORADDRESS', approvalProgram: 'TEALCODE', clearStateProgram: 'TEALCODE', method: method, args: ["arg1_value"] })
605
+ * ```
606
+ * @example Advanced example
607
+ * ```typescript
608
+ * const method = new ABIMethod({
609
+ * name: 'method',
610
+ * args: [{ name: 'arg1', type: 'string' }],
611
+ * returns: { type: 'string' },
612
+ * })
613
+ * composer.addAppCreateMethodCall({
614
+ * sender: 'CREATORADDRESS',
615
+ * method: method,
616
+ * args: ["arg1_value"],
617
+ * approvalProgram: "TEALCODE",
618
+ * clearStateProgram: "TEALCODE",
619
+ * schema: {
620
+ * globalInts: 1,
621
+ * globalByteSlices: 2,
622
+ * localInts: 3,
623
+ * localByteSlices: 4
624
+ * },
625
+ * extraProgramPages: 1,
626
+ * onComplete: algosdk.OnApplicationComplete.OptInOC,
627
+ * args: [new Uint8Array(1, 2, 3, 4)]
628
+ * accountReferences: ["ACCOUNT_1"]
629
+ * appReferences: [123n, 1234n]
630
+ * assetReferences: [12345n]
631
+ * boxReferences: ["box1", {appId: 1234n, name: "box2"}]
632
+ * accessReferences: [{ appId: 1234n }]
633
+ * lease: 'lease',
634
+ * note: 'note',
635
+ * // You wouldn't normally set this field
636
+ * firstValidRound: 1000n,
637
+ * validityWindow: 10,
638
+ * extraFee: (1000).microAlgo(),
639
+ * staticFee: (1000).microAlgo(),
640
+ * // Max fee doesn't make sense with extraFee AND staticFee
641
+ * // already specified, but here for completeness
642
+ * maxFee: (3000).microAlgo(),
643
+ * rejectVersion: 1,
644
+ *})
645
+ * ```
646
+ */
647
+ addAppCreateMethodCall(params) {
648
+ this.txns.push({
649
+ ...params,
650
+ type: "methodCall"
651
+ });
652
+ return this;
653
+ }
654
+ /**
655
+ * Add an ABI method update application call transaction to the transaction group.
656
+ *
657
+ * Note: we recommend using app clients to make it easier to make app calls.
658
+ * @param params The ABI update method application call transaction parameters
659
+ * @returns The composer so you can chain method calls
660
+ * @example Basic example
661
+ * ```typescript
662
+ * const method = new ABIMethod({
663
+ * name: 'method',
664
+ * args: [{ name: 'arg1', type: 'string' }],
665
+ * returns: { type: 'string' },
666
+ * })
667
+ * composer.addAppUpdateMethodCall({ sender: 'CREATORADDRESS', approvalProgram: 'TEALCODE', clearStateProgram: 'TEALCODE', method: method, args: ["arg1_value"] })
668
+ * ```
669
+ * @example Advanced example
670
+ * ```typescript
671
+ * const method = new ABIMethod({
672
+ * name: 'method',
673
+ * args: [{ name: 'arg1', type: 'string' }],
674
+ * returns: { type: 'string' },
675
+ * })
676
+ * composer.addAppUpdateMethodCall({
677
+ * sender: 'CREATORADDRESS',
678
+ * method: method,
679
+ * args: ["arg1_value"],
680
+ * approvalProgram: "TEALCODE",
681
+ * clearStateProgram: "TEALCODE",
682
+ * onComplete: algosdk.OnApplicationComplete.UpdateApplicationOC,
683
+ * args: [new Uint8Array(1, 2, 3, 4)]
684
+ * accountReferences: ["ACCOUNT_1"]
685
+ * appReferences: [123n, 1234n]
686
+ * assetReferences: [12345n]
687
+ * boxReferences: ["box1", {appId: 1234n, name: "box2"}]
688
+ * accessReferences: [{ appId: 1234n }]
689
+ * lease: 'lease',
690
+ * note: 'note',
691
+ * // You wouldn't normally set this field
692
+ * firstValidRound: 1000n,
693
+ * validityWindow: 10,
694
+ * extraFee: (1000).microAlgo(),
695
+ * staticFee: (1000).microAlgo(),
696
+ * // Max fee doesn't make sense with extraFee AND staticFee
697
+ * // already specified, but here for completeness
698
+ * maxFee: (3000).microAlgo(),
699
+ * rejectVersion: 1,
700
+ *})
701
+ * ```
702
+ */
703
+ addAppUpdateMethodCall(params) {
704
+ this.txns.push({
705
+ ...params,
706
+ type: "methodCall",
707
+ onComplete: algosdk.default.OnApplicationComplete.UpdateApplicationOC
708
+ });
709
+ return this;
710
+ }
711
+ /**
712
+ * Add an ABI method delete application call transaction to the transaction group.
713
+ *
714
+ * Note: we recommend using app clients to make it easier to make app calls.
715
+ * @param params The ABI delete method application call transaction parameters
716
+ * @returns The composer so you can chain method calls
717
+ * @example Basic example
718
+ * ```typescript
719
+ * const method = new ABIMethod({
720
+ * name: 'method',
721
+ * args: [{ name: 'arg1', type: 'string' }],
722
+ * returns: { type: 'string' },
723
+ * })
724
+ * composer.addAppDeleteMethodCall({ sender: 'CREATORADDRESS', method: method, args: ["arg1_value"] })
725
+ * ```
726
+ * @example Advanced example
727
+ * ```typescript
728
+ * const method = new ABIMethod({
729
+ * name: 'method',
730
+ * args: [{ name: 'arg1', type: 'string' }],
731
+ * returns: { type: 'string' },
732
+ * })
733
+ * composer.addAppDeleteMethodCall({
734
+ * sender: 'CREATORADDRESS',
735
+ * method: method,
736
+ * args: ["arg1_value"],
737
+ * onComplete: algosdk.OnApplicationComplete.DeleteApplicationOC,
738
+ * args: [new Uint8Array(1, 2, 3, 4)]
739
+ * accountReferences: ["ACCOUNT_1"]
740
+ * appReferences: [123n, 1234n]
741
+ * assetReferences: [12345n]
742
+ * boxReferences: ["box1", {appId: 1234n, name: "box2"}]
743
+ * accessReferences: [{ appId: 1234n }]
744
+ * lease: 'lease',
745
+ * note: 'note',
746
+ * // You wouldn't normally set this field
747
+ * firstValidRound: 1000n,
748
+ * validityWindow: 10,
749
+ * extraFee: (1000).microAlgo(),
750
+ * staticFee: (1000).microAlgo(),
751
+ * // Max fee doesn't make sense with extraFee AND staticFee
752
+ * // already specified, but here for completeness
753
+ * maxFee: (3000).microAlgo(),
754
+ * rejectVersion: 1,
755
+ *})
756
+ * ```
757
+ */
758
+ addAppDeleteMethodCall(params) {
759
+ this.txns.push({
760
+ ...params,
761
+ type: "methodCall",
762
+ onComplete: algosdk.default.OnApplicationComplete.DeleteApplicationOC
763
+ });
764
+ return this;
765
+ }
766
+ /**
767
+ * Add a non-create/non-update ABI method application call transaction to the transaction group.
768
+ *
769
+ * Note: we recommend using app clients to make it easier to make app calls.
770
+ * @param params The ABI method application call transaction parameters
771
+ * @returns The composer so you can chain method calls
772
+ * @example Basic example
773
+ * ```typescript
774
+ * const method = new ABIMethod({
775
+ * name: 'method',
776
+ * args: [{ name: 'arg1', type: 'string' }],
777
+ * returns: { type: 'string' },
778
+ * })
779
+ * composer.addAppCallMethodCall({ sender: 'CREATORADDRESS', method: method, args: ["arg1_value"] })
780
+ * ```
781
+ * @example Advanced example
782
+ * ```typescript
783
+ * const method = new ABIMethod({
784
+ * name: 'method',
785
+ * args: [{ name: 'arg1', type: 'string' }],
786
+ * returns: { type: 'string' },
787
+ * })
788
+ * composer.addAppCallMethodCall({
789
+ * sender: 'CREATORADDRESS',
790
+ * method: method,
791
+ * args: ["arg1_value"],
792
+ * onComplete: algosdk.OnApplicationComplete.OptInOC,
793
+ * args: [new Uint8Array(1, 2, 3, 4)]
794
+ * accountReferences: ["ACCOUNT_1"]
795
+ * appReferences: [123n, 1234n]
796
+ * assetReferences: [12345n]
797
+ * boxReferences: ["box1", {appId: 1234n, name: "box2"}]
798
+ * accessReferences: [{ appId: 1234n }]
799
+ * lease: 'lease',
800
+ * note: 'note',
801
+ * // You wouldn't normally set this field
802
+ * firstValidRound: 1000n,
803
+ * validityWindow: 10,
804
+ * extraFee: (1000).microAlgo(),
805
+ * staticFee: (1000).microAlgo(),
806
+ * // Max fee doesn't make sense with extraFee AND staticFee
807
+ * // already specified, but here for completeness
808
+ * maxFee: (3000).microAlgo(),
809
+ * rejectVersion: 1,
810
+ *})
811
+ * ```
812
+ */
813
+ addAppCallMethodCall(params) {
814
+ this.txns.push({
815
+ ...params,
816
+ type: "methodCall"
817
+ });
818
+ return this;
819
+ }
820
+ /**
821
+ * Add an online key registration transaction to the transaction group.
822
+ * @param params The online key registration transaction parameters
823
+ * @returns The composer so you can chain method calls
824
+ * @example Basic example
825
+ * ```typescript
826
+ * composer.addOnlineKeyRegistration({
827
+ * sender: 'SENDERADDRESS',
828
+ * voteKey: Uint8Array.from(Buffer.from("voteKeyBase64", 'base64')),
829
+ * selectionKey: Uint8Array.from(Buffer.from("selectionKeyBase64", 'base64')),
830
+ * stateProofKey: Uint8Array.from(Buffer.from("stateProofKeyBase64", 'base64')),
831
+ * voteFirst: 1n,
832
+ * voteLast: 1000n,
833
+ * voteKeyDilution: 1n,
834
+ * })
835
+ * ```
836
+ * @example Advanced example
837
+ * ```typescript
838
+ * composer.addOnlineKeyRegistration({
839
+ * sender: 'SENDERADDRESS',
840
+ * voteKey: Uint8Array.from(Buffer.from("voteKeyBase64", 'base64')),
841
+ * selectionKey: Uint8Array.from(Buffer.from("selectionKeyBase64", 'base64')),
842
+ * stateProofKey: Uint8Array.from(Buffer.from("stateProofKeyBase64", 'base64')),
843
+ * voteFirst: 1n,
844
+ * voteLast: 1000n,
845
+ * voteKeyDilution: 1n,
846
+ * lease: 'lease',
847
+ * note: 'note',
848
+ * // Use this with caution, it's generally better to use algorand.account.rekeyAccount
849
+ * rekeyTo: 'REKEYTOADDRESS',
850
+ * // You wouldn't normally set this field
851
+ * firstValidRound: 1000n,
852
+ * validityWindow: 10,
853
+ * extraFee: (1000).microAlgo(),
854
+ * staticFee: (1000).microAlgo(),
855
+ * // Max fee doesn't make sense with extraFee AND staticFee
856
+ * // already specified, but here for completeness
857
+ * maxFee: (3000).microAlgo(),
858
+ * })
859
+ * ```
860
+ */
861
+ addOnlineKeyRegistration(params) {
862
+ this.txns.push({
863
+ ...params,
864
+ type: "keyReg"
865
+ });
866
+ return this;
867
+ }
868
+ /**
869
+ * Add an offline key registration transaction to the transaction group.
870
+ * @param params The offline key registration transaction parameters
871
+ * @returns The composer so you can chain method calls
872
+ * @example Basic example
873
+ * ```typescript
874
+ * composer.addOfflineKeyRegistration({
875
+ * sender: 'SENDERADDRESS',
876
+ * })
877
+ * ```
878
+ * @example Advanced example
879
+ * ```typescript
880
+ * composer.addOfflineKeyRegistration({
881
+ * sender: 'SENDERADDRESS',
882
+ * lease: 'lease',
883
+ * note: 'note',
884
+ * // Use this with caution, it's generally better to use algorand.account.rekeyAccount
885
+ * rekeyTo: 'REKEYTOADDRESS',
886
+ * // You wouldn't normally set this field
887
+ * firstValidRound: 1000n,
888
+ * validityWindow: 10,
889
+ * extraFee: (1000).microAlgo(),
890
+ * staticFee: (1000).microAlgo(),
891
+ * // Max fee doesn't make sense with extraFee AND staticFee
892
+ * // already specified, but here for completeness
893
+ * maxFee: (3000).microAlgo(),
894
+ * })
895
+ * ```
896
+ */
897
+ addOfflineKeyRegistration(params) {
898
+ this.txns.push({
899
+ ...params,
900
+ type: "keyReg"
901
+ });
902
+ return this;
903
+ }
904
+ /**
905
+ * Add the transactions within an `AtomicTransactionComposer` to the transaction group.
906
+ * @param atc The `AtomicTransactionComposer` to build transactions from and add to the group
907
+ * @returns The composer so you can chain method calls
908
+ * @example
909
+ * ```typescript
910
+ * const atc = new AtomicTransactionComposer()
911
+ * .addPayment({ sender: 'SENDERADDRESS', receiver: 'RECEIVERADDRESS', amount: 1000n })
912
+ * composer.addAtc(atc)
913
+ * ```
914
+ */
915
+ addAtc(atc) {
916
+ this.txns.push({
917
+ atc,
918
+ type: "atc"
919
+ });
920
+ return this;
921
+ }
922
+ /** Build an ATC and return transactions ready to be incorporated into a broader set of transactions this composer is composing */
923
+ buildAtc(atc) {
924
+ return atc.buildGroup().map((ts, idx) => {
925
+ ts.txn.group = void 0;
926
+ if (atc["methodCalls"].get(idx)) return {
927
+ ...ts,
928
+ context: { abiMethod: atc["methodCalls"].get(idx) }
929
+ };
930
+ return {
931
+ ...ts,
932
+ context: {}
933
+ };
934
+ });
935
+ }
936
+ commonTxnBuildStep(buildTxn, params, txnParams) {
937
+ txnParams.suggestedParams = { ...txnParams.suggestedParams };
938
+ if (params.lease) txnParams.lease = require_transaction.encodeLease(params.lease);
939
+ if (params.rekeyTo) txnParams.rekeyTo = address(params.rekeyTo);
940
+ const encoder = new TextEncoder();
941
+ if (params.note) txnParams.note = typeof params.note === "string" ? encoder.encode(params.note) : params.note;
942
+ if (params.firstValidRound) txnParams.suggestedParams.firstValid = params.firstValidRound;
943
+ if (params.lastValidRound) txnParams.suggestedParams.lastValid = params.lastValidRound;
944
+ else {
945
+ const window = params.validityWindow ? BigInt(params.validityWindow) : !this.defaultValidityWindowIsExplicit && require_network_client.genesisIdIsLocalNet(txnParams.suggestedParams.genesisID ?? "unknown") ? 1000n : this.defaultValidityWindow;
946
+ txnParams.suggestedParams.lastValid = BigInt(txnParams.suggestedParams.firstValid) + window;
947
+ }
948
+ if (params.staticFee !== void 0 && params.extraFee !== void 0) throw Error("Cannot set both staticFee and extraFee");
949
+ if (params.staticFee !== void 0) {
950
+ txnParams.suggestedParams.fee = params.staticFee.microAlgo;
951
+ txnParams.suggestedParams.flatFee = true;
952
+ }
953
+ const txn = buildTxn(txnParams);
954
+ if (params.extraFee) txn.fee += params.extraFee.microAlgo;
955
+ if (params.maxFee !== void 0 && txn.fee > params.maxFee.microAlgo) throw Error(`Transaction fee ${txn.fee} µALGO is greater than maxFee ${params.maxFee}`);
956
+ return {
957
+ txn,
958
+ context: { maxFee: params.maxFee !== void 0 && params.maxFee.microAlgo > (params.staticFee?.microAlgo ?? 0n) ? params.maxFee : params.staticFee }
959
+ };
960
+ }
961
+ /**
962
+ * Builds an ABI method call transaction and any other associated transactions represented in the ABI args.
963
+ * @param includeSigner Whether to include the actual signer for the transactions.
964
+ * If you are just building transactions without signers yet then set this to `false`.
965
+ */
966
+ async buildMethodCall(params, suggestedParams, includeSigner) {
967
+ const methodArgs = [];
968
+ const transactionsForGroup = [];
969
+ const isAbiValue = (x) => {
970
+ if (Array.isArray(x)) return x.length == 0 || x.every(isAbiValue);
971
+ return typeof x === "bigint" || typeof x === "boolean" || typeof x === "number" || typeof x === "string" || x instanceof Uint8Array || x instanceof algosdk.default.Address;
972
+ };
973
+ for (let i = (params.args ?? []).length - 1; i >= 0; i--) {
974
+ const arg = params.args[i];
975
+ if (arg === void 0) {
976
+ if (algosdk.default.abiTypeIsTransaction(params.method.args[i].type) && transactionsForGroup.length > 0) {
977
+ const placeholderTransaction = transactionsForGroup.splice(-1, 1)[0];
978
+ methodArgs.push(placeholderTransaction);
979
+ continue;
980
+ }
981
+ throw Error(`No value provided for argument ${i + 1} within call to ${params.method.name}`);
982
+ }
983
+ if (isAbiValue(arg)) {
984
+ methodArgs.push(arg);
985
+ continue;
986
+ }
987
+ if (isTransactionWithSigner(arg)) {
988
+ methodArgs.push(arg);
989
+ continue;
990
+ }
991
+ if ("method" in arg) {
992
+ const tempTxnWithSigners = await this.buildMethodCall(arg, suggestedParams, includeSigner);
993
+ methodArgs.push(...tempTxnWithSigners.slice(-1));
994
+ transactionsForGroup.push(...tempTxnWithSigners.slice(0, -1).reverse());
995
+ continue;
996
+ }
997
+ const txn = await arg;
998
+ methodArgs.push({
999
+ txn,
1000
+ signer: includeSigner ? params.signer ? "signer" in params.signer ? params.signer.signer : params.signer : this.getSigner(txn.sender) : TransactionComposer.NULL_SIGNER
1001
+ });
1002
+ }
1003
+ const methodAtc = new algosdk.default.AtomicTransactionComposer();
1004
+ const maxFees = /* @__PURE__ */ new Map();
1005
+ transactionsForGroup.reverse().forEach(({ context, ...txnWithSigner }) => {
1006
+ methodAtc.addTransaction(txnWithSigner);
1007
+ const atcIndex = methodAtc.count() - 1;
1008
+ if (context.abiMethod) methodAtc["methodCalls"].set(atcIndex, context.abiMethod);
1009
+ if (context.maxFee !== void 0) maxFees.set(atcIndex, context.maxFee);
1010
+ });
1011
+ methodArgs.filter((arg) => {
1012
+ if (typeof arg === "object" && "context" in arg) {
1013
+ const { context, ...txnWithSigner } = arg;
1014
+ return isTransactionWithSigner(txnWithSigner);
1015
+ }
1016
+ return isTransactionWithSigner(arg);
1017
+ }).reverse().forEach((arg, idx) => {
1018
+ if (typeof arg === "object" && "context" in arg && arg.context) {
1019
+ const atcIndex = methodAtc.count() + idx;
1020
+ if (arg.context.abiMethod) methodAtc["methodCalls"].set(atcIndex, arg.context.abiMethod);
1021
+ if (arg.context.maxFee !== void 0) maxFees.set(atcIndex, arg.context.maxFee);
1022
+ }
1023
+ });
1024
+ const appId = Number("appId" in params ? params.appId : 0n);
1025
+ const approvalProgram = "approvalProgram" in params ? typeof params.approvalProgram === "string" ? (await this.appManager.compileTeal(params.approvalProgram)).compiledBase64ToBytes : params.approvalProgram : void 0;
1026
+ const clearStateProgram = "clearStateProgram" in params ? typeof params.clearStateProgram === "string" ? (await this.appManager.compileTeal(params.clearStateProgram)).compiledBase64ToBytes : params.clearStateProgram : void 0;
1027
+ const txnParams = {
1028
+ appID: appId,
1029
+ sender: params.sender,
1030
+ suggestedParams,
1031
+ onComplete: params.onComplete ?? algosdk.default.OnApplicationComplete.NoOpOC,
1032
+ appAccounts: params.accountReferences,
1033
+ appForeignApps: params.appReferences?.map((x) => Number(x)),
1034
+ appForeignAssets: params.assetReferences?.map((x) => Number(x)),
1035
+ boxes: params.boxReferences?.map(require_app_manager.AppManager.getBoxReference),
1036
+ access: params.accessReferences?.map(getResourceReference),
1037
+ approvalProgram,
1038
+ clearProgram: clearStateProgram,
1039
+ extraPages: appId === 0 ? "extraProgramPages" in params && params.extraProgramPages !== void 0 ? params.extraProgramPages : approvalProgram ? require_util.calculateExtraProgramPages(approvalProgram, clearStateProgram) : 0 : void 0,
1040
+ numLocalInts: appId === 0 ? "schema" in params ? params.schema?.localInts ?? 0 : 0 : void 0,
1041
+ numLocalByteSlices: appId === 0 ? "schema" in params ? params.schema?.localByteSlices ?? 0 : 0 : void 0,
1042
+ numGlobalInts: appId === 0 ? "schema" in params ? params.schema?.globalInts ?? 0 : 0 : void 0,
1043
+ numGlobalByteSlices: appId === 0 ? "schema" in params ? params.schema?.globalByteSlices ?? 0 : 0 : void 0,
1044
+ method: params.method,
1045
+ signer: includeSigner ? params.signer ? "signer" in params.signer ? params.signer.signer : params.signer : this.getSigner(params.sender) : TransactionComposer.NULL_SIGNER,
1046
+ methodArgs: methodArgs.map((arg) => {
1047
+ if (typeof arg === "object" && "context" in arg) {
1048
+ const { context, ...txnWithSigner } = arg;
1049
+ return txnWithSigner;
1050
+ }
1051
+ return arg;
1052
+ }).reverse(),
1053
+ rejectVersion: params.rejectVersion,
1054
+ note: void 0,
1055
+ lease: void 0,
1056
+ rekeyTo: void 0
1057
+ };
1058
+ const result = this.commonTxnBuildStep((txnParams) => {
1059
+ methodAtc.addMethodCall(txnParams);
1060
+ return methodAtc.buildGroup()[methodAtc.count() - 1].txn;
1061
+ }, params, txnParams);
1062
+ return this.buildAtc(methodAtc).map(({ context: _context, ...txnWithSigner }, idx) => {
1063
+ const maxFee = idx === methodAtc.count() - 1 ? result.context.maxFee : maxFees.get(idx);
1064
+ const context = {
1065
+ ..._context,
1066
+ maxFee
1067
+ };
1068
+ return {
1069
+ ...txnWithSigner,
1070
+ context
1071
+ };
1072
+ });
1073
+ }
1074
+ buildPayment(params, suggestedParams) {
1075
+ return this.commonTxnBuildStep(algosdk.default.makePaymentTxnWithSuggestedParamsFromObject, params, {
1076
+ sender: params.sender,
1077
+ receiver: params.receiver,
1078
+ amount: params.amount.microAlgo,
1079
+ closeRemainderTo: params.closeRemainderTo,
1080
+ suggestedParams
1081
+ });
1082
+ }
1083
+ buildAssetCreate(params, suggestedParams) {
1084
+ return this.commonTxnBuildStep(algosdk.default.makeAssetCreateTxnWithSuggestedParamsFromObject, params, {
1085
+ sender: params.sender,
1086
+ total: params.total,
1087
+ decimals: params.decimals ?? 0,
1088
+ assetName: params.assetName,
1089
+ unitName: params.unitName,
1090
+ assetURL: params.url,
1091
+ defaultFrozen: params.defaultFrozen ?? false,
1092
+ assetMetadataHash: typeof params.metadataHash === "string" ? Buffer.from(params.metadataHash, "utf-8") : params.metadataHash,
1093
+ manager: params.manager,
1094
+ reserve: params.reserve,
1095
+ freeze: params.freeze,
1096
+ clawback: params.clawback,
1097
+ suggestedParams
1098
+ });
1099
+ }
1100
+ buildAssetConfig(params, suggestedParams) {
1101
+ return this.commonTxnBuildStep(algosdk.default.makeAssetConfigTxnWithSuggestedParamsFromObject, params, {
1102
+ sender: params.sender,
1103
+ assetIndex: params.assetId,
1104
+ suggestedParams,
1105
+ manager: params.manager,
1106
+ reserve: params.reserve,
1107
+ freeze: params.freeze,
1108
+ clawback: params.clawback,
1109
+ strictEmptyAddressChecking: false
1110
+ });
1111
+ }
1112
+ buildAssetDestroy(params, suggestedParams) {
1113
+ return this.commonTxnBuildStep(algosdk.default.makeAssetDestroyTxnWithSuggestedParamsFromObject, params, {
1114
+ sender: params.sender,
1115
+ assetIndex: params.assetId,
1116
+ suggestedParams
1117
+ });
1118
+ }
1119
+ buildAssetFreeze(params, suggestedParams) {
1120
+ return this.commonTxnBuildStep(algosdk.default.makeAssetFreezeTxnWithSuggestedParamsFromObject, params, {
1121
+ sender: params.sender,
1122
+ assetIndex: params.assetId,
1123
+ freezeTarget: params.account,
1124
+ frozen: params.frozen,
1125
+ suggestedParams
1126
+ });
1127
+ }
1128
+ buildAssetTransfer(params, suggestedParams) {
1129
+ return this.commonTxnBuildStep(algosdk.default.makeAssetTransferTxnWithSuggestedParamsFromObject, params, {
1130
+ sender: params.sender,
1131
+ receiver: params.receiver,
1132
+ assetIndex: params.assetId,
1133
+ amount: params.amount,
1134
+ suggestedParams,
1135
+ closeRemainderTo: params.closeAssetTo,
1136
+ assetSender: params.clawbackTarget
1137
+ });
1138
+ }
1139
+ async buildAppCall(params, suggestedParams) {
1140
+ const appId = "appId" in params ? params.appId : 0n;
1141
+ const approvalProgram = "approvalProgram" in params ? typeof params.approvalProgram === "string" ? (await this.appManager.compileTeal(params.approvalProgram)).compiledBase64ToBytes : params.approvalProgram : void 0;
1142
+ const clearStateProgram = "clearStateProgram" in params ? typeof params.clearStateProgram === "string" ? (await this.appManager.compileTeal(params.clearStateProgram)).compiledBase64ToBytes : params.clearStateProgram : void 0;
1143
+ const sdkParams = {
1144
+ sender: params.sender,
1145
+ suggestedParams,
1146
+ appArgs: params.args,
1147
+ onComplete: params.onComplete ?? algosdk.default.OnApplicationComplete.NoOpOC,
1148
+ accounts: params.accountReferences,
1149
+ foreignApps: params.appReferences?.map((x) => Number(x)),
1150
+ foreignAssets: params.assetReferences?.map((x) => Number(x)),
1151
+ boxes: params.boxReferences?.map(require_app_manager.AppManager.getBoxReference),
1152
+ access: params.accessReferences?.map(getResourceReference),
1153
+ approvalProgram,
1154
+ clearProgram: clearStateProgram,
1155
+ rejectVersion: params.rejectVersion
1156
+ };
1157
+ if (appId === 0n) {
1158
+ if (sdkParams.approvalProgram === void 0 || sdkParams.clearProgram === void 0) throw new Error("approvalProgram and clearStateProgram are required for application creation");
1159
+ return this.commonTxnBuildStep(algosdk.default.makeApplicationCreateTxnFromObject, params, {
1160
+ ...sdkParams,
1161
+ extraPages: "extraProgramPages" in params && params.extraProgramPages !== void 0 ? params.extraProgramPages : require_util.calculateExtraProgramPages(approvalProgram, clearStateProgram),
1162
+ numLocalInts: "schema" in params ? params.schema?.localInts ?? 0 : 0,
1163
+ numLocalByteSlices: "schema" in params ? params.schema?.localByteSlices ?? 0 : 0,
1164
+ numGlobalInts: "schema" in params ? params.schema?.globalInts ?? 0 : 0,
1165
+ numGlobalByteSlices: "schema" in params ? params.schema?.globalByteSlices ?? 0 : 0,
1166
+ approvalProgram,
1167
+ clearProgram: clearStateProgram
1168
+ });
1169
+ } else return this.commonTxnBuildStep(algosdk.default.makeApplicationCallTxnFromObject, params, {
1170
+ ...sdkParams,
1171
+ appIndex: appId
1172
+ });
1173
+ }
1174
+ buildKeyReg(params, suggestedParams) {
1175
+ if ("voteKey" in params) return this.commonTxnBuildStep(algosdk.default.makeKeyRegistrationTxnWithSuggestedParamsFromObject, params, {
1176
+ sender: params.sender,
1177
+ voteKey: params.voteKey,
1178
+ selectionKey: params.selectionKey,
1179
+ voteFirst: params.voteFirst,
1180
+ voteLast: params.voteLast,
1181
+ voteKeyDilution: params.voteKeyDilution,
1182
+ suggestedParams,
1183
+ nonParticipation: false,
1184
+ stateProofKey: params.stateProofKey
1185
+ });
1186
+ return this.commonTxnBuildStep(algosdk.default.makeKeyRegistrationTxnWithSuggestedParamsFromObject, params, {
1187
+ sender: params.sender,
1188
+ suggestedParams,
1189
+ nonParticipation: params.preventAccountFromEverParticipatingAgain
1190
+ });
1191
+ }
1192
+ /** Builds all transaction types apart from `txnWithSigner`, `atc` and `methodCall` since those ones can have custom signers that need to be retrieved. */
1193
+ async buildTxn(txn, suggestedParams) {
1194
+ switch (txn.type) {
1195
+ case "pay": return [this.buildPayment(txn, suggestedParams)];
1196
+ case "assetCreate": return [this.buildAssetCreate(txn, suggestedParams)];
1197
+ case "appCall": return [await this.buildAppCall(txn, suggestedParams)];
1198
+ case "assetConfig": return [this.buildAssetConfig(txn, suggestedParams)];
1199
+ case "assetDestroy": return [this.buildAssetDestroy(txn, suggestedParams)];
1200
+ case "assetFreeze": return [this.buildAssetFreeze(txn, suggestedParams)];
1201
+ case "assetTransfer": return [this.buildAssetTransfer(txn, suggestedParams)];
1202
+ case "assetOptIn": return [this.buildAssetTransfer({
1203
+ ...txn,
1204
+ receiver: txn.sender,
1205
+ amount: 0n
1206
+ }, suggestedParams)];
1207
+ case "assetOptOut": return [this.buildAssetTransfer({
1208
+ ...txn,
1209
+ receiver: txn.sender,
1210
+ amount: 0n,
1211
+ closeAssetTo: txn.creator
1212
+ }, suggestedParams)];
1213
+ case "keyReg": return [this.buildKeyReg(txn, suggestedParams)];
1214
+ default: throw Error(`Unsupported txn type`);
1215
+ }
1216
+ }
1217
+ async buildTxnWithSigner(txn, suggestedParams) {
1218
+ if (txn.type === "txnWithSigner") return [{
1219
+ ...txn,
1220
+ context: {}
1221
+ }];
1222
+ if (txn.type === "atc") return this.buildAtc(txn.atc);
1223
+ if (txn.type === "methodCall") return await this.buildMethodCall(txn, suggestedParams, true);
1224
+ const signer = txn.signer ? "signer" in txn.signer ? txn.signer.signer : txn.signer : this.getSigner(txn.sender);
1225
+ return (await this.buildTxn(txn, suggestedParams)).map(({ txn, context }) => ({
1226
+ txn,
1227
+ signer,
1228
+ context
1229
+ }));
1230
+ }
1231
+ /**
1232
+ * Compose all of the transactions without signers and return the transaction objects directly along with any ABI method calls.
1233
+ *
1234
+ * @returns The array of built transactions and any corresponding method calls
1235
+ * @example
1236
+ * ```typescript
1237
+ * const { transactions, methodCalls, signers } = await composer.buildTransactions()
1238
+ * ```
1239
+ */
1240
+ async buildTransactions() {
1241
+ const suggestedParams = await this.getSuggestedParams();
1242
+ const transactions = [];
1243
+ const methodCalls = /* @__PURE__ */ new Map();
1244
+ const signers = /* @__PURE__ */ new Map();
1245
+ for (const txn of this.txns) if (![
1246
+ "txnWithSigner",
1247
+ "atc",
1248
+ "methodCall"
1249
+ ].includes(txn.type)) transactions.push(...(await this.buildTxn(txn, suggestedParams)).map((txn) => txn.txn));
1250
+ else (txn.type === "txnWithSigner" ? [txn] : txn.type === "atc" ? this.buildAtc(txn.atc) : txn.type === "methodCall" ? await this.buildMethodCall(txn, suggestedParams, false) : []).forEach((ts) => {
1251
+ transactions.push(ts.txn);
1252
+ const groupIdx = transactions.length - 1;
1253
+ if (ts.signer && ts.signer !== TransactionComposer.NULL_SIGNER) signers.set(groupIdx, ts.signer);
1254
+ if ("context" in ts && ts.context.abiMethod) methodCalls.set(groupIdx, ts.context.abiMethod);
1255
+ });
1256
+ return {
1257
+ transactions,
1258
+ methodCalls,
1259
+ signers
1260
+ };
1261
+ }
1262
+ /**
1263
+ * Get the number of transactions currently added to this composer.
1264
+ * @returns The number of transactions currently added to this composer
1265
+ */
1266
+ async count() {
1267
+ return (await this.buildTransactions()).transactions.length;
1268
+ }
1269
+ /**
1270
+ * Compose all of the transactions in a single atomic transaction group and an atomic transaction composer.
1271
+ *
1272
+ * You can then use the transactions standalone, or use the composer to execute or simulate the transactions.
1273
+ *
1274
+ * Once this method is called, no further transactions will be able to be added.
1275
+ * You can safely call this method multiple times to get the same result.
1276
+ * @returns The built atomic transaction composer, the transactions and any corresponding method calls
1277
+ * @example
1278
+ * ```typescript
1279
+ * const { atc, transactions, methodCalls } = await composer.build()
1280
+ * ```
1281
+ */
1282
+ async build() {
1283
+ if (this.atc.getStatus() === algosdk.default.AtomicTransactionComposerStatus.BUILDING) {
1284
+ const suggestedParams = await this.getSuggestedParams();
1285
+ const txnWithSigners = [];
1286
+ for (const txn of this.txns) txnWithSigners.push(...await this.buildTxnWithSigner(txn, suggestedParams));
1287
+ const methodCalls = /* @__PURE__ */ new Map();
1288
+ txnWithSigners.forEach(({ context, ...ts }, idx) => {
1289
+ this.atc.addTransaction(ts);
1290
+ if (context.abiMethod) methodCalls.set(idx, context.abiMethod);
1291
+ if (context.maxFee !== void 0) this.txnMaxFees.set(idx, context.maxFee);
1292
+ });
1293
+ this.atc["methodCalls"] = methodCalls;
1294
+ }
1295
+ const transactions = this.atc.buildGroup();
1296
+ return {
1297
+ atc: this.atc,
1298
+ transactions,
1299
+ methodCalls: this.atc["methodCalls"]
1300
+ };
1301
+ }
1302
+ /**
1303
+ * Rebuild the group, discarding any previously built transactions.
1304
+ * This will potentially cause new signers and suggested params to be used if the callbacks return a new value compared to the first build.
1305
+ * @returns The newly built atomic transaction composer and the transactions
1306
+ * @example
1307
+ * ```typescript
1308
+ * const { atc, transactions, methodCalls } = await composer.rebuild()
1309
+ * ```
1310
+ */
1311
+ async rebuild() {
1312
+ this.atc = new algosdk.default.AtomicTransactionComposer();
1313
+ return await this.build();
1314
+ }
1315
+ /**
1316
+ * Compose the atomic transaction group and send it to the network.
1317
+ * @param params The parameters to control execution with
1318
+ * @returns The execution result
1319
+ * @example
1320
+ * ```typescript
1321
+ * const result = await composer.send()
1322
+ * ```
1323
+ */
1324
+ async send(params) {
1325
+ const group = (await this.build()).transactions;
1326
+ let waitRounds = params?.maxRoundsToWaitForConfirmation;
1327
+ const suggestedParams = waitRounds === void 0 || params?.coverAppCallInnerTransactionFees ? await this.getSuggestedParams() : void 0;
1328
+ if (waitRounds === void 0) {
1329
+ const lastRound = group.reduce((max, txn) => txn.txn.lastValid > max ? txn.txn.lastValid : BigInt(max), 0n);
1330
+ const { firstValid: firstRound } = suggestedParams;
1331
+ waitRounds = Number(BigInt(lastRound) - BigInt(firstRound)) + 1;
1332
+ }
1333
+ try {
1334
+ return await require_transaction.sendAtomicTransactionComposer({
1335
+ atc: this.atc,
1336
+ suppressLog: params?.suppressLog,
1337
+ maxRoundsToWaitForConfirmation: waitRounds,
1338
+ populateAppCallResources: params?.populateAppCallResources,
1339
+ coverAppCallInnerTransactionFees: params?.coverAppCallInnerTransactionFees,
1340
+ additionalAtcContext: params?.coverAppCallInnerTransactionFees ? {
1341
+ maxFees: this.txnMaxFees,
1342
+ suggestedParams
1343
+ } : void 0
1344
+ }, this.algod);
1345
+ } catch (originalError) {
1346
+ throw await this.transformError(originalError);
1347
+ }
1348
+ }
1349
+ /**
1350
+ * @deprecated Use `send` instead.
1351
+ *
1352
+ * Compose the atomic transaction group and send it to the network
1353
+ *
1354
+ * An alias for `composer.send(params)`.
1355
+ * @param params The parameters to control execution with
1356
+ * @returns The execution result
1357
+ */
1358
+ async execute(params) {
1359
+ return this.send(params);
1360
+ }
1361
+ async simulate(options) {
1362
+ const { skipSignatures = false, ...rawOptions } = options ?? {};
1363
+ const atc = skipSignatures ? new AtomicTransactionComposer() : this.atc;
1364
+ if (skipSignatures) {
1365
+ rawOptions.allowEmptySignatures = true;
1366
+ rawOptions.fixSigners = true;
1367
+ const transactions = await this.buildTransactions();
1368
+ for (const txn of transactions.transactions) atc.addTransaction({
1369
+ txn,
1370
+ signer: TransactionComposer.NULL_SIGNER
1371
+ });
1372
+ atc["methodCalls"] = transactions.methodCalls;
1373
+ } else await this.build();
1374
+ const { methodResults, simulateResponse } = await atc.simulate(this.algod, new modelsv2.SimulateRequest({
1375
+ txnGroups: [],
1376
+ ...rawOptions,
1377
+ ...require_config.Config.debug ? {
1378
+ allowEmptySignatures: true,
1379
+ fixSigners: true,
1380
+ allowMoreLogging: true,
1381
+ execTraceConfig: new modelsv2.SimulateTraceConfig({
1382
+ enable: true,
1383
+ scratchChange: true,
1384
+ stackChange: true,
1385
+ stateChange: true
1386
+ })
1387
+ } : void 0
1388
+ }));
1389
+ const failedGroup = simulateResponse?.txnGroups[0];
1390
+ if (failedGroup?.failureMessage) {
1391
+ const errorMessage = `Transaction failed at transaction(s) ${failedGroup.failedAt?.join(", ") || "unknown"} in the group. ${failedGroup.failureMessage}`;
1392
+ const error = new Error(errorMessage);
1393
+ if (require_config.Config.debug) await require_config.Config.events.emitAsync("TxnGroupSimulated", { simulateResponse });
1394
+ throw await this.transformError(error);
1395
+ }
1396
+ if (require_config.Config.debug && require_config.Config.traceAll) await require_config.Config.events.emitAsync("TxnGroupSimulated", { simulateResponse });
1397
+ const transactions = atc.buildGroup().map((t) => t.txn);
1398
+ const methodCalls = [...atc["methodCalls"].values()];
1399
+ return {
1400
+ confirmations: simulateResponse.txnGroups[0].txnResults.map((t) => t.txnResult),
1401
+ transactions,
1402
+ txIds: transactions.map((t) => t.txID()),
1403
+ groupId: Buffer.from(transactions[0].group ?? /* @__PURE__ */ new Uint8Array()).toString("base64"),
1404
+ simulateResponse,
1405
+ returns: methodResults.map((r, i) => require_transaction.getABIReturnValue(r, methodCalls[i].returns.type))
1406
+ };
1407
+ }
1408
+ /**
1409
+ * Create an encoded transaction note that follows the ARC-2 spec.
1410
+ *
1411
+ * https://github.com/algorandfoundation/ARCs/blob/main/ARCs/arc-0002.md
1412
+ * @param note The ARC-2 transaction note data
1413
+ * @returns The binary encoded transaction note
1414
+ */
1415
+ static arc2Note(note) {
1416
+ const arc2Payload = `${note.dAppName}:${note.format}${typeof note.data === "string" ? note.data : require_util.asJson(note.data)}`;
1417
+ return new TextEncoder().encode(arc2Payload);
1418
+ }
1419
+ };
1483
1420
  /**
1484
- * Returns an `algosdk.TransactionResourceReference` given a `ResourceReference`.
1485
- */
1421
+ * Returns an `algosdk.TransactionResourceReference` given a `ResourceReference`.
1422
+ */
1486
1423
  function getResourceReference(accessReference) {
1487
- return {
1488
- address: typeof accessReference.address === 'string' ? algosdk.Address.fromString(accessReference.address) : accessReference.address,
1489
- appIndex: accessReference.appId,
1490
- assetIndex: accessReference.assetId,
1491
- holding: accessReference.holding ? getHoldingReference(accessReference.holding) : undefined,
1492
- locals: accessReference.locals ? getLocalsReference(accessReference.locals) : undefined,
1493
- box: accessReference.box ? types_appManager.AppManager.getBoxReference(accessReference.box) : undefined,
1494
- };
1424
+ return {
1425
+ address: typeof accessReference.address === "string" ? algosdk.Address.fromString(accessReference.address) : accessReference.address,
1426
+ appIndex: accessReference.appId,
1427
+ assetIndex: accessReference.assetId,
1428
+ holding: accessReference.holding ? getHoldingReference(accessReference.holding) : void 0,
1429
+ locals: accessReference.locals ? getLocalsReference(accessReference.locals) : void 0,
1430
+ box: accessReference.box ? require_app_manager.AppManager.getBoxReference(accessReference.box) : void 0
1431
+ };
1495
1432
  }
1496
1433
  function getHoldingReference(holdingReference) {
1497
- return {
1498
- assetIndex: holdingReference.assetId,
1499
- address: typeof holdingReference.address === 'string' ? algosdk.Address.fromString(holdingReference.address) : holdingReference.address,
1500
- };
1434
+ return {
1435
+ assetIndex: holdingReference.assetId,
1436
+ address: typeof holdingReference.address === "string" ? algosdk.Address.fromString(holdingReference.address) : holdingReference.address
1437
+ };
1501
1438
  }
1502
1439
  function getLocalsReference(localsReference) {
1503
- return {
1504
- appIndex: localsReference.appId,
1505
- address: typeof localsReference.address === 'string' ? algosdk.Address.fromString(localsReference.address) : localsReference.address,
1506
- };
1440
+ return {
1441
+ appIndex: localsReference.appId,
1442
+ address: typeof localsReference.address === "string" ? algosdk.Address.fromString(localsReference.address) : localsReference.address
1443
+ };
1507
1444
  }
1508
-
1445
+ //#endregion
1509
1446
  exports.MAX_TRANSACTION_GROUP_SIZE = MAX_TRANSACTION_GROUP_SIZE;
1510
1447
  exports.TransactionComposer = TransactionComposer;
1511
- //# sourceMappingURL=composer.js.map
1448
+
1449
+ //# sourceMappingURL=composer.js.map