@ledgerhq/coin-hedera 1.15.0-nightly.20251205111238 → 1.15.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 (187) hide show
  1. package/.turbo/turbo-build.log +1 -1
  2. package/CHANGELOG.md +26 -10
  3. package/lib/bridge/buildOptimisticOperation.d.ts.map +1 -1
  4. package/lib/bridge/buildOptimisticOperation.js +0 -33
  5. package/lib/bridge/buildOptimisticOperation.js.map +1 -1
  6. package/lib/bridge/getTransactionStatus.d.ts.map +1 -1
  7. package/lib/bridge/getTransactionStatus.js +0 -54
  8. package/lib/bridge/getTransactionStatus.js.map +1 -1
  9. package/lib/bridge/index.d.ts.map +1 -1
  10. package/lib/bridge/index.js +2 -4
  11. package/lib/bridge/index.js.map +1 -1
  12. package/lib/bridge/prepareTransaction.d.ts.map +1 -1
  13. package/lib/bridge/prepareTransaction.js +0 -16
  14. package/lib/bridge/prepareTransaction.js.map +1 -1
  15. package/lib/bridge/serialization.d.ts.map +1 -1
  16. package/lib/bridge/serialization.js +0 -20
  17. package/lib/bridge/serialization.js.map +1 -1
  18. package/lib/bridge/signOperation.d.ts +4 -4
  19. package/lib/bridge/signOperation.d.ts.map +1 -1
  20. package/lib/bridge/signOperation.js +0 -10
  21. package/lib/bridge/signOperation.js.map +1 -1
  22. package/lib/bridge/synchronisation.d.ts.map +1 -1
  23. package/lib/bridge/synchronisation.js +0 -8
  24. package/lib/bridge/synchronisation.js.map +1 -1
  25. package/lib/constants.d.ts +1 -21
  26. package/lib/constants.d.ts.map +1 -1
  27. package/lib/constants.js +1 -22
  28. package/lib/constants.js.map +1 -1
  29. package/lib/deviceTransactionConfig.d.ts.map +1 -1
  30. package/lib/deviceTransactionConfig.js +0 -30
  31. package/lib/deviceTransactionConfig.js.map +1 -1
  32. package/lib/errors.d.ts +0 -9
  33. package/lib/errors.d.ts.map +1 -1
  34. package/lib/errors.js +1 -4
  35. package/lib/errors.js.map +1 -1
  36. package/lib/logic/craftTransaction.d.ts +2 -2
  37. package/lib/logic/craftTransaction.d.ts.map +1 -1
  38. package/lib/logic/craftTransaction.js +8 -42
  39. package/lib/logic/craftTransaction.js.map +1 -1
  40. package/lib/logic/getBlock.d.ts.map +1 -1
  41. package/lib/logic/getBlock.js +0 -1
  42. package/lib/logic/getBlock.js.map +1 -1
  43. package/lib/logic/listOperations.d.ts.map +1 -1
  44. package/lib/logic/listOperations.js +7 -39
  45. package/lib/logic/listOperations.js.map +1 -1
  46. package/lib/logic/utils.d.ts +3 -61
  47. package/lib/logic/utils.d.ts.map +1 -1
  48. package/lib/logic/utils.js +3 -116
  49. package/lib/logic/utils.js.map +1 -1
  50. package/lib/network/api.d.ts +1 -3
  51. package/lib/network/api.d.ts.map +1 -1
  52. package/lib/network/api.js +0 -19
  53. package/lib/network/api.js.map +1 -1
  54. package/lib/test/fixtures/account.fixture.d.ts +1 -1
  55. package/lib/test/fixtures/account.fixture.d.ts.map +1 -1
  56. package/lib/test/fixtures/account.fixture.js +0 -2
  57. package/lib/test/fixtures/account.fixture.js.map +1 -1
  58. package/lib/transaction.d.ts.map +1 -1
  59. package/lib/transaction.js +0 -34
  60. package/lib/transaction.js.map +1 -1
  61. package/lib/types/alpaca.d.ts +0 -3
  62. package/lib/types/alpaca.d.ts.map +1 -1
  63. package/lib/types/bridge.d.ts +3 -87
  64. package/lib/types/bridge.d.ts.map +1 -1
  65. package/lib/types/logic.d.ts +1 -5
  66. package/lib/types/logic.d.ts.map +1 -1
  67. package/lib/types/mirror.d.ts +0 -19
  68. package/lib/types/mirror.d.ts.map +1 -1
  69. package/lib-es/bridge/buildOptimisticOperation.d.ts.map +1 -1
  70. package/lib-es/bridge/buildOptimisticOperation.js +1 -34
  71. package/lib-es/bridge/buildOptimisticOperation.js.map +1 -1
  72. package/lib-es/bridge/getTransactionStatus.d.ts.map +1 -1
  73. package/lib-es/bridge/getTransactionStatus.js +3 -57
  74. package/lib-es/bridge/getTransactionStatus.js.map +1 -1
  75. package/lib-es/bridge/index.d.ts.map +1 -1
  76. package/lib-es/bridge/index.js +2 -4
  77. package/lib-es/bridge/index.js.map +1 -1
  78. package/lib-es/bridge/prepareTransaction.d.ts.map +1 -1
  79. package/lib-es/bridge/prepareTransaction.js +2 -15
  80. package/lib-es/bridge/prepareTransaction.js.map +1 -1
  81. package/lib-es/bridge/serialization.d.ts.map +1 -1
  82. package/lib-es/bridge/serialization.js +0 -17
  83. package/lib-es/bridge/serialization.js.map +1 -1
  84. package/lib-es/bridge/signOperation.d.ts +4 -4
  85. package/lib-es/bridge/signOperation.d.ts.map +1 -1
  86. package/lib-es/bridge/signOperation.js +1 -11
  87. package/lib-es/bridge/signOperation.js.map +1 -1
  88. package/lib-es/bridge/synchronisation.d.ts.map +1 -1
  89. package/lib-es/bridge/synchronisation.js +0 -8
  90. package/lib-es/bridge/synchronisation.js.map +1 -1
  91. package/lib-es/constants.d.ts +1 -21
  92. package/lib-es/constants.d.ts.map +1 -1
  93. package/lib-es/constants.js +0 -21
  94. package/lib-es/constants.js.map +1 -1
  95. package/lib-es/deviceTransactionConfig.d.ts.map +1 -1
  96. package/lib-es/deviceTransactionConfig.js +1 -31
  97. package/lib-es/deviceTransactionConfig.js.map +1 -1
  98. package/lib-es/errors.d.ts +0 -9
  99. package/lib-es/errors.d.ts.map +1 -1
  100. package/lib-es/errors.js +0 -3
  101. package/lib-es/errors.js.map +1 -1
  102. package/lib-es/logic/craftTransaction.d.ts +2 -2
  103. package/lib-es/logic/craftTransaction.d.ts.map +1 -1
  104. package/lib-es/logic/craftTransaction.js +10 -44
  105. package/lib-es/logic/craftTransaction.js.map +1 -1
  106. package/lib-es/logic/getBlock.d.ts.map +1 -1
  107. package/lib-es/logic/getBlock.js +1 -2
  108. package/lib-es/logic/getBlock.js.map +1 -1
  109. package/lib-es/logic/listOperations.d.ts.map +1 -1
  110. package/lib-es/logic/listOperations.js +7 -39
  111. package/lib-es/logic/listOperations.js.map +1 -1
  112. package/lib-es/logic/utils.d.ts +3 -61
  113. package/lib-es/logic/utils.d.ts.map +1 -1
  114. package/lib-es/logic/utils.js +3 -106
  115. package/lib-es/logic/utils.js.map +1 -1
  116. package/lib-es/network/api.d.ts +1 -3
  117. package/lib-es/network/api.d.ts.map +1 -1
  118. package/lib-es/network/api.js +0 -19
  119. package/lib-es/network/api.js.map +1 -1
  120. package/lib-es/test/fixtures/account.fixture.d.ts +1 -1
  121. package/lib-es/test/fixtures/account.fixture.d.ts.map +1 -1
  122. package/lib-es/test/fixtures/account.fixture.js +0 -2
  123. package/lib-es/test/fixtures/account.fixture.js.map +1 -1
  124. package/lib-es/transaction.d.ts.map +1 -1
  125. package/lib-es/transaction.js +0 -34
  126. package/lib-es/transaction.js.map +1 -1
  127. package/lib-es/types/alpaca.d.ts +0 -3
  128. package/lib-es/types/alpaca.d.ts.map +1 -1
  129. package/lib-es/types/bridge.d.ts +3 -87
  130. package/lib-es/types/bridge.d.ts.map +1 -1
  131. package/lib-es/types/logic.d.ts +1 -5
  132. package/lib-es/types/logic.d.ts.map +1 -1
  133. package/lib-es/types/mirror.d.ts +0 -19
  134. package/lib-es/types/mirror.d.ts.map +1 -1
  135. package/package.json +9 -10
  136. package/src/api/index.integ.test.ts +1 -11
  137. package/src/bridge/buildOptimisticOperation.integration.test.ts +4 -159
  138. package/src/bridge/buildOptimisticOperation.ts +2 -50
  139. package/src/bridge/getTransactionStatus.test.ts +21 -191
  140. package/src/bridge/getTransactionStatus.ts +1 -75
  141. package/src/bridge/index.ts +2 -4
  142. package/src/bridge/prepareTransaction.test.ts +8 -112
  143. package/src/bridge/prepareTransaction.ts +2 -20
  144. package/src/bridge/serialization.ts +0 -17
  145. package/src/bridge/signOperation.ts +5 -15
  146. package/src/bridge/synchronisation.ts +0 -9
  147. package/src/bridge/utils.integration.test.ts +10 -3
  148. package/src/constants.ts +0 -22
  149. package/src/deviceTransactionConfig.ts +1 -37
  150. package/src/errors.ts +0 -7
  151. package/src/logic/craftTransaction.ts +13 -70
  152. package/src/logic/getBalance.test.ts +16 -15
  153. package/src/logic/getBlock.ts +1 -2
  154. package/src/logic/listOperations.test.ts +29 -86
  155. package/src/logic/listOperations.ts +6 -46
  156. package/src/logic/utils.test.ts +8 -362
  157. package/src/logic/utils.ts +3 -157
  158. package/src/network/api.test.ts +6 -58
  159. package/src/network/api.ts +0 -25
  160. package/src/network/thirdweb.test.ts +2 -2
  161. package/src/network/utils.test.ts +6 -4
  162. package/src/test/fixtures/account.fixture.ts +1 -3
  163. package/src/transaction.ts +0 -42
  164. package/src/types/alpaca.ts +0 -4
  165. package/src/types/bridge.ts +3 -108
  166. package/src/types/logic.ts +1 -6
  167. package/src/types/mirror.ts +0 -21
  168. package/lib/preload-data.d.ts +0 -7
  169. package/lib/preload-data.d.ts.map +0 -1
  170. package/lib/preload-data.js +0 -37
  171. package/lib/preload-data.js.map +0 -1
  172. package/lib/preload.d.ts +0 -8
  173. package/lib/preload.d.ts.map +0 -1
  174. package/lib/preload.js +0 -76
  175. package/lib/preload.js.map +0 -1
  176. package/lib-es/preload-data.d.ts +0 -7
  177. package/lib-es/preload-data.d.ts.map +0 -1
  178. package/lib-es/preload-data.js +0 -31
  179. package/lib-es/preload-data.js.map +0 -1
  180. package/lib-es/preload.d.ts +0 -8
  181. package/lib-es/preload.d.ts.map +0 -1
  182. package/lib-es/preload.js +0 -67
  183. package/lib-es/preload.js.map +0 -1
  184. package/src/deviceTransactionConfig.test.ts +0 -315
  185. package/src/preload-data.ts +0 -38
  186. package/src/preload.test.ts +0 -64
  187. package/src/preload.ts +0 -80
