@ledgerhq/coin-aptos 1.9.6 → 1.10.0-nightly.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (513) hide show
  1. package/.turbo/turbo-build.log +1 -1
  2. package/.unimportedrc.json +18 -6
  3. package/CHANGELOG.md +24 -0
  4. package/jest.config.js +1 -1
  5. package/jest.integ.config.js +8 -0
  6. package/lib/__tests__/api/craftTransaction.unit.test.d.ts +2 -0
  7. package/lib/__tests__/api/craftTransaction.unit.test.d.ts.map +1 -0
  8. package/lib/__tests__/api/craftTransaction.unit.test.js +50 -0
  9. package/lib/__tests__/api/craftTransaction.unit.test.js.map +1 -0
  10. package/lib/__tests__/api/getBalance.unit.test.d.ts +2 -0
  11. package/lib/__tests__/api/getBalance.unit.test.d.ts.map +1 -0
  12. package/lib/__tests__/api/getBalance.unit.test.js +41 -0
  13. package/lib/__tests__/api/getBalance.unit.test.js.map +1 -0
  14. package/lib/__tests__/api/index.integ.test.d.ts +2 -0
  15. package/lib/__tests__/api/index.integ.test.d.ts.map +1 -0
  16. package/lib/__tests__/api/index.integ.test.js +115 -0
  17. package/lib/__tests__/api/index.integ.test.js.map +1 -0
  18. package/lib/__tests__/api/index.test.js +48 -404
  19. package/lib/__tests__/api/index.test.js.map +1 -1
  20. package/lib/__tests__/bridge/broadcast.test.js +5 -5
  21. package/lib/__tests__/bridge/broadcast.test.js.map +1 -1
  22. package/lib/__tests__/bridge/getFeesForTransaction.test.js +115 -14
  23. package/lib/__tests__/bridge/getFeesForTransaction.test.js.map +1 -1
  24. package/lib/__tests__/bridge/getTransactionStatus.test.js +175 -37
  25. package/lib/__tests__/bridge/getTransactionStatus.test.js.map +1 -1
  26. package/lib/__tests__/bridge/logic.test.js +702 -478
  27. package/lib/__tests__/bridge/logic.test.js.map +1 -1
  28. package/lib/__tests__/bridge/prepareTransaction.test.js +3 -3
  29. package/lib/__tests__/bridge/prepareTransaction.test.js.map +1 -1
  30. package/lib/__tests__/bridge/signOperation.test.js +137 -14
  31. package/lib/__tests__/bridge/signOperation.test.js.map +1 -1
  32. package/lib/__tests__/bridge/synchronisation.test.js +1215 -68
  33. package/lib/__tests__/bridge/synchronisation.test.js.map +1 -1
  34. package/lib/__tests__/index.test.js +1 -1
  35. package/lib/__tests__/index.test.js.map +1 -1
  36. package/lib/__tests__/logic/buildTransaction.test.d.ts.map +1 -0
  37. package/lib/__tests__/logic/buildTransaction.test.js +112 -0
  38. package/lib/__tests__/logic/buildTransaction.test.js.map +1 -0
  39. package/lib/__tests__/logic/calculateAmount.unit.test.d.ts +2 -0
  40. package/lib/__tests__/logic/calculateAmount.unit.test.d.ts.map +1 -0
  41. package/lib/__tests__/logic/calculateAmount.unit.test.js +45 -0
  42. package/lib/__tests__/logic/calculateAmount.unit.test.js.map +1 -0
  43. package/lib/__tests__/logic/combine.unit.test.d.ts +2 -0
  44. package/lib/__tests__/logic/combine.unit.test.d.ts.map +1 -0
  45. package/lib/__tests__/logic/combine.unit.test.js +47 -0
  46. package/lib/__tests__/logic/combine.unit.test.js.map +1 -0
  47. package/lib/__tests__/logic/compareAddress.unit.test.d.ts +2 -0
  48. package/lib/__tests__/logic/compareAddress.unit.test.d.ts.map +1 -0
  49. package/lib/__tests__/logic/compareAddress.unit.test.js +26 -0
  50. package/lib/__tests__/logic/compareAddress.unit.test.js.map +1 -0
  51. package/lib/__tests__/logic/createTransaction.test.d.ts.map +1 -0
  52. package/lib/__tests__/{bridge → logic}/createTransaction.test.js +2 -2
  53. package/lib/__tests__/logic/createTransaction.test.js.map +1 -0
  54. package/lib/__tests__/logic/getCoinAndAmounts.unit.test.d.ts +2 -0
  55. package/lib/__tests__/logic/getCoinAndAmounts.unit.test.d.ts.map +1 -0
  56. package/lib/__tests__/logic/getCoinAndAmounts.unit.test.js +186 -0
  57. package/lib/__tests__/logic/getCoinAndAmounts.unit.test.js.map +1 -0
  58. package/lib/__tests__/logic/getFunctionAddress.unit.test.d.ts +2 -0
  59. package/lib/__tests__/logic/getFunctionAddress.unit.test.d.ts.map +1 -0
  60. package/lib/__tests__/logic/getFunctionAddress.unit.test.js +29 -0
  61. package/lib/__tests__/logic/getFunctionAddress.unit.test.js.map +1 -0
  62. package/lib/__tests__/logic/getResourceAddress.unit.test.d.ts +2 -0
  63. package/lib/__tests__/logic/getResourceAddress.unit.test.d.ts.map +1 -0
  64. package/lib/__tests__/logic/getResourceAddress.unit.test.js +218 -0
  65. package/lib/__tests__/logic/getResourceAddress.unit.test.js.map +1 -0
  66. package/lib/__tests__/logic/isTestnet.unit.test.d.ts +2 -0
  67. package/lib/__tests__/logic/isTestnet.unit.test.d.ts.map +1 -0
  68. package/lib/__tests__/logic/isTestnet.unit.test.js +12 -0
  69. package/lib/__tests__/logic/isTestnet.unit.test.js.map +1 -0
  70. package/lib/__tests__/logic/processRecipients.unit.test.d.ts +2 -0
  71. package/lib/__tests__/logic/processRecipients.unit.test.d.ts.map +1 -0
  72. package/lib/__tests__/logic/processRecipients.unit.test.js +79 -0
  73. package/lib/__tests__/logic/processRecipients.unit.test.js.map +1 -0
  74. package/lib/__tests__/network/client.test.d.ts +2 -0
  75. package/lib/__tests__/network/client.test.d.ts.map +1 -0
  76. package/lib/__tests__/network/client.test.js +992 -0
  77. package/lib/__tests__/network/client.test.js.map +1 -0
  78. package/lib/api/index.d.ts +4 -30
  79. package/lib/api/index.d.ts.map +1 -1
  80. package/lib/api/index.js +19 -170
  81. package/lib/api/index.js.map +1 -1
  82. package/lib/bridge/bridge.fixture.d.ts +2 -0
  83. package/lib/bridge/bridge.fixture.d.ts.map +1 -1
  84. package/lib/bridge/bridge.fixture.js +85 -13
  85. package/lib/bridge/bridge.fixture.js.map +1 -1
  86. package/lib/bridge/broadcast.d.ts +3 -2
  87. package/lib/bridge/broadcast.d.ts.map +1 -1
  88. package/lib/bridge/broadcast.js +4 -3
  89. package/lib/bridge/broadcast.js.map +1 -1
  90. package/lib/bridge/estimateMaxSpendable.d.ts.map +1 -1
  91. package/lib/bridge/estimateMaxSpendable.js +6 -5
  92. package/lib/bridge/estimateMaxSpendable.js.map +1 -1
  93. package/lib/bridge/getFeesForTransaction.d.ts +1 -1
  94. package/lib/bridge/getFeesForTransaction.d.ts.map +1 -1
  95. package/lib/bridge/getFeesForTransaction.js +20 -14
  96. package/lib/bridge/getFeesForTransaction.js.map +1 -1
  97. package/lib/bridge/getTransactionStatus.d.ts.map +1 -1
  98. package/lib/bridge/getTransactionStatus.js +28 -14
  99. package/lib/bridge/getTransactionStatus.js.map +1 -1
  100. package/lib/bridge/index.d.ts +1 -1
  101. package/lib/bridge/index.d.ts.map +1 -1
  102. package/lib/bridge/index.js +1 -1
  103. package/lib/bridge/index.js.map +1 -1
  104. package/lib/bridge/logic.d.ts +5 -19
  105. package/lib/bridge/logic.d.ts.map +1 -1
  106. package/lib/bridge/logic.js +50 -147
  107. package/lib/bridge/logic.js.map +1 -1
  108. package/lib/bridge/prepareTransaction.d.ts.map +1 -1
  109. package/lib/bridge/prepareTransaction.js +5 -4
  110. package/lib/bridge/prepareTransaction.js.map +1 -1
  111. package/lib/bridge/signOperation.d.ts.map +1 -1
  112. package/lib/bridge/signOperation.js +21 -7
  113. package/lib/bridge/signOperation.js.map +1 -1
  114. package/lib/bridge/synchronisation.d.ts +15 -0
  115. package/lib/bridge/synchronisation.d.ts.map +1 -1
  116. package/lib/bridge/synchronisation.js +129 -6
  117. package/lib/bridge/synchronisation.js.map +1 -1
  118. package/lib/config.d.ts +13 -0
  119. package/lib/config.d.ts.map +1 -0
  120. package/lib/config.js +9 -0
  121. package/lib/config.js.map +1 -0
  122. package/lib/constants.d.ts +10 -2
  123. package/lib/constants.d.ts.map +1 -1
  124. package/lib/constants.js +13 -2
  125. package/lib/constants.js.map +1 -1
  126. package/lib/{bridge → logic}/buildTransaction.d.ts +1 -1
  127. package/lib/logic/buildTransaction.d.ts.map +1 -0
  128. package/lib/logic/buildTransaction.js +45 -0
  129. package/lib/logic/buildTransaction.js.map +1 -0
  130. package/lib/logic/calculateAmount.d.ts +3 -0
  131. package/lib/logic/calculateAmount.d.ts.map +1 -0
  132. package/lib/logic/calculateAmount.js +13 -0
  133. package/lib/logic/calculateAmount.js.map +1 -0
  134. package/lib/logic/combine.d.ts +4 -0
  135. package/lib/logic/combine.d.ts.map +1 -0
  136. package/lib/logic/combine.js +34 -0
  137. package/lib/logic/combine.js.map +1 -0
  138. package/lib/logic/craftTransaction.d.ts +5 -0
  139. package/lib/logic/craftTransaction.d.ts.map +1 -0
  140. package/lib/logic/craftTransaction.js +23 -0
  141. package/lib/logic/craftTransaction.js.map +1 -0
  142. package/lib/logic/createTransaction.d.ts.map +1 -0
  143. package/lib/{bridge → logic}/createTransaction.js +3 -3
  144. package/lib/logic/createTransaction.js.map +1 -0
  145. package/lib/logic/getBalance.d.ts +5 -0
  146. package/lib/logic/getBalance.d.ts.map +1 -0
  147. package/lib/logic/getBalance.js +12 -0
  148. package/lib/logic/getBalance.js.map +1 -0
  149. package/lib/logic/getCoinAndAmounts.d.ts +13 -0
  150. package/lib/logic/getCoinAndAmounts.d.ts.map +1 -0
  151. package/lib/logic/getCoinAndAmounts.js +112 -0
  152. package/lib/logic/getCoinAndAmounts.js.map +1 -0
  153. package/lib/logic/getFunctionAddress.d.ts +3 -0
  154. package/lib/logic/getFunctionAddress.d.ts.map +1 -0
  155. package/lib/logic/getFunctionAddress.js +12 -0
  156. package/lib/logic/getFunctionAddress.js.map +1 -0
  157. package/lib/logic/getResourceAddress.d.ts +4 -0
  158. package/lib/logic/getResourceAddress.d.ts.map +1 -0
  159. package/lib/logic/getResourceAddress.js +17 -0
  160. package/lib/logic/getResourceAddress.js.map +1 -0
  161. package/lib/logic/isTestnet.d.ts +2 -0
  162. package/lib/logic/isTestnet.d.ts.map +1 -0
  163. package/lib/logic/isTestnet.js +9 -0
  164. package/lib/logic/isTestnet.js.map +1 -0
  165. package/lib/logic/isWriteSetChangeWriteResource.d.ts +3 -0
  166. package/lib/logic/isWriteSetChangeWriteResource.d.ts.map +1 -0
  167. package/lib/logic/isWriteSetChangeWriteResource.js +8 -0
  168. package/lib/logic/isWriteSetChangeWriteResource.js.map +1 -0
  169. package/lib/logic/normalizeTransactionOptions.d.ts +3 -0
  170. package/lib/logic/normalizeTransactionOptions.d.ts.map +1 -0
  171. package/lib/logic/normalizeTransactionOptions.js +21 -0
  172. package/lib/logic/normalizeTransactionOptions.js.map +1 -0
  173. package/lib/logic/processRecipients.d.ts +6 -0
  174. package/lib/logic/processRecipients.d.ts.map +1 -0
  175. package/lib/logic/processRecipients.js +57 -0
  176. package/lib/logic/processRecipients.js.map +1 -0
  177. package/lib/logic/transactionsToOperations.d.ts +7 -0
  178. package/lib/logic/transactionsToOperations.d.ts.map +1 -0
  179. package/lib/logic/transactionsToOperations.js +85 -0
  180. package/lib/logic/transactionsToOperations.js.map +1 -0
  181. package/lib/network/client.d.ts +38 -0
  182. package/lib/network/client.d.ts.map +1 -0
  183. package/lib/network/client.js +266 -0
  184. package/lib/network/client.js.map +1 -0
  185. package/lib/network/graphql/queries.d.ts.map +1 -0
  186. package/lib/{api → network}/graphql/queries.js +6 -6
  187. package/lib/network/graphql/queries.js.map +1 -0
  188. package/lib/{api → network}/graphql/types.d.ts +9 -9
  189. package/lib/network/graphql/types.d.ts.map +1 -0
  190. package/lib/{api → network}/graphql/types.js.map +1 -1
  191. package/lib/network/index.d.ts +2 -1
  192. package/lib/network/index.d.ts.map +1 -1
  193. package/lib/network/index.js +19 -7
  194. package/lib/network/index.js.map +1 -1
  195. package/lib/test/bot-specs.d.ts.map +1 -1
  196. package/lib/test/bot-specs.js +40 -1
  197. package/lib/test/bot-specs.js.map +1 -1
  198. package/lib/test/bridgeDatasetTest.d.ts.map +1 -1
  199. package/lib/test/bridgeDatasetTest.js +44 -62
  200. package/lib/test/bridgeDatasetTest.js.map +1 -1
  201. package/lib/test/speculos-deviceActions.d.ts +1 -0
  202. package/lib/test/speculos-deviceActions.d.ts.map +1 -1
  203. package/lib/test/speculos-deviceActions.js +37 -5
  204. package/lib/test/speculos-deviceActions.js.map +1 -1
  205. package/lib/types/assets.d.ts +12 -0
  206. package/lib/types/assets.d.ts.map +1 -0
  207. package/lib/types/assets.js +3 -0
  208. package/lib/types/assets.js.map +1 -0
  209. package/lib/types/index.d.ts +22 -7
  210. package/lib/types/index.d.ts.map +1 -1
  211. package/lib-es/__tests__/api/craftTransaction.unit.test.d.ts +2 -0
  212. package/lib-es/__tests__/api/craftTransaction.unit.test.d.ts.map +1 -0
  213. package/lib-es/__tests__/api/craftTransaction.unit.test.js +48 -0
  214. package/lib-es/__tests__/api/craftTransaction.unit.test.js.map +1 -0
  215. package/lib-es/__tests__/api/getBalance.unit.test.d.ts +2 -0
  216. package/lib-es/__tests__/api/getBalance.unit.test.d.ts.map +1 -0
  217. package/lib-es/__tests__/api/getBalance.unit.test.js +36 -0
  218. package/lib-es/__tests__/api/getBalance.unit.test.js.map +1 -0
  219. package/lib-es/__tests__/api/index.integ.test.d.ts +2 -0
  220. package/lib-es/__tests__/api/index.integ.test.d.ts.map +1 -0
  221. package/lib-es/__tests__/api/index.integ.test.js +113 -0
  222. package/lib-es/__tests__/api/index.integ.test.js.map +1 -0
  223. package/lib-es/__tests__/api/index.test.js +52 -408
  224. package/lib-es/__tests__/api/index.test.js.map +1 -1
  225. package/lib-es/__tests__/bridge/broadcast.test.js +2 -2
  226. package/lib-es/__tests__/bridge/broadcast.test.js.map +1 -1
  227. package/lib-es/__tests__/bridge/getFeesForTransaction.test.js +112 -11
  228. package/lib-es/__tests__/bridge/getFeesForTransaction.test.js.map +1 -1
  229. package/lib-es/__tests__/bridge/getTransactionStatus.test.js +177 -39
  230. package/lib-es/__tests__/bridge/getTransactionStatus.test.js.map +1 -1
  231. package/lib-es/__tests__/bridge/logic.test.js +702 -478
  232. package/lib-es/__tests__/bridge/logic.test.js.map +1 -1
  233. package/lib-es/__tests__/bridge/prepareTransaction.test.js +2 -2
  234. package/lib-es/__tests__/bridge/prepareTransaction.test.js.map +1 -1
  235. package/lib-es/__tests__/bridge/signOperation.test.js +137 -14
  236. package/lib-es/__tests__/bridge/signOperation.test.js.map +1 -1
  237. package/lib-es/__tests__/bridge/synchronisation.test.js +1213 -69
  238. package/lib-es/__tests__/bridge/synchronisation.test.js.map +1 -1
  239. package/lib-es/__tests__/index.test.js +1 -1
  240. package/lib-es/__tests__/index.test.js.map +1 -1
  241. package/lib-es/__tests__/logic/buildTransaction.test.d.ts.map +1 -0
  242. package/lib-es/__tests__/logic/buildTransaction.test.js +107 -0
  243. package/lib-es/__tests__/logic/buildTransaction.test.js.map +1 -0
  244. package/lib-es/__tests__/logic/calculateAmount.unit.test.d.ts +2 -0
  245. package/lib-es/__tests__/logic/calculateAmount.unit.test.d.ts.map +1 -0
  246. package/lib-es/__tests__/logic/calculateAmount.unit.test.js +40 -0
  247. package/lib-es/__tests__/logic/calculateAmount.unit.test.js.map +1 -0
  248. package/lib-es/__tests__/logic/combine.unit.test.d.ts +2 -0
  249. package/lib-es/__tests__/logic/combine.unit.test.d.ts.map +1 -0
  250. package/lib-es/__tests__/logic/combine.unit.test.js +45 -0
  251. package/lib-es/__tests__/logic/combine.unit.test.js.map +1 -0
  252. package/lib-es/__tests__/logic/compareAddress.unit.test.d.ts +2 -0
  253. package/lib-es/__tests__/logic/compareAddress.unit.test.d.ts.map +1 -0
  254. package/lib-es/__tests__/logic/compareAddress.unit.test.js +24 -0
  255. package/lib-es/__tests__/logic/compareAddress.unit.test.js.map +1 -0
  256. package/lib-es/__tests__/logic/createTransaction.test.d.ts.map +1 -0
  257. package/lib-es/__tests__/{bridge → logic}/createTransaction.test.js +2 -2
  258. package/lib-es/__tests__/logic/createTransaction.test.js.map +1 -0
  259. package/lib-es/__tests__/logic/getCoinAndAmounts.unit.test.d.ts +2 -0
  260. package/lib-es/__tests__/logic/getCoinAndAmounts.unit.test.d.ts.map +1 -0
  261. package/lib-es/__tests__/logic/getCoinAndAmounts.unit.test.js +181 -0
  262. package/lib-es/__tests__/logic/getCoinAndAmounts.unit.test.js.map +1 -0
  263. package/lib-es/__tests__/logic/getFunctionAddress.unit.test.d.ts +2 -0
  264. package/lib-es/__tests__/logic/getFunctionAddress.unit.test.d.ts.map +1 -0
  265. package/lib-es/__tests__/logic/getFunctionAddress.unit.test.js +27 -0
  266. package/lib-es/__tests__/logic/getFunctionAddress.unit.test.js.map +1 -0
  267. package/lib-es/__tests__/logic/getResourceAddress.unit.test.d.ts +2 -0
  268. package/lib-es/__tests__/logic/getResourceAddress.unit.test.d.ts.map +1 -0
  269. package/lib-es/__tests__/logic/getResourceAddress.unit.test.js +216 -0
  270. package/lib-es/__tests__/logic/getResourceAddress.unit.test.js.map +1 -0
  271. package/lib-es/__tests__/logic/isTestnet.unit.test.d.ts +2 -0
  272. package/lib-es/__tests__/logic/isTestnet.unit.test.d.ts.map +1 -0
  273. package/lib-es/__tests__/logic/isTestnet.unit.test.js +10 -0
  274. package/lib-es/__tests__/logic/isTestnet.unit.test.js.map +1 -0
  275. package/lib-es/__tests__/logic/processRecipients.unit.test.d.ts +2 -0
  276. package/lib-es/__tests__/logic/processRecipients.unit.test.d.ts.map +1 -0
  277. package/lib-es/__tests__/logic/processRecipients.unit.test.js +74 -0
  278. package/lib-es/__tests__/logic/processRecipients.unit.test.js.map +1 -0
  279. package/lib-es/__tests__/network/client.test.d.ts +2 -0
  280. package/lib-es/__tests__/network/client.test.d.ts.map +1 -0
  281. package/lib-es/__tests__/network/client.test.js +987 -0
  282. package/lib-es/__tests__/network/client.test.js.map +1 -0
  283. package/lib-es/api/index.d.ts +4 -30
  284. package/lib-es/api/index.d.ts.map +1 -1
  285. package/lib-es/api/index.js +17 -168
  286. package/lib-es/api/index.js.map +1 -1
  287. package/lib-es/bridge/bridge.fixture.d.ts +2 -0
  288. package/lib-es/bridge/bridge.fixture.d.ts.map +1 -1
  289. package/lib-es/bridge/bridge.fixture.js +82 -12
  290. package/lib-es/bridge/bridge.fixture.js.map +1 -1
  291. package/lib-es/bridge/broadcast.d.ts +3 -2
  292. package/lib-es/bridge/broadcast.d.ts.map +1 -1
  293. package/lib-es/bridge/broadcast.js +4 -3
  294. package/lib-es/bridge/broadcast.js.map +1 -1
  295. package/lib-es/bridge/estimateMaxSpendable.d.ts.map +1 -1
  296. package/lib-es/bridge/estimateMaxSpendable.js +4 -3
  297. package/lib-es/bridge/estimateMaxSpendable.js.map +1 -1
  298. package/lib-es/bridge/getFeesForTransaction.d.ts +1 -1
  299. package/lib-es/bridge/getFeesForTransaction.d.ts.map +1 -1
  300. package/lib-es/bridge/getFeesForTransaction.js +15 -9
  301. package/lib-es/bridge/getFeesForTransaction.js.map +1 -1
  302. package/lib-es/bridge/getTransactionStatus.d.ts.map +1 -1
  303. package/lib-es/bridge/getTransactionStatus.js +28 -14
  304. package/lib-es/bridge/getTransactionStatus.js.map +1 -1
  305. package/lib-es/bridge/index.d.ts +1 -1
  306. package/lib-es/bridge/index.d.ts.map +1 -1
  307. package/lib-es/bridge/index.js +1 -1
  308. package/lib-es/bridge/index.js.map +1 -1
  309. package/lib-es/bridge/logic.d.ts +5 -19
  310. package/lib-es/bridge/logic.d.ts.map +1 -1
  311. package/lib-es/bridge/logic.js +44 -134
  312. package/lib-es/bridge/logic.js.map +1 -1
  313. package/lib-es/bridge/prepareTransaction.d.ts.map +1 -1
  314. package/lib-es/bridge/prepareTransaction.js +5 -4
  315. package/lib-es/bridge/prepareTransaction.js.map +1 -1
  316. package/lib-es/bridge/signOperation.d.ts.map +1 -1
  317. package/lib-es/bridge/signOperation.js +19 -5
  318. package/lib-es/bridge/signOperation.js.map +1 -1
  319. package/lib-es/bridge/synchronisation.d.ts +15 -0
  320. package/lib-es/bridge/synchronisation.d.ts.map +1 -1
  321. package/lib-es/bridge/synchronisation.js +124 -4
  322. package/lib-es/bridge/synchronisation.js.map +1 -1
  323. package/lib-es/config.d.ts +13 -0
  324. package/lib-es/config.d.ts.map +1 -0
  325. package/lib-es/config.js +4 -0
  326. package/lib-es/config.js.map +1 -0
  327. package/lib-es/constants.d.ts +10 -2
  328. package/lib-es/constants.d.ts.map +1 -1
  329. package/lib-es/constants.js +9 -1
  330. package/lib-es/constants.js.map +1 -1
  331. package/lib-es/{bridge → logic}/buildTransaction.d.ts +1 -1
  332. package/lib-es/logic/buildTransaction.d.ts.map +1 -0
  333. package/lib-es/logic/buildTransaction.js +43 -0
  334. package/lib-es/logic/buildTransaction.js.map +1 -0
  335. package/lib-es/logic/calculateAmount.d.ts +3 -0
  336. package/lib-es/logic/calculateAmount.d.ts.map +1 -0
  337. package/lib-es/logic/calculateAmount.js +9 -0
  338. package/lib-es/logic/calculateAmount.js.map +1 -0
  339. package/lib-es/logic/combine.d.ts +4 -0
  340. package/lib-es/logic/combine.d.ts.map +1 -0
  341. package/lib-es/logic/combine.js +29 -0
  342. package/lib-es/logic/combine.js.map +1 -0
  343. package/lib-es/logic/craftTransaction.d.ts +5 -0
  344. package/lib-es/logic/craftTransaction.d.ts.map +1 -0
  345. package/lib-es/logic/craftTransaction.js +16 -0
  346. package/lib-es/logic/craftTransaction.js.map +1 -0
  347. package/lib-es/logic/createTransaction.d.ts.map +1 -0
  348. package/lib-es/{bridge → logic}/createTransaction.js +1 -1
  349. package/lib-es/logic/createTransaction.js.map +1 -0
  350. package/lib-es/logic/getBalance.d.ts +5 -0
  351. package/lib-es/logic/getBalance.d.ts.map +1 -0
  352. package/lib-es/logic/getBalance.js +8 -0
  353. package/lib-es/logic/getBalance.js.map +1 -0
  354. package/lib-es/logic/getCoinAndAmounts.d.ts +13 -0
  355. package/lib-es/logic/getCoinAndAmounts.d.ts.map +1 -0
  356. package/lib-es/logic/getCoinAndAmounts.js +101 -0
  357. package/lib-es/logic/getCoinAndAmounts.js.map +1 -0
  358. package/lib-es/logic/getFunctionAddress.d.ts +3 -0
  359. package/lib-es/logic/getFunctionAddress.d.ts.map +1 -0
  360. package/lib-es/logic/getFunctionAddress.js +8 -0
  361. package/lib-es/logic/getFunctionAddress.js.map +1 -0
  362. package/lib-es/logic/getResourceAddress.d.ts +4 -0
  363. package/lib-es/logic/getResourceAddress.d.ts.map +1 -0
  364. package/lib-es/logic/getResourceAddress.js +13 -0
  365. package/lib-es/logic/getResourceAddress.js.map +1 -0
  366. package/lib-es/logic/isTestnet.d.ts +2 -0
  367. package/lib-es/logic/isTestnet.d.ts.map +1 -0
  368. package/lib-es/logic/isTestnet.js +5 -0
  369. package/lib-es/logic/isTestnet.js.map +1 -0
  370. package/lib-es/logic/isWriteSetChangeWriteResource.d.ts +3 -0
  371. package/lib-es/logic/isWriteSetChangeWriteResource.d.ts.map +1 -0
  372. package/lib-es/logic/isWriteSetChangeWriteResource.js +4 -0
  373. package/lib-es/logic/isWriteSetChangeWriteResource.js.map +1 -0
  374. package/lib-es/logic/normalizeTransactionOptions.d.ts +3 -0
  375. package/lib-es/logic/normalizeTransactionOptions.d.ts.map +1 -0
  376. package/lib-es/logic/normalizeTransactionOptions.js +17 -0
  377. package/lib-es/logic/normalizeTransactionOptions.js.map +1 -0
  378. package/lib-es/logic/processRecipients.d.ts +6 -0
  379. package/lib-es/logic/processRecipients.d.ts.map +1 -0
  380. package/lib-es/logic/processRecipients.js +53 -0
  381. package/lib-es/logic/processRecipients.js.map +1 -0
  382. package/lib-es/logic/transactionsToOperations.d.ts +7 -0
  383. package/lib-es/logic/transactionsToOperations.d.ts.map +1 -0
  384. package/lib-es/logic/transactionsToOperations.js +77 -0
  385. package/lib-es/logic/transactionsToOperations.js.map +1 -0
  386. package/lib-es/network/client.d.ts +38 -0
  387. package/lib-es/network/client.d.ts.map +1 -0
  388. package/lib-es/network/client.js +259 -0
  389. package/lib-es/network/client.js.map +1 -0
  390. package/lib-es/network/graphql/queries.d.ts.map +1 -0
  391. package/lib-es/{api → network}/graphql/queries.js +6 -6
  392. package/lib-es/network/graphql/queries.js.map +1 -0
  393. package/lib-es/{api → network}/graphql/types.d.ts +9 -9
  394. package/lib-es/network/graphql/types.d.ts.map +1 -0
  395. package/lib-es/{api → network}/graphql/types.js.map +1 -1
  396. package/lib-es/network/index.d.ts +2 -1
  397. package/lib-es/network/index.d.ts.map +1 -1
  398. package/lib-es/network/index.js +6 -8
  399. package/lib-es/network/index.js.map +1 -1
  400. package/lib-es/test/bot-specs.d.ts.map +1 -1
  401. package/lib-es/test/bot-specs.js +41 -2
  402. package/lib-es/test/bot-specs.js.map +1 -1
  403. package/lib-es/test/bridgeDatasetTest.d.ts.map +1 -1
  404. package/lib-es/test/bridgeDatasetTest.js +44 -59
  405. package/lib-es/test/bridgeDatasetTest.js.map +1 -1
  406. package/lib-es/test/speculos-deviceActions.d.ts +1 -0
  407. package/lib-es/test/speculos-deviceActions.d.ts.map +1 -1
  408. package/lib-es/test/speculos-deviceActions.js +36 -4
  409. package/lib-es/test/speculos-deviceActions.js.map +1 -1
  410. package/lib-es/types/assets.d.ts +12 -0
  411. package/lib-es/types/assets.d.ts.map +1 -0
  412. package/lib-es/types/assets.js +2 -0
  413. package/lib-es/types/assets.js.map +1 -0
  414. package/lib-es/types/index.d.ts +22 -7
  415. package/lib-es/types/index.d.ts.map +1 -1
  416. package/package.json +9 -7
  417. package/src/__tests__/api/craftTransaction.unit.test.ts +70 -0
  418. package/src/__tests__/api/getBalance.unit.test.ts +44 -0
  419. package/src/__tests__/api/index.integ.test.ts +139 -0
  420. package/src/__tests__/api/index.test.ts +60 -477
  421. package/src/__tests__/bridge/broadcast.test.ts +2 -2
  422. package/src/__tests__/bridge/getFeesForTransaction.test.ts +146 -11
  423. package/src/__tests__/bridge/getTransactionStatus.test.ts +217 -38
  424. package/src/__tests__/bridge/logic.test.ts +727 -568
  425. package/src/__tests__/bridge/prepareTransaction.test.ts +2 -2
  426. package/src/__tests__/bridge/signOperation.test.ts +153 -15
  427. package/src/__tests__/bridge/synchronisation.test.ts +1265 -71
  428. package/src/__tests__/index.test.ts +1 -1
  429. package/src/__tests__/logic/buildTransaction.test.ts +148 -0
  430. package/src/__tests__/logic/calculateAmount.unit.test.ts +51 -0
  431. package/src/__tests__/logic/combine.unit.test.ts +65 -0
  432. package/src/__tests__/logic/compareAddress.unit.test.ts +27 -0
  433. package/src/__tests__/{bridge → logic}/createTransaction.test.ts +2 -2
  434. package/src/__tests__/logic/getCoinAndAmounts.unit.test.ts +195 -0
  435. package/src/__tests__/logic/getFunctionAddress.unit.test.ts +33 -0
  436. package/src/__tests__/logic/getResourceAddress.unit.test.ts +241 -0
  437. package/src/__tests__/logic/isTestnet.unit.test.ts +11 -0
  438. package/src/__tests__/logic/processRecipients.unit.test.ts +87 -0
  439. package/src/__tests__/network/client.test.ts +1107 -0
  440. package/src/api/index.ts +29 -224
  441. package/src/bridge/bridge.fixture.ts +91 -12
  442. package/src/bridge/broadcast.ts +7 -7
  443. package/src/bridge/estimateMaxSpendable.ts +4 -3
  444. package/src/bridge/getFeesForTransaction.ts +17 -11
  445. package/src/bridge/getTransactionStatus.ts +35 -13
  446. package/src/bridge/index.ts +2 -2
  447. package/src/bridge/logic.ts +58 -194
  448. package/src/bridge/prepareTransaction.ts +7 -4
  449. package/src/bridge/signOperation.ts +21 -5
  450. package/src/bridge/synchronisation.ts +171 -4
  451. package/src/config.ts +19 -0
  452. package/src/constants.ts +18 -2
  453. package/src/logic/buildTransaction.ts +62 -0
  454. package/src/logic/calculateAmount.ts +15 -0
  455. package/src/logic/combine.ts +51 -0
  456. package/src/logic/craftTransaction.ts +26 -0
  457. package/src/{bridge → logic}/createTransaction.ts +1 -1
  458. package/src/logic/getBalance.ts +15 -0
  459. package/src/logic/getCoinAndAmounts.ts +141 -0
  460. package/src/logic/getFunctionAddress.ts +9 -0
  461. package/src/logic/getResourceAddress.ts +24 -0
  462. package/src/logic/isTestnet.ts +5 -0
  463. package/src/logic/isWriteSetChangeWriteResource.ts +7 -0
  464. package/src/logic/normalizeTransactionOptions.ts +18 -0
  465. package/src/logic/processRecipients.ts +87 -0
  466. package/src/logic/transactionsToOperations.ts +105 -0
  467. package/src/network/client.ts +351 -0
  468. package/src/{api → network}/graphql/queries.ts +6 -6
  469. package/src/{api → network}/graphql/types.ts +9 -9
  470. package/src/network/index.ts +6 -14
  471. package/src/test/bot-specs.ts +63 -3
  472. package/src/test/bridgeDatasetTest.ts +46 -59
  473. package/src/test/speculos-deviceActions.ts +40 -4
  474. package/src/types/assets.ts +15 -0
  475. package/src/types/index.ts +20 -1
  476. package/lib/__tests__/bridge/buildTransaction.test.d.ts.map +0 -1
  477. package/lib/__tests__/bridge/buildTransaction.test.js +0 -53
  478. package/lib/__tests__/bridge/buildTransaction.test.js.map +0 -1
  479. package/lib/__tests__/bridge/createTransaction.test.d.ts.map +0 -1
  480. package/lib/__tests__/bridge/createTransaction.test.js.map +0 -1
  481. package/lib/api/graphql/queries.d.ts.map +0 -1
  482. package/lib/api/graphql/queries.js.map +0 -1
  483. package/lib/api/graphql/types.d.ts.map +0 -1
  484. package/lib/bridge/buildTransaction.d.ts.map +0 -1
  485. package/lib/bridge/buildTransaction.js +0 -19
  486. package/lib/bridge/buildTransaction.js.map +0 -1
  487. package/lib/bridge/createTransaction.d.ts.map +0 -1
  488. package/lib/bridge/createTransaction.js.map +0 -1
  489. package/lib-es/__tests__/bridge/buildTransaction.test.d.ts.map +0 -1
  490. package/lib-es/__tests__/bridge/buildTransaction.test.js +0 -48
  491. package/lib-es/__tests__/bridge/buildTransaction.test.js.map +0 -1
  492. package/lib-es/__tests__/bridge/createTransaction.test.d.ts.map +0 -1
  493. package/lib-es/__tests__/bridge/createTransaction.test.js.map +0 -1
  494. package/lib-es/api/graphql/queries.d.ts.map +0 -1
  495. package/lib-es/api/graphql/queries.js.map +0 -1
  496. package/lib-es/api/graphql/types.d.ts.map +0 -1
  497. package/lib-es/bridge/buildTransaction.d.ts.map +0 -1
  498. package/lib-es/bridge/buildTransaction.js +0 -17
  499. package/lib-es/bridge/buildTransaction.js.map +0 -1
  500. package/lib-es/bridge/createTransaction.d.ts.map +0 -1
  501. package/lib-es/bridge/createTransaction.js.map +0 -1
  502. package/src/__tests__/bridge/buildTransaction.test.ts +0 -61
  503. package/src/bridge/buildTransaction.ts +0 -29
  504. /package/lib/__tests__/{bridge → logic}/buildTransaction.test.d.ts +0 -0
  505. /package/lib/__tests__/{bridge → logic}/createTransaction.test.d.ts +0 -0
  506. /package/lib/{bridge → logic}/createTransaction.d.ts +0 -0
  507. /package/lib/{api → network}/graphql/queries.d.ts +0 -0
  508. /package/lib/{api → network}/graphql/types.js +0 -0
  509. /package/lib-es/__tests__/{bridge → logic}/buildTransaction.test.d.ts +0 -0
  510. /package/lib-es/__tests__/{bridge → logic}/createTransaction.test.d.ts +0 -0
  511. /package/lib-es/{bridge → logic}/createTransaction.d.ts +0 -0
  512. /package/lib-es/{api → network}/graphql/queries.d.ts +0 -0
  513. /package/lib-es/{api → network}/graphql/types.js +0 -0
