@algorandfoundation/algokit-utils 7.0.0-beta.1 → 7.0.0-beta.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (133) hide show
  1. package/README.md +1 -1
  2. package/account/account.d.ts +7 -7
  3. package/account/account.js +7 -7
  4. package/account/account.mjs +7 -7
  5. package/account/get-account.d.ts +2 -2
  6. package/account/get-account.js +1 -1
  7. package/account/get-account.mjs +1 -1
  8. package/account/get-dispenser-account.d.ts +1 -1
  9. package/account/get-dispenser-account.js +1 -1
  10. package/account/get-dispenser-account.mjs +1 -1
  11. package/account/mnemonic-account.d.ts +1 -1
  12. package/account/mnemonic-account.js +1 -1
  13. package/account/mnemonic-account.mjs +1 -1
  14. package/app-deploy.d.ts +18 -1
  15. package/app-deploy.d.ts.map +1 -1
  16. package/app-deploy.js +142 -333
  17. package/app-deploy.js.map +1 -1
  18. package/app-deploy.mjs +145 -336
  19. package/app-deploy.mjs.map +1 -1
  20. package/app.d.ts +38 -1
  21. package/app.d.ts.map +1 -1
  22. package/app.js +113 -370
  23. package/app.js.map +1 -1
  24. package/app.mjs +114 -371
  25. package/app.mjs.map +1 -1
  26. package/asset.d.ts +5 -5
  27. package/asset.js +5 -5
  28. package/asset.mjs +5 -5
  29. package/debugging/debugging.js +2 -2
  30. package/debugging/debugging.js.map +1 -1
  31. package/debugging/debugging.mjs +2 -2
  32. package/debugging/debugging.mjs.map +1 -1
  33. package/index.d.ts +1 -1
  34. package/index.d.ts.map +1 -1
  35. package/index.js +12 -12
  36. package/index.mjs +1 -1
  37. package/localnet/get-kmd-wallet-account.d.ts +1 -1
  38. package/localnet/get-kmd-wallet-account.js +1 -1
  39. package/localnet/get-kmd-wallet-account.mjs +1 -1
  40. package/localnet/get-localnet-dispenser-account.d.ts +1 -1
  41. package/localnet/get-localnet-dispenser-account.js +1 -1
  42. package/localnet/get-localnet-dispenser-account.mjs +1 -1
  43. package/localnet/get-or-create-kmd-wallet-account.d.ts +1 -1
  44. package/localnet/get-or-create-kmd-wallet-account.js +1 -1
  45. package/localnet/get-or-create-kmd-wallet-account.mjs +1 -1
  46. package/localnet/is-localnet.d.ts +1 -1
  47. package/localnet/is-localnet.js +1 -1
  48. package/localnet/is-localnet.mjs +1 -1
  49. package/network-client.d.ts +2 -2
  50. package/network-client.d.ts.map +1 -1
  51. package/network-client.js +2 -2
  52. package/network-client.mjs +2 -2
  53. package/package.json +1 -1
  54. package/testing/fixtures/algorand-fixture.js +12 -12
  55. package/testing/fixtures/algorand-fixture.js.map +1 -1
  56. package/testing/fixtures/algorand-fixture.mjs +12 -12
  57. package/testing/fixtures/algorand-fixture.mjs.map +1 -1
  58. package/transaction/legacy-bridge.d.ts +31 -5
  59. package/transaction/legacy-bridge.d.ts.map +1 -1
  60. package/transaction/legacy-bridge.js +99 -5
  61. package/transaction/legacy-bridge.js.map +1 -1
  62. package/transaction/legacy-bridge.mjs +98 -7
  63. package/transaction/legacy-bridge.mjs.map +1 -1
  64. package/transfer/transfer-algos.d.ts +1 -1
  65. package/transfer/transfer-algos.js +1 -1
  66. package/transfer/transfer-algos.mjs +1 -1
  67. package/transfer/transfer.d.ts +1 -1
  68. package/transfer/transfer.js +1 -1
  69. package/transfer/transfer.mjs +1 -1
  70. package/types/account-manager.d.ts +1 -1
  71. package/types/account-manager.d.ts.map +1 -1
  72. package/types/algorand-client-transaction-creator.d.ts +450 -20
  73. package/types/algorand-client-transaction-creator.d.ts.map +1 -1
  74. package/types/algorand-client-transaction-creator.js +406 -22
  75. package/types/algorand-client-transaction-creator.js.map +1 -1
  76. package/types/algorand-client-transaction-creator.mjs +406 -22
  77. package/types/algorand-client-transaction-creator.mjs.map +1 -1
  78. package/types/algorand-client-transaction-sender.d.ts +750 -24
  79. package/types/algorand-client-transaction-sender.d.ts.map +1 -1
  80. package/types/algorand-client-transaction-sender.js +426 -12
  81. package/types/algorand-client-transaction-sender.js.map +1 -1
  82. package/types/algorand-client-transaction-sender.mjs +426 -12
  83. package/types/algorand-client-transaction-sender.mjs.map +1 -1
  84. package/types/algorand-client.d.ts +8 -0
  85. package/types/algorand-client.d.ts.map +1 -1
  86. package/types/algorand-client.js +14 -1
  87. package/types/algorand-client.js.map +1 -1
  88. package/types/algorand-client.mjs +14 -1
  89. package/types/algorand-client.mjs.map +1 -1
  90. package/types/app-client.d.ts +13 -1
  91. package/types/app-client.d.ts.map +1 -1
  92. package/types/app-client.js +8 -5
  93. package/types/app-client.js.map +1 -1
  94. package/types/app-client.mjs +9 -6
  95. package/types/app-client.mjs.map +1 -1
  96. package/types/app-deployer.d.ts +121 -0
  97. package/types/app-deployer.d.ts.map +1 -0
  98. package/types/app-deployer.js +354 -0
  99. package/types/app-deployer.js.map +1 -0
  100. package/types/app-deployer.mjs +352 -0
  101. package/types/app-deployer.mjs.map +1 -0
  102. package/types/app-manager.d.ts +235 -0
  103. package/types/app-manager.d.ts.map +1 -0
  104. package/types/app-manager.js +336 -0
  105. package/types/app-manager.js.map +1 -0
  106. package/types/app-manager.mjs +334 -0
  107. package/types/app-manager.mjs.map +1 -0
  108. package/types/app.d.ts +42 -7
  109. package/types/app.d.ts.map +1 -1
  110. package/types/app.js +1 -1
  111. package/types/app.js.map +1 -1
  112. package/types/app.mjs +1 -1
  113. package/types/app.mjs.map +1 -1
  114. package/types/client-manager.d.ts +2 -0
  115. package/types/client-manager.d.ts.map +1 -1
  116. package/types/client-manager.js +4 -0
  117. package/types/client-manager.js.map +1 -1
  118. package/types/client-manager.mjs +4 -0
  119. package/types/client-manager.mjs.map +1 -1
  120. package/types/composer.d.ts +150 -39
  121. package/types/composer.d.ts.map +1 -1
  122. package/types/composer.js +218 -62
  123. package/types/composer.js.map +1 -1
  124. package/types/composer.mjs +218 -62
  125. package/types/composer.mjs.map +1 -1
  126. package/types/expand.d.ts +8 -0
  127. package/types/expand.d.ts.map +1 -0
  128. package/types/expand.js +3 -0
  129. package/types/expand.js.map +1 -0
  130. package/types/expand.mjs +2 -0
  131. package/types/expand.mjs.map +1 -0
  132. package/types/transaction.d.ts +3 -0
  133. package/types/transaction.d.ts.map +1 -1
