@ledgerhq/coin-tron 4.5.0 → 4.5.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 (110) hide show
  1. package/CHANGELOG.md +7 -0
  2. package/lib/api/index.d.ts +2 -2
  3. package/lib/api/index.d.ts.map +1 -1
  4. package/lib/api/index.integ.test.js.map +1 -1
  5. package/lib/api/index.js.map +1 -1
  6. package/lib/api/index.test.js +2 -3
  7. package/lib/api/index.test.js.map +1 -1
  8. package/lib/bridge/getEstimateFees.d.ts.map +1 -1
  9. package/lib/bridge/getEstimateFees.js +3 -4
  10. package/lib/bridge/getEstimateFees.js.map +1 -1
  11. package/lib/logic/craftTransaction.d.ts +3 -3
  12. package/lib/logic/craftTransaction.d.ts.map +1 -1
  13. package/lib/logic/craftTransaction.integ.test.js +11 -16
  14. package/lib/logic/craftTransaction.integ.test.js.map +1 -1
  15. package/lib/logic/craftTransaction.js +6 -5
  16. package/lib/logic/craftTransaction.js.map +1 -1
  17. package/lib/logic/craftTransaction.test.js +10 -14
  18. package/lib/logic/craftTransaction.test.js.map +1 -1
  19. package/lib/logic/estimateFees.d.ts +2 -2
  20. package/lib/logic/estimateFees.d.ts.map +1 -1
  21. package/lib/logic/estimateFees.js +1 -1
  22. package/lib/logic/estimateFees.js.map +1 -1
  23. package/lib/logic/estimateFees.test.js +4 -6
  24. package/lib/logic/estimateFees.test.js.map +1 -1
  25. package/lib/logic/getBalance.d.ts +3 -4
  26. package/lib/logic/getBalance.d.ts.map +1 -1
  27. package/lib/logic/getBalance.integ.test.js +4 -1
  28. package/lib/logic/getBalance.integ.test.js.map +1 -1
  29. package/lib/logic/getBalance.js +4 -6
  30. package/lib/logic/getBalance.js.map +1 -1
  31. package/lib/logic/getBalance.test.js +60 -20
  32. package/lib/logic/getBalance.test.js.map +1 -1
  33. package/lib/logic/listOperations.d.ts +1 -2
  34. package/lib/logic/listOperations.d.ts.map +1 -1
  35. package/lib/logic/listOperations.integ.test.js +8 -12
  36. package/lib/logic/listOperations.integ.test.js.map +1 -1
  37. package/lib/logic/listOperations.js.map +1 -1
  38. package/lib/logic/listOperations.unit.test.js.map +1 -1
  39. package/lib/network/trongrid/trongrid-adapters.d.ts +2 -2
  40. package/lib/network/trongrid/trongrid-adapters.d.ts.map +1 -1
  41. package/lib/network/trongrid/trongrid-adapters.js +4 -6
  42. package/lib/network/trongrid/trongrid-adapters.js.map +1 -1
  43. package/lib/network/trongrid/trongrid-adapters.test.js +1 -1
  44. package/lib/network/trongrid/trongrid-adapters.test.js.map +1 -1
  45. package/lib/types/assets.d.ts +1 -11
  46. package/lib/types/assets.d.ts.map +1 -1
  47. package/lib-es/api/index.d.ts +2 -2
  48. package/lib-es/api/index.d.ts.map +1 -1
  49. package/lib-es/api/index.integ.test.js.map +1 -1
  50. package/lib-es/api/index.js.map +1 -1
  51. package/lib-es/api/index.test.js +2 -3
  52. package/lib-es/api/index.test.js.map +1 -1
  53. package/lib-es/bridge/getEstimateFees.d.ts.map +1 -1
  54. package/lib-es/bridge/getEstimateFees.js +3 -4
  55. package/lib-es/bridge/getEstimateFees.js.map +1 -1
  56. package/lib-es/logic/craftTransaction.d.ts +3 -3
  57. package/lib-es/logic/craftTransaction.d.ts.map +1 -1
  58. package/lib-es/logic/craftTransaction.integ.test.js +11 -16
  59. package/lib-es/logic/craftTransaction.integ.test.js.map +1 -1
  60. package/lib-es/logic/craftTransaction.js +6 -5
  61. package/lib-es/logic/craftTransaction.js.map +1 -1
  62. package/lib-es/logic/craftTransaction.test.js +10 -14
  63. package/lib-es/logic/craftTransaction.test.js.map +1 -1
  64. package/lib-es/logic/estimateFees.d.ts +2 -2
  65. package/lib-es/logic/estimateFees.d.ts.map +1 -1
  66. package/lib-es/logic/estimateFees.js +1 -1
  67. package/lib-es/logic/estimateFees.js.map +1 -1
  68. package/lib-es/logic/estimateFees.test.js +4 -6
  69. package/lib-es/logic/estimateFees.test.js.map +1 -1
  70. package/lib-es/logic/getBalance.d.ts +3 -4
  71. package/lib-es/logic/getBalance.d.ts.map +1 -1
  72. package/lib-es/logic/getBalance.integ.test.js +4 -1
  73. package/lib-es/logic/getBalance.integ.test.js.map +1 -1
  74. package/lib-es/logic/getBalance.js +4 -6
  75. package/lib-es/logic/getBalance.js.map +1 -1
  76. package/lib-es/logic/getBalance.test.js +60 -20
  77. package/lib-es/logic/getBalance.test.js.map +1 -1
  78. package/lib-es/logic/listOperations.d.ts +1 -2
  79. package/lib-es/logic/listOperations.d.ts.map +1 -1
  80. package/lib-es/logic/listOperations.integ.test.js +8 -12
  81. package/lib-es/logic/listOperations.integ.test.js.map +1 -1
  82. package/lib-es/logic/listOperations.js.map +1 -1
  83. package/lib-es/logic/listOperations.unit.test.js.map +1 -1
  84. package/lib-es/network/trongrid/trongrid-adapters.d.ts +2 -2
  85. package/lib-es/network/trongrid/trongrid-adapters.d.ts.map +1 -1
  86. package/lib-es/network/trongrid/trongrid-adapters.js +4 -6
  87. package/lib-es/network/trongrid/trongrid-adapters.js.map +1 -1
  88. package/lib-es/network/trongrid/trongrid-adapters.test.js +1 -1
  89. package/lib-es/network/trongrid/trongrid-adapters.test.js.map +1 -1
  90. package/lib-es/types/assets.d.ts +1 -11
  91. package/lib-es/types/assets.d.ts.map +1 -1
  92. package/package.json +7 -7
  93. package/src/api/index.integ.test.ts +1 -2
  94. package/src/api/index.test.ts +4 -6
  95. package/src/api/index.ts +5 -7
  96. package/src/bridge/getEstimateFees.ts +5 -6
  97. package/src/logic/craftTransaction.integ.test.ts +11 -16
  98. package/src/logic/craftTransaction.test.ts +15 -20
  99. package/src/logic/craftTransaction.ts +11 -11
  100. package/src/logic/estimateFees.test.ts +7 -10
  101. package/src/logic/estimateFees.ts +3 -3
  102. package/src/logic/getBalance.integ.test.ts +4 -1
  103. package/src/logic/getBalance.test.ts +60 -20
  104. package/src/logic/getBalance.ts +12 -15
  105. package/src/logic/listOperations.integ.test.ts +12 -17
  106. package/src/logic/listOperations.ts +1 -2
  107. package/src/logic/listOperations.unit.test.ts +5 -5
  108. package/src/network/trongrid/trongrid-adapters.test.ts +1 -1
  109. package/src/network/trongrid/trongrid-adapters.ts +8 -10
  110. package/src/types/assets.ts +1 -13