@@ -4,24 +4,18 @@ import {
4
4
  InvalidAddressBecauseDestinationIsAlsoSource,
5
5
  AmountRequired,
6
6
  NotEnoughBalance,
7
- ClaimRewardsFeesWarning,
8
- RecipientRequired,
9
7
  } from "@ledgerhq/errors";
10
8
  import { HEDERA_TRANSACTION_MODES } from "../constants";
11
9
  import {
12
10
  HederaInsufficientFundsForAssociation,
13
- HederaInvalidStakingNodeIdError,
14
- HederaNoStakingRewardsError,
15
11
  HederaRecipientEvmAddressVerificationRequired,
16
12
  HederaRecipientInvalidChecksum,
17
13
  HederaRecipientTokenAssociationRequired,
18
14
  HederaRecipientTokenAssociationUnverified,
19
- HederaRedundantStakingNodeIdError,
20
15
  } from "../errors";
21
16
  import { getTransactionStatus } from "./getTransactionStatus";
22
17
  import * as estimateFees from "../logic/estimateFees";
23
18
  import * as logicUtils from "../logic/utils";
24
- import * as preloadData from "../preload-data";
25
19
  import { rpcClient } from "../network/rpc";
26
20
  import { getMockedAccount, getMockedTokenAccount } from "../test/fixtures/account.fixture";
