@algorandfoundation/algokit-utils 10.0.0-alpha.31 → 10.0.0-alpha.32
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/account-manager.d.ts +448 -0
- package/account-manager.js +623 -0
- package/account-manager.js.map +1 -0
- package/account-manager.mjs +620 -0
- package/account-manager.mjs.map +1 -0
- package/account.d.ts +156 -0
- package/account.js +10 -0
- package/account.js.map +1 -0
- package/account.mjs +9 -0
- package/account.mjs.map +1 -0
- package/algorand-client-transaction-creator.d.ts +1103 -0
- package/algorand-client-transaction-creator.js +735 -0
- package/algorand-client-transaction-creator.js.map +1 -0
- package/algorand-client-transaction-creator.mjs +734 -0
- package/algorand-client-transaction-creator.mjs.map +1 -0
- package/algorand-client-transaction-sender.d.ts +1317 -0
- package/algorand-client-transaction-sender.js +933 -0
- package/algorand-client-transaction-sender.js.map +1 -0
- package/algorand-client-transaction-sender.mjs +932 -0
- package/algorand-client-transaction-sender.mjs.map +1 -0
- package/algorand-client.d.ts +246 -0
- package/algorand-client.js +325 -0
- package/algorand-client.js.map +1 -0
- package/algorand-client.mjs +325 -0
- package/algorand-client.mjs.map +1 -0
- package/amount.d.ts +46 -3
- package/amount.js +92 -13
- package/amount.js.map +1 -1
- package/amount.mjs +80 -3
- package/amount.mjs.map +1 -1
- package/app-client.d.ts +2130 -0
- package/app-client.js +909 -0
- package/app-client.js.map +1 -0
- package/app-client.mjs +908 -0
- package/app-client.mjs.map +1 -0
- package/app-deployer.d.ts +166 -0
- package/app-deployer.js +353 -0
- package/app-deployer.js.map +1 -0
- package/app-deployer.mjs +353 -0
- package/app-deployer.mjs.map +1 -0
- package/app-factory.d.ts +965 -0
- package/app-factory.js +448 -0
- package/app-factory.js.map +1 -0
- package/app-factory.mjs +448 -0
- package/app-factory.mjs.map +1 -0
- package/app-manager.d.ts +323 -0
- package/app-manager.js +468 -0
- package/app-manager.js.map +1 -0
- package/app-manager.mjs +468 -0
- package/app-manager.mjs.map +1 -0
- package/app-spec.d.ts +203 -0
- package/app-spec.js +137 -0
- package/app-spec.js.map +1 -0
- package/app-spec.mjs +137 -0
- package/app-spec.mjs.map +1 -0
- package/app.d.ts +257 -0
- package/app.js +49 -0
- package/app.js.map +1 -0
- package/app.mjs +42 -0
- package/app.mjs.map +1 -0
- package/asset-manager.d.ts +212 -0
- package/asset-manager.js +166 -0
- package/asset-manager.js.map +1 -0
- package/asset-manager.mjs +166 -0
- package/asset-manager.mjs.map +1 -0
- package/async-event-emitter.d.ts +16 -0
- package/async-event-emitter.js +38 -0
- package/async-event-emitter.js.map +1 -0
- package/async-event-emitter.mjs +37 -0
- package/async-event-emitter.mjs.map +1 -0
- package/client-manager.d.ts +475 -0
- package/client-manager.js +616 -0
- package/client-manager.js.map +1 -0
- package/client-manager.mjs +616 -0
- package/client-manager.mjs.map +1 -0
- package/composer.d.ts +947 -0
- package/composer.js +1584 -0
- package/composer.js.map +1 -0
- package/composer.mjs +1583 -0
- package/composer.mjs.map +1 -0
- package/config.d.ts +1 -1
- package/config.js +2 -2
- package/config.js.map +1 -1
- package/config.mjs +1 -1
- package/config.mjs.map +1 -1
- package/debugging.d.ts +47 -0
- package/debugging.js +20 -0
- package/debugging.js.map +1 -0
- package/debugging.mjs +15 -0
- package/debugging.mjs.map +1 -0
- package/dispenser-client.d.ts +90 -0
- package/dispenser-client.js +127 -0
- package/dispenser-client.js.map +1 -0
- package/dispenser-client.mjs +127 -0
- package/dispenser-client.mjs.map +1 -0
- package/expand.d.ts +2 -0
- package/expand.js +0 -0
- package/expand.mjs +0 -0
- package/index.d.ts +6 -5
- package/index.js +4 -3
- package/index.mjs +5 -5
- package/indexer-client/indexer-lookup.d.ts +1 -1
- package/indexer-client/indexer-lookup.js.map +1 -1
- package/indexer-client/indexer-lookup.mjs.map +1 -1
- package/indexer.d.ts +40 -0
- package/indexer.js +38 -0
- package/indexer.js.map +1 -0
- package/indexer.mjs +35 -0
- package/indexer.mjs.map +1 -0
- package/instance-of.d.ts +8 -0
- package/kmd-account-manager.d.ts +74 -0
- package/kmd-account-manager.js +167 -0
- package/kmd-account-manager.js.map +1 -0
- package/kmd-account-manager.mjs +165 -0
- package/kmd-account-manager.mjs.map +1 -0
- package/lifecycle-events.d.ts +14 -0
- package/lifecycle-events.js +11 -0
- package/lifecycle-events.js.map +1 -0
- package/lifecycle-events.mjs +10 -0
- package/lifecycle-events.mjs.map +1 -0
- package/logging.d.ts +13 -0
- package/logging.js +47 -0
- package/logging.js.map +1 -0
- package/logging.mjs +42 -0
- package/logging.mjs.map +1 -0
- package/logic-error.d.ts +39 -0
- package/logic-error.js +54 -0
- package/logic-error.js.map +1 -0
- package/logic-error.mjs +53 -0
- package/logic-error.mjs.map +1 -0
- package/network-client.d.ts +43 -0
- package/network-client.js +14 -0
- package/network-client.js.map +1 -0
- package/network-client.mjs +13 -0
- package/network-client.mjs.map +1 -0
- package/package.json +11 -1
- package/testing/account.d.ts +2 -2
- package/testing/account.js +1 -1
- package/testing/account.js.map +1 -1
- package/testing/account.mjs +1 -1
- package/testing/account.mjs.map +1 -1
- package/testing/fixtures/algokit-log-capture-fixture.d.ts +1 -1
- package/testing/fixtures/algokit-log-capture-fixture.js.map +1 -1
- package/testing/fixtures/algokit-log-capture-fixture.mjs.map +1 -1
- package/testing/fixtures/algorand-fixture.d.ts +2 -2
- package/testing/fixtures/algorand-fixture.js +2 -2
- package/testing/fixtures/algorand-fixture.js.map +1 -1
- package/testing/fixtures/algorand-fixture.mjs +2 -2
- package/testing/fixtures/algorand-fixture.mjs.map +1 -1
- package/testing/index.d.ts +2 -1
- package/testing/test-logger.d.ts +1 -1
- package/testing/test-logger.js.map +1 -1
- package/testing/test-logger.mjs.map +1 -1
- package/testing/types.d.ts +156 -0
- package/transaction/index.d.ts +4 -0
- package/transaction/index.js +9 -0
- package/transaction/index.mjs +4 -0
- package/transaction/perform-transaction-composer-simulate.d.ts +1 -1
- package/transaction/perform-transaction-composer-simulate.js.map +1 -1
- package/transaction/perform-transaction-composer-simulate.mjs.map +1 -1
- package/transaction/transaction.d.ts +2 -2
- package/transaction/transaction.js.map +1 -1
- package/transaction/transaction.mjs.map +1 -1
- package/transaction/types.d.ts +133 -0
- package/transactions/app-call.d.ts +1 -1
- package/transactions/app-call.js +1 -1
- package/transactions/app-call.js.map +1 -1
- package/transactions/app-call.mjs +1 -1
- package/transactions/app-call.mjs.map +1 -1
- package/transactions/common.d.ts +1 -1
- package/transactions/common.js.map +1 -1
- package/transactions/common.mjs.map +1 -1
- package/transactions/method-call.d.ts +1 -1
- package/transactions/method-call.js +1 -1
- package/transactions/method-call.js.map +1 -1
- package/transactions/method-call.mjs +1 -1
- package/transactions/method-call.mjs.map +1 -1
- package/transactions/payment.d.ts +1 -1
- package/transactions/payment.js.map +1 -1
- package/transactions/payment.mjs.map +1 -1
- package/types/account-manager.d.ts +11 -442
- package/types/account-manager.js +5 -616
- package/types/account-manager.js.map +1 -1
- package/types/account-manager.mjs +5 -614
- package/types/account-manager.mjs.map +1 -1
- package/types/account.d.ts +8 -150
- package/types/account.js +3 -4
- package/types/account.js.map +1 -1
- package/types/account.mjs +4 -4
- package/types/account.mjs.map +1 -1
- package/types/algorand-client-transaction-creator.d.ts +5 -1098
- package/types/algorand-client-transaction-creator.js +3 -729
- package/types/algorand-client-transaction-creator.js.map +1 -1
- package/types/algorand-client-transaction-creator.mjs +4 -729
- package/types/algorand-client-transaction-creator.mjs.map +1 -1
- package/types/algorand-client-transaction-sender.d.ts +5 -1312
- package/types/algorand-client-transaction-sender.js +3 -927
- package/types/algorand-client-transaction-sender.js.map +1 -1
- package/types/algorand-client-transaction-sender.mjs +3 -926
- package/types/algorand-client-transaction-sender.mjs.map +1 -1
- package/types/algorand-client.d.ts +5 -241
- package/types/algorand-client.js +3 -319
- package/types/algorand-client.js.map +1 -1
- package/types/algorand-client.mjs +3 -319
- package/types/algorand-client.mjs.map +1 -1
- package/types/amount.d.ts +6 -45
- package/types/amount.js +3 -79
- package/types/amount.js.map +1 -1
- package/types/amount.mjs +4 -79
- package/types/amount.mjs.map +1 -1
- package/types/app-client.d.ts +75 -2125
- package/types/app-client.js +3 -903
- package/types/app-client.js.map +1 -1
- package/types/app-client.mjs +3 -902
- package/types/app-client.mjs.map +1 -1
- package/types/app-deployer.d.ts +21 -161
- package/types/app-deployer.js +3 -347
- package/types/app-deployer.js.map +1 -1
- package/types/app-deployer.mjs +3 -347
- package/types/app-deployer.mjs.map +1 -1
- package/types/app-factory.d.ts +21 -960
- package/types/app-factory.js +3 -442
- package/types/app-factory.js.map +1 -1
- package/types/app-factory.mjs +3 -442
- package/types/app-factory.mjs.map +1 -1
- package/types/app-manager.d.ts +15 -318
- package/types/app-manager.js +3 -462
- package/types/app-manager.js.map +1 -1
- package/types/app-manager.mjs +3 -462
- package/types/app-manager.mjs.map +1 -1
- package/types/app-spec.d.ts +39 -198
- package/types/app-spec.js +3 -131
- package/types/app-spec.js.map +1 -1
- package/types/app-spec.mjs +3 -131
- package/types/app-spec.mjs.map +1 -1
- package/types/app.d.ts +62 -247
- package/types/app.js +15 -37
- package/types/app.js.map +1 -1
- package/types/app.mjs +16 -37
- package/types/app.mjs.map +1 -1
- package/types/asset-manager.d.ts +9 -207
- package/types/asset-manager.js +3 -160
- package/types/asset-manager.js.map +1 -1
- package/types/asset-manager.mjs +3 -160
- package/types/asset-manager.mjs.map +1 -1
- package/types/async-event-emitter.d.ts +7 -11
- package/types/async-event-emitter.js +3 -32
- package/types/async-event-emitter.js.map +1 -1
- package/types/async-event-emitter.mjs +4 -32
- package/types/async-event-emitter.mjs.map +1 -1
- package/types/client-manager.d.ts +27 -470
- package/types/client-manager.js +3 -610
- package/types/client-manager.js.map +1 -1
- package/types/client-manager.mjs +3 -610
- package/types/client-manager.mjs.map +1 -1
- package/types/composer.d.ts +79 -943
- package/types/composer.js +3 -1578
- package/types/composer.js.map +1 -1
- package/types/composer.mjs +3 -1577
- package/types/composer.mjs.map +1 -1
- package/types/config.d.ts +7 -52
- package/types/config.js +3 -74
- package/types/config.js.map +1 -1
- package/types/config.mjs +3 -74
- package/types/config.mjs.map +1 -1
- package/types/debugging.d.ts +12 -37
- package/types/debugging.js +11 -10
- package/types/debugging.js.map +1 -1
- package/types/debugging.mjs +12 -10
- package/types/debugging.mjs.map +1 -1
- package/types/dispenser-client.d.ts +11 -85
- package/types/dispenser-client.js +3 -121
- package/types/dispenser-client.js.map +1 -1
- package/types/dispenser-client.mjs +3 -121
- package/types/dispenser-client.mjs.map +1 -1
- package/types/expand.d.ts +8 -2
- package/types/indexer.d.ts +16 -36
- package/types/indexer.js +7 -30
- package/types/indexer.js.map +1 -1
- package/types/indexer.mjs +8 -30
- package/types/indexer.mjs.map +1 -1
- package/types/instance-of.d.ts +4 -4
- package/types/kmd-account-manager.d.ts +5 -69
- package/types/kmd-account-manager.js +3 -161
- package/types/kmd-account-manager.js.map +1 -1
- package/types/kmd-account-manager.mjs +3 -159
- package/types/kmd-account-manager.mjs.map +1 -1
- package/types/lifecycle-events.d.ts +7 -9
- package/types/lifecycle-events.js +3 -5
- package/types/lifecycle-events.js.map +1 -1
- package/types/lifecycle-events.mjs +4 -5
- package/types/lifecycle-events.mjs.map +1 -1
- package/types/logging.d.ts +14 -9
- package/types/logging.js +11 -37
- package/types/logging.js.map +1 -1
- package/types/logging.mjs +12 -37
- package/types/logging.mjs.map +1 -1
- package/types/logic-error.d.ts +8 -35
- package/types/logic-error.js +3 -48
- package/types/logic-error.js.map +1 -1
- package/types/logic-error.mjs +4 -48
- package/types/logic-error.mjs.map +1 -1
- package/types/network-client.d.ts +10 -39
- package/types/network-client.js +3 -8
- package/types/network-client.js.map +1 -1
- package/types/network-client.mjs +4 -8
- package/types/network-client.mjs.map +1 -1
- package/types/testing.d.ts +13 -151
- package/types/transaction.d.ts +33 -128
- package/updatable-config.d.ts +57 -0
- package/updatable-config.js +80 -0
- package/updatable-config.js.map +1 -0
- package/updatable-config.mjs +80 -0
- package/updatable-config.mjs.map +1 -0
- package/util.js +1 -1
- package/util.js.map +1 -1
- package/util.mjs +1 -1
- package/util.mjs.map +1 -1
package/types/account-manager.js
CHANGED
|
@@ -1,621 +1,10 @@
|
|
|
1
|
-
const
|
|
2
|
-
const require_address = require('../packages/common/src/address.js');
|
|
3
|
-
const require_amount = require('./amount.js');
|
|
4
|
-
const require_config = require('../config.js');
|
|
5
|
-
const require_util = require('../util.js');
|
|
6
|
-
const require_index = require('../packages/algo25/src/index.js');
|
|
7
|
-
const require_signer = require('../packages/transact/src/signer.js');
|
|
8
|
-
const require_multisig = require('../packages/transact/src/multisig.js');
|
|
9
|
-
const require_logicsig = require('../packages/transact/src/logicsig.js');
|
|
10
|
-
const require_account = require('./account.js');
|
|
11
|
-
const require_composer = require('./composer.js');
|
|
12
|
-
const require_kmd_account_manager = require('./kmd-account-manager.js');
|
|
13
|
-
let tweetnacl = require("tweetnacl");
|
|
14
|
-
tweetnacl = require_rolldown_runtime.__toESM(tweetnacl);
|
|
1
|
+
const require_account_manager = require('../account-manager.js');
|
|
15
2
|
|
|
16
3
|
//#region src/types/account-manager.ts
|
|
17
|
-
/**
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
* @returns A transaction signer
|
|
22
|
-
* @example
|
|
23
|
-
* ```typescript
|
|
24
|
-
* const signer = getAccountTransactionSigner(account)
|
|
25
|
-
* ```
|
|
26
|
-
*/
|
|
27
|
-
const getAccountTransactionSigner = require_util.memoize(function(account) {
|
|
28
|
-
return account.signer;
|
|
29
|
-
});
|
|
30
|
-
/** Creates and keeps track of signing accounts that can sign transactions for a sending address. */
|
|
31
|
-
var AccountManager = class {
|
|
32
|
-
_clientManager;
|
|
33
|
-
_kmdAccountManager;
|
|
34
|
-
_accounts = {};
|
|
35
|
-
_defaultSigner;
|
|
36
|
-
/**
|
|
37
|
-
* Create a new account manager.
|
|
38
|
-
* @param clientManager The ClientManager client to use for algod and kmd clients
|
|
39
|
-
* @example Create a new account manager
|
|
40
|
-
* ```typescript
|
|
41
|
-
* const accountManager = new AccountManager(clientManager)
|
|
42
|
-
* ```
|
|
43
|
-
*/
|
|
44
|
-
constructor(clientManager) {
|
|
45
|
-
this._clientManager = clientManager;
|
|
46
|
-
this._kmdAccountManager = new require_kmd_account_manager.KmdAccountManager(clientManager);
|
|
47
|
-
}
|
|
48
|
-
_getComposer(getSuggestedParams) {
|
|
49
|
-
return new require_composer.TransactionComposer({
|
|
50
|
-
algod: this._clientManager.algod,
|
|
51
|
-
getSigner: this.getSigner.bind(this),
|
|
52
|
-
getSuggestedParams: getSuggestedParams ?? (() => this._clientManager.algod.suggestedParams())
|
|
53
|
-
});
|
|
54
|
-
}
|
|
55
|
-
/**
|
|
56
|
-
* KMD account manager that allows you to easily get and create accounts using KMD.
|
|
57
|
-
* @returns The `KmdAccountManager` instance.
|
|
58
|
-
* @example
|
|
59
|
-
* ```typescript
|
|
60
|
-
* const kmdManager = accountManager.kmd;
|
|
61
|
-
* ```
|
|
62
|
-
*/
|
|
63
|
-
get kmd() {
|
|
64
|
-
return this._kmdAccountManager;
|
|
65
|
-
}
|
|
66
|
-
/**
|
|
67
|
-
* Sets the default signer to use if no other signer is specified.
|
|
68
|
-
*
|
|
69
|
-
* If this isn't set an a transaction needs signing for a given sender
|
|
70
|
-
* then an error will be thrown from `getSigner` / `getAccount`.
|
|
71
|
-
* @param signer The signer to use, either a `TransactionSigner` or a `AddressWithSigner`
|
|
72
|
-
* @example
|
|
73
|
-
* ```typescript
|
|
74
|
-
* const signer = accountManager.random() // Can be anything that returns a `TransactionSigner` or `AddressWithSigner`
|
|
75
|
-
* accountManager.setDefaultSigner(signer)
|
|
76
|
-
*
|
|
77
|
-
* // When signing a transaction, if there is no signer registered for the sender then the default signer will be used
|
|
78
|
-
* const signer = accountManager.getSigner("SENDERADDRESS")
|
|
79
|
-
* ```
|
|
80
|
-
* @returns The `AccountManager` so method calls can be chained
|
|
81
|
-
*/
|
|
82
|
-
setDefaultSigner(signer) {
|
|
83
|
-
this._defaultSigner = "signer" in signer ? signer.signer : signer;
|
|
84
|
-
return this;
|
|
85
|
-
}
|
|
86
|
-
/**
|
|
87
|
-
* Records the given account (that can sign) against the address of the provided account for later
|
|
88
|
-
* retrieval and returns a `AddressWithTransactionSigner` along with the original account in an `account` property.
|
|
89
|
-
*/
|
|
90
|
-
signerAccount(account) {
|
|
91
|
-
const signer = getAccountTransactionSigner(account);
|
|
92
|
-
const acc = {
|
|
93
|
-
addr: account.addr,
|
|
94
|
-
signer
|
|
95
|
-
};
|
|
96
|
-
this._accounts[acc.addr.toString()] = acc;
|
|
97
|
-
const addressWithAccount = require_address.Address.fromString(acc.addr.toString());
|
|
98
|
-
addressWithAccount.account = account;
|
|
99
|
-
addressWithAccount.addr = acc.addr;
|
|
100
|
-
addressWithAccount.signer = signer;
|
|
101
|
-
return addressWithAccount;
|
|
102
|
-
}
|
|
103
|
-
/**
|
|
104
|
-
* Tracks the given account for later signing.
|
|
105
|
-
*
|
|
106
|
-
* Note: If you are generating accounts via the various methods on `AccountManager`
|
|
107
|
-
* (like `random`, `fromMnemonic`, `logicsig`, etc.) then they automatically get tracked.
|
|
108
|
-
* @param account The account to register, which can be a `AddressWithSigner` or
|
|
109
|
-
* a `algosdk.Account`, `algosdk.LogicSigAccount`, `SigningAccount` or `MultisigAccount`
|
|
110
|
-
* @example
|
|
111
|
-
* ```typescript
|
|
112
|
-
* const accountManager = new AccountManager(clientManager)
|
|
113
|
-
* .setSignerFromAccount(algosdk.generateAccount())
|
|
114
|
-
* .setSignerFromAccount(new algosdk.LogicSigAccount(program, args))
|
|
115
|
-
* .setSignerFromAccount(new SigningAccount(mnemonic, sender))
|
|
116
|
-
* .setSignerFromAccount(new MultisigAccount({version: 1, threshold: 1, addrs: ["ADDRESS1...", "ADDRESS2..."]}, [account1, account2]))
|
|
117
|
-
* .setSignerFromAccount({addr: "SENDERADDRESS", signer: transactionSigner})
|
|
118
|
-
* ```
|
|
119
|
-
* @returns The `AccountManager` instance for method chaining
|
|
120
|
-
*/
|
|
121
|
-
setSignerFromAccount(account) {
|
|
122
|
-
this.signerAccount(account);
|
|
123
|
-
return this;
|
|
124
|
-
}
|
|
125
|
-
/**
|
|
126
|
-
* Tracks the given `TransactionSigner` against the given sender address for later signing.
|
|
127
|
-
* @param sender The sender address to use this signer for
|
|
128
|
-
* @param signer The `TransactionSigner` to sign transactions with for the given sender
|
|
129
|
-
* @example
|
|
130
|
-
* ```typescript
|
|
131
|
-
* const accountManager = new AccountManager(clientManager)
|
|
132
|
-
* .setSigner("SENDERADDRESS", transactionSigner)
|
|
133
|
-
* ```
|
|
134
|
-
* @returns The `AccountManager` instance for method chaining
|
|
135
|
-
*/
|
|
136
|
-
setSigner(sender, signer) {
|
|
137
|
-
this._accounts[require_address.getAddress(sender).toString()] = {
|
|
138
|
-
addr: require_address.getAddress(sender),
|
|
139
|
-
signer
|
|
140
|
-
};
|
|
141
|
-
return this;
|
|
142
|
-
}
|
|
143
|
-
/**
|
|
144
|
-
* Takes all registered signers from the given `AccountManager` and adds them to this `AccountManager`.
|
|
145
|
-
*
|
|
146
|
-
* This is useful for situations where you have multiple contexts you are building accounts in such as unit tests.
|
|
147
|
-
* @param anotherAccountManager Another account manager with signers registered
|
|
148
|
-
* @param overwriteExisting Whether or not to overwrite any signers that have the same sender address with the ones in the other account manager or not (default: true)
|
|
149
|
-
* @returns The `AccountManager` instance for method chaining
|
|
150
|
-
* @example
|
|
151
|
-
* ```typescript
|
|
152
|
-
* accountManager2.setSigners(accountManager1);
|
|
153
|
-
* ```
|
|
154
|
-
*/
|
|
155
|
-
setSigners(anotherAccountManager, overwriteExisting = true) {
|
|
156
|
-
this._accounts = overwriteExisting ? {
|
|
157
|
-
...this._accounts,
|
|
158
|
-
...anotherAccountManager._accounts
|
|
159
|
-
} : {
|
|
160
|
-
...anotherAccountManager._accounts,
|
|
161
|
-
...this._accounts
|
|
162
|
-
};
|
|
163
|
-
return this;
|
|
164
|
-
}
|
|
165
|
-
/**
|
|
166
|
-
* Returns the `TransactionSigner` for the given sender address, ready to sign a transaction for that sender.
|
|
167
|
-
*
|
|
168
|
-
* If no signer has been registered for that address then the default signer is used if registered and
|
|
169
|
-
* if not then an error is thrown.
|
|
170
|
-
*
|
|
171
|
-
* @param sender The sender address
|
|
172
|
-
* @example
|
|
173
|
-
* ```typescript
|
|
174
|
-
* const signer = accountManager.getSigner("SENDERADDRESS")
|
|
175
|
-
* ```
|
|
176
|
-
* @returns The `TransactionSigner` or throws an error if not found and no default signer is set
|
|
177
|
-
*/
|
|
178
|
-
getSigner(sender) {
|
|
179
|
-
const signer = this._accounts[require_address.getAddress(sender).toString()]?.signer ?? this._defaultSigner;
|
|
180
|
-
if (!signer) throw new Error(`No signer found for address ${sender}`);
|
|
181
|
-
return signer;
|
|
182
|
-
}
|
|
183
|
-
/**
|
|
184
|
-
* Returns the `AddressWithSigner` for the given sender address.
|
|
185
|
-
*
|
|
186
|
-
* If no signer has been registered for that address then an error is thrown.
|
|
187
|
-
* @param sender The sender address
|
|
188
|
-
* @example
|
|
189
|
-
* ```typescript
|
|
190
|
-
* const sender = accountManager.random()
|
|
191
|
-
* // ...
|
|
192
|
-
* // Returns the `AddressWithSigner` for `sender` that has previously been registered
|
|
193
|
-
* const account = accountManager.getAccount(sender)
|
|
194
|
-
* ```
|
|
195
|
-
* @returns The `AddressWithSigner` or throws an error if not found
|
|
196
|
-
*/
|
|
197
|
-
getAccount(sender) {
|
|
198
|
-
const account = this._accounts[require_address.getAddress(sender).toString()];
|
|
199
|
-
if (!account) throw new Error(`No signer found for address ${sender}`);
|
|
200
|
-
return account;
|
|
201
|
-
}
|
|
202
|
-
/**
|
|
203
|
-
* Returns the given sender account's current status, balance and spendable amounts.
|
|
204
|
-
*
|
|
205
|
-
* [Response data schema details](https://dev.algorand.co/reference/rest-apis/algod/#accountinformation)
|
|
206
|
-
* @example
|
|
207
|
-
* ```typescript
|
|
208
|
-
* const address = "XBYLS2E6YI6XXL5BWCAMOA4GTWHXWENZMX5UHXMRNWWUQ7BXCY5WC5TEPA";
|
|
209
|
-
* const accountInfo = await accountManager.getInformation(address);
|
|
210
|
-
* ```
|
|
211
|
-
*
|
|
212
|
-
* @param sender The account / address to look up
|
|
213
|
-
* @returns The account information
|
|
214
|
-
*/
|
|
215
|
-
async getInformation(sender) {
|
|
216
|
-
const senderAddress = require_address.getAddress(sender).toString();
|
|
217
|
-
const { round, lastHeartbeat = void 0, lastProposed = void 0, address, ...account } = await this._clientManager.algod.accountInformation(senderAddress);
|
|
218
|
-
return {
|
|
219
|
-
...account,
|
|
220
|
-
authAddr: account.authAddr,
|
|
221
|
-
address,
|
|
222
|
-
balance: require_amount.AlgoAmount.MicroAlgo(Number(account.amount)),
|
|
223
|
-
amountWithoutPendingRewards: require_amount.AlgoAmount.MicroAlgo(Number(account.amountWithoutPendingRewards)),
|
|
224
|
-
minBalance: require_amount.AlgoAmount.MicroAlgo(Number(account.minBalance)),
|
|
225
|
-
pendingRewards: require_amount.AlgoAmount.MicroAlgo(Number(account.pendingRewards)),
|
|
226
|
-
rewards: require_amount.AlgoAmount.MicroAlgo(Number(account.rewards)),
|
|
227
|
-
validAsOfRound: BigInt(round),
|
|
228
|
-
totalAppsOptedIn: Number(account.totalAppsOptedIn),
|
|
229
|
-
totalAssetsOptedIn: Number(account.totalAssetsOptedIn),
|
|
230
|
-
totalCreatedApps: Number(account.totalCreatedApps),
|
|
231
|
-
totalCreatedAssets: Number(account.totalCreatedAssets),
|
|
232
|
-
appsTotalExtraPages: account.appsTotalExtraPages !== void 0 ? Number(account.appsTotalExtraPages) : void 0,
|
|
233
|
-
rewardBase: account.rewardBase !== void 0 ? Number(account.rewardBase) : void 0,
|
|
234
|
-
totalBoxBytes: account.totalBoxBytes !== void 0 ? Number(account.totalBoxBytes) : void 0,
|
|
235
|
-
totalBoxes: account.totalBoxes !== void 0 ? Number(account.totalBoxes) : void 0,
|
|
236
|
-
lastHeartbeatRound: lastHeartbeat !== void 0 ? BigInt(lastHeartbeat) : void 0,
|
|
237
|
-
lastProposedRound: lastProposed !== void 0 ? BigInt(lastProposed) : void 0
|
|
238
|
-
};
|
|
239
|
-
}
|
|
240
|
-
/**
|
|
241
|
-
* Tracks and returns an Algorand account with secret key loaded (i.e. that can sign transactions) by taking the mnemonic secret.
|
|
242
|
-
*
|
|
243
|
-
* @example
|
|
244
|
-
* ```typescript
|
|
245
|
-
* const account = accountManager.fromMnemonic("mnemonic secret ...")
|
|
246
|
-
* const rekeyedAccount = accountManager.fromMnemonic("mnemonic secret ...", "SENDERADDRESS...")
|
|
247
|
-
* ```
|
|
248
|
-
* @param mnemonicSecret The mnemonic secret representing the private key of an account; **Note: Be careful how the mnemonic is handled**,
|
|
249
|
-
* never commit it into source control and ideally load it from the environment (ideally via a secret storage service) rather than the file system.
|
|
250
|
-
* @param sender The optional sender address to use this signer for (aka a rekeyed account)
|
|
251
|
-
* @returns The account
|
|
252
|
-
*/
|
|
253
|
-
fromMnemonic(mnemonicSecret, sender) {
|
|
254
|
-
const seed = require_index.seedFromMnemonic(mnemonicSecret);
|
|
255
|
-
const keypair = tweetnacl.default.sign.keyPair.fromSeed(seed);
|
|
256
|
-
const addrWithSigners = require_signer.generateAddressWithSigners({
|
|
257
|
-
ed25519Pubkey: keypair.publicKey,
|
|
258
|
-
sendingAddress: require_address.getOptionalAddress(sender),
|
|
259
|
-
rawEd25519Signer: async (bytesToSign) => {
|
|
260
|
-
return tweetnacl.default.sign.detached(bytesToSign, keypair.secretKey);
|
|
261
|
-
}
|
|
262
|
-
});
|
|
263
|
-
return this.signerAccount(addrWithSigners);
|
|
264
|
-
}
|
|
265
|
-
/**
|
|
266
|
-
* Tracks and returns an Algorand account that is a rekeyed version of the given account to a new sender.
|
|
267
|
-
*
|
|
268
|
-
* @example
|
|
269
|
-
* ```typescript
|
|
270
|
-
* const account = accountManager.fromMnemonic("mnemonic secret ...")
|
|
271
|
-
* const rekeyedAccount = accountManager.rekeyed(account, "SENDERADDRESS...")
|
|
272
|
-
* ```
|
|
273
|
-
* @param account The account to use as the signer for this new rekeyed account
|
|
274
|
-
* @param sender The sender address to use as the new sender
|
|
275
|
-
* @returns The account
|
|
276
|
-
*/
|
|
277
|
-
rekeyed(sender, account) {
|
|
278
|
-
return this.signerAccount({
|
|
279
|
-
addr: require_address.getAddress(sender),
|
|
280
|
-
signer: account.signer
|
|
281
|
-
});
|
|
282
|
-
}
|
|
283
|
-
/**
|
|
284
|
-
* Tracks and returns an Algorand account with private key loaded by convention from environment variables based on the given name identifier.
|
|
285
|
-
*
|
|
286
|
-
* Note: This function expects to run in a Node.js environment.
|
|
287
|
-
*
|
|
288
|
-
* ## Convention:
|
|
289
|
-
* * **Non-LocalNet:** will load process.env['\{NAME\}_MNEMONIC'] as a mnemonic secret; **Note: Be careful how the mnemonic is handled**,
|
|
290
|
-
* never commit it into source control and ideally load it via a secret storage service rather than the file system.
|
|
291
|
-
* If process.env['\{NAME\}_SENDER'] is defined then it will use that for the sender address (i.e. to support rekeyed accounts)
|
|
292
|
-
* * **LocalNet:** will load the account from a KMD wallet called \{NAME\} and if that wallet doesn't exist it will create it and fund the account for you
|
|
293
|
-
*
|
|
294
|
-
* This allows you to write code that will work seamlessly in production and local development (LocalNet) without manual config locally (including when you reset the LocalNet).
|
|
295
|
-
*
|
|
296
|
-
* @example Default
|
|
297
|
-
*
|
|
298
|
-
* If you have a mnemonic secret loaded into `process.env.MY_ACCOUNT_MNEMONIC` then you can call the following to get that private key loaded into an account object:
|
|
299
|
-
* ```typescript
|
|
300
|
-
* const account = await accountManager.fromEnvironment('MY_ACCOUNT')
|
|
301
|
-
* ```
|
|
302
|
-
*
|
|
303
|
-
* 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.
|
|
304
|
-
* 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.
|
|
305
|
-
*
|
|
306
|
-
* @param name The name identifier of the account
|
|
307
|
-
* @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
|
|
308
|
-
* @returns The account
|
|
309
|
-
*/
|
|
310
|
-
async fromEnvironment(name, fundWith) {
|
|
311
|
-
if (!process || !process.env) throw new Error("Attempt to get account with private key from a non Node.js context; this is not supported!");
|
|
312
|
-
const accountMnemonic = process.env[`${name.toUpperCase()}_MNEMONIC`];
|
|
313
|
-
const sender = process.env[`${name.toUpperCase()}_SENDER`];
|
|
314
|
-
if (accountMnemonic) return this.fromMnemonic(accountMnemonic, sender);
|
|
315
|
-
if (await this._clientManager.isLocalNet()) {
|
|
316
|
-
const account = await this._kmdAccountManager.getOrCreateWalletAccount(name, fundWith);
|
|
317
|
-
return this.signerAccount(account);
|
|
318
|
-
}
|
|
319
|
-
throw new Error(`Missing environment variable ${name.toUpperCase()}_MNEMONIC when looking for account ${name}`);
|
|
320
|
-
}
|
|
321
|
-
/**
|
|
322
|
-
* Tracks and returns an Algorand account with private key loaded from the given KMD wallet (identified by name).
|
|
323
|
-
*
|
|
324
|
-
* @param name The name of the wallet to retrieve an account from
|
|
325
|
-
* @param predicate An optional filter to use to find the account (otherwise it will return a random account from the wallet)
|
|
326
|
-
* @param sender The optional sender address to use this signer for (aka a rekeyed account)
|
|
327
|
-
* @example Get default funded account in a LocalNet
|
|
328
|
-
*
|
|
329
|
-
* ```typescript
|
|
330
|
-
* const defaultDispenserAccount = await accountManager.fromKmd('unencrypted-default-wallet',
|
|
331
|
-
* a => a.status !== 'Offline' && a.amount > 1_000_000_000
|
|
332
|
-
* )
|
|
333
|
-
* ```
|
|
334
|
-
* @returns The account
|
|
335
|
-
*/
|
|
336
|
-
async fromKmd(name, predicate, sender) {
|
|
337
|
-
const account = await this._kmdAccountManager.getWalletAccount(name, predicate, sender);
|
|
338
|
-
if (!account) throw new Error(`Unable to find KMD account ${name}${predicate ? " with predicate" : ""}`);
|
|
339
|
-
return this.signerAccount(account);
|
|
340
|
-
}
|
|
341
|
-
/**
|
|
342
|
-
* Tracks and returns an account that supports partial or full multisig signing.
|
|
343
|
-
*
|
|
344
|
-
* @example
|
|
345
|
-
* ```typescript
|
|
346
|
-
* const account = accountManager.multisig({version: 1, threshold: 1, addrs: ["ADDRESS1...", "ADDRESS2..."]},
|
|
347
|
-
* [(await accountManager.fromEnvironment('ACCOUNT1')).account])
|
|
348
|
-
* ```
|
|
349
|
-
* @param multisigParams The parameters that define the multisig account
|
|
350
|
-
* @param subSigners The signers that are currently present
|
|
351
|
-
* @returns A multisig account wrapper
|
|
352
|
-
*/
|
|
353
|
-
multisig(multisigParams, subSigners) {
|
|
354
|
-
return this.signerAccount(new require_multisig.MultisigAccount(multisigParams, subSigners));
|
|
355
|
-
}
|
|
356
|
-
/**
|
|
357
|
-
* Tracks and returns an account that represents a logic signature.
|
|
358
|
-
*
|
|
359
|
-
* @example
|
|
360
|
-
* ```typescript
|
|
361
|
-
* const account = accountManager.logicsig(program, [new Uint8Array(3, ...)])
|
|
362
|
-
* ```
|
|
363
|
-
* @param program The bytes that make up the compiled logic signature
|
|
364
|
-
* @param args The (binary) arguments to pass into the logic signature
|
|
365
|
-
* @returns A logic signature account wrapper
|
|
366
|
-
*/
|
|
367
|
-
logicsig(program, args) {
|
|
368
|
-
return this.signerAccount(new require_logicsig.LogicSigAccount(program, args));
|
|
369
|
-
}
|
|
370
|
-
/**
|
|
371
|
-
* Tracks and returns a new, random Algorand account with secret key loaded.
|
|
372
|
-
*
|
|
373
|
-
* @example
|
|
374
|
-
* ```typescript
|
|
375
|
-
* const account = accountManager.random()
|
|
376
|
-
* ```
|
|
377
|
-
* @returns The account
|
|
378
|
-
*/
|
|
379
|
-
random() {
|
|
380
|
-
const keypair = tweetnacl.default.sign.keyPair();
|
|
381
|
-
const rawSigner = async (bytesToSign) => {
|
|
382
|
-
return tweetnacl.default.sign.detached(bytesToSign, keypair.secretKey);
|
|
383
|
-
};
|
|
384
|
-
const addrWithSigners = require_signer.generateAddressWithSigners({
|
|
385
|
-
ed25519Pubkey: keypair.publicKey,
|
|
386
|
-
rawEd25519Signer: rawSigner
|
|
387
|
-
});
|
|
388
|
-
this._accounts[addrWithSigners.addr.toString()] = addrWithSigners;
|
|
389
|
-
const acct = addrWithSigners.addr;
|
|
390
|
-
for (const prop in addrWithSigners) {
|
|
391
|
-
if (prop === "addr") {
|
|
392
|
-
acct.addr = new require_address.Address(addrWithSigners.addr.publicKey);
|
|
393
|
-
continue;
|
|
394
|
-
}
|
|
395
|
-
acct[prop] = addrWithSigners[prop];
|
|
396
|
-
}
|
|
397
|
-
return acct;
|
|
398
|
-
}
|
|
399
|
-
/**
|
|
400
|
-
* Returns an account (with private key loaded) that can act as a dispenser from
|
|
401
|
-
* environment variables, or against default LocalNet if no environment variables present.
|
|
402
|
-
*
|
|
403
|
-
* Note: requires a Node.js environment to execute.
|
|
404
|
-
*
|
|
405
|
-
* If present, it will load the account mnemonic stored in process.env.DISPENSER_MNEMONIC and optionally
|
|
406
|
-
* process.env.DISPENSER_SENDER if it's a rekeyed account.
|
|
407
|
-
*
|
|
408
|
-
* @example
|
|
409
|
-
* ```typescript
|
|
410
|
-
* const account = await accountManager.dispenserFromEnvironment()
|
|
411
|
-
* ```
|
|
412
|
-
*
|
|
413
|
-
* @returns The account
|
|
414
|
-
*/
|
|
415
|
-
async dispenserFromEnvironment() {
|
|
416
|
-
if (!process || !process.env) throw new Error("Attempt to get dispenser from environment from a non Node.js context; this is not supported!");
|
|
417
|
-
return process.env[`${require_account.DISPENSER_ACCOUNT.toUpperCase()}_MNEMONIC`] ? await this.fromEnvironment(require_account.DISPENSER_ACCOUNT) : await this.localNetDispenser();
|
|
418
|
-
}
|
|
419
|
-
/**
|
|
420
|
-
* Returns an Algorand account with private key loaded for the default LocalNet dispenser account (that can be used to fund other accounts).
|
|
421
|
-
*
|
|
422
|
-
* @example
|
|
423
|
-
* ```typescript
|
|
424
|
-
* const account = await accountManager.localNetDispenser()
|
|
425
|
-
* ```
|
|
426
|
-
* @returns The account
|
|
427
|
-
*/
|
|
428
|
-
async localNetDispenser() {
|
|
429
|
-
const dispenser = await this._kmdAccountManager.getLocalNetDispenserAccount();
|
|
430
|
-
return this.signerAccount(dispenser);
|
|
431
|
-
}
|
|
432
|
-
/**
|
|
433
|
-
* Rekey an account to a new address.
|
|
434
|
-
*
|
|
435
|
-
* **Note:** Please be careful with this function and be sure to read the [official rekey guidance](https://dev.algorand.co/concepts/accounts/rekeying).
|
|
436
|
-
*
|
|
437
|
-
* @param account The account to rekey
|
|
438
|
-
* @param rekeyTo The account address or signing account of the account that will be used to authorise transactions for the rekeyed account going forward.
|
|
439
|
-
* If a signing account is provided that will now be tracked as the signer for `account` in this `AccountManager`
|
|
440
|
-
* @param options Any parameters to control the transaction or execution of the transaction
|
|
441
|
-
*
|
|
442
|
-
* @example Basic example (with string addresses)
|
|
443
|
-
* ```typescript
|
|
444
|
-
* await accountManager.rekeyAccount({account: "ACCOUNTADDRESS", rekeyTo: "NEWADDRESS"})
|
|
445
|
-
* ```
|
|
446
|
-
* @example Basic example (with signer accounts)
|
|
447
|
-
* ```typescript
|
|
448
|
-
* await accountManager.rekeyAccount({account: account1, rekeyTo: newSignerAccount})
|
|
449
|
-
* ```
|
|
450
|
-
* @example Advanced example
|
|
451
|
-
* ```typescript
|
|
452
|
-
* await accountManager.rekeyAccount({
|
|
453
|
-
* account: "ACCOUNTADDRESS",
|
|
454
|
-
* rekeyTo: "NEWADDRESS",
|
|
455
|
-
* lease: 'lease',
|
|
456
|
-
* note: 'note',
|
|
457
|
-
* firstValidRound: 1000n,
|
|
458
|
-
* validityWindow: 10,
|
|
459
|
-
* extraFee: (1000).microAlgo(),
|
|
460
|
-
* staticFee: (1000).microAlgo(),
|
|
461
|
-
* // Max fee doesn't make sense with extraFee AND staticFee
|
|
462
|
-
* // already specified, but here for completeness
|
|
463
|
-
* maxFee: (3000).microAlgo(),
|
|
464
|
-
* maxRoundsToWaitForConfirmation: 5,
|
|
465
|
-
* suppressLog: true,
|
|
466
|
-
* })
|
|
467
|
-
* ```
|
|
468
|
-
* @returns The result of the transaction and the transaction that was sent
|
|
469
|
-
*/
|
|
470
|
-
async rekeyAccount(account, rekeyTo, options) {
|
|
471
|
-
const result = await this._getComposer().addPayment({
|
|
472
|
-
...options,
|
|
473
|
-
sender: require_address.getAddress(account),
|
|
474
|
-
receiver: require_address.getAddress(account),
|
|
475
|
-
amount: require_amount.AlgoAmount.MicroAlgo(0),
|
|
476
|
-
rekeyTo: require_address.getAddress(rekeyTo)
|
|
477
|
-
}).send(options);
|
|
478
|
-
if (typeof rekeyTo === "object" && "addr" in rekeyTo) this.rekeyed(account, rekeyTo);
|
|
479
|
-
require_config.Config.getLogger(options?.suppressLog).info(`Rekeyed ${account} to ${rekeyTo} via transaction ${result.txIds.at(-1)}`);
|
|
480
|
-
return {
|
|
481
|
-
...result,
|
|
482
|
-
transaction: result.transactions.at(-1),
|
|
483
|
-
confirmation: result.confirmations.at(-1)
|
|
484
|
-
};
|
|
485
|
-
}
|
|
486
|
-
async _getEnsureFundedAmount(sender, minSpendingBalance, minFundingIncrement) {
|
|
487
|
-
const accountInfo = await this.getInformation(sender);
|
|
488
|
-
const currentSpendingBalance = accountInfo.balance.microAlgo - accountInfo.minBalance.microAlgo;
|
|
489
|
-
const amountFunded = require_util.calculateFundAmount(minSpendingBalance.microAlgo, currentSpendingBalance, minFundingIncrement?.microAlgo ?? 0n);
|
|
490
|
-
return amountFunded === null ? void 0 : require_amount.AlgoAmount.MicroAlgo(amountFunded);
|
|
491
|
-
}
|
|
492
|
-
/**
|
|
493
|
-
* Funds a given account using a dispenser account as a funding source such that
|
|
494
|
-
* the given account has a certain amount of Algo free to spend (accounting for
|
|
495
|
-
* Algo locked in minimum balance requirement).
|
|
496
|
-
*
|
|
497
|
-
* https://dev.algorand.co/concepts/smart-contracts/costs-constraints#mbr
|
|
498
|
-
*
|
|
499
|
-
* @param accountToFund The account to fund
|
|
500
|
-
* @param dispenserAccount The account to use as a dispenser funding source
|
|
501
|
-
* @param minSpendingBalance The minimum balance of Algo that the account should have available to spend (i.e. on top of minimum balance requirement)
|
|
502
|
-
* @param options Optional parameters to control the funding increment, transaction or execution of the transaction
|
|
503
|
-
* @example Example using AlgorandClient
|
|
504
|
-
* ```typescript
|
|
505
|
-
* // Basic example
|
|
506
|
-
* await accountManager.ensureFunded("ACCOUNTADDRESS", "DISPENSERADDRESS", algokit.algo(1))
|
|
507
|
-
* // With configuration
|
|
508
|
-
* await accountManager.ensureFunded("ACCOUNTADDRESS", "DISPENSERADDRESS", algokit.algo(1),
|
|
509
|
-
* { minFundingIncrement: algokit.algo(2), fee: (1000).microAlgo(), suppressLog: true }
|
|
510
|
-
* )
|
|
511
|
-
* ```
|
|
512
|
-
* @returns
|
|
513
|
-
* - The result of executing the dispensing transaction and the `amountFunded` if funds were needed.
|
|
514
|
-
* - `undefined` if no funds were needed.
|
|
515
|
-
*/
|
|
516
|
-
async ensureFunded(accountToFund, dispenserAccount, minSpendingBalance, options) {
|
|
517
|
-
const addressToFund = require_address.getAddress(accountToFund);
|
|
518
|
-
const amountFunded = await this._getEnsureFundedAmount(addressToFund, minSpendingBalance, options?.minFundingIncrement);
|
|
519
|
-
if (!amountFunded) return void 0;
|
|
520
|
-
const result = await this._getComposer().addPayment({
|
|
521
|
-
...options,
|
|
522
|
-
sender: require_address.getAddress(dispenserAccount),
|
|
523
|
-
receiver: addressToFund,
|
|
524
|
-
amount: amountFunded
|
|
525
|
-
}).send(options);
|
|
526
|
-
return {
|
|
527
|
-
...result,
|
|
528
|
-
transaction: result.transactions[0],
|
|
529
|
-
confirmation: result.confirmations[0],
|
|
530
|
-
transactionId: result.txIds[0],
|
|
531
|
-
amountFunded
|
|
532
|
-
};
|
|
533
|
-
}
|
|
534
|
-
/**
|
|
535
|
-
* Funds a given account using a dispenser account retrieved from the environment,
|
|
536
|
-
* per the `dispenserFromEnvironment` method, as a funding source such that
|
|
537
|
-
* the given account has a certain amount of Algo free to spend (accounting for
|
|
538
|
-
* Algo locked in minimum balance requirement).
|
|
539
|
-
*
|
|
540
|
-
* **Note:** requires a Node.js environment to execute.
|
|
541
|
-
*
|
|
542
|
-
* The dispenser account is retrieved from the account mnemonic stored in
|
|
543
|
-
* process.env.DISPENSER_MNEMONIC and optionally process.env.DISPENSER_SENDER
|
|
544
|
-
* if it's a rekeyed account, or against default LocalNet if no environment variables present.
|
|
545
|
-
*
|
|
546
|
-
* https://dev.algorand.co/concepts/smart-contracts/costs-constraints#mbr
|
|
547
|
-
*
|
|
548
|
-
* @param accountToFund The account to fund
|
|
549
|
-
* @param minSpendingBalance The minimum balance of Algo that the account should have available to spend (i.e. on top of minimum balance requirement)
|
|
550
|
-
* @param options Optional parameters to control the funding increment, transaction or execution of the transaction
|
|
551
|
-
* @example Example using AlgorandClient
|
|
552
|
-
* ```typescript
|
|
553
|
-
* // Basic example
|
|
554
|
-
* await accountManager.ensureFundedFromEnvironment("ACCOUNTADDRESS", algokit.algo(1))
|
|
555
|
-
* // With configuration
|
|
556
|
-
* await accountManager.ensureFundedFromEnvironment("ACCOUNTADDRESS", algokit.algo(1),
|
|
557
|
-
* { minFundingIncrement: algokit.algo(2), fee: (1000).microAlgo(), suppressLog: true }
|
|
558
|
-
* )
|
|
559
|
-
* ```
|
|
560
|
-
* @returns
|
|
561
|
-
* - The result of executing the dispensing transaction and the `amountFunded` if funds were needed.
|
|
562
|
-
* - `undefined` if no funds were needed.
|
|
563
|
-
*/
|
|
564
|
-
async ensureFundedFromEnvironment(accountToFund, minSpendingBalance, options) {
|
|
565
|
-
const addressToFund = require_address.getAddress(accountToFund);
|
|
566
|
-
const dispenserAccount = await this.dispenserFromEnvironment();
|
|
567
|
-
const amountFunded = await this._getEnsureFundedAmount(addressToFund, minSpendingBalance, options?.minFundingIncrement);
|
|
568
|
-
if (!amountFunded) return void 0;
|
|
569
|
-
const result = await this._getComposer().addPayment({
|
|
570
|
-
...options,
|
|
571
|
-
sender: dispenserAccount,
|
|
572
|
-
receiver: addressToFund,
|
|
573
|
-
amount: amountFunded
|
|
574
|
-
}).send(options);
|
|
575
|
-
return {
|
|
576
|
-
...result,
|
|
577
|
-
transaction: result.transactions[0],
|
|
578
|
-
confirmation: result.confirmations[0],
|
|
579
|
-
transactionId: result.txIds[0],
|
|
580
|
-
amountFunded
|
|
581
|
-
};
|
|
582
|
-
}
|
|
583
|
-
/**
|
|
584
|
-
* Funds a given account using the TestNet Dispenser API as a funding source such that
|
|
585
|
-
* the account has a certain amount of Algo free to spend (accounting for Algo locked
|
|
586
|
-
* in minimum balance requirement).
|
|
587
|
-
*
|
|
588
|
-
* https://dev.algorand.co/concepts/smart-contracts/costs-constraints#mbr
|
|
589
|
-
*
|
|
590
|
-
* @param accountToFund The account to fund
|
|
591
|
-
* @param dispenserClient The TestNet dispenser funding client
|
|
592
|
-
* @param minSpendingBalance The minimum balance of Algo that the account should have available to spend (i.e. on top of minimum balance requirement)
|
|
593
|
-
* @param options Optional parameters to control the funding increment, transaction or execution of the transaction
|
|
594
|
-
* @example Example using AlgorandClient
|
|
595
|
-
* ```typescript
|
|
596
|
-
* // Basic example
|
|
597
|
-
* await accountManager.ensureFundedFromTestNetDispenserApi("ACCOUNTADDRESS", algorand.client.getTestNetDispenserFromEnvironment(), algokit.algo(1))
|
|
598
|
-
* // With configuration
|
|
599
|
-
* await accountManager.ensureFundedFromTestNetDispenserApi("ACCOUNTADDRESS", algorand.client.getTestNetDispenserFromEnvironment(), algokit.algo(1),
|
|
600
|
-
* { minFundingIncrement: algokit.algo(2) }
|
|
601
|
-
* )
|
|
602
|
-
* ```
|
|
603
|
-
* @returns
|
|
604
|
-
* - The result of executing the dispensing transaction and the `amountFunded` if funds were needed.
|
|
605
|
-
* - `undefined` if no funds were needed.
|
|
606
|
-
*/
|
|
607
|
-
async ensureFundedFromTestNetDispenserApi(accountToFund, dispenserClient, minSpendingBalance, options) {
|
|
608
|
-
if (!await this._clientManager.isTestNet()) throw new Error("Attempt to fund using TestNet dispenser API on non TestNet network.");
|
|
609
|
-
const addressToFund = require_address.getAddress(accountToFund);
|
|
610
|
-
const amountFunded = await this._getEnsureFundedAmount(addressToFund, minSpendingBalance, options?.minFundingIncrement);
|
|
611
|
-
if (!amountFunded) return void 0;
|
|
612
|
-
const result = await dispenserClient.fund(addressToFund, amountFunded.microAlgo);
|
|
613
|
-
return {
|
|
614
|
-
amountFunded: require_amount.AlgoAmount.MicroAlgo(result.amount),
|
|
615
|
-
transactionId: result.txId
|
|
616
|
-
};
|
|
617
|
-
}
|
|
618
|
-
};
|
|
4
|
+
/** @deprecated Import from `@algorandfoundation/algokit-utils/account-manager` instead */
|
|
5
|
+
const AccountManager = require_account_manager.AccountManager;
|
|
6
|
+
/** @deprecated Import from `@algorandfoundation/algokit-utils/account-manager` instead */
|
|
7
|
+
const getAccountTransactionSigner = require_account_manager.getAccountTransactionSigner;
|
|
619
8
|
|
|
620
9
|
//#endregion
|
|
621
10
|
exports.AccountManager = AccountManager;
|