@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
package/types/app-spec.js CHANGED
@@ -1,139 +1,129 @@
1
- 'use strict';
2
-
3
- var algosdk = require('algosdk');
4
-
5
- var ABIMethod = algosdk.ABIMethod;
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
+ const require_runtime = require("../_virtual/_rolldown/runtime.js");
3
+ let algosdk = require("algosdk");
4
+ algosdk = require_runtime.__toESM(algosdk);
5
+ //#region src/types/app-spec.ts
6
+ var ABIMethod = algosdk.default.ABIMethod;
6
7
  /**
7
- * Converts an ARC-32 Application Specification to an ARC-56 Contract
8
- * @param appSpec The ARC-32 Application Specification
9
- * @returns The ARC-56 Contract
10
- * @example
11
- * ```typescript
12
- * const arc56AppSpec = arc32ToArc56(arc32AppSpec)
13
- * ```
14
- */
8
+ * Converts an ARC-32 Application Specification to an ARC-56 Contract
9
+ * @param appSpec The ARC-32 Application Specification
10
+ * @returns The ARC-56 Contract
11
+ * @example
12
+ * ```typescript
13
+ * const arc56AppSpec = arc32ToArc56(arc32AppSpec)
14
+ * ```
15
+ */
15
16
  function arc32ToArc56(appSpec) {
16
- const arc32Structs = Object.values(appSpec.hints).flatMap((hint) => Object.entries(hint.structs ?? {}));
17
- const structs = Object.fromEntries(arc32Structs.map(([_, struct]) => {
18
- const fields = struct.elements.map((e) => ({ name: e[0], type: e[1] }));
19
- return [struct.name, fields];
20
- }));
21
- const hint = (m) => appSpec.hints[new ABIMethod(m).getSignature()];
22
- const actions = (m, type) => {
23
- // eslint-disable-next-line @typescript-eslint/no-non-null-asserted-optional-chain
24
- return hint(m)?.call_config !== undefined ? callConfigToActions(hint(m)?.call_config, type) : [];
25
- };
26
- const bareActions = (type) => {
27
- return callConfigToActions(appSpec.bare_call_config, type);
28
- };
29
- const callConfigToActions = (c, type) => {
30
- const actions = [];
31
- if (c.close_out && ['ALL', type].includes(c.close_out))
32
- actions.push('CloseOut');
33
- if (c.delete_application && ['ALL', type].includes(c.delete_application))
34
- actions.push('DeleteApplication');
35
- if (c.no_op && ['ALL', type].includes(c.no_op))
36
- actions.push('NoOp');
37
- if (c.opt_in && ['ALL', type].includes(c.opt_in))
38
- actions.push('OptIn');
39
- if (c.update_application && ['ALL', type].includes(c.update_application))
40
- actions.push('UpdateApplication');
41
- return actions;
42
- };
43
- const getDefaultArgValue = (type, defaultArg) => {
44
- if (!defaultArg)
45
- return undefined;
46
- if (defaultArg.source === 'abi-method') {
47
- return {
48
- source: 'method',
49
- data: defaultArg.data.name,
50
- };
51
- }
52
- return {
53
- source: defaultArg.source === 'constant' ? 'literal' : defaultArg.source === 'global-state' ? 'global' : 'local',
54
- data: Buffer.from(typeof defaultArg.data === 'number' ? algosdk.ABIType.from('uint64').encode(defaultArg.data) : defaultArg.data).toString('base64'),
55
- type: type === 'string' ? 'AVMString' : type,
56
- };
57
- };
58
- return {
59
- arcs: [],
60
- name: appSpec.contract.name,
61
- desc: appSpec.contract.desc,
62
- structs: structs,
63
- methods: appSpec.contract.methods.map((m) => ({
64
- name: m.name,
65
- desc: m.desc,
66
- args: m.args.map((a) => ({
67
- name: a.name,
68
- type: a.type,
69
- desc: a.desc,
70
- struct: a.name ? hint(m)?.structs?.[a.name]?.name : undefined,
71
- defaultValue: getDefaultArgValue(a.type, !a.name ? undefined : hint(m)?.default_arguments?.[a.name]),
72
- })),
73
- returns: {
74
- type: m.returns.type,
75
- desc: m.returns.desc,
76
- struct: hint(m)?.structs?.output?.name,
77
- },
78
- events: [],
79
- readonly: hint(m)?.read_only,
80
- actions: {
81
- create: actions(m, 'CREATE'),
82
- call: actions(m, 'CALL'),
83
- },
84
- })),
85
- state: {
86
- schema: {
87
- global: {
88
- ints: appSpec.state.global.num_uints,
89
- bytes: appSpec.state.global.num_byte_slices,
90
- },
91
- local: {
92
- ints: appSpec.state.local.num_uints,
93
- bytes: appSpec.state.local.num_byte_slices,
94
- },
95
- },
96
- keys: {
97
- global: Object.fromEntries(Object.entries(appSpec.schema.global.declared).map((s) => [
98
- s[0],
99
- {
100
- key: Buffer.from(s[1].key, 'utf-8').toString('base64'),
101
- keyType: 'AVMString',
102
- valueType: s[1].type === 'uint64' ? 'AVMUint64' : 'AVMBytes',
103
- desc: s[1].descr,
104
- },
105
- ])),
106
- local: Object.fromEntries(Object.entries(appSpec.schema.local.declared).map((s) => [
107
- s[0],
108
- {
109
- key: Buffer.from(s[1].key, 'utf-8').toString('base64'),
110
- keyType: 'AVMString',
111
- valueType: s[1].type === 'uint64' ? 'AVMUint64' : 'AVMBytes',
112
- desc: s[1].descr,
113
- },
114
- ])),
115
- box: {},
116
- },
117
- maps: {
118
- global: {},
119
- local: {},
120
- box: {},
121
- },
122
- },
123
- source: appSpec.source,
124
- bareActions: {
125
- create: bareActions('CREATE'),
126
- call: bareActions('CALL'),
127
- },
128
- byteCode: undefined,
129
- compilerInfo: undefined,
130
- events: undefined,
131
- networks: undefined,
132
- scratchVariables: undefined,
133
- sourceInfo: undefined,
134
- templateVariables: undefined,
135
- };
17
+ const arc32Structs = Object.values(appSpec.hints).flatMap((hint) => Object.entries(hint.structs ?? {}));
18
+ const structs = Object.fromEntries(arc32Structs.map(([_, struct]) => {
19
+ const fields = struct.elements.map((e) => ({
20
+ name: e[0],
21
+ type: e[1]
22
+ }));
23
+ return [struct.name, fields];
24
+ }));
25
+ const hint = (m) => appSpec.hints[new ABIMethod(m).getSignature()];
26
+ const actions = (m, type) => {
27
+ return hint(m)?.call_config !== void 0 ? callConfigToActions(hint(m)?.call_config, type) : [];
28
+ };
29
+ const bareActions = (type) => {
30
+ return callConfigToActions(appSpec.bare_call_config, type);
31
+ };
32
+ const callConfigToActions = (c, type) => {
33
+ const actions = [];
34
+ if (c.close_out && ["ALL", type].includes(c.close_out)) actions.push("CloseOut");
35
+ if (c.delete_application && ["ALL", type].includes(c.delete_application)) actions.push("DeleteApplication");
36
+ if (c.no_op && ["ALL", type].includes(c.no_op)) actions.push("NoOp");
37
+ if (c.opt_in && ["ALL", type].includes(c.opt_in)) actions.push("OptIn");
38
+ if (c.update_application && ["ALL", type].includes(c.update_application)) actions.push("UpdateApplication");
39
+ return actions;
40
+ };
41
+ const getDefaultArgValue = (type, defaultArg) => {
42
+ if (!defaultArg) return void 0;
43
+ if (defaultArg.source === "abi-method") return {
44
+ source: "method",
45
+ data: defaultArg.data.name
46
+ };
47
+ return {
48
+ source: defaultArg.source === "constant" ? "literal" : defaultArg.source === "global-state" ? "global" : "local",
49
+ data: Buffer.from(typeof defaultArg.data === "number" ? algosdk.default.ABIType.from("uint64").encode(defaultArg.data) : defaultArg.data).toString("base64"),
50
+ type: type === "string" ? "AVMString" : type
51
+ };
52
+ };
53
+ return {
54
+ arcs: [],
55
+ name: appSpec.contract.name,
56
+ desc: appSpec.contract.desc,
57
+ structs,
58
+ methods: appSpec.contract.methods.map((m) => ({
59
+ name: m.name,
60
+ desc: m.desc,
61
+ args: m.args.map((a) => ({
62
+ name: a.name,
63
+ type: a.type,
64
+ desc: a.desc,
65
+ struct: a.name ? hint(m)?.structs?.[a.name]?.name : void 0,
66
+ defaultValue: getDefaultArgValue(a.type, !a.name ? void 0 : hint(m)?.default_arguments?.[a.name])
67
+ })),
68
+ returns: {
69
+ type: m.returns.type,
70
+ desc: m.returns.desc,
71
+ struct: hint(m)?.structs?.output?.name
72
+ },
73
+ events: [],
74
+ readonly: hint(m)?.read_only,
75
+ actions: {
76
+ create: actions(m, "CREATE"),
77
+ call: actions(m, "CALL")
78
+ }
79
+ })),
80
+ state: {
81
+ schema: {
82
+ global: {
83
+ ints: appSpec.state.global.num_uints,
84
+ bytes: appSpec.state.global.num_byte_slices
85
+ },
86
+ local: {
87
+ ints: appSpec.state.local.num_uints,
88
+ bytes: appSpec.state.local.num_byte_slices
89
+ }
90
+ },
91
+ keys: {
92
+ global: Object.fromEntries(Object.entries(appSpec.schema.global.declared).map((s) => [s[0], {
93
+ key: Buffer.from(s[1].key, "utf-8").toString("base64"),
94
+ keyType: "AVMString",
95
+ valueType: s[1].type === "uint64" ? "AVMUint64" : "AVMBytes",
96
+ desc: s[1].descr
97
+ }])),
98
+ local: Object.fromEntries(Object.entries(appSpec.schema.local.declared).map((s) => [s[0], {
99
+ key: Buffer.from(s[1].key, "utf-8").toString("base64"),
100
+ keyType: "AVMString",
101
+ valueType: s[1].type === "uint64" ? "AVMUint64" : "AVMBytes",
102
+ desc: s[1].descr
103
+ }])),
104
+ box: {}
105
+ },
106
+ maps: {
107
+ global: {},
108
+ local: {},
109
+ box: {}
110
+ }
111
+ },
112
+ source: appSpec.source,
113
+ bareActions: {
114
+ create: bareActions("CREATE"),
115
+ call: bareActions("CALL")
116
+ },
117
+ byteCode: void 0,
118
+ compilerInfo: void 0,
119
+ events: void 0,
120
+ networks: void 0,
121
+ scratchVariables: void 0,
122
+ sourceInfo: void 0,
123
+ templateVariables: void 0
124
+ };
136
125
  }
