@algorandfoundation/algokit-utils 4.0.0 → 4.1.0

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/cjs/asset.d.ts ADDED
@@ -0,0 +1,21 @@
1
+ import { Account, Algodv2 } from 'algosdk';
2
+ /**
3
+ * Opt in to a list of assets on the Algorand blockchain.
4
+ *
5
+ * @param client - An instance of the Algodv2 class from the `algosdk` library.
6
+ * @param account - An instance of the Account class from the `algosdk` library representing the account that wants to opt in to the assets.
7
+ * @param assetIds - An array of asset IDs that the account wants to opt in to.
8
+ * @returns A record object where the keys are the asset IDs and the values are the corresponding transaction IDs for successful opt-ins.
9
+ * @throws If there is an error during the opt-in process.
10
+ */
11
+ export declare function optIn(client: Algodv2, account: Account, assetIds: number[]): Promise<Record<number, string>>;
12
+ /**
13
+ * Opt out of multiple assets in Algorand blockchain.
14
+ *
15
+ * @param {Algodv2} client - An instance of the Algodv2 client used to interact with the Algorand blockchain.
16
+ * @param {Account} account - The Algorand account that wants to opt out of the assets.
17
+ * @param {number[]} assetIds - An array of asset IDs representing the assets to opt out of.
18
+ * @returns {Promise<Record<number, string>>} - A record object containing asset IDs as keys and their corresponding transaction IDs as values.
19
+ */
20
+ export declare function optOut(client: Algodv2, account: Account, assetIds: number[]): Promise<Record<number, string>>;
21
+ //# sourceMappingURL=asset.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"asset.d.ts","sourceRoot":"","sources":["../../src/asset.ts"],"names":[],"mappings":"AAAA,OAAgB,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,SAAS,CAAA;AAmEnD;;;;;;;;GAQG;AACH,wBAAsB,KAAK,CAAC,MAAM,EAAE,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,mCA2ChF;AAED;;;;;;;GAOG;AACH,wBAAsB,MAAM,CAAC,MAAM,EAAE,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CA6CnH"}
package/cjs/asset.js ADDED
@@ -0,0 +1,163 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.optOut = exports.optIn = void 0;
7
+ const algosdk_1 = __importDefault(require("algosdk"));
8
+ const _1 = require(".");
9
+ const MaxTxGroupSize = 16;
10
+ var ValidationType;
11
+ (function (ValidationType) {
12
+ ValidationType[ValidationType["OptIn"] = 0] = "OptIn";
13
+ ValidationType[ValidationType["OptOut"] = 1] = "OptOut";
14
+ })(ValidationType || (ValidationType = {}));
15
+ function* chunks(arr, n) {
16
+ for (let i = 0; i < arr.length; i += n)
17
+ yield arr.slice(i, i + n);
18
+ }
19
+ async function ensureAccountIsValid(client, account) {
20
+ try {
21
+ await client.accountInformation(account.addr).do();
22
+ }
23
+ catch (error) {
24
+ throw new Error(`Account address ${account.addr} does not exist`);
25
+ }
26
+ }
27
+ async function ensureAssetBalanceConditions(client, account, assetIds, validationType) {
28
+ const accountInfo = await client.accountInformation(account.addr).do();
29
+ const assetPromises = assetIds.map(async (assetId) => {
30
+ if (validationType === ValidationType.OptIn) {
31
+ if (accountInfo.assets.find((a) => a['asset-id'] === assetId)) {
32
+ _1.Config.logger.debug(`Account ${account.addr} has already opted-in to asset ${assetId}`);
33
+ return assetId;
34
+ }
35
+ }
36
+ else if (validationType === ValidationType.OptOut) {
37
+ try {
38
+ const accountAssetInfo = await client.accountAssetInformation(account.addr, assetId).do();
39
+ if (accountAssetInfo['asset-holding']['amount'] !== 0) {
40
+ _1.Config.logger.debug(`Asset ${assetId} is not with zero balance`);
41
+ return assetId;
42
+ }
43
+ }
44
+ catch (e) {
45
+ _1.Config.logger.debug(`Account ${account.addr} does not have asset ${assetId}`);
46
+ return assetId;
47
+ }
48
+ }
49
+ return null;
50
+ });
51
+ const invalidAssets = (await Promise.all(assetPromises)).filter((assetId) => assetId !== null);
52
+ if (invalidAssets.length > 0) {
53
+ let errorMsg = '';
54
+ if (validationType === ValidationType.OptIn) {
55
+ errorMsg = `Assets ${invalidAssets.join(', ')} cannot be opted in. Ensure that they are valid and that the account has not previously opted into them.`;
56
+ }
57
+ else if (validationType === ValidationType.OptOut) {
58
+ errorMsg = `Assets ${invalidAssets.join(', ')} cannot be opted out. Ensure that they are valid and that the account has previously opted into them and holds zero balance.`;
59
+ }
60
+ throw new Error(errorMsg);
61
+ }
62
+ }
63
+ /**
64
+ * Opt in to a list of assets on the Algorand blockchain.
65
+ *
66
+ * @param client - An instance of the Algodv2 class from the `algosdk` library.
67
+ * @param account - An instance of the Account class from the `algosdk` library representing the account that wants to opt in to the assets.
68
+ * @param assetIds - An array of asset IDs that the account wants to opt in to.
69
+ * @returns A record object where the keys are the asset IDs and the values are the corresponding transaction IDs for successful opt-ins.
70
+ * @throws If there is an error during the opt-in process.
71
+ */
72
+ async function optIn(client, account, assetIds) {
73
+ const result = {};
74
+ await ensureAccountIsValid(client, account);
75
+ await ensureAssetBalanceConditions(client, account, assetIds, ValidationType.OptIn);
76
+ const assets = await Promise.all(assetIds.map((aid) => client.getAssetByID(aid).do()));
77
+ const suggestedParams = await client.getTransactionParams().do();
78
+ for (const assetGroup of chunks(assets, MaxTxGroupSize)) {
79
+ try {
80
+ const transactionToSign = assetGroup.flatMap((asset) => [
81
+ {
82
+ transaction: algosdk_1.default.makeAssetTransferTxnWithSuggestedParamsFromObject({
83
+ from: account.addr,
84
+ to: account.addr,
85
+ assetIndex: asset.index,
86
+ amount: 0,
87
+ rekeyTo: undefined,
88
+ revocationTarget: undefined,
89
+ closeRemainderTo: undefined,
90
+ suggestedParams,
91
+ }),
92
+ signer: account,
93
+ },
94
+ ]);
95
+ const txnGrp = {
96
+ transactions: transactionToSign,
97
+ signer: account,
98
+ };
99
+ const sendGroupOfTransactionsResult = await (0, _1.sendGroupOfTransactions)(txnGrp, client);
100
+ assetGroup.map((asset, index) => {
101
+ result[asset.index] = sendGroupOfTransactionsResult.txIds[index];
102
+ _1.Config.logger.info(`Successfully opted in of asset ${asset.index} with transaction ID ${sendGroupOfTransactionsResult.txIds[index]},
103
+ grouped under ${sendGroupOfTransactionsResult.groupId} round ${sendGroupOfTransactionsResult.confirmations}.`);
104
+ });
105
+ }
106
+ catch (e) {
107
+ throw new Error(`Received error trying to opt in ${e}`);
108
+ }
109
+ }
110
+ return result;
111
+ }
112
+ exports.optIn = optIn;
113
+ /**
114
+ * Opt out of multiple assets in Algorand blockchain.
115
+ *
116
+ * @param {Algodv2} client - An instance of the Algodv2 client used to interact with the Algorand blockchain.
117
+ * @param {Account} account - The Algorand account that wants to opt out of the assets.
118
+ * @param {number[]} assetIds - An array of asset IDs representing the assets to opt out of.
119
+ * @returns {Promise<Record<number, string>>} - A record object containing asset IDs as keys and their corresponding transaction IDs as values.
120
+ */
121
+ async function optOut(client, account, assetIds) {
122
+ const result = {};
123
+ // Verify assets
124
+ await ensureAccountIsValid(client, account);
125
+ await ensureAssetBalanceConditions(client, account, assetIds, ValidationType.OptOut);
126
+ const assets = await Promise.all(assetIds.map((aid) => client.getAssetByID(aid).do()));
127
+ const suggestedParams = await client.getTransactionParams().do();
128
+ for (const assetGroup of chunks(assets, MaxTxGroupSize)) {
129
+ try {
130
+ const transactionToSign = assetGroup.flatMap((asset) => [
131
+ {
132
+ transaction: algosdk_1.default.makeAssetTransferTxnWithSuggestedParamsFromObject({
133
+ assetIndex: asset.index,
134
+ amount: 0,
135
+ from: account.addr,
136
+ to: account.addr,
137
+ rekeyTo: undefined,
138
+ revocationTarget: undefined,
139
+ suggestedParams,
140
+ closeRemainderTo: asset.params.creator,
141
+ }),
142
+ signer: account,
143
+ },
144
+ ]);
145
+ const txnGrp = {
146
+ transactions: transactionToSign,
147
+ signer: account,
148
+ };
149
+ const sendGroupOfTransactionsResult = await (0, _1.sendGroupOfTransactions)(txnGrp, client);
150
+ assetGroup.map((asset, index) => {
151
+ result[asset.index] = sendGroupOfTransactionsResult.txIds[index];
152
+ _1.Config.logger.info(`Successfully opted out of asset ${asset.index} with transaction ID ${sendGroupOfTransactionsResult.txIds[index]},
153
+ grouped under ${sendGroupOfTransactionsResult.groupId} round ${sendGroupOfTransactionsResult.confirmations}.`);
154
+ });
155
+ }
156
+ catch (e) {
157
+ throw new Error(`Received error trying to opt out ${e}`);
158
+ }
159
+ }
160
+ return result;
161
+ }
162
+ exports.optOut = optOut;
163
+ //# sourceMappingURL=asset.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"asset.js","sourceRoot":"","sources":["../../src/asset.ts"],"names":[],"mappings":";;;;;;AAAA,sDAAmD;AACnD,wBAAmD;AAGnD,MAAM,cAAc,GAAG,EAAE,CAAA;AAEzB,IAAK,cAGJ;AAHD,WAAK,cAAc;IACjB,qDAAK,CAAA;IACL,uDAAM,CAAA;AACR,CAAC,EAHI,cAAc,KAAd,cAAc,QAGlB;AAED,QAAQ,CAAC,CAAC,MAAM,CAAI,GAAQ,EAAE,CAAS;IACrC,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,GAAG,CAAC,MAAM,EAAE,CAAC,IAAI,CAAC;QAAE,MAAM,GAAG,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,GAAG,CAAC,CAAC,CAAA;AACnE,CAAC;AAED,KAAK,UAAU,oBAAoB,CAAC,MAAuB,EAAE,OAAwB;IACnF,IAAI;QACF,MAAM,MAAM,CAAC,kBAAkB,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,EAAE,EAAE,CAAA;KACnD;IAAC,OAAO,KAAK,EAAE;QACd,MAAM,IAAI,KAAK,CAAC,mBAAmB,OAAO,CAAC,IAAI,iBAAiB,CAAC,CAAA;KAClE;AACH,CAAC;AAED,KAAK,UAAU,4BAA4B,CACzC,MAAuB,EACvB,OAAwB,EACxB,QAAkB,EAClB,cAA8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G,6BAA6B,CAAC,OAAO,UAAU,6BAA6B,CAAC,aAAa,GAAG,CAC9G,CAAA;YACH,CAAC,CAAC,CAAA;SACH;QAAC,OAAO,CAAC,EAAE;YACV,MAAM,IAAI,KAAK,CAAC,oCAAoC,CAAC,EAAE,CAAC,CAAA;SACzD;KACF;IACD,OAAO,MAAM,CAAA;AACf,CAAC;AA7CD,wBA6CC"}
package/cjs/index.d.ts CHANGED
@@ -4,12 +4,13 @@ export * from './amount';
4
4
  export * from './app';
