@ledgerhq/coin-aptos 2.5.1 → 2.5.2-nightly.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 (314) hide show
  1. package/.unimportedrc.json +5 -8
  2. package/CHANGELOG.md +8 -0
  3. package/lib/__tests__/bridge/deviceTransactionConfig.test.js +115 -30
  4. package/lib/__tests__/bridge/deviceTransactionConfig.test.js.map +1 -1
  5. package/lib/__tests__/bridge/getFeesForTransaction.test.js +10 -10
  6. package/lib/__tests__/bridge/getFeesForTransaction.test.js.map +1 -1
  7. package/lib/__tests__/bridge/getTransactionStatus.test.js +193 -2
  8. package/lib/__tests__/bridge/getTransactionStatus.test.js.map +1 -1
  9. package/lib/__tests__/bridge/index.test.js +4 -1
  10. package/lib/__tests__/bridge/index.test.js.map +1 -1
  11. package/lib/__tests__/bridge/logic.test.js +9 -9
  12. package/lib/__tests__/bridge/logic.test.js.map +1 -1
  13. package/lib/__tests__/bridge/prepareTransaction.test.js +1 -0
  14. package/lib/__tests__/bridge/prepareTransaction.test.js.map +1 -1
  15. package/lib/__tests__/bridge/serialization.d.ts +2 -0
  16. package/lib/__tests__/bridge/serialization.d.ts.map +1 -0
  17. package/lib/__tests__/bridge/serialization.js +91 -0
  18. package/lib/__tests__/bridge/serialization.js.map +1 -0
  19. package/lib/__tests__/bridge/synchronisation.test.js +763 -23
  20. package/lib/__tests__/bridge/synchronisation.test.js.map +1 -1
  21. package/lib/__tests__/logic/staking.test.d.ts +2 -0
  22. package/lib/__tests__/logic/staking.test.d.ts.map +1 -0
  23. package/lib/__tests__/logic/staking.test.js +202 -0
  24. package/lib/__tests__/logic/staking.test.js.map +1 -0
  25. package/lib/__tests__/network/client.test.js +3 -3
  26. package/lib/__tests__/network/validators.test.d.ts +2 -0
  27. package/lib/__tests__/network/validators.test.d.ts.map +1 -0
  28. package/lib/__tests__/network/validators.test.js +98 -0
  29. package/lib/__tests__/network/validators.test.js.map +1 -0
  30. package/lib/__tests__/utils/IconGenerator.test.d.ts +2 -0
  31. package/lib/__tests__/utils/IconGenerator.test.d.ts.map +1 -0
  32. package/lib/__tests__/utils/IconGenerator.test.js +14 -0
  33. package/lib/__tests__/utils/IconGenerator.test.js.map +1 -0
  34. package/lib/__tests__/utils/index.test.d.ts +2 -0
  35. package/lib/__tests__/utils/index.test.d.ts.map +1 -0
  36. package/lib/__tests__/utils/index.test.js +11 -0
  37. package/lib/__tests__/utils/index.test.js.map +1 -0
  38. package/lib/bridge/bridge.fixture.d.ts.map +1 -1
  39. package/lib/bridge/bridge.fixture.js +12 -0
  40. package/lib/bridge/bridge.fixture.js.map +1 -1
  41. package/lib/bridge/deviceTransactionConfig.d.ts +7 -8
  42. package/lib/bridge/deviceTransactionConfig.d.ts.map +1 -1
  43. package/lib/bridge/deviceTransactionConfig.js +83 -16
  44. package/lib/bridge/deviceTransactionConfig.js.map +1 -1
  45. package/lib/bridge/estimateMaxSpendable.d.ts +4 -4
  46. package/lib/bridge/estimateMaxSpendable.d.ts.map +1 -1
  47. package/lib/bridge/estimateMaxSpendable.js +1 -1
  48. package/lib/bridge/estimateMaxSpendable.js.map +1 -1
  49. package/lib/bridge/getFeesForTransaction.d.ts.map +1 -1
  50. package/lib/bridge/getFeesForTransaction.js +8 -4
  51. package/lib/bridge/getFeesForTransaction.js.map +1 -1
  52. package/lib/bridge/getTransactionStatus.d.ts +2 -3
  53. package/lib/bridge/getTransactionStatus.d.ts.map +1 -1
  54. package/lib/bridge/getTransactionStatus.js +139 -25
  55. package/lib/bridge/getTransactionStatus.js.map +1 -1
  56. package/lib/bridge/index.d.ts +3 -3
  57. package/lib/bridge/index.d.ts.map +1 -1
  58. package/lib/bridge/index.js +9 -2
  59. package/lib/bridge/index.js.map +1 -1
  60. package/lib/bridge/logic.d.ts +3 -3
  61. package/lib/bridge/logic.d.ts.map +1 -1
  62. package/lib/bridge/logic.js +23 -9
  63. package/lib/bridge/logic.js.map +1 -1
  64. package/lib/bridge/prepareTransaction.d.ts +2 -3
  65. package/lib/bridge/prepareTransaction.d.ts.map +1 -1
  66. package/lib/bridge/prepareTransaction.js +46 -10
  67. package/lib/bridge/prepareTransaction.js.map +1 -1
  68. package/lib/bridge/serialization.d.ts +7 -0
  69. package/lib/bridge/serialization.d.ts.map +1 -0
  70. package/lib/bridge/serialization.js +51 -0
  71. package/lib/bridge/serialization.js.map +1 -0
  72. package/lib/bridge/signOperation.d.ts.map +1 -1
  73. package/lib/bridge/signOperation.js +17 -5
  74. package/lib/bridge/signOperation.js.map +1 -1
  75. package/lib/bridge/synchronisation.d.ts +6 -4
  76. package/lib/bridge/synchronisation.d.ts.map +1 -1
  77. package/lib/bridge/synchronisation.js +51 -4
  78. package/lib/bridge/synchronisation.js.map +1 -1
  79. package/lib/constants.d.ts +25 -1
  80. package/lib/constants.d.ts.map +1 -1
  81. package/lib/constants.js +54 -8
  82. package/lib/constants.js.map +1 -1
  83. package/lib/index.d.ts +0 -1
  84. package/lib/index.d.ts.map +1 -1
  85. package/lib/index.js +0 -15
  86. package/lib/index.js.map +1 -1
  87. package/lib/logic/buildTransaction.d.ts.map +1 -1
  88. package/lib/logic/buildTransaction.js +42 -19
  89. package/lib/logic/buildTransaction.js.map +1 -1
  90. package/lib/logic/getCoinAndAmounts.d.ts +2 -0
  91. package/lib/logic/getCoinAndAmounts.d.ts.map +1 -1
  92. package/lib/logic/getCoinAndAmounts.js +65 -38
  93. package/lib/logic/getCoinAndAmounts.js.map +1 -1
  94. package/lib/logic/staking.d.ts +12 -0
  95. package/lib/logic/staking.d.ts.map +1 -0
  96. package/lib/logic/staking.js +81 -0
  97. package/lib/logic/staking.js.map +1 -0
  98. package/lib/logic/transactionsToOperations.js +3 -3
  99. package/lib/logic/transactionsToOperations.js.map +1 -1
  100. package/lib/network/client.d.ts +4 -1
  101. package/lib/network/client.d.ts.map +1 -1
  102. package/lib/network/client.js +32 -1
  103. package/lib/network/client.js.map +1 -1
  104. package/lib/network/graphql/queries.d.ts +2 -0
  105. package/lib/network/graphql/queries.d.ts.map +1 -1
  106. package/lib/network/graphql/queries.js +42 -2
  107. package/lib/network/graphql/queries.js.map +1 -1
  108. package/lib/network/graphql/types.d.ts +57 -6
  109. package/lib/network/graphql/types.d.ts.map +1 -1
  110. package/lib/network/index.d.ts.map +1 -1
  111. package/lib/network/index.js.map +1 -1
  112. package/lib/network/validators.d.ts +3 -0
  113. package/lib/network/validators.d.ts.map +1 -0
  114. package/lib/network/validators.js +42 -0
  115. package/lib/network/validators.js.map +1 -0
  116. package/lib/preload-data.d.ts +7 -0
  117. package/lib/preload-data.d.ts.map +1 -0
  118. package/lib/preload-data.js +42 -0
  119. package/lib/preload-data.js.map +1 -0
  120. package/lib/preload.d.ts +6 -0
  121. package/lib/preload.d.ts.map +1 -0
  122. package/lib/preload.js +21 -0
  123. package/lib/preload.js.map +1 -0
  124. package/lib/test/bridgeDatasetTest.d.ts.map +1 -1
  125. package/lib/test/bridgeDatasetTest.js +1 -0
  126. package/lib/test/bridgeDatasetTest.js.map +1 -1
  127. package/lib/types/index.d.ts +92 -8
  128. package/lib/types/index.d.ts.map +1 -1
  129. package/lib/types/index.js.map +1 -1
  130. package/lib/utils/IconGenerator.d.ts +12 -0
  131. package/lib/utils/IconGenerator.d.ts.map +1 -0
  132. package/lib/utils/IconGenerator.js +138 -0
  133. package/lib/utils/IconGenerator.js.map +1 -0
  134. package/lib/utils/index.d.ts +3 -0
  135. package/lib/utils/index.d.ts.map +1 -0
  136. package/lib/utils/index.js +31 -0
  137. package/lib/utils/index.js.map +1 -0
  138. package/lib-es/__tests__/bridge/deviceTransactionConfig.test.js +113 -8
  139. package/lib-es/__tests__/bridge/deviceTransactionConfig.test.js.map +1 -1
  140. package/lib-es/__tests__/bridge/getFeesForTransaction.test.js +10 -10
  141. package/lib-es/__tests__/bridge/getFeesForTransaction.test.js.map +1 -1
  142. package/lib-es/__tests__/bridge/getTransactionStatus.test.js +194 -3
  143. package/lib-es/__tests__/bridge/getTransactionStatus.test.js.map +1 -1
  144. package/lib-es/__tests__/bridge/index.test.js +4 -1
  145. package/lib-es/__tests__/bridge/index.test.js.map +1 -1
  146. package/lib-es/__tests__/bridge/logic.test.js +10 -10
  147. package/lib-es/__tests__/bridge/logic.test.js.map +1 -1
  148. package/lib-es/__tests__/bridge/prepareTransaction.test.js +1 -0
  149. package/lib-es/__tests__/bridge/prepareTransaction.test.js.map +1 -1
  150. package/lib-es/__tests__/bridge/serialization.d.ts +2 -0
  151. package/lib-es/__tests__/bridge/serialization.d.ts.map +1 -0
  152. package/lib-es/__tests__/bridge/serialization.js +86 -0
  153. package/lib-es/__tests__/bridge/serialization.js.map +1 -0
  154. package/lib-es/__tests__/bridge/synchronisation.test.js +763 -23
  155. package/lib-es/__tests__/bridge/synchronisation.test.js.map +1 -1
  156. package/lib-es/__tests__/logic/staking.test.d.ts +2 -0
  157. package/lib-es/__tests__/logic/staking.test.d.ts.map +1 -0
  158. package/lib-es/__tests__/logic/staking.test.js +197 -0
  159. package/lib-es/__tests__/logic/staking.test.js.map +1 -0
  160. package/lib-es/__tests__/network/client.test.js +3 -3
  161. package/lib-es/__tests__/network/validators.test.d.ts +2 -0
  162. package/lib-es/__tests__/network/validators.test.d.ts.map +1 -0
  163. package/lib-es/__tests__/network/validators.test.js +93 -0
  164. package/lib-es/__tests__/network/validators.test.js.map +1 -0
  165. package/lib-es/__tests__/utils/IconGenerator.test.d.ts +2 -0
  166. package/lib-es/__tests__/utils/IconGenerator.test.d.ts.map +1 -0
  167. package/lib-es/__tests__/utils/IconGenerator.test.js +12 -0
  168. package/lib-es/__tests__/utils/IconGenerator.test.js.map +1 -0
  169. package/lib-es/__tests__/utils/index.test.d.ts +2 -0
  170. package/lib-es/__tests__/utils/index.test.d.ts.map +1 -0
  171. package/lib-es/__tests__/utils/index.test.js +9 -0
  172. package/lib-es/__tests__/utils/index.test.js.map +1 -0
  173. package/lib-es/bridge/bridge.fixture.d.ts.map +1 -1
  174. package/lib-es/bridge/bridge.fixture.js +12 -0
  175. package/lib-es/bridge/bridge.fixture.js.map +1 -1
  176. package/lib-es/bridge/deviceTransactionConfig.d.ts +7 -8
  177. package/lib-es/bridge/deviceTransactionConfig.d.ts.map +1 -1
  178. package/lib-es/bridge/deviceTransactionConfig.js +83 -14
  179. package/lib-es/bridge/deviceTransactionConfig.js.map +1 -1
  180. package/lib-es/bridge/estimateMaxSpendable.d.ts +4 -4
  181. package/lib-es/bridge/estimateMaxSpendable.d.ts.map +1 -1
  182. package/lib-es/bridge/estimateMaxSpendable.js +1 -1
  183. package/lib-es/bridge/estimateMaxSpendable.js.map +1 -1
  184. package/lib-es/bridge/getFeesForTransaction.d.ts.map +1 -1
  185. package/lib-es/bridge/getFeesForTransaction.js +9 -5
  186. package/lib-es/bridge/getFeesForTransaction.js.map +1 -1
  187. package/lib-es/bridge/getTransactionStatus.d.ts +2 -3
  188. package/lib-es/bridge/getTransactionStatus.d.ts.map +1 -1
  189. package/lib-es/bridge/getTransactionStatus.js +140 -26
  190. package/lib-es/bridge/getTransactionStatus.js.map +1 -1
  191. package/lib-es/bridge/index.d.ts +3 -3
  192. package/lib-es/bridge/index.d.ts.map +1 -1
  193. package/lib-es/bridge/index.js +9 -2
  194. package/lib-es/bridge/index.js.map +1 -1
  195. package/lib-es/bridge/logic.d.ts +3 -3
  196. package/lib-es/bridge/logic.d.ts.map +1 -1
  197. package/lib-es/bridge/logic.js +23 -9
  198. package/lib-es/bridge/logic.js.map +1 -1
  199. package/lib-es/bridge/prepareTransaction.d.ts +2 -3
  200. package/lib-es/bridge/prepareTransaction.d.ts.map +1 -1
  201. package/lib-es/bridge/prepareTransaction.js +46 -10
  202. package/lib-es/bridge/prepareTransaction.js.map +1 -1
  203. package/lib-es/bridge/serialization.d.ts +7 -0
  204. package/lib-es/bridge/serialization.d.ts.map +1 -0
  205. package/lib-es/bridge/serialization.js +41 -0
  206. package/lib-es/bridge/serialization.js.map +1 -0
  207. package/lib-es/bridge/signOperation.d.ts.map +1 -1
  208. package/lib-es/bridge/signOperation.js +17 -5
  209. package/lib-es/bridge/signOperation.js.map +1 -1
  210. package/lib-es/bridge/synchronisation.d.ts +6 -4
  211. package/lib-es/bridge/synchronisation.d.ts.map +1 -1
  212. package/lib-es/bridge/synchronisation.js +49 -3
  213. package/lib-es/bridge/synchronisation.js.map +1 -1
  214. package/lib-es/constants.d.ts +25 -1
  215. package/lib-es/constants.d.ts.map +1 -1
  216. package/lib-es/constants.js +53 -7
  217. package/lib-es/constants.js.map +1 -1
  218. package/lib-es/index.d.ts +0 -1
  219. package/lib-es/index.d.ts.map +1 -1
  220. package/lib-es/index.js +0 -1
  221. package/lib-es/index.js.map +1 -1
  222. package/lib-es/logic/buildTransaction.d.ts.map +1 -1
  223. package/lib-es/logic/buildTransaction.js +42 -19
  224. package/lib-es/logic/buildTransaction.js.map +1 -1
  225. package/lib-es/logic/getCoinAndAmounts.d.ts +2 -0
  226. package/lib-es/logic/getCoinAndAmounts.d.ts.map +1 -1
  227. package/lib-es/logic/getCoinAndAmounts.js +66 -39
  228. package/lib-es/logic/getCoinAndAmounts.js.map +1 -1
  229. package/lib-es/logic/staking.d.ts +12 -0
  230. package/lib-es/logic/staking.d.ts.map +1 -0
  231. package/lib-es/logic/staking.js +67 -0
  232. package/lib-es/logic/staking.js.map +1 -0
  233. package/lib-es/logic/transactionsToOperations.js +4 -4
  234. package/lib-es/logic/transactionsToOperations.js.map +1 -1
  235. package/lib-es/network/client.d.ts +4 -1
  236. package/lib-es/network/client.d.ts.map +1 -1
  237. package/lib-es/network/client.js +32 -1
  238. package/lib-es/network/client.js.map +1 -1
  239. package/lib-es/network/graphql/queries.d.ts +2 -0
  240. package/lib-es/network/graphql/queries.d.ts.map +1 -1
  241. package/lib-es/network/graphql/queries.js +41 -1
  242. package/lib-es/network/graphql/queries.js.map +1 -1
  243. package/lib-es/network/graphql/types.d.ts +57 -6
  244. package/lib-es/network/graphql/types.d.ts.map +1 -1
  245. package/lib-es/network/index.d.ts.map +1 -1
  246. package/lib-es/network/index.js.map +1 -1
  247. package/lib-es/network/validators.d.ts +3 -0
  248. package/lib-es/network/validators.d.ts.map +1 -0
  249. package/lib-es/network/validators.js +35 -0
  250. package/lib-es/network/validators.js.map +1 -0
  251. package/lib-es/preload-data.d.ts +7 -0
  252. package/lib-es/preload-data.d.ts.map +1 -0
  253. package/lib-es/preload-data.js +36 -0
  254. package/lib-es/preload-data.js.map +1 -0
  255. package/lib-es/preload.d.ts +6 -0
  256. package/lib-es/preload.d.ts.map +1 -0
  257. package/lib-es/preload.js +16 -0
  258. package/lib-es/preload.js.map +1 -0
  259. package/lib-es/test/bridgeDatasetTest.d.ts.map +1 -1
  260. package/lib-es/test/bridgeDatasetTest.js +1 -0
  261. package/lib-es/test/bridgeDatasetTest.js.map +1 -1
  262. package/lib-es/types/index.d.ts +92 -8
  263. package/lib-es/types/index.d.ts.map +1 -1
  264. package/lib-es/types/index.js.map +1 -1
  265. package/lib-es/utils/IconGenerator.d.ts +12 -0
  266. package/lib-es/utils/IconGenerator.d.ts.map +1 -0
  267. package/lib-es/utils/IconGenerator.js +134 -0
  268. package/lib-es/utils/IconGenerator.js.map +1 -0
  269. package/lib-es/utils/index.d.ts +3 -0
  270. package/lib-es/utils/index.d.ts.map +1 -0
  271. package/lib-es/utils/index.js +13 -0
  272. package/lib-es/utils/index.js.map +1 -0
  273. package/package.json +12 -7
  274. package/src/__tests__/bridge/deviceTransactionConfig.test.ts +120 -8
  275. package/src/__tests__/bridge/getFeesForTransaction.test.ts +10 -10
  276. package/src/__tests__/bridge/getTransactionStatus.test.ts +247 -3
  277. package/src/__tests__/bridge/index.test.ts +5 -1
  278. package/src/__tests__/bridge/logic.test.ts +10 -10
  279. package/src/__tests__/bridge/prepareTransaction.test.ts +4 -4
  280. package/src/__tests__/bridge/serialization.ts +103 -0
  281. package/src/__tests__/bridge/synchronisation.test.ts +798 -32
  282. package/src/__tests__/logic/staking.test.ts +221 -0
  283. package/src/__tests__/network/client.test.ts +3 -3
  284. package/src/__tests__/network/validators.test.ts +105 -0
  285. package/src/__tests__/utils/IconGenerator.test.ts +13 -0
  286. package/src/__tests__/utils/index.test.ts +11 -0
  287. package/src/bridge/bridge.fixture.ts +12 -0
  288. package/src/bridge/deviceTransactionConfig.ts +90 -21
  289. package/src/bridge/estimateMaxSpendable.ts +5 -5
  290. package/src/bridge/getFeesForTransaction.ts +17 -5
  291. package/src/bridge/getTransactionStatus.ts +208 -32
  292. package/src/bridge/index.ts +14 -5
  293. package/src/bridge/logic.ts +28 -12
  294. package/src/bridge/prepareTransaction.ts +72 -24
  295. package/src/bridge/serialization.ts +52 -0
  296. package/src/bridge/signOperation.ts +20 -7
  297. package/src/bridge/synchronisation.ts +69 -12
  298. package/src/constants.ts +64 -2
  299. package/src/index.ts +0 -2
  300. package/src/logic/buildTransaction.ts +49 -24
  301. package/src/logic/getCoinAndAmounts.ts +91 -41
  302. package/src/logic/staking.ts +105 -0
  303. package/src/logic/transactionsToOperations.ts +5 -5
  304. package/src/network/client.ts +44 -4
  305. package/src/network/graphql/queries.ts +46 -1
  306. package/src/network/graphql/types.ts +63 -6
  307. package/src/network/index.ts +1 -0
  308. package/src/network/validators.ts +48 -0
  309. package/src/preload-data.ts +43 -0
  310. package/src/preload.ts +23 -0
  311. package/src/test/bridgeDatasetTest.ts +1 -0
  312. package/src/types/index.ts +106 -8
  313. package/src/utils/IconGenerator.ts +166 -0
  314. package/src/utils/index.ts +16 -0