137
-
126
+ //#endregion
138
127
  exports.arc32ToArc56 = arc32ToArc56;
139
- //# sourceMappingURL=app-spec.js.map
128
+
129
+ //# sourceMappingURL=app-spec.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"app-spec.js","sources":["../../src/types/app-spec.ts"],"sourcesContent":["import algosdk from 'algosdk'\nimport { Arc56Contract, Method as Arc56Method, StorageKey, StructField } from './app-arc56'\nimport ABIContractParams = algosdk.ABIContractParams\nimport ABIMethodParams = algosdk.ABIMethodParams\nimport ABIMethod = algosdk.ABIMethod\n\n/**\n * Converts an ARC-32 Application Specification to an ARC-56 Contract\n * @param appSpec The ARC-32 Application Specification\n * @returns The ARC-56 Contract\n * @example\n * ```typescript\n * const arc56AppSpec = arc32ToArc56(arc32AppSpec)\n * ```\n */\nexport function arc32ToArc56(appSpec: AppSpec): Arc56Contract {\n const arc32Structs = Object.values(appSpec.hints).flatMap((hint) => Object.entries(hint.structs ?? {}))\n const structs = Object.fromEntries(\n arc32Structs.map(([_, struct]) => {\n const fields = struct.elements.map((e) => ({ name: e[0], type: e[1] }))\n return [struct.name, fields]\n }),\n ) satisfies { [structName: string]: StructField[] }\n const hint = (m: ABIMethodParams) => appSpec.hints[new ABIMethod(m).getSignature()] as Hint | undefined\n const actions = (m: ABIMethodParams, type: 'CREATE' | 'CALL') => {\n // eslint-disable-next-line @typescript-eslint/no-non-null-asserted-optional-chain\n return hint(m)?.call_config !== undefined ? callConfigToActions(hint(m)?.call_config!, type) : []\n }\n const bareActions = (type: 'CREATE' | 'CALL') => {\n return callConfigToActions(appSpec.bare_call_config, type)\n }\n const callConfigToActions = (c: CallConfig, type: 'CREATE' | 'CALL') => {\n const actions: ('NoOp' | 'OptIn' | 'CloseOut' | 'ClearState' | 'UpdateApplication' | 'DeleteApplication')[] = []\n if (c.close_out && ['ALL', type].includes(c.close_out)) actions.push('CloseOut')\n if (c.delete_application && ['ALL', type].includes(c.delete_application)) actions.push('DeleteApplication')\n if (c.no_op && ['ALL', type].includes(c.no_op)) actions.push('NoOp')\n if (c.opt_in && ['ALL', type].includes(c.opt_in)) actions.push('OptIn')\n if (c.update_application && ['ALL', type].includes(c.update_application)) actions.push('UpdateApplication')\n return actions\n }\n const getDefaultArgValue = (\n type: string,\n defaultArg: DefaultArgument | undefined,\n ): Arc56Contract['methods'][0]['args'][0]['defaultValue'] => {\n if (!defaultArg) return undefined\n\n if (defaultArg.source === 'abi-method') {\n return {\n source: 'method',\n data: defaultArg.data.name,\n }\n }\n\n return {\n source: defaultArg.source === 'constant' ? 'literal' : defaultArg.source === 'global-state' ? 'global' : 'local',\n data: Buffer.from(\n typeof defaultArg.data === 'number' ? algosdk.ABIType.from('uint64').encode(defaultArg.data) : defaultArg.data,\n ).toString('base64'),\n type: type === 'string' ? 'AVMString' : type,\n }\n }\n\n return {\n arcs: [],\n name: appSpec.contract.name,\n desc: appSpec.contract.desc,\n structs: structs,\n methods: appSpec.contract.methods.map(\n (m) =>\n ({\n name: m.name,\n desc: m.desc,\n args: m.args.map((a) => ({\n name: a.name,\n type: a.type,\n desc: a.desc,\n struct: a.name ? hint(m)?.structs?.[a.name]?.name : undefined,\n defaultValue: getDefaultArgValue(a.type, !a.name ? undefined : hint(m)?.default_arguments?.[a.name]),\n })),\n returns: {\n type: m.returns.type,\n desc: m.returns.desc,\n struct: hint(m)?.structs?.output?.name,\n },\n events: [],\n readonly: hint(m)?.read_only,\n actions: {\n create: actions(m, 'CREATE') as Arc56Method['actions']['create'],\n call: actions(m, 'CALL'),\n },\n }) satisfies Arc56Method,\n ),\n state: {\n schema: {\n global: {\n ints: appSpec.state.global.num_uints,\n bytes: appSpec.state.global.num_byte_slices,\n },\n local: {\n ints: appSpec.state.local.num_uints,\n bytes: appSpec.state.local.num_byte_slices,\n },\n },\n keys: {\n global: Object.fromEntries(\n Object.entries(appSpec.schema.global.declared).map((s) => [\n s[0],\n {\n key: Buffer.from(s[1].key, 'utf-8').toString('base64'),\n keyType: 'AVMString',\n valueType: s[1].type === 'uint64' ? 'AVMUint64' : 'AVMBytes',\n desc: s[1].descr,\n } satisfies StorageKey,\n ]),\n ),\n local: Object.fromEntries(\n Object.entries(appSpec.schema.local.declared).map((s) => [\n s[0],\n {\n key: Buffer.from(s[1].key, 'utf-8').toString('base64'),\n keyType: 'AVMString',\n valueType: s[1].type === 'uint64' ? 'AVMUint64' : 'AVMBytes',\n desc: s[1].descr,\n } satisfies StorageKey,\n ]),\n ),\n box: {},\n },\n maps: {\n global: {},\n local: {},\n box: {},\n },\n },\n source: appSpec.source,\n bareActions: {\n create: bareActions('CREATE') as unknown as Arc56Contract['bareActions']['create'],\n call: bareActions('CALL'),\n },\n byteCode: undefined,\n compilerInfo: undefined,\n events: undefined,\n networks: undefined,\n scratchVariables: undefined,\n sourceInfo: undefined,\n templateVariables: undefined,\n } satisfies Arc56Contract\n}\n\n/** An ARC-0032 Application Specification see https://github.com/algorandfoundation/ARCs/pull/150 */\nexport interface AppSpec {\n /** Method call hints */\n hints: HintSpec\n /** The TEAL source */\n source: AppSources\n /** The ABI-0004 contract definition see https://github.com/algorandfoundation/ARCs/blob/main/ARCs/arc-0004.md */\n contract: ABIContractParams\n /** The values that make up the local and global state */\n schema: SchemaSpec\n /** The rolled-up schema allocation values for local and global state */\n state: StateSchemaSpec\n /** The config of all BARE calls (i.e. non ABI calls with no args) */\n bare_call_config: CallConfig\n}\n\n/** A lookup of encoded method call spec to hint */\nexport type HintSpec = Record<string, Hint>\n\n/** The TEAL source of a contract */\nexport interface AppSources {\n /** The TEAL source of the approval program */\n approval: string\n /** The TEAL source of the clear program */\n clear: string\n}\n\n/** The various call configs:\n * * `NEVER`: Will not be called\n * * `CALL`: Can be called during a non-create call i.e. app id != 0\n * * `CREATE`: Can be called during a create call i.e. app id = 0\n * * `ALL`: Can be during a create OR non-create call\n **/\nexport type CallConfigValue = 'NEVER' | 'CALL' | 'CREATE' | 'ALL'\n\n/** Call configuration for a method */\nexport interface CallConfig {\n /** NoOp call config */\n no_op?: CallConfigValue\n /** Opt-in call config */\n opt_in?: CallConfigValue\n /** Close out call config */\n close_out?: CallConfigValue\n /** Update call config */\n update_application?: CallConfigValue\n /** Delete call config */\n delete_application?: CallConfigValue\n}\n\n/** Hint information for a given method call to allow client generation */\nexport interface Hint {\n /** Any user-defined struct/tuple types used in the method call, keyed by parameter name or `output` for return type */\n structs?: Record<string, Struct>\n read_only?: boolean\n default_arguments?: Record<string, DefaultArgument>\n call_config: CallConfig\n}\n\n/** The name of a field */\nexport type FieldName = string\n\n/** The string name of an ABI type */\nexport type ABIType = string\n\n/** The elements of the struct/tuple: `FieldName`, `ABIType` */\nexport type StructElement = [FieldName, ABIType]\n\n/** A user-defined struct/tuple type */\nexport interface Struct {\n /** The name of the type */\n name: string\n /** The elements (in order) that make up the struct/tuple */\n elements: StructElement[]\n}\n\n/**\n * Defines a strategy for obtaining a default value for a given ABI arg.\n */\nexport type DefaultArgument =\n | {\n /**\n * The default value should be fetched by invoking an ABI method\n */\n source: 'abi-method'\n data: ABIMethodParams\n }\n | {\n /**\n * The default value should be fetched from global state\n */\n source: 'global-state'\n /**\n * The key of the state variable\n */\n data: string\n }\n | {\n /**\n * The default value should be fetched from the local state of the sender user\n */\n source: 'local-state'\n /**\n * The key of the state variable\n */\n data: string\n }\n | {\n /**\n * The default value is a constant.\n */\n source: 'constant'\n /**\n * The static default value to use.\n */\n data: string | number\n }\n\n/** AVM data type */\nexport type AVMType = 'uint64' | 'bytes'\n\n/** Declared schema value specification */\nexport interface DeclaredSchemaValueSpec {\n /** The type of value */\n type: AVMType\n /** The name of the key */\n key: string\n /** A description of the variable */\n descr?: string\n /** Whether or not the value is set statically (at create time only) or dynamically */\n static?: boolean\n}\n\n/** Reserved schema value specification */\nexport interface ReservedSchemaValueSpec {\n /** The type of value */\n type: AVMType\n /** The description of the reserved storage space */\n descr: string\n /** The maximum number of slots to reserve */\n max_keys: number\n}\n\n/** The schema for global and local storage */\nexport interface SchemaSpec {\n /** The local storage schema */\n local: Schema\n /** The global storage schema */\n global: Schema\n}\n\n/** The storage schema definition */\nexport interface Schema {\n /** Declared storage schema */\n declared: Record<string, DeclaredSchemaValueSpec>\n /** Reserved storage schema */\n reserved: Record<string, ReservedSchemaValueSpec>\n}\n\n/** The rolled-up schema allocation specification for local and global state */\nexport interface StateSchemaSpec {\n /** Global storage spec */\n global: StateSchema\n /** Local storage spec */\n local: StateSchema\n}\n\n/** Schema spec summary for global or local storage */\nexport type StateSchema = {\n /** Number of uint slots */\n num_uints: number\n /** Number of byte slots */\n num_byte_slices: number\n}\n"],"names":[],"mappings":";;;;AAIA,IAAO,SAAS,GAAG,OAAO,CAAC,SAAS;AAEpC;;;;;;;;AAQG;AACG,SAAU,YAAY,CAAC,OAAgB,EAAA;AAC3C,IAAA,MAAM,YAAY,GAAG,MAAM,CAAC,MAAM,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,OAAO,CAAC,CAAC,IAAI,KAAK,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC,OAAO,IAAI,EAAE,CAAC,CAAC;AACvG,IAAA,MAAM,OAAO,GAAG,MAAM,CAAC,WAAW,CAChC,YAAY,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,EAAE,MAAM,CAAC,KAAI;AAC/B,QAAA,MAAM,MAAM,GAAG,MAAM,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,CAAC,MAAM,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC,CAAC,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC;AACvE,QAAA,OAAO,CAAC,MAAM,CAAC,IAAI,EAAE,MAAM,CAAC;KAC7B,CAAC,CAC+C;IACnD,MAAM,IAAI,GAAG,CAAC,CAAkB,KAAK,OAAO,CAAC,KAAK,CAAC,IAAI,SAAS,CAAC,CAAC,CAAC,CAAC,YAAY,EAAE,CAAqB;AACvG,IAAA,MAAM,OAAO,GAAG,CAAC,CAAkB,EAAE,IAAuB,KAAI;;QAE9D,OAAO,IAAI,CAAC,CAAC,CAAC,EAAE,WAAW,KAAK,SAAS,GAAG,mBAAmB,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,WAAY,EAAE,IAAI,CAAC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R,aAAA;AACF,SAAA;QACD,MAAM,EAAE,OAAO,CAAC,MAAM;AACtB,QAAA,WAAW,EAAE;AACX,YAAA,MAAM,EAAE,WAAW,CAAC,QAAQ,CAAsD;AAClF,YAAA,IAAI,EAAE,WAAW,CAAC,MAAM,CAAC;AAC1B,SAAA;AACD,QAAA,QAAQ,EAAE,SAAS;AACnB,QAAA,YAAY,EAAE,SAAS;AACvB,QAAA,MAAM,EAAE,SAAS;AACjB,QAAA,QAAQ,EAAE,SAAS;AACnB,QAAA,gBAAgB,EAAE,SAAS;AAC3B,QAAA,UAAU,EAAE,SAAS;AACrB,QAAA,iBAAiB,EAAE,SAAS;KACL;AAC3B;;;;"}
1
+ {"version":3,"file":"app-spec.js","names":[],"sources":["../../src/types/app-spec.ts"],"sourcesContent":["import algosdk from 'algosdk'\nimport { Arc56Contract, Method as Arc56Method, StorageKey, StructField } from './app-arc56'\nimport ABIContractParams = algosdk.ABIContractParams\nimport ABIMethodParams = algosdk.ABIMethodParams\nimport ABIMethod = algosdk.ABIMethod\n\n/**\n * Converts an ARC-32 Application Specification to an ARC-56 Contract\n * @param appSpec The ARC-32 Application Specification\n * @returns The ARC-56 Contract\n * @example\n * ```typescript\n * const arc56AppSpec = arc32ToArc56(arc32AppSpec)\n * ```\n */\nexport function arc32ToArc56(appSpec: AppSpec): Arc56Contract {\n const arc32Structs = Object.values(appSpec.hints).flatMap((hint) => Object.entries(hint.structs ?? {}))\n const structs = Object.fromEntries(\n arc32Structs.map(([_, struct]) => {\n const fields = struct.elements.map((e) => ({ name: e[0], type: e[1] }))\n return [struct.name, fields]\n }),\n ) satisfies { [structName: string]: StructField[] }\n const hint = (m: ABIMethodParams) => appSpec.hints[new ABIMethod(m).getSignature()] as Hint | undefined\n const actions = (m: ABIMethodParams, type: 'CREATE' | 'CALL') => {\n // eslint-disable-next-line @typescript-eslint/no-non-null-asserted-optional-chain\n return hint(m)?.call_config !== undefined ? callConfigToActions(hint(m)?.call_config!, type) : []\n }\n const bareActions = (type: 'CREATE' | 'CALL') => {\n return callConfigToActions(appSpec.bare_call_config, type)\n }\n const callConfigToActions = (c: CallConfig, type: 'CREATE' | 'CALL') => {\n const actions: ('NoOp' | 'OptIn' | 'CloseOut' | 'ClearState' | 'UpdateApplication' | 'DeleteApplication')[] = []\n if (c.close_out && ['ALL', type].includes(c.close_out)) actions.push('CloseOut')\n if (c.delete_application && ['ALL', type].includes(c.delete_application)) actions.push('DeleteApplication')\n if (c.no_op && ['ALL', type].includes(c.no_op)) actions.push('NoOp')\n if (c.opt_in && ['ALL', type].includes(c.opt_in)) actions.push('OptIn')\n if (c.update_application && ['ALL', type].includes(c.update_application)) actions.push('UpdateApplication')\n return actions\n }\n const getDefaultArgValue = (\n type: string,\n defaultArg: DefaultArgument | undefined,\n ): Arc56Contract['methods'][0]['args'][0]['defaultValue'] => {\n if (!defaultArg) return undefined\n\n if (defaultArg.source === 'abi-method') {\n return {\n source: 'method',\n data: defaultArg.data.name,\n }\n }\n\n return {\n source: defaultArg.source === 'constant' ? 'literal' : defaultArg.source === 'global-state' ? 'global' : 'local',\n data: Buffer.from(\n typeof defaultArg.data === 'number' ? algosdk.ABIType.from('uint64').encode(defaultArg.data) : defaultArg.data,\n ).toString('base64'),\n type: type === 'string' ? 'AVMString' : type,\n }\n }\n\n return {\n arcs: [],\n name: appSpec.contract.name,\n desc: appSpec.contract.desc,\n structs: structs,\n methods: appSpec.contract.methods.map(\n (m) =>\n ({\n name: m.name,\n desc: m.desc,\n args: m.args.map((a) => ({\n name: a.name,\n type: a.type,\n desc: a.desc,\n struct: a.name ? hint(m)?.structs?.[a.name]?.name : undefined,\n defaultValue: getDefaultArgValue(a.type, !a.name ? undefined : hint(m)?.default_arguments?.[a.name]),\n })),\n returns: {\n type: m.returns.type,\n desc: m.returns.desc,\n struct: hint(m)?.structs?.output?.name,\n },\n events: [],\n readonly: hint(m)?.read_only,\n actions: {\n create: actions(m, 'CREATE') as Arc56Method['actions']['create'],\n call: actions(m, 'CALL'),\n },\n }) satisfies Arc56Method,\n ),\n state: {\n schema: {\n global: {\n ints: appSpec.state.global.num_uints,\n bytes: appSpec.state.global.num_byte_slices,\n },\n local: {\n ints: appSpec.state.local.num_uints,\n bytes: appSpec.state.local.num_byte_slices,\n },\n },\n keys: {\n global: Object.fromEntries(\n Object.entries(appSpec.schema.global.declared).map((s) => [\n s[0],\n {\n key: Buffer.from(s[1].key, 'utf-8').toString('base64'),\n keyType: 'AVMString',\n valueType: s[1].type === 'uint64' ? 'AVMUint64' : 'AVMBytes',\n desc: s[1].descr,\n } satisfies StorageKey,\n ]),\n ),\n local: Object.fromEntries(\n Object.entries(appSpec.schema.local.declared).map((s) => [\n s[0],\n {\n key: Buffer.from(s[1].key, 'utf-8').toString('base64'),\n keyType: 'AVMString',\n valueType: s[1].type === 'uint64' ? 'AVMUint64' : 'AVMBytes',\n desc: s[1].descr,\n } satisfies StorageKey,\n ]),\n ),\n box: {},\n },\n maps: {\n global: {},\n local: {},\n box: {},\n },\n },\n source: appSpec.source,\n bareActions: {\n create: bareActions('CREATE') as unknown as Arc56Contract['bareActions']['create'],\n call: bareActions('CALL'),\n },\n byteCode: undefined,\n compilerInfo: undefined,\n events: undefined,\n networks: undefined,\n scratchVariables: undefined,\n sourceInfo: undefined,\n templateVariables: undefined,\n } satisfies Arc56Contract\n}\n\n/** An ARC-0032 Application Specification see https://github.com/algorandfoundation/ARCs/pull/150 */\nexport interface AppSpec {\n /** Method call hints */\n hints: HintSpec\n /** The TEAL source */\n source: AppSources\n /** The ABI-0004 contract definition see https://github.com/algorandfoundation/ARCs/blob/main/ARCs/arc-0004.md */\n contract: ABIContractParams\n /** The values that make up the local and global state */\n schema: SchemaSpec\n /** The rolled-up schema allocation values for local and global state */\n state: StateSchemaSpec\n /** The config of all BARE calls (i.e. non ABI calls with no args) */\n bare_call_config: CallConfig\n}\n\n/** A lookup of encoded method call spec to hint */\nexport type HintSpec = Record<string, Hint>\n\n/** The TEAL source of a contract */\nexport interface AppSources {\n /** The TEAL source of the approval program */\n approval: string\n /** The TEAL source of the clear program */\n clear: string\n}\n\n/** The various call configs:\n * * `NEVER`: Will not be called\n * * `CALL`: Can be called during a non-create call i.e. app id != 0\n * * `CREATE`: Can be called during a create call i.e. app id = 0\n * * `ALL`: Can be during a create OR non-create call\n **/\nexport type CallConfigValue = 'NEVER' | 'CALL' | 'CREATE' | 'ALL'\n\n/** Call configuration for a method */\nexport interface CallConfig {\n /** NoOp call config */\n no_op?: CallConfigValue\n /** Opt-in call config */\n opt_in?: CallConfigValue\n /** Close out call config */\n close_out?: CallConfigValue\n /** Update call config */\n update_application?: CallConfigValue\n /** Delete call config */\n delete_application?: CallConfigValue\n}\n\n/** Hint information for a given method call to allow client generation */\nexport interface Hint {\n /** Any user-defined struct/tuple types used in the method call, keyed by parameter name or `output` for return type */\n structs?: Record<string, Struct>\n read_only?: boolean\n default_arguments?: Record<string, DefaultArgument>\n call_config: CallConfig\n}\n\n/** The name of a field */\nexport type FieldName = string\n\n/** The string name of an ABI type */\nexport type ABIType = string\n\n/** The elements of the struct/tuple: `FieldName`, `ABIType` */\nexport type StructElement = [FieldName, ABIType]\n\n/** A user-defined struct/tuple type */\nexport interface Struct {\n /** The name of the type */\n name: string\n /** The elements (in order) that make up the struct/tuple */\n elements: StructElement[]\n}\n\n/**\n * Defines a strategy for obtaining a default value for a given ABI arg.\n */\nexport type DefaultArgument =\n | {\n /**\n * The default value should be fetched by invoking an ABI method\n */\n source: 'abi-method'\n data: ABIMethodParams\n }\n | {\n /**\n * The default value should be fetched from global state\n */\n source: 'global-state'\n /**\n * The key of the state variable\n */\n data: string\n }\n | {\n /**\n * The default value should be fetched from the local state of the sender user\n */\n source: 'local-state'\n /**\n * The key of the state variable\n */\n data: string\n }\n | {\n /**\n * The default value is a constant.\n */\n source: 'constant'\n /**\n * The static default value to use.\n */\n data: string | number\n }\n\n/** AVM data type */\nexport type AVMType = 'uint64' | 'bytes'\n\n/** Declared schema value specification */\nexport interface DeclaredSchemaValueSpec {\n /** The type of value */\n type: AVMType\n /** The name of the key */\n key: string\n /** A description of the variable */\n descr?: string\n /** Whether or not the value is set statically (at create time only) or dynamically */\n static?: boolean\n}\n\n/** Reserved schema value specification */\nexport interface ReservedSchemaValueSpec {\n /** The type of value */\n type: AVMType\n /** The description of the reserved storage space */\n descr: string\n /** The maximum number of slots to reserve */\n max_keys: number\n}\n\n/** The schema for global and local storage */\nexport interface SchemaSpec {\n /** The local storage schema */\n local: Schema\n /** The global storage schema */\n global: Schema\n}\n\n/** The storage schema definition */\nexport interface Schema {\n /** Declared storage schema */\n declared: Record<string, DeclaredSchemaValueSpec>\n /** Reserved storage schema */\n reserved: Record<string, ReservedSchemaValueSpec>\n}\n\n/** The rolled-up schema allocation specification for local and global state */\nexport interface StateSchemaSpec {\n /** Global storage spec */\n global: StateSchema\n /** Local storage spec */\n local: StateSchema\n}\n\n/** Schema spec summary for global or local storage */\nexport type StateSchema = {\n /** Number of uint slots */\n num_uints: number\n /** Number of byte slots */\n num_byte_slices: number\n}\n"],"mappings":";;;;;AAIO,IAAA,YAAY,QAAA,QAAQ;;;;;;;;;;AAW3B,SAAgB,aAAa,SAAiC;CAC5D,MAAM,eAAe,OAAO,OAAO,QAAQ,KAAK,CAAC,CAAC,SAAS,SAAS,OAAO,QAAQ,KAAK,WAAW,CAAC,CAAC,CAAC;CACtG,MAAM,UAAU,OAAO,YACrB,aAAa,KAAK,CAAC,GAAG,YAAY;EAChC,MAAM,SAAS,OAAO,SAAS,KAAK,OAAO;GAAE,MAAM,EAAE;GAAI,MAAM,EAAE;EAAG,EAAE;EACtE,OAAO,CAAC,OAAO,MAAM,MAAM;CAC7B,CAAC,CACH;CACA,MAAM,QAAQ,MAAuB,QAAQ,MAAM,IAAI,UAAU,CAAC,CAAC,CAAC,aAAa;CACjF,MAAM,WAAW,GAAoB,SAA4B;EAE/D,OAAO,KAAK,CAAC,CAAC,EAAE,gBAAgB,KAAA,IAAY,oBAAoB,KAAK,CAAC,CAAC,EAAE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O,CAAC,CAAC,SAAS,QAAQ;KACrD,SAAS;KACT,WAAW,EAAE,EAAE,CAAC,SAAS,WAAW,cAAc;KAClD,MAAM,EAAE,EAAE,CAAC;IACb,CACF,CAAC,CACH;IACA,KAAK,CAAC;GACR;GACA,MAAM;IACJ,QAAQ,CAAC;IACT,OAAO,CAAC;IACR,KAAK,CAAC;GACR;EACF;EACA,QAAQ,QAAQ;EAChB,aAAa;GACX,QAAQ,YAAY,QAAQ;GAC5B,MAAM,YAAY,MAAM;EAC1B;EACA,UAAU,KAAA;EACV,cAAc,KAAA;EACd,QAAQ,KAAA;EACR,UAAU,KAAA;EACV,kBAAkB,KAAA;EAClB,YAAY,KAAA;EACZ,mBAAmB,KAAA;CACrB;AACF"}
@@ -1,137 +1,126 @@
1
- import algosdk from 'algosdk';
2
-
1
+ import algosdk from "algosdk";
2
+ //#region src/types/app-spec.ts
3
3
  var ABIMethod = algosdk.ABIMethod;
