@ledgerhq/coin-hedera 1.15.0-nightly.20251126023856 → 1.15.0-nightly.20251126160702

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 (280) hide show
  1. package/CHANGELOG.md +10 -8
  2. package/lib/api/index.d.ts.map +1 -1
  3. package/lib/api/index.js +6 -2
  4. package/lib/api/index.js.map +1 -1
  5. package/lib/bridge/broadcast.js +1 -1
  6. package/lib/bridge/broadcast.js.map +1 -1
  7. package/lib/bridge/buildOptimisticOperation.d.ts.map +1 -1
  8. package/lib/bridge/buildOptimisticOperation.js +80 -15
  9. package/lib/bridge/buildOptimisticOperation.js.map +1 -1
  10. package/lib/bridge/estimateMaxSpendable.js +5 -2
  11. package/lib/bridge/estimateMaxSpendable.js.map +1 -1
  12. package/lib/bridge/getTransactionStatus.d.ts.map +1 -1
  13. package/lib/bridge/getTransactionStatus.js +70 -13
  14. package/lib/bridge/getTransactionStatus.js.map +1 -1
  15. package/lib/bridge/index.js +1 -1
  16. package/lib/bridge/index.js.map +1 -1
  17. package/lib/bridge/prepareTransaction.d.ts.map +1 -1
  18. package/lib/bridge/prepareTransaction.js +40 -7
  19. package/lib/bridge/prepareTransaction.js.map +1 -1
  20. package/lib/bridge/signOperation.d.ts.map +1 -1
  21. package/lib/bridge/signOperation.js +19 -2
  22. package/lib/bridge/signOperation.js.map +1 -1
  23. package/lib/bridge/synchronisation.d.ts +2 -0
  24. package/lib/bridge/synchronisation.d.ts.map +1 -1
  25. package/lib/bridge/synchronisation.js +101 -30
  26. package/lib/bridge/synchronisation.js.map +1 -1
  27. package/lib/bridge/utils.d.ts +35 -2
  28. package/lib/bridge/utils.d.ts.map +1 -1
  29. package/lib/bridge/utils.js +215 -16
  30. package/lib/bridge/utils.js.map +1 -1
  31. package/lib/constants.d.ts +22 -2
  32. package/lib/constants.d.ts.map +1 -1
  33. package/lib/constants.js +42 -2
  34. package/lib/constants.js.map +1 -1
  35. package/lib/deviceTransactionConfig.d.ts +1 -1
  36. package/lib/deviceTransactionConfig.d.ts.map +1 -1
  37. package/lib/deviceTransactionConfig.js +8 -0
  38. package/lib/deviceTransactionConfig.js.map +1 -1
  39. package/lib/errors.d.ts +3 -0
  40. package/lib/errors.d.ts.map +1 -1
  41. package/lib/errors.js +2 -1
  42. package/lib/errors.js.map +1 -1
  43. package/lib/logic/craftTransaction.d.ts +4 -4
  44. package/lib/logic/craftTransaction.d.ts.map +1 -1
  45. package/lib/logic/craftTransaction.js +46 -5
  46. package/lib/logic/craftTransaction.js.map +1 -1
  47. package/lib/logic/estimateFees.d.ts +2 -4
  48. package/lib/logic/estimateFees.d.ts.map +1 -1
  49. package/lib/logic/estimateFees.js +45 -5
  50. package/lib/logic/estimateFees.js.map +1 -1
  51. package/lib/logic/listOperations.d.ts.map +1 -1
  52. package/lib/logic/listOperations.js +7 -3
  53. package/lib/logic/listOperations.js.map +1 -1
  54. package/lib/logic/utils.d.ts +24 -2
  55. package/lib/logic/utils.d.ts.map +1 -1
  56. package/lib/logic/utils.js +66 -13
  57. package/lib/logic/utils.js.map +1 -1
  58. package/lib/network/api.d.ts +12 -1
  59. package/lib/network/api.d.ts.map +1 -1
  60. package/lib/network/api.js +91 -19
  61. package/lib/network/api.js.map +1 -1
  62. package/lib/network/rpc.d.ts.map +1 -1
  63. package/lib/network/rpc.js +1 -0
  64. package/lib/network/rpc.js.map +1 -1
  65. package/lib/network/thirdweb.d.ts +21 -0
  66. package/lib/network/thirdweb.d.ts.map +1 -0
  67. package/lib/network/thirdweb.js +72 -0
  68. package/lib/network/thirdweb.js.map +1 -0
  69. package/lib/network/utils.d.ts +4 -1
  70. package/lib/network/utils.d.ts.map +1 -1
  71. package/lib/network/utils.js +53 -1
  72. package/lib/network/utils.js.map +1 -1
  73. package/lib/test/bridgeDatasetTest.d.ts.map +1 -1
  74. package/lib/test/bridgeDatasetTest.js +4 -4
  75. package/lib/test/bridgeDatasetTest.js.map +1 -1
  76. package/lib/test/fixtures/account.fixture.js +1 -1
  77. package/lib/test/fixtures/account.fixture.js.map +1 -1
  78. package/lib/test/fixtures/common.fixture.d.ts +12 -0
  79. package/lib/test/fixtures/common.fixture.d.ts.map +1 -0
  80. package/lib/test/fixtures/common.fixture.js +66 -0
  81. package/lib/test/fixtures/common.fixture.js.map +1 -0
  82. package/lib/test/fixtures/currency.fixture.d.ts +3 -1
  83. package/lib/test/fixtures/currency.fixture.d.ts.map +1 -1
  84. package/lib/test/fixtures/currency.fixture.js +63 -16
  85. package/lib/test/fixtures/currency.fixture.js.map +1 -1
  86. package/lib/test/fixtures/mirror.fixture.d.ts +3 -1
  87. package/lib/test/fixtures/mirror.fixture.d.ts.map +1 -1
  88. package/lib/test/fixtures/mirror.fixture.js +12 -1
  89. package/lib/test/fixtures/mirror.fixture.js.map +1 -1
  90. package/lib/test/fixtures/thirdweb.fixture.d.ts +3 -0
  91. package/lib/test/fixtures/thirdweb.fixture.d.ts.map +1 -0
  92. package/lib/test/fixtures/thirdweb.fixture.js +34 -0
  93. package/lib/test/fixtures/thirdweb.fixture.js.map +1 -0
  94. package/lib/transaction.d.ts.map +1 -1
  95. package/lib/transaction.js +2 -0
  96. package/lib/transaction.js.map +1 -1
  97. package/lib/types/alpaca.d.ts +5 -1
  98. package/lib/types/alpaca.d.ts.map +1 -1
  99. package/lib/types/bridge.d.ts +6 -1
  100. package/lib/types/bridge.d.ts.map +1 -1
  101. package/lib/types/index.d.ts +2 -0
  102. package/lib/types/index.d.ts.map +1 -1
  103. package/lib/types/index.js +2 -0
  104. package/lib/types/index.js.map +1 -1
  105. package/lib/types/logic.d.ts +39 -0
  106. package/lib/types/logic.d.ts.map +1 -0
  107. package/lib/types/logic.js +3 -0
  108. package/lib/types/logic.js.map +1 -0
  109. package/lib/types/mirror.d.ts +29 -0
  110. package/lib/types/mirror.d.ts.map +1 -1
  111. package/lib/types/thirdweb.d.ts +34 -0
  112. package/lib/types/thirdweb.d.ts.map +1 -0
  113. package/lib/types/thirdweb.js +3 -0
  114. package/lib/types/thirdweb.js.map +1 -0
  115. package/lib-es/api/index.d.ts.map +1 -1
  116. package/lib-es/api/index.js +7 -3
  117. package/lib-es/api/index.js.map +1 -1
  118. package/lib-es/bridge/broadcast.js +2 -2
  119. package/lib-es/bridge/broadcast.js.map +1 -1
  120. package/lib-es/bridge/buildOptimisticOperation.d.ts.map +1 -1
  121. package/lib-es/bridge/buildOptimisticOperation.js +83 -18
  122. package/lib-es/bridge/buildOptimisticOperation.js.map +1 -1
  123. package/lib-es/bridge/estimateMaxSpendable.js +5 -2
  124. package/lib-es/bridge/estimateMaxSpendable.js.map +1 -1
  125. package/lib-es/bridge/getTransactionStatus.d.ts.map +1 -1
  126. package/lib-es/bridge/getTransactionStatus.js +73 -16
  127. package/lib-es/bridge/getTransactionStatus.js.map +1 -1
  128. package/lib-es/bridge/index.js +2 -2
  129. package/lib-es/bridge/index.js.map +1 -1
  130. package/lib-es/bridge/prepareTransaction.d.ts.map +1 -1
  131. package/lib-es/bridge/prepareTransaction.js +42 -9
  132. package/lib-es/bridge/prepareTransaction.js.map +1 -1
  133. package/lib-es/bridge/signOperation.d.ts.map +1 -1
  134. package/lib-es/bridge/signOperation.js +21 -4
  135. package/lib-es/bridge/signOperation.js.map +1 -1
  136. package/lib-es/bridge/synchronisation.d.ts +2 -0
  137. package/lib-es/bridge/synchronisation.d.ts.map +1 -1
  138. package/lib-es/bridge/synchronisation.js +97 -27
  139. package/lib-es/bridge/synchronisation.js.map +1 -1
  140. package/lib-es/bridge/utils.d.ts +35 -2
  141. package/lib-es/bridge/utils.d.ts.map +1 -1
  142. package/lib-es/bridge/utils.js +211 -16
  143. package/lib-es/bridge/utils.js.map +1 -1
  144. package/lib-es/constants.d.ts +22 -2
  145. package/lib-es/constants.d.ts.map +1 -1
  146. package/lib-es/constants.js +38 -1
  147. package/lib-es/constants.js.map +1 -1
  148. package/lib-es/deviceTransactionConfig.d.ts +1 -1
  149. package/lib-es/deviceTransactionConfig.d.ts.map +1 -1
  150. package/lib-es/deviceTransactionConfig.js +8 -0
  151. package/lib-es/deviceTransactionConfig.js.map +1 -1
  152. package/lib-es/errors.d.ts +3 -0
  153. package/lib-es/errors.d.ts.map +1 -1
  154. package/lib-es/errors.js +1 -0
  155. package/lib-es/errors.js.map +1 -1
  156. package/lib-es/logic/craftTransaction.d.ts +4 -4
  157. package/lib-es/logic/craftTransaction.d.ts.map +1 -1
  158. package/lib-es/logic/craftTransaction.js +48 -7
  159. package/lib-es/logic/craftTransaction.js.map +1 -1
  160. package/lib-es/logic/estimateFees.d.ts +2 -4
  161. package/lib-es/logic/estimateFees.d.ts.map +1 -1
  162. package/lib-es/logic/estimateFees.js +47 -7
  163. package/lib-es/logic/estimateFees.js.map +1 -1
  164. package/lib-es/logic/listOperations.d.ts.map +1 -1
  165. package/lib-es/logic/listOperations.js +7 -3
  166. package/lib-es/logic/listOperations.js.map +1 -1
  167. package/lib-es/logic/utils.d.ts +24 -2
  168. package/lib-es/logic/utils.d.ts.map +1 -1
  169. package/lib-es/logic/utils.js +63 -13
  170. package/lib-es/logic/utils.js.map +1 -1
  171. package/lib-es/network/api.d.ts +12 -1
  172. package/lib-es/network/api.d.ts.map +1 -1
  173. package/lib-es/network/api.js +91 -19
  174. package/lib-es/network/api.js.map +1 -1
  175. package/lib-es/network/rpc.d.ts.map +1 -1
  176. package/lib-es/network/rpc.js +1 -0
  177. package/lib-es/network/rpc.js.map +1 -1
  178. package/lib-es/network/thirdweb.d.ts +21 -0
  179. package/lib-es/network/thirdweb.d.ts.map +1 -0
  180. package/lib-es/network/thirdweb.js +66 -0
  181. package/lib-es/network/thirdweb.js.map +1 -0
  182. package/lib-es/network/utils.d.ts +4 -1
  183. package/lib-es/network/utils.d.ts.map +1 -1
  184. package/lib-es/network/utils.js +49 -0
  185. package/lib-es/network/utils.js.map +1 -1
  186. package/lib-es/test/bridgeDatasetTest.d.ts.map +1 -1
  187. package/lib-es/test/bridgeDatasetTest.js +4 -4
  188. package/lib-es/test/bridgeDatasetTest.js.map +1 -1
  189. package/lib-es/test/fixtures/account.fixture.js +2 -2
  190. package/lib-es/test/fixtures/account.fixture.js.map +1 -1
  191. package/lib-es/test/fixtures/common.fixture.d.ts +12 -0
  192. package/lib-es/test/fixtures/common.fixture.d.ts.map +1 -0
  193. package/lib-es/test/fixtures/common.fixture.js +57 -0
  194. package/lib-es/test/fixtures/common.fixture.js.map +1 -0
  195. package/lib-es/test/fixtures/currency.fixture.d.ts +3 -1
  196. package/lib-es/test/fixtures/currency.fixture.d.ts.map +1 -1
  197. package/lib-es/test/fixtures/currency.fixture.js +59 -14
  198. package/lib-es/test/fixtures/currency.fixture.js.map +1 -1
  199. package/lib-es/test/fixtures/mirror.fixture.d.ts +3 -1
  200. package/lib-es/test/fixtures/mirror.fixture.d.ts.map +1 -1
  201. package/lib-es/test/fixtures/mirror.fixture.js +9 -0
  202. package/lib-es/test/fixtures/mirror.fixture.js.map +1 -1
  203. package/lib-es/test/fixtures/thirdweb.fixture.d.ts +3 -0
  204. package/lib-es/test/fixtures/thirdweb.fixture.d.ts.map +1 -0
  205. package/lib-es/test/fixtures/thirdweb.fixture.js +30 -0
  206. package/lib-es/test/fixtures/thirdweb.fixture.js.map +1 -0
  207. package/lib-es/transaction.d.ts.map +1 -1
  208. package/lib-es/transaction.js +2 -0
  209. package/lib-es/transaction.js.map +1 -1
  210. package/lib-es/types/alpaca.d.ts +5 -1
  211. package/lib-es/types/alpaca.d.ts.map +1 -1
  212. package/lib-es/types/bridge.d.ts +6 -1
  213. package/lib-es/types/bridge.d.ts.map +1 -1
  214. package/lib-es/types/index.d.ts +2 -0
  215. package/lib-es/types/index.d.ts.map +1 -1
  216. package/lib-es/types/index.js +2 -0
  217. package/lib-es/types/index.js.map +1 -1
  218. package/lib-es/types/logic.d.ts +39 -0
  219. package/lib-es/types/logic.d.ts.map +1 -0
  220. package/lib-es/types/logic.js +2 -0
  221. package/lib-es/types/logic.js.map +1 -0
  222. package/lib-es/types/mirror.d.ts +29 -0
  223. package/lib-es/types/mirror.d.ts.map +1 -1
  224. package/lib-es/types/thirdweb.d.ts +34 -0
  225. package/lib-es/types/thirdweb.d.ts.map +1 -0
  226. package/lib-es/types/thirdweb.js +2 -0
  227. package/lib-es/types/thirdweb.js.map +1 -0
  228. package/package.json +9 -8
  229. package/src/api/index.integ.test.ts +11 -8
  230. package/src/api/index.ts +10 -3
  231. package/src/bridge/broadcast.ts +2 -2
  232. package/src/bridge/buildOptimisticOperation.integration.test.ts +70 -19
  233. package/src/bridge/buildOptimisticOperation.ts +98 -20
  234. package/src/bridge/estimateMaxSpendable.ts +5 -5
  235. package/src/bridge/getTransactionStatus.test.ts +57 -12
  236. package/src/bridge/getTransactionStatus.ts +88 -15
  237. package/src/bridge/index.ts +2 -2
  238. package/src/bridge/js-estimateMaxSpendable.integration.test.ts +12 -9
  239. package/src/bridge/prepareTransaction.test.ts +3 -1
  240. package/src/bridge/prepareTransaction.ts +45 -10
  241. package/src/bridge/signOperation.ts +23 -5
  242. package/src/bridge/synchronisation.test.ts +67 -0
  243. package/src/bridge/synchronisation.ts +114 -34
  244. package/src/bridge/utils.integration.test.ts +486 -180
  245. package/src/bridge/utils.test.ts +404 -0
  246. package/src/bridge/utils.ts +330 -27
  247. package/src/constants.ts +47 -2
  248. package/src/deviceTransactionConfig.ts +10 -1
  249. package/src/errors.ts +3 -0
  250. package/src/logic/craftTransaction.test.ts +49 -9
  251. package/src/logic/craftTransaction.ts +76 -11
  252. package/src/logic/estimateFees.test.ts +180 -31
  253. package/src/logic/estimateFees.ts +68 -7
  254. package/src/logic/getAssetFromToken.test.ts +2 -2
  255. package/src/logic/getBalance.test.ts +18 -57
  256. package/src/logic/getTokenFromAsset.test.ts +2 -2
  257. package/src/logic/listOperations.ts +9 -5
  258. package/src/logic/utils.test.ts +157 -69
  259. package/src/logic/utils.ts +75 -13
  260. package/src/network/api.test.ts +211 -3
  261. package/src/network/api.ts +118 -24
  262. package/src/network/rpc.test.ts +1 -0
  263. package/src/network/rpc.ts +1 -0
  264. package/src/network/thirdweb.test.ts +188 -0
  265. package/src/network/thirdweb.ts +101 -0
  266. package/src/network/utils.test.ts +364 -164
  267. package/src/network/utils.ts +83 -1
  268. package/src/test/bridgeDatasetTest.ts +4 -5
  269. package/src/test/fixtures/account.fixture.ts +2 -2
  270. package/src/test/fixtures/common.fixture.ts +74 -0
  271. package/src/test/fixtures/currency.fixture.ts +66 -14
  272. package/src/test/fixtures/mirror.fixture.ts +23 -1
  273. package/src/test/fixtures/thirdweb.fixture.ts +33 -0
  274. package/src/transaction.ts +2 -0
  275. package/src/types/alpaca.ts +8 -1
  276. package/src/types/bridge.ts +6 -1
  277. package/src/types/index.ts +2 -0
  278. package/src/types/logic.ts +44 -0
  279. package/src/types/mirror.ts +35 -0
  280. package/src/types/thirdweb.ts +36 -0
