@algorandfoundation/algokit-utils 7.0.0-beta.9 → 8.0.0-beta.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (231) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +21 -3
  3. package/account/account.d.ts +4 -1
  4. package/account/account.js +10 -7
  5. package/account/account.js.map +1 -1
  6. package/account/account.mjs +11 -8
  7. package/account/account.mjs.map +1 -1
  8. package/account/get-account-config-from-environment.js.map +1 -1
  9. package/account/get-account-config-from-environment.mjs.map +1 -1
  10. package/account/get-account.js.map +1 -1
  11. package/account/get-account.mjs.map +1 -1
  12. package/account/get-dispenser-account.d.ts +1 -1
  13. package/account/get-dispenser-account.js.map +1 -1
  14. package/account/get-dispenser-account.mjs.map +1 -1
  15. package/account/mnemonic-account.js.map +1 -1
  16. package/account/mnemonic-account.mjs.map +1 -1
  17. package/amount.d.ts +1 -0
  18. package/amount.js +3 -2
  19. package/amount.js.map +1 -1
  20. package/amount.mjs +3 -3
  21. package/amount.mjs.map +1 -1
  22. package/app-client.d.ts +4 -4
  23. package/app-client.js +4 -4
  24. package/app-client.js.map +1 -1
  25. package/app-client.mjs +4 -4
  26. package/app-client.mjs.map +1 -1
  27. package/app-deploy.js +25 -15
  28. package/app-deploy.js.map +1 -1
  29. package/app-deploy.mjs +27 -17
  30. package/app-deploy.mjs.map +1 -1
  31. package/app.d.ts +2 -2
  32. package/app.js +9 -6
  33. package/app.js.map +1 -1
  34. package/app.mjs +9 -6
  35. package/app.mjs.map +1 -1
  36. package/asset.js.map +1 -1
  37. package/asset.mjs.map +1 -1
  38. package/debugging/debugging.js.map +1 -1
  39. package/debugging/debugging.mjs.map +1 -1
  40. package/dispenser-client.js.map +1 -1
  41. package/dispenser-client.mjs.map +1 -1
  42. package/index.d.ts +1 -0
  43. package/index.js +7 -1
  44. package/index.js.map +1 -1
  45. package/index.mjs +3 -2
  46. package/index.mjs.map +1 -1
  47. package/indexer-lookup.d.ts +10 -8
  48. package/indexer-lookup.js +14 -10
  49. package/indexer-lookup.js.map +1 -1
  50. package/indexer-lookup.mjs +14 -10
  51. package/indexer-lookup.mjs.map +1 -1
  52. package/localnet/get-kmd-wallet-account.js.map +1 -1
  53. package/localnet/get-kmd-wallet-account.mjs.map +1 -1
  54. package/localnet/get-localnet-dispenser-account.js.map +1 -1
  55. package/localnet/get-localnet-dispenser-account.mjs.map +1 -1
  56. package/localnet/get-or-create-kmd-wallet-account.js.map +1 -1
  57. package/localnet/get-or-create-kmd-wallet-account.mjs.map +1 -1
  58. package/localnet/is-localnet.js.map +1 -1
  59. package/localnet/is-localnet.mjs.map +1 -1
  60. package/network-client.d.ts +1 -7
  61. package/network-client.js +2 -9
  62. package/network-client.js.map +1 -1
  63. package/network-client.mjs +2 -9
  64. package/network-client.mjs.map +1 -1
  65. package/package.json +5 -5
  66. package/testing/_asset.d.ts +2 -1
  67. package/testing/account.d.ts +4 -3
  68. package/testing/account.js +8 -2
  69. package/testing/account.js.map +1 -1
  70. package/testing/account.mjs +9 -3
  71. package/testing/account.mjs.map +1 -1
  72. package/testing/fixtures/algokit-log-capture-fixture.js.map +1 -1
  73. package/testing/fixtures/algokit-log-capture-fixture.mjs.map +1 -1
  74. package/testing/fixtures/algorand-fixture.js +5 -6
  75. package/testing/fixtures/algorand-fixture.js.map +1 -1
  76. package/testing/fixtures/algorand-fixture.mjs +5 -6
  77. package/testing/fixtures/algorand-fixture.mjs.map +1 -1
  78. package/testing/indexer.js.map +1 -1
  79. package/testing/indexer.mjs.map +1 -1
  80. package/testing/test-logger.js +7 -1
  81. package/testing/test-logger.js.map +1 -1
  82. package/testing/test-logger.mjs +7 -1
  83. package/testing/test-logger.mjs.map +1 -1
  84. package/testing/transaction-logger.js.map +1 -1
  85. package/testing/transaction-logger.mjs.map +1 -1
  86. package/transaction/legacy-bridge.js +2 -2
  87. package/transaction/legacy-bridge.js.map +1 -1
  88. package/transaction/legacy-bridge.mjs +3 -3
  89. package/transaction/legacy-bridge.mjs.map +1 -1
  90. package/transaction/perform-atomic-transaction-composer-simulate.d.ts +4 -1
  91. package/transaction/perform-atomic-transaction-composer-simulate.js +14 -9
  92. package/transaction/perform-atomic-transaction-composer-simulate.js.map +1 -1
  93. package/transaction/perform-atomic-transaction-composer-simulate.mjs +15 -10
  94. package/transaction/perform-atomic-transaction-composer-simulate.mjs.map +1 -1
  95. package/transaction/transaction.d.ts +13 -22
  96. package/transaction/transaction.js +164 -110
  97. package/transaction/transaction.js.map +1 -1
  98. package/transaction/transaction.mjs +163 -109
  99. package/transaction/transaction.mjs.map +1 -1
  100. package/transfer/transfer-algos.js.map +1 -1
  101. package/transfer/transfer-algos.mjs.map +1 -1
  102. package/transfer/transfer.js +3 -1
  103. package/transfer/transfer.js.map +1 -1
  104. package/transfer/transfer.mjs +3 -1
  105. package/transfer/transfer.mjs.map +1 -1
  106. package/types/account-manager.d.ts +20 -20
  107. package/types/account-manager.js +36 -27
  108. package/types/account-manager.js.map +1 -1
  109. package/types/account-manager.mjs +38 -29
  110. package/types/account-manager.mjs.map +1 -1
  111. package/types/account.d.ts +17 -8
  112. package/types/account.js +2 -2
  113. package/types/account.js.map +1 -1
  114. package/types/account.mjs +3 -3
  115. package/types/account.mjs.map +1 -1
  116. package/types/algo-http-client-with-retry.d.ts +1 -2
  117. package/types/algo-http-client-with-retry.js +33 -3
  118. package/types/algo-http-client-with-retry.js.map +1 -1
  119. package/types/algo-http-client-with-retry.mjs +32 -2
  120. package/types/algo-http-client-with-retry.mjs.map +1 -1
  121. package/types/algorand-client-interface.d.ts +2 -2
  122. package/types/algorand-client-transaction-creator.d.ts +16 -14
  123. package/types/algorand-client-transaction-creator.js +3 -1
  124. package/types/algorand-client-transaction-creator.js.map +1 -1
  125. package/types/algorand-client-transaction-creator.mjs +3 -1
  126. package/types/algorand-client-transaction-creator.mjs.map +1 -1
  127. package/types/algorand-client-transaction-sender.d.ts +109 -105
  128. package/types/algorand-client-transaction-sender.js +6 -2
  129. package/types/algorand-client-transaction-sender.js.map +1 -1
  130. package/types/algorand-client-transaction-sender.mjs +6 -2
  131. package/types/algorand-client-transaction-sender.mjs.map +1 -1
  132. package/types/algorand-client.d.ts +6 -7
  133. package/types/algorand-client.js +3 -6
  134. package/types/algorand-client.js.map +1 -1
  135. package/types/algorand-client.mjs +5 -5
  136. package/types/algorand-client.mjs.map +1 -1
  137. package/types/amount.js.map +1 -1
  138. package/types/amount.mjs.map +1 -1
  139. package/types/app-arc56.d.ts +31 -20
  140. package/types/app-arc56.js.map +1 -1
  141. package/types/app-arc56.mjs.map +1 -1
  142. package/types/app-client.d.ts +298 -286
  143. package/types/app-client.js +148 -41
  144. package/types/app-client.js.map +1 -1
  145. package/types/app-client.mjs +147 -40
  146. package/types/app-client.mjs.map +1 -1
  147. package/types/app-deployer.d.ts +4 -4
  148. package/types/app-deployer.js +23 -24
  149. package/types/app-deployer.js.map +1 -1
  150. package/types/app-deployer.mjs +25 -26
  151. package/types/app-deployer.mjs.map +1 -1
  152. package/types/app-factory.d.ts +130 -130
  153. package/types/app-factory.js +4 -5
  154. package/types/app-factory.js.map +1 -1
  155. package/types/app-factory.mjs +5 -6
  156. package/types/app-factory.mjs.map +1 -1
  157. package/types/app-manager.d.ts +5 -5
  158. package/types/app-manager.js +116 -38
  159. package/types/app-manager.js.map +1 -1
  160. package/types/app-manager.mjs +117 -39
  161. package/types/app-manager.mjs.map +1 -1
  162. package/types/app-spec.js +8 -2
  163. package/types/app-spec.js.map +1 -1
  164. package/types/app-spec.mjs +8 -2
  165. package/types/app-spec.mjs.map +1 -1
  166. package/types/app.d.ts +12 -11
  167. package/types/app.js.map +1 -1
  168. package/types/app.mjs.map +1 -1
  169. package/types/asset-manager.d.ts +9 -9
  170. package/types/asset-manager.js +10 -13
  171. package/types/asset-manager.js.map +1 -1
  172. package/types/asset-manager.mjs +10 -13
  173. package/types/asset-manager.mjs.map +1 -1
  174. package/types/async-event-emitter.d.ts +1 -10
  175. package/types/async-event-emitter.js +0 -5
  176. package/types/async-event-emitter.js.map +1 -1
  177. package/types/async-event-emitter.mjs +1 -6
  178. package/types/async-event-emitter.mjs.map +1 -1
  179. package/types/client-manager.d.ts +2 -9
  180. package/types/client-manager.js +11 -21
  181. package/types/client-manager.js.map +1 -1
  182. package/types/client-manager.mjs +11 -21
  183. package/types/client-manager.mjs.map +1 -1
  184. package/types/composer.d.ts +58 -46
  185. package/types/composer.js +154 -105
  186. package/types/composer.js.map +1 -1
  187. package/types/composer.mjs +156 -105
  188. package/types/composer.mjs.map +1 -1
  189. package/types/config.js.map +1 -1
  190. package/types/config.mjs.map +1 -1
  191. package/types/debugging.d.ts +1 -1
  192. package/types/debugging.js +1 -1
  193. package/types/debugging.js.map +1 -1
  194. package/types/debugging.mjs +1 -1
  195. package/types/debugging.mjs.map +1 -1
  196. package/types/dispenser-client.d.ts +2 -1
  197. package/types/dispenser-client.js +5 -1
  198. package/types/dispenser-client.js.map +1 -1
  199. package/types/dispenser-client.mjs +5 -1
  200. package/types/dispenser-client.mjs.map +1 -1
  201. package/types/indexer.d.ts +74 -755
  202. package/types/indexer.js.map +1 -1
  203. package/types/indexer.mjs.map +1 -1
  204. package/types/kmd-account-manager.d.ts +2 -2
  205. package/types/kmd-account-manager.js +1 -1
  206. package/types/kmd-account-manager.js.map +1 -1
  207. package/types/kmd-account-manager.mjs +2 -2
  208. package/types/kmd-account-manager.mjs.map +1 -1
  209. package/types/lifecycle-events.d.ts +10 -0
  210. package/types/lifecycle-events.js +8 -0
  211. package/types/lifecycle-events.js.map +1 -0
  212. package/types/lifecycle-events.mjs +8 -0
  213. package/types/lifecycle-events.mjs.map +1 -0
  214. package/types/logging.js.map +1 -1
  215. package/types/logging.mjs.map +1 -1
  216. package/types/logic-error.d.ts +2 -3
  217. package/types/logic-error.js +3 -3
  218. package/types/logic-error.js.map +1 -1
  219. package/types/logic-error.mjs +3 -3
  220. package/types/logic-error.mjs.map +1 -1
  221. package/types/network-client.d.ts +1 -1
  222. package/types/network-client.js.map +1 -1
  223. package/types/network-client.mjs.map +1 -1
  224. package/types/testing.d.ts +6 -7
  225. package/util.js.map +1 -1
  226. package/util.mjs.map +1 -1
  227. package/types/urlTokenBaseHTTPClient.d.ts +0 -40
  228. package/types/urlTokenBaseHTTPClient.js +0 -153
  229. package/types/urlTokenBaseHTTPClient.js.map +0 -1
  230. package/types/urlTokenBaseHTTPClient.mjs +0 -151
  231. package/types/urlTokenBaseHTTPClient.mjs.map +0 -1
