@ledgerhq/coin-aptos 2.2.0-nightly.3 → 2.2.1-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 (51) hide show
  1. package/.turbo/turbo-build.log +1 -1
  2. package/CHANGELOG.md +32 -20
  3. package/lib/__tests__/api/craftTransaction.unit.test.js +31 -16
  4. package/lib/__tests__/api/craftTransaction.unit.test.js.map +1 -1
  5. package/lib/__tests__/api/index.integ.test.js +7 -14
  6. package/lib/__tests__/api/index.integ.test.js.map +1 -1
  7. package/lib/__tests__/api/index.test.js.map +1 -1
  8. package/lib/__tests__/network/client.test.js +3 -6
  9. package/lib/__tests__/network/client.test.js.map +1 -1
  10. package/lib/api/index.d.ts +3 -3
  11. package/lib/api/index.d.ts.map +1 -1
  12. package/lib/api/index.js.map +1 -1
  13. package/lib/logic/craftTransaction.d.ts +2 -2
  14. package/lib/logic/craftTransaction.d.ts.map +1 -1
  15. package/lib/logic/craftTransaction.js +3 -3
  16. package/lib/logic/craftTransaction.js.map +1 -1
  17. package/lib/network/client.d.ts +2 -2
  18. package/lib/network/client.d.ts.map +1 -1
  19. package/lib/network/client.js +2 -3
  20. package/lib/network/client.js.map +1 -1
  21. package/lib/types/assets.d.ts +4 -0
  22. package/lib/types/assets.d.ts.map +1 -1
  23. package/lib-es/__tests__/api/craftTransaction.unit.test.js +31 -16
  24. package/lib-es/__tests__/api/craftTransaction.unit.test.js.map +1 -1
  25. package/lib-es/__tests__/api/index.integ.test.js +7 -14
  26. package/lib-es/__tests__/api/index.integ.test.js.map +1 -1
  27. package/lib-es/__tests__/api/index.test.js.map +1 -1
  28. package/lib-es/__tests__/network/client.test.js +3 -6
  29. package/lib-es/__tests__/network/client.test.js.map +1 -1
  30. package/lib-es/api/index.d.ts +3 -3
  31. package/lib-es/api/index.d.ts.map +1 -1
  32. package/lib-es/api/index.js.map +1 -1
  33. package/lib-es/logic/craftTransaction.d.ts +2 -2
  34. package/lib-es/logic/craftTransaction.d.ts.map +1 -1
  35. package/lib-es/logic/craftTransaction.js +3 -3
  36. package/lib-es/logic/craftTransaction.js.map +1 -1
  37. package/lib-es/network/client.d.ts +2 -2
  38. package/lib-es/network/client.d.ts.map +1 -1
  39. package/lib-es/network/client.js +2 -3
  40. package/lib-es/network/client.js.map +1 -1
  41. package/lib-es/types/assets.d.ts +4 -0
  42. package/lib-es/types/assets.d.ts.map +1 -1
  43. package/package.json +6 -6
  44. package/src/__tests__/api/craftTransaction.unit.test.ts +37 -22
  45. package/src/__tests__/api/index.integ.test.ts +11 -17
  46. package/src/__tests__/api/index.test.ts +6 -4
  47. package/src/__tests__/network/client.test.ts +10 -13
  48. package/src/api/index.ts +6 -4
  49. package/src/logic/craftTransaction.ts +8 -6
  50. package/src/network/client.ts +10 -5
  51. package/src/types/assets.ts +5 -0
@@ -1,6 +1,6 @@
1
1
  import { Aptos } from "@aptos-labs/ts-sdk";
2
- import type { AlpacaApi } from "@ledgerhq/coin-framework/api/types";
3
- import type { AptosAsset } from "../../types/assets";
2
+ import type { Api } from "@ledgerhq/coin-framework/api/types";
3
+ import type { AptosAsset, AptosExtra, AptosFeeParameters, AptosSender } from "../../types/assets";
4
4
  import type { AptosConfig } from "../../config";