5
5
  export * from './app-client';
6
6
  export * from './app-deploy';
7
+ export { optIn, optOut } from './asset';
8
+ export * from './dispenser-client';
7
9
  export * from './indexer-lookup';
8
10
  export * from './localnet';
9
11
  export * from './network-client';
10
12
  export * from './transaction';
11
13
  export * from './transfer';
12
- export * from './dispenser-client';
13
14
  /** The AlgoKit config. To update it use the configure method. */
14
15
  export declare const Config: UpdatableConfig;
15
16
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAA;AAEhD,cAAc,WAAW,CAAA;AACzB,cAAc,UAAU,CAAA;AACxB,cAAc,OAAO,CAAA;AACrB,cAAc,cAAc,CAAA;AAC5B,cAAc,cAAc,CAAA;AAC5B,cAAc,kBAAkB,CAAA;AAChC,cAAc,YAAY,CAAA;AAC1B,cAAc,kBAAkB,CAAA;AAChC,cAAc,eAAe,CAAA;AAC7B,cAAc,YAAY,CAAA;AAC1B,cAAc,oBAAoB,CAAA;AAElC,iEAAiE;AACjE,eAAO,MAAM,MAAM,iBAAwB,CAAA"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAA;AAEhD,cAAc,WAAW,CAAA;AACzB,cAAc,UAAU,CAAA;AACxB,cAAc,OAAO,CAAA;AACrB,cAAc,cAAc,CAAA;AAC5B,cAAc,cAAc,CAAA;AAC5B,OAAO,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,SAAS,CAAA;AACvC,cAAc,oBAAoB,CAAA;AAClC,cAAc,kBAAkB,CAAA;AAChC,cAAc,YAAY,CAAA;AAC1B,cAAc,kBAAkB,CAAA;AAChC,cAAc,eAAe,CAAA;AAC7B,cAAc,YAAY,CAAA;AAE1B,iEAAiE;AACjE,eAAO,MAAM,MAAM,iBAAwB,CAAA"}
package/cjs/index.js CHANGED
@@ -14,19 +14,22 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
14
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
- exports.Config = void 0;
17
+ exports.Config = exports.optOut = exports.optIn = void 0;
18
18
  const config_1 = require("./types/config");
