@algorandfoundation/algokit-utils 1.0.0-beta.27 → 1.0.0-beta.29

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 ADDED
@@ -0,0 +1,31 @@
1
+ # AlgoKit TypeScript Utilities
2
+
3
+ A set of core Algorand utilities written in TypeScript and released via npm that make it easier to build solutions on Algorand. This project is part of [AlgoKit](https://github.com/algorandfoundation/algokit-cli).
4
+
5
+ The goal of this library is to provide intuitive, productive utility functions that make it easier, quicker and safer to build applications on Algorand. Largely these functions wrap the underlying Algorand SDK, but provide a higher level interface with sensible defaults and capabilities for common tasks.
6
+
7
+ Note: If you prefer Python there's an equivalent [Python utility library](https://github.com/algorandfoundation/algokit-utils-py).
8
+
9
+ [Install](#install) | [Documentation](docs/README.md)
10
+
11
+ ## Install
12
+
13
+ This library can be installed from NPM using your favourite npm client, e.g.:
14
+
15
+ ```
16
+ npm install @algorandfoundation/algokit-utils
17
+ ```
18
+
19
+ ## Guiding principles
20
+
21
+ This library follows the [Guiding Principles of AlgoKit](https://github.com/algorandfoundation/algokit-cli/docs/algokit.md#guiding-principles).
22
+
23
+ ## Contributing
24
+
25
+ This is an open source project managed by the Algorand Foundation. See the [AlgoKit contributing page](https://github.com/algorandfoundation/algokit-cli/blob/main/CONTRIBUTING.MD) to learn about making improvements.
26
+
27
+ To successfully run the tests in this repository you need to be running LocalNet via [AlgoKit](https://github.com/algorandfoundation/algokit-cli):
28
+
29
+ ```
30
+ algokit localnet start
31
+ ```
package/account.d.ts CHANGED
@@ -30,6 +30,12 @@ export declare function transactionSignerAccount(signer: TransactionSigner, send
30
30
  * never commit it into source control and ideally load it from the environment (ideally via a secret storage service) rather than the file system.
31
31
  */
32
32
  export declare function mnemonicAccount(mnemonicSecret: string): Account;
33
+ /** Returns a new, random Algorand account with secret key loaded.
34
+ *
35
+ * This is a wrapper around algosdk.generateAccount to provide a more friendly/obvious name.
36
+ *
37
+ */
38
+ export declare function randomAccount(): Account;
33
39
  /**
34
40
  * Returns an Algorand account with private key loaded by convention based on the given name identifier.
35
41
  *
@@ -75,7 +81,7 @@ export declare function getAccountAddressAsUint8Array(account: Account | string)
75
81
  export declare function getAccountAddressAsString(addressEncodedInB64: string): string;
76
82
  /** Returns an account (with private key loaded) that can act as a dispenser
77
83
  *
78
- * If running on Sandbox then it will return the default dispenser account automatically,
84
+ * If running on LocalNet then it will return the default dispenser account automatically,
79
85
  * otherwise it will load the account mnemonic stored in process.env.DISPENSER_MNEMONIC @see {getAccount}
80
86
  *
81
87
  * @param algod An algod client
package/account.d.ts.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"account.d.ts","sourceRoot":"","sources":["../src/account.ts"],"names":[],"mappings":"AAAA,OAAO,OAAO,EAAE,EAAE,OAAO,EAAE,OAAO,EAAE,GAAG,EAAE,gBAAgB,EAAE,iBAAiB,EAAE,MAAM,SAAS,CAAA;AAI7F,OAAO,EAAqB,eAAe,EAAE,cAAc,EAAE,wBAAwB,EAAE,MAAM,iBAAiB,CAAA;AAC9G,OAAO,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAA;AAE3C;;;;;GAKG;AACH,wBAAgB,eAAe,CAAC,cAAc,EAAE,gBAAgB,EAAE,eAAe,EAAE,CAAC,OAAO,GAAG,cAAc,CAAC,EAAE,mBAE9G;AAED;;;;;GAKG;AACH,wBAAgB,cAAc,CAAC,OAAO,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,kBAE9D;AAED;;;;;GAKG;AACH,wBAAgB,wBAAwB,CAAC,MAAM,EAAE,iBAAiB,EAAE,MAAM,EAAE,MAAM,GAAG,wBAAwB,CAE5G;AAED;;;;;;GAMG;AACH,wBAAgB,eAAe,CAAC,cAAc,EAAE,MAAM,GAAG,OAAO,CAG/D;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AACH,wBAAsB,UAAU,CAC9B,OAAO,EAAE;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,Q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wBAAsB,UAAU,CAC9B,OAAO,EAAE;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,EAAE,UAAU,CAAA;CAAE,GAAG,MAAM,EACzD,KAAK,EAAE,OAAO,EACd,SAAS,CAAC,EAAE,GAAG,GACd,OAAO,CAAC,OAAO,GAAG,cAAc,CAAC,CAmCnC;AAED;;;GAGG;AACH,wBAAgB,6BAA6B,CAAC,OAAO,EAAE,OAAO,GAAG,MAAM,cAEtE;AAED;;;GAGG;AACH,wBAAgB,yBAAyB,CAAC,mBAAmB,EAAE,MAAM,GAAG,MAAM,CAE7E;AAED;;;;;;;GAOG;AACH,wBAAsB,mBAAmB,CAAC,KAAK,EAAE,OAAO,EAAE,GAAG,CAAC,EAAE,GAAG,6CAIlE"}
package/account.js CHANGED
@@ -3,7 +3,7 @@ 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.getDispenserAccount = exports.getAccountAddressAsString = exports.getAccountAddressAsUint8Array = exports.getAccount = exports.mnemonicAccount = exports.transactionSignerAccount = exports.rekeyedAccount = exports.multisigAccount = void 0;
6
+ exports.getDispenserAccount = exports.getAccountAddressAsString = exports.getAccountAddressAsUint8Array = exports.getAccount = exports.randomAccount = exports.mnemonicAccount = exports.transactionSignerAccount = exports.rekeyedAccount = exports.multisigAccount = void 0;
7
7
  const algosdk_1 = __importDefault(require("algosdk"));
8
8
  const _1 = require("./");
9
9
  const localnet_1 = require("./localnet");
@@ -51,6 +51,16 @@ function mnemonicAccount(mnemonicSecret) {
51
51
  return algosdk_1.default.mnemonicToSecretKey(mnemonicSecret);
52
52
  }
53
53
  exports.mnemonicAccount = mnemonicAccount;
54
+ /** Returns a new, random Algorand account with secret key loaded.
55
+ *
56
+ * This is a wrapper around algosdk.generateAccount to provide a more friendly/obvious name.
57
+ *
58
+ */
59
+ function randomAccount() {
60
+ // This method is confusingly named, so this function provides a more dev friendly "wrapper" name
61
+ return algosdk_1.default.generateAccount();
62
+ }
63
+ exports.randomAccount = randomAccount;
54
64
  /**
55
65
  * Returns an Algorand account with private key loaded by convention based on the given name identifier.
56
66
  *
@@ -133,14 +143,14 @@ function getAccountAddressAsString(addressEncodedInB64) {
133
143
  exports.getAccountAddressAsString = getAccountAddressAsString;
134
144
  /** Returns an account (with private key loaded) that can act as a dispenser
135
145
  *
136
- * If running on Sandbox then it will return the default dispenser account automatically,
146
+ * If running on LocalNet then it will return the default dispenser account automatically,
137
147
  * otherwise it will load the account mnemonic stored in process.env.DISPENSER_MNEMONIC @see {getAccount}
138
148
  *
139
149
  * @param algod An algod client
140
150
  * @param kmd A KMD client, if not specified then a default KMD client will be loaded from environment variables @see {getAlgoKmdClient}
141
151
  */
142
152
  async function getDispenserAccount(algod, kmd) {
143
- // If we are running against a sandbox we can use the default account within it, otherwise use an automation account specified via environment variables and ensure it's populated with ALGOs
153
+ // If we are running against LocalNet we can use the default account within it, otherwise use an automation account specified via environment variables and ensure it's populated with ALGOs
144
154
  const canFundFromDefaultAccount = await (0, network_client_1.isLocalNet)(algod);
145
155
  return canFundFromDefaultAccount ? await (0, localnet_1.getLocalNetDispenserAccount)(algod, kmd) : await getAccount(account_1.DISPENSER_ACCOUNT, algod);
146
156
  }
package/account.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"account.js","sourceRoot":"","sources":["../src/account.ts"],"names":[],"mappings":";;;;;;AAAA,sDAA6F;AAC7F,yBAA2B;AAC3B,yCAAqF;AACrF,qDAA6C;AAC7C,6CAA8G;AAG9G;;;;;GAKG;AACH,SAAgB,eAAe,CAAC,cAAgC,EAAE,eAA6C;IAC7G,OAAO,IAAI,yBAAe,CAAC,cAAc,EAAE,eAAe,CAAC,CAAA;AAC7D,CAAC;AAFD,0CAEC;AAED;;;;;GAKG;AACH,SAAgB,cAAc,CAAC,OAAgB,EAAE,MAAc;IAC7D,OAAO,IAAI,wBAAc,C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SAAgB,6BAA6B,CAAC,OAAyB;IACrE,OAAO,iBAAO,CAAC,aAAa,CAAC,OAAO,OAAO,KAAK,QAAQ,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,SAAS,CAAA;AAC9F,CAAC;AAFD,sEAEC;AAED;;;GAGG;AACH,SAAgB,yBAAyB,CAAC,mBAA2B;IACnE,OAAO,iBAAO,CAAC,aAAa,CAAC,MAAM,CAAC,IAAI,CAAC,mBAAmB,EAAE,QAAQ,CAAC,CAAC,CAAA;AAC1E,CAAC;AAFD,8DAEC;AAED;;;;;;;GAOG;AACI,KAAK,UAAU,mBAAmB,CAAC,KAAc,EAAE,GAAS;IACjE,4LAA4L;IAC5L,MAAM,yBAAyB,GAAG,MAAM,IAAA,2BAAU,EAAC,KAAK,CAAC,CAAA;IACzD,OAAO,yBAAyB,CAAC,CAAC,CAAC,MAAM,IAAA,sCAA2B,EAAC,KAAK,EAAE,GAAG,CAAC,CAAC,CAAC,CAAC,MAAM,UAAU,CAAC,2BAAiB,EAAE,KAAK,CAAC,CAAA;AAC/H,CAAC;AAJD,kDAIC"}
package/app.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import algosdk, { ABIValue, Algodv2 } from 'algosdk';
2
2
  import { ApplicationResponse, EvalDelta, PendingTransactionResponse, TealValue } from './types/algod';
3
- import { ABIReturn, AppCallArgs, AppCallParams, AppCallTransactionResult, AppCompilationResult, AppReference, AppState, BoxName, BoxValueRequestParams, BoxValuesRequestParams, CompiledTeal, CreateAppParams, UpdateAppParams } from './types/app';
3
+ import { ABIAppCallArgs, ABIReturn, AppCallArgs, AppCallParams, AppCallTransactionResult, AppCompilationResult, AppReference, AppState, BoxName, BoxValueRequestParams, BoxValuesRequestParams, CompiledTeal, CreateAppParams, RawAppCallArgs, UpdateAppParams } from './types/app';
4
4
  import { SendTransactionFrom } from './types/transaction';
5
5
  /**
6
6
  * Creates a smart contract app, returns the details of the created app.
@@ -81,7 +81,7 @@ export declare function decodeAppState(state: {
81
81
  value: TealValue | EvalDelta;
82
82
  }[]): AppState;
83
83
  /** Returns the app args ready to load onto an app @see {Transaction} object */
84
- export declare function getAppArgsForTransaction(args?: AppCallArgs): {
84
+ export declare function getAppArgsForTransaction(args?: RawAppCallArgs): {
85
85
  accounts: string[] | undefined;
86
86
  appArgs: Uint8Array[] | undefined;
87
87
  boxes: algosdk.BoxReference[] | undefined;
@@ -89,6 +89,16 @@ export declare function getAppArgsForTransaction(args?: AppCallArgs): {
89
89
  foreignAssets: number[] | undefined;
90
90
  lease: Uint8Array | undefined;
91
91
  } | undefined;
92
+ /** Returns the app args ready to load onto an ABI method call in @see AtomicTransactionComposer */
93
+ export declare function getAppArgsForABICall(args: ABIAppCallArgs, from: SendTransactionFrom): {
94
+ method: algosdk.ABIMethod;
95
+ sender: string;
96
+ signer: algosdk.TransactionSigner;
97
+ boxes: algosdk.BoxReference[] | undefined;
98
+ lease: Uint8Array | undefined;
99
+ methodArgs: (string | number | bigint | boolean | Uint8Array | algosdk.ABIValue[] | algosdk.TransactionWithSigner)[];
100
+ rekeyTo: undefined;
101
+ };
92
102
  /**
93
103
  * Gets the current data for the given app from algod.
94
104
  *
package/app.d.ts.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"app.d.ts","sourceRoot":"","sources":["../src/app.ts"],"names":[],"mappings":"AAAA,OAAO,OAAO,EAAE,EAEd,QAAQ,EACR,OAAO,EAMR,MAAM,SAAS,CAAA;AAIhB,OAAO,EAAE,mBAAmB,EAAE,SAAS,EAAE,0BAA0B,EAAE,SAAS,EAAE,MAAM,eAAe,CAAA;AACrG,OAAO,EACL,SAAS,EAET,WAAW,EACX,aAAa,EACb,wBAAwB,EACxB,oBAAoB,EACpB,YAAY,EACZ,QAAQ,EAER,OAAO,EACP,qBAAqB,EACrB,sBAAsB,EACtB,YAAY,EACZ,eAAe,EACf,eAAe,EAChB,MAAM,aAAa,CAAA;AACpB,OAAO,EAAE,mBA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G,UAAU,GAAG,OAAO,CAAC,EAAE,EAAE,KAAK,EAAE,OAAO,GAAG,OAAO,CAAC,UAAU,EAAE,CAAC,CAEvI;AAED;;;;;GAKG;AACH,wBAAsB,yBAAyB,CAAC,OAAO,EAAE,qBAAqB,EAAE,KAAK,EAAE,OAAO,GAAG,OAAO,CAAC,QAAQ,CAAC,CAIjH;AAED;;;;;GAKG;AACH,wBAAsB,0BAA0B,CAAC,OAAO,EAAE,sBAAsB,EAAE,KAAK,EAAE,OAAO,GAAG,OAAO,CAAC,QAAQ,EAAE,CAAC,CAGrH;AAID,wBAAgB,cAAc,CAAC,KAAK,EAAE;IAAE,GAAG,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,SAAS,GAAG,SAAS,CAAA;CAAE,EAAE,GAAG,QAAQ,CAwC/F;AAED,+EAA+E;AAC/E,wBAAgB,wBAAwB,CAAC,IAAI,CAAC,EAAE,cAAc;;;;;;;cAoB7D;AAED,mGAAmG;AACnG,wBAAgB,oBAAoB,CAAC,IAAI,EAAE,cAAc,EAAE,IAAI,EAAE,mBAAmB;;;;;;;;EA2BnF;AAED;;;;;;GAMG;AACH,wBAAsB,aAAa,CAAC,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,OAAO,gCAEhE;AAED;;;;;;GAMG;AACH,wBAAsB,WAAW,CAAC,QAAQ,EAAE,MAAM,EAAE,KAAK,EAAE,OAAO,GAAG,OAAO,CAAC,YAAY,CAAC,CASzF"}
package/app.js CHANGED
@@ -23,7 +23,7 @@ var __importStar = (this && this.__importStar) || function (mod) {
23
23
  return result;
24
24
  };
25
25
  Object.defineProperty(exports, "__esModule", { value: true });
26
- exports.compileTeal = exports.getAppByIndex = exports.getAppArgsForTransaction = exports.decodeAppState = exports.getAppBoxValuesFromABIType = exports.getAppBoxValueFromABIType = exports.getAppBoxValues = exports.getAppBoxValue = exports.getAppBoxNames = exports.getAppLocalState = exports.getAppGlobalState = exports.getABIReturn = exports.callApp = exports.updateApp = exports.createApp = void 0;
26
+ exports.compileTeal = exports.getAppByIndex = exports.getAppArgsForABICall = exports.getAppArgsForTransaction = exports.decodeAppState = exports.getAppBoxValuesFromABIType = exports.getAppBoxValueFromABIType = exports.getAppBoxValues = exports.getAppBoxValue = exports.getAppBoxNames = exports.getAppLocalState = exports.getAppGlobalState = exports.getABIReturn = exports.callApp = exports.updateApp = exports.createApp = void 0;
27
27
  const algosdk_1 = __importStar(require("algosdk"));
28
28
  const buffer_1 = require("buffer");
29
29
  const _1 = require("./");
@@ -41,38 +41,102 @@ async function createApp(create, algod) {
41
41
  const approvalProgram = compiledApproval ? compiledApproval.compiledBase64ToBytes : approval;
42
42
  const compiledClear = typeof clear === 'string' ? await compileTeal(clear, algod) : undefined;
43
43
  const clearProgram = compiledClear ? compiledClear.compiledBase64ToBytes : clear;
44
- const transaction = algosdk_1.default.makeApplicationCreateTxnFromObject({
45
- approvalProgram: approvalProgram,
46
- clearProgram: clearProgram,
47
- numLocalInts: schema.localInts,
48
- numLocalByteSlices: schema.localByteSlices,
49
- numGlobalInts: schema.globalInts,
50
- numGlobalByteSlices: schema.globalByteSlices,
51
- extraPages: schema.extraPages ?? Math.floor((approvalProgram.length + clearProgram.length) / app_1.APP_PAGE_MAX_SIZE),
52
- onComplete: algosdk_1.default.OnApplicationComplete.NoOpOC,
53
- suggestedParams: await (0, transaction_1.getTransactionParams)(transactionParams, algod),
54
- from: (0, transaction_1.getSenderAddress)(from),
55
- note: (0, transaction_1.encodeTransactionNote)(note),
56
- ...getAppArgsForTransaction(args),
57
- rekeyTo: undefined,
58
- });
59
- const { confirmation } = await (0, transaction_1.sendTransaction)({ transaction, from, sendParams }, algod);
60
- if (confirmation) {
61
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
62
- const appId = confirmation['application-index'];
63
- _1.Config.getLogger(sendParams.suppressLog).debug(`Created app ${appId} from creator ${(0, transaction_1.getSenderAddress)(from)}`);
64
- return {
65
- transaction,
66
- confirmation,
67
- appId,
68
- appAddress: algosdk_1.default.getApplicationAddress(appId),
69
- return: getABIReturn(args, confirmation),
70
- compiledApproval,
71
- compiledClear,
72
- };
44
+ if (args && 'method' in args) {
45
+ const atc = attachATC(sendParams);
46
+ const before = (0, transaction_1.getAtomicTransactionComposerTransactions)(atc);
47
+ atc.addMethodCall({
48
+ appID: 0,
49
+ approvalProgram: approvalProgram,
50
+ clearProgram: clearProgram,
51
+ numLocalInts: schema.localInts,
52
+ numLocalByteSlices: schema.localByteSlices,
53
+ numGlobalInts: schema.globalInts,
54
+ numGlobalByteSlices: schema.globalByteSlices,
55
+ extraPages: schema.extraPages ?? Math.floor((approvalProgram.length + clearProgram.length) / app_1.APP_PAGE_MAX_SIZE),
56
+ onComplete: algosdk_1.default.OnApplicationComplete.NoOpOC,
57
+ suggestedParams: (0, transaction_1.controlFees)(await (0, transaction_1.getTransactionParams)(transactionParams, algod), sendParams),
58
+ note: (0, transaction_1.encodeTransactionNote)(note),
59
+ ...getAppArgsForABICall(args, from),
60
+ });
61
+ if (sendParams.skipSending) {
62
+ const after = atc.clone().buildGroup();
63
+ return {
64
+ transaction: after[after.length - 1].txn,
65
+ transactions: after.slice(before.length).map((t) => t.txn),
66
+ appId: 0,
67
+ appAddress: '',
68
+ compiledApproval,
69
+ compiledClear,
70
+ };
71
+ }
72
+ const result = await (0, transaction_1.sendAtomicTransactionComposer)({ atc, sendParams }, algod);
73
+ const confirmation = result.confirmations ? result.confirmations[result.confirmations?.length - 1] : undefined;
74
+ if (confirmation) {
75
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
76
+ const appId = confirmation['application-index'];
77
+ _1.Config.getLogger(sendParams.suppressLog).debug(`Created app ${appId} from creator ${(0, transaction_1.getSenderAddress)(from)}`);
78
+ return {
79
+ transactions: result.transactions,
80
+ confirmations: result.confirmations,
81
+ return: confirmation ? getABIReturn(args, confirmation) : undefined,
82
+ transaction: result.transactions[result.transactions.length - 1],
83
+ confirmation: confirmation,
84
+ appId,
85
+ appAddress: algosdk_1.default.getApplicationAddress(appId),
86
+ compiledApproval,
87
+ compiledClear,
88
+ };
89
+ }
90
+ else {
91
+ return {
92
+ transactions: result.transactions,
93
+ confirmations: result.confirmations,
94
+ return: confirmation ? getABIReturn(args, confirmation) : undefined,
95
+ transaction: result.transactions[result.transactions.length - 1],
96
+ confirmation: confirmation,
97
+ appId: 0,
98
+ appAddress: '',
99
+ compiledApproval,
100
+ compiledClear,
101
+ };
102
+ }
73
103
  }
74
104
  else {
75
- return { transaction, appId: 0, appAddress: '', compiledApproval, compiledClear };
105
+ const transaction = algosdk_1.default.makeApplicationCreateTxnFromObject({
106
+ approvalProgram: approvalProgram,
107
+ clearProgram: clearProgram,
108
+ numLocalInts: schema.localInts,
109
+ numLocalByteSlices: schema.localByteSlices,
110
+ numGlobalInts: schema.globalInts,
111
+ numGlobalByteSlices: schema.globalByteSlices,
112
+ extraPages: schema.extraPages ?? Math.floor((approvalProgram.length + clearProgram.length) / app_1.APP_PAGE_MAX_SIZE),
113
+ onComplete: algosdk_1.default.OnApplicationComplete.NoOpOC,
114
+ suggestedParams: await (0, transaction_1.getTransactionParams)(transactionParams, algod),
115
+ from: (0, transaction_1.getSenderAddress)(from),
116
+ note: (0, transaction_1.encodeTransactionNote)(note),
117
+ ...getAppArgsForTransaction(args),
118
+ rekeyTo: undefined,
119
+ });
120
+ const { confirmation } = await (0, transaction_1.sendTransaction)({ transaction, from, sendParams }, algod);
121
+ if (confirmation) {
122
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
123
+ const appId = confirmation['application-index'];
124
+ _1.Config.getLogger(sendParams.suppressLog).debug(`Created app ${appId} from creator ${(0, transaction_1.getSenderAddress)(from)}`);
125
+ return {
126
+ transaction,
127
+ transactions: [transaction],
128
+ confirmation,
129
+ confirmations: confirmation ? [confirmation] : undefined,
130
+ appId,
131
+ appAddress: algosdk_1.default.getApplicationAddress(appId),
132
+ return: getABIReturn(args, confirmation),
133
+ compiledApproval,
134
+ compiledClear,
135
+ };
136
+ }
137
+ else {
138
+ return { transaction, transactions: [transaction], appId: 0, appAddress: '', compiledApproval, compiledClear };
139
+ }
76
140
  }
77
141
  }
78
142
  exports.createApp = createApp;
@@ -88,26 +152,66 @@ async function updateApp(update, algod) {
88
152
  const approvalProgram = compiledApproval ? compiledApproval.compiledBase64ToBytes : approval;
89
153
  const compiledClear = typeof clear === 'string' ? await compileTeal(clear, algod) : undefined;
90
154
  const clearProgram = compiledClear ? compiledClear.compiledBase64ToBytes : clear;
91
- const transaction = algosdk_1.default.makeApplicationUpdateTxnFromObject({
92
- appIndex: appId,
93
- approvalProgram: approvalProgram,
94
- clearProgram: clearProgram,
95
- suggestedParams: await (0, transaction_1.getTransactionParams)(transactionParams, algod),
96
- from: (0, transaction_1.getSenderAddress)(from),
97
- note: (0, transaction_1.encodeTransactionNote)(note),
98
- ...getAppArgsForTransaction(args),
99
- rekeyTo: undefined,
100
- });
101
155
  _1.Config.getLogger(sendParams.suppressLog).debug(`Updating app ${appId}`);
102
- const result = await (0, transaction_1.sendTransaction)({ transaction, from, sendParams }, algod);
103
- return {
104
- ...result,
105
- return: getABIReturn(args, result.confirmation),
106
- compiledApproval,
107
- compiledClear,
108
- };
156
+ if (args && 'method' in args) {
157
+ const atc = attachATC(sendParams);
158
+ const before = (0, transaction_1.getAtomicTransactionComposerTransactions)(atc);
159
+ atc.addMethodCall({
160
+ appID: appId,
161
+ onComplete: algosdk_1.OnApplicationComplete.UpdateApplicationOC,
162
+ approvalProgram: approvalProgram,
163
+ clearProgram: clearProgram,
164
+ suggestedParams: (0, transaction_1.controlFees)(await (0, transaction_1.getTransactionParams)(transactionParams, algod), sendParams),
165
+ note: (0, transaction_1.encodeTransactionNote)(note),
166
+ ...getAppArgsForABICall(args, from),
167
+ });
168
+ if (sendParams.skipSending) {
169
+ const after = atc.clone().buildGroup();
170
+ return {
171
+ transaction: after[after.length - 1].txn,
172
+ transactions: after.slice(before.length).map((t) => t.txn),
173
+ };
174
+ }
175
+ const result = await (0, transaction_1.sendAtomicTransactionComposer)({ atc, sendParams }, algod);
176
+ const confirmation = result.confirmations ? result.confirmations[result.confirmations?.length - 1] : undefined;
177
+ return {
178
+ transactions: result.transactions,
179
+ confirmations: result.confirmations,
180
+ return: confirmation ? getABIReturn(args, confirmation) : undefined,
181
+ transaction: result.transactions[result.transactions.length - 1],
182
+ confirmation: confirmation,
183
+ };
184
+ }
185
+ else {
186
+ const transaction = algosdk_1.default.makeApplicationUpdateTxnFromObject({
187
+ appIndex: appId,
188
+ approvalProgram: approvalProgram,
189
+ clearProgram: clearProgram,
190
+ suggestedParams: await (0, transaction_1.getTransactionParams)(transactionParams, algod),
191
+ from: (0, transaction_1.getSenderAddress)(from),
192
+ note: (0, transaction_1.encodeTransactionNote)(note),
193
+ ...getAppArgsForTransaction(args),
194
+ rekeyTo: undefined,
195
+ });
196
+ const result = await (0, transaction_1.sendTransaction)({ transaction, from, sendParams }, algod);
197
+ return {
198
+ ...result,
199
+ transactions: [result.transaction],
200
+ confirmations: result.confirmation ? [result.confirmation] : undefined,
201
+ return: getABIReturn(args, result.confirmation),
202
+ compiledApproval,
203
+ compiledClear,
204
+ };
205
+ }
109
206
  }
110
207
  exports.updateApp = updateApp;
208
+ function attachATC(sendParams) {
209
+ if (sendParams.atc) {
210
+ sendParams.skipSending = true;
211
+ }
212
+ sendParams.atc = sendParams.atc ?? new algosdk_1.AtomicTransactionComposer();
213
+ return sendParams.atc;
214
+ }
111
215
  /**
112
216
  * Issues a call to a given app.
113
217
  * @param call The call details.
@@ -116,6 +220,41 @@ exports.updateApp = updateApp;
116
220
  */
117
221
  async function callApp(call, algod) {
118
222
  const { appId, callType, from, args, note, transactionParams, ...sendParams } = call;
223
+ if (args && 'method' in args) {
224
+ const atc = attachATC(sendParams);
225
+ const before = (0, transaction_1.getAtomicTransactionComposerTransactions)(atc);
226
+ atc.addMethodCall({
227
+ appID: appId,
228
+ suggestedParams: (0, transaction_1.controlFees)(await (0, transaction_1.getTransactionParams)(transactionParams, algod), sendParams),
229
+ note: (0, transaction_1.encodeTransactionNote)(note),
230
+ onComplete: callType === 'normal'
231
+ ? algosdk_1.OnApplicationComplete.NoOpOC
232
+ : callType === 'clearstate'
233
+ ? algosdk_1.OnApplicationComplete.ClearStateOC
234
+ : callType === 'closeout'
235
+ ? algosdk_1.OnApplicationComplete.CloseOutOC
236
+ : callType === 'delete'
237
+ ? algosdk_1.OnApplicationComplete.DeleteApplicationOC
238
+ : algosdk_1.OnApplicationComplete.OptInOC,
239
+ ...getAppArgsForABICall(args, from),
240
+ });
241
+ if (sendParams.skipSending) {
242
+ const after = atc.clone().buildGroup();
243
+ return {
244
+ transaction: after[after.length - 1].txn,
245
+ transactions: after.slice(before.length).map((t) => t.txn),
246
+ };
247
+ }
248
+ const result = await (0, transaction_1.sendAtomicTransactionComposer)({ atc, sendParams }, algod);
249
+ const confirmation = result.confirmations ? result.confirmations[result.confirmations?.length - 1] : undefined;
250
+ return {
251
+ transactions: result.transactions,
252
+ confirmations: result.confirmations,
253
+ return: confirmation ? getABIReturn(args, confirmation) : undefined,
254
+ transaction: result.transactions[result.transactions.length - 1],
255
+ confirmation: confirmation,
256
+ };
257
+ }
119
258
  const appCallParams = {
120
259
  appIndex: appId,
121
260
  from: (0, transaction_1.getSenderAddress)(from),
@@ -145,38 +284,37 @@ async function callApp(call, algod) {
145
284
  const result = await (0, transaction_1.sendTransaction)({ transaction, from, sendParams }, algod);
146
285
  return {
147
286
  ...result,
287
+ transactions: [result.transaction],
288
+ confirmations: result.confirmation ? [result.confirmation] : undefined,
148
289
  return: getABIReturn(args, result.confirmation),
149
290
  };
150
291
  }
151
292
  exports.callApp = callApp;
152
293
  function getABIReturn(args, confirmation) {
153
- try {
154
- if (!args || !('method' in args)) {
155
- return undefined;
156
- }
157
- const method = 'txnCount' in args.method ? args.method : new algosdk_1.ABIMethod(args.method);
158
- if (method.returns.type !== 'void' && confirmation) {
159
- const logs = confirmation.logs || [];
160
- if (logs.length === 0) {
161
- throw new Error('App call transaction did not log a return value');
162
- }
163
- const lastLog = logs[logs.length - 1];
164
- if (lastLog.byteLength < 4 || lastLog.slice(0, 4).toString() !== app_1.ABI_RETURN_PREFIX.toString()) {
165
- throw new Error('App call transaction did not log a return value (ABI_RETURN_PREFIX not found)');
166
- }
167
- return {
168
- rawReturnValue: new Uint8Array(lastLog.slice(4)),
169
- returnValue: method.returns.type.decode(new Uint8Array(lastLog.slice(4))),
170
- decodeError: undefined,
171
- };
172
- }
294
+ if (!args || !('method' in args)) {
295
+ return undefined;
173
296
  }
174
- catch (e) {
175
- return {
176
- rawReturnValue: undefined,
177
- returnValue: undefined,
178
- decodeError: e,
297
+ const method = 'txnCount' in args.method ? args.method : new algosdk_1.ABIMethod(args.method);
298
+ if (method.returns.type !== 'void' && confirmation) {
299
+ // The parseMethodResponse method mutates the second parameter :(
300
+ const resultDummy = {
301
+ txID: '',
302
+ method,
303
+ rawReturnValue: new Uint8Array(),
179
304
  };
305
+ const response = algosdk_1.AtomicTransactionComposer.parseMethodResponse(method, resultDummy, confirmation);
306
+ return !response.decodeError
307
+ ? {
308
+ rawReturnValue: response.rawReturnValue,
309
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
310
+ returnValue: response.returnValue,
311
+ decodeError: undefined,
312
+ }
313
+ : {
314
+ rawReturnValue: undefined,
315
+ returnValue: undefined,
316
+ decodeError: response.decodeError,
317
+ };
180
318
  }
181
319
  return undefined;
182
320
  }
@@ -320,77 +458,49 @@ exports.decodeAppState = decodeAppState;
320
458
  function getAppArgsForTransaction(args) {
321
459
  if (!args)
322
460
  return undefined;
323
- let actualArgs;
324
- if ('method' in args) {
325
- // todo: Land a change to algosdk that extracts the logic from ATC, because (fair warning) this is a HACK
326
- // I don't want to have to rewrite all of the ABI resolution logic so using an ATC temporarily here
327
- // and passing stuff in to keep it happy like a randomly generated account :O
328
- // Most of these values aren't being used since the transaction is discarded
329
- const dummyAtc = new algosdk_1.AtomicTransactionComposer();
330
- const dummyAccount = algosdk_1.default.generateAccount();
331
- const dummySigner = (0, algosdk_1.makeBasicAccountTransactionSigner)(dummyAccount);
332
- const dummyAppId = 1;
333
- const dummyParams = {
334
- fee: 1,
335
- firstRound: 1,
336
- genesisHash: buffer_1.Buffer.from('abcd', 'utf-8').toString('base64'),
337
- genesisID: 'a',
338
- lastRound: 1,
339
- };
340
- const methodArgs = args.args?.map((a) => {
341
- if (typeof a !== 'object') {
342
- return a;
343
- }
344
- // Handle the various forms of transactions to wrangle them for ATC
345
- return 'txn' in a
346
- ? a
347
- : 'transaction' in a
348
- ? { txn: a.transaction, signer: dummySigner }
349
- : 'txID' in a
350
- ? { txn: a, signer: dummySigner }
351
- : a;
352
- });
353
- const dummyOnComplete = algosdk_1.OnApplicationComplete.NoOpOC;
354
- dummyAtc.addMethodCall({
355
- method: 'txnCount' in args.method ? args.method : new algosdk_1.ABIMethod(args.method),
356
- methodArgs,
357
- // Rest are dummy values
358
- appID: dummyAppId,
359
- sender: dummyAccount.addr,
360
- signer: dummySigner,
361
- suggestedParams: dummyParams,
362
- onComplete: dummyOnComplete,
363
- });
364
- const txns = dummyAtc.buildGroup();
365
- const txn = txns[txns.length - 1];
366
- actualArgs = {
367
- accounts: txn.txn.appAccounts,
368
- appArgs: txn.txn.appArgs,
369
- apps: txn.txn.appForeignApps,
370
- assets: txn.txn.appForeignAssets,
371
- boxes: args.boxes?.map((b) => (typeof b === 'object' && 'appId' in b ? b : { appId: 0, name: b })),
372
- lease: args.lease,
373
- };
374
- }
375
- else {
376
- actualArgs = args;
377
- }
378
461
  const encoder = new TextEncoder();
379
462
  return {
380
- accounts: actualArgs?.accounts?.map((a) => (typeof a === 'string' ? a : algosdk_1.default.encodeAddress(a.publicKey))),
381
- appArgs: actualArgs?.appArgs?.map((a) => (typeof a === 'string' ? encoder.encode(a) : a)),
382
- boxes: actualArgs?.boxes
463
+ accounts: args?.accounts?.map((a) => (typeof a === 'string' ? a : algosdk_1.default.encodeAddress(a.publicKey))),
464
+ appArgs: args?.appArgs?.map((a) => (typeof a === 'string' ? encoder.encode(a) : a)),
465
+ boxes: args?.boxes
383
466
  ?.map((b) => (typeof b === 'object' && 'appId' in b ? b : { appId: 0, name: b }))
384
467
  ?.map((ref) => ({
385
468
  appIndex: ref.appId,
386
469
  name: typeof ref.name === 'string' ? encoder.encode(ref.name) : ref.name,
387
470
  })),
388
- foreignApps: actualArgs?.apps,
389
- foreignAssets: actualArgs?.assets,
390
- lease: typeof actualArgs?.lease === 'string' ? encoder.encode(actualArgs?.lease) : actualArgs?.lease,
471
+ foreignApps: args?.apps,
472
+ foreignAssets: args?.assets,
473
+ lease: typeof args?.lease === 'string' ? encoder.encode(args?.lease) : args?.lease,
391
474
  };
392
475
  }
393
476
  exports.getAppArgsForTransaction = getAppArgsForTransaction;
477
+ /** Returns the app args ready to load onto an ABI method call in @see AtomicTransactionComposer */
478
+ function getAppArgsForABICall(args, from) {
479
+ const encoder = new TextEncoder();
480
+ const signer = (0, transaction_1.getSenderTransactionSigner)(from);
481
+ const methodArgs = args.args?.map((a) => {
482
+ if (typeof a !== 'object') {
483
+ return a;
484
+ }
485
+ // Handle the various forms of transactions to wrangle them for ATC
486
+ return 'txn' in a ? a : 'transaction' in a ? { txn: a.transaction, signer } : 'txID' in a ? { txn: a, signer } : a;
487
+ });
488
+ return {
489
+ method: 'txnCount' in args.method ? args.method : new algosdk_1.ABIMethod(args.method),
490
+ sender: (0, transaction_1.getSenderAddress)(from),
491
+ signer: signer,
492
+ boxes: args.boxes
493
+ ?.map((b) => (typeof b === 'object' && 'appId' in b ? b : { appId: 0, name: b }))
494
+ ?.map((ref) => ({
495
+ appIndex: ref.appId,
496
+ name: typeof ref.name === 'string' ? encoder.encode(ref.name) : ref.name,
497
+ })),
498
+ lease: typeof args.lease === 'string' ? encoder.encode(args.lease) : args.lease,
499
+ methodArgs: methodArgs,
500
+ rekeyTo: undefined,
501
+ };
502
+ }
503
+ exports.getAppArgsForABICall = getAppArgsForABICall;
394
504
  /**
395
505
  * Gets the current data for the given app from algod.
396
506
  *