@@ -11,7 +11,7 @@ var util = require('../util.js');
11
11
  var types_app = require('./app.js');
12
12
  var types_appArc56 = require('./app-arc56.js');
13
13
  var types_appSpec = require('./app-spec.js');
14
- var types_asyncEventEmitter = require('./async-event-emitter.js');
14
+ var types_lifecycleEvents = require('./lifecycle-events.js');
15
15
  var types_logicError = require('./logic-error.js');
16
16
 
17
17
  var ABIMethod = algosdk.ABIMethod;
@@ -19,7 +19,7 @@ var AtomicTransactionComposer = algosdk.AtomicTransactionComposer;
19
19
  var getApplicationAddress = algosdk.getApplicationAddress;
20
20
  var Indexer = algosdk.Indexer;
21
21
  var OnApplicationComplete = algosdk.OnApplicationComplete;
22
- var SourceMap = algosdk.SourceMap;
22
+ var SourceMap = algosdk.ProgramSourceMap;
23
23
  /**
24
24
  * Determines deploy time control (UPDATABLE, DELETABLE) value by inspecting application specification
25
25
  * @param approval TEAL Approval program, not the base64 version found on the appSpec
@@ -42,6 +42,57 @@ function getDeployTimeControl(approval, appSpec, templateVariableName, callConfi
42
42
  return !!abiCallConfig && abiCallConfig !== 'NEVER';
43
43
  });
44
44
  }
45
+ const BYTE_CBLOCK = 38;
46
+ const INT_CBLOCK = 32;
47
+ /**
48
+ * Get the offset of the last constant block at the beginning of the program
49
+ * This value is used to calculate the program counter for an ARC56 program that has a pcOffsetMethod of "cblocks"
50
+ *
51
+ * @param program The program to parse
52
+ * @returns The PC value of the opcode after the last constant block
53
+ */
54
+ function getConstantBlockOffset(program) {
55
+ const bytes = [...program];
56
+ const programSize = bytes.length;
57
+ bytes.shift(); // remove version
58
+ /** The PC of the opcode after the bytecblock */
59
+ let bytecblockOffset;
60
+ /** The PC of the opcode after the intcblock */
61
+ let intcblockOffset;
62
+ while (bytes.length > 0) {
63
+ /** The current byte from the beginning of the byte array */
64
+ const byte = bytes.shift();
65
+ // If the byte is a constant block...
66
+ if (byte === BYTE_CBLOCK || byte === INT_CBLOCK) {
67
+ const isBytecblock = byte === BYTE_CBLOCK;
68
+ /** The byte following the opcode is the number of values in the constant block */
69
+ const valuesRemaining = bytes.shift();
70
+ // Iterate over all the values in the constant block
71
+ for (let i = 0; i < valuesRemaining; i++) {
72
+ if (isBytecblock) {
73
+ /** The byte following the opcode is the length of the next element */
74
+ const length = bytes.shift();
75
+ bytes.splice(0, length);
76
+ }
77
+ else {
78
+ // intcblock is a uvarint, so we need to keep reading until we find the end (MSB is not set)
79
+ while ((bytes.shift() & 0x80) !== 0) {
80
+ // Do nothing...
81
+ }
82
+ }
83
+ }
84
+ if (isBytecblock)
85
+ bytecblockOffset = programSize - bytes.length - 1;
86
+ else
87
+ intcblockOffset = programSize - bytes.length - 1;
88
+ if (bytes[0] !== BYTE_CBLOCK && bytes[0] !== INT_CBLOCK) {
89
+ // if the next opcode isn't a constant block, we're done
90
+ break;
91
+ }
92
+ }
93
+ }
94
+ return Math.max(bytecblockOffset ?? 0, intcblockOffset ?? 0);
95
+ }
45
96
  /** ARC-56/ARC-32 application client that allows you to manage calls and
46
97
  * state for a specific deployed instance of an app (with a known app ID). */
