@ledgerhq/coin-aptos 2.5.1 → 2.5.2-nightly.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (315) hide show
  1. package/.turbo/turbo-build.log +1 -1
  2. package/.unimportedrc.json +5 -8
  3. package/CHANGELOG.md +18 -0
  4. package/lib/__tests__/bridge/deviceTransactionConfig.test.js +115 -30
  5. package/lib/__tests__/bridge/deviceTransactionConfig.test.js.map +1 -1
  6. package/lib/__tests__/bridge/getFeesForTransaction.test.js +10 -10
  7. package/lib/__tests__/bridge/getFeesForTransaction.test.js.map +1 -1
  8. package/lib/__tests__/bridge/getTransactionStatus.test.js +193 -2
  9. package/lib/__tests__/bridge/getTransactionStatus.test.js.map +1 -1
  10. package/lib/__tests__/bridge/index.test.js +4 -1
  11. package/lib/__tests__/bridge/index.test.js.map +1 -1
  12. package/lib/__tests__/bridge/logic.test.js +9 -9
  13. package/lib/__tests__/bridge/logic.test.js.map +1 -1
  14. package/lib/__tests__/bridge/prepareTransaction.test.js +1 -0
  15. package/lib/__tests__/bridge/prepareTransaction.test.js.map +1 -1
  16. package/lib/__tests__/bridge/serialization.d.ts +2 -0
  17. package/lib/__tests__/bridge/serialization.d.ts.map +1 -0
  18. package/lib/__tests__/bridge/serialization.js +91 -0
  19. package/lib/__tests__/bridge/serialization.js.map +1 -0
  20. package/lib/__tests__/bridge/synchronisation.test.js +763 -23
  21. package/lib/__tests__/bridge/synchronisation.test.js.map +1 -1
  22. package/lib/__tests__/logic/staking.test.d.ts +2 -0
  23. package/lib/__tests__/logic/staking.test.d.ts.map +1 -0
  24. package/lib/__tests__/logic/staking.test.js +202 -0
  25. package/lib/__tests__/logic/staking.test.js.map +1 -0
  26. package/lib/__tests__/network/client.test.js +3 -3
  27. package/lib/__tests__/network/validators.test.d.ts +2 -0
  28. package/lib/__tests__/network/validators.test.d.ts.map +1 -0
  29. package/lib/__tests__/network/validators.test.js +98 -0
  30. package/lib/__tests__/network/validators.test.js.map +1 -0
  31. package/lib/__tests__/utils/IconGenerator.test.d.ts +2 -0
  32. package/lib/__tests__/utils/IconGenerator.test.d.ts.map +1 -0
  33. package/lib/__tests__/utils/IconGenerator.test.js +14 -0
  34. package/lib/__tests__/utils/IconGenerator.test.js.map +1 -0
  35. package/lib/__tests__/utils/index.test.d.ts +2 -0
  36. package/lib/__tests__/utils/index.test.d.ts.map +1 -0
  37. package/lib/__tests__/utils/index.test.js +11 -0
  38. package/lib/__tests__/utils/index.test.js.map +1 -0
  39. package/lib/bridge/bridge.fixture.d.ts.map +1 -1
  40. package/lib/bridge/bridge.fixture.js +12 -0
  41. package/lib/bridge/bridge.fixture.js.map +1 -1
  42. package/lib/bridge/deviceTransactionConfig.d.ts +7 -8
  43. package/lib/bridge/deviceTransactionConfig.d.ts.map +1 -1
  44. package/lib/bridge/deviceTransactionConfig.js +83 -16
  45. package/lib/bridge/deviceTransactionConfig.js.map +1 -1
  46. package/lib/bridge/estimateMaxSpendable.d.ts +4 -4
  47. package/lib/bridge/estimateMaxSpendable.d.ts.map +1 -1
  48. package/lib/bridge/estimateMaxSpendable.js +1 -1
  49. package/lib/bridge/estimateMaxSpendable.js.map +1 -1
  50. package/lib/bridge/getFeesForTransaction.d.ts.map +1 -1
  51. package/lib/bridge/getFeesForTransaction.js +8 -4
  52. package/lib/bridge/getFeesForTransaction.js.map +1 -1
  53. package/lib/bridge/getTransactionStatus.d.ts +2 -3
  54. package/lib/bridge/getTransactionStatus.d.ts.map +1 -1
  55. package/lib/bridge/getTransactionStatus.js +139 -25
  56. package/lib/bridge/getTransactionStatus.js.map +1 -1
  57. package/lib/bridge/index.d.ts +3 -3
  58. package/lib/bridge/index.d.ts.map +1 -1
  59. package/lib/bridge/index.js +9 -2
  60. package/lib/bridge/index.js.map +1 -1
  61. package/lib/bridge/logic.d.ts +3 -3
  62. package/lib/bridge/logic.d.ts.map +1 -1
  63. package/lib/bridge/logic.js +23 -9
  64. package/lib/bridge/logic.js.map +1 -1
  65. package/lib/bridge/prepareTransaction.d.ts +2 -3
  66. package/lib/bridge/prepareTransaction.d.ts.map +1 -1
  67. package/lib/bridge/prepareTransaction.js +46 -10
  68. package/lib/bridge/prepareTransaction.js.map +1 -1
  69. package/lib/bridge/serialization.d.ts +7 -0
  70. package/lib/bridge/serialization.d.ts.map +1 -0
  71. package/lib/bridge/serialization.js +51 -0
  72. package/lib/bridge/serialization.js.map +1 -0
  73. package/lib/bridge/signOperation.d.ts.map +1 -1
  74. package/lib/bridge/signOperation.js +17 -5
  75. package/lib/bridge/signOperation.js.map +1 -1
  76. package/lib/bridge/synchronisation.d.ts +6 -4
  77. package/lib/bridge/synchronisation.d.ts.map +1 -1
  78. package/lib/bridge/synchronisation.js +51 -4
  79. package/lib/bridge/synchronisation.js.map +1 -1
  80. package/lib/constants.d.ts +25 -1
  81. package/lib/constants.d.ts.map +1 -1
  82. package/lib/constants.js +54 -8
  83. package/lib/constants.js.map +1 -1
  84. package/lib/index.d.ts +0 -1
  85. package/lib/index.d.ts.map +1 -1
  86. package/lib/index.js +0 -15
  87. package/lib/index.js.map +1 -1
  88. package/lib/logic/buildTransaction.d.ts.map +1 -1
  89. package/lib/logic/buildTransaction.js +42 -19
  90. package/lib/logic/buildTransaction.js.map +1 -1
  91. package/lib/logic/getCoinAndAmounts.d.ts +2 -0
  92. package/lib/logic/getCoinAndAmounts.d.ts.map +1 -1
  93. package/lib/logic/getCoinAndAmounts.js +65 -38
  94. package/lib/logic/getCoinAndAmounts.js.map +1 -1
  95. package/lib/logic/staking.d.ts +12 -0
  96. package/lib/logic/staking.d.ts.map +1 -0
  97. package/lib/logic/staking.js +81 -0
  98. package/lib/logic/staking.js.map +1 -0
  99. package/lib/logic/transactionsToOperations.js +3 -3
  100. package/lib/logic/transactionsToOperations.js.map +1 -1
  101. package/lib/network/client.d.ts +4 -1
  102. package/lib/network/client.d.ts.map +1 -1
  103. package/lib/network/client.js +32 -1
  104. package/lib/network/client.js.map +1 -1
  105. package/lib/network/graphql/queries.d.ts +2 -0
  106. package/lib/network/graphql/queries.d.ts.map +1 -1
  107. package/lib/network/graphql/queries.js +42 -2
  108. package/lib/network/graphql/queries.js.map +1 -1
  109. package/lib/network/graphql/types.d.ts +57 -6
  110. package/lib/network/graphql/types.d.ts.map +1 -1
  111. package/lib/network/index.d.ts.map +1 -1
  112. package/lib/network/index.js.map +1 -1
  113. package/lib/network/validators.d.ts +3 -0
  114. package/lib/network/validators.d.ts.map +1 -0
  115. package/lib/network/validators.js +42 -0
  116. package/lib/network/validators.js.map +1 -0
  117. package/lib/preload-data.d.ts +7 -0
  118. package/lib/preload-data.d.ts.map +1 -0
  119. package/lib/preload-data.js +42 -0
  120. package/lib/preload-data.js.map +1 -0
  121. package/lib/preload.d.ts +6 -0
  122. package/lib/preload.d.ts.map +1 -0
  123. package/lib/preload.js +21 -0
  124. package/lib/preload.js.map +1 -0
  125. package/lib/test/bridgeDatasetTest.d.ts.map +1 -1
  126. package/lib/test/bridgeDatasetTest.js +1 -0
  127. package/lib/test/bridgeDatasetTest.js.map +1 -1
  128. package/lib/types/index.d.ts +92 -8
  129. package/lib/types/index.d.ts.map +1 -1
  130. package/lib/types/index.js.map +1 -1
  131. package/lib/utils/IconGenerator.d.ts +12 -0
  132. package/lib/utils/IconGenerator.d.ts.map +1 -0
  133. package/lib/utils/IconGenerator.js +138 -0
  134. package/lib/utils/IconGenerator.js.map +1 -0
  135. package/lib/utils/index.d.ts +3 -0
  136. package/lib/utils/index.d.ts.map +1 -0
  137. package/lib/utils/index.js +31 -0
  138. package/lib/utils/index.js.map +1 -0
  139. package/lib-es/__tests__/bridge/deviceTransactionConfig.test.js +113 -8
  140. package/lib-es/__tests__/bridge/deviceTransactionConfig.test.js.map +1 -1
  141. package/lib-es/__tests__/bridge/getFeesForTransaction.test.js +10 -10
  142. package/lib-es/__tests__/bridge/getFeesForTransaction.test.js.map +1 -1
  143. package/lib-es/__tests__/bridge/getTransactionStatus.test.js +194 -3
  144. package/lib-es/__tests__/bridge/getTransactionStatus.test.js.map +1 -1
  145. package/lib-es/__tests__/bridge/index.test.js +4 -1
  146. package/lib-es/__tests__/bridge/index.test.js.map +1 -1
  147. package/lib-es/__tests__/bridge/logic.test.js +10 -10
  148. package/lib-es/__tests__/bridge/logic.test.js.map +1 -1
  149. package/lib-es/__tests__/bridge/prepareTransaction.test.js +1 -0
  150. package/lib-es/__tests__/bridge/prepareTransaction.test.js.map +1 -1
  151. package/lib-es/__tests__/bridge/serialization.d.ts +2 -0
  152. package/lib-es/__tests__/bridge/serialization.d.ts.map +1 -0
  153. package/lib-es/__tests__/bridge/serialization.js +86 -0
  154. package/lib-es/__tests__/bridge/serialization.js.map +1 -0
  155. package/lib-es/__tests__/bridge/synchronisation.test.js +763 -23
  156. package/lib-es/__tests__/bridge/synchronisation.test.js.map +1 -1
  157. package/lib-es/__tests__/logic/staking.test.d.ts +2 -0
  158. package/lib-es/__tests__/logic/staking.test.d.ts.map +1 -0
  159. package/lib-es/__tests__/logic/staking.test.js +197 -0
  160. package/lib-es/__tests__/logic/staking.test.js.map +1 -0
  161. package/lib-es/__tests__/network/client.test.js +3 -3
  162. package/lib-es/__tests__/network/validators.test.d.ts +2 -0
  163. package/lib-es/__tests__/network/validators.test.d.ts.map +1 -0
  164. package/lib-es/__tests__/network/validators.test.js +93 -0
  165. package/lib-es/__tests__/network/validators.test.js.map +1 -0
  166. package/lib-es/__tests__/utils/IconGenerator.test.d.ts +2 -0
  167. package/lib-es/__tests__/utils/IconGenerator.test.d.ts.map +1 -0
  168. package/lib-es/__tests__/utils/IconGenerator.test.js +12 -0
  169. package/lib-es/__tests__/utils/IconGenerator.test.js.map +1 -0
  170. package/lib-es/__tests__/utils/index.test.d.ts +2 -0
  171. package/lib-es/__tests__/utils/index.test.d.ts.map +1 -0
  172. package/lib-es/__tests__/utils/index.test.js +9 -0
  173. package/lib-es/__tests__/utils/index.test.js.map +1 -0
  174. package/lib-es/bridge/bridge.fixture.d.ts.map +1 -1
  175. package/lib-es/bridge/bridge.fixture.js +12 -0
  176. package/lib-es/bridge/bridge.fixture.js.map +1 -1
  177. package/lib-es/bridge/deviceTransactionConfig.d.ts +7 -8
  178. package/lib-es/bridge/deviceTransactionConfig.d.ts.map +1 -1
  179. package/lib-es/bridge/deviceTransactionConfig.js +83 -14
  180. package/lib-es/bridge/deviceTransactionConfig.js.map +1 -1
  181. package/lib-es/bridge/estimateMaxSpendable.d.ts +4 -4
  182. package/lib-es/bridge/estimateMaxSpendable.d.ts.map +1 -1
  183. package/lib-es/bridge/estimateMaxSpendable.js +1 -1
  184. package/lib-es/bridge/estimateMaxSpendable.js.map +1 -1
  185. package/lib-es/bridge/getFeesForTransaction.d.ts.map +1 -1
  186. package/lib-es/bridge/getFeesForTransaction.js +9 -5
  187. package/lib-es/bridge/getFeesForTransaction.js.map +1 -1
  188. package/lib-es/bridge/getTransactionStatus.d.ts +2 -3
  189. package/lib-es/bridge/getTransactionStatus.d.ts.map +1 -1
  190. package/lib-es/bridge/getTransactionStatus.js +140 -26
  191. package/lib-es/bridge/getTransactionStatus.js.map +1 -1
  192. package/lib-es/bridge/index.d.ts +3 -3
  193. package/lib-es/bridge/index.d.ts.map +1 -1
  194. package/lib-es/bridge/index.js +9 -2
  195. package/lib-es/bridge/index.js.map +1 -1
  196. package/lib-es/bridge/logic.d.ts +3 -3
  197. package/lib-es/bridge/logic.d.ts.map +1 -1
  198. package/lib-es/bridge/logic.js +23 -9
  199. package/lib-es/bridge/logic.js.map +1 -1
  200. package/lib-es/bridge/prepareTransaction.d.ts +2 -3
  201. package/lib-es/bridge/prepareTransaction.d.ts.map +1 -1
  202. package/lib-es/bridge/prepareTransaction.js +46 -10
  203. package/lib-es/bridge/prepareTransaction.js.map +1 -1
  204. package/lib-es/bridge/serialization.d.ts +7 -0
  205. package/lib-es/bridge/serialization.d.ts.map +1 -0
  206. package/lib-es/bridge/serialization.js +41 -0
  207. package/lib-es/bridge/serialization.js.map +1 -0
  208. package/lib-es/bridge/signOperation.d.ts.map +1 -1
  209. package/lib-es/bridge/signOperation.js +17 -5
  210. package/lib-es/bridge/signOperation.js.map +1 -1
  211. package/lib-es/bridge/synchronisation.d.ts +6 -4
  212. package/lib-es/bridge/synchronisation.d.ts.map +1 -1
  213. package/lib-es/bridge/synchronisation.js +49 -3
  214. package/lib-es/bridge/synchronisation.js.map +1 -1
  215. package/lib-es/constants.d.ts +25 -1
  216. package/lib-es/constants.d.ts.map +1 -1
  217. package/lib-es/constants.js +53 -7
  218. package/lib-es/constants.js.map +1 -1
  219. package/lib-es/index.d.ts +0 -1
  220. package/lib-es/index.d.ts.map +1 -1
  221. package/lib-es/index.js +0 -1
  222. package/lib-es/index.js.map +1 -1
  223. package/lib-es/logic/buildTransaction.d.ts.map +1 -1
  224. package/lib-es/logic/buildTransaction.js +42 -19
  225. package/lib-es/logic/buildTransaction.js.map +1 -1
  226. package/lib-es/logic/getCoinAndAmounts.d.ts +2 -0
  227. package/lib-es/logic/getCoinAndAmounts.d.ts.map +1 -1
  228. package/lib-es/logic/getCoinAndAmounts.js +66 -39
  229. package/lib-es/logic/getCoinAndAmounts.js.map +1 -1
  230. package/lib-es/logic/staking.d.ts +12 -0
  231. package/lib-es/logic/staking.d.ts.map +1 -0
  232. package/lib-es/logic/staking.js +67 -0
  233. package/lib-es/logic/staking.js.map +1 -0
  234. package/lib-es/logic/transactionsToOperations.js +4 -4
  235. package/lib-es/logic/transactionsToOperations.js.map +1 -1
  236. package/lib-es/network/client.d.ts +4 -1
  237. package/lib-es/network/client.d.ts.map +1 -1
  238. package/lib-es/network/client.js +32 -1
  239. package/lib-es/network/client.js.map +1 -1
  240. package/lib-es/network/graphql/queries.d.ts +2 -0
  241. package/lib-es/network/graphql/queries.d.ts.map +1 -1
  242. package/lib-es/network/graphql/queries.js +41 -1
  243. package/lib-es/network/graphql/queries.js.map +1 -1
  244. package/lib-es/network/graphql/types.d.ts +57 -6
  245. package/lib-es/network/graphql/types.d.ts.map +1 -1
  246. package/lib-es/network/index.d.ts.map +1 -1
  247. package/lib-es/network/index.js.map +1 -1
  248. package/lib-es/network/validators.d.ts +3 -0
  249. package/lib-es/network/validators.d.ts.map +1 -0
  250. package/lib-es/network/validators.js +35 -0
  251. package/lib-es/network/validators.js.map +1 -0
  252. package/lib-es/preload-data.d.ts +7 -0
  253. package/lib-es/preload-data.d.ts.map +1 -0
  254. package/lib-es/preload-data.js +36 -0
  255. package/lib-es/preload-data.js.map +1 -0
  256. package/lib-es/preload.d.ts +6 -0
  257. package/lib-es/preload.d.ts.map +1 -0
  258. package/lib-es/preload.js +16 -0
  259. package/lib-es/preload.js.map +1 -0
  260. package/lib-es/test/bridgeDatasetTest.d.ts.map +1 -1
  261. package/lib-es/test/bridgeDatasetTest.js +1 -0
  262. package/lib-es/test/bridgeDatasetTest.js.map +1 -1
  263. package/lib-es/types/index.d.ts +92 -8
  264. package/lib-es/types/index.d.ts.map +1 -1
  265. package/lib-es/types/index.js.map +1 -1
  266. package/lib-es/utils/IconGenerator.d.ts +12 -0
  267. package/lib-es/utils/IconGenerator.d.ts.map +1 -0
  268. package/lib-es/utils/IconGenerator.js +134 -0
  269. package/lib-es/utils/IconGenerator.js.map +1 -0
  270. package/lib-es/utils/index.d.ts +3 -0
  271. package/lib-es/utils/index.d.ts.map +1 -0
  272. package/lib-es/utils/index.js +13 -0
  273. package/lib-es/utils/index.js.map +1 -0
  274. package/package.json +14 -9
  275. package/src/__tests__/bridge/deviceTransactionConfig.test.ts +120 -8
  276. package/src/__tests__/bridge/getFeesForTransaction.test.ts +10 -10
  277. package/src/__tests__/bridge/getTransactionStatus.test.ts +247 -3
  278. package/src/__tests__/bridge/index.test.ts +5 -1
  279. package/src/__tests__/bridge/logic.test.ts +10 -10
  280. package/src/__tests__/bridge/prepareTransaction.test.ts +4 -4
  281. package/src/__tests__/bridge/serialization.ts +103 -0
  282. package/src/__tests__/bridge/synchronisation.test.ts +798 -32
  283. package/src/__tests__/logic/staking.test.ts +221 -0
  284. package/src/__tests__/network/client.test.ts +3 -3
  285. package/src/__tests__/network/validators.test.ts +105 -0
  286. package/src/__tests__/utils/IconGenerator.test.ts +13 -0
  287. package/src/__tests__/utils/index.test.ts +11 -0
  288. package/src/bridge/bridge.fixture.ts +12 -0
  289. package/src/bridge/deviceTransactionConfig.ts +90 -21
  290. package/src/bridge/estimateMaxSpendable.ts +5 -5
  291. package/src/bridge/getFeesForTransaction.ts +17 -5
  292. package/src/bridge/getTransactionStatus.ts +208 -32
  293. package/src/bridge/index.ts +14 -5
  294. package/src/bridge/logic.ts +28 -12
  295. package/src/bridge/prepareTransaction.ts +72 -24
  296. package/src/bridge/serialization.ts +52 -0
  297. package/src/bridge/signOperation.ts +20 -7
  298. package/src/bridge/synchronisation.ts +69 -12
  299. package/src/constants.ts +64 -2
  300. package/src/index.ts +0 -2
  301. package/src/logic/buildTransaction.ts +49 -24
  302. package/src/logic/getCoinAndAmounts.ts +91 -41
  303. package/src/logic/staking.ts +105 -0
  304. package/src/logic/transactionsToOperations.ts +5 -5
  305. package/src/network/client.ts +44 -4
  306. package/src/network/graphql/queries.ts +46 -1
  307. package/src/network/graphql/types.ts +63 -6
  308. package/src/network/index.ts +1 -0
  309. package/src/network/validators.ts +48 -0
  310. package/src/preload-data.ts +43 -0
  311. package/src/preload.ts +23 -0
  312. package/src/test/bridgeDatasetTest.ts +1 -0
  313. package/src/types/index.ts +106 -8
  314. package/src/utils/IconGenerator.ts +166 -0
  315. package/src/utils/index.ts +16 -0