19
19
  __exportStar(require("./account"), exports);
20
20
  __exportStar(require("./amount"), exports);
21
21
  __exportStar(require("./app"), exports);
22
22
  __exportStar(require("./app-client"), exports);
23
23
  __exportStar(require("./app-deploy"), exports);
24
+ var asset_1 = require("./asset");
25
+ Object.defineProperty(exports, "optIn", { enumerable: true, get: function () { return asset_1.optIn; } });
26
+ Object.defineProperty(exports, "optOut", { enumerable: true, get: function () { return asset_1.optOut; } });
27
+ __exportStar(require("./dispenser-client"), exports);
24
28
  __exportStar(require("./indexer-lookup"), exports);
25
29
  __exportStar(require("./localnet"), exports);
26
30
  __exportStar(require("./network-client"), exports);
27
31
  __exportStar(require("./transaction"), exports);
28
32
  __exportStar(require("./transfer"), exports);
29
- __exportStar(require("./dispenser-client"), exports);
30
33
  /** The AlgoKit config. To update it use the configure method. */
31
34
  exports.Config = new config_1.UpdatableConfig();
32
35
  //# sourceMappingURL=index.js.map
package/cjs/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AAAA,2CAAgD;AAEhD,4CAAyB;AACzB,2CAAwB;AACxB,wCAAqB;AACrB,+CAA4B;AAC5B,+CAA4B;AAC5B,mDAAgC;AAChC,6CAA0B;AAC1B,mDAAgC;AAChC,gDAA6B;AAC7B,6CAA0B;AAC1B,qDAAkC;AAElC,iEAAiE;AACpD,QAAA,MAAM,GAAG,IAAI,wBAAe,EAAE,CAAA"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AAAA,2CAAgD;AAEhD,4CAAyB;AACzB,2CAAwB;AACxB,wCAAqB;AACrB,+CAA4B;AAC5B,+CAA4B;AAC5B,iCAAuC;AAA9B,8FAAA,KAAK,OAAA;AAAE,+FAAA,MAAM,OAAA;AACtB,qDAAkC;AAClC,mDAAgC;AAChC,6CAA0B;AAC1B,mDAAgC;AAChC,gDAA6B;AAC7B,6CAA0B;AAE1B,iEAAiE;AACpD,QAAA,MAAM,GAAG,IAAI,wBAAe,EAAE,CAAA"}
package/esm/asset.js ADDED
@@ -0,0 +1,155 @@
1
+ import algosdk from 'algosdk';
2
+ import { Config, sendGroupOfTransactions } from '.';
3
+ const MaxTxGroupSize = 16;
4
+ var ValidationType;
5
+ (function (ValidationType) {
6
+ ValidationType[ValidationType["OptIn"] = 0] = "OptIn";
7
+ ValidationType[ValidationType["OptOut"] = 1] = "OptOut";
8
+ })(ValidationType || (ValidationType = {}));
9
+ function* chunks(arr, n) {
10
+ for (let i = 0; i < arr.length; i += n)
11
+ yield arr.slice(i, i + n);
12
+ }
13
+ async function ensureAccountIsValid(client, account) {
14
+ try {
15
+ await client.accountInformation(account.addr).do();
16
+ }
17
+ catch (error) {
18
+ throw new Error(`Account address ${account.addr} does not exist`);
19
+ }
20
+ }
21
+ async function ensureAssetBalanceConditions(client, account, assetIds, validationType) {
22
+ const accountInfo = await client.accountInformation(account.addr).do();
23
+ const assetPromises = assetIds.map(async (assetId) => {
24
+ if (validationType === ValidationType.OptIn) {
25
+ if (accountInfo.assets.find((a) => a['asset-id'] === assetId)) {
26
+ Config.logger.debug(`Account ${account.addr} has already opted-in to asset ${assetId}`);
27
+ return assetId;
28
+ }
29
+ }
30
+ else if (validationType === ValidationType.OptOut) {
31
+ try {
32
+ const accountAssetInfo = await client.accountAssetInformation(account.addr, assetId).do();
33
+ if (accountAssetInfo['asset-holding']['amount'] !== 0) {
34
+ Config.logger.debug(`Asset ${assetId} is not with zero balance`);
35
+ return assetId;
36
+ }
37
+ }
38
+ catch (e) {
39
+ Config.logger.debug(`Account ${account.addr} does not have asset ${assetId}`);
40
+ return assetId;
41
+ }
42
+ }
43
+ return null;
44
+ });
45
+ const invalidAssets = (await Promise.all(assetPromises)).filter((assetId) => assetId !== null);
46
+ if (invalidAssets.length > 0) {
47
+ let errorMsg = '';
48
+ if (validationType === ValidationType.OptIn) {
49
+ errorMsg = `Assets ${invalidAssets.join(', ')} cannot be opted in. Ensure that they are valid and that the account has not previously opted into them.`;
50
+ }
51
+ else if (validationType === ValidationType.OptOut) {
52
+ errorMsg = `Assets ${invalidAssets.join(', ')} cannot be opted out. Ensure that they are valid and that the account has previously opted into them and holds zero balance.`;
53
+ }
54
+ throw new Error(errorMsg);
55
+ }
56
+ }
57
+ /**
58
+ * Opt in to a list of assets on the Algorand blockchain.
59
+ *
60
+ * @param client - An instance of the Algodv2 class from the `algosdk` library.
61
+ * @param account - An instance of the Account class from the `algosdk` library representing the account that wants to opt in to the assets.
62
+ * @param assetIds - An array of asset IDs that the account wants to opt in to.
63
+ * @returns A record object where the keys are the asset IDs and the values are the corresponding transaction IDs for successful opt-ins.
64
+ * @throws If there is an error during the opt-in process.
65
+ */
66
+ export async function optIn(client, account, assetIds) {
67
+ const result = {};
68
+ await ensureAccountIsValid(client, account);
69
+ await ensureAssetBalanceConditions(client, account, assetIds, ValidationType.OptIn);
70
+ const assets = await Promise.all(assetIds.map((aid) => client.getAssetByID(aid).do()));
71
+ const suggestedParams = await client.getTransactionParams().do();
72
+ for (const assetGroup of chunks(assets, MaxTxGroupSize)) {
73
+ try {
74
+ const transactionToSign = assetGroup.flatMap((asset) => [
75
+ {
76
+ transaction: algosdk.makeAssetTransferTxnWithSuggestedParamsFromObject({
77
+ from: account.addr,
78
+ to: account.addr,
79
+ assetIndex: asset.index,
80
+ amount: 0,
81
+ rekeyTo: undefined,
82
+ revocationTarget: undefined,
83
+ closeRemainderTo: undefined,
84
+ suggestedParams,
85
+ }),
86
+ signer: account,
87
+ },
88
+ ]);
89
+ const txnGrp = {
90
+ transactions: transactionToSign,
91
+ signer: account,
92
+ };
93
+ const sendGroupOfTransactionsResult = await sendGroupOfTransactions(txnGrp, client);
94
+ assetGroup.map((asset, index) => {
95
+ result[asset.index] = sendGroupOfTransactionsResult.txIds[index];
96
+ Config.logger.info(`Successfully opted in of asset ${asset.index} with transaction ID ${sendGroupOfTransactionsResult.txIds[index]},
97
+ grouped under ${sendGroupOfTransactionsResult.groupId} round ${sendGroupOfTransactionsResult.confirmations}.`);
98
+ });
99
+ }
100
+ catch (e) {
101
+ throw new Error(`Received error trying to opt in ${e}`);
102
+ }
103
+ }
104
+ return result;
105
+ }
106
+ /**
107
+ * Opt out of multiple assets in Algorand blockchain.
108
+ *
109
+ * @param {Algodv2} client - An instance of the Algodv2 client used to interact with the Algorand blockchain.
110
+ * @param {Account} account - The Algorand account that wants to opt out of the assets.
111
+ * @param {number[]} assetIds - An array of asset IDs representing the assets to opt out of.
112
+ * @returns {Promise<Record<number, string>>} - A record object containing asset IDs as keys and their corresponding transaction IDs as values.
113
+ */
114
+ export async function optOut(client, account, assetIds) {
115
+ const result = {};
116
+ // Verify assets
117
+ await ensureAccountIsValid(client, account);
118
+ await ensureAssetBalanceConditions(client, account, assetIds, ValidationType.OptOut);
119
+ const assets = await Promise.all(assetIds.map((aid) => client.getAssetByID(aid).do()));
120
+ const suggestedParams = await client.getTransactionParams().do();
121
+ for (const assetGroup of chunks(assets, MaxTxGroupSize)) {
122
+ try {
123
+ const transactionToSign = assetGroup.flatMap((asset) => [
124
+ {
125
+ transaction: algosdk.makeAssetTransferTxnWithSuggestedParamsFromObject({
126
+ assetIndex: asset.index,
127
+ amount: 0,
128
+ from: account.addr,
129
+ to: account.addr,
130
+ rekeyTo: undefined,
131
+ revocationTarget: undefined,
132
+ suggestedParams,
133
+ closeRemainderTo: asset.params.creator,
134
+ }),
135
+ signer: account,
136
+ },
137
+ ]);
138
+ const txnGrp = {
139
+ transactions: transactionToSign,
140
+ signer: account,
141
+ };
142
+ const sendGroupOfTransactionsResult = await sendGroupOfTransactions(txnGrp, client);
143
+ assetGroup.map((asset, index) => {
144
+ result[asset.index] = sendGroupOfTransactionsResult.txIds[index];
145
+ Config.logger.info(`Successfully opted out of asset ${asset.index} with transaction ID ${sendGroupOfTransactionsResult.txIds[index]},
146
+ grouped under ${sendGroupOfTransactionsResult.groupId} round ${sendGroupOfTransactionsResult.confirmations}.`);
147
+ });
148
+ }
149
+ catch (e) {
150
+ throw new Error(`Received error trying to opt out ${e}`);
151
+ }
152
+ }
153
+ return result;
154
+ }
155
+ //# sourceMappingURL=asset.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"asset.js","sourceRoot":"","sources":["../../src/asset.ts"],"names":[],"mappings":"AAAA,OAAO,OAA6B,MAAM,SAAS,CAAA;AACnD,OAAO,EAAE,MAAM,EAAE,uBAAuB,EAAE,MAAM,GAAG,CAAA;AAGnD,MAAM,cAAc,GAAG,EAAE,CAAA;AAEzB,IAAK,cAGJ;AAHD,WAAK,cAAc;IACjB,qDAAK,CAAA;IACL,uDAAM,CAAA;AACR,CAAC,EAHI,cAAc,KAAd,cAAc,QAGlB;AAED,QAAQ,CAAC,CAAC,MAAM,CAAI,GAAQ,EAAE,CAAS;IACrC,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,GAAG,CAAC,MAAM,EAAE,CAAC,IAAI,CAAC;QAAE,MAAM,GAAG,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,EAAE,iBAAiB;gBAC/B,MAAM,EAAE,OAAO;aAChB,CAAA;YACD,MAAM,6BAA6B,GAAG,MAAM,uBAAuB,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;YACnF,UAAU,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,KAAK,EAAE,EAAE;gBAC9B,MAAM,CAAC,KAAK,CAAC,KAAK,CAAC,GAAG,6BAA6B,CAAC,KAAK,CAAC,KAAK,CAAC,CAAA;gBAEhE,MAAM,CAAC,MAAM,CAAC,IAAI,CAChB,mCAAmC,KAAK,CAAC,KAAK,wBAAwB,6BAA6B,CAAC,KAAK,CAAC,KAAK,CAAC;0BAChG,6BAA6B,CAAC,OAAO,UAAU,6BAA6B,CAAC,aAAa,GAAG,CAC9G,CAAA;YACH,CAAC,CAAC,CAAA;SACH;QAAC,OAAO,CAAC,EAAE;YACV,MAAM,IAAI,KAAK,CAAC,oCAAoC,CAAC,EAAE,CAAC,CAAA;SACzD;KACF;IACD,OAAO,MAAM,CAAA;AACf,CAAC"}
package/esm/index.js CHANGED
@@ -4,12 +4,13 @@ export * from './amount';
4
4
  export * from './app';
