@algorandfoundation/algokit-utils 7.0.0-beta.2 → 7.0.0-beta.20

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 (352) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +3 -25
  3. package/account/account.d.ts +1 -2
  4. package/account/account.js +6 -4
  5. package/account/account.js.map +1 -1
  6. package/account/account.mjs +6 -4
  7. package/account/account.mjs.map +1 -1
  8. package/account/get-account-config-from-environment.d.ts +0 -1
  9. package/account/get-account-config-from-environment.js.map +1 -1
  10. package/account/get-account-config-from-environment.mjs.map +1 -1
  11. package/account/get-account.d.ts +0 -1
  12. package/account/get-account.js.map +1 -1
  13. package/account/get-account.mjs.map +1 -1
  14. package/account/get-dispenser-account.d.ts +0 -1
  15. package/account/get-dispenser-account.js.map +1 -1
  16. package/account/get-dispenser-account.mjs.map +1 -1
  17. package/account/index.d.ts +0 -1
  18. package/account/mnemonic-account.d.ts +0 -1
  19. package/account/mnemonic-account.js.map +1 -1
  20. package/account/mnemonic-account.mjs.map +1 -1
  21. package/amount.d.ts +14 -5
  22. package/amount.js +6 -0
  23. package/amount.js.map +1 -1
  24. package/amount.mjs +6 -0
  25. package/amount.mjs.map +1 -1
  26. package/app-client.d.ts +15 -1
  27. package/app-client.js +15 -0
  28. package/app-client.js.map +1 -1
  29. package/app-client.mjs +15 -0
  30. package/app-client.mjs.map +1 -1
  31. package/app-deploy.d.ts +0 -1
  32. package/app-deploy.js +4 -6
  33. package/app-deploy.js.map +1 -1
  34. package/app-deploy.mjs +7 -9
  35. package/app-deploy.mjs.map +1 -1
  36. package/app.d.ts +10 -11
  37. package/app.js +15 -11
  38. package/app.js.map +1 -1
  39. package/app.mjs +15 -11
  40. package/app.mjs.map +1 -1
  41. package/asset.d.ts +3 -4
  42. package/asset.js +3 -6
  43. package/asset.js.map +1 -1
  44. package/asset.mjs +3 -6
  45. package/asset.mjs.map +1 -1
  46. package/config.d.ts +0 -1
  47. package/config.js.map +1 -1
  48. package/config.mjs.map +1 -1
  49. package/debugging/debugging.d.ts +3 -5
  50. package/debugging/debugging.js +4 -128
  51. package/debugging/debugging.js.map +1 -1
  52. package/debugging/debugging.mjs +4 -109
  53. package/debugging/debugging.mjs.map +1 -1
  54. package/debugging/index.d.ts +0 -2
  55. package/dispenser-client.d.ts +0 -1
  56. package/dispenser-client.js.map +1 -1
  57. package/dispenser-client.mjs.map +1 -1
  58. package/index.d.ts +6 -5
  59. package/index.js +48 -38
  60. package/index.js.map +1 -1
  61. package/index.mjs +6 -5
  62. package/index.mjs.map +1 -1
  63. package/indexer-lookup.d.ts +0 -1
  64. package/indexer-lookup.js.map +1 -1
  65. package/indexer-lookup.mjs.map +1 -1
  66. package/localnet/get-kmd-wallet-account.d.ts +0 -1
  67. package/localnet/get-kmd-wallet-account.js.map +1 -1
  68. package/localnet/get-kmd-wallet-account.mjs.map +1 -1
  69. package/localnet/get-localnet-dispenser-account.d.ts +0 -1
  70. package/localnet/get-localnet-dispenser-account.js.map +1 -1
  71. package/localnet/get-localnet-dispenser-account.mjs.map +1 -1
  72. package/localnet/get-or-create-kmd-wallet-account.d.ts +0 -1
  73. package/localnet/get-or-create-kmd-wallet-account.js.map +1 -1
  74. package/localnet/get-or-create-kmd-wallet-account.mjs.map +1 -1
  75. package/localnet/index.d.ts +0 -1
  76. package/localnet/is-localnet.d.ts +0 -1
  77. package/localnet/is-localnet.js.map +1 -1
  78. package/localnet/is-localnet.mjs.map +1 -1
  79. package/network-client.d.ts +0 -1
  80. package/network-client.js.map +1 -1
  81. package/network-client.mjs.map +1 -1
  82. package/package.json +2 -2
  83. package/testing/_asset.d.ts +0 -1
  84. package/testing/account.d.ts +0 -1
  85. package/testing/account.js.map +1 -1
  86. package/testing/account.mjs.map +1 -1
  87. package/testing/fixtures/algokit-log-capture-fixture.d.ts +0 -1
  88. package/testing/fixtures/algokit-log-capture-fixture.js.map +1 -1
  89. package/testing/fixtures/algokit-log-capture-fixture.mjs.map +1 -1
  90. package/testing/fixtures/algorand-fixture.d.ts +0 -1
  91. package/testing/fixtures/algorand-fixture.js +1 -1
  92. package/testing/fixtures/algorand-fixture.js.map +1 -1
  93. package/testing/fixtures/algorand-fixture.mjs +1 -1
  94. package/testing/fixtures/algorand-fixture.mjs.map +1 -1
  95. package/testing/fixtures/index.d.ts +0 -1
  96. package/testing/index.d.ts +0 -1
  97. package/testing/indexer.d.ts +0 -1
  98. package/testing/indexer.js.map +1 -1
  99. package/testing/indexer.mjs.map +1 -1
  100. package/testing/test-logger.d.ts +0 -1
  101. package/testing/test-logger.js +1 -3
  102. package/testing/test-logger.js.map +1 -1
  103. package/testing/test-logger.mjs +1 -3
  104. package/testing/test-logger.mjs.map +1 -1
  105. package/testing/transaction-logger.d.ts +0 -1
  106. package/testing/transaction-logger.js.map +1 -1
  107. package/testing/transaction-logger.mjs.map +1 -1
  108. package/transaction/index.d.ts +0 -1
  109. package/transaction/legacy-bridge.d.ts +5 -6
  110. package/transaction/legacy-bridge.js +1 -1
  111. package/transaction/legacy-bridge.js.map +1 -1
  112. package/transaction/legacy-bridge.mjs +4 -4
  113. package/transaction/legacy-bridge.mjs.map +1 -1
  114. package/transaction/perform-atomic-transaction-composer-simulate.d.ts +0 -1
  115. package/transaction/perform-atomic-transaction-composer-simulate.js +1 -0
  116. package/transaction/perform-atomic-transaction-composer-simulate.js.map +1 -1
  117. package/transaction/perform-atomic-transaction-composer-simulate.mjs +1 -0
  118. package/transaction/perform-atomic-transaction-composer-simulate.mjs.map +1 -1
  119. package/transaction/transaction.d.ts +41 -6
  120. package/transaction/transaction.js +113 -61
  121. package/transaction/transaction.js.map +1 -1
  122. package/transaction/transaction.mjs +113 -62
  123. package/transaction/transaction.mjs.map +1 -1
  124. package/transfer/index.d.ts +0 -1
  125. package/transfer/transfer-algos.d.ts +1 -2
  126. package/transfer/transfer-algos.js +1 -1
  127. package/transfer/transfer-algos.js.map +1 -1
  128. package/transfer/transfer-algos.mjs +1 -1
  129. package/transfer/transfer-algos.mjs.map +1 -1
  130. package/transfer/transfer.d.ts +1 -2
  131. package/transfer/transfer.js +3 -3
  132. package/transfer/transfer.js.map +1 -1
  133. package/transfer/transfer.mjs +3 -3
  134. package/transfer/transfer.mjs.map +1 -1
  135. package/types/account-manager.d.ts +15 -7
  136. package/types/account-manager.js +27 -11
  137. package/types/account-manager.js.map +1 -1
  138. package/types/account-manager.mjs +29 -13
  139. package/types/account-manager.mjs.map +1 -1
  140. package/types/account.d.ts +9 -1
  141. package/types/account.js.map +1 -1
  142. package/types/account.mjs.map +1 -1
  143. package/types/algo-http-client-with-retry.d.ts +0 -1
  144. package/types/algo-http-client-with-retry.js.map +1 -1
  145. package/types/algo-http-client-with-retry.mjs.map +1 -1
  146. package/types/algorand-client-interface.d.ts +28 -0
  147. package/types/algorand-client-interface.js +3 -0
  148. package/types/algorand-client-interface.js.map +1 -0
  149. package/types/algorand-client-interface.mjs +2 -0
  150. package/types/algorand-client-interface.mjs.map +1 -0
  151. package/types/algorand-client-transaction-creator.d.ts +33 -34
  152. package/types/algorand-client-transaction-creator.js +31 -31
  153. package/types/algorand-client-transaction-creator.js.map +1 -1
  154. package/types/algorand-client-transaction-creator.mjs +31 -31
  155. package/types/algorand-client-transaction-creator.mjs.map +1 -1
  156. package/types/algorand-client-transaction-sender.d.ts +31 -32
  157. package/types/algorand-client-transaction-sender.js +25 -9
  158. package/types/algorand-client-transaction-sender.js.map +1 -1
  159. package/types/algorand-client-transaction-sender.mjs +25 -9
  160. package/types/algorand-client-transaction-sender.mjs.map +1 -1
  161. package/types/algorand-client.d.ts +13 -13
  162. package/types/algorand-client.js +10 -10
  163. package/types/algorand-client.js.map +1 -1
  164. package/types/algorand-client.mjs +12 -12
  165. package/types/algorand-client.mjs.map +1 -1
  166. package/types/amount.d.ts +10 -11
  167. package/types/amount.js +7 -7
  168. package/types/amount.js.map +1 -1
  169. package/types/amount.mjs +7 -7
  170. package/types/amount.mjs.map +1 -1
  171. package/types/app-arc56.d.ts +358 -0
  172. package/types/app-arc56.js +184 -0
  173. package/types/app-arc56.js.map +1 -0
  174. package/types/app-arc56.mjs +175 -0
  175. package/types/app-arc56.mjs.map +1 -0
  176. package/types/app-client.d.ts +1488 -8
  177. package/types/app-client.js +1000 -19
  178. package/types/app-client.js.map +1 -1
  179. package/types/app-client.mjs +1000 -20
  180. package/types/app-client.mjs.map +1 -1
  181. package/types/app-deployer.d.ts +19 -14
  182. package/types/app-deployer.js +25 -25
  183. package/types/app-deployer.js.map +1 -1
  184. package/types/app-deployer.mjs +27 -27
  185. package/types/app-deployer.mjs.map +1 -1
  186. package/types/app-factory.d.ts +846 -0
  187. package/types/app-factory.js +411 -0
  188. package/types/app-factory.js.map +1 -0
  189. package/types/app-factory.mjs +409 -0
  190. package/types/app-factory.mjs.map +1 -0
  191. package/types/app-manager.d.ts +12 -3
  192. package/types/app-manager.js +13 -15
  193. package/types/app-manager.js.map +1 -1
  194. package/types/app-manager.mjs +13 -15
  195. package/types/app-manager.mjs.map +1 -1
  196. package/types/app-spec.d.ts +2 -1
  197. package/types/app-spec.js +121 -0
  198. package/types/app-spec.js.map +1 -1
  199. package/types/app-spec.mjs +120 -0
  200. package/types/app-spec.mjs.map +1 -1
  201. package/types/app.d.ts +14 -9
  202. package/types/app.js.map +1 -1
  203. package/types/app.mjs.map +1 -1
  204. package/types/asset-manager.d.ts +7 -7
  205. package/types/asset-manager.js +5 -6
  206. package/types/asset-manager.js.map +1 -1
  207. package/types/asset-manager.mjs +5 -6
  208. package/types/asset-manager.mjs.map +1 -1
  209. package/types/asset.d.ts +0 -1
  210. package/types/async-event-emitter.d.ts +14 -0
  211. package/types/async-event-emitter.js +50 -0
  212. package/types/async-event-emitter.js.map +1 -0
  213. package/types/async-event-emitter.mjs +48 -0
  214. package/types/async-event-emitter.mjs.map +1 -0
  215. package/types/client-manager.d.ts +131 -51
  216. package/types/client-manager.js +143 -23
  217. package/types/client-manager.js.map +1 -1
  218. package/types/client-manager.mjs +144 -24
  219. package/types/client-manager.mjs.map +1 -1
  220. package/types/composer.d.ts +110 -37
  221. package/types/composer.js +139 -26
  222. package/types/composer.js.map +1 -1
  223. package/types/composer.mjs +140 -27
  224. package/types/composer.mjs.map +1 -1
  225. package/types/config.d.ts +3 -6
  226. package/types/config.js +5 -44
  227. package/types/config.js.map +1 -1
  228. package/types/config.mjs +5 -27
  229. package/types/config.mjs.map +1 -1
  230. package/types/debugging.d.ts +29 -101
  231. package/types/debugging.js +16 -109
  232. package/types/debugging.js.map +1 -1
  233. package/types/debugging.mjs +12 -107
  234. package/types/debugging.mjs.map +1 -1
  235. package/types/dispenser-client.d.ts +1 -2
  236. package/types/dispenser-client.js +6 -5
  237. package/types/dispenser-client.js.map +1 -1
  238. package/types/dispenser-client.mjs +6 -5
  239. package/types/dispenser-client.mjs.map +1 -1
  240. package/types/expand.d.ts +0 -1
  241. package/types/indexer.d.ts +0 -1
  242. package/types/indexer.js.map +1 -1
  243. package/types/indexer.mjs.map +1 -1
  244. package/types/kmd-account-manager.d.ts +0 -1
  245. package/types/kmd-account-manager.js +2 -2
  246. package/types/kmd-account-manager.js.map +1 -1
  247. package/types/kmd-account-manager.mjs +4 -4
  248. package/types/kmd-account-manager.mjs.map +1 -1
  249. package/types/lifecycle-events.d.ts +10 -0
  250. package/types/lifecycle-events.js +8 -0
  251. package/types/lifecycle-events.js.map +1 -0
  252. package/types/lifecycle-events.mjs +8 -0
  253. package/types/lifecycle-events.mjs.map +1 -0
  254. package/types/logging.d.ts +0 -1
  255. package/types/logging.js.map +1 -1
  256. package/types/logging.mjs.map +1 -1
  257. package/types/logic-error.d.ts +2 -4
  258. package/types/logic-error.js +3 -3
  259. package/types/logic-error.js.map +1 -1
  260. package/types/logic-error.mjs +3 -3
  261. package/types/logic-error.mjs.map +1 -1
  262. package/types/network-client.d.ts +13 -1
  263. package/types/network-client.js.map +1 -1
  264. package/types/network-client.mjs.map +1 -1
  265. package/types/testing.d.ts +3 -4
  266. package/types/transaction.d.ts +14 -4
  267. package/types/transfer.d.ts +0 -1
  268. package/types/urlTokenBaseHTTPClient.d.ts +0 -1
  269. package/types/urlTokenBaseHTTPClient.js +1 -1
  270. package/types/urlTokenBaseHTTPClient.js.map +1 -1
  271. package/types/urlTokenBaseHTTPClient.mjs +1 -1
  272. package/types/urlTokenBaseHTTPClient.mjs.map +1 -1
  273. package/util.d.ts +2 -2
  274. package/util.js +11 -10
  275. package/util.js.map +1 -1
  276. package/util.mjs +11 -10
  277. package/util.mjs.map +1 -1
  278. package/account/account.d.ts.map +0 -1
  279. package/account/get-account-config-from-environment.d.ts.map +0 -1
  280. package/account/get-account.d.ts.map +0 -1
  281. package/account/get-dispenser-account.d.ts.map +0 -1
  282. package/account/index.d.ts.map +0 -1
  283. package/account/mnemonic-account.d.ts.map +0 -1
  284. package/amount.d.ts.map +0 -1
  285. package/app-client.d.ts.map +0 -1
  286. package/app-deploy.d.ts.map +0 -1
  287. package/app.d.ts.map +0 -1
  288. package/asset.d.ts.map +0 -1
  289. package/config.d.ts.map +0 -1
  290. package/debugging/debugging.d.ts.map +0 -1
  291. package/debugging/index.d.ts.map +0 -1
  292. package/debugging/simulate-and-persist-response.d.ts +0 -20
  293. package/debugging/simulate-and-persist-response.d.ts.map +0 -1
  294. package/debugging/simulate-and-persist-response.js +0 -108
  295. package/debugging/simulate-and-persist-response.js.map +0 -1
  296. package/debugging/simulate-and-persist-response.mjs +0 -89
  297. package/debugging/simulate-and-persist-response.mjs.map +0 -1
  298. package/dispenser-client.d.ts.map +0 -1
  299. package/index.d.ts.map +0 -1
  300. package/indexer-lookup.d.ts.map +0 -1
  301. package/localnet/get-kmd-wallet-account.d.ts.map +0 -1
  302. package/localnet/get-localnet-dispenser-account.d.ts.map +0 -1
  303. package/localnet/get-or-create-kmd-wallet-account.d.ts.map +0 -1
  304. package/localnet/index.d.ts.map +0 -1
  305. package/localnet/is-localnet.d.ts.map +0 -1
  306. package/network-client.d.ts.map +0 -1
  307. package/testing/_asset.d.ts.map +0 -1
  308. package/testing/account.d.ts.map +0 -1
  309. package/testing/fixtures/algokit-log-capture-fixture.d.ts.map +0 -1
  310. package/testing/fixtures/algorand-fixture.d.ts.map +0 -1
  311. package/testing/fixtures/index.d.ts.map +0 -1
  312. package/testing/index.d.ts.map +0 -1
  313. package/testing/indexer.d.ts.map +0 -1
  314. package/testing/test-logger.d.ts.map +0 -1
  315. package/testing/transaction-logger.d.ts.map +0 -1
  316. package/transaction/index.d.ts.map +0 -1
  317. package/transaction/legacy-bridge.d.ts.map +0 -1
  318. package/transaction/perform-atomic-transaction-composer-simulate.d.ts.map +0 -1
  319. package/transaction/transaction.d.ts.map +0 -1
  320. package/transfer/index.d.ts.map +0 -1
  321. package/transfer/transfer-algos.d.ts.map +0 -1
  322. package/transfer/transfer.d.ts.map +0 -1
  323. package/types/account-manager.d.ts.map +0 -1
  324. package/types/account.d.ts.map +0 -1
  325. package/types/algo-http-client-with-retry.d.ts.map +0 -1
  326. package/types/algorand-client-transaction-creator.d.ts.map +0 -1
  327. package/types/algorand-client-transaction-sender.d.ts.map +0 -1
  328. package/types/algorand-client.d.ts.map +0 -1
  329. package/types/amount.d.ts.map +0 -1
  330. package/types/app-client.d.ts.map +0 -1
  331. package/types/app-deployer.d.ts.map +0 -1
  332. package/types/app-manager.d.ts.map +0 -1
  333. package/types/app-spec.d.ts.map +0 -1
  334. package/types/app.d.ts.map +0 -1
  335. package/types/asset-manager.d.ts.map +0 -1
  336. package/types/asset.d.ts.map +0 -1
  337. package/types/client-manager.d.ts.map +0 -1
  338. package/types/composer.d.ts.map +0 -1
  339. package/types/config.d.ts.map +0 -1
  340. package/types/debugging.d.ts.map +0 -1
  341. package/types/dispenser-client.d.ts.map +0 -1
  342. package/types/expand.d.ts.map +0 -1
  343. package/types/indexer.d.ts.map +0 -1
  344. package/types/kmd-account-manager.d.ts.map +0 -1
  345. package/types/logging.d.ts.map +0 -1
  346. package/types/logic-error.d.ts.map +0 -1
  347. package/types/network-client.d.ts.map +0 -1
  348. package/types/testing.d.ts.map +0 -1
  349. package/types/transaction.d.ts.map +0 -1
  350. package/types/transfer.d.ts.map +0 -1
  351. package/types/urlTokenBaseHTTPClient.d.ts.map +0 -1
  352. package/util.d.ts.map +0 -1