@@ -0,0 +1,221 @@
1
+ import BigNumber from "bignumber.js";
2
+ import {
3
+ canRestake,
4
+ canStake,
5
+ canUnstake,
6
+ canWithdraw,
7
+ getDelegationOpMaxAmount,
8
+ mapStakingPositions,
9
+ } from "../../logic/staking";
10
+ import { createFixtureAccount } from "../../bridge/bridge.fixture";
11
+ import { MIN_COINS_ON_SHARES_POOL } from "../../constants";
12
+
13
+ const stakingPositions = [
14
+ {
15
+ active: BigNumber(123456789),
16
+ inactive: BigNumber(567567567),
17
+ pendingInactive: BigNumber(5345),
18
+ validatorId: "validator-1",
19
+ },
20
+ {
21
+ active: BigNumber(0),
22
+ inactive: BigNumber(33333),
23
+ pendingInactive: BigNumber(67868678),
24
+ validatorId: "validator-2",
25
+ },
26
+ {
27
+ active: BigNumber(45864986459),
28
+ inactive: BigNumber(0),
29
+ pendingInactive: BigNumber(0),
30
+ validatorId: "validator-3",
31
+ },
32
+ ];
33
+
34
+ const nonBreakableSpace = " ";
35
+
36
+ describe("mapStakingPositions", () => {
37
+ it("returns the staking positions per validator", () => {
38
+ const validators = [
39
+ {
40
+ activeStake: BigNumber(8972343459783425),
41
+ commission: BigNumber(8),
42
+ address: "validator-1",
43
+ name: "validator-1",
44
+ shares: "no-shares",
45
+ },
46
+ {
47
+ activeStake: BigNumber(172343459783425),
48
+ commission: BigNumber(8),
49
+ address: "validator-2",
50
+ name: "validator-2",
51
+ shares: "no-shares",
52
+ },
53
+ {
54
+ activeStake: BigNumber(1743459783425),
55
+ commission: BigNumber(7),
56
+ address: "validator-3",
57
+ name: "validator-3",
58
+ shares: "no-shares",
59
+ },
60
+ ];
61
+
62
+ const expected = [
63
+ {
64
+ active: BigNumber("123456789"),
65
+ inactive: BigNumber("567567567"),
66
+ pendingInactive: BigNumber("5345"),
67
+ validatorId: "validator-1",
68
+ formattedAmount: `1.23456${nonBreakableSpace}APT`,
69
+ formattedPending: `0.00005345${nonBreakableSpace}APT`,
70
+ formattedAvailable: `5.67567${nonBreakableSpace}APT`,
71
+ rank: 0,
72
+ validator: {
73
+ activeStake: BigNumber("8972343459783425"),
74
+ commission: BigNumber("8"),
75
+ address: "validator-1",
76
+ name: "validator-1",
77
+ shares: "no-shares",
78
+ },
79
+ },
80
+ {
81
+ active: BigNumber("0"),
82
+ inactive: BigNumber("33333"),
83
+ pendingInactive: BigNumber("67868678"),
84
+ validatorId: "validator-2",
85
+ formattedAmount: `0${nonBreakableSpace}APT`,
86
+ formattedPending: `0.678686${nonBreakableSpace}APT`,
87
+ formattedAvailable: `0.00033333${nonBreakableSpace}APT`,
88
+ rank: 1,
89
+ validator: {
90
+ activeStake: BigNumber("172343459783425"),
91
+ commission: BigNumber("8"),
92
+ address: "validator-2",
93
+ name: "validator-2",
94
+ shares: "no-shares",
95
+ },
96
+ },
97
+ {
98
+ active: BigNumber("45864986459"),
99
+ inactive: BigNumber("0"),
100
+ pendingInactive: BigNumber("0"),
101
+ validatorId: "validator-3",
102
+ formattedAmount: `458.649${nonBreakableSpace}APT`,
103
+ formattedPending: `0${nonBreakableSpace}APT`,
104
+ formattedAvailable: `0${nonBreakableSpace}APT`,
105
+ rank: 2,
106
+ validator: {
107
+ activeStake: BigNumber("1743459783425"),
108
+ commission: BigNumber("7"),
109
+ address: "validator-3",
110
+ name: "validator-3",
111
+ shares: "no-shares",
112
+ },
113
+ },
114
+ ];
115
+
116
+ expect(
117
+ mapStakingPositions(stakingPositions, validators, {
118
+ name: "Aptos",
119
+ code: "APT",
120
+ magnitude: 8,
121
+ }),
122
+ ).toMatchObject(expected);
123
+ });
124
+ });
125
+
126
+ describe("canStake", () => {
127
+ it(`returns false for an account with a balance with less than ${MIN_COINS_ON_SHARES_POOL} APT`, () => {
128
+ const account = createFixtureAccount({
129
+ balance: BigNumber(5),
130
+ spendableBalance: BigNumber(5),
131
+ });
132
+ const expected = canStake(account);
133
+ expect(expected).toBe(false);
134
+ });
135
+
136
+ it(`returns true for an account with balance with more than ${MIN_COINS_ON_SHARES_POOL} APT`, () => {
137
+ const account = createFixtureAccount({
138
+ balance: BigNumber(1212312312312),
139
+ spendableBalance: BigNumber(1212312312312),
140
+ });
141
+ const expected = canStake(account);
142
+ expect(expected).toBe(true);
143
+ });
144
+ });
145
+
146
+ describe("canUnstake", () => {
147
+ it("returns true if there's no amount staked", () => {
148
+ const expected = canUnstake(stakingPositions[0]);
149
+ expect(expected).toBe(true);
150
+ });
151
+
152
+ it("returns false if there's no amount staked", () => {
153
+ const expected = canUnstake(stakingPositions[1]);
154
+ expect(expected).toBe(false);
155
+ });
156
+ });
157
+
158
+ describe("canWithdraw", () => {
159
+ it("returns true if there's no amount inactive", () => {
160
+ const expected = canWithdraw(stakingPositions[0]);
161
+ expect(expected).toBe(true);
162
+ });
163
+
164
+ it("returns false if there's no amount inactive", () => {
165
+ const expected = canWithdraw(stakingPositions[2]);
166
+ expect(expected).toBe(false);
167
+ });
168
+ });
169
+
170
+ describe("canRestake", () => {
171
+ it("returns true if there's no amount inactive", () => {
172
+ const expected = canRestake(stakingPositions[0]);
173
+ expect(expected).toBe(true);
174
+ });
175
+
176
+ it("returns false if there's no amount inactive", () => {
177
+ const expected = canRestake(stakingPositions[2]);
178
+ expect(expected).toBe(false);
179
+ });
180
+ });
181
+
182
+ describe("getDelegationOpMaxAmount", () => {
183
+ it("get maximum amount available to unstake", () => {
184
+ const account = createFixtureAccount({
185
+ aptosResources: {
186
+ activeBalance: BigNumber(45988443248),
187
+ pendingInactiveBalance: BigNumber(67874023),
188
+ inactiveBalance: BigNumber(567600900),
189
+ stakingPositions,
190
+ },
191
+ });
192
+ const expected = getDelegationOpMaxAmount(account, "validator-1", "unstake");
193
+ expect(expected).toEqual(BigNumber(123456789));
194
+ });
195
+
196
+ it("get maximum amount available to withdraw", () => {
197
+ const account = createFixtureAccount({
198
+ aptosResources: {
199
+ activeBalance: BigNumber(45988443248),
200
+ pendingInactiveBalance: BigNumber(67874023),
201
+ inactiveBalance: BigNumber(567600900),
202
+ stakingPositions,
203
+ },
204
+ });
205
+ const expected = getDelegationOpMaxAmount(account, "validator-1", "withdraw");
206
+ expect(expected).toEqual(BigNumber(567567567));
207
+ });
208
+
209
+ it("get maximum amount available to restake", () => {
210
+ const account = createFixtureAccount({
211
+ aptosResources: {
212
+ activeBalance: BigNumber(45988443248),
213
+ pendingInactiveBalance: BigNumber(67874023),
214
+ inactiveBalance: BigNumber(567600900),
215
+ stakingPositions,
216
+ },
217
+ });
218
+ const expected = getDelegationOpMaxAmount(account, "validator-1", "restake");
219
+ expect(expected).toEqual(BigNumber(5345));
220
+ });
221
+ });
@@ -649,7 +649,7 @@ describe("Aptos API", () => {
649
649
  },
650
650
  });
