@ledgerhq/coin-aptos 2.0.0 → 2.1.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 (390) hide show
  1. package/CHANGELOG.md +26 -0
  2. package/lib/__tests__/api/craftTransaction.unit.test.d.ts +2 -0
  3. package/lib/__tests__/api/craftTransaction.unit.test.d.ts.map +1 -0
  4. package/lib/__tests__/api/craftTransaction.unit.test.js +187 -0
  5. package/lib/__tests__/api/craftTransaction.unit.test.js.map +1 -0
  6. package/lib/__tests__/api/getBalance.unit.test.d.ts +2 -0
  7. package/lib/__tests__/api/getBalance.unit.test.d.ts.map +1 -0
  8. package/lib/__tests__/api/getBalance.unit.test.js +41 -0
  9. package/lib/__tests__/api/getBalance.unit.test.js.map +1 -0
  10. package/lib/__tests__/api/index.integ.test.js +276 -9
  11. package/lib/__tests__/api/index.integ.test.js.map +1 -1
  12. package/lib/__tests__/api/index.test.js +1 -1
  13. package/lib/__tests__/api/index.test.js.map +1 -1
  14. package/lib/__tests__/bridge/logic.test.js +8 -558
  15. package/lib/__tests__/bridge/logic.test.js.map +1 -1
  16. package/lib/__tests__/bridge/signOperation.test.js +7 -11
  17. package/lib/__tests__/bridge/signOperation.test.js.map +1 -1
  18. package/lib/__tests__/index.test.js +1 -1
  19. package/lib/__tests__/index.test.js.map +1 -1
  20. package/lib/__tests__/logic/buildTransaction.test.d.ts.map +1 -0
  21. package/lib/__tests__/{bridge → logic}/buildTransaction.test.js +14 -8
  22. package/lib/__tests__/logic/buildTransaction.test.js.map +1 -0
  23. package/lib/__tests__/logic/calculateAmount.unit.test.d.ts +2 -0
  24. package/lib/__tests__/logic/calculateAmount.unit.test.d.ts.map +1 -0
  25. package/lib/__tests__/logic/calculateAmount.unit.test.js +45 -0
  26. package/lib/__tests__/logic/calculateAmount.unit.test.js.map +1 -0
  27. package/lib/__tests__/logic/combine.unit.test.d.ts +2 -0
  28. package/lib/__tests__/logic/combine.unit.test.d.ts.map +1 -0
  29. package/lib/__tests__/logic/combine.unit.test.js +47 -0
  30. package/lib/__tests__/logic/combine.unit.test.js.map +1 -0
  31. package/lib/__tests__/logic/compareAddress.unit.test.d.ts +2 -0
  32. package/lib/__tests__/logic/compareAddress.unit.test.d.ts.map +1 -0
  33. package/lib/__tests__/logic/compareAddress.unit.test.js +26 -0
  34. package/lib/__tests__/logic/compareAddress.unit.test.js.map +1 -0
  35. package/lib/__tests__/logic/createTransaction.test.d.ts.map +1 -0
  36. package/lib/__tests__/{bridge → logic}/createTransaction.test.js +1 -1
  37. package/lib/__tests__/logic/createTransaction.test.js.map +1 -0
  38. package/lib/__tests__/logic/getCoinAndAmounts.unit.test.d.ts +2 -0
  39. package/lib/__tests__/logic/getCoinAndAmounts.unit.test.d.ts.map +1 -0
  40. package/lib/__tests__/logic/getCoinAndAmounts.unit.test.js +186 -0
  41. package/lib/__tests__/logic/getCoinAndAmounts.unit.test.js.map +1 -0
  42. package/lib/__tests__/logic/getFunctionAddress.unit.test.d.ts +2 -0
  43. package/lib/__tests__/logic/getFunctionAddress.unit.test.d.ts.map +1 -0
  44. package/lib/__tests__/logic/getFunctionAddress.unit.test.js +29 -0
  45. package/lib/__tests__/logic/getFunctionAddress.unit.test.js.map +1 -0
  46. package/lib/__tests__/logic/getResourceAddress.unit.test.d.ts +2 -0
  47. package/lib/__tests__/logic/getResourceAddress.unit.test.d.ts.map +1 -0
  48. package/lib/__tests__/logic/getResourceAddress.unit.test.js +218 -0
  49. package/lib/__tests__/logic/getResourceAddress.unit.test.js.map +1 -0
  50. package/lib/__tests__/logic/isTestnet.unit.test.d.ts +2 -0
  51. package/lib/__tests__/logic/isTestnet.unit.test.d.ts.map +1 -0
  52. package/lib/__tests__/logic/isTestnet.unit.test.js +12 -0
  53. package/lib/__tests__/logic/isTestnet.unit.test.js.map +1 -0
  54. package/lib/__tests__/logic/normalizeAddress.unit.test.d.ts +2 -0
  55. package/lib/__tests__/logic/normalizeAddress.unit.test.d.ts.map +1 -0
  56. package/lib/__tests__/logic/normalizeAddress.unit.test.js +12 -0
  57. package/lib/__tests__/logic/normalizeAddress.unit.test.js.map +1 -0
  58. package/lib/__tests__/logic/processRecipients.unit.test.d.ts +2 -0
  59. package/lib/__tests__/logic/processRecipients.unit.test.d.ts.map +1 -0
  60. package/lib/__tests__/logic/processRecipients.unit.test.js +79 -0
  61. package/lib/__tests__/logic/processRecipients.unit.test.js.map +1 -0
  62. package/lib/__tests__/network/client.test.js +613 -9
  63. package/lib/__tests__/network/client.test.js.map +1 -1
  64. package/lib/api/index.d.ts.map +1 -1
  65. package/lib/api/index.js +7 -12
  66. package/lib/api/index.js.map +1 -1
  67. package/lib/bridge/estimateMaxSpendable.d.ts.map +1 -1
  68. package/lib/bridge/estimateMaxSpendable.js.map +1 -1
  69. package/lib/bridge/getFeesForTransaction.d.ts.map +1 -1
  70. package/lib/bridge/getFeesForTransaction.js +1 -1
  71. package/lib/bridge/getFeesForTransaction.js.map +1 -1
  72. package/lib/bridge/index.js +1 -1
  73. package/lib/bridge/index.js.map +1 -1
  74. package/lib/bridge/logic.d.ts +1 -17
  75. package/lib/bridge/logic.d.ts.map +1 -1
  76. package/lib/bridge/logic.js +12 -204
  77. package/lib/bridge/logic.js.map +1 -1
  78. package/lib/bridge/prepareTransaction.js +1 -1
  79. package/lib/bridge/prepareTransaction.js.map +1 -1
  80. package/lib/bridge/signOperation.d.ts.map +1 -1
  81. package/lib/bridge/signOperation.js +1 -1
  82. package/lib/bridge/signOperation.js.map +1 -1
  83. package/lib/config.d.ts +1 -1
  84. package/lib/config.d.ts.map +1 -1
  85. package/lib/constants.d.ts +7 -4
  86. package/lib/constants.d.ts.map +1 -1
  87. package/lib/constants.js +8 -4
  88. package/lib/constants.js.map +1 -1
  89. package/lib/logic/buildTransaction.d.ts +9 -0
  90. package/lib/logic/buildTransaction.d.ts.map +1 -0
  91. package/lib/logic/buildTransaction.js +47 -0
  92. package/lib/logic/buildTransaction.js.map +1 -0
  93. package/lib/logic/calculateAmount.d.ts +3 -0
  94. package/lib/logic/calculateAmount.d.ts.map +1 -0
  95. package/lib/logic/calculateAmount.js +13 -0
  96. package/lib/logic/calculateAmount.js.map +1 -0
  97. package/lib/logic/combine.d.ts +4 -0
  98. package/lib/logic/combine.d.ts.map +1 -0
  99. package/lib/logic/combine.js +34 -0
  100. package/lib/logic/combine.js.map +1 -0
  101. package/lib/logic/craftTransaction.d.ts +5 -0
  102. package/lib/logic/craftTransaction.d.ts.map +1 -0
  103. package/lib/logic/craftTransaction.js +68 -0
  104. package/lib/logic/craftTransaction.js.map +1 -0
  105. package/lib/logic/createTransaction.d.ts.map +1 -0
  106. package/lib/logic/createTransaction.js.map +1 -0
  107. package/lib/logic/getBalance.d.ts +5 -0
  108. package/lib/logic/getBalance.d.ts.map +1 -0
  109. package/lib/logic/getBalance.js +12 -0
  110. package/lib/logic/getBalance.js.map +1 -0
  111. package/lib/logic/getCoinAndAmounts.d.ts +13 -0
  112. package/lib/logic/getCoinAndAmounts.d.ts.map +1 -0
  113. package/lib/logic/getCoinAndAmounts.js +112 -0
  114. package/lib/logic/getCoinAndAmounts.js.map +1 -0
  115. package/lib/logic/getFunctionAddress.d.ts +3 -0
  116. package/lib/logic/getFunctionAddress.d.ts.map +1 -0
  117. package/lib/logic/getFunctionAddress.js +12 -0
  118. package/lib/logic/getFunctionAddress.js.map +1 -0
  119. package/lib/logic/getResourceAddress.d.ts +4 -0
  120. package/lib/logic/getResourceAddress.d.ts.map +1 -0
  121. package/lib/logic/getResourceAddress.js +17 -0
  122. package/lib/logic/getResourceAddress.js.map +1 -0
  123. package/lib/logic/isTestnet.d.ts +2 -0
  124. package/lib/logic/isTestnet.d.ts.map +1 -0
  125. package/lib/logic/isTestnet.js +9 -0
  126. package/lib/logic/isTestnet.js.map +1 -0
  127. package/lib/logic/isWriteSetChangeWriteResource.d.ts +3 -0
  128. package/lib/logic/isWriteSetChangeWriteResource.d.ts.map +1 -0
  129. package/lib/logic/isWriteSetChangeWriteResource.js +8 -0
  130. package/lib/logic/isWriteSetChangeWriteResource.js.map +1 -0
  131. package/lib/logic/normalizeAddress.d.ts +2 -0
  132. package/lib/logic/normalizeAddress.d.ts.map +1 -0
  133. package/lib/logic/normalizeAddress.js +12 -0
  134. package/lib/logic/normalizeAddress.js.map +1 -0
  135. package/lib/logic/normalizeTransactionOptions.d.ts +3 -0
  136. package/lib/logic/normalizeTransactionOptions.d.ts.map +1 -0
  137. package/lib/logic/normalizeTransactionOptions.js +21 -0
  138. package/lib/logic/normalizeTransactionOptions.js.map +1 -0
  139. package/lib/logic/processRecipients.d.ts +6 -0
  140. package/lib/logic/processRecipients.d.ts.map +1 -0
  141. package/lib/logic/processRecipients.js +58 -0
  142. package/lib/logic/processRecipients.js.map +1 -0
  143. package/lib/logic/transactionsToOperations.d.ts +7 -0
  144. package/lib/logic/transactionsToOperations.d.ts.map +1 -0
  145. package/lib/logic/transactionsToOperations.js +89 -0
  146. package/lib/logic/transactionsToOperations.js.map +1 -0
  147. package/lib/network/client.d.ts +6 -4
  148. package/lib/network/client.d.ts.map +1 -1
  149. package/lib/network/client.js +50 -14
  150. package/lib/network/client.js.map +1 -1
  151. package/lib/network/index.d.ts.map +1 -1
  152. package/lib/network/index.js +4 -7
  153. package/lib/network/index.js.map +1 -1
  154. package/lib/types/assets.d.ts +5 -1
  155. package/lib/types/assets.d.ts.map +1 -1
  156. package/lib/types/index.d.ts +4 -0
  157. package/lib/types/index.d.ts.map +1 -1
  158. package/lib-es/__tests__/api/craftTransaction.unit.test.d.ts +2 -0
  159. package/lib-es/__tests__/api/craftTransaction.unit.test.d.ts.map +1 -0
  160. package/lib-es/__tests__/api/craftTransaction.unit.test.js +185 -0
  161. package/lib-es/__tests__/api/craftTransaction.unit.test.js.map +1 -0
  162. package/lib-es/__tests__/api/getBalance.unit.test.d.ts +2 -0
  163. package/lib-es/__tests__/api/getBalance.unit.test.d.ts.map +1 -0
  164. package/lib-es/__tests__/api/getBalance.unit.test.js +36 -0
  165. package/lib-es/__tests__/api/getBalance.unit.test.js.map +1 -0
  166. package/lib-es/__tests__/api/index.integ.test.js +277 -10
  167. package/lib-es/__tests__/api/index.integ.test.js.map +1 -1
  168. package/lib-es/__tests__/api/index.test.js +1 -1
  169. package/lib-es/__tests__/api/index.test.js.map +1 -1
  170. package/lib-es/__tests__/bridge/logic.test.js +8 -558
  171. package/lib-es/__tests__/bridge/logic.test.js.map +1 -1
  172. package/lib-es/__tests__/bridge/signOperation.test.js +7 -11
  173. package/lib-es/__tests__/bridge/signOperation.test.js.map +1 -1
  174. package/lib-es/__tests__/index.test.js +1 -1
  175. package/lib-es/__tests__/index.test.js.map +1 -1
  176. package/lib-es/__tests__/logic/buildTransaction.test.d.ts.map +1 -0
  177. package/lib-es/__tests__/{bridge → logic}/buildTransaction.test.js +11 -5
  178. package/lib-es/__tests__/logic/buildTransaction.test.js.map +1 -0
  179. package/lib-es/__tests__/logic/calculateAmount.unit.test.d.ts +2 -0
  180. package/lib-es/__tests__/logic/calculateAmount.unit.test.d.ts.map +1 -0
  181. package/lib-es/__tests__/logic/calculateAmount.unit.test.js +40 -0
  182. package/lib-es/__tests__/logic/calculateAmount.unit.test.js.map +1 -0
  183. package/lib-es/__tests__/logic/combine.unit.test.d.ts +2 -0
  184. package/lib-es/__tests__/logic/combine.unit.test.d.ts.map +1 -0
  185. package/lib-es/__tests__/logic/combine.unit.test.js +45 -0
  186. package/lib-es/__tests__/logic/combine.unit.test.js.map +1 -0
  187. package/lib-es/__tests__/logic/compareAddress.unit.test.d.ts +2 -0
  188. package/lib-es/__tests__/logic/compareAddress.unit.test.d.ts.map +1 -0
  189. package/lib-es/__tests__/logic/compareAddress.unit.test.js +24 -0
  190. package/lib-es/__tests__/logic/compareAddress.unit.test.js.map +1 -0
  191. package/lib-es/__tests__/logic/createTransaction.test.d.ts.map +1 -0
  192. package/lib-es/__tests__/{bridge → logic}/createTransaction.test.js +1 -1
  193. package/lib-es/__tests__/logic/createTransaction.test.js.map +1 -0
  194. package/lib-es/__tests__/logic/getCoinAndAmounts.unit.test.d.ts +2 -0
  195. package/lib-es/__tests__/logic/getCoinAndAmounts.unit.test.d.ts.map +1 -0
  196. package/lib-es/__tests__/logic/getCoinAndAmounts.unit.test.js +181 -0
  197. package/lib-es/__tests__/logic/getCoinAndAmounts.unit.test.js.map +1 -0
  198. package/lib-es/__tests__/logic/getFunctionAddress.unit.test.d.ts +2 -0
  199. package/lib-es/__tests__/logic/getFunctionAddress.unit.test.d.ts.map +1 -0
  200. package/lib-es/__tests__/logic/getFunctionAddress.unit.test.js +27 -0
  201. package/lib-es/__tests__/logic/getFunctionAddress.unit.test.js.map +1 -0
  202. package/lib-es/__tests__/logic/getResourceAddress.unit.test.d.ts +2 -0
  203. package/lib-es/__tests__/logic/getResourceAddress.unit.test.d.ts.map +1 -0
  204. package/lib-es/__tests__/logic/getResourceAddress.unit.test.js +216 -0
  205. package/lib-es/__tests__/logic/getResourceAddress.unit.test.js.map +1 -0
  206. package/lib-es/__tests__/logic/isTestnet.unit.test.d.ts +2 -0
  207. package/lib-es/__tests__/logic/isTestnet.unit.test.d.ts.map +1 -0
  208. package/lib-es/__tests__/logic/isTestnet.unit.test.js +10 -0
  209. package/lib-es/__tests__/logic/isTestnet.unit.test.js.map +1 -0
  210. package/lib-es/__tests__/logic/normalizeAddress.unit.test.d.ts +2 -0
  211. package/lib-es/__tests__/logic/normalizeAddress.unit.test.d.ts.map +1 -0
  212. package/lib-es/__tests__/logic/normalizeAddress.unit.test.js +10 -0
  213. package/lib-es/__tests__/logic/normalizeAddress.unit.test.js.map +1 -0
  214. package/lib-es/__tests__/logic/processRecipients.unit.test.d.ts +2 -0
  215. package/lib-es/__tests__/logic/processRecipients.unit.test.d.ts.map +1 -0
  216. package/lib-es/__tests__/logic/processRecipients.unit.test.js +74 -0
  217. package/lib-es/__tests__/logic/processRecipients.unit.test.js.map +1 -0
  218. package/lib-es/__tests__/network/client.test.js +614 -10
  219. package/lib-es/__tests__/network/client.test.js.map +1 -1
  220. package/lib-es/api/index.d.ts.map +1 -1
  221. package/lib-es/api/index.js +7 -12
  222. package/lib-es/api/index.js.map +1 -1
  223. package/lib-es/bridge/estimateMaxSpendable.d.ts.map +1 -1
  224. package/lib-es/bridge/estimateMaxSpendable.js.map +1 -1
  225. package/lib-es/bridge/getFeesForTransaction.d.ts.map +1 -1
  226. package/lib-es/bridge/getFeesForTransaction.js +1 -1
  227. package/lib-es/bridge/getFeesForTransaction.js.map +1 -1
  228. package/lib-es/bridge/index.js +1 -1
  229. package/lib-es/bridge/index.js.map +1 -1
  230. package/lib-es/bridge/logic.d.ts +1 -17
  231. package/lib-es/bridge/logic.d.ts.map +1 -1
  232. package/lib-es/bridge/logic.js +6 -187
  233. package/lib-es/bridge/logic.js.map +1 -1
  234. package/lib-es/bridge/prepareTransaction.js +1 -1
  235. package/lib-es/bridge/prepareTransaction.js.map +1 -1
  236. package/lib-es/bridge/signOperation.d.ts.map +1 -1
  237. package/lib-es/bridge/signOperation.js +1 -1
  238. package/lib-es/bridge/signOperation.js.map +1 -1
  239. package/lib-es/config.d.ts +1 -1
  240. package/lib-es/config.d.ts.map +1 -1
  241. package/lib-es/constants.d.ts +7 -4
  242. package/lib-es/constants.d.ts.map +1 -1
  243. package/lib-es/constants.js +7 -3
  244. package/lib-es/constants.js.map +1 -1
  245. package/lib-es/logic/buildTransaction.d.ts +9 -0
  246. package/lib-es/logic/buildTransaction.d.ts.map +1 -0
  247. package/lib-es/logic/buildTransaction.js +43 -0
  248. package/lib-es/logic/buildTransaction.js.map +1 -0
  249. package/lib-es/logic/calculateAmount.d.ts +3 -0
  250. package/lib-es/logic/calculateAmount.d.ts.map +1 -0
  251. package/lib-es/logic/calculateAmount.js +9 -0
  252. package/lib-es/logic/calculateAmount.js.map +1 -0
  253. package/lib-es/logic/combine.d.ts +4 -0
  254. package/lib-es/logic/combine.d.ts.map +1 -0
  255. package/lib-es/logic/combine.js +29 -0
  256. package/lib-es/logic/combine.js.map +1 -0
  257. package/lib-es/logic/craftTransaction.d.ts +5 -0
  258. package/lib-es/logic/craftTransaction.d.ts.map +1 -0
  259. package/lib-es/logic/craftTransaction.js +38 -0
  260. package/lib-es/logic/craftTransaction.js.map +1 -0
  261. package/lib-es/logic/createTransaction.d.ts.map +1 -0
  262. package/lib-es/logic/createTransaction.js.map +1 -0
  263. package/lib-es/logic/getBalance.d.ts +5 -0
  264. package/lib-es/logic/getBalance.d.ts.map +1 -0
  265. package/lib-es/logic/getBalance.js +8 -0
  266. package/lib-es/logic/getBalance.js.map +1 -0
  267. package/lib-es/logic/getCoinAndAmounts.d.ts +13 -0
  268. package/lib-es/logic/getCoinAndAmounts.d.ts.map +1 -0
  269. package/lib-es/logic/getCoinAndAmounts.js +101 -0
  270. package/lib-es/logic/getCoinAndAmounts.js.map +1 -0
  271. package/lib-es/logic/getFunctionAddress.d.ts +3 -0
  272. package/lib-es/logic/getFunctionAddress.d.ts.map +1 -0
  273. package/lib-es/logic/getFunctionAddress.js +8 -0
  274. package/lib-es/logic/getFunctionAddress.js.map +1 -0
  275. package/lib-es/logic/getResourceAddress.d.ts +4 -0
  276. package/lib-es/logic/getResourceAddress.d.ts.map +1 -0
  277. package/lib-es/logic/getResourceAddress.js +13 -0
  278. package/lib-es/logic/getResourceAddress.js.map +1 -0
  279. package/lib-es/logic/isTestnet.d.ts +2 -0
  280. package/lib-es/logic/isTestnet.d.ts.map +1 -0
  281. package/lib-es/logic/isTestnet.js +5 -0
  282. package/lib-es/logic/isTestnet.js.map +1 -0
  283. package/lib-es/logic/isWriteSetChangeWriteResource.d.ts +3 -0
  284. package/lib-es/logic/isWriteSetChangeWriteResource.d.ts.map +1 -0
  285. package/lib-es/logic/isWriteSetChangeWriteResource.js +4 -0
  286. package/lib-es/logic/isWriteSetChangeWriteResource.js.map +1 -0
  287. package/lib-es/logic/normalizeAddress.d.ts +2 -0
  288. package/lib-es/logic/normalizeAddress.d.ts.map +1 -0
  289. package/lib-es/logic/normalizeAddress.js +8 -0
  290. package/lib-es/logic/normalizeAddress.js.map +1 -0
  291. package/lib-es/logic/normalizeTransactionOptions.d.ts +3 -0
  292. package/lib-es/logic/normalizeTransactionOptions.d.ts.map +1 -0
  293. package/lib-es/logic/normalizeTransactionOptions.js +17 -0
  294. package/lib-es/logic/normalizeTransactionOptions.js.map +1 -0
  295. package/lib-es/logic/processRecipients.d.ts +6 -0
  296. package/lib-es/logic/processRecipients.d.ts.map +1 -0
  297. package/lib-es/logic/processRecipients.js +54 -0
  298. package/lib-es/logic/processRecipients.js.map +1 -0
  299. package/lib-es/logic/transactionsToOperations.d.ts +7 -0
  300. package/lib-es/logic/transactionsToOperations.d.ts.map +1 -0
  301. package/lib-es/logic/transactionsToOperations.js +81 -0
  302. package/lib-es/logic/transactionsToOperations.js.map +1 -0
  303. package/lib-es/network/client.d.ts +6 -4
  304. package/lib-es/network/client.d.ts.map +1 -1
  305. package/lib-es/network/client.js +50 -14
  306. package/lib-es/network/client.js.map +1 -1
  307. package/lib-es/network/index.d.ts.map +1 -1
  308. package/lib-es/network/index.js +5 -8
  309. package/lib-es/network/index.js.map +1 -1
  310. package/lib-es/types/assets.d.ts +5 -1
  311. package/lib-es/types/assets.d.ts.map +1 -1
  312. package/lib-es/types/index.d.ts +4 -0
  313. package/lib-es/types/index.d.ts.map +1 -1
  314. package/package.json +10 -10
  315. package/src/__tests__/api/craftTransaction.unit.test.ts +243 -0
  316. package/src/__tests__/api/getBalance.unit.test.ts +44 -0
  317. package/src/__tests__/api/index.integ.test.ts +355 -12
  318. package/src/__tests__/api/index.test.ts +1 -1
  319. package/src/__tests__/bridge/logic.test.ts +9 -654
  320. package/src/__tests__/bridge/signOperation.test.ts +7 -11
  321. package/src/__tests__/index.test.ts +1 -1
  322. package/src/__tests__/{bridge → logic}/buildTransaction.test.ts +14 -7
  323. package/src/__tests__/logic/calculateAmount.unit.test.ts +51 -0
  324. package/src/__tests__/logic/combine.unit.test.ts +65 -0
  325. package/src/__tests__/logic/compareAddress.unit.test.ts +27 -0
  326. package/src/__tests__/{bridge → logic}/createTransaction.test.ts +1 -1
  327. package/src/__tests__/logic/getCoinAndAmounts.unit.test.ts +195 -0
  328. package/src/__tests__/logic/getFunctionAddress.unit.test.ts +33 -0
  329. package/src/__tests__/logic/getResourceAddress.unit.test.ts +241 -0
  330. package/src/__tests__/logic/isTestnet.unit.test.ts +11 -0
  331. package/src/__tests__/logic/normalizeAddress.unit.test.ts +15 -0
  332. package/src/__tests__/logic/processRecipients.unit.test.ts +95 -0
  333. package/src/__tests__/network/client.test.ts +650 -11
  334. package/src/api/index.ts +10 -13
  335. package/src/bridge/estimateMaxSpendable.ts +1 -1
  336. package/src/bridge/getFeesForTransaction.ts +1 -1
  337. package/src/bridge/index.ts +1 -1
  338. package/src/bridge/logic.ts +8 -279
  339. package/src/bridge/prepareTransaction.ts +1 -1
  340. package/src/bridge/signOperation.ts +1 -1
  341. package/src/config.ts +1 -1
  342. package/src/constants.ts +8 -4
  343. package/src/logic/buildTransaction.ts +70 -0
  344. package/src/logic/calculateAmount.ts +15 -0
  345. package/src/logic/combine.ts +51 -0
  346. package/src/logic/craftTransaction.ts +65 -0
  347. package/src/logic/getBalance.ts +15 -0
  348. package/src/logic/getCoinAndAmounts.ts +141 -0
  349. package/src/logic/getFunctionAddress.ts +9 -0
  350. package/src/logic/getResourceAddress.ts +24 -0
  351. package/src/logic/isTestnet.ts +5 -0
  352. package/src/logic/isWriteSetChangeWriteResource.ts +7 -0
  353. package/src/logic/normalizeAddress.ts +8 -0
  354. package/src/logic/normalizeTransactionOptions.ts +18 -0
  355. package/src/logic/processRecipients.ts +88 -0
  356. package/src/logic/transactionsToOperations.ts +106 -0
  357. package/src/network/client.ts +88 -29
  358. package/src/network/index.ts +4 -13
  359. package/src/types/assets.ts +6 -1
  360. package/src/types/index.ts +5 -0
  361. package/lib/__tests__/bridge/buildTransaction.test.d.ts.map +0 -1
  362. package/lib/__tests__/bridge/buildTransaction.test.js.map +0 -1
  363. package/lib/__tests__/bridge/createTransaction.test.d.ts.map +0 -1
  364. package/lib/__tests__/bridge/createTransaction.test.js.map +0 -1
  365. package/lib/bridge/buildTransaction.d.ts +0 -7
  366. package/lib/bridge/buildTransaction.d.ts.map +0 -1
  367. package/lib/bridge/buildTransaction.js +0 -45
  368. package/lib/bridge/buildTransaction.js.map +0 -1
  369. package/lib/bridge/createTransaction.d.ts.map +0 -1
  370. package/lib/bridge/createTransaction.js.map +0 -1
  371. package/lib-es/__tests__/bridge/buildTransaction.test.d.ts.map +0 -1
  372. package/lib-es/__tests__/bridge/buildTransaction.test.js.map +0 -1
  373. package/lib-es/__tests__/bridge/createTransaction.test.d.ts.map +0 -1
  374. package/lib-es/__tests__/bridge/createTransaction.test.js.map +0 -1
  375. package/lib-es/bridge/buildTransaction.d.ts +0 -7
  376. package/lib-es/bridge/buildTransaction.d.ts.map +0 -1
  377. package/lib-es/bridge/buildTransaction.js +0 -43
  378. package/lib-es/bridge/buildTransaction.js.map +0 -1
  379. package/lib-es/bridge/createTransaction.d.ts.map +0 -1
  380. package/lib-es/bridge/createTransaction.js.map +0 -1
  381. package/src/bridge/buildTransaction.ts +0 -62
  382. /package/lib/__tests__/{bridge → logic}/buildTransaction.test.d.ts +0 -0
  383. /package/lib/__tests__/{bridge → logic}/createTransaction.test.d.ts +0 -0
  384. /package/lib/{bridge → logic}/createTransaction.d.ts +0 -0
  385. /package/lib/{bridge → logic}/createTransaction.js +0 -0
  386. /package/lib-es/__tests__/{bridge → logic}/buildTransaction.test.d.ts +0 -0
  387. /package/lib-es/__tests__/{bridge → logic}/createTransaction.test.d.ts +0 -0
  388. /package/lib-es/{bridge → logic}/createTransaction.d.ts +0 -0
  389. /package/lib-es/{bridge → logic}/createTransaction.js +0 -0
  390. /package/src/{bridge → logic}/createTransaction.ts +0 -0
