@algorandfoundation/algokit-utils 7.0.0 → 8.0.0-beta.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (148) hide show
  1. package/README.md +14 -3
  2. package/account/account.d.ts +4 -1
  3. package/account/account.js +4 -3
  4. package/account/account.js.map +1 -1
  5. package/account/account.mjs +5 -4
  6. package/account/account.mjs.map +1 -1
  7. package/account/get-dispenser-account.d.ts +1 -1
  8. package/amount.d.ts +1 -0
  9. package/amount.js +3 -2
  10. package/amount.js.map +1 -1
  11. package/amount.mjs +3 -3
  12. package/amount.mjs.map +1 -1
  13. package/app-client.d.ts +4 -4
  14. package/app-client.js +4 -4
  15. package/app-client.js.map +1 -1
  16. package/app-client.mjs +4 -4
  17. package/app-client.mjs.map +1 -1
  18. package/app-deploy.js +23 -5
  19. package/app-deploy.js.map +1 -1
  20. package/app-deploy.mjs +24 -6
  21. package/app-deploy.mjs.map +1 -1
  22. package/app.js +7 -4
  23. package/app.js.map +1 -1
  24. package/app.mjs +7 -4
  25. package/app.mjs.map +1 -1
  26. package/index.js +1 -1
  27. package/index.mjs +2 -2
  28. package/indexer-lookup.d.ts +10 -8
  29. package/indexer-lookup.js +14 -10
  30. package/indexer-lookup.js.map +1 -1
  31. package/indexer-lookup.mjs +14 -10
  32. package/indexer-lookup.mjs.map +1 -1
  33. package/network-client.d.ts +1 -7
  34. package/network-client.js +2 -9
  35. package/network-client.js.map +1 -1
  36. package/network-client.mjs +2 -9
  37. package/network-client.mjs.map +1 -1
  38. package/package.json +2 -2
  39. package/testing/_asset.d.ts +2 -1
  40. package/testing/account.d.ts +4 -3
  41. package/testing/account.js +8 -2
  42. package/testing/account.js.map +1 -1
  43. package/testing/account.mjs +9 -3
  44. package/testing/account.mjs.map +1 -1
  45. package/testing/fixtures/algorand-fixture.js +5 -6
  46. package/testing/fixtures/algorand-fixture.js.map +1 -1
  47. package/testing/fixtures/algorand-fixture.mjs +5 -6
  48. package/testing/fixtures/algorand-fixture.mjs.map +1 -1
  49. package/testing/test-logger.js +7 -1
  50. package/testing/test-logger.js.map +1 -1
  51. package/testing/test-logger.mjs +7 -1
  52. package/testing/test-logger.mjs.map +1 -1
  53. package/transaction/perform-atomic-transaction-composer-simulate.d.ts +4 -1
  54. package/transaction/perform-atomic-transaction-composer-simulate.js +14 -10
  55. package/transaction/perform-atomic-transaction-composer-simulate.js.map +1 -1
  56. package/transaction/perform-atomic-transaction-composer-simulate.mjs +15 -11
  57. package/transaction/perform-atomic-transaction-composer-simulate.mjs.map +1 -1
  58. package/transaction/transaction.d.ts +1 -17
  59. package/transaction/transaction.js +110 -82
  60. package/transaction/transaction.js.map +1 -1
  61. package/transaction/transaction.mjs +112 -83
  62. package/transaction/transaction.mjs.map +1 -1
  63. package/transfer/transfer.js +3 -1
  64. package/transfer/transfer.js.map +1 -1
  65. package/transfer/transfer.mjs +3 -1
  66. package/transfer/transfer.mjs.map +1 -1
  67. package/types/account-manager.d.ts +20 -20
  68. package/types/account-manager.js +27 -20
  69. package/types/account-manager.js.map +1 -1
  70. package/types/account-manager.mjs +28 -21
  71. package/types/account-manager.mjs.map +1 -1
  72. package/types/account.d.ts +8 -8
  73. package/types/account.js +2 -2
  74. package/types/account.js.map +1 -1
  75. package/types/account.mjs +3 -3
  76. package/types/account.mjs.map +1 -1
  77. package/types/algo-http-client-with-retry.d.ts +1 -2
  78. package/types/algo-http-client-with-retry.js +33 -3
  79. package/types/algo-http-client-with-retry.js.map +1 -1
  80. package/types/algo-http-client-with-retry.mjs +32 -2
  81. package/types/algo-http-client-with-retry.mjs.map +1 -1
  82. package/types/algorand-client-transaction-creator.d.ts +11 -11
  83. package/types/algorand-client-transaction-sender.d.ts +97 -97
  84. package/types/algorand-client-transaction-sender.js.map +1 -1
  85. package/types/algorand-client-transaction-sender.mjs.map +1 -1
  86. package/types/algorand-client.d.ts +3 -3
  87. package/types/algorand-client.js +1 -1
  88. package/types/algorand-client.js.map +1 -1
  89. package/types/algorand-client.mjs +1 -1
  90. package/types/algorand-client.mjs.map +1 -1
  91. package/types/app-client.d.ts +280 -279
  92. package/types/app-client.js +10 -10
  93. package/types/app-client.js.map +1 -1
  94. package/types/app-client.mjs +11 -11
  95. package/types/app-client.mjs.map +1 -1
  96. package/types/app-deployer.d.ts +4 -4
  97. package/types/app-deployer.js +22 -23
  98. package/types/app-deployer.js.map +1 -1
  99. package/types/app-deployer.mjs +23 -24
  100. package/types/app-deployer.mjs.map +1 -1
  101. package/types/app-factory.d.ts +128 -138
  102. package/types/app-factory.js +4 -3
  103. package/types/app-factory.js.map +1 -1
  104. package/types/app-factory.mjs +5 -4
  105. package/types/app-factory.mjs.map +1 -1
  106. package/types/app-manager.d.ts +5 -5
  107. package/types/app-manager.js +11 -15
  108. package/types/app-manager.js.map +1 -1
  109. package/types/app-manager.mjs +12 -16
  110. package/types/app-manager.mjs.map +1 -1
  111. package/types/app.d.ts +4 -4
  112. package/types/app.js.map +1 -1
  113. package/types/app.mjs.map +1 -1
  114. package/types/asset-manager.d.ts +5 -5
  115. package/types/asset-manager.js +8 -11
  116. package/types/asset-manager.js.map +1 -1
  117. package/types/asset-manager.mjs +8 -11
  118. package/types/asset-manager.mjs.map +1 -1
  119. package/types/client-manager.d.ts +2 -9
  120. package/types/client-manager.js +9 -19
  121. package/types/client-manager.js.map +1 -1
  122. package/types/client-manager.mjs +9 -19
  123. package/types/client-manager.mjs.map +1 -1
  124. package/types/composer.d.ts +22 -22
  125. package/types/composer.js +73 -83
  126. package/types/composer.js.map +1 -1
  127. package/types/composer.mjs +74 -84
  128. package/types/composer.mjs.map +1 -1
  129. package/types/dispenser-client.d.ts +2 -1
  130. package/types/dispenser-client.js +5 -1
  131. package/types/dispenser-client.js.map +1 -1
  132. package/types/dispenser-client.mjs +5 -1
  133. package/types/dispenser-client.mjs.map +1 -1
  134. package/types/indexer.d.ts +74 -755
  135. package/types/indexer.js.map +1 -1
  136. package/types/indexer.mjs.map +1 -1
  137. package/types/kmd-account-manager.d.ts +2 -2
  138. package/types/kmd-account-manager.js.map +1 -1
  139. package/types/kmd-account-manager.mjs.map +1 -1
  140. package/types/network-client.d.ts +1 -1
  141. package/types/network-client.js.map +1 -1
  142. package/types/network-client.mjs.map +1 -1
  143. package/types/testing.d.ts +5 -6
  144. package/types/urlTokenBaseHTTPClient.d.ts +0 -40
  145. package/types/urlTokenBaseHTTPClient.js +0 -153
  146. package/types/urlTokenBaseHTTPClient.js.map +0 -1
  147. package/types/urlTokenBaseHTTPClient.mjs +0 -151
  148. package/types/urlTokenBaseHTTPClient.mjs.map +0 -1