47
98
  class AppClient {
@@ -51,7 +102,7 @@ class AppClient {
51
102
  this._appSpec = AppClient.normaliseAppSpec(params.appSpec);
52
103
  this._appName = params.appName ?? this._appSpec.name;
53
104
  this._algorand = params.algorand;
54
- this._defaultSender = params.defaultSender;
105
+ this._defaultSender = typeof params.defaultSender === 'string' ? algosdk.Address.fromString(params.defaultSender) : params.defaultSender;
55
106
  this._defaultSigner = params.defaultSigner;
56
107
  this._approvalSourceMap = params.approvalSourceMap;
57
108
  this._clearSourceMap = params.clearSourceMap;
@@ -74,9 +125,24 @@ class AppClient {
74
125
  bare: this.getBareSendMethods(),
75
126
  };
76
127
  }
77
- /** Start a new `AlgoKitComposer` transaction group */
78
- newGroup() {
79
- return this._algorand.newGroup();
128
+ /**
129
+ * Clone this app client with different params
130
+ *
131
+ * @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.
132
+ * @returns A new app client with the altered params
133
+ */
134
+ clone(params) {
135
+ return new AppClient({
136
+ appId: this._appId,
137
+ appSpec: this._appSpec,
138
+ algorand: this._algorand,
139
+ appName: this._appName,
140
+ defaultSender: this._defaultSender,
141
+ defaultSigner: this._defaultSigner,
142
+ approvalSourceMap: this._approvalSourceMap,
143
+ clearSourceMap: this._clearSourceMap,
144
+ ...params,
145
+ });
80
146
  }
81
147
  /**
82
148
  * Returns a new `AppClient` client, resolving the app by creator address and name
@@ -140,7 +206,7 @@ class AppClient {
140
206
  get appAddress() {
141
207
  return this._appAddress;
142
208
  }
143
- /** The name of the app (from the ARC-32 / ARC-56 app spec). */
209
+ /** The name of the app (from the ARC-32 / ARC-56 app spec or override). */
144
210
  get appName() {
145
211
  return this._appName;
146
212
  }
@@ -283,11 +349,19 @@ class AppClient {
283
349
  * @param isClearStateProgram Whether or not the code was running the clear state program (defaults to approval program)
284
350
  * @returns The new error, or if there was no logic error or source map then the wrapped error with source details
285
351
  */
286
- exposeLogicError(e, isClearStateProgram) {
352
+ async exposeLogicError(e, isClearStateProgram) {
353
+ const pcOffsetMethod = this._appSpec.sourceInfo?.[isClearStateProgram ? 'clear' : 'approval']?.pcOffsetMethod;
354
+ let program;
355
+ if (pcOffsetMethod === 'cblocks') {
356
+ // TODO: Cache this if we deploy the app and it's not updateable
357
+ const appInfo = await this._algorand.app.getById(this.appId);
358
+ program = isClearStateProgram ? appInfo.clearStateProgram : appInfo.approvalProgram;
359
+ }
287
360
  return AppClient.exposeLogicError(e, this._appSpec, {
288
361
  isClearStateProgram,
289
362
  approvalSourceMap: this._approvalSourceMap,
290
363
  clearSourceMap: this._clearSourceMap,
364
+ program,
291
365
  });
292
366
  }
293
367
  /**
@@ -362,17 +436,45 @@ class AppClient {
362
436
  * @returns The new error, or if there was no logic error or source map then the wrapped error with source details
363
437
  */
364
438
  static exposeLogicError(e, appSpec, details) {
365
- const { isClearStateProgram, approvalSourceMap, clearSourceMap } = details;
366
- if ((!isClearStateProgram && approvalSourceMap == undefined) || (isClearStateProgram && clearSourceMap == undefined))
367
- return e;
439
+ const { isClearStateProgram, approvalSourceMap, clearSourceMap, program } = details;
440
+ const sourceMap = isClearStateProgram ? clearSourceMap : approvalSourceMap;
368
441
  const errorDetails = types_logicError.LogicError.parseLogicError(e);
369
- const errorMessage = (isClearStateProgram ? appSpec.sourceInfo?.clear : appSpec.sourceInfo?.approval)?.find((s) => s?.pc?.includes(errorDetails?.pc ?? -1))?.errorMessage;
370
- if (errorDetails !== undefined && appSpec.source)
442
+ // Return the error if we don't have a PC
443
+ if (errorDetails === undefined || errorDetails?.pc === undefined)
444
+ return e;
445
+ /** The PC value to find in the ARC56 SourceInfo */
446
+ let arc56Pc = errorDetails?.pc;
447
+ const programSourceInfo = isClearStateProgram ? appSpec.sourceInfo?.clear : appSpec.sourceInfo?.approval;
448
+ /** The offset to apply to the PC if using the cblocks pc offset method */
449
+ let cblocksOffset = 0;
450
+ // If the program uses cblocks offset, then we need to adjust the PC accordingly
451
+ if (programSourceInfo?.pcOffsetMethod === 'cblocks') {
452
+ if (program === undefined)
453
+ throw new Error('Program bytes are required to calculate the ARC56 cblocks PC offset');
454
+ cblocksOffset = getConstantBlockOffset(program);
455
+ arc56Pc = errorDetails.pc - cblocksOffset;
456
+ }
457
+ // Find the source info for this PC and get the error message
458
+ const sourceInfo = programSourceInfo?.sourceInfo.find((s) => s.pc.includes(arc56Pc));
459
+ const errorMessage = sourceInfo?.errorMessage;
460
+ // If we have the source we can display the TEAL in the error message
461
+ if (appSpec.source) {
462
+ let getLineForPc = (inputPc) => sourceMap?.getLocationForPc?.(inputPc)?.line;
463
+ // If the SourceMap is not defined, we need to provide our own function for going from a PC to TEAL based on ARC56 SourceInfo[]
464
+ if (sourceMap === undefined) {
465
+ getLineForPc = (inputPc) => {
466
+ const teal = programSourceInfo?.sourceInfo.find((s) => s.pc.includes(inputPc - cblocksOffset))?.teal;
467
+ if (teal === undefined)
468
+ return undefined;
469
+ return teal - 1;
470
+ };
471
+ }
371
472
  e = new types_logicError.LogicError(errorDetails, buffer.Buffer.from(isClearStateProgram ? appSpec.source.clear : appSpec.source.approval, 'base64')
372
473
  .toString()
373
474
  .split('\n'),
374
475
  // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
375
- isClearStateProgram ? clearSourceMap : approvalSourceMap);
476
+ getLineForPc);
477
+ }
376
478
  if (errorMessage) {
377
479
  const appId = JSON.stringify(e).match(/(?<=app=)\d+/)?.[0] || '';
378
480
  const txId = JSON.stringify(e).match(/(?<=transaction )\S+(?=:)/)?.[0];
@@ -412,7 +514,7 @@ class AppClient {
412
514
  const clearTemplate = buffer.Buffer.from(appSpec.source.clear, 'base64').toString('utf-8');
413
515
  const compiledClear = await appManager.compileTealTemplate(clearTemplate, deployTimeParams);
414
516
  if (config.Config.debug) {
415
- await config.Config.events.emitAsync(types_asyncEventEmitter.EventType.AppCompiled, {
517
+ await config.Config.events.emitAsync(types_lifecycleEvents.EventType.AppCompiled, {
416
518
  sources: [
417
519
  { compiledTeal: compiledApproval, appName: appSpec.name, fileName: 'approval' },
418
520
  { compiledTeal: compiledClear, appName: appSpec.name, fileName: 'clear' },
@@ -449,19 +551,22 @@ class AppClient {
449
551
  if (defaultValue) {
450
552
  switch (defaultValue.source) {
451
553
  case 'literal':
452
- if (typeof defaultValue.data === 'number')
453
- return defaultValue.data;
454
554
  return types_appArc56.getABIDecodedValue(buffer.Buffer.from(defaultValue.data, 'base64'), m.method.args[i].defaultValue?.type ?? m.method.args[i].type, this._appSpec.structs);
455
- // todo: When ARC-56 supports ABI calls as default args
456
- // case 'abi': {
457
- // const method = this.getABIMethod(defaultValue.data as string)
458
- // const result = await this.send.call({
459
- // method: defaultValue.data as string,
460
- // methodArgs: method.args.map(() => undefined),
461
- // sender,
462
- // })
463
- // return result.return!
464
- // }
555
+ case 'method': {
556
+ const method = this.getABIMethod(defaultValue.data);
557
+ const result = await this.send.call({
558
+ method: defaultValue.data,
559
+ args: method.args.map(() => undefined),
560
+ sender,
561
+ });
562
+ if (result.return === undefined) {
563
+ throw new Error('Default value method call did not return a value');
564
+ }
565
+ if (typeof result.return === 'object' && !(result.return instanceof Uint8Array) && !Array.isArray(result.return)) {
566
+ return types_appArc56.getABITupleFromABIStruct(result.return, this._appSpec.structs[method.returns.struct], this._appSpec.structs);
567
+ }
568
+ return result.return;
569
+ }
465
570
  case 'local':
466
571
  case 'global': {
467
572
  const state = defaultValue.source === 'global' ? await this.getGlobalState() : await this.getLocalState(sender);
@@ -479,7 +584,9 @@ class AppClient {
479
584
  }
480
585
  }
481
586
  }
482
- throw new Error(`No value provided for required argument ${arg.name ?? `arg${i + 1}`} in call to method ${m.name}`);
587
+ if (!algosdk.abiTypeIsTransaction(arg.type)) {
588
+ throw new Error(`No value provided for required argument ${arg.name ?? `arg${i + 1}`} in call to method ${m.name}`);
589
+ }
483
590
  }) ?? []);
484
591
  }
485
592
  getBareParamsMethods() {
@@ -648,13 +755,13 @@ class AppClient {
648
755
  */
649
756
  call: async (params) => {
650
757
  // Read-only call - do it via simulate
651
- if (params.onComplete === OnApplicationComplete.NoOpOC ||
652
- (!params.onComplete && types_appArc56.getArc56Method(params.method, this._appSpec).method.readonly)) {
758
+ if ((params.onComplete === OnApplicationComplete.NoOpOC || !params.onComplete) &&
759
+ types_appArc56.getArc56Method(params.method, this._appSpec).method.readonly) {
653
760
  const result = await this._algorand
654
761
  .newGroup()
655
762
  .addAppCallMethodCall(await this.params.call(params))
656
763
  .simulate({
657
- allowUnnamedResources: params.populateAppCallResources,
764
+ allowUnnamedResources: params.populateAppCallResources ?? true,
658
765
  // Simulate calls for a readonly method shouldn't invoke signing
659
766
  skipSignatures: true,
660
767
  });
@@ -714,7 +821,7 @@ class AppClient {
714
821
  if (!sender && !this._defaultSender) {
715
822
  throw new Error(`No sender provided and no default sender present in app client for call to app ${this._appName}`);
716
823
  }
717
- return sender ?? this._defaultSender;
824
+ return typeof sender === 'string' ? algosdk.Address.fromString(sender) : (sender ?? this._defaultSender);
718
825
  }
719
826
  /** Returns the signer for a call, using the provided signer or the `defaultSigner`
720
827
  * if no signer was provided and the call will use default sender
@@ -751,7 +858,7 @@ class AppClient {
751
858
  return await call();
752
859
  }
753
860
  catch (e) {
754
- throw this.exposeLogicError(e);
861
+ throw await this.exposeLogicError(e);
755
862
  }
756
863
  }
757
864
  getBoxMethods() {
@@ -919,7 +1026,7 @@ class ApplicationClient {
919
1026
  }
920
1027
  else {
921
1028
  this._appId = 0;
922
- this._creator = appIdentifier.creatorAddress;
1029
+ this._creator = appIdentifier.creatorAddress?.toString();
923
1030
  if (appIdentifier.findExistingUsing instanceof Indexer) {
924
1031
  this.indexer = appIdentifier.findExistingUsing;
925
1032
  }
@@ -930,7 +1037,7 @@ class ApplicationClient {
930
1037
  this.existingDeployments = appIdentifier.findExistingUsing;
931
1038
  }
932
1039
  }
933
- this._appAddress = algosdk.getApplicationAddress(this._appId);
1040
+ this._appAddress = algosdk.getApplicationAddress(this._appId).toString();
934
1041
  this.sender = sender;
935
1042
  this.params = params;
936
1043
  }
@@ -955,7 +1062,7 @@ class ApplicationClient {
955
1062
  const clearCompiled = await app.compileTeal(clear, this.algod);
956
1063
  this._clearSourceMap = clearCompiled?.sourceMap;
957
1064
  if (config.Config.debug) {
958
- await config.Config.events.emitAsync(types_asyncEventEmitter.EventType.AppCompiled, {
1065
+ await config.Config.events.emitAsync(types_lifecycleEvents.EventType.AppCompiled, {
959
1066
  sources: [
960
1067
  { compiledTeal: approvalCompiled, appName: this._appName, fileName: 'approval' },
961
1068
  { compiledTeal: clearCompiled, appName: this._appName, fileName: 'clear' },
@@ -1110,12 +1217,12 @@ class ApplicationClient {
1110
1217
  if (result.confirmation) {
1111
1218
  // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
1112
1219
  this._appId = result.confirmation.applicationIndex;
1113
- this._appAddress = getApplicationAddress(this._appId);
1220
+ this._appAddress = getApplicationAddress(this._appId).toString();
1114
1221
  }
1115
1222
  return { ...result, ...{ compiledApproval: approvalCompiled, compiledClear: clearCompiled } };
1116
1223
  }
1117
1224
  catch (e) {
1118
- throw this.exposeLogicError(e);
1225
+ throw await this.exposeLogicError(e);
1119
1226
  }
1120
1227
  }
1121
1228
  /**
@@ -1149,7 +1256,7 @@ class ApplicationClient {
1149
1256
  return { ...result, ...{ compiledApproval: approvalCompiled, compiledClear: clearCompiled } };
1150
1257
  }
1151
1258
  catch (e) {
1152
- throw this.exposeLogicError(e);
1259
+ throw await this.exposeLogicError(e);
1153
1260
  }
1154
1261
  }
1155
1262
  /**
@@ -1475,7 +1582,7 @@ class ApplicationClient {
1475
1582
  if (!app) {
1476
1583
  return {
1477
1584
  appId: 0,
1478
- appAddress: getApplicationAddress(0),
1585
+ appAddress: getApplicationAddress(0).toString(),
1479
1586
  };
1480
1587
  }
1481
1588
  return app;
@@ -1502,7 +1609,7 @@ class ApplicationClient {
1502
1609
  .toString()
1503
1610
  .split('\n'),
1504
1611
  // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
1505
- isClear ? this._clearSourceMap : this._approvalSourceMap);
1612
+ (pc) => (isClear ? this._clearSourceMap : this._approvalSourceMap)?.getLocationForPc(pc)?.line);
1506
1613
  else
1507
1614
  return e;
1508
1615
  }