@aptos-labs/ts-sdk 0.0.7 → 0.0.8

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 (423) hide show
  1. package/README.md +17 -1
  2. package/dist/browser/index.d.ts +798 -446
  3. package/dist/browser/index.global.js +30 -30
  4. package/dist/browser/index.global.js.map +1 -1
  5. package/dist/common/index.d.ts +798 -446
  6. package/dist/common/index.js +29 -29
  7. package/dist/common/index.js.map +1 -1
  8. package/dist/esm/api/account.d.mts +72 -47
  9. package/dist/esm/api/account.mjs +1 -1
  10. package/dist/esm/api/ans.d.mts +19 -17
  11. package/dist/esm/api/ans.mjs +1 -1
  12. package/dist/esm/api/aptos.d.mts +1 -0
  13. package/dist/esm/api/aptos.mjs +1 -1
  14. package/dist/esm/api/aptosConfig.d.mts +2 -2
  15. package/dist/esm/api/aptosConfig.mjs +1 -1
  16. package/dist/esm/api/coin.d.mts +4 -3
  17. package/dist/esm/api/coin.mjs +1 -1
  18. package/dist/esm/api/digitalAsset.d.mts +21 -18
  19. package/dist/esm/api/digitalAsset.mjs +1 -1
  20. package/dist/esm/api/event.d.mts +12 -14
  21. package/dist/esm/api/event.mjs +1 -1
  22. package/dist/esm/api/faucet.d.mts +4 -4
  23. package/dist/esm/api/faucet.mjs +1 -1
  24. package/dist/esm/api/fungibleAsset.d.mts +71 -30
  25. package/dist/esm/api/fungibleAsset.mjs +1 -1
  26. package/dist/esm/api/general.d.mts +12 -5
  27. package/dist/esm/api/general.mjs +1 -1
  28. package/dist/esm/api/index.d.mts +1 -0
  29. package/dist/esm/api/index.mjs +1 -1
  30. package/dist/esm/api/staking.d.mts +13 -9
  31. package/dist/esm/api/staking.mjs +1 -1
  32. package/dist/esm/api/transaction.d.mts +36 -2
  33. package/dist/esm/api/transaction.mjs +1 -1
  34. package/dist/esm/api/transactionSubmission/build.d.mts +1 -0
  35. package/dist/esm/api/transactionSubmission/build.mjs +1 -1
  36. package/dist/esm/api/transactionSubmission/sign.d.mts +1 -0
  37. package/dist/esm/api/transactionSubmission/sign.mjs +1 -1
  38. package/dist/esm/api/transactionSubmission/simulate.d.mts +1 -0
  39. package/dist/esm/api/transactionSubmission/simulate.mjs +1 -1
  40. package/dist/esm/api/transactionSubmission/submit.d.mts +1 -0
  41. package/dist/esm/api/transactionSubmission/submit.mjs +1 -1
  42. package/dist/esm/api/transactionSubmission.d.mts +23 -1
  43. package/dist/esm/api/transactionSubmission.mjs +1 -1
  44. package/dist/esm/api/utils.d.mts +21 -0
  45. package/dist/esm/api/utils.mjs +2 -0
  46. package/dist/esm/bcs/deserializer.d.mts +4 -4
  47. package/dist/esm/bcs/deserializer.mjs +1 -1
  48. package/dist/esm/bcs/index.mjs +1 -1
  49. package/dist/esm/bcs/serializable/entryFunctionBytes.mjs +1 -1
  50. package/dist/esm/bcs/serializable/fixedBytes.mjs +1 -1
  51. package/dist/esm/bcs/serializable/movePrimitives.mjs +1 -1
  52. package/dist/esm/bcs/serializable/moveStructs.mjs +1 -1
  53. package/dist/esm/bcs/serializer.d.mts +4 -4
  54. package/dist/esm/bcs/serializer.mjs +1 -1
  55. package/dist/esm/{chunk-UAAI3NCA.mjs → chunk-2SAKPC5Q.mjs} +2 -2
  56. package/dist/esm/{chunk-3732I6BR.mjs → chunk-2YQXX64E.mjs} +2 -2
  57. package/dist/esm/chunk-3F5WV6US.mjs +2 -0
  58. package/dist/esm/chunk-3F5WV6US.mjs.map +1 -0
  59. package/dist/esm/{chunk-ARVSIDVB.mjs → chunk-3RMXGSHK.mjs} +2 -2
  60. package/dist/esm/chunk-3RMXGSHK.mjs.map +1 -0
  61. package/dist/esm/{chunk-4ADA5BE7.mjs → chunk-53DS6NBQ.mjs} +2 -2
  62. package/dist/esm/chunk-5CUNY7X2.mjs +2 -0
  63. package/dist/esm/chunk-5CUNY7X2.mjs.map +1 -0
  64. package/dist/esm/{chunk-QWVR4RCV.mjs → chunk-5OPOJ43H.mjs} +2 -2
  65. package/dist/esm/{chunk-72F5YXGC.mjs → chunk-5UY5OKXR.mjs} +2 -2
  66. package/dist/esm/chunk-5UY5OKXR.mjs.map +1 -0
  67. package/dist/esm/chunk-5ZVCSKFX.mjs +2 -0
  68. package/dist/esm/chunk-5ZVCSKFX.mjs.map +1 -0
  69. package/dist/esm/{chunk-HVADSXTB.mjs → chunk-73VWOS4Z.mjs} +2 -2
  70. package/dist/esm/chunk-ALFESCPU.mjs +2 -0
  71. package/dist/esm/chunk-ALFESCPU.mjs.map +1 -0
  72. package/dist/esm/chunk-APSQ4M23.mjs +2 -0
  73. package/dist/esm/chunk-APSQ4M23.mjs.map +1 -0
  74. package/dist/esm/{chunk-U25N2VWA.mjs → chunk-AZUWHKN5.mjs} +2 -2
  75. package/dist/esm/{chunk-UDBH4CER.mjs → chunk-BQSE5HHW.mjs} +7 -7
  76. package/dist/esm/chunk-BQSE5HHW.mjs.map +1 -0
  77. package/dist/esm/chunk-CCXMVVXD.mjs +2 -0
  78. package/dist/esm/chunk-CCXMVVXD.mjs.map +1 -0
  79. package/dist/esm/{chunk-JZNLZMUC.mjs → chunk-CJPCOS4R.mjs} +2 -2
  80. package/dist/esm/{chunk-S36IYY6K.mjs → chunk-CL5B2QNS.mjs} +2 -2
  81. package/dist/esm/chunk-CLJLQXFQ.mjs +2 -0
  82. package/dist/esm/chunk-CLJLQXFQ.mjs.map +1 -0
  83. package/dist/esm/{chunk-EWTHPMEE.mjs → chunk-CU2DINU4.mjs} +2 -2
  84. package/dist/esm/{chunk-5LO7FR2P.mjs → chunk-EFRFDFS4.mjs} +2 -2
  85. package/dist/esm/chunk-EOC4UI5B.mjs +2 -0
  86. package/dist/esm/{chunk-KC64ESLO.mjs.map → chunk-EOC4UI5B.mjs.map} +1 -1
  87. package/dist/esm/{chunk-HA6JD5R6.mjs → chunk-F6K26WV5.mjs} +2 -2
  88. package/dist/esm/{chunk-HA6JD5R6.mjs.map → chunk-F6K26WV5.mjs.map} +1 -1
  89. package/dist/esm/chunk-F7EWDYTE.mjs +2 -0
  90. package/dist/esm/chunk-F7EWDYTE.mjs.map +1 -0
  91. package/dist/esm/{chunk-44MGBJ73.mjs → chunk-FZ56IS3E.mjs} +2 -2
  92. package/dist/esm/chunk-G36AY4R7.mjs +2 -0
  93. package/dist/esm/chunk-G36AY4R7.mjs.map +1 -0
  94. package/dist/esm/chunk-GEZSEAL5.mjs +2 -0
  95. package/dist/esm/chunk-GEZSEAL5.mjs.map +1 -0
  96. package/dist/esm/chunk-GIZLK7M7.mjs +2 -0
  97. package/dist/esm/chunk-GIZLK7M7.mjs.map +1 -0
  98. package/dist/esm/chunk-GMG4VR3K.mjs +2 -0
  99. package/dist/esm/chunk-GMG4VR3K.mjs.map +1 -0
  100. package/dist/esm/{chunk-U6SZNNVL.mjs → chunk-GXPGRCSW.mjs} +2 -2
  101. package/dist/esm/{chunk-U6SZNNVL.mjs.map → chunk-GXPGRCSW.mjs.map} +1 -1
  102. package/dist/esm/{chunk-TPWSHFFI.mjs → chunk-HC5VMNXA.mjs} +2 -2
  103. package/dist/esm/chunk-HTI5LEST.mjs +2 -0
  104. package/dist/esm/chunk-HTI5LEST.mjs.map +1 -0
  105. package/dist/esm/chunk-IELTCGLP.mjs +2 -0
  106. package/dist/esm/chunk-IELTCGLP.mjs.map +1 -0
  107. package/dist/esm/chunk-IHYTP2EW.mjs +1 -0
  108. package/dist/esm/chunk-IHYTP2EW.mjs.map +1 -0
  109. package/dist/esm/chunk-JI2BBZ2W.mjs +2 -0
  110. package/dist/esm/{chunk-ND3ZQKTT.mjs.map → chunk-JI2BBZ2W.mjs.map} +1 -1
  111. package/dist/esm/chunk-KKER5KL4.mjs +2 -0
  112. package/dist/esm/chunk-KKER5KL4.mjs.map +1 -0
  113. package/dist/esm/chunk-KNMWDGP4.mjs +2 -0
  114. package/dist/esm/chunk-KNMWDGP4.mjs.map +1 -0
  115. package/dist/esm/{chunk-YYRDFZE6.mjs → chunk-KZSJ5MFF.mjs} +2 -2
  116. package/dist/esm/{chunk-YYRDFZE6.mjs.map → chunk-KZSJ5MFF.mjs.map} +1 -1
  117. package/dist/esm/chunk-MWAMLQ25.mjs +2 -0
  118. package/dist/esm/chunk-MWAMLQ25.mjs.map +1 -0
  119. package/dist/esm/chunk-NL72WE3E.mjs +2 -0
  120. package/dist/esm/{chunk-TIH6ARYP.mjs.map → chunk-NL72WE3E.mjs.map} +1 -1
  121. package/dist/esm/chunk-NZSGGL25.mjs +2 -0
  122. package/dist/esm/chunk-NZSGGL25.mjs.map +1 -0
  123. package/dist/esm/chunk-OBOOY2QD.mjs +2 -0
  124. package/dist/esm/chunk-OBOOY2QD.mjs.map +1 -0
  125. package/dist/esm/chunk-OT2UDMUU.mjs +2 -0
  126. package/dist/esm/chunk-OT2UDMUU.mjs.map +1 -0
  127. package/dist/esm/chunk-OZZDXS26.mjs +2 -0
  128. package/dist/esm/chunk-OZZDXS26.mjs.map +1 -0
  129. package/dist/esm/{chunk-DRPMIJH7.mjs → chunk-P5747ZYC.mjs} +2 -2
  130. package/dist/esm/{chunk-BPYLPPEQ.mjs → chunk-PL2VA73L.mjs} +2 -2
  131. package/dist/esm/chunk-PXTMLJKO.mjs +2 -0
  132. package/dist/esm/{chunk-WL4OXZLN.mjs → chunk-QCBIJCU4.mjs} +2 -2
  133. package/dist/esm/chunk-QEXAMHPU.mjs +2 -0
  134. package/dist/esm/chunk-QEXAMHPU.mjs.map +1 -0
  135. package/dist/esm/{chunk-KQXRH5FK.mjs → chunk-QNTV5NMH.mjs} +2 -2
  136. package/dist/esm/{chunk-HO7K2UAK.mjs → chunk-RCM3K5JL.mjs} +2 -2
  137. package/dist/esm/{chunk-3VZ3OZKC.mjs → chunk-RLG3WOTH.mjs} +2 -2
  138. package/dist/esm/chunk-SDPICQ5B.mjs +2 -0
  139. package/dist/esm/{chunk-FYIFBLHU.mjs.map → chunk-SDPICQ5B.mjs.map} +1 -1
  140. package/dist/esm/chunk-SGTFMSOG.mjs +2 -0
  141. package/dist/esm/chunk-SGTFMSOG.mjs.map +1 -0
  142. package/dist/esm/chunk-SO6EE5DX.mjs +2 -0
  143. package/dist/esm/chunk-SO6EE5DX.mjs.map +1 -0
  144. package/dist/esm/chunk-SRGPSANH.mjs +2 -0
  145. package/dist/esm/chunk-SRGPSANH.mjs.map +1 -0
  146. package/dist/esm/{chunk-GAI75GOG.mjs → chunk-SSJQOXEP.mjs} +2 -2
  147. package/dist/esm/chunk-TZ623H2V.mjs +2 -0
  148. package/dist/esm/chunk-TZ623H2V.mjs.map +1 -0
  149. package/dist/esm/chunk-U6Z4FNB7.mjs +2 -0
  150. package/dist/esm/chunk-U6Z4FNB7.mjs.map +1 -0
  151. package/dist/esm/{chunk-GTC7WHMV.mjs → chunk-UDMADMVO.mjs} +1 -1
  152. package/dist/esm/{chunk-GTC7WHMV.mjs.map → chunk-UDMADMVO.mjs.map} +1 -1
  153. package/dist/esm/chunk-UIVJXLRM.mjs +1 -0
  154. package/dist/esm/chunk-UIVJXLRM.mjs.map +1 -0
  155. package/dist/esm/chunk-UKSA4H2O.mjs +2 -0
  156. package/dist/esm/chunk-UKSA4H2O.mjs.map +1 -0
  157. package/dist/esm/chunk-UW6HQ643.mjs +2 -0
  158. package/dist/esm/chunk-UW6HQ643.mjs.map +1 -0
  159. package/dist/esm/{chunk-ZUHN56GM.mjs → chunk-UWXDXOFK.mjs} +2 -2
  160. package/dist/esm/chunk-UWXDXOFK.mjs.map +1 -0
  161. package/dist/esm/chunk-VQ7LYNMD.mjs +2 -0
  162. package/dist/esm/chunk-VQ7LYNMD.mjs.map +1 -0
  163. package/dist/esm/{chunk-IBH7IOIM.mjs → chunk-WTGGCH34.mjs} +2 -2
  164. package/dist/esm/{chunk-X32O46IB.mjs → chunk-XITLXPBK.mjs} +2 -2
  165. package/dist/esm/chunk-XMUUI6HG.mjs +2 -0
  166. package/dist/esm/{chunk-R3KWVOFG.mjs.map → chunk-XMUUI6HG.mjs.map} +1 -1
  167. package/dist/esm/chunk-XX2Z26FH.mjs +2 -0
  168. package/dist/esm/chunk-XX2Z26FH.mjs.map +1 -0
  169. package/dist/esm/chunk-Y6PVFMBS.mjs +2 -0
  170. package/dist/esm/chunk-Y6PVFMBS.mjs.map +1 -0
  171. package/dist/esm/{chunk-VWVEDCBM.mjs → chunk-YN6UIVFB.mjs} +2 -2
  172. package/dist/esm/{chunk-4KTQIWUP.mjs → chunk-ZFK7QD3B.mjs} +2 -2
  173. package/dist/esm/chunk-ZJUDDSWN.mjs +2 -0
  174. package/dist/esm/chunk-ZJUDDSWN.mjs.map +1 -0
  175. package/dist/esm/client/core.mjs +1 -1
  176. package/dist/esm/client/get.d.mts +1 -1
  177. package/dist/esm/client/get.mjs +1 -1
  178. package/dist/esm/client/index.mjs +1 -1
  179. package/dist/esm/client/post.mjs +1 -1
  180. package/dist/esm/core/account.mjs +1 -1
  181. package/dist/esm/core/accountAddress.d.mts +9 -9
  182. package/dist/esm/core/accountAddress.mjs +1 -1
  183. package/dist/esm/core/authenticationKey.mjs +1 -1
  184. package/dist/esm/core/crypto/anyPublicKey.d.mts +5 -0
  185. package/dist/esm/core/crypto/anyPublicKey.mjs +1 -1
  186. package/dist/esm/core/crypto/anySignature.mjs +1 -1
  187. package/dist/esm/core/crypto/asymmetricCrypto.mjs +1 -1
  188. package/dist/esm/core/crypto/ed25519.d.mts +3 -0
  189. package/dist/esm/core/crypto/ed25519.mjs +1 -1
  190. package/dist/esm/core/crypto/index.d.mts +2 -2
  191. package/dist/esm/core/crypto/index.mjs +1 -1
  192. package/dist/esm/core/crypto/multiEd25519.mjs +1 -1
  193. package/dist/esm/core/crypto/multiKey.d.mts +2 -0
  194. package/dist/esm/core/crypto/multiKey.mjs +1 -1
  195. package/dist/esm/core/crypto/secp256k1.d.mts +3 -0
  196. package/dist/esm/core/crypto/secp256k1.mjs +1 -1
  197. package/dist/esm/core/hex.mjs +1 -1
  198. package/dist/esm/core/index.d.mts +2 -2
  199. package/dist/esm/core/index.mjs +1 -1
  200. package/dist/esm/index.d.mts +11 -8
  201. package/dist/esm/index.mjs +1 -1
  202. package/dist/esm/internal/account.d.mts +20 -33
  203. package/dist/esm/internal/account.mjs +1 -1
  204. package/dist/esm/internal/ans.d.mts +7 -10
  205. package/dist/esm/internal/ans.mjs +1 -1
  206. package/dist/esm/internal/coin.d.mts +4 -3
  207. package/dist/esm/internal/coin.mjs +1 -1
  208. package/dist/esm/internal/digitalAsset.d.mts +9 -18
  209. package/dist/esm/internal/digitalAsset.mjs +1 -1
  210. package/dist/esm/internal/event.d.mts +5 -12
  211. package/dist/esm/internal/event.mjs +1 -1
  212. package/dist/esm/internal/faucet.d.mts +5 -5
  213. package/dist/esm/internal/faucet.mjs +1 -1
  214. package/dist/esm/internal/fungibleAsset.d.mts +40 -22
  215. package/dist/esm/internal/fungibleAsset.mjs +1 -1
  216. package/dist/esm/internal/general.d.mts +9 -5
  217. package/dist/esm/internal/general.mjs +1 -1
  218. package/dist/esm/internal/staking.d.mts +5 -7
  219. package/dist/esm/internal/staking.mjs +1 -1
  220. package/dist/esm/internal/transaction.d.mts +12 -4
  221. package/dist/esm/internal/transaction.mjs +1 -1
  222. package/dist/esm/internal/transactionSubmission.d.mts +24 -5
  223. package/dist/esm/internal/transactionSubmission.mjs +1 -1
  224. package/dist/esm/transactions/authenticator/account.d.mts +5 -0
  225. package/dist/esm/transactions/authenticator/account.mjs +1 -1
  226. package/dist/esm/transactions/authenticator/index.d.mts +1 -0
  227. package/dist/esm/transactions/authenticator/index.mjs +1 -1
  228. package/dist/esm/transactions/authenticator/transaction.d.mts +1 -0
  229. package/dist/esm/transactions/authenticator/transaction.mjs +1 -1
  230. package/dist/esm/transactions/index.d.mts +4 -3
  231. package/dist/esm/transactions/index.mjs +1 -1
  232. package/dist/esm/transactions/instances/chainId.mjs +1 -1
  233. package/dist/esm/transactions/instances/identifier.mjs +1 -1
  234. package/dist/esm/transactions/instances/index.d.mts +1 -0
  235. package/dist/esm/transactions/instances/index.mjs +1 -1
  236. package/dist/esm/transactions/instances/moduleId.mjs +1 -1
  237. package/dist/esm/transactions/instances/rawTransaction.mjs +1 -1
  238. package/dist/esm/transactions/instances/rotationProofChallenge.mjs +1 -1
  239. package/dist/esm/transactions/instances/signedTransaction.d.mts +1 -0
  240. package/dist/esm/transactions/instances/signedTransaction.mjs +1 -1
  241. package/dist/esm/transactions/instances/transactionPayload.mjs +1 -1
  242. package/dist/esm/transactions/management/accountSequenceNumber.d.mts +89 -0
  243. package/dist/esm/transactions/management/accountSequenceNumber.mjs +2 -0
  244. package/dist/esm/transactions/management/accountSequenceNumber.mjs.map +1 -0
  245. package/dist/esm/transactions/management/asyncQueue.d.mts +58 -0
  246. package/dist/esm/transactions/management/asyncQueue.mjs +2 -0
  247. package/dist/esm/transactions/management/asyncQueue.mjs.map +1 -0
  248. package/dist/esm/transactions/management/index.d.mts +36 -0
  249. package/dist/esm/transactions/management/index.mjs +2 -0
  250. package/dist/esm/transactions/management/index.mjs.map +1 -0
  251. package/dist/esm/transactions/management/transactionWorker.d.mts +135 -0
  252. package/dist/esm/transactions/management/transactionWorker.mjs +2 -0
  253. package/dist/esm/transactions/management/transactionWorker.mjs.map +1 -0
  254. package/dist/esm/transactions/transactionBuilder/helpers.d.mts +3 -1
  255. package/dist/esm/transactions/transactionBuilder/helpers.mjs +1 -1
  256. package/dist/esm/transactions/transactionBuilder/index.d.mts +4 -3
  257. package/dist/esm/transactions/transactionBuilder/index.mjs +1 -1
  258. package/dist/esm/transactions/transactionBuilder/remoteAbi.d.mts +3 -1
  259. package/dist/esm/transactions/transactionBuilder/remoteAbi.mjs +1 -1
  260. package/dist/esm/transactions/transactionBuilder/transactionBuilder.d.mts +3 -2
  261. package/dist/esm/transactions/transactionBuilder/transactionBuilder.mjs +1 -1
  262. package/dist/esm/transactions/typeTag/index.mjs +1 -1
  263. package/dist/esm/transactions/typeTag/parser.mjs +1 -1
  264. package/dist/esm/transactions/types.d.mts +3 -2
  265. package/dist/esm/types/generated/operations.d.mts +3 -3
  266. package/dist/esm/types/generated/queries.d.mts +3 -3
  267. package/dist/esm/types/generated/queries.mjs +1 -1
  268. package/dist/esm/types/index.d.mts +27 -9
  269. package/dist/esm/types/index.mjs +1 -1
  270. package/dist/esm/utils/const.d.mts +18 -1
  271. package/dist/esm/utils/const.mjs +1 -1
  272. package/dist/esm/utils/index.d.mts +1 -1
  273. package/dist/esm/utils/index.mjs +1 -1
  274. package/dist/esm/version.d.mts +1 -1
  275. package/dist/esm/version.mjs +1 -1
  276. package/package.json +1 -1
  277. package/src/api/account.ts +150 -53
  278. package/src/api/ans.ts +19 -22
  279. package/src/api/aptosConfig.ts +2 -2
  280. package/src/api/coin.ts +2 -6
  281. package/src/api/digitalAsset.ts +72 -22
  282. package/src/api/event.ts +28 -17
  283. package/src/api/faucet.ts +12 -9
  284. package/src/api/fungibleAsset.ts +76 -35
  285. package/src/api/general.ts +19 -3
  286. package/src/api/staking.ts +30 -11
  287. package/src/api/transaction.ts +16 -1
  288. package/src/api/transactionSubmission.ts +43 -1
  289. package/src/api/utils.ts +37 -0
  290. package/src/bcs/deserializer.ts +4 -4
  291. package/src/bcs/serializer.ts +4 -4
  292. package/src/client/core.ts +6 -4
  293. package/src/client/get.ts +7 -6
  294. package/src/core/accountAddress.ts +20 -22
  295. package/src/core/crypto/anyPublicKey.ts +12 -0
  296. package/src/core/crypto/ed25519.ts +13 -0
  297. package/src/core/crypto/index.ts +2 -0
  298. package/src/core/crypto/secp256k1.ts +12 -0
  299. package/src/core/hex.ts +5 -7
  300. package/src/index.ts +1 -0
  301. package/src/internal/account.ts +56 -50
  302. package/src/internal/ans.ts +52 -39
  303. package/src/internal/coin.ts +4 -6
  304. package/src/internal/digitalAsset.ts +12 -22
  305. package/src/internal/event.ts +7 -14
  306. package/src/internal/faucet.ts +10 -6
  307. package/src/internal/fungibleAsset.ts +36 -18
  308. package/src/internal/general.ts +30 -3
  309. package/src/internal/queries/getNumberOfDelegatorsQuery.graphql +5 -5
  310. package/src/internal/queries/getProcessorStatus.graphql +2 -2
  311. package/src/internal/staking.ts +12 -14
  312. package/src/internal/transaction.ts +23 -26
  313. package/src/internal/transactionSubmission.ts +35 -5
  314. package/src/transactions/authenticator/account.ts +16 -0
  315. package/src/transactions/instances/moduleId.ts +1 -1
  316. package/src/transactions/management/accountSequenceNumber.ts +186 -0
  317. package/src/transactions/management/asyncQueue.ts +107 -0
  318. package/src/transactions/management/index.ts +2 -0
  319. package/src/transactions/management/transactionWorker.ts +275 -0
  320. package/src/transactions/transactionBuilder/helpers.ts +28 -1
  321. package/src/transactions/transactionBuilder/remoteAbi.ts +35 -28
  322. package/src/transactions/transactionBuilder/transactionBuilder.ts +28 -26
  323. package/src/transactions/typeTag/parser.ts +1 -1
  324. package/src/transactions/types.ts +2 -2
  325. package/src/types/generated/operations.ts +4 -2
  326. package/src/types/generated/queries.ts +4 -4
  327. package/src/types/index.ts +67 -11
  328. package/src/utils/const.ts +18 -0
  329. package/src/version.ts +1 -1
  330. package/dist/esm/chunk-2OZRBXLM.mjs +0 -2
  331. package/dist/esm/chunk-2OZRBXLM.mjs.map +0 -1
  332. package/dist/esm/chunk-33T7WTB6.mjs +0 -2
  333. package/dist/esm/chunk-33T7WTB6.mjs.map +0 -1
  334. package/dist/esm/chunk-62SCW5NH.mjs +0 -2
  335. package/dist/esm/chunk-62SCW5NH.mjs.map +0 -1
  336. package/dist/esm/chunk-67OGU66P.mjs +0 -2
  337. package/dist/esm/chunk-67OGU66P.mjs.map +0 -1
  338. package/dist/esm/chunk-72F5YXGC.mjs.map +0 -1
  339. package/dist/esm/chunk-ARVSIDVB.mjs.map +0 -1
  340. package/dist/esm/chunk-BFQRMCY2.mjs +0 -2
  341. package/dist/esm/chunk-BFQRMCY2.mjs.map +0 -1
  342. package/dist/esm/chunk-BM4HBROC.mjs +0 -2
  343. package/dist/esm/chunk-BM4HBROC.mjs.map +0 -1
  344. package/dist/esm/chunk-BV4OOU5Y.mjs +0 -2
  345. package/dist/esm/chunk-BV4OOU5Y.mjs.map +0 -1
  346. package/dist/esm/chunk-EFIYW4WK.mjs +0 -2
  347. package/dist/esm/chunk-FYIFBLHU.mjs +0 -2
  348. package/dist/esm/chunk-GU4OUKAF.mjs +0 -2
  349. package/dist/esm/chunk-GU4OUKAF.mjs.map +0 -1
  350. package/dist/esm/chunk-J5BH7V37.mjs +0 -2
  351. package/dist/esm/chunk-J5BH7V37.mjs.map +0 -1
  352. package/dist/esm/chunk-KC64ESLO.mjs +0 -2
  353. package/dist/esm/chunk-L7AA75WZ.mjs +0 -2
  354. package/dist/esm/chunk-L7AA75WZ.mjs.map +0 -1
  355. package/dist/esm/chunk-LACQ537H.mjs +0 -2
  356. package/dist/esm/chunk-LACQ537H.mjs.map +0 -1
  357. package/dist/esm/chunk-LDAD54H5.mjs +0 -2
  358. package/dist/esm/chunk-LDAD54H5.mjs.map +0 -1
  359. package/dist/esm/chunk-LXW3A3MJ.mjs +0 -2
  360. package/dist/esm/chunk-LXW3A3MJ.mjs.map +0 -1
  361. package/dist/esm/chunk-M2V2POWK.mjs +0 -2
  362. package/dist/esm/chunk-M2V2POWK.mjs.map +0 -1
  363. package/dist/esm/chunk-ND3ZQKTT.mjs +0 -2
  364. package/dist/esm/chunk-NZIJV4O2.mjs +0 -2
  365. package/dist/esm/chunk-NZIJV4O2.mjs.map +0 -1
  366. package/dist/esm/chunk-O2B54NZT.mjs +0 -2
  367. package/dist/esm/chunk-O2B54NZT.mjs.map +0 -1
  368. package/dist/esm/chunk-OCW2L33Q.mjs +0 -2
  369. package/dist/esm/chunk-OCW2L33Q.mjs.map +0 -1
  370. package/dist/esm/chunk-OCYS4V2V.mjs +0 -2
  371. package/dist/esm/chunk-OCYS4V2V.mjs.map +0 -1
  372. package/dist/esm/chunk-OSTH5JRX.mjs +0 -2
  373. package/dist/esm/chunk-OSTH5JRX.mjs.map +0 -1
  374. package/dist/esm/chunk-OVHY6ZUJ.mjs +0 -2
  375. package/dist/esm/chunk-OVHY6ZUJ.mjs.map +0 -1
  376. package/dist/esm/chunk-PZCMSHY6.mjs +0 -2
  377. package/dist/esm/chunk-PZCMSHY6.mjs.map +0 -1
  378. package/dist/esm/chunk-R3KWVOFG.mjs +0 -2
  379. package/dist/esm/chunk-RHS5ROLP.mjs +0 -2
  380. package/dist/esm/chunk-RHS5ROLP.mjs.map +0 -1
  381. package/dist/esm/chunk-RKKU2SY5.mjs +0 -2
  382. package/dist/esm/chunk-RKKU2SY5.mjs.map +0 -1
  383. package/dist/esm/chunk-RYETO74W.mjs +0 -2
  384. package/dist/esm/chunk-RYETO74W.mjs.map +0 -1
  385. package/dist/esm/chunk-TCTZCPQ6.mjs +0 -1
  386. package/dist/esm/chunk-TGKB6ALT.mjs +0 -2
  387. package/dist/esm/chunk-TGKB6ALT.mjs.map +0 -1
  388. package/dist/esm/chunk-TIH6ARYP.mjs +0 -2
  389. package/dist/esm/chunk-UDBH4CER.mjs.map +0 -1
  390. package/dist/esm/chunk-WEJAI26R.mjs +0 -2
  391. package/dist/esm/chunk-WEJAI26R.mjs.map +0 -1
  392. package/dist/esm/chunk-Y2HRRUZ6.mjs +0 -2
  393. package/dist/esm/chunk-Y2HRRUZ6.mjs.map +0 -1
  394. package/dist/esm/chunk-Y7VR7X5W.mjs +0 -2
  395. package/dist/esm/chunk-Y7VR7X5W.mjs.map +0 -1
  396. package/dist/esm/chunk-ZLW65YCO.mjs +0 -2
  397. package/dist/esm/chunk-ZLW65YCO.mjs.map +0 -1
  398. package/dist/esm/chunk-ZUHN56GM.mjs.map +0 -1
  399. /package/dist/esm/{chunk-TCTZCPQ6.mjs.map → api/utils.mjs.map} +0 -0
  400. /package/dist/esm/{chunk-UAAI3NCA.mjs.map → chunk-2SAKPC5Q.mjs.map} +0 -0
  401. /package/dist/esm/{chunk-3732I6BR.mjs.map → chunk-2YQXX64E.mjs.map} +0 -0
  402. /package/dist/esm/{chunk-4ADA5BE7.mjs.map → chunk-53DS6NBQ.mjs.map} +0 -0
  403. /package/dist/esm/{chunk-QWVR4RCV.mjs.map → chunk-5OPOJ43H.mjs.map} +0 -0
  404. /package/dist/esm/{chunk-HVADSXTB.mjs.map → chunk-73VWOS4Z.mjs.map} +0 -0
  405. /package/dist/esm/{chunk-U25N2VWA.mjs.map → chunk-AZUWHKN5.mjs.map} +0 -0
  406. /package/dist/esm/{chunk-JZNLZMUC.mjs.map → chunk-CJPCOS4R.mjs.map} +0 -0
  407. /package/dist/esm/{chunk-S36IYY6K.mjs.map → chunk-CL5B2QNS.mjs.map} +0 -0
  408. /package/dist/esm/{chunk-EWTHPMEE.mjs.map → chunk-CU2DINU4.mjs.map} +0 -0
  409. /package/dist/esm/{chunk-5LO7FR2P.mjs.map → chunk-EFRFDFS4.mjs.map} +0 -0
  410. /package/dist/esm/{chunk-44MGBJ73.mjs.map → chunk-FZ56IS3E.mjs.map} +0 -0
  411. /package/dist/esm/{chunk-TPWSHFFI.mjs.map → chunk-HC5VMNXA.mjs.map} +0 -0
  412. /package/dist/esm/{chunk-DRPMIJH7.mjs.map → chunk-P5747ZYC.mjs.map} +0 -0
  413. /package/dist/esm/{chunk-BPYLPPEQ.mjs.map → chunk-PL2VA73L.mjs.map} +0 -0
  414. /package/dist/esm/{chunk-EFIYW4WK.mjs.map → chunk-PXTMLJKO.mjs.map} +0 -0
  415. /package/dist/esm/{chunk-WL4OXZLN.mjs.map → chunk-QCBIJCU4.mjs.map} +0 -0
  416. /package/dist/esm/{chunk-KQXRH5FK.mjs.map → chunk-QNTV5NMH.mjs.map} +0 -0
  417. /package/dist/esm/{chunk-HO7K2UAK.mjs.map → chunk-RCM3K5JL.mjs.map} +0 -0
  418. /package/dist/esm/{chunk-3VZ3OZKC.mjs.map → chunk-RLG3WOTH.mjs.map} +0 -0
  419. /package/dist/esm/{chunk-GAI75GOG.mjs.map → chunk-SSJQOXEP.mjs.map} +0 -0
  420. /package/dist/esm/{chunk-IBH7IOIM.mjs.map → chunk-WTGGCH34.mjs.map} +0 -0
  421. /package/dist/esm/{chunk-X32O46IB.mjs.map → chunk-XITLXPBK.mjs.map} +0 -0
  422. /package/dist/esm/{chunk-VWVEDCBM.mjs.map → chunk-YN6UIVFB.mjs.map} +0 -0
  423. /package/dist/esm/{chunk-4KTQIWUP.mjs.map → chunk-ZFK7QD3B.mjs.map} +0 -0
