@algorandfoundation/algokit-utils 9.2.0 → 9.2.1-beta.2

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
@@ -1,607 +1,596 @@
1
- 'use strict';
2
-
3
- var algosdk = require('algosdk');
4
- var config = require('../config.js');
5
- var util = require('../util.js');
6
- var types_account = require('./account.js');
7
- var types_amount = require('./amount.js');
8
- var types_composer = require('./composer.js');
9
- var types_kmdAccountManager = require('./kmd-account-manager.js');
10
-
11
- var LogicSigAccount = algosdk.LogicSigAccount;
12
- const address = (address) => (typeof address === 'string' ? algosdk.Address.fromString(address) : address);
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
+ const require_util = require("../util.js");
5
+ const require_account = require("./account.js");
6
+ const require_amount = require("./amount.js");
7
+ const require_composer = require("./composer.js");
8
+ const require_kmd_account_manager = require("./kmd-account-manager.js");
9
+ let algosdk = require("algosdk");
10
+ algosdk = require_runtime.__toESM(algosdk);
11
+ //#region src/types/account-manager.ts
12
+ var LogicSigAccount = algosdk.default.LogicSigAccount;
13
+ const address = (address) => typeof address === "string" ? algosdk.Address.fromString(address) : address;
13
14
  /**
14
- * Returns a `TransactionSigner` for the given account that can sign a transaction.
15
- * This function has memoization, so will return the same transaction signer for a given account.
16
- * @param account An account that can sign a transaction
17
- * @returns A transaction signer
18
- * @example
19
- * ```typescript
20
- * const signer = getAccountTransactionSigner(account)
21
- * ```
22
- */
23
- const getAccountTransactionSigner = util.memoize(function (account) {
24
- return 'signer' in account
25
- ? account.signer
26
- : 'lsig' in account
27
- ? algosdk.makeLogicSigAccountTransactionSigner(account)
28
- : algosdk.makeBasicAccountTransactionSigner(account);
15
+ * Returns a `TransactionSigner` for the given account that can sign a transaction.
16
+ * This function has memoization, so will return the same transaction signer for a given account.
17
+ * @param account An account that can sign a transaction
18
+ * @returns A transaction signer
19
+ * @example
20
+ * ```typescript
21
+ * const signer = getAccountTransactionSigner(account)
22
+ * ```
23
+ */
24
+ const getAccountTransactionSigner = require_util.memoize(function(account) {
25
+ return "signer" in account ? account.signer : "lsig" in account ? algosdk.default.makeLogicSigAccountTransactionSigner(account) : algosdk.default.makeBasicAccountTransactionSigner(account);
29
26
  });
30
27
  /** Creates and keeps track of signing accounts that can sign transactions for a sending address. */
31
- class AccountManager {
32
- /**
33
- * Create a new account manager.
34
- * @param clientManager The ClientManager client to use for algod and kmd clients
35
- * @example Create a new account manager
36
- * ```typescript
37
- * const accountManager = new AccountManager(clientManager)
38
- * ```
39
- */
40
- constructor(clientManager) {
41
- this._accounts = {};
42
- this._clientManager = clientManager;
43
- this._kmdAccountManager = new types_kmdAccountManager.KmdAccountManager(clientManager);
44
- }
45
- _getComposer(getSuggestedParams) {
46
- return new types_composer.TransactionComposer({
47
- algod: this._clientManager.algod,
48
- getSigner: this.getSigner.bind(this),
49
- getSuggestedParams: getSuggestedParams ?? (() => this._clientManager.algod.getTransactionParams().do()),
50
- });
51
- }
52
- /**
53
- * KMD account manager that allows you to easily get and create accounts using KMD.
54
- * @returns The `KmdAccountManager` instance.
55
- * @example
56
- * ```typescript
57
- * const kmdManager = accountManager.kmd;
58
- * ```
59
- */
60
- get kmd() {
61
- return this._kmdAccountManager;
62
- }
63
- /**
64
- * Sets the default signer to use if no other signer is specified.
65
- *
66
- * If this isn't set an a transaction needs signing for a given sender
67
- * then an error will be thrown from `getSigner` / `getAccount`.
68
- * @param signer The signer to use, either a `TransactionSigner` or a `TransactionSignerAccount`
69
- * @example
70
- * ```typescript
71
- * const signer = accountManager.random() // Can be anything that returns a `algosdk.TransactionSigner` or `TransactionSignerAccount`
72
- * accountManager.setDefaultSigner(signer)
73
- *
74
- * // When signing a transaction, if there is no signer registered for the sender then the default signer will be used
75
- * const signer = accountManager.getSigner("SENDERADDRESS")
76
- * ```
77
- * @returns The `AccountManager` so method calls can be chained
78
- */
79
- setDefaultSigner(signer) {
80
- this._defaultSigner = 'signer' in signer ? signer.signer : signer;
81
- return this;
82
- }
83
- /**
84
- * Records the given account (that can sign) against the address of the provided account for later
85
- * retrieval and returns a `TransactionSignerAccount` along with the original account in an `account` property.
86
- */
87
- signerAccount(account) {
88
- const signer = getAccountTransactionSigner(account);
89
- const acc = {
90
- addr: 'addr' in account ? account.addr : account.address(),
91
- signer: signer,
92
- };
93
- this._accounts[acc.addr.toString()] = acc;
94
- const addressWithAccount = algosdk.Address.fromString(acc.addr.toString());
95
- addressWithAccount.account = account;
96
- addressWithAccount.addr = acc.addr;
97
- addressWithAccount.signer = signer;
98
- return addressWithAccount;
99
- }
100
- /**
101
- * Tracks the given account for later signing.
102
- *
103
- * Note: If you are generating accounts via the various methods on `AccountManager`
104
- * (like `random`, `fromMnemonic`, `logicsig`, etc.) then they automatically get tracked.
105
- * @param account The account to register, which can be a `TransactionSignerAccount` or
106
- * a `algosdk.Account`, `algosdk.LogicSigAccount`, `SigningAccount` or `MultisigAccount`
107
- * @example
108
- * ```typescript
109
- * const accountManager = new AccountManager(clientManager)
110
- * .setSignerFromAccount(algosdk.generateAccount())
111
- * .setSignerFromAccount(new algosdk.LogicSigAccount(program, args))
112
- * .setSignerFromAccount(new SigningAccount(mnemonic, sender))
113
- * .setSignerFromAccount(new MultisigAccount({version: 1, threshold: 1, addrs: ["ADDRESS1...", "ADDRESS2..."]}, [account1, account2]))
114
- * .setSignerFromAccount({addr: "SENDERADDRESS", signer: transactionSigner})
115
- * ```
116
- * @returns The `AccountManager` instance for method chaining
117
- */
118
- setSignerFromAccount(account) {
119
- this.signerAccount(account);
120
- return this;
121
- }
122
- /**
123
- * Tracks the given `algosdk.TransactionSigner` against the given sender address for later signing.
124
- * @param sender The sender address to use this signer for
125
- * @param signer The `algosdk.TransactionSigner` to sign transactions with for the given sender
126
- * @example
127
- * ```typescript
128
- * const accountManager = new AccountManager(clientManager)
129
- * .setSigner("SENDERADDRESS", transactionSigner)
130
- * ```
131
- * @returns The `AccountManager` instance for method chaining
132
- */
133
- setSigner(sender, signer) {
134
- this._accounts[address(sender).toString()] = { addr: address(sender), signer };
135
- return this;
136
- }
137
- /**
138
- * Takes all registered signers from the given `AccountManager` and adds them to this `AccountManager`.
139
- *
140
- * This is useful for situations where you have multiple contexts you are building accounts in such as unit tests.
141
- * @param anotherAccountManager Another account manager with signers registered
142
- * @param overwriteExisting Whether or not to overwrite any signers that have the same sender address with the ones in the other account manager or not (default: true)
143
- * @returns The `AccountManager` instance for method chaining
144
- * @example
145
- * ```typescript
146
- * accountManager2.setSigners(accountManager1);
147
- * ```
148
- */
149
- setSigners(anotherAccountManager, overwriteExisting = true) {
150
- this._accounts = overwriteExisting
151
- ? { ...this._accounts, ...anotherAccountManager._accounts }
152
- : { ...anotherAccountManager._accounts, ...this._accounts };
153
- return this;
154
- }
155
- /**
156
- * Returns the `TransactionSigner` for the given sender address, ready to sign a transaction for that sender.
157
- *
158
- * If no signer has been registered for that address then the default signer is used if registered and
159
- * if not then an error is thrown.
160
- *
161
- * @param sender The sender address
162
- * @example
163
- * ```typescript
164
- * const signer = accountManager.getSigner("SENDERADDRESS")
165
- * ```
166
- * @returns The `TransactionSigner` or throws an error if not found and no default signer is set
167
- */
168
- getSigner(sender) {
169
- const signer = this._accounts[address(sender).toString()]?.signer ?? this._defaultSigner;
170
- if (!signer)
171
- throw new Error(`No signer found for address ${sender}`);
172
- return signer;
173
- }
174
- /**
175
- * Returns the `TransactionSignerAccount` for the given sender address.
176
- *
177
- * If no signer has been registered for that address then an error is thrown.
178
- * @param sender The sender address
179
- * @example
180
- * ```typescript
181
- * const sender = accountManager.random()
182
- * // ...
183
- * // Returns the `TransactionSignerAccount` for `sender` that has previously been registered
184
- * const account = accountManager.getAccount(sender)
185
- * ```
186
- * @returns The `TransactionSignerAccount` or throws an error if not found
187
- */
188
- getAccount(sender) {
189
- const account = this._accounts[address(sender).toString()];
190
- if (!account)
191
- throw new Error(`No signer found for address ${sender}`);
192
- return account;
193
- }
194
- /**
195
- * Returns the given sender account's current status, balance and spendable amounts.
196
- *
197
- * [Response data schema details](https://dev.algorand.co/reference/rest-apis/algod/#accountinformation)
198
- * @example
199
- * ```typescript
200
- * const address = "XBYLS2E6YI6XXL5BWCAMOA4GTWHXWENZMX5UHXMRNWWUQ7BXCY5WC5TEPA";
201
- * const accountInfo = await accountManager.getInformation(address);
202
- * ```
203
- *
204
- * @param sender The account / address to look up
205
- * @returns The account information
206
- */
207
- async getInformation(sender) {
208
- const { round, lastHeartbeat = undefined, lastProposed = undefined, address, ...account } = await this._clientManager.algod.accountInformation(sender).do();
209
- return {
210
- ...account,
211
- // None of the Number types can practically overflow 2^53
212
- address: algosdk.Address.fromString(address),
213
- balance: types_amount.AlgoAmount.MicroAlgo(Number(account.amount)),
214
- amountWithoutPendingRewards: types_amount.AlgoAmount.MicroAlgo(Number(account.amountWithoutPendingRewards)),
215
- minBalance: types_amount.AlgoAmount.MicroAlgo(Number(account.minBalance)),
216
- pendingRewards: types_amount.AlgoAmount.MicroAlgo(Number(account.pendingRewards)),
217
- rewards: types_amount.AlgoAmount.MicroAlgo(Number(account.rewards)),
218
- validAsOfRound: BigInt(round),
219
- totalAppsOptedIn: Number(account.totalAppsOptedIn),
220
- totalAssetsOptedIn: Number(account.totalAssetsOptedIn),
221
- totalCreatedApps: Number(account.totalCreatedApps),
222
- totalCreatedAssets: Number(account.totalCreatedAssets),
223
- appsTotalExtraPages: account.appsTotalExtraPages !== undefined ? Number(account.appsTotalExtraPages) : undefined,
224
- rewardBase: account.rewardBase !== undefined ? Number(account.rewardBase) : undefined,
225
- totalBoxBytes: account.totalBoxBytes !== undefined ? Number(account.totalBoxBytes) : undefined,
226
- totalBoxes: account.totalBoxes !== undefined ? Number(account.totalBoxes) : undefined,
227
- lastHeartbeatRound: lastHeartbeat !== undefined ? BigInt(lastHeartbeat) : undefined,
228
- lastProposedRound: lastProposed !== undefined ? BigInt(lastProposed) : undefined,
229
- };
230
- }
231
- /**
232
- * Tracks and returns an Algorand account with secret key loaded (i.e. that can sign transactions) by taking the mnemonic secret.
233
- *
234
- * @example
235
- * ```typescript
236
- * const account = accountManager.fromMnemonic("mnemonic secret ...")
237
- * const rekeyedAccount = accountManager.fromMnemonic("mnemonic secret ...", "SENDERADDRESS...")
238
- * ```
239
- * @param mnemonicSecret The mnemonic secret representing the private key of an account; **Note: Be careful how the mnemonic is handled**,
240
- * never commit it into source control and ideally load it from the environment (ideally via a secret storage service) rather than the file system.
241
- * @param sender The optional sender address to use this signer for (aka a rekeyed account)
242
- * @returns The account
243
- */
244
- fromMnemonic(mnemonicSecret, sender) {
245
- const account = algosdk.mnemonicToSecretKey(mnemonicSecret);
246
- return this.signerAccount(new types_account.SigningAccount(account, sender));
247
- }
248
- /**
249
- * Tracks and returns an Algorand account that is a rekeyed version of the given account to a new sender.
250
- *
251
- * @example
252
- * ```typescript
253
- * const account = accountManager.fromMnemonic("mnemonic secret ...")
254
- * const rekeyedAccount = accountManager.rekeyed(account, "SENDERADDRESS...")
255
- * ```
256
- * @param account The account to use as the signer for this new rekeyed account
257
- * @param sender The sender address to use as the new sender
258
- * @returns The account
259
- */
260
- rekeyed(sender, account) {
261
- return this.signerAccount({ addr: address(sender), signer: account.signer });
262
- }
263
- /**
264
- * Tracks and returns an Algorand account with private key loaded by convention from environment variables based on the given name identifier.
265
- *
266
- * Note: This function expects to run in a Node.js environment.
267
- *
268
- * ## Convention:
269
- * * **Non-LocalNet:** will load process.env['\{NAME\}_MNEMONIC'] as a mnemonic secret; **Note: Be careful how the mnemonic is handled**,
270
- * never commit it into source control and ideally load it via a secret storage service rather than the file system.
271
- * If process.env['\{NAME\}_SENDER'] is defined then it will use that for the sender address (i.e. to support rekeyed accounts)
272
- * * **LocalNet:** will load the account from a KMD wallet called \{NAME\} and if that wallet doesn't exist it will create it and fund the account for you
273
- *
274
- * This allows you to write code that will work seamlessly in production and local development (LocalNet) without manual config locally (including when you reset the LocalNet).
275
- *
276
- * @example Default
277
- *
278
- * If you have a mnemonic secret loaded into `process.env.MY_ACCOUNT_MNEMONIC` then you can call the following to get that private key loaded into an account object:
279
- * ```typescript
280
- * const account = await accountManager.fromEnvironment('MY_ACCOUNT')
281
- * ```
282
- *
283
- * If that code runs against LocalNet then a wallet called `MY_ACCOUNT` will automatically be created with an account that is automatically funded with 1000 (default) ALGO from the default LocalNet dispenser.
284
- * If not running against LocalNet then it will use proces.env.MY_ACCOUNT_MNEMONIC as the private key and (if present) process.env.MY_ACCOUNT_SENDER as the sender address.
285
- *
286
- * @param name The name identifier of the account
287
- * @param fundWith The optional amount to fund the account with when it gets created (when targeting LocalNet), if not specified then 1000 ALGO will be funded from the dispenser account
288
- * @returns The account
289
- */
290
- async fromEnvironment(name, fundWith) {
291
- if (!process || !process.env) {
292
- throw new Error('Attempt to get account with private key from a non Node.js context; this is not supported!');
293
- }
294
- const accountMnemonic = process.env[`${name.toUpperCase()}_MNEMONIC`];
295
- const sender = process.env[`${name.toUpperCase()}_SENDER`];
296
- if (accountMnemonic) {
297
- const signer = algosdk.mnemonicToSecretKey(accountMnemonic);
298
- return this.signerAccount(new types_account.SigningAccount(signer, sender));
299
- }
300
- if (await this._clientManager.isLocalNet()) {
301
- const account = await this._kmdAccountManager.getOrCreateWalletAccount(name, fundWith);
302
- return this.signerAccount(account.account);
303
- }
304
- throw new Error(`Missing environment variable ${name.toUpperCase()}_MNEMONIC when looking for account ${name}`);
305
- }
306
- /**
307
- * Tracks and returns an Algorand account with private key loaded from the given KMD wallet (identified by name).
308
- *
309
- * @param name The name of the wallet to retrieve an account from
310
- * @param predicate An optional filter to use to find the account (otherwise it will return a random account from the wallet)
311
- * @param sender The optional sender address to use this signer for (aka a rekeyed account)
312
- * @example Get default funded account in a LocalNet
313
- *
314
- * ```typescript
315
- * const defaultDispenserAccount = await accountManager.fromKmd('unencrypted-default-wallet',
316
- * a => a.status !== 'Offline' && a.amount > 1_000_000_000
317
- * )
318
- * ```
319
- * @returns The account
320
- */
321
- async fromKmd(name,
322
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
323
- predicate, sender) {
324
- const account = await this._kmdAccountManager.getWalletAccount(name, predicate, sender);
325
- if (!account)
326
- throw new Error(`Unable to find KMD account ${name}${predicate ? ' with predicate' : ''}`);
327
- return this.signerAccount(account.account);
328
- }
329
- /**
330
- * Tracks and returns an account that supports partial or full multisig signing.
331
- *
332
- * @example
333
- * ```typescript
334
- * const account = accountManager.multisig({version: 1, threshold: 1, addrs: ["ADDRESS1...", "ADDRESS2..."]},
335
- * [(await accountManager.fromEnvironment('ACCOUNT1')).account])
336
- * ```
337
- * @param multisigParams The parameters that define the multisig account
338
- * @param signingAccounts The signers that are currently present
339
- * @returns A multisig account wrapper
340
- */
341
- multisig(multisigParams, signingAccounts) {
342
- return this.signerAccount(new types_account.MultisigAccount(multisigParams, signingAccounts));
343
- }
344
- /**
345
- * Tracks and returns an account that represents a logic signature.
346
- *
347
- * @example
348
- * ```typescript
349
- * const account = accountManager.logicsig(program, [new Uint8Array(3, ...)])
350
- * ```
351
- * @param program The bytes that make up the compiled logic signature
352
- * @param args The (binary) arguments to pass into the logic signature
353
- * @returns A logic signature account wrapper
354
- */
355
- logicsig(program, args) {
356
- return this.signerAccount(new LogicSigAccount(program, args));
357
- }
358
- /**
359
- * Tracks and returns a new, random Algorand account with secret key loaded.
360
- *
361
- * @example
362
- * ```typescript
363
- * const account = accountManager.random()
364
- * ```
365
- * @returns The account
366
- */
367
- random() {
368
- return this.signerAccount(algosdk.generateAccount());
369
- }
370
- /**
371
- * Returns an account (with private key loaded) that can act as a dispenser from
372
- * environment variables, or against default LocalNet if no environment variables present.
373
- *
374
- * Note: requires a Node.js environment to execute.
375
- *
376
- * If present, it will load the account mnemonic stored in process.env.DISPENSER_MNEMONIC and optionally
377
- * process.env.DISPENSER_SENDER if it's a rekeyed account.
378
- *
379
- * @example
380
- * ```typescript
381
- * const account = await accountManager.dispenserFromEnvironment()
382
- * ```
383
- *
384
- * @returns The account
385
- */
386
- async dispenserFromEnvironment() {
387
- if (!process || !process.env) {
388
- throw new Error('Attempt to get dispenser from environment from a non Node.js context; this is not supported!');
389
- }
390
- return process.env[`${types_account.DISPENSER_ACCOUNT.toUpperCase()}_MNEMONIC`]
391
- ? await this.fromEnvironment(types_account.DISPENSER_ACCOUNT)
392
- : await this.localNetDispenser();
393
- }
394
- /**
395
- * Returns an Algorand account with private key loaded for the default LocalNet dispenser account (that can be used to fund other accounts).
396
- *
397
- * @example
398
- * ```typescript
399
- * const account = await accountManager.localNetDispenser()
400
- * ```
401
- * @returns The account
402
- */
403
- async localNetDispenser() {
404
- const dispenser = await this._kmdAccountManager.getLocalNetDispenserAccount();
405
- return this.signerAccount(dispenser.account);
406
- }
407
- /**
408
- * Rekey an account to a new address.
409
- *
410
- * **Note:** Please be careful with this function and be sure to read the [official rekey guidance](https://dev.algorand.co/concepts/accounts/rekeying).
411
- *
412
- * @param account The account to rekey
413
- * @param rekeyTo The account address or signing account of the account that will be used to authorise transactions for the rekeyed account going forward.
414
- * If a signing account is provided that will now be tracked as the signer for `account` in this `AccountManager`
415
- * @param options Any parameters to control the transaction or execution of the transaction
416
- *
417
- * @example Basic example (with string addresses)
418
- * ```typescript
419
- * await accountManager.rekeyAccount({account: "ACCOUNTADDRESS", rekeyTo: "NEWADDRESS"})
420
- * ```
421
- * @example Basic example (with signer accounts)
422
- * ```typescript
423
- * await accountManager.rekeyAccount({account: account1, rekeyTo: newSignerAccount})
424
- * ```
425
- * @example Advanced example
426
- * ```typescript
427
- * await accountManager.rekeyAccount({
428
- * account: "ACCOUNTADDRESS",
429
- * rekeyTo: "NEWADDRESS",
430
- * lease: 'lease',
431
- * note: 'note',
432
- * firstValidRound: 1000n,
433
- * validityWindow: 10,
434
- * extraFee: (1000).microAlgo(),
435
- * staticFee: (1000).microAlgo(),
436
- * // Max fee doesn't make sense with extraFee AND staticFee
437
- * // already specified, but here for completeness
438
- * maxFee: (3000).microAlgo(),
439
- * maxRoundsToWaitForConfirmation: 5,
440
- * suppressLog: true,
441
- * })
442
- * ```
443
- * @returns The result of the transaction and the transaction that was sent
444
- */
445
- async rekeyAccount(account, rekeyTo, options) {
446
- const result = await this._getComposer()
447
- .addPayment({
448
- ...options,
449
- sender: address(account),
450
- receiver: address(account),
451
- amount: types_amount.AlgoAmount.MicroAlgo(0),
452
- rekeyTo: address(typeof rekeyTo === 'object' && 'addr' in rekeyTo ? rekeyTo.addr : rekeyTo),
453
- })
454
- .send(options);
455
- // If the rekey is a signing account set it as the signer for this account
456
- if (typeof rekeyTo === 'object' && 'addr' in rekeyTo) {
457
- this.rekeyed(account, rekeyTo);
458
- }
459
- config.Config.getLogger(options?.suppressLog).info(`Rekeyed ${account} to ${rekeyTo} via transaction ${result.txIds.at(-1)}`);
460
- return { ...result, transaction: result.transactions.at(-1), confirmation: result.confirmations.at(-1) };
461
- }
462
- async _getEnsureFundedAmount(sender, minSpendingBalance, minFundingIncrement) {
463
- const accountInfo = await this.getInformation(sender);
464
- const currentSpendingBalance = accountInfo.balance.microAlgo - accountInfo.minBalance.microAlgo;
465
- const amountFunded = util.calculateFundAmount(minSpendingBalance.microAlgo, currentSpendingBalance, minFundingIncrement?.microAlgo ?? 0n);
466
- return amountFunded === null ? undefined : types_amount.AlgoAmount.MicroAlgo(amountFunded);
467
- }
468
- /**
469
- * Funds a given account using a dispenser account as a funding source such that
470
- * the given account has a certain amount of Algo free to spend (accounting for
471
- * Algo locked in minimum balance requirement).
472
- *
473
- * https://dev.algorand.co/concepts/smart-contracts/costs-constraints#mbr
474
- *
475
- * @param accountToFund The account to fund
476
- * @param dispenserAccount The account to use as a dispenser funding source
477
- * @param minSpendingBalance The minimum balance of Algo that the account should have available to spend (i.e. on top of minimum balance requirement)
478
- * @param options Optional parameters to control the funding increment, transaction or execution of the transaction
479
- * @example Example using AlgorandClient
480
- * ```typescript
481
- * // Basic example
482
- * await accountManager.ensureFunded("ACCOUNTADDRESS", "DISPENSERADDRESS", algokit.algo(1))
483
- * // With configuration
484
- * await accountManager.ensureFunded("ACCOUNTADDRESS", "DISPENSERADDRESS", algokit.algo(1),
485
- * { minFundingIncrement: algokit.algo(2), fee: (1000).microAlgo(), suppressLog: true }
486
- * )
487
- * ```
488
- * @returns
489
- * - The result of executing the dispensing transaction and the `amountFunded` if funds were needed.
490
- * - `undefined` if no funds were needed.
491
- */
492
- async ensureFunded(accountToFund, dispenserAccount, minSpendingBalance, options) {
493
- const addressToFund = address(accountToFund);
494
- const amountFunded = await this._getEnsureFundedAmount(addressToFund, minSpendingBalance, options?.minFundingIncrement);
495
- if (!amountFunded)
496
- return undefined;
497
- const result = await this._getComposer()
498
- .addPayment({
499
- ...options,
500
- sender: address(dispenserAccount),
501
- receiver: addressToFund,
502
- amount: amountFunded,
503
- })
504
- .send(options);
505
- return {
506
- ...result,
507
- transaction: result.transactions[0],
508
- confirmation: result.confirmations[0],
509
- transactionId: result.txIds[0],
510
- amountFunded: amountFunded,
511
- };
512
- }
513
- /**
514
- * Funds a given account using a dispenser account retrieved from the environment,
515
- * per the `dispenserFromEnvironment` method, as a funding source such that
516
- * the given account has a certain amount of Algo free to spend (accounting for
517
- * Algo locked in minimum balance requirement).
518
- *
519
- * **Note:** requires a Node.js environment to execute.
520
- *
521
- * The dispenser account is retrieved from the account mnemonic stored in
522
- * process.env.DISPENSER_MNEMONIC and optionally process.env.DISPENSER_SENDER
523
- * if it's a rekeyed account, or against default LocalNet if no environment variables present.
524
- *
525
- * https://dev.algorand.co/concepts/smart-contracts/costs-constraints#mbr
526
- *
527
- * @param accountToFund The account to fund
528
- * @param minSpendingBalance The minimum balance of Algo that the account should have available to spend (i.e. on top of minimum balance requirement)
529
- * @param options Optional parameters to control the funding increment, transaction or execution of the transaction
530
- * @example Example using AlgorandClient
531
- * ```typescript
532
- * // Basic example
533
- * await accountManager.ensureFundedFromEnvironment("ACCOUNTADDRESS", algokit.algo(1))
534
- * // With configuration
535
- * await accountManager.ensureFundedFromEnvironment("ACCOUNTADDRESS", algokit.algo(1),
536
- * { minFundingIncrement: algokit.algo(2), fee: (1000).microAlgo(), suppressLog: true }
537
- * )
538
- * ```
539
- * @returns
540
- * - The result of executing the dispensing transaction and the `amountFunded` if funds were needed.
541
- * - `undefined` if no funds were needed.
542
- */
543
- async ensureFundedFromEnvironment(accountToFund, minSpendingBalance, options) {
544
- const addressToFund = address(accountToFund);
545
- const dispenserAccount = await this.dispenserFromEnvironment();
546
- const amountFunded = await this._getEnsureFundedAmount(addressToFund, minSpendingBalance, options?.minFundingIncrement);
547
- if (!amountFunded)
548
- return undefined;
549
- const result = await this._getComposer()
550
- .addPayment({
551
- ...options,
552
- sender: dispenserAccount,
553
- receiver: addressToFund,
554
- amount: amountFunded,
555
- })
556
- .send(options);
557
- return {
558
- ...result,
559
- transaction: result.transactions[0],
560
- confirmation: result.confirmations[0],
561
- transactionId: result.txIds[0],
562
- amountFunded: amountFunded,
563
- };
564
- }
565
- /**
566
- * Funds a given account using the TestNet Dispenser API as a funding source such that
567
- * the account has a certain amount of Algo free to spend (accounting for Algo locked
568
- * in minimum balance requirement).
569
- *
570
- * https://dev.algorand.co/concepts/smart-contracts/costs-constraints#mbr
571
- *
572
- * @param accountToFund The account to fund
573
- * @param dispenserClient The TestNet dispenser funding client
574
- * @param minSpendingBalance The minimum balance of Algo that the account should have available to spend (i.e. on top of minimum balance requirement)
575
- * @param options Optional parameters to control the funding increment, transaction or execution of the transaction
576
- * @example Example using AlgorandClient
577
- * ```typescript
578
- * // Basic example
579
- * await accountManager.ensureFundedFromTestNetDispenserApi("ACCOUNTADDRESS", algorand.client.getTestNetDispenserFromEnvironment(), algokit.algo(1))
580
- * // With configuration
581
- * await accountManager.ensureFundedFromTestNetDispenserApi("ACCOUNTADDRESS", algorand.client.getTestNetDispenserFromEnvironment(), algokit.algo(1),
582
- * { minFundingIncrement: algokit.algo(2) }
583
- * )
584
- * ```
585
- * @returns
586
- * - The result of executing the dispensing transaction and the `amountFunded` if funds were needed.
587
- * - `undefined` if no funds were needed.
588
- */
589
- async ensureFundedFromTestNetDispenserApi(accountToFund, dispenserClient, minSpendingBalance, options) {
590
- if (!(await this._clientManager.isTestNet())) {
591
- throw new Error('Attempt to fund using TestNet dispenser API on non TestNet network.');
592
- }
593
- const addressToFund = address(accountToFund);
594
- const amountFunded = await this._getEnsureFundedAmount(addressToFund, minSpendingBalance, options?.minFundingIncrement);
595
- if (!amountFunded)
596
- return undefined;
597
- const result = await dispenserClient.fund(addressToFund, amountFunded.microAlgo);
598
- return {
599
- amountFunded: types_amount.AlgoAmount.MicroAlgo(result.amount),
600
- transactionId: result.txId,
601
- };
602
- }
603
- }
604
-
28
+ var AccountManager = class {
29
+ _clientManager;
30
+ _kmdAccountManager;
31
+ _accounts = {};
32
+ _defaultSigner;
33
+ /**
34
+ * Create a new account manager.
35
+ * @param clientManager The ClientManager client to use for algod and kmd clients
36
+ * @example Create a new account manager
37
+ * ```typescript
38
+ * const accountManager = new AccountManager(clientManager)
39
+ * ```
40
+ */
41
+ constructor(clientManager) {
42
+ this._clientManager = clientManager;
43
+ this._kmdAccountManager = new require_kmd_account_manager.KmdAccountManager(clientManager);
44
+ }
45
+ _getComposer(getSuggestedParams) {
46
+ return new require_composer.TransactionComposer({
47
+ algod: this._clientManager.algod,
48
+ getSigner: this.getSigner.bind(this),
49
+ getSuggestedParams: getSuggestedParams ?? (() => this._clientManager.algod.getTransactionParams().do())
50
+ });
51
+ }
52
+ /**
53
+ * KMD account manager that allows you to easily get and create accounts using KMD.
54
+ * @returns The `KmdAccountManager` instance.
55
+ * @example
56
+ * ```typescript
57
+ * const kmdManager = accountManager.kmd;
58
+ * ```
59
+ */
60
+ get kmd() {
61
+ return this._kmdAccountManager;
62
+ }
63
+ /**
64
+ * Sets the default signer to use if no other signer is specified.
65
+ *
66
+ * If this isn't set an a transaction needs signing for a given sender
67
+ * then an error will be thrown from `getSigner` / `getAccount`.
68
+ * @param signer The signer to use, either a `TransactionSigner` or a `TransactionSignerAccount`
69
+ * @example
70
+ * ```typescript
71
+ * const signer = accountManager.random() // Can be anything that returns a `algosdk.TransactionSigner` or `TransactionSignerAccount`
72
+ * accountManager.setDefaultSigner(signer)
73
+ *
74
+ * // When signing a transaction, if there is no signer registered for the sender then the default signer will be used
75
+ * const signer = accountManager.getSigner("SENDERADDRESS")
76
+ * ```
77
+ * @returns The `AccountManager` so method calls can be chained
78
+ */
79
+ setDefaultSigner(signer) {
80
+ this._defaultSigner = "signer" in signer ? signer.signer : signer;
81
+ return this;
82
+ }
83
+ /**
84
+ * Records the given account (that can sign) against the address of the provided account for later
85
+ * retrieval and returns a `TransactionSignerAccount` along with the original account in an `account` property.
86
+ */
87
+ signerAccount(account) {
88
+ const signer = getAccountTransactionSigner(account);
89
+ const acc = {
90
+ addr: "addr" in account ? account.addr : account.address(),
91
+ signer
92
+ };
93
+ this._accounts[acc.addr.toString()] = acc;
94
+ const addressWithAccount = algosdk.Address.fromString(acc.addr.toString());
95
+ addressWithAccount.account = account;
96
+ addressWithAccount.addr = acc.addr;
97
+ addressWithAccount.signer = signer;
98
+ return addressWithAccount;
99
+ }
100
+ /**
101
+ * Tracks the given account for later signing.
102
+ *
103
+ * Note: If you are generating accounts via the various methods on `AccountManager`
104
+ * (like `random`, `fromMnemonic`, `logicsig`, etc.) then they automatically get tracked.
105
+ * @param account The account to register, which can be a `TransactionSignerAccount` or
106
+ * a `algosdk.Account`, `algosdk.LogicSigAccount`, `SigningAccount` or `MultisigAccount`
107
+ * @example
108
+ * ```typescript
109
+ * const accountManager = new AccountManager(clientManager)
110
+ * .setSignerFromAccount(algosdk.generateAccount())
111
+ * .setSignerFromAccount(new algosdk.LogicSigAccount(program, args))
112
+ * .setSignerFromAccount(new SigningAccount(mnemonic, sender))
113
+ * .setSignerFromAccount(new MultisigAccount({version: 1, threshold: 1, addrs: ["ADDRESS1...", "ADDRESS2..."]}, [account1, account2]))
114
+ * .setSignerFromAccount({addr: "SENDERADDRESS", signer: transactionSigner})
115
+ * ```
116
+ * @returns The `AccountManager` instance for method chaining
117
+ */
118
+ setSignerFromAccount(account) {
119
+ this.signerAccount(account);
120
+ return this;
121
+ }
122
+ /**
123
+ * Tracks the given `algosdk.TransactionSigner` against the given sender address for later signing.
124
+ * @param sender The sender address to use this signer for
125
+ * @param signer The `algosdk.TransactionSigner` to sign transactions with for the given sender
126
+ * @example
127
+ * ```typescript
128
+ * const accountManager = new AccountManager(clientManager)
129
+ * .setSigner("SENDERADDRESS", transactionSigner)
130
+ * ```
131
+ * @returns The `AccountManager` instance for method chaining
132
+ */
133
+ setSigner(sender, signer) {
134
+ this._accounts[address(sender).toString()] = {
135
+ addr: address(sender),
136
+ signer
137
+ };
138
+ return this;
139
+ }
140
+ /**
141
+ * Takes all registered signers from the given `AccountManager` and adds them to this `AccountManager`.
142
+ *
143
+ * This is useful for situations where you have multiple contexts you are building accounts in such as unit tests.
144
+ * @param anotherAccountManager Another account manager with signers registered
145
+ * @param overwriteExisting Whether or not to overwrite any signers that have the same sender address with the ones in the other account manager or not (default: true)
146
+ * @returns The `AccountManager` instance for method chaining
147
+ * @example
148
+ * ```typescript
149
+ * accountManager2.setSigners(accountManager1);
150
+ * ```
151
+ */
152
+ setSigners(anotherAccountManager, overwriteExisting = true) {
153
+ this._accounts = overwriteExisting ? {
154
+ ...this._accounts,
155
+ ...anotherAccountManager._accounts
156
+ } : {
157
+ ...anotherAccountManager._accounts,
158
+ ...this._accounts
159
+ };
160
+ return this;
161
+ }
162
+ /**
163
+ * Returns the `TransactionSigner` for the given sender address, ready to sign a transaction for that sender.
164
+ *
165
+ * If no signer has been registered for that address then the default signer is used if registered and
166
+ * if not then an error is thrown.
167
+ *
168
+ * @param sender The sender address
169
+ * @example
170
+ * ```typescript
171
+ * const signer = accountManager.getSigner("SENDERADDRESS")
172
+ * ```
173
+ * @returns The `TransactionSigner` or throws an error if not found and no default signer is set
174
+ */
175
+ getSigner(sender) {
176
+ const signer = this._accounts[address(sender).toString()]?.signer ?? this._defaultSigner;
177
+ if (!signer) throw new Error(`No signer found for address ${sender}`);
178
+ return signer;
179
+ }
180
+ /**
181
+ * Returns the `TransactionSignerAccount` for the given sender address.
182
+ *
183
+ * If no signer has been registered for that address then an error is thrown.
184
+ * @param sender The sender address
185
+ * @example
186
+ * ```typescript
187
+ * const sender = accountManager.random()
188
+ * // ...
189
+ * // Returns the `TransactionSignerAccount` for `sender` that has previously been registered
190
+ * const account = accountManager.getAccount(sender)
191
+ * ```
192
+ * @returns The `TransactionSignerAccount` or throws an error if not found
193
+ */
194
+ getAccount(sender) {
195
+ const account = this._accounts[address(sender).toString()];
196
+ if (!account) throw new Error(`No signer found for address ${sender}`);
197
+ return account;
198
+ }
199
+ /**
200
+ * Returns the given sender account's current status, balance and spendable amounts.
201
+ *
202
+ * [Response data schema details](https://dev.algorand.co/reference/rest-api/algod/operations/accountinformation/)
203
+ * @example
204
+ * ```typescript
205
+ * const address = "XBYLS2E6YI6XXL5BWCAMOA4GTWHXWENZMX5UHXMRNWWUQ7BXCY5WC5TEPA";
206
+ * const accountInfo = await accountManager.getInformation(address);
207
+ * ```
208
+ *
209
+ * @param sender The account / address to look up
210
+ * @returns The account information
211
+ */
212
+ async getInformation(sender) {
213
+ const { round, lastHeartbeat = void 0, lastProposed = void 0, address, ...account } = await this._clientManager.algod.accountInformation(sender).do();
214
+ return {
215
+ ...account,
216
+ address: algosdk.Address.fromString(address),
217
+ balance: require_amount.AlgoAmount.MicroAlgo(Number(account.amount)),
218
+ amountWithoutPendingRewards: require_amount.AlgoAmount.MicroAlgo(Number(account.amountWithoutPendingRewards)),
219
+ minBalance: require_amount.AlgoAmount.MicroAlgo(Number(account.minBalance)),
220
+ pendingRewards: require_amount.AlgoAmount.MicroAlgo(Number(account.pendingRewards)),
221
+ rewards: require_amount.AlgoAmount.MicroAlgo(Number(account.rewards)),
222
+ validAsOfRound: BigInt(round),
223
+ totalAppsOptedIn: Number(account.totalAppsOptedIn),
224
+ totalAssetsOptedIn: Number(account.totalAssetsOptedIn),
225
+ totalCreatedApps: Number(account.totalCreatedApps),
226
+ totalCreatedAssets: Number(account.totalCreatedAssets),
227
+ appsTotalExtraPages: account.appsTotalExtraPages !== void 0 ? Number(account.appsTotalExtraPages) : void 0,
228
+ rewardBase: account.rewardBase !== void 0 ? Number(account.rewardBase) : void 0,
229
+ totalBoxBytes: account.totalBoxBytes !== void 0 ? Number(account.totalBoxBytes) : void 0,
230
+ totalBoxes: account.totalBoxes !== void 0 ? Number(account.totalBoxes) : void 0,
231
+ lastHeartbeatRound: lastHeartbeat !== void 0 ? BigInt(lastHeartbeat) : void 0,
232
+ lastProposedRound: lastProposed !== void 0 ? BigInt(lastProposed) : void 0
233
+ };
234
+ }
235
+ /**
236
+ * Tracks and returns an Algorand account with secret key loaded (i.e. that can sign transactions) by taking the mnemonic secret.
237
+ *
238
+ * @example
239
+ * ```typescript
240
+ * const account = accountManager.fromMnemonic("mnemonic secret ...")
241
+ * const rekeyedAccount = accountManager.fromMnemonic("mnemonic secret ...", "SENDERADDRESS...")
242
+ * ```
243
+ * @param mnemonicSecret The mnemonic secret representing the private key of an account; **Note: Be careful how the mnemonic is handled**,
244
+ * never commit it into source control and ideally load it from the environment (ideally via a secret storage service) rather than the file system.
245
+ * @param sender The optional sender address to use this signer for (aka a rekeyed account)
246
+ * @returns The account
247
+ */
248
+ fromMnemonic(mnemonicSecret, sender) {
249
+ const account = algosdk.default.mnemonicToSecretKey(mnemonicSecret);
250
+ return this.signerAccount(new require_account.SigningAccount(account, sender));
251
+ }
252
+ /**
253
+ * Tracks and returns an Algorand account that is a rekeyed version of the given account to a new sender.
254
+ *
255
+ * @example
256
+ * ```typescript
257
+ * const account = accountManager.fromMnemonic("mnemonic secret ...")
258
+ * const rekeyedAccount = accountManager.rekeyed(account, "SENDERADDRESS...")
259
+ * ```
260
+ * @param account The account to use as the signer for this new rekeyed account
261
+ * @param sender The sender address to use as the new sender
262
+ * @returns The account
263
+ */
264
+ rekeyed(sender, account) {
265
+ return this.signerAccount({
266
+ addr: address(sender),
267
+ signer: account.signer
268
+ });
269
+ }
270
+ /**
271
+ * Tracks and returns an Algorand account with private key loaded by convention from environment variables based on the given name identifier.
272
+ *
273
+ * Note: This function expects to run in a Node.js environment.
274
+ *
275
+ * ## Convention:
276
+ * * **Non-LocalNet:** will load process.env['\{NAME\}_MNEMONIC'] as a mnemonic secret; **Note: Be careful how the mnemonic is handled**,
277
+ * never commit it into source control and ideally load it via a secret storage service rather than the file system.
278
+ * If process.env['\{NAME\}_SENDER'] is defined then it will use that for the sender address (i.e. to support rekeyed accounts)
279
+ * * **LocalNet:** will load the account from a KMD wallet called \{NAME\} and if that wallet doesn't exist it will create it and fund the account for you
280
+ *
281
+ * This allows you to write code that will work seamlessly in production and local development (LocalNet) without manual config locally (including when you reset the LocalNet).
282
+ *
283
+ * @example Default
284
+ *
285
+ * If you have a mnemonic secret loaded into `process.env.MY_ACCOUNT_MNEMONIC` then you can call the following to get that private key loaded into an account object:
286
+ * ```typescript
287
+ * const account = await accountManager.fromEnvironment('MY_ACCOUNT')
288
+ * ```
289
+ *
290
+ * If that code runs against LocalNet then a wallet called `MY_ACCOUNT` will automatically be created with an account that is automatically funded with 1000 (default) ALGO from the default LocalNet dispenser.
291
+ * If not running against LocalNet then it will use proces.env.MY_ACCOUNT_MNEMONIC as the private key and (if present) process.env.MY_ACCOUNT_SENDER as the sender address.
292
+ *
293
+ * @param name The name identifier of the account
294
+ * @param fundWith The optional amount to fund the account with when it gets created (when targeting LocalNet), if not specified then 1000 ALGO will be funded from the dispenser account
295
+ * @returns The account
296
+ */
297
+ async fromEnvironment(name, fundWith) {
298
+ if (!process || !process.env) throw new Error("Attempt to get account with private key from a non Node.js context; this is not supported!");
299
+ const accountMnemonic = process.env[`${name.toUpperCase()}_MNEMONIC`];
300
+ const sender = process.env[`${name.toUpperCase()}_SENDER`];
301
+ if (accountMnemonic) {
302
+ const signer = algosdk.default.mnemonicToSecretKey(accountMnemonic);
303
+ return this.signerAccount(new require_account.SigningAccount(signer, sender));
304
+ }
305
+ if (await this._clientManager.isLocalNet()) {
306
+ const account = await this._kmdAccountManager.getOrCreateWalletAccount(name, fundWith);
307
+ return this.signerAccount(account.account);
308
+ }
309
+ throw new Error(`Missing environment variable ${name.toUpperCase()}_MNEMONIC when looking for account ${name}`);
310
+ }
311
+ /**
312
+ * Tracks and returns an Algorand account with private key loaded from the given KMD wallet (identified by name).
313
+ *
314
+ * @param name The name of the wallet to retrieve an account from
315
+ * @param predicate An optional filter to use to find the account (otherwise it will return a random account from the wallet)
316
+ * @param sender The optional sender address to use this signer for (aka a rekeyed account)
317
+ * @example Get default funded account in a LocalNet
318
+ *
319
+ * ```typescript
320
+ * const defaultDispenserAccount = await accountManager.fromKmd('unencrypted-default-wallet',
321
+ * a => a.status !== 'Offline' && a.amount > 1_000_000_000
322
+ * )
323
+ * ```
324
+ * @returns The account
325
+ */
326
+ async fromKmd(name, predicate, sender) {
327
+ const account = await this._kmdAccountManager.getWalletAccount(name, predicate, sender);
328
+ if (!account) throw new Error(`Unable to find KMD account ${name}${predicate ? " with predicate" : ""}`);
329
+ return this.signerAccount(account.account);
330
+ }
331
+ /**
332
+ * Tracks and returns an account that supports partial or full multisig signing.
333
+ *
334
+ * @example
335
+ * ```typescript
336
+ * const account = accountManager.multisig({version: 1, threshold: 1, addrs: ["ADDRESS1...", "ADDRESS2..."]},
337
+ * [(await accountManager.fromEnvironment('ACCOUNT1')).account])
338
+ * ```
339
+ * @param multisigParams The parameters that define the multisig account
340
+ * @param signingAccounts The signers that are currently present
341
+ * @returns A multisig account wrapper
342
+ */
343
+ multisig(multisigParams, signingAccounts) {
344
+ return this.signerAccount(new require_account.MultisigAccount(multisigParams, signingAccounts));
345
+ }
346
+ /**
347
+ * Tracks and returns an account that represents a logic signature.
348
+ *
349
+ * @example
350
+ * ```typescript
351
+ * const account = accountManager.logicsig(program, [new Uint8Array(3, ...)])
352
+ * ```
353
+ * @param program The bytes that make up the compiled logic signature
354
+ * @param args The (binary) arguments to pass into the logic signature
355
+ * @returns A logic signature account wrapper
356
+ */
357
+ logicsig(program, args) {
358
+ return this.signerAccount(new LogicSigAccount(program, args));
359
+ }
360
+ /**
361
+ * Tracks and returns a new, random Algorand account with secret key loaded.
362
+ *
363
+ * @example
364
+ * ```typescript
365
+ * const account = accountManager.random()
366
+ * ```
367
+ * @returns The account
368
+ */
369
+ random() {
370
+ return this.signerAccount(algosdk.default.generateAccount());
371
+ }
372
+ /**
373
+ * Returns an account (with private key loaded) that can act as a dispenser from
374
+ * environment variables, or against default LocalNet if no environment variables present.
375
+ *
376
+ * Note: requires a Node.js environment to execute.
377
+ *
378
+ * If present, it will load the account mnemonic stored in process.env.DISPENSER_MNEMONIC and optionally
379
+ * process.env.DISPENSER_SENDER if it's a rekeyed account.
380
+ *
381
+ * @example
382
+ * ```typescript
383
+ * const account = await accountManager.dispenserFromEnvironment()
384
+ * ```
385
+ *
386
+ * @returns The account
387
+ */
388
+ async dispenserFromEnvironment() {
389
+ if (!process || !process.env) throw new Error("Attempt to get dispenser from environment from a non Node.js context; this is not supported!");
390
+ return process.env[`${"DISPENSER".toUpperCase()}_MNEMONIC`] ? await this.fromEnvironment(require_account.DISPENSER_ACCOUNT) : await this.localNetDispenser();
391
+ }
392
+ /**
393
+ * Returns an Algorand account with private key loaded for the default LocalNet dispenser account (that can be used to fund other accounts).
394
+ *
395
+ * @example
396
+ * ```typescript
397
+ * const account = await accountManager.localNetDispenser()
398
+ * ```
399
+ * @returns The account
400
+ */
401
+ async localNetDispenser() {
402
+ const dispenser = await this._kmdAccountManager.getLocalNetDispenserAccount();
403
+ return this.signerAccount(dispenser.account);
404
+ }
405
+ /**
406
+ * Rekey an account to a new address.
407
+ *
408
+ * **Note:** Please be careful with this function and be sure to read the [official rekey guidance](https://dev.algorand.co/concepts/accounts/rekeying).
409
+ *
410
+ * @param account The account to rekey
411
+ * @param rekeyTo The account address or signing account of the account that will be used to authorise transactions for the rekeyed account going forward.
412
+ * If a signing account is provided that will now be tracked as the signer for `account` in this `AccountManager`
413
+ * @param options Any parameters to control the transaction or execution of the transaction
414
+ *
415
+ * @example Basic example (with string addresses)
416
+ * ```typescript
417
+ * await accountManager.rekeyAccount({account: "ACCOUNTADDRESS", rekeyTo: "NEWADDRESS"})
418
+ * ```
419
+ * @example Basic example (with signer accounts)
420
+ * ```typescript
421
+ * await accountManager.rekeyAccount({account: account1, rekeyTo: newSignerAccount})
422
+ * ```
423
+ * @example Advanced example
424
+ * ```typescript
425
+ * await accountManager.rekeyAccount({
426
+ * account: "ACCOUNTADDRESS",
427
+ * rekeyTo: "NEWADDRESS",
428
+ * lease: 'lease',
429
+ * note: 'note',
430
+ * firstValidRound: 1000n,
431
+ * validityWindow: 10,
432
+ * extraFee: (1000).microAlgo(),
433
+ * staticFee: (1000).microAlgo(),
434
+ * // Max fee doesn't make sense with extraFee AND staticFee
435
+ * // already specified, but here for completeness
436
+ * maxFee: (3000).microAlgo(),
437
+ * maxRoundsToWaitForConfirmation: 5,
438
+ * suppressLog: true,
439
+ * })
440
+ * ```
441
+ * @returns The result of the transaction and the transaction that was sent
442
+ */
443
+ async rekeyAccount(account, rekeyTo, options) {
444
+ const result = await this._getComposer().addPayment({
445
+ ...options,
446
+ sender: address(account),
447
+ receiver: address(account),
448
+ amount: require_amount.AlgoAmount.MicroAlgo(0),
449
+ rekeyTo: address(typeof rekeyTo === "object" && "addr" in rekeyTo ? rekeyTo.addr : rekeyTo)
450
+ }).send(options);
451
+ if (typeof rekeyTo === "object" && "addr" in rekeyTo) this.rekeyed(account, rekeyTo);
452
+ require_config.Config.getLogger(options?.suppressLog).info(`Rekeyed ${account} to ${rekeyTo} via transaction ${result.txIds.at(-1)}`);
453
+ return {
454
+ ...result,
455
+ transaction: result.transactions.at(-1),
456
+ confirmation: result.confirmations.at(-1)
457
+ };
458
+ }
459
+ async _getEnsureFundedAmount(sender, minSpendingBalance, minFundingIncrement) {
460
+ const accountInfo = await this.getInformation(sender);
461
+ const currentSpendingBalance = accountInfo.balance.microAlgo - accountInfo.minBalance.microAlgo;
462
+ const amountFunded = require_util.calculateFundAmount(minSpendingBalance.microAlgo, currentSpendingBalance, minFundingIncrement?.microAlgo ?? 0n);
463
+ return amountFunded === null ? void 0 : require_amount.AlgoAmount.MicroAlgo(amountFunded);
464
+ }
465
+ /**
466
+ * Funds a given account using a dispenser account as a funding source such that
467
+ * the given account has a certain amount of Algo free to spend (accounting for
468
+ * Algo locked in minimum balance requirement).
469
+ *
470
+ * https://dev.algorand.co/concepts/smart-contracts/costs-constraints#mbr
471
+ *
472
+ * @param accountToFund The account to fund
473
+ * @param dispenserAccount The account to use as a dispenser funding source
474
+ * @param minSpendingBalance The minimum balance of Algo that the account should have available to spend (i.e. on top of minimum balance requirement)
475
+ * @param options Optional parameters to control the funding increment, transaction or execution of the transaction
476
+ * @example Example using AlgorandClient
477
+ * ```typescript
478
+ * // Basic example
479
+ * await accountManager.ensureFunded("ACCOUNTADDRESS", "DISPENSERADDRESS", algokit.algo(1))
480
+ * // With configuration
481
+ * await accountManager.ensureFunded("ACCOUNTADDRESS", "DISPENSERADDRESS", algokit.algo(1),
482
+ * { minFundingIncrement: algokit.algo(2), fee: (1000).microAlgo(), suppressLog: true }
483
+ * )
484
+ * ```
485
+ * @returns
486
+ * - The result of executing the dispensing transaction and the `amountFunded` if funds were needed.
487
+ * - `undefined` if no funds were needed.
488
+ */
489
+ async ensureFunded(accountToFund, dispenserAccount, minSpendingBalance, options) {
490
+ const addressToFund = address(accountToFund);
491
+ const amountFunded = await this._getEnsureFundedAmount(addressToFund, minSpendingBalance, options?.minFundingIncrement);
492
+ if (!amountFunded) return void 0;
493
+ const result = await this._getComposer().addPayment({
494
+ ...options,
495
+ sender: address(dispenserAccount),
496
+ receiver: addressToFund,
497
+ amount: amountFunded
498
+ }).send(options);
499
+ return {
500
+ ...result,
501
+ transaction: result.transactions[0],
502
+ confirmation: result.confirmations[0],
503
+ transactionId: result.txIds[0],
504
+ amountFunded
505
+ };
506
+ }
507
+ /**
508
+ * Funds a given account using a dispenser account retrieved from the environment,
509
+ * per the `dispenserFromEnvironment` method, as a funding source such that
510
+ * the given account has a certain amount of Algo free to spend (accounting for
511
+ * Algo locked in minimum balance requirement).
512
+ *
513
+ * **Note:** requires a Node.js environment to execute.
514
+ *
515
+ * The dispenser account is retrieved from the account mnemonic stored in
516
+ * process.env.DISPENSER_MNEMONIC and optionally process.env.DISPENSER_SENDER
517
+ * if it's a rekeyed account, or against default LocalNet if no environment variables present.
518
+ *
519
+ * https://dev.algorand.co/concepts/smart-contracts/costs-constraints#mbr
520
+ *
521
+ * @param accountToFund The account to fund
522
+ * @param minSpendingBalance The minimum balance of Algo that the account should have available to spend (i.e. on top of minimum balance requirement)
523
+ * @param options Optional parameters to control the funding increment, transaction or execution of the transaction
524
+ * @example Example using AlgorandClient
525
+ * ```typescript
526
+ * // Basic example
527
+ * await accountManager.ensureFundedFromEnvironment("ACCOUNTADDRESS", algokit.algo(1))
528
+ * // With configuration
529
+ * await accountManager.ensureFundedFromEnvironment("ACCOUNTADDRESS", algokit.algo(1),
530
+ * { minFundingIncrement: algokit.algo(2), fee: (1000).microAlgo(), suppressLog: true }
531
+ * )
532
+ * ```
533
+ * @returns
534
+ * - The result of executing the dispensing transaction and the `amountFunded` if funds were needed.
535
+ * - `undefined` if no funds were needed.
536
+ */
537
+ async ensureFundedFromEnvironment(accountToFund, minSpendingBalance, options) {
538
+ const addressToFund = address(accountToFund);
539
+ const dispenserAccount = await this.dispenserFromEnvironment();
540
+ const amountFunded = await this._getEnsureFundedAmount(addressToFund, minSpendingBalance, options?.minFundingIncrement);
541
+ if (!amountFunded) return void 0;
542
+ const result = await this._getComposer().addPayment({
543
+ ...options,
544
+ sender: dispenserAccount,
545
+ receiver: addressToFund,
546
+ amount: amountFunded
547
+ }).send(options);
548
+ return {
549
+ ...result,
550
+ transaction: result.transactions[0],
551
+ confirmation: result.confirmations[0],
552
+ transactionId: result.txIds[0],
553
+ amountFunded
554
+ };
555
+ }
556
+ /**
557
+ * Funds a given account using the TestNet Dispenser API as a funding source such that
558
+ * the account has a certain amount of Algo free to spend (accounting for Algo locked
559
+ * in minimum balance requirement).
560
+ *
561
+ * https://dev.algorand.co/concepts/smart-contracts/costs-constraints#mbr
562
+ *
563
+ * @param accountToFund The account to fund
564
+ * @param dispenserClient The TestNet dispenser funding client
565
+ * @param minSpendingBalance The minimum balance of Algo that the account should have available to spend (i.e. on top of minimum balance requirement)
566
+ * @param options Optional parameters to control the funding increment, transaction or execution of the transaction
567
+ * @example Example using AlgorandClient
568
+ * ```typescript
569
+ * // Basic example
570
+ * await accountManager.ensureFundedFromTestNetDispenserApi("ACCOUNTADDRESS", algorand.client.getTestNetDispenserFromEnvironment(), algokit.algo(1))
571
+ * // With configuration
572
+ * await accountManager.ensureFundedFromTestNetDispenserApi("ACCOUNTADDRESS", algorand.client.getTestNetDispenserFromEnvironment(), algokit.algo(1),
573
+ * { minFundingIncrement: algokit.algo(2) }
574
+ * )
575
+ * ```
576
+ * @returns
577
+ * - The result of executing the dispensing transaction and the `amountFunded` if funds were needed.
578
+ * - `undefined` if no funds were needed.
579
+ */
580
+ async ensureFundedFromTestNetDispenserApi(accountToFund, dispenserClient, minSpendingBalance, options) {
581
+ if (!await this._clientManager.isTestNet()) throw new Error("Attempt to fund using TestNet dispenser API on non TestNet network.");
582
+ const addressToFund = address(accountToFund);
583
+ const amountFunded = await this._getEnsureFundedAmount(addressToFund, minSpendingBalance, options?.minFundingIncrement);
584
+ if (!amountFunded) return void 0;
585
+ const result = await dispenserClient.fund(addressToFund, amountFunded.microAlgo);
586
+ return {
587
+ amountFunded: require_amount.AlgoAmount.MicroAlgo(result.amount),
588
+ transactionId: result.txId
589
+ };
590
+ }
591
+ };
592
+ //#endregion
605
593
  exports.AccountManager = AccountManager;
606
594
  exports.getAccountTransactionSigner = getAccountTransactionSigner;
607
- //# sourceMappingURL=account-manager.js.map
595
+
596
+ //# sourceMappingURL=account-manager.js.map