@ledgerhq/coin-aptos 2.7.0 → 3.0.0-nightly.3

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 (113) hide show
  1. package/.turbo/turbo-build.log +1 -1
  2. package/.unimportedrc.json +1 -7
  3. package/CHANGELOG.md +24 -32
  4. package/lib/__tests__/api/craftTransaction.unit.test.js +4 -4
  5. package/lib/__tests__/api/craftTransaction.unit.test.js.map +1 -1
  6. package/lib/__tests__/api/getBalance.unit.test.js +3 -4
  7. package/lib/__tests__/api/getBalance.unit.test.js.map +1 -1
  8. package/lib/__tests__/api/index.integ.test.js +23 -32
  9. package/lib/__tests__/api/index.integ.test.js.map +1 -1
  10. package/lib/__tests__/api/index.test.js.map +1 -1
  11. package/lib/__tests__/logic/getBalances.test.js +3 -4
  12. package/lib/__tests__/logic/getBalances.test.js.map +1 -1
  13. package/lib/__tests__/network/client.test.js +4 -8
  14. package/lib/__tests__/network/client.test.js.map +1 -1
  15. package/lib/api/index.d.ts +1 -2
  16. package/lib/api/index.d.ts.map +1 -1
  17. package/lib/api/index.js.map +1 -1
  18. package/lib/logic/buildTransaction.d.ts.map +1 -1
  19. package/lib/logic/buildTransaction.js +1 -0
  20. package/lib/logic/buildTransaction.js.map +1 -1
  21. package/lib/logic/craftTransaction.d.ts +1 -2
  22. package/lib/logic/craftTransaction.d.ts.map +1 -1
  23. package/lib/logic/craftTransaction.js +6 -4
  24. package/lib/logic/craftTransaction.js.map +1 -1
  25. package/lib/logic/getBalances.d.ts +1 -2
  26. package/lib/logic/getBalances.d.ts.map +1 -1
  27. package/lib/logic/getBalances.js +2 -2
  28. package/lib/logic/getBalances.js.map +1 -1
  29. package/lib/logic/processRecipients.d.ts +1 -2
  30. package/lib/logic/processRecipients.d.ts.map +1 -1
  31. package/lib/logic/processRecipients.js.map +1 -1
  32. package/lib/logic/transactionsToOperations.d.ts +1 -2
  33. package/lib/logic/transactionsToOperations.d.ts.map +1 -1
  34. package/lib/logic/transactionsToOperations.js +3 -4
  35. package/lib/logic/transactionsToOperations.js.map +1 -1
  36. package/lib/network/client.d.ts +2 -3
  37. package/lib/network/client.d.ts.map +1 -1
  38. package/lib/network/client.js +8 -15
  39. package/lib/network/client.js.map +1 -1
  40. package/lib/network/graphql/queries.d.ts.map +1 -1
  41. package/lib/network/graphql/queries.js +6 -1
  42. package/lib/network/graphql/queries.js.map +1 -1
  43. package/lib/network/graphql/types.d.ts +2 -0
  44. package/lib/network/graphql/types.d.ts.map +1 -1
  45. package/lib/preload.d.ts.map +1 -1
  46. package/lib/preload.js +1 -5
  47. package/lib/preload.js.map +1 -1
  48. package/lib/types/assets.d.ts +0 -6
  49. package/lib/types/assets.d.ts.map +1 -1
  50. package/lib-es/__tests__/api/craftTransaction.unit.test.js +4 -4
  51. package/lib-es/__tests__/api/craftTransaction.unit.test.js.map +1 -1
  52. package/lib-es/__tests__/api/getBalance.unit.test.js +3 -4
  53. package/lib-es/__tests__/api/getBalance.unit.test.js.map +1 -1
  54. package/lib-es/__tests__/api/index.integ.test.js +23 -32
  55. package/lib-es/__tests__/api/index.integ.test.js.map +1 -1
  56. package/lib-es/__tests__/api/index.test.js.map +1 -1
  57. package/lib-es/__tests__/logic/getBalances.test.js +3 -4
  58. package/lib-es/__tests__/logic/getBalances.test.js.map +1 -1
  59. package/lib-es/__tests__/network/client.test.js +4 -8
  60. package/lib-es/__tests__/network/client.test.js.map +1 -1
  61. package/lib-es/api/index.d.ts +1 -2
  62. package/lib-es/api/index.d.ts.map +1 -1
  63. package/lib-es/api/index.js.map +1 -1
  64. package/lib-es/logic/buildTransaction.d.ts.map +1 -1
  65. package/lib-es/logic/buildTransaction.js +1 -0
  66. package/lib-es/logic/buildTransaction.js.map +1 -1
  67. package/lib-es/logic/craftTransaction.d.ts +1 -2
  68. package/lib-es/logic/craftTransaction.d.ts.map +1 -1
  69. package/lib-es/logic/craftTransaction.js +6 -4
  70. package/lib-es/logic/craftTransaction.js.map +1 -1
  71. package/lib-es/logic/getBalances.d.ts +1 -2
  72. package/lib-es/logic/getBalances.d.ts.map +1 -1
  73. package/lib-es/logic/getBalances.js +2 -2
  74. package/lib-es/logic/getBalances.js.map +1 -1
  75. package/lib-es/logic/processRecipients.d.ts +1 -2
  76. package/lib-es/logic/processRecipients.d.ts.map +1 -1
  77. package/lib-es/logic/processRecipients.js.map +1 -1
  78. package/lib-es/logic/transactionsToOperations.d.ts +1 -2
  79. package/lib-es/logic/transactionsToOperations.d.ts.map +1 -1
  80. package/lib-es/logic/transactionsToOperations.js +3 -4
  81. package/lib-es/logic/transactionsToOperations.js.map +1 -1
  82. package/lib-es/network/client.d.ts +2 -3
  83. package/lib-es/network/client.d.ts.map +1 -1
  84. package/lib-es/network/client.js +9 -16
  85. package/lib-es/network/client.js.map +1 -1
  86. package/lib-es/network/graphql/queries.d.ts.map +1 -1
  87. package/lib-es/network/graphql/queries.js +6 -1
  88. package/lib-es/network/graphql/queries.js.map +1 -1
  89. package/lib-es/network/graphql/types.d.ts +2 -0
  90. package/lib-es/network/graphql/types.d.ts.map +1 -1
  91. package/lib-es/preload.d.ts.map +1 -1
  92. package/lib-es/preload.js +1 -5
  93. package/lib-es/preload.js.map +1 -1
  94. package/lib-es/types/assets.d.ts +0 -6
  95. package/lib-es/types/assets.d.ts.map +1 -1
  96. package/package.json +9 -10
  97. package/src/__tests__/api/craftTransaction.unit.test.ts +9 -10
  98. package/src/__tests__/api/getBalance.unit.test.ts +3 -4
  99. package/src/__tests__/api/index.integ.test.ts +23 -32
  100. package/src/__tests__/api/index.test.ts +2 -3
  101. package/src/__tests__/logic/getBalances.test.ts +3 -4
  102. package/src/__tests__/network/client.test.ts +7 -12
  103. package/src/api/index.ts +4 -6
  104. package/src/logic/buildTransaction.ts +1 -0
  105. package/src/logic/craftTransaction.ts +10 -7
  106. package/src/logic/getBalances.ts +3 -4
  107. package/src/logic/processRecipients.ts +4 -8
  108. package/src/logic/transactionsToOperations.ts +6 -8
  109. package/src/network/client.ts +10 -24
  110. package/src/network/graphql/queries.ts +6 -1
  111. package/src/network/graphql/types.ts +2 -0
  112. package/src/preload.ts +1 -5
  113. package/src/types/assets.ts +0 -9