@@ -12,9 +12,38 @@ import {
12
12
  InvalidAddress,
13
13
  InvalidAddressBecauseDestinationIsAlsoSource,
14
14
  NotEnoughBalance,
15
- NotEnoughBalanceFees,
15
+ NotEnoughToRestake,
16
+ NotEnoughToStake,
17
+ NotEnoughToUnstake,
16
18
  RecipientRequired,
17
19
  } from "@ledgerhq/errors";
20
+ import { MIN_COINS_ON_SHARES_POOL } from "../../constants";
21
+
22
+ const aptosResources = {
23
+ activeBalance: BigNumber(45988443248),
24
+ pendingInactiveBalance: BigNumber(67874023),
25
+ inactiveBalance: BigNumber(567600900),
26
+ stakingPositions: [
27
+ {
28
+ active: BigNumber(123456789),
29
+ inactive: BigNumber(567567567),
30
+ pendingInactive: BigNumber(5345),
31
+ validatorId: "validator-1",
32
+ },
33
+ {
34
+ active: BigNumber(3),
35
+ inactive: BigNumber(33333),
36
+ pendingInactive: BigNumber(67868678),
37
+ validatorId: "validator-2",
38
+ },
39
+ {
40
+ active: BigNumber(45864986459),
41
+ inactive: BigNumber(0),
42
+ pendingInactive: BigNumber(0),
43
+ validatorId: "validator-3",
44
+ },
45
+ ],
46
+ };
18
47
 