651
651
 
652
- expect(fees.value.toString()).toEqual("40");
652
+ expect(fees.value.toString()).toEqual("44");
653
653
  });
654
654
 
655
655
  it("estimates the fees for token coin", async () => {
@@ -716,7 +716,7 @@ describe("Aptos API", () => {
716
716
  },
717
717
  });
718
718
 
719
- expect(fees.value.toString()).toEqual("20");
719
+ expect(fees.value.toString()).toEqual("22");
720
720
  });
721
721
 
722
722
  it("estimates the fees for token FA", async () => {
@@ -782,7 +782,7 @@ describe("Aptos API", () => {
782
782
  },
783
783
  });
784
784
 
785
- expect(fees.value.toString()).toEqual("30");
785
+ expect(fees.value.toString()).toEqual("33");
786
786
  });
787
787
  });
788
788
 
@@ -0,0 +1,105 @@
1
+ import { Aptos } from "@aptos-labs/ts-sdk";
2
+ import { ApolloClient } from "@apollo/client";
3
+ import { getValidators } from "../../network/validators";
4
+ import BigNumber from "bignumber.js";
5
+
6
+ jest.mock("@aptos-labs/ts-sdk");
7
+ let mockedAptos: jest.Mocked<any>;
8
+
9
+ jest.mock("@apollo/client");
10
+ let mockedApolloClient: jest.Mocked<any>;
11
+
12
+ describe("getValidators", () => {
13
+ beforeEach(() => {
14
+ mockedAptos = jest.mocked(Aptos);
15
+ mockedApolloClient = jest.mocked(ApolloClient);
16
+ });
17
+
18
+ afterAll(() => {
19
+ jest.useRealTimers();
20
+ });
21
+
22
+ const current_delegator_balances = [
23
+ {
24
+ __typename: "current_delegator_balances",
25
+ current_pool_balance: {
26
+ __typename: "current_delegated_staking_pool_balances",
27
+ total_coins: 211045219713562,
28
+ operator_commission_percentage: 900,
29
+ staking_pool_address: "0x001232f58b963938486a11f88c1c36d61d82738b1828625a95a1e85b4c8d1282",
30
+ total_shares: 200020456320587.72,
31
+ },
32
+ shares: 94692342176,
33
+ delegator_address: "0xb1a1d4624c5163445c993d9db9cd5bd3fc6b2c5e85a14216c3781d04d4f92d08",
34
+ staking_pool_metadata: {
35
+ __typename: "current_staking_pool_voter",
36
+ operator_aptos_name: [],
37
+ },
38
+ },
39
+ {
40
+ __typename: "current_delegator_balances",
41
+ current_pool_balance: {
42
+ __typename: "current_delegated_staking_pool_balances",
43
+ total_coins: 116781362397133,
44
+ operator_commission_percentage: 499,
45
+ staking_pool_address: "0x05dece2ed08c68f8730527e9b3ebb3536efc3361f4ef37ba0b16a3310db836af",
46
+ total_shares: 115552903623705.77,
47
+ },
48
+ shares: 15149284011,
49
+ delegator_address: "0x4ee1f2b7a1069a09b7d9c800928bfe851bc7649a0fb4e0d918554e0d445db4bc",
50
+ staking_pool_metadata: {
51
+ __typename: "current_staking_pool_voter",
52
+ operator_aptos_name: [
53
+ {
54
+ __typename: "current_aptos_names",
55
+ domain_with_suffix: "cryptomolot.apt",
56
+ is_active: true,
57
+ },
58
+ ],
59
+ },
60
+ },
61
+ ];
62
+
63
+ const expectedResponse = [
64
+ {
65
+ activeStake: BigNumber(211045219713562),
66
+ address: "0x001232f58b963938486a11f88c1c36d61d82738b1828625a95a1e85b4c8d1282",
67
+ commission: BigNumber(9),
68
+ name: "0x001232f58b963938486a11f88c1c36d61d82738b1828625a95a1e85b4c8d1282",
69
+ nextUnlockTime: "32d 5h 26m",
70
+ shares: 200020456320587.72,
71
+ wwwUrl:
72
+ "https://explorer.aptoslabs.com/account/0x001232f58b963938486a11f88c1c36d61d82738b1828625a95a1e85b4c8d1282?network=mainnet",
73
+ },
74
+ {
75
+ activeStake: BigNumber(116781362397133),
76
+ address: "0x05dece2ed08c68f8730527e9b3ebb3536efc3361f4ef37ba0b16a3310db836af",
77
+ commission: BigNumber(4.99),
78
+ name: "cryptomolot.apt",
79
+ nextUnlockTime: "32d 5h 26m",
80
+ shares: 115552903623705.77,
81
+ wwwUrl:
82
+ "https://explorer.aptoslabs.com/account/0x05dece2ed08c68f8730527e9b3ebb3536efc3361f4ef37ba0b16a3310db836af?network=mainnet",
83
+ },
84
+ ];
85
+
86
+ it("returns the correct information", async () => {
87
+ mockedAptos.mockImplementation(() => ({
88
+ getAccountResource: async () => ({ locked_until_secs: "1750051574" }),
89
+ }));
90
+
91
+ mockedApolloClient.mockImplementation(() => ({
92
+ query: async () => ({
93
+ data: {
94
+ current_delegator_balances,
95
+ },
96
+ }),
97
+ }));
98
+
99
+ jest.useFakeTimers().setSystemTime(new Date("2025-05-15"));
100
+
101
+ const validators = await getValidators("aptos");
102
+
103
+ expect(validators).toMatchObject(expectedResponse);
104
+ });
105
+ });
@@ -0,0 +1,13 @@
1
+ import { IconGenerator } from "../../utils";
2
+
3
+ describe("IconGenerator", () => {
4
+ it("returns a picture bitmap", () => {
5
+ const icon = new IconGenerator("seed");
6
+ expect(icon).toBeInstanceOf(IconGenerator);
7
+ expect(icon.generate).toBeInstanceOf(Function);
8
+
9
+ const iconString = icon.generate();
10
+ expect(typeof iconString).toBe("string");
11
+ expect(iconString.startsWith("data:image/bmp;base64")).toBe(true);
12
+ });
13
+ });
@@ -0,0 +1,11 @@
1
+ import { endpointByCurrencyId } from "../../utils";
2
+
3
+ describe("endpointByCurrencyId", () => {
4
+ it("gets the aptos endpoint based on the currency id", () => {
5
+ expect(endpointByCurrencyId("aptos")).toBe("https://apt.coin.ledger.com/node/v1");
6
+ expect(endpointByCurrencyId("aptos_testnet")).toBe("https://apt.coin.ledger-stg.com/node/v1");
7
+ expect(() => endpointByCurrencyId("NONE")).toThrow(
8
+ "unexpected currency id format <NONE>, should be like aptos[_testnet]",
9
+ );
10
+ });
11
+ });
@@ -33,6 +33,12 @@ export function createFixtureAccount(account?: Partial<AptosAccount>): AptosAcco
33
33
  lastSyncDate: new Date(),
