@algorandfoundation/algokit-utils 7.0.0-beta.2 → 7.0.0-beta.21
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/LICENSE +21 -0
- package/README.md +3 -25
- package/account/account.d.ts +1 -2
- package/account/account.js +6 -4
- package/account/account.js.map +1 -1
- package/account/account.mjs +6 -4
- package/account/account.mjs.map +1 -1
- package/account/get-account-config-from-environment.d.ts +0 -1
- package/account/get-account-config-from-environment.js.map +1 -1
- package/account/get-account-config-from-environment.mjs.map +1 -1
- package/account/get-account.d.ts +0 -1
- package/account/get-account.js.map +1 -1
- package/account/get-account.mjs.map +1 -1
- package/account/get-dispenser-account.d.ts +0 -1
- package/account/get-dispenser-account.js.map +1 -1
- package/account/get-dispenser-account.mjs.map +1 -1
- package/account/index.d.ts +0 -1
- package/account/mnemonic-account.d.ts +0 -1
- package/account/mnemonic-account.js.map +1 -1
- package/account/mnemonic-account.mjs.map +1 -1
- package/amount.d.ts +14 -5
- package/amount.js +6 -0
- package/amount.js.map +1 -1
- package/amount.mjs +6 -0
- package/amount.mjs.map +1 -1
- package/app-client.d.ts +15 -1
- package/app-client.js +15 -0
- package/app-client.js.map +1 -1
- package/app-client.mjs +15 -0
- package/app-client.mjs.map +1 -1
- package/app-deploy.d.ts +0 -1
- package/app-deploy.js +4 -6
- package/app-deploy.js.map +1 -1
- package/app-deploy.mjs +7 -9
- package/app-deploy.mjs.map +1 -1
- package/app.d.ts +10 -11
- package/app.js +15 -11
- package/app.js.map +1 -1
- package/app.mjs +15 -11
- package/app.mjs.map +1 -1
- package/asset.d.ts +3 -4
- package/asset.js +3 -6
- package/asset.js.map +1 -1
- package/asset.mjs +3 -6
- package/asset.mjs.map +1 -1
- package/config.d.ts +0 -1
- package/config.js.map +1 -1
- package/config.mjs.map +1 -1
- package/debugging/debugging.d.ts +3 -5
- package/debugging/debugging.js +4 -128
- package/debugging/debugging.js.map +1 -1
- package/debugging/debugging.mjs +4 -109
- package/debugging/debugging.mjs.map +1 -1
- package/debugging/index.d.ts +0 -2
- package/dispenser-client.d.ts +0 -1
- package/dispenser-client.js.map +1 -1
- package/dispenser-client.mjs.map +1 -1
- package/index.d.ts +6 -5
- package/index.js +48 -38
- package/index.js.map +1 -1
- package/index.mjs +6 -5
- package/index.mjs.map +1 -1
- package/indexer-lookup.d.ts +0 -1
- package/indexer-lookup.js.map +1 -1
- package/indexer-lookup.mjs.map +1 -1
- package/localnet/get-kmd-wallet-account.d.ts +0 -1
- package/localnet/get-kmd-wallet-account.js.map +1 -1
- package/localnet/get-kmd-wallet-account.mjs.map +1 -1
- package/localnet/get-localnet-dispenser-account.d.ts +0 -1
- package/localnet/get-localnet-dispenser-account.js.map +1 -1
- package/localnet/get-localnet-dispenser-account.mjs.map +1 -1
- package/localnet/get-or-create-kmd-wallet-account.d.ts +0 -1
- package/localnet/get-or-create-kmd-wallet-account.js.map +1 -1
- package/localnet/get-or-create-kmd-wallet-account.mjs.map +1 -1
- package/localnet/index.d.ts +0 -1
- package/localnet/is-localnet.d.ts +0 -1
- package/localnet/is-localnet.js.map +1 -1
- package/localnet/is-localnet.mjs.map +1 -1
- package/network-client.d.ts +0 -1
- package/network-client.js.map +1 -1
- package/network-client.mjs.map +1 -1
- package/package.json +2 -2
- package/testing/_asset.d.ts +0 -1
- package/testing/account.d.ts +0 -1
- package/testing/account.js.map +1 -1
- package/testing/account.mjs.map +1 -1
- package/testing/fixtures/algokit-log-capture-fixture.d.ts +0 -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 +0 -1
- package/testing/fixtures/algorand-fixture.js +1 -1
- package/testing/fixtures/algorand-fixture.js.map +1 -1
- package/testing/fixtures/algorand-fixture.mjs +1 -1
- package/testing/fixtures/algorand-fixture.mjs.map +1 -1
- package/testing/fixtures/index.d.ts +0 -1
- package/testing/index.d.ts +0 -1
- package/testing/indexer.d.ts +0 -1
- package/testing/indexer.js.map +1 -1
- package/testing/indexer.mjs.map +1 -1
- package/testing/test-logger.d.ts +0 -1
- package/testing/test-logger.js +1 -3
- package/testing/test-logger.js.map +1 -1
- package/testing/test-logger.mjs +1 -3
- package/testing/test-logger.mjs.map +1 -1
- package/testing/transaction-logger.d.ts +0 -1
- package/testing/transaction-logger.js.map +1 -1
- package/testing/transaction-logger.mjs.map +1 -1
- package/transaction/index.d.ts +0 -1
- package/transaction/legacy-bridge.d.ts +5 -6
- package/transaction/legacy-bridge.js +1 -1
- package/transaction/legacy-bridge.js.map +1 -1
- package/transaction/legacy-bridge.mjs +4 -4
- package/transaction/legacy-bridge.mjs.map +1 -1
- package/transaction/perform-atomic-transaction-composer-simulate.d.ts +0 -1
- package/transaction/perform-atomic-transaction-composer-simulate.js +1 -0
- package/transaction/perform-atomic-transaction-composer-simulate.js.map +1 -1
- package/transaction/perform-atomic-transaction-composer-simulate.mjs +1 -0
- package/transaction/perform-atomic-transaction-composer-simulate.mjs.map +1 -1
- package/transaction/transaction.d.ts +41 -6
- package/transaction/transaction.js +113 -61
- package/transaction/transaction.js.map +1 -1
- package/transaction/transaction.mjs +113 -62
- package/transaction/transaction.mjs.map +1 -1
- package/transfer/index.d.ts +0 -1
- package/transfer/transfer-algos.d.ts +1 -2
- package/transfer/transfer-algos.js +1 -1
- package/transfer/transfer-algos.js.map +1 -1
- package/transfer/transfer-algos.mjs +1 -1
- package/transfer/transfer-algos.mjs.map +1 -1
- package/transfer/transfer.d.ts +1 -2
- package/transfer/transfer.js +3 -3
- package/transfer/transfer.js.map +1 -1
- package/transfer/transfer.mjs +3 -3
- package/transfer/transfer.mjs.map +1 -1
- package/types/account-manager.d.ts +15 -7
- package/types/account-manager.js +27 -11
- package/types/account-manager.js.map +1 -1
- package/types/account-manager.mjs +29 -13
- package/types/account-manager.mjs.map +1 -1
- package/types/account.d.ts +9 -1
- package/types/account.js.map +1 -1
- package/types/account.mjs.map +1 -1
- package/types/algo-http-client-with-retry.d.ts +0 -1
- package/types/algo-http-client-with-retry.js.map +1 -1
- package/types/algo-http-client-with-retry.mjs.map +1 -1
- package/types/algorand-client-interface.d.ts +28 -0
- package/types/algorand-client-interface.js +3 -0
- package/types/algorand-client-interface.js.map +1 -0
- package/types/algorand-client-interface.mjs +2 -0
- package/types/algorand-client-interface.mjs.map +1 -0
- package/types/algorand-client-transaction-creator.d.ts +33 -34
- package/types/algorand-client-transaction-creator.js +31 -31
- package/types/algorand-client-transaction-creator.js.map +1 -1
- package/types/algorand-client-transaction-creator.mjs +31 -31
- package/types/algorand-client-transaction-creator.mjs.map +1 -1
- package/types/algorand-client-transaction-sender.d.ts +31 -32
- package/types/algorand-client-transaction-sender.js +25 -9
- package/types/algorand-client-transaction-sender.js.map +1 -1
- package/types/algorand-client-transaction-sender.mjs +25 -9
- package/types/algorand-client-transaction-sender.mjs.map +1 -1
- package/types/algorand-client.d.ts +13 -13
- package/types/algorand-client.js +10 -10
- package/types/algorand-client.js.map +1 -1
- package/types/algorand-client.mjs +12 -12
- package/types/algorand-client.mjs.map +1 -1
- package/types/amount.d.ts +10 -11
- package/types/amount.js +7 -7
- package/types/amount.js.map +1 -1
- package/types/amount.mjs +7 -7
- package/types/amount.mjs.map +1 -1
- package/types/app-arc56.d.ts +359 -0
- package/types/app-arc56.js +184 -0
- package/types/app-arc56.js.map +1 -0
- package/types/app-arc56.mjs +175 -0
- package/types/app-arc56.mjs.map +1 -0
- package/types/app-client.d.ts +1494 -8
- package/types/app-client.js +1009 -19
- package/types/app-client.js.map +1 -1
- package/types/app-client.mjs +1009 -20
- package/types/app-client.mjs.map +1 -1
- package/types/app-deployer.d.ts +19 -14
- package/types/app-deployer.js +25 -25
- package/types/app-deployer.js.map +1 -1
- package/types/app-deployer.mjs +27 -27
- package/types/app-deployer.mjs.map +1 -1
- package/types/app-factory.d.ts +846 -0
- package/types/app-factory.js +409 -0
- package/types/app-factory.js.map +1 -0
- package/types/app-factory.mjs +407 -0
- package/types/app-factory.mjs.map +1 -0
- package/types/app-manager.d.ts +12 -3
- package/types/app-manager.js +13 -15
- package/types/app-manager.js.map +1 -1
- package/types/app-manager.mjs +13 -15
- package/types/app-manager.mjs.map +1 -1
- package/types/app-spec.d.ts +2 -1
- package/types/app-spec.js +127 -0
- package/types/app-spec.js.map +1 -1
- package/types/app-spec.mjs +126 -0
- package/types/app-spec.mjs.map +1 -1
- package/types/app.d.ts +14 -9
- package/types/app.js.map +1 -1
- package/types/app.mjs.map +1 -1
- package/types/asset-manager.d.ts +7 -7
- package/types/asset-manager.js +5 -6
- package/types/asset-manager.js.map +1 -1
- package/types/asset-manager.mjs +5 -6
- package/types/asset-manager.mjs.map +1 -1
- package/types/asset.d.ts +0 -1
- package/types/async-event-emitter.d.ts +14 -0
- package/types/async-event-emitter.js +50 -0
- package/types/async-event-emitter.js.map +1 -0
- package/types/async-event-emitter.mjs +48 -0
- package/types/async-event-emitter.mjs.map +1 -0
- package/types/client-manager.d.ts +131 -51
- package/types/client-manager.js +143 -23
- package/types/client-manager.js.map +1 -1
- package/types/client-manager.mjs +144 -24
- package/types/client-manager.mjs.map +1 -1
- package/types/composer.d.ts +110 -37
- package/types/composer.js +139 -26
- package/types/composer.js.map +1 -1
- package/types/composer.mjs +140 -27
- package/types/composer.mjs.map +1 -1
- package/types/config.d.ts +3 -6
- package/types/config.js +5 -44
- package/types/config.js.map +1 -1
- package/types/config.mjs +5 -27
- package/types/config.mjs.map +1 -1
- package/types/debugging.d.ts +29 -101
- package/types/debugging.js +16 -109
- package/types/debugging.js.map +1 -1
- package/types/debugging.mjs +12 -107
- package/types/debugging.mjs.map +1 -1
- package/types/dispenser-client.d.ts +1 -2
- package/types/dispenser-client.js +6 -5
- package/types/dispenser-client.js.map +1 -1
- package/types/dispenser-client.mjs +6 -5
- package/types/dispenser-client.mjs.map +1 -1
- package/types/expand.d.ts +0 -1
- package/types/indexer.d.ts +0 -1
- package/types/indexer.js.map +1 -1
- package/types/indexer.mjs.map +1 -1
- package/types/kmd-account-manager.d.ts +0 -1
- package/types/kmd-account-manager.js +2 -2
- package/types/kmd-account-manager.js.map +1 -1
- package/types/kmd-account-manager.mjs +4 -4
- package/types/kmd-account-manager.mjs.map +1 -1
- package/types/lifecycle-events.d.ts +10 -0
- package/types/lifecycle-events.js +8 -0
- package/types/lifecycle-events.js.map +1 -0
- package/types/lifecycle-events.mjs +8 -0
- package/types/lifecycle-events.mjs.map +1 -0
- package/types/logging.d.ts +0 -1
- package/types/logging.js.map +1 -1
- package/types/logging.mjs.map +1 -1
- package/types/logic-error.d.ts +2 -4
- package/types/logic-error.js +3 -3
- package/types/logic-error.js.map +1 -1
- package/types/logic-error.mjs +3 -3
- package/types/logic-error.mjs.map +1 -1
- package/types/network-client.d.ts +13 -1
- package/types/network-client.js.map +1 -1
- package/types/network-client.mjs.map +1 -1
- package/types/testing.d.ts +3 -4
- package/types/transaction.d.ts +14 -4
- package/types/transfer.d.ts +0 -1
- package/types/urlTokenBaseHTTPClient.d.ts +0 -1
- package/types/urlTokenBaseHTTPClient.js +1 -1
- package/types/urlTokenBaseHTTPClient.js.map +1 -1
- package/types/urlTokenBaseHTTPClient.mjs +1 -1
- package/types/urlTokenBaseHTTPClient.mjs.map +1 -1
- package/util.d.ts +2 -2
- package/util.js +11 -10
- package/util.js.map +1 -1
- package/util.mjs +11 -10
- package/util.mjs.map +1 -1
- package/account/account.d.ts.map +0 -1
- package/account/get-account-config-from-environment.d.ts.map +0 -1
- package/account/get-account.d.ts.map +0 -1
- package/account/get-dispenser-account.d.ts.map +0 -1
- package/account/index.d.ts.map +0 -1
- package/account/mnemonic-account.d.ts.map +0 -1
- package/amount.d.ts.map +0 -1
- package/app-client.d.ts.map +0 -1
- package/app-deploy.d.ts.map +0 -1
- package/app.d.ts.map +0 -1
- package/asset.d.ts.map +0 -1
- package/config.d.ts.map +0 -1
- package/debugging/debugging.d.ts.map +0 -1
- package/debugging/index.d.ts.map +0 -1
- package/debugging/simulate-and-persist-response.d.ts +0 -20
- package/debugging/simulate-and-persist-response.d.ts.map +0 -1
- package/debugging/simulate-and-persist-response.js +0 -108
- package/debugging/simulate-and-persist-response.js.map +0 -1
- package/debugging/simulate-and-persist-response.mjs +0 -89
- package/debugging/simulate-and-persist-response.mjs.map +0 -1
- package/dispenser-client.d.ts.map +0 -1
- package/index.d.ts.map +0 -1
- package/indexer-lookup.d.ts.map +0 -1
- package/localnet/get-kmd-wallet-account.d.ts.map +0 -1
- package/localnet/get-localnet-dispenser-account.d.ts.map +0 -1
- package/localnet/get-or-create-kmd-wallet-account.d.ts.map +0 -1
- package/localnet/index.d.ts.map +0 -1
- package/localnet/is-localnet.d.ts.map +0 -1
- package/network-client.d.ts.map +0 -1
- package/testing/_asset.d.ts.map +0 -1
- package/testing/account.d.ts.map +0 -1
- package/testing/fixtures/algokit-log-capture-fixture.d.ts.map +0 -1
- package/testing/fixtures/algorand-fixture.d.ts.map +0 -1
- package/testing/fixtures/index.d.ts.map +0 -1
- package/testing/index.d.ts.map +0 -1
- package/testing/indexer.d.ts.map +0 -1
- package/testing/test-logger.d.ts.map +0 -1
- package/testing/transaction-logger.d.ts.map +0 -1
- package/transaction/index.d.ts.map +0 -1
- package/transaction/legacy-bridge.d.ts.map +0 -1
- package/transaction/perform-atomic-transaction-composer-simulate.d.ts.map +0 -1
- package/transaction/transaction.d.ts.map +0 -1
- package/transfer/index.d.ts.map +0 -1
- package/transfer/transfer-algos.d.ts.map +0 -1
- package/transfer/transfer.d.ts.map +0 -1
- package/types/account-manager.d.ts.map +0 -1
- package/types/account.d.ts.map +0 -1
- package/types/algo-http-client-with-retry.d.ts.map +0 -1
- package/types/algorand-client-transaction-creator.d.ts.map +0 -1
- package/types/algorand-client-transaction-sender.d.ts.map +0 -1
- package/types/algorand-client.d.ts.map +0 -1
- package/types/amount.d.ts.map +0 -1
- package/types/app-client.d.ts.map +0 -1
- package/types/app-deployer.d.ts.map +0 -1
- package/types/app-manager.d.ts.map +0 -1
- package/types/app-spec.d.ts.map +0 -1
- package/types/app.d.ts.map +0 -1
- package/types/asset-manager.d.ts.map +0 -1
- package/types/asset.d.ts.map +0 -1
- package/types/client-manager.d.ts.map +0 -1
- package/types/composer.d.ts.map +0 -1
- package/types/config.d.ts.map +0 -1
- package/types/debugging.d.ts.map +0 -1
- package/types/dispenser-client.d.ts.map +0 -1
- package/types/expand.d.ts.map +0 -1
- package/types/indexer.d.ts.map +0 -1
- package/types/kmd-account-manager.d.ts.map +0 -1
- package/types/logging.d.ts.map +0 -1
- package/types/logic-error.d.ts.map +0 -1
- package/types/network-client.d.ts.map +0 -1
- package/types/testing.d.ts.map +0 -1
- package/types/transaction.d.ts.map +0 -1
- package/types/transfer.d.ts.map +0 -1
- package/types/urlTokenBaseHTTPClient.d.ts.map +0 -1
- package/util.d.ts.map +0 -1
package/types/app.d.ts
CHANGED
|
@@ -96,7 +96,7 @@ export type ABIAppCallArgs = CoreAppCallArgs & {
|
|
|
96
96
|
**/
|
|
97
97
|
export type AppCallArgs = RawAppCallArgs | ABIAppCallArgs;
|
|
98
98
|
/**
|
|
99
|
-
* @deprecated Use `
|
|
99
|
+
* @deprecated Use `TransactionComposer` to construct create app transactions instead.
|
|
100
100
|
*
|
|
101
101
|
* Base interface for common data passed to an app create or update.
|
|
102
102
|
*/
|
|
@@ -115,7 +115,7 @@ interface CreateOrUpdateAppParams extends SendTransactionParams {
|
|
|
115
115
|
args?: AppCallArgs;
|
|
116
116
|
}
|
|
117
117
|
/**
|
|
118
|
-
* @deprecated Use `
|
|
118
|
+
* @deprecated Use `TransactionComposer` to construct create app transactions instead.
|
|
119
119
|
*
|
|
120
120
|
* Parameters that are passed in when creating an app. */
|
|
121
121
|
export interface CreateAppParams extends CreateOrUpdateAppParams {
|
|
@@ -125,7 +125,7 @@ export interface CreateAppParams extends CreateOrUpdateAppParams {
|
|
|
125
125
|
onCompleteAction?: Exclude<AppCallType, 'clear_state'> | Exclude<OnApplicationComplete, OnApplicationComplete.ClearStateOC>;
|
|
126
126
|
}
|
|
127
127
|
/**
|
|
128
|
-
* @deprecated Use `
|
|
128
|
+
* @deprecated Use `TransactionComposer` to construct update app transactions instead.
|
|
129
129
|
*
|
|
130
130
|
* Parameters that are passed in when updating an app. */
|
|
131
131
|
export interface UpdateAppParams extends CreateOrUpdateAppParams {
|
|
@@ -181,7 +181,7 @@ export interface CompiledTeal {
|
|
|
181
181
|
teal: string;
|
|
182
182
|
/** The compiled code */
|
|
183
183
|
compiled: string;
|
|
184
|
-
/** The
|
|
184
|
+
/** The hash returned by the compiler */
|
|
185
185
|
compiledHash: string;
|
|
186
186
|
/** The base64 encoded code as a byte array */
|
|
187
187
|
compiledBase64ToBytes: Uint8Array;
|
|
@@ -199,10 +199,12 @@ export interface AppCallTransactionResult extends AppCallTransactionResultOfType
|
|
|
199
199
|
export type ABIReturn = {
|
|
200
200
|
rawReturnValue: Uint8Array;
|
|
201
201
|
returnValue: ABIValue;
|
|
202
|
+
method: ABIMethod;
|
|
202
203
|
decodeError: undefined;
|
|
203
204
|
} | {
|
|
204
|
-
rawReturnValue
|
|
205
|
-
returnValue
|
|
205
|
+
rawReturnValue?: undefined;
|
|
206
|
+
returnValue?: undefined;
|
|
207
|
+
method?: undefined;
|
|
206
208
|
decodeError: Error;
|
|
207
209
|
};
|
|
208
210
|
/**
|
|
@@ -285,13 +287,17 @@ export interface AppDeploymentParams extends Omit<CreateAppParams, 'onCompleteAc
|
|
|
285
287
|
/** Any args to pass to any delete transaction that is issued as part of deployment */
|
|
286
288
|
deleteArgs?: AppCallArgs;
|
|
287
289
|
}
|
|
288
|
-
/** The result of compiling the approval and clear TEAL for an app */
|
|
290
|
+
/** The result of compiling the approval and clear state TEAL programs for an app */
|
|
289
291
|
export interface AppCompilationResult {
|
|
290
292
|
/** The compilation result of approval */
|
|
291
293
|
compiledApproval: CompiledTeal;
|
|
292
294
|
/** The compilation result of clear */
|
|
293
295
|
compiledClear: CompiledTeal;
|
|
294
296
|
}
|
|
297
|
+
export type AppReturn<TReturn> = {
|
|
298
|
+
/** The ABI method call return value */
|
|
299
|
+
return?: TReturn;
|
|
300
|
+
};
|
|
295
301
|
/** Result from sending a single app transaction. */
|
|
296
302
|
export type SendAppTransactionResult = Expand<SendSingleTransactionResult & {
|
|
297
303
|
/** If an ABI method was called the processed return value */
|
|
@@ -309,7 +315,7 @@ export type SendAppCreateTransactionResult = Expand<SendAppUpdateTransactionResu
|
|
|
309
315
|
/** Object holding app state values */
|
|
310
316
|
export interface AppState {
|
|
311
317
|
[key: string]: {
|
|
312
|
-
value:
|
|
318
|
+
value: bigint;
|
|
313
319
|
keyRaw: Uint8Array;
|
|
314
320
|
keyBase64: string;
|
|
315
321
|
} | {
|
|
@@ -355,4 +361,3 @@ export interface BoxValuesRequestParams {
|
|
|
355
361
|
type: ABIType;
|
|
356
362
|
}
|
|
357
363
|
export {};
|
|
358
|
-
//# sourceMappingURL=app.d.ts.map
|
package/types/app.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"app.js","sources":["../../src/types/app.ts"],"sourcesContent":[null],"names":["OnUpdate","OnSchemaBreak"],"mappings":";;AAsBA;AACO,MAAM,uBAAuB,GAAG,iBAAgB;AAEvD;AACO,MAAM,uBAAuB,GAAG,iBAAgB;AAEvD;AACO,MAAM,oBAAoB,GAAG,mBAAkB;AAEtD;AACO,MAAM,iBAAiB,GAAG,KAAI;AAErC;AACa,MAAA,iBAAiB,GAAG,IAAI,UAAU,CAAC,CAAC,EAAE,EAAE,EAAE,EAAE,GAAG,EAAE,GAAG,CAAC,EAAC;AA2PnE;AACYA,0BASX;AATD,CAAA,UAAY,QAAQ,EAAA;;AAElB,IAAA,QAAA,CAAA,QAAA,CAAA,MAAA,CAAA,GAAA,CAAA,CAAA,GAAA,MAAI,CAAA;;AAEJ,IAAA,QAAA,CAAA,QAAA,CAAA,WAAA,CAAA,GAAA,CAAA,CAAA,GAAA,WAAS,CAAA;;AAET,IAAA,QAAA,CAAA,QAAA,CAAA,YAAA,CAAA,GAAA,CAAA,CAAA,GAAA,YAAU,CAAA;;AAEV,IAAA,QAAA,CAAA,QAAA,CAAA,WAAA,CAAA,GAAA,CAAA,CAAA,GAAA,WAAS,CAAA;AACX,CAAC,EATWA,gBAAQ,KAARA,gBAAQ,GASnB,EAAA,CAAA,CAAA,CAAA;AAED;AACYC,+BAOX;AAPD,CAAA,UAAY,aAAa,EAAA;;AAEvB,IAAA,aAAA,CAAA,aAAA,CAAA,MAAA,CAAA,GAAA,CAAA,CAAA,GAAA,MAAI,CAAA;;AAEJ,IAAA,aAAA,CAAA,aAAA,CAAA,YAAA,CAAA,GAAA,CAAA,CAAA,GAAA,YAAU,CAAA;;AAEV,IAAA,aAAA,CAAA,aAAA,CAAA,WAAA,CAAA,GAAA,CAAA,CAAA,GAAA,WAAS,CAAA;AACX,CAAC,EAPWA,qBAAa,KAAbA,qBAAa,GAOxB,EAAA,CAAA,CAAA;;;;;;;;"}
|
|
1
|
+
{"version":3,"file":"app.js","sources":["../../src/types/app.ts"],"sourcesContent":["import algosdk from 'algosdk'\nimport { Expand } from './expand'\nimport {\n SendSingleTransactionResult,\n SendTransactionFrom,\n SendTransactionParams,\n SendTransactionResult,\n SendTransactionResults,\n TransactionNote,\n TransactionToSign,\n} from './transaction'\nimport ABIArgument = algosdk.ABIArgument\nimport ABIMethod = algosdk.ABIMethod\nimport ABIMethodParams = algosdk.ABIMethodParams\nimport ABIType = algosdk.ABIType\nimport ABIValue = algosdk.ABIValue\nimport Address = algosdk.Address\nimport OnApplicationComplete = algosdk.OnApplicationComplete\nimport SourceMap = algosdk.SourceMap\nimport SuggestedParams = algosdk.SuggestedParams\nimport Transaction = algosdk.Transaction\n\n/** The name of the TEAL template variable for deploy-time immutability control */\nexport const UPDATABLE_TEMPLATE_NAME = 'TMPL_UPDATABLE'\n\n/** The name of the TEAL template variable for deploy-time permanence control */\nexport const DELETABLE_TEMPLATE_NAME = 'TMPL_DELETABLE'\n\n/** The app create/update [ARC-2](https://github.com/algorandfoundation/ARCs/blob/main/ARCs/arc-0002.md) transaction note prefix */\nexport const APP_DEPLOY_NOTE_DAPP = 'ALGOKIT_DEPLOYER'\n\n/** The maximum number of bytes in a single app code page */\nexport const APP_PAGE_MAX_SIZE = 2048\n\n/** First 4 bytes of SHA-512/256 hash of \"return\" for retrieving ABI return values */\nexport const ABI_RETURN_PREFIX = new Uint8Array([21, 31, 124, 117])\n\n/** Information about an Algorand app */\nexport interface AppReference {\n /** The id of the app */\n appId: number | bigint\n /** The Algorand address of the account associated with the app */\n appAddress: string\n}\n\n/**\n * @deprecated Use `types/app-manager/BoxReference` instead.\n *\n * A grouping of the app ID and name of the box in an Uint8Array\n */\nexport interface BoxReference {\n /**\n * A unique application id\n */\n appId: number | bigint\n /**\n * Name of box to reference\n */\n name: BoxIdentifier\n}\n\n/**\n * @deprecated Use `types/app-manager/BoxIdentifier` instead.\n *\n * Something that identifies a box name - either a:\n * * `Uint8Array`\n * * `string` (that will be encoded to a Uint8Array)\n * * `SendTransactionFrom` (encoded into the public key address of the corresponding account)\n */\nexport type BoxIdentifier = string | Uint8Array | SendTransactionFrom\n\n/** Common app call arguments for ABI and non-ABI (raw) calls */\nexport interface CoreAppCallArgs {\n /** The optional lease for the transaction */\n lease?: string | Uint8Array\n /** Any box references to load */\n boxes?: (algosdk.BoxReference | BoxReference | BoxIdentifier)[]\n /** The address of any accounts to load in */\n accounts?: (string | Address)[]\n /** IDs of any apps to load into the foreignApps array */\n apps?: number[]\n /** IDs of any assets to load into the foreignAssets array */\n assets?: number[]\n /** Optional account / account address that should be authorised to transact on behalf of the from account the app call is sent from after this transaction.\n *\n * **Note:** Use with extreme caution and review the [official rekey guidance](https://developer.algorand.org/docs/get-details/accounts/rekey/) first.\n */\n rekeyTo?: SendTransactionFrom | string\n}\n\n/**\n * App call args with non-ABI (raw) values (minus some processing like encoding strings as binary)\n */\nexport interface RawAppCallArgs extends CoreAppCallArgs {\n /** Any application arguments to pass through */\n appArgs?: (Uint8Array | string)[]\n /** Property to aid intellisense */\n method?: undefined\n}\n\n/** An argument for an ABI method, either a primitive value, or a transaction with or without signer, or the unawaited async return value of an algokit method that returns a `SendTransactionResult` */\nexport type ABIAppCallArg =\n | ABIArgument\n | TransactionToSign\n | Transaction\n | Promise<SendTransactionResult>\n | SendTransactionResult\n | undefined\n\n/**\n * App call args for an ABI call\n */\nexport type ABIAppCallArgs = CoreAppCallArgs & {\n /** The ABI method to call */\n method: ABIMethodParams | ABIMethod\n /** The ABI method args to pass in */\n methodArgs: ABIAppCallArg[]\n}\n\n/** Arguments to pass to an app call either:\n * * The raw app call values to pass through into the transaction (after processing); or\n * * An ABI method definition (method and args)\n **/\nexport type AppCallArgs = RawAppCallArgs | ABIAppCallArgs\n\n/**\n * @deprecated Use `TransactionComposer` to construct create app transactions instead.\n *\n * Base interface for common data passed to an app create or update.\n */\ninterface CreateOrUpdateAppParams extends SendTransactionParams {\n /** The account (with private key loaded) that will send the transaction */\n from: SendTransactionFrom\n /** The approval program as raw teal (string) or compiled teal, base 64 encoded as a byte array (Uint8Array) */\n approvalProgram: Uint8Array | string\n /** The clear state program as raw teal (string) or compiled teal, base 64 encoded as a byte array (Uint8Array) */\n clearStateProgram: Uint8Array | string\n /** Optional transaction parameters */\n transactionParams?: SuggestedParams\n /** The (optional) transaction note */\n note?: TransactionNote\n /** The arguments passed in to the app call */\n args?: AppCallArgs\n}\n\n/**\n * @deprecated Use `TransactionComposer` to construct create app transactions instead.\n *\n * Parameters that are passed in when creating an app. */\nexport interface CreateAppParams extends CreateOrUpdateAppParams {\n /** The storage schema to request for the created app */\n schema: AppStorageSchema\n /** Override the on-completion action for the create call; defaults to NoOp */\n onCompleteAction?: Exclude<AppCallType, 'clear_state'> | Exclude<OnApplicationComplete, OnApplicationComplete.ClearStateOC>\n}\n\n/**\n * @deprecated Use `TransactionComposer` to construct update app transactions instead.\n *\n * Parameters that are passed in when updating an app. */\nexport interface UpdateAppParams extends CreateOrUpdateAppParams {\n /** The id of the app to update */\n appId: number | bigint\n}\n\n/**\n * @deprecated Use `algosdk.OnApplicationComplete` directly instead.\n *\n * The type of call / [on-completion action](https://developer.algorand.org/docs/get-details/dapps/smart-contracts/apps/#the-lifecycle-of-a-smart-contract) for a smart contract call.\n *\n * Equivalent of `algosdk.OnApplicationComplete`, but as a more convenient string enum.\n *\n * * `no_op`: Normal smart contract call, no special on-complete action\n * * `opt_in`: Opt-in to smart contract local storage\n * * `close_out`: Close-out local storage storage\n * * `clear_state`: Clear local storage state\n * * `update_application`: Update the smart contract\n * * `delete_application`: Delete the smart contract\n */\nexport type AppCallType = 'no_op' | 'opt_in' | 'close_out' | 'clear_state' | 'update_application' | 'delete_application'\n\n/** Parameters representing a call to an app. */\nexport interface AppCallParams extends SendTransactionParams {\n /** The id of the app to call */\n appId: number | bigint\n /** The type of call, everything except create (see `createApp`) and update (see `updateApp`) */\n callType: Exclude<AppCallType, 'update_application'> | Exclude<OnApplicationComplete, OnApplicationComplete.UpdateApplicationOC>\n /** The account to make the call from */\n from: SendTransactionFrom\n /** Optional transaction parameters */\n transactionParams?: SuggestedParams\n /** The (optional) transaction note */\n note?: TransactionNote\n /** The arguments passed in to the app call */\n args?: AppCallArgs\n}\n\n/** Parameters representing the storage schema of an app. */\nexport interface AppStorageSchema {\n /** Restricts number of ints in per-user local state */\n localInts: number\n /** Restricts number of byte slices in per-user local state */\n localByteSlices: number\n /** Restricts number of ints in global state */\n globalInts: number\n /** Restricts number of byte slices in global state */\n globalByteSlices: number\n /** Any extra pages that are needed for the smart contract; if left blank then the right number of pages will be calculated based on the teal code size */\n extraPages?: number\n}\n\n/** Information about a compiled teal program */\nexport interface CompiledTeal {\n /** Original TEAL code */\n teal: string\n /** The compiled code */\n compiled: string\n /** The hash returned by the compiler */\n compiledHash: string\n /** The base64 encoded code as a byte array */\n compiledBase64ToBytes: Uint8Array\n /** Source map from the compilation */\n sourceMap: SourceMap\n}\n\nexport interface AppCallTransactionResultOfType<T> extends SendTransactionResults, SendTransactionResult {\n /** If an ABI method was called the processed return value */\n return?: T\n}\n\n/** Result from calling an app */\n// eslint-disable-next-line @typescript-eslint/no-empty-interface\nexport interface AppCallTransactionResult extends AppCallTransactionResultOfType<ABIReturn> {}\n\n/** The return value of an ABI method call */\nexport type ABIReturn =\n | {\n rawReturnValue: Uint8Array\n returnValue: ABIValue\n method: ABIMethod\n decodeError: undefined\n }\n | { rawReturnValue?: undefined; returnValue?: undefined; method?: undefined; decodeError: Error }\n\n/**\n * The payload of the metadata to add to the transaction note when deploying an app, noting it will be prefixed with `APP_DEPLOY_NOTE_PREFIX`.\n */\nexport interface AppDeployMetadata {\n /** The unique name identifier of the app within the creator account */\n name: string\n /** The version of app that is / will be deployed */\n version: string\n /** Whether or not the app is deletable / permanent / unspecified */\n deletable?: boolean\n /** Whether or not the app is updatable / immutable / unspecified */\n updatable?: boolean\n}\n\n/** The metadata that can be collected about a deployed app */\nexport interface AppMetadata extends AppReference, AppDeployMetadata {\n /** The round the app was created */\n createdRound: number\n /** The last round that the app was updated */\n updatedRound: number\n /** The metadata when the app was created */\n createdMetadata: AppDeployMetadata\n /** Whether or not the app is deleted */\n deleted: boolean\n}\n\n/** A lookup of name -> Algorand app for a creator */\nexport interface AppLookup {\n creator: Readonly<string>\n apps: Readonly<{\n [name: string]: AppMetadata\n }>\n}\n\n/** Dictionary of deploy-time parameters to replace in a teal template.\n *\n * Note: Looks for `TMPL_{parameter}` for template replacements i.e. you can leave out the `TMPL_`.\n *\n */\nexport interface TealTemplateParams {\n [key: string]: string | bigint | number | Uint8Array\n}\n\n/** What action to perform when deploying an app and an update is detected in the TEAL code */\nexport enum OnUpdate {\n /** Fail the deployment */\n Fail,\n /** Update the app */\n UpdateApp,\n /** Delete the app and create a new one in its place */\n ReplaceApp,\n /** Create a new app */\n AppendApp,\n}\n\n/** What action to perform when deploying an app and a breaking schema change is detected */\nexport enum OnSchemaBreak {\n /** Fail the deployment */\n Fail,\n /** Delete the app and create a new one in its place */\n ReplaceApp,\n /** Create a new app */\n AppendApp,\n}\n\n/** The parameters to deploy an app */\nexport interface AppDeploymentParams\n extends Omit<CreateAppParams, 'onCompleteAction' | 'args' | 'note' | 'skipSending' | 'skipWaiting' | 'atc'> {\n /** The deployment metadata */\n metadata: AppDeployMetadata\n /** Any deploy-time parameters to replace in the TEAL code */\n deployTimeParams?: TealTemplateParams\n /** What action to perform if a schema break is detected */\n onSchemaBreak?: 'replace' | 'fail' | 'append' | OnSchemaBreak\n /** What action to perform if a TEAL update is detected */\n onUpdate?: 'update' | 'replace' | 'fail' | 'append' | OnUpdate\n /** Optional cached value of the existing apps for the given creator */\n existingDeployments?: AppLookup\n /** Any args to pass to any create transaction that is issued as part of deployment */\n createArgs?: AppCallArgs\n /** Override the on-completion action for the create call; defaults to NoOp */\n createOnCompleteAction?: Exclude<AppCallType, 'clear_state'> | Exclude<OnApplicationComplete, OnApplicationComplete.ClearStateOC>\n /** Any args to pass to any update transaction that is issued as part of deployment */\n updateArgs?: AppCallArgs\n /** Any args to pass to any delete transaction that is issued as part of deployment */\n deleteArgs?: AppCallArgs\n}\n\n/** The result of compiling the approval and clear state TEAL programs for an app */\nexport interface AppCompilationResult {\n /** The compilation result of approval */\n compiledApproval: CompiledTeal\n /** The compilation result of clear */\n compiledClear: CompiledTeal\n}\n\nexport type AppReturn<TReturn> = {\n /** The ABI method call return value */\n return?: TReturn\n}\n\n/** Result from sending a single app transaction. */\nexport type SendAppTransactionResult = Expand<\n SendSingleTransactionResult & {\n /** If an ABI method was called the processed return value */\n return?: ABIReturn\n }\n>\n\n/** Result from sending a single app transaction. */\nexport type SendAppUpdateTransactionResult = Expand<SendAppTransactionResult & Partial<AppCompilationResult>>\n\n/** Result from sending a single app transaction. */\nexport type SendAppCreateTransactionResult = Expand<\n SendAppUpdateTransactionResult & {\n /** The id of the created app */\n appId: bigint\n /** The Algorand address of the account associated with the app */\n appAddress: string\n }\n>\n\n/** Object holding app state values */\nexport interface AppState {\n [key: string]:\n | {\n value: bigint\n keyRaw: Uint8Array\n keyBase64: string\n }\n | {\n value: string\n valueRaw: Uint8Array\n valueBase64: string\n keyRaw: Uint8Array\n keyBase64: string\n }\n}\n\n/**\n * The name of a box storage box */\nexport interface BoxName {\n /** Name in UTF-8 */\n name: string\n /** Name in binary bytes */\n nameRaw: Uint8Array\n /** Name in Base64 */\n nameBase64: string\n}\n\n/**\n * @deprecated Use `types/app-manager/BoxValueRequestParams` instead.\n * Parameters to get and decode a box value as an ABI type.\n */\nexport interface BoxValueRequestParams {\n /** The ID of the app return box names for */\n appId: number | bigint\n /** The name of the box to return either as a string, binary array or `BoxName` */\n boxName: string | Uint8Array | BoxName\n /** The ABI type to decode the value using */\n type: ABIType\n}\n\n/**\n * @deprecated Use `types/app-manager/BoxValuesRequestParams` instead.\n * Parameters to get and decode a box value as an ABI type.\n */\nexport interface BoxValuesRequestParams {\n /** The ID of the app return box names for */\n appId: number\n /** The names of the boxes to return either as a string, binary array or BoxName` */\n boxNames: (string | Uint8Array | BoxName)[]\n /** The ABI type to decode the value using */\n type: ABIType\n}\n"],"names":["OnUpdate","OnSchemaBreak"],"mappings":";;AAsBA;AACO,MAAM,uBAAuB,GAAG,iBAAgB;AAEvD;AACO,MAAM,uBAAuB,GAAG,iBAAgB;AAEvD;AACO,MAAM,oBAAoB,GAAG,mBAAkB;AAEtD;AACO,MAAM,iBAAiB,GAAG,KAAI;AAErC;AACa,MAAA,iBAAiB,GAAG,IAAI,UAAU,CAAC,CAAC,EAAE,EAAE,EAAE,EAAE,GAAG,EAAE,GAAG,CAAC,EAAC;AA4PnE;AACYA,0BASX;AATD,CAAA,UAAY,QAAQ,EAAA;;AAElB,IAAA,QAAA,CAAA,QAAA,CAAA,MAAA,CAAA,GAAA,CAAA,CAAA,GAAA,MAAI,CAAA;;AAEJ,IAAA,QAAA,CAAA,QAAA,CAAA,WAAA,CAAA,GAAA,CAAA,CAAA,GAAA,WAAS,CAAA;;AAET,IAAA,QAAA,CAAA,QAAA,CAAA,YAAA,CAAA,GAAA,C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,CAAA,CAAA,GAAA,YAAU,CAAA;;AAEV,IAAA,QAAA,CAAA,QAAA,CAAA,WAAA,CAAA,GAAA,CAAA,CAAA,GAAA,WAAS,CAAA;AACX,CAAC,EATW,QAAQ,KAAR,QAAQ,GASnB,EAAA,CAAA,CAAA,CAAA;AAED;IACY,cAOX;AAPD,CAAA,UAAY,aAAa,EAAA;;AAEvB,IAAA,aAAA,CAAA,aAAA,CAAA,MAAA,CAAA,GAAA,CAAA,CAAA,GAAA,MAAI,CAAA;;AAEJ,IAAA,aAAA,CAAA,aAAA,CAAA,YAAA,CAAA,GAAA,CAAA,CAAA,GAAA,YAAU,CAAA;;AAEV,IAAA,aAAA,CAAA,aAAA,CAAA,WAAA,CAAA,GAAA,CAAA,CAAA,GAAA,WAAS,CAAA;AACX,CAAC,EAPW,aAAa,KAAb,aAAa,GAOxB,EAAA,CAAA,CAAA;;;;"}
|
|
1
|
+
{"version":3,"file":"app.mjs","sources":["../../src/types/app.ts"],"sourcesContent":["import algosdk from 'algosdk'\nimport { Expand } from './expand'\nimport {\n SendSingleTransactionResult,\n SendTransactionFrom,\n SendTransactionParams,\n SendTransactionResult,\n SendTransactionResults,\n TransactionNote,\n TransactionToSign,\n} from './transaction'\nimport ABIArgument = algosdk.ABIArgument\nimport ABIMethod = algosdk.ABIMethod\nimport ABIMethodParams = algosdk.ABIMethodParams\nimport ABIType = algosdk.ABIType\nimport ABIValue = algosdk.ABIValue\nimport Address = algosdk.Address\nimport OnApplicationComplete = algosdk.OnApplicationComplete\nimport SourceMap = algosdk.SourceMap\nimport SuggestedParams = algosdk.SuggestedParams\nimport Transaction = algosdk.Transaction\n\n/** The name of the TEAL template variable for deploy-time immutability control */\nexport const UPDATABLE_TEMPLATE_NAME = 'TMPL_UPDATABLE'\n\n/** The name of the TEAL template variable for deploy-time permanence control */\nexport const DELETABLE_TEMPLATE_NAME = 'TMPL_DELETABLE'\n\n/** The app create/update [ARC-2](https://github.com/algorandfoundation/ARCs/blob/main/ARCs/arc-0002.md) transaction note prefix */\nexport const APP_DEPLOY_NOTE_DAPP = 'ALGOKIT_DEPLOYER'\n\n/** The maximum number of bytes in a single app code page */\nexport const APP_PAGE_MAX_SIZE = 2048\n\n/** First 4 bytes of SHA-512/256 hash of \"return\" for retrieving ABI return values */\nexport const ABI_RETURN_PREFIX = new Uint8Array([21, 31, 124, 117])\n\n/** Information about an Algorand app */\nexport interface AppReference {\n /** The id of the app */\n appId: number | bigint\n /** The Algorand address of the account associated with the app */\n appAddress: string\n}\n\n/**\n * @deprecated Use `types/app-manager/BoxReference` instead.\n *\n * A grouping of the app ID and name of the box in an Uint8Array\n */\nexport interface BoxReference {\n /**\n * A unique application id\n */\n appId: number | bigint\n /**\n * Name of box to reference\n */\n name: BoxIdentifier\n}\n\n/**\n * @deprecated Use `types/app-manager/BoxIdentifier` instead.\n *\n * Something that identifies a box name - either a:\n * * `Uint8Array`\n * * `string` (that will be encoded to a Uint8Array)\n * * `SendTransactionFrom` (encoded into the public key address of the corresponding account)\n */\nexport type BoxIdentifier = string | Uint8Array | SendTransactionFrom\n\n/** Common app call arguments for ABI and non-ABI (raw) calls */\nexport interface CoreAppCallArgs {\n /** The optional lease for the transaction */\n lease?: string | Uint8Array\n /** Any box references to load */\n boxes?: (algosdk.BoxReference | BoxReference | BoxIdentifier)[]\n /** The address of any accounts to load in */\n accounts?: (string | Address)[]\n /** IDs of any apps to load into the foreignApps array */\n apps?: number[]\n /** IDs of any assets to load into the foreignAssets array */\n assets?: number[]\n /** Optional account / account address that should be authorised to transact on behalf of the from account the app call is sent from after this transaction.\n *\n * **Note:** Use with extreme caution and review the [official rekey guidance](https://developer.algorand.org/docs/get-details/accounts/rekey/) first.\n */\n rekeyTo?: SendTransactionFrom | string\n}\n\n/**\n * App call args with non-ABI (raw) values (minus some processing like encoding strings as binary)\n */\nexport interface RawAppCallArgs extends CoreAppCallArgs {\n /** Any application arguments to pass through */\n appArgs?: (Uint8Array | string)[]\n /** Property to aid intellisense */\n method?: undefined\n}\n\n/** An argument for an ABI method, either a primitive value, or a transaction with or without signer, or the unawaited async return value of an algokit method that returns a `SendTransactionResult` */\nexport type ABIAppCallArg =\n | ABIArgument\n | TransactionToSign\n | Transaction\n | Promise<SendTransactionResult>\n | SendTransactionResult\n | undefined\n\n/**\n * App call args for an ABI call\n */\nexport type ABIAppCallArgs = CoreAppCallArgs & {\n /** The ABI method to call */\n method: ABIMethodParams | ABIMethod\n /** The ABI method args to pass in */\n methodArgs: ABIAppCallArg[]\n}\n\n/** Arguments to pass to an app call either:\n * * The raw app call values to pass through into the transaction (after processing); or\n * * An ABI method definition (method and args)\n **/\nexport type AppCallArgs = RawAppCallArgs | ABIAppCallArgs\n\n/**\n * @deprecated Use `TransactionComposer` to construct create app transactions instead.\n *\n * Base interface for common data passed to an app create or update.\n */\ninterface CreateOrUpdateAppParams extends SendTransactionParams {\n /** The account (with private key loaded) that will send the transaction */\n from: SendTransactionFrom\n /** The approval program as raw teal (string) or compiled teal, base 64 encoded as a byte array (Uint8Array) */\n approvalProgram: Uint8Array | string\n /** The clear state program as raw teal (string) or compiled teal, base 64 encoded as a byte array (Uint8Array) */\n clearStateProgram: Uint8Array | string\n /** Optional transaction parameters */\n transactionParams?: SuggestedParams\n /** The (optional) transaction note */\n note?: TransactionNote\n /** The arguments passed in to the app call */\n args?: AppCallArgs\n}\n\n/**\n * @deprecated Use `TransactionComposer` to construct create app transactions instead.\n *\n * Parameters that are passed in when creating an app. */\nexport interface CreateAppParams extends CreateOrUpdateAppParams {\n /** The storage schema to request for the created app */\n schema: AppStorageSchema\n /** Override the on-completion action for the create call; defaults to NoOp */\n onCompleteAction?: Exclude<AppCallType, 'clear_state'> | Exclude<OnApplicationComplete, OnApplicationComplete.ClearStateOC>\n}\n\n/**\n * @deprecated Use `TransactionComposer` to construct update app transactions instead.\n *\n * Parameters that are passed in when updating an app. */\nexport interface UpdateAppParams extends CreateOrUpdateAppParams {\n /** The id of the app to update */\n appId: number | bigint\n}\n\n/**\n * @deprecated Use `algosdk.OnApplicationComplete` directly instead.\n *\n * The type of call / [on-completion action](https://developer.algorand.org/docs/get-details/dapps/smart-contracts/apps/#the-lifecycle-of-a-smart-contract) for a smart contract call.\n *\n * Equivalent of `algosdk.OnApplicationComplete`, but as a more convenient string enum.\n *\n * * `no_op`: Normal smart contract call, no special on-complete action\n * * `opt_in`: Opt-in to smart contract local storage\n * * `close_out`: Close-out local storage storage\n * * `clear_state`: Clear local storage state\n * * `update_application`: Update the smart contract\n * * `delete_application`: Delete the smart contract\n */\nexport type AppCallType = 'no_op' | 'opt_in' | 'close_out' | 'clear_state' | 'update_application' | 'delete_application'\n\n/** Parameters representing a call to an app. */\nexport interface AppCallParams extends SendTransactionParams {\n /** The id of the app to call */\n appId: number | bigint\n /** The type of call, everything except create (see `createApp`) and update (see `updateApp`) */\n callType: Exclude<AppCallType, 'update_application'> | Exclude<OnApplicationComplete, OnApplicationComplete.UpdateApplicationOC>\n /** The account to make the call from */\n from: SendTransactionFrom\n /** Optional transaction parameters */\n transactionParams?: SuggestedParams\n /** The (optional) transaction note */\n note?: TransactionNote\n /** The arguments passed in to the app call */\n args?: AppCallArgs\n}\n\n/** Parameters representing the storage schema of an app. */\nexport interface AppStorageSchema {\n /** Restricts number of ints in per-user local state */\n localInts: number\n /** Restricts number of byte slices in per-user local state */\n localByteSlices: number\n /** Restricts number of ints in global state */\n globalInts: number\n /** Restricts number of byte slices in global state */\n globalByteSlices: number\n /** Any extra pages that are needed for the smart contract; if left blank then the right number of pages will be calculated based on the teal code size */\n extraPages?: number\n}\n\n/** Information about a compiled teal program */\nexport interface CompiledTeal {\n /** Original TEAL code */\n teal: string\n /** The compiled code */\n compiled: string\n /** The hash returned by the compiler */\n compiledHash: string\n /** The base64 encoded code as a byte array */\n compiledBase64ToBytes: Uint8Array\n /** Source map from the compilation */\n sourceMap: SourceMap\n}\n\nexport interface AppCallTransactionResultOfType<T> extends SendTransactionResults, SendTransactionResult {\n /** If an ABI method was called the processed return value */\n return?: T\n}\n\n/** Result from calling an app */\n// eslint-disable-next-line @typescript-eslint/no-empty-interface\nexport interface AppCallTransactionResult extends AppCallTransactionResultOfType<ABIReturn> {}\n\n/** The return value of an ABI method call */\nexport type ABIReturn =\n | {\n rawReturnValue: Uint8Array\n returnValue: ABIValue\n method: ABIMethod\n decodeError: undefined\n }\n | { rawReturnValue?: undefined; returnValue?: undefined; method?: undefined; decodeError: Error }\n\n/**\n * The payload of the metadata to add to the transaction note when deploying an app, noting it will be prefixed with `APP_DEPLOY_NOTE_PREFIX`.\n */\nexport interface AppDeployMetadata {\n /** The unique name identifier of the app within the creator account */\n name: string\n /** The version of app that is / will be deployed */\n version: string\n /** Whether or not the app is deletable / permanent / unspecified */\n deletable?: boolean\n /** Whether or not the app is updatable / immutable / unspecified */\n updatable?: boolean\n}\n\n/** The metadata that can be collected about a deployed app */\nexport interface AppMetadata extends AppReference, AppDeployMetadata {\n /** The round the app was created */\n createdRound: number\n /** The last round that the app was updated */\n updatedRound: number\n /** The metadata when the app was created */\n createdMetadata: AppDeployMetadata\n /** Whether or not the app is deleted */\n deleted: boolean\n}\n\n/** A lookup of name -> Algorand app for a creator */\nexport interface AppLookup {\n creator: Readonly<string>\n apps: Readonly<{\n [name: string]: AppMetadata\n }>\n}\n\n/** Dictionary of deploy-time parameters to replace in a teal template.\n *\n * Note: Looks for `TMPL_{parameter}` for template replacements i.e. you can leave out the `TMPL_`.\n *\n */\nexport interface TealTemplateParams {\n [key: string]: string | bigint | number | Uint8Array\n}\n\n/** What action to perform when deploying an app and an update is detected in the TEAL code */\nexport enum OnUpdate {\n /** Fail the deployment */\n Fail,\n /** Update the app */\n UpdateApp,\n /** Delete the app and create a new one in its place */\n ReplaceApp,\n /** Create a new app */\n AppendApp,\n}\n\n/** What action to perform when deploying an app and a breaking schema change is detected */\nexport enum OnSchemaBreak {\n /** Fail the deployment */\n Fail,\n /** Delete the app and create a new one in its place */\n ReplaceApp,\n /** Create a new app */\n AppendApp,\n}\n\n/** The parameters to deploy an app */\nexport interface AppDeploymentParams\n extends Omit<CreateAppParams, 'onCompleteAction' | 'args' | 'note' | 'skipSending' | 'skipWaiting' | 'atc'> {\n /** The deployment metadata */\n metadata: AppDeployMetadata\n /** Any deploy-time parameters to replace in the TEAL code */\n deployTimeParams?: TealTemplateParams\n /** What action to perform if a schema break is detected */\n onSchemaBreak?: 'replace' | 'fail' | 'append' | OnSchemaBreak\n /** What action to perform if a TEAL update is detected */\n onUpdate?: 'update' | 'replace' | 'fail' | 'append' | OnUpdate\n /** Optional cached value of the existing apps for the given creator */\n existingDeployments?: AppLookup\n /** Any args to pass to any create transaction that is issued as part of deployment */\n createArgs?: AppCallArgs\n /** Override the on-completion action for the create call; defaults to NoOp */\n createOnCompleteAction?: Exclude<AppCallType, 'clear_state'> | Exclude<OnApplicationComplete, OnApplicationComplete.ClearStateOC>\n /** Any args to pass to any update transaction that is issued as part of deployment */\n updateArgs?: AppCallArgs\n /** Any args to pass to any delete transaction that is issued as part of deployment */\n deleteArgs?: AppCallArgs\n}\n\n/** The result of compiling the approval and clear state TEAL programs for an app */\nexport interface AppCompilationResult {\n /** The compilation result of approval */\n compiledApproval: CompiledTeal\n /** The compilation result of clear */\n compiledClear: CompiledTeal\n}\n\nexport type AppReturn<TReturn> = {\n /** The ABI method call return value */\n return?: TReturn\n}\n\n/** Result from sending a single app transaction. */\nexport type SendAppTransactionResult = Expand<\n SendSingleTransactionResult & {\n /** If an ABI method was called the processed return value */\n return?: ABIReturn\n }\n>\n\n/** Result from sending a single app transaction. */\nexport type SendAppUpdateTransactionResult = Expand<SendAppTransactionResult & Partial<AppCompilationResult>>\n\n/** Result from sending a single app transaction. */\nexport type SendAppCreateTransactionResult = Expand<\n SendAppUpdateTransactionResult & {\n /** The id of the created app */\n appId: bigint\n /** The Algorand address of the account associated with the app */\n appAddress: string\n }\n>\n\n/** Object holding app state values */\nexport interface AppState {\n [key: string]:\n | {\n value: bigint\n keyRaw: Uint8Array\n keyBase64: string\n }\n | {\n value: string\n valueRaw: Uint8Array\n valueBase64: string\n keyRaw: Uint8Array\n keyBase64: string\n }\n}\n\n/**\n * The name of a box storage box */\nexport interface BoxName {\n /** Name in UTF-8 */\n name: string\n /** Name in binary bytes */\n nameRaw: Uint8Array\n /** Name in Base64 */\n nameBase64: string\n}\n\n/**\n * @deprecated Use `types/app-manager/BoxValueRequestParams` instead.\n * Parameters to get and decode a box value as an ABI type.\n */\nexport interface BoxValueRequestParams {\n /** The ID of the app return box names for */\n appId: number | bigint\n /** The name of the box to return either as a string, binary array or `BoxName` */\n boxName: string | Uint8Array | BoxName\n /** The ABI type to decode the value using */\n type: ABIType\n}\n\n/**\n * @deprecated Use `types/app-manager/BoxValuesRequestParams` instead.\n * Parameters to get and decode a box value as an ABI type.\n */\nexport interface BoxValuesRequestParams {\n /** The ID of the app return box names for */\n appId: number\n /** The names of the boxes to return either as a string, binary array or BoxName` */\n boxNames: (string | Uint8Array | BoxName)[]\n /** The ABI type to decode the value using */\n type: ABIType\n}\n"],"names":[],"mappings":"AAsBA;AACO,MAAM,uBAAuB,GAAG,iBAAgB;AAEvD;AACO,MAAM,uBAAuB,GAAG,iBAAgB;AAEvD;AACO,MAAM,oBAAoB,GAAG,mBAAkB;AAEtD;AACO,MAAM,iBAAiB,GAAG,KAAI;AAErC;AACa,MAAA,iBAAiB,GAAG,IAAI,UAAU,CAAC,CAAC,EAAE,EAAE,EAAE,EAAE,GAAG,EAAE,GAAG,CAAC,EAAC;AA4PnE;IACY,SASX;AATD,CAAA,UAAY,QAAQ,EAAA;;AAElB,IAAA,QAAA,CAAA,QAAA,CAAA,MAAA,CAAA,GAAA,CAAA,CAAA,GAAA,MAAI,CAAA;;AAEJ,IAAA,QAAA,CAAA,QAAA,CAAA,WAAA,CAAA,GAAA,CAAA,CAAA,GAAA,WAAS,CAAA;;AAET,IAAA,QAAA,CAAA,QAAA,CAAA,YAAA,CAAA,GAAA,CAAA,CAAA,GAAA,YAAU,CAAA;;AAEV,IAAA,QAAA,CAAA,QAAA,CAAA,WAAA,CAAA,GAAA,CAAA,CAAA,GAAA,WAAS,CAAA;AACX,CAAC,EATW,QAAQ,KAAR,QAAQ,GASnB,EAAA,CAAA,CAAA,CAAA;AAED;IACY,cAOX;AAPD,CAAA,UAAY,aAAa,EAAA;;AAEvB,IAAA,aAAA,CAAA,aAAA,CAAA,MAAA,CAAA,GAAA,CAAA,CAAA,GAAA,MAAI,CAAA;;AAEJ,IAAA,aAAA,CAAA,aAAA,CAAA,YAAA,CAAA,GAAA,CAAA,CAAA,GAAA,YAAU,CAAA;;AAEV,IAAA,aAAA,CAAA,aAAA,CAAA,WAAA,CAAA,GAAA,CAAA,CAAA,GAAA,WAAS,CAAA;AACX,CAAC,EAPW,aAAa,KAAb,aAAa,GAOxB,EAAA,CAAA,CAAA;;;;"}
|
package/types/asset-manager.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import algosdk from 'algosdk';
|
|
2
2
|
import { AccountAssetInformation, TransactionSignerAccount } from './account';
|
|
3
|
-
import
|
|
3
|
+
import TransactionComposer, { CommonTransactionParams } from './composer';
|
|
4
|
+
import { SendParams } from './transaction';
|
|
4
5
|
/** Individual result from performing a bulk opt-in or bulk opt-out for an account against a series of assets. */
|
|
5
6
|
export interface BulkAssetOptInOutResult {
|
|
6
7
|
/** The ID of the asset opted into / out of */
|
|
@@ -120,13 +121,13 @@ export declare class AssetManager {
|
|
|
120
121
|
/**
|
|
121
122
|
* Create a new asset manager.
|
|
122
123
|
* @param algod An algod client
|
|
123
|
-
* @param newGroup A function that creates a new `
|
|
124
|
+
* @param newGroup A function that creates a new `TransactionComposer` transaction group
|
|
124
125
|
* @example Create a new asset manager
|
|
125
126
|
* ```typescript
|
|
126
|
-
* const assetManager = new AssetManager(algod, () => new
|
|
127
|
+
* const assetManager = new AssetManager(algod, () => new TransactionComposer({algod, () => signer, () => suggestedParams}))
|
|
127
128
|
* ```
|
|
128
129
|
*/
|
|
129
|
-
constructor(algod: algosdk.Algodv2, newGroup: () =>
|
|
130
|
+
constructor(algod: algosdk.Algodv2, newGroup: () => TransactionComposer);
|
|
130
131
|
/**
|
|
131
132
|
* Returns the current asset information for the asset with the given ID.
|
|
132
133
|
*
|
|
@@ -172,7 +173,7 @@ export declare class AssetManager {
|
|
|
172
173
|
* ```
|
|
173
174
|
* @returns An array of records matching asset ID to transaction ID of the opt in
|
|
174
175
|
*/
|
|
175
|
-
bulkOptIn(account: string | TransactionSignerAccount, assetIds: bigint[], options?: Omit<CommonTransactionParams, 'sender'> &
|
|
176
|
+
bulkOptIn(account: string | TransactionSignerAccount, assetIds: bigint[], options?: Omit<CommonTransactionParams, 'sender'> & SendParams): Promise<BulkAssetOptInOutResult[]>;
|
|
176
177
|
/**
|
|
177
178
|
* Opt an account out of a list of Algorand Standard Assets.
|
|
178
179
|
*
|
|
@@ -190,7 +191,7 @@ export declare class AssetManager {
|
|
|
190
191
|
* ```
|
|
191
192
|
* @returns An array of records matching asset ID to transaction ID of the opt in
|
|
192
193
|
*/
|
|
193
|
-
bulkOptOut(account: string | TransactionSignerAccount, assetIds: bigint[], options?: Omit<CommonTransactionParams, 'sender'> &
|
|
194
|
+
bulkOptOut(account: string | TransactionSignerAccount, assetIds: bigint[], options?: Omit<CommonTransactionParams, 'sender'> & SendParams & {
|
|
194
195
|
/** Whether or not to check if the account has a zero balance for each asset first or not.
|
|
195
196
|
*
|
|
196
197
|
* Defaults to `true`.
|
|
@@ -202,4 +203,3 @@ export declare class AssetManager {
|
|
|
202
203
|
ensureZeroBalance?: boolean;
|
|
203
204
|
}): Promise<BulkAssetOptInOutResult[]>;
|
|
204
205
|
}
|
|
205
|
-
//# sourceMappingURL=asset-manager.d.ts.map
|
package/types/asset-manager.js
CHANGED
|
@@ -11,10 +11,10 @@ class AssetManager {
|
|
|
11
11
|
/**
|
|
12
12
|
* Create a new asset manager.
|
|
13
13
|
* @param algod An algod client
|
|
14
|
-
* @param newGroup A function that creates a new `
|
|
14
|
+
* @param newGroup A function that creates a new `TransactionComposer` transaction group
|
|
15
15
|
* @example Create a new asset manager
|
|
16
16
|
* ```typescript
|
|
17
|
-
* const assetManager = new AssetManager(algod, () => new
|
|
17
|
+
* const assetManager = new AssetManager(algod, () => new TransactionComposer({algod, () => signer, () => suggestedParams}))
|
|
18
18
|
* ```
|
|
19
19
|
*/
|
|
20
20
|
constructor(algod, newGroup) {
|
|
@@ -105,7 +105,7 @@ class AssetManager {
|
|
|
105
105
|
assetId: BigInt(assetId),
|
|
106
106
|
});
|
|
107
107
|
}
|
|
108
|
-
const result = await composer.
|
|
108
|
+
const result = await composer.send(options);
|
|
109
109
|
config.Config.getLogger(options?.suppressLog).info(`Successfully opted in ${account} for assets ${assetGroup.join(', ')} with transaction IDs ${result.txIds.join(', ')}` +
|
|
110
110
|
`\n Grouped under ${result.groupId} in round ${result.confirmations?.[0]?.confirmedRound}.`);
|
|
111
111
|
assetGroup.forEach((assetId, index) => {
|
|
@@ -133,7 +133,6 @@ class AssetManager {
|
|
|
133
133
|
*/
|
|
134
134
|
async bulkOptOut(account, assetIds, options) {
|
|
135
135
|
const results = [];
|
|
136
|
-
await this._algod.getTransactionParams().do();
|
|
137
136
|
const sender = typeof account === 'string' ? account : account.addr;
|
|
138
137
|
for (const assetGroup of util.chunkArray(assetIds, types_composer.MAX_TRANSACTION_GROUP_SIZE)) {
|
|
139
138
|
const composer = this._newGroup();
|
|
@@ -147,7 +146,7 @@ class AssetManager {
|
|
|
147
146
|
nonZeroBalanceAssetIds.push(BigInt(assetId));
|
|
148
147
|
}
|
|
149
148
|
}
|
|
150
|
-
catch
|
|
149
|
+
catch {
|
|
151
150
|
notOptedInAssetIds.push(BigInt(assetId));
|
|
152
151
|
}
|
|
153
152
|
}
|
|
@@ -165,7 +164,7 @@ class AssetManager {
|
|
|
165
164
|
assetId: BigInt(assetId),
|
|
166
165
|
});
|
|
167
166
|
}
|
|
168
|
-
const result = await composer.
|
|
167
|
+
const result = await composer.send(options);
|
|
169
168
|
config.Config.getLogger(options?.suppressLog).info(`Successfully opted ${account} out of assets ${assetGroup.join(', ')} with transaction IDs ${result.txIds.join(', ')}` +
|
|
170
169
|
`\n Grouped under ${result.groupId} in round ${result.confirmations?.[0]?.confirmedRound}.`);
|
|
171
170
|
assetGroup.forEach((assetId, index) => {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"asset-manager.js","sources":["../../src/types/asset-manager.ts"],"sourcesContent":[null],"names":["chunkArray","MAX_TRANSACTION_GROUP_SIZE","Config"],"mappings":";;;;;;;AAKA,IAAO,UAAU,GAAG,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAA;AAmI1C;MACa,YAAY,CAAA;AAIvB;;;;;;;;AAQG;IACH,WAAY,CAAA,KAAsB,EAAE,QAA+B,EAAA;AACjE,QAAA,IAAI,CAAC,MAAM,GAAG,KAAK,CAAA;AACnB,QAAA,IAAI,CAAC,SAAS,GAAG,QAAQ,CAAA;KAC1B;AAED;;;;;;;;;;AAUG;IACI,MAAM,OAAO,CAAC,OAAe,EAAA;QAClC,MAAM,KAAK,GAAG,UAAU,CAAC,qBAAqB,CAAC,MAAM,IAAI,CAAC,MAAM,CAAC,YAAY,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAA;QAEpG,OAAO;AACL,YAAA,OAAO,EAAE,MAAM,CAAC,KAAK,CAAC,KAAK,CAAC;YAC5B,KAAK,EAAE,MAAM,CAAC,KAAK,CAAC,MAAM,CAAC,KAAK,CAAC;YACjC,QAAQ,EAAE,MAAM,CAAC,KAAK,CAAC,MAAM,CAAC,QAAQ,CAAC;AACvC,YAAA,SAAS,EAAE,KAAK,CAAC,MAAM,CAAC,IAAI;AAC5B,YAAA,gBAAgB,EAAE,KAAK,CAAC,MAAM,CAAC,OAAO;AACtC,YAAA,QAAQ,EAAE,KAAK,CAAC,MAAM,CAAC,QAAQ;AAC/B,YAAA,eAAe,EAAE,KAAK,CAAC,MAAM,CAAC,WAAW;AACzC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AC,CAAA;SACH;AAED,QAAA,OAAO,OAAO,CAAA;KACf;AACF;;;;"}
|
|
1
|
+
{"version":3,"file":"asset-manager.js","sources":["../../src/types/asset-manager.ts"],"sourcesContent":["import algosdk from 'algosdk'\nimport { Config } from '../config'\nimport { chunkArray } from '../util'\nimport { AccountAssetInformation, TransactionSignerAccount } from './account'\nimport TransactionComposer, { CommonTransactionParams, MAX_TRANSACTION_GROUP_SIZE } from './composer'\nimport { SendParams } from './transaction'\nimport AssetModel = algosdk.modelsv2.Asset\n\n/** Individual result from performing a bulk opt-in or bulk opt-out for an account against a series of assets. */\nexport interface BulkAssetOptInOutResult {\n /** The ID of the asset opted into / out of */\n assetId: bigint\n /** The transaction ID of the resulting opt in / out */\n transactionId: string\n}\n\n/** Information about an asset. */\nexport interface AssetInformation {\n /** The ID of the asset. */\n assetId: bigint\n\n /** The address of the account that created the asset.\n *\n * This is the address where the parameters for this asset can be found,\n * and also the address where unwanted asset units can be sent when\n * closing out an asset position and opting-out of the asset.\n */\n creator: string\n\n /** The total amount of the smallest divisible (decimal) units that were created of the asset.\n *\n * For example, if `decimals` is, say, 2, then for every 100 `total` there is 1 whole unit.\n */\n total: bigint\n\n /** The amount of decimal places the asset was created with.\n *\n * * If 0, the asset is not divisible;\n * * If 1, the base unit of the asset is in tenths;\n * * If 2, the base unit of the asset is in hundredths;\n * * If 3, the base unit of the asset is in thousandths;\n * * and so on up to 19 decimal places.\n */\n decimals: number\n\n /** Whether the asset was frozen by default for all accounts.\n *\n * If `true` then for anyone apart from the creator to hold the\n * asset it needs to be unfrozen per account using an asset freeze\n * transaction from the `freeze` account.\n */\n defaultFrozen?: boolean\n\n /** The address of the optional account that can manage the configuration of the asset and destroy it.\n *\n * If not set the asset is permanently immutable.\n */\n manager?: string\n\n /**\n * The address of the optional account that holds the reserve (uncirculated supply) units of the asset.\n *\n * This address has no specific authority in the protocol itself and is informational only.\n *\n * Some standards like [ARC-19](https://github.com/algorandfoundation/ARCs/blob/main/ARCs/arc-0019.md)\n * rely on this field to hold meaningful data.\n *\n * It can be used in the case where you want to signal to holders of your asset that the uncirculated units\n * of the asset reside in an account that is different from the default creator account.\n *\n * If not set the field is permanently empty.\n */\n reserve?: string\n\n /**\n * The address of the optional account that can be used to freeze or unfreeze holdings of this asset for any account.\n *\n * If empty, freezing is not permitted.\n *\n * If not set the field is permanently empty.\n */\n freeze?: string\n\n /**\n * The address of the optional account that can clawback holdings of this asset from any account.\n *\n * The clawback account has the ability to **unconditionally take assets from any account**.\n *\n * If empty, clawback is not permitted.\n *\n * If not set the field is permanently empty.\n */\n clawback?: string\n\n /** The optional name of the unit of this asset (e.g. ticker name).\n *\n * Max size is 8 bytes.\n */\n unitName?: string\n\n /** The optional name of the unit of this asset (e.g. ticker name).\n *\n * Max size is 8 bytes.\n */\n unitNameAsBytes?: Uint8Array\n\n /** The optional name of the asset.\n *\n * Max size is 32 bytes.\n */\n assetName?: string\n\n /** The optional name of the asset.\n *\n * Max size is 32 bytes.\n */\n assetNameAsBytes?: Uint8Array\n\n /** Optional URL where more information about the asset can be retrieved (e.g. metadata).\n *\n * Max size is 96 bytes.\n */\n url?: string\n\n /** Optional URL where more information about the asset can be retrieved (e.g. metadata).\n *\n * Max size is 96 bytes.\n */\n urlAsBytes?: Uint8Array\n\n /** 32-byte hash of some metadata that is relevant to the asset and/or asset holders.\n *\n * The format of this metadata is up to the application.\n */\n metadataHash?: Uint8Array\n}\n\n/** Allows management of asset information. */\nexport class AssetManager {\n private _algod: algosdk.Algodv2\n private _newGroup: () => TransactionComposer\n\n /**\n * Create a new asset manager.\n * @param algod An algod client\n * @param newGroup A function that creates a new `TransactionComposer` transaction group\n * @example Create a new asset manager\n * ```typescript\n * const assetManager = new AssetManager(algod, () => new TransactionComposer({algod, () => signer, () => suggestedParams}))\n * ```\n */\n constructor(algod: algosdk.Algodv2, newGroup: () => TransactionComposer) {\n this._algod = algod\n this._newGroup = newGroup\n }\n\n /**\n * Returns the current asset information for the asset with the given ID.\n *\n * @example\n * ```typescript\n * const assetInfo = await assetManager.getById(12353n);\n * ```\n *\n * @param assetId The ID of the asset\n * @returns The asset information\n */\n public async getById(assetId: bigint): Promise<AssetInformation> {\n const asset = AssetModel.from_obj_for_encoding(await this._algod.getAssetByID(Number(assetId)).do())\n\n return {\n assetId: BigInt(asset.index),\n total: BigInt(asset.params.total),\n decimals: Number(asset.params.decimals),\n assetName: asset.params.name,\n assetNameAsBytes: asset.params.nameB64,\n unitName: asset.params.unitName,\n unitNameAsBytes: asset.params.unitNameB64,\n url: asset.params.url,\n urlAsBytes: asset.params.urlB64,\n creator: asset.params.creator,\n manager: asset.params.manager,\n clawback: asset.params.clawback,\n freeze: asset.params.freeze,\n reserve: asset.params.reserve,\n defaultFrozen: asset.params.defaultFrozen,\n metadataHash: asset.params.metadataHash,\n }\n }\n\n /**\n * Returns the given sender account's asset holding for a given asset.\n *\n * @example\n * ```typescript\n * const address = \"XBYLS2E6YI6XXL5BWCAMOA4GTWHXWENZMX5UHXMRNWWUQ7BXCY5WC5TEPA\";\n * const assetId = 123345n;\n * const accountInfo = await algorand.asset.getAccountInformation(address, assetId);\n * ```\n *\n * [Response data schema details](https://developer.algorand.org/docs/rest-apis/algod/#get-v2accountsaddressassetsasset-id)\n * @param sender The address of the sender/account to look up\n * @param assetId The ID of the asset to return a holding for\n * @returns The account asset holding information\n */\n public async getAccountInformation(sender: string | TransactionSignerAccount, assetId: bigint): Promise<AccountAssetInformation> {\n const info = await this._algod.accountAssetInformation(typeof sender === 'string' ? sender : sender.addr, Number(assetId)).do()\n\n return {\n assetId: BigInt(assetId),\n balance: BigInt(info['asset-holding']['amount']),\n frozen: info['asset-holding']['is-frozen'] === true,\n round: BigInt(info['round']),\n }\n }\n\n /**\n * Opt an account in to a list of Algorand Standard Assets.\n *\n * Transactions will be sent in batches of 16 as transaction groups.\n *\n * @param account The account to opt-in\n * @param assetIds The list of asset IDs to opt-in to\n * @param options Any parameters to control the transaction or execution of the transaction\n * @example Example using AlgorandClient\n * ```typescript\n * // Basic example\n * algorand.asset.bulkOptIn(\"ACCOUNTADDRESS\", [12345n, 67890n])\n * // With configuration\n * algorand.asset.bulkOptIn(\"ACCOUNTADDRESS\", [12345n, 67890n], { maxFee: (1000).microAlgo(), suppressLog: true })\n * ```\n * @returns An array of records matching asset ID to transaction ID of the opt in\n */\n async bulkOptIn(\n account: string | TransactionSignerAccount,\n assetIds: bigint[],\n options?: Omit<CommonTransactionParams, 'sender'> & SendParams,\n ): Promise<BulkAssetOptInOutResult[]> {\n const results: BulkAssetOptInOutResult[] = []\n\n for (const assetGroup of chunkArray(assetIds, MAX_TRANSACTION_GROUP_SIZE)) {\n const composer = this._newGroup()\n\n for (const assetId of assetGroup) {\n composer.addAssetOptIn({\n ...options,\n sender: typeof account === 'string' ? account : account.addr,\n assetId: BigInt(assetId),\n })\n }\n\n const result = await composer.send(options)\n\n Config.getLogger(options?.suppressLog).info(\n `Successfully opted in ${account} for assets ${assetGroup.join(', ')} with transaction IDs ${result.txIds.join(', ')}` +\n `\\n Grouped under ${result.groupId} in round ${result.confirmations?.[0]?.confirmedRound}.`,\n )\n\n assetGroup.forEach((assetId, index) => {\n results.push({ assetId: BigInt(assetId), transactionId: result.txIds[index] })\n })\n }\n\n return results\n }\n\n /**\n * Opt an account out of a list of Algorand Standard Assets.\n *\n * Transactions will be sent in batches of 16 as transaction groups.\n *\n * @param account The account to opt-in\n * @param assetIds The list of asset IDs to opt-out of\n * @param options Any parameters to control the transaction or execution of the transaction\n * @example Example using AlgorandClient\n * ```typescript\n * // Basic example\n * algorand.asset.bulkOptOut(\"ACCOUNTADDRESS\", [12345n, 67890n])\n * // With configuration\n * algorand.asset.bulkOptOut(\"ACCOUNTADDRESS\", [12345n, 67890n], { ensureZeroBalance: true, maxFee: (1000).microAlgo(), suppressLog: true })\n * ```\n * @returns An array of records matching asset ID to transaction ID of the opt in\n */\n async bulkOptOut(\n account: string | TransactionSignerAccount,\n assetIds: bigint[],\n options?: Omit<CommonTransactionParams, 'sender'> &\n SendParams & {\n /** Whether or not to check if the account has a zero balance for each asset first or not.\n *\n * Defaults to `true`.\n *\n * If this is set to `true` and the account has an asset balance it will throw an error.\n *\n * If this is set to `false` and the account has an asset balance it will lose those assets to the asset creator.\n */\n ensureZeroBalance?: boolean\n },\n ): Promise<BulkAssetOptInOutResult[]> {\n const results: BulkAssetOptInOutResult[] = []\n\n const sender = typeof account === 'string' ? account : account.addr\n\n for (const assetGroup of chunkArray(assetIds, MAX_TRANSACTION_GROUP_SIZE)) {\n const composer = this._newGroup()\n\n const notOptedInAssetIds: bigint[] = []\n const nonZeroBalanceAssetIds: bigint[] = []\n for (const assetId of assetGroup) {\n if (options?.ensureZeroBalance !== false) {\n try {\n const accountAssetInfo = await this.getAccountInformation(sender, assetId)\n if (accountAssetInfo.balance !== 0n) {\n nonZeroBalanceAssetIds.push(BigInt(assetId))\n }\n } catch {\n notOptedInAssetIds.push(BigInt(assetId))\n }\n }\n }\n\n if (notOptedInAssetIds.length > 0 || nonZeroBalanceAssetIds.length > 0) {\n throw new Error(\n `Account ${sender}${notOptedInAssetIds.length > 0 ? ` is not opted-in to Asset${notOptedInAssetIds.length > 1 ? 's' : ''} ${notOptedInAssetIds.join(', ')}` : ''}${\n nonZeroBalanceAssetIds.length > 0\n ? ` has non-zero balance for Asset${nonZeroBalanceAssetIds.length > 1 ? 's' : ''} ${nonZeroBalanceAssetIds.join(', ')}`\n : ''\n }; can't opt-out.`,\n )\n }\n\n for (const assetId of assetGroup) {\n composer.addAssetOptOut({\n ...options,\n creator: (await this.getById(BigInt(assetId))).creator,\n sender,\n assetId: BigInt(assetId),\n })\n }\n\n const result = await composer.send(options)\n\n Config.getLogger(options?.suppressLog).info(\n `Successfully opted ${account} out of assets ${assetGroup.join(', ')} with transaction IDs ${result.txIds.join(', ')}` +\n `\\n Grouped under ${result.groupId} in round ${result.confirmations?.[0]?.confirmedRound}.`,\n )\n\n assetGroup.forEach((assetId, index) => {\n results.push({ assetId: BigInt(assetId), transact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AAC,cAAc,CAAC;AACtB,oBAAA,GAAG,OAAO;AACV,oBAAA,OAAO,EAAE,CAAC,MAAM,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,EAAE,OAAO;oBACtD,MAAM;AACN,oBAAA,OAAO,EAAE,MAAM,CAAC,OAAO,CAAC;AACzB,iBAAA,CAAC,CAAA;aACH;YAED,MAAM,MAAM,GAAG,MAAM,QAAQ,CAAC,IAAI,CAAC,OAAO,CAAC,CAAA;AAE3C,YAAAC,aAAM,CAAC,SAAS,CAAC,OAAO,EAAE,WAAW,CAAC,CAAC,IAAI,CACzC,CAAsB,mBAAA,EAAA,OAAO,CAAkB,eAAA,EAAA,UAAU,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA,sBAAA,EAAyB,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAE,CAAA;AACpH,gBAAA,CAAA,kBAAA,EAAqB,MAAM,CAAC,OAAO,CAAA,UAAA,EAAa,MAAM,CAAC,aAAa,GAAG,CAAC,CAAC,EAAE,cAAc,CAAA,CAAA,CAAG,CAC/F,CAAA;YAED,UAAU,CAAC,OAAO,CAAC,CAAC,OAAO,EAAE,KAAK,KAAI;gBACpC,OAAO,CAAC,IAAI,CAAC,EAAE,OAAO,EAAE,MAAM,CAAC,OAAO,CAAC,EAAE,aAAa,EAAE,MAAM,CAAC,KAAK,CAAC,KAAK,CAAC,EAAE,CAAC,CAAA;AAChF,aAAC,CAAC,CAAA;SACH;AAED,QAAA,OAAO,OAAO,CAAA;KACf;AACF;;;;"}
|
package/types/asset-manager.mjs
CHANGED
|
@@ -9,10 +9,10 @@ class AssetManager {
|
|
|
9
9
|
/**
|
|
10
10
|
* Create a new asset manager.
|
|
11
11
|
* @param algod An algod client
|
|
12
|
-
* @param newGroup A function that creates a new `
|
|
12
|
+
* @param newGroup A function that creates a new `TransactionComposer` transaction group
|
|
13
13
|
* @example Create a new asset manager
|
|
14
14
|
* ```typescript
|
|
15
|
-
* const assetManager = new AssetManager(algod, () => new
|
|
15
|
+
* const assetManager = new AssetManager(algod, () => new TransactionComposer({algod, () => signer, () => suggestedParams}))
|
|
16
16
|
* ```
|
|
17
17
|
*/
|
|
18
18
|
constructor(algod, newGroup) {
|
|
@@ -103,7 +103,7 @@ class AssetManager {
|
|
|
103
103
|
assetId: BigInt(assetId),
|
|
104
104
|
});
|
|
105
105
|
}
|
|
106
|
-
const result = await composer.
|
|
106
|
+
const result = await composer.send(options);
|
|
107
107
|
Config.getLogger(options?.suppressLog).info(`Successfully opted in ${account} for assets ${assetGroup.join(', ')} with transaction IDs ${result.txIds.join(', ')}` +
|
|
108
108
|
`\n Grouped under ${result.groupId} in round ${result.confirmations?.[0]?.confirmedRound}.`);
|
|
109
109
|
assetGroup.forEach((assetId, index) => {
|
|
@@ -131,7 +131,6 @@ class AssetManager {
|
|
|
131
131
|
*/
|
|
132
132
|
async bulkOptOut(account, assetIds, options) {
|
|
133
133
|
const results = [];
|
|
134
|
-
await this._algod.getTransactionParams().do();
|
|
135
134
|
const sender = typeof account === 'string' ? account : account.addr;
|
|
136
135
|
for (const assetGroup of chunkArray(assetIds, MAX_TRANSACTION_GROUP_SIZE)) {
|
|
137
136
|
const composer = this._newGroup();
|
|
@@ -145,7 +144,7 @@ class AssetManager {
|
|
|
145
144
|
nonZeroBalanceAssetIds.push(BigInt(assetId));
|
|
146
145
|
}
|
|
147
146
|
}
|
|
148
|
-
catch
|
|
147
|
+
catch {
|
|
149
148
|
notOptedInAssetIds.push(BigInt(assetId));
|
|
150
149
|
}
|
|
151
150
|
}
|
|
@@ -163,7 +162,7 @@ class AssetManager {
|
|
|
163
162
|
assetId: BigInt(assetId),
|
|
164
163
|
});
|
|
165
164
|
}
|
|
166
|
-
const result = await composer.
|
|
165
|
+
const result = await composer.send(options);
|
|
167
166
|
Config.getLogger(options?.suppressLog).info(`Successfully opted ${account} out of assets ${assetGroup.join(', ')} with transaction IDs ${result.txIds.join(', ')}` +
|
|
168
167
|
`\n Grouped under ${result.groupId} in round ${result.confirmations?.[0]?.confirmedRound}.`);
|
|
169
168
|
assetGroup.forEach((assetId, index) => {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"asset-manager.mjs","sources":["../../src/types/asset-manager.ts"],"sourcesContent":[null],"names":[],"mappings":";;;;;AAKA,IAAO,UAAU,GAAG,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAA;AAmI1C;MACa,YAAY,CAAA;AAIvB;;;;;;;;AAQG;IACH,WAAY,CAAA,KAAsB,EAAE,QAA+B,EAAA;AACjE,QAAA,IAAI,CAAC,MAAM,GAAG,KAAK,CAAA;AACnB,QAAA,IAAI,CAAC,SAAS,GAAG,QAAQ,CAAA;KAC1B;AAED;;;;;;;;;;AAUG;IACI,MAAM,OAAO,CAAC,OAAe,EAAA;QAClC,MAAM,KAAK,GAAG,UAAU,CAAC,qBAAqB,CAAC,MAAM,IAAI,CAAC,MAAM,CAAC,YAAY,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAA;QAEpG,OAAO;AACL,YAAA,OAAO,EAAE,MAAM,CAAC,KAAK,CAAC,KAAK,CAAC;YAC5B,KAAK,EAAE,MAAM,CAAC,KAAK,CAAC,MAAM,CAAC,KAAK,CAAC;YACjC,QAAQ,EAAE,MAAM,CAAC,KAAK,CAAC,MAAM,CAAC,QAAQ,CAAC;AACvC,YAAA,SAAS,EAAE,KAAK,CAAC,MAAM,CAAC,IAAI;AAC5B,YAAA,gBAAgB,EAAE,KAAK,CAAC,MAAM,CAAC,OAAO;AACtC,YAAA,QAAQ,EAAE,KAAK,CAAC,MAAM,CAAC,QAAQ;AAC/B,YAAA,eAAe,EAAE,KAAK,CAAC,MAAM,CAAC,WAAW;AACzC,YAAA,GAAG,EAAE,KAAK,CAAC,MAAM,CAAC,GAAG;AACrB,YAAA,UAAU,EAAE,KAAK,CAAC,MAAM,CAAC,MAAM;AAC/B,YAAA,OAAO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":["import algosdk from 'algosdk'\nimport { Config } from '../config'\nimport { chunkArray } from '../util'\nimport { AccountAssetInformation, TransactionSignerAccount } from './account'\nimport TransactionComposer, { CommonTransactionParams, MAX_TRANSACTION_GROUP_SIZE } from './composer'\nimport { SendParams } from './transaction'\nimport AssetModel = algosdk.modelsv2.Asset\n\n/** Individual result from performing a bulk opt-in or bulk opt-out for an account against a series of assets. */\nexport interface BulkAssetOptInOutResult {\n /** The ID of the asset opted into / out of */\n assetId: bigint\n /** The transaction ID of the resulting opt in / out */\n transactionId: string\n}\n\n/** Information about an asset. */\nexport interface AssetInformation {\n /** The ID of the asset. */\n assetId: bigint\n\n /** The address of the account that created the asset.\n *\n * This is the address where the parameters for this asset can be found,\n * and also the address where unwanted asset units can be sent when\n * closing out an asset position and opting-out of the asset.\n */\n creator: string\n\n /** The total amount of the smallest divisible (decimal) units that were created of the asset.\n *\n * For example, if `decimals` is, say, 2, then for every 100 `total` there is 1 whole unit.\n */\n total: bigint\n\n /** The amount of decimal places the asset was created with.\n *\n * * If 0, the asset is not divisible;\n * * If 1, the base unit of the asset is in tenths;\n * * If 2, the base unit of the asset is in hundredths;\n * * If 3, the base unit of the asset is in thousandths;\n * * and so on up to 19 decimal places.\n */\n decimals: number\n\n /** Whether the asset was frozen by default for all accounts.\n *\n * If `true` then for anyone apart from the creator to hold the\n * asset it needs to be unfrozen per account using an asset freeze\n * transaction from the `freeze` account.\n */\n defaultFrozen?: boolean\n\n /** The address of the optional account that can manage the configuration of the asset and destroy it.\n *\n * If not set the asset is permanently immutable.\n */\n manager?: string\n\n /**\n * The address of the optional account that holds the reserve (uncirculated supply) units of the asset.\n *\n * This address has no specific authority in the protocol itself and is informational only.\n *\n * Some standards like [ARC-19](https://github.com/algorandfoundation/ARCs/blob/main/ARCs/arc-0019.md)\n * rely on this field to hold meaningful data.\n *\n * It can be used in the case where you want to signal to holders of your asset that the uncirculated units\n * of the asset reside in an account that is different from the default creator account.\n *\n * If not set the field is permanently empty.\n */\n reserve?: string\n\n /**\n * The address of the optional account that can be used to freeze or unfreeze holdings of this asset for any account.\n *\n * If empty, freezing is not permitted.\n *\n * If not set the field is permanently empty.\n */\n freeze?: string\n\n /**\n * The address of the optional account that can clawback holdings of this asset from any account.\n *\n * The clawback account has the ability to **unconditionally take assets from any account**.\n *\n * If empty, clawback is not permitted.\n *\n * If not set the field is permanently empty.\n */\n clawback?: string\n\n /** The optional name of the unit of this asset (e.g. ticker name).\n *\n * Max size is 8 bytes.\n */\n unitName?: string\n\n /** The optional name of the unit of this asset (e.g. ticker name).\n *\n * Max size is 8 bytes.\n */\n unitNameAsBytes?: Uint8Array\n\n /** The optional name of the asset.\n *\n * Max size is 32 bytes.\n */\n assetName?: string\n\n /** The optional name of the asset.\n *\n * Max size is 32 bytes.\n */\n assetNameAsBytes?: Uint8Array\n\n /** Optional URL where more information about the asset can be retrieved (e.g. metadata).\n *\n * Max size is 96 bytes.\n */\n url?: string\n\n /** Optional URL where more information about the asset can be retrieved (e.g. metadata).\n *\n * Max size is 96 bytes.\n */\n urlAsBytes?: Uint8Array\n\n /** 32-byte hash of some metadata that is relevant to the asset and/or asset holders.\n *\n * The format of this metadata is up to the application.\n */\n metadataHash?: Uint8Array\n}\n\n/** Allows management of asset information. */\nexport class AssetManager {\n private _algod: algosdk.Algodv2\n private _newGroup: () => TransactionComposer\n\n /**\n * Create a new asset manager.\n * @param algod An algod client\n * @param newGroup A function that creates a new `TransactionComposer` transaction group\n * @example Create a new asset manager\n * ```typescript\n * const assetManager = new AssetManager(algod, () => new TransactionComposer({algod, () => signer, () => suggestedParams}))\n * ```\n */\n constructor(algod: algosdk.Algodv2, newGroup: () => TransactionComposer) {\n this._algod = algod\n this._newGroup = newGroup\n }\n\n /**\n * Returns the current asset information for the asset with the given ID.\n *\n * @example\n * ```typescript\n * const assetInfo = await assetManager.getById(12353n);\n * ```\n *\n * @param assetId The ID of the asset\n * @returns The asset information\n */\n public async getById(assetId: bigint): Promise<AssetInformation> {\n const asset = AssetModel.from_obj_for_encoding(await this._algod.getAssetByID(Number(assetId)).do())\n\n return {\n assetId: BigInt(asset.index),\n total: BigInt(asset.params.total),\n decimals: Number(asset.params.decimals),\n assetName: asset.params.name,\n assetNameAsBytes: asset.params.nameB64,\n unitName: asset.params.unitName,\n unitNameAsBytes: asset.params.unitNameB64,\n url: asset.params.url,\n urlAsBytes: asset.params.urlB64,\n creator: asset.params.creator,\n manager: asset.params.manager,\n clawback: asset.params.clawback,\n freeze: asset.params.freeze,\n reserve: asset.params.reserve,\n defaultFrozen: asset.params.defaultFrozen,\n metadataHash: asset.params.metadataHash,\n }\n }\n\n /**\n * Returns the given sender account's asset holding for a given asset.\n *\n * @example\n * ```typescript\n * const address = \"XBYLS2E6YI6XXL5BWCAMOA4GTWHXWENZMX5UHXMRNWWUQ7BXCY5WC5TEPA\";\n * const assetId = 123345n;\n * const accountInfo = await algorand.asset.getAccountInformation(address, assetId);\n * ```\n *\n * [Response data schema details](https://developer.algorand.org/docs/rest-apis/algod/#get-v2accountsaddressassetsasset-id)\n * @param sender The address of the sender/account to look up\n * @param assetId The ID of the asset to return a holding for\n * @returns The account asset holding information\n */\n public async getAccountInformation(sender: string | TransactionSignerAccount, assetId: bigint): Promise<AccountAssetInformation> {\n const info = await this._algod.accountAssetInformation(typeof sender === 'string' ? sender : sender.addr, Number(assetId)).do()\n\n return {\n assetId: BigInt(assetId),\n balance: BigInt(info['asset-holding']['amount']),\n frozen: info['asset-holding']['is-frozen'] === true,\n round: BigInt(info['round']),\n }\n }\n\n /**\n * Opt an account in to a list of Algorand Standard Assets.\n *\n * Transactions will be sent in batches of 16 as transaction groups.\n *\n * @param account The account to opt-in\n * @param assetIds The list of asset IDs to opt-in to\n * @param options Any parameters to control the transaction or execution of the transaction\n * @example Example using AlgorandClient\n * ```typescript\n * // Basic example\n * algorand.asset.bulkOptIn(\"ACCOUNTADDRESS\", [12345n, 67890n])\n * // With configuration\n * algorand.asset.bulkOptIn(\"ACCOUNTADDRESS\", [12345n, 67890n], { maxFee: (1000).microAlgo(), suppressLog: true })\n * ```\n * @returns An array of records matching asset ID to transaction ID of the opt in\n */\n async bulkOptIn(\n account: string | TransactionSignerAccount,\n assetIds: bigint[],\n options?: Omit<CommonTransactionParams, 'sender'> & SendParams,\n ): Promise<BulkAssetOptInOutResult[]> {\n const results: BulkAssetOptInOutResult[] = []\n\n for (const assetGroup of chunkArray(assetIds, MAX_TRANSACTION_GROUP_SIZE)) {\n const composer = this._newGroup()\n\n for (const assetId of assetGroup) {\n composer.addAssetOptIn({\n ...options,\n sender: typeof account === 'string' ? account : account.addr,\n assetId: BigInt(assetId),\n })\n }\n\n const result = await composer.send(options)\n\n Config.getLogger(options?.suppressLog).info(\n `Successfully opted in ${account} for assets ${assetGroup.join(', ')} with transaction IDs ${result.txIds.join(', ')}` +\n `\\n Grouped under ${result.groupId} in round ${result.confirmations?.[0]?.confirmedRound}.`,\n )\n\n assetGroup.forEach((assetId, index) => {\n results.push({ assetId: BigInt(assetId), transactionId: result.txIds[index] })\n })\n }\n\n return results\n }\n\n /**\n * Opt an account out of a list of Algorand Standard Assets.\n *\n * Transactions will be sent in batches of 16 as transaction groups.\n *\n * @param account The account to opt-in\n * @param assetIds The list of asset IDs to opt-out of\n * @param options Any parameters to control the transaction or execution of the transaction\n * @example Example using AlgorandClient\n * ```typescript\n * // Basic example\n * algorand.asset.bulkOptOut(\"ACCOUNTADDRESS\", [12345n, 67890n])\n * // With configuration\n * algorand.asset.bulkOptOut(\"ACCOUNTADDRESS\", [12345n, 67890n], { ensureZeroBalance: true, maxFee: (1000).microAlgo(), suppressLog: true })\n * ```\n * @returns An array of records matching asset ID to transaction ID of the opt in\n */\n async bulkOptOut(\n account: string | TransactionSignerAccount,\n assetIds: bigint[],\n options?: Omit<CommonTransactionParams, 'sender'> &\n SendParams & {\n /** Whether or not to check if the account has a zero balance for each asset first or not.\n *\n * Defaults to `true`.\n *\n * If this is set to `true` and the account has an asset balance it will throw an error.\n *\n * If this is set to `false` and the account has an asset balance it will lose those assets to the asset creator.\n */\n ensureZeroBalance?: boolean\n },\n ): Promise<BulkAssetOptInOutResult[]> {\n const results: BulkAssetOptInOutResult[] = []\n\n const sender = typeof account === 'string' ? account : account.addr\n\n for (const assetGroup of chunkArray(assetIds, MAX_TRANSACTION_GROUP_SIZE)) {\n const composer = this._newGroup()\n\n const notOptedInAssetIds: bigint[] = []\n const nonZeroBalanceAssetIds: bigint[] = []\n for (const assetId of assetGroup) {\n if (options?.ensureZeroBalance !== false) {\n try {\n const accountAssetInfo = await this.getAccountInformation(sender, assetId)\n if (accountAssetInfo.balance !== 0n) {\n nonZeroBalanceAssetIds.push(BigInt(assetId))\n }\n } catch {\n notOptedInAssetIds.push(BigInt(assetId))\n }\n }\n }\n\n if (notOptedInAssetIds.length > 0 || nonZeroBalanceAssetIds.length > 0) {\n throw new Error(\n `Account ${sender}${notOptedInAssetIds.length > 0 ? ` is not opted-in to Asset${notOptedInAssetIds.length > 1 ? 's' : ''} ${notOptedInAssetIds.join(', ')}` : ''}${\n nonZeroBalanceAssetIds.length > 0\n ? ` has non-zero balance for Asset${nonZeroBalanceAssetIds.length > 1 ? 's' : ''} ${nonZeroBalanceAssetIds.join(', ')}`\n : ''\n }; can't opt-out.`,\n )\n }\n\n for (const assetId of assetGroup) {\n composer.addAssetOptOut({\n ...options,\n creator: (await this.getById(BigInt(assetId))).creator,\n sender,\n assetId: BigInt(assetId),\n })\n }\n\n const result = await composer.send(options)\n\n Config.getLogger(options?.suppressLog).info(\n `Successfully opted ${account} out of assets ${assetGroup.join(', ')} with transaction IDs ${result.txIds.join(', ')}` +\n `\\n Grouped under ${result.groupId} in round ${result.confirmations?.[0]?.confirmedRound}.`,\n )\n\n assetGroup.forEach((assetId, index) => {\n results.push({ assetId: BigInt(assetId), transactionId: result.txIds[index] })\n })\n }\n\n return results\n }\n}\n"],"names":[],"mappings":";;;;;AAMA,IAAO,UAAU,GAAG,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAA;AAmI1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AO,EAAE,MAAM,CAAC,OAAO,CAAC;AACzB,iBAAA,CAAC,CAAA;aACH;YAED,MAAM,MAAM,GAAG,MAAM,QAAQ,CAAC,IAAI,CAAC,OAAO,CAAC,CAAA;AAE3C,YAAA,MAAM,CAAC,SAAS,CAAC,OAAO,EAAE,WAAW,CAAC,CAAC,IAAI,CACzC,CAAsB,mBAAA,EAAA,OAAO,CAAkB,eAAA,EAAA,UAAU,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA,sBAAA,EAAyB,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAE,CAAA;AACpH,gBAAA,CAAA,kBAAA,EAAqB,MAAM,CAAC,OAAO,CAAA,UAAA,EAAa,MAAM,CAAC,aAAa,GAAG,CAAC,CAAC,EAAE,cAAc,CAAA,CAAA,CAAG,CAC/F,CAAA;YAED,UAAU,CAAC,OAAO,CAAC,CAAC,OAAO,EAAE,KAAK,KAAI;gBACpC,OAAO,CAAC,IAAI,CAAC,EAAE,OAAO,EAAE,MAAM,CAAC,OAAO,CAAC,EAAE,aAAa,EAAE,MAAM,CAAC,KAAK,CAAC,KAAK,CAAC,EAAE,CAAC,CAAA;AAChF,aAAC,CAAC,CAAA;SACH;AAED,QAAA,OAAO,OAAO,CAAA;KACf;AACF;;;;"}
|
package/types/asset.d.ts
CHANGED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { EventDataMap, EventType } from './lifecycle-events';
|
|
2
|
+
export type AsyncEventListener<T = unknown> = (event: T, eventName: string | symbol) => Promise<void> | void;
|
|
3
|
+
export declare class AsyncEventEmitter {
|
|
4
|
+
private listenerWrapperMap;
|
|
5
|
+
private listenerMap;
|
|
6
|
+
emitAsync<K extends EventType>(eventName: K, event: EventDataMap[K]): Promise<void>;
|
|
7
|
+
emitAsync(eventName: string | symbol, event: unknown): Promise<void>;
|
|
8
|
+
on<K extends EventType>(eventName: K, listener: AsyncEventListener<EventDataMap[K]>): AsyncEventEmitter;
|
|
9
|
+
on<T = unknown>(eventName: string | symbol, listener: AsyncEventListener<T>): AsyncEventEmitter;
|
|
10
|
+
once<K extends EventType>(eventName: K, listener: AsyncEventListener<EventDataMap[K]>): AsyncEventEmitter;
|
|
11
|
+
once<T = unknown>(eventName: string | symbol, listener: AsyncEventListener<T>): AsyncEventEmitter;
|
|
12
|
+
removeListener(eventName: string | symbol, listener: AsyncEventListener): AsyncEventEmitter;
|
|
13
|
+
off: (eventName: string | symbol, listener: AsyncEventListener) => AsyncEventEmitter;
|
|
14
|
+
}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
class AsyncEventEmitter {
|
|
4
|
+
constructor() {
|
|
5
|
+
this.listenerWrapperMap = new WeakMap();
|
|
6
|
+
this.listenerMap = {};
|
|
7
|
+
this.off = this.removeListener;
|
|
8
|
+
}
|
|
9
|
+
async emitAsync(eventName, event) {
|
|
10
|
+
for (const listener of this.listenerMap[eventName] ?? []) {
|
|
11
|
+
await listener(event, eventName);
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
on(eventName, listener) {
|
|
15
|
+
if (!this.listenerMap[eventName])
|
|
16
|
+
this.listenerMap[eventName] = [];
|
|
17
|
+
this.listenerMap[eventName].push(listener);
|
|
18
|
+
return this;
|
|
19
|
+
}
|
|
20
|
+
once(eventName, listener) {
|
|
21
|
+
const wrappedListener = async (event, eventName) => {
|
|
22
|
+
try {
|
|
23
|
+
return await listener(event, eventName);
|
|
24
|
+
}
|
|
25
|
+
finally {
|
|
26
|
+
this.removeListener(eventName, wrappedListener);
|
|
27
|
+
}
|
|
28
|
+
};
|
|
29
|
+
this.listenerWrapperMap.set(listener, wrappedListener);
|
|
30
|
+
return this.on(eventName, wrappedListener);
|
|
31
|
+
}
|
|
32
|
+
removeListener(eventName, listener) {
|
|
33
|
+
const wrappedListener = this.listenerWrapperMap.get(listener);
|
|
34
|
+
if (wrappedListener) {
|
|
35
|
+
this.listenerWrapperMap.delete(listener);
|
|
36
|
+
if (this.listenerMap[eventName]?.indexOf(wrappedListener) !== -1) {
|
|
37
|
+
this.listenerMap[eventName].splice(this.listenerMap[eventName].indexOf(wrappedListener), 1);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
else {
|
|
41
|
+
if (this.listenerMap[eventName]?.indexOf(listener) !== -1) {
|
|
42
|
+
this.listenerMap[eventName].splice(this.listenerMap[eventName].indexOf(listener), 1);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
return this;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
exports.AsyncEventEmitter = AsyncEventEmitter;
|
|
50
|
+
//# sourceMappingURL=async-event-emitter.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"async-event-emitter.js","sources":["../../src/types/async-event-emitter.ts"],"sourcesContent":["import { EventDataMap, EventType } from './lifecycle-events'\n\nexport type AsyncEventListener<T = unknown> = (event: T, eventName: string | symbol) => Promise<void> | void\n\nexport class AsyncEventEmitter {\n private listenerWrapperMap = new WeakMap<AsyncEventListener, AsyncEventListener>()\n private listenerMap: Record<string | symbol, AsyncEventListener[]> = {}\n\n async emitAsync<K extends EventType>(eventName: K, event: EventDataMap[K]): Promise<void>\n async emitAsync(eventName: string | symbol, event: unknown): Promise<void>\n async emitAsync(eventName: string | symbol, event: unknown): Promise<void> {\n for (const listener of this.listenerMap[eventName] ?? []) {\n await listener(event, eventName)\n }\n }\n\n on<K extends EventType>(eventName: K, listener: AsyncEventListener<EventDataMap[K]>): AsyncEventEmitter\n on<T = unknown>(eventName: string | symbol, listener: AsyncEventListener<T>): AsyncEventEmitter\n on(eventName: string | symbol, listener: AsyncEventListener): AsyncEventEmitter {\n if (!this.listenerMap[eventName]) this.listenerMap[eventName] = []\n this.listenerMap[eventName].push(listener as AsyncEventListener)\n return this\n }\n\n once<K extends EventType>(eventName: K, listener: AsyncEventListener<EventDataMap[K]>): AsyncEventEmitter\n once<T = unknown>(eventName: string | symbol, listener: AsyncEventListener<T>): AsyncEventEmitter\n once(eventName: string | symbol, listener: AsyncEventListener): AsyncEventEmitter {\n const wrappedListener: AsyncEventListener = async (event, eventName) => {\n try {\n return await listener(event, eventName)\n } finally {\n this.removeListener(eventName, wrappedListener)\n }\n }\n this.listenerWrapperMap.set(listener, wrappedListener)\n return this.on(eventName, wrappedListener)\n }\n\n removeListener(eventName: string | symbol, listener: AsyncEventListener): AsyncEventEmitter {\n const wrappedListener = this.listenerWrapperMap.get(listener)\n if (wrappedListener) {\n this.listenerWrapperMap.delete(listener)\n if (this.listenerMap[eventName]?.indexOf(wrappedListener) !== -1) {\n this.listenerMap[eventName].splice(this.listenerMap[eventName].indexOf(wrappedListener), 1)\n }\n } else {\n if (this.listenerMap[eventName]?.indexOf(listener) !== -1) {\n this.listenerMap[eventName].splice(this.listenerMap[eventName].indexOf(listener), 1)\n }\n }\n\n return this\n }\n\n off = this.removeListener\n}\n"],"names":[],"mappings":";;MAIa,iBAAiB,CAAA;AAA9B,IAAA,WAAA,GAAA;AACU,QAAA,IAAA,CAAA,kBAAkB,GAAG,IAAI,OAAO,EAA0C,CAAA;QAC1E,IAAW,CAAA,WAAA,GAAkD,EAAE,CAAA;AAgDvE,QAAA,IAAA,CAAA,GAAG,GAAG,IAAI,CAAC,cAAc,CAAA;KAC1B;AA7CC,IAAA,MAAM,SAAS,CAAC,SAA0B,EAAE,KAAc,EAAA;AACxD,QAAA,KAAK,MAAM,QAAQ,IAAI,IAAI,CAAC,WAAW,CAAC,SAAS,CAAC,IAAI,EAAE,EAAE;AACxD,YAAA,MAAM,QAAQ,CAAC,KAAK,EAAE,SAAS,CAAC,CAAA;SACjC;KACF;IAID,EAAE,CAAC,SAA0B,EAAE,QAA4B,EAAA;AACzD,QAAA,IAAI,CAAC,IAAI,CAAC,WAAW,CAAC,SAAS,CAAC;AAAE,YAAA,IAAI,CAAC,WAAW,CAAC,SAAS,CAAC,GAAG,EAAE,CAAA;QAClE,IAAI,C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AS,CAAC,CAAC,OAAO,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC,CAAA;aACrF;SACF;AAED,QAAA,OAAO,IAAI,CAAA;KACZ;AAGF;;;;"}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
class AsyncEventEmitter {
|
|
2
|
+
constructor() {
|
|
3
|
+
this.listenerWrapperMap = new WeakMap();
|
|
4
|
+
this.listenerMap = {};
|
|
5
|
+
this.off = this.removeListener;
|
|
6
|
+
}
|
|
7
|
+
async emitAsync(eventName, event) {
|
|
8
|
+
for (const listener of this.listenerMap[eventName] ?? []) {
|
|
9
|
+
await listener(event, eventName);
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
on(eventName, listener) {
|
|
13
|
+
if (!this.listenerMap[eventName])
|
|
14
|
+
this.listenerMap[eventName] = [];
|
|
15
|
+
this.listenerMap[eventName].push(listener);
|
|
16
|
+
return this;
|
|
17
|
+
}
|
|
18
|
+
once(eventName, listener) {
|
|
19
|
+
const wrappedListener = async (event, eventName) => {
|
|
20
|
+
try {
|
|
21
|
+
return await listener(event, eventName);
|
|
22
|
+
}
|
|
23
|
+
finally {
|
|
24
|
+
this.removeListener(eventName, wrappedListener);
|
|
25
|
+
}
|
|
26
|
+
};
|
|
27
|
+
this.listenerWrapperMap.set(listener, wrappedListener);
|
|
28
|
+
return this.on(eventName, wrappedListener);
|
|
29
|
+
}
|
|
30
|
+
removeListener(eventName, listener) {
|
|
31
|
+
const wrappedListener = this.listenerWrapperMap.get(listener);
|
|
32
|
+
if (wrappedListener) {
|
|
33
|
+
this.listenerWrapperMap.delete(listener);
|
|
34
|
+
if (this.listenerMap[eventName]?.indexOf(wrappedListener) !== -1) {
|
|
35
|
+
this.listenerMap[eventName].splice(this.listenerMap[eventName].indexOf(wrappedListener), 1);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
else {
|
|
39
|
+
if (this.listenerMap[eventName]?.indexOf(listener) !== -1) {
|
|
40
|
+
this.listenerMap[eventName].splice(this.listenerMap[eventName].indexOf(listener), 1);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
return this;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
export { AsyncEventEmitter };
|
|
48
|
+
//# sourceMappingURL=async-event-emitter.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"async-event-emitter.mjs","sources":["../../src/types/async-event-emitter.ts"],"sourcesContent":["import { EventDataMap, EventType } from './lifecycle-events'\n\nexport type AsyncEventListener<T = unknown> = (event: T, eventName: string | symbol) => Promise<void> | void\n\nexport class AsyncEventEmitter {\n private listenerWrapperMap = new WeakMap<AsyncEventListener, AsyncEventListener>()\n private listenerMap: Record<string | symbol, AsyncEventListener[]> = {}\n\n async emitAsync<K extends EventType>(eventName: K, event: EventDataMap[K]): Promise<void>\n async emitAsync(eventName: string | symbol, event: unknown): Promise<void>\n async emitAsync(eventName: string | symbol, event: unknown): Promise<void> {\n for (const listener of this.listenerMap[eventName] ?? []) {\n await listener(event, eventName)\n }\n }\n\n on<K extends EventType>(eventName: K, listener: AsyncEventListener<EventDataMap[K]>): AsyncEventEmitter\n on<T = unknown>(eventName: string | symbol, listener: AsyncEventListener<T>): AsyncEventEmitter\n on(eventName: string | symbol, listener: AsyncEventListener): AsyncEventEmitter {\n if (!this.listenerMap[eventName]) this.listenerMap[eventName] = []\n this.listenerMap[eventName].push(listener as AsyncEventListener)\n return this\n }\n\n once<K extends EventType>(eventName: K, listener: AsyncEventListener<EventDataMap[K]>): AsyncEventEmitter\n once<T = unknown>(eventName: string | symbol, listener: AsyncEventListener<T>): AsyncEventEmitter\n once(eventName: string | symbol, listener: AsyncEventListener): AsyncEventEmitter {\n const wrappedListener: AsyncEventListener = async (event, eventName) => {\n try {\n return await listener(event, eventName)\n } finally {\n this.removeListener(eventName, wrappedListener)\n }\n }\n this.listenerWrapperMap.set(listener, wrappedListener)\n return this.on(eventName, wrappedListener)\n }\n\n removeListener(eventName: string | symbol, listener: AsyncEventListener): AsyncEventEmitter {\n const wrappedListener = this.listenerWrapperMap.get(listener)\n if (wrappedListener) {\n this.listenerWrapperMap.delete(listener)\n if (this.listenerMap[eventName]?.indexOf(wrappedListener) !== -1) {\n this.listenerMap[eventName].splice(this.listenerMap[eventName].indexOf(wrappedListener), 1)\n }\n } else {\n if (this.listenerMap[eventName]?.indexOf(listener) !== -1) {\n this.listenerMap[eventName].splice(this.listenerMap[eventName].indexOf(listener), 1)\n }\n }\n\n return this\n }\n\n off = this.removeListener\n}\n"],"names":[],"mappings":"MAIa,iBAAiB,CAAA;AAA9B,IAAA,WAAA,GAAA;AACU,QAAA,IAAA,CAAA,kBAAkB,GAAG,IAAI,OAAO,EAA0C,CAAA;QAC1E,IAAW,CAAA,WAAA,GAAkD,EAAE,CAAA;AAgDvE,QAAA,IAAA,CAAA,GAAG,GAAG,IAAI,CAAC,cAAc,CAAA;KAC1B;AA7CC,IAAA,MAAM,SAAS,CAAC,SAA0B,EAAE,KAAc,EAAA;AACxD,QAAA,KAAK,MAAM,QAAQ,IAAI,IAAI,CAAC,WAAW,CAAC,SAAS,CAAC,IAAI,EAAE,EAAE;AACxD,YAAA,MAAM,QAAQ,CAAC,KAAK,EAAE,SAAS,CAAC,CAAA;SACjC;KACF;IAID,EAAE,CAAC,SAA0B,EAAE,QAA4B,EAAA;AACzD,QAAA,IAAI,CAAC,IAAI,CAAC,WAAW,CAAC,SAAS,CAAC;AAAE,YAAA,IAAI,CAAC,WAAW,CAAC,SAAS,CAAC,GAAG,EAAE,CAAA;QAClE,IAAI,CAAC,WAAW,CAAC,SAAS,CAAC,CAAC,IAAI,CAAC,QAA8B,CAAC,CAAA;AAChE,QAAA,OAAO,IAAI,CAAA;KACZ;IAID,IAAI,CAAC,SAA0B,EAAE,QAA4B,EAAA;QAC3D,MAAM,eAAe,GAAuB,OAAO,KAAK,EAAE,SAAS,KAAI;AACrE,YAAA,IAAI;AACF,gBAAA,OAAO,MAAM,QA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