@ledgerhq/coin-aptos 2.2.0-next.0 → 2.2.0-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 (72) hide show
  1. package/.turbo/turbo-build.log +1 -1
  2. package/CHANGELOG.md +13 -8
  3. package/lib/__tests__/api/getBalance.unit.test.js +68 -28
  4. package/lib/__tests__/api/getBalance.unit.test.js.map +1 -1
  5. package/lib/__tests__/api/index.integ.test.js +16 -4
  6. package/lib/__tests__/api/index.integ.test.js.map +1 -1
  7. package/lib/__tests__/bridge/synchronisation.test.js +15 -6
  8. package/lib/__tests__/bridge/synchronisation.test.js.map +1 -1
  9. package/lib/__tests__/logic/getBalances.test.d.ts +2 -0
  10. package/lib/__tests__/logic/getBalances.test.d.ts.map +1 -0
  11. package/lib/__tests__/logic/getBalances.test.js +63 -0
  12. package/lib/__tests__/logic/getBalances.test.js.map +1 -0
  13. package/lib/__tests__/network/client.test.js +63 -63
  14. package/lib/__tests__/network/client.test.js.map +1 -1
  15. package/lib/api/index.js +2 -2
  16. package/lib/api/index.js.map +1 -1
  17. package/lib/bridge/synchronisation.d.ts.map +1 -1
  18. package/lib/bridge/synchronisation.js +7 -2
  19. package/lib/bridge/synchronisation.js.map +1 -1
  20. package/lib/logic/getBalances.d.ts +5 -0
  21. package/lib/logic/getBalances.d.ts.map +1 -0
  22. package/lib/logic/getBalances.js +21 -0
  23. package/lib/logic/getBalances.js.map +1 -0
  24. package/lib/network/client.d.ts +1 -5
  25. package/lib/network/client.d.ts.map +1 -1
  26. package/lib/network/client.js +25 -60
  27. package/lib/network/client.js.map +1 -1
  28. package/lib-es/__tests__/api/getBalance.unit.test.js +69 -26
  29. package/lib-es/__tests__/api/getBalance.unit.test.js.map +1 -1
  30. package/lib-es/__tests__/api/index.integ.test.js +16 -4
  31. package/lib-es/__tests__/api/index.integ.test.js.map +1 -1
  32. package/lib-es/__tests__/bridge/synchronisation.test.js +15 -6
  33. package/lib-es/__tests__/bridge/synchronisation.test.js.map +1 -1
  34. package/lib-es/__tests__/logic/getBalances.test.d.ts +2 -0
  35. package/lib-es/__tests__/logic/getBalances.test.d.ts.map +1 -0
  36. package/lib-es/__tests__/logic/getBalances.test.js +61 -0
  37. package/lib-es/__tests__/logic/getBalances.test.js.map +1 -0
  38. package/lib-es/__tests__/network/client.test.js +63 -63
  39. package/lib-es/__tests__/network/client.test.js.map +1 -1
  40. package/lib-es/api/index.js +2 -2
  41. package/lib-es/api/index.js.map +1 -1
  42. package/lib-es/bridge/synchronisation.d.ts.map +1 -1
  43. package/lib-es/bridge/synchronisation.js +4 -2
  44. package/lib-es/bridge/synchronisation.js.map +1 -1
  45. package/lib-es/logic/getBalances.d.ts +5 -0
  46. package/lib-es/logic/getBalances.d.ts.map +1 -0
  47. package/lib-es/logic/getBalances.js +17 -0
  48. package/lib-es/logic/getBalances.js.map +1 -0
  49. package/lib-es/network/client.d.ts +1 -5
  50. package/lib-es/network/client.d.ts.map +1 -1
  51. package/lib-es/network/client.js +25 -60
  52. package/lib-es/network/client.js.map +1 -1
  53. package/package.json +6 -6
  54. package/src/__tests__/api/craftTransaction.unit.test.ts +1 -1
  55. package/src/__tests__/api/getBalance.unit.test.ts +82 -28
  56. package/src/__tests__/api/index.integ.test.ts +19 -4
  57. package/src/__tests__/bridge/synchronisation.test.ts +21 -6
  58. package/src/__tests__/logic/getBalances.test.ts +80 -0
  59. package/src/__tests__/network/client.test.ts +70 -79
  60. package/src/api/index.ts +2 -2
  61. package/src/bridge/synchronisation.ts +4 -2
  62. package/src/logic/getBalances.ts +27 -0
  63. package/src/network/client.ts +26 -64
  64. package/lib/logic/getBalance.d.ts +0 -5
  65. package/lib/logic/getBalance.d.ts.map +0 -1
  66. package/lib/logic/getBalance.js +0 -12
  67. package/lib/logic/getBalance.js.map +0 -1
  68. package/lib-es/logic/getBalance.d.ts +0 -5
  69. package/lib-es/logic/getBalance.d.ts.map +0 -1
  70. package/lib-es/logic/getBalance.js +0 -8
  71. package/lib-es/logic/getBalance.js.map +0 -1
  72. package/src/logic/getBalance.ts +0 -15