34
34
  balanceHistoryCache: emptyHistoryCache,
35
35
  swapHistory: [],
36
+ aptosResources: {
37
+ stakingPositions: [],
38
+ activeBalance: BigNumber(0),
39
+ inactiveBalance: BigNumber(0),
40
+ pendingInactiveBalance: BigNumber(0),
41
+ },
36
42
  ...account,
37
43
  };
38
44
  }
@@ -90,6 +96,12 @@ export function createFixtureAccountWithSubAccount(
90
96
  swapHistory: [],
91
97
  },
92
98
  ],
99
+ aptosResources: {
100
+ stakingPositions: [],
101
+ activeBalance: BigNumber(0),
102
+ inactiveBalance: BigNumber(0),
103
+ pendingInactiveBalance: BigNumber(0),
104
+ },
93
105
  ...account,
94
106
  };
95
107
  }
@@ -1,28 +1,97 @@
1
1
  import type { CommonDeviceTransactionField as DeviceTransactionField } from "@ledgerhq/coin-framework/transaction/common";
2
- import BigNumber from "bignumber.js";
2
+ import { Account, AccountLike } from "@ledgerhq/types-live";
3
+ import { Transaction } from "../types";
4
+ import { formatCurrencyUnit } from "@ledgerhq/coin-framework/currencies/formatCurrencyUnit";
5
+ import { getAccountCurrency, getMainAccount } from "@ledgerhq/coin-framework/account/helpers";
3
6
 
