@ledgerhq/coin-hedera 1.15.0-nightly.20251126023856 → 1.15.0-nightly.20251127023715
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/CHANGELOG.md +10 -8
- package/lib/api/index.d.ts.map +1 -1
- package/lib/api/index.js +6 -2
- package/lib/api/index.js.map +1 -1
- package/lib/bridge/broadcast.js +1 -1
- package/lib/bridge/broadcast.js.map +1 -1
- package/lib/bridge/buildOptimisticOperation.d.ts.map +1 -1
- package/lib/bridge/buildOptimisticOperation.js +80 -15
- package/lib/bridge/buildOptimisticOperation.js.map +1 -1
- package/lib/bridge/estimateMaxSpendable.js +5 -2
- package/lib/bridge/estimateMaxSpendable.js.map +1 -1
- package/lib/bridge/getTransactionStatus.d.ts.map +1 -1
- package/lib/bridge/getTransactionStatus.js +70 -13
- package/lib/bridge/getTransactionStatus.js.map +1 -1
- package/lib/bridge/index.js +1 -1
- package/lib/bridge/index.js.map +1 -1
- package/lib/bridge/prepareTransaction.d.ts.map +1 -1
- package/lib/bridge/prepareTransaction.js +40 -7
- package/lib/bridge/prepareTransaction.js.map +1 -1
- package/lib/bridge/signOperation.d.ts.map +1 -1
- package/lib/bridge/signOperation.js +19 -2
- package/lib/bridge/signOperation.js.map +1 -1
- package/lib/bridge/synchronisation.d.ts +2 -0
- package/lib/bridge/synchronisation.d.ts.map +1 -1
- package/lib/bridge/synchronisation.js +101 -30
- package/lib/bridge/synchronisation.js.map +1 -1
- package/lib/bridge/utils.d.ts +35 -2
- package/lib/bridge/utils.d.ts.map +1 -1
- package/lib/bridge/utils.js +215 -16
- package/lib/bridge/utils.js.map +1 -1
- package/lib/constants.d.ts +22 -2
- package/lib/constants.d.ts.map +1 -1
- package/lib/constants.js +42 -2
- 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 +8 -0
- package/lib/deviceTransactionConfig.js.map +1 -1
- package/lib/errors.d.ts +3 -0
- package/lib/errors.d.ts.map +1 -1
- package/lib/errors.js +2 -1
- package/lib/errors.js.map +1 -1
- package/lib/logic/craftTransaction.d.ts +4 -4
- package/lib/logic/craftTransaction.d.ts.map +1 -1
- package/lib/logic/craftTransaction.js +46 -5
- package/lib/logic/craftTransaction.js.map +1 -1
- package/lib/logic/estimateFees.d.ts +2 -4
- package/lib/logic/estimateFees.d.ts.map +1 -1
- package/lib/logic/estimateFees.js +45 -5
- package/lib/logic/estimateFees.js.map +1 -1
- package/lib/logic/listOperations.d.ts.map +1 -1
- package/lib/logic/listOperations.js +7 -3
- package/lib/logic/listOperations.js.map +1 -1
- package/lib/logic/utils.d.ts +24 -2
- package/lib/logic/utils.d.ts.map +1 -1
- package/lib/logic/utils.js +66 -13
- package/lib/logic/utils.js.map +1 -1
- package/lib/network/api.d.ts +12 -1
- package/lib/network/api.d.ts.map +1 -1
- package/lib/network/api.js +91 -19
- package/lib/network/api.js.map +1 -1
- package/lib/network/rpc.d.ts.map +1 -1
- package/lib/network/rpc.js +1 -0
- package/lib/network/rpc.js.map +1 -1
- package/lib/network/thirdweb.d.ts +21 -0
- package/lib/network/thirdweb.d.ts.map +1 -0
- package/lib/network/thirdweb.js +72 -0
- package/lib/network/thirdweb.js.map +1 -0
- package/lib/network/utils.d.ts +4 -1
- package/lib/network/utils.d.ts.map +1 -1
- package/lib/network/utils.js +53 -1
- package/lib/network/utils.js.map +1 -1
- package/lib/test/bridgeDatasetTest.d.ts.map +1 -1
- package/lib/test/bridgeDatasetTest.js +4 -4
- package/lib/test/bridgeDatasetTest.js.map +1 -1
- package/lib/test/fixtures/account.fixture.js +1 -1
- package/lib/test/fixtures/account.fixture.js.map +1 -1
- package/lib/test/fixtures/common.fixture.d.ts +12 -0
- package/lib/test/fixtures/common.fixture.d.ts.map +1 -0
- package/lib/test/fixtures/common.fixture.js +66 -0
- package/lib/test/fixtures/common.fixture.js.map +1 -0
- package/lib/test/fixtures/currency.fixture.d.ts +3 -1
- package/lib/test/fixtures/currency.fixture.d.ts.map +1 -1
- package/lib/test/fixtures/currency.fixture.js +63 -16
- package/lib/test/fixtures/currency.fixture.js.map +1 -1
- package/lib/test/fixtures/mirror.fixture.d.ts +3 -1
- package/lib/test/fixtures/mirror.fixture.d.ts.map +1 -1
- package/lib/test/fixtures/mirror.fixture.js +12 -1
- package/lib/test/fixtures/mirror.fixture.js.map +1 -1
- package/lib/test/fixtures/thirdweb.fixture.d.ts +3 -0
- package/lib/test/fixtures/thirdweb.fixture.d.ts.map +1 -0
- package/lib/test/fixtures/thirdweb.fixture.js +34 -0
- package/lib/test/fixtures/thirdweb.fixture.js.map +1 -0
- package/lib/transaction.d.ts.map +1 -1
- package/lib/transaction.js +2 -0
- package/lib/transaction.js.map +1 -1
- package/lib/types/alpaca.d.ts +5 -1
- package/lib/types/alpaca.d.ts.map +1 -1
- package/lib/types/bridge.d.ts +6 -1
- 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/types/logic.d.ts +39 -0
- package/lib/types/logic.d.ts.map +1 -0
- package/lib/types/logic.js +3 -0
- package/lib/types/logic.js.map +1 -0
- package/lib/types/mirror.d.ts +29 -0
- package/lib/types/mirror.d.ts.map +1 -1
- package/lib/types/thirdweb.d.ts +34 -0
- package/lib/types/thirdweb.d.ts.map +1 -0
- package/lib/types/thirdweb.js +3 -0
- package/lib/types/thirdweb.js.map +1 -0
- package/lib-es/api/index.d.ts.map +1 -1
- package/lib-es/api/index.js +7 -3
- package/lib-es/api/index.js.map +1 -1
- package/lib-es/bridge/broadcast.js +2 -2
- 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 +83 -18
- package/lib-es/bridge/buildOptimisticOperation.js.map +1 -1
- package/lib-es/bridge/estimateMaxSpendable.js +5 -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 +73 -16
- package/lib-es/bridge/getTransactionStatus.js.map +1 -1
- package/lib-es/bridge/index.js +2 -2
- package/lib-es/bridge/index.js.map +1 -1
- package/lib-es/bridge/prepareTransaction.d.ts.map +1 -1
- package/lib-es/bridge/prepareTransaction.js +42 -9
- package/lib-es/bridge/prepareTransaction.js.map +1 -1
- package/lib-es/bridge/signOperation.d.ts.map +1 -1
- package/lib-es/bridge/signOperation.js +21 -4
- package/lib-es/bridge/signOperation.js.map +1 -1
- package/lib-es/bridge/synchronisation.d.ts +2 -0
- package/lib-es/bridge/synchronisation.d.ts.map +1 -1
- package/lib-es/bridge/synchronisation.js +97 -27
- package/lib-es/bridge/synchronisation.js.map +1 -1
- package/lib-es/bridge/utils.d.ts +35 -2
- package/lib-es/bridge/utils.d.ts.map +1 -1
- package/lib-es/bridge/utils.js +211 -16
- package/lib-es/bridge/utils.js.map +1 -1
- package/lib-es/constants.d.ts +22 -2
- package/lib-es/constants.d.ts.map +1 -1
- package/lib-es/constants.js +38 -1
- 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 +8 -0
- package/lib-es/deviceTransactionConfig.js.map +1 -1
- package/lib-es/errors.d.ts +3 -0
- package/lib-es/errors.d.ts.map +1 -1
- package/lib-es/errors.js +1 -0
- package/lib-es/errors.js.map +1 -1
- package/lib-es/logic/craftTransaction.d.ts +4 -4
- package/lib-es/logic/craftTransaction.d.ts.map +1 -1
- package/lib-es/logic/craftTransaction.js +48 -7
- package/lib-es/logic/craftTransaction.js.map +1 -1
- package/lib-es/logic/estimateFees.d.ts +2 -4
- package/lib-es/logic/estimateFees.d.ts.map +1 -1
- package/lib-es/logic/estimateFees.js +47 -7
- package/lib-es/logic/estimateFees.js.map +1 -1
- package/lib-es/logic/listOperations.d.ts.map +1 -1
- package/lib-es/logic/listOperations.js +7 -3
- package/lib-es/logic/listOperations.js.map +1 -1
- package/lib-es/logic/utils.d.ts +24 -2
- package/lib-es/logic/utils.d.ts.map +1 -1
- package/lib-es/logic/utils.js +63 -13
- package/lib-es/logic/utils.js.map +1 -1
- package/lib-es/network/api.d.ts +12 -1
- package/lib-es/network/api.d.ts.map +1 -1
- package/lib-es/network/api.js +91 -19
- package/lib-es/network/api.js.map +1 -1
- package/lib-es/network/rpc.d.ts.map +1 -1
- package/lib-es/network/rpc.js +1 -0
- package/lib-es/network/rpc.js.map +1 -1
- package/lib-es/network/thirdweb.d.ts +21 -0
- package/lib-es/network/thirdweb.d.ts.map +1 -0
- package/lib-es/network/thirdweb.js +66 -0
- package/lib-es/network/thirdweb.js.map +1 -0
- package/lib-es/network/utils.d.ts +4 -1
- package/lib-es/network/utils.d.ts.map +1 -1
- package/lib-es/network/utils.js +49 -0
- package/lib-es/network/utils.js.map +1 -1
- package/lib-es/test/bridgeDatasetTest.d.ts.map +1 -1
- package/lib-es/test/bridgeDatasetTest.js +4 -4
- package/lib-es/test/bridgeDatasetTest.js.map +1 -1
- package/lib-es/test/fixtures/account.fixture.js +2 -2
- package/lib-es/test/fixtures/account.fixture.js.map +1 -1
- package/lib-es/test/fixtures/common.fixture.d.ts +12 -0
- package/lib-es/test/fixtures/common.fixture.d.ts.map +1 -0
- package/lib-es/test/fixtures/common.fixture.js +57 -0
- package/lib-es/test/fixtures/common.fixture.js.map +1 -0
- package/lib-es/test/fixtures/currency.fixture.d.ts +3 -1
- package/lib-es/test/fixtures/currency.fixture.d.ts.map +1 -1
- package/lib-es/test/fixtures/currency.fixture.js +59 -14
- package/lib-es/test/fixtures/currency.fixture.js.map +1 -1
- package/lib-es/test/fixtures/mirror.fixture.d.ts +3 -1
- package/lib-es/test/fixtures/mirror.fixture.d.ts.map +1 -1
- package/lib-es/test/fixtures/mirror.fixture.js +9 -0
- package/lib-es/test/fixtures/mirror.fixture.js.map +1 -1
- package/lib-es/test/fixtures/thirdweb.fixture.d.ts +3 -0
- package/lib-es/test/fixtures/thirdweb.fixture.d.ts.map +1 -0
- package/lib-es/test/fixtures/thirdweb.fixture.js +30 -0
- package/lib-es/test/fixtures/thirdweb.fixture.js.map +1 -0
- package/lib-es/transaction.d.ts.map +1 -1
- package/lib-es/transaction.js +2 -0
- package/lib-es/transaction.js.map +1 -1
- package/lib-es/types/alpaca.d.ts +5 -1
- package/lib-es/types/alpaca.d.ts.map +1 -1
- package/lib-es/types/bridge.d.ts +6 -1
- 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/types/logic.d.ts +39 -0
- package/lib-es/types/logic.d.ts.map +1 -0
- package/lib-es/types/logic.js +2 -0
- package/lib-es/types/logic.js.map +1 -0
- package/lib-es/types/mirror.d.ts +29 -0
- package/lib-es/types/mirror.d.ts.map +1 -1
- package/lib-es/types/thirdweb.d.ts +34 -0
- package/lib-es/types/thirdweb.d.ts.map +1 -0
- package/lib-es/types/thirdweb.js +2 -0
- package/lib-es/types/thirdweb.js.map +1 -0
- package/package.json +9 -8
- package/src/api/index.integ.test.ts +11 -8
- package/src/api/index.ts +10 -3
- package/src/bridge/broadcast.ts +2 -2
- package/src/bridge/buildOptimisticOperation.integration.test.ts +70 -19
- package/src/bridge/buildOptimisticOperation.ts +98 -20
- package/src/bridge/estimateMaxSpendable.ts +5 -5
- package/src/bridge/getTransactionStatus.test.ts +57 -12
- package/src/bridge/getTransactionStatus.ts +88 -15
- package/src/bridge/index.ts +2 -2
- package/src/bridge/js-estimateMaxSpendable.integration.test.ts +12 -9
- package/src/bridge/prepareTransaction.test.ts +3 -1
- package/src/bridge/prepareTransaction.ts +45 -10
- package/src/bridge/signOperation.ts +23 -5
- package/src/bridge/synchronisation.test.ts +67 -0
- package/src/bridge/synchronisation.ts +114 -34
- package/src/bridge/utils.integration.test.ts +486 -180
- package/src/bridge/utils.test.ts +404 -0
- package/src/bridge/utils.ts +330 -27
- package/src/constants.ts +47 -2
- package/src/deviceTransactionConfig.ts +10 -1
- package/src/errors.ts +3 -0
- package/src/logic/craftTransaction.test.ts +49 -9
- package/src/logic/craftTransaction.ts +76 -11
- package/src/logic/estimateFees.test.ts +180 -31
- package/src/logic/estimateFees.ts +68 -7
- package/src/logic/getAssetFromToken.test.ts +2 -2
- package/src/logic/getBalance.test.ts +18 -57
- package/src/logic/getTokenFromAsset.test.ts +2 -2
- package/src/logic/listOperations.ts +9 -5
- package/src/logic/utils.test.ts +157 -69
- package/src/logic/utils.ts +75 -13
- package/src/network/api.test.ts +211 -3
- package/src/network/api.ts +118 -24
- package/src/network/rpc.test.ts +1 -0
- package/src/network/rpc.ts +1 -0
- package/src/network/thirdweb.test.ts +188 -0
- package/src/network/thirdweb.ts +101 -0
- package/src/network/utils.test.ts +364 -164
- package/src/network/utils.ts +83 -1
- package/src/test/bridgeDatasetTest.ts +4 -5
- package/src/test/fixtures/account.fixture.ts +2 -2
- package/src/test/fixtures/common.fixture.ts +74 -0
- package/src/test/fixtures/currency.fixture.ts +66 -14
- package/src/test/fixtures/mirror.fixture.ts +23 -1
- package/src/test/fixtures/thirdweb.fixture.ts +33 -0
- package/src/transaction.ts +2 -0
- package/src/types/alpaca.ts +8 -1
- package/src/types/bridge.ts +6 -1
- package/src/types/index.ts +2 -0
- package/src/types/logic.ts +44 -0
- package/src/types/mirror.ts +35 -0
- package/src/types/thirdweb.ts +36 -0
|
@@ -2,14 +2,17 @@ import BigNumber from "bignumber.js";
|
|
|
2
2
|
import invariant from "invariant";
|
|
3
3
|
import {
|
|
4
4
|
AccountId,
|
|
5
|
+
ContractExecuteTransaction,
|
|
6
|
+
ContractFunctionParameters,
|
|
7
|
+
ContractId,
|
|
5
8
|
Hbar,
|
|
6
9
|
TokenAssociateTransaction,
|
|
7
10
|
TransactionId,
|
|
8
11
|
TransferTransaction,
|
|
9
12
|
} from "@hashgraph/sdk";
|
|
10
13
|
import type { FeeEstimation, TransactionIntent } from "@ledgerhq/coin-framework/api/index";
|
|
11
|
-
import { HEDERA_TRANSACTION_MODES } from "../constants";
|
|
12
|
-
import type { HederaMemo } from "../types";
|
|
14
|
+
import { DEFAULT_GAS_LIMIT, HEDERA_TRANSACTION_MODES } from "../constants";
|
|
15
|
+
import type { HederaMemo, HederaTxData } from "../types";
|
|
13
16
|
import { serializeTransaction } from "./utils";
|
|
14
17
|
|
|
15
18
|
// avoid "sign" prompt loop by having only one node (one transaction)
|
|
@@ -32,13 +35,21 @@ interface BuilderCoinTransferTransaction extends BuilderCommonTransactionFields
|
|
|
32
35
|
recipient: string;
|
|
33
36
|
}
|
|
34
37
|
|
|
35
|
-
interface
|
|
38
|
+
interface BuilderHTSTokenTransferTransaction extends BuilderCommonTransactionFields {
|
|
36
39
|
type: HEDERA_TRANSACTION_MODES.Send;
|
|
37
|
-
|
|
40
|
+
tokenAddress: string;
|
|
38
41
|
amount: BigNumber;
|
|
39
42
|
recipient: string;
|
|
40
43
|
}
|
|
41
44
|
|
|
45
|
+
interface BuilderERC20TokenTransferTransaction extends BuilderCommonTransactionFields {
|
|
46
|
+
type: HEDERA_TRANSACTION_MODES.Send;
|
|
47
|
+
tokenAddress: string;
|
|
48
|
+
amount: BigNumber;
|
|
49
|
+
recipient: string;
|
|
50
|
+
gasLimit: BigNumber;
|
|
51
|
+
}
|
|
52
|
+
|
|
42
53
|
interface BuilderTokenAssociateTransaction extends BuilderCommonTransactionFields {
|
|
43
54
|
type: HEDERA_TRANSACTION_MODES.TokenAssociate;
|
|
44
55
|
tokenId: string;
|
|
@@ -68,15 +79,15 @@ async function buildUnsignedCoinTransaction({
|
|
|
68
79
|
return tx.freeze();
|
|
69
80
|
}
|
|
70
81
|
|
|
71
|
-
async function
|
|
82
|
+
async function buildUnsignedHTSTokenTransaction({
|
|
72
83
|
account,
|
|
73
84
|
transaction,
|
|
74
85
|
}: {
|
|
75
86
|
account: BuilderOperator;
|
|
76
|
-
transaction:
|
|
87
|
+
transaction: BuilderHTSTokenTransferTransaction;
|
|
77
88
|
}): Promise<TransferTransaction> {
|
|
78
89
|
const accountId = account.accountId;
|
|
79
|
-
const tokenId = transaction.
|
|
90
|
+
const tokenId = transaction.tokenAddress;
|
|
80
91
|
|
|
81
92
|
const tx = new TransferTransaction()
|
|
82
93
|
.setNodeAccountIds(nodeAccountIds)
|
|
@@ -92,6 +103,39 @@ async function buildUnsignedTokenTransaction({
|
|
|
92
103
|
return tx.freeze();
|
|
93
104
|
}
|
|
94
105
|
|
|
106
|
+
async function buildUnsignedERC20TokenTransaction({
|
|
107
|
+
account,
|
|
108
|
+
transaction,
|
|
109
|
+
}: {
|
|
110
|
+
account: BuilderOperator;
|
|
111
|
+
transaction: BuilderERC20TokenTransferTransaction;
|
|
112
|
+
}): Promise<ContractExecuteTransaction> {
|
|
113
|
+
const accountId = AccountId.fromString(account.accountId);
|
|
114
|
+
const contractId = ContractId.fromEvmAddress(0, 0, transaction.tokenAddress);
|
|
115
|
+
const recipientEvmAddress = AccountId.fromString(transaction.recipient).toSolidityAddress();
|
|
116
|
+
const gas = transaction.gasLimit.toNumber();
|
|
117
|
+
|
|
118
|
+
// create function parameters for ERC20 transfer function
|
|
119
|
+
// transfer(address to, uint256 amount) returns (bool)
|
|
120
|
+
const functionParameters = new ContractFunctionParameters()
|
|
121
|
+
.addAddress(recipientEvmAddress)
|
|
122
|
+
.addUint256(transaction.amount.toNumber());
|
|
123
|
+
|
|
124
|
+
const tx = new ContractExecuteTransaction()
|
|
125
|
+
.setNodeAccountIds(nodeAccountIds)
|
|
126
|
+
.setTransactionId(TransactionId.generate(accountId))
|
|
127
|
+
.setTransactionMemo(transaction.memo ?? "")
|
|
128
|
+
.setContractId(contractId)
|
|
129
|
+
.setGas(gas)
|
|
130
|
+
.setFunction("transfer", functionParameters);
|
|
131
|
+
|
|
132
|
+
if (transaction.maxFee) {
|
|
133
|
+
tx.setMaxTransactionFee(Hbar.fromTinybars(transaction.maxFee.toNumber()));
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
return tx.freeze();
|
|
137
|
+
}
|
|
138
|
+
|
|
95
139
|
async function buildTokenAssociateTransaction({
|
|
96
140
|
account,
|
|
97
141
|
transaction,
|
|
@@ -116,7 +160,7 @@ async function buildTokenAssociateTransaction({
|
|
|
116
160
|
}
|
|
117
161
|
|
|
118
162
|
export async function craftTransaction(
|
|
119
|
-
txIntent: TransactionIntent<HederaMemo>,
|
|
163
|
+
txIntent: TransactionIntent<HederaMemo, HederaTxData>,
|
|
120
164
|
customFees?: FeeEstimation,
|
|
121
165
|
) {
|
|
122
166
|
const account = {
|
|
@@ -138,20 +182,41 @@ export async function craftTransaction(
|
|
|
138
182
|
maxFee: customFees ? new BigNumber(customFees.value.toString()) : undefined,
|
|
139
183
|
},
|
|
140
184
|
});
|
|
141
|
-
} else if (txIntent.type === HEDERA_TRANSACTION_MODES.Send && txIntent.asset.type
|
|
185
|
+
} else if (txIntent.type === HEDERA_TRANSACTION_MODES.Send && txIntent.asset.type === "hts") {
|
|
142
186
|
invariant("assetReference" in txIntent.asset, "hedera: no assetReference in token transfer");
|
|
143
187
|
|
|
144
188
|
const amount = new BigNumber(txIntent.amount.toString());
|
|
145
189
|
|
|
146
|
-
tx = await
|
|
190
|
+
tx = await buildUnsignedHTSTokenTransaction({
|
|
147
191
|
account,
|
|
148
192
|
transaction: {
|
|
149
193
|
type: txIntent.type,
|
|
150
|
-
|
|
194
|
+
tokenAddress: txIntent.asset.assetReference,
|
|
195
|
+
amount,
|
|
196
|
+
recipient: txIntent.recipient,
|
|
197
|
+
memo: txIntent.memo.value,
|
|
198
|
+
maxFee: customFees ? new BigNumber(customFees.value.toString()) : undefined,
|
|
199
|
+
},
|
|
200
|
+
});
|
|
201
|
+
} else if (txIntent.type === HEDERA_TRANSACTION_MODES.Send && txIntent.asset.type === "erc20") {
|
|
202
|
+
invariant("assetReference" in txIntent.asset, "hedera: no assetReference in token transfer");
|
|
203
|
+
|
|
204
|
+
const amount = new BigNumber(txIntent.amount.toString());
|
|
205
|
+
const gasLimit =
|
|
206
|
+
"data" in txIntent && txIntent.data.gasLimit
|
|
207
|
+
? new BigNumber(txIntent.data.gasLimit.toString())
|
|
208
|
+
: DEFAULT_GAS_LIMIT;
|
|
209
|
+
|
|
210
|
+
tx = await buildUnsignedERC20TokenTransaction({
|
|
211
|
+
account,
|
|
212
|
+
transaction: {
|
|
213
|
+
type: txIntent.type,
|
|
214
|
+
tokenAddress: txIntent.asset.assetReference,
|
|
151
215
|
amount,
|
|
152
216
|
recipient: txIntent.recipient,
|
|
153
217
|
memo: txIntent.memo.value,
|
|
154
218
|
maxFee: customFees ? new BigNumber(customFees.value.toString()) : undefined,
|
|
219
|
+
gasLimit,
|
|
155
220
|
},
|
|
156
221
|
});
|
|
157
222
|
} else {
|
|
@@ -1,19 +1,29 @@
|
|
|
1
1
|
import BigNumber from "bignumber.js";
|
|
2
2
|
import cvsApi from "@ledgerhq/live-countervalues/api/index";
|
|
3
3
|
import {
|
|
4
|
+
DEFAULT_GAS_LIMIT,
|
|
5
|
+
DEFAULT_GAS_PRICE_TINYBARS,
|
|
4
6
|
DEFAULT_TINYBAR_FEE,
|
|
5
7
|
ESTIMATED_FEE_SAFETY_RATE,
|
|
8
|
+
ESTIMATED_GAS_SAFETY_RATE,
|
|
6
9
|
HEDERA_OPERATION_TYPES,
|
|
10
|
+
HEDERA_TRANSACTION_MODES,
|
|
7
11
|
TINYBAR_SCALE,
|
|
8
12
|
} from "../constants";
|
|
9
13
|
import { estimateFees } from "./estimateFees";
|
|
10
14
|
import { getMockedAccount } from "../test/fixtures/account.fixture";
|
|
11
|
-
import { getCurrencyToUSDRate } from "./utils";
|
|
15
|
+
import { getCurrencyToUSDRate, toEVMAddress } from "./utils";
|
|
16
|
+
import { apiClient } from "../network/api";
|
|
17
|
+
import { getMockedERC20TokenCurrency } from "../test/fixtures/currency.fixture";
|
|
12
18
|
|
|
13
19
|
jest.mock("@ledgerhq/live-countervalues/api/index");
|
|
20
|
+
jest.mock("../network/api");
|
|
14
21
|
|
|
15
22
|
describe("getEstimatedFees", () => {
|
|
16
23
|
const mockedAccount = getMockedAccount();
|
|
24
|
+
const mockedTokenCurrencyERC20 = getMockedERC20TokenCurrency();
|
|
25
|
+
const senderAddress = "0.0.12345";
|
|
26
|
+
const recipientAddress = "0.0.67890";
|
|
17
27
|
|
|
18
28
|
beforeEach(() => {
|
|
19
29
|
jest.clearAllMocks();
|
|
@@ -21,79 +31,218 @@ describe("getEstimatedFees", () => {
|
|
|
21
31
|
getCurrencyToUSDRate.clear(mockedAccount.currency.ticker);
|
|
22
32
|
});
|
|
23
33
|
|
|
24
|
-
|
|
34
|
+
it("returns estimated fee based on USD rate for CryptoTransfer", async () => {
|
|
25
35
|
const usdRate = 1; // 1 HBAR = 1 USD
|
|
26
36
|
(cvsApi.fetchLatest as jest.Mock).mockResolvedValueOnce([usdRate]);
|
|
27
37
|
|
|
28
|
-
const result = await estimateFees(
|
|
29
|
-
mockedAccount.currency,
|
|
30
|
-
HEDERA_OPERATION_TYPES.CryptoTransfer,
|
|
31
|
-
);
|
|
38
|
+
const result = await estimateFees({
|
|
39
|
+
currency: mockedAccount.currency,
|
|
40
|
+
operationType: HEDERA_OPERATION_TYPES.CryptoTransfer,
|
|
41
|
+
});
|
|
32
42
|
|
|
33
43
|
const baseFeeTinybar = 0.0001 * 10 ** TINYBAR_SCALE;
|
|
34
|
-
const
|
|
44
|
+
const expectedTinybars = new BigNumber(baseFeeTinybar)
|
|
35
45
|
.div(usdRate)
|
|
36
46
|
.integerValue(BigNumber.ROUND_CEIL)
|
|
37
47
|
.multipliedBy(ESTIMATED_FEE_SAFETY_RATE);
|
|
38
48
|
|
|
39
|
-
expect(result).
|
|
49
|
+
expect(result).toMatchObject({
|
|
50
|
+
tinybars: expectedTinybars,
|
|
51
|
+
});
|
|
40
52
|
});
|
|
41
53
|
|
|
42
|
-
|
|
54
|
+
it("returns estimated fee based on USD rate for TokenTransfer", async () => {
|
|
43
55
|
const usdRate = 0.5; // 1 HBAR = 0.5 USD
|
|
44
56
|
(cvsApi.fetchLatest as jest.Mock).mockResolvedValueOnce([usdRate]);
|
|
45
57
|
|
|
46
|
-
const result = await estimateFees(
|
|
58
|
+
const result = await estimateFees({
|
|
59
|
+
currency: mockedAccount.currency,
|
|
60
|
+
operationType: HEDERA_OPERATION_TYPES.TokenTransfer,
|
|
61
|
+
});
|
|
47
62
|
|
|
48
63
|
const baseFeeTinybar = 0.001 * 10 ** TINYBAR_SCALE;
|
|
49
|
-
const
|
|
64
|
+
const expectedTinybars = new BigNumber(baseFeeTinybar)
|
|
50
65
|
.div(usdRate)
|
|
51
66
|
.integerValue(BigNumber.ROUND_CEIL)
|
|
52
67
|
.multipliedBy(ESTIMATED_FEE_SAFETY_RATE);
|
|
53
68
|
|
|
54
|
-
expect(result).
|
|
69
|
+
expect(result).toMatchObject({
|
|
70
|
+
tinybars: expectedTinybars,
|
|
71
|
+
});
|
|
55
72
|
});
|
|
56
73
|
|
|
57
|
-
|
|
74
|
+
it("returns estimated fee based on USD rate for TokenAssociate", async () => {
|
|
58
75
|
const usdRate = 2; // 1 HBAR = 2 USD
|
|
59
76
|
(cvsApi.fetchLatest as jest.Mock).mockResolvedValueOnce([usdRate]);
|
|
60
77
|
|
|
61
|
-
const result = await estimateFees(
|
|
62
|
-
mockedAccount.currency,
|
|
63
|
-
HEDERA_OPERATION_TYPES.TokenAssociate,
|
|
64
|
-
);
|
|
78
|
+
const result = await estimateFees({
|
|
79
|
+
currency: mockedAccount.currency,
|
|
80
|
+
operationType: HEDERA_OPERATION_TYPES.TokenAssociate,
|
|
81
|
+
});
|
|
65
82
|
|
|
66
83
|
const baseFeeTinybar = 0.05 * 10 ** TINYBAR_SCALE;
|
|
67
|
-
const
|
|
84
|
+
const expectedTinybars = new BigNumber(baseFeeTinybar)
|
|
68
85
|
.div(usdRate)
|
|
69
86
|
.integerValue(BigNumber.ROUND_CEIL)
|
|
70
87
|
.multipliedBy(ESTIMATED_FEE_SAFETY_RATE);
|
|
71
88
|
|
|
72
|
-
expect(result).
|
|
89
|
+
expect(result).toMatchObject({
|
|
90
|
+
tinybars: expectedTinybars,
|
|
91
|
+
});
|
|
92
|
+
});
|
|
93
|
+
|
|
94
|
+
it("returns estimated fee based on gas for ContractCall", async () => {
|
|
95
|
+
const estimatedGasLimit = new BigNumber(50000);
|
|
96
|
+
const gasPriceTinybars = new BigNumber(900);
|
|
97
|
+
const transferAmount = BigInt(1000000);
|
|
98
|
+
|
|
99
|
+
(apiClient.getNetworkFees as jest.Mock).mockResolvedValueOnce({
|
|
100
|
+
fees: [
|
|
101
|
+
{
|
|
102
|
+
transaction_type: "ContractCall",
|
|
103
|
+
gas: gasPriceTinybars.toNumber(),
|
|
104
|
+
},
|
|
105
|
+
],
|
|
106
|
+
});
|
|
107
|
+
|
|
108
|
+
(apiClient.estimateContractCallGas as jest.Mock).mockResolvedValueOnce(estimatedGasLimit);
|
|
109
|
+
|
|
110
|
+
const result = await estimateFees({
|
|
111
|
+
operationType: HEDERA_OPERATION_TYPES.ContractCall,
|
|
112
|
+
txIntent: {
|
|
113
|
+
intentType: "transaction",
|
|
114
|
+
type: HEDERA_TRANSACTION_MODES.Send,
|
|
115
|
+
sender: senderAddress,
|
|
116
|
+
recipient: recipientAddress,
|
|
117
|
+
amount: transferAmount,
|
|
118
|
+
asset: {
|
|
119
|
+
type: "erc20",
|
|
120
|
+
assetReference: mockedTokenCurrencyERC20.contractAddress,
|
|
121
|
+
},
|
|
122
|
+
},
|
|
123
|
+
});
|
|
124
|
+
|
|
125
|
+
const expectedGas = estimatedGasLimit
|
|
126
|
+
.multipliedBy(ESTIMATED_GAS_SAFETY_RATE)
|
|
127
|
+
.integerValue(BigNumber.ROUND_CEIL);
|
|
128
|
+
|
|
129
|
+
const expectedTinybars = expectedGas
|
|
130
|
+
.multipliedBy(gasPriceTinybars)
|
|
131
|
+
.integerValue(BigNumber.ROUND_CEIL);
|
|
132
|
+
|
|
133
|
+
expect(apiClient.getNetworkFees).toHaveBeenCalledTimes(1);
|
|
134
|
+
expect(apiClient.estimateContractCallGas).toHaveBeenCalledTimes(1);
|
|
135
|
+
expect(apiClient.estimateContractCallGas).toHaveBeenCalledWith(
|
|
136
|
+
toEVMAddress(senderAddress),
|
|
137
|
+
toEVMAddress(recipientAddress),
|
|
138
|
+
mockedTokenCurrencyERC20.contractAddress,
|
|
139
|
+
transferAmount,
|
|
140
|
+
);
|
|
141
|
+
expect(result).toMatchObject({
|
|
142
|
+
tinybars: expectedTinybars,
|
|
143
|
+
gas: expectedGas,
|
|
144
|
+
});
|
|
145
|
+
});
|
|
146
|
+
|
|
147
|
+
it("falls back to default gas values when getNetworkFees fail", async () => {
|
|
148
|
+
const transferAmount = BigInt(1000000);
|
|
149
|
+
|
|
150
|
+
(apiClient.getNetworkFees as jest.Mock).mockRejectedValueOnce(new Error("Network error"));
|
|
151
|
+
|
|
152
|
+
const result = await estimateFees({
|
|
153
|
+
operationType: HEDERA_OPERATION_TYPES.ContractCall,
|
|
154
|
+
txIntent: {
|
|
155
|
+
intentType: "transaction",
|
|
156
|
+
type: HEDERA_TRANSACTION_MODES.Send,
|
|
157
|
+
sender: senderAddress,
|
|
158
|
+
recipient: recipientAddress,
|
|
159
|
+
amount: transferAmount,
|
|
160
|
+
asset: {
|
|
161
|
+
type: "erc20",
|
|
162
|
+
assetReference: mockedTokenCurrencyERC20.contractAddress,
|
|
163
|
+
},
|
|
164
|
+
},
|
|
165
|
+
});
|
|
166
|
+
|
|
167
|
+
const expectedGas = DEFAULT_GAS_LIMIT;
|
|
168
|
+
const expectedTinybars = new BigNumber(expectedGas)
|
|
169
|
+
.multipliedBy(DEFAULT_GAS_PRICE_TINYBARS)
|
|
170
|
+
.integerValue(BigNumber.ROUND_CEIL);
|
|
171
|
+
|
|
172
|
+
expect(result).toMatchObject({
|
|
173
|
+
tinybars: expectedTinybars,
|
|
174
|
+
gas: expectedGas,
|
|
175
|
+
});
|
|
73
176
|
});
|
|
74
177
|
|
|
75
|
-
|
|
178
|
+
it("falls back to default gas values when estimateContractCallGas fail", async () => {
|
|
179
|
+
const transferAmount = BigInt(1000000);
|
|
180
|
+
|
|
181
|
+
(apiClient.getNetworkFees as jest.Mock).mockResolvedValueOnce({
|
|
182
|
+
fees: [],
|
|
183
|
+
});
|
|
184
|
+
(apiClient.estimateContractCallGas as jest.Mock).mockRejectedValueOnce(
|
|
185
|
+
new Error("Network error"),
|
|
186
|
+
);
|
|
187
|
+
|
|
188
|
+
const result = await estimateFees({
|
|
189
|
+
operationType: HEDERA_OPERATION_TYPES.ContractCall,
|
|
190
|
+
txIntent: {
|
|
191
|
+
intentType: "transaction",
|
|
192
|
+
type: HEDERA_TRANSACTION_MODES.Send,
|
|
193
|
+
sender: senderAddress,
|
|
194
|
+
recipient: recipientAddress,
|
|
195
|
+
amount: transferAmount,
|
|
196
|
+
asset: {
|
|
197
|
+
type: "erc20",
|
|
198
|
+
assetReference: mockedTokenCurrencyERC20.contractAddress,
|
|
199
|
+
},
|
|
200
|
+
},
|
|
201
|
+
});
|
|
202
|
+
|
|
203
|
+
const expectedGas = DEFAULT_GAS_LIMIT;
|
|
204
|
+
const expectedTinybars = new BigNumber(expectedGas)
|
|
205
|
+
.multipliedBy(DEFAULT_GAS_PRICE_TINYBARS)
|
|
206
|
+
.integerValue(BigNumber.ROUND_CEIL);
|
|
207
|
+
|
|
208
|
+
expect(result).toMatchObject({
|
|
209
|
+
tinybars: expectedTinybars,
|
|
210
|
+
gas: expectedGas,
|
|
211
|
+
});
|
|
212
|
+
});
|
|
213
|
+
|
|
214
|
+
it("falls back to default estimate when cvs api returns null", async () => {
|
|
76
215
|
const usdRate = null;
|
|
77
216
|
(cvsApi.fetchLatest as jest.Mock).mockResolvedValueOnce([usdRate]);
|
|
78
217
|
|
|
79
|
-
const result = await estimateFees(
|
|
80
|
-
mockedAccount.currency,
|
|
81
|
-
HEDERA_OPERATION_TYPES.CryptoTransfer,
|
|
218
|
+
const result = await estimateFees({
|
|
219
|
+
currency: mockedAccount.currency,
|
|
220
|
+
operationType: HEDERA_OPERATION_TYPES.CryptoTransfer,
|
|
221
|
+
});
|
|
222
|
+
|
|
223
|
+
const expectedTinybars = new BigNumber(DEFAULT_TINYBAR_FEE).multipliedBy(
|
|
224
|
+
ESTIMATED_FEE_SAFETY_RATE,
|
|
82
225
|
);
|
|
83
226
|
|
|
84
|
-
|
|
85
|
-
|
|
227
|
+
expect(result).toMatchObject({
|
|
228
|
+
tinybars: expectedTinybars,
|
|
229
|
+
});
|
|
86
230
|
});
|
|
87
231
|
|
|
88
|
-
|
|
232
|
+
it("falls back to default estimate on cvs api failure", async () => {
|
|
89
233
|
(cvsApi.fetchLatest as jest.Mock).mockRejectedValueOnce(new Error("Network error"));
|
|
90
234
|
|
|
91
|
-
const result = await estimateFees(
|
|
92
|
-
mockedAccount.currency,
|
|
93
|
-
HEDERA_OPERATION_TYPES.CryptoTransfer,
|
|
235
|
+
const result = await estimateFees({
|
|
236
|
+
currency: mockedAccount.currency,
|
|
237
|
+
operationType: HEDERA_OPERATION_TYPES.CryptoTransfer,
|
|
238
|
+
});
|
|
239
|
+
|
|
240
|
+
const expectedTinybars = new BigNumber(DEFAULT_TINYBAR_FEE).multipliedBy(
|
|
241
|
+
ESTIMATED_FEE_SAFETY_RATE,
|
|
94
242
|
);
|
|
95
243
|
|
|
96
|
-
|
|
97
|
-
|
|
244
|
+
expect(result).toMatchObject({
|
|
245
|
+
tinybars: expectedTinybars,
|
|
246
|
+
});
|
|
98
247
|
});
|
|
99
248
|
});
|
|
@@ -1,28 +1,89 @@
|
|
|
1
1
|
import BigNumber from "bignumber.js";
|
|
2
|
+
import type { TransactionIntent } from "@ledgerhq/coin-framework/api/types";
|
|
2
3
|
import type { CryptoCurrency } from "@ledgerhq/types-cryptoassets";
|
|
3
4
|
import {
|
|
4
5
|
BASE_USD_FEE_BY_OPERATION_TYPE,
|
|
6
|
+
DEFAULT_GAS_LIMIT,
|
|
7
|
+
DEFAULT_GAS_PRICE_TINYBARS,
|
|
5
8
|
DEFAULT_TINYBAR_FEE,
|
|
6
9
|
ESTIMATED_FEE_SAFETY_RATE,
|
|
10
|
+
ESTIMATED_GAS_SAFETY_RATE,
|
|
7
11
|
HEDERA_OPERATION_TYPES,
|
|
8
12
|
} from "../constants";
|
|
9
|
-
import {
|
|
13
|
+
import { apiClient } from "../network/api";
|
|
14
|
+
import type { EstimateFeesParams, EstimateFeesResult } from "../types";
|
|
15
|
+
import { getCurrencyToUSDRate, toEVMAddress } from "./utils";
|
|
10
16
|
|
|
11
|
-
|
|
17
|
+
const estimateContractCallFees = async (
|
|
18
|
+
txIntent: TransactionIntent,
|
|
19
|
+
): Promise<EstimateFeesResult> => {
|
|
20
|
+
let tinybars = new BigNumber(0);
|
|
21
|
+
let gas = new BigNumber(0);
|
|
22
|
+
|
|
23
|
+
const tokenEvmAddress = "assetReference" in txIntent.asset ? txIntent.asset.assetReference : null;
|
|
24
|
+
const senderEvmAddress = toEVMAddress(txIntent.sender);
|
|
25
|
+
const recipientEvmAddress = toEVMAddress(txIntent.recipient);
|
|
26
|
+
|
|
27
|
+
if (!tokenEvmAddress || !senderEvmAddress || !recipientEvmAddress) {
|
|
28
|
+
return {
|
|
29
|
+
tinybars,
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
try {
|
|
34
|
+
const [networkFees, gasLimit] = await Promise.all([
|
|
35
|
+
apiClient.getNetworkFees(),
|
|
36
|
+
apiClient.estimateContractCallGas(
|
|
37
|
+
senderEvmAddress,
|
|
38
|
+
recipientEvmAddress,
|
|
39
|
+
tokenEvmAddress,
|
|
40
|
+
txIntent.amount,
|
|
41
|
+
),
|
|
42
|
+
]);
|
|
43
|
+
|
|
44
|
+
const contractCallFees = networkFees.fees.find(
|
|
45
|
+
fee => fee.transaction_type === HEDERA_OPERATION_TYPES.ContractCall,
|
|
46
|
+
);
|
|
47
|
+
const gasTinybarRate = new BigNumber(contractCallFees?.gas ?? DEFAULT_GAS_PRICE_TINYBARS);
|
|
48
|
+
gas = gasLimit.multipliedBy(ESTIMATED_GAS_SAFETY_RATE).integerValue(BigNumber.ROUND_CEIL);
|
|
49
|
+
tinybars = gas.multipliedBy(gasTinybarRate).integerValue(BigNumber.ROUND_CEIL);
|
|
50
|
+
} catch {
|
|
51
|
+
const gasTinybarRate = DEFAULT_GAS_PRICE_TINYBARS;
|
|
52
|
+
gas = DEFAULT_GAS_LIMIT;
|
|
53
|
+
tinybars = gas.multipliedBy(gasTinybarRate).integerValue(BigNumber.ROUND_CEIL);
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
return {
|
|
57
|
+
tinybars,
|
|
58
|
+
gas,
|
|
59
|
+
};
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
const estimateStandardFees = async (
|
|
12
63
|
currency: CryptoCurrency,
|
|
13
64
|
operationType: HEDERA_OPERATION_TYPES,
|
|
14
|
-
): Promise<
|
|
15
|
-
let
|
|
65
|
+
): Promise<EstimateFeesResult> => {
|
|
66
|
+
let tinybars: BigNumber;
|
|
16
67
|
const usdRate = await getCurrencyToUSDRate(currency).catch(() => null);
|
|
17
68
|
|
|
18
69
|
if (usdRate) {
|
|
19
|
-
|
|
70
|
+
tinybars = new BigNumber(BASE_USD_FEE_BY_OPERATION_TYPE[operationType])
|
|
20
71
|
.dividedBy(new BigNumber(usdRate))
|
|
21
72
|
.integerValue(BigNumber.ROUND_CEIL)
|
|
22
73
|
.multipliedBy(ESTIMATED_FEE_SAFETY_RATE);
|
|
23
74
|
} else {
|
|
24
|
-
|
|
75
|
+
tinybars = new BigNumber(DEFAULT_TINYBAR_FEE).multipliedBy(ESTIMATED_FEE_SAFETY_RATE);
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
return {
|
|
79
|
+
tinybars,
|
|
80
|
+
};
|
|
81
|
+
};
|
|
82
|
+
|
|
83
|
+
export const estimateFees = async (params: EstimateFeesParams): Promise<EstimateFeesResult> => {
|
|
84
|
+
if (params.operationType === HEDERA_OPERATION_TYPES.ContractCall) {
|
|
85
|
+
return estimateContractCallFees(params.txIntent);
|
|
25
86
|
}
|
|
26
87
|
|
|
27
|
-
return
|
|
88
|
+
return estimateStandardFees(params.currency, params.operationType);
|
|
28
89
|
};
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { getAssetFromToken } from "./getAssetFromToken";
|
|
2
|
-
import {
|
|
2
|
+
import { getMockedHTSTokenCurrency } from "../test/fixtures/currency.fixture";
|
|
3
3
|
|
|
4
4
|
describe("getAssetFromToken", () => {
|
|
5
5
|
it("returns asset from TEST token", () => {
|
|
6
6
|
const owner = "owner";
|
|
7
|
-
const token =
|
|
7
|
+
const token = getMockedHTSTokenCurrency({
|
|
8
8
|
contractAddress: "0.0.1234567",
|
|
9
9
|
name: "TEST",
|
|
10
10
|
units: [
|
|
@@ -1,13 +1,11 @@
|
|
|
1
|
-
import { getBalance } from "./getBalance";
|
|
2
|
-
import { apiClient } from "../network/api";
|
|
3
|
-
import { getMockedCurrency } from "../test/fixtures/currency.fixture";
|
|
4
1
|
import { setupMockCryptoAssetsStore } from "@ledgerhq/cryptoassets/cal-client/test-helpers";
|
|
5
2
|
import type { TokenCurrency } from "@ledgerhq/types-cryptoassets";
|
|
3
|
+
import { getBalance } from "./getBalance";
|
|
4
|
+
import { apiClient } from "../network/api";
|
|
5
|
+
import { getMockedCurrency, getMockedHTSTokenCurrency } from "../test/fixtures/currency.fixture";
|
|
6
6
|
|
|
7
7
|
jest.mock("../network/api");
|
|
8
8
|
|
|
9
|
-
setupMockCryptoAssetsStore();
|
|
10
|
-
|
|
11
9
|
describe("getBalance", () => {
|
|
12
10
|
beforeEach(() => {
|
|
13
11
|
jest.clearAllMocks();
|
|
@@ -53,42 +51,16 @@ describe("getBalance", () => {
|
|
|
53
51
|
token_id: "0.0.7890",
|
|
54
52
|
balance: "5000",
|
|
55
53
|
},
|
|
56
|
-
{
|
|
57
|
-
token_id: "0.0.9876",
|
|
58
|
-
balance: "10000",
|
|
59
|
-
},
|
|
60
54
|
];
|
|
61
|
-
const
|
|
62
|
-
type: "TokenCurrency",
|
|
63
|
-
id: "token1",
|
|
55
|
+
const mockTokenHTS = getMockedHTSTokenCurrency({
|
|
64
56
|
contractAddress: "0.0.7890",
|
|
65
|
-
|
|
66
|
-
name: "Test Token 1",
|
|
67
|
-
ticker: "TT1",
|
|
68
|
-
parentCurrency: mockCurrency,
|
|
69
|
-
units: [{ name: "TT1", code: "tt1", magnitude: 6 }],
|
|
70
|
-
delisted: false,
|
|
71
|
-
disableCountervalue: false,
|
|
72
|
-
};
|
|
73
|
-
const mockToken2: TokenCurrency = {
|
|
74
|
-
type: "TokenCurrency",
|
|
75
|
-
id: "token2",
|
|
76
|
-
contractAddress: "0.0.9876",
|
|
77
|
-
tokenType: "hts",
|
|
78
|
-
name: "Test Token 2",
|
|
79
|
-
ticker: "TT2",
|
|
80
|
-
parentCurrency: mockCurrency,
|
|
81
|
-
units: [{ name: "TT2", code: "tt2", magnitude: 8 }],
|
|
82
|
-
delisted: false,
|
|
83
|
-
disableCountervalue: false,
|
|
84
|
-
};
|
|
57
|
+
});
|
|
85
58
|
|
|
86
59
|
const findTokenByAddressInCurrencyMock = jest
|
|
87
60
|
.fn()
|
|
88
61
|
.mockImplementation(
|
|
89
62
|
async (tokenId: string, _currencyId: string): Promise<TokenCurrency | undefined> => {
|
|
90
|
-
if (tokenId === "0.0.7890") return
|
|
91
|
-
if (tokenId === "0.0.9876") return mockToken2;
|
|
63
|
+
if (tokenId === "0.0.7890") return mockTokenHTS;
|
|
92
64
|
return undefined;
|
|
93
65
|
},
|
|
94
66
|
);
|
|
@@ -106,10 +78,9 @@ describe("getBalance", () => {
|
|
|
106
78
|
expect(apiClient.getAccount).toHaveBeenCalledWith(address);
|
|
107
79
|
expect(apiClient.getAccountTokens).toHaveBeenCalledTimes(1);
|
|
108
80
|
expect(apiClient.getAccountTokens).toHaveBeenCalledWith(address);
|
|
109
|
-
expect(findTokenByAddressInCurrencyMock).toHaveBeenCalledTimes(
|
|
81
|
+
expect(findTokenByAddressInCurrencyMock).toHaveBeenCalledTimes(1);
|
|
110
82
|
expect(findTokenByAddressInCurrencyMock).toHaveBeenCalledWith("0.0.7890", "hedera");
|
|
111
|
-
expect(
|
|
112
|
-
expect(result).toHaveLength(3);
|
|
83
|
+
expect(result).toHaveLength(2);
|
|
113
84
|
expect(result).toEqual(
|
|
114
85
|
expect.arrayContaining([
|
|
115
86
|
{
|
|
@@ -119,21 +90,11 @@ describe("getBalance", () => {
|
|
|
119
90
|
{
|
|
120
91
|
value: BigInt("5000"),
|
|
121
92
|
asset: {
|
|
122
|
-
type:
|
|
123
|
-
assetReference:
|
|
124
|
-
assetOwner: address,
|
|
125
|
-
name: mockToken1.name,
|
|
126
|
-
unit: mockToken1.units[0],
|
|
127
|
-
},
|
|
128
|
-
},
|
|
129
|
-
{
|
|
130
|
-
value: BigInt("10000"),
|
|
131
|
-
asset: {
|
|
132
|
-
type: mockToken2.tokenType,
|
|
133
|
-
assetReference: mockToken2.contractAddress,
|
|
93
|
+
type: mockTokenHTS.tokenType,
|
|
94
|
+
assetReference: mockTokenHTS.contractAddress,
|
|
134
95
|
assetOwner: address,
|
|
135
|
-
name:
|
|
136
|
-
unit:
|
|
96
|
+
name: mockTokenHTS.name,
|
|
97
|
+
unit: mockTokenHTS.units[0],
|
|
137
98
|
},
|
|
138
99
|
},
|
|
139
100
|
]),
|
|
@@ -158,7 +119,7 @@ describe("getBalance", () => {
|
|
|
158
119
|
balance: "10000",
|
|
159
120
|
},
|
|
160
121
|
];
|
|
161
|
-
const
|
|
122
|
+
const mockTokenHTS: TokenCurrency = {
|
|
162
123
|
type: "TokenCurrency",
|
|
163
124
|
id: "token1",
|
|
164
125
|
contractAddress: "0.0.7890",
|
|
@@ -175,7 +136,7 @@ describe("getBalance", () => {
|
|
|
175
136
|
.fn()
|
|
176
137
|
.mockImplementation(
|
|
177
138
|
async (tokenId: string, _currencyId: string): Promise<TokenCurrency | undefined> => {
|
|
178
|
-
if (tokenId === "0.0.7890") return
|
|
139
|
+
if (tokenId === "0.0.7890") return mockTokenHTS;
|
|
179
140
|
return undefined;
|
|
180
141
|
},
|
|
181
142
|
);
|
|
@@ -197,11 +158,11 @@ describe("getBalance", () => {
|
|
|
197
158
|
expect(result[1]).toEqual({
|
|
198
159
|
value: BigInt("5000"),
|
|
199
160
|
asset: {
|
|
200
|
-
type:
|
|
201
|
-
assetReference:
|
|
161
|
+
type: mockTokenHTS.tokenType,
|
|
162
|
+
assetReference: mockTokenHTS.contractAddress,
|
|
202
163
|
assetOwner: address,
|
|
203
|
-
name:
|
|
204
|
-
unit:
|
|
164
|
+
name: mockTokenHTS.name,
|
|
165
|
+
unit: mockTokenHTS.units[0],
|
|
205
166
|
},
|
|
206
167
|
});
|
|
207
168
|
});
|