@algorandfoundation/algokit-utils 9.2.0 → 9.2.1-beta.2

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 (340) hide show
  1. package/_virtual/_rolldown/runtime.js +33 -0
  2. package/_virtual/_rolldown/runtime.mjs +13 -0
  3. package/account/account.d.ts +25 -30
  4. package/account/account.js +151 -146
  5. package/account/account.js.map +1 -1
  6. package/account/account.mjs +149 -144
  7. package/account/account.mjs.map +1 -1
  8. package/account/get-account-config-from-environment.d.ts +7 -2
  9. package/account/get-account-config-from-environment.js +19 -21
  10. package/account/get-account-config-from-environment.js.map +1 -1
  11. package/account/get-account-config-from-environment.mjs +19 -19
  12. package/account/get-account-config-from-environment.mjs.map +1 -1
  13. package/account/get-account.d.ts +14 -12
  14. package/account/get-account.js +56 -59
  15. package/account/get-account.js.map +1 -1
  16. package/account/get-account.mjs +56 -57
  17. package/account/get-account.mjs.map +1 -1
  18. package/account/get-dispenser-account.d.ts +9 -5
  19. package/account/get-dispenser-account.js +20 -18
  20. package/account/get-dispenser-account.js.map +1 -1
  21. package/account/get-dispenser-account.mjs +20 -16
  22. package/account/get-dispenser-account.mjs.map +1 -1
  23. package/account/mnemonic-account.d.ts +7 -3
  24. package/account/mnemonic-account.js +17 -17
  25. package/account/mnemonic-account.js.map +1 -1
  26. package/account/mnemonic-account.mjs +15 -15
  27. package/account/mnemonic-account.mjs.map +1 -1
  28. package/amount.d.ts +40 -35
  29. package/amount.js +33 -34
  30. package/amount.js.map +1 -1
  31. package/amount.mjs +33 -32
  32. package/amount.mjs.map +1 -1
  33. package/app-client.d.ts +10 -6
  34. package/app-client.js +91 -86
  35. package/app-client.js.map +1 -1
  36. package/app-client.mjs +91 -84
  37. package/app-client.mjs.map +1 -1
  38. package/app-deploy.d.ts +26 -24
  39. package/app-deploy.js +235 -253
  40. package/app-deploy.js.map +1 -1
  41. package/app-deploy.mjs +233 -251
  42. package/app-deploy.mjs.map +1 -1
  43. package/app.d.ts +45 -46
  44. package/app.js +253 -271
  45. package/app.js.map +1 -1
  46. package/app.mjs +249 -267
  47. package/app.mjs.map +1 -1
  48. package/asset.d.ts +16 -12
  49. package/asset.js +116 -122
  50. package/asset.js.map +1 -1
  51. package/asset.mjs +116 -120
  52. package/asset.mjs.map +1 -1
  53. package/config.d.ts +7 -2
  54. package/config.js +5 -7
  55. package/config.js.map +1 -1
  56. package/config.mjs +5 -4
  57. package/config.mjs.map +1 -1
  58. package/debugging/debugging.d.ts +5 -1
  59. package/debugging/debugging.js +11 -11
  60. package/debugging/debugging.js.map +1 -1
  61. package/debugging/debugging.mjs +11 -9
  62. package/debugging/debugging.mjs.map +1 -1
  63. package/dispenser-client.d.ts +7 -2
  64. package/dispenser-client.js +23 -24
  65. package/dispenser-client.js.map +1 -1
  66. package/dispenser-client.mjs +23 -22
  67. package/dispenser-client.mjs.map +1 -1
  68. package/index.d.ts +27 -18
  69. package/index.js +140 -143
  70. package/index.mjs +27 -29
  71. package/indexer-lookup.d.ts +18 -11
  72. package/indexer-lookup.js +112 -120
  73. package/indexer-lookup.js.map +1 -1
  74. package/indexer-lookup.mjs +105 -118
  75. package/indexer-lookup.mjs.map +1 -1
  76. package/localnet/get-kmd-wallet-account.d.ts +9 -7
  77. package/localnet/get-kmd-wallet-account.js +28 -26
  78. package/localnet/get-kmd-wallet-account.js.map +1 -1
  79. package/localnet/get-kmd-wallet-account.mjs +28 -24
  80. package/localnet/get-kmd-wallet-account.mjs.map +1 -1
  81. package/localnet/get-localnet-dispenser-account.d.ts +7 -5
  82. package/localnet/get-localnet-dispenser-account.js +17 -15
  83. package/localnet/get-localnet-dispenser-account.js.map +1 -1
  84. package/localnet/get-localnet-dispenser-account.mjs +17 -13
  85. package/localnet/get-localnet-dispenser-account.mjs.map +1 -1
  86. package/localnet/get-or-create-kmd-wallet-account.d.ts +10 -8
  87. package/localnet/get-or-create-kmd-wallet-account.js +28 -26
  88. package/localnet/get-or-create-kmd-wallet-account.js.map +1 -1
  89. package/localnet/get-or-create-kmd-wallet-account.mjs +28 -24
  90. package/localnet/get-or-create-kmd-wallet-account.mjs.map +1 -1
  91. package/localnet/is-localnet.d.ts +7 -3
  92. package/localnet/is-localnet.js +9 -10
  93. package/localnet/is-localnet.js.map +1 -1
  94. package/localnet/is-localnet.mjs +9 -8
  95. package/localnet/is-localnet.mjs.map +1 -1
  96. package/network-client.d.ts +17 -15
  97. package/network-client.js +115 -116
  98. package/network-client.js.map +1 -1
  99. package/network-client.mjs +115 -114
  100. package/network-client.mjs.map +1 -1
  101. package/package.json +12 -3
  102. package/testing/account.d.ts +11 -9
  103. package/testing/account.js +31 -33
  104. package/testing/account.js.map +1 -1
  105. package/testing/account.mjs +29 -31
  106. package/testing/account.mjs.map +1 -1
  107. package/testing/fixtures/algokit-log-capture-fixture.d.ts +7 -2
  108. package/testing/fixtures/algokit-log-capture-fixture.js +36 -41
  109. package/testing/fixtures/algokit-log-capture-fixture.js.map +1 -1
  110. package/testing/fixtures/algokit-log-capture-fixture.mjs +36 -39
  111. package/testing/fixtures/algokit-log-capture-fixture.mjs.map +1 -1
  112. package/testing/fixtures/algorand-fixture.d.ts +9 -4
  113. package/testing/fixtures/algorand-fixture.js +67 -62
  114. package/testing/fixtures/algorand-fixture.js.map +1 -1
  115. package/testing/fixtures/algorand-fixture.mjs +66 -59
  116. package/testing/fixtures/algorand-fixture.mjs.map +1 -1
  117. package/testing/index.d.ts +7 -5
  118. package/testing/index.js +13 -18
  119. package/testing/index.mjs +7 -7
  120. package/testing/indexer.d.ts +5 -1
  121. package/testing/indexer.js +28 -37
  122. package/testing/indexer.js.map +1 -1
  123. package/testing/indexer.mjs +28 -35
  124. package/testing/indexer.mjs.map +1 -1
  125. package/testing/test-logger.d.ts +41 -36
  126. package/testing/test-logger.js +71 -76
  127. package/testing/test-logger.js.map +1 -1
  128. package/testing/test-logger.mjs +71 -74
  129. package/testing/test-logger.mjs.map +1 -1
  130. package/testing/transaction-logger.d.ts +30 -27
  131. package/testing/transaction-logger.js +77 -93
  132. package/testing/transaction-logger.js.map +1 -1
  133. package/testing/transaction-logger.mjs +74 -90
  134. package/testing/transaction-logger.mjs.map +1 -1
  135. package/transaction/legacy-bridge.js +100 -111
  136. package/transaction/legacy-bridge.js.map +1 -1
  137. package/transaction/legacy-bridge.mjs +97 -108
  138. package/transaction/legacy-bridge.mjs.map +1 -1
  139. package/transaction/perform-atomic-transaction-composer-simulate.d.ts +7 -5
  140. package/transaction/perform-atomic-transaction-composer-simulate.js +31 -36
  141. package/transaction/perform-atomic-transaction-composer-simulate.js.map +1 -1
  142. package/transaction/perform-atomic-transaction-composer-simulate.mjs +28 -33
  143. package/transaction/perform-atomic-transaction-composer-simulate.mjs.map +1 -1
  144. package/transaction/transaction.d.ts +34 -35
  145. package/transaction/transaction.js +716 -914
  146. package/transaction/transaction.js.map +1 -1
  147. package/transaction/transaction.mjs +713 -911
  148. package/transaction/transaction.mjs.map +1 -1
  149. package/transfer/transfer-algos.d.ts +9 -5
  150. package/transfer/transfer-algos.js +26 -27
  151. package/transfer/transfer-algos.js.map +1 -1
  152. package/transfer/transfer-algos.mjs +26 -25
  153. package/transfer/transfer-algos.mjs.map +1 -1
  154. package/transfer/transfer.d.ts +11 -8
  155. package/transfer/transfer.js +94 -100
  156. package/transfer/transfer.js.map +1 -1
  157. package/transfer/transfer.mjs +94 -98
  158. package/transfer/transfer.mjs.map +1 -1
  159. package/types/account-manager.d.ts +432 -429
  160. package/types/account-manager.js +591 -602
  161. package/types/account-manager.js.map +1 -1
  162. package/types/account-manager.mjs +587 -599
  163. package/types/account-manager.mjs.map +1 -1
  164. package/types/account.d.ts +192 -202
  165. package/types/account.js +91 -88
  166. package/types/account.js.map +1 -1
  167. package/types/account.mjs +88 -86
  168. package/types/account.mjs.map +1 -1
  169. package/types/algo-http-client-with-retry.d.ts +15 -10
  170. package/types/algo-http-client-with-retry.js +70 -92
  171. package/types/algo-http-client-with-retry.js.map +1 -1
  172. package/types/algo-http-client-with-retry.mjs +69 -90
  173. package/types/algo-http-client-with-retry.mjs.map +1 -1
  174. package/types/algorand-client-transaction-creator.d.ts +778 -771
  175. package/types/algorand-client-transaction-creator.js +733 -732
  176. package/types/algorand-client-transaction-creator.js.map +1 -1
  177. package/types/algorand-client-transaction-creator.mjs +732 -730
  178. package/types/algorand-client-transaction-creator.mjs.map +1 -1
  179. package/types/algorand-client-transaction-sender.d.ts +1090 -1360
  180. package/types/algorand-client-transaction-sender.js +930 -961
  181. package/types/algorand-client-transaction-sender.js.map +1 -1
  182. package/types/algorand-client-transaction-sender.mjs +927 -959
  183. package/types/algorand-client-transaction-sender.mjs.map +1 -1
  184. package/types/algorand-client.d.ts +239 -236
  185. package/types/algorand-client.js +322 -320
  186. package/types/algorand-client.js.map +1 -1
  187. package/types/algorand-client.mjs +321 -318
  188. package/types/algorand-client.mjs.map +1 -1
  189. package/types/amount.d.ts +47 -43
  190. package/types/amount.js +66 -70
  191. package/types/amount.js.map +1 -1
  192. package/types/amount.mjs +63 -68
  193. package/types/amount.mjs.map +1 -1
  194. package/types/app-arc56.d.ts +235 -272
  195. package/types/app-arc56.js +124 -170
  196. package/types/app-arc56.js.map +1 -1
  197. package/types/app-arc56.mjs +121 -168
  198. package/types/app-arc56.mjs.map +1 -1
  199. package/types/app-client.d.ts +1128 -2009
  200. package/types/app-client.js +1633 -1791
  201. package/types/app-client.js.map +1 -1
  202. package/types/app-client.mjs +1624 -1783
  203. package/types/app-client.mjs.map +1 -1
  204. package/types/app-deployer.d.ts +139 -141
  205. package/types/app-deployer.js +344 -384
  206. package/types/app-deployer.js.map +1 -1
  207. package/types/app-deployer.mjs +341 -382
  208. package/types/app-deployer.mjs.map +1 -1
  209. package/types/app-factory.d.ts +762 -932
  210. package/types/app-factory.js +496 -488
  211. package/types/app-factory.js.map +1 -1
  212. package/types/app-factory.mjs +491 -484
  213. package/types/app-factory.mjs.map +1 -1
  214. package/types/app-manager.d.ts +304 -310
  215. package/types/app-manager.js +422 -475
  216. package/types/app-manager.js.map +1 -1
  217. package/types/app-manager.mjs +419 -473
  218. package/types/app-manager.mjs.map +1 -1
  219. package/types/app-spec.d.ts +118 -117
  220. package/types/app-spec.js +125 -135
  221. package/types/app-spec.js.map +1 -1
  222. package/types/app-spec.mjs +121 -132
  223. package/types/app-spec.mjs.map +1 -1
  224. package/types/app.d.ts +229 -241
  225. package/types/app.js +36 -28
  226. package/types/app.js.map +1 -1
  227. package/types/app.mjs +33 -26
  228. package/types/app.mjs.map +1 -1
  229. package/types/asset-manager.d.ts +204 -199
  230. package/types/asset-manager.js +165 -174
  231. package/types/asset-manager.js.map +1 -1
  232. package/types/asset-manager.mjs +164 -172
  233. package/types/asset-manager.mjs.map +1 -1
  234. package/types/asset.d.ts +95 -91
  235. package/types/asset.js +0 -3
  236. package/types/asset.mjs +0 -2
  237. package/types/async-event-emitter.d.ts +18 -13
  238. package/types/async-event-emitter.js +37 -49
  239. package/types/async-event-emitter.js.map +1 -1
  240. package/types/async-event-emitter.mjs +36 -47
  241. package/types/async-event-emitter.mjs.map +1 -1
  242. package/types/client-manager.d.ts +453 -451
  243. package/types/client-manager.js +602 -598
  244. package/types/client-manager.js.map +1 -1
  245. package/types/client-manager.mjs +597 -594
  246. package/types/client-manager.mjs.map +1 -1
  247. package/types/composer.d.ts +1211 -1258
  248. package/types/composer.js +1436 -1498
  249. package/types/composer.js.map +1 -1
  250. package/types/composer.mjs +1430 -1493
  251. package/types/composer.mjs.map +1 -1
  252. package/types/config.d.ts +53 -48
  253. package/types/config.js +78 -77
  254. package/types/config.js.map +1 -1
  255. package/types/config.mjs +77 -75
  256. package/types/config.mjs.map +1 -1
  257. package/types/debugging.d.ts +25 -23
  258. package/types/debugging.js +9 -11
  259. package/types/debugging.js.map +1 -1
  260. package/types/debugging.mjs +8 -9
  261. package/types/debugging.mjs.map +1 -1
  262. package/types/dispenser-client.d.ts +57 -52
  263. package/types/dispenser-client.js +120 -141
  264. package/types/dispenser-client.js.map +1 -1
  265. package/types/dispenser-client.mjs +119 -139
  266. package/types/dispenser-client.mjs.map +1 -1
  267. package/types/expand.d.ts +5 -3
  268. package/types/expand.js +0 -3
  269. package/types/expand.mjs +0 -2
  270. package/types/indexer.d.ts +104 -100
  271. package/types/indexer.js +36 -31
  272. package/types/indexer.js.map +1 -1
  273. package/types/indexer.mjs +32 -30
  274. package/types/indexer.mjs.map +1 -1
  275. package/types/instance-of.d.ts +5 -3
  276. package/types/instance-of.js +0 -3
  277. package/types/instance-of.mjs +0 -2
  278. package/types/kmd-account-manager.d.ts +75 -70
  279. package/types/kmd-account-manager.js +150 -184
  280. package/types/kmd-account-manager.js.map +1 -1
  281. package/types/kmd-account-manager.mjs +147 -182
  282. package/types/kmd-account-manager.mjs.map +1 -1
  283. package/types/lifecycle-events.d.ts +13 -8
  284. package/types/lifecycle-events.js +10 -7
  285. package/types/lifecycle-events.js.map +1 -1
  286. package/types/lifecycle-events.mjs +9 -7
  287. package/types/lifecycle-events.mjs.map +1 -1
  288. package/types/logging.d.ts +15 -11
  289. package/types/logging.js +30 -31
  290. package/types/logging.js.map +1 -1
  291. package/types/logging.mjs +29 -29
  292. package/types/logging.mjs.map +1 -1
  293. package/types/logic-error.d.ts +33 -29
  294. package/types/logic-error.js +50 -49
  295. package/types/logic-error.js.map +1 -1
  296. package/types/logic-error.mjs +49 -47
  297. package/types/logic-error.mjs.map +1 -1
  298. package/types/network-client.d.ts +32 -27
  299. package/types/network-client.js +10 -9
  300. package/types/network-client.js.map +1 -1
  301. package/types/network-client.mjs +9 -7
  302. package/types/network-client.mjs.map +1 -1
  303. package/types/testing.d.ts +131 -132
  304. package/types/testing.js +0 -3
  305. package/types/testing.mjs +0 -2
  306. package/types/transaction.d.ts +110 -110
  307. package/types/transaction.js +0 -3
  308. package/types/transaction.mjs +0 -2
  309. package/types/transfer.d.ts +70 -66
  310. package/types/transfer.js +0 -3
  311. package/types/transfer.mjs +0 -2
  312. package/util.js +73 -118
  313. package/util.js.map +1 -1
  314. package/util.mjs +73 -116
  315. package/util.mjs.map +1 -1
  316. package/account/index.d.ts +0 -5
  317. package/debugging/index.d.ts +0 -1
  318. package/index.js.map +0 -1
  319. package/index.mjs.map +0 -1
  320. package/localnet/index.d.ts +0 -4
  321. package/testing/_asset.d.ts +0 -3
  322. package/testing/fixtures/index.d.ts +0 -2
  323. package/testing/index.js.map +0 -1
  324. package/testing/index.mjs.map +0 -1
  325. package/transaction/index.d.ts +0 -2
  326. package/transaction/legacy-bridge.d.ts +0 -35
  327. package/transfer/index.d.ts +0 -2
  328. package/types/asset.js.map +0 -1
  329. package/types/asset.mjs.map +0 -1
  330. package/types/expand.js.map +0 -1
  331. package/types/expand.mjs.map +0 -1
  332. package/types/instance-of.js.map +0 -1
  333. package/types/instance-of.mjs.map +0 -1
  334. package/types/testing.js.map +0 -1
  335. package/types/testing.mjs.map +0 -1
  336. package/types/transaction.js.map +0 -1
  337. package/types/transaction.mjs.map +0 -1
  338. package/types/transfer.js.map +0 -1
  339. package/types/transfer.mjs.map +0 -1
  340. package/util.d.ts +0 -48