27
21
  import {
@@ -29,28 +23,26 @@ import {
29
23
  getMockedHTSTokenCurrency,
30
24
  } from "../test/fixtures/currency.fixture";
31
25
  import { getMockedTransaction } from "../test/fixtures/transaction.fixture";
32
- import type { EstimateFeesResult, HederaPreloadData } from "../types";
26
+ import type { EstimateFeesResult } from "../types";
33
27
 
34
28
  describe("getTransactionStatus", () => {
35
29
  const mockedEstimatedFee: EstimateFeesResult = { tinybars: new BigNumber(1) };
36
30
  const mockedUsdRate = new BigNumber(1);
37
- const mockPreload = { validators: [{ nodeId: 1 }, { nodeId: 2 }] } as HederaPreloadData;
38
31
  const validRecipientAddress = "0.0.1234567";
39
32
  const validRecipientAddressWithChecksum = "0.0.1234567-ylkls";
40
33
 
41
34
  beforeEach(() => {
42
35
  jest.clearAllMocks();
43
36
 
44
- jest.spyOn(estimateFees, "estimateFees").mockResolvedValueOnce(mockedEstimatedFee);
45
37
  jest.spyOn(logicUtils, "getCurrencyToUSDRate").mockResolvedValueOnce(mockedUsdRate);
46
- jest.spyOn(preloadData, "getCurrentHederaPreloadData").mockReturnValueOnce(mockPreload);
38
+ jest.spyOn(estimateFees, "estimateFees").mockResolvedValueOnce(mockedEstimatedFee);
47
39
  });
48
40
 
49
41
  afterAll(() => {
50
42
  rpcClient._resetInstance();
51
43
  });
52
44
 
53
- it("coin transfer with valid recipient and sufficient balance completes successfully", async () => {
45
+ test("coin transfer with valid recipient and sufficient balance completes successfully", async () => {
54
46
  const mockedAccount = getMockedAccount({ balance: new BigNumber(1000) });
55
47
  const mockedTransaction = getMockedTransaction({
56
48
  recipient: validRecipientAddress,
@@ -65,7 +57,7 @@ describe("getTransactionStatus", () => {
65
57
  expect(result.totalSpent.isGreaterThan(100)).toBe(true);
66
58
  });
67
59
 
68
- it("hts token transfer with valid recipient and sufficient balance completes successfully", async () => {
60
+ test("hts token transfer with valid recipient and sufficient balance completes successfully", async () => {
69
61
  jest.spyOn(logicUtils, "checkAccountTokenAssociationStatus").mockResolvedValueOnce(true);
70
62
 
71
63
  const tokenCurrency = getMockedHTSTokenCurrency();
@@ -84,7 +76,7 @@ describe("getTransactionStatus", () => {
84
76
  expect(result.amount).toEqual(new BigNumber(200));
85
77
  });
86
78
 
87
- it("erc20 token transfer with valid recipient and sufficient balance completes successfully", async () => {
79
+ test("erc20 token transfer with valid recipient and sufficient balance completes successfully", async () => {
88
80
  const tokenCurrency = getMockedERC20TokenCurrency();
89
81
  const tokenAccount = getMockedTokenAccount(tokenCurrency, { balance: new BigNumber(500) });
90
82
  const account = getMockedAccount({ balance: new BigNumber(1000), subAccounts: [tokenAccount] });
@@ -103,7 +95,7 @@ describe("getTransactionStatus", () => {
103
95
  expect(result.amount).toEqual(new BigNumber(200));
104
96
  });
105
97
 
106
- it("token associate transaction with sufficient USD worth completes successfully", async () => {
98
+ test("token associate transaction with sufficient USD worth completes successfully", async () => {
107
99
  const mockedTokenCurrency = getMockedHTSTokenCurrency();
108
100
  const mockedAccount = getMockedAccount();
109
101
  const mockedTransaction = getMockedTransaction({
@@ -122,7 +114,7 @@ describe("getTransactionStatus", () => {
122
114
  expect(result.estimatedFees).toEqual(mockedEstimatedFee.tinybars);
123
115
  });
124
116
 
125
- it("recipient with checksum is supported", async () => {
117
+ test("recipient with checksum is supported", async () => {
126
118
  const mockedAccount = getMockedAccount({ balance: new BigNumber(1000) });
127
119
  const mockedTransaction = getMockedTransaction({
128
120
  recipient: validRecipientAddressWithChecksum,
@@ -135,25 +127,22 @@ describe("getTransactionStatus", () => {
135
127
  expect(result.warnings).toEqual({});
136
128
  });
137
129
 
138
- it("adds error for invalid recipient address", async () => {
130
+ test("adds error for invalid recipient address", async () => {
139
131
  const mockedAccount = getMockedAccount();
140
132
 
141
- const txWithInvalidAddress1 = getMockedTransaction({ recipient: "" });
142
- const txWithInvalidAddress2 = getMockedTransaction({ recipient: "invalid_address" });
133
+ const txWithInvalidAddress = getMockedTransaction({ recipient: "invalid_address" });
143
134
  const txWithInvalidAddressChecksum = getMockedTransaction({ recipient: "0.0.9124531-invld" });
144
135
 
145
- const [result1, result2, result3] = await Promise.all([
146
- getTransactionStatus(mockedAccount, txWithInvalidAddress1),
147
- getTransactionStatus(mockedAccount, txWithInvalidAddress2),
136
+ const [result1, result2] = await Promise.all([
137
+ getTransactionStatus(mockedAccount, txWithInvalidAddress),
148
138
  getTransactionStatus(mockedAccount, txWithInvalidAddressChecksum),
149
139
  ]);
150
140
 
151
- expect(result1.errors.recipient).toBeInstanceOf(RecipientRequired);
152
- expect(result2.errors.recipient).toBeInstanceOf(InvalidAddress);
153
- expect(result3.errors.recipient).toBeInstanceOf(HederaRecipientInvalidChecksum);
141
+ expect(result1.errors.recipient).toBeInstanceOf(InvalidAddress);
142
+ expect(result2.errors.recipient).toBeInstanceOf(HederaRecipientInvalidChecksum);
154
143
  });
155
144
 
156
- it("adds error for self transfers", async () => {
145
+ test("adds error for self transfers", async () => {
157
146
  const mockedAccount = getMockedAccount();
158
147
  const mockedTransaction = getMockedTransaction({
159
148
  recipient: mockedAccount.freshAddress,
@@ -164,7 +153,7 @@ describe("getTransactionStatus", () => {
164
153
  expect(result.errors.recipient).toBeInstanceOf(InvalidAddressBecauseDestinationIsAlsoSource);
165
154
  });
166
155
 
167
- it("adds error during coin transfer with insufficient balance", async () => {
156
+ test("adds error during coin transfer with insufficient balance", async () => {
168
157
  const mockedAccount = getMockedAccount({ balance: new BigNumber(0) });
169
158
  const mockedTransaction = getMockedTransaction({
170
159
  amount: new BigNumber(100),
@@ -176,7 +165,7 @@ describe("getTransactionStatus", () => {
176
165
  expect(result.errors.amount).toBeInstanceOf(NotEnoughBalance);
177
166
  });
178
167
 
179
- it("adds error if USD balance is too low for token association", async () => {
168
+ test("adds error if USD balance is too low for token association", async () => {
180
169
  const mockedTokenCurrency = getMockedHTSTokenCurrency();
181
170
  const mockedAccount = getMockedAccount({ balance: new BigNumber(0) });
182
171
  const mockedTransaction = getMockedTransaction({
@@ -193,7 +182,7 @@ describe("getTransactionStatus", () => {
193
182
  );
194
183
  });
195
184
 
196
- it("adds warning during token transfer if recipient has no token associated", async () => {
185
+ test("adds warning during token transfer if recipient has no token associated", async () => {
197
186
  jest.spyOn(logicUtils, "checkAccountTokenAssociationStatus").mockResolvedValueOnce(false);
198
187
 
199
188
  const mockedTokenCurrency = getMockedHTSTokenCurrency();
@@ -211,7 +200,7 @@ describe("getTransactionStatus", () => {
211
200
  );
212
201
  });
213
202
 
214
- it("adds evm address verification warning during ERC20 token transfer", async () => {
203
+ test("adds evm address verification warning during ERC20 token transfer", async () => {
215
204
  const mockedTokenCurrency = getMockedERC20TokenCurrency();
216
205
  const mockedTokenAccount = getMockedTokenAccount(mockedTokenCurrency);
217
206
  const mockedAccount = getMockedAccount({ subAccounts: [mockedTokenAccount] });
@@ -227,7 +216,7 @@ describe("getTransactionStatus", () => {
227
216
  );
228
217
  });
229
218
 
230
- it("adds warning if token association status can't be verified", async () => {
219
+ test("adds warning if token association status can't be verified", async () => {
231
220
  jest
232
221
  .spyOn(logicUtils, "checkAccountTokenAssociationStatus")
233
222
  .mockRejectedValueOnce(new HederaRecipientTokenAssociationUnverified());
@@ -247,7 +236,7 @@ describe("getTransactionStatus", () => {
247
236
  );
248
237
  });
249
238
 
250
- it("adds error during token transfer with insufficient balance", async () => {
239
+ test("adds error during token transfer with insufficient balance", async () => {
251
240
  const mockedTokenCurrency = getMockedHTSTokenCurrency();
252
241
  const mockedTokenAccount = getMockedTokenAccount(mockedTokenCurrency, {
253
242
  balance: new BigNumber(0),
@@ -264,7 +253,7 @@ describe("getTransactionStatus", () => {
264
253
  expect(result.errors.amount).toBeInstanceOf(NotEnoughBalance);
265
254
  });
266
255
 
267
- it("adds error if amount is zero and useAllAmount is false", async () => {
256
+ test("adds error if amount is zero and useAllAmount is false", async () => {
268
257
  const mockedAccount = getMockedAccount();
269
258
  const mockedTransaction = getMockedTransaction({
270
259
  recipient: validRecipientAddress,
@@ -276,163 +265,4 @@ describe("getTransactionStatus", () => {
276
265
 
277
266
  expect(result.errors.amount).toBeInstanceOf(AmountRequired);
278
267
  });
279
-
280
- it("delegate transaction with valid node completes successfully", async () => {
281
- const account = getMockedAccount();
282
- const transaction = getMockedTransaction({
283
- mode: HEDERA_TRANSACTION_MODES.Delegate,
284
- properties: { stakingNodeId: 1 },
285
- });
286
-
287
- const result = await getTransactionStatus(account, transaction);
288
-
289
- expect(result.errors).toEqual({});
290
- expect(result.warnings).toEqual({});
291
- expect(result.amount).toEqual(new BigNumber(0));
292
- });
293
-
294
- it("adds error for delegation without staking node id", async () => {
295
- const account = getMockedAccount();
296
- const transaction = getMockedTransaction({
297
- mode: HEDERA_TRANSACTION_MODES.Delegate,
298
- properties: {} as any,
299
- });
300
-
301
- const result = await getTransactionStatus(account, transaction);
302
-
303
- expect(result.errors.missingStakingNodeId).toBeInstanceOf(HederaInvalidStakingNodeIdError);
304
- });
305
-
306
- it("adds error for delegation with invalid staking node id", async () => {
307
- const account = getMockedAccount();
308
- const transaction = getMockedTransaction({
309
- mode: HEDERA_TRANSACTION_MODES.Delegate,
310
- properties: { stakingNodeId: 999 },
311
- });
312
-
313
- const result = await getTransactionStatus(account, transaction);
314
-
315
- expect(result.errors.stakingNodeId).toBeInstanceOf(HederaInvalidStakingNodeIdError);
316
- });
317
-
318
- it("adds error for delegation to already delegated node", async () => {
319
- const account = getMockedAccount({
320
- hederaResources: {
321
- maxAutomaticTokenAssociations: 0,
322
- isAutoTokenAssociationEnabled: false,
323
- delegation: {
324
- nodeId: 1,
325
- pendingReward: new BigNumber(0),
326
- delegated: new BigNumber(1000),
327
- },
328
- },
329
- });
330
- const transaction = getMockedTransaction({
331
- mode: HEDERA_TRANSACTION_MODES.Delegate,
332
- properties: { stakingNodeId: 1 },
333
- });
334
-
335
- const result = await getTransactionStatus(account, transaction);
336
-
337
- expect(result.errors.stakingNodeId).toBeInstanceOf(HederaRedundantStakingNodeIdError);
338
- });
339
-
340
- it("adds error during staking transfer with insufficient balance", async () => {
341
- const mockedAccount = getMockedAccount({ balance: new BigNumber(0) });
342
- const mockedDelegateTransaction = getMockedTransaction({
343
- mode: HEDERA_TRANSACTION_MODES.Delegate,
344
- properties: { stakingNodeId: 1 },
345
- });
346
- const mockedUndelegateTransaction = getMockedTransaction({
347
- mode: HEDERA_TRANSACTION_MODES.Undelegate,
348
- properties: { stakingNodeId: null },
349
- });
350
- const mockedRedelegateTransaction = getMockedTransaction({
351
- mode: HEDERA_TRANSACTION_MODES.Redelegate,
352
- properties: { stakingNodeId: 2 },
353
- });
354
- const mockedClaimRewardsTransaction = getMockedTransaction({
355
- mode: HEDERA_TRANSACTION_MODES.ClaimRewards,
356
- });
357
-
358
- const [resultDelegate, resultUndelegate, resultRedelegate, resultClaimRewards] =
359
- await Promise.all([
360
- getTransactionStatus(mockedAccount, mockedDelegateTransaction),
361
- getTransactionStatus(mockedAccount, mockedUndelegateTransaction),
362
- getTransactionStatus(mockedAccount, mockedRedelegateTransaction),
363
- getTransactionStatus(mockedAccount, mockedClaimRewardsTransaction),
364
- ]);
365
-
366
- expect(resultDelegate.errors.fee).toBeInstanceOf(NotEnoughBalance);
367
- expect(resultUndelegate.errors.fee).toBeInstanceOf(NotEnoughBalance);
368
- expect(resultRedelegate.errors.fee).toBeInstanceOf(NotEnoughBalance);
369
- expect(resultClaimRewards.errors.fee).toBeInstanceOf(NotEnoughBalance);
370
- });
371
-
372
- it("adds error when claiming rewards with no rewards available", async () => {
373
- const account = getMockedAccount({
374
- hederaResources: {
375
- maxAutomaticTokenAssociations: 0,
376
- isAutoTokenAssociationEnabled: false,
377
- delegation: {
378
- nodeId: 1,
379
- pendingReward: new BigNumber(0),
380
- delegated: new BigNumber(1000),
381
- },
382
- },
383
- });
384
- const transaction = getMockedTransaction({
385
- mode: HEDERA_TRANSACTION_MODES.ClaimRewards,
386
- });
387
-
388
- const result = await getTransactionStatus(account, transaction);
389
-
390
- expect(result.errors.noRewardsToClaim).toBeInstanceOf(HederaNoStakingRewardsError);
391
- });
392
-
393
- it("adds warning when claiming rewards with fee higher than rewards", async () => {
394
- const account = getMockedAccount({
395
- hederaResources: {
396
- maxAutomaticTokenAssociations: 0,
397
- isAutoTokenAssociationEnabled: false,
398
- delegation: {
399
- nodeId: 1,
400
- pendingReward: new BigNumber(10),
401
- delegated: new BigNumber(1000),
402
- },
403
- },
404
- });
405
- const transaction = getMockedTransaction({
406
- mode: HEDERA_TRANSACTION_MODES.ClaimRewards,
407
- maxFee: new BigNumber(100),
408
- });
409
-
410
- const result = await getTransactionStatus(account, transaction);
411
-
412
- expect(result.warnings.claimRewardsFee).toBeInstanceOf(ClaimRewardsFeesWarning);
413
- });
414
-
415
- it("claim rewards with sufficient rewards completes successfully", async () => {
416
- const account = getMockedAccount({
417
- hederaResources: {
418
- maxAutomaticTokenAssociations: 0,
419
- isAutoTokenAssociationEnabled: false,
420
- delegation: {
421
- nodeId: 1,
422
- pendingReward: new BigNumber(100),
423
- delegated: new BigNumber(1000),
424
- },
425
- },
426
- });
427
- const transaction = getMockedTransaction({
428
- mode: HEDERA_TRANSACTION_MODES.ClaimRewards,
429
- maxFee: new BigNumber(10),
430
- });
431
-
432
- const result = await getTransactionStatus(account, transaction);
433
-
434
- expect(result.errors).toEqual({});
435
- expect(result.warnings).toEqual({});
436
- expect(result.amount).toEqual(new BigNumber(0));
437
- });
438
268
  });
@@ -1,11 +1,9 @@
1
1
  import BigNumber from "bignumber.js";
2
- import invariant from "invariant";
3
2
  import {
4
3
  AmountRequired,
5
4
  NotEnoughBalance,
6
5
  InvalidAddressBecauseDestinationIsAlsoSource,
7
6
  RecipientRequired,
8
- ClaimRewardsFeesWarning,
9
7
  } from "@ledgerhq/errors";
10
8
  import type { Account, AccountBridge, TokenAccount } from "@ledgerhq/types-live";
11
9
  import { findSubAccountById } from "@ledgerhq/coin-framework/account";
@@ -16,9 +14,6 @@ import {
16
14
  HederaRecipientTokenAssociationRequired,
17
15
  HederaRecipientTokenAssociationUnverified,
18
16
  HederaRecipientEvmAddressVerificationRequired,
19
- HederaInvalidStakingNodeIdError,
20
- HederaRedundantStakingNodeIdError,
21
- HederaNoStakingRewardsError,
22
17
  } from "../errors";
23
18
  import { estimateFees } from "../logic/estimateFees";
24
19
  import {
@@ -27,15 +22,8 @@ import {
27
22
  getCurrencyToUSDRate,
28
23
  checkAccountTokenAssociationStatus,
29
24
  safeParseAccountId,
30
- isStakingTransaction,
31
25
  } from "../logic/utils";
32
- import { getCurrentHederaPreloadData } from "../preload-data";
33
- import type {
34
- HederaAccount,
35
- Transaction,
36
- TransactionStatus,
37
- TransactionTokenAssociate,
38
- } from "../types";
26
+ import type { Transaction, TransactionStatus, TransactionTokenAssociate } from "../types";
39
27
  import { calculateAmount } from "./utils";
40
28
 
41
29
  type Errors = Record<string, Error>;
@@ -253,66 +241,6 @@ async function handleCoinTransaction(
253
241
  };
254
242
  }
255
243
 
256
- async function handleStakingTransaction(account: HederaAccount, transaction: Transaction) {
257
- invariant(isStakingTransaction(transaction), "invalid transaction properties");
258
-
259
- const errors: Record<string, Error> = {};
260
- const warnings: Record<string, Error> = {};
261
- const { validators } = getCurrentHederaPreloadData(account.currency);
262
- const estimatedFees = await estimateFees({
263
- operationType: HEDERA_OPERATION_TYPES.CryptoUpdate,
264
- currency: account.currency,
265
- });
266
- const amount = BigNumber(0);
267
- const totalSpent = amount.plus(estimatedFees.tinybars);
268
-
269
- if (
270
- transaction.mode === HEDERA_TRANSACTION_MODES.Delegate ||
271
- transaction.mode === HEDERA_TRANSACTION_MODES.Redelegate
272
- ) {
273
- if (typeof transaction.properties?.stakingNodeId === "number") {
274
- const isValid = validators.some(validator => {
275
- return validator.nodeId === transaction.properties?.stakingNodeId;
276
- });
277
-
278
- if (!isValid) {
279
- errors.stakingNodeId = new HederaInvalidStakingNodeIdError();
280
- }
281
- } else {
282
- errors.missingStakingNodeId = new HederaInvalidStakingNodeIdError("Validator must be set");
283
- }
284
-
285
- if (account.hederaResources?.delegation?.nodeId === transaction.properties?.stakingNodeId) {
286
- errors.stakingNodeId = new HederaRedundantStakingNodeIdError();
287
- }
288
- }
289
-
290
- if (transaction.mode === HEDERA_TRANSACTION_MODES.ClaimRewards) {
291
- const rewardsToClaim = account.hederaResources?.delegation?.pendingReward || new BigNumber(0);
292
- const transactionFee = transaction.maxFee ?? new BigNumber(0);
293
-
294
- if (rewardsToClaim.lte(0)) {
295
- errors.noRewardsToClaim = new HederaNoStakingRewardsError();
296
- }
297
-
298
- if (transactionFee.gt(rewardsToClaim)) {
299
- warnings.claimRewardsFee = new ClaimRewardsFeesWarning();
300
- }
301
- }
302
-
303
- if (account.balance.isLessThan(totalSpent)) {
304
- errors.fee = new NotEnoughBalance("");
305
- }
306
-
307
- return {
308
- amount: new BigNumber(0),
309
- estimatedFees: estimatedFees.tinybars,
310
- totalSpent,
311
- errors,
312
- warnings,
313
- };
314
- }
315
-
316
244
  export const getTransactionStatus: AccountBridge<
317
245
  Transaction,
318
246
  Account,
@@ -330,8 +258,6 @@ export const getTransactionStatus: AccountBridge<
330
258
  return handleHTSTokenTransaction(account, subAccount, transaction);
331
259
  } else if (isERC20TokenTransaction) {
332
260
  return handleERC20TokenTransaction(account, subAccount, transaction);
333
- } else if (isStakingTransaction(transaction)) {
334
- return handleStakingTransaction(account, transaction);
335
261
  } else {
336
262
  return handleCoinTransaction(account, transaction);
337
263
  }
@@ -13,7 +13,6 @@ import { estimateMaxSpendable } from "./estimateMaxSpendable";
13
13
  import { getTransactionStatus } from "./getTransactionStatus";
14
14
  import { prepareTransaction } from "./prepareTransaction";
15
15
  import { receive } from "./receive";
16
- import { getPreloadStrategy, hydrate, preload } from "../preload";
17
16
  import { buildSignOperation } from "./signOperation";
18
17
  import { getAccountShape, buildIterateResult, postSync } from "./synchronisation";
19
18
  import { assignFromAccountRaw, assignToAccountRaw } from "./serialization";
@@ -30,9 +29,8 @@ function buildCurrencyBridge(signerContext: SignerContext<HederaSigner>): Curren
30
29
  });
31
30
 
32
31
  return {
33
- preload,
34
- hydrate,
35
- getPreloadStrategy,
32
+ preload: () => Promise.resolve({}),
33
+ hydrate: () => {},
36
34
  scanAccounts,
37
35
  };
38
36
  }
@@ -1,136 +1,32 @@
1
1
  import BigNumber from "bignumber.js";
2
2
  import { estimateFees } from "../logic/estimateFees";
3
3
  import { prepareTransaction } from "./prepareTransaction";
4
- import { getMockedAccount, getMockedTokenAccount } from "../test/fixtures/account.fixture";
4
+ import { getMockedAccount } from "../test/fixtures/account.fixture";
5
5
  import { getMockedTransaction } from "../test/fixtures/transaction.fixture";
6
6
  import * as utils from "./utils";
7
7
  import type { EstimateFeesResult } from "../types";
8
- import { HEDERA_OPERATION_TYPES, HEDERA_TRANSACTION_MODES } from "../constants";
9
- import {
10
- getMockedERC20TokenCurrency,
11
- getMockedHTSTokenCurrency,
12
- } from "../test/fixtures/currency.fixture";
13
8
 
14
9
  jest.mock("../logic/estimateFees");
15
10
 
16
11
  describe("prepareTransaction", () => {
17
12
  const mockAccount = getMockedAccount();
18
13
  const mockTx = getMockedTransaction();
19
- const mockFeeEstimation: EstimateFeesResult = {
20
- tinybars: new BigNumber(10),
21
- gas: new BigNumber(5),
22
- };
23
- const mockCalculatedAmount = {
24
- amount: new BigNumber(100),
25
- totalSpent: new BigNumber(100),
26
- };
14
+ const mockFeeEstimation: EstimateFeesResult = { tinybars: new BigNumber(10) };
27
15
 
28
16
  beforeEach(() => {
29
17
  jest.clearAllMocks();
30
18
 
31
19
  (estimateFees as jest.Mock).mockResolvedValue(mockFeeEstimation);
32
- jest.spyOn(utils, "calculateAmount").mockResolvedValue(mockCalculatedAmount);
20
+ jest
21
+ .spyOn(utils, "calculateAmount")
22
+ .mockResolvedValue(
23
+ Promise.resolve({ amount: new BigNumber(100), totalSpent: new BigNumber(100) }),
24
+ );
33
25
  });
34
26
 
35
- it("should set amount and maxFee from utils", async () => {
27
+ test("should set amount and maxFee from utils", async () => {
36
28
  const result = await prepareTransaction(mockAccount, mockTx);
37
-
38
29
  expect(result.amount).toStrictEqual(new BigNumber(100));
39
30
  expect(result.maxFee).toStrictEqual(new BigNumber(10));
40
31
  });
41
-
42
- it("should build ContractCall estimation params with txIntent", async () => {
43
- const mockTokenERC20 = getMockedERC20TokenCurrency();
44
- const tokenAccount = getMockedTokenAccount(mockTokenERC20);
45
- const accountWithToken = getMockedAccount({ subAccounts: [tokenAccount] });
46
- const transaction = getMockedTransaction({
47
- mode: HEDERA_TRANSACTION_MODES.Send,
48
- subAccountId: tokenAccount.id,
49
- amount: new BigNumber(5000),
50
- recipient: "0.0.9999",
51
- });
52
-
53
- await prepareTransaction(accountWithToken, transaction);
54
-
55
- expect(estimateFees).toHaveBeenCalledWith({
56
- operationType: HEDERA_OPERATION_TYPES.ContractCall,
57
- txIntent: {
58
- intentType: "transaction",
59
- type: HEDERA_TRANSACTION_MODES.Send,
60
- asset: {
61
- type: mockTokenERC20.tokenType,
62
- assetReference: mockTokenERC20.contractAddress,
63
- assetOwner: accountWithToken.freshAddress,
64
- },
65
- amount: BigInt(5000),
66
- sender: accountWithToken.freshAddress,
67
- recipient: transaction.recipient,
68
- },
69
- });
70
- });
71
-
72
- it("should set gasLimit for ERC20 transactions when gas is estimated", async () => {
73
- const mockTokenERC20 = getMockedERC20TokenCurrency();
74
- const tokenAccount = getMockedTokenAccount(mockTokenERC20);
75
- const accountWithToken = getMockedAccount({ subAccounts: [tokenAccount] });
76
- const transaction = getMockedTransaction({
77
- mode: HEDERA_TRANSACTION_MODES.Send,
78
- subAccountId: tokenAccount.id,
79
- });
80
-
81
- const result = await prepareTransaction(accountWithToken, transaction);
82
-
83
- expect(result).toMatchObject({
84
- gasLimit: mockFeeEstimation.gas,
85
- });
86
- });
87
-
88
- it("should use TokenTransfer operation type for HTS tokens", async () => {
89
- const mockTokenHTS = getMockedHTSTokenCurrency();
90
- const tokenAccount = getMockedTokenAccount(mockTokenHTS);
91
- const accountWithToken = getMockedAccount({ subAccounts: [tokenAccount] });
92
- const transaction = getMockedTransaction({
93
- mode: HEDERA_TRANSACTION_MODES.Send,
94
- subAccountId: tokenAccount.id,
95
- });
96
-
97
- await prepareTransaction(accountWithToken, transaction);
98
-
99
- expect(estimateFees).toHaveBeenCalledWith({
100
- currency: accountWithToken.currency,
101
- operationType: HEDERA_OPERATION_TYPES.TokenTransfer,
102
- });
103
- });
104
-
105
- it("should use TokenAssociate operation type", async () => {
106
- const mockTokenHTS = getMockedHTSTokenCurrency();
107
- const transaction = getMockedTransaction({
108
- mode: HEDERA_TRANSACTION_MODES.TokenAssociate,
109
- properties: {
110
- token: mockTokenHTS,
111
- },
112
- });
113
-
114
- await prepareTransaction(mockAccount, transaction);
115
-
116
- expect(estimateFees).toHaveBeenCalledWith({
117
- currency: mockAccount.currency,
118
- operationType: HEDERA_OPERATION_TYPES.TokenAssociate,
119
- });
120
- });
121
-
122
- it("should use CryptoTransfer operation type for native transfers", async () => {
123
- const transaction = getMockedTransaction({
124
- mode: HEDERA_TRANSACTION_MODES.Send,
125
- amount: new BigNumber(1000000),
126
- recipient: "0.0.12345",
127
- });
128
-
129
- await prepareTransaction(mockAccount, transaction);
130
-
131
- expect(estimateFees).toHaveBeenCalledWith({
132
- currency: mockAccount.currency,
133
- operationType: HEDERA_OPERATION_TYPES.CryptoTransfer,
134
- });
135
- });
136
32
  });
@@ -1,14 +1,8 @@
1
- import BigNumber from "bignumber.js";
2
1
  import { findSubAccountById } from "@ledgerhq/coin-framework/account/helpers";
3
- import { getEnv } from "@ledgerhq/live-env";
4
2
  import type { AccountBridge } from "@ledgerhq/types-live";
5
- import {
6
- HEDERA_OPERATION_TYPES,
7
- HEDERA_TRANSACTION_MODES,
8
- MAP_STAKING_MODE_TO_MEMO,
9
- } from "../constants";
3
+ import { HEDERA_OPERATION_TYPES, HEDERA_TRANSACTION_MODES } from "../constants";
10
4
  import { estimateFees } from "../logic/estimateFees";
11
- import { isTokenAssociateTransaction, isStakingTransaction } from "../logic/utils";
5
+ import { isTokenAssociateTransaction } from "../logic/utils";
12
6
  import type { EstimateFeesParams, Transaction } from "../types";
13
7
  import { calculateAmount } from "./utils";
14
8
 
@@ -38,8 +32,6 @@ export const prepareTransaction: AccountBridge<Transaction>["prepareTransaction"
38
32
  operationType = HEDERA_OPERATION_TYPES.TokenTransfer;
39
33
  } else if (isERC20TokenTransaction) {
40
34
  operationType = HEDERA_OPERATION_TYPES.ContractCall;
41
- } else if (isStakingTransaction(transaction)) {
42
- operationType = HEDERA_OPERATION_TYPES.CryptoUpdate;
43
35
  } else {
44
36
  operationType = HEDERA_OPERATION_TYPES.CryptoTransfer;
45
37
  }
@@ -87,15 +79,5 @@ export const prepareTransaction: AccountBridge<Transaction>["prepareTransaction"
87
79
  transaction.gasLimit = estimatedFees.gas;
88
80
  }
89
81
 
90
- if (isStakingTransaction(transaction)) {
91
- transaction.memo = MAP_STAKING_MODE_TO_MEMO[transaction.mode];
92
-
93
- // claiming staking rewards is triggered by sending 1 tinybar to staking reward account
94
- if (transaction.mode === HEDERA_TRANSACTION_MODES.ClaimRewards) {
95
- transaction.recipient = getEnv("HEDERA_CLAIM_REWARDS_RECIPIENT_ACCOUNT_ID");
96
- transaction.amount = new BigNumber(1);
97
- }
98
- }
99
-
100
82
  return transaction;
101
83
  };