5
5
  export * from './app-client';
6
6
  export * from './app-deploy';
7
+ export { optIn, optOut } from './asset';
8
+ export * from './dispenser-client';
7
9
  export * from './indexer-lookup';
8
10
  export * from './localnet';
9
11
  export * from './network-client';
10
12
  export * from './transaction';
11
13
  export * from './transfer';
12
- export * from './dispenser-client';
13
14
  /** The AlgoKit config. To update it use the configure method. */
14
15
  export const Config = new UpdatableConfig();
15
16
  //# sourceMappingURL=index.js.map
package/esm/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAA;AAEhD,cAAc,WAAW,CAAA;AACzB,cAAc,UAAU,CAAA;AACxB,cAAc,OAAO,CAAA;AACrB,cAAc,cAAc,CAAA;AAC5B,cAAc,cAAc,CAAA;AAC5B,cAAc,kBAAkB,CAAA;AAChC,cAAc,YAAY,CAAA;AAC1B,cAAc,kBAAkB,CAAA;AAChC,cAAc,eAAe,CAAA;AAC7B,cAAc,YAAY,CAAA;AAC1B,cAAc,oBAAoB,CAAA;AAElC,iEAAiE;AACjE,MAAM,CAAC,MAAM,MAAM,GAAG,IAAI,eAAe,EAAE,CAAA"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAA;AAEhD,cAAc,WAAW,CAAA;AACzB,cAAc,UAAU,CAAA;AACxB,cAAc,OAAO,CAAA;AACrB,cAAc,cAAc,CAAA;AAC5B,cAAc,cAAc,CAAA;AAC5B,OAAO,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,SAAS,CAAA;AACvC,cAAc,oBAAoB,CAAA;AAClC,cAAc,kBAAkB,CAAA;AAChC,cAAc,YAAY,CAAA;AAC1B,cAAc,kBAAkB,CAAA;AAChC,cAAc,eAAe,CAAA;AAC7B,cAAc,YAAY,CAAA;AAE1B,iEAAiE;AACjE,MAAM,CAAC,MAAM,MAAM,GAAG,IAAI,eAAe,EAAE,CAAA"}
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "main": "./cjs/index.js",
3
3
  "types": "./types/index.d.ts",