@@ -1,7 +1,18 @@
1
1
  import BigNumber from "bignumber.js";
2
2
  import { AccountId } from "@hashgraph/sdk";
3
+ import { getCryptoAssetsStore } from "@ledgerhq/cryptoassets/state";
3
4
  import type { Operation, OperationType } from "@ledgerhq/types-live";
4
- import type { HederaMirrorTokenTransfer, HederaMirrorCoinTransfer } from "../types";
5
+ import { apiClient } from "./api";
6
+ import type {
7
+ HederaMirrorTokenTransfer,
8
+ HederaMirrorCoinTransfer,
9
+ HederaThirdwebTransaction,
10
+ HederaThirdwebDecodedTransferParams,
11
+ OperationERC20,
12
+ HederaERC20TokenBalance,
13
+ } from "../types";
14
+ import { TokenCurrency } from "@ledgerhq/types-cryptoassets";
15
+ import { SUPPORTED_ERC20_TOKENS } from "../constants";
5
16
 
6
17
  function isValidRecipient(accountId: AccountId, recipients: string[]): boolean {
7
18
  if (accountId.shard.eq(0) && accountId.realm.eq(0)) {
@@ -56,3 +67,74 @@ export function parseTransfers(
56
67
  recipients,
57
68
  };
58
69
  }
70
+
71
+ export async function getERC20BalancesForAccount(
72
+ evmAccountId: string,
73
+ supportedTokenIds = SUPPORTED_ERC20_TOKENS.map(token => token.id),
74
+ ): Promise<HederaERC20TokenBalance[]> {
75
+ const availableTokens: TokenCurrency[] = [];
76
+
77
+ for (const erc20TokenId of supportedTokenIds) {
78
+ const calToken = await getCryptoAssetsStore().findTokenById(erc20TokenId);
79
+
80
+ if (calToken) {
81
+ availableTokens.push(calToken);
82
+ }
83
+ }
84
+
85
+ const promises = availableTokens.map(async erc20token => {
86
+ const balance = await apiClient.getERC20Balance(evmAccountId, erc20token.contractAddress);
87
+
88
+ return {
89
+ balance,
90
+ token: erc20token,
91
+ };
92
+ });
93
+
94
+ const balances = await Promise.all(promises);
95
+
96
+ return balances;
97
+ }
98
+
99
+ export const getERC20Operations = async (
100
+ latestERC20Transactions: HederaThirdwebTransaction[],
101
+ ): Promise<OperationERC20[]> => {
102
+ const latestERC20Operations: OperationERC20[] = [];
103
+
104
+ for (const thirdwebTransaction of latestERC20Transactions) {
105
+ const tokenId = thirdwebTransaction.address;
106
+ const token = await getCryptoAssetsStore().findTokenByAddressInCurrency(tokenId, "hedera");
107
+
108
+ if (!token) continue;
109
+
110
+ const hash = thirdwebTransaction.transactionHash;
111
+ const contractCallResult = await apiClient.getContractCallResult(hash);
112
+ const mirrorTransaction = await apiClient.findTransactionByContractCall(
113
+ contractCallResult.timestamp,
114
+ contractCallResult.contract_id,
115
+ );
116
+
117
+ if (!mirrorTransaction) continue;
118
+
119
+ latestERC20Operations.push({
120
+ thirdwebTransaction,
121
+ mirrorTransaction,
122
+ contractCallResult,
123
+ token,
124
+ });
125
+ }
126
+
127
+ return latestERC20Operations;
128
+ };
129
+
130
+ export function parseThirdwebTransactionParams(
131
+ transaction: HederaThirdwebTransaction,
132
+ ): HederaThirdwebDecodedTransferParams | null {
133
+ const { from, to, value } = transaction.decoded.params;
134
+
135
+ if (typeof from !== "string" || typeof to !== "string" || typeof value !== "string") {
136
+ return null;
137
+ }
138
+
139
+ return { from, to, value };
140
+ }
@@ -5,7 +5,6 @@ import {
5
5
  InvalidAddressBecauseDestinationIsAlsoSource,
6
6
  AmountRequired,
7
7
  } from "@ledgerhq/errors";
8
-
9
8
  import { HEDERA_TRANSACTION_MODES } from "../constants";
10
9
  import { fromTransactionRaw } from "../transaction";
11
10
  import type { Transaction } from "../types";
@@ -42,10 +41,10 @@ export const hedera: CurrenciesData<Transaction> = {
42
41
  {
43
42
  name: "Recipient and sender must not be the same",
44
43
  transaction: fromTransactionRaw({
44
+ mode: HEDERA_TRANSACTION_MODES.Send,
45
45
  family: "hedera",
46
46
  recipient: "0.0.751515",
47
47
  amount: "100000000",
48
- mode: HEDERA_TRANSACTION_MODES.Send,
49
48
  }),
50
49
  expectedStatus: {
51
50
  errors: {
@@ -57,10 +56,10 @@ export const hedera: CurrenciesData<Transaction> = {
57
56
  {
58
57
  name: "Amount Required",
59
58
  transaction: fromTransactionRaw({
59
+ mode: HEDERA_TRANSACTION_MODES.Send,
60
60
  family: "hedera",
61
61
  recipient: "0.0.751515",
62
62
  amount: "0",
63
- mode: HEDERA_TRANSACTION_MODES.Send,
64
63
  }),
65
64
  expectedStatus: {
66
65
  errors: {
@@ -72,10 +71,10 @@ export const hedera: CurrenciesData<Transaction> = {
72
71
  {
73
72
  name: "Not enough balance",
74
73
  transaction: fromTransactionRaw({
74
+ mode: HEDERA_TRANSACTION_MODES.Send,
75
75
  family: "hedera",
76
76
  recipient: "0.0.751515",
77
77
  amount: "1000000000000000",
78
- mode: HEDERA_TRANSACTION_MODES.Send,
79
78
  }),
80
79
  expectedStatus: {
81
80
  errors: {
@@ -87,10 +86,10 @@ export const hedera: CurrenciesData<Transaction> = {
87
86
  {
88
87
  name: "Send max",
89
88
  transaction: fromTransactionRaw({
89
+ mode: HEDERA_TRANSACTION_MODES.Send,
90
90
  family: "hedera",
91
91
  recipient: "0.0.751515",
92
92
  amount: "1000000000000000",
93
- mode: HEDERA_TRANSACTION_MODES.Send,
94
93
  useAllAmount: true,
95
94
  }),
96
95
  expectedStatus: (account, _, status) => {
@@ -6,11 +6,11 @@ import type {
6
6
  HederaResourcesRaw,
7
7
  } from "../../types";
8
8
  import type { TokenAccount } from "@ledgerhq/types-live";
9
- import { getMockedCurrency, getMockedTokenCurrency } from "./currency.fixture";
9
+ import { getMockedCurrency, getMockedHTSTokenCurrency } from "./currency.fixture";
10
10
  import { TokenCurrency } from "@ledgerhq/types-cryptoassets";
11
11
 
12
12
  const defaultMockedCurrency = getMockedCurrency();
13
- const defaultMockedTokenCurrency = getMockedTokenCurrency();
13
+ const defaultMockedTokenCurrency = getMockedHTSTokenCurrency();
14
14
  const defaultMockAccountId = "js:2:hedera:0.0.1234567:hederaBip44";
15
15
  const defaultMockTokenAccountId = `${defaultMockAccountId}+${defaultMockedTokenCurrency.id}`;
16
16
  const defaultBalance = new BigNumber(100000000);
@@ -0,0 +1,74 @@
1
+ import BigNumber from "bignumber.js";
2
+ import type network from "@ledgerhq/live-network";
3
+ import type { TokenCurrency } from "@ledgerhq/types-cryptoassets";
4
+ import { getMockedThirdwebTransaction } from "./thirdweb.fixture";
5
+ import type { ERC20OperationFields, OperationERC20 } from "../../types";
6
+
7
+ export const getMockResponse = (data: unknown): Awaited<ReturnType<typeof network>> => ({
8
+ data,
9
+ status: 200,
10
+ });
11
+
12
+ export const getMockERC20Operation = ({
13
+ hash,
14
+ from,
15
+ to,
16
+ token,
17
+ }: {
18
+ hash: string;
19
+ from: string;
20
+ to: string;
21
+ token: TokenCurrency;
22
+ }): OperationERC20 => ({
23
+ thirdwebTransaction: getMockedThirdwebTransaction({
24
+ transactionHash: hash,
25
+ blockHash: "0xBLOCK",
26
+ decoded: {
27
+ name: "Transfer",
28
+ signature: "Transfer(address,address,uint256)",
29
+ params: {
30
+ from,
31
+ to,
32
+ value: "1000000",
33
+ },
34
+ },
35
+ }),
36
+ mirrorTransaction: {
37
+ transaction_hash: hash,
38
+ consensus_timestamp: "1234567890.000000000",
39
+ transaction_id: "0.0.123@1234567890.000",
40
+ charged_tx_fee: 100000,
41
+ memo_base64: "",
42
+ } as any,
43
+ contractCallResult: {
44
+ timestamp: "1234567890.000000000",
45
+ contract_id: "0.0.TOKEN",
46
+ gas_consumed: 50000,
47
+ gas_limit: 100000,
48
+ gas_used: 50000,
49
+ } as any,
50
+ token,
51
+ });
52
+
53
+ export const getMockERC20Fields = (
54
+ overrides?: Partial<ERC20OperationFields>,
55
+ ): ERC20OperationFields => ({
56
+ date: new Date("2024-01-15T10:00:00Z"),
57
+ type: "OUT",
58
+ fee: new BigNumber(100000),
59
+ value: new BigNumber(1000000),
60
+ senders: ["0.0.SENDER"],
61
+ recipients: ["0.0.RECIPIENT"],
62
+ blockHeight: 12345,
63
+ blockHash: "0xBLOCK",
64
+ extra: {
65
+ consensusTimestamp: "1234567890.000000000",
66
+ transactionId: "0.0.123@1234567890.000",
67
+ gasConsumed: 50000,
68
+ gasLimit: 100000,
69
+ gasUsed: 50000,
70
+ },
71
+ standard: "erc20",
72
+ hasFailed: false,
73
+ ...overrides,
74
+ });
@@ -32,11 +32,11 @@ export const getMockedCurrency = (overrides?: Partial<CryptoCurrency>): CryptoCu
32
32
  const HARDCODED_HEDERA_TOKENS: TokenCurrency[] = [
33
33
  {
34
34
  type: "TokenCurrency",
35
- id: "hedera/hts/0.0.456858",
35
+ id: "hedera/hts/usd_coin_0.0.456858",
36
36
  contractAddress: "0.0.456858",
37
37
  parentCurrency: getMockedCurrency(),
38
38
  tokenType: "hts",
39
- name: "USDC",
39
+ name: "USD Coin",
40
40
  ticker: "USDC",
41
41
  delisted: false,
42
42
  disableCountervalue: false,
@@ -50,19 +50,37 @@ const HARDCODED_HEDERA_TOKENS: TokenCurrency[] = [
50
50
  },
51
51
  {
52
52
  type: "TokenCurrency",
53
- id: "hedera/hts/0.0.7243470",
53
+ id: "hedera/hts/xpack_0.0.7243470",
54
54
  contractAddress: "0.0.7243470",
55
55
  parentCurrency: getMockedCurrency(),
56
56
  tokenType: "hts",
57
- name: "HBARX",
58
- ticker: "HBARX",
57
+ name: "xPACK",
58
+ ticker: "XPACK",
59
59
  delisted: false,
60
60
  disableCountervalue: false,
61
61
  units: [
62
62
  {
63
- name: "HBARX",
64
- code: "HBARX",
65
- magnitude: 8,
63
+ name: "XPACK",
64
+ code: "XPACK",
65
+ magnitude: 6,
66
+ },
67
+ ],
68
+ },
69
+ {
70
+ type: "TokenCurrency",
71
+ id: "hedera/erc20/audd_0x39ceba2b467fa987546000eb5d1373acf1f3a2e1",
72
+ contractAddress: "0x39ceba2b467fa987546000eb5d1373acf1f3a2e1",
73
+ parentCurrency: getMockedCurrency(),
74
+ tokenType: "erc20",
75
+ name: "AUDD",
76
+ ticker: "AUDD",
77
+ delisted: false,
78
+ disableCountervalue: false,
79
+ units: [
80
+ {
81
+ name: "AUDD",
82
+ code: "AUDD",
83
+ magnitude: 6,
66
84
  },
67
85
  ],
68
86
  },
@@ -85,19 +103,53 @@ export const getTokenCurrencyFromCAL = (
85
103
  };
86
104
  };
87
105
 
88
- export const getMockedTokenCurrency = (overrides?: Partial<TokenCurrency>): TokenCurrency => {
106
+ export const getTokenCurrencyFromCALByType = (
107
+ type: "hts" | "erc20",
108
+ overrides?: Partial<TokenCurrency>,
109
+ ): TokenCurrency => {
110
+ const token = HARDCODED_HEDERA_TOKENS.find(t => t.tokenType === type);
111
+
112
+ invariant(token, `token of type ${type} not found in CAL`);
113
+
89
114
  return {
90
- id: "hedera/hts/test_0.0.1234567",
115
+ ...token,
116
+ ...overrides,
117
+ };
118
+ };
119
+
120
+ export const getMockedHTSTokenCurrency = (overrides?: Partial<TokenCurrency>): TokenCurrency => {
121
+ return {
122
+ id: "hedera/hts/test1_0.0.1234567",
91
123
  contractAddress: "0.0.1001",
92
124
  parentCurrency: getMockedCurrency(),
93
125
  tokenType: "hts",
94
- name: "Test token",
95
- ticker: "TEST",
126
+ name: "Test HTS token",
127
+ ticker: "TEST1",
128
+ type: "TokenCurrency",
129
+ units: [
130
+ {
131
+ name: "Test HTS",
132
+ code: "TEST1",
133
+ magnitude: 8,
134
+ },
135
+ ],
136
+ ...overrides,
137
+ };
138
+ };
139
+
140
+ export const getMockedERC20TokenCurrency = (overrides?: Partial<TokenCurrency>): TokenCurrency => {
141
+ return {
142
+ id: "hedera/erc20/_0x915fe7c00730c08708581e30e27d9c0605be40bd",
143
+ contractAddress: "0x915fe7c00730c08708581e30e27d9c0605be40bd",
144
+ parentCurrency: getMockedCurrency(),
145
+ tokenType: "erc20",
146
+ name: "Test ERC20 token",
147
+ ticker: "TEST2",
96
148
  type: "TokenCurrency",
97
149
  units: [
98
150
  {
99
- name: "Test",
100
- code: "TEST",
151
+ name: "Test ERC20",
152
+ code: "TEST2",
101
153
  magnitude: 8,
102
154
  },
103
155
  ],
@@ -1,4 +1,8 @@
1
- import { HederaMirrorToken } from "../../types";
1
+ import type {
2
+ HederaMirrorCoinTransfer,
3
+ HederaMirrorToken,
4
+ HederaMirrorTokenTransfer,
5
+ } from "../../types";
2
6
 
3
7
  export const getMockedMirrorToken = (overrides?: Partial<HederaMirrorToken>): HederaMirrorToken => {
4
8
  return {
@@ -12,3 +16,21 @@ export const getMockedMirrorToken = (overrides?: Partial<HederaMirrorToken>): He
12
16
  ...overrides,
13
17
  };
14
18
  };
19
+
20
+ export const createMirrorCoinTransfer = (
21
+ account: string,
22
+ amount: number,
23
+ ): HederaMirrorCoinTransfer => ({
24
+ account,
25
+ amount,
26
+ });
27
+
28
+ export const createMirrorTokenTransfer = (
29
+ account: string,
30
+ amount: number,
31
+ tokenId: string,
32
+ ): HederaMirrorTokenTransfer => ({
33
+ token_id: tokenId,
34
+ account,
35
+ amount,
36
+ });
@@ -0,0 +1,33 @@
1
+ import { ERC20_TRANSFER_EVENT_TOPIC } from "../../constants";
2
+ import type { HederaThirdwebTransaction } from "../../types";
3
+
4
+ export const getMockedThirdwebTransaction = (
5
+ overrides?: Partial<HederaThirdwebTransaction>,
6
+ ): HederaThirdwebTransaction => {
7
+ return {
8
+ address: "0x0000000000000000000000000000000000000002",
9
+ blockHash: "0x0000000000000000000000000000000000000002",
10
+ blockNumber: 1,
11
+ blockTimestamp: 1234123,
12
+ chainId: "295",
13
+ data: "0x0000000000000000000000000000000000000002",
14
+ decoded: {
15
+ name: "test",
16
+ params: {
17
+ from: "0x0000000000000000000000000000000000000001",
18
+ to: "0x0000000000000000000000000000000000000002",
19
+ value: "10000",
20
+ },
21
+ signature: "abc",
22
+ },
23
+ logIndex: 1,
24
+ topics: [
25
+ ERC20_TRANSFER_EVENT_TOPIC,
26
+ "0x0000000000000000000000000000000000000001",
27
+ "0x0000000000000000000000000000000000000002",
28
+ ],
29
+ transactionHash: "0x0000000000000000000000000000000000000003",
30
+ transactionIndex: 2,
31
+ ...overrides,
32
+ };
33
+ };
@@ -44,6 +44,7 @@ export function fromTransactionRaw(tr: TransactionRaw): Transaction {
44
44
  ...commonGeneric,
45
45
  ...commonHedera,
46
46
  mode: tr.mode,
47
+ ...(tr.gasLimit && { gasLimit: new BigNumber(tr.gasLimit) }),
47
48
  };
48
49
  }
49
50
 
@@ -70,6 +71,7 @@ export function toTransactionRaw(t: Transaction): TransactionRaw {
70
71
  ...commonGeneric,
71
72
  ...commonHedera,
72
73
  mode: t.mode,
74
+ ...(t.gasLimit && { gasLimit: t.gasLimit.toString() }),
73
75
  };
74
76
  }
75
77
 
@@ -1,3 +1,10 @@
1
- import type { StringMemo } from "@ledgerhq/coin-framework/api/types";
1
+ import type { StringMemo, TxDataNotSupported } from "@ledgerhq/coin-framework/api/types";
2
2
 
3
3
  export type HederaMemo = StringMemo;
4
+
5
+ export type HederaTxData =
6
+ | TxDataNotSupported
7
+ | {
8
+ type: "erc20";
9
+ gasLimit: bigint;
10
+ };
@@ -26,6 +26,7 @@ export type Transaction = TransactionCommon & {
26
26
  } & (
27
27
  | {
28
28
  mode: HEDERA_TRANSACTION_MODES.Send;
29
+ gasLimit?: BigNumber;
29
30
  properties?: never;
30
31
  }
31
32
  | {
@@ -45,6 +46,7 @@ export type TransactionRaw = TransactionCommonRaw & {
45
46
  } & (
46
47
  | {
47
48
  mode: HEDERA_TRANSACTION_MODES.Send;
49
+ gasLimit?: string;
48
50
  properties?: never;
49
51
  }
50
52
  | {
@@ -59,7 +61,7 @@ export type TransactionRaw = TransactionCommonRaw & {
59
61
 
60
62
  export type TransactionTokenAssociate = Extract<
61
63
  Transaction,
62
- { mode: typeof HEDERA_TRANSACTION_MODES.TokenAssociate }
64
+ { mode: HEDERA_TRANSACTION_MODES.TokenAssociate }
63
65
  >;
64
66
 
65
67
  export type TransactionStatus = TransactionStatusCommon;
@@ -89,6 +91,9 @@ export type HederaOperationExtra = {
89
91
  transactionId?: string;
90
92
  associatedTokenId?: string;
91
93
  pagingToken?: string;
94
+ gasConsumed?: number;
95
+ gasLimit?: number;
96
+ gasUsed?: number;
92
97
  memo?: string | null;
93
98
  };
94
99
 
@@ -1,4 +1,6 @@
1
1
  export * from "./alpaca";
2
2
  export * from "./bridge";
3
+ export * from "./logic";
3
4
  export * from "./mirror";
4
5
  export * from "./signer";
6
+ export * from "./thirdweb";
@@ -0,0 +1,44 @@
1
+ import type BigNumber from "bignumber.js";
2
+ import type { TransactionIntent } from "@ledgerhq/coin-framework/api/types";
3
+ import type { CryptoCurrency, TokenCurrency } from "@ledgerhq/types-cryptoassets";
4
+ import type { OperationType } from "@ledgerhq/types-live";
5
+ import type { HederaOperationExtra } from "./bridge";
6
+ import type { HEDERA_OPERATION_TYPES } from "../constants";
7
+ import type { HederaMirrorContractCallResult, HederaMirrorTransaction } from "./mirror";
8
+ import type { HederaThirdwebTransaction } from "./thirdweb";
9
+
10
+ export type EstimateFeesParams =
11
+ | {
12
+ currency: CryptoCurrency;
13
+ operationType: Exclude<HEDERA_OPERATION_TYPES, HEDERA_OPERATION_TYPES.ContractCall>;
14
+ }
15
+ | {
16
+ operationType: typeof HEDERA_OPERATION_TYPES.ContractCall;
17
+ txIntent: TransactionIntent;
18
+ };
19
+
20
+ export interface EstimateFeesResult {
21
+ tinybars: BigNumber;
22
+ gas?: BigNumber;
23
+ }
24
+
25
+ export interface OperationERC20 {
26
+ thirdwebTransaction: HederaThirdwebTransaction;
27
+ mirrorTransaction: HederaMirrorTransaction;
28
+ contractCallResult: HederaMirrorContractCallResult;
29
+ token: TokenCurrency;
30
+ }
31
+
32
+ export interface ERC20OperationFields {
33
+ date: Date;
34
+ type: OperationType;
35
+ fee: BigNumber;
36
+ value: BigNumber;
37
+ senders: string[];
38
+ recipients: string[];
39
+ blockHeight: number;
40
+ blockHash: string;
41
+ extra: HederaOperationExtra;
42
+ standard: "erc20";
43
+ hasFailed: false;
44
+ }
@@ -1,3 +1,6 @@
1
+ import BigNumber from "bignumber.js";
2
+ import type { TokenCurrency } from "@ledgerhq/types-cryptoassets";
3
+
1
4
  type FreezeStatus = "NOT_APPLICABLE" | "FROZEN" | "UNFROZEN";
2
5
 
3
6
  type KycStatus = "NOT_APPLICABLE" | "GRANTED" | "REVOKED";
@@ -19,7 +22,9 @@ export interface HederaMirrorTransaction {
19
22
  token_transfers: HederaMirrorTokenTransfer[];
20
23
  charged_tx_fee: number;
21
24
  transaction_hash: string;
25
+ transaction_id: string;
22
26
  consensus_timestamp: string;
27
+ entity_id: string | null;
23
28
  result: string;
24
29
  name: string;
25
30
  memo_base64?: string;
@@ -68,3 +73,33 @@ export interface HederaMirrorTransactionsResponse {
68
73
  next: string | null;
69
74
  };
70
75
  }
76
+
77
+ export interface HederaMirrorNetworkFees {
78
+ fees: {
79
+ gas: number;
80
+ transaction_type: "ContractCall" | "ContractCreate" | "EthereumTransaction";
81
+ }[];
82
+ timestamp: string;
83
+ }
84
+
85
+ export interface HederaMirrorContractCallResult {
86
+ contract_id: string;
87
+ block_gas_used: number;
88
+ gas_consumed: number;
89
+ gas_limit: number;
90
+ gas_used: number;
91
+ timestamp: string;
92
+ }
93
+
94
+ export interface HederaERC20TokenBalance {
95
+ token: TokenCurrency;
96
+ balance: BigNumber;
97
+ }
98
+
99
+ export interface HederaMirrorContractCallEstimate {
100
+ result: string;
101
+ }
102
+
103
+ export interface HederaMirrorContractCallBalance {
104
+ result: string;
105
+ }
@@ -0,0 +1,36 @@
1
+ export interface HederaThirdwebDecodedTransferParams {
2
+ from: string;
3
+ to: string;
4
+ value: string;
5
+ }
6
+
7
+ export interface HederaThirdwebTransaction {
8
+ address: string;
9
+ blockHash: string;
10
+ blockNumber: number;
11
+ blockTimestamp: number;
12
+ chainId: string;
13
+ data: string;
14
+ decoded: {
15
+ name: string;
16
+ params: Record<string, unknown>;
17
+ signature: string;
18
+ };
19
+ logIndex: number;
20
+ topics: string[];
21
+ transactionHash: string;
22
+ transactionIndex: number;
23
+ }
24
+
25
+ export interface HederaThirdwebPagination {
26
+ limit: number;
27
+ page: number;
28
+ totalCount: number;
29
+ }
30
+
31
+ export interface HederaThirdwebContractEventsResponse {
32
+ result: {
33
+ events: HederaThirdwebTransaction[];
34
+ pagination: HederaThirdwebPagination;
35
+ };
36
+ }