@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,174 +1,166 @@
1
- import { Config } from '../config.mjs';
2
- import { chunkArray } from '../util.mjs';
3
- import { MAX_TRANSACTION_GROUP_SIZE } from './composer.mjs';
4
-
1
+ import { Config } from "../config.mjs";
2
+ import { chunkArray } from "../util.mjs";
3
+ import "./composer.mjs";
4
+ //#region src/types/asset-manager.ts
5
5
  /** Allows management of asset information. */
6
- class AssetManager {
7
- /**
8
- * Create a new asset manager.
9
- * @param algod An algod client
10
- * @param newGroup A function that creates a new `TransactionComposer` transaction group
11
- * @example Create a new asset manager
12
- * ```typescript
13
- * const assetManager = new AssetManager(algod, () => new TransactionComposer({algod, () => signer, () => suggestedParams}))
14
- * ```
15
- */
16
- constructor(algod, newGroup) {
17
- this._algod = algod;
18
- this._newGroup = newGroup;
19
- }
20
- /**
21
- * Returns the current asset information for the asset with the given ID.
22
- *
23
- * @example
24
- * ```typescript
25
- * const assetInfo = await assetManager.getById(12353n);
26
- * ```
27
- *
28
- * @param assetId The ID of the asset
29
- * @returns The asset information
30
- */
31
- async getById(assetId) {
32
- const asset = await this._algod.getAssetByID(Number(assetId)).do();
33
- return {
34
- assetId: BigInt(asset.index),
35
- total: BigInt(asset.params.total),
36
- decimals: Number(asset.params.decimals),
37
- assetName: asset.params.name,
38
- assetNameAsBytes: asset.params.nameB64,
39
- unitName: asset.params.unitName,
40
- unitNameAsBytes: asset.params.unitNameB64,
41
- url: asset.params.url,
42
- urlAsBytes: asset.params.urlB64,
43
- creator: asset.params.creator,
44
- manager: asset.params.manager,
45
- clawback: asset.params.clawback,
46
- freeze: asset.params.freeze,
47
- reserve: asset.params.reserve,
48
- defaultFrozen: asset.params.defaultFrozen,
49
- metadataHash: asset.params.metadataHash,
50
- };
51
- }
52
- /**
53
- * Returns the given sender account's asset holding for a given asset.
54
- *
55
- * @example
56
- * ```typescript
57
- * const address = "XBYLS2E6YI6XXL5BWCAMOA4GTWHXWENZMX5UHXMRNWWUQ7BXCY5WC5TEPA";
58
- * const assetId = 123345n;
59
- * const accountInfo = await assetManager.getAccountInformation(address, assetId);
60
- * ```
61
- *
62
- * [Response data schema details](https://dev.algorand.co/reference/rest-apis/algod/#accountassetinformation)
63
- * @param sender The address of the sender/account to look up
64
- * @param assetId The ID of the asset to return a holding for
65
- * @returns The account asset holding information
66
- */
67
- async getAccountInformation(sender, assetId) {
68
- const info = await this._algod.accountAssetInformation(sender, Number(assetId)).do();
69
- return {
70
- assetId: BigInt(assetId),
71
- balance: BigInt(info.assetHolding?.amount ?? 0),
72
- frozen: info.assetHolding?.isFrozen === true,
73
- round: BigInt(info['round']),
74
- };
75
- }
76
- /**
77
- * Opt an account in to a list of Algorand Standard Assets.
78
- *
79
- * Transactions will be sent in batches of 16 as transaction groups.
80
- *
81
- * @param account The account to opt-in
82
- * @param assetIds The list of asset IDs to opt-in to
83
- * @param options Any parameters to control the transaction or execution of the transaction
84
- * @example Example using AlgorandClient
85
- * ```typescript
86
- * // Basic example
87
- * assetManager.bulkOptIn("ACCOUNTADDRESS", [12345n, 67890n])
88
- * // With configuration
89
- * assetManager.bulkOptIn("ACCOUNTADDRESS", [12345n, 67890n], { maxFee: (1000).microAlgo(), suppressLog: true })
90
- * ```
91
- * @returns An array of records matching asset ID to transaction ID of the opt in
92
- */
93
- async bulkOptIn(account, assetIds, options) {
94
- const results = [];
95
- for (const assetGroup of chunkArray(assetIds, MAX_TRANSACTION_GROUP_SIZE)) {
96
- const composer = this._newGroup();
97
- for (const assetId of assetGroup) {
98
- composer.addAssetOptIn({
99
- ...options,
100
- sender: account,
101
- assetId: BigInt(assetId),
102
- });
103
- }
104
- const result = await composer.send(options);
105
- Config.getLogger(options?.suppressLog).info(`Successfully opted in ${account} for assets ${assetGroup.join(', ')} with transaction IDs ${result.txIds.join(', ')}` +
106
- `\n Grouped under ${result.groupId} in round ${result.confirmations?.[0]?.confirmedRound}.`);
107
- assetGroup.forEach((assetId, index) => {
108
- results.push({ assetId: BigInt(assetId), transactionId: result.txIds[index] });
109
- });
110
- }
111
- return results;
112
- }
113
- /**
114
- * Opt an account out of a list of Algorand Standard Assets.
115
- *
116
- * Transactions will be sent in batches of 16 as transaction groups.
117
- *
118
- * @param account The account to opt-in
119
- * @param assetIds The list of asset IDs to opt-out of
120
- * @param options Any parameters to control the transaction or execution of the transaction
121
- * @example Example using AlgorandClient
122
- * ```typescript
123
- * // Basic example
124
- * assetManager.bulkOptOut("ACCOUNTADDRESS", [12345n, 67890n])
125
- * // With configuration
126
- * assetManager.bulkOptOut("ACCOUNTADDRESS", [12345n, 67890n], { ensureZeroBalance: true, maxFee: (1000).microAlgo(), suppressLog: true })
127
- * ```
128
- * @returns An array of records matching asset ID to transaction ID of the opt in
129
- */
130
- async bulkOptOut(account, assetIds, options) {
131
- const results = [];
132
- for (const assetGroup of chunkArray(assetIds, MAX_TRANSACTION_GROUP_SIZE)) {
133
- const composer = this._newGroup();
134
- const notOptedInAssetIds = [];
135
- const nonZeroBalanceAssetIds = [];
136
- for (const assetId of assetGroup) {
137
- if (options?.ensureZeroBalance !== false) {
138
- try {
139
- const accountAssetInfo = await this.getAccountInformation(account, assetId);
140
- if (accountAssetInfo.balance !== 0n) {
141
- nonZeroBalanceAssetIds.push(BigInt(assetId));
142
- }
143
- }
144
- catch {
145
- notOptedInAssetIds.push(BigInt(assetId));
146
- }
147
- }
148
- }
149
- if (notOptedInAssetIds.length > 0 || nonZeroBalanceAssetIds.length > 0) {
150
- throw new Error(`Account ${account}${notOptedInAssetIds.length > 0 ? ` is not opted-in to Asset${notOptedInAssetIds.length > 1 ? 's' : ''} ${notOptedInAssetIds.join(', ')}` : ''}${nonZeroBalanceAssetIds.length > 0
151
- ? ` has non-zero balance for Asset${nonZeroBalanceAssetIds.length > 1 ? 's' : ''} ${nonZeroBalanceAssetIds.join(', ')}`
152
- : ''}; can't opt-out.`);
153
- }
154
- for (const assetId of assetGroup) {
155
- composer.addAssetOptOut({
156
- ...options,
157
- creator: (await this.getById(BigInt(assetId))).creator,
158
- sender: account,
159
- assetId: BigInt(assetId),
160
- });
161
- }
162
- const result = await composer.send(options);
163
- Config.getLogger(options?.suppressLog).info(`Successfully opted ${account} out of assets ${assetGroup.join(', ')} with transaction IDs ${result.txIds.join(', ')}` +
164
- `\n Grouped under ${result.groupId} in round ${result.confirmations?.[0]?.confirmedRound}.`);
165
- assetGroup.forEach((assetId, index) => {
166
- results.push({ assetId: BigInt(assetId), transactionId: result.txIds[index] });
167
- });
168
- }
169
- return results;
170
- }
171
- }
172
-
6
+ var AssetManager = class {
7
+ _algod;
8
+ _newGroup;
9
+ /**
10
+ * Create a new asset manager.
11
+ * @param algod An algod client
12
+ * @param newGroup A function that creates a new `TransactionComposer` transaction group
13
+ * @example Create a new asset manager
14
+ * ```typescript
15
+ * const assetManager = new AssetManager(algod, () => new TransactionComposer({algod, () => signer, () => suggestedParams}))
16
+ * ```
17
+ */
18
+ constructor(algod, newGroup) {
19
+ this._algod = algod;
20
+ this._newGroup = newGroup;
21
+ }
22
+ /**
23
+ * Returns the current asset information for the asset with the given ID.
24
+ *
25
+ * @example
26
+ * ```typescript
27
+ * const assetInfo = await assetManager.getById(12353n);
28
+ * ```
29
+ *
30
+ * @param assetId The ID of the asset
31
+ * @returns The asset information
32
+ */
33
+ async getById(assetId) {
34
+ const asset = await this._algod.getAssetByID(Number(assetId)).do();
35
+ const params = asset.params;
36
+ return {
37
+ assetId: BigInt(asset.index),
38
+ total: BigInt(params.total),
39
+ decimals: Number(params.decimals),
40
+ assetName: params.name,
41
+ assetNameAsBytes: params.nameB64,
42
+ unitName: params.unitName,
43
+ unitNameAsBytes: params.unitNameB64,
44
+ url: params.url,
45
+ urlAsBytes: params.urlB64,
46
+ creator: params.creator,
47
+ manager: params.manager,
48
+ clawback: params.clawback,
49
+ freeze: params.freeze,
50
+ reserve: params.reserve,
51
+ defaultFrozen: params.defaultFrozen,
52
+ metadataHash: params.metadataHash
53
+ };
54
+ }
55
+ /**
56
+ * Returns the given sender account's asset holding for a given asset.
57
+ *
58
+ * @example
59
+ * ```typescript
60
+ * const address = "XBYLS2E6YI6XXL5BWCAMOA4GTWHXWENZMX5UHXMRNWWUQ7BXCY5WC5TEPA";
61
+ * const assetId = 123345n;
62
+ * const accountInfo = await assetManager.getAccountInformation(address, assetId);
63
+ * ```
64
+ *
65
+ * [Response data schema details](https://dev.algorand.co/reference/rest-api/algod/operations/accountassetinformation/)
66
+ * @param sender The address of the sender/account to look up
67
+ * @param assetId The ID of the asset to return a holding for
68
+ * @returns The account asset holding information
69
+ */
70
+ async getAccountInformation(sender, assetId) {
71
+ const info = await this._algod.accountAssetInformation(sender, Number(assetId)).do();
72
+ return {
73
+ assetId: BigInt(assetId),
74
+ balance: BigInt(info.assetHolding?.amount ?? 0),
75
+ frozen: info.assetHolding?.isFrozen === true,
76
+ round: BigInt(info["round"])
77
+ };
78
+ }
79
+ /**
80
+ * Opt an account in to a list of Algorand Standard Assets.
81
+ *
82
+ * Transactions will be sent in batches of 16 as transaction groups.
83
+ *
84
+ * @param account The account to opt-in
85
+ * @param assetIds The list of asset IDs to opt-in to
86
+ * @param options Any parameters to control the transaction or execution of the transaction
87
+ * @example Example using AlgorandClient
88
+ * ```typescript
89
+ * // Basic example
90
+ * assetManager.bulkOptIn("ACCOUNTADDRESS", [12345n, 67890n])
91
+ * // With configuration
92
+ * assetManager.bulkOptIn("ACCOUNTADDRESS", [12345n, 67890n], { maxFee: (1000).microAlgo(), suppressLog: true })
93
+ * ```
94
+ * @returns An array of records matching asset ID to transaction ID of the opt in
95
+ */
96
+ async bulkOptIn(account, assetIds, options) {
97
+ const results = [];
98
+ for (const assetGroup of chunkArray(assetIds, 16)) {
99
+ const composer = this._newGroup();
100
+ for (const assetId of assetGroup) composer.addAssetOptIn({
101
+ ...options,
102
+ sender: account,
103
+ assetId: BigInt(assetId)
104
+ });
105
+ const result = await composer.send(options);
106
+ Config.getLogger(options?.suppressLog).info(`Successfully opted in ${account} for assets ${assetGroup.join(", ")} with transaction IDs ${result.txIds.join(", ")}\n Grouped under ${result.groupId} in round ${result.confirmations?.[0]?.confirmedRound}.`);
107
+ assetGroup.forEach((assetId, index) => {
108
+ results.push({
109
+ assetId: BigInt(assetId),
110
+ transactionId: result.txIds[index]
111
+ });
112
+ });
113
+ }
114
+ return results;
115
+ }
116
+ /**
117
+ * Opt an account out of a list of Algorand Standard Assets.
118
+ *
119
+ * Transactions will be sent in batches of 16 as transaction groups.
120
+ *
121
+ * @param account The account to opt-in
122
+ * @param assetIds The list of asset IDs to opt-out of
123
+ * @param options Any parameters to control the transaction or execution of the transaction
124
+ * @example Example using AlgorandClient
125
+ * ```typescript
126
+ * // Basic example
127
+ * assetManager.bulkOptOut("ACCOUNTADDRESS", [12345n, 67890n])
128
+ * // With configuration
129
+ * assetManager.bulkOptOut("ACCOUNTADDRESS", [12345n, 67890n], { ensureZeroBalance: true, maxFee: (1000).microAlgo(), suppressLog: true })
130
+ * ```
131
+ * @returns An array of records matching asset ID to transaction ID of the opt in
132
+ */
133
+ async bulkOptOut(account, assetIds, options) {
134
+ const results = [];
135
+ for (const assetGroup of chunkArray(assetIds, 16)) {
136
+ const composer = this._newGroup();
137
+ const notOptedInAssetIds = [];
138
+ const nonZeroBalanceAssetIds = [];
139
+ for (const assetId of assetGroup) if (options?.ensureZeroBalance !== false) try {
140
+ if ((await this.getAccountInformation(account, assetId)).balance !== 0n) nonZeroBalanceAssetIds.push(BigInt(assetId));
141
+ } catch {
142
+ notOptedInAssetIds.push(BigInt(assetId));
143
+ }
144
+ if (notOptedInAssetIds.length > 0 || nonZeroBalanceAssetIds.length > 0) throw new Error(`Account ${account}${notOptedInAssetIds.length > 0 ? ` is not opted-in to Asset${notOptedInAssetIds.length > 1 ? "s" : ""} ${notOptedInAssetIds.join(", ")}` : ""}${nonZeroBalanceAssetIds.length > 0 ? ` has non-zero balance for Asset${nonZeroBalanceAssetIds.length > 1 ? "s" : ""} ${nonZeroBalanceAssetIds.join(", ")}` : ""}; can't opt-out.`);
145
+ for (const assetId of assetGroup) composer.addAssetOptOut({
146
+ ...options,
147
+ creator: (await this.getById(BigInt(assetId))).creator,
148
+ sender: account,
149
+ assetId: BigInt(assetId)
150
+ });
151
+ const result = await composer.send(options);
152
+ Config.getLogger(options?.suppressLog).info(`Successfully opted ${account} out of assets ${assetGroup.join(", ")} with transaction IDs ${result.txIds.join(", ")}\n Grouped under ${result.groupId} in round ${result.confirmations?.[0]?.confirmedRound}.`);
153
+ assetGroup.forEach((assetId, index) => {
154
+ results.push({
155
+ assetId: BigInt(assetId),
156
+ transactionId: result.txIds[index]
157
+ });
158
+ });
159
+ }
160
+ return results;
161
+ }
162
+ };
163
+ //#endregion
173
164
  export { AssetManager };
