@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
@@ -1,5 +1,4 @@
1
1
  import { ApolloClient, InMemoryCache } from "@apollo/client";
2
-
3
2
  import {
4
3
  type AccountData,
5
4
  Aptos,
@@ -9,6 +8,7 @@ import {
9
8
  type InputEntryFunctionData,
10
9
  type InputGenerateTransactionOptions,
11
10
  MimeType,
11
+ MoveStructId,
12
12
  type RawTransaction,
13
13
  type SimpleTransaction,
14
14
  type TransactionResponse,
@@ -30,7 +30,12 @@ import {
30
30
  ESTIMATE_GAS_MUL,
31
31
  TOKEN_TYPE,
32
32
  } from "../constants";
33
- import type { AptosBalance, AptosTransaction, TransactionOptions } from "../types";
33
+ import type {
34
+ AptosBalance,
35
+ AptosTransaction,
36
+ StakePoolResource,
37
+ TransactionOptions,
38
+ } from "../types";
34
39
  import { GetAccountTransactionsData, GetAccountTransactionsDataGt } from "./graphql/queries";
35
40
  import type {
36
41
  GetAccountTransactionsDataQuery,
@@ -59,7 +64,8 @@ const getIndexerEndpoint = (currencyId: string) =>
59
64
  export class AptosAPI {
60
65
  private readonly aptosConfig: AptosConfig;
61
66
  private readonly aptosClient: Aptos;
62
- private readonly apolloClient: ApolloClient<object>;
67
+
68
+ readonly apolloClient: ApolloClient<object>;
63
69
 
64
70
  constructor(currencyIdOrSettings: AptosSettings | string) {
65
71
  if (typeof currencyIdOrSettings === "string") {
@@ -211,7 +217,9 @@ export class AptosAPI {
211
217
  const simulation = await this.simulateTransaction(publicKeyEd, tx);
212
218
  const completedTx = simulation[0];
213
219
 
214
- const gasLimit = new BigNumber(completedTx.gas_used).multipliedBy(ESTIMATE_GAS_MUL);
220
+ const gasLimit = new BigNumber(completedTx.gas_used)
221
+ .multipliedBy(ESTIMATE_GAS_MUL)
222
+ .integerValue();
215
223
  const gasPrice = new BigNumber(completedTx.gas_unit_price);
216
224
 
217
225
  const expectedGas = gasPrice.multipliedBy(gasLimit);
@@ -226,6 +234,38 @@ export class AptosAPI {
226
234
  };
227
235
  }
228
236
 
237
+ async getNextUnlockTime(stakingPoolAddress: string): Promise<string | undefined> {
238
+ const resourceType: MoveStructId = "0x1::stake::StakePool";
239
+ try {
240
+ const resource = await this.aptosClient.getAccountResource<StakePoolResource>({
241
+ accountAddress: stakingPoolAddress,
242
+ resourceType,
243
+ });
244
+ return resource.locked_until_secs;
245
+ } catch (error) {
246
+ log("error", "Failed to fetch StakePool resource:", { error });
247
+ }
248
+ }
249
+
250
+ async getDelegatorBalanceInPool(
251
+ poolAddress: string,
252
+ delegatorAddress: string,
253
+ ): Promise<Array<string>> {
254
+ try {
255
+ // Query the delegator balance in the pool
256
+ return await this.aptosClient.view<[string]>({
257
+ payload: {
258
+ function: "0x1::delegation_pool::get_stake",
259
+ typeArguments: [],
260
+ functionArguments: [poolAddress, delegatorAddress],
261
+ },
262
+ });
263
+ } catch (error) {
264
+ log("error", "Failed to fetch delegation_pool::get_stake", { error });
265
+ return ["0", "0", "0"];
266
+ }
267
+ }
268
+
229
269
  async listOperations(
230
270
  rawAddress: string,
231
271
  pagination: Pagination,
@@ -1,4 +1,3 @@
1
- // We need to target CJS for the CJS build of the lib
2
1
  import { gql } from "@apollo/client";
3
2
 
4
3
  export const GetDelegatedStakingActivities = gql`
@@ -16,6 +15,7 @@ export const GetDelegatedStakingActivities = gql`
16
15
  }
17
16
  }
18
17
  `;
18
+
19
19
  export const GetAccountTransactionsData = gql`
20
20
  query GetAccountTransactionsData($address: String, $limit: Int) {
21
21
  account_transactions(
@@ -28,6 +28,7 @@ export const GetAccountTransactionsData = gql`
28
28
  }
29
29
  }
30
30
  `;
31
+
31
32
  export const GetAccountTransactionsDataGt = gql`
32
33
  query GetAccountTransactionsDataGt($address: String, $limit: Int, $gt: bigint) {
33
34
  account_transactions(
@@ -40,6 +41,7 @@ export const GetAccountTransactionsDataGt = gql`
40
41
  }
41
42
  }
42
43
  `;
44
+
43
45
  export const GetAccountTransactionsDataLt = gql`
44
46
  query GetAccountTransactionsDataLt($address: String, $limit: Int, $lt: bigint) {
45
47
  account_transactions(
@@ -52,3 +54,46 @@ export const GetAccountTransactionsDataLt = gql`
52
54
  }
53
55
  }
54
56
  `;
57
+
58
+ export const GetNumActiveDelegatorPerPoolData = gql`
59
+ query GetNumActiveDelegatorPerPoolData {
60
+ num_active_delegator_per_pool {
61
+ num_active_delegator
62
+ pool_address
63
+ }
64
+ delegated_staking_pools {
65
+ staking_pool_address
66
+ current_staking_pool {
67
+ operator_address
68
+ operator_aptos_name(where: { is_active: { _eq: true } }) {
69
+ domain
70
+ is_primary
71
+ }
72
+ }
73
+ }
74
+ }
75
+ `;
76
+
77
+ export const GetCurrentDelegatorBalancesData = gql`
78
+ query GetCurrentDelegatorBalances {
79
+ current_delegator_balances(
80
+ distinct_on: pool_address
81
+ order_by: { current_pool_balance: { total_coins: desc }, pool_address: asc }
82
+ ) {
83
+ current_pool_balance {
84
+ total_coins
85
+ operator_commission_percentage
86
+ staking_pool_address
87
+ total_shares
88
+ }
89
+ shares
90
+ delegator_address
91
+ staking_pool_metadata {
92
+ operator_aptos_name {
93
+ domain_with_suffix
94
+ is_active
95
+ }
96
+ }
97
+ }
98
+ }
99
+ `;
@@ -21,9 +21,7 @@ export type GetAccountTransactionsDataQueryVariables = Exact<{
21
21
  }>;
22
22
 
23
23
  export type GetAccountTransactionsDataQuery = {
24
- __typename?: "query_root";
25
24
  account_transactions: Array<{
26
- __typename?: "account_transactions";
27
25
  transaction_version: number;
28
26
  }>;
29
27
  };
@@ -35,9 +33,7 @@ export type GetAccountTransactionsDataGtQueryVariables = Exact<{
35
33
  }>;
36
34
 
37
35
  export type GetAccountTransactionsDataGtQuery = {
38
- __typename?: "query_root";
39
36
  account_transactions: Array<{
40
- __typename?: "account_transactions";
41
37
  transaction_version: number;
42
38
  }>;
43
39
  };
@@ -49,9 +45,7 @@ export type GetAccountTransactionsDataLtQueryVariables = Exact<{
49
45
  }>;
50
46
 
51
47
  export type GetAccountTransactionsDataLtQuery = {
52
- __typename?: "query_root";
53
48
  account_transactions: Array<{
54
- __typename?: "account_transactions";
55
49
  transaction_version: number;
56
50
  }>;
57
51
  };
@@ -83,3 +77,66 @@ export type StakeDetails = {
83
77
  canWithdrawPendingInactive: boolean;
84
78
  poolAddress: string;
85
79
  };
80
+
81
+ export type GetNumActiveDelegatorPerPoolQuery = {
82
+ num_active_delegator_per_pool: Array<{
83
+ pool_address: string;
84
+ num_active_delegator: number;
85
+ }>;
86
+ delegated_staking_pools: Array<{
87
+ staking_pool_address: string;
88
+ current_staking_pool: {
89
+ operator_address: string;
90
+ operator_aptos_name: Array<{
91
+ domain: string;
92
+ is_primary: boolean;
93
+ }>;
94
+ };
95
+ }>;
96
+ };
97
+
98
+ export type GetCurrentDelegatorBalancesQuery = {
99
+ current_delegator_balances: Array<{
100
+ current_pool_balance: {
101
+ total_coins: string;
102
+ operator_commission_percentage: string;
103
+ staking_pool_address: string;
104
+ total_shares: string;
105
+ };
106
+ shares: string;
107
+ delegator_address: string;
108
+ staking_pool_metadata: {
109
+ operator_aptos_name: {
110
+ domain_with_suffix: string;
111
+ is_active: boolean;
112
+ };
113
+ };
114
+ }>;
115
+ };
116
+
117
+ export interface DelegationPoolAddress {
118
+ staking_pool_address: string;
119
+ }
120
+
121
+ interface CurrentPoolBalance {
122
+ total_coins: string;
123
+ operator_commission_percentage: string;
124
+ staking_pool_address: string;
125
+ total_shares: string;
126
+ }
127
+
128
+ interface StakingPoolMetadata {
129
+ operator_aptos_name: OperatorAptosName;
130
+ }
131
+
132
+ interface OperatorAptosName {
133
+ domain_with_suffix: string;
134
+ is_active: boolean;
135
+ }
136
+
137
+ export interface CurrentDelegatorBalance {
138
+ shares: string;
139
+ delegator_address: string;
140
+ current_pool_balance: CurrentPoolBalance;
141
+ staking_pool_metadata: StakingPoolMetadata;
142
+ }
@@ -11,6 +11,7 @@ import { Account } from "@ledgerhq/types-live";
11
11
  import { AptosSigner } from "../types";
12
12
  import { sha3_256 as sha3Hash } from "@noble/hashes/sha3";
13
13
  import { combineSignedTransaction } from "../logic/combine";
14
+
14
15
  export * from "./client";
15
16
 
16
17
  export async function signTransaction(
@@ -0,0 +1,48 @@
1
+ import BigNumber from "bignumber.js";
2
+ import { AptosAPI } from "../network";
3
+ import { GetCurrentDelegatorBalancesData } from "./graphql/queries";
4
+ import { CurrentDelegatorBalance, GetCurrentDelegatorBalancesQuery } from "./graphql/types";
5
+ import { AptosValidator } from "../types";
6
+ import { isTestnet } from "../logic/isTestnet";
7
+ import { APTOS_EXPLORER_ACCOUNT_URL } from "../constants";
8
+ import { formatUnlockTime } from "../logic/staking";
9
+
10
+ export async function getValidators(currencyId: string): Promise<AptosValidator[]> {
11
+ const api = new AptosAPI(currencyId);
12
+ const query = GetCurrentDelegatorBalancesData;
13
+ const queryResponse = await api.apolloClient.query<GetCurrentDelegatorBalancesQuery, object>({
14
+ query: query,
15
+ fetchPolicy: "network-only",
16
+ });
17
+
18
+ const stakingData: CurrentDelegatorBalance[] = queryResponse.data.current_delegator_balances;
19
+
20
+ const list: AptosValidator[] = await Promise.all(
21
+ stakingData.map(async pool => {
22
+ const aptosName = pool.staking_pool_metadata.operator_aptos_name;
23
+ const naming =
24
+ Array.isArray(aptosName) && aptosName.length > 0 && aptosName[0].domain_with_suffix
25
+ ? aptosName[0].domain_with_suffix
26
+ : pool.current_pool_balance.staking_pool_address;
27
+
28
+ const url = `${APTOS_EXPLORER_ACCOUNT_URL}/${pool.current_pool_balance.staking_pool_address}?network=${isTestnet(currencyId) ? "testnet" : "mainnet"}`;
29
+
30
+ const unblockdata = await api.getNextUnlockTime(
31
+ pool.current_pool_balance.staking_pool_address,
32
+ );
33
+ const nextUnlockTime = unblockdata ? formatUnlockTime(unblockdata) : undefined; //`${30}d ${20}h ${30}m`;
34
+
35
+ return {
36
+ commission: BigNumber(pool.current_pool_balance.operator_commission_percentage).div(100),
37
+ activeStake: BigNumber(pool.current_pool_balance.total_coins),
38
+ address: pool.current_pool_balance.staking_pool_address,
39
+ name: naming,
40
+ shares: pool.current_pool_balance.total_shares,
41
+ wwwUrl: url,
42
+ nextUnlockTime: nextUnlockTime,
43
+ };
44
+ }),
45
+ );
46
+
47
+ return list.sort((a, b) => b.activeStake.toNumber() - a.activeStake.toNumber());
48
+ }
@@ -0,0 +1,43 @@
1
+ import { CryptoCurrency } from "@ledgerhq/types-cryptoassets";
2
+ import { BehaviorSubject, Observable } from "rxjs";
3
+ import { AptosPreloadData } from "./types";
4
+
5
+ const initialData: AptosPreloadData = {
6
+ validatorsWithMeta: [],
7
+ validators: [],
8
+ };
9
+
10
+ const dataByCurrency = new Map<string, AptosPreloadData>([
11
+ ["aptos", initialData],
12
+ ["aptos_testnet", initialData],
13
+ ]);
14
+
15
+ const dataUpdatesByCurrency = new Map([
16
+ ["aptos", new BehaviorSubject<AptosPreloadData>(initialData)],
17
+ ["aptos_testnet", new BehaviorSubject<AptosPreloadData>(initialData)],
18
+ ]);
19
+
20
+ export function setAptosPreloadData(data: AptosPreloadData, currency: CryptoCurrency): void {
21
+ dataByCurrency.set(currency.id, data ?? initialData);
22
+ const subject = dataUpdatesByCurrency.get(currency.id);
23
+ if (subject === undefined) {
24
+ throw new Error(`unsupported currency ${currency.id}`);
25
+ }
26
+ subject.next(data);
27
+ }
28
+
29
+ export function getAptosPreloadData(currency: CryptoCurrency): Observable<AptosPreloadData> {
30
+ const subject = dataUpdatesByCurrency.get(currency.id);
31
+ if (subject === undefined) {
32
+ throw new Error(`unsupported currency ${currency.id}`);
33
+ }
34
+ return subject.asObservable();
35
+ }
36
+
37
+ export function getCurrentAptosPreloadData(currency: CryptoCurrency): AptosPreloadData {
38
+ const data = dataByCurrency.get(currency.id);
39
+ if (data === undefined) {
40
+ throw new Error(`unsupported currency ${currency.id}`);
41
+ }
42
+ return data;
43
+ }
package/src/preload.ts ADDED
@@ -0,0 +1,23 @@
1
+ import { CryptoCurrency } from "@ledgerhq/types-cryptoassets";
2
+ import { setAptosPreloadData } from "./preload-data";
3
+ import { AptosPreloadData, AptosValidator } from "./types";
4
+ import { getValidators } from "./network/validators";
5
+
6
+ export const PRELOAD_MAX_AGE = 15 * 60 * 1000; // 15min
7
+
8
+ export async function preloadWithValidators(currency: CryptoCurrency): Promise<AptosPreloadData> {
9
+ const validators: AptosValidator[] = await getValidators(currency.id);
10
+
11
+ const data: AptosPreloadData = {
12
+ validatorsWithMeta: [],
13
+ validators,
14
+ };
15
+
16
+ setAptosPreloadData(data, currency);
17
+
18
+ return data;
19
+ }
20
+
21
+ export function hydrate(data: AptosPreloadData, currency: CryptoCurrency): void {
22
+ setAptosPreloadData(data, currency);
23
+ }
@@ -2,6 +2,7 @@ import { CurrenciesData, DatasetTest } from "@ledgerhq/types-live";
2
2
  import { Transaction } from "../types";
3
3
 
4
4
  const aptos: CurrenciesData<Transaction> = {
5
+ FIXME_ignorePreloadFields: ["validators"],
5
6
  scanAccounts: [
6
7
  {
7
8
  name: "aptos seed 1",
@@ -1,6 +1,7 @@
1
1
  import type { UserTransactionResponse } from "@aptos-labs/ts-sdk";
2
2
  import type {
3
3
  Account,
4
+ AccountRaw,
4
5
  Operation,
5
6
  TransactionCommon,
6
7
  TransactionCommonRaw,
@@ -8,6 +9,7 @@ import type {
8
9
  TransactionStatusCommonRaw,
9
10
  } from "@ledgerhq/types-live";
10
11
  import type { BigNumber } from "bignumber.js";
12
+
11
13
  export * from "./signer";
12
14
  export * from "./bridge";
13
15
 
@@ -18,9 +20,15 @@ export type AptosTransaction = UserTransactionResponse & {
18
20
  };
19
21
  };
20
22
 
21
- export type AptosOperation = Operation;
23
+ export type AptosOperation = Operation<AptosOperationExtra>;
24
+
25
+ export type AptosOperationRaw = Operation<AptosOperationExtraRaw>;
26
+
27
+ export type AptosAccount = Account & { aptosResources: AptosResources };
22
28
 
23
- export type AptosAccount = Account;
29
+ export type AptosAccountRaw = AccountRaw & {
30
+ aptosResources: AptosResourcesRaw;
31
+ };
24
32
 
25
33
  export type TransactionStatus = TransactionStatusCommon;
26
34
 
@@ -43,19 +51,14 @@ export type AptosAddress = {
43
51
  path: string;
44
52
  };
45
53
 
46
- export interface TransactionOptions {
47
- maxGasAmount: string;
48
- gasUnitPrice: string;
49
- }
50
-
51
54
  export type TransactionErrors = {
52
55
  maxGasAmount?: string;
53
56
  gasUnitPrice?: string;
54
57
  };
55
58
 
56
59
  export type Transaction = TransactionCommon & {
57
- mode: string;
58
60
  family: "aptos";
61
+ mode: string;
59
62
  fees?: BigNumber | null;
60
63
  options: TransactionOptions;
61
64
  errors?: TransactionErrors;
@@ -87,6 +90,101 @@ export type AptosMoveResource = {
87
90
  [key: string]: AptosMoveResourceData;
88
91
  };
89
92
 
93
+ export type AptosOperationExtra = {
94
+ stake?: ExtraStakeInfo;
95
+ };
96
+
97
+ export type ExtraStakeInfo = {
98
+ address: string;
99
+ amount: BigNumber;
100
+ };
101
+
102
+ export type AptosOperationExtraRaw = {
103
+ stake?: ExtraStakeInfoRaw;
104
+ };
105
+
106
+ export type ExtraStakeInfoRaw = {
107
+ address: string;
108
+ amount: string;
109
+ };
110
+
111
+ export type AptosResources = {
112
+ activeBalance: BigNumber;
113
+ inactiveBalance: BigNumber;
114
+ pendingInactiveBalance: BigNumber;
115
+ stakingPositions: AptosStakingPosition[];
116
+ };
117
+
118
+ export type AptosResourcesRaw = {
119
+ activeBalance: string;
120
+ pendingInactiveBalance: string;
121
+ inactiveBalance: string;
122
+ stakingPositions: {
123
+ active: string;
124
+ pendingInactive: string;
125
+ inactive: string;
126
+ validatorId: string;
127
+ }[];
128
+ };
129
+
130
+ export type AptosStakingPosition = {
131
+ active: BigNumber;
132
+ inactive: BigNumber;
133
+ pendingInactive: BigNumber;
134
+ validatorId: string;
135
+ };
136
+
137
+ export type AptosMappedStakingPosition = AptosStakingPosition & {
138
+ formattedAmount: string;
139
+ formattedPending: string;
140
+ formattedAvailable: string;
141
+ rank: number;
142
+ validator: AptosValidator | null | undefined;
143
+ };
144
+
145
+ export type AptosValidator = {
146
+ activeStake: BigNumber;
147
+ commission: BigNumber;
148
+ address: string;
149
+ name?: string | undefined;
150
+ shares: string;
151
+ avatarUrl?: string | undefined;
152
+ wwwUrl?: string | undefined;
153
+ nextUnlockTime?: string | undefined;
154
+ };
155
+
156
+ export type AptosValidatorRaw = {
157
+ active_stake?: number | null;
158
+ commission?: number | null;
159
+ addr?: string | null;
160
+ name?: string | null;
161
+ shares: string;
162
+ avatar_url?: string | null;
163
+ www_url?: string | null;
164
+ nextUnlockTime?: string | undefined;
165
+ };
166
+
167
+ export type AptosValidatorWithMeta = {
168
+ validator: AptosValidator;
169
+ meta: {
170
+ name?: string;
171
+ img?: string;
172
+ };
173
+ };
174
+
175
+ export type AptosPreloadData = {
176
+ validatorsWithMeta: AptosValidatorWithMeta[];
177
+ validators: AptosValidator[];
178
+ };
179
+
180
+ export interface TransactionOptions {
181
+ maxGasAmount: string;
182
+ gasUnitPrice: string;
183
+ }
184
+
185
+ export interface StakePoolResource {
186
+ locked_until_secs: string;
187
+ }
90
188
  export type AptosBalance = {
91
189
  contractAddress: string;
92
190
  amount: BigNumber;