@@ -0,0 +1,186 @@
1
+ /**
2
+ * A wrapper that handles and manages an account sequence number.
3
+ *
4
+ * Submit up to `maximumInFlight` transactions per account in parallel with a timeout of `sleepTime`
5
+ * If local assumes `maximumInFlight` are in flight, determine the actual committed state from the network
6
+ * If there are less than `maximumInFlight` due to some being committed, adjust the window
7
+ * If `maximumInFlight` are in flight, wait `sleepTime` seconds before re-evaluating
8
+ * If ever waiting more than `maxWaitTime` restart the sequence number to the current on-chain state
9
+ *
10
+ * Assumptions:
11
+ * Accounts are expected to be managed by a single AccountSequenceNumber and not used otherwise.
12
+ * They are initialized to the current on-chain state, so if there are already transactions in
13
+ * flight, they may take some time to reset.
14
+ * Accounts are automatically initialized if not explicitly
15
+ *
16
+ * Notes:
17
+ * This is co-routine safe, that is many async tasks can be reading from this concurrently.
18
+ * The state of an account cannot be used across multiple AccountSequenceNumber services.
19
+ * The synchronize method will create a barrier that prevents additional nextSequenceNumber
20
+ * calls until it is complete.
21
+ * This only manages the distribution of sequence numbers it does not help handle transaction
22
+ * failures.
23
+ * If a transaction fails, you should call synchronize and wait for timeouts.
24
+ */
25
+
26
+ import { AptosConfig } from "../../api/aptosConfig";
27
+ import { Account } from "../../core";
28
+ import { getInfo } from "../../internal/account";
29
+ import { sleep } from "../../utils/helpers";
30
+
31
+ // returns `now` time in seconds
32
+ const now = () => Math.floor(Date.now() / 1000);
33
+
34
+ export class AccountSequenceNumber {
35
+ readonly aptosConfig: AptosConfig;
36
+
37
+ readonly account: Account;
38
+
39
+ // sequence number on chain
40
+ lastUncommintedNumber: bigint | null = null;
41
+
42
+ // local sequence number
43
+ currentNumber: bigint | null = null;
44
+
45
+ /**
46
+ * We want to guarantee that we preserve ordering of workers to requests.
47
+ *
48
+ * `lock` is used to try to prevent multiple coroutines from accessing a shared resource at the same time,
49
+ * which can result in race conditions and data inconsistency.
50
+ * This code actually doesn't do it though, since we aren't giving out a slot, it is still somewhat a race condition.
51
+ *
52
+ * The ideal solution is likely that each thread grabs the next number from a incremental integer.
53
+ * When they complete, they increment that number and that entity is able to enter the `lock`.
54
+ * That would guarantee ordering.
55
+ */
56
+ lock = false;
57
+
58
+ maxWaitTime: number;
59
+
60
+ maximumInFlight: number;
61
+
62
+ sleepTime: number;
63
+
64
+ constructor(
65
+ aptosConfig: AptosConfig,
66
+ account: Account,
67
+ maxWaitTime: number,
68
+ maximumInFlight: number,
69
+ sleepTime: number,
70
+ ) {
71
+ this.aptosConfig = aptosConfig;
72
+ this.account = account;
73
+ this.maxWaitTime = maxWaitTime;
74
+ this.maximumInFlight = maximumInFlight;
75
+ this.sleepTime = sleepTime;
76
+ }
77
+
78
+ /**
79
+ * Returns the next available sequence number for this account
80
+ *
81
+ * @returns next available sequence number
82
+ */
83
+ async nextSequenceNumber(): Promise<bigint | null> {
84
+ /* eslint-disable no-await-in-loop */
85
+ while (this.lock) {
86
+ await sleep(this.sleepTime);
87
+ }
88
+
89
+ this.lock = true;
90
+ let nextNumber = BigInt(0);
91
+ try {
92
+ if (this.lastUncommintedNumber === null || this.currentNumber === null) {
93
+ await this.initialize();
94
+ }
95
+
96
+ if (this.currentNumber! - this.lastUncommintedNumber! >= this.maximumInFlight) {
97
+ await this.update();
98
+
99
+ const startTime = now();
100
+ while (this.currentNumber! - this.lastUncommintedNumber! >= this.maximumInFlight) {
101
+ await sleep(this.sleepTime);
102
+ if (now() - startTime > this.maxWaitTime) {
103
+ /* eslint-disable no-console */
104
+ console.warn(
105
+ `Waited over 30 seconds for a transaction to commit, resyncing ${this.account.accountAddress.toString()}`,
106
+ );
107
+ await this.initialize();
108
+ } else {
109
+ await this.update();
110
+ }
111
+ }
112
+ }
113
+ nextNumber = this.currentNumber!;
114
+ this.currentNumber! += BigInt(1);
115
+ } catch (e) {
116
+ console.error("error in getting next sequence number for this account", e);
117
+ } finally {
118
+ this.lock = false;
119
+ }
120
+ return nextNumber;
121
+ }
122
+
123
+ /**
124
+ * Initializes this account with the sequence number on chain
125
+ */
126
+ async initialize(): Promise<void> {
127
+ const { sequence_number: sequenceNumber } = await getInfo({
128
+ aptosConfig: this.aptosConfig,
129
+ accountAddress: this.account.accountAddress,
130
+ });
131
+ this.currentNumber = BigInt(sequenceNumber);
132
+ this.lastUncommintedNumber = BigInt(sequenceNumber);
133
+ }
134
+
135
+ /**
136
+ * Updates this account sequence number with the one on-chain
137
+ *
138
+ * @returns on-chain sequence number for this account
139
+ */
140
+ async update(): Promise<bigint> {
141
+ const { sequence_number: sequenceNumber } = await getInfo({
142
+ aptosConfig: this.aptosConfig,
143
+ accountAddress: this.account.accountAddress,
144
+ });
145
+ this.lastUncommintedNumber = BigInt(sequenceNumber);
146
+ return this.lastUncommintedNumber;
147
+ }
148
+
149
+ /**
150
+ * Synchronizes local sequence number with the seqeunce number on chain for this account.
151
+ *
152
+ * Poll the network until all submitted transactions have either been committed or until
153
+ * the maximum wait time has elapsed
154
+ */
155
+ async synchronize(): Promise<void> {
156
+ if (this.lastUncommintedNumber === this.currentNumber) return;
157
+
158
+ /* eslint-disable no-await-in-loop */
159
+ while (this.lock) {
160
+ await sleep(this.sleepTime);
161
+ }
162
+
163
+ this.lock = true;
164
+
165
+ try {
166
+ await this.update();
167
+ const startTime = now();
168
+ while (this.lastUncommintedNumber !== this.currentNumber) {
169
+ if (now() - startTime > this.maxWaitTime) {
170
+ /* eslint-disable no-console */
171
+ console.warn(
172
+ `Waited over 30 seconds for a transaction to commit, resyncing ${this.account.accountAddress.toString()}`,
173
+ );
174
+ await this.initialize();
175
+ } else {
176
+ await sleep(this.sleepTime);
177
+ await this.update();
178
+ }
179
+ }
180
+ } catch (e) {
181
+ console.error("error in synchronizing this account sequence number with the one on chain", e);
182
+ } finally {
183
+ this.lock = false;
184
+ }
185
+ }
186
+ }
@@ -0,0 +1,107 @@
1
+ /**
2
+ * The AsyncQueue class is an async-aware data structure that provides a queue-like
3
+ * behavior for managing asynchronous tasks or operations.
4
+ * It allows to enqueue items and dequeue them asynchronously.
5
+ * This is not thread-safe but it is async concurrency safe and
6
+ * it does not guarantee ordering for those that call into and await on enqueue.
7
+ */
8
+
9
+ interface PendingDequeue<T> {
10
+ resolve: (value: T) => void;
11
+ reject: (reason?: AsyncQueueCancelledError) => void;
12
+ }
13
+
14
+ export class AsyncQueue<T> {
15
+ readonly queue: T[] = [];
16
+
17
+ // The pendingDequeue is used to handle the resolution of promises when items are enqueued and dequeued.
18
+ private pendingDequeue: PendingDequeue<T>[] = [];
19
+
20
+ private cancelled: boolean = false;
21
+
22
+ /**
23
+ * The enqueue method adds an item to the queue. If there are pending dequeued promises,
24
+ * in the pendingDequeue, it resolves the oldest promise with the enqueued item immediately.
25
+ * Otherwise, it adds the item to the queue.
26
+ *
27
+ * @param item T
28
+ */
29
+ enqueue(item: T): void {
30
+ this.cancelled = false;
31
+
32
+ if (this.pendingDequeue.length > 0) {
33
+ const promise = this.pendingDequeue.shift();
34
+
35
+ promise?.resolve(item);
36
+
37
+ return;
38
+ }
39
+
40
+ this.queue.push(item);
41
+ }
42
+
43
+ /**
44
+ * The dequeue method returns a promise that resolves to the next item in the queue.
45
+ * If the queue is not empty, it resolves the promise immediately with the next item.
46
+ * Otherwise, it creates a new promise. The promise's resolve function is stored
47
+ * in the pendingDequeue with a unique counter value as the key.
48
+ * The newly created promise is then returned, and it will be resolved later when an item is enqueued.
49
+ *
50
+ * @returns Promise<T>
51
+ */
52
+ async dequeue(): Promise<T> {
53
+ if (this.queue.length > 0) {
54
+ return Promise.resolve(this.queue.shift()!);
55
+ }
56
+
57
+ return new Promise<T>((resolve, reject) => {
58
+ this.pendingDequeue.push({ resolve, reject });
59
+ });
60
+ }
61
+
62
+ /**
63
+ * The isEmpty method returns whether the queue is empty or not.
64
+ *
65
+ * @returns boolean
66
+ */
67
+ isEmpty(): boolean {
68
+ return this.queue.length === 0;
69
+ }
70
+
71
+ /**
72
+ * The cancel method cancels all pending promises in the queue.
73
+ * It rejects the promises with a AsyncQueueCancelledError error,
74
+ * ensuring that any awaiting code can handle the cancellation appropriately.
75
+ */
76
+ cancel(): void {
77
+ this.cancelled = true;
78
+
79
+ this.pendingDequeue.forEach(async ({ reject }) => {
80
+ reject(new AsyncQueueCancelledError("Task cancelled"));
81
+ });
82
+
83
+ this.pendingDequeue = [];
84
+
85
+ this.queue.length = 0;
86
+ }
87
+
88
+ /**
89
+ * The isCancelled method returns whether the queue is cancelled or not.
90
+ *
91
+ * @returns boolean
92
+ */
93
+ isCancelled(): boolean {
94
+ return this.cancelled;
95
+ }
96
+
97
+ /**
98
+ * The pendingDequeueLength method returns the length of the pendingDequeue.
99
+ *
100
+ * @returns number
101
+ */
102
+ pendingDequeueLength(): number {
103
+ return this.pendingDequeue.length;
104
+ }
105
+ }
106
+
107
+ export class AsyncQueueCancelledError extends Error {}
@@ -0,0 +1,2 @@
1
+ export * from "./accountSequenceNumber";
2
+ export * from "./transactionWorker";
@@ -0,0 +1,275 @@
1
+ /* eslint-disable no-await-in-loop */
2
+
3
+ /**
4
+ * TransactionWorker provides a simple framework for receiving payloads to be processed.
5
+ *
6
+ * Once one `start()` the process and pushes a new transaction, the worker acquires
7
+ * the current account's next sequence number (by using the AccountSequenceNumber class),
8
+ * generates a signed transaction and pushes an async submission process into the `outstandingTransactions` queue.
9
+ * At the same time, the worker processes transactions by reading the `outstandingTransactions` queue
10
+ * and submits the next transaction to chain, it
11
+ * 1) waits for resolution of the submission process or get pre-execution validation error
12
+ * and 2) waits for the resolution of the execution process or get an execution error.
13
+ * The worker fires events for any submission and/or execution success and/or failure.
14
+ */
15
+
16
+ import { AptosConfig } from "../../api/aptosConfig";
17
+ import { Account } from "../../core";
18
+ import { waitForTransaction } from "../../internal/transaction";
19
+ import { generateTransaction, signAndSubmitTransaction } from "../../internal/transactionSubmission";
20
+ import { PendingTransactionResponse, TransactionResponse } from "../../types";
21
+ import {
22
+ InputGenerateTransactionOptions,
23
+ InputGenerateTransactionPayloadData,
24
+ SingleSignerTransaction,
25
+ } from "../types";
26
+ import { AccountSequenceNumber } from "./accountSequenceNumber";
27
+ import { AsyncQueue, AsyncQueueCancelledError } from "./asyncQueue";
28
+
29
+ const promiseFulfilledStatus = "fulfilled";
30
+
31
+ export class TransactionWorker {
32
+ readonly aptosConfig: AptosConfig;
33
+
34
+ readonly account: Account;
35
+
36
+ // current account sequence number
37
+ readonly accountSequnceNumber: AccountSequenceNumber;
38
+
39
+ readonly taskQueue: AsyncQueue<() => Promise<void>> = new AsyncQueue<() => Promise<void>>();
40
+
41
+ // process has started
42
+ started: boolean;
43
+
44
+ /**
45
+ * transactions payloads waiting to be generated and signed
46
+ *
47
+ * TODO support entry function payload from ABI builder
48
+ */
49
+ transactionsQueue = new AsyncQueue<
50
+ [InputGenerateTransactionPayloadData, InputGenerateTransactionOptions | undefined]
51
+ >();
52
+
53
+ /**
54
+ * signed transactions waiting to be submitted
55
+ */
56
+ outstandingTransactions = new AsyncQueue<[Promise<PendingTransactionResponse>, bigint]>();
57
+
58
+ /**
59
+ * transactions that have been submitted to chain
60
+ */
61
+ sentTransactions: Array<[string, bigint, any]> = [];
62
+
63
+ /**
64
+ * transactions that have been committed to chain
65
+ */
66
+ executedTransactions: Array<[string, bigint, any]> = [];
67
+
68
+ /**
69
+ * Provides a simple framework for receiving payloads to be processed.
70
+ *
71
+ * @param aptosConfig - a config object
72
+ * @param sender - a sender as Account
73
+ * @param maxWaitTime - the max wait time to wait before resyncing the sequence number
74
+ * to the current on-chain state, default to 30
75
+ * @param maximumInFlight - submit up to `maximumInFlight` transactions per account.
76
+ * Mempool limits the number of transactions per account to 100, hence why we default to 100.
77
+ * @param sleepTime - If `maximumInFlight` are in flight, wait `sleepTime` seconds before re-evaluating, default to 10
78
+ */
79
+ constructor(
80
+ aptosConfig: AptosConfig,
81
+ account: Account,
82
+ maxWaitTime: number = 30,
83
+ maximumInFlight: number = 100,
84
+ sleepTime: number = 10,
85
+ ) {
86
+ this.aptosConfig = aptosConfig;
87
+ this.account = account;
88
+ this.started = false;
89
+ this.accountSequnceNumber = new AccountSequenceNumber(
90
+ aptosConfig,
91
+ account,
92
+ maxWaitTime,
93
+ maximumInFlight,
94
+ sleepTime,
95
+ );
96
+ }
97
+
98
+ /**
99
+ * Gets the current account sequence number,
100
+ * generates the transaction with the account sequence number,
101
+ * adds the transaction to the outstanding transaction queue
102
+ * to be processed later.
103
+ */
104
+ async submitNextTransaction() {
105
+ try {
106
+ /* eslint-disable no-constant-condition */
107
+ while (true) {
108
+ if (this.transactionsQueue.isEmpty()) return;
109
+ const sequenceNumber = await this.accountSequnceNumber.nextSequenceNumber();
110
+ if (sequenceNumber === null) return;
111
+ const transaction = await this.generateNextTransaction(this.account, sequenceNumber);
112
+ if (!transaction) return;
113
+ const pendingTransaction = signAndSubmitTransaction({
114
+ aptosConfig: this.aptosConfig,
115
+ transaction,
116
+ signer: this.account,
117
+ });
118
+ await this.outstandingTransactions.enqueue([pendingTransaction, sequenceNumber]);
119
+ }
120
+ } catch (error: any) {
121
+ if (error instanceof AsyncQueueCancelledError) {
122
+ return;
123
+ }
124
+ throw new Error(`Submit transaction failed for ${this.account.accountAddress.toString()} with error ${error}`);
125
+ }
126
+ }
127
+
128
+ /**
129
+ * Reads the outstanding transaction queue and submits the transaction to chain.
130
+ *
131
+ * If the transaction has fulfilled, it pushes the transaction to the processed
132
+ * transactions queue and fires a transactionsFulfilled event.
133
+ *
134
+ * If the transaction has failed, it pushes the transaction to the processed
135
+ * transactions queue with the failure reason and fires a transactionsFailed event.
136
+ */
137
+ async processTransactions() {
138
+ try {
139
+ /* eslint-disable no-constant-condition */
140
+ while (true) {
141
+ const awaitingTransactions = [];
142
+ const sequenceNumbers = [];
143
+ let [pendingTransaction, sequenceNumber] = await this.outstandingTransactions.dequeue();
144
+
145
+ awaitingTransactions.push(pendingTransaction);
146
+ sequenceNumbers.push(sequenceNumber);
147
+
148
+ while (!this.outstandingTransactions.isEmpty()) {
149
+ [pendingTransaction, sequenceNumber] = await this.outstandingTransactions.dequeue();
150
+
151
+ awaitingTransactions.push(pendingTransaction);
152
+ sequenceNumbers.push(sequenceNumber);
153
+ }
154
+ // send awaiting transactions to chain
155
+ const sentTransactions = await Promise.allSettled(awaitingTransactions);
156
+ for (let i = 0; i < sentTransactions.length && i < sequenceNumbers.length; i += 1) {
157
+ // check sent transaction status
158
+ const sentTransaction = sentTransactions[i];
159
+ sequenceNumber = sequenceNumbers[i];
160
+ if (sentTransaction.status === promiseFulfilledStatus) {
161
+ // transaction sent to chain
162
+ this.sentTransactions.push([sentTransaction.value.hash, sequenceNumber, null]);
163
+ // check sent transaction execution
164
+ await this.checkTransaction(sentTransaction, sequenceNumber);
165
+ } else {
166
+ // send transaction failed
167
+ this.sentTransactions.push([sentTransaction.status, sequenceNumber, sentTransaction.reason]);
168
+ }
169
+ }
170
+ }
171
+ } catch (error: any) {
172
+ if (error instanceof AsyncQueueCancelledError) {
173
+ return;
174
+ }
175
+ throw new Error(`Process execution failed for ${this.account.accountAddress.toString()} with error ${error}`);
176
+ }
177
+ }
178
+
179
+ /**
180
+ * Once transaction has been sent to chain, we check for its execution status.
181
+ * @param sentTransaction transactions that were sent to chain and are now waiting to be executed
182
+ * @param sequenceNumber the account's sequence number that was sent with the transaction
183
+ */
184
+ async checkTransaction(sentTransaction: PromiseFulfilledResult<PendingTransactionResponse>, sequenceNumber: bigint) {
185
+ try {
186
+ const waitFor: Array<Promise<TransactionResponse>> = [];
187
+ waitFor.push(waitForTransaction({ aptosConfig: this.aptosConfig, transactionHash: sentTransaction.value.hash }));
188
+ const sentTransactions = await Promise.allSettled(waitFor);
189
+
190
+ for (let i = 0; i < sentTransactions.length; i += 1) {
191
+ const executedTransaction = sentTransactions[i];
192
+ if (executedTransaction.status === promiseFulfilledStatus) {
193
+ // transaction executed to chain
194
+ this.executedTransactions.push([executedTransaction.value.hash, sequenceNumber, null]);
195
+ } else {
196
+ // transaction execution failed
197
+ this.executedTransactions.push([executedTransaction.status, sequenceNumber, executedTransaction.reason]);
198
+ }
199
+ }
200
+ } catch (error: any) {
201
+ throw new Error(`Check transaction failed for ${this.account.accountAddress.toString()} with error ${error}`);
202
+ }
203
+ }
204
+
205
+ /**
206
+ * Push transaction to the transactions queue
207
+ * @param payload Transaction payload
208
+ */
209
+ async push(
210
+ transactionData: InputGenerateTransactionPayloadData,
211
+ options?: InputGenerateTransactionOptions,
212
+ ): Promise<void> {
213
+ await this.transactionsQueue.enqueue([transactionData, options]);
214
+ }
215
+
216
+ /**
217
+ * Generates a signed transaction that can be submitted to chain
218
+ * @param account an Aptos account
219
+ * @param sequenceNumber a sequence number the transaction will be generated with
220
+ * @returns
221
+ */
222
+ async generateNextTransaction(
223
+ account: Account,
224
+ sequenceNumber: bigint,
225
+ ): Promise<SingleSignerTransaction | undefined> {
226
+ if (this.transactionsQueue.isEmpty()) return undefined;
227
+ const [transactionData, options] = await this.transactionsQueue.dequeue();
228
+ const transaction = await generateTransaction({
229
+ aptosConfig: this.aptosConfig,
230
+ sender: account.accountAddress,
231
+ data: transactionData,
232
+ options: { ...options, accountSequenceNumber: sequenceNumber },
233
+ });
234
+
235
+ return transaction;
236
+ }
237
+
238
+ /**
239
+ * Starts transaction submission and transaction processing.
240
+ */
241
+ async run() {
242
+ try {
243
+ while (!this.taskQueue.isCancelled()) {
244
+ const task = await this.taskQueue.dequeue();
245
+ await task();
246
+ }
247
+ } catch (error: any) {
248
+ throw new Error(`Unable to start transaction batching: ${error}`);
249
+ }
250
+ }
251
+
252
+ /**
253
+ * Starts the transaction management process.
254
+ */
255
+ start() {
256
+ if (this.started) {
257
+ throw new Error("worker has already started");
258
+ }
259
+ this.started = true;
260
+ this.taskQueue.enqueue(() => this.submitNextTransaction());
261
+ this.taskQueue.enqueue(() => this.processTransactions());
262
+ this.run();
263
+ }
264
+
265
+ /**
266
+ * Stops the the transaction management process.
267
+ */
268
+ stop() {
269
+ if (this.taskQueue.isCancelled()) {
270
+ throw new Error("worker has already stopped");
271
+ }
272
+ this.started = false;
273
+ this.taskQueue.cancel();
274
+ }
275
+ }
@@ -8,7 +8,7 @@ import {
8
8
  InputScriptData,
9
9
  SimpleEntryFunctionArgumentTypes,
10
10
  } from "../types";