4
4
  "name": "@algorandfoundation/algokit-utils",
5
- "version": "4.0.0",
5
+ "version": "4.1.0",
6
6
  "private": false,
7
7
  "description": "A set of core Algorand utilities written in TypeScript and released via npm that make it easier to build solutions on Algorand.",
8
8
  "author": "Algorand Foundation",
@@ -0,0 +1,21 @@
1
+ import { Account, Algodv2 } from 'algosdk';
2
+ /**
3
+ * Opt in to a list of assets on the Algorand blockchain.
4
+ *
5
+ * @param client - An instance of the Algodv2 class from the `algosdk` library.
6
+ * @param account - An instance of the Account class from the `algosdk` library representing the account that wants to opt in to the assets.
7
+ * @param assetIds - An array of asset IDs that the account wants to opt in to.
8
+ * @returns A record object where the keys are the asset IDs and the values are the corresponding transaction IDs for successful opt-ins.
9
+ * @throws If there is an error during the opt-in process.
10
+ */
11
+ export declare function optIn(client: Algodv2, account: Account, assetIds: number[]): Promise<Record<number, string>>;
12
+ /**
13
+ * Opt out of multiple assets in Algorand blockchain.
14
+ *
15
+ * @param {Algodv2} client - An instance of the Algodv2 client used to interact with the Algorand blockchain.
16
+ * @param {Account} account - The Algorand account that wants to opt out of the assets.
17
+ * @param {number[]} assetIds - An array of asset IDs representing the assets to opt out of.
18
+ * @returns {Promise<Record<number, string>>} - A record object containing asset IDs as keys and their corresponding transaction IDs as values.
19
+ */
20
+ export declare function optOut(client: Algodv2, account: Account, assetIds: number[]): Promise<Record<number, string>>;
21
+ //# sourceMappingURL=asset.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"asset.d.ts","sourceRoot":"","sources":["../../src/asset.ts"],"names":[],"mappings":"AAAA,OAAgB,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,SAAS,CAAA;AAmEnD;;;;;;;;GAQG;AACH,wBAAsB,KAAK,CAAC,MAAM,EAAE,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,mCA2ChF;AAED;;;;;;;GAOG;AACH,wBAAsB,MAAM,CAAC,MAAM,EAAE,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CA6CnH"}
package/types/index.d.ts CHANGED
@@ -4,12 +4,13 @@ export * from './amount';
4
4
  export * from './app';