@@ -3,17 +3,20 @@ import { Buffer } from 'buffer';
3
3
  import { compileTeal, createApp, updateApp, callApp, getAppGlobalState, getAppLocalState, getAppBoxNames, getAppBoxValue, getAppBoxValueFromABIType } from '../app.mjs';
4
4
  import { replaceDeployTimeControlParams, performTemplateSubstitution, deployApp, getCreatorAppsByName } from '../app-deploy.mjs';
5
5
  import { Config } from '../config.mjs';
6
- import { persistSourceMaps } from '../debugging/debugging.mjs';
7
6
  import { legacySendTransactionBridge } from '../transaction/legacy-bridge.mjs';
8
7
  import { getSenderAddress, encodeTransactionNote } from '../transaction/transaction.mjs';
8
+ import { binaryStartsWith } from '../util.mjs';
9
9
  import { UPDATABLE_TEMPLATE_NAME, DELETABLE_TEMPLATE_NAME } from './app.mjs';
10
- import { PersistSourceMapInput } from './debugging.mjs';
10
+ import { getArc56Method, getArc56ReturnValue, getABITupleFromABIStruct, getABIDecodedValue, getABIEncodedValue } from './app-arc56.mjs';
11
+ import { arc32ToArc56 } from './app-spec.mjs';
12
+ import { EventType } from './lifecycle-events.mjs';
11
13
  import { LogicError } from './logic-error.mjs';