11
- import { Bool, FixedBytes, MoveString, U128, U16, U256, U32, U64, U8 } from "../../bcs";
11
+ import { Bool, FixedBytes, MoveOption, MoveString, MoveVector, U128, U16, U256, U32, U64, U8 } from "../../bcs";
12
12
  import { AccountAddress } from "../../core";
13
13
  import { MoveFunction, MoveFunctionId } from "../../types";
14
14
 
@@ -32,17 +32,39 @@ export function isNull(arg: SimpleEntryFunctionArgumentTypes): arg is null | und
32
32
  return arg === null || arg === undefined;
33
33
  }
34
34
 
35
+ export function isEncodedEntryFunctionArgument(
36
+ arg: EntryFunctionArgumentTypes | SimpleEntryFunctionArgumentTypes,
37
+ ): arg is EntryFunctionArgumentTypes {
38
+ return (
39
+ isBcsBool(arg) ||
40
+ isBcsU8(arg) ||
41
+ isBcsU16(arg) ||
42
+ isBcsU32(arg) ||
43
+ isBcsU64(arg) ||
44
+ isBcsU128(arg) ||
45
+ isBcsU256(arg) ||
46
+ isBcsAddress(arg) ||
47
+ isBcsString(arg) ||
48
+ isBcsFixedBytes(arg) ||
49
+ arg instanceof MoveVector ||
50
+ arg instanceof MoveOption
51
+ );
52
+ }
53
+
35
54
  export function isBcsBool(arg: EntryFunctionArgumentTypes | SimpleEntryFunctionArgumentTypes): arg is Bool {
36
55
  return arg instanceof Bool;
37
56
  }