4
4
  /**
5
- * Converts an ARC-32 Application Specification to an ARC-56 Contract
6
- * @param appSpec The ARC-32 Application Specification
7
- * @returns The ARC-56 Contract
8
- * @example
9
- * ```typescript
10
- * const arc56AppSpec = arc32ToArc56(arc32AppSpec)
11
- * ```
12
- */
5
+ * Converts an ARC-32 Application Specification to an ARC-56 Contract
6
+ * @param appSpec The ARC-32 Application Specification
7
+ * @returns The ARC-56 Contract
8
+ * @example
9
+ * ```typescript
10
+ * const arc56AppSpec = arc32ToArc56(arc32AppSpec)
11
+ * ```
12
+ */
13
13
  function arc32ToArc56(appSpec) {
14
- const arc32Structs = Object.values(appSpec.hints).flatMap((hint) => Object.entries(hint.structs ?? {}));
15
- const structs = Object.fromEntries(arc32Structs.map(([_, struct]) => {
16
- const fields = struct.elements.map((e) => ({ name: e[0], type: e[1] }));
17
- return [struct.name, fields];
18
- }));
19
- const hint = (m) => appSpec.hints[new ABIMethod(m).getSignature()];
20
- const actions = (m, type) => {
21
- // eslint-disable-next-line @typescript-eslint/no-non-null-asserted-optional-chain
22
- return hint(m)?.call_config !== undefined ? callConfigToActions(hint(m)?.call_config, type) : [];
23
- };
24
- const bareActions = (type) => {
25
- return callConfigToActions(appSpec.bare_call_config, type);
26
- };
27
- const callConfigToActions = (c, type) => {
28
- const actions = [];
29
- if (c.close_out && ['ALL', type].includes(c.close_out))
30
- actions.push('CloseOut');
31
- if (c.delete_application && ['ALL', type].includes(c.delete_application))
32
- actions.push('DeleteApplication');
33
- if (c.no_op && ['ALL', type].includes(c.no_op))
34
- actions.push('NoOp');
35
- if (c.opt_in && ['ALL', type].includes(c.opt_in))
36
- actions.push('OptIn');
37
- if (c.update_application && ['ALL', type].includes(c.update_application))
38
- actions.push('UpdateApplication');
39
- return actions;
40
- };
41
- const getDefaultArgValue = (type, defaultArg) => {
42
- if (!defaultArg)
43
- return undefined;
44
- if (defaultArg.source === 'abi-method') {
45
- return {
46
- source: 'method',
47
- data: defaultArg.data.name,
48
- };
49
- }
50
- return {
51
- source: defaultArg.source === 'constant' ? 'literal' : defaultArg.source === 'global-state' ? 'global' : 'local',
52
- data: Buffer.from(typeof defaultArg.data === 'number' ? algosdk.ABIType.from('uint64').encode(defaultArg.data) : defaultArg.data).toString('base64'),
53
- type: type === 'string' ? 'AVMString' : type,
54
- };
55
- };
56
- return {
57
- arcs: [],
58
- name: appSpec.contract.name,
59
- desc: appSpec.contract.desc,
60
- structs: structs,
61
- methods: appSpec.contract.methods.map((m) => ({
62
- name: m.name,
63
- desc: m.desc,
64
- args: m.args.map((a) => ({
65
- name: a.name,
66
- type: a.type,
67
- desc: a.desc,
68
- struct: a.name ? hint(m)?.structs?.[a.name]?.name : undefined,
69
- defaultValue: getDefaultArgValue(a.type, !a.name ? undefined : hint(m)?.default_arguments?.[a.name]),
70
- })),
71
- returns: {
72
- type: m.returns.type,
73
- desc: m.returns.desc,
74
- struct: hint(m)?.structs?.output?.name,
75
- },
76
- events: [],
77
- readonly: hint(m)?.read_only,
78
- actions: {
79
- create: actions(m, 'CREATE'),
80
- call: actions(m, 'CALL'),
81
- },
82
- })),
83
- state: {
84
- schema: {
85
- global: {
86
- ints: appSpec.state.global.num_uints,
87
- bytes: appSpec.state.global.num_byte_slices,
88
- },
89
- local: {
90
- ints: appSpec.state.local.num_uints,
91
- bytes: appSpec.state.local.num_byte_slices,
92
- },
93
- },
94
- keys: {
95
- global: Object.fromEntries(Object.entries(appSpec.schema.global.declared).map((s) => [
96
- s[0],
97
- {
98
- key: Buffer.from(s[1].key, 'utf-8').toString('base64'),
99
- keyType: 'AVMString',
100
- valueType: s[1].type === 'uint64' ? 'AVMUint64' : 'AVMBytes',
101
- desc: s[1].descr,
102
- },
103
- ])),
104
- local: Object.fromEntries(Object.entries(appSpec.schema.local.declared).map((s) => [
105
- s[0],
106
- {
107
- key: Buffer.from(s[1].key, 'utf-8').toString('base64'),
108
- keyType: 'AVMString',
109
- valueType: s[1].type === 'uint64' ? 'AVMUint64' : 'AVMBytes',
110
- desc: s[1].descr,
111
- },
112
- ])),
113
- box: {},
114
- },
115
- maps: {
116
- global: {},
117
- local: {},
118
- box: {},
119
- },
120
- },
121
- source: appSpec.source,
122
- bareActions: {
123
- create: bareActions('CREATE'),
124
- call: bareActions('CALL'),
125
- },
126
- byteCode: undefined,
127
- compilerInfo: undefined,
128
- events: undefined,
129
- networks: undefined,
130
- scratchVariables: undefined,
131
- sourceInfo: undefined,
132
- templateVariables: undefined,
133
- };
14
+ const arc32Structs = Object.values(appSpec.hints).flatMap((hint) => Object.entries(hint.structs ?? {}));
15
+ const structs = Object.fromEntries(arc32Structs.map(([_, struct]) => {
16
+ const fields = struct.elements.map((e) => ({
17
+ name: e[0],
18
+ type: e[1]
19
+ }));
20
+ return [struct.name, fields];
21
+ }));
22
+ const hint = (m) => appSpec.hints[new ABIMethod(m).getSignature()];
23
+ const actions = (m, type) => {
24
+ return hint(m)?.call_config !== void 0 ? callConfigToActions(hint(m)?.call_config, type) : [];
25
+ };
26
+ const bareActions = (type) => {
27
+ return callConfigToActions(appSpec.bare_call_config, type);
28
+ };
29
+ const callConfigToActions = (c, type) => {
30
+ const actions = [];
31
+ if (c.close_out && ["ALL", type].includes(c.close_out)) actions.push("CloseOut");
32
+ if (c.delete_application && ["ALL", type].includes(c.delete_application)) actions.push("DeleteApplication");
33
+ if (c.no_op && ["ALL", type].includes(c.no_op)) actions.push("NoOp");
34
+ if (c.opt_in && ["ALL", type].includes(c.opt_in)) actions.push("OptIn");
35
+ if (c.update_application && ["ALL", type].includes(c.update_application)) actions.push("UpdateApplication");
36
+ return actions;
37
+ };
38
+ const getDefaultArgValue = (type, defaultArg) => {
39
+ if (!defaultArg) return void 0;
40
+ if (defaultArg.source === "abi-method") return {
41
+ source: "method",
42
+ data: defaultArg.data.name
43
+ };
44
+ return {
45
+ source: defaultArg.source === "constant" ? "literal" : defaultArg.source === "global-state" ? "global" : "local",
46
+ data: Buffer.from(typeof defaultArg.data === "number" ? algosdk.ABIType.from("uint64").encode(defaultArg.data) : defaultArg.data).toString("base64"),
47
+ type: type === "string" ? "AVMString" : type
48
+ };
49
+ };
50
+ return {
51
+ arcs: [],
52
+ name: appSpec.contract.name,
53
+ desc: appSpec.contract.desc,
54
+ structs,
55
+ methods: appSpec.contract.methods.map((m) => ({
56
+ name: m.name,
57
+ desc: m.desc,
58
+ args: m.args.map((a) => ({
59
+ name: a.name,
60
+ type: a.type,
61
+ desc: a.desc,
62
+ struct: a.name ? hint(m)?.structs?.[a.name]?.name : void 0,
63
+ defaultValue: getDefaultArgValue(a.type, !a.name ? void 0 : hint(m)?.default_arguments?.[a.name])
64
+ })),
65
+ returns: {
66
+ type: m.returns.type,
67
+ desc: m.returns.desc,
68
+ struct: hint(m)?.structs?.output?.name
69
+ },
70
+ events: [],
71
+ readonly: hint(m)?.read_only,
72
+ actions: {
73
+ create: actions(m, "CREATE"),
74
+ call: actions(m, "CALL")
75
+ }
76
+ })),
77
+ state: {
78
+ schema: {
79
+ global: {
80
+ ints: appSpec.state.global.num_uints,
81
+ bytes: appSpec.state.global.num_byte_slices
82
+ },
83
+ local: {
84
+ ints: appSpec.state.local.num_uints,
85
+ bytes: appSpec.state.local.num_byte_slices
86
+ }
87
+ },
88
+ keys: {
89
+ global: Object.fromEntries(Object.entries(appSpec.schema.global.declared).map((s) => [s[0], {
90
+ key: Buffer.from(s[1].key, "utf-8").toString("base64"),
91
+ keyType: "AVMString",
92
+ valueType: s[1].type === "uint64" ? "AVMUint64" : "AVMBytes",
93
+ desc: s[1].descr
94
+ }])),
95
+ local: Object.fromEntries(Object.entries(appSpec.schema.local.declared).map((s) => [s[0], {
96
+ key: Buffer.from(s[1].key, "utf-8").toString("base64"),
97
+ keyType: "AVMString",
98
+ valueType: s[1].type === "uint64" ? "AVMUint64" : "AVMBytes",
99
+ desc: s[1].descr
100
+ }])),
101
+ box: {}
102
+ },
103
+ maps: {
104
+ global: {},
105
+ local: {},
106
+ box: {}
107
+ }
108
+ },
109
+ source: appSpec.source,
110
+ bareActions: {
111
+ create: bareActions("CREATE"),
112
+ call: bareActions("CALL")
113
+ },
114
+ byteCode: void 0,
115
+ compilerInfo: void 0,
116
+ events: void 0,
117
+ networks: void 0,
118
+ scratchVariables: void 0,
119
+ sourceInfo: void 0,
120
+ templateVariables: void 0
121
+ };
134
122
  }
135
-
123
+ //#endregion
136
124
  export { arc32ToArc56 };
137
- //# sourceMappingURL=app-spec.mjs.map
125
+
126
+ //# sourceMappingURL=app-spec.mjs.map