@algorandfoundation/algokit-utils 7.0.0-beta.9 → 8.0.0-beta.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +21 -3
- package/account/account.d.ts +4 -1
- package/account/account.js +10 -7
- package/account/account.js.map +1 -1
- package/account/account.mjs +11 -8
- package/account/account.mjs.map +1 -1
- package/account/get-account-config-from-environment.js.map +1 -1
- package/account/get-account-config-from-environment.mjs.map +1 -1
- package/account/get-account.js.map +1 -1
- package/account/get-account.mjs.map +1 -1
- package/account/get-dispenser-account.d.ts +1 -1
- package/account/get-dispenser-account.js.map +1 -1
- package/account/get-dispenser-account.mjs.map +1 -1
- package/account/mnemonic-account.js.map +1 -1
- package/account/mnemonic-account.mjs.map +1 -1
- package/amount.d.ts +1 -0
- package/amount.js +3 -2
- package/amount.js.map +1 -1
- package/amount.mjs +3 -3
- package/amount.mjs.map +1 -1
- package/app-client.d.ts +4 -4
- package/app-client.js +4 -4
- package/app-client.js.map +1 -1
- package/app-client.mjs +4 -4
- package/app-client.mjs.map +1 -1
- package/app-deploy.js +25 -15
- package/app-deploy.js.map +1 -1
- package/app-deploy.mjs +27 -17
- package/app-deploy.mjs.map +1 -1
- package/app.d.ts +2 -2
- package/app.js +9 -6
- package/app.js.map +1 -1
- package/app.mjs +9 -6
- package/app.mjs.map +1 -1
- package/asset.js.map +1 -1
- package/asset.mjs.map +1 -1
- package/debugging/debugging.js.map +1 -1
- package/debugging/debugging.mjs.map +1 -1
- package/dispenser-client.js.map +1 -1
- package/dispenser-client.mjs.map +1 -1
- package/index.d.ts +1 -0
- package/index.js +7 -1
- package/index.js.map +1 -1
- package/index.mjs +3 -2
- package/index.mjs.map +1 -1
- package/indexer-lookup.d.ts +10 -8
- package/indexer-lookup.js +14 -10
- package/indexer-lookup.js.map +1 -1
- package/indexer-lookup.mjs +14 -10
- package/indexer-lookup.mjs.map +1 -1
- package/localnet/get-kmd-wallet-account.js.map +1 -1
- package/localnet/get-kmd-wallet-account.mjs.map +1 -1
- package/localnet/get-localnet-dispenser-account.js.map +1 -1
- package/localnet/get-localnet-dispenser-account.mjs.map +1 -1
- package/localnet/get-or-create-kmd-wallet-account.js.map +1 -1
- package/localnet/get-or-create-kmd-wallet-account.mjs.map +1 -1
- package/localnet/is-localnet.js.map +1 -1
- package/localnet/is-localnet.mjs.map +1 -1
- package/network-client.d.ts +1 -7
- package/network-client.js +2 -9
- package/network-client.js.map +1 -1
- package/network-client.mjs +2 -9
- package/network-client.mjs.map +1 -1
- package/package.json +5 -5
- package/testing/_asset.d.ts +2 -1
- package/testing/account.d.ts +4 -3
- package/testing/account.js +8 -2
- package/testing/account.js.map +1 -1
- package/testing/account.mjs +9 -3
- package/testing/account.mjs.map +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.js +5 -6
- package/testing/fixtures/algorand-fixture.js.map +1 -1
- package/testing/fixtures/algorand-fixture.mjs +5 -6
- package/testing/fixtures/algorand-fixture.mjs.map +1 -1
- package/testing/indexer.js.map +1 -1
- package/testing/indexer.mjs.map +1 -1
- package/testing/test-logger.js +7 -1
- package/testing/test-logger.js.map +1 -1
- package/testing/test-logger.mjs +7 -1
- package/testing/test-logger.mjs.map +1 -1
- package/testing/transaction-logger.js.map +1 -1
- package/testing/transaction-logger.mjs.map +1 -1
- package/transaction/legacy-bridge.js +2 -2
- package/transaction/legacy-bridge.js.map +1 -1
- package/transaction/legacy-bridge.mjs +3 -3
- package/transaction/legacy-bridge.mjs.map +1 -1
- package/transaction/perform-atomic-transaction-composer-simulate.d.ts +4 -1
- package/transaction/perform-atomic-transaction-composer-simulate.js +14 -9
- package/transaction/perform-atomic-transaction-composer-simulate.js.map +1 -1
- package/transaction/perform-atomic-transaction-composer-simulate.mjs +15 -10
- package/transaction/perform-atomic-transaction-composer-simulate.mjs.map +1 -1
- package/transaction/transaction.d.ts +13 -22
- package/transaction/transaction.js +164 -110
- package/transaction/transaction.js.map +1 -1
- package/transaction/transaction.mjs +163 -109
- package/transaction/transaction.mjs.map +1 -1
- package/transfer/transfer-algos.js.map +1 -1
- package/transfer/transfer-algos.mjs.map +1 -1
- package/transfer/transfer.js +3 -1
- package/transfer/transfer.js.map +1 -1
- package/transfer/transfer.mjs +3 -1
- package/transfer/transfer.mjs.map +1 -1
- package/types/account-manager.d.ts +20 -20
- package/types/account-manager.js +36 -27
- package/types/account-manager.js.map +1 -1
- package/types/account-manager.mjs +38 -29
- package/types/account-manager.mjs.map +1 -1
- package/types/account.d.ts +17 -8
- package/types/account.js +2 -2
- package/types/account.js.map +1 -1
- package/types/account.mjs +3 -3
- package/types/account.mjs.map +1 -1
- package/types/algo-http-client-with-retry.d.ts +1 -2
- package/types/algo-http-client-with-retry.js +33 -3
- package/types/algo-http-client-with-retry.js.map +1 -1
- package/types/algo-http-client-with-retry.mjs +32 -2
- package/types/algo-http-client-with-retry.mjs.map +1 -1
- package/types/algorand-client-interface.d.ts +2 -2
- package/types/algorand-client-transaction-creator.d.ts +16 -14
- package/types/algorand-client-transaction-creator.js +3 -1
- package/types/algorand-client-transaction-creator.js.map +1 -1
- package/types/algorand-client-transaction-creator.mjs +3 -1
- package/types/algorand-client-transaction-creator.mjs.map +1 -1
- package/types/algorand-client-transaction-sender.d.ts +109 -105
- package/types/algorand-client-transaction-sender.js +6 -2
- package/types/algorand-client-transaction-sender.js.map +1 -1
- package/types/algorand-client-transaction-sender.mjs +6 -2
- package/types/algorand-client-transaction-sender.mjs.map +1 -1
- package/types/algorand-client.d.ts +6 -7
- package/types/algorand-client.js +3 -6
- package/types/algorand-client.js.map +1 -1
- package/types/algorand-client.mjs +5 -5
- package/types/algorand-client.mjs.map +1 -1
- package/types/amount.js.map +1 -1
- package/types/amount.mjs.map +1 -1
- package/types/app-arc56.d.ts +31 -20
- package/types/app-arc56.js.map +1 -1
- package/types/app-arc56.mjs.map +1 -1
- package/types/app-client.d.ts +298 -286
- package/types/app-client.js +148 -41
- package/types/app-client.js.map +1 -1
- package/types/app-client.mjs +147 -40
- package/types/app-client.mjs.map +1 -1
- package/types/app-deployer.d.ts +4 -4
- package/types/app-deployer.js +23 -24
- package/types/app-deployer.js.map +1 -1
- package/types/app-deployer.mjs +25 -26
- package/types/app-deployer.mjs.map +1 -1
- package/types/app-factory.d.ts +130 -130
- package/types/app-factory.js +4 -5
- package/types/app-factory.js.map +1 -1
- package/types/app-factory.mjs +5 -6
- package/types/app-factory.mjs.map +1 -1
- package/types/app-manager.d.ts +5 -5
- package/types/app-manager.js +116 -38
- package/types/app-manager.js.map +1 -1
- package/types/app-manager.mjs +117 -39
- package/types/app-manager.mjs.map +1 -1
- package/types/app-spec.js +8 -2
- package/types/app-spec.js.map +1 -1
- package/types/app-spec.mjs +8 -2
- package/types/app-spec.mjs.map +1 -1
- package/types/app.d.ts +12 -11
- package/types/app.js.map +1 -1
- package/types/app.mjs.map +1 -1
- package/types/asset-manager.d.ts +9 -9
- package/types/asset-manager.js +10 -13
- package/types/asset-manager.js.map +1 -1
- package/types/asset-manager.mjs +10 -13
- package/types/asset-manager.mjs.map +1 -1
- package/types/async-event-emitter.d.ts +1 -10
- package/types/async-event-emitter.js +0 -5
- package/types/async-event-emitter.js.map +1 -1
- package/types/async-event-emitter.mjs +1 -6
- package/types/async-event-emitter.mjs.map +1 -1
- package/types/client-manager.d.ts +2 -9
- package/types/client-manager.js +11 -21
- package/types/client-manager.js.map +1 -1
- package/types/client-manager.mjs +11 -21
- package/types/client-manager.mjs.map +1 -1
- package/types/composer.d.ts +58 -46
- package/types/composer.js +154 -105
- package/types/composer.js.map +1 -1
- package/types/composer.mjs +156 -105
- package/types/composer.mjs.map +1 -1
- package/types/config.js.map +1 -1
- package/types/config.mjs.map +1 -1
- package/types/debugging.d.ts +1 -1
- package/types/debugging.js +1 -1
- package/types/debugging.js.map +1 -1
- package/types/debugging.mjs +1 -1
- package/types/debugging.mjs.map +1 -1
- package/types/dispenser-client.d.ts +2 -1
- package/types/dispenser-client.js +5 -1
- package/types/dispenser-client.js.map +1 -1
- package/types/dispenser-client.mjs +5 -1
- package/types/dispenser-client.mjs.map +1 -1
- package/types/indexer.d.ts +74 -755
- package/types/indexer.js.map +1 -1
- package/types/indexer.mjs.map +1 -1
- package/types/kmd-account-manager.d.ts +2 -2
- package/types/kmd-account-manager.js +1 -1
- package/types/kmd-account-manager.js.map +1 -1
- package/types/kmd-account-manager.mjs +2 -2
- package/types/kmd-account-manager.mjs.map +1 -1
- package/types/lifecycle-events.d.ts +10 -0
- package/types/lifecycle-events.js +8 -0
- package/types/lifecycle-events.js.map +1 -0
- package/types/lifecycle-events.mjs +8 -0
- package/types/lifecycle-events.mjs.map +1 -0
- package/types/logging.js.map +1 -1
- package/types/logging.mjs.map +1 -1
- package/types/logic-error.d.ts +2 -3
- package/types/logic-error.js +3 -3
- package/types/logic-error.js.map +1 -1
- package/types/logic-error.mjs +3 -3
- package/types/logic-error.mjs.map +1 -1
- package/types/network-client.d.ts +1 -1
- package/types/network-client.js.map +1 -1
- package/types/network-client.mjs.map +1 -1
- package/types/testing.d.ts +6 -7
- package/util.js.map +1 -1
- package/util.mjs.map +1 -1
- package/types/urlTokenBaseHTTPClient.d.ts +0 -40
- package/types/urlTokenBaseHTTPClient.js +0 -153
- package/types/urlTokenBaseHTTPClient.js.map +0 -1
- package/types/urlTokenBaseHTTPClient.mjs +0 -151
- package/types/urlTokenBaseHTTPClient.mjs.map +0 -1
|
@@ -3,17 +3,16 @@
|
|
|
3
3
|
var algosdk = require('algosdk');
|
|
4
4
|
var buffer = require('buffer');
|
|
5
5
|
var config = require('../config.js');
|
|
6
|
-
var
|
|
6
|
+
var types_lifecycleEvents = require('../types/lifecycle-events.js');
|
|
7
7
|
var util = require('../util.js');
|
|
8
8
|
var performAtomicTransactionComposerSimulate = require('./perform-atomic-transaction-composer-simulate.js');
|
|
9
9
|
|
|
10
10
|
var AtomicTransactionComposer = algosdk.AtomicTransactionComposer;
|
|
11
|
-
var modelsv2 = algosdk.modelsv2;
|
|
12
11
|
const MAX_TRANSACTION_GROUP_SIZE = 16;
|
|
13
12
|
const MAX_APP_CALL_FOREIGN_REFERENCES = 8;
|
|
14
13
|
const MAX_APP_CALL_ACCOUNT_REFERENCES = 4;
|
|
15
14
|
/**
|
|
16
|
-
* @deprecated Convert your data to a `string` or `Uint8Array`, if using ARC-2 use `
|
|
15
|
+
* @deprecated Convert your data to a `string` or `Uint8Array`, if using ARC-2 use `TransactionComposer.arc2Note`.
|
|
17
16
|
*
|
|
18
17
|
* Encodes a transaction note into a byte array ready to be included in an Algorand transaction.
|
|
19
18
|
*
|
|
@@ -89,10 +88,10 @@ function encodeLease(lease) {
|
|
|
89
88
|
* @returns The public address
|
|
90
89
|
*/
|
|
91
90
|
const getSenderAddress = function (sender) {
|
|
92
|
-
return typeof sender === 'string' ? sender : 'addr' in sender ? sender.addr : sender.address();
|
|
91
|
+
return typeof sender === 'string' ? sender : 'addr' in sender ? sender.addr.toString() : sender.address().toString();
|
|
93
92
|
};
|
|
94
93
|
/**
|
|
95
|
-
* @deprecated Use `AlgorandClient` / `
|
|
94
|
+
* @deprecated Use `AlgorandClient` / `TransactionComposer` to construct transactions instead or
|
|
96
95
|
* construct an `algosdk.TransactionWithSigner` manually instead.
|
|
97
96
|
*
|
|
98
97
|
* Given a transaction in a variety of supported formats, returns a TransactionWithSigner object ready to be passed to an
|
|
@@ -149,7 +148,7 @@ const getSenderTransactionSigner = memoize(function (sender) {
|
|
|
149
148
|
: algosdk.makeBasicAccountTransactionSigner(sender);
|
|
150
149
|
});
|
|
151
150
|
/**
|
|
152
|
-
* @deprecated Use `AlgorandClient` / `
|
|
151
|
+
* @deprecated Use `AlgorandClient` / `TransactionComposer` to sign transactions
|
|
153
152
|
* or use the relevant underlying `account.signTxn` / `algosdk.signLogicSigTransactionObject`
|
|
154
153
|
* / `multiSigAccount.sign` / `TransactionSigner` methods directly.
|
|
155
154
|
*
|
|
@@ -168,7 +167,7 @@ const signTransaction = async (transaction, signer) => {
|
|
|
168
167
|
: (await signer.signer([transaction], [0]))[0];
|
|
169
168
|
};
|
|
170
169
|
/**
|
|
171
|
-
* @deprecated Use `AlgorandClient` / `
|
|
170
|
+
* @deprecated Use `AlgorandClient` / `TransactionComposer` to send transactions.
|
|
172
171
|
*
|
|
173
172
|
* Prepares a transaction for sending and then (if instructed) signs and sends the given transaction to the chain.
|
|
174
173
|
*
|
|
@@ -218,29 +217,18 @@ const sendTransaction = async function (send, algod) {
|
|
|
218
217
|
* @returns The unnamed resources accessed by the group and by each transaction in the group
|
|
219
218
|
*/
|
|
220
219
|
async function getUnnamedAppCallResourcesAccessed(atc, algod) {
|
|
221
|
-
const
|
|
220
|
+
const simulateRequest = new algosdk.modelsv2.SimulateRequest({
|
|
222
221
|
txnGroups: [],
|
|
223
222
|
allowUnnamedResources: true,
|
|
224
223
|
allowEmptySignatures: true,
|
|
224
|
+
fixSigners: true,
|
|
225
225
|
});
|
|
226
|
-
const
|
|
227
|
-
const stxns = await algosdk.makeEmptyTransactionSigner()(txns, indexes);
|
|
228
|
-
return Promise.all(stxns.map(async (stxn) => {
|
|
229
|
-
const decodedStxn = algosdk.decodeSignedTransaction(stxn);
|
|
230
|
-
const sender = algosdk.encodeAddress(decodedStxn.txn.from.publicKey);
|
|
231
|
-
const authAddr = (await algod.accountInformation(sender).do())['auth-addr'];
|
|
232
|
-
const stxnObj = { txn: decodedStxn.txn.get_obj_for_encoding() };
|
|
233
|
-
if (authAddr !== undefined) {
|
|
234
|
-
stxnObj.sgnr = buffer.Buffer.from(algosdk.decodeAddress(authAddr).publicKey);
|
|
235
|
-
}
|
|
236
|
-
return algosdk.encodeObj(stxnObj);
|
|
237
|
-
}));
|
|
238
|
-
};
|
|
226
|
+
const nullSigner = algosdk.makeEmptyTransactionSigner();
|
|
239
227
|
const emptySignerAtc = atc.clone();
|
|
240
228
|
emptySignerAtc['transactions'].forEach((t) => {
|
|
241
|
-
t.signer =
|
|
229
|
+
t.signer = nullSigner;
|
|
242
230
|
});
|
|
243
|
-
const result = await emptySignerAtc.simulate(algod,
|
|
231
|
+
const result = await emptySignerAtc.simulate(algod, simulateRequest);
|
|
244
232
|
const groupResponse = result.simulateResponse.txnGroups[0];
|
|
245
233
|
if (groupResponse.failureMessage) {
|
|
246
234
|
throw Error(`Error during resource population simulation in transaction ${groupResponse.failedAt}: ${groupResponse.failureMessage}`);
|
|
@@ -273,7 +261,7 @@ async function populateAppCallResources(atc, algod) {
|
|
|
273
261
|
const unnamedResourcesAccessed = await getUnnamedAppCallResourcesAccessed(atc, algod);
|
|
274
262
|
const group = atc.buildGroup();
|
|
275
263
|
unnamedResourcesAccessed.txns.forEach((r, i) => {
|
|
276
|
-
if (r === undefined)
|
|
264
|
+
if (r === undefined || group[i].txn.type !== algosdk.TransactionType.appl)
|
|
277
265
|
return;
|
|
278
266
|
if (r.boxes || r.extraBoxRefs)
|
|
279
267
|
throw Error('Unexpected boxes at the transaction level');
|
|
@@ -281,22 +269,19 @@ async function populateAppCallResources(atc, algod) {
|
|
|
281
269
|
throw Error('Unexpected app local at the transaction level');
|
|
282
270
|
if (r.assetHoldings)
|
|
283
271
|
throw Error('Unexpected asset holding at the transaction level');
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
}
|
|
291
|
-
|
|
292
|
-
group[i].txn.appForeignAssets = [...(group[i].txn.appForeignAssets ?? []), Number(a)];
|
|
293
|
-
});
|
|
294
|
-
const accounts = group[i].txn.appAccounts?.length || 0;
|
|
272
|
+
group[i].txn['applicationCall'] = {
|
|
273
|
+
...group[i].txn.applicationCall,
|
|
274
|
+
accounts: [...(group[i].txn?.applicationCall?.accounts ?? []), ...(r.accounts ?? [])],
|
|
275
|
+
foreignApps: [...(group[i].txn?.applicationCall?.foreignApps ?? []), ...(r.apps ?? [])],
|
|
276
|
+
foreignAssets: [...(group[i].txn?.applicationCall?.foreignAssets ?? []), ...(r.assets ?? [])],
|
|
277
|
+
boxes: [...(group[i].txn?.applicationCall?.boxes ?? []), ...(r.boxes ?? [])],
|
|
278
|
+
};
|
|
279
|
+
const accounts = group[i].txn.applicationCall?.accounts?.length ?? 0;
|
|
295
280
|
if (accounts > MAX_APP_CALL_ACCOUNT_REFERENCES)
|
|
296
281
|
throw Error(`Account reference limit of ${MAX_APP_CALL_ACCOUNT_REFERENCES} exceeded in transaction ${i}`);
|
|
297
|
-
const assets = group[i].txn.
|
|
298
|
-
const apps = group[i].txn.
|
|
299
|
-
const boxes = group[i].txn.boxes?.length
|
|
282
|
+
const assets = group[i].txn.applicationCall?.foreignAssets?.length ?? 0;
|
|
283
|
+
const apps = group[i].txn.applicationCall?.foreignApps?.length ?? 0;
|
|
284
|
+
const boxes = group[i].txn.applicationCall?.boxes?.length ?? 0;
|
|
300
285
|
if (accounts + assets + apps + boxes > MAX_APP_CALL_FOREIGN_REFERENCES) {
|
|
301
286
|
throw Error(`Resource reference limit of ${MAX_APP_CALL_FOREIGN_REFERENCES} exceeded in transaction ${i}`);
|
|
302
287
|
}
|
|
@@ -305,10 +290,10 @@ async function populateAppCallResources(atc, algod) {
|
|
|
305
290
|
const isApplBelowLimit = (t) => {
|
|
306
291
|
if (t.txn.type !== algosdk.TransactionType.appl)
|
|
307
292
|
return false;
|
|
308
|
-
const accounts = t.txn.
|
|
309
|
-
const assets = t.txn.
|
|
310
|
-
const apps = t.txn.
|
|
311
|
-
const boxes = t.txn.boxes?.length
|
|
293
|
+
const accounts = t.txn.applicationCall?.accounts?.length ?? 0;
|
|
294
|
+
const assets = t.txn.applicationCall?.foreignAssets?.length ?? 0;
|
|
295
|
+
const apps = t.txn.applicationCall?.foreignApps?.length ?? 0;
|
|
296
|
+
const boxes = t.txn.applicationCall?.boxes?.length ?? 0;
|
|
312
297
|
return accounts + assets + apps + boxes < MAX_APP_CALL_FOREIGN_REFERENCES;
|
|
313
298
|
};
|
|
314
299
|
// If this is a asset holding or app local, first try to find a transaction that already has the account available
|
|
@@ -319,22 +304,26 @@ async function populateAppCallResources(atc, algod) {
|
|
|
319
304
|
return false;
|
|
320
305
|
return (
|
|
321
306
|
// account is in the foreign accounts array
|
|
322
|
-
t.txn.
|
|
307
|
+
t.txn.applicationCall?.accounts?.map((a) => a.toString()).includes(account.toString()) ||
|
|
323
308
|
// account is available as an app account
|
|
324
|
-
t.txn.
|
|
309
|
+
t.txn.applicationCall?.foreignApps?.map((a) => algosdk.getApplicationAddress(a).toString()).includes(account.toString()) ||
|
|
325
310
|
// account is available since it's in one of the fields
|
|
326
|
-
Object.values(t.txn)
|
|
327
|
-
.map((f) => JSON.stringify(f))
|
|
328
|
-
.includes(JSON.stringify(algosdk.decodeAddress(account))));
|
|
311
|
+
Object.values(t.txn).some((f) => algosdk.stringifyJSON(f, (_, v) => (v instanceof algosdk.Address ? v.toString() : v))?.includes(account.toString())));
|
|
329
312
|
});
|
|
330
313
|
if (txnIndex > -1) {
|
|
331
314
|
if (type === 'assetHolding') {
|
|
332
315
|
const { asset } = reference;
|
|
333
|
-
txns[txnIndex].txn
|
|
316
|
+
txns[txnIndex].txn['applicationCall'] = {
|
|
317
|
+
...txns[txnIndex].txn.applicationCall,
|
|
318
|
+
foreignAssets: [...(txns[txnIndex].txn?.applicationCall?.foreignAssets ?? []), ...[asset]],
|
|
319
|
+
};
|
|
334
320
|
}
|
|
335
321
|
else {
|
|
336
322
|
const { app } = reference;
|
|
337
|
-
txns[txnIndex].txn
|
|
323
|
+
txns[txnIndex].txn['applicationCall'] = {
|
|
324
|
+
...txns[txnIndex].txn.applicationCall,
|
|
325
|
+
foreignApps: [...(txns[txnIndex].txn?.applicationCall?.foreignApps ?? []), ...[app]],
|
|
326
|
+
};
|
|
338
327
|
}
|
|
339
328
|
return;
|
|
340
329
|
}
|
|
@@ -343,20 +332,23 @@ async function populateAppCallResources(atc, algod) {
|
|
|
343
332
|
if (!isApplBelowLimit(t))
|
|
344
333
|
return false;
|
|
345
334
|
// check if there is space in the accounts array
|
|
346
|
-
if ((t.txn.
|
|
335
|
+
if ((t.txn.applicationCall?.accounts?.length ?? 0) >= MAX_APP_CALL_ACCOUNT_REFERENCES)
|
|
347
336
|
return false;
|
|
348
337
|
if (type === 'assetHolding') {
|
|
349
338
|
const { asset } = reference;
|
|
350
|
-
return t.txn.
|
|
339
|
+
return t.txn.applicationCall?.foreignAssets?.includes(asset);
|
|
351
340
|
}
|
|
352
341
|
else {
|
|
353
342
|
const { app } = reference;
|
|
354
|
-
return t.txn.
|
|
343
|
+
return t.txn.applicationCall?.foreignApps?.includes(app) || t.txn.applicationCall?.appIndex === app;
|
|
355
344
|
}
|
|
356
345
|
});
|
|
357
346
|
if (txnIndex > -1) {
|
|
358
347
|
const { account } = reference;
|
|
359
|
-
txns[txnIndex].txn
|
|
348
|
+
txns[txnIndex].txn['applicationCall'] = {
|
|
349
|
+
...txns[txnIndex].txn.applicationCall,
|
|
350
|
+
accounts: [...(txns[txnIndex].txn?.applicationCall?.accounts ?? []), ...[account]],
|
|
351
|
+
};
|
|
360
352
|
return;
|
|
361
353
|
}
|
|
362
354
|
}
|
|
@@ -367,10 +359,13 @@ async function populateAppCallResources(atc, algod) {
|
|
|
367
359
|
if (!isApplBelowLimit(t))
|
|
368
360
|
return false;
|
|
369
361
|
// If the app is in the foreign array OR the app being called, then we know it's available
|
|
370
|
-
return t.txn.
|
|
362
|
+
return t.txn.applicationCall?.foreignApps?.includes(app) || t.txn.applicationCall?.appIndex === app;
|
|
371
363
|
});
|
|
372
364
|
if (txnIndex > -1) {
|
|
373
|
-
txns[txnIndex].txn
|
|
365
|
+
txns[txnIndex].txn['applicationCall'] = {
|
|
366
|
+
...txns[txnIndex].txn.applicationCall,
|
|
367
|
+
boxes: [...(txns[txnIndex].txn?.applicationCall?.boxes ?? []), ...[{ appIndex: app, name }]],
|
|
368
|
+
};
|
|
374
369
|
return;
|
|
375
370
|
}
|
|
376
371
|
}
|
|
@@ -378,12 +373,12 @@ async function populateAppCallResources(atc, algod) {
|
|
|
378
373
|
const txnIndex = txns.findIndex((t) => {
|
|
379
374
|
if (t.txn.type !== algosdk.TransactionType.appl)
|
|
380
375
|
return false;
|
|
381
|
-
const accounts = t.txn.
|
|
376
|
+
const accounts = t.txn.applicationCall?.accounts?.length ?? 0;
|
|
382
377
|
if (type === 'account')
|
|
383
378
|
return accounts < MAX_APP_CALL_ACCOUNT_REFERENCES;
|
|
384
|
-
const assets = t.txn.
|
|
385
|
-
const apps = t.txn.
|
|
386
|
-
const boxes = t.txn.boxes?.length
|
|
379
|
+
const assets = t.txn.applicationCall?.foreignAssets?.length ?? 0;
|
|
380
|
+
const apps = t.txn.applicationCall?.foreignApps?.length ?? 0;
|
|
381
|
+
const boxes = t.txn.applicationCall?.boxes?.length ?? 0;
|
|
387
382
|
// If we're adding local state or asset holding, we need space for the acocunt and the other reference
|
|
388
383
|
if (type === 'assetHolding' || type === 'appLocal') {
|
|
389
384
|
return accounts + assets + apps + boxes < MAX_APP_CALL_FOREIGN_REFERENCES - 1 && accounts < MAX_APP_CALL_ACCOUNT_REFERENCES;
|
|
@@ -398,30 +393,57 @@ async function populateAppCallResources(atc, algod) {
|
|
|
398
393
|
throw Error('No more transactions below reference limit. Add another app call to the group.');
|
|
399
394
|
}
|
|
400
395
|
if (type === 'account') {
|
|
401
|
-
txns[txnIndex].txn
|
|
396
|
+
txns[txnIndex].txn['applicationCall'] = {
|
|
397
|
+
...txns[txnIndex].txn.applicationCall,
|
|
398
|
+
accounts: [...(txns[txnIndex].txn?.applicationCall?.accounts ?? []), ...[reference]],
|
|
399
|
+
};
|
|
402
400
|
}
|
|
403
401
|
else if (type === 'app') {
|
|
404
|
-
txns[txnIndex].txn
|
|
402
|
+
txns[txnIndex].txn['applicationCall'] = {
|
|
403
|
+
...txns[txnIndex].txn.applicationCall,
|
|
404
|
+
foreignApps: [
|
|
405
|
+
...(txns[txnIndex].txn?.applicationCall?.foreignApps ?? []),
|
|
406
|
+
...[typeof reference === 'bigint' ? reference : BigInt(reference)],
|
|
407
|
+
],
|
|
408
|
+
};
|
|
405
409
|
}
|
|
406
410
|
else if (type === 'box') {
|
|
407
411
|
const { app, name } = reference;
|
|
408
|
-
txns[txnIndex].txn
|
|
412
|
+
txns[txnIndex].txn['applicationCall'] = {
|
|
413
|
+
...txns[txnIndex].txn.applicationCall,
|
|
414
|
+
boxes: [...(txns[txnIndex].txn?.applicationCall?.boxes ?? []), ...[{ appIndex: app, name }]],
|
|
415
|
+
};
|
|
409
416
|
if (app.toString() !== '0') {
|
|
410
|
-
txns[txnIndex].txn
|
|
417
|
+
txns[txnIndex].txn['applicationCall'] = {
|
|
418
|
+
...txns[txnIndex].txn.applicationCall,
|
|
419
|
+
foreignApps: [...(txns[txnIndex].txn?.applicationCall?.foreignApps ?? []), ...[app]],
|
|
420
|
+
};
|
|
411
421
|
}
|
|
412
422
|
}
|
|
413
423
|
else if (type === 'assetHolding') {
|
|
414
424
|
const { asset, account } = reference;
|
|
415
|
-
txns[txnIndex].txn
|
|
416
|
-
|
|
425
|
+
txns[txnIndex].txn['applicationCall'] = {
|
|
426
|
+
...txns[txnIndex].txn.applicationCall,
|
|
427
|
+
foreignAssets: [...(txns[txnIndex].txn?.applicationCall?.foreignAssets ?? []), ...[asset]],
|
|
428
|
+
accounts: [...(txns[txnIndex].txn?.applicationCall?.accounts ?? []), ...[account]],
|
|
429
|
+
};
|
|
417
430
|
}
|
|
418
431
|
else if (type === 'appLocal') {
|
|
419
432
|
const { app, account } = reference;
|
|
420
|
-
txns[txnIndex].txn
|
|
421
|
-
|
|
433
|
+
txns[txnIndex].txn['applicationCall'] = {
|
|
434
|
+
...txns[txnIndex].txn.applicationCall,
|
|
435
|
+
foreignApps: [...(txns[txnIndex].txn?.applicationCall?.foreignApps ?? []), ...[app]],
|
|
436
|
+
accounts: [...(txns[txnIndex].txn?.applicationCall?.accounts ?? []), ...[account]],
|
|
437
|
+
};
|
|
422
438
|
}
|
|
423
439
|
else if (type === 'asset') {
|
|
424
|
-
txns[txnIndex].txn
|
|
440
|
+
txns[txnIndex].txn['applicationCall'] = {
|
|
441
|
+
...txns[txnIndex].txn.applicationCall,
|
|
442
|
+
foreignAssets: [
|
|
443
|
+
...(txns[txnIndex].txn?.applicationCall?.foreignAssets ?? []),
|
|
444
|
+
...[typeof reference === 'bigint' ? reference : BigInt(reference)],
|
|
445
|
+
],
|
|
446
|
+
};
|
|
425
447
|
}
|
|
426
448
|
};
|
|
427
449
|
const g = unnamedResourcesAccessed.group;
|
|
@@ -480,20 +502,14 @@ async function populateAppCallResources(atc, algod) {
|
|
|
480
502
|
const sendAtomicTransactionComposer = async function (atcSend, algod) {
|
|
481
503
|
const { atc: givenAtc, sendParams, ...executeParams } = atcSend;
|
|
482
504
|
let atc;
|
|
483
|
-
// const hasAppCalls = () =>
|
|
484
|
-
// givenAtc
|
|
485
|
-
// .buildGroup()
|
|
486
|
-
// .map((t) => t.txn.type)
|
|
487
|
-
// .includes(algosdk.TransactionType.appl)
|
|
488
505
|
atc = givenAtc;
|
|
489
506
|
try {
|
|
507
|
+
const transactionsWithSigner = atc.buildGroup();
|
|
490
508
|
// If populateAppCallResources is true OR if populateAppCallResources is undefined and there are app calls, then populate resources
|
|
491
|
-
// NOTE: Temporary false by default until this algod bug is fixed: https://github.com/algorand/go-algorand/issues/5914
|
|
492
509
|
const populateResources = executeParams?.populateAppCallResources ?? sendParams?.populateAppCallResources ?? config.Config.populateAppCallResources;
|
|
493
|
-
if (populateResources) {
|
|
510
|
+
if (populateResources && transactionsWithSigner.map((t) => t.txn.type).includes(algosdk.TransactionType.appl)) {
|
|
494
511
|
atc = await populateAppCallResources(givenAtc, algod);
|
|
495
512
|
}
|
|
496
|
-
const transactionsWithSigner = atc.buildGroup();
|
|
497
513
|
const transactionsToSend = transactionsWithSigner.map((t) => {
|
|
498
514
|
return t.txn;
|
|
499
515
|
});
|
|
@@ -508,7 +524,7 @@ const sendAtomicTransactionComposer = async function (atcSend, algod) {
|
|
|
508
524
|
if (config.Config.debug && config.Config.traceAll) {
|
|
509
525
|
// Dump the traces to a file for use with AlgoKit AVM debugger
|
|
510
526
|
const simulateResponse = await performAtomicTransactionComposerSimulate.performAtomicTransactionComposerSimulate(atc, algod);
|
|
511
|
-
await config.Config.events.emitAsync(
|
|
527
|
+
await config.Config.events.emitAsync(types_lifecycleEvents.EventType.TxnGroupSimulated, {
|
|
512
528
|
simulateResponse,
|
|
513
529
|
});
|
|
514
530
|
}
|
|
@@ -517,22 +533,18 @@ const sendAtomicTransactionComposer = async function (atcSend, algod) {
|
|
|
517
533
|
config.Config.getLogger(executeParams?.suppressLog ?? sendParams?.suppressLog).verbose(`Group transaction (${groupId}) sent with ${transactionsToSend.length} transactions`);
|
|
518
534
|
}
|
|
519
535
|
else {
|
|
520
|
-
config.Config.getLogger(executeParams?.suppressLog ?? sendParams?.suppressLog).verbose(`Sent transaction ID ${transactionsToSend[0].txID()} ${transactionsToSend[0].type} from ${
|
|
536
|
+
config.Config.getLogger(executeParams?.suppressLog ?? sendParams?.suppressLog).verbose(`Sent transaction ID ${transactionsToSend[0].txID()} ${transactionsToSend[0].type} from ${transactionsToSend[0].sender.toString()}`);
|
|
521
537
|
}
|
|
522
538
|
let confirmations = undefined;
|
|
523
539
|
if (!sendParams?.skipWaiting) {
|
|
524
|
-
confirmations = await Promise.all(transactionsToSend.map(async (t) =>
|
|
540
|
+
confirmations = await Promise.all(transactionsToSend.map(async (t) => await algod.pendingTransactionInformation(t.txID()).do()));
|
|
525
541
|
}
|
|
526
542
|
return {
|
|
527
543
|
groupId,
|
|
528
544
|
confirmations,
|
|
529
545
|
txIds: transactionsToSend.map((t) => t.txID()),
|
|
530
546
|
transactions: transactionsToSend,
|
|
531
|
-
returns: result.methodResults.map(
|
|
532
|
-
decodeError: r.decodeError,
|
|
533
|
-
returnValue: r.returnValue,
|
|
534
|
-
rawReturnValue: r.rawReturnValue,
|
|
535
|
-
})),
|
|
547
|
+
returns: result.methodResults.map(getABIReturnValue),
|
|
536
548
|
};
|
|
537
549
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
538
550
|
}
|
|
@@ -545,6 +557,9 @@ const sendAtomicTransactionComposer = async function (atcSend, algod) {
|
|
|
545
557
|
// Remove headers as it doesn't have anything useful.
|
|
546
558
|
delete e.response?.headers;
|
|
547
559
|
err.response = e.response;
|
|
560
|
+
// body property very noisy
|
|
561
|
+
if (e.response && 'body' in e.response)
|
|
562
|
+
delete err.response.body;
|
|
548
563
|
err.name = e.name;
|
|
549
564
|
}
|
|
550
565
|
if (config.Config.debug && typeof e === 'object') {
|
|
@@ -552,14 +567,15 @@ const sendAtomicTransactionComposer = async function (atcSend, algod) {
|
|
|
552
567
|
config.Config.logger.error('Received error executing Atomic Transaction Composer and debug flag enabled; attempting simulation to get more information', err);
|
|
553
568
|
const simulate = await performAtomicTransactionComposerSimulate.performAtomicTransactionComposerSimulate(atc, algod);
|
|
554
569
|
if (config.Config.debug && !config.Config.traceAll) {
|
|
555
|
-
|
|
570
|
+
// Emit the event only if traceAll: false, as it should have already been emitted above
|
|
571
|
+
await config.Config.events.emitAsync(types_lifecycleEvents.EventType.TxnGroupSimulated, {
|
|
556
572
|
simulateResponse: simulate,
|
|
557
573
|
});
|
|
558
574
|
}
|
|
559
575
|
if (simulate && simulate.txnGroups[0].failedAt) {
|
|
560
576
|
for (const txn of simulate.txnGroups[0].txnResults) {
|
|
561
577
|
err.traces.push({
|
|
562
|
-
trace: txn.execTrace?.
|
|
578
|
+
trace: txn.execTrace?.toEncodingData(),
|
|
563
579
|
appBudget: txn.appBudgetConsumed,
|
|
564
580
|
logicSigBudget: txn.logicSigBudgetConsumed,
|
|
565
581
|
logs: txn.txnResult.logs,
|
|
@@ -574,24 +590,47 @@ const sendAtomicTransactionComposer = async function (atcSend, algod) {
|
|
|
574
590
|
throw err;
|
|
575
591
|
}
|
|
576
592
|
};
|
|
593
|
+
const convertABIDecodedBigIntToNumber = (value, type) => {
|
|
594
|
+
if (typeof value === 'bigint') {
|
|
595
|
+
if (type instanceof algosdk.ABIUintType) {
|
|
596
|
+
return type.bitSize < 53 ? Number(value) : value;
|
|
597
|
+
}
|
|
598
|
+
else {
|
|
599
|
+
return value;
|
|
600
|
+
}
|
|
601
|
+
}
|
|
602
|
+
else if (Array.isArray(value) && (type instanceof algosdk.ABIArrayStaticType || type instanceof algosdk.ABIArrayDynamicType)) {
|
|
603
|
+
return value.map((v) => convertABIDecodedBigIntToNumber(v, type.childType));
|
|
604
|
+
}
|
|
605
|
+
else if (Array.isArray(value) && type instanceof algosdk.ABITupleType) {
|
|
606
|
+
return value.map((v, i) => convertABIDecodedBigIntToNumber(v, type.childTypes[i]));
|
|
607
|
+
}
|
|
608
|
+
else {
|
|
609
|
+
return value;
|
|
610
|
+
}
|
|
611
|
+
};
|
|
577
612
|
/**
|
|
578
|
-
*
|
|
579
|
-
*
|
|
580
|
-
*
|
|
581
|
-
* @param atc The AtomicTransactionComposer` with transaction(s) loaded
|
|
582
|
-
* @param algod An Algod client
|
|
583
|
-
* @returns The dryrun result
|
|
613
|
+
* Takes an algosdk `ABIResult` and converts it to an `ABIReturn`.
|
|
614
|
+
* Converts `bigint`'s for Uint's < 64 to `number` for easier use.
|
|
615
|
+
* @param result The `ABIReturn`
|
|
584
616
|
*/
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
return
|
|
617
|
+
function getABIReturnValue(result) {
|
|
618
|
+
if (result.decodeError) {
|
|
619
|
+
return {
|
|
620
|
+
decodeError: result.decodeError,
|
|
621
|
+
};
|
|
622
|
+
}
|
|
623
|
+
return {
|
|
624
|
+
method: result.method,
|
|
625
|
+
rawReturnValue: result.rawReturnValue,
|
|
626
|
+
decodeError: undefined,
|
|
627
|
+
returnValue: result.returnValue !== undefined && result.method.returns.type !== 'void'
|
|
628
|
+
? convertABIDecodedBigIntToNumber(result.returnValue, result.method.returns.type)
|
|
629
|
+
: result.returnValue,
|
|
630
|
+
};
|
|
592
631
|
}
|
|
593
632
|
/**
|
|
594
|
-
* @deprecated Use `
|
|
633
|
+
* @deprecated Use `TransactionComposer` (`algorand.newGroup()`) or `AtomicTransactionComposer` to construct and send group transactions instead.
|
|
595
634
|
*
|
|
596
635
|
* Signs and sends a group of [up to 16](https://developer.algorand.org/docs/get-details/atomic_transfers/#create-transactions) transactions to the chain
|
|
597
636
|
*
|
|
@@ -642,7 +681,7 @@ const waitForConfirmation = async function (transactionId, maxRoundsToWait, algo
|
|
|
642
681
|
throw new Error(`Invalid timeout, received ${maxRoundsToWait}, expected > 0`);
|
|
643
682
|
}
|
|
644
683
|
// Get current round
|
|
645
|
-
const status =
|
|
684
|
+
const status = await algod.status().do();
|
|
646
685
|
if (status === undefined) {
|
|
647
686
|
throw new Error('Unable to get node status');
|
|
648
687
|
}
|
|
@@ -651,7 +690,7 @@ const waitForConfirmation = async function (transactionId, maxRoundsToWait, algo
|
|
|
651
690
|
let currentRound = startRound;
|
|
652
691
|
while (currentRound < startRound + BigInt(maxRoundsToWait)) {
|
|
653
692
|
try {
|
|
654
|
-
const pendingInfo =
|
|
693
|
+
const pendingInfo = await algod.pendingTransactionInformation(transactionId).do();
|
|
655
694
|
if (pendingInfo !== undefined) {
|
|
656
695
|
const confirmedRound = pendingInfo.confirmedRound;
|
|
657
696
|
if (confirmedRound && confirmedRound > 0) {
|
|
@@ -679,7 +718,7 @@ const waitForConfirmation = async function (transactionId, maxRoundsToWait, algo
|
|
|
679
718
|
throw new Error(`Transaction ${transactionId} not confirmed after ${maxRoundsToWait} rounds`);
|
|
680
719
|
};
|
|
681
720
|
/**
|
|
682
|
-
* @deprecated Use `
|
|
721
|
+
* @deprecated Use `TransactionComposer` and the `maxFee` field in the transaction params instead.
|
|
683
722
|
*
|
|
684
723
|
* Limit the acceptable fee to a defined amount of µAlgo.
|
|
685
724
|
* This also sets the transaction to be flatFee to ensure the transaction only succeeds at
|
|
@@ -689,21 +728,23 @@ const waitForConfirmation = async function (transactionId, maxRoundsToWait, algo
|
|
|
689
728
|
*/
|
|
690
729
|
function capTransactionFee(transaction, maxAcceptableFee) {
|
|
691
730
|
// If a flat fee hasn't already been defined
|
|
692
|
-
if (!transaction.flatFee) {
|
|
731
|
+
if (!('flatFee' in transaction) || !transaction.flatFee) {
|
|
693
732
|
// Once a transaction has been constructed by algosdk, transaction.fee indicates what the total transaction fee
|
|
694
733
|
// Will be based on the current suggested fee-per-byte value.
|
|
695
734
|
if (transaction.fee > maxAcceptableFee.microAlgo) {
|
|
696
735
|
throw new Error(`Cancelled transaction due to high network congestion fees. Algorand suggested fees would cause this transaction to cost ${transaction.fee} µALGO. Cap for this transaction is ${maxAcceptableFee.microAlgo} µALGO.`);
|
|
697
736
|
}
|
|
698
|
-
else if (transaction.fee >
|
|
737
|
+
else if (transaction.fee > 1000000) {
|
|
699
738
|
config.Config.logger.warn(`Algorand network congestion fees are in effect. This transaction will incur a fee of ${transaction.fee} µALGO.`);
|
|
700
739
|
}
|
|
701
740
|
// Now set the flat on the transaction. Otherwise the network may increase the fee above our cap and perform the transaction.
|
|
702
|
-
|
|
741
|
+
if ('flatFee' in transaction) {
|
|
742
|
+
transaction.flatFee = true;
|
|
743
|
+
}
|
|
703
744
|
}
|
|
704
745
|
}
|
|
705
746
|
/**
|
|
706
|
-
* @deprecated Use `
|
|
747
|
+
* @deprecated Use `TransactionComposer` and the `maxFee` and `staticFee` fields in the transaction params instead.
|
|
707
748
|
*
|
|
708
749
|
* Allows for control of fees on a `Transaction` or `SuggestedParams` object
|
|
709
750
|
* @param transaction The transaction or suggested params
|
|
@@ -713,7 +754,9 @@ function controlFees(transaction, feeControl) {
|
|
|
713
754
|
const { fee, maxFee } = feeControl;
|
|
714
755
|
if (fee) {
|
|
715
756
|
transaction.fee = Number(fee.microAlgo);
|
|
716
|
-
|
|
757
|
+
if ('flatFee' in transaction) {
|
|
758
|
+
transaction.flatFee = true;
|
|
759
|
+
}
|
|
717
760
|
}
|
|
718
761
|
if (maxFee !== undefined) {
|
|
719
762
|
capTransactionFee(transaction, maxFee);
|
|
@@ -729,7 +772,18 @@ function controlFees(transaction, feeControl) {
|
|
|
729
772
|
* @returns The suggested transaction parameters
|
|
730
773
|
*/
|
|
731
774
|
async function getTransactionParams(params, algod) {
|
|
732
|
-
|
|
775
|
+
if (params) {
|
|
776
|
+
return { ...params };
|
|
777
|
+
}
|
|
778
|
+
const p = await algod.getTransactionParams().do();
|
|
779
|
+
return {
|
|
780
|
+
fee: p.fee,
|
|
781
|
+
firstValid: p.firstValid,
|
|
782
|
+
lastValid: p.lastValid,
|
|
783
|
+
genesisID: p.genesisID,
|
|
784
|
+
genesisHash: p.genesisHash,
|
|
785
|
+
minFee: p.minFee,
|
|
786
|
+
};
|
|
733
787
|
}
|
|
734
788
|
/**
|
|
735
789
|
* @deprecated Use `atc.clone().buildGroup()` instead.
|
|
@@ -754,12 +808,12 @@ exports.capTransactionFee = capTransactionFee;
|
|
|
754
808
|
exports.controlFees = controlFees;
|
|
755
809
|
exports.encodeLease = encodeLease;
|
|
756
810
|
exports.encodeTransactionNote = encodeTransactionNote;
|
|
811
|
+
exports.getABIReturnValue = getABIReturnValue;
|
|
757
812
|
exports.getAtomicTransactionComposerTransactions = getAtomicTransactionComposerTransactions;
|
|
758
813
|
exports.getSenderAddress = getSenderAddress;
|
|
759
814
|
exports.getSenderTransactionSigner = getSenderTransactionSigner;
|
|
760
815
|
exports.getTransactionParams = getTransactionParams;
|
|
761
816
|
exports.getTransactionWithSigner = getTransactionWithSigner;
|
|
762
|
-
exports.performAtomicTransactionComposerDryrun = performAtomicTransactionComposerDryrun;
|
|
763
817
|
exports.populateAppCallResources = populateAppCallResources;
|
|
764
818
|
exports.sendAtomicTransactionComposer = sendAtomicTransactionComposer;
|
|
765
819
|
exports.sendGroupOfTransactions = sendGroupOfTransactions;
|