@@ -36,7 +36,6 @@ import type {
36
36
  GetAccountTransactionsDataQuery,
37
37
  GetAccountTransactionsDataGtQueryVariables,
38
38
  } from "./graphql/types";
39
- import { TokenCurrency } from "@ledgerhq/types-cryptoassets";
40
39
  import {
41
40
  BlockInfo,
42
41
  FeeEstimation,
@@ -88,13 +87,12 @@ export class AptosAPI {
88
87
 
89
88
  async getAccountInfo(address: string, startAt?: string) {
90
89
  const [balance, transactions, blockHeight] = await Promise.all([
91
- this.getCoinBalance(address, APTOS_ASSET_ID),
90
+ this.getBalances(address, APTOS_ASSET_ID),
92
91
  this.fetchTransactions(address, startAt),
93
92
  this.getHeight(),
94
93
  ]);
95
-
96
94
  return {
97
- balance,
95
+ balance: balance[0].amount ?? BigInt(0),
98
96
  transactions,
99
97
  blockHeight,
100
98
  };
@@ -167,14 +165,6 @@ export class AptosAPI {
167
165
  return pendingTx.data.hash;
168
166
  }
169
167
 
170
- async getBalance(address: string, token: TokenCurrency): Promise<BigNumber> {
171
- if (token.tokenType === "coin") {
172
- return await this.getCoinBalance(address, token.contractAddress);
173
- }
174
-
175
- return await this.getFABalance(address, token.contractAddress);
176
- }
177
-
178
168
  async getLastBlock(): Promise<BlockInfo> {
179
169
  const { block_height } = await this.aptosClient.getLedgerInfo();
180
170
  const block = await this.aptosClient.getBlockByHeight({ blockHeight: Number(block_height) });
@@ -185,44 +175,6 @@ export class AptosAPI {
185
175
  };
186
176
  }
187
177
 
188
- async getCoinBalance(address: string, contract_address: string): Promise<BigNumber> {
189
- try {
190
- const [balanceStr] = await this.aptosClient.view<[string]>({
191
- payload: {
192
- function: "0x1::coin::balance",
193
- typeArguments: [contract_address],
194
- functionArguments: [address],
195
- },
196
- });
197
- const balance = parseInt(balanceStr, 10);
198
- return new BigNumber(balance);
199
- } catch (error) {
200
- log("error", "getCoinBalance", {
201
- error,
202
- });
203
- return new BigNumber(0);
204
- }
205
- }
206
-
207
- async getFABalance(address: string, contract_address: string): Promise<BigNumber> {
208
- try {
209
- const [balanceStr] = await this.aptosClient.view<[string]>({
210
- payload: {
211
- function: "0x1::primary_fungible_store::balance",
212
- typeArguments: ["0x1::object::ObjectCore"],
213
- functionArguments: [address, contract_address],
214
- },
215
- });
216
- const balance = parseInt(balanceStr, 10);
217
- return new BigNumber(balance);
218
- } catch (error) {
219
- log("error", "getFABalance", {
220
- error,
221
- });
222
- return new BigNumber(0);
223
- }
224
- }
225
-
226
178
  async estimateFees(transactionIntent: TransactionIntent<AptosAsset>): Promise<FeeEstimation> {
227
179
  const publicKeyEd = new Ed25519PublicKey(transactionIntent?.senderPublicKey ?? "");
228
180
 
@@ -349,21 +301,31 @@ export class AptosAPI {
349
301
  };
350
302
  }
351
303
 
352
- async getBalances(address: string): Promise<AptosBalance[]> {
353
- const response = await this.aptosClient.getCurrentFungibleAssetBalances({
354
- options: {
355
- offset: 0,
356
- limit: 1000,
357
- where: {
358
- asset_type: { _eq: APTOS_ASSET_ID }, // to return all asset balances (native / token) we should remove this filter
359
- owner_address: { _eq: address },
304
+ async getBalances(address: string, contractAddress?: string): Promise<AptosBalance[]> {
305
+ try {
306
+ const whereCondition: any = {
307
+ owner_address: { _eq: address },
308
+ };
309
+
310
+ if (contractAddress !== undefined && contractAddress !== "") {
311
+ whereCondition.asset_type = { _eq: contractAddress };
312
+ }
313
+
314
+ const response = await this.aptosClient.getCurrentFungibleAssetBalances({
315
+ options: {
316
+ where: whereCondition,
360
317
  },
361
- },
362
- });
318
+ });
363
319
 
364
- return response.map(x => ({
365
- contractAddress: x.asset_type ?? "-",
366
- amount: BigNumber(x.amount),
367
- }));
320
+ return response.map(x => ({
321
+ contractAddress: x.asset_type ?? "",
322
+ amount: BigNumber(x.amount),
323
+ }));
324
+ } catch (error) {
325
+ log("error", "getCoinBalance", {
326
+ error,
327
+ });
328
+ return [{ amount: BigNumber(0), contractAddress: "" }];
329
+ }
368
330
  }
369
331
  }
@@ -1,5 +0,0 @@
1
- import type { Balance } from "@ledgerhq/coin-framework/lib/api/types";
2
- import type { AptosAsset } from "../types/assets";
3
- import type { AptosAPI } from "../network";
4
- export declare function getBalance(aptosClient: AptosAPI, address: string): Promise<Balance<AptosAsset>[]>;
5
- //# sourceMappingURL=getBalance.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"getBalance.d.ts","sourceRoot":"","sources":["../../src/logic/getBalance.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,wCAAwC,CAAC;AACtE,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAClD,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAE3C,wBAAsB,UAAU,CAC9B,WAAW,EAAE,QAAQ,EACrB,OAAO,EAAE,MAAM,GACd,OAAO,CAAC,OAAO,CAAC,UAAU,CAAC,EAAE,CAAC,CAOhC"}
@@ -1,12 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getBalance = void 0;
4
- async function getBalance(aptosClient, address) {
5
- const balance = await aptosClient.getBalances(address);
6
- return balance.map(x => ({
7
- value: BigInt(x.amount.toString()),
8
- asset: { type: "native" },
9
- }));
10
- }
11
- exports.getBalance = getBalance;
12
- //# sourceMappingURL=getBalance.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"getBalance.js","sourceRoot":"","sources":["../../src/logic/getBalance.ts"],"names":[],"mappings":";;;AAIO,KAAK,UAAU,UAAU,CAC9B,WAAqB,EACrB,OAAe;IAEf,MAAM,OAAO,GAAG,MAAM,WAAW,CAAC,WAAW,CAAC,OAAO,CAAC,CAAC;IAEvD,OAAO,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC;QACvB,KAAK,EAAE,MAAM,CAAC,CAAC,CAAC,MAAM,CAAC,QAAQ,EAAE,CAAC;QAClC,KAAK,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE;KAC1B,CAAC,CAAC,CAAC;AACN,CAAC;AAVD,gCAUC"}
@@ -1,5 +0,0 @@
1
- import type { Balance } from "@ledgerhq/coin-framework/lib/api/types";
2
- import type { AptosAsset } from "../types/assets";
3
- import type { AptosAPI } from "../network";
4
- export declare function getBalance(aptosClient: AptosAPI, address: string): Promise<Balance<AptosAsset>[]>;
5
- //# sourceMappingURL=getBalance.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"getBalance.d.ts","sourceRoot":"","sources":["../../src/logic/getBalance.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,wCAAwC,CAAC;AACtE,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAClD,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAE3C,wBAAsB,UAAU,CAC9B,WAAW,EAAE,QAAQ,EACrB,OAAO,EAAE,MAAM,GACd,OAAO,CAAC,OAAO,CAAC,UAAU,CAAC,EAAE,CAAC,CAOhC"}
@@ -1,8 +0,0 @@
1
- export async function getBalance(aptosClient, address) {
2
- const balance = await aptosClient.getBalances(address);
3
- return balance.map(x => ({
4
- value: BigInt(x.amount.toString()),
5
- asset: { type: "native" },
6
- }));
7
- }
8
- //# sourceMappingURL=getBalance.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"getBalance.js","sourceRoot":"","sources":["../../src/logic/getBalance.ts"],"names":[],"mappings":"AAIA,MAAM,CAAC,KAAK,UAAU,UAAU,CAC9B,WAAqB,EACrB,OAAe;IAEf,MAAM,OAAO,GAAG,MAAM,WAAW,CAAC,WAAW,CAAC,OAAO,CAAC,CAAC;IAEvD,OAAO,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC;QACvB,KAAK,EAAE,MAAM,CAAC,CAAC,CAAC,MAAM,CAAC,QAAQ,EAAE,CAAC;QAClC,KAAK,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE;KAC1B,CAAC,CAAC,CAAC;AACN,CAAC"}
@@ -1,15 +0,0 @@
1
- import type { Balance } from "@ledgerhq/coin-framework/lib/api/types";
2
- import type { AptosAsset } from "../types/assets";
3
- import type { AptosAPI } from "../network";
4
-
5
- export async function getBalance(
6
- aptosClient: AptosAPI,
7
- address: string,
8
- ): Promise<Balance<AptosAsset>[]> {
9
- const balance = await aptosClient.getBalances(address);
10
-
11
- return balance.map(x => ({
12
- value: BigInt(x.amount.toString()),
13
- asset: { type: "native" },
14
- }));
15
- }