@ledgerhq/coin-aptos 1.4.0-next.0

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 (439) hide show
  1. package/.turbo/turbo-build.log +4 -0
  2. package/.unimportedrc.json +16 -0
  3. package/CHANGELOG.md +18 -0
  4. package/LICENSE.txt +21 -0
  5. package/jest.config.js +8 -0
  6. package/lib/__tests__/api/index.test.d.ts +2 -0
  7. package/lib/__tests__/api/index.test.d.ts.map +1 -0
  8. package/lib/__tests__/api/index.test.js +447 -0
  9. package/lib/__tests__/api/index.test.js.map +1 -0
  10. package/lib/__tests__/bridge/broadcast.test.d.ts +2 -0
  11. package/lib/__tests__/bridge/broadcast.test.d.ts.map +1 -0
  12. package/lib/__tests__/bridge/broadcast.test.js +98 -0
  13. package/lib/__tests__/bridge/broadcast.test.js.map +1 -0
  14. package/lib/__tests__/bridge/buildTransaction.test.d.ts +2 -0
  15. package/lib/__tests__/bridge/buildTransaction.test.d.ts.map +1 -0
  16. package/lib/__tests__/bridge/buildTransaction.test.js +62 -0
  17. package/lib/__tests__/bridge/buildTransaction.test.js.map +1 -0
  18. package/lib/__tests__/bridge/createTransaction.test.d.ts +2 -0
  19. package/lib/__tests__/bridge/createTransaction.test.d.ts.map +1 -0
  20. package/lib/__tests__/bridge/createTransaction.test.js +38 -0
  21. package/lib/__tests__/bridge/createTransaction.test.js.map +1 -0
  22. package/lib/__tests__/bridge/deviceTransactionConfig.test.d.ts +2 -0
  23. package/lib/__tests__/bridge/deviceTransactionConfig.test.d.ts.map +1 -0
  24. package/lib/__tests__/bridge/deviceTransactionConfig.test.js +43 -0
  25. package/lib/__tests__/bridge/deviceTransactionConfig.test.js.map +1 -0
  26. package/lib/__tests__/bridge/estimateMaxSpendable.test.d.ts +2 -0
  27. package/lib/__tests__/bridge/estimateMaxSpendable.test.d.ts.map +1 -0
  28. package/lib/__tests__/bridge/estimateMaxSpendable.test.js +84 -0
  29. package/lib/__tests__/bridge/estimateMaxSpendable.test.js.map +1 -0
  30. package/lib/__tests__/bridge/getFeesForTransaction.test.d.ts +2 -0
  31. package/lib/__tests__/bridge/getFeesForTransaction.test.d.ts.map +1 -0
  32. package/lib/__tests__/bridge/getFeesForTransaction.test.js +188 -0
  33. package/lib/__tests__/bridge/getFeesForTransaction.test.js.map +1 -0
  34. package/lib/__tests__/bridge/getTransactionStatus.test.d.ts +2 -0
  35. package/lib/__tests__/bridge/getTransactionStatus.test.d.ts.map +1 -0
  36. package/lib/__tests__/bridge/getTransactionStatus.test.js +133 -0
  37. package/lib/__tests__/bridge/getTransactionStatus.test.js.map +1 -0
  38. package/lib/__tests__/bridge/index.test.d.ts +2 -0
  39. package/lib/__tests__/bridge/index.test.d.ts.map +1 -0
  40. package/lib/__tests__/bridge/index.test.js +116 -0
  41. package/lib/__tests__/bridge/index.test.js.map +1 -0
  42. package/lib/__tests__/bridge/logic.test.d.ts +2 -0
  43. package/lib/__tests__/bridge/logic.test.d.ts.map +1 -0
  44. package/lib/__tests__/bridge/logic.test.js +773 -0
  45. package/lib/__tests__/bridge/logic.test.js.map +1 -0
  46. package/lib/__tests__/bridge/prepareTransaction.test.d.ts +2 -0
  47. package/lib/__tests__/bridge/prepareTransaction.test.d.ts.map +1 -0
  48. package/lib/__tests__/bridge/prepareTransaction.test.js +121 -0
  49. package/lib/__tests__/bridge/prepareTransaction.test.js.map +1 -0
  50. package/lib/__tests__/bridge/signOperation.test.d.ts +2 -0
  51. package/lib/__tests__/bridge/signOperation.test.d.ts.map +1 -0
  52. package/lib/__tests__/bridge/signOperation.test.js +185 -0
  53. package/lib/__tests__/bridge/signOperation.test.js.map +1 -0
  54. package/lib/__tests__/bridge/synchronisation.test.d.ts +2 -0
  55. package/lib/__tests__/bridge/synchronisation.test.d.ts.map +1 -0
  56. package/lib/__tests__/bridge/synchronisation.test.js +349 -0
  57. package/lib/__tests__/bridge/synchronisation.test.js.map +1 -0
  58. package/lib/__tests__/bridge/transaction.test.d.ts +2 -0
  59. package/lib/__tests__/bridge/transaction.test.d.ts.map +1 -0
  60. package/lib/__tests__/bridge/transaction.test.js +231 -0
  61. package/lib/__tests__/bridge/transaction.test.js.map +1 -0
  62. package/lib/__tests__/errors.test.d.ts +2 -0
  63. package/lib/__tests__/errors.test.d.ts.map +1 -0
  64. package/lib/__tests__/errors.test.js +18 -0
  65. package/lib/__tests__/errors.test.js.map +1 -0
  66. package/lib/__tests__/index.test.d.ts +2 -0
  67. package/lib/__tests__/index.test.d.ts.map +1 -0
  68. package/lib/__tests__/index.test.js +27 -0
  69. package/lib/__tests__/index.test.js.map +1 -0
  70. package/lib/__tests__/network/index.test.d.ts +2 -0
  71. package/lib/__tests__/network/index.test.d.ts.map +1 -0
  72. package/lib/__tests__/network/index.test.js +57 -0
  73. package/lib/__tests__/network/index.test.js.map +1 -0
  74. package/lib/__tests__/signer/index.test.d.ts +2 -0
  75. package/lib/__tests__/signer/index.test.d.ts.map +1 -0
  76. package/lib/__tests__/signer/index.test.js +37 -0
  77. package/lib/__tests__/signer/index.test.js.map +1 -0
  78. package/lib/api/graphql/queries.d.ts +5 -0
  79. package/lib/api/graphql/queries.d.ts.map +1 -0
  80. package/lib/api/graphql/queries.js +56 -0
  81. package/lib/api/graphql/queries.js.map +1 -0
  82. package/lib/api/graphql/types.d.ts +79 -0
  83. package/lib/api/graphql/types.d.ts.map +1 -0
  84. package/lib/api/graphql/types.js +3 -0
  85. package/lib/api/graphql/types.js.map +1 -0
  86. package/lib/api/index.d.ts +31 -0
  87. package/lib/api/index.d.ts.map +1 -0
  88. package/lib/api/index.js +200 -0
  89. package/lib/api/index.js.map +1 -0
  90. package/lib/bridge/bridge.fixture.d.ts +4 -0
  91. package/lib/bridge/bridge.fixture.d.ts.map +1 -0
  92. package/lib/bridge/bridge.fixture.js +56 -0
  93. package/lib/bridge/bridge.fixture.js.map +1 -0
  94. package/lib/bridge/broadcast.d.ts +7 -0
  95. package/lib/bridge/broadcast.d.ts.map +1 -0
  96. package/lib/bridge/broadcast.js +20 -0
  97. package/lib/bridge/broadcast.js.map +1 -0
  98. package/lib/bridge/buildTransaction.d.ts +7 -0
  99. package/lib/bridge/buildTransaction.d.ts.map +1 -0
  100. package/lib/bridge/buildTransaction.js +28 -0
  101. package/lib/bridge/buildTransaction.js.map +1 -0
  102. package/lib/bridge/createTransaction.d.ts +4 -0
  103. package/lib/bridge/createTransaction.d.ts.map +1 -0
  104. package/lib/bridge/createTransaction.js +20 -0
  105. package/lib/bridge/createTransaction.js.map +1 -0
  106. package/lib/bridge/deviceTransactionConfig.d.ts +11 -0
  107. package/lib/bridge/deviceTransactionConfig.d.ts.map +1 -0
  108. package/lib/bridge/deviceTransactionConfig.js +23 -0
  109. package/lib/bridge/deviceTransactionConfig.js.map +1 -0
  110. package/lib/bridge/estimateMaxSpendable.d.ts +10 -0
  111. package/lib/bridge/estimateMaxSpendable.d.ts.map +1 -0
  112. package/lib/bridge/estimateMaxSpendable.js +30 -0
  113. package/lib/bridge/estimateMaxSpendable.js.map +1 -0
  114. package/lib/bridge/getFeesForTransaction.d.ts +16 -0
  115. package/lib/bridge/getFeesForTransaction.d.ts.map +1 -0
  116. package/lib/bridge/getFeesForTransaction.js +74 -0
  117. package/lib/bridge/getFeesForTransaction.js.map +1 -0
  118. package/lib/bridge/getTransactionStatus.d.ts +5 -0
  119. package/lib/bridge/getTransactionStatus.d.ts.map +1 -0
  120. package/lib/bridge/getTransactionStatus.js +48 -0
  121. package/lib/bridge/getTransactionStatus.js.map +1 -0
  122. package/lib/bridge/index.d.ts +8 -0
  123. package/lib/bridge/index.d.ts.map +1 -0
  124. package/lib/bridge/index.js +54 -0
  125. package/lib/bridge/index.js.map +1 -0
  126. package/lib/bridge/logic.d.ts +24 -0
  127. package/lib/bridge/logic.d.ts.map +1 -0
  128. package/lib/bridge/logic.js +200 -0
  129. package/lib/bridge/logic.js.map +1 -0
  130. package/lib/bridge/prepareTransaction.d.ts +5 -0
  131. package/lib/bridge/prepareTransaction.d.ts.map +1 -0
  132. package/lib/bridge/prepareTransaction.js +44 -0
  133. package/lib/bridge/prepareTransaction.js.map +1 -0
  134. package/lib/bridge/signOperation.d.ts +11 -0
  135. package/lib/bridge/signOperation.d.ts.map +1 -0
  136. package/lib/bridge/signOperation.js +77 -0
  137. package/lib/bridge/signOperation.js.map +1 -0
  138. package/lib/bridge/synchronisation.d.ts +3 -0
  139. package/lib/bridge/synchronisation.d.ts.map +1 -0
  140. package/lib/bridge/synchronisation.js +53 -0
  141. package/lib/bridge/synchronisation.js.map +1 -0
  142. package/lib/bridge/transaction.d.ts +15 -0
  143. package/lib/bridge/transaction.d.ts.map +1 -0
  144. package/lib/bridge/transaction.js +37 -0
  145. package/lib/bridge/transaction.js.map +1 -0
  146. package/lib/constants.d.ts +19 -0
  147. package/lib/constants.d.ts.map +1 -0
  148. package/lib/constants.js +33 -0
  149. package/lib/constants.js.map +1 -0
  150. package/lib/errors.d.ts +10 -0
  151. package/lib/errors.d.ts.map +1 -0
  152. package/lib/errors.js +8 -0
  153. package/lib/errors.js.map +1 -0
  154. package/lib/index.d.ts +3 -0
  155. package/lib/index.d.ts.map +1 -0
  156. package/lib/index.js +21 -0
  157. package/lib/index.js.map +1 -0
  158. package/lib/network/index.d.ts +6 -0
  159. package/lib/network/index.d.ts.map +1 -0
  160. package/lib/network/index.js +39 -0
  161. package/lib/network/index.js.map +1 -0
  162. package/lib/signer/index.d.ts +6 -0
  163. package/lib/signer/index.d.ts.map +1 -0
  164. package/lib/signer/index.js +23 -0
  165. package/lib/signer/index.js.map +1 -0
  166. package/lib/test/bot-specs.d.ts +7 -0
  167. package/lib/test/bot-specs.d.ts.map +1 -0
  168. package/lib/test/bot-specs.js +77 -0
  169. package/lib/test/bot-specs.js.map +1 -0
  170. package/lib/test/bridgeDatasetTest.d.ts +4 -0
  171. package/lib/test/bridgeDatasetTest.d.ts.map +1 -0
  172. package/lib/test/bridgeDatasetTest.js +85 -0
  173. package/lib/test/bridgeDatasetTest.js.map +1 -0
  174. package/lib/test/cli.d.ts +19 -0
  175. package/lib/test/cli.d.ts.map +1 -0
  176. package/lib/test/cli.js +59 -0
  177. package/lib/test/cli.js.map +1 -0
  178. package/lib/test/index.d.ts +4 -0
  179. package/lib/test/index.d.ts.map +1 -0
  180. package/lib/test/index.js +20 -0
  181. package/lib/test/index.js.map +1 -0
  182. package/lib/test/speculos-deviceActions.d.ts +5 -0
  183. package/lib/test/speculos-deviceActions.d.ts.map +1 -0
  184. package/lib/test/speculos-deviceActions.js +46 -0
  185. package/lib/test/speculos-deviceActions.js.map +1 -0
  186. package/lib/types/bridge.d.ts +5 -0
  187. package/lib/types/bridge.d.ts.map +1 -0
  188. package/lib/types/bridge.js +9 -0
  189. package/lib/types/bridge.js.map +1 -0
  190. package/lib/types/index.d.ts +62 -0
  191. package/lib/types/index.d.ts.map +1 -0
  192. package/lib/types/index.js +19 -0
  193. package/lib/types/index.js.map +1 -0
  194. package/lib/types/signer.d.ts +27 -0
  195. package/lib/types/signer.d.ts.map +1 -0
  196. package/lib/types/signer.js +3 -0
  197. package/lib/types/signer.js.map +1 -0
  198. package/lib-es/__tests__/api/index.test.d.ts +2 -0
  199. package/lib-es/__tests__/api/index.test.d.ts.map +1 -0
  200. package/lib-es/__tests__/api/index.test.js +442 -0
  201. package/lib-es/__tests__/api/index.test.js.map +1 -0
  202. package/lib-es/__tests__/bridge/broadcast.test.d.ts +2 -0
  203. package/lib-es/__tests__/bridge/broadcast.test.d.ts.map +1 -0
  204. package/lib-es/__tests__/bridge/broadcast.test.js +93 -0
  205. package/lib-es/__tests__/bridge/broadcast.test.js.map +1 -0
  206. package/lib-es/__tests__/bridge/buildTransaction.test.d.ts +2 -0
  207. package/lib-es/__tests__/bridge/buildTransaction.test.d.ts.map +1 -0
  208. package/lib-es/__tests__/bridge/buildTransaction.test.js +57 -0
  209. package/lib-es/__tests__/bridge/buildTransaction.test.js.map +1 -0
  210. package/lib-es/__tests__/bridge/createTransaction.test.d.ts +2 -0
  211. package/lib-es/__tests__/bridge/createTransaction.test.d.ts.map +1 -0
  212. package/lib-es/__tests__/bridge/createTransaction.test.js +33 -0
  213. package/lib-es/__tests__/bridge/createTransaction.test.js.map +1 -0
  214. package/lib-es/__tests__/bridge/deviceTransactionConfig.test.d.ts +2 -0
  215. package/lib-es/__tests__/bridge/deviceTransactionConfig.test.d.ts.map +1 -0
  216. package/lib-es/__tests__/bridge/deviceTransactionConfig.test.js +18 -0
  217. package/lib-es/__tests__/bridge/deviceTransactionConfig.test.js.map +1 -0
  218. package/lib-es/__tests__/bridge/estimateMaxSpendable.test.d.ts +2 -0
  219. package/lib-es/__tests__/bridge/estimateMaxSpendable.test.d.ts.map +1 -0
  220. package/lib-es/__tests__/bridge/estimateMaxSpendable.test.js +79 -0
  221. package/lib-es/__tests__/bridge/estimateMaxSpendable.test.js.map +1 -0
  222. package/lib-es/__tests__/bridge/getFeesForTransaction.test.d.ts +2 -0
  223. package/lib-es/__tests__/bridge/getFeesForTransaction.test.d.ts.map +1 -0
  224. package/lib-es/__tests__/bridge/getFeesForTransaction.test.js +160 -0
  225. package/lib-es/__tests__/bridge/getFeesForTransaction.test.js.map +1 -0
  226. package/lib-es/__tests__/bridge/getTransactionStatus.test.d.ts +2 -0
  227. package/lib-es/__tests__/bridge/getTransactionStatus.test.d.ts.map +1 -0
  228. package/lib-es/__tests__/bridge/getTransactionStatus.test.js +128 -0
  229. package/lib-es/__tests__/bridge/getTransactionStatus.test.js.map +1 -0
  230. package/lib-es/__tests__/bridge/index.test.d.ts +2 -0
  231. package/lib-es/__tests__/bridge/index.test.d.ts.map +1 -0
  232. package/lib-es/__tests__/bridge/index.test.js +111 -0
  233. package/lib-es/__tests__/bridge/index.test.js.map +1 -0
  234. package/lib-es/__tests__/bridge/logic.test.d.ts +2 -0
  235. package/lib-es/__tests__/bridge/logic.test.d.ts.map +1 -0
  236. package/lib-es/__tests__/bridge/logic.test.js +768 -0
  237. package/lib-es/__tests__/bridge/logic.test.js.map +1 -0
  238. package/lib-es/__tests__/bridge/prepareTransaction.test.d.ts +2 -0
  239. package/lib-es/__tests__/bridge/prepareTransaction.test.d.ts.map +1 -0
  240. package/lib-es/__tests__/bridge/prepareTransaction.test.js +116 -0
  241. package/lib-es/__tests__/bridge/prepareTransaction.test.js.map +1 -0
  242. package/lib-es/__tests__/bridge/signOperation.test.d.ts +2 -0
  243. package/lib-es/__tests__/bridge/signOperation.test.d.ts.map +1 -0
  244. package/lib-es/__tests__/bridge/signOperation.test.js +157 -0
  245. package/lib-es/__tests__/bridge/signOperation.test.js.map +1 -0
  246. package/lib-es/__tests__/bridge/synchronisation.test.d.ts +2 -0
  247. package/lib-es/__tests__/bridge/synchronisation.test.d.ts.map +1 -0
  248. package/lib-es/__tests__/bridge/synchronisation.test.js +347 -0
  249. package/lib-es/__tests__/bridge/synchronisation.test.js.map +1 -0
  250. package/lib-es/__tests__/bridge/transaction.test.d.ts +2 -0
  251. package/lib-es/__tests__/bridge/transaction.test.d.ts.map +1 -0
  252. package/lib-es/__tests__/bridge/transaction.test.js +226 -0
  253. package/lib-es/__tests__/bridge/transaction.test.js.map +1 -0
  254. package/lib-es/__tests__/errors.test.d.ts +2 -0
  255. package/lib-es/__tests__/errors.test.d.ts.map +1 -0
  256. package/lib-es/__tests__/errors.test.js +16 -0
  257. package/lib-es/__tests__/errors.test.js.map +1 -0
  258. package/lib-es/__tests__/index.test.d.ts +2 -0
  259. package/lib-es/__tests__/index.test.d.ts.map +1 -0
  260. package/lib-es/__tests__/index.test.js +25 -0
  261. package/lib-es/__tests__/index.test.js.map +1 -0
  262. package/lib-es/__tests__/network/index.test.d.ts +2 -0
  263. package/lib-es/__tests__/network/index.test.d.ts.map +1 -0
  264. package/lib-es/__tests__/network/index.test.js +55 -0
  265. package/lib-es/__tests__/network/index.test.js.map +1 -0
  266. package/lib-es/__tests__/signer/index.test.d.ts +2 -0
  267. package/lib-es/__tests__/signer/index.test.d.ts.map +1 -0
  268. package/lib-es/__tests__/signer/index.test.js +32 -0
  269. package/lib-es/__tests__/signer/index.test.js.map +1 -0
  270. package/lib-es/api/graphql/queries.d.ts +5 -0
  271. package/lib-es/api/graphql/queries.d.ts.map +1 -0
  272. package/lib-es/api/graphql/queries.js +53 -0
  273. package/lib-es/api/graphql/queries.js.map +1 -0
  274. package/lib-es/api/graphql/types.d.ts +79 -0
  275. package/lib-es/api/graphql/types.d.ts.map +1 -0
  276. package/lib-es/api/graphql/types.js +2 -0
  277. package/lib-es/api/graphql/types.js.map +1 -0
  278. package/lib-es/api/index.d.ts +31 -0
  279. package/lib-es/api/index.d.ts.map +1 -0
  280. package/lib-es/api/index.js +193 -0
  281. package/lib-es/api/index.js.map +1 -0
  282. package/lib-es/bridge/bridge.fixture.d.ts +4 -0
  283. package/lib-es/bridge/bridge.fixture.d.ts.map +1 -0
  284. package/lib-es/bridge/bridge.fixture.js +48 -0
  285. package/lib-es/bridge/bridge.fixture.js.map +1 -0
  286. package/lib-es/bridge/broadcast.d.ts +7 -0
  287. package/lib-es/bridge/broadcast.d.ts.map +1 -0
  288. package/lib-es/bridge/broadcast.js +18 -0
  289. package/lib-es/bridge/broadcast.js.map +1 -0
  290. package/lib-es/bridge/buildTransaction.d.ts +7 -0
  291. package/lib-es/bridge/buildTransaction.d.ts.map +1 -0
  292. package/lib-es/bridge/buildTransaction.js +26 -0
  293. package/lib-es/bridge/buildTransaction.js.map +1 -0
  294. package/lib-es/bridge/createTransaction.d.ts +4 -0
  295. package/lib-es/bridge/createTransaction.d.ts.map +1 -0
  296. package/lib-es/bridge/createTransaction.js +15 -0
  297. package/lib-es/bridge/createTransaction.js.map +1 -0
  298. package/lib-es/bridge/deviceTransactionConfig.d.ts +11 -0
  299. package/lib-es/bridge/deviceTransactionConfig.d.ts.map +1 -0
  300. package/lib-es/bridge/deviceTransactionConfig.js +19 -0
  301. package/lib-es/bridge/deviceTransactionConfig.js.map +1 -0
  302. package/lib-es/bridge/estimateMaxSpendable.d.ts +10 -0
  303. package/lib-es/bridge/estimateMaxSpendable.d.ts.map +1 -0
  304. package/lib-es/bridge/estimateMaxSpendable.js +28 -0
  305. package/lib-es/bridge/estimateMaxSpendable.js.map +1 -0
  306. package/lib-es/bridge/getFeesForTransaction.d.ts +16 -0
  307. package/lib-es/bridge/getFeesForTransaction.d.ts.map +1 -0
  308. package/lib-es/bridge/getFeesForTransaction.js +66 -0
  309. package/lib-es/bridge/getFeesForTransaction.js.map +1 -0
  310. package/lib-es/bridge/getTransactionStatus.d.ts +5 -0
  311. package/lib-es/bridge/getTransactionStatus.d.ts.map +1 -0
  312. package/lib-es/bridge/getTransactionStatus.js +46 -0
  313. package/lib-es/bridge/getTransactionStatus.js.map +1 -0
  314. package/lib-es/bridge/index.d.ts +8 -0
  315. package/lib-es/bridge/index.d.ts.map +1 -0
  316. package/lib-es/bridge/index.js +47 -0
  317. package/lib-es/bridge/index.js.map +1 -0
  318. package/lib-es/bridge/logic.d.ts +24 -0
  319. package/lib-es/bridge/logic.d.ts.map +1 -0
  320. package/lib-es/bridge/logic.js +183 -0
  321. package/lib-es/bridge/logic.js.map +1 -0
  322. package/lib-es/bridge/prepareTransaction.d.ts +5 -0
  323. package/lib-es/bridge/prepareTransaction.d.ts.map +1 -0
  324. package/lib-es/bridge/prepareTransaction.js +39 -0
  325. package/lib-es/bridge/prepareTransaction.js.map +1 -0
  326. package/lib-es/bridge/signOperation.d.ts +11 -0
  327. package/lib-es/bridge/signOperation.d.ts.map +1 -0
  328. package/lib-es/bridge/signOperation.js +70 -0
  329. package/lib-es/bridge/signOperation.js.map +1 -0
  330. package/lib-es/bridge/synchronisation.d.ts +3 -0
  331. package/lib-es/bridge/synchronisation.d.ts.map +1 -0
  332. package/lib-es/bridge/synchronisation.js +49 -0
  333. package/lib-es/bridge/synchronisation.js.map +1 -0
  334. package/lib-es/bridge/transaction.d.ts +15 -0
  335. package/lib-es/bridge/transaction.d.ts.map +1 -0
  336. package/lib-es/bridge/transaction.js +31 -0
  337. package/lib-es/bridge/transaction.js.map +1 -0
  338. package/lib-es/constants.d.ts +19 -0
  339. package/lib-es/constants.d.ts.map +1 -0
  340. package/lib-es/constants.js +30 -0
  341. package/lib-es/constants.js.map +1 -0
  342. package/lib-es/errors.d.ts +10 -0
  343. package/lib-es/errors.d.ts.map +1 -0
  344. package/lib-es/errors.js +5 -0
  345. package/lib-es/errors.js.map +1 -0
  346. package/lib-es/index.d.ts +3 -0
  347. package/lib-es/index.d.ts.map +1 -0
  348. package/lib-es/index.js +3 -0
  349. package/lib-es/index.js.map +1 -0
  350. package/lib-es/network/index.d.ts +6 -0
  351. package/lib-es/network/index.d.ts.map +1 -0
  352. package/lib-es/network/index.js +35 -0
  353. package/lib-es/network/index.js.map +1 -0
  354. package/lib-es/signer/index.d.ts +6 -0
  355. package/lib-es/signer/index.d.ts.map +1 -0
  356. package/lib-es/signer/index.js +21 -0
  357. package/lib-es/signer/index.js.map +1 -0
  358. package/lib-es/test/bot-specs.d.ts +7 -0
  359. package/lib-es/test/bot-specs.d.ts.map +1 -0
  360. package/lib-es/test/bot-specs.js +72 -0
  361. package/lib-es/test/bot-specs.js.map +1 -0
  362. package/lib-es/test/bridgeDatasetTest.d.ts +4 -0
  363. package/lib-es/test/bridgeDatasetTest.d.ts.map +1 -0
  364. package/lib-es/test/bridgeDatasetTest.js +79 -0
  365. package/lib-es/test/bridgeDatasetTest.js.map +1 -0
  366. package/lib-es/test/cli.d.ts +19 -0
  367. package/lib-es/test/cli.d.ts.map +1 -0
  368. package/lib-es/test/cli.js +53 -0
  369. package/lib-es/test/cli.js.map +1 -0
  370. package/lib-es/test/index.d.ts +4 -0
  371. package/lib-es/test/index.d.ts.map +1 -0
  372. package/lib-es/test/index.js +4 -0
  373. package/lib-es/test/index.js.map +1 -0
  374. package/lib-es/test/speculos-deviceActions.d.ts +5 -0
  375. package/lib-es/test/speculos-deviceActions.d.ts.map +1 -0
  376. package/lib-es/test/speculos-deviceActions.js +43 -0
  377. package/lib-es/test/speculos-deviceActions.js.map +1 -0
  378. package/lib-es/types/bridge.d.ts +5 -0
  379. package/lib-es/types/bridge.d.ts.map +1 -0
  380. package/lib-es/types/bridge.js +6 -0
  381. package/lib-es/types/bridge.js.map +1 -0
  382. package/lib-es/types/index.d.ts +62 -0
  383. package/lib-es/types/index.d.ts.map +1 -0
  384. package/lib-es/types/index.js +3 -0
  385. package/lib-es/types/index.js.map +1 -0
  386. package/lib-es/types/signer.d.ts +27 -0
  387. package/lib-es/types/signer.d.ts.map +1 -0
  388. package/lib-es/types/signer.js +2 -0
  389. package/lib-es/types/signer.js.map +1 -0
  390. package/package.json +124 -0
  391. package/src/__tests__/api/index.test.ts +499 -0
  392. package/src/__tests__/bridge/broadcast.test.ts +98 -0
  393. package/src/__tests__/bridge/buildTransaction.test.ts +61 -0
  394. package/src/__tests__/bridge/createTransaction.test.ts +27 -0
  395. package/src/__tests__/bridge/deviceTransactionConfig.test.ts +19 -0
  396. package/src/__tests__/bridge/estimateMaxSpendable.test.ts +94 -0
  397. package/src/__tests__/bridge/getFeesForTransaction.test.ts +189 -0
  398. package/src/__tests__/bridge/getTransactionStatus.test.ts +155 -0
  399. package/src/__tests__/bridge/index.test.ts +108 -0
  400. package/src/__tests__/bridge/logic.test.ts +876 -0
  401. package/src/__tests__/bridge/prepareTransaction.test.ts +118 -0
  402. package/src/__tests__/bridge/signOperation.test.ts +178 -0
  403. package/src/__tests__/bridge/synchronisation.test.ts +374 -0
  404. package/src/__tests__/bridge/transaction.test.ts +261 -0
  405. package/src/__tests__/errors.test.ts +25 -0
  406. package/src/__tests__/index.test.ts +26 -0
  407. package/src/__tests__/network/index.test.ts +95 -0
  408. package/src/__tests__/signer/index.test.ts +24 -0
  409. package/src/api/graphql/queries.ts +53 -0
  410. package/src/api/graphql/types.ts +85 -0
  411. package/src/api/index.ts +224 -0
  412. package/src/bridge/bridge.fixture.ts +53 -0
  413. package/src/bridge/broadcast.ts +17 -0
  414. package/src/bridge/buildTransaction.ts +29 -0
  415. package/src/bridge/createTransaction.ts +17 -0
  416. package/src/bridge/deviceTransactionConfig.ts +30 -0
  417. package/src/bridge/estimateMaxSpendable.ts +35 -0
  418. package/src/bridge/getFeesForTransaction.ts +87 -0
  419. package/src/bridge/getTransactionStatus.ts +54 -0
  420. package/src/bridge/index.ts +65 -0
  421. package/src/bridge/logic.ts +265 -0
  422. package/src/bridge/prepareTransaction.ts +55 -0
  423. package/src/bridge/signOperation.ts +82 -0
  424. package/src/bridge/synchronisation.ts +50 -0
  425. package/src/bridge/transaction.ts +61 -0
  426. package/src/constants.ts +34 -0
  427. package/src/errors.ts +7 -0
  428. package/src/index.ts +3 -0
  429. package/src/network/index.ts +54 -0
  430. package/src/signer/index.ts +17 -0
  431. package/src/test/bot-specs.ts +86 -0
  432. package/src/test/bridgeDatasetTest.ts +82 -0
  433. package/src/test/cli.ts +80 -0
  434. package/src/test/index.ts +3 -0
  435. package/src/test/speculos-deviceActions.ts +52 -0
  436. package/src/types/bridge.ts +4 -0
  437. package/src/types/index.ts +74 -0
  438. package/src/types/signer.ts +26 -0
  439. package/tsconfig.json +14 -0