57
+
38
58
  export function isBcsAddress(
39
59
  arg: EntryFunctionArgumentTypes | SimpleEntryFunctionArgumentTypes,
40
60
  ): arg is AccountAddress {
41
61
  return arg instanceof AccountAddress;
42
62
  }
63
+
43
64
  export function isBcsString(arg: EntryFunctionArgumentTypes | SimpleEntryFunctionArgumentTypes): arg is MoveString {
44
65
  return arg instanceof MoveString;
45
66
  }
67
+
46
68
  export function isBcsFixedBytes(arg: EntryFunctionArgumentTypes | SimpleEntryFunctionArgumentTypes): arg is FixedBytes {
47
69
  return arg instanceof FixedBytes;
48
70
  }
@@ -50,18 +72,23 @@ export function isBcsFixedBytes(arg: EntryFunctionArgumentTypes | SimpleEntryFun
50
72
  export function isBcsU8(arg: EntryFunctionArgumentTypes | SimpleEntryFunctionArgumentTypes): arg is U8 {
51
73
  return arg instanceof U8;
52
74
  }
75
+
53
76
  export function isBcsU16(arg: EntryFunctionArgumentTypes | SimpleEntryFunctionArgumentTypes): arg is U16 {
54
77
  return arg instanceof U16;
55
78
  }
79
+
56
80
  export function isBcsU32(arg: EntryFunctionArgumentTypes | SimpleEntryFunctionArgumentTypes): arg is U32 {
57
81
  return arg instanceof U32;
58
82
  }
83
+
59
84
  export function isBcsU64(arg: EntryFunctionArgumentTypes | SimpleEntryFunctionArgumentTypes): arg is U64 {
60
85
  return arg instanceof U64;
61
86
  }
87
+
62
88
  export function isBcsU128(arg: EntryFunctionArgumentTypes | SimpleEntryFunctionArgumentTypes): arg is U128 {
63
89
  return arg instanceof U128;
64
90
  }
91
+
65
92
  export function isBcsU256(arg: EntryFunctionArgumentTypes | SimpleEntryFunctionArgumentTypes): arg is U256 {
66
93
  return arg instanceof U256;
67
94
  }