174
- //# sourceMappingURL=asset-manager.mjs.map
165
+
166
+ //# sourceMappingURL=asset-manager.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"asset-manager.mjs","sources":["../../src/types/asset-manager.ts"],"sourcesContent":["import algosdk, { Address } from 'algosdk'\nimport { Config } from '../config'\nimport { chunkArray } from '../util'\nimport { AccountAssetInformation } from './account'\nimport { CommonTransactionParams, MAX_TRANSACTION_GROUP_SIZE, TransactionComposer } from './composer'\nimport { SendParams } from './transaction'\n\n/** Individual result from performing a bulk opt-in or bulk opt-out for an account against a series of assets. */\nexport interface BulkAssetOptInOutResult {\n /** The ID of the asset opted into / out of */\n assetId: bigint\n /** The transaction ID of the resulting opt in / out */\n transactionId: string\n}\n\n/** Information about an asset. */\nexport interface AssetInformation {\n /** The ID of the asset. */\n assetId: bigint\n\n /** The address of the account that created the asset.\n *\n * This is the address where the parameters for this asset can be found,\n * and also the address where unwanted asset units can be sent when\n * closing out an asset position and opting-out of the asset.\n */\n creator: string\n\n /** The total amount of the smallest divisible (decimal) units that were created of the asset.\n *\n * For example, if `decimals` is, say, 2, then for every 100 `total` there is 1 whole unit.\n */\n total: bigint\n\n /** The amount of decimal places the asset was created with.\n *\n * * If 0, the asset is not divisible;\n * * If 1, the base unit of the asset is in tenths;\n * * If 2, the base unit of the asset is in hundredths;\n * * If 3, the base unit of the asset is in thousandths;\n * * and so on up to 19 decimal places.\n */\n decimals: number\n\n /** Whether the asset was frozen by default for all accounts.\n *\n * If `true` then for anyone apart from the creator to hold the\n * asset it needs to be unfrozen per account using an asset freeze\n * transaction from the `freeze` account.\n */\n defaultFrozen?: boolean\n\n /** The address of the optional account that can manage the configuration of the asset and destroy it.\n *\n * If not set the asset is permanently immutable.\n */\n manager?: string\n\n /**\n * The address of the optional account that holds the reserve (uncirculated supply) units of the asset.\n *\n * This address has no specific authority in the protocol itself and is informational only.\n *\n * Some standards like [ARC-19](https://github.com/algorandfoundation/ARCs/blob/main/ARCs/arc-0019.md)\n * rely on this field to hold meaningful data.\n *\n * It can be used in the case where you want to signal to holders of your asset that the uncirculated units\n * of the asset reside in an account that is different from the default creator account.\n *\n * If not set the field is permanently empty.\n */\n reserve?: string\n\n /**\n * The address of the optional account that can be used to freeze or unfreeze holdings of this asset for any account.\n *\n * If empty, freezing is not permitted.\n *\n * If not set the field is permanently empty.\n */\n freeze?: string\n\n /**\n * The address of the optional account that can clawback holdings of this asset from any account.\n *\n * The clawback account has the ability to **unconditionally take assets from any account**.\n *\n * If empty, clawback is not permitted.\n *\n * If not set the field is permanently empty.\n */\n clawback?: string\n\n /** The optional name of the unit of this asset (e.g. ticker name).\n *\n * Max size is 8 bytes.\n */\n unitName?: string\n\n /** The optional name of the unit of this asset (e.g. ticker name).\n *\n * Max size is 8 bytes.\n */\n unitNameAsBytes?: Uint8Array\n\n /** The optional name of the asset.\n *\n * Max size is 32 bytes.\n */\n assetName?: string\n\n /** The optional name of the asset.\n *\n * Max size is 32 bytes.\n */\n assetNameAsBytes?: Uint8Array\n\n /** Optional URL where more information about the asset can be retrieved (e.g. metadata).\n *\n * Max size is 96 bytes.\n */\n url?: string\n\n /** Optional URL where more information about the asset can be retrieved (e.g. metadata).\n *\n * Max size is 96 bytes.\n */\n urlAsBytes?: Uint8Array\n\n /** 32-byte hash of some metadata that is relevant to the asset and/or asset holders.\n *\n * The format of this metadata is up to the application.\n */\n metadataHash?: Uint8Array\n}\n\n/** Allows management of asset information. */\nexport class AssetManager {\n private _algod: algosdk.Algodv2\n private _newGroup: () => TransactionComposer\n\n /**\n * Create a new asset manager.\n * @param algod An algod client\n * @param newGroup A function that creates a new `TransactionComposer` transaction group\n * @example Create a new asset manager\n * ```typescript\n * const assetManager = new AssetManager(algod, () => new TransactionComposer({algod, () => signer, () => suggestedParams}))\n * ```\n */\n constructor(algod: algosdk.Algodv2, newGroup: () => TransactionComposer) {\n this._algod = algod\n this._newGroup = newGroup\n }\n\n /**\n * Returns the current asset information for the asset with the given ID.\n *\n * @example\n * ```typescript\n * const assetInfo = await assetManager.getById(12353n);\n * ```\n *\n * @param assetId The ID of the asset\n * @returns The asset information\n */\n public async getById(assetId: bigint): Promise<AssetInformation> {\n const asset = await this._algod.getAssetByID(Number(assetId)).do()\n\n return {\n assetId: BigInt(asset.index),\n total: BigInt(asset.params.total),\n decimals: Number(asset.params.decimals),\n assetName: asset.params.name,\n assetNameAsBytes: asset.params.nameB64,\n unitName: asset.params.unitName,\n unitNameAsBytes: asset.params.unitNameB64,\n url: asset.params.url,\n urlAsBytes: asset.params.urlB64,\n creator: asset.params.creator,\n manager: asset.params.manager,\n clawback: asset.params.clawback,\n freeze: asset.params.freeze,\n reserve: asset.params.reserve,\n defaultFrozen: asset.params.defaultFrozen,\n metadataHash: asset.params.metadataHash,\n }\n }\n\n /**\n * Returns the given sender account's asset holding for a given asset.\n *\n * @example\n * ```typescript\n * const address = \"XBYLS2E6YI6XXL5BWCAMOA4GTWHXWENZMX5UHXMRNWWUQ7BXCY5WC5TEPA\";\n * const assetId = 123345n;\n * const accountInfo = await assetManager.getAccountInformation(address, assetId);\n * ```\n *\n * [Response data schema details](https://dev.algorand.co/reference/rest-apis/algod/#accountassetinformation)\n * @param sender The address of the sender/account to look up\n * @param assetId The ID of the asset to return a holding for\n * @returns The account asset holding information\n */\n public async getAccountInformation(sender: string | Address, assetId: bigint): Promise<AccountAssetInformation> {\n const info = await this._algod.accountAssetInformation(sender, Number(assetId)).do()\n\n return {\n assetId: BigInt(assetId),\n balance: BigInt(info.assetHolding?.amount ?? 0),\n frozen: info.assetHolding?.isFrozen === true,\n round: BigInt(info['round']),\n }\n }\n\n /**\n * Opt an account in to a list of Algorand Standard Assets.\n *\n * Transactions will be sent in batches of 16 as transaction groups.\n *\n * @param account The account to opt-in\n * @param assetIds The list of asset IDs to opt-in to\n * @param options Any parameters to control the transaction or execution of the transaction\n * @example Example using AlgorandClient\n * ```typescript\n * // Basic example\n * assetManager.bulkOptIn(\"ACCOUNTADDRESS\", [12345n, 67890n])\n * // With configuration\n * assetManager.bulkOptIn(\"ACCOUNTADDRESS\", [12345n, 67890n], { maxFee: (1000).microAlgo(), suppressLog: true })\n * ```\n * @returns An array of records matching asset ID to transaction ID of the opt in\n */\n async bulkOptIn(\n account: string | Address,\n assetIds: bigint[],\n options?: Omit<CommonTransactionParams, 'sender'> & SendParams,\n ): Promise<BulkAssetOptInOutResult[]> {\n const results: BulkAssetOptInOutResult[] = []\n\n for (const assetGroup of chunkArray(assetIds, MAX_TRANSACTION_GROUP_SIZE)) {\n const composer = this._newGroup()\n\n for (const assetId of assetGroup) {\n composer.addAssetOptIn({\n ...options,\n sender: account,\n assetId: BigInt(assetId),\n })\n }\n\n const result = await composer.send(options)\n\n Config.getLogger(options?.suppressLog).info(\n `Successfully opted in ${account} for assets ${assetGroup.join(', ')} with transaction IDs ${result.txIds.join(', ')}` +\n `\\n Grouped under ${result.groupId} in round ${result.confirmations?.[0]?.confirmedRound}.`,\n )\n\n assetGroup.forEach((assetId, index) => {\n results.push({ assetId: BigInt(assetId), transactionId: result.txIds[index] })\n })\n }\n\n return results\n }\n\n /**\n * Opt an account out of a list of Algorand Standard Assets.\n *\n * Transactions will be sent in batches of 16 as transaction groups.\n *\n * @param account The account to opt-in\n * @param assetIds The list of asset IDs to opt-out of\n * @param options Any parameters to control the transaction or execution of the transaction\n * @example Example using AlgorandClient\n * ```typescript\n * // Basic example\n * assetManager.bulkOptOut(\"ACCOUNTADDRESS\", [12345n, 67890n])\n * // With configuration\n * assetManager.bulkOptOut(\"ACCOUNTADDRESS\", [12345n, 67890n], { ensureZeroBalance: true, maxFee: (1000).microAlgo(), suppressLog: true })\n * ```\n * @returns An array of records matching asset ID to transaction ID of the opt in\n */\n async bulkOptOut(\n account: string | Address,\n assetIds: bigint[],\n options?: Omit<CommonTransactionParams, 'sender'> &\n SendParams & {\n /** Whether or not to check if the account has a zero balance for each asset first or not.\n *\n * Defaults to `true`.\n *\n * If this is set to `true` and the account has an asset balance it will throw an error.\n *\n * If this is set to `false` and the account has an asset balance it will lose those assets to the asset creator.\n */\n ensureZeroBalance?: boolean\n },\n ): Promise<BulkAssetOptInOutResult[]> {\n const results: BulkAssetOptInOutResult[] = []\n\n for (const assetGroup of chunkArray(assetIds, MAX_TRANSACTION_GROUP_SIZE)) {\n const composer = this._newGroup()\n\n const notOptedInAssetIds: bigint[] = []\n const nonZeroBalanceAssetIds: bigint[] = []\n for (const assetId of assetGroup) {\n if (options?.ensureZeroBalance !== false) {\n try {\n const accountAssetInfo = await this.getAccountInformation(account, assetId)\n if (accountAssetInfo.balance !== 0n) {\n nonZeroBalanceAssetIds.push(BigInt(assetId))\n }\n } catch {\n notOptedInAssetIds.push(BigInt(assetId))\n }\n }\n }\n\n if (notOptedInAssetIds.length > 0 || nonZeroBalanceAssetIds.length > 0) {\n throw new Error(\n `Account ${account}${notOptedInAssetIds.length > 0 ? ` is not opted-in to Asset${notOptedInAssetIds.length > 1 ? 's' : ''} ${notOptedInAssetIds.join(', ')}` : ''}${\n nonZeroBalanceAssetIds.length > 0\n ? ` has non-zero balance for Asset${nonZeroBalanceAssetIds.length > 1 ? 's' : ''} ${nonZeroBalanceAssetIds.join(', ')}`\n : ''\n }; can't opt-out.`,\n )\n }\n\n for (const assetId of assetGroup) {\n composer.addAssetOptOut({\n ...options,\n creator: (await this.getById(BigInt(assetId))).creator,\n sender: account,\n assetId: BigInt(assetId),\n })\n }\n\n const result = await composer.send(options)\n\n Config.getLogger(options?.suppressLog).info(\n `Successfully opted ${account} out of assets ${assetGroup.join(', ')} with transaction IDs ${result.txIds.join(', ')}` +\n `\\n Grouped under ${result.groupId} in round ${result.confirmations?.[0]?.confirmedRound}.`,\n )\n\n assetGroup.forEach((assetId, index) => {\n results.push({ assetId: BigInt(assetId), transactionId: result.txIds[index] })\n })\n }\n\n return results\n }\n}\n"],"names":[],"mappings":";;;;AAwIA;MACa,YAAY,CAAA;AAIvB;;;;;;;;AAQG;IACH,WAAY,CAAA,KAAsB,EAAE,QAAmC,EAAA;AACrE,QAAA,IAAI,CAAC,MAAM,GAAG,KAAK;AACnB,QAAA,IAAI,CAAC,SAAS,GAAG,QAAQ;;AAG3B;;;;;;;;;;AAUG;IACI,MAAM,OAAO,CAAC,OAAe,EAAA;AAClC,QAAA,MAAM,KAAK,GAAG,MAAM,IAAI,CAAC,MAAM,CAAC,YAA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AC;AAChF,aAAC,CAAC;;AAGJ,QAAA,OAAO,OAAO;;AAEjB;;;;"}
1
+ {"version":3,"file":"asset-manager.mjs","names":[],"sources":["../../src/types/asset-manager.ts"],"sourcesContent":["import algosdk, { Address } from 'algosdk'\nimport { Config } from '../config'\nimport { chunkArray } from '../util'\nimport { AccountAssetInformation } from './account'\nimport { CommonTransactionParams, MAX_TRANSACTION_GROUP_SIZE, TransactionComposer } from './composer'\nimport { SendParams } from './transaction'\n\n/** Individual result from performing a bulk opt-in or bulk opt-out for an account against a series of assets. */\nexport interface BulkAssetOptInOutResult {\n /** The ID of the asset opted into / out of */\n assetId: bigint\n /** The transaction ID of the resulting opt in / out */\n transactionId: string\n}\n\n/** Information about an asset. */\nexport interface AssetInformation {\n /** The ID of the asset. */\n assetId: bigint\n\n /** The address of the account that created the asset.\n *\n * This is the address where the parameters for this asset can be found,\n * and also the address where unwanted asset units can be sent when\n * closing out an asset position and opting-out of the asset.\n */\n creator: string\n\n /** The total amount of the smallest divisible (decimal) units that were created of the asset.\n *\n * For example, if `decimals` is, say, 2, then for every 100 `total` there is 1 whole unit.\n */\n total: bigint\n\n /** The amount of decimal places the asset was created with.\n *\n * * If 0, the asset is not divisible;\n * * If 1, the base unit of the asset is in tenths;\n * * If 2, the base unit of the asset is in hundredths;\n * * If 3, the base unit of the asset is in thousandths;\n * * and so on up to 19 decimal places.\n */\n decimals: number\n\n /** Whether the asset was frozen by default for all accounts.\n *\n * If `true` then for anyone apart from the creator to hold the\n * asset it needs to be unfrozen per account using an asset freeze\n * transaction from the `freeze` account.\n */\n defaultFrozen?: boolean\n\n /** The address of the optional account that can manage the configuration of the asset and destroy it.\n *\n * If not set the asset is permanently immutable.\n */\n manager?: string\n\n /**\n * The address of the optional account that holds the reserve (uncirculated supply) units of the asset.\n *\n * This address has no specific authority in the protocol itself and is informational only.\n *\n * Some standards like [ARC-19](https://github.com/algorandfoundation/ARCs/blob/main/ARCs/arc-0019.md)\n * rely on this field to hold meaningful data.\n *\n * It can be used in the case where you want to signal to holders of your asset that the uncirculated units\n * of the asset reside in an account that is different from the default creator account.\n *\n * If not set the field is permanently empty.\n */\n reserve?: string\n\n /**\n * The address of the optional account that can be used to freeze or unfreeze holdings of this asset for any account.\n *\n * If empty, freezing is not permitted.\n *\n * If not set the field is permanently empty.\n */\n freeze?: string\n\n /**\n * The address of the optional account that can clawback holdings of this asset from any account.\n *\n * The clawback account has the ability to **unconditionally take assets from any account**.\n *\n * If empty, clawback is not permitted.\n *\n * If not set the field is permanently empty.\n */\n clawback?: string\n\n /** The optional name of the unit of this asset (e.g. ticker name).\n *\n * Max size is 8 bytes.\n */\n unitName?: string\n\n /** The optional name of the unit of this asset (e.g. ticker name).\n *\n * Max size is 8 bytes.\n */\n unitNameAsBytes?: Uint8Array\n\n /** The optional name of the asset.\n *\n * Max size is 32 bytes.\n */\n assetName?: string\n\n /** The optional name of the asset.\n *\n * Max size is 32 bytes.\n */\n assetNameAsBytes?: Uint8Array\n\n /** Optional URL where more information about the asset can be retrieved (e.g. metadata).\n *\n * Max size is 96 bytes.\n */\n url?: string\n\n /** Optional URL where more information about the asset can be retrieved (e.g. metadata).\n *\n * Max size is 96 bytes.\n */\n urlAsBytes?: Uint8Array\n\n /** 32-byte hash of some metadata that is relevant to the asset and/or asset holders.\n *\n * The format of this metadata is up to the application.\n */\n metadataHash?: Uint8Array\n}\n\n/** Allows management of asset information. */\nexport class AssetManager {\n private _algod: algosdk.Algodv2\n private _newGroup: () => TransactionComposer\n\n /**\n * Create a new asset manager.\n * @param algod An algod client\n * @param newGroup A function that creates a new `TransactionComposer` transaction group\n * @example Create a new asset manager\n * ```typescript\n * const assetManager = new AssetManager(algod, () => new TransactionComposer({algod, () => signer, () => suggestedParams}))\n * ```\n */\n constructor(algod: algosdk.Algodv2, newGroup: () => TransactionComposer) {\n this._algod = algod\n this._newGroup = newGroup\n }\n\n /**\n * Returns the current asset information for the asset with the given ID.\n *\n * @example\n * ```typescript\n * const assetInfo = await assetManager.getById(12353n);\n * ```\n *\n * @param assetId The ID of the asset\n * @returns The asset information\n */\n public async getById(assetId: bigint): Promise<AssetInformation> {\n const asset = await this._algod.getAssetByID(Number(assetId)).do()\n const params = asset.params!\n\n return {\n assetId: BigInt(asset.index),\n total: BigInt(params.total),\n decimals: Number(params.decimals),\n assetName: params.name,\n assetNameAsBytes: params.nameB64,\n unitName: params.unitName,\n unitNameAsBytes: params.unitNameB64,\n url: params.url,\n urlAsBytes: params.urlB64,\n creator: params.creator,\n manager: params.manager,\n clawback: params.clawback,\n freeze: params.freeze,\n reserve: params.reserve,\n defaultFrozen: params.defaultFrozen,\n metadataHash: params.metadataHash,\n }\n }\n\n /**\n * Returns the given sender account's asset holding for a given asset.\n *\n * @example\n * ```typescript\n * const address = \"XBYLS2E6YI6XXL5BWCAMOA4GTWHXWENZMX5UHXMRNWWUQ7BXCY5WC5TEPA\";\n * const assetId = 123345n;\n * const accountInfo = await assetManager.getAccountInformation(address, assetId);\n * ```\n *\n * [Response data schema details](https://dev.algorand.co/reference/rest-api/algod/operations/accountassetinformation/)\n * @param sender The address of the sender/account to look up\n * @param assetId The ID of the asset to return a holding for\n * @returns The account asset holding information\n */\n public async getAccountInformation(sender: string | Address, assetId: bigint): Promise<AccountAssetInformation> {\n const info = await this._algod.accountAssetInformation(sender, Number(assetId)).do()\n\n return {\n assetId: BigInt(assetId),\n balance: BigInt(info.assetHolding?.amount ?? 0),\n frozen: info.assetHolding?.isFrozen === true,\n round: BigInt(info['round']),\n }\n }\n\n /**\n * Opt an account in to a list of Algorand Standard Assets.\n *\n * Transactions will be sent in batches of 16 as transaction groups.\n *\n * @param account The account to opt-in\n * @param assetIds The list of asset IDs to opt-in to\n * @param options Any parameters to control the transaction or execution of the transaction\n * @example Example using AlgorandClient\n * ```typescript\n * // Basic example\n * assetManager.bulkOptIn(\"ACCOUNTADDRESS\", [12345n, 67890n])\n * // With configuration\n * assetManager.bulkOptIn(\"ACCOUNTADDRESS\", [12345n, 67890n], { maxFee: (1000).microAlgo(), suppressLog: true })\n * ```\n * @returns An array of records matching asset ID to transaction ID of the opt in\n */\n async bulkOptIn(\n account: string | Address,\n assetIds: bigint[],\n options?: Omit<CommonTransactionParams, 'sender'> & SendParams,\n ): Promise<BulkAssetOptInOutResult[]> {\n const results: BulkAssetOptInOutResult[] = []\n\n for (const assetGroup of chunkArray(assetIds, MAX_TRANSACTION_GROUP_SIZE)) {\n const composer = this._newGroup()\n\n for (const assetId of assetGroup) {\n composer.addAssetOptIn({\n ...options,\n sender: account,\n assetId: BigInt(assetId),\n })\n }\n\n const result = await composer.send(options)\n\n Config.getLogger(options?.suppressLog).info(\n `Successfully opted in ${account} for assets ${assetGroup.join(', ')} with transaction IDs ${result.txIds.join(', ')}` +\n `\\n Grouped under ${result.groupId} in round ${result.confirmations?.[0]?.confirmedRound}.`,\n )\n\n assetGroup.forEach((assetId, index) => {\n results.push({ assetId: BigInt(assetId), transactionId: result.txIds[index] })\n })\n }\n\n return results\n }\n\n /**\n * Opt an account out of a list of Algorand Standard Assets.\n *\n * Transactions will be sent in batches of 16 as transaction groups.\n *\n * @param account The account to opt-in\n * @param assetIds The list of asset IDs to opt-out of\n * @param options Any parameters to control the transaction or execution of the transaction\n * @example Example using AlgorandClient\n * ```typescript\n * // Basic example\n * assetManager.bulkOptOut(\"ACCOUNTADDRESS\", [12345n, 67890n])\n * // With configuration\n * assetManager.bulkOptOut(\"ACCOUNTADDRESS\", [12345n, 67890n], { ensureZeroBalance: true, maxFee: (1000).microAlgo(), suppressLog: true })\n * ```\n * @returns An array of records matching asset ID to transaction ID of the opt in\n */\n async bulkOptOut(\n account: string | Address,\n assetIds: bigint[],\n options?: Omit<CommonTransactionParams, 'sender'> &\n SendParams & {\n /** Whether or not to check if the account has a zero balance for each asset first or not.\n *\n * Defaults to `true`.\n *\n * If this is set to `true` and the account has an asset balance it will throw an error.\n *\n * If this is set to `false` and the account has an asset balance it will lose those assets to the asset creator.\n */\n ensureZeroBalance?: boolean\n },\n ): Promise<BulkAssetOptInOutResult[]> {\n const results: BulkAssetOptInOutResult[] = []\n\n for (const assetGroup of chunkArray(assetIds, MAX_TRANSACTION_GROUP_SIZE)) {\n const composer = this._newGroup()\n\n const notOptedInAssetIds: bigint[] = []\n const nonZeroBalanceAssetIds: bigint[] = []\n for (const assetId of assetGroup) {\n if (options?.ensureZeroBalance !== false) {\n try {\n const accountAssetInfo = await this.getAccountInformation(account, assetId)\n if (accountAssetInfo.balance !== 0n) {\n nonZeroBalanceAssetIds.push(BigInt(assetId))\n }\n } catch {\n notOptedInAssetIds.push(BigInt(assetId))\n }\n }\n }\n\n if (notOptedInAssetIds.length > 0 || nonZeroBalanceAssetIds.length > 0) {\n throw new Error(\n `Account ${account}${notOptedInAssetIds.length > 0 ? ` is not opted-in to Asset${notOptedInAssetIds.length > 1 ? 's' : ''} ${notOptedInAssetIds.join(', ')}` : ''}${\n nonZeroBalanceAssetIds.length > 0\n ? ` has non-zero balance for Asset${nonZeroBalanceAssetIds.length > 1 ? 's' : ''} ${nonZeroBalanceAssetIds.join(', ')}`\n : ''\n }; can't opt-out.`,\n )\n }\n\n for (const assetId of assetGroup) {\n composer.addAssetOptOut({\n ...options,\n creator: (await this.getById(BigInt(assetId))).creator,\n sender: account,\n assetId: BigInt(assetId),\n })\n }\n\n const result = await composer.send(options)\n\n Config.getLogger(options?.suppressLog).info(\n `Successfully opted ${account} out of assets ${assetGroup.join(', ')} with transaction IDs ${result.txIds.join(', ')}` +\n `\\n Grouped under ${result.groupId} in round ${result.confirmations?.[0]?.confirmedRound}.`,\n )\n\n assetGroup.forEach((assetId, index) => {\n results.push({ assetId: BigInt(assetId), transactionId: result.txIds[index] })\n })\n }\n\n return results\n }\n}\n"],"mappings":";;;;;AAyIA,IAAa,eAAb,MAA0B;CACxB;CACA;;;;;;;;;;CAWA,YAAY,OAAwB,UAAqC;EACvE,KAAK,SAAS;EACd,KAAK,YAAY;CACnB;;;;;;;;;;;;CAaA,MAAa,QAAQ,SAA4C;EAC/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IAAI,EAAA,oBAC5F,OAAO,QAAQ,YAAY,OAAO,gBAAgB,EAAE,EAAE,eAAe,EAC9F;GAEA,WAAW,SAAS,SAAS,UAAU;IACrC,QAAQ,KAAK;KAAE,SAAS,OAAO,OAAO;KAAG,eAAe,OAAO,MAAM;IAAO,CAAC;GAC/E,CAAC;EACH;EAEA,OAAO;CACT;AACF"}
package/types/asset.d.ts CHANGED
@@ -1,99 +1,103 @@
1
- import algosdk from 'algosdk';
2
- import { AlgoAmount } from './amount';
3
- import { SendTransactionFrom, SendTransactionParams, TransactionNote } from './transaction';
4
- import SuggestedParams = algosdk.SuggestedParams;
1
+ import { AlgoAmount } from "./amount.js";
2
+ import { SendTransactionFrom, SendTransactionParams, TransactionNote } from "./transaction.js";
3
+ import algosdk from "algosdk";
4
+
5
+ //#region src/types/asset.d.ts
5
6
  /** @deprecated Parameters for `createAsset` call. */
