@algorandfoundation/algokit-utils 10.0.0-alpha.31 → 10.0.0-alpha.32
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.
- package/account-manager.d.ts +448 -0
- package/account-manager.js +623 -0
- package/account-manager.js.map +1 -0
- package/account-manager.mjs +620 -0
- package/account-manager.mjs.map +1 -0
- package/account.d.ts +156 -0
- package/account.js +10 -0
- package/account.js.map +1 -0
- package/account.mjs +9 -0
- package/account.mjs.map +1 -0
- package/algorand-client-transaction-creator.d.ts +1103 -0
- package/algorand-client-transaction-creator.js +735 -0
- package/algorand-client-transaction-creator.js.map +1 -0
- package/algorand-client-transaction-creator.mjs +734 -0
- package/algorand-client-transaction-creator.mjs.map +1 -0
- package/algorand-client-transaction-sender.d.ts +1317 -0
- package/algorand-client-transaction-sender.js +933 -0
- package/algorand-client-transaction-sender.js.map +1 -0
- package/algorand-client-transaction-sender.mjs +932 -0
- package/algorand-client-transaction-sender.mjs.map +1 -0
- package/algorand-client.d.ts +246 -0
- package/algorand-client.js +325 -0
- package/algorand-client.js.map +1 -0
- package/algorand-client.mjs +325 -0
- package/algorand-client.mjs.map +1 -0
- package/amount.d.ts +46 -3
- package/amount.js +92 -13
- package/amount.js.map +1 -1
- package/amount.mjs +80 -3
- package/amount.mjs.map +1 -1
- package/app-client.d.ts +2130 -0
- package/app-client.js +909 -0
- package/app-client.js.map +1 -0
- package/app-client.mjs +908 -0
- package/app-client.mjs.map +1 -0
- package/app-deployer.d.ts +166 -0
- package/app-deployer.js +353 -0
- package/app-deployer.js.map +1 -0
- package/app-deployer.mjs +353 -0
- package/app-deployer.mjs.map +1 -0
- package/app-factory.d.ts +965 -0
- package/app-factory.js +448 -0
- package/app-factory.js.map +1 -0
- package/app-factory.mjs +448 -0
- package/app-factory.mjs.map +1 -0
- package/app-manager.d.ts +323 -0
- package/app-manager.js +468 -0
- package/app-manager.js.map +1 -0
- package/app-manager.mjs +468 -0
- package/app-manager.mjs.map +1 -0
- package/app-spec.d.ts +203 -0
- package/app-spec.js +137 -0
- package/app-spec.js.map +1 -0
- package/app-spec.mjs +137 -0
- package/app-spec.mjs.map +1 -0
- package/app.d.ts +257 -0
- package/app.js +49 -0
- package/app.js.map +1 -0
- package/app.mjs +42 -0
- package/app.mjs.map +1 -0
- package/asset-manager.d.ts +212 -0
- package/asset-manager.js +166 -0
- package/asset-manager.js.map +1 -0
- package/asset-manager.mjs +166 -0
- package/asset-manager.mjs.map +1 -0
- package/async-event-emitter.d.ts +16 -0
- package/async-event-emitter.js +38 -0
- package/async-event-emitter.js.map +1 -0
- package/async-event-emitter.mjs +37 -0
- package/async-event-emitter.mjs.map +1 -0
- package/client-manager.d.ts +475 -0
- package/client-manager.js +616 -0
- package/client-manager.js.map +1 -0
- package/client-manager.mjs +616 -0
- package/client-manager.mjs.map +1 -0
- package/composer.d.ts +947 -0
- package/composer.js +1584 -0
- package/composer.js.map +1 -0
- package/composer.mjs +1583 -0
- package/composer.mjs.map +1 -0
- package/config.d.ts +1 -1
- package/config.js +2 -2
- package/config.js.map +1 -1
- package/config.mjs +1 -1
- package/config.mjs.map +1 -1
- package/debugging.d.ts +47 -0
- package/debugging.js +20 -0
- package/debugging.js.map +1 -0
- package/debugging.mjs +15 -0
- package/debugging.mjs.map +1 -0
- package/dispenser-client.d.ts +90 -0
- package/dispenser-client.js +127 -0
- package/dispenser-client.js.map +1 -0
- package/dispenser-client.mjs +127 -0
- package/dispenser-client.mjs.map +1 -0
- package/expand.d.ts +2 -0
- package/expand.js +0 -0
- package/expand.mjs +0 -0
- package/index.d.ts +6 -5
- package/index.js +4 -3
- package/index.mjs +5 -5
- package/indexer-client/indexer-lookup.d.ts +1 -1
- package/indexer-client/indexer-lookup.js.map +1 -1
- package/indexer-client/indexer-lookup.mjs.map +1 -1
- package/indexer.d.ts +40 -0
- package/indexer.js +38 -0
- package/indexer.js.map +1 -0
- package/indexer.mjs +35 -0
- package/indexer.mjs.map +1 -0
- package/instance-of.d.ts +8 -0
- package/kmd-account-manager.d.ts +74 -0
- package/kmd-account-manager.js +167 -0
- package/kmd-account-manager.js.map +1 -0
- package/kmd-account-manager.mjs +165 -0
- package/kmd-account-manager.mjs.map +1 -0
- package/lifecycle-events.d.ts +14 -0
- package/lifecycle-events.js +11 -0
- package/lifecycle-events.js.map +1 -0
- package/lifecycle-events.mjs +10 -0
- package/lifecycle-events.mjs.map +1 -0
- package/logging.d.ts +13 -0
- package/logging.js +47 -0
- package/logging.js.map +1 -0
- package/logging.mjs +42 -0
- package/logging.mjs.map +1 -0
- package/logic-error.d.ts +39 -0
- package/logic-error.js +54 -0
- package/logic-error.js.map +1 -0
- package/logic-error.mjs +53 -0
- package/logic-error.mjs.map +1 -0
- package/network-client.d.ts +43 -0
- package/network-client.js +14 -0
- package/network-client.js.map +1 -0
- package/network-client.mjs +13 -0
- package/network-client.mjs.map +1 -0
- package/package.json +11 -1
- package/testing/account.d.ts +2 -2
- package/testing/account.js +1 -1
- package/testing/account.js.map +1 -1
- package/testing/account.mjs +1 -1
- package/testing/account.mjs.map +1 -1
- package/testing/fixtures/algokit-log-capture-fixture.d.ts +1 -1
- package/testing/fixtures/algokit-log-capture-fixture.js.map +1 -1
- package/testing/fixtures/algokit-log-capture-fixture.mjs.map +1 -1
- package/testing/fixtures/algorand-fixture.d.ts +2 -2
- package/testing/fixtures/algorand-fixture.js +2 -2
- package/testing/fixtures/algorand-fixture.js.map +1 -1
- package/testing/fixtures/algorand-fixture.mjs +2 -2
- package/testing/fixtures/algorand-fixture.mjs.map +1 -1
- package/testing/index.d.ts +2 -1
- package/testing/test-logger.d.ts +1 -1
- package/testing/test-logger.js.map +1 -1
- package/testing/test-logger.mjs.map +1 -1
- package/testing/types.d.ts +156 -0
- package/transaction/index.d.ts +4 -0
- package/transaction/index.js +9 -0
- package/transaction/index.mjs +4 -0
- package/transaction/perform-transaction-composer-simulate.d.ts +1 -1
- package/transaction/perform-transaction-composer-simulate.js.map +1 -1
- package/transaction/perform-transaction-composer-simulate.mjs.map +1 -1
- package/transaction/transaction.d.ts +2 -2
- package/transaction/transaction.js.map +1 -1
- package/transaction/transaction.mjs.map +1 -1
- package/transaction/types.d.ts +133 -0
- package/transactions/app-call.d.ts +1 -1
- package/transactions/app-call.js +1 -1
- package/transactions/app-call.js.map +1 -1
- package/transactions/app-call.mjs +1 -1
- package/transactions/app-call.mjs.map +1 -1
- package/transactions/common.d.ts +1 -1
- package/transactions/common.js.map +1 -1
- package/transactions/common.mjs.map +1 -1
- package/transactions/method-call.d.ts +1 -1
- package/transactions/method-call.js +1 -1
- package/transactions/method-call.js.map +1 -1
- package/transactions/method-call.mjs +1 -1
- package/transactions/method-call.mjs.map +1 -1
- package/transactions/payment.d.ts +1 -1
- package/transactions/payment.js.map +1 -1
- package/transactions/payment.mjs.map +1 -1
- package/types/account-manager.d.ts +11 -442
- package/types/account-manager.js +5 -616
- package/types/account-manager.js.map +1 -1
- package/types/account-manager.mjs +5 -614
- package/types/account-manager.mjs.map +1 -1
- package/types/account.d.ts +8 -150
- package/types/account.js +3 -4
- package/types/account.js.map +1 -1
- package/types/account.mjs +4 -4
- package/types/account.mjs.map +1 -1
- package/types/algorand-client-transaction-creator.d.ts +5 -1098
- package/types/algorand-client-transaction-creator.js +3 -729
- package/types/algorand-client-transaction-creator.js.map +1 -1
- package/types/algorand-client-transaction-creator.mjs +4 -729
- package/types/algorand-client-transaction-creator.mjs.map +1 -1
- package/types/algorand-client-transaction-sender.d.ts +5 -1312
- package/types/algorand-client-transaction-sender.js +3 -927
- package/types/algorand-client-transaction-sender.js.map +1 -1
- package/types/algorand-client-transaction-sender.mjs +3 -926
- package/types/algorand-client-transaction-sender.mjs.map +1 -1
- package/types/algorand-client.d.ts +5 -241
- package/types/algorand-client.js +3 -319
- package/types/algorand-client.js.map +1 -1
- package/types/algorand-client.mjs +3 -319
- package/types/algorand-client.mjs.map +1 -1
- package/types/amount.d.ts +6 -45
- package/types/amount.js +3 -79
- package/types/amount.js.map +1 -1
- package/types/amount.mjs +4 -79
- package/types/amount.mjs.map +1 -1
- package/types/app-client.d.ts +75 -2125
- package/types/app-client.js +3 -903
- package/types/app-client.js.map +1 -1
- package/types/app-client.mjs +3 -902
- package/types/app-client.mjs.map +1 -1
- package/types/app-deployer.d.ts +21 -161
- package/types/app-deployer.js +3 -347
- package/types/app-deployer.js.map +1 -1
- package/types/app-deployer.mjs +3 -347
- package/types/app-deployer.mjs.map +1 -1
- package/types/app-factory.d.ts +21 -960
- package/types/app-factory.js +3 -442
- package/types/app-factory.js.map +1 -1
- package/types/app-factory.mjs +3 -442
- package/types/app-factory.mjs.map +1 -1
- package/types/app-manager.d.ts +15 -318
- package/types/app-manager.js +3 -462
- package/types/app-manager.js.map +1 -1
- package/types/app-manager.mjs +3 -462
- package/types/app-manager.mjs.map +1 -1
- package/types/app-spec.d.ts +39 -198
- package/types/app-spec.js +3 -131
- package/types/app-spec.js.map +1 -1
- package/types/app-spec.mjs +3 -131
- package/types/app-spec.mjs.map +1 -1
- package/types/app.d.ts +62 -247
- package/types/app.js +15 -37
- package/types/app.js.map +1 -1
- package/types/app.mjs +16 -37
- package/types/app.mjs.map +1 -1
- package/types/asset-manager.d.ts +9 -207
- package/types/asset-manager.js +3 -160
- package/types/asset-manager.js.map +1 -1
- package/types/asset-manager.mjs +3 -160
- package/types/asset-manager.mjs.map +1 -1
- package/types/async-event-emitter.d.ts +7 -11
- package/types/async-event-emitter.js +3 -32
- package/types/async-event-emitter.js.map +1 -1
- package/types/async-event-emitter.mjs +4 -32
- package/types/async-event-emitter.mjs.map +1 -1
- package/types/client-manager.d.ts +27 -470
- package/types/client-manager.js +3 -610
- package/types/client-manager.js.map +1 -1
- package/types/client-manager.mjs +3 -610
- package/types/client-manager.mjs.map +1 -1
- package/types/composer.d.ts +79 -943
- package/types/composer.js +3 -1578
- package/types/composer.js.map +1 -1
- package/types/composer.mjs +3 -1577
- package/types/composer.mjs.map +1 -1
- package/types/config.d.ts +7 -52
- package/types/config.js +3 -74
- package/types/config.js.map +1 -1
- package/types/config.mjs +3 -74
- package/types/config.mjs.map +1 -1
- package/types/debugging.d.ts +12 -37
- package/types/debugging.js +11 -10
- package/types/debugging.js.map +1 -1
- package/types/debugging.mjs +12 -10
- package/types/debugging.mjs.map +1 -1
- package/types/dispenser-client.d.ts +11 -85
- package/types/dispenser-client.js +3 -121
- package/types/dispenser-client.js.map +1 -1
- package/types/dispenser-client.mjs +3 -121
- package/types/dispenser-client.mjs.map +1 -1
- package/types/expand.d.ts +8 -2
- package/types/indexer.d.ts +16 -36
- package/types/indexer.js +7 -30
- package/types/indexer.js.map +1 -1
- package/types/indexer.mjs +8 -30
- package/types/indexer.mjs.map +1 -1
- package/types/instance-of.d.ts +4 -4
- package/types/kmd-account-manager.d.ts +5 -69
- package/types/kmd-account-manager.js +3 -161
- package/types/kmd-account-manager.js.map +1 -1
- package/types/kmd-account-manager.mjs +3 -159
- package/types/kmd-account-manager.mjs.map +1 -1
- package/types/lifecycle-events.d.ts +7 -9
- package/types/lifecycle-events.js +3 -5
- package/types/lifecycle-events.js.map +1 -1
- package/types/lifecycle-events.mjs +4 -5
- package/types/lifecycle-events.mjs.map +1 -1
- package/types/logging.d.ts +14 -9
- package/types/logging.js +11 -37
- package/types/logging.js.map +1 -1
- package/types/logging.mjs +12 -37
- package/types/logging.mjs.map +1 -1
- package/types/logic-error.d.ts +8 -35
- package/types/logic-error.js +3 -48
- package/types/logic-error.js.map +1 -1
- package/types/logic-error.mjs +4 -48
- package/types/logic-error.mjs.map +1 -1
- package/types/network-client.d.ts +10 -39
- package/types/network-client.js +3 -8
- package/types/network-client.js.map +1 -1
- package/types/network-client.mjs +4 -8
- package/types/network-client.mjs.map +1 -1
- package/types/testing.d.ts +13 -151
- package/types/transaction.d.ts +33 -128
- package/updatable-config.d.ts +57 -0
- package/updatable-config.js +80 -0
- package/updatable-config.js.map +1 -0
- package/updatable-config.mjs +80 -0
- package/updatable-config.mjs.map +1 -0
- package/util.js +1 -1
- package/util.js.map +1 -1
- package/util.mjs +1 -1
- package/util.mjs.map +1 -1
package/types/asset-manager.d.ts
CHANGED
|
@@ -1,212 +1,14 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { AlgodClient } from "../packages/algod_client/src/client.js";
|
|
3
|
-
import { CommonTransactionParams } from "../transactions/common.js";
|
|
4
|
-
import { SendParams } from "./transaction.js";
|
|
5
|
-
import { TransactionComposer, TransactionComposerConfig } from "./composer.js";
|
|
6
|
-
import { AccountAssetInformation } from "./account.js";
|
|
1
|
+
import { AssetInformation as AssetInformation$1, AssetManager as AssetManager$1, BulkAssetOptInOutResult as BulkAssetOptInOutResult$1 } from "../asset-manager.js";
|
|
7
2
|
|
|
8
3
|
//#region src/types/asset-manager.d.ts
|
|
9
|
-
/**
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
interface AssetInformation {
|
|
18
|
-
/** The ID of the asset. */
|
|
19
|
-
assetId: bigint;
|
|
20
|
-
/** The address of the account that created the asset.
|
|
21
|
-
*
|
|
22
|
-
* This is the address where the parameters for this asset can be found,
|
|
23
|
-
* and also the address where unwanted asset units can be sent when
|
|
24
|
-
* closing out an asset position and opting-out of the asset.
|
|
25
|
-
*/
|
|
26
|
-
creator: string;
|
|
27
|
-
/** The total amount of the smallest divisible (decimal) units that were created of the asset.
|
|
28
|
-
*
|
|
29
|
-
* For example, if `decimals` is, say, 2, then for every 100 `total` there is 1 whole unit.
|
|
30
|
-
*/
|
|
31
|
-
total: bigint;
|
|
32
|
-
/** The amount of decimal places the asset was created with.
|
|
33
|
-
*
|
|
34
|
-
* * If 0, the asset is not divisible;
|
|
35
|
-
* * If 1, the base unit of the asset is in tenths;
|
|
36
|
-
* * If 2, the base unit of the asset is in hundredths;
|
|
37
|
-
* * If 3, the base unit of the asset is in thousandths;
|
|
38
|
-
* * and so on up to 19 decimal places.
|
|
39
|
-
*/
|
|
40
|
-
decimals: number;
|
|
41
|
-
/** Whether the asset was frozen by default for all accounts.
|
|
42
|
-
*
|
|
43
|
-
* If `true` then for anyone apart from the creator to hold the
|
|
44
|
-
* asset it needs to be unfrozen per account using an asset freeze
|
|
45
|
-
* transaction from the `freeze` account.
|
|
46
|
-
*/
|
|
47
|
-
defaultFrozen?: boolean;
|
|
48
|
-
/** The address of the optional account that can manage the configuration of the asset and destroy it.
|
|
49
|
-
*
|
|
50
|
-
* If not set the asset is permanently immutable.
|
|
51
|
-
*/
|
|
52
|
-
manager?: string;
|
|
53
|
-
/**
|
|
54
|
-
* The address of the optional account that holds the reserve (uncirculated supply) units of the asset.
|
|
55
|
-
*
|
|
56
|
-
* This address has no specific authority in the protocol itself and is informational only.
|
|
57
|
-
*
|
|
58
|
-
* Some standards like [ARC-19](https://github.com/algorandfoundation/ARCs/blob/main/ARCs/arc-0019.md)
|
|
59
|
-
* rely on this field to hold meaningful data.
|
|
60
|
-
*
|
|
61
|
-
* It can be used in the case where you want to signal to holders of your asset that the uncirculated units
|
|
62
|
-
* of the asset reside in an account that is different from the default creator account.
|
|
63
|
-
*
|
|
64
|
-
* If not set the field is permanently empty.
|
|
65
|
-
*/
|
|
66
|
-
reserve?: string;
|
|
67
|
-
/**
|
|
68
|
-
* The address of the optional account that can be used to freeze or unfreeze holdings of this asset for any account.
|
|
69
|
-
*
|
|
70
|
-
* If empty, freezing is not permitted.
|
|
71
|
-
*
|
|
72
|
-
* If not set the field is permanently empty.
|
|
73
|
-
*/
|
|
74
|
-
freeze?: string;
|
|
75
|
-
/**
|
|
76
|
-
* The address of the optional account that can clawback holdings of this asset from any account.
|
|
77
|
-
*
|
|
78
|
-
* The clawback account has the ability to **unconditionally take assets from any account**.
|
|
79
|
-
*
|
|
80
|
-
* If empty, clawback is not permitted.
|
|
81
|
-
*
|
|
82
|
-
* If not set the field is permanently empty.
|
|
83
|
-
*/
|
|
84
|
-
clawback?: string;
|
|
85
|
-
/** The optional name of the unit of this asset (e.g. ticker name).
|
|
86
|
-
*
|
|
87
|
-
* Max size is 8 bytes.
|
|
88
|
-
*/
|
|
89
|
-
unitName?: string;
|
|
90
|
-
/** The optional name of the unit of this asset (e.g. ticker name).
|
|
91
|
-
*
|
|
92
|
-
* Max size is 8 bytes.
|
|
93
|
-
*/
|
|
94
|
-
unitNameAsBytes?: Uint8Array;
|
|
95
|
-
/** The optional name of the asset.
|
|
96
|
-
*
|
|
97
|
-
* Max size is 32 bytes.
|
|
98
|
-
*/
|
|
99
|
-
assetName?: string;
|
|
100
|
-
/** The optional name of the asset.
|
|
101
|
-
*
|
|
102
|
-
* Max size is 32 bytes.
|
|
103
|
-
*/
|
|
104
|
-
assetNameAsBytes?: Uint8Array;
|
|
105
|
-
/** Optional URL where more information about the asset can be retrieved (e.g. metadata).
|
|
106
|
-
*
|
|
107
|
-
* Max size is 96 bytes.
|
|
108
|
-
*/
|
|
109
|
-
url?: string;
|
|
110
|
-
/** Optional URL where more information about the asset can be retrieved (e.g. metadata).
|
|
111
|
-
*
|
|
112
|
-
* Max size is 96 bytes.
|
|
113
|
-
*/
|
|
114
|
-
urlAsBytes?: Uint8Array;
|
|
115
|
-
/** 32-byte hash of some metadata that is relevant to the asset and/or asset holders.
|
|
116
|
-
*
|
|
117
|
-
* The format of this metadata is up to the application.
|
|
118
|
-
*/
|
|
119
|
-
metadataHash?: Uint8Array;
|
|
120
|
-
}
|
|
121
|
-
/** Allows management of asset information. */
|
|
122
|
-
declare class AssetManager {
|
|
123
|
-
private _algod;
|
|
124
|
-
private _newGroup;
|
|
125
|
-
/**
|
|
126
|
-
* Create a new asset manager.
|
|
127
|
-
* @param algod An algod client
|
|
128
|
-
* @param newGroup A function that creates a new `TransactionComposer` transaction group
|
|
129
|
-
* @example Create a new asset manager
|
|
130
|
-
* ```typescript
|
|
131
|
-
* const assetManager = new AssetManager(algod, () => new TransactionComposer({algod, () => signer, () => suggestedParams}))
|
|
132
|
-
* ```
|
|
133
|
-
*/
|
|
134
|
-
constructor(algod: AlgodClient, newGroup: (config?: TransactionComposerConfig) => TransactionComposer);
|
|
135
|
-
/**
|
|
136
|
-
* Returns the current asset information for the asset with the given ID.
|
|
137
|
-
*
|
|
138
|
-
* @example
|
|
139
|
-
* ```typescript
|
|
140
|
-
* const assetInfo = await assetManager.getById(12353n);
|
|
141
|
-
* ```
|
|
142
|
-
*
|
|
143
|
-
* @param assetId The ID of the asset
|
|
144
|
-
* @returns The asset information
|
|
145
|
-
*/
|
|
146
|
-
getById(assetId: bigint): Promise<AssetInformation>;
|
|
147
|
-
/**
|
|
148
|
-
* Returns the given sender account's asset holding for a given asset.
|
|
149
|
-
*
|
|
150
|
-
* @example
|
|
151
|
-
* ```typescript
|
|
152
|
-
* const address = "XBYLS2E6YI6XXL5BWCAMOA4GTWHXWENZMX5UHXMRNWWUQ7BXCY5WC5TEPA";
|
|
153
|
-
* const assetId = 123345n;
|
|
154
|
-
* const accountInfo = await assetManager.getAccountInformation(address, assetId);
|
|
155
|
-
* ```
|
|
156
|
-
*
|
|
157
|
-
* [Response data schema details](https://dev.algorand.co/reference/rest-apis/algod/#accountassetinformation)
|
|
158
|
-
* @param sender The address of the sender/account to look up
|
|
159
|
-
* @param assetId The ID of the asset to return a holding for
|
|
160
|
-
* @returns The account asset holding information
|
|
161
|
-
*/
|
|
162
|
-
getAccountInformation(sender: string | Address, assetId: bigint): Promise<AccountAssetInformation>;
|
|
163
|
-
/**
|
|
164
|
-
* Opt an account in to a list of Algorand Standard Assets.
|
|
165
|
-
*
|
|
166
|
-
* Transactions will be sent in batches of 16 as transaction groups.
|
|
167
|
-
*
|
|
168
|
-
* @param account The account to opt-in
|
|
169
|
-
* @param assetIds The list of asset IDs to opt-in to
|
|
170
|
-
* @param options Any parameters to control the transaction or execution of the transaction
|
|
171
|
-
* @example Example using AlgorandClient
|
|
172
|
-
* ```typescript
|
|
173
|
-
* // Basic example
|
|
174
|
-
* assetManager.bulkOptIn("ACCOUNTADDRESS", [12345n, 67890n])
|
|
175
|
-
* // With configuration
|
|
176
|
-
* assetManager.bulkOptIn("ACCOUNTADDRESS", [12345n, 67890n], { maxFee: (1000).microAlgo(), suppressLog: true })
|
|
177
|
-
* ```
|
|
178
|
-
* @returns An array of records matching asset ID to transaction ID of the opt in
|
|
179
|
-
*/
|
|
180
|
-
bulkOptIn(account: string | Address, assetIds: bigint[], options?: Omit<CommonTransactionParams, 'sender'> & SendParams): Promise<BulkAssetOptInOutResult[]>;
|
|
181
|
-
/**
|
|
182
|
-
* Opt an account out of a list of Algorand Standard Assets.
|
|
183
|
-
*
|
|
184
|
-
* Transactions will be sent in batches of 16 as transaction groups.
|
|
185
|
-
*
|
|
186
|
-
* @param account The account to opt-in
|
|
187
|
-
* @param assetIds The list of asset IDs to opt-out of
|
|
188
|
-
* @param options Any parameters to control the transaction or execution of the transaction
|
|
189
|
-
* @example Example using AlgorandClient
|
|
190
|
-
* ```typescript
|
|
191
|
-
* // Basic example
|
|
192
|
-
* assetManager.bulkOptOut("ACCOUNTADDRESS", [12345n, 67890n])
|
|
193
|
-
* // With configuration
|
|
194
|
-
* assetManager.bulkOptOut("ACCOUNTADDRESS", [12345n, 67890n], { ensureZeroBalance: true, maxFee: (1000).microAlgo(), suppressLog: true })
|
|
195
|
-
* ```
|
|
196
|
-
* @returns An array of records matching asset ID to transaction ID of the opt in
|
|
197
|
-
*/
|
|
198
|
-
bulkOptOut(account: string | Address, assetIds: bigint[], options?: Omit<CommonTransactionParams, 'sender'> & SendParams & {
|
|
199
|
-
/** Whether or not to check if the account has a zero balance for each asset first or not.
|
|
200
|
-
*
|
|
201
|
-
* Defaults to `true`.
|
|
202
|
-
*
|
|
203
|
-
* If this is set to `true` and the account has an asset balance it will throw an error.
|
|
204
|
-
*
|
|
205
|
-
* If this is set to `false` and the account has an asset balance it will lose those assets to the asset creator.
|
|
206
|
-
*/
|
|
207
|
-
ensureZeroBalance?: boolean;
|
|
208
|
-
}): Promise<BulkAssetOptInOutResult[]>;
|
|
209
|
-
}
|
|
4
|
+
/** @deprecated Import from `@algorandfoundation/algokit-utils/asset-manager` instead */
|
|
5
|
+
type BulkAssetOptInOutResult = BulkAssetOptInOutResult$1;
|
|
6
|
+
/** @deprecated Import from `@algorandfoundation/algokit-utils/asset-manager` instead */
|
|
7
|
+
type AssetInformation = AssetInformation$1;
|
|
8
|
+
/** @deprecated Import from `@algorandfoundation/algokit-utils/asset-manager` instead */
|
|
9
|
+
declare const AssetManager: typeof AssetManager$1;
|
|
10
|
+
/** @deprecated Import from `@algorandfoundation/algokit-utils/asset-manager` instead */
|
|
11
|
+
type AssetManager = AssetManager$1;
|
|
210
12
|
//#endregion
|
|
211
13
|
export { AssetInformation, AssetManager, BulkAssetOptInOutResult };
|
|
212
14
|
//# sourceMappingURL=asset-manager.d.ts.map
|
package/types/asset-manager.js
CHANGED
|
@@ -1,165 +1,8 @@
|
|
|
1
|
-
const
|
|
2
|
-
const require_config = require('../config.js');
|
|
3
|
-
const require_util = require('../util.js');
|
|
1
|
+
const require_asset_manager = require('../asset-manager.js');
|
|
4
2
|
|
|
5
3
|
//#region src/types/asset-manager.ts
|
|
6
|
-
/**
|
|
7
|
-
|
|
8
|
-
_algod;
|
|
9
|
-
_newGroup;
|
|
10
|
-
/**
|
|
11
|
-
* Create a new asset manager.
|
|
12
|
-
* @param algod An algod client
|
|
13
|
-
* @param newGroup A function that creates a new `TransactionComposer` transaction group
|
|
14
|
-
* @example Create a new asset manager
|
|
15
|
-
* ```typescript
|
|
16
|
-
* const assetManager = new AssetManager(algod, () => new TransactionComposer({algod, () => signer, () => suggestedParams}))
|
|
17
|
-
* ```
|
|
18
|
-
*/
|
|
19
|
-
constructor(algod, newGroup) {
|
|
20
|
-
this._algod = algod;
|
|
21
|
-
this._newGroup = newGroup;
|
|
22
|
-
}
|
|
23
|
-
/**
|
|
24
|
-
* Returns the current asset information for the asset with the given ID.
|
|
25
|
-
*
|
|
26
|
-
* @example
|
|
27
|
-
* ```typescript
|
|
28
|
-
* const assetInfo = await assetManager.getById(12353n);
|
|
29
|
-
* ```
|
|
30
|
-
*
|
|
31
|
-
* @param assetId The ID of the asset
|
|
32
|
-
* @returns The asset information
|
|
33
|
-
*/
|
|
34
|
-
async getById(assetId) {
|
|
35
|
-
const asset = await this._algod.assetById(assetId);
|
|
36
|
-
return {
|
|
37
|
-
assetId: BigInt(asset.id),
|
|
38
|
-
total: BigInt(asset.params.total),
|
|
39
|
-
decimals: Number(asset.params.decimals),
|
|
40
|
-
assetName: asset.params.name,
|
|
41
|
-
assetNameAsBytes: asset.params.nameB64,
|
|
42
|
-
unitName: asset.params.unitName,
|
|
43
|
-
unitNameAsBytes: asset.params.unitNameB64,
|
|
44
|
-
url: asset.params.url,
|
|
45
|
-
urlAsBytes: asset.params.urlB64,
|
|
46
|
-
creator: asset.params.creator,
|
|
47
|
-
manager: asset.params.manager,
|
|
48
|
-
clawback: asset.params.clawback,
|
|
49
|
-
freeze: asset.params.freeze,
|
|
50
|
-
reserve: asset.params.reserve,
|
|
51
|
-
defaultFrozen: asset.params.defaultFrozen,
|
|
52
|
-
metadataHash: asset.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-apis/algod/#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.toString(), assetId);
|
|
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 require_util.chunkArray(assetIds, require_constants.MAX_TRANSACTION_GROUP_SIZE)) {
|
|
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
|
-
require_config.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 require_util.chunkArray(assetIds, require_constants.MAX_TRANSACTION_GROUP_SIZE)) {
|
|
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
|
-
require_config.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
|
-
};
|
|
4
|
+
/** @deprecated Import from `@algorandfoundation/algokit-utils/asset-manager` instead */
|
|
5
|
+
const AssetManager = require_asset_manager.AssetManager;
|
|
163
6
|
|
|
164
7
|
//#endregion
|
|
165
8
|
exports.AssetManager = AssetManager;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"asset-manager.js","names":["results: BulkAssetOptInOutResult[]","chunkArray","MAX_TRANSACTION_GROUP_SIZE","notOptedInAssetIds: bigint[]","nonZeroBalanceAssetIds: bigint[]"],"sources":["../../src/types/asset-manager.ts"],"sourcesContent":["import { AlgodClient } from '@algorandfoundation/algokit-algod-client'\nimport { Address, MAX_TRANSACTION_GROUP_SIZE } from '@algorandfoundation/algokit-common'\nimport { Config } from '../config'\nimport { chunkArray } from '../util'\nimport { AccountAssetInformation } from './account'\nimport { CommonTransactionParams, TransactionComposer, TransactionComposerConfig } 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: AlgodClient\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: AlgodClient, newGroup: (config?: TransactionComposerConfig) => 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.assetById(assetId)\n\n return {\n assetId: BigInt(asset.id),\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.toString(), assetId)\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":";;;;;;AA0IA,IAAa,eAAb,MAA0B;CACxB,AAAQ;CACR,AAAQ;;;;;;;;;;CAWR,YAAY,OAAoB,UAAuE;AACrG,OAAK,SAAS;AACd,OAAK,YAAY;;;;;;;;;;;;;CAcnB,MAAa,QAAQ,SAA4C;EAC/D,MAAM,QAAQ,MAAM,KAAK,OAAO,UAAU,QAAQ;AAElD,SAAO;GACL,SAAS,OAAO,MAAM,GAAG;GACzB,OAAO,OAAO,MAAM,OAAO,MAAM;GACjC,UAAU,OAAO,MAAM,OAAO,SAAS;GAC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9E;;AAGJ,SAAO"}
|
|
1
|
+
{"version":3,"file":"asset-manager.js","names":["_AssetManager"],"sources":["../../src/types/asset-manager.ts"],"sourcesContent":["// Re-exports with deprecation notices for backwards compatibility\n// New imports should use '@algorandfoundation/algokit-utils/asset-manager'\n\nimport {\n type BulkAssetOptInOutResult as _BulkAssetOptInOutResult,\n type AssetInformation as _AssetInformation,\n AssetManager as _AssetManager,\n} from '../asset-manager'\n\n/** @deprecated Import from `@algorandfoundation/algokit-utils/asset-manager` instead */\nexport type BulkAssetOptInOutResult = _BulkAssetOptInOutResult\n\n/** @deprecated Import from `@algorandfoundation/algokit-utils/asset-manager` instead */\nexport type AssetInformation = _AssetInformation\n\n/** @deprecated Import from `@algorandfoundation/algokit-utils/asset-manager` instead */\nexport const AssetManager = _AssetManager\n/** @deprecated Import from `@algorandfoundation/algokit-utils/asset-manager` instead */\nexport type AssetManager = _AssetManager\n"],"mappings":";;;;AAgBA,MAAa,eAAeA"}
|
package/types/asset-manager.mjs
CHANGED
|
@@ -1,165 +1,8 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { Config } from "../config.mjs";
|
|
3
|
-
import { chunkArray } from "../util.mjs";
|
|
1
|
+
import { AssetManager as AssetManager$1 } from "../asset-manager.mjs";
|
|
4
2
|
|
|
5
3
|
//#region src/types/asset-manager.ts
|
|
6
|
-
/**
|
|
7
|
-
|
|
8
|
-
_algod;
|
|
9
|
-
_newGroup;
|
|
10
|
-
/**
|
|
11
|
-
* Create a new asset manager.
|
|
12
|
-
* @param algod An algod client
|
|
13
|
-
* @param newGroup A function that creates a new `TransactionComposer` transaction group
|
|
14
|
-
* @example Create a new asset manager
|
|
15
|
-
* ```typescript
|
|
16
|
-
* const assetManager = new AssetManager(algod, () => new TransactionComposer({algod, () => signer, () => suggestedParams}))
|
|
17
|
-
* ```
|
|
18
|
-
*/
|
|
19
|
-
constructor(algod, newGroup) {
|
|
20
|
-
this._algod = algod;
|
|
21
|
-
this._newGroup = newGroup;
|
|
22
|
-
}
|
|
23
|
-
/**
|
|
24
|
-
* Returns the current asset information for the asset with the given ID.
|
|
25
|
-
*
|
|
26
|
-
* @example
|
|
27
|
-
* ```typescript
|
|
28
|
-
* const assetInfo = await assetManager.getById(12353n);
|
|
29
|
-
* ```
|
|
30
|
-
*
|
|
31
|
-
* @param assetId The ID of the asset
|
|
32
|
-
* @returns The asset information
|
|
33
|
-
*/
|
|
34
|
-
async getById(assetId) {
|
|
35
|
-
const asset = await this._algod.assetById(assetId);
|
|
36
|
-
return {
|
|
37
|
-
assetId: BigInt(asset.id),
|
|
38
|
-
total: BigInt(asset.params.total),
|
|
39
|
-
decimals: Number(asset.params.decimals),
|
|
40
|
-
assetName: asset.params.name,
|
|
41
|
-
assetNameAsBytes: asset.params.nameB64,
|
|
42
|
-
unitName: asset.params.unitName,
|
|
43
|
-
unitNameAsBytes: asset.params.unitNameB64,
|
|
44
|
-
url: asset.params.url,
|
|
45
|
-
urlAsBytes: asset.params.urlB64,
|
|
46
|
-
creator: asset.params.creator,
|
|
47
|
-
manager: asset.params.manager,
|
|
48
|
-
clawback: asset.params.clawback,
|
|
49
|
-
freeze: asset.params.freeze,
|
|
50
|
-
reserve: asset.params.reserve,
|
|
51
|
-
defaultFrozen: asset.params.defaultFrozen,
|
|
52
|
-
metadataHash: asset.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-apis/algod/#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.toString(), assetId);
|
|
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, MAX_TRANSACTION_GROUP_SIZE)) {
|
|
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, MAX_TRANSACTION_GROUP_SIZE)) {
|
|
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
|
-
};
|
|
4
|
+
/** @deprecated Import from `@algorandfoundation/algokit-utils/asset-manager` instead */
|
|
5
|
+
const AssetManager = AssetManager$1;
|
|
163
6
|
|
|
164
7
|
//#endregion
|
|
165
8
|
export { AssetManager };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"asset-manager.mjs","names":["results: BulkAssetOptInOutResult[]","notOptedInAssetIds: bigint[]","nonZeroBalanceAssetIds: bigint[]"],"sources":["../../src/types/asset-manager.ts"],"sourcesContent":["import { AlgodClient } from '@algorandfoundation/algokit-algod-client'\nimport { Address, MAX_TRANSACTION_GROUP_SIZE } from '@algorandfoundation/algokit-common'\nimport { Config } from '../config'\nimport { chunkArray } from '../util'\nimport { AccountAssetInformation } from './account'\nimport { CommonTransactionParams, TransactionComposer, TransactionComposerConfig } 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: AlgodClient\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: AlgodClient, newGroup: (config?: TransactionComposerConfig) => 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.assetById(assetId)\n\n return {\n assetId: BigInt(asset.id),\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.toString(), assetId)\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":";;;;;;AA0IA,IAAa,eAAb,MAA0B;CACxB,AAAQ;CACR,AAAQ;;;;;;;;;;CAWR,YAAY,OAAoB,UAAuE;AACrG,OAAK,SAAS;AACd,OAAK,YAAY;;;;;;;;;;;;;CAcnB,MAAa,QAAQ,SAA4C;EAC/D,MAAM,QAAQ,MAAM,KAAK,OAAO,UAAU,QAAQ;AAElD,SAAO;GACL,SAAS,OAAO,MAAM,GAA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;KAAE,SAAS,OAAO,QAAQ;KAAE,eAAe,OAAO,MAAM;KAAQ,CAAC;KAC9E;;AAGJ,SAAO"}
|
|
1
|
+
{"version":3,"file":"asset-manager.mjs","names":["_AssetManager"],"sources":["../../src/types/asset-manager.ts"],"sourcesContent":["// Re-exports with deprecation notices for backwards compatibility\n// New imports should use '@algorandfoundation/algokit-utils/asset-manager'\n\nimport {\n type BulkAssetOptInOutResult as _BulkAssetOptInOutResult,\n type AssetInformation as _AssetInformation,\n AssetManager as _AssetManager,\n} from '../asset-manager'\n\n/** @deprecated Import from `@algorandfoundation/algokit-utils/asset-manager` instead */\nexport type BulkAssetOptInOutResult = _BulkAssetOptInOutResult\n\n/** @deprecated Import from `@algorandfoundation/algokit-utils/asset-manager` instead */\nexport type AssetInformation = _AssetInformation\n\n/** @deprecated Import from `@algorandfoundation/algokit-utils/asset-manager` instead */\nexport const AssetManager = _AssetManager\n/** @deprecated Import from `@algorandfoundation/algokit-utils/asset-manager` instead */\nexport type AssetManager = _AssetManager\n"],"mappings":";;;;AAgBA,MAAa,eAAeA"}
|
|
@@ -1,16 +1,12 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { AsyncEventEmitter as AsyncEventEmitter$1, AsyncEventListener as AsyncEventListener$1 } from "../async-event-emitter.js";
|
|
2
2
|
|
|
3
3
|
//#region src/types/async-event-emitter.d.ts
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
once<K extends string | symbol>(eventName: K, listener: AsyncEventListener<K extends EventType ? EventDataMap[K] : unknown>): AsyncEventEmitter;
|
|
11
|
-
removeListener(eventName: string | symbol, listener: AsyncEventListener): AsyncEventEmitter;
|
|
12
|
-
off: (eventName: string | symbol, listener: AsyncEventListener) => AsyncEventEmitter;
|
|
13
|
-
}
|
|
4
|
+
/** @deprecated Import from `@algorandfoundation/algokit-utils/async-event-emitter` instead */
|
|
5
|
+
type AsyncEventListener<T = unknown> = AsyncEventListener$1<T>;
|
|
6
|
+
/** @deprecated Import from `@algorandfoundation/algokit-utils/async-event-emitter` instead */
|
|
7
|
+
declare const AsyncEventEmitter: typeof AsyncEventEmitter$1;
|
|
8
|
+
/** @deprecated Import from `@algorandfoundation/algokit-utils/async-event-emitter` instead */
|
|
9
|
+
type AsyncEventEmitter = AsyncEventEmitter$1;
|
|
14
10
|
//#endregion
|
|
15
11
|
export { AsyncEventEmitter, AsyncEventListener };
|
|
16
12
|
//# sourceMappingURL=async-event-emitter.d.ts.map
|