5
5
  import { createApi } from "../../api";
6
6
  import coinConfig from "../../config";
@@ -33,7 +33,8 @@ describe("createApi", () => {
33
33
  });
34
34
 
35
35
  it("should return an API object with alpaca api methods", () => {
36
- const api: AlpacaApi<AptosAsset> = createApi(mockAptosConfig);
36
+ const api: Api<AptosAsset, AptosExtra, AptosSender, AptosFeeParameters> =
37
+ createApi(mockAptosConfig);
37
38
 
38
39
  // Check that methods are set with what we expect
39
40
  expect(api.broadcast).toBeDefined();
@@ -69,7 +70,8 @@ describe("lastBlock", () => {
69
70
  }),
70
71
  }));
71
72
 
72
- const api: AlpacaApi<AptosAsset> = createApi(mockAptosConfig);
73
+ const api: Api<AptosAsset, AptosExtra, AptosSender, AptosFeeParameters> =
74
+ createApi(mockAptosConfig);
73
75
 
74
76
  expect(await api.lastBlock()).toStrictEqual({
75
77
  height: 123,
@@ -14,7 +14,7 @@ import {
14
14
  import network from "@ledgerhq/live-network";
15
15
  import BigNumber from "bignumber.js";
16
16
  import { AptosAPI } from "../../network";
17
- import { AptosAsset } from "../../types/assets";
17
+ import { AptosAsset, AptosExtra, AptosSender } from "../../types/assets";
18
18
  import { Pagination, TransactionIntent } from "@ledgerhq/coin-framework/api/types";
19
19
  import { APTOS_ASSET_ID } from "../../constants";
20
20
  import { AptosBalance, AptosTransaction } from "../../types";
@@ -559,20 +559,19 @@ describe("Aptos API", () => {
559
559
  }));
560
560
 
561
561
  const amount = BigInt(100);
562
- const sender = {
562
+ const sender: AptosSender = {
563
563
  xpub: "xpub",
564
564
  freshAddress: "address1",
565
565
  };
566
566
  const recipient = "address2";
567
567
 
568
568
  const api = new AptosAPI("aptos");
569
- const transactionIntent: TransactionIntent<AptosAsset> = {
569
+ const transactionIntent: TransactionIntent<AptosAsset, AptosExtra, AptosSender> = {
570
570
  asset: {
571
571
  type: "native",
572
572
  },
573
573
  type: "send",
574
- sender: sender.freshAddress,
575
- senderPublicKey: sender.xpub,
574
+ sender,
576
575
  amount,
577
576
  recipient,
578
577
  };
@@ -624,22 +623,21 @@ describe("Aptos API", () => {
624
623
  }));
625
624
 
626
625
  const amount = BigInt(100);
627
- const sender = {
626
+ const sender: AptosSender = {
628
627
  xpub: "xpub",
629
628
  freshAddress: "address1",
630
629
  };
631
630
  const recipient = "address2";
632
631
 
633
632
  const api = new AptosAPI("aptos");
634
- const transactionIntent: TransactionIntent<AptosAsset> = {
633
+ const transactionIntent: TransactionIntent<AptosAsset, AptosExtra, AptosSender> = {
635
634
  asset: {
636
635
  type: "token",
637
636
  standard: "coin",
638
637
  contractAddress: "0x111",
639
638
  },
640
639
  type: "send",
641
- sender: sender.freshAddress,
642
- senderPublicKey: sender.xpub,
640
+ sender,
643
641
  amount,
644
642
  recipient,
645
643
  };
@@ -690,22 +688,21 @@ describe("Aptos API", () => {
690
688
  }));
691
689
 
692
690
  const amount = BigInt(100);
693
- const sender = {
691
+ const sender: AptosSender = {
694
692
  xpub: "xpub",
695
693
  freshAddress: "address1",
696
694
  };
697
695
  const recipient = "address2";
698
696
 
699
697
  const api = new AptosAPI("aptos");
700
- const transactionIntent: TransactionIntent<AptosAsset> = {
698
+ const transactionIntent: TransactionIntent<AptosAsset, AptosExtra, AptosSender> = {
701
699
  asset: {
702
700
  type: "token",
703
701
  standard: "fungible_asset",
704
702
  contractAddress: "0x111",
705
703
  },
706
704
  type: "send",
707
- sender: sender.freshAddress,
708
- senderPublicKey: sender.xpub,
705
+ sender,
709
706
  amount,
710
707
  recipient,
711
708
  };
package/src/api/index.ts CHANGED
@@ -1,14 +1,16 @@
1
- import type { AlpacaApi } from "@ledgerhq/coin-framework/api/index";
1
+ import type { Api } from "@ledgerhq/coin-framework/api/index";
2
2
  import type { AptosConfig as AptosConfigApi } from "../config";
3
3
  import type { Balance, Pagination, TransactionIntent } from "@ledgerhq/coin-framework/api/types";
4
4
  import coinConfig from "../config";
5
- import type { AptosAsset } from "../types/assets";
5
+ import type { AptosAsset, AptosExtra, AptosFeeParameters, AptosSender } from "../types/assets";
6
6
  import { AptosAPI } from "../network";
7
7
  import { combine } from "../logic/combine";
8
8
  import { craftTransaction } from "../logic/craftTransaction";
9
9
  import { getBalances } from "../logic/getBalances";
10
10
 
11
- export function createApi(config: AptosConfigApi): AlpacaApi<AptosAsset> {
11
+ export function createApi(
12
+ config: AptosConfigApi,
13
+ ): Api<AptosAsset, AptosExtra, AptosSender, AptosFeeParameters> {
12
14
  coinConfig.setCoinConfig(() => ({ ...config, status: { type: "active" } }));
13
15
 
14
16
  const client = new AptosAPI(config.aptosSettings);
@@ -18,7 +20,7 @@ export function createApi(config: AptosConfigApi): AlpacaApi<AptosAsset> {
18
20
  combine: (tx, signature, pubkey): string => combine(tx, signature, pubkey),
19
21
  craftTransaction: (transactionIntent, _customFees): Promise<string> =>
20
22
  craftTransaction(client, transactionIntent),
21
- estimateFees: (transactionIntent: TransactionIntent<AptosAsset>) =>
23
+ estimateFees: (transactionIntent: TransactionIntent<AptosAsset, AptosExtra, AptosSender>) =>
22
24
  client.estimateFees(transactionIntent),
23
25
  getBalance: (address): Promise<Balance<AptosAsset>[]> => getBalances(client, address),
24
26
  lastBlock: () => client.getLastBlock(),
@@ -1,5 +1,5 @@
1
1
  import type { TransactionIntent } from "@ledgerhq/coin-framework/lib/api/types";
2
- import type { AptosAsset } from "../types/assets";
2
+ import type { AptosAsset, AptosExtra, AptosSender } from "../types/assets";
3
3
  import type { Account, TokenAccount } from "@ledgerhq/types-live";
4
4
  import type { AptosAPI } from "../network";
5
5
  import buildTransaction, { isTokenType } from "./buildTransaction";
@@ -10,7 +10,7 @@ import type { AptosBalance } from "../types";
10
10
 
11
11
  export async function craftTransaction(
12
12
  aptosClient: AptosAPI,
13
- transactionIntent: TransactionIntent<AptosAsset>,
13
+ transactionIntent: TransactionIntent<AptosAsset, AptosExtra, AptosSender>,
14
14
  ): Promise<string> {
15
15
  const newTx = createTransaction();
16
16
  newTx.amount = BigNumber(transactionIntent.amount.toString());
@@ -19,8 +19,8 @@ export async function craftTransaction(
19
19
  newTx.useAllAmount = transactionIntent.amount === BigInt(0);
20
20
 
21
21
  const account = {
22
- freshAddress: transactionIntent.sender,
23
- xpub: transactionIntent.senderPublicKey,
22
+ freshAddress: transactionIntent.sender.freshAddress,
23
+ xpub: transactionIntent.sender.xpub,
24
24
  subAccounts: new Array<TokenAccount>(),
25
25
  } as Account;
26
26
 
@@ -29,7 +29,7 @@ export async function craftTransaction(
29
29
  let balance: AptosBalance | undefined;
30
30
 
31
31
  if (newTx.useAllAmount === true) {
32
- const balances = await aptosClient.getBalances(transactionIntent.sender);
32
+ const balances = await aptosClient.getBalances(transactionIntent.sender.freshAddress);
33
33
  balance = balances?.find(
34
34
  b => b.contractAddress.toLowerCase() === contractAddress?.toLowerCase(),
35
35
  );
@@ -54,7 +54,9 @@ export async function craftTransaction(
54
54
  return aptosTx.bcsToHex().toString();
55
55
  }
56
56
 
57
- function getContractAddress(txIntent: TransactionIntent<AptosAsset>): string {
57
+ function getContractAddress(
58
+ txIntent: TransactionIntent<AptosAsset, AptosExtra, AptosSender>,
59
+ ): string {
58
60
  if (txIntent.asset.type === "token" && isTokenType(txIntent.asset.standard)) {
59
61
  return txIntent.asset.contractAddress;
60
62
  }
@@ -43,7 +43,7 @@ import {
43
43
  Pagination,
44
44
  TransactionIntent,
45
45
  } from "@ledgerhq/coin-framework/api/types";
46
- import { AptosAsset } from "../types/assets";
46
+ import { AptosAsset, AptosExtra, AptosFeeParameters, AptosSender } from "../types/assets";
47
47
  import { log } from "@ledgerhq/logs";
48
48
  import { transactionsToOperations } from "../logic/transactionsToOperations";
49
49
  import { isTestnet } from "../logic/isTestnet";
@@ -175,8 +175,10 @@ export class AptosAPI {
175
175
  };
176
176
  }
177
177
 
178
- async estimateFees(transactionIntent: TransactionIntent<AptosAsset>): Promise<FeeEstimation> {
179
- const publicKeyEd = new Ed25519PublicKey(transactionIntent?.senderPublicKey ?? "");
178
+ async estimateFees(
179
+ transactionIntent: TransactionIntent<AptosAsset, AptosExtra, AptosSender>,
180
+ ): Promise<FeeEstimation<AptosFeeParameters>> {
181
+ const publicKeyEd = new Ed25519PublicKey(transactionIntent.sender.xpub);
180
182
 
181
183
  const txPayload: InputEntryFunctionData = {
182
184
  function: "0x1::aptos_account::transfer_coins",
@@ -206,7 +208,11 @@ export class AptosAPI {
206
208
  gasUnitPrice: DEFAULT_GAS_PRICE.toString(),
207
209
  };
208
210
 
209
- const tx = await this.generateTransaction(transactionIntent.sender, txPayload, txOptions);
211
+ const tx = await this.generateTransaction(
212
+ transactionIntent.sender.freshAddress,
213
+ txPayload,
214
+ txOptions,
215
+ );
210
216
 
211
217
  const simulation = await this.simulateTransaction(publicKeyEd, tx);
212
218
  const completedTx = simulation[0];
@@ -219,7 +225,6 @@ export class AptosAPI {
219
225
  return {
220
226
  value: BigInt(expectedGas.toString()),
221
227
  parameters: {
222
- storageLimit: BigInt(0),
223
228
  gasLimit: BigInt(gasLimit.toString()),
224
229
  gasPrice: BigInt(gasPrice.toString()),
225
230
  },
@@ -9,6 +9,11 @@ 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
+
12
17
  export type AptosFeeParameters = {
13
18
  gasLimit: bigint;
14
19
  gasPrice: bigint;