@@ -11,7 +11,6 @@ import coinConfig from "../config";
11
11
  import { TronConfig } from "../config";
12
12
  import { AlpacaApi, Pagination, TransactionIntent } from "@ledgerhq/coin-framework/api/types";
13
13
  import { createApi } from ".";
14
- import { TronAsset } from "../types";
15
14
 
16
15
  jest.mock("../config", () => ({
17
16
  setCoinConfig: jest.fn(),
@@ -49,16 +48,15 @@ describe("createApi", () => {
49
48
  });
50
49
 
51
50
  it("should pass parameters correctly", async () => {
52
- const api: AlpacaApi<TronAsset> = createApi(mockTronConfig);
53
- const intent: TransactionIntent<TronAsset> = {
51
+ const api: AlpacaApi = createApi(mockTronConfig);
52
+ const intent: TransactionIntent = {
54
53
  type: "send",
55
54
  sender: "sender",
56
55
  recipient: "recipient",
57
56
  amount: BigInt(10),
58
57
  asset: {
59
- type: "token",
60
- standard: "trc10",
61
- tokenId: "1002000",
58
+ type: "trc10",
59
+ assetReference: "1002000",
62
60
  },
63
61
  };
64
62
  // Simulate calling all methods
package/src/api/index.ts CHANGED
@@ -18,9 +18,9 @@ import {
18
18
  lastBlock,
19
19
  Options,
20
20
  } from "../logic";
21
- import type { TronAsset, TronMemo } from "../types";
21
+ import type { TronMemo } from "../types";
22
22
 
23
- export function createApi(config: TronConfig): AlpacaApi<TronAsset, TronMemo> {
23
+ export function createApi(config: TronConfig): AlpacaApi<TronMemo> {
24
24
  coinConfig.setCoinConfig(() => ({ ...config, status: { type: "active" } }));
25
25
 
26
26
  return {
@@ -31,7 +31,7 @@ export function createApi(config: TronConfig): AlpacaApi<TronAsset, TronMemo> {
31
31
  getBalance,
32
32
  lastBlock,
33
33
  listOperations,
34
- getBlock(_height): Promise<Block<TronAsset>> {
34
+ getBlock(_height): Promise<Block> {
35
35
  throw new Error("getBlock is not supported");
36
36
  },
37
37
  getBlockInfo(_height: number): Promise<BlockInfo> {
@@ -40,9 +40,7 @@ export function createApi(config: TronConfig): AlpacaApi<TronAsset, TronMemo> {
40
40
  };
41
41
  }
42
42
 
43
- async function estimate(
44
- transactionIntent: TransactionIntent<TronAsset, TronMemo>,
45
- ): Promise<FeeEstimation> {
43
+ async function estimate(transactionIntent: TransactionIntent<TronMemo>): Promise<FeeEstimation> {
46
44
  const fees = await estimateFees(transactionIntent);
47
45
  return { value: fees };
48
46
  }
@@ -50,7 +48,7 @@ async function estimate(
50
48
  async function listOperations(
51
49
  address: string,
52
50
  pagination: Pagination,
53
- ): Promise<[Operation<TronAsset>[], string]> {
51
+ ): Promise<[Operation[], string]> {
54
52
  const { minHeight } = pagination;
55
53
  const options: Options = {
56
54
  softLimit: 200,
@@ -2,7 +2,7 @@ import { Account, TokenAccount } from "@ledgerhq/types-live";
2
2
  import BigNumber from "bignumber.js";
3
3
  import { ACTIVATION_FEES, STANDARD_FEES_NATIVE, STANDARD_FEES_TRC_20 } from "../logic/constants";
4
4
  import type { AccountTronAPI } from "../network/types";
5
- import type { Transaction, TronAsset } from "../types";
5
+ import type { Transaction } from "../types";
6
6
  import { extractBandwidthInfo, getEstimatedBlockSize } from "./utils";
7
7
  import { estimateFees, getAccount } from "../logic";
8
8
  import type { TransactionIntent } from "@ledgerhq/coin-framework/api/index";
@@ -48,7 +48,7 @@ const getFeesFromAccountActivation = async (
48
48
  return ACTIVATION_FEES; // cost is around 1 TRX
49
49
  }
50
50
 
51
- const transactionIntent: TransactionIntent<TronAsset> = {
51
+ const transactionIntent: TransactionIntent = {
52
52
  type: transaction.mode,
53
53
  sender: account.freshAddress,
54
54
  recipient: transaction.recipient,
@@ -56,11 +56,10 @@ const getFeesFromAccountActivation = async (
56
56
  asset:
57
57
  tokenAccount?.token.tokenType === "trc20"
58
58
  ? {
59
- type: "token",
60
- standard: "trc20",
61
- contractAddress: tokenAccount.token.contractAddress,
59
+ type: "trc20",
60
+ assetReference: tokenAccount.token.contractAddress,
62
61
  }
63
- : { type: "token", standard: "trc10", tokenId: tokenAccount?.token.id },
62
+ : { type: "trc10", assetReference: tokenAccount?.token.id },
64
63
  };
65
64
 
66
65
  // if we have a token account but the recipient is either not active or the account does not have a trc20 balance for the given token.
@@ -25,9 +25,8 @@ describe("Testing craftTransaction function", () => {
25
25
  const result = await craftTransaction({
26
26
  type: "send",
27
27
  asset: {
28
- type: "token",
29
- standard: "trc10",
30
- tokenId: "1002000",
28
+ type: "trc10",
29
+ assetReference: "1002000",
31
30
  },
32
31
  sender,
33
32
  recipient,
@@ -67,9 +66,8 @@ describe("Testing craftTransaction function", () => {
67
66
  const result = await craftTransaction({
68
67
  type: "send",
69
68
  asset: {
70
- type: "token",
71
- standard: "trc20",
72
- contractAddress: "TLa2f6VPqDgRE67v1736s7bJ8Ray5wYjU7",
69
+ type: "trc20",
70
+ assetReference: "TLa2f6VPqDgRE67v1736s7bJ8Ray5wYjU7",
73
71
  },
74
72
  sender,
75
73
  recipient,
@@ -107,9 +105,8 @@ describe("Testing craftTransaction function", () => {
107
105
  const result = await craftTransaction({
108
106
  type: "send",
109
107
  asset: {
110
- type: "token",
111
- standard: "trc20",
112
- contractAddress: "TLa2f6VPqDgRE67v1736s7bJ8Ray5wYjU7",
108
+ type: "trc20",
109
+ assetReference: "TLa2f6VPqDgRE67v1736s7bJ8Ray5wYjU7",
113
110
  },
114
111
  sender,
115
112
  recipient,
@@ -136,15 +133,14 @@ describe("Testing craftTransaction function", () => {
136
133
  {
137
134
  type: "send",
138
135
  asset: {
139
- type: "token",
140
- standard: "trc20",
141
- contractAddress: "TLa2f6VPqDgRE67v1736s7bJ8Ray5wYjU7",
136
+ type: "trc20",
137
+ assetReference: "TLa2f6VPqDgRE67v1736s7bJ8Ray5wYjU7",
142
138
  },
143
139
  sender,
144
140
  recipient,
145
141
  amount,
146
142
  },
147
- customFees,
143
+ { value: customFees },
148
144
  );
149
145
 
150
146
  const decodeResult = await decodeTransaction(result);
@@ -233,9 +229,8 @@ describe("Testing craftTransaction function", () => {
233
229
  craftTransaction({
234
230
  type: "send",
235
231
  asset: {
236
- type: "token",
237
- standard: "trc20",
238
- contractAddress: "TLa2f6VPqDgRE67v1736s7bJ8Ray5wYjU7",
232
+ type: "trc20",
233
+ assetReference: "TLa2f6VPqDgRE67v1736s7bJ8Ray5wYjU7",
239
234
  },
240
235
  sender,
241
236
  recipient,
@@ -2,7 +2,6 @@ import { TransactionIntent } from "@ledgerhq/coin-framework/api/index";
2
2
  import BigNumber from "bignumber.js";
3
3
  import { craftStandardTransaction, craftTrc20Transaction } from "../network";
4
4
  import { decode58Check } from "../network/format";
5
- import { TronAsset } from "../types";
6
5
  import { craftTransaction } from "./craftTransaction";
7
6
 
8
7
  jest.mock("../network/format", () => ({
@@ -22,7 +21,7 @@ describe("craftTransaction", () => {
22
21
  });
23
22
 
24
23
  it("should craft a standard transaction", async () => {
25
- const transactionIntent: TransactionIntent<TronAsset> = {
24
+ const transactionIntent: TransactionIntent = {
26
25
  asset: { type: "native" },
27
26
  type: "send",
28
27
  recipient: "recipient",
@@ -52,12 +51,11 @@ describe("craftTransaction", () => {
52
51
  });
53
52
 
54
53
  it("should craft a TRC20 transaction", async () => {
55
- const transactionIntent: TransactionIntent<TronAsset> = {
54
+ const transactionIntent: TransactionIntent = {
56
55
  type: "send",
57
56
  asset: {
58
- type: "token",
59
- standard: "trc20",
60
- contractAddress: "contractAddress",
57
+ type: "trc20",
58
+ assetReference: "contractAddress",
61
59
  },
62
60
  recipient: "recipient",
63
61
  sender: "sender",
@@ -89,19 +87,18 @@ describe("craftTransaction", () => {
89
87
  const amount: number = 1000;
90
88
  const transactionIntent = {
91
89
  asset: {
92
- type: "token",
93
- standard: "trc20",
94
- contractAddress: "contractAddress",
90
+ type: "trc20",
91
+ assetReference: "contractAddress",
95
92
  },
96
93
  amount: BigInt(amount),
97
- } as TransactionIntent<TronAsset>;
94
+ } as TransactionIntent;
98
95
 
99
96
  (decode58Check as jest.Mock).mockImplementation(_address => undefined);
100
97
  (craftTrc20Transaction as jest.Mock).mockResolvedValue({
101
98
  raw_data_hex: "extendedRawDataHex",
102
99
  });
103
100
 
104
- await craftTransaction(transactionIntent, customFees);
101
+ await craftTransaction(transactionIntent, { value: customFees });
105
102
  expect(craftTrc20Transaction).toHaveBeenCalledWith(
106
103
  "contractAddress",
107
104
  undefined,
@@ -116,12 +113,11 @@ describe("craftTransaction", () => {
116
113
  const amount = 1000;
117
114
  const transactionIntent = {
118
115
  asset: {
119
- type: "token",
120
- standard: "trc20",
121
- contractAddress: "contractAddress",
116
+ type: "trc20",
117
+ assetReference: "contractAddress",
122
118
  },
123
119
  amount: BigInt(amount),
124
- } as TransactionIntent<TronAsset>;
120
+ } as TransactionIntent;
125
121
 
126
122
  (decode58Check as jest.Mock).mockImplementation(_address => undefined);
127
123
  (craftTrc20Transaction as jest.Mock).mockResolvedValue({
@@ -146,12 +142,11 @@ describe("craftTransaction", () => {
146
142
  await craftTransaction(
147
143
  {
148
144
  asset: {
149
- type: "token",
150
- standard: "trc20",
151
- contractAddress: "contractAddress",
145
+ type: "trc20",
146
+ assetReference: "contractAddress",
152
147
  },
153
- } as TransactionIntent<TronAsset>,
154
- customFees,
148
+ } as TransactionIntent,
149
+ { value: customFees },
155
150
  );
156
151
  } catch (error) {
157
152
  expect((error as Error).message).toEqual(
@@ -1,13 +1,13 @@
1
- import { TransactionIntent } from "@ledgerhq/coin-framework/api/index";
1
+ import { FeeEstimation, TransactionIntent } from "@ledgerhq/coin-framework/api/index";
2
2
  import BigNumber from "bignumber.js";
3
3
  import { craftStandardTransaction, craftTrc20Transaction } from "../network";
4
4
  import { decode58Check } from "../network/format";
5
- import { TronAsset, TronMemo } from "../types";
5
+ import { TronMemo } from "../types";
6
6
  import { feesToNumber } from "./utils";
7
7
 
8
8
  export async function craftTransaction(
9
- transactionIntent: TransactionIntent<TronAsset, TronMemo>,
10
- customFees?: bigint,
9
+ transactionIntent: TransactionIntent<TronMemo>,
10
+ customFees?: FeeEstimation,
11
11
  ): Promise<string> {
12
12
  const { asset, recipient, sender, amount, expiration } = transactionIntent;
13
13
  const rawMemo = "memo" in transactionIntent ? transactionIntent.memo : undefined;
@@ -16,8 +16,9 @@ export async function craftTransaction(
16
16
  const recipientAddress = decode58Check(recipient);
17
17
  const senderAddress = decode58Check(sender);
18
18
 
19
- if (asset.type === "token" && asset.standard === "trc20" && asset.contractAddress) {
20
- if (customFees !== undefined && (customFees <= 0 || customFees > Number.MAX_SAFE_INTEGER)) {
19
+ if (asset.type === "trc20" && asset.assetReference) {
20
+ const fees = customFees?.value;
21
+ if (fees !== undefined && (fees <= 0 || fees > Number.MAX_SAFE_INTEGER)) {
21
22
  throw new Error(
22
23
  `fees must be between 0 and ${Number.MAX_SAFE_INTEGER} (Typescript Number type value limit)`,
23
24
  );
@@ -28,18 +29,17 @@ export async function craftTransaction(
28
29
  }
29
30
 
30
31
  const { raw_data_hex: rawDataHex } = await craftTrc20Transaction(
31
- asset.contractAddress,
32
+ asset.assetReference,
32
33
  recipientAddress,
33
34
  senderAddress,
34
35
  new BigNumber(amount.toString()),
35
- feesToNumber(customFees),
36
+ feesToNumber(fees),
36
37
  expiration,
37
38
  );
38
39
  return rawDataHex as string;
39
40
  } else {
40
- const isTransferAsset = asset.type === "token" && asset.standard === "trc10";
41
- const tokenId =
42
- asset.type === "token" && asset.standard === "trc10" ? asset.tokenId : undefined;
41
+ const isTransferAsset = asset.type === "trc10";
42
+ const tokenId = asset.type === "trc10" ? asset.assetReference : undefined;
43
43
  const { raw_data_hex: rawDataHex } = await craftStandardTransaction(
44
44
  tokenId,
45
45
  recipientAddress,
@@ -1,11 +1,10 @@
1
1
  import { estimateFees } from "./estimateFees";
2
2
  import { ACTIVATION_FEES_TRC_20, STANDARD_FEES_NATIVE } from "./constants";
3
3
  import { TransactionIntent } from "@ledgerhq/coin-framework/api/index";
4
- import { TronAsset } from "../types";
5
4
 
6
5
  describe("estimateFees", () => {
7
6
  it("should calculate fees for native trx transactionIntent", async () => {
8
- const transactionIntent: TransactionIntent<TronAsset> = {
7
+ const transactionIntent: TransactionIntent = {
9
8
  type: "send",
10
9
  sender: "sender1",
11
10
  recipient: "recipient1",
@@ -18,15 +17,14 @@ describe("estimateFees", () => {
18
17
  expect(result).toEqual(BigInt(STANDARD_FEES_NATIVE.toString()));
19
18
  });
20
19
  it("should calculate fees for trc10 transactionIntent", async () => {
21
- const transactionIntent: TransactionIntent<TronAsset> = {
20
+ const transactionIntent: TransactionIntent = {
22
21
  type: "send",
23
22
  sender: "sender1",
24
23
  recipient: "recipient1",
25
24
  amount: BigInt(1000),
26
25
  asset: {
27
- type: "token",
28
- standard: "trc10",
29
- tokenId: "1002000",
26
+ type: "trc10",
27
+ assetReference: "1002000",
30
28
  },
31
29
  };
32
30
 
@@ -36,15 +34,14 @@ describe("estimateFees", () => {
36
34
  });
37
35
 
38
36
  it("should calculate fees for trc20 transactionIntent", async () => {
39
- const transactionIntent: TransactionIntent<TronAsset> = {
37
+ const transactionIntent: TransactionIntent = {
40
38
  type: "send",
41
39
  sender: "sender1",
42
40
  recipient: "recipient1",
43
41
  amount: BigInt(1000),
44
42
  asset: {
45
- type: "token",
46
- standard: "trc20",
47
- contractAddress: "T9yD14Nj9j7xAB4dbGeiX9h8unkKHxuWwb",
43
+ type: "trc20",
44
+ assetReference: "T9yD14Nj9j7xAB4dbGeiX9h8unkKHxuWwb",
48
45
  },
49
46
  };
50
47
  const result = await estimateFees(transactionIntent);
@@ -1,11 +1,11 @@
1
- import { TronAsset, TronMemo } from "../types";
1
+ import { TronMemo } from "../types";
2
2
  import { ACTIVATION_FEES_TRC_20, STANDARD_FEES_NATIVE } from "./constants";
3
3
  import type { TransactionIntent } from "@ledgerhq/coin-framework/api/index";
4
4
 
5
5
  export async function estimateFees(
6
- transactionIntent: TransactionIntent<TronAsset, TronMemo>,
6
+ transactionIntent: TransactionIntent<TronMemo>,
7
7
  ): Promise<bigint> {
8
- if (transactionIntent.asset.type === "token" && transactionIntent.asset.standard === "trc20") {
8
+ if (transactionIntent.asset.type === "trc20") {
9
9
  return BigInt(ACTIVATION_FEES_TRC_20.toString());
10
10
  } else {
11
11
  return BigInt(STANDARD_FEES_NATIVE.toString());
@@ -17,7 +17,10 @@ describe("getBalance", () => {
17
17
  const balances = await getBalance("TRqkRnAj6ceJFYAn2p1eE7aWrgBBwtdhS9");
18
18
 
19
19
  expect(balances[0].asset).toEqual({ type: "native" });
20
- balances.slice(1).forEach(balance => expect(balance.asset).toMatchObject({ type: "token" }));
20
+ // Backend either returns trc10 or trc20 first (randomly)
21
+ balances
22
+ .slice(1)
23
+ .forEach(balance => expect(["trc20", "trc10"].includes(balance.asset.type)).toBe(true));
21
24
  balances.forEach(balance => expect(balance.value).toBeGreaterThanOrEqual(0));
22
25
  });
23
26
  });
@@ -224,33 +224,73 @@ describe("getBalance", () => {
224
224
  const balance = await getBalance("41ae18eb0a9e067f8884058470ed187f44135d816d");
225
225
  expect(balance).toEqual([
226
226
  { asset: { type: "native" }, value: 27781772n },
227
- { asset: { standard: "trc10", tokenId: "1002897", type: "token" }, value: 10000000n },
228
- { asset: { standard: "trc10", tokenId: "1002775", type: "token" }, value: 5000000n },
229
- { asset: { standard: "trc10", tokenId: "1002830", type: "token" }, value: 10000000n },
230
- { asset: { standard: "trc10", tokenId: "1002962", type: "token" }, value: 10000000n },
231
- { asset: { standard: "trc10", tokenId: "1002876", type: "token" }, value: 10000000n },
232
- { asset: { standard: "trc10", tokenId: "1002398", type: "token" }, value: 5000000n },
233
- { asset: { standard: "trc10", tokenId: "1002573", type: "token" }, value: 5000000n },
234
- { asset: { standard: "trc10", tokenId: "1002881", type: "token" }, value: 10000000n },
235
- { asset: { standard: "trc10", tokenId: "1002927", type: "token" }, value: 10000000n },
236
- { asset: { standard: "trc10", tokenId: "1002736", type: "token" }, value: 5000000n },
237
- { asset: { standard: "trc10", tokenId: "1002814", type: "token" }, value: 10000000n },
238
- { asset: { standard: "trc10", tokenId: "1002858", type: "token" }, value: 10000000n },
239
- { asset: { standard: "trc10", tokenId: "1002000", type: "token" }, value: 26888000n },
240
- { asset: { standard: "trc10", tokenId: "1004031", type: "token" }, value: 9856699n },
227
+ {
228
+ asset: { type: "trc10", assetReference: "1002897" },
229
+ value: 10000000n,
230
+ },
231
+ {
232
+ asset: { type: "trc10", assetReference: "1002775" },
233
+ value: 5000000n,
234
+ },
235
+ {
236
+ asset: { type: "trc10", assetReference: "1002830" },
237
+ value: 10000000n,
238
+ },
239
+ {
240
+ asset: { type: "trc10", assetReference: "1002962" },
241
+ value: 10000000n,
242
+ },
243
+ {
244
+ asset: { type: "trc10", assetReference: "1002876" },
245
+ value: 10000000n,
246
+ },
247
+ {
248
+ asset: { type: "trc10", assetReference: "1002398" },
249
+ value: 5000000n,
250
+ },
251
+ {
252
+ asset: { type: "trc10", assetReference: "1002573" },
253
+ value: 5000000n,
254
+ },
255
+ {
256
+ asset: { type: "trc10", assetReference: "1002881" },
257
+ value: 10000000n,
258
+ },
259
+ {
260
+ asset: { type: "trc10", assetReference: "1002927" },
261
+ value: 10000000n,
262
+ },
263
+ {
264
+ asset: { type: "trc10", assetReference: "1002736" },
265
+ value: 5000000n,
266
+ },
267
+ {
268
+ asset: { type: "trc10", assetReference: "1002814" },
269
+ value: 10000000n,
270
+ },
271
+ {
272
+ asset: { type: "trc10", assetReference: "1002858" },
273
+ value: 10000000n,
274
+ },
275
+ {
276
+ asset: { type: "trc10", assetReference: "1002000" },
277
+ value: 26888000n,
278
+ },
279
+ {
280
+ asset: { type: "trc10", assetReference: "1004031" },
281
+ value: 9856699n,
282
+ },
241
283
  {
242
284
  asset: {
243
- contractAddress: "TLa2f6VPqDgRE67v1736s7bJ8Ray5wYjU7",
244
- standard: "trc20",
245
- type: "token",
285
+ type: "trc20",
286
+ assetReference: "TLa2f6VPqDgRE67v1736s7bJ8Ray5wYjU7",
246
287
  },
247
288
  value: 46825830n,
248
289
  },
249
290
  {
250
291
  asset: {
251
- contractAddress: "TR7NHqjeKQxGTCi8q8ZY4pL8otSzgjLj6t",
252
- standard: "trc20",
253
- type: "token",
292
+ type: "trc20",
293
+ assetReference: "TR7NHqjeKQxGTCi8q8ZY4pL8otSzgjLj6t",
254
294
  },
255
295
  value: 376n,
256
296
  },
@@ -1,14 +1,13 @@
1
1
  import BigNumber from "bignumber.js";
2
2
  import type { AccountTronAPI } from "../network/types";
3
3
  import { getTronResources } from "./utils";
4
- import { Asset, Balance } from "@ledgerhq/coin-framework/api/index";
4
+ import { Balance } from "@ledgerhq/coin-framework/api/index";
5
5
  import { fetchTronAccount } from "../network";
6
- import { Trc10Token, Trc20Token, TronAsset } from "../types";
7
6
 
8
7
  const bigIntOrZero = (val: number | BigNumber | undefined | null): bigint =>
9
8
  BigInt(val?.toString() ?? 0);
10
9
 
11
- export async function getBalance(address: string): Promise<Balance<TronAsset>[]> {
10
+ export async function getBalance(address: string): Promise<Balance[]> {
12
11
  const accounts = await fetchTronAccount(address);
13
12
 
14
13
  // if account is not activated, an empty array is returned
@@ -16,43 +15,41 @@ export async function getBalance(address: string): Promise<Balance<TronAsset>[]>
16
15
 
17
16
  const account = accounts[0];
18
17
 
19
- const nativeBalance: Balance<TronAsset> = computeBalance(account);
20
- const trc10Balance: Balance<TronAsset>[] = extractTrc10Balance(account);
21
- const trc20Balance: Balance<TronAsset>[] = extractTrc20Balance(account);
18
+ const nativeBalance: Balance = computeBalance(account);
19
+ const trc10Balance: Balance[] = extractTrc10Balance(account);
20
+ const trc20Balance: Balance[] = extractTrc20Balance(account);
22
21
 
23
22
  return [nativeBalance].concat(trc10Balance).concat(trc20Balance);
24
23
  }
25
24
 
26
- function extractTrc10Balance(account: AccountTronAPI): Balance<Asset<Trc10Token>>[] {
25
+ function extractTrc10Balance(account: AccountTronAPI): Balance[] {
27
26
  return (
28
27
  account.assetV2?.map(trc => {
29
28
  return {
30
29
  value: BigInt(trc.value),
31
30
  asset: {
32
- type: "token",
33
- standard: "trc10",
34
- tokenId: trc.key,
31
+ type: "trc10",
32
+ assetReference: trc.key,
35
33
  },
36
34
  };
37
35
  }) ?? []
38
36
  );
39
37
  }
40
38
 
41
- function extractTrc20Balance(account: AccountTronAPI): Balance<Asset<Trc20Token>>[] {
39
+ function extractTrc20Balance(account: AccountTronAPI): Balance[] {
42
40
  return account.trc20.map(trc => {
43
41
  const [[contractAddress, balance]] = Object.entries(trc);
44
42
  return {
45
43
  value: BigInt(balance),
46
44
  asset: {
47
- type: "token",
48
- standard: "trc20",
49
- contractAddress,
45
+ type: "trc20",
46
+ assetReference: contractAddress,
50
47
  },
51
48
  };
52
49
  });
53
50
  }
54
51
 
55
- export function computeBalance(account: AccountTronAPI): Balance<Asset> {
52
+ export function computeBalance(account: AccountTronAPI): Balance {
56
53
  const tronResources = getTronResources(account);
57
54
 
58
55
  let balance = bigIntOrZero(account.balance ?? 0);
@@ -1,7 +1,6 @@
1
1
  import { defaultOptions, listOperations, Options } from "./listOperations";
2
2
  import coinConfig from "../config";
3
3
  import { Operation } from "@ledgerhq/coin-framework/api/types";
4
- import { TronAsset } from "../types";
5
4
 
6
5
  describe("listOperations", () => {
7
6
  beforeAll(() => {
@@ -18,7 +17,7 @@ describe("listOperations", () => {
18
17
  describe("Account TRqkRnAj6ceJFYAn2p1eE7aWrgBBwtdhS9 with minHeight", () => {
19
18
  // https://tronscan.org/#/address/TRqkRnAj6ceJFYAn2p1eE7aWrgBBwtdhS9
20
19
 
21
- let operations: Operation<TronAsset>[];
20
+ let operations: Operation[];
22
21
 
23
22
  const testingAccount = "TRqkRnAj6ceJFYAn2p1eE7aWrgBBwtdhS9";
24
23
 
@@ -44,7 +43,7 @@ describe("listOperations", () => {
44
43
  describe("Account TRRYfGVrzuUvJYRe9UaA8KqxjgVSwU9m6L withe more than 15k+ txs, with minHeight 0 / order asc / softLimit 2", () => {
45
44
  // https://tronscan.org/#/address/TRRYfGVrzuUvJYRe9UaA8KqxjgVSwU9m6L
46
45
 
47
- let operations: Operation<TronAsset>[];
46
+ let operations: Operation[];
48
47
 
49
48
  const testingAccount = "TRRYfGVrzuUvJYRe9UaA8KqxjgVSwU9m6L";
50
49
 
@@ -77,7 +76,7 @@ describe("listOperations", () => {
77
76
  describe("Account TRRYfGVrzuUvJYRe9UaA8KqxjgVSwU9m6L withe more than 15k+ txs, with minHeight / order asc / softLimit 2", () => {
78
77
  // https://tronscan.org/#/address/TRRYfGVrzuUvJYRe9UaA8KqxjgVSwU9m6L
79
78
 
80
- let operations: Operation<TronAsset>[];
79
+ let operations: Operation[];
81
80
 
82
81
  const testingAccount = "TRRYfGVrzuUvJYRe9UaA8KqxjgVSwU9m6L";
83
82
 
@@ -117,7 +116,7 @@ describe("listOperations", () => {
117
116
  // 255 as of 17/02/2025
118
117
  const historySize = 255;
119
118
 
120
- let operations: Operation<TronAsset>[];
119
+ let operations: Operation[];
121
120
 
122
121
  const testingAccount = "TRqkRnAj6ceJFYAn2p1eE7aWrgBBwtdhS9";
123
122
 
@@ -223,9 +222,8 @@ describe("listOperations", () => {
223
222
  recipients: [testingAccount],
224
223
  senders: ["TWBEcQ57vbFSEhrQCvsHLDuSb39wprpsEX"],
225
224
  asset: {
226
- type: "token",
227
- standard: "trc10",
228
- tokenId: "1004031",
225
+ type: "trc10",
226
+ assetReference: "1004031",
229
227
  },
230
228
  });
231
229
  });
@@ -240,9 +238,8 @@ describe("listOperations", () => {
240
238
  senders: [testingAccount],
241
239
  recipients: ["TVKG4gUar24bpAVrDv4GSzyDRtPkjPkogL"],
242
240
  asset: {
243
- type: "token",
244
- standard: "trc10",
245
- tokenId: "1002000",
241
+ type: "trc10",
242
+ assetReference: "1002000",
246
243
  },
247
244
  });
248
245
  });
@@ -260,9 +257,8 @@ describe("listOperations", () => {
260
257
  senders: ["TUgU8FRUFSUfxTAoSPsaUBzJgSwpUuJs9N"],
261
258
  recipients: [testingAccount],
262
259
  asset: {
263
- type: "token",
264
- standard: "trc20",
265
- contractAddress: "TR7NHqjeKQxGTCi8q8ZY4pL8otSzgjLj6t",
260
+ type: "trc20",
261
+ assetReference: "TR7NHqjeKQxGTCi8q8ZY4pL8otSzgjLj6t",
266
262
  },
267
263
  });
268
264
  });
@@ -278,9 +274,8 @@ describe("listOperations", () => {
278
274
  senders: [testingAccount],
279
275
  recipients: ["TLAhq1ds7UR339t48TpzYcJWtfGnXk1KzX"],
280
276
  asset: {
281
- type: "token",
282
- standard: "trc20",
283
- contractAddress: "TLa2f6VPqDgRE67v1736s7bJ8Ray5wYjU7",
277
+ type: "trc20",
278
+ assetReference: "TLa2f6VPqDgRE67v1736s7bJ8Ray5wYjU7",
284
279
  },
285
280
  });
286
281
  });
@@ -6,7 +6,6 @@ import {
6
6
  getBlock,
7
7
  } from "../network";
8
8
  import { fromTrongridTxInfoToOperation } from "../network/trongrid/trongrid-adapters";
9
- import { TronAsset } from "../types";
10
9
 
11
10
  export type Options = {
12
11
  // the soft limit is an indicative number of transactions to fetch
@@ -27,7 +26,7 @@ export const defaultOptions: Options = {
27
26
  export async function listOperations(
28
27
  address: string,
29
28
  options: Options,
30
- ): Promise<[Operation<TronAsset>[], string]> {
29
+ ): Promise<[Operation[], string]> {
31
30
  // there is a possible optimisation here: when height is 0, set the minTimestamp to 0
32
31
  const block = await getBlock(options.minHeight);
33
32
  const minTimestamp = block.time?.getTime() ?? defaultFetchParams.minTimestamp;