@@ -0,0 +1,876 @@
1
+ import {
2
+ EntryFunctionPayloadResponse,
3
+ Event,
4
+ InputEntryFunctionData,
5
+ WriteSetChange,
6
+ } from "@aptos-labs/ts-sdk";
7
+ import type { Operation, OperationType } from "@ledgerhq/types-live";
8
+ import BigNumber from "bignumber.js";
9
+ import { APTOS_ASSET_ID, APTOS_COIN_CHANGE, DIRECTION } from "../../constants";
10
+ import {
11
+ calculateAmount,
12
+ compareAddress,
13
+ getAptosAmounts,
14
+ getFunctionAddress,
15
+ isChangeOfAptos,
16
+ isTestnet,
17
+ processRecipients,
18
+ getMaxSendBalance,
19
+ normalizeTransactionOptions,
20
+ getBlankOperation,
21
+ txsToOps,
22
+ } from "../../bridge/logic";
23
+ import type { AptosTransaction, TransactionOptions } from "../../types";
24
+
25
+ jest.mock("@ledgerhq/cryptoassets", () => ({
26
+ getCryptoCurrencyById: jest.fn(),
27
+ }));
28
+
29
+ describe("Aptos logic ", () => {
30
+ describe("isTestnet", () => {
31
+ it("should return true for testnet currencies", () => {
32
+ expect(isTestnet("aptos_testnet")).toBe(true);
33
+ });
34
+
35
+ it("should return false for mainnet currencies", () => {
36
+ expect(isTestnet("aptos")).toBe(false);
37
+ });
38
+ });
39
+
40
+ describe("getMaxSendBalance", () => {
41
+ it("should return the correct max send balance when amount is greater than total gas", () => {
42
+ const amount = new BigNumber(1000000);
43
+ const gas = new BigNumber(200);
44
+ const gasPrice = new BigNumber(100);
45
+ const result = getMaxSendBalance(amount, gas, gasPrice);
46
+ expect(result.isEqualTo(amount.minus(gas.multipliedBy(gasPrice)))).toBe(true);
47
+ });
48
+
49
+ it("should return zero when amount is less than total gas", () => {
50
+ const amount = new BigNumber(1000);
51
+ const gas = new BigNumber(200);
52
+ const gasPrice = new BigNumber(100);
53
+ const result = getMaxSendBalance(amount, gas, gasPrice);
54
+ expect(result.isEqualTo(new BigNumber(0))).toBe(true);
55
+ });
56
+
57
+ it("should return zero when amount is equal to total gas", () => {
58
+ const amount = new BigNumber(20000);
59
+ const gas = new BigNumber(200);
60
+ const gasPrice = new BigNumber(100);
61
+ const result = getMaxSendBalance(amount, gas, gasPrice);
62
+ expect(result.isEqualTo(new BigNumber(0))).toBe(true);
63
+ });
64
+
65
+ it("should handle zero amount", () => {
66
+ const amount = new BigNumber(0);
67
+ const gas = new BigNumber(200);
68
+ const gasPrice = new BigNumber(100);
69
+ const result = getMaxSendBalance(amount, gas, gasPrice);
70
+ expect(result.isEqualTo(new BigNumber(0))).toBe(true);
71
+ });
72
+
73
+ it("should handle zero gas and gas price", () => {
74
+ const amount = new BigNumber(1000000);
75
+ const gas = new BigNumber(0);
76
+ const gasPrice = new BigNumber(0);
77
+ const result = getMaxSendBalance(amount, gas, gasPrice);
78
+ expect(result.isEqualTo(amount)).toBe(true);
79
+ });
80
+ });
81
+
82
+ describe("normalizeTransactionOptions", () => {
83
+ it("should normalize transaction options", () => {
84
+ const options: TransactionOptions = {
85
+ maxGasAmount: "1000",
86
+ gasUnitPrice: "10",
87
+ };
88
+
89
+ const result = normalizeTransactionOptions(options);
90
+ expect(result).toEqual(options);
91
+ });
92
+
93
+ it("should return undefined for empty values", () => {
94
+ const options: TransactionOptions = {
95
+ maxGasAmount: "",
96
+ gasUnitPrice: "",
97
+ };
98
+
99
+ const result = normalizeTransactionOptions(options);
100
+ expect(result).toEqual({
101
+ maxGasAmount: undefined,
102
+ gasUnitPrice: undefined,
103
+ });
104
+ });
105
+ });
106
+
107
+ describe("getBlankOperation", () => {
108
+ it("should return a blank operation", () => {
109
+ const tx: AptosTransaction = {
110
+ hash: "0x123",
111
+ block: { hash: "0xabc", height: 1 },
112
+ timestamp: "1000000",
113
+ sequence_number: "1",
114
+ version: "1",
115
+ } as unknown as AptosTransaction;
116
+
117
+ const id = "test-id";
118
+ const result = getBlankOperation(tx, id);
119
+
120
+ expect(result).toEqual({
121
+ id: "",
122
+ hash: "0x123",
123
+ type: "",
124
+ value: new BigNumber(0),
125
+ fee: new BigNumber(0),
126
+ blockHash: "0xabc",
127
+ blockHeight: 1,
128
+ senders: [],
129
+ recipients: [],
130
+ accountId: id,
131
+ date: new Date(1000),
132
+ extra: { version: "1" },
133
+ transactionSequenceNumber: 1,
134
+ hasFailed: false,
135
+ });
136
+ });
137
+
138
+ it("should return a blank operation even when some transaction fields are missing", () => {
139
+ const tx: AptosTransaction = {
140
+ hash: "0x123",
141
+ timestamp: "1000000",
142
+ sequence_number: "1",
143
+ } as unknown as AptosTransaction;
144
+
145
+ const id = "test-id";
146
+ const result = getBlankOperation(tx, id);
147
+
148
+ expect(result).toEqual({
149
+ id: "",
150
+ hash: "0x123",
151
+ type: "",
152
+ value: new BigNumber(0),
153
+ fee: new BigNumber(0),
154
+ blockHash: undefined,
155
+ blockHeight: undefined,
156
+ senders: [],
157
+ recipients: [],
158
+ accountId: id,
159
+ date: new Date(1000),
160
+ extra: { version: undefined },
161
+ transactionSequenceNumber: 1,
162
+ hasFailed: false,
163
+ });
164
+ });
165
+ });
166
+ });
167
+
168
+ describe("Aptos sync logic ", () => {
169
+ describe("compareAddress", () => {
170
+ it("should return true for identical addresses", () => {
171
+ const addressA = "0x1234567890abcdef";
172
+ const addressB = "0x1234567890abcdef";
173
+ expect(compareAddress(addressA, addressB)).toBe(true);
174
+ });
175
+
176
+ it("should return true for addresses with different cases", () => {
177
+ const addressA = "0x1234567890abcdef";
178
+ const addressB = "0x1234567890ABCDEF";
179
+ expect(compareAddress(addressA, addressB)).toBe(true);
180
+ });
181
+
182
+ it("should return true for addresses with different hex formats", () => {
183
+ const addressA = "0x1234567890abcdef";
184
+ const addressB = "1234567890abcdef";
185
+ expect(compareAddress(addressA, addressB)).toBe(true);
186
+ });
187
+
188
+ it("should return false for different addresses", () => {
189
+ const addressA = "0x1234567890abcdef";
190
+ const addressB = "0xfedcba0987654321";
191
+ expect(compareAddress(addressA, addressB)).toBe(false);
192
+ });
193
+ });
194
+
195
+ describe("getFunctionAddress", () => {
196
+ it("should return the function address when payload contains a function", () => {
197
+ const payload: InputEntryFunctionData = {
198
+ function: "0x1::coin::transfer",
199
+ typeArguments: [],
200
+ functionArguments: [],
201
+ };
202
+
203
+ const result = getFunctionAddress(payload);
204
+ expect(result).toBe("0x1");
205
+ });
206
+
207
+ it("should return undefined when payload does not contain a function", () => {
208
+ const payload = {
209
+ function: "::::",
210
+ typeArguments: [],
211
+ functionArguments: [],
212
+ } as InputEntryFunctionData;
213
+
214
+ const result = getFunctionAddress(payload);
215
+ expect(result).toBeUndefined();
216
+ });
217
+
218
+ it("should return undefined when payload is empty", () => {
219
+ const payload = {} as InputEntryFunctionData;
220
+
221
+ const result = getFunctionAddress(payload);
222
+ expect(result).toBeUndefined();
223
+ });
224
+ });
225
+
226
+ describe("processRecipients", () => {
227
+ let op: Operation;
228
+
229
+ beforeEach(() => {
230
+ op = {
231
+ id: "",
232
+ hash: "",
233
+ type: "" as OperationType,
234
+ value: new BigNumber(0),
235
+ fee: new BigNumber(0),
236
+ blockHash: "",
237
+ blockHeight: 0,
238
+ senders: [],
239
+ recipients: [],
240
+ accountId: "",
241
+ date: new Date(),
242
+ extra: {},
243
+ transactionSequenceNumber: 0,
244
+ hasFailed: false,
245
+ };
246
+ });
247
+
248
+ it("should add recipient for transfer-like functions from LL account", () => {
249
+ const payload: InputEntryFunctionData = {
250
+ function: "0x1::coin::transfer",
251
+ typeArguments: [],
252
+ functionArguments: ["0x13", 1], // from: &signer, to: address, amount: u64
253
+ };
254
+
255
+ processRecipients(payload, "0x13", op, "0x1");
256
+ expect(op.recipients).toContain("0x13");
257
+ });
258
+
259
+ it("should add recipient for transfer-like functions from external account", () => {
260
+ const payload: InputEntryFunctionData = {
261
+ function: "0x1::coin::transfer",
262
+ typeArguments: [],
263
+ functionArguments: ["0x12", 1], // from: &signer, to: address, amount: u64
264
+ };
265
+
266
+ processRecipients(payload, "0x13", op, "0x1");
267
+ expect(op.recipients).toContain("0x12");
268
+ });
269
+
270
+ it("should add recipients for batch transfer functions", () => {
271
+ const payload: InputEntryFunctionData = {
272
+ function: "0x1::aptos_account::batch_transfer_coins",
273
+ typeArguments: [APTOS_ASSET_ID],
274
+ functionArguments: [
275
+ ["0x12", "0x13"],
276
+ [1, 2],
277
+ ],
278
+ };
279
+
280
+ op.senders.push("0x11");
281
+ processRecipients(payload, "0x12", op, "0x1");
282
+ expect(op.recipients).toContain("0x12");
283
+ });
284
+
285
+ it("should add function address as recipient for other smart contracts", () => {
286
+ const payload: InputEntryFunctionData = {
287
+ function: "0x2::other::contract",
288
+ typeArguments: [],
289
+ functionArguments: [["0x12"], [1]],
290
+ };
291
+
292
+ processRecipients(payload, "0x11", op, "0x2");
293
+ expect(op.recipients).toContain("0x2");
294
+ });
295
+ });
296
+
297
+ describe("isChangeOfAptos", () => {
298
+ it("should return true for a valid change of Aptos", () => {
299
+ const change = {
300
+ type: "write_resource",
301
+ data: {
302
+ type: APTOS_COIN_CHANGE,
303
+ data: {
304
+ withdraw_events: {
305
+ guid: {
306
+ id: {
307
+ addr: "0x11",
308
+ creation_num: "2",
309
+ },
310
+ },
311
+ },
312
+ },
313
+ },
314
+ } as unknown as WriteSetChange;
315
+
316
+ const event = {
317
+ guid: {
318
+ account_address: "0x11",
319
+ creation_number: "2",
320
+ },
321
+ type: "0x1::coin::WithdrawEvent",
322
+ } as Event;
323
+
324
+ const result = isChangeOfAptos(change, event, "withdraw_events");
325
+ expect(result).toBe(true);
326
+ });
327
+
328
+ it("should return false for an invalid change of Aptos", () => {
329
+ const change = {
330
+ type: "write_resource",
331
+ data: {
332
+ type: APTOS_COIN_CHANGE,
333
+ data: {
334
+ withdraw_events: {
335
+ guid: {
336
+ id: {
337
+ addr: "0x12",
338
+ creation_num: "2",
339
+ },
340
+ },
341
+ },
342
+ },
343
+ },
344
+ } as unknown as WriteSetChange;
345
+
346
+ const event = {
347
+ guid: {
348
+ account_address: "0x11",
349
+ creation_number: "1",
350
+ },
351
+ type: "0x1::coin::WithdrawEvent",
352
+ } as Event;
353
+
354
+ const result = isChangeOfAptos(change, event, "withdraw_events");
355
+ expect(result).toBe(false);
356
+ });
357
+
358
+ it("should return false for a change with a different WriteSet type", () => {
359
+ const change = {
360
+ type: "write_module",
361
+ data: {},
362
+ } as unknown as WriteSetChange;
363
+
364
+ const event = {
365
+ guid: {
366
+ account_address: "0x1",
367
+ creation_number: "1",
368
+ },
369
+ type: "0x1::coin::WithdrawEvent",
370
+ } as Event;
371
+
372
+ const result = isChangeOfAptos(change, event, "withdraw_events");
373
+ expect(result).toBe(false);
374
+ });
375
+
376
+ it("should return false if no data in WriteSet Change", () => {
377
+ const change = {
378
+ type: "write_resource",
379
+ } as unknown as WriteSetChange;
380
+
381
+ const event = {
382
+ guid: {
383
+ account_address: "0x11",
384
+ creation_number: "2",
385
+ },
386
+ type: "0x1::coin::WithdrawEvent",
387
+ } as Event;
388
+
389
+ const result = isChangeOfAptos(change, event, "withdraw_events");
390
+ expect(result).toBe(false);
391
+ });
392
+
393
+ it("should return false if no type in change data", () => {
394
+ const change = {
395
+ type: "write_resource",
396
+ data: {
397
+ data: {
398
+ withdraw_events: {
399
+ guid: {
400
+ id: {
401
+ addr: "0x11",
402
+ creation_num: "2",
403
+ },
404
+ },
405
+ },
406
+ },
407
+ },
408
+ } as unknown as WriteSetChange;
409
+
410
+ const event = {
411
+ guid: {
412
+ account_address: "0x11",
413
+ creation_number: "2",
414
+ },
415
+ type: "0x1::coin::WithdrawEvent",
416
+ } as Event;
417
+
418
+ const result = isChangeOfAptos(change, event, "withdraw_events");
419
+ expect(result).toBe(false);
420
+ });
421
+
422
+ it("should return false for a change with a different WriteSet Change type", () => {
423
+ const change = {
424
+ type: "write_resource",
425
+ data: {
426
+ type: "0x1::coin::CoinStore<0x1::aptos_coin::ANY_OTHER_COIN>",
427
+ data: {
428
+ withdraw_events: {
429
+ guid: {
430
+ id: {
431
+ addr: "0x11",
432
+ creation_num: "2",
433
+ },
434
+ },
435
+ },
436
+ },
437
+ },
438
+ } as unknown as WriteSetChange;
439
+
440
+ const event = {
441
+ guid: {
442
+ account_address: "0x11",
443
+ creation_number: "2",
444
+ },
445
+ type: "0x1::coin::WithdrawEvent",
446
+ } as Event;
447
+
448
+ const result = isChangeOfAptos(change, event, "withdraw_events");
449
+ expect(result).toBe(false);
450
+ });
451
+ });
452
+
453
+ describe("getAptosAmounts", () => {
454
+ it("should calculate the correct amounts for withdraw and deposit events", () => {
455
+ const tx = {
456
+ events: [
457
+ {
458
+ type: "0x1::coin::WithdrawEvent",
459
+ guid: {
460
+ account_address: "0x11",
461
+ creation_number: "1",
462
+ },
463
+ data: {
464
+ amount: "100",
465
+ },
466
+ },
467
+ {
468
+ type: "0x1::coin::DepositEvent",
469
+ guid: {
470
+ account_address: "0x11",
471
+ creation_number: "2",
472
+ },
473
+ data: {
474
+ amount: "50",
475
+ },
476
+ },
477
+ ],
478
+ changes: [
479
+ {
480
+ type: "write_resource",
481
+ data: {
482
+ type: APTOS_COIN_CHANGE,
483
+ data: {
484
+ withdraw_events: {
485
+ guid: {
486
+ id: {
487
+ addr: "0x11",
488
+ creation_num: "1",
489
+ },
490
+ },
491
+ },
492
+ deposit_events: {
493
+ guid: {
494
+ id: {
495
+ addr: "0x11",
496
+ creation_num: "2",
497
+ },
498
+ },
499
+ },
500
+ },
501
+ },
502
+ },
503
+ ],
504
+ } as unknown as AptosTransaction;
505
+
506
+ const address = "0x11";
507
+ const result = getAptosAmounts(tx, address);
508
+
509
+ expect(result.amount_in).toEqual(new BigNumber(50));
510
+ expect(result.amount_out).toEqual(new BigNumber(100));
511
+ });
512
+
513
+ it("should return zero amounts if no matching events are found", () => {
514
+ const tx = {
515
+ events: [
516
+ {
517
+ type: "0x1::coin::WithdrawEvent",
518
+ guid: {
519
+ account_address: "0x11",
520
+ creation_number: "1",
521
+ },
522
+ data: {
523
+ amount: "100",
524
+ },
525
+ },
526
+ {
527
+ type: "0x1::coin::DepositEvent",
528
+ guid: {
529
+ account_address: "0x11",
530
+ creation_number: "2",
531
+ },
532
+ data: {
533
+ amount: "50",
534
+ },
535
+ },
536
+ ],
537
+ changes: [
538
+ {
539
+ type: "write_resource",
540
+ data: {
541
+ type: APTOS_COIN_CHANGE,
542
+ data: {
543
+ withdraw_events: {
544
+ guid: {
545
+ id: {
546
+ addr: "0x12", // should fail by address check
547
+ creation_num: "1",
548
+ },
549
+ },
550
+ },
551
+ deposit_events: {
552
+ guid: {
553
+ id: {
554
+ addr: "0x11",
555
+ creation_num: "3", // should fail by number check
556
+ },
557
+ },
558
+ },
559
+ },
560
+ },
561
+ },
562
+ ],
563
+ } as unknown as AptosTransaction;
564
+
565
+ const address = "0x11";
566
+ const result = getAptosAmounts(tx, address);
567
+
568
+ expect(result.amount_in).toEqual(new BigNumber(0));
569
+ expect(result.amount_out).toEqual(new BigNumber(0));
570
+ });
571
+
572
+ it("should handle transactions with other events", () => {
573
+ const tx = {
574
+ events: [
575
+ {
576
+ type: "0x1::coin::OtherEvent",
577
+ guid: {
578
+ account_address: "0x11",
579
+ creation_number: "1",
580
+ },
581
+ data: {
582
+ amount: "100",
583
+ },
584
+ },
585
+ ],
586
+ } as unknown as AptosTransaction;
587
+
588
+ const address = "0x1";
589
+ const result = getAptosAmounts(tx, address);
590
+
591
+ expect(result.amount_in).toEqual(new BigNumber(0));
592
+ expect(result.amount_out).toEqual(new BigNumber(0));
593
+ });
594
+ });
595
+
596
+ describe("calculateAmount", () => {
597
+ it("should calculate the correct amount when the address is the sender", () => {
598
+ const address = "0x11";
599
+ const sender = "0x11";
600
+ const fee = new BigNumber(10); // account pays fees
601
+ const amount_in = new BigNumber(50);
602
+ const amount_out = new BigNumber(100);
603
+
604
+ const result = calculateAmount(sender, address, fee, amount_in, amount_out);
605
+
606
+ // LL negates the amount for SEND transactions during output
607
+ expect(result).toEqual(new BigNumber(60)); // -(50 - 100 - 10)
608
+ });
609
+
610
+ it("should calculate the correct amount when the address is not the sender", () => {
611
+ const address = "0x11";
612
+ const sender = "0x12";
613
+ const fee = new BigNumber(10); // sender pays fees
614
+ const amount_in = new BigNumber(100);
615
+ const amount_out = new BigNumber(50);
616
+
617
+ const result = calculateAmount(sender, address, fee, amount_in, amount_out);
618
+
619
+ expect(result).toEqual(new BigNumber(50)); // 100 - 50
620
+ });
621
+
622
+ it("should handle transactions with zero amounts", () => {
623
+ const address = "0x11";
624
+ const sender = "0x11";
625
+ const fee = new BigNumber(10);
626
+ const amount_in = new BigNumber(0);
627
+ const amount_out = new BigNumber(0);
628
+
629
+ const result = calculateAmount(sender, address, fee, amount_in, amount_out);
630
+
631
+ // LL negates the amount for SEND transactions during output
632
+ expect(result).toEqual(new BigNumber(10)); // -(0 - 0 - 10)
633
+ });
634
+
635
+ it("should get negative numbers (for send tx with deposit to account)", () => {
636
+ const address = "0x11";
637
+ const sender = "0x11";
638
+ const fee = new BigNumber(10);
639
+ const amount_in = new BigNumber(100);
640
+ const amount_out = new BigNumber(0);
641
+
642
+ const result = calculateAmount(sender, address, fee, amount_in, amount_out);
643
+
644
+ // LL negates the amount for SEND transactions during output
645
+ expect(result).toEqual(new BigNumber(90).negated()); // 100 - 10
646
+ });
647
+ });
648
+
649
+ describe("txsToOps", () => {
650
+ it("should convert transactions to operations correctly", () => {
651
+ const address = "0x11";
652
+ const id = "test-id";
653
+ const txs: AptosTransaction[] = [
654
+ {
655
+ hash: "0x123",
656
+ sender: "0x11",
657
+ gas_used: "200",
658
+ gas_unit_price: "100",
659
+ success: true,
660
+ payload: {
661
+ type: "entry_function_payload",
662
+ function: "0x1::coin::transfer",
663
+ type_arguments: [],
664
+ arguments: ["0x12", 100],
665
+ } as EntryFunctionPayloadResponse,
666
+ events: [
667
+ {
668
+ type: "0x1::coin::WithdrawEvent",
669
+ guid: {
670
+ account_address: "0x11",
671
+ creation_number: "1",
672
+ },
673
+ data: {
674
+ amount: "100",
675
+ },
676
+ },
677
+ {
678
+ type: "0x1::coin::DepositEvent",
679
+ guid: {
680
+ account_address: "0x12",
681
+ creation_number: "2",
682
+ },
683
+ data: {
684
+ amount: "100",
685
+ },
686
+ },
687
+ ],
688
+ changes: [
689
+ {
690
+ type: "write_resource",
691
+ data: {
692
+ type: APTOS_COIN_CHANGE,
693
+ data: {
694
+ withdraw_events: {
695
+ guid: {
696
+ id: {
697
+ addr: "0x11",
698
+ creation_num: "1",
699
+ },
700
+ },
701
+ },
702
+ deposit_events: {
703
+ guid: {
704
+ id: {
705
+ addr: "0x12",
706
+ creation_num: "2",
707
+ },
708
+ },
709
+ },
710
+ },
711
+ },
712
+ },
713
+ ],
714
+ block: { hash: "0xabc", height: 1 },
715
+ timestamp: "1000000",
716
+ sequence_number: "1",
717
+ } as unknown as AptosTransaction,
718
+ ];
719
+
720
+ const result = txsToOps({ address }, id, txs);
721
+
722
+ expect(result).toHaveLength(1);
723
+ expect(result[0]).toEqual({
724
+ id: expect.any(String),
725
+ hash: "0x123",
726
+ type: DIRECTION.OUT,
727
+ value: new BigNumber(20100),
728
+ fee: new BigNumber(20000),
729
+ blockHash: "0xabc",
730
+ blockHeight: 1,
731
+ senders: ["0x11"],
732
+ recipients: ["0x12"],
733
+ accountId: id,
734
+ date: new Date(1000),
735
+ extra: { version: undefined },
736
+ transactionSequenceNumber: 1,
737
+ hasFailed: false,
738
+ });
739
+ });
740
+
741
+ it("should skip transactions without functions in payload", () => {
742
+ const address = "0x11";
743
+ const id = "test-id";
744
+ const txs: AptosTransaction[] = [
745
+ {
746
+ hash: "0x123",
747
+ sender: "0x11",
748
+ gas_used: "200",
749
+ gas_unit_price: "100",
750
+ success: true,
751
+ payload: {} as EntryFunctionPayloadResponse,
752
+ // payload: {
753
+ // type: "entry_function_payload",
754
+ // function: "0x1::coin::transfer",
755
+ // type_arguments: [],
756
+ // arguments: ["0x12", 100],
757
+ // } as EntryFunctionPayloadResponse,
758
+ events: [],
759
+ changes: [],
760
+ block: { hash: "0xabc", height: 1 },
761
+ timestamp: "1000000",
762
+ sequence_number: "1",
763
+ } as unknown as AptosTransaction,
764
+ ];
765
+
766
+ const result = txsToOps({ address }, id, txs);
767
+
768
+ expect(result).toHaveLength(0);
769
+ });
770
+
771
+ it("should skip transactions that result in no Aptos change", () => {
772
+ const address = "0x11";
773
+ const id = "test-id";
774
+ const txs: AptosTransaction[] = [
775
+ {
776
+ hash: "0x123",
777
+ sender: "0x12",
778
+ gas_used: "200",
779
+ gas_unit_price: "100",
780
+ success: true,
781
+ payload: {
782
+ type: "entry_function_payload",
783
+ function: "0x1::coin::transfer",
784
+ type_arguments: [],
785
+ arguments: ["0x11", 100],
786
+ } as EntryFunctionPayloadResponse,
787
+ events: [],
788
+ changes: [],
789
+ block: { hash: "0xabc", height: 1 },
790
+ timestamp: "1000000",
791
+ sequence_number: "1",
792
+ } as unknown as AptosTransaction,
793
+ ];
794
+
795
+ const result = txsToOps({ address }, id, txs);
796
+
797
+ expect(result).toHaveLength(0);
798
+ });
799
+
800
+ it("should handle failed transactions", () => {
801
+ const address = "0x11";
802
+ const id = "test-id";
803
+ const txs: AptosTransaction[] = [
804
+ {
805
+ hash: "0x123",
806
+ sender: "0x11",
807
+ gas_used: "200",
808
+ gas_unit_price: "100",
809
+ success: false,
810
+ payload: {
811
+ type: "entry_function_payload",
812
+ function: "0x1::coin::transfer",
813
+ type_arguments: [],
814
+ arguments: ["0x12", 100],
815
+ } as EntryFunctionPayloadResponse,
816
+ events: [
817
+ {
818
+ type: "0x1::coin::WithdrawEvent",
819
+ guid: {
820
+ account_address: "0x11",
821
+ creation_number: "1",
822
+ },
823
+ data: {
824
+ amount: "100",
825
+ },
826
+ },
827
+ {
828
+ type: "0x1::coin::DepositEvent",
829
+ guid: {
830
+ account_address: "0x12",
831
+ creation_number: "2",
832
+ },
833
+ data: {
834
+ amount: "100",
835
+ },
836
+ },
837
+ ],
838
+ changes: [
839
+ {
840
+ type: "write_resource",
841
+ data: {
842
+ type: APTOS_COIN_CHANGE,
843
+ data: {
844
+ withdraw_events: {
845
+ guid: {
846
+ id: {
847
+ addr: "0x11",
848
+ creation_num: "1",
849
+ },
850
+ },
851
+ },
852
+ deposit_events: {
853
+ guid: {
854
+ id: {
855
+ addr: "0x12",
856
+ creation_num: "2",
857
+ },
858
+ },
859
+ },
860
+ },
861
+ },
862
+ },
863
+ ],
864
+ block: { hash: "0xabc", height: 1 },
865
+ timestamp: "1000000",
866
+ sequence_number: "1",
867
+ } as unknown as AptosTransaction,
868
+ ];
869
+
870
+ const result = txsToOps({ address }, id, txs);
871
+
872
+ expect(result).toHaveLength(1);
873
+ expect(result[0].hasFailed).toBe(true);
874
+ });
875
+ });
876
+ });