6
- export interface CreateAssetParams extends SendTransactionParams {
7
- /** The account to create the asset.
8
- *
9
- * This account automatically is opted in to the asset and holds all units after creation. */
10
- creator: SendTransactionFrom;
11
- /** The total number of base (decimal) units of the asset to create.
12
- * If decimal is, say, 2, then for every 100 `total` there would be 1 whole unit.
13
- * This field can only be specified upon asset creation.
14
- */
15
- total: number | bigint;
16
- /** The number of digits to use after the decimal point when displaying the asset.
17
- * If 0, the asset is not divisible.
18
- * If 1, the base unit of the asset is in tenths.
19
- * If 2, the base unit of the asset is in hundredths.
20
- * If 3, the base unit of the asset is in thousandths, and so on up to 19 decimal places.
21
- * This field can only be specified upon asset creation.
22
- */
23
- decimals: number;
24
- /** The optional name of the asset. Max size if 32 bytes. This field can only be specified upon asset creation. */
25
- name?: string;
26
- /** The optional name of the unit of this asset. Max size is 8 bytes. This field can only be specified upon asset creation. */
27
- unit?: string;
28
- /** Specifies an optional URL where more information about the asset can be retrieved. Max size is 96 bytes.
29
- * This field can only be specified upon asset creation.
30
- */
31
- url?: string;
32
- /** This field is intended to be a 32-byte hash of some metadata that is relevant to your asset and/or asset holders.
33
- * The format of this metadata is up to the application. This field can only be specified upon asset creation.
34
- */
35
- metadataHash?: string | Uint8Array;
36
- /** The optional account that can manage the configuration of the asset and destroy it.
37
- * If not set at asset creation or subsequently set to empty by the manager the asset becomes immutable.
38
- */
39
- manager?: string | SendTransactionFrom;
40
- /** The optional account that holds the reserve (non-minted) units of the asset. This address has no specific authority in the protocol itself and is informational.
41
- * Some standards like [ARC-19](https://github.com/algorandfoundation/ARCs/blob/main/ARCs/arc-0019.md) rely on this field to hold meaningful data.
42
- * It is used in the case where you want to signal to holders of your asset that the non-minted units of the asset reside in an account that is different from the default creator account.
43
- * If not set at asset creation or subsequently set to empty by the manager the field is permanently empty.
44
- */
45
- reserveAccount?: string | SendTransactionFrom;
46
- /** The optional account that can be used to freeze holdings of this asset. If empty, freezing is not permitted.
47
- * If not set at asset creation or subsequently set to empty by the manager the field is permanently empty.
48
- */
49
- freezeAccount?: string | SendTransactionFrom;
50
- /** The optional account that can clawback holdings of this asset. If empty, clawback is not permitted.
51
- * If not set at asset creation or subsequently set to empty by the manager the field is permanently empty.
52
- */
53
- clawbackAccount?: string | SendTransactionFrom;
54
- /** Whether to freeze holdings for this asset by default. If `true` then for anyone apart from the creator to hold the asset it needs to be unfrozen per account using `freeze`. Defaults to `false`. */
55
- frozenByDefault?: boolean;
56
- /** Optional transaction parameters */
57
- transactionParams?: SuggestedParams;
58
- /** The (optional) transaction note */
59
- note?: TransactionNote;
60
- /** An (optional) [transaction lease](https://dev.algorand.co/concepts/transactions/leases) to apply */
61
- lease?: string | Uint8Array;
7
+ interface CreateAssetParams extends SendTransactionParams {
8
+ /** The account to create the asset.
9
+ *
10
+ * This account automatically is opted in to the asset and holds all units after creation. */
11
+ creator: SendTransactionFrom;
12
+ /** The total number of base (decimal) units of the asset to create.
13
+ * If decimal is, say, 2, then for every 100 `total` there would be 1 whole unit.
14
+ * This field can only be specified upon asset creation.
15
+ */
16
+ total: number | bigint;
17
+ /** The number of digits to use after the decimal point when displaying the asset.
18
+ * If 0, the asset is not divisible.
19
+ * If 1, the base unit of the asset is in tenths.
20
+ * If 2, the base unit of the asset is in hundredths.
21
+ * If 3, the base unit of the asset is in thousandths, and so on up to 19 decimal places.
22
+ * This field can only be specified upon asset creation.
23
+ */
24
+ decimals: number;
25
+ /** The optional name of the asset. Max size if 32 bytes. This field can only be specified upon asset creation. */
26
+ name?: string;
27
+ /** The optional name of the unit of this asset. Max size is 8 bytes. This field can only be specified upon asset creation. */
28
+ unit?: string;
29
+ /** Specifies an optional URL where more information about the asset can be retrieved. Max size is 96 bytes.
30
+ * This field can only be specified upon asset creation.
31
+ */
32
+ url?: string;
33
+ /** This field is intended to be a 32-byte hash of some metadata that is relevant to your asset and/or asset holders.
34
+ * The format of this metadata is up to the application. This field can only be specified upon asset creation.
35
+ */
36
+ metadataHash?: string | Uint8Array;
37
+ /** The optional account that can manage the configuration of the asset and destroy it.
38
+ * If not set at asset creation or subsequently set to empty by the manager the asset becomes immutable.
39
+ */
40
+ manager?: string | SendTransactionFrom;
41
+ /** The optional account that holds the reserve (non-minted) units of the asset. This address has no specific authority in the protocol itself and is informational.
42
+ * Some standards like [ARC-19](https://github.com/algorandfoundation/ARCs/blob/main/ARCs/arc-0019.md) rely on this field to hold meaningful data.
43
+ * It is used in the case where you want to signal to holders of your asset that the non-minted units of the asset reside in an account that is different from the default creator account.
44
+ * If not set at asset creation or subsequently set to empty by the manager the field is permanently empty.
45
+ */
46
+ reserveAccount?: string | SendTransactionFrom;
47
+ /** The optional account that can be used to freeze holdings of this asset. If empty, freezing is not permitted.
48
+ * If not set at asset creation or subsequently set to empty by the manager the field is permanently empty.
49
+ */
50
+ freezeAccount?: string | SendTransactionFrom;
51
+ /** The optional account that can clawback holdings of this asset. If empty, clawback is not permitted.
52
+ * If not set at asset creation or subsequently set to empty by the manager the field is permanently empty.
53
+ */
54
+ clawbackAccount?: string | SendTransactionFrom;
55
+ /** Whether to freeze holdings for this asset by default. If `true` then for anyone apart from the creator to hold the asset it needs to be unfrozen per account using `freeze`. Defaults to `false`. */
56
+ frozenByDefault?: boolean;
57
+ /** Optional transaction parameters */
58
+ transactionParams?: SuggestedParams;
59
+ /** The (optional) transaction note */
60
+ note?: TransactionNote;
61
+ /** An (optional) [transaction lease](https://dev.algorand.co/concepts/transactions/leases) to apply */
62
+ lease?: string | Uint8Array;
62
63
  }
63
64
  /** @deprecated Parameters for `assetOptIn` call. */
64
- export interface AssetOptInParams extends SendTransactionParams {
65
- /** The account to opt in/out for */
66
- account: SendTransactionFrom;
67
- /** The ID of the assets to opt in for / out of */
68
- assetId: number;
69
- /** Optional transaction parameters */
70
- transactionParams?: SuggestedParams;
71
- /** The (optional) transaction note */
72
- note?: TransactionNote;
73
- /** An (optional) [transaction lease](https://dev.algorand.co/concepts/transactions/leases) to apply */
74
- lease?: string | Uint8Array;
65
+ interface AssetOptInParams extends SendTransactionParams {
66
+ /** The account to opt in/out for */
67
+ account: SendTransactionFrom;
68
+ /** The ID of the assets to opt in for / out of */
69
+ assetId: number;
70
+ /** Optional transaction parameters */
71
+ transactionParams?: SuggestedParams;
72
+ /** The (optional) transaction note */
73
+ note?: TransactionNote;
74
+ /** An (optional) [transaction lease](https://dev.algorand.co/concepts/transactions/leases) to apply */
75
+ lease?: string | Uint8Array;
75
76
  }
76
77
  /** @deprecated Parameters for `assetOptOut` call. */
77
- export interface AssetOptOutParams extends AssetOptInParams {
78
- /** The address of the creator account for the asset; if unspecified then it looks it up using algod */
79
- assetCreatorAddress?: string;
80
- /** Whether or not to validate the account has a zero-balance before issuing the opt-out; default = true */
81
- ensureZeroBalance?: boolean;
78
+ interface AssetOptOutParams extends AssetOptInParams {
79
+ /** The address of the creator account for the asset; if unspecified then it looks it up using algod */
80
+ assetCreatorAddress?: string;
81
+ /** Whether or not to validate the account has a zero-balance before issuing the opt-out; default = true */
82
+ ensureZeroBalance?: boolean;
82
83
  }
83
84
  /** @deprecated Parameters for `assetBulkOptIn` / `assetBulkOptOut` call. */
84
- export interface AssetBulkOptInOutParams {
85
- /** The account to opt in/out for */
86
- account: SendTransactionFrom;
87
- /** The IDs of the assets to opt in for / out of */
88
- assetIds: number[];
89
- /** Whether or not to validate the opt-in/out is valid before issuing transactions; default = true */
90
- validateBalances?: boolean;
91
- /** Optional transaction parameters */
92
- transactionParams?: SuggestedParams;
93
- /** The (optional) transaction note */
94
- note?: TransactionNote;
95
- /** The maximum fee that you are happy to pay per transaction (default: unbounded) - if this is set it's possible the transaction could get rejected during network congestion */
96
- maxFee?: AlgoAmount;
97
- /** Whether to suppress log messages from transaction send, default: do not suppress */
98
- suppressLog?: boolean;
85
+ interface AssetBulkOptInOutParams {
86
+ /** The account to opt in/out for */
87
+ account: SendTransactionFrom;
88
+ /** The IDs of the assets to opt in for / out of */
89
+ assetIds: number[];
90
+ /** Whether or not to validate the opt-in/out is valid before issuing transactions; default = true */
91
+ validateBalances?: boolean;
92
+ /** Optional transaction parameters */
93
+ transactionParams?: SuggestedParams;
94
+ /** The (optional) transaction note */
95
+ note?: TransactionNote;
96
+ /** The maximum fee that you are happy to pay per transaction (default: unbounded) - if this is set it's possible the transaction could get rejected during network congestion */
97
+ maxFee?: AlgoAmount;
98
+ /** Whether to suppress log messages from transaction send, default: do not suppress */
99
+ suppressLog?: boolean;
99
100
  }
101
+ //#endregion
102
+ export { AssetBulkOptInOutParams, AssetOptInParams, AssetOptOutParams, CreateAssetParams };
103
+ //# sourceMappingURL=asset.d.ts.map