@algorandfoundation/algokit-utils 6.2.1 → 7.0.0-alpha.1

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