@algorandfoundation/algokit-utils 1.0.0-beta.4 → 1.0.0-beta.41
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 +9 -2
- package/{dist/account.d.ts → account.d.ts} +41 -36
- package/account.d.ts.map +1 -0
- package/{dist/account.js → account.js} +59 -44
- package/account.js.map +1 -0
- 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/{dist/deploy-app.js → app-deploy.js} +158 -121
- package/app-deploy.js.map +1 -0
- package/app.d.ts +153 -0
- package/app.d.ts.map +1 -0
- package/app.js +582 -0
- package/app.js.map +1 -0
- package/index.d.ts +14 -0
- package/index.d.ts.map +1 -0
- package/{dist/index.js → index.js} +7 -3
- package/index.js.map +1 -0
- package/{dist/indexer-lookup.d.ts → indexer-lookup.d.ts} +11 -4
- package/indexer-lookup.d.ts.map +1 -0
- package/{dist/indexer-lookup.js → indexer-lookup.js} +19 -9
- package/indexer-lookup.js.map +1 -0
- package/{dist/localnet.d.ts → localnet.d.ts} +10 -10
- package/localnet.d.ts.map +1 -0
- package/{dist/localnet.js → localnet.js} +16 -16
- package/localnet.js.map +1 -0
- package/{dist/network-client.d.ts → network-client.d.ts} +15 -24
- package/network-client.d.ts.map +1 -0
- package/{dist/network-client.js → network-client.js} +16 -16
- package/{dist/network-client.js.map → network-client.js.map} +1 -1
- package/package.json +5 -93
- 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 +121 -0
- package/transaction.d.ts.map +1 -0
- package/transaction.js +364 -0
- package/transaction.js.map +1 -0
- package/transfer.d.ts +22 -0
- package/transfer.d.ts.map +1 -0
- package/transfer.js +67 -0
- package/transfer.js.map +1 -0
- 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/{dist → types}/algo-http-client-with-retry.js +3 -3
- package/types/algo-http-client-with-retry.js.map +1 -0
- package/{dist/types → types}/algod.d.ts +28 -15
- package/types/algod.d.ts.map +1 -0
- package/{dist/algo-amount.d.ts → types/amount.d.ts} +9 -3
- package/types/amount.d.ts.map +1 -0
- package/{dist/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/{dist/types/appspec.js → types/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 +624 -0
- package/types/indexer.d.ts.map +1 -0
- package/{dist/types → types}/indexer.js +9 -0
- package/types/indexer.js.map +1 -0
- package/{dist/config.d.ts → types/logging.d.ts} +2 -16
- package/types/logging.d.ts.map +1 -0
- package/{dist/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/LICENSE +0 -21
- package/dist/account.d.ts.map +0 -1
- package/dist/account.js.map +0 -1
- package/dist/algo-amount.d.ts.map +0 -1
- package/dist/algo-amount.js.map +0 -1
- package/dist/algo-http-client-with-retry.d.ts.map +0 -1
- package/dist/algo-http-client-with-retry.js.map +0 -1
- package/dist/app.d.ts +0 -150
- package/dist/app.d.ts.map +0 -1
- package/dist/app.js +0 -156
- package/dist/app.js.map +0 -1
- package/dist/application-client.d.ts +0 -71
- package/dist/application-client.d.ts.map +0 -1
- package/dist/application-client.js +0 -145
- package/dist/application-client.js.map +0 -1
- package/dist/config.d.ts.map +0 -1
- package/dist/config.js.map +0 -1
- package/dist/deploy-app.d.ts +0 -149
- package/dist/deploy-app.d.ts.map +0 -1
- package/dist/deploy-app.js.map +0 -1
- package/dist/index.d.ts +0 -11
- package/dist/index.d.ts.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/indexer-lookup.d.ts.map +0 -1
- package/dist/indexer-lookup.js.map +0 -1
- package/dist/localnet.d.ts.map +0 -1
- package/dist/localnet.js.map +0 -1
- package/dist/network-client.d.ts.map +0 -1
- package/dist/package.json +0 -20
- package/dist/transaction.d.ts +0 -152
- package/dist/transaction.d.ts.map +0 -1
- package/dist/transaction.js +0 -268
- package/dist/transaction.js.map +0 -1
- package/dist/transfer.d.ts +0 -24
- package/dist/transfer.d.ts.map +0 -1
- package/dist/transfer.js +0 -33
- package/dist/transfer.js.map +0 -1
- package/dist/types/algod.d.ts.map +0 -1
- package/dist/types/appspec.d.ts +0 -79
- package/dist/types/appspec.d.ts.map +0 -1
- package/dist/types/appspec.js.map +0 -1
- package/dist/types/indexer.d.ts +0 -314
- package/dist/types/indexer.d.ts.map +0 -1
- package/dist/types/indexer.js.map +0 -1
- package/dist/urlTokenBaseHTTPClient.d.ts.map +0 -1
- package/dist/urlTokenBaseHTTPClient.js.map +0 -1
- /package/{dist → types}/algo-http-client-with-retry.d.ts +0 -0
- /package/{dist/types → types}/algod.js +0 -0
- /package/{dist/types → types}/algod.js.map +0 -0
- /package/{dist → types}/urlTokenBaseHTTPClient.d.ts +0 -0
- /package/{dist → types}/urlTokenBaseHTTPClient.js +0 -0
package/transaction.d.ts
ADDED
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
import algosdk, { Algodv2, AtomicTransactionComposer, SuggestedParams, Transaction } from 'algosdk';
|
|
2
|
+
import { PendingTransactionResponse } from './types/algod';
|
|
3
|
+
import { AlgoAmount } from './types/amount';
|
|
4
|
+
import { AtomicTransactionComposerToSend, SendAtomicTransactionComposerResults, SendTransactionFrom, SendTransactionParams, SendTransactionResult, TransactionGroupToSend, TransactionNote } from './types/transaction';
|
|
5
|
+
/** Encodes a transaction note into a byte array ready to be included in an Algorand transaction.
|
|
6
|
+
*
|
|
7
|
+
* @param note The transaction note
|
|
8
|
+
* @returns the transaction note ready for inclusion in a transaction
|
|
9
|
+
*
|
|
10
|
+
* Case on the value of `data` this either either be:
|
|
11
|
+
* * `null` | `undefined`: `undefined`
|
|
12
|
+
* * `string`: The string value
|
|
13
|
+
* * Uint8Array: passthrough
|
|
14
|
+
* * Arc2TransactionNote object: ARC-0002 compatible transaction note
|
|
15
|
+
* * Else: The object/value converted into a JSON string representation
|
|
16
|
+
*/
|
|
17
|
+
export declare function encodeTransactionNote(note?: TransactionNote): Uint8Array | undefined;
|
|
18
|
+
/**
|
|
19
|
+
* Returns the public address of the given transaction sender.
|
|
20
|
+
* @param sender A transaction sender
|
|
21
|
+
* @returns The public address
|
|
22
|
+
*/
|
|
23
|
+
export declare const getSenderAddress: (sender: SendTransactionFrom) => string;
|
|
24
|
+
/**
|
|
25
|
+
* Returns a `TransactionSigner` for the given transaction sender.
|
|
26
|
+
* This function has memoization, so will return the same transaction signer for a given sender.
|
|
27
|
+
* @param sender A transaction sender
|
|
28
|
+
* @returns A transaction signer
|
|
29
|
+
*/
|
|
30
|
+
export declare const getSenderTransactionSigner: (val: SendTransactionFrom) => algosdk.TransactionSigner;
|
|
31
|
+
/**
|
|
32
|
+
* Signs a single transaction by the given signer.
|
|
33
|
+
* @param transaction The transaction to sign
|
|
34
|
+
* @param signer The signer to sign
|
|
35
|
+
* @returns The signed transaction as a `Uint8Array`
|
|
36
|
+
*/
|
|
37
|
+
export declare const signTransaction: (transaction: Transaction, signer: SendTransactionFrom) => Promise<Uint8Array>;
|
|
38
|
+
/** Prepares a transaction for sending and then (if instructed) signs and sends the given transaction to the chain.
|
|
39
|
+
*
|
|
40
|
+
* @param send The details for the transaction to prepare/send, including:
|
|
41
|
+
* * `transaction`: The unsigned transaction
|
|
42
|
+
* * `from`: The account to sign the transaction with: either an account with private key loaded or a logic signature account
|
|
43
|
+
* * `config`: The sending configuration for this transaction
|
|
44
|
+
* @param algod An algod client
|
|
45
|
+
*
|
|
46
|
+
* @returns An object with transaction (`transaction`) and (if `skipWaiting` is `false` or `undefined`) confirmation (`confirmation`)
|
|
47
|
+
*/
|
|
48
|
+
export declare const sendTransaction: (send: {
|
|
49
|
+
transaction: Transaction;
|
|
50
|
+
from: SendTransactionFrom;
|
|
51
|
+
sendParams?: SendTransactionParams;
|
|
52
|
+
}, algod: Algodv2) => Promise<SendTransactionResult>;
|
|
53
|
+
/**
|
|
54
|
+
* Signs and sends transactions that have been collected by an `AtomicTransactionComposer`.
|
|
55
|
+
* @param atcSend The parameters controlling the send, including:
|
|
56
|
+
* * `atc` The `AtomicTransactionComposer`
|
|
57
|
+
* * `sendParams` The parameters to control the send behaviour
|
|
58
|
+
* @param algod An algod client
|
|
59
|
+
* @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`)
|
|
60
|
+
*/
|
|
61
|
+
export declare const sendAtomicTransactionComposer: (atcSend: AtomicTransactionComposerToSend, algod: Algodv2) => Promise<SendAtomicTransactionComposerResults>;
|
|
62
|
+
/**
|
|
63
|
+
* Performs a dry run of the transactions loaded into the given AtomicTransactionComposer`
|
|
64
|
+
* @param atc The AtomicTransactionComposer` with transaction(s) loaded
|
|
65
|
+
* @param algod An Algod client
|
|
66
|
+
* @returns The dryrun result
|
|
67
|
+
*/
|
|
68
|
+
export declare function performAtomicTransactionComposerDryrun(atc: AtomicTransactionComposer, algod: Algodv2): Promise<algosdk.DryrunResult>;
|
|
69
|
+
/**
|
|
70
|
+
* Signs and sends a group of [up to 16](https://developer.algorand.org/docs/get-details/atomic_transfers/#create-transactions) transactions to the chain
|
|
71
|
+
*
|
|
72
|
+
* @param groupSend The group details to send, with:
|
|
73
|
+
* * `transactions`: The array of transactions to send along with their signing account
|
|
74
|
+
* * `sendParams`: The parameters to dictate how the group is sent
|
|
75
|
+
* @param algod An algod client
|
|
76
|
+
* @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`)
|
|
77
|
+
*/
|
|
78
|
+
export declare const sendGroupOfTransactions: (groupSend: TransactionGroupToSend, algod: Algodv2) => Promise<Omit<SendAtomicTransactionComposerResults, "returns">>;
|
|
79
|
+
/**
|
|
80
|
+
* Wait until the transaction is confirmed or rejected, or until `timeout`
|
|
81
|
+
* number of rounds have passed.
|
|
82
|
+
*
|
|
83
|
+
* @param algod An algod client
|
|
84
|
+
* @param transactionId The transaction ID to wait for
|
|
85
|
+
* @param maxRoundsToWait Maximum number of rounds to wait
|
|
86
|
+
*
|
|
87
|
+
* @return Pending transaction information
|
|
88
|
+
* @throws Throws an error if the transaction is not confirmed or rejected in the next `timeout` rounds
|
|
89
|
+
*/
|
|
90
|
+
export declare const waitForConfirmation: (transactionId: string, maxRoundsToWait: number, algod: Algodv2) => Promise<PendingTransactionResponse>;
|
|
91
|
+
/**
|
|
92
|
+
* Limit the acceptable fee to a defined amount of µALGOs.
|
|
93
|
+
* This also sets the transaction to be flatFee to ensure the transaction only succeeds at
|
|
94
|
+
* the estimated rate.
|
|
95
|
+
* @param transaction The transaction to cap or suggested params object about to be used to create a transaction
|
|
96
|
+
* @param maxAcceptableFee The maximum acceptable fee to pay
|
|
97
|
+
*/
|
|
98
|
+
export declare function capTransactionFee(transaction: algosdk.Transaction | SuggestedParams, maxAcceptableFee: AlgoAmount): void;
|
|
99
|
+
/**
|
|
100
|
+
* Allows for control of fees on a `Transaction` or `SuggestedParams` object
|
|
101
|
+
* @param transaction The transaction or suggested params
|
|
102
|
+
* @param feeControl The fee control parameters
|
|
103
|
+
*/
|
|
104
|
+
export declare function controlFees<T extends SuggestedParams | Transaction>(transaction: T, feeControl: {
|
|
105
|
+
fee?: AlgoAmount;
|
|
106
|
+
maxFee?: AlgoAmount;
|
|
107
|
+
}): T;
|
|
108
|
+
/**
|
|
109
|
+
* Returns suggested transaction parameters from algod unless some are already provided.
|
|
110
|
+
* @param params Optionally provide parameters to use
|
|
111
|
+
* @param algod Algod algod
|
|
112
|
+
* @returns The suggested transaction parameters
|
|
113
|
+
*/
|
|
114
|
+
export declare function getTransactionParams(params: SuggestedParams | undefined, algod: Algodv2): Promise<algosdk.SuggestedParams>;
|
|
115
|
+
/**
|
|
116
|
+
* Returns the array of transactions currently present in the given `AtomicTransactionComposer`
|
|
117
|
+
* @param atc The atomic transaction composer
|
|
118
|
+
* @returns The array of transactions with signers
|
|
119
|
+
*/
|
|
120
|
+
export declare function getAtomicTransactionComposerTransactions(atc: AtomicTransactionComposer): algosdk.TransactionWithSigner[];
|
|
121
|
+
//# sourceMappingURL=transaction.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"transaction.d.ts","sourceRoot":"","sources":["../src/transaction.ts"],"names":[],"mappings":"AAAA,OAAO,OAAO,EAAE,EAAE,OAAO,EAAE,yBAAyB,EAAE,eAAe,EAAE,WAAW,EAAqB,MAAM,SAAS,CAAA;AAGtH,OAAO,EAAE,0BAA0B,EAAE,MAAM,eAAe,CAAA;AAC1D,OAAO,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAA;AAE3C,OAAO,EACL,+BAA+B,EAC/B,oCAAoC,EACpC,mBAAmB,EACnB,qBAAqB,EACrB,qBAAqB,EACrB,sBAAsB,EACtB,eAAe,EAChB,MAAM,qBAAqB,CAAA;AAE5B;;;;;;;;;;;GAWG;AACH,wBAAgB,qBAAqB,CAAC,IAAI,CAAC,EAAE,eAAe,GAAG,UAAU,G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oCAE7F;AAED;;;;GAIG;AACH,wBAAgB,wCAAwC,CAAC,GAAG,EAAE,yBAAyB,mCAMtF"}
|
package/transaction.js
ADDED
|
@@ -0,0 +1,364 @@
|
|
|
1
|
+
"use strict";
|
|
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;
|
|
24
|
+
};
|
|
25
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
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"));
|
|
28
|
+
const buffer_1 = require("buffer");
|
|
29
|
+
const _1 = require("./");
|
|
30
|
+
/** Encodes a transaction note into a byte array ready to be included in an Algorand transaction.
|
|
31
|
+
*
|
|
32
|
+
* @param note The transaction note
|
|
33
|
+
* @returns the transaction note ready for inclusion in a transaction
|
|
34
|
+
*
|
|
35
|
+
* Case on the value of `data` this either either be:
|
|
36
|
+
* * `null` | `undefined`: `undefined`
|
|
37
|
+
* * `string`: The string value
|
|
38
|
+
* * Uint8Array: passthrough
|
|
39
|
+
* * Arc2TransactionNote object: ARC-0002 compatible transaction note
|
|
40
|
+
* * Else: The object/value converted into a JSON string representation
|
|
41
|
+
*/
|
|
42
|
+
function encodeTransactionNote(note) {
|
|
43
|
+
if (note == null || typeof note === 'undefined') {
|
|
44
|
+
return undefined;
|
|
45
|
+
}
|
|
46
|
+
else if (typeof note === 'object' && note.constructor === Uint8Array) {
|
|
47
|
+
return note;
|
|
48
|
+
}
|
|
49
|
+
else if (typeof note === 'object' && 'dAppName' in note) {
|
|
50
|
+
const arc2Payload = `${note.dAppName}:${note.format}${typeof note.data === 'string' ? note.data : JSON.stringify(note.data)}`;
|
|
51
|
+
const encoder = new TextEncoder();
|
|
52
|
+
return encoder.encode(arc2Payload);
|
|
53
|
+
}
|
|
54
|
+
else {
|
|
55
|
+
const n = typeof note === 'string' ? note : JSON.stringify(note);
|
|
56
|
+
const encoder = new TextEncoder();
|
|
57
|
+
return encoder.encode(n);
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
exports.encodeTransactionNote = encodeTransactionNote;
|
|
61
|
+
/**
|
|
62
|
+
* Returns the public address of the given transaction sender.
|
|
63
|
+
* @param sender A transaction sender
|
|
64
|
+
* @returns The public address
|
|
65
|
+
*/
|
|
66
|
+
const getSenderAddress = function (sender) {
|
|
67
|
+
return 'addr' in sender ? sender.addr : sender.address();
|
|
68
|
+
};
|
|
69
|
+
exports.getSenderAddress = getSenderAddress;
|
|
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.
|
|
108
|
+
*
|
|
109
|
+
* @param send The details for the transaction to prepare/send, including:
|
|
110
|
+
* * `transaction`: The unsigned transaction
|
|
111
|
+
* * `from`: The account to sign the transaction with: either an account with private key loaded or a logic signature account
|
|
112
|
+
* * `config`: The sending configuration for this transaction
|
|
113
|
+
* @param algod An algod client
|
|
114
|
+
*
|
|
115
|
+
* @returns An object with transaction (`transaction`) and (if `skipWaiting` is `false` or `undefined`) confirmation (`confirmation`)
|
|
116
|
+
*/
|
|
117
|
+
const sendTransaction = async function (send, algod) {
|
|
118
|
+
const { transaction, from, sendParams } = send;
|
|
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 };
|
|
124
|
+
}
|
|
125
|
+
if (skipSending) {
|
|
126
|
+
return { transaction };
|
|
127
|
+
}
|
|
128
|
+
const signedTransaction = await (0, exports.signTransaction)(transaction, from);
|
|
129
|
+
await algod.sendRawTransaction(signedTransaction).do();
|
|
130
|
+
_1.Config.getLogger(suppressLog).info(`Sent transaction ID ${transaction.txID()} ${transaction.type} from ${(0, exports.getSenderAddress)(from)}`);
|
|
131
|
+
let confirmation = undefined;
|
|
132
|
+
if (!skipWaiting) {
|
|
133
|
+
confirmation = await (0, exports.waitForConfirmation)(transaction.txID(), maxRoundsToWaitForConfirmation ?? 5, algod);
|
|
134
|
+
}
|
|
135
|
+
return { transaction, confirmation };
|
|
136
|
+
};
|
|
137
|
+
exports.sendTransaction = sendTransaction;
|
|
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;
|
|
221
|
+
/**
|
|
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
|
|
223
|
+
*
|
|
224
|
+
* @param groupSend The group details to send, with:
|
|
225
|
+
* * `transactions`: The array of transactions to send along with their signing account
|
|
226
|
+
* * `sendParams`: The parameters to dictate how the group is sent
|
|
227
|
+
* @param algod An algod client
|
|
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`)
|
|
229
|
+
*/
|
|
230
|
+
const sendGroupOfTransactions = async function (groupSend, algod) {
|
|
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.`);
|
|
243
|
+
}
|
|
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));
|
|
254
|
+
};
|
|
255
|
+
exports.sendGroupOfTransactions = sendGroupOfTransactions;
|
|
256
|
+
/**
|
|
257
|
+
* Wait until the transaction is confirmed or rejected, or until `timeout`
|
|
258
|
+
* number of rounds have passed.
|
|
259
|
+
*
|
|
260
|
+
* @param algod An algod client
|
|
261
|
+
* @param transactionId The transaction ID to wait for
|
|
262
|
+
* @param maxRoundsToWait Maximum number of rounds to wait
|
|
263
|
+
*
|
|
264
|
+
* @return Pending transaction information
|
|
265
|
+
* @throws Throws an error if the transaction is not confirmed or rejected in the next `timeout` rounds
|
|
266
|
+
*/
|
|
267
|
+
const waitForConfirmation = async function (transactionId, maxRoundsToWait, algod) {
|
|
268
|
+
if (maxRoundsToWait < 0) {
|
|
269
|
+
throw new Error(`Invalid timeout, received ${maxRoundsToWait}, expected > 0`);
|
|
270
|
+
}
|
|
271
|
+
// Get current round
|
|
272
|
+
const status = await algod.status().do();
|
|
273
|
+
if (status === undefined) {
|
|
274
|
+
throw new Error('Unable to get node status');
|
|
275
|
+
}
|
|
276
|
+
// Loop for up to `timeout` rounds looking for a confirmed transaction
|
|
277
|
+
const startRound = status['last-round'] + 1;
|
|
278
|
+
let currentRound = startRound;
|
|
279
|
+
while (currentRound < startRound + maxRoundsToWait) {
|
|
280
|
+
const pendingInfo = (await algod.pendingTransactionInformation(transactionId).do());
|
|
281
|
+
if (pendingInfo !== undefined) {
|
|
282
|
+
const confirmedRound = pendingInfo['confirmed-round'];
|
|
283
|
+
if (confirmedRound && confirmedRound > 0) {
|
|
284
|
+
return pendingInfo;
|
|
285
|
+
}
|
|
286
|
+
else {
|
|
287
|
+
const poolError = pendingInfo['pool-error'];
|
|
288
|
+
if (poolError != null && poolError.length > 0) {
|
|
289
|
+
// If there was a pool error, then the transaction has been rejected!
|
|
290
|
+
throw new Error(`Transaction ${transactionId} was rejected; pool error: ${poolError}`);
|
|
291
|
+
}
|
|
292
|
+
}
|
|
293
|
+
}
|
|
294
|
+
await algod.statusAfterBlock(currentRound).do();
|
|
295
|
+
currentRound++;
|
|
296
|
+
}
|
|
297
|
+
throw new Error(`Transaction ${transactionId} not confirmed after ${maxRoundsToWait} rounds`);
|
|
298
|
+
};
|
|
299
|
+
exports.waitForConfirmation = waitForConfirmation;
|
|
300
|
+
/**
|
|
301
|
+
* Limit the acceptable fee to a defined amount of µALGOs.
|
|
302
|
+
* This also sets the transaction to be flatFee to ensure the transaction only succeeds at
|
|
303
|
+
* the estimated rate.
|
|
304
|
+
* @param transaction The transaction to cap or suggested params object about to be used to create a transaction
|
|
305
|
+
* @param maxAcceptableFee The maximum acceptable fee to pay
|
|
306
|
+
*/
|
|
307
|
+
function capTransactionFee(transaction, maxAcceptableFee) {
|
|
308
|
+
// If a flat fee hasn't already been defined
|
|
309
|
+
if (!transaction.flatFee) {
|
|
310
|
+
// Once a transaction has been constructed by algosdk, transaction.fee indicates what the total transaction fee
|
|
311
|
+
// Will be based on the current suggested fee-per-byte value.
|
|
312
|
+
if (transaction.fee > maxAcceptableFee.microAlgos) {
|
|
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.`);
|
|
314
|
+
}
|
|
315
|
+
else if (transaction.fee > algosdk_1.default.ALGORAND_MIN_TX_FEE) {
|
|
316
|
+
_1.Config.logger.warn(`Algorand network congestion fees are in effect. This transaction will incur a fee of ${transaction.fee} µALGOs.`);
|
|
317
|
+
}
|
|
318
|
+
// Now set the flat on the transaction. Otherwise the network may increase the fee above our cap and perform the transaction.
|
|
319
|
+
transaction.flatFee = true;
|
|
320
|
+
}
|
|
321
|
+
}
|
|
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;
|
|
340
|
+
/**
|
|
341
|
+
* Returns suggested transaction parameters from algod unless some are already provided.
|
|
342
|
+
* @param params Optionally provide parameters to use
|
|
343
|
+
* @param algod Algod algod
|
|
344
|
+
* @returns The suggested transaction parameters
|
|
345
|
+
*/
|
|
346
|
+
async function getTransactionParams(params, algod) {
|
|
347
|
+
return params ? { ...params } : await algod.getTransactionParams().do();
|
|
348
|
+
}
|
|
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;
|
|
364
|
+
//# sourceMappingURL=transaction.js.map
|
|
@@ -0,0 +1 @@
|
|
|
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,I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;KAChC;IAAC,MAAM;QACN,OAAO,EAAE,CAAA;KACV;AACH,CAAC;AAND,4FAMC"}
|
package/transfer.d.ts
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { Algodv2, Kmd } from 'algosdk';
|
|
2
|
+
import { SendTransactionResult } from './types/transaction';
|
|
3
|
+
import { AlgoTransferParams, EnsureFundedParams } from './types/transfer';
|
|
4
|
+
/**
|
|
5
|
+
* Transfer ALGOs between two accounts.
|
|
6
|
+
* @param transfer The transfer definition
|
|
7
|
+
* @param algod An algod client
|
|
8
|
+
* @returns The transaction object and optionally the confirmation if it was sent to the chain (`skipSending` is `false` or unset)
|
|
9
|
+
*/
|
|
10
|
+
export declare function transferAlgos(transfer: AlgoTransferParams, algod: Algodv2): Promise<SendTransactionResult>;
|
|
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>;
|
|
22
|
+
//# sourceMappingURL=transfer.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
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
ADDED
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.ensureFunded = exports.transferAlgos = void 0;
|
|
7
|
+
const algosdk_1 = __importDefault(require("algosdk"));
|
|
8
|
+
const _1 = require("./");
|
|
9
|
+
const transaction_1 = require("./transaction");
|
|
10
|
+
/**
|
|
11
|
+
* Transfer ALGOs between two accounts.
|
|
12
|
+
* @param transfer The transfer definition
|
|
13
|
+
* @param algod An algod client
|
|
14
|
+
* @returns The transaction object and optionally the confirmation if it was sent to the chain (`skipSending` is `false` or unset)
|
|
15
|
+
*/
|
|
16
|
+
async function transferAlgos(transfer, algod) {
|
|
17
|
+
const { from, to, amount, note, transactionParams, ...sendParams } = transfer;
|
|
18
|
+
const transaction = algosdk_1.default.makePaymentTxnWithSuggestedParamsFromObject({
|
|
19
|
+
from: (0, transaction_1.getSenderAddress)(from),
|
|
20
|
+
to: typeof to === 'string' ? to : (0, transaction_1.getSenderAddress)(to),
|
|
21
|
+
amount: amount.microAlgos,
|
|
22
|
+
note: (0, transaction_1.encodeTransactionNote)(note),
|
|
23
|
+
suggestedParams: await (0, transaction_1.getTransactionParams)(transactionParams, algod),
|
|
24
|
+
closeRemainderTo: undefined,
|
|
25
|
+
rekeyTo: undefined,
|
|
26
|
+
});
|
|
27
|
+
if (!sendParams.skipSending) {
|
|
28
|
+
_1.Config.getLogger(sendParams.suppressLog).debug(`Transferring ${amount.microAlgos}µALGOs from ${(0, transaction_1.getSenderAddress)(from)} to ${to}`);
|
|
29
|
+
}
|
|
30
|
+
return (0, transaction_1.sendTransaction)({ transaction, from, sendParams }, algod);
|
|
31
|
+
}
|
|
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;
|
|
67
|
+
//# sourceMappingURL=transfer.js.map
|
package/transfer.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
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,QAAQ,CAAA;IAE7E,MAAM,WAAW,GAAG,iBAAO,CAAC,2CAA2C,CAAC;QACtE,IAAI,EAAE,IAAA,8BAAgB,EAAC,IAAI,CAAC;QAC5B,EAAE,EAAE,OAAO,EAAE,KAAK,QAAQ,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,IAAA,8BAAgB,EAAC,EAAE,CAAC;QACtD,MAAM,EAAE,MAAM,CAAC,UAAU;QACzB,IAAI,EAAE,IAAA,mCAAqB,EAAC,IAAI,CAAC;QACjC,eAAe,EAAE,MAAM,IAAA,kCAAoB,EAAC,iBAAiB,EAAE,KAAK,CAAC;QACrE,gBAAgB,EAAE,SAAS;QAC3B,OAAO,EAAE,SAAS;KACnB,CAAC,CAAA;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