@@ -1,5 +1,5 @@
1
- import algosdk from 'algosdk';
2
- import { AccountAssetInformation, TransactionSignerAccount } from './account';
1
+ import algosdk, { Address } from 'algosdk';
2
+ import { AccountAssetInformation } from './account';
3
3
  import { CommonTransactionParams, TransactionComposer } from './composer';
4
4
  import { SendParams } from './transaction';
5
5
  /** Individual result from performing a bulk opt-in or bulk opt-out for an account against a series of assets. */
@@ -155,7 +155,7 @@ export declare class AssetManager {
155
155
  * @param assetId The ID of the asset to return a holding for
156
156
  * @returns The account asset holding information
157
157
  */
158
- getAccountInformation(sender: string | TransactionSignerAccount, assetId: bigint): Promise<AccountAssetInformation>;
158
+ getAccountInformation(sender: string | Address, assetId: bigint): Promise<AccountAssetInformation>;
159
159
  /**
160
160
  * Opt an account in to a list of Algorand Standard Assets.
161
161
  *
@@ -173,7 +173,7 @@ export declare class AssetManager {
173
173
  * ```
174
174
  * @returns An array of records matching asset ID to transaction ID of the opt in
175
175
  */
176
- bulkOptIn(account: string | TransactionSignerAccount, assetIds: bigint[], options?: Omit<CommonTransactionParams, 'sender'> & SendParams): Promise<BulkAssetOptInOutResult[]>;
176
+ bulkOptIn(account: string | Address, assetIds: bigint[], options?: Omit<CommonTransactionParams, 'sender'> & SendParams): Promise<BulkAssetOptInOutResult[]>;
177
177
  /**
178
178
  * Opt an account out of a list of Algorand Standard Assets.
179
179
  *
@@ -191,7 +191,7 @@ export declare class AssetManager {
191
191
  * ```
192
192
  * @returns An array of records matching asset ID to transaction ID of the opt in
193
193
  */
194
- bulkOptOut(account: string | TransactionSignerAccount, assetIds: bigint[], options?: Omit<CommonTransactionParams, 'sender'> & SendParams & {
194
+ bulkOptOut(account: string | Address, assetIds: bigint[], options?: Omit<CommonTransactionParams, 'sender'> & SendParams & {
195
195
  /** Whether or not to check if the account has a zero balance for each asset first or not.
196
196
  *
197
197
  * Defaults to `true`.
@@ -1,11 +1,9 @@
1
1
  'use strict';
2
2
 
3
- var algosdk = require('algosdk');
4
3
  var config = require('../config.js');
5
4
  var util = require('../util.js');
6
5
  var types_composer = require('./composer.js');
7
6
 
8
- var AssetModel = algosdk.modelsv2.Asset;
9
7
  /** Allows management of asset information. */
10
8
  class AssetManager {
11
9
  /**
@@ -33,7 +31,7 @@ class AssetManager {
33
31
  * @returns The asset information
34
32
  */
35
33
  async getById(assetId) {
36
- const asset = AssetModel.from_obj_for_encoding(await this._algod.getAssetByID(Number(assetId)).do());
34
+ const asset = await this._algod.getAssetByID(Number(assetId)).do();
37
35
  return {
38
36
  assetId: BigInt(asset.index),
39
37
  total: BigInt(asset.params.total),
@@ -69,11 +67,11 @@ class AssetManager {
69
67
  * @returns The account asset holding information
70
68
  */
71
69
  async getAccountInformation(sender, assetId) {
72
- const info = await this._algod.accountAssetInformation(typeof sender === 'string' ? sender : sender.addr, Number(assetId)).do();
70
+ const info = await this._algod.accountAssetInformation(sender, Number(assetId)).do();
73
71
  return {
74
72
  assetId: BigInt(assetId),
75
- balance: BigInt(info['asset-holding']['amount']),
76
- frozen: info['asset-holding']['is-frozen'] === true,
73
+ balance: BigInt(info.assetHolding?.amount ?? 0),
74
+ frozen: info.assetHolding?.isFrozen === true,
77
75
  round: BigInt(info['round']),
78
76
  };
79
77
  }
@@ -101,7 +99,7 @@ class AssetManager {
101
99
  for (const assetId of assetGroup) {
102
100
  composer.addAssetOptIn({
103
101
  ...options,
104
- sender: typeof account === 'string' ? account : account.addr,
102
+ sender: account,
105
103
  assetId: BigInt(assetId),
106
104
  });
107
105
  }
@@ -133,7 +131,6 @@ class AssetManager {
133
131
  */
134
132
  async bulkOptOut(account, assetIds, options) {
135
133
  const results = [];
136
- const sender = typeof account === 'string' ? account : account.addr;
137
134
  for (const assetGroup of util.chunkArray(assetIds, types_composer.MAX_TRANSACTION_GROUP_SIZE)) {
138
135
  const composer = this._newGroup();
139
136
  const notOptedInAssetIds = [];
@@ -141,7 +138,7 @@ class AssetManager {
141
138
  for (const assetId of assetGroup) {
142
139
  if (options?.ensureZeroBalance !== false) {
143
140
  try {
144
- const accountAssetInfo = await this.getAccountInformation(sender, assetId);
141
+ const accountAssetInfo = await this.getAccountInformation(account, assetId);
145
142
  if (accountAssetInfo.balance !== 0n) {
146
143
  nonZeroBalanceAssetIds.push(BigInt(assetId));
147
144
  }
@@ -152,7 +149,7 @@ class AssetManager {
152
149
  }
153
150
  }
154
151
  if (notOptedInAssetIds.length > 0 || nonZeroBalanceAssetIds.length > 0) {
155
- throw new Error(`Account ${sender}${notOptedInAssetIds.length > 0 ? ` is not opted-in to Asset${notOptedInAssetIds.length > 1 ? 's' : ''} ${notOptedInAssetIds.join(', ')}` : ''}${nonZeroBalanceAssetIds.length > 0
152
+ throw new Error(`Account ${account}${notOptedInAssetIds.length > 0 ? ` is not opted-in to Asset${notOptedInAssetIds.length > 1 ? 's' : ''} ${notOptedInAssetIds.join(', ')}` : ''}${nonZeroBalanceAssetIds.length > 0
156
153
  ? ` has non-zero balance for Asset${nonZeroBalanceAssetIds.length > 1 ? 's' : ''} ${nonZeroBalanceAssetIds.join(', ')}`
157
154
  : ''}; can't opt-out.`);
158
155
  }
@@ -160,7 +157,7 @@ class AssetManager {
160
157
  composer.addAssetOptOut({
161
158
  ...options,
162
159
  creator: (await this.getById(BigInt(assetId))).creator,
163
- sender,
160
+ sender: account,
164
161
  assetId: BigInt(assetId),
165
162
  });
166
163
  }
@@ -1 +1 @@
1
- {"version":3,"file":"asset-manager.js","sources":["../../src/types/asset-manager.ts"],"sourcesContent":["import algosdk from 'algosdk'\nimport { Config } from '../config'\nimport { chunkArray } from '../util'\nimport { AccountAssetInformation, TransactionSignerAccount } from './account'\nimport { CommonTransactionParams, MAX_TRANSACTION_GROUP_SIZE, TransactionComposer } from './composer'\nimport { SendParams } from './transaction'\nimport AssetModel = algosdk.modelsv2.Asset\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 = AssetModel.from_obj_for_encoding(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 algorand.asset.getAccountInformation(address, assetId);\n * ```\n *\n * [Response data schema details](https://developer.algorand.org/docs/rest-apis/algod/#get-v2accountsaddressassetsasset-id)\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 | TransactionSignerAccount, assetId: bigint): Promise<AccountAssetInformation> {\n const info = await this._algod.accountAssetInformation(typeof sender === 'string' ? sender : sender.addr, Number(assetId)).do()\n\n return {\n assetId: BigInt(assetId),\n balance: BigInt(info['asset-holding']['amount']),\n frozen: info['asset-holding']['is-frozen'] === 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 * algorand.asset.bulkOptIn(\"ACCOUNTADDRESS\", [12345n, 67890n])\n * // With configuration\n * algorand.asset.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 | TransactionSignerAccount,\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: typeof account === 'string' ? account : account.addr,\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 * algorand.asset.bulkOptOut(\"ACCOUNTADDRESS\", [12345n, 67890n])\n * // With configuration\n * algorand.asset.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 | TransactionSignerAccount,\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 const sender = typeof account === 'string' ? account : account.addr\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(sender, 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 ${sender}${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,\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":["chunkArray","MAX_TRANSACTION_GROUP_SIZE","Config"],"mappings":";;;;;;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AC;AAE3C,YAAAC,aAAM,CAAC,SAAS,CAAC,OAAO,EAAE,WAAW,CAAC,CAAC,IAAI,CACzC,CAAsB,mBAAA,EAAA,OAAO,CAAkB,eAAA,EAAA,UAAU,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA,sBAAA,EAAyB,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAE,CAAA;AACpH,gBAAA,CAAA,kBAAA,EAAqB,MAAM,CAAC,OAAO,CAAA,UAAA,EAAa,MAAM,CAAC,aAAa,GAAG,CAAC,CAAC,EAAE,cAAc,CAAA,CAAA,CAAG,CAC/F;YAED,UAAU,CAAC,OAAO,CAAC,CAAC,OAAO,EAAE,KAAK,KAAI;gBACpC,OAAO,CAAC,IAAI,CAAC,EAAE,OAAO,EAAE,MAAM,CAAC,OAAO,CAAC,EAAE,aAAa,EAAE,MAAM,CAAC,KAAK,CAAC,KAAK,CAAC,EAAE,CAAC;AAChF,aAAC,CAAC;;AAGJ,QAAA,OAAO,OAAO;;AAEjB;;;;"}
1
+ {"version":3,"file":"asset-manager.js","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 algorand.asset.getAccountInformation(address, assetId);\n * ```\n *\n * [Response data schema details](https://developer.algorand.org/docs/rest-apis/algod/#get-v2accountsaddressassetsasset-id)\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 * algorand.asset.bulkOptIn(\"ACCOUNTADDRESS\", [12345n, 67890n])\n * // With configuration\n * algorand.asset.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 * algorand.asset.bulkOptOut(\"ACCOUNTADDRESS\", [12345n, 67890n])\n * // With configuration\n * algorand.asset.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":["chunkArray","MAX_TRANSACTION_GROUP_SIZE","Config"],"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,YAAY,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,EAAE;QAElE,OAAO;AACL,YAAA,OAAO,EAAE,MAAM,CAAC,KAAK,CAAC,KAAK,CAAC;YAC5B,KAAK,EAAE,MAAM,CAAC,KAAK,CAAC,MAAM,CAAC,KAAK,CAAC;YACjC,QAAQ,EAAE,MAAM,CAAC,KAAK,CAAC,MAAM,CAAC,QAAQ,CAAC;AACvC,YAAA,SAAS,EAAE,KAAK,CAAC,MAAM,CAAC,IAAI;AAC5B,YAAA,gBAAgB,EAAE,KAAK,CAAC,MAAM,CAAC,OAAO;AACtC,YAAA,QAAQ,EAAE,KAAK,CA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E,CAAC,MAAM,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,EAAE,OAAO;AACtD,oBAAA,MAAM,EAAE,OAAO;AACf,oBAAA,OAAO,EAAE,MAAM,CAAC,OAAO,CAAC;AACzB,iBAAA,CAAC;;YAGJ,MAAM,MAAM,GAAG,MAAM,QAAQ,CAAC,IAAI,CAAC,OAAO,CAAC;AAE3C,YAAAC,aAAM,CAAC,SAAS,CAAC,OAAO,EAAE,WAAW,CAAC,CAAC,IAAI,CACzC,CAAsB,mBAAA,EAAA,OAAO,CAAkB,eAAA,EAAA,UAAU,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA,sBAAA,EAAyB,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAE,CAAA;AACpH,gBAAA,CAAA,kBAAA,EAAqB,MAAM,CAAC,OAAO,CAAA,UAAA,EAAa,MAAM,CAAC,aAAa,GAAG,CAAC,CAAC,EAAE,cAAc,CAAA,CAAA,CAAG,CAC/F;YAED,UAAU,CAAC,OAAO,CAAC,CAAC,OAAO,EAAE,KAAK,KAAI;gBACpC,OAAO,CAAC,IAAI,CAAC,EAAE,OAAO,EAAE,MAAM,CAAC,OAAO,CAAC,EAAE,aAAa,EAAE,MAAM,CAAC,KAAK,CAAC,KAAK,CAAC,EAAE,CAAC;AAChF,aAAC,CAAC;;AAGJ,QAAA,OAAO,OAAO;;AAEjB;;;;"}
@@ -1,9 +1,7 @@
1
- import algosdk from 'algosdk';
2
1
  import { Config } from '../config.mjs';
3
2
  import { chunkArray } from '../util.mjs';
4
3
  import { MAX_TRANSACTION_GROUP_SIZE } from './composer.mjs';
5
4
 
6
- var AssetModel = algosdk.modelsv2.Asset;
7
5
  /** Allows management of asset information. */
8
6
  class AssetManager {
9
7
  /**
@@ -31,7 +29,7 @@ class AssetManager {
31
29
  * @returns The asset information
32
30
  */
33
31
  async getById(assetId) {
34
- const asset = AssetModel.from_obj_for_encoding(await this._algod.getAssetByID(Number(assetId)).do());
32
+ const asset = await this._algod.getAssetByID(Number(assetId)).do();
35
33
  return {
36
34
  assetId: BigInt(asset.index),
37
35
  total: BigInt(asset.params.total),
@@ -67,11 +65,11 @@ class AssetManager {
67
65
  * @returns The account asset holding information
68
66
  */
69
67
  async getAccountInformation(sender, assetId) {
70
- const info = await this._algod.accountAssetInformation(typeof sender === 'string' ? sender : sender.addr, Number(assetId)).do();
68
+ const info = await this._algod.accountAssetInformation(sender, Number(assetId)).do();
71
69
  return {
72
70
  assetId: BigInt(assetId),
73
- balance: BigInt(info['asset-holding']['amount']),
74
- frozen: info['asset-holding']['is-frozen'] === true,
71
+ balance: BigInt(info.assetHolding?.amount ?? 0),
72
+ frozen: info.assetHolding?.isFrozen === true,
75
73
  round: BigInt(info['round']),
76
74
  };
77
75
  }
@@ -99,7 +97,7 @@ class AssetManager {
99
97
  for (const assetId of assetGroup) {
100
98
  composer.addAssetOptIn({
101
99
  ...options,
102
- sender: typeof account === 'string' ? account : account.addr,
100
+ sender: account,
103
101
  assetId: BigInt(assetId),
104
102
  });
105
103
  }
@@ -131,7 +129,6 @@ class AssetManager {
131
129
  */
132
130
  async bulkOptOut(account, assetIds, options) {
133
131
  const results = [];
134
- const sender = typeof account === 'string' ? account : account.addr;
135
132
  for (const assetGroup of chunkArray(assetIds, MAX_TRANSACTION_GROUP_SIZE)) {
136
133
  const composer = this._newGroup();
137
134
  const notOptedInAssetIds = [];
@@ -139,7 +136,7 @@ class AssetManager {
139
136
  for (const assetId of assetGroup) {
140
137
  if (options?.ensureZeroBalance !== false) {
141
138
  try {
142
- const accountAssetInfo = await this.getAccountInformation(sender, assetId);
139
+ const accountAssetInfo = await this.getAccountInformation(account, assetId);
143
140
  if (accountAssetInfo.balance !== 0n) {
144
141
  nonZeroBalanceAssetIds.push(BigInt(assetId));
145
142
  }
@@ -150,7 +147,7 @@ class AssetManager {
150
147
  }
151
148
  }
152
149
  if (notOptedInAssetIds.length > 0 || nonZeroBalanceAssetIds.length > 0) {
153
- throw new Error(`Account ${sender}${notOptedInAssetIds.length > 0 ? ` is not opted-in to Asset${notOptedInAssetIds.length > 1 ? 's' : ''} ${notOptedInAssetIds.join(', ')}` : ''}${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
154
151
  ? ` has non-zero balance for Asset${nonZeroBalanceAssetIds.length > 1 ? 's' : ''} ${nonZeroBalanceAssetIds.join(', ')}`
155
152
  : ''}; can't opt-out.`);
156
153
  }
@@ -158,7 +155,7 @@ class AssetManager {
158
155
  composer.addAssetOptOut({
159
156
  ...options,
160
157
  creator: (await this.getById(BigInt(assetId))).creator,
161
- sender,
158
+ sender: account,
162
159
  assetId: BigInt(assetId),
163
160
  });
164
161
  }
@@ -1 +1 @@
1
- {"version":3,"file":"asset-manager.mjs","sources":["../../src/types/asset-manager.ts"],"sourcesContent":["import algosdk from 'algosdk'\nimport { Config } from '../config'\nimport { chunkArray } from '../util'\nimport { AccountAssetInformation, TransactionSignerAccount } from './account'\nimport { CommonTransactionParams, MAX_TRANSACTION_GROUP_SIZE, TransactionComposer } from './composer'\nimport { SendParams } from './transaction'\nimport AssetModel = algosdk.modelsv2.Asset\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 = AssetModel.from_obj_for_encoding(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 algorand.asset.getAccountInformation(address, assetId);\n * ```\n *\n * [Response data schema details](https://developer.algorand.org/docs/rest-apis/algod/#get-v2accountsaddressassetsasset-id)\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 | TransactionSignerAccount, assetId: bigint): Promise<AccountAssetInformation> {\n const info = await this._algod.accountAssetInformation(typeof sender === 'string' ? sender : sender.addr, Number(assetId)).do()\n\n return {\n assetId: BigInt(assetId),\n balance: BigInt(info['asset-holding']['amount']),\n frozen: info['asset-holding']['is-frozen'] === 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 * algorand.asset.bulkOptIn(\"ACCOUNTADDRESS\", [12345n, 67890n])\n * // With configuration\n * algorand.asset.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 | TransactionSignerAccount,\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: typeof account === 'string' ? account : account.addr,\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 * algorand.asset.bulkOptOut(\"ACCOUNTADDRESS\", [12345n, 67890n])\n * // With configuration\n * algorand.asset.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 | TransactionSignerAccount,\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 const sender = typeof account === 'string' ? account : account.addr\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(sender, 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 ${sender}${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,\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":";;;;;AAMA,IAAO,UAAU,GAAG,OAAO,CAAC,QAAQ,CAAC,KAAK;AAmI1C;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;QAClC,MAAM,KAAK,GAAG,UAAU,CAAC,qBAAqB,CAAC,MAAM,IAAI,CAAC,MAAM,CAAC,YAAY,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC;QAEpG,OAAO;AACL,YAAA,OAAO,EAAE,MAAM,CAAC,KAAK,CAAC,KAAK,CAAC;YAC5B,KAAK,EAAE,MAAM,CAAC,KAAK,CAAC,MAAM,CAAC,KAAK,CAAC;YACjC,QAAQ,EAAE,MAAM,CAAC,KAAK,CAAC,MAAM,CAAC,QAAQ,CAAC;AACvC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,"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 algorand.asset.getAccountInformation(address, assetId);\n * ```\n *\n * [Response data schema details](https://developer.algorand.org/docs/rest-apis/algod/#get-v2accountsaddressassetsasset-id)\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 * algorand.asset.bulkOptIn(\"ACCOUNTADDRESS\", [12345n, 67890n])\n * // With configuration\n * algorand.asset.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 * algorand.asset.bulkOptOut(\"ACCOUNTADDRESS\", [12345n, 67890n])\n * // With configuration\n * algorand.asset.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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AO,CAAC,IAAI,CAAC,EAAE,OAAO,EAAE,MAAM,CAAC,OAAO,CAAC,EAAE,aAAa,EAAE,MAAM,CAAC,KAAK,CAAC,KAAK,CAAC,EAAE,CAAC;AAChF,aAAC,CAAC;;AAGJ,QAAA,OAAO,OAAO;;AAEjB;;;;"}
@@ -8,7 +8,6 @@ import { AlgoClientConfig, AlgoConfig, NetworkDetails } from './network-client';
8
8
  import Kmd = algosdk.Kmd;
9
9
  import Indexer = algosdk.Indexer;
10
10
  import Algodv2 = algosdk.Algodv2;
11
- import IntDecoding = algosdk.IntDecoding;
12
11
  /** Clients from algosdk that interact with the official Algorand APIs */
13
12
  export interface AlgoSdkClients {
14
13
  /** Algod client, see https://developer.algorand.org/docs/rest-apis/algod/ */
@@ -343,7 +342,6 @@ export declare class ClientManager {
343
342
  * Returns an indexer SDK client that automatically retries on idempotent calls
344
343
  *
345
344
  * @param config The config of the client
346
- * @param overrideIntDecoding Override the default int decoding for responses, uses MIXED by default to avoid lost precision for big integers
347
345
  * @example AlgoNode (testnet)
348
346
  * ```typescript
349
347
  * const indexer = ClientManager.getIndexerClient(ClientManager.getAlgoNodeConfig('testnet', 'indexer'))
@@ -359,16 +357,11 @@ export declare class ClientManager {
359
357
  * const indexer = ClientManager.getIndexerClient({server: 'http://localhost', port: '8980', token: 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa'})
360
358
  * await indexer.makeHealthCheck().do()
361
359
  * ```
362
- * @example Override int decoding for responses
363
- * ```typescript
364
- * const indexer = ClientManager.getIndexerClient(config, IntDecoding.BIGINT)
365
- * ```
366
360
  */
367
- static getIndexerClient(config: AlgoClientConfig, overrideIntDecoding?: IntDecoding): Indexer;
361
+ static getIndexerClient(config: AlgoClientConfig): Indexer;
368
362
  /**
369
363
  * Returns an indexer SDK client that automatically retries on idempotent calls loaded from environment variables (expects to be called from a Node.js environment).
370
364
  *
371
- * @param overrideIntDecoding Override the default int decoding for responses, uses MIXED by default to avoid lost precision for big integers
372
365
  * @example
373
366
  *
374
367
  * ```typescript
@@ -377,7 +370,7 @@ export declare class ClientManager {
377
370
  * await indexer.makeHealthCheck().do()
378
371
  * ```
379
372
  */
380
- static getIndexerClientFromEnvironment(overrideIntDecoding?: IntDecoding): Indexer;
373
+ static getIndexerClientFromEnvironment(): Indexer;
381
374
  /**
382
375
  * Returns a KMD SDK client.
383
376
  *
@@ -9,7 +9,6 @@ var types_networkClient = require('./network-client.js');
9
9
 
10
10
  var Kmd = algosdk.Kmd;
11
11
  var Indexer = algosdk.Indexer;
12
- var IntDecoding = algosdk.IntDecoding;
13
12
  /** Exposes access to various API clients. */
14
13
  class ClientManager {
15
14
  /**
@@ -80,11 +79,11 @@ class ClientManager {
80
79
  }
81
80
  const params = await this._getNetworkPromise;
82
81
  return {
83
- isTestNet: ['testnet-v1.0', 'testnet-v1', 'testnet'].includes(params.genesisID),
84
- isMainNet: ['mainnet-v1.0', 'mainnet-v1', 'mainnet'].includes(params.genesisID),
85
- isLocalNet: ClientManager.genesisIdIsLocalNet(params.genesisID),
86
- genesisId: params.genesisID,
87
- genesisHash: params.genesisHash,
82
+ isTestNet: ['testnet-v1.0', 'testnet-v1', 'testnet'].includes(params.genesisID ?? 'unknown'),
83
+ isMainNet: ['mainnet-v1.0', 'mainnet-v1', 'mainnet'].includes(params.genesisID ?? 'unknown'),
84
+ isLocalNet: ClientManager.genesisIdIsLocalNet(params.genesisID ?? 'unknown'),
85
+ genesisId: params.genesisID ?? 'unknown',
86
+ genesisHash: params.genesisHash ? Buffer.from(params.genesisHash).toString('base64') : 'unknown',
88
87
  };
89
88
  }
90
89
  /**
@@ -469,7 +468,6 @@ class ClientManager {
469
468
  * Returns an indexer SDK client that automatically retries on idempotent calls
470
469
  *
471
470
  * @param config The config of the client
472
- * @param overrideIntDecoding Override the default int decoding for responses, uses MIXED by default to avoid lost precision for big integers
473
471
  * @example AlgoNode (testnet)
474
472
  * ```typescript
475
473
  * const indexer = ClientManager.getIndexerClient(ClientManager.getAlgoNodeConfig('testnet', 'indexer'))
@@ -485,24 +483,16 @@ class ClientManager {
485
483
  * const indexer = ClientManager.getIndexerClient({server: 'http://localhost', port: '8980', token: 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa'})
486
484
  * await indexer.makeHealthCheck().do()
487
485
  * ```
488
- * @example Override int decoding for responses
489
- * ```typescript
490
- * const indexer = ClientManager.getIndexerClient(config, IntDecoding.BIGINT)
491
- * ```
492
486
  */
493
- static getIndexerClient(config, overrideIntDecoding) {
487
+ static getIndexerClient(config) {
494
488
  const { token, server, port } = config;
495
489
  const tokenHeader = typeof token === 'string' ? { 'X-Indexer-API-Token': token } : (token ?? {});
496
490
  const httpClientWithRetry = new types_algoHttpClientWithRetry.AlgoHttpClientWithRetry(tokenHeader, server, port);
497
- const indexer = new Indexer(httpClientWithRetry);
498
- // Use mixed int decoding by default so bigints don't have lost precision
499
- indexer.setIntEncoding(overrideIntDecoding ?? IntDecoding.MIXED);
500
- return indexer;
491
+ return new Indexer(httpClientWithRetry);
501
492
  }
502
493
  /**
503
494
  * Returns an indexer SDK client that automatically retries on idempotent calls loaded from environment variables (expects to be called from a Node.js environment).
504
495
  *
505
- * @param overrideIntDecoding Override the default int decoding for responses, uses MIXED by default to avoid lost precision for big integers
506
496
  * @example
507
497
  *
508
498
  * ```typescript
@@ -511,8 +501,8 @@ class ClientManager {
511
501
  * await indexer.makeHealthCheck().do()
512
502
  * ```
513
503
  */
514
- static getIndexerClientFromEnvironment(overrideIntDecoding) {
515
- return ClientManager.getIndexerClient(ClientManager.getIndexerConfigFromEnvironment(), overrideIntDecoding);
504
+ static getIndexerClientFromEnvironment() {
505
+ return ClientManager.getIndexerClient(ClientManager.getIndexerConfigFromEnvironment());
516
506
  }
517
507
  /**
518
508
  * Returns a KMD SDK client.