12
14
 
13
15
  var ABIMethod = algosdk.ABIMethod;
14
16
  var AtomicTransactionComposer = algosdk.AtomicTransactionComposer;
15
17
  var getApplicationAddress = algosdk.getApplicationAddress;
16
18
  var Indexer = algosdk.Indexer;
19
+ var OnApplicationComplete = algosdk.OnApplicationComplete;
17
20
  var SourceMap = algosdk.SourceMap;
18
21
  /**
19
22
  * Determines deploy time control (UPDATABLE, DELETABLE) value by inspecting application specification
@@ -37,13 +40,967 @@ function getDeployTimeControl(approval, appSpec, templateVariableName, callConfi
37
40
  return !!abiCallConfig && abiCallConfig !== 'NEVER';
38
41
  });
39
42
  }
40
- /** Application client - a class that wraps an ARC-0032 app spec and provides high productivity methods to deploy and call the app */
43
+ const BYTE_CBLOCK = 38;
44
+ const INT_CBLOCK = 32;
45
+ /**
46
+ * Get the offset of the last constant block at the beginning of the program
47
+ * This value is used to calculate the program counter for an ARC56 program that has a pcOffsetMethod of "cblocks"
48
+ *
49
+ * @param program The program to parse
50
+ * @returns The PC value of the opcode after the last constant block
51
+ */
52
+ function getConstantBlockOffset(program) {
53
+ const bytes = [...program];
54
+ const programSize = bytes.length;
55
+ bytes.shift(); // remove version
56
+ /** The PC of the opcode after the bytecblock */
57
+ let bytecblockOffset;
58
+ /** The PC of the opcode after the intcblock */
59
+ let intcblockOffset;
60
+ while (bytes.length > 0) {
61
+ /** The current byte from the beginning of the byte array */
62
+ const byte = bytes.shift();
63
+ // If the byte is a constant block...
64
+ if (byte === BYTE_CBLOCK || byte === INT_CBLOCK) {
65
+ const isBytecblock = byte === BYTE_CBLOCK;
66
+ /** The byte following the opcode is the number of values in the constant block */
67
+ const valuesRemaining = bytes.shift();
68
+ // Iterate over all the values in the constant block
69
+ for (let i = 0; i < valuesRemaining; i++) {
70
+ if (isBytecblock) {
71
+ /** The byte following the opcode is the length of the next element */
72
+ const length = bytes.shift();
73
+ bytes.splice(0, length);
74
+ }
75
+ else {
76
+ // intcblock is a uvarint, so we need to keep reading until we find the end (MSB is not set)
77
+ while ((bytes.shift() & 0x80) !== 0) {
78
+ // Do nothing...
79
+ }
80
+ }
81
+ }
82
+ if (isBytecblock)
83
+ bytecblockOffset = programSize - bytes.length - 1;
84
+ else
85
+ intcblockOffset = programSize - bytes.length - 1;
86
+ if (bytes[0] !== BYTE_CBLOCK && bytes[0] !== INT_CBLOCK) {
87
+ // if the next opcode isn't a constant block, we're done
88
+ break;
89
+ }
90
+ }
91
+ }
92
+ return Math.max(bytecblockOffset ?? 0, intcblockOffset ?? 0);
93
+ }
94
+ /** ARC-56/ARC-32 application client that allows you to manage calls and
95
+ * state for a specific deployed instance of an app (with a known app ID). */
96
+ class AppClient {
97
+ constructor(params) {
98
+ this._appId = params.appId;
99
+ this._appAddress = algosdk.getApplicationAddress(this._appId);
100
+ this._appSpec = AppClient.normaliseAppSpec(params.appSpec);
101
+ this._appName = params.appName ?? this._appSpec.name;
102
+ this._algorand = params.algorand;
103
+ this._defaultSender = params.defaultSender;
104
+ this._defaultSigner = params.defaultSigner;
105
+ this._approvalSourceMap = params.approvalSourceMap;
106
+ this._clearSourceMap = params.clearSourceMap;
107
+ this._localStateMethods = (address) => this.getStateMethods(() => this.getLocalState(address), () => this._appSpec.state.keys.local, () => this._appSpec.state.maps.local);
108
+ this._globalStateMethods = this.getStateMethods(() => this.getGlobalState(), () => this._appSpec.state.keys.global, () => this._appSpec.state.maps.global);
109
+ this._boxStateMethods = this.getBoxMethods();
110
+ this._paramsMethods = {
111
+ ...this.getMethodCallParamsMethods(),
112
+ /** Get parameters to define bare (raw) transactions to the current app */
113
+ bare: this.getBareParamsMethods(),
114
+ };
115
+ this._createTransactionsMethods = {
116
+ ...this.getMethodCallCreateTransactionMethods(),
117
+ /** Get transactions for bare (raw) calls to the current app */
118
+ bare: this.getBareCreateTransactionMethods(),
119
+ };
120
+ this._sendMethods = {
121
+ ...this.getMethodCallSendMethods(),
122
+ /** Send bare (raw) transactions to the current app */
123
+ bare: this.getBareSendMethods(),
124
+ };
125
+ }
126
+ clone(params) {
127
+ return new AppClient({
128
+ appId: this._appId,
129
+ appSpec: this._appSpec,
130
+ algorand: this._algorand,
131
+ appName: this._appName,
132
+ defaultSender: this._defaultSender,
133
+ defaultSigner: this._defaultSigner,
134
+ approvalSourceMap: this._approvalSourceMap,
135
+ clearSourceMap: this._clearSourceMap,
136
+ ...params,
137
+ });
138
+ }
139
+ /** Start a new `TransactionComposer` transaction group */
140
+ newGroup() {
141
+ return this._algorand.newGroup();
142
+ }
143
+ /**
144
+ * Returns a new `AppClient` client, resolving the app by creator address and name
145
+ * using AlgoKit app deployment semantics (i.e. looking for the app creation transaction note).
146
+ * @param params The parameters to create the app client
147
+ */
148
+ static async fromCreatorAndName(params) {
149
+ const appSpec = AppClient.normaliseAppSpec(params.appSpec);
150
+ const appLookup = params.appLookupCache ?? (await params.algorand.appDeployer.getCreatorAppsByName(params.creatorAddress, params.ignoreCache));
151
+ const appMetadata = appLookup.apps[params.appName ?? appSpec.name];
152
+ if (!appMetadata) {
153
+ throw new Error(`App not found for creator ${params.creatorAddress} and name ${params.appName ?? appSpec.name}`);
154
+ }
155
+ return new AppClient({
156
+ ...params,
157
+ algorand: params.algorand,
158
+ appId: appMetadata.appId,
159
+ });
160
+ }
161
+ /**
162
+ * Returns an `AppClient` instance for the current network based on
163
+ * pre-determined network-specific app IDs specified in the ARC-56 app spec.
164
+ *
165
+ * If no IDs are in the app spec or the network isn't recognised, an error is thrown.
166
+ * @param params The parameters to create the app client
167
+ */
168
+ static async fromNetwork(params) {
169
+ const network = await params.algorand.client.network();
170
+ const appSpec = AppClient.normaliseAppSpec(params.appSpec);
171
+ const networkNames = [network.genesisHash];
172
+ if (network.isLocalNet)
173
+ networkNames.push('localnet');
174
+ if (network.isTestNet)
175
+ networkNames.push('testnet');
176
+ if (network.isMainNet)
177
+ networkNames.push('mainnet');
178
+ const availableAppSpecNetworks = Object.keys(appSpec.networks ?? {});
179
+ const networkIndex = availableAppSpecNetworks.findIndex((n) => networkNames.includes(n));
180
+ if (networkIndex === -1) {
181
+ throw new Error(`No app ID found for network ${JSON.stringify(networkNames)} in the app spec`);
182
+ }
183
+ const appId = BigInt(appSpec.networks[networkIndex].appID);
184
+ return new AppClient({ ...params, appId, appSpec });
185
+ }
186
+ /**
187
+ * Takes a string or parsed JSON object that could be ARC-32 or ARC-56 format and
188
+ * normalises it into a parsed ARC-56 contract object.
189
+ * @param spec The spec to normalise
190
+ * @returns The normalised ARC-56 contract object
191
+ */
192
+ static normaliseAppSpec(spec) {
193
+ const parsedSpec = typeof spec === 'string' ? JSON.parse(spec) : spec;
194
+ const appSpec = 'hints' in parsedSpec ? arc32ToArc56(parsedSpec) : parsedSpec;
195
+ return appSpec;
196
+ }
197
+ /** The ID of the app instance this client is linked to. */
198
+ get appId() {
199
+ return this._appId;
200
+ }
201
+ /** The app address of the app instance this client is linked to. */
202
+ get appAddress() {
203
+ return this._appAddress;
204
+ }
205
+ /** The name of the app (from the ARC-32 / ARC-56 app spec). */
206
+ get appName() {
207
+ return this._appName;
208
+ }
209
+ /** The ARC-56 app spec being used */
210
+ get appSpec() {
211
+ return this._appSpec;
212
+ }
213
+ /** A reference to the underlying `AlgorandClient` this app client is using. */
214
+ get algorand() {
215
+ return this._algorand;
216
+ }
217
+ /** Get parameters to create transactions for the current app.
218
+ *
219
+ * A good mental model for this is that these parameters represent a deferred transaction creation.
220
+ * @example Create a transaction in the future using Algorand Client
221
+ * ```typescript
222
+ * const myMethodCall = appClient.params.call({method: 'my_method', args: [123, 'hello']})
223
+ * // ...
224
+ * await algorand.send.AppMethodCall(myMethodCall)
225
+ * ```
226
+ * @example Define a nested transaction as an ABI argument
227
+ * ```typescript
228
+ * const myMethodCall = appClient.params.call({method: 'my_method', args: [123, 'hello']})
229
+ * await appClient.send.call({method: 'my_method2', args: [myMethodCall]})
230
+ * ```
231
+ */
232
+ get params() {
233
+ return this._paramsMethods;
234
+ }
235
+ /** Create transactions for the current app */
236
+ get createTransaction() {
237
+ return this._createTransactionsMethods;
238
+ }
239
+ /** Send transactions to the current app */
240
+ get send() {
241
+ return this._sendMethods;
242
+ }
243
+ /** Get state (local, global, box) from the current app */
244
+ get state() {
245
+ return {
246
+ /**
247
+ * Methods to access local state for the current app
248
+ * @param address The address of the account to get the local state for
249
+ */
250
+ local: this._localStateMethods,
251
+ /**
252
+ * Methods to access global state for the current app
253
+ */
254
+ global: this._globalStateMethods,
255
+ /**
256
+ * Methods to access box storage for the current app
257
+ */
258
+ box: this._boxStateMethods,
259
+ };
260
+ }
261
+ /**
262
+ * Funds Algo into the app account for this app.
263
+ *
264
+ * An alias for `appClient.send.fundAppAccount(params)`.
265
+ * @param params The parameters for the funding transaction
266
+ * @returns The result of the funding
267
+ */
268
+ async fundAppAccount(params) {
269
+ return this.send.fundAppAccount(params);
270
+ }
271
+ /**
272
+ * Returns raw global state for the current app.
273
+ * @returns The global state
274
+ */
275
+ async getGlobalState() {
276
+ return await this._algorand.app.getGlobalState(this.appId);
277
+ }
278
+ /**
279
+ * Returns raw local state for the given account address.
280
+ * @param address The address of the account to get the local state for
281
+ * @returns The local state
282
+ */
283
+ async getLocalState(address) {
284
+ return await this._algorand.app.getLocalState(this.appId, address);
285
+ }
286
+ /**
287
+ * Returns the names of all current boxes for the current app.
288
+ * @returns The names of the boxes
289
+ */
290
+ async getBoxNames() {
291
+ return await this._algorand.app.getBoxNames(this.appId);
292
+ }
293
+ /**
294
+ * Returns the value of the given box for the current app.
295
+ * @param name The identifier of the box to return
296
+ * @returns The current box value as a byte array
297
+ */
298
+ async getBoxValue(name) {
299
+ return await this._algorand.app.getBoxValue(this.appId, name);
300
+ }
301
+ /**
302
+ * Returns the value of the given box for the current app.
303
+ * @param name The identifier of the box to return
304
+ * @param type
305
+ * @returns The current box value as a byte array
306
+ */
307
+ async getBoxValueFromABIType(name, type) {
308
+ return await this._algorand.app.getBoxValueFromABIType({
309
+ appId: this.appId,
310
+ boxName: name,
311
+ type,
312
+ });
313
+ }
314
+ /**
315
+ * Returns the values of all current boxes for the current app.
316
+ * Note: This will issue multiple HTTP requests (one per box) and it's not an atomic operation so values may be out of sync.
317
+ * @param filter Optional filter to filter which boxes' values are returned
318
+ * @returns The (name, value) pair of the boxes with values as raw byte arrays
319
+ */
320
+ async getBoxValues(filter) {
321
+ const names = (await this.getBoxNames()).filter(filter ?? ((_) => true));
322
+ const values = await this._algorand.app.getBoxValues(this.appId, names.map((name) => name.nameRaw));
323
+ return names.map((name, i) => ({ name, value: values[i] }));
324
+ }
325
+ /**
326
+ * Returns the values of all current boxes for the current app decoded using an ABI Type.
327
+ * Note: This will issue multiple HTTP requests (one per box) and it's not an atomic operation so values may be out of sync.
328
+ * @param type The ABI type to decode the values with
329
+ * @param filter Optional filter to filter which boxes' values are returned
330
+ * @returns The (name, value) pair of the boxes with values as the ABI Value
331
+ */
332
+ async getBoxValuesFromABIType(type, filter) {
333
+ const names = (await this.getBoxNames()).filter(filter ?? ((_) => true));
334
+ const values = await this._algorand.app.getBoxValuesFromABIType({
335
+ appId: this.appId,
336
+ boxNames: names.map((name) => name.nameRaw),
337
+ type,
338
+ });
339
+ return names.map((name, i) => ({ name, value: values[i] }));
340
+ }
341
+ /**
342
+ * Takes an error that may include a logic error from a call to the current app and re-exposes the
343
+ * error to include source code information via the source map and ARC-56 spec.
344
+ * @param e The error to parse
345
+ * @param isClearStateProgram Whether or not the code was running the clear state program (defaults to approval program)
346
+ * @returns The new error, or if there was no logic error or source map then the wrapped error with source details
347
+ */
348
+ async exposeLogicError(e, isClearStateProgram) {
349
+ const pcOffsetMethod = this._appSpec.sourceInfo?.[isClearStateProgram ? 'clear' : 'approval']?.pcOffsetMethod;
350
+ let program;
351
+ if (pcOffsetMethod === 'cblocks') {
352
+ // TODO: Cache this if we deploy the app and it's not updateable
353
+ const appInfo = await this._algorand.app.getById(this.appId);
354
+ program = isClearStateProgram ? appInfo.clearStateProgram : appInfo.approvalProgram;
355
+ }
356
+ return AppClient.exposeLogicError(e, this._appSpec, {
357
+ isClearStateProgram,
358
+ approvalSourceMap: this._approvalSourceMap,
359
+ clearSourceMap: this._clearSourceMap,
360
+ program,
361
+ });
362
+ }
363
+ /**
364
+ * Export the current source maps for the app.
365
+ * @returns The source maps
366
+ */
367
+ exportSourceMaps() {
368
+ if (!this._approvalSourceMap || !this._clearSourceMap) {
369
+ throw new Error("Unable to export source maps; they haven't been loaded into this client - you need to call create, update, or deploy first");
370
+ }
371
+ return {
372
+ approvalSourceMap: this._approvalSourceMap,
373
+ clearSourceMap: this._clearSourceMap,
374
+ };
375
+ }
376
+ /**
377
+ * Import source maps for the app.
378
+ * @param sourceMaps The source maps to import
379
+ */
380
+ importSourceMaps(sourceMaps) {
381
+ this._approvalSourceMap = new SourceMap(sourceMaps.approvalSourceMap);
382
+ this._clearSourceMap = new SourceMap(sourceMaps.clearSourceMap);
383
+ }
384
+ /**
385
+ * Returns the ABI Method spec for the given method string for the app represented by this application client instance
386
+ * @param methodNameOrSignature The method name or method signature to call if an ABI call is being emitted.
387
+ * e.g. `my_method` or `my_method(unit64,string)bytes`
388
+ * @returns A tuple with: [ARC-56 `Method`, algosdk `ABIMethod`]
389
+ */
390
+ getABIMethod(methodNameOrSignature) {
391
+ return getArc56Method(methodNameOrSignature, this._appSpec);
392
+ }
393
+ /**
394
+ * Checks for decode errors on the SendAppTransactionResult and maps the return value to the specified type
395
+ * on the ARC-56 method, replacing the `return` property with the decoded type.
396
+ *
397
+ * If the return type is an ARC-56 struct then the struct will be returned.
398
+ *
399
+ * @param result The SendAppTransactionResult to be mapped
400
+ * @param method The method that was called
401
+ * @returns The smart contract response with an updated return value
402
+ */
403
+ async processMethodCallReturn(result, method) {
404
+ const resultValue = await result;
405
+ return { ...resultValue, return: getArc56ReturnValue(resultValue.return, method, this._appSpec.structs) };
406
+ }
407
+ /**
408
+ * Compiles the approval and clear state programs (if TEAL templates provided),
409
+ * performing any provided deploy-time parameter replacement and stores
410
+ * the source maps.
411
+ *
412
+ * If no TEAL templates provided it will use any byte code provided in the app spec.
413
+ *
414
+ * Will store any generated source maps for later use in debugging.
415
+ */
416
+ async compile(compilation) {
417
+ const result = await AppClient.compile(this._appSpec, this._algorand.app, compilation);
418
+ if (result.compiledApproval) {
419
+ this._approvalSourceMap = result.compiledApproval.sourceMap;
420
+ }
421
+ if (result.compiledClear) {
422
+ this._clearSourceMap = result.compiledClear.sourceMap;
423
+ }
424
+ return result;
425
+ }
426
+ /**
427
+ * Takes an error that may include a logic error from a call to the current app and re-exposes the
428
+ * error to include source code information via the source map and ARC-56 spec.
429
+ * @param e The error to parse
430
+ * @param appSpec The app spec for the app
431
+ * @param details Additional information to inform the error
432
+ * @returns The new error, or if there was no logic error or source map then the wrapped error with source details
433
+ */
434
+ static exposeLogicError(e, appSpec, details) {
435
+ const { isClearStateProgram, approvalSourceMap, clearSourceMap, program } = details;
436
+ const sourceMap = isClearStateProgram ? clearSourceMap : approvalSourceMap;
437
+ const errorDetails = LogicError.parseLogicError(e);
438
+ // Return the error if we don't have a PC
439
+ if (errorDetails === undefined || errorDetails?.pc === undefined)
440
+ return e;
441
+ /** The PC value to find in the ARC56 SourceInfo */
442
+ let arc56Pc = errorDetails?.pc;
443
+ const programSourceInfo = isClearStateProgram ? appSpec.sourceInfo?.clear : appSpec.sourceInfo?.approval;
444
+ /** The offset to apply to the PC if using the cblocks pc offset method */
445
+ let cblocksOffset = 0;
446
+ // If the program uses cblocks offset, then we need to adjust the PC accordingly
447
+ if (programSourceInfo?.pcOffsetMethod === 'cblocks') {
448
+ if (program === undefined)
449
+ throw new Error('Program bytes are required to calculate the ARC56 cblocks PC offset');
450
+ cblocksOffset = getConstantBlockOffset(program);
451
+ arc56Pc = errorDetails.pc - cblocksOffset;
452
+ }
453
+ // Find the source info for this PC and get the error message
454
+ const sourceInfo = programSourceInfo?.sourceInfo.find((s) => s.pc.includes(arc56Pc));
455
+ const errorMessage = sourceInfo?.errorMessage;
456
+ // If we have the source we can display the TEAL in the error message
457
+ if (appSpec.source) {
458
+ let getLineForPc = (inputPc) => sourceMap?.getLineForPc?.(inputPc);
459
+ // If the SourceMap is not defined, we need to provide our own function for going from a PC to TEAL based on ARC56 SourceInfo[]
460
+ if (sourceMap === undefined) {
461
+ getLineForPc = (inputPc) => {
462
+ const teal = programSourceInfo?.sourceInfo.find((s) => s.pc.includes(inputPc - cblocksOffset))?.teal;
463
+ if (teal === undefined)
464
+ return undefined;
465
+ return teal - 1;
466
+ };
467
+ }
468
+ e = new LogicError(errorDetails, Buffer.from(isClearStateProgram ? appSpec.source.clear : appSpec.source.approval, 'base64')
469
+ .toString()
470
+ .split('\n'),
471
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
472
+ getLineForPc);
473
+ }
474
+ if (errorMessage) {
475
+ const appId = JSON.stringify(e).match(/(?<=app=)\d+/)?.[0] || '';
476
+ const txId = JSON.stringify(e).match(/(?<=transaction )\S+(?=:)/)?.[0];
477
+ const error = new Error(`Runtime error when executing ${appSpec.name} (appId: ${appId}) in transaction ${txId}: ${errorMessage}`);
478
+ error.cause = e;
479
+ return error;
480
+ }
481
+ return e;
482
+ }
483
+ /**
484
+ * Compiles the approval and clear state programs (if TEAL templates provided),
485
+ * performing any provided deploy-time parameter replacement and returns
486
+ * the compiled code and any compilation results (including source maps).
487
+ *
488
+ * If no TEAL templates provided it will use any byte code provided in the app spec.
489
+ *
490
+ * Will store any generated source maps for later use in debugging.
491
+ * @param appSpec The app spec for the app
492
+ * @param compilation Any compilation parameters to use
493
+ */
494
+ static async compile(appSpec, appManager, compilation) {
495
+ const { deployTimeParams, updatable, deletable } = compilation ?? {};
496
+ if (!appSpec.source) {
497
+ if (!appSpec.byteCode?.approval || !appSpec.byteCode?.clear) {
498
+ throw new Error(`Attempt to compile app ${appSpec.name} without source or byteCode`);
499
+ }
500
+ return {
501
+ approvalProgram: Buffer.from(appSpec.byteCode.approval, 'base64'),
502
+ clearStateProgram: Buffer.from(appSpec.byteCode.clear, 'base64'),
503
+ };
504
+ }
505
+ const approvalTemplate = Buffer.from(appSpec.source.approval, 'base64').toString('utf-8');
506
+ const compiledApproval = await appManager.compileTealTemplate(approvalTemplate, deployTimeParams, {
507
+ updatable,
508
+ deletable,
509
+ });
510
+ const clearTemplate = Buffer.from(appSpec.source.clear, 'base64').toString('utf-8');
511
+ const compiledClear = await appManager.compileTealTemplate(clearTemplate, deployTimeParams);
512
+ if (Config.debug) {
513
+ await Config.events.emitAsync(EventType.AppCompiled, {
514
+ sources: [
515
+ { compiledTeal: compiledApproval, appName: appSpec.name, fileName: 'approval' },
516
+ { compiledTeal: compiledClear, appName: appSpec.name, fileName: 'clear' },
517
+ ],
518
+ });
519
+ }
520
+ return {
521
+ approvalProgram: compiledApproval.compiledBase64ToBytes,
522
+ compiledApproval,
523
+ clearStateProgram: compiledClear.compiledBase64ToBytes,
524
+ compiledClear,
525
+ };
526
+ }
527
+ /**
528
+ * Returns ABI method arguments ready for a method call params object with default values populated
529
+ * and structs replaced with tuples.
530
+ *
531
+ * It does this by replacing any `undefined` values with the equivalent default value from the given ARC-56 app spec.
532
+ * @param methodNameOrSignature The method name or method signature to call if an ABI call is being emitted.
533
+ * e.g. `my_method` or `my_method(unit64,string)bytes`
534
+ * @param args The arguments to the method with `undefined` for any that should be populated with a default value
535
+ */
536
+ async getABIArgsWithDefaultValues(methodNameOrSignature, args, sender) {
537
+ const m = getArc56Method(methodNameOrSignature, this._appSpec);
538
+ return await Promise.all(args?.map(async (a, i) => {
539
+ const arg = m.args[i];
540
+ if (a !== undefined) {
541
+ // If a struct then convert to tuple for the underlying call
542
+ return arg.struct && typeof a === 'object' && !Array.isArray(a)
543
+ ? getABITupleFromABIStruct(a, this._appSpec.structs[arg.struct], this._appSpec.structs)
544
+ : a;
545
+ }
546
+ const defaultValue = arg.defaultValue;
547
+ if (defaultValue) {
548
+ switch (defaultValue.source) {
549
+ case 'literal':
550
+ if (typeof defaultValue.data === 'number')
551
+ return defaultValue.data;
552
+ return getABIDecodedValue(Buffer.from(defaultValue.data, 'base64'), m.method.args[i].defaultValue?.type ?? m.method.args[i].type, this._appSpec.structs);
553
+ // todo: When ARC-56 supports ABI calls as default args
554
+ // case 'abi': {
555
+ // const method = this.getABIMethod(defaultValue.data as string)
556
+ // const result = await this.send.call({
557
+ // method: defaultValue.data as string,
558
+ // methodArgs: method.args.map(() => undefined),
559
+ // sender,
560
+ // })
561
+ // return result.return!
562
+ // }
563
+ case 'local':
564
+ case 'global': {
565
+ const state = defaultValue.source === 'global' ? await this.getGlobalState() : await this.getLocalState(sender);
566
+ const value = Object.values(state).find((s) => s.keyBase64 === defaultValue.data);
567
+ if (!value) {
568
+ throw new Error(`Preparing default value for argument ${arg.name ?? `arg${i + 1}`} resulted in the failure: The key '${defaultValue.data}' could not be found in ${defaultValue.source} storage`);
569
+ }
570
+ return 'valueRaw' in value
571
+ ? getABIDecodedValue(value.valueRaw, m.method.args[i].defaultValue?.type ?? m.method.args[i].type, this._appSpec.structs)
572
+ : value.value;
573
+ }
574
+ case 'box': {
575
+ const value = await this.getBoxValue(Buffer.from(defaultValue.data, 'base64'));
576
+ return getABIDecodedValue(value, m.method.args[i].defaultValue?.type ?? m.method.args[i].type, this._appSpec.structs);
577
+ }
578
+ }
579
+ }
580
+ if (!algosdk.abiTypeIsTransaction(arg.type)) {
581
+ throw new Error(`No value provided for required argument ${arg.name ?? `arg${i + 1}`} in call to method ${m.name}`);
582
+ }
583
+ }) ?? []);
584
+ }
585
+ getBareParamsMethods() {
586
+ return {
587
+ /** Return params for an update call, including deploy-time TEAL template replacements and compilation if provided */
588
+ update: async (params) => {
589
+ return this.getBareParams({
590
+ ...params,
591
+ ...(await this.compile(params)),
592
+ }, OnApplicationComplete.UpdateApplicationOC);
593
+ },
594
+ /** Return params for an opt-in call */
595
+ optIn: (params) => {
596
+ return this.getBareParams(params, OnApplicationComplete.OptInOC);
597
+ },
598
+ /** Return params for a delete call */
599
+ delete: (params) => {
600
+ return this.getBareParams(params, OnApplicationComplete.DeleteApplicationOC);
601
+ },
602
+ /** Return params for a clear state call */
603
+ clearState: (params) => {
604
+ return this.getBareParams(params, OnApplicationComplete.ClearStateOC);
605
+ },
606
+ /** Return params for a close out call */
607
+ closeOut: (params) => {
608
+ return this.getBareParams(params, OnApplicationComplete.CloseOutOC);
609
+ },
610
+ /** Return params for a call (defaults to no-op) */
611
+ call: (params) => {
612
+ return this.getBareParams(params, params?.onComplete ?? OnApplicationComplete.NoOpOC);
613
+ },
614
+ };
615
+ }
616
+ getBareCreateTransactionMethods() {
617
+ return {
618
+ /** Returns a transaction for an update call, including deploy-time TEAL template replacements and compilation if provided */
619
+ update: async (params) => {
620
+ return this._algorand.createTransaction.appUpdate(await this.params.bare.update(params));
621
+ },
622
+ /** Returns a transaction for an opt-in call */
623
+ optIn: (params) => {
624
+ return this._algorand.createTransaction.appCall(this.params.bare.optIn(params));
625
+ },
626
+ /** Returns a transaction for a delete call */
627
+ delete: (params) => {
628
+ return this._algorand.createTransaction.appDelete(this.params.bare.delete(params));
629
+ },
630
+ /** Returns a transaction for a clear state call */
631
+ clearState: (params) => {
632
+ return this._algorand.createTransaction.appCall(this.params.bare.clearState(params));
633
+ },
634
+ /** Returns a transaction for a close out call */
635
+ closeOut: (params) => {
636
+ return this._algorand.createTransaction.appCall(this.params.bare.closeOut(params));
637
+ },
638
+ /** Returns a transaction for a call (defaults to no-op) */
639
+ call: (params) => {
640
+ return this._algorand.createTransaction.appCall(this.params.bare.call(params));
641
+ },
642
+ };
643
+ }
644
+ getBareSendMethods() {
645
+ return {
646
+ /** Signs and sends an update call, including deploy-time TEAL template replacements and compilation if provided */
647
+ update: async (params) => {
648
+ const compiled = await this.compile(params);
649
+ return {
650
+ ...(await this.handleCallErrors(async () => this._algorand.send.appUpdate(await this.params.bare.update(params)))),
651
+ ...compiled,
652
+ };
653
+ },
654
+ /** Signs and sends an opt-in call */
655
+ optIn: (params) => {
656
+ return this.handleCallErrors(() => this._algorand.send.appCall(this.params.bare.optIn(params)));
657
+ },
658
+ /** Signs and sends a delete call */
659
+ delete: (params) => {
660
+ return this.handleCallErrors(() => this._algorand.send.appDelete(this.params.bare.delete(params)));
661
+ },
662
+ /** Signs and sends a clear state call */
663
+ clearState: (params) => {
664
+ return this.handleCallErrors(() => this._algorand.send.appCall(this.params.bare.clearState(params)));
665
+ },
666
+ /** Signs and sends a close out call */
667
+ closeOut: (params) => {
668
+ return this.handleCallErrors(() => this._algorand.send.appCall(this.params.bare.closeOut(params)));
669
+ },
670
+ /** Signs and sends a call (defaults to no-op) */
671
+ call: (params) => {
672
+ return this.handleCallErrors(() => this._algorand.send.appCall(this.params.bare.call(params)));
673
+ },
674
+ };
675
+ }
676
+ getMethodCallParamsMethods() {
677
+ return {
678
+ /** Return params for a payment transaction to fund the app account */
679
+ fundAppAccount: (params) => {
680
+ return {
681
+ ...params,
682
+ sender: this.getSender(params.sender),
683
+ signer: this.getSigner(params.sender, params.signer),
684
+ receiver: this.appAddress,
685
+ };
686
+ },
687
+ /** Return params for an update ABI call, including deploy-time TEAL template replacements and compilation if provided */
688
+ update: async (params) => {
689
+ return (await this.getABIParams({
690
+ ...params,
691
+ ...(await this.compile(params)),
692
+ }, OnApplicationComplete.UpdateApplicationOC));
693
+ },
694
+ /** Return params for an opt-in ABI call */
695
+ optIn: async (params) => {
696
+ return (await this.getABIParams(params, OnApplicationComplete.OptInOC));
697
+ },
698
+ /** Return params for an delete ABI call */
699
+ delete: async (params) => {
700
+ return (await this.getABIParams(params, OnApplicationComplete.DeleteApplicationOC));
701
+ },
702
+ /** Return params for an close out ABI call */
703
+ closeOut: async (params) => {
704
+ return (await this.getABIParams(params, OnApplicationComplete.CloseOutOC));
705
+ },
706
+ /** Return params for an ABI call */
707
+ call: async (params) => {
708
+ return (await this.getABIParams(params, params.onComplete ?? OnApplicationComplete.NoOpOC));
709
+ },
710
+ };
711
+ }
712
+ getMethodCallSendMethods() {
713
+ return {
714
+ /** Sign and send transactions for a payment transaction to fund the app account */
715
+ fundAppAccount: (params) => {
716
+ return this._algorand.send.payment(this.params.fundAppAccount(params));
717
+ },
718
+ /**
719
+ * Sign and send transactions for an update ABI call, including deploy-time TEAL template replacements and compilation if provided
720
+ */
721
+ update: async (params) => {
722
+ const compiled = await this.compile(params);
723
+ return {
724
+ ...(await this.handleCallErrors(async () => this.processMethodCallReturn(this._algorand.send.appUpdateMethodCall(await this.params.update({ ...params })), getArc56Method(params.method, this._appSpec)))),
725
+ ...compiled,
726
+ };
727
+ },
728
+ /**
729
+ * Sign and send transactions for an opt-in ABI call
730
+ */
731
+ optIn: (params) => {
732
+ return this.handleCallErrors(async () => this.processMethodCallReturn(this._algorand.send.appCallMethodCall(await this.params.optIn(params)), getArc56Method(params.method, this._appSpec)));
733
+ },
734
+ /**
735
+ * Sign and send transactions for a delete ABI call
736
+ */
737
+ delete: (params) => {
738
+ return this.handleCallErrors(async () => this.processMethodCallReturn(this._algorand.send.appDeleteMethodCall(await this.params.delete(params)), getArc56Method(params.method, this._appSpec)));
739
+ },
740
+ /**
741
+ * Sign and send transactions for a close out ABI call
742
+ */
743
+ closeOut: (params) => {
744
+ return this.handleCallErrors(async () => this.processMethodCallReturn(this._algorand.send.appCallMethodCall(await this.params.closeOut(params)), getArc56Method(params.method, this._appSpec)));
745
+ },
746
+ /**
747
+ * Sign and send transactions for a call (defaults to no-op)
748
+ */
749
+ call: async (params) => {
750
+ // Read-only call - do it via simulate
751
+ if (params.onComplete === OnApplicationComplete.NoOpOC ||
752
+ (!params.onComplete && getArc56Method(params.method, this._appSpec).method.readonly)) {
753
+ const result = await this._algorand
754
+ .newGroup()
755
+ .addAppCallMethodCall(await this.params.call(params))
756
+ .simulate({
757
+ allowUnnamedResources: params.populateAppCallResources ?? true,
758
+ // Simulate calls for a readonly method shouldn't invoke signing
759
+ skipSignatures: true,
760
+ });
761
+ return this.processMethodCallReturn({
762
+ ...result,
763
+ transaction: result.transactions.at(-1),
764
+ confirmation: result.confirmations.at(-1),
765
+ // eslint-disable-next-line @typescript-eslint/no-non-null-asserted-optional-chain
766
+ return: (result.returns?.length ?? 0 > 0) ? result.returns?.at(-1) : undefined,
767
+ }, getArc56Method(params.method, this._appSpec));
768
+ }
769
+ return this.handleCallErrors(async () => this.processMethodCallReturn(this._algorand.send.appCallMethodCall(await this.params.call(params)), getArc56Method(params.method, this._appSpec)));
770
+ },
771
+ };
772
+ }
773
+ getMethodCallCreateTransactionMethods() {
774
+ return {
775
+ /** Return transaction for a payment transaction to fund the app account */
776
+ fundAppAccount: (params) => {
777
+ return this._algorand.createTransaction.payment(this.params.fundAppAccount(params));
778
+ },
779
+ /**
780
+ * Return transactions for an update ABI call, including deploy-time TEAL template replacements and compilation if provided
781
+ */
782
+ update: async (params) => {
783
+ return this._algorand.createTransaction.appUpdateMethodCall(await this.params.update(params));
784
+ },
785
+ /**
786
+ * Return transactions for an opt-in ABI call
787
+ */
788
+ optIn: async (params) => {
789
+ return this._algorand.createTransaction.appCallMethodCall(await this.params.optIn(params));
790
+ },
791
+ /**
792
+ * Return transactions for a delete ABI call
793
+ */
794
+ delete: async (params) => {
795
+ return this._algorand.createTransaction.appDeleteMethodCall(await this.params.delete(params));
796
+ },
797
+ /**
798
+ * Return transactions for a close out ABI call
799
+ */
800
+ closeOut: async (params) => {
801
+ return this._algorand.createTransaction.appCallMethodCall(await this.params.closeOut(params));
802
+ },
803
+ /**
804
+ * Return transactions for an ABI call (defaults to no-op)
805
+ */
806
+ call: async (params) => {
807
+ return this._algorand.createTransaction.appCallMethodCall(await this.params.call(params));
808
+ },
809
+ };
810
+ }
811
+ /** Returns the sender for a call, using the provided sender or using the `defaultSender`
812
+ * if none provided and throws an error if neither provided */
813
+ getSender(sender) {
814
+ if (!sender && !this._defaultSender) {
815
+ throw new Error(`No sender provided and no default sender present in app client for call to app ${this._appName}`);
816
+ }
817
+ return sender ?? this._defaultSender;
818
+ }
819
+ /** Returns the signer for a call, using the provided signer or the `defaultSigner`
820
+ * if no signer was provided and the call will use default sender
821
+ * or `undefined` otherwise (so the signer is resolved from `AlgorandClient`) */
822
+ getSigner(sender, signer) {
823
+ return signer ?? (!sender ? this._defaultSigner : undefined);
824
+ }
825
+ getBareParams(params, onComplete) {
826
+ return {
827
+ ...params,
828
+ appId: this._appId,
829
+ sender: this.getSender(params?.sender),
830
+ signer: this.getSigner(params?.sender, params?.signer),
831
+ onComplete,
832
+ };
833
+ }
834
+ async getABIParams(params, onComplete) {
835
+ const sender = this.getSender(params.sender);
836
+ const method = getArc56Method(params.method, this._appSpec);
837
+ const args = await this.getABIArgsWithDefaultValues(params.method, params.args, sender);
838
+ return {
839
+ ...params,
840
+ appId: this._appId,
841
+ sender: sender,
842
+ signer: this.getSigner(params.sender, params.signer),
843
+ method,
844
+ onComplete,
845
+ args,
846
+ };
847
+ }
848
+ /** Make the given call and catch any errors, augmenting with debugging information before re-throwing. */
849
+ async handleCallErrors(call) {
850
+ try {
851
+ return await call();
852
+ }
853
+ catch (e) {
854
+ throw await this.exposeLogicError(e);
855
+ }
856
+ }
857
+ getBoxMethods() {
858
+ // eslint-disable-next-line @typescript-eslint/no-this-alias
859
+ const that = this;
860
+ const stateMethods = {
861
+ /**
862
+ * Returns all single-key state values in a record keyed by the key name and the value a decoded ABI value.
863
+ */
864
+ getAll: async () => {
865
+ return Object.fromEntries(await Promise.all(Object.keys(that._appSpec.state.keys.box).map(async (key) => [key, await stateMethods.getValue(key)])));
866
+ },
867
+ /**
868
+ * Returns a single state value for the current app with the value a decoded ABI value.
869
+ * @param name The name of the state value to retrieve the value for
870
+ * @returns
871
+ */
872
+ getValue: async (name) => {
873
+ const metadata = that._appSpec.state.keys.box[name];
874
+ const value = await that.getBoxValue(Buffer.from(metadata.key, 'base64'));
875
+ return getABIDecodedValue(value, metadata.valueType, that._appSpec.structs);
876
+ },
877
+ /**
878
+ *
879
+ * @param mapName The name of the map to read from
880
+ * @param key The key within the map (without any map prefix) as either a Buffer with the bytes or a value
881
+ * that will be converted to bytes by encoding it using the specified ABI key type
882
+ * in the ARC-56 spec
883
+ */
884
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
885
+ getMapValue: async (mapName, key) => {
886
+ const metadata = that._appSpec.state.maps.box[mapName];
887
+ const prefix = Buffer.from(metadata.prefix ?? '', 'base64');
888
+ const encodedKey = Buffer.concat([prefix, getABIEncodedValue(key, metadata.keyType, that._appSpec.structs)]);
889
+ const base64Key = Buffer.from(encodedKey).toString('base64');
890
+ const value = await that.getBoxValue(Buffer.from(base64Key, 'base64'));
891
+ return getABIDecodedValue(value, metadata.valueType, that._appSpec.structs);
892
+ },
893
+ /**
894
+ *
895
+ * @param mapName The name of the map to read from
896
+ * @param key The key within the map as either a Buffer with the bytes or a value
897
+ * that will be converted to bytes by encoding it using the specified ABI key type
898
+ * in the ARC-56 spec
899
+ * @param appState
900
+ */
901
+ getMap: async (mapName) => {
902
+ const metadata = that._appSpec.state.maps.box[mapName];
903
+ const prefix = Buffer.from(metadata.prefix ?? '', 'base64');
904
+ const boxNames = await that.getBoxNames();
905
+ return new Map(await Promise.all(boxNames
906
+ .filter((b) => binaryStartsWith(b.nameRaw, prefix))
907
+ .map(async (b) => {
908
+ const encodedKey = Buffer.concat([prefix, b.nameRaw]);
909
+ const base64Key = Buffer.from(encodedKey).toString('base64');
910
+ return [
911
+ getABIDecodedValue(b.nameRaw.slice(prefix.length), metadata.keyType, that._appSpec.structs),
912
+ getABIDecodedValue(await that.getBoxValue(Buffer.from(base64Key, 'base64')), metadata.valueType, that._appSpec.structs),
913
+ ];
914
+ })));
915
+ },
916
+ };
917
+ return stateMethods;
918
+ }
919
+ getStateMethods(stateGetter, keyGetter, mapGetter) {
920
+ // eslint-disable-next-line @typescript-eslint/no-this-alias
921
+ const that = this;
922
+ const stateMethods = {
923
+ /**
924
+ * Returns all single-key state values in a record keyed by the key name and the value a decoded ABI value.
925
+ */
926
+ getAll: async () => {
927
+ const appState = await stateGetter();
928
+ return Object.fromEntries(await Promise.all(Object.keys(keyGetter()).map(async (key) => [key, await stateMethods.getValue(key, appState)])));
929
+ },
930
+ /**
931
+ * Returns a single state value for the current app with the value a decoded ABI value.
932
+ * @param name The name of the state value to retrieve the value for
933
+ * @param appState Optional cached value of the current state
934
+ * @returns
935
+ */
936
+ getValue: async (name, appState) => {
937
+ const state = Object.values(appState ?? (await stateGetter()));
938
+ const metadata = keyGetter()[name];
939
+ const value = state.find((s) => s.keyBase64 === metadata.key);
940
+ if (value && 'valueRaw' in value) {
941
+ return getABIDecodedValue(value.valueRaw, metadata.valueType, that._appSpec.structs);
942
+ }
943
+ return value?.value;
944
+ },
945
+ /**
946
+ * Returns a single value from the given map for the current app with the value a decoded ABI value.
947
+ * @param mapName The name of the map to read from
948
+ * @param key The key within the map (without any map prefix) as either a Buffer with the bytes or a value
949
+ * that will be converted to bytes by encoding it using the specified ABI key type
950
+ * in the ARC-56 spec
951
+ * @param appState Optional cached value of the current state
952
+ */
953
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
954
+ getMapValue: async (mapName, key, appState) => {
955
+ const state = Object.values(appState ?? (await stateGetter()));
956
+ const metadata = mapGetter()[mapName];
957
+ const prefix = Buffer.from(metadata.prefix ?? '', 'base64');
958
+ const encodedKey = Buffer.concat([prefix, getABIEncodedValue(key, metadata.keyType, that._appSpec.structs)]);
959
+ const base64Key = Buffer.from(encodedKey).toString('base64');
960
+ const value = state.find((s) => s.keyBase64 === base64Key);
961
+ if (value && 'valueRaw' in value) {
962
+ return getABIDecodedValue(value.valueRaw, metadata.valueType, that._appSpec.structs);
963
+ }
964
+ return value?.value;
965
+ },
966
+ /**
967
+ * Returns all map values for the given map.
968
+ * @param mapName The name of the map to read from
969
+ * @param appState Optional cached value of the current state
970
+ * @returns A map of all key-value pairs in the map as a `Record<string, ABIValue>`
971
+ */
972
+ getMap: async (mapName) => {
973
+ const state = Object.values(await stateGetter());
974
+ const metadata = mapGetter()[mapName];
975
+ const prefix = Buffer.from(metadata.prefix ?? '', 'base64');
976
+ return new Map(state
977
+ .filter((s) => binaryStartsWith(s.keyRaw, prefix))
978
+ .map((s) => {
979
+ const key = s.keyRaw.slice(prefix.length);
980
+ return [
981
+ getABIDecodedValue(key, metadata.keyType, this._appSpec.structs),
982
+ getABIDecodedValue('valueRaw' in s ? s.valueRaw : s.value, metadata.valueType, this._appSpec.structs),
983
+ ];
984
+ }));
985
+ },
986
+ };
987
+ return stateMethods;
988
+ }
989
+ }
990
+ /**
991
+ * @deprecated Use `AppClient` instead e.g. via `algorand.client.getAppClientById` or
992
+ * `algorand.client.getAppClientByCreatorAndName`.
993
+ * If you want to `create` or `deploy` then use `AppFactory` e.g. via `algorand.client.getAppFactory`,
994
+ * which will in turn give you an `AppClient` instance against the created/deployed app to make other calls.
995
+ *
996
+ * Application client - a class that wraps an ARC-0032 app spec and provides high productivity methods to deploy and call the app */
41
997
  class ApplicationClient {
42
- // todo: process ABI args as needed to make them nicer to deal with like beaker-ts
43
- // todo: support readonly, noop method calls
44
- // todo: find create, update, delete, etc. methods from app spec and call them by default
45
- // todo: intelligent version management when deploying
46
998
  /**
999
+ * @deprecated Use `AppClient` instead e.g. via `algorand.client.getAppClientById` or
1000
+ * `algorand.client.getAppClientByCreatorAndName`.
1001
+ * If you want to `create` or `deploy` then use `AppFactory` e.g. via `algorand.client.getAppFactory`,
1002
+ * which will in turn give you an `AppClient` instance against the created/deployed app to make other calls.
1003
+ *
47
1004
  * Create a new ApplicationClient instance
48
1005
  * @param appDetails The details of the app
49
1006
  * @param algod An algod instance
@@ -78,9 +1035,11 @@ class ApplicationClient {
78
1035
  this.params = params;
79
1036
  }
80
1037
  /**
81
- * Compiles the approval and clear programs and sets up the source map.
1038
+ * @deprecated Use `AppClient.compile()` instead.
1039
+ *
1040
+ * Compiles the approval and clear state programs and sets up the source map.
82
1041
  * @param compilation The deploy-time parameters for the compilation
83
- * @returns The compiled approval and clear programs
1042
+ * @returns The compiled approval and clear state programs
84
1043
  */
85
1044
  async compile(compilation) {
86
1045
  const { deployTimeParams, updatable, deletable } = compilation ?? {};
@@ -95,15 +1054,12 @@ class ApplicationClient {
95
1054
  const clear = performTemplateSubstitution(clearTemplate, deployTimeParams ?? this.deployTimeParams);
96
1055
  const clearCompiled = await compileTeal(clear, this.algod);
97
1056
  this._clearSourceMap = clearCompiled?.sourceMap;
98
- if (Config.debug && Config.projectRoot) {
99
- persistSourceMaps({
1057
+ if (Config.debug) {
1058
+ await Config.events.emitAsync(EventType.AppCompiled, {
100
1059
  sources: [
101
- PersistSourceMapInput.fromCompiledTeal(approvalCompiled, this._appName, 'approval.teal'),
102
- PersistSourceMapInput.fromCompiledTeal(clearCompiled, this._appName, 'clear.teal'),
1060
+ { compiledTeal: approvalCompiled, appName: this._appName, fileName: 'approval' },
1061
+ { compiledTeal: clearCompiled, appName: this._appName, fileName: 'clear' },
103
1062
  ],
104
- projectRoot: Config.projectRoot,
105
- client: this.algod,
106
- withSources: true,
107
1063
  });
108
1064
  }
109
1065
  return { approvalCompiled, clearCompiled };
@@ -130,6 +1086,8 @@ class ApplicationClient {
130
1086
  this._clearSourceMap = new SourceMap(sourceMaps.clearSourceMap);
131
1087
  }
132
1088
  /**
1089
+ * @deprecated Use `deploy` from an `AppFactory` instance instead.
1090
+ *
133
1091
  * Idempotently deploy (create, update/delete if changed) an app against the given name via the given creator account, including deploy-time template placeholder substitutions.
134
1092
  *
135
1093
  * To understand the architecture decisions behind this functionality please see https://github.com/algorandfoundation/algokit-cli/blob/main/docs/architecture-decisions/2023-01-12_smart-contract-deployment.md
@@ -215,6 +1173,8 @@ class ApplicationClient {
215
1173
  }
216
1174
  }
217
1175
  /**
1176
+ * @deprecated Use `create` from an `AppFactory` instance instead.
1177
+ *
218
1178
  * Creates a smart contract app, returns the details of the created app.
219
1179
  * @param create The parameters to create the app with
220
1180
  * @returns The details of the created app, or the transaction to create it if `skipSending` and the compilation result
@@ -255,10 +1215,12 @@ class ApplicationClient {
255
1215
  return { ...result, ...{ compiledApproval: approvalCompiled, compiledClear: clearCompiled } };
256
1216
  }
257
1217
  catch (e) {
258
- throw this.exposeLogicError(e);
1218
+ throw await this.exposeLogicError(e);
259
1219
  }
260
1220
  }
261
1221
  /**
1222
+ * @deprecated Use `appClient.send.update` or `appClient.createTransaction.update` from an `AppClient` instance instead.
1223
+ *
262
1224
  * Updates the smart contract app.
263
1225
  * @param update The parameters to update the app with
264
1226
  * @returns The transaction send result and the compilation result
@@ -287,10 +1249,12 @@ class ApplicationClient {
287
1249
  return { ...result, ...{ compiledApproval: approvalCompiled, compiledClear: clearCompiled } };
288
1250
  }
289
1251
  catch (e) {
290
- throw this.exposeLogicError(e);
1252
+ throw await this.exposeLogicError(e);
291
1253
  }
292
1254
  }
293
1255
  /**
1256
+ * @deprecated Use `appClient.send.call` or `appClient.createTransaction.call` from an `AppClient` instance instead.
1257
+ *
294
1258
  * Issues a no_op (normal) call to the app.
295
1259
  * @param call The call details.
296
1260
  * @returns The result of the call
@@ -324,6 +1288,8 @@ class ApplicationClient {
324
1288
  return await this.callOfType(call, 'no_op');
325
1289
  }
326
1290
  /**
1291
+ * @deprecated Use `appClient.send.optIn` or `appClient.createTransaction.optIn` from an `AppClient` instance instead.
1292
+ *
327
1293
  * Issues a opt_in call to the app.
328
1294
  * @param call The call details.
329
1295
  * @returns The result of the call
@@ -332,6 +1298,8 @@ class ApplicationClient {
332
1298
  return await this.callOfType(call, 'opt_in');
333
1299
  }
334
1300
  /**
1301
+ * @deprecated Use `appClient.send.closeOut` or `appClient.createTransaction.closeOut` from an `AppClient` instance instead.
1302
+ *
335
1303
  * Issues a close_out call to the app.
336
1304
  * @param call The call details.
337
1305
  * @returns The result of the call
@@ -340,6 +1308,8 @@ class ApplicationClient {
340
1308
  return await this.callOfType(call, 'close_out');
341
1309
  }
342
1310
  /**
1311
+ * @deprecated Use `appClient.send.clearState` or `appClient.createTransaction.clearState` from an `AppClient` instance instead.
1312
+ *
343
1313
  * Issues a clear_state call to the app.
344
1314
  * @param call The call details.
345
1315
  * @returns The result of the call
@@ -348,6 +1318,8 @@ class ApplicationClient {
348
1318
  return await this.callOfType(call, 'clear_state');
349
1319
  }
350
1320
  /**
1321
+ * @deprecated Use `appClient.send.delete` or `appClient.createTransaction.delete` from an `AppClient` instance instead.
1322
+ *
351
1323
  * Issues a delete_application call to the app.
352
1324
  * @param call The call details.
353
1325
  * @returns The result of the call
@@ -356,6 +1328,8 @@ class ApplicationClient {
356
1328
  return await this.callOfType(call, 'delete_application');
357
1329
  }
358
1330
  /**
1331
+ * @deprecated Use `appClient.send.call` or `appClient.createTransaction.call` from an `AppClient` instance instead.
1332
+ *
359
1333
  * Issues a call to the app with the given call type.
360
1334
  * @param call The call details.
361
1335
  * @param callType The call type
@@ -498,6 +1472,8 @@ class ApplicationClient {
498
1472
  })));
499
1473
  }
500
1474
  /**
1475
+ * @deprecated Use `appClient.params.*` from an `AppClient` instance instead.
1476
+ *
501
1477
  * Returns the arguments for an app call for the given ABI method or raw method specification.
502
1478
  * @param args The call args specific to this application client
503
1479
  * @param sender The sender of this call. Will be used to fetch any default argument values if applicable
@@ -555,6 +1531,8 @@ class ApplicationClient {
555
1531
  }
556
1532
  }
557
1533
  /**
1534
+ * @deprecated Use `appClient.getABIMethod` instead.
1535
+ *
558
1536
  * Returns the ABI Method parameters for the given method name string for the app represented by this application client instance
559
1537
  * @param method Either the name of the method or the ABI method spec definition string
560
1538
  * @returns The ABI method params for the given method
@@ -581,6 +1559,8 @@ class ApplicationClient {
581
1559
  return methodParams ? new ABIMethod(methodParams) : undefined;
582
1560
  }
583
1561
  /**
1562
+ * @deprecated Use `appClient.appId` and `appClient.appAddress` from an `AppClient` instance instead.
1563
+ *
584
1564
  * Gets the reference information for the current application instance.
585
1565
  * `appId` will be 0 if it can't find an app.
586
1566
  * @returns The app reference, or if deployed using the `deploy` method, the app metadata too
@@ -622,7 +1602,7 @@ class ApplicationClient {
622
1602
  .toString()
623
1603
  .split('\n'),
624
1604
  // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
625
- isClear ? this._clearSourceMap : this._approvalSourceMap);
1605
+ (pc) => (isClear ? this._clearSourceMap : this._approvalSourceMap).getLineForPc(pc));
626
1606
  else
627
1607
  return e;
628
1608
  }
@@ -631,5 +1611,5 @@ class ApplicationClient {
631
1611
  }
632
1612
  }
633
1613
 
634
- export { ApplicationClient };
1614
+ export { AppClient, ApplicationClient };
635
1615
  //# sourceMappingURL=app-client.mjs.map