@ledgerhq/coin-aptos 2.2.0-next.1 → 2.2.0-nightly.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (97) hide show
  1. package/.turbo/turbo-build.log +1 -1
  2. package/CHANGELOG.md +19 -15
  3. package/lib/__tests__/api/craftTransaction.unit.test.js +16 -31
  4. package/lib/__tests__/api/craftTransaction.unit.test.js.map +1 -1
  5. package/lib/__tests__/api/getBalance.unit.test.js +68 -28
  6. package/lib/__tests__/api/getBalance.unit.test.js.map +1 -1
  7. package/lib/__tests__/api/index.integ.test.js +30 -11
  8. package/lib/__tests__/api/index.integ.test.js.map +1 -1
  9. package/lib/__tests__/api/index.test.js.map +1 -1
  10. package/lib/__tests__/bridge/synchronisation.test.js +15 -6
  11. package/lib/__tests__/bridge/synchronisation.test.js.map +1 -1
  12. package/lib/__tests__/logic/getBalances.test.d.ts +2 -0
  13. package/lib/__tests__/logic/getBalances.test.d.ts.map +1 -0
  14. package/lib/__tests__/logic/getBalances.test.js +63 -0
  15. package/lib/__tests__/logic/getBalances.test.js.map +1 -0
  16. package/lib/__tests__/network/client.test.js +69 -66
  17. package/lib/__tests__/network/client.test.js.map +1 -1
  18. package/lib/api/index.d.ts +3 -3
  19. package/lib/api/index.d.ts.map +1 -1
  20. package/lib/api/index.js +2 -2
  21. package/lib/api/index.js.map +1 -1
  22. package/lib/bridge/synchronisation.d.ts.map +1 -1
  23. package/lib/bridge/synchronisation.js +7 -2
  24. package/lib/bridge/synchronisation.js.map +1 -1
  25. package/lib/logic/craftTransaction.d.ts +2 -2
  26. package/lib/logic/craftTransaction.d.ts.map +1 -1
  27. package/lib/logic/craftTransaction.js +3 -3
  28. package/lib/logic/craftTransaction.js.map +1 -1
  29. package/lib/logic/getBalances.d.ts +5 -0
  30. package/lib/logic/getBalances.d.ts.map +1 -0
  31. package/lib/logic/getBalances.js +21 -0
  32. package/lib/logic/getBalances.js.map +1 -0
  33. package/lib/network/client.d.ts +3 -7
  34. package/lib/network/client.d.ts.map +1 -1
  35. package/lib/network/client.js +28 -62
  36. package/lib/network/client.js.map +1 -1
  37. package/lib/types/assets.d.ts +0 -4
  38. package/lib/types/assets.d.ts.map +1 -1
  39. package/lib-es/__tests__/api/craftTransaction.unit.test.js +16 -31
  40. package/lib-es/__tests__/api/craftTransaction.unit.test.js.map +1 -1
  41. package/lib-es/__tests__/api/getBalance.unit.test.js +69 -26
  42. package/lib-es/__tests__/api/getBalance.unit.test.js.map +1 -1
  43. package/lib-es/__tests__/api/index.integ.test.js +30 -11
  44. package/lib-es/__tests__/api/index.integ.test.js.map +1 -1
  45. package/lib-es/__tests__/api/index.test.js.map +1 -1
  46. package/lib-es/__tests__/bridge/synchronisation.test.js +15 -6
  47. package/lib-es/__tests__/bridge/synchronisation.test.js.map +1 -1
  48. package/lib-es/__tests__/logic/getBalances.test.d.ts +2 -0
  49. package/lib-es/__tests__/logic/getBalances.test.d.ts.map +1 -0
  50. package/lib-es/__tests__/logic/getBalances.test.js +61 -0
  51. package/lib-es/__tests__/logic/getBalances.test.js.map +1 -0
  52. package/lib-es/__tests__/network/client.test.js +69 -66
  53. package/lib-es/__tests__/network/client.test.js.map +1 -1
  54. package/lib-es/api/index.d.ts +3 -3
  55. package/lib-es/api/index.d.ts.map +1 -1
  56. package/lib-es/api/index.js +2 -2
  57. package/lib-es/api/index.js.map +1 -1
  58. package/lib-es/bridge/synchronisation.d.ts.map +1 -1
  59. package/lib-es/bridge/synchronisation.js +4 -2
  60. package/lib-es/bridge/synchronisation.js.map +1 -1
  61. package/lib-es/logic/craftTransaction.d.ts +2 -2
  62. package/lib-es/logic/craftTransaction.d.ts.map +1 -1
  63. package/lib-es/logic/craftTransaction.js +3 -3
  64. package/lib-es/logic/craftTransaction.js.map +1 -1
  65. package/lib-es/logic/getBalances.d.ts +5 -0
  66. package/lib-es/logic/getBalances.d.ts.map +1 -0
  67. package/lib-es/logic/getBalances.js +17 -0
  68. package/lib-es/logic/getBalances.js.map +1 -0
  69. package/lib-es/network/client.d.ts +3 -7
  70. package/lib-es/network/client.d.ts.map +1 -1
  71. package/lib-es/network/client.js +28 -62
  72. package/lib-es/network/client.js.map +1 -1
  73. package/lib-es/types/assets.d.ts +0 -4
  74. package/lib-es/types/assets.d.ts.map +1 -1
  75. package/package.json +8 -8
  76. package/src/__tests__/api/craftTransaction.unit.test.ts +23 -38
  77. package/src/__tests__/api/getBalance.unit.test.ts +82 -28
  78. package/src/__tests__/api/index.integ.test.ts +36 -15
  79. package/src/__tests__/api/index.test.ts +4 -6
  80. package/src/__tests__/bridge/synchronisation.test.ts +21 -6
  81. package/src/__tests__/logic/getBalances.test.ts +80 -0
  82. package/src/__tests__/network/client.test.ts +83 -89
  83. package/src/api/index.ts +6 -8
  84. package/src/bridge/synchronisation.ts +4 -2
  85. package/src/logic/craftTransaction.ts +6 -8
  86. package/src/logic/getBalances.ts +27 -0
  87. package/src/network/client.ts +31 -74
  88. package/src/types/assets.ts +0 -5
  89. package/lib/logic/getBalance.d.ts +0 -5
  90. package/lib/logic/getBalance.d.ts.map +0 -1
  91. package/lib/logic/getBalance.js +0 -12
  92. package/lib/logic/getBalance.js.map +0 -1
  93. package/lib-es/logic/getBalance.d.ts +0 -5
  94. package/lib-es/logic/getBalance.d.ts.map +0 -1
  95. package/lib-es/logic/getBalance.js +0 -8
  96. package/lib-es/logic/getBalance.js.map +0 -1
  97. 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,