4
- export const methodToString = (method: number): string => {
5
- switch (method) {
6
- case 0:
7
- return "Coin transfer";
8
- default:
9
- return "Unknown";
10
- }
11
- };
7
+ function getDeviceTransactionConfig({
8
+ account,
9
+ parentAccount,
10
+ transaction,
11
+ }: {
12
+ account: AccountLike;
13
+ parentAccount: Account | null | undefined;
14
+ transaction: Transaction;
15
+ }): Array<DeviceTransactionField> {
16
+ const { mode } = transaction;
17
+ const fields: DeviceTransactionField[] = [];
18
+ const mainAccount = getMainAccount(account, parentAccount);
12
19
 
13
- export type ExtraDeviceTransactionField = {
14
- type: "aptos.extendedAmount";
15
- label: string;
16
- value: number | BigNumber;
17
- };
20
+ const { fees } = transaction;
21
+ if (fees) {
22
+ fields.push({
23
+ type: "text",
24
+ label: "Transaction Fee",
25
+ value: formatCurrencyUnit(getAccountCurrency(mainAccount).units[0], fees, {
26
+ showCode: true,
27
+ disableRounding: true,
28
+ }),
29
+ });
30
+ }
18
31
 
19
- function getDeviceTransactionConfig(): Array<DeviceTransactionField> {
20
- const fields: Array<DeviceTransactionField> = [];
21
- fields.push({
22
- type: "text",
23
- label: "Type",
24
- value: methodToString(0),
25
- });
32
+ if (mode === "send") {
33
+ if (account.type === "TokenAccount") {
34
+ fields.push({
35
+ type: "text",
36
+ label: "Type",
37
+ value: "Token transfer",
38
+ });
39
+ fields.push({
40
+ type: "text",
41
+ label: "Amount",
42
+ value: formatCurrencyUnit(getAccountCurrency(account).units[0], transaction.amount, {
43
+ showCode: true,
44
+ disableRounding: true,
45
+ }),
46
+ });
47
+ } else if (account.type === "Account") {
48
+ fields.push({
49
+ type: "text",
50
+ label: "Amount",
51
+ value: formatCurrencyUnit(getAccountCurrency(account).units[0], transaction.amount, {
52
+ showCode: true,
53
+ disableRounding: true,
54
+ }),
55
+ });
56
+ }
57
+ } else if ((mode === "stake" || mode === "restake") && account.type === "Account") {
58
+ fields.push({
59
+ type: "text",
60
+ label: "Delegate to",
61
+ value: transaction.recipient,
62
+ });
63
+ fields.push({
64
+ type: "text",
65
+ label: "Amount",
66
+ value: formatCurrencyUnit(getAccountCurrency(account).units[0], transaction.amount, {
67
+ showCode: true,
68
+ disableRounding: true,
69
+ }),
70
+ });
71
+ } else if (mode === "unstake" && account.type === "Account") {
72
+ fields.push({
73
+ type: "text",
74
+ label: "Undelegate from",
75
+ value: transaction.recipient,
76
+ });
77
+ fields.push({
78
+ type: "text",
79
+ label: "Amount",
80
+ value: formatCurrencyUnit(getAccountCurrency(account).units[0], transaction.amount, {
81
+ showCode: true,
82
+ disableRounding: true,
83
+ }),
84
+ });
85
+ } else if (mode === "withdraw" && account.type === "Account") {
86
+ fields.push({
87
+ type: "text",
88
+ label: "Amount",
89
+ value: formatCurrencyUnit(getAccountCurrency(account).units[0], transaction.amount, {
90
+ showCode: true,
91
+ disableRounding: true,
92
+ }),
93
+ });
94
+ }
26
95
 
27
96
  return fields;
28
97
  }
@@ -1,19 +1,19 @@
1
- import type { Account, AccountLike } from "@ledgerhq/types-live";
1
+ import type { AccountLike } from "@ledgerhq/types-live";
2
2
  import { BigNumber } from "bignumber.js";
3
3
  import { getMainAccount } from "@ledgerhq/coin-framework/account/index";
4
4
  import { AptosAPI } from "../network";
5
5
  import { getEstimatedGas } from "./getFeesForTransaction";
6
6
  import { getMaxSendBalance } from "./logic";
7
- import type { Transaction } from "../types";
8
7
  import { DEFAULT_GAS, DEFAULT_GAS_PRICE } from "../constants";
8
+ import type { AptosAccount, Transaction } from "../types";
9
9
 
10
10
  const estimateMaxSpendable = async ({
11
11
  account,
12
12
  parentAccount,
13
13
  transaction,
14
14
  }: {
15
- account: AccountLike;
16
- parentAccount?: Account;
15
+ account: AccountLike<AptosAccount>;
16
+ parentAccount?: AptosAccount;
17
17
  transaction?: Transaction;
18
18
  }): Promise<BigNumber> => {
19
19
  const mainAccount = getMainAccount(account, parentAccount);
@@ -30,7 +30,7 @@ const estimateMaxSpendable = async ({
30
30
  gasUnitPrice = BigNumber(estimate.gasUnitPrice);
31
31
  }
32
32
 
33
- return getMaxSendBalance(maxGasAmount, gasUnitPrice, mainAccount, transaction);
33
+ return getMaxSendBalance(mainAccount, transaction, maxGasAmount, gasUnitPrice);
34
34
  };
35
35
 
36
36
  export default estimateMaxSpendable;
@@ -5,7 +5,13 @@ import BigNumber from "bignumber.js";
5
5
  import { makeLRUCache, seconds } from "@ledgerhq/live-network/cache";
6
6
  import { AptosAPI } from "../network";
7
7
  import { getTokenAccount } from "./logic";
8
- import { DEFAULT_GAS, DEFAULT_GAS_PRICE, ESTIMATE_GAS_MUL } from "../constants";
8
+ import {
9
+ DEFAULT_GAS,
10
+ DEFAULT_GAS_PRICE,
11
+ ESTIMATE_GAS_MUL,
12
+ ESTIMATE_GAS_MUL_FOR_STAKING,
13
+ STAKING_TX_MODES,
14
+ } from "../constants";
9
15
  import type { Transaction, TransactionErrors } from "../types";
10
16
  import buildTransaction from "../logic/buildTransaction";
11
17
 
@@ -38,14 +44,17 @@ export const getFee = async (
38
44
  maxGasAmount: gasLimit.toString(),
39
45
  gasUnitPrice: gasPrice.toString(),
40
46
  };
47
+
41
48
  if (account.xpub) {
42
49
  try {
43
50
  const publicKeyEd = new Ed25519PublicKey(account.xpub as string);
44
51
  const tx = await buildTransaction(account, transaction, aptosClient);
45
- const simulation = await aptosClient.simulateTransaction(publicKeyEd, tx);
46
- const completedTx = simulation[0];
52
+ const [completedTx] = await aptosClient.simulateTransaction(publicKeyEd, tx);
47
53
 
48
- gasLimit = new BigNumber(completedTx.gas_used).multipliedBy(ESTIMATE_GAS_MUL);
54
+ const gasMultiplier = STAKING_TX_MODES.includes(transaction.mode)
55
+ ? ESTIMATE_GAS_MUL_FOR_STAKING
56
+ : ESTIMATE_GAS_MUL;
57
+ gasLimit = new BigNumber(completedTx.gas_used).multipliedBy(gasMultiplier).integerValue();
49
58
  gasPrice = new BigNumber(completedTx.gas_unit_price);
50
59
 
51
60
  const expectedGas = gasPrice.multipliedBy(gasLimit);
@@ -55,9 +64,11 @@ export const getFee = async (
55
64
  res.errors.maxGasAmount = "GasInsufficientBalance";
56
65
  } else if (
57
66
  !completedTx.vm_status.includes("INSUFFICIENT_BALANCE") &&
67
+ !completedTx.vm_status.includes("EDELEGATOR_ACTIVE_BALANCE_TOO_LOW") &&
68
+ !completedTx.vm_status.includes("EDELEGATOR_PENDING_INACTIVE_BALANCE_TOO_LOW") &&
58
69
  !completedTx.vm_status.includes("0x203ed") // 0x203ed -> PROLOGUE_ECANT_PAY_GAS_DEPOSIT equivalent to INSUFFICIENT_BALANCE_FOR_TRANSACTION_FEE
59
70
  ) {
60
- // INSUFFICIENT_BALANCE will be processed by getTransactionStatus
71
+ // INSUFFICIENT_BALANCE and EDELEGATOR_ACTIVE_BALANCE_TOO_LOW will be processed by getTransactionStatus
61
72
  throw Error(`Simulation failed with following error: ${completedTx.vm_status}`);
62
73
  }
63
74
  }
@@ -70,6 +81,7 @@ export const getFee = async (
70
81
  throw error;
71
82
  }
72
83
  }
84
+
73
85
  return res;
74
86
  };
75
87