@ledgerhq/coin-hedera 1.13.0-nightly.2 → 1.13.0-nightly.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.turbo/turbo-build.log +1 -1
- package/.unimportedrc.json +1 -1
- package/CHANGELOG.md +14 -0
- package/jest.config.js +1 -1
- package/jest.integ.config.js +8 -0
- package/lib/api/index.d.ts +4 -0
- package/lib/api/index.d.ts.map +1 -0
- package/lib/api/index.js +119 -0
- package/lib/api/index.js.map +1 -0
- package/lib/bridge/broadcast.d.ts +1 -1
- package/lib/bridge/broadcast.d.ts.map +1 -1
- package/lib/bridge/broadcast.js +6 -9
- package/lib/bridge/broadcast.js.map +1 -1
- package/lib/bridge/buildOptimisticOperation.d.ts.map +1 -1
- package/lib/bridge/buildOptimisticOperation.js +14 -11
- package/lib/bridge/buildOptimisticOperation.js.map +1 -1
- package/lib/bridge/createTransaction.d.ts +1 -1
- package/lib/bridge/createTransaction.d.ts.map +1 -1
- package/lib/bridge/createTransaction.js +2 -0
- package/lib/bridge/createTransaction.js.map +1 -1
- package/lib/bridge/estimateMaxSpendable.d.ts.map +1 -1
- package/lib/bridge/estimateMaxSpendable.js +2 -2
- package/lib/bridge/estimateMaxSpendable.js.map +1 -1
- package/lib/bridge/getTransactionStatus.d.ts.map +1 -1
- package/lib/bridge/getTransactionStatus.js +11 -10
- package/lib/bridge/getTransactionStatus.js.map +1 -1
- package/lib/bridge/prepareTransaction.d.ts.map +1 -1
- package/lib/bridge/prepareTransaction.js +6 -5
- package/lib/bridge/prepareTransaction.js.map +1 -1
- package/lib/bridge/signOperation.d.ts +1 -1
- package/lib/bridge/signOperation.d.ts.map +1 -1
- package/lib/bridge/signOperation.js +53 -14
- package/lib/bridge/signOperation.js.map +1 -1
- package/lib/bridge/synchronisation.d.ts.map +1 -1
- package/lib/bridge/synchronisation.js +24 -11
- package/lib/bridge/synchronisation.js.map +1 -1
- package/lib/bridge/utils.d.ts +3 -13
- package/lib/bridge/utils.d.ts.map +1 -1
- package/lib/bridge/utils.js +10 -119
- package/lib/bridge/utils.js.map +1 -1
- package/lib/config.d.ts +8 -0
- package/lib/config.d.ts.map +1 -0
- package/lib/config.js +9 -0
- package/lib/config.js.map +1 -0
- package/lib/constants.d.ts +11 -8
- package/lib/constants.d.ts.map +1 -1
- package/lib/constants.js +17 -13
- package/lib/constants.js.map +1 -1
- package/lib/deviceTransactionConfig.d.ts +1 -1
- package/lib/deviceTransactionConfig.d.ts.map +1 -1
- package/lib/deviceTransactionConfig.js +3 -3
- package/lib/deviceTransactionConfig.js.map +1 -1
- package/lib/logic/broadcast.d.ts +3 -0
- package/lib/logic/broadcast.d.ts.map +1 -0
- package/lib/logic/broadcast.js +11 -0
- package/lib/logic/broadcast.js.map +1 -0
- package/lib/logic/combine.d.ts +2 -0
- package/lib/logic/combine.d.ts.map +1 -0
- package/lib/logic/combine.js +19 -0
- package/lib/logic/combine.js.map +1 -0
- package/lib/logic/craftTransaction.d.ts +8 -0
- package/lib/logic/craftTransaction.d.ts.map +1 -0
- package/lib/logic/craftTransaction.js +107 -0
- package/lib/logic/craftTransaction.js.map +1 -0
- package/lib/logic/estimateFees.d.ts +5 -0
- package/lib/logic/estimateFees.d.ts.map +1 -0
- package/lib/logic/estimateFees.js +25 -0
- package/lib/logic/estimateFees.js.map +1 -0
- package/lib/logic/getAssetFromToken.d.ts +4 -0
- package/lib/logic/getAssetFromToken.d.ts.map +1 -0
- package/lib/logic/getAssetFromToken.js +14 -0
- package/lib/logic/getAssetFromToken.js.map +1 -0
- package/lib/logic/getBalance.d.ts +4 -0
- package/lib/logic/getBalance.d.ts.map +1 -0
- package/lib/logic/getBalance.js +36 -0
- package/lib/logic/getBalance.js.map +1 -0
- package/lib/logic/getTokenFromAsset.d.ts +4 -0
- package/lib/logic/getTokenFromAsset.d.ts.map +1 -0
- package/lib/logic/getTokenFromAsset.js +13 -0
- package/lib/logic/getTokenFromAsset.js.map +1 -0
- package/lib/logic/index.d.ts +10 -0
- package/lib/logic/index.d.ts.map +1 -0
- package/lib/logic/index.js +22 -0
- package/lib/logic/index.js.map +1 -0
- package/lib/logic/lastBlock.d.ts +12 -0
- package/lib/logic/lastBlock.d.ts.map +1 -0
- package/lib/logic/lastBlock.js +25 -0
- package/lib/logic/lastBlock.js.map +1 -0
- package/lib/logic/listOperations.d.ts +19 -0
- package/lib/logic/listOperations.d.ts.map +1 -0
- package/lib/logic/listOperations.js +179 -0
- package/lib/logic/listOperations.js.map +1 -0
- package/lib/logic/utils.d.ts +55 -0
- package/lib/logic/utils.d.ts.map +1 -0
- package/lib/logic/utils.js +197 -0
- package/lib/logic/utils.js.map +1 -0
- package/lib/network/api.d.ts +24 -0
- package/lib/network/api.d.ts.map +1 -0
- package/lib/network/api.js +119 -0
- package/lib/network/api.js.map +1 -0
- package/lib/network/rpc.d.ts +12 -0
- package/lib/network/rpc.d.ts.map +1 -0
- package/lib/network/rpc.js +22 -0
- package/lib/network/rpc.js.map +1 -0
- package/lib/{api → network}/utils.d.ts +1 -5
- package/lib/network/utils.d.ts.map +1 -0
- package/lib/network/utils.js +52 -0
- package/lib/network/utils.js.map +1 -0
- package/lib/test/bridgeDatasetTest.d.ts.map +1 -1
- package/lib/test/bridgeDatasetTest.js +5 -1
- package/lib/test/bridgeDatasetTest.js.map +1 -1
- package/lib/test/fixtures/account.fixture.d.ts +17 -0
- package/lib/test/fixtures/account.fixture.d.ts.map +1 -1
- package/lib/test/fixtures/account.fixture.js +18 -1
- package/lib/test/fixtures/account.fixture.js.map +1 -1
- package/lib/test/fixtures/currency.fixture.d.ts.map +1 -1
- package/lib/test/fixtures/currency.fixture.js +1 -1
- package/lib/test/fixtures/currency.fixture.js.map +1 -1
- package/lib/test/fixtures/mirror.fixture.d.ts +1 -1
- package/lib/test/fixtures/mirror.fixture.d.ts.map +1 -1
- package/lib/test/fixtures/network.fixture.d.ts +3 -0
- package/lib/test/fixtures/network.fixture.d.ts.map +1 -0
- package/lib/test/fixtures/network.fixture.js +9 -0
- package/lib/test/fixtures/network.fixture.js.map +1 -0
- package/lib/test/fixtures/transaction.fixture.d.ts.map +1 -1
- package/lib/test/fixtures/transaction.fixture.js +3 -0
- package/lib/test/fixtures/transaction.fixture.js.map +1 -1
- package/lib/transaction.d.ts +1 -1
- package/lib/transaction.d.ts.map +1 -1
- package/lib/transaction.js +35 -6
- package/lib/transaction.js.map +1 -1
- package/lib/types/alpaca.d.ts +3 -0
- package/lib/types/alpaca.d.ts.map +1 -0
- package/lib/{api/types.js → types/alpaca.js} +1 -1
- package/lib/types/alpaca.js.map +1 -0
- package/lib/types/bridge.d.ts +28 -9
- package/lib/types/bridge.d.ts.map +1 -1
- package/lib/types/index.d.ts +2 -0
- package/lib/types/index.d.ts.map +1 -1
- package/lib/types/index.js +2 -0
- package/lib/types/index.js.map +1 -1
- package/lib/{api/types.d.ts → types/mirror.d.ts} +21 -2
- package/lib/types/mirror.d.ts.map +1 -0
- package/lib/types/mirror.js +3 -0
- package/lib/types/mirror.js.map +1 -0
- package/lib-es/api/index.d.ts +4 -0
- package/lib-es/api/index.d.ts.map +1 -0
- package/lib-es/api/index.js +112 -0
- package/lib-es/api/index.js.map +1 -0
- package/lib-es/bridge/broadcast.d.ts +1 -1
- package/lib-es/bridge/broadcast.d.ts.map +1 -1
- package/lib-es/bridge/broadcast.js +4 -7
- package/lib-es/bridge/broadcast.js.map +1 -1
- package/lib-es/bridge/buildOptimisticOperation.d.ts.map +1 -1
- package/lib-es/bridge/buildOptimisticOperation.js +12 -9
- package/lib-es/bridge/buildOptimisticOperation.js.map +1 -1
- package/lib-es/bridge/createTransaction.d.ts +1 -1
- package/lib-es/bridge/createTransaction.d.ts.map +1 -1
- package/lib-es/bridge/createTransaction.js +2 -0
- package/lib-es/bridge/createTransaction.js.map +1 -1
- package/lib-es/bridge/estimateMaxSpendable.d.ts.map +1 -1
- package/lib-es/bridge/estimateMaxSpendable.js +2 -2
- package/lib-es/bridge/estimateMaxSpendable.js.map +1 -1
- package/lib-es/bridge/getTransactionStatus.d.ts.map +1 -1
- package/lib-es/bridge/getTransactionStatus.js +7 -6
- package/lib-es/bridge/getTransactionStatus.js.map +1 -1
- package/lib-es/bridge/prepareTransaction.d.ts.map +1 -1
- package/lib-es/bridge/prepareTransaction.js +4 -3
- package/lib-es/bridge/prepareTransaction.js.map +1 -1
- package/lib-es/bridge/signOperation.d.ts +1 -1
- package/lib-es/bridge/signOperation.d.ts.map +1 -1
- package/lib-es/bridge/signOperation.js +53 -14
- package/lib-es/bridge/signOperation.js.map +1 -1
- package/lib-es/bridge/synchronisation.d.ts.map +1 -1
- package/lib-es/bridge/synchronisation.js +24 -11
- package/lib-es/bridge/synchronisation.js.map +1 -1
- package/lib-es/bridge/utils.d.ts +3 -13
- package/lib-es/bridge/utils.d.ts.map +1 -1
- package/lib-es/bridge/utils.js +7 -113
- package/lib-es/bridge/utils.js.map +1 -1
- package/lib-es/config.d.ts +8 -0
- package/lib-es/config.d.ts.map +1 -0
- package/lib-es/config.js +4 -0
- package/lib-es/config.js.map +1 -0
- package/lib-es/constants.d.ts +11 -8
- package/lib-es/constants.d.ts.map +1 -1
- package/lib-es/constants.js +13 -9
- package/lib-es/constants.js.map +1 -1
- package/lib-es/deviceTransactionConfig.d.ts +1 -1
- package/lib-es/deviceTransactionConfig.d.ts.map +1 -1
- package/lib-es/deviceTransactionConfig.js +1 -1
- package/lib-es/deviceTransactionConfig.js.map +1 -1
- package/lib-es/logic/broadcast.d.ts +3 -0
- package/lib-es/logic/broadcast.d.ts.map +1 -0
- package/lib-es/logic/broadcast.js +7 -0
- package/lib-es/logic/broadcast.js.map +1 -0
- package/lib-es/logic/combine.d.ts +2 -0
- package/lib-es/logic/combine.d.ts.map +1 -0
- package/lib-es/logic/combine.js +12 -0
- package/lib-es/logic/combine.js.map +1 -0
- package/lib-es/logic/craftTransaction.d.ts +8 -0
- package/lib-es/logic/craftTransaction.d.ts.map +1 -0
- package/lib-es/logic/craftTransaction.js +100 -0
- package/lib-es/logic/craftTransaction.js.map +1 -0
- package/lib-es/logic/estimateFees.d.ts +5 -0
- package/lib-es/logic/estimateFees.d.ts.map +1 -0
- package/lib-es/logic/estimateFees.js +18 -0
- package/lib-es/logic/estimateFees.js.map +1 -0
- package/lib-es/logic/getAssetFromToken.d.ts +4 -0
- package/lib-es/logic/getAssetFromToken.d.ts.map +1 -0
- package/lib-es/logic/getAssetFromToken.js +10 -0
- package/lib-es/logic/getAssetFromToken.js.map +1 -0
- package/lib-es/logic/getBalance.d.ts +4 -0
- package/lib-es/logic/getBalance.d.ts.map +1 -0
- package/lib-es/logic/getBalance.js +32 -0
- package/lib-es/logic/getBalance.js.map +1 -0
- package/lib-es/logic/getTokenFromAsset.d.ts +4 -0
- package/lib-es/logic/getTokenFromAsset.d.ts.map +1 -0
- package/lib-es/logic/getTokenFromAsset.js +9 -0
- package/lib-es/logic/getTokenFromAsset.js.map +1 -0
- package/lib-es/logic/index.d.ts +10 -0
- package/lib-es/logic/index.d.ts.map +1 -0
- package/lib-es/logic/index.js +10 -0
- package/lib-es/logic/index.js.map +1 -0
- package/lib-es/logic/lastBlock.d.ts +12 -0
- package/lib-es/logic/lastBlock.d.ts.map +1 -0
- package/lib-es/logic/lastBlock.js +21 -0
- package/lib-es/logic/lastBlock.js.map +1 -0
- package/lib-es/logic/listOperations.d.ts +19 -0
- package/lib-es/logic/listOperations.d.ts.map +1 -0
- package/lib-es/logic/listOperations.js +172 -0
- package/lib-es/logic/listOperations.js.map +1 -0
- package/lib-es/logic/utils.d.ts +55 -0
- package/lib-es/logic/utils.d.ts.map +1 -0
- package/lib-es/logic/utils.js +174 -0
- package/lib-es/logic/utils.js.map +1 -0
- package/lib-es/network/api.d.ts +24 -0
- package/lib-es/network/api.d.ts.map +1 -0
- package/lib-es/network/api.js +113 -0
- package/lib-es/network/api.js.map +1 -0
- package/lib-es/network/rpc.d.ts +12 -0
- package/lib-es/network/rpc.d.ts.map +1 -0
- package/lib-es/network/rpc.js +19 -0
- package/lib-es/network/rpc.js.map +1 -0
- package/lib-es/{api → network}/utils.d.ts +1 -5
- package/lib-es/network/utils.d.ts.map +1 -0
- package/lib-es/network/utils.js +45 -0
- package/lib-es/network/utils.js.map +1 -0
- package/lib-es/test/bridgeDatasetTest.d.ts.map +1 -1
- package/lib-es/test/bridgeDatasetTest.js +5 -1
- package/lib-es/test/bridgeDatasetTest.js.map +1 -1
- package/lib-es/test/fixtures/account.fixture.d.ts +17 -0
- package/lib-es/test/fixtures/account.fixture.d.ts.map +1 -1
- package/lib-es/test/fixtures/account.fixture.js +17 -0
- package/lib-es/test/fixtures/account.fixture.js.map +1 -1
- package/lib-es/test/fixtures/currency.fixture.d.ts.map +1 -1
- package/lib-es/test/fixtures/currency.fixture.js +1 -1
- package/lib-es/test/fixtures/currency.fixture.js.map +1 -1
- package/lib-es/test/fixtures/mirror.fixture.d.ts +1 -1
- package/lib-es/test/fixtures/mirror.fixture.d.ts.map +1 -1
- package/lib-es/test/fixtures/network.fixture.d.ts +3 -0
- package/lib-es/test/fixtures/network.fixture.d.ts.map +1 -0
- package/lib-es/test/fixtures/network.fixture.js +5 -0
- package/lib-es/test/fixtures/network.fixture.js.map +1 -0
- package/lib-es/test/fixtures/transaction.fixture.d.ts.map +1 -1
- package/lib-es/test/fixtures/transaction.fixture.js +3 -0
- package/lib-es/test/fixtures/transaction.fixture.js.map +1 -1
- package/lib-es/transaction.d.ts +1 -1
- package/lib-es/transaction.d.ts.map +1 -1
- package/lib-es/transaction.js +35 -6
- package/lib-es/transaction.js.map +1 -1
- package/lib-es/types/alpaca.d.ts +3 -0
- package/lib-es/types/alpaca.d.ts.map +1 -0
- package/lib-es/types/alpaca.js +2 -0
- package/lib-es/types/alpaca.js.map +1 -0
- package/lib-es/types/bridge.d.ts +28 -9
- package/lib-es/types/bridge.d.ts.map +1 -1
- package/lib-es/types/index.d.ts +2 -0
- package/lib-es/types/index.d.ts.map +1 -1
- package/lib-es/types/index.js +2 -0
- package/lib-es/types/index.js.map +1 -1
- package/lib-es/{api/types.d.ts → types/mirror.d.ts} +21 -2
- package/lib-es/types/mirror.d.ts.map +1 -0
- package/lib-es/types/mirror.js +2 -0
- package/lib-es/types/mirror.js.map +1 -0
- package/package.json +4 -3
- package/src/api/index.integ.test.ts +401 -0
- package/src/api/index.test.ts +30 -0
- package/src/api/index.ts +149 -0
- package/src/bridge/broadcast.ts +5 -10
- package/src/bridge/buildOptimisticOperation.integration.test.ts +8 -8
- package/src/bridge/buildOptimisticOperation.ts +13 -10
- package/src/bridge/createTransaction.ts +3 -1
- package/src/bridge/estimateMaxSpendable.ts +6 -3
- package/src/bridge/getTransactionStatus.test.ts +11 -10
- package/src/bridge/getTransactionStatus.ts +12 -11
- package/src/bridge/js-estimateMaxSpendable.integration.test.ts +6 -3
- package/src/bridge/prepareTransaction.test.ts +9 -17
- package/src/bridge/prepareTransaction.ts +5 -4
- package/src/bridge/serialization.test.ts +6 -6
- package/src/bridge/signOperation.ts +69 -16
- package/src/bridge/synchronisation.ts +22 -14
- package/src/bridge/utils.integration.test.ts +19 -248
- package/src/bridge/utils.ts +14 -160
- package/src/config.ts +7 -0
- package/src/constants.ts +15 -9
- package/src/deviceTransactionConfig.ts +2 -2
- package/src/logic/broadcast.test.ts +58 -0
- package/src/logic/broadcast.ts +8 -0
- package/src/logic/combine.test.ts +119 -0
- package/src/logic/combine.ts +14 -0
- package/src/logic/craftTransaction.test.ts +215 -0
- package/src/logic/craftTransaction.ts +175 -0
- package/src/logic/estimateFees.test.ts +99 -0
- package/src/logic/estimateFees.ts +28 -0
- package/src/logic/getAssetFromToken.test.ts +27 -0
- package/src/logic/getAssetFromToken.ts +12 -0
- package/src/logic/getBalance.test.ts +200 -0
- package/src/logic/getBalance.ts +39 -0
- package/src/logic/getTokenFromAsset.test.ts +22 -0
- package/src/logic/getTokenFromAsset.ts +17 -0
- package/src/logic/index.ts +9 -0
- package/src/logic/lastBlock.test.ts +23 -0
- package/src/logic/lastBlock.ts +23 -0
- package/src/logic/listOperations.test.ts +388 -0
- package/src/logic/listOperations.ts +247 -0
- package/src/logic/utils.test.ts +432 -0
- package/src/logic/utils.ts +255 -0
- package/src/{api/mirror.test.ts → network/api.test.ts} +81 -35
- package/src/network/api.ts +159 -0
- package/src/network/rpc.test.ts +68 -0
- package/src/network/rpc.ts +25 -0
- package/src/network/utils.test.ts +175 -0
- package/src/network/utils.ts +58 -0
- package/src/test/bridgeDatasetTest.ts +6 -2
- package/src/test/fixtures/account.fixture.ts +18 -0
- package/src/test/fixtures/currency.fixture.ts +1 -1
- package/src/test/fixtures/mirror.fixture.ts +1 -1
- package/src/test/fixtures/network.fixture.ts +6 -0
- package/src/test/fixtures/transaction.fixture.ts +5 -2
- package/src/transaction.ts +40 -9
- package/src/types/alpaca.ts +3 -0
- package/src/types/bridge.ts +36 -10
- package/src/types/index.ts +2 -0
- package/src/{api/types.ts → types/mirror.ts} +23 -1
- package/lib/api/mirror.d.ts +0 -6
- package/lib/api/mirror.d.ts.map +0 -1
- package/lib/api/mirror.js +0 -84
- package/lib/api/mirror.js.map +0 -1
- package/lib/api/network.d.ts +0 -11
- package/lib/api/network.d.ts.map +0 -1
- package/lib/api/network.js +0 -80
- package/lib/api/network.js.map +0 -1
- package/lib/api/types.d.ts.map +0 -1
- package/lib/api/types.js.map +0 -1
- package/lib/api/utils.d.ts.map +0 -1
- package/lib/api/utils.js +0 -132
- package/lib/api/utils.js.map +0 -1
- package/lib/logic.d.ts +0 -11
- package/lib/logic.d.ts.map +0 -1
- package/lib/logic.js +0 -37
- package/lib/logic.js.map +0 -1
- package/lib-es/api/mirror.d.ts +0 -6
- package/lib-es/api/mirror.d.ts.map +0 -1
- package/lib-es/api/mirror.js +0 -74
- package/lib-es/api/mirror.js.map +0 -1
- package/lib-es/api/network.d.ts +0 -11
- package/lib-es/api/network.d.ts.map +0 -1
- package/lib-es/api/network.js +0 -71
- package/lib-es/api/network.js.map +0 -1
- package/lib-es/api/types.d.ts.map +0 -1
- package/lib-es/api/types.js +0 -2
- package/lib-es/api/types.js.map +0 -1
- package/lib-es/api/utils.d.ts.map +0 -1
- package/lib-es/api/utils.js +0 -124
- package/lib-es/api/utils.js.map +0 -1
- package/lib-es/logic.d.ts +0 -11
- package/lib-es/logic.d.ts.map +0 -1
- package/lib-es/logic.js +0 -29
- package/lib-es/logic.js.map +0 -1
- package/src/api/mirror.ts +0 -91
- package/src/api/network.test.ts +0 -49
- package/src/api/network.ts +0 -125
- package/src/api/utils.ts +0 -150
- package/src/logic.test.ts +0 -152
- package/src/logic.ts +0 -66
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import BigNumber from "bignumber.js";
|
|
2
|
+
import type { CryptoCurrency } from "@ledgerhq/types-cryptoassets";
|
|
3
|
+
import {
|
|
4
|
+
BASE_USD_FEE_BY_OPERATION_TYPE,
|
|
5
|
+
DEFAULT_TINYBAR_FEE,
|
|
6
|
+
ESTIMATED_FEE_SAFETY_RATE,
|
|
7
|
+
HEDERA_OPERATION_TYPES,
|
|
8
|
+
} from "../constants";
|
|
9
|
+
import { getCurrencyToUSDRate } from "./utils";
|
|
10
|
+
|
|
11
|
+
export const estimateFees = async (
|
|
12
|
+
currency: CryptoCurrency,
|
|
13
|
+
operationType: HEDERA_OPERATION_TYPES,
|
|
14
|
+
): Promise<BigNumber> => {
|
|
15
|
+
let fee: BigNumber | undefined;
|
|
16
|
+
const usdRate = await getCurrencyToUSDRate(currency).catch(() => null);
|
|
17
|
+
|
|
18
|
+
if (usdRate) {
|
|
19
|
+
fee = new BigNumber(BASE_USD_FEE_BY_OPERATION_TYPE[operationType])
|
|
20
|
+
.dividedBy(new BigNumber(usdRate))
|
|
21
|
+
.integerValue(BigNumber.ROUND_CEIL)
|
|
22
|
+
.multipliedBy(ESTIMATED_FEE_SAFETY_RATE);
|
|
23
|
+
} else {
|
|
24
|
+
fee = new BigNumber(DEFAULT_TINYBAR_FEE).multipliedBy(ESTIMATED_FEE_SAFETY_RATE);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
return fee;
|
|
28
|
+
};
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { getAssetFromToken } from "./getAssetFromToken";
|
|
2
|
+
import { getMockedTokenCurrency } from "../test/fixtures/currency.fixture";
|
|
3
|
+
|
|
4
|
+
describe("getAssetFromToken", () => {
|
|
5
|
+
it("returns asset from TEST token", () => {
|
|
6
|
+
const owner = "owner";
|
|
7
|
+
const token = getMockedTokenCurrency({
|
|
8
|
+
contractAddress: "0.0.1234567",
|
|
9
|
+
name: "TEST",
|
|
10
|
+
units: [
|
|
11
|
+
{
|
|
12
|
+
name: "Test",
|
|
13
|
+
code: "TEST",
|
|
14
|
+
magnitude: 8,
|
|
15
|
+
},
|
|
16
|
+
],
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
expect(getAssetFromToken(token, owner)).toEqual({
|
|
20
|
+
assetReference: token.contractAddress,
|
|
21
|
+
assetOwner: owner,
|
|
22
|
+
name: token.name,
|
|
23
|
+
type: token.tokenType,
|
|
24
|
+
unit: token.units[0],
|
|
25
|
+
});
|
|
26
|
+
});
|
|
27
|
+
});
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { AssetInfo } from "@ledgerhq/coin-framework/api/types";
|
|
2
|
+
import type { TokenCurrency } from "@ledgerhq/types-cryptoassets";
|
|
3
|
+
|
|
4
|
+
export function getAssetFromToken(token: TokenCurrency, owner: string): AssetInfo {
|
|
5
|
+
return {
|
|
6
|
+
type: token.tokenType,
|
|
7
|
+
assetReference: token.contractAddress,
|
|
8
|
+
assetOwner: owner,
|
|
9
|
+
name: token.name,
|
|
10
|
+
unit: token.units[0],
|
|
11
|
+
};
|
|
12
|
+
}
|
|
@@ -0,0 +1,200 @@
|
|
|
1
|
+
import { findTokenByAddressInCurrency } from "@ledgerhq/cryptoassets/tokens";
|
|
2
|
+
import { getBalance } from "./getBalance";
|
|
3
|
+
import { apiClient } from "../network/api";
|
|
4
|
+
import { getMockedCurrency } from "../test/fixtures/currency.fixture";
|
|
5
|
+
|
|
6
|
+
jest.mock("../network/api");
|
|
7
|
+
jest.mock("@ledgerhq/cryptoassets/tokens");
|
|
8
|
+
|
|
9
|
+
describe("getBalance", () => {
|
|
10
|
+
beforeEach(() => {
|
|
11
|
+
jest.clearAllMocks();
|
|
12
|
+
});
|
|
13
|
+
|
|
14
|
+
it("should return native balance when only HBAR is present", async () => {
|
|
15
|
+
const address = "0.0.12345";
|
|
16
|
+
const mockCurrency = getMockedCurrency();
|
|
17
|
+
const mockMirrorAccount = {
|
|
18
|
+
balance: {
|
|
19
|
+
balance: "1000000000",
|
|
20
|
+
},
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
(apiClient.getAccount as jest.Mock).mockResolvedValue(mockMirrorAccount);
|
|
24
|
+
(apiClient.getAccountTokens as jest.Mock).mockResolvedValue([]);
|
|
25
|
+
|
|
26
|
+
const result = await getBalance(mockCurrency, address);
|
|
27
|
+
|
|
28
|
+
expect(apiClient.getAccount).toHaveBeenCalledTimes(1);
|
|
29
|
+
expect(apiClient.getAccount).toHaveBeenCalledWith(address);
|
|
30
|
+
expect(apiClient.getAccountTokens).toHaveBeenCalledTimes(1);
|
|
31
|
+
expect(apiClient.getAccountTokens).toHaveBeenCalledWith(address);
|
|
32
|
+
expect(result).toHaveLength(1);
|
|
33
|
+
expect(result).toEqual([
|
|
34
|
+
{
|
|
35
|
+
asset: { type: "native" },
|
|
36
|
+
value: BigInt("1000000000"),
|
|
37
|
+
},
|
|
38
|
+
]);
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
it("should return native balance and token balances", async () => {
|
|
42
|
+
const address = "0.0.12345";
|
|
43
|
+
const mockCurrency = getMockedCurrency();
|
|
44
|
+
const mockMirrorAccount = {
|
|
45
|
+
balance: {
|
|
46
|
+
balance: "1000000000",
|
|
47
|
+
},
|
|
48
|
+
};
|
|
49
|
+
const mockMirrorTokens = [
|
|
50
|
+
{
|
|
51
|
+
token_id: "0.0.7890",
|
|
52
|
+
balance: "5000",
|
|
53
|
+
},
|
|
54
|
+
{
|
|
55
|
+
token_id: "0.0.9876",
|
|
56
|
+
balance: "10000",
|
|
57
|
+
},
|
|
58
|
+
];
|
|
59
|
+
const mockToken1 = {
|
|
60
|
+
id: "token1",
|
|
61
|
+
contractAddress: "0.0.7890",
|
|
62
|
+
tokenType: "hts",
|
|
63
|
+
name: "Test Token 1",
|
|
64
|
+
units: [{ name: "TT1", code: "tt1", magnitude: 6 }],
|
|
65
|
+
};
|
|
66
|
+
const mockToken2 = {
|
|
67
|
+
id: "token2",
|
|
68
|
+
contractAddress: "0.0.9876",
|
|
69
|
+
tokenType: "hts",
|
|
70
|
+
name: "Test Token 2",
|
|
71
|
+
units: [{ name: "TT2", code: "tt2", magnitude: 8 }],
|
|
72
|
+
};
|
|
73
|
+
|
|
74
|
+
(apiClient.getAccount as jest.Mock).mockResolvedValue(mockMirrorAccount);
|
|
75
|
+
(apiClient.getAccountTokens as jest.Mock).mockResolvedValue(mockMirrorTokens);
|
|
76
|
+
(findTokenByAddressInCurrency as jest.Mock).mockImplementation(tokenId => {
|
|
77
|
+
if (tokenId === "0.0.7890") return mockToken1;
|
|
78
|
+
if (tokenId === "0.0.9876") return mockToken2;
|
|
79
|
+
return null;
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
const result = await getBalance(mockCurrency, address);
|
|
83
|
+
|
|
84
|
+
expect(apiClient.getAccount).toHaveBeenCalledTimes(1);
|
|
85
|
+
expect(apiClient.getAccount).toHaveBeenCalledWith(address);
|
|
86
|
+
expect(apiClient.getAccountTokens).toHaveBeenCalledTimes(1);
|
|
87
|
+
expect(apiClient.getAccountTokens).toHaveBeenCalledWith(address);
|
|
88
|
+
expect(findTokenByAddressInCurrency).toHaveBeenCalledTimes(2);
|
|
89
|
+
expect(findTokenByAddressInCurrency).toHaveBeenCalledWith("0.0.7890", "hedera");
|
|
90
|
+
expect(findTokenByAddressInCurrency).toHaveBeenCalledWith("0.0.9876", "hedera");
|
|
91
|
+
expect(result).toHaveLength(3);
|
|
92
|
+
expect(result).toEqual(
|
|
93
|
+
expect.arrayContaining([
|
|
94
|
+
{
|
|
95
|
+
asset: { type: "native" },
|
|
96
|
+
value: BigInt("1000000000"),
|
|
97
|
+
},
|
|
98
|
+
{
|
|
99
|
+
value: BigInt("5000"),
|
|
100
|
+
asset: {
|
|
101
|
+
type: mockToken1.tokenType,
|
|
102
|
+
assetReference: mockToken1.contractAddress,
|
|
103
|
+
assetOwner: address,
|
|
104
|
+
name: mockToken1.name,
|
|
105
|
+
unit: mockToken1.units[0],
|
|
106
|
+
},
|
|
107
|
+
},
|
|
108
|
+
{
|
|
109
|
+
value: BigInt("10000"),
|
|
110
|
+
asset: {
|
|
111
|
+
type: mockToken2.tokenType,
|
|
112
|
+
assetReference: mockToken2.contractAddress,
|
|
113
|
+
assetOwner: address,
|
|
114
|
+
name: mockToken2.name,
|
|
115
|
+
unit: mockToken2.units[0],
|
|
116
|
+
},
|
|
117
|
+
},
|
|
118
|
+
]),
|
|
119
|
+
);
|
|
120
|
+
});
|
|
121
|
+
|
|
122
|
+
it("should skip tokens not found in CAL", async () => {
|
|
123
|
+
const address = "0.0.12345";
|
|
124
|
+
const mockCurrency = getMockedCurrency();
|
|
125
|
+
const mockMirrorAccount = {
|
|
126
|
+
balance: {
|
|
127
|
+
balance: "1000000000",
|
|
128
|
+
},
|
|
129
|
+
};
|
|
130
|
+
const mockMirrorTokens = [
|
|
131
|
+
{
|
|
132
|
+
token_id: "0.0.7890",
|
|
133
|
+
balance: "5000",
|
|
134
|
+
},
|
|
135
|
+
{
|
|
136
|
+
token_id: "0.0.9876",
|
|
137
|
+
balance: "10000",
|
|
138
|
+
},
|
|
139
|
+
];
|
|
140
|
+
const mockToken1 = {
|
|
141
|
+
id: "token1",
|
|
142
|
+
contractAddress: "0.0.7890",
|
|
143
|
+
tokenType: "hts",
|
|
144
|
+
name: "Test Token 1",
|
|
145
|
+
units: [{ name: "TT1", code: "tt1", magnitude: 6 }],
|
|
146
|
+
};
|
|
147
|
+
|
|
148
|
+
(apiClient.getAccount as jest.Mock).mockResolvedValue(mockMirrorAccount);
|
|
149
|
+
(apiClient.getAccountTokens as jest.Mock).mockResolvedValue(mockMirrorTokens);
|
|
150
|
+
(findTokenByAddressInCurrency as jest.Mock).mockImplementation(tokenId => {
|
|
151
|
+
if (tokenId === "0.0.7890") return mockToken1;
|
|
152
|
+
return null;
|
|
153
|
+
});
|
|
154
|
+
|
|
155
|
+
const result = await getBalance(mockCurrency, address);
|
|
156
|
+
|
|
157
|
+
expect(result).toHaveLength(2);
|
|
158
|
+
expect(result[0]).toEqual({
|
|
159
|
+
asset: { type: "native" },
|
|
160
|
+
value: BigInt("1000000000"),
|
|
161
|
+
});
|
|
162
|
+
expect(result[1]).toEqual({
|
|
163
|
+
value: BigInt("5000"),
|
|
164
|
+
asset: {
|
|
165
|
+
type: mockToken1.tokenType,
|
|
166
|
+
assetReference: mockToken1.contractAddress,
|
|
167
|
+
assetOwner: address,
|
|
168
|
+
name: mockToken1.name,
|
|
169
|
+
unit: mockToken1.units[0],
|
|
170
|
+
},
|
|
171
|
+
});
|
|
172
|
+
});
|
|
173
|
+
|
|
174
|
+
it("should throw when failing to getAccount data", async () => {
|
|
175
|
+
const address = "0.0.12345";
|
|
176
|
+
const mockCurrency = getMockedCurrency();
|
|
177
|
+
const error = new Error("Network error");
|
|
178
|
+
|
|
179
|
+
(apiClient.getAccount as jest.Mock).mockRejectedValue(error);
|
|
180
|
+
(apiClient.getAccountTokens as jest.Mock).mockResolvedValue([]);
|
|
181
|
+
|
|
182
|
+
await expect(getBalance(mockCurrency, address)).rejects.toThrow(error);
|
|
183
|
+
});
|
|
184
|
+
|
|
185
|
+
it("should throw when failing to getAccountTokens data", async () => {
|
|
186
|
+
const address = "0.0.12345";
|
|
187
|
+
const mockCurrency = getMockedCurrency();
|
|
188
|
+
const error = new Error("Network error");
|
|
189
|
+
const mockMirrorAccount = {
|
|
190
|
+
balance: {
|
|
191
|
+
balance: "1000000000",
|
|
192
|
+
},
|
|
193
|
+
};
|
|
194
|
+
|
|
195
|
+
(apiClient.getAccount as jest.Mock).mockResolvedValue(mockMirrorAccount);
|
|
196
|
+
(apiClient.getAccountTokens as jest.Mock).mockRejectedValue(error);
|
|
197
|
+
|
|
198
|
+
await expect(getBalance(mockCurrency, address)).rejects.toThrow(error);
|
|
199
|
+
});
|
|
200
|
+
});
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import type { Balance } from "@ledgerhq/coin-framework/api/types";
|
|
2
|
+
import type { CryptoCurrency } from "@ledgerhq/types-cryptoassets";
|
|
3
|
+
import { findTokenByAddressInCurrency } from "@ledgerhq/cryptoassets/tokens";
|
|
4
|
+
import { apiClient } from "../network/api";
|
|
5
|
+
|
|
6
|
+
export async function getBalance(currency: CryptoCurrency, address: string): Promise<Balance[]> {
|
|
7
|
+
const [mirrorAccount, mirrorTokens] = await Promise.all([
|
|
8
|
+
apiClient.getAccount(address),
|
|
9
|
+
apiClient.getAccountTokens(address),
|
|
10
|
+
]);
|
|
11
|
+
|
|
12
|
+
const balance: Balance[] = [
|
|
13
|
+
{
|
|
14
|
+
asset: { type: "native" },
|
|
15
|
+
value: BigInt(mirrorAccount.balance.balance),
|
|
16
|
+
},
|
|
17
|
+
];
|
|
18
|
+
|
|
19
|
+
for (const mirrorToken of mirrorTokens) {
|
|
20
|
+
const calToken = findTokenByAddressInCurrency(mirrorToken.token_id, currency.id);
|
|
21
|
+
|
|
22
|
+
if (!calToken) {
|
|
23
|
+
continue;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
balance.push({
|
|
27
|
+
value: BigInt(mirrorToken.balance),
|
|
28
|
+
asset: {
|
|
29
|
+
type: calToken.tokenType,
|
|
30
|
+
assetReference: calToken.contractAddress,
|
|
31
|
+
assetOwner: address,
|
|
32
|
+
name: calToken.name,
|
|
33
|
+
unit: calToken.units[0],
|
|
34
|
+
},
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
return balance;
|
|
39
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { getTokenFromAsset } from "./getTokenFromAsset";
|
|
2
|
+
import { getMockedCurrency } from "../test/fixtures/currency.fixture";
|
|
3
|
+
|
|
4
|
+
describe("getTokenFromAsset", () => {
|
|
5
|
+
const mockCurrency = getMockedCurrency();
|
|
6
|
+
|
|
7
|
+
it("returns token from USDC asset", async () => {
|
|
8
|
+
const asset1 = { type: "hts", assetReference: "0.0.5022567" };
|
|
9
|
+
|
|
10
|
+
expect(await getTokenFromAsset(mockCurrency, asset1)).toMatchObject({
|
|
11
|
+
id: "hedera/hts/hbark_0.0.5022567",
|
|
12
|
+
contractAddress: "0.0.5022567",
|
|
13
|
+
name: "hBARK",
|
|
14
|
+
});
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
it("returns undefined for native asset", async () => {
|
|
18
|
+
const nativeAsset = { type: "native" };
|
|
19
|
+
|
|
20
|
+
expect(await getTokenFromAsset(mockCurrency, nativeAsset)).toBeUndefined();
|
|
21
|
+
});
|
|
22
|
+
});
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { AssetInfo } from "@ledgerhq/coin-framework/api/types";
|
|
2
|
+
import type { CryptoCurrency, TokenCurrency } from "@ledgerhq/types-cryptoassets";
|
|
3
|
+
import { findTokenByAddressInCurrency } from "@ledgerhq/cryptoassets/tokens";
|
|
4
|
+
|
|
5
|
+
export async function getTokenFromAsset(
|
|
6
|
+
currency: CryptoCurrency,
|
|
7
|
+
asset: AssetInfo,
|
|
8
|
+
): Promise<TokenCurrency | undefined> {
|
|
9
|
+
const tokenId =
|
|
10
|
+
asset.type !== "native" && "assetReference" in asset ? asset.assetReference : undefined;
|
|
11
|
+
|
|
12
|
+
if (!tokenId) {
|
|
13
|
+
return;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
return findTokenByAddressInCurrency(tokenId, currency.id);
|
|
17
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export { broadcast } from "./broadcast";
|
|
2
|
+
export { combine } from "./combine";
|
|
3
|
+
export { craftTransaction } from "./craftTransaction";
|
|
4
|
+
export { estimateFees } from "./estimateFees";
|
|
5
|
+
export { getBalance } from "./getBalance";
|
|
6
|
+
export { lastBlock } from "./lastBlock";
|
|
7
|
+
export { listOperations } from "./listOperations";
|
|
8
|
+
export { getAssetFromToken } from "./getAssetFromToken";
|
|
9
|
+
export { getTokenFromAsset } from "./getTokenFromAsset";
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { lastBlock } from "./lastBlock";
|
|
2
|
+
import { apiClient } from "../network/api";
|
|
3
|
+
import { getSyntheticBlock } from "./utils";
|
|
4
|
+
|
|
5
|
+
jest.mock("../network/api");
|
|
6
|
+
|
|
7
|
+
describe("lastBlock", () => {
|
|
8
|
+
it("should return the last block info", async () => {
|
|
9
|
+
const mockTransaction = {
|
|
10
|
+
consensus_timestamp: "1625097600.000000000",
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
(apiClient.getLatestTransaction as jest.Mock).mockResolvedValue(mockTransaction);
|
|
14
|
+
|
|
15
|
+
const result = await lastBlock();
|
|
16
|
+
const expectedSyntheticBlock = getSyntheticBlock(mockTransaction.consensus_timestamp);
|
|
17
|
+
|
|
18
|
+
expect(apiClient.getLatestTransaction).toHaveBeenCalledTimes(1);
|
|
19
|
+
expect(result.height).toEqual(expectedSyntheticBlock.blockHeight);
|
|
20
|
+
expect(result.hash).toEqual(expectedSyntheticBlock.blockHash);
|
|
21
|
+
expect(result.time).toEqual(expectedSyntheticBlock.blockTime);
|
|
22
|
+
});
|
|
23
|
+
});
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import type { BlockInfo } from "@ledgerhq/coin-framework/api/index";
|
|
2
|
+
import { apiClient } from "../network/api";
|
|
3
|
+
import { getSyntheticBlock } from "./utils";
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Gets the latest "block" information for Hedera.
|
|
7
|
+
*
|
|
8
|
+
* Hedera doesn't have actual blocks - it uses a timestamp-based consensus model.
|
|
9
|
+
* To make Hedera compatible with block-based architecture:
|
|
10
|
+
* 1. We fetch the most recent transaction from the mirror node
|
|
11
|
+
* 2. Extract its consensus timestamp
|
|
12
|
+
* 3. Convert this timestamp into a synthetic block using a hardcoded time window (10 seconds by default)
|
|
13
|
+
*/
|
|
14
|
+
export async function lastBlock(): Promise<BlockInfo> {
|
|
15
|
+
const latestTransaction = await apiClient.getLatestTransaction();
|
|
16
|
+
const syntheticBlock = getSyntheticBlock(latestTransaction.consensus_timestamp);
|
|
17
|
+
|
|
18
|
+
return {
|
|
19
|
+
height: syntheticBlock.blockHeight,
|
|
20
|
+
hash: syntheticBlock.blockHash,
|
|
21
|
+
time: syntheticBlock.blockTime,
|
|
22
|
+
};
|
|
23
|
+
}
|