@@ -70,7 +70,7 @@ describe("getBalance", () => {
70
70
  expect(await api.getBalance(accountAddress)).toStrictEqual([
71
71
  {
72
72
  value: 25n,
73
- asset: { type: "token", contractAddress: TOKEN_ASSET_ID, standard: TOKEN_TYPE.COIN },
73
+ asset: { type: TOKEN_TYPE.COIN, assetReference: TOKEN_ASSET_ID },
74
74
  },
75
75
  ]);
76
76
  });
@@ -88,9 +88,8 @@ describe("getBalance", () => {
88
88
  {
89
89
  value: 25n,
90
90
  asset: {
91
- type: "token",
92
- contractAddress: TOKEN_ASSET_ID,
93
- standard: TOKEN_TYPE.FUNGIBLE_ASSET,
91
+ type: TOKEN_TYPE.FUNGIBLE_ASSET,
92
+ assetReference: TOKEN_ASSET_ID,
94
93
  },
95
94
  },
96
95
  ]);
@@ -71,9 +71,8 @@ describe("createApi", () => {
71
71
 
72
72
  const fees = await api.estimateFees({
73
73
  asset: {
74
- type: "token",
75
- standard: "coin",
76
- contractAddress:
74
+ type: "coin",
75
+ assetReference:
77
76
  "0x50788befc1107c0cc4473848a92e5c783c635866ce3c98de71d2eeb7d2a34f85::usdc_coin::USDCoin",
78
77
  },
79
78
  type: "send",
@@ -91,9 +90,8 @@ describe("createApi", () => {
91
90
 
92
91
  const fees = await api.estimateFees({
93
92
  asset: {
94
- type: "token",
95
- standard: "fungible_asset",
96
- contractAddress: "0x357b0b74bc833e95a115ad22604854d6b0fca151cecd94111770e5d6ffc9dc2b",
93
+ type: "fungible_asset",
94
+ assetReference: "0x357b0b74bc833e95a115ad22604854d6b0fca151cecd94111770e5d6ffc9dc2b",
97
95
  },
98
96
  type: "send",
99
97
  sender: sender.freshAddress,
@@ -117,7 +115,7 @@ describe("createApi", () => {
117
115
  type: "send",
118
116
  asset: { type: "native" },
119
117
  },
120
- 0n,
118
+ { value: 0n },
121
119
  );
122
120
 
123
121
  const rawTx = RawTransaction.deserialize(
@@ -138,13 +136,12 @@ describe("createApi", () => {
138
136
  recipient: recipient.freshAddress,
139
137
  type: "send",
140
138
  asset: {
141
- type: "token",
142
- standard: "coin",
143
- contractAddress:
139
+ type: "coin",
140
+ assetReference:
144
141
  "0x50788befc1107c0cc4473848a92e5c783c635866ce3c98de71d2eeb7d2a34f85::aptos_coin::AptosCoin",
145
142
  },
146
143
  },
147
- 0n,
144
+ { value: 0n },
148
145
  );
149
146
 
150
147
  const rawTx = RawTransaction.deserialize(
@@ -165,13 +162,12 @@ describe("createApi", () => {
165
162
  recipient: recipient.freshAddress,
166
163
  type: "send",
167
164
  asset: {
168
- type: "token",
169
- standard: "coin",
170
- contractAddress:
165
+ type: "coin",
166
+ assetReference:
171
167
  "0x50788befc1107c0cc4473848a92e5c783c635866ce3c98de71d2eeb7d2a34f85::aptos_coin::AptosCoin",
172
168
  },
173
169
  },
174
- 0n,
170
+ { value: 0n },
175
171
  );
176
172
 
177
173
  const rawTx = RawTransaction.deserialize(
@@ -194,12 +190,11 @@ describe("createApi", () => {
194
190
  recipient: r.freshAddress,
195
191
  type: "send",
196
192
  asset: {
197
- type: "token",
198
- standard: "fungible_asset",
199
- contractAddress: "0x2ebb2ccac5e027a87fa0e2e5f656a3a4238d6a48d93ec9b610d570fc0aa0df12",
193
+ type: "fungible_asset",
194
+ assetReference: "0x2ebb2ccac5e027a87fa0e2e5f656a3a4238d6a48d93ec9b610d570fc0aa0df12",
200
195
  },
201
196
  },
202
- 0n,
197
+ { value: 0n },
203
198
  );
204
199
 
205
200
  const rawTx = RawTransaction.deserialize(
@@ -225,7 +220,7 @@ describe("createApi", () => {
225
220
  const tokenBalances = balances.filter(
226
221
  b =>
227
222
  b.asset.type === assetTypeToken &&
228
- b.asset.contractAddress ===
223
+ b.asset.assetReference ===
229
224
  "0x2ebb2ccac5e027a87fa0e2e5f656a3a4238d6a48d93ec9b610d570fc0aa0df12",
230
225
  );
231
226
  expect(tokenBalances.length).toBeGreaterThan(0);
@@ -345,9 +340,8 @@ describe("createApi", () => {
345
340
  recipients: [tokenAccount.freshAddress],
346
341
  senders: ["0x24dbf71ba20209753035505c51d4607ed67aa0c81b930d9ef4483ec84b349fcb"],
347
342
  asset: {
348
- type: "token",
349
- standard: "coin",
350
- contractAddress:
343
+ type: "coin",
344
+ assetReference:
351
345
  "0xd11107bdf0d6d7040c6c0bfbdecb6545191fdf13e8d8d259952f53e1713f61b5::staked_coin::StakedAptos",
352
346
  },
353
347
  tx: {
@@ -364,9 +358,8 @@ describe("createApi", () => {
364
358
  recipients: ["0x24dbf71ba20209753035505c51d4607ed67aa0c81b930d9ef4483ec84b349fcb"],
365
359
  senders: [tokenAccount.freshAddress],
366
360
  asset: {
367
- type: "token",
368
- standard: "coin",
369
- contractAddress:
361
+ type: "coin",
362
+ assetReference:
370
363
  "0xd11107bdf0d6d7040c6c0bfbdecb6545191fdf13e8d8d259952f53e1713f61b5::staked_coin::StakedAptos",
371
364
  },
372
365
  tx: {
@@ -388,9 +381,8 @@ describe("createApi", () => {
388
381
  recipients: [tokenAccount.freshAddress],
389
382
  senders: ["0x24dbf71ba20209753035505c51d4607ed67aa0c81b930d9ef4483ec84b349fcb"],
390
383
  asset: {
391
- type: "token",
392
- standard: "fungible_asset",
393
- contractAddress: "0x2ebb2ccac5e027a87fa0e2e5f656a3a4238d6a48d93ec9b610d570fc0aa0df12",
384
+ type: "fungible_asset",
385
+ assetReference: "0x2ebb2ccac5e027a87fa0e2e5f656a3a4238d6a48d93ec9b610d570fc0aa0df12",
394
386
  },
395
387
  tx: {
396
388
  hash: "0x88856968603dee4f08579036bc30322b9a5f329561656888e3467ce27cc11ea7",
@@ -406,9 +398,8 @@ describe("createApi", () => {
406
398
  recipients: ["0x24dbf71ba20209753035505c51d4607ed67aa0c81b930d9ef4483ec84b349fcb"],
407
399
  senders: [tokenAccount.freshAddress],
408
400
  asset: {
409
- type: "token",
410
- standard: "fungible_asset",
411
- contractAddress: "0x2ebb2ccac5e027a87fa0e2e5f656a3a4238d6a48d93ec9b610d570fc0aa0df12",
401
+ type: "fungible_asset",
402
+ assetReference: "0x2ebb2ccac5e027a87fa0e2e5f656a3a4238d6a48d93ec9b610d570fc0aa0df12",
412
403
  },
413
404
  tx: {
414
405
  hash: "0x8aa9e980760fe8aeb6804f387350b3019a2471aa61a5506a260c32cd5d6db32c",
@@ -1,6 +1,5 @@
1
1
  import { Aptos } from "@aptos-labs/ts-sdk";
2
2
  import type { AlpacaApi } from "@ledgerhq/coin-framework/api/types";
3
- import type { AptosAsset } from "../../types/assets";
4
3
  import type { AptosConfig } from "../../config";
5
4
  import { createApi } from "../../api";
6
5
  import coinConfig from "../../config";
@@ -33,7 +32,7 @@ describe("createApi", () => {
33
32
  });
34
33
 
35
34
  it("should return an API object with alpaca api methods", () => {
36
- const api: AlpacaApi<AptosAsset> = createApi(mockAptosConfig);
35
+ const api: AlpacaApi = createApi(mockAptosConfig);
37
36
 
38
37
  // Check that methods are set with what we expect
39
38
  expect(api.broadcast).toBeDefined();
@@ -69,7 +68,7 @@ describe("lastBlock", () => {
69
68
  }),
70
69
  }));
71
70
 
72
- const api: AlpacaApi<AptosAsset> = createApi(mockAptosConfig);
71
+ const api: AlpacaApi = createApi(mockAptosConfig);
73
72
 
74
73
  expect(await api.lastBlock()).toStrictEqual({
75
74
  height: 123,
@@ -51,7 +51,7 @@ describe("getBalance", () => {
51
51
  expect(balances).toStrictEqual([
52
52
  {
53
53
  value: 25n,
54
- asset: { type: "token", contractAddress: TOKEN_ASSET_ID, standard: TOKEN_TYPE.COIN },
54
+ asset: { type: TOKEN_TYPE.COIN, assetReference: TOKEN_ASSET_ID },
55
55
  },
56
56
  ]);
57
57
  });
@@ -70,9 +70,8 @@ describe("getBalance", () => {
70
70
  {
71
71
  value: 25n,
72
72
  asset: {
73
- type: "token",
74
- contractAddress: TOKEN_ASSET_ID,
75
- standard: TOKEN_TYPE.FUNGIBLE_ASSET,
73
+ type: TOKEN_TYPE.FUNGIBLE_ASSET,
74
+ assetReference: TOKEN_ASSET_ID,
76
75
  },
77
76
  },
78
77
  ]);
@@ -14,7 +14,6 @@ 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";
18
17
  import { Pagination, TransactionIntent } from "@ledgerhq/coin-framework/api/types";
19
18
  import { APTOS_ASSET_ID } from "../../constants";
20
19
  import { AptosBalance, AptosTransaction } from "../../types";
@@ -622,7 +621,7 @@ describe("Aptos API", () => {
622
621
  const recipient = "address2";
623
622
 
624
623
  const api = new AptosAPI("aptos");
625
- const transactionIntent: TransactionIntent<AptosAsset> = {
624
+ const transactionIntent: TransactionIntent = {
626
625
  asset: {
627
626
  type: "native",
628
627
  },
@@ -687,11 +686,10 @@ describe("Aptos API", () => {
687
686
  const recipient = "address2";
688
687
 
689
688
  const api = new AptosAPI("aptos");
690
- const transactionIntent: TransactionIntent<AptosAsset> = {
689
+ const transactionIntent: TransactionIntent = {
691
690
  asset: {
692
- type: "token",
693
- standard: "coin",
694
- contractAddress: "0x111",
691
+ type: "coin",
692
+ assetReference: "0x111",
695
693
  },
696
694
  type: "send",
697
695
  sender: sender.freshAddress,
@@ -753,11 +751,10 @@ describe("Aptos API", () => {
753
751
  const recipient = "address2";
754
752
 
755
753
  const api = new AptosAPI("aptos");
756
- const transactionIntent: TransactionIntent<AptosAsset> = {
754
+ const transactionIntent: TransactionIntent = {
757
755
  asset: {
758
- type: "token",
759
- standard: "fungible_asset",
760
- contractAddress: "0x111",
756
+ type: "fungible_asset",
757
+ assetReference: "0x111",
761
758
  },
762
759
  type: "send",
763
760
  sender: sender.freshAddress,
@@ -868,7 +865,6 @@ describe("Aptos API", () => {
868
865
  const txs: AptosTransaction[] = [
869
866
  {
870
867
  version: "2532591427",
871
- replay_protection_nonce: "replay_protection_nonce",
872
868
  hash: "0x3f35",
873
869
  state_change_hash: "0xb480",
874
870
  event_root_hash: "0x3fa1",
@@ -1082,7 +1078,6 @@ describe("Aptos API", () => {
1082
1078
  },
1083
1079
  {
1084
1080
  version: "2532549325",
1085
- replay_protection_nonce: "replay_protection_nonce",
1086
1081
  hash: "0x9a6b",
1087
1082
  state_change_hash: "0xa424",
1088
1083
  event_root_hash: "0x0321",
package/src/api/index.ts CHANGED
@@ -2,13 +2,12 @@ import type { AlpacaApi, Block, BlockInfo } from "@ledgerhq/coin-framework/api/i
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";
6
5
  import { AptosAPI } from "../network";
7
6
  import { combine } from "../logic/combine";
8
7
  import { craftTransaction } from "../logic/craftTransaction";
9
8
  import { getBalances } from "../logic/getBalances";
10
9
 
11
- export function createApi(config: AptosConfigApi): AlpacaApi<AptosAsset> {
10
+ export function createApi(config: AptosConfigApi): AlpacaApi {
12
11
  coinConfig.setCoinConfig(() => ({ ...config, status: { type: "active" } }));
13
12
 
14
13
  const client = new AptosAPI(config.aptosSettings);
@@ -18,13 +17,12 @@ export function createApi(config: AptosConfigApi): AlpacaApi<AptosAsset> {
18
17
  combine: (tx, signature, pubkey): string => combine(tx, signature, pubkey),
19
18
  craftTransaction: (transactionIntent, _customFees): Promise<string> =>
20
19
  craftTransaction(client, transactionIntent),
21
- estimateFees: (transactionIntent: TransactionIntent<AptosAsset>) =>
22
- client.estimateFees(transactionIntent),
23
- getBalance: (address): Promise<Balance<AptosAsset>[]> => getBalances(client, address),
20
+ estimateFees: (transactionIntent: TransactionIntent) => client.estimateFees(transactionIntent),
21
+ getBalance: (address): Promise<Balance[]> => getBalances(client, address),
24
22
  lastBlock: () => client.getLastBlock(),
25
23
  listOperations: (address: string, pagination: Pagination) =>
26
24
  client.listOperations(address, pagination),
27
- getBlock(_height): Promise<Block<AptosAsset>> {
25
+ getBlock(_height): Promise<Block> {
28
26
  throw new Error("getBlock is not supported");
29
27
  },
30
28
  getBlockInfo(_height: number): Promise<BlockInfo> {
@@ -88,6 +88,7 @@ const getPayload = ({
88
88
  };
89
89
  };
90
90
 
91
+ // FIXME: terminology overlop, using tokentype here when AssetInfo refers to `standard`
91
92
  export const isTokenType = (value: string): boolean => {
92
93
  return Object.values(TOKEN_TYPE).includes(value as TOKEN_TYPE);
93
94
  };
@@ -1,5 +1,4 @@
1
1
  import type { TransactionIntent } from "@ledgerhq/coin-framework/lib/api/types";
2
- import type { AptosAsset } from "../types/assets";
3
2
  import type { Account, TokenAccount } from "@ledgerhq/types-live";
4
3
  import type { AptosAPI } from "../network";
5
4
  import buildTransaction, { isTokenType } from "./buildTransaction";
@@ -10,7 +9,7 @@ import type { AptosBalance } from "../types";
10
9
 
11
10
  export async function craftTransaction(
12
11
  aptosClient: AptosAPI,
13
- transactionIntent: TransactionIntent<AptosAsset>,
12
+ transactionIntent: TransactionIntent,
14
13
  ): Promise<string> {
15
14
  const newTx = createTransaction();
16
15
  newTx.amount = BigNumber(transactionIntent.amount.toString());
@@ -39,8 +38,8 @@ export async function craftTransaction(
39
38
  }
40
39
  }
41
40
 
42
- if (transactionIntent.asset.type === "token") {
43
- tokenType = transactionIntent.asset.standard as TOKEN_TYPE;
41
+ if (transactionIntent.asset.type !== "native") {
42
+ tokenType = transactionIntent.asset.type as TOKEN_TYPE;
44
43
  }
45
44
 
46
45
  const aptosTx = await buildTransaction(
@@ -54,9 +53,13 @@ export async function craftTransaction(
54
53
  return aptosTx.bcsToHex().toString();
55
54
  }
56
55
 
57
- function getContractAddress(txIntent: TransactionIntent<AptosAsset>): string {
58
- if (txIntent.asset.type === "token" && isTokenType(txIntent.asset.standard)) {
59
- return txIntent.asset.contractAddress;
56
+ function getContractAddress(txIntent: TransactionIntent): string {
57
+ if (
58
+ txIntent.asset.type !== "native" &&
59
+ isTokenType(txIntent.asset.type as string) &&
60
+ "assetReference" in txIntent.asset
61
+ ) {
62
+ return txIntent.asset.assetReference as string;
60
63
  }
61
64
 
62
65
  return APTOS_ASSET_ID;
@@ -1,5 +1,4 @@
1
1
  import type { Balance } from "@ledgerhq/coin-framework/lib/api/types";
2
- import type { AptosAsset } from "../types/assets";
3
2
  import type { AptosAPI } from "../network";
4
3
  import { APTOS_ASSET_ID, TOKEN_TYPE } from "../constants";
5
4
 
@@ -7,12 +6,12 @@ export async function getBalances(
7
6
  aptosClient: AptosAPI,
8
7
  address: string,
9
8
  contract_address?: string,
10
- ): Promise<Balance<AptosAsset>[]> {
9
+ ): Promise<Balance[]> {
11
10
  const balances = await aptosClient.getBalances(address, contract_address);
12
11
 
13
12
  return balances.map(balance => {
14
13
  const isNative = balance.contractAddress === APTOS_ASSET_ID;
15
- const standard =
14
+ const type =
16
15
  balance.contractAddress.split("::").length === 3
17
16
  ? TOKEN_TYPE.COIN
18
17
  : TOKEN_TYPE.FUNGIBLE_ASSET;
@@ -21,7 +20,7 @@ export async function getBalances(
21
20
  value: BigInt(balance.amount.toString()),
22
21
  asset: isNative
23
22
  ? { type: "native" }
24
- : { type: "token", contractAddress: balance.contractAddress, standard: standard },
23
+ : { type: type, assetReference: balance.contractAddress },
25
24
  };
26
25
  });
27
26
  }
@@ -1,7 +1,6 @@
1
1
  import { InputEntryFunctionData } from "@aptos-labs/ts-sdk";
2
2
  import { Operation } from "@ledgerhq/types-live";
3
3
  import { Operation as APIOperation } from "@ledgerhq/coin-framework/api/types";
4
- import { AptosAsset } from "../types/assets";
5
4
  import {
6
5
  BATCH_TRANSFER_TYPES,
7
6
  COIN_TRANSFER_TYPES,
@@ -16,7 +15,7 @@ const transferLikeFunctions = (payload: InputEntryFunctionData) =>
16
15
  DELEGATION_POOL_TYPES.includes(payload.function);
17
16
 
18
17
  const addLikeFunctionsToRecipients = (
19
- op: Operation | APIOperation<AptosAsset>,
18
+ op: Operation | APIOperation,
20
19
  payload: InputEntryFunctionData,
21
20
  ) => {
22
21
  if (
@@ -28,10 +27,7 @@ const addLikeFunctionsToRecipients = (
28
27
  }
29
28
  };
30
29
 
31
- const addFungibleToRecipients = (
32
- op: Operation | APIOperation<AptosAsset>,
33
- payload: InputEntryFunctionData,
34
- ) => {
30
+ const addFungibleToRecipients = (op: Operation | APIOperation, payload: InputEntryFunctionData) => {
35
31
  if (
36
32
  payload.functionArguments &&
37
33
  payload.functionArguments.length > 1 &&
@@ -43,7 +39,7 @@ const addFungibleToRecipients = (
43
39
  };
44
40
 
45
41
  const addBatchedFunctions = (
46
- op: Operation | APIOperation<AptosAsset>,
42
+ op: Operation | APIOperation,
47
43
  payload: InputEntryFunctionData,
48
44
  address: string,
49
45
  ) => {
@@ -66,7 +62,7 @@ const addBatchedFunctions = (
66
62
  export function processRecipients(
67
63
  payload: InputEntryFunctionData,
68
64
  address: string,
69
- op: Operation | APIOperation<AptosAsset>,
65
+ op: Operation | APIOperation,
70
66
  function_address: string,
71
67
  ): void {
72
68
  // get recipients by 3 groups
@@ -1,6 +1,5 @@
1
1
  import { AptosTransaction } from "../types";
2
2
  import { Operation } from "@ledgerhq/coin-framework/api/types";
3
- import { AptosAsset } from "../types/assets";
4
3
  import BigNumber from "bignumber.js";
5
4
  import { EntryFunctionPayloadResponse, InputEntryFunctionData } from "@aptos-labs/ts-sdk";
6
5
  import { APTOS_ASSET_ID, OP_TYPE } from "../constants";
@@ -29,7 +28,7 @@ const detectType = (address: string, tx: AptosTransaction, value: BigNumber): OP
29
28
  return type;
30
29
  };
31
30
 
32
- const getTokenStandard = (coin_id: string): string => {
31
+ const getTokenType = (coin_id: string) => {
33
32
  const parts = coin_id.split("::");
34
33
  if (parts.length === 3) {
35
34
  return "coin";
@@ -40,8 +39,8 @@ const getTokenStandard = (coin_id: string): string => {
40
39
  export function transactionsToOperations(
41
40
  address: string,
42
41
  txs: (AptosTransaction | null)[],
43
- ): Operation<AptosAsset>[] {
44
- const operations: Operation<AptosAsset>[] = [];
42
+ ): Operation[] {
43
+ const operations: Operation[] = [];
45
44
 
46
45
  return txs.reduce((acc, tx) => {
47
46
  if (tx === null) {
@@ -62,7 +61,7 @@ export function transactionsToOperations(
62
61
  const value = calculateAmount(tx.sender, address, amount_in, amount_out);
63
62
  const type = detectType(address, tx, value);
64
63
 
65
- const op: Operation<AptosAsset> = {
64
+ const op: Operation = {
66
65
  id: tx.hash,
67
66
  type,
68
67
  senders: [],
@@ -94,9 +93,8 @@ export function transactionsToOperations(
94
93
  return acc;
95
94
  } else {
96
95
  op.asset = {
97
- type: "token",
98
- standard: getTokenStandard(coin_id),
99
- contractAddress: coin_id,
96
+ type: getTokenType(coin_id),
97
+ assetReference: coin_id,
100
98
  };
101
99
  acc.push(op);
102
100
  }
@@ -18,7 +18,6 @@ import {
18
18
  Hex,
19
19
  postAptosFullNode,
20
20
  type PendingTransactionResponse,
21
- Network,
22
21
  } from "@aptos-labs/ts-sdk";
23
22
  import { getEnv } from "@ledgerhq/live-env";
24
23
  import network from "@ledgerhq/live-network";
@@ -49,7 +48,6 @@ import {
49
48
  Pagination,
50
49
  TransactionIntent,
51
50
  } from "@ledgerhq/coin-framework/api/types";
52
- import { AptosAsset } from "../types/assets";
53
51
  import { log } from "@ledgerhq/logs";
54
52
  import { transactionsToOperations } from "../logic/transactionsToOperations";
55
53
  import { isTestnet } from "../logic/isTestnet";
@@ -61,8 +59,6 @@ const getIndexerEndpoint = (currencyId: string) =>
61
59
  isTestnet(currencyId)
62
60
  ? getEnv("APTOS_TESTNET_INDEXER_ENDPOINT")
63
61
  : getEnv("APTOS_INDEXER_ENDPOINT");
64
- const getNetwork = (currencyId: string) =>
65
- isTestnet(currencyId) ? Network.TESTNET : Network.MAINNET;
66
62
 
67
63
  export class AptosAPI {
68
64
  private readonly aptosConfig: AptosConfig;
@@ -71,18 +67,10 @@ export class AptosAPI {
71
67
  readonly apolloClient: ApolloClient<object>;
72
68
 
73
69
  constructor(currencyIdOrSettings: AptosSettings | string) {
74
- const appVersion = getEnv("LEDGER_CLIENT_VERSION");
75
-
76
70
  if (typeof currencyIdOrSettings === "string") {
77
71
  this.aptosConfig = new AptosConfig({
78
- network: getNetwork(currencyIdOrSettings),
79
72
  fullnode: getApiEndpoint(currencyIdOrSettings),
80
73
  indexer: getIndexerEndpoint(currencyIdOrSettings),
81
- clientConfig: {
82
- HEADERS: {
83
- "X-Ledger-Client-Version": appVersion,
84
- },
85
- },
86
74
  });
87
75
  } else {
88
76
  this.aptosConfig = new AptosConfig(currencyIdOrSettings);
@@ -93,7 +81,7 @@ export class AptosAPI {
93
81
  uri: this.aptosConfig.indexer ?? "",
94
82
  cache: new InMemoryCache(),
95
83
  headers: {
96
- "X-Ledger-Client-Version": appVersion,
84
+ "x-client": "ledger-live",
97
85
  },
98
86
  });
99
87
  }
@@ -192,7 +180,7 @@ export class AptosAPI {
192
180
  };
193
181
  }
194
182
 
195
- async estimateFees(transactionIntent: TransactionIntent<AptosAsset>): Promise<FeeEstimation> {
183
+ async estimateFees(transactionIntent: TransactionIntent): Promise<FeeEstimation> {
196
184
  const publicKeyEd = new Ed25519PublicKey(transactionIntent?.senderPublicKey ?? "");
197
185
 
198
186
  const txPayload: InputEntryFunctionData = {
@@ -201,20 +189,21 @@ export class AptosAPI {
201
189
  functionArguments: [transactionIntent.recipient, transactionIntent.amount],
202
190
  };
203
191
 
204
- if (transactionIntent.asset.type === "token") {
205
- const { standard } = transactionIntent.asset;
192
+ // TODO: this should be looked over again, might be more precise in terms of types..
193
+ if (transactionIntent.asset.type !== "native") {
194
+ const { type } = transactionIntent.asset;
206
195
 
207
- if (standard === TOKEN_TYPE.FUNGIBLE_ASSET) {
196
+ if (type === TOKEN_TYPE.FUNGIBLE_ASSET) {
208
197
  txPayload.function = "0x1::primary_fungible_store::transfer";
209
198
  txPayload.typeArguments = ["0x1::fungible_asset::Metadata"];
210
199
  txPayload.functionArguments = [
211
- transactionIntent.asset.contractAddress,
200
+ transactionIntent.asset.assetReference,
212
201
  transactionIntent.recipient,
213
202
  transactionIntent.amount,
214
203
  ];
215
- } else if (standard === TOKEN_TYPE.COIN) {
204
+ } else if (type === TOKEN_TYPE.COIN) {
216
205
  txPayload.function = "0x1::aptos_account::transfer_coins";
217
- txPayload.typeArguments = [transactionIntent.asset.contractAddress];
206
+ txPayload.typeArguments = [transactionIntent.asset.assetReference as string];
218
207
  }
219
208
  }
220
209
 
@@ -277,10 +266,7 @@ export class AptosAPI {
277
266
  }
278
267
  }
279
268
 
280
- async listOperations(
281
- rawAddress: string,
282
- pagination: Pagination,
283
- ): Promise<[Operation<AptosAsset>[], string]> {
269
+ async listOperations(rawAddress: string, pagination: Pagination): Promise<[Operation[], string]> {
284
270
  const address = normalizeAddress(rawAddress);
285
271
  const transactions = await this.getAccountInfo(address, pagination.minHeight.toString());
286
272
  const newOperations = transactionsToOperations(address, transactions.transactions);
@@ -8,6 +8,8 @@ export const GetDelegatedStakingActivities = gql`
8
8
  ) {
9
9
  amount
10
10
  delegator_address
11
+ event_index
12
+ event_type
11
13
  pool_address
12
14
  transaction_version
13
15
  }
@@ -74,7 +76,10 @@ export const GetNumActiveDelegatorPerPoolData = gql`
74
76
 
75
77
  export const GetCurrentDelegatorBalancesData = gql`
76
78
  query GetCurrentDelegatorBalances {
77
- current_delegator_balances(distinct_on: pool_address) {
79
+ current_delegator_balances(
80
+ distinct_on: pool_address
81
+ order_by: { current_pool_balance: { total_coins: desc }, pool_address: asc }
82
+ ) {
78
83
  current_pool_balance {
79
84
  total_coins
80
85
  operator_commission_percentage
@@ -53,6 +53,8 @@ export type GetAccountTransactionsDataLtQuery = {
53
53
  export type DelegatedStakingActivity = {
54
54
  amount: number;
55
55
  delegator_address: string;
56
+ event_index: number;
57
+ event_type: string;
56
58
  pool_address: string;
57
59
  transaction_version: bigint;
58
60
  };
package/src/preload.ts CHANGED
@@ -2,15 +2,11 @@ import { CryptoCurrency } from "@ledgerhq/types-cryptoassets";
2
2
  import { setAptosPreloadData } from "./preload-data";
3
3
  import { AptosPreloadData, AptosValidator } from "./types";
4
4
  import { getValidators } from "./network/validators";
5
- import { getEnv } from "@ledgerhq/live-env";
6
5
 
7
6
  export const PRELOAD_MAX_AGE = 15 * 60 * 1000; // 15min
8
7
 
9
8
  export async function preloadWithValidators(currency: CryptoCurrency): Promise<AptosPreloadData> {
10
- let validators: AptosValidator[] = [];
11
- if (getEnv("APTOS_ENABLE_STAKING") === true) {
12
- validators = await getValidators(currency.id);
13
- }
9
+ const validators: AptosValidator[] = await getValidators(currency.id);
14
10
 
15
11
  const data: AptosPreloadData = {
16
12
  validatorsWithMeta: [],
@@ -1,12 +1,3 @@
1
- import type { Asset } from "@ledgerhq/coin-framework/api/types";
2
-
3
- export type AptosAsset = Asset<AptosTokenInformation>;
4
-
5
- export type AptosTokenInformation = {
6
- standard: string;
7
- contractAddress: string;
8
- };
9
-
10
1
  export type AptosExtra = Record<string, unknown>;
11
2
 
12
3
  export type AptosFeeParameters = {