Skip to content

Commit

Permalink
fix: Switched to singular .algo and .microAlgo methods for `AlgoAmoun…
Browse files Browse the repository at this point in the history
…t`, retained existing methods to avoid breaking changes
  • Loading branch information
robdmoore committed Aug 28, 2024
1 parent 6ed993e commit fed61c9
Show file tree
Hide file tree
Showing 35 changed files with 530 additions and 341 deletions.
10 changes: 5 additions & 5 deletions docs/capabilities/account.md
Original file line number Diff line number Diff line change
Expand Up @@ -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,
})
Expand Down Expand Up @@ -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')
```
Expand All @@ -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())
```
2 changes: 1 addition & 1 deletion docs/capabilities/algorand-client.md
Original file line number Diff line number Diff line change
Expand Up @@ -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()
```
Expand Down
20 changes: 10 additions & 10 deletions docs/capabilities/amount.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:

Expand All @@ -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.

Expand Down
2 changes: 1 addition & 1 deletion docs/capabilities/app-client.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 },
}),
],
Expand Down
34 changes: 17 additions & 17 deletions docs/capabilities/asset.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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,
})
```
Expand All @@ -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,
})
```
Expand Down
32 changes: 16 additions & 16 deletions docs/capabilities/transfer.md
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -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
Expand Down Expand Up @@ -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,
})

Expand All @@ -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) },
)
```

Expand Down
2 changes: 1 addition & 1 deletion docs/capabilities/typed-app-clients.md
Original file line number Diff line number Diff line change
Expand Up @@ -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, {
Expand Down
24 changes: 12 additions & 12 deletions docs/code/classes/types_account_manager.AccountManager.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
)
```

Expand Down Expand Up @@ -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 }
)
```

Expand Down Expand Up @@ -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) }
)
```

Expand Down Expand Up @@ -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,
})
Expand Down
Loading

0 comments on commit fed61c9

Please sign in to comment.