@algorandfoundation/algokit-utils 10.0.0-alpha.1 → 10.0.0-alpha.10

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 (316) hide show
  1. package/README.md +27 -5
  2. package/_virtual/rolldown_runtime.js +20 -11
  3. package/_virtual/rolldown_runtime.mjs +10 -5
  4. package/algo25/index.d.ts +2 -0
  5. package/algo25/index.js +9 -0
  6. package/algo25/index.mjs +3 -0
  7. package/algod-client/index.d.ts +2 -5
  8. package/package.json +1 -1
  9. package/packages/abi/src/abi-method.d.ts +1 -1
  10. package/packages/abi/src/abi-method.js.map +1 -1
  11. package/packages/abi/src/abi-method.mjs.map +1 -1
  12. package/packages/abi/src/abi-type.d.ts +1 -1
  13. package/packages/abi/src/abi-type.js +2 -1
  14. package/packages/abi/src/abi-type.js.map +1 -1
  15. package/packages/abi/src/abi-type.mjs +2 -1
  16. package/packages/abi/src/abi-type.mjs.map +1 -1
  17. package/packages/abi/src/arc56-contract.js +1 -0
  18. package/packages/abi/src/arc56-contract.js.map +1 -1
  19. package/packages/abi/src/arc56-contract.mjs +1 -0
  20. package/packages/abi/src/arc56-contract.mjs.map +1 -1
  21. package/packages/algo25/src/english.js.map +1 -1
  22. package/packages/algo25/src/english.mjs.map +1 -1
  23. package/packages/algo25/src/index.d.ts +40 -0
  24. package/packages/algo25/src/index.js +44 -0
  25. package/packages/algo25/src/index.js.map +1 -1
  26. package/packages/algo25/src/index.mjs +39 -1
  27. package/packages/algo25/src/index.mjs.map +1 -1
  28. package/packages/algod_client/src/apis/api-service.d.ts +44 -44
  29. package/packages/algod_client/src/apis/api-service.js +153 -153
  30. package/packages/algod_client/src/apis/api-service.js.map +1 -1
  31. package/packages/algod_client/src/apis/api-service.mjs +153 -153
  32. package/packages/algod_client/src/apis/api-service.mjs.map +1 -1
  33. package/packages/algod_client/src/core/api-error.js +3 -1
  34. package/packages/algod_client/src/core/api-error.js.map +1 -1
  35. package/packages/algod_client/src/core/api-error.mjs +3 -1
  36. package/packages/algod_client/src/core/api-error.mjs.map +1 -1
  37. package/packages/algod_client/src/core/model-runtime.js +4 -4
  38. package/packages/algod_client/src/core/model-runtime.js.map +1 -1
  39. package/packages/algod_client/src/core/model-runtime.mjs +6 -6
  40. package/packages/algod_client/src/core/model-runtime.mjs.map +1 -1
  41. package/packages/algod_client/src/models/account-participation.js +4 -4
  42. package/packages/algod_client/src/models/account-participation.js.map +1 -1
  43. package/packages/algod_client/src/models/account-participation.mjs +4 -4
  44. package/packages/algod_client/src/models/account-participation.mjs.map +1 -1
  45. package/packages/algod_client/src/models/application-state-schema.d.ts +2 -2
  46. package/packages/algod_client/src/models/application-state-schema.js +2 -2
  47. package/packages/algod_client/src/models/application-state-schema.js.map +1 -1
  48. package/packages/algod_client/src/models/application-state-schema.mjs +2 -2
  49. package/packages/algod_client/src/models/application-state-schema.mjs.map +1 -1
  50. package/packages/algod_client/src/models/asset-params.js +2 -1
  51. package/packages/algod_client/src/models/asset-params.js.map +1 -1
  52. package/packages/algod_client/src/models/asset-params.mjs +2 -1
  53. package/packages/algod_client/src/models/asset-params.mjs.map +1 -1
  54. package/packages/algod_client/src/models/block-response.js +1 -2
  55. package/packages/algod_client/src/models/block-response.js.map +1 -1
  56. package/packages/algod_client/src/models/block-response.mjs +2 -3
  57. package/packages/algod_client/src/models/block-response.mjs.map +1 -1
  58. package/packages/algod_client/src/models/block.d.ts +49 -29
  59. package/packages/algod_client/src/models/block.js +174 -98
  60. package/packages/algod_client/src/models/block.js.map +1 -1
  61. package/packages/algod_client/src/models/block.mjs +174 -98
  62. package/packages/algod_client/src/models/block.mjs.map +1 -1
  63. package/packages/algod_client/src/models/ledger-state-delta.js +1 -1
  64. package/packages/algod_client/src/models/ledger-state-delta.js.map +1 -1
  65. package/packages/algod_client/src/models/ledger-state-delta.mjs +2 -2
  66. package/packages/algod_client/src/models/ledger-state-delta.mjs.map +1 -1
  67. package/packages/algod_client/src/models/simulate-unnamed-resources-accessed.d.ts +3 -5
  68. package/packages/algod_client/src/models/simulate-unnamed-resources-accessed.js +4 -6
  69. package/packages/algod_client/src/models/simulate-unnamed-resources-accessed.js.map +1 -1
  70. package/packages/algod_client/src/models/simulate-unnamed-resources-accessed.mjs +3 -5
  71. package/packages/algod_client/src/models/simulate-unnamed-resources-accessed.mjs.map +1 -1
  72. package/packages/algod_client/src/models/transaction-parameters-response.js +2 -2
  73. package/packages/algod_client/src/models/transaction-parameters-response.js.map +1 -1
  74. package/packages/algod_client/src/models/transaction-parameters-response.mjs +2 -2
  75. package/packages/algod_client/src/models/transaction-parameters-response.mjs.map +1 -1
  76. package/packages/common/src/address.js +0 -14
  77. package/packages/common/src/address.js.map +1 -1
  78. package/packages/common/src/address.mjs +1 -14
  79. package/packages/common/src/address.mjs.map +1 -1
  80. package/packages/common/src/codecs/composite/map.js +7 -4
  81. package/packages/common/src/codecs/composite/map.js.map +1 -1
  82. package/packages/common/src/codecs/composite/map.mjs +7 -4
  83. package/packages/common/src/codecs/composite/map.mjs.map +1 -1
  84. package/packages/common/src/codecs/composite/record.js +0 -1
  85. package/packages/common/src/codecs/composite/record.js.map +1 -1
  86. package/packages/common/src/codecs/primitives/address.js +0 -1
  87. package/packages/common/src/codecs/primitives/address.js.map +1 -1
  88. package/packages/common/src/codecs/primitives/bytes.js +0 -1
  89. package/packages/common/src/codecs/primitives/bytes.js.map +1 -1
  90. package/packages/common/src/codecs/primitives/fixed-bytes.js +0 -1
  91. package/packages/common/src/codecs/primitives/fixed-bytes.js.map +1 -1
  92. package/packages/common/src/codecs/wire.js +0 -1
  93. package/packages/common/src/codecs/wire.js.map +1 -1
  94. package/packages/common/src/json.mjs +2 -2
  95. package/packages/common/src/json.mjs.map +1 -1
  96. package/packages/common/src/msgpack.js +0 -1
  97. package/packages/common/src/msgpack.js.map +1 -1
  98. package/packages/indexer_client/src/apis/api-service.d.ts +1 -1
  99. package/packages/indexer_client/src/apis/api-service.js +12 -12
  100. package/packages/indexer_client/src/apis/api-service.js.map +1 -1
  101. package/packages/indexer_client/src/apis/api-service.mjs +12 -12
  102. package/packages/indexer_client/src/apis/api-service.mjs.map +1 -1
  103. package/packages/indexer_client/src/core/api-error.js +3 -1
  104. package/packages/indexer_client/src/core/api-error.js.map +1 -1
  105. package/packages/indexer_client/src/core/api-error.mjs +3 -1
  106. package/packages/indexer_client/src/core/api-error.mjs.map +1 -1
  107. package/packages/indexer_client/src/core/model-runtime.js +4 -4
  108. package/packages/indexer_client/src/core/model-runtime.js.map +1 -1
  109. package/packages/indexer_client/src/core/model-runtime.mjs +6 -6
  110. package/packages/indexer_client/src/core/model-runtime.mjs.map +1 -1
  111. package/packages/indexer_client/src/models/account-participation.js +4 -4
  112. package/packages/indexer_client/src/models/account-participation.js.map +1 -1
  113. package/packages/indexer_client/src/models/account-participation.mjs +4 -4
  114. package/packages/indexer_client/src/models/account-participation.mjs.map +1 -1
  115. package/packages/indexer_client/src/models/application-state-schema.d.ts +2 -2
  116. package/packages/indexer_client/src/models/application-state-schema.js +2 -2
  117. package/packages/indexer_client/src/models/application-state-schema.js.map +1 -1
  118. package/packages/indexer_client/src/models/application-state-schema.mjs +2 -2
  119. package/packages/indexer_client/src/models/application-state-schema.mjs.map +1 -1
  120. package/packages/indexer_client/src/models/asset-params.js +2 -1
  121. package/packages/indexer_client/src/models/asset-params.js.map +1 -1
  122. package/packages/indexer_client/src/models/asset-params.mjs +2 -1
  123. package/packages/indexer_client/src/models/asset-params.mjs.map +1 -1
  124. package/packages/indexer_client/src/models/block.js +8 -8
  125. package/packages/indexer_client/src/models/block.js.map +1 -1
  126. package/packages/indexer_client/src/models/block.mjs +8 -8
  127. package/packages/indexer_client/src/models/block.mjs.map +1 -1
  128. package/packages/indexer_client/src/models/eval-delta-key-value.d.ts +1 -1
  129. package/packages/indexer_client/src/models/eval-delta-key-value.js +2 -2
  130. package/packages/indexer_client/src/models/eval-delta-key-value.js.map +1 -1
  131. package/packages/indexer_client/src/models/eval-delta-key-value.mjs +2 -2
  132. package/packages/indexer_client/src/models/eval-delta-key-value.mjs.map +1 -1
  133. package/packages/indexer_client/src/models/eval-delta.d.ts +1 -1
  134. package/packages/indexer_client/src/models/eval-delta.js +2 -2
  135. package/packages/indexer_client/src/models/eval-delta.js.map +1 -1
  136. package/packages/indexer_client/src/models/eval-delta.mjs +2 -2
  137. package/packages/indexer_client/src/models/eval-delta.mjs.map +1 -1
  138. package/packages/indexer_client/src/models/hb-proof-fields.js +6 -6
  139. package/packages/indexer_client/src/models/hb-proof-fields.js.map +1 -1
  140. package/packages/indexer_client/src/models/hb-proof-fields.mjs +6 -6
  141. package/packages/indexer_client/src/models/hb-proof-fields.mjs.map +1 -1
  142. package/packages/indexer_client/src/models/state-proof-verifier.js +2 -2
  143. package/packages/indexer_client/src/models/state-proof-verifier.js.map +1 -1
  144. package/packages/indexer_client/src/models/state-proof-verifier.mjs +2 -2
  145. package/packages/indexer_client/src/models/state-proof-verifier.mjs.map +1 -1
  146. package/packages/indexer_client/src/models/state-schema.d.ts +2 -2
  147. package/packages/indexer_client/src/models/state-schema.js +2 -2
  148. package/packages/indexer_client/src/models/state-schema.js.map +1 -1
  149. package/packages/indexer_client/src/models/state-schema.mjs +2 -2
  150. package/packages/indexer_client/src/models/state-schema.mjs.map +1 -1
  151. package/packages/indexer_client/src/models/teal-key-value.d.ts +1 -1
  152. package/packages/indexer_client/src/models/teal-key-value.js +2 -2
  153. package/packages/indexer_client/src/models/teal-key-value.js.map +1 -1
  154. package/packages/indexer_client/src/models/teal-key-value.mjs +2 -2
  155. package/packages/indexer_client/src/models/teal-key-value.mjs.map +1 -1
  156. package/packages/indexer_client/src/models/transaction-heartbeat.js +2 -1
  157. package/packages/indexer_client/src/models/transaction-heartbeat.js.map +1 -1
  158. package/packages/indexer_client/src/models/transaction-heartbeat.mjs +2 -1
  159. package/packages/indexer_client/src/models/transaction-heartbeat.mjs.map +1 -1
  160. package/packages/indexer_client/src/models/transaction-keyreg.js +4 -4
  161. package/packages/indexer_client/src/models/transaction-keyreg.js.map +1 -1
  162. package/packages/indexer_client/src/models/transaction-keyreg.mjs +4 -4
  163. package/packages/indexer_client/src/models/transaction-keyreg.mjs.map +1 -1
  164. package/packages/indexer_client/src/models/transaction-signature-logicsig.js +2 -1
  165. package/packages/indexer_client/src/models/transaction-signature-logicsig.js.map +1 -1
  166. package/packages/indexer_client/src/models/transaction-signature-logicsig.mjs +2 -1
  167. package/packages/indexer_client/src/models/transaction-signature-logicsig.mjs.map +1 -1
  168. package/packages/indexer_client/src/models/transaction-signature-multisig-subsignature.js +3 -3
  169. package/packages/indexer_client/src/models/transaction-signature-multisig-subsignature.js.map +1 -1
  170. package/packages/indexer_client/src/models/transaction-signature-multisig-subsignature.mjs +3 -3
  171. package/packages/indexer_client/src/models/transaction-signature-multisig-subsignature.mjs.map +1 -1
  172. package/packages/indexer_client/src/models/transaction.d.ts +2 -2
  173. package/packages/indexer_client/src/models/transaction.js +6 -5
  174. package/packages/indexer_client/src/models/transaction.js.map +1 -1
  175. package/packages/indexer_client/src/models/transaction.mjs +6 -5
  176. package/packages/indexer_client/src/models/transaction.mjs.map +1 -1
  177. package/packages/kmd_client/src/apis/api-service.d.ts +5 -5
  178. package/packages/kmd_client/src/apis/api-service.js +32 -32
  179. package/packages/kmd_client/src/apis/api-service.js.map +1 -1
  180. package/packages/kmd_client/src/apis/api-service.mjs +32 -32
  181. package/packages/kmd_client/src/apis/api-service.mjs.map +1 -1
  182. package/packages/kmd_client/src/core/api-error.js +3 -1
  183. package/packages/kmd_client/src/core/api-error.js.map +1 -1
  184. package/packages/kmd_client/src/core/api-error.mjs +3 -1
  185. package/packages/kmd_client/src/core/api-error.mjs.map +1 -1
  186. package/packages/kmd_client/src/core/model-runtime.js +4 -4
  187. package/packages/kmd_client/src/core/model-runtime.js.map +1 -1
  188. package/packages/kmd_client/src/core/model-runtime.mjs +6 -6
  189. package/packages/kmd_client/src/core/model-runtime.mjs.map +1 -1
  190. package/packages/sdk/src/encoding/encoding.js +12 -2
  191. package/packages/sdk/src/encoding/encoding.js.map +1 -1
  192. package/packages/sdk/src/encoding/encoding.mjs +12 -1
  193. package/packages/sdk/src/encoding/encoding.mjs.map +1 -1
  194. package/packages/sdk/src/encoding/schema/map.js +0 -2
  195. package/packages/sdk/src/encoding/schema/map.js.map +1 -1
  196. package/packages/sdk/src/utils/utils.mjs +2 -2
  197. package/packages/sdk/src/utils/utils.mjs.map +1 -1
  198. package/packages/transact/src/logicsig.d.ts +3 -15
  199. package/packages/transact/src/logicsig.js +16 -36
  200. package/packages/transact/src/logicsig.js.map +1 -1
  201. package/packages/transact/src/logicsig.mjs +18 -36
  202. package/packages/transact/src/logicsig.mjs.map +1 -1
  203. package/packages/transact/src/multisig.d.ts +7 -115
  204. package/packages/transact/src/multisig.js +86 -136
  205. package/packages/transact/src/multisig.js.map +1 -1
  206. package/packages/transact/src/multisig.mjs +87 -117
  207. package/packages/transact/src/multisig.mjs.map +1 -1
  208. package/packages/transact/src/transactions/app-call.d.ts +10 -10
  209. package/packages/transact/src/transactions/app-call.js.map +1 -1
  210. package/packages/transact/src/transactions/app-call.mjs.map +1 -1
  211. package/packages/transact/src/transactions/reference-types-meta.d.ts +26 -0
  212. package/packages/transact/src/transactions/reference-types-meta.js +71 -0
  213. package/packages/transact/src/transactions/reference-types-meta.js.map +1 -0
  214. package/packages/transact/src/transactions/reference-types-meta.mjs +69 -0
  215. package/packages/transact/src/transactions/reference-types-meta.mjs.map +1 -0
  216. package/packages/transact/src/transactions/signed-transaction-meta.js +2 -3
  217. package/packages/transact/src/transactions/signed-transaction-meta.js.map +1 -1
  218. package/packages/transact/src/transactions/signed-transaction-meta.mjs +3 -3
  219. package/packages/transact/src/transactions/signed-transaction-meta.mjs.map +1 -1
  220. package/packages/transact/src/transactions/signed-transaction.d.ts +2 -2
  221. package/packages/transact/src/transactions/signed-transaction.js.map +1 -1
  222. package/packages/transact/src/transactions/signed-transaction.mjs.map +1 -1
  223. package/packages/transact/src/transactions/transaction-meta.js +29 -23
  224. package/packages/transact/src/transactions/transaction-meta.js.map +1 -1
  225. package/packages/transact/src/transactions/transaction-meta.mjs +29 -23
  226. package/packages/transact/src/transactions/transaction-meta.mjs.map +1 -1
  227. package/packages/transact/src/transactions/transaction.js +1 -0
  228. package/packages/transact/src/transactions/transaction.js.map +1 -1
  229. package/packages/transact/src/transactions/transaction.mjs +1 -0
  230. package/packages/transact/src/transactions/transaction.mjs.map +1 -1
  231. package/sdk/index.js +1 -1
  232. package/testing/fixtures/algorand-fixture.d.ts +3 -3
  233. package/testing/fixtures/algorand-fixture.js.map +1 -1
  234. package/testing/fixtures/algorand-fixture.mjs.map +1 -1
  235. package/transact/index.d.ts +5 -4
  236. package/transact/index.js +4 -22
  237. package/transact/index.mjs +4 -3
  238. package/transaction/transaction.js +2 -2
  239. package/transaction/transaction.js.map +1 -1
  240. package/transaction/transaction.mjs +2 -2
  241. package/transaction/transaction.mjs.map +1 -1
  242. package/transactions/app-call.d.ts +4 -3
  243. package/transactions/app-call.js +15 -15
  244. package/transactions/app-call.js.map +1 -1
  245. package/transactions/app-call.mjs +15 -15
  246. package/transactions/app-call.mjs.map +1 -1
  247. package/transactions/asset-config.d.ts +1 -1
  248. package/transactions/asset-config.js +1 -1
  249. package/transactions/asset-config.js.map +1 -1
  250. package/transactions/asset-config.mjs +1 -1
  251. package/transactions/asset-config.mjs.map +1 -1
  252. package/transactions/method-call.js +12 -12
  253. package/transactions/method-call.js.map +1 -1
  254. package/transactions/method-call.mjs +12 -12
  255. package/transactions/method-call.mjs.map +1 -1
  256. package/types/account-manager.js +2 -2
  257. package/types/account-manager.js.map +1 -1
  258. package/types/account-manager.mjs +2 -2
  259. package/types/account-manager.mjs.map +1 -1
  260. package/types/algorand-client-transaction-creator.d.ts +97 -83
  261. package/types/algorand-client-transaction-creator.js +8 -0
  262. package/types/algorand-client-transaction-creator.js.map +1 -1
  263. package/types/algorand-client-transaction-creator.mjs +8 -0
  264. package/types/algorand-client-transaction-creator.mjs.map +1 -1
  265. package/types/algorand-client-transaction-sender.d.ts +100 -86
  266. package/types/algorand-client-transaction-sender.js +8 -1
  267. package/types/algorand-client-transaction-sender.js.map +1 -1
  268. package/types/algorand-client-transaction-sender.mjs +8 -0
  269. package/types/algorand-client-transaction-sender.mjs.map +1 -1
  270. package/types/app-client.d.ts +265 -260
  271. package/types/app-client.js +0 -1
  272. package/types/app-client.js.map +1 -1
  273. package/types/app-deployer.js +1 -1
  274. package/types/app-deployer.js.map +1 -1
  275. package/types/app-deployer.mjs +1 -1
  276. package/types/app-deployer.mjs.map +1 -1
  277. package/types/app-factory.d.ts +91 -88
  278. package/types/app-manager.d.ts +3 -1
  279. package/types/app-manager.js +16 -10
  280. package/types/app-manager.js.map +1 -1
  281. package/types/app-manager.mjs +16 -10
  282. package/types/app-manager.mjs.map +1 -1
  283. package/types/app-spec.js +12 -5
  284. package/types/app-spec.js.map +1 -1
  285. package/types/app-spec.mjs +12 -5
  286. package/types/app-spec.mjs.map +1 -1
  287. package/types/asset-manager.js +1 -1
  288. package/types/asset-manager.js.map +1 -1
  289. package/types/asset-manager.mjs +1 -1
  290. package/types/asset-manager.mjs.map +1 -1
  291. package/types/composer.d.ts +9 -0
  292. package/types/composer.js +28 -13
  293. package/types/composer.js.map +1 -1
  294. package/types/composer.mjs +28 -12
  295. package/types/composer.mjs.map +1 -1
  296. package/types/kmd-account-manager.d.ts +1 -0
  297. package/types/kmd-account-manager.js +21 -10
  298. package/types/kmd-account-manager.js.map +1 -1
  299. package/types/kmd-account-manager.mjs +22 -11
  300. package/types/kmd-account-manager.mjs.map +1 -1
  301. package/types/testing.d.ts +2 -2
  302. package/packages/algod_client/src/models/application-local-reference.d.ts +0 -20
  303. package/packages/algod_client/src/models/application-local-reference.js +0 -23
  304. package/packages/algod_client/src/models/application-local-reference.js.map +0 -1
  305. package/packages/algod_client/src/models/application-local-reference.mjs +0 -23
  306. package/packages/algod_client/src/models/application-local-reference.mjs.map +0 -1
  307. package/packages/algod_client/src/models/asset-holding-reference.d.ts +0 -20
  308. package/packages/algod_client/src/models/asset-holding-reference.js +0 -23
  309. package/packages/algod_client/src/models/asset-holding-reference.js.map +0 -1
  310. package/packages/algod_client/src/models/asset-holding-reference.mjs +0 -23
  311. package/packages/algod_client/src/models/asset-holding-reference.mjs.map +0 -1
  312. package/packages/algod_client/src/models/box-reference.d.ts +0 -17
  313. package/packages/algod_client/src/models/box-reference.js +0 -23
  314. package/packages/algod_client/src/models/box-reference.js.map +0 -1
  315. package/packages/algod_client/src/models/box-reference.mjs +0 -23
  316. package/packages/algod_client/src/models/box-reference.mjs.map +0 -1