5
5
  export * from './app-client';
6
6
  export * from './app-deploy';
7
+ export { optIn, optOut } from './asset';
8
+ export * from './dispenser-client';
7
9
  export * from './indexer-lookup';
8
10
  export * from './localnet';
9
11
  export * from './network-client';
10
12
  export * from './transaction';
11
13
  export * from './transfer';
12
- export * from './dispenser-client';
13
14
  /** The AlgoKit config. To update it use the configure method. */
14
15
  export declare const Config: UpdatableConfig;
15
16
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAA;AAEhD,cAAc,WAAW,CAAA;AACzB,cAAc,UAAU,CAAA;AACxB,cAAc,OAAO,CAAA;AACrB,cAAc,cAAc,CAAA;AAC5B,cAAc,cAAc,CAAA;AAC5B,cAAc,kBAAkB,CAAA;AAChC,cAAc,YAAY,CAAA;AAC1B,cAAc,kBAAkB,CAAA;AAChC,cAAc,eAAe,CAAA;AAC7B,cAAc,YAAY,CAAA;AAC1B,cAAc,oBAAoB,CAAA;AAElC,iEAAiE;AACjE,eAAO,MAAM,MAAM,iBAAwB,CAAA"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAA;AAEhD,cAAc,WAAW,CAAA;AACzB,cAAc,UAAU,CAAA;AACxB,cAAc,OAAO,CAAA;AACrB,cAAc,cAAc,CAAA;AAC5B,cAAc,cAAc,CAAA;AAC5B,OAAO,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,SAAS,CAAA;AACvC,cAAc,oBAAoB,CAAA;AAClC,cAAc,kBAAkB,CAAA;AAChC,cAAc,YAAY,CAAA;AAC1B,cAAc,kBAAkB,CAAA;AAChC,cAAc,eAAe,CAAA;AAC7B,cAAc,YAAY,CAAA;AAE1B,iEAAiE;AACjE,eAAO,MAAM,MAAM,iBAAwB,CAAA"}