@@ -44,7 +43,7 @@ import {
44
43
  Pagination,
45
44
  TransactionIntent,
46
45
  } from "@ledgerhq/coin-framework/api/types";
47
- import { AptosAsset, AptosExtra, AptosFeeParameters, AptosSender } from "../types/assets";
46
+ import { AptosAsset } from "../types/assets";
48
47
  import { log } from "@ledgerhq/logs";
49
48
  import { transactionsToOperations } from "../logic/transactionsToOperations";
50
49
  import { isTestnet } from "../logic/isTestnet";
@@ -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,48 +175,8 @@ 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
- async estimateFees(
227
- transactionIntent: TransactionIntent<AptosAsset, AptosExtra, AptosSender>,
228
- ): Promise<FeeEstimation<AptosFeeParameters>> {
229
- const publicKeyEd = new Ed25519PublicKey(transactionIntent.sender.xpub);
178
+ async estimateFees(transactionIntent: TransactionIntent<AptosAsset>): Promise<FeeEstimation> {
179
+ const publicKeyEd = new Ed25519PublicKey(transactionIntent?.senderPublicKey ?? "");
230
180
 
231
181
  const txPayload: InputEntryFunctionData = {
232
182
  function: "0x1::aptos_account::transfer_coins",
@@ -256,11 +206,7 @@ export class AptosAPI {
256
206
  gasUnitPrice: DEFAULT_GAS_PRICE.toString(),
257
207
  };
258
208
 
259
- const tx = await this.generateTransaction(
260
- transactionIntent.sender.freshAddress,
261
- txPayload,
262
- txOptions,
263
- );
209
+ const tx = await this.generateTransaction(transactionIntent.sender, txPayload, txOptions);
264
210
 
265
211
  const simulation = await this.simulateTransaction(publicKeyEd, tx);
266
212
  const completedTx = simulation[0];
@@ -273,6 +219,7 @@ export class AptosAPI {
273
219
  return {
274
220
  value: BigInt(expectedGas.toString()),
275
221
  parameters: {
222
+ storageLimit: BigInt(0),
276
223
  gasLimit: BigInt(gasLimit.toString()),
277
224
  gasPrice: BigInt(gasPrice.toString()),
278
225
  },
@@ -354,21 +301,31 @@ export class AptosAPI {
354
301
  };
355
302
  }
356
303
 
357
- async getBalances(address: string): Promise<AptosBalance[]> {
358
- const response = await this.aptosClient.getCurrentFungibleAssetBalances({
359
- options: {
360
- offset: 0,
361
- limit: 1000,
362
- where: {
363
- asset_type: { _eq: APTOS_ASSET_ID }, // to return all asset balances (native / token) we should remove this filter
364
- 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,
365
317
  },
366
- },
367
- });
318
+ });
368
319
 
369
- return response.map(x => ({
370
- contractAddress: x.asset_type ?? "-",
371
- amount: BigNumber(x.amount),
372
- }));
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
+ }
373
330
  }
374
331
  }
@@ -9,11 +9,6 @@ export type AptosTokenInformation = {
9
9
 
10
10
  export type AptosExtra = Record<string, unknown>;
11
11
 
12
- export type AptosSender = {
13
- xpub: string;
14
- freshAddress: string;
15
- };
16
-
17
12
  export type AptosFeeParameters = {
18
13
  gasLimit: bigint;
19
14
  gasPrice: bigint;
@@ -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
- }