@@ -1 +1 @@
1
- {"version":3,"file":"app-spec.mjs","names":["hint","actions: ('NoOp' | 'OptIn' | 'CloseOut' | 'ClearState' | 'UpdateApplication' | 'DeleteApplication')[]","actions","ABITypeClass"],"sources":["../../src/types/app-spec.ts"],"sourcesContent":["import {\n ABIMethod,\n ABIType as ABITypeClass,\n ARC28Event,\n Arc56Contract,\n Arc56Method,\n StorageKey,\n StructField,\n} from '@algorandfoundation/algokit-abi'\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[getABIMethodParamsSignature(m)] 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' ? ABITypeClass.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\nfunction getABIMethodParamsSignature(params: ABIMethodParams) {\n const args = params.args.map((a) => a.type).join(',')\n return `${params.name}(${args})${params.returns.type}`\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\ninterface ABIContractParams {\n name: string\n desc?: string\n networks?: ABIContractNetworks\n methods: ABIMethodParams[]\n events?: ARC28Event[]\n}\n\ninterface ABIContractNetworks {\n [network: string]: ABIContractNetworkInfo\n}\n\ninterface ABIContractNetworkInfo {\n appID: number\n}\n\ninterface ABIMethodParams {\n name: string\n desc?: string\n args: ABIMethodArgParams[]\n returns: ABIMethodReturnParams\n /** Optional, is it a read-only method (according to [ARC-22](https://arc.algorand.foundation/ARCs/arc-0022)) */\n readonly?: boolean\n /** [ARC-28](https://arc.algorand.foundation/ARCs/arc-0028) events that MAY be emitted by this method */\n events?: ARC28Event[]\n}\n\ninterface ABIMethodArgParams {\n type: string\n name?: string\n desc?: string\n}\n\ninterface ABIMethodReturnParams {\n type: string\n desc?: string\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: ABIMethod\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":";;;;;;;;;;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AM,CACxD,EAAE,IACF;KACE,KAAK,OAAO,KAAK,EAAE,GAAG,KAAK,QAAQ,CAAC,SAAS,SAAS;KACtD,SAAS;KACT,WAAW,EAAE,GAAG,SAAS,WAAW,cAAc;KAClD,MAAM,EAAE,GAAG;KACZ,CACF,CAAC,CACH;IACD,OAAO,OAAO,YACZ,OAAO,QAAQ,QAAQ,OAAO,MAAM,SAAS,CAAC,KAAK,MAAM,CACvD,EAAE,IACF;KACE,KAAK,OAAO,KAAK,EAAE,GAAG,KAAK,QAAQ,CAAC,SAAS,SAAS;KACtD,SAAS;KACT,WAAW,EAAE,GAAG,SAAS,WAAW,cAAc;KAClD,MAAM,EAAE,GAAG;KACZ,CACF,CAAC,CACH;IACD,KAAK,EAAE;IACR;GACD,MAAM;IACJ,QAAQ,EAAE;IACV,OAAO,EAAE;IACT,KAAK,EAAE;IACR;GACF;EACD,QAAQ,QAAQ;EAChB,aAAa;GACX,QAAQ,YAAY,SAAS;GAC7B,MAAM,YAAY,OAAO;GAC1B;EACD,UAAU;EACV,cAAc;EACd,QAAQ;EACR,UAAU;EACV,kBAAkB;EAClB,YAAY;EACZ,mBAAmB;EACpB;;AAGH,SAAS,4BAA4B,QAAyB;CAC5D,MAAM,OAAO,OAAO,KAAK,KAAK,MAAM,EAAE,KAAK,CAAC,KAAK,IAAI;AACrD,QAAO,GAAG,OAAO,KAAK,GAAG,KAAK,GAAG,OAAO,QAAQ"}
1
+ {"version":3,"file":"app-spec.mjs","names":["hint","actions: ('NoOp' | 'OptIn' | 'CloseOut' | 'ClearState' | 'UpdateApplication' | 'DeleteApplication')[]","actions","defaultValueType: string | undefined","ABITypeClass"],"sources":["../../src/types/app-spec.ts"],"sourcesContent":["import {\n ABIMethod,\n ABIType as ABITypeClass,\n ARC28Event,\n Arc56Contract,\n Arc56Method,\n StorageKey,\n StructField,\n} from '@algorandfoundation/algokit-abi'\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[getABIMethodParamsSignature(m)] 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 = (defaultArg: DefaultArgument | undefined): 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 const mappedSource = defaultArg.source === 'constant' ? 'literal' : defaultArg.source === 'global-state' ? 'global' : 'local'\n\n // type is only set for literal source\n let defaultValueType: string | undefined = undefined\n if (mappedSource === 'literal') {\n if (typeof defaultArg.data === 'number') {\n defaultValueType = 'uint64'\n } else if (typeof defaultArg.data === 'string') {\n defaultValueType = 'AVMString'\n }\n }\n\n const argData =\n typeof defaultArg.data === 'number'\n ? ABITypeClass.from('uint64').encode(defaultArg.data)\n : typeof defaultArg.data === 'string'\n ? new TextEncoder().encode(defaultArg.data)\n : defaultArg.data\n\n return {\n source: mappedSource,\n data: Buffer.from(argData).toString('base64'),\n type: defaultValueType,\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.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\nfunction getABIMethodParamsSignature(params: ABIMethodParams) {\n const args = params.args.map((a) => a.type).join(',')\n return `${params.name}(${args})${params.returns.type}`\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\ninterface ABIContractParams {\n name: string\n desc?: string\n networks?: ABIContractNetworks\n methods: ABIMethodParams[]\n events?: ARC28Event[]\n}\n\ninterface ABIContractNetworks {\n [network: string]: ABIContractNetworkInfo\n}\n\ninterface ABIContractNetworkInfo {\n appID: number\n}\n\ninterface ABIMethodParams {\n name: string\n desc?: string\n args: ABIMethodArgParams[]\n returns: ABIMethodReturnParams\n /** Optional, is it a read-only method (according to [ARC-22](https://arc.algorand.foundation/ARCs/arc-0022)) */\n readonly?: boolean\n /** [ARC-28](https://arc.algorand.foundation/ARCs/arc-0028) events that MAY be emitted by this method */\n events?: ARC28Event[]\n}\n\ninterface ABIMethodArgParams {\n type: string\n name?: string\n desc?: string\n}\n\ninterface ABIMethodReturnParams {\n type: string\n desc?: string\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: ABIMethod\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":";;;;;;;;;;;;AAmBA,SAAgB,aAAa,SAAiC;CAC5D,MAAM,eAAe,OAAO,OAAO,QAAQ,MAAM,CAAC,SAAS,WAAS,OAAO,QAAQA,OAAK,WAAW,EAAE,CAAC,CAAC;CACvG,MAAM,UAAU,OAAO,YACrB,aAAa,KAAK,CAAC,GAAG,YAAY;EAChC,MAAM,SAAS,OAAO,SAAS,KAAK,OAAO;GAAE,MAAM,EAAE;GAAI,MAAM,EAAE;GAAI,EAAE;AACvE,SAAO,CAAC,OAAO,MAAM,OAAO;GAC5B,CACH;CACD,MAAM,QAAQ,MAAuB,QAAQ,MAAM,4BAA4B,EAAE;CACjF,MAAM,WAAW,GAAoB,SAA4B;AAE/D,SAAO,KAAK,EAAE,EAAE,gBAAgB,SAAY,oBAAoB,KAAK,EAAE,EAAE,aAAc,KAAK,GAAG,EA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GAAG,KAAK,QAAQ,CAAC,SAAS,SAAS;KACtD,SAAS;KACT,WAAW,EAAE,GAAG,SAAS,WAAW,cAAc;KAClD,MAAM,EAAE,GAAG;KACZ,CACF,CAAC,CACH;IACD,KAAK,EAAE;IACR;GACD,MAAM;IACJ,QAAQ,EAAE;IACV,OAAO,EAAE;IACT,KAAK,EAAE;IACR;GACF;EACD,QAAQ,QAAQ;EAChB,aAAa;GACX,QAAQ,YAAY,SAAS;GAC7B,MAAM,YAAY,OAAO;GAC1B;EACD,UAAU;EACV,cAAc;EACd,QAAQ;EACR,UAAU;EACV,kBAAkB;EAClB,YAAY;EACZ,mBAAmB;EACpB;;AAGH,SAAS,4BAA4B,QAAyB;CAC5D,MAAM,OAAO,OAAO,KAAK,KAAK,MAAM,EAAE,KAAK,CAAC,KAAK,IAAI;AACrD,QAAO,GAAG,OAAO,KAAK,GAAG,KAAK,GAAG,OAAO,QAAQ"}
@@ -32,7 +32,7 @@ var AssetManager = class {
32
32
  * @returns The asset information
33
33
  */
34
34
  async getById(assetId) {
35
- const asset = await this._algod.getAssetById(assetId);
35
+ const asset = await this._algod.assetById(assetId);
36
36
  return {
37
37
  assetId: BigInt(asset.id),
38
38
  total: BigInt(asset.params.total),
@@ -1 +1 @@
1
- {"version":3,"file":"asset-manager.js","names":["results: BulkAssetOptInOutResult[]","chunkArray","MAX_TRANSACTION_GROUP_SIZE","notOptedInAssetIds: bigint[]","nonZeroBalanceAssetIds: bigint[]"],"sources":["../../src/types/asset-manager.ts"],"sourcesContent":["import { AlgodClient } from '@algorandfoundation/algokit-algod-client'\nimport { Address, MAX_TRANSACTION_GROUP_SIZE } from '@algorandfoundation/algokit-common'\nimport { Config } from '../config'\nimport { chunkArray } from '../util'\nimport { AccountAssetInformation } from './account'\nimport { CommonTransactionParams, TransactionComposer, TransactionComposerConfig } from './composer'\nimport { SendParams } from './transaction'\n\n/** Individual result from performing a bulk opt-in or bulk opt-out for an account against a series of assets. */\nexport interface BulkAssetOptInOutResult {\n /** The ID of the asset opted into / out of */\n assetId: bigint\n /** The transaction ID of the resulting opt in / out */\n transactionId: string\n}\n\n/** Information about an asset. */\nexport interface AssetInformation {\n /** The ID of the asset. */\n assetId: bigint\n\n /** The address of the account that created the asset.\n *\n * This is the address where the parameters for this asset can be found,\n * and also the address where unwanted asset units can be sent when\n * closing out an asset position and opting-out of the asset.\n */\n creator: string\n\n /** The total amount of the smallest divisible (decimal) units that were created of the asset.\n *\n * For example, if `decimals` is, say, 2, then for every 100 `total` there is 1 whole unit.\n */\n total: bigint\n\n /** The amount of decimal places the asset was created with.\n *\n * * If 0, the asset is not divisible;\n * * If 1, the base unit of the asset is in tenths;\n * * If 2, the base unit of the asset is in hundredths;\n * * If 3, the base unit of the asset is in thousandths;\n * * and so on up to 19 decimal places.\n */\n decimals: number\n\n /** Whether the asset was frozen by default for all accounts.\n *\n * If `true` then for anyone apart from the creator to hold the\n * asset it needs to be unfrozen per account using an asset freeze\n * transaction from the `freeze` account.\n */\n defaultFrozen?: boolean\n\n /** The address of the optional account that can manage the configuration of the asset and destroy it.\n *\n * If not set the asset is permanently immutable.\n */\n manager?: string\n\n /**\n * The address of the optional account that holds the reserve (uncirculated supply) units of the asset.\n *\n * This address has no specific authority in the protocol itself and is informational only.\n *\n * Some standards like [ARC-19](https://github.com/algorandfoundation/ARCs/blob/main/ARCs/arc-0019.md)\n * rely on this field to hold meaningful data.\n *\n * It can be used in the case where you want to signal to holders of your asset that the uncirculated units\n * of the asset reside in an account that is different from the default creator account.\n *\n * If not set the field is permanently empty.\n */\n reserve?: string\n\n /**\n * The address of the optional account that can be used to freeze or unfreeze holdings of this asset for any account.\n *\n * If empty, freezing is not permitted.\n *\n * If not set the field is permanently empty.\n */\n freeze?: string\n\n /**\n * The address of the optional account that can clawback holdings of this asset from any account.\n *\n * The clawback account has the ability to **unconditionally take assets from any account**.\n *\n * If empty, clawback is not permitted.\n *\n * If not set the field is permanently empty.\n */\n clawback?: string\n\n /** The optional name of the unit of this asset (e.g. ticker name).\n *\n * Max size is 8 bytes.\n */\n unitName?: string\n\n /** The optional name of the unit of this asset (e.g. ticker name).\n *\n * Max size is 8 bytes.\n */\n unitNameAsBytes?: Uint8Array\n\n /** The optional name of the asset.\n *\n * Max size is 32 bytes.\n */\n assetName?: string\n\n /** The optional name of the asset.\n *\n * Max size is 32 bytes.\n */\n assetNameAsBytes?: Uint8Array\n\n /** Optional URL where more information about the asset can be retrieved (e.g. metadata).\n *\n * Max size is 96 bytes.\n */\n url?: string\n\n /** Optional URL where more information about the asset can be retrieved (e.g. metadata).\n *\n * Max size is 96 bytes.\n */\n urlAsBytes?: Uint8Array\n\n /** 32-byte hash of some metadata that is relevant to the asset and/or asset holders.\n *\n * The format of this metadata is up to the application.\n */\n metadataHash?: Uint8Array\n}\n\n/** Allows management of asset information. */\nexport class AssetManager {\n private _algod: AlgodClient\n private _newGroup: () => TransactionComposer\n\n /**\n * Create a new asset manager.\n * @param algod An algod client\n * @param newGroup A function that creates a new `TransactionComposer` transaction group\n * @example Create a new asset manager\n * ```typescript\n * const assetManager = new AssetManager(algod, () => new TransactionComposer({algod, () => signer, () => suggestedParams}))\n * ```\n */\n constructor(algod: AlgodClient, newGroup: (config?: TransactionComposerConfig) => TransactionComposer) {\n this._algod = algod\n this._newGroup = newGroup\n }\n\n /**\n * Returns the current asset information for the asset with the given ID.\n *\n * @example\n * ```typescript\n * const assetInfo = await assetManager.getById(12353n);\n * ```\n *\n * @param assetId The ID of the asset\n * @returns The asset information\n */\n public async getById(assetId: bigint): Promise<AssetInformation> {\n const asset = await this._algod.getAssetById(assetId)\n\n return {\n assetId: BigInt(asset.id),\n total: BigInt(asset.params.total),\n decimals: Number(asset.params.decimals),\n assetName: asset.params.name,\n assetNameAsBytes: asset.params.nameB64,\n unitName: asset.params.unitName,\n unitNameAsBytes: asset.params.unitNameB64,\n url: asset.params.url,\n urlAsBytes: asset.params.urlB64,\n creator: asset.params.creator,\n manager: asset.params.manager,\n clawback: asset.params.clawback,\n freeze: asset.params.freeze,\n reserve: asset.params.reserve,\n defaultFrozen: asset.params.defaultFrozen,\n metadataHash: asset.params.metadataHash,\n }\n }\n\n /**\n * Returns the given sender account's asset holding for a given asset.\n *\n * @example\n * ```typescript\n * const address = \"XBYLS2E6YI6XXL5BWCAMOA4GTWHXWENZMX5UHXMRNWWUQ7BXCY5WC5TEPA\";\n * const assetId = 123345n;\n * const accountInfo = await assetManager.getAccountInformation(address, assetId);\n * ```\n *\n * [Response data schema details](https://dev.algorand.co/reference/rest-apis/algod/#accountassetinformation)\n * @param sender The address of the sender/account to look up\n * @param assetId The ID of the asset to return a holding for\n * @returns The account asset holding information\n */\n public async getAccountInformation(sender: string | Address, assetId: bigint): Promise<AccountAssetInformation> {\n const info = await this._algod.accountAssetInformation(sender.toString(), assetId)\n\n return {\n assetId: BigInt(assetId),\n balance: BigInt(info.assetHolding?.amount ?? 0),\n frozen: info.assetHolding?.isFrozen === true,\n round: BigInt(info['round']),\n }\n }\n\n /**\n * Opt an account in to a list of Algorand Standard Assets.\n *\n * Transactions will be sent in batches of 16 as transaction groups.\n *\n * @param account The account to opt-in\n * @param assetIds The list of asset IDs to opt-in to\n * @param options Any parameters to control the transaction or execution of the transaction\n * @example Example using AlgorandClient\n * ```typescript\n * // Basic example\n * assetManager.bulkOptIn(\"ACCOUNTADDRESS\", [12345n, 67890n])\n * // With configuration\n * assetManager.bulkOptIn(\"ACCOUNTADDRESS\", [12345n, 67890n], { maxFee: (1000).microAlgo(), suppressLog: true })\n * ```\n * @returns An array of records matching asset ID to transaction ID of the opt in\n */\n async bulkOptIn(\n account: string | Address,\n assetIds: bigint[],\n options?: Omit<CommonTransactionParams, 'sender'> & SendParams,\n ): Promise<BulkAssetOptInOutResult[]> {\n const results: BulkAssetOptInOutResult[] = []\n\n for (const assetGroup of chunkArray(assetIds, MAX_TRANSACTION_GROUP_SIZE)) {\n const composer = this._newGroup()\n\n for (const assetId of assetGroup) {\n composer.addAssetOptIn({\n ...options,\n sender: account,\n assetId: BigInt(assetId),\n })\n }\n\n const result = await composer.send(options)\n\n Config.getLogger(options?.suppressLog).info(\n `Successfully opted in ${account} for assets ${assetGroup.join(', ')} with transaction IDs ${result.txIds.join(', ')}` +\n `\\n Grouped under ${result.groupId} in round ${result.confirmations?.[0]?.confirmedRound}.`,\n )\n\n assetGroup.forEach((assetId, index) => {\n results.push({ assetId: BigInt(assetId), transactionId: result.txIds[index] })\n })\n }\n\n return results\n }\n\n /**\n * Opt an account out of a list of Algorand Standard Assets.\n *\n * Transactions will be sent in batches of 16 as transaction groups.\n *\n * @param account The account to opt-in\n * @param assetIds The list of asset IDs to opt-out of\n * @param options Any parameters to control the transaction or execution of the transaction\n * @example Example using AlgorandClient\n * ```typescript\n * // Basic example\n * assetManager.bulkOptOut(\"ACCOUNTADDRESS\", [12345n, 67890n])\n * // With configuration\n * assetManager.bulkOptOut(\"ACCOUNTADDRESS\", [12345n, 67890n], { ensureZeroBalance: true, maxFee: (1000).microAlgo(), suppressLog: true })\n * ```\n * @returns An array of records matching asset ID to transaction ID of the opt in\n */\n async bulkOptOut(\n account: string | Address,\n assetIds: bigint[],\n options?: Omit<CommonTransactionParams, 'sender'> &\n SendParams & {\n /** Whether or not to check if the account has a zero balance for each asset first or not.\n *\n * Defaults to `true`.\n *\n * If this is set to `true` and the account has an asset balance it will throw an error.\n *\n * If this is set to `false` and the account has an asset balance it will lose those assets to the asset creator.\n */\n ensureZeroBalance?: boolean\n },\n ): Promise<BulkAssetOptInOutResult[]> {\n const results: BulkAssetOptInOutResult[] = []\n\n for (const assetGroup of chunkArray(assetIds, MAX_TRANSACTION_GROUP_SIZE)) {\n const composer = this._newGroup()\n\n const notOptedInAssetIds: bigint[] = []\n const nonZeroBalanceAssetIds: bigint[] = []\n for (const assetId of assetGroup) {\n if (options?.ensureZeroBalance !== false) {\n try {\n const accountAssetInfo = await this.getAccountInformation(account, assetId)\n if (accountAssetInfo.balance !== 0n) {\n nonZeroBalanceAssetIds.push(BigInt(assetId))\n }\n } catch {\n notOptedInAssetIds.push(BigInt(assetId))\n }\n }\n }\n\n if (notOptedInAssetIds.length > 0 || nonZeroBalanceAssetIds.length > 0) {\n throw new Error(\n `Account ${account}${notOptedInAssetIds.length > 0 ? ` is not opted-in to Asset${notOptedInAssetIds.length > 1 ? 's' : ''} ${notOptedInAssetIds.join(', ')}` : ''}${\n nonZeroBalanceAssetIds.length > 0\n ? ` has non-zero balance for Asset${nonZeroBalanceAssetIds.length > 1 ? 's' : ''} ${nonZeroBalanceAssetIds.join(', ')}`\n : ''\n }; can't opt-out.`,\n )\n }\n\n for (const assetId of assetGroup) {\n composer.addAssetOptOut({\n ...options,\n creator: (await this.getById(BigInt(assetId))).creator,\n sender: account,\n assetId: BigInt(assetId),\n })\n }\n\n const result = await composer.send(options)\n\n Config.getLogger(options?.suppressLog).info(\n `Successfully opted ${account} out of assets ${assetGroup.join(', ')} with transaction IDs ${result.txIds.join(', ')}` +\n `\\n Grouped under ${result.groupId} in round ${result.confirmations?.[0]?.confirmedRound}.`,\n )\n\n assetGroup.forEach((assetId, index) => {\n results.push({ assetId: BigInt(assetId), transactionId: result.txIds[index] })\n })\n }\n\n return results\n }\n}\n"],"mappings":";;;;;;AA0IA,IAAa,eAAb,MAA0B;CACxB,AAAQ;CACR,AAAQ;;;;;;;;;;CAWR,YAAY,OAAoB,UAAuE;AACrG,OAAK,SAAS;AACd,OAAK,YAAY;;;;;;;;;;;;;CAcnB,MAAa,QAAQ,SAA4C;EAC/D,MAAM,QAAQ,MAAM,KAAK,OAAO,aAAa,QAAQ;AAErD,SAAO;GACL,SAAS,OAAO,MAAM,GAAG;GACzB,OAAO,OAAO,MAAM,OAAO,MAAM;GACjC,UAAU,OAAO,MAAM,OAAO,SAAS;GACvC,WAAW,MAAM,OAAO;GACxB,kBAAkB,MAAM,OAAO;GAC/B,UAAU,MAAM,OAAO;GACvB,iBAAiB,MAAM,OAAO;GAC9B,KAAK,MAAM,OAAO;GAClB,YAAY,MAAM,OAAO;GACz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"sources":["../../src/types/asset-manager.ts"],"sourcesContent":["import { AlgodClient } from '@algorandfoundation/algokit-algod-client'\nimport { Address, MAX_TRANSACTION_GROUP_SIZE } from '@algorandfoundation/algokit-common'\nimport { Config } from '../config'\nimport { chunkArray } from '../util'\nimport { AccountAssetInformation } from './account'\nimport { CommonTransactionParams, TransactionComposer, TransactionComposerConfig } from './composer'\nimport { SendParams } from './transaction'\n\n/** Individual result from performing a bulk opt-in or bulk opt-out for an account against a series of assets. */\nexport interface BulkAssetOptInOutResult {\n /** The ID of the asset opted into / out of */\n assetId: bigint\n /** The transaction ID of the resulting opt in / out */\n transactionId: string\n}\n\n/** Information about an asset. */\nexport interface AssetInformation {\n /** The ID of the asset. */\n assetId: bigint\n\n /** The address of the account that created the asset.\n *\n * This is the address where the parameters for this asset can be found,\n * and also the address where unwanted asset units can be sent when\n * closing out an asset position and opting-out of the asset.\n */\n creator: string\n\n /** The total amount of the smallest divisible (decimal) units that were created of the asset.\n *\n * For example, if `decimals` is, say, 2, then for every 100 `total` there is 1 whole unit.\n */\n total: bigint\n\n /** The amount of decimal places the asset was created with.\n *\n * * If 0, the asset is not divisible;\n * * If 1, the base unit of the asset is in tenths;\n * * If 2, the base unit of the asset is in hundredths;\n * * If 3, the base unit of the asset is in thousandths;\n * * and so on up to 19 decimal places.\n */\n decimals: number\n\n /** Whether the asset was frozen by default for all accounts.\n *\n * If `true` then for anyone apart from the creator to hold the\n * asset it needs to be unfrozen per account using an asset freeze\n * transaction from the `freeze` account.\n */\n defaultFrozen?: boolean\n\n /** The address of the optional account that can manage the configuration of the asset and destroy it.\n *\n * If not set the asset is permanently immutable.\n */\n manager?: string\n\n /**\n * The address of the optional account that holds the reserve (uncirculated supply) units of the asset.\n *\n * This address has no specific authority in the protocol itself and is informational only.\n *\n * Some standards like [ARC-19](https://github.com/algorandfoundation/ARCs/blob/main/ARCs/arc-0019.md)\n * rely on this field to hold meaningful data.\n *\n * It can be used in the case where you want to signal to holders of your asset that the uncirculated units\n * of the asset reside in an account that is different from the default creator account.\n *\n * If not set the field is permanently empty.\n */\n reserve?: string\n\n /**\n * The address of the optional account that can be used to freeze or unfreeze holdings of this asset for any account.\n *\n * If empty, freezing is not permitted.\n *\n * If not set the field is permanently empty.\n */\n freeze?: string\n\n /**\n * The address of the optional account that can clawback holdings of this asset from any account.\n *\n * The clawback account has the ability to **unconditionally take assets from any account**.\n *\n * If empty, clawback is not permitted.\n *\n * If not set the field is permanently empty.\n */\n clawback?: string\n\n /** The optional name of the unit of this asset (e.g. ticker name).\n *\n * Max size is 8 bytes.\n */\n unitName?: string\n\n /** The optional name of the unit of this asset (e.g. ticker name).\n *\n * Max size is 8 bytes.\n */\n unitNameAsBytes?: Uint8Array\n\n /** The optional name of the asset.\n *\n * Max size is 32 bytes.\n */\n assetName?: string\n\n /** The optional name of the asset.\n *\n * Max size is 32 bytes.\n */\n assetNameAsBytes?: Uint8Array\n\n /** Optional URL where more information about the asset can be retrieved (e.g. metadata).\n *\n * Max size is 96 bytes.\n */\n url?: string\n\n /** Optional URL where more information about the asset can be retrieved (e.g. metadata).\n *\n * Max size is 96 bytes.\n */\n urlAsBytes?: Uint8Array\n\n /** 32-byte hash of some metadata that is relevant to the asset and/or asset holders.\n *\n * The format of this metadata is up to the application.\n */\n metadataHash?: Uint8Array\n}\n\n/** Allows management of asset information. */\nexport class AssetManager {\n private _algod: AlgodClient\n private _newGroup: () => TransactionComposer\n\n /**\n * Create a new asset manager.\n * @param algod An algod client\n * @param newGroup A function that creates a new `TransactionComposer` transaction group\n * @example Create a new asset manager\n * ```typescript\n * const assetManager = new AssetManager(algod, () => new TransactionComposer({algod, () => signer, () => suggestedParams}))\n * ```\n */\n constructor(algod: AlgodClient, newGroup: (config?: TransactionComposerConfig) => TransactionComposer) {\n this._algod = algod\n this._newGroup = newGroup\n }\n\n /**\n * Returns the current asset information for the asset with the given ID.\n *\n * @example\n * ```typescript\n * const assetInfo = await assetManager.getById(12353n);\n * ```\n *\n * @param assetId The ID of the asset\n * @returns The asset information\n */\n public async getById(assetId: bigint): Promise<AssetInformation> {\n const asset = await this._algod.assetById(assetId)\n\n return {\n assetId: BigInt(asset.id),\n total: BigInt(asset.params.total),\n decimals: Number(asset.params.decimals),\n assetName: asset.params.name,\n assetNameAsBytes: asset.params.nameB64,\n unitName: asset.params.unitName,\n unitNameAsBytes: asset.params.unitNameB64,\n url: asset.params.url,\n urlAsBytes: asset.params.urlB64,\n creator: asset.params.creator,\n manager: asset.params.manager,\n clawback: asset.params.clawback,\n freeze: asset.params.freeze,\n reserve: asset.params.reserve,\n defaultFrozen: asset.params.defaultFrozen,\n metadataHash: asset.params.metadataHash,\n }\n }\n\n /**\n * Returns the given sender account's asset holding for a given asset.\n *\n * @example\n * ```typescript\n * const address = \"XBYLS2E6YI6XXL5BWCAMOA4GTWHXWENZMX5UHXMRNWWUQ7BXCY5WC5TEPA\";\n * const assetId = 123345n;\n * const accountInfo = await assetManager.getAccountInformation(address, assetId);\n * ```\n *\n * [Response data schema details](https://dev.algorand.co/reference/rest-apis/algod/#accountassetinformation)\n * @param sender The address of the sender/account to look up\n * @param assetId The ID of the asset to return a holding for\n * @returns The account asset holding information\n */\n public async getAccountInformation(sender: string | Address, assetId: bigint): Promise<AccountAssetInformation> {\n const info = await this._algod.accountAssetInformation(sender.toString(), assetId)\n\n return {\n assetId: BigInt(assetId),\n balance: BigInt(info.assetHolding?.amount ?? 0),\n frozen: info.assetHolding?.isFrozen === true,\n round: BigInt(info['round']),\n }\n }\n\n /**\n * Opt an account in to a list of Algorand Standard Assets.\n *\n * Transactions will be sent in batches of 16 as transaction groups.\n *\n * @param account The account to opt-in\n * @param assetIds The list of asset IDs to opt-in to\n * @param options Any parameters to control the transaction or execution of the transaction\n * @example Example using AlgorandClient\n * ```typescript\n * // Basic example\n * assetManager.bulkOptIn(\"ACCOUNTADDRESS\", [12345n, 67890n])\n * // With configuration\n * assetManager.bulkOptIn(\"ACCOUNTADDRESS\", [12345n, 67890n], { maxFee: (1000).microAlgo(), suppressLog: true })\n * ```\n * @returns An array of records matching asset ID to transaction ID of the opt in\n */\n async bulkOptIn(\n account: string | Address,\n assetIds: bigint[],\n options?: Omit<CommonTransactionParams, 'sender'> & SendParams,\n ): Promise<BulkAssetOptInOutResult[]> {\n const results: BulkAssetOptInOutResult[] = []\n\n for (const assetGroup of chunkArray(assetIds, MAX_TRANSACTION_GROUP_SIZE)) {\n const composer = this._newGroup()\n\n for (const assetId of assetGroup) {\n composer.addAssetOptIn({\n ...options,\n sender: account,\n assetId: BigInt(assetId),\n })\n }\n\n const result = await composer.send(options)\n\n Config.getLogger(options?.suppressLog).info(\n `Successfully opted in ${account} for assets ${assetGroup.join(', ')} with transaction IDs ${result.txIds.join(', ')}` +\n `\\n Grouped under ${result.groupId} in round ${result.confirmations?.[0]?.confirmedRound}.`,\n )\n\n assetGroup.forEach((assetId, index) => {\n results.push({ assetId: BigInt(assetId), transactionId: result.txIds[index] })\n })\n }\n\n return results\n }\n\n /**\n * Opt an account out of a list of Algorand Standard Assets.\n *\n * Transactions will be sent in batches of 16 as transaction groups.\n *\n * @param account The account to opt-in\n * @param assetIds The list of asset IDs to opt-out of\n * @param options Any parameters to control the transaction or execution of the transaction\n * @example Example using AlgorandClient\n * ```typescript\n * // Basic example\n * assetManager.bulkOptOut(\"ACCOUNTADDRESS\", [12345n, 67890n])\n * // With configuration\n * assetManager.bulkOptOut(\"ACCOUNTADDRESS\", [12345n, 67890n], { ensureZeroBalance: true, maxFee: (1000).microAlgo(), suppressLog: true })\n * ```\n * @returns An array of records matching asset ID to transaction ID of the opt in\n */\n async bulkOptOut(\n account: string | Address,\n assetIds: bigint[],\n options?: Omit<CommonTransactionParams, 'sender'> &\n SendParams & {\n /** Whether or not to check if the account has a zero balance for each asset first or not.\n *\n * Defaults to `true`.\n *\n * If this is set to `true` and the account has an asset balance it will throw an error.\n *\n * If this is set to `false` and the account has an asset balance it will lose those assets to the asset creator.\n */\n ensureZeroBalance?: boolean\n },\n ): Promise<BulkAssetOptInOutResult[]> {\n const results: BulkAssetOptInOutResult[] = []\n\n for (const assetGroup of chunkArray(assetIds, MAX_TRANSACTION_GROUP_SIZE)) {\n const composer = this._newGroup()\n\n const notOptedInAssetIds: bigint[] = []\n const nonZeroBalanceAssetIds: bigint[] = []\n for (const assetId of assetGroup) {\n if (options?.ensureZeroBalance !== false) {\n try {\n const accountAssetInfo = await this.getAccountInformation(account, assetId)\n if (accountAssetInfo.balance !== 0n) {\n nonZeroBalanceAssetIds.push(BigInt(assetId))\n }\n } catch {\n notOptedInAssetIds.push(BigInt(assetId))\n }\n }\n }\n\n if (notOptedInAssetIds.length > 0 || nonZeroBalanceAssetIds.length > 0) {\n throw new Error(\n `Account ${account}${notOptedInAssetIds.length > 0 ? ` is not opted-in to Asset${notOptedInAssetIds.length > 1 ? 's' : ''} ${notOptedInAssetIds.join(', ')}` : ''}${\n nonZeroBalanceAssetIds.length > 0\n ? ` has non-zero balance for Asset${nonZeroBalanceAssetIds.length > 1 ? 's' : ''} ${nonZeroBalanceAssetIds.join(', ')}`\n : ''\n }; can't opt-out.`,\n )\n }\n\n for (const assetId of assetGroup) {\n composer.addAssetOptOut({\n ...options,\n creator: (await this.getById(BigInt(assetId))).creator,\n sender: account,\n assetId: BigInt(assetId),\n })\n }\n\n const result = await composer.send(options)\n\n Config.getLogger(options?.suppressLog).info(\n `Successfully opted ${account} out of assets ${assetGroup.join(', ')} with transaction IDs ${result.txIds.join(', ')}` +\n `\\n Grouped under ${result.groupId} in round ${result.confirmations?.[0]?.confirmedRound}.`,\n )\n\n assetGroup.forEach((assetId, index) => {\n results.push({ assetId: BigInt(assetId), transactionId: result.txIds[index] })\n })\n }\n\n return results\n }\n}\n"],"mappings":";;;;;;AA0IA,IAAa,eAAb,MAA0B;CACxB,AAAQ;CACR,AAAQ;;;;;;;;;;CAWR,YAAY,OAAoB,UAAuE;AACrG,OAAK,SAAS;AACd,OAAK,YAAY;;;;;;;;;;;;;CAcnB,MAAa,QAAQ,SAA4C;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OAAO,QAAQ,YAAY,OAAO,gBAAgB,IAAI,eAAe,GAC7F;AAED,cAAW,SAAS,SAAS,UAAU;AACrC,YAAQ,KAAK;KAAE,SAAS,OAAO,QAAQ;KAAE,eAAe,OAAO,MAAM;KAAQ,CAAC;KAC9E;;AAGJ,SAAO"}
@@ -32,7 +32,7 @@ var AssetManager = class {
32
32
  * @returns The asset information
33
33
  */
34
34
  async getById(assetId) {
35
- const asset = await this._algod.getAssetById(assetId);
35
+ const asset = await this._algod.assetById(assetId);
36
36
  return {
37
37
  assetId: BigInt(asset.id),
38
38
  total: BigInt(asset.params.total),
@@ -1 +1 @@
1
- {"version":3,"file":"asset-manager.mjs","names":["results: BulkAssetOptInOutResult[]","notOptedInAssetIds: bigint[]","nonZeroBalanceAssetIds: bigint[]"],"sources":["../../src/types/asset-manager.ts"],"sourcesContent":["import { AlgodClient } from '@algorandfoundation/algokit-algod-client'\nimport { Address, MAX_TRANSACTION_GROUP_SIZE } from '@algorandfoundation/algokit-common'\nimport { Config } from '../config'\nimport { chunkArray } from '../util'\nimport { AccountAssetInformation } from './account'\nimport { CommonTransactionParams, TransactionComposer, TransactionComposerConfig } from './composer'\nimport { SendParams } from './transaction'\n\n/** Individual result from performing a bulk opt-in or bulk opt-out for an account against a series of assets. */\nexport interface BulkAssetOptInOutResult {\n /** The ID of the asset opted into / out of */\n assetId: bigint\n /** The transaction ID of the resulting opt in / out */\n transactionId: string\n}\n\n/** Information about an asset. */\nexport interface AssetInformation {\n /** The ID of the asset. */\n assetId: bigint\n\n /** The address of the account that created the asset.\n *\n * This is the address where the parameters for this asset can be found,\n * and also the address where unwanted asset units can be sent when\n * closing out an asset position and opting-out of the asset.\n */\n creator: string\n\n /** The total amount of the smallest divisible (decimal) units that were created of the asset.\n *\n * For example, if `decimals` is, say, 2, then for every 100 `total` there is 1 whole unit.\n */\n total: bigint\n\n /** The amount of decimal places the asset was created with.\n *\n * * If 0, the asset is not divisible;\n * * If 1, the base unit of the asset is in tenths;\n * * If 2, the base unit of the asset is in hundredths;\n * * If 3, the base unit of the asset is in thousandths;\n * * and so on up to 19 decimal places.\n */\n decimals: number\n\n /** Whether the asset was frozen by default for all accounts.\n *\n * If `true` then for anyone apart from the creator to hold the\n * asset it needs to be unfrozen per account using an asset freeze\n * transaction from the `freeze` account.\n */\n defaultFrozen?: boolean\n\n /** The address of the optional account that can manage the configuration of the asset and destroy it.\n *\n * If not set the asset is permanently immutable.\n */\n manager?: string\n\n /**\n * The address of the optional account that holds the reserve (uncirculated supply) units of the asset.\n *\n * This address has no specific authority in the protocol itself and is informational only.\n *\n * Some standards like [ARC-19](https://github.com/algorandfoundation/ARCs/blob/main/ARCs/arc-0019.md)\n * rely on this field to hold meaningful data.\n *\n * It can be used in the case where you want to signal to holders of your asset that the uncirculated units\n * of the asset reside in an account that is different from the default creator account.\n *\n * If not set the field is permanently empty.\n */\n reserve?: string\n\n /**\n * The address of the optional account that can be used to freeze or unfreeze holdings of this asset for any account.\n *\n * If empty, freezing is not permitted.\n *\n * If not set the field is permanently empty.\n */\n freeze?: string\n\n /**\n * The address of the optional account that can clawback holdings of this asset from any account.\n *\n * The clawback account has the ability to **unconditionally take assets from any account**.\n *\n * If empty, clawback is not permitted.\n *\n * If not set the field is permanently empty.\n */\n clawback?: string\n\n /** The optional name of the unit of this asset (e.g. ticker name).\n *\n * Max size is 8 bytes.\n */\n unitName?: string\n\n /** The optional name of the unit of this asset (e.g. ticker name).\n *\n * Max size is 8 bytes.\n */\n unitNameAsBytes?: Uint8Array\n\n /** The optional name of the asset.\n *\n * Max size is 32 bytes.\n */\n assetName?: string\n\n /** The optional name of the asset.\n *\n * Max size is 32 bytes.\n */\n assetNameAsBytes?: Uint8Array\n\n /** Optional URL where more information about the asset can be retrieved (e.g. metadata).\n *\n * Max size is 96 bytes.\n */\n url?: string\n\n /** Optional URL where more information about the asset can be retrieved (e.g. metadata).\n *\n * Max size is 96 bytes.\n */\n urlAsBytes?: Uint8Array\n\n /** 32-byte hash of some metadata that is relevant to the asset and/or asset holders.\n *\n * The format of this metadata is up to the application.\n */\n metadataHash?: Uint8Array\n}\n\n/** Allows management of asset information. */\nexport class AssetManager {\n private _algod: AlgodClient\n private _newGroup: () => TransactionComposer\n\n /**\n * Create a new asset manager.\n * @param algod An algod client\n * @param newGroup A function that creates a new `TransactionComposer` transaction group\n * @example Create a new asset manager\n * ```typescript\n * const assetManager = new AssetManager(algod, () => new TransactionComposer({algod, () => signer, () => suggestedParams}))\n * ```\n */\n constructor(algod: AlgodClient, newGroup: (config?: TransactionComposerConfig) => TransactionComposer) {\n this._algod = algod\n this._newGroup = newGroup\n }\n\n /**\n * Returns the current asset information for the asset with the given ID.\n *\n * @example\n * ```typescript\n * const assetInfo = await assetManager.getById(12353n);\n * ```\n *\n * @param assetId The ID of the asset\n * @returns The asset information\n */\n public async getById(assetId: bigint): Promise<AssetInformation> {\n const asset = await this._algod.getAssetById(assetId)\n\n return {\n assetId: BigInt(asset.id),\n total: BigInt(asset.params.total),\n decimals: Number(asset.params.decimals),\n assetName: asset.params.name,\n assetNameAsBytes: asset.params.nameB64,\n unitName: asset.params.unitName,\n unitNameAsBytes: asset.params.unitNameB64,\n url: asset.params.url,\n urlAsBytes: asset.params.urlB64,\n creator: asset.params.creator,\n manager: asset.params.manager,\n clawback: asset.params.clawback,\n freeze: asset.params.freeze,\n reserve: asset.params.reserve,\n defaultFrozen: asset.params.defaultFrozen,\n metadataHash: asset.params.metadataHash,\n }\n }\n\n /**\n * Returns the given sender account's asset holding for a given asset.\n *\n * @example\n * ```typescript\n * const address = \"XBYLS2E6YI6XXL5BWCAMOA4GTWHXWENZMX5UHXMRNWWUQ7BXCY5WC5TEPA\";\n * const assetId = 123345n;\n * const accountInfo = await assetManager.getAccountInformation(address, assetId);\n * ```\n *\n * [Response data schema details](https://dev.algorand.co/reference/rest-apis/algod/#accountassetinformation)\n * @param sender The address of the sender/account to look up\n * @param assetId The ID of the asset to return a holding for\n * @returns The account asset holding information\n */\n public async getAccountInformation(sender: string | Address, assetId: bigint): Promise<AccountAssetInformation> {\n const info = await this._algod.accountAssetInformation(sender.toString(), assetId)\n\n return {\n assetId: BigInt(assetId),\n balance: BigInt(info.assetHolding?.amount ?? 0),\n frozen: info.assetHolding?.isFrozen === true,\n round: BigInt(info['round']),\n }\n }\n\n /**\n * Opt an account in to a list of Algorand Standard Assets.\n *\n * Transactions will be sent in batches of 16 as transaction groups.\n *\n * @param account The account to opt-in\n * @param assetIds The list of asset IDs to opt-in to\n * @param options Any parameters to control the transaction or execution of the transaction\n * @example Example using AlgorandClient\n * ```typescript\n * // Basic example\n * assetManager.bulkOptIn(\"ACCOUNTADDRESS\", [12345n, 67890n])\n * // With configuration\n * assetManager.bulkOptIn(\"ACCOUNTADDRESS\", [12345n, 67890n], { maxFee: (1000).microAlgo(), suppressLog: true })\n * ```\n * @returns An array of records matching asset ID to transaction ID of the opt in\n */\n async bulkOptIn(\n account: string | Address,\n assetIds: bigint[],\n options?: Omit<CommonTransactionParams, 'sender'> & SendParams,\n ): Promise<BulkAssetOptInOutResult[]> {\n const results: BulkAssetOptInOutResult[] = []\n\n for (const assetGroup of chunkArray(assetIds, MAX_TRANSACTION_GROUP_SIZE)) {\n const composer = this._newGroup()\n\n for (const assetId of assetGroup) {\n composer.addAssetOptIn({\n ...options,\n sender: account,\n assetId: BigInt(assetId),\n })\n }\n\n const result = await composer.send(options)\n\n Config.getLogger(options?.suppressLog).info(\n `Successfully opted in ${account} for assets ${assetGroup.join(', ')} with transaction IDs ${result.txIds.join(', ')}` +\n `\\n Grouped under ${result.groupId} in round ${result.confirmations?.[0]?.confirmedRound}.`,\n )\n\n assetGroup.forEach((assetId, index) => {\n results.push({ assetId: BigInt(assetId), transactionId: result.txIds[index] })\n })\n }\n\n return results\n }\n\n /**\n * Opt an account out of a list of Algorand Standard Assets.\n *\n * Transactions will be sent in batches of 16 as transaction groups.\n *\n * @param account The account to opt-in\n * @param assetIds The list of asset IDs to opt-out of\n * @param options Any parameters to control the transaction or execution of the transaction\n * @example Example using AlgorandClient\n * ```typescript\n * // Basic example\n * assetManager.bulkOptOut(\"ACCOUNTADDRESS\", [12345n, 67890n])\n * // With configuration\n * assetManager.bulkOptOut(\"ACCOUNTADDRESS\", [12345n, 67890n], { ensureZeroBalance: true, maxFee: (1000).microAlgo(), suppressLog: true })\n * ```\n * @returns An array of records matching asset ID to transaction ID of the opt in\n */\n async bulkOptOut(\n account: string | Address,\n assetIds: bigint[],\n options?: Omit<CommonTransactionParams, 'sender'> &\n SendParams & {\n /** Whether or not to check if the account has a zero balance for each asset first or not.\n *\n * Defaults to `true`.\n *\n * If this is set to `true` and the account has an asset balance it will throw an error.\n *\n * If this is set to `false` and the account has an asset balance it will lose those assets to the asset creator.\n */\n ensureZeroBalance?: boolean\n },\n ): Promise<BulkAssetOptInOutResult[]> {\n const results: BulkAssetOptInOutResult[] = []\n\n for (const assetGroup of chunkArray(assetIds, MAX_TRANSACTION_GROUP_SIZE)) {\n const composer = this._newGroup()\n\n const notOptedInAssetIds: bigint[] = []\n const nonZeroBalanceAssetIds: bigint[] = []\n for (const assetId of assetGroup) {\n if (options?.ensureZeroBalance !== false) {\n try {\n const accountAssetInfo = await this.getAccountInformation(account, assetId)\n if (accountAssetInfo.balance !== 0n) {\n nonZeroBalanceAssetIds.push(BigInt(assetId))\n }\n } catch {\n notOptedInAssetIds.push(BigInt(assetId))\n }\n }\n }\n\n if (notOptedInAssetIds.length > 0 || nonZeroBalanceAssetIds.length > 0) {\n throw new Error(\n `Account ${account}${notOptedInAssetIds.length > 0 ? ` is not opted-in to Asset${notOptedInAssetIds.length > 1 ? 's' : ''} ${notOptedInAssetIds.join(', ')}` : ''}${\n nonZeroBalanceAssetIds.length > 0\n ? ` has non-zero balance for Asset${nonZeroBalanceAssetIds.length > 1 ? 's' : ''} ${nonZeroBalanceAssetIds.join(', ')}`\n : ''\n }; can't opt-out.`,\n )\n }\n\n for (const assetId of assetGroup) {\n composer.addAssetOptOut({\n ...options,\n creator: (await this.getById(BigInt(assetId))).creator,\n sender: account,\n assetId: BigInt(assetId),\n })\n }\n\n const result = await composer.send(options)\n\n Config.getLogger(options?.suppressLog).info(\n `Successfully opted ${account} out of assets ${assetGroup.join(', ')} with transaction IDs ${result.txIds.join(', ')}` +\n `\\n Grouped under ${result.groupId} in round ${result.confirmations?.[0]?.confirmedRound}.`,\n )\n\n assetGroup.forEach((assetId, index) => {\n results.push({ assetId: BigInt(assetId), transactionId: result.txIds[index] })\n })\n }\n\n return results\n }\n}\n"],"mappings":";;;;;;AA0IA,IAAa,eAAb,MAA0B;CACxB,AAAQ;CACR,AAAQ;;;;;;;;;;CAWR,YAAY,OAAoB,UAAuE;AACrG,OAAK,SAAS;AACd,OAAK,YAAY;;;;;;;;;;;;;CAcnB,MAAa,QAAQ,SAA4C;EAC/D,MAAM,QAAQ,MAAM,KAAK,OAAO,aAAa,QAAQ;AAErD,SAAO;GACL,SAAS,OAAO,MAAM,GAAG;GACzB,OAAO,OAAO,MAAM,OAAO,MAAM;GACjC,UAAU,OAAO,MAAM,OAAO,SAAS;GACvC,WAAW,MAAM,OAAO;GACxB,kBAAkB,MAAM,OAAO;GAC/B,UAAU,MAAM,OAAO;GACvB,iBAAiB,MAAM,OAAO;GAC9B,KAAK,MAAM,OAAO;GAClB,YAAY,MAAM,OAAO;GACzB,SAAS,MAAM,OAAO;GACtB,SAAS,MAAM,OAAO;GACtB,UAAU,MAAM,OAAO;GACvB,QAAQ,MAAM,OAAO;GACrB,SAAS,MAAM,OAAO;GACtB,eAAe,MAAM,OAAO;GAC5B,cAAc,MAAM,OAAO;GAC5B;;;;;;;;;;;;;;;;;CAkBH,MAAa,sBAAsB,QAA0B,SAAmD;EAC9G,MAAM,OAAO,MAAM,KAAK,OAAO,wBAAwB,OAAO,UAAU,EAAE,QAAQ;AAElF,SAAO;GACL,SAAS,OAAO,QAAQ;GACxB,SAAS,OAAO,KAAK,cAAc,UAAU,EAAE;GAC/C,QAAQ,KAAK,cAAc,aAAa;GACxC,O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,GAAG,mBAAmB,KAAK,KAAK,KAAK,KAC7J,uBAAuB,SAAS,IAC5B,kCAAkC,uBAAuB,SAAS,IAAI,MAAM,GAAG,GAAG,uBAAuB,KAAK,KAAK,KACnH,GACL,kBACF;AAGH,QAAK,MAAM,WAAW,WACpB,UAAS,eAAe;IACtB,GAAG;IACH,UAAU,MAAM,KAAK,QAAQ,OAAO,QAAQ,CAAC,EAAE;IAC/C,QAAQ;IACR,SAAS,OAAO,QAAQ;IACzB,CAAC;GAGJ,MAAM,SAAS,MAAM,SAAS,KAAK,QAAQ;AAE3C,UAAO,UAAU,SAAS,YAAY,CAAC,KACrC,sBAAsB,QAAQ,iBAAiB,WAAW,KAAK,KAAK,CAAC,wBAAwB,OAAO,MAAM,KAAK,KAAK,qBAC7F,OAAO,QAAQ,YAAY,OAAO,gBAAgB,IAAI,eAAe,GAC7F;AAED,cAAW,SAAS,SAAS,UAAU;AACrC,YAAQ,KAAK;KAAE,SAAS,OAAO,QAAQ;KAAE,eAAe,OAAO,MAAM;KAAQ,CAAC;KAC9E;;AAGJ,SAAO"}
1
+ {"version":3,"file":"asset-manager.mjs","names":["results: BulkAssetOptInOutResult[]","notOptedInAssetIds: bigint[]","nonZeroBalanceAssetIds: bigint[]"],"sources":["../../src/types/asset-manager.ts"],"sourcesContent":["import { AlgodClient } from '@algorandfoundation/algokit-algod-client'\nimport { Address, MAX_TRANSACTION_GROUP_SIZE } from '@algorandfoundation/algokit-common'\nimport { Config } from '../config'\nimport { chunkArray } from '../util'\nimport { AccountAssetInformation } from './account'\nimport { CommonTransactionParams, TransactionComposer, TransactionComposerConfig } from './composer'\nimport { SendParams } from './transaction'\n\n/** Individual result from performing a bulk opt-in or bulk opt-out for an account against a series of assets. */\nexport interface BulkAssetOptInOutResult {\n /** The ID of the asset opted into / out of */\n assetId: bigint\n /** The transaction ID of the resulting opt in / out */\n transactionId: string\n}\n\n/** Information about an asset. */\nexport interface AssetInformation {\n /** The ID of the asset. */\n assetId: bigint\n\n /** The address of the account that created the asset.\n *\n * This is the address where the parameters for this asset can be found,\n * and also the address where unwanted asset units can be sent when\n * closing out an asset position and opting-out of the asset.\n */\n creator: string\n\n /** The total amount of the smallest divisible (decimal) units that were created of the asset.\n *\n * For example, if `decimals` is, say, 2, then for every 100 `total` there is 1 whole unit.\n */\n total: bigint\n\n /** The amount of decimal places the asset was created with.\n *\n * * If 0, the asset is not divisible;\n * * If 1, the base unit of the asset is in tenths;\n * * If 2, the base unit of the asset is in hundredths;\n * * If 3, the base unit of the asset is in thousandths;\n * * and so on up to 19 decimal places.\n */\n decimals: number\n\n /** Whether the asset was frozen by default for all accounts.\n *\n * If `true` then for anyone apart from the creator to hold the\n * asset it needs to be unfrozen per account using an asset freeze\n * transaction from the `freeze` account.\n */\n defaultFrozen?: boolean\n\n /** The address of the optional account that can manage the configuration of the asset and destroy it.\n *\n * If not set the asset is permanently immutable.\n */\n manager?: string\n\n /**\n * The address of the optional account that holds the reserve (uncirculated supply) units of the asset.\n *\n * This address has no specific authority in the protocol itself and is informational only.\n *\n * Some standards like [ARC-19](https://github.com/algorandfoundation/ARCs/blob/main/ARCs/arc-0019.md)\n * rely on this field to hold meaningful data.\n *\n * It can be used in the case where you want to signal to holders of your asset that the uncirculated units\n * of the asset reside in an account that is different from the default creator account.\n *\n * If not set the field is permanently empty.\n */\n reserve?: string\n\n /**\n * The address of the optional account that can be used to freeze or unfreeze holdings of this asset for any account.\n *\n * If empty, freezing is not permitted.\n *\n * If not set the field is permanently empty.\n */\n freeze?: string\n\n /**\n * The address of the optional account that can clawback holdings of this asset from any account.\n *\n * The clawback account has the ability to **unconditionally take assets from any account**.\n *\n * If empty, clawback is not permitted.\n *\n * If not set the field is permanently empty.\n */\n clawback?: string\n\n /** The optional name of the unit of this asset (e.g. ticker name).\n *\n * Max size is 8 bytes.\n */\n unitName?: string\n\n /** The optional name of the unit of this asset (e.g. ticker name).\n *\n * Max size is 8 bytes.\n */\n unitNameAsBytes?: Uint8Array\n\n /** The optional name of the asset.\n *\n * Max size is 32 bytes.\n */\n assetName?: string\n\n /** The optional name of the asset.\n *\n * Max size is 32 bytes.\n */\n assetNameAsBytes?: Uint8Array\n\n /** Optional URL where more information about the asset can be retrieved (e.g. metadata).\n *\n * Max size is 96 bytes.\n */\n url?: string\n\n /** Optional URL where more information about the asset can be retrieved (e.g. metadata).\n *\n * Max size is 96 bytes.\n */\n urlAsBytes?: Uint8Array\n\n /** 32-byte hash of some metadata that is relevant to the asset and/or asset holders.\n *\n * The format of this metadata is up to the application.\n */\n metadataHash?: Uint8Array\n}\n\n/** Allows management of asset information. */\nexport class AssetManager {\n private _algod: AlgodClient\n private _newGroup: () => TransactionComposer\n\n /**\n * Create a new asset manager.\n * @param algod An algod client\n * @param newGroup A function that creates a new `TransactionComposer` transaction group\n * @example Create a new asset manager\n * ```typescript\n * const assetManager = new AssetManager(algod, () => new TransactionComposer({algod, () => signer, () => suggestedParams}))\n * ```\n */\n constructor(algod: AlgodClient, newGroup: (config?: TransactionComposerConfig) => TransactionComposer) {\n this._algod = algod\n this._newGroup = newGroup\n }\n\n /**\n * Returns the current asset information for the asset with the given ID.\n *\n * @example\n * ```typescript\n * const assetInfo = await assetManager.getById(12353n);\n * ```\n *\n * @param assetId The ID of the asset\n * @returns The asset information\n */\n public async getById(assetId: bigint): Promise<AssetInformation> {\n const asset = await this._algod.assetById(assetId)\n\n return {\n assetId: BigInt(asset.id),\n total: BigInt(asset.params.total),\n decimals: Number(asset.params.decimals),\n assetName: asset.params.name,\n assetNameAsBytes: asset.params.nameB64,\n unitName: asset.params.unitName,\n unitNameAsBytes: asset.params.unitNameB64,\n url: asset.params.url,\n urlAsBytes: asset.params.urlB64,\n creator: asset.params.creator,\n manager: asset.params.manager,\n clawback: asset.params.clawback,\n freeze: asset.params.freeze,\n reserve: asset.params.reserve,\n defaultFrozen: asset.params.defaultFrozen,\n metadataHash: asset.params.metadataHash,\n }\n }\n\n /**\n * Returns the given sender account's asset holding for a given asset.\n *\n * @example\n * ```typescript\n * const address = \"XBYLS2E6YI6XXL5BWCAMOA4GTWHXWENZMX5UHXMRNWWUQ7BXCY5WC5TEPA\";\n * const assetId = 123345n;\n * const accountInfo = await assetManager.getAccountInformation(address, assetId);\n * ```\n *\n * [Response data schema details](https://dev.algorand.co/reference/rest-apis/algod/#accountassetinformation)\n * @param sender The address of the sender/account to look up\n * @param assetId The ID of the asset to return a holding for\n * @returns The account asset holding information\n */\n public async getAccountInformation(sender: string | Address, assetId: bigint): Promise<AccountAssetInformation> {\n const info = await this._algod.accountAssetInformation(sender.toString(), assetId)\n\n return {\n assetId: BigInt(assetId),\n balance: BigInt(info.assetHolding?.amount ?? 0),\n frozen: info.assetHolding?.isFrozen === true,\n round: BigInt(info['round']),\n }\n }\n\n /**\n * Opt an account in to a list of Algorand Standard Assets.\n *\n * Transactions will be sent in batches of 16 as transaction groups.\n *\n * @param account The account to opt-in\n * @param assetIds The list of asset IDs to opt-in to\n * @param options Any parameters to control the transaction or execution of the transaction\n * @example Example using AlgorandClient\n * ```typescript\n * // Basic example\n * assetManager.bulkOptIn(\"ACCOUNTADDRESS\", [12345n, 67890n])\n * // With configuration\n * assetManager.bulkOptIn(\"ACCOUNTADDRESS\", [12345n, 67890n], { maxFee: (1000).microAlgo(), suppressLog: true })\n * ```\n * @returns An array of records matching asset ID to transaction ID of the opt in\n */\n async bulkOptIn(\n account: string | Address,\n assetIds: bigint[],\n options?: Omit<CommonTransactionParams, 'sender'> & SendParams,\n ): Promise<BulkAssetOptInOutResult[]> {\n const results: BulkAssetOptInOutResult[] = []\n\n for (const assetGroup of chunkArray(assetIds, MAX_TRANSACTION_GROUP_SIZE)) {\n const composer = this._newGroup()\n\n for (const assetId of assetGroup) {\n composer.addAssetOptIn({\n ...options,\n sender: account,\n assetId: BigInt(assetId),\n })\n }\n\n const result = await composer.send(options)\n\n Config.getLogger(options?.suppressLog).info(\n `Successfully opted in ${account} for assets ${assetGroup.join(', ')} with transaction IDs ${result.txIds.join(', ')}` +\n `\\n Grouped under ${result.groupId} in round ${result.confirmations?.[0]?.confirmedRound}.`,\n )\n\n assetGroup.forEach((assetId, index) => {\n results.push({ assetId: BigInt(assetId), transactionId: result.txIds[index] })\n })\n }\n\n return results\n }\n\n /**\n * Opt an account out of a list of Algorand Standard Assets.\n *\n * Transactions will be sent in batches of 16 as transaction groups.\n *\n * @param account The account to opt-in\n * @param assetIds The list of asset IDs to opt-out of\n * @param options Any parameters to control the transaction or execution of the transaction\n * @example Example using AlgorandClient\n * ```typescript\n * // Basic example\n * assetManager.bulkOptOut(\"ACCOUNTADDRESS\", [12345n, 67890n])\n * // With configuration\n * assetManager.bulkOptOut(\"ACCOUNTADDRESS\", [12345n, 67890n], { ensureZeroBalance: true, maxFee: (1000).microAlgo(), suppressLog: true })\n * ```\n * @returns An array of records matching asset ID to transaction ID of the opt in\n */\n async bulkOptOut(\n account: string | Address,\n assetIds: bigint[],\n options?: Omit<CommonTransactionParams, 'sender'> &\n SendParams & {\n /** Whether or not to check if the account has a zero balance for each asset first or not.\n *\n * Defaults to `true`.\n *\n * If this is set to `true` and the account has an asset balance it will throw an error.\n *\n * If this is set to `false` and the account has an asset balance it will lose those assets to the asset creator.\n */\n ensureZeroBalance?: boolean\n },\n ): Promise<BulkAssetOptInOutResult[]> {\n const results: BulkAssetOptInOutResult[] = []\n\n for (const assetGroup of chunkArray(assetIds, MAX_TRANSACTION_GROUP_SIZE)) {\n const composer = this._newGroup()\n\n const notOptedInAssetIds: bigint[] = []\n const nonZeroBalanceAssetIds: bigint[] = []\n for (const assetId of assetGroup) {\n if (options?.ensureZeroBalance !== false) {\n try {\n const accountAssetInfo = await this.getAccountInformation(account, assetId)\n if (accountAssetInfo.balance !== 0n) {\n nonZeroBalanceAssetIds.push(BigInt(assetId))\n }\n } catch {\n notOptedInAssetIds.push(BigInt(assetId))\n }\n }\n }\n\n if (notOptedInAssetIds.length > 0 || nonZeroBalanceAssetIds.length > 0) {\n throw new Error(\n `Account ${account}${notOptedInAssetIds.length > 0 ? ` is not opted-in to Asset${notOptedInAssetIds.length > 1 ? 's' : ''} ${notOptedInAssetIds.join(', ')}` : ''}${\n nonZeroBalanceAssetIds.length > 0\n ? ` has non-zero balance for Asset${nonZeroBalanceAssetIds.length > 1 ? 's' : ''} ${nonZeroBalanceAssetIds.join(', ')}`\n : ''\n }; can't opt-out.`,\n )\n }\n\n for (const assetId of assetGroup) {\n composer.addAssetOptOut({\n ...options,\n creator: (await this.getById(BigInt(assetId))).creator,\n sender: account,\n assetId: BigInt(assetId),\n })\n }\n\n const result = await composer.send(options)\n\n Config.getLogger(options?.suppressLog).info(\n `Successfully opted ${account} out of assets ${assetGroup.join(', ')} with transaction IDs ${result.txIds.join(', ')}` +\n `\\n Grouped under ${result.groupId} in round ${result.confirmations?.[0]?.confirmedRound}.`,\n )\n\n assetGroup.forEach((assetId, index) => {\n results.push({ assetId: BigInt(assetId), transactionId: result.txIds[index] })\n })\n }\n\n return results\n }\n}\n"],"mappings":";;;;;;AA0IA,IAAa,eAAb,MAA0B;CACxB,AAAQ;CACR,AAAQ;;;;;;;;;;CAWR,YAAY,OAAoB,UAAuE;AACrG,OAAK,SAAS;AACd,OAAK,YAAY;;;;;;;;;;;;;CAcnB,MAAa,QAAQ,SAA4C;EAC/D,MAAM,QAAQ,MAAM,KAAK,OAAO,UAAU,QAAQ;AAElD,SAAO;GACL,SAAS,OAAO,MAAM,GAAG;GACzB,OAAO,OAAO,MAAM,OAAO,MAAM;GACjC,UAAU,OAAO,MAAM,OAAO,SAAS;GACvC,WAAW,MAAM,OAAO;GACxB,kBAAkB,MAAM,OAAO;GAC/B,UAAU,MAAM,OAAO;GACvB,iBAAiB,MAAM,OAAO;GAC9B,KAAK,MAAM,OAAO;GAClB,YAAY,MAAM,OAAO;GACzB,SAAS,MAAM,OAAO;GACtB,SAAS,MAAM,OAAO;GACtB,UAAU,MAAM,OAAO;GACvB,QAAQ,MAAM,OAAO;GACrB,SAAS,MAAM,OAAO;GACtB,eAAe,MAAM,OAA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yB,MAAM,KAAK,sBAAsB,SAAS,QAAQ,EACtD,YAAY,GAC/B,wBAAuB,KAAK,OAAO,QAAQ,CAAC;WAExC;AACN,uBAAmB,KAAK,OAAO,QAAQ,CAAC;;AAK9C,OAAI,mBAAmB,SAAS,KAAK,uBAAuB,SAAS,EACnE,OAAM,IAAI,MACR,WAAW,UAAU,mBAAmB,SAAS,IAAI,4BAA4B,mBAAmB,SAAS,IAAI,MAAM,GAAG,GAAG,mBAAmB,KAAK,KAAK,KAAK,KAC7J,uBAAuB,SAAS,IAC5B,kCAAkC,uBAAuB,SAAS,IAAI,MAAM,GAAG,GAAG,uBAAuB,KAAK,KAAK,KACnH,GACL,kBACF;AAGH,QAAK,MAAM,WAAW,WACpB,UAAS,eAAe;IACtB,GAAG;IACH,UAAU,MAAM,KAAK,QAAQ,OAAO,QAAQ,CAAC,EAAE;IAC/C,QAAQ;IACR,SAAS,OAAO,QAAQ;IACzB,CAAC;GAGJ,MAAM,SAAS,MAAM,SAAS,KAAK,QAAQ;AAE3C,UAAO,UAAU,SAAS,YAAY,CAAC,KACrC,sBAAsB,QAAQ,iBAAiB,WAAW,KAAK,KAAK,CAAC,wBAAwB,OAAO,MAAM,KAAK,KAAK,qBAC7F,OAAO,QAAQ,YAAY,OAAO,gBAAgB,IAAI,eAAe,GAC7F;AAED,cAAW,SAAS,SAAS,UAAU;AACrC,YAAQ,KAAK;KAAE,SAAS,OAAO,QAAQ;KAAE,eAAe,OAAO,MAAM;KAAQ,CAAC;KAC9E;;AAGJ,SAAO"}
@@ -102,6 +102,7 @@ declare class TransactionComposer {
102
102
  private signedTransactions?;
103
103
  private rawBuildTransactions?;
104
104
  private transformError;
105
+ private validateReferenceParams;
105
106
  /**
106
107
  * Create a `TransactionComposer`.
107
108
  * @param params The configuration for this composer
@@ -432,6 +433,7 @@ declare class TransactionComposer {
432
433
  * // Max fee doesn't make sense with extraFee AND staticFee
433
434
  * // already specified, but here for completeness
434
435
  * maxFee: (3000).microAlgo(),
436
+ * rejectVersion: 1,
435
437
  * // Signer only needed if you want to provide one,
436
438
  * // generally you'd register it with AlgorandClient
437
439
  * // against the sender and not need to pass it in
@@ -475,6 +477,7 @@ declare class TransactionComposer {
475
477
  * // Max fee doesn't make sense with extraFee AND staticFee
476
478
  * // already specified, but here for completeness
477
479
  * maxFee: (3000).microAlgo(),
480
+ * rejectVersion: 1,
478
481
  *})
479
482
  * ```
480
483
  */
@@ -510,6 +513,7 @@ declare class TransactionComposer {
510
513
  * // Max fee doesn't make sense with extraFee AND staticFee
511
514
  * // already specified, but here for completeness
512
515
  * maxFee: (3000).microAlgo(),
516
+ * rejectVersion: 1,
513
517
  *})
514
518
  * ```
515
519
  */
@@ -547,6 +551,7 @@ declare class TransactionComposer {
547
551
  * // Max fee doesn't make sense with extraFee AND staticFee
548
552
  * // already specified, but here for completeness
549
553
  * maxFee: (3000).microAlgo(),
554
+ * rejectVersion: 1,
550
555
  *})
551
556
  * ```
552
557
  */
@@ -603,6 +608,7 @@ declare class TransactionComposer {
603
608
  * // Max fee doesn't make sense with extraFee AND staticFee
604
609
  * // already specified, but here for completeness
605
610
  * maxFee: (3000).microAlgo(),
611
+ * rejectVersion: 1,
606
612
  *})
607
613
  * ```
608
614
  */
@@ -652,6 +658,7 @@ declare class TransactionComposer {
652
658
  * // Max fee doesn't make sense with extraFee AND staticFee
653
659
  * // already specified, but here for completeness
654
660
  * maxFee: (3000).microAlgo(),
661
+ * rejectVersion: 1,
655
662
  *})
656
663
  * ```
657
664
  */
@@ -699,6 +706,7 @@ declare class TransactionComposer {
699
706
  * // Max fee doesn't make sense with extraFee AND staticFee
700
707
  * // already specified, but here for completeness
701
708
  * maxFee: (3000).microAlgo(),
709
+ * rejectVersion: 1,
702
710
  *})
703
711
  * ```
704
712
  */
@@ -746,6 +754,7 @@ declare class TransactionComposer {
746
754
  * // Max fee doesn't make sense with extraFee AND staticFee
747
755
  * // already specified, but here for completeness
748
756
  * maxFee: (3000).microAlgo(),
757
+ * rejectVersion: 1,
749
758
  *})
750
759
  * ```
751
760
  */
package/types/composer.js CHANGED
@@ -20,7 +20,6 @@ const require_payment = require('../transactions/payment.js');
20
20
  const require_lifecycle_events = require('./lifecycle-events.js');
21
21
  const require_network_client = require('./network-client.js');
22
22
  let buffer = require("buffer");
23
- buffer = require_rolldown_runtime.__toESM(buffer);
24
23
 
25
24
  //#region src/types/composer.ts
26
25
  var InvalidErrorTransformerValue = class extends Error {
@@ -64,6 +63,9 @@ var TransactionComposer = class TransactionComposer {
64
63
  }
65
64
  return transformedError;
66
65
  }
66
+ validateReferenceParams(params) {
67
+ if (params.accessReferences && params.accessReferences.length > 0 && (params.appReferences && params.appReferences.length > 0 || params.assetReferences && params.assetReferences.length > 0 || params.boxReferences && params.boxReferences.length > 0)) throw new Error("Cannot specify both `accessReferences` and reference arrays (`appReferences`, `assetReferences`, `boxReferences`).");
68
+ }
67
69
  /**
68
70
  * Create a `TransactionComposer`.
69
71
  * @param params The configuration for this composer
@@ -569,6 +571,7 @@ var TransactionComposer = class TransactionComposer {
569
571
  * // Max fee doesn't make sense with extraFee AND staticFee
570
572
  * // already specified, but here for completeness
571
573
  * maxFee: (3000).microAlgo(),
574
+ * rejectVersion: 1,
572
575
  * // Signer only needed if you want to provide one,
573
576
  * // generally you'd register it with AlgorandClient
574
577
  * // against the sender and not need to pass it in
@@ -579,6 +582,7 @@ var TransactionComposer = class TransactionComposer {
579
582
  * ```
580
583
  */
581
584
  addAppCreate(params) {
585
+ this.validateReferenceParams(params);
582
586
  this.push({
583
587
  data: params,
584
588
  type: "appCall"
@@ -618,10 +622,12 @@ var TransactionComposer = class TransactionComposer {
618
622
  * // Max fee doesn't make sense with extraFee AND staticFee
619
623
  * // already specified, but here for completeness
620
624
  * maxFee: (3000).microAlgo(),
625
+ * rejectVersion: 1,
621
626
  *})
622
627
  * ```
623
628
  */
624
629
  addAppUpdate(params) {
630
+ this.validateReferenceParams(params);
625
631
  this.push({
626
632
  data: {
627
633
  ...params,
@@ -662,10 +668,12 @@ var TransactionComposer = class TransactionComposer {
662
668
  * // Max fee doesn't make sense with extraFee AND staticFee
663
669
  * // already specified, but here for completeness
664
670
  * maxFee: (3000).microAlgo(),
671
+ * rejectVersion: 1,
665
672
  *})
666
673
  * ```
667
674
  */
668
675
  addAppDelete(params) {
676
+ this.validateReferenceParams(params);
669
677
  this.push({
670
678
  data: {
671
679
  ...params,
@@ -708,10 +716,12 @@ var TransactionComposer = class TransactionComposer {
708
716
  * // Max fee doesn't make sense with extraFee AND staticFee
709
717
  * // already specified, but here for completeness
710
718
  * maxFee: (3000).microAlgo(),
719
+ * rejectVersion: 1,
711
720
  *})
712
721
  * ```
713
722
  */
714
723
  addAppCall(params) {
724
+ this.validateReferenceParams(params);
715
725
  this.push({
716
726
  data: params,
717
727
  type: "appCall"
@@ -770,10 +780,12 @@ var TransactionComposer = class TransactionComposer {
770
780
  * // Max fee doesn't make sense with extraFee AND staticFee
771
781
  * // already specified, but here for completeness
772
782
  * maxFee: (3000).microAlgo(),
783
+ * rejectVersion: 1,
773
784
  *})
774
785
  * ```
775
786
  */
776
787
  addAppCreateMethodCall(params) {
788
+ this.validateReferenceParams(params);
777
789
  const txnArgs = require_method_call.extractComposerTransactionsFromAppMethodCallParams(params);
778
790
  this.push(...txnArgs, {
779
791
  data: {
@@ -829,10 +841,12 @@ var TransactionComposer = class TransactionComposer {
829
841
  * // Max fee doesn't make sense with extraFee AND staticFee
830
842
  * // already specified, but here for completeness
831
843
  * maxFee: (3000).microAlgo(),
844
+ * rejectVersion: 1,
832
845
  *})
833
846
  * ```
834
847
  */
835
848
  addAppUpdateMethodCall(params) {
849
+ this.validateReferenceParams(params);
836
850
  const txnArgs = require_method_call.extractComposerTransactionsFromAppMethodCallParams(params);
837
851
  this.push(...txnArgs, {
838
852
  data: {
@@ -887,10 +901,12 @@ var TransactionComposer = class TransactionComposer {
887
901
  * // Max fee doesn't make sense with extraFee AND staticFee
888
902
  * // already specified, but here for completeness
889
903
  * maxFee: (3000).microAlgo(),
904
+ * rejectVersion: 1,
890
905
  *})
891
906
  * ```
892
907
  */
893
908
  addAppDeleteMethodCall(params) {
909
+ this.validateReferenceParams(params);
894
910
  const txnArgs = require_method_call.extractComposerTransactionsFromAppMethodCallParams(params);
895
911
  this.push(...txnArgs, {
896
912
  data: {
@@ -945,10 +961,12 @@ var TransactionComposer = class TransactionComposer {
945
961
  * // Max fee doesn't make sense with extraFee AND staticFee
946
962
  * // already specified, but here for completeness
947
963
  * maxFee: (3000).microAlgo(),
964
+ * rejectVersion: 1,
948
965
  *})
949
966
  * ```
950
967
  */
951
968
  addAppCallMethodCall(params) {
969
+ this.validateReferenceParams(params);
952
970
  const txnArgs = require_method_call.extractComposerTransactionsFromAppMethodCallParams(params);
953
971
  this.push(...txnArgs, {
954
972
  data: {
@@ -1067,7 +1085,7 @@ var TransactionComposer = class TransactionComposer {
1067
1085
  if (!this.transactionsWithSigners) {
1068
1086
  const suggestedParams = await this.getSuggestedParams();
1069
1087
  const builtTransactions = await this._buildTransactions(suggestedParams);
1070
- this.rawBuildTransactions = builtTransactions.transactions;
1088
+ this.rawBuildTransactions = builtTransactions.transactions.map((txn) => new require_transaction.Transaction({ ...txn }));
1071
1089
  const groupAnalysis = (this.composerConfig.coverAppCallInnerTransactionFees || this.composerConfig.populateAppCallResources) && builtTransactions.transactions.some((txn) => txn.type === require_transaction_type.TransactionType.AppCall) ? await this.analyzeGroupRequirements(builtTransactions.transactions, suggestedParams, this.composerConfig) : void 0;
1072
1090
  this.populateTransactionAndGroupResources(builtTransactions.transactions, groupAnalysis);
1073
1091
  this.transactionsWithSigners = builtTransactions.transactions.map((txn, index) => {
@@ -1127,7 +1145,7 @@ var TransactionComposer = class TransactionComposer {
1127
1145
  transaction = require_asset_transfer.buildAssetOptOut(ctxn.data, suggestedParams, defaultValidityWindow);
1128
1146
  break;
1129
1147
  case "appCall":
1130
- if (!("appId" in ctxn.data)) transaction = await require_app_call$1.buildAppCreate(ctxn.data, this.appManager, suggestedParams, defaultValidityWindow);
1148
+ if (ctxn.data.appId === void 0 || ctxn.data.appId === 0) transaction = await require_app_call$1.buildAppCreate(ctxn.data, this.appManager, suggestedParams, defaultValidityWindow);
1131
1149
  else if ("approvalProgram" in ctxn.data && "clearStateProgram" in ctxn.data) transaction = await require_app_call$1.buildAppUpdate(ctxn.data, this.appManager, suggestedParams, defaultValidityWindow);
1132
1150
  else transaction = require_app_call$1.buildAppCall(ctxn.data, suggestedParams, defaultValidityWindow);
1133
1151
  break;
@@ -1135,7 +1153,7 @@ var TransactionComposer = class TransactionComposer {
1135
1153
  transaction = require_key_registration.buildKeyReg(ctxn.data, suggestedParams, defaultValidityWindow);
1136
1154
  break;
1137
1155
  case "methodCall":
1138
- if (!("appId" in ctxn.data)) transaction = await require_method_call.buildAppCreateMethodCall(ctxn.data, this.appManager, suggestedParams, defaultValidityWindow);
1156
+ if (ctxn.data.appId === void 0 || ctxn.data.appId === 0) transaction = await require_method_call.buildAppCreateMethodCall(ctxn.data, this.appManager, suggestedParams, defaultValidityWindow);
1139
1157
  else if ("approvalProgram" in ctxn.data && "clearStateProgram" in ctxn.data) transaction = await require_method_call.buildAppUpdateMethodCall(ctxn.data, this.appManager, suggestedParams, defaultValidityWindow);
1140
1158
  else transaction = await require_method_call.buildAppCallMethodCall(ctxn.data, suggestedParams, defaultValidityWindow);
1141
1159
  break;
@@ -1303,13 +1321,13 @@ var TransactionComposer = class TransactionComposer {
1303
1321
  sortedResources.assets?.sort(compare);
1304
1322
  sortedResources.apps?.sort(compare);
1305
1323
  sortedResources.boxes?.sort((a, b) => {
1306
- return compare(`${a.app}-${a.name}`, `${b.app}-${b.name}`);
1324
+ return compare(`${a.appId}-${a.name}`, `${b.appId}-${b.name}`);
1307
1325
  });
1308
1326
  sortedResources.appLocals?.sort((a, b) => {
1309
- return compare(`${a.app}-${a.account}`, `${b.app}-${b.account}`);
1327
+ return compare(`${a.appId}-${a.address}`, `${b.appId}-${b.address}`);
1310
1328
  });
1311
1329
  sortedResources.assetHoldings?.sort((a, b) => {
1312
- return compare(`${a.asset}-${a.account}`, `${b.asset}-${b.account}`);
1330
+ return compare(`${a.assetId}-${a.address}`, `${b.assetId}-${b.address}`);
1313
1331
  });
1314
1332
  }
1315
1333
  return {
@@ -1436,7 +1454,7 @@ var TransactionComposer = class TransactionComposer {
1436
1454
  }
1437
1455
  }
1438
1456
  async simulate(options) {
1439
- const { skipSignatures = false, resultOnFailure = false,...rawOptions } = options ?? {};
1457
+ const { skipSignatures = false, resultOnFailure = false, ...rawOptions } = options ?? {};
1440
1458
  if (skipSignatures) {
1441
1459
  rawOptions.allowEmptySignatures = true;
1442
1460
  rawOptions.fixSigners = true;
@@ -1533,11 +1551,8 @@ var TransactionComposer = class TransactionComposer {
1533
1551
  const confirmation = confirmations[i];
1534
1552
  const txn = this.txns[i];
1535
1553
  if (txn?.type !== "methodCall") continue;
1536
- const method = txn.data.method;
1537
- if (method.returns.type !== "void") {
1538
- const abiReturn = require_app_manager.AppManager.getABIReturn(confirmation, method);
1539
- if (abiReturn !== void 0) abiReturns.push(abiReturn);
1540
- }
1554
+ const abiReturn = require_app_manager.AppManager.getABIReturn(confirmation, txn.data.method);
1555
+ if (abiReturn !== void 0) abiReturns.push(abiReturn);
1541
1556
  }
1542
1557
  return abiReturns;
1543
1558
  }