From db7750a00b023bb3601f876c987b363b6ecc6d4c Mon Sep 17 00:00:00 2001 From: "Rob Moore (MakerX)" Date: Sun, 16 Jun 2024 11:39:20 +0800 Subject: [PATCH 01/18] feat: Ensuring equivalent implementation of transfer, asset and part of transaction modules * Collapsed the second object in algorand.send.type(params, *executeOptions*) to combine into params and make it easier to use * Added `algorand.client.getTestNetDispenserFromEnvironment` * Added `algorand.account.assetBulkOptIn` * Added `algorand.account.assetBulkOptOut` * Added `algorand.account.ensureFunded` * Added `algorand.account.ensureFundedFromEnvironment` * Added `algorand.account.ensureFundedFromTestNetDispenserApi` * Added `algorand.send/transaction.rekey` * Added `algorand.send/transaction.assetOptOut` --- docs/capabilities/dispenser-client.md | 2 +- .../types_account_manager.AccountManager.md | 305 ++++++++++++-- .../types_algorand_client.AlgorandClient.md | 98 +++-- .../types_client_manager.ClientManager.md | 76 +++- docs/code/classes/types_composer.default.md | 122 ++++-- ...penser_client.TestNetDispenserApiClient.md | 6 +- ...account_manager.BulkAssetOptInOutResult.md | 38 ++ ...ypes_account_manager.EnsureFundedResult.md | 38 ++ .../types_client_manager.TypedAppClient.md | 2 +- .../types_composer.ExecuteParams.md | 4 +- ..._client.TestNetDispenserApiClientParams.md | 2 +- docs/code/modules/index.md | 20 +- docs/code/modules/types_account_manager.md | 7 +- docs/code/modules/types_algorand_client.md | 2 +- docs/code/modules/types_client_manager.md | 8 +- docs/code/modules/types_composer.md | 70 +++- src/asset.spec.ts | 24 +- src/asset.ts | 373 ++++-------------- src/dispenser-client.ts | 4 +- src/testing/account.ts | 11 +- src/transaction/legacy-bridge.ts | 36 ++ src/transaction/transaction.spec.ts | 4 +- src/transfer/transfer-algos.ts | 41 +- src/transfer/transfer.spec.ts | 8 +- src/transfer/transfer.ts | 219 ++++------ src/types/account-manager.ts | 349 +++++++++++++++- src/types/algorand-client.ts | 213 +++++++++- src/types/client-manager.ts | 23 +- src/types/composer.ts | 178 ++++++++- src/types/dispenser-client.spec.ts | 12 +- src/types/dispenser-client.ts | 20 +- src/util.ts | 24 ++ 32 files changed, 1636 insertions(+), 703 deletions(-) create mode 100644 docs/code/interfaces/types_account_manager.BulkAssetOptInOutResult.md create mode 100644 docs/code/interfaces/types_account_manager.EnsureFundedResult.md create mode 100644 src/transaction/legacy-bridge.ts diff --git a/docs/capabilities/dispenser-client.md b/docs/capabilities/dispenser-client.md index 7e192af8..2aca1eb4 100644 --- a/docs/capabilities/dispenser-client.md +++ b/docs/capabilities/dispenser-client.md @@ -23,7 +23,7 @@ const clientFromAlgorandClient = algorand.client.getTestNetDispenser({ authToken // Using environment variable process.env['ALGOKIT_DISPENSER_ACCESS_TOKEN'] = 'your_auth_token' const client = new TestNetDispenserApiClient() -const clientFromAlgorandClient = algorand.client.getTestNetDispenserApiClient() +const clientFromAlgorandClient = algorand.client.getTestNetDispenserFromEnvironment() ``` ## Funding an Account diff --git a/docs/code/classes/types_account_manager.AccountManager.md b/docs/code/classes/types_account_manager.AccountManager.md index 10743fbf..7cfbd32a 100644 --- a/docs/code/classes/types_account_manager.AccountManager.md +++ b/docs/code/classes/types_account_manager.AccountManager.md @@ -25,7 +25,14 @@ Creates and keeps track of signing accounts that can sign transactions for a sen ### Methods +- [\_getComposer](types_account_manager.AccountManager.md#_getcomposer) +- [\_getEnsureFundedAmount](types_account_manager.AccountManager.md#_getensurefundedamount) +- [assetBulkOptIn](types_account_manager.AccountManager.md#assetbulkoptin) +- [assetBulkOptOut](types_account_manager.AccountManager.md#assetbulkoptout) - [dispenserFromEnvironment](types_account_manager.AccountManager.md#dispenserfromenvironment) +- [ensureFunded](types_account_manager.AccountManager.md#ensurefunded) +- [ensureFundedFromEnvironment](types_account_manager.AccountManager.md#ensurefundedfromenvironment) +- [ensureFundedFromTestNetDispenserApi](types_account_manager.AccountManager.md#ensurefundedfromtestnetdispenserapi) - [fromEnvironment](types_account_manager.AccountManager.md#fromenvironment) - [fromKmd](types_account_manager.AccountManager.md#fromkmd) - [fromMnemonic](types_account_manager.AccountManager.md#frommnemonic) @@ -69,7 +76,7 @@ const accountManager = new AccountManager(clientManager) #### Defined in -[src/types/account-manager.ts:51](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/account-manager.ts#L51) +[src/types/account-manager.ts:63](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/account-manager.ts#L63) ## Properties @@ -83,7 +90,7 @@ const accountManager = new AccountManager(clientManager) #### Defined in -[src/types/account-manager.ts:40](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/account-manager.ts#L40) +[src/types/account-manager.ts:52](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/account-manager.ts#L52) ___ @@ -93,7 +100,7 @@ ___ #### Defined in -[src/types/account-manager.ts:38](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/account-manager.ts#L38) +[src/types/account-manager.ts:50](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/account-manager.ts#L50) ___ @@ -103,7 +110,7 @@ ___ #### Defined in -[src/types/account-manager.ts:41](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/account-manager.ts#L41) +[src/types/account-manager.ts:53](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/account-manager.ts#L53) ___ @@ -113,7 +120,7 @@ ___ #### Defined in -[src/types/account-manager.ts:39](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/account-manager.ts#L39) +[src/types/account-manager.ts:51](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/account-manager.ts#L51) ## Accessors @@ -129,10 +136,126 @@ KMD account manager that allows you to easily get and create accounts using KMD. #### Defined in -[src/types/account-manager.ts:57](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/account-manager.ts#L57) +[src/types/account-manager.ts:77](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/account-manager.ts#L77) ## Methods +### \_getComposer + +▸ **_getComposer**(`getSuggestedParams?`): [`default`](types_composer.default.md) + +#### Parameters + +| Name | Type | +| :------ | :------ | +| `getSuggestedParams?` | () => `Promise`\<`SuggestedParams`\> | + +#### Returns + +[`default`](types_composer.default.md) + +#### Defined in + +[src/types/account-manager.ts:68](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/account-manager.ts#L68) + +___ + +### \_getEnsureFundedAmount + +▸ **_getEnsureFundedAmount**(`sender`, `minSpendingBalance`, `minFundingIncrement?`): `Promise`\<`undefined` \| [`AlgoAmount`](types_amount.AlgoAmount.md)\> + +#### Parameters + +| Name | Type | +| :------ | :------ | +| `sender` | `string` | +| `minSpendingBalance` | [`AlgoAmount`](types_amount.AlgoAmount.md) | +| `minFundingIncrement?` | [`AlgoAmount`](types_amount.AlgoAmount.md) | + +#### Returns + +`Promise`\<`undefined` \| [`AlgoAmount`](types_amount.AlgoAmount.md)\> + +#### Defined in + +[src/types/account-manager.ts:593](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/account-manager.ts#L593) + +___ + +### assetBulkOptIn + +▸ **assetBulkOptIn**(`account`, `assetIds`, `options?`): `Promise`\<[`BulkAssetOptInOutResult`](../interfaces/types_account_manager.BulkAssetOptInOutResult.md)[]\> + +Opt an account in to a list of Algorand Standard Assets. + +Transactions will be sent in batches of 16 as transaction groups. + +#### Parameters + +| Name | Type | Description | +| :------ | :------ | :------ | +| `account` | `string` \| [`TransactionSignerAccount`](../interfaces/types_account.TransactionSignerAccount.md) | The account to opt-in | +| `assetIds` | (`number` \| `bigint`)[] | The list of asset IDs to opt-in to | +| `options?` | `Omit`\<[`CommonTransactionParams`](../modules/types_composer.md#commontransactionparams), ``"sender"``\> & [`ExecuteParams`](../interfaces/types_composer.ExecuteParams.md) | Any parameters to control the transaction or execution of the transaction | + +#### Returns + +`Promise`\<[`BulkAssetOptInOutResult`](../interfaces/types_account_manager.BulkAssetOptInOutResult.md)[]\> + +An array of records matching asset ID to transaction ID of the opt in + +**`Example`** + +```typescript +// Basic example +algorand.account.assetBulkOptIn("ACCOUNTADDRESS", [12345, 67890]) +// With configuration +algorand.account.assetBulkOptIn("ACCOUNTADDRESS", [12345, 67890], { maxFee: (1000).microAlgos(), suppressLog: true }) +``` + +#### Defined in + +[src/types/account-manager.ts:470](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/account-manager.ts#L470) + +___ + +### assetBulkOptOut + +▸ **assetBulkOptOut**(`account`, `assetIds`, `options?`): `Promise`\<[`BulkAssetOptInOutResult`](../interfaces/types_account_manager.BulkAssetOptInOutResult.md)[]\> + +Opt an account out of a list of Algorand Standard Assets. + +Transactions will be sent in batches of 16 as transaction groups. + +#### Parameters + +| Name | Type | Description | +| :------ | :------ | :------ | +| `account` | `string` \| [`TransactionSignerAccount`](../interfaces/types_account.TransactionSignerAccount.md) | The account to opt-in | +| `assetIds` | (`number` \| `bigint`)[] | The list of asset IDs to opt-out of | +| `options?` | `Omit`\<[`CommonTransactionParams`](../modules/types_composer.md#commontransactionparams), ``"sender"``\> & [`ExecuteParams`](../interfaces/types_composer.ExecuteParams.md) & \{ `ensureZeroBalance`: `boolean` } | Any parameters to control the transaction or execution of the transaction | + +#### Returns + +`Promise`\<[`BulkAssetOptInOutResult`](../interfaces/types_account_manager.BulkAssetOptInOutResult.md)[]\> + +An array of records matching asset ID to transaction ID of the opt in + +**`Example`** + +```typescript +// Basic example +algorand.account.assetBulkOptOut("ACCOUNTADDRESS", [12345, 67890]) +// With configuration +algorand.account.assetBulkOptOut("ACCOUNTADDRESS", [12345, 67890], { maxFee: (1000).microAlgos(), suppressLog: true }) +``` + +#### Defined in + +[src/types/account-manager.ts:522](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/account-manager.ts#L522) + +___ + ### dispenserFromEnvironment ▸ **dispenserFromEnvironment**(): `Promise`\<[`TransactionSignerAccount`](../interfaces/types_account.TransactionSignerAccount.md) & \{ `account`: [`SigningAccount`](types_account.SigningAccount.md) }\> @@ -159,7 +282,143 @@ const account = await account.dispenserFromEnvironment() #### Defined in -[src/types/account-manager.ts:409](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/account-manager.ts#L409) +[src/types/account-manager.ts:429](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/account-manager.ts#L429) + +___ + +### ensureFunded + +▸ **ensureFunded**(`accountToFund`, `dispenserAccount`, `minSpendingBalance`, `options?`): `Promise`\<`undefined` \| [`SendAtomicTransactionComposerResults`](../interfaces/types_transaction.SendAtomicTransactionComposerResults.md) & [`ConfirmedTransactionResult`](../interfaces/types_transaction.ConfirmedTransactionResult.md) & [`EnsureFundedResult`](../interfaces/types_account_manager.EnsureFundedResult.md)\> + +Funds a given account using a dispenser account as a funding source such that +the given account has a certain amount of algos free to spend (accounting for +ALGOs locked in minimum balance requirement). + +https://developer.algorand.org/docs/get-details/accounts/#minimum-balance + +#### Parameters + +| Name | Type | Description | +| :------ | :------ | :------ | +| `accountToFund` | `string` \| [`TransactionSignerAccount`](../interfaces/types_account.TransactionSignerAccount.md) | The account to fund | +| `dispenserAccount` | `string` \| [`TransactionSignerAccount`](../interfaces/types_account.TransactionSignerAccount.md) | The account to use as a dispenser funding source | +| `minSpendingBalance` | [`AlgoAmount`](types_amount.AlgoAmount.md) | The minimum balance of ALGOs that the account should have available to spend (i.e. on top of minimum balance requirement) | +| `options?` | \{ `minFundingIncrement?`: [`AlgoAmount`](types_amount.AlgoAmount.md) } & [`ExecuteParams`](../interfaces/types_composer.ExecuteParams.md) & `Omit`\<[`CommonTransactionParams`](../modules/types_composer.md#commontransactionparams), ``"sender"``\> | Optional parameters to control the funding increment, transaction or execution of the transaction | + +#### Returns + +`Promise`\<`undefined` \| [`SendAtomicTransactionComposerResults`](../interfaces/types_transaction.SendAtomicTransactionComposerResults.md) & [`ConfirmedTransactionResult`](../interfaces/types_transaction.ConfirmedTransactionResult.md) & [`EnsureFundedResult`](../interfaces/types_account_manager.EnsureFundedResult.md)\> + +- The result of executing the dispensing transaction and the `amountFunded` if funds were needed. +- `undefined` if no funds were needed. + +**`Example`** + +```typescript +// Basic example +await algorand.account.ensureFunded("ACCOUNTADDRESS", "DISPENSERADDRESS", algokit.algos(1)) +// With configuration +await algorand.account.ensureFunded("ACCOUNTADDRESS", "DISPENSERADDRESS", algokit.algos(1), + { minFundingIncrement: algokit.algos(2), fee: (1000).microAlgos(), suppressLog: true } +) +``` + +#### Defined in + +[src/types/account-manager.ts:626](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/account-manager.ts#L626) + +___ + +### ensureFundedFromEnvironment + +▸ **ensureFundedFromEnvironment**(`accountToFund`, `minSpendingBalance`, `options?`): `Promise`\<`undefined` \| [`SendAtomicTransactionComposerResults`](../interfaces/types_transaction.SendAtomicTransactionComposerResults.md) & [`ConfirmedTransactionResult`](../interfaces/types_transaction.ConfirmedTransactionResult.md) & [`EnsureFundedResult`](../interfaces/types_account_manager.EnsureFundedResult.md)\> + +Funds a given account using a dispenser account retrieved from the environment, +per the `dispenserFromEnvironment` method, as a funding source such that +the given account has a certain amount of algos free to spend (accounting for +ALGOs locked in minimum balance requirement). + +**Note:** requires a Node.js environment to execute. + +The dispenser account is retrieved from the account mnemonic stored in +process.env.DISPENSER_MNEMONIC and optionally process.env.DISPENSER_SENDER +if it's a rekeyed account, or against default LocalNet if no environment variables present. + +https://developer.algorand.org/docs/get-details/accounts/#minimum-balance + +#### Parameters + +| Name | Type | Description | +| :------ | :------ | :------ | +| `accountToFund` | `string` \| [`TransactionSignerAccount`](../interfaces/types_account.TransactionSignerAccount.md) | The account to fund | +| `minSpendingBalance` | [`AlgoAmount`](types_amount.AlgoAmount.md) | The minimum balance of ALGOs that the account should have available to spend (i.e. on top of minimum balance requirement) | +| `options?` | \{ `minFundingIncrement?`: [`AlgoAmount`](types_amount.AlgoAmount.md) } & [`ExecuteParams`](../interfaces/types_composer.ExecuteParams.md) & `Omit`\<[`CommonTransactionParams`](../modules/types_composer.md#commontransactionparams), ``"sender"``\> | Optional parameters to control the funding increment, transaction or execution of the transaction | + +#### Returns + +`Promise`\<`undefined` \| [`SendAtomicTransactionComposerResults`](../interfaces/types_transaction.SendAtomicTransactionComposerResults.md) & [`ConfirmedTransactionResult`](../interfaces/types_transaction.ConfirmedTransactionResult.md) & [`EnsureFundedResult`](../interfaces/types_account_manager.EnsureFundedResult.md)\> + +- The result of executing the dispensing transaction and the `amountFunded` if funds were needed. +- `undefined` if no funds were needed. + +**`Example`** + +```typescript +// Basic example +await algorand.account.ensureFundedFromEnvironment("ACCOUNTADDRESS", algokit.algos(1)) +// With configuration +await algorand.account.ensureFundedFromEnvironment("ACCOUNTADDRESS", algokit.algos(1), + { minFundingIncrement: algokit.algos(2), fee: (1000).microAlgos(), suppressLog: true } +) +``` + +#### Defined in + +[src/types/account-manager.ts:688](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/account-manager.ts#L688) + +___ + +### ensureFundedFromTestNetDispenserApi + +▸ **ensureFundedFromTestNetDispenserApi**(`accountToFund`, `dispenserClient`, `minSpendingBalance`, `options`): `Promise`\<`undefined` \| [`EnsureFundedResult`](../interfaces/types_account_manager.EnsureFundedResult.md)\> + +Funds a given account using the TestNet Dispenser API as a funding source such that +the account has a certain amount of algos free to spend (accounting for ALGOs locked +in minimum balance requirement). + +https://developer.algorand.org/docs/get-details/accounts/#minimum-balance + +#### Parameters + +| Name | Type | Description | +| :------ | :------ | :------ | +| `accountToFund` | `string` \| [`TransactionSignerAccount`](../interfaces/types_account.TransactionSignerAccount.md) | The account to fund | +| `dispenserClient` | [`TestNetDispenserApiClient`](types_dispenser_client.TestNetDispenserApiClient.md) | The TestNet dispenser funding client | +| `minSpendingBalance` | [`AlgoAmount`](types_amount.AlgoAmount.md) | The minimum balance of ALGOs that the account should have available to spend (i.e. on top of minimum balance requirement) | +| `options` | `Object` | Optional parameters to control the funding increment, transaction or execution of the transaction | +| `options.minFundingIncrement?` | [`AlgoAmount`](types_amount.AlgoAmount.md) | - | + +#### Returns + +`Promise`\<`undefined` \| [`EnsureFundedResult`](../interfaces/types_account_manager.EnsureFundedResult.md)\> + +- The result of executing the dispensing transaction and the `amountFunded` if funds were needed. +- `undefined` if no funds were needed. + +**`Example`** + +```typescript +// Basic example +await algorand.account.ensureFundedUsingDispenserAPI("ACCOUNTADDRESS", algorand.client.getTestNetDispenserFromEnvironment(), algokit.algos(1)) +// With configuration +await algorand.account.ensureFundedUsingDispenserAPI("ACCOUNTADDRESS", algorand.client.getTestNetDispenserFromEnvironment(), algokit.algos(1), + { minFundingIncrement: algokit.algos(2) } +) +``` + +#### Defined in + +[src/types/account-manager.ts:744](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/account-manager.ts#L744) ___ @@ -204,7 +463,7 @@ If not running against LocalNet then it will use proces.env.MY_ACCOUNT_MNEMONIC #### Defined in -[src/types/account-manager.ts:302](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/account-manager.ts#L302) +[src/types/account-manager.ts:322](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/account-manager.ts#L322) ___ @@ -238,7 +497,7 @@ const defaultDispenserAccount = await account.fromKmd('unencrypted-default-walle #### Defined in -[src/types/account-manager.ts:338](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/account-manager.ts#L338) +[src/types/account-manager.ts:358](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/account-manager.ts#L358) ___ @@ -270,7 +529,7 @@ const rekeyedAccount = accountManager.fromMnemonic("mnemonic secret ...", "SENDE #### Defined in -[src/types/account-manager.ts:254](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/account-manager.ts#L254) +[src/types/account-manager.ts:274](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/account-manager.ts#L274) ___ @@ -305,7 +564,7 @@ const account = accountManager.getAccount(sender) #### Defined in -[src/types/account-manager.ts:169](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/account-manager.ts#L169) +[src/types/account-manager.ts:189](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/account-manager.ts#L189) ___ @@ -340,7 +599,7 @@ const accountInfo = await accountManager.getAssetInformation(address, assetId); #### Defined in -[src/types/account-manager.ts:228](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/account-manager.ts#L228) +[src/types/account-manager.ts:248](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/account-manager.ts#L248) ___ @@ -373,7 +632,7 @@ const accountInfo = await accountManager.getInformation(address); #### Defined in -[src/types/account-manager.ts:188](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/account-manager.ts#L188) +[src/types/account-manager.ts:208](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/account-manager.ts#L208) ___ @@ -406,7 +665,7 @@ const signer = accountManager.getSigner("SENDERADDRESS") #### Defined in -[src/types/account-manager.ts:149](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/account-manager.ts#L149) +[src/types/account-manager.ts:169](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/account-manager.ts#L169) ___ @@ -430,7 +689,7 @@ const account = await account.localNetDispenser() #### Defined in -[src/types/account-manager.ts:428](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/account-manager.ts#L428) +[src/types/account-manager.ts:448](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/account-manager.ts#L448) ___ @@ -461,7 +720,7 @@ const account = account.logicsig(program, [new Uint8Array(3, ...)]) #### Defined in -[src/types/account-manager.ts:376](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/account-manager.ts#L376) +[src/types/account-manager.ts:396](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/account-manager.ts#L396) ___ @@ -493,7 +752,7 @@ const account = accountManager.multisig({version: 1, threshold: 1, addrs: ["ADDR #### Defined in -[src/types/account-manager.ts:361](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/account-manager.ts#L361) +[src/types/account-manager.ts:381](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/account-manager.ts#L381) ___ @@ -517,7 +776,7 @@ const account = account.random() #### Defined in -[src/types/account-manager.ts:389](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/account-manager.ts#L389) +[src/types/account-manager.ts:409](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/account-manager.ts#L409) ___ @@ -549,7 +808,7 @@ const rekeyedAccount = accountManager.rekeyed(account, "SENDERADDRESS...") #### Defined in -[src/types/account-manager.ts:271](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/account-manager.ts#L271) +[src/types/account-manager.ts:291](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/account-manager.ts#L291) ___ @@ -586,7 +845,7 @@ const signer = accountManager.getSigner("{SENDERADDRESS}") #### Defined in -[src/types/account-manager.ts:77](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/account-manager.ts#L77) +[src/types/account-manager.ts:97](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/account-manager.ts#L97) ___ @@ -618,7 +877,7 @@ const accountManager = new AccountManager(clientManager) #### Defined in -[src/types/account-manager.ts:131](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/account-manager.ts#L131) +[src/types/account-manager.ts:151](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/account-manager.ts#L151) ___ @@ -656,7 +915,7 @@ const accountManager = new AccountManager(clientManager) #### Defined in -[src/types/account-manager.ts:115](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/account-manager.ts#L115) +[src/types/account-manager.ts:135](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/account-manager.ts#L135) ___ @@ -685,4 +944,4 @@ retrieval and returns a `TransactionSignerAccount` along with the original accou #### Defined in -[src/types/account-manager.ts:86](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/account-manager.ts#L86) +[src/types/account-manager.ts:106](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/account-manager.ts#L106) diff --git a/docs/code/classes/types_algorand_client.AlgorandClient.md b/docs/code/classes/types_algorand_client.AlgorandClient.md index 33820e47..a02bc4b6 100644 --- a/docs/code/classes/types_algorand_client.AlgorandClient.md +++ b/docs/code/classes/types_algorand_client.AlgorandClient.md @@ -65,7 +65,7 @@ A client that brokers easy access to Algorand functionality. #### Defined in -[src/types/algorand-client.ts:27](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/algorand-client.ts#L27) +[src/types/algorand-client.ts:29](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/algorand-client.ts#L29) ## Properties @@ -75,7 +75,7 @@ A client that brokers easy access to Algorand functionality. #### Defined in -[src/types/algorand-client.ts:19](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/algorand-client.ts#L19) +[src/types/algorand-client.ts:21](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/algorand-client.ts#L21) ___ @@ -85,7 +85,7 @@ ___ #### Defined in -[src/types/algorand-client.ts:21](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/algorand-client.ts#L21) +[src/types/algorand-client.ts:23](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/algorand-client.ts#L23) ___ @@ -95,7 +95,7 @@ ___ #### Defined in -[src/types/algorand-client.ts:22](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/algorand-client.ts#L22) +[src/types/algorand-client.ts:24](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/algorand-client.ts#L24) ___ @@ -105,7 +105,7 @@ ___ #### Defined in -[src/types/algorand-client.ts:23](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/algorand-client.ts#L23) +[src/types/algorand-client.ts:25](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/algorand-client.ts#L25) ___ @@ -115,7 +115,7 @@ ___ #### Defined in -[src/types/algorand-client.ts:18](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/algorand-client.ts#L18) +[src/types/algorand-client.ts:20](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/algorand-client.ts#L20) ___ @@ -125,7 +125,7 @@ ___ #### Defined in -[src/types/algorand-client.ts:25](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/algorand-client.ts#L25) +[src/types/algorand-client.ts:27](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/algorand-client.ts#L27) ___ @@ -139,20 +139,22 @@ Methods for sending a single transaction. | Name | Type | Description | | :------ | :------ | :------ | -| `appCall` | (`params`: [`AppCallParams`](../modules/types_composer.md#appcallparams), `config?`: [`ExecuteParams`](../interfaces/types_composer.ExecuteParams.md)) => `Promise`\<[`SendSingleTransactionResult`](../modules/types_algorand_client.md#sendsingletransactionresult)\> | - | -| `assetConfig` | (`params`: [`AssetConfigParams`](../modules/types_composer.md#assetconfigparams), `config?`: [`ExecuteParams`](../interfaces/types_composer.ExecuteParams.md)) => `Promise`\<[`SendSingleTransactionResult`](../modules/types_algorand_client.md#sendsingletransactionresult)\> | - | -| `assetCreate` | (`params`: [`AssetCreateParams`](../modules/types_composer.md#assetcreateparams), `config?`: [`ExecuteParams`](../interfaces/types_composer.ExecuteParams.md)) => `Promise`\<[`SendSingleTransactionResult`](../modules/types_algorand_client.md#sendsingletransactionresult)\> | - | -| `assetDestroy` | (`params`: [`AssetDestroyParams`](../modules/types_composer.md#assetdestroyparams), `config?`: [`ExecuteParams`](../interfaces/types_composer.ExecuteParams.md)) => `Promise`\<[`SendSingleTransactionResult`](../modules/types_algorand_client.md#sendsingletransactionresult)\> | - | -| `assetFreeze` | (`params`: [`AssetFreezeParams`](../modules/types_composer.md#assetfreezeparams), `config?`: [`ExecuteParams`](../interfaces/types_composer.ExecuteParams.md)) => `Promise`\<[`SendSingleTransactionResult`](../modules/types_algorand_client.md#sendsingletransactionresult)\> | - | -| `assetOptIn` | (`params`: [`AssetOptInParams`](../modules/types_composer.md#assetoptinparams), `config?`: [`ExecuteParams`](../interfaces/types_composer.ExecuteParams.md)) => `Promise`\<[`SendSingleTransactionResult`](../modules/types_algorand_client.md#sendsingletransactionresult)\> | - | -| `assetTransfer` | (`params`: [`AssetTransferParams`](../modules/types_composer.md#assettransferparams), `config?`: [`ExecuteParams`](../interfaces/types_composer.ExecuteParams.md)) => `Promise`\<[`SendSingleTransactionResult`](../modules/types_algorand_client.md#sendsingletransactionresult)\> | - | -| `methodCall` | (`params`: [`MethodCallParams`](../modules/types_composer.md#methodcallparams), `config?`: [`ExecuteParams`](../interfaces/types_composer.ExecuteParams.md)) => `Promise`\<[`SendSingleTransactionResult`](../modules/types_algorand_client.md#sendsingletransactionresult)\> | - | -| `onlineKeyRegistration` | (`params`: [`OnlineKeyRegistrationParams`](../modules/types_composer.md#onlinekeyregistrationparams), `config?`: [`ExecuteParams`](../interfaces/types_composer.ExecuteParams.md)) => `Promise`\<[`SendSingleTransactionResult`](../modules/types_algorand_client.md#sendsingletransactionresult)\> | - | -| `payment` | (`params`: [`PaymentParams`](../modules/types_composer.md#paymentparams), `config?`: [`ExecuteParams`](../interfaces/types_composer.ExecuteParams.md)) => `Promise`\<[`SendSingleTransactionResult`](../modules/types_algorand_client.md#sendsingletransactionresult)\> | - | +| `appCall` | (`params`: [`CommonTransactionParams`](../modules/types_composer.md#commontransactionparams) & \{ `accountReferences?`: `string`[] ; `appId?`: `bigint` ; `appReferences?`: `bigint`[] ; `approvalProgram?`: `Uint8Array` ; `args?`: `Uint8Array`[] ; `assetReferences?`: `bigint`[] ; `boxReferences?`: `BoxReference`[] ; `clearProgram?`: `Uint8Array` ; `extraPages?`: `number` ; `onComplete?`: `OnApplicationComplete` ; `schema?`: \{ `globalByteSlices`: `number` ; `globalUints`: `number` ; `localByteSlices`: `number` ; `localUints`: `number` } } & [`ExecuteParams`](../interfaces/types_composer.ExecuteParams.md)) => `Promise`\<[`SendSingleTransactionResult`](../modules/types_algorand_client.md#sendsingletransactionresult)\> | - | +| `assetConfig` | (`params`: [`CommonTransactionParams`](../modules/types_composer.md#commontransactionparams) & \{ `assetId`: `bigint` ; `clawback?`: `string` ; `freeze?`: `string` ; `manager?`: `string` ; `reserve?`: `string` } & [`ExecuteParams`](../interfaces/types_composer.ExecuteParams.md)) => `Promise`\<[`SendSingleTransactionResult`](../modules/types_algorand_client.md#sendsingletransactionresult)\> | - | +| `assetCreate` | (`params`: [`CommonTransactionParams`](../modules/types_composer.md#commontransactionparams) & \{ `assetName?`: `string` ; `clawback?`: `string` ; `decimals?`: `number` ; `defaultFrozen?`: `boolean` ; `freeze?`: `string` ; `manager?`: `string` ; `metadataHash?`: `string` \| `Uint8Array` ; `reserve?`: `string` ; `total`: `bigint` ; `unitName?`: `string` ; `url?`: `string` } & [`ExecuteParams`](../interfaces/types_composer.ExecuteParams.md)) => `Promise`\<[`SendSingleTransactionResult`](../modules/types_algorand_client.md#sendsingletransactionresult)\> | - | +| `assetDestroy` | (`params`: [`CommonTransactionParams`](../modules/types_composer.md#commontransactionparams) & \{ `assetId`: `bigint` } & [`ExecuteParams`](../interfaces/types_composer.ExecuteParams.md)) => `Promise`\<[`SendSingleTransactionResult`](../modules/types_algorand_client.md#sendsingletransactionresult)\> | - | +| `assetFreeze` | (`params`: [`CommonTransactionParams`](../modules/types_composer.md#commontransactionparams) & \{ `account`: `string` ; `assetId`: `bigint` ; `frozen`: `boolean` } & [`ExecuteParams`](../interfaces/types_composer.ExecuteParams.md)) => `Promise`\<[`SendSingleTransactionResult`](../modules/types_algorand_client.md#sendsingletransactionresult)\> | - | +| `assetOptIn` | (`params`: [`CommonTransactionParams`](../modules/types_composer.md#commontransactionparams) & \{ `assetId`: `bigint` } & [`ExecuteParams`](../interfaces/types_composer.ExecuteParams.md)) => `Promise`\<[`SendSingleTransactionResult`](../modules/types_algorand_client.md#sendsingletransactionresult)\> | - | +| `assetOptOut` | (`params`: `Omit`\<[`AssetOptOutParams`](../modules/types_composer.md#assetoptoutparams), ``"creator"``\> & \{ `creator?`: `string` ; `ensureZeroBalance`: `boolean` } & [`ExecuteParams`](../interfaces/types_composer.ExecuteParams.md)) => `Promise`\<[`SendSingleTransactionResult`](../modules/types_algorand_client.md#sendsingletransactionresult)\> | - | +| `assetTransfer` | (`params`: [`CommonTransactionParams`](../modules/types_composer.md#commontransactionparams) & \{ `amount`: `bigint` ; `assetId`: `bigint` ; `clawbackTarget?`: `string` ; `closeAssetTo?`: `string` ; `receiver`: `string` } & [`ExecuteParams`](../interfaces/types_composer.ExecuteParams.md)) => `Promise`\<[`SendSingleTransactionResult`](../modules/types_algorand_client.md#sendsingletransactionresult)\> | - | +| `methodCall` | (`params`: [`CommonTransactionParams`](../modules/types_composer.md#commontransactionparams) & `Omit`\<[`AppCallParams`](../modules/types_composer.md#appcallparams), ``"args"``\> & \{ `appId`: `bigint` ; `args?`: (`TransactionWithSigner` \| `Transaction` \| `ABIValue` \| `Promise`\<`Transaction`\> \| [`MethodCallParams`](../modules/types_composer.md#methodcallparams))[] ; `method`: `ABIMethod` } & [`ExecuteParams`](../interfaces/types_composer.ExecuteParams.md)) => `Promise`\<[`SendSingleTransactionResult`](../modules/types_algorand_client.md#sendsingletransactionresult)\> | - | +| `onlineKeyRegistration` | (`params`: [`CommonTransactionParams`](../modules/types_composer.md#commontransactionparams) & \{ `selectionKey`: `Uint8Array` ; `stateProofKey?`: `Uint8Array` ; `voteFirst`: `bigint` ; `voteKey`: `Uint8Array` ; `voteKeyDilution`: `bigint` ; `voteLast`: `bigint` } & [`ExecuteParams`](../interfaces/types_composer.ExecuteParams.md)) => `Promise`\<[`SendSingleTransactionResult`](../modules/types_algorand_client.md#sendsingletransactionresult)\> | - | +| `payment` | (`params`: [`CommonTransactionParams`](../modules/types_composer.md#commontransactionparams) & \{ `amount`: [`AlgoAmount`](types_amount.AlgoAmount.md) ; `closeRemainderTo?`: `string` ; `receiver`: `string` } & [`ExecuteParams`](../interfaces/types_composer.ExecuteParams.md)) => `Promise`\<[`SendSingleTransactionResult`](../modules/types_algorand_client.md#sendsingletransactionresult)\> | - | +| `rekey` | (`params`: [`CommonTransactionParams`](../modules/types_composer.md#commontransactionparams) & \{ `rekeyTo`: `string` } & [`ExecuteParams`](../interfaces/types_composer.ExecuteParams.md)) => `Promise`\<[`SendSingleTransactionResult`](../modules/types_algorand_client.md#sendsingletransactionresult)\> | - | #### Defined in -[src/types/algorand-client.ts:169](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/algorand-client.ts#L169) +[src/types/algorand-client.ts:183](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/algorand-client.ts#L183) ___ @@ -172,14 +174,16 @@ Methods for building transactions | `assetDestroy` | (`params`: [`AssetDestroyParams`](../modules/types_composer.md#assetdestroyparams)) => `Promise`\<`Transaction`\> | - | | `assetFreeze` | (`params`: [`AssetFreezeParams`](../modules/types_composer.md#assetfreezeparams)) => `Promise`\<`Transaction`\> | - | | `assetOptIn` | (`params`: [`AssetOptInParams`](../modules/types_composer.md#assetoptinparams)) => `Promise`\<`Transaction`\> | - | +| `assetOptOut` | (`params`: [`AssetOptOutParams`](../modules/types_composer.md#assetoptoutparams)) => `Promise`\<`Transaction`\> | - | | `assetTransfer` | (`params`: [`AssetTransferParams`](../modules/types_composer.md#assettransferparams)) => `Promise`\<`Transaction`\> | - | | `methodCall` | (`params`: [`MethodCallParams`](../modules/types_composer.md#methodcallparams)) => `Promise`\<`Transaction`[]\> | - | | `onlineKeyRegistration` | (`params`: [`OnlineKeyRegistrationParams`](../modules/types_composer.md#onlinekeyregistrationparams)) => `Promise`\<`Transaction`\> | - | | `payment` | (`params`: [`PaymentParams`](../modules/types_composer.md#paymentparams)) => `Promise`\<`Transaction`\> | - | +| `rekey` | (`params`: [`RekeyParams`](../modules/types_composer.md#rekeyparams)) => `Promise`\<`Transaction`\> | - | #### Defined in -[src/types/algorand-client.ts:245](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/algorand-client.ts#L245) +[src/types/algorand-client.ts:370](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/algorand-client.ts#L370) ## Accessors @@ -195,7 +199,7 @@ Get or create accounts that can sign transactions. #### Defined in -[src/types/algorand-client.ts:117](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/algorand-client.ts#L117) +[src/types/algorand-client.ts:131](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/algorand-client.ts#L131) ___ @@ -211,13 +215,13 @@ Get clients, including algosdk clients and app clients. #### Defined in -[src/types/algorand-client.ts:112](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/algorand-client.ts#L112) +[src/types/algorand-client.ts:126](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/algorand-client.ts#L126) ## Methods ### \_send -▸ **_send**\<`T`\>(`c`, `log?`): (`params`: `T`, `config?`: [`ExecuteParams`](../interfaces/types_composer.ExecuteParams.md)) => `Promise`\<[`SendSingleTransactionResult`](../modules/types_algorand_client.md#sendsingletransactionresult)\> +▸ **_send**\<`T`\>(`c`, `log?`): (`params`: `T` & [`ExecuteParams`](../interfaces/types_composer.ExecuteParams.md)) => `Promise`\<[`SendSingleTransactionResult`](../modules/types_algorand_client.md#sendsingletransactionresult)\> #### Type parameters @@ -238,14 +242,13 @@ Get clients, including algosdk clients and app clients. `fn` -▸ (`params`, `config?`): `Promise`\<[`SendSingleTransactionResult`](../modules/types_algorand_client.md#sendsingletransactionresult)\> +▸ (`params`): `Promise`\<[`SendSingleTransactionResult`](../modules/types_algorand_client.md#sendsingletransactionresult)\> ##### Parameters | Name | Type | | :------ | :------ | -| `params` | `T` | -| `config?` | [`ExecuteParams`](../interfaces/types_composer.ExecuteParams.md) | +| `params` | `T` & [`ExecuteParams`](../interfaces/types_composer.ExecuteParams.md) | ##### Returns @@ -253,7 +256,7 @@ Get clients, including algosdk clients and app clients. #### Defined in -[src/types/algorand-client.ts:131](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/algorand-client.ts#L131) +[src/types/algorand-client.ts:145](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/algorand-client.ts#L145) ___ @@ -291,7 +294,7 @@ ___ #### Defined in -[src/types/algorand-client.ts:234](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/algorand-client.ts#L234) +[src/types/algorand-client.ts:359](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/algorand-client.ts#L359) ___ @@ -307,7 +310,7 @@ Get suggested params for a transaction (either cached or from algod if the cache #### Defined in -[src/types/algorand-client.ts:96](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/algorand-client.ts#L96) +[src/types/algorand-client.ts:110](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/algorand-client.ts#L110) ___ @@ -323,7 +326,7 @@ Start a new `AlgokitComposer` transaction group #### Defined in -[src/types/algorand-client.ts:122](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/algorand-client.ts#L122) +[src/types/algorand-client.ts:136](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/algorand-client.ts#L136) ___ @@ -347,7 +350,7 @@ The `AlgorandClient` so method calls can be chained #### Defined in -[src/types/algorand-client.ts:47](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/algorand-client.ts#L47) +[src/types/algorand-client.ts:49](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/algorand-client.ts#L49) ___ @@ -371,7 +374,7 @@ The `AlgorandClient` so method calls can be chained #### Defined in -[src/types/algorand-client.ts:37](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/algorand-client.ts#L37) +[src/types/algorand-client.ts:39](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/algorand-client.ts#L39) ___ @@ -396,7 +399,7 @@ The `AlgorandClient` so method calls can be chained #### Defined in -[src/types/algorand-client.ts:68](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/algorand-client.ts#L68) +[src/types/algorand-client.ts:82](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/algorand-client.ts#L82) ___ @@ -410,7 +413,7 @@ Tracks the given account for later signing. | Name | Type | Description | | :------ | :------ | :------ | -| `account` | [`SendTransactionFrom`](../modules/types_transaction.md#sendtransactionfrom) | The account to register | +| `account` | [`MultisigAccount`](types_account.MultisigAccount.md) \| `default` \| [`SigningAccount`](types_account.SigningAccount.md) \| [`TransactionSignerAccount`](../interfaces/types_account.TransactionSignerAccount.md) \| `LogicSigAccount` | The account to register, which can be a `TransactionSignerAccount` or a `algosdk.Account`, `algosdk.LogicSigAccount`, `SigningAccount` or `MultisigAccount` | #### Returns @@ -418,9 +421,20 @@ Tracks the given account for later signing. The `AlgorandClient` so method calls can be chained +**`Example`** + +```typescript +const accountManager = AlgorandClient.mainnet() + .setSignerFromAccount(algosdk.generateAccount()) + .setSignerFromAccount(new algosdk.LogicSigAccount(program, args)) + .setSignerFromAccount(new SigningAccount(mnemonic, sender)) + .setSignerFromAccount(new MultisigAccount({version: 1, threshold: 1, addrs: ["ADDRESS1...", "ADDRESS2..."]}, [account1, account2])) + .setSignerFromAccount({addr: "SENDERADDRESS", signer: transactionSigner}) +``` + #### Defined in -[src/types/algorand-client.ts:57](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/algorand-client.ts#L57) +[src/types/algorand-client.ts:69](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/algorand-client.ts#L69) ___ @@ -445,7 +459,7 @@ The `AlgorandClient` so method calls can be chained #### Defined in -[src/types/algorand-client.ts:79](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/algorand-client.ts#L79) +[src/types/algorand-client.ts:93](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/algorand-client.ts#L93) ___ @@ -469,7 +483,7 @@ The `AlgorandClient` so method calls can be chained #### Defined in -[src/types/algorand-client.ts:90](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/algorand-client.ts#L90) +[src/types/algorand-client.ts:104](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/algorand-client.ts#L104) ___ @@ -487,7 +501,7 @@ The `AlgorandClient` #### Defined in -[src/types/algorand-client.ts:276](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/algorand-client.ts#L276) +[src/types/algorand-client.ts:465](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/algorand-client.ts#L465) ___ @@ -511,7 +525,7 @@ The `AlgorandClient` #### Defined in -[src/types/algorand-client.ts:313](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/algorand-client.ts#L313) +[src/types/algorand-client.ts:502](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/algorand-client.ts#L502) ___ @@ -535,7 +549,7 @@ The `AlgorandClient` #### Defined in -[src/types/algorand-client.ts:343](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/algorand-client.ts#L343) +[src/types/algorand-client.ts:532](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/algorand-client.ts#L532) ___ @@ -566,7 +580,7 @@ The `AlgorandClient` #### Defined in -[src/types/algorand-client.ts:334](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/algorand-client.ts#L334) +[src/types/algorand-client.ts:523](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/algorand-client.ts#L523) ___ @@ -584,7 +598,7 @@ The `AlgorandClient` #### Defined in -[src/types/algorand-client.ts:300](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/algorand-client.ts#L300) +[src/types/algorand-client.ts:489](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/algorand-client.ts#L489) ___ @@ -602,4 +616,4 @@ The `AlgorandClient` #### Defined in -[src/types/algorand-client.ts:288](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/algorand-client.ts#L288) +[src/types/algorand-client.ts:477](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/algorand-client.ts#L477) diff --git a/docs/code/classes/types_client_manager.ClientManager.md b/docs/code/classes/types_client_manager.ClientManager.md index 5ccf2c2f..e7f85f72 100644 --- a/docs/code/classes/types_client_manager.ClientManager.md +++ b/docs/code/classes/types_client_manager.ClientManager.md @@ -30,6 +30,7 @@ Exposes access to various API clients. - [getAppClientByCreatorAndName](types_client_manager.ClientManager.md#getappclientbycreatorandname) - [getAppClientById](types_client_manager.ClientManager.md#getappclientbyid) - [getTestNetDispenser](types_client_manager.ClientManager.md#gettestnetdispenser) +- [getTestNetDispenserFromEnvironment](types_client_manager.ClientManager.md#gettestnetdispenserfromenvironment) - [getTypedAppClientByCreatorAndName](types_client_manager.ClientManager.md#gettypedappclientbycreatorandname) - [getTypedAppClientById](types_client_manager.ClientManager.md#gettypedappclientbyid) - [isLocalNet](types_client_manager.ClientManager.md#islocalnet) @@ -206,7 +207,7 @@ The `ApplicationClient` #### Defined in -[src/types/client-manager.ts:185](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/client-manager.ts#L185) +[src/types/client-manager.ts:204](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/client-manager.ts#L204) ___ @@ -230,22 +231,23 @@ The `ApplicationClient` #### Defined in -[src/types/client-manager.ts:197](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/client-manager.ts#L197) +[src/types/client-manager.ts:216](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/client-manager.ts#L216) ___ ### getTestNetDispenser -▸ **getTestNetDispenser**(`params?`): [`TestNetDispenserApiClient`](types_dispenser_client.TestNetDispenserApiClient.md) +▸ **getTestNetDispenser**(`params`): [`TestNetDispenserApiClient`](types_dispenser_client.TestNetDispenserApiClient.md) Returns a TestNet Dispenser API client. + Refer to [docs](https://github.com/algorandfoundation/algokit/blob/main/docs/testnet_api.md) on guidance to obtain an access token. #### Parameters -| Name | Type | Default value | Description | -| :------ | :------ | :------ | :------ | -| `params` | ``null`` \| [`TestNetDispenserApiClientParams`](../interfaces/types_dispenser_client.TestNetDispenserApiClientParams.md) | `null` | An object containing parameters for the TestNetDispenserApiClient class. Or null if you want the client to load the access token from the environment variable `ALGOKIT_DISPENSER_ACCESS_TOKEN`. | +| Name | Type | Description | +| :------ | :------ | :------ | +| `params` | [`TestNetDispenserApiClientParams`](../interfaces/types_dispenser_client.TestNetDispenserApiClientParams.md) | An object containing parameters for the TestNetDispenserApiClient class. | #### Returns @@ -270,6 +272,42 @@ const client = clientManager.getTestNetDispenser( ___ +### getTestNetDispenserFromEnvironment + +▸ **getTestNetDispenserFromEnvironment**(`params?`): [`TestNetDispenserApiClient`](types_dispenser_client.TestNetDispenserApiClient.md) + +Returns a TestNet Dispenser API client, loading the auth token from `process.env.ALGOKIT_DISPENSER_ACCESS_TOKEN`. + +Refer to [docs](https://github.com/algorandfoundation/algokit/blob/main/docs/testnet_api.md) on guidance to obtain an access token. + +#### Parameters + +| Name | Type | Description | +| :------ | :------ | :------ | +| `params?` | `Omit`\<[`TestNetDispenserApiClientParams`](../interfaces/types_dispenser_client.TestNetDispenserApiClientParams.md), ``"authToken"``\> | An object containing parameters for the TestNetDispenserApiClient class. | + +#### Returns + +[`TestNetDispenserApiClient`](types_dispenser_client.TestNetDispenserApiClient.md) + +An instance of the TestNetDispenserApiClient class. + +**`Example`** + +```ts +const client = clientManager.getTestNetDispenserFromEnvironment( + { + requestTimeout: 15, + } +) +``` + +#### Defined in + +[src/types/client-manager.ts:194](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/client-manager.ts#L194) + +___ + ### getTypedAppClientByCreatorAndName ▸ **getTypedAppClientByCreatorAndName**\<`TClient`\>(`typedClient`, `details`, `cachedAppLookup?`): `TClient` @@ -298,7 +336,7 @@ The typed client instance #### Defined in -[src/types/client-manager.ts:208](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/client-manager.ts#L208) +[src/types/client-manager.ts:227](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/client-manager.ts#L227) ___ @@ -329,7 +367,7 @@ The typed client instance #### Defined in -[src/types/client-manager.ts:222](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/client-manager.ts#L222) +[src/types/client-manager.ts:241](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/client-manager.ts#L241) ___ @@ -455,7 +493,7 @@ Returns the Algorand configuration to point to the free tier of the AlgoNode ser #### Defined in -[src/types/client-manager.ts:314](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/client-manager.ts#L314) +[src/types/client-manager.ts:333](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/client-manager.ts#L333) ___ @@ -498,7 +536,7 @@ Returns an algod SDK client that automatically retries on idempotent calls. #### Defined in -[src/types/client-manager.ts:353](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/client-manager.ts#L353) +[src/types/client-manager.ts:372](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/client-manager.ts#L372) ___ @@ -522,7 +560,7 @@ Returns an algod SDK client that automatically retries on idempotent calls loade #### Defined in -[src/types/client-manager.ts:370](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/client-manager.ts#L370) +[src/types/client-manager.ts:389](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/client-manager.ts#L389) ___ @@ -540,7 +578,7 @@ Expects `process.env.ALGOD_SERVER` to be defined, and you can also specify `proc #### Defined in -[src/types/client-manager.ts:272](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/client-manager.ts#L272) +[src/types/client-manager.ts:291](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/client-manager.ts#L291) ___ @@ -573,7 +611,7 @@ const config = ClientManager.getConfigFromEnvironmentOrLocalNet() #### Defined in -[src/types/client-manager.ts:243](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/client-manager.ts#L243) +[src/types/client-manager.ts:262](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/client-manager.ts#L262) ___ @@ -595,7 +633,7 @@ Returns the Algorand configuration to point to the default LocalNet. #### Defined in -[src/types/client-manager.ts:325](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/client-manager.ts#L325) +[src/types/client-manager.ts:344](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/client-manager.ts#L344) ___ @@ -645,7 +683,7 @@ Returns an indexer SDK client that automatically retries on idempotent calls #### Defined in -[src/types/client-manager.ts:399](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/client-manager.ts#L399) +[src/types/client-manager.ts:418](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/client-manager.ts#L418) ___ @@ -675,7 +713,7 @@ Returns an indexer SDK client that automatically retries on idempotent calls loa #### Defined in -[src/types/client-manager.ts:421](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/client-manager.ts#L421) +[src/types/client-manager.ts:440](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/client-manager.ts#L440) ___ @@ -693,7 +731,7 @@ Expects `process.env.INDEXER_SERVER` to be defined, and you can also specify `pr #### Defined in -[src/types/client-manager.ts:293](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/client-manager.ts#L293) +[src/types/client-manager.ts:312](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/client-manager.ts#L312) ___ @@ -723,7 +761,7 @@ KMD client allows you to export private keys, which is useful to (for instance) #### Defined in -[src/types/client-manager.ts:436](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/client-manager.ts#L436) +[src/types/client-manager.ts:455](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/client-manager.ts#L455) ___ @@ -746,4 +784,4 @@ Returns a KMD SDK client that automatically retries on idempotent calls loaded f #### Defined in -[src/types/client-manager.ts:450](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/client-manager.ts#L450) +[src/types/client-manager.ts:469](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/client-manager.ts#L469) diff --git a/docs/code/classes/types_composer.default.md b/docs/code/classes/types_composer.default.md index e8b42de1..862437c2 100644 --- a/docs/code/classes/types_composer.default.md +++ b/docs/code/classes/types_composer.default.md @@ -33,11 +33,13 @@ Note: this class is a new Beta feature and may be subject to change. - [addAssetDestroy](types_composer.default.md#addassetdestroy) - [addAssetFreeze](types_composer.default.md#addassetfreeze) - [addAssetOptIn](types_composer.default.md#addassetoptin) +- [addAssetOptOut](types_composer.default.md#addassetoptout) - [addAssetTransfer](types_composer.default.md#addassettransfer) - [addAtc](types_composer.default.md#addatc) - [addMethodCall](types_composer.default.md#addmethodcall) - [addOnlineKeyRegistration](types_composer.default.md#addonlinekeyregistration) - [addPayment](types_composer.default.md#addpayment) +- [addRekey](types_composer.default.md#addrekey) - [build](types_composer.default.md#build) - [buildAppCall](types_composer.default.md#buildappcall) - [buildAssetConfig](types_composer.default.md#buildassetconfig) @@ -74,7 +76,7 @@ Create an `AlgoKitComposer`. #### Defined in -[src/types/composer.ts:273](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/composer.ts#L273) +[src/types/composer.ts:386](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/composer.ts#L386) ## Properties @@ -86,7 +88,7 @@ The algod client used by the composer. #### Defined in -[src/types/composer.ts:255](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/composer.ts#L255) +[src/types/composer.ts:368](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/composer.ts#L368) ___ @@ -98,7 +100,7 @@ The ATC used to compose the group #### Defined in -[src/types/composer.ts:246](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/composer.ts#L246) +[src/types/composer.ts:359](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/composer.ts#L359) ___ @@ -110,7 +112,7 @@ The default transaction validity window #### Defined in -[src/types/composer.ts:264](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/composer.ts#L264) +[src/types/composer.ts:377](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/composer.ts#L377) ___ @@ -122,7 +124,7 @@ Whether the validity window was explicitly set on construction #### Defined in -[src/types/composer.ts:267](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/composer.ts#L267) +[src/types/composer.ts:380](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/composer.ts#L380) ___ @@ -148,7 +150,7 @@ A function that takes in an address and return a signer function for that addres #### Defined in -[src/types/composer.ts:261](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/composer.ts#L261) +[src/types/composer.ts:374](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/composer.ts#L374) ___ @@ -168,7 +170,7 @@ An async function that will return suggestedParams. #### Defined in -[src/types/composer.ts:258](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/composer.ts#L258) +[src/types/composer.ts:371](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/composer.ts#L371) ___ @@ -180,7 +182,7 @@ Map of txid to ABI method #### Defined in -[src/types/composer.ts:249](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/composer.ts#L249) +[src/types/composer.ts:362](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/composer.ts#L362) ___ @@ -192,7 +194,7 @@ Transactions that have not yet been composed #### Defined in -[src/types/composer.ts:252](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/composer.ts#L252) +[src/types/composer.ts:365](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/composer.ts#L365) ## Methods @@ -218,7 +220,7 @@ The composer so you can chain method calls #### Defined in -[src/types/composer.ts:366](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/composer.ts#L366) +[src/types/composer.ts:503](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/composer.ts#L503) ___ @@ -242,7 +244,7 @@ The composer so you can chain method calls #### Defined in -[src/types/composer.ts:309](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/composer.ts#L309) +[src/types/composer.ts:435](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/composer.ts#L435) ___ @@ -266,7 +268,7 @@ The composer so you can chain method calls #### Defined in -[src/types/composer.ts:298](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/composer.ts#L298) +[src/types/composer.ts:424](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/composer.ts#L424) ___ @@ -290,7 +292,7 @@ The composer so you can chain method calls #### Defined in -[src/types/composer.ts:331](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/composer.ts#L331) +[src/types/composer.ts:457](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/composer.ts#L457) ___ @@ -314,7 +316,7 @@ The composer so you can chain method calls #### Defined in -[src/types/composer.ts:320](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/composer.ts#L320) +[src/types/composer.ts:446](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/composer.ts#L446) ___ @@ -338,7 +340,31 @@ The composer so you can chain method calls #### Defined in -[src/types/composer.ts:353](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/composer.ts#L353) +[src/types/composer.ts:479](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/composer.ts#L479) + +___ + +### addAssetOptOut + +▸ **addAssetOptOut**(`params`): [`default`](types_composer.default.md) + +Add an asset opt-out transaction to the transaction group. + +#### Parameters + +| Name | Type | Description | +| :------ | :------ | :------ | +| `params` | [`AssetOptOutParams`](../modules/types_composer.md#assetoptoutparams) | The asset opt-out transaction parameters | + +#### Returns + +[`default`](types_composer.default.md) + +The composer so you can chain method calls + +#### Defined in + +[src/types/composer.ts:490](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/composer.ts#L490) ___ @@ -362,7 +388,7 @@ The composer so you can chain method calls #### Defined in -[src/types/composer.ts:342](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/composer.ts#L342) +[src/types/composer.ts:468](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/composer.ts#L468) ___ @@ -386,7 +412,7 @@ The composer so you can chain method calls #### Defined in -[src/types/composer.ts:400](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/composer.ts#L400) +[src/types/composer.ts:537](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/composer.ts#L537) ___ @@ -412,7 +438,7 @@ The composer so you can chain method calls #### Defined in -[src/types/composer.ts:379](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/composer.ts#L379) +[src/types/composer.ts:516](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/composer.ts#L516) ___ @@ -436,7 +462,7 @@ The composer so you can chain method calls #### Defined in -[src/types/composer.ts:389](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/composer.ts#L389) +[src/types/composer.ts:526](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/composer.ts#L526) ___ @@ -446,6 +472,8 @@ ___ Add a payment transaction to the transaction group. +**Warning:** Please be careful with this parameter and be sure to read the [official rekey guidance](https://developer.algorand.org/docs/get-details/accounts/rekey/). + #### Parameters | Name | Type | Description | @@ -460,7 +488,31 @@ The composer so you can chain method calls #### Defined in -[src/types/composer.ts:287](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/composer.ts#L287) +[src/types/composer.ts:402](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/composer.ts#L402) + +___ + +### addRekey + +▸ **addRekey**(`params`): [`default`](types_composer.default.md) + +Add a rekey transaction to the transaction group. + +#### Parameters + +| Name | Type | Description | +| :------ | :------ | :------ | +| `params` | [`RekeyParams`](../modules/types_composer.md#rekeyparams) | The rekey transaction parameters | + +#### Returns + +[`default`](types_composer.default.md) + +The composer so you can chain method calls + +#### Defined in + +[src/types/composer.ts:413](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/composer.ts#L413) ___ @@ -480,7 +532,7 @@ The built atomic transaction composer and the transactions #### Defined in -[src/types/composer.ts:738](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/composer.ts#L738) +[src/types/composer.ts:886](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/composer.ts#L886) ___ @@ -501,7 +553,7 @@ ___ #### Defined in -[src/types/composer.ts:617](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/composer.ts#L617) +[src/types/composer.ts:754](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/composer.ts#L754) ___ @@ -522,7 +574,7 @@ ___ #### Defined in -[src/types/composer.ts:566](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/composer.ts#L566) +[src/types/composer.ts:703](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/composer.ts#L703) ___ @@ -543,7 +595,7 @@ ___ #### Defined in -[src/types/composer.ts:546](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/composer.ts#L546) +[src/types/composer.ts:683](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/composer.ts#L683) ___ @@ -564,7 +616,7 @@ ___ #### Defined in -[src/types/composer.ts:581](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/composer.ts#L581) +[src/types/composer.ts:718](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/composer.ts#L718) ___ @@ -585,7 +637,7 @@ ___ #### Defined in -[src/types/composer.ts:591](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/composer.ts#L591) +[src/types/composer.ts:728](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/composer.ts#L728) ___ @@ -606,7 +658,7 @@ ___ #### Defined in -[src/types/composer.ts:603](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/composer.ts#L603) +[src/types/composer.ts:740](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/composer.ts#L740) ___ @@ -626,7 +678,7 @@ ___ #### Defined in -[src/types/composer.ts:405](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/composer.ts#L405) +[src/types/composer.ts:542](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/composer.ts#L542) ___ @@ -647,7 +699,7 @@ ___ #### Defined in -[src/types/composer.ts:657](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/composer.ts#L657) +[src/types/composer.ts:794](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/composer.ts#L794) ___ @@ -668,7 +720,7 @@ ___ #### Defined in -[src/types/composer.ts:460](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/composer.ts#L460) +[src/types/composer.ts:597](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/composer.ts#L597) ___ @@ -689,7 +741,7 @@ ___ #### Defined in -[src/types/composer.ts:534](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/composer.ts#L534) +[src/types/composer.ts:671](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/composer.ts#L671) ___ @@ -710,7 +762,7 @@ ___ #### Defined in -[src/types/composer.ts:675](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/composer.ts#L675) +[src/types/composer.ts:812](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/composer.ts#L812) ___ @@ -732,7 +784,7 @@ ___ #### Defined in -[src/types/composer.ts:419](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/composer.ts#L419) +[src/types/composer.ts:556](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/composer.ts#L556) ___ @@ -756,7 +808,7 @@ The execution result #### Defined in -[src/types/composer.ts:780](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/composer.ts#L780) +[src/types/composer.ts:928](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/composer.ts#L928) ___ @@ -775,4 +827,4 @@ The newly built atomic transaction composer and the transactions #### Defined in -[src/types/composer.ts:770](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/composer.ts#L770) +[src/types/composer.ts:918](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/composer.ts#L918) diff --git a/docs/code/classes/types_dispenser_client.TestNetDispenserApiClient.md b/docs/code/classes/types_dispenser_client.TestNetDispenserApiClient.md index 2b39d6e8..8527f982 100644 --- a/docs/code/classes/types_dispenser_client.TestNetDispenserApiClient.md +++ b/docs/code/classes/types_dispenser_client.TestNetDispenserApiClient.md @@ -64,13 +64,13 @@ If neither the environment variable 'ALGOKIT_DISPENSER_ACCESS_TOKEN' nor the aut ### constructor -• **new TestNetDispenserApiClient**(`params`): [`TestNetDispenserApiClient`](types_dispenser_client.TestNetDispenserApiClient.md) +• **new TestNetDispenserApiClient**(`params?`): [`TestNetDispenserApiClient`](types_dispenser_client.TestNetDispenserApiClient.md) #### Parameters | Name | Type | | :------ | :------ | -| `params` | ``null`` \| [`TestNetDispenserApiClientParams`](../interfaces/types_dispenser_client.TestNetDispenserApiClientParams.md) | +| `params?` | [`TestNetDispenserApiClientParams`](../interfaces/types_dispenser_client.TestNetDispenserApiClientParams.md) | #### Returns @@ -145,7 +145,7 @@ Sends a funding request to the dispenser API to fund the specified address with | Name | Type | Description | | :------ | :------ | :------ | | `address` | `string` | The address to fund. | -| `amount` | `number` | The amount of Algo to fund. | +| `amount` | `number` | The amount of microAlgos to fund. | #### Returns diff --git a/docs/code/interfaces/types_account_manager.BulkAssetOptInOutResult.md b/docs/code/interfaces/types_account_manager.BulkAssetOptInOutResult.md new file mode 100644 index 00000000..b8916474 --- /dev/null +++ b/docs/code/interfaces/types_account_manager.BulkAssetOptInOutResult.md @@ -0,0 +1,38 @@ +[@algorandfoundation/algokit-utils](../README.md) / [types/account-manager](../modules/types_account_manager.md) / BulkAssetOptInOutResult + +# Interface: BulkAssetOptInOutResult + +[types/account-manager](../modules/types_account_manager.md).BulkAssetOptInOutResult + +Individual result from performing a bulk opt-in or bulk opt-out for an account against a series of assets. + +## Table of contents + +### Properties + +- [assetId](types_account_manager.BulkAssetOptInOutResult.md#assetid) +- [transactionId](types_account_manager.BulkAssetOptInOutResult.md#transactionid) + +## Properties + +### assetId + +• **assetId**: `bigint` + +The ID of the asset opted into / out of + +#### Defined in + +[src/types/account-manager.ts:19](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/account-manager.ts#L19) + +___ + +### transactionId + +• **transactionId**: `string` + +The transaction ID of the resulting opt in / out + +#### Defined in + +[src/types/account-manager.ts:21](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/account-manager.ts#L21) diff --git a/docs/code/interfaces/types_account_manager.EnsureFundedResult.md b/docs/code/interfaces/types_account_manager.EnsureFundedResult.md new file mode 100644 index 00000000..9fd726e3 --- /dev/null +++ b/docs/code/interfaces/types_account_manager.EnsureFundedResult.md @@ -0,0 +1,38 @@ +[@algorandfoundation/algokit-utils](../README.md) / [types/account-manager](../modules/types_account_manager.md) / EnsureFundedResult + +# Interface: EnsureFundedResult + +[types/account-manager](../modules/types_account_manager.md).EnsureFundedResult + +Result from performing an ensureFunded call. + +## Table of contents + +### Properties + +- [amountFunded](types_account_manager.EnsureFundedResult.md#amountfunded) +- [transactionId](types_account_manager.EnsureFundedResult.md#transactionid) + +## Properties + +### amountFunded + +• **amountFunded**: [`AlgoAmount`](../classes/types_amount.AlgoAmount.md) + +The amount that was sent to the account. + +#### Defined in + +[src/types/account-manager.ts:29](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/account-manager.ts#L29) + +___ + +### transactionId + +• **transactionId**: `string` + +The transaction ID of the transaction that funded the account. + +#### Defined in + +[src/types/account-manager.ts:27](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/account-manager.ts#L27) diff --git a/docs/code/interfaces/types_client_manager.TypedAppClient.md b/docs/code/interfaces/types_client_manager.TypedAppClient.md index bed15b81..b5bbd5e7 100644 --- a/docs/code/interfaces/types_client_manager.TypedAppClient.md +++ b/docs/code/interfaces/types_client_manager.TypedAppClient.md @@ -37,4 +37,4 @@ Interface to identify a typed client that can be used to interact with an applic #### Defined in -[src/types/client-manager.ts:461](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/client-manager.ts#L461) +[src/types/client-manager.ts:480](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/client-manager.ts#L480) diff --git a/docs/code/interfaces/types_composer.ExecuteParams.md b/docs/code/interfaces/types_composer.ExecuteParams.md index 29fb22c8..a179cce0 100644 --- a/docs/code/interfaces/types_composer.ExecuteParams.md +++ b/docs/code/interfaces/types_composer.ExecuteParams.md @@ -23,7 +23,7 @@ The number of rounds to wait for confirmation. By default until the latest lastV #### Defined in -[src/types/composer.ts:219](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/composer.ts#L219) +[src/types/composer.ts:332](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/composer.ts#L332) ___ @@ -35,4 +35,4 @@ Whether to suppress log messages from transaction send, default: do not suppress #### Defined in -[src/types/composer.ts:221](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/composer.ts#L221) +[src/types/composer.ts:334](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/composer.ts#L334) diff --git a/docs/code/interfaces/types_dispenser_client.TestNetDispenserApiClientParams.md b/docs/code/interfaces/types_dispenser_client.TestNetDispenserApiClientParams.md index b20f569d..70981be3 100644 --- a/docs/code/interfaces/types_dispenser_client.TestNetDispenserApiClientParams.md +++ b/docs/code/interfaces/types_dispenser_client.TestNetDispenserApiClientParams.md @@ -25,7 +25,7 @@ ___ ### requestTimeout -• **requestTimeout**: ``null`` \| `number` +• `Optional` **requestTimeout**: `number` #### Defined in diff --git a/docs/code/modules/index.md b/docs/code/modules/index.md index 758ce060..08b01a6a 100644 --- a/docs/code/modules/index.md +++ b/docs/code/modules/index.md @@ -216,7 +216,7 @@ algokit.bulkOptIn({ account: account, assetIds: [12345, 67890] }, algod) #### Defined in -[src/asset.ts:242](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/asset.ts#L242) +[src/asset.ts:123](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/asset.ts#L123) ___ @@ -251,7 +251,7 @@ algokit.bulkOptOut({ account: account, assetIds: [12345, 67890] }, algod) #### Defined in -[src/asset.ts:309](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/asset.ts#L309) +[src/asset.ts:148](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/asset.ts#L148) ___ @@ -282,7 +282,7 @@ await algokit.assetOptIn({ account, assetId }, algod) #### Defined in -[src/asset.ts:153](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/asset.ts#L153) +[src/asset.ts:64](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/asset.ts#L64) ___ @@ -313,7 +313,7 @@ await algokit.assetOptOut({ account, assetId, assetCreatorAddress }, algod) #### Defined in -[src/asset.ts:191](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/asset.ts#L191) +[src/asset.ts:93](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/asset.ts#L93) ___ @@ -475,7 +475,7 @@ await algokit.createAsset({ creator: account, total: 1, decimals: 0, name: 'My a #### Defined in -[src/asset.ts:81](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/asset.ts#L81) +[src/asset.ts:22](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/asset.ts#L22) ___ @@ -640,7 +640,7 @@ https://developer.algorand.org/docs/get-details/accounts/#minimum-balance #### Defined in -[src/transfer/transfer.ts:89](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/transfer/transfer.ts#L89) +[src/transfer/transfer.ts:23](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/transfer/transfer.ts#L23) ___ @@ -1956,7 +1956,7 @@ An instance of the TestNetDispenserApiClient class. **`Deprecated`** -Use `clientManager.getTestNetDispenser` instead +Use `clientManager.getTestNetDispenser` or `clientManager.getTestNetDispenserFromEnvironment` instead Create a new TestNetDispenserApiClient instance. Refer to [docs](https://github.com/algorandfoundation/algokit/blob/main/docs/testnet_api.md) on guidance to obtain an access token. @@ -2571,7 +2571,7 @@ await algokit.rekeyAccount({ from, rekeyTo }, algod) #### Defined in -[src/transfer/transfer.ts:182](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/transfer/transfer.ts#L182) +[src/transfer/transfer.ts:116](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/transfer/transfer.ts#L116) ___ @@ -2905,7 +2905,7 @@ await algokit.transferAlgos({ from, to, amount: algokit.algos(1) }, algod) #### Defined in -[src/transfer/transfer-algos.ts:19](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/transfer/transfer-algos.ts#L19) +[src/transfer/transfer-algos.ts:20](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/transfer/transfer-algos.ts#L20) ___ @@ -2936,7 +2936,7 @@ await algokit.transferAsset({ from, to, assetId, amount }, algod) #### Defined in -[src/transfer/transfer.ts:140](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/transfer/transfer.ts#L140) +[src/transfer/transfer.ts:83](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/transfer/transfer.ts#L83) ___ diff --git a/docs/code/modules/types_account_manager.md b/docs/code/modules/types_account_manager.md index 28931899..67c372a0 100644 --- a/docs/code/modules/types_account_manager.md +++ b/docs/code/modules/types_account_manager.md @@ -8,6 +8,11 @@ - [AccountManager](../classes/types_account_manager.AccountManager.md) +### Interfaces + +- [BulkAssetOptInOutResult](../interfaces/types_account_manager.BulkAssetOptInOutResult.md) +- [EnsureFundedResult](../interfaces/types_account_manager.EnsureFundedResult.md) + ### Functions - [getAccountTransactionSigner](types_account_manager.md#getaccounttransactionsigner) @@ -35,4 +40,4 @@ A transaction signer #### Defined in -[src/types/account-manager.ts:26](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/account-manager.ts#L26) +[src/types/account-manager.ts:38](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/account-manager.ts#L38) diff --git a/docs/code/modules/types_algorand_client.md b/docs/code/modules/types_algorand_client.md index 82c52f10..194e04d7 100644 --- a/docs/code/modules/types_algorand_client.md +++ b/docs/code/modules/types_algorand_client.md @@ -32,4 +32,4 @@ Result from sending a single transaction. #### Defined in -[src/types/algorand-client.ts:12](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/algorand-client.ts#L12) +[src/types/algorand-client.ts:14](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/algorand-client.ts#L14) diff --git a/docs/code/modules/types_client_manager.md b/docs/code/modules/types_client_manager.md index 4378b237..2c9f943f 100644 --- a/docs/code/modules/types_client_manager.md +++ b/docs/code/modules/types_client_manager.md @@ -31,7 +31,7 @@ Details to resolve an app client by creator address and name. #### Defined in -[src/types/client-manager.ts:467](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/client-manager.ts#L467) +[src/types/client-manager.ts:486](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/client-manager.ts#L486) ___ @@ -43,7 +43,7 @@ Details to resolve an app client by app ID. #### Defined in -[src/types/client-manager.ts:479](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/client-manager.ts#L479) +[src/types/client-manager.ts:498](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/client-manager.ts#L498) ___ @@ -55,7 +55,7 @@ Details to resolve a typed app creator address and name. #### Defined in -[src/types/client-manager.ts:474](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/client-manager.ts#L474) +[src/types/client-manager.ts:493](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/client-manager.ts#L493) ___ @@ -67,4 +67,4 @@ Details to resolve a typed app by app ID. #### Defined in -[src/types/client-manager.ts:484](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/client-manager.ts#L484) +[src/types/client-manager.ts:503](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/client-manager.ts#L503) diff --git a/docs/code/modules/types_composer.md b/docs/code/modules/types_composer.md index d123359f..37d563ed 100644 --- a/docs/code/modules/types_composer.md +++ b/docs/code/modules/types_composer.md @@ -21,11 +21,17 @@ - [AssetDestroyParams](types_composer.md#assetdestroyparams) - [AssetFreezeParams](types_composer.md#assetfreezeparams) - [AssetOptInParams](types_composer.md#assetoptinparams) +- [AssetOptOutParams](types_composer.md#assetoptoutparams) - [AssetTransferParams](types_composer.md#assettransferparams) - [CommonTransactionParams](types_composer.md#commontransactionparams) - [MethodCallParams](types_composer.md#methodcallparams) - [OnlineKeyRegistrationParams](types_composer.md#onlinekeyregistrationparams) - [PaymentParams](types_composer.md#paymentparams) +- [RekeyParams](types_composer.md#rekeyparams) + +### Variables + +- [MAX\_TRANSACTION\_GROUP\_SIZE](types_composer.md#max_transaction_group_size) ## Type Aliases @@ -46,7 +52,7 @@ Parameters to create an `AlgokitComposer`. #### Defined in -[src/types/composer.ts:225](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/composer.ts#L225) +[src/types/composer.ts:338](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/composer.ts#L338) ___ @@ -58,7 +64,7 @@ Parameters to define an application call transaction. #### Defined in -[src/types/composer.ts:151](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/composer.ts#L151) +[src/types/composer.ts:262](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/composer.ts#L262) ___ @@ -70,19 +76,21 @@ Parameters to define an asset config transaction. #### Defined in -[src/types/composer.ts:79](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/composer.ts#L79) +[src/types/composer.ts:179](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/composer.ts#L179) ___ ### AssetCreateParams -Ƭ **AssetCreateParams**: [`CommonTransactionParams`](types_composer.md#commontransactionparams) & \{ `assetName?`: `string` ; `clawback?`: `string` ; `decimals?`: `number` ; `defaultFrozen?`: `boolean` ; `freeze?`: `string` ; `manager?`: `string` ; `metadataHash?`: `Uint8Array` ; `reserve?`: `string` ; `total`: `bigint` ; `unitName?`: `string` ; `url?`: `string` } +Ƭ **AssetCreateParams**: [`CommonTransactionParams`](types_composer.md#commontransactionparams) & \{ `assetName?`: `string` ; `clawback?`: `string` ; `decimals?`: `number` ; `defaultFrozen?`: `boolean` ; `freeze?`: `string` ; `manager?`: `string` ; `metadataHash?`: `string` \| `Uint8Array` ; `reserve?`: `string` ; `total`: `bigint` ; `unitName?`: `string` ; `url?`: `string` } Parameters to define an asset create transaction. +The account that sends this transaction will automatically be opted in to the asset and will hold all units after creation. + #### Defined in -[src/types/composer.ts:53](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/composer.ts#L53) +[src/types/composer.ts:70](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/composer.ts#L70) ___ @@ -94,7 +102,7 @@ Parameters to define an asset destroy transaction. #### Defined in -[src/types/composer.ts:103](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/composer.ts#L103) +[src/types/composer.ts:203](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/composer.ts#L203) ___ @@ -106,7 +114,7 @@ Parameters to define an asset freeze transaction. #### Defined in -[src/types/composer.ts:93](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/composer.ts#L93) +[src/types/composer.ts:193](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/composer.ts#L193) ___ @@ -118,7 +126,19 @@ Parameters to define an asset opt-in transaction. #### Defined in -[src/types/composer.ts:123](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/composer.ts#L123) +[src/types/composer.ts:223](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/composer.ts#L223) + +___ + +### AssetOptOutParams + +Ƭ **AssetOptOutParams**: [`CommonTransactionParams`](types_composer.md#commontransactionparams) & \{ `assetId`: `bigint` ; `creator`: `string` } + +Parameters to define an asset opt-out transaction. + +#### Defined in + +[src/types/composer.ts:229](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/composer.ts#L229) ___ @@ -130,7 +150,7 @@ Parameters to define an asset transfer transaction. #### Defined in -[src/types/composer.ts:109](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/composer.ts#L109) +[src/types/composer.ts:209](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/composer.ts#L209) ___ @@ -150,7 +170,7 @@ Common parameters for defining a transaction. | `lease?` | `Uint8Array` \| `string` | Prevent multiple transactions with the same lease being included within the validity window | | `maxFee?` | [`AlgoAmount`](../classes/types_amount.AlgoAmount.md) | Throw an error if the fee for the transaction is more than this amount | | `note?` | `Uint8Array` \| `string` | Note to attach to the transaction | -| `rekeyTo?` | `string` | Change the signing key of the sender to the given address | +| `rekeyTo?` | `string` | Change the signing key of the sender to the given address. **Warning:** Please be careful with this parameter and be sure to read the [official rekey guidance](https://developer.algorand.org/docs/get-details/accounts/rekey/). | | `sender` | `string` | The address sending the transaction | | `signer?` | `algosdk.TransactionSigner` \| [`TransactionSignerAccount`](../interfaces/types_account.TransactionSignerAccount.md) | The function used to sign transactions | | `staticFee?` | [`AlgoAmount`](../classes/types_amount.AlgoAmount.md) | The transaction fee. In most cases you want to use `extraFee` unless setting the fee to 0 to be covered by another transaction | @@ -158,7 +178,7 @@ Common parameters for defining a transaction. #### Defined in -[src/types/composer.ts:13](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/composer.ts#L13) +[src/types/composer.ts:15](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/composer.ts#L15) ___ @@ -170,7 +190,7 @@ Parameters to define an ABI method application call transaction. #### Defined in -[src/types/composer.ts:186](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/composer.ts#L186) +[src/types/composer.ts:297](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/composer.ts#L297) ___ @@ -182,7 +202,7 @@ Parameters to define an online key registration transaction. #### Defined in -[src/types/composer.ts:129](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/composer.ts#L129) +[src/types/composer.ts:240](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/composer.ts#L240) ___ @@ -194,4 +214,26 @@ Parameters to define a payment transaction. #### Defined in -[src/types/composer.ts:43](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/composer.ts#L43) +[src/types/composer.ts:48](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/composer.ts#L48) + +___ + +### RekeyParams + +Ƭ **RekeyParams**: [`CommonTransactionParams`](types_composer.md#commontransactionparams) & \{ `rekeyTo`: `string` } + +Parameters to define a rekey transaction. + +#### Defined in + +[src/types/composer.ts:58](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/composer.ts#L58) + +## Variables + +### MAX\_TRANSACTION\_GROUP\_SIZE + +• `Const` **MAX\_TRANSACTION\_GROUP\_SIZE**: ``16`` + +#### Defined in + +[src/types/composer.ts:12](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/composer.ts#L12) diff --git a/src/asset.spec.ts b/src/asset.spec.ts index 77643cc0..fb81a97b 100644 --- a/src/asset.spec.ts +++ b/src/asset.spec.ts @@ -62,24 +62,6 @@ describe('asset', () => { expect(testAccountInfoAfterOptIn['total-assets-opted-in']).toBe(1) }) - test('OptIn assets to an account second attempt failed ', async () => { - const { algod, testAccount, generateAccount } = localnet.context - const dummyAssetId = await generateTestAsset(algod, testAccount, 0) - const dummyAssetId2 = await generateTestAsset(algod, testAccount, 0) - const dummyAssetIds = [dummyAssetId, dummyAssetId2] - const secondAccount = await generateAccount({ initialFunds: (1).algos() }) - - await algokit.assetBulkOptIn({ account: secondAccount, assetIds: dummyAssetIds }, algod) - - const secondAccountInfo = await algod.accountInformation(secondAccount.addr).do() - expect(secondAccountInfo['total-assets-opted-in']).toBe(2) - - // await optIn(algod, secondAccount, dummyAssetIds) - await expect(algokit.assetBulkOptIn({ account: secondAccount, assetIds: [dummyAssetId] }, algod)).rejects.toThrow( - `Asset ${dummyAssetId} cannot be opted in. Ensure that they are valid and that the account has not previously opted into them.`, - ) - }, 10e6) - test('OptIn two batches of asset to an account succeed', async () => { const { algod, testAccount, generateAccount } = localnet.context const dummyAssetIds: number[] = [] @@ -123,7 +105,7 @@ describe('asset', () => { expect(secondAccountInfo['total-assets-opted-in']).toBe(1) await expect(algokit.assetBulkOptOut({ account: secondAccount, assetIds: dummyAssetIds }, algod)).rejects.toThrow( - 'Assets 1234567, -132 cannot be opted out. Ensure that they are valid and that the account has previously opted into them and holds zero balance.', + `Account ${secondAccount.addr} is not opted-in to Assets 1234567, -132; can't opt-out.`, ) const secondAccountInfoAfterFailedOptOut = await algod.accountInformation(secondAccount.addr).do() @@ -154,7 +136,7 @@ describe('asset', () => { ) await expect(algokit.assetBulkOptOut({ account: secondAccount, assetIds: dummyAssetIds }, algod)).rejects.toThrow( - `Asset ${dummyAssetId} cannot be opted out. Ensure that they are valid and that the account has previously opted into them and holds zero balance.`, + `Account ${secondAccount.addr} has non-zero balance for Asset ${dummyAssetId}; can't opt-out.`, ) const secondAccountInfoAfterFailedOptOut = await algod.accountInformation(secondAccount.addr).do() @@ -196,7 +178,7 @@ describe('asset', () => { ) await expect(algokit.assetOptOut({ account: secondAccount, assetId: dummyAssetId }, algod)).rejects.toThrow( - `Asset ${dummyAssetId} cannot be opted out. Ensure that they are valid and that the account has previously opted into them and holds zero balance.`, + `Account ${secondAccount.addr} does not have a zero balance for Asset ${dummyAssetId}; can't opt-out.`, ) const secondAccountInfoAfterFailedOptOut = await algod.accountInformation(secondAccount.addr).do() diff --git a/src/asset.ts b/src/asset.ts index ee938ebe..c75ec840 100644 --- a/src/asset.ts +++ b/src/asset.ts @@ -1,72 +1,13 @@ import algosdk from 'algosdk' -import { Config } from './config' -import { - MAX_TRANSACTION_GROUP_SIZE, - encodeLease, - encodeTransactionNote, - getSenderAddress, - getTransactionParams, - sendGroupOfTransactions, - sendTransaction, -} from './transaction' +import { encodeTransactionNote, getSenderAddress } from './transaction' +import { legacySendTransactionBridge } from './transaction/legacy-bridge' +import { AccountManager } from './types/account-manager' import { AssetBulkOptInOutParams, AssetOptInParams, AssetOptOutParams, CreateAssetParams } from './types/asset' -import { SendTransactionFrom, SendTransactionResult, TransactionGroupToSend, TransactionToSign } from './types/transaction' +import { ClientManager } from './types/client-manager' +import { AssetCreateParams, AssetOptInParams as NewAssetOptInParams, AssetOptOutParams as NewAssetOptOutParams } from './types/composer' +import { SendTransactionResult } from './types/transaction' import Algodv2 = algosdk.Algodv2 -enum ValidationType { - OptIn, - OptOut, -} - -function* chunks(arr: T[], n: number): Generator { - for (let i = 0; i < arr.length; i += n) yield arr.slice(i, i + n) -} - -async function ensureAssetBalanceConditions( - account: SendTransactionFrom, - assetIds: number[], - validationType: ValidationType, - algod: algosdk.Algodv2, -) { - const accountAddress = getSenderAddress(account) - const accountInfo = await algod.accountInformation(accountAddress).do() - const assetPromises = assetIds.map(async (assetId) => { - if (validationType === ValidationType.OptIn) { - if (accountInfo.assets.find((a: Record) => a['asset-id'] === assetId)) { - Config.logger.debug(`Account ${accountAddress} has already opted-in to asset ${assetId}`) - return assetId - } - } else if (validationType === ValidationType.OptOut) { - try { - const accountAssetInfo = await algod.accountAssetInformation(accountAddress, assetId).do() - if (accountAssetInfo['asset-holding']['amount'] !== 0) { - Config.logger.debug(`Asset ${assetId} is not with zero balance`) - return assetId - } - } catch (e) { - Config.logger.debug(`Account ${accountAddress} does not have asset ${assetId}`) - return assetId - } - } - return null - }) - - const invalidAssets = (await Promise.all(assetPromises)).filter((assetId) => assetId !== null) - if (invalidAssets.length > 0) { - let errorMessage = '' - if (validationType === ValidationType.OptIn) { - errorMessage = `Asset${invalidAssets.length === 1 ? '' : 's'} ${invalidAssets.join( - ', ', - )} cannot be opted in. Ensure that they are valid and that the account has not previously opted into them.` - } else if (validationType === ValidationType.OptOut) { - errorMessage = `Asset${invalidAssets.length === 1 ? '' : 's'} ${invalidAssets.join( - ', ', - )} cannot be opted out. Ensure that they are valid and that the account has previously opted into them and holds zero balance.` - } - throw new Error(errorMessage) - } -} - /** * Create an Algorand Standard Asset (ASA). * @param create The asset creation definition @@ -82,61 +23,31 @@ export async function createAsset( create: CreateAssetParams, algod: Algodv2, ): Promise { - const { - creator, - total, - decimals, - name, - unit, - url, - metadataHash, - manager, - reserveAccount, - freezeAccount, - clawbackAccount, - frozenByDefault, - note, - transactionParams, - lease, - ...sendParams - } = create - - const transaction = algosdk.makeAssetCreateTxnWithSuggestedParamsFromObject({ - from: getSenderAddress(creator), - total, - decimals, - assetName: name, - unitName: unit, - assetURL: url, - defaultFrozen: frozenByDefault ?? false, - assetMetadataHash: metadataHash, - manager: manager ? getSenderAddress(manager) : undefined, - reserve: reserveAccount ? getSenderAddress(reserveAccount) : undefined, - freeze: freezeAccount ? getSenderAddress(freezeAccount) : undefined, - clawback: clawbackAccount ? getSenderAddress(clawbackAccount) : undefined, - rekeyTo: undefined, - suggestedParams: await getTransactionParams(transactionParams, algod), - note: encodeTransactionNote(note), - }) - - const encodedLease = encodeLease(lease) - if (encodedLease) { - transaction.addLease(encodedLease) - } - - const result = await sendTransaction({ transaction, from: creator, sendParams }, algod) - - if (!sendParams.skipSending) { - Config.getLogger(sendParams.suppressLog).info( - `Successfully created asset ${name ? `${name} ` : ''}${unit ? `(${unit}) ` : ''} with ${total} units and ${decimals} decimals via transaction ${transaction.txID()} with asset index ${ - result.confirmation?.assetIndex - } and creator ${getSenderAddress(creator)}.`, - ) - - return result as SendTransactionResult & { confirmation: { assetIndex: number | bigint } } + const params: AssetCreateParams = { + sender: getSenderAddress(create.creator), + total: BigInt(create.total), + decimals: create.decimals, + assetName: create.name, + unitName: create.unit, + manager: create.manager ? getSenderAddress(create.manager) : undefined, + clawback: create.clawbackAccount ? getSenderAddress(create.clawbackAccount) : undefined, + freeze: create.freezeAccount ? getSenderAddress(create.freezeAccount) : undefined, + reserve: create.reserveAccount ? getSenderAddress(create.reserveAccount) : undefined, + defaultFrozen: create.frozenByDefault, + lease: create.lease, + metadataHash: create.metadataHash, + note: encodeTransactionNote(create.note), + url: create.url, } - return { transaction: result.transaction } + return (await legacySendTransactionBridge( + algod, + create.creator, + create, + params, + (client) => client.transactions.assetCreate, + (client) => client.send.assetCreate, + )) as SendTransactionResult & { confirmation: { assetIndex: number | bigint } } } /** @@ -151,30 +62,21 @@ export async function createAsset( * ``` */ export async function assetOptIn(optIn: AssetOptInParams, algod: Algodv2): Promise { - const { account, assetId, note, transactionParams, lease, ...sendParams } = optIn - - const transaction = algosdk.makeAssetTransferTxnWithSuggestedParamsFromObject({ - from: getSenderAddress(account), - to: getSenderAddress(account), - assetIndex: assetId, - amount: 0, - rekeyTo: undefined, - revocationTarget: undefined, - closeRemainderTo: undefined, - suggestedParams: await getTransactionParams(transactionParams, algod), - note: encodeTransactionNote(note), - }) - - const encodedLease = encodeLease(lease) - if (encodedLease) { - transaction.addLease(encodedLease) - } - - if (!sendParams.skipSending) { - Config.getLogger(sendParams.suppressLog).debug(`Opted-in ${getSenderAddress(account)} to asset ${assetId}`) + const params: NewAssetOptInParams = { + assetId: BigInt(optIn.assetId), + sender: getSenderAddress(optIn.account), + note: encodeTransactionNote(optIn.note), + lease: optIn.lease, } - return sendTransaction({ transaction, from: account, sendParams }, algod) + return legacySendTransactionBridge( + algod, + optIn.account, + optIn, + params, + (c) => c.transactions.assetOptIn, + (c) => c.send.assetOptIn, + ) } /** @@ -189,45 +91,24 @@ export async function assetOptIn(optIn: AssetOptInParams, algod: Algodv2): Promi * ``` */ export async function assetOptOut(optOut: AssetOptOutParams, algod: Algodv2): Promise { - const { - account, - assetId, - note, - transactionParams, - lease, - assetCreatorAddress: _assetCreatorAddress, - ensureZeroBalance, - ...sendParams - } = optOut - - if (ensureZeroBalance === undefined || ensureZeroBalance) { - await ensureAssetBalanceConditions(account, [assetId], ValidationType.OptOut, algod) - } - - const assetCreatorAddress = _assetCreatorAddress ?? (await algod.getAssetByID(assetId).do()).params.creator - - const transaction = algosdk.makeAssetTransferTxnWithSuggestedParamsFromObject({ - from: getSenderAddress(account), - to: getSenderAddress(account), - assetIndex: assetId, - amount: 0, - rekeyTo: undefined, - revocationTarget: undefined, - closeRemainderTo: assetCreatorAddress, - suggestedParams: await getTransactionParams(transactionParams, algod), - note: encodeTransactionNote(note), - }) - - const encodedLease = encodeLease(lease) - if (encodedLease) { - transaction.addLease(encodedLease) + const assetCreatorAddress = optOut.assetCreatorAddress ?? (await algod.getAssetByID(optOut.assetId).do()).params.creator + + const params: NewAssetOptOutParams = { + assetId: BigInt(optOut.assetId), + creator: assetCreatorAddress, + sender: getSenderAddress(optOut.account), + note: encodeTransactionNote(optOut.note), + lease: optOut.lease, } - if (!sendParams.skipSending) { - Config.getLogger(sendParams.suppressLog).debug(`Opted-out ${getSenderAddress(account)} from asset ${assetId}`) - } - - return sendTransaction({ transaction, from: account, sendParams }, algod) + return legacySendTransactionBridge( + algod, + optOut.account, + optOut, + params, + (c) => c.transactions.assetOptOut, + (c) => (params: NewAssetOptOutParams) => c.send.assetOptOut({ ...params, ensureZeroBalance: optOut.ensureZeroBalance ?? true }), + ) } /** @@ -239,62 +120,20 @@ export async function assetOptOut(optOut: AssetOptOutParams, algod: Algodv2): Pr * @throws If there is an error during the opt-in process. * @example algokit.bulkOptIn({ account: account, assetIds: [12345, 67890] }, algod) */ -export async function assetBulkOptIn(optIn: AssetBulkOptInOutParams, algod: Algodv2) { - const { account, assetIds, validateBalances, transactionParams, note, maxFee, suppressLog } = optIn - const result: Record = {} - - if (validateBalances === undefined || validateBalances) { - await ensureAssetBalanceConditions(account, assetIds, ValidationType.OptIn, algod) - } - - const suggestedParams = await getTransactionParams(transactionParams, algod) - - for (const assetGroup of chunks(assetIds, MAX_TRANSACTION_GROUP_SIZE)) { - try { - const transactionsToSign: TransactionToSign[] = await Promise.all( - assetGroup.map(async (assetId) => ({ - transaction: ( - await assetOptIn( - { - account, - assetId, - transactionParams: suggestedParams, - note, - maxFee, - skipSending: true, - suppressLog: true, - }, - algod, - ) - ).transaction, - signer: account, - })), - ) - const txnGrp: TransactionGroupToSend = { - transactions: transactionsToSign, - signer: account, - sendParams: { - suppressLog: true, - }, - } - const sendGroupOfTransactionsResult = await sendGroupOfTransactions(txnGrp, algod) - assetGroup.map((assetId, index) => { - result[assetId] = sendGroupOfTransactionsResult.txIds[index] - - Config.getLogger(suppressLog).info( - `Successfully opted in ${getSenderAddress(account)} for asset ${assetId} with transaction ID ${ - sendGroupOfTransactionsResult.txIds[index] - }, - grouped under ${sendGroupOfTransactionsResult.groupId} round ${ - sendGroupOfTransactionsResult.confirmations?.[0]?.confirmedRound - }.`, - ) - }) - } catch (e) { - throw new Error(`Received error trying to opt in ${e}`) - } +export async function assetBulkOptIn(optIn: AssetBulkOptInOutParams, algod: Algodv2): Promise> { + const result = await new AccountManager(new ClientManager({ algod })) + .setSignerFromAccount(optIn.account) + .assetBulkOptIn(getSenderAddress(optIn.account), optIn.assetIds, { + note: encodeTransactionNote(optIn.note), + maxFee: optIn.maxFee, + suppressLog: optIn.suppressLog, + }) + + const returnResult: Record = {} + for (const r of result) { + returnResult[Number(r.assetId)] = r.transactionId } - return result + return returnResult } /** @@ -307,62 +146,18 @@ export async function assetBulkOptIn(optIn: AssetBulkOptInOutParams, algod: Algo * @example algokit.bulkOptOut({ account: account, assetIds: [12345, 67890] }, algod) */ export async function assetBulkOptOut(optOut: AssetBulkOptInOutParams, algod: Algodv2): Promise> { - const { account, validateBalances, transactionParams, note, assetIds, maxFee, suppressLog } = optOut - const result: Record = {} - - if (validateBalances === undefined || validateBalances) { - await ensureAssetBalanceConditions(account, assetIds, ValidationType.OptOut, algod) - } - - const suggestedParams = await getTransactionParams(transactionParams, algod) - - const assetDetails = await Promise.all(assetIds.map((assetId) => algod.getAssetByID(assetId).do())) - - for (const assetGroup of chunks(assetDetails, MAX_TRANSACTION_GROUP_SIZE)) { - try { - const transactionToSign: TransactionToSign[] = await Promise.all( - assetGroup.map(async (asset) => ({ - transaction: ( - await assetOptOut( - { - account, - assetId: asset.index, - assetCreatorAddress: asset.params.creator, - transactionParams: suggestedParams, - note, - maxFee, - skipSending: true, - suppressLog: true, - }, - algod, - ) - ).transaction, - signer: account, - })), - ) - const txnGrp: TransactionGroupToSend = { - transactions: transactionToSign, - signer: account, - sendParams: { - suppressLog: true, - }, - } - const sendGroupOfTransactionsResult = await sendGroupOfTransactions(txnGrp, algod) - assetGroup.map((asset, index) => { - result[asset.index] = sendGroupOfTransactionsResult.txIds[index] - - Config.getLogger(suppressLog).info( - `Successfully opted out ${getSenderAddress(account)} from asset ${asset.index} with transaction ID ${ - sendGroupOfTransactionsResult.txIds[index] - }, - grouped under ${sendGroupOfTransactionsResult.groupId} round ${ - sendGroupOfTransactionsResult.confirmations?.[0]?.confirmedRound - }.`, - ) - }) - } catch (e) { - throw new Error(`Received error trying to opt out ${e}`) - } + const result = await new AccountManager(new ClientManager({ algod })) + .setSignerFromAccount(optOut.account) + .assetBulkOptOut(getSenderAddress(optOut.account), optOut.assetIds, { + ensureZeroBalance: optOut.validateBalances ?? true, + note: encodeTransactionNote(optOut.note), + maxFee: optOut.maxFee, + suppressLog: optOut.suppressLog, + }) + + const returnResult: Record = {} + for (const r of result) { + returnResult[Number(r.assetId)] = r.transactionId } - return result + return returnResult } diff --git a/src/dispenser-client.ts b/src/dispenser-client.ts index f62a0da9..05aa4b73 100644 --- a/src/dispenser-client.ts +++ b/src/dispenser-client.ts @@ -1,7 +1,7 @@ import { TestNetDispenserApiClient, TestNetDispenserApiClientParams } from './types/dispenser-client' /** - * @deprecated Use `clientManager.getTestNetDispenser` instead + * @deprecated Use `clientManager.getTestNetDispenser` or `clientManager.getTestNetDispenserFromEnvironment` instead * * Create a new TestNetDispenserApiClient instance. * Refer to [docs](https://github.com/algorandfoundation/algokit/blob/main/docs/testnet_api.md) on guidance to obtain an access token. @@ -19,5 +19,5 @@ import { TestNetDispenserApiClient, TestNetDispenserApiClientParams } from './ty * @returns An instance of the TestNetDispenserApiClient class. */ export function getTestNetDispenserApiClient(params: TestNetDispenserApiClientParams | null = null) { - return new TestNetDispenserApiClient(params) + return new TestNetDispenserApiClient(params === null ? undefined : params) } diff --git a/src/testing/account.ts b/src/testing/account.ts index 1d79ed32..79608756 100644 --- a/src/testing/account.ts +++ b/src/testing/account.ts @@ -49,10 +49,13 @@ export async function getTestAccount( const dispenser = await algorand.account.dispenserFromEnvironment() - await algorand.send.payment( - { sender: dispenser.addr, receiver: account.addr, amount: initialFunds, note: 'Funding test account' }, - { suppressLog }, - ) + await algorand.send.payment({ + sender: dispenser.addr, + receiver: account.addr, + amount: initialFunds, + note: 'Funding test account', + suppressLog, + }) const accountInfo = await algorand.account.getInformation(account.addr) diff --git a/src/transaction/legacy-bridge.ts b/src/transaction/legacy-bridge.ts new file mode 100644 index 00000000..aa9b9451 --- /dev/null +++ b/src/transaction/legacy-bridge.ts @@ -0,0 +1,36 @@ +import algosdk from 'algosdk' +import { AlgorandClient, SendSingleTransactionResult } from '../types/algorand-client' +import { CommonTransactionParams, ExecuteParams } from '../types/composer' +import { SendTransactionFrom, SendTransactionParams, SendTransactionResult } from '../types/transaction' +import { getSenderTransactionSigner } from './transaction' +import Algodv2 = algosdk.Algodv2 +import Transaction = algosdk.Transaction + +/** Bridges between legacy `sendTransaction` behaviour and new `AlgorandClient` behaviour. */ +export async function legacySendTransactionBridge( + algod: Algodv2, + from: SendTransactionFrom, + sendParams: SendTransactionParams, + params: T, + txn: (c: AlgorandClient) => (params: T) => Promise, + send: (c: AlgorandClient) => (params: T & ExecuteParams) => Promise, +): Promise { + const client = AlgorandClient.fromClients({ algod }).setSignerFromAccount(from) + + if (sendParams.fee) { + params.staticFee = sendParams.fee + } + if (sendParams.maxFee) { + params.maxFee = sendParams.maxFee + } + + if (sendParams.atc || sendParams.skipSending) { + const transaction = await txn(client)(params) + if (sendParams.atc) { + sendParams.atc.addTransaction(await { txn: transaction, signer: getSenderTransactionSigner(from) }) + } + return { transaction } + } + + return await send(client)({ ...sendParams, ...params }) +} diff --git a/src/transaction/transaction.spec.ts b/src/transaction/transaction.spec.ts index 892288de..aeb09d8f 100644 --- a/src/transaction/transaction.spec.ts +++ b/src/transaction/transaction.spec.ts @@ -790,11 +790,9 @@ describe('Resource Packer: meta', () => { const authAddr = algorand.account.random().account - await algorand.send.payment({ + await algorand.send.rekey({ sender: testAccount.addr, - receiver: testAccount.addr, rekeyTo: authAddr.addr, - amount: algokit.microAlgos(0), }) await externalClient.fundAppAccount(algokit.microAlgos(200_000)) diff --git a/src/transfer/transfer-algos.ts b/src/transfer/transfer-algos.ts index c9e50325..557241c1 100644 --- a/src/transfer/transfer-algos.ts +++ b/src/transfer/transfer-algos.ts @@ -1,6 +1,7 @@ import algosdk from 'algosdk' -import { Config } from '../config' -import { encodeLease, encodeTransactionNote, getSenderAddress, getTransactionParams, sendTransaction } from '../transaction/transaction' +import { legacySendTransactionBridge } from '../transaction/legacy-bridge' +import { encodeTransactionNote, getSenderAddress } from '../transaction/transaction' +import { PaymentParams } from '../types/composer' import { SendTransactionResult } from '../types/transaction' import { AlgoTransferParams } from '../types/transfer' import Algodv2 = algosdk.Algodv2 @@ -17,28 +18,20 @@ import Algodv2 = algosdk.Algodv2 * ``` */ export async function transferAlgos(transfer: AlgoTransferParams, algod: Algodv2): Promise { - const { from, to, amount, note, transactionParams, lease, ...sendParams } = transfer - - const transaction = algosdk.makePaymentTxnWithSuggestedParamsFromObject({ - from: getSenderAddress(from), - to: getSenderAddress(to), - amount: amount.microAlgos, - note: encodeTransactionNote(note), - suggestedParams: await getTransactionParams(transactionParams, algod), - closeRemainderTo: undefined, - rekeyTo: undefined, - }) - - const encodedLease = encodeLease(lease) - if (encodedLease) { - transaction.addLease(encodedLease) - } - - if (!sendParams.skipSending) { - Config.getLogger(sendParams.suppressLog).debug( - `Transferring ${amount.microAlgos}µALGOs from ${getSenderAddress(from)} to ${getSenderAddress(to)}`, - ) + const params: PaymentParams = { + sender: getSenderAddress(transfer.from), + receiver: getSenderAddress(transfer.to), + amount: transfer.amount, + note: encodeTransactionNote(transfer.note), + lease: transfer.lease, } - return sendTransaction({ transaction, from, sendParams }, algod) + return await legacySendTransactionBridge( + algod, + transfer.from, + transfer, + params, + (c) => c.transactions.payment, + (c) => c.send.payment, + ) } diff --git a/src/transfer/transfer.spec.ts b/src/transfer/transfer.spec.ts index dea43b11..eac55ad0 100644 --- a/src/transfer/transfer.spec.ts +++ b/src/transfer/transfer.spec.ts @@ -372,11 +372,11 @@ describe('transfer', () => { expect(accountInfo['amount']).toBe(1_000_000) }) - test('ensureFunded uses dispenser api with access token sucessfully', async () => { + test('ensureFunded uses dispenser api with access token successfully', async () => { process.env.ALGOKIT_DISPENSER_ACCESS_TOKEN = 'dummy_token' const algodClient = ClientManager.getAlgodClient(ClientManager.getAlgoNodeConfig('testnet', 'algod')) - const dispenserClient = new TestNetDispenserApiClient(null) + const dispenserClient = new TestNetDispenserApiClient() Object.assign(dispenserClient, { fund: jest.fn().mockImplementation(() => { return Promise.resolve({ txId: 'dummy_tx_id', amount: 200_000 }) @@ -404,7 +404,7 @@ describe('transfer', () => { process.env.ALGOKIT_DISPENSER_ACCESS_TOKEN = 'dummy_token' const algodClient = ClientManager.getAlgodClient(ClientManager.getAlgoNodeConfig('testnet', 'algod')) - const dispenserClient = new TestNetDispenserApiClient(null) + const dispenserClient = new TestNetDispenserApiClient() Object.assign(dispenserClient, { fund: jest.fn().mockImplementation(() => { return Promise.reject(new Error('dummy_error')) @@ -443,7 +443,6 @@ describe('rekey', () => { test('Rekey works', async () => { const { algod, testAccount, algorand } = localnet.context const secondAccount = algorand.account.random() - const rekeyedAccount = algorand.account.rekeyed(secondAccount, testAccount.addr) await algokit.rekeyAccount( { @@ -455,6 +454,7 @@ describe('rekey', () => { ) // This will throw if the rekey wasn't successful + const rekeyedAccount = algorand.account.rekeyed(secondAccount, testAccount.addr) await algokit.transferAlgos( { amount: (1).microAlgos(), diff --git a/src/transfer/transfer.ts b/src/transfer/transfer.ts index 753d9130..31c830ba 100644 --- a/src/transfer/transfer.ts +++ b/src/transfer/transfer.ts @@ -1,79 +1,13 @@ import algosdk from 'algosdk' -import { microAlgos } from '../amount' -import { Config } from '../config' -import { encodeLease, encodeTransactionNote, getSenderAddress, getTransactionParams, sendTransaction } from '../transaction/transaction' -import { AccountManager } from '../types/account-manager' -import { AlgoAmount } from '../types/amount' -import { ClientManager } from '../types/client-manager' +import { AlgorandClient } from '..' +import { legacySendTransactionBridge } from '../transaction/legacy-bridge' +import { encodeTransactionNote, getSenderAddress } from '../transaction/transaction' import { TestNetDispenserApiClient } from '../types/dispenser-client' -import { SendTransactionResult, TransactionNote } from '../types/transaction' +import { SendTransactionResult } from '../types/transaction' import { AlgoRekeyParams, EnsureFundedParams, EnsureFundedReturnType, TransferAssetParams } from '../types/transfer' -import { calculateFundAmount } from '../util' -import { transferAlgos } from './transfer-algos' import Algodv2 = algosdk.Algodv2 import Kmd = algosdk.Kmd -async function fundUsingDispenserApi( - dispenserClient: TestNetDispenserApiClient, - addressToFund: string, - fundAmount: number, -): Promise { - const response = await dispenserClient.fund(addressToFund, fundAmount) - return { transactionId: response.txId, amount: response.amount } -} - -async function fundUsingTransfer({ - algod, - addressToFund, - funding, - fundAmount, - transactionParams, - sendParams, - note, - kmd, -}: { - algod: Algodv2 - addressToFund: string - funding: EnsureFundedParams - fundAmount: number - transactionParams: algosdk.SuggestedParams | undefined - sendParams: { - skipSending?: boolean | undefined - skipWaiting?: boolean | undefined - atc?: algosdk.AtomicTransactionComposer | undefined - suppressLog?: boolean | undefined - fee?: AlgoAmount | undefined - maxFee?: AlgoAmount | undefined - maxRoundsToWaitForConfirmation?: number | undefined - } - note: TransactionNote - kmd?: Kmd -}): Promise { - if (funding.fundingSource instanceof TestNetDispenserApiClient) { - throw new Error('Dispenser API client is not supported in this context.') - } - - const from = funding.fundingSource ?? (await new AccountManager(new ClientManager({ algod, kmd })).dispenserFromEnvironment()) - const amount = microAlgos(Math.max(fundAmount, funding.minFundingIncrement?.microAlgos ?? 0)) - const response = await transferAlgos( - { - from, - to: addressToFund, - note: note ?? 'Funding account to meet minimum requirement', - amount: amount, - transactionParams: transactionParams, - lease: funding.lease, - ...sendParams, - }, - algod, - ) - - return { - transactionId: response.transaction.txID(), - amount: Number(response.transaction.amount), - } -} - /** * Funds a given account using a funding source such that it has a certain amount of algos free to spend (accounting for ALGOs locked in minimum balance requirement). * @@ -91,39 +25,48 @@ export async function ensureFunded( algod: Algodv2, kmd?: Kmd, ): Promise { - const { accountToFund, fundingSource, minSpendingBalance, minFundingIncrement, transactionParams, note, ...sendParams } = funding + const algorand = AlgorandClient.fromClients({ algod, kmd }) - const addressToFund = typeof accountToFund === 'string' ? accountToFund : getSenderAddress(accountToFund) - - const accountInfo = await algod.accountInformation(addressToFund).do() - const balance = Number(accountInfo.amount) - const minimumBalanceRequirement = microAlgos(Number(accountInfo['min-balance'])) - const currentSpendingBalance = microAlgos(balance - minimumBalanceRequirement.microAlgos) - - const fundAmount = calculateFundAmount( - minSpendingBalance.microAlgos, - currentSpendingBalance.microAlgos, - minFundingIncrement?.microAlgos ?? 0, - ) - - if (fundAmount !== null) { - if ((await new ClientManager({ algod }).isTestNet()) && fundingSource instanceof TestNetDispenserApiClient) { - return await fundUsingDispenserApi(fundingSource, addressToFund, fundAmount) - } else { - return await fundUsingTransfer({ - algod, - addressToFund, - funding, - fundAmount, - transactionParams, - sendParams, - note, - kmd, - }) + if (funding.fundingSource instanceof TestNetDispenserApiClient) { + const result = await algorand.account.ensureFundedFromTestNetDispenserApi( + getSenderAddress(funding.accountToFund), + funding.fundingSource, + funding.minSpendingBalance, + { + minFundingIncrement: funding.minFundingIncrement, + }, + ) + if (!result) return undefined + return { + amount: result.amountFunded.microAlgos, + transactionId: result.transactionId, } - } + } else { + const sender = funding.fundingSource ?? (await algorand.account.dispenserFromEnvironment()) + algorand.setSignerFromAccount(sender) + + const result = await algorand.account.ensureFunded( + getSenderAddress(funding.accountToFund), + getSenderAddress(sender), + funding.minSpendingBalance, + { + minFundingIncrement: funding.minFundingIncrement, + note: encodeTransactionNote(funding.note), + staticFee: funding.fee, + lease: funding.lease, + maxFee: funding.maxFee, + maxRoundsToWaitForConfirmation: funding.maxRoundsToWaitForConfirmation, + suppressLog: funding.suppressLog, + }, + ) - return undefined + return result + ? { + amount: result.amountFunded.microAlgos, + transactionId: result.txIds[0], + } + : undefined + } } /** @@ -138,31 +81,22 @@ export async function ensureFunded( * ``` */ export async function transferAsset(transfer: TransferAssetParams, algod: Algodv2): Promise { - const { from, to, assetId, amount, transactionParams, clawbackFrom, note, lease, ...sendParams } = transfer - const transaction = algosdk.makeAssetTransferTxnWithSuggestedParamsFromObject({ - from: getSenderAddress(from), - to: getSenderAddress(to), - closeRemainderTo: undefined, - revocationTarget: clawbackFrom ? getSenderAddress(clawbackFrom) : undefined, - amount: amount, - note: encodeTransactionNote(note), - assetIndex: assetId, - suggestedParams: await getTransactionParams(transactionParams, algod), - rekeyTo: undefined, - }) - - const encodedLease = encodeLease(lease) - if (encodedLease) { - transaction.addLease(encodedLease) - } - - if (!sendParams.skipSending) { - Config.getLogger(sendParams.suppressLog).debug( - `Transferring ASA (${assetId}) of amount ${amount} from ${getSenderAddress(from)} to ${getSenderAddress(to)}`, - ) - } - - return sendTransaction({ transaction, from, sendParams }, algod) + return legacySendTransactionBridge( + algod, + transfer.from, + transfer, + { + assetId: BigInt(transfer.assetId), + sender: getSenderAddress(transfer.from), + receiver: getSenderAddress(transfer.to), + clawbackTarget: transfer.clawbackFrom ? getSenderAddress(transfer.clawbackFrom) : undefined, + amount: BigInt(transfer.amount), + note: encodeTransactionNote(transfer.note), + lease: transfer.lease, + }, + (c) => c.transactions.assetTransfer, + (c) => c.send.assetTransfer, + ) } /** @@ -180,26 +114,17 @@ export async function transferAsset(transfer: TransferAssetParams, algod: Algodv * ``` */ export async function rekeyAccount(rekey: AlgoRekeyParams, algod: Algodv2): Promise { - const { from, rekeyTo, note, transactionParams, lease, ...sendParams } = rekey - - const transaction = algosdk.makePaymentTxnWithSuggestedParamsFromObject({ - from: getSenderAddress(from), - to: getSenderAddress(from), - rekeyTo: getSenderAddress(rekeyTo), - amount: 0, - note: encodeTransactionNote(note), - suggestedParams: await getTransactionParams(transactionParams, algod), - closeRemainderTo: undefined, - }) - - const encodedLease = encodeLease(lease) - if (encodedLease) { - transaction.addLease(encodedLease) - } - - if (!sendParams.skipSending) { - Config.getLogger(sendParams.suppressLog).debug(`Rekeying ${getSenderAddress(from)} to ${getSenderAddress(rekeyTo)}`) - } - - return sendTransaction({ transaction, from, sendParams }, algod) + return legacySendTransactionBridge( + algod, + rekey.from, + rekey, + { + sender: getSenderAddress(rekey.from), + rekeyTo: typeof rekey.rekeyTo === 'string' ? rekey.rekeyTo : getSenderAddress(rekey.rekeyTo), + note: encodeTransactionNote(rekey.note), + lease: rekey.lease, + }, + (c) => c.transactions.rekey, + (c) => c.send.rekey, + ) } diff --git a/src/types/account-manager.ts b/src/types/account-manager.ts index a1133240..5002f29d 100644 --- a/src/types/account-manager.ts +++ b/src/types/account-manager.ts @@ -1,20 +1,32 @@ import algosdk from 'algosdk' +import { Config } from '../config' +import { calculateFundAmount, chunkArray, memoize } from '../util' import { AccountInformation, DISPENSER_ACCOUNT, MultisigAccount, SigningAccount, TransactionSignerAccount } from './account' +import { SendSingleTransactionResult } from './algorand-client' import { AlgoAmount } from './amount' import { ClientManager } from './client-manager' +import AlgokitComposer, { CommonTransactionParams, ExecuteParams, MAX_TRANSACTION_GROUP_SIZE } from './composer' +import { TestNetDispenserApiClient } from './dispenser-client' import { KmdAccountManager } from './kmd-account-manager' import LogicSigAccount = algosdk.LogicSigAccount import Account = algosdk.Account import TransactionSigner = algosdk.TransactionSigner import AccountInformationModel = algosdk.modelsv2.Account -const memoize = (fn: (val: T) => R) => { - const cache = new Map() - const cached = function (this: unknown, val: T) { - return cache.has(val) ? cache.get(val) : cache.set(val, fn.call(this, val)) && cache.get(val) - } - cached.cache = cache - return cached as (val: T) => R +/** Individual result from performing a bulk opt-in or bulk opt-out for an account against a series of assets. */ +export interface BulkAssetOptInOutResult { + /** The ID of the asset opted into / out of */ + assetId: bigint + /** The transaction ID of the resulting opt in / out */ + transactionId: string +} + +/** Result from performing an ensureFunded call. */ +export interface EnsureFundedResult { + /** The transaction ID of the transaction that funded the account. */ + transactionId: string + /** The amount that was sent to the account. */ + amountFunded: AlgoAmount } /** @@ -53,6 +65,14 @@ export class AccountManager { this._kmdAccountManager = new KmdAccountManager(clientManager) } + private _getComposer(getSuggestedParams?: () => Promise) { + return new AlgokitComposer({ + algod: this._clientManager.algod, + getSigner: this.getSigner.bind(this), + getSuggestedParams: getSuggestedParams ?? (() => this._clientManager.algod.getTransactionParams().do()), + }) + } + /** KMD account manager that allows you to easily get and create accounts using KMD. */ public get kmd() { return this._kmdAccountManager @@ -429,4 +449,319 @@ export class AccountManager { const dispenser = await this._kmdAccountManager.getLocalNetDispenserAccount() return this.signerAccount(dispenser.account) } + + /** + * Opt an account in to a list of Algorand Standard Assets. + * + * Transactions will be sent in batches of 16 as transaction groups. + * + * @param account The account to opt-in + * @param assetIds The list of asset IDs to opt-in to + * @param options Any parameters to control the transaction or execution of the transaction + * @example Example using AlgorandClient + * ```typescript + * // Basic example + * algorand.account.assetBulkOptIn("ACCOUNTADDRESS", [12345, 67890]) + * // With configuration + * algorand.account.assetBulkOptIn("ACCOUNTADDRESS", [12345, 67890], { maxFee: (1000).microAlgos(), suppressLog: true }) + * ``` + * @returns An array of records matching asset ID to transaction ID of the opt in + */ + async assetBulkOptIn( + account: string | TransactionSignerAccount, + assetIds: (number | bigint)[], + options?: Omit & ExecuteParams, + ): Promise { + const results: BulkAssetOptInOutResult[] = [] + + const params = await this._clientManager.algod.getTransactionParams().do() + + for (const assetGroup of chunkArray(assetIds, MAX_TRANSACTION_GROUP_SIZE)) { + const composer = this._getComposer(() => Promise.resolve(params)) + + for (const assetId of assetGroup) { + composer.addAssetOptIn({ + ...options, + sender: typeof account === 'string' ? account : account.addr, + assetId: BigInt(assetId), + }) + } + + const result = await composer.execute(options) + + Config.getLogger(options?.suppressLog).info( + `Successfully opted in ${account} for assets ${assetGroup.join(', ')} with transaction IDs ${result.txIds.join(', ')}` + + `\n Grouped under ${result.groupId} in round ${result.confirmations?.[0]?.confirmedRound}.`, + ) + + assetGroup.forEach((assetId, index) => { + results.push({ assetId: BigInt(assetId), transactionId: result.txIds[index] }) + }) + } + + return results + } + + /** + * Opt an account out of a list of Algorand Standard Assets. + * + * Transactions will be sent in batches of 16 as transaction groups. + * + * @param account The account to opt-in + * @param assetIds The list of asset IDs to opt-out of + * @param options Any parameters to control the transaction or execution of the transaction + * @example Example using AlgorandClient + * ```typescript + * // Basic example + * algorand.account.assetBulkOptOut("ACCOUNTADDRESS", [12345, 67890]) + * // With configuration + * algorand.account.assetBulkOptOut("ACCOUNTADDRESS", [12345, 67890], { maxFee: (1000).microAlgos(), suppressLog: true }) + * ``` + * @returns An array of records matching asset ID to transaction ID of the opt in + */ + async assetBulkOptOut( + account: string | TransactionSignerAccount, + assetIds: (number | bigint)[], + options?: Omit & + ExecuteParams & { + /** Whether or not to check if the account has a zero balance for each asset first or not. + * + * If this is set to `true` and the account has an asset balance it will throw an error. + * + * If this is set to `false` and the account has an asset balance it will lose those assets to the asset creator. + */ + ensureZeroBalance: boolean + }, + ): Promise { + const results: BulkAssetOptInOutResult[] = [] + + const params = await this._clientManager.algod.getTransactionParams().do() + const sender = typeof account === 'string' ? account : account.addr + + for (const assetGroup of chunkArray(assetIds, MAX_TRANSACTION_GROUP_SIZE)) { + const composer = this._getComposer(() => Promise.resolve(params)) + + const notOptedInAssetIds: bigint[] = [] + const nonZeroBalanceAssetIds: bigint[] = [] + for (const assetId of assetGroup) { + if (options?.ensureZeroBalance) { + try { + const accountAssetInfo = await this.getAssetInformation(sender, assetId) + if (accountAssetInfo.balance !== 0n) { + nonZeroBalanceAssetIds.push(BigInt(assetId)) + } + } catch (e) { + notOptedInAssetIds.push(BigInt(assetId)) + } + } + } + + if (notOptedInAssetIds.length > 0 || nonZeroBalanceAssetIds.length > 0) { + throw new Error( + `Account ${sender}${notOptedInAssetIds.length > 0 ? ` is not opted-in to Asset${notOptedInAssetIds.length > 1 ? 's' : ''} ${notOptedInAssetIds.join(', ')}` : ''}${ + nonZeroBalanceAssetIds.length > 0 + ? ` has non-zero balance for Asset${nonZeroBalanceAssetIds.length > 1 ? 's' : ''} ${nonZeroBalanceAssetIds.join(', ')}` + : '' + }; can't opt-out.`, + ) + } + + for (const assetId of assetGroup) { + composer.addAssetOptOut({ + ...options, + creator: (await this._clientManager.algod.getAssetByID(Number(assetId)).do()).params.creator as string, + sender, + assetId: BigInt(assetId), + }) + } + + const result = await composer.execute(options) + + Config.getLogger(options?.suppressLog).info( + `Successfully opted ${account} out of assets ${assetGroup.join(', ')} with transaction IDs ${result.txIds.join(', ')}` + + `\n Grouped under ${result.groupId} in round ${result.confirmations?.[0]?.confirmedRound}.`, + ) + + assetGroup.forEach((assetId, index) => { + results.push({ assetId: BigInt(assetId), transactionId: result.txIds[index] }) + }) + } + + return results + } + + private async _getEnsureFundedAmount(sender: string, minSpendingBalance: AlgoAmount, minFundingIncrement?: AlgoAmount) { + const accountInfo = await this.getInformation(sender) + const currentSpendingBalance = accountInfo.amount - accountInfo.minBalance + + const amountFunded = calculateFundAmount(minSpendingBalance.microAlgos, currentSpendingBalance, minFundingIncrement?.microAlgos ?? 0) + + return amountFunded === null ? undefined : AlgoAmount.MicroAlgos(amountFunded) + } + + /** + * Funds a given account using a dispenser account as a funding source such that + * the given account has a certain amount of algos free to spend (accounting for + * ALGOs locked in minimum balance requirement). + * + * https://developer.algorand.org/docs/get-details/accounts/#minimum-balance + * + * @param accountToFund The account to fund + * @param dispenserAccount The account to use as a dispenser funding source + * @param minSpendingBalance The minimum balance of ALGOs that the account should have available to spend (i.e. on top of minimum balance requirement) + * @param options Optional parameters to control the funding increment, transaction or execution of the transaction + * @example Example using AlgorandClient + * ```typescript + * // Basic example + * await algorand.account.ensureFunded("ACCOUNTADDRESS", "DISPENSERADDRESS", algokit.algos(1)) + * // With configuration + * await algorand.account.ensureFunded("ACCOUNTADDRESS", "DISPENSERADDRESS", algokit.algos(1), + * { minFundingIncrement: algokit.algos(2), fee: (1000).microAlgos(), suppressLog: true } + * ) + * ``` + * @returns + * - The result of executing the dispensing transaction and the `amountFunded` if funds were needed. + * - `undefined` if no funds were needed. + */ + async ensureFunded( + accountToFund: string | TransactionSignerAccount, + dispenserAccount: string | TransactionSignerAccount, + minSpendingBalance: AlgoAmount, + options?: { + minFundingIncrement?: AlgoAmount + } & ExecuteParams & + Omit, + ): Promise<(SendSingleTransactionResult & EnsureFundedResult) | undefined> { + const addressToFund = typeof accountToFund === 'string' ? accountToFund : accountToFund.addr + + const amountFunded = await this._getEnsureFundedAmount(addressToFund, minSpendingBalance, options?.minFundingIncrement) + if (!amountFunded) return undefined + + const result = await this._getComposer() + .addPayment({ + ...options, + sender: typeof dispenserAccount === 'string' ? dispenserAccount : dispenserAccount.addr, + receiver: addressToFund, + amount: amountFunded, + }) + .execute(options) + + return { + ...result, + transaction: result.transactions[0], + confirmation: result.confirmations[0], + transactionId: result.txIds[0], + amountFunded: amountFunded, + } + } + + /** + * Funds a given account using a dispenser account retrieved from the environment, + * per the `dispenserFromEnvironment` method, as a funding source such that + * the given account has a certain amount of algos free to spend (accounting for + * ALGOs locked in minimum balance requirement). + * + * **Note:** requires a Node.js environment to execute. + * + * The dispenser account is retrieved from the account mnemonic stored in + * process.env.DISPENSER_MNEMONIC and optionally process.env.DISPENSER_SENDER + * if it's a rekeyed account, or against default LocalNet if no environment variables present. + * + * https://developer.algorand.org/docs/get-details/accounts/#minimum-balance + * + * @param accountToFund The account to fund + * @param minSpendingBalance The minimum balance of ALGOs that the account should have available to spend (i.e. on top of minimum balance requirement) + * @param options Optional parameters to control the funding increment, transaction or execution of the transaction + * @example Example using AlgorandClient + * ```typescript + * // Basic example + * await algorand.account.ensureFundedFromEnvironment("ACCOUNTADDRESS", algokit.algos(1)) + * // With configuration + * await algorand.account.ensureFundedFromEnvironment("ACCOUNTADDRESS", algokit.algos(1), + * { minFundingIncrement: algokit.algos(2), fee: (1000).microAlgos(), suppressLog: true } + * ) + * ``` + * @returns + * - The result of executing the dispensing transaction and the `amountFunded` if funds were needed. + * - `undefined` if no funds were needed. + */ + async ensureFundedFromEnvironment( + accountToFund: string | TransactionSignerAccount, + minSpendingBalance: AlgoAmount, + options?: { + minFundingIncrement?: AlgoAmount + } & ExecuteParams & + Omit, + ): Promise<(SendSingleTransactionResult & EnsureFundedResult) | undefined> { + const addressToFund = typeof accountToFund === 'string' ? accountToFund : accountToFund.addr + const dispenserAccount = await this.dispenserFromEnvironment() + + const amountFunded = await this._getEnsureFundedAmount(addressToFund, minSpendingBalance, options?.minFundingIncrement) + if (!amountFunded) return undefined + + const result = await this._getComposer() + .addPayment({ + ...options, + sender: dispenserAccount.addr, + receiver: addressToFund, + amount: amountFunded, + }) + .execute(options) + + return { + ...result, + transaction: result.transactions[0], + confirmation: result.confirmations[0], + transactionId: result.txIds[0], + amountFunded: amountFunded, + } + } + + /** + * Funds a given account using the TestNet Dispenser API as a funding source such that + * the account has a certain amount of algos free to spend (accounting for ALGOs locked + * in minimum balance requirement). + * + * https://developer.algorand.org/docs/get-details/accounts/#minimum-balance + * + * @param accountToFund The account to fund + * @param dispenserClient The TestNet dispenser funding client + * @param minSpendingBalance The minimum balance of ALGOs that the account should have available to spend (i.e. on top of minimum balance requirement) + * @param options Optional parameters to control the funding increment, transaction or execution of the transaction + * @example Example using AlgorandClient + * ```typescript + * // Basic example + * await algorand.account.ensureFundedUsingDispenserAPI("ACCOUNTADDRESS", algorand.client.getTestNetDispenserFromEnvironment(), algokit.algos(1)) + * // With configuration + * await algorand.account.ensureFundedUsingDispenserAPI("ACCOUNTADDRESS", algorand.client.getTestNetDispenserFromEnvironment(), algokit.algos(1), + * { minFundingIncrement: algokit.algos(2) } + * ) + * ``` + * @returns + * - The result of executing the dispensing transaction and the `amountFunded` if funds were needed. + * - `undefined` if no funds were needed. + */ + async ensureFundedFromTestNetDispenserApi( + accountToFund: string | TransactionSignerAccount, + dispenserClient: TestNetDispenserApiClient, + minSpendingBalance: AlgoAmount, + options: { + minFundingIncrement?: AlgoAmount + }, + ): Promise { + if (!(await this._clientManager.isTestNet())) { + throw new Error('Attempt to fund using TestNet dispenser API on non TestNet network.') + } + + const addressToFund = typeof accountToFund === 'string' ? accountToFund : accountToFund.addr + + const amountFunded = await this._getEnsureFundedAmount(addressToFund, minSpendingBalance, options?.minFundingIncrement) + if (!amountFunded) return undefined + + const result = await dispenserClient.fund(addressToFund, amountFunded.microAlgos) + return { + amountFunded: AlgoAmount.MicroAlgos(result.amount), + transactionId: result.txId, + } + } } diff --git a/src/types/algorand-client.ts b/src/types/algorand-client.ts index 0172b69c..f8824549 100644 --- a/src/types/algorand-client.ts +++ b/src/types/algorand-client.ts @@ -1,12 +1,14 @@ import algosdk from 'algosdk' import { Config } from '../config' -import { TransactionSignerAccount } from './account' +import { MultisigAccount, SigningAccount, TransactionSignerAccount } from './account' import { AccountManager } from './account-manager' import { AlgoSdkClients, ClientManager } from './client-manager' -import AlgokitComposer, { ExecuteParams, MethodCallParams } from './composer' +import AlgokitComposer, { AssetOptOutParams, ExecuteParams, MethodCallParams } from './composer' import { AlgoConfig } from './network-client' -import { ConfirmedTransactionResult, SendAtomicTransactionComposerResults, SendTransactionFrom } from './transaction' +import { ConfirmedTransactionResult, SendAtomicTransactionComposerResults } from './transaction' import Transaction = algosdk.Transaction +import Account = algosdk.Account +import LogicSigAccount = algosdk.LogicSigAccount /** Result from sending a single transaction. */ export type SendSingleTransactionResult = SendAtomicTransactionComposerResults & ConfirmedTransactionResult @@ -51,10 +53,22 @@ export class AlgorandClient { /** * Tracks the given account for later signing. - * @param account The account to register + * @param account The account to register, which can be a `TransactionSignerAccount` or + * a `algosdk.Account`, `algosdk.LogicSigAccount`, `SigningAccount` or `MultisigAccount` + * @example + * ```typescript + * const accountManager = AlgorandClient.mainnet() + * .setSignerFromAccount(algosdk.generateAccount()) + * .setSignerFromAccount(new algosdk.LogicSigAccount(program, args)) + * .setSignerFromAccount(new SigningAccount(mnemonic, sender)) + * .setSignerFromAccount(new MultisigAccount({version: 1, threshold: 1, addrs: ["ADDRESS1...", "ADDRESS2..."]}, [account1, account2])) + * .setSignerFromAccount({addr: "SENDERADDRESS", signer: transactionSigner}) + * ``` * @returns The `AlgorandClient` so method calls can be chained */ - public setSignerFromAccount(account: TransactionSignerAccount | SendTransactionFrom) { + public setSignerFromAccount( + account: TransactionSignerAccount | TransactionSignerAccount | Account | LogicSigAccount | SigningAccount | MultisigAccount, + ) { this._accountManager.setSignerFromAccount(account) return this } @@ -134,8 +148,8 @@ export class AlgorandClient { preLog?: (params: T, transaction: Transaction) => string postLog?: (params: T, result: SendSingleTransactionResult) => string }, - ): (params: T, config?: ExecuteParams) => Promise { - return async (params, config) => { + ): (params: T & ExecuteParams) => Promise { + return async (params) => { const composer = this.newGroup() // Ensure `this` is properly populated @@ -143,10 +157,10 @@ export class AlgorandClient { if (log?.preLog) { const transaction = (await composer.build()).transactions.at(-1)!.txn - Config.getLogger(config?.suppressLog).debug(log.preLog(params, transaction)) + Config.getLogger(params?.suppressLog).debug(log.preLog(params, transaction)) } - const rawResult = await composer.execute(config) + const rawResult = await composer.execute(params) const result = { // Last item covers when a group is created by an app call with ABI transaction parameters transaction: rawResult.transactions[rawResult.transactions.length - 1], @@ -156,7 +170,7 @@ export class AlgorandClient { } if (log?.postLog) { - Config.getLogger(config?.suppressLog).debug(log.postLog(params, result)) + Config.getLogger(params?.suppressLog).debug(log.postLog(params, result)) } return result @@ -168,12 +182,87 @@ export class AlgorandClient { */ send = { /** - * Send a payment transaction. + * Send a payment transaction to transfer algos between accounts. + * @param params The parameters for the payment transaction + * @example Basic example + * ```typescript + * const result = await algorandClient.send.payment({ + * sender: 'SENDERADDRESS', + * receiver: 'RECEIVERADDRESS', + * amount: algosdk.algosToMicroalgos(1), + * }) + * ``` + * @example Advanced example + * ```typescript + * const result = await algorandClient.send.payment({ + * amount: (4).algos(), + * receiver: 'RECEIVERADDRESS', + * sender: 'SENDERADDRESS', + * closeRemainderTo: 'CLOSEREMAINDERTOADDRESS', + * lease: 'lease', + * note: 'note', + * // Use this with caution, it's generally better to use algorand.send.rekey + * rekeyTo: 'REKEYTOADDRESS', + * firstValidRound: 1000n, + * validityWindow: 10, + * extraFee: (1000).microAlgos(), + * staticFee: (1000).microAlgos(), + * // Max fee doesn't make sense with extraFee AND staticFee + * // already specified, but here for completeness + * maxFee: (3000).microAlgos(), + * // Signer only needed if you want to provide one, + * // generally you'd register it with AlgorandClient + * // against the sender nad not need to pass it in + * signer: transactionSigner, + * maxRoundsToWaitForConfirmation: 5, + * suppressLog: true, + * }) + * ``` + * + * @returns The result of the transaction and the transaction that was sent */ payment: this._send((c) => c.addPayment, { preLog: (params, transaction) => `Sending ${params.amount.microAlgos} µALGOs from ${params.sender} to ${params.receiver} via transaction ${transaction.txID()}`, }), + /** + * Rekey an account to a new address. + * + * **Note:** Please be careful with this function and be sure to read the [official rekey guidance](https://developer.algorand.org/docs/get-details/accounts/rekey/). + * + * @param params The parameters for the rekey transaction + * + * @example Basic example + * ```typescript + * await algorand.send.rekey({sender: "ACCOUNTADDRESS", rekeyTo: "NEWADDRESS"}) + * ``` + * @example Advanced example + * ```typescript + * await algorand.send.rekey({ + * sender: "ACCOUNTADDRESS", + * rekeyTo: "NEWADDRESS", + * lease: 'lease', + * note: 'note', + * firstValidRound: 1000n, + * validityWindow: 10, + * extraFee: (1000).microAlgos(), + * staticFee: (1000).microAlgos(), + * // Max fee doesn't make sense with extraFee AND staticFee + * // already specified, but here for completeness + * maxFee: (3000).microAlgos(), + * // Signer only needed if you want to provide one, + * // generally you'd register it with AlgorandClient + * // against the sender nad not need to pass it in + * signer: transactionSigner, + * maxRoundsToWaitForConfirmation: 5, + * suppressLog: true, + * }) + * ``` + * @returns The result of the transaction and the transaction that was sent + */ + rekey: this._send((c) => c.addRekey, { + postLog: (params, result) => `Rekeyed ${params.sender} to ${params.rekeyTo} via transaction ${result.txIds.at(-1)}`, + }), /** * Create an asset. */ @@ -213,6 +302,42 @@ export class AlgorandClient { preLog: (params, transaction) => `Opting in ${params.sender} to asset with ID ${params.assetId} via transaction ${transaction.txID()}`, }), + /** + * Opt an account out of an asset. + */ + assetOptOut: async ( + params: Omit & { + /** Optional asset creator account address; if not specified it will be retrieved from algod */ + creator?: string + /** Whether or not to check if the account has a zero balance first or not. + * + * If this is set to `true` and the account has an asset balance it will throw an error. + * + * If this is set to `false` and the account has an asset balance it will lose those assets to the asset creator. + */ + ensureZeroBalance: boolean + } & ExecuteParams, + ) => { + if (params.ensureZeroBalance) { + let balance = 0n + try { + const accountAssetInfo = await this.account.getAssetInformation(params.sender, params.assetId) + balance = accountAssetInfo.balance + } catch (e) { + throw new Error(`Account ${params.sender} is not opted-in to Asset ${params.assetId}; can't opt-out.`) + } + if (balance !== 0n) { + throw new Error(`Account ${params.sender} does not have a zero balance for Asset ${params.assetId}; can't opt-out.`) + } + } + + params.creator = params.creator ?? ((await this.client.algod.getAssetByID(Number(params.assetId)).do()).params.creator as string) + + return await this._send((c) => c.addAssetOptOut, { + preLog: (params, transaction) => + `Opting ${params.sender} out of asset with ID ${params.assetId} to creator ${params.creator} via transaction ${transaction.txID()}`, + })(params as AssetOptOutParams & ExecuteParams) + }, /** * Call a smart contract. * @@ -243,8 +368,70 @@ export class AlgorandClient { * Methods for building transactions */ transactions = { - /** Create a payment transaction. */ + /** + * Create a payment transaction to transfer algos between accounts. + * @param params The parameters for the payment transaction + * @example Basic example + * ```typescript + * const result = await algorandClient.send.payment({ + * sender: 'SENDERADDRESS', + * receiver: 'RECEIVERADDRESS', + * amount: algosdk.algosToMicroalgos(1), + * }) + * ``` + * @example Advanced example + * ```typescript + * const result = await algorandClient.send.payment({ + * amount: (4).algos(), + * receiver: 'RECEIVERADDRESS', + * sender: 'SENDERADDRESS', + * closeRemainderTo: 'CLOSEREMAINDERTOADDRESS', + * lease: 'lease', + * note: 'note', + * rekeyTo: 'REKEYTOADDRESS', + * firstValidRound: 1000n, + * validityWindow: 10, + * extraFee: (1000).microAlgos(), + * staticFee: (1000).microAlgos(), + * // Max fee doesn't make sense with extraFee AND staticFee + * // already specified, but here for completeness + * maxFee: (3000).microAlgos(), + * }) + * ``` + * + * @returns The payment transaction + */ payment: this._transaction((c) => c.addPayment), + /** + * Create a rekey transaction to rekey an account to a new address. + * + * **Note:** Please be careful with this function and be sure to read the [official rekey guidance](https://developer.algorand.org/docs/get-details/accounts/rekey/). + * + * @param params The parameters for the rekey transaction + * + * @example Basic example + * ```typescript + * await algorand.transactions.rekey({sender: "ACCOUNTADDRESS", rekeyTo: "NEWADDRESS"}) + * ``` + * @example Advanced example + * ```typescript + * await algorand.transactions.rekey({ + * sender: "ACCOUNTADDRESS", + * rekeyTo: "NEWADDRESS", + * lease: 'lease', + * note: 'note', + * firstValidRound: 1000n, + * validityWindow: 10, + * extraFee: (1000).microAlgos(), + * staticFee: (1000).microAlgos(), + * // Max fee doesn't make sense with extraFee AND staticFee + * // already specified, but here for completeness + * maxFee: (3000).microAlgos(), + * }) + * ``` + * @returns The rekey transaction + */ + rekey: this._transaction((c) => c.addRekey), /** Create an asset creation transaction. */ assetCreate: this._transaction((c) => c.addAssetCreate), /** Create an asset config transaction. */ @@ -257,6 +444,8 @@ export class AlgorandClient { assetTransfer: this._transaction((c) => c.addAssetTransfer), /** Create an asset opt-in transaction. */ assetOptIn: this._transaction((c) => c.addAssetOptIn), + /** Create an asset opt-out transaction. */ + assetOptOut: this._transaction((c) => c.addAssetOptOut), /** Create an application call transaction. */ appCall: this._transaction((c) => c.addAppCall), /** Create an application call with ABI method call transaction. */ diff --git a/src/types/client-manager.ts b/src/types/client-manager.ts index e7159d87..a37c23de 100644 --- a/src/types/client-manager.ts +++ b/src/types/client-manager.ts @@ -158,10 +158,10 @@ export class ClientManager { /** * Returns a TestNet Dispenser API client. + * * Refer to [docs](https://github.com/algorandfoundation/algokit/blob/main/docs/testnet_api.md) on guidance to obtain an access token. * * @param params An object containing parameters for the TestNetDispenserApiClient class. - * Or null if you want the client to load the access token from the environment variable `ALGOKIT_DISPENSER_ACCESS_TOKEN`. * @example * const client = clientManager.getTestNetDispenser( * { @@ -172,10 +172,29 @@ export class ClientManager { * * @returns An instance of the TestNetDispenserApiClient class. */ - public getTestNetDispenser(params: TestNetDispenserApiClientParams | null = null) { + public getTestNetDispenser(params: TestNetDispenserApiClientParams) { return new TestNetDispenserApiClient(params) } + /** + * Returns a TestNet Dispenser API client, loading the auth token from `process.env.ALGOKIT_DISPENSER_ACCESS_TOKEN`. + * + * Refer to [docs](https://github.com/algorandfoundation/algokit/blob/main/docs/testnet_api.md) on guidance to obtain an access token. + * + * @param params An object containing parameters for the TestNetDispenserApiClient class. + * @example + * const client = clientManager.getTestNetDispenserFromEnvironment( + * { + * requestTimeout: 15, + * } + * ) + * + * @returns An instance of the TestNetDispenserApiClient class. + */ + public getTestNetDispenserFromEnvironment(params?: Omit) { + return new TestNetDispenserApiClient(params ? { ...params, authToken: '' } : undefined) + } + /** * Returns a new `ApplicationClient` client, resolving the app by creator address and name. * @param details The details to resolve the app by creator address and name diff --git a/src/types/composer.ts b/src/types/composer.ts index f64a0070..3edab36b 100644 --- a/src/types/composer.ts +++ b/src/types/composer.ts @@ -9,15 +9,20 @@ import TransactionWithSigner = algosdk.TransactionWithSigner import isTransactionWithSigner = algosdk.isTransactionWithSigner import encodeAddress = algosdk.encodeAddress +export const MAX_TRANSACTION_GROUP_SIZE = 16 + /** Common parameters for defining a transaction. */ export type CommonTransactionParams = { /** The address sending the transaction */ sender: string /** The function used to sign transactions */ signer?: algosdk.TransactionSigner | TransactionSignerAccount - /** Change the signing key of the sender to the given address */ + /** Change the signing key of the sender to the given address. + * + * **Warning:** Please be careful with this parameter and be sure to read the [official rekey guidance](https://developer.algorand.org/docs/get-details/accounts/rekey/). + */ rekeyTo?: string - /** Note to attach to the transaction*/ + /** Note to attach to the transaction */ note?: Uint8Array | string /** Prevent multiple transactions with the same lease being included within the validity window */ lease?: Uint8Array | string @@ -49,30 +54,125 @@ export type PaymentParams = CommonTransactionParams & { closeRemainderTo?: string } -/** Parameters to define an asset create transaction. */ +/** Parameters to define a rekey transaction. */ +export type RekeyParams = CommonTransactionParams & { + /** Change the signing key of the sender to the given address. + * + * **Warning:** Please be careful with this parameter and be sure to read the [official rekey guidance](https://developer.algorand.org/docs/get-details/accounts/rekey/). + */ + rekeyTo: string +} + +/** Parameters to define an asset create transaction. + * + * The account that sends this transaction will automatically be opted in to the asset and will hold all units after creation. + */ export type AssetCreateParams = CommonTransactionParams & { - /** The total amount of the smallest divisible unit to create */ + /** The total amount of the smallest divisible (decimal) unit to create. + * + * For example, if `decimals` is, say, 2, then for every 100 `total` there would be 1 whole unit. + * + * This field can only be specified upon asset creation. + */ total: bigint - /** The amount of decimal places the asset should have */ + + /** The amount of decimal places the asset should have. + * + * * If 0, the asset is not divisible; + * * If 1, the base unit of the asset is in tenths; + * * If 2, the base unit of the asset is in hundredths; + * * If 3, the base unit of the asset is in thousandths; + * * and so on up to 19 decimal places. + * + * This field can only be specified upon asset creation. + */ decimals?: number - /** Whether the asset is frozen by default in the creator address */ + + /** Whether the asset is frozen by default in the creator address. + * Defaults to `false`. + * + * If `true` then for anyone apart from the creator to hold the + * asset it needs to be unfrozen per account using an asset freeze + * transaction from the `freeze` account, which must be set on creation. + * + * This field can only be specified upon asset creation. + */ defaultFrozen?: boolean - /** The address that can change the manager, reserve, clawback, and freeze addresses. There will permanently be no manager if undefined or an empty string */ + + /** The address of the optional account that can manage the configuration of the asset and destroy it. + * + * The configuration fields it can change are `manager`, `reserve`, `clawback`, and `freeze`. + * + * If not set (`undefined` or `""`) at asset creation or subsequently set to empty by the `manager` the asset becomes permanently immutable. + */ manager?: string - /** The address that holds the uncirculated supply */ + + /** + * The address of the optional account that holds the reserve (uncirculated supply) units of the asset. + * + * This address has no specific authority in the protocol itself and is informational only. + * + * Some standards like [ARC-19](https://github.com/algorandfoundation/ARCs/blob/main/ARCs/arc-0019.md) + * rely on this field to hold meaningful data. + * + * It can be used in the case where you want to signal to holders of your asset that the uncirculated units + * of the asset reside in an account that is different from the default creator account. + * + * If not set (`undefined` or `""`) at asset creation or subsequently set to empty by the manager the field is permanently empty. + */ reserve?: string - /** The address that can freeze the asset in any account. Freezing will be permanently disabled if undefined or an empty string. */ + + /** + * The address of the optional account that can be used to freeze or unfreeze holdings of this asset for any account. + * + * If empty, freezing is not permitted. + * + * If not set (`undefined` or `""`) at asset creation or subsequently set to empty by the manager the field is permanently empty. + */ freeze?: string - /** The address that can clawback the asset from any account. Clawback will be permanently disabled if undefined or an empty string. */ + + /** + * The address of the optional account that can clawback holdings of this asset from any account. + * + * **This field should be used with caution** as the clawback account has the ability to **unconditionally take assets from any account**. + * + * If empty, clawback is not permitted. + * + * If not set (`undefined` or `""`) at asset creation or subsequently set to empty by the manager the field is permanently empty. + */ clawback?: string - /** The short ticker name for the asset */ + + /** The optional name of the unit of this asset (e.g. ticker name). + * + * Max size is 8 bytes. + * + * This field can only be specified upon asset creation. + */ unitName?: string - /** The full name of the asset */ + + /** The optional name of the asset. + * + * Max size is 32 bytes. + * + * This field can only be specified upon asset creation. + */ assetName?: string - /** The metadata URL for the asset */ + + /** Specifies an optional URL where more information about the asset can be retrieved (e.g. metadata). + * + * Max size is 96 bytes. + * + * This field can only be specified upon asset creation. + */ url?: string - /** Hash of the metadata contained in the metadata URL */ - metadataHash?: Uint8Array + + /** 32-byte hash of some metadata that is relevant to your asset and/or asset holders. + * + * The format of this metadata is up to the application. + * + * This field can only be specified upon asset creation. + */ + metadataHash?: string | Uint8Array } /** Parameters to define an asset config transaction. */ @@ -125,6 +225,17 @@ export type AssetOptInParams = CommonTransactionParams & { assetId: bigint } +/** Parameters to define an asset opt-out transaction. */ +export type AssetOptOutParams = CommonTransactionParams & { + /** ID of the asset */ + assetId: bigint + /** + * The address of the asset creator account to close the asset + * position to (any remaining asset units will be sent to this account) + */ + creator: string +} + /** Parameters to define an online key registration transaction. */ export type OnlineKeyRegistrationParams = CommonTransactionParams & { /** The root participation public key */ @@ -201,12 +312,14 @@ export type MethodCallParams = CommonTransactionParams & type Txn = | (PaymentParams & { type: 'pay' }) + | (RekeyParams & { type: 'rekey' }) | (AssetCreateParams & { type: 'assetCreate' }) | (AssetConfigParams & { type: 'assetConfig' }) | (AssetFreezeParams & { type: 'assetFreeze' }) | (AssetDestroyParams & { type: 'assetDestroy' }) | (AssetTransferParams & { type: 'assetTransfer' }) | (AssetOptInParams & { type: 'assetOptIn' }) + | (AssetOptOutParams & { type: 'assetOptOut' }) | (AppCallParams & { type: 'appCall' }) | (OnlineKeyRegistrationParams & { type: 'keyReg' }) | (algosdk.TransactionWithSigner & { type: 'txnWithSigner' }) @@ -281,6 +394,8 @@ export default class AlgokitComposer { /** * Add a payment transaction to the transaction group. + * + * **Warning:** Please be careful with this parameter and be sure to read the [official rekey guidance](https://developer.algorand.org/docs/get-details/accounts/rekey/). * @param params The payment transaction parameters * @returns The composer so you can chain method calls */ @@ -290,6 +405,17 @@ export default class AlgokitComposer { return this } + /** + * Add a rekey transaction to the transaction group. + * @param params The rekey transaction parameters + * @returns The composer so you can chain method calls + */ + addRekey(params: RekeyParams): AlgokitComposer { + this.txns.push({ ...params, type: 'rekey' }) + + return this + } + /** * Add an asset create transaction to the transaction group. * @param params The asset create transaction parameters @@ -356,6 +482,17 @@ export default class AlgokitComposer { return this } + /** + * Add an asset opt-out transaction to the transaction group. + * @param params The asset opt-out transaction parameters + * @returns The composer so you can chain method calls + */ + addAssetOptOut(params: AssetOptOutParams): AlgokitComposer { + this.txns.push({ ...params, type: 'assetOptOut' }) + + return this + } + /** * Add an application call transaction to the transaction group. * @@ -692,6 +829,10 @@ export default class AlgokitComposer { const payment = this.buildPayment(txn, suggestedParams) return [{ txn: payment, signer }] } + case 'rekey': { + const rekey = this.buildPayment({ ...txn, receiver: txn.sender, amount: (0).microAlgos() }, suggestedParams) + return [{ txn: rekey, signer }] + } case 'assetCreate': { const assetCreate = this.buildAssetCreate(txn, suggestedParams) return [{ txn: assetCreate, signer }] @@ -720,6 +861,13 @@ export default class AlgokitComposer { const assetTransfer = this.buildAssetTransfer({ ...txn, receiver: txn.sender, amount: 0n }, suggestedParams) return [{ txn: assetTransfer, signer }] } + case 'assetOptOut': { + const assetTransfer = this.buildAssetTransfer( + { ...txn, receiver: txn.sender, amount: 0n, closeAssetTo: txn.creator }, + suggestedParams, + ) + return [{ txn: assetTransfer, signer }] + } case 'keyReg': { const keyReg = this.buildKeyReg(txn, suggestedParams) return [{ txn: keyReg, signer }] diff --git a/src/types/dispenser-client.spec.ts b/src/types/dispenser-client.spec.ts index 5a1971de..9e1b2240 100644 --- a/src/types/dispenser-client.spec.ts +++ b/src/types/dispenser-client.spec.ts @@ -17,7 +17,7 @@ describe('TestNetDispenserApiClient', () => { const mockResponse = { txID: 'dummy_tx_id', amount: 1 } fetchMock.mockResponseOnce(JSON.stringify(mockResponse)) - const dispenserClient = new TestNetDispenserApiClient({ authToken: 'dummy_auth_token', requestTimeout: null }) + const dispenserClient = new TestNetDispenserApiClient({ authToken: 'dummy_auth_token' }) const address = 'dummy_address' const amount = 1 @@ -29,7 +29,7 @@ describe('TestNetDispenserApiClient', () => { it('should register refund with auth token', async () => { fetchMock.mockResponseOnce(JSON.stringify({})) - const dispenserClient = new TestNetDispenserApiClient({ authToken: 'dummy_auth_token', requestTimeout: null }) + const dispenserClient = new TestNetDispenserApiClient({ authToken: 'dummy_auth_token' }) const refundTxnId = 'dummy_txn_id' await dispenserClient.refund(refundTxnId) @@ -47,24 +47,24 @@ describe('TestNetDispenserApiClient', () => { const mockResponse = { amount: amount } fetchMock.mockResponseOnce(JSON.stringify(mockResponse)) - const dispenserClient = new TestNetDispenserApiClient({ authToken: 'dummy_auth_token', requestTimeout: null }) + const dispenserClient = new TestNetDispenserApiClient({ authToken: 'dummy_auth_token' }) const response = await dispenserClient.getLimit() expect(response.amount).toEqual(amount) }) it('should throw error when no auth token provided', () => { - expect(() => new TestNetDispenserApiClient(null)).toThrow() + expect(() => new TestNetDispenserApiClient()).toThrow() }) it('should init with environment variable', () => { process.env.ALGOKIT_DISPENSER_ACCESS_TOKEN = 'dummy_token' - const client = new TestNetDispenserApiClient(null) + const client = new TestNetDispenserApiClient() expect(client.authToken).toEqual('dummy_token') }) it('should init with argument over environment variable', () => { process.env.ALGOKIT_DISPENSER_ACCESS_TOKEN = 'dummy_token' - const client = new TestNetDispenserApiClient({ authToken: 'test_value_2', requestTimeout: null }) + const client = new TestNetDispenserApiClient({ authToken: 'test_value_2' }) expect(client.authToken).toEqual('test_value_2') }) }) diff --git a/src/types/dispenser-client.ts b/src/types/dispenser-client.ts index 05370334..c107d981 100644 --- a/src/types/dispenser-client.ts +++ b/src/types/dispenser-client.ts @@ -1,6 +1,6 @@ -const baseUrl = 'https://api.dispenser.algorandfoundation.tools' -const dispenserRequestTimeout = 15 -const dispenserAccessTokenKey = 'ALGOKIT_DISPENSER_ACCESS_TOKEN' +const DISPENSER_BASE_URL = 'https://api.dispenser.algorandfoundation.tools' +const DEFAULT_DISPENSER_REQUEST_TIMEOUT = 15 +const DISPENSER_ACCESS_TOKEN_KEY = 'ALGOKIT_DISPENSER_ACCESS_TOKEN' enum DispenserAssetName { Algo = 0, @@ -25,7 +25,7 @@ export interface DispenserLimitResponse { export interface TestNetDispenserApiClientParams { authToken: string - requestTimeout: number | null + requestTimeout?: number } /** @@ -58,8 +58,8 @@ export class TestNetDispenserApiClient { private _authToken: string private _requestTimeout: number - constructor(params: TestNetDispenserApiClientParams | null) { - const authTokenFromEnv = process.env[dispenserAccessTokenKey] + constructor(params?: TestNetDispenserApiClientParams) { + const authTokenFromEnv = process?.env?.[DISPENSER_ACCESS_TOKEN_KEY] if (params?.authToken) { this._authToken = params.authToken @@ -67,11 +67,11 @@ export class TestNetDispenserApiClient { this._authToken = authTokenFromEnv } else { throw new Error( - `Can't init AlgoKit TestNet Dispenser API client because neither environment variable ${dispenserAccessTokenKey} or the authToken were provided.`, + `Can't init AlgoKit TestNet Dispenser API client because neither environment variable ${DISPENSER_ACCESS_TOKEN_KEY} or the authToken were provided.`, ) } - this._requestTimeout = params?.requestTimeout || dispenserRequestTimeout + this._requestTimeout = params?.requestTimeout || DEFAULT_DISPENSER_REQUEST_TIMEOUT } get authToken(): string { @@ -110,7 +110,7 @@ export class TestNetDispenserApiClient { requestArgs.body = JSON.stringify(body) } - const response = await fetch(`${baseUrl}/${urlSuffix}`, requestArgs) + const response = await fetch(`${DISPENSER_BASE_URL}/${urlSuffix}`, requestArgs) if (!response.ok) { let error_message = `Error processing dispenser API request: ${response.status}` let error_response = null @@ -135,7 +135,7 @@ export class TestNetDispenserApiClient { * Sends a funding request to the dispenser API to fund the specified address with the given amount of Algo. * * @param address - The address to fund. - * @param amount - The amount of Algo to fund. + * @param amount - The amount of microAlgos to fund. * * @returns DispenserFundResponse: An object containing the transaction ID and funded amount. */ diff --git a/src/util.ts b/src/util.ts index 30f8cde5..51e80f14 100644 --- a/src/util.ts +++ b/src/util.ts @@ -49,3 +49,27 @@ export const calculateFundAmount = ( export const isNode = () => { return typeof process !== 'undefined' && process.versions != null && process.versions.node != null } + +/** + * Returns the given array split into chunks of `batchSize` batches. + * @param array The array to chunk + * @param batchSize The size of batches to split the array into + * @returns A generator that yields the array split into chunks of `batchSize` batches + */ +export function* chunkArray(array: T[], batchSize: number): Generator { + for (let i = 0; i < array.length; i += batchSize) yield array.slice(i, i + batchSize) +} + +/** + * Memoize calls to the given function in an in-memory map. + * @param fn The function to memoize + * @returns The memoized function + */ +export const memoize = (fn: (val: T) => R) => { + const cache = new Map() + const cached = function (this: unknown, val: T) { + return cache.has(val) ? cache.get(val) : cache.set(val, fn.call(this, val)) && cache.get(val) + } + cached.cache = cache + return cached as (val: T) => R +} From 4370e08122101de3e057dcb1fe86f65f92f0d697 Mon Sep 17 00:00:00 2001 From: "Rob Moore (MakerX)" Date: Sun, 16 Jun 2024 23:55:13 +0800 Subject: [PATCH 02/18] feat: Deprecated asset and transfer modules Added: * `AssetManager` class and `algorand.asset.getById()` * `indexer` export off of `@algorandfoundation/algokit-utils` as the future home of all indexer methods Changed: * Order of `algorand.account.rekeyed()` parameters to be `rekeyed(sender, signer)` since it conceptually makes more sense (the sender is rekeyed so should come first) * All microAlgo return values from `algorand.account.getInformation()` now return an `AlgoAmount`, renamed `amount` to `balance` and `round` to `validAsAtRound` (which is now a `bigint` for broader consistency) * Return value of `algorand.send.assetCreate` now includes `{ assetId: bigint }` Deprecated: * `algokit.createAsset` * `algokit.assetOptIn` * `algokit.assetOptOut` * `algokit.assetBulkOptIn` * `algokit.assetBulkOptOut` * `algokit.ensureFunded` * `algokit.transferAsset` * `algokit.rekeyAccount` * `algokit.transferAlgos` --- docs/capabilities/account.md | 2 +- .../types_asset_manager.AssetManager.md | 89 ++++ .../types_asset_manager.AssetInformation.md | 270 ++++++++++ docs/code/modules/index.indexer.md | 174 +++++++ .../types_algorand_client_asset_spec.md | 3 + .../types_algorand_client_transfer_spec.md | 3 + docs/code/modules/types_asset_manager.md | 13 + src/account/account.ts | 31 +- src/app.spec.ts | 2 +- src/asset.spec.ts | 205 -------- src/asset.ts | 14 +- src/index.ts | 7 +- src/testing/_asset.ts | 37 +- src/testing/account.ts | 2 +- src/transfer/transfer-algos.ts | 2 + src/transfer/transfer.spec.ts | 467 ------------------ src/transfer/transfer.ts | 7 + src/types/account-manager.spec.ts | 2 +- src/types/account-manager.ts | 40 +- src/types/account.ts | 147 +++++- src/types/algorand-client.asset.spec.ts | 198 ++++++++ src/types/algorand-client.spec.ts | 42 +- src/types/algorand-client.transfer.spec.ts | 378 ++++++++++++++ src/types/algorand-client.ts | 23 +- src/types/app-client.spec.ts | 2 +- src/types/asset-manager.ts | 174 +++++++ src/types/asset.ts | 8 +- src/types/composer.ts | 4 +- src/types/transfer.ts | 9 +- 29 files changed, 1588 insertions(+), 767 deletions(-) create mode 100644 docs/code/classes/types_asset_manager.AssetManager.md create mode 100644 docs/code/interfaces/types_asset_manager.AssetInformation.md create mode 100644 docs/code/modules/index.indexer.md create mode 100644 docs/code/modules/types_algorand_client_asset_spec.md create mode 100644 docs/code/modules/types_algorand_client_transfer_spec.md create mode 100644 docs/code/modules/types_asset_manager.md delete mode 100644 src/asset.spec.ts delete mode 100644 src/transfer/transfer.spec.ts create mode 100644 src/types/algorand-client.asset.spec.ts create mode 100644 src/types/algorand-client.transfer.spec.ts create mode 100644 src/types/asset-manager.ts diff --git a/docs/capabilities/account.md b/docs/capabilities/account.md index 13c7a76c..5d24e4bb 100644 --- a/docs/capabilities/account.md +++ b/docs/capabilities/account.md @@ -50,7 +50,7 @@ In order to get/register accounts for signing operations you can use the followi - Note: `fundWith` allows you to control how many ALGOs are seeded into an account created in KMD - [`algorand.account.fromMnemonic(mnemonicSecret, sender?)`](../code/classes/types_account_manager.AccountManager.md#frommnemonic) - Registers and returns an account with secret key loaded by taking the mnemonic secret - [`algorand.account.multisig(multisigParams, signingAccounts)`](../code/classes/types_account_manager.AccountManager.md#multisig) - Registers and returns a multisig account with one or more signing keys loaded -- [`algorand.account.rekeyed(signer, sender)`](../code/classes/types_account_manager.AccountManager.md#rekeyed) - Registers and returns an account representing the given rekeyed sender/signer combination +- [`algorand.account.rekeyed(sender, signer)`](../code/classes/types_account_manager.AccountManager.md#rekeyed) - Registers and returns an account representing the given rekeyed sender/signer combination - [`algorand.account.random()`](../code/classes/types_account_manager.AccountManager.md#random) - Returns a new, cryptographically randomly generated account with private key loaded - [`algorand.account.fromKmd()`](../code/classes/types_account_manager.AccountManager.md#fromkmd) - Returns an account with private key loaded from the given KMD wallet (identified by name) - [`algorand.account.logicsig(program, args?)`](../code/classes/types_account_manager.AccountManager.md#logicsig) - Returns an account that represents a logic signature diff --git a/docs/code/classes/types_asset_manager.AssetManager.md b/docs/code/classes/types_asset_manager.AssetManager.md new file mode 100644 index 00000000..2fae1315 --- /dev/null +++ b/docs/code/classes/types_asset_manager.AssetManager.md @@ -0,0 +1,89 @@ +[@algorandfoundation/algokit-utils](../README.md) / [types/asset-manager](../modules/types_asset_manager.md) / AssetManager + +# Class: AssetManager + +[types/asset-manager](../modules/types_asset_manager.md).AssetManager + +Allows management of asset information. + +## Table of contents + +### Constructors + +- [constructor](types_asset_manager.AssetManager.md#constructor) + +### Properties + +- [\_clientManager](types_asset_manager.AssetManager.md#_clientmanager) + +### Methods + +- [getById](types_asset_manager.AssetManager.md#getbyid) + +## Constructors + +### constructor + +• **new AssetManager**(`clientManager`): [`AssetManager`](types_asset_manager.AssetManager.md) + +Create a new asset manager. + +#### Parameters + +| Name | Type | Description | +| :------ | :------ | :------ | +| `clientManager` | [`ClientManager`](types_client_manager.ClientManager.md) | The ClientManager client to use for algod client | + +#### Returns + +[`AssetManager`](types_asset_manager.AssetManager.md) + +**`Example`** + +```typescript +const assetManager = new AssetManager(clientManager) +``` + +#### Defined in + +[src/types/asset-manager.ts:137](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/asset-manager.ts#L137) + +## Properties + +### \_clientManager + +• `Private` **\_clientManager**: [`ClientManager`](types_client_manager.ClientManager.md) + +#### Defined in + +[src/types/asset-manager.ts:127](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/asset-manager.ts#L127) + +## Methods + +### getById + +▸ **getById**(`assetId`): `Promise`\<[`AssetInformation`](../interfaces/types_asset_manager.AssetInformation.md)\> + +Returns the current asset information for the asset with the given ID. + +#### Parameters + +| Name | Type | Description | +| :------ | :------ | :------ | +| `assetId` | `bigint` | The ID of the asset | + +#### Returns + +`Promise`\<[`AssetInformation`](../interfaces/types_asset_manager.AssetInformation.md)\> + +The asset information + +**`Example`** + +```typescript +const assetInfo = await assetManager.getById(12353n); +``` + +#### Defined in + +[src/types/asset-manager.ts:152](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/asset-manager.ts#L152) diff --git a/docs/code/interfaces/types_asset_manager.AssetInformation.md b/docs/code/interfaces/types_asset_manager.AssetInformation.md new file mode 100644 index 00000000..2b5218f5 --- /dev/null +++ b/docs/code/interfaces/types_asset_manager.AssetInformation.md @@ -0,0 +1,270 @@ +[@algorandfoundation/algokit-utils](../README.md) / [types/asset-manager](../modules/types_asset_manager.md) / AssetInformation + +# Interface: AssetInformation + +[types/asset-manager](../modules/types_asset_manager.md).AssetInformation + +## Table of contents + +### Properties + +- [assetId](types_asset_manager.AssetInformation.md#assetid) +- [assetName](types_asset_manager.AssetInformation.md#assetname) +- [assetNameAsBytes](types_asset_manager.AssetInformation.md#assetnameasbytes) +- [clawback](types_asset_manager.AssetInformation.md#clawback) +- [creator](types_asset_manager.AssetInformation.md#creator) +- [decimals](types_asset_manager.AssetInformation.md#decimals) +- [defaultFrozen](types_asset_manager.AssetInformation.md#defaultfrozen) +- [freeze](types_asset_manager.AssetInformation.md#freeze) +- [manager](types_asset_manager.AssetInformation.md#manager) +- [metadataHash](types_asset_manager.AssetInformation.md#metadatahash) +- [reserve](types_asset_manager.AssetInformation.md#reserve) +- [total](types_asset_manager.AssetInformation.md#total) +- [unitName](types_asset_manager.AssetInformation.md#unitname) +- [unitNameAsBytes](types_asset_manager.AssetInformation.md#unitnameasbytes) +- [url](types_asset_manager.AssetInformation.md#url) +- [urlAsBytes](types_asset_manager.AssetInformation.md#urlasbytes) + +## Properties + +### assetId + +• **assetId**: `bigint` + +The ID of the asset. + +#### Defined in + +[src/types/asset-manager.ts:7](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/asset-manager.ts#L7) + +___ + +### assetName + +• `Optional` **assetName**: `string` + +The optional name of the asset. + +Max size is 32 bytes. + +#### Defined in + +[src/types/asset-manager.ts:98](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/asset-manager.ts#L98) + +___ + +### assetNameAsBytes + +• `Optional` **assetNameAsBytes**: `Uint8Array` + +The optional name of the asset. + +Max size is 32 bytes. + +#### Defined in + +[src/types/asset-manager.ts:104](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/asset-manager.ts#L104) + +___ + +### clawback + +• `Optional` **clawback**: `string` + +The address of the optional account that can clawback holdings of this asset from any account. + +The clawback account has the ability to **unconditionally take assets from any account**. + +If empty, clawback is not permitted. + +If not set the field is permanently empty. + +#### Defined in + +[src/types/asset-manager.ts:80](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/asset-manager.ts#L80) + +___ + +### creator + +• **creator**: `string` + +The address of the account that created the asset. + +This is the address where the parameters for this asset can be found, +and also the address where unwanted asset units can be sent when +closing out an asset position and opting-out of the asset. + +#### Defined in + +[src/types/asset-manager.ts:15](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/asset-manager.ts#L15) + +___ + +### decimals + +• **decimals**: `number` + +The amount of decimal places the asset was created with. + +* If 0, the asset is not divisible; +* If 1, the base unit of the asset is in tenths; +* If 2, the base unit of the asset is in hundredths; +* If 3, the base unit of the asset is in thousandths; +* and so on up to 19 decimal places. + +#### Defined in + +[src/types/asset-manager.ts:31](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/asset-manager.ts#L31) + +___ + +### defaultFrozen + +• `Optional` **defaultFrozen**: `boolean` + +Whether the asset was frozen by default for all accounts. + +If `true` then for anyone apart from the creator to hold the +asset it needs to be unfrozen per account using an asset freeze +transaction from the `freeze` account. + +#### Defined in + +[src/types/asset-manager.ts:39](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/asset-manager.ts#L39) + +___ + +### freeze + +• `Optional` **freeze**: `string` + +The address of the optional account that can be used to freeze or unfreeze holdings of this asset for any account. + +If empty, freezing is not permitted. + +If not set the field is permanently empty. + +#### Defined in + +[src/types/asset-manager.ts:69](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/asset-manager.ts#L69) + +___ + +### manager + +• `Optional` **manager**: `string` + +The address of the optional account that can manage the configuration of the asset and destroy it. + +If not set the asset is permanently immutable. + +#### Defined in + +[src/types/asset-manager.ts:45](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/asset-manager.ts#L45) + +___ + +### metadataHash + +• `Optional` **metadataHash**: `Uint8Array` + +32-byte hash of some metadata that is relevant to the asset and/or asset holders. + +The format of this metadata is up to the application. + +#### Defined in + +[src/types/asset-manager.ts:122](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/asset-manager.ts#L122) + +___ + +### reserve + +• `Optional` **reserve**: `string` + +The address of the optional account that holds the reserve (uncirculated supply) units of the asset. + +This address has no specific authority in the protocol itself and is informational only. + +Some standards like [ARC-19](https://github.com/algorandfoundation/ARCs/blob/main/ARCs/arc-0019.md) +rely on this field to hold meaningful data. + +It can be used in the case where you want to signal to holders of your asset that the uncirculated units +of the asset reside in an account that is different from the default creator account. + +If not set the field is permanently empty. + +#### Defined in + +[src/types/asset-manager.ts:60](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/asset-manager.ts#L60) + +___ + +### total + +• **total**: `bigint` + +The total amount of the smallest divisible (decimal) units that were created of the asset. + +For example, if `decimals` is, say, 2, then for every 100 `total` there is 1 whole unit. + +#### Defined in + +[src/types/asset-manager.ts:21](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/asset-manager.ts#L21) + +___ + +### unitName + +• `Optional` **unitName**: `string` + +The optional name of the unit of this asset (e.g. ticker name). + +Max size is 8 bytes. + +#### Defined in + +[src/types/asset-manager.ts:86](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/asset-manager.ts#L86) + +___ + +### unitNameAsBytes + +• `Optional` **unitNameAsBytes**: `Uint8Array` + +The optional name of the unit of this asset (e.g. ticker name). + +Max size is 8 bytes. + +#### Defined in + +[src/types/asset-manager.ts:92](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/asset-manager.ts#L92) + +___ + +### url + +• `Optional` **url**: `string` + +Optional URL where more information about the asset can be retrieved (e.g. metadata). + +Max size is 96 bytes. + +#### Defined in + +[src/types/asset-manager.ts:110](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/asset-manager.ts#L110) + +___ + +### urlAsBytes + +• `Optional` **urlAsBytes**: `Uint8Array` + +Optional URL where more information about the asset can be retrieved (e.g. metadata). + +Max size is 96 bytes. + +#### Defined in + +[src/types/asset-manager.ts:116](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/asset-manager.ts#L116) diff --git a/docs/code/modules/index.indexer.md b/docs/code/modules/index.indexer.md new file mode 100644 index 00000000..594f7f92 --- /dev/null +++ b/docs/code/modules/index.indexer.md @@ -0,0 +1,174 @@ +[@algorandfoundation/algokit-utils](../README.md) / [index](index.md) / indexer + +# Namespace: indexer + +[index](index.md).indexer + +## Table of contents + +### Functions + +- [executePaginatedRequest](index.indexer.md#executepaginatedrequest) +- [lookupAccountByAddress](index.indexer.md#lookupaccountbyaddress) +- [lookupAccountCreatedApplicationByAddress](index.indexer.md#lookupaccountcreatedapplicationbyaddress) +- [lookupAssetHoldings](index.indexer.md#lookupassetholdings) +- [lookupTransactionById](index.indexer.md#lookuptransactionbyid) +- [searchTransactions](index.indexer.md#searchtransactions) + +## Functions + +### executePaginatedRequest + +▸ **executePaginatedRequest**\<`TResult`, `TRequest`\>(`extractItems`, `buildRequest`): `Promise`\<`TResult`[]\> + +#### Type parameters + +| Name | Type | +| :------ | :------ | +| `TResult` | `TResult` | +| `TRequest` | extends `Object` | + +#### Parameters + +| Name | Type | +| :------ | :------ | +| `extractItems` | (`response`: `any`) => `TResult`[] | +| `buildRequest` | (`nextToken?`: `string`) => `TRequest` | + +#### Returns + +`Promise`\<`TResult`[]\> + +#### Defined in + +[src/indexer-lookup.ts:152](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/indexer-lookup.ts#L152) + +___ + +### lookupAccountByAddress + +▸ **lookupAccountByAddress**(`accountAddress`, `indexer`): `Promise`\<[`AccountLookupResult`](../interfaces/types_indexer.AccountLookupResult.md)\> + +Looks up an account by address using Indexer. + +#### Parameters + +| Name | Type | Description | +| :------ | :------ | :------ | +| `accountAddress` | `string` | The address of the account to look up | +| `indexer` | `default` | An indexer client | + +#### Returns + +`Promise`\<[`AccountLookupResult`](../interfaces/types_indexer.AccountLookupResult.md)\> + +The result of the look-up + +#### Defined in + +[src/indexer-lookup.ts:33](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/indexer-lookup.ts#L33) + +___ + +### lookupAccountCreatedApplicationByAddress + +▸ **lookupAccountCreatedApplicationByAddress**(`indexer`, `address`, `getAll?`, `paginationLimit?`): `Promise`\<[`ApplicationResult`](../interfaces/types_indexer.ApplicationResult.md)[]\> + +Looks up applications that were created by the given address; will automatically paginate through all data. + +#### Parameters + +| Name | Type | Default value | Description | +| :------ | :------ | :------ | :------ | +| `indexer` | `default` | `undefined` | An indexer instance | +| `address` | `string` | `undefined` | The address of the creator to look up | +| `getAll` | `undefined` \| `boolean` | `undefined` | Whether or not to include deleted applications | +| `paginationLimit?` | `number` | `undefined` | The number of records to return per paginated request, default 1000 | + +#### Returns + +`Promise`\<[`ApplicationResult`](../interfaces/types_indexer.ApplicationResult.md)[]\> + +The list of application results + +#### Defined in + +[src/indexer-lookup.ts:45](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/indexer-lookup.ts#L45) + +___ + +### lookupAssetHoldings + +▸ **lookupAssetHoldings**(`indexer`, `assetId`, `options?`, `paginationLimit?`): `Promise`\<[`MiniAssetHolding`](../interfaces/types_indexer.MiniAssetHolding.md)[]\> + +Looks up asset holdings for the given asset; will automatically paginate through all data. + +#### Parameters + +| Name | Type | Description | +| :------ | :------ | :------ | +| `indexer` | `default` | An indexer instance | +| `assetId` | `number` \| `bigint` | The ID of the asset to look up holdings for | +| `options?` | [`LookupAssetHoldingsOptions`](../interfaces/types_indexer.LookupAssetHoldingsOptions.md) | Optional options to control the lookup | +| `paginationLimit?` | `number` | The number of records to return per paginated request, default 1000 | + +#### Returns + +`Promise`\<[`MiniAssetHolding`](../interfaces/types_indexer.MiniAssetHolding.md)[]\> + +The list of application results + +#### Defined in + +[src/indexer-lookup.ts:79](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/indexer-lookup.ts#L79) + +___ + +### lookupTransactionById + +▸ **lookupTransactionById**(`transactionId`, `indexer`): `Promise`\<[`TransactionLookupResult`](../interfaces/types_indexer.TransactionLookupResult.md)\> + +Looks up a transaction by ID using Indexer. + +#### Parameters + +| Name | Type | Description | +| :------ | :------ | :------ | +| `transactionId` | `string` | The ID of the transaction to look up | +| `indexer` | `default` | An indexer client | + +#### Returns + +`Promise`\<[`TransactionLookupResult`](../interfaces/types_indexer.TransactionLookupResult.md)\> + +The result of the look-up + +#### Defined in + +[src/indexer-lookup.ts:23](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/indexer-lookup.ts#L23) + +___ + +### searchTransactions + +▸ **searchTransactions**(`indexer`, `searchCriteria`, `paginationLimit?`): `Promise`\<[`TransactionSearchResults`](../interfaces/types_indexer.TransactionSearchResults.md)\> + +Allows transactions to be searched for the given criteria. + +#### Parameters + +| Name | Type | Description | +| :------ | :------ | :------ | +| `indexer` | `default` | An indexer client | +| `searchCriteria` | (`s`: `default`) => `default` | The criteria to search for | +| `paginationLimit?` | `number` | The number of records to return per paginated request, default 1000 | + +#### Returns + +`Promise`\<[`TransactionSearchResults`](../interfaces/types_indexer.TransactionSearchResults.md)\> + +The search results + +#### Defined in + +[src/indexer-lookup.ts:118](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/indexer-lookup.ts#L118) diff --git a/docs/code/modules/types_algorand_client_asset_spec.md b/docs/code/modules/types_algorand_client_asset_spec.md new file mode 100644 index 00000000..7b7d0d62 --- /dev/null +++ b/docs/code/modules/types_algorand_client_asset_spec.md @@ -0,0 +1,3 @@ +[@algorandfoundation/algokit-utils](../README.md) / types/algorand-client.asset.spec + +# Module: types/algorand-client.asset.spec diff --git a/docs/code/modules/types_algorand_client_transfer_spec.md b/docs/code/modules/types_algorand_client_transfer_spec.md new file mode 100644 index 00000000..6987b9a6 --- /dev/null +++ b/docs/code/modules/types_algorand_client_transfer_spec.md @@ -0,0 +1,3 @@ +[@algorandfoundation/algokit-utils](../README.md) / types/algorand-client.transfer.spec + +# Module: types/algorand-client.transfer.spec diff --git a/docs/code/modules/types_asset_manager.md b/docs/code/modules/types_asset_manager.md new file mode 100644 index 00000000..77dade94 --- /dev/null +++ b/docs/code/modules/types_asset_manager.md @@ -0,0 +1,13 @@ +[@algorandfoundation/algokit-utils](../README.md) / types/asset-manager + +# Module: types/asset-manager + +## Table of contents + +### Classes + +- [AssetManager](../classes/types_asset_manager.AssetManager.md) + +### Interfaces + +- [AssetInformation](../interfaces/types_asset_manager.AssetInformation.md) diff --git a/src/account/account.ts b/src/account/account.ts index 45e31af1..1ee9cb7b 100644 --- a/src/account/account.ts +++ b/src/account/account.ts @@ -1,6 +1,6 @@ import algosdk from 'algosdk' import { getSenderAddress } from '../transaction/transaction' -import { AccountAssetInformation, AccountInformation, MultisigAccount, SigningAccount, TransactionSignerAccount } from '../types/account' +import { AccountAssetInformation, MultisigAccount, SigningAccount, TransactionSignerAccount } from '../types/account' import { AccountManager } from '../types/account-manager' import { AlgoAmount } from '../types/amount' import { ClientManager } from '../types/client-manager' @@ -10,6 +10,7 @@ import Algodv2 = algosdk.Algodv2 import Kmd = algosdk.Kmd import MultisigMetadata = algosdk.MultisigMetadata import TransactionSigner = algosdk.TransactionSigner +import AccountInformationModel = algosdk.modelsv2.Account /** * @deprecated Use `algorandClient.account.multisig(multisigParams, signingAccounts)` or `new MultisigAccount(multisigParams, signingAccounts)` instead. @@ -24,7 +25,7 @@ export function multisigAccount(multisigParams: MultisigMetadata, signingAccount } /** - * @deprecated Use `algorandClient.account.rekeyed(account, sender)` or `new SigningAccount(account, sender)` instead. + * @deprecated Use `algorandClient.account.rekeyed(sender, account)` or `new SigningAccount(account, sender)` instead. * * Returns an account wrapper that supports a rekeyed account. * @param signer The account, with private key loaded, that is signing @@ -127,6 +128,11 @@ export function getAccountAddressAsString(addressEncodedInB64: string): string { return algosdk.encodeAddress(Buffer.from(addressEncodedInB64, 'base64')) } +type NumberConverter = { [key in keyof T]: ToNumberIfExtends } +type ToNumberIfExtends = K extends E ? number : K +/** @deprecated Account information at a given round. */ +export type AccountInformation = Omit, 'get_obj_for_encoding'> + /** * @deprecated Use `algorandClient.account.getInformation(sender)` or `new AccountManager(clientManager).getInformation(sender)` instead. * @@ -144,7 +150,26 @@ export function getAccountAddressAsString(addressEncodedInB64: string): string { * @returns The account information */ export async function getAccountInformation(sender: string | SendTransactionFrom, algod: Algodv2): Promise { - return new AccountManager(new ClientManager({ algod })).getInformation(getSenderAddress(sender)) + const account = AccountInformationModel.from_obj_for_encoding(await algod.accountInformation(getSenderAddress(sender)).do()) + + return { + ...account, + // None of these can practically overflow 2^53 + amount: Number(account.amount), + amountWithoutPendingRewards: Number(account.amountWithoutPendingRewards), + minBalance: Number(account.minBalance), + pendingRewards: Number(account.pendingRewards), + rewards: Number(account.rewards), + round: Number(account.round), + totalAppsOptedIn: Number(account.totalAppsOptedIn), + totalAssetsOptedIn: Number(account.totalAssetsOptedIn), + totalCreatedApps: Number(account.totalCreatedApps), + totalCreatedAssets: Number(account.totalCreatedAssets), + appsTotalExtraPages: account.appsTotalExtraPages ? Number(account.appsTotalExtraPages) : undefined, + rewardBase: account.rewardBase ? Number(account.rewardBase) : undefined, + totalBoxBytes: account.totalBoxBytes ? Number(account.totalBoxBytes) : undefined, + totalBoxes: account.totalBoxes ? Number(account.totalBoxes) : undefined, + } } /** diff --git a/src/app.spec.ts b/src/app.spec.ts index 698b84a0..312d4b0e 100644 --- a/src/app.spec.ts +++ b/src/app.spec.ts @@ -50,7 +50,7 @@ describe('app', () => { ) // If the rekey didn't work this will throw - const rekeyedAccount = algorand.account.rekeyed(rekeyTo, testAccount.addr) + const rekeyedAccount = algorand.account.rekeyed(testAccount.addr, rekeyTo) await algokit.transferAlgos( { amount: (0).algos(), diff --git a/src/asset.spec.ts b/src/asset.spec.ts deleted file mode 100644 index fb81a97b..00000000 --- a/src/asset.spec.ts +++ /dev/null @@ -1,205 +0,0 @@ -import { describe, test } from '@jest/globals' -import invariant from 'tiny-invariant' -import * as algokit from './' -import { algorandFixture } from './testing' -import { generateTestAsset } from './testing/_asset' - -describe('asset', () => { - const localnet = algorandFixture() - beforeEach(localnet.beforeEach, 100_000) - - test('Create an asset succeeds', async () => { - const { algod, testAccount, algorand } = localnet.context - const accounts = [algorand.account.random(), algorand.account.random(), algorand.account.random(), algorand.account.random()] - const hash = new Uint8Array(32).fill(1) - const result = await algokit.createAsset( - { - creator: testAccount, - total: 1000, - decimals: 0, - name: 'Test Asset', - unit: 'TEST', - url: 'https://example.com', - metadataHash: hash, - manager: accounts[0].addr, - reserveAccount: accounts[1].addr, - freezeAccount: accounts[2].addr, - clawbackAccount: accounts[3].addr, - frozenByDefault: true, - }, - algod, - ) - - expect(result.confirmation?.assetIndex).toBeGreaterThan(0) - invariant(result.confirmation) - invariant(typeof result.confirmation!.assetIndex! === 'number') - const assetData = await algod.getAssetByID(result.confirmation.assetIndex).do() - expect(assetData.params.total).toBe(1000) - expect(assetData.params.decimals).toBe(0) - expect(assetData.params['default-frozen']).toBe(true) - expect(assetData.params['unit-name']).toBe('TEST') - expect(assetData.params.name).toBe('Test Asset') - expect(assetData.params.url).toBe('https://example.com') - expect(assetData.params['metadata-hash']).toBe(Buffer.from(hash).toString('base64')) - expect(assetData.params.manager).toBe(accounts[0].addr) - expect(assetData.params.reserve).toBe(accounts[1].addr) - expect(assetData.params.freeze).toBe(accounts[2].addr) - expect(assetData.params.clawback).toBe(accounts[3].addr) - }) - - test('OptIn an asset to an account succeed', async () => { - const { algod, testAccount, generateAccount } = localnet.context - const dummyAssetId = await generateTestAsset(algod, testAccount, 1) - const dummyAssetIds = [dummyAssetId] - const secondAccount = await generateAccount({ initialFunds: (1).algos() }) - - const secondAccountInfo = await algod.accountInformation(secondAccount.addr).do() - expect(secondAccountInfo['total-assets-opted-in']).toBe(0) - - await algokit.assetBulkOptIn({ account: secondAccount, assetIds: dummyAssetIds }, algod) - - const testAccountInfoAfterOptIn = await algod.accountInformation(secondAccount.addr).do() - expect(testAccountInfoAfterOptIn['total-assets-opted-in']).toBe(1) - }) - - test('OptIn two batches of asset to an account succeed', async () => { - const { algod, testAccount, generateAccount } = localnet.context - const dummyAssetIds: number[] = [] - const secondAccount = await generateAccount({ initialFunds: (3).algos() }) - for (let i = 0; i < 20; i++) { - const dummyAssetId = await generateTestAsset(algod, testAccount, 0) - dummyAssetIds.push(dummyAssetId) - } - await algokit.assetBulkOptIn({ account: secondAccount, assetIds: dummyAssetIds }, algod) - const secondAccountInfo = await algod.accountInformation(secondAccount.addr).do() - expect(secondAccountInfo['total-assets-opted-in']).toBe(20) - }, 10e6) - - test('OptOut of an asset to an account succeed', async () => { - const { algod, testAccount, generateAccount } = localnet.context - const dummyAssetId = await generateTestAsset(algod, testAccount, 0) - const dummyAssetId2 = await generateTestAsset(algod, testAccount, 0) - const dummyAssetIds = [dummyAssetId, dummyAssetId2] - const secondAccount = await generateAccount({ initialFunds: (1).algos() }) - - await algokit.assetBulkOptIn({ account: secondAccount, assetIds: dummyAssetIds }, algod) - - const secondAccountInfo = await algod.accountInformation(secondAccount.addr).do() - expect(secondAccountInfo['total-assets-opted-in']).toBe(2) - - await algokit.assetBulkOptOut({ account: secondAccount, assetIds: dummyAssetIds }, algod) - - const secondAccountInfoAfterOptOut = await algod.accountInformation(secondAccount.addr).do() - expect(secondAccountInfoAfterOptOut['total-assets-opted-in']).toBe(0) - }) - - test('OptOut of an not opt-in asset to an account failed', async () => { - const { algod, testAccount, generateAccount } = localnet.context - const dummyAssetId = await generateTestAsset(algod, testAccount, 0) - const dummyAssetIds = [dummyAssetId, 1234567, -132] - const secondAccount = await generateAccount({ initialFunds: (1).algos() }) - - await algokit.assetBulkOptIn({ account: secondAccount, assetIds: [dummyAssetId] }, algod) - - const secondAccountInfo = await algod.accountInformation(secondAccount.addr).do() - expect(secondAccountInfo['total-assets-opted-in']).toBe(1) - - await expect(algokit.assetBulkOptOut({ account: secondAccount, assetIds: dummyAssetIds }, algod)).rejects.toThrow( - `Account ${secondAccount.addr} is not opted-in to Assets 1234567, -132; can't opt-out.`, - ) - - const secondAccountInfoAfterFailedOptOut = await algod.accountInformation(secondAccount.addr).do() - expect(secondAccountInfoAfterFailedOptOut['total-assets-opted-in']).toBe(1) - }) - - test('Bulk OptOut of an non-zero balance asset to an account failed ', async () => { - const { algod, testAccount, generateAccount } = localnet.context - const dummyAssetId = await generateTestAsset(algod, testAccount, 0) - const dummyAssetId2 = await generateTestAsset(algod, testAccount, 0) - const dummyAssetIds = [dummyAssetId, dummyAssetId2] - const secondAccount = await generateAccount({ initialFunds: (1).algos() }) - - await algokit.assetBulkOptIn({ account: secondAccount, assetIds: dummyAssetIds }, algod) - - const secondAccountInfo = await algod.accountInformation(secondAccount.addr).do() - expect(secondAccountInfo['total-assets-opted-in']).toBe(2) - - await algokit.transferAsset( - { - from: testAccount, - to: secondAccount.addr, - assetId: dummyAssetId, - amount: 5, - note: `Transfer 5 assets with id ${dummyAssetId}`, - }, - algod, - ) - - await expect(algokit.assetBulkOptOut({ account: secondAccount, assetIds: dummyAssetIds }, algod)).rejects.toThrow( - `Account ${secondAccount.addr} has non-zero balance for Asset ${dummyAssetId}; can't opt-out.`, - ) - - const secondAccountInfoAfterFailedOptOut = await algod.accountInformation(secondAccount.addr).do() - expect(secondAccountInfoAfterFailedOptOut['total-assets-opted-in']).toBe(2) - }) - - test('OptIn and OptOut of a single asset ', async () => { - const { algod, testAccount, generateAccount } = localnet.context - const dummyAssetId = await generateTestAsset(algod, testAccount, 0) - const secondAccount = await generateAccount({ initialFunds: (1).algos() }) - - await algokit.assetOptIn({ account: secondAccount, assetId: dummyAssetId }, algod) - - const secondAccountInfo = await algod.accountInformation(secondAccount.addr).do() - expect(secondAccountInfo['total-assets-opted-in']).toBe(1) - - await algokit.assetOptOut({ account: secondAccount, assetId: dummyAssetId }, algod) - - const secondAccountInfoAfterOptOut = await algod.accountInformation(secondAccount.addr).do() - expect(secondAccountInfoAfterOptOut['total-assets-opted-in']).toBe(0) - }) - - test('OptOut of non-zero balance single asset to an account fails by default', async () => { - const { algod, testAccount, generateAccount } = localnet.context - const dummyAssetId = await generateTestAsset(algod, testAccount, 0) - const secondAccount = await generateAccount({ initialFunds: (1).algos() }) - - await algokit.assetOptIn({ account: secondAccount, assetId: dummyAssetId }, algod) - - await algokit.transferAsset( - { - from: testAccount, - to: secondAccount.addr, - assetId: dummyAssetId, - amount: 5, - note: `Transfer 5 assets with id ${dummyAssetId}`, - }, - algod, - ) - - await expect(algokit.assetOptOut({ account: secondAccount, assetId: dummyAssetId }, algod)).rejects.toThrow( - `Account ${secondAccount.addr} does not have a zero balance for Asset ${dummyAssetId}; can't opt-out.`, - ) - - const secondAccountInfoAfterFailedOptOut = await algod.accountInformation(secondAccount.addr).do() - expect(secondAccountInfoAfterFailedOptOut['total-assets-opted-in']).toBe(1) - }) - - test('OptOut of two batches of asset to an account succeed', async () => { - const { algod, testAccount, generateAccount } = localnet.context - const dummyAssetIds: number[] = [] - const secondAccount = await generateAccount({ initialFunds: (3).algos() }) - for (let i = 0; i < 20; i++) { - const dummyAssetId = await generateTestAsset(algod, testAccount, 0) - dummyAssetIds.push(dummyAssetId) - } - await algokit.assetBulkOptIn({ account: secondAccount, assetIds: dummyAssetIds }, algod) - const secondAccountInfo = await algod.accountInformation(secondAccount.addr).do() - expect(secondAccountInfo['total-assets-opted-in']).toBe(20) - - await algokit.assetBulkOptOut({ account: secondAccount, assetIds: dummyAssetIds }, algod) - - const secondAccountInfoAfterOptOut = await algod.accountInformation(secondAccount.addr).do() - expect(secondAccountInfoAfterOptOut['total-assets-opted-in']).toBe(0) - }, 10e6) -}) diff --git a/src/asset.ts b/src/asset.ts index c75ec840..acb1e7b6 100644 --- a/src/asset.ts +++ b/src/asset.ts @@ -9,6 +9,8 @@ import { SendTransactionResult } from './types/transaction' import Algodv2 = algosdk.Algodv2 /** + * @deprecated use `algorandClient.send.assetCreate()` / `algorandClient.transaction.assetCreate()` instead + * * Create an Algorand Standard Asset (ASA). * @param create The asset creation definition * @param algod An algod client @@ -51,6 +53,8 @@ export async function createAsset( } /** + * @deprecated use `algorandClient.send.assetOptIn()` / `algorandClient.transaction.assetOptIn()` instead + * * Opt-in an account to an asset. * @param optIn The opt-in definition * @param algod An algod client @@ -80,6 +84,8 @@ export async function assetOptIn(optIn: AssetOptInParams, algod: Algodv2): Promi } /** + * @deprecated use `algorandClient.send.assetOptOut()` / `algorandClient.transaction.assetOptOut()` instead + * * Opt-out an account from an asset. * @param optOut The opt-in definition * @param algod An algod client @@ -112,6 +118,8 @@ export async function assetOptOut(optOut: AssetOptOutParams, algod: Algodv2): Pr } /** + * @deprecated use `algorandClient.account.assetBulkOptIn()` instead + * * Opt in to a list of assets on the Algorand blockchain. * * @param optIn - The bulk opt-in request. @@ -123,7 +131,7 @@ export async function assetOptOut(optOut: AssetOptOutParams, algod: Algodv2): Pr export async function assetBulkOptIn(optIn: AssetBulkOptInOutParams, algod: Algodv2): Promise> { const result = await new AccountManager(new ClientManager({ algod })) .setSignerFromAccount(optIn.account) - .assetBulkOptIn(getSenderAddress(optIn.account), optIn.assetIds, { + .assetBulkOptIn(getSenderAddress(optIn.account), optIn.assetIds.map(BigInt), { note: encodeTransactionNote(optIn.note), maxFee: optIn.maxFee, suppressLog: optIn.suppressLog, @@ -137,6 +145,8 @@ export async function assetBulkOptIn(optIn: AssetBulkOptInOutParams, algod: Algo } /** + * @deprecated use `algorandClient.account.assetBulkOptOut()` instead + * * Opt out of multiple assets in Algorand blockchain. * * @param optOut The bulk opt-out request. @@ -148,7 +158,7 @@ export async function assetBulkOptIn(optIn: AssetBulkOptInOutParams, algod: Algo export async function assetBulkOptOut(optOut: AssetBulkOptInOutParams, algod: Algodv2): Promise> { const result = await new AccountManager(new ClientManager({ algod })) .setSignerFromAccount(optOut.account) - .assetBulkOptOut(getSenderAddress(optOut.account), optOut.assetIds, { + .assetBulkOptOut(getSenderAddress(optOut.account), optOut.assetIds.map(BigInt), { ensureZeroBalance: optOut.validateBalances ?? true, note: encodeTransactionNote(optOut.note), maxFee: optOut.maxFee, diff --git a/src/index.ts b/src/index.ts index c2169442..54f01108 100644 --- a/src/index.ts +++ b/src/index.ts @@ -2,19 +2,20 @@ export * from './app' export * from './app-client' export * from './app-deploy' -export * from './asset' export * from './debugging' -export * from './indexer-lookup' export * from './transaction' -export * from './transfer' // Legacy exports - remove after 2 x major version bumps export * from './account' +export * from './asset' export * from './dispenser-client' +export * from './indexer-lookup' export * from './localnet' export * from './network-client' +export * from './transfer' // Up to date exports export * from './amount' export * from './config' +export * as indexer from './indexer-lookup' export { AlgorandClient } from './types/algorand-client' diff --git a/src/testing/_asset.ts b/src/testing/_asset.ts index 6a97a86b..e8384583 100644 --- a/src/testing/_asset.ts +++ b/src/testing/_asset.ts @@ -1,38 +1,23 @@ -import algosdk from 'algosdk' -import Account = algosdk.Account -import Algodv2 = algosdk.Algodv2 -import makeAssetCreateTxnWithSuggestedParamsFromObject = algosdk.makeAssetCreateTxnWithSuggestedParamsFromObject +import { AlgorandClient } from '../types/algorand-client' -export async function generateTestAsset(client: Algodv2, sender: Account, total?: number) { +export async function generateTestAsset(algorand: AlgorandClient, sender: string, total?: number) { total = !total ? Math.floor(Math.random() * 100) + 20 : total const decimals = 0 const assetName = `ASA ${Math.floor(Math.random() * 100) + 1}_${Math.floor(Math.random() * 100) + 1}_${total}` - const params = await client.getTransactionParams().do() - - const txn = makeAssetCreateTxnWithSuggestedParamsFromObject({ - from: sender.addr, - suggestedParams: params, - total: total * 10 ** decimals, + const asset = await algorand.send.assetCreate({ + sender: sender, + total: BigInt(total * 10 ** decimals), decimals: decimals, defaultFrozen: false, unitName: '', assetName: assetName, - manager: sender.addr, - reserve: sender.addr, - freeze: sender.addr, - clawback: sender.addr, - assetURL: 'https://path/to/my/asset/details', + manager: sender, + reserve: sender, + freeze: sender, + clawback: sender, + url: 'https://path/to/my/asset/details', }) - const stxn = txn.signTxn(sender.sk) - - let txid = await client.sendRawTransaction(stxn).do() - txid = txid['txId'] - - const ptx = await client.pendingTransactionInformation(txid).do() - - const assetId = ptx['asset-index'] - - return assetId + return asset.assetId } diff --git a/src/testing/account.ts b/src/testing/account.ts index 79608756..8ec4dbb8 100644 --- a/src/testing/account.ts +++ b/src/testing/account.ts @@ -59,7 +59,7 @@ export async function getTestAccount( const accountInfo = await algorand.account.getInformation(account.addr) - Config.getLogger(suppressLog).info('Test account funded; account balance: %d µAlgos', accountInfo.amount) + Config.getLogger(suppressLog).info('Test account funded; account balance: %d µAlgos', accountInfo.balance.microAlgos) return account } diff --git a/src/transfer/transfer-algos.ts b/src/transfer/transfer-algos.ts index 557241c1..bd8e9037 100644 --- a/src/transfer/transfer-algos.ts +++ b/src/transfer/transfer-algos.ts @@ -7,6 +7,8 @@ import { AlgoTransferParams } from '../types/transfer' import Algodv2 = algosdk.Algodv2 /** + * @deprecated Use `algorand.send.payment()` / `algorand.transaction.payment()` instead + * * Transfer ALGOs between two accounts. * @param transfer The transfer definition * @param algod An algod client diff --git a/src/transfer/transfer.spec.ts b/src/transfer/transfer.spec.ts deleted file mode 100644 index eac55ad0..00000000 --- a/src/transfer/transfer.spec.ts +++ /dev/null @@ -1,467 +0,0 @@ -import { describe, test } from '@jest/globals' -import algosdk, { TransactionType } from 'algosdk' -import invariant from 'tiny-invariant' -import * as algokit from '..' -import { algorandFixture } from '../testing' -import { generateTestAsset } from '../testing/_asset' -import { ClientManager } from '../types/client-manager' -import { TestNetDispenserApiClient } from '../types/dispenser-client' - -describe('transfer', () => { - const localnet = algorandFixture() - const env = process.env - - beforeEach(async () => { - jest.resetModules() - process.env = { ...env } - await localnet.beforeEach() - }, 10_000) - - afterEach(() => { - process.env = env - }) - - test('Transfer Algo is sent and waited for', async () => { - const { algod, testAccount } = localnet.context - const secondAccount = algosdk.generateAccount() - - const { transaction, confirmation } = await algokit.transferAlgos( - { - from: testAccount, - to: secondAccount.addr, - amount: algokit.algos(5), - note: 'Transfer 5 ALGOs', - }, - algod, - ) - const accountInfo = await algod.accountInformation(secondAccount.addr).do() - - expect(transaction).toBeInstanceOf(algosdk.Transaction) - expect(transaction.type).toBe(TransactionType.pay) - expect(confirmation?.txn.txn.type).toBe('pay') - - expect(transaction.amount).toBe(5_000_000) - expect(confirmation?.txn.txn.amt).toBe(5_000_000) - - expect(algosdk.encodeAddress(transaction.from.publicKey)).toBe(testAccount.addr) - // eslint-disable-next-line @typescript-eslint/no-non-null-assertion - expect(algosdk.encodeAddress(confirmation!.txn.txn.snd)).toBe(testAccount.addr) - - expect(accountInfo['amount']).toBe(5_000_000) - }) - - test('Transfer Algo respects string lease', async () => { - const { algod, testAccount } = localnet.context - const secondAccount = algosdk.generateAccount() - - await algokit.transferAlgos( - { - from: testAccount, - to: secondAccount.addr, - amount: algokit.algos(1), - lease: 'test', - }, - algod, - ) - - await expect( - algokit.transferAlgos( - { - from: testAccount, - to: secondAccount.addr, - amount: algokit.algos(1), - lease: 'test', - }, - algod, - ), - ).rejects.toThrow(/overlapping lease/) - }) - - test('Transfer Algo respects byte array lease', async () => { - const { algod, testAccount } = localnet.context - const secondAccount = algosdk.generateAccount() - - await algokit.transferAlgos( - { - from: testAccount, - to: secondAccount.addr, - amount: algokit.algos(1), - lease: new Uint8Array([1, 2, 3, 4]), - }, - algod, - ) - - await expect( - algokit.transferAlgos( - { - from: testAccount, - to: secondAccount.addr, - amount: algokit.algos(1), - lease: new Uint8Array([1, 2, 3, 4]), - }, - algod, - ), - ).rejects.toThrow(/overlapping lease/) - }) - - test('Transfer ASA, receiver is not opted in', async () => { - const { algod, testAccount, generateAccount } = localnet.context - const dummyAssetId = await generateTestAsset(algod, testAccount, 100) - const secondAccount = await generateAccount({ initialFunds: (1).algos() }) - await algokit.assetOptIn({ account: secondAccount, assetId: dummyAssetId }, algod) - await algokit.transferAsset( - { - from: testAccount, - to: secondAccount.addr, - assetId: dummyAssetId, - amount: 1, - lease: 'test', - }, - algod, - ) - - await expect( - algokit.transferAsset( - { - from: testAccount, - to: secondAccount.addr, - assetId: dummyAssetId, - amount: 1, - lease: 'test', - }, - algod, - ), - ).rejects.toThrow(/overlapping lease/) - }, 10e6) - - test('Transfer ASA respects lease', async () => { - const { algod, testAccount } = localnet.context - const dummyAssetId = await generateTestAsset(algod, testAccount, 100) - const secondAccount = algosdk.generateAccount() - - try { - await algokit.transferAsset( - { - from: testAccount, - to: secondAccount.addr, - assetId: dummyAssetId, - amount: 5, - note: `Transfer 5 assets with id ${dummyAssetId}`, - }, - algod, - ) - } catch (e: unknown) { - expect((e as Error).name).toEqual('URLTokenBaseHTTPError') - expect((e as Error).message).toContain('receiver error: must optin') - } - }, 10e6) - - test('Transfer ASA, sender is not opted in', async () => { - const { algod, testAccount, generateAccount } = localnet.context - const dummyAssetId = await generateTestAsset(algod, testAccount, 100) - const secondAccount = await generateAccount({ initialFunds: (1).algos() }) - - await algokit.assetOptIn({ account: secondAccount, assetId: dummyAssetId }, algod) - - try { - await algokit.transferAsset( - { - from: testAccount, - to: secondAccount.addr, - assetId: dummyAssetId, - amount: 5, - note: `Transfer 5 assets with id ${dummyAssetId}`, - }, - algod, - ) - } catch (e: unknown) { - expect((e as Error).name).toEqual('URLTokenBaseHTTPError') - expect((e as Error).message).toContain('sender error: must optin') - } - }, 10e6) - - test('Transfer ASA, asset doesnt exist', async () => { - const { algod, testAccount, generateAccount } = localnet.context - const dummyAssetId = await generateTestAsset(algod, testAccount, 100) - const secondAccount = await generateAccount({ initialFunds: (1).algos() }) - - await algokit.assetOptIn({ account: secondAccount, assetId: dummyAssetId }, algod) - - try { - await algokit.transferAsset( - { - from: testAccount, - to: secondAccount.addr, - assetId: 1, - amount: 5, - note: `Transfer asset with wrong id`, - }, - algod, - ) - } catch (e: unknown) { - expect((e as Error).name).toEqual('URLTokenBaseHTTPError') - expect((e as Error).message).toContain('asset 1 missing from') - } - }, 10e6) - - test('Transfer ASA, without sending', async () => { - const { algod, testAccount, generateAccount } = localnet.context - const dummyAssetId = await generateTestAsset(algod, testAccount, 100) - const secondAccount = await generateAccount({ initialFunds: (1).algos() }) - - await algokit.assetOptIn({ account: secondAccount, assetId: dummyAssetId }, algod) - - const response = await algokit.transferAsset( - { - from: testAccount, - to: secondAccount.addr, - assetId: 1, - amount: 5, - note: `Transfer asset with wrong id`, - skipSending: true, - }, - algod, - ) - - expect(response.transaction).toBeDefined() - expect(response.confirmation).toBeUndefined() - }, 10e6) - - test('Transfer ASA, asset is transfered to another account', async () => { - const { algod, testAccount, generateAccount } = localnet.context - const dummyAssetId = await generateTestAsset(algod, testAccount, 100) - const secondAccount = await generateAccount({ initialFunds: (1).algos() }) - - await algokit.assetOptIn({ account: secondAccount, assetId: dummyAssetId }, algod) - - await algokit.transferAsset( - { - from: testAccount, - to: secondAccount.addr, - assetId: dummyAssetId, - amount: 5, - note: `Transfer 5 assets with id ${dummyAssetId}`, - }, - algod, - ) - - const secondAccountInfo = await algod.accountAssetInformation(secondAccount.addr, dummyAssetId).do() - expect(secondAccountInfo['asset-holding']['amount']).toBe(5) - - const testAccountInfo = await algod.accountAssetInformation(testAccount.addr, dummyAssetId).do() - expect(testAccountInfo['asset-holding']['amount']).toBe(95) - }, 10e6) - - test('Transfer ASA, asset is transfered to another account from revocationTarget', async () => { - const { algod, testAccount, generateAccount } = localnet.context - const dummyAssetId = await generateTestAsset(algod, testAccount, 100) - const secondAccount = await generateAccount({ initialFunds: (1).algos() }) - const clawbackAccount = await generateAccount({ initialFunds: (1).algos() }) - - await algokit.assetOptIn({ account: secondAccount, assetId: dummyAssetId }, algod) - - await algokit.assetOptIn({ account: clawbackAccount, assetId: dummyAssetId }, algod) - - await algokit.transferAsset( - { - from: testAccount, - to: clawbackAccount.addr, - assetId: dummyAssetId, - amount: 5, - note: `Transfer 5 assets with id ${dummyAssetId}`, - }, - algod, - ) - - const clawbackFromInfo = await algod.accountAssetInformation(clawbackAccount.addr, dummyAssetId).do() - expect(clawbackFromInfo['asset-holding']['amount']).toBe(5) - - await algokit.transferAsset( - { - from: testAccount, - to: secondAccount.addr, - assetId: dummyAssetId, - amount: 5, - note: `Transfer 5 assets with id ${dummyAssetId}`, - clawbackFrom: clawbackAccount, - }, - algod, - ) - - const secondAccountInfo = await algod.accountAssetInformation(secondAccount.addr, dummyAssetId).do() - expect(secondAccountInfo['asset-holding']['amount']).toBe(5) - - const clawbackAccountInfo = await algod.accountAssetInformation(clawbackAccount.addr, dummyAssetId).do() - expect(clawbackAccountInfo['asset-holding']['amount']).toBe(0) - - const testAccountInfo = await algod.accountAssetInformation(testAccount.addr, dummyAssetId).do() - expect(testAccountInfo['asset-holding']['amount']).toBe(95) - }, 10e6) - - test('ensureFunded is sent and waited for with correct amount for new account', async () => { - const { algod, kmd, testAccount, algorand } = localnet.context - const secondAccount = algorand.account.random() - - const result = await algokit.ensureFunded( - { - accountToFund: secondAccount, - fundingSource: testAccount, - minSpendingBalance: algokit.microAlgos(1), - }, - algod, - kmd, - ) - const accountInfo = await algod.accountInformation(secondAccount.addr).do() - - invariant(result) - expect(result.transactionId).toBeDefined() - expect(result.amount).toBeDefined() - const txnInfo = await algod.pendingTransactionInformation(result.transactionId).do() - - expect(txnInfo.txn.txn.type).toBe('pay') - - expect(result.amount).toBe(100_001) - expect(txnInfo.txn.txn.amt).toBe(100_001) - expect(accountInfo['amount']).toBe(100_001) - - // eslint-disable-next-line @typescript-eslint/no-non-null-assertion - expect(algosdk.encodeAddress(txnInfo.txn.txn.snd)).toBe(testAccount.addr) - // eslint-disable-next-line @typescript-eslint/no-non-null-assertion - expect(algosdk.encodeAddress(txnInfo.txn.txn.rcv!)).toBe(secondAccount.addr) - }) - - test('ensureFunded respects minimum funding increment', async () => { - const { algod, testAccount, kmd, generateAccount } = localnet.context - const secondAccount = await generateAccount({ initialFunds: (1).algos() }) - - await algokit.ensureFunded( - { - accountToFund: secondAccount, - fundingSource: testAccount, - minSpendingBalance: algokit.microAlgos(1), - minFundingIncrement: algokit.algos(1), - }, - algod, - kmd, - ) - - const accountInfo = await algod.accountInformation(secondAccount.addr).do() - expect(accountInfo['amount']).toBe(1_000_000) - }) - - test('ensureFunded uses dispenser account by default', async () => { - const { algod, kmd, algorand } = localnet.context - const secondAccount = algorand.account.random() - const dispenser = await algorand.account.dispenserFromEnvironment() - - const result = await algokit.ensureFunded( - { - accountToFund: secondAccount, - minSpendingBalance: algokit.microAlgos(1), - minFundingIncrement: algokit.algos(1), - }, - algod, - kmd, - ) - - invariant(result) - const txnInfo = await algod.pendingTransactionInformation(result.transactionId).do() - const resultReceiver = algosdk.encodeAddress(txnInfo.txn.txn.snd) - expect(resultReceiver).toBe(dispenser.addr) - const accountInfo = await algod.accountInformation(secondAccount.addr).do() - expect(accountInfo['amount']).toBe(1_000_000) - }) - - test('ensureFunded uses dispenser api with access token successfully', async () => { - process.env.ALGOKIT_DISPENSER_ACCESS_TOKEN = 'dummy_token' - - const algodClient = ClientManager.getAlgodClient(ClientManager.getAlgoNodeConfig('testnet', 'algod')) - const dispenserClient = new TestNetDispenserApiClient() - Object.assign(dispenserClient, { - fund: jest.fn().mockImplementation(() => { - return Promise.resolve({ txId: 'dummy_tx_id', amount: 200_000 }) - }), - }) - - const accountToFund = algosdk.generateAccount() - - const result = await algokit.ensureFunded( - { - accountToFund: accountToFund, - minSpendingBalance: algokit.algos(100), - minFundingIncrement: algokit.algos(0.1), - fundingSource: dispenserClient, - }, - algodClient, - ) - - invariant(result) - expect(result.transactionId).toBeDefined() - expect(result.amount).toBe(200_000) - }) - - test('ensureFunded uses dispenser api and fails with rejected response', async () => { - process.env.ALGOKIT_DISPENSER_ACCESS_TOKEN = 'dummy_token' - - const algodClient = ClientManager.getAlgodClient(ClientManager.getAlgoNodeConfig('testnet', 'algod')) - const dispenserClient = new TestNetDispenserApiClient() - Object.assign(dispenserClient, { - fund: jest.fn().mockImplementation(() => { - return Promise.reject(new Error('dummy_error')) - }), - }) - const accountToFund = algosdk.generateAccount() - - await expect( - algokit.ensureFunded( - { - accountToFund: accountToFund, - minSpendingBalance: algokit.algos(100), - minFundingIncrement: algokit.algos(1), - fundingSource: dispenserClient, - }, - algodClient, - ), - ).rejects.toThrowErrorMatchingInlineSnapshot('"dummy_error"') - }) -}) - -describe('rekey', () => { - const localnet = algorandFixture() - const env = process.env - - beforeEach(async () => { - jest.resetModules() - process.env = { ...env } - await localnet.beforeEach() - }, 10_000) - - afterEach(() => { - process.env = env - }) - - test('Rekey works', async () => { - const { algod, testAccount, algorand } = localnet.context - const secondAccount = algorand.account.random() - - await algokit.rekeyAccount( - { - from: testAccount, - rekeyTo: secondAccount, - note: 'Rekey', - }, - algod, - ) - - // This will throw if the rekey wasn't successful - const rekeyedAccount = algorand.account.rekeyed(secondAccount, testAccount.addr) - await algokit.transferAlgos( - { - amount: (1).microAlgos(), - from: rekeyedAccount, - to: testAccount.addr, - }, - algod, - ) - }) -}) diff --git a/src/transfer/transfer.ts b/src/transfer/transfer.ts index 31c830ba..b0af5caa 100644 --- a/src/transfer/transfer.ts +++ b/src/transfer/transfer.ts @@ -9,6 +9,9 @@ import Algodv2 = algosdk.Algodv2 import Kmd = algosdk.Kmd /** + * @deprecated Use `algorand.account.ensureFunded()` / `algorand.account.ensureFundedFromEnvironment()` + * / `algorand.account.ensureFundedFromTestNetDispenserApi()` instead + * * Funds a given account using a funding source such that it has a certain amount of algos free to spend (accounting for ALGOs locked in minimum balance requirement). * * https://developer.algorand.org/docs/get-details/accounts/#minimum-balance @@ -70,6 +73,8 @@ export async function ensureFunded( } /** + * @deprecated Use `algorand.send.assetTransfer()` / `algorand.transaction.assetTransfer()` instead + * * Transfer asset between two accounts. * @param transfer The transfer definition * @param algod An algod client @@ -100,6 +105,8 @@ export async function transferAsset(transfer: TransferAssetParams, algod: Algodv } /** + * @deprecated Use `algorand.send.rekey()` / `algorand.transaction.rekey()` instead + * * Rekey an account to a new address. * * **Note:** Please be careful with this function and be sure to read the [official rekey guidance](https://developer.algorand.org/docs/get-details/accounts/rekey/). diff --git a/src/types/account-manager.spec.ts b/src/types/account-manager.spec.ts index eeab5b11..dd6f2a6c 100644 --- a/src/types/account-manager.spec.ts +++ b/src/types/account-manager.spec.ts @@ -14,7 +14,7 @@ describe('AccountManager', () => { const account = await algorand.account.fromEnvironment(uuid()) const accountInfo = await algorand.account.getInformation(account.addr) - expect(accountInfo.amount).toBeGreaterThan(0) + expect(accountInfo.balance.microAlgos).toBeGreaterThan(0) }, 10e6) test('Same account is subsequently retrieved', async () => { diff --git a/src/types/account-manager.ts b/src/types/account-manager.ts index 5002f29d..f1c1e900 100644 --- a/src/types/account-manager.ts +++ b/src/types/account-manager.ts @@ -1,9 +1,17 @@ import algosdk from 'algosdk' import { Config } from '../config' import { calculateFundAmount, chunkArray, memoize } from '../util' -import { AccountInformation, DISPENSER_ACCOUNT, MultisigAccount, SigningAccount, TransactionSignerAccount } from './account' +import { + AccountAssetInformation, + AccountInformation, + DISPENSER_ACCOUNT, + MultisigAccount, + SigningAccount, + TransactionSignerAccount, +} from './account' import { SendSingleTransactionResult } from './algorand-client' import { AlgoAmount } from './amount' +import { AssetManager } from './asset-manager' import { ClientManager } from './client-manager' import AlgokitComposer, { CommonTransactionParams, ExecuteParams, MAX_TRANSACTION_GROUP_SIZE } from './composer' import { TestNetDispenserApiClient } from './dispenser-client' @@ -213,12 +221,12 @@ export class AccountManager { return { ...account, // None of these can practically overflow 2^53 - amount: Number(account.amount), - amountWithoutPendingRewards: Number(account.amountWithoutPendingRewards), - minBalance: Number(account.minBalance), - pendingRewards: Number(account.pendingRewards), - rewards: Number(account.rewards), - round: Number(account.round), + balance: AlgoAmount.MicroAlgos(Number(account.amount)), + amountWithoutPendingRewards: AlgoAmount.MicroAlgos(Number(account.amountWithoutPendingRewards)), + minBalance: AlgoAmount.MicroAlgos(Number(account.minBalance)), + pendingRewards: AlgoAmount.MicroAlgos(Number(account.pendingRewards)), + rewards: AlgoAmount.MicroAlgos(Number(account.rewards)), + validAsOfRound: BigInt(account.round), totalAppsOptedIn: Number(account.totalAppsOptedIn), totalAssetsOptedIn: Number(account.totalAssetsOptedIn), totalCreatedApps: Number(account.totalCreatedApps), @@ -245,7 +253,7 @@ export class AccountManager { * @param assetId The ID of the asset to return a holding for * @returns The account asset holding information */ - public async getAssetInformation(sender: string | TransactionSignerAccount, assetId: number | bigint) { + public async getAssetInformation(sender: string | TransactionSignerAccount, assetId: number | bigint): Promise { const info = await this._clientManager.algod .accountAssetInformation(typeof sender === 'string' ? sender : sender.addr, Number(assetId)) .do() @@ -288,7 +296,7 @@ export class AccountManager { * @param sender The sender address to use as the new sender * @returns The account */ - public rekeyed(account: TransactionSignerAccount, sender: string) { + public rekeyed(sender: string, account: TransactionSignerAccount) { return this.signerAccount({ addr: sender, signer: account.signer }) } @@ -469,7 +477,7 @@ export class AccountManager { */ async assetBulkOptIn( account: string | TransactionSignerAccount, - assetIds: (number | bigint)[], + assetIds: bigint[], options?: Omit & ExecuteParams, ): Promise { const results: BulkAssetOptInOutResult[] = [] @@ -521,16 +529,18 @@ export class AccountManager { */ async assetBulkOptOut( account: string | TransactionSignerAccount, - assetIds: (number | bigint)[], + assetIds: bigint[], options?: Omit & ExecuteParams & { /** Whether or not to check if the account has a zero balance for each asset first or not. + * + * Defaults to `true`. * * If this is set to `true` and the account has an asset balance it will throw an error. * * If this is set to `false` and the account has an asset balance it will lose those assets to the asset creator. */ - ensureZeroBalance: boolean + ensureZeroBalance?: boolean }, ): Promise { const results: BulkAssetOptInOutResult[] = [] @@ -544,7 +554,7 @@ export class AccountManager { const notOptedInAssetIds: bigint[] = [] const nonZeroBalanceAssetIds: bigint[] = [] for (const assetId of assetGroup) { - if (options?.ensureZeroBalance) { + if (options?.ensureZeroBalance !== false) { try { const accountAssetInfo = await this.getAssetInformation(sender, assetId) if (accountAssetInfo.balance !== 0n) { @@ -569,7 +579,7 @@ export class AccountManager { for (const assetId of assetGroup) { composer.addAssetOptOut({ ...options, - creator: (await this._clientManager.algod.getAssetByID(Number(assetId)).do()).params.creator as string, + creator: (await new AssetManager(this._clientManager).getById(BigInt(assetId))).creator, sender, assetId: BigInt(assetId), }) @@ -592,7 +602,7 @@ export class AccountManager { private async _getEnsureFundedAmount(sender: string, minSpendingBalance: AlgoAmount, minFundingIncrement?: AlgoAmount) { const accountInfo = await this.getInformation(sender) - const currentSpendingBalance = accountInfo.amount - accountInfo.minBalance + const currentSpendingBalance = accountInfo.balance.microAlgos - accountInfo.minBalance.microAlgos const amountFunded = calculateFundAmount(minSpendingBalance.microAlgos, currentSpendingBalance, minFundingIncrement?.microAlgos ?? 0) diff --git a/src/types/account.ts b/src/types/account.ts index c5b5a425..f8ece8e7 100644 --- a/src/types/account.ts +++ b/src/types/account.ts @@ -1,5 +1,11 @@ import algosdk from 'algosdk' -import AccountInformationModel = algosdk.modelsv2.Account +import { AlgoAmount } from './amount' +import ApplicationLocalState = algosdk.modelsv2.ApplicationLocalState +import ApplicationStateSchema = algosdk.modelsv2.ApplicationStateSchema +import AssetHolding = algosdk.modelsv2.AssetHolding +import Application = algosdk.modelsv2.Application +import Asset = algosdk.modelsv2.Asset +import AccountParticipation = algosdk.modelsv2.AccountParticipation import Account = algosdk.Account import MultisigMetadata = algosdk.MultisigMetadata import Transaction = algosdk.Transaction @@ -115,10 +121,143 @@ export interface TransactionSignerAccount { signer: TransactionSigner } -type NumberConverter = { [key in keyof T]: ToNumberIfExtends } -type ToNumberIfExtends = K extends E ? number : K /** Account information at a given round. */ -export type AccountInformation = Omit, 'get_obj_for_encoding'> +export type AccountInformation = { + /** + * The account public key + */ + address: string + + /** The balance of Algos currently held by the account. */ + balance: AlgoAmount + + /** + * The amount of Algos in the account, without the pending rewards. + */ + amountWithoutPendingRewards: AlgoAmount + + /** + * Algo balance required to be held by the account. + * + * The requirement grows based on asset and application usage. + */ + minBalance: AlgoAmount + /** + * Amount of Algos of pending rewards in this account. + */ + pendingRewards: AlgoAmount + + /** + * Total rewards of Algos the account has received, including pending + * rewards. + */ + rewards: AlgoAmount + + /** + * The round number for which this information is relevant. + */ + validAsOfRound: bigint + + /** + * Delegation status of the account's MicroAlgos: + * * Offline - indicates that the associated account is delegated. + * * Online - indicates that the associated account used as part of the delegation pool. + * * NotParticipating - indicates that the associated account is neither a delegator nor a delegate. + */ + status: string + + /** + * The count of all applications that have been opted in, equivalent to the count + * of application local data (AppLocalState objects) stored in this account. + */ + totalAppsOptedIn: number + + /** + * The count of all assets that have been opted in, equivalent to the count of + * AssetHolding objects held by this account. + */ + totalAssetsOptedIn: number + + /** + * The count of all apps (AppParams objects) created by this account. + */ + totalCreatedApps: number + + /** + * The count of all assets (AssetParams objects) created by this account. + */ + totalCreatedAssets: number + + /** + * Applications local data stored in this account. + */ + appsLocalState?: ApplicationLocalState[] + + /** + * The sum of all extra application program pages for this account. + */ + appsTotalExtraPages?: number + /** + * (tsch) stores the sum of all of the local schemas and global schemas in this + * account. + * Note: the raw account uses `StateSchema` for this type. + */ + appsTotalSchema?: ApplicationStateSchema + + /** + * Assets held by this account. + */ + assets?: AssetHolding[] + + /** + * The address against which signing should be checked. If empty, the + * address of the current account is used. This field can be updated in any + * transaction by setting the `RekeyTo` field. + */ + authAddr?: string + + /** + * Parameters of applications created by this account including app global data. + */ + createdApps?: Application[] + + /** + * (apar) parameters of assets created by this account. + * Note: the raw account uses `map[int] -> Asset` for this type. + */ + createdAssets?: Asset[] + + /** + * AccountParticipation describes the parameters used by this account in consensus + * protocol. + */ + participation?: AccountParticipation + + /** + * Used as part of the rewards computation. Only applicable to accounts + * which are participating. + */ + rewardBase?: number + + /** + * Indicates what type of signature is used by this account, must be one of: + * * sig + * * msig + * * lsig + */ + sigType?: string + + /** + * The total number of bytes used by this account's app's box keys and + * values. + */ + totalBoxBytes?: number + + /** + * The number of existing boxes created by this account's app. + */ + totalBoxes?: number +} /** Account asset holding information at a given round. */ export type AccountAssetInformation = { diff --git a/src/types/algorand-client.asset.spec.ts b/src/types/algorand-client.asset.spec.ts new file mode 100644 index 00000000..52c25eb6 --- /dev/null +++ b/src/types/algorand-client.asset.spec.ts @@ -0,0 +1,198 @@ +import { describe, test } from '@jest/globals' +import { algorandFixture } from '../testing' +import { generateTestAsset } from '../testing/_asset' + +describe('Asset capability', () => { + const localnet = algorandFixture() + beforeEach(localnet.beforeEach, 100_000) + + test('Create an asset succeeds', async () => { + const { testAccount, algorand } = localnet.context + const accounts = [algorand.account.random(), algorand.account.random(), algorand.account.random(), algorand.account.random()] + const hash = new Uint8Array(32).fill(1) + const result = await algorand.send.assetCreate({ + sender: testAccount.addr, + total: 1000n, + decimals: 0, + assetName: 'Test Asset', + unitName: 'TEST', + url: 'https://example.com', + metadataHash: hash, + manager: accounts[0].addr, + reserve: accounts[1].addr, + freeze: accounts[2].addr, + clawback: accounts[3].addr, + defaultFrozen: true, + }) + + expect(result.confirmation.assetIndex).toBeGreaterThan(0n) + const assetData = await algorand.asset.getById(result.assetId) + expect(assetData.creator).toBe(testAccount.addr) + expect(assetData.total).toBe(1000n) + expect(assetData.decimals).toBe(0) + expect(assetData.defaultFrozen).toBe(true) + expect(assetData.unitName).toBe('TEST') + expect(assetData.assetName).toBe('Test Asset') + expect(assetData.url).toBe('https://example.com') + expect(assetData.metadataHash).toEqual(hash) + expect(assetData.manager).toBe(accounts[0].addr) + expect(assetData.reserve).toBe(accounts[1].addr) + expect(assetData.freeze).toBe(accounts[2].addr) + expect(assetData.clawback).toBe(accounts[3].addr) + }) + + test('OptIn an asset to an account succeed', async () => { + const { algorand, testAccount, generateAccount } = localnet.context + const dummyAssetId = await generateTestAsset(algorand, testAccount.addr, 1) + const dummyAssetIds = [dummyAssetId] + const secondAccount = await generateAccount({ initialFunds: (1).algos() }) + + const secondAccountInfo = await algorand.account.getInformation(secondAccount.addr) + expect(secondAccountInfo.totalAssetsOptedIn).toBe(0) + + await algorand.account.assetBulkOptIn(secondAccount, dummyAssetIds, { validityWindow: 100 }) + + const testAccountInfoAfterOptIn = await algorand.account.getInformation(secondAccount.addr) + expect(testAccountInfoAfterOptIn.totalAssetsOptedIn).toBe(1) + }) + + test('OptIn two batches of asset to an account succeed', async () => { + const { algorand, testAccount, generateAccount } = localnet.context + const dummyAssetIds: bigint[] = [] + const secondAccount = await generateAccount({ initialFunds: (3).algos() }) + for (let i = 0; i < 20; i++) { + const dummyAssetId = await generateTestAsset(algorand, testAccount.addr, 0) + dummyAssetIds.push(dummyAssetId) + } + await algorand.account.assetBulkOptIn(secondAccount, dummyAssetIds, { validityWindow: 100 }) + const secondAccountInfo = await algorand.account.getInformation(secondAccount.addr) + expect(secondAccountInfo.totalAssetsOptedIn).toBe(20) + }, 10e6) + + test('OptOut of an asset to an account succeed', async () => { + const { algorand, testAccount, generateAccount } = localnet.context + const dummyAssetId = await generateTestAsset(algorand, testAccount.addr, 0) + const dummyAssetId2 = await generateTestAsset(algorand, testAccount.addr, 0) + const dummyAssetIds = [dummyAssetId, dummyAssetId2] + const secondAccount = await generateAccount({ initialFunds: (1).algos() }) + + await algorand.account.assetBulkOptIn(secondAccount, dummyAssetIds, { validityWindow: 100 }) + + const secondAccountInfo = await algorand.account.getInformation(secondAccount.addr) + expect(secondAccountInfo.totalAssetsOptedIn).toBe(2) + + await algorand.account.assetBulkOptOut(secondAccount, dummyAssetIds, { validityWindow: 100 }) + + const secondAccountInfoAfterOptOut = await algorand.account.getInformation(secondAccount.addr) + expect(secondAccountInfoAfterOptOut.totalAssetsOptedIn).toBe(0) + }) + + test('OptOut of an not opt-in asset to an account failed', async () => { + const { algorand, testAccount, generateAccount } = localnet.context + const dummyAssetId = await generateTestAsset(algorand, testAccount.addr, 0) + const dummyAssetIds = [dummyAssetId, 1234567n, -132n] + const secondAccount = await generateAccount({ initialFunds: (1).algos() }) + + await algorand.account.assetBulkOptIn(secondAccount, [dummyAssetId], { validityWindow: 100 }) + + const secondAccountInfo = await algorand.account.getInformation(secondAccount.addr) + expect(secondAccountInfo.totalAssetsOptedIn).toBe(1) + + await expect(algorand.account.assetBulkOptOut(secondAccount, dummyAssetIds, { validityWindow: 100 })).rejects.toThrow( + `Account ${secondAccount.addr} is not opted-in to Assets 1234567, -132; can't opt-out.`, + ) + + const secondAccountInfoAfterFailedOptOut = await algorand.account.getInformation(secondAccount.addr) + expect(secondAccountInfoAfterFailedOptOut.totalAssetsOptedIn).toBe(1) + }) + + test('Bulk OptOut of an non-zero balance asset to an account failed ', async () => { + const { algorand, testAccount, generateAccount } = localnet.context + const dummyAssetId = await generateTestAsset(algorand, testAccount.addr, 0) + const dummyAssetId2 = await generateTestAsset(algorand, testAccount.addr, 0) + const dummyAssetIds = [dummyAssetId, dummyAssetId2] + const secondAccount = await generateAccount({ initialFunds: (1).algos() }) + + await algorand.account.assetBulkOptIn(secondAccount, dummyAssetIds, { validityWindow: 100 }) + + const secondAccountInfo = await algorand.account.getInformation(secondAccount.addr) + expect(secondAccountInfo.totalAssetsOptedIn).toBe(2) + + await algorand.send.assetTransfer({ + sender: testAccount.addr, + receiver: secondAccount.addr, + assetId: dummyAssetId, + amount: 5n, + note: `Transfer 5 assets with id ${dummyAssetId}`, + }) + + await expect(algorand.account.assetBulkOptOut(secondAccount, dummyAssetIds, { validityWindow: 100 })).rejects.toThrow( + `Account ${secondAccount.addr} has non-zero balance for Asset ${dummyAssetId}; can't opt-out.`, + ) + + const secondAccountInfoAfterFailedOptOut = await algorand.account.getInformation(secondAccount.addr) + expect(secondAccountInfoAfterFailedOptOut.totalAssetsOptedIn).toBe(2) + }) + + test('OptIn and OptOut of a single asset ', async () => { + const { algorand, testAccount, generateAccount } = localnet.context + const dummyAssetId = await generateTestAsset(algorand, testAccount.addr, 0) + const secondAccount = await generateAccount({ initialFunds: (1).algos() }) + + await algorand.send.assetOptIn({ sender: secondAccount.addr, assetId: dummyAssetId }) + + const secondAccountInfo = await algorand.account.getInformation(secondAccount.addr) + expect(secondAccountInfo.totalAssetsOptedIn).toBe(1) + + await algorand.send.assetOptOut({ + sender: secondAccount.addr, + creator: testAccount.addr, + assetId: dummyAssetId, + ensureZeroBalance: true, + }) + + const secondAccountInfoAfterOptOut = await algorand.account.getInformation(secondAccount.addr) + expect(secondAccountInfoAfterOptOut.totalAssetsOptedIn).toBe(0) + }) + + test('OptOut of non-zero balance single asset to an account fails by default', async () => { + const { algorand, testAccount, generateAccount } = localnet.context + const dummyAssetId = await generateTestAsset(algorand, testAccount.addr, 0) + const secondAccount = await generateAccount({ initialFunds: (1).algos() }) + + await algorand.send.assetOptIn({ sender: secondAccount.addr, assetId: dummyAssetId }) + + await algorand.send.assetTransfer({ + sender: testAccount.addr, + receiver: secondAccount.addr, + assetId: dummyAssetId, + amount: 5n, + note: `Transfer 5 assets with id ${dummyAssetId}`, + }) + + await expect( + algorand.send.assetOptOut({ sender: secondAccount.addr, creator: testAccount.addr, assetId: dummyAssetId, ensureZeroBalance: true }), + ).rejects.toThrow(`Account ${secondAccount.addr} does not have a zero balance for Asset ${dummyAssetId}; can't opt-out.`) + + const secondAccountInfoAfterFailedOptOut = await algorand.account.getInformation(secondAccount.addr) + expect(secondAccountInfoAfterFailedOptOut.totalAssetsOptedIn).toBe(1) + }) + + test('OptOut of two batches of asset to an account succeed', async () => { + const { algorand, testAccount, generateAccount } = localnet.context + const dummyAssetIds: bigint[] = [] + const secondAccount = await generateAccount({ initialFunds: (3).algos() }) + for (let i = 0; i < 20; i++) { + const dummyAssetId = await generateTestAsset(algorand, testAccount.addr, 0) + dummyAssetIds.push(dummyAssetId) + } + await algorand.account.assetBulkOptIn(secondAccount, dummyAssetIds, { validityWindow: 100 }) + const secondAccountInfo = await algorand.account.getInformation(secondAccount.addr) + expect(secondAccountInfo.totalAssetsOptedIn).toBe(20) + + await algorand.account.assetBulkOptOut(secondAccount, dummyAssetIds, { validityWindow: 100 }) + + const secondAccountInfoAfterOptOut = await algorand.account.getInformation(secondAccount.addr) + expect(secondAccountInfoAfterOptOut.totalAssetsOptedIn).toBe(0) + }, 10e6) +}) diff --git a/src/types/algorand-client.spec.ts b/src/types/algorand-client.spec.ts index 8b4f9fdf..194e9449 100644 --- a/src/types/algorand-client.spec.ts +++ b/src/types/algorand-client.spec.ts @@ -40,27 +40,25 @@ describe('AlgorandClient', () => { }, 10_000) test('sendPayment', async () => { - const alicePreBalance = (await algorand.account.getInformation(alice)).amount - const bobPreBalance = (await algorand.account.getInformation(bob)).amount + const alicePreBalance = (await algorand.account.getInformation(alice)).balance + const bobPreBalance = (await algorand.account.getInformation(bob)).balance await algorand.send.payment({ sender: alice.addr, receiver: bob.addr, amount: AlgoAmount.MicroAlgos(1) }) - const alicePostBalance = (await algorand.account.getInformation(alice)).amount - const bobPostBalance = (await algorand.account.getInformation(bob)).amount + const alicePostBalance = (await algorand.account.getInformation(alice)).balance + const bobPostBalance = (await algorand.account.getInformation(bob)).balance - expect(alicePostBalance).toBe(alicePreBalance - 1001) - expect(bobPostBalance).toBe(bobPreBalance + 1) + expect(alicePostBalance.microAlgos).toBe(alicePreBalance.microAlgos - 1001) + expect(bobPostBalance.microAlgos).toBe(bobPreBalance.microAlgos + 1) }) test('sendAssetCreate', async () => { const createResult = await algorand.send.assetCreate({ sender: alice.addr, total: 100n }) - const assetIndex = Number(createResult.confirmation.assetIndex) - - expect(assetIndex).toBeGreaterThan(0) + expect(createResult.assetId).toBeGreaterThan(0) }) test('addAtc from generated client', async () => { - const alicePreBalance = (await algorand.account.getInformation(alice)).amount - const bobPreBalance = (await algorand.account.getInformation(bob)).amount + const alicePreBalance = (await algorand.account.getInformation(alice)).balance + const bobPreBalance = (await algorand.account.getInformation(bob)).balance const doMathAtc = await appClient.compose().doMath({ a: 1, b: 2, operation: 'sum' }).atc() const result = await algorand @@ -69,18 +67,18 @@ describe('AlgorandClient', () => { .addAtc(doMathAtc) .execute() - const alicePostBalance = (await algorand.account.getInformation(alice)).amount - const bobPostBalance = (await algorand.account.getInformation(bob)).amount + const alicePostBalance = (await algorand.account.getInformation(alice)).balance + const bobPostBalance = (await algorand.account.getInformation(bob)).balance - expect(alicePostBalance).toBe(alicePreBalance - 2001) - expect(bobPostBalance).toBe(bobPreBalance + 1) + expect(alicePostBalance.microAlgos).toBe(alicePreBalance.microAlgos - 2001) + expect(bobPostBalance.microAlgos).toBe(bobPreBalance.microAlgos + 1) expect(result.returns?.[0].returnValue?.valueOf()).toBe(3n) }) test('addMethodCall', async () => { - const alicePreBalance = (await algorand.account.getInformation(alice)).amount - const bobPreBalance = (await algorand.account.getInformation(bob)).amount + const alicePreBalance = (await algorand.account.getInformation(alice)).balance + const bobPreBalance = (await algorand.account.getInformation(bob)).balance const methodRes = await algorand .newGroup() @@ -93,11 +91,11 @@ describe('AlgorandClient', () => { }) .execute() - const alicePostBalance = (await algorand.account.getInformation(alice)).amount - const bobPostBalance = (await algorand.account.getInformation(bob)).amount + const alicePostBalance = (await algorand.account.getInformation(alice)).balance + const bobPostBalance = (await algorand.account.getInformation(bob)).balance - expect(alicePostBalance).toBe(alicePreBalance - 2001) - expect(bobPostBalance).toBe(bobPreBalance + 1) + expect(alicePostBalance.microAlgos).toBe(alicePreBalance.microAlgos - 2001) + expect(bobPostBalance.microAlgos).toBe(bobPreBalance.microAlgos + 1) expect(methodRes.returns?.[0].returnValue?.valueOf()).toBe(3n) }) @@ -195,7 +193,7 @@ describe('AlgorandClient', () => { test('assetOptIn', async () => { const { algod } = fixture.context - const assetId = BigInt((await algorand.send.assetCreate({ sender: alice.addr, total: 1n })).confirmation.assetIndex!) + const assetId = (await algorand.send.assetCreate({ sender: alice.addr, total: 1n })).assetId await algorand.send.assetOptIn({ sender: alice.addr, diff --git a/src/types/algorand-client.transfer.spec.ts b/src/types/algorand-client.transfer.spec.ts new file mode 100644 index 00000000..34e88b58 --- /dev/null +++ b/src/types/algorand-client.transfer.spec.ts @@ -0,0 +1,378 @@ +import { describe, test } from '@jest/globals' +import algosdk, { TransactionType } from 'algosdk' +import invariant from 'tiny-invariant' +import { transferAsset } from '..' +import { algorandFixture } from '../testing' +import { generateTestAsset } from '../testing/_asset' +import { AlgorandClient } from './algorand-client' +import { TestNetDispenserApiClient } from './dispenser-client' + +describe('Transfer capability', () => { + const localnet = algorandFixture() + const env = process.env + + beforeEach(async () => { + jest.resetModules() + process.env = { ...env } + await localnet.beforeEach() + }, 10_000) + + afterEach(() => { + process.env = env + }) + + test('Transfer Algo is sent and waited for', async () => { + const { algorand, testAccount } = localnet.context + const secondAccount = algorand.account.random() + + const result = await algorand.send.payment({ + sender: testAccount.addr, + receiver: secondAccount.addr, + amount: (5).algos(), + note: 'Transfer 5 ALGOs', + }) + + const accountInfo = await algorand.account.getInformation(secondAccount.addr) + + expect(result.transaction).toBeInstanceOf(algosdk.Transaction) + expect(result.transaction.type).toBe(TransactionType.pay) + expect(result.confirmation.txn.txn.type).toBe('pay') + + expect(result.transaction.amount).toBe(5_000_000) + expect(result.confirmation.txn.txn.amt).toBe(5_000_000) + + expect(algosdk.encodeAddress(result.transaction.from.publicKey)).toBe(testAccount.addr) + // eslint-disable-next-line @typescript-eslint/no-non-null-assertion + expect(algosdk.encodeAddress(result.confirmation.txn.txn.snd)).toBe(testAccount.addr) + + expect(accountInfo.balance.microAlgos).toBe(5_000_000) + }) + + test('Transfer Algo respects string lease', async () => { + const { algorand, testAccount } = localnet.context + const secondAccount = algorand.account.random() + + await algorand.send.payment({ + sender: testAccount.addr, + receiver: secondAccount.addr, + amount: (1).algos(), + lease: 'test', + }) + + await expect( + algorand.send.payment({ + sender: testAccount.addr, + receiver: secondAccount.addr, + amount: (2).algos(), + lease: 'test', + }), + ).rejects.toThrow(/overlapping lease/) + }) + + test('Transfer Algo respects byte array lease', async () => { + const { algorand, testAccount } = localnet.context + const secondAccount = algorand.account.random() + + await algorand.send.payment({ + sender: testAccount.addr, + receiver: secondAccount.addr, + amount: (1).algos(), + lease: new Uint8Array([1, 2, 3, 4]), + }) + + await expect( + algorand.send.payment({ + sender: testAccount.addr, + receiver: secondAccount.addr, + amount: (2).algos(), + lease: new Uint8Array([1, 2, 3, 4]), + }), + ).rejects.toThrow(/overlapping lease/) + }) + + test('Transfer ASA, respects lease', async () => { + const { algorand, testAccount, generateAccount } = localnet.context + const dummyAssetId = await generateTestAsset(algorand, testAccount.addr, 100) + const secondAccount = await generateAccount({ initialFunds: (1).algos() }) + + await algorand.send.assetOptIn({ sender: secondAccount.addr, assetId: dummyAssetId }) + await algorand.send.assetTransfer({ + sender: testAccount.addr, + receiver: secondAccount.addr, + assetId: dummyAssetId, + amount: 1n, + lease: 'test', + }) + + await expect( + algorand.send.assetTransfer({ + sender: testAccount.addr, + receiver: secondAccount.addr, + assetId: dummyAssetId, + amount: 2n, + lease: 'test', + }), + ).rejects.toThrow(/overlapping lease/) + }, 10e6) + + test('Transfer ASA, receiver is not opted in', async () => { + const { algorand, testAccount } = localnet.context + const dummyAssetId = await generateTestAsset(algorand, testAccount.addr, 100) + const secondAccount = algorand.account.random() + + try { + await algorand.send.assetTransfer({ + sender: testAccount.addr, + receiver: secondAccount.addr, + assetId: dummyAssetId, + amount: 1n, + note: `Transfer 5 assets with id ${dummyAssetId}`, + }) + } catch (e: unknown) { + expect((e as Error).name).toEqual('URLTokenBaseHTTPError') + expect((e as Error).message).toContain('receiver error: must optin') + } + }, 10e6) + + test('Transfer ASA, sender is not opted in', async () => { + const { algorand, testAccount, generateAccount } = localnet.context + const dummyAssetId = await generateTestAsset(algorand, testAccount.addr, 100) + const secondAccount = await generateAccount({ initialFunds: (1).algos() }) + + await algorand.send.assetOptIn({ sender: secondAccount.addr, assetId: dummyAssetId }) + + try { + await algorand.send.assetTransfer({ + sender: testAccount.addr, + receiver: secondAccount.addr, + assetId: dummyAssetId, + amount: 1n, + note: `Transfer 5 assets with id ${dummyAssetId}`, + }) + } catch (e: unknown) { + expect((e as Error).name).toEqual('URLTokenBaseHTTPError') + expect((e as Error).message).toContain('sender error: must optin') + } + }, 10e6) + + test('Transfer ASA, asset doesnt exist', async () => { + const { algorand, testAccount, generateAccount } = localnet.context + const secondAccount = await generateAccount({ initialFunds: (1).algos() }) + + try { + await algorand.send.assetTransfer({ + sender: testAccount.addr, + receiver: secondAccount.addr, + assetId: 1n, + amount: 5n, + note: 'Transfer asset with wrong id', + }) + } catch (e: unknown) { + expect((e as Error).name).toEqual('URLTokenBaseHTTPError') + expect((e as Error).message).toContain('asset 1 missing from') + } + }, 10e6) + + // @deprecated test - remove when removing transferAsset + test('Transfer ASA, without sending', async () => { + const { algod, testAccount, generateAccount } = localnet.context + const secondAccount = await generateAccount({ initialFunds: (1).algos() }) + + const response = await transferAsset( + { + from: testAccount, + to: secondAccount.addr, + assetId: 1, + amount: 5, + note: `Transfer asset with wrong id`, + skipSending: true, + }, + algod, + ) + + expect(response.transaction).toBeDefined() + expect(response.confirmation).toBeUndefined() + }, 10e6) + + test('Transfer ASA, asset is transfered to another account', async () => { + const { algorand, testAccount, generateAccount } = localnet.context + const dummyAssetId = await generateTestAsset(algorand, testAccount.addr, 100) + const secondAccount = await generateAccount({ initialFunds: (1).algos() }) + + await algorand.send.assetOptIn({ sender: secondAccount.addr, assetId: dummyAssetId }) + + await algorand.send.assetTransfer({ + sender: testAccount.addr, + receiver: secondAccount.addr, + assetId: dummyAssetId, + amount: 5n, + note: `Transfer 5 assets with id ${dummyAssetId}`, + }) + + const secondAccountInfo = await algorand.account.getAssetInformation(secondAccount.addr, dummyAssetId) + expect(secondAccountInfo.balance).toBe(5n) + + const testAccountInfo = await algorand.account.getAssetInformation(testAccount.addr, dummyAssetId) + expect(testAccountInfo.balance).toBe(95n) + }, 10e6) + + test('Transfer ASA, asset is transfered to another account from revocationTarget', async () => { + const { algorand, testAccount, generateAccount } = localnet.context + const dummyAssetId = await generateTestAsset(algorand, testAccount.addr, 100) + const secondAccount = await generateAccount({ initialFunds: (1).algos() }) + const clawbackAccount = await generateAccount({ initialFunds: (1).algos() }) + + await algorand.send.assetOptIn({ sender: secondAccount.addr, assetId: dummyAssetId }) + + await algorand.send.assetOptIn({ sender: clawbackAccount.addr, assetId: dummyAssetId }) + + await algorand.send.assetTransfer({ + sender: testAccount.addr, + receiver: clawbackAccount.addr, + assetId: dummyAssetId, + amount: 5n, + note: `Transfer 5 assets with id ${dummyAssetId}`, + }) + + const clawbackFromInfo = await algorand.account.getAssetInformation(clawbackAccount.addr, dummyAssetId) + expect(clawbackFromInfo.balance).toBe(5n) + + await algorand.send.assetTransfer({ + sender: testAccount.addr, + receiver: secondAccount.addr, + assetId: dummyAssetId, + amount: 5n, + note: `Transfer 5 assets with id ${dummyAssetId}`, + clawbackTarget: clawbackAccount.addr, + }) + + const secondAccountInfo = await algorand.account.getAssetInformation(secondAccount.addr, dummyAssetId) + expect(secondAccountInfo.balance).toBe(5n) + + const clawbackAccountInfo = await algorand.account.getAssetInformation(clawbackAccount.addr, dummyAssetId) + expect(clawbackAccountInfo.balance).toBe(0n) + + const testAccountInfo = await algorand.account.getAssetInformation(testAccount.addr, dummyAssetId) + expect(testAccountInfo.balance).toBe(95n) + }, 10e6) + + test('ensureFunded is sent and waited for with correct amount for new account', async () => { + const { algorand, testAccount } = localnet.context + const secondAccount = algorand.account.random() + + const result = await algorand.account.ensureFunded(secondAccount, testAccount, (1).microAlgos()) + const accountInfo = await algorand.account.getInformation(secondAccount.addr) + + invariant(result) + expect(result.transactionId).toBe(result.transaction.txID()) + expect(result.amountFunded.microAlgos).toBe(100_001) + expect(accountInfo.balance.microAlgos).toBe(100_001) + }) + + test('ensureFunded respects minimum funding increment', async () => { + const { algorand, testAccount, generateAccount } = localnet.context + const secondAccount = await generateAccount({ initialFunds: (100_000).microAlgos() }) + + const result = await algorand.account.ensureFunded(secondAccount, testAccount, (1).microAlgos(), { + minFundingIncrement: (1).algos(), + }) + + invariant(result) + expect(result.amountFunded.algos).toBe(1) + const accountInfo = await algorand.account.getInformation(secondAccount.addr) + expect(accountInfo.balance.microAlgos).toBe(1_100_000) + }) + + test('ensureFunded uses dispenser account by default', async () => { + const { algorand } = localnet.context + const secondAccount = algorand.account.random() + const dispenser = await algorand.account.dispenserFromEnvironment() + + const result = await algorand.account.ensureFundedFromEnvironment(secondAccount, (1).microAlgos(), { + minFundingIncrement: (1).algos(), + }) + + invariant(result) + const resultReceiver = algosdk.encodeAddress(result.confirmation.txn.txn.snd) + expect(resultReceiver).toBe(dispenser.addr) + const accountInfo = await algorand.account.getInformation(secondAccount.addr) + expect(accountInfo.balance.algos).toBe(1) + }) + + test('ensureFunded uses dispenser api with access token successfully', async () => { + process.env.ALGOKIT_DISPENSER_ACCESS_TOKEN = 'dummy_token' + + const algorand = AlgorandClient.testNet() + + const dispenserClient = new TestNetDispenserApiClient() + Object.assign(dispenserClient, { + fund: jest.fn().mockImplementation(() => { + return Promise.resolve({ txId: 'dummy_tx_id', amount: 200_000 }) + }), + }) + + const accountToFund = algorand.account.random() + + const result = await algorand.account.ensureFundedFromTestNetDispenserApi(accountToFund, dispenserClient, (100).algos(), { + minFundingIncrement: (0.1).algos(), + }) + + invariant(result) + expect(result.transactionId).toBeDefined() + expect(result.amountFunded.algos).toBe(0.2) + }) + + test('ensureFunded uses dispenser api and fails with rejected response', async () => { + process.env.ALGOKIT_DISPENSER_ACCESS_TOKEN = 'dummy_token' + + const algorand = AlgorandClient.testNet() + + const dispenserClient = new TestNetDispenserApiClient() + Object.assign(dispenserClient, { + fund: jest.fn().mockImplementation(() => { + return Promise.reject(new Error('dummy_error')) + }), + }) + const accountToFund = algorand.account.random() + + await expect( + algorand.account.ensureFundedFromTestNetDispenserApi(accountToFund, dispenserClient, (100).algos(), { + minFundingIncrement: (1).algos(), + }), + ).rejects.toThrowErrorMatchingInlineSnapshot('"dummy_error"') + }) +}) + +describe('rekey', () => { + const localnet = algorandFixture() + const env = process.env + + beforeEach(async () => { + jest.resetModules() + process.env = { ...env } + await localnet.beforeEach() + }, 10_000) + + afterEach(() => { + process.env = env + }) + + test('Rekey works', async () => { + const { testAccount, algorand } = localnet.context + const secondAccount = algorand.account.random() + + await algorand.send.rekey({ + sender: testAccount.addr, + rekeyTo: secondAccount.addr, + note: 'Rekey', + }) + + // This will throw if the rekey wasn't successful + await algorand.send.payment({ + sender: testAccount.addr, + receiver: testAccount.addr, + amount: (1).microAlgos(), + signer: secondAccount.signer, + }) + }) +}) diff --git a/src/types/algorand-client.ts b/src/types/algorand-client.ts index f8824549..9cfa35a4 100644 --- a/src/types/algorand-client.ts +++ b/src/types/algorand-client.ts @@ -2,8 +2,9 @@ import algosdk from 'algosdk' import { Config } from '../config' import { MultisigAccount, SigningAccount, TransactionSignerAccount } from './account' import { AccountManager } from './account-manager' +import { AssetManager } from './asset-manager' import { AlgoSdkClients, ClientManager } from './client-manager' -import AlgokitComposer, { AssetOptOutParams, ExecuteParams, MethodCallParams } from './composer' +import AlgokitComposer, { AssetCreateParams, AssetOptOutParams, ExecuteParams, MethodCallParams } from './composer' import { AlgoConfig } from './network-client' import { ConfirmedTransactionResult, SendAtomicTransactionComposerResults } from './transaction' import Transaction = algosdk.Transaction @@ -19,6 +20,7 @@ export type SendSingleTransactionResult = SendAtomicTransactionComposerResults & export class AlgorandClient { private _clientManager: ClientManager private _accountManager: AccountManager + private _assetManager: AssetManager private _cachedSuggestedParams?: algosdk.SuggestedParams private _cachedSuggestedParamsExpiry?: Date @@ -29,6 +31,7 @@ export class AlgorandClient { private constructor(config: AlgoConfig | AlgoSdkClients) { this._clientManager = new ClientManager(config) this._accountManager = new AccountManager(this._clientManager) + this._assetManager = new AssetManager(this._clientManager) } /** @@ -132,6 +135,11 @@ export class AlgorandClient { return this._accountManager } + /** Methods for interacting with assets. */ + get asset() { + return this._assetManager + } + /** Start a new `AlgokitComposer` transaction group */ newGroup() { return new AlgokitComposer({ @@ -266,10 +274,13 @@ export class AlgorandClient { /** * Create an asset. */ - assetCreate: this._send((c) => c.addAssetCreate, { - postLog: (params, result) => - `Created asset${params.assetName ? ` ${params.assetName} ` : ''}${params.unitName ? ` (${params.unitName}) ` : ''} with ${params.total} units and ${params.decimals ?? 0} decimals created by ${params.sender} with ID ${result.confirmation.assetIndex} via transaction ${result.txIds.at(-1)}`, - }), + assetCreate: async (params: AssetCreateParams & ExecuteParams) => { + const result = await this._send((c) => c.addAssetCreate, { + postLog: (params, result) => + `Created asset${params.assetName ? ` ${params.assetName}` : ''}${params.unitName ? ` (${params.unitName})` : ''} with ${params.total} units and ${params.decimals ?? 0} decimals created by ${params.sender} with ID ${result.confirmation.assetIndex} via transaction ${result.txIds.at(-1)}`, + })(params) + return { ...result, assetId: BigInt(result.confirmation.assetIndex ?? 0) } + }, /** * Configure an existing asset. */ @@ -331,7 +342,7 @@ export class AlgorandClient { } } - params.creator = params.creator ?? ((await this.client.algod.getAssetByID(Number(params.assetId)).do()).params.creator as string) + params.creator = params.creator ?? (await this.asset.getById(params.assetId)).creator return await this._send((c) => c.addAssetOptOut, { preLog: (params, transaction) => diff --git a/src/types/app-client.spec.ts b/src/types/app-client.spec.ts index c8989232..358fb4ca 100644 --- a/src/types/app-client.spec.ts +++ b/src/types/app-client.spec.ts @@ -427,7 +427,7 @@ describe('application-client', () => { }) // If the rekey didn't work this will throw - const rekeyedAccount = algorand.account.rekeyed(rekeyTo, testAccount.addr) + const rekeyedAccount = algorand.account.rekeyed(testAccount.addr, rekeyTo) await algokit.transferAlgos( { amount: (0).algos(), diff --git a/src/types/asset-manager.ts b/src/types/asset-manager.ts new file mode 100644 index 00000000..89d62c15 --- /dev/null +++ b/src/types/asset-manager.ts @@ -0,0 +1,174 @@ +import algosdk from 'algosdk' +import { ClientManager } from './client-manager' +import AssetModel = algosdk.modelsv2.Asset + +export interface AssetInformation { + /** The ID of the asset. */ + assetId: bigint + + /** The address of the account that created the asset. + * + * This is the address where the parameters for this asset can be found, + * and also the address where unwanted asset units can be sent when + * closing out an asset position and opting-out of the asset. + */ + creator: string + + /** The total amount of the smallest divisible (decimal) units that were created of the asset. + * + * For example, if `decimals` is, say, 2, then for every 100 `total` there is 1 whole unit. + */ + total: bigint + + /** The amount of decimal places the asset was created with. + * + * * If 0, the asset is not divisible; + * * If 1, the base unit of the asset is in tenths; + * * If 2, the base unit of the asset is in hundredths; + * * If 3, the base unit of the asset is in thousandths; + * * and so on up to 19 decimal places. + */ + decimals: number + + /** Whether the asset was frozen by default for all accounts. + * + * If `true` then for anyone apart from the creator to hold the + * asset it needs to be unfrozen per account using an asset freeze + * transaction from the `freeze` account. + */ + defaultFrozen?: boolean + + /** The address of the optional account that can manage the configuration of the asset and destroy it. + * + * If not set the asset is permanently immutable. + */ + manager?: string + + /** + * The address of the optional account that holds the reserve (uncirculated supply) units of the asset. + * + * This address has no specific authority in the protocol itself and is informational only. + * + * Some standards like [ARC-19](https://github.com/algorandfoundation/ARCs/blob/main/ARCs/arc-0019.md) + * rely on this field to hold meaningful data. + * + * It can be used in the case where you want to signal to holders of your asset that the uncirculated units + * of the asset reside in an account that is different from the default creator account. + * + * If not set the field is permanently empty. + */ + reserve?: string + + /** + * The address of the optional account that can be used to freeze or unfreeze holdings of this asset for any account. + * + * If empty, freezing is not permitted. + * + * If not set the field is permanently empty. + */ + freeze?: string + + /** + * The address of the optional account that can clawback holdings of this asset from any account. + * + * The clawback account has the ability to **unconditionally take assets from any account**. + * + * If empty, clawback is not permitted. + * + * If not set the field is permanently empty. + */ + clawback?: string + + /** The optional name of the unit of this asset (e.g. ticker name). + * + * Max size is 8 bytes. + */ + unitName?: string + + /** The optional name of the unit of this asset (e.g. ticker name). + * + * Max size is 8 bytes. + */ + unitNameAsBytes?: Uint8Array + + /** The optional name of the asset. + * + * Max size is 32 bytes. + */ + assetName?: string + + /** The optional name of the asset. + * + * Max size is 32 bytes. + */ + assetNameAsBytes?: Uint8Array + + /** Optional URL where more information about the asset can be retrieved (e.g. metadata). + * + * Max size is 96 bytes. + */ + url?: string + + /** Optional URL where more information about the asset can be retrieved (e.g. metadata). + * + * Max size is 96 bytes. + */ + urlAsBytes?: Uint8Array + + /** 32-byte hash of some metadata that is relevant to the asset and/or asset holders. + * + * The format of this metadata is up to the application. + */ + metadataHash?: Uint8Array +} + +/** Allows management of asset information. */ +export class AssetManager { + private _clientManager: ClientManager + + /** + * Create a new asset manager. + * @param clientManager The ClientManager client to use for algod client + * @example Create a new asset manager + * ```typescript + * const assetManager = new AssetManager(clientManager) + * ``` + */ + constructor(clientManager: ClientManager) { + this._clientManager = clientManager + } + + /** + * Returns the current asset information for the asset with the given ID. + * + * @example + * ```typescript + * const assetInfo = await assetManager.getById(12353n); + * ``` + * + * @param assetId The ID of the asset + * @returns The asset information + */ + public async getById(assetId: bigint): Promise { + const asset = AssetModel.from_obj_for_encoding(await this._clientManager.algod.getAssetByID(Number(assetId)).do()) + + return { + assetId: BigInt(asset.index), + total: BigInt(asset.params.total), + decimals: Number(asset.params.decimals), + assetName: asset.params.name, + assetNameAsBytes: asset.params.nameB64, + unitName: asset.params.unitName, + unitNameAsBytes: asset.params.unitNameB64, + url: asset.params.url, + urlAsBytes: asset.params.urlB64, + creator: asset.params.creator, + manager: asset.params.manager, + clawback: asset.params.clawback, + freeze: asset.params.freeze, + reserve: asset.params.reserve, + defaultFrozen: asset.params.defaultFrozen, + metadataHash: asset.params.metadataHash, + } + } +} diff --git a/src/types/asset.ts b/src/types/asset.ts index 6be72d25..34d0a453 100644 --- a/src/types/asset.ts +++ b/src/types/asset.ts @@ -3,7 +3,7 @@ import { AlgoAmount } from './amount' import { SendTransactionFrom, SendTransactionParams, TransactionNote } from './transaction' import SuggestedParams = algosdk.SuggestedParams -/** Parameters for `createAsset` call. */ +/** @deprecated Parameters for `createAsset` call. */ export interface CreateAssetParams extends SendTransactionParams { /** The account to create the asset. * @@ -66,7 +66,7 @@ export interface CreateAssetParams extends SendTransactionParams { lease?: string | Uint8Array } -/** Parameters for `assetOptIn` call. */ +/** @deprecated Parameters for `assetOptIn` call. */ export interface AssetOptInParams extends SendTransactionParams { /** The account to opt in/out for */ account: SendTransactionFrom @@ -80,7 +80,7 @@ export interface AssetOptInParams extends SendTransactionParams { lease?: string | Uint8Array } -/** Parameters for `assetOptOut` call. */ +/** @deprecated Parameters for `assetOptOut` call. */ export interface AssetOptOutParams extends AssetOptInParams { /** The address of the creator account for the asset; if unspecified then it looks it up using algod */ assetCreatorAddress?: string @@ -88,7 +88,7 @@ export interface AssetOptOutParams extends AssetOptInParams { ensureZeroBalance?: boolean } -/** Parameters for `assetBulkOptIn` / `assetBulkOptOut` call. */ +/** @deprecated Parameters for `assetBulkOptIn` / `assetBulkOptOut` call. */ export interface AssetBulkOptInOutParams { /** The account to opt in/out for */ account: SendTransactionFrom diff --git a/src/types/composer.ts b/src/types/composer.ts index 3edab36b..ed5c0413 100644 --- a/src/types/composer.ts +++ b/src/types/composer.ts @@ -77,6 +77,8 @@ export type AssetCreateParams = CommonTransactionParams & { total: bigint /** The amount of decimal places the asset should have. + * + * If unspecified then the asset will be in whole units (i.e. `0`). * * * If 0, the asset is not divisible; * * If 1, the base unit of the asset is in tenths; @@ -88,7 +90,7 @@ export type AssetCreateParams = CommonTransactionParams & { */ decimals?: number - /** Whether the asset is frozen by default in the creator address. + /** Whether the asset is frozen by default for all accounts. * Defaults to `false`. * * If `true` then for anyone apart from the creator to hold the diff --git a/src/types/transfer.ts b/src/types/transfer.ts index d9144511..748d600e 100644 --- a/src/types/transfer.ts +++ b/src/types/transfer.ts @@ -4,7 +4,7 @@ import { TestNetDispenserApiClient } from './dispenser-client' import { SendTransactionFrom, SendTransactionParams, TransactionNote } from './transaction' import SuggestedParams = algosdk.SuggestedParams -/** Parameters for `transferAlgos` call. */ +/** @deprecated Parameters for `transferAlgos` call. */ export interface AlgoTransferParams extends SendTransactionParams { /** The account that will send the ALGOs */ from: SendTransactionFrom @@ -20,7 +20,7 @@ export interface AlgoTransferParams extends SendTransactionParams { lease?: string | Uint8Array } -/** Parameters for `rekeyAccount` call. */ +/** @deprecated Parameters for `rekeyAccount` call. */ export interface AlgoRekeyParams extends SendTransactionParams { /** The account that will be rekeyed */ from: SendTransactionFrom @@ -34,7 +34,7 @@ export interface AlgoRekeyParams extends SendTransactionParams { lease?: string | Uint8Array } -/** Parameters for `ensureFunded` call. */ +/** @deprecated Parameters for `ensureFunded` call. */ export interface EnsureFundedParams extends SendTransactionParams { /** The account to fund */ accountToFund: SendTransactionFrom | string @@ -52,7 +52,7 @@ export interface EnsureFundedParams extends SendTransactionParams { lease?: string | Uint8Array } -/** Parameters for `transferAsset` call. */ +/** @deprecated Parameters for `transferAsset` call. */ export interface TransferAssetParams extends SendTransactionParams { /** The account that will send the asset */ from: SendTransactionFrom @@ -72,6 +72,7 @@ export interface TransferAssetParams extends SendTransactionParams { lease?: string | Uint8Array } +/** @deprecated */ export interface EnsureFundedReturnType { /** The transaction */ transactionId: string From 485c5e2529df2f06906778df3dd51bfc2271dd64 Mon Sep 17 00:00:00 2001 From: "Rob Moore (MakerX)" Date: Tue, 18 Jun 2024 01:22:36 +0800 Subject: [PATCH 03/18] docs: Started writing docs for algorand client (WIP) --- src/types/algorand-client.ts | 502 +++++++++++++++++++++++++++++++++-- src/types/composer.ts | 31 ++- 2 files changed, 508 insertions(+), 25 deletions(-) diff --git a/src/types/algorand-client.ts b/src/types/algorand-client.ts index 9cfa35a4..654db328 100644 --- a/src/types/algorand-client.ts +++ b/src/types/algorand-client.ts @@ -110,7 +110,7 @@ export class AlgorandClient { } /** Get suggested params for a transaction (either cached or from algod if the cache is stale or empty) */ - async getSuggestedParams(): Promise { + public async getSuggestedParams(): Promise { if (this._cachedSuggestedParams && (!this._cachedSuggestedParamsExpiry || this._cachedSuggestedParamsExpiry > new Date())) { return { ...this._cachedSuggestedParams, @@ -136,12 +136,12 @@ export class AlgorandClient { } /** Methods for interacting with assets. */ - get asset() { + public get asset() { return this._assetManager } /** Start a new `AlgokitComposer` transaction group */ - newGroup() { + public newGroup() { return new AlgokitComposer({ algod: this.client.algod, getSigner: (addr: string) => this.account.getSigner(addr), @@ -188,7 +188,7 @@ export class AlgorandClient { /** * Methods for sending a single transaction. */ - send = { + public send = { /** * Send a payment transaction to transfer algos between accounts. * @param params The parameters for the payment transaction @@ -272,7 +272,50 @@ export class AlgorandClient { postLog: (params, result) => `Rekeyed ${params.sender} to ${params.rekeyTo} via transaction ${result.txIds.at(-1)}`, }), /** - * Create an asset. + * Create a new Algorand Standard Asset. + * + * The account that sends this transaction will automatically be + * opted in to the asset and will hold all units after creation. + * + * @param params The parameters for the asset creation transaction + * + * @example Basic example + * ```typescript + * await algorand.send.assetCreate({sender: "CREATORADDRESS", total: 100n}) + * ``` + * @example Advanced example + * ```typescript + * await algorand.send.assetCreate({ + * sender: 'CREATORADDRESS', + * total: 100n, + * decimals: 2, + * assetName: 'asset', + * unitName: 'unit', + * url: 'url', + * metadataHash: 'metadataHash', + * defaultFrozen: false, + * manager: 'MANAGERADDRESS', + * reserve: 'RESERVEADDRESS', + * freeze: 'FREEZEADDRESS', + * clawback: 'CLAWBACKADDRESS', + * lease: 'lease', + * note: 'note', + * firstValidRound: 1000n, + * validityWindow: 10, + * extraFee: (1000).microAlgos(), + * staticFee: (1000).microAlgos(), + * // Max fee doesn't make sense with extraFee AND staticFee + * // already specified, but here for completeness + * maxFee: (3000).microAlgos(), + * // Signer only needed if you want to provide one, + * // generally you'd register it with AlgorandClient + * // against the sender nad not need to pass it in + * signer: transactionSigner, + * maxRoundsToWaitForConfirmation: 5, + * suppressLog: true, + * }) + * ``` + * @returns The result of the transaction and the transaction that was sent */ assetCreate: async (params: AssetCreateParams & ExecuteParams) => { const result = await this._send((c) => c.addAssetCreate, { @@ -282,39 +325,248 @@ export class AlgorandClient { return { ...result, assetId: BigInt(result.confirmation.assetIndex ?? 0) } }, /** - * Configure an existing asset. + * Configure an existing Algorand Standard Asset. + * + * **Note:** The manager, reserve, freeze, and clawback addresses + * are immutably empty if they are not set. If manager is not set then + * all fields are immutable from that point forward. + * + * @param params The parameters for the asset config transaction + * + * @example Basic example + * ```typescript + * await algorand.send.assetConfig({sender: "MANAGERADDRESS", assetId: 123456n, manager: "MANAGERADDRESS" }) + * ``` + * @example Advanced example + * ```typescript + * await algorand.send.assetCreate({ + * sender: 'MANAGERADDRESS', + * assetId: 123456n, + * manager: 'MANAGERADDRESS', + * reserve: 'RESERVEADDRESS', + * freeze: 'FREEZEADDRESS', + * clawback: 'CLAWBACKADDRESS', + * lease: 'lease', + * note: 'note', + * firstValidRound: 1000n, + * validityWindow: 10, + * extraFee: (1000).microAlgos(), + * staticFee: (1000).microAlgos(), + * // Max fee doesn't make sense with extraFee AND staticFee + * // already specified, but here for completeness + * maxFee: (3000).microAlgos(), + * // Signer only needed if you want to provide one, + * // generally you'd register it with AlgorandClient + * // against the sender nad not need to pass it in + * signer: transactionSigner, + * maxRoundsToWaitForConfirmation: 5, + * suppressLog: true, + * }) + * ``` + * @returns The result of the transaction and the transaction that was sent */ assetConfig: this._send((c) => c.addAssetConfig, { preLog: (params, transaction) => `Configuring asset with ID ${params.assetId} via transaction ${transaction.txID()}`, }), /** - * Freeze or unfreeze an asset. + * Freeze or unfreeze an Algorand Standard Asset for an account. + * + * @param params The parameters for the asset freeze transaction + * + * @example Basic example + * ```typescript + * await algorand.send.assetFreeze({sender: "MANAGERADDRESS", assetId: 123456n, account: "ACCOUNTADDRESS", frozen: true }) + * ``` + * @example Advanced example + * ```typescript + * await algorand.send.assetFreeze({ + * sender: 'MANAGERADDRESS', + * assetId: 123456n, + * account: 'ACCOUNTADDRESS', + * frozen: true, + * lease: 'lease', + * note: 'note', + * firstValidRound: 1000n, + * validityWindow: 10, + * extraFee: (1000).microAlgos(), + * staticFee: (1000).microAlgos(), + * // Max fee doesn't make sense with extraFee AND staticFee + * // already specified, but here for completeness + * maxFee: (3000).microAlgos(), + * // Signer only needed if you want to provide one, + * // generally you'd register it with AlgorandClient + * // against the sender nad not need to pass it in + * signer: transactionSigner, + * maxRoundsToWaitForConfirmation: 5, + * suppressLog: true, + * }) + * ``` + * @returns The result of the transaction and the transaction that was sent */ assetFreeze: this._send((c) => c.addAssetFreeze, { preLog: (params, transaction) => `Freezing asset with ID ${params.assetId} via transaction ${transaction.txID()}`, }), /** - * Destroy an asset. + * Destroys an Algorand Standard Asset. + * + * Created assets can be destroyed only by the asset manager account. + * All of the assets must be owned by the creator of the asset before + * the asset can be deleted. + * + * @param params The parameters for the asset destroy transaction + * + * @example Basic example + * ```typescript + * await algorand.send.assetDestroy({sender: "MANAGERADDRESS", assetId: 123456n }) + * ``` + * @example Advanced example + * ```typescript + * await algorand.send.assetDestroy({ + * sender: 'MANAGERADDRESS', + * assetId: 123456n, + * lease: 'lease', + * note: 'note', + * firstValidRound: 1000n, + * validityWindow: 10, + * extraFee: (1000).microAlgos(), + * staticFee: (1000).microAlgos(), + * // Max fee doesn't make sense with extraFee AND staticFee + * // already specified, but here for completeness + * maxFee: (3000).microAlgos(), + * // Signer only needed if you want to provide one, + * // generally you'd register it with AlgorandClient + * // against the sender nad not need to pass it in + * signer: transactionSigner, + * maxRoundsToWaitForConfirmation: 5, + * suppressLog: true, + * }) + * ``` + * @returns The result of the transaction and the transaction that was sent */ assetDestroy: this._send((c) => c.addAssetDestroy, { preLog: (params, transaction) => `Destroying asset with ID ${params.assetId} via transaction ${transaction.txID()}`, }), /** - * Transfer an asset. + * Transfer an Algorand Standard Asset. + * + * @param params The parameters for the asset transfer transaction + * + * @example Basic example + * ```typescript + * await algorand.send.assetTransfer({sender: "HOLDERADDRESS", assetId: 123456n, amount: 1n, receiver: "RECEIVERADDRESS" }) + * ``` + * @example Advanced example (with clawback) + * ```typescript + * await algorand.send.assetTransfer({ + * sender: 'CLAWBACKADDRESS', + * assetId: 123456n, + * amount: 1n, + * receiver: 'RECEIVERADDRESS', + * clawbackTarget: 'HOLDERADDRESS', + * // This field needs to be used with caution + * closeAssetTo: 'ADDRESSTOCLOSETO' + * lease: 'lease', + * note: 'note', + * firstValidRound: 1000n, + * validityWindow: 10, + * extraFee: (1000).microAlgos(), + * staticFee: (1000).microAlgos(), + * // Max fee doesn't make sense with extraFee AND staticFee + * // already specified, but here for completeness + * maxFee: (3000).microAlgos(), + * // Signer only needed if you want to provide one, + * // generally you'd register it with AlgorandClient + * // against the sender nad not need to pass it in + * signer: transactionSigner, + * maxRoundsToWaitForConfirmation: 5, + * suppressLog: true, + * }) + * ``` + * @returns The result of the transaction and the transaction that was sent */ assetTransfer: this._send((c) => c.addAssetTransfer, { preLog: (params, transaction) => `Transferring ${params.amount} units of asset with ID ${params.assetId} from ${params.sender} to ${params.receiver} via transaction ${transaction.txID()}`, }), /** - * Opt an account into an asset. + * Opt an account into an Algorand Standard Asset. + * + * @param params The parameters for the asset opt-in transaction + * + * @example Basic example + * ```typescript + * await algorand.send.assetOptIn({sender: "SENDERADDRESS", assetId: 123456n }) + * ``` + * @example Advanced example + * ```typescript + * await algorand.send.assetOptIn({ + * sender: 'SENDERADDRESS', + * assetId: 123456n, + * lease: 'lease', + * note: 'note', + * firstValidRound: 1000n, + * validityWindow: 10, + * extraFee: (1000).microAlgos(), + * staticFee: (1000).microAlgos(), + * // Max fee doesn't make sense with extraFee AND staticFee + * // already specified, but here for completeness + * maxFee: (3000).microAlgos(), + * // Signer only needed if you want to provide one, + * // generally you'd register it with AlgorandClient + * // against the sender nad not need to pass it in + * signer: transactionSigner, + * maxRoundsToWaitForConfirmation: 5, + * suppressLog: true, + * }) + * ``` + * @returns The result of the transaction and the transaction that was sent */ assetOptIn: this._send((c) => c.addAssetOptIn, { preLog: (params, transaction) => `Opting in ${params.sender} to asset with ID ${params.assetId} via transaction ${transaction.txID()}`, }), /** - * Opt an account out of an asset. + * Opt an account out of an Algorand Standard Asset. + * + * *Note:* If the account has a balance of the asset, + * it will not be able to opt-out unless `ensureZeroBalance` + * is set to `false` (but then the account will lose the assets). + * + * @param params The parameters for the asset opt-out transaction + * + * @example Basic example (without creator) + * ```typescript + * await algorand.send.assetOptOut({sender: "SENDERADDRESS", assetId: 123456n, ensureZeroBalance: true }) + * ``` + * @example Basic example (with creator) + * ```typescript + * await algorand.send.assetOptOut({sender: "SENDERADDRESS", creator: "CREATORADDRESS", assetId: 123456n, ensureZeroBalance: true }) + * ``` + * @example Advanced example + * ```typescript + * await algorand.send.assetOptIn({ + * sender: 'SENDERADDRESS', + * assetId: 123456n, + * creator: 'CREATORADDRESS', + * ensureZeroBalance: true, + * lease: 'lease', + * note: 'note', + * firstValidRound: 1000n, + * validityWindow: 10, + * extraFee: (1000).microAlgos(), + * staticFee: (1000).microAlgos(), + * // Max fee doesn't make sense with extraFee AND staticFee + * // already specified, but here for completeness + * maxFee: (3000).microAlgos(), + * // Signer only needed if you want to provide one, + * // generally you'd register it with AlgorandClient + * // against the sender nad not need to pass it in + * signer: transactionSigner, + * maxRoundsToWaitForConfirmation: 5, + * suppressLog: true, + * }) + * ``` + * @returns The result of the transaction and the transaction that was sent */ assetOptOut: async ( params: Omit & { @@ -378,7 +630,7 @@ export class AlgorandClient { /** * Methods for building transactions */ - transactions = { + public transactions = { /** * Create a payment transaction to transfer algos between accounts. * @param params The parameters for the payment transaction @@ -443,19 +695,231 @@ export class AlgorandClient { * @returns The rekey transaction */ rekey: this._transaction((c) => c.addRekey), - /** Create an asset creation transaction. */ + /** Create a create Algorand Standard Asset transaction. + * + * The account that sends this transaction will automatically be + * opted in to the asset and will hold all units after creation. + * + * @param params The parameters for the asset creation transaction + * + * @example Basic example + * ```typescript + * await algorand.transaction.assetCreate({sender: "CREATORADDRESS", total: 100n}) + * ``` + * @example Advanced example + * ```typescript + * await algorand.transaction.assetCreate({ + * sender: 'CREATORADDRESS', + * total: 100n, + * decimals: 2, + * assetName: 'asset', + * unitName: 'unit', + * url: 'url', + * metadataHash: 'metadataHash', + * defaultFrozen: false, + * manager: 'MANAGERADDRESS', + * reserve: 'RESERVEADDRESS', + * freeze: 'FREEZEADDRESS', + * clawback: 'CLAWBACKADDRESS', + * lease: 'lease', + * note: 'note', + * firstValidRound: 1000n, + * validityWindow: 10, + * extraFee: (1000).microAlgos(), + * staticFee: (1000).microAlgos(), + * // Max fee doesn't make sense with extraFee AND staticFee + * // already specified, but here for completeness + * maxFee: (3000).microAlgos(), + * }) + * ``` + * @returns The asset create transaction + */ assetCreate: this._transaction((c) => c.addAssetCreate), - /** Create an asset config transaction. */ + /** Create an asset config transaction to reconfigure an existing Algorand Standard Asset. + * + * **Note:** The manager, reserve, freeze, and clawback addresses + * are immutably empty if they are not set. If manager is not set then + * all fields are immutable from that point forward. + * + * @param params The parameters for the asset config transaction + * + * @example Basic example + * ```typescript + * await algorand.transaction.assetConfig({sender: "MANAGERADDRESS", assetId: 123456n, manager: "MANAGERADDRESS" }) + * ``` + * @example Advanced example + * ```typescript + * await algorand.transaction.assetCreate({ + * sender: 'MANAGERADDRESS', + * assetId: 123456n, + * manager: 'MANAGERADDRESS', + * reserve: 'RESERVEADDRESS', + * freeze: 'FREEZEADDRESS', + * clawback: 'CLAWBACKADDRESS', + * lease: 'lease', + * note: 'note', + * firstValidRound: 1000n, + * validityWindow: 10, + * extraFee: (1000).microAlgos(), + * staticFee: (1000).microAlgos(), + * // Max fee doesn't make sense with extraFee AND staticFee + * // already specified, but here for completeness + * maxFee: (3000).microAlgos(), + * }) + * ``` + * @returns The asset config transaction + */ assetConfig: this._transaction((c) => c.addAssetConfig), - /** Create an asset freeze transaction. */ + /** Create an Algorand Standard Asset freeze transaction. + * + * @param params The parameters for the asset freeze transaction + * + * @example Basic example + * ```typescript + * await algorand.transaction.assetFreeze({sender: "MANAGERADDRESS", assetId: 123456n, account: "ACCOUNTADDRESS", frozen: true }) + * ``` + * @example Advanced example + * ```typescript + * await algorand.transaction.assetFreeze({ + * sender: 'MANAGERADDRESS', + * assetId: 123456n, + * account: 'ACCOUNTADDRESS', + * frozen: true, + * lease: 'lease', + * note: 'note', + * firstValidRound: 1000n, + * validityWindow: 10, + * extraFee: (1000).microAlgos(), + * staticFee: (1000).microAlgos(), + * // Max fee doesn't make sense with extraFee AND staticFee + * // already specified, but here for completeness + * maxFee: (3000).microAlgos(), + * }) + * ``` + * @returns The asset freeze transaction + */ assetFreeze: this._transaction((c) => c.addAssetFreeze), - /** Create an asset destroy transaction. */ + /** Create an Algorand Standard Asset destroy transaction. + * + * Created assets can be destroyed only by the asset manager account. + * All of the assets must be owned by the creator of the asset before + * the asset can be deleted. + * + * @param params The parameters for the asset destroy transaction + * + * @example Basic example + * ```typescript + * await algorand.transaction.assetDestroy({sender: "MANAGERADDRESS", assetId: 123456n }) + * ``` + * @example Advanced example + * ```typescript + * await algorand.transaction.assetDestroy({ + * sender: 'MANAGERADDRESS', + * assetId: 123456n, + * lease: 'lease', + * note: 'note', + * firstValidRound: 1000n, + * validityWindow: 10, + * extraFee: (1000).microAlgos(), + * staticFee: (1000).microAlgos(), + * // Max fee doesn't make sense with extraFee AND staticFee + * // already specified, but here for completeness + * maxFee: (3000).microAlgos(), + * }) + * ``` + * @returns The asset destroy transaction + */ assetDestroy: this._transaction((c) => c.addAssetDestroy), - /** Create an asset transfer transaction. */ + /** Create an Algorand Standard Asset transfer transaction. + * + * @param params The parameters for the asset transfer transaction + * + * @example Basic example + * ```typescript + * await algorand.transaction.assetTransfer({sender: "HOLDERADDRESS", assetId: 123456n, amount: 1n, receiver: "RECEIVERADDRESS" }) + * ``` + * @example Advanced example (with clawback) + * ```typescript + * await algorand.transaction.assetTransfer({ + * sender: 'CLAWBACKADDRESS', + * assetId: 123456n, + * amount: 1n, + * receiver: 'RECEIVERADDRESS', + * clawbackTarget: 'HOLDERADDRESS', + * // This field needs to be used with caution + * closeAssetTo: 'ADDRESSTOCLOSETO' + * lease: 'lease', + * note: 'note', + * firstValidRound: 1000n, + * validityWindow: 10, + * extraFee: (1000).microAlgos(), + * staticFee: (1000).microAlgos(), + * // Max fee doesn't make sense with extraFee AND staticFee + * // already specified, but here for completeness + * maxFee: (3000).microAlgos(), + * }) + * ``` + * @returns The result of the asset transfer transaction + */ assetTransfer: this._transaction((c) => c.addAssetTransfer), - /** Create an asset opt-in transaction. */ + /** Create an Algorand Standard Asset opt-in transaction. + * + * @param params The parameters for the asset opt-in transaction + * + * @example Basic example + * ```typescript + * await algorand.transaction.assetOptIn({sender: "SENDERADDRESS", assetId: 123456n }) + * ``` + * @example Advanced example + * ```typescript + * await algorand.transaction.assetOptIn({ + * sender: 'SENDERADDRESS', + * assetId: 123456n, + * lease: 'lease', + * note: 'note', + * firstValidRound: 1000n, + * validityWindow: 10, + * extraFee: (1000).microAlgos(), + * staticFee: (1000).microAlgos(), + * // Max fee doesn't make sense with extraFee AND staticFee + * // already specified, but here for completeness + * maxFee: (3000).microAlgos(), + * }) + * ``` + * @returns The asset opt-in transaction + */ assetOptIn: this._transaction((c) => c.addAssetOptIn), - /** Create an asset opt-out transaction. */ + /** Create an asset opt-out transaction. + * + * *Note:* If the account has a balance of the asset, + * it will lose those assets + * + * @param params The parameters for the asset opt-out transaction + * + * @example Basic example + * ```typescript + * await algorand.transaction.assetOptOut({sender: "SENDERADDRESS", creator: "CREATORADDRESS", assetId: 123456n }) + * ``` + * @example Advanced example + * ```typescript + * await algorand.transaction.assetOptIn({ + * sender: 'SENDERADDRESS', + * assetId: 123456n, + * creator: 'CREATORADDRESS', + * ensureZeroBalance: true, + * lease: 'lease', + * note: 'note', + * firstValidRound: 1000n, + * validityWindow: 10, + * extraFee: (1000).microAlgos(), + * staticFee: (1000).microAlgos(), + * // Max fee doesn't make sense with extraFee AND staticFee + * // already specified, but here for completeness + * maxFee: (3000).microAlgos(), + * }) + * ``` + * @returns The asset opt-out transaction + */ assetOptOut: this._transaction((c) => c.addAssetOptOut), /** Create an application call transaction. */ appCall: this._transaction((c) => c.addAppCall), diff --git a/src/types/composer.ts b/src/types/composer.ts index ed5c0413..edbcf7f9 100644 --- a/src/types/composer.ts +++ b/src/types/composer.ts @@ -50,7 +50,10 @@ export type PaymentParams = CommonTransactionParams & { receiver: string /** Amount to send */ amount: AlgoAmount - /** If given, close the sender account and send the remaining balance to this address */ + /** If given, close the sender account and send the remaining balance to this address + * + * *Warning:* Be careful with this parameter as it can lead to loss of funds if not used correctly. + */ closeRemainderTo?: string } @@ -177,12 +180,17 @@ export type AssetCreateParams = CommonTransactionParams & { metadataHash?: string | Uint8Array } -/** Parameters to define an asset config transaction. */ +/** Parameters to define an asset reconfiguration transaction. + * + * **Note:** The manager, reserve, freeze, and clawback addresses + * are immutably empty if they are not set. If manager is not set then + * all fields are immutable from that point forward. + */ export type AssetConfigParams = CommonTransactionParams & { /** ID of the asset */ assetId: bigint /** The address that can change the manager, reserve, clawback, and freeze addresses. There will permanently be no manager if undefined or an empty string */ - manager?: string + manager: string | undefined /** The address that holds the uncirculated supply */ reserve?: string /** The address that can freeze the asset in any account. Freezing will be permanently disabled if undefined or an empty string. */ @@ -201,7 +209,10 @@ export type AssetFreezeParams = CommonTransactionParams & { frozen: boolean } -/** Parameters to define an asset destroy transaction. */ +/** Parameters to define an asset destroy transaction. + * + * Created assets can be destroyed only by the asset manager account. All of the assets must be owned by the creator of the asset before the asset can be deleted. + */ export type AssetDestroyParams = CommonTransactionParams & { /** ID of the asset */ assetId: bigint @@ -215,9 +226,17 @@ export type AssetTransferParams = CommonTransactionParams & { amount: bigint /** The account to send the asset to */ receiver: string - /** The account to take the asset from */ + /** The account to take the asset from. + * + * Requires the sender to be the clawback account. + * + * *Warning:* Be careful with this parameter as it can lead to unexpected loss of funds if not used correctly. + */ clawbackTarget?: string - /** The account to close the asset to */ + /** The account to close the asset to + * + * *Warning:* Be careful with this parameter as it can lead to loss of funds if not used correctly. + */ closeAssetTo?: string } From e248c652fe7da458de41fcaf59f050352dcee578 Mon Sep 17 00:00:00 2001 From: "Rob Moore (MakerX)" Date: Tue, 18 Jun 2024 10:14:01 +0800 Subject: [PATCH 04/18] feat: Moved from rekey being a transaction type to being a method on `AccountManager` Added: * `algorand.account.rekeyAccount()` Removed: * `algorand.send.rekey()` --- src/transaction/transaction.spec.ts | 5 +- src/transfer/transfer.ts | 8 ++- src/types/account-manager.ts | 63 +++++++++++++++++++ src/types/algorand-client.transfer.spec.ts | 4 +- src/types/algorand-client.ts | 71 +--------------------- src/types/composer.ts | 27 -------- 6 files changed, 72 insertions(+), 106 deletions(-) diff --git a/src/transaction/transaction.spec.ts b/src/transaction/transaction.spec.ts index aeb09d8f..fcb39a7c 100644 --- a/src/transaction/transaction.spec.ts +++ b/src/transaction/transaction.spec.ts @@ -790,10 +790,7 @@ describe('Resource Packer: meta', () => { const authAddr = algorand.account.random().account - await algorand.send.rekey({ - sender: testAccount.addr, - rekeyTo: authAddr.addr, - }) + await algorand.account.rekeyAccount(testAccount.addr, authAddr.addr) await externalClient.fundAppAccount(algokit.microAlgos(200_000)) diff --git a/src/transfer/transfer.ts b/src/transfer/transfer.ts index b0af5caa..a2c524df 100644 --- a/src/transfer/transfer.ts +++ b/src/transfer/transfer.ts @@ -105,7 +105,7 @@ export async function transferAsset(transfer: TransferAssetParams, algod: Algodv } /** - * @deprecated Use `algorand.send.rekey()` / `algorand.transaction.rekey()` instead + * @deprecated Use `algorand.account.rekeyAccount()` instead * * Rekey an account to a new address. * @@ -127,11 +127,13 @@ export async function rekeyAccount(rekey: AlgoRekeyParams, algod: Algodv2): Prom rekey, { sender: getSenderAddress(rekey.from), + receiver: getSenderAddress(rekey.from), + amount: (0).microAlgos(), rekeyTo: typeof rekey.rekeyTo === 'string' ? rekey.rekeyTo : getSenderAddress(rekey.rekeyTo), note: encodeTransactionNote(rekey.note), lease: rekey.lease, }, - (c) => c.transactions.rekey, - (c) => c.send.rekey, + (c) => c.transactions.payment, + (c) => c.send.payment, ) } diff --git a/src/types/account-manager.ts b/src/types/account-manager.ts index f1c1e900..37a3fa84 100644 --- a/src/types/account-manager.ts +++ b/src/types/account-manager.ts @@ -600,6 +600,69 @@ export class AccountManager { return results } + /** + * Rekey an account to a new address. + * + * **Note:** Please be careful with this function and be sure to read the [official rekey guidance](https://developer.algorand.org/docs/get-details/accounts/rekey/). + * + * @param account The account to rekey + * @param rekeyTo The new address to rekey the account to, or a signing account that should now + * be tracked as the signer for `account` in this `AccountManager` + * @param options Any parameters to control the transaction or execution of the transaction + * + * @example Basic example (with string addresses) + * ```typescript + * await algorand.account.rekeyAccount({account: "ACCOUNTADDRESS", rekeyTo: "NEWADDRESS"}) + * ``` + * @example Basic example (with signer accounts) + * ```typescript + * await algorand.account.rekeyAccount({account: account1, rekeyTo: newSignerAccount}) + * ``` + * @example Advanced example + * ```typescript + * await algorand.account.rekeyAccount({ + * account: "ACCOUNTADDRESS", + * rekeyTo: "NEWADDRESS", + * lease: 'lease', + * note: 'note', + * firstValidRound: 1000n, + * validityWindow: 10, + * extraFee: (1000).microAlgos(), + * staticFee: (1000).microAlgos(), + * // Max fee doesn't make sense with extraFee AND staticFee + * // already specified, but here for completeness + * maxFee: (3000).microAlgos(), + * maxRoundsToWaitForConfirmation: 5, + * suppressLog: true, + * }) + * ``` + * @returns The result of the transaction and the transaction that was sent + */ + async rekeyAccount( + account: string | TransactionSignerAccount, + rekeyTo: string | TransactionSignerAccount, + options?: Omit & ExecuteParams, + ): Promise { + const result = await this._getComposer() + .addPayment({ + ...options, + sender: typeof account === 'string' ? account : account.addr, + receiver: typeof account === 'string' ? account : account.addr, + amount: AlgoAmount.MicroAlgos(0), + rekeyTo: typeof rekeyTo === 'string' ? rekeyTo : rekeyTo.addr, + }) + .execute(options) + + // If the rekey is a signing account set it as the signer for this account + if (typeof rekeyTo !== 'string') { + this.rekeyed(typeof account === 'string' ? account : account.addr, rekeyTo) + } + + Config.getLogger(options?.suppressLog).info(`Rekeyed ${account} to ${rekeyTo} via transaction ${result.txIds.at(-1)}`) + + return { ...result, transaction: result.transactions.at(-1)!, confirmation: result.confirmations.at(-1)! } + } + private async _getEnsureFundedAmount(sender: string, minSpendingBalance: AlgoAmount, minFundingIncrement?: AlgoAmount) { const accountInfo = await this.getInformation(sender) const currentSpendingBalance = accountInfo.balance.microAlgos - accountInfo.minBalance.microAlgos diff --git a/src/types/algorand-client.transfer.spec.ts b/src/types/algorand-client.transfer.spec.ts index 34e88b58..06ccb674 100644 --- a/src/types/algorand-client.transfer.spec.ts +++ b/src/types/algorand-client.transfer.spec.ts @@ -361,9 +361,7 @@ describe('rekey', () => { const { testAccount, algorand } = localnet.context const secondAccount = algorand.account.random() - await algorand.send.rekey({ - sender: testAccount.addr, - rekeyTo: secondAccount.addr, + await algorand.account.rekeyAccount(testAccount.addr, secondAccount.addr, { note: 'Rekey', }) diff --git a/src/types/algorand-client.ts b/src/types/algorand-client.ts index 654db328..9eb75d15 100644 --- a/src/types/algorand-client.ts +++ b/src/types/algorand-client.ts @@ -209,7 +209,7 @@ export class AlgorandClient { * closeRemainderTo: 'CLOSEREMAINDERTOADDRESS', * lease: 'lease', * note: 'note', - * // Use this with caution, it's generally better to use algorand.send.rekey + * // Use this with caution, it's generally better to use algorand.account.rekeyAccount * rekeyTo: 'REKEYTOADDRESS', * firstValidRound: 1000n, * validityWindow: 10, @@ -233,44 +233,6 @@ export class AlgorandClient { preLog: (params, transaction) => `Sending ${params.amount.microAlgos} µALGOs from ${params.sender} to ${params.receiver} via transaction ${transaction.txID()}`, }), - /** - * Rekey an account to a new address. - * - * **Note:** Please be careful with this function and be sure to read the [official rekey guidance](https://developer.algorand.org/docs/get-details/accounts/rekey/). - * - * @param params The parameters for the rekey transaction - * - * @example Basic example - * ```typescript - * await algorand.send.rekey({sender: "ACCOUNTADDRESS", rekeyTo: "NEWADDRESS"}) - * ``` - * @example Advanced example - * ```typescript - * await algorand.send.rekey({ - * sender: "ACCOUNTADDRESS", - * rekeyTo: "NEWADDRESS", - * lease: 'lease', - * note: 'note', - * firstValidRound: 1000n, - * validityWindow: 10, - * extraFee: (1000).microAlgos(), - * staticFee: (1000).microAlgos(), - * // Max fee doesn't make sense with extraFee AND staticFee - * // already specified, but here for completeness - * maxFee: (3000).microAlgos(), - * // Signer only needed if you want to provide one, - * // generally you'd register it with AlgorandClient - * // against the sender nad not need to pass it in - * signer: transactionSigner, - * maxRoundsToWaitForConfirmation: 5, - * suppressLog: true, - * }) - * ``` - * @returns The result of the transaction and the transaction that was sent - */ - rekey: this._send((c) => c.addRekey, { - postLog: (params, result) => `Rekeyed ${params.sender} to ${params.rekeyTo} via transaction ${result.txIds.at(-1)}`, - }), /** * Create a new Algorand Standard Asset. * @@ -651,6 +613,7 @@ export class AlgorandClient { * closeRemainderTo: 'CLOSEREMAINDERTOADDRESS', * lease: 'lease', * note: 'note', + * // Use this with caution, it's generally better to use algorand.account.rekeyAccount * rekeyTo: 'REKEYTOADDRESS', * firstValidRound: 1000n, * validityWindow: 10, @@ -665,36 +628,6 @@ export class AlgorandClient { * @returns The payment transaction */ payment: this._transaction((c) => c.addPayment), - /** - * Create a rekey transaction to rekey an account to a new address. - * - * **Note:** Please be careful with this function and be sure to read the [official rekey guidance](https://developer.algorand.org/docs/get-details/accounts/rekey/). - * - * @param params The parameters for the rekey transaction - * - * @example Basic example - * ```typescript - * await algorand.transactions.rekey({sender: "ACCOUNTADDRESS", rekeyTo: "NEWADDRESS"}) - * ``` - * @example Advanced example - * ```typescript - * await algorand.transactions.rekey({ - * sender: "ACCOUNTADDRESS", - * rekeyTo: "NEWADDRESS", - * lease: 'lease', - * note: 'note', - * firstValidRound: 1000n, - * validityWindow: 10, - * extraFee: (1000).microAlgos(), - * staticFee: (1000).microAlgos(), - * // Max fee doesn't make sense with extraFee AND staticFee - * // already specified, but here for completeness - * maxFee: (3000).microAlgos(), - * }) - * ``` - * @returns The rekey transaction - */ - rekey: this._transaction((c) => c.addRekey), /** Create a create Algorand Standard Asset transaction. * * The account that sends this transaction will automatically be diff --git a/src/types/composer.ts b/src/types/composer.ts index edbcf7f9..a4053d52 100644 --- a/src/types/composer.ts +++ b/src/types/composer.ts @@ -57,15 +57,6 @@ export type PaymentParams = CommonTransactionParams & { closeRemainderTo?: string } -/** Parameters to define a rekey transaction. */ -export type RekeyParams = CommonTransactionParams & { - /** Change the signing key of the sender to the given address. - * - * **Warning:** Please be careful with this parameter and be sure to read the [official rekey guidance](https://developer.algorand.org/docs/get-details/accounts/rekey/). - */ - rekeyTo: string -} - /** Parameters to define an asset create transaction. * * The account that sends this transaction will automatically be opted in to the asset and will hold all units after creation. @@ -333,7 +324,6 @@ export type MethodCallParams = CommonTransactionParams & type Txn = | (PaymentParams & { type: 'pay' }) - | (RekeyParams & { type: 'rekey' }) | (AssetCreateParams & { type: 'assetCreate' }) | (AssetConfigParams & { type: 'assetConfig' }) | (AssetFreezeParams & { type: 'assetFreeze' }) @@ -415,8 +405,6 @@ export default class AlgokitComposer { /** * Add a payment transaction to the transaction group. - * - * **Warning:** Please be careful with this parameter and be sure to read the [official rekey guidance](https://developer.algorand.org/docs/get-details/accounts/rekey/). * @param params The payment transaction parameters * @returns The composer so you can chain method calls */ @@ -426,17 +414,6 @@ export default class AlgokitComposer { return this } - /** - * Add a rekey transaction to the transaction group. - * @param params The rekey transaction parameters - * @returns The composer so you can chain method calls - */ - addRekey(params: RekeyParams): AlgokitComposer { - this.txns.push({ ...params, type: 'rekey' }) - - return this - } - /** * Add an asset create transaction to the transaction group. * @param params The asset create transaction parameters @@ -850,10 +827,6 @@ export default class AlgokitComposer { const payment = this.buildPayment(txn, suggestedParams) return [{ txn: payment, signer }] } - case 'rekey': { - const rekey = this.buildPayment({ ...txn, receiver: txn.sender, amount: (0).microAlgos() }, suggestedParams) - return [{ txn: rekey, signer }] - } case 'assetCreate': { const assetCreate = this.buildAssetCreate(txn, suggestedParams) return [{ txn: assetCreate, signer }] From 3b9f9f72c4f9dd4572af6d9d01d2650870e9e077 Mon Sep 17 00:00:00 2001 From: "Rob Moore (MakerX)" Date: Wed, 19 Jun 2024 02:06:43 +0800 Subject: [PATCH 05/18] docs: Added up to date documentation for rekeyAccount, AlgorandClient, asset, dispenser client, indexer, testing, transfer --- docs/README.md | 38 +- docs/capabilities/account.md | 64 ++- docs/capabilities/algorand-client.md | 97 +++++ docs/capabilities/amount.md | 4 +- docs/capabilities/app-client.md | 2 + docs/capabilities/asset.md | 366 +++++++++++++----- docs/capabilities/dispenser-client.md | 26 +- docs/capabilities/indexer.md | 33 +- docs/capabilities/testing.md | 17 +- docs/capabilities/transfer.md | 177 ++++++--- docs/capabilities/typed-app-clients.md | 100 +++++ docs/code/README.md | 3 + .../classes/types_account.MultisigAccount.md | 20 +- .../classes/types_account.SigningAccount.md | 16 +- .../types_account_manager.AccountManager.md | 161 +++++--- .../types_algorand_client.AlgorandClient.md | 88 +++-- .../types_client_manager.ClientManager.md | 54 ++- docs/code/classes/types_composer.default.md | 99 ++--- ...penser_client.TestNetDispenserApiClient.md | 18 +- .../interfaces/types_account.AccountConfig.md | 8 +- .../types_account.TransactionSignerAccount.md | 4 +- ...account_manager.BulkAssetOptInOutResult.md | 4 +- ...ypes_account_manager.EnsureFundedResult.md | 4 +- .../types_asset.AssetBulkOptInOutParams.md | 2 + .../types_asset.AssetOptInParams.md | 2 + .../types_asset.AssetOptOutParams.md | 2 + .../types_asset.CreateAssetParams.md | 2 + .../types_client_manager.TypedAppClient.md | 2 +- .../types_composer.ExecuteParams.md | 6 +- ..._dispenser_client.DispenserFundResponse.md | 10 +- ...dispenser_client.DispenserLimitResponse.md | 6 +- ..._client.TestNetDispenserApiClientParams.md | 10 +- .../types_testing.AlgorandFixtureConfig.md | 2 +- .../types_transfer.AlgoRekeyParams.md | 2 + .../types_transfer.AlgoTransferParams.md | 6 +- .../types_transfer.EnsureFundedParams.md | 4 +- .../types_transfer.EnsureFundedReturnType.md | 6 +- .../types_transfer.TransferAssetParams.md | 2 + docs/code/modules/index.md | 353 +++++++---------- docs/code/modules/types_account.md | 37 +- docs/code/modules/types_account_manager.md | 2 +- docs/code/modules/types_algorand_client.md | 2 +- docs/code/modules/types_client_manager.md | 8 +- docs/code/modules/types_composer.md | 67 ++-- src/account/account.ts | 2 +- src/account/get-account.ts | 6 +- src/amount.ts | 2 +- src/indexer-lookup.spec.ts | 70 ++-- src/testing/fixtures/algorand-fixture.ts | 7 +- src/transaction/transaction.spec.ts | 4 +- src/transaction/transaction.ts | 6 +- src/transfer/transfer-algos.ts | 2 +- src/transfer/transfer.ts | 2 +- src/types/account-manager.ts | 30 +- src/types/algorand-client.transfer.spec.ts | 2 +- src/types/algorand-client.ts | 44 ++- src/types/amount.spec.ts | 4 +- src/types/amount.ts | 2 +- src/types/client-manager.ts | 22 ++ src/types/composer.ts | 163 +++++--- src/types/dispenser-client.spec.ts | 2 +- src/types/dispenser-client.ts | 8 + src/types/kmd-account-manager.ts | 2 +- src/types/testing.ts | 2 +- src/types/transfer.ts | 6 +- 65 files changed, 1492 insertions(+), 832 deletions(-) create mode 100644 docs/capabilities/typed-app-clients.md diff --git a/docs/README.md b/docs/README.md index 530f4bcc..92fe3ccf 100644 --- a/docs/README.md +++ b/docs/README.md @@ -39,7 +39,7 @@ import { AlgorandClient, Config } from '@algorandfoundation/algokit-utils' As well as `AlgorandClient` and `Config`, you can use intellisense to auto-complete the various types that you can import withing the {} in your favourite Integrated Development Environment (IDE), or you can refer to the [reference documentation](./code/modules/index.md). > [!WARNING] -> Previous versions of AlgoKit Utils encouraged you to include an import that looks like this (note the subtle difference of the extra `* as`): +> Previous versions of AlgoKit Utils encouraged you to include an import that looks like this (note the subtle difference of the extra `* as algokit`): > > ```typescript > import * as algokit from '@algorandfoundation/algokit-utils' @@ -47,7 +47,7 @@ As well as `AlgorandClient` and `Config`, you can use intellisense to auto-compl > > This version will still work, but it exposes an older, function-based interface to the functionality that is in the process of being deprecated. The recommended way to use AlgoKit Utils is via the `AlgorandClient` class mentioned below, which is easier and more convenient to use. Some functionality won't yet be migrated to the new approach and this old approach will be needed, but the documentation pages will indicate when this is the case. -The main entrypoint to the bulk of the functionality is the `AlgorandClient` class, most of the time you can get started by typing `algokit.AlgorandClient.` and choosing one of the static initialisation methods to create an [Algorand client](./capabilities/algorand-client.md), e.g.: +The main entrypoint to the bulk of the functionality is the `AlgorandClient` class, most of the time you can get started by typing `AlgorandClient.` and choosing one of the static initialisation methods to create an [Algorand client](./capabilities/algorand-client.md), e.g.: ```typescript // Point to the network configured through environment variables or @@ -155,29 +155,21 @@ algokit.Config.withDebug(() => { The library helps you interact with and develop against the Algorand blockchain with a series of end-to-end capabilities as described below: - [**AlgorandClient**](./capabilities/algorand-client.md) - The key entrypoint to the AlgoKit Utils functionality -- Core capabilities - - [**Client management**](./capabilities/client.md) - Creation of (auto-retry) algod, indexer and kmd clients against various networks resolved from environment or specified configuration - - [**Account management**](./capabilities/account.md) - Creation and use of accounts including mnemonic, rekeyed, multisig, transaction signer ([useWallet](https://github.com/TxnLab/use-wallet) for dApps and Atomic Transaction Composer compatible signers), idempotent KMD accounts and environment variable injected - - [**Algo amount handling**](./capabilities/amount.md) - Reliable and terse specification of microAlgo and Algo amounts and conversion between them - - [**Transaction management**](./capabilities/transaction.md) - Ability to send single, grouped or Atomic Transaction Composer transactions with consistent and highly configurable semantics, including configurable control of transaction notes (including ARC-0002), logging, fees, multiple sender account types, and sending behaviour -- Higher-order use cases - - [**App management**](./capabilities/app.md) - Creation, updating, deleting, calling (ABI and otherwise) smart contract apps and the metadata associated with them (including state and boxes) - - [**App deployment**](./capabilities/app-deploy.md) - Idempotent (safely retryable) deployment of an app, including deploy-time immutability and permanence control and TEAL template substitution - - [**ARC-0032 Application Spec client**](./capabilities/app-client.md) - Builds on top of the App management and App deployment capabilities to provide a high productivity application client that works with ARC-0032 application spec defined smart contracts (e.g. via Beaker) - - [**Algo transfers**](./capabilities/transfer.md) - Ability to easily initiate algo transfers between accounts, including dispenser management and idempotent account funding +- **Core capabilities** + - [**Client management**](./capabilities/client.md) - Creation of (auto-retry) algod, indexer and kmd clients against various networks resolved from environment or specified configuration, and creation of other API clients (e.g. TestNet Dispenser API and app clients) + - [**Account management**](./capabilities/account.md) - Creation, use, and management of accounts including mnemonic, rekeyed, multisig, transaction signer ([useWallet](https://github.com/TxnLab/use-wallet) for dApps and Atomic Transaction Composer compatible signers), idempotent KMD accounts and environment variable injected + - [**Algo amount handling**](./capabilities/amount.md) - Reliable, explicit, and terse specification of microAlgo and Algo amounts and safe conversion between them + - [**Transaction management**](./capabilities/transaction.md) - Ability to construct and send single and atomically grouped transactions with consistent and highly configurable semantics, including configurable control of transaction notes, logging, fees, validity, signing, and sending behaviour +- **Higher-order use cases** + - [**Asset management**](./capabilities/asset.md) - Creation, transfer, destroying, opting in and out and managing Algorand Standard Assets + - [**Typed application clients**](./capabilities/typed-app-clients.md) - Type-safe application clients that are [generated](https://github.com/algorandfoundation/algokit-cli/blob/main/docs/features/generate.md#1-typed-clients) from ARC-0032 application spec files and allow you to intuitively and productively interact with a deployed app, which is the recommended way of interacting with apps and builds on top of the following capabilities: + - [**ARC-0032 Application Spec client**](./capabilities/app-client.md) - Builds on top of the App management and App deployment capabilities (below) to provide a high productivity application client that works with ARC-0032 application spec defined smart contracts + - [**App management**](./capabilities/app.md) - Creation, updating, deleting, calling (ABI and otherwise) smart contract apps and the metadata associated with them (including state and boxes) + - [**App deployment**](./capabilities/app-deploy.md) - Idempotent (safely retryable) deployment of an app, including deploy-time immutability and permanence control and TEAL template substitution + - [**Algo transfers (payments)**](./capabilities/transfer.md) - Ability to easily initiate algo transfers between accounts, including dispenser management and idempotent account funding - [**Automated testing**](./capabilities/testing.md) - Terse, robust automated testing primitives that work across any testing framework (including jest and vitest) to facilitate fixture management, quickly generating isolated and funded test accounts, transaction logging, indexer wait management and log capture - - [**Indexer lookups / searching**](./capabilities/indexer.md) - Type-safe indexer API wrappers (no more `Record` pain), including automatic pagination control + - [**Indexer lookups / searching**](./capabilities/indexer.md) - Type-safe indexer API wrappers (no `Record` pain from the SDK client), including automatic pagination control # Reference documentation We have [auto-generated reference documentation for the code](./code/README.md). - -# Roadmap - -This library will naturally evolve with any logical developer experience improvements needed to facilitate the [AlgoKit](https://github.com/algorandfoundation/algokit-cli) roadmap as it evolves. - -Likely future capability additions include: - -- Typed application client (similar to [beaker-ts](https://github.com/algorand-devrel/beaker-ts)) -- Asset management -- Expanded indexer API wrapper support diff --git a/docs/capabilities/account.md b/docs/capabilities/account.md index 5d24e4bb..f74f5c13 100644 --- a/docs/capabilities/account.md +++ b/docs/capabilities/account.md @@ -47,7 +47,7 @@ In order to get/register accounts for signing operations you can use the followi - [`algorand.account.fromEnvironment(name, fundWith)`](../code/classes/types_account_manager.AccountManager.md#fromenvironment) - Registers and returns an account with private key loaded by convention based on the given name identifier - either by idempotently creating the account in KMD or from environment variable via `process.env['{NAME}_MNEMONIC']` and (optionally) `process.env['{NAME}_SENDER']` (if account is rekeyed) - This allows you to have powerful code that will automatically create and fund an account by name locally and when deployed against TestNet/MainNet will automatically resolve from environment variables, without having to have different code - - Note: `fundWith` allows you to control how many ALGOs are seeded into an account created in KMD + - Note: `fundWith` allows you to control how many Algos are seeded into an account created in KMD - [`algorand.account.fromMnemonic(mnemonicSecret, sender?)`](../code/classes/types_account_manager.AccountManager.md#frommnemonic) - Registers and returns an account with secret key loaded by taking the mnemonic secret - [`algorand.account.multisig(multisigParams, signingAccounts)`](../code/classes/types_account_manager.AccountManager.md#multisig) - Registers and returns a multisig account with one or more signing keys loaded - [`algorand.account.rekeyed(sender, signer)`](../code/classes/types_account_manager.AccountManager.md#rekeyed) - Registers and returns an account representing the given rekeyed sender/signer combination @@ -62,31 +62,53 @@ In order to get/register accounts for signing operations you can use the followi ## Rekey account -> [!NOTE] -> This method requires the [legacy AlgoKit Utils import method to access them](../README.md#usage). - One of the unique features of Algorand is the ability to change the private key that can authorise transactions for an account. This is called [rekeying](https://developer.algorand.org/docs/get-details/accounts/rekey/). -You can issue a transaction to rekey an account by using the `algokit.rekeyAccount(rekey, algod)` function. The `rekey` parameter is an [`AlgoRekeyParams`](../code/interfaces/types_transfer.AlgoRekeyParams.md) object with the following properties: +> [!WARNING] +> Rekeying should be done with caution as a rekey transaction can result in permanent loss of control of an account. + +You can issue a transaction to rekey an account by using the [`algorand.account.rekeyAccount(account, rekeyTo, options)`](../code/classes/types_account_manager.AccountManager.md#rekeyaccount) function: -- All properties in [`SendTransactionParams`](./transaction.md#sendtransactionparams) -- `from: SendTransactionFrom` - The account that will be rekeyed -- `rekeyTo: SendTransactionFrom | string` - The address of the account that will be used to authorise transactions for the rekeyed account going forward -- `transactionParams?: SuggestedParams` - The optional [transaction parameters](./transaction.md#transaction-params) -- `note?: TransactionNote` - The [transaction note](./transaction.md#transaction-notes) -- `lease?: string | Uint8Array`: A [lease](https://developer.algorand.org/articles/leased-transactions-securing-advanced-smart-contract-design/) to assign to the transaction to enforce a mutually exclusive transaction (useful to prevent double-posting and other scenarios) +- `account: string | TransactionSignerAccount` - The account address or signing account of the account that will be rekeyed +- `rekeyTo: string | TransactionSignerAccount` - The account address or signing account of the account that will be used to authorise transactions for the rekeyed account going forward. If a signing account is provided that will now be tracked as the signer for `account` in the `AccountManager` instance. +- An `options` object, which has: + - [Common transaction parameters](./algorand-client.md#transaction-parameters) + - [Execution parameters](./algorand-client.md#sending-a-single-transaction) + +You can also pass in `rekeyTo` as a [common transaction parameter](./algorand-client.md#transaction-parameters) to any transaction. + +### Examples ```typescript -// Example -await algokit.rekeyAccount( - { - from: account, - rekeyTo: newAccount, - // Optionally specify transactionParams, note, lease and transaction sending parameters - }, - algod, -) +// Basic example (with string addresses) + +await algorand.account.rekeyAccount({ account: 'ACCOUNTADDRESS', rekeyTo: 'NEWADDRESS' }) + +// Basic example (with signer accounts) + +await algorand.account.rekeyAccount({ account: account1, rekeyTo: newSignerAccount }) + +// Advanced example + +await algorand.account.rekeyAccount({ + account: 'ACCOUNTADDRESS', + rekeyTo: 'NEWADDRESS', + lease: 'lease', + note: 'note', + firstValidRound: 1000n, + validityWindow: 10, + extraFee: (1000).microAlgos(), + staticFee: (1000).microAlgos(), + // Max fee doesn't make sense with extraFee AND staticFee + // already specified, but here for completeness + maxFee: (3000).microAlgos(), + maxRoundsToWaitForConfirmation: 5, + suppressLog: true, +}) + +// Using a rekeyed account +// Note: if a signing account is passed into `algorand.account.rekeyAccount` then you don't need to call `rekeyedAccount` to register the new signer const rekeyedAccount = algokit.rekeyedAccount(newAccount, account.addr) // rekeyedAccount can be used to sign transactions on behalf of account... ``` @@ -95,7 +117,7 @@ const rekeyedAccount = algokit.rekeyedAccount(newAccount, account.addr) When running LocalNet, you have an instance of the [Key Management Daemon](https://github.com/algorand/go-algorand/blob/master/daemon/kmd/README.md), which is useful for: -- Accessing the private key of the default accounts that are pre-seeded with algos so that other accounts can be funded and it's possible to use LocalNet +- Accessing the private key of the default accounts that are pre-seeded with Algos so that other accounts can be funded and it's possible to use LocalNet - Idempotently creating new accounts against a name that will stay intact while the LocalNet instance is running without you needing to store private keys anywhere (i.e. completely automated) The KMD SDK is fairly low level so to make use of it there is a fair bit of boilerplate code that's needed. This code has been abstracted away into the `KmdAccountManager` class. diff --git a/docs/capabilities/algorand-client.md b/docs/capabilities/algorand-client.md index 624d74fe..279edd8c 100644 --- a/docs/capabilities/algorand-client.md +++ b/docs/capabilities/algorand-client.md @@ -36,3 +36,100 @@ const algodClient = algorand.client.algod const indexerClient = algorand.client.indexer const kmdClient = algorand.client.kmd ``` + +## Accessing manager class instances + +The `AlgorandClient` has a number of manager class instances that help you quickly use intellisense to get access to advanced functionality. + +- [`AccountManager`](./account.md) via `algorand.account`, there are also some convenience methods that wrap some methods within `AccountManager` that return `AlgorandClient` and thus allow for method chaining: + - `algorand.setDefaultSigner(signer)` - + - `algorand.setSignerFromAccount(account)` - + - `algorand.setSigner(sender, signer)` +- [`AssetManager`](./asset.md) via `algorand.asset` +- [`ClientManager`](./client.md) via `algorand.client` + +## Creating and issuing transactions + +`AlgorandClient` exposes a series of methods that allow you to create, execute, and compose groups of transactions: + +### Creating single transactions + +You can compose a single transaction via `algorand.transaction...`. Intellisense will guide you on the different options. + +The signature for the calls to send a single transaction usually look like: + +`algorand.transaction.{method}(params: {ComposerTransactionTypeParams} & CommonTransactionParams): Transaction` + +- To get intellisense on the params, open an object parenthesis (`{`) and use your IDE's intellisense keyboard shortcut (e.g. ctrl+space). +- `{ComposerTransactionTypeParams}` will be the parameters that are specific to that transaction type e.g. `PaymentParams`, [see the full list](../code/modules/types_composer.md#type-aliases) +- [`CommonTransactionParams`](../code/modules/types_composer.md#commontransactionparams) are the [common transaction parameters](#transaction-parameters) that can be specified for every single transaction +- `Transaction` is an `algosdk.Transaction` object + +### Sending a single transaction + +You can compose a single transaction via `algorand.send...`. Intellisense will guide you on the different options. + +Further documentation is present in the related capabilities: + +- [App management](./app.md) +- [Asset management](./asset.md) +- [Algo transfers](./transfer.md) + +The signature for the calls to send a single transaction usually look like: + +`algorand.send.{method}(params: {ComposerTransactionTypeParams} & CommonTransactionParams & ExecuteParams): SingleSendTransactionResult` + +- To get intellisense on the params, open an object parenthesis (`{`) and use your IDE's intellisense keyboard shortcut (e.g. ctrl+space). +- `{ComposerTransactionTypeParams}` will be the parameters that are specific to that transaction type e.g. `PaymentParams`, [see the full list](../code/modules/types_composer.md#type-aliases) +- [`CommonTransactionParams`](../code/modules/types_composer.md#commontransactionparams) are the [common transaction parameters](#transaction-parameters) that can be specified for every single transaction +- [`ExecuteParams`](../code/interfaces/types_composer.ExecuteParams.md) are the [parameters](#transaction-parameters) that control execution semantics when sending transactions to the network +- [`SendSingleTransactionResult`](../code/modules/types_algorand_client.md#sendsingletransactionresult) is all of the information that is relevant when [sending a single transaction to the network](./transaction.md#sending-a-transaction) + +Generally, the functions to immediately send a single transaction will emit log messages before and/or after sending the transaction. You can opt-out of this by sending `suppressLog: true`. + +### Composing a group of transactions + +You can compose a group of transactions for execution by using the `newGroup()` method on `AlgorandClient` and then use the various `.add{Type}()` methods to add a series of transactions. + +```typescript +const result = algorand + .newGroup() + .addPayment({ sender: 'SENDERADDRESS', receiver: 'RECEIVERADDRESS', amount: (1).microAlgos() }) + .addAssetOptIn({ sender: 'SENDERADDRESS', assetId: 12345n }) + .execute() +``` + +`newGroup()` returns a new [`AlgoKitComposer`](./algokit-composer.md) instance, which can also return the group of transactions, simulate them and other things. + +### Transaction parameters + +To create a transaction you define a set of parameters as a plain TypeScript object. + +There are two common base interfaces that get reused: + +- [`CommonTransactionParams`](../code/modules/types_composer.md#commontransactionparams) + - `sender: string` - The address of the account sending the transaction. + - `signer?: algosdk.TransactionSigner | TransactionSignerAccount` - The function used to sign transaction(s); if not specified then an attempt will be made to find a registered signer for the given `sender` or use a default signer (if configured). + - `rekeyTo?: string` - Change the signing key of the sender to the given address. **Warning:** Please be careful with this parameter and be sure to read the [official rekey guidance](https://developer.algorand.org/docs/get-details/accounts/rekey/). + - `note?: Uint8Array | string` - Note to attach to the transaction. Max of 1000 bytes. + - `lease?: Uint8Array | string` - Prevent multiple transactions with the same lease being included within the validity window. A [lease](https://developer.algorand.org/articles/leased-transactions-securing-advanced-smart-contract-design/) enforces a mutually exclusive transaction (useful to prevent double-posting and other scenarios). + - Fee management + - `staticFee?: AlgoAmount` - The static transaction fee. In most cases you want to use `extraFee` unless setting the fee to 0 to be covered by another transaction. + - `extraFee?: AlgoAmount` - The fee to pay IN ADDITION to the suggested fee. Useful for covering inner transaction fees. + - `maxFee?: AlgoAmount` - Throw an error if the fee for the transaction is more than this amount; prevents overspending on fees during high congestion periods. + - Round validity management + - `validityWindow?: number` - How many rounds the transaction should be valid for, if not specified then the registered default validity window will be used. + - `firstValidRound?: bigint` - Set the first round this transaction is valid. If left undefined, the value from algod will be used. We recommend you only set this when you intentionally want this to be some time in the future. + - `lastValidRound?: bigint` - The last round this transaction is valid. It is recommended to use `validityWindow` instead. +- [`ExecuteParams`](../code/interfaces/types_composer.ExecuteParams.md) + - `maxRoundsToWaitForConfirmation?: number` - The number of rounds to wait for confirmation. By default until the latest lastValid has past. + - `suppressLog?: boolean` - Whether to suppress log messages from transaction send, default: do not suppress. + +### Transaction configuration + +AlgorandClient caches network provided transaction values for you automatically to reduce network traffic. It has a set of default configurations that control this behaviour, but you have the ability to override and change the configuration of this behaviour: + +- `algorand.setDefaultValidityWindow(validityWindow)` - Set the default validity window (number of rounds from the current known round that the transaction will be valid to be accepted for), having a smallish value for this is usually ideal to avoid transactions that are valid for a long future period and may be submitted even after you think it failed to submit if waiting for a particular number of rounds for the transaction to be successfully submitted. The validity window defaults to 10, except in [automated testing](./testing.md) where it's set to 1000 when targeting LocalNet. +- `algorand.setSuggestedParams(suggestedParams, until?)` - Set the suggested network parameters to use (optionally until the given time) +- `algorand.setSuggestedParamsTimeout(timeout)` - Set the timeout that is used to cache the suggested network parameters (by default 3 seconds) +- `algorand.getSuggestedParams()` - Get the current suggested network parameters object, either the cached value, or if the cache has expired a fresh value diff --git a/docs/capabilities/amount.md b/docs/capabilities/amount.md index 63818760..4bde93e1 100644 --- a/docs/capabilities/amount.md +++ b/docs/capabilities/amount.md @@ -2,7 +2,7 @@ Algo amount handling is one of the core capabilities provided by AlgoKit Utils. It allows you to reliably and tersely specify amounts of microAlgos and Algos and safely convert between them. -Any AlgoKit Utils function that needs an Algo amount will take an `AlgoAmount` object, which ensures that there is never any confusion about what value is being passed around. Whenever an AlgoKit Utils function calls into an underlying algosdk function, or if you need to take an `AlgoAmount` and pass it into an underlying algosdk function (per the [modularity principle](../README.md#core-principles)) you can safely and explicitly convert to microAlgos or algos. +Any AlgoKit Utils function that needs an Algo amount will take an `AlgoAmount` object, which ensures that there is never any confusion about what value is being passed around. Whenever an AlgoKit Utils function calls into an underlying algosdk function, or if you need to take an `AlgoAmount` and pass it into an underlying algosdk function (per the [modularity principle](../README.md#core-principles)) you can safely and explicitly convert to microAlgos or Algos. To see some usage examples check out the [automated tests](../../src/types/amount.spec.ts). Alternatively, you see the [reference documentation](../code/classes/types_amount.AlgoAmount.md) for `AlgoAmount`. @@ -41,7 +41,7 @@ import { AlgoAmount } from '@algorandfoundation/algokit-utils/types/amount' ### Extracting a value from `AlgoAmount` -The `AlgoAmount` class has methods to return algos and microAlgos: +The `AlgoAmount` class has methods to return Algos and microAlgos: - `amount.algos()` - Returns the value in Algos - `amount.microAlgos()` - Returns the value in microAlgos diff --git a/docs/capabilities/app-client.md b/docs/capabilities/app-client.md index 3c4f99f7..543b8fff 100644 --- a/docs/capabilities/app-client.md +++ b/docs/capabilities/app-client.md @@ -27,6 +27,7 @@ const client = algorand.client.getAppClientByCreatorAndName({ app: appSpec, creatorAddress, }) + // With optional params const client = algorand.client.getAppClientByCreatorAndName({ app: appSpec, @@ -41,6 +42,7 @@ const client = algorand.client.getAppClientById({ id: 12345, app: appSpec, }) + // With optional params const client = algorand.client.getAppClientById({ id: 12345, diff --git a/docs/capabilities/asset.md b/docs/capabilities/asset.md index f528e238..145aede0 100644 --- a/docs/capabilities/asset.md +++ b/docs/capabilities/asset.md @@ -1,150 +1,310 @@ # Assets The Algorand Standard Asset (asset) management functions include creating, opting in and transferring assets, which are fundamental to asset interaction in a blockchain environment. -To see some usage examples check out the [automated tests](../../src/asset.spec.ts). + +To see some usage examples check out the [automated tests](../../src/types/algorand-client.asset.spec.ts). + +## `AssetManager` + +The [`AssetManager`](../code/classes/types_asset_manager.AssetManager.md) is a class that is used to manage asset information. + +To get an instance of `AssetManager`, you can use either [`AlgorandClient`](./algorand-client.md) via `algorand.asset` or instantiate it directly (passing in a [`ClientManager`](./client.md)): + +```typescript +import { AssetManager } from '@algorandfoundation/algokit-utils/types/asset-manager' + +const assetManager = new AssetManager(clientManager) +``` ## Creation -> [!NOTE] -> This method requires the [legacy AlgoKit Utils import method to access it](../README.md#usage). - -To create an asset you can use the `createAsset(create, algod)` function, which returns a [`SendTransactionResult`](./transaction.md#sendtransactionresult) and takes an [`AssetCreateParams`](../code/interfaces/types_asset.CreateAssetParams.md): - -- All properties in [`SendTransactionParams`](./transaction.md#sendtransactionparams) -- `creator: SendTransactionFrom` - The account to create the asset. This account automatically is opted in to the asset and holds all units after creation. -- `total: number | bigint` - The total number of base (decimal) units of the asset to create. If decimal is, say, 2, then for every 100 `total` there would be 1 whole unit. -- `decimals: number` - The number of digits to use after the decimal point when displaying the asset. If 0, the asset is not divisible. If 1, the base unit of the asset is in tenths, and so on up to 19 decimal places. -- `name?: string` - The optional name of the asset. Max size if 32 bytes. -- `unit?: string` - The optional name of the unit of this asset. Max size is 8 bytes. -- `url?: string` - Specifies an optional URL where more information about the asset can be retrieved. Max size is 96 bytes. -- `metadataHash?: string | Uint8Array` - This field is intended to be a 32-byte hash of some metadata that is relevant to your asset and/or asset holders. -- `manager?: string | SendTransactionFrom` - The optional account that can manage the configuration of the asset and destroy it. -- `reserveAccount?: string | SendTransactionFrom` - The optional account that holds the reserve (non-minted) units of the asset. This address has no specific authority in the protocol itself and is informational. -- `freezeAccount?: string | SendTransactionFrom` - The optional account that can be used to freeze holdings of this asset. If empty, freezing is not permitted. -- `clawbackAccount?: string | SendTransactionFrom` - The optional account that can clawback holdings of this asset. If empty, clawback is not permitted. -- `frozenByDefault?: boolean` - Whether to freeze holdings for this asset by default. If `true` then for anyone apart from the creator to hold the asset it needs to be unfrozen per account using `freeze`. Defaults to `false`. -- `transactionParams?: SuggestedParams` - The optional [transaction parameters](./transaction.md#transaction-params) -- `note?: TransactionNote` - The [transaction note](./transaction.md#transaction-notes) -- `lease?: string | Uint8Array`: A [lease](https://developer.algorand.org/articles/leased-transactions-securing-advanced-smart-contract-design/) to assign to the transaction to enforce a mutually exclusive transaction (useful to prevent double-posting and other scenarios) +To create an asset you can use `algorand.send.assetCreate(params)` (immediately send a single asset creation transaction), `algorand.transaction.assetCreate(params)` (construct an asset creation transaction), or `algorand.newGroup().addAssetCreate(params)` (add asset creation to a group of transactions) per [`AlgorandClient`](./algorand-client.md) [transaction semantics](./algorand-client.md#creating-and-issuing-transactions). + +The base type for specifying an asset creation transaction is [`AssetCreateParams`](../code/modules/types_composer.md#assetcreateparams), which has the following parameters in addition to the [common transaction parameters](./algorand-client.md#transaction-parameters): + +- `total: bigint` - The total amount of the smallest divisible (decimal) unit to create. For example, if `decimals` is, say, 2, then for every 100 `total` there would be 1 whole unit. This field can only be specified upon asset creation. +- `decimals: number` - The amount of decimal places the asset should have. If unspecified then the asset will be in whole units (i.e. `0`). If 0, the asset is not divisible. If 1, the base unit of the asset is in tenths, and so on up to 19 decimal places. This field can only be specified upon asset creation. +- `assetName?: string` - The optional name of the asset. Max size is 32 bytes. This field can only be specified upon asset creation. +- `unitName?: string` - The optional name of the unit of this asset (e.g. ticker name). Max size is 8 bytes. This field can only be specified upon asset creation. +- `url?: string` - Specifies an optional URL where more information about the asset can be retrieved. Max size is 96 bytes. This field can only be specified upon asset creation. +- `metadataHash?: string | Uint8Array` - 32-byte hash of some metadata that is relevant to your asset and/or asset holders. The format of this metadata is up to the application. This field can only be specified upon asset creation. +- `defaultFrozen?: boolean` - Whether to freeze holdings for this asset by default. Defaults to `false`. If `true` then for anyone apart from the creator to hold the asset it needs to be unfrozen using an asset freeze transaction from the `freeze` account, which must be set on creation. This field can only be specified upon asset creation. +- `manager?: string` - The address of the optional account that can manage the configuration of the asset and destroy it. The configuration fields it can change are `manager`, `reserve`, `clawback`, and `freeze`. If not set (`undefined` or `""`) at asset creation or subsequently set to empty by the `manager` the asset becomes permanently immutable. +- `reserveAccount?: string` - The address of the optional account that holds the reserve (uncirculated supply) units of the asset. This address has no specific authority in the protocol itself and is informational only. Some standards like [ARC-19](https://github.com/algorandfoundation/ARCs/blob/main/ARCs/arc-0019.md) rely on this field to hold meaningful data. It can be used in the case where you want to signal to holders of your asset that the uncirculated units of the asset reside in an account that is different from the default creator account. If not set (`undefined` or `""`) at asset creation or subsequently set to empty by the manager the field is permanently empty. +- `freezeAccount?: string` - The address of the optional account that can be used to freeze or unfreeze holdings of this asset for any account. If empty, freezing is not permitted. If not set (`undefined` or `""`) at asset creation or subsequently set to empty by the manager the field is permanently empty. +- `clawbackAccount?: string` - The address of the optional account that can clawback holdings of this asset from any account. **This field should be used with caution** as the clawback account has the ability to **unconditionally take assets from any account**. If empty, clawback is not permitted. If not set (`undefined` or `""`) at asset creation or subsequently set to empty by the manager the field is permanently empty. + +### Examples + +```typescript +// Basic example +const result = await algorand.send.assetCreate({ sender: 'CREATORADDRESS', total: 100n }) +const createdAssetId = result.assetId + +// Advanced example +await algorand.send.assetCreate({ + sender: 'CREATORADDRESS', + total: 100n, + decimals: 2, + assetName: 'asset', + unitName: 'unit', + url: 'url', + metadataHash: 'metadataHash', + defaultFrozen: false, + manager: 'MANAGERADDRESS', + reserve: 'RESERVEADDRESS', + freeze: 'FREEZEADDRESS', + clawback: 'CLAWBACKADDRESS', + lease: 'lease', + note: 'note', + // You wouldn't normally set this field + firstValidRound: 1000n, + validityWindow: 10, + extraFee: (1000).microAlgos(), + staticFee: (1000).microAlgos(), + // Max fee doesn't make sense with extraFee AND staticFee + // already specified, but here for completeness + maxFee: (3000).microAlgos(), + // Signer only needed if you want to provide one, + // generally you'd register it with AlgorandClient + // against the sender and not need to pass it in + signer: transactionSigner, + maxRoundsToWaitForConfirmation: 5, + suppressLog: true, +}) +``` + +## Reconfigure + +If you have a `manager` address set on an asset, that address can end a reconfiguration transaction to change the `manager`, `reserve`, `freeze` and `clawback` fields of the asset if they haven't been set to empty. + +> [!WARNING] +> If you issue a reconfigure transaction and don't set the _existing_ values for any of the below fields then that field will be permanently set to empty. + +To reconfigure an asset you can use `algorand.send.assetConfig(params)` (immediately send a single asset config transaction), `algorand.transaction.assetConfig(params)` (construct an asset config transaction), or `algorand.newGroup().addAssetConfig(params)` (add asset config to a group of transactions) per [`AlgorandClient`](./algorand-client.md) [transaction semantics](./algorand-client.md#creating-and-issuing-transactions). + +The base type for specifying an asset creation transaction is [`AssetConfigParams`](../code/modules/types_composer.md#assetconfigparams), which has the following parameters in addition to the [common transaction parameters](./algorand-client.md#transaction-parameters): + +- `assetId: bigint` - ID of the asset to reconfigure +- `manager: string | undefined` - The address of the optional account that can manage the configuration of the asset and destroy it. The configuration fields it can change are `manager`, `reserve`, `clawback`, and `freeze`. If not set (`undefined` or `""`) the asset will become permanently immutable. +- `reserve?: string` - The address of the optional account that holds the reserve (uncirculated supply) units of the asset. This address has no specific authority in the protocol itself and is informational only. Some standards like [ARC-19](https://github.com/algorandfoundation/ARCs/blob/main/ARCs/arc-0019.md) rely on this field to hold meaningful data. It can be used in the case where you want to signal to holders of your asset that the uncirculated units of the asset reside in an account that is different from the default creator account. If not set (`undefined` or `""`) the field will become permanently empty. +- `freeze?: string` - The address of the optional account that can be used to freeze or unfreeze holdings of this asset for any account. If empty, freezing is not permitted. If not set (`undefined` or `""`) the field will become permanently empty. +- `clawback?: string` - The address of the optional account that can clawback holdings of this asset from any account. **This field should be used with caution** as the clawback account has the ability to **unconditionally take assets from any account**. If empty, clawback is not permitted. If not set (`undefined` or `""`) the field will become permanently empty. + +### Examples ```typescript -await algokit.createAsset( - { - creator: account, - total: 100, - decimals: 0, - name: 'My asset', - // Can optionally specify other parameters per above - // Can optionally also specify transactionParams, note, lease and other send params - }, - algod, -) +// Basic example + +await algorand.send.assetConfig({ sender: 'MANAGERADDRESS', assetId: 123456n, manager: 'MANAGERADDRESS' }) + +// Advanced example + +await algorand.send.assetCreate({ + sender: 'MANAGERADDRESS', + assetId: 123456n, + manager: 'MANAGERADDRESS', + reserve: 'RESERVEADDRESS', + freeze: 'FREEZEADDRESS', + clawback: 'CLAWBACKADDRESS', + lease: 'lease', + note: 'note', + // You wouldn't normally set this field + firstValidRound: 1000n, + validityWindow: 10, + extraFee: (1000).microAlgos(), + staticFee: (1000).microAlgos(), + // Max fee doesn't make sense with extraFee AND staticFee + // already specified, but here for completeness + maxFee: (3000).microAlgos(), + // Signer only needed if you want to provide one, + // generally you'd register it with AlgorandClient + // against the sender and not need to pass it in + signer: transactionSigner, + maxRoundsToWaitForConfirmation: 5, + suppressLog: true, +}) ``` ## Transfer -> [!NOTE] -> These methods require the [legacy AlgoKit Utils import method to access them](../README.md#usage). +To transfer unit(s) of an asset between accounts you can use `algorand.send.assetTransfer(params)` (immediately send a single asset transfer transaction), `algorand.transaction.assetTransfer(params)` (construct an asset transfer transaction), or `algorand.newGroup().addAssetTransfer(params)` (add asset transfer to a group of transactions) per [`AlgorandClient`](./algorand-client.md) [transaction semantics](./algorand-client.md#creating-and-issuing-transactions). -### `transferAsset` +**Note:** For an account to receive an asset it needs to have [opted-in](#opt-inout). -The key function to facilitate asset transfers is `transferAsset(transfer, algod)`, which returns a [`SendTransactionResult`](./transaction.md#sendtransactionresult) and takes a [`TransferAssetParams`](../code/interfaces/types_transfer.TransferAssetParams.md): +The base type for specifying an asset transfer transaction is [`AssetTransferParams`](../code/modules/types_composer.md#assettransferparams), which has the following parameters in addition to the [common transaction parameters](./algorand-client.md#transaction-parameters): -- All properties in [`SendTransactionParams`](./transaction.md#sendtransactionparams) -- `from: SendTransactionFrom` - The account that will send the asset -- `to: SendTransactionFrom | string` - The account / account address that will receive the asset -- `assetId: number` - The asset id that will be transfered -- `amount: number | bigint` - The amount to send in the smallest divisible unit -- `transactionParams?: SuggestedParams` - The optional [transaction parameters](./transaction.md#transaction-params) -- `clawbackFrom: SendTransactionFrom | string` - An optional address of a target account from which to perform a clawback operation. Please note, in such cases senderAccount must be equal to clawback field on ASA metadata. -- `note?: TransactionNote` - The [transaction note](./transaction.md#transaction-notes) -- `lease?: string | Uint8Array`: A [lease](https://developer.algorand.org/articles/leased-transactions-securing-advanced-smart-contract-design/) to assign to the transaction to enforce a mutually exclusive transaction (useful to prevent double-posting and other scenarios) +- `assetId: bigint` - ID of the asset to transfer. +- `amount: bigint` - Amount of the asset to transfer (in smallest divisible (decimal) units). +- `receiver: string` - The address of the account that will receive the asset unit(s). +- `clawbackTarget?: string` - Optional address of an account to clawback the asset from. Requires the sender to be the clawback account. **Warning:** Be careful with this parameter as it can lead to unexpected loss of funds if not used correctly. +- `closeAssetTo?: string` - Optional address of an account to close the asset position to. **Warning:** Be careful with this parameter as it can lead to loss of funds if not used correctly. -## Opt-in/out +### Examples -> [!NOTE] -> These methods require the [legacy AlgoKit Utils import method to access them](../README.md#usage). +```typescript +// Basic example + +await algorand.send.assetTransfer({sender: 'HOLDERADDRESS', assetId: 123456n, amount: 1n, receiver: 'RECEIVERADDRESS' }) + +// Advanced example (with clawback and close asset to) + +await algorand.send.assetTransfer({ + sender: 'CLAWBACKADDRESS', + assetId: 123456n, + amount: 1n, + receiver: 'RECEIVERADDRESS', + clawbackTarget: 'HOLDERADDRESS', + // This field needs to be used with caution + closeAssetTo: 'ADDRESSTOCLOSETO' + lease: 'lease', + note: 'note', + // You wouldn't normally set this field + firstValidRound: 1000n, + validityWindow: 10, + extraFee: (1000).microAlgos(), + staticFee: (1000).microAlgos(), + // Max fee doesn't make sense with extraFee AND staticFee + // already specified, but here for completeness + maxFee: (3000).microAlgos(), + // Signer only needed if you want to provide one, + // generally you'd register it with AlgorandClient + // against the sender and not need to pass it in + signer: transactionSigner, + maxRoundsToWaitForConfirmation: 5, + suppressLog: true, +}) +``` + +## Opt-in/out -Before an account can receive a specific asset, it must `opt-in` to receive it. An opt-in transaction places an asset holding of 0 into the account and increases its minimum balance by [100,000 microAlgos](https://developer.algorand.org/docs/get-details/asa/#assets-overview). +Before an account can receive a specific asset, it must [`opt-in`](https://developer.algorand.org/docs/get-details/asa/#receiving-an-asset) to receive it. An opt-in transaction places an asset holding of 0 into the account and increases the [minimum balance](https://developer.algorand.org/docs/get-details/accounts/#minimum-balance) of that account by [100,000 microAlgos](https://developer.algorand.org/docs/get-details/asa/#assets-overview). -An account can opt out of an asset at any time. This means that the account will no longer hold the asset, and the account will no longer be able to receive the asset. The account also recovers the Minimum Balance Requirement for the asset (100,000 microAlgos). +An account can opt out of an asset at any time by closing out it's asset position to another account (usually to the asset creator). This means that the account will no longer hold the asset, and the account will no longer be able to receive the asset. The account also recovers the Minimum Balance Requirement for the asset (100,000 microAlgos). -When opting-out you generally want to be careful to ensure you have a zero-balance otherwise you will forfeit the balance you do have. By default, AlgoKit Utils protects you from making this mistake by checking you have a zero-balance before issuing the opt-out transaction. You can turn this check off if you want to avoid the extra calls to Algorand and are confident in what you are doing. +When opting-out you generally want to be careful to ensure you have a zero-balance otherwise you will forfeit the balance you do have. AlgoKit Utils can protect you from making this mistake by checking you have a zero-balance before issuing the opt-out transaction. You can turn this check off if you want to avoid the extra calls to Algorand and are confident in what you are doing. -AlgoKit Utils gives you functions that allow you to do opt-ins in bulk or as a single operation. The bulk operations give you less control over the sending semantics as they automatically send the transactions to Algorand in the most optimal way using transaction groups. +AlgoKit Utils gives you functions that allow you to do opt-ins and opt-outs in bulk or as a single operation. The bulk operations give you less control over the sending semantics as they automatically send the transactions to Algorand in the most optimal way using transaction groups of 16 at a time. ### `assetOptIn` -To opt-in an account to a single asset you can use the [`algokit.assetOptIn(optIn, algod)`](../code/modules/index.md#assetoptin) function. The `optIn` argument is an object [containing](../code/interfaces/types_asset.AssetOptInParams.md): +To opt-in to an asset you can use `algorand.send.assetOptIn(params)` (immediately send a single asset opt-in transaction), `algorand.transaction.assetOptIn(params)` (construct an asset opt-in transaction), or `algorand.newGroup().addAssetOptIn(params)` (add asset opt-in to a group of transactions) per [`AlgorandClient`](./algorand-client.md) [transaction semantics](./algorand-client.md#creating-and-issuing-transactions). -- All properties in [`SendTransactionParams`](./transaction.md#sendtransactionparams) -- `account: SendTransactionFrom` - The account that will opt-in to the asset -- `assetId: number` - The asset id that will be opted-in to -- `transactionParams: SuggestedParams` - The optional [transaction parameters](./transaction.md#transaction-params) -- `note: TransactionNote` - The optional [transaction note](./transaction.md#transaction-notes) -- `lease: string | Uint8Array`: A [lease](https://developer.algorand.org/articles/leased-transactions-securing-advanced-smart-contract-design/) to assign to the transaction to enforce a mutually exclusive transaction (useful to prevent double-posting and other scenarios) +The base type for specifying an asset opt-in transaction is [`AssetOptInParams`](../code/modules/types_composer.md#assetoptinparams), which has the following parameters in addition to the [common transaction parameters](./algorand-client.md#transaction-parameters): + +- `assetId: bigint` - The ID of the asset that will be opted-in to ```typescript -// Example -await algokit.assetOptIn( - { - account: account, - assetId: 12345, - // Can optionally also specify transactionParams, note, lease and other send params - }, - algod, -) +// Basic example + +await algorand.send.assetOptIn({ sender: 'SENDERADDRESS', assetId: 123456n }) + +// Advanced example + +await algorand.send.assetOptIn({ + sender: 'SENDERADDRESS', + assetId: 123456n, + lease: 'lease', + note: 'note', + // You wouldn't normally set this field + firstValidRound: 1000n, + validityWindow: 10, + extraFee: (1000).microAlgos(), + staticFee: (1000).microAlgos(), + // Max fee doesn't make sense with extraFee AND staticFee + // already specified, but here for completeness + maxFee: (3000).microAlgos(), + // Signer only needed if you want to provide one, + // generally you'd register it with AlgorandClient + // against the sender and not need to pass it in + signer: transactionSigner, + maxRoundsToWaitForConfirmation: 5, + suppressLog: true, +}) ``` ### `assetOptOut` -To opt-out an account from a single asset you can use the [`algokit.assetOptOut(optOut, algod)`](../code/modules/index.md#assetoptout) function. The `optOut` argument is an object [containing](../code/interfaces/types_asset.AssetOptOutParams.md): +To opt-out to an asset you can use `algorand.send.assetOptOut(params)` (immediately send a single asset opt-out transaction), `algorand.transaction.assetOptOut(params)` (construct an asset opt-out transaction), or `algorand.newGroup().addAssetOptOut(params)` (add asset opt-out to a group of transactions) per [`AlgorandClient`](./algorand-client.md) [transaction semantics](./algorand-client.md#creating-and-issuing-transactions). + +The base type for specifying an asset opt-out transaction is [`AssetOptOutParams`](../code/modules/types_composer.md#assetoptoutparams), which has the following parameters in addition to the [common transaction parameters](./algorand-client.md#transaction-parameters): + +- `assetId: bigint` - The ID of the asset that will be opted-out of +- `creator: string` - The address of the asset creator account to close the asset position to (any remaining asset units will be sent to this account). -- All properties from [`assetOptIn`](#assetoptin) -- `assetCreatorAddress: string` - The address of the creator account for the asset; if unspecified then it looks it up using algod -- `ensureZeroBalance: boolean` - Whether or not to validate the account has a zero-balance before issuing the opt-out; defaults to true +If you are using the `send` variant then there is an additional parameter: + +- `ensureZeroBalance: boolean` - Whether or not to check if the account has a zero balance first or not. If this is set to `true` and the account has an asset balance it will throw an error. If this is set to `false` and the account has an asset balance it will lose those assets to the asset creator. + +> [!WARNING] +> If you are using the `transaction` or `addAssetOptOut` variants then you need to take responsibility to ensure the asset holding balance is `0` to avoid losing assets. ```typescript -// Example -await algokit.assetOptOut( - { - account: account, - assetId: 12345, - assetCreatorAddress: creator, - // Can optionally also specify ensureZeroBalance, transactionParams, note, lease and other send params - }, - algod, -) +// Basic example (without creator) + +await algorand.send.assetOptOut({ sender: 'SENDERADDRESS', assetId: 123456n, ensureZeroBalance: true }) + +// Basic example (with creator) + +await algorand.send.assetOptOut({ sender: 'SENDERADDRESS', creator: 'CREATORADDRESS', assetId: 123456n, ensureZeroBalance: true }) + +// Advanced example + +await algorand.send.assetOptOut({ + sender: 'SENDERADDRESS', + assetId: 123456n, + creator: 'CREATORADDRESS', + ensureZeroBalance: true, + lease: 'lease', + note: 'note', + // You wouldn't normally set this field + firstValidRound: 1000n, + validityWindow: 10, + extraFee: (1000).microAlgos(), + staticFee: (1000).microAlgos(), + // Max fee doesn't make sense with extraFee AND staticFee + // already specified, but here for completeness + maxFee: (3000).microAlgos(), + // Signer only needed if you want to provide one, + // generally you'd register it with AlgorandClient + // against the sender and not need to pass it in + signer: transactionSigner, + maxRoundsToWaitForConfirmation: 5, + suppressLog: true, +}) ``` ### `assetBulkOptIn` -The [`assetBulkOptIn`](../code/modules/index.md#assetbulkoptin) function facilitates the opt-in process for an account to multiple assets, allowing the account to receive and hold those assets. +The [`assetBulkOptIn`](../code/classes/types_account_manager.AccountManager.md#assetbulkoptin) function facilitates the opt-in process for an account to multiple assets, allowing the account to receive and hold those assets. ```typescript -// Example -await algokit.assetBulkOptIn( - { - account: account, - assetIds: [12354, 673453], - // Can optionally also specify validateBalances, transactionParams, note - }, - algod, -) +// Basic example + +algorand.account.assetBulkOptIn('ACCOUNTADDRESS', [12345n, 67890n]) + +// Advanced example + +algorand.account.assetBulkOptIn('ACCOUNTADDRESS', [12345n, 67890n], { + maxFee: (1000).microAlgos(), + suppressLog: true, +}) ``` ### `assetBulkOptOut` -The `assetBulkOptOut` function manages the opt-out process for a number of assets, permitting the account to discontinue holding a group of assets. +The [`assetBulkOptOut`](../code/classes/types_account_manager.AccountManager.md#assetbulkoptout) function facilitates the opt-out process for an account from multiple assets, permitting the account to discontinue holding a group of assets. ```typescript -// Example -await algokit.assetBulkOptOut( - { - account: account, - assetIds: [12354, 673453], - // Can optionally also specify validateBalances, transactionParams, note - }, - algod, -) +// Basic example + +algorand.account.assetBulkOptOut('ACCOUNTADDRESS', [12345n, 67890n]) + +// Advanced example + +algorand.account.assetBulkOptOut('ACCOUNTADDRESS', [12345n, 67890n], { + ensureZeroBalance: true, + maxFee: (1000).microAlgos(), + suppressLog: true, +}) ``` diff --git a/docs/capabilities/dispenser-client.md b/docs/capabilities/dispenser-client.md index 2aca1eb4..0df12e1b 100644 --- a/docs/capabilities/dispenser-client.md +++ b/docs/capabilities/dispenser-client.md @@ -11,7 +11,31 @@ To create a Dispenser Client, you need to provide an authorization token. This c If both methods are used, the constructor argument takes precedence. -You can get a TestNet dispenser API client via `ClientManager` (e.g. via `algorand.client.testNetDispenser()`), or directly, e.g.: +The recommended way to get a TestNet dispenser API client is [via `ClientManager`](./client.md): + +```typescript +// With auth token +const dispenserClient = algorand.client.getTestNetDispenser({ + authToken: 'your_auth_token', +}) + +// With auth token and timeout +const dispenserClient = algorand.client.getTestNetDispenser({ + authToken: 'your_auth_token', + requestTimeout: 2 /* seconds */, +}) + +// From environment variables +// i.e. process.env['ALGOKIT_DISPENSER_ACCESS_TOKEN'] = 'your_auth_token' +const dispenserClient = algorand.client.getTestNetDispenserFromEnvironment() + +// From environment variables with request timeout +const dispenserClient = algorand.client.getTestNetDispenserFromEnvironment({ + requestTimeout: 2 /* seconds */, +}) +``` + +Alternatively, you can construct it directly. ```ts import { TestNetDispenserApiClient } from '@algorandfoundation/algokit-utils/types/dispenser-client' diff --git a/docs/capabilities/indexer.md b/docs/capabilities/indexer.md index a55343e5..b08393cb 100644 --- a/docs/capabilities/indexer.md +++ b/docs/capabilities/indexer.md @@ -4,31 +4,38 @@ Indexer lookups / searching is a higher-order use case capability provided by Al To see some usage examples check out the [automated tests](../../src/indexer-lookup.spec.ts). -> [!NOTE] -> The methods on this page require the [legacy AlgoKit Utils import method to access them](../README.md#usage). +To import the indexer functions you can: + +```typescript +import { indexer } from '@algorandfoundation/algokit-utils' +``` + +All of the indexer functions require you to pass in an indexer SDK client, which you can get from [`AlgorandClient`](./algorand-client.md) via `algorand.client.indexer`. These calls are not made more easy to call by exposing via `AlgorandClient` and thus not requiring the indexer SDK client to be passed in. This is because we want to add a tiny bit of friction to using indexer, given it's an expensive API to run for node providers, the data from it can sometimes be slow and stale, and there are alternatives [that](https://github.com/algorandfoundation/algokit-subscriber-ts) [allow](https://github.com/algorand/conduit) individual projects to index subsets of chain data specific to them as a preferred option. In saying that, it's a very useful API for doing ad hoc data retrieval, writing automated tests, and many other uses. ## Indexer wrapper functions There is a subset of [indexer API calls](https://developer.algorand.org/docs/rest-apis/indexer) that are exposed as easy to use methods with correct typing exposed and automatic pagination for multi item returns. -- [`algokit.lookupTransactionById(transactionId, indexer)`](../code/modules/index.md#lookuptransactionbyid) - Finds a transaction by ID -- [`algokit.lookupAccountByAddress(accountAddress, indexer)`](../code/modules/index.md#lookupaccountbyaddress) - Finds an account by address -- [`algokit.lookupAccountCreatedApplicationByAddress(indexer, address, getAll?, paginationLimit?)`](../code/modules/index.md#lookupaccountcreatedapplicationbyaddress) - Finds all applications created for an account -- [`algokit.lookupAssetHoldings(indexer, assetId, options?, paginationLimit?)`](../code/modules/index.md#lookupassetholdings) - Finds all asset holdings for the given asset -- [`algokit.searchTransactions(indexer, searchCriteria, paginationLimit?)`](../code/modules/index.md#searchtransactions) - Search for transactions with a given set of criteria -- [`algokit.executePaginatedRequest(extractItems, buildRequest)`](../code/modules/index.md#executepaginatedrequest) - Execute the given indexer request with automatic pagination +- [`indexer.lookupTransactionById(transactionId, algorand.client.indexer)`](../code/modules/index.md#lookuptransactionbyid) - Finds a transaction by ID +- [`indexer.lookupAccountByAddress(accountAddress, algorand.client.indexer)`](../code/modules/index.md#lookupaccountbyaddress) - Finds an account by address +- [`indexer.lookupAccountCreatedApplicationByAddress(algorand.client.indexer, address, getAll?, paginationLimit?)`](../code/modules/index.md#lookupaccountcreatedapplicationbyaddress) - Finds all applications created for an account +- [`indexer.lookupAssetHoldings(algorand.client.indexer, assetId, options?, paginationLimit?)`](../code/modules/index.md#lookupassetholdings) - Finds all asset holdings for the given asset +- [`indexer.searchTransactions(algorand.client.indexer, searchCriteria, paginationLimit?)`](../code/modules/index.md#searchtransactions) - Search for transactions with a given set of criteria +- [`indexer.executePaginatedRequest(extractItems, buildRequest)`](../code/modules/index.md#executepaginatedrequest) - Execute the given indexer request with automatic pagination ### Search transactions example -To use the `algokit.searchTransaction` method, you can follow this example as a starting point: +To use the `indexer.searchTransaction` method, you can follow this example as a starting point: ```typescript -const transactions = await algokit.searchTransactions(indexer, (s) => s.txType('pay').addressRole('sender').address(myAddress)) +const transactions = await indexer.searchTransactions(algorand.client.indexer, (s) => + s.txType('pay').addressRole('sender').address(myAddress), +) ``` ### Automatic pagination example -To use the `algokit.executePaginatedRequest` method, you can follow this example as a starting point: +To use the `indexer.executePaginatedRequest` method, you can follow this example as a starting point: ```typescript const transactions = await executePaginatedRequest( @@ -36,7 +43,7 @@ const transactions = await executePaginatedRequest( return response.transactions }, (nextToken) => { - let s = indexer.searchForTransactions().txType('pay').address(myAddress).limit(1000) + let s = algorand.client.indexer.searchForTransactions().txType('pay').address(myAddress).limit(1000) if (nextToken) { s = s.nextToken(nextToken) } @@ -72,5 +79,5 @@ import { TransactionLookupResult } from '@algorandfoundation/algokit-utils/types ... -const transaction = (await indexer.lookupTransactionByID(transactionId).do()) as TransactionLookupResult +const transaction = (await algorand.client.indexer.lookupTransactionByID(transactionId).do()) as TransactionLookupResult ``` diff --git a/docs/capabilities/testing.md b/docs/capabilities/testing.md index 74d81469..a439bba3 100644 --- a/docs/capabilities/testing.md +++ b/docs/capabilities/testing.md @@ -35,7 +35,7 @@ describe('MY MODULE', () => { beforeEach(fixture.beforeEach, 10_000) test('MY TEST', async () => { - const { algod, testAccount /* ... */ } = fixture.context + const { algorand, testAccount /* ... */ } = fixture.context // Test stuff! }) @@ -57,7 +57,7 @@ describe('MY MODULE', () => { beforeEach(fixture.beforeEach, 10_000) test('MY TEST', async () => { - const { algod, testAccount /* ... */ } = fixture.context + const { algorand, testAccount /* ... */ } = fixture.context // Test stuff! }) @@ -71,12 +71,13 @@ When calling `algorandFixture()` you can optionally pass in some fixture configu - `algod?: Algodv2` - An optional algod client, if not specified then it will create one against environment variables defined network (if present) or default LocalNet - `indexer?: Indexer` - An optional indexer client, if not specified then it will create one against environment variables defined network (if present) or default LocalNet - `kmd?: Kmd` - An optional kmd client, if not specified then it will create one against environment variables defined network (if present) or default LocalNet -- `testAccountFunding?: AlgoAmount` - The [amount](./amount.md) of funds to allocate to the default testing account, if not specified then it will get `10` ALGOs +- `testAccountFunding?: AlgoAmount` - The [amount](./amount.md) of funds to allocate to the default testing account, if not specified then it will get `10` Algos ### Using the fixture context The `fixture.context` property is of type [`AlgorandTestAutomationContext`](../code/interfaces/types_testing.AlgorandTestAutomationContext.md) exposes the following properties from which you can pick which ones you want in a given test using an object [destructuring assignment](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Destructuring_assignment): +- `algorand: AlgorandClient` - An [`AlgorandClient`](./algorand-client.md) instance - `algod: Algodv2` - Proxy Algod client instance that will log sent transactions in `transactionLogger` - `indexer: Indexer` - Indexer client instance - `kmd: Kmd` - KMD client instance @@ -110,6 +111,7 @@ describe('MY MODULE', () => { afterEach(logs.afterEach) test('MY TEST', async () => { + const { algorand, testAccount } = fixture.context // Test stuff! const capturedLogs = logs.testLogger.capturedLogs @@ -132,6 +134,7 @@ describe('MY MODULE', () => { afterEach(logs.afterEach) test('MY TEST', async () => { + const { algorand, testAccount } = fixture.context // Test stuff! const capturedLogs = logs.testLogger.capturedLogs @@ -147,8 +150,8 @@ If you want to quickly pin some behaviour of what logic you have does in terms o This might look something like this: ```typescript -const { algod, indexer, testAccount } = fixture.context -const result = await algokit.deployApp(getAppDeploymentParams(), algod, indexer) +const { algorand, testAccount } = fixture.context +const result = await algorand.client.getTypedClientById(HelloWorldContractClient, { id: 0 }).deploy() expect( logging.testLogger.getLogSnapshot({ accounts: [testAccount], @@ -188,14 +191,14 @@ The easiest way to use this functionality is via the [Algorand fixture](#algoran ## Getting a test account -When testing, it's often useful to ephemerally generate random accounts, fund them with some number of ALGOs and then use that account to perform transactions. By creating an ephemeral, random account you naturally get isolation between tests and test runs and don't need to start from a specific blockchain network state. This makes test less flakey, and also means the same test can be run against LocalNet and (say) TestNet. +When testing, it's often useful to ephemerally generate random accounts, fund them with some number of Algos and then use that account to perform transactions. By creating an ephemeral, random account you naturally get isolation between tests and test runs and don't need to start from a specific blockchain network state. This makes test less flakey, and also means the same test can be run against LocalNet and (say) TestNet. The key when generating a test account is getting hold of a [dispenser](./transfer.md#dispenser) and then [ensuring the test account is funded](./transfer.md#ensurefunded). To make it easier to quickly get a test account the testing capability provides the following mechanisms: - [`algotesting.getTestAccount(testAccountParams, algod, kmd?)`](../code/modules/testing.md#gettestaccount) - Generates a random new account, logs the mnemonic of the account (unless suppressed), funds it from the [dispenser](./transfer.md#dispenser) -- `algorandFixture.testAccount` - A test account that is always generated for every test (log output suppressed to reduce noise, but worth noting that means the mnemonic isn't logged for this account), by default it is given 10 ALGOs unless overridden in the [fixture config](#fixture-configuration) +- `algorandFixture.testAccount` - A test account that is always generated for every test (log output suppressed to reduce noise, but worth noting that means the mnemonic isn't logged for this account), by default it is given 10 Algos unless overridden in the [fixture config](#fixture-configuration) - [`algorandFixture.generateAccount(testAccountParams)`](../code/interfaces/types_testing.AlgorandTestAutomationContext.md#generateaccount) - Allows you to quickly generate a test account with the `algod` and `kmd` instances that are part of the given fixture The parameters object that controls test account generation, [`GetTestAccountParams`](../code/interfaces/types_testing.GetTestAccountParams.md), has the following properties: diff --git a/docs/capabilities/transfer.md b/docs/capabilities/transfer.md index 4b44496a..36575071 100644 --- a/docs/capabilities/transfer.md +++ b/docs/capabilities/transfer.md @@ -1,57 +1,136 @@ -# Algo transfers - -Algo transfers is a higher-order use case capability provided by AlgoKit Utils that builds on top of the core capabilities, particularly [Algo amount handling](./amount.md) and [Transaction management](./transaction.md). It allows you to easily initiate algo transfers between accounts, including dispenser management and idempotent account funding. - -To see some usage examples check out the [automated tests](../../src/transfer.spec.ts). - -> [!NOTE] -> The methods on this page require the [legacy AlgoKit Utils import method to access them](../README.md#usage). - -## `transferAlgos` - -The key function to facilitate Algo transfers is `algokit.transferAlgos(transfer, algod)`, which returns a [`SendTransactionResult`](./transaction.md#sendtransactionresult) and takes a [`AlgoTransferParams`](../code/interfaces/types_transfer.AlgoTransferParams.md): - -- All properties in [`SendTransactionParams`](./transaction.md#sendtransactionparams) -- `from: SendTransactionFrom` - The account that will send the ALGOs -- `to: SendTransactionFrom | string` - The address of the account that will receive the ALGOs -- `amount: AlgoAmount` - The [amount](./amount.md) of ALGOs to send -- `transactionParams?: SuggestedParams` - The optional [transaction parameters](./transaction.md#transaction-params) -- `note?: TransactionNote` - The [transaction note](./transaction.md#transaction-notes) -- `lease?: string | Uint8Array`: A [lease](https://developer.algorand.org/articles/leased-transactions-securing-advanced-smart-contract-design/) to assign to the transaction to enforce a mutually exclusive transaction (useful to prevent double-posting and other scenarios) +# Algo transfers (payments) + +Algo transfers, or [payments](https://developer.algorand.org/docs/get-details/transactions/#payment-transaction), is a higher-order use case capability provided by AlgoKit Utils that builds on top of the core capabilities, particularly [Algo amount handling](./amount.md) and [Transaction management](./transaction.md). It allows you to easily initiate Algo transfers between accounts, including dispenser management and idempotent account funding. + +To see some usage examples check out the [automated tests](../../src/types/algorand-client.transfer.spec.ts). + +## `payment` + +The key function to facilitate Algo transfers is `algorand.send.payment(params)` (immediately send a single payment transaction), `algorand.transaction.payment(params)` (construct a payment transaction), or `algorand.newGroup().addPayment(params)` (add payment to a group of transactions) per [`AlgorandClient`](./algorand-client.md) [transaction semantics](./algorand-client.md#creating-and-issuing-transactions). + +The base type for specifying a payment transaction is [`PaymentParams`](../code/modules/types_composer.md#paymentparams), which has the following parameters in addition to the [common transaction parameters](./algorand-client.md#transaction-parameters): + +- `receiver: string` - The address of the account that will receive the Algos +- `amount: AlgoAmount` - The amount of Algos to send +- `closeRemainderTo?: string` - If given, close the sender account and send the remaining balance to this address (**warning:** use this carefully as it can result in loss of funds if used incorrectly) + +```typescript +// Minimal example +const result = await algorand.send.payment({ + sender: 'SENDERADDRESS', + receiver: 'RECEIVERADDRESS', + amount: (4).algos(), +}) + +// Advanced example +const result2 = await algorand.send.payment({ + sender: 'SENDERADDRESS', + receiver: 'RECEIVERADDRESS', + amount: (4).algos(), + closeRemainderTo: 'CLOSEREMAINDERTOADDRESS', + lease: 'lease', + note: 'note', + // Use this with caution, it's generally better to use algorand.account.rekeyAccount + rekeyTo: 'REKEYTOADDRESS', + // You wouldn't normally set this field + firstValidRound: 1000n, + validityWindow: 10, + extraFee: (1000).microAlgos(), + staticFee: (1000).microAlgos(), + // Max fee doesn't make sense with extraFee AND staticFee + // already specified, but here for completeness + maxFee: (3000).microAlgos(), + // Signer only needed if you want to provide one, + // generally you'd register it with AlgorandClient + // against the sender and not need to pass it in + signer: transactionSigner, + maxRoundsToWaitForConfirmation: 5, + suppressLog: true, +}) +``` ## `ensureFunded` -The `ensureFunded` function automatically funds an account to maintain a minimum amount of disposable ALGOs. This is particularly useful for automation and deployment scripts. The function is defined as `algokit.ensureFunded(funding, algod, kmd?)` and returns a [`EnsureFundedReturnType`](../code/interfaces/types_transfer.EnsureFundedReturnType.md) if a transaction was needed, or `undefined` if no transaction was required. The function takes a [`EnsureFundedParams`](../code/interfaces/types_transfer.EnsureFundedParams.md) object as an argument: - -- All properties in [`SendTransactionParams`](./transaction.md#sendtransactionparams) -- `accountToFund: SendTransactionFrom | string` - The account that is to be funded -- `fundingSource?: SendTransactionFrom | TestNetDispenserApiClient` - The account that is the source of funds or a dispenser API client. If not specified, it will use the [dispenser](./account.md#dispenser) -- `minSpendingBalance: AlgoAmount` - The minimum balance of ALGOs that the account should have available to spend (i.e., on top of the minimum balance requirement) -- `minFundingIncrement?: AlgoAmount` - When issuing a funding amount, the minimum amount to transfer. This avoids many small transfers if this function gets called often on an active account -- `transactionParams?: SuggestedParams` - The optional [transaction parameters](./transaction.md#transaction-params) -- `note?: TransactionNote` - The [transaction note](./transaction.md#transaction-notes) -- `lease?: string | Uint8Array`: A [lease](https://developer.algorand.org/articles/leased-transactions-securing-advanced-smart-contract-design/) to assign to the transaction to enforce a mutually exclusive transaction (useful to prevent double-posting and other scenarios) - -The function calls Algod to find the current balance and minimum balance requirement, calculates the difference between those two numbers, and checks to see if it's more than the `minSpendingBalance`. If so, it will send the difference, or the `minFundingIncrement` if that is specified. If the `fundingSource` is an instance of `TestNetDispenserApiClient`, the function will use the dispenser API to fund the account. Refer to [algokit-cli documentation](https://github.com/algorandfoundation/algokit-cli/blob/main/docs/features/dispenser.md#ci-access-token) for details on obtaining an access token for AlgoKit TestNet Dispenser API. - -## `transferAsset` - -The key function to facilitate asset transfers is `transferAsset(transfer, algod)`, which returns a [`SendTransactionResult`](./transaction.md#sendtransactionresult) and takes a [`TransferAssetParams`](../code/interfaces/types_transfer.TransferAssetParams.md): - -- All properties in [`SendTransactionParams`](./transaction.md#sendtransactionparams) -- `from: SendTransactionFrom` - The account that will send the asset -- `to: SendTransactionFrom | string` - The account / account address that will receive the asset -- `assetId: number` - The asset id that will be transfered -- `amount: number | bigint` - The amount to send in the smallest divisible unit -- `transactionParams?: SuggestedParams` - The optional [transaction parameters](./transaction.md#transaction-params) -- `clawbackFrom: SendTransactionFrom | string` - An optional address of a target account from which to perform a clawback operation. Please note, in such cases senderAccount must be equal to clawback field on ASA metadata. -- `note?: TransactionNote` - The [transaction note](./transaction.md#transaction-notes) -- `lease?: string | Uint8Array`: A [lease](https://developer.algorand.org/articles/leased-transactions-securing-advanced-smart-contract-design/) to assign to the transaction to enforce a mutually exclusive transaction (useful to prevent double-posting and other scenarios) +The `ensureFunded` function automatically funds an account to maintain a minimum amount of [disposable Algos](https://developer.algorand.org/docs/get-details/accounts/#minimum-balance). This is particularly useful for automation and deployment scripts that get run multiple times and consume Algos when run. + +There are 3 variants of this function: + +- [`algorand.account.ensureFunded(accountToFund, dispenserAccount, minSpendingBalance, options?)`](../code/classes/types_account_manager.AccountManager.md#ensurefunded) - Funds a given account using a dispenser account as a funding source such that the given account has a certain amount of Algos free to spend (accounting for Algos locked in minimum balance requirement). +- [`algorand.account.ensureFundedFromEnvironment(accountToFund, minSpendingBalance, options?)`](../code/classes/types_account_manager.AccountManager.md#ensurefundedfromenvironment) - Funds a given account using a dispenser account retrieved from the environment, per the [`dispenserFromEnvironment`](#dispenser) method, as a funding source such that the given account has a certain amount of Algos free to spend (accounting for Algos locked in minimum balance requirement). + - **Note:** requires a Node.js environment to execute. + - The dispenser account is retrieved from the account mnemonic stored in `process.env.DISPENSER_MNEMONIC` and optionally `process.env.DISPENSER_SENDER` + if it's a rekeyed account, or against default LocalNet if no environment variables present. +- [`algorand.account.ensureFundedFromTestNetDispenserApi(accountToFund, dispenserClient, minSpendingBalance, options)`](../code/classes/types_account_manager.AccountManager.md#ensurefundedfromtestnetdispenserapi) - Funds a given account using the [TestNet Dispenser API](https://github.com/algorandfoundation/algokit/blob/main/docs/testnet_api.md) as a funding source such that the account has a certain amount of Algos free to spend (accounting for Algos locked in minimum balance requirement). + +The general structure of these calls is similar, they all take: + +- `accountToFund: string | TransactionSignerAccount` - Address or signing account of the account to fund +- The source (dispenser): + - In `ensureFunded`: `dispenserAccount: string | TransactionSignerAccount` - the address or signing account of the account to use as a dispenser + - In `ensureFundedFromEnvironment`: Not specified, loaded automatically from the ephemeral environment + - In `ensureFundedFromTestNetDispenserApi`: `dispenserClient: TestNetDispenserApiClient` - a client instance of the [TestNet dispenser API](./dispenser-client.md) +- `minSpendingBalance: AlgoAmount` - The minimum balance of Algos that the account should have available to spend (i.e., on top of the minimum balance requirement) +- An `options` object, which has: + - [Common transaction parameters](./algorand-client.md#transaction-parameters) (not for TestNet Dispenser API) + - [Execution parameters](./algorand-client.md#sending-a-single-transaction) (not for TestNet Dispenser API) + - `minFundingIncrement?: AlgoAmount` - When issuing a funding amount, the minimum amount to transfer; this avoids many small transfers if this function gets called often on an active account + +### Examples + +```typescript +// From account + +// Basic example +await algorand.account.ensureFunded('ACCOUNTADDRESS', 'DISPENSERADDRESS', algokit.algos(1)) +// With configuration +await algorand.account.ensureFunded('ACCOUNTADDRESS', 'DISPENSERADDRESS', algokit.algos(1), { + minFundingIncrement: algokit.algos(2), + fee: (1000).microAlgos(), + suppressLog: true, +}) + +// From environment + +// Basic example +await algorand.account.ensureFundedFromEnvironment('ACCOUNTADDRESS', algokit.algos(1)) +// With configuration +await algorand.account.ensureFundedFromEnvironment('ACCOUNTADDRESS', algokit.algos(1), { + minFundingIncrement: algokit.algos(2), + fee: (1000).microAlgos(), + suppressLog: true, +}) + +// TestNet Dispenser API + +// Basic example +await algorand.account.ensureFundedUsingDispenserAPI( + 'ACCOUNTADDRESS', + algorand.client.getTestNetDispenserFromEnvironment(), + algokit.algos(1), +) +// With configuration +await algorand.account.ensureFundedUsingDispenserAPI( + 'ACCOUNTADDRESS', + algorand.client.getTestNetDispenserFromEnvironment(), + algokit.algos(1), + { minFundingIncrement: algokit.algos(2) }, +) +``` + +All 3 variants return an [`EnsureFundedReturnType`](../code/modules/types_account_manager.md#) (and the first two also return a [single transaction result](./algorand-client.md#sending-a-single-transaction)) if a funding transaction was needed, or `undefined` if no transaction was required: + +- `amountFunded: AlgoAmount` - The number of Algos that was paid +- `transactionId: string` - The ID of the transaction that funded the account + +If you are using the TestNet Dispenser API then the `transactionId` is useful if you want to use the [refund functionality](./dispenser-client.md#registering-a-refund). ## Dispenser -If you want to programmtically send funds then you will often need a "dispenser" account that has a store of ALGOs that can be sent and a private key available for that dispenser account. +If you want to programmatically send funds to an account so it can transact then you will often need a "dispenser" account that has a store of Algos that can be sent and a private key available for that dispenser account. -There is a standard AlgoKit Utils function to get access to a [dispenser account](./account.md#accounts): [`algokit.getDispenserAccount(algod, kmd?)`](../code/modules/index.md#getdispenseraccount). When running against [LocalNet](https://github.com/algorandfoundation/algokit-cli/blob/main/docs/features/localnet.md), the dispenser account can be automatically determined using the [Kmd API](https://developer.algorand.org/docs/rest-apis/kmd). When running against other networks like TestNet or MainNet the mnemonic (and optionally sender address if it's been rekeyed) of the dispenser account can be provided via environment variables (`process.env.DISPENSER_MNEMONIC` and optionally `process.env.DISPENSER_SENDER` if rekeyed). +There's a number of ways to get a dispensing account in AlgoKit Utils: -> Please note that this does not refer to the [AlgoKit TestNet Dispenser API](./dispenser-client.md) which is a separate abstraction that can be used to fund accounts on TestNet via dedicated API service. +- Get a dispenser via [account manager](./account.md#dispenser) - either automatically from [LocalNet](https://github.com/algorandfoundation/algokit-cli/blob/main/docs/features/localnet.md) or from the environment +- By programmatically creating one of the many account types via [account manager](./account.md#accounts) +- By programmatically interacting with [KMD](./account.md#kmd-account-management) if running against LocalNet +- By using the [AlgoKit TestNet Dispenser API client](./dispenser-client.md) which can be used to fund accounts on TestNet via a dedicated API service diff --git a/docs/capabilities/typed-app-clients.md b/docs/capabilities/typed-app-clients.md new file mode 100644 index 00000000..1dbc2180 --- /dev/null +++ b/docs/capabilities/typed-app-clients.md @@ -0,0 +1,100 @@ +# Typed application clients + +Typed deployment clients are automatically generated, typed TypeScript deployment and invocation clients for smart contracts that have an [ARC-0032 application specification](https://github.com/algorandfoundation/ARCs/blob/main/ARCs/arc-0032.md) so that the development experience is easier with less upskill ramp-up and less deployment errors. These clients give you a type-safe, intellisense-driven experience for invoking the smart contract. + +Typed application clients are the recommended way of interacting with smart contracts. If you don't have/want a typed client, but have an ARC-0032 app spec then you can use the [non-typed app client](./app-client.md) and if you want to call a smart contract you don't have an ARC-0032 file for you can use the underlying [app management](./app.md) and [app deployment](./app-deploy.md) functionality. + +## Generating an ARC-0032 app spec + +You can generate an ARC-0032 app spec file: + +- Using [Algorand Python](https://algorandfoundation.github.io/puya/#quick-start) +- Using [TEALScript](https://tealscript.netlify.app/tutorials/hello-world/0004-artifacts/) +- Using [Beaker](https://algorand-devrel.github.io/beaker/html/usage.html) (PyTEAL) +- By hand by [following the specification](https://github.com/algorandfoundation/ARCs/blob/main/ARCs/arc-0032.md) + +## Generating a typed client + +To generate a typed client from an ARC-0032 app spec file you can use [algokit CLI](https://github.com/algorandfoundation/algokit-cli/blob/main/docs/features/generate.md#1-typed-clients): + +``` +> algokit generate client application.json --output /absolute/path/to/client.ts +``` + +## Getting a typed client instance + +To get an instance of a typed client you can use an [`AlgorandClient`](./algorand-client.md) instance, which coordinates passing in SDK clients etc.: + +```typescript +// Resolve by ID +const appClient = algorand.client.getTypedAppClientById(MyContractClient, { + // 0 means it's not been deployed yet and it will be created and the ID + // set if you call `create` or `deploy`, alternatively you can specify + // the ID of an existing deployed app + id: 0, +}) +// Resolve by creator address and contract name +const appClient = algorand.client.getTypedAppClientByCreatorAndName(MyContractClient, { + creatorAddress: 'CREATORADDRESS', +}) +const appClient = algorand.client.getTypedAppClientByCreatorAndName(MyContractClient, { + creatorAddress: 'CREATORADDRESS', + // Override the name (by default uses the name in the ARC-32 app spec) + name: 'contract-name', +}) + +// With all optional params specified +const client = algorand.client.getTypedAppClientById({ + id: 12345, + name: nameOverride, + deployTimeParams, + params: suggestedParams, + sender: defaultSender, +}) +const appClient = algorand.client.getTypedAppClientByCreatorAndName( + MyContractClient, + { + creatorAddress: 'CREATORADDRESS', + name: nameOverride, + deployTimeParams, + params: suggestedParams, + sender: defaultSender, + }, + // Cached app lookup to avoid indexer calls + cachedAppLookup, +) +``` + +To understand the difference between resolving by ID and name see the underlying [app client documentation](./app-client.md#creating-an-application-client). + +## Client usage + +See the [official usage docs](https://github.com/algorandfoundation/algokit-client-generator-ts/blob/main/docs/usage.md) for full details. + +For a simple example that deploys a contract and calls a `"hello"` method, see below: + +```typescript +// A similar working example can be seen in the AlgoKit init production smart contract templates, when using TypeScript deployment +// In this case the generated client is called `HelloWorldAppClient` and is in `./artifacts/HelloWorldApp/client.ts` +import { HelloWorldAppClient } from './artifacts/HelloWorldApp/client' +import { AlgorandClient } from '@algorandfoundation/algokit-utils' + +// These require environment variables to be present, or it will retrieve from default LocalNet +const algorand = AlgorandClient.fromEnvironment() +const deployer = algorand.account.fromEnvironment('DEPLOYER', (1).algos()) + +// Create the typed app client +const appClient = algorand.client.getTypedAppClientByCreatorAndName(HelloWorldAppClient, { + creatorAddress: deployer.addr, + sender: deployer, +}) + +// Create the app (note: this creates a new instance of the app every time, +// you can use .deploy() to deploy idempotently if the app wasn't previously +// deployed or needs to be updated if that's allowed) +const app = await appClient.create() + +// Make a call to an ABI method and print the result +const response = await appClient.hello({ name: 'world' }) +console.log(response) +``` diff --git a/docs/code/README.md b/docs/code/README.md index 08dbbb13..ed5de139 100644 --- a/docs/code/README.md +++ b/docs/code/README.md @@ -13,7 +13,9 @@ - [types/account-manager.spec](modules/types_account_manager_spec.md) - [types/algo-http-client-with-retry](modules/types_algo_http_client_with_retry.md) - [types/algorand-client](modules/types_algorand_client.md) +- [types/algorand-client.asset.spec](modules/types_algorand_client_asset_spec.md) - [types/algorand-client.spec](modules/types_algorand_client_spec.md) +- [types/algorand-client.transfer.spec](modules/types_algorand_client_transfer_spec.md) - [types/amount](modules/types_amount.md) - [types/amount.spec](modules/types_amount_spec.md) - [types/app](modules/types_app.md) @@ -21,6 +23,7 @@ - [types/app-client.spec](modules/types_app_client_spec.md) - [types/app-spec](modules/types_app_spec.md) - [types/asset](modules/types_asset.md) +- [types/asset-manager](modules/types_asset_manager.md) - [types/client-manager](modules/types_client_manager.md) - [types/client-manager.spec](modules/types_client_manager_spec.md) - [types/composer](modules/types_composer.md) diff --git a/docs/code/classes/types_account.MultisigAccount.md b/docs/code/classes/types_account.MultisigAccount.md index 4fb42093..3915e8ab 100644 --- a/docs/code/classes/types_account.MultisigAccount.md +++ b/docs/code/classes/types_account.MultisigAccount.md @@ -49,7 +49,7 @@ Account wrapper that supports partial or full multisig signing. #### Defined in -[src/types/account.ts:39](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/account.ts#L39) +[src/types/account.ts:45](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/account.ts#L45) ## Properties @@ -59,7 +59,7 @@ Account wrapper that supports partial or full multisig signing. #### Defined in -[src/types/account.ts:17](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/account.ts#L17) +[src/types/account.ts:23](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/account.ts#L23) ___ @@ -69,7 +69,7 @@ ___ #### Defined in -[src/types/account.ts:15](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/account.ts#L15) +[src/types/account.ts:21](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/account.ts#L21) ___ @@ -79,7 +79,7 @@ ___ #### Defined in -[src/types/account.ts:18](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/account.ts#L18) +[src/types/account.ts:24](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/account.ts#L24) ___ @@ -89,7 +89,7 @@ ___ #### Defined in -[src/types/account.ts:16](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/account.ts#L16) +[src/types/account.ts:22](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/account.ts#L22) ## Accessors @@ -105,7 +105,7 @@ The address of the multisig account #### Defined in -[src/types/account.ts:31](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/account.ts#L31) +[src/types/account.ts:37](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/account.ts#L37) ___ @@ -121,7 +121,7 @@ The parameters for the multisig account #### Defined in -[src/types/account.ts:21](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/account.ts#L21) +[src/types/account.ts:27](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/account.ts#L27) ___ @@ -135,7 +135,7 @@ ___ #### Defined in -[src/types/account.ts:35](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/account.ts#L35) +[src/types/account.ts:41](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/account.ts#L41) ___ @@ -151,7 +151,7 @@ readonly (`default` \| [`SigningAccount`](types_account.SigningAccount.md))[] #### Defined in -[src/types/account.ts:26](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/account.ts#L26) +[src/types/account.ts:32](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/account.ts#L32) ## Methods @@ -175,4 +175,4 @@ The transaction signed by the present signers #### Defined in -[src/types/account.ts:54](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/account.ts#L54) +[src/types/account.ts:60](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/account.ts#L60) diff --git a/docs/code/classes/types_account.SigningAccount.md b/docs/code/classes/types_account.SigningAccount.md index 1304b0d7..54ed16ff 100644 --- a/docs/code/classes/types_account.SigningAccount.md +++ b/docs/code/classes/types_account.SigningAccount.md @@ -48,7 +48,7 @@ Account wrapper that supports a rekeyed account #### Defined in -[src/types/account.ts:105](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/account.ts#L105) +[src/types/account.ts:111](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/account.ts#L111) ## Properties @@ -58,7 +58,7 @@ Account wrapper that supports a rekeyed account #### Defined in -[src/types/account.ts:70](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/account.ts#L70) +[src/types/account.ts:76](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/account.ts#L76) ___ @@ -68,7 +68,7 @@ ___ #### Defined in -[src/types/account.ts:72](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/account.ts#L72) +[src/types/account.ts:78](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/account.ts#L78) ___ @@ -78,7 +78,7 @@ ___ #### Defined in -[src/types/account.ts:71](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/account.ts#L71) +[src/types/account.ts:77](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/account.ts#L77) ## Accessors @@ -98,7 +98,7 @@ Account.addr #### Defined in -[src/types/account.ts:77](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/account.ts#L77) +[src/types/account.ts:83](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/account.ts#L83) ___ @@ -114,7 +114,7 @@ Algorand account of the sender address and signer private key #### Defined in -[src/types/account.ts:98](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/account.ts#L98) +[src/types/account.ts:104](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/account.ts#L104) ___ @@ -130,7 +130,7 @@ Transaction signer for the underlying signing account #### Defined in -[src/types/account.ts:91](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/account.ts#L91) +[src/types/account.ts:97](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/account.ts#L97) ___ @@ -150,4 +150,4 @@ Account.sk #### Defined in -[src/types/account.ts:84](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/account.ts#L84) +[src/types/account.ts:90](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/account.ts#L90) diff --git a/docs/code/classes/types_account_manager.AccountManager.md b/docs/code/classes/types_account_manager.AccountManager.md index 7cfbd32a..93724efb 100644 --- a/docs/code/classes/types_account_manager.AccountManager.md +++ b/docs/code/classes/types_account_manager.AccountManager.md @@ -44,6 +44,7 @@ Creates and keeps track of signing accounts that can sign transactions for a sen - [logicsig](types_account_manager.AccountManager.md#logicsig) - [multisig](types_account_manager.AccountManager.md#multisig) - [random](types_account_manager.AccountManager.md#random) +- [rekeyAccount](types_account_manager.AccountManager.md#rekeyaccount) - [rekeyed](types_account_manager.AccountManager.md#rekeyed) - [setDefaultSigner](types_account_manager.AccountManager.md#setdefaultsigner) - [setSigner](types_account_manager.AccountManager.md#setsigner) @@ -76,7 +77,7 @@ const accountManager = new AccountManager(clientManager) #### Defined in -[src/types/account-manager.ts:63](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/account-manager.ts#L63) +[src/types/account-manager.ts:71](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/account-manager.ts#L71) ## Properties @@ -90,7 +91,7 @@ const accountManager = new AccountManager(clientManager) #### Defined in -[src/types/account-manager.ts:52](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/account-manager.ts#L52) +[src/types/account-manager.ts:60](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/account-manager.ts#L60) ___ @@ -100,7 +101,7 @@ ___ #### Defined in -[src/types/account-manager.ts:50](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/account-manager.ts#L50) +[src/types/account-manager.ts:58](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/account-manager.ts#L58) ___ @@ -110,7 +111,7 @@ ___ #### Defined in -[src/types/account-manager.ts:53](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/account-manager.ts#L53) +[src/types/account-manager.ts:61](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/account-manager.ts#L61) ___ @@ -120,7 +121,7 @@ ___ #### Defined in -[src/types/account-manager.ts:51](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/account-manager.ts#L51) +[src/types/account-manager.ts:59](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/account-manager.ts#L59) ## Accessors @@ -136,7 +137,7 @@ KMD account manager that allows you to easily get and create accounts using KMD. #### Defined in -[src/types/account-manager.ts:77](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/account-manager.ts#L77) +[src/types/account-manager.ts:85](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/account-manager.ts#L85) ## Methods @@ -156,7 +157,7 @@ KMD account manager that allows you to easily get and create accounts using KMD. #### Defined in -[src/types/account-manager.ts:68](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/account-manager.ts#L68) +[src/types/account-manager.ts:76](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/account-manager.ts#L76) ___ @@ -178,7 +179,7 @@ ___ #### Defined in -[src/types/account-manager.ts:593](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/account-manager.ts#L593) +[src/types/account-manager.ts:666](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/account-manager.ts#L666) ___ @@ -195,7 +196,7 @@ Transactions will be sent in batches of 16 as transaction groups. | Name | Type | Description | | :------ | :------ | :------ | | `account` | `string` \| [`TransactionSignerAccount`](../interfaces/types_account.TransactionSignerAccount.md) | The account to opt-in | -| `assetIds` | (`number` \| `bigint`)[] | The list of asset IDs to opt-in to | +| `assetIds` | `bigint`[] | The list of asset IDs to opt-in to | | `options?` | `Omit`\<[`CommonTransactionParams`](../modules/types_composer.md#commontransactionparams), ``"sender"``\> & [`ExecuteParams`](../interfaces/types_composer.ExecuteParams.md) | Any parameters to control the transaction or execution of the transaction | #### Returns @@ -208,14 +209,14 @@ An array of records matching asset ID to transaction ID of the opt in ```typescript // Basic example -algorand.account.assetBulkOptIn("ACCOUNTADDRESS", [12345, 67890]) +algorand.account.assetBulkOptIn("ACCOUNTADDRESS", [12345n, 67890n]) // With configuration -algorand.account.assetBulkOptIn("ACCOUNTADDRESS", [12345, 67890], { maxFee: (1000).microAlgos(), suppressLog: true }) +algorand.account.assetBulkOptIn("ACCOUNTADDRESS", [12345n, 67890n], { maxFee: (1000).microAlgos(), suppressLog: true }) ``` #### Defined in -[src/types/account-manager.ts:470](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/account-manager.ts#L470) +[src/types/account-manager.ts:478](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/account-manager.ts#L478) ___ @@ -232,8 +233,8 @@ Transactions will be sent in batches of 16 as transaction groups. | Name | Type | Description | | :------ | :------ | :------ | | `account` | `string` \| [`TransactionSignerAccount`](../interfaces/types_account.TransactionSignerAccount.md) | The account to opt-in | -| `assetIds` | (`number` \| `bigint`)[] | The list of asset IDs to opt-out of | -| `options?` | `Omit`\<[`CommonTransactionParams`](../modules/types_composer.md#commontransactionparams), ``"sender"``\> & [`ExecuteParams`](../interfaces/types_composer.ExecuteParams.md) & \{ `ensureZeroBalance`: `boolean` } | Any parameters to control the transaction or execution of the transaction | +| `assetIds` | `bigint`[] | The list of asset IDs to opt-out of | +| `options?` | `Omit`\<[`CommonTransactionParams`](../modules/types_composer.md#commontransactionparams), ``"sender"``\> & [`ExecuteParams`](../interfaces/types_composer.ExecuteParams.md) & \{ `ensureZeroBalance?`: `boolean` } | Any parameters to control the transaction or execution of the transaction | #### Returns @@ -245,14 +246,14 @@ An array of records matching asset ID to transaction ID of the opt in ```typescript // Basic example -algorand.account.assetBulkOptOut("ACCOUNTADDRESS", [12345, 67890]) +algorand.account.assetBulkOptOut("ACCOUNTADDRESS", [12345n, 67890n]) // With configuration -algorand.account.assetBulkOptOut("ACCOUNTADDRESS", [12345, 67890], { maxFee: (1000).microAlgos(), suppressLog: true }) +algorand.account.assetBulkOptOut("ACCOUNTADDRESS", [12345n, 67890n], { ensureZeroBalance: true, maxFee: (1000).microAlgos(), suppressLog: true }) ``` #### Defined in -[src/types/account-manager.ts:522](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/account-manager.ts#L522) +[src/types/account-manager.ts:530](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/account-manager.ts#L530) ___ @@ -282,7 +283,7 @@ const account = await account.dispenserFromEnvironment() #### Defined in -[src/types/account-manager.ts:429](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/account-manager.ts#L429) +[src/types/account-manager.ts:437](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/account-manager.ts#L437) ___ @@ -291,8 +292,8 @@ ___ ▸ **ensureFunded**(`accountToFund`, `dispenserAccount`, `minSpendingBalance`, `options?`): `Promise`\<`undefined` \| [`SendAtomicTransactionComposerResults`](../interfaces/types_transaction.SendAtomicTransactionComposerResults.md) & [`ConfirmedTransactionResult`](../interfaces/types_transaction.ConfirmedTransactionResult.md) & [`EnsureFundedResult`](../interfaces/types_account_manager.EnsureFundedResult.md)\> Funds a given account using a dispenser account as a funding source such that -the given account has a certain amount of algos free to spend (accounting for -ALGOs locked in minimum balance requirement). +the given account has a certain amount of Algos free to spend (accounting for +Algos locked in minimum balance requirement). https://developer.algorand.org/docs/get-details/accounts/#minimum-balance @@ -302,7 +303,7 @@ https://developer.algorand.org/docs/get-details/accounts/#minimum-balance | :------ | :------ | :------ | | `accountToFund` | `string` \| [`TransactionSignerAccount`](../interfaces/types_account.TransactionSignerAccount.md) | The account to fund | | `dispenserAccount` | `string` \| [`TransactionSignerAccount`](../interfaces/types_account.TransactionSignerAccount.md) | The account to use as a dispenser funding source | -| `minSpendingBalance` | [`AlgoAmount`](types_amount.AlgoAmount.md) | The minimum balance of ALGOs that the account should have available to spend (i.e. on top of minimum balance requirement) | +| `minSpendingBalance` | [`AlgoAmount`](types_amount.AlgoAmount.md) | The minimum balance of Algos that the account should have available to spend (i.e. on top of minimum balance requirement) | | `options?` | \{ `minFundingIncrement?`: [`AlgoAmount`](types_amount.AlgoAmount.md) } & [`ExecuteParams`](../interfaces/types_composer.ExecuteParams.md) & `Omit`\<[`CommonTransactionParams`](../modules/types_composer.md#commontransactionparams), ``"sender"``\> | Optional parameters to control the funding increment, transaction or execution of the transaction | #### Returns @@ -325,7 +326,7 @@ await algorand.account.ensureFunded("ACCOUNTADDRESS", "DISPENSERADDRESS", algoki #### Defined in -[src/types/account-manager.ts:626](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/account-manager.ts#L626) +[src/types/account-manager.ts:699](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/account-manager.ts#L699) ___ @@ -335,8 +336,8 @@ ___ Funds a given account using a dispenser account retrieved from the environment, per the `dispenserFromEnvironment` method, as a funding source such that -the given account has a certain amount of algos free to spend (accounting for -ALGOs locked in minimum balance requirement). +the given account has a certain amount of Algos free to spend (accounting for +Algos locked in minimum balance requirement). **Note:** requires a Node.js environment to execute. @@ -351,7 +352,7 @@ https://developer.algorand.org/docs/get-details/accounts/#minimum-balance | Name | Type | Description | | :------ | :------ | :------ | | `accountToFund` | `string` \| [`TransactionSignerAccount`](../interfaces/types_account.TransactionSignerAccount.md) | The account to fund | -| `minSpendingBalance` | [`AlgoAmount`](types_amount.AlgoAmount.md) | The minimum balance of ALGOs that the account should have available to spend (i.e. on top of minimum balance requirement) | +| `minSpendingBalance` | [`AlgoAmount`](types_amount.AlgoAmount.md) | The minimum balance of Algos that the account should have available to spend (i.e. on top of minimum balance requirement) | | `options?` | \{ `minFundingIncrement?`: [`AlgoAmount`](types_amount.AlgoAmount.md) } & [`ExecuteParams`](../interfaces/types_composer.ExecuteParams.md) & `Omit`\<[`CommonTransactionParams`](../modules/types_composer.md#commontransactionparams), ``"sender"``\> | Optional parameters to control the funding increment, transaction or execution of the transaction | #### Returns @@ -374,7 +375,7 @@ await algorand.account.ensureFundedFromEnvironment("ACCOUNTADDRESS", algokit.alg #### Defined in -[src/types/account-manager.ts:688](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/account-manager.ts#L688) +[src/types/account-manager.ts:761](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/account-manager.ts#L761) ___ @@ -383,7 +384,7 @@ ___ ▸ **ensureFundedFromTestNetDispenserApi**(`accountToFund`, `dispenserClient`, `minSpendingBalance`, `options`): `Promise`\<`undefined` \| [`EnsureFundedResult`](../interfaces/types_account_manager.EnsureFundedResult.md)\> Funds a given account using the TestNet Dispenser API as a funding source such that -the account has a certain amount of algos free to spend (accounting for ALGOs locked +the account has a certain amount of algos free to spend (accounting for Algos locked in minimum balance requirement). https://developer.algorand.org/docs/get-details/accounts/#minimum-balance @@ -394,7 +395,7 @@ https://developer.algorand.org/docs/get-details/accounts/#minimum-balance | :------ | :------ | :------ | | `accountToFund` | `string` \| [`TransactionSignerAccount`](../interfaces/types_account.TransactionSignerAccount.md) | The account to fund | | `dispenserClient` | [`TestNetDispenserApiClient`](types_dispenser_client.TestNetDispenserApiClient.md) | The TestNet dispenser funding client | -| `minSpendingBalance` | [`AlgoAmount`](types_amount.AlgoAmount.md) | The minimum balance of ALGOs that the account should have available to spend (i.e. on top of minimum balance requirement) | +| `minSpendingBalance` | [`AlgoAmount`](types_amount.AlgoAmount.md) | The minimum balance of Algos that the account should have available to spend (i.e. on top of minimum balance requirement) | | `options` | `Object` | Optional parameters to control the funding increment, transaction or execution of the transaction | | `options.minFundingIncrement?` | [`AlgoAmount`](types_amount.AlgoAmount.md) | - | @@ -418,7 +419,7 @@ await algorand.account.ensureFundedUsingDispenserAPI("ACCOUNTADDRESS", algorand. #### Defined in -[src/types/account-manager.ts:744](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/account-manager.ts#L744) +[src/types/account-manager.ts:817](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/account-manager.ts#L817) ___ @@ -458,12 +459,12 @@ If you have a mnemonic secret loaded into `process.env.MY_ACCOUNT_MNEMONIC` then const account = await accountManager.fromEnvironment('MY_ACCOUNT') ``` -If that code runs against LocalNet then a wallet called `MY_ACCOUNT` will automatically be created with an account that is automatically funded with 1000 (default) ALGOs from the default LocalNet dispenser. +If that code runs against LocalNet then a wallet called `MY_ACCOUNT` will automatically be created with an account that is automatically funded with 1000 (default) Algos from the default LocalNet dispenser. If not running against LocalNet then it will use proces.env.MY_ACCOUNT_MNEMONIC as the private key and (if present) process.env.MY_ACCOUNT_SENDER as the sender address. #### Defined in -[src/types/account-manager.ts:322](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/account-manager.ts#L322) +[src/types/account-manager.ts:330](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/account-manager.ts#L330) ___ @@ -497,7 +498,7 @@ const defaultDispenserAccount = await account.fromKmd('unencrypted-default-walle #### Defined in -[src/types/account-manager.ts:358](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/account-manager.ts#L358) +[src/types/account-manager.ts:366](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/account-manager.ts#L366) ___ @@ -529,7 +530,7 @@ const rekeyedAccount = accountManager.fromMnemonic("mnemonic secret ...", "SENDE #### Defined in -[src/types/account-manager.ts:274](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/account-manager.ts#L274) +[src/types/account-manager.ts:282](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/account-manager.ts#L282) ___ @@ -564,13 +565,13 @@ const account = accountManager.getAccount(sender) #### Defined in -[src/types/account-manager.ts:189](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/account-manager.ts#L189) +[src/types/account-manager.ts:197](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/account-manager.ts#L197) ___ ### getAssetInformation -▸ **getAssetInformation**(`sender`, `assetId`): `Promise`\<\{ `assetId`: `bigint` ; `balance`: `bigint` ; `frozen`: `boolean` ; `round`: `bigint` }\> +▸ **getAssetInformation**(`sender`, `assetId`): `Promise`\<[`AccountAssetInformation`](../modules/types_account.md#accountassetinformation)\> Returns the given sender account's asset holding for a given asset. @@ -583,7 +584,7 @@ Returns the given sender account's asset holding for a given asset. #### Returns -`Promise`\<\{ `assetId`: `bigint` ; `balance`: `bigint` ; `frozen`: `boolean` ; `round`: `bigint` }\> +`Promise`\<[`AccountAssetInformation`](../modules/types_account.md#accountassetinformation)\> The account asset holding information @@ -599,7 +600,7 @@ const accountInfo = await accountManager.getAssetInformation(address, assetId); #### Defined in -[src/types/account-manager.ts:248](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/account-manager.ts#L248) +[src/types/account-manager.ts:256](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/account-manager.ts#L256) ___ @@ -632,7 +633,7 @@ const accountInfo = await accountManager.getInformation(address); #### Defined in -[src/types/account-manager.ts:208](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/account-manager.ts#L208) +[src/types/account-manager.ts:216](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/account-manager.ts#L216) ___ @@ -665,7 +666,7 @@ const signer = accountManager.getSigner("SENDERADDRESS") #### Defined in -[src/types/account-manager.ts:169](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/account-manager.ts#L169) +[src/types/account-manager.ts:177](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/account-manager.ts#L177) ___ @@ -689,7 +690,7 @@ const account = await account.localNetDispenser() #### Defined in -[src/types/account-manager.ts:448](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/account-manager.ts#L448) +[src/types/account-manager.ts:456](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/account-manager.ts#L456) ___ @@ -720,7 +721,7 @@ const account = account.logicsig(program, [new Uint8Array(3, ...)]) #### Defined in -[src/types/account-manager.ts:396](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/account-manager.ts#L396) +[src/types/account-manager.ts:404](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/account-manager.ts#L404) ___ @@ -752,7 +753,7 @@ const account = accountManager.multisig({version: 1, threshold: 1, addrs: ["ADDR #### Defined in -[src/types/account-manager.ts:381](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/account-manager.ts#L381) +[src/types/account-manager.ts:389](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/account-manager.ts#L389) ___ @@ -776,13 +777,73 @@ const account = account.random() #### Defined in -[src/types/account-manager.ts:409](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/account-manager.ts#L409) +[src/types/account-manager.ts:417](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/account-manager.ts#L417) + +___ + +### rekeyAccount + +▸ **rekeyAccount**(`account`, `rekeyTo`, `options?`): `Promise`\<[`SendSingleTransactionResult`](../modules/types_algorand_client.md#sendsingletransactionresult)\> + +Rekey an account to a new address. + +**Note:** Please be careful with this function and be sure to read the [official rekey guidance](https://developer.algorand.org/docs/get-details/accounts/rekey/). + +#### Parameters + +| Name | Type | Description | +| :------ | :------ | :------ | +| `account` | `string` \| [`TransactionSignerAccount`](../interfaces/types_account.TransactionSignerAccount.md) | The account to rekey | +| `rekeyTo` | `string` \| [`TransactionSignerAccount`](../interfaces/types_account.TransactionSignerAccount.md) | The account address or signing account of the account that will be used to authorise transactions for the rekeyed account going forward. If a signing account is provided that will now be tracked as the signer for `account` in this `AccountManager` | +| `options?` | `Omit`\<[`CommonTransactionParams`](../modules/types_composer.md#commontransactionparams), ``"sender"``\> & [`ExecuteParams`](../interfaces/types_composer.ExecuteParams.md) | Any parameters to control the transaction or execution of the transaction | + +#### Returns + +`Promise`\<[`SendSingleTransactionResult`](../modules/types_algorand_client.md#sendsingletransactionresult)\> + +The result of the transaction and the transaction that was sent + +**`Example`** + +```typescript +await algorand.account.rekeyAccount({account: "ACCOUNTADDRESS", rekeyTo: "NEWADDRESS"}) +``` + +**`Example`** + +```typescript +await algorand.account.rekeyAccount({account: account1, rekeyTo: newSignerAccount}) +``` + +**`Example`** + +```typescript +await algorand.account.rekeyAccount({ + account: "ACCOUNTADDRESS", + rekeyTo: "NEWADDRESS", + lease: 'lease', + note: 'note', + firstValidRound: 1000n, + validityWindow: 10, + extraFee: (1000).microAlgos(), + staticFee: (1000).microAlgos(), + // Max fee doesn't make sense with extraFee AND staticFee + // already specified, but here for completeness + maxFee: (3000).microAlgos(), + maxRoundsToWaitForConfirmation: 5, + suppressLog: true, +}) +``` + +#### Defined in + +[src/types/account-manager.ts:641](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/account-manager.ts#L641) ___ ### rekeyed -▸ **rekeyed**(`account`, `sender`): [`TransactionSignerAccount`](../interfaces/types_account.TransactionSignerAccount.md) & \{ `account`: \{ `addr`: `string` = sender; `signer`: `TransactionSigner` = account.signer } } +▸ **rekeyed**(`sender`, `account`): [`TransactionSignerAccount`](../interfaces/types_account.TransactionSignerAccount.md) & \{ `account`: \{ `addr`: `string` = sender; `signer`: `TransactionSigner` = account.signer } } Tracks and returns an Algorand account that is a rekeyed version of the given account to a new sender. @@ -790,8 +851,8 @@ Tracks and returns an Algorand account that is a rekeyed version of the given ac | Name | Type | Description | | :------ | :------ | :------ | -| `account` | [`TransactionSignerAccount`](../interfaces/types_account.TransactionSignerAccount.md) | The account to use as the signer for this new rekeyed account | | `sender` | `string` | The sender address to use as the new sender | +| `account` | [`TransactionSignerAccount`](../interfaces/types_account.TransactionSignerAccount.md) | The account to use as the signer for this new rekeyed account | #### Returns @@ -808,7 +869,7 @@ const rekeyedAccount = accountManager.rekeyed(account, "SENDERADDRESS...") #### Defined in -[src/types/account-manager.ts:291](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/account-manager.ts#L291) +[src/types/account-manager.ts:299](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/account-manager.ts#L299) ___ @@ -845,7 +906,7 @@ const signer = accountManager.getSigner("{SENDERADDRESS}") #### Defined in -[src/types/account-manager.ts:97](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/account-manager.ts#L97) +[src/types/account-manager.ts:105](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/account-manager.ts#L105) ___ @@ -877,7 +938,7 @@ const accountManager = new AccountManager(clientManager) #### Defined in -[src/types/account-manager.ts:151](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/account-manager.ts#L151) +[src/types/account-manager.ts:159](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/account-manager.ts#L159) ___ @@ -915,7 +976,7 @@ const accountManager = new AccountManager(clientManager) #### Defined in -[src/types/account-manager.ts:135](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/account-manager.ts#L135) +[src/types/account-manager.ts:143](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/account-manager.ts#L143) ___ @@ -944,4 +1005,4 @@ retrieval and returns a `TransactionSignerAccount` along with the original accou #### Defined in -[src/types/account-manager.ts:106](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/account-manager.ts#L106) +[src/types/account-manager.ts:114](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/account-manager.ts#L114) diff --git a/docs/code/classes/types_algorand_client.AlgorandClient.md b/docs/code/classes/types_algorand_client.AlgorandClient.md index a02bc4b6..112d5a18 100644 --- a/docs/code/classes/types_algorand_client.AlgorandClient.md +++ b/docs/code/classes/types_algorand_client.AlgorandClient.md @@ -15,6 +15,7 @@ A client that brokers easy access to Algorand functionality. ### Properties - [\_accountManager](types_algorand_client.AlgorandClient.md#_accountmanager) +- [\_assetManager](types_algorand_client.AlgorandClient.md#_assetmanager) - [\_cachedSuggestedParams](types_algorand_client.AlgorandClient.md#_cachedsuggestedparams) - [\_cachedSuggestedParamsExpiry](types_algorand_client.AlgorandClient.md#_cachedsuggestedparamsexpiry) - [\_cachedSuggestedParamsTimeout](types_algorand_client.AlgorandClient.md#_cachedsuggestedparamstimeout) @@ -26,6 +27,7 @@ A client that brokers easy access to Algorand functionality. ### Accessors - [account](types_algorand_client.AlgorandClient.md#account) +- [asset](types_algorand_client.AlgorandClient.md#asset) - [client](types_algorand_client.AlgorandClient.md#client) ### Methods @@ -65,7 +67,7 @@ A client that brokers easy access to Algorand functionality. #### Defined in -[src/types/algorand-client.ts:29](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/algorand-client.ts#L29) +[src/types/algorand-client.ts:31](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/algorand-client.ts#L31) ## Properties @@ -75,7 +77,17 @@ A client that brokers easy access to Algorand functionality. #### Defined in -[src/types/algorand-client.ts:21](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/algorand-client.ts#L21) +[src/types/algorand-client.ts:22](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/algorand-client.ts#L22) + +___ + +### \_assetManager + +• `Private` **\_assetManager**: [`AssetManager`](types_asset_manager.AssetManager.md) + +#### Defined in + +[src/types/algorand-client.ts:23](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/algorand-client.ts#L23) ___ @@ -85,7 +97,7 @@ ___ #### Defined in -[src/types/algorand-client.ts:23](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/algorand-client.ts#L23) +[src/types/algorand-client.ts:25](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/algorand-client.ts#L25) ___ @@ -95,7 +107,7 @@ ___ #### Defined in -[src/types/algorand-client.ts:24](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/algorand-client.ts#L24) +[src/types/algorand-client.ts:26](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/algorand-client.ts#L26) ___ @@ -105,7 +117,7 @@ ___ #### Defined in -[src/types/algorand-client.ts:25](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/algorand-client.ts#L25) +[src/types/algorand-client.ts:27](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/algorand-client.ts#L27) ___ @@ -115,7 +127,7 @@ ___ #### Defined in -[src/types/algorand-client.ts:20](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/algorand-client.ts#L20) +[src/types/algorand-client.ts:21](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/algorand-client.ts#L21) ___ @@ -125,7 +137,7 @@ ___ #### Defined in -[src/types/algorand-client.ts:27](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/algorand-client.ts#L27) +[src/types/algorand-client.ts:29](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/algorand-client.ts#L29) ___ @@ -140,8 +152,8 @@ Methods for sending a single transaction. | Name | Type | Description | | :------ | :------ | :------ | | `appCall` | (`params`: [`CommonTransactionParams`](../modules/types_composer.md#commontransactionparams) & \{ `accountReferences?`: `string`[] ; `appId?`: `bigint` ; `appReferences?`: `bigint`[] ; `approvalProgram?`: `Uint8Array` ; `args?`: `Uint8Array`[] ; `assetReferences?`: `bigint`[] ; `boxReferences?`: `BoxReference`[] ; `clearProgram?`: `Uint8Array` ; `extraPages?`: `number` ; `onComplete?`: `OnApplicationComplete` ; `schema?`: \{ `globalByteSlices`: `number` ; `globalUints`: `number` ; `localByteSlices`: `number` ; `localUints`: `number` } } & [`ExecuteParams`](../interfaces/types_composer.ExecuteParams.md)) => `Promise`\<[`SendSingleTransactionResult`](../modules/types_algorand_client.md#sendsingletransactionresult)\> | - | -| `assetConfig` | (`params`: [`CommonTransactionParams`](../modules/types_composer.md#commontransactionparams) & \{ `assetId`: `bigint` ; `clawback?`: `string` ; `freeze?`: `string` ; `manager?`: `string` ; `reserve?`: `string` } & [`ExecuteParams`](../interfaces/types_composer.ExecuteParams.md)) => `Promise`\<[`SendSingleTransactionResult`](../modules/types_algorand_client.md#sendsingletransactionresult)\> | - | -| `assetCreate` | (`params`: [`CommonTransactionParams`](../modules/types_composer.md#commontransactionparams) & \{ `assetName?`: `string` ; `clawback?`: `string` ; `decimals?`: `number` ; `defaultFrozen?`: `boolean` ; `freeze?`: `string` ; `manager?`: `string` ; `metadataHash?`: `string` \| `Uint8Array` ; `reserve?`: `string` ; `total`: `bigint` ; `unitName?`: `string` ; `url?`: `string` } & [`ExecuteParams`](../interfaces/types_composer.ExecuteParams.md)) => `Promise`\<[`SendSingleTransactionResult`](../modules/types_algorand_client.md#sendsingletransactionresult)\> | - | +| `assetConfig` | (`params`: [`CommonTransactionParams`](../modules/types_composer.md#commontransactionparams) & \{ `assetId`: `bigint` ; `clawback?`: `string` ; `freeze?`: `string` ; `manager`: `undefined` \| `string` ; `reserve?`: `string` } & [`ExecuteParams`](../interfaces/types_composer.ExecuteParams.md)) => `Promise`\<[`SendSingleTransactionResult`](../modules/types_algorand_client.md#sendsingletransactionresult)\> | - | +| `assetCreate` | (`params`: [`CommonTransactionParams`](../modules/types_composer.md#commontransactionparams) & \{ `assetName?`: `string` ; `clawback?`: `string` ; `decimals?`: `number` ; `defaultFrozen?`: `boolean` ; `freeze?`: `string` ; `manager?`: `string` ; `metadataHash?`: `string` \| `Uint8Array` ; `reserve?`: `string` ; `total`: `bigint` ; `unitName?`: `string` ; `url?`: `string` } & [`ExecuteParams`](../interfaces/types_composer.ExecuteParams.md)) => `Promise`\<\{ `assetId`: `bigint` ; `confirmation`: `PendingTransactionResponse` ; `confirmations`: `PendingTransactionResponse`[] ; `groupId`: `string` ; `returns?`: [`ABIReturn`](../modules/types_app.md#abireturn)[] ; `transaction`: `Transaction` ; `transactions`: `Transaction`[] ; `txIds`: `string`[] }\> | - | | `assetDestroy` | (`params`: [`CommonTransactionParams`](../modules/types_composer.md#commontransactionparams) & \{ `assetId`: `bigint` } & [`ExecuteParams`](../interfaces/types_composer.ExecuteParams.md)) => `Promise`\<[`SendSingleTransactionResult`](../modules/types_algorand_client.md#sendsingletransactionresult)\> | - | | `assetFreeze` | (`params`: [`CommonTransactionParams`](../modules/types_composer.md#commontransactionparams) & \{ `account`: `string` ; `assetId`: `bigint` ; `frozen`: `boolean` } & [`ExecuteParams`](../interfaces/types_composer.ExecuteParams.md)) => `Promise`\<[`SendSingleTransactionResult`](../modules/types_algorand_client.md#sendsingletransactionresult)\> | - | | `assetOptIn` | (`params`: [`CommonTransactionParams`](../modules/types_composer.md#commontransactionparams) & \{ `assetId`: `bigint` } & [`ExecuteParams`](../interfaces/types_composer.ExecuteParams.md)) => `Promise`\<[`SendSingleTransactionResult`](../modules/types_algorand_client.md#sendsingletransactionresult)\> | - | @@ -150,11 +162,10 @@ Methods for sending a single transaction. | `methodCall` | (`params`: [`CommonTransactionParams`](../modules/types_composer.md#commontransactionparams) & `Omit`\<[`AppCallParams`](../modules/types_composer.md#appcallparams), ``"args"``\> & \{ `appId`: `bigint` ; `args?`: (`TransactionWithSigner` \| `Transaction` \| `ABIValue` \| `Promise`\<`Transaction`\> \| [`MethodCallParams`](../modules/types_composer.md#methodcallparams))[] ; `method`: `ABIMethod` } & [`ExecuteParams`](../interfaces/types_composer.ExecuteParams.md)) => `Promise`\<[`SendSingleTransactionResult`](../modules/types_algorand_client.md#sendsingletransactionresult)\> | - | | `onlineKeyRegistration` | (`params`: [`CommonTransactionParams`](../modules/types_composer.md#commontransactionparams) & \{ `selectionKey`: `Uint8Array` ; `stateProofKey?`: `Uint8Array` ; `voteFirst`: `bigint` ; `voteKey`: `Uint8Array` ; `voteKeyDilution`: `bigint` ; `voteLast`: `bigint` } & [`ExecuteParams`](../interfaces/types_composer.ExecuteParams.md)) => `Promise`\<[`SendSingleTransactionResult`](../modules/types_algorand_client.md#sendsingletransactionresult)\> | - | | `payment` | (`params`: [`CommonTransactionParams`](../modules/types_composer.md#commontransactionparams) & \{ `amount`: [`AlgoAmount`](types_amount.AlgoAmount.md) ; `closeRemainderTo?`: `string` ; `receiver`: `string` } & [`ExecuteParams`](../interfaces/types_composer.ExecuteParams.md)) => `Promise`\<[`SendSingleTransactionResult`](../modules/types_algorand_client.md#sendsingletransactionresult)\> | - | -| `rekey` | (`params`: [`CommonTransactionParams`](../modules/types_composer.md#commontransactionparams) & \{ `rekeyTo`: `string` } & [`ExecuteParams`](../interfaces/types_composer.ExecuteParams.md)) => `Promise`\<[`SendSingleTransactionResult`](../modules/types_algorand_client.md#sendsingletransactionresult)\> | - | #### Defined in -[src/types/algorand-client.ts:183](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/algorand-client.ts#L183) +[src/types/algorand-client.ts:191](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/algorand-client.ts#L191) ___ @@ -179,11 +190,10 @@ Methods for building transactions | `methodCall` | (`params`: [`MethodCallParams`](../modules/types_composer.md#methodcallparams)) => `Promise`\<`Transaction`[]\> | - | | `onlineKeyRegistration` | (`params`: [`OnlineKeyRegistrationParams`](../modules/types_composer.md#onlinekeyregistrationparams)) => `Promise`\<`Transaction`\> | - | | `payment` | (`params`: [`PaymentParams`](../modules/types_composer.md#paymentparams)) => `Promise`\<`Transaction`\> | - | -| `rekey` | (`params`: [`RekeyParams`](../modules/types_composer.md#rekeyparams)) => `Promise`\<`Transaction`\> | - | #### Defined in -[src/types/algorand-client.ts:370](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/algorand-client.ts#L370) +[src/types/algorand-client.ts:603](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/algorand-client.ts#L603) ## Accessors @@ -199,7 +209,23 @@ Get or create accounts that can sign transactions. #### Defined in -[src/types/algorand-client.ts:131](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/algorand-client.ts#L131) +[src/types/algorand-client.ts:134](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/algorand-client.ts#L134) + +___ + +### asset + +• `get` **asset**(): [`AssetManager`](types_asset_manager.AssetManager.md) + +Methods for interacting with assets. + +#### Returns + +[`AssetManager`](types_asset_manager.AssetManager.md) + +#### Defined in + +[src/types/algorand-client.ts:139](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/algorand-client.ts#L139) ___ @@ -215,7 +241,7 @@ Get clients, including algosdk clients and app clients. #### Defined in -[src/types/algorand-client.ts:126](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/algorand-client.ts#L126) +[src/types/algorand-client.ts:129](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/algorand-client.ts#L129) ## Methods @@ -256,7 +282,7 @@ Get clients, including algosdk clients and app clients. #### Defined in -[src/types/algorand-client.ts:145](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/algorand-client.ts#L145) +[src/types/algorand-client.ts:153](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/algorand-client.ts#L153) ___ @@ -294,7 +320,7 @@ ___ #### Defined in -[src/types/algorand-client.ts:359](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/algorand-client.ts#L359) +[src/types/algorand-client.ts:592](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/algorand-client.ts#L592) ___ @@ -310,7 +336,7 @@ Get suggested params for a transaction (either cached or from algod if the cache #### Defined in -[src/types/algorand-client.ts:110](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/algorand-client.ts#L110) +[src/types/algorand-client.ts:113](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/algorand-client.ts#L113) ___ @@ -326,7 +352,7 @@ Start a new `AlgokitComposer` transaction group #### Defined in -[src/types/algorand-client.ts:136](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/algorand-client.ts#L136) +[src/types/algorand-client.ts:144](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/algorand-client.ts#L144) ___ @@ -350,7 +376,7 @@ The `AlgorandClient` so method calls can be chained #### Defined in -[src/types/algorand-client.ts:49](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/algorand-client.ts#L49) +[src/types/algorand-client.ts:52](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/algorand-client.ts#L52) ___ @@ -374,7 +400,7 @@ The `AlgorandClient` so method calls can be chained #### Defined in -[src/types/algorand-client.ts:39](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/algorand-client.ts#L39) +[src/types/algorand-client.ts:42](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/algorand-client.ts#L42) ___ @@ -399,7 +425,7 @@ The `AlgorandClient` so method calls can be chained #### Defined in -[src/types/algorand-client.ts:82](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/algorand-client.ts#L82) +[src/types/algorand-client.ts:85](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/algorand-client.ts#L85) ___ @@ -434,7 +460,7 @@ const accountManager = AlgorandClient.mainnet() #### Defined in -[src/types/algorand-client.ts:69](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/algorand-client.ts#L69) +[src/types/algorand-client.ts:72](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/algorand-client.ts#L72) ___ @@ -459,7 +485,7 @@ The `AlgorandClient` so method calls can be chained #### Defined in -[src/types/algorand-client.ts:93](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/algorand-client.ts#L93) +[src/types/algorand-client.ts:96](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/algorand-client.ts#L96) ___ @@ -483,7 +509,7 @@ The `AlgorandClient` so method calls can be chained #### Defined in -[src/types/algorand-client.ts:104](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/algorand-client.ts#L104) +[src/types/algorand-client.ts:107](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/algorand-client.ts#L107) ___ @@ -501,7 +527,7 @@ The `AlgorandClient` #### Defined in -[src/types/algorand-client.ts:465](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/algorand-client.ts#L465) +[src/types/algorand-client.ts:889](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/algorand-client.ts#L889) ___ @@ -525,7 +551,7 @@ The `AlgorandClient` #### Defined in -[src/types/algorand-client.ts:502](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/algorand-client.ts#L502) +[src/types/algorand-client.ts:926](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/algorand-client.ts#L926) ___ @@ -549,7 +575,7 @@ The `AlgorandClient` #### Defined in -[src/types/algorand-client.ts:532](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/algorand-client.ts#L532) +[src/types/algorand-client.ts:956](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/algorand-client.ts#L956) ___ @@ -580,7 +606,7 @@ The `AlgorandClient` #### Defined in -[src/types/algorand-client.ts:523](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/algorand-client.ts#L523) +[src/types/algorand-client.ts:947](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/algorand-client.ts#L947) ___ @@ -598,7 +624,7 @@ The `AlgorandClient` #### Defined in -[src/types/algorand-client.ts:489](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/algorand-client.ts#L489) +[src/types/algorand-client.ts:913](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/algorand-client.ts#L913) ___ @@ -616,4 +642,4 @@ The `AlgorandClient` #### Defined in -[src/types/algorand-client.ts:477](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/algorand-client.ts#L477) +[src/types/algorand-client.ts:901](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/algorand-client.ts#L901) diff --git a/docs/code/classes/types_client_manager.ClientManager.md b/docs/code/classes/types_client_manager.ClientManager.md index e7f85f72..b52c1e61 100644 --- a/docs/code/classes/types_client_manager.ClientManager.md +++ b/docs/code/classes/types_client_manager.ClientManager.md @@ -334,9 +334,28 @@ Returns a new typed client, resolving the app by creator address and name. The typed client instance +**`Example`** + +```typescript +const appClient = algorand.client.getTypedAppClientByCreatorAndName(MyContractClient, { + creatorAddress: "CREATORADDRESS", + sender: alice, +}) +``` + +**`Example`** + +```typescript +const appClient = algorand.client.getTypedAppClientByCreatorAndName(MyContractClient, { + creatorAddress: "CREATORADDRESS", + name: "contract-name", + sender: alice, +}) +``` + #### Defined in -[src/types/client-manager.ts:227](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/client-manager.ts#L227) +[src/types/client-manager.ts:242](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/client-manager.ts#L242) ___ @@ -365,9 +384,18 @@ Returns a new typed client, resolving the app by app ID. The typed client instance +**`Example`** + +```typescript +const appClient = algorand.client.getTypedAppClientById(MyContractClient, { + id: 12345, + sender: alice, +}) +``` + #### Defined in -[src/types/client-manager.ts:241](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/client-manager.ts#L241) +[src/types/client-manager.ts:263](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/client-manager.ts#L263) ___ @@ -493,7 +521,7 @@ Returns the Algorand configuration to point to the free tier of the AlgoNode ser #### Defined in -[src/types/client-manager.ts:333](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/client-manager.ts#L333) +[src/types/client-manager.ts:355](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/client-manager.ts#L355) ___ @@ -536,7 +564,7 @@ Returns an algod SDK client that automatically retries on idempotent calls. #### Defined in -[src/types/client-manager.ts:372](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/client-manager.ts#L372) +[src/types/client-manager.ts:394](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/client-manager.ts#L394) ___ @@ -560,7 +588,7 @@ Returns an algod SDK client that automatically retries on idempotent calls loade #### Defined in -[src/types/client-manager.ts:389](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/client-manager.ts#L389) +[src/types/client-manager.ts:411](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/client-manager.ts#L411) ___ @@ -578,7 +606,7 @@ Expects `process.env.ALGOD_SERVER` to be defined, and you can also specify `proc #### Defined in -[src/types/client-manager.ts:291](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/client-manager.ts#L291) +[src/types/client-manager.ts:313](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/client-manager.ts#L313) ___ @@ -611,7 +639,7 @@ const config = ClientManager.getConfigFromEnvironmentOrLocalNet() #### Defined in -[src/types/client-manager.ts:262](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/client-manager.ts#L262) +[src/types/client-manager.ts:284](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/client-manager.ts#L284) ___ @@ -633,7 +661,7 @@ Returns the Algorand configuration to point to the default LocalNet. #### Defined in -[src/types/client-manager.ts:344](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/client-manager.ts#L344) +[src/types/client-manager.ts:366](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/client-manager.ts#L366) ___ @@ -683,7 +711,7 @@ Returns an indexer SDK client that automatically retries on idempotent calls #### Defined in -[src/types/client-manager.ts:418](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/client-manager.ts#L418) +[src/types/client-manager.ts:440](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/client-manager.ts#L440) ___ @@ -713,7 +741,7 @@ Returns an indexer SDK client that automatically retries on idempotent calls loa #### Defined in -[src/types/client-manager.ts:440](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/client-manager.ts#L440) +[src/types/client-manager.ts:462](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/client-manager.ts#L462) ___ @@ -731,7 +759,7 @@ Expects `process.env.INDEXER_SERVER` to be defined, and you can also specify `pr #### Defined in -[src/types/client-manager.ts:312](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/client-manager.ts#L312) +[src/types/client-manager.ts:334](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/client-manager.ts#L334) ___ @@ -761,7 +789,7 @@ KMD client allows you to export private keys, which is useful to (for instance) #### Defined in -[src/types/client-manager.ts:455](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/client-manager.ts#L455) +[src/types/client-manager.ts:477](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/client-manager.ts#L477) ___ @@ -784,4 +812,4 @@ Returns a KMD SDK client that automatically retries on idempotent calls loaded f #### Defined in -[src/types/client-manager.ts:469](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/client-manager.ts#L469) +[src/types/client-manager.ts:491](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/client-manager.ts#L491) diff --git a/docs/code/classes/types_composer.default.md b/docs/code/classes/types_composer.default.md index 862437c2..6d7620e1 100644 --- a/docs/code/classes/types_composer.default.md +++ b/docs/code/classes/types_composer.default.md @@ -39,7 +39,6 @@ Note: this class is a new Beta feature and may be subject to change. - [addMethodCall](types_composer.default.md#addmethodcall) - [addOnlineKeyRegistration](types_composer.default.md#addonlinekeyregistration) - [addPayment](types_composer.default.md#addpayment) -- [addRekey](types_composer.default.md#addrekey) - [build](types_composer.default.md#build) - [buildAppCall](types_composer.default.md#buildappcall) - [buildAssetConfig](types_composer.default.md#buildassetconfig) @@ -76,7 +75,7 @@ Create an `AlgoKitComposer`. #### Defined in -[src/types/composer.ts:386](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/composer.ts#L386) +[src/types/composer.ts:436](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/composer.ts#L436) ## Properties @@ -88,7 +87,7 @@ The algod client used by the composer. #### Defined in -[src/types/composer.ts:368](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/composer.ts#L368) +[src/types/composer.ts:418](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/composer.ts#L418) ___ @@ -100,7 +99,7 @@ The ATC used to compose the group #### Defined in -[src/types/composer.ts:359](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/composer.ts#L359) +[src/types/composer.ts:409](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/composer.ts#L409) ___ @@ -112,7 +111,7 @@ The default transaction validity window #### Defined in -[src/types/composer.ts:377](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/composer.ts#L377) +[src/types/composer.ts:427](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/composer.ts#L427) ___ @@ -124,7 +123,7 @@ Whether the validity window was explicitly set on construction #### Defined in -[src/types/composer.ts:380](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/composer.ts#L380) +[src/types/composer.ts:430](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/composer.ts#L430) ___ @@ -150,7 +149,7 @@ A function that takes in an address and return a signer function for that addres #### Defined in -[src/types/composer.ts:374](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/composer.ts#L374) +[src/types/composer.ts:424](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/composer.ts#L424) ___ @@ -170,7 +169,7 @@ An async function that will return suggestedParams. #### Defined in -[src/types/composer.ts:371](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/composer.ts#L371) +[src/types/composer.ts:421](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/composer.ts#L421) ___ @@ -182,7 +181,7 @@ Map of txid to ABI method #### Defined in -[src/types/composer.ts:362](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/composer.ts#L362) +[src/types/composer.ts:412](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/composer.ts#L412) ___ @@ -194,7 +193,7 @@ Transactions that have not yet been composed #### Defined in -[src/types/composer.ts:365](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/composer.ts#L365) +[src/types/composer.ts:415](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/composer.ts#L415) ## Methods @@ -220,7 +219,7 @@ The composer so you can chain method calls #### Defined in -[src/types/composer.ts:503](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/composer.ts#L503) +[src/types/composer.ts:540](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/composer.ts#L540) ___ @@ -244,7 +243,7 @@ The composer so you can chain method calls #### Defined in -[src/types/composer.ts:435](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/composer.ts#L435) +[src/types/composer.ts:472](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/composer.ts#L472) ___ @@ -268,7 +267,7 @@ The composer so you can chain method calls #### Defined in -[src/types/composer.ts:424](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/composer.ts#L424) +[src/types/composer.ts:461](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/composer.ts#L461) ___ @@ -292,7 +291,7 @@ The composer so you can chain method calls #### Defined in -[src/types/composer.ts:457](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/composer.ts#L457) +[src/types/composer.ts:494](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/composer.ts#L494) ___ @@ -316,7 +315,7 @@ The composer so you can chain method calls #### Defined in -[src/types/composer.ts:446](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/composer.ts#L446) +[src/types/composer.ts:483](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/composer.ts#L483) ___ @@ -340,7 +339,7 @@ The composer so you can chain method calls #### Defined in -[src/types/composer.ts:479](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/composer.ts#L479) +[src/types/composer.ts:516](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/composer.ts#L516) ___ @@ -364,7 +363,7 @@ The composer so you can chain method calls #### Defined in -[src/types/composer.ts:490](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/composer.ts#L490) +[src/types/composer.ts:527](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/composer.ts#L527) ___ @@ -388,7 +387,7 @@ The composer so you can chain method calls #### Defined in -[src/types/composer.ts:468](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/composer.ts#L468) +[src/types/composer.ts:505](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/composer.ts#L505) ___ @@ -412,7 +411,7 @@ The composer so you can chain method calls #### Defined in -[src/types/composer.ts:537](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/composer.ts#L537) +[src/types/composer.ts:574](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/composer.ts#L574) ___ @@ -438,7 +437,7 @@ The composer so you can chain method calls #### Defined in -[src/types/composer.ts:516](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/composer.ts#L516) +[src/types/composer.ts:553](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/composer.ts#L553) ___ @@ -462,7 +461,7 @@ The composer so you can chain method calls #### Defined in -[src/types/composer.ts:526](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/composer.ts#L526) +[src/types/composer.ts:563](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/composer.ts#L563) ___ @@ -472,8 +471,6 @@ ___ Add a payment transaction to the transaction group. -**Warning:** Please be careful with this parameter and be sure to read the [official rekey guidance](https://developer.algorand.org/docs/get-details/accounts/rekey/). - #### Parameters | Name | Type | Description | @@ -488,31 +485,7 @@ The composer so you can chain method calls #### Defined in -[src/types/composer.ts:402](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/composer.ts#L402) - -___ - -### addRekey - -▸ **addRekey**(`params`): [`default`](types_composer.default.md) - -Add a rekey transaction to the transaction group. - -#### Parameters - -| Name | Type | Description | -| :------ | :------ | :------ | -| `params` | [`RekeyParams`](../modules/types_composer.md#rekeyparams) | The rekey transaction parameters | - -#### Returns - -[`default`](types_composer.default.md) - -The composer so you can chain method calls - -#### Defined in - -[src/types/composer.ts:413](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/composer.ts#L413) +[src/types/composer.ts:450](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/composer.ts#L450) ___ @@ -532,7 +505,7 @@ The built atomic transaction composer and the transactions #### Defined in -[src/types/composer.ts:886](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/composer.ts#L886) +[src/types/composer.ts:919](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/composer.ts#L919) ___ @@ -553,7 +526,7 @@ ___ #### Defined in -[src/types/composer.ts:754](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/composer.ts#L754) +[src/types/composer.ts:791](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/composer.ts#L791) ___ @@ -574,7 +547,7 @@ ___ #### Defined in -[src/types/composer.ts:703](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/composer.ts#L703) +[src/types/composer.ts:740](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/composer.ts#L740) ___ @@ -595,7 +568,7 @@ ___ #### Defined in -[src/types/composer.ts:683](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/composer.ts#L683) +[src/types/composer.ts:720](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/composer.ts#L720) ___ @@ -616,7 +589,7 @@ ___ #### Defined in -[src/types/composer.ts:718](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/composer.ts#L718) +[src/types/composer.ts:755](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/composer.ts#L755) ___ @@ -637,7 +610,7 @@ ___ #### Defined in -[src/types/composer.ts:728](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/composer.ts#L728) +[src/types/composer.ts:765](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/composer.ts#L765) ___ @@ -658,7 +631,7 @@ ___ #### Defined in -[src/types/composer.ts:740](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/composer.ts#L740) +[src/types/composer.ts:777](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/composer.ts#L777) ___ @@ -678,7 +651,7 @@ ___ #### Defined in -[src/types/composer.ts:542](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/composer.ts#L542) +[src/types/composer.ts:579](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/composer.ts#L579) ___ @@ -699,7 +672,7 @@ ___ #### Defined in -[src/types/composer.ts:794](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/composer.ts#L794) +[src/types/composer.ts:831](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/composer.ts#L831) ___ @@ -720,7 +693,7 @@ ___ #### Defined in -[src/types/composer.ts:597](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/composer.ts#L597) +[src/types/composer.ts:634](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/composer.ts#L634) ___ @@ -741,7 +714,7 @@ ___ #### Defined in -[src/types/composer.ts:671](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/composer.ts#L671) +[src/types/composer.ts:708](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/composer.ts#L708) ___ @@ -762,7 +735,7 @@ ___ #### Defined in -[src/types/composer.ts:812](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/composer.ts#L812) +[src/types/composer.ts:849](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/composer.ts#L849) ___ @@ -784,7 +757,7 @@ ___ #### Defined in -[src/types/composer.ts:556](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/composer.ts#L556) +[src/types/composer.ts:593](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/composer.ts#L593) ___ @@ -808,7 +781,7 @@ The execution result #### Defined in -[src/types/composer.ts:928](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/composer.ts#L928) +[src/types/composer.ts:961](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/composer.ts#L961) ___ @@ -827,4 +800,4 @@ The newly built atomic transaction composer and the transactions #### Defined in -[src/types/composer.ts:918](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/composer.ts#L918) +[src/types/composer.ts:951](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/composer.ts#L951) diff --git a/docs/code/classes/types_dispenser_client.TestNetDispenserApiClient.md b/docs/code/classes/types_dispenser_client.TestNetDispenserApiClient.md index 8527f982..7d4278c3 100644 --- a/docs/code/classes/types_dispenser_client.TestNetDispenserApiClient.md +++ b/docs/code/classes/types_dispenser_client.TestNetDispenserApiClient.md @@ -78,7 +78,7 @@ If neither the environment variable 'ALGOKIT_DISPENSER_ACCESS_TOKEN' nor the aut #### Defined in -[src/types/dispenser-client.ts:61](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/dispenser-client.ts#L61) +[src/types/dispenser-client.ts:69](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/dispenser-client.ts#L69) ## Properties @@ -88,7 +88,7 @@ If neither the environment variable 'ALGOKIT_DISPENSER_ACCESS_TOKEN' nor the aut #### Defined in -[src/types/dispenser-client.ts:58](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/dispenser-client.ts#L58) +[src/types/dispenser-client.ts:66](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/dispenser-client.ts#L66) ___ @@ -98,7 +98,7 @@ ___ #### Defined in -[src/types/dispenser-client.ts:59](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/dispenser-client.ts#L59) +[src/types/dispenser-client.ts:67](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/dispenser-client.ts#L67) ## Accessors @@ -114,7 +114,7 @@ The authentication token used for API requests. #### Defined in -[src/types/dispenser-client.ts:77](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/dispenser-client.ts#L77) +[src/types/dispenser-client.ts:85](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/dispenser-client.ts#L85) ___ @@ -130,7 +130,7 @@ The timeout for API requests, in seconds. #### Defined in -[src/types/dispenser-client.ts:81](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/dispenser-client.ts#L81) +[src/types/dispenser-client.ts:89](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/dispenser-client.ts#L89) ## Methods @@ -155,7 +155,7 @@ DispenserFundResponse: An object containing the transaction ID and funded amount #### Defined in -[src/types/dispenser-client.ts:142](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/dispenser-client.ts#L142) +[src/types/dispenser-client.ts:150](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/dispenser-client.ts#L150) ___ @@ -173,7 +173,7 @@ DispenserLimitResponse: An object containing the funding limit amount. #### Defined in -[src/types/dispenser-client.ts:168](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/dispenser-client.ts#L168) +[src/types/dispenser-client.ts:176](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/dispenser-client.ts#L176) ___ @@ -200,7 +200,7 @@ The API response. #### Defined in -[src/types/dispenser-client.ts:95](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/dispenser-client.ts#L95) +[src/types/dispenser-client.ts:103](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/dispenser-client.ts#L103) ___ @@ -222,4 +222,4 @@ Sends a refund request to the dispenser API for the specified refundTxnId. #### Defined in -[src/types/dispenser-client.ts:159](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/dispenser-client.ts#L159) +[src/types/dispenser-client.ts:167](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/dispenser-client.ts#L167) diff --git a/docs/code/interfaces/types_account.AccountConfig.md b/docs/code/interfaces/types_account.AccountConfig.md index 380701c9..25cdb953 100644 --- a/docs/code/interfaces/types_account.AccountConfig.md +++ b/docs/code/interfaces/types_account.AccountConfig.md @@ -28,7 +28,7 @@ Mnemonic for an account #### Defined in -[src/types/account.ts:140](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/account.ts#L140) +[src/types/account.ts:279](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/account.ts#L279) ___ @@ -40,7 +40,7 @@ Account name used to retrieve config #### Defined in -[src/types/account.ts:144](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/account.ts#L144) +[src/types/account.ts:283](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/account.ts#L283) ___ @@ -52,7 +52,7 @@ Address of a rekeyed account #### Defined in -[src/types/account.ts:142](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/account.ts#L142) +[src/types/account.ts:281](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/account.ts#L281) ___ @@ -66,4 +66,4 @@ Renamed to senderAddress in 2.3.1 #### Defined in -[src/types/account.ts:147](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/account.ts#L147) +[src/types/account.ts:286](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/account.ts#L286) diff --git a/docs/code/interfaces/types_account.TransactionSignerAccount.md b/docs/code/interfaces/types_account.TransactionSignerAccount.md index 469aaecd..526efb46 100644 --- a/docs/code/interfaces/types_account.TransactionSignerAccount.md +++ b/docs/code/interfaces/types_account.TransactionSignerAccount.md @@ -21,7 +21,7 @@ A wrapper around `TransactionSigner` that also has the sender address. #### Defined in -[src/types/account.ts:114](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/account.ts#L114) +[src/types/account.ts:120](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/account.ts#L120) ___ @@ -31,4 +31,4 @@ ___ #### Defined in -[src/types/account.ts:115](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/account.ts#L115) +[src/types/account.ts:121](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/account.ts#L121) diff --git a/docs/code/interfaces/types_account_manager.BulkAssetOptInOutResult.md b/docs/code/interfaces/types_account_manager.BulkAssetOptInOutResult.md index b8916474..ede8d762 100644 --- a/docs/code/interfaces/types_account_manager.BulkAssetOptInOutResult.md +++ b/docs/code/interfaces/types_account_manager.BulkAssetOptInOutResult.md @@ -23,7 +23,7 @@ The ID of the asset opted into / out of #### Defined in -[src/types/account-manager.ts:19](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/account-manager.ts#L19) +[src/types/account-manager.ts:27](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/account-manager.ts#L27) ___ @@ -35,4 +35,4 @@ The transaction ID of the resulting opt in / out #### Defined in -[src/types/account-manager.ts:21](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/account-manager.ts#L21) +[src/types/account-manager.ts:29](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/account-manager.ts#L29) diff --git a/docs/code/interfaces/types_account_manager.EnsureFundedResult.md b/docs/code/interfaces/types_account_manager.EnsureFundedResult.md index 9fd726e3..739afab5 100644 --- a/docs/code/interfaces/types_account_manager.EnsureFundedResult.md +++ b/docs/code/interfaces/types_account_manager.EnsureFundedResult.md @@ -23,7 +23,7 @@ The amount that was sent to the account. #### Defined in -[src/types/account-manager.ts:29](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/account-manager.ts#L29) +[src/types/account-manager.ts:37](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/account-manager.ts#L37) ___ @@ -35,4 +35,4 @@ The transaction ID of the transaction that funded the account. #### Defined in -[src/types/account-manager.ts:27](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/account-manager.ts#L27) +[src/types/account-manager.ts:35](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/account-manager.ts#L35) diff --git a/docs/code/interfaces/types_asset.AssetBulkOptInOutParams.md b/docs/code/interfaces/types_asset.AssetBulkOptInOutParams.md index 1ff02635..cb99c97a 100644 --- a/docs/code/interfaces/types_asset.AssetBulkOptInOutParams.md +++ b/docs/code/interfaces/types_asset.AssetBulkOptInOutParams.md @@ -4,6 +4,8 @@ [types/asset](../modules/types_asset.md).AssetBulkOptInOutParams +**`Deprecated`** + Parameters for `assetBulkOptIn` / `assetBulkOptOut` call. ## Table of contents diff --git a/docs/code/interfaces/types_asset.AssetOptInParams.md b/docs/code/interfaces/types_asset.AssetOptInParams.md index 712bd67b..1c72d40b 100644 --- a/docs/code/interfaces/types_asset.AssetOptInParams.md +++ b/docs/code/interfaces/types_asset.AssetOptInParams.md @@ -4,6 +4,8 @@ [types/asset](../modules/types_asset.md).AssetOptInParams +**`Deprecated`** + Parameters for `assetOptIn` call. ## Hierarchy diff --git a/docs/code/interfaces/types_asset.AssetOptOutParams.md b/docs/code/interfaces/types_asset.AssetOptOutParams.md index c79bacfa..550a3e01 100644 --- a/docs/code/interfaces/types_asset.AssetOptOutParams.md +++ b/docs/code/interfaces/types_asset.AssetOptOutParams.md @@ -4,6 +4,8 @@ [types/asset](../modules/types_asset.md).AssetOptOutParams +**`Deprecated`** + Parameters for `assetOptOut` call. ## Hierarchy diff --git a/docs/code/interfaces/types_asset.CreateAssetParams.md b/docs/code/interfaces/types_asset.CreateAssetParams.md index efddbc12..75436a7f 100644 --- a/docs/code/interfaces/types_asset.CreateAssetParams.md +++ b/docs/code/interfaces/types_asset.CreateAssetParams.md @@ -4,6 +4,8 @@ [types/asset](../modules/types_asset.md).CreateAssetParams +**`Deprecated`** + Parameters for `createAsset` call. ## Hierarchy diff --git a/docs/code/interfaces/types_client_manager.TypedAppClient.md b/docs/code/interfaces/types_client_manager.TypedAppClient.md index b5bbd5e7..5eedb0cf 100644 --- a/docs/code/interfaces/types_client_manager.TypedAppClient.md +++ b/docs/code/interfaces/types_client_manager.TypedAppClient.md @@ -37,4 +37,4 @@ Interface to identify a typed client that can be used to interact with an applic #### Defined in -[src/types/client-manager.ts:480](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/client-manager.ts#L480) +[src/types/client-manager.ts:502](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/client-manager.ts#L502) diff --git a/docs/code/interfaces/types_composer.ExecuteParams.md b/docs/code/interfaces/types_composer.ExecuteParams.md index a179cce0..e5e65478 100644 --- a/docs/code/interfaces/types_composer.ExecuteParams.md +++ b/docs/code/interfaces/types_composer.ExecuteParams.md @@ -23,7 +23,7 @@ The number of rounds to wait for confirmation. By default until the latest lastV #### Defined in -[src/types/composer.ts:332](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/composer.ts#L332) +[src/types/composer.ts:382](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/composer.ts#L382) ___ @@ -31,8 +31,8 @@ ___ • `Optional` **suppressLog**: `boolean` -Whether to suppress log messages from transaction send, default: do not suppress +Whether to suppress log messages from transaction send, default: do not suppress. #### Defined in -[src/types/composer.ts:334](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/composer.ts#L334) +[src/types/composer.ts:384](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/composer.ts#L384) diff --git a/docs/code/interfaces/types_dispenser_client.DispenserFundResponse.md b/docs/code/interfaces/types_dispenser_client.DispenserFundResponse.md index f85c8e6f..e4cfe99d 100644 --- a/docs/code/interfaces/types_dispenser_client.DispenserFundResponse.md +++ b/docs/code/interfaces/types_dispenser_client.DispenserFundResponse.md @@ -4,6 +4,8 @@ [types/dispenser-client](../modules/types_dispenser_client.md).DispenserFundResponse +The TestNet Dispenser API response when funding. + ## Table of contents ### Properties @@ -17,9 +19,11 @@ • **amount**: `number` +The number of microAlgos that was funded. + #### Defined in -[src/types/dispenser-client.ts:19](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/dispenser-client.ts#L19) +[src/types/dispenser-client.ts:22](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/dispenser-client.ts#L22) ___ @@ -27,6 +31,8 @@ ___ • **txId**: `string` +The ID of the transaction that was issued to fund the account. + #### Defined in -[src/types/dispenser-client.ts:18](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/dispenser-client.ts#L18) +[src/types/dispenser-client.ts:20](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/dispenser-client.ts#L20) diff --git a/docs/code/interfaces/types_dispenser_client.DispenserLimitResponse.md b/docs/code/interfaces/types_dispenser_client.DispenserLimitResponse.md index 6e286f73..c925298f 100644 --- a/docs/code/interfaces/types_dispenser_client.DispenserLimitResponse.md +++ b/docs/code/interfaces/types_dispenser_client.DispenserLimitResponse.md @@ -4,6 +4,8 @@ [types/dispenser-client](../modules/types_dispenser_client.md).DispenserLimitResponse +The TestNet Dispenser API response when getting the current limit. + ## Table of contents ### Properties @@ -16,6 +18,8 @@ • **amount**: `number` +The limit, in microAlgos, that you can currently fund. + #### Defined in -[src/types/dispenser-client.ts:23](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/dispenser-client.ts#L23) +[src/types/dispenser-client.ts:28](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/dispenser-client.ts#L28) diff --git a/docs/code/interfaces/types_dispenser_client.TestNetDispenserApiClientParams.md b/docs/code/interfaces/types_dispenser_client.TestNetDispenserApiClientParams.md index 70981be3..51b1fd92 100644 --- a/docs/code/interfaces/types_dispenser_client.TestNetDispenserApiClientParams.md +++ b/docs/code/interfaces/types_dispenser_client.TestNetDispenserApiClientParams.md @@ -4,6 +4,8 @@ [types/dispenser-client](../modules/types_dispenser_client.md).TestNetDispenserApiClientParams +The parameters to construct a TestNet Dispenser API client. + ## Table of contents ### Properties @@ -17,9 +19,11 @@ • **authToken**: `string` +The API auth token + #### Defined in -[src/types/dispenser-client.ts:27](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/dispenser-client.ts#L27) +[src/types/dispenser-client.ts:34](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/dispenser-client.ts#L34) ___ @@ -27,6 +31,8 @@ ___ • `Optional` **requestTimeout**: `number` +The request timeout in seconds + #### Defined in -[src/types/dispenser-client.ts:28](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/dispenser-client.ts#L28) +[src/types/dispenser-client.ts:36](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/dispenser-client.ts#L36) diff --git a/docs/code/interfaces/types_testing.AlgorandFixtureConfig.md b/docs/code/interfaces/types_testing.AlgorandFixtureConfig.md index 483a5f43..72bc5149 100644 --- a/docs/code/interfaces/types_testing.AlgorandFixtureConfig.md +++ b/docs/code/interfaces/types_testing.AlgorandFixtureConfig.md @@ -142,7 +142,7 @@ ___ • `Optional` **testAccountFunding**: [`AlgoAmount`](../classes/types_amount.AlgoAmount.md) -The amount of funds to allocate to the default testing account, if not specified then it will get 10 ALGOs. +The amount of funds to allocate to the default testing account, if not specified then it will get 10 Algos. #### Defined in diff --git a/docs/code/interfaces/types_transfer.AlgoRekeyParams.md b/docs/code/interfaces/types_transfer.AlgoRekeyParams.md index a32e4848..473f5dce 100644 --- a/docs/code/interfaces/types_transfer.AlgoRekeyParams.md +++ b/docs/code/interfaces/types_transfer.AlgoRekeyParams.md @@ -4,6 +4,8 @@ [types/transfer](../modules/types_transfer.md).AlgoRekeyParams +**`Deprecated`** + Parameters for `rekeyAccount` call. ## Hierarchy diff --git a/docs/code/interfaces/types_transfer.AlgoTransferParams.md b/docs/code/interfaces/types_transfer.AlgoTransferParams.md index f0a934f6..d64a0788 100644 --- a/docs/code/interfaces/types_transfer.AlgoTransferParams.md +++ b/docs/code/interfaces/types_transfer.AlgoTransferParams.md @@ -4,6 +4,8 @@ [types/transfer](../modules/types_transfer.md).AlgoTransferParams +**`Deprecated`** + Parameters for `transferAlgos` call. ## Hierarchy @@ -81,7 +83,7 @@ ___ • **from**: [`SendTransactionFrom`](../modules/types_transaction.md#sendtransactionfrom) -The account that will send the ALGOs +The account that will send the Algos #### Defined in @@ -214,7 +216,7 @@ ___ • **to**: `string` \| [`SendTransactionFrom`](../modules/types_transaction.md#sendtransactionfrom) -The account / account address that will receive the ALGOs +The account / account address that will receive the Algos #### Defined in diff --git a/docs/code/interfaces/types_transfer.EnsureFundedParams.md b/docs/code/interfaces/types_transfer.EnsureFundedParams.md index 27559ebd..23bb6326 100644 --- a/docs/code/interfaces/types_transfer.EnsureFundedParams.md +++ b/docs/code/interfaces/types_transfer.EnsureFundedParams.md @@ -4,6 +4,8 @@ [types/transfer](../modules/types_transfer.md).EnsureFundedParams +**`Deprecated`** + Parameters for `ensureFunded` call. ## Hierarchy @@ -150,7 +152,7 @@ ___ • **minSpendingBalance**: [`AlgoAmount`](../classes/types_amount.AlgoAmount.md) -The minimum balance of ALGOs that the account should have available to spend (i.e. on top of minimum balance requirement) +The minimum balance of Algos that the account should have available to spend (i.e. on top of minimum balance requirement) #### Defined in diff --git a/docs/code/interfaces/types_transfer.EnsureFundedReturnType.md b/docs/code/interfaces/types_transfer.EnsureFundedReturnType.md index e425b9fc..f60f3258 100644 --- a/docs/code/interfaces/types_transfer.EnsureFundedReturnType.md +++ b/docs/code/interfaces/types_transfer.EnsureFundedReturnType.md @@ -4,6 +4,8 @@ [types/transfer](../modules/types_transfer.md).EnsureFundedReturnType +**`Deprecated`** + ## Table of contents ### Properties @@ -21,7 +23,7 @@ The response if the transaction was sent and waited for #### Defined in -[src/types/transfer.ts:79](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/transfer.ts#L79) +[src/types/transfer.ts:80](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/transfer.ts#L80) ___ @@ -33,4 +35,4 @@ The transaction #### Defined in -[src/types/transfer.ts:77](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/transfer.ts#L77) +[src/types/transfer.ts:78](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/transfer.ts#L78) diff --git a/docs/code/interfaces/types_transfer.TransferAssetParams.md b/docs/code/interfaces/types_transfer.TransferAssetParams.md index f8358eb5..b202fda4 100644 --- a/docs/code/interfaces/types_transfer.TransferAssetParams.md +++ b/docs/code/interfaces/types_transfer.TransferAssetParams.md @@ -4,6 +4,8 @@ [types/transfer](../modules/types_transfer.md).TransferAssetParams +**`Deprecated`** + Parameters for `transferAsset` call. ## Hierarchy diff --git a/docs/code/modules/index.md b/docs/code/modules/index.md index 08b01a6a..dd20df80 100644 --- a/docs/code/modules/index.md +++ b/docs/code/modules/index.md @@ -7,6 +7,20 @@ ### References - [AlgorandClient](index.md#algorandclient) +- [executePaginatedRequest](index.md#executepaginatedrequest) +- [lookupAccountByAddress](index.md#lookupaccountbyaddress) +- [lookupAccountCreatedApplicationByAddress](index.md#lookupaccountcreatedapplicationbyaddress) +- [lookupAssetHoldings](index.md#lookupassetholdings) +- [lookupTransactionById](index.md#lookuptransactionbyid) +- [searchTransactions](index.md#searchtransactions) + +### Namespaces + +- [indexer](index.indexer.md) + +### Type Aliases + +- [AccountInformation](index.md#accountinformation) ### Variables @@ -33,7 +47,6 @@ - [encodeLease](index.md#encodelease) - [encodeTransactionNote](index.md#encodetransactionnote) - [ensureFunded](index.md#ensurefunded) -- [executePaginatedRequest](index.md#executepaginatedrequest) - [getABIMethodSignature](index.md#getabimethodsignature) - [getABIReturn](index.md#getabireturn) - [getAccount](index.md#getaccount) @@ -81,10 +94,6 @@ - [isMainNet](index.md#ismainnet) - [isSchemaIsBroken](index.md#isschemaisbroken) - [isTestNet](index.md#istestnet) -- [lookupAccountByAddress](index.md#lookupaccountbyaddress) -- [lookupAccountCreatedApplicationByAddress](index.md#lookupaccountcreatedapplicationbyaddress) -- [lookupAssetHoldings](index.md#lookupassetholdings) -- [lookupTransactionById](index.md#lookuptransactionbyid) - [microAlgos](index.md#microalgos) - [mnemonicAccount](index.md#mnemonicaccount) - [mnemonicAccountFromEnvironment](index.md#mnemonicaccountfromenvironment) @@ -99,7 +108,6 @@ - [rekeyAccount](index.md#rekeyaccount) - [rekeyedAccount](index.md#rekeyedaccount) - [replaceDeployTimeControlParams](index.md#replacedeploytimecontrolparams) -- [searchTransactions](index.md#searchtransactions) - [sendAtomicTransactionComposer](index.md#sendatomictransactioncomposer) - [sendGroupOfTransactions](index.md#sendgroupoftransactions) - [sendTransaction](index.md#sendtransaction) @@ -119,6 +127,56 @@ Re-exports [AlgorandClient](../classes/types_algorand_client.AlgorandClient.md) +___ + +### executePaginatedRequest + +Re-exports [executePaginatedRequest](index.indexer.md#executepaginatedrequest) + +___ + +### lookupAccountByAddress + +Re-exports [lookupAccountByAddress](index.indexer.md#lookupaccountbyaddress) + +___ + +### lookupAccountCreatedApplicationByAddress + +Re-exports [lookupAccountCreatedApplicationByAddress](index.indexer.md#lookupaccountcreatedapplicationbyaddress) + +___ + +### lookupAssetHoldings + +Re-exports [lookupAssetHoldings](index.indexer.md#lookupassetholdings) + +___ + +### lookupTransactionById + +Re-exports [lookupTransactionById](index.indexer.md#lookuptransactionbyid) + +___ + +### searchTransactions + +Re-exports [searchTransactions](index.indexer.md#searchtransactions) + +## Type Aliases + +### AccountInformation + +Ƭ **AccountInformation**: `Omit`\<`NumberConverter`\<`AccountInformationModel`\>, ``"get_obj_for_encoding"``\> + +**`Deprecated`** + +Account information at a given round. + +#### Defined in + +[src/account/account.ts:134](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/account/account.ts#L134) + ## Variables ### Config @@ -189,8 +247,6 @@ ___ ▸ **assetBulkOptIn**(`optIn`, `algod`): `Promise`\<`Record`\<`number`, `string`\>\> -Opt in to a list of assets on the Algorand blockchain. - #### Parameters | Name | Type | Description | @@ -204,6 +260,12 @@ Opt in to a list of assets on the Algorand blockchain. A record object where the keys are the asset IDs and the values are the corresponding transaction IDs for successful opt-ins. +**`Deprecated`** + +use `algorandClient.account.assetBulkOptIn()` instead + +Opt in to a list of assets on the Algorand blockchain. + **`Throws`** If there is an error during the opt-in process. @@ -216,7 +278,7 @@ algokit.bulkOptIn({ account: account, assetIds: [12345, 67890] }, algod) #### Defined in -[src/asset.ts:123](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/asset.ts#L123) +[src/asset.ts:131](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/asset.ts#L131) ___ @@ -224,8 +286,6 @@ ___ ▸ **assetBulkOptOut**(`optOut`, `algod`): `Promise`\<`Record`\<`number`, `string`\>\> -Opt out of multiple assets in Algorand blockchain. - #### Parameters | Name | Type | Description | @@ -239,6 +299,12 @@ Opt out of multiple assets in Algorand blockchain. A record object containing asset IDs as keys and their corresponding transaction IDs as values. +**`Deprecated`** + +use `algorandClient.account.assetBulkOptOut()` instead + +Opt out of multiple assets in Algorand blockchain. + **`Throws`** If there is an error during the opt-out process. @@ -251,7 +317,7 @@ algokit.bulkOptOut({ account: account, assetIds: [12345, 67890] }, algod) #### Defined in -[src/asset.ts:148](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/asset.ts#L148) +[src/asset.ts:158](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/asset.ts#L158) ___ @@ -259,8 +325,6 @@ ___ ▸ **assetOptIn**(`optIn`, `algod`): `Promise`\<[`SendTransactionResult`](../interfaces/types_transaction.SendTransactionResult.md)\> -Opt-in an account to an asset. - #### Parameters | Name | Type | Description | @@ -274,6 +338,12 @@ Opt-in an account to an asset. The transaction object and optionally the confirmation if it was sent to the chain (`skipSending` is `false` or unset) +**`Deprecated`** + +use `algorandClient.send.assetOptIn()` / `algorandClient.transaction.assetOptIn()` instead + +Opt-in an account to an asset. + **`Example`** ```typescript @@ -282,7 +352,7 @@ await algokit.assetOptIn({ account, assetId }, algod) #### Defined in -[src/asset.ts:64](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/asset.ts#L64) +[src/asset.ts:68](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/asset.ts#L68) ___ @@ -290,8 +360,6 @@ ___ ▸ **assetOptOut**(`optOut`, `algod`): `Promise`\<[`SendTransactionResult`](../interfaces/types_transaction.SendTransactionResult.md)\> -Opt-out an account from an asset. - #### Parameters | Name | Type | Description | @@ -305,6 +373,12 @@ Opt-out an account from an asset. The transaction object and optionally the confirmation if it was sent to the chain (`skipSending` is `false` or unset) +**`Deprecated`** + +use `algorandClient.send.assetOptOut()` / `algorandClient.transaction.assetOptOut()` instead + +Opt-out an account from an asset. + **`Example`** ```typescript @@ -313,7 +387,7 @@ await algokit.assetOptOut({ account, assetId, assetCreatorAddress }, algod) #### Defined in -[src/asset.ts:93](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/asset.ts#L93) +[src/asset.ts:99](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/asset.ts#L99) ___ @@ -346,7 +420,7 @@ ___ ▸ **capTransactionFee**(`transaction`, `maxAcceptableFee`): `void` -Limit the acceptable fee to a defined amount of µALGOs. +Limit the acceptable fee to a defined amount of µAlgos. This also sets the transaction to be flatFee to ensure the transaction only succeeds at the estimated rate. @@ -452,8 +526,6 @@ ___ ▸ **createAsset**(`create`, `algod`): `Promise`\<[`SendTransactionResult`](../interfaces/types_transaction.SendTransactionResult.md) & \{ `confirmation?`: \{ `assetIndex`: `number` \| `bigint` } }\> -Create an Algorand Standard Asset (ASA). - #### Parameters | Name | Type | Description | @@ -467,6 +539,12 @@ Create an Algorand Standard Asset (ASA). The transaction object and optionally the confirmation if it was sent to the chain (`skipSending` is `false` or unset) +**`Deprecated`** + +use `algorandClient.send.assetCreate()` / `algorandClient.transaction.assetCreate()` instead + +Create an Algorand Standard Asset (ASA). + **`Example`** ```typescript @@ -475,7 +553,7 @@ await algokit.createAsset({ creator: account, total: 1, decimals: 0, name: 'My a #### Defined in -[src/asset.ts:22](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/asset.ts#L22) +[src/asset.ts:24](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/asset.ts#L24) ___ @@ -613,10 +691,6 @@ ___ ▸ **ensureFunded**\<`T`\>(`funding`, `algod`, `kmd?`): `Promise`\<[`EnsureFundedReturnType`](../interfaces/types_transfer.EnsureFundedReturnType.md) \| `undefined`\> -Funds a given account using a funding source such that it has a certain amount of algos free to spend (accounting for ALGOs locked in minimum balance requirement). - -https://developer.algorand.org/docs/get-details/accounts/#minimum-balance - #### Type parameters | Name | Type | @@ -638,37 +712,18 @@ https://developer.algorand.org/docs/get-details/accounts/#minimum-balance - `EnsureFundedReturnType` if funds were transferred. - `undefined` if no funds were needed. -#### Defined in - -[src/transfer/transfer.ts:23](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/transfer/transfer.ts#L23) - -___ - -### executePaginatedRequest - -▸ **executePaginatedRequest**\<`TResult`, `TRequest`\>(`extractItems`, `buildRequest`): `Promise`\<`TResult`[]\> - -#### Type parameters - -| Name | Type | -| :------ | :------ | -| `TResult` | `TResult` | -| `TRequest` | extends `Object` | - -#### Parameters +**`Deprecated`** -| Name | Type | -| :------ | :------ | -| `extractItems` | (`response`: `any`) => `TResult`[] | -| `buildRequest` | (`nextToken?`: `string`) => `TRequest` | +Use `algorand.account.ensureFunded()` / `algorand.account.ensureFundedFromEnvironment()` +/ `algorand.account.ensureFundedFromTestNetDispenserApi()` instead -#### Returns +Funds a given account using a funding source such that it has a certain amount of algos free to spend (accounting for Algos locked in minimum balance requirement). -`Promise`\<`TResult`[]\> +https://developer.algorand.org/docs/get-details/accounts/#minimum-balance #### Defined in -[src/indexer-lookup.ts:152](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/indexer-lookup.ts#L152) +[src/transfer/transfer.ts:26](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/transfer/transfer.ts#L26) ___ @@ -762,7 +817,7 @@ If you have a mnemonic secret loaded into `process.env.ACCOUNT_MNEMONIC` then yo const account = await getAccount('ACCOUNT', algod) ``` -If that code runs against LocalNet then a wallet called `ACCOUNT` will automatically be created with an account that is automatically funded with 1000 (default) ALGOs from the default LocalNet dispenser. +If that code runs against LocalNet then a wallet called `ACCOUNT` will automatically be created with an account that is automatically funded with 1000 (default) Algos from the default LocalNet dispenser. #### Defined in @@ -800,7 +855,7 @@ If you have a mnemonic secret loaded into `process.env.ACCOUNT_MNEMONIC` then yo const account = await getAccount({config: getAccountConfigFromEnvironment('ACCOUNT')}, algod) ``` -If that code runs against LocalNet then a wallet called `ACCOUNT` will automatically be created with an account that is automatically funded with 1000 (default) ALGOs from the default LocalNet dispenser. +If that code runs against LocalNet then a wallet called `ACCOUNT` will automatically be created with an account that is automatically funded with 1000 (default) Algos from the default LocalNet dispenser. #### Defined in @@ -830,7 +885,7 @@ Returns the string address of an Algorand account from a base64 encoded version #### Defined in -[src/account/account.ts:126](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/account/account.ts#L126) +[src/account/account.ts:127](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/account/account.ts#L127) ___ @@ -856,7 +911,7 @@ Returns an account's address as a byte array #### Defined in -[src/account/account.ts:115](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/account/account.ts#L115) +[src/account/account.ts:116](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/account/account.ts#L116) ___ @@ -896,7 +951,7 @@ const accountInfo = await account.getAccountAssetInformation(address, assetId, a #### Defined in -[src/account/account.ts:168](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/account/account.ts#L168) +[src/account/account.ts:193](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/account/account.ts#L193) ___ @@ -935,7 +990,7 @@ ___ ### getAccountInformation -▸ **getAccountInformation**(`sender`, `algod`): `Promise`\<[`AccountInformation`](types_account.md#accountinformation)\> +▸ **getAccountInformation**(`sender`, `algod`): `Promise`\<[`AccountInformation`](index.md#accountinformation)\> #### Parameters @@ -946,7 +1001,7 @@ ___ #### Returns -`Promise`\<[`AccountInformation`](types_account.md#accountinformation)\> +`Promise`\<[`AccountInformation`](index.md#accountinformation)\> The account information @@ -967,7 +1022,7 @@ const accountInfo = await account.getInformation(address, algod); #### Defined in -[src/account/account.ts:146](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/account/account.ts#L146) +[src/account/account.ts:152](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/account/account.ts#L152) ___ @@ -2130,110 +2185,6 @@ Use `await algorandClient.client.isTestNet()` or `await new ClientManager({ algo ___ -### lookupAccountByAddress - -▸ **lookupAccountByAddress**(`accountAddress`, `indexer`): `Promise`\<[`AccountLookupResult`](../interfaces/types_indexer.AccountLookupResult.md)\> - -Looks up an account by address using Indexer. - -#### Parameters - -| Name | Type | Description | -| :------ | :------ | :------ | -| `accountAddress` | `string` | The address of the account to look up | -| `indexer` | `default` | An indexer client | - -#### Returns - -`Promise`\<[`AccountLookupResult`](../interfaces/types_indexer.AccountLookupResult.md)\> - -The result of the look-up - -#### Defined in - -[src/indexer-lookup.ts:33](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/indexer-lookup.ts#L33) - -___ - -### lookupAccountCreatedApplicationByAddress - -▸ **lookupAccountCreatedApplicationByAddress**(`indexer`, `address`, `getAll?`, `paginationLimit?`): `Promise`\<[`ApplicationResult`](../interfaces/types_indexer.ApplicationResult.md)[]\> - -Looks up applications that were created by the given address; will automatically paginate through all data. - -#### Parameters - -| Name | Type | Default value | Description | -| :------ | :------ | :------ | :------ | -| `indexer` | `default` | `undefined` | An indexer instance | -| `address` | `string` | `undefined` | The address of the creator to look up | -| `getAll` | `undefined` \| `boolean` | `undefined` | Whether or not to include deleted applications | -| `paginationLimit?` | `number` | `undefined` | The number of records to return per paginated request, default 1000 | - -#### Returns - -`Promise`\<[`ApplicationResult`](../interfaces/types_indexer.ApplicationResult.md)[]\> - -The list of application results - -#### Defined in - -[src/indexer-lookup.ts:45](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/indexer-lookup.ts#L45) - -___ - -### lookupAssetHoldings - -▸ **lookupAssetHoldings**(`indexer`, `assetId`, `options?`, `paginationLimit?`): `Promise`\<[`MiniAssetHolding`](../interfaces/types_indexer.MiniAssetHolding.md)[]\> - -Looks up asset holdings for the given asset; will automatically paginate through all data. - -#### Parameters - -| Name | Type | Description | -| :------ | :------ | :------ | -| `indexer` | `default` | An indexer instance | -| `assetId` | `number` \| `bigint` | The ID of the asset to look up holdings for | -| `options?` | [`LookupAssetHoldingsOptions`](../interfaces/types_indexer.LookupAssetHoldingsOptions.md) | Optional options to control the lookup | -| `paginationLimit?` | `number` | The number of records to return per paginated request, default 1000 | - -#### Returns - -`Promise`\<[`MiniAssetHolding`](../interfaces/types_indexer.MiniAssetHolding.md)[]\> - -The list of application results - -#### Defined in - -[src/indexer-lookup.ts:79](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/indexer-lookup.ts#L79) - -___ - -### lookupTransactionById - -▸ **lookupTransactionById**(`transactionId`, `indexer`): `Promise`\<[`TransactionLookupResult`](../interfaces/types_indexer.TransactionLookupResult.md)\> - -Looks up a transaction by ID using Indexer. - -#### Parameters - -| Name | Type | Description | -| :------ | :------ | :------ | -| `transactionId` | `string` | The ID of the transaction to look up | -| `indexer` | `default` | An indexer client | - -#### Returns - -`Promise`\<[`TransactionLookupResult`](../interfaces/types_indexer.TransactionLookupResult.md)\> - -The result of the look-up - -#### Defined in - -[src/indexer-lookup.ts:23](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/indexer-lookup.ts#L23) - -___ - ### microAlgos ▸ **microAlgos**(`microAlgos`): [`AlgoAmount`](../classes/types_amount.AlgoAmount.md) @@ -2325,12 +2276,12 @@ If you have a mnemonic secret loaded into `process.env.MY_ACCOUNT_MNEMONIC` then const account = await mnemonicAccountFromEnvironment('MY_ACCOUNT', algod) ``` -If that code runs against LocalNet then a wallet called `MY_ACCOUNT` will automatically be created with an account that is automatically funded with 1000 (default) ALGOs from the default LocalNet dispenser. +If that code runs against LocalNet then a wallet called `MY_ACCOUNT` will automatically be created with an account that is automatically funded with 1000 (default) Algos from the default LocalNet dispenser. If not running against LocalNet then it will use proces.env.MY_ACCOUNT_MNEMONIC as the private key and (if present) process.env.MY_ACCOUNT_SENDER as the sender address. #### Defined in -[src/account/account.ts:95](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/account/account.ts#L95) +[src/account/account.ts:96](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/account/account.ts#L96) ___ @@ -2359,7 +2310,7 @@ Returns an account wrapper that supports partial or full multisig signing. #### Defined in -[src/account/account.ts:22](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/account/account.ts#L22) +[src/account/account.ts:23](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/account/account.ts#L23) ___ @@ -2538,7 +2489,7 @@ This is a wrapper around algosdk.generateAccount to provide a more friendly/obvi #### Defined in -[src/account/account.ts:58](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/account/account.ts#L58) +[src/account/account.ts:59](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/account/account.ts#L59) ___ @@ -2546,10 +2497,6 @@ ___ ▸ **rekeyAccount**(`rekey`, `algod`): `Promise`\<[`SendTransactionResult`](../interfaces/types_transaction.SendTransactionResult.md)\> -Rekey an account to a new address. - -**Note:** Please be careful with this function and be sure to read the [official rekey guidance](https://developer.algorand.org/docs/get-details/accounts/rekey/). - #### Parameters | Name | Type | Description | @@ -2563,6 +2510,14 @@ Rekey an account to a new address. The transaction object and optionally the confirmation if it was sent to the chain (`skipSending` is `false` or unset) +**`Deprecated`** + +Use `algorand.account.rekeyAccount()` instead + +Rekey an account to a new address. + +**Note:** Please be careful with this function and be sure to read the [official rekey guidance](https://developer.algorand.org/docs/get-details/accounts/rekey/). + **`Example`** ```typescript @@ -2571,7 +2526,7 @@ await algokit.rekeyAccount({ from, rekeyTo }, algod) #### Defined in -[src/transfer/transfer.ts:116](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/transfer/transfer.ts#L116) +[src/transfer/transfer.ts:123](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/transfer/transfer.ts#L123) ___ @@ -2594,13 +2549,13 @@ The SigningAccount wrapper **`Deprecated`** -Use `algorandClient.account.rekeyed(account, sender)` or `new SigningAccount(account, sender)` instead. +Use `algorandClient.account.rekeyed(sender, account)` or `new SigningAccount(account, sender)` instead. Returns an account wrapper that supports a rekeyed account. #### Defined in -[src/account/account.ts:34](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/account/account.ts#L34) +[src/account/account.ts:35](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/account/account.ts#L35) ___ @@ -2637,32 +2592,6 @@ The replaced TEAL code ___ -### searchTransactions - -▸ **searchTransactions**(`indexer`, `searchCriteria`, `paginationLimit?`): `Promise`\<[`TransactionSearchResults`](../interfaces/types_indexer.TransactionSearchResults.md)\> - -Allows transactions to be searched for the given criteria. - -#### Parameters - -| Name | Type | Description | -| :------ | :------ | :------ | -| `indexer` | `default` | An indexer client | -| `searchCriteria` | (`s`: `default`) => `default` | The criteria to search for | -| `paginationLimit?` | `number` | The number of records to return per paginated request, default 1000 | - -#### Returns - -`Promise`\<[`TransactionSearchResults`](../interfaces/types_indexer.TransactionSearchResults.md)\> - -The search results - -#### Defined in - -[src/indexer-lookup.ts:118](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/indexer-lookup.ts#L118) - -___ - ### sendAtomicTransactionComposer ▸ **sendAtomicTransactionComposer**(`atcSend`, `algod`): `Promise`\<[`SendAtomicTransactionComposerResults`](../interfaces/types_transaction.SendAtomicTransactionComposerResults.md)\> @@ -2837,7 +2766,7 @@ Returns an amount of µAlgos to cover standard fees for the given number of tran | Name | Type | Description | | :------ | :------ | :------ | -| `numberOfTransactions` | `number` | The of standard transaction fees to return the amount of ALGOs | +| `numberOfTransactions` | `number` | The of standard transaction fees to return the amount of Algos | #### Returns @@ -2874,7 +2803,7 @@ Returns an account wrapper that supports a transaction signer with associated se #### Defined in -[src/account/account.ts:46](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/account/account.ts#L46) +[src/account/account.ts:47](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/account/account.ts#L47) ___ @@ -2882,8 +2811,6 @@ ___ ▸ **transferAlgos**(`transfer`, `algod`): `Promise`\<[`SendTransactionResult`](../interfaces/types_transaction.SendTransactionResult.md)\> -Transfer ALGOs between two accounts. - #### Parameters | Name | Type | Description | @@ -2897,6 +2824,12 @@ Transfer ALGOs between two accounts. The transaction object and optionally the confirmation if it was sent to the chain (`skipSending` is `false` or unset) +**`Deprecated`** + +Use `algorand.send.payment()` / `algorand.transaction.payment()` instead + +Transfer Algos between two accounts. + **`Example`** ```typescript @@ -2905,7 +2838,7 @@ await algokit.transferAlgos({ from, to, amount: algokit.algos(1) }, algod) #### Defined in -[src/transfer/transfer-algos.ts:20](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/transfer/transfer-algos.ts#L20) +[src/transfer/transfer-algos.ts:22](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/transfer/transfer-algos.ts#L22) ___ @@ -2913,8 +2846,6 @@ ___ ▸ **transferAsset**(`transfer`, `algod`): `Promise`\<[`SendTransactionResult`](../interfaces/types_transaction.SendTransactionResult.md)\> -Transfer asset between two accounts. - #### Parameters | Name | Type | Description | @@ -2928,6 +2859,12 @@ Transfer asset between two accounts. The transaction object and optionally the confirmation if it was sent to the chain (`skipSending` is `false` or unset) +**`Deprecated`** + +Use `algorand.send.assetTransfer()` / `algorand.transaction.assetTransfer()` instead + +Transfer asset between two accounts. + **`Example`** ```typescript @@ -2936,7 +2873,7 @@ await algokit.transferAsset({ from, to, assetId, amount }, algod) #### Defined in -[src/transfer/transfer.ts:83](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/transfer/transfer.ts#L83) +[src/transfer/transfer.ts:88](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/transfer/transfer.ts#L88) ___ diff --git a/docs/code/modules/types_account.md b/docs/code/modules/types_account.md index 299d2384..fa8ecf38 100644 --- a/docs/code/modules/types_account.md +++ b/docs/code/modules/types_account.md @@ -42,19 +42,48 @@ Account asset holding information at a given round. #### Defined in -[src/types/account.ts:124](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/account.ts#L124) +[src/types/account.ts:263](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/account.ts#L263) ___ ### AccountInformation -Ƭ **AccountInformation**: `Omit`\<`NumberConverter`\<`AccountInformationModel`\>, ``"get_obj_for_encoding"``\> +Ƭ **AccountInformation**: `Object` Account information at a given round. +#### Type declaration + +| Name | Type | Description | +| :------ | :------ | :------ | +| `address` | `string` | The account public key | +| `amountWithoutPendingRewards` | [`AlgoAmount`](../classes/types_amount.AlgoAmount.md) | The amount of Algos in the account, without the pending rewards. | +| `appsLocalState?` | `ApplicationLocalState`[] | Applications local data stored in this account. | +| `appsTotalExtraPages?` | `number` | The sum of all extra application program pages for this account. | +| `appsTotalSchema?` | `ApplicationStateSchema` | (tsch) stores the sum of all of the local schemas and global schemas in this account. Note: the raw account uses `StateSchema` for this type. | +| `assets?` | `AssetHolding`[] | Assets held by this account. | +| `authAddr?` | `string` | The address against which signing should be checked. If empty, the address of the current account is used. This field can be updated in any transaction by setting the `RekeyTo` field. | +| `balance` | [`AlgoAmount`](../classes/types_amount.AlgoAmount.md) | The balance of Algos currently held by the account. | +| `createdApps?` | `Application`[] | Parameters of applications created by this account including app global data. | +| `createdAssets?` | `Asset`[] | (apar) parameters of assets created by this account. Note: the raw account uses `map[int] -> Asset` for this type. | +| `minBalance` | [`AlgoAmount`](../classes/types_amount.AlgoAmount.md) | Algo balance required to be held by the account. The requirement grows based on asset and application usage. | +| `participation?` | `AccountParticipation` | AccountParticipation describes the parameters used by this account in consensus protocol. | +| `pendingRewards` | [`AlgoAmount`](../classes/types_amount.AlgoAmount.md) | Amount of Algos of pending rewards in this account. | +| `rewardBase?` | `number` | Used as part of the rewards computation. Only applicable to accounts which are participating. | +| `rewards` | [`AlgoAmount`](../classes/types_amount.AlgoAmount.md) | Total rewards of Algos the account has received, including pending rewards. | +| `sigType?` | `string` | Indicates what type of signature is used by this account, must be one of: * sig * msig * lsig | +| `status` | `string` | Delegation status of the account's MicroAlgos: * Offline - indicates that the associated account is delegated. * Online - indicates that the associated account used as part of the delegation pool. * NotParticipating - indicates that the associated account is neither a delegator nor a delegate. | +| `totalAppsOptedIn` | `number` | The count of all applications that have been opted in, equivalent to the count of application local data (AppLocalState objects) stored in this account. | +| `totalAssetsOptedIn` | `number` | The count of all assets that have been opted in, equivalent to the count of AssetHolding objects held by this account. | +| `totalBoxBytes?` | `number` | The total number of bytes used by this account's app's box keys and values. | +| `totalBoxes?` | `number` | The number of existing boxes created by this account's app. | +| `totalCreatedApps` | `number` | The count of all apps (AppParams objects) created by this account. | +| `totalCreatedAssets` | `number` | The count of all assets (AssetParams objects) created by this account. | +| `validAsOfRound` | `bigint` | The round number for which this information is relevant. | + #### Defined in -[src/types/account.ts:121](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/account.ts#L121) +[src/types/account.ts:125](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/account.ts#L125) ## Variables @@ -66,4 +95,4 @@ The account name identifier used for fund dispensing in test environments #### Defined in -[src/types/account.ts:11](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/account.ts#L11) +[src/types/account.ts:17](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/account.ts#L17) diff --git a/docs/code/modules/types_account_manager.md b/docs/code/modules/types_account_manager.md index 67c372a0..0442fabf 100644 --- a/docs/code/modules/types_account_manager.md +++ b/docs/code/modules/types_account_manager.md @@ -40,4 +40,4 @@ A transaction signer #### Defined in -[src/types/account-manager.ts:38](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/account-manager.ts#L38) +[src/types/account-manager.ts:46](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/account-manager.ts#L46) diff --git a/docs/code/modules/types_algorand_client.md b/docs/code/modules/types_algorand_client.md index 194e04d7..b72697e5 100644 --- a/docs/code/modules/types_algorand_client.md +++ b/docs/code/modules/types_algorand_client.md @@ -32,4 +32,4 @@ Result from sending a single transaction. #### Defined in -[src/types/algorand-client.ts:14](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/algorand-client.ts#L14) +[src/types/algorand-client.ts:15](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/algorand-client.ts#L15) diff --git a/docs/code/modules/types_client_manager.md b/docs/code/modules/types_client_manager.md index 2c9f943f..f6bd4f29 100644 --- a/docs/code/modules/types_client_manager.md +++ b/docs/code/modules/types_client_manager.md @@ -31,7 +31,7 @@ Details to resolve an app client by creator address and name. #### Defined in -[src/types/client-manager.ts:486](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/client-manager.ts#L486) +[src/types/client-manager.ts:508](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/client-manager.ts#L508) ___ @@ -43,7 +43,7 @@ Details to resolve an app client by app ID. #### Defined in -[src/types/client-manager.ts:498](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/client-manager.ts#L498) +[src/types/client-manager.ts:520](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/client-manager.ts#L520) ___ @@ -55,7 +55,7 @@ Details to resolve a typed app creator address and name. #### Defined in -[src/types/client-manager.ts:493](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/client-manager.ts#L493) +[src/types/client-manager.ts:515](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/client-manager.ts#L515) ___ @@ -67,4 +67,4 @@ Details to resolve a typed app by app ID. #### Defined in -[src/types/client-manager.ts:503](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/client-manager.ts#L503) +[src/types/client-manager.ts:525](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/client-manager.ts#L525) diff --git a/docs/code/modules/types_composer.md b/docs/code/modules/types_composer.md index 37d563ed..9be1dbeb 100644 --- a/docs/code/modules/types_composer.md +++ b/docs/code/modules/types_composer.md @@ -27,7 +27,6 @@ - [MethodCallParams](types_composer.md#methodcallparams) - [OnlineKeyRegistrationParams](types_composer.md#onlinekeyregistrationparams) - [PaymentParams](types_composer.md#paymentparams) -- [RekeyParams](types_composer.md#rekeyparams) ### Variables @@ -52,7 +51,7 @@ Parameters to create an `AlgokitComposer`. #### Defined in -[src/types/composer.ts:338](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/composer.ts#L338) +[src/types/composer.ts:388](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/composer.ts#L388) ___ @@ -64,19 +63,23 @@ Parameters to define an application call transaction. #### Defined in -[src/types/composer.ts:262](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/composer.ts#L262) +[src/types/composer.ts:313](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/composer.ts#L313) ___ ### AssetConfigParams -Ƭ **AssetConfigParams**: [`CommonTransactionParams`](types_composer.md#commontransactionparams) & \{ `assetId`: `bigint` ; `clawback?`: `string` ; `freeze?`: `string` ; `manager?`: `string` ; `reserve?`: `string` } +Ƭ **AssetConfigParams**: [`CommonTransactionParams`](types_composer.md#commontransactionparams) & \{ `assetId`: `bigint` ; `clawback?`: `string` ; `freeze?`: `string` ; `manager`: `string` \| `undefined` ; `reserve?`: `string` } -Parameters to define an asset config transaction. +Parameters to define an asset reconfiguration transaction. + +**Note:** The manager, reserve, freeze, and clawback addresses +are immutably empty if they are not set. If manager is not set then +all fields are immutable from that point forward. #### Defined in -[src/types/composer.ts:179](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/composer.ts#L179) +[src/types/composer.ts:188](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/composer.ts#L188) ___ @@ -90,7 +93,7 @@ The account that sends this transaction will automatically be opted in to the as #### Defined in -[src/types/composer.ts:70](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/composer.ts#L70) +[src/types/composer.ts:72](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/composer.ts#L72) ___ @@ -100,9 +103,11 @@ ___ Parameters to define an asset destroy transaction. +Created assets can be destroyed only by the asset manager account. All of the assets must be owned by the creator of the asset before the asset can be deleted. + #### Defined in -[src/types/composer.ts:203](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/composer.ts#L203) +[src/types/composer.ts:246](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/composer.ts#L246) ___ @@ -114,7 +119,7 @@ Parameters to define an asset freeze transaction. #### Defined in -[src/types/composer.ts:193](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/composer.ts#L193) +[src/types/composer.ts:233](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/composer.ts#L233) ___ @@ -126,7 +131,7 @@ Parameters to define an asset opt-in transaction. #### Defined in -[src/types/composer.ts:223](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/composer.ts#L223) +[src/types/composer.ts:274](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/composer.ts#L274) ___ @@ -138,7 +143,7 @@ Parameters to define an asset opt-out transaction. #### Defined in -[src/types/composer.ts:229](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/composer.ts#L229) +[src/types/composer.ts:280](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/composer.ts#L280) ___ @@ -150,7 +155,7 @@ Parameters to define an asset transfer transaction. #### Defined in -[src/types/composer.ts:209](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/composer.ts#L209) +[src/types/composer.ts:252](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/composer.ts#L252) ___ @@ -164,17 +169,17 @@ Common parameters for defining a transaction. | Name | Type | Description | | :------ | :------ | :------ | -| `extraFee?` | [`AlgoAmount`](../classes/types_amount.AlgoAmount.md) | The fee to pay IN ADDITION to the suggested fee. Useful for covering inner transaction fees | -| `firstValidRound?` | `bigint` | Set the first round this transaction is valid. If left undefined, the value from algod will be used. Only set this when you intentionally want this to be some time in the future | -| `lastValidRound?` | `bigint` | The last round this transaction is valid. It is recommended to use validityWindow instead | -| `lease?` | `Uint8Array` \| `string` | Prevent multiple transactions with the same lease being included within the validity window | -| `maxFee?` | [`AlgoAmount`](../classes/types_amount.AlgoAmount.md) | Throw an error if the fee for the transaction is more than this amount | -| `note?` | `Uint8Array` \| `string` | Note to attach to the transaction | +| `extraFee?` | [`AlgoAmount`](../classes/types_amount.AlgoAmount.md) | The fee to pay IN ADDITION to the suggested fee. Useful for covering inner transaction fees. | +| `firstValidRound?` | `bigint` | Set the first round this transaction is valid. If left undefined, the value from algod will be used. We recommend you only set this when you intentionally want this to be some time in the future. | +| `lastValidRound?` | `bigint` | The last round this transaction is valid. It is recommended to use `validityWindow` instead. | +| `lease?` | `Uint8Array` \| `string` | Prevent multiple transactions with the same lease being included within the validity window. A [lease](https://developer.algorand.org/articles/leased-transactions-securing-advanced-smart-contract-design/) enforces a mutually exclusive transaction (useful to prevent double-posting and other scenarios). | +| `maxFee?` | [`AlgoAmount`](../classes/types_amount.AlgoAmount.md) | Throw an error if the fee for the transaction is more than this amount; prevents overspending on fees during high congestion periods. | +| `note?` | `Uint8Array` \| `string` | Note to attach to the transaction. Max of 1000 bytes. | | `rekeyTo?` | `string` | Change the signing key of the sender to the given address. **Warning:** Please be careful with this parameter and be sure to read the [official rekey guidance](https://developer.algorand.org/docs/get-details/accounts/rekey/). | -| `sender` | `string` | The address sending the transaction | -| `signer?` | `algosdk.TransactionSigner` \| [`TransactionSignerAccount`](../interfaces/types_account.TransactionSignerAccount.md) | The function used to sign transactions | -| `staticFee?` | [`AlgoAmount`](../classes/types_amount.AlgoAmount.md) | The transaction fee. In most cases you want to use `extraFee` unless setting the fee to 0 to be covered by another transaction | -| `validityWindow?` | `number` | How many rounds the transaction should be valid for | +| `sender` | `string` | The address of the account sending the transaction. | +| `signer?` | `algosdk.TransactionSigner` \| [`TransactionSignerAccount`](../interfaces/types_account.TransactionSignerAccount.md) | The function used to sign transaction(s); if not specified then an attempt will be made to find a registered signer for the given `sender` or use a default signer (if configured). | +| `staticFee?` | [`AlgoAmount`](../classes/types_amount.AlgoAmount.md) | The static transaction fee. In most cases you want to use `extraFee` unless setting the fee to 0 to be covered by another transaction. | +| `validityWindow?` | `number` | How many rounds the transaction should be valid for, if not specified then the registered default validity window will be used. | #### Defined in @@ -190,7 +195,7 @@ Parameters to define an ABI method application call transaction. #### Defined in -[src/types/composer.ts:297](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/composer.ts#L297) +[src/types/composer.ts:348](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/composer.ts#L348) ___ @@ -202,7 +207,7 @@ Parameters to define an online key registration transaction. #### Defined in -[src/types/composer.ts:240](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/composer.ts#L240) +[src/types/composer.ts:291](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/composer.ts#L291) ___ @@ -214,19 +219,7 @@ Parameters to define a payment transaction. #### Defined in -[src/types/composer.ts:48](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/composer.ts#L48) - -___ - -### RekeyParams - -Ƭ **RekeyParams**: [`CommonTransactionParams`](types_composer.md#commontransactionparams) & \{ `rekeyTo`: `string` } - -Parameters to define a rekey transaction. - -#### Defined in - -[src/types/composer.ts:58](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/composer.ts#L58) +[src/types/composer.ts:56](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/composer.ts#L56) ## Variables diff --git a/src/account/account.ts b/src/account/account.ts index 1ee9cb7b..d8c11298 100644 --- a/src/account/account.ts +++ b/src/account/account.ts @@ -83,7 +83,7 @@ export function randomAccount(): Account { * const account = await mnemonicAccountFromEnvironment('MY_ACCOUNT', algod) * ``` * - * If that code runs against LocalNet then a wallet called `MY_ACCOUNT` will automatically be created with an account that is automatically funded with 1000 (default) ALGOs from the default LocalNet dispenser. + * If that code runs against LocalNet then a wallet called `MY_ACCOUNT` will automatically be created with an account that is automatically funded with 1000 (default) Algos from the default LocalNet dispenser. * If not running against LocalNet then it will use proces.env.MY_ACCOUNT_MNEMONIC as the private key and (if present) process.env.MY_ACCOUNT_SENDER as the sender address. * * @param account The details of the account to get, either the name identifier (string) or an object with: diff --git a/src/account/get-account.ts b/src/account/get-account.ts index 01e2f0ad..93ecce83 100644 --- a/src/account/get-account.ts +++ b/src/account/get-account.ts @@ -29,7 +29,7 @@ import Kmd = algosdk.Kmd * const account = await getAccount('ACCOUNT', algod) * ``` * - * If that code runs against LocalNet then a wallet called `ACCOUNT` will automatically be created with an account that is automatically funded with 1000 (default) ALGOs from the default LocalNet dispenser. + * If that code runs against LocalNet then a wallet called `ACCOUNT` will automatically be created with an account that is automatically funded with 1000 (default) Algos from the default LocalNet dispenser. * * @param account The details of the account to get, either the name identifier (string) or an object with: * * `name`: The name identifier of the account @@ -56,7 +56,7 @@ export async function getAccount( * const account = await getAccount({config: getAccountConfigFromEnvironment('ACCOUNT')}, algod) * ``` * - * If that code runs against LocalNet then a wallet called `ACCOUNT` will automatically be created with an account that is automatically funded with 1000 (default) ALGOs from the default LocalNet dispenser. + * If that code runs against LocalNet then a wallet called `ACCOUNT` will automatically be created with an account that is automatically funded with 1000 (default) Algos from the default LocalNet dispenser. * * @param account The details of the account to get, an object with: * * `config`: Account configuration. To get from environment use getAccountConfigFromEnvironment(accountName) @@ -91,7 +91,7 @@ export async function getAccount( * const account = await getAccount({config: getAccountConfigFromEnvironment('ACCOUNT')}, algod) * ``` * - * If that code runs against LocalNet then a wallet called `ACCOUNT` will automatically be created with an account that is automatically funded with 1000 (default) ALGOs from the default LocalNet dispenser. + * If that code runs against LocalNet then a wallet called `ACCOUNT` will automatically be created with an account that is automatically funded with 1000 (default) Algos from the default LocalNet dispenser. * * @param account The details of the account to get, either the name identifier (string) or an object with: * * `config`: Account configuration. To get from environment use getAccountConfigFromEnvironment(accountName) OR diff --git a/src/amount.ts b/src/amount.ts index 2c01a312..17646b73 100644 --- a/src/amount.ts +++ b/src/amount.ts @@ -31,7 +31,7 @@ export const microAlgos = (microAlgos: number) => { } /** Returns an amount of µAlgos to cover standard fees for the given number of transactions using AlgoAmount - * @param numberOfTransactions The of standard transaction fees to return the amount of ALGOs + * @param numberOfTransactions The of standard transaction fees to return the amount of Algos */ export const transactionFees = (numberOfTransactions: number) => { return AlgoAmount.MicroAlgos(numberOfTransactions * algosdk.ALGORAND_MIN_TX_FEE) diff --git a/src/indexer-lookup.spec.ts b/src/indexer-lookup.spec.ts index e3d503c4..48498398 100644 --- a/src/indexer-lookup.spec.ts +++ b/src/indexer-lookup.spec.ts @@ -1,61 +1,54 @@ -import { describe, test } from '@jest/globals' -import algosdk from 'algosdk' -import { getTestingAppCreateParams } from '../tests/example-contracts/testing-app/contract' -import * as algokit from './' +import { beforeEach, describe, test } from '@jest/globals' +import { getTestingAppContract, getTestingAppCreateParams } from '../tests/example-contracts/testing-app/contract' +import { indexer } from './' import { algorandFixture, runWhenIndexerCaughtUp } from './testing' +import { AlgoAmount } from './types/amount' describe('indexer-lookup', () => { const localnet = algorandFixture() beforeEach(localnet.beforeEach, 10_000) - const getTestTransaction = async (amount?: number, from?: string) => { - return algosdk.makePaymentTxnWithSuggestedParamsFromObject({ - from: from ?? localnet.context.testAccount.addr, - to: localnet.context.testAccount.addr, - amount: amount ?? 1, - suggestedParams: await localnet.context.algod.getTransactionParams().do(), + const sendTestTransaction = async (amount?: AlgoAmount, from?: string) => { + return await localnet.context.algorand.send.payment({ + sender: from ?? localnet.context.testAccount.addr, + receiver: localnet.context.testAccount.addr, + amount: amount ?? (1).microAlgos(), }) } test('Transaction is found by id', async () => { - const { algod, indexer, testAccount, waitForIndexer } = localnet.context - const { transaction } = await algokit.sendTransaction({ transaction: await getTestTransaction(), from: testAccount }, algod) + const { algorand, waitForIndexer } = localnet.context + const { transaction } = await sendTestTransaction() await waitForIndexer() - const txn = await algokit.lookupTransactionById(transaction.txID(), indexer) + const txn = await indexer.lookupTransactionById(transaction.txID(), algorand.client.indexer) expect(txn.transaction.id).toBe(transaction.txID()) expect(txn['current-round']).toBeGreaterThanOrEqual(transaction.firstRound) }, 20_000) test('Account is found by id', async () => { - const { indexer, testAccount } = localnet.context - await runWhenIndexerCaughtUp(() => algokit.lookupAccountByAddress(testAccount.addr, indexer)) + const { algorand, testAccount } = localnet.context + await runWhenIndexerCaughtUp(() => indexer.lookupAccountByAddress(testAccount.addr, algorand.client.indexer)) - const account = await algokit.lookupAccountByAddress(testAccount.addr, indexer) + const account = await indexer.lookupAccountByAddress(testAccount.addr, algorand.client.indexer) expect(account.account.address).toBe(testAccount.addr) }, 20_000) test('Transactions are searched with pagination', async () => { - const { algod, indexer, testAccount, generateAccount, waitForIndexer } = localnet.context + const { algorand, testAccount, generateAccount, waitForIndexer } = localnet.context const secondAccount = await generateAccount({ - initialFunds: algokit.algos(1), + initialFunds: (1).algos(), suppressLog: true, }) - const { transaction: transaction1 } = await algokit.sendTransaction( - { transaction: await getTestTransaction(1), from: testAccount }, - algod, - ) - const { transaction: transaction2 } = await algokit.sendTransaction( - { transaction: await getTestTransaction(1), from: testAccount }, - algod, - ) - await algokit.sendTransaction({ transaction: await getTestTransaction(1, secondAccount.addr), from: secondAccount }, algod) + const { transaction: transaction1 } = await sendTestTransaction((1).microAlgos()) + const { transaction: transaction2 } = await sendTestTransaction((2).microAlgos()) + await sendTestTransaction((1).microAlgos(), secondAccount.addr) await waitForIndexer() - const transactions = await algokit.searchTransactions( - indexer, + const transactions = await indexer.searchTransactions( + algorand.client.indexer, (s) => s.txType('pay').addressRole('sender').address(testAccount.addr), 1, ) @@ -65,9 +58,9 @@ describe('indexer-lookup', () => { }, 20_000) test('Application create transactions are found by creator with pagination', async () => { - const { algod, indexer, testAccount, generateAccount, waitForIndexer } = localnet.context + const { algorand, testAccount, generateAccount, waitForIndexer } = localnet.context const secondAccount = await generateAccount({ - initialFunds: algokit.algos(1), + initialFunds: (1).algos(), suppressLog: true, }) const createParams = await getTestingAppCreateParams(testAccount, { @@ -76,12 +69,19 @@ describe('indexer-lookup', () => { updatable: false, deletable: false, }) - const app1 = await algokit.createApp(createParams, algod) - const app2 = await algokit.createApp(createParams, algod) - await algokit.createApp({ ...createParams, from: secondAccount }, algod) + const app = await getTestingAppContract() + const app1 = await algorand.client + .getAppClientById({ app: app.appSpec, id: 0, sender: testAccount }) + .create({ deletable: false, updatable: false, deployTimeParams: { VALUE: 1 } }) + const app2 = await algorand.client + .getAppClientById({ app: app.appSpec, id: 0, sender: testAccount }) + .create({ deletable: false, updatable: false, deployTimeParams: { VALUE: 1 } }) + await algorand.client + .getAppClientById({ app: app.appSpec, id: 0, sender: secondAccount }) + .create({ deletable: false, updatable: false, deployTimeParams: { VALUE: 1 } }) await waitForIndexer() - const apps = await algokit.lookupAccountCreatedApplicationByAddress(indexer, testAccount.addr, true, 1) + const apps = await indexer.lookupAccountCreatedApplicationByAddress(algorand.client.indexer, testAccount.addr, true, 1) expect(apps.map((a) => a.id).sort()).toEqual([app1.appId, app2.appId].sort()) }, 20_000) diff --git a/src/testing/fixtures/algorand-fixture.ts b/src/testing/fixtures/algorand-fixture.ts index b4c1a0ec..a000c8ca 100644 --- a/src/testing/fixtures/algorand-fixture.ts +++ b/src/testing/fixtures/algorand-fixture.ts @@ -92,7 +92,12 @@ export function algorandFixture(fixtureConfig?: AlgorandFixtureConfig, config?: const transactionLoggerAlgod = transactionLogger.capture(algod) algorandClient = algorandClient ?? AlgorandClient.fromClients({ algod: transactionLoggerAlgod, indexer, kmd }) const acc = await getTestAccount({ initialFunds: fixtureConfig?.testAccountFunding ?? algos(10), suppressLog: true }, algorandClient) - algorandClient.setSignerFromAccount(acc).setDefaultValidityWindow(1000).setSuggestedParamsTimeout(0) + algorandClient.setSignerFromAccount(acc).setSuggestedParamsTimeout(0) + // If running against LocalNet we are likely in dev mode and we need to set a much higher validity window + // otherwise we are more likely to get invalid transactions. + if (await algorandClient.client.isLocalNet()) { + algorandClient.setDefaultValidityWindow(1000) + } const testAccount = { ...acc, signer: algorandClient.account.getSigner(acc.addr) } context = { algorand: algorandClient, diff --git a/src/transaction/transaction.spec.ts b/src/transaction/transaction.spec.ts index fcb39a7c..1740f556 100644 --- a/src/transaction/transaction.spec.ts +++ b/src/transaction/transaction.spec.ts @@ -48,8 +48,8 @@ describe('transaction', () => { ) }).rejects.toThrowError( 'Cancelled transaction due to high network congestion fees. ' + - 'Algorand suggested fees would cause this transaction to cost 1000 µALGOs. ' + - 'Cap for this transaction is 1 µALGOs.', + 'Algorand suggested fees would cause this transaction to cost 1000 µAlgos. ' + + 'Cap for this transaction is 1 µAlgos.', ) }) diff --git a/src/transaction/transaction.ts b/src/transaction/transaction.ts index 3a7f024f..018832ce 100644 --- a/src/transaction/transaction.ts +++ b/src/transaction/transaction.ts @@ -807,7 +807,7 @@ export const waitForConfirmation = async function ( } /** - * Limit the acceptable fee to a defined amount of µALGOs. + * Limit the acceptable fee to a defined amount of µAlgos. * This also sets the transaction to be flatFee to ensure the transaction only succeeds at * the estimated rate. * @param transaction The transaction to cap or suggested params object about to be used to create a transaction @@ -820,10 +820,10 @@ export function capTransactionFee(transaction: algosdk.Transaction | SuggestedPa // Will be based on the current suggested fee-per-byte value. if (transaction.fee > maxAcceptableFee.microAlgos) { throw new Error( - `Cancelled transaction due to high network congestion fees. Algorand suggested fees would cause this transaction to cost ${transaction.fee} µALGOs. Cap for this transaction is ${maxAcceptableFee.microAlgos} µALGOs.`, + `Cancelled transaction due to high network congestion fees. Algorand suggested fees would cause this transaction to cost ${transaction.fee} µAlgos. Cap for this transaction is ${maxAcceptableFee.microAlgos} µAlgos.`, ) } else if (transaction.fee > algosdk.ALGORAND_MIN_TX_FEE) { - Config.logger.warn(`Algorand network congestion fees are in effect. This transaction will incur a fee of ${transaction.fee} µALGOs.`) + Config.logger.warn(`Algorand network congestion fees are in effect. This transaction will incur a fee of ${transaction.fee} µAlgos.`) } // Now set the flat on the transaction. Otherwise the network may increase the fee above our cap and perform the transaction. diff --git a/src/transfer/transfer-algos.ts b/src/transfer/transfer-algos.ts index bd8e9037..517aaf55 100644 --- a/src/transfer/transfer-algos.ts +++ b/src/transfer/transfer-algos.ts @@ -9,7 +9,7 @@ import Algodv2 = algosdk.Algodv2 /** * @deprecated Use `algorand.send.payment()` / `algorand.transaction.payment()` instead * - * Transfer ALGOs between two accounts. + * Transfer Algos between two accounts. * @param transfer The transfer definition * @param algod An algod client * @returns The transaction object and optionally the confirmation if it was sent to the chain (`skipSending` is `false` or unset) diff --git a/src/transfer/transfer.ts b/src/transfer/transfer.ts index a2c524df..f95a26c6 100644 --- a/src/transfer/transfer.ts +++ b/src/transfer/transfer.ts @@ -12,7 +12,7 @@ import Kmd = algosdk.Kmd * @deprecated Use `algorand.account.ensureFunded()` / `algorand.account.ensureFundedFromEnvironment()` * / `algorand.account.ensureFundedFromTestNetDispenserApi()` instead * - * Funds a given account using a funding source such that it has a certain amount of algos free to spend (accounting for ALGOs locked in minimum balance requirement). + * Funds a given account using a funding source such that it has a certain amount of algos free to spend (accounting for Algos locked in minimum balance requirement). * * https://developer.algorand.org/docs/get-details/accounts/#minimum-balance * diff --git a/src/types/account-manager.ts b/src/types/account-manager.ts index 37a3fa84..05b88f22 100644 --- a/src/types/account-manager.ts +++ b/src/types/account-manager.ts @@ -320,7 +320,7 @@ export class AccountManager { * const account = await accountManager.fromEnvironment('MY_ACCOUNT') * ``` * - * If that code runs against LocalNet then a wallet called `MY_ACCOUNT` will automatically be created with an account that is automatically funded with 1000 (default) ALGOs from the default LocalNet dispenser. + * If that code runs against LocalNet then a wallet called `MY_ACCOUNT` will automatically be created with an account that is automatically funded with 1000 (default) Algos from the default LocalNet dispenser. * If not running against LocalNet then it will use proces.env.MY_ACCOUNT_MNEMONIC as the private key and (if present) process.env.MY_ACCOUNT_SENDER as the sender address. * * @param name The name identifier of the account @@ -469,9 +469,9 @@ export class AccountManager { * @example Example using AlgorandClient * ```typescript * // Basic example - * algorand.account.assetBulkOptIn("ACCOUNTADDRESS", [12345, 67890]) + * algorand.account.assetBulkOptIn("ACCOUNTADDRESS", [12345n, 67890n]) * // With configuration - * algorand.account.assetBulkOptIn("ACCOUNTADDRESS", [12345, 67890], { maxFee: (1000).microAlgos(), suppressLog: true }) + * algorand.account.assetBulkOptIn("ACCOUNTADDRESS", [12345n, 67890n], { maxFee: (1000).microAlgos(), suppressLog: true }) * ``` * @returns An array of records matching asset ID to transaction ID of the opt in */ @@ -521,9 +521,9 @@ export class AccountManager { * @example Example using AlgorandClient * ```typescript * // Basic example - * algorand.account.assetBulkOptOut("ACCOUNTADDRESS", [12345, 67890]) + * algorand.account.assetBulkOptOut("ACCOUNTADDRESS", [12345n, 67890n]) * // With configuration - * algorand.account.assetBulkOptOut("ACCOUNTADDRESS", [12345, 67890], { maxFee: (1000).microAlgos(), suppressLog: true }) + * algorand.account.assetBulkOptOut("ACCOUNTADDRESS", [12345n, 67890n], { ensureZeroBalance: true, maxFee: (1000).microAlgos(), suppressLog: true }) * ``` * @returns An array of records matching asset ID to transaction ID of the opt in */ @@ -606,8 +606,8 @@ export class AccountManager { * **Note:** Please be careful with this function and be sure to read the [official rekey guidance](https://developer.algorand.org/docs/get-details/accounts/rekey/). * * @param account The account to rekey - * @param rekeyTo The new address to rekey the account to, or a signing account that should now - * be tracked as the signer for `account` in this `AccountManager` + * @param rekeyTo The account address or signing account of the account that will be used to authorise transactions for the rekeyed account going forward. + * If a signing account is provided that will now be tracked as the signer for `account` in this `AccountManager` * @param options Any parameters to control the transaction or execution of the transaction * * @example Basic example (with string addresses) @@ -674,14 +674,14 @@ export class AccountManager { /** * Funds a given account using a dispenser account as a funding source such that - * the given account has a certain amount of algos free to spend (accounting for - * ALGOs locked in minimum balance requirement). + * the given account has a certain amount of Algos free to spend (accounting for + * Algos locked in minimum balance requirement). * * https://developer.algorand.org/docs/get-details/accounts/#minimum-balance * * @param accountToFund The account to fund * @param dispenserAccount The account to use as a dispenser funding source - * @param minSpendingBalance The minimum balance of ALGOs that the account should have available to spend (i.e. on top of minimum balance requirement) + * @param minSpendingBalance The minimum balance of Algos that the account should have available to spend (i.e. on top of minimum balance requirement) * @param options Optional parameters to control the funding increment, transaction or execution of the transaction * @example Example using AlgorandClient * ```typescript @@ -731,8 +731,8 @@ export class AccountManager { /** * Funds a given account using a dispenser account retrieved from the environment, * per the `dispenserFromEnvironment` method, as a funding source such that - * the given account has a certain amount of algos free to spend (accounting for - * ALGOs locked in minimum balance requirement). + * the given account has a certain amount of Algos free to spend (accounting for + * Algos locked in minimum balance requirement). * * **Note:** requires a Node.js environment to execute. * @@ -743,7 +743,7 @@ export class AccountManager { * https://developer.algorand.org/docs/get-details/accounts/#minimum-balance * * @param accountToFund The account to fund - * @param minSpendingBalance The minimum balance of ALGOs that the account should have available to spend (i.e. on top of minimum balance requirement) + * @param minSpendingBalance The minimum balance of Algos that the account should have available to spend (i.e. on top of minimum balance requirement) * @param options Optional parameters to control the funding increment, transaction or execution of the transaction * @example Example using AlgorandClient * ```typescript @@ -792,14 +792,14 @@ export class AccountManager { /** * Funds a given account using the TestNet Dispenser API as a funding source such that - * the account has a certain amount of algos free to spend (accounting for ALGOs locked + * the account has a certain amount of algos free to spend (accounting for Algos locked * in minimum balance requirement). * * https://developer.algorand.org/docs/get-details/accounts/#minimum-balance * * @param accountToFund The account to fund * @param dispenserClient The TestNet dispenser funding client - * @param minSpendingBalance The minimum balance of ALGOs that the account should have available to spend (i.e. on top of minimum balance requirement) + * @param minSpendingBalance The minimum balance of Algos that the account should have available to spend (i.e. on top of minimum balance requirement) * @param options Optional parameters to control the funding increment, transaction or execution of the transaction * @example Example using AlgorandClient * ```typescript diff --git a/src/types/algorand-client.transfer.spec.ts b/src/types/algorand-client.transfer.spec.ts index 06ccb674..1bf428c4 100644 --- a/src/types/algorand-client.transfer.spec.ts +++ b/src/types/algorand-client.transfer.spec.ts @@ -29,7 +29,7 @@ describe('Transfer capability', () => { sender: testAccount.addr, receiver: secondAccount.addr, amount: (5).algos(), - note: 'Transfer 5 ALGOs', + note: 'Transfer 5 Algos', }) const accountInfo = await algorand.account.getInformation(secondAccount.addr) diff --git a/src/types/algorand-client.ts b/src/types/algorand-client.ts index 9eb75d15..6f6e1e55 100644 --- a/src/types/algorand-client.ts +++ b/src/types/algorand-client.ts @@ -190,14 +190,14 @@ export class AlgorandClient { */ public send = { /** - * Send a payment transaction to transfer algos between accounts. + * Send a payment transaction to transfer Algos between accounts. * @param params The parameters for the payment transaction * @example Basic example * ```typescript * const result = await algorandClient.send.payment({ * sender: 'SENDERADDRESS', * receiver: 'RECEIVERADDRESS', - * amount: algosdk.algosToMicroalgos(1), + * amount: (4).algos(), * }) * ``` * @example Advanced example @@ -211,6 +211,7 @@ export class AlgorandClient { * note: 'note', * // Use this with caution, it's generally better to use algorand.account.rekeyAccount * rekeyTo: 'REKEYTOADDRESS', + * // You wouldn't normally set this field * firstValidRound: 1000n, * validityWindow: 10, * extraFee: (1000).microAlgos(), @@ -220,7 +221,7 @@ export class AlgorandClient { * maxFee: (3000).microAlgos(), * // Signer only needed if you want to provide one, * // generally you'd register it with AlgorandClient - * // against the sender nad not need to pass it in + * // against the sender and not need to pass it in * signer: transactionSigner, * maxRoundsToWaitForConfirmation: 5, * suppressLog: true, @@ -231,7 +232,7 @@ export class AlgorandClient { */ payment: this._send((c) => c.addPayment, { preLog: (params, transaction) => - `Sending ${params.amount.microAlgos} µALGOs from ${params.sender} to ${params.receiver} via transaction ${transaction.txID()}`, + `Sending ${params.amount.microAlgos} µAlgos from ${params.sender} to ${params.receiver} via transaction ${transaction.txID()}`, }), /** * Create a new Algorand Standard Asset. @@ -262,6 +263,7 @@ export class AlgorandClient { * clawback: 'CLAWBACKADDRESS', * lease: 'lease', * note: 'note', + * // You wouldn't normally set this field * firstValidRound: 1000n, * validityWindow: 10, * extraFee: (1000).microAlgos(), @@ -271,7 +273,7 @@ export class AlgorandClient { * maxFee: (3000).microAlgos(), * // Signer only needed if you want to provide one, * // generally you'd register it with AlgorandClient - * // against the sender nad not need to pass it in + * // against the sender and not need to pass it in * signer: transactionSigner, * maxRoundsToWaitForConfirmation: 5, * suppressLog: true, @@ -310,6 +312,7 @@ export class AlgorandClient { * clawback: 'CLAWBACKADDRESS', * lease: 'lease', * note: 'note', + * // You wouldn't normally set this field * firstValidRound: 1000n, * validityWindow: 10, * extraFee: (1000).microAlgos(), @@ -319,7 +322,7 @@ export class AlgorandClient { * maxFee: (3000).microAlgos(), * // Signer only needed if you want to provide one, * // generally you'd register it with AlgorandClient - * // against the sender nad not need to pass it in + * // against the sender and not need to pass it in * signer: transactionSigner, * maxRoundsToWaitForConfirmation: 5, * suppressLog: true, @@ -348,6 +351,7 @@ export class AlgorandClient { * frozen: true, * lease: 'lease', * note: 'note', + * // You wouldn't normally set this field * firstValidRound: 1000n, * validityWindow: 10, * extraFee: (1000).microAlgos(), @@ -357,7 +361,7 @@ export class AlgorandClient { * maxFee: (3000).microAlgos(), * // Signer only needed if you want to provide one, * // generally you'd register it with AlgorandClient - * // against the sender nad not need to pass it in + * // against the sender and not need to pass it in * signer: transactionSigner, * maxRoundsToWaitForConfirmation: 5, * suppressLog: true, @@ -388,6 +392,7 @@ export class AlgorandClient { * assetId: 123456n, * lease: 'lease', * note: 'note', + * // You wouldn't normally set this field * firstValidRound: 1000n, * validityWindow: 10, * extraFee: (1000).microAlgos(), @@ -397,7 +402,7 @@ export class AlgorandClient { * maxFee: (3000).microAlgos(), * // Signer only needed if you want to provide one, * // generally you'd register it with AlgorandClient - * // against the sender nad not need to pass it in + * // against the sender and not need to pass it in * signer: transactionSigner, * maxRoundsToWaitForConfirmation: 5, * suppressLog: true, @@ -429,6 +434,7 @@ export class AlgorandClient { * closeAssetTo: 'ADDRESSTOCLOSETO' * lease: 'lease', * note: 'note', + * // You wouldn't normally set this field * firstValidRound: 1000n, * validityWindow: 10, * extraFee: (1000).microAlgos(), @@ -438,7 +444,7 @@ export class AlgorandClient { * maxFee: (3000).microAlgos(), * // Signer only needed if you want to provide one, * // generally you'd register it with AlgorandClient - * // against the sender nad not need to pass it in + * // against the sender and not need to pass it in * signer: transactionSigner, * maxRoundsToWaitForConfirmation: 5, * suppressLog: true, @@ -466,6 +472,7 @@ export class AlgorandClient { * assetId: 123456n, * lease: 'lease', * note: 'note', + * // You wouldn't normally set this field * firstValidRound: 1000n, * validityWindow: 10, * extraFee: (1000).microAlgos(), @@ -475,7 +482,7 @@ export class AlgorandClient { * maxFee: (3000).microAlgos(), * // Signer only needed if you want to provide one, * // generally you'd register it with AlgorandClient - * // against the sender nad not need to pass it in + * // against the sender and not need to pass it in * signer: transactionSigner, * maxRoundsToWaitForConfirmation: 5, * suppressLog: true, @@ -506,13 +513,14 @@ export class AlgorandClient { * ``` * @example Advanced example * ```typescript - * await algorand.send.assetOptIn({ + * await algorand.send.assetOptOut({ * sender: 'SENDERADDRESS', * assetId: 123456n, * creator: 'CREATORADDRESS', * ensureZeroBalance: true, * lease: 'lease', * note: 'note', + * // You wouldn't normally set this field * firstValidRound: 1000n, * validityWindow: 10, * extraFee: (1000).microAlgos(), @@ -522,7 +530,7 @@ export class AlgorandClient { * maxFee: (3000).microAlgos(), * // Signer only needed if you want to provide one, * // generally you'd register it with AlgorandClient - * // against the sender nad not need to pass it in + * // against the sender and not need to pass it in * signer: transactionSigner, * maxRoundsToWaitForConfirmation: 5, * suppressLog: true, @@ -594,14 +602,14 @@ export class AlgorandClient { */ public transactions = { /** - * Create a payment transaction to transfer algos between accounts. + * Create a payment transaction to transfer Algos between accounts. * @param params The parameters for the payment transaction * @example Basic example * ```typescript * const result = await algorandClient.send.payment({ * sender: 'SENDERADDRESS', * receiver: 'RECEIVERADDRESS', - * amount: algosdk.algosToMicroalgos(1), + * amount: (4).algos(), * }) * ``` * @example Advanced example @@ -615,6 +623,7 @@ export class AlgorandClient { * note: 'note', * // Use this with caution, it's generally better to use algorand.account.rekeyAccount * rekeyTo: 'REKEYTOADDRESS', + * // You wouldn't normally set this field * firstValidRound: 1000n, * validityWindow: 10, * extraFee: (1000).microAlgos(), @@ -656,6 +665,7 @@ export class AlgorandClient { * clawback: 'CLAWBACKADDRESS', * lease: 'lease', * note: 'note', + * // You wouldn't normally set this field * firstValidRound: 1000n, * validityWindow: 10, * extraFee: (1000).microAlgos(), @@ -691,6 +701,7 @@ export class AlgorandClient { * clawback: 'CLAWBACKADDRESS', * lease: 'lease', * note: 'note', + * // You wouldn't normally set this field * firstValidRound: 1000n, * validityWindow: 10, * extraFee: (1000).microAlgos(), @@ -720,6 +731,7 @@ export class AlgorandClient { * frozen: true, * lease: 'lease', * note: 'note', + * // You wouldn't normally set this field * firstValidRound: 1000n, * validityWindow: 10, * extraFee: (1000).microAlgos(), @@ -751,6 +763,7 @@ export class AlgorandClient { * assetId: 123456n, * lease: 'lease', * note: 'note', + * // You wouldn't normally set this field * firstValidRound: 1000n, * validityWindow: 10, * extraFee: (1000).microAlgos(), @@ -783,6 +796,7 @@ export class AlgorandClient { * closeAssetTo: 'ADDRESSTOCLOSETO' * lease: 'lease', * note: 'note', + * // You wouldn't normally set this field * firstValidRound: 1000n, * validityWindow: 10, * extraFee: (1000).microAlgos(), @@ -810,6 +824,7 @@ export class AlgorandClient { * assetId: 123456n, * lease: 'lease', * note: 'note', + * // You wouldn't normally set this field * firstValidRound: 1000n, * validityWindow: 10, * extraFee: (1000).microAlgos(), @@ -842,6 +857,7 @@ export class AlgorandClient { * ensureZeroBalance: true, * lease: 'lease', * note: 'note', + * // You wouldn't normally set this field * firstValidRound: 1000n, * validityWindow: 10, * extraFee: (1000).microAlgos(), diff --git a/src/types/amount.spec.ts b/src/types/amount.spec.ts index f89a2f9b..fc99090d 100644 --- a/src/types/amount.spec.ts +++ b/src/types/amount.spec.ts @@ -4,10 +4,10 @@ import { AlgoAmount } from './amount' describe('amount', () => { test('toString on 1', () => { - expect(`${microAlgos(1)}`).toBe(`1 µALGO`) + expect(`${microAlgos(1)}`).toBe(`1 µAlgo`) }) test('toString on big amount', () => { - expect(`${algos(100)}`).toBe(`100,000,000 µALGOs`) + expect(`${algos(100)}`).toBe(`100,000,000 µAlgos`) }) test('microalgos to microalgos', () => { expect(microAlgos(100).microAlgos).toBe(100) diff --git a/src/types/amount.ts b/src/types/amount.ts index d5444d65..cabf0312 100644 --- a/src/types/amount.ts +++ b/src/types/amount.ts @@ -19,7 +19,7 @@ export class AlgoAmount { } toString(): string { - return `${this.microAlgos.toLocaleString('en-US')} µALGO${this.microAlgos === 1 ? '' : 's'}` + return `${this.microAlgos.toLocaleString('en-US')} µAlgo${this.microAlgos === 1 ? '' : 's'}` } /** valueOf allows you to use `AlgoAmount` in comparison operations such as `<` and `>=` etc., diff --git a/src/types/client-manager.ts b/src/types/client-manager.ts index a37c23de..8c692f2e 100644 --- a/src/types/client-manager.ts +++ b/src/types/client-manager.ts @@ -222,6 +222,21 @@ export class ClientManager { * @param typedClient The typed client type to use * @param details The details to resolve the app by creator address and name * @param cachedAppLookup A cached app lookup that matches a name to on-chain details; either this is needed or indexer is required to be passed in to this manager on construction. + * @example Use name in ARC-32 app spec + * ```typescript + * const appClient = algorand.client.getTypedAppClientByCreatorAndName(MyContractClient, { + * creatorAddress: "CREATORADDRESS", + * sender: alice, + * }) + * ``` + * @example Specify name + * ```typescript + * const appClient = algorand.client.getTypedAppClientByCreatorAndName(MyContractClient, { + * creatorAddress: "CREATORADDRESS", + * name: "contract-name", + * sender: alice, + * }) + * ``` * @returns The typed client instance */ public getTypedAppClientByCreatorAndName( @@ -236,6 +251,13 @@ export class ClientManager { * Returns a new typed client, resolving the app by app ID. * @param typedClient The typed client type to use * @param details The details to resolve the app by ID + * @example + * ```typescript + * const appClient = algorand.client.getTypedAppClientById(MyContractClient, { + * id: 12345, + * sender: alice, + * }) + * ``` * @returns The typed client instance */ public getTypedAppClientById(typedClient: TypedAppClient, details: TypedAppClientByIdDetails) { diff --git a/src/types/composer.ts b/src/types/composer.ts index a4053d52..f6d63f49 100644 --- a/src/types/composer.ts +++ b/src/types/composer.ts @@ -13,40 +13,48 @@ export const MAX_TRANSACTION_GROUP_SIZE = 16 /** Common parameters for defining a transaction. */ export type CommonTransactionParams = { - /** The address sending the transaction */ + /** The address of the account sending the transaction. */ sender: string - /** The function used to sign transactions */ + /** The function used to sign transaction(s); if not specified then + * an attempt will be made to find a registered signer for the + * given `sender` or use a default signer (if configured). + */ signer?: algosdk.TransactionSigner | TransactionSignerAccount /** Change the signing key of the sender to the given address. * * **Warning:** Please be careful with this parameter and be sure to read the [official rekey guidance](https://developer.algorand.org/docs/get-details/accounts/rekey/). */ rekeyTo?: string - /** Note to attach to the transaction */ + /** Note to attach to the transaction. Max of 1000 bytes. */ note?: Uint8Array | string - /** Prevent multiple transactions with the same lease being included within the validity window */ + /** Prevent multiple transactions with the same lease being included within the validity window. + * + * A [lease](https://developer.algorand.org/articles/leased-transactions-securing-advanced-smart-contract-design/) + * enforces a mutually exclusive transaction (useful to prevent double-posting and other scenarios). + */ lease?: Uint8Array | string - /** The transaction fee. In most cases you want to use `extraFee` unless setting the fee to 0 to be covered by another transaction */ + /** The static transaction fee. In most cases you want to use `extraFee` unless setting the fee to 0 to be covered by another transaction. */ staticFee?: AlgoAmount - /** The fee to pay IN ADDITION to the suggested fee. Useful for covering inner transaction fees */ + /** The fee to pay IN ADDITION to the suggested fee. Useful for covering inner transaction fees. */ extraFee?: AlgoAmount - /** Throw an error if the fee for the transaction is more than this amount */ + /** Throw an error if the fee for the transaction is more than this amount; prevents overspending on fees during high congestion periods. */ maxFee?: AlgoAmount - /** How many rounds the transaction should be valid for */ + /** How many rounds the transaction should be valid for, if not specified then the registered default validity window will be used. */ validityWindow?: number /** * Set the first round this transaction is valid. * If left undefined, the value from algod will be used. - * Only set this when you intentionally want this to be some time in the future + * + * We recommend you only set this when you intentionally want this to be some time in the future. */ firstValidRound?: bigint - /** The last round this transaction is valid. It is recommended to use validityWindow instead */ + /** The last round this transaction is valid. It is recommended to use `validityWindow` instead. */ lastValidRound?: bigint } /** Parameters to define a payment transaction. */ export type PaymentParams = CommonTransactionParams & { - /** That account that will receive the ALGO */ + /** The address of the account that will receive the Algos */ receiver: string /** Amount to send */ amount: AlgoAmount @@ -84,6 +92,38 @@ export type AssetCreateParams = CommonTransactionParams & { */ decimals?: number + /** The optional name of the asset. + * + * Max size is 32 bytes. + * + * This field can only be specified upon asset creation. + */ + assetName?: string + + /** The optional name of the unit of this asset (e.g. ticker name). + * + * Max size is 8 bytes. + * + * This field can only be specified upon asset creation. + */ + unitName?: string + + /** Specifies an optional URL where more information about the asset can be retrieved (e.g. metadata). + * + * Max size is 96 bytes. + * + * This field can only be specified upon asset creation. + */ + url?: string + + /** 32-byte hash of some metadata that is relevant to your asset and/or asset holders. + * + * The format of this metadata is up to the application. + * + * This field can only be specified upon asset creation. + */ + metadataHash?: string | Uint8Array + /** Whether the asset is frozen by default for all accounts. * Defaults to `false`. * @@ -137,38 +177,6 @@ export type AssetCreateParams = CommonTransactionParams & { * If not set (`undefined` or `""`) at asset creation or subsequently set to empty by the manager the field is permanently empty. */ clawback?: string - - /** The optional name of the unit of this asset (e.g. ticker name). - * - * Max size is 8 bytes. - * - * This field can only be specified upon asset creation. - */ - unitName?: string - - /** The optional name of the asset. - * - * Max size is 32 bytes. - * - * This field can only be specified upon asset creation. - */ - assetName?: string - - /** Specifies an optional URL where more information about the asset can be retrieved (e.g. metadata). - * - * Max size is 96 bytes. - * - * This field can only be specified upon asset creation. - */ - url?: string - - /** 32-byte hash of some metadata that is relevant to your asset and/or asset holders. - * - * The format of this metadata is up to the application. - * - * This field can only be specified upon asset creation. - */ - metadataHash?: string | Uint8Array } /** Parameters to define an asset reconfiguration transaction. @@ -178,23 +186,54 @@ export type AssetCreateParams = CommonTransactionParams & { * all fields are immutable from that point forward. */ export type AssetConfigParams = CommonTransactionParams & { - /** ID of the asset */ + /** ID of the asset to reconfigure */ assetId: bigint - /** The address that can change the manager, reserve, clawback, and freeze addresses. There will permanently be no manager if undefined or an empty string */ + /** The address of the optional account that can manage the configuration of the asset and destroy it. + * + * The configuration fields it can change are `manager`, `reserve`, `clawback`, and `freeze`. + * + * If not set (`undefined` or `""`) the asset will become permanently immutable. + */ manager: string | undefined - /** The address that holds the uncirculated supply */ + /** + * The address of the optional account that holds the reserve (uncirculated supply) units of the asset. + * + * This address has no specific authority in the protocol itself and is informational only. + * + * Some standards like [ARC-19](https://github.com/algorandfoundation/ARCs/blob/main/ARCs/arc-0019.md) + * rely on this field to hold meaningful data. + * + * It can be used in the case where you want to signal to holders of your asset that the uncirculated units + * of the asset reside in an account that is different from the default creator account. + * + * If not set (`undefined` or `""`) the field will become permanently empty. + */ reserve?: string - /** The address that can freeze the asset in any account. Freezing will be permanently disabled if undefined or an empty string. */ + /** + * The address of the optional account that can be used to freeze or unfreeze holdings of this asset for any account. + * + * If empty, freezing is not permitted. + * + * If not set (`undefined` or `""`) the field will become permanently empty. + */ freeze?: string - /** The address that can clawback the asset from any account. Clawback will be permanently disabled if undefined or an empty string. */ + /** + * The address of the optional account that can clawback holdings of this asset from any account. + * + * **This field should be used with caution** as the clawback account has the ability to **unconditionally take assets from any account**. + * + * If empty, clawback is not permitted. + * + * If not set (`undefined` or `""`) the field will become permanently empty. + */ clawback?: string } /** Parameters to define an asset freeze transaction. */ export type AssetFreezeParams = CommonTransactionParams & { - /** The ID of the asset */ + /** The ID of the asset to freeze/unfreeze */ assetId: bigint - /** The account to freeze or unfreeze */ + /** The address of the account to freeze or unfreeze */ account: string /** Whether the assets in the account should be frozen */ frozen: boolean @@ -205,45 +244,45 @@ export type AssetFreezeParams = CommonTransactionParams & { * Created assets can be destroyed only by the asset manager account. All of the assets must be owned by the creator of the asset before the asset can be deleted. */ export type AssetDestroyParams = CommonTransactionParams & { - /** ID of the asset */ + /** ID of the asset to destroy */ assetId: bigint } /** Parameters to define an asset transfer transaction. */ export type AssetTransferParams = CommonTransactionParams & { - /** ID of the asset */ + /** ID of the asset to transfer. */ assetId: bigint - /** Amount of the asset to transfer (smallest divisible unit) */ + /** Amount of the asset to transfer (in smallest divisible (decimal) units). */ amount: bigint - /** The account to send the asset to */ + /** The address of the account that will receive the asset unit(s). */ receiver: string - /** The account to take the asset from. + /** Optional address of an account to clawback the asset from. * * Requires the sender to be the clawback account. * - * *Warning:* Be careful with this parameter as it can lead to unexpected loss of funds if not used correctly. + * **Warning:** Be careful with this parameter as it can lead to unexpected loss of funds if not used correctly. */ clawbackTarget?: string - /** The account to close the asset to + /** Optional address of an account to close the asset position to. * - * *Warning:* Be careful with this parameter as it can lead to loss of funds if not used correctly. + * **Warning:** Be careful with this parameter as it can lead to loss of funds if not used correctly. */ closeAssetTo?: string } /** Parameters to define an asset opt-in transaction. */ export type AssetOptInParams = CommonTransactionParams & { - /** ID of the asset */ + /** ID of the asset that will be opted-in to. */ assetId: bigint } /** Parameters to define an asset opt-out transaction. */ export type AssetOptOutParams = CommonTransactionParams & { - /** ID of the asset */ + /** ID of the asset that will be opted-out of. */ assetId: bigint /** * The address of the asset creator account to close the asset - * position to (any remaining asset units will be sent to this account) + * position to (any remaining asset units will be sent to this account). */ creator: string } @@ -341,7 +380,7 @@ type Txn = export interface ExecuteParams { /** The number of rounds to wait for confirmation. By default until the latest lastValid has past. */ maxRoundsToWaitForConfirmation?: number - /** Whether to suppress log messages from transaction send, default: do not suppress */ + /** Whether to suppress log messages from transaction send, default: do not suppress. */ suppressLog?: boolean } diff --git a/src/types/dispenser-client.spec.ts b/src/types/dispenser-client.spec.ts index 9e1b2240..d4276a71 100644 --- a/src/types/dispenser-client.spec.ts +++ b/src/types/dispenser-client.spec.ts @@ -13,7 +13,7 @@ describe('TestNetDispenserApiClient', () => { afterEach(() => { process.env = env }) - it('should fund account with algos with auth token', async () => { + it('should fund account with Algos with auth token', async () => { const mockResponse = { txID: 'dummy_tx_id', amount: 1 } fetchMock.mockResponseOnce(JSON.stringify(mockResponse)) diff --git a/src/types/dispenser-client.ts b/src/types/dispenser-client.ts index c107d981..5b1c3b98 100644 --- a/src/types/dispenser-client.ts +++ b/src/types/dispenser-client.ts @@ -14,17 +14,25 @@ const dispenserAssets = { }, } +/** The TestNet Dispenser API response when funding. */ export interface DispenserFundResponse { + /** The ID of the transaction that was issued to fund the account. */ txId: string + /** The number of microAlgos that was funded. */ amount: number } +/** The TestNet Dispenser API response when getting the current limit. */ export interface DispenserLimitResponse { + /** The limit, in microAlgos, that you can currently fund. */ amount: number } +/** The parameters to construct a TestNet Dispenser API client. */ export interface TestNetDispenserApiClientParams { + /** The API auth token */ authToken: string + /** The request timeout in seconds */ requestTimeout?: number } diff --git a/src/types/kmd-account-manager.ts b/src/types/kmd-account-manager.ts index 9672fe3d..c83e2127 100644 --- a/src/types/kmd-account-manager.ts +++ b/src/types/kmd-account-manager.ts @@ -156,7 +156,7 @@ export class KmdAccountManager { Config.logger.info( `LocalNet account '${name}' doesn't yet exist; created account ${account.addr} with keys stored in KMD and funding with ${ fundWith?.algos ?? 1000 - } ALGOs`, + } Algos`, ) // Fund the account from the dispenser diff --git a/src/types/testing.ts b/src/types/testing.ts index c691dc98..067ed5e8 100644 --- a/src/types/testing.ts +++ b/src/types/testing.ts @@ -57,7 +57,7 @@ export interface AlgorandFixtureConfig extends Partial { indexer?: Indexer /** An optional kmd client, if not specified then it will create one against `kmdConfig` (if present) then environment variables defined network (if present) or default LocalNet. */ kmd?: Kmd - /** The amount of funds to allocate to the default testing account, if not specified then it will get 10 ALGOs. */ + /** The amount of funds to allocate to the default testing account, if not specified then it will get 10 Algos. */ testAccountFunding?: AlgoAmount /** Optional override for how to get an account; this allows you to retrieve accounts from a known or cached list of accounts. */ accountGetter?: (algod: Algodv2, kmd?: Kmd) => Promise diff --git a/src/types/transfer.ts b/src/types/transfer.ts index 748d600e..f1e92436 100644 --- a/src/types/transfer.ts +++ b/src/types/transfer.ts @@ -6,9 +6,9 @@ import SuggestedParams = algosdk.SuggestedParams /** @deprecated Parameters for `transferAlgos` call. */ export interface AlgoTransferParams extends SendTransactionParams { - /** The account that will send the ALGOs */ + /** The account that will send the Algos */ from: SendTransactionFrom - /** The account / account address that will receive the ALGOs */ + /** The account / account address that will receive the Algos */ to: SendTransactionFrom | string /** The amount to send */ amount: AlgoAmount @@ -40,7 +40,7 @@ export interface EnsureFundedParams extends SendTransactionParams { accountToFund: SendTransactionFrom | string /** The account to use as a funding source, will default to using the dispenser account returned by `algokit.getDispenserAccount` */ fundingSource?: SendTransactionFrom | TestNetDispenserApiClient - /** The minimum balance of ALGOs that the account should have available to spend (i.e. on top of minimum balance requirement) */ + /** The minimum balance of Algos that the account should have available to spend (i.e. on top of minimum balance requirement) */ minSpendingBalance: AlgoAmount /** When issuing a funding amount, the minimum amount to transfer (avoids many small transfers if this gets called often on an active account) */ minFundingIncrement?: AlgoAmount From 54b59faf8896f7cd5b3ffaf1c64de573fe31a021 Mon Sep 17 00:00:00 2001 From: "Rob Moore (MakerX)" Date: Wed, 21 Aug 2024 17:12:00 +0800 Subject: [PATCH 06/18] docs: PR feedback - docs tweaks and consistent Algo/ALGO use according to brand guidelines --- docs/README.md | 2 +- docs/capabilities/account.md | 6 ++-- docs/capabilities/algorand-client.md | 2 +- docs/capabilities/amount.md | 20 ++++++------ docs/capabilities/asset.md | 4 +-- docs/capabilities/dispenser-client.md | 4 +-- docs/capabilities/testing.md | 6 ++-- docs/capabilities/transaction.md | 2 +- docs/capabilities/transfer.md | 18 +++++------ .../types_account_manager.AccountManager.md | 20 ++++++------ docs/code/classes/types_amount.AlgoAmount.md | 10 +++--- .../types_app_client.ApplicationClient.md | 2 +- ...penser_client.TestNetDispenserApiClient.md | 4 +-- ...s_kmd_account_manager.KmdAccountManager.md | 4 +-- ..._dispenser_client.DispenserFundResponse.md | 2 +- ...dispenser_client.DispenserLimitResponse.md | 2 +- .../interfaces/types_indexer.AccountResult.md | 10 +++--- .../types_indexer.PaymentTransactionResult.md | 4 +-- .../types_network_client.AlgoConfig.md | 2 +- .../types_testing.AlgorandFixtureConfig.md | 4 +-- .../types_transfer.AlgoTransferParams.md | 4 +-- .../types_transfer.EnsureFundedParams.md | 2 +- docs/code/modules/index.md | 32 +++++++++---------- docs/code/modules/testing.md | 2 +- docs/code/modules/types_account.md | 10 +++--- src/account/account.ts | 4 +-- src/account/get-account.ts | 12 +++---- src/amount.ts | 12 +++---- .../get-or-create-kmd-wallet-account.ts | 2 +- src/testing/account.ts | 2 +- src/testing/fixtures/algorand-fixture.ts | 2 +- src/transaction/transaction.spec.ts | 4 +-- src/transaction/transaction.ts | 6 ++-- src/transfer/transfer-algos.ts | 2 +- src/transfer/transfer.ts | 2 +- src/types/account-manager.ts | 20 ++++++------ src/types/account.ts | 10 +++--- src/types/algorand-client.ts | 10 +++--- src/types/amount.spec.ts | 4 +-- src/types/amount.ts | 12 +++---- src/types/app-client.ts | 2 +- src/types/composer.ts | 2 +- src/types/dispenser-client.spec.ts | 2 +- src/types/dispenser-client.ts | 8 ++--- src/types/indexer.ts | 14 ++++---- src/types/kmd-account-manager.ts | 6 ++-- src/types/network-client.ts | 2 +- src/types/testing.ts | 2 +- src/types/transfer.ts | 6 ++-- 49 files changed, 163 insertions(+), 163 deletions(-) diff --git a/docs/README.md b/docs/README.md index 92fe3ccf..57d092c6 100644 --- a/docs/README.md +++ b/docs/README.md @@ -166,7 +166,7 @@ The library helps you interact with and develop against the Algorand blockchain - [**ARC-0032 Application Spec client**](./capabilities/app-client.md) - Builds on top of the App management and App deployment capabilities (below) to provide a high productivity application client that works with ARC-0032 application spec defined smart contracts - [**App management**](./capabilities/app.md) - Creation, updating, deleting, calling (ABI and otherwise) smart contract apps and the metadata associated with them (including state and boxes) - [**App deployment**](./capabilities/app-deploy.md) - Idempotent (safely retryable) deployment of an app, including deploy-time immutability and permanence control and TEAL template substitution - - [**Algo transfers (payments)**](./capabilities/transfer.md) - Ability to easily initiate algo transfers between accounts, including dispenser management and idempotent account funding + - [**Algo transfers (payments)**](./capabilities/transfer.md) - Ability to easily initiate Algo transfers between accounts, including dispenser management and idempotent account funding - [**Automated testing**](./capabilities/testing.md) - Terse, robust automated testing primitives that work across any testing framework (including jest and vitest) to facilitate fixture management, quickly generating isolated and funded test accounts, transaction logging, indexer wait management and log capture - [**Indexer lookups / searching**](./capabilities/indexer.md) - Type-safe indexer API wrappers (no `Record` pain from the SDK client), including automatic pagination control diff --git a/docs/capabilities/account.md b/docs/capabilities/account.md index f74f5c13..a62eaabe 100644 --- a/docs/capabilities/account.md +++ b/docs/capabilities/account.md @@ -47,7 +47,7 @@ In order to get/register accounts for signing operations you can use the followi - [`algorand.account.fromEnvironment(name, fundWith)`](../code/classes/types_account_manager.AccountManager.md#fromenvironment) - Registers and returns an account with private key loaded by convention based on the given name identifier - either by idempotently creating the account in KMD or from environment variable via `process.env['{NAME}_MNEMONIC']` and (optionally) `process.env['{NAME}_SENDER']` (if account is rekeyed) - This allows you to have powerful code that will automatically create and fund an account by name locally and when deployed against TestNet/MainNet will automatically resolve from environment variables, without having to have different code - - Note: `fundWith` allows you to control how many Algos are seeded into an account created in KMD + - Note: `fundWith` allows you to control how many Algo are seeded into an account created in KMD - [`algorand.account.fromMnemonic(mnemonicSecret, sender?)`](../code/classes/types_account_manager.AccountManager.md#frommnemonic) - Registers and returns an account with secret key loaded by taking the mnemonic secret - [`algorand.account.multisig(multisigParams, signingAccounts)`](../code/classes/types_account_manager.AccountManager.md#multisig) - Registers and returns a multisig account with one or more signing keys loaded - [`algorand.account.rekeyed(sender, signer)`](../code/classes/types_account_manager.AccountManager.md#rekeyed) - Registers and returns an account representing the given rekeyed sender/signer combination @@ -117,7 +117,7 @@ const rekeyedAccount = algokit.rekeyedAccount(newAccount, account.addr) When running LocalNet, you have an instance of the [Key Management Daemon](https://github.com/algorand/go-algorand/blob/master/daemon/kmd/README.md), which is useful for: -- Accessing the private key of the default accounts that are pre-seeded with Algos so that other accounts can be funded and it's possible to use LocalNet +- Accessing the private key of the default accounts that are pre-seeded with Algo so that other accounts can be funded and it's possible to use LocalNet - Idempotently creating new accounts against a name that will stay intact while the LocalNet instance is running without you needing to store private keys anywhere (i.e. completely automated) The KMD SDK is fairly low level so to make use of it there is a fair bit of boilerplate code that's needed. This code has been abstracted away into the `KmdAccountManager` class. @@ -146,7 +146,7 @@ const defaultDispenserAccount = await kmdAccountManager.getWalletAccount( // Same as above, but dedicated method call for convenience const localNetDispenserAccount = await kmdAccountManager.getLocalNetDispenserAccount() // Idempotently get (if exists) or create (if it doesn't exist yet) an account by name using KMD -// if creating it then fund it with 2 Algos from the default dispenser account +// if creating it then fund it with 2 ALGO from the default dispenser account const newAccount = await kmdAccountManager.getOrCreateWalletAccount('account1', (2).algos()) // This will return the same account as above since the name matches const existingAccount = await kmdAccountManager.getOrCreateWalletAccount('account1') diff --git a/docs/capabilities/algorand-client.md b/docs/capabilities/algorand-client.md index 279edd8c..8cddd70f 100644 --- a/docs/capabilities/algorand-client.md +++ b/docs/capabilities/algorand-client.md @@ -41,7 +41,7 @@ const kmdClient = algorand.client.kmd The `AlgorandClient` has a number of manager class instances that help you quickly use intellisense to get access to advanced functionality. -- [`AccountManager`](./account.md) via `algorand.account`, there are also some convenience methods that wrap some methods within `AccountManager` that return `AlgorandClient` and thus allow for method chaining: +- [`AccountManager`](./account.md) via `algorand.account`, there are also some chainable convenience methods which wrap specific methods in `AccountManager`: - `algorand.setDefaultSigner(signer)` - - `algorand.setSignerFromAccount(account)` - - `algorand.setSigner(sender, signer)` diff --git a/docs/capabilities/amount.md b/docs/capabilities/amount.md index 4bde93e1..cfbcefb2 100644 --- a/docs/capabilities/amount.md +++ b/docs/capabilities/amount.md @@ -1,14 +1,14 @@ # Algo amount handling -Algo amount handling is one of the core capabilities provided by AlgoKit Utils. It allows you to reliably and tersely specify amounts of microAlgos and Algos and safely convert between them. +Algo amount handling is one of the core capabilities provided by AlgoKit Utils. It allows you to reliably and tersely specify amounts of microAlgo and Algo and safely convert between them. -Any AlgoKit Utils function that needs an Algo amount will take an `AlgoAmount` object, which ensures that there is never any confusion about what value is being passed around. Whenever an AlgoKit Utils function calls into an underlying algosdk function, or if you need to take an `AlgoAmount` and pass it into an underlying algosdk function (per the [modularity principle](../README.md#core-principles)) you can safely and explicitly convert to microAlgos or Algos. +Any AlgoKit Utils function that needs an Algo amount will take an `AlgoAmount` object, which ensures that there is never any confusion about what value is being passed around. Whenever an AlgoKit Utils function calls into an underlying algosdk function, or if you need to take an `AlgoAmount` and pass it into an underlying algosdk function (per the [modularity principle](../README.md#core-principles)) you can safely and explicitly convert to microAlgo or Algo. To see some usage examples check out the [automated tests](../../src/types/amount.spec.ts). Alternatively, you see the [reference documentation](../code/classes/types_amount.AlgoAmount.md) for `AlgoAmount`. ## `AlgoAmount` -The `AlgoAmount` class provides a safe wrapper around an underlying `number` amount of microAlgos where any value entering or existing the `AlgoAmount` class must be explicitly stated to be in microAlgos or Algos. This makes it much safer to handle Algo amounts rather than passing them around as raw `number`'s where it's easy to make a (potentially costly!) mistake and not perform a conversion when one is needed (or perform one when it shouldn't be!). +The `AlgoAmount` class provides a safe wrapper around an underlying `number` amount of microAlgo where any value entering or existing the `AlgoAmount` class must be explicitly stated to be in microAlgo or Algo. This makes it much safer to handle Algo amounts rather than passing them around as raw `number`'s where it's easy to make a (potentially costly!) mistake and not perform a conversion when one is needed (or perform one when it shouldn't be!). To import the AlgoAmount class you can access it via: @@ -22,12 +22,12 @@ You may not need to import this type to use it though since there are also speci There are a few ways to create an `AlgoAmount`: -- Algos +- Algo - Constructor: `new AlgoAmount({algos: 10})` - Static helper: `AlgoAmount.algos(10)` - AlgoKit Helper: `algokit.algos(10)` - Number coersion: `(10).algos()` (note: you have to wrap the number in brackets or have it in a variable or function return, a raw number value can't have a method called on it) -- microAlgos +- microAlgo - Constructor: `new AlgoAmount({microAlgos: 10_000})` - Static helper: `AlgoAmount.algos(10)` - AlgoKit Helper: `algokit.microAlgos(10_000)` @@ -41,11 +41,11 @@ import { AlgoAmount } from '@algorandfoundation/algokit-utils/types/amount' ### Extracting a value from `AlgoAmount` -The `AlgoAmount` class has methods to return Algos and microAlgos: +The `AlgoAmount` class has methods to return Algo and microAlgo: -- `amount.algos()` - Returns the value in Algos -- `amount.microAlgos()` - Returns the value in microAlgos +- `amount.algos()` - Returns the value in Algo +- `amount.microAlgos()` - Returns the value in microAlgo -`AlgoAmount` will coerce to a `number` automatically (in microAlgos), which is not recommended to be used outside of allowing you to use `AlgoAmount` objects in comparison operations such as `<` and `>=` etc. +`AlgoAmount` will coerce to a `number` automatically (in microAlgo), which is not recommended to be used outside of allowing you to use `AlgoAmount` objects in comparison operations such as `<` and `>=` etc. -You can also call `.toString()` or use an `AlgoAmount` directly in string interpolation to convert it to a nice user-facing formatted amount expressed in microAlgos. +You can also call `.toString()` or use an `AlgoAmount` directly in string interpolation to convert it to a nice user-facing formatted amount expressed in microAlgo. diff --git a/docs/capabilities/asset.md b/docs/capabilities/asset.md index 145aede0..e0bd2b3a 100644 --- a/docs/capabilities/asset.md +++ b/docs/capabilities/asset.md @@ -76,7 +76,7 @@ await algorand.send.assetCreate({ ## Reconfigure -If you have a `manager` address set on an asset, that address can end a reconfiguration transaction to change the `manager`, `reserve`, `freeze` and `clawback` fields of the asset if they haven't been set to empty. +If you have a `manager` address set on an asset, that address can send a reconfiguration transaction to change the `manager`, `reserve`, `freeze` and `clawback` fields of the asset if they haven't been set to empty. > [!WARNING] > If you issue a reconfigure transaction and don't set the _existing_ values for any of the below fields then that field will be permanently set to empty. @@ -100,7 +100,7 @@ await algorand.send.assetConfig({ sender: 'MANAGERADDRESS', assetId: 123456n, ma // Advanced example -await algorand.send.assetCreate({ +await algorand.send.assetConfig({ sender: 'MANAGERADDRESS', assetId: 123456n, manager: 'MANAGERADDRESS', diff --git a/docs/capabilities/dispenser-client.md b/docs/capabilities/dispenser-client.md index 0df12e1b..f2fe4644 100644 --- a/docs/capabilities/dispenser-client.md +++ b/docs/capabilities/dispenser-client.md @@ -52,7 +52,7 @@ const clientFromAlgorandClient = algorand.client.getTestNetDispenserFromEnvironm ## Funding an Account -To fund an account with Algos from the dispenser API, use the `fund` method. This method requires the receiver's address, the amount to be funded, and the asset ID. +To fund an account with Algo from the dispenser API, use the `fund` method. This method requires the receiver's address, the amount to be funded, and the asset ID. ```ts const response = await client.fund('receiver_address', 1000) @@ -72,7 +72,7 @@ await client.refund('transaction_id') ## Getting Current Limit -To get the current limit for an account with Algos from the dispenser API, use the `getLimit` method. This method requires the account address. +To get the current limit for an account with Algo from the dispenser API, use the `getLimit` method. This method requires the account address. ```ts const response = await client.getLimit() diff --git a/docs/capabilities/testing.md b/docs/capabilities/testing.md index a439bba3..38973ecc 100644 --- a/docs/capabilities/testing.md +++ b/docs/capabilities/testing.md @@ -71,7 +71,7 @@ When calling `algorandFixture()` you can optionally pass in some fixture configu - `algod?: Algodv2` - An optional algod client, if not specified then it will create one against environment variables defined network (if present) or default LocalNet - `indexer?: Indexer` - An optional indexer client, if not specified then it will create one against environment variables defined network (if present) or default LocalNet - `kmd?: Kmd` - An optional kmd client, if not specified then it will create one against environment variables defined network (if present) or default LocalNet -- `testAccountFunding?: AlgoAmount` - The [amount](./amount.md) of funds to allocate to the default testing account, if not specified then it will get `10` Algos +- `testAccountFunding?: AlgoAmount` - The [amount](./amount.md) of funds to allocate to the default testing account, if not specified then it will get `10` ALGO ### Using the fixture context @@ -191,14 +191,14 @@ The easiest way to use this functionality is via the [Algorand fixture](#algoran ## Getting a test account -When testing, it's often useful to ephemerally generate random accounts, fund them with some number of Algos and then use that account to perform transactions. By creating an ephemeral, random account you naturally get isolation between tests and test runs and don't need to start from a specific blockchain network state. This makes test less flakey, and also means the same test can be run against LocalNet and (say) TestNet. +When testing, it's often useful to ephemerally generate random accounts, fund them with some number of Algo and then use that account to perform transactions. By creating an ephemeral, random account you naturally get isolation between tests and test runs and don't need to start from a specific blockchain network state. This makes test less flakey, and also means the same test can be run against LocalNet and (say) TestNet. The key when generating a test account is getting hold of a [dispenser](./transfer.md#dispenser) and then [ensuring the test account is funded](./transfer.md#ensurefunded). To make it easier to quickly get a test account the testing capability provides the following mechanisms: - [`algotesting.getTestAccount(testAccountParams, algod, kmd?)`](../code/modules/testing.md#gettestaccount) - Generates a random new account, logs the mnemonic of the account (unless suppressed), funds it from the [dispenser](./transfer.md#dispenser) -- `algorandFixture.testAccount` - A test account that is always generated for every test (log output suppressed to reduce noise, but worth noting that means the mnemonic isn't logged for this account), by default it is given 10 Algos unless overridden in the [fixture config](#fixture-configuration) +- `algorandFixture.testAccount` - A test account that is always generated for every test (log output suppressed to reduce noise, but worth noting that means the mnemonic isn't logged for this account), by default it is given 10 Algo unless overridden in the [fixture config](#fixture-configuration) - [`algorandFixture.generateAccount(testAccountParams)`](../code/interfaces/types_testing.AlgorandTestAutomationContext.md#generateaccount) - Allows you to quickly generate a test account with the `algod` and `kmd` instances that are part of the given fixture The parameters object that controls test account generation, [`GetTestAccountParams`](../code/interfaces/types_testing.GetTestAccountParams.md), has the following properties: diff --git a/docs/capabilities/transaction.md b/docs/capabilities/transaction.md index 4d2a2bdc..eb9b43bb 100644 --- a/docs/capabilities/transaction.md +++ b/docs/capabilities/transaction.md @@ -70,7 +70,7 @@ There is a [`algokit.waitForConfirmation(transactionId, maxRoundsToWait, algod)` If you want to control the fees of a transaction before sending then you can use: -- [`algokit.capTransactionFee(transaction, maxAcceptableFee)`](../code/modules/index.md#captransactionfee) - Limit the acceptable maximum fee of a `algosdk.Transaction` or `algosdk.SuggestedParams` to a defined amount of algos. +- [`algokit.capTransactionFee(transaction, maxAcceptableFee)`](../code/modules/index.md#captransactionfee) - Limit the acceptable maximum fee of a `algosdk.Transaction` or `algosdk.SuggestedParams` to a defined amount of Algo. - [`algokit.controlFees(transaction, feeControl)`](../code/modules/index.md#controlfees) - Allows you to control fees on a `algosdk.Transaction` or `algosdk.SuggestedParams` object either applying a flat fee or a max fee ### Transaction notes diff --git a/docs/capabilities/transfer.md b/docs/capabilities/transfer.md index 36575071..b8a2bc85 100644 --- a/docs/capabilities/transfer.md +++ b/docs/capabilities/transfer.md @@ -10,8 +10,8 @@ The key function to facilitate Algo transfers is `algorand.send.payment(params)` The base type for specifying a payment transaction is [`PaymentParams`](../code/modules/types_composer.md#paymentparams), which has the following parameters in addition to the [common transaction parameters](./algorand-client.md#transaction-parameters): -- `receiver: string` - The address of the account that will receive the Algos -- `amount: AlgoAmount` - The amount of Algos to send +- `receiver: string` - The address of the account that will receive the Algo +- `amount: AlgoAmount` - The amount of Algo to send - `closeRemainderTo?: string` - If given, close the sender account and send the remaining balance to this address (**warning:** use this carefully as it can result in loss of funds if used incorrectly) ```typescript @@ -51,16 +51,16 @@ const result2 = await algorand.send.payment({ ## `ensureFunded` -The `ensureFunded` function automatically funds an account to maintain a minimum amount of [disposable Algos](https://developer.algorand.org/docs/get-details/accounts/#minimum-balance). This is particularly useful for automation and deployment scripts that get run multiple times and consume Algos when run. +The `ensureFunded` function automatically funds an account to maintain a minimum amount of [disposable Algo](https://developer.algorand.org/docs/get-details/accounts/#minimum-balance). This is particularly useful for automation and deployment scripts that get run multiple times and consume Algo when run. There are 3 variants of this function: -- [`algorand.account.ensureFunded(accountToFund, dispenserAccount, minSpendingBalance, options?)`](../code/classes/types_account_manager.AccountManager.md#ensurefunded) - Funds a given account using a dispenser account as a funding source such that the given account has a certain amount of Algos free to spend (accounting for Algos locked in minimum balance requirement). -- [`algorand.account.ensureFundedFromEnvironment(accountToFund, minSpendingBalance, options?)`](../code/classes/types_account_manager.AccountManager.md#ensurefundedfromenvironment) - Funds a given account using a dispenser account retrieved from the environment, per the [`dispenserFromEnvironment`](#dispenser) method, as a funding source such that the given account has a certain amount of Algos free to spend (accounting for Algos locked in minimum balance requirement). +- [`algorand.account.ensureFunded(accountToFund, dispenserAccount, minSpendingBalance, options?)`](../code/classes/types_account_manager.AccountManager.md#ensurefunded) - Funds a given account using a dispenser account as a funding source such that the given account has a certain amount of Algo free to spend (accounting for Algo locked in minimum balance requirement). +- [`algorand.account.ensureFundedFromEnvironment(accountToFund, minSpendingBalance, options?)`](../code/classes/types_account_manager.AccountManager.md#ensurefundedfromenvironment) - Funds a given account using a dispenser account retrieved from the environment, per the [`dispenserFromEnvironment`](#dispenser) method, as a funding source such that the given account has a certain amount of Algo free to spend (accounting for Algo locked in minimum balance requirement). - **Note:** requires a Node.js environment to execute. - The dispenser account is retrieved from the account mnemonic stored in `process.env.DISPENSER_MNEMONIC` and optionally `process.env.DISPENSER_SENDER` if it's a rekeyed account, or against default LocalNet if no environment variables present. -- [`algorand.account.ensureFundedFromTestNetDispenserApi(accountToFund, dispenserClient, minSpendingBalance, options)`](../code/classes/types_account_manager.AccountManager.md#ensurefundedfromtestnetdispenserapi) - Funds a given account using the [TestNet Dispenser API](https://github.com/algorandfoundation/algokit/blob/main/docs/testnet_api.md) as a funding source such that the account has a certain amount of Algos free to spend (accounting for Algos locked in minimum balance requirement). +- [`algorand.account.ensureFundedFromTestNetDispenserApi(accountToFund, dispenserClient, minSpendingBalance, options)`](../code/classes/types_account_manager.AccountManager.md#ensurefundedfromtestnetdispenserapi) - Funds a given account using the [TestNet Dispenser API](https://github.com/algorandfoundation/algokit/blob/main/docs/testnet_api.md) as a funding source such that the account has a certain amount of Algo free to spend (accounting for Algo locked in minimum balance requirement). The general structure of these calls is similar, they all take: @@ -69,7 +69,7 @@ The general structure of these calls is similar, they all take: - In `ensureFunded`: `dispenserAccount: string | TransactionSignerAccount` - the address or signing account of the account to use as a dispenser - In `ensureFundedFromEnvironment`: Not specified, loaded automatically from the ephemeral environment - In `ensureFundedFromTestNetDispenserApi`: `dispenserClient: TestNetDispenserApiClient` - a client instance of the [TestNet dispenser API](./dispenser-client.md) -- `minSpendingBalance: AlgoAmount` - The minimum balance of Algos that the account should have available to spend (i.e., on top of the minimum balance requirement) +- `minSpendingBalance: AlgoAmount` - The minimum balance of Algo that the account should have available to spend (i.e., on top of the minimum balance requirement) - An `options` object, which has: - [Common transaction parameters](./algorand-client.md#transaction-parameters) (not for TestNet Dispenser API) - [Execution parameters](./algorand-client.md#sending-a-single-transaction) (not for TestNet Dispenser API) @@ -119,14 +119,14 @@ await algorand.account.ensureFundedUsingDispenserAPI( All 3 variants return an [`EnsureFundedReturnType`](../code/modules/types_account_manager.md#) (and the first two also return a [single transaction result](./algorand-client.md#sending-a-single-transaction)) if a funding transaction was needed, or `undefined` if no transaction was required: -- `amountFunded: AlgoAmount` - The number of Algos that was paid +- `amountFunded: AlgoAmount` - The number of Algo that was paid - `transactionId: string` - The ID of the transaction that funded the account If you are using the TestNet Dispenser API then the `transactionId` is useful if you want to use the [refund functionality](./dispenser-client.md#registering-a-refund). ## Dispenser -If you want to programmatically send funds to an account so it can transact then you will often need a "dispenser" account that has a store of Algos that can be sent and a private key available for that dispenser account. +If you want to programmatically send funds to an account so it can transact then you will often need a "dispenser" account that has a store of Algo that can be sent and a private key available for that dispenser account. There's a number of ways to get a dispensing account in AlgoKit Utils: diff --git a/docs/code/classes/types_account_manager.AccountManager.md b/docs/code/classes/types_account_manager.AccountManager.md index 93724efb..21558990 100644 --- a/docs/code/classes/types_account_manager.AccountManager.md +++ b/docs/code/classes/types_account_manager.AccountManager.md @@ -292,8 +292,8 @@ ___ ▸ **ensureFunded**(`accountToFund`, `dispenserAccount`, `minSpendingBalance`, `options?`): `Promise`\<`undefined` \| [`SendAtomicTransactionComposerResults`](../interfaces/types_transaction.SendAtomicTransactionComposerResults.md) & [`ConfirmedTransactionResult`](../interfaces/types_transaction.ConfirmedTransactionResult.md) & [`EnsureFundedResult`](../interfaces/types_account_manager.EnsureFundedResult.md)\> Funds a given account using a dispenser account as a funding source such that -the given account has a certain amount of Algos free to spend (accounting for -Algos locked in minimum balance requirement). +the given account has a certain amount of Algo free to spend (accounting for +Algo locked in minimum balance requirement). https://developer.algorand.org/docs/get-details/accounts/#minimum-balance @@ -303,7 +303,7 @@ https://developer.algorand.org/docs/get-details/accounts/#minimum-balance | :------ | :------ | :------ | | `accountToFund` | `string` \| [`TransactionSignerAccount`](../interfaces/types_account.TransactionSignerAccount.md) | The account to fund | | `dispenserAccount` | `string` \| [`TransactionSignerAccount`](../interfaces/types_account.TransactionSignerAccount.md) | The account to use as a dispenser funding source | -| `minSpendingBalance` | [`AlgoAmount`](types_amount.AlgoAmount.md) | The minimum balance of Algos that the account should have available to spend (i.e. on top of minimum balance requirement) | +| `minSpendingBalance` | [`AlgoAmount`](types_amount.AlgoAmount.md) | The minimum balance of Algo that the account should have available to spend (i.e. on top of minimum balance requirement) | | `options?` | \{ `minFundingIncrement?`: [`AlgoAmount`](types_amount.AlgoAmount.md) } & [`ExecuteParams`](../interfaces/types_composer.ExecuteParams.md) & `Omit`\<[`CommonTransactionParams`](../modules/types_composer.md#commontransactionparams), ``"sender"``\> | Optional parameters to control the funding increment, transaction or execution of the transaction | #### Returns @@ -336,8 +336,8 @@ ___ Funds a given account using a dispenser account retrieved from the environment, per the `dispenserFromEnvironment` method, as a funding source such that -the given account has a certain amount of Algos free to spend (accounting for -Algos locked in minimum balance requirement). +the given account has a certain amount of Algo free to spend (accounting for +Algo locked in minimum balance requirement). **Note:** requires a Node.js environment to execute. @@ -352,7 +352,7 @@ https://developer.algorand.org/docs/get-details/accounts/#minimum-balance | Name | Type | Description | | :------ | :------ | :------ | | `accountToFund` | `string` \| [`TransactionSignerAccount`](../interfaces/types_account.TransactionSignerAccount.md) | The account to fund | -| `minSpendingBalance` | [`AlgoAmount`](types_amount.AlgoAmount.md) | The minimum balance of Algos that the account should have available to spend (i.e. on top of minimum balance requirement) | +| `minSpendingBalance` | [`AlgoAmount`](types_amount.AlgoAmount.md) | The minimum balance of Algo that the account should have available to spend (i.e. on top of minimum balance requirement) | | `options?` | \{ `minFundingIncrement?`: [`AlgoAmount`](types_amount.AlgoAmount.md) } & [`ExecuteParams`](../interfaces/types_composer.ExecuteParams.md) & `Omit`\<[`CommonTransactionParams`](../modules/types_composer.md#commontransactionparams), ``"sender"``\> | Optional parameters to control the funding increment, transaction or execution of the transaction | #### Returns @@ -384,7 +384,7 @@ ___ ▸ **ensureFundedFromTestNetDispenserApi**(`accountToFund`, `dispenserClient`, `minSpendingBalance`, `options`): `Promise`\<`undefined` \| [`EnsureFundedResult`](../interfaces/types_account_manager.EnsureFundedResult.md)\> Funds a given account using the TestNet Dispenser API as a funding source such that -the account has a certain amount of algos free to spend (accounting for Algos locked +the account has a certain amount of Algo free to spend (accounting for Algo locked in minimum balance requirement). https://developer.algorand.org/docs/get-details/accounts/#minimum-balance @@ -395,7 +395,7 @@ https://developer.algorand.org/docs/get-details/accounts/#minimum-balance | :------ | :------ | :------ | | `accountToFund` | `string` \| [`TransactionSignerAccount`](../interfaces/types_account.TransactionSignerAccount.md) | The account to fund | | `dispenserClient` | [`TestNetDispenserApiClient`](types_dispenser_client.TestNetDispenserApiClient.md) | The TestNet dispenser funding client | -| `minSpendingBalance` | [`AlgoAmount`](types_amount.AlgoAmount.md) | The minimum balance of Algos that the account should have available to spend (i.e. on top of minimum balance requirement) | +| `minSpendingBalance` | [`AlgoAmount`](types_amount.AlgoAmount.md) | The minimum balance of Algo that the account should have available to spend (i.e. on top of minimum balance requirement) | | `options` | `Object` | Optional parameters to control the funding increment, transaction or execution of the transaction | | `options.minFundingIncrement?` | [`AlgoAmount`](types_amount.AlgoAmount.md) | - | @@ -444,7 +444,7 @@ This allows you to write code that will work seamlessly in production and local | Name | Type | Description | | :------ | :------ | :------ | | `name` | `string` | The name identifier of the account | -| `fundWith?` | [`AlgoAmount`](types_amount.AlgoAmount.md) | The optional amount to fund the account with when it gets created (when targeting LocalNet), if not specified then 1000 Algos will be funded from the dispenser account | +| `fundWith?` | [`AlgoAmount`](types_amount.AlgoAmount.md) | The optional amount to fund the account with when it gets created (when targeting LocalNet), if not specified then 1000 ALGO will be funded from the dispenser account | #### Returns @@ -459,7 +459,7 @@ If you have a mnemonic secret loaded into `process.env.MY_ACCOUNT_MNEMONIC` then const account = await accountManager.fromEnvironment('MY_ACCOUNT') ``` -If that code runs against LocalNet then a wallet called `MY_ACCOUNT` will automatically be created with an account that is automatically funded with 1000 (default) Algos from the default LocalNet dispenser. +If that code runs against LocalNet then a wallet called `MY_ACCOUNT` will automatically be created with an account that is automatically funded with 1000 (default) ALGO from the default LocalNet dispenser. If not running against LocalNet then it will use proces.env.MY_ACCOUNT_MNEMONIC as the private key and (if present) process.env.MY_ACCOUNT_SENDER as the sender address. #### Defined in diff --git a/docs/code/classes/types_amount.AlgoAmount.md b/docs/code/classes/types_amount.AlgoAmount.md index 0458321e..64f9edca 100644 --- a/docs/code/classes/types_amount.AlgoAmount.md +++ b/docs/code/classes/types_amount.AlgoAmount.md @@ -4,7 +4,7 @@ [types/amount](../modules/types_amount.md).AlgoAmount -Wrapper class to ensure safe, explicit conversion between µAlgos, Algos and numbers +Wrapper class to ensure safe, explicit conversion between µAlgo, Algo and numbers ## Table of contents @@ -64,7 +64,7 @@ Wrapper class to ensure safe, explicit conversion between µAlgos, Algos and num • `get` **algos**(): `number` -Return the amount as a number in Algos +Return the amount as a number in Algo #### Returns @@ -80,7 +80,7 @@ ___ • `get` **microAlgos**(): `number` -Return the amount as a number in µAlgos +Return the amount as a number in µAlgo #### Returns @@ -128,7 +128,7 @@ ___ ▸ **Algos**(`amount`): [`AlgoAmount`](types_amount.AlgoAmount.md) -Create a `AlgoAmount` object representing the given number of Algos +Create a `AlgoAmount` object representing the given number of Algo #### Parameters @@ -150,7 +150,7 @@ ___ ▸ **MicroAlgos**(`amount`): [`AlgoAmount`](types_amount.AlgoAmount.md) -Create a `AlgoAmount` object representing the given number of µAlgos +Create a `AlgoAmount` object representing the given number of µAlgo #### Parameters diff --git a/docs/code/classes/types_app_client.ApplicationClient.md b/docs/code/classes/types_app_client.ApplicationClient.md index c5e075bb..aefc27e9 100644 --- a/docs/code/classes/types_app_client.ApplicationClient.md +++ b/docs/code/classes/types_app_client.ApplicationClient.md @@ -459,7 +459,7 @@ ___ ▸ **fundAppAccount**(`fund`): `Promise`\<[`SendTransactionResult`](../interfaces/types_transaction.SendTransactionResult.md)\> -Funds ALGOs into the app account for this app. +Funds Algo into the app account for this app. #### Parameters diff --git a/docs/code/classes/types_dispenser_client.TestNetDispenserApiClient.md b/docs/code/classes/types_dispenser_client.TestNetDispenserApiClient.md index 7d4278c3..25aa8aea 100644 --- a/docs/code/classes/types_dispenser_client.TestNetDispenserApiClient.md +++ b/docs/code/classes/types_dispenser_client.TestNetDispenserApiClient.md @@ -5,7 +5,7 @@ [types/dispenser-client](../modules/types_dispenser_client.md).TestNetDispenserApiClient `TestNetDispenserApiClient` is a class that provides methods to interact with the [Algorand TestNet Dispenser API](https://github.com/algorandfoundation/algokit/blob/main/docs/testnet_api.md). -It allows you to fund an address with Algos, refund a transaction, and get the funding limit for the Algo asset. +It allows you to fund an address with Algo, refund a transaction, and get the funding limit for the Algo asset. The class requires an authentication token and a request timeout to be initialized. The authentication token can be provided either directly as a parameter or through an `ALGOKIT_DISPENSER_ACCESS_TOKEN` environment variable. If neither is provided, an error is thrown. @@ -145,7 +145,7 @@ Sends a funding request to the dispenser API to fund the specified address with | Name | Type | Description | | :------ | :------ | :------ | | `address` | `string` | The address to fund. | -| `amount` | `number` | The amount of microAlgos to fund. | +| `amount` | `number` | The amount of µAlgo to fund. | #### Returns diff --git a/docs/code/classes/types_kmd_account_manager.KmdAccountManager.md b/docs/code/classes/types_kmd_account_manager.KmdAccountManager.md index bf85deae..a0aae270 100644 --- a/docs/code/classes/types_kmd_account_manager.KmdAccountManager.md +++ b/docs/code/classes/types_kmd_account_manager.KmdAccountManager.md @@ -110,7 +110,7 @@ If this is used via `mnemonicAccountFromEnvironment`, then you can even use the | Name | Type | Description | | :------ | :------ | :------ | | `name` | `string` | The name of the wallet to retrieve / create | -| `fundWith?` | [`AlgoAmount`](types_amount.AlgoAmount.md) | The number of Algos to fund the account with when it gets created, if not specified then 1000 Algos will be funded from the dispenser account | +| `fundWith?` | [`AlgoAmount`](types_amount.AlgoAmount.md) | The number of Algo to fund the account with when it gets created, if not specified then 1000 ALGO will be funded from the dispenser account | #### Returns @@ -122,7 +122,7 @@ An Algorand account with private key loaded - either one that already existed in ```typescript // Idempotently get (if exists) or crate (if it doesn't exist yet) an account by name using KMD -// if creating it then fund it with 2 Algos from the default dispenser account +// if creating it then fund it with 2 ALGO from the default dispenser account const newAccount = await kmdAccountManager.getOrCreateWalletAccount('account1', (2).algos()) // This will return the same account as above since the name matches const existingAccount = await kmdAccountManager.getOrCreateWalletAccount('account1') diff --git a/docs/code/interfaces/types_dispenser_client.DispenserFundResponse.md b/docs/code/interfaces/types_dispenser_client.DispenserFundResponse.md index e4cfe99d..5f516686 100644 --- a/docs/code/interfaces/types_dispenser_client.DispenserFundResponse.md +++ b/docs/code/interfaces/types_dispenser_client.DispenserFundResponse.md @@ -19,7 +19,7 @@ The TestNet Dispenser API response when funding. • **amount**: `number` -The number of microAlgos that was funded. +The number of µAlgo that was funded. #### Defined in diff --git a/docs/code/interfaces/types_dispenser_client.DispenserLimitResponse.md b/docs/code/interfaces/types_dispenser_client.DispenserLimitResponse.md index c925298f..363ba75d 100644 --- a/docs/code/interfaces/types_dispenser_client.DispenserLimitResponse.md +++ b/docs/code/interfaces/types_dispenser_client.DispenserLimitResponse.md @@ -18,7 +18,7 @@ The TestNet Dispenser API response when getting the current limit. • **amount**: `number` -The limit, in microAlgos, that you can currently fund. +The limit, in µAlgo, that you can currently fund. #### Defined in diff --git a/docs/code/interfaces/types_indexer.AccountResult.md b/docs/code/interfaces/types_indexer.AccountResult.md index 6f96820d..827b58db 100644 --- a/docs/code/interfaces/types_indexer.AccountResult.md +++ b/docs/code/interfaces/types_indexer.AccountResult.md @@ -61,7 +61,7 @@ ___ • **amount**: `number` -[algo] total number of MicroAlgos in the account +[algo] total number of µAlgo in the account #### Defined in @@ -73,7 +73,7 @@ ___ • **amount-without-pending-rewards**: `number` -specifies the amount of MicroAlgos in the account, without the pending rewards. +specifies the amount of µAlgo in the account, without the pending rewards. #### Defined in @@ -231,7 +231,7 @@ ___ • **pending-rewards**: `number` -amount of MicroAlgos of pending rewards in this account. +amount of µAlgo of pending rewards in this account. #### Defined in @@ -255,7 +255,7 @@ ___ • **rewards**: `number` -[ern] total rewards of MicroAlgos the account has received, including pending rewards. +[ern] total rewards of µAlgo the account has received, including pending rewards. #### Defined in @@ -291,7 +291,7 @@ ___ • **status**: [`AccountStatus`](../enums/types_indexer.AccountStatus.md) -[onl] delegation status of the account's MicroAlgos +[onl] delegation status of the account's µAlgo #### Defined in diff --git a/docs/code/interfaces/types_indexer.PaymentTransactionResult.md b/docs/code/interfaces/types_indexer.PaymentTransactionResult.md index 2326d65f..b0668545 100644 --- a/docs/code/interfaces/types_indexer.PaymentTransactionResult.md +++ b/docs/code/interfaces/types_indexer.PaymentTransactionResult.md @@ -21,7 +21,7 @@ Fields for a payment transaction https://developer.algorand.org/docs/rest-apis/i • **amount**: `number` -[amt] number of MicroAlgos intended to be transferred. +[amt] number of µAlgo intended to be transferred. #### Defined in @@ -33,7 +33,7 @@ ___ • `Optional` **close-amount**: `number` -Number of MicroAlgos that were sent to the close-remainder-to address when closing the sender account. +Number of µAlgo that were sent to the close-remainder-to address when closing the sender account. #### Defined in diff --git a/docs/code/interfaces/types_network_client.AlgoConfig.md b/docs/code/interfaces/types_network_client.AlgoConfig.md index ade6b4fa..a136607f 100644 --- a/docs/code/interfaces/types_network_client.AlgoConfig.md +++ b/docs/code/interfaces/types_network_client.AlgoConfig.md @@ -20,7 +20,7 @@ Configuration for algod, indexer and kmd clients. • **algodConfig**: [`AlgoClientConfig`](types_network_client.AlgoClientConfig.md) -Algo client configuration +Algod client configuration #### Defined in diff --git a/docs/code/interfaces/types_testing.AlgorandFixtureConfig.md b/docs/code/interfaces/types_testing.AlgorandFixtureConfig.md index 72bc5149..14ad69ea 100644 --- a/docs/code/interfaces/types_testing.AlgorandFixtureConfig.md +++ b/docs/code/interfaces/types_testing.AlgorandFixtureConfig.md @@ -70,7 +70,7 @@ ___ • `Optional` **algodConfig**: [`AlgoClientConfig`](types_network_client.AlgoClientConfig.md) -Algo client configuration +Algod client configuration #### Inherited from @@ -142,7 +142,7 @@ ___ • `Optional` **testAccountFunding**: [`AlgoAmount`](../classes/types_amount.AlgoAmount.md) -The amount of funds to allocate to the default testing account, if not specified then it will get 10 Algos. +The amount of funds to allocate to the default testing account, if not specified then it will get 10 ALGO. #### Defined in diff --git a/docs/code/interfaces/types_transfer.AlgoTransferParams.md b/docs/code/interfaces/types_transfer.AlgoTransferParams.md index d64a0788..482a80ed 100644 --- a/docs/code/interfaces/types_transfer.AlgoTransferParams.md +++ b/docs/code/interfaces/types_transfer.AlgoTransferParams.md @@ -83,7 +83,7 @@ ___ • **from**: [`SendTransactionFrom`](../modules/types_transaction.md#sendtransactionfrom) -The account that will send the Algos +The account that will send the Algo #### Defined in @@ -216,7 +216,7 @@ ___ • **to**: `string` \| [`SendTransactionFrom`](../modules/types_transaction.md#sendtransactionfrom) -The account / account address that will receive the Algos +The account / account address that will receive the Algo #### Defined in diff --git a/docs/code/interfaces/types_transfer.EnsureFundedParams.md b/docs/code/interfaces/types_transfer.EnsureFundedParams.md index 23bb6326..77204c36 100644 --- a/docs/code/interfaces/types_transfer.EnsureFundedParams.md +++ b/docs/code/interfaces/types_transfer.EnsureFundedParams.md @@ -152,7 +152,7 @@ ___ • **minSpendingBalance**: [`AlgoAmount`](../classes/types_amount.AlgoAmount.md) -The minimum balance of Algos that the account should have available to spend (i.e. on top of minimum balance requirement) +The minimum balance of Algo that the account should have available to spend (i.e. on top of minimum balance requirement) #### Defined in diff --git a/docs/code/modules/index.md b/docs/code/modules/index.md index dd20df80..158dd48f 100644 --- a/docs/code/modules/index.md +++ b/docs/code/modules/index.md @@ -225,13 +225,13 @@ ___ ▸ **algos**(`algos`): [`AlgoAmount`](../classes/types_amount.AlgoAmount.md) -Returns an amount of Algos using AlgoAmount +Returns an amount of Algo using AlgoAmount #### Parameters | Name | Type | Description | | :------ | :------ | :------ | -| `algos` | `number` | The amount in Algos | +| `algos` | `number` | The amount of Algo | #### Returns @@ -420,7 +420,7 @@ ___ ▸ **capTransactionFee**(`transaction`, `maxAcceptableFee`): `void` -Limit the acceptable fee to a defined amount of µAlgos. +Limit the acceptable fee to a defined amount of µAlgo. This also sets the transaction to be flatFee to ensure the transaction only succeeds at the estimated rate. @@ -717,7 +717,7 @@ ___ Use `algorand.account.ensureFunded()` / `algorand.account.ensureFundedFromEnvironment()` / `algorand.account.ensureFundedFromTestNetDispenserApi()` instead -Funds a given account using a funding source such that it has a certain amount of algos free to spend (accounting for Algos locked in minimum balance requirement). +Funds a given account using a funding source such that it has a certain amount of Algo free to spend (accounting for Algo locked in minimum balance requirement). https://developer.algorand.org/docs/get-details/accounts/#minimum-balance @@ -784,7 +784,7 @@ ___ | Name | Type | Description | | :------ | :------ | :------ | -| `account` | `string` \| \{ `fundWith?`: [`AlgoAmount`](../classes/types_amount.AlgoAmount.md) ; `name`: `string` } | The details of the account to get, either the name identifier (string) or an object with: * `name`: The name identifier of the account * `fundWith`: The amount to fund the account with when it gets created (when targeting LocalNet), if not specified then 1000 Algos will be funded from the dispenser account | +| `account` | `string` \| \{ `fundWith?`: [`AlgoAmount`](../classes/types_amount.AlgoAmount.md) ; `name`: `string` } | The details of the account to get, either the name identifier (string) or an object with: * `name`: The name identifier of the account * `fundWith`: The amount to fund the account with when it gets created (when targeting LocalNet), if not specified then 1000 ALGO will be funded from the dispenser account | | `algod` | `default` | An algod client | | `kmdClient?` | `default` | An optional KMD client to use to create an account (when targeting LocalNet), if not specified then a default KMD client will be loaded from environment variables | @@ -817,7 +817,7 @@ If you have a mnemonic secret loaded into `process.env.ACCOUNT_MNEMONIC` then yo const account = await getAccount('ACCOUNT', algod) ``` -If that code runs against LocalNet then a wallet called `ACCOUNT` will automatically be created with an account that is automatically funded with 1000 (default) Algos from the default LocalNet dispenser. +If that code runs against LocalNet then a wallet called `ACCOUNT` will automatically be created with an account that is automatically funded with 1000 (default) ALGO from the default LocalNet dispenser. #### Defined in @@ -829,7 +829,7 @@ If that code runs against LocalNet then a wallet called `ACCOUNT` will automatic | Name | Type | Description | | :------ | :------ | :------ | -| `account` | `Object` | The details of the account to get, an object with: * `config`: Account configuration. To get from environment use getAccountConfigFromEnvironment(accountName) * `fundWith`: The amount to fund the account with when it gets created (when targeting LocalNet), if not specified then 1000 Algos will be funded from the dispenser account | +| `account` | `Object` | The details of the account to get, an object with: * `config`: Account configuration. To get from environment use getAccountConfigFromEnvironment(accountName) * `fundWith`: The amount to fund the account with when it gets created (when targeting LocalNet), if not specified then 1000 ALGO will be funded from the dispenser account | | `account.config` | [`AccountConfig`](../interfaces/types_account.AccountConfig.md) | - | | `account.fundWith?` | [`AlgoAmount`](../classes/types_amount.AlgoAmount.md) | - | | `algod` | `default` | An algod client | @@ -855,7 +855,7 @@ If you have a mnemonic secret loaded into `process.env.ACCOUNT_MNEMONIC` then yo const account = await getAccount({config: getAccountConfigFromEnvironment('ACCOUNT')}, algod) ``` -If that code runs against LocalNet then a wallet called `ACCOUNT` will automatically be created with an account that is automatically funded with 1000 (default) Algos from the default LocalNet dispenser. +If that code runs against LocalNet then a wallet called `ACCOUNT` will automatically be created with an account that is automatically funded with 1000 (default) ALGO from the default LocalNet dispenser. #### Defined in @@ -1914,7 +1914,7 @@ ___ | Name | Type | Description | | :------ | :------ | :------ | -| `walletAccount` | `Object` | The wallet details with: * `name`: The name of the wallet to retrieve / create * `fundWith`: The number of Algos to fund the account with when it gets created, if not specified then 1000 Algos will be funded from the dispenser account | +| `walletAccount` | `Object` | The wallet details with: * `name`: The name of the wallet to retrieve / create * `fundWith`: The number of Algo to fund the account with when it gets created, if not specified then 1000 ALGO will be funded from the dispenser account | | `walletAccount.fundWith?` | [`AlgoAmount`](../classes/types_amount.AlgoAmount.md) | - | | `walletAccount.name` | `string` | - | | `algod` | `default` | An algod client | @@ -2189,13 +2189,13 @@ ___ ▸ **microAlgos**(`microAlgos`): [`AlgoAmount`](../classes/types_amount.AlgoAmount.md) -Returns an amount of µAlgos using AlgoAmount +Returns an amount of µAlgo using AlgoAmount #### Parameters | Name | Type | Description | | :------ | :------ | :------ | -| `microAlgos` | `number` | The amount in µAlgos | +| `microAlgos` | `number` | The amount of µAlgo | #### Returns @@ -2243,7 +2243,7 @@ ___ | Name | Type | Description | | :------ | :------ | :------ | -| `account` | `string` \| \{ `fundWith?`: [`AlgoAmount`](../classes/types_amount.AlgoAmount.md) ; `name`: `string` } | The details of the account to get, either the name identifier (string) or an object with: * `name`: string: The name identifier of the account * `fundWith`: The amount to fund the account with when it gets created (when targeting LocalNet), if not specified then 1000 Algos will be funded from the dispenser account | +| `account` | `string` \| \{ `fundWith?`: [`AlgoAmount`](../classes/types_amount.AlgoAmount.md) ; `name`: `string` } | The details of the account to get, either the name identifier (string) or an object with: * `name`: string: The name identifier of the account * `fundWith`: The amount to fund the account with when it gets created (when targeting LocalNet), if not specified then 1000 ALGO will be funded from the dispenser account | | `algod` | `default` | An algod client | | `kmdClient?` | `default` | An optional KMD client to use to create an account (when targeting LocalNet), if not specified then a default KMD client will be loaded from environment variables | @@ -2276,7 +2276,7 @@ If you have a mnemonic secret loaded into `process.env.MY_ACCOUNT_MNEMONIC` then const account = await mnemonicAccountFromEnvironment('MY_ACCOUNT', algod) ``` -If that code runs against LocalNet then a wallet called `MY_ACCOUNT` will automatically be created with an account that is automatically funded with 1000 (default) Algos from the default LocalNet dispenser. +If that code runs against LocalNet then a wallet called `MY_ACCOUNT` will automatically be created with an account that is automatically funded with 1000 (default) ALGO from the default LocalNet dispenser. If not running against LocalNet then it will use proces.env.MY_ACCOUNT_MNEMONIC as the private key and (if present) process.env.MY_ACCOUNT_SENDER as the sender address. #### Defined in @@ -2760,13 +2760,13 @@ ___ ▸ **transactionFees**(`numberOfTransactions`): [`AlgoAmount`](../classes/types_amount.AlgoAmount.md) -Returns an amount of µAlgos to cover standard fees for the given number of transactions using AlgoAmount +Returns an amount of µAlgo to cover standard fees for the given number of transactions using AlgoAmount #### Parameters | Name | Type | Description | | :------ | :------ | :------ | -| `numberOfTransactions` | `number` | The of standard transaction fees to return the amount of Algos | +| `numberOfTransactions` | `number` | The of standard transaction fees to return the amount of Algo | #### Returns @@ -2828,7 +2828,7 @@ The transaction object and optionally the confirmation if it was sent to the cha Use `algorand.send.payment()` / `algorand.transaction.payment()` instead -Transfer Algos between two accounts. +Transfer Algo between two accounts. **`Example`** diff --git a/docs/code/modules/testing.md b/docs/code/modules/testing.md index 808965b5..dd8830f1 100644 --- a/docs/code/modules/testing.md +++ b/docs/code/modules/testing.md @@ -112,7 +112,7 @@ test('My test', async () => { | Name | Type | Description | | :------ | :------ | :------ | | `fixtureConfig` | `undefined` \| [`AlgorandFixtureConfig`](../interfaces/types_testing.AlgorandFixtureConfig.md) | The fixture configuration | -| `config` | [`AlgoConfig`](../interfaces/types_network_client.AlgoConfig.md) | The algo configuration | +| `config` | [`AlgoConfig`](../interfaces/types_network_client.AlgoConfig.md) | The fixture configuration | #### Returns diff --git a/docs/code/modules/types_account.md b/docs/code/modules/types_account.md index fa8ecf38..4f198f74 100644 --- a/docs/code/modules/types_account.md +++ b/docs/code/modules/types_account.md @@ -57,22 +57,22 @@ Account information at a given round. | Name | Type | Description | | :------ | :------ | :------ | | `address` | `string` | The account public key | -| `amountWithoutPendingRewards` | [`AlgoAmount`](../classes/types_amount.AlgoAmount.md) | The amount of Algos in the account, without the pending rewards. | +| `amountWithoutPendingRewards` | [`AlgoAmount`](../classes/types_amount.AlgoAmount.md) | The amount of Algo in the account, without the pending rewards. | | `appsLocalState?` | `ApplicationLocalState`[] | Applications local data stored in this account. | | `appsTotalExtraPages?` | `number` | The sum of all extra application program pages for this account. | | `appsTotalSchema?` | `ApplicationStateSchema` | (tsch) stores the sum of all of the local schemas and global schemas in this account. Note: the raw account uses `StateSchema` for this type. | | `assets?` | `AssetHolding`[] | Assets held by this account. | | `authAddr?` | `string` | The address against which signing should be checked. If empty, the address of the current account is used. This field can be updated in any transaction by setting the `RekeyTo` field. | -| `balance` | [`AlgoAmount`](../classes/types_amount.AlgoAmount.md) | The balance of Algos currently held by the account. | +| `balance` | [`AlgoAmount`](../classes/types_amount.AlgoAmount.md) | The balance of Algo currently held by the account. | | `createdApps?` | `Application`[] | Parameters of applications created by this account including app global data. | | `createdAssets?` | `Asset`[] | (apar) parameters of assets created by this account. Note: the raw account uses `map[int] -> Asset` for this type. | | `minBalance` | [`AlgoAmount`](../classes/types_amount.AlgoAmount.md) | Algo balance required to be held by the account. The requirement grows based on asset and application usage. | | `participation?` | `AccountParticipation` | AccountParticipation describes the parameters used by this account in consensus protocol. | -| `pendingRewards` | [`AlgoAmount`](../classes/types_amount.AlgoAmount.md) | Amount of Algos of pending rewards in this account. | +| `pendingRewards` | [`AlgoAmount`](../classes/types_amount.AlgoAmount.md) | Amount of Algo of pending rewards in this account. | | `rewardBase?` | `number` | Used as part of the rewards computation. Only applicable to accounts which are participating. | -| `rewards` | [`AlgoAmount`](../classes/types_amount.AlgoAmount.md) | Total rewards of Algos the account has received, including pending rewards. | +| `rewards` | [`AlgoAmount`](../classes/types_amount.AlgoAmount.md) | Total rewards of Algo the account has received, including pending rewards. | | `sigType?` | `string` | Indicates what type of signature is used by this account, must be one of: * sig * msig * lsig | -| `status` | `string` | Delegation status of the account's MicroAlgos: * Offline - indicates that the associated account is delegated. * Online - indicates that the associated account used as part of the delegation pool. * NotParticipating - indicates that the associated account is neither a delegator nor a delegate. | +| `status` | `string` | Delegation status of the account's Algo: * Offline - indicates that the associated account is delegated. * Online - indicates that the associated account used as part of the delegation pool. * NotParticipating - indicates that the associated account is neither a delegator nor a delegate. | | `totalAppsOptedIn` | `number` | The count of all applications that have been opted in, equivalent to the count of application local data (AppLocalState objects) stored in this account. | | `totalAssetsOptedIn` | `number` | The count of all assets that have been opted in, equivalent to the count of AssetHolding objects held by this account. | | `totalBoxBytes?` | `number` | The total number of bytes used by this account's app's box keys and values. | diff --git a/src/account/account.ts b/src/account/account.ts index d8c11298..94129812 100644 --- a/src/account/account.ts +++ b/src/account/account.ts @@ -83,12 +83,12 @@ export function randomAccount(): Account { * const account = await mnemonicAccountFromEnvironment('MY_ACCOUNT', algod) * ``` * - * If that code runs against LocalNet then a wallet called `MY_ACCOUNT` will automatically be created with an account that is automatically funded with 1000 (default) Algos from the default LocalNet dispenser. + * If that code runs against LocalNet then a wallet called `MY_ACCOUNT` will automatically be created with an account that is automatically funded with 1000 (default) ALGO from the default LocalNet dispenser. * If not running against LocalNet then it will use proces.env.MY_ACCOUNT_MNEMONIC as the private key and (if present) process.env.MY_ACCOUNT_SENDER as the sender address. * * @param account The details of the account to get, either the name identifier (string) or an object with: * * `name`: string: The name identifier of the account - * * `fundWith`: The amount to fund the account with when it gets created (when targeting LocalNet), if not specified then 1000 Algos will be funded from the dispenser account + * * `fundWith`: The amount to fund the account with when it gets created (when targeting LocalNet), if not specified then 1000 ALGO will be funded from the dispenser account * @param algod An algod client * @param kmdClient An optional KMD client to use to create an account (when targeting LocalNet), if not specified then a default KMD client will be loaded from environment variables * @returns The requested account with private key loaded from the environment variables or when targeting LocalNet from KMD (idempotently creating and funding the account) diff --git a/src/account/get-account.ts b/src/account/get-account.ts index 93ecce83..16538172 100644 --- a/src/account/get-account.ts +++ b/src/account/get-account.ts @@ -29,11 +29,11 @@ import Kmd = algosdk.Kmd * const account = await getAccount('ACCOUNT', algod) * ``` * - * If that code runs against LocalNet then a wallet called `ACCOUNT` will automatically be created with an account that is automatically funded with 1000 (default) Algos from the default LocalNet dispenser. + * If that code runs against LocalNet then a wallet called `ACCOUNT` will automatically be created with an account that is automatically funded with 1000 (default) ALGO from the default LocalNet dispenser. * * @param account The details of the account to get, either the name identifier (string) or an object with: * * `name`: The name identifier of the account - * * `fundWith`: The amount to fund the account with when it gets created (when targeting LocalNet), if not specified then 1000 Algos will be funded from the dispenser account + * * `fundWith`: The amount to fund the account with when it gets created (when targeting LocalNet), if not specified then 1000 ALGO will be funded from the dispenser account * @param algod An algod client * @param kmdClient An optional KMD client to use to create an account (when targeting LocalNet), if not specified then a default KMD client will be loaded from environment variables * @returns The requested account with private key loaded from the environment variables or when targeting LocalNet from KMD (idempotently creating and funding the account) @@ -56,11 +56,11 @@ export async function getAccount( * const account = await getAccount({config: getAccountConfigFromEnvironment('ACCOUNT')}, algod) * ``` * - * If that code runs against LocalNet then a wallet called `ACCOUNT` will automatically be created with an account that is automatically funded with 1000 (default) Algos from the default LocalNet dispenser. + * If that code runs against LocalNet then a wallet called `ACCOUNT` will automatically be created with an account that is automatically funded with 1000 (default) ALGO from the default LocalNet dispenser. * * @param account The details of the account to get, an object with: * * `config`: Account configuration. To get from environment use getAccountConfigFromEnvironment(accountName) - * * `fundWith`: The amount to fund the account with when it gets created (when targeting LocalNet), if not specified then 1000 Algos will be funded from the dispenser account + * * `fundWith`: The amount to fund the account with when it gets created (when targeting LocalNet), if not specified then 1000 ALGO will be funded from the dispenser account * @param algod An algod client * @param kmdClient An optional KMD client to use to create an account (when targeting LocalNet), if not specified then a default KMD client will be loaded from environment variables * @returns The requested account with private key loaded from the environment variables or when targeting LocalNet from KMD (idempotently creating and funding the account) @@ -91,13 +91,13 @@ export async function getAccount( * const account = await getAccount({config: getAccountConfigFromEnvironment('ACCOUNT')}, algod) * ``` * - * If that code runs against LocalNet then a wallet called `ACCOUNT` will automatically be created with an account that is automatically funded with 1000 (default) Algos from the default LocalNet dispenser. + * If that code runs against LocalNet then a wallet called `ACCOUNT` will automatically be created with an account that is automatically funded with 1000 (default) ALGO from the default LocalNet dispenser. * * @param account The details of the account to get, either the name identifier (string) or an object with: * * `config`: Account configuration. To get from environment use getAccountConfigFromEnvironment(accountName) OR * * `name`: string: The name identifier of the account (deprecated) * And optionally - * * `fundWith`: The amount to fund the account with when it gets created (when targeting LocalNet), if not specified then 1000 Algos will be funded from the dispenser account + * * `fundWith`: The amount to fund the account with when it gets created (when targeting LocalNet), if not specified then 1000 ALGO will be funded from the dispenser account * @param algod An algod client * @param kmdClient An optional KMD client to use to create an account (when targeting LocalNet), if not specified then a default KMD client will be loaded from environment variables * @returns The requested account with private key loaded from the environment variables or when targeting LocalNet from KMD (idempotently creating and funding the account) diff --git a/src/amount.ts b/src/amount.ts index 17646b73..a631499f 100644 --- a/src/amount.ts +++ b/src/amount.ts @@ -16,22 +16,22 @@ Number.prototype.algos = function () { return AlgoAmount.Algos(this) } -/** Returns an amount of Algos using AlgoAmount - * @param algos The amount in Algos +/** Returns an amount of Algo using AlgoAmount + * @param algos The amount of Algo */ export const algos = (algos: number) => { return AlgoAmount.Algos(algos) } -/** Returns an amount of µAlgos using AlgoAmount - * @param microAlgos The amount in µAlgos +/** Returns an amount of µAlgo using AlgoAmount + * @param microAlgos The amount of µAlgo */ export const microAlgos = (microAlgos: number) => { return AlgoAmount.MicroAlgos(microAlgos) } -/** Returns an amount of µAlgos to cover standard fees for the given number of transactions using AlgoAmount - * @param numberOfTransactions The of standard transaction fees to return the amount of Algos +/** Returns an amount of µAlgo to cover standard fees for the given number of transactions using AlgoAmount + * @param numberOfTransactions The of standard transaction fees to return the amount of Algo */ export const transactionFees = (numberOfTransactions: number) => { return AlgoAmount.MicroAlgos(numberOfTransactions * algosdk.ALGORAND_MIN_TX_FEE) diff --git a/src/localnet/get-or-create-kmd-wallet-account.ts b/src/localnet/get-or-create-kmd-wallet-account.ts index 206bfa50..6ec43bae 100644 --- a/src/localnet/get-or-create-kmd-wallet-account.ts +++ b/src/localnet/get-or-create-kmd-wallet-account.ts @@ -19,7 +19,7 @@ import Kmd = algosdk.Kmd * * @param walletAccount The wallet details with: * * `name`: The name of the wallet to retrieve / create - * * `fundWith`: The number of Algos to fund the account with when it gets created, if not specified then 1000 Algos will be funded from the dispenser account + * * `fundWith`: The number of Algo to fund the account with when it gets created, if not specified then 1000 ALGO will be funded from the dispenser account * @param algod An algod client * @param kmdClient A KMD client, if not specified then a default KMD client will be loaded from environment variables * diff --git a/src/testing/account.ts b/src/testing/account.ts index 8ec4dbb8..d9568e16 100644 --- a/src/testing/account.ts +++ b/src/testing/account.ts @@ -59,7 +59,7 @@ export async function getTestAccount( const accountInfo = await algorand.account.getInformation(account.addr) - Config.getLogger(suppressLog).info('Test account funded; account balance: %d µAlgos', accountInfo.balance.microAlgos) + Config.getLogger(suppressLog).info('Test account funded; account balance: %d µALGO', accountInfo.balance.microAlgos) return account } diff --git a/src/testing/fixtures/algorand-fixture.ts b/src/testing/fixtures/algorand-fixture.ts index a000c8ca..097549db 100644 --- a/src/testing/fixtures/algorand-fixture.ts +++ b/src/testing/fixtures/algorand-fixture.ts @@ -69,7 +69,7 @@ export function algorandFixture(fixtureConfig?: AlgorandFixtureConfig): Algorand * ``` * * @param fixtureConfig The fixture configuration - * @param config The algo configuration + * @param config The fixture configuration * @returns The fixture */ export function algorandFixture(fixtureConfig: AlgorandFixtureConfig | undefined, config: AlgoConfig): AlgorandFixture diff --git a/src/transaction/transaction.spec.ts b/src/transaction/transaction.spec.ts index 1740f556..b49dd11b 100644 --- a/src/transaction/transaction.spec.ts +++ b/src/transaction/transaction.spec.ts @@ -48,8 +48,8 @@ describe('transaction', () => { ) }).rejects.toThrowError( 'Cancelled transaction due to high network congestion fees. ' + - 'Algorand suggested fees would cause this transaction to cost 1000 µAlgos. ' + - 'Cap for this transaction is 1 µAlgos.', + 'Algorand suggested fees would cause this transaction to cost 1000 µALGO. ' + + 'Cap for this transaction is 1 µALGO.', ) }) diff --git a/src/transaction/transaction.ts b/src/transaction/transaction.ts index 018832ce..a811eebb 100644 --- a/src/transaction/transaction.ts +++ b/src/transaction/transaction.ts @@ -807,7 +807,7 @@ export const waitForConfirmation = async function ( } /** - * Limit the acceptable fee to a defined amount of µAlgos. + * Limit the acceptable fee to a defined amount of µAlgo. * This also sets the transaction to be flatFee to ensure the transaction only succeeds at * the estimated rate. * @param transaction The transaction to cap or suggested params object about to be used to create a transaction @@ -820,10 +820,10 @@ export function capTransactionFee(transaction: algosdk.Transaction | SuggestedPa // Will be based on the current suggested fee-per-byte value. if (transaction.fee > maxAcceptableFee.microAlgos) { throw new Error( - `Cancelled transaction due to high network congestion fees. Algorand suggested fees would cause this transaction to cost ${transaction.fee} µAlgos. Cap for this transaction is ${maxAcceptableFee.microAlgos} µAlgos.`, + `Cancelled transaction due to high network congestion fees. Algorand suggested fees would cause this transaction to cost ${transaction.fee} µALGO. Cap for this transaction is ${maxAcceptableFee.microAlgos} µALGO.`, ) } else if (transaction.fee > algosdk.ALGORAND_MIN_TX_FEE) { - Config.logger.warn(`Algorand network congestion fees are in effect. This transaction will incur a fee of ${transaction.fee} µAlgos.`) + Config.logger.warn(`Algorand network congestion fees are in effect. This transaction will incur a fee of ${transaction.fee} µALGO.`) } // Now set the flat on the transaction. Otherwise the network may increase the fee above our cap and perform the transaction. diff --git a/src/transfer/transfer-algos.ts b/src/transfer/transfer-algos.ts index 517aaf55..02934496 100644 --- a/src/transfer/transfer-algos.ts +++ b/src/transfer/transfer-algos.ts @@ -9,7 +9,7 @@ import Algodv2 = algosdk.Algodv2 /** * @deprecated Use `algorand.send.payment()` / `algorand.transaction.payment()` instead * - * Transfer Algos between two accounts. + * Transfer Algo between two accounts. * @param transfer The transfer definition * @param algod An algod client * @returns The transaction object and optionally the confirmation if it was sent to the chain (`skipSending` is `false` or unset) diff --git a/src/transfer/transfer.ts b/src/transfer/transfer.ts index f95a26c6..fff27ca3 100644 --- a/src/transfer/transfer.ts +++ b/src/transfer/transfer.ts @@ -12,7 +12,7 @@ import Kmd = algosdk.Kmd * @deprecated Use `algorand.account.ensureFunded()` / `algorand.account.ensureFundedFromEnvironment()` * / `algorand.account.ensureFundedFromTestNetDispenserApi()` instead * - * Funds a given account using a funding source such that it has a certain amount of algos free to spend (accounting for Algos locked in minimum balance requirement). + * Funds a given account using a funding source such that it has a certain amount of Algo free to spend (accounting for Algo locked in minimum balance requirement). * * https://developer.algorand.org/docs/get-details/accounts/#minimum-balance * diff --git a/src/types/account-manager.ts b/src/types/account-manager.ts index 05b88f22..9f81e4f7 100644 --- a/src/types/account-manager.ts +++ b/src/types/account-manager.ts @@ -320,11 +320,11 @@ export class AccountManager { * const account = await accountManager.fromEnvironment('MY_ACCOUNT') * ``` * - * If that code runs against LocalNet then a wallet called `MY_ACCOUNT` will automatically be created with an account that is automatically funded with 1000 (default) Algos from the default LocalNet dispenser. + * If that code runs against LocalNet then a wallet called `MY_ACCOUNT` will automatically be created with an account that is automatically funded with 1000 (default) ALGO from the default LocalNet dispenser. * If not running against LocalNet then it will use proces.env.MY_ACCOUNT_MNEMONIC as the private key and (if present) process.env.MY_ACCOUNT_SENDER as the sender address. * * @param name The name identifier of the account - * @param fundWith The optional amount to fund the account with when it gets created (when targeting LocalNet), if not specified then 1000 Algos will be funded from the dispenser account + * @param fundWith The optional amount to fund the account with when it gets created (when targeting LocalNet), if not specified then 1000 ALGO will be funded from the dispenser account * @returns The account */ public async fromEnvironment(name: string, fundWith?: AlgoAmount) { @@ -674,14 +674,14 @@ export class AccountManager { /** * Funds a given account using a dispenser account as a funding source such that - * the given account has a certain amount of Algos free to spend (accounting for - * Algos locked in minimum balance requirement). + * the given account has a certain amount of Algo free to spend (accounting for + * Algo locked in minimum balance requirement). * * https://developer.algorand.org/docs/get-details/accounts/#minimum-balance * * @param accountToFund The account to fund * @param dispenserAccount The account to use as a dispenser funding source - * @param minSpendingBalance The minimum balance of Algos that the account should have available to spend (i.e. on top of minimum balance requirement) + * @param minSpendingBalance The minimum balance of Algo that the account should have available to spend (i.e. on top of minimum balance requirement) * @param options Optional parameters to control the funding increment, transaction or execution of the transaction * @example Example using AlgorandClient * ```typescript @@ -731,8 +731,8 @@ export class AccountManager { /** * Funds a given account using a dispenser account retrieved from the environment, * per the `dispenserFromEnvironment` method, as a funding source such that - * the given account has a certain amount of Algos free to spend (accounting for - * Algos locked in minimum balance requirement). + * the given account has a certain amount of Algo free to spend (accounting for + * Algo locked in minimum balance requirement). * * **Note:** requires a Node.js environment to execute. * @@ -743,7 +743,7 @@ export class AccountManager { * https://developer.algorand.org/docs/get-details/accounts/#minimum-balance * * @param accountToFund The account to fund - * @param minSpendingBalance The minimum balance of Algos that the account should have available to spend (i.e. on top of minimum balance requirement) + * @param minSpendingBalance The minimum balance of Algo that the account should have available to spend (i.e. on top of minimum balance requirement) * @param options Optional parameters to control the funding increment, transaction or execution of the transaction * @example Example using AlgorandClient * ```typescript @@ -792,14 +792,14 @@ export class AccountManager { /** * Funds a given account using the TestNet Dispenser API as a funding source such that - * the account has a certain amount of algos free to spend (accounting for Algos locked + * the account has a certain amount of Algo free to spend (accounting for Algo locked * in minimum balance requirement). * * https://developer.algorand.org/docs/get-details/accounts/#minimum-balance * * @param accountToFund The account to fund * @param dispenserClient The TestNet dispenser funding client - * @param minSpendingBalance The minimum balance of Algos that the account should have available to spend (i.e. on top of minimum balance requirement) + * @param minSpendingBalance The minimum balance of Algo that the account should have available to spend (i.e. on top of minimum balance requirement) * @param options Optional parameters to control the funding increment, transaction or execution of the transaction * @example Example using AlgorandClient * ```typescript diff --git a/src/types/account.ts b/src/types/account.ts index f8ece8e7..10258b62 100644 --- a/src/types/account.ts +++ b/src/types/account.ts @@ -128,11 +128,11 @@ export type AccountInformation = { */ address: string - /** The balance of Algos currently held by the account. */ + /** The balance of Algo currently held by the account. */ balance: AlgoAmount /** - * The amount of Algos in the account, without the pending rewards. + * The amount of Algo in the account, without the pending rewards. */ amountWithoutPendingRewards: AlgoAmount @@ -143,12 +143,12 @@ export type AccountInformation = { */ minBalance: AlgoAmount /** - * Amount of Algos of pending rewards in this account. + * Amount of Algo of pending rewards in this account. */ pendingRewards: AlgoAmount /** - * Total rewards of Algos the account has received, including pending + * Total rewards of Algo the account has received, including pending * rewards. */ rewards: AlgoAmount @@ -159,7 +159,7 @@ export type AccountInformation = { validAsOfRound: bigint /** - * Delegation status of the account's MicroAlgos: + * Delegation status of the account's Algo: * * Offline - indicates that the associated account is delegated. * * Online - indicates that the associated account used as part of the delegation pool. * * NotParticipating - indicates that the associated account is neither a delegator nor a delegate. diff --git a/src/types/algorand-client.ts b/src/types/algorand-client.ts index 6f6e1e55..4c6dc107 100644 --- a/src/types/algorand-client.ts +++ b/src/types/algorand-client.ts @@ -190,7 +190,7 @@ export class AlgorandClient { */ public send = { /** - * Send a payment transaction to transfer Algos between accounts. + * Send a payment transaction to transfer Algo between accounts. * @param params The parameters for the payment transaction * @example Basic example * ```typescript @@ -232,7 +232,7 @@ export class AlgorandClient { */ payment: this._send((c) => c.addPayment, { preLog: (params, transaction) => - `Sending ${params.amount.microAlgos} µAlgos from ${params.sender} to ${params.receiver} via transaction ${transaction.txID()}`, + `Sending ${params.amount.microAlgos} µAlgo from ${params.sender} to ${params.receiver} via transaction ${transaction.txID()}`, }), /** * Create a new Algorand Standard Asset. @@ -303,7 +303,7 @@ export class AlgorandClient { * ``` * @example Advanced example * ```typescript - * await algorand.send.assetCreate({ + * await algorand.send.assetConfig({ * sender: 'MANAGERADDRESS', * assetId: 123456n, * manager: 'MANAGERADDRESS', @@ -602,7 +602,7 @@ export class AlgorandClient { */ public transactions = { /** - * Create a payment transaction to transfer Algos between accounts. + * Create a payment transaction to transfer Algo between accounts. * @param params The parameters for the payment transaction * @example Basic example * ```typescript @@ -692,7 +692,7 @@ export class AlgorandClient { * ``` * @example Advanced example * ```typescript - * await algorand.transaction.assetCreate({ + * await algorand.transaction.assetConfig({ * sender: 'MANAGERADDRESS', * assetId: 123456n, * manager: 'MANAGERADDRESS', diff --git a/src/types/amount.spec.ts b/src/types/amount.spec.ts index fc99090d..a17371d4 100644 --- a/src/types/amount.spec.ts +++ b/src/types/amount.spec.ts @@ -4,10 +4,10 @@ import { AlgoAmount } from './amount' describe('amount', () => { test('toString on 1', () => { - expect(`${microAlgos(1)}`).toBe(`1 µAlgo`) + expect(`${microAlgos(1)}`).toBe(`1 µALGO`) }) test('toString on big amount', () => { - expect(`${algos(100)}`).toBe(`100,000,000 µAlgos`) + expect(`${algos(100)}`).toBe(`100,000,000 µALGO`) }) test('microalgos to microalgos', () => { expect(microAlgos(100).microAlgos).toBe(100) diff --git a/src/types/amount.ts b/src/types/amount.ts index cabf0312..2d2c720c 100644 --- a/src/types/amount.ts +++ b/src/types/amount.ts @@ -1,15 +1,15 @@ import algosdk from 'algosdk' -/** Wrapper class to ensure safe, explicit conversion between µAlgos, Algos and numbers */ +/** Wrapper class to ensure safe, explicit conversion between µAlgo, Algo and numbers */ export class AlgoAmount { private amountInMicroAlgos - /** Return the amount as a number in µAlgos */ + /** Return the amount as a number in µAlgo */ get microAlgos() { return this.amountInMicroAlgos } - /** Return the amount as a number in Algos */ + /** Return the amount as a number in Algo */ get algos() { return algosdk.microalgosToAlgos(this.amountInMicroAlgos) } @@ -19,7 +19,7 @@ export class AlgoAmount { } toString(): string { - return `${this.microAlgos.toLocaleString('en-US')} µAlgo${this.microAlgos === 1 ? '' : 's'}` + return `${this.microAlgos.toLocaleString('en-US')} µALGO` } /** valueOf allows you to use `AlgoAmount` in comparison operations such as `<` and `>=` etc., @@ -30,12 +30,12 @@ export class AlgoAmount { return this.microAlgos } - /** Create a `AlgoAmount` object representing the given number of Algos */ + /** Create a `AlgoAmount` object representing the given number of Algo */ static Algos(amount: number) { return new AlgoAmount({ algos: amount }) } - /** Create a `AlgoAmount` object representing the given number of µAlgos */ + /** Create a `AlgoAmount` object representing the given number of µAlgo */ static MicroAlgos(amount: number) { return new AlgoAmount({ microAlgos: amount }) } diff --git a/src/types/app-client.ts b/src/types/app-client.ts index 642c42fd..772a05ca 100644 --- a/src/types/app-client.ts +++ b/src/types/app-client.ts @@ -724,7 +724,7 @@ export class ApplicationClient { } /** - * Funds ALGOs into the app account for this app. + * Funds Algo into the app account for this app. * @param fund The parameters for the funding or the funding amount * @returns The result of the funding */ diff --git a/src/types/composer.ts b/src/types/composer.ts index f6d63f49..32c40717 100644 --- a/src/types/composer.ts +++ b/src/types/composer.ts @@ -54,7 +54,7 @@ export type CommonTransactionParams = { /** Parameters to define a payment transaction. */ export type PaymentParams = CommonTransactionParams & { - /** The address of the account that will receive the Algos */ + /** The address of the account that will receive the Algo */ receiver: string /** Amount to send */ amount: AlgoAmount diff --git a/src/types/dispenser-client.spec.ts b/src/types/dispenser-client.spec.ts index d4276a71..cd584a19 100644 --- a/src/types/dispenser-client.spec.ts +++ b/src/types/dispenser-client.spec.ts @@ -13,7 +13,7 @@ describe('TestNetDispenserApiClient', () => { afterEach(() => { process.env = env }) - it('should fund account with Algos with auth token', async () => { + it('should fund account with Algo with auth token', async () => { const mockResponse = { txID: 'dummy_tx_id', amount: 1 } fetchMock.mockResponseOnce(JSON.stringify(mockResponse)) diff --git a/src/types/dispenser-client.ts b/src/types/dispenser-client.ts index 5b1c3b98..04725960 100644 --- a/src/types/dispenser-client.ts +++ b/src/types/dispenser-client.ts @@ -18,13 +18,13 @@ const dispenserAssets = { export interface DispenserFundResponse { /** The ID of the transaction that was issued to fund the account. */ txId: string - /** The number of microAlgos that was funded. */ + /** The number of µAlgo that was funded. */ amount: number } /** The TestNet Dispenser API response when getting the current limit. */ export interface DispenserLimitResponse { - /** The limit, in microAlgos, that you can currently fund. */ + /** The limit, in µAlgo, that you can currently fund. */ amount: number } @@ -38,7 +38,7 @@ export interface TestNetDispenserApiClientParams { /** * `TestNetDispenserApiClient` is a class that provides methods to interact with the [Algorand TestNet Dispenser API](https://github.com/algorandfoundation/algokit/blob/main/docs/testnet_api.md). - * It allows you to fund an address with Algos, refund a transaction, and get the funding limit for the Algo asset. + * It allows you to fund an address with Algo, refund a transaction, and get the funding limit for the Algo asset. * * The class requires an authentication token and a request timeout to be initialized. The authentication token can be provided * either directly as a parameter or through an `ALGOKIT_DISPENSER_ACCESS_TOKEN` environment variable. If neither is provided, an error is thrown. @@ -143,7 +143,7 @@ export class TestNetDispenserApiClient { * Sends a funding request to the dispenser API to fund the specified address with the given amount of Algo. * * @param address - The address to fund. - * @param amount - The amount of microAlgos to fund. + * @param amount - The amount of µAlgo to fund. * * @returns DispenserFundResponse: An object containing the transaction ID and funded amount. */ diff --git a/src/types/indexer.ts b/src/types/indexer.ts index 33074255..42f9c1b8 100644 --- a/src/types/indexer.ts +++ b/src/types/indexer.ts @@ -210,9 +210,9 @@ export interface TransactionResult extends Record { export interface AccountResult extends Record { /** the account public key */ address: string - /** [algo] total number of MicroAlgos in the account */ + /** [algo] total number of µAlgo in the account */ amount: number - /** specifies the amount of MicroAlgos in the account, without the pending rewards. */ + /** specifies the amount of µAlgo in the account, without the pending rewards. */ 'amount-without-pending-rewards': number /** [appl] applications local data stored in this account. * @@ -256,17 +256,17 @@ export interface AccountResult extends Record { deleted?: boolean /** If participating in consensus, the parameters used by this account in the consensus protocol. */ participation?: AccountParticipation - /** amount of MicroAlgos of pending rewards in this account. */ + /** amount of µAlgo of pending rewards in this account. */ 'pending-rewards': number /** [ebase] used as part of the rewards computation. Only applicable to accounts which are participating. */ 'reward-base'?: number - /** [ern] total rewards of MicroAlgos the account has received, including pending rewards. */ + /** [ern] total rewards of µAlgo the account has received, including pending rewards. */ rewards: number /** The round for which this information is relevant. */ round: number /** Indicates what type of signature is used by this account */ 'sig-type': SignatureType - /** [onl] delegation status of the account's MicroAlgos */ + /** [onl] delegation status of the account's µAlgo */ status: AccountStatus /** The count of all applications that have been opted in, equivalent to the count of application local data (AppLocalState objects) stored in this account. */ 'total-apps-opted-in': number @@ -284,9 +284,9 @@ export interface AccountResult extends Record { /** Fields for a payment transaction https://developer.algorand.org/docs/rest-apis/indexer/#transactionpayment */ export interface PaymentTransactionResult { - /** [amt] number of MicroAlgos intended to be transferred. */ + /** [amt] number of µAlgo intended to be transferred. */ amount: number - /** Number of MicroAlgos that were sent to the close-remainder-to address when closing the sender account. */ + /** Number of µAlgo that were sent to the close-remainder-to address when closing the sender account. */ 'close-amount'?: number /** [close] when set, indicates that the sending account should be closed and all remaining funds be transferred to this address. */ 'close-remainder-to'?: string diff --git a/src/types/kmd-account-manager.ts b/src/types/kmd-account-manager.ts index c83e2127..bb8f6875 100644 --- a/src/types/kmd-account-manager.ts +++ b/src/types/kmd-account-manager.ts @@ -119,12 +119,12 @@ export class KmdAccountManager { * If this is used via `mnemonicAccountFromEnvironment`, then you can even use the same code that runs on production without changes for local development! * * @param name The name of the wallet to retrieve / create - * @param fundWith The number of Algos to fund the account with when it gets created, if not specified then 1000 Algos will be funded from the dispenser account + * @param fundWith The number of Algo to fund the account with when it gets created, if not specified then 1000 ALGO will be funded from the dispenser account * * @example * ```typescript * // Idempotently get (if exists) or crate (if it doesn't exist yet) an account by name using KMD - * // if creating it then fund it with 2 Algos from the default dispenser account + * // if creating it then fund it with 2 ALGO from the default dispenser account * const newAccount = await kmdAccountManager.getOrCreateWalletAccount('account1', (2).algos()) * // This will return the same account as above since the name matches * const existingAccount = await kmdAccountManager.getOrCreateWalletAccount('account1') @@ -156,7 +156,7 @@ export class KmdAccountManager { Config.logger.info( `LocalNet account '${name}' doesn't yet exist; created account ${account.addr} with keys stored in KMD and funding with ${ fundWith?.algos ?? 1000 - } Algos`, + } ALGO`, ) // Fund the account from the dispenser diff --git a/src/types/network-client.ts b/src/types/network-client.ts index d25d037f..2b371d18 100644 --- a/src/types/network-client.ts +++ b/src/types/network-client.ts @@ -12,7 +12,7 @@ export interface AlgoClientConfig { /** Configuration for algod, indexer and kmd clients. */ export interface AlgoConfig { - /** Algo client configuration */ + /** Algod client configuration */ algodConfig: AlgoClientConfig /** Indexer client configuration */ indexerConfig?: AlgoClientConfig diff --git a/src/types/testing.ts b/src/types/testing.ts index 067ed5e8..3e597265 100644 --- a/src/types/testing.ts +++ b/src/types/testing.ts @@ -57,7 +57,7 @@ export interface AlgorandFixtureConfig extends Partial { indexer?: Indexer /** An optional kmd client, if not specified then it will create one against `kmdConfig` (if present) then environment variables defined network (if present) or default LocalNet. */ kmd?: Kmd - /** The amount of funds to allocate to the default testing account, if not specified then it will get 10 Algos. */ + /** The amount of funds to allocate to the default testing account, if not specified then it will get 10 ALGO. */ testAccountFunding?: AlgoAmount /** Optional override for how to get an account; this allows you to retrieve accounts from a known or cached list of accounts. */ accountGetter?: (algod: Algodv2, kmd?: Kmd) => Promise diff --git a/src/types/transfer.ts b/src/types/transfer.ts index f1e92436..a6184808 100644 --- a/src/types/transfer.ts +++ b/src/types/transfer.ts @@ -6,9 +6,9 @@ import SuggestedParams = algosdk.SuggestedParams /** @deprecated Parameters for `transferAlgos` call. */ export interface AlgoTransferParams extends SendTransactionParams { - /** The account that will send the Algos */ + /** The account that will send the Algo */ from: SendTransactionFrom - /** The account / account address that will receive the Algos */ + /** The account / account address that will receive the Algo */ to: SendTransactionFrom | string /** The amount to send */ amount: AlgoAmount @@ -40,7 +40,7 @@ export interface EnsureFundedParams extends SendTransactionParams { accountToFund: SendTransactionFrom | string /** The account to use as a funding source, will default to using the dispenser account returned by `algokit.getDispenserAccount` */ fundingSource?: SendTransactionFrom | TestNetDispenserApiClient - /** The minimum balance of Algos that the account should have available to spend (i.e. on top of minimum balance requirement) */ + /** The minimum balance of Algo that the account should have available to spend (i.e. on top of minimum balance requirement) */ minSpendingBalance: AlgoAmount /** When issuing a funding amount, the minimum amount to transfer (avoids many small transfers if this gets called often on an active account) */ minFundingIncrement?: AlgoAmount From 2dad415e389d8ecbcfebfad13dbbe2c12f598214 Mon Sep 17 00:00:00 2001 From: "Rob Moore (MakerX)" Date: Wed, 21 Aug 2024 21:53:23 +0800 Subject: [PATCH 07/18] fix: Pull request feedback Moved account.assetBulkOptIn -> asset.bulkOptIn Moved account.assetBulkOptOut -> asset.bulkOptOut Moved account.getAssetInformation -> asset.getAccountInformation Fixed other miscellaneous issues --- docs/README.md | 16 +- docs/capabilities/account.md | 2 +- docs/capabilities/algorand-client.md | 18 +- docs/capabilities/asset.md | 36 +++- .../types_account_manager.AccountManager.md | 168 +++------------ .../types_asset_manager.AssetManager.md | 153 +++++++++++++- ...account_manager.BulkAssetOptInOutResult.md | 38 ---- ...ypes_account_manager.EnsureFundedResult.md | 4 +- .../types_asset_manager.AssetInformation.md | 34 +-- ...s_asset_manager.BulkAssetOptInOutResult.md | 38 ++++ docs/code/modules/index.md | 36 ++-- docs/code/modules/types_account_manager.md | 3 +- docs/code/modules/types_asset_manager.md | 1 + src/account/account.ts | 6 +- src/asset.ts | 27 ++- src/indexer-lookup.spec.ts | 9 +- src/types/account-manager.ts | 192 +---------------- src/types/algorand-client.asset.spec.ts | 20 +- src/types/algorand-client.transfer.spec.ts | 12 +- src/types/algorand-client.ts | 6 +- src/types/asset-manager.ts | 196 +++++++++++++++++- 21 files changed, 541 insertions(+), 474 deletions(-) delete mode 100644 docs/code/interfaces/types_account_manager.BulkAssetOptInOutResult.md create mode 100644 docs/code/interfaces/types_asset_manager.BulkAssetOptInOutResult.md diff --git a/docs/README.md b/docs/README.md index 57d092c6..b20a826c 100644 --- a/docs/README.md +++ b/docs/README.md @@ -53,21 +53,21 @@ The main entrypoint to the bulk of the functionality is the `AlgorandClient` cla // Point to the network configured through environment variables or // if no environment variables it will point to the default LocalNet // configuration -const algorand = algokit.AlgorandClient.fromEnvironment() +const algorand = AlgorandClient.fromEnvironment() // Point to default LocalNet configuration -const algorand = algokit.AlgorandClient.defaultLocalNet() +const algorand = AlgorandClient.defaultLocalNet() // Point to TestNet using AlgoNode free tier -const algorand = algokit.AlgorandClient.testNet() +const algorand = AlgorandClient.testNet() // Point to MainNet using AlgoNode free tier -const algorand = algokit.AlgorandClient.mainNet() +const algorand = AlgorandClient.mainNet() // Point to a pre-created algod client -const algorand = algokit.AlgorandClient.fromClients({ algod }) +const algorand = AlgorandClient.fromClients({ algod }) // Point to pre-created algod, indexer and kmd clients -const algorand = algokit.AlgorandClient.fromClients({ algod, indexer, kmd }) +const algorand = AlgorandClient.fromClients({ algod, indexer, kmd }) // Point to custom configuration for algod -const algorand = algokit.AlgorandClient.fromConfig({ algodConfig }) +const algorand = AlgorandClient.fromConfig({ algodConfig }) // Point to custom configuration for algod, indexer and kmd -const algorand = algokit.AlgorandClient.fromConfig({ algodConfig, indexerConfig, kmdConfig }) +const algorand = AlgorandClient.fromConfig({ algodConfig, indexerConfig, kmdConfig }) ``` ## Testing diff --git a/docs/capabilities/account.md b/docs/capabilities/account.md index a62eaabe..df05ba72 100644 --- a/docs/capabilities/account.md +++ b/docs/capabilities/account.md @@ -109,7 +109,7 @@ await algorand.account.rekeyAccount({ // Using a rekeyed account // Note: if a signing account is passed into `algorand.account.rekeyAccount` then you don't need to call `rekeyedAccount` to register the new signer -const rekeyedAccount = algokit.rekeyedAccount(newAccount, account.addr) +const rekeyedAccount = algorand.account.rekeyed(account.addr, newAccount) // rekeyedAccount can be used to sign transactions on behalf of account... ``` diff --git a/docs/capabilities/algorand-client.md b/docs/capabilities/algorand-client.md index 8cddd70f..8489abcf 100644 --- a/docs/capabilities/algorand-client.md +++ b/docs/capabilities/algorand-client.md @@ -2,27 +2,27 @@ `AlgorandClient` is a client class that brokers easy access to Algorand functionality. It's the [default entrypoint](../README.md#usage) into AlgoKit Utils functionality. -The main entrypoint to the bulk of the functionality in AlgoKit Utils is the `AlgorandClient` class, most of the time you can get started by typing `algokit.AlgorandClient.` and choosing one of the static initialisation methods to create an [Algorand client](./capabilities/algorand-client.md), e.g.: +The main entrypoint to the bulk of the functionality in AlgoKit Utils is the `AlgorandClient` class, most of the time you can get started by typing `AlgorandClient.` and choosing one of the static initialisation methods to create an [Algorand client](./capabilities/algorand-client.md), e.g.: ```typescript // Point to the network configured through environment variables or // if no environment variables it will point to the default LocalNet // configuration -const algorand = algokit.AlgorandClient.fromEnvironment() +const algorand = AlgorandClient.fromEnvironment() // Point to default LocalNet configuration -const algorand = algokit.AlgorandClient.defaultLocalNet() +const algorand = AlgorandClient.defaultLocalNet() // Point to TestNet using AlgoNode free tier -const algorand = algokit.AlgorandClient.testNet() +const algorand = AlgorandClient.testNet() // Point to MainNet using AlgoNode free tier -const algorand = algokit.AlgorandClient.mainNet() +const algorand = AlgorandClient.mainNet() // Point to a pre-created algod client -const algorand = algokit.AlgorandClient.fromClients({ algod }) +const algorand = AlgorandClient.fromClients({ algod }) // Point to pre-created algod, indexer and kmd clients -const algorand = algokit.AlgorandClient.fromClients({ algod, indexer, kmd }) +const algorand = AlgorandClient.fromClients({ algod, indexer, kmd }) // Point to custom configuration for algod -const algorand = algokit.AlgorandClient.fromConfig({ algodConfig }) +const algorand = AlgorandClient.fromConfig({ algodConfig }) // Point to custom configuration for algod, indexer and kmd -const algorand = algokit.AlgorandClient.fromConfig({ algodConfig, indexerConfig, kmdConfig }) +const algorand = AlgorandClient.fromConfig({ algodConfig, indexerConfig, kmdConfig }) ``` ## Accessing SDK clients diff --git a/docs/capabilities/asset.md b/docs/capabilities/asset.md index e0bd2b3a..a5fd8aa0 100644 --- a/docs/capabilities/asset.md +++ b/docs/capabilities/asset.md @@ -274,37 +274,57 @@ await algorand.send.assetOptOut({ }) ``` -### `assetBulkOptIn` +### `asset.bulkOptIn` -The [`assetBulkOptIn`](../code/classes/types_account_manager.AccountManager.md#assetbulkoptin) function facilitates the opt-in process for an account to multiple assets, allowing the account to receive and hold those assets. +The [`asset.bulkOptIn`](../code/classes/types_asset_manager.AssetManager.md#bulkoptin) function facilitates the opt-in process for an account to multiple assets, allowing the account to receive and hold those assets. ```typescript // Basic example -algorand.account.assetBulkOptIn('ACCOUNTADDRESS', [12345n, 67890n]) +algorand.asset.bulkOptIn('ACCOUNTADDRESS', [12345n, 67890n]) // Advanced example -algorand.account.assetBulkOptIn('ACCOUNTADDRESS', [12345n, 67890n], { +algorand.asset.bulkOptIn('ACCOUNTADDRESS', [12345n, 67890n], { maxFee: (1000).microAlgos(), suppressLog: true, }) ``` -### `assetBulkOptOut` +### `asset.bulkOptOut` -The [`assetBulkOptOut`](../code/classes/types_account_manager.AccountManager.md#assetbulkoptout) function facilitates the opt-out process for an account from multiple assets, permitting the account to discontinue holding a group of assets. +The [`asset.bulkOptOut`](../code/classes/types_asset_manager.AssetManager.md#bulkoptout) function facilitates the opt-out process for an account from multiple assets, permitting the account to discontinue holding a group of assets. ```typescript // Basic example -algorand.account.assetBulkOptOut('ACCOUNTADDRESS', [12345n, 67890n]) +algorand.asset.bulkOptOut('ACCOUNTADDRESS', [12345n, 67890n]) // Advanced example -algorand.account.assetBulkOptOut('ACCOUNTADDRESS', [12345n, 67890n], { +algorand.asset.bulkOptOut('ACCOUNTADDRESS', [12345n, 67890n], { ensureZeroBalance: true, maxFee: (1000).microAlgos(), suppressLog: true, }) ``` + +## Get information + +### Getting current parameters for an asset + +You can get the current parameters of an asset from algod by using `algorand.asset.getById(assetId)`. + +```typescript +const assetInfo = await assetManager.getById(12353n) +``` + +### Getting current holdings of an asset for an account + +You can get the current holdings of an asset for a given account from algod by using `algorand.asset.getAccountInformation(accountAddress, assetId)`. + +```typescript +const address = 'XBYLS2E6YI6XXL5BWCAMOA4GTWHXWENZMX5UHXMRNWWUQ7BXCY5WC5TEPA' +const assetId = 123345n +const accountInfo = await algorand.asset.getAccountInformation(address, assetId) +``` diff --git a/docs/code/classes/types_account_manager.AccountManager.md b/docs/code/classes/types_account_manager.AccountManager.md index 21558990..5a9da9f4 100644 --- a/docs/code/classes/types_account_manager.AccountManager.md +++ b/docs/code/classes/types_account_manager.AccountManager.md @@ -27,8 +27,6 @@ Creates and keeps track of signing accounts that can sign transactions for a sen - [\_getComposer](types_account_manager.AccountManager.md#_getcomposer) - [\_getEnsureFundedAmount](types_account_manager.AccountManager.md#_getensurefundedamount) -- [assetBulkOptIn](types_account_manager.AccountManager.md#assetbulkoptin) -- [assetBulkOptOut](types_account_manager.AccountManager.md#assetbulkoptout) - [dispenserFromEnvironment](types_account_manager.AccountManager.md#dispenserfromenvironment) - [ensureFunded](types_account_manager.AccountManager.md#ensurefunded) - [ensureFundedFromEnvironment](types_account_manager.AccountManager.md#ensurefundedfromenvironment) @@ -37,7 +35,6 @@ Creates and keeps track of signing accounts that can sign transactions for a sen - [fromKmd](types_account_manager.AccountManager.md#fromkmd) - [fromMnemonic](types_account_manager.AccountManager.md#frommnemonic) - [getAccount](types_account_manager.AccountManager.md#getaccount) -- [getAssetInformation](types_account_manager.AccountManager.md#getassetinformation) - [getInformation](types_account_manager.AccountManager.md#getinformation) - [getSigner](types_account_manager.AccountManager.md#getsigner) - [localNetDispenser](types_account_manager.AccountManager.md#localnetdispenser) @@ -77,7 +74,7 @@ const accountManager = new AccountManager(clientManager) #### Defined in -[src/types/account-manager.ts:71](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/account-manager.ts#L71) +[src/types/account-manager.ts:55](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/account-manager.ts#L55) ## Properties @@ -91,7 +88,7 @@ const accountManager = new AccountManager(clientManager) #### Defined in -[src/types/account-manager.ts:60](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/account-manager.ts#L60) +[src/types/account-manager.ts:44](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/account-manager.ts#L44) ___ @@ -101,7 +98,7 @@ ___ #### Defined in -[src/types/account-manager.ts:58](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/account-manager.ts#L58) +[src/types/account-manager.ts:42](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/account-manager.ts#L42) ___ @@ -111,7 +108,7 @@ ___ #### Defined in -[src/types/account-manager.ts:61](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/account-manager.ts#L61) +[src/types/account-manager.ts:45](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/account-manager.ts#L45) ___ @@ -121,7 +118,7 @@ ___ #### Defined in -[src/types/account-manager.ts:59](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/account-manager.ts#L59) +[src/types/account-manager.ts:43](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/account-manager.ts#L43) ## Accessors @@ -137,7 +134,7 @@ KMD account manager that allows you to easily get and create accounts using KMD. #### Defined in -[src/types/account-manager.ts:85](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/account-manager.ts#L85) +[src/types/account-manager.ts:69](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/account-manager.ts#L69) ## Methods @@ -157,7 +154,7 @@ KMD account manager that allows you to easily get and create accounts using KMD. #### Defined in -[src/types/account-manager.ts:76](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/account-manager.ts#L76) +[src/types/account-manager.ts:60](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/account-manager.ts#L60) ___ @@ -179,81 +176,7 @@ ___ #### Defined in -[src/types/account-manager.ts:666](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/account-manager.ts#L666) - -___ - -### assetBulkOptIn - -▸ **assetBulkOptIn**(`account`, `assetIds`, `options?`): `Promise`\<[`BulkAssetOptInOutResult`](../interfaces/types_account_manager.BulkAssetOptInOutResult.md)[]\> - -Opt an account in to a list of Algorand Standard Assets. - -Transactions will be sent in batches of 16 as transaction groups. - -#### Parameters - -| Name | Type | Description | -| :------ | :------ | :------ | -| `account` | `string` \| [`TransactionSignerAccount`](../interfaces/types_account.TransactionSignerAccount.md) | The account to opt-in | -| `assetIds` | `bigint`[] | The list of asset IDs to opt-in to | -| `options?` | `Omit`\<[`CommonTransactionParams`](../modules/types_composer.md#commontransactionparams), ``"sender"``\> & [`ExecuteParams`](../interfaces/types_composer.ExecuteParams.md) | Any parameters to control the transaction or execution of the transaction | - -#### Returns - -`Promise`\<[`BulkAssetOptInOutResult`](../interfaces/types_account_manager.BulkAssetOptInOutResult.md)[]\> - -An array of records matching asset ID to transaction ID of the opt in - -**`Example`** - -```typescript -// Basic example -algorand.account.assetBulkOptIn("ACCOUNTADDRESS", [12345n, 67890n]) -// With configuration -algorand.account.assetBulkOptIn("ACCOUNTADDRESS", [12345n, 67890n], { maxFee: (1000).microAlgos(), suppressLog: true }) -``` - -#### Defined in - -[src/types/account-manager.ts:478](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/account-manager.ts#L478) - -___ - -### assetBulkOptOut - -▸ **assetBulkOptOut**(`account`, `assetIds`, `options?`): `Promise`\<[`BulkAssetOptInOutResult`](../interfaces/types_account_manager.BulkAssetOptInOutResult.md)[]\> - -Opt an account out of a list of Algorand Standard Assets. - -Transactions will be sent in batches of 16 as transaction groups. - -#### Parameters - -| Name | Type | Description | -| :------ | :------ | :------ | -| `account` | `string` \| [`TransactionSignerAccount`](../interfaces/types_account.TransactionSignerAccount.md) | The account to opt-in | -| `assetIds` | `bigint`[] | The list of asset IDs to opt-out of | -| `options?` | `Omit`\<[`CommonTransactionParams`](../modules/types_composer.md#commontransactionparams), ``"sender"``\> & [`ExecuteParams`](../interfaces/types_composer.ExecuteParams.md) & \{ `ensureZeroBalance?`: `boolean` } | Any parameters to control the transaction or execution of the transaction | - -#### Returns - -`Promise`\<[`BulkAssetOptInOutResult`](../interfaces/types_account_manager.BulkAssetOptInOutResult.md)[]\> - -An array of records matching asset ID to transaction ID of the opt in - -**`Example`** - -```typescript -// Basic example -algorand.account.assetBulkOptOut("ACCOUNTADDRESS", [12345n, 67890n]) -// With configuration -algorand.account.assetBulkOptOut("ACCOUNTADDRESS", [12345n, 67890n], { ensureZeroBalance: true, maxFee: (1000).microAlgos(), suppressLog: true }) -``` - -#### Defined in - -[src/types/account-manager.ts:530](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/account-manager.ts#L530) +[src/types/account-manager.ts:480](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/account-manager.ts#L480) ___ @@ -283,7 +206,7 @@ const account = await account.dispenserFromEnvironment() #### Defined in -[src/types/account-manager.ts:437](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/account-manager.ts#L437) +[src/types/account-manager.ts:393](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/account-manager.ts#L393) ___ @@ -326,7 +249,7 @@ await algorand.account.ensureFunded("ACCOUNTADDRESS", "DISPENSERADDRESS", algoki #### Defined in -[src/types/account-manager.ts:699](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/account-manager.ts#L699) +[src/types/account-manager.ts:513](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/account-manager.ts#L513) ___ @@ -375,7 +298,7 @@ await algorand.account.ensureFundedFromEnvironment("ACCOUNTADDRESS", algokit.alg #### Defined in -[src/types/account-manager.ts:761](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/account-manager.ts#L761) +[src/types/account-manager.ts:575](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/account-manager.ts#L575) ___ @@ -419,7 +342,7 @@ await algorand.account.ensureFundedUsingDispenserAPI("ACCOUNTADDRESS", algorand. #### Defined in -[src/types/account-manager.ts:817](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/account-manager.ts#L817) +[src/types/account-manager.ts:631](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/account-manager.ts#L631) ___ @@ -464,7 +387,7 @@ If not running against LocalNet then it will use proces.env.MY_ACCOUNT_MNEMONIC #### Defined in -[src/types/account-manager.ts:330](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/account-manager.ts#L330) +[src/types/account-manager.ts:286](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/account-manager.ts#L286) ___ @@ -498,7 +421,7 @@ const defaultDispenserAccount = await account.fromKmd('unencrypted-default-walle #### Defined in -[src/types/account-manager.ts:366](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/account-manager.ts#L366) +[src/types/account-manager.ts:322](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/account-manager.ts#L322) ___ @@ -530,7 +453,7 @@ const rekeyedAccount = accountManager.fromMnemonic("mnemonic secret ...", "SENDE #### Defined in -[src/types/account-manager.ts:282](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/account-manager.ts#L282) +[src/types/account-manager.ts:238](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/account-manager.ts#L238) ___ @@ -565,42 +488,7 @@ const account = accountManager.getAccount(sender) #### Defined in -[src/types/account-manager.ts:197](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/account-manager.ts#L197) - -___ - -### getAssetInformation - -▸ **getAssetInformation**(`sender`, `assetId`): `Promise`\<[`AccountAssetInformation`](../modules/types_account.md#accountassetinformation)\> - -Returns the given sender account's asset holding for a given asset. - -#### Parameters - -| Name | Type | Description | -| :------ | :------ | :------ | -| `sender` | `string` \| [`TransactionSignerAccount`](../interfaces/types_account.TransactionSignerAccount.md) | The address of the sender/account to look up | -| `assetId` | `number` \| `bigint` | The ID of the asset to return a holding for | - -#### Returns - -`Promise`\<[`AccountAssetInformation`](../modules/types_account.md#accountassetinformation)\> - -The account asset holding information - -**`Example`** - -```typescript -const address = "XBYLS2E6YI6XXL5BWCAMOA4GTWHXWENZMX5UHXMRNWWUQ7BXCY5WC5TEPA"; -const assetId = 123345; -const accountInfo = await accountManager.getAssetInformation(address, assetId); -``` - -[Response data schema details](https://developer.algorand.org/docs/rest-apis/algod/#get-v2accountsaddressassetsasset-id) - -#### Defined in - -[src/types/account-manager.ts:256](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/account-manager.ts#L256) +[src/types/account-manager.ts:181](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/account-manager.ts#L181) ___ @@ -633,7 +521,7 @@ const accountInfo = await accountManager.getInformation(address); #### Defined in -[src/types/account-manager.ts:216](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/account-manager.ts#L216) +[src/types/account-manager.ts:200](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/account-manager.ts#L200) ___ @@ -666,7 +554,7 @@ const signer = accountManager.getSigner("SENDERADDRESS") #### Defined in -[src/types/account-manager.ts:177](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/account-manager.ts#L177) +[src/types/account-manager.ts:161](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/account-manager.ts#L161) ___ @@ -690,7 +578,7 @@ const account = await account.localNetDispenser() #### Defined in -[src/types/account-manager.ts:456](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/account-manager.ts#L456) +[src/types/account-manager.ts:412](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/account-manager.ts#L412) ___ @@ -721,7 +609,7 @@ const account = account.logicsig(program, [new Uint8Array(3, ...)]) #### Defined in -[src/types/account-manager.ts:404](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/account-manager.ts#L404) +[src/types/account-manager.ts:360](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/account-manager.ts#L360) ___ @@ -753,7 +641,7 @@ const account = accountManager.multisig({version: 1, threshold: 1, addrs: ["ADDR #### Defined in -[src/types/account-manager.ts:389](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/account-manager.ts#L389) +[src/types/account-manager.ts:345](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/account-manager.ts#L345) ___ @@ -777,7 +665,7 @@ const account = account.random() #### Defined in -[src/types/account-manager.ts:417](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/account-manager.ts#L417) +[src/types/account-manager.ts:373](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/account-manager.ts#L373) ___ @@ -837,7 +725,7 @@ await algorand.account.rekeyAccount({ #### Defined in -[src/types/account-manager.ts:641](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/account-manager.ts#L641) +[src/types/account-manager.ts:455](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/account-manager.ts#L455) ___ @@ -869,7 +757,7 @@ const rekeyedAccount = accountManager.rekeyed(account, "SENDERADDRESS...") #### Defined in -[src/types/account-manager.ts:299](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/account-manager.ts#L299) +[src/types/account-manager.ts:255](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/account-manager.ts#L255) ___ @@ -906,7 +794,7 @@ const signer = accountManager.getSigner("{SENDERADDRESS}") #### Defined in -[src/types/account-manager.ts:105](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/account-manager.ts#L105) +[src/types/account-manager.ts:89](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/account-manager.ts#L89) ___ @@ -938,7 +826,7 @@ const accountManager = new AccountManager(clientManager) #### Defined in -[src/types/account-manager.ts:159](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/account-manager.ts#L159) +[src/types/account-manager.ts:143](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/account-manager.ts#L143) ___ @@ -976,7 +864,7 @@ const accountManager = new AccountManager(clientManager) #### Defined in -[src/types/account-manager.ts:143](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/account-manager.ts#L143) +[src/types/account-manager.ts:127](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/account-manager.ts#L127) ___ @@ -1005,4 +893,4 @@ retrieval and returns a `TransactionSignerAccount` along with the original accou #### Defined in -[src/types/account-manager.ts:114](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/account-manager.ts#L114) +[src/types/account-manager.ts:98](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/account-manager.ts#L98) diff --git a/docs/code/classes/types_asset_manager.AssetManager.md b/docs/code/classes/types_asset_manager.AssetManager.md index 2fae1315..febe3c03 100644 --- a/docs/code/classes/types_asset_manager.AssetManager.md +++ b/docs/code/classes/types_asset_manager.AssetManager.md @@ -14,17 +14,22 @@ Allows management of asset information. ### Properties +- [\_accountManager](types_asset_manager.AssetManager.md#_accountmanager) - [\_clientManager](types_asset_manager.AssetManager.md#_clientmanager) ### Methods +- [\_getComposer](types_asset_manager.AssetManager.md#_getcomposer) +- [bulkOptIn](types_asset_manager.AssetManager.md#bulkoptin) +- [bulkOptOut](types_asset_manager.AssetManager.md#bulkoptout) +- [getAccountInformation](types_asset_manager.AssetManager.md#getaccountinformation) - [getById](types_asset_manager.AssetManager.md#getbyid) ## Constructors ### constructor -• **new AssetManager**(`clientManager`): [`AssetManager`](types_asset_manager.AssetManager.md) +• **new AssetManager**(`clientManager`, `accountManager`): [`AssetManager`](types_asset_manager.AssetManager.md) Create a new asset manager. @@ -33,6 +38,7 @@ Create a new asset manager. | Name | Type | Description | | :------ | :------ | :------ | | `clientManager` | [`ClientManager`](types_client_manager.ClientManager.md) | The ClientManager client to use for algod client | +| `accountManager` | [`AccountManager`](types_account_manager.AccountManager.md) | - | #### Returns @@ -46,20 +52,159 @@ const assetManager = new AssetManager(clientManager) #### Defined in -[src/types/asset-manager.ts:137](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/asset-manager.ts#L137) +[src/types/asset-manager.ts:152](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/asset-manager.ts#L152) ## Properties +### \_accountManager + +• `Private` **\_accountManager**: [`AccountManager`](types_account_manager.AccountManager.md) + +#### Defined in + +[src/types/asset-manager.ts:142](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/asset-manager.ts#L142) + +___ + ### \_clientManager • `Private` **\_clientManager**: [`ClientManager`](types_client_manager.ClientManager.md) #### Defined in -[src/types/asset-manager.ts:127](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/asset-manager.ts#L127) +[src/types/asset-manager.ts:141](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/asset-manager.ts#L141) ## Methods +### \_getComposer + +▸ **_getComposer**(`getSuggestedParams?`): [`default`](types_composer.default.md) + +#### Parameters + +| Name | Type | +| :------ | :------ | +| `getSuggestedParams?` | () => `Promise`\<`SuggestedParams`\> | + +#### Returns + +[`default`](types_composer.default.md) + +#### Defined in + +[src/types/asset-manager.ts:157](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/asset-manager.ts#L157) + +___ + +### bulkOptIn + +▸ **bulkOptIn**(`account`, `assetIds`, `options?`): `Promise`\<[`BulkAssetOptInOutResult`](../interfaces/types_asset_manager.BulkAssetOptInOutResult.md)[]\> + +Opt an account in to a list of Algorand Standard Assets. + +Transactions will be sent in batches of 16 as transaction groups. + +#### Parameters + +| Name | Type | Description | +| :------ | :------ | :------ | +| `account` | `string` \| [`TransactionSignerAccount`](../interfaces/types_account.TransactionSignerAccount.md) | The account to opt-in | +| `assetIds` | `bigint`[] | The list of asset IDs to opt-in to | +| `options?` | `Omit`\<[`CommonTransactionParams`](../modules/types_composer.md#commontransactionparams), ``"sender"``\> & [`ExecuteParams`](../interfaces/types_composer.ExecuteParams.md) | Any parameters to control the transaction or execution of the transaction | + +#### Returns + +`Promise`\<[`BulkAssetOptInOutResult`](../interfaces/types_asset_manager.BulkAssetOptInOutResult.md)[]\> + +An array of records matching asset ID to transaction ID of the opt in + +**`Example`** + +```typescript +// Basic example +algorand.asset.bulkOptIn("ACCOUNTADDRESS", [12345n, 67890n]) +// With configuration +algorand.asset.bulkOptIn("ACCOUNTADDRESS", [12345n, 67890n], { maxFee: (1000).microAlgos(), suppressLog: true }) +``` + +#### Defined in + +[src/types/asset-manager.ts:244](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/asset-manager.ts#L244) + +___ + +### bulkOptOut + +▸ **bulkOptOut**(`account`, `assetIds`, `options?`): `Promise`\<[`BulkAssetOptInOutResult`](../interfaces/types_asset_manager.BulkAssetOptInOutResult.md)[]\> + +Opt an account out of a list of Algorand Standard Assets. + +Transactions will be sent in batches of 16 as transaction groups. + +#### Parameters + +| Name | Type | Description | +| :------ | :------ | :------ | +| `account` | `string` \| [`TransactionSignerAccount`](../interfaces/types_account.TransactionSignerAccount.md) | The account to opt-in | +| `assetIds` | `bigint`[] | The list of asset IDs to opt-out of | +| `options?` | `Omit`\<[`CommonTransactionParams`](../modules/types_composer.md#commontransactionparams), ``"sender"``\> & [`ExecuteParams`](../interfaces/types_composer.ExecuteParams.md) & \{ `ensureZeroBalance?`: `boolean` } | Any parameters to control the transaction or execution of the transaction | + +#### Returns + +`Promise`\<[`BulkAssetOptInOutResult`](../interfaces/types_asset_manager.BulkAssetOptInOutResult.md)[]\> + +An array of records matching asset ID to transaction ID of the opt in + +**`Example`** + +```typescript +// Basic example +algorand.asset.bulkOptOut("ACCOUNTADDRESS", [12345n, 67890n]) +// With configuration +algorand.asset.bulkOptOut("ACCOUNTADDRESS", [12345n, 67890n], { ensureZeroBalance: true, maxFee: (1000).microAlgos(), suppressLog: true }) +``` + +#### Defined in + +[src/types/asset-manager.ts:296](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/asset-manager.ts#L296) + +___ + +### getAccountInformation + +▸ **getAccountInformation**(`sender`, `assetId`): `Promise`\<[`AccountAssetInformation`](../modules/types_account.md#accountassetinformation)\> + +Returns the given sender account's asset holding for a given asset. + +#### Parameters + +| Name | Type | Description | +| :------ | :------ | :------ | +| `sender` | `string` \| [`TransactionSignerAccount`](../interfaces/types_account.TransactionSignerAccount.md) | The address of the sender/account to look up | +| `assetId` | `bigint` | The ID of the asset to return a holding for | + +#### Returns + +`Promise`\<[`AccountAssetInformation`](../modules/types_account.md#accountassetinformation)\> + +The account asset holding information + +**`Example`** + +```typescript +const address = "XBYLS2E6YI6XXL5BWCAMOA4GTWHXWENZMX5UHXMRNWWUQ7BXCY5WC5TEPA"; +const assetId = 123345n; +const accountInfo = await algorand.asset.getAccountInformation(address, assetId); +``` + +[Response data schema details](https://developer.algorand.org/docs/rest-apis/algod/#get-v2accountsaddressassetsasset-id) + +#### Defined in + +[src/types/asset-manager.ts:214](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/asset-manager.ts#L214) + +___ + ### getById ▸ **getById**(`assetId`): `Promise`\<[`AssetInformation`](../interfaces/types_asset_manager.AssetInformation.md)\> @@ -86,4 +231,4 @@ const assetInfo = await assetManager.getById(12353n); #### Defined in -[src/types/asset-manager.ts:152](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/asset-manager.ts#L152) +[src/types/asset-manager.ts:176](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/asset-manager.ts#L176) diff --git a/docs/code/interfaces/types_account_manager.BulkAssetOptInOutResult.md b/docs/code/interfaces/types_account_manager.BulkAssetOptInOutResult.md deleted file mode 100644 index ede8d762..00000000 --- a/docs/code/interfaces/types_account_manager.BulkAssetOptInOutResult.md +++ /dev/null @@ -1,38 +0,0 @@ -[@algorandfoundation/algokit-utils](../README.md) / [types/account-manager](../modules/types_account_manager.md) / BulkAssetOptInOutResult - -# Interface: BulkAssetOptInOutResult - -[types/account-manager](../modules/types_account_manager.md).BulkAssetOptInOutResult - -Individual result from performing a bulk opt-in or bulk opt-out for an account against a series of assets. - -## Table of contents - -### Properties - -- [assetId](types_account_manager.BulkAssetOptInOutResult.md#assetid) -- [transactionId](types_account_manager.BulkAssetOptInOutResult.md#transactionid) - -## Properties - -### assetId - -• **assetId**: `bigint` - -The ID of the asset opted into / out of - -#### Defined in - -[src/types/account-manager.ts:27](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/account-manager.ts#L27) - -___ - -### transactionId - -• **transactionId**: `string` - -The transaction ID of the resulting opt in / out - -#### Defined in - -[src/types/account-manager.ts:29](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/account-manager.ts#L29) diff --git a/docs/code/interfaces/types_account_manager.EnsureFundedResult.md b/docs/code/interfaces/types_account_manager.EnsureFundedResult.md index 739afab5..75df9c74 100644 --- a/docs/code/interfaces/types_account_manager.EnsureFundedResult.md +++ b/docs/code/interfaces/types_account_manager.EnsureFundedResult.md @@ -23,7 +23,7 @@ The amount that was sent to the account. #### Defined in -[src/types/account-manager.ts:37](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/account-manager.ts#L37) +[src/types/account-manager.ts:21](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/account-manager.ts#L21) ___ @@ -35,4 +35,4 @@ The transaction ID of the transaction that funded the account. #### Defined in -[src/types/account-manager.ts:35](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/account-manager.ts#L35) +[src/types/account-manager.ts:19](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/account-manager.ts#L19) diff --git a/docs/code/interfaces/types_asset_manager.AssetInformation.md b/docs/code/interfaces/types_asset_manager.AssetInformation.md index 2b5218f5..0d4e47b7 100644 --- a/docs/code/interfaces/types_asset_manager.AssetInformation.md +++ b/docs/code/interfaces/types_asset_manager.AssetInformation.md @@ -4,6 +4,8 @@ [types/asset-manager](../modules/types_asset_manager.md).AssetInformation +Information about an asset. + ## Table of contents ### Properties @@ -35,7 +37,7 @@ The ID of the asset. #### Defined in -[src/types/asset-manager.ts:7](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/asset-manager.ts#L7) +[src/types/asset-manager.ts:21](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/asset-manager.ts#L21) ___ @@ -49,7 +51,7 @@ Max size is 32 bytes. #### Defined in -[src/types/asset-manager.ts:98](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/asset-manager.ts#L98) +[src/types/asset-manager.ts:112](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/asset-manager.ts#L112) ___ @@ -63,7 +65,7 @@ Max size is 32 bytes. #### Defined in -[src/types/asset-manager.ts:104](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/asset-manager.ts#L104) +[src/types/asset-manager.ts:118](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/asset-manager.ts#L118) ___ @@ -81,7 +83,7 @@ If not set the field is permanently empty. #### Defined in -[src/types/asset-manager.ts:80](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/asset-manager.ts#L80) +[src/types/asset-manager.ts:94](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/asset-manager.ts#L94) ___ @@ -97,7 +99,7 @@ closing out an asset position and opting-out of the asset. #### Defined in -[src/types/asset-manager.ts:15](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/asset-manager.ts#L15) +[src/types/asset-manager.ts:29](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/asset-manager.ts#L29) ___ @@ -115,7 +117,7 @@ The amount of decimal places the asset was created with. #### Defined in -[src/types/asset-manager.ts:31](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/asset-manager.ts#L31) +[src/types/asset-manager.ts:45](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/asset-manager.ts#L45) ___ @@ -131,7 +133,7 @@ transaction from the `freeze` account. #### Defined in -[src/types/asset-manager.ts:39](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/asset-manager.ts#L39) +[src/types/asset-manager.ts:53](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/asset-manager.ts#L53) ___ @@ -147,7 +149,7 @@ If not set the field is permanently empty. #### Defined in -[src/types/asset-manager.ts:69](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/asset-manager.ts#L69) +[src/types/asset-manager.ts:83](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/asset-manager.ts#L83) ___ @@ -161,7 +163,7 @@ If not set the asset is permanently immutable. #### Defined in -[src/types/asset-manager.ts:45](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/asset-manager.ts#L45) +[src/types/asset-manager.ts:59](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/asset-manager.ts#L59) ___ @@ -175,7 +177,7 @@ The format of this metadata is up to the application. #### Defined in -[src/types/asset-manager.ts:122](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/asset-manager.ts#L122) +[src/types/asset-manager.ts:136](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/asset-manager.ts#L136) ___ @@ -197,7 +199,7 @@ If not set the field is permanently empty. #### Defined in -[src/types/asset-manager.ts:60](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/asset-manager.ts#L60) +[src/types/asset-manager.ts:74](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/asset-manager.ts#L74) ___ @@ -211,7 +213,7 @@ For example, if `decimals` is, say, 2, then for every 100 `total` there is 1 who #### Defined in -[src/types/asset-manager.ts:21](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/asset-manager.ts#L21) +[src/types/asset-manager.ts:35](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/asset-manager.ts#L35) ___ @@ -225,7 +227,7 @@ Max size is 8 bytes. #### Defined in -[src/types/asset-manager.ts:86](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/asset-manager.ts#L86) +[src/types/asset-manager.ts:100](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/asset-manager.ts#L100) ___ @@ -239,7 +241,7 @@ Max size is 8 bytes. #### Defined in -[src/types/asset-manager.ts:92](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/asset-manager.ts#L92) +[src/types/asset-manager.ts:106](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/asset-manager.ts#L106) ___ @@ -253,7 +255,7 @@ Max size is 96 bytes. #### Defined in -[src/types/asset-manager.ts:110](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/asset-manager.ts#L110) +[src/types/asset-manager.ts:124](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/asset-manager.ts#L124) ___ @@ -267,4 +269,4 @@ Max size is 96 bytes. #### Defined in -[src/types/asset-manager.ts:116](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/asset-manager.ts#L116) +[src/types/asset-manager.ts:130](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/asset-manager.ts#L130) diff --git a/docs/code/interfaces/types_asset_manager.BulkAssetOptInOutResult.md b/docs/code/interfaces/types_asset_manager.BulkAssetOptInOutResult.md new file mode 100644 index 00000000..bc9ce521 --- /dev/null +++ b/docs/code/interfaces/types_asset_manager.BulkAssetOptInOutResult.md @@ -0,0 +1,38 @@ +[@algorandfoundation/algokit-utils](../README.md) / [types/asset-manager](../modules/types_asset_manager.md) / BulkAssetOptInOutResult + +# Interface: BulkAssetOptInOutResult + +[types/asset-manager](../modules/types_asset_manager.md).BulkAssetOptInOutResult + +Individual result from performing a bulk opt-in or bulk opt-out for an account against a series of assets. + +## Table of contents + +### Properties + +- [assetId](types_asset_manager.BulkAssetOptInOutResult.md#assetid) +- [transactionId](types_asset_manager.BulkAssetOptInOutResult.md#transactionid) + +## Properties + +### assetId + +• **assetId**: `bigint` + +The ID of the asset opted into / out of + +#### Defined in + +[src/types/asset-manager.ts:13](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/asset-manager.ts#L13) + +___ + +### transactionId + +• **transactionId**: `string` + +The transaction ID of the resulting opt in / out + +#### Defined in + +[src/types/asset-manager.ts:15](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/asset-manager.ts#L15) diff --git a/docs/code/modules/index.md b/docs/code/modules/index.md index 158dd48f..bab7972c 100644 --- a/docs/code/modules/index.md +++ b/docs/code/modules/index.md @@ -175,7 +175,7 @@ Account information at a given round. #### Defined in -[src/account/account.ts:134](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/account/account.ts#L134) +[src/account/account.ts:135](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/account/account.ts#L135) ## Variables @@ -262,7 +262,7 @@ A record object where the keys are the asset IDs and the values are the correspo **`Deprecated`** -use `algorandClient.account.assetBulkOptIn()` instead +use `algorandClient.asset.bulkOptIn()` instead Opt in to a list of assets on the Algorand blockchain. @@ -278,7 +278,7 @@ algokit.bulkOptIn({ account: account, assetIds: [12345, 67890] }, algod) #### Defined in -[src/asset.ts:131](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/asset.ts#L131) +[src/asset.ts:132](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/asset.ts#L132) ___ @@ -301,7 +301,7 @@ A record object containing asset IDs as keys and their corresponding transaction **`Deprecated`** -use `algorandClient.account.assetBulkOptOut()` instead +use `algorandClient.asset.bulkOptOut()` instead Opt out of multiple assets in Algorand blockchain. @@ -317,7 +317,7 @@ algokit.bulkOptOut({ account: account, assetIds: [12345, 67890] }, algod) #### Defined in -[src/asset.ts:158](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/asset.ts#L158) +[src/asset.ts:162](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/asset.ts#L162) ___ @@ -352,7 +352,7 @@ await algokit.assetOptIn({ account, assetId }, algod) #### Defined in -[src/asset.ts:68](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/asset.ts#L68) +[src/asset.ts:69](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/asset.ts#L69) ___ @@ -387,7 +387,7 @@ await algokit.assetOptOut({ account, assetId, assetCreatorAddress }, algod) #### Defined in -[src/asset.ts:99](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/asset.ts#L99) +[src/asset.ts:100](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/asset.ts#L100) ___ @@ -553,7 +553,7 @@ await algokit.createAsset({ creator: account, total: 1, decimals: 0, name: 'My a #### Defined in -[src/asset.ts:24](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/asset.ts#L24) +[src/asset.ts:25](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/asset.ts#L25) ___ @@ -885,7 +885,7 @@ Returns the string address of an Algorand account from a base64 encoded version #### Defined in -[src/account/account.ts:127](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/account/account.ts#L127) +[src/account/account.ts:128](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/account/account.ts#L128) ___ @@ -911,7 +911,7 @@ Returns an account's address as a byte array #### Defined in -[src/account/account.ts:116](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/account/account.ts#L116) +[src/account/account.ts:117](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/account/account.ts#L117) ___ @@ -935,7 +935,7 @@ The account asset holding information **`Deprecated`** -Use `algorandClient.account.getAssetInformation(sender, assetId)` or `new AccountManager(clientManager).getAssetInformation(sender, assetId)` instead. +Use `algorandClient.asset.getAccountInformation(sender, assetId)` or `new AssetManager(clientManager, accountManager).getAccountInformation(sender, assetId)` instead. Returns the given sender account's asset holding for a given asset. @@ -951,7 +951,7 @@ const accountInfo = await account.getAccountAssetInformation(address, assetId, a #### Defined in -[src/account/account.ts:193](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/account/account.ts#L193) +[src/account/account.ts:194](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/account/account.ts#L194) ___ @@ -1022,7 +1022,7 @@ const accountInfo = await account.getInformation(address, algod); #### Defined in -[src/account/account.ts:152](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/account/account.ts#L152) +[src/account/account.ts:153](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/account/account.ts#L153) ___ @@ -2281,7 +2281,7 @@ If not running against LocalNet then it will use proces.env.MY_ACCOUNT_MNEMONIC #### Defined in -[src/account/account.ts:96](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/account/account.ts#L96) +[src/account/account.ts:97](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/account/account.ts#L97) ___ @@ -2310,7 +2310,7 @@ Returns an account wrapper that supports partial or full multisig signing. #### Defined in -[src/account/account.ts:23](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/account/account.ts#L23) +[src/account/account.ts:24](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/account/account.ts#L24) ___ @@ -2489,7 +2489,7 @@ This is a wrapper around algosdk.generateAccount to provide a more friendly/obvi #### Defined in -[src/account/account.ts:59](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/account/account.ts#L59) +[src/account/account.ts:60](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/account/account.ts#L60) ___ @@ -2555,7 +2555,7 @@ Returns an account wrapper that supports a rekeyed account. #### Defined in -[src/account/account.ts:35](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/account/account.ts#L35) +[src/account/account.ts:36](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/account/account.ts#L36) ___ @@ -2803,7 +2803,7 @@ Returns an account wrapper that supports a transaction signer with associated se #### Defined in -[src/account/account.ts:47](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/account/account.ts#L47) +[src/account/account.ts:48](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/account/account.ts#L48) ___ diff --git a/docs/code/modules/types_account_manager.md b/docs/code/modules/types_account_manager.md index 0442fabf..796a5638 100644 --- a/docs/code/modules/types_account_manager.md +++ b/docs/code/modules/types_account_manager.md @@ -10,7 +10,6 @@ ### Interfaces -- [BulkAssetOptInOutResult](../interfaces/types_account_manager.BulkAssetOptInOutResult.md) - [EnsureFundedResult](../interfaces/types_account_manager.EnsureFundedResult.md) ### Functions @@ -40,4 +39,4 @@ A transaction signer #### Defined in -[src/types/account-manager.ts:46](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/account-manager.ts#L46) +[src/types/account-manager.ts:30](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/account-manager.ts#L30) diff --git a/docs/code/modules/types_asset_manager.md b/docs/code/modules/types_asset_manager.md index 77dade94..90f4864a 100644 --- a/docs/code/modules/types_asset_manager.md +++ b/docs/code/modules/types_asset_manager.md @@ -11,3 +11,4 @@ ### Interfaces - [AssetInformation](../interfaces/types_asset_manager.AssetInformation.md) +- [BulkAssetOptInOutResult](../interfaces/types_asset_manager.BulkAssetOptInOutResult.md) diff --git a/src/account/account.ts b/src/account/account.ts index 94129812..cfbb1a2e 100644 --- a/src/account/account.ts +++ b/src/account/account.ts @@ -3,6 +3,7 @@ import { getSenderAddress } from '../transaction/transaction' import { AccountAssetInformation, MultisigAccount, SigningAccount, TransactionSignerAccount } from '../types/account' import { AccountManager } from '../types/account-manager' import { AlgoAmount } from '../types/amount' +import { AssetManager } from '../types/asset-manager' import { ClientManager } from '../types/client-manager' import { SendTransactionFrom } from '../types/transaction' import Account = algosdk.Account @@ -173,7 +174,7 @@ export async function getAccountInformation(sender: string | SendTransactionFrom } /** - * @deprecated Use `algorandClient.account.getAssetInformation(sender, assetId)` or `new AccountManager(clientManager).getAssetInformation(sender, assetId)` instead. + * @deprecated Use `algorandClient.asset.getAccountInformation(sender, assetId)` or `new AssetManager(clientManager, accountManager).getAccountInformation(sender, assetId)` instead. * * Returns the given sender account's asset holding for a given asset. * @@ -195,5 +196,6 @@ export async function getAccountAssetInformation( assetId: number | bigint, algod: Algodv2, ): Promise { - return new AccountManager(new ClientManager({ algod })).getAssetInformation(getSenderAddress(sender), assetId) + const clientManager = new ClientManager({ algod }) + return new AssetManager(clientManager, new AccountManager(clientManager)).getAccountInformation(getSenderAddress(sender), BigInt(assetId)) } diff --git a/src/asset.ts b/src/asset.ts index acb1e7b6..254535c5 100644 --- a/src/asset.ts +++ b/src/asset.ts @@ -3,6 +3,7 @@ import { encodeTransactionNote, getSenderAddress } from './transaction' import { legacySendTransactionBridge } from './transaction/legacy-bridge' import { AccountManager } from './types/account-manager' import { AssetBulkOptInOutParams, AssetOptInParams, AssetOptOutParams, CreateAssetParams } from './types/asset' +import { AssetManager } from './types/asset-manager' import { ClientManager } from './types/client-manager' import { AssetCreateParams, AssetOptInParams as NewAssetOptInParams, AssetOptOutParams as NewAssetOptOutParams } from './types/composer' import { SendTransactionResult } from './types/transaction' @@ -118,7 +119,7 @@ export async function assetOptOut(optOut: AssetOptOutParams, algod: Algodv2): Pr } /** - * @deprecated use `algorandClient.account.assetBulkOptIn()` instead + * @deprecated use `algorandClient.asset.bulkOptIn()` instead * * Opt in to a list of assets on the Algorand blockchain. * @@ -129,13 +130,16 @@ export async function assetOptOut(optOut: AssetOptOutParams, algod: Algodv2): Pr * @example algokit.bulkOptIn({ account: account, assetIds: [12345, 67890] }, algod) */ export async function assetBulkOptIn(optIn: AssetBulkOptInOutParams, algod: Algodv2): Promise> { - const result = await new AccountManager(new ClientManager({ algod })) - .setSignerFromAccount(optIn.account) - .assetBulkOptIn(getSenderAddress(optIn.account), optIn.assetIds.map(BigInt), { + const clientManager = new ClientManager({ algod }) + const result = await new AssetManager(clientManager, new AccountManager(clientManager).setSignerFromAccount(optIn.account)).bulkOptIn( + getSenderAddress(optIn.account), + optIn.assetIds.map(BigInt), + { note: encodeTransactionNote(optIn.note), maxFee: optIn.maxFee, suppressLog: optIn.suppressLog, - }) + }, + ) const returnResult: Record = {} for (const r of result) { @@ -145,7 +149,7 @@ export async function assetBulkOptIn(optIn: AssetBulkOptInOutParams, algod: Algo } /** - * @deprecated use `algorandClient.account.assetBulkOptOut()` instead + * @deprecated use `algorandClient.asset.bulkOptOut()` instead * * Opt out of multiple assets in Algorand blockchain. * @@ -156,14 +160,17 @@ export async function assetBulkOptIn(optIn: AssetBulkOptInOutParams, algod: Algo * @example algokit.bulkOptOut({ account: account, assetIds: [12345, 67890] }, algod) */ export async function assetBulkOptOut(optOut: AssetBulkOptInOutParams, algod: Algodv2): Promise> { - const result = await new AccountManager(new ClientManager({ algod })) - .setSignerFromAccount(optOut.account) - .assetBulkOptOut(getSenderAddress(optOut.account), optOut.assetIds.map(BigInt), { + const clientManager = new ClientManager({ algod }) + const result = await new AssetManager(clientManager, new AccountManager(clientManager).setSignerFromAccount(optOut.account)).bulkOptOut( + getSenderAddress(optOut.account), + optOut.assetIds.map(BigInt), + { ensureZeroBalance: optOut.validateBalances ?? true, note: encodeTransactionNote(optOut.note), maxFee: optOut.maxFee, suppressLog: optOut.suppressLog, - }) + }, + ) const returnResult: Record = {} for (const r of result) { diff --git a/src/indexer-lookup.spec.ts b/src/indexer-lookup.spec.ts index 48498398..90091cc7 100644 --- a/src/indexer-lookup.spec.ts +++ b/src/indexer-lookup.spec.ts @@ -1,5 +1,5 @@ import { beforeEach, describe, test } from '@jest/globals' -import { getTestingAppContract, getTestingAppCreateParams } from '../tests/example-contracts/testing-app/contract' +import { getTestingAppContract } from '../tests/example-contracts/testing-app/contract' import { indexer } from './' import { algorandFixture, runWhenIndexerCaughtUp } from './testing' import { AlgoAmount } from './types/amount' @@ -63,12 +63,7 @@ describe('indexer-lookup', () => { initialFunds: (1).algos(), suppressLog: true, }) - const createParams = await getTestingAppCreateParams(testAccount, { - name: 'test', - version: '1.0', - updatable: false, - deletable: false, - }) + const app = await getTestingAppContract() const app1 = await algorand.client .getAppClientById({ app: app.appSpec, id: 0, sender: testAccount }) diff --git a/src/types/account-manager.ts b/src/types/account-manager.ts index 9f81e4f7..e9bc73a1 100644 --- a/src/types/account-manager.ts +++ b/src/types/account-manager.ts @@ -1,19 +1,11 @@ import algosdk from 'algosdk' import { Config } from '../config' -import { calculateFundAmount, chunkArray, memoize } from '../util' -import { - AccountAssetInformation, - AccountInformation, - DISPENSER_ACCOUNT, - MultisigAccount, - SigningAccount, - TransactionSignerAccount, -} from './account' +import { calculateFundAmount, memoize } from '../util' +import { AccountInformation, DISPENSER_ACCOUNT, MultisigAccount, SigningAccount, TransactionSignerAccount } from './account' import { SendSingleTransactionResult } from './algorand-client' import { AlgoAmount } from './amount' -import { AssetManager } from './asset-manager' import { ClientManager } from './client-manager' -import AlgokitComposer, { CommonTransactionParams, ExecuteParams, MAX_TRANSACTION_GROUP_SIZE } from './composer' +import AlgokitComposer, { CommonTransactionParams, ExecuteParams } from './composer' import { TestNetDispenserApiClient } from './dispenser-client' import { KmdAccountManager } from './kmd-account-manager' import LogicSigAccount = algosdk.LogicSigAccount @@ -21,14 +13,6 @@ import Account = algosdk.Account import TransactionSigner = algosdk.TransactionSigner import AccountInformationModel = algosdk.modelsv2.Account -/** Individual result from performing a bulk opt-in or bulk opt-out for an account against a series of assets. */ -export interface BulkAssetOptInOutResult { - /** The ID of the asset opted into / out of */ - assetId: bigint - /** The transaction ID of the resulting opt in / out */ - transactionId: string -} - /** Result from performing an ensureFunded call. */ export interface EnsureFundedResult { /** The transaction ID of the transaction that funded the account. */ @@ -238,34 +222,6 @@ export class AccountManager { } } - /** - * Returns the given sender account's asset holding for a given asset. - * - * @example - * ```typescript - * const address = "XBYLS2E6YI6XXL5BWCAMOA4GTWHXWENZMX5UHXMRNWWUQ7BXCY5WC5TEPA"; - * const assetId = 123345; - * const accountInfo = await accountManager.getAssetInformation(address, assetId); - * ``` - * - * [Response data schema details](https://developer.algorand.org/docs/rest-apis/algod/#get-v2accountsaddressassetsasset-id) - * @param sender The address of the sender/account to look up - * @param assetId The ID of the asset to return a holding for - * @returns The account asset holding information - */ - public async getAssetInformation(sender: string | TransactionSignerAccount, assetId: number | bigint): Promise { - const info = await this._clientManager.algod - .accountAssetInformation(typeof sender === 'string' ? sender : sender.addr, Number(assetId)) - .do() - - return { - assetId: BigInt(assetId), - balance: BigInt(info['asset-holding']['amount']), - frozen: info['asset-holding']['is-frozen'] === true, - round: BigInt(info['round']), - } - } - /** * Tracks and returns an Algorand account with secret key loaded (i.e. that can sign transactions) by taking the mnemonic secret. * @@ -458,148 +414,6 @@ export class AccountManager { return this.signerAccount(dispenser.account) } - /** - * Opt an account in to a list of Algorand Standard Assets. - * - * Transactions will be sent in batches of 16 as transaction groups. - * - * @param account The account to opt-in - * @param assetIds The list of asset IDs to opt-in to - * @param options Any parameters to control the transaction or execution of the transaction - * @example Example using AlgorandClient - * ```typescript - * // Basic example - * algorand.account.assetBulkOptIn("ACCOUNTADDRESS", [12345n, 67890n]) - * // With configuration - * algorand.account.assetBulkOptIn("ACCOUNTADDRESS", [12345n, 67890n], { maxFee: (1000).microAlgos(), suppressLog: true }) - * ``` - * @returns An array of records matching asset ID to transaction ID of the opt in - */ - async assetBulkOptIn( - account: string | TransactionSignerAccount, - assetIds: bigint[], - options?: Omit & ExecuteParams, - ): Promise { - const results: BulkAssetOptInOutResult[] = [] - - const params = await this._clientManager.algod.getTransactionParams().do() - - for (const assetGroup of chunkArray(assetIds, MAX_TRANSACTION_GROUP_SIZE)) { - const composer = this._getComposer(() => Promise.resolve(params)) - - for (const assetId of assetGroup) { - composer.addAssetOptIn({ - ...options, - sender: typeof account === 'string' ? account : account.addr, - assetId: BigInt(assetId), - }) - } - - const result = await composer.execute(options) - - Config.getLogger(options?.suppressLog).info( - `Successfully opted in ${account} for assets ${assetGroup.join(', ')} with transaction IDs ${result.txIds.join(', ')}` + - `\n Grouped under ${result.groupId} in round ${result.confirmations?.[0]?.confirmedRound}.`, - ) - - assetGroup.forEach((assetId, index) => { - results.push({ assetId: BigInt(assetId), transactionId: result.txIds[index] }) - }) - } - - return results - } - - /** - * Opt an account out of a list of Algorand Standard Assets. - * - * Transactions will be sent in batches of 16 as transaction groups. - * - * @param account The account to opt-in - * @param assetIds The list of asset IDs to opt-out of - * @param options Any parameters to control the transaction or execution of the transaction - * @example Example using AlgorandClient - * ```typescript - * // Basic example - * algorand.account.assetBulkOptOut("ACCOUNTADDRESS", [12345n, 67890n]) - * // With configuration - * algorand.account.assetBulkOptOut("ACCOUNTADDRESS", [12345n, 67890n], { ensureZeroBalance: true, maxFee: (1000).microAlgos(), suppressLog: true }) - * ``` - * @returns An array of records matching asset ID to transaction ID of the opt in - */ - async assetBulkOptOut( - account: string | TransactionSignerAccount, - assetIds: bigint[], - options?: Omit & - ExecuteParams & { - /** Whether or not to check if the account has a zero balance for each asset first or not. - * - * Defaults to `true`. - * - * If this is set to `true` and the account has an asset balance it will throw an error. - * - * If this is set to `false` and the account has an asset balance it will lose those assets to the asset creator. - */ - ensureZeroBalance?: boolean - }, - ): Promise { - const results: BulkAssetOptInOutResult[] = [] - - const params = await this._clientManager.algod.getTransactionParams().do() - const sender = typeof account === 'string' ? account : account.addr - - for (const assetGroup of chunkArray(assetIds, MAX_TRANSACTION_GROUP_SIZE)) { - const composer = this._getComposer(() => Promise.resolve(params)) - - const notOptedInAssetIds: bigint[] = [] - const nonZeroBalanceAssetIds: bigint[] = [] - for (const assetId of assetGroup) { - if (options?.ensureZeroBalance !== false) { - try { - const accountAssetInfo = await this.getAssetInformation(sender, assetId) - if (accountAssetInfo.balance !== 0n) { - nonZeroBalanceAssetIds.push(BigInt(assetId)) - } - } catch (e) { - notOptedInAssetIds.push(BigInt(assetId)) - } - } - } - - if (notOptedInAssetIds.length > 0 || nonZeroBalanceAssetIds.length > 0) { - throw new Error( - `Account ${sender}${notOptedInAssetIds.length > 0 ? ` is not opted-in to Asset${notOptedInAssetIds.length > 1 ? 's' : ''} ${notOptedInAssetIds.join(', ')}` : ''}${ - nonZeroBalanceAssetIds.length > 0 - ? ` has non-zero balance for Asset${nonZeroBalanceAssetIds.length > 1 ? 's' : ''} ${nonZeroBalanceAssetIds.join(', ')}` - : '' - }; can't opt-out.`, - ) - } - - for (const assetId of assetGroup) { - composer.addAssetOptOut({ - ...options, - creator: (await new AssetManager(this._clientManager).getById(BigInt(assetId))).creator, - sender, - assetId: BigInt(assetId), - }) - } - - const result = await composer.execute(options) - - Config.getLogger(options?.suppressLog).info( - `Successfully opted ${account} out of assets ${assetGroup.join(', ')} with transaction IDs ${result.txIds.join(', ')}` + - `\n Grouped under ${result.groupId} in round ${result.confirmations?.[0]?.confirmedRound}.`, - ) - - assetGroup.forEach((assetId, index) => { - results.push({ assetId: BigInt(assetId), transactionId: result.txIds[index] }) - }) - } - - return results - } - /** * Rekey an account to a new address. * diff --git a/src/types/algorand-client.asset.spec.ts b/src/types/algorand-client.asset.spec.ts index 52c25eb6..5bb777c1 100644 --- a/src/types/algorand-client.asset.spec.ts +++ b/src/types/algorand-client.asset.spec.ts @@ -50,7 +50,7 @@ describe('Asset capability', () => { const secondAccountInfo = await algorand.account.getInformation(secondAccount.addr) expect(secondAccountInfo.totalAssetsOptedIn).toBe(0) - await algorand.account.assetBulkOptIn(secondAccount, dummyAssetIds, { validityWindow: 100 }) + await algorand.asset.bulkOptIn(secondAccount, dummyAssetIds, { validityWindow: 100 }) const testAccountInfoAfterOptIn = await algorand.account.getInformation(secondAccount.addr) expect(testAccountInfoAfterOptIn.totalAssetsOptedIn).toBe(1) @@ -64,7 +64,7 @@ describe('Asset capability', () => { const dummyAssetId = await generateTestAsset(algorand, testAccount.addr, 0) dummyAssetIds.push(dummyAssetId) } - await algorand.account.assetBulkOptIn(secondAccount, dummyAssetIds, { validityWindow: 100 }) + await algorand.asset.bulkOptIn(secondAccount, dummyAssetIds, { validityWindow: 100 }) const secondAccountInfo = await algorand.account.getInformation(secondAccount.addr) expect(secondAccountInfo.totalAssetsOptedIn).toBe(20) }, 10e6) @@ -76,12 +76,12 @@ describe('Asset capability', () => { const dummyAssetIds = [dummyAssetId, dummyAssetId2] const secondAccount = await generateAccount({ initialFunds: (1).algos() }) - await algorand.account.assetBulkOptIn(secondAccount, dummyAssetIds, { validityWindow: 100 }) + await algorand.asset.bulkOptIn(secondAccount, dummyAssetIds, { validityWindow: 100 }) const secondAccountInfo = await algorand.account.getInformation(secondAccount.addr) expect(secondAccountInfo.totalAssetsOptedIn).toBe(2) - await algorand.account.assetBulkOptOut(secondAccount, dummyAssetIds, { validityWindow: 100 }) + await algorand.asset.bulkOptOut(secondAccount, dummyAssetIds, { validityWindow: 100 }) const secondAccountInfoAfterOptOut = await algorand.account.getInformation(secondAccount.addr) expect(secondAccountInfoAfterOptOut.totalAssetsOptedIn).toBe(0) @@ -93,12 +93,12 @@ describe('Asset capability', () => { const dummyAssetIds = [dummyAssetId, 1234567n, -132n] const secondAccount = await generateAccount({ initialFunds: (1).algos() }) - await algorand.account.assetBulkOptIn(secondAccount, [dummyAssetId], { validityWindow: 100 }) + await algorand.asset.bulkOptIn(secondAccount, [dummyAssetId], { validityWindow: 100 }) const secondAccountInfo = await algorand.account.getInformation(secondAccount.addr) expect(secondAccountInfo.totalAssetsOptedIn).toBe(1) - await expect(algorand.account.assetBulkOptOut(secondAccount, dummyAssetIds, { validityWindow: 100 })).rejects.toThrow( + await expect(algorand.asset.bulkOptOut(secondAccount, dummyAssetIds, { validityWindow: 100 })).rejects.toThrow( `Account ${secondAccount.addr} is not opted-in to Assets 1234567, -132; can't opt-out.`, ) @@ -113,7 +113,7 @@ describe('Asset capability', () => { const dummyAssetIds = [dummyAssetId, dummyAssetId2] const secondAccount = await generateAccount({ initialFunds: (1).algos() }) - await algorand.account.assetBulkOptIn(secondAccount, dummyAssetIds, { validityWindow: 100 }) + await algorand.asset.bulkOptIn(secondAccount, dummyAssetIds, { validityWindow: 100 }) const secondAccountInfo = await algorand.account.getInformation(secondAccount.addr) expect(secondAccountInfo.totalAssetsOptedIn).toBe(2) @@ -126,7 +126,7 @@ describe('Asset capability', () => { note: `Transfer 5 assets with id ${dummyAssetId}`, }) - await expect(algorand.account.assetBulkOptOut(secondAccount, dummyAssetIds, { validityWindow: 100 })).rejects.toThrow( + await expect(algorand.asset.bulkOptOut(secondAccount, dummyAssetIds, { validityWindow: 100 })).rejects.toThrow( `Account ${secondAccount.addr} has non-zero balance for Asset ${dummyAssetId}; can't opt-out.`, ) @@ -186,11 +186,11 @@ describe('Asset capability', () => { const dummyAssetId = await generateTestAsset(algorand, testAccount.addr, 0) dummyAssetIds.push(dummyAssetId) } - await algorand.account.assetBulkOptIn(secondAccount, dummyAssetIds, { validityWindow: 100 }) + await algorand.asset.bulkOptIn(secondAccount, dummyAssetIds, { validityWindow: 100 }) const secondAccountInfo = await algorand.account.getInformation(secondAccount.addr) expect(secondAccountInfo.totalAssetsOptedIn).toBe(20) - await algorand.account.assetBulkOptOut(secondAccount, dummyAssetIds, { validityWindow: 100 }) + await algorand.asset.bulkOptOut(secondAccount, dummyAssetIds, { validityWindow: 100 }) const secondAccountInfoAfterOptOut = await algorand.account.getInformation(secondAccount.addr) expect(secondAccountInfoAfterOptOut.totalAssetsOptedIn).toBe(0) diff --git a/src/types/algorand-client.transfer.spec.ts b/src/types/algorand-client.transfer.spec.ts index 1bf428c4..00797f13 100644 --- a/src/types/algorand-client.transfer.spec.ts +++ b/src/types/algorand-client.transfer.spec.ts @@ -209,10 +209,10 @@ describe('Transfer capability', () => { note: `Transfer 5 assets with id ${dummyAssetId}`, }) - const secondAccountInfo = await algorand.account.getAssetInformation(secondAccount.addr, dummyAssetId) + const secondAccountInfo = await algorand.asset.getAccountInformation(secondAccount.addr, dummyAssetId) expect(secondAccountInfo.balance).toBe(5n) - const testAccountInfo = await algorand.account.getAssetInformation(testAccount.addr, dummyAssetId) + const testAccountInfo = await algorand.asset.getAccountInformation(testAccount.addr, dummyAssetId) expect(testAccountInfo.balance).toBe(95n) }, 10e6) @@ -234,7 +234,7 @@ describe('Transfer capability', () => { note: `Transfer 5 assets with id ${dummyAssetId}`, }) - const clawbackFromInfo = await algorand.account.getAssetInformation(clawbackAccount.addr, dummyAssetId) + const clawbackFromInfo = await algorand.asset.getAccountInformation(clawbackAccount.addr, dummyAssetId) expect(clawbackFromInfo.balance).toBe(5n) await algorand.send.assetTransfer({ @@ -246,13 +246,13 @@ describe('Transfer capability', () => { clawbackTarget: clawbackAccount.addr, }) - const secondAccountInfo = await algorand.account.getAssetInformation(secondAccount.addr, dummyAssetId) + const secondAccountInfo = await algorand.asset.getAccountInformation(secondAccount.addr, dummyAssetId) expect(secondAccountInfo.balance).toBe(5n) - const clawbackAccountInfo = await algorand.account.getAssetInformation(clawbackAccount.addr, dummyAssetId) + const clawbackAccountInfo = await algorand.asset.getAccountInformation(clawbackAccount.addr, dummyAssetId) expect(clawbackAccountInfo.balance).toBe(0n) - const testAccountInfo = await algorand.account.getAssetInformation(testAccount.addr, dummyAssetId) + const testAccountInfo = await algorand.asset.getAccountInformation(testAccount.addr, dummyAssetId) expect(testAccountInfo.balance).toBe(95n) }, 10e6) diff --git a/src/types/algorand-client.ts b/src/types/algorand-client.ts index 4c6dc107..627d3687 100644 --- a/src/types/algorand-client.ts +++ b/src/types/algorand-client.ts @@ -31,7 +31,7 @@ export class AlgorandClient { private constructor(config: AlgoConfig | AlgoSdkClients) { this._clientManager = new ClientManager(config) this._accountManager = new AccountManager(this._clientManager) - this._assetManager = new AssetManager(this._clientManager) + this._assetManager = new AssetManager(this._clientManager, this._accountManager) } /** @@ -232,7 +232,7 @@ export class AlgorandClient { */ payment: this._send((c) => c.addPayment, { preLog: (params, transaction) => - `Sending ${params.amount.microAlgos} µAlgo from ${params.sender} to ${params.receiver} via transaction ${transaction.txID()}`, + `Sending ${params.amount.microAlgos} µALGO from ${params.sender} to ${params.receiver} via transaction ${transaction.txID()}`, }), /** * Create a new Algorand Standard Asset. @@ -554,7 +554,7 @@ export class AlgorandClient { if (params.ensureZeroBalance) { let balance = 0n try { - const accountAssetInfo = await this.account.getAssetInformation(params.sender, params.assetId) + const accountAssetInfo = await this.asset.getAccountInformation(params.sender, params.assetId) balance = accountAssetInfo.balance } catch (e) { throw new Error(`Account ${params.sender} is not opted-in to Asset ${params.assetId}; can't opt-out.`) diff --git a/src/types/asset-manager.ts b/src/types/asset-manager.ts index 89d62c15..8b2b15e1 100644 --- a/src/types/asset-manager.ts +++ b/src/types/asset-manager.ts @@ -1,7 +1,21 @@ import algosdk from 'algosdk' +import { Config } from '../config' +import { chunkArray } from '../util' +import { AccountAssetInformation, TransactionSignerAccount } from './account' +import { AccountManager } from './account-manager' import { ClientManager } from './client-manager' +import AlgokitComposer, { CommonTransactionParams, ExecuteParams, MAX_TRANSACTION_GROUP_SIZE } from './composer' import AssetModel = algosdk.modelsv2.Asset +/** Individual result from performing a bulk opt-in or bulk opt-out for an account against a series of assets. */ +export interface BulkAssetOptInOutResult { + /** The ID of the asset opted into / out of */ + assetId: bigint + /** The transaction ID of the resulting opt in / out */ + transactionId: string +} + +/** Information about an asset. */ export interface AssetInformation { /** The ID of the asset. */ assetId: bigint @@ -125,6 +139,7 @@ export interface AssetInformation { /** Allows management of asset information. */ export class AssetManager { private _clientManager: ClientManager + private _accountManager: AccountManager /** * Create a new asset manager. @@ -134,8 +149,17 @@ export class AssetManager { * const assetManager = new AssetManager(clientManager) * ``` */ - constructor(clientManager: ClientManager) { + constructor(clientManager: ClientManager, accountManager: AccountManager) { this._clientManager = clientManager + this._accountManager = accountManager + } + + private _getComposer(getSuggestedParams?: () => Promise) { + return new AlgokitComposer({ + algod: this._clientManager.algod, + getSigner: this._accountManager.getSigner.bind(this._accountManager), + getSuggestedParams: getSuggestedParams ?? (() => this._clientManager.algod.getTransactionParams().do()), + }) } /** @@ -171,4 +195,174 @@ export class AssetManager { metadataHash: asset.params.metadataHash, } } + + /** + * Returns the given sender account's asset holding for a given asset. + * + * @example + * ```typescript + * const address = "XBYLS2E6YI6XXL5BWCAMOA4GTWHXWENZMX5UHXMRNWWUQ7BXCY5WC5TEPA"; + * const assetId = 123345n; + * const accountInfo = await algorand.asset.getAccountInformation(address, assetId); + * ``` + * + * [Response data schema details](https://developer.algorand.org/docs/rest-apis/algod/#get-v2accountsaddressassetsasset-id) + * @param sender The address of the sender/account to look up + * @param assetId The ID of the asset to return a holding for + * @returns The account asset holding information + */ + public async getAccountInformation(sender: string | TransactionSignerAccount, assetId: bigint): Promise { + const info = await this._clientManager.algod + .accountAssetInformation(typeof sender === 'string' ? sender : sender.addr, Number(assetId)) + .do() + + return { + assetId: BigInt(assetId), + balance: BigInt(info['asset-holding']['amount']), + frozen: info['asset-holding']['is-frozen'] === true, + round: BigInt(info['round']), + } + } + + /** + * Opt an account in to a list of Algorand Standard Assets. + * + * Transactions will be sent in batches of 16 as transaction groups. + * + * @param account The account to opt-in + * @param assetIds The list of asset IDs to opt-in to + * @param options Any parameters to control the transaction or execution of the transaction + * @example Example using AlgorandClient + * ```typescript + * // Basic example + * algorand.asset.bulkOptIn("ACCOUNTADDRESS", [12345n, 67890n]) + * // With configuration + * algorand.asset.bulkOptIn("ACCOUNTADDRESS", [12345n, 67890n], { maxFee: (1000).microAlgos(), suppressLog: true }) + * ``` + * @returns An array of records matching asset ID to transaction ID of the opt in + */ + async bulkOptIn( + account: string | TransactionSignerAccount, + assetIds: bigint[], + options?: Omit & ExecuteParams, + ): Promise { + const results: BulkAssetOptInOutResult[] = [] + + const params = await this._clientManager.algod.getTransactionParams().do() + + for (const assetGroup of chunkArray(assetIds, MAX_TRANSACTION_GROUP_SIZE)) { + const composer = this._getComposer(() => Promise.resolve(params)) + + for (const assetId of assetGroup) { + composer.addAssetOptIn({ + ...options, + sender: typeof account === 'string' ? account : account.addr, + assetId: BigInt(assetId), + }) + } + + const result = await composer.execute(options) + + Config.getLogger(options?.suppressLog).info( + `Successfully opted in ${account} for assets ${assetGroup.join(', ')} with transaction IDs ${result.txIds.join(', ')}` + + `\n Grouped under ${result.groupId} in round ${result.confirmations?.[0]?.confirmedRound}.`, + ) + + assetGroup.forEach((assetId, index) => { + results.push({ assetId: BigInt(assetId), transactionId: result.txIds[index] }) + }) + } + + return results + } + + /** + * Opt an account out of a list of Algorand Standard Assets. + * + * Transactions will be sent in batches of 16 as transaction groups. + * + * @param account The account to opt-in + * @param assetIds The list of asset IDs to opt-out of + * @param options Any parameters to control the transaction or execution of the transaction + * @example Example using AlgorandClient + * ```typescript + * // Basic example + * algorand.asset.bulkOptOut("ACCOUNTADDRESS", [12345n, 67890n]) + * // With configuration + * algorand.asset.bulkOptOut("ACCOUNTADDRESS", [12345n, 67890n], { ensureZeroBalance: true, maxFee: (1000).microAlgos(), suppressLog: true }) + * ``` + * @returns An array of records matching asset ID to transaction ID of the opt in + */ + async bulkOptOut( + account: string | TransactionSignerAccount, + assetIds: bigint[], + options?: Omit & + ExecuteParams & { + /** Whether or not to check if the account has a zero balance for each asset first or not. + * + * Defaults to `true`. + * + * If this is set to `true` and the account has an asset balance it will throw an error. + * + * If this is set to `false` and the account has an asset balance it will lose those assets to the asset creator. + */ + ensureZeroBalance?: boolean + }, + ): Promise { + const results: BulkAssetOptInOutResult[] = [] + + const params = await this._clientManager.algod.getTransactionParams().do() + const sender = typeof account === 'string' ? account : account.addr + + for (const assetGroup of chunkArray(assetIds, MAX_TRANSACTION_GROUP_SIZE)) { + const composer = this._getComposer(() => Promise.resolve(params)) + + const notOptedInAssetIds: bigint[] = [] + const nonZeroBalanceAssetIds: bigint[] = [] + for (const assetId of assetGroup) { + if (options?.ensureZeroBalance !== false) { + try { + const accountAssetInfo = await this.getAccountInformation(sender, assetId) + if (accountAssetInfo.balance !== 0n) { + nonZeroBalanceAssetIds.push(BigInt(assetId)) + } + } catch (e) { + notOptedInAssetIds.push(BigInt(assetId)) + } + } + } + + if (notOptedInAssetIds.length > 0 || nonZeroBalanceAssetIds.length > 0) { + throw new Error( + `Account ${sender}${notOptedInAssetIds.length > 0 ? ` is not opted-in to Asset${notOptedInAssetIds.length > 1 ? 's' : ''} ${notOptedInAssetIds.join(', ')}` : ''}${ + nonZeroBalanceAssetIds.length > 0 + ? ` has non-zero balance for Asset${nonZeroBalanceAssetIds.length > 1 ? 's' : ''} ${nonZeroBalanceAssetIds.join(', ')}` + : '' + }; can't opt-out.`, + ) + } + + for (const assetId of assetGroup) { + composer.addAssetOptOut({ + ...options, + creator: (await this.getById(BigInt(assetId))).creator, + sender, + assetId: BigInt(assetId), + }) + } + + const result = await composer.execute(options) + + Config.getLogger(options?.suppressLog).info( + `Successfully opted ${account} out of assets ${assetGroup.join(', ')} with transaction IDs ${result.txIds.join(', ')}` + + `\n Grouped under ${result.groupId} in round ${result.confirmations?.[0]?.confirmedRound}.`, + ) + + assetGroup.forEach((assetId, index) => { + results.push({ assetId: BigInt(assetId), transactionId: result.txIds[index] }) + }) + } + + return results + } } From acde1a27b07890e6918f2935f92a0e3a159faa4e Mon Sep 17 00:00:00 2001 From: Neil Campbell Date: Wed, 21 Aug 2024 23:43:52 +0800 Subject: [PATCH 08/18] fix: remove AlgorandClient memoize in AlgorandFixture --- src/testing/fixtures/algorand-fixture.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/testing/fixtures/algorand-fixture.ts b/src/testing/fixtures/algorand-fixture.ts index 097549db..044f52e6 100644 --- a/src/testing/fixtures/algorand-fixture.ts +++ b/src/testing/fixtures/algorand-fixture.ts @@ -90,7 +90,7 @@ export function algorandFixture(fixtureConfig?: AlgorandFixtureConfig, config?: Config.configure({ debug: true }) const transactionLogger = new TransactionLogger() const transactionLoggerAlgod = transactionLogger.capture(algod) - algorandClient = algorandClient ?? AlgorandClient.fromClients({ algod: transactionLoggerAlgod, indexer, kmd }) + algorandClient = AlgorandClient.fromClients({ algod: transactionLoggerAlgod, indexer, kmd }) const acc = await getTestAccount({ initialFunds: fixtureConfig?.testAccountFunding ?? algos(10), suppressLog: true }, algorandClient) algorandClient.setSignerFromAccount(acc).setSuggestedParamsTimeout(0) // If running against LocalNet we are likely in dev mode and we need to set a much higher validity window From 8b21fd7809558580f81025a087a750b408c0c52a Mon Sep 17 00:00:00 2001 From: "Rob Moore (MakerX)" Date: Wed, 28 Aug 2024 00:28:07 +0800 Subject: [PATCH 09/18] Removed the circular dependency in App Client --- src/transaction/legacy-bridge.ts | 44 ++++++++++++++++++++++++++++++-- src/types/app-client.ts | 21 +++++++-------- src/types/composer.ts | 13 +++------- 3 files changed, 57 insertions(+), 21 deletions(-) diff --git a/src/transaction/legacy-bridge.ts b/src/transaction/legacy-bridge.ts index aa9b9451..6a240bdf 100644 --- a/src/transaction/legacy-bridge.ts +++ b/src/transaction/legacy-bridge.ts @@ -1,8 +1,8 @@ import algosdk from 'algosdk' import { AlgorandClient, SendSingleTransactionResult } from '../types/algorand-client' -import { CommonTransactionParams, ExecuteParams } from '../types/composer' +import AlgokitComposer, { CommonTransactionParams, ExecuteParams } from '../types/composer' import { SendTransactionFrom, SendTransactionParams, SendTransactionResult } from '../types/transaction' -import { getSenderTransactionSigner } from './transaction' +import { getSenderTransactionSigner, getTransactionParams } from './transaction' import Algodv2 = algosdk.Algodv2 import Transaction = algosdk.Transaction @@ -34,3 +34,43 @@ export async function legacySendTransactionBridge( + algod: Algodv2, + from: SendTransactionFrom, + params: T, + compose: (c: AlgokitComposer) => (params: T) => AlgokitComposer, + sendParams?: SendTransactionParams, + suggestedParams?: algosdk.SuggestedParams, +): Promise { + const composer = new AlgokitComposer({ + algod, + getSigner: (address) => getSenderTransactionSigner(from), + getSuggestedParams: async () => await getTransactionParams(suggestedParams, algod), + }) + sendParams = sendParams ?? {} + + if (sendParams.fee) { + params.staticFee = sendParams.fee + } + if (sendParams.maxFee) { + params.maxFee = sendParams.maxFee + } + + if (sendParams.atc || sendParams.skipSending) { + await compose(composer)(params) + const transactions = await composer.build() + if (sendParams.atc) { + transactions.transactions.forEach((txn) => sendParams!.atc!.addTransaction(txn)) + } + return { transaction: transactions.transactions[transactions.transactions.length - 1].txn } + } + + const result = await compose(composer)(params).execute(sendParams) + return { + ...result, + transaction: result.transactions[result.transactions.length - 1], + confirmation: result.confirmations[result.confirmations.length - 1], + } +} diff --git a/src/types/app-client.ts b/src/types/app-client.ts index 772a05ca..84c0e24a 100644 --- a/src/types/app-client.ts +++ b/src/types/app-client.ts @@ -15,8 +15,8 @@ import { import { deployApp, getCreatorAppsByName, performTemplateSubstitution, replaceDeployTimeControlParams } from '../app-deploy' import { Config } from '../config' import { persistSourceMaps } from '../debugging/debugging' -import { getSenderAddress } from '../transaction/transaction' -import { transferAlgos } from '../transfer/transfer-algos' +import { legacySendTransactionBridgeComposer } from '../transaction/legacy-bridge' +import { encodeTransactionNote, getSenderAddress } from '../transaction/transaction' import { AlgoAmount } from './amount' import { ABIAppCallArg, @@ -736,17 +736,18 @@ export class ApplicationClient { } const ref = await this.getAppReference() - return await transferAlgos( + return legacySendTransactionBridgeComposer( + this.algod, + sender ?? this.sender!, { - to: ref.appAddress, + receiver: ref.appAddress, + sender: getSenderAddress(sender ?? this.sender!), amount: amount, - // eslint-disable-next-line @typescript-eslint/no-non-null-assertion - from: sender ?? this.sender!, - note: note, - transactionParams: this.params, - ...(sendParams ?? {}), + note: encodeTransactionNote(note), }, - this.algod, + (c) => c.addPayment, + sendParams, + this.params, ) } diff --git a/src/types/composer.ts b/src/types/composer.ts index 32c40717..c247759b 100644 --- a/src/types/composer.ts +++ b/src/types/composer.ts @@ -385,7 +385,7 @@ export interface ExecuteParams { } /** Parameters to create an `AlgokitComposer`. */ -export type AlgokitComposerParams = { +export type AlgoKitComposerParams = { /** The algod client to use to get suggestedParams and send the transaction group */ algod: algosdk.Algodv2 /** The function used to get the TransactionSigner for a given address */ @@ -398,12 +398,7 @@ export type AlgokitComposerParams = { defaultValidityWindow?: number } -/** AlgoKit Composer helps you compose and execute transactions as a transaction group. - * - * Note: this class is a new Beta feature and may be subject to change. - * - * @beta - */ +/** AlgoKit Composer helps you compose and execute transactions as a transaction group. */ export default class AlgokitComposer { /** The ATC used to compose the group */ private atc = new algosdk.AtomicTransactionComposer() @@ -417,7 +412,7 @@ export default class AlgokitComposer { /** The algod client used by the composer. */ private algod: algosdk.Algodv2 - /** An async function that will return suggestedParams. */ + /** An async function that will return suggested params for the transaction. */ private getSuggestedParams: () => Promise /** A function that takes in an address and return a signer function for that address. */ @@ -433,7 +428,7 @@ export default class AlgokitComposer { * Create an `AlgoKitComposer`. * @param params The configuration for this composer */ - constructor(params: AlgokitComposerParams) { + constructor(params: AlgoKitComposerParams) { this.algod = params.algod const defaultGetSuggestedParams = () => params.algod.getTransactionParams().do() this.getSuggestedParams = params.getSuggestedParams ?? defaultGetSuggestedParams From 003934e2aa02715cefb1db2c6389c7bd2cebc802 Mon Sep 17 00:00:00 2001 From: "Rob Moore (MakerX)" Date: Wed, 28 Aug 2024 00:30:32 +0800 Subject: [PATCH 10/18] Renamed AlgokitComposer to AlgoKitComposer --- src/transaction/legacy-bridge.ts | 6 +++--- src/types/account-manager.ts | 4 ++-- src/types/algorand-client.ts | 8 ++++---- src/types/asset-manager.ts | 4 ++-- src/types/composer.ts | 24 ++++++++++++------------ src/types/kmd-account-manager.ts | 4 ++-- 6 files changed, 25 insertions(+), 25 deletions(-) diff --git a/src/transaction/legacy-bridge.ts b/src/transaction/legacy-bridge.ts index 6a240bdf..2c4332cd 100644 --- a/src/transaction/legacy-bridge.ts +++ b/src/transaction/legacy-bridge.ts @@ -1,6 +1,6 @@ import algosdk from 'algosdk' import { AlgorandClient, SendSingleTransactionResult } from '../types/algorand-client' -import AlgokitComposer, { CommonTransactionParams, ExecuteParams } from '../types/composer' +import AlgoKitComposer, { CommonTransactionParams, ExecuteParams } from '../types/composer' import { SendTransactionFrom, SendTransactionParams, SendTransactionResult } from '../types/transaction' import { getSenderTransactionSigner, getTransactionParams } from './transaction' import Algodv2 = algosdk.Algodv2 @@ -40,11 +40,11 @@ export async function legacySendTransactionBridgeComposer (params: T) => AlgokitComposer, + compose: (c: AlgoKitComposer) => (params: T) => AlgoKitComposer, sendParams?: SendTransactionParams, suggestedParams?: algosdk.SuggestedParams, ): Promise { - const composer = new AlgokitComposer({ + const composer = new AlgoKitComposer({ algod, getSigner: (address) => getSenderTransactionSigner(from), getSuggestedParams: async () => await getTransactionParams(suggestedParams, algod), diff --git a/src/types/account-manager.ts b/src/types/account-manager.ts index e9bc73a1..ef502d81 100644 --- a/src/types/account-manager.ts +++ b/src/types/account-manager.ts @@ -5,7 +5,7 @@ import { AccountInformation, DISPENSER_ACCOUNT, MultisigAccount, SigningAccount, import { SendSingleTransactionResult } from './algorand-client' import { AlgoAmount } from './amount' import { ClientManager } from './client-manager' -import AlgokitComposer, { CommonTransactionParams, ExecuteParams } from './composer' +import AlgoKitComposer, { CommonTransactionParams, ExecuteParams } from './composer' import { TestNetDispenserApiClient } from './dispenser-client' import { KmdAccountManager } from './kmd-account-manager' import LogicSigAccount = algosdk.LogicSigAccount @@ -58,7 +58,7 @@ export class AccountManager { } private _getComposer(getSuggestedParams?: () => Promise) { - return new AlgokitComposer({ + return new AlgoKitComposer({ algod: this._clientManager.algod, getSigner: this.getSigner.bind(this), getSuggestedParams: getSuggestedParams ?? (() => this._clientManager.algod.getTransactionParams().do()), diff --git a/src/types/algorand-client.ts b/src/types/algorand-client.ts index 627d3687..bc707b4b 100644 --- a/src/types/algorand-client.ts +++ b/src/types/algorand-client.ts @@ -4,7 +4,7 @@ import { MultisigAccount, SigningAccount, TransactionSignerAccount } from './acc import { AccountManager } from './account-manager' import { AssetManager } from './asset-manager' import { AlgoSdkClients, ClientManager } from './client-manager' -import AlgokitComposer, { AssetCreateParams, AssetOptOutParams, ExecuteParams, MethodCallParams } from './composer' +import AlgoKitComposer, { AssetCreateParams, AssetOptOutParams, ExecuteParams, MethodCallParams } from './composer' import { AlgoConfig } from './network-client' import { ConfirmedTransactionResult, SendAtomicTransactionComposerResults } from './transaction' import Transaction = algosdk.Transaction @@ -142,7 +142,7 @@ export class AlgorandClient { /** Start a new `AlgokitComposer` transaction group */ public newGroup() { - return new AlgokitComposer({ + return new AlgoKitComposer({ algod: this.client.algod, getSigner: (addr: string) => this.account.getSigner(addr), getSuggestedParams: () => this.getSuggestedParams(), @@ -151,7 +151,7 @@ export class AlgorandClient { } private _send( - c: (c: AlgokitComposer) => (params: T) => AlgokitComposer, + c: (c: AlgoKitComposer) => (params: T) => AlgoKitComposer, log?: { preLog?: (params: T, transaction: Transaction) => string postLog?: (params: T, result: SendSingleTransactionResult) => string @@ -589,7 +589,7 @@ export class AlgorandClient { }), } - private _transaction(c: (c: AlgokitComposer) => (params: T) => AlgokitComposer): (params: T) => Promise { + private _transaction(c: (c: AlgoKitComposer) => (params: T) => AlgoKitComposer): (params: T) => Promise { return async (params: T) => { const composer = this.newGroup() const result = await c(composer).apply(composer, [params]).build() diff --git a/src/types/asset-manager.ts b/src/types/asset-manager.ts index 8b2b15e1..a41825ad 100644 --- a/src/types/asset-manager.ts +++ b/src/types/asset-manager.ts @@ -4,7 +4,7 @@ import { chunkArray } from '../util' import { AccountAssetInformation, TransactionSignerAccount } from './account' import { AccountManager } from './account-manager' import { ClientManager } from './client-manager' -import AlgokitComposer, { CommonTransactionParams, ExecuteParams, MAX_TRANSACTION_GROUP_SIZE } from './composer' +import AlgoKitComposer, { CommonTransactionParams, ExecuteParams, MAX_TRANSACTION_GROUP_SIZE } from './composer' import AssetModel = algosdk.modelsv2.Asset /** Individual result from performing a bulk opt-in or bulk opt-out for an account against a series of assets. */ @@ -155,7 +155,7 @@ export class AssetManager { } private _getComposer(getSuggestedParams?: () => Promise) { - return new AlgokitComposer({ + return new AlgoKitComposer({ algod: this._clientManager.algod, getSigner: this._accountManager.getSigner.bind(this._accountManager), getSuggestedParams: getSuggestedParams ?? (() => this._clientManager.algod.getTransactionParams().do()), diff --git a/src/types/composer.ts b/src/types/composer.ts index c247759b..c24e1eba 100644 --- a/src/types/composer.ts +++ b/src/types/composer.ts @@ -399,7 +399,7 @@ export type AlgoKitComposerParams = { } /** AlgoKit Composer helps you compose and execute transactions as a transaction group. */ -export default class AlgokitComposer { +export default class AlgoKitComposer { /** The ATC used to compose the group */ private atc = new algosdk.AtomicTransactionComposer() @@ -442,7 +442,7 @@ export default class AlgokitComposer { * @param params The payment transaction parameters * @returns The composer so you can chain method calls */ - addPayment(params: PaymentParams): AlgokitComposer { + addPayment(params: PaymentParams): AlgoKitComposer { this.txns.push({ ...params, type: 'pay' }) return this @@ -453,7 +453,7 @@ export default class AlgokitComposer { * @param params The asset create transaction parameters * @returns The composer so you can chain method calls */ - addAssetCreate(params: AssetCreateParams): AlgokitComposer { + addAssetCreate(params: AssetCreateParams): AlgoKitComposer { this.txns.push({ ...params, type: 'assetCreate' }) return this @@ -464,7 +464,7 @@ export default class AlgokitComposer { * @param params The asset config transaction parameters * @returns The composer so you can chain method calls */ - addAssetConfig(params: AssetConfigParams): AlgokitComposer { + addAssetConfig(params: AssetConfigParams): AlgoKitComposer { this.txns.push({ ...params, type: 'assetConfig' }) return this @@ -475,7 +475,7 @@ export default class AlgokitComposer { * @param params The asset freeze transaction parameters * @returns The composer so you can chain method calls */ - addAssetFreeze(params: AssetFreezeParams): AlgokitComposer { + addAssetFreeze(params: AssetFreezeParams): AlgoKitComposer { this.txns.push({ ...params, type: 'assetFreeze' }) return this @@ -486,7 +486,7 @@ export default class AlgokitComposer { * @param params The asset destroy transaction parameters * @returns The composer so you can chain method calls */ - addAssetDestroy(params: AssetDestroyParams): AlgokitComposer { + addAssetDestroy(params: AssetDestroyParams): AlgoKitComposer { this.txns.push({ ...params, type: 'assetDestroy' }) return this @@ -497,7 +497,7 @@ export default class AlgokitComposer { * @param params The asset transfer transaction parameters * @returns The composer so you can chain method calls */ - addAssetTransfer(params: AssetTransferParams): AlgokitComposer { + addAssetTransfer(params: AssetTransferParams): AlgoKitComposer { this.txns.push({ ...params, type: 'assetTransfer' }) return this @@ -508,7 +508,7 @@ export default class AlgokitComposer { * @param params The asset opt-in transaction parameters * @returns The composer so you can chain method calls */ - addAssetOptIn(params: AssetOptInParams): AlgokitComposer { + addAssetOptIn(params: AssetOptInParams): AlgoKitComposer { this.txns.push({ ...params, type: 'assetOptIn' }) return this @@ -519,7 +519,7 @@ export default class AlgokitComposer { * @param params The asset opt-out transaction parameters * @returns The composer so you can chain method calls */ - addAssetOptOut(params: AssetOptOutParams): AlgokitComposer { + addAssetOptOut(params: AssetOptOutParams): AlgoKitComposer { this.txns.push({ ...params, type: 'assetOptOut' }) return this @@ -532,7 +532,7 @@ export default class AlgokitComposer { * @param params The application call transaction parameters * @returns The composer so you can chain method calls */ - addAppCall(params: AppCallParams): AlgokitComposer { + addAppCall(params: AppCallParams): AlgoKitComposer { this.txns.push({ ...params, type: 'appCall' }) return this @@ -555,7 +555,7 @@ export default class AlgokitComposer { * @param params The online key registration transaction parameters * @returns The composer so you can chain method calls */ - addOnlineKeyRegistration(params: OnlineKeyRegistrationParams): AlgokitComposer { + addOnlineKeyRegistration(params: OnlineKeyRegistrationParams): AlgoKitComposer { this.txns.push({ ...params, type: 'keyReg' }) return this @@ -566,7 +566,7 @@ export default class AlgokitComposer { * @param atc The `AtomicTransactionComposer` to build transactions from and add to the group * @returns The composer so you can chain method calls */ - addAtc(atc: algosdk.AtomicTransactionComposer): AlgokitComposer { + addAtc(atc: algosdk.AtomicTransactionComposer): AlgoKitComposer { this.txns.push({ atc, type: 'atc' }) return this } diff --git a/src/types/kmd-account-manager.ts b/src/types/kmd-account-manager.ts index bb8f6875..7cc876d3 100644 --- a/src/types/kmd-account-manager.ts +++ b/src/types/kmd-account-manager.ts @@ -3,7 +3,7 @@ import { Config } from '../config' import { SigningAccount, TransactionSignerAccount } from './account' import { AlgoAmount } from './amount' import { ClientManager } from './client-manager' -import AlgokitComposer from './composer' +import AlgoKitComposer from './composer' /** Provides abstractions over a [KMD](https://github.com/algorand/go-algorand/blob/master/daemon/kmd/README.md) instance * that makes it easier to get and manage accounts using KMD. */ @@ -161,7 +161,7 @@ export class KmdAccountManager { // Fund the account from the dispenser const dispenser = await this.getLocalNetDispenserAccount() - await new AlgokitComposer({ + await new AlgoKitComposer({ algod: this._clientManager.algod, getSigner: () => dispenser.signer, getSuggestedParams: () => this._clientManager.algod.getTransactionParams().do(), From dfdd6766b50e8bad80ddbfab750174836f402004 Mon Sep 17 00:00:00 2001 From: "Rob Moore (MakerX)" Date: Wed, 28 Aug 2024 00:40:02 +0800 Subject: [PATCH 11/18] Fixing broken test --- .../types_app_client.ApplicationClient.md | 24 +++--- docs/code/classes/types_composer.default.md | 78 +++++++++---------- docs/code/modules/types_composer.md | 6 +- src/transaction/legacy-bridge.ts | 4 +- 4 files changed, 55 insertions(+), 57 deletions(-) diff --git a/docs/code/classes/types_app_client.ApplicationClient.md b/docs/code/classes/types_app_client.ApplicationClient.md index aefc27e9..633c88b9 100644 --- a/docs/code/classes/types_app_client.ApplicationClient.md +++ b/docs/code/classes/types_app_client.ApplicationClient.md @@ -451,7 +451,7 @@ The new error, or if there was no logic error or source map then the wrapped err #### Defined in -[src/types/app-client.ts:1007](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/app-client.ts#L1007) +[src/types/app-client.ts:1008](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/app-client.ts#L1008) ___ @@ -499,7 +499,7 @@ The ABI method for the given method #### Defined in -[src/types/app-client.ts:966](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/app-client.ts#L966) +[src/types/app-client.ts:967](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/app-client.ts#L967) ___ @@ -523,7 +523,7 @@ The ABI method params for the given method #### Defined in -[src/types/app-client.ts:944](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/app-client.ts#L944) +[src/types/app-client.ts:945](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/app-client.ts#L945) ___ @@ -542,7 +542,7 @@ The app reference, or if deployed using the `deploy` method, the app metadata to #### Defined in -[src/types/app-client.ts:976](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/app-client.ts#L976) +[src/types/app-client.ts:977](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/app-client.ts#L977) ___ @@ -560,7 +560,7 @@ The names of the boxes #### Defined in -[src/types/app-client.ts:785](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/app-client.ts#L785) +[src/types/app-client.ts:786](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/app-client.ts#L786) ___ @@ -584,7 +584,7 @@ The current box value as a byte array #### Defined in -[src/types/app-client.ts:800](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/app-client.ts#L800) +[src/types/app-client.ts:801](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/app-client.ts#L801) ___ @@ -609,7 +609,7 @@ The current box value as a byte array #### Defined in -[src/types/app-client.ts:816](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/app-client.ts#L816) +[src/types/app-client.ts:817](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/app-client.ts#L817) ___ @@ -634,7 +634,7 @@ The (name, value) pair of the boxes with values as raw byte arrays #### Defined in -[src/types/app-client.ts:832](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/app-client.ts#L832) +[src/types/app-client.ts:833](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/app-client.ts#L833) ___ @@ -660,7 +660,7 @@ The (name, value) pair of the boxes with values as the ABI Value #### Defined in -[src/types/app-client.ts:854](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/app-client.ts#L854) +[src/types/app-client.ts:855](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/app-client.ts#L855) ___ @@ -685,7 +685,7 @@ The call args ready to pass into an app call #### Defined in -[src/types/app-client.ts:876](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/app-client.ts#L876) +[src/types/app-client.ts:877](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/app-client.ts#L877) ___ @@ -703,7 +703,7 @@ The global state #### Defined in -[src/types/app-client.ts:757](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/app-client.ts#L757) +[src/types/app-client.ts:758](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/app-client.ts#L758) ___ @@ -727,7 +727,7 @@ The global state #### Defined in -[src/types/app-client.ts:771](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/app-client.ts#L771) +[src/types/app-client.ts:772](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/app-client.ts#L772) ___ diff --git a/docs/code/classes/types_composer.default.md b/docs/code/classes/types_composer.default.md index 6d7620e1..4f9d22e6 100644 --- a/docs/code/classes/types_composer.default.md +++ b/docs/code/classes/types_composer.default.md @@ -6,8 +6,6 @@ AlgoKit Composer helps you compose and execute transactions as a transaction group. -Note: this class is a new Beta feature and may be subject to change. - ## Table of contents ### Constructors @@ -67,7 +65,7 @@ Create an `AlgoKitComposer`. | Name | Type | Description | | :------ | :------ | :------ | -| `params` | [`AlgokitComposerParams`](../modules/types_composer.md#algokitcomposerparams) | The configuration for this composer | +| `params` | [`AlgoKitComposerParams`](../modules/types_composer.md#algokitcomposerparams) | The configuration for this composer | #### Returns @@ -75,7 +73,7 @@ Create an `AlgoKitComposer`. #### Defined in -[src/types/composer.ts:436](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/composer.ts#L436) +[src/types/composer.ts:431](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/composer.ts#L431) ## Properties @@ -87,7 +85,7 @@ The algod client used by the composer. #### Defined in -[src/types/composer.ts:418](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/composer.ts#L418) +[src/types/composer.ts:413](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/composer.ts#L413) ___ @@ -99,7 +97,7 @@ The ATC used to compose the group #### Defined in -[src/types/composer.ts:409](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/composer.ts#L409) +[src/types/composer.ts:404](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/composer.ts#L404) ___ @@ -111,7 +109,7 @@ The default transaction validity window #### Defined in -[src/types/composer.ts:427](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/composer.ts#L427) +[src/types/composer.ts:422](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/composer.ts#L422) ___ @@ -123,7 +121,7 @@ Whether the validity window was explicitly set on construction #### Defined in -[src/types/composer.ts:430](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/composer.ts#L430) +[src/types/composer.ts:425](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/composer.ts#L425) ___ @@ -149,7 +147,7 @@ A function that takes in an address and return a signer function for that addres #### Defined in -[src/types/composer.ts:424](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/composer.ts#L424) +[src/types/composer.ts:419](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/composer.ts#L419) ___ @@ -157,7 +155,7 @@ ___ • `Private` **getSuggestedParams**: () => `Promise`\<`SuggestedParams`\> -An async function that will return suggestedParams. +An async function that will return suggested params for the transaction. #### Type declaration @@ -169,7 +167,7 @@ An async function that will return suggestedParams. #### Defined in -[src/types/composer.ts:421](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/composer.ts#L421) +[src/types/composer.ts:416](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/composer.ts#L416) ___ @@ -181,7 +179,7 @@ Map of txid to ABI method #### Defined in -[src/types/composer.ts:412](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/composer.ts#L412) +[src/types/composer.ts:407](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/composer.ts#L407) ___ @@ -193,7 +191,7 @@ Transactions that have not yet been composed #### Defined in -[src/types/composer.ts:415](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/composer.ts#L415) +[src/types/composer.ts:410](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/composer.ts#L410) ## Methods @@ -219,7 +217,7 @@ The composer so you can chain method calls #### Defined in -[src/types/composer.ts:540](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/composer.ts#L540) +[src/types/composer.ts:535](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/composer.ts#L535) ___ @@ -243,7 +241,7 @@ The composer so you can chain method calls #### Defined in -[src/types/composer.ts:472](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/composer.ts#L472) +[src/types/composer.ts:467](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/composer.ts#L467) ___ @@ -267,7 +265,7 @@ The composer so you can chain method calls #### Defined in -[src/types/composer.ts:461](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/composer.ts#L461) +[src/types/composer.ts:456](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/composer.ts#L456) ___ @@ -291,7 +289,7 @@ The composer so you can chain method calls #### Defined in -[src/types/composer.ts:494](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/composer.ts#L494) +[src/types/composer.ts:489](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/composer.ts#L489) ___ @@ -315,7 +313,7 @@ The composer so you can chain method calls #### Defined in -[src/types/composer.ts:483](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/composer.ts#L483) +[src/types/composer.ts:478](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/composer.ts#L478) ___ @@ -339,7 +337,7 @@ The composer so you can chain method calls #### Defined in -[src/types/composer.ts:516](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/composer.ts#L516) +[src/types/composer.ts:511](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/composer.ts#L511) ___ @@ -363,7 +361,7 @@ The composer so you can chain method calls #### Defined in -[src/types/composer.ts:527](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/composer.ts#L527) +[src/types/composer.ts:522](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/composer.ts#L522) ___ @@ -387,7 +385,7 @@ The composer so you can chain method calls #### Defined in -[src/types/composer.ts:505](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/composer.ts#L505) +[src/types/composer.ts:500](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/composer.ts#L500) ___ @@ -411,7 +409,7 @@ The composer so you can chain method calls #### Defined in -[src/types/composer.ts:574](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/composer.ts#L574) +[src/types/composer.ts:569](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/composer.ts#L569) ___ @@ -437,7 +435,7 @@ The composer so you can chain method calls #### Defined in -[src/types/composer.ts:553](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/composer.ts#L553) +[src/types/composer.ts:548](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/composer.ts#L548) ___ @@ -461,7 +459,7 @@ The composer so you can chain method calls #### Defined in -[src/types/composer.ts:563](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/composer.ts#L563) +[src/types/composer.ts:558](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/composer.ts#L558) ___ @@ -485,7 +483,7 @@ The composer so you can chain method calls #### Defined in -[src/types/composer.ts:450](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/composer.ts#L450) +[src/types/composer.ts:445](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/composer.ts#L445) ___ @@ -505,7 +503,7 @@ The built atomic transaction composer and the transactions #### Defined in -[src/types/composer.ts:919](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/composer.ts#L919) +[src/types/composer.ts:914](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/composer.ts#L914) ___ @@ -526,7 +524,7 @@ ___ #### Defined in -[src/types/composer.ts:791](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/composer.ts#L791) +[src/types/composer.ts:786](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/composer.ts#L786) ___ @@ -547,7 +545,7 @@ ___ #### Defined in -[src/types/composer.ts:740](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/composer.ts#L740) +[src/types/composer.ts:735](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/composer.ts#L735) ___ @@ -568,7 +566,7 @@ ___ #### Defined in -[src/types/composer.ts:720](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/composer.ts#L720) +[src/types/composer.ts:715](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/composer.ts#L715) ___ @@ -589,7 +587,7 @@ ___ #### Defined in -[src/types/composer.ts:755](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/composer.ts#L755) +[src/types/composer.ts:750](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/composer.ts#L750) ___ @@ -610,7 +608,7 @@ ___ #### Defined in -[src/types/composer.ts:765](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/composer.ts#L765) +[src/types/composer.ts:760](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/composer.ts#L760) ___ @@ -631,7 +629,7 @@ ___ #### Defined in -[src/types/composer.ts:777](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/composer.ts#L777) +[src/types/composer.ts:772](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/composer.ts#L772) ___ @@ -651,7 +649,7 @@ ___ #### Defined in -[src/types/composer.ts:579](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/composer.ts#L579) +[src/types/composer.ts:574](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/composer.ts#L574) ___ @@ -672,7 +670,7 @@ ___ #### Defined in -[src/types/composer.ts:831](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/composer.ts#L831) +[src/types/composer.ts:826](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/composer.ts#L826) ___ @@ -693,7 +691,7 @@ ___ #### Defined in -[src/types/composer.ts:634](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/composer.ts#L634) +[src/types/composer.ts:629](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/composer.ts#L629) ___ @@ -714,7 +712,7 @@ ___ #### Defined in -[src/types/composer.ts:708](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/composer.ts#L708) +[src/types/composer.ts:703](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/composer.ts#L703) ___ @@ -735,7 +733,7 @@ ___ #### Defined in -[src/types/composer.ts:849](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/composer.ts#L849) +[src/types/composer.ts:844](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/composer.ts#L844) ___ @@ -757,7 +755,7 @@ ___ #### Defined in -[src/types/composer.ts:593](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/composer.ts#L593) +[src/types/composer.ts:588](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/composer.ts#L588) ___ @@ -781,7 +779,7 @@ The execution result #### Defined in -[src/types/composer.ts:961](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/composer.ts#L961) +[src/types/composer.ts:956](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/composer.ts#L956) ___ @@ -800,4 +798,4 @@ The newly built atomic transaction composer and the transactions #### Defined in -[src/types/composer.ts:951](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/composer.ts#L951) +[src/types/composer.ts:946](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/composer.ts#L946) diff --git a/docs/code/modules/types_composer.md b/docs/code/modules/types_composer.md index 9be1dbeb..25a16eb3 100644 --- a/docs/code/modules/types_composer.md +++ b/docs/code/modules/types_composer.md @@ -14,7 +14,7 @@ ### Type Aliases -- [AlgokitComposerParams](types_composer.md#algokitcomposerparams) +- [AlgoKitComposerParams](types_composer.md#algokitcomposerparams) - [AppCallParams](types_composer.md#appcallparams) - [AssetConfigParams](types_composer.md#assetconfigparams) - [AssetCreateParams](types_composer.md#assetcreateparams) @@ -34,9 +34,9 @@ ## Type Aliases -### AlgokitComposerParams +### AlgoKitComposerParams -Ƭ **AlgokitComposerParams**: `Object` +Ƭ **AlgoKitComposerParams**: `Object` Parameters to create an `AlgokitComposer`. diff --git a/src/transaction/legacy-bridge.ts b/src/transaction/legacy-bridge.ts index 2c4332cd..e6c47d41 100644 --- a/src/transaction/legacy-bridge.ts +++ b/src/transaction/legacy-bridge.ts @@ -59,7 +59,7 @@ export async function legacySendTransactionBridgeComposer sendParams!.atc!.addTransaction(txn)) @@ -67,7 +67,7 @@ export async function legacySendTransactionBridgeComposer Date: Wed, 28 Aug 2024 00:45:46 +0800 Subject: [PATCH 12/18] chore: Fixing vulnerable dependency --- package-lock.json | 8 ++++---- package.json | 3 ++- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/package-lock.json b/package-lock.json index 0726ee3f..e5457ac9 100644 --- a/package-lock.json +++ b/package-lock.json @@ -8321,12 +8321,12 @@ } }, "node_modules/micromatch": { - "version": "4.0.5", - "resolved": "https://registry.npmjs.org/micromatch/-/micromatch-4.0.5.tgz", - "integrity": "sha512-DMy+ERcEW2q8Z2Po+WNXuw3c5YaUSFjAO5GsJqfEl7UjvtIuFKO6ZrKvcItdy98dwFI2N1tg3zNIdKaQT+aNdA==", + "version": "4.0.8", + "resolved": "https://registry.npmjs.org/micromatch/-/micromatch-4.0.8.tgz", + "integrity": "sha512-PXwfBhYu0hBCPw8Dn0E+WDYb7af3dSLVWKi3HGv84IdF4TyFoC0ysxFd0Goxw7nSv4T/PzEJQxsYsEiFCKo2BA==", "dev": true, "dependencies": { - "braces": "^3.0.2", + "braces": "^3.0.3", "picomatch": "^2.3.1" }, "engines": { diff --git a/package.json b/package.json index 57b29469..1166593a 100644 --- a/package.json +++ b/package.json @@ -54,7 +54,8 @@ "overrides": { "semver": "7.5.2", "eslint-plugin-prettier": "5.0.0", - "braces": "3.0.3" + "braces": "3.0.3", + "micromatch": "4.0.8" }, "dependencies": { "buffer": "^6.0.3" From a5b03ddd088e4a64af653c737e1bb1054b53e812 Mon Sep 17 00:00:00 2001 From: "Rob Moore (MakerX)" Date: Wed, 28 Aug 2024 01:37:29 +0800 Subject: [PATCH 13/18] fix: No longer require registration of a signer when building individual transactions refactor: Refactored AlgorandClient to have separate classes for `send` and `transaction` refactor: Refactored legacyTransactionBridge to not have a dependency of AlgorandClient --- docs/code/README.md | 2 + .../types_account_manager.AccountManager.md | 4 +- .../types_algorand_client.AlgorandClient.md | 155 +--- ...rand_client_sender.AlgorandClientSender.md | 711 +++++++++++++++++ ...reator.AlgorandClientTransactionCreator.md | 637 +++++++++++++++ .../types_app_client.ApplicationClient.md | 24 +- .../types_asset_manager.AssetManager.md | 55 +- docs/code/classes/types_composer.default.md | 70 +- .../types_asset_manager.AssetInformation.md | 32 +- ...s_asset_manager.BulkAssetOptInOutResult.md | 4 +- docs/code/modules/index.md | 12 +- docs/code/modules/types_algorand_client.md | 16 - .../modules/types_algorand_client_sender.md | 25 + ...pes_algorand_client_transaction_creator.md | 9 + src/account/account.ts | 7 +- src/asset.ts | 35 +- src/transaction/legacy-bridge.ts | 62 +- src/transfer/transfer-algos.ts | 4 +- src/transfer/transfer.ts | 8 +- src/types/account-manager.ts | 2 +- src/types/algorand-client-sender.ts | 459 +++++++++++ .../algorand-client-transaction-creator.ts | 304 +++++++ src/types/algorand-client.ts | 740 +----------------- src/types/app-client.ts | 9 +- src/types/asset-manager.ts | 39 +- src/types/composer.ts | 117 +-- 26 files changed, 2431 insertions(+), 1111 deletions(-) create mode 100644 docs/code/classes/types_algorand_client_sender.AlgorandClientSender.md create mode 100644 docs/code/classes/types_algorand_client_transaction_creator.AlgorandClientTransactionCreator.md create mode 100644 docs/code/modules/types_algorand_client_sender.md create mode 100644 docs/code/modules/types_algorand_client_transaction_creator.md create mode 100644 src/types/algorand-client-sender.ts create mode 100644 src/types/algorand-client-transaction-creator.ts diff --git a/docs/code/README.md b/docs/code/README.md index ed5de139..6d97e94c 100644 --- a/docs/code/README.md +++ b/docs/code/README.md @@ -13,6 +13,8 @@ - [types/account-manager.spec](modules/types_account_manager_spec.md) - [types/algo-http-client-with-retry](modules/types_algo_http_client_with_retry.md) - [types/algorand-client](modules/types_algorand_client.md) +- [types/algorand-client-sender](modules/types_algorand_client_sender.md) +- [types/algorand-client-transaction-creator](modules/types_algorand_client_transaction_creator.md) - [types/algorand-client.asset.spec](modules/types_algorand_client_asset_spec.md) - [types/algorand-client.spec](modules/types_algorand_client_spec.md) - [types/algorand-client.transfer.spec](modules/types_algorand_client_transfer_spec.md) diff --git a/docs/code/classes/types_account_manager.AccountManager.md b/docs/code/classes/types_account_manager.AccountManager.md index 5a9da9f4..d4a115a9 100644 --- a/docs/code/classes/types_account_manager.AccountManager.md +++ b/docs/code/classes/types_account_manager.AccountManager.md @@ -671,7 +671,7 @@ ___ ### rekeyAccount -▸ **rekeyAccount**(`account`, `rekeyTo`, `options?`): `Promise`\<[`SendSingleTransactionResult`](../modules/types_algorand_client.md#sendsingletransactionresult)\> +▸ **rekeyAccount**(`account`, `rekeyTo`, `options?`): `Promise`\<[`SendSingleTransactionResult`](../modules/types_algorand_client_sender.md#sendsingletransactionresult)\> Rekey an account to a new address. @@ -687,7 +687,7 @@ Rekey an account to a new address. #### Returns -`Promise`\<[`SendSingleTransactionResult`](../modules/types_algorand_client.md#sendsingletransactionresult)\> +`Promise`\<[`SendSingleTransactionResult`](../modules/types_algorand_client_sender.md#sendsingletransactionresult)\> The result of the transaction and the transaction that was sent diff --git a/docs/code/classes/types_algorand_client.AlgorandClient.md b/docs/code/classes/types_algorand_client.AlgorandClient.md index 112d5a18..3df21d65 100644 --- a/docs/code/classes/types_algorand_client.AlgorandClient.md +++ b/docs/code/classes/types_algorand_client.AlgorandClient.md @@ -21,19 +21,19 @@ A client that brokers easy access to Algorand functionality. - [\_cachedSuggestedParamsTimeout](types_algorand_client.AlgorandClient.md#_cachedsuggestedparamstimeout) - [\_clientManager](types_algorand_client.AlgorandClient.md#_clientmanager) - [\_defaultValidityWindow](types_algorand_client.AlgorandClient.md#_defaultvaliditywindow) -- [send](types_algorand_client.AlgorandClient.md#send) -- [transactions](types_algorand_client.AlgorandClient.md#transactions) +- [\_sender](types_algorand_client.AlgorandClient.md#_sender) +- [\_transactionCreator](types_algorand_client.AlgorandClient.md#_transactioncreator) ### Accessors - [account](types_algorand_client.AlgorandClient.md#account) - [asset](types_algorand_client.AlgorandClient.md#asset) - [client](types_algorand_client.AlgorandClient.md#client) +- [send](types_algorand_client.AlgorandClient.md#send) +- [transactions](types_algorand_client.AlgorandClient.md#transactions) ### Methods -- [\_send](types_algorand_client.AlgorandClient.md#_send) -- [\_transaction](types_algorand_client.AlgorandClient.md#_transaction) - [getSuggestedParams](types_algorand_client.AlgorandClient.md#getsuggestedparams) - [newGroup](types_algorand_client.AlgorandClient.md#newgroup) - [setDefaultSigner](types_algorand_client.AlgorandClient.md#setdefaultsigner) @@ -67,7 +67,7 @@ A client that brokers easy access to Algorand functionality. #### Defined in -[src/types/algorand-client.ts:31](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/algorand-client.ts#L31) +[src/types/algorand-client.ts:29](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/algorand-client.ts#L29) ## Properties @@ -77,7 +77,7 @@ A client that brokers easy access to Algorand functionality. #### Defined in -[src/types/algorand-client.ts:22](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/algorand-client.ts#L22) +[src/types/algorand-client.ts:18](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/algorand-client.ts#L18) ___ @@ -87,7 +87,7 @@ ___ #### Defined in -[src/types/algorand-client.ts:23](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/algorand-client.ts#L23) +[src/types/algorand-client.ts:19](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/algorand-client.ts#L19) ___ @@ -97,7 +97,7 @@ ___ #### Defined in -[src/types/algorand-client.ts:25](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/algorand-client.ts#L25) +[src/types/algorand-client.ts:23](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/algorand-client.ts#L23) ___ @@ -107,7 +107,7 @@ ___ #### Defined in -[src/types/algorand-client.ts:26](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/algorand-client.ts#L26) +[src/types/algorand-client.ts:24](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/algorand-client.ts#L24) ___ @@ -117,7 +117,7 @@ ___ #### Defined in -[src/types/algorand-client.ts:27](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/algorand-client.ts#L27) +[src/types/algorand-client.ts:25](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/algorand-client.ts#L25) ___ @@ -127,7 +127,7 @@ ___ #### Defined in -[src/types/algorand-client.ts:21](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/algorand-client.ts#L21) +[src/types/algorand-client.ts:17](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/algorand-client.ts#L17) ___ @@ -137,63 +137,27 @@ ___ #### Defined in -[src/types/algorand-client.ts:29](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/algorand-client.ts#L29) +[src/types/algorand-client.ts:27](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/algorand-client.ts#L27) ___ -### send - -• **send**: `Object` +### \_sender -Methods for sending a single transaction. - -#### Type declaration - -| Name | Type | Description | -| :------ | :------ | :------ | -| `appCall` | (`params`: [`CommonTransactionParams`](../modules/types_composer.md#commontransactionparams) & \{ `accountReferences?`: `string`[] ; `appId?`: `bigint` ; `appReferences?`: `bigint`[] ; `approvalProgram?`: `Uint8Array` ; `args?`: `Uint8Array`[] ; `assetReferences?`: `bigint`[] ; `boxReferences?`: `BoxReference`[] ; `clearProgram?`: `Uint8Array` ; `extraPages?`: `number` ; `onComplete?`: `OnApplicationComplete` ; `schema?`: \{ `globalByteSlices`: `number` ; `globalUints`: `number` ; `localByteSlices`: `number` ; `localUints`: `number` } } & [`ExecuteParams`](../interfaces/types_composer.ExecuteParams.md)) => `Promise`\<[`SendSingleTransactionResult`](../modules/types_algorand_client.md#sendsingletransactionresult)\> | - | -| `assetConfig` | (`params`: [`CommonTransactionParams`](../modules/types_composer.md#commontransactionparams) & \{ `assetId`: `bigint` ; `clawback?`: `string` ; `freeze?`: `string` ; `manager`: `undefined` \| `string` ; `reserve?`: `string` } & [`ExecuteParams`](../interfaces/types_composer.ExecuteParams.md)) => `Promise`\<[`SendSingleTransactionResult`](../modules/types_algorand_client.md#sendsingletransactionresult)\> | - | -| `assetCreate` | (`params`: [`CommonTransactionParams`](../modules/types_composer.md#commontransactionparams) & \{ `assetName?`: `string` ; `clawback?`: `string` ; `decimals?`: `number` ; `defaultFrozen?`: `boolean` ; `freeze?`: `string` ; `manager?`: `string` ; `metadataHash?`: `string` \| `Uint8Array` ; `reserve?`: `string` ; `total`: `bigint` ; `unitName?`: `string` ; `url?`: `string` } & [`ExecuteParams`](../interfaces/types_composer.ExecuteParams.md)) => `Promise`\<\{ `assetId`: `bigint` ; `confirmation`: `PendingTransactionResponse` ; `confirmations`: `PendingTransactionResponse`[] ; `groupId`: `string` ; `returns?`: [`ABIReturn`](../modules/types_app.md#abireturn)[] ; `transaction`: `Transaction` ; `transactions`: `Transaction`[] ; `txIds`: `string`[] }\> | - | -| `assetDestroy` | (`params`: [`CommonTransactionParams`](../modules/types_composer.md#commontransactionparams) & \{ `assetId`: `bigint` } & [`ExecuteParams`](../interfaces/types_composer.ExecuteParams.md)) => `Promise`\<[`SendSingleTransactionResult`](../modules/types_algorand_client.md#sendsingletransactionresult)\> | - | -| `assetFreeze` | (`params`: [`CommonTransactionParams`](../modules/types_composer.md#commontransactionparams) & \{ `account`: `string` ; `assetId`: `bigint` ; `frozen`: `boolean` } & [`ExecuteParams`](../interfaces/types_composer.ExecuteParams.md)) => `Promise`\<[`SendSingleTransactionResult`](../modules/types_algorand_client.md#sendsingletransactionresult)\> | - | -| `assetOptIn` | (`params`: [`CommonTransactionParams`](../modules/types_composer.md#commontransactionparams) & \{ `assetId`: `bigint` } & [`ExecuteParams`](../interfaces/types_composer.ExecuteParams.md)) => `Promise`\<[`SendSingleTransactionResult`](../modules/types_algorand_client.md#sendsingletransactionresult)\> | - | -| `assetOptOut` | (`params`: `Omit`\<[`AssetOptOutParams`](../modules/types_composer.md#assetoptoutparams), ``"creator"``\> & \{ `creator?`: `string` ; `ensureZeroBalance`: `boolean` } & [`ExecuteParams`](../interfaces/types_composer.ExecuteParams.md)) => `Promise`\<[`SendSingleTransactionResult`](../modules/types_algorand_client.md#sendsingletransactionresult)\> | - | -| `assetTransfer` | (`params`: [`CommonTransactionParams`](../modules/types_composer.md#commontransactionparams) & \{ `amount`: `bigint` ; `assetId`: `bigint` ; `clawbackTarget?`: `string` ; `closeAssetTo?`: `string` ; `receiver`: `string` } & [`ExecuteParams`](../interfaces/types_composer.ExecuteParams.md)) => `Promise`\<[`SendSingleTransactionResult`](../modules/types_algorand_client.md#sendsingletransactionresult)\> | - | -| `methodCall` | (`params`: [`CommonTransactionParams`](../modules/types_composer.md#commontransactionparams) & `Omit`\<[`AppCallParams`](../modules/types_composer.md#appcallparams), ``"args"``\> & \{ `appId`: `bigint` ; `args?`: (`TransactionWithSigner` \| `Transaction` \| `ABIValue` \| `Promise`\<`Transaction`\> \| [`MethodCallParams`](../modules/types_composer.md#methodcallparams))[] ; `method`: `ABIMethod` } & [`ExecuteParams`](../interfaces/types_composer.ExecuteParams.md)) => `Promise`\<[`SendSingleTransactionResult`](../modules/types_algorand_client.md#sendsingletransactionresult)\> | - | -| `onlineKeyRegistration` | (`params`: [`CommonTransactionParams`](../modules/types_composer.md#commontransactionparams) & \{ `selectionKey`: `Uint8Array` ; `stateProofKey?`: `Uint8Array` ; `voteFirst`: `bigint` ; `voteKey`: `Uint8Array` ; `voteKeyDilution`: `bigint` ; `voteLast`: `bigint` } & [`ExecuteParams`](../interfaces/types_composer.ExecuteParams.md)) => `Promise`\<[`SendSingleTransactionResult`](../modules/types_algorand_client.md#sendsingletransactionresult)\> | - | -| `payment` | (`params`: [`CommonTransactionParams`](../modules/types_composer.md#commontransactionparams) & \{ `amount`: [`AlgoAmount`](types_amount.AlgoAmount.md) ; `closeRemainderTo?`: `string` ; `receiver`: `string` } & [`ExecuteParams`](../interfaces/types_composer.ExecuteParams.md)) => `Promise`\<[`SendSingleTransactionResult`](../modules/types_algorand_client.md#sendsingletransactionresult)\> | - | +• `Private` **\_sender**: [`AlgorandClientSender`](types_algorand_client_sender.AlgorandClientSender.md) #### Defined in -[src/types/algorand-client.ts:191](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/algorand-client.ts#L191) +[src/types/algorand-client.ts:20](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/algorand-client.ts#L20) ___ -### transactions - -• **transactions**: `Object` - -Methods for building transactions +### \_transactionCreator -#### Type declaration - -| Name | Type | Description | -| :------ | :------ | :------ | -| `appCall` | (`params`: [`AppCallParams`](../modules/types_composer.md#appcallparams)) => `Promise`\<`Transaction`\> | - | -| `assetConfig` | (`params`: [`AssetConfigParams`](../modules/types_composer.md#assetconfigparams)) => `Promise`\<`Transaction`\> | - | -| `assetCreate` | (`params`: [`AssetCreateParams`](../modules/types_composer.md#assetcreateparams)) => `Promise`\<`Transaction`\> | - | -| `assetDestroy` | (`params`: [`AssetDestroyParams`](../modules/types_composer.md#assetdestroyparams)) => `Promise`\<`Transaction`\> | - | -| `assetFreeze` | (`params`: [`AssetFreezeParams`](../modules/types_composer.md#assetfreezeparams)) => `Promise`\<`Transaction`\> | - | -| `assetOptIn` | (`params`: [`AssetOptInParams`](../modules/types_composer.md#assetoptinparams)) => `Promise`\<`Transaction`\> | - | -| `assetOptOut` | (`params`: [`AssetOptOutParams`](../modules/types_composer.md#assetoptoutparams)) => `Promise`\<`Transaction`\> | - | -| `assetTransfer` | (`params`: [`AssetTransferParams`](../modules/types_composer.md#assettransferparams)) => `Promise`\<`Transaction`\> | - | -| `methodCall` | (`params`: [`MethodCallParams`](../modules/types_composer.md#methodcallparams)) => `Promise`\<`Transaction`[]\> | - | -| `onlineKeyRegistration` | (`params`: [`OnlineKeyRegistrationParams`](../modules/types_composer.md#onlinekeyregistrationparams)) => `Promise`\<`Transaction`\> | - | -| `payment` | (`params`: [`PaymentParams`](../modules/types_composer.md#paymentparams)) => `Promise`\<`Transaction`\> | - | +• `Private` **\_transactionCreator**: [`AlgorandClientTransactionCreator`](types_algorand_client_transaction_creator.AlgorandClientTransactionCreator.md) #### Defined in -[src/types/algorand-client.ts:603](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/algorand-client.ts#L603) +[src/types/algorand-client.ts:21](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/algorand-client.ts#L21) ## Accessors @@ -243,86 +207,39 @@ Get clients, including algosdk clients and app clients. [src/types/algorand-client.ts:129](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/algorand-client.ts#L129) -## Methods - -### \_send - -▸ **_send**\<`T`\>(`c`, `log?`): (`params`: `T` & [`ExecuteParams`](../interfaces/types_composer.ExecuteParams.md)) => `Promise`\<[`SendSingleTransactionResult`](../modules/types_algorand_client.md#sendsingletransactionresult)\> - -#### Type parameters +___ -| Name | -| :------ | -| `T` | +### send -#### Parameters +• `get` **send**(): [`AlgorandClientSender`](types_algorand_client_sender.AlgorandClientSender.md) -| Name | Type | -| :------ | :------ | -| `c` | (`c`: [`default`](types_composer.default.md)) => (`params`: `T`) => [`default`](types_composer.default.md) | -| `log?` | `Object` | -| `log.postLog?` | (`params`: `T`, `result`: [`SendSingleTransactionResult`](../modules/types_algorand_client.md#sendsingletransactionresult)) => `string` | -| `log.preLog?` | (`params`: `T`, `transaction`: `Transaction`) => `string` | +Methods for sending a single transaction. #### Returns -`fn` - -▸ (`params`): `Promise`\<[`SendSingleTransactionResult`](../modules/types_algorand_client.md#sendsingletransactionresult)\> - -##### Parameters - -| Name | Type | -| :------ | :------ | -| `params` | `T` & [`ExecuteParams`](../interfaces/types_composer.ExecuteParams.md) | - -##### Returns - -`Promise`\<[`SendSingleTransactionResult`](../modules/types_algorand_client.md#sendsingletransactionresult)\> +[`AlgorandClientSender`](types_algorand_client_sender.AlgorandClientSender.md) #### Defined in -[src/types/algorand-client.ts:153](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/algorand-client.ts#L153) +[src/types/algorand-client.ts:156](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/algorand-client.ts#L156) ___ -### \_transaction - -▸ **_transaction**\<`T`\>(`c`): (`params`: `T`) => `Promise`\<`Transaction`\> - -#### Type parameters - -| Name | -| :------ | -| `T` | +### transactions -#### Parameters +• `get` **transactions**(): [`AlgorandClientTransactionCreator`](types_algorand_client_transaction_creator.AlgorandClientTransactionCreator.md) -| Name | Type | -| :------ | :------ | -| `c` | (`c`: [`default`](types_composer.default.md)) => (`params`: `T`) => [`default`](types_composer.default.md) | +Methods for building transactions #### Returns -`fn` - -▸ (`params`): `Promise`\<`Transaction`\> - -##### Parameters - -| Name | Type | -| :------ | :------ | -| `params` | `T` | - -##### Returns - -`Promise`\<`Transaction`\> +[`AlgorandClientTransactionCreator`](types_algorand_client_transaction_creator.AlgorandClientTransactionCreator.md) #### Defined in -[src/types/algorand-client.ts:592](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/algorand-client.ts#L592) +[src/types/algorand-client.ts:163](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/algorand-client.ts#L163) -___ +## Methods ### getSuggestedParams @@ -527,7 +444,7 @@ The `AlgorandClient` #### Defined in -[src/types/algorand-client.ts:889](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/algorand-client.ts#L889) +[src/types/algorand-client.ts:173](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/algorand-client.ts#L173) ___ @@ -551,7 +468,7 @@ The `AlgorandClient` #### Defined in -[src/types/algorand-client.ts:926](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/algorand-client.ts#L926) +[src/types/algorand-client.ts:210](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/algorand-client.ts#L210) ___ @@ -575,7 +492,7 @@ The `AlgorandClient` #### Defined in -[src/types/algorand-client.ts:956](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/algorand-client.ts#L956) +[src/types/algorand-client.ts:240](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/algorand-client.ts#L240) ___ @@ -606,7 +523,7 @@ The `AlgorandClient` #### Defined in -[src/types/algorand-client.ts:947](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/algorand-client.ts#L947) +[src/types/algorand-client.ts:231](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/algorand-client.ts#L231) ___ @@ -624,7 +541,7 @@ The `AlgorandClient` #### Defined in -[src/types/algorand-client.ts:913](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/algorand-client.ts#L913) +[src/types/algorand-client.ts:197](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/algorand-client.ts#L197) ___ @@ -642,4 +559,4 @@ The `AlgorandClient` #### Defined in -[src/types/algorand-client.ts:901](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/algorand-client.ts#L901) +[src/types/algorand-client.ts:185](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/algorand-client.ts#L185) diff --git a/docs/code/classes/types_algorand_client_sender.AlgorandClientSender.md b/docs/code/classes/types_algorand_client_sender.AlgorandClientSender.md new file mode 100644 index 00000000..09a21f56 --- /dev/null +++ b/docs/code/classes/types_algorand_client_sender.AlgorandClientSender.md @@ -0,0 +1,711 @@ +[@algorandfoundation/algokit-utils](../README.md) / [types/algorand-client-sender](../modules/types_algorand_client_sender.md) / AlgorandClientSender + +# Class: AlgorandClientSender + +[types/algorand-client-sender](../modules/types_algorand_client_sender.md).AlgorandClientSender + +Orchestrates sending transactions for `AlgorandClient`. + +## Table of contents + +### Constructors + +- [constructor](types_algorand_client_sender.AlgorandClientSender.md#constructor) + +### Properties + +- [\_assetManager](types_algorand_client_sender.AlgorandClientSender.md#_assetmanager) +- [\_newGroup](types_algorand_client_sender.AlgorandClientSender.md#_newgroup) +- [appCall](types_algorand_client_sender.AlgorandClientSender.md#appcall) +- [assetConfig](types_algorand_client_sender.AlgorandClientSender.md#assetconfig) +- [assetDestroy](types_algorand_client_sender.AlgorandClientSender.md#assetdestroy) +- [assetFreeze](types_algorand_client_sender.AlgorandClientSender.md#assetfreeze) +- [assetOptIn](types_algorand_client_sender.AlgorandClientSender.md#assetoptin) +- [assetTransfer](types_algorand_client_sender.AlgorandClientSender.md#assettransfer) +- [methodCall](types_algorand_client_sender.AlgorandClientSender.md#methodcall) +- [onlineKeyRegistration](types_algorand_client_sender.AlgorandClientSender.md#onlinekeyregistration) +- [payment](types_algorand_client_sender.AlgorandClientSender.md#payment) + +### Methods + +- [\_send](types_algorand_client_sender.AlgorandClientSender.md#_send) +- [assetCreate](types_algorand_client_sender.AlgorandClientSender.md#assetcreate) +- [assetOptOut](types_algorand_client_sender.AlgorandClientSender.md#assetoptout) + +## Constructors + +### constructor + +• **new AlgorandClientSender**(`newGroup`, `assetManager`): [`AlgorandClientSender`](types_algorand_client_sender.AlgorandClientSender.md) + +Creates a new `AlgorandClientSender` + +#### Parameters + +| Name | Type | Description | +| :------ | :------ | :------ | +| `newGroup` | () => [`default`](types_composer.default.md) | A lambda that Start a new `AlgokitComposer` transaction group | +| `assetManager` | [`AssetManager`](types_asset_manager.AssetManager.md) | An `AssetManager` instance | + +#### Returns + +[`AlgorandClientSender`](types_algorand_client_sender.AlgorandClientSender.md) + +#### Defined in + +[src/types/algorand-client-sender.ts:22](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/algorand-client-sender.ts#L22) + +## Properties + +### \_assetManager + +• `Private` **\_assetManager**: [`AssetManager`](types_asset_manager.AssetManager.md) + +#### Defined in + +[src/types/algorand-client-sender.ts:15](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/algorand-client-sender.ts#L15) + +___ + +### \_newGroup + +• `Private` **\_newGroup**: () => [`default`](types_composer.default.md) + +#### Type declaration + +▸ (): [`default`](types_composer.default.md) + +##### Returns + +[`default`](types_composer.default.md) + +#### Defined in + +[src/types/algorand-client-sender.ts:14](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/algorand-client-sender.ts#L14) + +___ + +### appCall + +• **appCall**: (`params`: [`CommonTransactionParams`](../modules/types_composer.md#commontransactionparams) & \{ `accountReferences?`: `string`[] ; `appId?`: `bigint` ; `appReferences?`: `bigint`[] ; `approvalProgram?`: `Uint8Array` ; `args?`: `Uint8Array`[] ; `assetReferences?`: `bigint`[] ; `boxReferences?`: `BoxReference`[] ; `clearProgram?`: `Uint8Array` ; `extraPages?`: `number` ; `onComplete?`: `OnApplicationComplete` ; `schema?`: \{ `globalByteSlices`: `number` ; `globalUints`: `number` ; `localByteSlices`: `number` ; `localUints`: `number` } } & [`ExecuteParams`](../interfaces/types_composer.ExecuteParams.md)) => `Promise`\<[`SendSingleTransactionResult`](../modules/types_algorand_client_sender.md#sendsingletransactionresult)\> + +Call a smart contract. + +Note: you may prefer to use `algorandClient.client` to get an app client for more advanced functionality. + +#### Type declaration + +▸ (`params`): `Promise`\<[`SendSingleTransactionResult`](../modules/types_algorand_client_sender.md#sendsingletransactionresult)\> + +##### Parameters + +| Name | Type | +| :------ | :------ | +| `params` | [`CommonTransactionParams`](../modules/types_composer.md#commontransactionparams) & \{ `accountReferences?`: `string`[] ; `appId?`: `bigint` ; `appReferences?`: `bigint`[] ; `approvalProgram?`: `Uint8Array` ; `args?`: `Uint8Array`[] ; `assetReferences?`: `bigint`[] ; `boxReferences?`: `BoxReference`[] ; `clearProgram?`: `Uint8Array` ; `extraPages?`: `number` ; `onComplete?`: `OnApplicationComplete` ; `schema?`: \{ `globalByteSlices`: `number` ; `globalUints`: `number` ; `localByteSlices`: `number` ; `localUints`: `number` } } & [`ExecuteParams`](../interfaces/types_composer.ExecuteParams.md) | + +##### Returns + +`Promise`\<[`SendSingleTransactionResult`](../modules/types_algorand_client_sender.md#sendsingletransactionresult)\> + +#### Defined in + +[src/types/algorand-client-sender.ts:448](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/algorand-client-sender.ts#L448) + +___ + +### assetConfig + +• **assetConfig**: (`params`: [`CommonTransactionParams`](../modules/types_composer.md#commontransactionparams) & \{ `assetId`: `bigint` ; `clawback?`: `string` ; `freeze?`: `string` ; `manager`: `undefined` \| `string` ; `reserve?`: `string` } & [`ExecuteParams`](../interfaces/types_composer.ExecuteParams.md)) => `Promise`\<[`SendSingleTransactionResult`](../modules/types_algorand_client_sender.md#sendsingletransactionresult)\> + +Configure an existing Algorand Standard Asset. + +**Note:** The manager, reserve, freeze, and clawback addresses +are immutably empty if they are not set. If manager is not set then +all fields are immutable from that point forward. + +**`Example`** + +```typescript +await algorand.send.assetConfig({sender: "MANAGERADDRESS", assetId: 123456n, manager: "MANAGERADDRESS" }) +``` + +**`Example`** + +```typescript +await algorand.send.assetConfig({ + sender: 'MANAGERADDRESS', + assetId: 123456n, + manager: 'MANAGERADDRESS', + reserve: 'RESERVEADDRESS', + freeze: 'FREEZEADDRESS', + clawback: 'CLAWBACKADDRESS', + lease: 'lease', + note: 'note', + // You wouldn't normally set this field + firstValidRound: 1000n, + validityWindow: 10, + extraFee: (1000).microAlgos(), + staticFee: (1000).microAlgos(), + // Max fee doesn't make sense with extraFee AND staticFee + // already specified, but here for completeness + maxFee: (3000).microAlgos(), + // Signer only needed if you want to provide one, + // generally you'd register it with AlgorandClient + // against the sender and not need to pass it in + signer: transactionSigner, + maxRoundsToWaitForConfirmation: 5, + suppressLog: true, +}) +``` + +#### Type declaration + +▸ (`params`): `Promise`\<[`SendSingleTransactionResult`](../modules/types_algorand_client_sender.md#sendsingletransactionresult)\> + +##### Parameters + +| Name | Type | Description | +| :------ | :------ | :------ | +| `params` | [`CommonTransactionParams`](../modules/types_composer.md#commontransactionparams) & \{ `assetId`: `bigint` ; `clawback?`: `string` ; `freeze?`: `string` ; `manager`: `undefined` \| `string` ; `reserve?`: `string` } & [`ExecuteParams`](../interfaces/types_composer.ExecuteParams.md) | The parameters for the asset config transaction | + +##### Returns + +`Promise`\<[`SendSingleTransactionResult`](../modules/types_algorand_client_sender.md#sendsingletransactionresult)\> + +#### Defined in + +[src/types/algorand-client-sender.ts:203](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/algorand-client-sender.ts#L203) + +___ + +### assetDestroy + +• **assetDestroy**: (`params`: [`CommonTransactionParams`](../modules/types_composer.md#commontransactionparams) & \{ `assetId`: `bigint` } & [`ExecuteParams`](../interfaces/types_composer.ExecuteParams.md)) => `Promise`\<[`SendSingleTransactionResult`](../modules/types_algorand_client_sender.md#sendsingletransactionresult)\> + +Destroys an Algorand Standard Asset. + +Created assets can be destroyed only by the asset manager account. +All of the assets must be owned by the creator of the asset before +the asset can be deleted. + +**`Example`** + +```typescript +await algorand.send.assetDestroy({sender: "MANAGERADDRESS", assetId: 123456n }) +``` + +**`Example`** + +```typescript +await algorand.send.assetDestroy({ + sender: 'MANAGERADDRESS', + assetId: 123456n, + lease: 'lease', + note: 'note', + // You wouldn't normally set this field + firstValidRound: 1000n, + validityWindow: 10, + extraFee: (1000).microAlgos(), + staticFee: (1000).microAlgos(), + // Max fee doesn't make sense with extraFee AND staticFee + // already specified, but here for completeness + maxFee: (3000).microAlgos(), + // Signer only needed if you want to provide one, + // generally you'd register it with AlgorandClient + // against the sender and not need to pass it in + signer: transactionSigner, + maxRoundsToWaitForConfirmation: 5, + suppressLog: true, +}) +``` + +#### Type declaration + +▸ (`params`): `Promise`\<[`SendSingleTransactionResult`](../modules/types_algorand_client_sender.md#sendsingletransactionresult)\> + +##### Parameters + +| Name | Type | Description | +| :------ | :------ | :------ | +| `params` | [`CommonTransactionParams`](../modules/types_composer.md#commontransactionparams) & \{ `assetId`: `bigint` } & [`ExecuteParams`](../interfaces/types_composer.ExecuteParams.md) | The parameters for the asset destroy transaction | + +##### Returns + +`Promise`\<[`SendSingleTransactionResult`](../modules/types_algorand_client_sender.md#sendsingletransactionresult)\> + +#### Defined in + +[src/types/algorand-client-sender.ts:283](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/algorand-client-sender.ts#L283) + +___ + +### assetFreeze + +• **assetFreeze**: (`params`: [`CommonTransactionParams`](../modules/types_composer.md#commontransactionparams) & \{ `account`: `string` ; `assetId`: `bigint` ; `frozen`: `boolean` } & [`ExecuteParams`](../interfaces/types_composer.ExecuteParams.md)) => `Promise`\<[`SendSingleTransactionResult`](../modules/types_algorand_client_sender.md#sendsingletransactionresult)\> + +Freeze or unfreeze an Algorand Standard Asset for an account. + +**`Example`** + +```typescript +await algorand.send.assetFreeze({sender: "MANAGERADDRESS", assetId: 123456n, account: "ACCOUNTADDRESS", frozen: true }) +``` + +**`Example`** + +```typescript +await algorand.send.assetFreeze({ + sender: 'MANAGERADDRESS', + assetId: 123456n, + account: 'ACCOUNTADDRESS', + frozen: true, + lease: 'lease', + note: 'note', + // You wouldn't normally set this field + firstValidRound: 1000n, + validityWindow: 10, + extraFee: (1000).microAlgos(), + staticFee: (1000).microAlgos(), + // Max fee doesn't make sense with extraFee AND staticFee + // already specified, but here for completeness + maxFee: (3000).microAlgos(), + // Signer only needed if you want to provide one, + // generally you'd register it with AlgorandClient + // against the sender and not need to pass it in + signer: transactionSigner, + maxRoundsToWaitForConfirmation: 5, + suppressLog: true, +}) +``` + +#### Type declaration + +▸ (`params`): `Promise`\<[`SendSingleTransactionResult`](../modules/types_algorand_client_sender.md#sendsingletransactionresult)\> + +##### Parameters + +| Name | Type | Description | +| :------ | :------ | :------ | +| `params` | [`CommonTransactionParams`](../modules/types_composer.md#commontransactionparams) & \{ `account`: `string` ; `assetId`: `bigint` ; `frozen`: `boolean` } & [`ExecuteParams`](../interfaces/types_composer.ExecuteParams.md) | The parameters for the asset freeze transaction | + +##### Returns + +`Promise`\<[`SendSingleTransactionResult`](../modules/types_algorand_client_sender.md#sendsingletransactionresult)\> + +#### Defined in + +[src/types/algorand-client-sender.ts:242](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/algorand-client-sender.ts#L242) + +___ + +### assetOptIn + +• **assetOptIn**: (`params`: [`CommonTransactionParams`](../modules/types_composer.md#commontransactionparams) & \{ `assetId`: `bigint` } & [`ExecuteParams`](../interfaces/types_composer.ExecuteParams.md)) => `Promise`\<[`SendSingleTransactionResult`](../modules/types_algorand_client_sender.md#sendsingletransactionresult)\> + +Opt an account into an Algorand Standard Asset. + +**`Example`** + +```typescript +await algorand.send.assetOptIn({sender: "SENDERADDRESS", assetId: 123456n }) +``` + +**`Example`** + +```typescript +await algorand.send.assetOptIn({ + sender: 'SENDERADDRESS', + assetId: 123456n, + lease: 'lease', + note: 'note', + // You wouldn't normally set this field + firstValidRound: 1000n, + validityWindow: 10, + extraFee: (1000).microAlgos(), + staticFee: (1000).microAlgos(), + // Max fee doesn't make sense with extraFee AND staticFee + // already specified, but here for completeness + maxFee: (3000).microAlgos(), + // Signer only needed if you want to provide one, + // generally you'd register it with AlgorandClient + // against the sender and not need to pass it in + signer: transactionSigner, + maxRoundsToWaitForConfirmation: 5, + suppressLog: true, +}) +``` + +#### Type declaration + +▸ (`params`): `Promise`\<[`SendSingleTransactionResult`](../modules/types_algorand_client_sender.md#sendsingletransactionresult)\> + +##### Parameters + +| Name | Type | Description | +| :------ | :------ | :------ | +| `params` | [`CommonTransactionParams`](../modules/types_composer.md#commontransactionparams) & \{ `assetId`: `bigint` } & [`ExecuteParams`](../interfaces/types_composer.ExecuteParams.md) | The parameters for the asset opt-in transaction | + +##### Returns + +`Promise`\<[`SendSingleTransactionResult`](../modules/types_algorand_client_sender.md#sendsingletransactionresult)\> + +#### Defined in + +[src/types/algorand-client-sender.ts:363](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/algorand-client-sender.ts#L363) + +___ + +### assetTransfer + +• **assetTransfer**: (`params`: [`CommonTransactionParams`](../modules/types_composer.md#commontransactionparams) & \{ `amount`: `bigint` ; `assetId`: `bigint` ; `clawbackTarget?`: `string` ; `closeAssetTo?`: `string` ; `receiver`: `string` } & [`ExecuteParams`](../interfaces/types_composer.ExecuteParams.md)) => `Promise`\<[`SendSingleTransactionResult`](../modules/types_algorand_client_sender.md#sendsingletransactionresult)\> + +Transfer an Algorand Standard Asset. + +**`Example`** + +```typescript +await algorand.send.assetTransfer({sender: "HOLDERADDRESS", assetId: 123456n, amount: 1n, receiver: "RECEIVERADDRESS" }) +``` + +**`Example`** + +```typescript +await algorand.send.assetTransfer({ + sender: 'CLAWBACKADDRESS', + assetId: 123456n, + amount: 1n, + receiver: 'RECEIVERADDRESS', + clawbackTarget: 'HOLDERADDRESS', + // This field needs to be used with caution + closeAssetTo: 'ADDRESSTOCLOSETO' + lease: 'lease', + note: 'note', + // You wouldn't normally set this field + firstValidRound: 1000n, + validityWindow: 10, + extraFee: (1000).microAlgos(), + staticFee: (1000).microAlgos(), + // Max fee doesn't make sense with extraFee AND staticFee + // already specified, but here for completeness + maxFee: (3000).microAlgos(), + // Signer only needed if you want to provide one, + // generally you'd register it with AlgorandClient + // against the sender and not need to pass it in + signer: transactionSigner, + maxRoundsToWaitForConfirmation: 5, + suppressLog: true, +}) +``` + +#### Type declaration + +▸ (`params`): `Promise`\<[`SendSingleTransactionResult`](../modules/types_algorand_client_sender.md#sendsingletransactionresult)\> + +##### Parameters + +| Name | Type | Description | +| :------ | :------ | :------ | +| `params` | [`CommonTransactionParams`](../modules/types_composer.md#commontransactionparams) & \{ `amount`: `bigint` ; `assetId`: `bigint` ; `clawbackTarget?`: `string` ; `closeAssetTo?`: `string` ; `receiver`: `string` } & [`ExecuteParams`](../interfaces/types_composer.ExecuteParams.md) | The parameters for the asset transfer transaction | + +##### Returns + +`Promise`\<[`SendSingleTransactionResult`](../modules/types_algorand_client_sender.md#sendsingletransactionresult)\> + +#### Defined in + +[src/types/algorand-client-sender.ts:325](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/algorand-client-sender.ts#L325) + +___ + +### methodCall + +• **methodCall**: (`params`: [`CommonTransactionParams`](../modules/types_composer.md#commontransactionparams) & `Omit`\<[`AppCallParams`](../modules/types_composer.md#appcallparams), ``"args"``\> & \{ `appId`: `bigint` ; `args?`: (`TransactionWithSigner` \| `Transaction` \| `ABIValue` \| `Promise`\<`Transaction`\> \| [`MethodCallParams`](../modules/types_composer.md#methodcallparams))[] ; `method`: `ABIMethod` } & [`ExecuteParams`](../interfaces/types_composer.ExecuteParams.md)) => `Promise`\<[`SendSingleTransactionResult`](../modules/types_algorand_client_sender.md#sendsingletransactionresult)\> + +Call a smart contract ABI method. + +Note: you may prefer to use `algorandClient.client` to get an app client for more advanced functionality. + +#### Type declaration + +▸ (`params`): `Promise`\<[`SendSingleTransactionResult`](../modules/types_algorand_client_sender.md#sendsingletransactionresult)\> + +##### Parameters + +| Name | Type | +| :------ | :------ | +| `params` | [`CommonTransactionParams`](../modules/types_composer.md#commontransactionparams) & `Omit`\<[`AppCallParams`](../modules/types_composer.md#appcallparams), ``"args"``\> & \{ `appId`: `bigint` ; `args?`: (`TransactionWithSigner` \| `Transaction` \| `ABIValue` \| `Promise`\<`Transaction`\> \| [`MethodCallParams`](../modules/types_composer.md#methodcallparams))[] ; `method`: `ABIMethod` } & [`ExecuteParams`](../interfaces/types_composer.ExecuteParams.md) | + +##### Returns + +`Promise`\<[`SendSingleTransactionResult`](../modules/types_algorand_client_sender.md#sendsingletransactionresult)\> + +#### Defined in + +[src/types/algorand-client-sender.ts:454](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/algorand-client-sender.ts#L454) + +___ + +### onlineKeyRegistration + +• **onlineKeyRegistration**: (`params`: [`CommonTransactionParams`](../modules/types_composer.md#commontransactionparams) & \{ `selectionKey`: `Uint8Array` ; `stateProofKey?`: `Uint8Array` ; `voteFirst`: `bigint` ; `voteKey`: `Uint8Array` ; `voteKeyDilution`: `bigint` ; `voteLast`: `bigint` } & [`ExecuteParams`](../interfaces/types_composer.ExecuteParams.md)) => `Promise`\<[`SendSingleTransactionResult`](../modules/types_algorand_client_sender.md#sendsingletransactionresult)\> + +Register an online key. + +#### Type declaration + +▸ (`params`): `Promise`\<[`SendSingleTransactionResult`](../modules/types_algorand_client_sender.md#sendsingletransactionresult)\> + +##### Parameters + +| Name | Type | +| :------ | :------ | +| `params` | [`CommonTransactionParams`](../modules/types_composer.md#commontransactionparams) & \{ `selectionKey`: `Uint8Array` ; `stateProofKey?`: `Uint8Array` ; `voteFirst`: `bigint` ; `voteKey`: `Uint8Array` ; `voteKeyDilution`: `bigint` ; `voteLast`: `bigint` } & [`ExecuteParams`](../interfaces/types_composer.ExecuteParams.md) | + +##### Returns + +`Promise`\<[`SendSingleTransactionResult`](../modules/types_algorand_client_sender.md#sendsingletransactionresult)\> + +#### Defined in + +[src/types/algorand-client-sender.ts:456](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/algorand-client-sender.ts#L456) + +___ + +### payment + +• **payment**: (`params`: [`CommonTransactionParams`](../modules/types_composer.md#commontransactionparams) & \{ `amount`: [`AlgoAmount`](types_amount.AlgoAmount.md) ; `closeRemainderTo?`: `string` ; `receiver`: `string` } & [`ExecuteParams`](../interfaces/types_composer.ExecuteParams.md)) => `Promise`\<[`SendSingleTransactionResult`](../modules/types_algorand_client_sender.md#sendsingletransactionresult)\> + +Send a payment transaction to transfer Algo between accounts. + +**`Example`** + +```typescript +const result = await algorandClient.send.payment({ + sender: 'SENDERADDRESS', + receiver: 'RECEIVERADDRESS', + amount: (4).algos(), +}) +``` + +**`Example`** + +```typescript +const result = await algorandClient.send.payment({ + amount: (4).algos(), + receiver: 'RECEIVERADDRESS', + sender: 'SENDERADDRESS', + closeRemainderTo: 'CLOSEREMAINDERTOADDRESS', + lease: 'lease', + note: 'note', + // Use this with caution, it's generally better to use algorand.account.rekeyAccount + rekeyTo: 'REKEYTOADDRESS', + // You wouldn't normally set this field + firstValidRound: 1000n, + validityWindow: 10, + extraFee: (1000).microAlgos(), + staticFee: (1000).microAlgos(), + // Max fee doesn't make sense with extraFee AND staticFee + // already specified, but here for completeness + maxFee: (3000).microAlgos(), + // Signer only needed if you want to provide one, + // generally you'd register it with AlgorandClient + // against the sender and not need to pass it in + signer: transactionSigner, + maxRoundsToWaitForConfirmation: 5, + suppressLog: true, +}) +``` + +#### Type declaration + +▸ (`params`): `Promise`\<[`SendSingleTransactionResult`](../modules/types_algorand_client_sender.md#sendsingletransactionresult)\> + +##### Parameters + +| Name | Type | Description | +| :------ | :------ | :------ | +| `params` | [`CommonTransactionParams`](../modules/types_composer.md#commontransactionparams) & \{ `amount`: [`AlgoAmount`](types_amount.AlgoAmount.md) ; `closeRemainderTo?`: `string` ; `receiver`: `string` } & [`ExecuteParams`](../interfaces/types_composer.ExecuteParams.md) | The parameters for the payment transaction | + +##### Returns + +`Promise`\<[`SendSingleTransactionResult`](../modules/types_algorand_client_sender.md#sendsingletransactionresult)\> + +#### Defined in + +[src/types/algorand-client-sender.ts:103](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/algorand-client-sender.ts#L103) + +## Methods + +### \_send + +▸ **_send**\<`T`\>(`c`, `log?`): (`params`: `T` & [`ExecuteParams`](../interfaces/types_composer.ExecuteParams.md)) => `Promise`\<[`SendSingleTransactionResult`](../modules/types_algorand_client_sender.md#sendsingletransactionresult)\> + +#### Type parameters + +| Name | +| :------ | +| `T` | + +#### Parameters + +| Name | Type | +| :------ | :------ | +| `c` | (`c`: [`default`](types_composer.default.md)) => (`params`: `T`) => [`default`](types_composer.default.md) | +| `log?` | `Object` | +| `log.postLog?` | (`params`: `T`, `result`: [`SendSingleTransactionResult`](../modules/types_algorand_client_sender.md#sendsingletransactionresult)) => `string` | +| `log.preLog?` | (`params`: `T`, `transaction`: `Transaction`) => `string` | + +#### Returns + +`fn` + +▸ (`params`): `Promise`\<[`SendSingleTransactionResult`](../modules/types_algorand_client_sender.md#sendsingletransactionresult)\> + +##### Parameters + +| Name | Type | +| :------ | :------ | +| `params` | `T` & [`ExecuteParams`](../interfaces/types_composer.ExecuteParams.md) | + +##### Returns + +`Promise`\<[`SendSingleTransactionResult`](../modules/types_algorand_client_sender.md#sendsingletransactionresult)\> + +#### Defined in + +[src/types/algorand-client-sender.ts:27](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/algorand-client-sender.ts#L27) + +___ + +### assetCreate + +▸ **assetCreate**(`params`): `Promise`\<\{ `assetId`: `bigint` ; `confirmation`: `PendingTransactionResponse` ; `confirmations`: `PendingTransactionResponse`[] ; `groupId`: `string` ; `returns?`: [`ABIReturn`](../modules/types_app.md#abireturn)[] ; `transaction`: `Transaction` ; `transactions`: `Transaction`[] ; `txIds`: `string`[] }\> + +Create a new Algorand Standard Asset. + +The account that sends this transaction will automatically be +opted in to the asset and will hold all units after creation. + +#### Parameters + +| Name | Type | Description | +| :------ | :------ | :------ | +| `params` | [`CommonTransactionParams`](../modules/types_composer.md#commontransactionparams) & \{ `assetName?`: `string` ; `clawback?`: `string` ; `decimals?`: `number` ; `defaultFrozen?`: `boolean` ; `freeze?`: `string` ; `manager?`: `string` ; `metadataHash?`: `string` \| `Uint8Array` ; `reserve?`: `string` ; `total`: `bigint` ; `unitName?`: `string` ; `url?`: `string` } & [`ExecuteParams`](../interfaces/types_composer.ExecuteParams.md) | The parameters for the asset creation transaction | + +#### Returns + +`Promise`\<\{ `assetId`: `bigint` ; `confirmation`: `PendingTransactionResponse` ; `confirmations`: `PendingTransactionResponse`[] ; `groupId`: `string` ; `returns?`: [`ABIReturn`](../modules/types_app.md#abireturn)[] ; `transaction`: `Transaction` ; `transactions`: `Transaction`[] ; `txIds`: `string`[] }\> + +The result of the transaction and the transaction that was sent + +**`Example`** + +```typescript +await algorand.send.assetCreate({sender: "CREATORADDRESS", total: 100n}) +``` + +**`Example`** + +```typescript +await algorand.send.assetCreate({ + sender: 'CREATORADDRESS', + total: 100n, + decimals: 2, + assetName: 'asset', + unitName: 'unit', + url: 'url', + metadataHash: 'metadataHash', + defaultFrozen: false, + manager: 'MANAGERADDRESS', + reserve: 'RESERVEADDRESS', + freeze: 'FREEZEADDRESS', + clawback: 'CLAWBACKADDRESS', + lease: 'lease', + note: 'note', + // You wouldn't normally set this field + firstValidRound: 1000n, + validityWindow: 10, + extraFee: (1000).microAlgos(), + staticFee: (1000).microAlgos(), + // Max fee doesn't make sense with extraFee AND staticFee + // already specified, but here for completeness + maxFee: (3000).microAlgos(), + // Signer only needed if you want to provide one, + // generally you'd register it with AlgorandClient + // against the sender and not need to pass it in + signer: transactionSigner, + maxRoundsToWaitForConfirmation: 5, + suppressLog: true, +}) +``` + +#### Defined in + +[src/types/algorand-client-sender.ts:154](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/algorand-client-sender.ts#L154) + +___ + +### assetOptOut + +▸ **assetOptOut**(`params`): `Promise`\<[`SendSingleTransactionResult`](../modules/types_algorand_client_sender.md#sendsingletransactionresult)\> + +Opt an account out of an Algorand Standard Asset. + +*Note:* If the account has a balance of the asset, +it will not be able to opt-out unless `ensureZeroBalance` +is set to `false` (but then the account will lose the assets). + +#### Parameters + +| Name | Type | Description | +| :------ | :------ | :------ | +| `params` | `Omit`\<[`AssetOptOutParams`](../modules/types_composer.md#assetoptoutparams), ``"creator"``\> & \{ `creator?`: `string` ; `ensureZeroBalance`: `boolean` } & [`ExecuteParams`](../interfaces/types_composer.ExecuteParams.md) | The parameters for the asset opt-out transaction | + +#### Returns + +`Promise`\<[`SendSingleTransactionResult`](../modules/types_algorand_client_sender.md#sendsingletransactionresult)\> + +The result of the transaction and the transaction that was sent + +**`Example`** + +```typescript +await algorand.send.assetOptOut({sender: "SENDERADDRESS", assetId: 123456n, ensureZeroBalance: true }) +``` + +**`Example`** + +```typescript +await algorand.send.assetOptOut({sender: "SENDERADDRESS", creator: "CREATORADDRESS", assetId: 123456n, ensureZeroBalance: true }) +``` + +**`Example`** + +```typescript +await algorand.send.assetOptOut({ + sender: 'SENDERADDRESS', + assetId: 123456n, + creator: 'CREATORADDRESS', + ensureZeroBalance: true, + lease: 'lease', + note: 'note', + // You wouldn't normally set this field + firstValidRound: 1000n, + validityWindow: 10, + extraFee: (1000).microAlgos(), + staticFee: (1000).microAlgos(), + // Max fee doesn't make sense with extraFee AND staticFee + // already specified, but here for completeness + maxFee: (3000).microAlgos(), + // Signer only needed if you want to provide one, + // generally you'd register it with AlgorandClient + // against the sender and not need to pass it in + signer: transactionSigner, + maxRoundsToWaitForConfirmation: 5, + suppressLog: true, +}) +``` + +#### Defined in + +[src/types/algorand-client-sender.ts:410](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/algorand-client-sender.ts#L410) diff --git a/docs/code/classes/types_algorand_client_transaction_creator.AlgorandClientTransactionCreator.md b/docs/code/classes/types_algorand_client_transaction_creator.AlgorandClientTransactionCreator.md new file mode 100644 index 00000000..e963cad8 --- /dev/null +++ b/docs/code/classes/types_algorand_client_transaction_creator.AlgorandClientTransactionCreator.md @@ -0,0 +1,637 @@ +[@algorandfoundation/algokit-utils](../README.md) / [types/algorand-client-transaction-creator](../modules/types_algorand_client_transaction_creator.md) / AlgorandClientTransactionCreator + +# Class: AlgorandClientTransactionCreator + +[types/algorand-client-transaction-creator](../modules/types_algorand_client_transaction_creator.md).AlgorandClientTransactionCreator + +Orchestrates sending transactions for `AlgorandClient`. + +## Table of contents + +### Constructors + +- [constructor](types_algorand_client_transaction_creator.AlgorandClientTransactionCreator.md#constructor) + +### Properties + +- [\_newGroup](types_algorand_client_transaction_creator.AlgorandClientTransactionCreator.md#_newgroup) +- [appCall](types_algorand_client_transaction_creator.AlgorandClientTransactionCreator.md#appcall) +- [assetConfig](types_algorand_client_transaction_creator.AlgorandClientTransactionCreator.md#assetconfig) +- [assetCreate](types_algorand_client_transaction_creator.AlgorandClientTransactionCreator.md#assetcreate) +- [assetDestroy](types_algorand_client_transaction_creator.AlgorandClientTransactionCreator.md#assetdestroy) +- [assetFreeze](types_algorand_client_transaction_creator.AlgorandClientTransactionCreator.md#assetfreeze) +- [assetOptIn](types_algorand_client_transaction_creator.AlgorandClientTransactionCreator.md#assetoptin) +- [assetOptOut](types_algorand_client_transaction_creator.AlgorandClientTransactionCreator.md#assetoptout) +- [assetTransfer](types_algorand_client_transaction_creator.AlgorandClientTransactionCreator.md#assettransfer) +- [onlineKeyRegistration](types_algorand_client_transaction_creator.AlgorandClientTransactionCreator.md#onlinekeyregistration) +- [payment](types_algorand_client_transaction_creator.AlgorandClientTransactionCreator.md#payment) + +### Methods + +- [\_transaction](types_algorand_client_transaction_creator.AlgorandClientTransactionCreator.md#_transaction) +- [methodCall](types_algorand_client_transaction_creator.AlgorandClientTransactionCreator.md#methodcall) + +## Constructors + +### constructor + +• **new AlgorandClientTransactionCreator**(`newGroup`): [`AlgorandClientTransactionCreator`](types_algorand_client_transaction_creator.AlgorandClientTransactionCreator.md) + +Creates a new `AlgorandClientSender` + +#### Parameters + +| Name | Type | Description | +| :------ | :------ | :------ | +| `newGroup` | () => [`default`](types_composer.default.md) | A lambda that Start a new `AlgokitComposer` transaction group | + +#### Returns + +[`AlgorandClientTransactionCreator`](types_algorand_client_transaction_creator.AlgorandClientTransactionCreator.md) + +#### Defined in + +[src/types/algorand-client-transaction-creator.ts:15](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/algorand-client-transaction-creator.ts#L15) + +## Properties + +### \_newGroup + +• `Private` **\_newGroup**: () => [`default`](types_composer.default.md) + +#### Type declaration + +▸ (): [`default`](types_composer.default.md) + +##### Returns + +[`default`](types_composer.default.md) + +#### Defined in + +[src/types/algorand-client-transaction-creator.ts:8](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/algorand-client-transaction-creator.ts#L8) + +___ + +### appCall + +• **appCall**: (`params`: [`AppCallParams`](../modules/types_composer.md#appcallparams)) => `Promise`\<`Transaction`\> + +Create an application call transaction. + +#### Type declaration + +▸ (`params`): `Promise`\<`Transaction`\> + +##### Parameters + +| Name | Type | +| :------ | :------ | +| `params` | [`AppCallParams`](../modules/types_composer.md#appcallparams) | + +##### Returns + +`Promise`\<`Transaction`\> + +#### Defined in + +[src/types/algorand-client-transaction-creator.ts:297](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/algorand-client-transaction-creator.ts#L297) + +___ + +### assetConfig + +• **assetConfig**: (`params`: [`AssetConfigParams`](../modules/types_composer.md#assetconfigparams)) => `Promise`\<`Transaction`\> + +Create an asset config transaction to reconfigure an existing Algorand Standard Asset. + +**Note:** The manager, reserve, freeze, and clawback addresses +are immutably empty if they are not set. If manager is not set then +all fields are immutable from that point forward. + +**`Example`** + +```typescript +await algorand.transaction.assetConfig({sender: "MANAGERADDRESS", assetId: 123456n, manager: "MANAGERADDRESS" }) +``` + +**`Example`** + +```typescript +await algorand.transaction.assetConfig({ + sender: 'MANAGERADDRESS', + assetId: 123456n, + manager: 'MANAGERADDRESS', + reserve: 'RESERVEADDRESS', + freeze: 'FREEZEADDRESS', + clawback: 'CLAWBACKADDRESS', + lease: 'lease', + note: 'note', + // You wouldn't normally set this field + firstValidRound: 1000n, + validityWindow: 10, + extraFee: (1000).microAlgos(), + staticFee: (1000).microAlgos(), + // Max fee doesn't make sense with extraFee AND staticFee + // already specified, but here for completeness + maxFee: (3000).microAlgos(), +}) +``` + +#### Type declaration + +▸ (`params`): `Promise`\<`Transaction`\> + +##### Parameters + +| Name | Type | Description | +| :------ | :------ | :------ | +| `params` | [`AssetConfigParams`](../modules/types_composer.md#assetconfigparams) | The parameters for the asset config transaction | + +##### Returns + +`Promise`\<`Transaction`\> + +#### Defined in + +[src/types/algorand-client-transaction-creator.ts:139](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/algorand-client-transaction-creator.ts#L139) + +___ + +### assetCreate + +• **assetCreate**: (`params`: [`AssetCreateParams`](../modules/types_composer.md#assetcreateparams)) => `Promise`\<`Transaction`\> + +Create a create Algorand Standard Asset transaction. + +The account that sends this transaction will automatically be +opted in to the asset and will hold all units after creation. + +**`Example`** + +```typescript +await algorand.transaction.assetCreate({sender: "CREATORADDRESS", total: 100n}) +``` + +**`Example`** + +```typescript +await algorand.transaction.assetCreate({ + sender: 'CREATORADDRESS', + total: 100n, + decimals: 2, + assetName: 'asset', + unitName: 'unit', + url: 'url', + metadataHash: 'metadataHash', + defaultFrozen: false, + manager: 'MANAGERADDRESS', + reserve: 'RESERVEADDRESS', + freeze: 'FREEZEADDRESS', + clawback: 'CLAWBACKADDRESS', + lease: 'lease', + note: 'note', + // You wouldn't normally set this field + firstValidRound: 1000n, + validityWindow: 10, + extraFee: (1000).microAlgos(), + staticFee: (1000).microAlgos(), + // Max fee doesn't make sense with extraFee AND staticFee + // already specified, but here for completeness + maxFee: (3000).microAlgos(), +}) +``` + +#### Type declaration + +▸ (`params`): `Promise`\<`Transaction`\> + +##### Parameters + +| Name | Type | Description | +| :------ | :------ | :------ | +| `params` | [`AssetCreateParams`](../modules/types_composer.md#assetcreateparams) | The parameters for the asset creation transaction | + +##### Returns + +`Promise`\<`Transaction`\> + +#### Defined in + +[src/types/algorand-client-transaction-creator.ts:103](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/algorand-client-transaction-creator.ts#L103) + +___ + +### assetDestroy + +• **assetDestroy**: (`params`: [`AssetDestroyParams`](../modules/types_composer.md#assetdestroyparams)) => `Promise`\<`Transaction`\> + +Create an Algorand Standard Asset destroy transaction. + +Created assets can be destroyed only by the asset manager account. +All of the assets must be owned by the creator of the asset before +the asset can be deleted. + +**`Example`** + +```typescript +await algorand.transaction.assetDestroy({sender: "MANAGERADDRESS", assetId: 123456n }) +``` + +**`Example`** + +```typescript +await algorand.transaction.assetDestroy({ + sender: 'MANAGERADDRESS', + assetId: 123456n, + lease: 'lease', + note: 'note', + // You wouldn't normally set this field + firstValidRound: 1000n, + validityWindow: 10, + extraFee: (1000).microAlgos(), + staticFee: (1000).microAlgos(), + // Max fee doesn't make sense with extraFee AND staticFee + // already specified, but here for completeness + maxFee: (3000).microAlgos(), +}) +``` + +#### Type declaration + +▸ (`params`): `Promise`\<`Transaction`\> + +##### Parameters + +| Name | Type | Description | +| :------ | :------ | :------ | +| `params` | [`AssetDestroyParams`](../modules/types_composer.md#assetdestroyparams) | The parameters for the asset destroy transaction | + +##### Returns + +`Promise`\<`Transaction`\> + +#### Defined in + +[src/types/algorand-client-transaction-creator.ts:201](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/algorand-client-transaction-creator.ts#L201) + +___ + +### assetFreeze + +• **assetFreeze**: (`params`: [`AssetFreezeParams`](../modules/types_composer.md#assetfreezeparams)) => `Promise`\<`Transaction`\> + +Create an Algorand Standard Asset freeze transaction. + +**`Example`** + +```typescript +await algorand.transaction.assetFreeze({sender: "MANAGERADDRESS", assetId: 123456n, account: "ACCOUNTADDRESS", frozen: true }) +``` + +**`Example`** + +```typescript +await algorand.transaction.assetFreeze({ + sender: 'MANAGERADDRESS', + assetId: 123456n, + account: 'ACCOUNTADDRESS', + frozen: true, + lease: 'lease', + note: 'note', + // You wouldn't normally set this field + firstValidRound: 1000n, + validityWindow: 10, + extraFee: (1000).microAlgos(), + staticFee: (1000).microAlgos(), + // Max fee doesn't make sense with extraFee AND staticFee + // already specified, but here for completeness + maxFee: (3000).microAlgos(), +}) +``` + +#### Type declaration + +▸ (`params`): `Promise`\<`Transaction`\> + +##### Parameters + +| Name | Type | Description | +| :------ | :------ | :------ | +| `params` | [`AssetFreezeParams`](../modules/types_composer.md#assetfreezeparams) | The parameters for the asset freeze transaction | + +##### Returns + +`Promise`\<`Transaction`\> + +#### Defined in + +[src/types/algorand-client-transaction-creator.ts:169](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/algorand-client-transaction-creator.ts#L169) + +___ + +### assetOptIn + +• **assetOptIn**: (`params`: [`AssetOptInParams`](../modules/types_composer.md#assetoptinparams)) => `Promise`\<`Transaction`\> + +Create an Algorand Standard Asset opt-in transaction. + +**`Example`** + +```typescript +await algorand.transaction.assetOptIn({sender: "SENDERADDRESS", assetId: 123456n }) +``` + +**`Example`** + +```typescript +await algorand.transaction.assetOptIn({ + sender: 'SENDERADDRESS', + assetId: 123456n, + lease: 'lease', + note: 'note', + // You wouldn't normally set this field + firstValidRound: 1000n, + validityWindow: 10, + extraFee: (1000).microAlgos(), + staticFee: (1000).microAlgos(), + // Max fee doesn't make sense with extraFee AND staticFee + // already specified, but here for completeness + maxFee: (3000).microAlgos(), +}) +``` + +#### Type declaration + +▸ (`params`): `Promise`\<`Transaction`\> + +##### Parameters + +| Name | Type | Description | +| :------ | :------ | :------ | +| `params` | [`AssetOptInParams`](../modules/types_composer.md#assetoptinparams) | The parameters for the asset opt-in transaction | + +##### Returns + +`Promise`\<`Transaction`\> + +#### Defined in + +[src/types/algorand-client-transaction-creator.ts:262](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/algorand-client-transaction-creator.ts#L262) + +___ + +### assetOptOut + +• **assetOptOut**: (`params`: [`AssetOptOutParams`](../modules/types_composer.md#assetoptoutparams)) => `Promise`\<`Transaction`\> + +Create an asset opt-out transaction. + +*Note:* If the account has a balance of the asset, +it will lose those assets + +**`Example`** + +```typescript +await algorand.transaction.assetOptOut({sender: "SENDERADDRESS", creator: "CREATORADDRESS", assetId: 123456n }) +``` + +**`Example`** + +```typescript +await algorand.transaction.assetOptIn({ + sender: 'SENDERADDRESS', + assetId: 123456n, + creator: 'CREATORADDRESS', + ensureZeroBalance: true, + lease: 'lease', + note: 'note', + // You wouldn't normally set this field + firstValidRound: 1000n, + validityWindow: 10, + extraFee: (1000).microAlgos(), + staticFee: (1000).microAlgos(), + // Max fee doesn't make sense with extraFee AND staticFee + // already specified, but here for completeness + maxFee: (3000).microAlgos(), +}) +``` + +#### Type declaration + +▸ (`params`): `Promise`\<`Transaction`\> + +##### Parameters + +| Name | Type | Description | +| :------ | :------ | :------ | +| `params` | [`AssetOptOutParams`](../modules/types_composer.md#assetoptoutparams) | The parameters for the asset opt-out transaction | + +##### Returns + +`Promise`\<`Transaction`\> + +#### Defined in + +[src/types/algorand-client-transaction-creator.ts:295](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/algorand-client-transaction-creator.ts#L295) + +___ + +### assetTransfer + +• **assetTransfer**: (`params`: [`AssetTransferParams`](../modules/types_composer.md#assettransferparams)) => `Promise`\<`Transaction`\> + +Create an Algorand Standard Asset transfer transaction. + +**`Example`** + +```typescript +await algorand.transaction.assetTransfer({sender: "HOLDERADDRESS", assetId: 123456n, amount: 1n, receiver: "RECEIVERADDRESS" }) +``` + +**`Example`** + +```typescript +await algorand.transaction.assetTransfer({ + sender: 'CLAWBACKADDRESS', + assetId: 123456n, + amount: 1n, + receiver: 'RECEIVERADDRESS', + clawbackTarget: 'HOLDERADDRESS', + // This field needs to be used with caution + closeAssetTo: 'ADDRESSTOCLOSETO' + lease: 'lease', + note: 'note', + // You wouldn't normally set this field + firstValidRound: 1000n, + validityWindow: 10, + extraFee: (1000).microAlgos(), + staticFee: (1000).microAlgos(), + // Max fee doesn't make sense with extraFee AND staticFee + // already specified, but here for completeness + maxFee: (3000).microAlgos(), +}) +``` + +#### Type declaration + +▸ (`params`): `Promise`\<`Transaction`\> + +##### Parameters + +| Name | Type | Description | +| :------ | :------ | :------ | +| `params` | [`AssetTransferParams`](../modules/types_composer.md#assettransferparams) | The parameters for the asset transfer transaction | + +##### Returns + +`Promise`\<`Transaction`\> + +#### Defined in + +[src/types/algorand-client-transaction-creator.ts:234](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/algorand-client-transaction-creator.ts#L234) + +___ + +### onlineKeyRegistration + +• **onlineKeyRegistration**: (`params`: [`OnlineKeyRegistrationParams`](../modules/types_composer.md#onlinekeyregistrationparams)) => `Promise`\<`Transaction`\> + +Create an online key registration transaction. + +#### Type declaration + +▸ (`params`): `Promise`\<`Transaction`\> + +##### Parameters + +| Name | Type | +| :------ | :------ | +| `params` | [`OnlineKeyRegistrationParams`](../modules/types_composer.md#onlinekeyregistrationparams) | + +##### Returns + +`Promise`\<`Transaction`\> + +#### Defined in + +[src/types/algorand-client-transaction-creator.ts:303](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/algorand-client-transaction-creator.ts#L303) + +___ + +### payment + +• **payment**: (`params`: [`PaymentParams`](../modules/types_composer.md#paymentparams)) => `Promise`\<`Transaction`\> + +Create a payment transaction to transfer Algo between accounts. + +**`Example`** + +```typescript +const result = await algorandClient.send.payment({ + sender: 'SENDERADDRESS', + receiver: 'RECEIVERADDRESS', + amount: (4).algos(), +}) +``` + +**`Example`** + +```typescript +const result = await algorandClient.send.payment({ + amount: (4).algos(), + receiver: 'RECEIVERADDRESS', + sender: 'SENDERADDRESS', + closeRemainderTo: 'CLOSEREMAINDERTOADDRESS', + lease: 'lease', + note: 'note', + // Use this with caution, it's generally better to use algorand.account.rekeyAccount + rekeyTo: 'REKEYTOADDRESS', + // You wouldn't normally set this field + firstValidRound: 1000n, + validityWindow: 10, + extraFee: (1000).microAlgos(), + staticFee: (1000).microAlgos(), + // Max fee doesn't make sense with extraFee AND staticFee + // already specified, but here for completeness + maxFee: (3000).microAlgos(), +}) +``` + +#### Type declaration + +▸ (`params`): `Promise`\<`Transaction`\> + +##### Parameters + +| Name | Type | Description | +| :------ | :------ | :------ | +| `params` | [`PaymentParams`](../modules/types_composer.md#paymentparams) | The parameters for the payment transaction | + +##### Returns + +`Promise`\<`Transaction`\> + +#### Defined in + +[src/types/algorand-client-transaction-creator.ts:62](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/algorand-client-transaction-creator.ts#L62) + +## Methods + +### \_transaction + +▸ **_transaction**\<`T`\>(`c`): (`params`: `T`) => `Promise`\<`Transaction`\> + +#### Type parameters + +| Name | +| :------ | +| `T` | + +#### Parameters + +| Name | Type | +| :------ | :------ | +| `c` | (`c`: [`default`](types_composer.default.md)) => (`params`: `T`) => [`default`](types_composer.default.md) | + +#### Returns + +`fn` + +▸ (`params`): `Promise`\<`Transaction`\> + +##### Parameters + +| Name | Type | +| :------ | :------ | +| `params` | `T` | + +##### Returns + +`Promise`\<`Transaction`\> + +#### Defined in + +[src/types/algorand-client-transaction-creator.ts:19](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/algorand-client-transaction-creator.ts#L19) + +___ + +### methodCall + +▸ **methodCall**(`params`): `Promise`\<`Transaction`[]\> + +Create an application call with ABI method call transaction. + +#### Parameters + +| Name | Type | +| :------ | :------ | +| `params` | [`MethodCallParams`](../modules/types_composer.md#methodcallparams) | + +#### Returns + +`Promise`\<`Transaction`[]\> + +#### Defined in + +[src/types/algorand-client-transaction-creator.ts:299](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/algorand-client-transaction-creator.ts#L299) diff --git a/docs/code/classes/types_app_client.ApplicationClient.md b/docs/code/classes/types_app_client.ApplicationClient.md index 633c88b9..8434f26b 100644 --- a/docs/code/classes/types_app_client.ApplicationClient.md +++ b/docs/code/classes/types_app_client.ApplicationClient.md @@ -451,7 +451,7 @@ The new error, or if there was no logic error or source map then the wrapped err #### Defined in -[src/types/app-client.ts:1008](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/app-client.ts#L1008) +[src/types/app-client.ts:1009](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/app-client.ts#L1009) ___ @@ -499,7 +499,7 @@ The ABI method for the given method #### Defined in -[src/types/app-client.ts:967](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/app-client.ts#L967) +[src/types/app-client.ts:968](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/app-client.ts#L968) ___ @@ -523,7 +523,7 @@ The ABI method params for the given method #### Defined in -[src/types/app-client.ts:945](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/app-client.ts#L945) +[src/types/app-client.ts:946](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/app-client.ts#L946) ___ @@ -542,7 +542,7 @@ The app reference, or if deployed using the `deploy` method, the app metadata to #### Defined in -[src/types/app-client.ts:977](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/app-client.ts#L977) +[src/types/app-client.ts:978](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/app-client.ts#L978) ___ @@ -560,7 +560,7 @@ The names of the boxes #### Defined in -[src/types/app-client.ts:786](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/app-client.ts#L786) +[src/types/app-client.ts:787](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/app-client.ts#L787) ___ @@ -584,7 +584,7 @@ The current box value as a byte array #### Defined in -[src/types/app-client.ts:801](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/app-client.ts#L801) +[src/types/app-client.ts:802](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/app-client.ts#L802) ___ @@ -609,7 +609,7 @@ The current box value as a byte array #### Defined in -[src/types/app-client.ts:817](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/app-client.ts#L817) +[src/types/app-client.ts:818](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/app-client.ts#L818) ___ @@ -634,7 +634,7 @@ The (name, value) pair of the boxes with values as raw byte arrays #### Defined in -[src/types/app-client.ts:833](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/app-client.ts#L833) +[src/types/app-client.ts:834](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/app-client.ts#L834) ___ @@ -660,7 +660,7 @@ The (name, value) pair of the boxes with values as the ABI Value #### Defined in -[src/types/app-client.ts:855](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/app-client.ts#L855) +[src/types/app-client.ts:856](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/app-client.ts#L856) ___ @@ -685,7 +685,7 @@ The call args ready to pass into an app call #### Defined in -[src/types/app-client.ts:877](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/app-client.ts#L877) +[src/types/app-client.ts:878](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/app-client.ts#L878) ___ @@ -703,7 +703,7 @@ The global state #### Defined in -[src/types/app-client.ts:758](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/app-client.ts#L758) +[src/types/app-client.ts:759](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/app-client.ts#L759) ___ @@ -727,7 +727,7 @@ The global state #### Defined in -[src/types/app-client.ts:772](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/app-client.ts#L772) +[src/types/app-client.ts:773](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/app-client.ts#L773) ___ diff --git a/docs/code/classes/types_asset_manager.AssetManager.md b/docs/code/classes/types_asset_manager.AssetManager.md index febe3c03..71b697a0 100644 --- a/docs/code/classes/types_asset_manager.AssetManager.md +++ b/docs/code/classes/types_asset_manager.AssetManager.md @@ -14,12 +14,11 @@ Allows management of asset information. ### Properties -- [\_accountManager](types_asset_manager.AssetManager.md#_accountmanager) -- [\_clientManager](types_asset_manager.AssetManager.md#_clientmanager) +- [\_algod](types_asset_manager.AssetManager.md#_algod) +- [\_newGroup](types_asset_manager.AssetManager.md#_newgroup) ### Methods -- [\_getComposer](types_asset_manager.AssetManager.md#_getcomposer) - [bulkOptIn](types_asset_manager.AssetManager.md#bulkoptin) - [bulkOptOut](types_asset_manager.AssetManager.md#bulkoptout) - [getAccountInformation](types_asset_manager.AssetManager.md#getaccountinformation) @@ -29,7 +28,7 @@ Allows management of asset information. ### constructor -• **new AssetManager**(`clientManager`, `accountManager`): [`AssetManager`](types_asset_manager.AssetManager.md) +• **new AssetManager**(`algod`, `newGroup`): [`AssetManager`](types_asset_manager.AssetManager.md) Create a new asset manager. @@ -37,8 +36,8 @@ Create a new asset manager. | Name | Type | Description | | :------ | :------ | :------ | -| `clientManager` | [`ClientManager`](types_client_manager.ClientManager.md) | The ClientManager client to use for algod client | -| `accountManager` | [`AccountManager`](types_account_manager.AccountManager.md) | - | +| `algod` | `default` | An algod client | +| `newGroup` | () => [`default`](types_composer.default.md) | A function that creates a new `AlgoKitComposer` transaction group | #### Returns @@ -47,54 +46,42 @@ Create a new asset manager. **`Example`** ```typescript -const assetManager = new AssetManager(clientManager) +const assetManager = new AssetManager(algod, () => new AlgoKitComposer({algod, () => signer, () => suggestedParams})) ``` #### Defined in -[src/types/asset-manager.ts:152](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/asset-manager.ts#L152) +[src/types/asset-manager.ts:151](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/asset-manager.ts#L151) ## Properties -### \_accountManager +### \_algod -• `Private` **\_accountManager**: [`AccountManager`](types_account_manager.AccountManager.md) +• `Private` **\_algod**: `default` #### Defined in -[src/types/asset-manager.ts:142](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/asset-manager.ts#L142) +[src/types/asset-manager.ts:139](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/asset-manager.ts#L139) ___ -### \_clientManager +### \_newGroup -• `Private` **\_clientManager**: [`ClientManager`](types_client_manager.ClientManager.md) +• `Private` **\_newGroup**: () => [`default`](types_composer.default.md) -#### Defined in - -[src/types/asset-manager.ts:141](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/asset-manager.ts#L141) - -## Methods - -### \_getComposer +#### Type declaration -▸ **_getComposer**(`getSuggestedParams?`): [`default`](types_composer.default.md) +▸ (): [`default`](types_composer.default.md) -#### Parameters - -| Name | Type | -| :------ | :------ | -| `getSuggestedParams?` | () => `Promise`\<`SuggestedParams`\> | - -#### Returns +##### Returns [`default`](types_composer.default.md) #### Defined in -[src/types/asset-manager.ts:157](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/asset-manager.ts#L157) +[src/types/asset-manager.ts:140](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/asset-manager.ts#L140) -___ +## Methods ### bulkOptIn @@ -129,7 +116,7 @@ algorand.asset.bulkOptIn("ACCOUNTADDRESS", [12345n, 67890n], { maxFee: (1000).mi #### Defined in -[src/types/asset-manager.ts:244](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/asset-manager.ts#L244) +[src/types/asset-manager.ts:233](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/asset-manager.ts#L233) ___ @@ -166,7 +153,7 @@ algorand.asset.bulkOptOut("ACCOUNTADDRESS", [12345n, 67890n], { ensureZeroBalanc #### Defined in -[src/types/asset-manager.ts:296](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/asset-manager.ts#L296) +[src/types/asset-manager.ts:283](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/asset-manager.ts#L283) ___ @@ -201,7 +188,7 @@ const accountInfo = await algorand.asset.getAccountInformation(address, assetId) #### Defined in -[src/types/asset-manager.ts:214](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/asset-manager.ts#L214) +[src/types/asset-manager.ts:205](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/asset-manager.ts#L205) ___ @@ -231,4 +218,4 @@ const assetInfo = await assetManager.getById(12353n); #### Defined in -[src/types/asset-manager.ts:176](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/asset-manager.ts#L176) +[src/types/asset-manager.ts:167](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/asset-manager.ts#L167) diff --git a/docs/code/classes/types_composer.default.md b/docs/code/classes/types_composer.default.md index 4f9d22e6..b4a28fa3 100644 --- a/docs/code/classes/types_composer.default.md +++ b/docs/code/classes/types_composer.default.md @@ -48,7 +48,9 @@ AlgoKit Composer helps you compose and execute transactions as a transaction gro - [buildKeyReg](types_composer.default.md#buildkeyreg) - [buildMethodCall](types_composer.default.md#buildmethodcall) - [buildPayment](types_composer.default.md#buildpayment) +- [buildTransactions](types_composer.default.md#buildtransactions) - [buildTxn](types_composer.default.md#buildtxn) +- [buildTxnWithSigner](types_composer.default.md#buildtxnwithsigner) - [commonTxnBuildStep](types_composer.default.md#commontxnbuildstep) - [execute](types_composer.default.md#execute) - [rebuild](types_composer.default.md#rebuild) @@ -503,7 +505,7 @@ The built atomic transaction composer and the transactions #### Defined in -[src/types/composer.ts:914](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/composer.ts#L914) +[src/types/composer.ts:921](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/composer.ts#L921) ___ @@ -524,7 +526,7 @@ ___ #### Defined in -[src/types/composer.ts:786](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/composer.ts#L786) +[src/types/composer.ts:789](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/composer.ts#L789) ___ @@ -545,7 +547,7 @@ ___ #### Defined in -[src/types/composer.ts:735](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/composer.ts#L735) +[src/types/composer.ts:738](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/composer.ts#L738) ___ @@ -566,7 +568,7 @@ ___ #### Defined in -[src/types/composer.ts:715](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/composer.ts#L715) +[src/types/composer.ts:718](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/composer.ts#L718) ___ @@ -587,7 +589,7 @@ ___ #### Defined in -[src/types/composer.ts:750](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/composer.ts#L750) +[src/types/composer.ts:753](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/composer.ts#L753) ___ @@ -608,7 +610,7 @@ ___ #### Defined in -[src/types/composer.ts:760](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/composer.ts#L760) +[src/types/composer.ts:763](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/composer.ts#L763) ___ @@ -629,7 +631,7 @@ ___ #### Defined in -[src/types/composer.ts:772](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/composer.ts#L772) +[src/types/composer.ts:775](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/composer.ts#L775) ___ @@ -670,13 +672,13 @@ ___ #### Defined in -[src/types/composer.ts:826](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/composer.ts#L826) +[src/types/composer.ts:829](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/composer.ts#L829) ___ ### buildMethodCall -▸ **buildMethodCall**(`params`, `suggestedParams`): `Promise`\<`TransactionWithSigner`[]\> +▸ **buildMethodCall**(`params`, `suggestedParams`, `includeSigner`): `Promise`\<`TransactionWithSigner`[]\> #### Parameters @@ -684,6 +686,7 @@ ___ | :------ | :------ | | `params` | [`MethodCallParams`](../modules/types_composer.md#methodcallparams) | | `suggestedParams` | `SuggestedParams` | +| `includeSigner` | `boolean` | #### Returns @@ -712,13 +715,52 @@ ___ #### Defined in -[src/types/composer.ts:703](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/composer.ts#L703) +[src/types/composer.ts:706](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/composer.ts#L706) + +___ + +### buildTransactions + +▸ **buildTransactions**(): `Promise`\<`Transaction`[]\> + +Compose all of the transactions without signers and return the transaction objects directly. + +#### Returns + +`Promise`\<`Transaction`[]\> + +The array of built transactions + +#### Defined in + +[src/types/composer.ts:903](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/composer.ts#L903) ___ ### buildTxn -▸ **buildTxn**(`txn`, `suggestedParams`): `Promise`\<`TransactionWithSigner`[]\> +▸ **buildTxn**(`txn`, `suggestedParams`): `Promise`\<`Transaction`[]\> + +#### Parameters + +| Name | Type | +| :------ | :------ | +| `txn` | `Txn` | +| `suggestedParams` | `SuggestedParams` | + +#### Returns + +`Promise`\<`Transaction`[]\> + +#### Defined in + +[src/types/composer.ts:847](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/composer.ts#L847) + +___ + +### buildTxnWithSigner + +▸ **buildTxnWithSigner**(`txn`, `suggestedParams`): `Promise`\<`TransactionWithSigner`[]\> #### Parameters @@ -733,7 +775,7 @@ ___ #### Defined in -[src/types/composer.ts:844](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/composer.ts#L844) +[src/types/composer.ts:880](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/composer.ts#L880) ___ @@ -779,7 +821,7 @@ The execution result #### Defined in -[src/types/composer.ts:956](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/composer.ts#L956) +[src/types/composer.ts:963](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/composer.ts#L963) ___ @@ -798,4 +840,4 @@ The newly built atomic transaction composer and the transactions #### Defined in -[src/types/composer.ts:946](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/composer.ts#L946) +[src/types/composer.ts:953](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/composer.ts#L953) diff --git a/docs/code/interfaces/types_asset_manager.AssetInformation.md b/docs/code/interfaces/types_asset_manager.AssetInformation.md index 0d4e47b7..206d187e 100644 --- a/docs/code/interfaces/types_asset_manager.AssetInformation.md +++ b/docs/code/interfaces/types_asset_manager.AssetInformation.md @@ -37,7 +37,7 @@ The ID of the asset. #### Defined in -[src/types/asset-manager.ts:21](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/asset-manager.ts#L21) +[src/types/asset-manager.ts:19](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/asset-manager.ts#L19) ___ @@ -51,7 +51,7 @@ Max size is 32 bytes. #### Defined in -[src/types/asset-manager.ts:112](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/asset-manager.ts#L112) +[src/types/asset-manager.ts:110](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/asset-manager.ts#L110) ___ @@ -65,7 +65,7 @@ Max size is 32 bytes. #### Defined in -[src/types/asset-manager.ts:118](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/asset-manager.ts#L118) +[src/types/asset-manager.ts:116](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/asset-manager.ts#L116) ___ @@ -83,7 +83,7 @@ If not set the field is permanently empty. #### Defined in -[src/types/asset-manager.ts:94](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/asset-manager.ts#L94) +[src/types/asset-manager.ts:92](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/asset-manager.ts#L92) ___ @@ -99,7 +99,7 @@ closing out an asset position and opting-out of the asset. #### Defined in -[src/types/asset-manager.ts:29](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/asset-manager.ts#L29) +[src/types/asset-manager.ts:27](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/asset-manager.ts#L27) ___ @@ -117,7 +117,7 @@ The amount of decimal places the asset was created with. #### Defined in -[src/types/asset-manager.ts:45](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/asset-manager.ts#L45) +[src/types/asset-manager.ts:43](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/asset-manager.ts#L43) ___ @@ -133,7 +133,7 @@ transaction from the `freeze` account. #### Defined in -[src/types/asset-manager.ts:53](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/asset-manager.ts#L53) +[src/types/asset-manager.ts:51](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/asset-manager.ts#L51) ___ @@ -149,7 +149,7 @@ If not set the field is permanently empty. #### Defined in -[src/types/asset-manager.ts:83](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/asset-manager.ts#L83) +[src/types/asset-manager.ts:81](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/asset-manager.ts#L81) ___ @@ -163,7 +163,7 @@ If not set the asset is permanently immutable. #### Defined in -[src/types/asset-manager.ts:59](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/asset-manager.ts#L59) +[src/types/asset-manager.ts:57](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/asset-manager.ts#L57) ___ @@ -177,7 +177,7 @@ The format of this metadata is up to the application. #### Defined in -[src/types/asset-manager.ts:136](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/asset-manager.ts#L136) +[src/types/asset-manager.ts:134](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/asset-manager.ts#L134) ___ @@ -199,7 +199,7 @@ If not set the field is permanently empty. #### Defined in -[src/types/asset-manager.ts:74](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/asset-manager.ts#L74) +[src/types/asset-manager.ts:72](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/asset-manager.ts#L72) ___ @@ -213,7 +213,7 @@ For example, if `decimals` is, say, 2, then for every 100 `total` there is 1 who #### Defined in -[src/types/asset-manager.ts:35](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/asset-manager.ts#L35) +[src/types/asset-manager.ts:33](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/asset-manager.ts#L33) ___ @@ -227,7 +227,7 @@ Max size is 8 bytes. #### Defined in -[src/types/asset-manager.ts:100](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/asset-manager.ts#L100) +[src/types/asset-manager.ts:98](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/asset-manager.ts#L98) ___ @@ -241,7 +241,7 @@ Max size is 8 bytes. #### Defined in -[src/types/asset-manager.ts:106](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/asset-manager.ts#L106) +[src/types/asset-manager.ts:104](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/asset-manager.ts#L104) ___ @@ -255,7 +255,7 @@ Max size is 96 bytes. #### Defined in -[src/types/asset-manager.ts:124](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/asset-manager.ts#L124) +[src/types/asset-manager.ts:122](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/asset-manager.ts#L122) ___ @@ -269,4 +269,4 @@ Max size is 96 bytes. #### Defined in -[src/types/asset-manager.ts:130](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/asset-manager.ts#L130) +[src/types/asset-manager.ts:128](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/asset-manager.ts#L128) diff --git a/docs/code/interfaces/types_asset_manager.BulkAssetOptInOutResult.md b/docs/code/interfaces/types_asset_manager.BulkAssetOptInOutResult.md index bc9ce521..1297e837 100644 --- a/docs/code/interfaces/types_asset_manager.BulkAssetOptInOutResult.md +++ b/docs/code/interfaces/types_asset_manager.BulkAssetOptInOutResult.md @@ -23,7 +23,7 @@ The ID of the asset opted into / out of #### Defined in -[src/types/asset-manager.ts:13](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/asset-manager.ts#L13) +[src/types/asset-manager.ts:11](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/asset-manager.ts#L11) ___ @@ -35,4 +35,4 @@ The transaction ID of the resulting opt in / out #### Defined in -[src/types/asset-manager.ts:15](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/asset-manager.ts#L15) +[src/types/asset-manager.ts:13](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/asset-manager.ts#L13) diff --git a/docs/code/modules/index.md b/docs/code/modules/index.md index bab7972c..f8c32d86 100644 --- a/docs/code/modules/index.md +++ b/docs/code/modules/index.md @@ -278,7 +278,7 @@ algokit.bulkOptIn({ account: account, assetIds: [12345, 67890] }, algod) #### Defined in -[src/asset.ts:132](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/asset.ts#L132) +[src/asset.ts:131](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/asset.ts#L131) ___ @@ -317,7 +317,7 @@ algokit.bulkOptOut({ account: account, assetIds: [12345, 67890] }, algod) #### Defined in -[src/asset.ts:162](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/asset.ts#L162) +[src/asset.ts:159](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/asset.ts#L159) ___ @@ -352,7 +352,7 @@ await algokit.assetOptIn({ account, assetId }, algod) #### Defined in -[src/asset.ts:69](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/asset.ts#L69) +[src/asset.ts:68](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/asset.ts#L68) ___ @@ -387,7 +387,7 @@ await algokit.assetOptOut({ account, assetId, assetCreatorAddress }, algod) #### Defined in -[src/asset.ts:100](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/asset.ts#L100) +[src/asset.ts:99](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/asset.ts#L99) ___ @@ -553,7 +553,7 @@ await algokit.createAsset({ creator: account, total: 1, decimals: 0, name: 'My a #### Defined in -[src/asset.ts:25](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/asset.ts#L25) +[src/asset.ts:24](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/asset.ts#L24) ___ @@ -935,7 +935,7 @@ The account asset holding information **`Deprecated`** -Use `algorandClient.asset.getAccountInformation(sender, assetId)` or `new AssetManager(clientManager, accountManager).getAccountInformation(sender, assetId)` instead. +Use `algorandClient.asset.getAccountInformation(sender, assetId)` or `new AssetManager(...).getAccountInformation(sender, assetId)` instead. Returns the given sender account's asset holding for a given asset. diff --git a/docs/code/modules/types_algorand_client.md b/docs/code/modules/types_algorand_client.md index b72697e5..7b753e0e 100644 --- a/docs/code/modules/types_algorand_client.md +++ b/docs/code/modules/types_algorand_client.md @@ -12,24 +12,8 @@ - [AlgorandClient](../classes/types_algorand_client.AlgorandClient.md) -### Type Aliases - -- [SendSingleTransactionResult](types_algorand_client.md#sendsingletransactionresult) - ## References ### default Renames and re-exports [AlgorandClient](../classes/types_algorand_client.AlgorandClient.md) - -## Type Aliases - -### SendSingleTransactionResult - -Ƭ **SendSingleTransactionResult**: [`SendAtomicTransactionComposerResults`](../interfaces/types_transaction.SendAtomicTransactionComposerResults.md) & [`ConfirmedTransactionResult`](../interfaces/types_transaction.ConfirmedTransactionResult.md) - -Result from sending a single transaction. - -#### Defined in - -[src/types/algorand-client.ts:15](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/algorand-client.ts#L15) diff --git a/docs/code/modules/types_algorand_client_sender.md b/docs/code/modules/types_algorand_client_sender.md new file mode 100644 index 00000000..d179c2af --- /dev/null +++ b/docs/code/modules/types_algorand_client_sender.md @@ -0,0 +1,25 @@ +[@algorandfoundation/algokit-utils](../README.md) / types/algorand-client-sender + +# Module: types/algorand-client-sender + +## Table of contents + +### Classes + +- [AlgorandClientSender](../classes/types_algorand_client_sender.AlgorandClientSender.md) + +### Type Aliases + +- [SendSingleTransactionResult](types_algorand_client_sender.md#sendsingletransactionresult) + +## Type Aliases + +### SendSingleTransactionResult + +Ƭ **SendSingleTransactionResult**: [`SendAtomicTransactionComposerResults`](../interfaces/types_transaction.SendAtomicTransactionComposerResults.md) & [`ConfirmedTransactionResult`](../interfaces/types_transaction.ConfirmedTransactionResult.md) + +Result from sending a single transaction. + +#### Defined in + +[src/types/algorand-client-sender.ts:10](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/algorand-client-sender.ts#L10) diff --git a/docs/code/modules/types_algorand_client_transaction_creator.md b/docs/code/modules/types_algorand_client_transaction_creator.md new file mode 100644 index 00000000..e6433b17 --- /dev/null +++ b/docs/code/modules/types_algorand_client_transaction_creator.md @@ -0,0 +1,9 @@ +[@algorandfoundation/algokit-utils](../README.md) / types/algorand-client-transaction-creator + +# Module: types/algorand-client-transaction-creator + +## Table of contents + +### Classes + +- [AlgorandClientTransactionCreator](../classes/types_algorand_client_transaction_creator.AlgorandClientTransactionCreator.md) diff --git a/src/account/account.ts b/src/account/account.ts index cfbb1a2e..1b565fde 100644 --- a/src/account/account.ts +++ b/src/account/account.ts @@ -1,9 +1,9 @@ import algosdk from 'algosdk' +import { AlgorandClient } from '..' import { getSenderAddress } from '../transaction/transaction' import { AccountAssetInformation, MultisigAccount, SigningAccount, TransactionSignerAccount } from '../types/account' import { AccountManager } from '../types/account-manager' import { AlgoAmount } from '../types/amount' -import { AssetManager } from '../types/asset-manager' import { ClientManager } from '../types/client-manager' import { SendTransactionFrom } from '../types/transaction' import Account = algosdk.Account @@ -174,7 +174,7 @@ export async function getAccountInformation(sender: string | SendTransactionFrom } /** - * @deprecated Use `algorandClient.asset.getAccountInformation(sender, assetId)` or `new AssetManager(clientManager, accountManager).getAccountInformation(sender, assetId)` instead. + * @deprecated Use `algorandClient.asset.getAccountInformation(sender, assetId)` or `new AssetManager(...).getAccountInformation(sender, assetId)` instead. * * Returns the given sender account's asset holding for a given asset. * @@ -196,6 +196,5 @@ export async function getAccountAssetInformation( assetId: number | bigint, algod: Algodv2, ): Promise { - const clientManager = new ClientManager({ algod }) - return new AssetManager(clientManager, new AccountManager(clientManager)).getAccountInformation(getSenderAddress(sender), BigInt(assetId)) + return AlgorandClient.fromClients({ algod }).asset.getAccountInformation(getSenderAddress(sender), BigInt(assetId)) } diff --git a/src/asset.ts b/src/asset.ts index 254535c5..f7234a32 100644 --- a/src/asset.ts +++ b/src/asset.ts @@ -1,9 +1,8 @@ import algosdk from 'algosdk' +import { AlgorandClient } from '.' import { encodeTransactionNote, getSenderAddress } from './transaction' import { legacySendTransactionBridge } from './transaction/legacy-bridge' -import { AccountManager } from './types/account-manager' import { AssetBulkOptInOutParams, AssetOptInParams, AssetOptOutParams, CreateAssetParams } from './types/asset' -import { AssetManager } from './types/asset-manager' import { ClientManager } from './types/client-manager' import { AssetCreateParams, AssetOptInParams as NewAssetOptInParams, AssetOptOutParams as NewAssetOptOutParams } from './types/composer' import { SendTransactionResult } from './types/transaction' @@ -48,8 +47,8 @@ export async function createAsset( create.creator, create, params, - (client) => client.transactions.assetCreate, - (client) => client.send.assetCreate, + (client) => client.assetCreate, + (client) => client.assetCreate, )) as SendTransactionResult & { confirmation: { assetIndex: number | bigint } } } @@ -79,8 +78,8 @@ export async function assetOptIn(optIn: AssetOptInParams, algod: Algodv2): Promi optIn.account, optIn, params, - (c) => c.transactions.assetOptIn, - (c) => c.send.assetOptIn, + (c) => c.assetOptIn, + (c) => c.assetOptIn, ) } @@ -113,8 +112,8 @@ export async function assetOptOut(optOut: AssetOptOutParams, algod: Algodv2): Pr optOut.account, optOut, params, - (c) => c.transactions.assetOptOut, - (c) => (params: NewAssetOptOutParams) => c.send.assetOptOut({ ...params, ensureZeroBalance: optOut.ensureZeroBalance ?? true }), + (c) => c.assetOptOut, + (c) => (params: NewAssetOptOutParams) => c.assetOptOut({ ...params, ensureZeroBalance: optOut.ensureZeroBalance ?? true }), ) } @@ -131,15 +130,13 @@ export async function assetOptOut(optOut: AssetOptOutParams, algod: Algodv2): Pr */ export async function assetBulkOptIn(optIn: AssetBulkOptInOutParams, algod: Algodv2): Promise> { const clientManager = new ClientManager({ algod }) - const result = await new AssetManager(clientManager, new AccountManager(clientManager).setSignerFromAccount(optIn.account)).bulkOptIn( - getSenderAddress(optIn.account), - optIn.assetIds.map(BigInt), - { + const result = await AlgorandClient.fromClients({ algod }) + .setSignerFromAccount(optIn.account) + .asset.bulkOptIn(getSenderAddress(optIn.account), optIn.assetIds.map(BigInt), { note: encodeTransactionNote(optIn.note), maxFee: optIn.maxFee, suppressLog: optIn.suppressLog, - }, - ) + }) const returnResult: Record = {} for (const r of result) { @@ -161,16 +158,14 @@ export async function assetBulkOptIn(optIn: AssetBulkOptInOutParams, algod: Algo */ export async function assetBulkOptOut(optOut: AssetBulkOptInOutParams, algod: Algodv2): Promise> { const clientManager = new ClientManager({ algod }) - const result = await new AssetManager(clientManager, new AccountManager(clientManager).setSignerFromAccount(optOut.account)).bulkOptOut( - getSenderAddress(optOut.account), - optOut.assetIds.map(BigInt), - { + const result = await AlgorandClient.fromClients({ algod }) + .setSignerFromAccount(optOut.account) + .asset.bulkOptOut(getSenderAddress(optOut.account), optOut.assetIds.map(BigInt), { ensureZeroBalance: optOut.validateBalances ?? true, note: encodeTransactionNote(optOut.note), maxFee: optOut.maxFee, suppressLog: optOut.suppressLog, - }, - ) + }) const returnResult: Record = {} for (const r of result) { diff --git a/src/transaction/legacy-bridge.ts b/src/transaction/legacy-bridge.ts index e6c47d41..afdcb8a3 100644 --- a/src/transaction/legacy-bridge.ts +++ b/src/transaction/legacy-bridge.ts @@ -1,5 +1,7 @@ import algosdk from 'algosdk' -import { AlgorandClient, SendSingleTransactionResult } from '../types/algorand-client' +import { AlgorandClientSender, SendSingleTransactionResult } from '../types/algorand-client-sender' +import { AlgorandClientTransactionCreator } from '../types/algorand-client-transaction-creator' +import { AssetManager } from '../types/asset-manager' import AlgoKitComposer, { CommonTransactionParams, ExecuteParams } from '../types/composer' import { SendTransactionFrom, SendTransactionParams, SendTransactionResult } from '../types/transaction' import { getSenderTransactionSigner, getTransactionParams } from './transaction' @@ -12,10 +14,18 @@ export async function legacySendTransactionBridge (params: T) => Promise, - send: (c: AlgorandClient) => (params: T & ExecuteParams) => Promise, + txn: (c: AlgorandClientTransactionCreator) => (params: T) => Promise, + send: (c: AlgorandClientSender) => (params: T & ExecuteParams) => Promise, + suggestedParams?: algosdk.SuggestedParams, ): Promise { - const client = AlgorandClient.fromClients({ algod }).setSignerFromAccount(from) + const newGroup = () => + new AlgoKitComposer({ + algod, + getSigner: () => getSenderTransactionSigner(from), + getSuggestedParams: async () => await getTransactionParams(suggestedParams, algod), + }) + const sender = new AlgorandClientSender(newGroup, new AssetManager(algod, newGroup)) + const transactionCreator = new AlgorandClientTransactionCreator(newGroup) if (sendParams.fee) { params.staticFee = sendParams.fee @@ -25,52 +35,12 @@ export async function legacySendTransactionBridge( - algod: Algodv2, - from: SendTransactionFrom, - params: T, - compose: (c: AlgoKitComposer) => (params: T) => AlgoKitComposer, - sendParams?: SendTransactionParams, - suggestedParams?: algosdk.SuggestedParams, -): Promise { - const composer = new AlgoKitComposer({ - algod, - getSigner: (address) => getSenderTransactionSigner(from), - getSuggestedParams: async () => await getTransactionParams(suggestedParams, algod), - }) - sendParams = sendParams ?? {} - - if (sendParams.fee) { - params.staticFee = sendParams.fee - } - if (sendParams.maxFee) { - params.maxFee = sendParams.maxFee - } - - if (sendParams.atc || sendParams.skipSending) { - await compose(composer).apply(composer, [params]) - const transactions = await composer.build() - if (sendParams.atc) { - transactions.transactions.forEach((txn) => sendParams!.atc!.addTransaction(txn)) - } - return { transaction: transactions.transactions[transactions.transactions.length - 1].txn } - } - - const result = await compose(composer).apply(composer, [params]).execute(sendParams) - return { - ...result, - transaction: result.transactions[result.transactions.length - 1], - confirmation: result.confirmations[result.confirmations.length - 1], - } + return await send(sender)({ ...sendParams, ...params }) } diff --git a/src/transfer/transfer-algos.ts b/src/transfer/transfer-algos.ts index 02934496..e0b6864f 100644 --- a/src/transfer/transfer-algos.ts +++ b/src/transfer/transfer-algos.ts @@ -33,7 +33,7 @@ export async function transferAlgos(transfer: AlgoTransferParams, algod: Algodv2 transfer.from, transfer, params, - (c) => c.transactions.payment, - (c) => c.send.payment, + (c) => c.payment, + (c) => c.payment, ) } diff --git a/src/transfer/transfer.ts b/src/transfer/transfer.ts index fff27ca3..a04a4a31 100644 --- a/src/transfer/transfer.ts +++ b/src/transfer/transfer.ts @@ -99,8 +99,8 @@ export async function transferAsset(transfer: TransferAssetParams, algod: Algodv note: encodeTransactionNote(transfer.note), lease: transfer.lease, }, - (c) => c.transactions.assetTransfer, - (c) => c.send.assetTransfer, + (c) => c.assetTransfer, + (c) => c.assetTransfer, ) } @@ -133,7 +133,7 @@ export async function rekeyAccount(rekey: AlgoRekeyParams, algod: Algodv2): Prom note: encodeTransactionNote(rekey.note), lease: rekey.lease, }, - (c) => c.transactions.payment, - (c) => c.send.payment, + (c) => c.payment, + (c) => c.payment, ) } diff --git a/src/types/account-manager.ts b/src/types/account-manager.ts index ef502d81..017cd016 100644 --- a/src/types/account-manager.ts +++ b/src/types/account-manager.ts @@ -2,7 +2,7 @@ import algosdk from 'algosdk' import { Config } from '../config' import { calculateFundAmount, memoize } from '../util' import { AccountInformation, DISPENSER_ACCOUNT, MultisigAccount, SigningAccount, TransactionSignerAccount } from './account' -import { SendSingleTransactionResult } from './algorand-client' +import { SendSingleTransactionResult } from './algorand-client-sender' import { AlgoAmount } from './amount' import { ClientManager } from './client-manager' import AlgoKitComposer, { CommonTransactionParams, ExecuteParams } from './composer' diff --git a/src/types/algorand-client-sender.ts b/src/types/algorand-client-sender.ts new file mode 100644 index 00000000..63b235a1 --- /dev/null +++ b/src/types/algorand-client-sender.ts @@ -0,0 +1,459 @@ +import algosdk from 'algosdk' +import { Config } from '../config' +import { AssetManager } from './asset-manager' +import AlgoKitComposer, { AssetCreateParams, AssetOptOutParams, ExecuteParams } from './composer' +import { ConfirmedTransactionResult, SendAtomicTransactionComposerResults } from './transaction' + +import Transaction = algosdk.Transaction + +/** Result from sending a single transaction. */ +export type SendSingleTransactionResult = SendAtomicTransactionComposerResults & ConfirmedTransactionResult + +/** Orchestrates sending transactions for `AlgorandClient`. */ +export class AlgorandClientSender { + private _newGroup: () => AlgoKitComposer + private _assetManager: AssetManager + + /** + * Creates a new `AlgorandClientSender` + * @param newGroup A lambda that Start a new `AlgokitComposer` transaction group + * @param assetManager An `AssetManager` instance + */ + constructor(newGroup: () => AlgoKitComposer, assetManager: AssetManager) { + this._newGroup = newGroup + this._assetManager = assetManager + } + + private _send( + c: (c: AlgoKitComposer) => (params: T) => AlgoKitComposer, + log?: { + preLog?: (params: T, transaction: Transaction) => string + postLog?: (params: T, result: SendSingleTransactionResult) => string + }, + ): (params: T & ExecuteParams) => Promise { + return async (params) => { + const composer = this._newGroup() + + // Ensure `this` is properly populated + c(composer).apply(composer, [params]) + + if (log?.preLog) { + const transaction = (await composer.build()).transactions.at(-1)!.txn + Config.getLogger(params?.suppressLog).debug(log.preLog(params, transaction)) + } + + const rawResult = await composer.execute(params) + const result = { + // Last item covers when a group is created by an app call with ABI transaction parameters + transaction: rawResult.transactions[rawResult.transactions.length - 1], + confirmation: rawResult.confirmations![rawResult.confirmations!.length - 1], + txId: rawResult.txIds[0], + ...rawResult, + } + + if (log?.postLog) { + Config.getLogger(params?.suppressLog).debug(log.postLog(params, result)) + } + + return result + } + } + + /** + * Send a payment transaction to transfer Algo between accounts. + * @param params The parameters for the payment transaction + * @example Basic example + * ```typescript + * const result = await algorandClient.send.payment({ + * sender: 'SENDERADDRESS', + * receiver: 'RECEIVERADDRESS', + * amount: (4).algos(), + * }) + * ``` + * @example Advanced example + * ```typescript + * const result = await algorandClient.send.payment({ + * amount: (4).algos(), + * receiver: 'RECEIVERADDRESS', + * sender: 'SENDERADDRESS', + * closeRemainderTo: 'CLOSEREMAINDERTOADDRESS', + * lease: 'lease', + * note: 'note', + * // Use this with caution, it's generally better to use algorand.account.rekeyAccount + * rekeyTo: 'REKEYTOADDRESS', + * // You wouldn't normally set this field + * firstValidRound: 1000n, + * validityWindow: 10, + * extraFee: (1000).microAlgos(), + * staticFee: (1000).microAlgos(), + * // Max fee doesn't make sense with extraFee AND staticFee + * // already specified, but here for completeness + * maxFee: (3000).microAlgos(), + * // Signer only needed if you want to provide one, + * // generally you'd register it with AlgorandClient + * // against the sender and not need to pass it in + * signer: transactionSigner, + * maxRoundsToWaitForConfirmation: 5, + * suppressLog: true, + * }) + * ``` + * + * @returns The result of the transaction and the transaction that was sent + */ + payment = this._send((c) => c.addPayment, { + preLog: (params, transaction) => + `Sending ${params.amount.microAlgos} µALGO from ${params.sender} to ${params.receiver} via transaction ${transaction.txID()}`, + }) + /** + * Create a new Algorand Standard Asset. + * + * The account that sends this transaction will automatically be + * opted in to the asset and will hold all units after creation. + * + * @param params The parameters for the asset creation transaction + * + * @example Basic example + * ```typescript + * await algorand.send.assetCreate({sender: "CREATORADDRESS", total: 100n}) + * ``` + * @example Advanced example + * ```typescript + * await algorand.send.assetCreate({ + * sender: 'CREATORADDRESS', + * total: 100n, + * decimals: 2, + * assetName: 'asset', + * unitName: 'unit', + * url: 'url', + * metadataHash: 'metadataHash', + * defaultFrozen: false, + * manager: 'MANAGERADDRESS', + * reserve: 'RESERVEADDRESS', + * freeze: 'FREEZEADDRESS', + * clawback: 'CLAWBACKADDRESS', + * lease: 'lease', + * note: 'note', + * // You wouldn't normally set this field + * firstValidRound: 1000n, + * validityWindow: 10, + * extraFee: (1000).microAlgos(), + * staticFee: (1000).microAlgos(), + * // Max fee doesn't make sense with extraFee AND staticFee + * // already specified, but here for completeness + * maxFee: (3000).microAlgos(), + * // Signer only needed if you want to provide one, + * // generally you'd register it with AlgorandClient + * // against the sender and not need to pass it in + * signer: transactionSigner, + * maxRoundsToWaitForConfirmation: 5, + * suppressLog: true, + * }) + * ``` + * @returns The result of the transaction and the transaction that was sent + */ + assetCreate = async (params: AssetCreateParams & ExecuteParams) => { + const result = await this._send((c) => c.addAssetCreate, { + postLog: (params, result) => + `Created asset${params.assetName ? ` ${params.assetName}` : ''}${params.unitName ? ` (${params.unitName})` : ''} with ${params.total} units and ${params.decimals ?? 0} decimals created by ${params.sender} with ID ${result.confirmation.assetIndex} via transaction ${result.txIds.at(-1)}`, + })(params) + return { ...result, assetId: BigInt(result.confirmation.assetIndex ?? 0) } + } + /** + * Configure an existing Algorand Standard Asset. + * + * **Note:** The manager, reserve, freeze, and clawback addresses + * are immutably empty if they are not set. If manager is not set then + * all fields are immutable from that point forward. + * + * @param params The parameters for the asset config transaction + * + * @example Basic example + * ```typescript + * await algorand.send.assetConfig({sender: "MANAGERADDRESS", assetId: 123456n, manager: "MANAGERADDRESS" }) + * ``` + * @example Advanced example + * ```typescript + * await algorand.send.assetConfig({ + * sender: 'MANAGERADDRESS', + * assetId: 123456n, + * manager: 'MANAGERADDRESS', + * reserve: 'RESERVEADDRESS', + * freeze: 'FREEZEADDRESS', + * clawback: 'CLAWBACKADDRESS', + * lease: 'lease', + * note: 'note', + * // You wouldn't normally set this field + * firstValidRound: 1000n, + * validityWindow: 10, + * extraFee: (1000).microAlgos(), + * staticFee: (1000).microAlgos(), + * // Max fee doesn't make sense with extraFee AND staticFee + * // already specified, but here for completeness + * maxFee: (3000).microAlgos(), + * // Signer only needed if you want to provide one, + * // generally you'd register it with AlgorandClient + * // against the sender and not need to pass it in + * signer: transactionSigner, + * maxRoundsToWaitForConfirmation: 5, + * suppressLog: true, + * }) + * ``` + * @returns The result of the transaction and the transaction that was sent + */ + assetConfig = this._send((c) => c.addAssetConfig, { + preLog: (params, transaction) => `Configuring asset with ID ${params.assetId} via transaction ${transaction.txID()}`, + }) + /** + * Freeze or unfreeze an Algorand Standard Asset for an account. + * + * @param params The parameters for the asset freeze transaction + * + * @example Basic example + * ```typescript + * await algorand.send.assetFreeze({sender: "MANAGERADDRESS", assetId: 123456n, account: "ACCOUNTADDRESS", frozen: true }) + * ``` + * @example Advanced example + * ```typescript + * await algorand.send.assetFreeze({ + * sender: 'MANAGERADDRESS', + * assetId: 123456n, + * account: 'ACCOUNTADDRESS', + * frozen: true, + * lease: 'lease', + * note: 'note', + * // You wouldn't normally set this field + * firstValidRound: 1000n, + * validityWindow: 10, + * extraFee: (1000).microAlgos(), + * staticFee: (1000).microAlgos(), + * // Max fee doesn't make sense with extraFee AND staticFee + * // already specified, but here for completeness + * maxFee: (3000).microAlgos(), + * // Signer only needed if you want to provide one, + * // generally you'd register it with AlgorandClient + * // against the sender and not need to pass it in + * signer: transactionSigner, + * maxRoundsToWaitForConfirmation: 5, + * suppressLog: true, + * }) + * ``` + * @returns The result of the transaction and the transaction that was sent + */ + assetFreeze = this._send((c) => c.addAssetFreeze, { + preLog: (params, transaction) => `Freezing asset with ID ${params.assetId} via transaction ${transaction.txID()}`, + }) + /** + * Destroys an Algorand Standard Asset. + * + * Created assets can be destroyed only by the asset manager account. + * All of the assets must be owned by the creator of the asset before + * the asset can be deleted. + * + * @param params The parameters for the asset destroy transaction + * + * @example Basic example + * ```typescript + * await algorand.send.assetDestroy({sender: "MANAGERADDRESS", assetId: 123456n }) + * ``` + * @example Advanced example + * ```typescript + * await algorand.send.assetDestroy({ + * sender: 'MANAGERADDRESS', + * assetId: 123456n, + * lease: 'lease', + * note: 'note', + * // You wouldn't normally set this field + * firstValidRound: 1000n, + * validityWindow: 10, + * extraFee: (1000).microAlgos(), + * staticFee: (1000).microAlgos(), + * // Max fee doesn't make sense with extraFee AND staticFee + * // already specified, but here for completeness + * maxFee: (3000).microAlgos(), + * // Signer only needed if you want to provide one, + * // generally you'd register it with AlgorandClient + * // against the sender and not need to pass it in + * signer: transactionSigner, + * maxRoundsToWaitForConfirmation: 5, + * suppressLog: true, + * }) + * ``` + * @returns The result of the transaction and the transaction that was sent + */ + assetDestroy = this._send((c) => c.addAssetDestroy, { + preLog: (params, transaction) => `Destroying asset with ID ${params.assetId} via transaction ${transaction.txID()}`, + }) + /** + * Transfer an Algorand Standard Asset. + * + * @param params The parameters for the asset transfer transaction + * + * @example Basic example + * ```typescript + * await algorand.send.assetTransfer({sender: "HOLDERADDRESS", assetId: 123456n, amount: 1n, receiver: "RECEIVERADDRESS" }) + * ``` + * @example Advanced example (with clawback) + * ```typescript + * await algorand.send.assetTransfer({ + * sender: 'CLAWBACKADDRESS', + * assetId: 123456n, + * amount: 1n, + * receiver: 'RECEIVERADDRESS', + * clawbackTarget: 'HOLDERADDRESS', + * // This field needs to be used with caution + * closeAssetTo: 'ADDRESSTOCLOSETO' + * lease: 'lease', + * note: 'note', + * // You wouldn't normally set this field + * firstValidRound: 1000n, + * validityWindow: 10, + * extraFee: (1000).microAlgos(), + * staticFee: (1000).microAlgos(), + * // Max fee doesn't make sense with extraFee AND staticFee + * // already specified, but here for completeness + * maxFee: (3000).microAlgos(), + * // Signer only needed if you want to provide one, + * // generally you'd register it with AlgorandClient + * // against the sender and not need to pass it in + * signer: transactionSigner, + * maxRoundsToWaitForConfirmation: 5, + * suppressLog: true, + * }) + * ``` + * @returns The result of the transaction and the transaction that was sent + */ + assetTransfer = this._send((c) => c.addAssetTransfer, { + preLog: (params, transaction) => + `Transferring ${params.amount} units of asset with ID ${params.assetId} from ${params.sender} to ${params.receiver} via transaction ${transaction.txID()}`, + }) + /** + * Opt an account into an Algorand Standard Asset. + * + * @param params The parameters for the asset opt-in transaction + * + * @example Basic example + * ```typescript + * await algorand.send.assetOptIn({sender: "SENDERADDRESS", assetId: 123456n }) + * ``` + * @example Advanced example + * ```typescript + * await algorand.send.assetOptIn({ + * sender: 'SENDERADDRESS', + * assetId: 123456n, + * lease: 'lease', + * note: 'note', + * // You wouldn't normally set this field + * firstValidRound: 1000n, + * validityWindow: 10, + * extraFee: (1000).microAlgos(), + * staticFee: (1000).microAlgos(), + * // Max fee doesn't make sense with extraFee AND staticFee + * // already specified, but here for completeness + * maxFee: (3000).microAlgos(), + * // Signer only needed if you want to provide one, + * // generally you'd register it with AlgorandClient + * // against the sender and not need to pass it in + * signer: transactionSigner, + * maxRoundsToWaitForConfirmation: 5, + * suppressLog: true, + * }) + * ``` + * @returns The result of the transaction and the transaction that was sent + */ + assetOptIn = this._send((c) => c.addAssetOptIn, { + preLog: (params, transaction) => `Opting in ${params.sender} to asset with ID ${params.assetId} via transaction ${transaction.txID()}`, + }) + /** + * Opt an account out of an Algorand Standard Asset. + * + * *Note:* If the account has a balance of the asset, + * it will not be able to opt-out unless `ensureZeroBalance` + * is set to `false` (but then the account will lose the assets). + * + * @param params The parameters for the asset opt-out transaction + * + * @example Basic example (without creator) + * ```typescript + * await algorand.send.assetOptOut({sender: "SENDERADDRESS", assetId: 123456n, ensureZeroBalance: true }) + * ``` + * @example Basic example (with creator) + * ```typescript + * await algorand.send.assetOptOut({sender: "SENDERADDRESS", creator: "CREATORADDRESS", assetId: 123456n, ensureZeroBalance: true }) + * ``` + * @example Advanced example + * ```typescript + * await algorand.send.assetOptOut({ + * sender: 'SENDERADDRESS', + * assetId: 123456n, + * creator: 'CREATORADDRESS', + * ensureZeroBalance: true, + * lease: 'lease', + * note: 'note', + * // You wouldn't normally set this field + * firstValidRound: 1000n, + * validityWindow: 10, + * extraFee: (1000).microAlgos(), + * staticFee: (1000).microAlgos(), + * // Max fee doesn't make sense with extraFee AND staticFee + * // already specified, but here for completeness + * maxFee: (3000).microAlgos(), + * // Signer only needed if you want to provide one, + * // generally you'd register it with AlgorandClient + * // against the sender and not need to pass it in + * signer: transactionSigner, + * maxRoundsToWaitForConfirmation: 5, + * suppressLog: true, + * }) + * ``` + * @returns The result of the transaction and the transaction that was sent + */ + assetOptOut = async ( + params: Omit & { + /** Optional asset creator account address; if not specified it will be retrieved from algod */ + creator?: string + /** Whether or not to check if the account has a zero balance first or not. + * + * If this is set to `true` and the account has an asset balance it will throw an error. + * + * If this is set to `false` and the account has an asset balance it will lose those assets to the asset creator. + */ + ensureZeroBalance: boolean + } & ExecuteParams, + ) => { + if (params.ensureZeroBalance) { + let balance = 0n + try { + const accountAssetInfo = await this._assetManager.getAccountInformation(params.sender, params.assetId) + balance = accountAssetInfo.balance + } catch (e) { + throw new Error(`Account ${params.sender} is not opted-in to Asset ${params.assetId}; can't opt-out.`) + } + if (balance !== 0n) { + throw new Error(`Account ${params.sender} does not have a zero balance for Asset ${params.assetId}; can't opt-out.`) + } + } + + params.creator = params.creator ?? (await this._assetManager.getById(params.assetId)).creator + + return await this._send((c) => c.addAssetOptOut, { + preLog: (params, transaction) => + `Opting ${params.sender} out of asset with ID ${params.assetId} to creator ${params.creator} via transaction ${transaction.txID()}`, + })(params as AssetOptOutParams & ExecuteParams) + } + /** + * Call a smart contract. + * + * Note: you may prefer to use `algorandClient.client` to get an app client for more advanced functionality. + */ + appCall = this._send((c) => c.addAppCall) + /** + * Call a smart contract ABI method. + * + * Note: you may prefer to use `algorandClient.client` to get an app client for more advanced functionality. + */ + methodCall = this._send((c) => c.addMethodCall) + /** Register an online key. */ + onlineKeyRegistration = this._send((c) => c.addOnlineKeyRegistration, { + preLog: (params, transaction) => `Registering online key for ${params.sender} via transaction ${transaction.txID()}`, + }) +} diff --git a/src/types/algorand-client-transaction-creator.ts b/src/types/algorand-client-transaction-creator.ts new file mode 100644 index 00000000..b66ee92b --- /dev/null +++ b/src/types/algorand-client-transaction-creator.ts @@ -0,0 +1,304 @@ +import algosdk from 'algosdk' +import AlgoKitComposer, { MethodCallParams } from './composer' + +import Transaction = algosdk.Transaction + +/** Orchestrates sending transactions for `AlgorandClient`. */ +export class AlgorandClientTransactionCreator { + private _newGroup: () => AlgoKitComposer + + /** + * Creates a new `AlgorandClientSender` + * @param newGroup A lambda that Start a new `AlgokitComposer` transaction group + * @param assetManager An `AssetManager` instance + */ + constructor(newGroup: () => AlgoKitComposer) { + this._newGroup = newGroup + } + + private _transaction(c: (c: AlgoKitComposer) => (params: T) => AlgoKitComposer): (params: T) => Promise { + return async (params: T) => { + const composer = this._newGroup() + const result = await c(composer).apply(composer, [params]).buildTransactions() + return result[result.length - 1] + } + } + + /** + * Create a payment transaction to transfer Algo between accounts. + * @param params The parameters for the payment transaction + * @example Basic example + * ```typescript + * const result = await algorandClient.send.payment({ + * sender: 'SENDERADDRESS', + * receiver: 'RECEIVERADDRESS', + * amount: (4).algos(), + * }) + * ``` + * @example Advanced example + * ```typescript + * const result = await algorandClient.send.payment({ + * amount: (4).algos(), + * receiver: 'RECEIVERADDRESS', + * sender: 'SENDERADDRESS', + * closeRemainderTo: 'CLOSEREMAINDERTOADDRESS', + * lease: 'lease', + * note: 'note', + * // Use this with caution, it's generally better to use algorand.account.rekeyAccount + * rekeyTo: 'REKEYTOADDRESS', + * // You wouldn't normally set this field + * firstValidRound: 1000n, + * validityWindow: 10, + * extraFee: (1000).microAlgos(), + * staticFee: (1000).microAlgos(), + * // Max fee doesn't make sense with extraFee AND staticFee + * // already specified, but here for completeness + * maxFee: (3000).microAlgos(), + * }) + * ``` + * + * @returns The payment transaction + */ + payment = this._transaction((c) => c.addPayment) + /** Create a create Algorand Standard Asset transaction. + * + * The account that sends this transaction will automatically be + * opted in to the asset and will hold all units after creation. + * + * @param params The parameters for the asset creation transaction + * + * @example Basic example + * ```typescript + * await algorand.transaction.assetCreate({sender: "CREATORADDRESS", total: 100n}) + * ``` + * @example Advanced example + * ```typescript + * await algorand.transaction.assetCreate({ + * sender: 'CREATORADDRESS', + * total: 100n, + * decimals: 2, + * assetName: 'asset', + * unitName: 'unit', + * url: 'url', + * metadataHash: 'metadataHash', + * defaultFrozen: false, + * manager: 'MANAGERADDRESS', + * reserve: 'RESERVEADDRESS', + * freeze: 'FREEZEADDRESS', + * clawback: 'CLAWBACKADDRESS', + * lease: 'lease', + * note: 'note', + * // You wouldn't normally set this field + * firstValidRound: 1000n, + * validityWindow: 10, + * extraFee: (1000).microAlgos(), + * staticFee: (1000).microAlgos(), + * // Max fee doesn't make sense with extraFee AND staticFee + * // already specified, but here for completeness + * maxFee: (3000).microAlgos(), + * }) + * ``` + * @returns The asset create transaction + */ + assetCreate = this._transaction((c) => c.addAssetCreate) + /** Create an asset config transaction to reconfigure an existing Algorand Standard Asset. + * + * **Note:** The manager, reserve, freeze, and clawback addresses + * are immutably empty if they are not set. If manager is not set then + * all fields are immutable from that point forward. + * + * @param params The parameters for the asset config transaction + * + * @example Basic example + * ```typescript + * await algorand.transaction.assetConfig({sender: "MANAGERADDRESS", assetId: 123456n, manager: "MANAGERADDRESS" }) + * ``` + * @example Advanced example + * ```typescript + * await algorand.transaction.assetConfig({ + * sender: 'MANAGERADDRESS', + * assetId: 123456n, + * manager: 'MANAGERADDRESS', + * reserve: 'RESERVEADDRESS', + * freeze: 'FREEZEADDRESS', + * clawback: 'CLAWBACKADDRESS', + * lease: 'lease', + * note: 'note', + * // You wouldn't normally set this field + * firstValidRound: 1000n, + * validityWindow: 10, + * extraFee: (1000).microAlgos(), + * staticFee: (1000).microAlgos(), + * // Max fee doesn't make sense with extraFee AND staticFee + * // already specified, but here for completeness + * maxFee: (3000).microAlgos(), + * }) + * ``` + * @returns The asset config transaction + */ + assetConfig = this._transaction((c) => c.addAssetConfig) + /** Create an Algorand Standard Asset freeze transaction. + * + * @param params The parameters for the asset freeze transaction + * + * @example Basic example + * ```typescript + * await algorand.transaction.assetFreeze({sender: "MANAGERADDRESS", assetId: 123456n, account: "ACCOUNTADDRESS", frozen: true }) + * ``` + * @example Advanced example + * ```typescript + * await algorand.transaction.assetFreeze({ + * sender: 'MANAGERADDRESS', + * assetId: 123456n, + * account: 'ACCOUNTADDRESS', + * frozen: true, + * lease: 'lease', + * note: 'note', + * // You wouldn't normally set this field + * firstValidRound: 1000n, + * validityWindow: 10, + * extraFee: (1000).microAlgos(), + * staticFee: (1000).microAlgos(), + * // Max fee doesn't make sense with extraFee AND staticFee + * // already specified, but here for completeness + * maxFee: (3000).microAlgos(), + * }) + * ``` + * @returns The asset freeze transaction + */ + assetFreeze = this._transaction((c) => c.addAssetFreeze) + /** Create an Algorand Standard Asset destroy transaction. + * + * Created assets can be destroyed only by the asset manager account. + * All of the assets must be owned by the creator of the asset before + * the asset can be deleted. + * + * @param params The parameters for the asset destroy transaction + * + * @example Basic example + * ```typescript + * await algorand.transaction.assetDestroy({sender: "MANAGERADDRESS", assetId: 123456n }) + * ``` + * @example Advanced example + * ```typescript + * await algorand.transaction.assetDestroy({ + * sender: 'MANAGERADDRESS', + * assetId: 123456n, + * lease: 'lease', + * note: 'note', + * // You wouldn't normally set this field + * firstValidRound: 1000n, + * validityWindow: 10, + * extraFee: (1000).microAlgos(), + * staticFee: (1000).microAlgos(), + * // Max fee doesn't make sense with extraFee AND staticFee + * // already specified, but here for completeness + * maxFee: (3000).microAlgos(), + * }) + * ``` + * @returns The asset destroy transaction + */ + assetDestroy = this._transaction((c) => c.addAssetDestroy) + /** Create an Algorand Standard Asset transfer transaction. + * + * @param params The parameters for the asset transfer transaction + * + * @example Basic example + * ```typescript + * await algorand.transaction.assetTransfer({sender: "HOLDERADDRESS", assetId: 123456n, amount: 1n, receiver: "RECEIVERADDRESS" }) + * ``` + * @example Advanced example (with clawback) + * ```typescript + * await algorand.transaction.assetTransfer({ + * sender: 'CLAWBACKADDRESS', + * assetId: 123456n, + * amount: 1n, + * receiver: 'RECEIVERADDRESS', + * clawbackTarget: 'HOLDERADDRESS', + * // This field needs to be used with caution + * closeAssetTo: 'ADDRESSTOCLOSETO' + * lease: 'lease', + * note: 'note', + * // You wouldn't normally set this field + * firstValidRound: 1000n, + * validityWindow: 10, + * extraFee: (1000).microAlgos(), + * staticFee: (1000).microAlgos(), + * // Max fee doesn't make sense with extraFee AND staticFee + * // already specified, but here for completeness + * maxFee: (3000).microAlgos(), + * }) + * ``` + * @returns The result of the asset transfer transaction + */ + assetTransfer = this._transaction((c) => c.addAssetTransfer) + /** Create an Algorand Standard Asset opt-in transaction. + * + * @param params The parameters for the asset opt-in transaction + * + * @example Basic example + * ```typescript + * await algorand.transaction.assetOptIn({sender: "SENDERADDRESS", assetId: 123456n }) + * ``` + * @example Advanced example + * ```typescript + * await algorand.transaction.assetOptIn({ + * sender: 'SENDERADDRESS', + * assetId: 123456n, + * lease: 'lease', + * note: 'note', + * // You wouldn't normally set this field + * firstValidRound: 1000n, + * validityWindow: 10, + * extraFee: (1000).microAlgos(), + * staticFee: (1000).microAlgos(), + * // Max fee doesn't make sense with extraFee AND staticFee + * // already specified, but here for completeness + * maxFee: (3000).microAlgos(), + * }) + * ``` + * @returns The asset opt-in transaction + */ + assetOptIn = this._transaction((c) => c.addAssetOptIn) + /** Create an asset opt-out transaction. + * + * *Note:* If the account has a balance of the asset, + * it will lose those assets + * + * @param params The parameters for the asset opt-out transaction + * + * @example Basic example + * ```typescript + * await algorand.transaction.assetOptOut({sender: "SENDERADDRESS", creator: "CREATORADDRESS", assetId: 123456n }) + * ``` + * @example Advanced example + * ```typescript + * await algorand.transaction.assetOptIn({ + * sender: 'SENDERADDRESS', + * assetId: 123456n, + * creator: 'CREATORADDRESS', + * ensureZeroBalance: true, + * lease: 'lease', + * note: 'note', + * // You wouldn't normally set this field + * firstValidRound: 1000n, + * validityWindow: 10, + * extraFee: (1000).microAlgos(), + * staticFee: (1000).microAlgos(), + * // Max fee doesn't make sense with extraFee AND staticFee + * // already specified, but here for completeness + * maxFee: (3000).microAlgos(), + * }) + * ``` + * @returns The asset opt-out transaction + */ + assetOptOut = this._transaction((c) => c.addAssetOptOut) + /** Create an application call transaction. */ + appCall = this._transaction((c) => c.addAppCall) + /** Create an application call with ABI method call transaction. */ + methodCall = async (params: MethodCallParams) => { + return await this._newGroup().addMethodCall(params).buildTransactions() + } + /** Create an online key registration transaction. */ + onlineKeyRegistration = this._transaction((c) => c.addOnlineKeyRegistration) +} diff --git a/src/types/algorand-client.ts b/src/types/algorand-client.ts index bc707b4b..b3987938 100644 --- a/src/types/algorand-client.ts +++ b/src/types/algorand-client.ts @@ -1,19 +1,15 @@ import algosdk from 'algosdk' -import { Config } from '../config' import { MultisigAccount, SigningAccount, TransactionSignerAccount } from './account' import { AccountManager } from './account-manager' +import { AlgorandClientSender } from './algorand-client-sender' +import { AlgorandClientTransactionCreator } from './algorand-client-transaction-creator' import { AssetManager } from './asset-manager' import { AlgoSdkClients, ClientManager } from './client-manager' -import AlgoKitComposer, { AssetCreateParams, AssetOptOutParams, ExecuteParams, MethodCallParams } from './composer' +import AlgoKitComposer from './composer' import { AlgoConfig } from './network-client' -import { ConfirmedTransactionResult, SendAtomicTransactionComposerResults } from './transaction' -import Transaction = algosdk.Transaction import Account = algosdk.Account import LogicSigAccount = algosdk.LogicSigAccount -/** Result from sending a single transaction. */ -export type SendSingleTransactionResult = SendAtomicTransactionComposerResults & ConfirmedTransactionResult - /** * A client that brokers easy access to Algorand functionality. */ @@ -21,6 +17,8 @@ export class AlgorandClient { private _clientManager: ClientManager private _accountManager: AccountManager private _assetManager: AssetManager + private _sender: AlgorandClientSender + private _transactionCreator: AlgorandClientTransactionCreator private _cachedSuggestedParams?: algosdk.SuggestedParams private _cachedSuggestedParamsExpiry?: Date @@ -31,7 +29,9 @@ export class AlgorandClient { private constructor(config: AlgoConfig | AlgoSdkClients) { this._clientManager = new ClientManager(config) this._accountManager = new AccountManager(this._clientManager) - this._assetManager = new AssetManager(this._clientManager, this._accountManager) + this._assetManager = new AssetManager(this._clientManager.algod, () => this.newGroup()) + this._sender = new AlgorandClientSender(() => this.newGroup(), this._assetManager) + this._transactionCreator = new AlgorandClientTransactionCreator(() => this.newGroup()) } /** @@ -150,734 +150,18 @@ export class AlgorandClient { }) } - private _send( - c: (c: AlgoKitComposer) => (params: T) => AlgoKitComposer, - log?: { - preLog?: (params: T, transaction: Transaction) => string - postLog?: (params: T, result: SendSingleTransactionResult) => string - }, - ): (params: T & ExecuteParams) => Promise { - return async (params) => { - const composer = this.newGroup() - - // Ensure `this` is properly populated - c(composer).apply(composer, [params]) - - if (log?.preLog) { - const transaction = (await composer.build()).transactions.at(-1)!.txn - Config.getLogger(params?.suppressLog).debug(log.preLog(params, transaction)) - } - - const rawResult = await composer.execute(params) - const result = { - // Last item covers when a group is created by an app call with ABI transaction parameters - transaction: rawResult.transactions[rawResult.transactions.length - 1], - confirmation: rawResult.confirmations![rawResult.confirmations!.length - 1], - txId: rawResult.txIds[0], - ...rawResult, - } - - if (log?.postLog) { - Config.getLogger(params?.suppressLog).debug(log.postLog(params, result)) - } - - return result - } - } - /** * Methods for sending a single transaction. */ - public send = { - /** - * Send a payment transaction to transfer Algo between accounts. - * @param params The parameters for the payment transaction - * @example Basic example - * ```typescript - * const result = await algorandClient.send.payment({ - * sender: 'SENDERADDRESS', - * receiver: 'RECEIVERADDRESS', - * amount: (4).algos(), - * }) - * ``` - * @example Advanced example - * ```typescript - * const result = await algorandClient.send.payment({ - * amount: (4).algos(), - * receiver: 'RECEIVERADDRESS', - * sender: 'SENDERADDRESS', - * closeRemainderTo: 'CLOSEREMAINDERTOADDRESS', - * lease: 'lease', - * note: 'note', - * // Use this with caution, it's generally better to use algorand.account.rekeyAccount - * rekeyTo: 'REKEYTOADDRESS', - * // You wouldn't normally set this field - * firstValidRound: 1000n, - * validityWindow: 10, - * extraFee: (1000).microAlgos(), - * staticFee: (1000).microAlgos(), - * // Max fee doesn't make sense with extraFee AND staticFee - * // already specified, but here for completeness - * maxFee: (3000).microAlgos(), - * // Signer only needed if you want to provide one, - * // generally you'd register it with AlgorandClient - * // against the sender and not need to pass it in - * signer: transactionSigner, - * maxRoundsToWaitForConfirmation: 5, - * suppressLog: true, - * }) - * ``` - * - * @returns The result of the transaction and the transaction that was sent - */ - payment: this._send((c) => c.addPayment, { - preLog: (params, transaction) => - `Sending ${params.amount.microAlgos} µALGO from ${params.sender} to ${params.receiver} via transaction ${transaction.txID()}`, - }), - /** - * Create a new Algorand Standard Asset. - * - * The account that sends this transaction will automatically be - * opted in to the asset and will hold all units after creation. - * - * @param params The parameters for the asset creation transaction - * - * @example Basic example - * ```typescript - * await algorand.send.assetCreate({sender: "CREATORADDRESS", total: 100n}) - * ``` - * @example Advanced example - * ```typescript - * await algorand.send.assetCreate({ - * sender: 'CREATORADDRESS', - * total: 100n, - * decimals: 2, - * assetName: 'asset', - * unitName: 'unit', - * url: 'url', - * metadataHash: 'metadataHash', - * defaultFrozen: false, - * manager: 'MANAGERADDRESS', - * reserve: 'RESERVEADDRESS', - * freeze: 'FREEZEADDRESS', - * clawback: 'CLAWBACKADDRESS', - * lease: 'lease', - * note: 'note', - * // You wouldn't normally set this field - * firstValidRound: 1000n, - * validityWindow: 10, - * extraFee: (1000).microAlgos(), - * staticFee: (1000).microAlgos(), - * // Max fee doesn't make sense with extraFee AND staticFee - * // already specified, but here for completeness - * maxFee: (3000).microAlgos(), - * // Signer only needed if you want to provide one, - * // generally you'd register it with AlgorandClient - * // against the sender and not need to pass it in - * signer: transactionSigner, - * maxRoundsToWaitForConfirmation: 5, - * suppressLog: true, - * }) - * ``` - * @returns The result of the transaction and the transaction that was sent - */ - assetCreate: async (params: AssetCreateParams & ExecuteParams) => { - const result = await this._send((c) => c.addAssetCreate, { - postLog: (params, result) => - `Created asset${params.assetName ? ` ${params.assetName}` : ''}${params.unitName ? ` (${params.unitName})` : ''} with ${params.total} units and ${params.decimals ?? 0} decimals created by ${params.sender} with ID ${result.confirmation.assetIndex} via transaction ${result.txIds.at(-1)}`, - })(params) - return { ...result, assetId: BigInt(result.confirmation.assetIndex ?? 0) } - }, - /** - * Configure an existing Algorand Standard Asset. - * - * **Note:** The manager, reserve, freeze, and clawback addresses - * are immutably empty if they are not set. If manager is not set then - * all fields are immutable from that point forward. - * - * @param params The parameters for the asset config transaction - * - * @example Basic example - * ```typescript - * await algorand.send.assetConfig({sender: "MANAGERADDRESS", assetId: 123456n, manager: "MANAGERADDRESS" }) - * ``` - * @example Advanced example - * ```typescript - * await algorand.send.assetConfig({ - * sender: 'MANAGERADDRESS', - * assetId: 123456n, - * manager: 'MANAGERADDRESS', - * reserve: 'RESERVEADDRESS', - * freeze: 'FREEZEADDRESS', - * clawback: 'CLAWBACKADDRESS', - * lease: 'lease', - * note: 'note', - * // You wouldn't normally set this field - * firstValidRound: 1000n, - * validityWindow: 10, - * extraFee: (1000).microAlgos(), - * staticFee: (1000).microAlgos(), - * // Max fee doesn't make sense with extraFee AND staticFee - * // already specified, but here for completeness - * maxFee: (3000).microAlgos(), - * // Signer only needed if you want to provide one, - * // generally you'd register it with AlgorandClient - * // against the sender and not need to pass it in - * signer: transactionSigner, - * maxRoundsToWaitForConfirmation: 5, - * suppressLog: true, - * }) - * ``` - * @returns The result of the transaction and the transaction that was sent - */ - assetConfig: this._send((c) => c.addAssetConfig, { - preLog: (params, transaction) => `Configuring asset with ID ${params.assetId} via transaction ${transaction.txID()}`, - }), - /** - * Freeze or unfreeze an Algorand Standard Asset for an account. - * - * @param params The parameters for the asset freeze transaction - * - * @example Basic example - * ```typescript - * await algorand.send.assetFreeze({sender: "MANAGERADDRESS", assetId: 123456n, account: "ACCOUNTADDRESS", frozen: true }) - * ``` - * @example Advanced example - * ```typescript - * await algorand.send.assetFreeze({ - * sender: 'MANAGERADDRESS', - * assetId: 123456n, - * account: 'ACCOUNTADDRESS', - * frozen: true, - * lease: 'lease', - * note: 'note', - * // You wouldn't normally set this field - * firstValidRound: 1000n, - * validityWindow: 10, - * extraFee: (1000).microAlgos(), - * staticFee: (1000).microAlgos(), - * // Max fee doesn't make sense with extraFee AND staticFee - * // already specified, but here for completeness - * maxFee: (3000).microAlgos(), - * // Signer only needed if you want to provide one, - * // generally you'd register it with AlgorandClient - * // against the sender and not need to pass it in - * signer: transactionSigner, - * maxRoundsToWaitForConfirmation: 5, - * suppressLog: true, - * }) - * ``` - * @returns The result of the transaction and the transaction that was sent - */ - assetFreeze: this._send((c) => c.addAssetFreeze, { - preLog: (params, transaction) => `Freezing asset with ID ${params.assetId} via transaction ${transaction.txID()}`, - }), - /** - * Destroys an Algorand Standard Asset. - * - * Created assets can be destroyed only by the asset manager account. - * All of the assets must be owned by the creator of the asset before - * the asset can be deleted. - * - * @param params The parameters for the asset destroy transaction - * - * @example Basic example - * ```typescript - * await algorand.send.assetDestroy({sender: "MANAGERADDRESS", assetId: 123456n }) - * ``` - * @example Advanced example - * ```typescript - * await algorand.send.assetDestroy({ - * sender: 'MANAGERADDRESS', - * assetId: 123456n, - * lease: 'lease', - * note: 'note', - * // You wouldn't normally set this field - * firstValidRound: 1000n, - * validityWindow: 10, - * extraFee: (1000).microAlgos(), - * staticFee: (1000).microAlgos(), - * // Max fee doesn't make sense with extraFee AND staticFee - * // already specified, but here for completeness - * maxFee: (3000).microAlgos(), - * // Signer only needed if you want to provide one, - * // generally you'd register it with AlgorandClient - * // against the sender and not need to pass it in - * signer: transactionSigner, - * maxRoundsToWaitForConfirmation: 5, - * suppressLog: true, - * }) - * ``` - * @returns The result of the transaction and the transaction that was sent - */ - assetDestroy: this._send((c) => c.addAssetDestroy, { - preLog: (params, transaction) => `Destroying asset with ID ${params.assetId} via transaction ${transaction.txID()}`, - }), - /** - * Transfer an Algorand Standard Asset. - * - * @param params The parameters for the asset transfer transaction - * - * @example Basic example - * ```typescript - * await algorand.send.assetTransfer({sender: "HOLDERADDRESS", assetId: 123456n, amount: 1n, receiver: "RECEIVERADDRESS" }) - * ``` - * @example Advanced example (with clawback) - * ```typescript - * await algorand.send.assetTransfer({ - * sender: 'CLAWBACKADDRESS', - * assetId: 123456n, - * amount: 1n, - * receiver: 'RECEIVERADDRESS', - * clawbackTarget: 'HOLDERADDRESS', - * // This field needs to be used with caution - * closeAssetTo: 'ADDRESSTOCLOSETO' - * lease: 'lease', - * note: 'note', - * // You wouldn't normally set this field - * firstValidRound: 1000n, - * validityWindow: 10, - * extraFee: (1000).microAlgos(), - * staticFee: (1000).microAlgos(), - * // Max fee doesn't make sense with extraFee AND staticFee - * // already specified, but here for completeness - * maxFee: (3000).microAlgos(), - * // Signer only needed if you want to provide one, - * // generally you'd register it with AlgorandClient - * // against the sender and not need to pass it in - * signer: transactionSigner, - * maxRoundsToWaitForConfirmation: 5, - * suppressLog: true, - * }) - * ``` - * @returns The result of the transaction and the transaction that was sent - */ - assetTransfer: this._send((c) => c.addAssetTransfer, { - preLog: (params, transaction) => - `Transferring ${params.amount} units of asset with ID ${params.assetId} from ${params.sender} to ${params.receiver} via transaction ${transaction.txID()}`, - }), - /** - * Opt an account into an Algorand Standard Asset. - * - * @param params The parameters for the asset opt-in transaction - * - * @example Basic example - * ```typescript - * await algorand.send.assetOptIn({sender: "SENDERADDRESS", assetId: 123456n }) - * ``` - * @example Advanced example - * ```typescript - * await algorand.send.assetOptIn({ - * sender: 'SENDERADDRESS', - * assetId: 123456n, - * lease: 'lease', - * note: 'note', - * // You wouldn't normally set this field - * firstValidRound: 1000n, - * validityWindow: 10, - * extraFee: (1000).microAlgos(), - * staticFee: (1000).microAlgos(), - * // Max fee doesn't make sense with extraFee AND staticFee - * // already specified, but here for completeness - * maxFee: (3000).microAlgos(), - * // Signer only needed if you want to provide one, - * // generally you'd register it with AlgorandClient - * // against the sender and not need to pass it in - * signer: transactionSigner, - * maxRoundsToWaitForConfirmation: 5, - * suppressLog: true, - * }) - * ``` - * @returns The result of the transaction and the transaction that was sent - */ - assetOptIn: this._send((c) => c.addAssetOptIn, { - preLog: (params, transaction) => - `Opting in ${params.sender} to asset with ID ${params.assetId} via transaction ${transaction.txID()}`, - }), - /** - * Opt an account out of an Algorand Standard Asset. - * - * *Note:* If the account has a balance of the asset, - * it will not be able to opt-out unless `ensureZeroBalance` - * is set to `false` (but then the account will lose the assets). - * - * @param params The parameters for the asset opt-out transaction - * - * @example Basic example (without creator) - * ```typescript - * await algorand.send.assetOptOut({sender: "SENDERADDRESS", assetId: 123456n, ensureZeroBalance: true }) - * ``` - * @example Basic example (with creator) - * ```typescript - * await algorand.send.assetOptOut({sender: "SENDERADDRESS", creator: "CREATORADDRESS", assetId: 123456n, ensureZeroBalance: true }) - * ``` - * @example Advanced example - * ```typescript - * await algorand.send.assetOptOut({ - * sender: 'SENDERADDRESS', - * assetId: 123456n, - * creator: 'CREATORADDRESS', - * ensureZeroBalance: true, - * lease: 'lease', - * note: 'note', - * // You wouldn't normally set this field - * firstValidRound: 1000n, - * validityWindow: 10, - * extraFee: (1000).microAlgos(), - * staticFee: (1000).microAlgos(), - * // Max fee doesn't make sense with extraFee AND staticFee - * // already specified, but here for completeness - * maxFee: (3000).microAlgos(), - * // Signer only needed if you want to provide one, - * // generally you'd register it with AlgorandClient - * // against the sender and not need to pass it in - * signer: transactionSigner, - * maxRoundsToWaitForConfirmation: 5, - * suppressLog: true, - * }) - * ``` - * @returns The result of the transaction and the transaction that was sent - */ - assetOptOut: async ( - params: Omit & { - /** Optional asset creator account address; if not specified it will be retrieved from algod */ - creator?: string - /** Whether or not to check if the account has a zero balance first or not. - * - * If this is set to `true` and the account has an asset balance it will throw an error. - * - * If this is set to `false` and the account has an asset balance it will lose those assets to the asset creator. - */ - ensureZeroBalance: boolean - } & ExecuteParams, - ) => { - if (params.ensureZeroBalance) { - let balance = 0n - try { - const accountAssetInfo = await this.asset.getAccountInformation(params.sender, params.assetId) - balance = accountAssetInfo.balance - } catch (e) { - throw new Error(`Account ${params.sender} is not opted-in to Asset ${params.assetId}; can't opt-out.`) - } - if (balance !== 0n) { - throw new Error(`Account ${params.sender} does not have a zero balance for Asset ${params.assetId}; can't opt-out.`) - } - } - - params.creator = params.creator ?? (await this.asset.getById(params.assetId)).creator - - return await this._send((c) => c.addAssetOptOut, { - preLog: (params, transaction) => - `Opting ${params.sender} out of asset with ID ${params.assetId} to creator ${params.creator} via transaction ${transaction.txID()}`, - })(params as AssetOptOutParams & ExecuteParams) - }, - /** - * Call a smart contract. - * - * Note: you may prefer to use `algorandClient.client` to get an app client for more advanced functionality. - */ - appCall: this._send((c) => c.addAppCall), - /** - * Call a smart contract ABI method. - * - * Note: you may prefer to use `algorandClient.client` to get an app client for more advanced functionality. - */ - methodCall: this._send((c) => c.addMethodCall), - /** Register an online key. */ - onlineKeyRegistration: this._send((c) => c.addOnlineKeyRegistration, { - preLog: (params, transaction) => `Registering online key for ${params.sender} via transaction ${transaction.txID()}`, - }), - } - - private _transaction(c: (c: AlgoKitComposer) => (params: T) => AlgoKitComposer): (params: T) => Promise { - return async (params: T) => { - const composer = this.newGroup() - const result = await c(composer).apply(composer, [params]).build() - return result.transactions.map((ts) => ts.txn)[0] - } + public get send() { + return this._sender } /** * Methods for building transactions */ - public transactions = { - /** - * Create a payment transaction to transfer Algo between accounts. - * @param params The parameters for the payment transaction - * @example Basic example - * ```typescript - * const result = await algorandClient.send.payment({ - * sender: 'SENDERADDRESS', - * receiver: 'RECEIVERADDRESS', - * amount: (4).algos(), - * }) - * ``` - * @example Advanced example - * ```typescript - * const result = await algorandClient.send.payment({ - * amount: (4).algos(), - * receiver: 'RECEIVERADDRESS', - * sender: 'SENDERADDRESS', - * closeRemainderTo: 'CLOSEREMAINDERTOADDRESS', - * lease: 'lease', - * note: 'note', - * // Use this with caution, it's generally better to use algorand.account.rekeyAccount - * rekeyTo: 'REKEYTOADDRESS', - * // You wouldn't normally set this field - * firstValidRound: 1000n, - * validityWindow: 10, - * extraFee: (1000).microAlgos(), - * staticFee: (1000).microAlgos(), - * // Max fee doesn't make sense with extraFee AND staticFee - * // already specified, but here for completeness - * maxFee: (3000).microAlgos(), - * }) - * ``` - * - * @returns The payment transaction - */ - payment: this._transaction((c) => c.addPayment), - /** Create a create Algorand Standard Asset transaction. - * - * The account that sends this transaction will automatically be - * opted in to the asset and will hold all units after creation. - * - * @param params The parameters for the asset creation transaction - * - * @example Basic example - * ```typescript - * await algorand.transaction.assetCreate({sender: "CREATORADDRESS", total: 100n}) - * ``` - * @example Advanced example - * ```typescript - * await algorand.transaction.assetCreate({ - * sender: 'CREATORADDRESS', - * total: 100n, - * decimals: 2, - * assetName: 'asset', - * unitName: 'unit', - * url: 'url', - * metadataHash: 'metadataHash', - * defaultFrozen: false, - * manager: 'MANAGERADDRESS', - * reserve: 'RESERVEADDRESS', - * freeze: 'FREEZEADDRESS', - * clawback: 'CLAWBACKADDRESS', - * lease: 'lease', - * note: 'note', - * // You wouldn't normally set this field - * firstValidRound: 1000n, - * validityWindow: 10, - * extraFee: (1000).microAlgos(), - * staticFee: (1000).microAlgos(), - * // Max fee doesn't make sense with extraFee AND staticFee - * // already specified, but here for completeness - * maxFee: (3000).microAlgos(), - * }) - * ``` - * @returns The asset create transaction - */ - assetCreate: this._transaction((c) => c.addAssetCreate), - /** Create an asset config transaction to reconfigure an existing Algorand Standard Asset. - * - * **Note:** The manager, reserve, freeze, and clawback addresses - * are immutably empty if they are not set. If manager is not set then - * all fields are immutable from that point forward. - * - * @param params The parameters for the asset config transaction - * - * @example Basic example - * ```typescript - * await algorand.transaction.assetConfig({sender: "MANAGERADDRESS", assetId: 123456n, manager: "MANAGERADDRESS" }) - * ``` - * @example Advanced example - * ```typescript - * await algorand.transaction.assetConfig({ - * sender: 'MANAGERADDRESS', - * assetId: 123456n, - * manager: 'MANAGERADDRESS', - * reserve: 'RESERVEADDRESS', - * freeze: 'FREEZEADDRESS', - * clawback: 'CLAWBACKADDRESS', - * lease: 'lease', - * note: 'note', - * // You wouldn't normally set this field - * firstValidRound: 1000n, - * validityWindow: 10, - * extraFee: (1000).microAlgos(), - * staticFee: (1000).microAlgos(), - * // Max fee doesn't make sense with extraFee AND staticFee - * // already specified, but here for completeness - * maxFee: (3000).microAlgos(), - * }) - * ``` - * @returns The asset config transaction - */ - assetConfig: this._transaction((c) => c.addAssetConfig), - /** Create an Algorand Standard Asset freeze transaction. - * - * @param params The parameters for the asset freeze transaction - * - * @example Basic example - * ```typescript - * await algorand.transaction.assetFreeze({sender: "MANAGERADDRESS", assetId: 123456n, account: "ACCOUNTADDRESS", frozen: true }) - * ``` - * @example Advanced example - * ```typescript - * await algorand.transaction.assetFreeze({ - * sender: 'MANAGERADDRESS', - * assetId: 123456n, - * account: 'ACCOUNTADDRESS', - * frozen: true, - * lease: 'lease', - * note: 'note', - * // You wouldn't normally set this field - * firstValidRound: 1000n, - * validityWindow: 10, - * extraFee: (1000).microAlgos(), - * staticFee: (1000).microAlgos(), - * // Max fee doesn't make sense with extraFee AND staticFee - * // already specified, but here for completeness - * maxFee: (3000).microAlgos(), - * }) - * ``` - * @returns The asset freeze transaction - */ - assetFreeze: this._transaction((c) => c.addAssetFreeze), - /** Create an Algorand Standard Asset destroy transaction. - * - * Created assets can be destroyed only by the asset manager account. - * All of the assets must be owned by the creator of the asset before - * the asset can be deleted. - * - * @param params The parameters for the asset destroy transaction - * - * @example Basic example - * ```typescript - * await algorand.transaction.assetDestroy({sender: "MANAGERADDRESS", assetId: 123456n }) - * ``` - * @example Advanced example - * ```typescript - * await algorand.transaction.assetDestroy({ - * sender: 'MANAGERADDRESS', - * assetId: 123456n, - * lease: 'lease', - * note: 'note', - * // You wouldn't normally set this field - * firstValidRound: 1000n, - * validityWindow: 10, - * extraFee: (1000).microAlgos(), - * staticFee: (1000).microAlgos(), - * // Max fee doesn't make sense with extraFee AND staticFee - * // already specified, but here for completeness - * maxFee: (3000).microAlgos(), - * }) - * ``` - * @returns The asset destroy transaction - */ - assetDestroy: this._transaction((c) => c.addAssetDestroy), - /** Create an Algorand Standard Asset transfer transaction. - * - * @param params The parameters for the asset transfer transaction - * - * @example Basic example - * ```typescript - * await algorand.transaction.assetTransfer({sender: "HOLDERADDRESS", assetId: 123456n, amount: 1n, receiver: "RECEIVERADDRESS" }) - * ``` - * @example Advanced example (with clawback) - * ```typescript - * await algorand.transaction.assetTransfer({ - * sender: 'CLAWBACKADDRESS', - * assetId: 123456n, - * amount: 1n, - * receiver: 'RECEIVERADDRESS', - * clawbackTarget: 'HOLDERADDRESS', - * // This field needs to be used with caution - * closeAssetTo: 'ADDRESSTOCLOSETO' - * lease: 'lease', - * note: 'note', - * // You wouldn't normally set this field - * firstValidRound: 1000n, - * validityWindow: 10, - * extraFee: (1000).microAlgos(), - * staticFee: (1000).microAlgos(), - * // Max fee doesn't make sense with extraFee AND staticFee - * // already specified, but here for completeness - * maxFee: (3000).microAlgos(), - * }) - * ``` - * @returns The result of the asset transfer transaction - */ - assetTransfer: this._transaction((c) => c.addAssetTransfer), - /** Create an Algorand Standard Asset opt-in transaction. - * - * @param params The parameters for the asset opt-in transaction - * - * @example Basic example - * ```typescript - * await algorand.transaction.assetOptIn({sender: "SENDERADDRESS", assetId: 123456n }) - * ``` - * @example Advanced example - * ```typescript - * await algorand.transaction.assetOptIn({ - * sender: 'SENDERADDRESS', - * assetId: 123456n, - * lease: 'lease', - * note: 'note', - * // You wouldn't normally set this field - * firstValidRound: 1000n, - * validityWindow: 10, - * extraFee: (1000).microAlgos(), - * staticFee: (1000).microAlgos(), - * // Max fee doesn't make sense with extraFee AND staticFee - * // already specified, but here for completeness - * maxFee: (3000).microAlgos(), - * }) - * ``` - * @returns The asset opt-in transaction - */ - assetOptIn: this._transaction((c) => c.addAssetOptIn), - /** Create an asset opt-out transaction. - * - * *Note:* If the account has a balance of the asset, - * it will lose those assets - * - * @param params The parameters for the asset opt-out transaction - * - * @example Basic example - * ```typescript - * await algorand.transaction.assetOptOut({sender: "SENDERADDRESS", creator: "CREATORADDRESS", assetId: 123456n }) - * ``` - * @example Advanced example - * ```typescript - * await algorand.transaction.assetOptIn({ - * sender: 'SENDERADDRESS', - * assetId: 123456n, - * creator: 'CREATORADDRESS', - * ensureZeroBalance: true, - * lease: 'lease', - * note: 'note', - * // You wouldn't normally set this field - * firstValidRound: 1000n, - * validityWindow: 10, - * extraFee: (1000).microAlgos(), - * staticFee: (1000).microAlgos(), - * // Max fee doesn't make sense with extraFee AND staticFee - * // already specified, but here for completeness - * maxFee: (3000).microAlgos(), - * }) - * ``` - * @returns The asset opt-out transaction - */ - assetOptOut: this._transaction((c) => c.addAssetOptOut), - /** Create an application call transaction. */ - appCall: this._transaction((c) => c.addAppCall), - /** Create an application call with ABI method call transaction. */ - methodCall: async (params: MethodCallParams) => { - return (await this.newGroup().addMethodCall(params).build()).transactions.map((ts) => ts.txn) - }, - /** Create an online key registration transaction. */ - onlineKeyRegistration: this._transaction((c) => c.addOnlineKeyRegistration), + public get transactions() { + return this._transactionCreator } // Static methods to create an `AlgorandClient` diff --git a/src/types/app-client.ts b/src/types/app-client.ts index 84c0e24a..56f8319f 100644 --- a/src/types/app-client.ts +++ b/src/types/app-client.ts @@ -15,7 +15,7 @@ import { import { deployApp, getCreatorAppsByName, performTemplateSubstitution, replaceDeployTimeControlParams } from '../app-deploy' import { Config } from '../config' import { persistSourceMaps } from '../debugging/debugging' -import { legacySendTransactionBridgeComposer } from '../transaction/legacy-bridge' +import { legacySendTransactionBridge } from '../transaction/legacy-bridge' import { encodeTransactionNote, getSenderAddress } from '../transaction/transaction' import { AlgoAmount } from './amount' import { @@ -736,17 +736,18 @@ export class ApplicationClient { } const ref = await this.getAppReference() - return legacySendTransactionBridgeComposer( + return legacySendTransactionBridge( this.algod, sender ?? this.sender!, + sendParams ?? {}, { receiver: ref.appAddress, sender: getSenderAddress(sender ?? this.sender!), amount: amount, note: encodeTransactionNote(note), }, - (c) => c.addPayment, - sendParams, + (c) => c.payment, + (c) => c.payment, this.params, ) } diff --git a/src/types/asset-manager.ts b/src/types/asset-manager.ts index a41825ad..a14279c4 100644 --- a/src/types/asset-manager.ts +++ b/src/types/asset-manager.ts @@ -2,8 +2,6 @@ import algosdk from 'algosdk' import { Config } from '../config' import { chunkArray } from '../util' import { AccountAssetInformation, TransactionSignerAccount } from './account' -import { AccountManager } from './account-manager' -import { ClientManager } from './client-manager' import AlgoKitComposer, { CommonTransactionParams, ExecuteParams, MAX_TRANSACTION_GROUP_SIZE } from './composer' import AssetModel = algosdk.modelsv2.Asset @@ -138,28 +136,21 @@ export interface AssetInformation { /** Allows management of asset information. */ export class AssetManager { - private _clientManager: ClientManager - private _accountManager: AccountManager + private _algod: algosdk.Algodv2 + private _newGroup: () => AlgoKitComposer /** * Create a new asset manager. - * @param clientManager The ClientManager client to use for algod client + * @param algod An algod client + * @param newGroup A function that creates a new `AlgoKitComposer` transaction group * @example Create a new asset manager * ```typescript - * const assetManager = new AssetManager(clientManager) + * const assetManager = new AssetManager(algod, () => new AlgoKitComposer({algod, () => signer, () => suggestedParams})) * ``` */ - constructor(clientManager: ClientManager, accountManager: AccountManager) { - this._clientManager = clientManager - this._accountManager = accountManager - } - - private _getComposer(getSuggestedParams?: () => Promise) { - return new AlgoKitComposer({ - algod: this._clientManager.algod, - getSigner: this._accountManager.getSigner.bind(this._accountManager), - getSuggestedParams: getSuggestedParams ?? (() => this._clientManager.algod.getTransactionParams().do()), - }) + constructor(algod: algosdk.Algodv2, newGroup: () => AlgoKitComposer) { + this._algod = algod + this._newGroup = newGroup } /** @@ -174,7 +165,7 @@ export class AssetManager { * @returns The asset information */ public async getById(assetId: bigint): Promise { - const asset = AssetModel.from_obj_for_encoding(await this._clientManager.algod.getAssetByID(Number(assetId)).do()) + const asset = AssetModel.from_obj_for_encoding(await this._algod.getAssetByID(Number(assetId)).do()) return { assetId: BigInt(asset.index), @@ -212,9 +203,7 @@ export class AssetManager { * @returns The account asset holding information */ public async getAccountInformation(sender: string | TransactionSignerAccount, assetId: bigint): Promise { - const info = await this._clientManager.algod - .accountAssetInformation(typeof sender === 'string' ? sender : sender.addr, Number(assetId)) - .do() + const info = await this._algod.accountAssetInformation(typeof sender === 'string' ? sender : sender.addr, Number(assetId)).do() return { assetId: BigInt(assetId), @@ -248,10 +237,8 @@ export class AssetManager { ): Promise { const results: BulkAssetOptInOutResult[] = [] - const params = await this._clientManager.algod.getTransactionParams().do() - for (const assetGroup of chunkArray(assetIds, MAX_TRANSACTION_GROUP_SIZE)) { - const composer = this._getComposer(() => Promise.resolve(params)) + const composer = this._newGroup() for (const assetId of assetGroup) { composer.addAssetOptIn({ @@ -311,11 +298,11 @@ export class AssetManager { ): Promise { const results: BulkAssetOptInOutResult[] = [] - const params = await this._clientManager.algod.getTransactionParams().do() + const params = await this._algod.getTransactionParams().do() const sender = typeof account === 'string' ? account : account.addr for (const assetGroup of chunkArray(assetIds, MAX_TRANSACTION_GROUP_SIZE)) { - const composer = this._getComposer(() => Promise.resolve(params)) + const composer = this._newGroup() const notOptedInAssetIds: bigint[] = [] const nonZeroBalanceAssetIds: bigint[] = [] diff --git a/src/types/composer.ts b/src/types/composer.ts index c24e1eba..e640c3ed 100644 --- a/src/types/composer.ts +++ b/src/types/composer.ts @@ -629,6 +629,7 @@ export default class AlgoKitComposer { private async buildMethodCall( params: MethodCallParams, suggestedParams: algosdk.SuggestedParams, + includeSigner: boolean, ): Promise { const methodArgs: algosdk.ABIArgument[] = [] const isAbiValue = (x: unknown): x is algosdk.ABIValue => { @@ -649,7 +650,7 @@ export default class AlgoKitComposer { } if ('method' in arg) { - const tempTxnWithSigners = await this.buildMethodCall(arg, suggestedParams) + const tempTxnWithSigners = await this.buildMethodCall(arg, suggestedParams, includeSigner) methodArgs.push(...tempTxnWithSigners) continue } @@ -657,11 +658,13 @@ export default class AlgoKitComposer { const txn = await arg methodArgs.push({ txn, - signer: params.signer - ? 'signer' in params.signer - ? params.signer.signer - : params.signer - : this.getSigner(encodeAddress(txn.from.publicKey)), + signer: includeSigner + ? params.signer + ? 'signer' in params.signer + ? params.signer.signer + : params.signer + : this.getSigner(encodeAddress(txn.from.publicKey)) + : algosdk.makeEmptyTransactionSigner(), }) } @@ -841,7 +844,40 @@ export default class AlgoKitComposer { return this.commonTxnBuildStep(params, txn, suggestedParams) } - private async buildTxn(txn: Txn, suggestedParams: algosdk.SuggestedParams): Promise { + private async buildTxn(txn: Txn, suggestedParams: algosdk.SuggestedParams): Promise { + switch (txn.type) { + case 'txnWithSigner': + return [txn.txn] + case 'atc': + return txn.atc.buildGroup().map((ts) => ts.txn) + case 'methodCall': + return (await this.buildMethodCall(txn, suggestedParams, false)).map((ts) => ts.txn) + case 'pay': + return [this.buildPayment(txn, suggestedParams)] + case 'assetCreate': + return [this.buildAssetCreate(txn, suggestedParams)] + case 'appCall': + return [this.buildAppCall(txn, suggestedParams)] + case 'assetConfig': + return [this.buildAssetConfig(txn, suggestedParams)] + case 'assetDestroy': + return [this.buildAssetDestroy(txn, suggestedParams)] + case 'assetFreeze': + return [this.buildAssetFreeze(txn, suggestedParams)] + case 'assetTransfer': + return [this.buildAssetTransfer(txn, suggestedParams)] + case 'assetOptIn': + return [this.buildAssetTransfer({ ...txn, receiver: txn.sender, amount: 0n }, suggestedParams)] + case 'assetOptOut': + return [this.buildAssetTransfer({ ...txn, receiver: txn.sender, amount: 0n, closeAssetTo: txn.creator }, suggestedParams)] + case 'keyReg': + return [this.buildKeyReg(txn, suggestedParams)] + default: + throw Error(`Unsupported txn type`) + } + } + + private async buildTxnWithSigner(txn: Txn, suggestedParams: algosdk.SuggestedParams): Promise { if (txn.type === 'txnWithSigner') { return [txn] } @@ -851,58 +887,29 @@ export default class AlgoKitComposer { } if (txn.type === 'methodCall') { - return await this.buildMethodCall(txn, suggestedParams) + return await this.buildMethodCall(txn, suggestedParams, true) } const signer = txn.signer ? ('signer' in txn.signer ? txn.signer.signer : txn.signer) : this.getSigner(txn.sender) - switch (txn.type) { - case 'pay': { - const payment = this.buildPayment(txn, suggestedParams) - return [{ txn: payment, signer }] - } - case 'assetCreate': { - const assetCreate = this.buildAssetCreate(txn, suggestedParams) - return [{ txn: assetCreate, signer }] - } - case 'appCall': { - const appCall = this.buildAppCall(txn, suggestedParams) - return [{ txn: appCall, signer }] - } - case 'assetConfig': { - const assetConfig = this.buildAssetConfig(txn, suggestedParams) - return [{ txn: assetConfig, signer }] - } - case 'assetDestroy': { - const assetDestroy = this.buildAssetDestroy(txn, suggestedParams) - return [{ txn: assetDestroy, signer }] - } - case 'assetFreeze': { - const assetFreeze = this.buildAssetFreeze(txn, suggestedParams) - return [{ txn: assetFreeze, signer }] - } - case 'assetTransfer': { - const assetTransfer = this.buildAssetTransfer(txn, suggestedParams) - return [{ txn: assetTransfer, signer }] - } - case 'assetOptIn': { - const assetTransfer = this.buildAssetTransfer({ ...txn, receiver: txn.sender, amount: 0n }, suggestedParams) - return [{ txn: assetTransfer, signer }] - } - case 'assetOptOut': { - const assetTransfer = this.buildAssetTransfer( - { ...txn, receiver: txn.sender, amount: 0n, closeAssetTo: txn.creator }, - suggestedParams, - ) - return [{ txn: assetTransfer, signer }] - } - case 'keyReg': { - const keyReg = this.buildKeyReg(txn, suggestedParams) - return [{ txn: keyReg, signer }] - } - default: - throw Error(`Unsupported txn type`) + return (await this.buildTxn(txn, suggestedParams)).map((txn) => ({ txn, signer })) + } + + /** + * Compose all of the transactions without signers and return the transaction objects directly. + * + * @returns The array of built transactions + */ + async buildTransactions() { + const suggestedParams = await this.getSuggestedParams() + + const transactions: algosdk.Transaction[] = [] + + for (const txn of this.txns) { + transactions.push(...(await this.buildTxn(txn, suggestedParams))) } + + return transactions } /** @@ -918,7 +925,7 @@ export default class AlgoKitComposer { const txnWithSigners: algosdk.TransactionWithSigner[] = [] for (const txn of this.txns) { - txnWithSigners.push(...(await this.buildTxn(txn, suggestedParams))) + txnWithSigners.push(...(await this.buildTxnWithSigner(txn, suggestedParams))) } txnWithSigners.forEach((ts) => { From c0313a068178726c6a848fb357730d478dc45e24 Mon Sep 17 00:00:00 2001 From: "Rob Moore (MakerX)" Date: Wed, 28 Aug 2024 01:46:31 +0800 Subject: [PATCH 14/18] fix: Removing circular dependency --- docs/code/classes/types_composer.default.md | 30 ++++++++++----------- docs/code/modules/types_network_client.md | 28 +++++++++++++++++++ src/types/client-manager.ts | 4 +-- src/types/composer.ts | 6 ++--- src/types/network-client.ts | 9 +++++++ 5 files changed, 56 insertions(+), 21 deletions(-) diff --git a/docs/code/classes/types_composer.default.md b/docs/code/classes/types_composer.default.md index b4a28fa3..2af765c5 100644 --- a/docs/code/classes/types_composer.default.md +++ b/docs/code/classes/types_composer.default.md @@ -505,7 +505,7 @@ The built atomic transaction composer and the transactions #### Defined in -[src/types/composer.ts:921](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/composer.ts#L921) +[src/types/composer.ts:919](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/composer.ts#L919) ___ @@ -526,7 +526,7 @@ ___ #### Defined in -[src/types/composer.ts:789](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/composer.ts#L789) +[src/types/composer.ts:787](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/composer.ts#L787) ___ @@ -547,7 +547,7 @@ ___ #### Defined in -[src/types/composer.ts:738](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/composer.ts#L738) +[src/types/composer.ts:736](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/composer.ts#L736) ___ @@ -568,7 +568,7 @@ ___ #### Defined in -[src/types/composer.ts:718](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/composer.ts#L718) +[src/types/composer.ts:716](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/composer.ts#L716) ___ @@ -589,7 +589,7 @@ ___ #### Defined in -[src/types/composer.ts:753](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/composer.ts#L753) +[src/types/composer.ts:751](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/composer.ts#L751) ___ @@ -610,7 +610,7 @@ ___ #### Defined in -[src/types/composer.ts:763](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/composer.ts#L763) +[src/types/composer.ts:761](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/composer.ts#L761) ___ @@ -631,7 +631,7 @@ ___ #### Defined in -[src/types/composer.ts:775](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/composer.ts#L775) +[src/types/composer.ts:773](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/composer.ts#L773) ___ @@ -672,7 +672,7 @@ ___ #### Defined in -[src/types/composer.ts:829](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/composer.ts#L829) +[src/types/composer.ts:827](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/composer.ts#L827) ___ @@ -694,7 +694,7 @@ ___ #### Defined in -[src/types/composer.ts:629](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/composer.ts#L629) +[src/types/composer.ts:627](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/composer.ts#L627) ___ @@ -715,7 +715,7 @@ ___ #### Defined in -[src/types/composer.ts:706](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/composer.ts#L706) +[src/types/composer.ts:704](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/composer.ts#L704) ___ @@ -733,7 +733,7 @@ The array of built transactions #### Defined in -[src/types/composer.ts:903](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/composer.ts#L903) +[src/types/composer.ts:901](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/composer.ts#L901) ___ @@ -754,7 +754,7 @@ ___ #### Defined in -[src/types/composer.ts:847](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/composer.ts#L847) +[src/types/composer.ts:845](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/composer.ts#L845) ___ @@ -775,7 +775,7 @@ ___ #### Defined in -[src/types/composer.ts:880](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/composer.ts#L880) +[src/types/composer.ts:878](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/composer.ts#L878) ___ @@ -821,7 +821,7 @@ The execution result #### Defined in -[src/types/composer.ts:963](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/composer.ts#L963) +[src/types/composer.ts:961](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/composer.ts#L961) ___ @@ -840,4 +840,4 @@ The newly built atomic transaction composer and the transactions #### Defined in -[src/types/composer.ts:953](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/composer.ts#L953) +[src/types/composer.ts:951](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/composer.ts#L951) diff --git a/docs/code/modules/types_network_client.md b/docs/code/modules/types_network_client.md index 4a035f02..10c87334 100644 --- a/docs/code/modules/types_network_client.md +++ b/docs/code/modules/types_network_client.md @@ -8,3 +8,31 @@ - [AlgoClientConfig](../interfaces/types_network_client.AlgoClientConfig.md) - [AlgoConfig](../interfaces/types_network_client.AlgoConfig.md) + +### Functions + +- [genesisIdIsLocalNet](types_network_client.md#genesisidislocalnet) + +## Functions + +### genesisIdIsLocalNet + +▸ **genesisIdIsLocalNet**(`genesisId`): `boolean` + +Returns true if the given network genesisId is associated with a LocalNet network. + +#### Parameters + +| Name | Type | Description | +| :------ | :------ | :------ | +| `genesisId` | `string` | The network genesis ID | + +#### Returns + +`boolean` + +Whether the given genesis ID is associated with a LocalNet network + +#### Defined in + +[src/types/network-client.ts:28](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/network-client.ts#L28) diff --git a/src/types/client-manager.ts b/src/types/client-manager.ts index 8c692f2e..80bf2300 100644 --- a/src/types/client-manager.ts +++ b/src/types/client-manager.ts @@ -11,7 +11,7 @@ import { ResolveAppByIdBase, } from './app-client' import { TestNetDispenserApiClient, TestNetDispenserApiClientParams } from './dispenser-client' -import { AlgoClientConfig, AlgoConfig } from './network-client' +import { AlgoClientConfig, AlgoConfig, genesisIdIsLocalNet } from './network-client' import Kmd = algosdk.Kmd import Indexer = algosdk.Indexer import Algodv2 = algosdk.Algodv2 @@ -129,7 +129,7 @@ export class ClientManager { * @returns Whether the given genesis ID is associated with a LocalNet network */ public static genesisIdIsLocalNet(genesisId: string) { - return genesisId === 'devnet-v1' || genesisId === 'sandnet-v1' || genesisId === 'dockernet-v1' + return genesisIdIsLocalNet(genesisId) } /** diff --git a/src/types/composer.ts b/src/types/composer.ts index e640c3ed..04cb0f99 100644 --- a/src/types/composer.ts +++ b/src/types/composer.ts @@ -2,7 +2,7 @@ import algosdk from 'algosdk' import { encodeLease, encodeTransactionNote, sendAtomicTransactionComposer } from '../transaction/transaction' import { TransactionSignerAccount } from './account' import { AlgoAmount } from './amount' -import { ClientManager } from './client-manager' +import { genesisIdIsLocalNet } from './network-client' import { SendAtomicTransactionComposerResults } from './transaction' import Transaction = algosdk.Transaction import TransactionWithSigner = algosdk.TransactionWithSigner @@ -601,9 +601,7 @@ export default class AlgoKitComposer { // LocalNet set a bigger window to avoid dead transactions const window = params.validityWindow ?? - (!this.defaultValidityWindowIsExplicit && ClientManager.genesisIdIsLocalNet(suggestedParams.genesisID) - ? 1000 - : this.defaultValidityWindow) + (!this.defaultValidityWindowIsExplicit && genesisIdIsLocalNet(suggestedParams.genesisID) ? 1000 : this.defaultValidityWindow) txn.lastRound = txn.firstRound + window } diff --git a/src/types/network-client.ts b/src/types/network-client.ts index 2b371d18..61a091d7 100644 --- a/src/types/network-client.ts +++ b/src/types/network-client.ts @@ -19,3 +19,12 @@ export interface AlgoConfig { /** Kmd configuration */ kmdConfig?: AlgoClientConfig } + +/** + * Returns true if the given network genesisId is associated with a LocalNet network. + * @param genesisId The network genesis ID + * @returns Whether the given genesis ID is associated with a LocalNet network + */ +export function genesisIdIsLocalNet(genesisId: string) { + return genesisId === 'devnet-v1' || genesisId === 'sandnet-v1' || genesisId === 'dockernet-v1' +} From f88b4c8ad43c9b15704acda8b241ad0bc0d087cc Mon Sep 17 00:00:00 2001 From: "Rob Moore (MakerX)" Date: Wed, 28 Aug 2024 01:55:31 +0800 Subject: [PATCH 15/18] fix: Resolving circular dependency --- src/account/account.ts | 2 +- src/asset.ts | 2 +- src/transfer/transfer.ts | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/account/account.ts b/src/account/account.ts index 1b565fde..ec691d2f 100644 --- a/src/account/account.ts +++ b/src/account/account.ts @@ -1,8 +1,8 @@ import algosdk from 'algosdk' -import { AlgorandClient } from '..' import { getSenderAddress } from '../transaction/transaction' import { AccountAssetInformation, MultisigAccount, SigningAccount, TransactionSignerAccount } from '../types/account' import { AccountManager } from '../types/account-manager' +import { AlgorandClient } from '../types/algorand-client' import { AlgoAmount } from '../types/amount' import { ClientManager } from '../types/client-manager' import { SendTransactionFrom } from '../types/transaction' diff --git a/src/asset.ts b/src/asset.ts index f7234a32..4ee93f34 100644 --- a/src/asset.ts +++ b/src/asset.ts @@ -1,7 +1,7 @@ import algosdk from 'algosdk' -import { AlgorandClient } from '.' import { encodeTransactionNote, getSenderAddress } from './transaction' import { legacySendTransactionBridge } from './transaction/legacy-bridge' +import { AlgorandClient } from './types/algorand-client' import { AssetBulkOptInOutParams, AssetOptInParams, AssetOptOutParams, CreateAssetParams } from './types/asset' import { ClientManager } from './types/client-manager' import { AssetCreateParams, AssetOptInParams as NewAssetOptInParams, AssetOptOutParams as NewAssetOptOutParams } from './types/composer' diff --git a/src/transfer/transfer.ts b/src/transfer/transfer.ts index a04a4a31..f9715d6e 100644 --- a/src/transfer/transfer.ts +++ b/src/transfer/transfer.ts @@ -1,7 +1,7 @@ import algosdk from 'algosdk' -import { AlgorandClient } from '..' import { legacySendTransactionBridge } from '../transaction/legacy-bridge' import { encodeTransactionNote, getSenderAddress } from '../transaction/transaction' +import { AlgorandClient } from '../types/algorand-client' import { TestNetDispenserApiClient } from '../types/dispenser-client' import { SendTransactionResult } from '../types/transaction' import { AlgoRekeyParams, EnsureFundedParams, EnsureFundedReturnType, TransferAssetParams } from '../types/transfer' From 6ed993e1ac6122057205a82c6f874825308df6e4 Mon Sep 17 00:00:00 2001 From: "Rob Moore (MakerX)" Date: Wed, 28 Aug 2024 13:49:19 +0800 Subject: [PATCH 16/18] chore: PR review --- docs/capabilities/account.md | 2 +- .../types_algorand_client.AlgorandClient.md | 2 +- ...rand_client_sender.AlgorandClientSender.md | 2 +- ...reator.AlgorandClientTransactionCreator.md | 32 +++++++++---------- docs/code/modules/types_composer.md | 2 +- src/transaction/legacy-bridge.ts | 2 +- src/types/algorand-client-sender.ts | 2 +- .../algorand-client-transaction-creator.ts | 7 ++-- src/types/algorand-client.ts | 2 +- src/types/composer.ts | 2 +- 10 files changed, 27 insertions(+), 28 deletions(-) diff --git a/docs/capabilities/account.md b/docs/capabilities/account.md index df05ba72..f106eb2b 100644 --- a/docs/capabilities/account.md +++ b/docs/capabilities/account.md @@ -4,7 +4,7 @@ Account management is one of the core capabilities provided by AlgoKit Utils. It ## `AccountManager` -The [`AccountManager`](../code/classes/types_account_manager.AccountManager.md) is a class that is used to get, create, and fund accounts and perform account-related actions such as funding. The `AccountManager` also keeps track of signers for each address so when using the [`AlgokitComposer`](./algokit-composer.md) to send transactions, a signer function does not need to manually be specified for each transaction - instead it can be inferred from the sender address automatically! +The [`AccountManager`](../code/classes/types_account_manager.AccountManager.md) is a class that is used to get, create, and fund accounts and perform account-related actions such as funding. The `AccountManager` also keeps track of signers for each address so when using the [`AlgoKitComposer`](./algokit-composer.md) to send transactions, a signer function does not need to manually be specified for each transaction - instead it can be inferred from the sender address automatically! To get an instance of `AccountManager`, you can use either [`AlgorandClient`](./algorand-client.md) via `algorand.account` or instantiate it directly (passing in a [`ClientManager`](./client.md)): diff --git a/docs/code/classes/types_algorand_client.AlgorandClient.md b/docs/code/classes/types_algorand_client.AlgorandClient.md index 3df21d65..9bbd9719 100644 --- a/docs/code/classes/types_algorand_client.AlgorandClient.md +++ b/docs/code/classes/types_algorand_client.AlgorandClient.md @@ -261,7 +261,7 @@ ___ ▸ **newGroup**(): [`default`](types_composer.default.md) -Start a new `AlgokitComposer` transaction group +Start a new `AlgoKitComposer` transaction group #### Returns diff --git a/docs/code/classes/types_algorand_client_sender.AlgorandClientSender.md b/docs/code/classes/types_algorand_client_sender.AlgorandClientSender.md index 09a21f56..5891c570 100644 --- a/docs/code/classes/types_algorand_client_sender.AlgorandClientSender.md +++ b/docs/code/classes/types_algorand_client_sender.AlgorandClientSender.md @@ -44,7 +44,7 @@ Creates a new `AlgorandClientSender` | Name | Type | Description | | :------ | :------ | :------ | -| `newGroup` | () => [`default`](types_composer.default.md) | A lambda that Start a new `AlgokitComposer` transaction group | +| `newGroup` | () => [`default`](types_composer.default.md) | A lambda that starts a new `AlgoKitComposer` transaction group | | `assetManager` | [`AssetManager`](types_asset_manager.AssetManager.md) | An `AssetManager` instance | #### Returns diff --git a/docs/code/classes/types_algorand_client_transaction_creator.AlgorandClientTransactionCreator.md b/docs/code/classes/types_algorand_client_transaction_creator.AlgorandClientTransactionCreator.md index e963cad8..acb64b28 100644 --- a/docs/code/classes/types_algorand_client_transaction_creator.AlgorandClientTransactionCreator.md +++ b/docs/code/classes/types_algorand_client_transaction_creator.AlgorandClientTransactionCreator.md @@ -4,7 +4,7 @@ [types/algorand-client-transaction-creator](../modules/types_algorand_client_transaction_creator.md).AlgorandClientTransactionCreator -Orchestrates sending transactions for `AlgorandClient`. +Orchestrates creating transactions for `AlgorandClient`. ## Table of contents @@ -37,13 +37,13 @@ Orchestrates sending transactions for `AlgorandClient`. • **new AlgorandClientTransactionCreator**(`newGroup`): [`AlgorandClientTransactionCreator`](types_algorand_client_transaction_creator.AlgorandClientTransactionCreator.md) -Creates a new `AlgorandClientSender` +Creates a new `AlgorandClientTransactionCreator` #### Parameters | Name | Type | Description | | :------ | :------ | :------ | -| `newGroup` | () => [`default`](types_composer.default.md) | A lambda that Start a new `AlgokitComposer` transaction group | +| `newGroup` | () => [`default`](types_composer.default.md) | A lambda that starts a new `AlgoKitComposer` transaction group | #### Returns @@ -51,7 +51,7 @@ Creates a new `AlgorandClientSender` #### Defined in -[src/types/algorand-client-transaction-creator.ts:15](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/algorand-client-transaction-creator.ts#L15) +[src/types/algorand-client-transaction-creator.ts:14](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/algorand-client-transaction-creator.ts#L14) ## Properties @@ -95,7 +95,7 @@ Create an application call transaction. #### Defined in -[src/types/algorand-client-transaction-creator.ts:297](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/algorand-client-transaction-creator.ts#L297) +[src/types/algorand-client-transaction-creator.ts:296](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/algorand-client-transaction-creator.ts#L296) ___ @@ -154,7 +154,7 @@ await algorand.transaction.assetConfig({ #### Defined in -[src/types/algorand-client-transaction-creator.ts:139](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/algorand-client-transaction-creator.ts#L139) +[src/types/algorand-client-transaction-creator.ts:138](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/algorand-client-transaction-creator.ts#L138) ___ @@ -218,7 +218,7 @@ await algorand.transaction.assetCreate({ #### Defined in -[src/types/algorand-client-transaction-creator.ts:103](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/algorand-client-transaction-creator.ts#L103) +[src/types/algorand-client-transaction-creator.ts:102](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/algorand-client-transaction-creator.ts#L102) ___ @@ -273,7 +273,7 @@ await algorand.transaction.assetDestroy({ #### Defined in -[src/types/algorand-client-transaction-creator.ts:201](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/algorand-client-transaction-creator.ts#L201) +[src/types/algorand-client-transaction-creator.ts:200](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/algorand-client-transaction-creator.ts#L200) ___ @@ -326,7 +326,7 @@ await algorand.transaction.assetFreeze({ #### Defined in -[src/types/algorand-client-transaction-creator.ts:169](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/algorand-client-transaction-creator.ts#L169) +[src/types/algorand-client-transaction-creator.ts:168](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/algorand-client-transaction-creator.ts#L168) ___ @@ -377,7 +377,7 @@ await algorand.transaction.assetOptIn({ #### Defined in -[src/types/algorand-client-transaction-creator.ts:262](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/algorand-client-transaction-creator.ts#L262) +[src/types/algorand-client-transaction-creator.ts:261](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/algorand-client-transaction-creator.ts#L261) ___ @@ -433,7 +433,7 @@ await algorand.transaction.assetOptIn({ #### Defined in -[src/types/algorand-client-transaction-creator.ts:295](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/algorand-client-transaction-creator.ts#L295) +[src/types/algorand-client-transaction-creator.ts:294](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/algorand-client-transaction-creator.ts#L294) ___ @@ -489,7 +489,7 @@ await algorand.transaction.assetTransfer({ #### Defined in -[src/types/algorand-client-transaction-creator.ts:234](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/algorand-client-transaction-creator.ts#L234) +[src/types/algorand-client-transaction-creator.ts:233](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/algorand-client-transaction-creator.ts#L233) ___ @@ -515,7 +515,7 @@ Create an online key registration transaction. #### Defined in -[src/types/algorand-client-transaction-creator.ts:303](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/algorand-client-transaction-creator.ts#L303) +[src/types/algorand-client-transaction-creator.ts:302](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/algorand-client-transaction-creator.ts#L302) ___ @@ -574,7 +574,7 @@ const result = await algorandClient.send.payment({ #### Defined in -[src/types/algorand-client-transaction-creator.ts:62](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/algorand-client-transaction-creator.ts#L62) +[src/types/algorand-client-transaction-creator.ts:61](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/algorand-client-transaction-creator.ts#L61) ## Methods @@ -612,7 +612,7 @@ const result = await algorandClient.send.payment({ #### Defined in -[src/types/algorand-client-transaction-creator.ts:19](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/algorand-client-transaction-creator.ts#L19) +[src/types/algorand-client-transaction-creator.ts:18](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/algorand-client-transaction-creator.ts#L18) ___ @@ -634,4 +634,4 @@ Create an application call with ABI method call transaction. #### Defined in -[src/types/algorand-client-transaction-creator.ts:299](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/algorand-client-transaction-creator.ts#L299) +[src/types/algorand-client-transaction-creator.ts:298](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/algorand-client-transaction-creator.ts#L298) diff --git a/docs/code/modules/types_composer.md b/docs/code/modules/types_composer.md index 25a16eb3..6859c969 100644 --- a/docs/code/modules/types_composer.md +++ b/docs/code/modules/types_composer.md @@ -38,7 +38,7 @@ Ƭ **AlgoKitComposerParams**: `Object` -Parameters to create an `AlgokitComposer`. +Parameters to create an `AlgoKitComposer`. #### Type declaration diff --git a/src/transaction/legacy-bridge.ts b/src/transaction/legacy-bridge.ts index afdcb8a3..cb36bd54 100644 --- a/src/transaction/legacy-bridge.ts +++ b/src/transaction/legacy-bridge.ts @@ -37,7 +37,7 @@ export async function legacySendTransactionBridge AlgoKitComposer, assetManager: AssetManager) { diff --git a/src/types/algorand-client-transaction-creator.ts b/src/types/algorand-client-transaction-creator.ts index b66ee92b..4a4a7bac 100644 --- a/src/types/algorand-client-transaction-creator.ts +++ b/src/types/algorand-client-transaction-creator.ts @@ -3,14 +3,13 @@ import AlgoKitComposer, { MethodCallParams } from './composer' import Transaction = algosdk.Transaction -/** Orchestrates sending transactions for `AlgorandClient`. */ +/** Orchestrates creating transactions for `AlgorandClient`. */ export class AlgorandClientTransactionCreator { private _newGroup: () => AlgoKitComposer /** - * Creates a new `AlgorandClientSender` - * @param newGroup A lambda that Start a new `AlgokitComposer` transaction group - * @param assetManager An `AssetManager` instance + * Creates a new `AlgorandClientTransactionCreator` + * @param newGroup A lambda that starts a new `AlgoKitComposer` transaction group */ constructor(newGroup: () => AlgoKitComposer) { this._newGroup = newGroup diff --git a/src/types/algorand-client.ts b/src/types/algorand-client.ts index b3987938..02204e0e 100644 --- a/src/types/algorand-client.ts +++ b/src/types/algorand-client.ts @@ -140,7 +140,7 @@ export class AlgorandClient { return this._assetManager } - /** Start a new `AlgokitComposer` transaction group */ + /** Start a new `AlgoKitComposer` transaction group */ public newGroup() { return new AlgoKitComposer({ algod: this.client.algod, diff --git a/src/types/composer.ts b/src/types/composer.ts index 04cb0f99..49017c41 100644 --- a/src/types/composer.ts +++ b/src/types/composer.ts @@ -384,7 +384,7 @@ export interface ExecuteParams { suppressLog?: boolean } -/** Parameters to create an `AlgokitComposer`. */ +/** Parameters to create an `AlgoKitComposer`. */ export type AlgoKitComposerParams = { /** The algod client to use to get suggestedParams and send the transaction group */ algod: algosdk.Algodv2 From fed61c96fd8a27eb7e8099436e02e41fc3d56b1d Mon Sep 17 00:00:00 2001 From: "Rob Moore (MakerX)" Date: Wed, 28 Aug 2024 14:02:50 +0800 Subject: [PATCH 17/18] fix: Switched to singular .algo and .microAlgo methods for `AlgoAmount`, retained existing methods to avoid breaking changes --- docs/capabilities/account.md | 10 +- docs/capabilities/algorand-client.md | 2 +- docs/capabilities/amount.md | 20 ++-- docs/capabilities/app-client.md | 2 +- docs/capabilities/asset.md | 34 +++---- docs/capabilities/transfer.md | 32 +++--- docs/capabilities/typed-app-clients.md | 2 +- .../types_account_manager.AccountManager.md | 24 ++--- ...rand_client_sender.AlgorandClientSender.md | 52 +++++----- ...reator.AlgorandClientTransactionCreator.md | 52 +++++----- docs/code/classes/types_amount.AlgoAmount.md | 98 +++++++++++++++++-- .../types_asset_manager.AssetManager.md | 4 +- ...s_kmd_account_manager.KmdAccountManager.md | 2 +- docs/code/modules/index.md | 54 +++++++++- src/amount.ts | 46 ++++++++- src/app.spec.ts | 2 +- src/indexer-lookup.spec.ts | 12 +-- src/testing/account.ts | 2 +- src/transaction/transaction.spec.ts | 46 ++++----- src/transaction/transaction.ts | 6 +- src/transfer/transfer-algos.ts | 2 +- src/transfer/transfer.ts | 6 +- src/types/account-manager.spec.ts | 2 +- src/types/account-manager.ts | 46 ++++----- src/types/algorand-client-sender.ts | 54 +++++----- .../algorand-client-transaction-creator.ts | 52 +++++----- src/types/algorand-client.asset.spec.ts | 16 +-- src/types/algorand-client.spec.ts | 34 +++---- src/types/algorand-client.transfer.spec.ts | 60 ++++++------ src/types/amount.spec.ts | 22 ++--- src/types/amount.ts | 41 ++++++-- src/types/app-client.spec.ts | 16 +-- src/types/asset-manager.ts | 4 +- src/types/composer.ts | 8 +- src/types/kmd-account-manager.ts | 6 +- 35 files changed, 530 insertions(+), 341 deletions(-) diff --git a/docs/capabilities/account.md b/docs/capabilities/account.md index f106eb2b..11fbd9f4 100644 --- a/docs/capabilities/account.md +++ b/docs/capabilities/account.md @@ -97,11 +97,11 @@ await algorand.account.rekeyAccount({ note: 'note', firstValidRound: 1000n, validityWindow: 10, - extraFee: (1000).microAlgos(), - staticFee: (1000).microAlgos(), + extraFee: (1000).microAlgo(), + staticFee: (1000).microAlgo(), // Max fee doesn't make sense with extraFee AND staticFee // already specified, but here for completeness - maxFee: (3000).microAlgos(), + maxFee: (3000).microAlgo(), maxRoundsToWaitForConfirmation: 5, suppressLog: true, }) @@ -147,7 +147,7 @@ const defaultDispenserAccount = await kmdAccountManager.getWalletAccount( const localNetDispenserAccount = await kmdAccountManager.getLocalNetDispenserAccount() // Idempotently get (if exists) or create (if it doesn't exist yet) an account by name using KMD // if creating it then fund it with 2 ALGO from the default dispenser account -const newAccount = await kmdAccountManager.getOrCreateWalletAccount('account1', (2).algos()) +const newAccount = await kmdAccountManager.getOrCreateWalletAccount('account1', (2).algo()) // This will return the same account as above since the name matches const existingAccount = await kmdAccountManager.getOrCreateWalletAccount('account1') ``` @@ -160,5 +160,5 @@ const localNetDispenser = await algorand.account.localNetDispenser() // Get and register a dispenser by environment variable, or if not set then LocalNet dispenser via KMD const dispenser = await algorand.account.dispenserFromEnvironment() // Get / create and register account from KMD idempotently by name -const account1 = await algorand.account.fromKmd('account1', (2).algos()) +const account1 = await algorand.account.fromKmd('account1', (2).algo()) ``` diff --git a/docs/capabilities/algorand-client.md b/docs/capabilities/algorand-client.md index 8489abcf..2cf1d320 100644 --- a/docs/capabilities/algorand-client.md +++ b/docs/capabilities/algorand-client.md @@ -94,7 +94,7 @@ You can compose a group of transactions for execution by using the `newGroup()` ```typescript const result = algorand .newGroup() - .addPayment({ sender: 'SENDERADDRESS', receiver: 'RECEIVERADDRESS', amount: (1).microAlgos() }) + .addPayment({ sender: 'SENDERADDRESS', receiver: 'RECEIVERADDRESS', amount: (1).microAlgo() }) .addAssetOptIn({ sender: 'SENDERADDRESS', assetId: 12345n }) .execute() ``` diff --git a/docs/capabilities/amount.md b/docs/capabilities/amount.md index cfbcefb2..fa9508ca 100644 --- a/docs/capabilities/amount.md +++ b/docs/capabilities/amount.md @@ -23,15 +23,15 @@ You may not need to import this type to use it though since there are also speci There are a few ways to create an `AlgoAmount`: - Algo - - Constructor: `new AlgoAmount({algos: 10})` - - Static helper: `AlgoAmount.algos(10)` - - AlgoKit Helper: `algokit.algos(10)` - - Number coersion: `(10).algos()` (note: you have to wrap the number in brackets or have it in a variable or function return, a raw number value can't have a method called on it) + - Constructor: `new AlgoAmount({algo: 10})` + - Static helper: `AlgoAmount.algo(10)` + - AlgoKit Helper: `algokit.algo(10)` + - Number coersion: `(10).algo()` (note: you have to wrap the number in brackets or have it in a variable or function return, a raw number value can't have a method called on it) - microAlgo - Constructor: `new AlgoAmount({microAlgos: 10_000})` - - Static helper: `AlgoAmount.algos(10)` - - AlgoKit Helper: `algokit.microAlgos(10_000)` - - Number coersion: `(10_000).microAlgos()` (note: you have to wrap the number in brackets or have it in a variable or function return, a raw number value can't have a method called on it) + - Static helper: `AlgoAmount.algo(10)` + - AlgoKit Helper: `algokit.microAlgo(10_000)` + - Number coersion: `(10_000).microAlgo()` (note: you have to wrap the number in brackets or have it in a variable or function return, a raw number value can't have a method called on it) Note: per above, to use any of the versions that reference `AlgoAmount` type itself you need to import it: @@ -41,10 +41,10 @@ import { AlgoAmount } from '@algorandfoundation/algokit-utils/types/amount' ### Extracting a value from `AlgoAmount` -The `AlgoAmount` class has methods to return Algo and microAlgo: +The `AlgoAmount` class has properties to return Algo and microAlgo: -- `amount.algos()` - Returns the value in Algo -- `amount.microAlgos()` - Returns the value in microAlgo +- `amount.algo` - Returns the value in Algo +- `amount.microAlgo` - Returns the value in microAlgo `AlgoAmount` will coerce to a `number` automatically (in microAlgo), which is not recommended to be used outside of allowing you to use `AlgoAmount` objects in comparison operations such as `<` and `>=` etc. diff --git a/docs/capabilities/app-client.md b/docs/capabilities/app-client.md index 543b8fff..277f536f 100644 --- a/docs/capabilities/app-client.md +++ b/docs/capabilities/app-client.md @@ -153,7 +153,7 @@ const result = await appClient.call({ methodArgs: { args: [ appClient.fundAppAccount({ - amount: algokit.microAlgos(200_000), + amount: algokit.microAlgo(200_000), sendParams: { skipSending: true }, }), ], diff --git a/docs/capabilities/asset.md b/docs/capabilities/asset.md index a5fd8aa0..5df19607 100644 --- a/docs/capabilities/asset.md +++ b/docs/capabilities/asset.md @@ -60,11 +60,11 @@ await algorand.send.assetCreate({ // You wouldn't normally set this field firstValidRound: 1000n, validityWindow: 10, - extraFee: (1000).microAlgos(), - staticFee: (1000).microAlgos(), + extraFee: (1000).microAlgo(), + staticFee: (1000).microAlgo(), // Max fee doesn't make sense with extraFee AND staticFee // already specified, but here for completeness - maxFee: (3000).microAlgos(), + maxFee: (3000).microAlgo(), // Signer only needed if you want to provide one, // generally you'd register it with AlgorandClient // against the sender and not need to pass it in @@ -112,11 +112,11 @@ await algorand.send.assetConfig({ // You wouldn't normally set this field firstValidRound: 1000n, validityWindow: 10, - extraFee: (1000).microAlgos(), - staticFee: (1000).microAlgos(), + extraFee: (1000).microAlgo(), + staticFee: (1000).microAlgo(), // Max fee doesn't make sense with extraFee AND staticFee // already specified, but here for completeness - maxFee: (3000).microAlgos(), + maxFee: (3000).microAlgo(), // Signer only needed if you want to provide one, // generally you'd register it with AlgorandClient // against the sender and not need to pass it in @@ -162,11 +162,11 @@ await algorand.send.assetTransfer({ // You wouldn't normally set this field firstValidRound: 1000n, validityWindow: 10, - extraFee: (1000).microAlgos(), - staticFee: (1000).microAlgos(), + extraFee: (1000).microAlgo(), + staticFee: (1000).microAlgo(), // Max fee doesn't make sense with extraFee AND staticFee // already specified, but here for completeness - maxFee: (3000).microAlgos(), + maxFee: (3000).microAlgo(), // Signer only needed if you want to provide one, // generally you'd register it with AlgorandClient // against the sender and not need to pass it in @@ -209,11 +209,11 @@ await algorand.send.assetOptIn({ // You wouldn't normally set this field firstValidRound: 1000n, validityWindow: 10, - extraFee: (1000).microAlgos(), - staticFee: (1000).microAlgos(), + extraFee: (1000).microAlgo(), + staticFee: (1000).microAlgo(), // Max fee doesn't make sense with extraFee AND staticFee // already specified, but here for completeness - maxFee: (3000).microAlgos(), + maxFee: (3000).microAlgo(), // Signer only needed if you want to provide one, // generally you'd register it with AlgorandClient // against the sender and not need to pass it in @@ -260,11 +260,11 @@ await algorand.send.assetOptOut({ // You wouldn't normally set this field firstValidRound: 1000n, validityWindow: 10, - extraFee: (1000).microAlgos(), - staticFee: (1000).microAlgos(), + extraFee: (1000).microAlgo(), + staticFee: (1000).microAlgo(), // Max fee doesn't make sense with extraFee AND staticFee // already specified, but here for completeness - maxFee: (3000).microAlgos(), + maxFee: (3000).microAlgo(), // Signer only needed if you want to provide one, // generally you'd register it with AlgorandClient // against the sender and not need to pass it in @@ -286,7 +286,7 @@ algorand.asset.bulkOptIn('ACCOUNTADDRESS', [12345n, 67890n]) // Advanced example algorand.asset.bulkOptIn('ACCOUNTADDRESS', [12345n, 67890n], { - maxFee: (1000).microAlgos(), + maxFee: (1000).microAlgo(), suppressLog: true, }) ``` @@ -304,7 +304,7 @@ algorand.asset.bulkOptOut('ACCOUNTADDRESS', [12345n, 67890n]) algorand.asset.bulkOptOut('ACCOUNTADDRESS', [12345n, 67890n], { ensureZeroBalance: true, - maxFee: (1000).microAlgos(), + maxFee: (1000).microAlgo(), suppressLog: true, }) ``` diff --git a/docs/capabilities/transfer.md b/docs/capabilities/transfer.md index b8a2bc85..9d6685f5 100644 --- a/docs/capabilities/transfer.md +++ b/docs/capabilities/transfer.md @@ -19,14 +19,14 @@ The base type for specifying a payment transaction is [`PaymentParams`](../code/ const result = await algorand.send.payment({ sender: 'SENDERADDRESS', receiver: 'RECEIVERADDRESS', - amount: (4).algos(), + amount: (4).algo(), }) // Advanced example const result2 = await algorand.send.payment({ sender: 'SENDERADDRESS', receiver: 'RECEIVERADDRESS', - amount: (4).algos(), + amount: (4).algo(), closeRemainderTo: 'CLOSEREMAINDERTOADDRESS', lease: 'lease', note: 'note', @@ -35,11 +35,11 @@ const result2 = await algorand.send.payment({ // You wouldn't normally set this field firstValidRound: 1000n, validityWindow: 10, - extraFee: (1000).microAlgos(), - staticFee: (1000).microAlgos(), + extraFee: (1000).microAlgo(), + staticFee: (1000).microAlgo(), // Max fee doesn't make sense with extraFee AND staticFee // already specified, but here for completeness - maxFee: (3000).microAlgos(), + maxFee: (3000).microAlgo(), // Signer only needed if you want to provide one, // generally you'd register it with AlgorandClient // against the sender and not need to pass it in @@ -81,22 +81,22 @@ The general structure of these calls is similar, they all take: // From account // Basic example -await algorand.account.ensureFunded('ACCOUNTADDRESS', 'DISPENSERADDRESS', algokit.algos(1)) +await algorand.account.ensureFunded('ACCOUNTADDRESS', 'DISPENSERADDRESS', algokit.algo(1)) // With configuration -await algorand.account.ensureFunded('ACCOUNTADDRESS', 'DISPENSERADDRESS', algokit.algos(1), { - minFundingIncrement: algokit.algos(2), - fee: (1000).microAlgos(), +await algorand.account.ensureFunded('ACCOUNTADDRESS', 'DISPENSERADDRESS', algokit.algo(1), { + minFundingIncrement: algokit.algo(2), + fee: (1000).microAlgo(), suppressLog: true, }) // From environment // Basic example -await algorand.account.ensureFundedFromEnvironment('ACCOUNTADDRESS', algokit.algos(1)) +await algorand.account.ensureFundedFromEnvironment('ACCOUNTADDRESS', algokit.algo(1)) // With configuration -await algorand.account.ensureFundedFromEnvironment('ACCOUNTADDRESS', algokit.algos(1), { - minFundingIncrement: algokit.algos(2), - fee: (1000).microAlgos(), +await algorand.account.ensureFundedFromEnvironment('ACCOUNTADDRESS', algokit.algo(1), { + minFundingIncrement: algokit.algo(2), + fee: (1000).microAlgo(), suppressLog: true, }) @@ -106,14 +106,14 @@ await algorand.account.ensureFundedFromEnvironment('ACCOUNTADDRESS', algokit.alg await algorand.account.ensureFundedUsingDispenserAPI( 'ACCOUNTADDRESS', algorand.client.getTestNetDispenserFromEnvironment(), - algokit.algos(1), + algokit.algo(1), ) // With configuration await algorand.account.ensureFundedUsingDispenserAPI( 'ACCOUNTADDRESS', algorand.client.getTestNetDispenserFromEnvironment(), - algokit.algos(1), - { minFundingIncrement: algokit.algos(2) }, + algokit.algo(1), + { minFundingIncrement: algokit.algo(2) }, ) ``` diff --git a/docs/capabilities/typed-app-clients.md b/docs/capabilities/typed-app-clients.md index 1dbc2180..a2c8b73e 100644 --- a/docs/capabilities/typed-app-clients.md +++ b/docs/capabilities/typed-app-clients.md @@ -81,7 +81,7 @@ import { AlgorandClient } from '@algorandfoundation/algokit-utils' // These require environment variables to be present, or it will retrieve from default LocalNet const algorand = AlgorandClient.fromEnvironment() -const deployer = algorand.account.fromEnvironment('DEPLOYER', (1).algos()) +const deployer = algorand.account.fromEnvironment('DEPLOYER', (1).algo()) // Create the typed app client const appClient = algorand.client.getTypedAppClientByCreatorAndName(HelloWorldAppClient, { diff --git a/docs/code/classes/types_account_manager.AccountManager.md b/docs/code/classes/types_account_manager.AccountManager.md index d4a115a9..a3e09a0c 100644 --- a/docs/code/classes/types_account_manager.AccountManager.md +++ b/docs/code/classes/types_account_manager.AccountManager.md @@ -240,10 +240,10 @@ https://developer.algorand.org/docs/get-details/accounts/#minimum-balance ```typescript // Basic example -await algorand.account.ensureFunded("ACCOUNTADDRESS", "DISPENSERADDRESS", algokit.algos(1)) +await algorand.account.ensureFunded("ACCOUNTADDRESS", "DISPENSERADDRESS", algokit.algo(1)) // With configuration -await algorand.account.ensureFunded("ACCOUNTADDRESS", "DISPENSERADDRESS", algokit.algos(1), - { minFundingIncrement: algokit.algos(2), fee: (1000).microAlgos(), suppressLog: true } +await algorand.account.ensureFunded("ACCOUNTADDRESS", "DISPENSERADDRESS", algokit.algo(1), + { minFundingIncrement: algokit.algo(2), fee: (1000).microAlgo(), suppressLog: true } ) ``` @@ -289,10 +289,10 @@ https://developer.algorand.org/docs/get-details/accounts/#minimum-balance ```typescript // Basic example -await algorand.account.ensureFundedFromEnvironment("ACCOUNTADDRESS", algokit.algos(1)) +await algorand.account.ensureFundedFromEnvironment("ACCOUNTADDRESS", algokit.algo(1)) // With configuration -await algorand.account.ensureFundedFromEnvironment("ACCOUNTADDRESS", algokit.algos(1), - { minFundingIncrement: algokit.algos(2), fee: (1000).microAlgos(), suppressLog: true } +await algorand.account.ensureFundedFromEnvironment("ACCOUNTADDRESS", algokit.algo(1), + { minFundingIncrement: algokit.algo(2), fee: (1000).microAlgo(), suppressLog: true } ) ``` @@ -333,10 +333,10 @@ https://developer.algorand.org/docs/get-details/accounts/#minimum-balance ```typescript // Basic example -await algorand.account.ensureFundedUsingDispenserAPI("ACCOUNTADDRESS", algorand.client.getTestNetDispenserFromEnvironment(), algokit.algos(1)) +await algorand.account.ensureFundedUsingDispenserAPI("ACCOUNTADDRESS", algorand.client.getTestNetDispenserFromEnvironment(), algokit.algo(1)) // With configuration -await algorand.account.ensureFundedUsingDispenserAPI("ACCOUNTADDRESS", algorand.client.getTestNetDispenserFromEnvironment(), algokit.algos(1), - { minFundingIncrement: algokit.algos(2) } +await algorand.account.ensureFundedUsingDispenserAPI("ACCOUNTADDRESS", algorand.client.getTestNetDispenserFromEnvironment(), algokit.algo(1), + { minFundingIncrement: algokit.algo(2) } ) ``` @@ -713,11 +713,11 @@ await algorand.account.rekeyAccount({ note: 'note', firstValidRound: 1000n, validityWindow: 10, - extraFee: (1000).microAlgos(), - staticFee: (1000).microAlgos(), + extraFee: (1000).microAlgo(), + staticFee: (1000).microAlgo(), // Max fee doesn't make sense with extraFee AND staticFee // already specified, but here for completeness - maxFee: (3000).microAlgos(), + maxFee: (3000).microAlgo(), maxRoundsToWaitForConfirmation: 5, suppressLog: true, }) diff --git a/docs/code/classes/types_algorand_client_sender.AlgorandClientSender.md b/docs/code/classes/types_algorand_client_sender.AlgorandClientSender.md index 5891c570..6b4a23d9 100644 --- a/docs/code/classes/types_algorand_client_sender.AlgorandClientSender.md +++ b/docs/code/classes/types_algorand_client_sender.AlgorandClientSender.md @@ -144,11 +144,11 @@ await algorand.send.assetConfig({ // You wouldn't normally set this field firstValidRound: 1000n, validityWindow: 10, - extraFee: (1000).microAlgos(), - staticFee: (1000).microAlgos(), + extraFee: (1000).microAlgo(), + staticFee: (1000).microAlgo(), // Max fee doesn't make sense with extraFee AND staticFee // already specified, but here for completeness - maxFee: (3000).microAlgos(), + maxFee: (3000).microAlgo(), // Signer only needed if you want to provide one, // generally you'd register it with AlgorandClient // against the sender and not need to pass it in @@ -205,11 +205,11 @@ await algorand.send.assetDestroy({ // You wouldn't normally set this field firstValidRound: 1000n, validityWindow: 10, - extraFee: (1000).microAlgos(), - staticFee: (1000).microAlgos(), + extraFee: (1000).microAlgo(), + staticFee: (1000).microAlgo(), // Max fee doesn't make sense with extraFee AND staticFee // already specified, but here for completeness - maxFee: (3000).microAlgos(), + maxFee: (3000).microAlgo(), // Signer only needed if you want to provide one, // generally you'd register it with AlgorandClient // against the sender and not need to pass it in @@ -264,11 +264,11 @@ await algorand.send.assetFreeze({ // You wouldn't normally set this field firstValidRound: 1000n, validityWindow: 10, - extraFee: (1000).microAlgos(), - staticFee: (1000).microAlgos(), + extraFee: (1000).microAlgo(), + staticFee: (1000).microAlgo(), // Max fee doesn't make sense with extraFee AND staticFee // already specified, but here for completeness - maxFee: (3000).microAlgos(), + maxFee: (3000).microAlgo(), // Signer only needed if you want to provide one, // generally you'd register it with AlgorandClient // against the sender and not need to pass it in @@ -321,11 +321,11 @@ await algorand.send.assetOptIn({ // You wouldn't normally set this field firstValidRound: 1000n, validityWindow: 10, - extraFee: (1000).microAlgos(), - staticFee: (1000).microAlgos(), + extraFee: (1000).microAlgo(), + staticFee: (1000).microAlgo(), // Max fee doesn't make sense with extraFee AND staticFee // already specified, but here for completeness - maxFee: (3000).microAlgos(), + maxFee: (3000).microAlgo(), // Signer only needed if you want to provide one, // generally you'd register it with AlgorandClient // against the sender and not need to pass it in @@ -383,11 +383,11 @@ await algorand.send.assetTransfer({ // You wouldn't normally set this field firstValidRound: 1000n, validityWindow: 10, - extraFee: (1000).microAlgos(), - staticFee: (1000).microAlgos(), + extraFee: (1000).microAlgo(), + staticFee: (1000).microAlgo(), // Max fee doesn't make sense with extraFee AND staticFee // already specified, but here for completeness - maxFee: (3000).microAlgos(), + maxFee: (3000).microAlgo(), // Signer only needed if you want to provide one, // generally you'd register it with AlgorandClient // against the sender and not need to pass it in @@ -483,7 +483,7 @@ Send a payment transaction to transfer Algo between accounts. const result = await algorandClient.send.payment({ sender: 'SENDERADDRESS', receiver: 'RECEIVERADDRESS', - amount: (4).algos(), + amount: (4).algo(), }) ``` @@ -491,7 +491,7 @@ const result = await algorandClient.send.payment({ ```typescript const result = await algorandClient.send.payment({ - amount: (4).algos(), + amount: (4).algo(), receiver: 'RECEIVERADDRESS', sender: 'SENDERADDRESS', closeRemainderTo: 'CLOSEREMAINDERTOADDRESS', @@ -502,11 +502,11 @@ const result = await algorandClient.send.payment({ // You wouldn't normally set this field firstValidRound: 1000n, validityWindow: 10, - extraFee: (1000).microAlgos(), - staticFee: (1000).microAlgos(), + extraFee: (1000).microAlgo(), + staticFee: (1000).microAlgo(), // Max fee doesn't make sense with extraFee AND staticFee // already specified, but here for completeness - maxFee: (3000).microAlgos(), + maxFee: (3000).microAlgo(), // Signer only needed if you want to provide one, // generally you'd register it with AlgorandClient // against the sender and not need to pass it in @@ -625,11 +625,11 @@ await algorand.send.assetCreate({ // You wouldn't normally set this field firstValidRound: 1000n, validityWindow: 10, - extraFee: (1000).microAlgos(), - staticFee: (1000).microAlgos(), + extraFee: (1000).microAlgo(), + staticFee: (1000).microAlgo(), // Max fee doesn't make sense with extraFee AND staticFee // already specified, but here for completeness - maxFee: (3000).microAlgos(), + maxFee: (3000).microAlgo(), // Signer only needed if you want to provide one, // generally you'd register it with AlgorandClient // against the sender and not need to pass it in @@ -692,11 +692,11 @@ await algorand.send.assetOptOut({ // You wouldn't normally set this field firstValidRound: 1000n, validityWindow: 10, - extraFee: (1000).microAlgos(), - staticFee: (1000).microAlgos(), + extraFee: (1000).microAlgo(), + staticFee: (1000).microAlgo(), // Max fee doesn't make sense with extraFee AND staticFee // already specified, but here for completeness - maxFee: (3000).microAlgos(), + maxFee: (3000).microAlgo(), // Signer only needed if you want to provide one, // generally you'd register it with AlgorandClient // against the sender and not need to pass it in diff --git a/docs/code/classes/types_algorand_client_transaction_creator.AlgorandClientTransactionCreator.md b/docs/code/classes/types_algorand_client_transaction_creator.AlgorandClientTransactionCreator.md index acb64b28..a71fa3eb 100644 --- a/docs/code/classes/types_algorand_client_transaction_creator.AlgorandClientTransactionCreator.md +++ b/docs/code/classes/types_algorand_client_transaction_creator.AlgorandClientTransactionCreator.md @@ -130,11 +130,11 @@ await algorand.transaction.assetConfig({ // You wouldn't normally set this field firstValidRound: 1000n, validityWindow: 10, - extraFee: (1000).microAlgos(), - staticFee: (1000).microAlgos(), + extraFee: (1000).microAlgo(), + staticFee: (1000).microAlgo(), // Max fee doesn't make sense with extraFee AND staticFee // already specified, but here for completeness - maxFee: (3000).microAlgos(), + maxFee: (3000).microAlgo(), }) ``` @@ -194,11 +194,11 @@ await algorand.transaction.assetCreate({ // You wouldn't normally set this field firstValidRound: 1000n, validityWindow: 10, - extraFee: (1000).microAlgos(), - staticFee: (1000).microAlgos(), + extraFee: (1000).microAlgo(), + staticFee: (1000).microAlgo(), // Max fee doesn't make sense with extraFee AND staticFee // already specified, but here for completeness - maxFee: (3000).microAlgos(), + maxFee: (3000).microAlgo(), }) ``` @@ -249,11 +249,11 @@ await algorand.transaction.assetDestroy({ // You wouldn't normally set this field firstValidRound: 1000n, validityWindow: 10, - extraFee: (1000).microAlgos(), - staticFee: (1000).microAlgos(), + extraFee: (1000).microAlgo(), + staticFee: (1000).microAlgo(), // Max fee doesn't make sense with extraFee AND staticFee // already specified, but here for completeness - maxFee: (3000).microAlgos(), + maxFee: (3000).microAlgo(), }) ``` @@ -302,11 +302,11 @@ await algorand.transaction.assetFreeze({ // You wouldn't normally set this field firstValidRound: 1000n, validityWindow: 10, - extraFee: (1000).microAlgos(), - staticFee: (1000).microAlgos(), + extraFee: (1000).microAlgo(), + staticFee: (1000).microAlgo(), // Max fee doesn't make sense with extraFee AND staticFee // already specified, but here for completeness - maxFee: (3000).microAlgos(), + maxFee: (3000).microAlgo(), }) ``` @@ -353,11 +353,11 @@ await algorand.transaction.assetOptIn({ // You wouldn't normally set this field firstValidRound: 1000n, validityWindow: 10, - extraFee: (1000).microAlgos(), - staticFee: (1000).microAlgos(), + extraFee: (1000).microAlgo(), + staticFee: (1000).microAlgo(), // Max fee doesn't make sense with extraFee AND staticFee // already specified, but here for completeness - maxFee: (3000).microAlgos(), + maxFee: (3000).microAlgo(), }) ``` @@ -409,11 +409,11 @@ await algorand.transaction.assetOptIn({ // You wouldn't normally set this field firstValidRound: 1000n, validityWindow: 10, - extraFee: (1000).microAlgos(), - staticFee: (1000).microAlgos(), + extraFee: (1000).microAlgo(), + staticFee: (1000).microAlgo(), // Max fee doesn't make sense with extraFee AND staticFee // already specified, but here for completeness - maxFee: (3000).microAlgos(), + maxFee: (3000).microAlgo(), }) ``` @@ -465,11 +465,11 @@ await algorand.transaction.assetTransfer({ // You wouldn't normally set this field firstValidRound: 1000n, validityWindow: 10, - extraFee: (1000).microAlgos(), - staticFee: (1000).microAlgos(), + extraFee: (1000).microAlgo(), + staticFee: (1000).microAlgo(), // Max fee doesn't make sense with extraFee AND staticFee // already specified, but here for completeness - maxFee: (3000).microAlgos(), + maxFee: (3000).microAlgo(), }) ``` @@ -531,7 +531,7 @@ Create a payment transaction to transfer Algo between accounts. const result = await algorandClient.send.payment({ sender: 'SENDERADDRESS', receiver: 'RECEIVERADDRESS', - amount: (4).algos(), + amount: (4).algo(), }) ``` @@ -539,7 +539,7 @@ const result = await algorandClient.send.payment({ ```typescript const result = await algorandClient.send.payment({ - amount: (4).algos(), + amount: (4).algo(), receiver: 'RECEIVERADDRESS', sender: 'SENDERADDRESS', closeRemainderTo: 'CLOSEREMAINDERTOADDRESS', @@ -550,11 +550,11 @@ const result = await algorandClient.send.payment({ // You wouldn't normally set this field firstValidRound: 1000n, validityWindow: 10, - extraFee: (1000).microAlgos(), - staticFee: (1000).microAlgos(), + extraFee: (1000).microAlgo(), + staticFee: (1000).microAlgo(), // Max fee doesn't make sense with extraFee AND staticFee // already specified, but here for completeness - maxFee: (3000).microAlgos(), + maxFee: (3000).microAlgo(), }) ``` diff --git a/docs/code/classes/types_amount.AlgoAmount.md b/docs/code/classes/types_amount.AlgoAmount.md index 64f9edca..4b19a435 100644 --- a/docs/code/classes/types_amount.AlgoAmount.md +++ b/docs/code/classes/types_amount.AlgoAmount.md @@ -14,18 +14,22 @@ Wrapper class to ensure safe, explicit conversion between µAlgo, Algo and numbe ### Properties -- [amountInMicroAlgos](types_amount.AlgoAmount.md#amountinmicroalgos) +- [amountInMicroAlgo](types_amount.AlgoAmount.md#amountinmicroalgo) ### Accessors +- [algo](types_amount.AlgoAmount.md#algo) - [algos](types_amount.AlgoAmount.md#algos) +- [microAlgo](types_amount.AlgoAmount.md#microalgo) - [microAlgos](types_amount.AlgoAmount.md#microalgos) ### Methods - [toString](types_amount.AlgoAmount.md#tostring) - [valueOf](types_amount.AlgoAmount.md#valueof) +- [Algo](types_amount.AlgoAmount.md#algo-1) - [Algos](types_amount.AlgoAmount.md#algos-1) +- [MicroAlgo](types_amount.AlgoAmount.md#microalgo-1) - [MicroAlgos](types_amount.AlgoAmount.md#microalgos-1) ## Constructors @@ -38,7 +42,7 @@ Wrapper class to ensure safe, explicit conversion between µAlgo, Algo and numbe | Name | Type | | :------ | :------ | -| `amount` | \{ `algos`: `number` } \| \{ `microAlgos`: `number` } | +| `amount` | \{ `algos`: `number` } \| \{ `algo`: `number` } \| \{ `microAlgos`: `number` } \| \{ `microAlgo`: `number` } | #### Returns @@ -46,13 +50,13 @@ Wrapper class to ensure safe, explicit conversion between µAlgo, Algo and numbe #### Defined in -[src/types/amount.ts:17](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/amount.ts#L17) +[src/types/amount.ts:27](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/amount.ts#L27) ## Properties -### amountInMicroAlgos +### amountInMicroAlgo -• `Private` **amountInMicroAlgos**: `number` +• `Private` **amountInMicroAlgo**: `number` #### Defined in @@ -60,6 +64,22 @@ Wrapper class to ensure safe, explicit conversion between µAlgo, Algo and numbe ## Accessors +### algo + +• `get` **algo**(): `number` + +Return the amount as a number in Algo + +#### Returns + +`number` + +#### Defined in + +[src/types/amount.ts:23](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/amount.ts#L23) + +___ + ### algos • `get` **algos**(): `number` @@ -72,6 +92,22 @@ Return the amount as a number in Algo #### Defined in +[src/types/amount.ts:18](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/amount.ts#L18) + +___ + +### microAlgo + +• `get` **microAlgo**(): `number` + +Return the amount as a number in µAlgo + +#### Returns + +`number` + +#### Defined in + [src/types/amount.ts:13](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/amount.ts#L13) ___ @@ -102,7 +138,7 @@ Return the amount as a number in µAlgo #### Defined in -[src/types/amount.ts:21](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/amount.ts#L21) +[src/types/amount.ts:38](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/amount.ts#L38) ___ @@ -120,7 +156,29 @@ the algos or microAlgos properties #### Defined in -[src/types/amount.ts:29](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/amount.ts#L29) +[src/types/amount.ts:46](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/amount.ts#L46) + +___ + +### Algo + +▸ **Algo**(`amount`): [`AlgoAmount`](types_amount.AlgoAmount.md) + +Create a `AlgoAmount` object representing the given number of Algo + +#### Parameters + +| Name | Type | +| :------ | :------ | +| `amount` | `number` | + +#### Returns + +[`AlgoAmount`](types_amount.AlgoAmount.md) + +#### Defined in + +[src/types/amount.ts:56](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/amount.ts#L56) ___ @@ -142,7 +200,29 @@ Create a `AlgoAmount` object representing the given number of Algo #### Defined in -[src/types/amount.ts:34](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/amount.ts#L34) +[src/types/amount.ts:51](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/amount.ts#L51) + +___ + +### MicroAlgo + +▸ **MicroAlgo**(`amount`): [`AlgoAmount`](types_amount.AlgoAmount.md) + +Create a `AlgoAmount` object representing the given number of µAlgo + +#### Parameters + +| Name | Type | +| :------ | :------ | +| `amount` | `number` | + +#### Returns + +[`AlgoAmount`](types_amount.AlgoAmount.md) + +#### Defined in + +[src/types/amount.ts:66](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/amount.ts#L66) ___ @@ -164,4 +244,4 @@ Create a `AlgoAmount` object representing the given number of µAlgo #### Defined in -[src/types/amount.ts:39](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/amount.ts#L39) +[src/types/amount.ts:61](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/amount.ts#L61) diff --git a/docs/code/classes/types_asset_manager.AssetManager.md b/docs/code/classes/types_asset_manager.AssetManager.md index 71b697a0..7a2a062a 100644 --- a/docs/code/classes/types_asset_manager.AssetManager.md +++ b/docs/code/classes/types_asset_manager.AssetManager.md @@ -111,7 +111,7 @@ An array of records matching asset ID to transaction ID of the opt in // Basic example algorand.asset.bulkOptIn("ACCOUNTADDRESS", [12345n, 67890n]) // With configuration -algorand.asset.bulkOptIn("ACCOUNTADDRESS", [12345n, 67890n], { maxFee: (1000).microAlgos(), suppressLog: true }) +algorand.asset.bulkOptIn("ACCOUNTADDRESS", [12345n, 67890n], { maxFee: (1000).microAlgo(), suppressLog: true }) ``` #### Defined in @@ -148,7 +148,7 @@ An array of records matching asset ID to transaction ID of the opt in // Basic example algorand.asset.bulkOptOut("ACCOUNTADDRESS", [12345n, 67890n]) // With configuration -algorand.asset.bulkOptOut("ACCOUNTADDRESS", [12345n, 67890n], { ensureZeroBalance: true, maxFee: (1000).microAlgos(), suppressLog: true }) +algorand.asset.bulkOptOut("ACCOUNTADDRESS", [12345n, 67890n], { ensureZeroBalance: true, maxFee: (1000).microAlgo(), suppressLog: true }) ``` #### Defined in diff --git a/docs/code/classes/types_kmd_account_manager.KmdAccountManager.md b/docs/code/classes/types_kmd_account_manager.KmdAccountManager.md index a0aae270..62d92eda 100644 --- a/docs/code/classes/types_kmd_account_manager.KmdAccountManager.md +++ b/docs/code/classes/types_kmd_account_manager.KmdAccountManager.md @@ -123,7 +123,7 @@ An Algorand account with private key loaded - either one that already existed in ```typescript // Idempotently get (if exists) or crate (if it doesn't exist yet) an account by name using KMD // if creating it then fund it with 2 ALGO from the default dispenser account -const newAccount = await kmdAccountManager.getOrCreateWalletAccount('account1', (2).algos()) +const newAccount = await kmdAccountManager.getOrCreateWalletAccount('account1', (2).algo()) // This will return the same account as above since the name matches const existingAccount = await kmdAccountManager.getOrCreateWalletAccount('account1') ``` diff --git a/docs/code/modules/index.md b/docs/code/modules/index.md index f8c32d86..9e6b6aae 100644 --- a/docs/code/modules/index.md +++ b/docs/code/modules/index.md @@ -31,6 +31,7 @@ ### Functions +- [algo](index.md#algo) - [algos](index.md#algos) - [assetBulkOptIn](index.md#assetbulkoptin) - [assetBulkOptOut](index.md#assetbulkoptout) @@ -94,6 +95,7 @@ - [isMainNet](index.md#ismainnet) - [isSchemaIsBroken](index.md#isschemaisbroken) - [isTestNet](index.md#istestnet) +- [microAlgo](index.md#microalgo) - [microAlgos](index.md#microalgos) - [mnemonicAccount](index.md#mnemonicaccount) - [mnemonicAccountFromEnvironment](index.md#mnemonicaccountfromenvironment) @@ -221,6 +223,28 @@ ___ ## Functions +### algo + +▸ **algo**(`algos`): [`AlgoAmount`](../classes/types_amount.AlgoAmount.md) + +Returns an amount of Algo using AlgoAmount + +#### Parameters + +| Name | Type | Description | +| :------ | :------ | :------ | +| `algos` | `number` | The amount of Algo | + +#### Returns + +[`AlgoAmount`](../classes/types_amount.AlgoAmount.md) + +#### Defined in + +[src/amount.ts:51](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/amount.ts#L51) + +___ + ### algos ▸ **algos**(`algos`): [`AlgoAmount`](../classes/types_amount.AlgoAmount.md) @@ -239,7 +263,7 @@ Returns an amount of Algo using AlgoAmount #### Defined in -[src/amount.ts:22](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/amount.ts#L22) +[src/amount.ts:44](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/amount.ts#L44) ___ @@ -2185,6 +2209,28 @@ Use `await algorandClient.client.isTestNet()` or `await new ClientManager({ algo ___ +### microAlgo + +▸ **microAlgo**(`microAlgos`): [`AlgoAmount`](../classes/types_amount.AlgoAmount.md) + +Returns an amount of µAlgo using AlgoAmount + +#### Parameters + +| Name | Type | Description | +| :------ | :------ | :------ | +| `microAlgos` | `number` | The amount of µAlgo | + +#### Returns + +[`AlgoAmount`](../classes/types_amount.AlgoAmount.md) + +#### Defined in + +[src/amount.ts:65](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/amount.ts#L65) + +___ + ### microAlgos ▸ **microAlgos**(`microAlgos`): [`AlgoAmount`](../classes/types_amount.AlgoAmount.md) @@ -2203,7 +2249,7 @@ Returns an amount of µAlgo using AlgoAmount #### Defined in -[src/amount.ts:29](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/amount.ts#L29) +[src/amount.ts:58](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/amount.ts#L58) ___ @@ -2774,7 +2820,7 @@ Returns an amount of µAlgo to cover standard fees for the given number of trans #### Defined in -[src/amount.ts:36](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/amount.ts#L36) +[src/amount.ts:72](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/amount.ts#L72) ___ @@ -2833,7 +2879,7 @@ Transfer Algo between two accounts. **`Example`** ```typescript -await algokit.transferAlgos({ from, to, amount: algokit.algos(1) }, algod) +await algokit.transferAlgos({ from, to, amount: algokit.algo(1) }, algod) ``` #### Defined in diff --git a/src/amount.ts b/src/amount.ts index a631499f..924914b2 100644 --- a/src/amount.ts +++ b/src/amount.ts @@ -3,36 +3,72 @@ import { AlgoAmount } from './types/amount' declare global { interface Number { + /** + * Returns an `AlgoAmount` using this number of microAlgo. + */ microAlgos(this: number): AlgoAmount + /** + * Returns an `AlgoAmount` using this number of Algo. + */ algos(this: number): AlgoAmount + /** + * Returns an `AlgoAmount` using this number of microAlgo. + */ + microAlgo(this: number): AlgoAmount + /** + * Returns an `AlgoAmount` using this number of Algo. + */ + algo(this: number): AlgoAmount } } Number.prototype.microAlgos = function () { - return AlgoAmount.MicroAlgos(this) + return AlgoAmount.MicroAlgo(this) } Number.prototype.algos = function () { - return AlgoAmount.Algos(this) + return AlgoAmount.Algo(this) +} + +Number.prototype.microAlgo = function () { + return AlgoAmount.MicroAlgo(this) +} + +Number.prototype.algo = function () { + return AlgoAmount.Algo(this) } /** Returns an amount of Algo using AlgoAmount * @param algos The amount of Algo */ export const algos = (algos: number) => { - return AlgoAmount.Algos(algos) + return AlgoAmount.Algo(algos) +} + +/** Returns an amount of Algo using AlgoAmount + * @param algos The amount of Algo + */ +export const algo = (algos: number) => { + return AlgoAmount.Algo(algos) } /** Returns an amount of µAlgo using AlgoAmount * @param microAlgos The amount of µAlgo */ export const microAlgos = (microAlgos: number) => { - return AlgoAmount.MicroAlgos(microAlgos) + return AlgoAmount.MicroAlgo(microAlgos) +} + +/** Returns an amount of µAlgo using AlgoAmount + * @param microAlgos The amount of µAlgo + */ +export const microAlgo = (microAlgos: number) => { + return AlgoAmount.MicroAlgo(microAlgos) } /** Returns an amount of µAlgo to cover standard fees for the given number of transactions using AlgoAmount * @param numberOfTransactions The of standard transaction fees to return the amount of Algo */ export const transactionFees = (numberOfTransactions: number) => { - return AlgoAmount.MicroAlgos(numberOfTransactions * algosdk.ALGORAND_MIN_TX_FEE) + return AlgoAmount.MicroAlgo(numberOfTransactions * algosdk.ALGORAND_MIN_TX_FEE) } diff --git a/src/app.spec.ts b/src/app.spec.ts index 312d4b0e..25810ecc 100644 --- a/src/app.spec.ts +++ b/src/app.spec.ts @@ -53,7 +53,7 @@ describe('app', () => { const rekeyedAccount = algorand.account.rekeyed(testAccount.addr, rekeyTo) await algokit.transferAlgos( { - amount: (0).algos(), + amount: (0).algo(), from: rekeyedAccount, to: testAccount, }, diff --git a/src/indexer-lookup.spec.ts b/src/indexer-lookup.spec.ts index 90091cc7..26b6b6f7 100644 --- a/src/indexer-lookup.spec.ts +++ b/src/indexer-lookup.spec.ts @@ -12,7 +12,7 @@ describe('indexer-lookup', () => { return await localnet.context.algorand.send.payment({ sender: from ?? localnet.context.testAccount.addr, receiver: localnet.context.testAccount.addr, - amount: amount ?? (1).microAlgos(), + amount: amount ?? (1).microAlgo(), }) } @@ -39,12 +39,12 @@ describe('indexer-lookup', () => { test('Transactions are searched with pagination', async () => { const { algorand, testAccount, generateAccount, waitForIndexer } = localnet.context const secondAccount = await generateAccount({ - initialFunds: (1).algos(), + initialFunds: (1).algo(), suppressLog: true, }) - const { transaction: transaction1 } = await sendTestTransaction((1).microAlgos()) - const { transaction: transaction2 } = await sendTestTransaction((2).microAlgos()) - await sendTestTransaction((1).microAlgos(), secondAccount.addr) + const { transaction: transaction1 } = await sendTestTransaction((1).microAlgo()) + const { transaction: transaction2 } = await sendTestTransaction((2).microAlgo()) + await sendTestTransaction((1).microAlgo(), secondAccount.addr) await waitForIndexer() const transactions = await indexer.searchTransactions( @@ -60,7 +60,7 @@ describe('indexer-lookup', () => { test('Application create transactions are found by creator with pagination', async () => { const { algorand, testAccount, generateAccount, waitForIndexer } = localnet.context const secondAccount = await generateAccount({ - initialFunds: (1).algos(), + initialFunds: (1).algo(), suppressLog: true, }) diff --git a/src/testing/account.ts b/src/testing/account.ts index d9568e16..8f0cb0da 100644 --- a/src/testing/account.ts +++ b/src/testing/account.ts @@ -59,7 +59,7 @@ export async function getTestAccount( const accountInfo = await algorand.account.getInformation(account.addr) - Config.getLogger(suppressLog).info('Test account funded; account balance: %d µALGO', accountInfo.balance.microAlgos) + Config.getLogger(suppressLog).info('Test account funded; account balance: %d µALGO', accountInfo.balance.microAlgo) return account } diff --git a/src/transaction/transaction.spec.ts b/src/transaction/transaction.spec.ts index b49dd11b..717ef6b1 100644 --- a/src/transaction/transaction.spec.ts +++ b/src/transaction/transaction.spec.ts @@ -41,7 +41,7 @@ describe('transaction', () => { transaction: txn, from: testAccount, sendParams: { - maxFee: algokit.microAlgos(1), + maxFee: algokit.microAlgo(1), }, }, algod, @@ -62,7 +62,7 @@ describe('transaction', () => { transaction: txn, from: testAccount, sendParams: { - maxFee: algokit.microAlgos(1), + maxFee: algokit.microAlgo(1), }, }, algod, @@ -77,7 +77,7 @@ describe('transaction', () => { transaction: txn, from: testAccount, sendParams: { - maxFee: algokit.microAlgos(1000_000), + maxFee: algokit.microAlgo(1000_000), }, }, algod, @@ -89,7 +89,7 @@ describe('transaction', () => { test('Transaction fee is overridable', async () => { const { algod, testAccount } = localnet.context const txn = await getTestTransaction() - const fee = algokit.algos(1) + const fee = algokit.algo(1) const result = await algokit.sendTransaction( { transaction: txn, @@ -102,7 +102,7 @@ describe('transaction', () => { ) invariant(result.confirmation) - expect(result.confirmation.txn.txn.fee).toBe(fee.microAlgos) + expect(result.confirmation.txn.txn.fee).toBe(fee.microAlgo) }) test('Transaction group is sent', async () => { @@ -143,7 +143,7 @@ describe('transaction', () => { const txn1 = await getTestTransaction(1) const txn2Promise = algokit.transferAlgos( { - amount: algokit.microAlgos(2), + amount: algokit.microAlgo(2), from: testAccount, to: testAccount.addr, skipSending: true, @@ -168,7 +168,7 @@ describe('transaction', () => { test('Transaction group is sent using transaction signers', async () => { const { algod, testAccount, generateAccount } = localnet.context - const account2 = await generateAccount({ suppressLog: true, initialFunds: algokit.algos(10) }) + const account2 = await generateAccount({ suppressLog: true, initialFunds: algokit.algo(10) }) const txn1 = await getTestTransaction(1) const txn2 = await getTestTransaction(2, account2.addr) const txn3 = await getTestTransaction(3) @@ -233,7 +233,7 @@ describe('transaction', () => { { from: testAccount, to: multisig.addr, - amount: algokit.algos(1), + amount: algokit.algo(1), }, algod, ) @@ -243,7 +243,7 @@ describe('transaction', () => { { from: multisig, to: testAccount.addr, - amount: algokit.microAlgos(500), + amount: algokit.microAlgo(500), }, algod, ) @@ -252,7 +252,7 @@ describe('transaction', () => { test('Multisig double account', async () => { const { algod, testAccount, generateAccount } = localnet.context const account2 = await generateAccount({ - initialFunds: algokit.algos(10), + initialFunds: algokit.algo(10), suppressLog: true, }) @@ -271,7 +271,7 @@ describe('transaction', () => { { from: testAccount, to: multisig.addr, - amount: algokit.algos(1), + amount: algokit.algo(1), }, algod, ) @@ -281,7 +281,7 @@ describe('transaction', () => { { from: multisig, to: testAccount.addr, - amount: algokit.microAlgos(500), + amount: algokit.microAlgo(500), }, algod, ) @@ -416,9 +416,9 @@ const tests = (version: 8 | 9) => () => { await appClient.create({ method: 'createApplication', methodArgs: [] }) - await appClient.fundAppAccount(algokit.microAlgos(2334300)) + await appClient.fundAppAccount(algokit.microAlgo(2334300)) - await appClient.call({ method: 'bootstrap', methodArgs: [], sendParams: { fee: algokit.microAlgos(3_000) } }) + await appClient.call({ method: 'bootstrap', methodArgs: [], sendParams: { fee: algokit.microAlgo(3_000) } }) externalClient = new ApplicationClient( { @@ -474,7 +474,7 @@ const tests = (version: 8 | 9) => () => { appClient.call({ method: 'externalAppCall', methodArgs: [], - sendParams: { populateAppCallResources: false, fee: algokit.microAlgos(2_000) }, + sendParams: { populateAppCallResources: false, fee: algokit.microAlgo(2_000) }, }), ).rejects.toThrow('unavailable App') }) @@ -483,7 +483,7 @@ const tests = (version: 8 | 9) => () => { await appClient.call({ method: 'externalAppCall', methodArgs: [], - sendParams: { fee: algokit.microAlgos(2_000) }, + sendParams: { fee: algokit.microAlgo(2_000) }, }) }) }) @@ -684,8 +684,8 @@ describe('Resource Packer: Mixed', () => { test('app account', async () => { const { algod, testAccount } = fixture.context - await v8Client.fundAppAccount(algokit.microAlgos(328500)) - await v8Client.call({ method: 'bootstrap', methodArgs: [], sendParams: { fee: algokit.microAlgos(3_000) } }) + await v8Client.fundAppAccount(algokit.microAlgo(328500)) + await v8Client.call({ method: 'bootstrap', methodArgs: [], sendParams: { fee: algokit.microAlgo(3_000) } }) const externalAppID = (await v8Client.getGlobalState()).externalAppID!.value as bigint @@ -766,18 +766,18 @@ describe('Resource Packer: meta', () => { amount: 0, }) - await externalClient.fundAppAccount(algokit.microAlgos(106100)) + await externalClient.fundAppAccount(algokit.microAlgo(106100)) await externalClient.call({ method: 'boxWithPayment', methodArgs: [{ transaction: payment, signer: testAccount }] }) }) test('sender asset holding', async () => { - await externalClient.fundAppAccount(algokit.microAlgos(200_000)) + await externalClient.fundAppAccount(algokit.microAlgo(200_000)) await externalClient.call({ method: 'createAsset', methodArgs: [], - sendParams: { fee: algokit.microAlgos(2_000) }, + sendParams: { fee: algokit.microAlgo(2_000) }, }) const res = await externalClient.call({ method: 'senderAssetBalance', methodArgs: [] }) @@ -792,12 +792,12 @@ describe('Resource Packer: meta', () => { await algorand.account.rekeyAccount(testAccount.addr, authAddr.addr) - await externalClient.fundAppAccount(algokit.microAlgos(200_000)) + await externalClient.fundAppAccount(algokit.microAlgo(200_000)) await externalClient.call({ method: 'createAsset', methodArgs: [], - sendParams: { fee: algokit.microAlgos(2_000) }, + sendParams: { fee: algokit.microAlgo(2_000) }, sender: { addr: testAccount.addr, signer: algosdk.makeBasicAccountTransactionSigner(authAddr) }, }) const res = await externalClient.call({ diff --git a/src/transaction/transaction.ts b/src/transaction/transaction.ts index a811eebb..925a4874 100644 --- a/src/transaction/transaction.ts +++ b/src/transaction/transaction.ts @@ -818,9 +818,9 @@ export function capTransactionFee(transaction: algosdk.Transaction | SuggestedPa if (!transaction.flatFee) { // Once a transaction has been constructed by algosdk, transaction.fee indicates what the total transaction fee // Will be based on the current suggested fee-per-byte value. - if (transaction.fee > maxAcceptableFee.microAlgos) { + if (transaction.fee > maxAcceptableFee.microAlgo) { throw new Error( - `Cancelled transaction due to high network congestion fees. Algorand suggested fees would cause this transaction to cost ${transaction.fee} µALGO. Cap for this transaction is ${maxAcceptableFee.microAlgos} µALGO.`, + `Cancelled transaction due to high network congestion fees. Algorand suggested fees would cause this transaction to cost ${transaction.fee} µALGO. Cap for this transaction is ${maxAcceptableFee.microAlgo} µALGO.`, ) } else if (transaction.fee > algosdk.ALGORAND_MIN_TX_FEE) { Config.logger.warn(`Algorand network congestion fees are in effect. This transaction will incur a fee of ${transaction.fee} µALGO.`) @@ -842,7 +842,7 @@ export function controlFees( ) { const { fee, maxFee } = feeControl if (fee) { - transaction.fee = fee.microAlgos + transaction.fee = fee.microAlgo transaction.flatFee = true } diff --git a/src/transfer/transfer-algos.ts b/src/transfer/transfer-algos.ts index e0b6864f..356d04a9 100644 --- a/src/transfer/transfer-algos.ts +++ b/src/transfer/transfer-algos.ts @@ -16,7 +16,7 @@ import Algodv2 = algosdk.Algodv2 * * @example Usage example * ```typescript - * await algokit.transferAlgos({ from, to, amount: algokit.algos(1) }, algod) + * await algokit.transferAlgos({ from, to, amount: algokit.algo(1) }, algod) * ``` */ export async function transferAlgos(transfer: AlgoTransferParams, algod: Algodv2): Promise { diff --git a/src/transfer/transfer.ts b/src/transfer/transfer.ts index f9715d6e..00729bd8 100644 --- a/src/transfer/transfer.ts +++ b/src/transfer/transfer.ts @@ -41,7 +41,7 @@ export async function ensureFunded( ) if (!result) return undefined return { - amount: result.amountFunded.microAlgos, + amount: result.amountFunded.microAlgo, transactionId: result.transactionId, } } else { @@ -65,7 +65,7 @@ export async function ensureFunded( return result ? { - amount: result.amountFunded.microAlgos, + amount: result.amountFunded.microAlgo, transactionId: result.txIds[0], } : undefined @@ -128,7 +128,7 @@ export async function rekeyAccount(rekey: AlgoRekeyParams, algod: Algodv2): Prom { sender: getSenderAddress(rekey.from), receiver: getSenderAddress(rekey.from), - amount: (0).microAlgos(), + amount: (0).microAlgo(), rekeyTo: typeof rekey.rekeyTo === 'string' ? rekey.rekeyTo : getSenderAddress(rekey.rekeyTo), note: encodeTransactionNote(rekey.note), lease: rekey.lease, diff --git a/src/types/account-manager.spec.ts b/src/types/account-manager.spec.ts index dd6f2a6c..159f64b2 100644 --- a/src/types/account-manager.spec.ts +++ b/src/types/account-manager.spec.ts @@ -14,7 +14,7 @@ describe('AccountManager', () => { const account = await algorand.account.fromEnvironment(uuid()) const accountInfo = await algorand.account.getInformation(account.addr) - expect(accountInfo.balance.microAlgos).toBeGreaterThan(0) + expect(accountInfo.balance.microAlgo).toBeGreaterThan(0) }, 10e6) test('Same account is subsequently retrieved', async () => { diff --git a/src/types/account-manager.ts b/src/types/account-manager.ts index 017cd016..21be433e 100644 --- a/src/types/account-manager.ts +++ b/src/types/account-manager.ts @@ -205,11 +205,11 @@ export class AccountManager { return { ...account, // None of these can practically overflow 2^53 - balance: AlgoAmount.MicroAlgos(Number(account.amount)), - amountWithoutPendingRewards: AlgoAmount.MicroAlgos(Number(account.amountWithoutPendingRewards)), - minBalance: AlgoAmount.MicroAlgos(Number(account.minBalance)), - pendingRewards: AlgoAmount.MicroAlgos(Number(account.pendingRewards)), - rewards: AlgoAmount.MicroAlgos(Number(account.rewards)), + balance: AlgoAmount.MicroAlgo(Number(account.amount)), + amountWithoutPendingRewards: AlgoAmount.MicroAlgo(Number(account.amountWithoutPendingRewards)), + minBalance: AlgoAmount.MicroAlgo(Number(account.minBalance)), + pendingRewards: AlgoAmount.MicroAlgo(Number(account.pendingRewards)), + rewards: AlgoAmount.MicroAlgo(Number(account.rewards)), validAsOfRound: BigInt(account.round), totalAppsOptedIn: Number(account.totalAppsOptedIn), totalAssetsOptedIn: Number(account.totalAssetsOptedIn), @@ -441,11 +441,11 @@ export class AccountManager { * note: 'note', * firstValidRound: 1000n, * validityWindow: 10, - * extraFee: (1000).microAlgos(), - * staticFee: (1000).microAlgos(), + * extraFee: (1000).microAlgo(), + * staticFee: (1000).microAlgo(), * // Max fee doesn't make sense with extraFee AND staticFee * // already specified, but here for completeness - * maxFee: (3000).microAlgos(), + * maxFee: (3000).microAlgo(), * maxRoundsToWaitForConfirmation: 5, * suppressLog: true, * }) @@ -462,7 +462,7 @@ export class AccountManager { ...options, sender: typeof account === 'string' ? account : account.addr, receiver: typeof account === 'string' ? account : account.addr, - amount: AlgoAmount.MicroAlgos(0), + amount: AlgoAmount.MicroAlgo(0), rekeyTo: typeof rekeyTo === 'string' ? rekeyTo : rekeyTo.addr, }) .execute(options) @@ -479,11 +479,11 @@ export class AccountManager { private async _getEnsureFundedAmount(sender: string, minSpendingBalance: AlgoAmount, minFundingIncrement?: AlgoAmount) { const accountInfo = await this.getInformation(sender) - const currentSpendingBalance = accountInfo.balance.microAlgos - accountInfo.minBalance.microAlgos + const currentSpendingBalance = accountInfo.balance.microAlgo - accountInfo.minBalance.microAlgo - const amountFunded = calculateFundAmount(minSpendingBalance.microAlgos, currentSpendingBalance, minFundingIncrement?.microAlgos ?? 0) + const amountFunded = calculateFundAmount(minSpendingBalance.microAlgo, currentSpendingBalance, minFundingIncrement?.microAlgo ?? 0) - return amountFunded === null ? undefined : AlgoAmount.MicroAlgos(amountFunded) + return amountFunded === null ? undefined : AlgoAmount.MicroAlgo(amountFunded) } /** @@ -500,10 +500,10 @@ export class AccountManager { * @example Example using AlgorandClient * ```typescript * // Basic example - * await algorand.account.ensureFunded("ACCOUNTADDRESS", "DISPENSERADDRESS", algokit.algos(1)) + * await algorand.account.ensureFunded("ACCOUNTADDRESS", "DISPENSERADDRESS", algokit.algo(1)) * // With configuration - * await algorand.account.ensureFunded("ACCOUNTADDRESS", "DISPENSERADDRESS", algokit.algos(1), - * { minFundingIncrement: algokit.algos(2), fee: (1000).microAlgos(), suppressLog: true } + * await algorand.account.ensureFunded("ACCOUNTADDRESS", "DISPENSERADDRESS", algokit.algo(1), + * { minFundingIncrement: algokit.algo(2), fee: (1000).microAlgo(), suppressLog: true } * ) * ``` * @returns @@ -562,10 +562,10 @@ export class AccountManager { * @example Example using AlgorandClient * ```typescript * // Basic example - * await algorand.account.ensureFundedFromEnvironment("ACCOUNTADDRESS", algokit.algos(1)) + * await algorand.account.ensureFundedFromEnvironment("ACCOUNTADDRESS", algokit.algo(1)) * // With configuration - * await algorand.account.ensureFundedFromEnvironment("ACCOUNTADDRESS", algokit.algos(1), - * { minFundingIncrement: algokit.algos(2), fee: (1000).microAlgos(), suppressLog: true } + * await algorand.account.ensureFundedFromEnvironment("ACCOUNTADDRESS", algokit.algo(1), + * { minFundingIncrement: algokit.algo(2), fee: (1000).microAlgo(), suppressLog: true } * ) * ``` * @returns @@ -618,10 +618,10 @@ export class AccountManager { * @example Example using AlgorandClient * ```typescript * // Basic example - * await algorand.account.ensureFundedUsingDispenserAPI("ACCOUNTADDRESS", algorand.client.getTestNetDispenserFromEnvironment(), algokit.algos(1)) + * await algorand.account.ensureFundedUsingDispenserAPI("ACCOUNTADDRESS", algorand.client.getTestNetDispenserFromEnvironment(), algokit.algo(1)) * // With configuration - * await algorand.account.ensureFundedUsingDispenserAPI("ACCOUNTADDRESS", algorand.client.getTestNetDispenserFromEnvironment(), algokit.algos(1), - * { minFundingIncrement: algokit.algos(2) } + * await algorand.account.ensureFundedUsingDispenserAPI("ACCOUNTADDRESS", algorand.client.getTestNetDispenserFromEnvironment(), algokit.algo(1), + * { minFundingIncrement: algokit.algo(2) } * ) * ``` * @returns @@ -645,9 +645,9 @@ export class AccountManager { const amountFunded = await this._getEnsureFundedAmount(addressToFund, minSpendingBalance, options?.minFundingIncrement) if (!amountFunded) return undefined - const result = await dispenserClient.fund(addressToFund, amountFunded.microAlgos) + const result = await dispenserClient.fund(addressToFund, amountFunded.microAlgo) return { - amountFunded: AlgoAmount.MicroAlgos(result.amount), + amountFunded: AlgoAmount.MicroAlgo(result.amount), transactionId: result.txId, } } diff --git a/src/types/algorand-client-sender.ts b/src/types/algorand-client-sender.ts index a6fc7c5c..7e806459 100644 --- a/src/types/algorand-client-sender.ts +++ b/src/types/algorand-client-sender.ts @@ -67,13 +67,13 @@ export class AlgorandClientSender { * const result = await algorandClient.send.payment({ * sender: 'SENDERADDRESS', * receiver: 'RECEIVERADDRESS', - * amount: (4).algos(), + * amount: (4).algo(), * }) * ``` * @example Advanced example * ```typescript * const result = await algorandClient.send.payment({ - * amount: (4).algos(), + * amount: (4).algo(), * receiver: 'RECEIVERADDRESS', * sender: 'SENDERADDRESS', * closeRemainderTo: 'CLOSEREMAINDERTOADDRESS', @@ -84,11 +84,11 @@ export class AlgorandClientSender { * // You wouldn't normally set this field * firstValidRound: 1000n, * validityWindow: 10, - * extraFee: (1000).microAlgos(), - * staticFee: (1000).microAlgos(), + * extraFee: (1000).microAlgo(), + * staticFee: (1000).microAlgo(), * // Max fee doesn't make sense with extraFee AND staticFee * // already specified, but here for completeness - * maxFee: (3000).microAlgos(), + * maxFee: (3000).microAlgo(), * // Signer only needed if you want to provide one, * // generally you'd register it with AlgorandClient * // against the sender and not need to pass it in @@ -102,7 +102,7 @@ export class AlgorandClientSender { */ payment = this._send((c) => c.addPayment, { preLog: (params, transaction) => - `Sending ${params.amount.microAlgos} µALGO from ${params.sender} to ${params.receiver} via transaction ${transaction.txID()}`, + `Sending ${params.amount.microAlgo} µALGO from ${params.sender} to ${params.receiver} via transaction ${transaction.txID()}`, }) /** * Create a new Algorand Standard Asset. @@ -136,11 +136,11 @@ export class AlgorandClientSender { * // You wouldn't normally set this field * firstValidRound: 1000n, * validityWindow: 10, - * extraFee: (1000).microAlgos(), - * staticFee: (1000).microAlgos(), + * extraFee: (1000).microAlgo(), + * staticFee: (1000).microAlgo(), * // Max fee doesn't make sense with extraFee AND staticFee * // already specified, but here for completeness - * maxFee: (3000).microAlgos(), + * maxFee: (3000).microAlgo(), * // Signer only needed if you want to provide one, * // generally you'd register it with AlgorandClient * // against the sender and not need to pass it in @@ -185,11 +185,11 @@ export class AlgorandClientSender { * // You wouldn't normally set this field * firstValidRound: 1000n, * validityWindow: 10, - * extraFee: (1000).microAlgos(), - * staticFee: (1000).microAlgos(), + * extraFee: (1000).microAlgo(), + * staticFee: (1000).microAlgo(), * // Max fee doesn't make sense with extraFee AND staticFee * // already specified, but here for completeness - * maxFee: (3000).microAlgos(), + * maxFee: (3000).microAlgo(), * // Signer only needed if you want to provide one, * // generally you'd register it with AlgorandClient * // against the sender and not need to pass it in @@ -224,11 +224,11 @@ export class AlgorandClientSender { * // You wouldn't normally set this field * firstValidRound: 1000n, * validityWindow: 10, - * extraFee: (1000).microAlgos(), - * staticFee: (1000).microAlgos(), + * extraFee: (1000).microAlgo(), + * staticFee: (1000).microAlgo(), * // Max fee doesn't make sense with extraFee AND staticFee * // already specified, but here for completeness - * maxFee: (3000).microAlgos(), + * maxFee: (3000).microAlgo(), * // Signer only needed if you want to provide one, * // generally you'd register it with AlgorandClient * // against the sender and not need to pass it in @@ -265,11 +265,11 @@ export class AlgorandClientSender { * // You wouldn't normally set this field * firstValidRound: 1000n, * validityWindow: 10, - * extraFee: (1000).microAlgos(), - * staticFee: (1000).microAlgos(), + * extraFee: (1000).microAlgo(), + * staticFee: (1000).microAlgo(), * // Max fee doesn't make sense with extraFee AND staticFee * // already specified, but here for completeness - * maxFee: (3000).microAlgos(), + * maxFee: (3000).microAlgo(), * // Signer only needed if you want to provide one, * // generally you'd register it with AlgorandClient * // against the sender and not need to pass it in @@ -307,11 +307,11 @@ export class AlgorandClientSender { * // You wouldn't normally set this field * firstValidRound: 1000n, * validityWindow: 10, - * extraFee: (1000).microAlgos(), - * staticFee: (1000).microAlgos(), + * extraFee: (1000).microAlgo(), + * staticFee: (1000).microAlgo(), * // Max fee doesn't make sense with extraFee AND staticFee * // already specified, but here for completeness - * maxFee: (3000).microAlgos(), + * maxFee: (3000).microAlgo(), * // Signer only needed if you want to provide one, * // generally you'd register it with AlgorandClient * // against the sender and not need to pass it in @@ -345,11 +345,11 @@ export class AlgorandClientSender { * // You wouldn't normally set this field * firstValidRound: 1000n, * validityWindow: 10, - * extraFee: (1000).microAlgos(), - * staticFee: (1000).microAlgos(), + * extraFee: (1000).microAlgo(), + * staticFee: (1000).microAlgo(), * // Max fee doesn't make sense with extraFee AND staticFee * // already specified, but here for completeness - * maxFee: (3000).microAlgos(), + * maxFee: (3000).microAlgo(), * // Signer only needed if you want to provide one, * // generally you'd register it with AlgorandClient * // against the sender and not need to pass it in @@ -392,11 +392,11 @@ export class AlgorandClientSender { * // You wouldn't normally set this field * firstValidRound: 1000n, * validityWindow: 10, - * extraFee: (1000).microAlgos(), - * staticFee: (1000).microAlgos(), + * extraFee: (1000).microAlgo(), + * staticFee: (1000).microAlgo(), * // Max fee doesn't make sense with extraFee AND staticFee * // already specified, but here for completeness - * maxFee: (3000).microAlgos(), + * maxFee: (3000).microAlgo(), * // Signer only needed if you want to provide one, * // generally you'd register it with AlgorandClient * // against the sender and not need to pass it in diff --git a/src/types/algorand-client-transaction-creator.ts b/src/types/algorand-client-transaction-creator.ts index 4a4a7bac..cf834d1c 100644 --- a/src/types/algorand-client-transaction-creator.ts +++ b/src/types/algorand-client-transaction-creator.ts @@ -31,13 +31,13 @@ export class AlgorandClientTransactionCreator { * const result = await algorandClient.send.payment({ * sender: 'SENDERADDRESS', * receiver: 'RECEIVERADDRESS', - * amount: (4).algos(), + * amount: (4).algo(), * }) * ``` * @example Advanced example * ```typescript * const result = await algorandClient.send.payment({ - * amount: (4).algos(), + * amount: (4).algo(), * receiver: 'RECEIVERADDRESS', * sender: 'SENDERADDRESS', * closeRemainderTo: 'CLOSEREMAINDERTOADDRESS', @@ -48,11 +48,11 @@ export class AlgorandClientTransactionCreator { * // You wouldn't normally set this field * firstValidRound: 1000n, * validityWindow: 10, - * extraFee: (1000).microAlgos(), - * staticFee: (1000).microAlgos(), + * extraFee: (1000).microAlgo(), + * staticFee: (1000).microAlgo(), * // Max fee doesn't make sense with extraFee AND staticFee * // already specified, but here for completeness - * maxFee: (3000).microAlgos(), + * maxFee: (3000).microAlgo(), * }) * ``` * @@ -90,11 +90,11 @@ export class AlgorandClientTransactionCreator { * // You wouldn't normally set this field * firstValidRound: 1000n, * validityWindow: 10, - * extraFee: (1000).microAlgos(), - * staticFee: (1000).microAlgos(), + * extraFee: (1000).microAlgo(), + * staticFee: (1000).microAlgo(), * // Max fee doesn't make sense with extraFee AND staticFee * // already specified, but here for completeness - * maxFee: (3000).microAlgos(), + * maxFee: (3000).microAlgo(), * }) * ``` * @returns The asset create transaction @@ -126,11 +126,11 @@ export class AlgorandClientTransactionCreator { * // You wouldn't normally set this field * firstValidRound: 1000n, * validityWindow: 10, - * extraFee: (1000).microAlgos(), - * staticFee: (1000).microAlgos(), + * extraFee: (1000).microAlgo(), + * staticFee: (1000).microAlgo(), * // Max fee doesn't make sense with extraFee AND staticFee * // already specified, but here for completeness - * maxFee: (3000).microAlgos(), + * maxFee: (3000).microAlgo(), * }) * ``` * @returns The asset config transaction @@ -156,11 +156,11 @@ export class AlgorandClientTransactionCreator { * // You wouldn't normally set this field * firstValidRound: 1000n, * validityWindow: 10, - * extraFee: (1000).microAlgos(), - * staticFee: (1000).microAlgos(), + * extraFee: (1000).microAlgo(), + * staticFee: (1000).microAlgo(), * // Max fee doesn't make sense with extraFee AND staticFee * // already specified, but here for completeness - * maxFee: (3000).microAlgos(), + * maxFee: (3000).microAlgo(), * }) * ``` * @returns The asset freeze transaction @@ -188,11 +188,11 @@ export class AlgorandClientTransactionCreator { * // You wouldn't normally set this field * firstValidRound: 1000n, * validityWindow: 10, - * extraFee: (1000).microAlgos(), - * staticFee: (1000).microAlgos(), + * extraFee: (1000).microAlgo(), + * staticFee: (1000).microAlgo(), * // Max fee doesn't make sense with extraFee AND staticFee * // already specified, but here for completeness - * maxFee: (3000).microAlgos(), + * maxFee: (3000).microAlgo(), * }) * ``` * @returns The asset destroy transaction @@ -221,11 +221,11 @@ export class AlgorandClientTransactionCreator { * // You wouldn't normally set this field * firstValidRound: 1000n, * validityWindow: 10, - * extraFee: (1000).microAlgos(), - * staticFee: (1000).microAlgos(), + * extraFee: (1000).microAlgo(), + * staticFee: (1000).microAlgo(), * // Max fee doesn't make sense with extraFee AND staticFee * // already specified, but here for completeness - * maxFee: (3000).microAlgos(), + * maxFee: (3000).microAlgo(), * }) * ``` * @returns The result of the asset transfer transaction @@ -249,11 +249,11 @@ export class AlgorandClientTransactionCreator { * // You wouldn't normally set this field * firstValidRound: 1000n, * validityWindow: 10, - * extraFee: (1000).microAlgos(), - * staticFee: (1000).microAlgos(), + * extraFee: (1000).microAlgo(), + * staticFee: (1000).microAlgo(), * // Max fee doesn't make sense with extraFee AND staticFee * // already specified, but here for completeness - * maxFee: (3000).microAlgos(), + * maxFee: (3000).microAlgo(), * }) * ``` * @returns The asset opt-in transaction @@ -282,11 +282,11 @@ export class AlgorandClientTransactionCreator { * // You wouldn't normally set this field * firstValidRound: 1000n, * validityWindow: 10, - * extraFee: (1000).microAlgos(), - * staticFee: (1000).microAlgos(), + * extraFee: (1000).microAlgo(), + * staticFee: (1000).microAlgo(), * // Max fee doesn't make sense with extraFee AND staticFee * // already specified, but here for completeness - * maxFee: (3000).microAlgos(), + * maxFee: (3000).microAlgo(), * }) * ``` * @returns The asset opt-out transaction diff --git a/src/types/algorand-client.asset.spec.ts b/src/types/algorand-client.asset.spec.ts index 5bb777c1..813a4324 100644 --- a/src/types/algorand-client.asset.spec.ts +++ b/src/types/algorand-client.asset.spec.ts @@ -45,7 +45,7 @@ describe('Asset capability', () => { const { algorand, testAccount, generateAccount } = localnet.context const dummyAssetId = await generateTestAsset(algorand, testAccount.addr, 1) const dummyAssetIds = [dummyAssetId] - const secondAccount = await generateAccount({ initialFunds: (1).algos() }) + const secondAccount = await generateAccount({ initialFunds: (1).algo() }) const secondAccountInfo = await algorand.account.getInformation(secondAccount.addr) expect(secondAccountInfo.totalAssetsOptedIn).toBe(0) @@ -59,7 +59,7 @@ describe('Asset capability', () => { test('OptIn two batches of asset to an account succeed', async () => { const { algorand, testAccount, generateAccount } = localnet.context const dummyAssetIds: bigint[] = [] - const secondAccount = await generateAccount({ initialFunds: (3).algos() }) + const secondAccount = await generateAccount({ initialFunds: (3).algo() }) for (let i = 0; i < 20; i++) { const dummyAssetId = await generateTestAsset(algorand, testAccount.addr, 0) dummyAssetIds.push(dummyAssetId) @@ -74,7 +74,7 @@ describe('Asset capability', () => { const dummyAssetId = await generateTestAsset(algorand, testAccount.addr, 0) const dummyAssetId2 = await generateTestAsset(algorand, testAccount.addr, 0) const dummyAssetIds = [dummyAssetId, dummyAssetId2] - const secondAccount = await generateAccount({ initialFunds: (1).algos() }) + const secondAccount = await generateAccount({ initialFunds: (1).algo() }) await algorand.asset.bulkOptIn(secondAccount, dummyAssetIds, { validityWindow: 100 }) @@ -91,7 +91,7 @@ describe('Asset capability', () => { const { algorand, testAccount, generateAccount } = localnet.context const dummyAssetId = await generateTestAsset(algorand, testAccount.addr, 0) const dummyAssetIds = [dummyAssetId, 1234567n, -132n] - const secondAccount = await generateAccount({ initialFunds: (1).algos() }) + const secondAccount = await generateAccount({ initialFunds: (1).algo() }) await algorand.asset.bulkOptIn(secondAccount, [dummyAssetId], { validityWindow: 100 }) @@ -111,7 +111,7 @@ describe('Asset capability', () => { const dummyAssetId = await generateTestAsset(algorand, testAccount.addr, 0) const dummyAssetId2 = await generateTestAsset(algorand, testAccount.addr, 0) const dummyAssetIds = [dummyAssetId, dummyAssetId2] - const secondAccount = await generateAccount({ initialFunds: (1).algos() }) + const secondAccount = await generateAccount({ initialFunds: (1).algo() }) await algorand.asset.bulkOptIn(secondAccount, dummyAssetIds, { validityWindow: 100 }) @@ -137,7 +137,7 @@ describe('Asset capability', () => { test('OptIn and OptOut of a single asset ', async () => { const { algorand, testAccount, generateAccount } = localnet.context const dummyAssetId = await generateTestAsset(algorand, testAccount.addr, 0) - const secondAccount = await generateAccount({ initialFunds: (1).algos() }) + const secondAccount = await generateAccount({ initialFunds: (1).algo() }) await algorand.send.assetOptIn({ sender: secondAccount.addr, assetId: dummyAssetId }) @@ -158,7 +158,7 @@ describe('Asset capability', () => { test('OptOut of non-zero balance single asset to an account fails by default', async () => { const { algorand, testAccount, generateAccount } = localnet.context const dummyAssetId = await generateTestAsset(algorand, testAccount.addr, 0) - const secondAccount = await generateAccount({ initialFunds: (1).algos() }) + const secondAccount = await generateAccount({ initialFunds: (1).algo() }) await algorand.send.assetOptIn({ sender: secondAccount.addr, assetId: dummyAssetId }) @@ -181,7 +181,7 @@ describe('Asset capability', () => { test('OptOut of two batches of asset to an account succeed', async () => { const { algorand, testAccount, generateAccount } = localnet.context const dummyAssetIds: bigint[] = [] - const secondAccount = await generateAccount({ initialFunds: (3).algos() }) + const secondAccount = await generateAccount({ initialFunds: (3).algo() }) for (let i = 0; i < 20; i++) { const dummyAssetId = await generateTestAsset(algorand, testAccount.addr, 0) dummyAssetIds.push(dummyAssetId) diff --git a/src/types/algorand-client.spec.ts b/src/types/algorand-client.spec.ts index 194e9449..00883cca 100644 --- a/src/types/algorand-client.spec.ts +++ b/src/types/algorand-client.spec.ts @@ -27,7 +27,7 @@ describe('AlgorandClient', () => { await fixture.beforeEach() alice = fixture.context.testAccount - bob = await fixture.context.generateAccount({ initialFunds: AlgoAmount.MicroAlgos(100_000) }) + bob = await fixture.context.generateAccount({ initialFunds: AlgoAmount.MicroAlgo(100_000) }) algorand = fixture.algorand appClient = algorand.client.getTypedAppClientById(TestContractClient, { @@ -42,12 +42,12 @@ describe('AlgorandClient', () => { test('sendPayment', async () => { const alicePreBalance = (await algorand.account.getInformation(alice)).balance const bobPreBalance = (await algorand.account.getInformation(bob)).balance - await algorand.send.payment({ sender: alice.addr, receiver: bob.addr, amount: AlgoAmount.MicroAlgos(1) }) + await algorand.send.payment({ sender: alice.addr, receiver: bob.addr, amount: AlgoAmount.MicroAlgo(1) }) const alicePostBalance = (await algorand.account.getInformation(alice)).balance const bobPostBalance = (await algorand.account.getInformation(bob)).balance - expect(alicePostBalance.microAlgos).toBe(alicePreBalance.microAlgos - 1001) - expect(bobPostBalance.microAlgos).toBe(bobPreBalance.microAlgos + 1) + expect(alicePostBalance.microAlgo).toBe(alicePreBalance.microAlgo - 1001) + expect(bobPostBalance.microAlgo).toBe(bobPreBalance.microAlgo + 1) }) test('sendAssetCreate', async () => { @@ -63,15 +63,15 @@ describe('AlgorandClient', () => { const doMathAtc = await appClient.compose().doMath({ a: 1, b: 2, operation: 'sum' }).atc() const result = await algorand .newGroup() - .addPayment({ sender: alice.addr, receiver: bob.addr, amount: AlgoAmount.MicroAlgos(1) }) + .addPayment({ sender: alice.addr, receiver: bob.addr, amount: AlgoAmount.MicroAlgo(1) }) .addAtc(doMathAtc) .execute() const alicePostBalance = (await algorand.account.getInformation(alice)).balance const bobPostBalance = (await algorand.account.getInformation(bob)).balance - expect(alicePostBalance.microAlgos).toBe(alicePreBalance.microAlgos - 2001) - expect(bobPostBalance.microAlgos).toBe(bobPreBalance.microAlgos + 1) + expect(alicePostBalance.microAlgo).toBe(alicePreBalance.microAlgo - 2001) + expect(bobPostBalance.microAlgo).toBe(bobPreBalance.microAlgo + 1) expect(result.returns?.[0].returnValue?.valueOf()).toBe(3n) }) @@ -82,7 +82,7 @@ describe('AlgorandClient', () => { const methodRes = await algorand .newGroup() - .addPayment({ sender: alice.addr, receiver: bob.addr, amount: AlgoAmount.MicroAlgos(1), note: new Uint8Array([1]) }) + .addPayment({ sender: alice.addr, receiver: bob.addr, amount: AlgoAmount.MicroAlgo(1), note: new Uint8Array([1]) }) .addMethodCall({ sender: alice.addr, appId: appId, @@ -94,8 +94,8 @@ describe('AlgorandClient', () => { const alicePostBalance = (await algorand.account.getInformation(alice)).balance const bobPostBalance = (await algorand.account.getInformation(bob)).balance - expect(alicePostBalance.microAlgos).toBe(alicePreBalance.microAlgos - 2001) - expect(bobPostBalance.microAlgos).toBe(bobPreBalance.microAlgos + 1) + expect(alicePostBalance.microAlgo).toBe(alicePreBalance.microAlgo - 2001) + expect(bobPostBalance.microAlgo).toBe(bobPreBalance.microAlgo + 1) expect(methodRes.returns?.[0].returnValue?.valueOf()).toBe(3n) }) @@ -105,12 +105,12 @@ describe('AlgorandClient', () => { sender: alice.addr, appId: appId, method: appClient.appClient.getABIMethod('txnArg')!, - args: [algorand.transactions.payment({ sender: alice.addr, receiver: alice.addr, amount: AlgoAmount.MicroAlgos(0) })], + args: [algorand.transactions.payment({ sender: alice.addr, receiver: alice.addr, amount: AlgoAmount.MicroAlgo(0) })], } const txnRes = await algorand .newGroup() - .addPayment({ sender: alice.addr, receiver: alice.addr, amount: AlgoAmount.MicroAlgos(0), note: new Uint8Array([1]) }) + .addPayment({ sender: alice.addr, receiver: alice.addr, amount: AlgoAmount.MicroAlgo(0), note: new Uint8Array([1]) }) .addMethodCall(txnArgParams) .execute() @@ -143,7 +143,7 @@ describe('AlgorandClient', () => { sender: alice.addr, appId: appId, method: appClient.appClient.getABIMethod('txnArg')!, - args: [algorand.transactions.payment({ sender: alice.addr, receiver: alice.addr, amount: AlgoAmount.MicroAlgos(0) })], + args: [algorand.transactions.payment({ sender: alice.addr, receiver: alice.addr, amount: AlgoAmount.MicroAlgo(0) })], } satisfies MethodCallParams const nestedTxnArgRes = await algorand @@ -165,14 +165,14 @@ describe('AlgorandClient', () => { sender: alice.addr, appId: appId, method: appClient.appClient.getABIMethod('txnArg')!, - args: [algorand.transactions.payment({ sender: alice.addr, receiver: alice.addr, amount: AlgoAmount.MicroAlgos(0) })], + args: [algorand.transactions.payment({ sender: alice.addr, receiver: alice.addr, amount: AlgoAmount.MicroAlgo(0) })], } satisfies MethodCallParams const secondTxnCall = { sender: alice.addr, appId: appId, method: appClient.appClient.getABIMethod('txnArg')!, - args: [algorand.transactions.payment({ sender: alice.addr, receiver: alice.addr, amount: AlgoAmount.MicroAlgos(1) })], + args: [algorand.transactions.payment({ sender: alice.addr, receiver: alice.addr, amount: AlgoAmount.MicroAlgo(1) })], note: new Uint8Array([1]), } satisfies MethodCallParams @@ -223,12 +223,12 @@ describe('AlgorandClient', () => { await algorand.send.payment({ sender: (await algorand.account.localNetDispenser()).addr, receiver: alice.addr, - amount: (2).algos(), + amount: (2).algo(), }) // Default validity window is 10 for (let i = 0; i < 10; i++) { - await algorand.send.payment({ sender: alice.addr, receiver: alice.addr, amount: i.microAlgos() }) + await algorand.send.payment({ sender: alice.addr, receiver: alice.addr, amount: i.microAlgo() }) } }) }) diff --git a/src/types/algorand-client.transfer.spec.ts b/src/types/algorand-client.transfer.spec.ts index 00797f13..c3a79aff 100644 --- a/src/types/algorand-client.transfer.spec.ts +++ b/src/types/algorand-client.transfer.spec.ts @@ -28,7 +28,7 @@ describe('Transfer capability', () => { const result = await algorand.send.payment({ sender: testAccount.addr, receiver: secondAccount.addr, - amount: (5).algos(), + amount: (5).algo(), note: 'Transfer 5 Algos', }) @@ -45,7 +45,7 @@ describe('Transfer capability', () => { // eslint-disable-next-line @typescript-eslint/no-non-null-assertion expect(algosdk.encodeAddress(result.confirmation.txn.txn.snd)).toBe(testAccount.addr) - expect(accountInfo.balance.microAlgos).toBe(5_000_000) + expect(accountInfo.balance.microAlgo).toBe(5_000_000) }) test('Transfer Algo respects string lease', async () => { @@ -55,7 +55,7 @@ describe('Transfer capability', () => { await algorand.send.payment({ sender: testAccount.addr, receiver: secondAccount.addr, - amount: (1).algos(), + amount: (1).algo(), lease: 'test', }) @@ -63,7 +63,7 @@ describe('Transfer capability', () => { algorand.send.payment({ sender: testAccount.addr, receiver: secondAccount.addr, - amount: (2).algos(), + amount: (2).algo(), lease: 'test', }), ).rejects.toThrow(/overlapping lease/) @@ -76,7 +76,7 @@ describe('Transfer capability', () => { await algorand.send.payment({ sender: testAccount.addr, receiver: secondAccount.addr, - amount: (1).algos(), + amount: (1).algo(), lease: new Uint8Array([1, 2, 3, 4]), }) @@ -84,7 +84,7 @@ describe('Transfer capability', () => { algorand.send.payment({ sender: testAccount.addr, receiver: secondAccount.addr, - amount: (2).algos(), + amount: (2).algo(), lease: new Uint8Array([1, 2, 3, 4]), }), ).rejects.toThrow(/overlapping lease/) @@ -93,7 +93,7 @@ describe('Transfer capability', () => { test('Transfer ASA, respects lease', async () => { const { algorand, testAccount, generateAccount } = localnet.context const dummyAssetId = await generateTestAsset(algorand, testAccount.addr, 100) - const secondAccount = await generateAccount({ initialFunds: (1).algos() }) + const secondAccount = await generateAccount({ initialFunds: (1).algo() }) await algorand.send.assetOptIn({ sender: secondAccount.addr, assetId: dummyAssetId }) await algorand.send.assetTransfer({ @@ -137,7 +137,7 @@ describe('Transfer capability', () => { test('Transfer ASA, sender is not opted in', async () => { const { algorand, testAccount, generateAccount } = localnet.context const dummyAssetId = await generateTestAsset(algorand, testAccount.addr, 100) - const secondAccount = await generateAccount({ initialFunds: (1).algos() }) + const secondAccount = await generateAccount({ initialFunds: (1).algo() }) await algorand.send.assetOptIn({ sender: secondAccount.addr, assetId: dummyAssetId }) @@ -157,7 +157,7 @@ describe('Transfer capability', () => { test('Transfer ASA, asset doesnt exist', async () => { const { algorand, testAccount, generateAccount } = localnet.context - const secondAccount = await generateAccount({ initialFunds: (1).algos() }) + const secondAccount = await generateAccount({ initialFunds: (1).algo() }) try { await algorand.send.assetTransfer({ @@ -176,7 +176,7 @@ describe('Transfer capability', () => { // @deprecated test - remove when removing transferAsset test('Transfer ASA, without sending', async () => { const { algod, testAccount, generateAccount } = localnet.context - const secondAccount = await generateAccount({ initialFunds: (1).algos() }) + const secondAccount = await generateAccount({ initialFunds: (1).algo() }) const response = await transferAsset( { @@ -197,7 +197,7 @@ describe('Transfer capability', () => { test('Transfer ASA, asset is transfered to another account', async () => { const { algorand, testAccount, generateAccount } = localnet.context const dummyAssetId = await generateTestAsset(algorand, testAccount.addr, 100) - const secondAccount = await generateAccount({ initialFunds: (1).algos() }) + const secondAccount = await generateAccount({ initialFunds: (1).algo() }) await algorand.send.assetOptIn({ sender: secondAccount.addr, assetId: dummyAssetId }) @@ -219,8 +219,8 @@ describe('Transfer capability', () => { test('Transfer ASA, asset is transfered to another account from revocationTarget', async () => { const { algorand, testAccount, generateAccount } = localnet.context const dummyAssetId = await generateTestAsset(algorand, testAccount.addr, 100) - const secondAccount = await generateAccount({ initialFunds: (1).algos() }) - const clawbackAccount = await generateAccount({ initialFunds: (1).algos() }) + const secondAccount = await generateAccount({ initialFunds: (1).algo() }) + const clawbackAccount = await generateAccount({ initialFunds: (1).algo() }) await algorand.send.assetOptIn({ sender: secondAccount.addr, assetId: dummyAssetId }) @@ -260,27 +260,27 @@ describe('Transfer capability', () => { const { algorand, testAccount } = localnet.context const secondAccount = algorand.account.random() - const result = await algorand.account.ensureFunded(secondAccount, testAccount, (1).microAlgos()) + const result = await algorand.account.ensureFunded(secondAccount, testAccount, (1).microAlgo()) const accountInfo = await algorand.account.getInformation(secondAccount.addr) invariant(result) expect(result.transactionId).toBe(result.transaction.txID()) - expect(result.amountFunded.microAlgos).toBe(100_001) - expect(accountInfo.balance.microAlgos).toBe(100_001) + expect(result.amountFunded.microAlgo).toBe(100_001) + expect(accountInfo.balance.microAlgo).toBe(100_001) }) test('ensureFunded respects minimum funding increment', async () => { const { algorand, testAccount, generateAccount } = localnet.context - const secondAccount = await generateAccount({ initialFunds: (100_000).microAlgos() }) + const secondAccount = await generateAccount({ initialFunds: (100_000).microAlgo() }) - const result = await algorand.account.ensureFunded(secondAccount, testAccount, (1).microAlgos(), { - minFundingIncrement: (1).algos(), + const result = await algorand.account.ensureFunded(secondAccount, testAccount, (1).microAlgo(), { + minFundingIncrement: (1).algo(), }) invariant(result) - expect(result.amountFunded.algos).toBe(1) + expect(result.amountFunded.algo).toBe(1) const accountInfo = await algorand.account.getInformation(secondAccount.addr) - expect(accountInfo.balance.microAlgos).toBe(1_100_000) + expect(accountInfo.balance.microAlgo).toBe(1_100_000) }) test('ensureFunded uses dispenser account by default', async () => { @@ -288,15 +288,15 @@ describe('Transfer capability', () => { const secondAccount = algorand.account.random() const dispenser = await algorand.account.dispenserFromEnvironment() - const result = await algorand.account.ensureFundedFromEnvironment(secondAccount, (1).microAlgos(), { - minFundingIncrement: (1).algos(), + const result = await algorand.account.ensureFundedFromEnvironment(secondAccount, (1).microAlgo(), { + minFundingIncrement: (1).algo(), }) invariant(result) const resultReceiver = algosdk.encodeAddress(result.confirmation.txn.txn.snd) expect(resultReceiver).toBe(dispenser.addr) const accountInfo = await algorand.account.getInformation(secondAccount.addr) - expect(accountInfo.balance.algos).toBe(1) + expect(accountInfo.balance.algo).toBe(1) }) test('ensureFunded uses dispenser api with access token successfully', async () => { @@ -313,13 +313,13 @@ describe('Transfer capability', () => { const accountToFund = algorand.account.random() - const result = await algorand.account.ensureFundedFromTestNetDispenserApi(accountToFund, dispenserClient, (100).algos(), { - minFundingIncrement: (0.1).algos(), + const result = await algorand.account.ensureFundedFromTestNetDispenserApi(accountToFund, dispenserClient, (100).algo(), { + minFundingIncrement: (0.1).algo(), }) invariant(result) expect(result.transactionId).toBeDefined() - expect(result.amountFunded.algos).toBe(0.2) + expect(result.amountFunded.algo).toBe(0.2) }) test('ensureFunded uses dispenser api and fails with rejected response', async () => { @@ -336,8 +336,8 @@ describe('Transfer capability', () => { const accountToFund = algorand.account.random() await expect( - algorand.account.ensureFundedFromTestNetDispenserApi(accountToFund, dispenserClient, (100).algos(), { - minFundingIncrement: (1).algos(), + algorand.account.ensureFundedFromTestNetDispenserApi(accountToFund, dispenserClient, (100).algo(), { + minFundingIncrement: (1).algo(), }), ).rejects.toThrowErrorMatchingInlineSnapshot('"dummy_error"') }) @@ -369,7 +369,7 @@ describe('rekey', () => { await algorand.send.payment({ sender: testAccount.addr, receiver: testAccount.addr, - amount: (1).microAlgos(), + amount: (1).microAlgo(), signer: secondAccount.signer, }) }) diff --git a/src/types/amount.spec.ts b/src/types/amount.spec.ts index a17371d4..cd044b12 100644 --- a/src/types/amount.spec.ts +++ b/src/types/amount.spec.ts @@ -10,32 +10,32 @@ describe('amount', () => { expect(`${algos(100)}`).toBe(`100,000,000 µALGO`) }) test('microalgos to microalgos', () => { - expect(microAlgos(100).microAlgos).toBe(100) + expect(microAlgos(100).microAlgo).toBe(100) }) test('algos to microalgos', () => { - expect(algos(100).microAlgos).toBe(100_000_000) + expect(algos(100).microAlgo).toBe(100_000_000) }) test('algos to algos', () => { - expect(algos(100).algos).toBe(100) + expect(algos(100).algo).toBe(100) }) test('small microalgos to algos', () => { - expect(microAlgos(1000).algos).toBe(0.001) + expect(microAlgos(1000).algo).toBe(0.001) }) test('large microalgos to algos', () => { - expect(microAlgos(100_000_000).algos).toBe(100) + expect(microAlgos(100_000_000).algo).toBe(100) }) test('single transaction fee', () => { - expect(transactionFees(1).microAlgos).toBe(1_000) + expect(transactionFees(1).microAlgo).toBe(1_000) }) test('multiple transaction fees', () => { - expect(transactionFees(10).microAlgos).toBe(10_000) + expect(transactionFees(10).microAlgo).toBe(10_000) }) test('algos via Number.prototype', () => { - expect((100).algos()).toBeInstanceOf(AlgoAmount) - expect((100).algos().algos).toBe(100) + expect((100).algo()).toBeInstanceOf(AlgoAmount) + expect((100).algo().algo).toBe(100) }) test('microAlgos via Number.prototype', () => { - expect((100).microAlgos()).toBeInstanceOf(AlgoAmount) - expect((100).microAlgos().microAlgos).toBe(100) + expect((100).microAlgo()).toBeInstanceOf(AlgoAmount) + expect((100).microAlgo().microAlgo).toBe(100) }) }) diff --git a/src/types/amount.ts b/src/types/amount.ts index 2d2c720c..72ca54c3 100644 --- a/src/types/amount.ts +++ b/src/types/amount.ts @@ -2,24 +2,41 @@ import algosdk from 'algosdk' /** Wrapper class to ensure safe, explicit conversion between µAlgo, Algo and numbers */ export class AlgoAmount { - private amountInMicroAlgos + private amountInMicroAlgo /** Return the amount as a number in µAlgo */ get microAlgos() { - return this.amountInMicroAlgos + return this.amountInMicroAlgo + } + + /** Return the amount as a number in µAlgo */ + get microAlgo() { + return this.amountInMicroAlgo } /** Return the amount as a number in Algo */ get algos() { - return algosdk.microalgosToAlgos(this.amountInMicroAlgos) + return algosdk.microalgosToAlgos(this.amountInMicroAlgo) } - constructor(amount: { algos: number } | { microAlgos: number }) { - this.amountInMicroAlgos = 'microAlgos' in amount ? amount.microAlgos : algosdk.algosToMicroalgos(amount.algos) + /** Return the amount as a number in Algo */ + get algo() { + return algosdk.microalgosToAlgos(this.amountInMicroAlgo) + } + + constructor(amount: { algos: number } | { algo: number } | { microAlgos: number } | { microAlgo: number }) { + this.amountInMicroAlgo = + 'microAlgos' in amount + ? amount.microAlgos + : 'microAlgo' in amount + ? amount.microAlgo + : 'algos' in amount + ? algosdk.algosToMicroalgos(amount.algos) + : algosdk.algosToMicroalgos(amount.algo) } toString(): string { - return `${this.microAlgos.toLocaleString('en-US')} µALGO` + return `${this.microAlgo.toLocaleString('en-US')} µALGO` } /** valueOf allows you to use `AlgoAmount` in comparison operations such as `<` and `>=` etc., @@ -27,7 +44,7 @@ export class AlgoAmount { * the algos or microAlgos properties */ valueOf(): number { - return this.microAlgos + return this.microAlgo } /** Create a `AlgoAmount` object representing the given number of Algo */ @@ -35,8 +52,18 @@ export class AlgoAmount { return new AlgoAmount({ algos: amount }) } + /** Create a `AlgoAmount` object representing the given number of Algo */ + static Algo(amount: number) { + return new AlgoAmount({ algos: amount }) + } + /** Create a `AlgoAmount` object representing the given number of µAlgo */ static MicroAlgos(amount: number) { return new AlgoAmount({ microAlgos: amount }) } + + /** Create a `AlgoAmount` object representing the given number of µAlgo */ + static MicroAlgo(amount: number) { + return new AlgoAmount({ microAlgos: amount }) + } } diff --git a/src/types/app-client.spec.ts b/src/types/app-client.spec.ts index 358fb4ca..3ea84360 100644 --- a/src/types/app-client.spec.ts +++ b/src/types/app-client.spec.ts @@ -430,7 +430,7 @@ describe('application-client', () => { const rekeyedAccount = algorand.account.rekeyed(testAccount.addr, rekeyTo) await algokit.transferAlgos( { - amount: (0).algos(), + amount: (0).algo(), from: rekeyedAccount, to: testAccount, }, @@ -547,7 +547,7 @@ describe('application-client', () => { { from: testAccount, to: testAccount.addr, - amount: algokit.microAlgos(Math.ceil(Math.random() * 10000)), + amount: algokit.microAlgo(Math.ceil(Math.random() * 10000)), skipSending: true, }, algod, @@ -573,7 +573,7 @@ describe('application-client', () => { { from: testAccount, to: testAccount.addr, - amount: algokit.microAlgos(Math.ceil(Math.random() * 10000)), + amount: algokit.microAlgo(Math.ceil(Math.random() * 10000)), skipSending: true, }, algod, @@ -597,13 +597,13 @@ describe('application-client', () => { test('Sign transaction in group with different signer if provided', async () => { const { algod, indexer, testAccount, generateAccount } = localnet.context - const signer = await generateAccount({ initialFunds: (1).algos() }) + const signer = await generateAccount({ initialFunds: (1).algo() }) const transaction = ( await algokit.transferAlgos( { from: signer, to: signer.addr, - amount: algokit.microAlgos(Math.ceil(Math.random() * 10000)), + amount: algokit.microAlgo(Math.ceil(Math.random() * 10000)), skipSending: true, }, algod, @@ -746,14 +746,14 @@ describe('application-client', () => { test('Fund app account', async () => { const { algod, indexer, testAccount } = localnet.context - const fundAmount = algokit.microAlgos(200_000) + const fundAmount = algokit.microAlgo(200_000) const { client, app } = await deploy(testAccount, algod, indexer) const result = await client.fundAppAccount({ amount: fundAmount, }) - expect(result.transaction.amount).toBe(fundAmount.microAlgos) + expect(result.transaction.amount).toBe(fundAmount.microAlgo) expect(result.transaction.type).toBe(TransactionType.pay) expect(algosdk.encodeAddress(result.transaction.to.publicKey)).toBe(app.appAddress) expect(algosdk.encodeAddress(result.transaction.from.publicKey)).toBe(testAccount.addr) @@ -798,7 +798,7 @@ describe('application-client', () => { const boxName1Base64 = Buffer.from(boxName1).toString('base64') const boxName2 = new Uint8Array([0, 0, 0, 2]) const boxName2Base64 = Buffer.from(boxName2).toString('base64') - await client.fundAppAccount(algokit.algos(1)) + await client.fundAppAccount(algokit.algo(1)) await client.call({ method: 'set_box', methodArgs: [boxName1, 'value1'], diff --git a/src/types/asset-manager.ts b/src/types/asset-manager.ts index a14279c4..44f0f17c 100644 --- a/src/types/asset-manager.ts +++ b/src/types/asset-manager.ts @@ -226,7 +226,7 @@ export class AssetManager { * // Basic example * algorand.asset.bulkOptIn("ACCOUNTADDRESS", [12345n, 67890n]) * // With configuration - * algorand.asset.bulkOptIn("ACCOUNTADDRESS", [12345n, 67890n], { maxFee: (1000).microAlgos(), suppressLog: true }) + * algorand.asset.bulkOptIn("ACCOUNTADDRESS", [12345n, 67890n], { maxFee: (1000).microAlgo(), suppressLog: true }) * ``` * @returns An array of records matching asset ID to transaction ID of the opt in */ @@ -276,7 +276,7 @@ export class AssetManager { * // Basic example * algorand.asset.bulkOptOut("ACCOUNTADDRESS", [12345n, 67890n]) * // With configuration - * algorand.asset.bulkOptOut("ACCOUNTADDRESS", [12345n, 67890n], { ensureZeroBalance: true, maxFee: (1000).microAlgos(), suppressLog: true }) + * algorand.asset.bulkOptOut("ACCOUNTADDRESS", [12345n, 67890n], { ensureZeroBalance: true, maxFee: (1000).microAlgo(), suppressLog: true }) * ``` * @returns An array of records matching asset ID to transaction ID of the opt in */ diff --git a/src/types/composer.ts b/src/types/composer.ts index 49017c41..0c5ea70c 100644 --- a/src/types/composer.ts +++ b/src/types/composer.ts @@ -610,14 +610,14 @@ export default class AlgoKitComposer { } if (params.staticFee !== undefined) { - txn.fee = params.staticFee.microAlgos + txn.fee = params.staticFee.microAlgo } else { txn.fee = txn.estimateSize() * suggestedParams.fee || algosdk.ALGORAND_MIN_TX_FEE - if (params.extraFee) txn.fee += params.extraFee.microAlgos + if (params.extraFee) txn.fee += params.extraFee.microAlgo } txn.flatFee = true - if (params.maxFee !== undefined && txn.fee > params.maxFee.microAlgos) { + if (params.maxFee !== undefined && txn.fee > params.maxFee.microAlgo) { throw Error(`Transaction fee ${txn.fee} is greater than maxFee ${params.maxFee}`) } @@ -705,7 +705,7 @@ export default class AlgoKitComposer { const txn = algosdk.makePaymentTxnWithSuggestedParamsFromObject({ from: params.sender, to: params.receiver, - amount: params.amount.microAlgos, + amount: params.amount.microAlgo, closeRemainderTo: params.closeRemainderTo, suggestedParams, }) diff --git a/src/types/kmd-account-manager.ts b/src/types/kmd-account-manager.ts index 7cc876d3..9c5d0068 100644 --- a/src/types/kmd-account-manager.ts +++ b/src/types/kmd-account-manager.ts @@ -125,7 +125,7 @@ export class KmdAccountManager { * ```typescript * // Idempotently get (if exists) or crate (if it doesn't exist yet) an account by name using KMD * // if creating it then fund it with 2 ALGO from the default dispenser account - * const newAccount = await kmdAccountManager.getOrCreateWalletAccount('account1', (2).algos()) + * const newAccount = await kmdAccountManager.getOrCreateWalletAccount('account1', (2).algo()) * // This will return the same account as above since the name matches * const existingAccount = await kmdAccountManager.getOrCreateWalletAccount('account1') * ``` @@ -155,7 +155,7 @@ export class KmdAccountManager { Config.logger.info( `LocalNet account '${name}' doesn't yet exist; created account ${account.addr} with keys stored in KMD and funding with ${ - fundWith?.algos ?? 1000 + fundWith?.algo ?? 1000 } ALGO`, ) @@ -167,7 +167,7 @@ export class KmdAccountManager { getSuggestedParams: () => this._clientManager.algod.getTransactionParams().do(), }) .addPayment({ - amount: fundWith ?? AlgoAmount.Algos(1000), + amount: fundWith ?? AlgoAmount.Algo(1000), receiver: account.addr, sender: dispenser.addr, }) From 3c637f2e1cf88ed5236e8f9ebfa8a1a031708c84 Mon Sep 17 00:00:00 2001 From: "Rob Moore (MakerX)" Date: Wed, 28 Aug 2024 14:11:29 +0800 Subject: [PATCH 18/18] Renamed AlgorandClientSender to AlgorandClientTransactionSender for consistency --- docs/code/README.md | 2 +- .../types_account_manager.AccountManager.md | 4 +- .../types_algorand_client.AlgorandClient.md | 18 +-- ...sender.AlgorandClientTransactionSender.md} | 136 +++++++++--------- .../modules/types_algorand_client_sender.md | 25 ---- ...ypes_algorand_client_transaction_sender.md | 25 ++++ src/transaction/legacy-bridge.ts | 8 +- src/types/account-manager.ts | 2 +- ... => algorand-client-transaction-sender.ts} | 2 +- src/types/algorand-client.ts | 8 +- 10 files changed, 115 insertions(+), 115 deletions(-) rename docs/code/classes/{types_algorand_client_sender.AlgorandClientSender.md => types_algorand_client_transaction_sender.AlgorandClientTransactionSender.md} (75%) delete mode 100644 docs/code/modules/types_algorand_client_sender.md create mode 100644 docs/code/modules/types_algorand_client_transaction_sender.md rename src/types/{algorand-client-sender.ts => algorand-client-transaction-sender.ts} (99%) diff --git a/docs/code/README.md b/docs/code/README.md index 6d97e94c..f07fa41d 100644 --- a/docs/code/README.md +++ b/docs/code/README.md @@ -13,8 +13,8 @@ - [types/account-manager.spec](modules/types_account_manager_spec.md) - [types/algo-http-client-with-retry](modules/types_algo_http_client_with_retry.md) - [types/algorand-client](modules/types_algorand_client.md) -- [types/algorand-client-sender](modules/types_algorand_client_sender.md) - [types/algorand-client-transaction-creator](modules/types_algorand_client_transaction_creator.md) +- [types/algorand-client-transaction-sender](modules/types_algorand_client_transaction_sender.md) - [types/algorand-client.asset.spec](modules/types_algorand_client_asset_spec.md) - [types/algorand-client.spec](modules/types_algorand_client_spec.md) - [types/algorand-client.transfer.spec](modules/types_algorand_client_transfer_spec.md) diff --git a/docs/code/classes/types_account_manager.AccountManager.md b/docs/code/classes/types_account_manager.AccountManager.md index a3e09a0c..25ac4e9b 100644 --- a/docs/code/classes/types_account_manager.AccountManager.md +++ b/docs/code/classes/types_account_manager.AccountManager.md @@ -671,7 +671,7 @@ ___ ### rekeyAccount -▸ **rekeyAccount**(`account`, `rekeyTo`, `options?`): `Promise`\<[`SendSingleTransactionResult`](../modules/types_algorand_client_sender.md#sendsingletransactionresult)\> +▸ **rekeyAccount**(`account`, `rekeyTo`, `options?`): `Promise`\<[`SendSingleTransactionResult`](../modules/types_algorand_client_transaction_sender.md#sendsingletransactionresult)\> Rekey an account to a new address. @@ -687,7 +687,7 @@ Rekey an account to a new address. #### Returns -`Promise`\<[`SendSingleTransactionResult`](../modules/types_algorand_client_sender.md#sendsingletransactionresult)\> +`Promise`\<[`SendSingleTransactionResult`](../modules/types_algorand_client_transaction_sender.md#sendsingletransactionresult)\> The result of the transaction and the transaction that was sent diff --git a/docs/code/classes/types_algorand_client.AlgorandClient.md b/docs/code/classes/types_algorand_client.AlgorandClient.md index 9bbd9719..3a9df0a9 100644 --- a/docs/code/classes/types_algorand_client.AlgorandClient.md +++ b/docs/code/classes/types_algorand_client.AlgorandClient.md @@ -21,8 +21,8 @@ A client that brokers easy access to Algorand functionality. - [\_cachedSuggestedParamsTimeout](types_algorand_client.AlgorandClient.md#_cachedsuggestedparamstimeout) - [\_clientManager](types_algorand_client.AlgorandClient.md#_clientmanager) - [\_defaultValidityWindow](types_algorand_client.AlgorandClient.md#_defaultvaliditywindow) -- [\_sender](types_algorand_client.AlgorandClient.md#_sender) - [\_transactionCreator](types_algorand_client.AlgorandClient.md#_transactioncreator) +- [\_transactionSender](types_algorand_client.AlgorandClient.md#_transactionsender) ### Accessors @@ -141,23 +141,23 @@ ___ ___ -### \_sender +### \_transactionCreator -• `Private` **\_sender**: [`AlgorandClientSender`](types_algorand_client_sender.AlgorandClientSender.md) +• `Private` **\_transactionCreator**: [`AlgorandClientTransactionCreator`](types_algorand_client_transaction_creator.AlgorandClientTransactionCreator.md) #### Defined in -[src/types/algorand-client.ts:20](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/algorand-client.ts#L20) +[src/types/algorand-client.ts:21](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/algorand-client.ts#L21) ___ -### \_transactionCreator +### \_transactionSender -• `Private` **\_transactionCreator**: [`AlgorandClientTransactionCreator`](types_algorand_client_transaction_creator.AlgorandClientTransactionCreator.md) +• `Private` **\_transactionSender**: [`AlgorandClientTransactionSender`](types_algorand_client_transaction_sender.AlgorandClientTransactionSender.md) #### Defined in -[src/types/algorand-client.ts:21](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/algorand-client.ts#L21) +[src/types/algorand-client.ts:20](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/algorand-client.ts#L20) ## Accessors @@ -211,13 +211,13 @@ ___ ### send -• `get` **send**(): [`AlgorandClientSender`](types_algorand_client_sender.AlgorandClientSender.md) +• `get` **send**(): [`AlgorandClientTransactionSender`](types_algorand_client_transaction_sender.AlgorandClientTransactionSender.md) Methods for sending a single transaction. #### Returns -[`AlgorandClientSender`](types_algorand_client_sender.AlgorandClientSender.md) +[`AlgorandClientTransactionSender`](types_algorand_client_transaction_sender.AlgorandClientTransactionSender.md) #### Defined in diff --git a/docs/code/classes/types_algorand_client_sender.AlgorandClientSender.md b/docs/code/classes/types_algorand_client_transaction_sender.AlgorandClientTransactionSender.md similarity index 75% rename from docs/code/classes/types_algorand_client_sender.AlgorandClientSender.md rename to docs/code/classes/types_algorand_client_transaction_sender.AlgorandClientTransactionSender.md index 6b4a23d9..05ea5455 100644 --- a/docs/code/classes/types_algorand_client_sender.AlgorandClientSender.md +++ b/docs/code/classes/types_algorand_client_transaction_sender.AlgorandClientTransactionSender.md @@ -1,8 +1,8 @@ -[@algorandfoundation/algokit-utils](../README.md) / [types/algorand-client-sender](../modules/types_algorand_client_sender.md) / AlgorandClientSender +[@algorandfoundation/algokit-utils](../README.md) / [types/algorand-client-transaction-sender](../modules/types_algorand_client_transaction_sender.md) / AlgorandClientTransactionSender -# Class: AlgorandClientSender +# Class: AlgorandClientTransactionSender -[types/algorand-client-sender](../modules/types_algorand_client_sender.md).AlgorandClientSender +[types/algorand-client-transaction-sender](../modules/types_algorand_client_transaction_sender.md).AlgorandClientTransactionSender Orchestrates sending transactions for `AlgorandClient`. @@ -10,33 +10,33 @@ Orchestrates sending transactions for `AlgorandClient`. ### Constructors -- [constructor](types_algorand_client_sender.AlgorandClientSender.md#constructor) +- [constructor](types_algorand_client_transaction_sender.AlgorandClientTransactionSender.md#constructor) ### Properties -- [\_assetManager](types_algorand_client_sender.AlgorandClientSender.md#_assetmanager) -- [\_newGroup](types_algorand_client_sender.AlgorandClientSender.md#_newgroup) -- [appCall](types_algorand_client_sender.AlgorandClientSender.md#appcall) -- [assetConfig](types_algorand_client_sender.AlgorandClientSender.md#assetconfig) -- [assetDestroy](types_algorand_client_sender.AlgorandClientSender.md#assetdestroy) -- [assetFreeze](types_algorand_client_sender.AlgorandClientSender.md#assetfreeze) -- [assetOptIn](types_algorand_client_sender.AlgorandClientSender.md#assetoptin) -- [assetTransfer](types_algorand_client_sender.AlgorandClientSender.md#assettransfer) -- [methodCall](types_algorand_client_sender.AlgorandClientSender.md#methodcall) -- [onlineKeyRegistration](types_algorand_client_sender.AlgorandClientSender.md#onlinekeyregistration) -- [payment](types_algorand_client_sender.AlgorandClientSender.md#payment) +- [\_assetManager](types_algorand_client_transaction_sender.AlgorandClientTransactionSender.md#_assetmanager) +- [\_newGroup](types_algorand_client_transaction_sender.AlgorandClientTransactionSender.md#_newgroup) +- [appCall](types_algorand_client_transaction_sender.AlgorandClientTransactionSender.md#appcall) +- [assetConfig](types_algorand_client_transaction_sender.AlgorandClientTransactionSender.md#assetconfig) +- [assetDestroy](types_algorand_client_transaction_sender.AlgorandClientTransactionSender.md#assetdestroy) +- [assetFreeze](types_algorand_client_transaction_sender.AlgorandClientTransactionSender.md#assetfreeze) +- [assetOptIn](types_algorand_client_transaction_sender.AlgorandClientTransactionSender.md#assetoptin) +- [assetTransfer](types_algorand_client_transaction_sender.AlgorandClientTransactionSender.md#assettransfer) +- [methodCall](types_algorand_client_transaction_sender.AlgorandClientTransactionSender.md#methodcall) +- [onlineKeyRegistration](types_algorand_client_transaction_sender.AlgorandClientTransactionSender.md#onlinekeyregistration) +- [payment](types_algorand_client_transaction_sender.AlgorandClientTransactionSender.md#payment) ### Methods -- [\_send](types_algorand_client_sender.AlgorandClientSender.md#_send) -- [assetCreate](types_algorand_client_sender.AlgorandClientSender.md#assetcreate) -- [assetOptOut](types_algorand_client_sender.AlgorandClientSender.md#assetoptout) +- [\_send](types_algorand_client_transaction_sender.AlgorandClientTransactionSender.md#_send) +- [assetCreate](types_algorand_client_transaction_sender.AlgorandClientTransactionSender.md#assetcreate) +- [assetOptOut](types_algorand_client_transaction_sender.AlgorandClientTransactionSender.md#assetoptout) ## Constructors ### constructor -• **new AlgorandClientSender**(`newGroup`, `assetManager`): [`AlgorandClientSender`](types_algorand_client_sender.AlgorandClientSender.md) +• **new AlgorandClientTransactionSender**(`newGroup`, `assetManager`): [`AlgorandClientTransactionSender`](types_algorand_client_transaction_sender.AlgorandClientTransactionSender.md) Creates a new `AlgorandClientSender` @@ -49,11 +49,11 @@ Creates a new `AlgorandClientSender` #### Returns -[`AlgorandClientSender`](types_algorand_client_sender.AlgorandClientSender.md) +[`AlgorandClientTransactionSender`](types_algorand_client_transaction_sender.AlgorandClientTransactionSender.md) #### Defined in -[src/types/algorand-client-sender.ts:22](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/algorand-client-sender.ts#L22) +[src/types/algorand-client-transaction-sender.ts:22](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/algorand-client-transaction-sender.ts#L22) ## Properties @@ -63,7 +63,7 @@ Creates a new `AlgorandClientSender` #### Defined in -[src/types/algorand-client-sender.ts:15](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/algorand-client-sender.ts#L15) +[src/types/algorand-client-transaction-sender.ts:15](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/algorand-client-transaction-sender.ts#L15) ___ @@ -81,13 +81,13 @@ ___ #### Defined in -[src/types/algorand-client-sender.ts:14](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/algorand-client-sender.ts#L14) +[src/types/algorand-client-transaction-sender.ts:14](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/algorand-client-transaction-sender.ts#L14) ___ ### appCall -• **appCall**: (`params`: [`CommonTransactionParams`](../modules/types_composer.md#commontransactionparams) & \{ `accountReferences?`: `string`[] ; `appId?`: `bigint` ; `appReferences?`: `bigint`[] ; `approvalProgram?`: `Uint8Array` ; `args?`: `Uint8Array`[] ; `assetReferences?`: `bigint`[] ; `boxReferences?`: `BoxReference`[] ; `clearProgram?`: `Uint8Array` ; `extraPages?`: `number` ; `onComplete?`: `OnApplicationComplete` ; `schema?`: \{ `globalByteSlices`: `number` ; `globalUints`: `number` ; `localByteSlices`: `number` ; `localUints`: `number` } } & [`ExecuteParams`](../interfaces/types_composer.ExecuteParams.md)) => `Promise`\<[`SendSingleTransactionResult`](../modules/types_algorand_client_sender.md#sendsingletransactionresult)\> +• **appCall**: (`params`: [`CommonTransactionParams`](../modules/types_composer.md#commontransactionparams) & \{ `accountReferences?`: `string`[] ; `appId?`: `bigint` ; `appReferences?`: `bigint`[] ; `approvalProgram?`: `Uint8Array` ; `args?`: `Uint8Array`[] ; `assetReferences?`: `bigint`[] ; `boxReferences?`: `BoxReference`[] ; `clearProgram?`: `Uint8Array` ; `extraPages?`: `number` ; `onComplete?`: `OnApplicationComplete` ; `schema?`: \{ `globalByteSlices`: `number` ; `globalUints`: `number` ; `localByteSlices`: `number` ; `localUints`: `number` } } & [`ExecuteParams`](../interfaces/types_composer.ExecuteParams.md)) => `Promise`\<[`SendSingleTransactionResult`](../modules/types_algorand_client_transaction_sender.md#sendsingletransactionresult)\> Call a smart contract. @@ -95,7 +95,7 @@ Note: you may prefer to use `algorandClient.client` to get an app client for mor #### Type declaration -▸ (`params`): `Promise`\<[`SendSingleTransactionResult`](../modules/types_algorand_client_sender.md#sendsingletransactionresult)\> +▸ (`params`): `Promise`\<[`SendSingleTransactionResult`](../modules/types_algorand_client_transaction_sender.md#sendsingletransactionresult)\> ##### Parameters @@ -105,17 +105,17 @@ Note: you may prefer to use `algorandClient.client` to get an app client for mor ##### Returns -`Promise`\<[`SendSingleTransactionResult`](../modules/types_algorand_client_sender.md#sendsingletransactionresult)\> +`Promise`\<[`SendSingleTransactionResult`](../modules/types_algorand_client_transaction_sender.md#sendsingletransactionresult)\> #### Defined in -[src/types/algorand-client-sender.ts:448](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/algorand-client-sender.ts#L448) +[src/types/algorand-client-transaction-sender.ts:448](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/algorand-client-transaction-sender.ts#L448) ___ ### assetConfig -• **assetConfig**: (`params`: [`CommonTransactionParams`](../modules/types_composer.md#commontransactionparams) & \{ `assetId`: `bigint` ; `clawback?`: `string` ; `freeze?`: `string` ; `manager`: `undefined` \| `string` ; `reserve?`: `string` } & [`ExecuteParams`](../interfaces/types_composer.ExecuteParams.md)) => `Promise`\<[`SendSingleTransactionResult`](../modules/types_algorand_client_sender.md#sendsingletransactionresult)\> +• **assetConfig**: (`params`: [`CommonTransactionParams`](../modules/types_composer.md#commontransactionparams) & \{ `assetId`: `bigint` ; `clawback?`: `string` ; `freeze?`: `string` ; `manager`: `undefined` \| `string` ; `reserve?`: `string` } & [`ExecuteParams`](../interfaces/types_composer.ExecuteParams.md)) => `Promise`\<[`SendSingleTransactionResult`](../modules/types_algorand_client_transaction_sender.md#sendsingletransactionresult)\> Configure an existing Algorand Standard Asset. @@ -160,7 +160,7 @@ await algorand.send.assetConfig({ #### Type declaration -▸ (`params`): `Promise`\<[`SendSingleTransactionResult`](../modules/types_algorand_client_sender.md#sendsingletransactionresult)\> +▸ (`params`): `Promise`\<[`SendSingleTransactionResult`](../modules/types_algorand_client_transaction_sender.md#sendsingletransactionresult)\> ##### Parameters @@ -170,17 +170,17 @@ await algorand.send.assetConfig({ ##### Returns -`Promise`\<[`SendSingleTransactionResult`](../modules/types_algorand_client_sender.md#sendsingletransactionresult)\> +`Promise`\<[`SendSingleTransactionResult`](../modules/types_algorand_client_transaction_sender.md#sendsingletransactionresult)\> #### Defined in -[src/types/algorand-client-sender.ts:203](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/algorand-client-sender.ts#L203) +[src/types/algorand-client-transaction-sender.ts:203](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/algorand-client-transaction-sender.ts#L203) ___ ### assetDestroy -• **assetDestroy**: (`params`: [`CommonTransactionParams`](../modules/types_composer.md#commontransactionparams) & \{ `assetId`: `bigint` } & [`ExecuteParams`](../interfaces/types_composer.ExecuteParams.md)) => `Promise`\<[`SendSingleTransactionResult`](../modules/types_algorand_client_sender.md#sendsingletransactionresult)\> +• **assetDestroy**: (`params`: [`CommonTransactionParams`](../modules/types_composer.md#commontransactionparams) & \{ `assetId`: `bigint` } & [`ExecuteParams`](../interfaces/types_composer.ExecuteParams.md)) => `Promise`\<[`SendSingleTransactionResult`](../modules/types_algorand_client_transaction_sender.md#sendsingletransactionresult)\> Destroys an Algorand Standard Asset. @@ -221,7 +221,7 @@ await algorand.send.assetDestroy({ #### Type declaration -▸ (`params`): `Promise`\<[`SendSingleTransactionResult`](../modules/types_algorand_client_sender.md#sendsingletransactionresult)\> +▸ (`params`): `Promise`\<[`SendSingleTransactionResult`](../modules/types_algorand_client_transaction_sender.md#sendsingletransactionresult)\> ##### Parameters @@ -231,17 +231,17 @@ await algorand.send.assetDestroy({ ##### Returns -`Promise`\<[`SendSingleTransactionResult`](../modules/types_algorand_client_sender.md#sendsingletransactionresult)\> +`Promise`\<[`SendSingleTransactionResult`](../modules/types_algorand_client_transaction_sender.md#sendsingletransactionresult)\> #### Defined in -[src/types/algorand-client-sender.ts:283](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/algorand-client-sender.ts#L283) +[src/types/algorand-client-transaction-sender.ts:283](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/algorand-client-transaction-sender.ts#L283) ___ ### assetFreeze -• **assetFreeze**: (`params`: [`CommonTransactionParams`](../modules/types_composer.md#commontransactionparams) & \{ `account`: `string` ; `assetId`: `bigint` ; `frozen`: `boolean` } & [`ExecuteParams`](../interfaces/types_composer.ExecuteParams.md)) => `Promise`\<[`SendSingleTransactionResult`](../modules/types_algorand_client_sender.md#sendsingletransactionresult)\> +• **assetFreeze**: (`params`: [`CommonTransactionParams`](../modules/types_composer.md#commontransactionparams) & \{ `account`: `string` ; `assetId`: `bigint` ; `frozen`: `boolean` } & [`ExecuteParams`](../interfaces/types_composer.ExecuteParams.md)) => `Promise`\<[`SendSingleTransactionResult`](../modules/types_algorand_client_transaction_sender.md#sendsingletransactionresult)\> Freeze or unfreeze an Algorand Standard Asset for an account. @@ -280,7 +280,7 @@ await algorand.send.assetFreeze({ #### Type declaration -▸ (`params`): `Promise`\<[`SendSingleTransactionResult`](../modules/types_algorand_client_sender.md#sendsingletransactionresult)\> +▸ (`params`): `Promise`\<[`SendSingleTransactionResult`](../modules/types_algorand_client_transaction_sender.md#sendsingletransactionresult)\> ##### Parameters @@ -290,17 +290,17 @@ await algorand.send.assetFreeze({ ##### Returns -`Promise`\<[`SendSingleTransactionResult`](../modules/types_algorand_client_sender.md#sendsingletransactionresult)\> +`Promise`\<[`SendSingleTransactionResult`](../modules/types_algorand_client_transaction_sender.md#sendsingletransactionresult)\> #### Defined in -[src/types/algorand-client-sender.ts:242](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/algorand-client-sender.ts#L242) +[src/types/algorand-client-transaction-sender.ts:242](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/algorand-client-transaction-sender.ts#L242) ___ ### assetOptIn -• **assetOptIn**: (`params`: [`CommonTransactionParams`](../modules/types_composer.md#commontransactionparams) & \{ `assetId`: `bigint` } & [`ExecuteParams`](../interfaces/types_composer.ExecuteParams.md)) => `Promise`\<[`SendSingleTransactionResult`](../modules/types_algorand_client_sender.md#sendsingletransactionresult)\> +• **assetOptIn**: (`params`: [`CommonTransactionParams`](../modules/types_composer.md#commontransactionparams) & \{ `assetId`: `bigint` } & [`ExecuteParams`](../interfaces/types_composer.ExecuteParams.md)) => `Promise`\<[`SendSingleTransactionResult`](../modules/types_algorand_client_transaction_sender.md#sendsingletransactionresult)\> Opt an account into an Algorand Standard Asset. @@ -337,7 +337,7 @@ await algorand.send.assetOptIn({ #### Type declaration -▸ (`params`): `Promise`\<[`SendSingleTransactionResult`](../modules/types_algorand_client_sender.md#sendsingletransactionresult)\> +▸ (`params`): `Promise`\<[`SendSingleTransactionResult`](../modules/types_algorand_client_transaction_sender.md#sendsingletransactionresult)\> ##### Parameters @@ -347,17 +347,17 @@ await algorand.send.assetOptIn({ ##### Returns -`Promise`\<[`SendSingleTransactionResult`](../modules/types_algorand_client_sender.md#sendsingletransactionresult)\> +`Promise`\<[`SendSingleTransactionResult`](../modules/types_algorand_client_transaction_sender.md#sendsingletransactionresult)\> #### Defined in -[src/types/algorand-client-sender.ts:363](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/algorand-client-sender.ts#L363) +[src/types/algorand-client-transaction-sender.ts:363](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/algorand-client-transaction-sender.ts#L363) ___ ### assetTransfer -• **assetTransfer**: (`params`: [`CommonTransactionParams`](../modules/types_composer.md#commontransactionparams) & \{ `amount`: `bigint` ; `assetId`: `bigint` ; `clawbackTarget?`: `string` ; `closeAssetTo?`: `string` ; `receiver`: `string` } & [`ExecuteParams`](../interfaces/types_composer.ExecuteParams.md)) => `Promise`\<[`SendSingleTransactionResult`](../modules/types_algorand_client_sender.md#sendsingletransactionresult)\> +• **assetTransfer**: (`params`: [`CommonTransactionParams`](../modules/types_composer.md#commontransactionparams) & \{ `amount`: `bigint` ; `assetId`: `bigint` ; `clawbackTarget?`: `string` ; `closeAssetTo?`: `string` ; `receiver`: `string` } & [`ExecuteParams`](../interfaces/types_composer.ExecuteParams.md)) => `Promise`\<[`SendSingleTransactionResult`](../modules/types_algorand_client_transaction_sender.md#sendsingletransactionresult)\> Transfer an Algorand Standard Asset. @@ -399,7 +399,7 @@ await algorand.send.assetTransfer({ #### Type declaration -▸ (`params`): `Promise`\<[`SendSingleTransactionResult`](../modules/types_algorand_client_sender.md#sendsingletransactionresult)\> +▸ (`params`): `Promise`\<[`SendSingleTransactionResult`](../modules/types_algorand_client_transaction_sender.md#sendsingletransactionresult)\> ##### Parameters @@ -409,17 +409,17 @@ await algorand.send.assetTransfer({ ##### Returns -`Promise`\<[`SendSingleTransactionResult`](../modules/types_algorand_client_sender.md#sendsingletransactionresult)\> +`Promise`\<[`SendSingleTransactionResult`](../modules/types_algorand_client_transaction_sender.md#sendsingletransactionresult)\> #### Defined in -[src/types/algorand-client-sender.ts:325](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/algorand-client-sender.ts#L325) +[src/types/algorand-client-transaction-sender.ts:325](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/algorand-client-transaction-sender.ts#L325) ___ ### methodCall -• **methodCall**: (`params`: [`CommonTransactionParams`](../modules/types_composer.md#commontransactionparams) & `Omit`\<[`AppCallParams`](../modules/types_composer.md#appcallparams), ``"args"``\> & \{ `appId`: `bigint` ; `args?`: (`TransactionWithSigner` \| `Transaction` \| `ABIValue` \| `Promise`\<`Transaction`\> \| [`MethodCallParams`](../modules/types_composer.md#methodcallparams))[] ; `method`: `ABIMethod` } & [`ExecuteParams`](../interfaces/types_composer.ExecuteParams.md)) => `Promise`\<[`SendSingleTransactionResult`](../modules/types_algorand_client_sender.md#sendsingletransactionresult)\> +• **methodCall**: (`params`: [`CommonTransactionParams`](../modules/types_composer.md#commontransactionparams) & `Omit`\<[`AppCallParams`](../modules/types_composer.md#appcallparams), ``"args"``\> & \{ `appId`: `bigint` ; `args?`: (`TransactionWithSigner` \| `Transaction` \| `ABIValue` \| `Promise`\<`Transaction`\> \| [`MethodCallParams`](../modules/types_composer.md#methodcallparams))[] ; `method`: `ABIMethod` } & [`ExecuteParams`](../interfaces/types_composer.ExecuteParams.md)) => `Promise`\<[`SendSingleTransactionResult`](../modules/types_algorand_client_transaction_sender.md#sendsingletransactionresult)\> Call a smart contract ABI method. @@ -427,7 +427,7 @@ Note: you may prefer to use `algorandClient.client` to get an app client for mor #### Type declaration -▸ (`params`): `Promise`\<[`SendSingleTransactionResult`](../modules/types_algorand_client_sender.md#sendsingletransactionresult)\> +▸ (`params`): `Promise`\<[`SendSingleTransactionResult`](../modules/types_algorand_client_transaction_sender.md#sendsingletransactionresult)\> ##### Parameters @@ -437,23 +437,23 @@ Note: you may prefer to use `algorandClient.client` to get an app client for mor ##### Returns -`Promise`\<[`SendSingleTransactionResult`](../modules/types_algorand_client_sender.md#sendsingletransactionresult)\> +`Promise`\<[`SendSingleTransactionResult`](../modules/types_algorand_client_transaction_sender.md#sendsingletransactionresult)\> #### Defined in -[src/types/algorand-client-sender.ts:454](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/algorand-client-sender.ts#L454) +[src/types/algorand-client-transaction-sender.ts:454](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/algorand-client-transaction-sender.ts#L454) ___ ### onlineKeyRegistration -• **onlineKeyRegistration**: (`params`: [`CommonTransactionParams`](../modules/types_composer.md#commontransactionparams) & \{ `selectionKey`: `Uint8Array` ; `stateProofKey?`: `Uint8Array` ; `voteFirst`: `bigint` ; `voteKey`: `Uint8Array` ; `voteKeyDilution`: `bigint` ; `voteLast`: `bigint` } & [`ExecuteParams`](../interfaces/types_composer.ExecuteParams.md)) => `Promise`\<[`SendSingleTransactionResult`](../modules/types_algorand_client_sender.md#sendsingletransactionresult)\> +• **onlineKeyRegistration**: (`params`: [`CommonTransactionParams`](../modules/types_composer.md#commontransactionparams) & \{ `selectionKey`: `Uint8Array` ; `stateProofKey?`: `Uint8Array` ; `voteFirst`: `bigint` ; `voteKey`: `Uint8Array` ; `voteKeyDilution`: `bigint` ; `voteLast`: `bigint` } & [`ExecuteParams`](../interfaces/types_composer.ExecuteParams.md)) => `Promise`\<[`SendSingleTransactionResult`](../modules/types_algorand_client_transaction_sender.md#sendsingletransactionresult)\> Register an online key. #### Type declaration -▸ (`params`): `Promise`\<[`SendSingleTransactionResult`](../modules/types_algorand_client_sender.md#sendsingletransactionresult)\> +▸ (`params`): `Promise`\<[`SendSingleTransactionResult`](../modules/types_algorand_client_transaction_sender.md#sendsingletransactionresult)\> ##### Parameters @@ -463,17 +463,17 @@ Register an online key. ##### Returns -`Promise`\<[`SendSingleTransactionResult`](../modules/types_algorand_client_sender.md#sendsingletransactionresult)\> +`Promise`\<[`SendSingleTransactionResult`](../modules/types_algorand_client_transaction_sender.md#sendsingletransactionresult)\> #### Defined in -[src/types/algorand-client-sender.ts:456](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/algorand-client-sender.ts#L456) +[src/types/algorand-client-transaction-sender.ts:456](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/algorand-client-transaction-sender.ts#L456) ___ ### payment -• **payment**: (`params`: [`CommonTransactionParams`](../modules/types_composer.md#commontransactionparams) & \{ `amount`: [`AlgoAmount`](types_amount.AlgoAmount.md) ; `closeRemainderTo?`: `string` ; `receiver`: `string` } & [`ExecuteParams`](../interfaces/types_composer.ExecuteParams.md)) => `Promise`\<[`SendSingleTransactionResult`](../modules/types_algorand_client_sender.md#sendsingletransactionresult)\> +• **payment**: (`params`: [`CommonTransactionParams`](../modules/types_composer.md#commontransactionparams) & \{ `amount`: [`AlgoAmount`](types_amount.AlgoAmount.md) ; `closeRemainderTo?`: `string` ; `receiver`: `string` } & [`ExecuteParams`](../interfaces/types_composer.ExecuteParams.md)) => `Promise`\<[`SendSingleTransactionResult`](../modules/types_algorand_client_transaction_sender.md#sendsingletransactionresult)\> Send a payment transaction to transfer Algo between accounts. @@ -518,7 +518,7 @@ const result = await algorandClient.send.payment({ #### Type declaration -▸ (`params`): `Promise`\<[`SendSingleTransactionResult`](../modules/types_algorand_client_sender.md#sendsingletransactionresult)\> +▸ (`params`): `Promise`\<[`SendSingleTransactionResult`](../modules/types_algorand_client_transaction_sender.md#sendsingletransactionresult)\> ##### Parameters @@ -528,17 +528,17 @@ const result = await algorandClient.send.payment({ ##### Returns -`Promise`\<[`SendSingleTransactionResult`](../modules/types_algorand_client_sender.md#sendsingletransactionresult)\> +`Promise`\<[`SendSingleTransactionResult`](../modules/types_algorand_client_transaction_sender.md#sendsingletransactionresult)\> #### Defined in -[src/types/algorand-client-sender.ts:103](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/algorand-client-sender.ts#L103) +[src/types/algorand-client-transaction-sender.ts:103](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/algorand-client-transaction-sender.ts#L103) ## Methods ### \_send -▸ **_send**\<`T`\>(`c`, `log?`): (`params`: `T` & [`ExecuteParams`](../interfaces/types_composer.ExecuteParams.md)) => `Promise`\<[`SendSingleTransactionResult`](../modules/types_algorand_client_sender.md#sendsingletransactionresult)\> +▸ **_send**\<`T`\>(`c`, `log?`): (`params`: `T` & [`ExecuteParams`](../interfaces/types_composer.ExecuteParams.md)) => `Promise`\<[`SendSingleTransactionResult`](../modules/types_algorand_client_transaction_sender.md#sendsingletransactionresult)\> #### Type parameters @@ -552,14 +552,14 @@ const result = await algorandClient.send.payment({ | :------ | :------ | | `c` | (`c`: [`default`](types_composer.default.md)) => (`params`: `T`) => [`default`](types_composer.default.md) | | `log?` | `Object` | -| `log.postLog?` | (`params`: `T`, `result`: [`SendSingleTransactionResult`](../modules/types_algorand_client_sender.md#sendsingletransactionresult)) => `string` | +| `log.postLog?` | (`params`: `T`, `result`: [`SendSingleTransactionResult`](../modules/types_algorand_client_transaction_sender.md#sendsingletransactionresult)) => `string` | | `log.preLog?` | (`params`: `T`, `transaction`: `Transaction`) => `string` | #### Returns `fn` -▸ (`params`): `Promise`\<[`SendSingleTransactionResult`](../modules/types_algorand_client_sender.md#sendsingletransactionresult)\> +▸ (`params`): `Promise`\<[`SendSingleTransactionResult`](../modules/types_algorand_client_transaction_sender.md#sendsingletransactionresult)\> ##### Parameters @@ -569,11 +569,11 @@ const result = await algorandClient.send.payment({ ##### Returns -`Promise`\<[`SendSingleTransactionResult`](../modules/types_algorand_client_sender.md#sendsingletransactionresult)\> +`Promise`\<[`SendSingleTransactionResult`](../modules/types_algorand_client_transaction_sender.md#sendsingletransactionresult)\> #### Defined in -[src/types/algorand-client-sender.ts:27](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/algorand-client-sender.ts#L27) +[src/types/algorand-client-transaction-sender.ts:27](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/algorand-client-transaction-sender.ts#L27) ___ @@ -641,13 +641,13 @@ await algorand.send.assetCreate({ #### Defined in -[src/types/algorand-client-sender.ts:154](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/algorand-client-sender.ts#L154) +[src/types/algorand-client-transaction-sender.ts:154](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/algorand-client-transaction-sender.ts#L154) ___ ### assetOptOut -▸ **assetOptOut**(`params`): `Promise`\<[`SendSingleTransactionResult`](../modules/types_algorand_client_sender.md#sendsingletransactionresult)\> +▸ **assetOptOut**(`params`): `Promise`\<[`SendSingleTransactionResult`](../modules/types_algorand_client_transaction_sender.md#sendsingletransactionresult)\> Opt an account out of an Algorand Standard Asset. @@ -663,7 +663,7 @@ is set to `false` (but then the account will lose the assets). #### Returns -`Promise`\<[`SendSingleTransactionResult`](../modules/types_algorand_client_sender.md#sendsingletransactionresult)\> +`Promise`\<[`SendSingleTransactionResult`](../modules/types_algorand_client_transaction_sender.md#sendsingletransactionresult)\> The result of the transaction and the transaction that was sent @@ -708,4 +708,4 @@ await algorand.send.assetOptOut({ #### Defined in -[src/types/algorand-client-sender.ts:410](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/algorand-client-sender.ts#L410) +[src/types/algorand-client-transaction-sender.ts:410](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/algorand-client-transaction-sender.ts#L410) diff --git a/docs/code/modules/types_algorand_client_sender.md b/docs/code/modules/types_algorand_client_sender.md deleted file mode 100644 index d179c2af..00000000 --- a/docs/code/modules/types_algorand_client_sender.md +++ /dev/null @@ -1,25 +0,0 @@ -[@algorandfoundation/algokit-utils](../README.md) / types/algorand-client-sender - -# Module: types/algorand-client-sender - -## Table of contents - -### Classes - -- [AlgorandClientSender](../classes/types_algorand_client_sender.AlgorandClientSender.md) - -### Type Aliases - -- [SendSingleTransactionResult](types_algorand_client_sender.md#sendsingletransactionresult) - -## Type Aliases - -### SendSingleTransactionResult - -Ƭ **SendSingleTransactionResult**: [`SendAtomicTransactionComposerResults`](../interfaces/types_transaction.SendAtomicTransactionComposerResults.md) & [`ConfirmedTransactionResult`](../interfaces/types_transaction.ConfirmedTransactionResult.md) - -Result from sending a single transaction. - -#### Defined in - -[src/types/algorand-client-sender.ts:10](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/algorand-client-sender.ts#L10) diff --git a/docs/code/modules/types_algorand_client_transaction_sender.md b/docs/code/modules/types_algorand_client_transaction_sender.md new file mode 100644 index 00000000..7afee355 --- /dev/null +++ b/docs/code/modules/types_algorand_client_transaction_sender.md @@ -0,0 +1,25 @@ +[@algorandfoundation/algokit-utils](../README.md) / types/algorand-client-transaction-sender + +# Module: types/algorand-client-transaction-sender + +## Table of contents + +### Classes + +- [AlgorandClientTransactionSender](../classes/types_algorand_client_transaction_sender.AlgorandClientTransactionSender.md) + +### Type Aliases + +- [SendSingleTransactionResult](types_algorand_client_transaction_sender.md#sendsingletransactionresult) + +## Type Aliases + +### SendSingleTransactionResult + +Ƭ **SendSingleTransactionResult**: [`SendAtomicTransactionComposerResults`](../interfaces/types_transaction.SendAtomicTransactionComposerResults.md) & [`ConfirmedTransactionResult`](../interfaces/types_transaction.ConfirmedTransactionResult.md) + +Result from sending a single transaction. + +#### Defined in + +[src/types/algorand-client-transaction-sender.ts:10](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/algorand-client-transaction-sender.ts#L10) diff --git a/src/transaction/legacy-bridge.ts b/src/transaction/legacy-bridge.ts index cb36bd54..fe707b79 100644 --- a/src/transaction/legacy-bridge.ts +++ b/src/transaction/legacy-bridge.ts @@ -1,6 +1,6 @@ import algosdk from 'algosdk' -import { AlgorandClientSender, SendSingleTransactionResult } from '../types/algorand-client-sender' import { AlgorandClientTransactionCreator } from '../types/algorand-client-transaction-creator' +import { AlgorandClientTransactionSender, SendSingleTransactionResult } from '../types/algorand-client-transaction-sender' import { AssetManager } from '../types/asset-manager' import AlgoKitComposer, { CommonTransactionParams, ExecuteParams } from '../types/composer' import { SendTransactionFrom, SendTransactionParams, SendTransactionResult } from '../types/transaction' @@ -15,7 +15,7 @@ export async function legacySendTransactionBridge (params: T) => Promise, - send: (c: AlgorandClientSender) => (params: T & ExecuteParams) => Promise, + send: (c: AlgorandClientTransactionSender) => (params: T & ExecuteParams) => Promise, suggestedParams?: algosdk.SuggestedParams, ): Promise { const newGroup = () => @@ -24,7 +24,7 @@ export async function legacySendTransactionBridge getSenderTransactionSigner(from), getSuggestedParams: async () => await getTransactionParams(suggestedParams, algod), }) - const sender = new AlgorandClientSender(newGroup, new AssetManager(algod, newGroup)) + const transactionSender = new AlgorandClientTransactionSender(newGroup, new AssetManager(algod, newGroup)) const transactionCreator = new AlgorandClientTransactionCreator(newGroup) if (sendParams.fee) { @@ -42,5 +42,5 @@ export async function legacySendTransactionBridge AlgoKitComposer private _assetManager: AssetManager diff --git a/src/types/algorand-client.ts b/src/types/algorand-client.ts index 02204e0e..2ed09795 100644 --- a/src/types/algorand-client.ts +++ b/src/types/algorand-client.ts @@ -1,8 +1,8 @@ import algosdk from 'algosdk' import { MultisigAccount, SigningAccount, TransactionSignerAccount } from './account' import { AccountManager } from './account-manager' -import { AlgorandClientSender } from './algorand-client-sender' import { AlgorandClientTransactionCreator } from './algorand-client-transaction-creator' +import { AlgorandClientTransactionSender } from './algorand-client-transaction-sender' import { AssetManager } from './asset-manager' import { AlgoSdkClients, ClientManager } from './client-manager' import AlgoKitComposer from './composer' @@ -17,7 +17,7 @@ export class AlgorandClient { private _clientManager: ClientManager private _accountManager: AccountManager private _assetManager: AssetManager - private _sender: AlgorandClientSender + private _transactionSender: AlgorandClientTransactionSender private _transactionCreator: AlgorandClientTransactionCreator private _cachedSuggestedParams?: algosdk.SuggestedParams @@ -30,7 +30,7 @@ export class AlgorandClient { this._clientManager = new ClientManager(config) this._accountManager = new AccountManager(this._clientManager) this._assetManager = new AssetManager(this._clientManager.algod, () => this.newGroup()) - this._sender = new AlgorandClientSender(() => this.newGroup(), this._assetManager) + this._transactionSender = new AlgorandClientTransactionSender(() => this.newGroup(), this._assetManager) this._transactionCreator = new AlgorandClientTransactionCreator(() => this.newGroup()) } @@ -154,7 +154,7 @@ export class AlgorandClient { * Methods for sending a single transaction. */ public get send() { - return this._sender + return this._transactionSender } /**