19
48
  describe("getTransactionStatus Test", () => {
20
49
  it("should return error for AmountRequired", async () => {
@@ -53,6 +82,7 @@ describe("getTransactionStatus Test", () => {
53
82
  const expected = {
54
83
  errors: {
55
84
  fees: new FeeNotLoaded(),
85
+ amount: new NotEnoughBalance(),
56
86
  },
57
87
  warnings: {},
58
88
  estimatedFees: BigNumber(0),
@@ -200,7 +230,7 @@ describe("getTransactionStatus Test", () => {
200
230
 
201
231
  const expected = {
202
232
  errors: {
203
- amount: new NotEnoughBalanceFees(),
233
+ amount: new NotEnoughBalance(),
204
234
  },
205
235
  warnings: {},
206
236
  estimatedFees: BigNumber(0),
@@ -225,6 +255,7 @@ describe("getTransactionStatus Test", () => {
225
255
  const expected = {
226
256
  errors: {
227
257
  recipient: new RecipientRequired(),
258
+ amount: new NotEnoughBalance(),
228
259
  },
229
260
  warnings: {},
230
261
  estimatedFees: BigNumber(2),
@@ -315,7 +346,6 @@ describe("getTransactionStatus Test", () => {
315
346
 
316
347
  const transaction = createFixtureTransaction();
317
348
  transaction.recipient = "0x" + "0".repeat(64);
318
- transaction.amount = BigNumber(2);
319
349
  transaction.fees = BigNumber(2);
320
350
  transaction.useAllAmount = true;
321
351
 
@@ -331,4 +361,218 @@ describe("getTransactionStatus Test", () => {
331
361
 
332
362
  expect(result).toEqual(expected);
333
363
  });
364
+
365
+ it("should return not enough balance if trying to stake more than the current balance", async () => {
366
+ const account = createFixtureAccount({
367
+ balance: BigNumber(123456),
368
+ spendableBalance: BigNumber(123456),
369
+ });
370
+
371
+ const transaction = createFixtureTransaction({ mode: "stake", amount: BigNumber(123453336) });
372
+
373
+ const result = await getTransactionStatus(account, transaction);
374
+
375
+ const expected = {
376
+ errors: {
377
+ amount: new NotEnoughBalance(),
378
+ },
379
+ };
380
+
381
+ expect(result).toMatchObject(expected);
382
+ });
383
+
384
+ it(`should return not enough balance to stake if trying to stake less than ${MIN_COINS_ON_SHARES_POOL} APT`, async () => {
385
+ const account = createFixtureAccount({
386
+ balance: BigNumber(123456),
387
+ spendableBalance: BigNumber(123456),
388
+ });
389
+
390
+ const transaction = createFixtureTransaction({ mode: "stake", amount: BigNumber(5) });
391
+
392
+ const result = await getTransactionStatus(account, transaction);
393
+
394
+ const expected = {
395
+ errors: {
396
+ amount: new NotEnoughToStake(),
397
+ },
398
+ };
399
+
400
+ expect(result).toMatchObject(expected);
401
+ });
402
+
403
+ it(`should return not enough balance to stake if trying to stake the max balance but it is less than ${MIN_COINS_ON_SHARES_POOL} APT`, async () => {
404
+ const account = createFixtureAccount({
405
+ balance: BigNumber(4),
406
+ spendableBalance: BigNumber(4),
407
+ });
408
+
409
+ const transaction = createFixtureTransaction({ mode: "stake", useAllAmount: true });
410
+
411
+ const result = await getTransactionStatus(account, transaction);
412
+
413
+ const expected = {
414
+ errors: {
415
+ amount: new NotEnoughToStake(),
416
+ },
417
+ };
418
+
419
+ expect(result).toMatchObject(expected);
420
+ });
421
+
422
+ it("should return an error if there's no staking position to restake", async () => {
423
+ const account = createFixtureAccount({
424
+ balance: BigNumber(4),
425
+ spendableBalance: BigNumber(4),
426
+ });
427
+
428
+ const transaction = createFixtureTransaction({ mode: "restake" });
429
+
430
+ const result = await getTransactionStatus(account, transaction);
431
+
432
+ const expected = {
433
+ errors: {
434
+ recipient: new RecipientRequired(),
435
+ },
436
+ };
437
+
438
+ expect(result).toMatchObject(expected);
439
+ });
440
+
441
+ it("should return an error if there's not enough pending inactive balance", async () => {
442
+ const account = createFixtureAccount({
443
+ balance: BigNumber(4),
444
+ spendableBalance: BigNumber(4),
445
+ aptosResources,
446
+ });
447
+
448
+ const transaction = createFixtureTransaction({
449
+ mode: "restake",
450
+ recipient: "validator-1",
451
+ amount: BigNumber(67874022223),
452
+ fees: BigNumber(1),
453
+ });
454
+
455
+ const result = await getTransactionStatus(account, transaction);
456
+
457
+ const expected = {
458
+ errors: {
459
+ amount: new NotEnoughBalance(),
460
+ },
461
+ };
462
+
463
+ expect(result).toMatchObject(expected);
464
+ });
465
+
466
+ it(`should return not enough amount if trying to restake but it is less than ${MIN_COINS_ON_SHARES_POOL} APT`, async () => {
467
+ const account = createFixtureAccount({
468
+ balance: BigNumber(4),
469
+ spendableBalance: BigNumber(4),
470
+ aptosResources,
471
+ });
472
+
473
+ const transaction = createFixtureTransaction({
474
+ mode: "restake",
475
+ recipient: "validator-2",
476
+ amount: BigNumber(4),
477
+ fees: BigNumber(1),
478
+ });
479
+
480
+ const result = await getTransactionStatus(account, transaction);
481
+
482
+ const expected = {
483
+ errors: {
484
+ amount: new NotEnoughToRestake(),
485
+ },
486
+ };
487
+
488
+ expect(result).toMatchObject(expected);
489
+ });
490
+
491
+ it("should return an error if there's no staking position to unstake", async () => {
492
+ const account = createFixtureAccount({
493
+ balance: BigNumber(4),
494
+ spendableBalance: BigNumber(4),
495
+ });
496
+
497
+ const transaction = createFixtureTransaction({ mode: "unstake" });
498
+
499
+ const result = await getTransactionStatus(account, transaction);
500
+
501
+ const expected = {
502
+ errors: {
503
+ recipient: new RecipientRequired(),
504
+ },
505
+ };
506
+
507
+ expect(result).toMatchObject(expected);
508
+ });
509
+
510
+ it(`should return not enough to unstake if the amount to unstake is less than ${MIN_COINS_ON_SHARES_POOL} APT`, async () => {
511
+ const account = createFixtureAccount({
512
+ balance: BigNumber(4),
513
+ spendableBalance: BigNumber(4),
514
+ aptosResources,
515
+ });
516
+
517
+ const transaction = createFixtureTransaction({
518
+ mode: "unstake",
519
+ recipient: "validator-2",
520
+ amount: BigNumber(2),
521
+ fees: BigNumber(0.5),
522
+ });
523
+
524
+ const result = await getTransactionStatus(account, transaction);
525
+
526
+ const expected = {
527
+ errors: {
528
+ amount: new NotEnoughToUnstake(),
529
+ },
530
+ };
531
+
532
+ expect(result).toMatchObject(expected);
533
+ });
534
+
535
+ it("should return an error if there's no staking position to withdraw", async () => {
536
+ const account = createFixtureAccount({
537
+ balance: BigNumber(4),
538
+ spendableBalance: BigNumber(4),
539
+ });
540
+
541
+ const transaction = createFixtureTransaction({ mode: "withdraw" });
542
+
543
+ const result = await getTransactionStatus(account, transaction);
544
+
545
+ const expected = {
546
+ errors: {
547
+ recipient: new RecipientRequired(),
548
+ },
549
+ };
550
+
551
+ expect(result).toMatchObject(expected);
552
+ });
553
+
554
+ it("should return an error if there's not enough inactive balance to withdraw", async () => {
555
+ const account = createFixtureAccount({
556
+ balance: BigNumber(4),
557
+ spendableBalance: BigNumber(4),
558
+ aptosResources,
559
+ });
560
+
561
+ const transaction = createFixtureTransaction({
562
+ mode: "restake",
563
+ recipient: "validator-1",
564
+ amount: BigNumber(56756756745),
565
+ fees: BigNumber(1),
566
+ });
567
+
568
+ const result = await getTransactionStatus(account, transaction);
569
+
570
+ const expected = {
571
+ errors: {
572
+ amount: new NotEnoughBalance(),
573
+ },
574
+ };
575
+
576
+ expect(result).toMatchObject(expected);
577
+ });
334
578
  });
@@ -1,3 +1,7 @@
1
+ jest.mock("../../network/validators", () => ({
2
+ getValidators: jest.fn(() => Promise.resolve([])),
3
+ }));
4
+
1
5
  import BigNumber from "bignumber.js";
2
6
  import { createBridges } from "../../bridge";
3
7
  import { getCryptoCurrencyById } from "@ledgerhq/cryptoassets/currencies";
@@ -11,7 +15,7 @@ describe("Aptos bridge interface ", () => {
11
15
  const cryptoCurrency = getCryptoCurrencyById("aptos");
12
16
  const result = bridge.currencyBridge.preload(cryptoCurrency);
13
17
  expect(result).toBeInstanceOf(Promise);
14
- await expect(result).resolves.toEqual({});
18
+ await expect(result).resolves.toMatchObject({ validatorsWithMeta: [] });
15
19
  });
16
20
 
17
21
  it("should have a hydrate method that is a function", () => {
@@ -1,6 +1,6 @@
1
1
  import { EntryFunctionPayloadResponse } from "@aptos-labs/ts-sdk";
2
2
  import BigNumber from "bignumber.js";
3
- import { APTOS_COIN_CHANGE, DIRECTION } from "../../constants";
3
+ import { APTOS_COIN_CHANGE, OP_TYPE } from "../../constants";
4
4
  import { getMaxSendBalance, getBlankOperation, txsToOps } from "../../bridge/logic";
5
5
  import type { AptosTransaction, TransactionOptions } from "../../types";
6
6
  import { createFixtureAccount, createFixtureTransaction } from "../../bridge/bridge.fixture";
@@ -19,7 +19,7 @@ describe("Aptos logic ", () => {
19
19
  const transaction = createFixtureTransaction();
20
20
  const gas = new BigNumber(200);
21
21
  const gasPrice = new BigNumber(100);
22
- const result = getMaxSendBalance(gas, gasPrice, account, transaction);
22
+ const result = getMaxSendBalance(account, transaction, gas, gasPrice);
23
23
  expect(result.isEqualTo(amount.minus(gas.multipliedBy(gasPrice)))).toBe(true);
24
24
  });
25
25
 
@@ -28,7 +28,7 @@ describe("Aptos logic ", () => {
28
28
  const transaction = createFixtureTransaction();
29
29
  const gas = new BigNumber(200);
30
30
  const gasPrice = new BigNumber(100);
31
- const result = getMaxSendBalance(gas, gasPrice, account, transaction);
31
+ const result = getMaxSendBalance(account, transaction, gas, gasPrice);
32
32
  expect(result.isEqualTo(new BigNumber(0))).toBe(true);
33
33
  });
34
34
 
@@ -37,7 +37,7 @@ describe("Aptos logic ", () => {
37
37
  const transaction = createFixtureTransaction();
38
38
  const gas = new BigNumber(200);
39
39
  const gasPrice = new BigNumber(100);
40
- const result = getMaxSendBalance(gas, gasPrice, account, transaction);
40
+ const result = getMaxSendBalance(account, transaction, gas, gasPrice);
41
41
  expect(result.isEqualTo(new BigNumber(0))).toBe(true);
42
42
  });
43
43
 
@@ -46,7 +46,7 @@ describe("Aptos logic ", () => {
46
46
  const transaction = createFixtureTransaction();
47
47
  const gas = new BigNumber(200);
48
48
  const gasPrice = new BigNumber(100);
49
- const result = getMaxSendBalance(gas, gasPrice, account, transaction);
49
+ const result = getMaxSendBalance(account, transaction, gas, gasPrice);
50
50
  expect(result.isEqualTo(new BigNumber(0))).toBe(true);
51
51
  });
52
52
 
@@ -56,7 +56,7 @@ describe("Aptos logic ", () => {
56
56
  const transaction = createFixtureTransaction();
57
57
  const gas = new BigNumber(0);
58
58
  const gasPrice = new BigNumber(0);
59
- const result = getMaxSendBalance(gas, gasPrice, account, transaction);
59
+ const result = getMaxSendBalance(account, transaction, gas, gasPrice);
60
60
  expect(result.isEqualTo(amount)).toBe(true);
61
61
  });
62
62
  });
@@ -225,7 +225,7 @@ describe("Aptos sync logic ", () => {
225
225
  expect(result[0]).toEqual({
226
226
  id: expect.any(String),
227
227
  hash: "0x123",
228
- type: DIRECTION.OUT,
228
+ type: OP_TYPE.OUT,
229
229
  value: new BigNumber(100),
230
230
  fee: new BigNumber(20000),
231
231
  blockHash: "0xabc",
@@ -424,7 +424,7 @@ describe("Aptos sync logic ", () => {
424
424
  expect(result[0]).toEqual({
425
425
  id: expect.any(String),
426
426
  hash: "0x0189",
427
- type: DIRECTION.OUT,
427
+ type: OP_TYPE.OUT,
428
428
  value: new BigNumber(20000),
429
429
  fee: new BigNumber(20000),
430
430
  blockHash: "0xc496",
@@ -722,7 +722,7 @@ describe("Aptos sync logic ", () => {
722
722
  expect(tokenOps[0]).toEqual({
723
723
  id: expect.any(String),
724
724
  hash: "0x123",
725
- type: DIRECTION.OUT,
725
+ type: OP_TYPE.OUT,
726
726
  value: new BigNumber(1500000),
727
727
  fee: new BigNumber(20000),
728
728
  blockHash: "0xabc",
@@ -1018,7 +1018,7 @@ describe("Aptos sync logic ", () => {
1018
1018
  id: expect.any(String),
1019
1019
  accountId: "token_account_id",
1020
1020
  hash: "0x10c9",
1021
- type: DIRECTION.IN,
1021
+ type: OP_TYPE.IN,
1022
1022
  value: new BigNumber(193),
1023
1023
  fee: new BigNumber(20000),
1024
1024
  blockHash: "0xabc",
@@ -3,8 +3,7 @@ import { AptosAPI } from "../../network";
3
3
  import { getEstimatedGas } from "../../bridge/getFeesForTransaction";
4
4
  import { getMaxSendBalance } from "../../bridge/logic";
5
5
  import BigNumber from "bignumber.js";
6
- import type { Account } from "@ledgerhq/types-live";
7
- import type { Transaction } from "../../types";
6
+ import type { AptosAccount, Transaction } from "../../types";
8
7
 
9
8
  jest.mock("../../network");
10
9
  jest.mock("../../bridge/getFeesForTransaction");
@@ -12,7 +11,7 @@ jest.mock("../../bridge/logic");
12
11
 
13
12
  describe("Aptos prepareTransaction", () => {
14
13
  describe("prepareTransaction", () => {
15
- let account: Account;
14
+ let account: AptosAccount;
16
15
  let transaction: Transaction;
17
16
 
18
17
  beforeEach(() => {
@@ -33,13 +32,14 @@ describe("Aptos prepareTransaction", () => {
33
32
  unit: { code: "APT", name: "Aptos", magnitude: 6 },
34
33
  lastSyncDate: new Date(),
35
34
  subAccounts: [],
36
- } as unknown as Account;
35
+ } as unknown as AptosAccount;
37
36
 
38
37
  transaction = {
39
38
  amount: new BigNumber(0),
40
39
  recipient: "",
41
40
  useAllAmount: false,
42
41
  fees: new BigNumber(0),
42
+ mode: "send",
43
43
  } as Transaction;
44
44
  });
45
45
 
@@ -0,0 +1,103 @@
1
+ import BigNumber from "bignumber.js";
2
+ import {
3
+ assignFromAccountRaw,
4
+ assignToAccountRaw,
5
+ fromAptosResourcesRaw,
6
+ toAptosResourcesRaw,
7
+ } from "../../bridge/serialization";
8
+ import { createFixtureAccount } from "../../bridge/bridge.fixture";
9
+ import { AccountRaw } from "@ledgerhq/types-live";
10
+ import { AptosAccountRaw } from "../../types";
11
+
12
+ describe("serialization", () => {
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 aptosResources = {
35
+ activeBalance: BigNumber(9834759839345),
36
+ inactiveBalance: BigNumber(789346249),
37
+ pendingInactiveBalance: BigNumber(0),
38
+ stakingPositions,
39
+ };
40
+
41
+ const aptosResourcesRaw = {
42
+ activeBalance: "9834759839345",
43
+ pendingInactiveBalance: "0",
44
+ inactiveBalance: "789346249",
45
+ stakingPositions: [
46
+ {
47
+ active: "123456789",
48
+ pendingInactive: "5345",
49
+ inactive: "567567567",
50
+ validatorId: "validator-1",
51
+ },
52
+ {
53
+ active: "0",
54
+ pendingInactive: "67868678",
55
+ inactive: "33333",
56
+ validatorId: "validator-2",
57
+ },
58
+ {
59
+ active: "45864986459",
60
+ pendingInactive: "0",
61
+ inactive: "0",
62
+ validatorId: "validator-3",
63
+ },
64
+ ],
65
+ };
66
+
67
+ const account = createFixtureAccount({ aptosResources });
68
+
69
+ const accountRaw = {
70
+ id: "1",
71
+ seedIdentifier: "seedIdentifier",
72
+ derivationMode: "",
73
+ index: 1,
74
+ freshAddress: "freshAddress",
75
+ freshAddressPath: "freshAddressPath",
76
+ balance: "1234",
77
+ blockHeight: 1,
78
+ currencyId: "aptos",
79
+ operations: [],
80
+ pendingOperations: [],
81
+ lastSyncDate: "",
82
+ };
83
+
84
+ it("toAptosResourcesRaw", () => {
85
+ expect(toAptosResourcesRaw(aptosResources)).toMatchObject(aptosResourcesRaw);
86
+ });
87
+
88
+ it("fromAptosResourcesRaw", () => {
89
+ expect(fromAptosResourcesRaw(aptosResourcesRaw)).toMatchObject(aptosResources);
90
+ });
91
+
92
+ it("assignToAccountRaw", () => {
93
+ assignToAccountRaw(account, accountRaw as AccountRaw);
94
+ expect((accountRaw as unknown as AptosAccountRaw).aptosResources).toMatchObject(
95
+ aptosResourcesRaw,
96
+ );
97
+ });
98
+
99
+ it("assignFromAccountRaw", () => {
100
+ assignFromAccountRaw(accountRaw as AccountRaw, account);
101
+ expect((account as unknown as AptosAccountRaw).aptosResources).toMatchObject(aptosResources);
102
+ });
103
+ });