@ledgerhq/coin-aptos 1.10.0-nightly.0 → 1.10.0-nightly.2

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 (459) hide show
  1. package/.turbo/turbo-build.log +1 -1
  2. package/.unimportedrc.json +18 -6
  3. package/CHANGELOG.md +40 -9
  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 -460
  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 +9 -9
  23. package/lib/__tests__/bridge/getFeesForTransaction.test.js.map +1 -1
  24. package/lib/__tests__/bridge/logic.test.js +3 -553
  25. package/lib/__tests__/bridge/logic.test.js.map +1 -1
  26. package/lib/__tests__/bridge/prepareTransaction.test.js +3 -3
  27. package/lib/__tests__/bridge/prepareTransaction.test.js.map +1 -1
  28. package/lib/__tests__/bridge/signOperation.test.js +9 -12
  29. package/lib/__tests__/bridge/signOperation.test.js.map +1 -1
  30. package/lib/__tests__/bridge/synchronisation.test.js +6 -6
  31. package/lib/__tests__/bridge/synchronisation.test.js.map +1 -1
  32. package/lib/__tests__/index.test.js +1 -1
  33. package/lib/__tests__/index.test.js.map +1 -1
  34. package/lib/__tests__/logic/buildTransaction.test.d.ts.map +1 -0
  35. package/lib/__tests__/{bridge → logic}/buildTransaction.test.js +16 -12
  36. package/lib/__tests__/logic/buildTransaction.test.js.map +1 -0
  37. package/lib/__tests__/logic/calculateAmount.unit.test.d.ts +2 -0
  38. package/lib/__tests__/logic/calculateAmount.unit.test.d.ts.map +1 -0
  39. package/lib/__tests__/logic/calculateAmount.unit.test.js +45 -0
  40. package/lib/__tests__/logic/calculateAmount.unit.test.js.map +1 -0
  41. package/lib/__tests__/logic/combine.unit.test.d.ts +2 -0
  42. package/lib/__tests__/logic/combine.unit.test.d.ts.map +1 -0
  43. package/lib/__tests__/logic/combine.unit.test.js +47 -0
  44. package/lib/__tests__/logic/combine.unit.test.js.map +1 -0
  45. package/lib/__tests__/logic/compareAddress.unit.test.d.ts +2 -0
  46. package/lib/__tests__/logic/compareAddress.unit.test.d.ts.map +1 -0
  47. package/lib/__tests__/logic/compareAddress.unit.test.js +26 -0
  48. package/lib/__tests__/logic/compareAddress.unit.test.js.map +1 -0
  49. package/lib/__tests__/logic/createTransaction.test.d.ts.map +1 -0
  50. package/lib/__tests__/{bridge → logic}/createTransaction.test.js +2 -2
  51. package/lib/__tests__/logic/createTransaction.test.js.map +1 -0
  52. package/lib/__tests__/logic/getCoinAndAmounts.unit.test.d.ts +2 -0
  53. package/lib/__tests__/logic/getCoinAndAmounts.unit.test.d.ts.map +1 -0
  54. package/lib/__tests__/logic/getCoinAndAmounts.unit.test.js +186 -0
  55. package/lib/__tests__/logic/getCoinAndAmounts.unit.test.js.map +1 -0
  56. package/lib/__tests__/logic/getFunctionAddress.unit.test.d.ts +2 -0
  57. package/lib/__tests__/logic/getFunctionAddress.unit.test.d.ts.map +1 -0
  58. package/lib/__tests__/logic/getFunctionAddress.unit.test.js +29 -0
  59. package/lib/__tests__/logic/getFunctionAddress.unit.test.js.map +1 -0
  60. package/lib/__tests__/logic/getResourceAddress.unit.test.d.ts +2 -0
  61. package/lib/__tests__/logic/getResourceAddress.unit.test.d.ts.map +1 -0
  62. package/lib/__tests__/logic/getResourceAddress.unit.test.js +218 -0
  63. package/lib/__tests__/logic/getResourceAddress.unit.test.js.map +1 -0
  64. package/lib/__tests__/logic/isTestnet.unit.test.d.ts +2 -0
  65. package/lib/__tests__/logic/isTestnet.unit.test.d.ts.map +1 -0
  66. package/lib/__tests__/logic/isTestnet.unit.test.js +12 -0
  67. package/lib/__tests__/logic/isTestnet.unit.test.js.map +1 -0
  68. package/lib/__tests__/logic/processRecipients.unit.test.d.ts +2 -0
  69. package/lib/__tests__/logic/processRecipients.unit.test.d.ts.map +1 -0
  70. package/lib/__tests__/logic/processRecipients.unit.test.js +79 -0
  71. package/lib/__tests__/logic/processRecipients.unit.test.js.map +1 -0
  72. package/lib/__tests__/network/client.test.d.ts +2 -0
  73. package/lib/__tests__/network/client.test.d.ts.map +1 -0
  74. package/lib/__tests__/network/client.test.js +992 -0
  75. package/lib/__tests__/network/client.test.js.map +1 -0
  76. package/lib/api/index.d.ts +4 -33
  77. package/lib/api/index.d.ts.map +1 -1
  78. package/lib/api/index.js +19 -196
  79. package/lib/api/index.js.map +1 -1
  80. package/lib/bridge/broadcast.d.ts +3 -2
  81. package/lib/bridge/broadcast.d.ts.map +1 -1
  82. package/lib/bridge/broadcast.js +4 -3
  83. package/lib/bridge/broadcast.js.map +1 -1
  84. package/lib/bridge/estimateMaxSpendable.d.ts.map +1 -1
  85. package/lib/bridge/estimateMaxSpendable.js +5 -4
  86. package/lib/bridge/estimateMaxSpendable.js.map +1 -1
  87. package/lib/bridge/getFeesForTransaction.d.ts +1 -1
  88. package/lib/bridge/getFeesForTransaction.d.ts.map +1 -1
  89. package/lib/bridge/getFeesForTransaction.js +8 -7
  90. package/lib/bridge/getFeesForTransaction.js.map +1 -1
  91. package/lib/bridge/index.d.ts +1 -1
  92. package/lib/bridge/index.d.ts.map +1 -1
  93. package/lib/bridge/index.js +1 -1
  94. package/lib/bridge/index.js.map +1 -1
  95. package/lib/bridge/logic.d.ts +1 -20
  96. package/lib/bridge/logic.d.ts.map +1 -1
  97. package/lib/bridge/logic.js +12 -207
  98. package/lib/bridge/logic.js.map +1 -1
  99. package/lib/bridge/prepareTransaction.d.ts.map +1 -1
  100. package/lib/bridge/prepareTransaction.js +4 -3
  101. package/lib/bridge/prepareTransaction.js.map +1 -1
  102. package/lib/bridge/signOperation.d.ts.map +1 -1
  103. package/lib/bridge/signOperation.js +4 -4
  104. package/lib/bridge/signOperation.js.map +1 -1
  105. package/lib/bridge/synchronisation.js +3 -3
  106. package/lib/bridge/synchronisation.js.map +1 -1
  107. package/lib/config.d.ts +13 -0
  108. package/lib/config.d.ts.map +1 -0
  109. package/lib/config.js +9 -0
  110. package/lib/config.js.map +1 -0
  111. package/lib/constants.d.ts +5 -1
  112. package/lib/constants.d.ts.map +1 -1
  113. package/lib/constants.js +8 -1
  114. package/lib/constants.js.map +1 -1
  115. package/lib/{bridge → logic}/buildTransaction.d.ts +1 -1
  116. package/lib/logic/buildTransaction.d.ts.map +1 -0
  117. package/lib/{bridge → logic}/buildTransaction.js +2 -2
  118. package/lib/logic/buildTransaction.js.map +1 -0
  119. package/lib/logic/calculateAmount.d.ts +3 -0
  120. package/lib/logic/calculateAmount.d.ts.map +1 -0
  121. package/lib/logic/calculateAmount.js +13 -0
  122. package/lib/logic/calculateAmount.js.map +1 -0
  123. package/lib/logic/combine.d.ts +4 -0
  124. package/lib/logic/combine.d.ts.map +1 -0
  125. package/lib/logic/combine.js +34 -0
  126. package/lib/logic/combine.js.map +1 -0
  127. package/lib/logic/craftTransaction.d.ts +5 -0
  128. package/lib/logic/craftTransaction.d.ts.map +1 -0
  129. package/lib/logic/craftTransaction.js +23 -0
  130. package/lib/logic/craftTransaction.js.map +1 -0
  131. package/lib/logic/createTransaction.d.ts.map +1 -0
  132. package/lib/{bridge → logic}/createTransaction.js +3 -3
  133. package/lib/logic/createTransaction.js.map +1 -0
  134. package/lib/logic/getBalance.d.ts +5 -0
  135. package/lib/logic/getBalance.d.ts.map +1 -0
  136. package/lib/logic/getBalance.js +12 -0
  137. package/lib/logic/getBalance.js.map +1 -0
  138. package/lib/logic/getCoinAndAmounts.d.ts +13 -0
  139. package/lib/logic/getCoinAndAmounts.d.ts.map +1 -0
  140. package/lib/logic/getCoinAndAmounts.js +112 -0
  141. package/lib/logic/getCoinAndAmounts.js.map +1 -0
  142. package/lib/logic/getFunctionAddress.d.ts +3 -0
  143. package/lib/logic/getFunctionAddress.d.ts.map +1 -0
  144. package/lib/logic/getFunctionAddress.js +12 -0
  145. package/lib/logic/getFunctionAddress.js.map +1 -0
  146. package/lib/logic/getResourceAddress.d.ts +4 -0
  147. package/lib/logic/getResourceAddress.d.ts.map +1 -0
  148. package/lib/logic/getResourceAddress.js +17 -0
  149. package/lib/logic/getResourceAddress.js.map +1 -0
  150. package/lib/logic/isTestnet.d.ts +2 -0
  151. package/lib/logic/isTestnet.d.ts.map +1 -0
  152. package/lib/logic/isTestnet.js +9 -0
  153. package/lib/logic/isTestnet.js.map +1 -0
  154. package/lib/logic/isWriteSetChangeWriteResource.d.ts +3 -0
  155. package/lib/logic/isWriteSetChangeWriteResource.d.ts.map +1 -0
  156. package/lib/logic/isWriteSetChangeWriteResource.js +8 -0
  157. package/lib/logic/isWriteSetChangeWriteResource.js.map +1 -0
  158. package/lib/logic/normalizeTransactionOptions.d.ts +3 -0
  159. package/lib/logic/normalizeTransactionOptions.d.ts.map +1 -0
  160. package/lib/logic/normalizeTransactionOptions.js +21 -0
  161. package/lib/logic/normalizeTransactionOptions.js.map +1 -0
  162. package/lib/logic/processRecipients.d.ts +6 -0
  163. package/lib/logic/processRecipients.d.ts.map +1 -0
  164. package/lib/logic/processRecipients.js +57 -0
  165. package/lib/logic/processRecipients.js.map +1 -0
  166. package/lib/logic/transactionsToOperations.d.ts +7 -0
  167. package/lib/logic/transactionsToOperations.d.ts.map +1 -0
  168. package/lib/logic/transactionsToOperations.js +85 -0
  169. package/lib/logic/transactionsToOperations.js.map +1 -0
  170. package/lib/network/client.d.ts +38 -0
  171. package/lib/network/client.d.ts.map +1 -0
  172. package/lib/network/client.js +266 -0
  173. package/lib/network/client.js.map +1 -0
  174. package/lib/network/graphql/queries.d.ts.map +1 -0
  175. package/lib/network/graphql/queries.js.map +1 -0
  176. package/lib/network/graphql/types.d.ts.map +1 -0
  177. package/lib/{api → network}/graphql/types.js.map +1 -1
  178. package/lib/network/index.d.ts +2 -1
  179. package/lib/network/index.d.ts.map +1 -1
  180. package/lib/network/index.js +19 -7
  181. package/lib/network/index.js.map +1 -1
  182. package/lib/types/assets.d.ts +12 -0
  183. package/lib/types/assets.d.ts.map +1 -0
  184. package/lib/types/assets.js +3 -0
  185. package/lib/types/assets.js.map +1 -0
  186. package/lib/types/index.d.ts +4 -0
  187. package/lib/types/index.d.ts.map +1 -1
  188. package/lib-es/__tests__/api/craftTransaction.unit.test.d.ts +2 -0
  189. package/lib-es/__tests__/api/craftTransaction.unit.test.d.ts.map +1 -0
  190. package/lib-es/__tests__/api/craftTransaction.unit.test.js +48 -0
  191. package/lib-es/__tests__/api/craftTransaction.unit.test.js.map +1 -0
  192. package/lib-es/__tests__/api/getBalance.unit.test.d.ts +2 -0
  193. package/lib-es/__tests__/api/getBalance.unit.test.d.ts.map +1 -0
  194. package/lib-es/__tests__/api/getBalance.unit.test.js +36 -0
  195. package/lib-es/__tests__/api/getBalance.unit.test.js.map +1 -0
  196. package/lib-es/__tests__/api/index.integ.test.d.ts +2 -0
  197. package/lib-es/__tests__/api/index.integ.test.d.ts.map +1 -0
  198. package/lib-es/__tests__/api/index.integ.test.js +113 -0
  199. package/lib-es/__tests__/api/index.integ.test.js.map +1 -0
  200. package/lib-es/__tests__/api/index.test.js +52 -464
  201. package/lib-es/__tests__/api/index.test.js.map +1 -1
  202. package/lib-es/__tests__/bridge/broadcast.test.js +2 -2
  203. package/lib-es/__tests__/bridge/broadcast.test.js.map +1 -1
  204. package/lib-es/__tests__/bridge/getFeesForTransaction.test.js +2 -2
  205. package/lib-es/__tests__/bridge/getFeesForTransaction.test.js.map +1 -1
  206. package/lib-es/__tests__/bridge/logic.test.js +3 -553
  207. package/lib-es/__tests__/bridge/logic.test.js.map +1 -1
  208. package/lib-es/__tests__/bridge/prepareTransaction.test.js +2 -2
  209. package/lib-es/__tests__/bridge/prepareTransaction.test.js.map +1 -1
  210. package/lib-es/__tests__/bridge/signOperation.test.js +9 -12
  211. package/lib-es/__tests__/bridge/signOperation.test.js.map +1 -1
  212. package/lib-es/__tests__/bridge/synchronisation.test.js +3 -3
  213. package/lib-es/__tests__/bridge/synchronisation.test.js.map +1 -1
  214. package/lib-es/__tests__/index.test.js +1 -1
  215. package/lib-es/__tests__/index.test.js.map +1 -1
  216. package/lib-es/__tests__/logic/buildTransaction.test.d.ts.map +1 -0
  217. package/lib-es/__tests__/{bridge → logic}/buildTransaction.test.js +9 -5
  218. package/lib-es/__tests__/logic/buildTransaction.test.js.map +1 -0
  219. package/lib-es/__tests__/logic/calculateAmount.unit.test.d.ts +2 -0
  220. package/lib-es/__tests__/logic/calculateAmount.unit.test.d.ts.map +1 -0
  221. package/lib-es/__tests__/logic/calculateAmount.unit.test.js +40 -0
  222. package/lib-es/__tests__/logic/calculateAmount.unit.test.js.map +1 -0
  223. package/lib-es/__tests__/logic/combine.unit.test.d.ts +2 -0
  224. package/lib-es/__tests__/logic/combine.unit.test.d.ts.map +1 -0
  225. package/lib-es/__tests__/logic/combine.unit.test.js +45 -0
  226. package/lib-es/__tests__/logic/combine.unit.test.js.map +1 -0
  227. package/lib-es/__tests__/logic/compareAddress.unit.test.d.ts +2 -0
  228. package/lib-es/__tests__/logic/compareAddress.unit.test.d.ts.map +1 -0
  229. package/lib-es/__tests__/logic/compareAddress.unit.test.js +24 -0
  230. package/lib-es/__tests__/logic/compareAddress.unit.test.js.map +1 -0
  231. package/lib-es/__tests__/logic/createTransaction.test.d.ts.map +1 -0
  232. package/lib-es/__tests__/{bridge → logic}/createTransaction.test.js +2 -2
  233. package/lib-es/__tests__/logic/createTransaction.test.js.map +1 -0
  234. package/lib-es/__tests__/logic/getCoinAndAmounts.unit.test.d.ts +2 -0
  235. package/lib-es/__tests__/logic/getCoinAndAmounts.unit.test.d.ts.map +1 -0
  236. package/lib-es/__tests__/logic/getCoinAndAmounts.unit.test.js +181 -0
  237. package/lib-es/__tests__/logic/getCoinAndAmounts.unit.test.js.map +1 -0
  238. package/lib-es/__tests__/logic/getFunctionAddress.unit.test.d.ts +2 -0
  239. package/lib-es/__tests__/logic/getFunctionAddress.unit.test.d.ts.map +1 -0
  240. package/lib-es/__tests__/logic/getFunctionAddress.unit.test.js +27 -0
  241. package/lib-es/__tests__/logic/getFunctionAddress.unit.test.js.map +1 -0
  242. package/lib-es/__tests__/logic/getResourceAddress.unit.test.d.ts +2 -0
  243. package/lib-es/__tests__/logic/getResourceAddress.unit.test.d.ts.map +1 -0
  244. package/lib-es/__tests__/logic/getResourceAddress.unit.test.js +216 -0
  245. package/lib-es/__tests__/logic/getResourceAddress.unit.test.js.map +1 -0
  246. package/lib-es/__tests__/logic/isTestnet.unit.test.d.ts +2 -0
  247. package/lib-es/__tests__/logic/isTestnet.unit.test.d.ts.map +1 -0
  248. package/lib-es/__tests__/logic/isTestnet.unit.test.js +10 -0
  249. package/lib-es/__tests__/logic/isTestnet.unit.test.js.map +1 -0
  250. package/lib-es/__tests__/logic/processRecipients.unit.test.d.ts +2 -0
  251. package/lib-es/__tests__/logic/processRecipients.unit.test.d.ts.map +1 -0
  252. package/lib-es/__tests__/logic/processRecipients.unit.test.js +74 -0
  253. package/lib-es/__tests__/logic/processRecipients.unit.test.js.map +1 -0
  254. package/lib-es/__tests__/network/client.test.d.ts +2 -0
  255. package/lib-es/__tests__/network/client.test.d.ts.map +1 -0
  256. package/lib-es/__tests__/network/client.test.js +987 -0
  257. package/lib-es/__tests__/network/client.test.js.map +1 -0
  258. package/lib-es/api/index.d.ts +4 -33
  259. package/lib-es/api/index.d.ts.map +1 -1
  260. package/lib-es/api/index.js +17 -194
  261. package/lib-es/api/index.js.map +1 -1
  262. package/lib-es/bridge/broadcast.d.ts +3 -2
  263. package/lib-es/bridge/broadcast.d.ts.map +1 -1
  264. package/lib-es/bridge/broadcast.js +4 -3
  265. package/lib-es/bridge/broadcast.js.map +1 -1
  266. package/lib-es/bridge/estimateMaxSpendable.d.ts.map +1 -1
  267. package/lib-es/bridge/estimateMaxSpendable.js +3 -2
  268. package/lib-es/bridge/estimateMaxSpendable.js.map +1 -1
  269. package/lib-es/bridge/getFeesForTransaction.d.ts +1 -1
  270. package/lib-es/bridge/getFeesForTransaction.d.ts.map +1 -1
  271. package/lib-es/bridge/getFeesForTransaction.js +3 -2
  272. package/lib-es/bridge/getFeesForTransaction.js.map +1 -1
  273. package/lib-es/bridge/index.d.ts +1 -1
  274. package/lib-es/bridge/index.d.ts.map +1 -1
  275. package/lib-es/bridge/index.js +1 -1
  276. package/lib-es/bridge/index.js.map +1 -1
  277. package/lib-es/bridge/logic.d.ts +1 -20
  278. package/lib-es/bridge/logic.d.ts.map +1 -1
  279. package/lib-es/bridge/logic.js +6 -190
  280. package/lib-es/bridge/logic.js.map +1 -1
  281. package/lib-es/bridge/prepareTransaction.d.ts.map +1 -1
  282. package/lib-es/bridge/prepareTransaction.js +3 -2
  283. package/lib-es/bridge/prepareTransaction.js.map +1 -1
  284. package/lib-es/bridge/signOperation.d.ts.map +1 -1
  285. package/lib-es/bridge/signOperation.js +2 -2
  286. package/lib-es/bridge/signOperation.js.map +1 -1
  287. package/lib-es/bridge/synchronisation.js +1 -1
  288. package/lib-es/bridge/synchronisation.js.map +1 -1
  289. package/lib-es/config.d.ts +13 -0
  290. package/lib-es/config.d.ts.map +1 -0
  291. package/lib-es/config.js +4 -0
  292. package/lib-es/config.js.map +1 -0
  293. package/lib-es/constants.d.ts +5 -1
  294. package/lib-es/constants.d.ts.map +1 -1
  295. package/lib-es/constants.js +4 -0
  296. package/lib-es/constants.js.map +1 -1
  297. package/lib-es/{bridge → logic}/buildTransaction.d.ts +1 -1
  298. package/lib-es/logic/buildTransaction.d.ts.map +1 -0
  299. package/lib-es/{bridge → logic}/buildTransaction.js +1 -1
  300. package/lib-es/logic/buildTransaction.js.map +1 -0
  301. package/lib-es/logic/calculateAmount.d.ts +3 -0
  302. package/lib-es/logic/calculateAmount.d.ts.map +1 -0
  303. package/lib-es/logic/calculateAmount.js +9 -0
  304. package/lib-es/logic/calculateAmount.js.map +1 -0
  305. package/lib-es/logic/combine.d.ts +4 -0
  306. package/lib-es/logic/combine.d.ts.map +1 -0
  307. package/lib-es/logic/combine.js +29 -0
  308. package/lib-es/logic/combine.js.map +1 -0
  309. package/lib-es/logic/craftTransaction.d.ts +5 -0
  310. package/lib-es/logic/craftTransaction.d.ts.map +1 -0
  311. package/lib-es/logic/craftTransaction.js +16 -0
  312. package/lib-es/logic/craftTransaction.js.map +1 -0
  313. package/lib-es/logic/createTransaction.d.ts.map +1 -0
  314. package/lib-es/{bridge → logic}/createTransaction.js +1 -1
  315. package/lib-es/logic/createTransaction.js.map +1 -0
  316. package/lib-es/logic/getBalance.d.ts +5 -0
  317. package/lib-es/logic/getBalance.d.ts.map +1 -0
  318. package/lib-es/logic/getBalance.js +8 -0
  319. package/lib-es/logic/getBalance.js.map +1 -0
  320. package/lib-es/logic/getCoinAndAmounts.d.ts +13 -0
  321. package/lib-es/logic/getCoinAndAmounts.d.ts.map +1 -0
  322. package/lib-es/logic/getCoinAndAmounts.js +101 -0
  323. package/lib-es/logic/getCoinAndAmounts.js.map +1 -0
  324. package/lib-es/logic/getFunctionAddress.d.ts +3 -0
  325. package/lib-es/logic/getFunctionAddress.d.ts.map +1 -0
  326. package/lib-es/logic/getFunctionAddress.js +8 -0
  327. package/lib-es/logic/getFunctionAddress.js.map +1 -0
  328. package/lib-es/logic/getResourceAddress.d.ts +4 -0
  329. package/lib-es/logic/getResourceAddress.d.ts.map +1 -0
  330. package/lib-es/logic/getResourceAddress.js +13 -0
  331. package/lib-es/logic/getResourceAddress.js.map +1 -0
  332. package/lib-es/logic/isTestnet.d.ts +2 -0
  333. package/lib-es/logic/isTestnet.d.ts.map +1 -0
  334. package/lib-es/logic/isTestnet.js +5 -0
  335. package/lib-es/logic/isTestnet.js.map +1 -0
  336. package/lib-es/logic/isWriteSetChangeWriteResource.d.ts +3 -0
  337. package/lib-es/logic/isWriteSetChangeWriteResource.d.ts.map +1 -0
  338. package/lib-es/logic/isWriteSetChangeWriteResource.js +4 -0
  339. package/lib-es/logic/isWriteSetChangeWriteResource.js.map +1 -0
  340. package/lib-es/logic/normalizeTransactionOptions.d.ts +3 -0
  341. package/lib-es/logic/normalizeTransactionOptions.d.ts.map +1 -0
  342. package/lib-es/logic/normalizeTransactionOptions.js +17 -0
  343. package/lib-es/logic/normalizeTransactionOptions.js.map +1 -0
  344. package/lib-es/logic/processRecipients.d.ts +6 -0
  345. package/lib-es/logic/processRecipients.d.ts.map +1 -0
  346. package/lib-es/logic/processRecipients.js +53 -0
  347. package/lib-es/logic/processRecipients.js.map +1 -0
  348. package/lib-es/logic/transactionsToOperations.d.ts +7 -0
  349. package/lib-es/logic/transactionsToOperations.d.ts.map +1 -0
  350. package/lib-es/logic/transactionsToOperations.js +77 -0
  351. package/lib-es/logic/transactionsToOperations.js.map +1 -0
  352. package/lib-es/network/client.d.ts +38 -0
  353. package/lib-es/network/client.d.ts.map +1 -0
  354. package/lib-es/network/client.js +259 -0
  355. package/lib-es/network/client.js.map +1 -0
  356. package/lib-es/network/graphql/queries.d.ts.map +1 -0
  357. package/lib-es/network/graphql/queries.js.map +1 -0
  358. package/lib-es/network/graphql/types.d.ts.map +1 -0
  359. package/lib-es/{api → network}/graphql/types.js.map +1 -1
  360. package/lib-es/network/index.d.ts +2 -1
  361. package/lib-es/network/index.d.ts.map +1 -1
  362. package/lib-es/network/index.js +6 -8
  363. package/lib-es/network/index.js.map +1 -1
  364. package/lib-es/types/assets.d.ts +12 -0
  365. package/lib-es/types/assets.d.ts.map +1 -0
  366. package/lib-es/types/assets.js +2 -0
  367. package/lib-es/types/assets.js.map +1 -0
  368. package/lib-es/types/index.d.ts +4 -0
  369. package/lib-es/types/index.d.ts.map +1 -1
  370. package/package.json +9 -8
  371. package/src/__tests__/api/craftTransaction.unit.test.ts +70 -0
  372. package/src/__tests__/api/getBalance.unit.test.ts +44 -0
  373. package/src/__tests__/api/index.integ.test.ts +139 -0
  374. package/src/__tests__/api/index.test.ts +60 -547
  375. package/src/__tests__/bridge/broadcast.test.ts +2 -2
  376. package/src/__tests__/bridge/getFeesForTransaction.test.ts +2 -2
  377. package/src/__tests__/bridge/logic.test.ts +4 -649
  378. package/src/__tests__/bridge/prepareTransaction.test.ts +2 -2
  379. package/src/__tests__/bridge/signOperation.test.ts +12 -13
  380. package/src/__tests__/bridge/synchronisation.test.ts +4 -4
  381. package/src/__tests__/index.test.ts +1 -1
  382. package/src/__tests__/{bridge → logic}/buildTransaction.test.ts +12 -7
  383. package/src/__tests__/logic/calculateAmount.unit.test.ts +51 -0
  384. package/src/__tests__/logic/combine.unit.test.ts +65 -0
  385. package/src/__tests__/logic/compareAddress.unit.test.ts +27 -0
  386. package/src/__tests__/{bridge → logic}/createTransaction.test.ts +2 -2
  387. package/src/__tests__/logic/getCoinAndAmounts.unit.test.ts +195 -0
  388. package/src/__tests__/logic/getFunctionAddress.unit.test.ts +33 -0
  389. package/src/__tests__/logic/getResourceAddress.unit.test.ts +241 -0
  390. package/src/__tests__/logic/isTestnet.unit.test.ts +11 -0
  391. package/src/__tests__/logic/processRecipients.unit.test.ts +87 -0
  392. package/src/__tests__/network/client.test.ts +1107 -0
  393. package/src/api/index.ts +29 -251
  394. package/src/bridge/broadcast.ts +7 -7
  395. package/src/bridge/estimateMaxSpendable.ts +3 -2
  396. package/src/bridge/getFeesForTransaction.ts +4 -3
  397. package/src/bridge/index.ts +2 -2
  398. package/src/bridge/logic.ts +8 -283
  399. package/src/bridge/prepareTransaction.ts +4 -2
  400. package/src/bridge/signOperation.ts +2 -2
  401. package/src/bridge/synchronisation.ts +1 -1
  402. package/src/config.ts +19 -0
  403. package/src/constants.ts +6 -1
  404. package/src/{bridge → logic}/buildTransaction.ts +2 -2
  405. package/src/logic/calculateAmount.ts +15 -0
  406. package/src/logic/combine.ts +51 -0
  407. package/src/logic/craftTransaction.ts +26 -0
  408. package/src/{bridge → logic}/createTransaction.ts +1 -1
  409. package/src/logic/getBalance.ts +15 -0
  410. package/src/logic/getCoinAndAmounts.ts +141 -0
  411. package/src/logic/getFunctionAddress.ts +9 -0
  412. package/src/logic/getResourceAddress.ts +24 -0
  413. package/src/logic/isTestnet.ts +5 -0
  414. package/src/logic/isWriteSetChangeWriteResource.ts +7 -0
  415. package/src/logic/normalizeTransactionOptions.ts +18 -0
  416. package/src/logic/processRecipients.ts +87 -0
  417. package/src/logic/transactionsToOperations.ts +105 -0
  418. package/src/network/client.ts +351 -0
  419. package/src/network/index.ts +6 -14
  420. package/src/types/assets.ts +15 -0
  421. package/src/types/index.ts +5 -0
  422. package/lib/__tests__/bridge/buildTransaction.test.d.ts.map +0 -1
  423. package/lib/__tests__/bridge/buildTransaction.test.js.map +0 -1
  424. package/lib/__tests__/bridge/createTransaction.test.d.ts.map +0 -1
  425. package/lib/__tests__/bridge/createTransaction.test.js.map +0 -1
  426. package/lib/api/graphql/queries.d.ts.map +0 -1
  427. package/lib/api/graphql/queries.js.map +0 -1
  428. package/lib/api/graphql/types.d.ts.map +0 -1
  429. package/lib/bridge/buildTransaction.d.ts.map +0 -1
  430. package/lib/bridge/buildTransaction.js.map +0 -1
  431. package/lib/bridge/createTransaction.d.ts.map +0 -1
  432. package/lib/bridge/createTransaction.js.map +0 -1
  433. package/lib-es/__tests__/bridge/buildTransaction.test.d.ts.map +0 -1
  434. package/lib-es/__tests__/bridge/buildTransaction.test.js.map +0 -1
  435. package/lib-es/__tests__/bridge/createTransaction.test.d.ts.map +0 -1
  436. package/lib-es/__tests__/bridge/createTransaction.test.js.map +0 -1
  437. package/lib-es/api/graphql/queries.d.ts.map +0 -1
  438. package/lib-es/api/graphql/queries.js.map +0 -1
  439. package/lib-es/api/graphql/types.d.ts.map +0 -1
  440. package/lib-es/bridge/buildTransaction.d.ts.map +0 -1
  441. package/lib-es/bridge/buildTransaction.js.map +0 -1
  442. package/lib-es/bridge/createTransaction.d.ts.map +0 -1
  443. package/lib-es/bridge/createTransaction.js.map +0 -1
  444. /package/lib/__tests__/{bridge → logic}/buildTransaction.test.d.ts +0 -0
  445. /package/lib/__tests__/{bridge → logic}/createTransaction.test.d.ts +0 -0
  446. /package/lib/{bridge → logic}/createTransaction.d.ts +0 -0
  447. /package/lib/{api → network}/graphql/queries.d.ts +0 -0
  448. /package/lib/{api → network}/graphql/queries.js +0 -0
  449. /package/lib/{api → network}/graphql/types.d.ts +0 -0
  450. /package/lib/{api → network}/graphql/types.js +0 -0
  451. /package/lib-es/__tests__/{bridge → logic}/buildTransaction.test.d.ts +0 -0
  452. /package/lib-es/__tests__/{bridge → logic}/createTransaction.test.d.ts +0 -0
  453. /package/lib-es/{bridge → logic}/createTransaction.d.ts +0 -0
  454. /package/lib-es/{api → network}/graphql/queries.d.ts +0 -0
  455. /package/lib-es/{api → network}/graphql/queries.js +0 -0
  456. /package/lib-es/{api → network}/graphql/types.d.ts +0 -0
  457. /package/lib-es/{api → network}/graphql/types.js +0 -0
  458. /package/src/{api → network}/graphql/queries.ts +0 -0
  459. /package/src/{api → network}/graphql/types.ts +0 -0