package/app.mjs CHANGED
@@ -1,197 +1,77 @@
1
1
  import algosdk from 'algosdk';
2
- import { Buffer } from 'buffer';
3
- import { Config } from './config.mjs';
4
- import { getAtomicTransactionComposerTransactions, controlFees, getTransactionParams, encodeTransactionNote, sendAtomicTransactionComposer, getSenderAddress, sendTransaction, encodeLease, getSenderTransactionSigner } from './transaction/transaction.mjs';
5
- import { APP_PAGE_MAX_SIZE } from './types/app.mjs';
2
+ import { legacySendAppTransactionBridge, _getAppArgsForABICall, _getBoxReference } from './transaction/legacy-bridge.mjs';
3
+ import { getSenderAddress, encodeLease } from './transaction/transaction.mjs';
4
+ import { AppManager } from './types/app-manager.mjs';
6
5
  import { toNumber } from './util.mjs';
7
6
 
8
7
  var ABIMethod = algosdk.ABIMethod;
9
- var AtomicTransactionComposer = algosdk.AtomicTransactionComposer;
10
8
  var modelsv2 = algosdk.modelsv2;
11
9
  var OnApplicationComplete = algosdk.OnApplicationComplete;
12
- var SourceMap = algosdk.SourceMap;
13
10
  /**
11
+ * @deprecated Use `algorand.send.appCreate()` / `algorand.transactions.appCreate()` / `algorand.send.appCreateMethodCall()`
12
+ * / `algorand.transactions.appCreateMethodCall()` instead
13
+ *
14
14
  * Creates a smart contract app, returns the details of the created app.
15
15
  * @param create The parameters to create the app with
16
16
  * @param algod An algod client
17
17
  * @returns The details of the created app, or the transaction to create it if `skipSending` and the compilation result
18
18
  */
