@algorandfoundation/algokit-utils 1.0.0-beta.9 → 1.1.0
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/README.md +38 -0
- package/account.d.ts +41 -36
- package/account.d.ts.map +1 -1
- package/account.js +59 -44
- package/account.js.map +1 -1
- package/amount.d.ts +20 -0
- package/amount.d.ts.map +1 -0
- package/amount.js +36 -0
- package/amount.js.map +1 -0
- package/app-client.d.ts +14 -0
- package/app-client.d.ts.map +1 -0
- package/app-client.js +19 -0
- package/app-client.js.map +1 -0
- package/app-deploy.d.ts +95 -0
- package/app-deploy.d.ts.map +1 -0
- package/{deploy-app.js → app-deploy.js} +129 -119
- package/app-deploy.js.map +1 -0
- package/app.d.ts +112 -148
- package/app.d.ts.map +1 -1
- package/app.js +460 -143
- package/app.js.map +1 -1
- package/index.d.ts +6 -4
- package/index.d.ts.map +1 -1
- package/index.js +7 -4
- package/index.js.map +1 -1
- package/indexer-lookup.d.ts +11 -4
- package/indexer-lookup.d.ts.map +1 -1
- package/indexer-lookup.js +19 -9
- package/indexer-lookup.js.map +1 -1
- package/localnet.d.ts +10 -10
- package/localnet.d.ts.map +1 -1
- package/localnet.js +16 -16
- package/localnet.js.map +1 -1
- package/network-client.d.ts +15 -24
- package/network-client.d.ts.map +1 -1
- package/network-client.js +16 -16
- package/network-client.js.map +1 -1
- package/package.json +2 -2
- package/testing/account.d.ts +14 -0
- package/testing/account.d.ts.map +1 -0
- package/testing/account.js +31 -0
- package/testing/account.js.map +1 -0
- package/testing/fixtures/algokit-log-capture-fixture.d.ts +19 -0
- package/testing/fixtures/algokit-log-capture-fixture.d.ts.map +1 -0
- package/testing/fixtures/algokit-log-capture-fixture.js +43 -0
- package/testing/fixtures/algokit-log-capture-fixture.js.map +1 -0
- package/testing/fixtures/algorand-fixture.d.ts +24 -0
- package/testing/fixtures/algorand-fixture.d.ts.map +1 -0
- package/testing/fixtures/algorand-fixture.js +60 -0
- package/testing/fixtures/algorand-fixture.js.map +1 -0
- package/testing/fixtures/index.d.ts +3 -0
- package/testing/fixtures/index.d.ts.map +1 -0
- package/testing/fixtures/index.js +19 -0
- package/testing/fixtures/index.js.map +1 -0
- package/testing/index.d.ts +6 -0
- package/testing/index.d.ts.map +1 -0
- package/testing/index.js +22 -0
- package/testing/index.js.map +1 -0
- package/testing/indexer.d.ts +12 -0
- package/testing/indexer.d.ts.map +1 -0
- package/testing/indexer.js +40 -0
- package/testing/indexer.js.map +1 -0
- package/testing/test-logger.d.ts +41 -0
- package/testing/test-logger.d.ts.map +1 -0
- package/testing/test-logger.js +71 -0
- package/testing/test-logger.js.map +1 -0
- package/testing/transaction-logger.d.ts +29 -0
- package/testing/transaction-logger.d.ts.map +1 -0
- package/testing/transaction-logger.js +71 -0
- package/testing/transaction-logger.js.map +1 -0
- package/transaction.d.ts +55 -91
- package/transaction.d.ts.map +1 -1
- package/transaction.js +213 -155
- package/transaction.js.map +1 -1
- package/transfer.d.ts +14 -16
- package/transfer.d.ts.map +1 -1
- package/transfer.js +38 -4
- package/transfer.js.map +1 -1
- package/types/account.d.ts +55 -0
- package/types/account.d.ts.map +1 -0
- package/types/account.js +91 -0
- package/types/account.js.map +1 -0
- package/types/algo-http-client-with-retry.d.ts.map +1 -0
- package/{algo-http-client-with-retry.js → types/algo-http-client-with-retry.js} +3 -3
- package/types/algo-http-client-with-retry.js.map +1 -0
- package/types/algod.d.ts +28 -15
- package/types/algod.d.ts.map +1 -1
- package/{algo-amount.d.ts → types/amount.d.ts} +9 -3
- package/types/amount.d.ts.map +1 -0
- package/{algo-amount.js → types/amount.js} +13 -3
- package/types/amount.js.map +1 -0
- package/types/app-client.d.ts +282 -0
- package/types/app-client.d.ts.map +1 -0
- package/types/app-client.js +529 -0
- package/types/app-client.js.map +1 -0
- package/types/app-spec.d.ts +141 -0
- package/types/app-spec.d.ts.map +1 -0
- package/types/{appspec.js → app-spec.js} +5 -7
- package/types/app-spec.js.map +1 -0
- package/types/app.d.ts +285 -0
- package/types/app.d.ts.map +1 -0
- package/types/app.js +32 -0
- package/types/app.js.map +1 -0
- package/types/config.d.ts +32 -0
- package/types/config.d.ts.map +1 -0
- package/types/config.js +53 -0
- package/types/config.js.map +1 -0
- package/types/indexer.d.ts +368 -58
- package/types/indexer.d.ts.map +1 -1
- package/types/indexer.js +9 -0
- package/types/indexer.js.map +1 -1
- package/{config.d.ts → types/logging.d.ts} +2 -16
- package/types/logging.d.ts.map +1 -0
- package/{config.js → types/logging.js} +5 -24
- package/types/logging.js.map +1 -0
- package/types/logic-error.d.ts +37 -0
- package/types/logic-error.d.ts.map +1 -0
- package/types/logic-error.js +50 -0
- package/types/logic-error.js.map +1 -0
- package/types/network-client.d.ts +11 -0
- package/types/network-client.d.ts.map +1 -0
- package/types/network-client.js +3 -0
- package/types/network-client.js.map +1 -0
- package/types/testing.d.ts +89 -0
- package/types/testing.d.ts.map +1 -0
- package/types/testing.js +3 -0
- package/types/testing.js.map +1 -0
- package/types/transaction.d.ts +112 -0
- package/types/transaction.d.ts.map +1 -0
- package/types/transaction.js +3 -0
- package/types/transaction.js.map +1 -0
- package/types/transfer.d.ts +32 -0
- package/types/transfer.d.ts.map +1 -0
- package/types/transfer.js +3 -0
- package/types/transfer.js.map +1 -0
- package/types/urlTokenBaseHTTPClient.d.ts.map +1 -0
- package/types/urlTokenBaseHTTPClient.js.map +1 -0
- package/algo-amount.d.ts.map +0 -1
- package/algo-amount.js.map +0 -1
- package/algo-http-client-with-retry.d.ts.map +0 -1
- package/algo-http-client-with-retry.js.map +0 -1
- package/application-client.d.ts +0 -113
- package/application-client.d.ts.map +0 -1
- package/application-client.js +0 -258
- package/application-client.js.map +0 -1
- package/config.d.ts.map +0 -1
- package/config.js.map +0 -1
- package/deploy-app.d.ts +0 -164
- package/deploy-app.d.ts.map +0 -1
- package/deploy-app.js.map +0 -1
- package/types/appspec.d.ts +0 -78
- package/types/appspec.d.ts.map +0 -1
- package/types/appspec.js.map +0 -1
- package/urlTokenBaseHTTPClient.d.ts.map +0 -1
- package/urlTokenBaseHTTPClient.js.map +0 -1
- /package/{algo-http-client-with-retry.d.ts → types/algo-http-client-with-retry.d.ts} +0 -0
- /package/{urlTokenBaseHTTPClient.d.ts → types/urlTokenBaseHTTPClient.d.ts} +0 -0
- /package/{urlTokenBaseHTTPClient.js → types/urlTokenBaseHTTPClient.js} +0 -0
package/transaction.js
CHANGED
|
@@ -1,78 +1,32 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var
|
|
3
|
-
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
4
24
|
};
|
|
5
25
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.getTransactionParams = exports.capTransactionFee = exports.waitForConfirmation = exports.sendGroupOfTransactions = exports.sendTransaction = exports.
|
|
7
|
-
const algosdk_1 =
|
|
26
|
+
exports.getAtomicTransactionComposerTransactions = exports.getTransactionParams = exports.controlFees = exports.capTransactionFee = exports.waitForConfirmation = exports.sendGroupOfTransactions = exports.performAtomicTransactionComposerDryrun = exports.sendAtomicTransactionComposer = exports.sendTransaction = exports.signTransaction = exports.getSenderTransactionSigner = exports.getSenderAddress = exports.encodeTransactionNote = void 0;
|
|
27
|
+
const algosdk_1 = __importStar(require("algosdk"));
|
|
8
28
|
const buffer_1 = require("buffer");
|
|
9
|
-
const
|
|
10
|
-
/** Account wrapper that supports partial or full multisig signing */
|
|
11
|
-
class MultisigAccount {
|
|
12
|
-
get params() {
|
|
13
|
-
return this._params;
|
|
14
|
-
}
|
|
15
|
-
get signingAccounts() {
|
|
16
|
-
return this._signingAccounts;
|
|
17
|
-
}
|
|
18
|
-
get addr() {
|
|
19
|
-
return this._addr;
|
|
20
|
-
}
|
|
21
|
-
constructor(multisigParams, signingAccounts) {
|
|
22
|
-
this._params = multisigParams;
|
|
23
|
-
this._signingAccounts = signingAccounts;
|
|
24
|
-
this._addr = algosdk_1.default.multisigAddress(multisigParams);
|
|
25
|
-
}
|
|
26
|
-
sign(transaction) {
|
|
27
|
-
let signedTxn = 'from' in transaction ? undefined : transaction;
|
|
28
|
-
for (const signer of this._signingAccounts) {
|
|
29
|
-
if (signedTxn) {
|
|
30
|
-
signedTxn = algosdk_1.default.appendSignMultisigTransaction(signedTxn, this._params, signer.sk).blob;
|
|
31
|
-
}
|
|
32
|
-
else {
|
|
33
|
-
signedTxn = algosdk_1.default.signMultisigTransaction(transaction, this._params, signer.sk).blob;
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
37
|
-
return signedTxn;
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
exports.MultisigAccount = MultisigAccount;
|
|
41
|
-
/** Account wrapper that supports a rekeyed account */
|
|
42
|
-
class SigningAccount {
|
|
43
|
-
/**
|
|
44
|
-
* Algorand address of the sender
|
|
45
|
-
*/
|
|
46
|
-
get addr() {
|
|
47
|
-
return this._sender;
|
|
48
|
-
}
|
|
49
|
-
/**
|
|
50
|
-
* Secret key belonging to the signer
|
|
51
|
-
*/
|
|
52
|
-
get sk() {
|
|
53
|
-
return this._account.sk;
|
|
54
|
-
}
|
|
55
|
-
/**
|
|
56
|
-
* Algorand account of the underlying signing account
|
|
57
|
-
*/
|
|
58
|
-
get signer() {
|
|
59
|
-
return this._account;
|
|
60
|
-
}
|
|
61
|
-
/**
|
|
62
|
-
* Algorand account of the sender address and signer private key
|
|
63
|
-
*/
|
|
64
|
-
get sender() {
|
|
65
|
-
return {
|
|
66
|
-
addr: this._sender,
|
|
67
|
-
sk: this._account.sk,
|
|
68
|
-
};
|
|
69
|
-
}
|
|
70
|
-
constructor(account, sender) {
|
|
71
|
-
this._account = account;
|
|
72
|
-
this._sender = sender ?? account.addr;
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
exports.SigningAccount = SigningAccount;
|
|
29
|
+
const _1 = require("./");
|
|
76
30
|
/** Encodes a transaction note into a byte array ready to be included in an Algorand transaction.
|
|
77
31
|
*
|
|
78
32
|
* @param note The transaction note
|
|
@@ -93,7 +47,7 @@ function encodeTransactionNote(note) {
|
|
|
93
47
|
return note;
|
|
94
48
|
}
|
|
95
49
|
else if (typeof note === 'object' && 'dAppName' in note) {
|
|
96
|
-
const arc2Payload = `${note.dAppName}:${note.format}${note.data}`;
|
|
50
|
+
const arc2Payload = `${note.dAppName}:${note.format}${typeof note.data === 'string' ? note.data : JSON.stringify(note.data)}`;
|
|
97
51
|
const encoder = new TextEncoder();
|
|
98
52
|
return encoder.encode(arc2Payload);
|
|
99
53
|
}
|
|
@@ -113,34 +67,67 @@ const getSenderAddress = function (sender) {
|
|
|
113
67
|
return 'addr' in sender ? sender.addr : sender.address();
|
|
114
68
|
};
|
|
115
69
|
exports.getSenderAddress = getSenderAddress;
|
|
116
|
-
|
|
70
|
+
const memoize = (fn) => {
|
|
71
|
+
const cache = new Map();
|
|
72
|
+
const cached = function (val) {
|
|
73
|
+
return cache.has(val) ? cache.get(val) : cache.set(val, fn.call(this, val)) && cache.get(val);
|
|
74
|
+
};
|
|
75
|
+
cached.cache = cache;
|
|
76
|
+
return cached;
|
|
77
|
+
};
|
|
78
|
+
/**
|
|
79
|
+
* Returns a `TransactionSigner` for the given transaction sender.
|
|
80
|
+
* This function has memoization, so will return the same transaction signer for a given sender.
|
|
81
|
+
* @param sender A transaction sender
|
|
82
|
+
* @returns A transaction signer
|
|
83
|
+
*/
|
|
84
|
+
exports.getSenderTransactionSigner = memoize(function (sender) {
|
|
85
|
+
return 'signer' in sender
|
|
86
|
+
? sender.signer
|
|
87
|
+
: 'lsig' in sender
|
|
88
|
+
? algosdk_1.default.makeLogicSigAccountTransactionSigner(sender)
|
|
89
|
+
: algosdk_1.default.makeBasicAccountTransactionSigner(sender);
|
|
90
|
+
});
|
|
91
|
+
/**
|
|
92
|
+
* Signs a single transaction by the given signer.
|
|
93
|
+
* @param transaction The transaction to sign
|
|
94
|
+
* @param signer The signer to sign
|
|
95
|
+
* @returns The signed transaction as a `Uint8Array`
|
|
96
|
+
*/
|
|
97
|
+
const signTransaction = async (transaction, signer) => {
|
|
98
|
+
return 'sk' in signer
|
|
99
|
+
? transaction.signTxn(signer.sk)
|
|
100
|
+
: 'lsig' in signer
|
|
101
|
+
? algosdk_1.default.signLogicSigTransactionObject(transaction, signer).blob
|
|
102
|
+
: 'sign' in signer
|
|
103
|
+
? signer.sign(transaction)
|
|
104
|
+
: (await signer.signer([transaction], [0]))[0];
|
|
105
|
+
};
|
|
106
|
+
exports.signTransaction = signTransaction;
|
|
107
|
+
/** Prepares a transaction for sending and then (if instructed) signs and sends the given transaction to the chain.
|
|
117
108
|
*
|
|
118
|
-
* @param send The details for the transaction to send, including:
|
|
109
|
+
* @param send The details for the transaction to prepare/send, including:
|
|
119
110
|
* * `transaction`: The unsigned transaction
|
|
120
111
|
* * `from`: The account to sign the transaction with: either an account with private key loaded or a logic signature account
|
|
121
112
|
* * `config`: The sending configuration for this transaction
|
|
122
113
|
* @param algod An algod client
|
|
123
114
|
*
|
|
124
|
-
* @returns An object with transaction (`transaction`) and (if `skipWaiting` is `false` or
|
|
115
|
+
* @returns An object with transaction (`transaction`) and (if `skipWaiting` is `false` or `undefined`) confirmation (`confirmation`)
|
|
125
116
|
*/
|
|
126
117
|
const sendTransaction = async function (send, algod) {
|
|
127
118
|
const { transaction, from, sendParams } = send;
|
|
128
|
-
const { skipSending, skipWaiting, maxFee, suppressLog, maxRoundsToWaitForConfirmation } = sendParams ?? {};
|
|
129
|
-
|
|
130
|
-
|
|
119
|
+
const { skipSending, skipWaiting, fee, maxFee, suppressLog, maxRoundsToWaitForConfirmation, atc } = sendParams ?? {};
|
|
120
|
+
controlFees(transaction, { fee, maxFee });
|
|
121
|
+
if (atc) {
|
|
122
|
+
atc.addTransaction({ txn: transaction, signer: (0, exports.getSenderTransactionSigner)(from) });
|
|
123
|
+
return { transaction };
|
|
131
124
|
}
|
|
132
125
|
if (skipSending) {
|
|
133
126
|
return { transaction };
|
|
134
127
|
}
|
|
135
|
-
const signedTransaction =
|
|
136
|
-
? transaction.signTxn(from.sk)
|
|
137
|
-
: 'lsig' in from
|
|
138
|
-
? algosdk_1.default.signLogicSigTransactionObject(transaction, from).blob
|
|
139
|
-
: 'signer' in from
|
|
140
|
-
? (await from.signer([transaction], [0]))[0]
|
|
141
|
-
: from.sign(transaction);
|
|
128
|
+
const signedTransaction = await (0, exports.signTransaction)(transaction, from);
|
|
142
129
|
await algod.sendRawTransaction(signedTransaction).do();
|
|
143
|
-
|
|
130
|
+
_1.Config.getLogger(suppressLog).info(`Sent transaction ID ${transaction.txID()} ${transaction.type} from ${(0, exports.getSenderAddress)(from)}`);
|
|
144
131
|
let confirmation = undefined;
|
|
145
132
|
if (!skipWaiting) {
|
|
146
133
|
confirmation = await (0, exports.waitForConfirmation)(transaction.txID(), maxRoundsToWaitForConfirmation ?? 5, algod);
|
|
@@ -148,12 +135,89 @@ const sendTransaction = async function (send, algod) {
|
|
|
148
135
|
return { transaction, confirmation };
|
|
149
136
|
};
|
|
150
137
|
exports.sendTransaction = sendTransaction;
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
138
|
+
/**
|
|
139
|
+
* Signs and sends transactions that have been collected by an `AtomicTransactionComposer`.
|
|
140
|
+
* @param atcSend The parameters controlling the send, including:
|
|
141
|
+
* * `atc` The `AtomicTransactionComposer`
|
|
142
|
+
* * `sendParams` The parameters to control the send behaviour
|
|
143
|
+
* @param algod An algod client
|
|
144
|
+
* @returns An object with transaction IDs, transactions, group transaction ID (`groupTransactionId`) if more than 1 transaction sent, and (if `skipWaiting` is `false` or unset) confirmation (`confirmation`)
|
|
145
|
+
*/
|
|
146
|
+
const sendAtomicTransactionComposer = async function (atcSend, algod) {
|
|
147
|
+
const { atc, sendParams } = atcSend;
|
|
148
|
+
const transactionsWithSigner = atc.buildGroup();
|
|
149
|
+
const transactionsToSend = transactionsWithSigner.map((t) => {
|
|
150
|
+
return t.txn;
|
|
151
|
+
});
|
|
152
|
+
let groupId = undefined;
|
|
153
|
+
if (transactionsToSend.length > 1) {
|
|
154
|
+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
155
|
+
groupId = transactionsToSend[0].group ? buffer_1.Buffer.from(transactionsToSend[0].group).toString('base64') : '';
|
|
156
|
+
_1.Config.getLogger(sendParams?.suppressLog).info(`Sending group of ${transactionsToSend.length} transactions (${groupId})`, {
|
|
157
|
+
transactionsToSend,
|
|
158
|
+
});
|
|
159
|
+
_1.Config.getLogger(sendParams?.suppressLog).debug(`Transaction IDs (${groupId})`, transactionsToSend.map((t) => t.txID()));
|
|
160
|
+
}
|
|
161
|
+
try {
|
|
162
|
+
const result = await atc.execute(algod, sendParams?.maxRoundsToWaitForConfirmation ?? 5);
|
|
163
|
+
if (transactionsToSend.length > 1) {
|
|
164
|
+
_1.Config.getLogger(sendParams?.suppressLog).info(`Group transaction (${groupId}) sent with ${transactionsToSend.length} transactions`);
|
|
165
|
+
}
|
|
166
|
+
else {
|
|
167
|
+
_1.Config.getLogger(sendParams?.suppressLog).info(`Sent transaction ID ${transactionsToSend[0].txID()} ${transactionsToSend[0].type} from ${algosdk_1.default.encodeAddress(transactionsToSend[0].from.publicKey)}`);
|
|
168
|
+
}
|
|
169
|
+
let confirmations = undefined;
|
|
170
|
+
if (!sendParams?.skipWaiting) {
|
|
171
|
+
confirmations = await Promise.all(transactionsToSend.map(async (t) => (await algod.pendingTransactionInformation(t.txID()).do())));
|
|
172
|
+
}
|
|
173
|
+
return {
|
|
174
|
+
groupId,
|
|
175
|
+
confirmations,
|
|
176
|
+
txIds: transactionsToSend.map((t) => t.txID()),
|
|
177
|
+
transactions: transactionsToSend,
|
|
178
|
+
returns: result.methodResults.map((r) => ({
|
|
179
|
+
decodeError: r.decodeError,
|
|
180
|
+
returnValue: r.returnValue,
|
|
181
|
+
rawReturnValue: r.rawReturnValue,
|
|
182
|
+
})),
|
|
183
|
+
};
|
|
184
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
185
|
+
}
|
|
186
|
+
catch (e) {
|
|
187
|
+
if (_1.Config.debug && typeof e === 'object') {
|
|
188
|
+
e.traces = [];
|
|
189
|
+
_1.Config.logger.debug('Received error executing Atomic Transaction Composer and debug flag enabled; attempting dry run to get more information');
|
|
190
|
+
const dryrun = await performAtomicTransactionComposerDryrun(atc, algod);
|
|
191
|
+
for (const txn of dryrun.txns) {
|
|
192
|
+
if (txn.appCallRejected()) {
|
|
193
|
+
e.traces.push({
|
|
194
|
+
trace: txn.appTrace(),
|
|
195
|
+
cost: txn.cost,
|
|
196
|
+
logs: txn.logs,
|
|
197
|
+
messages: txn.appCallMessages,
|
|
198
|
+
});
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
throw e;
|
|
203
|
+
}
|
|
204
|
+
};
|
|
205
|
+
exports.sendAtomicTransactionComposer = sendAtomicTransactionComposer;
|
|
206
|
+
/**
|
|
207
|
+
* Performs a dry run of the transactions loaded into the given AtomicTransactionComposer`
|
|
208
|
+
* @param atc The AtomicTransactionComposer` with transaction(s) loaded
|
|
209
|
+
* @param algod An Algod client
|
|
210
|
+
* @returns The dryrun result
|
|
211
|
+
*/
|
|
212
|
+
async function performAtomicTransactionComposerDryrun(atc, algod) {
|
|
213
|
+
const signedTransactions = await atc.gatherSignatures();
|
|
214
|
+
const txns = signedTransactions.map((t) => {
|
|
215
|
+
return algosdk_1.default.decodeSignedTransaction(t);
|
|
216
|
+
});
|
|
217
|
+
const dryrun = await algosdk_1.default.createDryrun({ client: algod, txns });
|
|
218
|
+
return new algosdk_1.default.DryrunResult(await algod.dryrun(dryrun).do());
|
|
219
|
+
}
|
|
220
|
+
exports.performAtomicTransactionComposerDryrun = performAtomicTransactionComposerDryrun;
|
|
157
221
|
/**
|
|
158
222
|
* Signs and sends a group of [up to 16](https://developer.algorand.org/docs/get-details/atomic_transfers/#create-transactions) transactions to the chain
|
|
159
223
|
*
|
|
@@ -161,69 +225,32 @@ const groupBy = (array, predicate) => array.reduce((acc, value, index, array) =>
|
|
|
161
225
|
* * `transactions`: The array of transactions to send along with their signing account
|
|
162
226
|
* * `sendParams`: The parameters to dictate how the group is sent
|
|
163
227
|
* @param algod An algod client
|
|
164
|
-
* @returns An object with group transaction ID (`groupTransactionId`) and (if `skipWaiting` is `false` or unset) confirmation (`confirmation`)
|
|
228
|
+
* @returns An object with transaction IDs, transactions, group transaction ID (`groupTransactionId`) if more than 1 transaction sent, and (if `skipWaiting` is `false` or unset) confirmation (`confirmation`)
|
|
165
229
|
*/
|
|
166
230
|
const sendGroupOfTransactions = async function (groupSend, algod) {
|
|
167
|
-
const { transactions, sendParams } = groupSend;
|
|
168
|
-
const
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
if (transactions.find((t) => !('signer' in t.signer))) {
|
|
180
|
-
throw new Error("When issuing a group transaction the signers should either all be TransactionSignerAccount's or all not. " +
|
|
181
|
-
'Received at least one TransactionSignerAccount, but not all of them so failing the send.');
|
|
231
|
+
const { transactions, signer, sendParams } = groupSend;
|
|
232
|
+
const defaultTransactionSigner = signer ? (0, exports.getSenderTransactionSigner)(signer) : undefined;
|
|
233
|
+
const transactionsWithSigner = await Promise.all(transactions.map(async (t) => {
|
|
234
|
+
if ('signer' in t)
|
|
235
|
+
return {
|
|
236
|
+
txn: t.transaction,
|
|
237
|
+
signer: (0, exports.getSenderTransactionSigner)(t.signer),
|
|
238
|
+
sender: t.signer,
|
|
239
|
+
};
|
|
240
|
+
const txn = 'then' in t ? (await t).transaction : t;
|
|
241
|
+
if (!signer) {
|
|
242
|
+
throw new Error(`Attempt to send transaction ${txn.txID()} as part of a group transaction, but no signer parameter was provided.`);
|
|
182
243
|
}
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
txn,
|
|
194
|
-
index: indexes[i],
|
|
195
|
-
}));
|
|
196
|
-
}))).flatMap((a) => a);
|
|
197
|
-
// Extract the signed transactions in order
|
|
198
|
-
signedTransactions = signed.sort((s1, s2) => s1.index - s2.index).map((s) => s.txn);
|
|
199
|
-
}
|
|
200
|
-
else {
|
|
201
|
-
signedTransactions = group.map((groupedTransaction, index) => {
|
|
202
|
-
const signer = transactions[index].signer;
|
|
203
|
-
return 'sk' in signer
|
|
204
|
-
? groupedTransaction.signTxn(signer.sk)
|
|
205
|
-
: 'lsig' in signer
|
|
206
|
-
? algosdk_1.default.signLogicSigTransactionObject(groupedTransaction, signer).blob
|
|
207
|
-
: 'sign' in signer
|
|
208
|
-
? signer.sign(groupedTransaction)
|
|
209
|
-
: // This bit will never happen because above if statement
|
|
210
|
-
new Uint8Array();
|
|
211
|
-
});
|
|
212
|
-
}
|
|
213
|
-
config_1.AlgoKitConfig.getLogger(sendParams?.suppressLog).debug(`Signer IDs (${groupId})`, transactions.map((t) => (0, exports.getSenderAddress)(t.signer)));
|
|
214
|
-
config_1.AlgoKitConfig.getLogger(sendParams?.suppressLog).debug(`Transaction IDs (${groupId})`, transactionsToSend.map((t) => t.txID()));
|
|
215
|
-
// https://developer.algorand.org/docs/rest-apis/algod/v2/#post-v2transactions
|
|
216
|
-
await algod.sendRawTransaction(signedTransactions).do();
|
|
217
|
-
config_1.AlgoKitConfig.getLogger(sendParams?.suppressLog).info(`Group transaction (${groupId}) sent with ${transactionsToSend.length} transactions`);
|
|
218
|
-
let confirmations = undefined;
|
|
219
|
-
if (!sendParams?.skipWaiting) {
|
|
220
|
-
confirmations = await Promise.all(transactionsToSend.map(async (t) => await (0, exports.waitForConfirmation)(t.txID(), sendParams?.maxRoundsToWaitForConfirmation ?? 5, algod)));
|
|
221
|
-
}
|
|
222
|
-
return {
|
|
223
|
-
groupId,
|
|
224
|
-
confirmations,
|
|
225
|
-
txIds: transactionsToSend.map((t) => t.txID()),
|
|
226
|
-
};
|
|
244
|
+
return {
|
|
245
|
+
txn,
|
|
246
|
+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
247
|
+
signer: defaultTransactionSigner,
|
|
248
|
+
sender: signer,
|
|
249
|
+
};
|
|
250
|
+
}));
|
|
251
|
+
const atc = new algosdk_1.AtomicTransactionComposer();
|
|
252
|
+
transactionsWithSigner.forEach((txn) => atc.addTransaction(txn));
|
|
253
|
+
return (await (0, exports.sendAtomicTransactionComposer)({ atc, sendParams }, algod));
|
|
227
254
|
};
|
|
228
255
|
exports.sendGroupOfTransactions = sendGroupOfTransactions;
|
|
229
256
|
/**
|
|
@@ -274,7 +301,7 @@ exports.waitForConfirmation = waitForConfirmation;
|
|
|
274
301
|
* Limit the acceptable fee to a defined amount of µALGOs.
|
|
275
302
|
* This also sets the transaction to be flatFee to ensure the transaction only succeeds at
|
|
276
303
|
* the estimated rate.
|
|
277
|
-
* @param transaction The transaction to cap
|
|
304
|
+
* @param transaction The transaction to cap or suggested params object about to be used to create a transaction
|
|
278
305
|
* @param maxAcceptableFee The maximum acceptable fee to pay
|
|
279
306
|
*/
|
|
280
307
|
function capTransactionFee(transaction, maxAcceptableFee) {
|
|
@@ -286,13 +313,30 @@ function capTransactionFee(transaction, maxAcceptableFee) {
|
|
|
286
313
|
throw new Error(`Cancelled transaction due to high network congestion fees. Algorand suggested fees would cause this transaction to cost ${transaction.fee} µALGOs. Cap for this transaction is ${maxAcceptableFee.microAlgos} µALGOs.`);
|
|
287
314
|
}
|
|
288
315
|
else if (transaction.fee > algosdk_1.default.ALGORAND_MIN_TX_FEE) {
|
|
289
|
-
|
|
316
|
+
_1.Config.logger.warn(`Algorand network congestion fees are in effect. This transaction will incur a fee of ${transaction.fee} µALGOs.`);
|
|
290
317
|
}
|
|
291
318
|
// Now set the flat on the transaction. Otherwise the network may increase the fee above our cap and perform the transaction.
|
|
292
319
|
transaction.flatFee = true;
|
|
293
320
|
}
|
|
294
321
|
}
|
|
295
322
|
exports.capTransactionFee = capTransactionFee;
|
|
323
|
+
/**
|
|
324
|
+
* Allows for control of fees on a `Transaction` or `SuggestedParams` object
|
|
325
|
+
* @param transaction The transaction or suggested params
|
|
326
|
+
* @param feeControl The fee control parameters
|
|
327
|
+
*/
|
|
328
|
+
function controlFees(transaction, feeControl) {
|
|
329
|
+
const { fee, maxFee } = feeControl;
|
|
330
|
+
if (fee) {
|
|
331
|
+
transaction.fee = fee.microAlgos;
|
|
332
|
+
transaction.flatFee = true;
|
|
333
|
+
}
|
|
334
|
+
if (maxFee !== undefined) {
|
|
335
|
+
capTransactionFee(transaction, maxFee);
|
|
336
|
+
}
|
|
337
|
+
return transaction;
|
|
338
|
+
}
|
|
339
|
+
exports.controlFees = controlFees;
|
|
296
340
|
/**
|
|
297
341
|
* Returns suggested transaction parameters from algod unless some are already provided.
|
|
298
342
|
* @param params Optionally provide parameters to use
|
|
@@ -300,7 +344,21 @@ exports.capTransactionFee = capTransactionFee;
|
|
|
300
344
|
* @returns The suggested transaction parameters
|
|
301
345
|
*/
|
|
302
346
|
async function getTransactionParams(params, algod) {
|
|
303
|
-
return params
|
|
347
|
+
return params ? { ...params } : await algod.getTransactionParams().do();
|
|
304
348
|
}
|
|
305
349
|
exports.getTransactionParams = getTransactionParams;
|
|
350
|
+
/**
|
|
351
|
+
* Returns the array of transactions currently present in the given `AtomicTransactionComposer`
|
|
352
|
+
* @param atc The atomic transaction composer
|
|
353
|
+
* @returns The array of transactions with signers
|
|
354
|
+
*/
|
|
355
|
+
function getAtomicTransactionComposerTransactions(atc) {
|
|
356
|
+
try {
|
|
357
|
+
return atc.clone().buildGroup();
|
|
358
|
+
}
|
|
359
|
+
catch {
|
|
360
|
+
return [];
|
|
361
|
+
}
|
|
362
|
+
}
|
|
363
|
+
exports.getAtomicTransactionComposerTransactions = getAtomicTransactionComposerTransactions;
|
|
306
364
|
//# sourceMappingURL=transaction.js.map
|
package/transaction.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"transaction.js","sourceRoot":"","sources":["../src/transaction.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"transaction.js","sourceRoot":"","sources":["../src/transaction.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,mDAAsH;AACtH,mCAA+B;AAC/B,yBAA2B;AAc3B;;;;;;;;;;;GAWG;AACH,SAAgB,qBAAqB,CAAC,IAAsB;IAC1D,IAAI,IAAI,IAAI,IAAI,IAAI,OAAO,IAAI,KAAK,WAAW,EAAE;QAC/C,OAAO,SAAS,CAAA;KACjB;SAAM,IAAI,OAAO,IAAI,KAAK,QAAQ,IAAI,IAAI,CAAC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{ Algodv2,
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
interface AlgoTransferParams extends SendTransactionParams {
|
|
5
|
-
/** The account (with private key loaded) that will send the µALGOs */
|
|
6
|
-
from: SendTransactionFrom;
|
|
7
|
-
/** The account address that will receive the ALGOs */
|
|
8
|
-
to: string;
|
|
9
|
-
/** The amount to send */
|
|
10
|
-
amount: AlgoAmount;
|
|
11
|
-
/** Optional transaction parameters */
|
|
12
|
-
transactionParams?: SuggestedParams;
|
|
13
|
-
/** The (optional) transaction note */
|
|
14
|
-
note?: TransactionNote;
|
|
15
|
-
}
|
|
1
|
+
import { Algodv2, Kmd } from 'algosdk';
|
|
2
|
+
import { SendTransactionResult } from './types/transaction';
|
|
3
|
+
import { AlgoTransferParams, EnsureFundedParams } from './types/transfer';
|
|
16
4
|
/**
|
|
17
5
|
* Transfer ALGOs between two accounts.
|
|
18
6
|
* @param transfer The transfer definition
|
|
@@ -20,5 +8,15 @@ interface AlgoTransferParams extends SendTransactionParams {
|
|
|
20
8
|
* @returns The transaction object and optionally the confirmation if it was sent to the chain (`skipSending` is `false` or unset)
|
|
21
9
|
*/
|
|
22
10
|
export declare function transferAlgos(transfer: AlgoTransferParams, algod: Algodv2): Promise<SendTransactionResult>;
|
|
23
|
-
|
|
11
|
+
/**
|
|
12
|
+
* Funds a given account using a funding source such that it has a certain amount of algos free to spend (accounting for ALGOs locked in minimum balance requirement).
|
|
13
|
+
*
|
|
14
|
+
* https://developer.algorand.org/docs/get-details/accounts/#minimum-balance
|
|
15
|
+
*
|
|
16
|
+
* @param funding The funding configuration
|
|
17
|
+
* @param algod An algod client
|
|
18
|
+
* @param kmd An optional kmd client
|
|
19
|
+
* @returns undefined if nothing was needed or the transaction send result
|
|
20
|
+
*/
|
|
21
|
+
export declare function ensureFunded(funding: EnsureFundedParams, algod: Algodv2, kmd?: Kmd): Promise<SendTransactionResult | undefined>;
|
|
24
22
|
//# sourceMappingURL=transfer.d.ts.map
|
package/transfer.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"transfer.d.ts","sourceRoot":"","sources":["../src/transfer.ts"],"names":[],"mappings":"AAAA,OAAgB,EAAE,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"transfer.d.ts","sourceRoot":"","sources":["../src/transfer.ts"],"names":[],"mappings":"AAAA,OAAgB,EAAE,OAAO,EAAE,GAAG,EAAE,MAAM,SAAS,CAAA;AAG/C,OAAO,EAAE,qBAAqB,EAAE,MAAM,qBAAqB,CAAA;AAC3D,OAAO,EAAE,kBAAkB,EAAE,kBAAkB,EAAE,MAAM,kBAAkB,CAAA;AAEzE;;;;;GAKG;AACH,wBAAsB,aAAa,CAAC,QAAQ,EAAE,kBAAkB,EAAE,KAAK,EAAE,OAAO,GAAG,OAAO,CAAC,qBAAqB,CAAC,CAkBhH;AAED;;;;;;;;;GASG;AACH,wBAAsB,YAAY,CAAC,OAAO,EAAE,kBAAkB,EAAE,KAAK,EAAE,OAAO,EAAE,GAAG,CAAC,EAAE,GAAG,GAAG,OAAO,CAAC,qBAAqB,GAAG,SAAS,CAAC,CAiCrI"}
|
package/transfer.js
CHANGED
|
@@ -3,9 +3,9 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.transferAlgos = void 0;
|
|
6
|
+
exports.ensureFunded = exports.transferAlgos = void 0;
|
|
7
7
|
const algosdk_1 = __importDefault(require("algosdk"));
|
|
8
|
-
const
|
|
8
|
+
const _1 = require("./");
|
|
9
9
|
const transaction_1 = require("./transaction");
|
|
10
10
|
/**
|
|
11
11
|
* Transfer ALGOs between two accounts.
|
|
@@ -17,7 +17,7 @@ async function transferAlgos(transfer, algod) {
|
|
|
17
17
|
const { from, to, amount, note, transactionParams, ...sendParams } = transfer;
|
|
18
18
|
const transaction = algosdk_1.default.makePaymentTxnWithSuggestedParamsFromObject({
|
|
19
19
|
from: (0, transaction_1.getSenderAddress)(from),
|
|
20
|
-
to: to,
|
|
20
|
+
to: typeof to === 'string' ? to : (0, transaction_1.getSenderAddress)(to),
|
|
21
21
|
amount: amount.microAlgos,
|
|
22
22
|
note: (0, transaction_1.encodeTransactionNote)(note),
|
|
23
23
|
suggestedParams: await (0, transaction_1.getTransactionParams)(transactionParams, algod),
|
|
@@ -25,9 +25,43 @@ async function transferAlgos(transfer, algod) {
|
|
|
25
25
|
rekeyTo: undefined,
|
|
26
26
|
});
|
|
27
27
|
if (!sendParams.skipSending) {
|
|
28
|
-
|
|
28
|
+
_1.Config.getLogger(sendParams.suppressLog).debug(`Transferring ${amount.microAlgos}µALGOs from ${(0, transaction_1.getSenderAddress)(from)} to ${to}`);
|
|
29
29
|
}
|
|
30
30
|
return (0, transaction_1.sendTransaction)({ transaction, from, sendParams }, algod);
|
|
31
31
|
}
|
|
32
32
|
exports.transferAlgos = transferAlgos;
|
|
33
|
+
/**
|
|
34
|
+
* Funds a given account using a funding source such that it has a certain amount of algos free to spend (accounting for ALGOs locked in minimum balance requirement).
|
|
35
|
+
*
|
|
36
|
+
* https://developer.algorand.org/docs/get-details/accounts/#minimum-balance
|
|
37
|
+
*
|
|
38
|
+
* @param funding The funding configuration
|
|
39
|
+
* @param algod An algod client
|
|
40
|
+
* @param kmd An optional kmd client
|
|
41
|
+
* @returns undefined if nothing was needed or the transaction send result
|
|
42
|
+
*/
|
|
43
|
+
async function ensureFunded(funding, algod, kmd) {
|
|
44
|
+
const { accountToFund, fundingSource, minSpendingBalance, minFundingIncrement, transactionParams, note, ...sendParams } = funding;
|
|
45
|
+
const addressToFund = typeof accountToFund === 'string' ? accountToFund : (0, transaction_1.getSenderAddress)(accountToFund);
|
|
46
|
+
const accountInfo = await algod.accountInformation(addressToFund).do();
|
|
47
|
+
const balance = Number(accountInfo.amount);
|
|
48
|
+
const minimumBalanceRequirement = (0, _1.microAlgos)(Number(accountInfo['min-balance']));
|
|
49
|
+
const currentSpendingBalance = (0, _1.microAlgos)(balance - minimumBalanceRequirement.microAlgos);
|
|
50
|
+
if (minSpendingBalance > currentSpendingBalance) {
|
|
51
|
+
const from = fundingSource ?? (await (0, _1.getDispenserAccount)(algod, kmd));
|
|
52
|
+
const minFundAmount = (0, _1.microAlgos)(minSpendingBalance.microAlgos - currentSpendingBalance.microAlgos);
|
|
53
|
+
const fundAmount = (0, _1.microAlgos)(Math.max(minFundAmount.microAlgos, minFundingIncrement?.microAlgos ?? 0));
|
|
54
|
+
_1.Config.getLogger(sendParams.suppressLog).info(`Funding ${addressToFund} ${fundAmount} from ${(0, transaction_1.getSenderAddress)(from)} to reach minimum spend amount of ${minSpendingBalance} (balance = ${balance}, min_balance_req = ${minimumBalanceRequirement})`);
|
|
55
|
+
return await transferAlgos({
|
|
56
|
+
from,
|
|
57
|
+
to: addressToFund,
|
|
58
|
+
note: note ?? 'Funding account to meet minimum requirement',
|
|
59
|
+
amount: fundAmount,
|
|
60
|
+
transactionParams,
|
|
61
|
+
...sendParams,
|
|
62
|
+
}, algod);
|
|
63
|
+
}
|
|
64
|
+
return undefined;
|
|
65
|
+
}
|
|
66
|
+
exports.ensureFunded = ensureFunded;
|
|
33
67
|
//# sourceMappingURL=transfer.js.map
|
package/transfer.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"transfer.js","sourceRoot":"","sources":["../src/transfer.ts"],"names":[],"mappings":";;;;;;AAAA,
|
|
1
|
+
{"version":3,"file":"transfer.js","sourceRoot":"","sources":["../src/transfer.ts"],"names":[],"mappings":";;;;;;AAAA,sDAA+C;AAC/C,yBAA4D;AAC5D,+CAA8G;AAI9G;;;;;GAKG;AACI,KAAK,UAAU,aAAa,CAAC,QAA4B,EAAE,KAAc;IAC9E,MAAM,EAAE,IAAI,EAAE,EAAE,EAAE,MAAM,EAAE,IAAI,EAAE,iBAAiB,EAAE,GAAG,UAAU,EAAE,GAAG,QA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