@algorandfoundation/algokit-utils 10.0.0-alpha.31 → 10.0.0-alpha.32

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 (318) hide show
  1. package/account-manager.d.ts +448 -0
  2. package/account-manager.js +623 -0
  3. package/account-manager.js.map +1 -0
  4. package/account-manager.mjs +620 -0
  5. package/account-manager.mjs.map +1 -0
  6. package/account.d.ts +156 -0
  7. package/account.js +10 -0
  8. package/account.js.map +1 -0
  9. package/account.mjs +9 -0
  10. package/account.mjs.map +1 -0
  11. package/algorand-client-transaction-creator.d.ts +1103 -0
  12. package/algorand-client-transaction-creator.js +735 -0
  13. package/algorand-client-transaction-creator.js.map +1 -0
  14. package/algorand-client-transaction-creator.mjs +734 -0
  15. package/algorand-client-transaction-creator.mjs.map +1 -0
  16. package/algorand-client-transaction-sender.d.ts +1317 -0
  17. package/algorand-client-transaction-sender.js +933 -0
  18. package/algorand-client-transaction-sender.js.map +1 -0
  19. package/algorand-client-transaction-sender.mjs +932 -0
  20. package/algorand-client-transaction-sender.mjs.map +1 -0
  21. package/algorand-client.d.ts +246 -0
  22. package/algorand-client.js +325 -0
  23. package/algorand-client.js.map +1 -0
  24. package/algorand-client.mjs +325 -0
  25. package/algorand-client.mjs.map +1 -0
  26. package/amount.d.ts +46 -3
  27. package/amount.js +92 -13
  28. package/amount.js.map +1 -1
  29. package/amount.mjs +80 -3
  30. package/amount.mjs.map +1 -1
  31. package/app-client.d.ts +2130 -0
  32. package/app-client.js +909 -0
  33. package/app-client.js.map +1 -0
  34. package/app-client.mjs +908 -0
  35. package/app-client.mjs.map +1 -0
  36. package/app-deployer.d.ts +166 -0
  37. package/app-deployer.js +353 -0
  38. package/app-deployer.js.map +1 -0
  39. package/app-deployer.mjs +353 -0
  40. package/app-deployer.mjs.map +1 -0
  41. package/app-factory.d.ts +965 -0
  42. package/app-factory.js +448 -0
  43. package/app-factory.js.map +1 -0
  44. package/app-factory.mjs +448 -0
  45. package/app-factory.mjs.map +1 -0
  46. package/app-manager.d.ts +323 -0
  47. package/app-manager.js +468 -0
  48. package/app-manager.js.map +1 -0
  49. package/app-manager.mjs +468 -0
  50. package/app-manager.mjs.map +1 -0
  51. package/app-spec.d.ts +203 -0
  52. package/app-spec.js +137 -0
  53. package/app-spec.js.map +1 -0
  54. package/app-spec.mjs +137 -0
  55. package/app-spec.mjs.map +1 -0
  56. package/app.d.ts +257 -0
  57. package/app.js +49 -0
  58. package/app.js.map +1 -0
  59. package/app.mjs +42 -0
  60. package/app.mjs.map +1 -0
  61. package/asset-manager.d.ts +212 -0
  62. package/asset-manager.js +166 -0
  63. package/asset-manager.js.map +1 -0
  64. package/asset-manager.mjs +166 -0
  65. package/asset-manager.mjs.map +1 -0
  66. package/async-event-emitter.d.ts +16 -0
  67. package/async-event-emitter.js +38 -0
  68. package/async-event-emitter.js.map +1 -0
  69. package/async-event-emitter.mjs +37 -0
  70. package/async-event-emitter.mjs.map +1 -0
  71. package/client-manager.d.ts +475 -0
  72. package/client-manager.js +616 -0
  73. package/client-manager.js.map +1 -0
  74. package/client-manager.mjs +616 -0
  75. package/client-manager.mjs.map +1 -0
  76. package/composer.d.ts +947 -0
  77. package/composer.js +1584 -0
  78. package/composer.js.map +1 -0
  79. package/composer.mjs +1583 -0
  80. package/composer.mjs.map +1 -0
  81. package/config.d.ts +1 -1
  82. package/config.js +2 -2
  83. package/config.js.map +1 -1
  84. package/config.mjs +1 -1
  85. package/config.mjs.map +1 -1
  86. package/debugging.d.ts +47 -0
  87. package/debugging.js +20 -0
  88. package/debugging.js.map +1 -0
  89. package/debugging.mjs +15 -0
  90. package/debugging.mjs.map +1 -0
  91. package/dispenser-client.d.ts +90 -0
  92. package/dispenser-client.js +127 -0
  93. package/dispenser-client.js.map +1 -0
  94. package/dispenser-client.mjs +127 -0
  95. package/dispenser-client.mjs.map +1 -0
  96. package/expand.d.ts +2 -0
  97. package/expand.js +0 -0
  98. package/expand.mjs +0 -0
  99. package/index.d.ts +6 -5
  100. package/index.js +4 -3
  101. package/index.mjs +5 -5
  102. package/indexer-client/indexer-lookup.d.ts +1 -1
  103. package/indexer-client/indexer-lookup.js.map +1 -1
  104. package/indexer-client/indexer-lookup.mjs.map +1 -1
  105. package/indexer.d.ts +40 -0
  106. package/indexer.js +38 -0
  107. package/indexer.js.map +1 -0
  108. package/indexer.mjs +35 -0
  109. package/indexer.mjs.map +1 -0
  110. package/instance-of.d.ts +8 -0
  111. package/kmd-account-manager.d.ts +74 -0
  112. package/kmd-account-manager.js +167 -0
  113. package/kmd-account-manager.js.map +1 -0
  114. package/kmd-account-manager.mjs +165 -0
  115. package/kmd-account-manager.mjs.map +1 -0
  116. package/lifecycle-events.d.ts +14 -0
  117. package/lifecycle-events.js +11 -0
  118. package/lifecycle-events.js.map +1 -0
  119. package/lifecycle-events.mjs +10 -0
  120. package/lifecycle-events.mjs.map +1 -0
  121. package/logging.d.ts +13 -0
  122. package/logging.js +47 -0
  123. package/logging.js.map +1 -0
  124. package/logging.mjs +42 -0
  125. package/logging.mjs.map +1 -0
  126. package/logic-error.d.ts +39 -0
  127. package/logic-error.js +54 -0
  128. package/logic-error.js.map +1 -0
  129. package/logic-error.mjs +53 -0
  130. package/logic-error.mjs.map +1 -0
  131. package/network-client.d.ts +43 -0
  132. package/network-client.js +14 -0
  133. package/network-client.js.map +1 -0
  134. package/network-client.mjs +13 -0
  135. package/network-client.mjs.map +1 -0
  136. package/package.json +11 -1
  137. package/testing/account.d.ts +2 -2
  138. package/testing/account.js +1 -1
  139. package/testing/account.js.map +1 -1
  140. package/testing/account.mjs +1 -1
  141. package/testing/account.mjs.map +1 -1
  142. package/testing/fixtures/algokit-log-capture-fixture.d.ts +1 -1
  143. package/testing/fixtures/algokit-log-capture-fixture.js.map +1 -1
  144. package/testing/fixtures/algokit-log-capture-fixture.mjs.map +1 -1
  145. package/testing/fixtures/algorand-fixture.d.ts +2 -2
  146. package/testing/fixtures/algorand-fixture.js +2 -2
  147. package/testing/fixtures/algorand-fixture.js.map +1 -1
  148. package/testing/fixtures/algorand-fixture.mjs +2 -2
  149. package/testing/fixtures/algorand-fixture.mjs.map +1 -1
  150. package/testing/index.d.ts +2 -1
  151. package/testing/test-logger.d.ts +1 -1
  152. package/testing/test-logger.js.map +1 -1
  153. package/testing/test-logger.mjs.map +1 -1
  154. package/testing/types.d.ts +156 -0
  155. package/transaction/index.d.ts +4 -0
  156. package/transaction/index.js +9 -0
  157. package/transaction/index.mjs +4 -0
  158. package/transaction/perform-transaction-composer-simulate.d.ts +1 -1
  159. package/transaction/perform-transaction-composer-simulate.js.map +1 -1
  160. package/transaction/perform-transaction-composer-simulate.mjs.map +1 -1
  161. package/transaction/transaction.d.ts +2 -2
  162. package/transaction/transaction.js.map +1 -1
  163. package/transaction/transaction.mjs.map +1 -1
  164. package/transaction/types.d.ts +133 -0
  165. package/transactions/app-call.d.ts +1 -1
  166. package/transactions/app-call.js +1 -1
  167. package/transactions/app-call.js.map +1 -1
  168. package/transactions/app-call.mjs +1 -1
  169. package/transactions/app-call.mjs.map +1 -1
  170. package/transactions/common.d.ts +1 -1
  171. package/transactions/common.js.map +1 -1
  172. package/transactions/common.mjs.map +1 -1
  173. package/transactions/method-call.d.ts +1 -1
  174. package/transactions/method-call.js +1 -1
  175. package/transactions/method-call.js.map +1 -1
  176. package/transactions/method-call.mjs +1 -1
  177. package/transactions/method-call.mjs.map +1 -1
  178. package/transactions/payment.d.ts +1 -1
  179. package/transactions/payment.js.map +1 -1
  180. package/transactions/payment.mjs.map +1 -1
  181. package/types/account-manager.d.ts +11 -442
  182. package/types/account-manager.js +5 -616
  183. package/types/account-manager.js.map +1 -1
  184. package/types/account-manager.mjs +5 -614
  185. package/types/account-manager.mjs.map +1 -1
  186. package/types/account.d.ts +8 -150
  187. package/types/account.js +3 -4
  188. package/types/account.js.map +1 -1
  189. package/types/account.mjs +4 -4
  190. package/types/account.mjs.map +1 -1
  191. package/types/algorand-client-transaction-creator.d.ts +5 -1098
  192. package/types/algorand-client-transaction-creator.js +3 -729
  193. package/types/algorand-client-transaction-creator.js.map +1 -1
  194. package/types/algorand-client-transaction-creator.mjs +4 -729
  195. package/types/algorand-client-transaction-creator.mjs.map +1 -1
  196. package/types/algorand-client-transaction-sender.d.ts +5 -1312
  197. package/types/algorand-client-transaction-sender.js +3 -927
  198. package/types/algorand-client-transaction-sender.js.map +1 -1
  199. package/types/algorand-client-transaction-sender.mjs +3 -926
  200. package/types/algorand-client-transaction-sender.mjs.map +1 -1
  201. package/types/algorand-client.d.ts +5 -241
  202. package/types/algorand-client.js +3 -319
  203. package/types/algorand-client.js.map +1 -1
  204. package/types/algorand-client.mjs +3 -319
  205. package/types/algorand-client.mjs.map +1 -1
  206. package/types/amount.d.ts +6 -45
  207. package/types/amount.js +3 -79
  208. package/types/amount.js.map +1 -1
  209. package/types/amount.mjs +4 -79
  210. package/types/amount.mjs.map +1 -1
  211. package/types/app-client.d.ts +75 -2125
  212. package/types/app-client.js +3 -903
  213. package/types/app-client.js.map +1 -1
  214. package/types/app-client.mjs +3 -902
  215. package/types/app-client.mjs.map +1 -1
  216. package/types/app-deployer.d.ts +21 -161
  217. package/types/app-deployer.js +3 -347
  218. package/types/app-deployer.js.map +1 -1
  219. package/types/app-deployer.mjs +3 -347
  220. package/types/app-deployer.mjs.map +1 -1
  221. package/types/app-factory.d.ts +21 -960
  222. package/types/app-factory.js +3 -442
  223. package/types/app-factory.js.map +1 -1
  224. package/types/app-factory.mjs +3 -442
  225. package/types/app-factory.mjs.map +1 -1
  226. package/types/app-manager.d.ts +15 -318
  227. package/types/app-manager.js +3 -462
  228. package/types/app-manager.js.map +1 -1
  229. package/types/app-manager.mjs +3 -462
  230. package/types/app-manager.mjs.map +1 -1
  231. package/types/app-spec.d.ts +39 -198
  232. package/types/app-spec.js +3 -131
  233. package/types/app-spec.js.map +1 -1
  234. package/types/app-spec.mjs +3 -131
  235. package/types/app-spec.mjs.map +1 -1
  236. package/types/app.d.ts +62 -247
  237. package/types/app.js +15 -37
  238. package/types/app.js.map +1 -1
  239. package/types/app.mjs +16 -37
  240. package/types/app.mjs.map +1 -1
  241. package/types/asset-manager.d.ts +9 -207
  242. package/types/asset-manager.js +3 -160
  243. package/types/asset-manager.js.map +1 -1
  244. package/types/asset-manager.mjs +3 -160
  245. package/types/asset-manager.mjs.map +1 -1
  246. package/types/async-event-emitter.d.ts +7 -11
  247. package/types/async-event-emitter.js +3 -32
  248. package/types/async-event-emitter.js.map +1 -1
  249. package/types/async-event-emitter.mjs +4 -32
  250. package/types/async-event-emitter.mjs.map +1 -1
  251. package/types/client-manager.d.ts +27 -470
  252. package/types/client-manager.js +3 -610
  253. package/types/client-manager.js.map +1 -1
  254. package/types/client-manager.mjs +3 -610
  255. package/types/client-manager.mjs.map +1 -1
  256. package/types/composer.d.ts +79 -943
  257. package/types/composer.js +3 -1578
  258. package/types/composer.js.map +1 -1
  259. package/types/composer.mjs +3 -1577
  260. package/types/composer.mjs.map +1 -1
  261. package/types/config.d.ts +7 -52
  262. package/types/config.js +3 -74
  263. package/types/config.js.map +1 -1
  264. package/types/config.mjs +3 -74
  265. package/types/config.mjs.map +1 -1
  266. package/types/debugging.d.ts +12 -37
  267. package/types/debugging.js +11 -10
  268. package/types/debugging.js.map +1 -1
  269. package/types/debugging.mjs +12 -10
  270. package/types/debugging.mjs.map +1 -1
  271. package/types/dispenser-client.d.ts +11 -85
  272. package/types/dispenser-client.js +3 -121
  273. package/types/dispenser-client.js.map +1 -1
  274. package/types/dispenser-client.mjs +3 -121
  275. package/types/dispenser-client.mjs.map +1 -1
  276. package/types/expand.d.ts +8 -2
  277. package/types/indexer.d.ts +16 -36
  278. package/types/indexer.js +7 -30
  279. package/types/indexer.js.map +1 -1
  280. package/types/indexer.mjs +8 -30
  281. package/types/indexer.mjs.map +1 -1
  282. package/types/instance-of.d.ts +4 -4
  283. package/types/kmd-account-manager.d.ts +5 -69
  284. package/types/kmd-account-manager.js +3 -161
  285. package/types/kmd-account-manager.js.map +1 -1
  286. package/types/kmd-account-manager.mjs +3 -159
  287. package/types/kmd-account-manager.mjs.map +1 -1
  288. package/types/lifecycle-events.d.ts +7 -9
  289. package/types/lifecycle-events.js +3 -5
  290. package/types/lifecycle-events.js.map +1 -1
  291. package/types/lifecycle-events.mjs +4 -5
  292. package/types/lifecycle-events.mjs.map +1 -1
  293. package/types/logging.d.ts +14 -9
  294. package/types/logging.js +11 -37
  295. package/types/logging.js.map +1 -1
  296. package/types/logging.mjs +12 -37
  297. package/types/logging.mjs.map +1 -1
  298. package/types/logic-error.d.ts +8 -35
  299. package/types/logic-error.js +3 -48
  300. package/types/logic-error.js.map +1 -1
  301. package/types/logic-error.mjs +4 -48
  302. package/types/logic-error.mjs.map +1 -1
  303. package/types/network-client.d.ts +10 -39
  304. package/types/network-client.js +3 -8
  305. package/types/network-client.js.map +1 -1
  306. package/types/network-client.mjs +4 -8
  307. package/types/network-client.mjs.map +1 -1
  308. package/types/testing.d.ts +13 -151
  309. package/types/transaction.d.ts +33 -128
  310. package/updatable-config.d.ts +57 -0
  311. package/updatable-config.js +80 -0
  312. package/updatable-config.js.map +1 -0
  313. package/updatable-config.mjs +80 -0
  314. package/updatable-config.mjs.map +1 -0
  315. package/util.js +1 -1
  316. package/util.js.map +1 -1
  317. package/util.mjs +1 -1
  318. package/util.mjs.map +1 -1