@@ -1,490 +1,498 @@
1
- 'use strict';
2
-
3
- var algosdk = require('algosdk');
4
- var types_app = require('./app.js');
5
- var types_appArc56 = require('./app-arc56.js');
6
- var types_appClient = require('./app-client.js');
7
-
8
- var SourceMap = algosdk.ProgramSourceMap;
9
- var OnApplicationComplete = algosdk.OnApplicationComplete;
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
+ const require_runtime = require("../_virtual/_rolldown/runtime.js");
3
+ require("./app.js");
4
+ const require_app_arc56 = require("./app-arc56.js");
5
+ const require_app_client = require("./app-client.js");
6
+ let algosdk = require("algosdk");
7
+ algosdk = require_runtime.__toESM(algosdk);
8
+ //#region src/types/app-factory.ts
9
+ var SourceMap = algosdk.default.ProgramSourceMap;
10
+ var OnApplicationComplete = algosdk.default.OnApplicationComplete;
10
11
  /**
11
- * ARC-56/ARC-32 app factory that, for a given app spec, allows you to create
12
- * and deploy one or more app instances and to create one or more app clients
13
- * to interact with those (or other) app instances.
14
- */
15
- class AppFactory {
16
- /**
17
- * Create a new app factory.
18
- * @param params The parameters to create the app factory
19
- * @returns The `AppFactory` instance
20
- * @example
21
- * ```typescript
22
- * const appFactory = new AppFactory({
23
- * appSpec: appSpec,
24
- * algorand: AlgorandClient.mainNet(),
25
- * })
26
- */
27
- constructor(params) {
28
- /** Create transactions for the current app */
29
- this.createTransaction = {
30
- /** Create bare (raw) transactions for the current app */
31
- bare: {
32
- /**
33
- * Create a create app call transaction using a bare (raw) create call.
34
- *
35
- * Performs deploy-time TEAL template placeholder substitutions (if specified).
36
- * @param params The parameters to create the create call transaction
37
- * @returns The create call transaction
38
- */
39
- create: async (params) => {
40
- return this._algorand.createTransaction.appCreate(await this.params.bare.create(params));
41
- },
42
- },
43
- /**
44
- * Create a create app call transaction using an ABI create call.
45
- *
46
- * Performs deploy-time TEAL template placeholder substitutions (if specified).
47
- * @param params The parameters to create the create call transaction
48
- * @returns The create call transaction
49
- */
50
- create: async (params) => {
51
- return this._algorand.createTransaction.appCreateMethodCall(await this.params.create(params));
52
- },
53
- };
54
- /** Send transactions to the current app */
55
- this.send = {
56
- /** Send bare (raw) transactions for the current app */
57
- bare: {
58
- /**
59
- * Creates an instance of the app using a bare (raw) create call and returns the result
60
- * of the creation transaction and an app client to interact with that app instance.
61
- *
62
- * Performs deploy-time TEAL template placeholder substitutions (if specified).
63
- * @param params The parameters to create the app
64
- * @returns The app client and the result of the creation transaction
65
- */
66
- create: async (params) => {
67
- const updatable = params?.updatable ?? this._updatable;
68
- const deletable = params?.deletable ?? this._deletable;
69
- const deployTimeParams = params?.deployTimeParams ?? this._deployTimeParams;
70
- const compiled = await this.compile({ deployTimeParams, updatable, deletable });
71
- const result = await this.handleCallErrors(async () => ({
72
- ...(await this._algorand.send.appCreate(await this.params.bare.create({ ...params, updatable, deletable, deployTimeParams }))),
73
- return: undefined,
74
- }));
75
- return {
76
- appClient: this.getAppClientById({
77
- appId: result.appId,
78
- }),
79
- result: {
80
- ...result,
81
- ...compiled,
82
- },
83
- };
84
- },
85
- },
86
- /**
87
- * Creates an instance of the app and returns the result of the creation
88
- * transaction and an app client to interact with that app instance.
89
- *
90
- * Performs deploy-time TEAL template placeholder substitutions (if specified).
91
- * @param params The parameters to create the app
92
- * @returns The app client and the result of the creation transaction
93
- */
94
- create: async (params) => {
95
- const updatable = params?.updatable ?? this._updatable;
96
- const deletable = params?.deletable ?? this._deletable;
97
- const deployTimeParams = params?.deployTimeParams ?? this._deployTimeParams;
98
- const compiled = await this.compile({ deployTimeParams, updatable, deletable });
99
- const result = await this.handleCallErrors(async () => this.parseMethodCallReturn(this._algorand.send.appCreateMethodCall(await this.params.create({ ...params, updatable, deletable, deployTimeParams })), types_appArc56.getArc56Method(params.method, this._appSpec)));
100
- return {
101
- appClient: this.getAppClientById({
102
- appId: result.appId,
103
- }),
104
- result: {
105
- ...result,
106
- ...compiled,
107
- },
108
- };
109
- },
110
- };
111
- this._appSpec = types_appClient.AppClient.normaliseAppSpec(params.appSpec);
112
- this._appName = params.appName ?? this._appSpec.name;
113
- this._algorand = params.algorand;
114
- this._version = params.version ?? '1.0';
115
- this._defaultSender = typeof params.defaultSender === 'string' ? algosdk.Address.fromString(params.defaultSender) : params.defaultSender;
116
- this._defaultSigner = params.defaultSigner;
117
- this._deployTimeParams = params.deployTimeParams;
118
- this._updatable = params.updatable;
119
- this._deletable = params.deletable;
120
- this._paramsMethods = this.getParamsMethods();
121
- }
122
- /** The name of the app (from the ARC-32 / ARC-56 app spec or override). */
123
- get appName() {
124
- return this._appName;
125
- }
126
- /** The ARC-56 app spec being used */
127
- get appSpec() {
128
- return this._appSpec;
129
- }
130
- /** Return the algorand client this factory is using. */
131
- get algorand() {
132
- return this._algorand;
133
- }
134
- /** Get parameters to create transactions (create and deploy related calls) for the current app.
135
- *
136
- * A good mental model for this is that these parameters represent a deferred transaction creation.
137
- * @example Create a transaction in the future using Algorand Client
138
- * ```typescript
139
- * const createAppParams = appFactory.params.create({method: 'create_method', args: [123, 'hello']})
140
- * // ...
141
- * await algorand.send.AppCreateMethodCall(createAppParams)
142
- * ```
143
- * @example Define a nested transaction as an ABI argument
144
- * ```typescript
145
- * const createAppParams = appFactory.params.create({method: 'create_method', args: [123, 'hello']})
146
- * await appClient.send.call({method: 'my_method', args: [createAppParams]})
147
- * ```
148
- */
149
- get params() {
150
- return this._paramsMethods;
151
- }
152
- /**
153
- * Idempotently deploy (create if not exists, update if changed) an app against the given name for the given creator account, including deploy-time TEAL template placeholder substitutions (if specified).
154
- *
155
- * **Note:** When using the return from this function be sure to check `operationPerformed` to get access to various return properties like `transaction`, `confirmation` and `deleteResult`.
156
- *
157
- * **Note:** if there is a breaking state schema change to an existing app (and `onSchemaBreak` is set to `'replace'`) the existing app will be deleted and re-created.
158
- *
159
- * **Note:** if there is an update (different TEAL code) to an existing app (and `onUpdate` is set to `'replace'`) the existing app will be deleted and re-created.
160
- * @param params The arguments to control the app deployment
161
- * @returns The app client and the result of the deployment
162
- * @example
163
- * ```ts
164
- * const { appClient, result } = await factory.deploy({
165
- * createParams: {
166
- * sender: 'SENDER_ADDRESS',
167
- * approvalProgram: 'APPROVAL PROGRAM',
168
- * clearStateProgram: 'CLEAR PROGRAM',
169
- * schema: {
170
- * globalByteSlices: 0,
171
- * globalInts: 0,
172
- * localByteSlices: 0,
173
- * localInts: 0
174
- * }
175
- * },
176
- * updateParams: {
177
- * sender: 'SENDER_ADDRESS'
178
- * },
179
- * deleteParams: {
180
- * sender: 'SENDER_ADDRESS'
181
- * },
182
- * metadata: { name: 'my_app', version: '2.0', updatable: false, deletable: false },
183
- * onSchemaBreak: 'append',
184
- * onUpdate: 'append'
185
- * })
186
- * ```
187
- */
188
- async deploy(params) {
189
- const updatable = params.updatable ?? this._updatable ?? this.getDeployTimeControl('updatable');
190
- const deletable = params.deletable ?? this._deletable ?? this.getDeployTimeControl('deletable');
191
- const deployTimeParams = params.deployTimeParams ?? this._deployTimeParams;
192
- // Compile using a appID 0 AppClient so we can register the error handler and use the programs
193
- // to identify the app within the error handler (because we can't use app ID 0)
194
- const tempAppClient = this.getAppClientById({ appId: 0n });
195
- const compiled = await tempAppClient.compile({ deployTimeParams, updatable, deletable });
196
- const deployResult = await this._algorand.appDeployer.deploy({
197
- ...params,
198
- createParams: await (params.createParams && 'method' in params.createParams
199
- ? this.params.create({ ...params.createParams, updatable, deletable, deployTimeParams })
200
- : this.params.bare.create({ ...params.createParams, updatable, deletable, deployTimeParams })),
201
- updateParams: params.updateParams && 'method' in params.updateParams
202
- ? this.params.deployUpdate(params.updateParams)
203
- : this.params.bare.deployUpdate(params.updateParams),
204
- deleteParams: params.deleteParams && 'method' in params.deleteParams
205
- ? this.params.deployDelete(params.deleteParams)
206
- : this.params.bare.deployDelete(params.deleteParams),
207
- metadata: {
208
- name: params.appName ?? this._appName,
209
- version: this._version,
210
- updatable,
211
- deletable,
212
- },
213
- });
214
- const appClient = this.getAppClientById({
215
- appId: deployResult.appId,
216
- appName: params.appName,
217
- });
218
- const result = {
219
- ...deployResult,
220
- ...compiled,
221
- };
222
- return {
223
- appClient,
224
- result: {
225
- ...result,
226
- return: 'return' in result
227
- ? result.operationPerformed === 'update'
228
- ? params.updateParams && 'method' in params.updateParams
229
- ? types_appArc56.getArc56ReturnValue(result.return, types_appArc56.getArc56Method(params.updateParams.method, this._appSpec), this._appSpec.structs)
230
- : undefined
231
- : params.createParams && 'method' in params.createParams
232
- ? types_appArc56.getArc56ReturnValue(result.return, types_appArc56.getArc56Method(params.createParams.method, this._appSpec), this._appSpec.structs)
233
- : undefined
234
- : undefined,
235
- deleteReturn: 'deleteReturn' in result && params.deleteParams && 'method' in params.deleteParams
236
- ? types_appArc56.getArc56ReturnValue(result.deleteReturn, types_appArc56.getArc56Method(params.deleteParams.method, this._appSpec), this._appSpec.structs)
237
- : undefined,
238
- },
239
- };
240
- }
241
- /**
242
- * Returns a new `AppClient` client for an app instance of the given ID.
243
- *
244
- * Automatically populates appName, defaultSender and source maps from the factory
245
- * if not specified in the params.
246
- * @param params The parameters to create the app client
247
- * @returns The `AppClient` instance
248
- * @example
249
- * ```typescript
250
- * const appClient = factory.getAppClientById({ appId: 12345n })
251
- * ```
252
- */
253
- getAppClientById(params) {
254
- return new types_appClient.AppClient({
255
- ...params,
256
- algorand: this._algorand,
257
- appSpec: this._appSpec,
258
- appName: params.appName ?? this._appName,
259
- defaultSender: params.defaultSender ?? this._defaultSender,
260
- defaultSigner: params.defaultSigner ?? this._defaultSigner,
261
- approvalSourceMap: params.approvalSourceMap ?? this._approvalSourceMap,
262
- clearSourceMap: params.clearSourceMap ?? this._clearSourceMap,
263
- });
264
- }
265
- /**
266
- * Returns a new `AppClient` client, resolving the app by creator address and name
267
- * using AlgoKit app deployment semantics (i.e. looking for the app creation transaction note).
268
- *
269
- * Automatically populates appName, defaultSender and source maps from the factory
270
- * if not specified in the params.
271
- * @param params The parameters to create the app client
272
- * @returns The `AppClient` instance
273
- * @example
274
- * ```typescript
275
- * const appClient = factory.getAppClientByCreatorAndName({ creatorAddress: 'CREATOR_ADDRESS', appName: 'my_app' })
276
- * ```
277
- */
278
- getAppClientByCreatorAndName(params) {
279
- return types_appClient.AppClient.fromCreatorAndName({
280
- ...params,
281
- algorand: this._algorand,
282
- appSpec: this._appSpec,
283
- appName: params.appName ?? this._appName,
284
- defaultSender: params.defaultSender ?? this._defaultSender,
285
- approvalSourceMap: params.approvalSourceMap ?? this._approvalSourceMap,
286
- clearSourceMap: params.clearSourceMap ?? this._clearSourceMap,
287
- });
288
- }
289
- /**
290
- * Takes an error that may include a logic error from a call to the current app and re-exposes the
291
- * error to include source code information via the source map and ARC-56 spec.
292
- * @param e The error to parse
293
- * @param isClearStateProgram Whether or not the code was running the clear state program (defaults to approval program)
294
- * @returns The new error, or if there was no logic error or source map then the wrapped error with source details
295
- */
296
- exposeLogicError(e, isClearStateProgram) {
297
- return types_appClient.AppClient.exposeLogicError(e, this._appSpec, {
298
- isClearStateProgram,
299
- approvalSourceMap: this._approvalSourceMap,
300
- clearSourceMap: this._clearSourceMap,
301
- });
302
- }
303
- /**
304
- * Export the current source maps for the app.
305
- * @returns The source maps
306
- */
307
- exportSourceMaps() {
308
- if (!this._approvalSourceMap || !this._clearSourceMap) {
309
- 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");
310
- }
311
- return {
312
- approvalSourceMap: this._approvalSourceMap,
313
- clearSourceMap: this._clearSourceMap,
314
- };
315
- }
316
- /**
317
- * Import source maps for the app.
318
- * @param sourceMaps The source maps to import
319
- */
320
- importSourceMaps(sourceMaps) {
321
- this._approvalSourceMap = new SourceMap(sourceMaps.approvalSourceMap);
322
- this._clearSourceMap = new SourceMap(sourceMaps.clearSourceMap);
323
- }
324
- getDeployTimeControl(control) {
325
- const approval = this._appSpec.source?.approval ? Buffer.from(this._appSpec.source.approval, 'base64').toString('utf-8') : undefined;
326
- // variable not present, so unknown control value
327
- if (!approval || !approval.includes(control === 'updatable' ? types_app.UPDATABLE_TEMPLATE_NAME : types_app.DELETABLE_TEMPLATE_NAME))
328
- return undefined;
329
- // A call is present and configured
330
- return (this._appSpec.bareActions.call.includes(control === 'updatable' ? 'UpdateApplication' : 'DeleteApplication') ||
331
- Object.values(this._appSpec.methods).some((c) => c.actions.call.includes(control === 'updatable' ? 'UpdateApplication' : 'DeleteApplication')));
332
- }
333
- getParamsMethods() {
334
- return {
335
- /** Return params for a create ABI call, including deploy-time TEAL template replacements and compilation if provided */
336
- create: async (params) => {
337
- const compiled = await this.compile({ ...params, deployTimeParams: params.deployTimeParams ?? this._deployTimeParams });
338
- return this.getABIParams({
339
- ...params,
340
- deployTimeParams: params.deployTimeParams ?? this._deployTimeParams,
341
- schema: params.schema ?? {
342
- globalByteSlices: this._appSpec.state.schema.global.bytes,
343
- globalInts: this._appSpec.state.schema.global.ints,
344
- localByteSlices: this._appSpec.state.schema.local.bytes,
345
- localInts: this._appSpec.state.schema.local.ints,
346
- },
347
- approvalProgram: compiled.approvalProgram,
348
- clearStateProgram: compiled.clearStateProgram,
349
- }, params.onComplete ?? OnApplicationComplete.NoOpOC);
350
- },
351
- /** Return params for a deployment update ABI call */
352
- deployUpdate: (params) => {
353
- return this.getABIParams(params, OnApplicationComplete.UpdateApplicationOC);
354
- },
355
- /** Return params for a deployment delete ABI call */
356
- deployDelete: (params) => {
357
- return this.getABIParams(params, OnApplicationComplete.DeleteApplicationOC);
358
- },
359
- bare: {
360
- /** Return params for a create bare call, including deploy-time TEAL template replacements and compilation if provided */
361
- create: async (params) => {
362
- return this.getBareParams({
363
- ...params,
364
- deployTimeParams: params?.deployTimeParams ?? this._deployTimeParams,
365
- schema: params?.schema ?? {
366
- globalByteSlices: this._appSpec.state.schema.global.bytes,
367
- globalInts: this._appSpec.state.schema.global.ints,
368
- localByteSlices: this._appSpec.state.schema.local.bytes,
369
- localInts: this._appSpec.state.schema.local.ints,
370
- },
371
- ...(await this.compile({ ...params, deployTimeParams: params?.deployTimeParams ?? this._deployTimeParams })),
372
- }, params?.onComplete ?? OnApplicationComplete.NoOpOC);
373
- },
374
- /** Return params for a deployment update bare call */
375
- deployUpdate: (params) => {
376
- return this.getBareParams(params, OnApplicationComplete.UpdateApplicationOC);
377
- },
378
- /** Return params for a deployment delete bare call */
379
- deployDelete: (params) => {
380
- return this.getBareParams(params, OnApplicationComplete.DeleteApplicationOC);
381
- },
382
- },
383
- };
384
- }
385
- /** Make the given call and catch any errors, augmenting with debugging information before re-throwing. */
386
- async handleCallErrors(call) {
387
- try {
388
- return await call();
389
- }
390
- catch (e) {
391
- throw this.exposeLogicError(e);
392
- }
393
- }
394
- /**
395
- * Compiles the approval and clear state programs (if TEAL templates provided),
396
- * performing any provided deploy-time parameter replacement and stores
397
- * the source maps.
398
- *
399
- * If no TEAL templates provided it will use any byte code provided in the app spec.
400
- *
401
- * Will store any generated source maps for later use in debugging.
402
- * @param compilation Optional compilation parameters to use for the compilation
403
- * @returns The compilation result
404
- * @example
405
- * ```typescript
406
- * const result = await factory.compile()
407
- * ```
408
- */
409
- async compile(compilation) {
410
- const result = await types_appClient.AppClient.compile(this._appSpec, this._algorand.app, compilation);
411
- if (result.compiledApproval) {
412
- this._approvalSourceMap = result.compiledApproval.sourceMap;
413
- }
414
- if (result.compiledClear) {
415
- this._clearSourceMap = result.compiledClear.sourceMap;
416
- }
417
- return result;
418
- }
419
- getBareParams(params, onComplete) {
420
- return {
421
- ...params,
422
- sender: this.getSender(params?.sender),
423
- signer: this.getSigner(params?.sender, params?.signer),
424
- onComplete,
425
- };
426
- }
427
- getABIParams(params, onComplete) {
428
- return {
429
- ...params,
430
- sender: this.getSender(params.sender),
431
- signer: this.getSigner(params.sender, params.signer),
432
- method: types_appArc56.getArc56Method(params.method, this._appSpec),
433
- args: this.getCreateABIArgsWithDefaultValues(params.method, params.args),
434
- onComplete,
435
- };
436
- }
437
- getCreateABIArgsWithDefaultValues(methodNameOrSignature, args) {
438
- const m = types_appArc56.getArc56Method(methodNameOrSignature, this._appSpec);
439
- return args?.map((a, i) => {
440
- const arg = m.args[i];
441
- if (a !== undefined) {
442
- // If a struct then convert to tuple for the underlying call
443
- return arg.struct && typeof a === 'object' && !Array.isArray(a)
444
- ? types_appArc56.getABITupleFromABIStruct(a, this._appSpec.structs[arg.struct], this._appSpec.structs)
445
- : a;
446
- }
447
- const defaultValue = arg.defaultValue;
448
- if (defaultValue) {
449
- switch (defaultValue.source) {
450
- case 'literal':
451
- return types_appArc56.getABIDecodedValue(Buffer.from(defaultValue.data, 'base64'), m.method.args[i].type, this._appSpec.structs);
452
- default:
453
- throw new Error(`Can't provide default value for ${defaultValue.source} for a contract creation call`);
454
- }
455
- }
456
- throw new Error(`No value provided for required argument ${arg.name ?? `arg${i + 1}`} in call to method ${m.name}`);
457
- });
458
- }
459
- /** Returns the sender for a call, using the `defaultSender`
460
- * if none provided and throws an error if neither provided */
461
- getSender(sender) {
462
- if (!sender && !this._defaultSender) {
463
- throw new Error(`No sender provided and no default sender present in app factory for call to app ${this._appName}`);
464
- }
465
- return typeof sender === 'string' ? algosdk.Address.fromString(sender) : (sender ?? this._defaultSender);
466
- }
467
- /** Returns the signer for a call, using the provided signer or the `defaultSigner`
468
- * if no signer was provided and the sender resolves to the default sender, the call will use default signer
469
- * or `undefined` otherwise (so the signer is resolved from `AlgorandClient`) */
470
- getSigner(sender, signer) {
471
- return signer ?? (!sender || sender === this._defaultSender ? this._defaultSigner : undefined);
472
- }
473
- /**
474
- * Checks for decode errors on the SendAppTransactionResult and maps the return value to the specified type
475
- * on the ARC-56 method.
476
- *
477
- * If the return type is a struct then the struct will be returned.
478
- *
479
- * @param result The SendAppTransactionResult to be mapped
480
- * @param method The method that was called
481
- * @returns The smart contract response with an updated return value
482
- */
483
- async parseMethodCallReturn(result, method) {
484
- const resultValue = await result;
485
- return { ...resultValue, return: types_appArc56.getArc56ReturnValue(resultValue.return, method, this._appSpec.structs) };
486
- }
487
- }
488
-
12
+ * ARC-56/ARC-32 app factory that, for a given app spec, allows you to create
13
+ * and deploy one or more app instances and to create one or more app clients
14
+ * to interact with those (or other) app instances.
15
+ */
16
+ var AppFactory = class {
17
+ _appSpec;
18
+ _appName;
19
+ _algorand;
20
+ _version;
21
+ _defaultSender;
22
+ _defaultSigner;
23
+ _deployTimeParams;
24
+ _updatable;
25
+ _deletable;
26
+ _approvalSourceMap;
27
+ _clearSourceMap;
28
+ _paramsMethods;
29
+ /**
30
+ * Create a new app factory.
31
+ * @param params The parameters to create the app factory
32
+ * @returns The `AppFactory` instance
33
+ * @example
34
+ * ```typescript
35
+ * const appFactory = new AppFactory({
36
+ * appSpec: appSpec,
37
+ * algorand: AlgorandClient.mainNet(),
38
+ * })
39
+ */
40
+ constructor(params) {
41
+ this._appSpec = require_app_client.AppClient.normaliseAppSpec(params.appSpec);
42
+ this._appName = params.appName ?? this._appSpec.name;
43
+ this._algorand = params.algorand;
44
+ this._version = params.version ?? "1.0";
45
+ this._defaultSender = typeof params.defaultSender === "string" ? algosdk.Address.fromString(params.defaultSender) : params.defaultSender;
46
+ this._defaultSigner = params.defaultSigner;
47
+ this._deployTimeParams = params.deployTimeParams;
48
+ this._updatable = params.updatable;
49
+ this._deletable = params.deletable;
50
+ this._paramsMethods = this.getParamsMethods();
51
+ }
52
+ /** The name of the app (from the ARC-32 / ARC-56 app spec or override). */
53
+ get appName() {
54
+ return this._appName;
55
+ }
56
+ /** The ARC-56 app spec being used */
57
+ get appSpec() {
58
+ return this._appSpec;
59
+ }
60
+ /** Return the algorand client this factory is using. */
61
+ get algorand() {
62
+ return this._algorand;
63
+ }
64
+ /** Get parameters to create transactions (create and deploy related calls) for the current app.
65
+ *
66
+ * A good mental model for this is that these parameters represent a deferred transaction creation.
67
+ * @example Create a transaction in the future using Algorand Client
68
+ * ```typescript
69
+ * const createAppParams = appFactory.params.create({method: 'create_method', args: [123, 'hello']})
70
+ * // ...
71
+ * await algorand.send.AppCreateMethodCall(createAppParams)
72
+ * ```
73
+ * @example Define a nested transaction as an ABI argument
74
+ * ```typescript
75
+ * const createAppParams = appFactory.params.create({method: 'create_method', args: [123, 'hello']})
76
+ * await appClient.send.call({method: 'my_method', args: [createAppParams]})
77
+ * ```
78
+ */
79
+ get params() {
80
+ return this._paramsMethods;
81
+ }
82
+ /** Create transactions for the current app */
83
+ createTransaction = {
84
+ /** Create bare (raw) transactions for the current app */
85
+ bare: {
86
+ /**
87
+ * Create a create app call transaction using a bare (raw) create call.
88
+ *
89
+ * Performs deploy-time TEAL template placeholder substitutions (if specified).
90
+ * @param params The parameters to create the create call transaction
91
+ * @returns The create call transaction
92
+ */
93
+ create: async (params) => {
94
+ return this._algorand.createTransaction.appCreate(await this.params.bare.create(params));
95
+ } },
96
+ /**
97
+ * Create a create app call transaction using an ABI create call.
98
+ *
99
+ * Performs deploy-time TEAL template placeholder substitutions (if specified).
100
+ * @param params The parameters to create the create call transaction
101
+ * @returns The create call transaction
102
+ */
103
+ create: async (params) => {
104
+ return this._algorand.createTransaction.appCreateMethodCall(await this.params.create(params));
105
+ }
106
+ };
107
+ /** Send transactions to the current app */
108
+ send = {
109
+ /** Send bare (raw) transactions for the current app */
110
+ bare: {
111
+ /**
112
+ * Creates an instance of the app using a bare (raw) create call and returns the result
113
+ * of the creation transaction and an app client to interact with that app instance.
114
+ *
115
+ * Performs deploy-time TEAL template placeholder substitutions (if specified).
116
+ * @param params The parameters to create the app
117
+ * @returns The app client and the result of the creation transaction
118
+ */
119
+ create: async (params) => {
120
+ const updatable = params?.updatable ?? this._updatable;
121
+ const deletable = params?.deletable ?? this._deletable;
122
+ const deployTimeParams = params?.deployTimeParams ?? this._deployTimeParams;
123
+ const compiled = await this.compile({
124
+ deployTimeParams,
125
+ updatable,
126
+ deletable
127
+ });
128
+ const result = await this.handleCallErrors(async () => ({
129
+ ...await this._algorand.send.appCreate(await this.params.bare.create({
130
+ ...params,
131
+ updatable,
132
+ deletable,
133
+ deployTimeParams
134
+ })),
135
+ return: void 0
136
+ }));
137
+ return {
138
+ appClient: this.getAppClientById({ appId: result.appId }),
139
+ result: {
140
+ ...result,
141
+ ...compiled
142
+ }
143
+ };
144
+ } },
145
+ /**
146
+ * Creates an instance of the app and returns the result of the creation
147
+ * transaction and an app client to interact with that app instance.
148
+ *
149
+ * Performs deploy-time TEAL template placeholder substitutions (if specified).
150
+ * @param params The parameters to create the app
151
+ * @returns The app client and the result of the creation transaction
152
+ */
153
+ create: async (params) => {
154
+ const updatable = params?.updatable ?? this._updatable;
155
+ const deletable = params?.deletable ?? this._deletable;
156
+ const deployTimeParams = params?.deployTimeParams ?? this._deployTimeParams;
157
+ const compiled = await this.compile({
158
+ deployTimeParams,
159
+ updatable,
160
+ deletable
161
+ });
162
+ const result = await this.handleCallErrors(async () => this.parseMethodCallReturn(this._algorand.send.appCreateMethodCall(await this.params.create({
163
+ ...params,
164
+ updatable,
165
+ deletable,
166
+ deployTimeParams
167
+ })), require_app_arc56.getArc56Method(params.method, this._appSpec)));
168
+ return {
169
+ appClient: this.getAppClientById({ appId: result.appId }),
170
+ result: {
171
+ ...result,
172
+ ...compiled
173
+ }
174
+ };
175
+ }
176
+ };
177
+ /**
178
+ * Idempotently deploy (create if not exists, update if changed) an app against the given name for the given creator account, including deploy-time TEAL template placeholder substitutions (if specified).
179
+ *
180
+ * **Note:** When using the return from this function be sure to check `operationPerformed` to get access to various return properties like `transaction`, `confirmation` and `deleteResult`.
181
+ *
182
+ * **Note:** if there is a breaking state schema change to an existing app (and `onSchemaBreak` is set to `'replace'`) the existing app will be deleted and re-created.
183
+ *
184
+ * **Note:** if there is an update (different TEAL code) to an existing app (and `onUpdate` is set to `'replace'`) the existing app will be deleted and re-created.
185
+ * @param params The arguments to control the app deployment
186
+ * @returns The app client and the result of the deployment
187
+ * @example
188
+ * ```ts
189
+ * const { appClient, result } = await factory.deploy({
190
+ * createParams: {
191
+ * sender: 'SENDER_ADDRESS',
192
+ * approvalProgram: 'APPROVAL PROGRAM',
193
+ * clearStateProgram: 'CLEAR PROGRAM',
194
+ * schema: {
195
+ * globalByteSlices: 0,
196
+ * globalInts: 0,
197
+ * localByteSlices: 0,
198
+ * localInts: 0
199
+ * }
200
+ * },
201
+ * updateParams: {
202
+ * sender: 'SENDER_ADDRESS'
203
+ * },
204
+ * deleteParams: {
205
+ * sender: 'SENDER_ADDRESS'
206
+ * },
207
+ * metadata: { name: 'my_app', version: '2.0', updatable: false, deletable: false },
208
+ * onSchemaBreak: 'append',
209
+ * onUpdate: 'append'
210
+ * })
211
+ * ```
212
+ */
213
+ async deploy(params) {
214
+ const updatable = params.updatable ?? this._updatable ?? this.getDeployTimeControl("updatable");
215
+ const deletable = params.deletable ?? this._deletable ?? this.getDeployTimeControl("deletable");
216
+ const deployTimeParams = params.deployTimeParams ?? this._deployTimeParams;
217
+ const compiled = await this.getAppClientById({ appId: 0n }).compile({
218
+ deployTimeParams,
219
+ updatable,
220
+ deletable
221
+ });
222
+ const deployResult = await this._algorand.appDeployer.deploy({
223
+ ...params,
224
+ createParams: await (params.createParams && "method" in params.createParams ? this.params.create({
225
+ ...params.createParams,
226
+ updatable,
227
+ deletable,
228
+ deployTimeParams
229
+ }) : this.params.bare.create({
230
+ ...params.createParams,
231
+ updatable,
232
+ deletable,
233
+ deployTimeParams
234
+ })),
235
+ updateParams: params.updateParams && "method" in params.updateParams ? this.params.deployUpdate(params.updateParams) : this.params.bare.deployUpdate(params.updateParams),
236
+ deleteParams: params.deleteParams && "method" in params.deleteParams ? this.params.deployDelete(params.deleteParams) : this.params.bare.deployDelete(params.deleteParams),
237
+ metadata: {
238
+ name: params.appName ?? this._appName,
239
+ version: this._version,
240
+ updatable,
241
+ deletable
242
+ }
243
+ });
244
+ const appClient = this.getAppClientById({
245
+ appId: deployResult.appId,
246
+ appName: params.appName
247
+ });
248
+ const result = {
249
+ ...deployResult,
250
+ ...compiled
251
+ };
252
+ return {
253
+ appClient,
254
+ result: {
255
+ ...result,
256
+ return: "return" in result ? result.operationPerformed === "update" ? params.updateParams && "method" in params.updateParams ? require_app_arc56.getArc56ReturnValue(result.return, require_app_arc56.getArc56Method(params.updateParams.method, this._appSpec), this._appSpec.structs) : void 0 : params.createParams && "method" in params.createParams ? require_app_arc56.getArc56ReturnValue(result.return, require_app_arc56.getArc56Method(params.createParams.method, this._appSpec), this._appSpec.structs) : void 0 : void 0,
257
+ deleteReturn: "deleteReturn" in result && params.deleteParams && "method" in params.deleteParams ? require_app_arc56.getArc56ReturnValue(result.deleteReturn, require_app_arc56.getArc56Method(params.deleteParams.method, this._appSpec), this._appSpec.structs) : void 0
258
+ }
259
+ };
260
+ }
261
+ /**
262
+ * Returns a new `AppClient` client for an app instance of the given ID.
263
+ *
264
+ * Automatically populates appName, defaultSender and source maps from the factory
265
+ * if not specified in the params.
266
+ * @param params The parameters to create the app client
267
+ * @returns The `AppClient` instance
268
+ * @example
269
+ * ```typescript
270
+ * const appClient = factory.getAppClientById({ appId: 12345n })
271
+ * ```
272
+ */
273
+ getAppClientById(params) {
274
+ return new require_app_client.AppClient({
275
+ ...params,
276
+ algorand: this._algorand,
277
+ appSpec: this._appSpec,
278
+ appName: params.appName ?? this._appName,
279
+ defaultSender: params.defaultSender ?? this._defaultSender,
280
+ defaultSigner: params.defaultSigner ?? this._defaultSigner,
281
+ approvalSourceMap: params.approvalSourceMap ?? this._approvalSourceMap,
282
+ clearSourceMap: params.clearSourceMap ?? this._clearSourceMap
283
+ });
284
+ }
285
+ /**
286
+ * Returns a new `AppClient` client, resolving the app by creator address and name
287
+ * using AlgoKit app deployment semantics (i.e. looking for the app creation transaction note).
288
+ *
289
+ * Automatically populates appName, defaultSender and source maps from the factory
290
+ * if not specified in the params.
291
+ * @param params The parameters to create the app client
292
+ * @returns The `AppClient` instance
293
+ * @example
294
+ * ```typescript
295
+ * const appClient = factory.getAppClientByCreatorAndName({ creatorAddress: 'CREATOR_ADDRESS', appName: 'my_app' })
296
+ * ```
297
+ */
298
+ getAppClientByCreatorAndName(params) {
299
+ return require_app_client.AppClient.fromCreatorAndName({
300
+ ...params,
301
+ algorand: this._algorand,
302
+ appSpec: this._appSpec,
303
+ appName: params.appName ?? this._appName,
304
+ defaultSender: params.defaultSender ?? this._defaultSender,
305
+ approvalSourceMap: params.approvalSourceMap ?? this._approvalSourceMap,
306
+ clearSourceMap: params.clearSourceMap ?? this._clearSourceMap
307
+ });
308
+ }
309
+ /**
310
+ * Takes an error that may include a logic error from a call to the current app and re-exposes the
311
+ * error to include source code information via the source map and ARC-56 spec.
312
+ * @param e The error to parse
313
+ * @param isClearStateProgram Whether or not the code was running the clear state program (defaults to approval program)
314
+ * @returns The new error, or if there was no logic error or source map then the wrapped error with source details
315
+ */
316
+ exposeLogicError(e, isClearStateProgram) {
317
+ return require_app_client.AppClient.exposeLogicError(e, this._appSpec, {
318
+ isClearStateProgram,
319
+ approvalSourceMap: this._approvalSourceMap,
320
+ clearSourceMap: this._clearSourceMap
321
+ });
322
+ }
323
+ /**
324
+ * Export the current source maps for the app.
325
+ * @returns The source maps
326
+ */
327
+ exportSourceMaps() {
328
+ if (!this._approvalSourceMap || !this._clearSourceMap) 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");
329
+ return {
330
+ approvalSourceMap: this._approvalSourceMap,
331
+ clearSourceMap: this._clearSourceMap
332
+ };
333
+ }
334
+ /**
335
+ * Import source maps for the app.
336
+ * @param sourceMaps The source maps to import
337
+ */
338
+ importSourceMaps(sourceMaps) {
339
+ this._approvalSourceMap = new SourceMap(sourceMaps.approvalSourceMap);
340
+ this._clearSourceMap = new SourceMap(sourceMaps.clearSourceMap);
341
+ }
342
+ getDeployTimeControl(control) {
343
+ const approval = this._appSpec.source?.approval ? Buffer.from(this._appSpec.source.approval, "base64").toString("utf-8") : void 0;
344
+ if (!approval || !approval.includes(control === "updatable" ? "TMPL_UPDATABLE" : "TMPL_DELETABLE")) return void 0;
345
+ return this._appSpec.bareActions.call.includes(control === "updatable" ? "UpdateApplication" : "DeleteApplication") || Object.values(this._appSpec.methods).some((c) => c.actions.call.includes(control === "updatable" ? "UpdateApplication" : "DeleteApplication"));
346
+ }
347
+ getParamsMethods() {
348
+ return {
349
+ /** Return params for a create ABI call, including deploy-time TEAL template replacements and compilation if provided */
350
+ create: async (params) => {
351
+ const compiled = await this.compile({
352
+ ...params,
353
+ deployTimeParams: params.deployTimeParams ?? this._deployTimeParams
354
+ });
355
+ return this.getABIParams({
356
+ ...params,
357
+ deployTimeParams: params.deployTimeParams ?? this._deployTimeParams,
358
+ schema: params.schema ?? {
359
+ globalByteSlices: this._appSpec.state.schema.global.bytes,
360
+ globalInts: this._appSpec.state.schema.global.ints,
361
+ localByteSlices: this._appSpec.state.schema.local.bytes,
362
+ localInts: this._appSpec.state.schema.local.ints
363
+ },
364
+ approvalProgram: compiled.approvalProgram,
365
+ clearStateProgram: compiled.clearStateProgram
366
+ }, params.onComplete ?? OnApplicationComplete.NoOpOC);
367
+ },
368
+ /** Return params for a deployment update ABI call */
369
+ deployUpdate: (params) => {
370
+ return this.getABIParams(params, OnApplicationComplete.UpdateApplicationOC);
371
+ },
372
+ /** Return params for a deployment delete ABI call */
373
+ deployDelete: (params) => {
374
+ return this.getABIParams(params, OnApplicationComplete.DeleteApplicationOC);
375
+ },
376
+ bare: {
377
+ /** Return params for a create bare call, including deploy-time TEAL template replacements and compilation if provided */
378
+ create: async (params) => {
379
+ return this.getBareParams({
380
+ ...params,
381
+ deployTimeParams: params?.deployTimeParams ?? this._deployTimeParams,
382
+ schema: params?.schema ?? {
383
+ globalByteSlices: this._appSpec.state.schema.global.bytes,
384
+ globalInts: this._appSpec.state.schema.global.ints,
385
+ localByteSlices: this._appSpec.state.schema.local.bytes,
386
+ localInts: this._appSpec.state.schema.local.ints
387
+ },
388
+ ...await this.compile({
389
+ ...params,
390
+ deployTimeParams: params?.deployTimeParams ?? this._deployTimeParams
391
+ })
392
+ }, params?.onComplete ?? OnApplicationComplete.NoOpOC);
393
+ },
394
+ /** Return params for a deployment update bare call */
395
+ deployUpdate: (params) => {
396
+ return this.getBareParams(params, OnApplicationComplete.UpdateApplicationOC);
397
+ },
398
+ /** Return params for a deployment delete bare call */
399
+ deployDelete: (params) => {
400
+ return this.getBareParams(params, OnApplicationComplete.DeleteApplicationOC);
401
+ }
402
+ }
403
+ };
404
+ }
405
+ /** Make the given call and catch any errors, augmenting with debugging information before re-throwing. */
406
+ async handleCallErrors(call) {
407
+ try {
408
+ return await call();
409
+ } catch (e) {
410
+ throw this.exposeLogicError(e);
411
+ }
412
+ }
413
+ /**
414
+ * Compiles the approval and clear state programs (if TEAL templates provided),
415
+ * performing any provided deploy-time parameter replacement and stores
416
+ * the source maps.
417
+ *
418
+ * If no TEAL templates provided it will use any byte code provided in the app spec.
419
+ *
420
+ * Will store any generated source maps for later use in debugging.
421
+ * @param compilation Optional compilation parameters to use for the compilation
422
+ * @returns The compilation result
423
+ * @example
424
+ * ```typescript
425
+ * const result = await factory.compile()
426
+ * ```
427
+ */
428
+ async compile(compilation) {
429
+ const result = await require_app_client.AppClient.compile(this._appSpec, this._algorand.app, compilation);
430
+ if (result.compiledApproval) this._approvalSourceMap = result.compiledApproval.sourceMap;
431
+ if (result.compiledClear) this._clearSourceMap = result.compiledClear.sourceMap;
432
+ return result;
433
+ }
434
+ getBareParams(params, onComplete) {
435
+ return {
436
+ ...params,
437
+ sender: this.getSender(params?.sender),
438
+ signer: this.getSigner(params?.sender, params?.signer),
439
+ onComplete
440
+ };
441
+ }
442
+ getABIParams(params, onComplete) {
443
+ return {
444
+ ...params,
445
+ sender: this.getSender(params.sender),
446
+ signer: this.getSigner(params.sender, params.signer),
447
+ method: require_app_arc56.getArc56Method(params.method, this._appSpec),
448
+ args: this.getCreateABIArgsWithDefaultValues(params.method, params.args),
449
+ onComplete
450
+ };
451
+ }
452
+ getCreateABIArgsWithDefaultValues(methodNameOrSignature, args) {
453
+ const m = require_app_arc56.getArc56Method(methodNameOrSignature, this._appSpec);
454
+ return args?.map((a, i) => {
455
+ const arg = m.args[i];
456
+ if (a !== void 0) return arg.struct && typeof a === "object" && !Array.isArray(a) ? require_app_arc56.getABITupleFromABIStruct(a, this._appSpec.structs[arg.struct], this._appSpec.structs) : a;
457
+ const defaultValue = arg.defaultValue;
458
+ if (defaultValue) switch (defaultValue.source) {
459
+ case "literal": return require_app_arc56.getABIDecodedValue(Buffer.from(defaultValue.data, "base64"), m.method.args[i].type, this._appSpec.structs);
460
+ default: throw new Error(`Can't provide default value for ${defaultValue.source} for a contract creation call`);
461
+ }
462
+ throw new Error(`No value provided for required argument ${arg.name ?? `arg${i + 1}`} in call to method ${m.name}`);
463
+ });
464
+ }
465
+ /** Returns the sender for a call, using the `defaultSender`
466
+ * if none provided and throws an error if neither provided */
467
+ getSender(sender) {
468
+ if (!sender && !this._defaultSender) throw new Error(`No sender provided and no default sender present in app factory for call to app ${this._appName}`);
469
+ return typeof sender === "string" ? algosdk.Address.fromString(sender) : sender ?? this._defaultSender;
470
+ }
471
+ /** Returns the signer for a call, using the provided signer or the `defaultSigner`
472
+ * if no signer was provided and the sender resolves to the default sender, the call will use default signer
473
+ * or `undefined` otherwise (so the signer is resolved from `AlgorandClient`) */
474
+ getSigner(sender, signer) {
475
+ return signer ?? (!sender || sender === this._defaultSender ? this._defaultSigner : void 0);
476
+ }
477
+ /**
478
+ * Checks for decode errors on the SendAppTransactionResult and maps the return value to the specified type
479
+ * on the ARC-56 method.
480
+ *
481
+ * If the return type is a struct then the struct will be returned.
482
+ *
483
+ * @param result The SendAppTransactionResult to be mapped
484
+ * @param method The method that was called
485
+ * @returns The smart contract response with an updated return value
486
+ */
487
+ async parseMethodCallReturn(result, method) {
488
+ const resultValue = await result;
489
+ return {
490
+ ...resultValue,
491
+ return: require_app_arc56.getArc56ReturnValue(resultValue.return, method, this._appSpec.structs)
492
+ };
493
+ }
494
+ };
495
+ //#endregion
489
496
  exports.AppFactory = AppFactory;
490
- //# sourceMappingURL=app-factory.js.map
497
+
498
+ //# sourceMappingURL=app-factory.js.map