package/src/api/index.ts CHANGED
@@ -1,252 +1,30 @@
1
- import { ApolloClient, InMemoryCache } from "@apollo/client";
2
-
3
- import {
4
- AccountData,
5
- Aptos,
6
- AptosApiType,
7
- AptosConfig,
8
- Ed25519PublicKey,
9
- GasEstimation,
10
- InputEntryFunctionData,
11
- InputGenerateTransactionOptions,
12
- MimeType,
13
- post,
14
- RawTransaction,
15
- SimpleTransaction,
16
- TransactionResponse,
17
- UserTransactionResponse,
18
- PostRequestOptions,
19
- Block,
20
- } from "@aptos-labs/ts-sdk";
21
- import { getEnv } from "@ledgerhq/live-env";
22
- import network from "@ledgerhq/live-network";
23
- import BigNumber from "bignumber.js";
24
- import isUndefined from "lodash/isUndefined";
25
- import { APTOS_ASSET_ID } from "../constants";
26
- import { isTestnet } from "../bridge/logic";
27
- import type { AptosTransaction, TransactionOptions } from "../types";
28
- import { GetAccountTransactionsData, GetAccountTransactionsDataGt } from "./graphql/queries";
29
- import {
30
- GetAccountTransactionsDataQuery,
31
- GetAccountTransactionsDataGtQueryVariables,
32
- } from "./graphql/types";
33
- import { TokenCurrency } from "@ledgerhq/types-cryptoassets";
34
-
35
- const getApiEndpoint = (currencyId: string) =>
36
- isTestnet(currencyId) ? getEnv("APTOS_TESTNET_API_ENDPOINT") : getEnv("APTOS_API_ENDPOINT");
37
- const getIndexerEndpoint = (currencyId: string) =>
38
- isTestnet(currencyId)
39
- ? getEnv("APTOS_TESTNET_INDEXER_ENDPOINT")
40
- : getEnv("APTOS_INDEXER_ENDPOINT");
41
-
42
- export class AptosAPI {
43
- private apiUrl: string;
44
- private indexerUrl: string;
45
- private aptosConfig: AptosConfig;
46
- private aptosClient: Aptos;
47
- private apolloClient: ApolloClient<object>;
48
-
49
- constructor(currencyId: string) {
50
- this.apiUrl = getApiEndpoint(currencyId);
51
- this.indexerUrl = getIndexerEndpoint(currencyId);
52
- this.aptosConfig = new AptosConfig({
53
- fullnode: this.apiUrl,
54
- indexer: this.indexerUrl,
55
- });
56
- this.aptosClient = new Aptos(this.aptosConfig);
57
- this.apolloClient = new ApolloClient({
58
- uri: this.indexerUrl,
59
- cache: new InMemoryCache(),
60
- headers: {
61
- "x-client": "ledger-live",
62
- },
63
- });
64
- }
65
-
66
- async getAccount(address: string): Promise<AccountData> {
67
- return this.aptosClient.getAccountInfo({ accountAddress: address });
68
- }
69
-
70
- async getAccountInfo(address: string, startAt?: string) {
71
- const [balance, transactions, blockHeight] = await Promise.all([
72
- this.getCoinBalance(address, APTOS_ASSET_ID),
73
- this.fetchTransactions(address, startAt),
74
- this.getHeight(),
75
- ]);
76
-
77
- return {
78
- balance,
79
- transactions,
80
- blockHeight,
81
- };
82
- }
83
-
84
- async estimateGasPrice(): Promise<GasEstimation> {
85
- return this.aptosClient.getGasPriceEstimation();
86
- }
87
-
88
- async generateTransaction(
89
- address: string,
90
- payload: InputEntryFunctionData,
91
- options: TransactionOptions,
92
- ): Promise<RawTransaction> {
93
- const opts: Partial<InputGenerateTransactionOptions> = {};
94
- if (!isUndefined(options.maxGasAmount)) {
95
- opts.maxGasAmount = Number(options.maxGasAmount);
96
- }
97
-
98
- if (!isUndefined(options.gasUnitPrice)) {
99
- opts.gasUnitPrice = Number(options.gasUnitPrice);
100
- }
101
-
102
- try {
103
- const { ledger_timestamp } = await this.aptosClient.getLedgerInfo();
104
- opts.expireTimestamp = Number(Math.ceil(+ledger_timestamp / 1_000_000 + 2 * 60)); // in milliseconds
105
- } catch {
106
- // skip
107
- }
108
-
109
- return this.aptosClient.transaction.build
110
- .simple({
111
- sender: address,
112
- data: payload,
113
- options: opts,
114
- })
115
- .then(t => t.rawTransaction)
116
- .catch(error => {
117
- throw error;
118
- });
119
- }
120
-
121
- async simulateTransaction(
122
- address: Ed25519PublicKey,
123
- tx: RawTransaction,
124
- options = {
125
- estimateGasUnitPrice: true,
126
- estimateMaxGasAmount: true,
127
- estimatePrioritizedGasUnitPrice: false,
128
- },
129
- ): Promise<UserTransactionResponse[]> {
130
- return this.aptosClient.transaction.simulate.simple({
131
- signerPublicKey: address,
132
- transaction: { rawTransaction: tx } as SimpleTransaction,
133
- options,
134
- });
135
- }
136
-
137
- async broadcast(signature: string): Promise<string> {
138
- const txBytes = Uint8Array.from(Buffer.from(signature, "hex"));
139
- const pendingTx = await post<PostRequestOptions, TransactionResponse>({
140
- contentType: MimeType.BCS_SIGNED_TRANSACTION,
141
- aptosConfig: this.aptosClient.config,
142
- body: txBytes,
143
- path: "transactions",
144
- type: AptosApiType.FULLNODE,
145
- originMethod: "",
146
- });
147
- return pendingTx.data.hash;
148
- }
149
-
150
- async getBalance(address: string, token: TokenCurrency): Promise<BigNumber> {
151
- let balance = new BigNumber(0);
152
- if (token.tokenType === "coin") {
153
- balance = await this.getCoinBalance(address, token.contractAddress);
154
- } else {
155
- balance = await this.getFABalance(address, token.contractAddress);
156
- }
157
- return balance;
158
- }
159
-
160
- async getCoinBalance(address: string, contract_address: string): Promise<BigNumber> {
161
- try {
162
- const [balanceStr] = await this.aptosClient.view<[string]>({
163
- payload: {
164
- function: "0x1::coin::balance",
165
- typeArguments: [contract_address],
166
- functionArguments: [address],
167
- },
168
- });
169
- const balance = parseInt(balanceStr, 10);
170
- return new BigNumber(balance);
171
- } catch (_) {
172
- return new BigNumber(0);
173
- }
174
- }
175
-
176
- async getFABalance(address: string, contract_address: string): Promise<BigNumber> {
177
- try {
178
- const [balanceStr] = await this.aptosClient.view<[string]>({
179
- payload: {
180
- function: "0x1::primary_fungible_store::balance",
181
- typeArguments: ["0x1::object::ObjectCore"],
182
- functionArguments: [address, contract_address],
183
- },
184
- });
185
- const balance = parseInt(balanceStr, 10);
186
- return new BigNumber(balance);
187
- } catch (_) {
188
- return new BigNumber(0);
189
- }
190
- }
191
-
192
- private async fetchTransactions(address: string, gt?: string) {
193
- if (!address) {
194
- return [];
195
- }
196
-
197
- let query = GetAccountTransactionsData;
198
- if (gt) {
199
- query = GetAccountTransactionsDataGt;
200
- }
201
-
202
- const queryResponse = await this.apolloClient.query<
203
- GetAccountTransactionsDataQuery,
204
- GetAccountTransactionsDataGtQueryVariables
205
- >({
206
- query,
207
- variables: {
208
- address,
209
- limit: 1000,
210
- gt,
211
- },
212
- fetchPolicy: "network-only",
213
- });
214
-
215
- return Promise.all(
216
- queryResponse.data.account_transactions.map(({ transaction_version }) => {
217
- return this.richItemByVersion(transaction_version);
218
- }),
219
- );
220
- }
221
-
222
- private async richItemByVersion(version: number): Promise<AptosTransaction | null> {
223
- try {
224
- const tx: TransactionResponse = await this.aptosClient.getTransactionByVersion({
225
- ledgerVersion: version,
226
- });
227
- const block = await this.getBlock(version);
228
- return {
229
- ...tx,
230
- block,
231
- } as AptosTransaction;
232
- } catch (error) {
233
- return null;
234
- }
235
- }
236
-
237
- private async getHeight(): Promise<number> {
238
- const { data } = await network<Block>({
239
- method: "GET",
240
- url: this.apiUrl,
241
- });
242
- return parseInt(data.block_height);
243
- }
244
-
245
- private async getBlock(version: number) {
246
- const block = await this.aptosClient.getBlockByVersion({ ledgerVersion: version });
247
- return {
248
- height: parseInt(block.block_height),
249
- hash: block.block_hash,
250
- };
251
- }
1
+ import type { Api } from "@ledgerhq/coin-framework/api/index";
2
+ import type { AptosConfig as AptosConfigApi } from "../config";
3
+ import type { Balance, Pagination, TransactionIntent } from "@ledgerhq/coin-framework/api/types";
4
+ import coinConfig from "../config";
5
+ import type { AptosAsset, AptosExtra, AptosFeeParameters, AptosSender } from "../types/assets";
6
+ import { AptosAPI } from "../network";
7
+ import { combine } from "../logic/combine";
8
+ import { craftTransaction } from "../logic/craftTransaction";
9
+ import { getBalance } from "../logic/getBalance";
10
+
11
+ export function createApi(
12
+ config: AptosConfigApi,
13
+ ): Api<AptosAsset, AptosExtra, AptosSender, AptosFeeParameters> {
14
+ coinConfig.setCoinConfig(() => ({ ...config, status: { type: "active" } }));
15
+
16
+ const client = new AptosAPI(config.aptosSettings);
17
+
18
+ return {
19
+ broadcast: (tx: string) => client.broadcast(tx),
20
+ combine: (tx, signature, pubkey): string => combine(tx, signature, pubkey),
21
+ craftTransaction: (transactionIntent, _customFees): Promise<string> =>
22
+ craftTransaction(client, transactionIntent),
23
+ estimateFees: (transactionIntent: TransactionIntent<AptosAsset, AptosExtra, AptosSender>) =>
24
+ client.estimateFees(transactionIntent),
25
+ getBalance: (address): Promise<Balance<AptosAsset>[]> => getBalance(client, address),
26
+ lastBlock: () => client.getLastBlock(),
27
+ listOperations: (address: string, pagination: Pagination) =>
28
+ client.listOperations(address, pagination),
29
+ };
252
30
  }
@@ -1,16 +1,16 @@
1
1
  import type { Account, Operation, SignedOperation } from "@ledgerhq/types-live";
2
2
  import { patchOperationWithHash } from "@ledgerhq/coin-framework/operation";
3
- import { AptosAPI } from "../api";
3
+ import { AptosAPI } from "../network";
4
4
 
5
- const broadcast = async ({
6
- signedOperation,
7
- account,
8
- }: {
5
+ type broadcastFunc = {
9
6
  signedOperation: SignedOperation;
10
7
  account: Account;
11
- }): Promise<Operation> => {
8
+ };
9
+
10
+ const broadcast = async ({ signedOperation, account }: broadcastFunc): Promise<Operation> => {
12
11
  const { signature, operation } = signedOperation;
13
- const hash = await new AptosAPI(account.currency.id).broadcast(signature);
12
+ const client = new AptosAPI(account.currency.id);
13
+ const hash = await client.broadcast(signature);
14
14
  return patchOperationWithHash(operation, hash);
15
15
  };
16
16
 
@@ -1,10 +1,11 @@
1
1
  import type { Account, AccountLike } from "@ledgerhq/types-live";
2
2
  import { BigNumber } from "bignumber.js";
3
3
  import { getMainAccount } from "@ledgerhq/coin-framework/account/index";
4
- import { AptosAPI } from "../api";
4
+ import { AptosAPI } from "../network";
5
5
  import { getEstimatedGas } from "./getFeesForTransaction";
6
- import { DEFAULT_GAS, DEFAULT_GAS_PRICE, getMaxSendBalance } from "./logic";
6
+ import { getMaxSendBalance } from "./logic";
7
7
  import type { Transaction } from "../types";
8
+ import { DEFAULT_GAS, DEFAULT_GAS_PRICE } from "../constants";
8
9
 
9
10
  const estimateMaxSpendable = async ({
10
11
  account,
@@ -3,10 +3,11 @@ import { log } from "@ledgerhq/logs";
3
3
  import type { Account } from "@ledgerhq/types-live";
4
4
  import BigNumber from "bignumber.js";
5
5
  import { makeLRUCache, seconds } from "@ledgerhq/live-network/cache";
6
- import { AptosAPI } from "../api";
7
- import buildTransaction from "./buildTransaction";
8
- import { DEFAULT_GAS, DEFAULT_GAS_PRICE, ESTIMATE_GAS_MUL, getTokenAccount } from "./logic";
6
+ import { AptosAPI } from "../network";
7
+ import { getTokenAccount } from "./logic";
8
+ import { DEFAULT_GAS, DEFAULT_GAS_PRICE, ESTIMATE_GAS_MUL } from "../constants";
9
9
  import type { Transaction, TransactionErrors } from "../types";
10
+ import buildTransaction from "../logic/buildTransaction";
10
11
 
11
12
  type IGetEstimatedGasReturnType = {
12
13
  fees: BigNumber;
@@ -6,17 +6,17 @@ import {
6
6
  updateTransaction,
7
7
  } from "@ledgerhq/coin-framework/bridge/jsHelpers";
8
8
  import getAddressWrapper from "@ledgerhq/coin-framework/bridge/getAddressWrapper";
9
- import { SignerContext } from "@ledgerhq/coin-framework/signer";
9
+ import type { SignerContext } from "@ledgerhq/coin-framework/signer";
10
10
  import type { Account, AccountBridge, CurrencyBridge } from "@ledgerhq/types-live";
11
11
  import resolver from "../signer";
12
12
  import type { Transaction, TransactionStatus, AptosSigner } from "../types";
13
13
  import getTransactionStatus from "./getTransactionStatus";
14
14
  import estimateMaxSpendable from "./estimateMaxSpendable";
15
15
  import prepareTransaction from "./prepareTransaction";
16
- import createTransaction from "./createTransaction";
17
16
  import { getAccountShape } from "./synchronisation";
18
17
  import buildSignOperation from "./signOperation";
19
18
  import broadcast from "./broadcast";
19
+ import createTransaction from "../logic/createTransaction";
20
20
 
21
21
  function buildCurrencyBridge(signerContext: SignerContext<AptosSigner>): CurrencyBridge {
22
22
  const getAddress = resolver(signerContext);
@@ -1,12 +1,4 @@
1
- import {
2
- EntryFunctionPayloadResponse,
3
- Event,
4
- InputEntryFunctionData,
5
- MoveResource,
6
- WriteSetChange,
7
- WriteSetChangeWriteResource,
8
- } from "@aptos-labs/ts-sdk";
9
- import { getCryptoCurrencyById } from "@ledgerhq/cryptoassets/currencies";
1
+ import { EntryFunctionPayloadResponse } from "@aptos-labs/ts-sdk";
10
2
  import type { Account, Operation, OperationType, TokenAccount } from "@ledgerhq/types-live";
11
3
  import {
12
4
  decodeTokenAccountId,
@@ -16,35 +8,14 @@ import {
16
8
  } from "@ledgerhq/coin-framework/account/index";
17
9
  import BigNumber from "bignumber.js";
18
10
  import { encodeOperationId } from "@ledgerhq/coin-framework/operation";
19
- import {
20
- APTOS_ASSET_ID,
21
- APTOS_FUNGIBLE_STORE,
22
- BATCH_TRANSFER_TYPES,
23
- DELEGATION_POOL_TYPES,
24
- DIRECTION,
25
- COIN_TRANSFER_TYPES,
26
- FA_TRANSFER_TYPES,
27
- APTOS_OBJECT_CORE,
28
- } from "../constants";
29
- import type {
30
- AptosFungibleoObjectCoreResourceData,
31
- AptosFungibleStoreResourceData,
32
- AptosMoveResource,
33
- AptosTransaction,
34
- Transaction,
35
- TransactionOptions,
36
- } from "../types";
11
+ import { APTOS_ASSET_ID, DIRECTION } from "../constants";
12
+ import type { AptosTransaction, Transaction } from "../types";
37
13
  import { findTokenByAddressInCurrency } from "@ledgerhq/cryptoassets";
38
-
39
- export const DEFAULT_GAS = new BigNumber(200);
40
- export const DEFAULT_GAS_PRICE = new BigNumber(100);
41
- export const ESTIMATE_GAS_MUL = new BigNumber(1.0); // define buffer for gas estimation change here, if needed
42
-
43
- const CLEAN_HEX_REGEXP = /^0x0*|^0+/;
44
-
45
- export function isTestnet(currencyId: string): boolean {
46
- return getCryptoCurrencyById(currencyId).isTestnetFor ? true : false;
47
- }
14
+ import { convertFunctionPayloadResponseToInputEntryFunctionData } from "../logic/transactionsToOperations";
15
+ import { compareAddress, getCoinAndAmounts } from "../logic/getCoinAndAmounts";
16
+ import { calculateAmount } from "../logic/calculateAmount";
17
+ import { processRecipients } from "../logic/processRecipients";
18
+ import { getFunctionAddress } from "../logic/getFunctionAddress";
48
19
 
49
20
  export const getMaxSendBalance = (
50
21
  gas: BigNumber,
@@ -64,23 +35,6 @@ export const getMaxSendBalance = (
64
35
  : new BigNumber(0);
65
36
  };
66
37
 
67
- export function normalizeTransactionOptions(options: TransactionOptions): TransactionOptions {
68
- // FIXME: this is wrong. TransactionOptions is
69
- // {
70
- // maxGasAmount: string;
71
- // gasUnitPrice: string;
72
- // sequenceNumber?: string;
73
- // expirationTimestampSecs?: string;
74
- // }
75
- // meaning we can't return undefined in check method.
76
- // This method is useless, not deleting as it breaks code and this iteration is coin modularisation.
77
- const check = (v: any) => ((v ?? "").toString().trim() ? v : undefined);
78
- return {
79
- maxGasAmount: check(options.maxGasAmount),
80
- gasUnitPrice: check(options.gasUnitPrice),
81
- };
82
- }
83
-
84
38
  export const getBlankOperation = (
85
39
  tx: AptosTransaction,
86
40
  id: string,
@@ -101,14 +55,6 @@ export const getBlankOperation = (
101
55
  hasFailed: false,
102
56
  });
103
57
 
104
- const convertFunctionPayloadResponseToInputEntryFunctionData = (
105
- payload: EntryFunctionPayloadResponse,
106
- ): InputEntryFunctionData => ({
107
- function: payload.function,
108
- typeArguments: payload.type_arguments,
109
- functionArguments: payload.arguments,
110
- });
111
-
112
58
  export const txsToOps = (
113
59
  info: { address: string },
114
60
  id: string,
@@ -173,227 +119,6 @@ export const txsToOps = (
173
119
  return [ops, opsTokens];
174
120
  };
175
121
 
176
- export function compareAddress(addressA: string, addressB: string) {
177
- return (
178
- addressA.replace(CLEAN_HEX_REGEXP, "").toLowerCase() ===
179
- addressB.replace(CLEAN_HEX_REGEXP, "").toLowerCase()
180
- );
181
- }
182
-
183
- export function getFunctionAddress(payload: InputEntryFunctionData): string | undefined {
184
- if (payload.function) {
185
- const parts = payload.function.split("::");
186
- return parts.length === 3 && parts[0].length ? parts[0] : undefined;
187
- }
188
- return undefined;
189
- }
190
-
191
- export function processRecipients(
192
- payload: InputEntryFunctionData,
193
- address: string,
194
- op: Operation,
195
- function_address: string,
196
- ): void {
197
- // get recipients buy 3 groups
198
- if (
199
- (COIN_TRANSFER_TYPES.includes(payload.function) ||
200
- DELEGATION_POOL_TYPES.includes(payload.function)) &&
201
- payload.functionArguments &&
202
- payload.functionArguments.length > 0 &&
203
- typeof payload.functionArguments[0] === "string"
204
- ) {
205
- // 1. Transfer like functions (includes some delegation pool functions)
206
- op.recipients.push(payload.functionArguments[0].toString());
207
- } else if (
208
- FA_TRANSFER_TYPES.includes(payload.function) &&
209
- payload.functionArguments &&
210
- payload.functionArguments.length > 1 &&
211
- typeof payload.functionArguments[0] === "object" &&
212
- typeof payload.functionArguments[1] === "string"
213
- ) {
214
- // 1. Transfer like functions (includes some delegation pool functions)
215
- op.recipients.push(payload.functionArguments[1].toString());
216
- } else if (
217
- BATCH_TRANSFER_TYPES.includes(payload.function) &&
218
- payload.functionArguments &&
219
- payload.functionArguments.length > 0 &&
220
- Array.isArray(payload.functionArguments[0])
221
- ) {
222
- // 2. Batch function, to validate we are in the recipients list
223
- if (!compareAddress(op.senders[0], address)) {
224
- for (const recipient of payload.functionArguments[0]) {
225
- if (recipient && compareAddress(recipient.toString(), address)) {
226
- op.recipients.push(recipient.toString());
227
- }
228
- }
229
- }
230
- } else {
231
- // 3. other smart contracts, in this case smart contract will be treated as a recipient
232
- op.recipients.push(function_address);
233
- }
234
- }
235
-
236
- export function getEventCoinAddress(
237
- change: WriteSetChangeWriteResource,
238
- event: Event,
239
- event_name: string,
240
- ): string | null {
241
- const change_data = change.data;
242
-
243
- const mr = change_data as MoveResource<AptosMoveResource>; // -> this is data that we want to parse
244
-
245
- if (!(event_name in mr.data)) {
246
- return null;
247
- }
248
-
249
- const change_event_data = mr.data[event_name];
250
- if (
251
- change_event_data.guid.id.addr !== event.guid.account_address ||
252
- change_event_data.guid.id.creation_num !== event.guid.creation_number
253
- ) {
254
- return null;
255
- }
256
-
257
- const address = extractAddress(mr.type);
258
-
259
- return address;
260
- }
261
-
262
- export function getEventFAAddress(
263
- change: WriteSetChangeWriteResource,
264
- event: Event,
265
- _event_name: string,
266
- ): string | null {
267
- const change_data = change.data;
268
-
269
- if (change_data.type !== APTOS_FUNGIBLE_STORE) {
270
- return null;
271
- }
272
-
273
- const mr = change_data as MoveResource<AptosFungibleStoreResourceData>;
274
-
275
- if (change.address !== event.data.store) {
276
- return null;
277
- }
278
-
279
- return mr.data.metadata.inner;
280
- }
281
-
282
- export function getResourceAddress(
283
- tx: AptosTransaction,
284
- event: Event,
285
- event_name: string,
286
- getAddressProcessor: (
287
- change: WriteSetChangeWriteResource,
288
- event: Event,
289
- event_name: string,
290
- ) => string | null,
291
- ): string | null {
292
- for (const change of tx.changes) {
293
- if (isWriteSetChangeWriteResource(change)) {
294
- const address = getAddressProcessor(change, event, event_name);
295
- if (address !== null) {
296
- return address;
297
- }
298
- }
299
- }
300
- return null;
301
- }
302
-
303
- function isWriteSetChangeWriteResource(
304
- change: WriteSetChange,
305
- ): change is WriteSetChangeWriteResource {
306
- return (change as WriteSetChangeWriteResource).data !== undefined;
307
- }
308
-
309
- export function checkFAOwner(tx: AptosTransaction, event: Event, user_address: string): boolean {
310
- for (const change of tx.changes) {
311
- if (isWriteSetChangeWriteResource(change)) {
312
- const storeData = change.data as MoveResource<AptosFungibleoObjectCoreResourceData>;
313
- if (
314
- change.address == event.data.store &&
315
- storeData.type == APTOS_OBJECT_CORE &&
316
- storeData.data.owner == user_address
317
- ) {
318
- return true;
319
- }
320
- }
321
- }
322
- return false;
323
- }
324
-
325
- export function getCoinAndAmounts(
326
- tx: AptosTransaction,
327
- address: string,
328
- ): { coin_id: string | null; amount_in: BigNumber; amount_out: BigNumber } {
329
- let coin_id: string | null = null;
330
- let amount_in = BigNumber(0);
331
- let amount_out = BigNumber(0);
332
-
333
- // collect all events related to the address and calculate the overall amounts
334
- tx.events.forEach(event => {
335
- switch (event.type) {
336
- case "0x1::coin::WithdrawEvent":
337
- if (compareAddress(event.guid.account_address, address)) {
338
- coin_id = getResourceAddress(tx, event, "withdraw_events", getEventCoinAddress);
339
- amount_out = amount_out.plus(event.data.amount);
340
- }
341
- break;
342
- case "0x1::coin::DepositEvent":
343
- if (compareAddress(event.guid.account_address, address)) {
344
- coin_id = getResourceAddress(tx, event, "deposit_events", getEventCoinAddress);
345
- amount_in = amount_in.plus(event.data.amount);
346
- }
347
- break;
348
- case "0x1::fungible_asset::Withdraw":
349
- if (checkFAOwner(tx, event, address)) {
350
- coin_id = getResourceAddress(tx, event, "withdraw_events", getEventFAAddress);
351
- amount_out = amount_out.plus(event.data.amount);
352
- }
353
- break;
354
- case "0x1::fungible_asset::Deposit":
355
- if (checkFAOwner(tx, event, address)) {
356
- coin_id = getResourceAddress(tx, event, "deposit_events", getEventFAAddress);
357
- amount_in = amount_in.plus(event.data.amount);
358
- }
359
- break;
360
- case "0x1::transaction_fee::FeeStatement":
361
- if (tx.sender === address) {
362
- if (coin_id === null) coin_id = APTOS_ASSET_ID;
363
- if (coin_id === APTOS_ASSET_ID) {
364
- const fees = BigNumber(tx.gas_unit_price).times(BigNumber(tx.gas_used));
365
- amount_out = amount_out.plus(fees);
366
- }
367
- }
368
- break;
369
- }
370
- });
371
- return { coin_id, amount_in, amount_out }; // TODO: manage situation when there are several coinID from the events parsing
372
- }
373
-
374
- export function calculateAmount(
375
- sender: string,
376
- address: string,
377
- amount_in: BigNumber,
378
- amount_out: BigNumber,
379
- ): BigNumber {
380
- const is_sender: boolean = compareAddress(sender, address);
381
- // LL negates the amount for SEND transactions
382
- // to show positive amount on the send transaction (ex: in "cancel" tx, when amount will be returned to our account)
383
- // we need to make it negative
384
- return is_sender ? amount_out.minus(amount_in) : amount_in.minus(amount_out);
385
- }
386
-
387
- /**
388
- * Extracts the address from a string like "0x1::coin::CoinStore<address::module::type>"
389
- * @param {string} str - The input string containing the address.
390
- * @returns {string | null} - The extracted address or null if not found.
391
- */
392
- function extractAddress(str: string): string | null {
393
- const match = str.match(/<([^<>]+)>{1}$/);
394
- return match ? match[1] : null;
395
- }
396
-
397
122
  export function getTokenAccount(
398
123
  account: Account,
399
124
  transaction: Transaction,
@@ -1,9 +1,11 @@
1
1
  import type { Account } from "@ledgerhq/types-live";
2
2
  import BigNumber from "bignumber.js";
3
- import { AptosAPI } from "../api";
3
+
4
+ import { AptosAPI } from "../network";
4
5
  import { getEstimatedGas } from "./getFeesForTransaction";
5
6
  import type { Transaction } from "../types";
6
- import { DEFAULT_GAS, DEFAULT_GAS_PRICE, getMaxSendBalance } from "./logic";
7
+ import { getMaxSendBalance } from "./logic";
8
+ import { DEFAULT_GAS, DEFAULT_GAS_PRICE } from "../constants";
7
9
 
8
10
  const prepareTransaction = async (
9
11
  account: Account,