@@ -1,80 +1,62 @@
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";
1
+ import { EntryFunctionPayloadResponse } from "@aptos-labs/ts-sdk";
8
2
  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";
3
+ import { APTOS_COIN_CHANGE, DIRECTION } from "../../constants";
4
+ import { getMaxSendBalance, getBlankOperation, txsToOps } from "../../bridge/logic";
23
5
  import type { AptosTransaction, TransactionOptions } from "../../types";
6
+ import { createFixtureAccount, createFixtureTransaction } from "../../bridge/bridge.fixture";
7
+ import { findTokenByAddressInCurrency } from "@ledgerhq/cryptoassets";
8
+ import { decodeTokenAccountId, encodeTokenAccountId } from "@ledgerhq/coin-framework/account/index";
9
+ import { normalizeTransactionOptions } from "../../logic/normalizeTransactionOptions";
24
10
 
25
- jest.mock("@ledgerhq/cryptoassets", () => ({
26
- getCryptoCurrencyById: jest.fn(),
27
- }));
11
+ jest.mock("@ledgerhq/cryptoassets");
12
+ jest.mock("@ledgerhq/coin-framework/account/index");
28
13
 
29
14
  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
15
  describe("getMaxSendBalance", () => {
41
16
  it("should return the correct max send balance when amount is greater than total gas", () => {
42
17
  const amount = new BigNumber(1000000);
18
+ const account = createFixtureAccount({ balance: amount, spendableBalance: amount });
19
+ const transaction = createFixtureTransaction();
43
20
  const gas = new BigNumber(200);
44
21
  const gasPrice = new BigNumber(100);
45
- const result = getMaxSendBalance(amount, gas, gasPrice);
22
+ const result = getMaxSendBalance(gas, gasPrice, account, transaction);
46
23
  expect(result.isEqualTo(amount.minus(gas.multipliedBy(gasPrice)))).toBe(true);
47
24
  });
48
25
 
49
26
  it("should return zero when amount is less than total gas", () => {
50
- const amount = new BigNumber(1000);
27
+ const account = createFixtureAccount();
28
+ const transaction = createFixtureTransaction();
51
29
  const gas = new BigNumber(200);
52
30
  const gasPrice = new BigNumber(100);
53
- const result = getMaxSendBalance(amount, gas, gasPrice);
31
+ const result = getMaxSendBalance(gas, gasPrice, account, transaction);
54
32
  expect(result.isEqualTo(new BigNumber(0))).toBe(true);
55
33
  });
56
34
 
57
35
  it("should return zero when amount is equal to total gas", () => {
58
- const amount = new BigNumber(20000);
36
+ const account = createFixtureAccount();
37
+ const transaction = createFixtureTransaction();
59
38
  const gas = new BigNumber(200);
60
39
  const gasPrice = new BigNumber(100);
61
- const result = getMaxSendBalance(amount, gas, gasPrice);
40
+ const result = getMaxSendBalance(gas, gasPrice, account, transaction);
62
41
  expect(result.isEqualTo(new BigNumber(0))).toBe(true);
63
42
  });
64
43
 
65
44
  it("should handle zero amount", () => {
66
- const amount = new BigNumber(0);
45
+ const account = createFixtureAccount();
46
+ const transaction = createFixtureTransaction();
67
47
  const gas = new BigNumber(200);
68
48
  const gasPrice = new BigNumber(100);
69
- const result = getMaxSendBalance(amount, gas, gasPrice);
49
+ const result = getMaxSendBalance(gas, gasPrice, account, transaction);
70
50
  expect(result.isEqualTo(new BigNumber(0))).toBe(true);
71
51
  });
72
52
 
73
53
  it("should handle zero gas and gas price", () => {
74
54
  const amount = new BigNumber(1000000);
55
+ const account = createFixtureAccount({ balance: amount, spendableBalance: amount });
56
+ const transaction = createFixtureTransaction();
75
57
  const gas = new BigNumber(0);
76
58
  const gasPrice = new BigNumber(0);
77
- const result = getMaxSendBalance(amount, gas, gasPrice);
59
+ const result = getMaxSendBalance(gas, gasPrice, account, transaction);
78
60
  expect(result.isEqualTo(amount)).toBe(true);
79
61
  });
80
62
  });