19
19
  async function createApp(create, algod) {
20
- const { from, approvalProgram: approval, clearStateProgram: clear, schema, note, transactionParams, args, onCompleteAction, ...sendParams } = create;
21
- const compiledApproval = typeof approval === 'string' ? await compileTeal(approval, algod) : undefined;
22
- const approvalProgram = compiledApproval ? compiledApproval.compiledBase64ToBytes : approval;
23
- const compiledClear = typeof clear === 'string' ? await compileTeal(clear, algod) : undefined;
24
- const clearProgram = compiledClear ? compiledClear.compiledBase64ToBytes : clear;
25
- if (args && args.method) {
26
- const atc = attachATC(sendParams);
27
- const before = getAtomicTransactionComposerTransactions(atc);
28
- atc.addMethodCall({
29
- appID: 0,
30
- approvalProgram: approvalProgram,
31
- clearProgram: clearProgram,
32
- numLocalInts: schema.localInts,
33
- numLocalByteSlices: schema.localByteSlices,
34
- numGlobalInts: schema.globalInts,
35
- numGlobalByteSlices: schema.globalByteSlices,
36
- extraPages: schema.extraPages ?? Math.floor((approvalProgram.length + clearProgram.length) / APP_PAGE_MAX_SIZE),
37
- onComplete: getAppOnCompleteAction(onCompleteAction),
38
- suggestedParams: controlFees(await getTransactionParams(transactionParams, algod), sendParams),
39
- note: encodeTransactionNote(note),
40
- ...(await getAppArgsForABICall(args, from)),
41
- });
42
- if (sendParams.skipSending) {
43
- const after = atc.clone().buildGroup();
44
- return {
45
- transaction: after[after.length - 1].txn,
46
- transactions: after.slice(before.length).map((t) => t.txn),
47
- appId: 0,
48
- appAddress: '',
49
- compiledApproval,
50
- compiledClear,
51
- };
52
- }
53
- const result = await sendAtomicTransactionComposer({ atc, sendParams }, algod);
54
- const confirmation = result.confirmations ? result.confirmations[result.confirmations?.length - 1] : undefined;
55
- if (confirmation) {
56
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
57
- const appId = confirmation.applicationIndex;
58
- Config.getLogger(sendParams.suppressLog).debug(`Created app ${appId} from creator ${getSenderAddress(from)}`);
59
- return {
60
- transactions: result.transactions,
61
- confirmations: result.confirmations,
62
- return: confirmation ? getABIReturn(args, confirmation) : undefined,
63
- transaction: result.transactions[result.transactions.length - 1],
64
- confirmation: confirmation,
65
- appId,
66
- appAddress: algosdk.getApplicationAddress(appId),
67
- compiledApproval,
68
- compiledClear,
69
- };
70
- }
71
- else {
72
- return {
73
- transactions: result.transactions,
74
- confirmations: result.confirmations,
75
- return: confirmation ? getABIReturn(args, confirmation) : undefined,
76
- transaction: result.transactions[result.transactions.length - 1],
77
- confirmation: confirmation,
78
- appId: 0,
79
- appAddress: '',
80
- compiledApproval,
81
- compiledClear,
82
- };
83
- }
84
- }
85
- else {
86
- const transaction = algosdk.makeApplicationCreateTxnFromObject({
87
- approvalProgram: approvalProgram,
88
- clearProgram: clearProgram,
89
- numLocalInts: schema.localInts,
90
- numLocalByteSlices: schema.localByteSlices,
91
- numGlobalInts: schema.globalInts,
92
- numGlobalByteSlices: schema.globalByteSlices,
93
- extraPages: schema.extraPages ?? Math.floor((approvalProgram.length + clearProgram.length) / APP_PAGE_MAX_SIZE),
94
- onComplete: getAppOnCompleteAction(onCompleteAction),
95
- suggestedParams: await getTransactionParams(transactionParams, algod),
96
- from: getSenderAddress(from),
97
- note: encodeTransactionNote(note),
98
- ...getAppArgsForTransaction(args),
99
- rekeyTo: args?.rekeyTo ? (typeof args.rekeyTo === 'string' ? args.rekeyTo : getSenderAddress(args.rekeyTo)) : undefined,
100
- });
101
- const { confirmation } = await sendTransaction({ transaction, from, sendParams }, algod);
102
- if (confirmation) {
103
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
104
- const appId = confirmation.applicationIndex;
105
- Config.getLogger(sendParams.suppressLog).debug(`Created app ${appId} from creator ${getSenderAddress(from)}`);
106
- return {
107
- transaction,
108
- transactions: [transaction],
109
- confirmation,
110
- confirmations: confirmation ? [confirmation] : undefined,
111
- appId,
112
- appAddress: algosdk.getApplicationAddress(appId),
113
- return: getABIReturn(args, confirmation),
114
- compiledApproval,
115
- compiledClear,
116
- };
117
- }
118
- else {
119
- return { transaction, transactions: [transaction], appId: 0, appAddress: '', compiledApproval, compiledClear };
120
- }
20
+ const onComplete = getAppOnCompleteAction(create.onCompleteAction);
21
+ if (onComplete === algosdk.OnApplicationComplete.ClearStateOC) {
22
+ throw new Error('Cannot create an app with on-complete action of ClearState');
121
23
  }
24
+ const result = create.args?.method
25
+ ? await legacySendAppTransactionBridge(algod, create.from, create.args, create, {
26
+ sender: getSenderAddress(create.from),
27
+ onComplete,
28
+ approvalProgram: create.approvalProgram,
29
+ clearStateProgram: create.clearStateProgram,
30
+ method: create.args.method instanceof ABIMethod ? create.args.method : new ABIMethod(create.args.method),
31
+ extraProgramPages: create.schema.extraPages,
32
+ schema: create.schema,
33
+ }, (c) => c.appCreateMethodCall, (c) => c.appCreateMethodCall)
34
+ : await legacySendAppTransactionBridge(algod, create.from, create.args, create, {
35
+ sender: getSenderAddress(create.from),
36
+ onComplete,
37
+ approvalProgram: create.approvalProgram,
38
+ clearStateProgram: create.clearStateProgram,
39
+ extraProgramPages: create.schema.extraPages,
40
+ schema: create.schema,
41
+ }, (c) => c.appCreate, (c) => c.appCreate);
42
+ return { ...result, appId: 'appId' in result ? Number(result.appId) : 0, appAddress: 'appAddress' in result ? result.appAddress : '' };
122
43
  }
123
44
  /**
45
+ * @deprecated Use `algorand.send.appUpdate()` / `algorand.transactions.appUpdate()` / `algorand.send.appUpdateMethodCall()`
46
+ * / `algorand.transactions.appUpdateMethodCall()` instead
47
+ *
124
48
  * Updates a smart contract app.
125
49
  * @param update The parameters to update the app with
126
50
  * @param algod An algod client
127
51
  * @returns The transaction send result and the compilation result
128
52
  */
129
53
  async function updateApp(update, algod) {
130
- const { appId, from, approvalProgram: approval, clearStateProgram: clear, note, transactionParams, args, ...sendParams } = update;
131
- const compiledApproval = typeof approval === 'string' ? await compileTeal(approval, algod) : undefined;
132
- const approvalProgram = compiledApproval ? compiledApproval.compiledBase64ToBytes : approval;
133
- const compiledClear = typeof clear === 'string' ? await compileTeal(clear, algod) : undefined;
134
- const clearProgram = compiledClear ? compiledClear.compiledBase64ToBytes : clear;
135
- Config.getLogger(sendParams.suppressLog).debug(`Updating app ${appId}`);
136
- if (args && args.method) {
137
- const atc = attachATC(sendParams);
138
- const before = getAtomicTransactionComposerTransactions(atc);
139
- atc.addMethodCall({
140
- appID: toNumber(appId),
141
- onComplete: OnApplicationComplete.UpdateApplicationOC,
142
- approvalProgram: approvalProgram,
143
- clearProgram: clearProgram,
144
- suggestedParams: controlFees(await getTransactionParams(transactionParams, algod), sendParams),
145
- note: encodeTransactionNote(note),
146
- ...(await getAppArgsForABICall(args, from)),
147
- });
148
- if (sendParams.skipSending) {
149
- const after = atc.clone().buildGroup();
150
- return {
151
- transaction: after[after.length - 1].txn,
152
- transactions: after.slice(before.length).map((t) => t.txn),
153
- };
154
- }
155
- const result = await sendAtomicTransactionComposer({ atc, sendParams }, algod);
156
- const confirmation = result.confirmations ? result.confirmations[result.confirmations?.length - 1] : undefined;
157
- return {
158
- transactions: result.transactions,
159
- confirmations: result.confirmations,
160
- return: confirmation ? getABIReturn(args, confirmation) : undefined,
161
- transaction: result.transactions[result.transactions.length - 1],
162
- confirmation: confirmation,
163
- };
164
- }
165
- else {
166
- const transaction = algosdk.makeApplicationUpdateTxnFromObject({
167
- appIndex: toNumber(appId),
168
- approvalProgram: approvalProgram,
169
- clearProgram: clearProgram,
170
- suggestedParams: await getTransactionParams(transactionParams, algod),
171
- from: getSenderAddress(from),
172
- note: encodeTransactionNote(note),
173
- ...getAppArgsForTransaction(args),
174
- rekeyTo: args?.rekeyTo ? (typeof args.rekeyTo === 'string' ? args.rekeyTo : getSenderAddress(args.rekeyTo)) : undefined,
175
- });
176
- const result = await sendTransaction({ transaction, from, sendParams }, algod);
177
- return {
178
- ...result,
179
- transactions: [result.transaction],
180
- confirmations: result.confirmation ? [result.confirmation] : undefined,
181
- return: getABIReturn(args, result.confirmation),
182
- compiledApproval,
183
- compiledClear,
184
- };
185
- }
186
- }
187
- function attachATC(sendParams) {
188
- if (sendParams.atc) {
189
- sendParams.skipSending = true;
190
- }
191
- sendParams.atc = sendParams.atc ?? new AtomicTransactionComposer();
192
- return sendParams.atc;
54
+ return update.args?.method
55
+ ? await legacySendAppTransactionBridge(algod, update.from, update.args, update, {
56
+ appId: BigInt(update.appId),
57
+ sender: getSenderAddress(update.from),
58
+ onComplete: algosdk.OnApplicationComplete.UpdateApplicationOC,
59
+ approvalProgram: update.approvalProgram,
60
+ clearStateProgram: update.clearStateProgram,
61
+ method: update.args.method instanceof ABIMethod ? update.args.method : new ABIMethod(update.args.method),
62
+ }, (c) => c.appUpdateMethodCall, (c) => c.appUpdateMethodCall)
63
+ : await legacySendAppTransactionBridge(algod, update.from, update.args, update, {
64
+ appId: BigInt(update.appId),
65
+ sender: getSenderAddress(update.from),
66
+ onComplete: algosdk.OnApplicationComplete.UpdateApplicationOC,
67
+ approvalProgram: update.approvalProgram,
68
+ clearStateProgram: update.clearStateProgram,
69
+ }, (c) => c.appUpdate, (c) => c.appUpdate);
193
70
  }
194
- /** Returns an `algosdk.OnApplicationComplete` for the given onCompleteAction.
71
+ /**
72
+ * @deprecated Use `algosdk.OnApplicationComplete` directly instead.
73
+ *
74
+ * Returns a `algosdk.OnApplicationComplete` for the given onCompleteAction.
195
75
  *
196
76
  * If given `undefined` will return `OnApplicationComplete.NoOpOC`.
197
77
  *
@@ -224,77 +104,35 @@ function getAppOnCompleteAction(onCompletionAction) {
224
104
  }
225
105
  }
226
106
  /**
107
+ * @deprecated Use `algorand.send.appUpdate()` / `algorand.transactions.appUpdate()` / `algorand.send.appUpdateMethodCall()`
108
+ * / `algorand.transactions.appUpdateMethodCall()` instead
109
+ *
227
110
  * Issues a call to a given app.
228
111
  * @param call The call details.
229
112
  * @param algod An algod client
230
113
  * @returns The result of the call
231
114
  */
232
115
  async function callApp(call, algod) {
233
- const { appId, callType, from, args, note, transactionParams, ...sendParams } = call;
234
- if (args && args.method) {
235
- const atc = attachATC(sendParams);
236
- const before = getAtomicTransactionComposerTransactions(atc);
237
- atc.addMethodCall({
238
- appID: toNumber(appId),
239
- suggestedParams: controlFees(await getTransactionParams(transactionParams, algod), sendParams),
240
- note: encodeTransactionNote(note),
241
- onComplete: getAppOnCompleteAction(callType),
242
- ...(await getAppArgsForABICall(args, from)),
243
- });
244
- if (sendParams.skipSending) {
245
- const after = atc.clone().buildGroup();
246
- return {
247
- transaction: after[after.length - 1].txn,
248
- transactions: after.slice(before.length).map((t) => t.txn),
249
- };
250
- }
251
- const result = await sendAtomicTransactionComposer({ atc, sendParams }, algod);
252
- const confirmation = result.confirmations ? result.confirmations[result.confirmations?.length - 1] : undefined;
253
- return {
254
- transactions: result.transactions,
255
- confirmations: result.confirmations,
256
- return: confirmation ? getABIReturn(args, confirmation) : undefined,
257
- transaction: result.transactions[result.transactions.length - 1],
258
- confirmation: confirmation,
259
- };
116
+ const onComplete = getAppOnCompleteAction(call.callType);
117
+ if (onComplete === algosdk.OnApplicationComplete.UpdateApplicationOC) {
118
+ throw new Error('Cannot execute an app call with on-complete action of Update');
260
119
  }
261
- const appCallParams = {
262
- appIndex: toNumber(appId),
263
- from: getSenderAddress(from),
264
- suggestedParams: await getTransactionParams(transactionParams, algod),
265
- ...getAppArgsForTransaction(args),
266
- note: encodeTransactionNote(note),
267
- rekeyTo: args?.rekeyTo ? (typeof args.rekeyTo === 'string' ? args.rekeyTo : getSenderAddress(args.rekeyTo)) : undefined,
268
- };
269
- let transaction;
270
- switch (getAppOnCompleteAction(callType)) {
271
- case OnApplicationComplete.OptInOC:
272
- transaction = algosdk.makeApplicationOptInTxnFromObject(appCallParams);
273
- break;
274
- case OnApplicationComplete.ClearStateOC:
275
- transaction = algosdk.makeApplicationClearStateTxnFromObject(appCallParams);
276
- break;
277
- case OnApplicationComplete.CloseOutOC:
278
- transaction = algosdk.makeApplicationCloseOutTxnFromObject(appCallParams);
279
- break;
280
- case OnApplicationComplete.DeleteApplicationOC:
281
- transaction = algosdk.makeApplicationDeleteTxnFromObject(appCallParams);
282
- break;
283
- case OnApplicationComplete.NoOpOC:
284
- transaction = algosdk.makeApplicationNoOpTxnFromObject(appCallParams);
285
- break;
286
- default:
287
- throw new Error(`Received unexpected call type ${callType}`);
288
- }
289
- const result = await sendTransaction({ transaction, from, sendParams }, algod);
290
- return {
291
- ...result,
292
- transactions: [result.transaction],
293
- confirmations: result.confirmation ? [result.confirmation] : undefined,
294
- return: getABIReturn(args, result.confirmation),
295
- };
120
+ return call.args?.method
121
+ ? await legacySendAppTransactionBridge(algod, call.from, call.args, call, {
122
+ appId: BigInt(call.appId),
123
+ sender: getSenderAddress(call.from),
124
+ onComplete,
125
+ method: call.args.method instanceof ABIMethod ? call.args.method : new ABIMethod(call.args.method),
126
+ }, (c) => c.appCallMethodCall, (c) => c.appCallMethodCall)
127
+ : await legacySendAppTransactionBridge(algod, call.from, call.args, call, {
128
+ appId: BigInt(call.appId),
129
+ sender: getSenderAddress(call.from),
130
+ onComplete,
131
+ }, (c) => c.appCall, (c) => c.appCall);
296
132
  }
297
133
  /**
134
+ * @deprecated Use `AppManager.getABIReturn` instead.
135
+ *
298
136
  * Returns any ABI return values for the given app call arguments and transaction confirmation.
299
137
  * @param args The arguments that were used for the call
300
138
  * @param confirmation The transaction confirmation from algod
@@ -305,43 +143,22 @@ function getABIReturn(args, confirmation) {
305
143
  return undefined;
306
144
  }
307
145
  const method = 'txnCount' in args.method ? args.method : new ABIMethod(args.method);
308
- if (method.returns.type !== 'void' && confirmation) {
309
- // The parseMethodResponse method mutates the second parameter :(
310
- const resultDummy = {
311
- txID: '',
312
- method,
313
- rawReturnValue: new Uint8Array(),
314
- };
315
- const response = AtomicTransactionComposer.parseMethodResponse(method, resultDummy, confirmation);
316
- return !response.decodeError
317
- ? {
318
- rawReturnValue: response.rawReturnValue,
319
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
320
- returnValue: response.returnValue,
321
- decodeError: undefined,
322
- }
323
- : {
324
- rawReturnValue: undefined,
325
- returnValue: undefined,
326
- decodeError: response.decodeError,
327
- };
328
- }
329
- return undefined;
146
+ return AppManager.getABIReturn(confirmation, method);
330
147
  }
331
148
  /**
149
+ * @deprecated Use `(await appManager.getById(appId)).globalState` instead.
150
+ *
332
151
  * Returns the current global state values for the given app ID
333
152
  * @param appId The ID of the app return global state for
334
153
  * @param algod An algod client instance
335
154
  * @returns The current global state
336
155
  */
337
156
  async function getAppGlobalState(appId, algod) {
338
- const appInfo = await getAppById(appId, algod);
339
- if (!appInfo.params || !appInfo.params.globalState) {
340
- throw new Error("Couldn't find global state");
341
- }
342
- return decodeAppState(appInfo.params.globalState);
157
+ return (await new AppManager(algod).getById(BigInt(appId))).globalState;
343
158
  }
344
159
  /**
160
+ * @deprecated Use `algorand.app.getLocalState` instead.
161
+ *
345
162
  * Returns the current global state values for the given app ID and account
346
163
  * @param appId The ID of the app return global state for
347
164
  * @param account Either the string address of an account or an account object for the account to get local state for the given app
@@ -349,30 +166,20 @@ async function getAppGlobalState(appId, algod) {
349
166
  * @returns The current local state for the given (app, account) combination
350
167
  */
351
168
  async function getAppLocalState(appId, account, algod) {
352
- const accountAddress = typeof account === 'string' ? account : getSenderAddress(account);
353
- const appInfo = modelsv2.AccountApplicationResponse.from_obj_for_encoding(await algod.accountApplicationInformation(accountAddress, toNumber(appId)).do());
354
- if (!appInfo.appLocalState?.keyValue) {
355
- throw new Error("Couldn't find local state");
356
- }
357
- return decodeAppState(appInfo.appLocalState.keyValue);
169
+ return new AppManager(algod).getLocalState(BigInt(appId), getSenderAddress(account));
358
170
  }
359
171
  /**
172
+ * @deprecated Use `algorand.app.getBoxNames` instead.
360
173
  * Returns the names of the boxes for the given app.
361
174
  * @param appId The ID of the app return box names for
362
175
  * @param algod An algod client instance
363
176
  * @returns The current box names
364
177
  */
365
178
  async function getAppBoxNames(appId, algod) {
366
- const boxResult = await algod.getApplicationBoxes(toNumber(appId)).do();
367
- return boxResult.boxes.map((b) => {
368
- return {
369
- nameRaw: b.name,
370
- nameBase64: Buffer.from(b.name).toString('base64'),
371
- name: Buffer.from(b.name).toString('utf-8'),
372
- };
373
- });
179
+ return new AppManager(algod).getBoxNames(BigInt(appId));
374
180
  }
375
181
  /**
182
+ * @deprecated Use `algorand.app.getBoxValue` instead.
376
183
  * Returns the value of the given box name for the given app.
377
184
  * @param appId The ID of the app return box names for
378
185
  * @param boxName The name of the box to return either as a string, binary array or `BoxName`
@@ -380,11 +187,10 @@ async function getAppBoxNames(appId, algod) {
380
187
  * @returns The current box value as a byte array
381
188
  */
382
189
  async function getAppBoxValue(appId, boxName, algod) {
383
- const name = typeof boxName === 'string' ? new Uint8Array(Buffer.from(boxName, 'utf-8')) : 'name' in boxName ? boxName.nameRaw : boxName;
384
- const boxResult = await algod.getApplicationBoxByName(toNumber(appId), name).do();
385
- return boxResult.value;
190
+ return new AppManager(algod).getBoxValue(BigInt(appId), typeof boxName !== 'string' && 'name' in boxName ? boxName.nameRaw : boxName);
386
191
  }
387
192
  /**
193
+ * @deprecated Use `algorand.app.getBoxValues` instead.
388
194
  * Returns the value of the given box names for the given app.
389
195
  * @param appId The ID of the app return box names for
390
196
  * @param boxNames The names of the boxes to return either as a string, binary array or `BoxName`
@@ -392,74 +198,50 @@ async function getAppBoxValue(appId, boxName, algod) {
392
198
  * @returns The current box values as a byte array in the same order as the passed in box names
393
199
  */
394
200
  async function getAppBoxValues(appId, boxNames, algod) {
395
- return await Promise.all(boxNames.map(async (boxName) => await getAppBoxValue(appId, boxName, algod)));
201
+ return new AppManager(algod).getBoxValues(BigInt(appId), boxNames.map((b) => (typeof b !== 'string' && 'name' in b ? b.nameRaw : b)));
396
202
  }
397
203
  /**
204
+ * @deprecated Use `algorand.app.getBoxValueFromABIType` instead.
398
205
  * Returns the value of the given box name for the given app decoded based on the given ABI type.
399
206
  * @param request The parameters for the box value request
400
207
  * @param algod An algod client instance
401
208
  * @returns The current box value as an ABI value
402
209
  */
403
210
  async function getAppBoxValueFromABIType(request, algod) {
404
- const { appId, boxName, type } = request;
405
- const value = await getAppBoxValue(appId, boxName, algod);
406
- return type.decode(value);
211
+ return new AppManager(algod).getBoxValueFromABIType({
212
+ appId: BigInt(request.appId),
213
+ boxName: typeof request.boxName !== 'string' && 'name' in request.boxName ? request.boxName.nameRaw : request.boxName,
214
+ type: request.type,
215
+ });
407
216
  }
408
217
  /**
218
+ * @deprecated Use `algorand.app.getBoxValuesFromABIType` instead.
409
219
  * Returns the value of the given box names for the given app decoded based on the given ABI type.
410
220
  * @param request The parameters for the box value request
411
221
  * @param algod An algod client instance
412
222
  * @returns The current box values as an ABI value in the same order as the passed in box names
413
223
  */
414
224
  async function getAppBoxValuesFromABIType(request, algod) {
415
- const { appId, boxNames, type } = request;
416
- return await Promise.all(boxNames.map(async (boxName) => await getAppBoxValueFromABIType({ appId, boxName, type }, algod)));
225
+ return new AppManager(algod).getBoxValuesFromABIType({
226
+ appId: BigInt(request.appId),
227
+ boxNames: request.boxNames.map((b) => (typeof b !== 'string' && 'name' in b ? b.nameRaw : b)),
228
+ type: request.type,
229
+ });
417
230
  }
418
231
  /**
232
+ * @deprecated Use `AppManager.decodeAppState` instead.
233
+ *
419
234
  * Converts an array of global/local state values from the algod api to a more friendly
420
235
  * generic object keyed by the UTF-8 value of the key.
421
236
  * @param state A `global-state`, `local-state`, `global-state-deltas` or `local-state-deltas`
422
237
  * @returns An object keyeed by the UTF-8 representation of the key with various parsings of the values
423
238
  */
424
239
  function decodeAppState(state) {
425
- const stateValues = {};
426
- // Start with empty set
427
- for (const stateVal of state) {
428
- const keyBase64 = stateVal.key;
429
- const keyRaw = Buffer.from(keyBase64, 'base64');
430
- const key = keyRaw.toString('utf-8');
431
- const tealValue = stateVal.value;
432
- const dataTypeFlag = 'action' in tealValue ? tealValue.action : tealValue.type;
433
- let valueBase64;
434
- let valueRaw;
435
- switch (dataTypeFlag) {
436
- case 1:
437
- valueBase64 = tealValue.bytes ?? '';
438
- valueRaw = Buffer.from(valueBase64, 'base64');
439
- stateValues[key] = {
440
- keyRaw,
441
- keyBase64,
442
- valueRaw: new Uint8Array(valueRaw),
443
- valueBase64: valueBase64,
444
- value: valueRaw.toString('utf-8'),
445
- };
446
- break;
447
- case 2: {
448
- const value = tealValue.uint ?? 0;
449
- stateValues[key] = {
450
- keyRaw,
451
- keyBase64,
452
- value,
453
- };
454
- break;
455
- }
456
- default:
457
- throw new Error(`Received unknown state data type of ${dataTypeFlag}`);
458
- }
459
- }
460
- return stateValues;
240
+ return AppManager.decodeAppState(state);
461
241
  }
462
242
  /**
243
+ * @deprecated Use `AlgoKitComposer` methods to construct transactions instead.
244
+ *
463
245
  * Returns the app args ready to load onto an app `Transaction` object
464
246
  * @param args The app call args
465
247
  * @returns The args ready to load into a `Transaction`
@@ -478,68 +260,32 @@ function getAppArgsForTransaction(args) {
478
260
  };
479
261
  }
480
262
  /**
263
+ * @deprecated Use `AlgoKitComposer` methods to construct transactions instead.
264
+ *
481
265
  * Returns the app args ready to load onto an ABI method call in `AtomicTransactionComposer`
482
266
  * @param args The ABI app call args
483
267
  * @param from The transaction signer
484
268
  * @returns The parameters ready to pass into `addMethodCall` within AtomicTransactionComposer
485
269
  */
486
270
  async function getAppArgsForABICall(args, from) {
487
- const signer = getSenderTransactionSigner(from);
488
- const methodArgs = await Promise.all(('methodArgs' in args ? args.methodArgs : args)?.map(async (a, index) => {
489
- if (a === undefined) {
490
- throw new Error(`Argument at position ${index} does not have a value`);
491
- }
492
- if (typeof a !== 'object') {
493
- return a;
494
- }
495
- // Handle the various forms of transactions to wrangle them for ATC
496
- return 'txn' in a
497
- ? a
498
- : a instanceof Promise
499
- ? { txn: (await a).transaction, signer }
500
- : 'transaction' in a
501
- ? { txn: a.transaction, signer: 'signer' in a ? getSenderTransactionSigner(a.signer) : signer }
502
- : 'txID' in a
503
- ? { txn: a, signer }
504
- : a;
505
- }));
506
- return {
507
- method: 'txnCount' in args.method ? args.method : new ABIMethod(args.method),
508
- sender: getSenderAddress(from),
509
- signer: signer,
510
- boxes: args.boxes?.map(getBoxReference),
511
- lease: encodeLease(args.lease),
512
- appForeignApps: args.apps,
513
- appForeignAssets: args.assets,
514
- appAccounts: args.accounts?.map(_getAccountAddress),
515
- methodArgs: methodArgs,
516
- rekeyTo: args?.rekeyTo ? (typeof args.rekeyTo === 'string' ? args.rekeyTo : getSenderAddress(args.rekeyTo)) : undefined,
517
- };
271
+ return _getAppArgsForABICall(args, from);
518
272
  }
519
273
  /**
274
+ * @deprecated Use `AppManager.getBoxReference()` instead.
275
+ *
520
276
  * Returns a `algosdk.BoxReference` given a `BoxIdentifier` or `BoxReference`.
521
277
  * @param box The box to return a reference for
522
278
  * @returns The box reference ready to pass into a `Transaction`
523
279
  */
524
280
  function getBoxReference(box) {
525
- const encoder = new TextEncoder();
526
- if (typeof box === 'object' && 'appIndex' in box) {
527
- return box;
528
- }
529
- const ref = typeof box === 'object' && 'appId' in box ? box : { appId: 0, name: box };
530
- return {
531
- appIndex: ref.appId,
532
- name: typeof ref.name === 'string'
533
- ? encoder.encode(ref.name)
534
- : 'length' in ref.name
535
- ? ref.name
536
- : algosdk.decodeAddress(getSenderAddress(ref.name)).publicKey,
537
- };
281
+ return _getBoxReference(box);
538
282
  }
539
283
  function _getAccountAddress(account) {
540
284
  return typeof account === 'string' ? account : algosdk.encodeAddress(account.publicKey);
541
285
  }
542
286
  /**
287
+ * @deprecated Use `algorand.app.getById` instead.
288
+ *
543
289
  * Gets the current data for the given app from algod.
544
290
  *
545
291
  * @param appId The id of the app
@@ -550,6 +296,8 @@ async function getAppById(appId, algod) {
550
296
  return modelsv2.Application.from_obj_for_encoding(await algod.getApplicationByID(toNumber(appId)).do());
551
297
  }
552
298
  /**
299
+ * @deprecated Use `algorand.app.compileTeal` instead.
300
+ *
553
301
  * Compiles the given TEAL using algod and returns the result, including source map.
554
302
  *
555
303
  * @param algod An algod client
@@ -557,16 +305,11 @@ async function getAppById(appId, algod) {
557
305
  * @returns The information about the compiled file
558
306
  */
559
307
  async function compileTeal(tealCode, algod) {
560
- const compiled = await algod.compile(tealCode).sourcemap(true).do();
561
- return {
562
- teal: tealCode,
563
- compiled: compiled.result,
564
- compiledHash: compiled.hash,
565
- compiledBase64ToBytes: new Uint8Array(Buffer.from(compiled.result, 'base64')),
566
- sourceMap: new SourceMap(compiled['sourcemap']),
567
- };
308
+ return await new AppManager(algod).compileTeal(tealCode);
568
309
  }
569
310
  /**
311
+ * @deprecated Use `abiMethod.getSignature()` or `new ABIMethod(abiMethodParams).getSignature()` instead.
312
+ *
570
313
  * Returns the encoded ABI spec for a given ABI Method
571
314
  * @param method The method to return a signature for
572
315
  * @returns The encoded ABI method spec e.g. `method_name(uint64,string)string`