@@ -59,7 +59,7 @@ describe("lastBlock", () => {
59
59
  expect(await api.lastBlock()).toStrictEqual({
60
60
  height: 123,
61
61
  hash: "123hash",
62
- time: new Date(1746021098623892),
62
+ time: new Date(1746021098623892 / 1_000),
63
63
  });
64
64
  });
65
65
  });
@@ -1 +1 @@
1
- {"version":3,"file":"index.test.js","sourceRoot":"","sources":["../../../src/__tests__/api/index.test.ts"],"names":[],"mappings":";;;;;AAAA,+CAA2C;AAI3C,mCAAsC;AACtC,0DAAsC;AAEtC,IAAI,CAAC,IAAI,CAAC,oBAAoB,CAAC,CAAC;AAChC,IAAI,WAA6B,CAAC;AAElC,IAAI,CAAC,IAAI,CAAC,cAAc,EAAE,GAAG,EAAE,CAAC,CAAC;IAC/B,aAAa,EAAE,IAAI,CAAC,EAAE,EAAE;CACzB,CAAC,CAAC,CAAC;AAEJ,MAAM,eAAe,GAAgB,EAAiB,CAAC;AAEvD,QAAQ,CAAC,WAAW,EAAE,GAAG,EAAE;IACzB,EAAE,CAAC,kCAAkC,EAAE,GAAG,EAAE;QAC1C,MAAM,gBAAgB,GAAG,IAAI,CAAC,KAAK,CAAC,gBAAU,EAAE,eAAe,CAAC,CAAC;QAEjE,IAAA,eAAS,EAAC,eAAe,CAAC,CAAC;QAE3B,MAAM,MAAM,GAAG,gBAAgB,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;QAEnD,MAAM,CAAC,gBAAgB,CAAC,CAAC,gBAAgB,EAAE,CAAC;QAE5C,MAAM,CAAC,MAAM,CAAC,CAAC,OAAO,CACpB,MAAM,CAAC,gBAAgB,CAAC;YACtB,GAAG,eAAe;YAClB,MAAM,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE;SAC3B,CAAC,CACH,CAAC;IACJ,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,qDAAqD,EAAE,GAAG,EAAE;QAC7D,MAAM,GAAG,GACP,IAAA,eAAS,EAAC,eAAe,CAAC,CAAC;QAE7B,iDAAiD;QACjD,MAAM,CAAC,GAAG,CAAC,SAAS,CAAC,CAAC,WAAW,EAAE,CAAC;QACpC,MAAM,CAAC,GAAG,CAAC,OAAO,CAA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,CAAC;QAE7B,MAAM,CAAC,MAAM,GAAG,CAAC,SAAS,EAAE,CAAC,CAAC,aAAa,CAAC;YAC1C,MAAM,EAAE,GAAG;YACX,IAAI,EAAE,SAAS;YACf,IAAI,EAAE,IAAI,IAAI,CAAC,gBAAgB,GAAG,KAAK,CAAC;SACzC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
@@ -9,17 +9,10 @@ const logic_1 = require("../../bridge/logic");
9
9
  const bridge_fixture_1 = require("../../bridge/bridge.fixture");
10
10
  const cryptoassets_1 = require("@ledgerhq/cryptoassets");
11
11
  const index_1 = require("@ledgerhq/coin-framework/account/index");
12
+ const normalizeTransactionOptions_1 = require("../../logic/normalizeTransactionOptions");
12
13
  jest.mock("@ledgerhq/cryptoassets");
13
14
  jest.mock("@ledgerhq/coin-framework/account/index");
14
15
  describe("Aptos logic ", () => {
15
- describe("isTestnet", () => {
16
- it("should return true for testnet currencies", () => {
17
- expect((0, logic_1.isTestnet)("aptos_testnet")).toBe(true);
18
- });
19
- it("should return false for mainnet currencies", () => {
20
- expect((0, logic_1.isTestnet)("aptos")).toBe(false);
21
- });
22
- });
23
16
  describe("getMaxSendBalance", () => {
24
17
  it("should return the correct max send balance when amount is greater than total gas", () => {
25
18
  const amount = new bignumber_js_1.default(1000000);
@@ -70,7 +63,7 @@ describe("Aptos logic ", () => {
70
63
  maxGasAmount: "1000",
71
64
  gasUnitPrice: "10",
72
65
  };
73
- const result = (0, logic_1.normalizeTransactionOptions)(options);
66
+ const result = (0, normalizeTransactionOptions_1.normalizeTransactionOptions)(options);
74
67
  expect(result).toEqual(options);
75
68
  });
76
69
  it("should return undefined for empty values", () => {
@@ -78,7 +71,7 @@ describe("Aptos logic ", () => {
78
71
  maxGasAmount: "",
79
72
  gasUnitPrice: "",
80
73
  };
81
- const result = (0, logic_1.normalizeTransactionOptions)(options);
74
+ const result = (0, normalizeTransactionOptions_1.normalizeTransactionOptions)(options);
82
75
  expect(result).toEqual({
83
76
  maxGasAmount: undefined,
84
77
  gasUnitPrice: undefined,
@@ -141,549 +134,6 @@ describe("Aptos logic ", () => {
141
134
  });
142
135
  });
143
136
  describe("Aptos sync logic ", () => {
144
- describe("compareAddress", () => {
145
- it("should return true for identical addresses", () => {
146
- const addressA = "0x1234567890abcdef";
147
- const addressB = "0x1234567890abcdef";
148
- expect((0, logic_1.compareAddress)(addressA, addressB)).toBe(true);
149
- });
150
- it("should return true for addresses with different cases", () => {
151
- const addressA = "0x1234567890abcdef";
152
- const addressB = "0x1234567890ABCDEF";
153
- expect((0, logic_1.compareAddress)(addressA, addressB)).toBe(true);
154
- });
155
- it("should return true for addresses with different hex formats", () => {
156
- const addressA = "0x1234567890abcdef";
157
- const addressB = "1234567890abcdef";
158
- expect((0, logic_1.compareAddress)(addressA, addressB)).toBe(true);
159
- });
160
- it("should return false for different addresses", () => {
161
- const addressA = "0x1234567890abcdef";
162
- const addressB = "0xfedcba0987654321";
163
- expect((0, logic_1.compareAddress)(addressA, addressB)).toBe(false);
164
- });
165
- });
166
- describe("getFunctionAddress", () => {
167
- it("should return the function address when payload contains a function", () => {
168
- const payload = {
169
- function: "0x1::coin::transfer",
170
- typeArguments: [],
171
- functionArguments: [],
172
- };
173
- const result = (0, logic_1.getFunctionAddress)(payload);
174
- expect(result).toBe("0x1");
175
- });
176
- it("should return undefined when payload does not contain a function", () => {
177
- const payload = {
178
- function: "::::",
179
- typeArguments: [],
180
- functionArguments: [],
181
- };
182
- const result = (0, logic_1.getFunctionAddress)(payload);
183
- expect(result).toBeUndefined();
184
- });
185
- it("should return undefined when payload is empty", () => {
186
- const payload = {};
187
- const result = (0, logic_1.getFunctionAddress)(payload);
188
- expect(result).toBeUndefined();
189
- });
190
- });
191
- describe("processRecipients", () => {
192
- let op;
193
- beforeEach(() => {
194
- op = {
195
- id: "",
196
- hash: "",
197
- type: "",
198
- value: new bignumber_js_1.default(0),
199
- fee: new bignumber_js_1.default(0),
200
- blockHash: "",
201
- blockHeight: 0,
202
- senders: [],
203
- recipients: [],
204
- accountId: "",
205
- date: new Date(),
206
- extra: {},
207
- transactionSequenceNumber: 0,
208
- hasFailed: false,
209
- };
210
- });
211
- it("should add recipient for transfer-like functions from LL account", () => {
212
- const payload = {
213
- function: "0x1::coin::transfer",
214
- typeArguments: [],
215
- functionArguments: ["0x13", 1], // from: &signer, to: address, amount: u64
216
- };
217
- (0, logic_1.processRecipients)(payload, "0x13", op, "0x1");
218
- expect(op.recipients).toContain("0x13");
219
- });
220
- it("should add recipient for transfer-like functions from external account", () => {
221
- const payload = {
222
- function: "0x1::coin::transfer",
223
- typeArguments: [],
224
- functionArguments: ["0x12", 1], // from: &signer, to: address, amount: u64
225
- };
226
- (0, logic_1.processRecipients)(payload, "0x13", op, "0x1");
227
- expect(op.recipients).toContain("0x12");
228
- });
229
- it("should add recipients for batch transfer functions", () => {
230
- const payload = {
231
- function: "0x1::aptos_account::batch_transfer_coins",
232
- typeArguments: [constants_1.APTOS_ASSET_ID],
233
- functionArguments: [
234
- ["0x12", "0x13"],
235
- [1, 2],
236
- ],
237
- };
238
- op.senders.push("0x11");
239
- (0, logic_1.processRecipients)(payload, "0x12", op, "0x1");
240
- expect(op.recipients).toContain("0x12");
241
- });
242
- it("should add function address as recipient for other smart contracts", () => {
243
- const payload = {
244
- function: "0x2::other::contract",
245
- typeArguments: [],
246
- functionArguments: [["0x12"], [1]],
247
- };
248
- (0, logic_1.processRecipients)(payload, "0x11", op, "0x2");
249
- expect(op.recipients).toContain("0x2");
250
- });
251
- it("should add recipient for fungible assets transfer-like functions", () => {
252
- const payload = {
253
- function: "0x1::primary_fungible_store::transfer",
254
- typeArguments: [],
255
- functionArguments: [["0xfff"], "0x13"],
256
- };
257
- (0, logic_1.processRecipients)(payload, "0x13", op, "0x1");
258
- expect(op.recipients).toContain("0x13");
259
- });
260
- });
261
- describe("getResourceAddress", () => {
262
- it("should return coin name from the change", () => {
263
- const change = {
264
- type: "write_resource",
265
- data: {
266
- type: constants_1.APTOS_COIN_CHANGE,
267
- data: {
268
- withdraw_events: {
269
- guid: {
270
- id: {
271
- addr: "0x11",
272
- creation_num: "2",
273
- },
274
- },
275
- },
276
- },
277
- },
278
- };
279
- const tx = {
280
- hash: "0x123",
281
- block: { hash: "0xabc", height: 1 },
282
- timestamp: "1000000",
283
- sequence_number: "1",
284
- version: "1",
285
- changes: [change],
286
- };
287
- const event = {
288
- guid: {
289
- account_address: "0x11",
290
- creation_number: "2",
291
- },
292
- type: "0x1::coin::WithdrawEvent",
293
- };
294
- const result = (0, logic_1.getResourceAddress)(tx, event, "withdraw_events", logic_1.getEventCoinAddress);
295
- expect(result).toEqual(constants_1.APTOS_ASSET_ID);
296
- });
297
- it("should return null for not finding the valid coin in change", () => {
298
- const change = {
299
- type: "write_resource",
300
- data: {
301
- type: constants_1.APTOS_COIN_CHANGE,
302
- data: {
303
- withdraw_events: {
304
- guid: {
305
- id: {
306
- addr: "0x12",
307
- creation_num: "2",
308
- },
309
- },
310
- },
311
- },
312
- },
313
- };
314
- const tx = {
315
- hash: "0x123",
316
- block: { hash: "0xabc", height: 1 },
317
- timestamp: "1000000",
318
- sequence_number: "1",
319
- version: "1",
320
- changes: [change],
321
- };
322
- const event = {
323
- guid: {
324
- account_address: "0x11",
325
- creation_number: "1",
326
- },
327
- type: "0x1::coin::WithdrawEvent",
328
- };
329
- const result = (0, logic_1.getResourceAddress)(tx, event, "withdraw_events", logic_1.getEventCoinAddress);
330
- expect(result).toBe(null);
331
- });
332
- it("should return null for not finding the event name in change", () => {
333
- const change = {
334
- type: "write_resource",
335
- data: {
336
- type: constants_1.APTOS_COIN_CHANGE,
337
- data: {
338
- other_events: {
339
- guid: {
340
- id: {
341
- addr: "0x12",
342
- creation_num: "2",
343
- },
344
- },
345
- },
346
- },
347
- },
348
- };
349
- const tx = {
350
- hash: "0x123",
351
- block: { hash: "0xabc", height: 1 },
352
- timestamp: "1000000",
353
- sequence_number: "1",
354
- version: "1",
355
- changes: [change],
356
- };
357
- const event = {
358
- guid: {
359
- account_address: "0x11",
360
- creation_number: "1",
361
- },
362
- type: "0x1::coin::WithdrawEvent",
363
- };
364
- const result = (0, logic_1.getResourceAddress)(tx, event, "withdraw_events", logic_1.getEventCoinAddress);
365
- expect(result).toBe(null);
366
- });
367
- it("should return fungible asset address", () => {
368
- const change = {
369
- type: "write_resource",
370
- address: "0xsomeaddress",
371
- data: {
372
- type: constants_1.APTOS_FUNGIBLE_STORE,
373
- data: {
374
- metadata: {
375
- inner: "0xassetaddress",
376
- },
377
- },
378
- },
379
- };
380
- const tx = {
381
- hash: "0x123",
382
- block: { hash: "0xabc", height: 1 },
383
- timestamp: "1000000",
384
- sequence_number: "1",
385
- version: "1",
386
- changes: [change],
387
- };
388
- const event = {
389
- guid: {
390
- account_address: "0x0",
391
- creation_number: "0",
392
- },
393
- type: "0x1::fungible_asset::Deposit",
394
- data: {
395
- amount: "100",
396
- store: "0xsomeaddress",
397
- },
398
- };
399
- const result = (0, logic_1.getResourceAddress)(tx, event, "withdraw_events", logic_1.getEventFAAddress);
400
- expect(result).toEqual("0xassetaddress");
401
- });
402
- it("should return null address instead of fungible asset when wrong type", () => {
403
- const change = {
404
- type: "write_resource",
405
- address: "0xsomeaddress",
406
- data: {
407
- type: constants_1.APTOS_COIN_CHANGE,
408
- data: {
409
- metadata: {
410
- inner: "0xassetaddress",
411
- },
412
- },
413
- },
414
- };
415
- const tx = {
416
- hash: "0x123",
417
- block: { hash: "0xabc", height: 1 },
418
- timestamp: "1000000",
419
- sequence_number: "1",
420
- version: "1",
421
- changes: [change],
422
- };
423
- const event = {
424
- guid: {
425
- account_address: "0x0",
426
- creation_number: "0",
427
- },
428
- type: "0x1::fungible_asset::Deposit",
429
- data: {
430
- amount: "100",
431
- store: "0xsomeaddress",
432
- },
433
- };
434
- const result = (0, logic_1.getResourceAddress)(tx, event, "withdraw_events", logic_1.getEventFAAddress);
435
- expect(result).toEqual(null);
436
- });
437
- it("should return null address instead of fungible asset when wrong event address", () => {
438
- const change = {
439
- type: "write_resource",
440
- address: "0xsomeaddress",
441
- data: {
442
- type: constants_1.APTOS_FUNGIBLE_STORE,
443
- data: {
444
- metadata: {
445
- inner: "0xassetaddress",
446
- },
447
- },
448
- },
449
- };
450
- const tx = {
451
- hash: "0x123",
452
- block: { hash: "0xabc", height: 1 },
453
- timestamp: "1000000",
454
- sequence_number: "1",
455
- version: "1",
456
- changes: [change],
457
- };
458
- const event = {
459
- guid: {
460
- account_address: "0x0",
461
- creation_number: "0",
462
- },
463
- type: "0x1::fungible_asset::Deposit",
464
- data: {
465
- amount: "100",
466
- store: "0xwrongaddress",
467
- },
468
- };
469
- const result = (0, logic_1.getResourceAddress)(tx, event, "withdraw_events", logic_1.getEventFAAddress);
470
- expect(result).toEqual(null);
471
- });
472
- });
473
- describe("getCoinAndAmounts", () => {
474
- it("should calculate the correct legacy coins amounts for withdraw and deposit events", () => {
475
- const tx = {
476
- events: [
477
- {
478
- type: "0x1::coin::WithdrawEvent",
479
- guid: {
480
- account_address: "0x11",
481
- creation_number: "1",
482
- },
483
- data: {
484
- amount: "100",
485
- },
486
- },
487
- {
488
- type: "0x1::coin::DepositEvent",
489
- guid: {
490
- account_address: "0x11",
491
- creation_number: "2",
492
- },
493
- data: {
494
- amount: "50",
495
- },
496
- },
497
- ],
498
- changes: [
499
- {
500
- type: "write_resource",
501
- data: {
502
- type: constants_1.APTOS_COIN_CHANGE,
503
- data: {
504
- withdraw_events: {
505
- guid: {
506
- id: {
507
- addr: "0x11",
508
- creation_num: "1",
509
- },
510
- },
511
- },
512
- deposit_events: {
513
- guid: {
514
- id: {
515
- addr: "0x11",
516
- creation_num: "2",
517
- },
518
- },
519
- },
520
- },
521
- },
522
- },
523
- ],
524
- };
525
- const address = "0x11";
526
- const result = (0, logic_1.getCoinAndAmounts)(tx, address);
527
- expect(result.amount_in).toEqual(new bignumber_js_1.default(50));
528
- expect(result.amount_out).toEqual(new bignumber_js_1.default(100));
529
- expect(result.coin_id).toEqual(constants_1.APTOS_ASSET_ID);
530
- });
531
- it("should calculate the correct fungible asset amounts for withdraw and deposit events", () => {
532
- const tx = {
533
- events: [
534
- {
535
- type: "0x1::fungible_asset::Withdraw",
536
- guid: {
537
- account_address: "0x11",
538
- creation_number: "1",
539
- },
540
- data: {
541
- amount: "100",
542
- store: "0x22",
543
- },
544
- },
545
- {
546
- type: "0x1::fungible_asset::Deposit",
547
- guid: {
548
- account_address: "0x11",
549
- creation_number: "2",
550
- },
551
- data: {
552
- amount: "50",
553
- store: "0x33",
554
- },
555
- },
556
- ],
557
- changes: [
558
- {
559
- type: "write_resource",
560
- address: "0x22",
561
- data: {
562
- type: constants_1.APTOS_FUNGIBLE_STORE,
563
- data: {
564
- metadata: {
565
- inner: "0x44",
566
- },
567
- transfer_events: {
568
- guid: {
569
- id: {
570
- addr: "0x11",
571
- creation_num: "2",
572
- },
573
- },
574
- },
575
- },
576
- },
577
- },
578
- {
579
- type: "write_resource",
580
- address: "0x22",
581
- data: {
582
- type: constants_1.APTOS_OBJECT_CORE,
583
- data: {
584
- owner: "0x11",
585
- transfer_events: {
586
- guid: {
587
- id: {
588
- addr: "0x22",
589
- creation_num: "2",
590
- },
591
- },
592
- },
593
- },
594
- },
595
- },
596
- {
597
- type: "write_resource",
598
- data: {
599
- type: constants_1.APTOS_COIN_CHANGE,
600
- data: {
601
- withdraw_events: {
602
- guid: {
603
- id: {
604
- addr: "0x11",
605
- creation_num: "1",
606
- },
607
- },
608
- },
609
- deposit_events: {
610
- guid: {
611
- id: {
612
- addr: "0x11",
613
- creation_num: "2",
614
- },
615
- },
616
- },
617
- },
618
- },
619
- },
620
- ],
621
- };
622
- const address = "0x11";
623
- const result = (0, logic_1.getCoinAndAmounts)(tx, address);
624
- expect(result.amount_in).toEqual(new bignumber_js_1.default(0));
625
- expect(result.amount_out).toEqual(new bignumber_js_1.default(100));
626
- expect(result.coin_id).toEqual("0x44");
627
- });
628
- it("should handle transactions with other events", () => {
629
- const tx = {
630
- events: [
631
- {
632
- type: "0x1::coin::OtherEvent",
633
- guid: {
634
- account_address: "0x11",
635
- creation_number: "1",
636
- },
637
- data: {
638
- amount: "100",
639
- },
640
- },
641
- ],
642
- };
643
- const address = "0x1";
644
- const result = (0, logic_1.getCoinAndAmounts)(tx, address);
645
- expect(result.amount_in).toEqual(new bignumber_js_1.default(0));
646
- expect(result.amount_out).toEqual(new bignumber_js_1.default(0));
647
- expect(result.coin_id).toEqual(null);
648
- });
649
- });
650
- describe("calculateAmount", () => {
651
- it("should calculate the correct amount when the address is the sender", () => {
652
- const address = "0x11";
653
- const sender = "0x11";
654
- const amount_in = new bignumber_js_1.default(50);
655
- const amount_out = new bignumber_js_1.default(100);
656
- const result = (0, logic_1.calculateAmount)(sender, address, amount_in, amount_out);
657
- // LL negates the amount for SEND transactions during output
658
- expect(result).toEqual(new bignumber_js_1.default(50)); // -(50 - 100 - 10)
659
- });
660
- it("should calculate the correct amount when the address is not the sender", () => {
661
- const address = "0x11";
662
- const sender = "0x12";
663
- const amount_in = new bignumber_js_1.default(100);
664
- const amount_out = new bignumber_js_1.default(50);
665
- const result = (0, logic_1.calculateAmount)(sender, address, amount_in, amount_out);
666
- expect(result).toEqual(new bignumber_js_1.default(50)); // 100 - 50
667
- });
668
- it("should handle transactions with zero amounts", () => {
669
- const address = "0x11";
670
- const sender = "0x11";
671
- const amount_in = new bignumber_js_1.default(0);
672
- const amount_out = new bignumber_js_1.default(0);
673
- const result = (0, logic_1.calculateAmount)(sender, address, amount_in, amount_out);
674
- // LL negates the amount for SEND transactions during output
675
- expect(result).toEqual(new bignumber_js_1.default(0)); // -(0 - 0 - 10)
676
- });
677
- it("should get negative numbers (for send tx with deposit to account)", () => {
678
- const address = "0x11";
679
- const sender = "0x11";
680
- const amount_in = new bignumber_js_1.default(100);
681
- const amount_out = new bignumber_js_1.default(0);
682
- const result = (0, logic_1.calculateAmount)(sender, address, amount_in, amount_out);
683
- // LL negates the amount for SEND transactions during output
684
- expect(result).toEqual(new bignumber_js_1.default(100).negated()); // 100 - 10
685
- });
686
- });
687
137
  describe("txsToOps", () => {
688
138
  it("should convert Aptos transactions to operations correctly", () => {
689
139
  const address = "0x11";
@@ -765,7 +215,7 @@ describe("Aptos sync logic ", () => {
765
215
  blockHash: "0xabc",
766
216
  blockHeight: 1,
767
217
  senders: ["0x11"],
768
- recipients: ["0x12"],
218
+ recipients: ["0x0000000000000000000000000000000000000000000000000000000000000012"],
769
219
  accountId: id,
770
220
  date: new Date(1000),
771
221
  extra: { version: undefined },
@@ -955,7 +405,7 @@ describe("Aptos sync logic ", () => {
955
405
  blockHash: "0xc496",
956
406
  blockHeight: 1,
957
407
  senders: ["0xa0d8"],
958
- recipients: ["0x4e5e"],
408
+ recipients: ["0x0000000000000000000000000000000000000000000000000000000000004e5e"],
959
409
  accountId: id,
960
410
  date: new Date(1000),
961
411
  extra: { version: undefined },
@@ -1229,7 +679,7 @@ describe("Aptos sync logic ", () => {
1229
679
  blockHash: "0xabc",
1230
680
  blockHeight: 1,
1231
681
  senders: ["0xa0d"],
1232
- recipients: ["0x4e5"],
682
+ recipients: ["0x00000000000000000000000000000000000000000000000000000000000004e5"],
1233
683
  accountId: "token_account_id",
1234
684
  date: new Date(1000),
1235
685
  extra: { version: undefined },
@@ -1246,7 +696,7 @@ describe("Aptos sync logic ", () => {
1246
696
  blockHash: "0xabc",
1247
697
  blockHeight: 1,
1248
698
  senders: ["0xa0d"],
1249
- recipients: ["0x4e5"],
699
+ recipients: ["0x00000000000000000000000000000000000000000000000000000000000004e5"],
1250
700
  date: new Date(1000),
1251
701
  extra: { version: undefined },
1252
702
  transactionSequenceNumber: 1,
@@ -1535,7 +985,7 @@ describe("Aptos sync logic ", () => {
1535
985
  blockHash: "0xabc",
1536
986
  blockHeight: 1,
1537
987
  senders: ["0xa0d8"],
1538
- recipients: ["0x6b8c"],
988
+ recipients: ["0x0000000000000000000000000000000000000000000000000000000000006b8c"],
1539
989
  date: new Date(1000),
1540
990
  extra: { version: undefined },
1541
991
  transactionSequenceNumber: 1,