@@ -1,908 +1,8 @@
1
- const require_rolldown_runtime = require('../_virtual/rolldown_runtime.js');
2
- const require_address = require('../packages/common/src/address.js');
3
- const require_config = require('../config.js');
4
- const require_util = require('../util.js');
5
- const require_sourcemap = require('../packages/common/src/sourcemap.js');
6
- const require_app_call = require('../packages/transact/src/transactions/app-call.js');
7
- const require_abi_method = require('../packages/abi/src/abi-method.js');
8
- const require_arc56_contract = require('../packages/abi/src/arc56-contract.js');
9
- const require_lifecycle_events = require('./lifecycle-events.js');
10
- const require_app_spec = require('./app-spec.js');
11
- const require_logic_error = require('./logic-error.js');
12
- let buffer = require("buffer");
1
+ const require_app_client = require('../app-client.js');
13
2
 
14
3
  //#region src/types/app-client.ts
15
- /** The maximum opcode budget for a simulate call as per https://github.com/algorand/go-algorand/blob/807b29a91c371d225e12b9287c5d56e9b33c4e4c/ledger/simulation/trace.go#L104 */
16
- const MAX_SIMULATE_OPCODE_BUDGET = 2e4 * 16;
17
- const BYTE_CBLOCK = 38;
18
- const INT_CBLOCK = 32;
19
- /**
20
- * Get the offset of the last constant block at the beginning of the program
21
- * This value is used to calculate the program counter for an ARC56 program that has a pcOffsetMethod of "cblocks"
22
- *
23
- * @param program The program to parse
24
- * @returns The PC value of the opcode after the last constant block
25
- */
26
- function getConstantBlockOffset(program) {
27
- const bytes = [...program];
28
- const programSize = bytes.length;
29
- bytes.shift();
30
- /** The PC of the opcode after the bytecblock */
31
- let bytecblockOffset;
32
- /** The PC of the opcode after the intcblock */
33
- let intcblockOffset;
34
- while (bytes.length > 0) {
35
- /** The current byte from the beginning of the byte array */
36
- const byte = bytes.shift();
37
- if (byte === BYTE_CBLOCK || byte === INT_CBLOCK) {
38
- const isBytecblock = byte === BYTE_CBLOCK;
39
- /** The byte following the opcode is the number of values in the constant block */
40
- const valuesRemaining = bytes.shift();
41
- for (let i = 0; i < valuesRemaining; i++) if (isBytecblock) {
42
- /** The byte following the opcode is the length of the next element */
43
- const length = bytes.shift();
44
- bytes.splice(0, length);
45
- } else while ((bytes.shift() & 128) !== 0);
46
- if (isBytecblock) bytecblockOffset = programSize - bytes.length - 1;
47
- else intcblockOffset = programSize - bytes.length - 1;
48
- if (bytes[0] !== BYTE_CBLOCK && bytes[0] !== INT_CBLOCK) break;
49
- }
50
- }
51
- return Math.max(bytecblockOffset ?? 0, intcblockOffset ?? 0);
52
- }
53
- /** ARC-56/ARC-32 application client that allows you to manage calls and
54
- * state for a specific deployed instance of an app (with a known app ID). */
55
- var AppClient = class AppClient {
56
- _appId;
57
- _appAddress;
58
- _appName;
59
- _appSpec;
60
- _algorand;
61
- _defaultSender;
62
- _defaultSigner;
63
- _approvalSourceMap;
64
- _clearSourceMap;
65
- _localStateMethods;
66
- _globalStateMethods;
67
- _boxStateMethods;
68
- _paramsMethods;
69
- _createTransactionsMethods;
70
- _sendMethods;
71
- _lastCompiled;
72
- /**
73
- * Create a new app client.
74
- * @param params The parameters to create the app client
75
- * @returns The `AppClient` instance
76
- * @example
77
- * ```typescript
78
- * const appClient = new AppClient({
79
- * appId: 12345678n,
80
- * appSpec: appSpec,
81
- * algorand: AlgorandClient.mainNet(),
82
- * })
83
- */
84
- constructor(params) {
85
- this._appId = params.appId;
86
- this._appAddress = require_address.getApplicationAddress(this._appId);
87
- this._appSpec = AppClient.normaliseAppSpec(params.appSpec);
88
- this._appName = params.appName ?? this._appSpec.name;
89
- this._algorand = params.algorand;
90
- this._algorand.registerErrorTransformer(this.handleCallErrors);
91
- this._defaultSender = require_address.getOptionalAddress(params.defaultSender);
92
- this._defaultSigner = params.defaultSigner;
93
- this._lastCompiled = {};
94
- this._approvalSourceMap = params.approvalSourceMap;
95
- this._clearSourceMap = params.clearSourceMap;
96
- this._localStateMethods = (address) => this.getStateMethods(() => this.getLocalState(address), () => require_arc56_contract.getLocalABIStorageKeys(this._appSpec), () => require_arc56_contract.getLocalABIStorageMaps(this._appSpec));
97
- this._globalStateMethods = this.getStateMethods(() => this.getGlobalState(), () => require_arc56_contract.getGlobalABIStorageKeys(this._appSpec), () => require_arc56_contract.getGlobalABIStorageMaps(this._appSpec));
98
- this._boxStateMethods = this.getBoxMethods();
99
- this._paramsMethods = {
100
- ...this.getMethodCallParamsMethods(),
101
- bare: this.getBareParamsMethods()
102
- };
103
- this._createTransactionsMethods = {
104
- ...this.getMethodCallCreateTransactionMethods(),
105
- bare: this.getBareCreateTransactionMethods()
106
- };
107
- this._sendMethods = {
108
- ...this.getMethodCallSendMethods(),
109
- bare: this.getBareSendMethods()
110
- };
111
- }
112
- /**
113
- * Clone this app client with different params
114
- *
115
- * @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.
116
- * @returns A new app client with the altered params
117
- * @example
118
- * ```typescript
119
- * const appClient2 = appClient.clone({ defaultSender: 'NEW_SENDER_ADDRESS' })
120
- * ```
121
- */
122
- clone(params) {
123
- return new AppClient({
124
- appId: this._appId,
125
- appSpec: this._appSpec,
126
- algorand: this._algorand,
127
- appName: this._appName,
128
- defaultSender: this._defaultSender,
129
- defaultSigner: this._defaultSigner,
130
- approvalSourceMap: this._approvalSourceMap,
131
- clearSourceMap: this._clearSourceMap,
132
- ...params
133
- });
134
- }
135
- /**
136
- * Returns a new `AppClient` client, resolving the app by creator address and name
137
- * using AlgoKit app deployment semantics (i.e. looking for the app creation transaction note).
138
- * @param params The parameters to create the app client
139
- * @returns The `AppClient` instance
140
- * @example
141
- * ```typescript
142
- * const appClient = await AppClient.fromCreatorAndName({
143
- * creatorAddress: 'CREATOR_ADDRESS',
144
- * name: 'APP_NAME',
145
- * appSpec: appSpec,
146
- * algorand: AlgorandClient.mainNet(),
147
- * })
148
- */
149
- static async fromCreatorAndName(params) {
150
- const appSpec = AppClient.normaliseAppSpec(params.appSpec);
151
- const appMetadata = (params.appLookupCache ?? await params.algorand.appDeployer.getCreatorAppsByName(params.creatorAddress, params.ignoreCache)).apps[params.appName ?? appSpec.name];
152
- if (!appMetadata) throw new Error(`App not found for creator ${params.creatorAddress} and name ${params.appName ?? appSpec.name}`);
153
- return new AppClient({
154
- ...params,
155
- algorand: params.algorand,
156
- appId: appMetadata.appId
157
- });
158
- }
159
- /**
160
- * Returns an `AppClient` instance for the current network based on
161
- * pre-determined network-specific app IDs specified in the ARC-56 app spec.
162
- *
163
- * If no IDs are in the app spec or the network isn't recognised, an error is thrown.
164
- * @param params The parameters to create the app client
165
- * @returns The `AppClient` instance
166
- * @example
167
- * ```typescript
168
- * const appClient = await AppClient.fromNetwork({
169
- * appSpec: appSpec,
170
- * algorand: AlgorandClient.mainNet(),
171
- * })
172
- */
173
- static async fromNetwork(params) {
174
- const network = await params.algorand.client.network();
175
- const appSpec = AppClient.normaliseAppSpec(params.appSpec);
176
- const networkNames = [network.genesisHash];
177
- if (network.isLocalNet) networkNames.push("localnet");
178
- if (network.isTestNet) networkNames.push("testnet");
179
- if (network.isMainNet) networkNames.push("mainnet");
180
- const networkIndex = Object.keys(appSpec.networks ?? {}).findIndex((n) => networkNames.includes(n));
181
- if (networkIndex === -1) throw new Error(`No app ID found for network ${require_util.asJson(networkNames)} in the app spec`);
182
- const appId = BigInt(appSpec.networks[networkIndex].appID);
183
- return new AppClient({
184
- ...params,
185
- appId,
186
- appSpec
187
- });
188
- }
189
- /**
190
- * Takes a string or parsed JSON object that could be ARC-32 or ARC-56 format and
191
- * normalises it into a parsed ARC-56 contract object.
192
- * @param spec The spec to normalise
193
- * @returns The normalised ARC-56 contract object
194
- * @example
195
- * ```typescript
196
- * const arc56AppSpec = AppClient.normaliseAppSpec(appSpec)
197
- * ```
198
- */
199
- static normaliseAppSpec(spec) {
200
- const parsedSpec = typeof spec === "string" ? JSON.parse(spec) : spec;
201
- return "hints" in parsedSpec ? require_app_spec.arc32ToArc56(parsedSpec) : parsedSpec;
202
- }
203
- /** The ID of the app instance this client is linked to. */
204
- get appId() {
205
- return this._appId;
206
- }
207
- /** The app address of the app instance this client is linked to. */
208
- get appAddress() {
209
- return this._appAddress;
210
- }
211
- /** The name of the app (from the ARC-32 / ARC-56 app spec or override). */
212
- get appName() {
213
- return this._appName;
214
- }
215
- /** The ARC-56 app spec being used */
216
- get appSpec() {
217
- return this._appSpec;
218
- }
219
- /** A reference to the underlying `AlgorandClient` this app client is using. */
220
- get algorand() {
221
- return this._algorand;
222
- }
223
- /** Get parameters to create transactions for the current app.
224
- *
225
- * A good mental model for this is that these parameters represent a deferred transaction creation.
226
- * @example Create a transaction in the future using Algorand Client
227
- * ```typescript
228
- * const myMethodCall = appClient.params.call({method: 'my_method', args: [123, 'hello']})
229
- * // ...
230
- * await algorand.send.AppMethodCall(myMethodCall)
231
- * ```
232
- * @example Define a nested transaction as an ABI argument
233
- * ```typescript
234
- * const myMethodCall = appClient.params.call({method: 'my_method', args: [123, 'hello']})
235
- * await appClient.send.call({method: 'my_method2', args: [myMethodCall]})
236
- * ```
237
- */
238
- get params() {
239
- return this._paramsMethods;
240
- }
241
- /** Create transactions for the current app */
242
- get createTransaction() {
243
- return this._createTransactionsMethods;
244
- }
245
- /** Send transactions to the current app */
246
- get send() {
247
- return this._sendMethods;
248
- }
249
- /** Get state (local, global, box) from the current app */
250
- get state() {
251
- return {
252
- local: this._localStateMethods,
253
- global: this._globalStateMethods,
254
- box: this._boxStateMethods
255
- };
256
- }
257
- /**
258
- * Funds Algo into the app account for this app.
259
- *
260
- * An alias for `appClient.send.fundAppAccount(params)`.
261
- * @param params The parameters for the funding transaction
262
- * @returns The result of the funding
263
- * @example
264
- * ```typescript
265
- * await appClient.fundAppAccount({ amount: algo(1) })
266
- * ```
267
- */
268
- async fundAppAccount(params) {
269
- return this.send.fundAppAccount(params);
270
- }
271
- /**
272
- * Returns raw global state for the current app.
273
- * @returns The global state
274
- * @example
275
- * ```typescript
276
- * const globalState = await appClient.getGlobalState()
277
- * ```
278
- */
279
- async getGlobalState() {
280
- return await this._algorand.app.getGlobalState(this.appId);
281
- }
282
- /**
283
- * Returns raw local state for the given account address.
284
- * @param address The address of the account to get the local state for
285
- * @returns The local state
286
- * @example
287
- * ```typescript
288
- * const localState = await appClient.getLocalState('ACCOUNT_ADDRESS')
289
- * ```
290
- */
291
- async getLocalState(address) {
292
- return await this._algorand.app.getLocalState(this.appId, require_address.getAddress(address));
293
- }
294
- /**
295
- * Returns the names of all current boxes for the current app.
296
- * @returns The names of the boxes
297
- * @example
298
- * ```typescript
299
- * const boxNames = await appClient.getBoxNames()
300
- * ```
301
- */
302
- async getBoxNames() {
303
- return await this._algorand.app.getBoxNames(this.appId);
304
- }
305
- /**
306
- * Returns the value of the given box for the current app.
307
- * @param name The identifier of the box to return
308
- * @returns The current box value as a byte array
309
- * @example
310
- * ```typescript
311
- * const boxValue = await appClient.getBoxValue('boxName')
312
- * ```
313
- */
314
- async getBoxValue(name) {
315
- return await this._algorand.app.getBoxValue(this.appId, name);
316
- }
317
- /**
318
- * Returns the value of the given box for the current app.
319
- * @param name The identifier of the box to return
320
- * @param type
321
- * @returns The current box value as a byte array
322
- * @example
323
- * ```typescript
324
- * const boxValue = await appClient.getBoxValueFromABIType('boxName', new ABIUintType(32))
325
- * ```
326
- */
327
- async getBoxValueFromABIType(name, type) {
328
- return await this._algorand.app.getBoxValueFromABIType({
329
- appId: this.appId,
330
- boxName: name,
331
- type
332
- });
333
- }
334
- /**
335
- * Returns the values of all current boxes for the current app.
336
- * Note: This will issue multiple HTTP requests (one per box) and it's not an atomic operation so values may be out of sync.
337
- * @param filter Optional filter to filter which boxes' values are returned
338
- * @returns The (name, value) pair of the boxes with values as raw byte arrays
339
- * @example
340
- * ```typescript
341
- * const boxValues = await appClient.getBoxValues()
342
- * ```
343
- */
344
- async getBoxValues(filter) {
345
- const names = (await this.getBoxNames()).filter(filter ?? ((_) => true));
346
- const values = await this._algorand.app.getBoxValues(this.appId, names.map((name) => name.nameRaw));
347
- return names.map((name, i) => ({
348
- name,
349
- value: values[i]
350
- }));
351
- }
352
- /**
353
- * Returns the values of all current boxes for the current app decoded using an ABI Type.
354
- * Note: This will issue multiple HTTP requests (one per box) and it's not an atomic operation so values may be out of sync.
355
- * @param type The ABI type to decode the values with
356
- * @param filter Optional filter to filter which boxes' values are returned
357
- * @returns The (name, value) pair of the boxes with values as the ABI Value
358
- * @example
359
- * ```typescript
360
- * const boxValues = await appClient.getBoxValuesFromABIType(new ABIUintType(32))
361
- * ```
362
- */
363
- async getBoxValuesFromABIType(type, filter) {
364
- const names = (await this.getBoxNames()).filter(filter ?? ((_) => true));
365
- const values = await this._algorand.app.getBoxValuesFromABIType({
366
- appId: this.appId,
367
- boxNames: names.map((name) => name.nameRaw),
368
- type
369
- });
370
- return names.map((name, i) => ({
371
- name,
372
- value: values[i]
373
- }));
374
- }
375
- /**
376
- * Takes an error that may include a logic error from a call to the current app and re-exposes the
377
- * error to include source code information via the source map and ARC-56 spec.
378
- * @param e The error to parse
379
- * @param isClearStateProgram Whether or not the code was running the clear state program (defaults to approval program)
380
- * @returns The new error, or if there was no logic error or source map then the wrapped error with source details
381
- */
382
- async exposeLogicError(e, isClearStateProgram) {
383
- const pcOffsetMethod = this._appSpec.sourceInfo?.[isClearStateProgram ? "clear" : "approval"]?.pcOffsetMethod;
384
- let program;
385
- if (pcOffsetMethod === "cblocks") {
386
- const appInfo = await this._algorand.app.getById(this.appId);
387
- program = isClearStateProgram ? appInfo.clearStateProgram : appInfo.approvalProgram;
388
- }
389
- return AppClient.exposeLogicError(e, this._appSpec, {
390
- isClearStateProgram,
391
- approvalSourceMap: this._approvalSourceMap,
392
- clearSourceMap: this._clearSourceMap,
393
- program
394
- });
395
- }
396
- /**
397
- * Export the current source maps for the app.
398
- * @returns The source maps
399
- */
400
- exportSourceMaps() {
401
- 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");
402
- return {
403
- approvalSourceMap: this._approvalSourceMap,
404
- clearSourceMap: this._clearSourceMap
405
- };
406
- }
407
- /**
408
- * Import source maps for the app.
409
- * @param sourceMaps The source maps to import
410
- */
411
- importSourceMaps(sourceMaps) {
412
- this._approvalSourceMap = new require_sourcemap.ProgramSourceMap(sourceMaps.approvalSourceMap);
413
- this._clearSourceMap = new require_sourcemap.ProgramSourceMap(sourceMaps.clearSourceMap);
414
- }
415
- /**
416
- * Returns the ABI Method spec for the given method string for the app represented by this application client instance
417
- * @param methodNameOrSignature The method name or method signature to call if an ABI call is being emitted.
418
- * e.g. `my_method` or `my_method(unit64,string)bytes`
419
- * @returns A tuple with: [ARC-56 `Method`, algosdk `ABIMethod`]
420
- */
421
- getABIMethod(methodNameOrSignature) {
422
- return require_abi_method.getABIMethod(methodNameOrSignature, this._appSpec);
423
- }
424
- /**
425
- * Checks for decode errors on the SendAppTransactionResult and maps the return value to the specified type
426
- * on the ARC-56 method, replacing the `return` property with the decoded type.
427
- *
428
- * If the return type is an ARC-56 struct then the struct will be returned.
429
- *
430
- * @param result The SendAppTransactionResult to be mapped
431
- * @param method The method that was called
432
- * @returns The smart contract response with an updated return value
433
- */
434
- async processMethodCallReturn(result) {
435
- const resultValue = await result;
436
- return {
437
- ...resultValue,
438
- return: resultValue.return?.returnValue
439
- };
440
- }
441
- /**
442
- * Compiles the approval and clear state programs (if TEAL templates provided),
443
- * performing any provided deploy-time parameter replacement and stores
444
- * the source maps.
445
- *
446
- * If no TEAL templates provided it will use any byte code provided in the app spec.
447
- *
448
- * Will store any generated source maps for later use in debugging.
449
- * @param compilation Any compilation parameters to use
450
- * @returns The compiled code and any compilation results (including source maps)
451
- */
452
- async compile(compilation) {
453
- const result = await AppClient.compile(this._appSpec, this._algorand.app, compilation);
454
- if (result.compiledApproval) {
455
- this._approvalSourceMap = result.compiledApproval.sourceMap;
456
- this._lastCompiled.approval = result.compiledApproval.compiledBase64ToBytes;
457
- }
458
- if (result.compiledClear) {
459
- this._clearSourceMap = result.compiledClear.sourceMap;
460
- this._lastCompiled.clear = result.compiledClear.compiledBase64ToBytes;
461
- }
462
- return result;
463
- }
464
- /**
465
- * Takes an error that may include a logic error from a call to the current app and re-exposes the
466
- * error to include source code information via the source map and ARC-56 spec.
467
- * @param e The error to parse
468
- * @param appSpec The app spec for the app
469
- * @param details Additional information to inform the error
470
- * @returns The new error, or if there was no logic error or source map then the wrapped error with source details
471
- */
472
- static exposeLogicError(e, appSpec, details) {
473
- const { isClearStateProgram, approvalSourceMap, clearSourceMap, program } = details;
474
- const sourceMap = isClearStateProgram ? clearSourceMap : approvalSourceMap;
475
- const errorDetails = require_logic_error.LogicError.parseLogicError(e);
476
- if (errorDetails === void 0 || errorDetails?.pc === void 0) return e;
477
- /** The PC value to find in the ARC56 SourceInfo */
478
- let arc56Pc = errorDetails?.pc;
479
- const programSourceInfo = isClearStateProgram ? appSpec.sourceInfo?.clear : appSpec.sourceInfo?.approval;
480
- /** The offset to apply to the PC if using the cblocks pc offset method */
481
- let cblocksOffset = 0;
482
- if (programSourceInfo?.pcOffsetMethod === "cblocks") {
483
- if (program === void 0) throw new Error("Program bytes are required to calculate the ARC56 cblocks PC offset");
484
- cblocksOffset = getConstantBlockOffset(program);
485
- arc56Pc = errorDetails.pc - cblocksOffset;
486
- }
487
- const errorMessage = (programSourceInfo?.sourceInfo.find((s) => s.pc.includes(arc56Pc)))?.errorMessage;
488
- if (appSpec.source) {
489
- let getLineForPc = (inputPc) => sourceMap?.getLocationForPc?.(inputPc)?.line;
490
- if (sourceMap === void 0) getLineForPc = (inputPc) => {
491
- const teal = programSourceInfo?.sourceInfo.find((s) => s.pc.includes(inputPc - cblocksOffset))?.teal;
492
- if (teal === void 0) return void 0;
493
- return teal - 1;
494
- };
495
- e = new require_logic_error.LogicError(errorDetails, buffer.Buffer.from(isClearStateProgram ? appSpec.source.clear : appSpec.source.approval, "base64").toString().split("\n"), getLineForPc);
496
- }
497
- if (errorMessage) {
498
- const appId = require_util.asJson(e).match(/(?<=app=)\d+/)?.[0] || "";
499
- const txId = require_util.asJson(e).match(/(?<=transaction )\S+(?=:)/)?.[0];
500
- const error = /* @__PURE__ */ new Error(`Runtime error when executing ${appSpec.name} (appId: ${appId}) in transaction ${txId}: ${errorMessage}`);
501
- error.cause = e;
502
- return error;
503
- }
504
- return e;
505
- }
506
- /**
507
- * Compiles the approval and clear state programs (if TEAL templates provided),
508
- * performing any provided deploy-time parameter replacement and returns
509
- * the compiled code and any compilation results (including source maps).
510
- *
511
- * If no TEAL templates provided it will use any byte code provided in the app spec.
512
- *
513
- * Will store any generated source maps for later use in debugging.
514
- * @param appSpec The app spec for the app
515
- * @param appManager The app manager to use for compilation
516
- * @param compilation Any compilation parameters to use
517
- * @returns The compiled code and any compilation results (including source maps)
518
- */
519
- static async compile(appSpec, appManager, compilation) {
520
- const { deployTimeParams, updatable, deletable } = compilation ?? {};
521
- if (!appSpec.source) {
522
- if (!appSpec.byteCode?.approval || !appSpec.byteCode?.clear) throw new Error(`Attempt to compile app ${appSpec.name} without source or byteCode`);
523
- return {
524
- approvalProgram: buffer.Buffer.from(appSpec.byteCode.approval, "base64"),
525
- clearStateProgram: buffer.Buffer.from(appSpec.byteCode.clear, "base64")
526
- };
527
- }
528
- const approvalTemplate = buffer.Buffer.from(appSpec.source.approval, "base64").toString("utf-8");
529
- const compiledApproval = await appManager.compileTealTemplate(approvalTemplate, deployTimeParams, {
530
- updatable,
531
- deletable
532
- });
533
- const clearTemplate = buffer.Buffer.from(appSpec.source.clear, "base64").toString("utf-8");
534
- const compiledClear = await appManager.compileTealTemplate(clearTemplate, deployTimeParams);
535
- if (require_config.Config.debug) await require_config.Config.events.emitAsync(require_lifecycle_events.EventType.AppCompiled, { sources: [{
536
- compiledTeal: compiledApproval,
537
- appName: appSpec.name,
538
- fileName: "approval"
539
- }, {
540
- compiledTeal: compiledClear,
541
- appName: appSpec.name,
542
- fileName: "clear"
543
- }] });
544
- return {
545
- approvalProgram: compiledApproval.compiledBase64ToBytes,
546
- compiledApproval,
547
- clearStateProgram: compiledClear.compiledBase64ToBytes,
548
- compiledClear
549
- };
550
- }
551
- /**
552
- * Returns ABI method arguments ready for a method call params object with default values populated
553
- * and structs replaced with tuples.
554
- *
555
- * It does this by replacing any `undefined` values with the equivalent default value from the given ARC-56 app spec.
556
- * @param methodNameOrSignature The method name or method signature to call if an ABI call is being emitted.
557
- * e.g. `my_method` or `my_method(unit64,string)bytes`
558
- * @param args The arguments to the method with `undefined` for any that should be populated with a default value
559
- */
560
- async getABIArgsWithDefaultValues(methodNameOrSignature, args, sender) {
561
- const m = require_abi_method.getABIMethod(methodNameOrSignature, this._appSpec);
562
- return await Promise.all(args?.map(async (arg, i) => {
563
- const methodArg = m.args[i];
564
- if (!methodArg) throw new Error(`Unexpected arg at position ${i}. ${m.name} only expects ${m.args.length} args`);
565
- if (require_abi_method.argTypeIsTransaction(methodArg.type)) return arg;
566
- if (arg !== void 0) return arg;
567
- const defaultValue = methodArg.defaultValue;
568
- if (defaultValue) switch (defaultValue.source) {
569
- case "literal": {
570
- const bytes = buffer.Buffer.from(defaultValue.data, "base64");
571
- return require_abi_method.getABIDecodedValue(defaultValue.type ?? methodArg.type, bytes);
572
- }
573
- case "method": {
574
- const method = this.getABIMethod(defaultValue.data);
575
- const result = await this.send.call({
576
- method: defaultValue.data,
577
- args: method.args.map(() => void 0),
578
- sender
579
- });
580
- if (result.return === void 0) throw new Error("Default value method call did not return a value");
581
- return result.return;
582
- }
583
- case "local":
584
- case "global":
585
- case "box": return await this.getDefaultValueFromStorage({
586
- data: defaultValue.data,
587
- source: defaultValue.source
588
- }, methodArg.name ?? `arg${i + 1}`, sender);
589
- }
590
- }) ?? []);
591
- }
592
- async getDefaultValueFromStorage(defaultValue, argName, sender) {
593
- const keys = defaultValue.source === "box" ? require_arc56_contract.getBoxABIStorageKeys(this.appSpec) : defaultValue.source === "global" ? require_arc56_contract.getGlobalABIStorageKeys(this.appSpec) : require_arc56_contract.getLocalABIStorageKeys(this.appSpec);
594
- const key = Object.values(keys).find((s) => s.key === defaultValue.data);
595
- if (!key) throw new Error(`Unable to find default value for argument '${argName}': The storage key (base64: '${defaultValue.data}') is not defined in the contract's ${defaultValue.source} storage schema`);
596
- if (defaultValue.source === "box") {
597
- const value$1 = await this.getBoxValue(buffer.Buffer.from(defaultValue.data, "base64"));
598
- return require_abi_method.getABIDecodedValue(key.valueType, value$1);
599
- }
600
- const state = defaultValue.source === "global" ? await this.getGlobalState() : await this.getLocalState(sender);
601
- const value = Object.values(state).find((s) => s.keyBase64 === defaultValue.data);
602
- if (!value) throw new Error(`Unable to find default value for argument '${argName}': No value exists in ${defaultValue.source} storage for key (base64: '${defaultValue.data}')`);
603
- return "valueRaw" in value ? require_abi_method.getABIDecodedValue(key.valueType, value.valueRaw) : value.value;
604
- }
605
- getBareParamsMethods() {
606
- return {
607
- update: async (params) => {
608
- return this.getBareParams({
609
- ...params,
610
- ...await this.compile(params)
611
- }, require_app_call.OnApplicationComplete.UpdateApplication);
612
- },
613
- optIn: (params) => {
614
- return this.getBareParams(params, require_app_call.OnApplicationComplete.OptIn);
615
- },
616
- delete: (params) => {
617
- return this.getBareParams(params, require_app_call.OnApplicationComplete.DeleteApplication);
618
- },
619
- clearState: (params) => {
620
- return this.getBareParams(params, require_app_call.OnApplicationComplete.ClearState);
621
- },
622
- closeOut: (params) => {
623
- return this.getBareParams(params, require_app_call.OnApplicationComplete.CloseOut);
624
- },
625
- call: (params) => {
626
- return this.getBareParams(params, params?.onComplete ?? require_app_call.OnApplicationComplete.NoOp);
627
- }
628
- };
629
- }
630
- getBareCreateTransactionMethods() {
631
- return {
632
- update: async (params) => {
633
- return this._algorand.createTransaction.appUpdate(await this.params.bare.update(params));
634
- },
635
- optIn: (params) => {
636
- return this._algorand.createTransaction.appCall(this.params.bare.optIn(params));
637
- },
638
- delete: (params) => {
639
- return this._algorand.createTransaction.appDelete(this.params.bare.delete(params));
640
- },
641
- clearState: (params) => {
642
- return this._algorand.createTransaction.appCall(this.params.bare.clearState(params));
643
- },
644
- closeOut: (params) => {
645
- return this._algorand.createTransaction.appCall(this.params.bare.closeOut(params));
646
- },
647
- call: (params) => {
648
- return this._algorand.createTransaction.appCall(this.params.bare.call(params));
649
- }
650
- };
651
- }
652
- getBareSendMethods() {
653
- return {
654
- update: async (params) => {
655
- const compiled = await this.compile(params);
656
- return {
657
- ...await this._algorand.send.appUpdate(await this.params.bare.update(params)),
658
- ...compiled
659
- };
660
- },
661
- optIn: (params) => {
662
- return this._algorand.send.appCall(this.params.bare.optIn(params));
663
- },
664
- delete: (params) => {
665
- return this._algorand.send.appDelete(this.params.bare.delete(params));
666
- },
667
- clearState: (params) => {
668
- return this._algorand.send.appCall(this.params.bare.clearState(params));
669
- },
670
- closeOut: (params) => {
671
- return this._algorand.send.appCall(this.params.bare.closeOut(params));
672
- },
673
- call: (params) => {
674
- return this._algorand.send.appCall(this.params.bare.call(params));
675
- }
676
- };
677
- }
678
- getMethodCallParamsMethods() {
679
- return {
680
- fundAppAccount: (params) => {
681
- return {
682
- ...params,
683
- sender: this.getSender(params.sender),
684
- signer: this.getSigner(params.sender, params.signer),
685
- receiver: this.appAddress
686
- };
687
- },
688
- update: async (params) => {
689
- return await this.getABIParams({
690
- ...params,
691
- ...await this.compile(params)
692
- }, require_app_call.OnApplicationComplete.UpdateApplication);
693
- },
694
- optIn: async (params) => {
695
- return await this.getABIParams(params, require_app_call.OnApplicationComplete.OptIn);
696
- },
697
- delete: async (params) => {
698
- return await this.getABIParams(params, require_app_call.OnApplicationComplete.DeleteApplication);
699
- },
700
- closeOut: async (params) => {
701
- return await this.getABIParams(params, require_app_call.OnApplicationComplete.CloseOut);
702
- },
703
- call: async (params) => {
704
- return await this.getABIParams(params, params.onComplete ?? require_app_call.OnApplicationComplete.NoOp);
705
- }
706
- };
707
- }
708
- getMethodCallSendMethods() {
709
- return {
710
- fundAppAccount: (params) => {
711
- return this._algorand.send.payment(this.params.fundAppAccount(params));
712
- },
713
- update: async (params) => {
714
- const compiled = await this.compile(params);
715
- return {
716
- ...await this.processMethodCallReturn(this._algorand.send.appUpdateMethodCall(await this.params.update({ ...params }))),
717
- ...compiled
718
- };
719
- },
720
- optIn: async (params) => {
721
- return this.processMethodCallReturn(this._algorand.send.appCallMethodCall(await this.params.optIn(params)));
722
- },
723
- delete: async (params) => {
724
- return this.processMethodCallReturn(this._algorand.send.appDeleteMethodCall(await this.params.delete(params)));
725
- },
726
- closeOut: async (params) => {
727
- return this.processMethodCallReturn(this._algorand.send.appCallMethodCall(await this.params.closeOut(params)));
728
- },
729
- call: async (params) => {
730
- if ((params.onComplete === require_app_call.OnApplicationComplete.NoOp || !params.onComplete) && require_abi_method.getABIMethod(params.method, this._appSpec).readonly) {
731
- const readonlyParams = { ...params };
732
- if (params.coverAppCallInnerTransactionFees && params.maxFee) {
733
- readonlyParams.staticFee = params.maxFee;
734
- readonlyParams.extraFee = void 0;
735
- }
736
- try {
737
- const result = await this._algorand.newGroup().addAppCallMethodCall(await this.params.call(readonlyParams)).simulate({
738
- allowUnnamedResources: params.populateAppCallResources ?? true,
739
- skipSignatures: true,
740
- extraOpcodeBudget: MAX_SIMULATE_OPCODE_BUDGET
741
- });
742
- return this.processMethodCallReturn({
743
- ...result,
744
- transaction: result.transactions.at(-1),
745
- confirmation: result.confirmations.at(-1),
746
- return: result.returns && result.returns.length > 0 ? result.returns.at(-1) : void 0
747
- });
748
- } catch (e) {
749
- const error = e;
750
- if (params.coverAppCallInnerTransactionFees && error && error.message && error.message.match(/fee too small/)) throw Error(`Fees were too small. You may need to increase the transaction maxFee.`);
751
- throw e;
752
- }
753
- }
754
- return this.processMethodCallReturn(this._algorand.send.appCallMethodCall(await this.params.call(params)));
755
- }
756
- };
757
- }
758
- getMethodCallCreateTransactionMethods() {
759
- return {
760
- fundAppAccount: (params) => {
761
- return this._algorand.createTransaction.payment(this.params.fundAppAccount(params));
762
- },
763
- update: async (params) => {
764
- return this._algorand.createTransaction.appUpdateMethodCall(await this.params.update(params));
765
- },
766
- optIn: async (params) => {
767
- return this._algorand.createTransaction.appCallMethodCall(await this.params.optIn(params));
768
- },
769
- delete: async (params) => {
770
- return this._algorand.createTransaction.appDeleteMethodCall(await this.params.delete(params));
771
- },
772
- closeOut: async (params) => {
773
- return this._algorand.createTransaction.appCallMethodCall(await this.params.closeOut(params));
774
- },
775
- call: async (params) => {
776
- return this._algorand.createTransaction.appCallMethodCall(await this.params.call(params));
777
- }
778
- };
779
- }
780
- /** Returns the sender for a call, using the provided sender or using the `defaultSender`
781
- * if none provided and throws an error if neither provided */
782
- getSender(sender) {
783
- if (!sender && !this._defaultSender) throw new Error(`No sender provided and no default sender present in app client for call to app ${this._appName}`);
784
- return require_address.getAddress(sender ?? this._defaultSender);
785
- }
786
- /** Returns the signer for a call, using the provided signer or the `defaultSigner`
787
- * if no signer was provided and the sender resolves to the default sender, the call will use default signer
788
- * or `undefined` otherwise (so the signer is resolved from `AlgorandClient`) */
789
- getSigner(sender, signer) {
790
- return signer ?? (!sender || sender === this._defaultSender ? this._defaultSigner : void 0);
791
- }
792
- getBareParams(params, onComplete) {
793
- return {
794
- ...params,
795
- appId: this._appId,
796
- sender: this.getSender(params?.sender),
797
- signer: this.getSigner(params?.sender, params?.signer),
798
- onComplete
799
- };
800
- }
801
- async getABIParams(params, onComplete) {
802
- const sender = this.getSender(params.sender);
803
- const method = require_abi_method.getABIMethod(params.method, this._appSpec);
804
- const args = await this.getABIArgsWithDefaultValues(params.method, params.args, sender);
805
- return {
806
- ...params,
807
- appId: this._appId,
808
- sender,
809
- signer: this.getSigner(params.sender, params.signer),
810
- method,
811
- onComplete,
812
- args
813
- };
814
- }
815
- /** Make the given call and catch any errors, augmenting with debugging information before re-throwing. */
816
- handleCallErrors = async (e) => {
817
- if (this.appId === 0n) {
818
- if (e.sentTransactions === void 0) return e;
819
- const txn = e.sentTransactions.find((t) => e.message.includes(t.txId()));
820
- const programsDefinedAndEqual = (a, b) => {
821
- if (a === void 0 || b === void 0) return false;
822
- if (a.length !== b.length) return false;
823
- for (let i = 0; i < a.length; i++) if (a[i] !== b[i]) return false;
824
- return true;
825
- };
826
- if (!programsDefinedAndEqual(txn?.appCall?.clearStateProgram, this._lastCompiled.clear) || !programsDefinedAndEqual(txn?.appCall?.approvalProgram, this._lastCompiled?.approval)) return e;
827
- } else {
828
- const appIdString = `app=${this._appId.toString()}`;
829
- if (!e.message.includes(appIdString)) return e;
830
- }
831
- const logicError = await this.exposeLogicError(e);
832
- if (logicError instanceof require_logic_error.LogicError) {
833
- let currentLine = logicError.teal_line - logicError.lines - 1;
834
- const stackWithLines = logicError.stack?.split("\n").map((line) => `${currentLine += 1}: ${line}`).join("\n");
835
- require_config.Config.logger.error(`${logicError.message}\n\n${stackWithLines}`);
836
- }
837
- return logicError;
838
- };
839
- getBoxMethods() {
840
- const that = this;
841
- const stateMethods = {
842
- getAll: async () => {
843
- return Object.fromEntries(await Promise.all(Object.keys(that._appSpec.state.keys.box).map(async (key) => [key, await stateMethods.getValue(key)])));
844
- },
845
- getValue: async (name) => {
846
- const metadata = require_arc56_contract.getBoxABIStorageKey(that._appSpec, name);
847
- const value = await that.getBoxValue(buffer.Buffer.from(metadata.key, "base64"));
848
- return require_abi_method.getABIDecodedValue(metadata.valueType, value);
849
- },
850
- getMapValue: async (mapName, key) => {
851
- const metadata = require_arc56_contract.getBoxABIStorageMap(that._appSpec, mapName);
852
- const prefix = buffer.Buffer.from(metadata.prefix ?? "", "base64");
853
- const encodedKey = buffer.Buffer.concat([prefix, require_abi_method.getABIEncodedValue(metadata.keyType, key)]);
854
- const base64Key = buffer.Buffer.from(encodedKey).toString("base64");
855
- const value = await that.getBoxValue(buffer.Buffer.from(base64Key, "base64"));
856
- return require_abi_method.getABIDecodedValue(metadata.valueType, value);
857
- },
858
- getMap: async (mapName) => {
859
- const metadata = require_arc56_contract.getBoxABIStorageMap(that._appSpec, mapName);
860
- const prefix = buffer.Buffer.from(metadata.prefix ?? "", "base64");
861
- const boxNames = await that.getBoxNames();
862
- return new Map(await Promise.all(boxNames.filter((b) => require_util.binaryStartsWith(b.nameRaw, prefix)).map(async (b) => {
863
- return [require_abi_method.getABIDecodedValue(metadata.keyType, b.nameRaw.slice(prefix.length)), require_abi_method.getABIDecodedValue(metadata.valueType, await that.getBoxValue(b.nameRaw))];
864
- })));
865
- }
866
- };
867
- return stateMethods;
868
- }
869
- getStateMethods(stateGetter, keyGetter, mapGetter) {
870
- const stateMethods = {
871
- getAll: async () => {
872
- const appState = await stateGetter();
873
- return Object.fromEntries(await Promise.all(Object.keys(keyGetter()).map(async (key) => [key, await stateMethods.getValue(key, appState)])));
874
- },
875
- getValue: async (name, appState) => {
876
- const state = Object.values(appState ?? await stateGetter());
877
- const metadata = keyGetter()[name];
878
- if (metadata === void 0) throw new Error(`Attempted to get state value ${name}, but it does not exist`);
879
- const value = state.find((s) => s.keyBase64 === metadata.key);
880
- if (value && "valueRaw" in value) return require_abi_method.getABIDecodedValue(metadata.valueType, value.valueRaw);
881
- return value?.value;
882
- },
883
- getMapValue: async (mapName, key, appState) => {
884
- const state = Object.values(appState ?? await stateGetter());
885
- const metadata = mapGetter()[mapName];
886
- const prefix = buffer.Buffer.from(metadata.prefix ?? "", "base64");
887
- const encodedKey = buffer.Buffer.concat([prefix, require_abi_method.getABIEncodedValue(metadata.keyType, key)]);
888
- const base64Key = buffer.Buffer.from(encodedKey).toString("base64");
889
- const value = state.find((s) => s.keyBase64 === base64Key);
890
- if (value && "valueRaw" in value) return require_abi_method.getABIDecodedValue(metadata.valueType, value.valueRaw);
891
- return value?.value;
892
- },
893
- getMap: async (mapName) => {
894
- const state = Object.values(await stateGetter());
895
- const metadata = mapGetter()[mapName];
896
- const prefix = buffer.Buffer.from(metadata.prefix ?? "", "base64");
897
- return new Map(state.filter((s) => require_util.binaryStartsWith(s.keyRaw, prefix)).map((s) => {
898
- const key = s.keyRaw.slice(prefix.length);
899
- return [require_abi_method.getABIDecodedValue(metadata.keyType, key), "valueRaw" in s ? require_abi_method.getABIDecodedValue(metadata.valueType, s.valueRaw) : s.value];
900
- }));
901
- }
902
- };
903
- return stateMethods;
904
- }
905
- };
4
+ /** @deprecated Import from `@algorandfoundation/algokit-utils/app-client` instead */
5
+ const AppClient = require_app_client.AppClient;
906
6
 
907
7
  //#endregion
908
8
  exports.AppClient = AppClient;