@algorandfoundation/algokit-utils 8.2.0-beta.1 → 8.2.0-beta.3
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/package.json +3 -2
- package/types/account-manager.d.ts +33 -18
- package/types/account-manager.js +33 -18
- package/types/account-manager.js.map +1 -1
- package/types/account-manager.mjs +33 -18
- package/types/account-manager.mjs.map +1 -1
- package/types/account.d.ts +5 -0
- package/types/account.js +5 -0
- package/types/account.js.map +1 -1
- package/types/account.mjs +5 -0
- package/types/account.mjs.map +1 -1
- package/types/algorand-client-transaction-creator.d.ts +103 -70
- package/types/algorand-client-transaction-creator.js +103 -70
- package/types/algorand-client-transaction-creator.js.map +1 -1
- package/types/algorand-client-transaction-creator.mjs +103 -70
- package/types/algorand-client-transaction-creator.mjs.map +1 -1
- package/types/algorand-client-transaction-sender.d.ts +107 -20
- package/types/algorand-client-transaction-sender.js +107 -21
- package/types/algorand-client-transaction-sender.js.map +1 -1
- package/types/algorand-client-transaction-sender.mjs +107 -21
- package/types/algorand-client-transaction-sender.mjs.map +1 -1
- package/types/algorand-client.d.ts +108 -24
- package/types/algorand-client.js +107 -23
- package/types/algorand-client.js.map +1 -1
- package/types/algorand-client.mjs +107 -23
- package/types/algorand-client.mjs.map +1 -1
- package/types/amount.d.ts +10 -0
- package/types/amount.js +10 -0
- package/types/amount.js.map +1 -1
- package/types/amount.mjs +10 -0
- package/types/amount.mjs.map +1 -1
- package/types/app-client.d.ts +128 -8
- package/types/app-client.js +131 -8
- package/types/app-client.js.map +1 -1
- package/types/app-client.mjs +131 -8
- package/types/app-client.mjs.map +1 -1
- package/types/app-deployer.d.ts +33 -1
- package/types/app-deployer.js +33 -1
- package/types/app-deployer.js.map +1 -1
- package/types/app-deployer.mjs +33 -1
- package/types/app-deployer.mjs.map +1 -1
- package/types/app-factory.d.ts +74 -4
- package/types/app-factory.js +74 -4
- package/types/app-factory.js.map +1 -1
- package/types/app-factory.mjs +74 -4
- package/types/app-factory.mjs.map +1 -1
- package/types/app-manager.d.ts +64 -0
- package/types/app-manager.js +64 -0
- package/types/app-manager.js.map +1 -1
- package/types/app-manager.mjs +64 -0
- package/types/app-manager.mjs.map +1 -1
- package/types/app-spec.d.ts +9 -0
- package/types/app-spec.js +9 -0
- package/types/app-spec.js.map +1 -1
- package/types/app-spec.mjs +9 -0
- package/types/app-spec.mjs.map +1 -1
- package/types/asset-manager.d.ts +5 -5
- package/types/asset-manager.js +5 -5
- package/types/asset-manager.js.map +1 -1
- package/types/asset-manager.mjs +5 -5
- package/types/asset-manager.mjs.map +1 -1
- package/types/client-manager.d.ts +79 -18
- package/types/client-manager.js +79 -18
- package/types/client-manager.js.map +1 -1
- package/types/client-manager.mjs +79 -18
- package/types/client-manager.mjs.map +1 -1
- package/types/composer.d.ts +599 -1
- package/types/composer.js +575 -1
- package/types/composer.js.map +1 -1
- package/types/composer.mjs +575 -1
- package/types/composer.mjs.map +1 -1
|
@@ -26,6 +26,10 @@ class AlgorandClient {
|
|
|
26
26
|
* Sets the default validity window for transactions.
|
|
27
27
|
* @param validityWindow The number of rounds between the first and last valid rounds
|
|
28
28
|
* @returns The `AlgorandClient` so method calls can be chained
|
|
29
|
+
* @example
|
|
30
|
+
* ```typescript
|
|
31
|
+
* const algorand = AlgorandClient.mainNet().setDefaultValidityWindow(1000);
|
|
32
|
+
* ```
|
|
29
33
|
*/
|
|
30
34
|
setDefaultValidityWindow(validityWindow) {
|
|
31
35
|
this._defaultValidityWindow = BigInt(validityWindow);
|
|
@@ -35,6 +39,11 @@ class AlgorandClient {
|
|
|
35
39
|
* Sets the default signer to use if no other signer is specified.
|
|
36
40
|
* @param signer The signer to use, either a `TransactionSigner` or a `TransactionSignerAccount`
|
|
37
41
|
* @returns The `AlgorandClient` so method calls can be chained
|
|
42
|
+
* @example
|
|
43
|
+
* ```typescript
|
|
44
|
+
* const signer = new SigningAccount(account, account.addr)
|
|
45
|
+
* const algorand = AlgorandClient.mainNet().setDefaultSigner(signer)
|
|
46
|
+
* ```
|
|
38
47
|
*/
|
|
39
48
|
setDefaultSigner(signer) {
|
|
40
49
|
this._accountManager.setDefaultSigner(signer);
|
|
@@ -46,10 +55,10 @@ class AlgorandClient {
|
|
|
46
55
|
* a `algosdk.Account`, `algosdk.LogicSigAccount`, `SigningAccount` or `MultisigAccount`
|
|
47
56
|
* @example
|
|
48
57
|
* ```typescript
|
|
49
|
-
* const accountManager = AlgorandClient.
|
|
58
|
+
* const accountManager = AlgorandClient.mainNet()
|
|
50
59
|
* .setSignerFromAccount(algosdk.generateAccount())
|
|
51
60
|
* .setSignerFromAccount(new algosdk.LogicSigAccount(program, args))
|
|
52
|
-
* .setSignerFromAccount(new SigningAccount(
|
|
61
|
+
* .setSignerFromAccount(new SigningAccount(account, sender))
|
|
53
62
|
* .setSignerFromAccount(new MultisigAccount({version: 1, threshold: 1, addrs: ["ADDRESS1...", "ADDRESS2..."]}, [account1, account2]))
|
|
54
63
|
* .setSignerFromAccount({addr: "SENDERADDRESS", signer: transactionSigner})
|
|
55
64
|
* ```
|
|
@@ -64,6 +73,11 @@ class AlgorandClient {
|
|
|
64
73
|
* @param sender The sender address to use this signer for
|
|
65
74
|
* @param signer The signer to sign transactions with for the given sender
|
|
66
75
|
* @returns The `AlgorandClient` so method calls can be chained
|
|
76
|
+
* @example
|
|
77
|
+
* ```typescript
|
|
78
|
+
* const signer = new SigningAccount(account, account.addr)
|
|
79
|
+
* const algorand = AlgorandClient.mainNet().setSigner(signer.addr, signer.signer)
|
|
80
|
+
* ```
|
|
67
81
|
*/
|
|
68
82
|
setSigner(sender, signer) {
|
|
69
83
|
this._accountManager.setSigner(sender, signer);
|
|
@@ -74,6 +88,10 @@ class AlgorandClient {
|
|
|
74
88
|
* @param suggestedParams The suggested params to use
|
|
75
89
|
* @param until A date until which to cache, or if not specified then the timeout is used
|
|
76
90
|
* @returns The `AlgorandClient` so method calls can be chained
|
|
91
|
+
* @example
|
|
92
|
+
* ```typescript
|
|
93
|
+
* const algorand = AlgorandClient.mainNet().setSuggestedParamsCache(suggestedParams, new Date(+new Date() + 3_600_000))
|
|
94
|
+
* ```
|
|
77
95
|
*/
|
|
78
96
|
setSuggestedParamsCache(suggestedParams, until) {
|
|
79
97
|
this._cachedSuggestedParams = suggestedParams;
|
|
@@ -84,12 +102,21 @@ class AlgorandClient {
|
|
|
84
102
|
* Sets the timeout for caching suggested params.
|
|
85
103
|
* @param timeout The timeout in milliseconds
|
|
86
104
|
* @returns The `AlgorandClient` so method calls can be chained
|
|
105
|
+
* @example
|
|
106
|
+
* ```typescript
|
|
107
|
+
* const algorand = AlgorandClient.mainNet().setSuggestedParamsCacheTimeout(10_000)
|
|
108
|
+
* ```
|
|
87
109
|
*/
|
|
88
110
|
setSuggestedParamsCacheTimeout(timeout) {
|
|
89
111
|
this._cachedSuggestedParamsTimeout = timeout;
|
|
90
112
|
return this;
|
|
91
113
|
}
|
|
92
|
-
/**
|
|
114
|
+
/**
|
|
115
|
+
* Get suggested params for a transaction (either cached or from algod if the cache is stale or empty)
|
|
116
|
+
* @returns The suggested transaction parameters.
|
|
117
|
+
* @example
|
|
118
|
+
* const params = await AlgorandClient.mainNet().getSuggestedParams();
|
|
119
|
+
*/
|
|
93
120
|
async getSuggestedParams() {
|
|
94
121
|
if (this._cachedSuggestedParams && (!this._cachedSuggestedParamsExpiry || this._cachedSuggestedParamsExpiry > new Date())) {
|
|
95
122
|
return {
|
|
@@ -102,27 +129,58 @@ class AlgorandClient {
|
|
|
102
129
|
...this._cachedSuggestedParams,
|
|
103
130
|
};
|
|
104
131
|
}
|
|
105
|
-
/**
|
|
132
|
+
/**
|
|
133
|
+
* Get clients, including algosdk clients and app clients.
|
|
134
|
+
* @returns The `ClientManager` instance.
|
|
135
|
+
* @example
|
|
136
|
+
* const clientManager = AlgorandClient.mainNet().client;
|
|
137
|
+
*/
|
|
106
138
|
get client() {
|
|
107
139
|
return this._clientManager;
|
|
108
140
|
}
|
|
109
|
-
/**
|
|
141
|
+
/**
|
|
142
|
+
* Get or create accounts that can sign transactions.
|
|
143
|
+
* @returns The `AccountManager` instance.
|
|
144
|
+
* @example
|
|
145
|
+
* const accountManager = AlgorandClient.mainNet().account;
|
|
146
|
+
*/
|
|
110
147
|
get account() {
|
|
111
148
|
return this._accountManager;
|
|
112
149
|
}
|
|
113
|
-
/**
|
|
150
|
+
/**
|
|
151
|
+
* Methods for interacting with assets.
|
|
152
|
+
* @returns The `AssetManager` instance.
|
|
153
|
+
* @example
|
|
154
|
+
* const assetManager = AlgorandClient.mainNet().asset;
|
|
155
|
+
*/
|
|
114
156
|
get asset() {
|
|
115
157
|
return this._assetManager;
|
|
116
158
|
}
|
|
117
|
-
/**
|
|
159
|
+
/**
|
|
160
|
+
* Methods for interacting with apps.
|
|
161
|
+
* @returns The `AppManager` instance.
|
|
162
|
+
* @example
|
|
163
|
+
* const appManager = AlgorandClient.mainNet().app;
|
|
164
|
+
*/
|
|
118
165
|
get app() {
|
|
119
166
|
return this._appManager;
|
|
120
167
|
}
|
|
121
|
-
/**
|
|
168
|
+
/**
|
|
169
|
+
* Methods for deploying apps and managing app deployment metadata.
|
|
170
|
+
* @returns The `AppDeployer` instance.
|
|
171
|
+
* @example
|
|
172
|
+
* const deployer = AlgorandClient.mainNet().appDeployer;
|
|
173
|
+
*/
|
|
122
174
|
get appDeployer() {
|
|
123
175
|
return this._appDeployer;
|
|
124
176
|
}
|
|
125
|
-
/**
|
|
177
|
+
/**
|
|
178
|
+
* Start a new `TransactionComposer` transaction group
|
|
179
|
+
* @returns A new instance of `TransactionComposer`.
|
|
180
|
+
* @example
|
|
181
|
+
* const composer = AlgorandClient.mainNet().newGroup();
|
|
182
|
+
* const result = await composer.addTransaction(payment).send()
|
|
183
|
+
*/
|
|
126
184
|
newGroup() {
|
|
127
185
|
return new TransactionComposer({
|
|
128
186
|
algod: this.client.algod,
|
|
@@ -134,20 +192,36 @@ class AlgorandClient {
|
|
|
134
192
|
}
|
|
135
193
|
/**
|
|
136
194
|
* Methods for sending a transaction.
|
|
195
|
+
* @returns The `AlgorandClientTransactionSender` instance.
|
|
196
|
+
* @example
|
|
197
|
+
* const result = await AlgorandClient.mainNet().send.payment({
|
|
198
|
+
* sender: "SENDERADDRESS",
|
|
199
|
+
* receiver: "RECEIVERADDRESS",
|
|
200
|
+
* amount: algo(1)
|
|
201
|
+
* })
|
|
137
202
|
*/
|
|
138
203
|
get send() {
|
|
139
204
|
return this._transactionSender;
|
|
140
205
|
}
|
|
141
206
|
/**
|
|
142
207
|
* Methods for creating a transaction.
|
|
208
|
+
* @returns The `AlgorandClientTransactionCreator` instance.
|
|
209
|
+
* @example
|
|
210
|
+
* const payment = await AlgorandClient.mainNet().createTransaction.payment({
|
|
211
|
+
* sender: "SENDERADDRESS",
|
|
212
|
+
* receiver: "RECEIVERADDRESS",
|
|
213
|
+
* amount: algo(1)
|
|
214
|
+
* })
|
|
143
215
|
*/
|
|
144
216
|
get createTransaction() {
|
|
145
217
|
return this._transactionCreator;
|
|
146
218
|
}
|
|
147
219
|
// Static methods to create an `AlgorandClient`
|
|
148
220
|
/**
|
|
149
|
-
*
|
|
150
|
-
* @returns
|
|
221
|
+
* Creates an `AlgorandClient` pointing at default LocalNet ports and API token.
|
|
222
|
+
* @returns An instance of the `AlgorandClient`.
|
|
223
|
+
* @example
|
|
224
|
+
* const algorand = AlgorandClient.defaultLocalNet();
|
|
151
225
|
*/
|
|
152
226
|
static defaultLocalNet() {
|
|
153
227
|
return new AlgorandClient({
|
|
@@ -157,8 +231,10 @@ class AlgorandClient {
|
|
|
157
231
|
});
|
|
158
232
|
}
|
|
159
233
|
/**
|
|
160
|
-
*
|
|
161
|
-
* @returns
|
|
234
|
+
* Creates an `AlgorandClient` pointing at TestNet using AlgoNode.
|
|
235
|
+
* @returns An instance of the `AlgorandClient`.
|
|
236
|
+
* @example
|
|
237
|
+
* const algorand = AlgorandClient.testNet();
|
|
162
238
|
*/
|
|
163
239
|
static testNet() {
|
|
164
240
|
return new AlgorandClient({
|
|
@@ -168,8 +244,10 @@ class AlgorandClient {
|
|
|
168
244
|
});
|
|
169
245
|
}
|
|
170
246
|
/**
|
|
171
|
-
*
|
|
172
|
-
* @returns
|
|
247
|
+
* Creates an `AlgorandClient` pointing at MainNet using AlgoNode.
|
|
248
|
+
* @returns An instance of the `AlgorandClient`.
|
|
249
|
+
* @example
|
|
250
|
+
* const algorand = AlgorandClient.mainNet();
|
|
173
251
|
*/
|
|
174
252
|
static mainNet() {
|
|
175
253
|
return new AlgorandClient({
|
|
@@ -179,15 +257,17 @@ class AlgorandClient {
|
|
|
179
257
|
});
|
|
180
258
|
}
|
|
181
259
|
/**
|
|
182
|
-
*
|
|
183
|
-
* @param clients The clients to use
|
|
184
|
-
* @returns
|
|
260
|
+
* Creates an `AlgorandClient` pointing to the given client(s).
|
|
261
|
+
* @param clients The clients to use.
|
|
262
|
+
* @returns An instance of the `AlgorandClient`.
|
|
263
|
+
* @example
|
|
264
|
+
* const algorand = AlgorandClient.fromClients({ algod, indexer, kmd });
|
|
185
265
|
*/
|
|
186
266
|
static fromClients(clients) {
|
|
187
267
|
return new AlgorandClient(clients);
|
|
188
268
|
}
|
|
189
269
|
/**
|
|
190
|
-
*
|
|
270
|
+
* Creates an `AlgorandClient` loading the configuration from environment variables.
|
|
191
271
|
*
|
|
192
272
|
* Retrieve configurations from environment variables when defined or get default LocalNet configuration if they aren't defined.
|
|
193
273
|
*
|
|
@@ -201,15 +281,19 @@ class AlgorandClient {
|
|
|
201
281
|
*
|
|
202
282
|
* It will return a KMD configuration that uses `process.env.KMD_PORT` (or port 4002) if `process.env.ALGOD_SERVER` is defined,
|
|
203
283
|
* otherwise it will use the default LocalNet config unless it detects testnet or mainnet.
|
|
204
|
-
* @returns
|
|
284
|
+
* @returns An instance of the `AlgorandClient`.
|
|
285
|
+
* @example
|
|
286
|
+
* const client = AlgorandClient.fromEnvironment();
|
|
205
287
|
*/
|
|
206
288
|
static fromEnvironment() {
|
|
207
289
|
return new AlgorandClient(ClientManager.getConfigFromEnvironmentOrLocalNet());
|
|
208
290
|
}
|
|
209
291
|
/**
|
|
210
|
-
*
|
|
211
|
-
* @param config The config to use
|
|
212
|
-
* @returns
|
|
292
|
+
* Creates an `AlgorandClient` from the given config.
|
|
293
|
+
* @param config The config to use.
|
|
294
|
+
* @returns An instance of the `AlgorandClient`.
|
|
295
|
+
* @example
|
|
296
|
+
* const client = AlgorandClient.fromConfig({ algodConfig, indexerConfig, kmdConfig });
|
|
213
297
|
*/
|
|
214
298
|
static fromConfig(config) {
|
|
215
299
|
return new AlgorandClient(config);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"algorand-client.mjs","sources":["../../src/types/algorand-client.ts"],"sourcesContent":["import algosdk, { Address } from 'algosdk'\nimport { MultisigAccount, SigningAccount, TransactionSignerAccount } from './account'\nimport { AccountManager } from './account-manager'\nimport { AlgorandClientTransactionCreator } from './algorand-client-transaction-creator'\nimport { AlgorandClientTransactionSender } from './algorand-client-transaction-sender'\nimport { AppDeployer } from './app-deployer'\nimport { AppManager } from './app-manager'\nimport { AssetManager } from './asset-manager'\nimport { AlgoSdkClients, ClientManager } from './client-manager'\nimport { TransactionComposer } from './composer'\nimport { AlgoConfig } from './network-client'\nimport Account = algosdk.Account\nimport LogicSigAccount = algosdk.LogicSigAccount\n\n/**\n * A client that brokers easy access to Algorand functionality.\n */\nexport class AlgorandClient {\n private _clientManager: ClientManager\n private _accountManager: AccountManager\n private _appManager: AppManager\n private _appDeployer: AppDeployer\n private _assetManager: AssetManager\n private _transactionSender: AlgorandClientTransactionSender\n private _transactionCreator: AlgorandClientTransactionCreator\n\n private _cachedSuggestedParams?: algosdk.SuggestedParams\n private _cachedSuggestedParamsExpiry?: Date\n private _cachedSuggestedParamsTimeout: number = 3_000 // three seconds\n\n private _defaultValidityWindow: bigint | undefined = undefined\n\n private constructor(config: AlgoConfig | AlgoSdkClients) {\n this._clientManager = new ClientManager(config, this)\n this._accountManager = new AccountManager(this._clientManager)\n this._appManager = new AppManager(this._clientManager.algod)\n this._assetManager = new AssetManager(this._clientManager.algod, () => this.newGroup())\n this._transactionSender = new AlgorandClientTransactionSender(() => this.newGroup(), this._assetManager, this._appManager)\n this._transactionCreator = new AlgorandClientTransactionCreator(() => this.newGroup())\n this._appDeployer = new AppDeployer(this._appManager, this._transactionSender, this._clientManager.indexerIfPresent)\n }\n\n /**\n * Sets the default validity window for transactions.\n * @param validityWindow The number of rounds between the first and last valid rounds\n * @returns The `AlgorandClient` so method calls can be chained\n */\n public setDefaultValidityWindow(validityWindow: number | bigint) {\n this._defaultValidityWindow = BigInt(validityWindow)\n return this\n }\n\n /**\n * Sets the default signer to use if no other signer is specified.\n * @param signer The signer to use, either a `TransactionSigner` or a `TransactionSignerAccount`\n * @returns The `AlgorandClient` so method calls can be chained\n */\n public setDefaultSigner(signer: algosdk.TransactionSigner | TransactionSignerAccount): AlgorandClient {\n this._accountManager.setDefaultSigner(signer)\n return this\n }\n\n /**\n * Tracks the given account (object that encapsulates an address and a signer) for later signing.\n * @param account The account to register, which can be a `TransactionSignerAccount` or\n * a `algosdk.Account`, `algosdk.LogicSigAccount`, `SigningAccount` or `MultisigAccount`\n * @example\n * ```typescript\n * const accountManager = AlgorandClient.mainnet()\n * .setSignerFromAccount(algosdk.generateAccount())\n * .setSignerFromAccount(new algosdk.LogicSigAccount(program, args))\n * .setSignerFromAccount(new SigningAccount(mnemonic, sender))\n * .setSignerFromAccount(new MultisigAccount({version: 1, threshold: 1, addrs: [\"ADDRESS1...\", \"ADDRESS2...\"]}, [account1, account2]))\n * .setSignerFromAccount({addr: \"SENDERADDRESS\", signer: transactionSigner})\n * ```\n * @returns The `AlgorandClient` so method calls can be chained\n */\n public setSignerFromAccount(\n account: TransactionSignerAccount | TransactionSignerAccount | Account | LogicSigAccount | SigningAccount | MultisigAccount,\n ) {\n this._accountManager.setSignerFromAccount(account)\n return this\n }\n\n /**\n * Tracks the given signer against the given sender for later signing.\n * @param sender The sender address to use this signer for\n * @param signer The signer to sign transactions with for the given sender\n * @returns The `AlgorandClient` so method calls can be chained\n */\n public setSigner(sender: string | Address, signer: algosdk.TransactionSigner) {\n this._accountManager.setSigner(sender, signer)\n return this\n }\n\n /**\n * Sets a cache value to use for suggested transaction params.\n * @param suggestedParams The suggested params to use\n * @param until A date until which to cache, or if not specified then the timeout is used\n * @returns The `AlgorandClient` so method calls can be chained\n */\n public setSuggestedParamsCache(suggestedParams: algosdk.SuggestedParams, until?: Date) {\n this._cachedSuggestedParams = suggestedParams\n this._cachedSuggestedParamsExpiry = until ?? new Date(+new Date() + this._cachedSuggestedParamsTimeout)\n return this\n }\n\n /**\n * Sets the timeout for caching suggested params.\n * @param timeout The timeout in milliseconds\n * @returns The `AlgorandClient` so method calls can be chained\n */\n public setSuggestedParamsCacheTimeout(timeout: number) {\n this._cachedSuggestedParamsTimeout = timeout\n return this\n }\n\n /** Get suggested params for a transaction (either cached or from algod if the cache is stale or empty) */\n public async getSuggestedParams(): Promise<algosdk.SuggestedParams> {\n if (this._cachedSuggestedParams && (!this._cachedSuggestedParamsExpiry || this._cachedSuggestedParamsExpiry > new Date())) {\n return {\n ...this._cachedSuggestedParams,\n }\n }\n\n this._cachedSuggestedParams = await this._clientManager.algod.getTransactionParams().do()\n this._cachedSuggestedParamsExpiry = new Date(new Date().getTime() + this._cachedSuggestedParamsTimeout)\n\n return {\n ...this._cachedSuggestedParams,\n }\n }\n\n /** Get clients, including algosdk clients and app clients. */\n public get client() {\n return this._clientManager\n }\n\n /** Get or create accounts that can sign transactions. */\n public get account() {\n return this._accountManager\n }\n\n /** Methods for interacting with assets. */\n public get asset() {\n return this._assetManager\n }\n\n /** Methods for interacting with apps. */\n public get app() {\n return this._appManager\n }\n\n /** Methods for deploying apps and managing app deployment metadata. */\n public get appDeployer() {\n return this._appDeployer\n }\n\n /** Start a new `TransactionComposer` transaction group */\n public newGroup() {\n return new TransactionComposer({\n algod: this.client.algod,\n getSigner: (addr: string | Address) => this.account.getSigner(addr),\n getSuggestedParams: () => this.getSuggestedParams(),\n defaultValidityWindow: this._defaultValidityWindow,\n appManager: this._appManager,\n })\n }\n\n /**\n * Methods for sending a transaction.\n */\n public get send() {\n return this._transactionSender\n }\n\n /**\n * Methods for creating a transaction.\n */\n public get createTransaction() {\n return this._transactionCreator\n }\n\n // Static methods to create an `AlgorandClient`\n\n /**\n * Returns an `AlgorandClient` pointing at default LocalNet ports and API token.\n * @returns The `AlgorandClient`\n */\n public static defaultLocalNet() {\n return new AlgorandClient({\n algodConfig: ClientManager.getDefaultLocalNetConfig('algod'),\n indexerConfig: ClientManager.getDefaultLocalNetConfig('indexer'),\n kmdConfig: ClientManager.getDefaultLocalNetConfig('kmd'),\n })\n }\n\n /**\n * Returns an `AlgorandClient` pointing at TestNet using AlgoNode.\n * @returns The `AlgorandClient`\n */\n public static testNet() {\n return new AlgorandClient({\n algodConfig: ClientManager.getAlgoNodeConfig('testnet', 'algod'),\n indexerConfig: ClientManager.getAlgoNodeConfig('testnet', 'indexer'),\n kmdConfig: undefined,\n })\n }\n\n /**\n * Returns an `AlgorandClient` pointing at MainNet using AlgoNode.\n * @returns The `AlgorandClient`\n */\n public static mainNet() {\n return new AlgorandClient({\n algodConfig: ClientManager.getAlgoNodeConfig('mainnet', 'algod'),\n indexerConfig: ClientManager.getAlgoNodeConfig('mainnet', 'indexer'),\n kmdConfig: undefined,\n })\n }\n\n /**\n * Returns an `AlgorandClient` pointing to the given client(s).\n * @param clients The clients to use\n * @returns The `AlgorandClient`\n */\n public static fromClients(clients: AlgoSdkClients) {\n return new AlgorandClient(clients)\n }\n\n /**\n * Returns an `AlgorandClient` loading the configuration from environment variables.\n *\n * Retrieve configurations from environment variables when defined or get default LocalNet configuration if they aren't defined.\n *\n * Expects to be called from a Node.js environment.\n *\n * If `process.env.ALGOD_SERVER` is defined it will use that along with optional `process.env.ALGOD_PORT` and `process.env.ALGOD_TOKEN`.\n *\n * If `process.env.INDEXER_SERVER` is defined it will use that along with optional `process.env.INDEXER_PORT` and `process.env.INDEXER_TOKEN`.\n *\n * If either aren't defined it will use the default LocalNet config.\n *\n * It will return a KMD configuration that uses `process.env.KMD_PORT` (or port 4002) if `process.env.ALGOD_SERVER` is defined,\n * otherwise it will use the default LocalNet config unless it detects testnet or mainnet.\n * @returns The `AlgorandClient`\n */\n public static fromEnvironment() {\n return new AlgorandClient(ClientManager.getConfigFromEnvironmentOrLocalNet())\n }\n\n /**\n * Returns an `AlgorandClient` from the given config.\n * @param config The config to use\n * @returns The `AlgorandClient`\n */\n public static fromConfig(config: AlgoConfig) {\n return new AlgorandClient(config)\n }\n}\n"],"names":[],"mappings":";;;;;;;;;AAcA;;AAEG;MACU,cAAc,CAAA;AAezB,IAAA,WAAA,CAAoB,MAAmC,EAAA;AAJ/C,QAAA,IAAA,CAAA,6BAA6B,GAAW,IAAK,CAAA;QAE7C,IAAsB,CAAA,sBAAA,GAAuB,SAAS;QAG5D,IAAI,CAAC,cAAc,GAAG,IAAI,aAAa,CAAC,MAAM,EAAE,IAAI,CAAC;QACrD,IAAI,CAAC,eAAe,GAAG,IAAI,cAAc,CAAC,IAAI,CAAC,cAAc,CAAC;AAC9D,QAAA,IAAI,CAAC,WAAW,GAAG,IAAI,UAAU,CAAC,IAAI,CAAC,cAAc,CAAC,KAAK,CAAC;QAC5D,IAAI,CAAC,aAAa,GAAG,IAAI,YAAY,CAAC,IAAI,CAAC,cAAc,CAAC,KAAK,EAAE,MAAM,IAAI,CAAC,QAAQ,EAAE,CAAC;QACvF,IAAI,CAAC,kBAAkB,GAAG,IAAI,+BAA+B,CAAC,MAAM,IAAI,CAAC,QAAQ,EAAE,EAAE,IAAI,CAAC,aAAa,EAAE,IAAI,CAAC,WAAW,CAAC;AAC1H,QAAA,IAAI,CAAC,mBAAmB,GAAG,IAAI,gCAAgC,CAAC,MAAM,IAAI,CAAC,QAAQ,EAAE,CAAC;QACtF,IAAI,CAAC,YAAY,GAAG,IAAI,WAAW,CAAC,IAAI,CAAC,WAAW,EAAE,IA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YAAA,WAAW,EAAE,aAAa,CAAC,wBAAwB,CAAC,OAAO,CAAC;AAC5D,YAAA,aAAa,EAAE,aAAa,CAAC,wBAAwB,CAAC,SAAS,CAAC;AAChE,YAAA,SAAS,EAAE,aAAa,CAAC,wBAAwB,CAAC,KAAK,CAAC;AACzD,SAAA,CAAC;;AAGJ;;;AAGG;AACI,IAAA,OAAO,OAAO,GAAA;QACnB,OAAO,IAAI,cAAc,CAAC;YACxB,WAAW,EAAE,aAAa,CAAC,iBAAiB,CAAC,SAAS,EAAE,OAAO,CAAC;YAChE,aAAa,EAAE,aAAa,CAAC,iBAAiB,CAAC,SAAS,EAAE,SAAS,CAAC;AACpE,YAAA,SAAS,EAAE,SAAS;AACrB,SAAA,CAAC;;AAGJ;;;AAGG;AACI,IAAA,OAAO,OAAO,GAAA;QACnB,OAAO,IAAI,cAAc,CAAC;YACxB,WAAW,EAAE,aAAa,CAAC,iBAAiB,CAAC,SAAS,EAAE,OAAO,CAAC;YAChE,aAAa,EAAE,aAAa,CAAC,iBAAiB,CAAC,SAAS,EAAE,SAAS,CAAC;AACpE,YAAA,SAAS,EAAE,SAAS;AACrB,SAAA,CAAC;;AAGJ;;;;AAIG;IACI,OAAO,WAAW,CAAC,OAAuB,EAAA;AAC/C,QAAA,OAAO,IAAI,cAAc,CAAC,OAAO,CAAC;;AAGpC;;;;;;;;;;;;;;;;AAgBG;AACI,IAAA,OAAO,eAAe,GAAA;QAC3B,OAAO,IAAI,cAAc,CAAC,aAAa,CAAC,kCAAkC,EAAE,CAAC;;AAG/E;;;;AAIG;IACI,OAAO,UAAU,CAAC,MAAkB,EAAA;AACzC,QAAA,OAAO,IAAI,cAAc,CAAC,MAAM,CAAC;;AAEpC;;;;"}
|
|
1
|
+
{"version":3,"file":"algorand-client.mjs","sources":["../../src/types/algorand-client.ts"],"sourcesContent":["import algosdk, { Address } from 'algosdk'\nimport { MultisigAccount, SigningAccount, TransactionSignerAccount } from './account'\nimport { AccountManager } from './account-manager'\nimport { AlgorandClientTransactionCreator } from './algorand-client-transaction-creator'\nimport { AlgorandClientTransactionSender } from './algorand-client-transaction-sender'\nimport { AppDeployer } from './app-deployer'\nimport { AppManager } from './app-manager'\nimport { AssetManager } from './asset-manager'\nimport { AlgoSdkClients, ClientManager } from './client-manager'\nimport { TransactionComposer } from './composer'\nimport { AlgoConfig } from './network-client'\nimport Account = algosdk.Account\nimport LogicSigAccount = algosdk.LogicSigAccount\n\n/**\n * A client that brokers easy access to Algorand functionality.\n */\nexport class AlgorandClient {\n private _clientManager: ClientManager\n private _accountManager: AccountManager\n private _appManager: AppManager\n private _appDeployer: AppDeployer\n private _assetManager: AssetManager\n private _transactionSender: AlgorandClientTransactionSender\n private _transactionCreator: AlgorandClientTransactionCreator\n\n private _cachedSuggestedParams?: algosdk.SuggestedParams\n private _cachedSuggestedParamsExpiry?: Date\n private _cachedSuggestedParamsTimeout: number = 3_000 // three seconds\n\n private _defaultValidityWindow: bigint | undefined = undefined\n\n private constructor(config: AlgoConfig | AlgoSdkClients) {\n this._clientManager = new ClientManager(config, this)\n this._accountManager = new AccountManager(this._clientManager)\n this._appManager = new AppManager(this._clientManager.algod)\n this._assetManager = new AssetManager(this._clientManager.algod, () => this.newGroup())\n this._transactionSender = new AlgorandClientTransactionSender(() => this.newGroup(), this._assetManager, this._appManager)\n this._transactionCreator = new AlgorandClientTransactionCreator(() => this.newGroup())\n this._appDeployer = new AppDeployer(this._appManager, this._transactionSender, this._clientManager.indexerIfPresent)\n }\n\n /**\n * Sets the default validity window for transactions.\n * @param validityWindow The number of rounds between the first and last valid rounds\n * @returns The `AlgorandClient` so method calls can be chained\n * @example\n * ```typescript\n * const algorand = AlgorandClient.mainNet().setDefaultValidityWindow(1000);\n * ```\n */\n public setDefaultValidityWindow(validityWindow: number | bigint) {\n this._defaultValidityWindow = BigInt(validityWindow)\n return this\n }\n\n /**\n * Sets the default signer to use if no other signer is specified.\n * @param signer The signer to use, either a `TransactionSigner` or a `TransactionSignerAccount`\n * @returns The `AlgorandClient` so method calls can be chained\n * @example\n * ```typescript\n * const signer = new SigningAccount(account, account.addr)\n * const algorand = AlgorandClient.mainNet().setDefaultSigner(signer)\n * ```\n */\n public setDefaultSigner(signer: algosdk.TransactionSigner | TransactionSignerAccount): AlgorandClient {\n this._accountManager.setDefaultSigner(signer)\n return this\n }\n\n /**\n * Tracks the given account (object that encapsulates an address and a signer) for later signing.\n * @param account The account to register, which can be a `TransactionSignerAccount` or\n * a `algosdk.Account`, `algosdk.LogicSigAccount`, `SigningAccount` or `MultisigAccount`\n * @example\n * ```typescript\n * const accountManager = AlgorandClient.mainNet()\n * .setSignerFromAccount(algosdk.generateAccount())\n * .setSignerFromAccount(new algosdk.LogicSigAccount(program, args))\n * .setSignerFromAccount(new SigningAccount(account, sender))\n * .setSignerFromAccount(new MultisigAccount({version: 1, threshold: 1, addrs: [\"ADDRESS1...\", \"ADDRESS2...\"]}, [account1, account2]))\n * .setSignerFromAccount({addr: \"SENDERADDRESS\", signer: transactionSigner})\n * ```\n * @returns The `AlgorandClient` so method calls can be chained\n */\n public setSignerFromAccount(account: TransactionSignerAccount | Account | LogicSigAccount | SigningAccount | MultisigAccount) {\n this._accountManager.setSignerFromAccount(account)\n return this\n }\n\n /**\n * Tracks the given signer against the given sender for later signing.\n * @param sender The sender address to use this signer for\n * @param signer The signer to sign transactions with for the given sender\n * @returns The `AlgorandClient` so method calls can be chained\n * @example\n * ```typescript\n * const signer = new SigningAccount(account, account.addr)\n * const algorand = AlgorandClient.mainNet().setSigner(signer.addr, signer.signer)\n * ```\n */\n public setSigner(sender: string | Address, signer: algosdk.TransactionSigner) {\n this._accountManager.setSigner(sender, signer)\n return this\n }\n\n /**\n * Sets a cache value to use for suggested transaction params.\n * @param suggestedParams The suggested params to use\n * @param until A date until which to cache, or if not specified then the timeout is used\n * @returns The `AlgorandClient` so method calls can be chained\n * @example\n * ```typescript\n * const algorand = AlgorandClient.mainNet().setSuggestedParamsCache(suggestedParams, new Date(+new Date() + 3_600_000))\n * ```\n */\n public setSuggestedParamsCache(suggestedParams: algosdk.SuggestedParams, until?: Date) {\n this._cachedSuggestedParams = suggestedParams\n this._cachedSuggestedParamsExpiry = until ?? new Date(+new Date() + this._cachedSuggestedParamsTimeout)\n return this\n }\n\n /**\n * Sets the timeout for caching suggested params.\n * @param timeout The timeout in milliseconds\n * @returns The `AlgorandClient` so method calls can be chained\n * @example\n * ```typescript\n * const algorand = AlgorandClient.mainNet().setSuggestedParamsCacheTimeout(10_000)\n * ```\n */\n public setSuggestedParamsCacheTimeout(timeout: number) {\n this._cachedSuggestedParamsTimeout = timeout\n return this\n }\n\n /**\n * Get suggested params for a transaction (either cached or from algod if the cache is stale or empty)\n * @returns The suggested transaction parameters.\n * @example\n * const params = await AlgorandClient.mainNet().getSuggestedParams();\n */\n public async getSuggestedParams(): Promise<algosdk.SuggestedParams> {\n if (this._cachedSuggestedParams && (!this._cachedSuggestedParamsExpiry || this._cachedSuggestedParamsExpiry > new Date())) {\n return {\n ...this._cachedSuggestedParams,\n }\n }\n\n this._cachedSuggestedParams = await this._clientManager.algod.getTransactionParams().do()\n this._cachedSuggestedParamsExpiry = new Date(new Date().getTime() + this._cachedSuggestedParamsTimeout)\n\n return {\n ...this._cachedSuggestedParams,\n }\n }\n\n /**\n * Get clients, including algosdk clients and app clients.\n * @returns The `ClientManager` instance.\n * @example\n * const clientManager = AlgorandClient.mainNet().client;\n */\n public get client() {\n return this._clientManager\n }\n\n /**\n * Get or create accounts that can sign transactions.\n * @returns The `AccountManager` instance.\n * @example\n * const accountManager = AlgorandClient.mainNet().account;\n */\n public get account() {\n return this._accountManager\n }\n\n /**\n * Methods for interacting with assets.\n * @returns The `AssetManager` instance.\n * @example\n * const assetManager = AlgorandClient.mainNet().asset;\n */\n public get asset() {\n return this._assetManager\n }\n\n /**\n * Methods for interacting with apps.\n * @returns The `AppManager` instance.\n * @example\n * const appManager = AlgorandClient.mainNet().app;\n */\n public get app() {\n return this._appManager\n }\n\n /**\n * Methods for deploying apps and managing app deployment metadata.\n * @returns The `AppDeployer` instance.\n * @example\n * const deployer = AlgorandClient.mainNet().appDeployer;\n */\n public get appDeployer() {\n return this._appDeployer\n }\n\n /**\n * Start a new `TransactionComposer` transaction group\n * @returns A new instance of `TransactionComposer`.\n * @example\n * const composer = AlgorandClient.mainNet().newGroup();\n * const result = await composer.addTransaction(payment).send()\n */\n public newGroup() {\n return new TransactionComposer({\n algod: this.client.algod,\n getSigner: (addr: string | Address) => this.account.getSigner(addr),\n getSuggestedParams: () => this.getSuggestedParams(),\n defaultValidityWindow: this._defaultValidityWindow,\n appManager: this._appManager,\n })\n }\n\n /**\n * Methods for sending a transaction.\n * @returns The `AlgorandClientTransactionSender` instance.\n * @example\n * const result = await AlgorandClient.mainNet().send.payment({\n * sender: \"SENDERADDRESS\",\n * receiver: \"RECEIVERADDRESS\",\n * amount: algo(1)\n * })\n */\n public get send() {\n return this._transactionSender\n }\n\n /**\n * Methods for creating a transaction.\n * @returns The `AlgorandClientTransactionCreator` instance.\n * @example\n * const payment = await AlgorandClient.mainNet().createTransaction.payment({\n * sender: \"SENDERADDRESS\",\n * receiver: \"RECEIVERADDRESS\",\n * amount: algo(1)\n * })\n */\n public get createTransaction() {\n return this._transactionCreator\n }\n\n // Static methods to create an `AlgorandClient`\n\n /**\n * Creates an `AlgorandClient` pointing at default LocalNet ports and API token.\n * @returns An instance of the `AlgorandClient`.\n * @example\n * const algorand = AlgorandClient.defaultLocalNet();\n */\n public static defaultLocalNet() {\n return new AlgorandClient({\n algodConfig: ClientManager.getDefaultLocalNetConfig('algod'),\n indexerConfig: ClientManager.getDefaultLocalNetConfig('indexer'),\n kmdConfig: ClientManager.getDefaultLocalNetConfig('kmd'),\n })\n }\n\n /**\n * Creates an `AlgorandClient` pointing at TestNet using AlgoNode.\n * @returns An instance of the `AlgorandClient`.\n * @example\n * const algorand = AlgorandClient.testNet();\n */\n public static testNet() {\n return new AlgorandClient({\n algodConfig: ClientManager.getAlgoNodeConfig('testnet', 'algod'),\n indexerConfig: ClientManager.getAlgoNodeConfig('testnet', 'indexer'),\n kmdConfig: undefined,\n })\n }\n\n /**\n * Creates an `AlgorandClient` pointing at MainNet using AlgoNode.\n * @returns An instance of the `AlgorandClient`.\n * @example\n * const algorand = AlgorandClient.mainNet();\n */\n public static mainNet() {\n return new AlgorandClient({\n algodConfig: ClientManager.getAlgoNodeConfig('mainnet', 'algod'),\n indexerConfig: ClientManager.getAlgoNodeConfig('mainnet', 'indexer'),\n kmdConfig: undefined,\n })\n }\n\n /**\n * Creates an `AlgorandClient` pointing to the given client(s).\n * @param clients The clients to use.\n * @returns An instance of the `AlgorandClient`.\n * @example\n * const algorand = AlgorandClient.fromClients({ algod, indexer, kmd });\n */\n public static fromClients(clients: AlgoSdkClients) {\n return new AlgorandClient(clients)\n }\n\n /**\n * Creates an `AlgorandClient` loading the configuration from environment variables.\n *\n * Retrieve configurations from environment variables when defined or get default LocalNet configuration if they aren't defined.\n *\n * Expects to be called from a Node.js environment.\n *\n * If `process.env.ALGOD_SERVER` is defined it will use that along with optional `process.env.ALGOD_PORT` and `process.env.ALGOD_TOKEN`.\n *\n * If `process.env.INDEXER_SERVER` is defined it will use that along with optional `process.env.INDEXER_PORT` and `process.env.INDEXER_TOKEN`.\n *\n * If either aren't defined it will use the default LocalNet config.\n *\n * It will return a KMD configuration that uses `process.env.KMD_PORT` (or port 4002) if `process.env.ALGOD_SERVER` is defined,\n * otherwise it will use the default LocalNet config unless it detects testnet or mainnet.\n * @returns An instance of the `AlgorandClient`.\n * @example\n * const client = AlgorandClient.fromEnvironment();\n */\n public static fromEnvironment() {\n return new AlgorandClient(ClientManager.getConfigFromEnvironmentOrLocalNet())\n }\n\n /**\n * Creates an `AlgorandClient` from the given config.\n * @param config The config to use.\n * @returns An instance of the `AlgorandClient`.\n * @example\n * const client = AlgorandClient.fromConfig({ algodConfig, indexerConfig, kmdConfig });\n */\n public static fromConfig(config: AlgoConfig) {\n return new AlgorandClient(config)\n }\n}\n"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OAAO,OAAO,GAAA;QACnB,OAAO,IAAI,cAAc,CAAC;YACxB,WAAW,EAAE,aAAa,CAAC,iBAAiB,CAAC,SAAS,EAAE,OAAO,CAAC;YAChE,aAAa,EAAE,aAAa,CAAC,iBAAiB,CAAC,SAAS,EAAE,SAAS,CAAC;AACpE,YAAA,SAAS,EAAE,SAAS;AACrB,SAAA,CAAC;;AAGJ;;;;;AAKG;AACI,IAAA,OAAO,OAAO,GAAA;QACnB,OAAO,IAAI,cAAc,CAAC;YACxB,WAAW,EAAE,aAAa,CAAC,iBAAiB,CAAC,SAAS,EAAE,OAAO,CAAC;YAChE,aAAa,EAAE,aAAa,CAAC,iBAAiB,CAAC,SAAS,EAAE,SAAS,CAAC;AACpE,YAAA,SAAS,EAAE,SAAS;AACrB,SAAA,CAAC;;AAGJ;;;;;;AAMG;IACI,OAAO,WAAW,CAAC,OAAuB,EAAA;AAC/C,QAAA,OAAO,IAAI,cAAc,CAAC,OAAO,CAAC;;AAGpC;;;;;;;;;;;;;;;;;;AAkBG;AACI,IAAA,OAAO,eAAe,GAAA;QAC3B,OAAO,IAAI,cAAc,CAAC,aAAa,CAAC,kCAAkC,EAAE,CAAC;;AAG/E;;;;;;AAMG;IACI,OAAO,UAAU,CAAC,MAAkB,EAAA;AACzC,QAAA,OAAO,IAAI,cAAc,CAAC,MAAM,CAAC;;AAEpC;;;;"}
|
package/types/amount.d.ts
CHANGED
|
@@ -9,6 +9,16 @@ export declare class AlgoAmount {
|
|
|
9
9
|
get algos(): number;
|
|
10
10
|
/** Return the amount as a number in Algo */
|
|
11
11
|
get algo(): number;
|
|
12
|
+
/**
|
|
13
|
+
* Create a new `AlgoAmount` instance.
|
|
14
|
+
*
|
|
15
|
+
* @param amount - An object specifying the amount in Algo or µALGO. Use the key 'algo' for Algo amounts and 'microAlgo' for µALGO.
|
|
16
|
+
* @returns A new instance of `AlgoAmount` representing the specified amount.
|
|
17
|
+
* @example
|
|
18
|
+
* ```typescript
|
|
19
|
+
* const amount = new AlgoAmount({ algo: 5 });
|
|
20
|
+
* ```
|
|
21
|
+
*/
|
|
12
22
|
constructor(amount: {
|
|
13
23
|
algos: number | bigint;
|
|
14
24
|
} | {
|
package/types/amount.js
CHANGED
|
@@ -20,6 +20,16 @@ class AlgoAmount {
|
|
|
20
20
|
get algo() {
|
|
21
21
|
return algosdk.microalgosToAlgos(Number(this.amountInMicroAlgo));
|
|
22
22
|
}
|
|
23
|
+
/**
|
|
24
|
+
* Create a new `AlgoAmount` instance.
|
|
25
|
+
*
|
|
26
|
+
* @param amount - An object specifying the amount in Algo or µALGO. Use the key 'algo' for Algo amounts and 'microAlgo' for µALGO.
|
|
27
|
+
* @returns A new instance of `AlgoAmount` representing the specified amount.
|
|
28
|
+
* @example
|
|
29
|
+
* ```typescript
|
|
30
|
+
* const amount = new AlgoAmount({ algo: 5 });
|
|
31
|
+
* ```
|
|
32
|
+
*/
|
|
23
33
|
constructor(amount) {
|
|
24
34
|
this.amountInMicroAlgo =
|
|
25
35
|
'microAlgos' in amount
|
package/types/amount.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"amount.js","sources":["../../src/types/amount.ts"],"sourcesContent":["import algosdk from 'algosdk'\n\n/** Wrapper class to ensure safe, explicit conversion between µAlgo, Algo and numbers */\nexport class AlgoAmount {\n private amountInMicroAlgo: bigint\n\n /** Return the amount as a number in µAlgo */\n get microAlgos() {\n return this.amountInMicroAlgo\n }\n\n /** Return the amount as a number in µAlgo */\n get microAlgo() {\n return this.amountInMicroAlgo\n }\n\n /** Return the amount as a number in Algo */\n get algos() {\n return algosdk.microalgosToAlgos(Number(this.amountInMicroAlgo))\n }\n\n /** Return the amount as a number in Algo */\n get algo() {\n return algosdk.microalgosToAlgos(Number(this.amountInMicroAlgo))\n }\n\n constructor(\n amount: { algos: number | bigint } | { algo: number | bigint } | { microAlgos: number | bigint } | { microAlgo: number | bigint },\n ) {\n this.amountInMicroAlgo =\n 'microAlgos' in amount\n ? BigInt(amount.microAlgos)\n : 'microAlgo' in amount\n ? BigInt(amount.microAlgo)\n : 'algos' in amount\n ? BigInt(algosdk.algosToMicroalgos(Number(amount.algos)))\n : BigInt(algosdk.algosToMicroalgos(Number(amount.algo)))\n }\n\n toString(): string {\n return `${this.microAlgo.toLocaleString('en-US')} µALGO`\n }\n\n /** valueOf allows you to use `AlgoAmount` in comparison operations such as `<` and `>=` etc.,\n * but it's not recommended to use this to convert to a number, it's much safer to explicitly call\n * the algos or microAlgos properties\n */\n valueOf(): number {\n return Number(this.microAlgo)\n }\n\n /** Create a `AlgoAmount` object representing the given number of Algo */\n static Algos(amount: number | bigint) {\n return new AlgoAmount({ algos: amount })\n }\n\n /** Create a `AlgoAmount` object representing the given number of Algo */\n static Algo(amount: number | bigint) {\n return new AlgoAmount({ algos: amount })\n }\n\n /** Create a `AlgoAmount` object representing the given number of µAlgo */\n static MicroAlgos(amount: number | bigint) {\n return new AlgoAmount({ microAlgos: amount })\n }\n\n /** Create a `AlgoAmount` object representing the given number of µAlgo */\n static MicroAlgo(amount: number | bigint) {\n return new AlgoAmount({ microAlgos: amount })\n }\n}\n"],"names":[],"mappings":";;;;AAEA;MACa,UAAU,CAAA;;AAIrB,IAAA,IAAI,UAAU,GAAA;QACZ,OAAO,IAAI,CAAC,iBAAiB;;;AAI/B,IAAA,IAAI,SAAS,GAAA;QACX,OAAO,IAAI,CAAC,iBAAiB;;;AAI/B,IAAA,IAAI,KAAK,GAAA;QACP,OAAO,OAAO,CAAC,iBAAiB,CAAC,MAAM,CAAC,IAAI,CAAC,iBAAiB,CAAC,CAAC;;;AAIlE,IAAA,IAAI,IAAI,GAAA;QACN,OAAO,OAAO,CAAC,iBAAiB,CAAC,MAAM,CAAC,IAAI,CAAC,iBAAiB,CAAC,CAAC;;AAGlE,IAAA,WAAA,CACE,MAAiI,EAAA;AAEjI,QAAA,IAAI,CAAC,iBAAiB;AACpB,YAAA,YAAY,IAAI;AACd,kBAAE,MAAM,CAAC,MAAM,CAAC,UAAU;kBACxB,WAAW,IAAI;AACf,sBAAE,MAAM,CAAC,MAAM,CAAC,SAAS;sBACvB,OAAO,IAAI;AACX,0BAAE,MAAM,CAAC,OAAO,CAAC,iBAAiB,CAAC,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;AACxD,0BAAE,MAAM,CAAC,OAAO,CAAC,iBAAiB,CAAC,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC;;IAGlE,QAAQ,GAAA;QACN,OAAO,CAAA,EAAG,IAAI,CAAC,SAAS,CAAC,cAAc,CAAC,OAAO,CAAC,CAAA,MAAA,CAAQ;;AAG1D;;;AAGG;IACH,OAAO,GAAA;AACL,QAAA,OAAO,MAAM,CAAC,IAAI,CAAC,SAAS,CAAC;;;IAI/B,OAAO,KAAK,CAAC,MAAuB,EAAA;QAClC,OAAO,IAAI,UAAU,CAAC,EAAE,KAAK,EAAE,MAAM,EAAE,CAAC;;;IAI1C,OAAO,IAAI,CAAC,MAAuB,EAAA;QACjC,OAAO,IAAI,UAAU,CAAC,EAAE,KAAK,EAAE,MAAM,EAAE,CAAC;;;IAI1C,OAAO,UAAU,CAAC,MAAuB,EAAA;QACvC,OAAO,IAAI,UAAU,CAAC,EAAE,UAAU,EAAE,MAAM,EAAE,CAAC;;;IAI/C,OAAO,SAAS,CAAC,MAAuB,EAAA;QACtC,OAAO,IAAI,UAAU,CAAC,EAAE,UAAU,EAAE,MAAM,EAAE,CAAC;;AAEhD;;;;"}
|
|
1
|
+
{"version":3,"file":"amount.js","sources":["../../src/types/amount.ts"],"sourcesContent":["import algosdk from 'algosdk'\n\n/** Wrapper class to ensure safe, explicit conversion between µAlgo, Algo and numbers */\nexport class AlgoAmount {\n private amountInMicroAlgo: bigint\n\n /** Return the amount as a number in µAlgo */\n get microAlgos() {\n return this.amountInMicroAlgo\n }\n\n /** Return the amount as a number in µAlgo */\n get microAlgo() {\n return this.amountInMicroAlgo\n }\n\n /** Return the amount as a number in Algo */\n get algos() {\n return algosdk.microalgosToAlgos(Number(this.amountInMicroAlgo))\n }\n\n /** Return the amount as a number in Algo */\n get algo() {\n return algosdk.microalgosToAlgos(Number(this.amountInMicroAlgo))\n }\n\n /**\n * Create a new `AlgoAmount` instance.\n *\n * @param amount - An object specifying the amount in Algo or µALGO. Use the key 'algo' for Algo amounts and 'microAlgo' for µALGO.\n * @returns A new instance of `AlgoAmount` representing the specified amount.\n * @example\n * ```typescript\n * const amount = new AlgoAmount({ algo: 5 });\n * ```\n */\n constructor(\n amount: { algos: number | bigint } | { algo: number | bigint } | { microAlgos: number | bigint } | { microAlgo: number | bigint },\n ) {\n this.amountInMicroAlgo =\n 'microAlgos' in amount\n ? BigInt(amount.microAlgos)\n : 'microAlgo' in amount\n ? BigInt(amount.microAlgo)\n : 'algos' in amount\n ? BigInt(algosdk.algosToMicroalgos(Number(amount.algos)))\n : BigInt(algosdk.algosToMicroalgos(Number(amount.algo)))\n }\n\n toString(): string {\n return `${this.microAlgo.toLocaleString('en-US')} µALGO`\n }\n\n /** valueOf allows you to use `AlgoAmount` in comparison operations such as `<` and `>=` etc.,\n * but it's not recommended to use this to convert to a number, it's much safer to explicitly call\n * the algos or microAlgos properties\n */\n valueOf(): number {\n return Number(this.microAlgo)\n }\n\n /** Create a `AlgoAmount` object representing the given number of Algo */\n static Algos(amount: number | bigint) {\n return new AlgoAmount({ algos: amount })\n }\n\n /** Create a `AlgoAmount` object representing the given number of Algo */\n static Algo(amount: number | bigint) {\n return new AlgoAmount({ algos: amount })\n }\n\n /** Create a `AlgoAmount` object representing the given number of µAlgo */\n static MicroAlgos(amount: number | bigint) {\n return new AlgoAmount({ microAlgos: amount })\n }\n\n /** Create a `AlgoAmount` object representing the given number of µAlgo */\n static MicroAlgo(amount: number | bigint) {\n return new AlgoAmount({ microAlgos: amount })\n }\n}\n"],"names":[],"mappings":";;;;AAEA;MACa,UAAU,CAAA;;AAIrB,IAAA,IAAI,UAAU,GAAA;QACZ,OAAO,IAAI,CAAC,iB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E,MAAM,EAAE,CAAC;;;IAI/C,OAAO,SAAS,CAAC,MAAuB,EAAA;QACtC,OAAO,IAAI,UAAU,CAAC,EAAE,UAAU,EAAE,MAAM,EAAE,CAAC;;AAEhD;;;;"}
|
package/types/amount.mjs
CHANGED
|
@@ -18,6 +18,16 @@ class AlgoAmount {
|
|
|
18
18
|
get algo() {
|
|
19
19
|
return algosdk.microalgosToAlgos(Number(this.amountInMicroAlgo));
|
|
20
20
|
}
|
|
21
|
+
/**
|
|
22
|
+
* Create a new `AlgoAmount` instance.
|
|
23
|
+
*
|
|
24
|
+
* @param amount - An object specifying the amount in Algo or µALGO. Use the key 'algo' for Algo amounts and 'microAlgo' for µALGO.
|
|
25
|
+
* @returns A new instance of `AlgoAmount` representing the specified amount.
|
|
26
|
+
* @example
|
|
27
|
+
* ```typescript
|
|
28
|
+
* const amount = new AlgoAmount({ algo: 5 });
|
|
29
|
+
* ```
|
|
30
|
+
*/
|
|
21
31
|
constructor(amount) {
|
|
22
32
|
this.amountInMicroAlgo =
|
|
23
33
|
'microAlgos' in amount
|
package/types/amount.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"amount.mjs","sources":["../../src/types/amount.ts"],"sourcesContent":["import algosdk from 'algosdk'\n\n/** Wrapper class to ensure safe, explicit conversion between µAlgo, Algo and numbers */\nexport class AlgoAmount {\n private amountInMicroAlgo: bigint\n\n /** Return the amount as a number in µAlgo */\n get microAlgos() {\n return this.amountInMicroAlgo\n }\n\n /** Return the amount as a number in µAlgo */\n get microAlgo() {\n return this.amountInMicroAlgo\n }\n\n /** Return the amount as a number in Algo */\n get algos() {\n return algosdk.microalgosToAlgos(Number(this.amountInMicroAlgo))\n }\n\n /** Return the amount as a number in Algo */\n get algo() {\n return algosdk.microalgosToAlgos(Number(this.amountInMicroAlgo))\n }\n\n constructor(\n amount: { algos: number | bigint } | { algo: number | bigint } | { microAlgos: number | bigint } | { microAlgo: number | bigint },\n ) {\n this.amountInMicroAlgo =\n 'microAlgos' in amount\n ? BigInt(amount.microAlgos)\n : 'microAlgo' in amount\n ? BigInt(amount.microAlgo)\n : 'algos' in amount\n ? BigInt(algosdk.algosToMicroalgos(Number(amount.algos)))\n : BigInt(algosdk.algosToMicroalgos(Number(amount.algo)))\n }\n\n toString(): string {\n return `${this.microAlgo.toLocaleString('en-US')} µALGO`\n }\n\n /** valueOf allows you to use `AlgoAmount` in comparison operations such as `<` and `>=` etc.,\n * but it's not recommended to use this to convert to a number, it's much safer to explicitly call\n * the algos or microAlgos properties\n */\n valueOf(): number {\n return Number(this.microAlgo)\n }\n\n /** Create a `AlgoAmount` object representing the given number of Algo */\n static Algos(amount: number | bigint) {\n return new AlgoAmount({ algos: amount })\n }\n\n /** Create a `AlgoAmount` object representing the given number of Algo */\n static Algo(amount: number | bigint) {\n return new AlgoAmount({ algos: amount })\n }\n\n /** Create a `AlgoAmount` object representing the given number of µAlgo */\n static MicroAlgos(amount: number | bigint) {\n return new AlgoAmount({ microAlgos: amount })\n }\n\n /** Create a `AlgoAmount` object representing the given number of µAlgo */\n static MicroAlgo(amount: number | bigint) {\n return new AlgoAmount({ microAlgos: amount })\n }\n}\n"],"names":[],"mappings":";;AAEA;MACa,UAAU,CAAA;;AAIrB,IAAA,IAAI,UAAU,GAAA;QACZ,OAAO,IAAI,CAAC,iBAAiB;;;AAI/B,IAAA,IAAI,SAAS,GAAA;QACX,OAAO,IAAI,CAAC,iBAAiB;;;AAI/B,IAAA,IAAI,KAAK,GAAA;QACP,OAAO,OAAO,CAAC,iBAAiB,CAAC,MAAM,CAAC,IAAI,CAAC,iBAAiB,CAAC,CAAC;;;AAIlE,IAAA,IAAI,IAAI,GAAA;QACN,OAAO,OAAO,CAAC,iBAAiB,CAAC,MAAM,CAAC,IAAI,CAAC,iBAAiB,CAAC,CAAC;;AAGlE,IAAA,WAAA,CACE,MAAiI,EAAA;AAEjI,QAAA,IAAI,CAAC,iBAAiB;AACpB,YAAA,YAAY,IAAI;AACd,kBAAE,MAAM,CAAC,MAAM,CAAC,UAAU;kBACxB,WAAW,IAAI;AACf,sBAAE,MAAM,CAAC,MAAM,CAAC,SAAS;sBACvB,OAAO,IAAI;AACX,0BAAE,MAAM,CAAC,OAAO,CAAC,iBAAiB,CAAC,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;AACxD,0BAAE,MAAM,CAAC,OAAO,CAAC,iBAAiB,CAAC,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC;;IAGlE,QAAQ,GAAA;QACN,OAAO,CAAA,EAAG,IAAI,CAAC,SAAS,CAAC,cAAc,CAAC,OAAO,CAAC,CAAA,MAAA,CAAQ;;AAG1D;;;AAGG;IACH,OAAO,GAAA;AACL,QAAA,OAAO,MAAM,CAAC,IAAI,CAAC,SAAS,CAAC;;;IAI/B,OAAO,KAAK,CAAC,MAAuB,EAAA;QAClC,OAAO,IAAI,UAAU,CAAC,EAAE,KAAK,EAAE,MAAM,EAAE,CAAC;;;IAI1C,OAAO,IAAI,CAAC,MAAuB,EAAA;QACjC,OAAO,IAAI,UAAU,CAAC,EAAE,KAAK,EAAE,MAAM,EAAE,CAAC;;;IAI1C,OAAO,UAAU,CAAC,MAAuB,EAAA;QACvC,OAAO,IAAI,UAAU,CAAC,EAAE,UAAU,EAAE,MAAM,EAAE,CAAC;;;IAI/C,OAAO,SAAS,CAAC,MAAuB,EAAA;QACtC,OAAO,IAAI,UAAU,CAAC,EAAE,UAAU,EAAE,MAAM,EAAE,CAAC;;AAEhD;;;;"}
|
|
1
|
+
{"version":3,"file":"amount.mjs","sources":["../../src/types/amount.ts"],"sourcesContent":["import algosdk from 'algosdk'\n\n/** Wrapper class to ensure safe, explicit conversion between µAlgo, Algo and numbers */\nexport class AlgoAmount {\n private amountInMicroAlgo: bigint\n\n /** Return the amount as a number in µAlgo */\n get microAlgos() {\n return this.amountInMicroAlgo\n }\n\n /** Return the amount as a number in µAlgo */\n get microAlgo() {\n return this.amountInMicroAlgo\n }\n\n /** Return the amount as a number in Algo */\n get algos() {\n return algosdk.microalgosToAlgos(Number(this.amountInMicroAlgo))\n }\n\n /** Return the amount as a number in Algo */\n get algo() {\n return algosdk.microalgosToAlgos(Number(this.amountInMicroAlgo))\n }\n\n /**\n * Create a new `AlgoAmount` instance.\n *\n * @param amount - An object specifying the amount in Algo or µALGO. Use the key 'algo' for Algo amounts and 'microAlgo' for µALGO.\n * @returns A new instance of `AlgoAmount` representing the specified amount.\n * @example\n * ```typescript\n * const amount = new AlgoAmount({ algo: 5 });\n * ```\n */\n constructor(\n amount: { algos: number | bigint } | { algo: number | bigint } | { microAlgos: number | bigint } | { microAlgo: number | bigint },\n ) {\n this.amountInMicroAlgo =\n 'microAlgos' in amount\n ? BigInt(amount.microAlgos)\n : 'microAlgo' in amount\n ? BigInt(amount.microAlgo)\n : 'algos' in amount\n ? BigInt(algosdk.algosToMicroalgos(Number(amount.algos)))\n : BigInt(algosdk.algosToMicroalgos(Number(amount.algo)))\n }\n\n toString(): string {\n return `${this.microAlgo.toLocaleString('en-US')} µALGO`\n }\n\n /** valueOf allows you to use `AlgoAmount` in comparison operations such as `<` and `>=` etc.,\n * but it's not recommended to use this to convert to a number, it's much safer to explicitly call\n * the algos or microAlgos properties\n */\n valueOf(): number {\n return Number(this.microAlgo)\n }\n\n /** Create a `AlgoAmount` object representing the given number of Algo */\n static Algos(amount: number | bigint) {\n return new AlgoAmount({ algos: amount })\n }\n\n /** Create a `AlgoAmount` object representing the given number of Algo */\n static Algo(amount: number | bigint) {\n return new AlgoAmount({ algos: amount })\n }\n\n /** Create a `AlgoAmount` object representing the given number of µAlgo */\n static MicroAlgos(amount: number | bigint) {\n return new AlgoAmount({ microAlgos: amount })\n }\n\n /** Create a `AlgoAmount` object representing the given number of µAlgo */\n static MicroAlgo(amount: number | bigint) {\n return new AlgoAmount({ microAlgos: amount })\n }\n}\n"],"names":[],"mappings":";;AAEA;MACa,UAAU,CAAA;;AAIrB,IAAA,IAAI,UAAU,GAA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