@@ -114,7 +96,7 @@ describe("Aptos logic ", () => {
114
96
  version: "1",
115
97
  } as unknown as AptosTransaction;
116
98
 
117
- const id = "test-id";
99
+ const id = "test_id";
118
100
  const result = getBlankOperation(tx, id);
119
101
 
120
102
  expect(result).toEqual({
@@ -142,7 +124,7 @@ describe("Aptos logic ", () => {
142
124
  sequence_number: "1",
143
125
  } as unknown as AptosTransaction;
144
126
 
145
- const id = "test-id";
127
+ const id = "test_id";
146
128
  const result = getBlankOperation(tx, id);
147
129
 
148
130
  expect(result).toEqual({
@@ -166,490 +148,10 @@ describe("Aptos logic ", () => {
166
148
  });
167
149
 
168
150
  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
151
  describe("txsToOps", () => {
650
- it("should convert transactions to operations correctly", () => {
152
+ it("should convert Aptos transactions to operations correctly", () => {
651
153
  const address = "0x11";
652
- const id = "test-id";
154
+ const id = "test_id";
653
155
  const txs: AptosTransaction[] = [
654
156
  {
655
157
  hash: "0x123",
@@ -717,14 +219,14 @@ describe("Aptos sync logic ", () => {
717
219
  } as unknown as AptosTransaction,
718
220
  ];
719
221
 
720
- const result = txsToOps({ address }, id, txs);
222
+ const [result] = txsToOps({ address }, id, txs);
721
223
 
722
224
  expect(result).toHaveLength(1);
723
225
  expect(result[0]).toEqual({
724
226
  id: expect.any(String),
725
227
  hash: "0x123",
726
228
  type: DIRECTION.OUT,
727
- value: new BigNumber(20100),
229
+ value: new BigNumber(100),
728
230
  fee: new BigNumber(20000),
729
231
  blockHash: "0xabc",
730
232
  blockHeight: 1,
@@ -740,7 +242,7 @@ describe("Aptos sync logic ", () => {
740
242
 
741
243
  it("should skip transactions without functions in payload", () => {
742
244
  const address = "0x11";
743
- const id = "test-id";
245
+ const id = "test_id";
744
246
  const txs: AptosTransaction[] = [
745
247
  {
746
248
  hash: "0x123",
@@ -749,12 +251,6 @@ describe("Aptos sync logic ", () => {
749
251
  gas_unit_price: "100",
750
252
  success: true,
751
253
  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
254
  events: [],
759
255
  changes: [],
760
256
  block: { hash: "0xabc", height: 1 },
@@ -763,14 +259,14 @@ describe("Aptos sync logic ", () => {
763
259
  } as unknown as AptosTransaction,
764
260
  ];
765
261
 
766
- const result = txsToOps({ address }, id, txs);
262
+ const [result] = txsToOps({ address }, id, txs);
767
263
 
768
264
  expect(result).toHaveLength(0);
769
265
  });
770
266
 
771
267
  it("should skip transactions that result in no Aptos change", () => {
772
268
  const address = "0x11";
773
- const id = "test-id";
269
+ const id = "test_id";
774
270
  const txs: AptosTransaction[] = [
775
271
  {
776
272
  hash: "0x123",
@@ -792,85 +288,748 @@ describe("Aptos sync logic ", () => {
792
288
  } as unknown as AptosTransaction,
793
289
  ];
794
290
 
795
- const result = txsToOps({ address }, id, txs);
291
+ const [result] = txsToOps({ address }, id, txs);
796
292
 
797
293
  expect(result).toHaveLength(0);
798
294
  });
799
295
 
800
296
  it("should handle failed transactions", () => {
801
- const address = "0x11";
802
- const id = "test-id";
297
+ const address = "0xa0d8";
298
+ const id = "test_id";
803
299
  const txs: AptosTransaction[] = [
804
300
  {
805
- hash: "0x123",
806
- sender: "0x11",
301
+ hash: "0x0189",
302
+ sender: "0xa0d8",
807
303
  gas_used: "200",
808
304
  gas_unit_price: "100",
809
305
  success: false,
810
306
  payload: {
811
- type: "entry_function_payload",
812
307
  function: "0x1::coin::transfer",
813
- type_arguments: [],
814
- arguments: ["0x12", 100],
308
+ type_arguments: ["0xd111::staked_coin::StakedAptos"],
309
+ arguments: ["0x4e5e", "50000000"],
310
+ type: "entry_function_payload",
815
311
  } as EntryFunctionPayloadResponse,
816
312
  events: [
817
313
  {
818
- type: "0x1::coin::WithdrawEvent",
819
314
  guid: {
820
- account_address: "0x11",
821
- creation_number: "1",
315
+ creation_number: "0",
316
+ account_address: "0x0",
822
317
  },
318
+ sequence_number: "0",
319
+ type: "0x1::transaction_fee::FeeStatement",
823
320
  data: {
824
- amount: "100",
321
+ execution_gas_units: "5",
322
+ io_gas_units: "4",
323
+ storage_fee_octas: "0",
324
+ storage_fee_refund_octas: "0",
325
+ total_charge_gas_units: "8",
825
326
  },
826
327
  },
328
+ ],
329
+ changes: [
827
330
  {
828
- type: "0x1::coin::DepositEvent",
829
- guid: {
830
- account_address: "0x12",
831
- creation_number: "2",
832
- },
331
+ address: "0xa0d8",
332
+ state_key_hash: "0x1709",
833
333
  data: {
834
- amount: "100",
334
+ type: "0x1::coin::CoinStore<0x1::aptos_coin::AptosCoin>",
335
+ data: {
336
+ coin: {
337
+ value: "573163341",
338
+ },
339
+ deposit_events: {
340
+ counter: "45",
341
+ guid: {
342
+ id: {
343
+ addr: "0xa0d8",
344
+ creation_num: "2",
345
+ },
346
+ },
347
+ },
348
+ frozen: false,
349
+ withdraw_events: {
350
+ counter: "82",
351
+ guid: {
352
+ id: {
353
+ addr: "0xa0d8",
354
+ creation_num: "3",
355
+ },
356
+ },
357
+ },
358
+ },
835
359
  },
360
+ type: "write_resource",
836
361
  },
837
- ],
838
- changes: [
839
362
  {
840
- type: "write_resource",
363
+ address: "0xa0d8",
364
+ state_key_hash: "0x6f1e",
841
365
  data: {
842
- type: APTOS_COIN_CHANGE,
366
+ type: "0x1::account::Account",
843
367
  data: {
844
- withdraw_events: {
368
+ authentication_key: "0xa0d8",
369
+ coin_register_events: {
370
+ counter: "5",
845
371
  guid: {
846
372
  id: {
847
- addr: "0x11",
848
- creation_num: "1",
373
+ addr: "0xa0d8",
374
+ creation_num: "0",
849
375
  },
850
376
  },
851
377
  },
852
- deposit_events: {
378
+ guid_creation_num: "12",
379
+ key_rotation_events: {
380
+ counter: "0",
853
381
  guid: {
854
382
  id: {
855
- addr: "0x12",
856
- creation_num: "2",
383
+ addr: "0xa0d8",
384
+ creation_num: "1",
857
385
  },
858
386
  },
859
387
  },
388
+ rotation_capability_offer: {
389
+ for: {
390
+ vec: [],
391
+ },
392
+ },
393
+ sequence_number: "83",
394
+ signer_capability_offer: {
395
+ for: {
396
+ vec: [],
397
+ },
398
+ },
860
399
  },
861
400
  },
401
+ type: "write_resource",
402
+ },
403
+ {
404
+ state_key_hash: "0x6e4b",
405
+ handle: "0x1b85",
406
+ key: "0x0619",
407
+ value: "0x72c5e483c25c96010000000000000000",
408
+ data: null,
409
+ type: "write_table_item",
862
410
  },
863
411
  ],
864
- block: { hash: "0xabc", height: 1 },
412
+ block: {
413
+ hash: "0xc496",
414
+ height: 1,
415
+ },
865
416
  timestamp: "1000000",
866
417
  sequence_number: "1",
867
418
  } as unknown as AptosTransaction,
868
419
  ];
869
420
 
870
- const result = txsToOps({ address }, id, txs);
421
+ const [result] = txsToOps({ address }, id, txs);
871
422
 
872
423
  expect(result).toHaveLength(1);
873
- expect(result[0].hasFailed).toBe(true);
424
+ expect(result[0]).toEqual({
425
+ id: expect.any(String),
426
+ hash: "0x0189",
427
+ type: DIRECTION.OUT,
428
+ value: new BigNumber(20000),
429
+ fee: new BigNumber(20000),
430
+ blockHash: "0xc496",
431
+ blockHeight: 1,
432
+ senders: ["0xa0d8"],
433
+ recipients: ["0x4e5e"],
434
+ accountId: id,
435
+ date: new Date(1000),
436
+ extra: { version: undefined },
437
+ transactionSequenceNumber: 1,
438
+ hasFailed: true,
439
+ });
440
+ });
441
+
442
+ it("should convert Aptos token transactions to operations correctly", () => {
443
+ (findTokenByAddressInCurrency as jest.Mock).mockReturnValue({
444
+ type: "TokenCurrency",
445
+ id: "aptos/coin/dstapt::staked_coin::stakedaptos",
446
+ contractAddress: "0xd111::staked_coin::StakedAptos",
447
+ parentCurrency: {
448
+ type: "CryptoCurrency",
449
+ id: "aptos",
450
+ coinType: 637,
451
+ name: "Aptos",
452
+ managerAppName: "Aptos",
453
+ ticker: "APT",
454
+ scheme: "aptos",
455
+ color: "#231F20",
456
+ family: "aptos",
457
+ units: [
458
+ {
459
+ name: "APT",
460
+ code: "APT",
461
+ magnitude: 8,
462
+ },
463
+ ],
464
+ explorerViews: [
465
+ {
466
+ address: "https://explorer.aptoslabs.com/account/$address?network=mainnet",
467
+ tx: "https://explorer.aptoslabs.com/txn/$hash?network=mainnet",
468
+ },
469
+ ],
470
+ },
471
+ name: "dstAPT",
472
+ tokenType: "coin",
473
+ ticker: "dstAPT",
474
+ disableCountervalue: false,
475
+ delisted: false,
476
+ units: [
477
+ {
478
+ name: "dstAPT",
479
+ code: "dstAPT",
480
+ magnitude: 8,
481
+ },
482
+ ],
483
+ });
484
+
485
+ jest.mock("../../bridge/logic", () => ({
486
+ ...jest.requireActual("../../bridge/logic"),
487
+ getResourceAddress: jest.fn().mockReturnValue("0xd111::staked_coin::StakedAptos"),
488
+ }));
489
+
490
+ (decodeTokenAccountId as jest.Mock).mockReturnValue({
491
+ accountId: "token_account_id",
492
+ });
493
+
494
+ const address = "0xa0d";
495
+ const id = "test_id";
496
+ const txs: AptosTransaction[] = [
497
+ {
498
+ hash: "0x123",
499
+ sender: address,
500
+ gas_used: "200",
501
+ gas_unit_price: "100",
502
+ success: true,
503
+ payload: {
504
+ function: "0x1::aptos_account::transfer_coins",
505
+ type_arguments: ["0xd111::staked_coin::StakedAptos"],
506
+ arguments: ["0x4e5", "1500000"],
507
+ type: "entry_function_payload",
508
+ } as EntryFunctionPayloadResponse,
509
+ events: [
510
+ {
511
+ guid: {
512
+ creation_number: "11",
513
+ account_address: "0xa0d",
514
+ },
515
+ sequence_number: "12",
516
+ type: "0x1::coin::WithdrawEvent",
517
+ data: {
518
+ amount: "1500000",
519
+ },
520
+ },
521
+ {
522
+ guid: {
523
+ creation_number: "4",
524
+ account_address: "0x4e5",
525
+ },
526
+ sequence_number: "8",
527
+ type: "0x1::coin::DepositEvent",
528
+ data: {
529
+ amount: "1500000",
530
+ },
531
+ },
532
+ {
533
+ guid: {
534
+ creation_number: "0",
535
+ account_address: "0x0",
536
+ },
537
+ sequence_number: "0",
538
+ type: "0x1::transaction_fee::FeeStatement",
539
+ data: {
540
+ execution_gas_units: "6",
541
+ io_gas_units: "6",
542
+ storage_fee_octas: "0",
543
+ storage_fee_refund_octas: "0",
544
+ total_charge_gas_units: "12",
545
+ },
546
+ },
547
+ ],
548
+ changes: [
549
+ {
550
+ address: "0x4e5",
551
+ state_key_hash: "0x3c0",
552
+ data: {
553
+ type: "0x1::coin::CoinStore<0xd111::staked_coin::StakedAptos>",
554
+ data: {
555
+ coin: {
556
+ value: "4000000",
557
+ },
558
+ deposit_events: {
559
+ counter: "9",
560
+ guid: {
561
+ id: {
562
+ addr: "0x4e5",
563
+ creation_num: "4",
564
+ },
565
+ },
566
+ },
567
+ frozen: false,
568
+ withdraw_events: {
569
+ counter: "6",
570
+ guid: {
571
+ id: {
572
+ addr: "0x4e5",
573
+ creation_num: "5",
574
+ },
575
+ },
576
+ },
577
+ },
578
+ },
579
+ type: "write_resource",
580
+ },
581
+ {
582
+ address: "0xa0d",
583
+ state_key_hash: "0x1709",
584
+ data: {
585
+ type: "0x1::coin::CoinStore<0x1::aptos_coin::AptosCoin>",
586
+ data: {
587
+ coin: {
588
+ value: "68254118",
589
+ },
590
+ deposit_events: {
591
+ counter: "46",
592
+ guid: {
593
+ id: {
594
+ addr: "0xa0d",
595
+ creation_num: "2",
596
+ },
597
+ },
598
+ },
599
+ frozen: false,
600
+ withdraw_events: {
601
+ counter: "89",
602
+ guid: {
603
+ id: {
604
+ addr: "0xa0d",
605
+ creation_num: "3",
606
+ },
607
+ },
608
+ },
609
+ },
610
+ },
611
+ type: "write_resource",
612
+ },
613
+ {
614
+ address: "0xa0d",
615
+ state_key_hash: "0x5520",
616
+ data: {
617
+ type: "0x1::coin::CoinStore<0xd111::staked_coin::StakedAptos>",
618
+ data: {
619
+ coin: {
620
+ value: "1000000",
621
+ },
622
+ deposit_events: {
623
+ counter: "7",
624
+ guid: {
625
+ id: {
626
+ addr: "0xa0d",
627
+ creation_num: "10",
628
+ },
629
+ },
630
+ },
631
+ frozen: false,
632
+ withdraw_events: {
633
+ counter: "13",
634
+ guid: {
635
+ id: {
636
+ addr: "0xa0d",
637
+ creation_num: "11",
638
+ },
639
+ },
640
+ },
641
+ },
642
+ },
643
+ type: "write_resource",
644
+ },
645
+ {
646
+ address: "0xa0d",
647
+ state_key_hash: "0x6f1e",
648
+ data: {
649
+ type: "0x1::account::Account",
650
+ data: {
651
+ authentication_key: "0xa0d",
652
+ coin_register_events: {
653
+ counter: "5",
654
+ guid: {
655
+ id: {
656
+ addr: "0xa0d",
657
+ creation_num: "0",
658
+ },
659
+ },
660
+ },
661
+ guid_creation_num: "12",
662
+ key_rotation_events: {
663
+ counter: "0",
664
+ guid: {
665
+ id: {
666
+ addr: "0xa0d",
667
+ creation_num: "1",
668
+ },
669
+ },
670
+ },
671
+ rotation_capability_offer: {
672
+ for: {
673
+ vec: [],
674
+ },
675
+ },
676
+ sequence_number: "122",
677
+ signer_capability_offer: {
678
+ for: {
679
+ vec: [],
680
+ },
681
+ },
682
+ },
683
+ },
684
+ type: "write_resource",
685
+ },
686
+ {
687
+ state_key_hash: "0x6e4b",
688
+ handle: "0x1b85",
689
+ key: "0x0619",
690
+ value: "0x1ddaf8da3b1497010000000000000000",
691
+ data: null,
692
+ type: "write_table_item",
693
+ },
694
+ ],
695
+ block: { hash: "0xabc", height: 1 },
696
+ timestamp: "1000000",
697
+ sequence_number: "1",
698
+ } as unknown as AptosTransaction,
699
+ ];
700
+
701
+ const [ops, tokenOps] = txsToOps({ address }, id, txs);
702
+
703
+ expect(ops).toHaveLength(1);
704
+ expect(ops[0]).toEqual({
705
+ id: expect.any(String),
706
+ hash: "0x123",
707
+ type: "FEES",
708
+ value: new BigNumber(20000),
709
+ fee: new BigNumber(20000),
710
+ blockHash: "0xabc",
711
+ blockHeight: 1,
712
+ senders: ["0xa0d"],
713
+ recipients: ["0x4e5"],
714
+ accountId: "token_account_id",
715
+ date: new Date(1000),
716
+ extra: { version: undefined },
717
+ transactionSequenceNumber: 1,
718
+ hasFailed: false,
719
+ });
720
+
721
+ expect(tokenOps).toHaveLength(1);
722
+ expect(tokenOps[0]).toEqual({
723
+ id: expect.any(String),
724
+ hash: "0x123",
725
+ type: DIRECTION.OUT,
726
+ value: new BigNumber(1500000),
727
+ fee: new BigNumber(20000),
728
+ blockHash: "0xabc",
729
+ blockHeight: 1,
730
+ senders: ["0xa0d"],
731
+ recipients: ["0x4e5"],
732
+ date: new Date(1000),
733
+ extra: { version: undefined },
734
+ transactionSequenceNumber: 1,
735
+ hasFailed: false,
736
+ });
737
+ });
738
+
739
+ it("should convert Aptos token transactions to operations correctly", () => {
740
+ (findTokenByAddressInCurrency as jest.Mock).mockReturnValue({
741
+ type: "TokenCurrency",
742
+ id: "aptos/fungible_asset/cellana_0x2ebb2ccac5e027a87fa0e2e5f656a3a4238d6a48d93ec9b610d570fc0aa0df12",
743
+ contractAddress: "0x2ebb",
744
+ parentCurrency: {
745
+ type: "CryptoCurrency",
746
+ id: "aptos",
747
+ coinType: 637,
748
+ name: "Aptos",
749
+ managerAppName: "Aptos",
750
+ ticker: "APT",
751
+ scheme: "aptos",
752
+ color: "#231F20",
753
+ family: "aptos",
754
+ units: [
755
+ {
756
+ name: "APT",
757
+ code: "APT",
758
+ magnitude: 8,
759
+ },
760
+ ],
761
+ explorerViews: [
762
+ {
763
+ address: "https://explorer.aptoslabs.com/account/$address?network=mainnet",
764
+ tx: "https://explorer.aptoslabs.com/txn/$hash?network=mainnet",
765
+ },
766
+ ],
767
+ },
768
+ name: "CELLANA",
769
+ tokenType: "fungible_asset",
770
+ ticker: "CELL",
771
+ disableCountervalue: false,
772
+ delisted: false,
773
+ units: [
774
+ {
775
+ name: "CELLANA",
776
+ code: "CELL",
777
+ magnitude: 8,
778
+ },
779
+ ],
780
+ });
781
+
782
+ jest.mock("../../bridge/logic", () => ({
783
+ ...jest.requireActual("../../bridge/logic"),
784
+ getResourceAddress: jest.fn().mockReturnValue("0x2ebb"),
785
+ }));
786
+
787
+ (encodeTokenAccountId as jest.Mock).mockReturnValue("token_account_id");
788
+
789
+ const txs: AptosTransaction[] = [
790
+ {
791
+ hash: "0x10c9",
792
+ sender: "0xa0d8",
793
+ gas_used: "200",
794
+ gas_unit_price: "100",
795
+ success: true,
796
+ payload: {
797
+ function: "0x1::primary_fungible_store::transfer",
798
+ type_arguments: ["0x1::fungible_asset::Metadata"],
799
+ arguments: [
800
+ {
801
+ inner: "0x2ebb",
802
+ },
803
+ "0x6b8c",
804
+ "193",
805
+ ],
806
+ type: "entry_function_payload",
807
+ } as EntryFunctionPayloadResponse,
808
+ events: [
809
+ {
810
+ guid: {
811
+ creation_number: "0",
812
+ account_address: "0x0",
813
+ },
814
+ sequence_number: "0",
815
+ type: "0x1::fungible_asset::Withdraw",
816
+ data: {
817
+ amount: "193",
818
+ store: "0xd475",
819
+ },
820
+ },
821
+ {
822
+ guid: {
823
+ creation_number: "0",
824
+ account_address: "0x0",
825
+ },
826
+ sequence_number: "0",
827
+ type: "0x1::fungible_asset::Deposit",
828
+ data: {
829
+ amount: "193",
830
+ store: "0xaaa9",
831
+ },
832
+ },
833
+ {
834
+ guid: {
835
+ creation_number: "0",
836
+ account_address: "0x0",
837
+ },
838
+ sequence_number: "0",
839
+ type: "0x1::transaction_fee::FeeStatement",
840
+ data: {
841
+ execution_gas_units: "4",
842
+ io_gas_units: "6",
843
+ storage_fee_octas: "0",
844
+ storage_fee_refund_octas: "0",
845
+ total_charge_gas_units: "10",
846
+ },
847
+ },
848
+ ],
849
+ changes: [
850
+ {
851
+ address: "0xaaa9",
852
+ state_key_hash: "0x9a17",
853
+ data: {
854
+ type: "0x1::fungible_asset::FungibleStore",
855
+ data: {
856
+ balance: "10044959",
857
+ frozen: false,
858
+ metadata: {
859
+ inner: "0x2ebb",
860
+ },
861
+ },
862
+ },
863
+ type: "write_resource",
864
+ },
865
+ {
866
+ address: "0xaaa9",
867
+ state_key_hash: "0x9a17",
868
+ data: {
869
+ type: "0x1::object::ObjectCore",
870
+ data: {
871
+ allow_ungated_transfer: false,
872
+ guid_creation_num: "1125899906842625",
873
+ owner: "0x6b8c",
874
+ transfer_events: {
875
+ counter: "0",
876
+ guid: {
877
+ id: {
878
+ addr: "0xaaa9",
879
+ creation_num: "1125899906842624",
880
+ },
881
+ },
882
+ },
883
+ },
884
+ },
885
+ type: "write_resource",
886
+ },
887
+ {
888
+ address: "0xa0d8",
889
+ state_key_hash: "0x1709",
890
+ data: {
891
+ type: "0x1::coin::CoinStore<0x1::aptos_coin::AptosCoin>",
892
+ data: {
893
+ coin: {
894
+ value: "98423118",
895
+ },
896
+ deposit_events: {
897
+ counter: "46",
898
+ guid: {
899
+ id: {
900
+ addr: "0xa0d8",
901
+ creation_num: "2",
902
+ },
903
+ },
904
+ },
905
+ frozen: false,
906
+ withdraw_events: {
907
+ counter: "88",
908
+ guid: {
909
+ id: {
910
+ addr: "0xa0d8",
911
+ creation_num: "3",
912
+ },
913
+ },
914
+ },
915
+ },
916
+ },
917
+ type: "write_resource",
918
+ },
919
+ {
920
+ address: "0xa0d8",
921
+ state_key_hash: "0x6f1e",
922
+ data: {
923
+ type: "0x1::account::Account",
924
+ data: {
925
+ authentication_key: "0xa0d8",
926
+ coin_register_events: {
927
+ counter: "5",
928
+ guid: {
929
+ id: {
930
+ addr: "0xa0d8",
931
+ creation_num: "0",
932
+ },
933
+ },
934
+ },
935
+ guid_creation_num: "12",
936
+ key_rotation_events: {
937
+ counter: "0",
938
+ guid: {
939
+ id: {
940
+ addr: "0xa0d8",
941
+ creation_num: "1",
942
+ },
943
+ },
944
+ },
945
+ rotation_capability_offer: {
946
+ for: {
947
+ vec: [],
948
+ },
949
+ },
950
+ sequence_number: "108",
951
+ signer_capability_offer: {
952
+ for: {
953
+ vec: [],
954
+ },
955
+ },
956
+ },
957
+ },
958
+ type: "write_resource",
959
+ },
960
+ {
961
+ address: "0xd475",
962
+ state_key_hash: "0x7567",
963
+ data: {
964
+ type: "0x1::fungible_asset::FungibleStore",
965
+ data: {
966
+ balance: "14000",
967
+ frozen: false,
968
+ metadata: {
969
+ inner: "0x2ebb",
970
+ },
971
+ },
972
+ },
973
+ type: "write_resource",
974
+ },
975
+ {
976
+ address: "0xd475",
977
+ state_key_hash: "0x7567",
978
+ data: {
979
+ type: "0x1::object::ObjectCore",
980
+ data: {
981
+ allow_ungated_transfer: false,
982
+ guid_creation_num: "1125899906842625",
983
+ owner: "0xa0d8",
984
+ transfer_events: {
985
+ counter: "0",
986
+ guid: {
987
+ id: {
988
+ addr: "0xd475",
989
+ creation_num: "1125899906842624",
990
+ },
991
+ },
992
+ },
993
+ },
994
+ },
995
+ type: "write_resource",
996
+ },
997
+ {
998
+ state_key_hash: "0x6e4b",
999
+ handle: "0x1b85",
1000
+ key: "0x0619",
1001
+ value: "0xad4388dc7daf96010000000000000000",
1002
+ data: null,
1003
+ type: "write_table_item",
1004
+ },
1005
+ ],
1006
+ block: { hash: "0xabc", height: 1 },
1007
+ timestamp: "1000000",
1008
+ sequence_number: "1",
1009
+ } as unknown as AptosTransaction,
1010
+ ];
1011
+
1012
+ const [ops, tokenOps] = txsToOps({ address: "0x6b8c" }, "test_id", txs);
1013
+
1014
+ expect(ops).toHaveLength(0);
1015
+
1016
+ expect(tokenOps).toHaveLength(1);
1017
+ expect(tokenOps[0]).toEqual({
1018
+ id: expect.any(String),
1019
+ accountId: "token_account_id",
1020
+ hash: "0x10c9",
1021
+ type: DIRECTION.IN,
1022
+ value: new BigNumber(193),
1023
+ fee: new BigNumber(20000),
1024
+ blockHash: "0xabc",
1025
+ blockHeight: 1,
1026
+ senders: ["0xa0d8"],
1027
+ recipients: ["0x6b8c"],
1028
+ date: new Date(1000),
1029
+ extra: { version: undefined },
1030
+ transactionSequenceNumber: 1,
1031
+ hasFailed: false,
1032
+ });
874
1033
  });
875
1034
  });
876
1035
  });