@ledgerhq/coin-evm 2.28.0-nightly.3 → 2.28.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.eslintrc.js +0 -1
- package/.turbo/turbo-build.log +1 -1
- package/CHANGELOG.md +20 -32
- package/{lib-es/__fixtures__/ethereum-erc20-weth.json → lib/__fixtures__/ethereum-erc20-usd_tether__erc20_.json} +8 -8
- package/lib/__fixtures__/{optimism-erc20-usd_coin.json → scroll_sepolia-erc20-new_token_mock.json} +20 -21
- package/lib/__tests__/fixtures/accounts.fixtures.d.ts +1 -1
- package/lib/__tests__/fixtures/accounts.fixtures.d.ts.map +1 -1
- package/lib/__tests__/fixtures/accounts.fixtures.js +19 -2
- package/lib/__tests__/fixtures/accounts.fixtures.js.map +1 -1
- package/lib/__tests__/fixtures/common.fixtures.d.ts +0 -1
- package/lib/__tests__/fixtures/common.fixtures.d.ts.map +1 -1
- package/lib/__tests__/fixtures/common.fixtures.js +0 -1
- package/lib/__tests__/fixtures/common.fixtures.js.map +1 -1
- package/lib/__tests__/fixtures/prepareTransaction.fixtures.d.ts.map +1 -1
- package/lib/__tests__/fixtures/prepareTransaction.fixtures.js +2 -3
- package/lib/__tests__/fixtures/prepareTransaction.fixtures.js.map +1 -1
- package/lib/__tests__/fixtures/synchronization.fixtures.d.ts +1 -1
- package/lib/__tests__/fixtures/synchronization.fixtures.d.ts.map +1 -1
- package/lib/__tests__/fixtures/synchronization.fixtures.js +18 -3
- package/lib/__tests__/fixtures/synchronization.fixtures.js.map +1 -1
- package/lib/__tests__/fixtures/transaction.fixtures.d.ts +2 -2
- package/lib/__tests__/fixtures/transaction.fixtures.d.ts.map +1 -1
- package/lib/__tests__/fixtures/transaction.fixtures.js +2 -3
- package/lib/__tests__/fixtures/transaction.fixtures.js.map +1 -1
- package/lib/__tests__/unit/accounts.unit.test.js +27 -0
- package/lib/__tests__/unit/accounts.unit.test.js.map +1 -1
- package/lib/__tests__/unit/adapters/etherscan.unit.test.js +7 -72
- package/lib/__tests__/unit/adapters/etherscan.unit.test.js.map +1 -1
- package/lib/__tests__/unit/adapters/ledger.unit.test.js +2 -15
- package/lib/__tests__/unit/adapters/ledger.unit.test.js.map +1 -1
- package/lib/__tests__/unit/api/explorer/etherscan.unit.test.js +0 -8
- package/lib/__tests__/unit/api/explorer/etherscan.unit.test.js.map +1 -1
- package/lib/__tests__/unit/api/explorer/ledger.unit.test.js +0 -12
- package/lib/__tests__/unit/api/explorer/ledger.unit.test.js.map +1 -1
- package/lib/__tests__/unit/broadcast.unit.test.js +1 -3
- package/lib/__tests__/unit/broadcast.unit.test.js.map +1 -1
- package/lib/__tests__/unit/buildOptimisticOperation.unit.test.js +1 -3
- package/lib/__tests__/unit/buildOptimisticOperation.unit.test.js.map +1 -1
- package/lib/__tests__/unit/deviceTransactionConfig.unit.test.d.ts +1 -1
- package/lib/__tests__/unit/deviceTransactionConfig.unit.test.d.ts.map +1 -1
- package/lib/__tests__/unit/deviceTransactionConfig.unit.test.js +0 -1
- package/lib/__tests__/unit/deviceTransactionConfig.unit.test.js.map +1 -1
- package/lib/__tests__/unit/estimateMaxSpendable.unit.test.js +1 -3
- package/lib/__tests__/unit/estimateMaxSpendable.unit.test.js.map +1 -1
- package/lib/__tests__/unit/getTransactionStatus.unit.test.js +1 -3
- package/lib/__tests__/unit/getTransactionStatus.unit.test.js.map +1 -1
- package/lib/__tests__/unit/logic.unit.test.js +18 -22
- package/lib/__tests__/unit/logic.unit.test.js.map +1 -1
- package/lib/__tests__/unit/operation.test.js +2 -6
- package/lib/__tests__/unit/operation.test.js.map +1 -1
- package/lib/__tests__/unit/prepareTransaction.unit.test.js +17 -4
- package/lib/__tests__/unit/prepareTransaction.unit.test.js.map +1 -1
- package/lib/adapters/etherscan.d.ts.map +1 -1
- package/lib/adapters/etherscan.js +2 -2
- package/lib/adapters/etherscan.js.map +1 -1
- package/lib/adapters/ledger.d.ts.map +1 -1
- package/lib/adapters/ledger.js +2 -2
- package/lib/adapters/ledger.js.map +1 -1
- package/lib/api/index.d.ts.map +1 -1
- package/lib/api/index.js +4 -2
- package/lib/api/index.js.map +1 -1
- package/lib/bridge/js.d.ts +1 -2
- package/lib/bridge/js.d.ts.map +1 -1
- package/lib/bridge/js.js +1 -3
- package/lib/bridge/js.js.map +1 -1
- package/lib/bridge/preload.d.ts +0 -1
- package/lib/bridge/preload.d.ts.map +1 -1
- package/lib/bridge/preload.js +1 -10
- package/lib/bridge/preload.js.map +1 -1
- package/lib/deviceTransactionConfig.d.ts.map +1 -1
- package/lib/deviceTransactionConfig.js +2 -2
- package/lib/deviceTransactionConfig.js.map +1 -1
- package/lib/logic/common.d.ts +0 -18
- package/lib/logic/common.d.ts.map +1 -1
- package/lib/logic/common.js +1 -35
- package/lib/logic/common.js.map +1 -1
- package/lib/logic/estimateFees.d.ts +1 -1
- package/lib/logic/estimateFees.d.ts.map +1 -1
- package/lib/logic/estimateFees.js +12 -25
- package/lib/logic/estimateFees.js.map +1 -1
- package/lib/logic/estimateFees.test.js +41 -93
- package/lib/logic/estimateFees.test.js.map +1 -1
- package/lib/logic/index.d.ts +0 -1
- package/lib/logic/index.d.ts.map +1 -1
- package/lib/logic/index.js +0 -1
- package/lib/logic/index.js.map +1 -1
- package/lib/types/transaction.d.ts +0 -9
- package/lib/types/transaction.d.ts.map +1 -1
- package/{lib/__fixtures__/ethereum-erc20-weth.json → lib-es/__fixtures__/ethereum-erc20-usd_tether__erc20_.json} +8 -8
- package/lib-es/__fixtures__/{optimism-erc20-usd_coin.json → scroll_sepolia-erc20-new_token_mock.json} +20 -21
- package/lib-es/__tests__/fixtures/accounts.fixtures.d.ts +1 -1
- package/lib-es/__tests__/fixtures/accounts.fixtures.d.ts.map +1 -1
- package/lib-es/__tests__/fixtures/accounts.fixtures.js +18 -1
- package/lib-es/__tests__/fixtures/accounts.fixtures.js.map +1 -1
- package/lib-es/__tests__/fixtures/common.fixtures.d.ts +0 -1
- package/lib-es/__tests__/fixtures/common.fixtures.d.ts.map +1 -1
- package/lib-es/__tests__/fixtures/common.fixtures.js +0 -1
- package/lib-es/__tests__/fixtures/common.fixtures.js.map +1 -1
- package/lib-es/__tests__/fixtures/prepareTransaction.fixtures.d.ts.map +1 -1
- package/lib-es/__tests__/fixtures/prepareTransaction.fixtures.js +2 -3
- package/lib-es/__tests__/fixtures/prepareTransaction.fixtures.js.map +1 -1
- package/lib-es/__tests__/fixtures/synchronization.fixtures.d.ts +1 -1
- package/lib-es/__tests__/fixtures/synchronization.fixtures.d.ts.map +1 -1
- package/lib-es/__tests__/fixtures/synchronization.fixtures.js +18 -3
- package/lib-es/__tests__/fixtures/synchronization.fixtures.js.map +1 -1
- package/lib-es/__tests__/fixtures/transaction.fixtures.d.ts +2 -2
- package/lib-es/__tests__/fixtures/transaction.fixtures.d.ts.map +1 -1
- package/lib-es/__tests__/fixtures/transaction.fixtures.js +2 -3
- package/lib-es/__tests__/fixtures/transaction.fixtures.js.map +1 -1
- package/lib-es/__tests__/unit/accounts.unit.test.js +27 -0
- package/lib-es/__tests__/unit/accounts.unit.test.js.map +1 -1
- package/lib-es/__tests__/unit/adapters/etherscan.unit.test.js +7 -72
- package/lib-es/__tests__/unit/adapters/etherscan.unit.test.js.map +1 -1
- package/lib-es/__tests__/unit/adapters/ledger.unit.test.js +2 -15
- package/lib-es/__tests__/unit/adapters/ledger.unit.test.js.map +1 -1
- package/lib-es/__tests__/unit/api/explorer/etherscan.unit.test.js +0 -8
- package/lib-es/__tests__/unit/api/explorer/etherscan.unit.test.js.map +1 -1
- package/lib-es/__tests__/unit/api/explorer/ledger.unit.test.js +0 -12
- package/lib-es/__tests__/unit/api/explorer/ledger.unit.test.js.map +1 -1
- package/lib-es/__tests__/unit/broadcast.unit.test.js +2 -4
- package/lib-es/__tests__/unit/broadcast.unit.test.js.map +1 -1
- package/lib-es/__tests__/unit/buildOptimisticOperation.unit.test.js +2 -4
- package/lib-es/__tests__/unit/buildOptimisticOperation.unit.test.js.map +1 -1
- package/lib-es/__tests__/unit/deviceTransactionConfig.unit.test.d.ts +1 -1
- package/lib-es/__tests__/unit/deviceTransactionConfig.unit.test.d.ts.map +1 -1
- package/lib-es/__tests__/unit/deviceTransactionConfig.unit.test.js +0 -1
- package/lib-es/__tests__/unit/deviceTransactionConfig.unit.test.js.map +1 -1
- package/lib-es/__tests__/unit/estimateMaxSpendable.unit.test.js +2 -4
- package/lib-es/__tests__/unit/estimateMaxSpendable.unit.test.js.map +1 -1
- package/lib-es/__tests__/unit/getTransactionStatus.unit.test.js +2 -4
- package/lib-es/__tests__/unit/getTransactionStatus.unit.test.js.map +1 -1
- package/lib-es/__tests__/unit/logic.unit.test.js +19 -23
- package/lib-es/__tests__/unit/logic.unit.test.js.map +1 -1
- package/lib-es/__tests__/unit/operation.test.js +3 -7
- package/lib-es/__tests__/unit/operation.test.js.map +1 -1
- package/lib-es/__tests__/unit/prepareTransaction.unit.test.js +17 -4
- package/lib-es/__tests__/unit/prepareTransaction.unit.test.js.map +1 -1
- package/lib-es/adapters/etherscan.d.ts.map +1 -1
- package/lib-es/adapters/etherscan.js +2 -2
- package/lib-es/adapters/etherscan.js.map +1 -1
- package/lib-es/adapters/ledger.d.ts.map +1 -1
- package/lib-es/adapters/ledger.js +2 -2
- package/lib-es/adapters/ledger.js.map +1 -1
- package/lib-es/api/index.d.ts.map +1 -1
- package/lib-es/api/index.js +5 -3
- package/lib-es/api/index.js.map +1 -1
- package/lib-es/bridge/js.d.ts +1 -2
- package/lib-es/bridge/js.d.ts.map +1 -1
- package/lib-es/bridge/js.js +1 -3
- package/lib-es/bridge/js.js.map +1 -1
- package/lib-es/bridge/preload.d.ts +0 -1
- package/lib-es/bridge/preload.d.ts.map +1 -1
- package/lib-es/bridge/preload.js +0 -8
- package/lib-es/bridge/preload.js.map +1 -1
- package/lib-es/deviceTransactionConfig.d.ts.map +1 -1
- package/lib-es/deviceTransactionConfig.js +2 -2
- package/lib-es/deviceTransactionConfig.js.map +1 -1
- package/lib-es/logic/common.d.ts +0 -18
- package/lib-es/logic/common.d.ts.map +1 -1
- package/lib-es/logic/common.js +0 -30
- package/lib-es/logic/common.js.map +1 -1
- package/lib-es/logic/estimateFees.d.ts +1 -1
- package/lib-es/logic/estimateFees.d.ts.map +1 -1
- package/lib-es/logic/estimateFees.js +12 -25
- package/lib-es/logic/estimateFees.js.map +1 -1
- package/lib-es/logic/estimateFees.test.js +41 -93
- package/lib-es/logic/estimateFees.test.js.map +1 -1
- package/lib-es/logic/index.d.ts +0 -1
- package/lib-es/logic/index.d.ts.map +1 -1
- package/lib-es/logic/index.js +0 -1
- package/lib-es/logic/index.js.map +1 -1
- package/lib-es/types/transaction.d.ts +0 -9
- package/lib-es/types/transaction.d.ts.map +1 -1
- package/package.json +13 -13
- package/src/__tests__/fixtures/accounts.fixtures.ts +23 -1
- package/src/__tests__/fixtures/common.fixtures.ts +0 -1
- package/src/__tests__/fixtures/prepareTransaction.fixtures.ts +4 -4
- package/src/__tests__/fixtures/synchronization.fixtures.ts +20 -3
- package/src/__tests__/fixtures/transaction.fixtures.ts +3 -4
- package/src/__tests__/unit/accounts.unit.test.ts +36 -0
- package/src/__tests__/unit/adapters/etherscan.unit.test.ts +7 -87
- package/src/__tests__/unit/adapters/ledger.unit.test.ts +2 -20
- package/src/__tests__/unit/api/explorer/etherscan.unit.test.ts +0 -12
- package/src/__tests__/unit/api/explorer/ledger.unit.test.ts +0 -16
- package/src/__tests__/unit/broadcast.unit.test.ts +3 -5
- package/src/__tests__/unit/buildOptimisticOperation.unit.test.ts +2 -5
- package/src/__tests__/unit/deviceTransactionConfig.unit.test.ts +0 -1
- package/src/__tests__/unit/estimateMaxSpendable.unit.test.ts +3 -5
- package/src/__tests__/unit/getTransactionStatus.unit.test.ts +2 -5
- package/src/__tests__/unit/logic.unit.test.ts +29 -41
- package/src/__tests__/unit/operation.test.ts +5 -9
- package/src/__tests__/unit/prepareTransaction.unit.test.ts +18 -4
- package/src/adapters/etherscan.ts +2 -5
- package/src/adapters/ledger.ts +2 -5
- package/src/api/index.ts +5 -4
- package/src/bridge/js.ts +0 -4
- package/src/bridge/preload.ts +0 -8
- package/src/deviceTransactionConfig.ts +2 -3
- package/src/logic/common.ts +0 -52
- package/src/logic/estimateFees.test.ts +57 -98
- package/src/logic/estimateFees.ts +18 -28
- package/src/logic/index.ts +0 -1
- package/src/types/transaction.ts +0 -12
- package/lib/__fixtures__/cardano-native-8654e8b350e298c80d2451beb5ed80fc9eee9f38ce6b039fb8706bc34c4f4253544552.json +0 -52
- package/lib/__fixtures__/ethereum-erc20-usd__coin-0x02b972f304dc24c9bc362e6435c4ad654241f9af916689a4790145c9bcbdf4cf-IN-i0.json +0 -20
- package/lib/__fixtures__/ethereum-erc20-usd__coin-0x02b972f304dc24c9bc362e6435c4ad654241f9af916689a4790145c9bcbdf4cf-OUT-i0.json +0 -19
- package/lib/__tests__/fixtures/cryptoAssetsStore.fixtures.d.ts +0 -2
- package/lib/__tests__/fixtures/cryptoAssetsStore.fixtures.d.ts.map +0 -1
- package/lib/__tests__/fixtures/cryptoAssetsStore.fixtures.js +0 -44
- package/lib/__tests__/fixtures/cryptoAssetsStore.fixtures.js.map +0 -1
- package/lib/cryptoAssetsStore.d.ts +0 -5
- package/lib/cryptoAssetsStore.d.ts.map +0 -1
- package/lib/cryptoAssetsStore.js +0 -17
- package/lib/cryptoAssetsStore.js.map +0 -1
- package/lib/cryptoAssetsStore.test.d.ts +0 -2
- package/lib/cryptoAssetsStore.test.d.ts.map +0 -1
- package/lib/cryptoAssetsStore.test.js +0 -15
- package/lib/cryptoAssetsStore.test.js.map +0 -1
- package/lib/logic/validateIntent.d.ts +0 -4
- package/lib/logic/validateIntent.d.ts.map +0 -1
- package/lib/logic/validateIntent.js +0 -192
- package/lib/logic/validateIntent.js.map +0 -1
- package/lib/logic/validateIntent.test.d.ts +0 -2
- package/lib/logic/validateIntent.test.d.ts.map +0 -1
- package/lib/logic/validateIntent.test.js +0 -485
- package/lib/logic/validateIntent.test.js.map +0 -1
- package/lib-es/__fixtures__/cardano-native-8654e8b350e298c80d2451beb5ed80fc9eee9f38ce6b039fb8706bc34c4f4253544552.json +0 -52
- package/lib-es/__fixtures__/ethereum-erc20-usd__coin-0x02b972f304dc24c9bc362e6435c4ad654241f9af916689a4790145c9bcbdf4cf-IN-i0.json +0 -20
- package/lib-es/__fixtures__/ethereum-erc20-usd__coin-0x02b972f304dc24c9bc362e6435c4ad654241f9af916689a4790145c9bcbdf4cf-OUT-i0.json +0 -19
- package/lib-es/__tests__/fixtures/cryptoAssetsStore.fixtures.d.ts +0 -2
- package/lib-es/__tests__/fixtures/cryptoAssetsStore.fixtures.d.ts.map +0 -1
- package/lib-es/__tests__/fixtures/cryptoAssetsStore.fixtures.js +0 -19
- package/lib-es/__tests__/fixtures/cryptoAssetsStore.fixtures.js.map +0 -1
- package/lib-es/cryptoAssetsStore.d.ts +0 -5
- package/lib-es/cryptoAssetsStore.d.ts.map +0 -1
- package/lib-es/cryptoAssetsStore.js +0 -12
- package/lib-es/cryptoAssetsStore.js.map +0 -1
- package/lib-es/cryptoAssetsStore.test.d.ts +0 -2
- package/lib-es/cryptoAssetsStore.test.d.ts.map +0 -1
- package/lib-es/cryptoAssetsStore.test.js +0 -13
- package/lib-es/cryptoAssetsStore.test.js.map +0 -1
- package/lib-es/logic/validateIntent.d.ts +0 -4
- package/lib-es/logic/validateIntent.d.ts.map +0 -1
- package/lib-es/logic/validateIntent.js +0 -185
- package/lib-es/logic/validateIntent.js.map +0 -1
- package/lib-es/logic/validateIntent.test.d.ts +0 -2
- package/lib-es/logic/validateIntent.test.d.ts.map +0 -1
- package/lib-es/logic/validateIntent.test.js +0 -480
- package/lib-es/logic/validateIntent.test.js.map +0 -1
- package/src/__fixtures__/cardano-native-8654e8b350e298c80d2451beb5ed80fc9eee9f38ce6b039fb8706bc34c4f4253544552.json +0 -52
- package/src/__fixtures__/ethereum-erc20-usd__coin-0x02b972f304dc24c9bc362e6435c4ad654241f9af916689a4790145c9bcbdf4cf-IN-i0.json +0 -20
- package/src/__fixtures__/ethereum-erc20-usd__coin-0x02b972f304dc24c9bc362e6435c4ad654241f9af916689a4790145c9bcbdf4cf-OUT-i0.json +0 -19
- package/src/__fixtures__/ethereum-erc20-usd__coin-0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48.json +0 -73
- package/src/__fixtures__/ethereum-erc20-weth.json +0 -73
- package/src/__fixtures__/optimism-erc20-usd_coin.json +0 -69
- package/src/__tests__/fixtures/cryptoAssetsStore.fixtures.ts +0 -24
- package/src/cryptoAssetsStore.test.ts +0 -19
- package/src/cryptoAssetsStore.ts +0 -16
- package/src/logic/validateIntent.test.ts +0 -659
- package/src/logic/validateIntent.ts +0 -274
|
@@ -6,6 +6,7 @@ import {
|
|
|
6
6
|
} from "@ledgerhq/coin-framework/nft/nftOperationId";
|
|
7
7
|
import { Operation, OperationType } from "@ledgerhq/types-live";
|
|
8
8
|
import { encodeNftId } from "@ledgerhq/coin-framework/nft/nftId";
|
|
9
|
+
import { findTokenByAddressInCurrency } from "@ledgerhq/cryptoassets";
|
|
9
10
|
import { decodeAccountId, encodeTokenAccountId } from "@ledgerhq/coin-framework/account/index";
|
|
10
11
|
import { encodeOperationId, encodeSubOperationId } from "@ledgerhq/coin-framework/operation";
|
|
11
12
|
import {
|
|
@@ -16,7 +17,6 @@ import {
|
|
|
16
17
|
EtherscanInternalTransaction,
|
|
17
18
|
} from "../types";
|
|
18
19
|
import { safeEncodeEIP55 } from "../utils";
|
|
19
|
-
import { getCryptoAssetsStore } from "../cryptoAssetsStore";
|
|
20
20
|
|
|
21
21
|
/**
|
|
22
22
|
* Adapter to convert an Etherscan operation into Ledger Live Operations.
|
|
@@ -82,10 +82,7 @@ export const etherscanERC20EventToOperations = (
|
|
|
82
82
|
index = 0,
|
|
83
83
|
): Operation[] => {
|
|
84
84
|
const { currencyId, xpubOrAddress: address } = decodeAccountId(accountId);
|
|
85
|
-
const tokenCurrency =
|
|
86
|
-
event.contractAddress,
|
|
87
|
-
currencyId,
|
|
88
|
-
);
|
|
85
|
+
const tokenCurrency = findTokenByAddressInCurrency(event.contractAddress, currencyId);
|
|
89
86
|
if (!tokenCurrency) return [];
|
|
90
87
|
|
|
91
88
|
const tokenAccountId = encodeTokenAccountId(accountId, tokenCurrency);
|
package/src/adapters/ledger.ts
CHANGED
|
@@ -6,6 +6,7 @@ import {
|
|
|
6
6
|
} from "@ledgerhq/coin-framework/nft/nftOperationId";
|
|
7
7
|
import { Operation, OperationType } from "@ledgerhq/types-live";
|
|
8
8
|
import { encodeNftId } from "@ledgerhq/coin-framework/nft/nftId";
|
|
9
|
+
import { findTokenByAddressInCurrency } from "@ledgerhq/cryptoassets";
|
|
9
10
|
import { decodeAccountId, encodeTokenAccountId } from "@ledgerhq/coin-framework/account/index";
|
|
10
11
|
import { encodeOperationId, encodeSubOperationId } from "@ledgerhq/coin-framework/operation";
|
|
11
12
|
import {
|
|
@@ -16,7 +17,6 @@ import {
|
|
|
16
17
|
LedgerExplorerInternalTransaction,
|
|
17
18
|
} from "../types";
|
|
18
19
|
import { safeEncodeEIP55 } from "../utils";
|
|
19
|
-
import { getCryptoAssetsStore } from "../cryptoAssetsStore";
|
|
20
20
|
|
|
21
21
|
/**
|
|
22
22
|
* Adapter to convert a Ledger Explorer operation
|
|
@@ -82,10 +82,7 @@ export const ledgerERC20EventToOperations = (
|
|
|
82
82
|
const { accountId, hash, fee, blockHeight, blockHash, transactionSequenceNumber, date } =
|
|
83
83
|
coinOperation;
|
|
84
84
|
const { currencyId, xpubOrAddress: address } = decodeAccountId(accountId);
|
|
85
|
-
const tokenCurrency =
|
|
86
|
-
event.contract,
|
|
87
|
-
currencyId,
|
|
88
|
-
);
|
|
85
|
+
const tokenCurrency = findTokenByAddressInCurrency(event.contract, currencyId);
|
|
89
86
|
if (!tokenCurrency) return [];
|
|
90
87
|
|
|
91
88
|
const tokenAccountId = encodeTokenAccountId(accountId, tokenCurrency);
|
package/src/api/index.ts
CHANGED
|
@@ -27,7 +27,6 @@ import {
|
|
|
27
27
|
listOperations,
|
|
28
28
|
getBalance,
|
|
29
29
|
getSequence,
|
|
30
|
-
validateIntent,
|
|
31
30
|
} from "../logic/index";
|
|
32
31
|
|
|
33
32
|
export function createApi(config: EvmConfig, currencyId: CryptoCurrencyId): Api {
|
|
@@ -44,7 +43,8 @@ export function createApi(config: EvmConfig, currencyId: CryptoCurrencyId): Api
|
|
|
44
43
|
): Promise<string> => craftTransaction(currency, { transactionIntent, customFees }),
|
|
45
44
|
estimateFees: (
|
|
46
45
|
transactionIntent: TransactionIntent<MemoNotSupported>,
|
|
47
|
-
|
|
46
|
+
customFees?: FeeEstimation,
|
|
47
|
+
): Promise<FeeEstimation> => estimateFees(currency, transactionIntent, customFees),
|
|
48
48
|
getBalance: (address: string): Promise<Balance[]> => getBalance(currency, address),
|
|
49
49
|
lastBlock: (): Promise<BlockInfo> => lastBlock(currency),
|
|
50
50
|
listOperations: (
|
|
@@ -65,7 +65,8 @@ export function createApi(config: EvmConfig, currencyId: CryptoCurrencyId): Api
|
|
|
65
65
|
throw new Error("getRewards is not supported");
|
|
66
66
|
},
|
|
67
67
|
getSequence: (address: string): Promise<number> => getSequence(currency, address),
|
|
68
|
-
validateIntent
|
|
69
|
-
validateIntent
|
|
68
|
+
validateIntent(_intent: TransactionIntent): Promise<TransactionValidation> {
|
|
69
|
+
throw new Error("validateIntent is not supported");
|
|
70
|
+
},
|
|
70
71
|
};
|
|
71
72
|
}
|
package/src/bridge/js.ts
CHANGED
|
@@ -8,12 +8,10 @@ import {
|
|
|
8
8
|
import { SignerContext } from "@ledgerhq/coin-framework/signer";
|
|
9
9
|
import type { AccountBridge, Bridge, CurrencyBridge } from "@ledgerhq/types-live";
|
|
10
10
|
import getAddressWrapper from "@ledgerhq/coin-framework/bridge/getAddressWrapper";
|
|
11
|
-
import type { CryptoAssetsStoreGetter } from "@ledgerhq/types-live";
|
|
12
11
|
import type { Transaction as EvmTransaction } from "../types/index";
|
|
13
12
|
import { setCoinConfig, type CoinConfig } from "../config";
|
|
14
13
|
import type { EvmSigner } from "../types/signer";
|
|
15
14
|
import resolver from "../hw-getAddress";
|
|
16
|
-
import { setCryptoAssetsStoreGetter } from "../cryptoAssetsStore";
|
|
17
15
|
import { estimateMaxSpendable } from "./estimateMaxSpendable";
|
|
18
16
|
import { getTransactionStatus } from "./getTransactionStatus";
|
|
19
17
|
import { getAccountShape, sync } from "./synchronization";
|
|
@@ -68,10 +66,8 @@ export function buildAccountBridge(
|
|
|
68
66
|
export function createBridges(
|
|
69
67
|
signerContext: SignerContext<EvmSigner>,
|
|
70
68
|
coinConfig: CoinConfig,
|
|
71
|
-
cryptoAssetsStoreGetter: CryptoAssetsStoreGetter,
|
|
72
69
|
): Bridge<EvmTransaction> {
|
|
73
70
|
setCoinConfig(coinConfig);
|
|
74
|
-
setCryptoAssetsStoreGetter(cryptoAssetsStoreGetter);
|
|
75
71
|
|
|
76
72
|
return {
|
|
77
73
|
currencyBridge: buildCurrencyBridge(signerContext),
|
package/src/bridge/preload.ts
CHANGED
|
@@ -10,11 +10,6 @@ import { CryptoCurrency } from "@ledgerhq/types-cryptoassets";
|
|
|
10
10
|
import { fetchTokensFromCALService } from "@ledgerhq/cryptoassets/crypto-assets-importer/fetch/index";
|
|
11
11
|
import { getCALHash, setCALHash } from "../logic";
|
|
12
12
|
|
|
13
|
-
let shouldSkipTokenLoading = false;
|
|
14
|
-
export function setShouldSkipTokenLoading(skip: boolean): void {
|
|
15
|
-
shouldSkipTokenLoading = skip;
|
|
16
|
-
}
|
|
17
|
-
|
|
18
13
|
export const fetchERC20Tokens: (
|
|
19
14
|
currency: CryptoCurrency,
|
|
20
15
|
) => Promise<ERC20Token[] | null> = async currency => {
|
|
@@ -83,8 +78,6 @@ export const fetchERC20Tokens: (
|
|
|
83
78
|
};
|
|
84
79
|
|
|
85
80
|
export async function preload(currency: CryptoCurrency): Promise<ERC20Token[] | undefined> {
|
|
86
|
-
if (shouldSkipTokenLoading) return;
|
|
87
|
-
|
|
88
81
|
const erc20 = await fetchERC20Tokens(currency);
|
|
89
82
|
if (!erc20) return;
|
|
90
83
|
|
|
@@ -94,7 +87,6 @@ export async function preload(currency: CryptoCurrency): Promise<ERC20Token[] |
|
|
|
94
87
|
}
|
|
95
88
|
|
|
96
89
|
export function hydrate(value: unknown, currency: CryptoCurrency): void {
|
|
97
|
-
if (shouldSkipTokenLoading) return;
|
|
98
90
|
if (!Array.isArray(value)) {
|
|
99
91
|
const { chainId } = currency.ethereumLikeInfo || {};
|
|
100
92
|
const tokens = tokensByChainId[chainId as keyof typeof tokensByChainId] || [];
|
|
@@ -6,12 +6,12 @@ import {
|
|
|
6
6
|
ERC1155_CLEAR_SIGNED_SELECTORS,
|
|
7
7
|
} from "@ledgerhq/evm-tools/selectors/index";
|
|
8
8
|
import { Account, AccountLike } from "@ledgerhq/types-live";
|
|
9
|
+
import { findTokenByAddress } from "@ledgerhq/cryptoassets/tokens";
|
|
9
10
|
import { validateDomain } from "@ledgerhq/domain-service/utils/index";
|
|
10
11
|
import { getMainAccount } from "@ledgerhq/coin-framework/account/index";
|
|
11
12
|
import { formatCurrencyUnit } from "@ledgerhq/coin-framework/currencies/index";
|
|
12
13
|
import type { CommonDeviceTransactionField } from "@ledgerhq/coin-framework/transaction/common";
|
|
13
14
|
import { Transaction as EvmTransaction, TransactionStatus } from "./types";
|
|
14
|
-
import { getCryptoAssetsStore } from "./cryptoAssetsStore";
|
|
15
15
|
|
|
16
16
|
type DeviceTransactionField = CommonDeviceTransactionField;
|
|
17
17
|
|
|
@@ -29,8 +29,7 @@ const inferDeviceTransactionConfigWalletApi = (
|
|
|
29
29
|
const knownNft = mainAccount.nfts?.find(
|
|
30
30
|
nft => nft.contract.toLowerCase() === transaction.recipient.toLowerCase(),
|
|
31
31
|
);
|
|
32
|
-
|
|
33
|
-
const token = getCryptoAssetsStore().findTokenByAddress(transaction.recipient);
|
|
32
|
+
const token = findTokenByAddress(transaction.recipient);
|
|
34
33
|
|
|
35
34
|
// ERC20 fields
|
|
36
35
|
if (token && Object.values<string>(ERC20_CLEAR_SIGNED_SELECTORS).includes(selector)) {
|
package/src/logic/common.ts
CHANGED
|
@@ -1,58 +1,6 @@
|
|
|
1
1
|
import { ethers } from "ethers";
|
|
2
2
|
import { TransactionTypes } from "ethers/lib/utils";
|
|
3
|
-
import { FeeEstimation } from "@ledgerhq/coin-framework/api/types";
|
|
4
3
|
import ERC20ABI from "../abis/erc20.abi.json";
|
|
5
|
-
import { ApiFeeData, ApiGasOptions } from "../types";
|
|
6
|
-
|
|
7
|
-
export function isApiGasOptions(options: unknown): options is ApiGasOptions {
|
|
8
|
-
if (!options || typeof options !== "object") return false;
|
|
9
|
-
|
|
10
|
-
return (
|
|
11
|
-
"slow" in options &&
|
|
12
|
-
isApiFeeData(options.slow) &&
|
|
13
|
-
"medium" in options &&
|
|
14
|
-
isApiFeeData(options.medium) &&
|
|
15
|
-
"fast" in options &&
|
|
16
|
-
isApiFeeData(options.fast)
|
|
17
|
-
);
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
export function isApiFeeData(fees: unknown): fees is ApiFeeData {
|
|
21
|
-
if (!fees || typeof fees !== "object") return false;
|
|
22
|
-
|
|
23
|
-
const isBigIntOrNull = (value: unknown): boolean => value === null || typeof value === "bigint";
|
|
24
|
-
|
|
25
|
-
return (
|
|
26
|
-
"maxFeePerGas" in fees &&
|
|
27
|
-
isBigIntOrNull(fees.maxFeePerGas) &&
|
|
28
|
-
"maxPriorityFeePerGas" in fees &&
|
|
29
|
-
isBigIntOrNull(fees.maxPriorityFeePerGas) &&
|
|
30
|
-
"gasPrice" in fees &&
|
|
31
|
-
isBigIntOrNull(fees.gasPrice) &&
|
|
32
|
-
"nextBaseFee" in fees &&
|
|
33
|
-
isBigIntOrNull(fees.nextBaseFee)
|
|
34
|
-
);
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
type LegacyFeeEstimation = FeeEstimation & { parameters: { gasPrice: bigint } };
|
|
38
|
-
type Eip1559FeeEstimation = FeeEstimation & {
|
|
39
|
-
parameters: { maxFeePerGas: bigint; maxPriorityFeePerGas: bigint };
|
|
40
|
-
};
|
|
41
|
-
|
|
42
|
-
export function isLegacyFeeEstimation(
|
|
43
|
-
estimation: FeeEstimation,
|
|
44
|
-
): estimation is LegacyFeeEstimation {
|
|
45
|
-
return typeof estimation.parameters?.gasPrice === "bigint";
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
export function isEip1559FeeEstimation(
|
|
49
|
-
estimation: FeeEstimation,
|
|
50
|
-
): estimation is Eip1559FeeEstimation {
|
|
51
|
-
return (
|
|
52
|
-
typeof estimation.parameters?.maxFeePerGas === "bigint" &&
|
|
53
|
-
typeof estimation.parameters?.maxPriorityFeePerGas === "bigint"
|
|
54
|
-
);
|
|
55
|
-
}
|
|
56
4
|
|
|
57
5
|
export function getTransactionType(intentType: string): TransactionTypes {
|
|
58
6
|
if (!["send-legacy", "send-eip1559"].includes(intentType)) {
|
|
@@ -7,8 +7,6 @@ import type {
|
|
|
7
7
|
} from "@ledgerhq/coin-framework/api/index";
|
|
8
8
|
import { getNodeApi } from "../network/node";
|
|
9
9
|
import { FeeData } from "../types";
|
|
10
|
-
import ledgerGasTracker from "../network/gasTracker/ledger";
|
|
11
|
-
import { EvmCoinConfig, setCoinConfig } from "../config";
|
|
12
10
|
import { estimateFees } from "./estimateFees";
|
|
13
11
|
|
|
14
12
|
jest.mock("../network/node", () => ({ getNodeApi: jest.fn() }));
|
|
@@ -48,39 +46,9 @@ describe("estimateFees", () => {
|
|
|
48
46
|
mockNodeApi.getGasEstimation.mockResolvedValue(mockGasLimit);
|
|
49
47
|
mockNodeApi.getFeeData.mockResolvedValue(mockFeeData);
|
|
50
48
|
jest.mocked(getNodeApi).mockReturnValue(mockNodeApi as any);
|
|
51
|
-
|
|
52
|
-
setCoinConfig(
|
|
53
|
-
() =>
|
|
54
|
-
({
|
|
55
|
-
info: {
|
|
56
|
-
gasTracker: { type: "ledger", explorerId: "eth" },
|
|
57
|
-
},
|
|
58
|
-
}) as unknown as EvmCoinConfig,
|
|
59
|
-
);
|
|
60
49
|
});
|
|
61
50
|
|
|
62
51
|
it("should estimate fees for native asset", async () => {
|
|
63
|
-
jest.spyOn(ledgerGasTracker, "getGasOptions").mockResolvedValue({
|
|
64
|
-
fast: {
|
|
65
|
-
maxFeePerGas: new BigNumber("30000000000"),
|
|
66
|
-
maxPriorityFeePerGas: new BigNumber("3000000000"),
|
|
67
|
-
gasPrice: new BigNumber("30000000000"),
|
|
68
|
-
nextBaseFee: null,
|
|
69
|
-
},
|
|
70
|
-
medium: {
|
|
71
|
-
maxFeePerGas: new BigNumber("20000000000"),
|
|
72
|
-
maxPriorityFeePerGas: new BigNumber("2000000000"),
|
|
73
|
-
gasPrice: new BigNumber("20000000000"),
|
|
74
|
-
nextBaseFee: null,
|
|
75
|
-
},
|
|
76
|
-
slow: {
|
|
77
|
-
maxFeePerGas: new BigNumber("10000000000"),
|
|
78
|
-
maxPriorityFeePerGas: new BigNumber("1000000000"),
|
|
79
|
-
gasPrice: new BigNumber("10000000000"),
|
|
80
|
-
nextBaseFee: null,
|
|
81
|
-
},
|
|
82
|
-
});
|
|
83
|
-
|
|
84
52
|
const result = await estimateFees(mockCurrency, mockIntent);
|
|
85
53
|
|
|
86
54
|
expect(mockNodeApi.getFeeData).toHaveBeenCalledWith(mockCurrency, {
|
|
@@ -88,33 +56,12 @@ describe("estimateFees", () => {
|
|
|
88
56
|
type: 0,
|
|
89
57
|
});
|
|
90
58
|
expect(result).toEqual({
|
|
91
|
-
value:
|
|
59
|
+
value: BigInt(mockGasLimit.multipliedBy(mockFeeData.gasPrice!).toFixed()),
|
|
92
60
|
parameters: {
|
|
93
61
|
gasPrice: 20000000000n,
|
|
94
62
|
maxFeePerGas: 20000000000n,
|
|
95
63
|
maxPriorityFeePerGas: 2000000000n,
|
|
96
64
|
nextBaseFee: null,
|
|
97
|
-
gasLimit: 21000n,
|
|
98
|
-
gasOptions: {
|
|
99
|
-
fast: {
|
|
100
|
-
maxFeePerGas: 30000000000n,
|
|
101
|
-
maxPriorityFeePerGas: 3000000000n,
|
|
102
|
-
gasPrice: 30000000000n,
|
|
103
|
-
nextBaseFee: null,
|
|
104
|
-
},
|
|
105
|
-
medium: {
|
|
106
|
-
gasPrice: 20000000000n,
|
|
107
|
-
maxFeePerGas: 20000000000n,
|
|
108
|
-
maxPriorityFeePerGas: 2000000000n,
|
|
109
|
-
nextBaseFee: null,
|
|
110
|
-
},
|
|
111
|
-
slow: {
|
|
112
|
-
gasPrice: 10000000000n,
|
|
113
|
-
maxFeePerGas: 10000000000n,
|
|
114
|
-
maxPriorityFeePerGas: 1000000000n,
|
|
115
|
-
nextBaseFee: null,
|
|
116
|
-
},
|
|
117
|
-
},
|
|
118
65
|
},
|
|
119
66
|
});
|
|
120
67
|
});
|
|
@@ -128,33 +75,12 @@ describe("estimateFees", () => {
|
|
|
128
75
|
type: 0,
|
|
129
76
|
});
|
|
130
77
|
expect(result).toEqual({
|
|
131
|
-
value:
|
|
78
|
+
value: BigInt(mockGasLimit.multipliedBy(mockFeeData.gasPrice!).toFixed()),
|
|
132
79
|
parameters: {
|
|
133
80
|
gasPrice: 20000000000n,
|
|
134
81
|
maxFeePerGas: 20000000000n,
|
|
135
82
|
maxPriorityFeePerGas: 2000000000n,
|
|
136
83
|
nextBaseFee: null,
|
|
137
|
-
gasLimit: 21000n,
|
|
138
|
-
gasOptions: {
|
|
139
|
-
fast: {
|
|
140
|
-
maxFeePerGas: 30000000000n,
|
|
141
|
-
maxPriorityFeePerGas: 3000000000n,
|
|
142
|
-
gasPrice: 30000000000n,
|
|
143
|
-
nextBaseFee: null,
|
|
144
|
-
},
|
|
145
|
-
medium: {
|
|
146
|
-
gasPrice: 20000000000n,
|
|
147
|
-
maxFeePerGas: 20000000000n,
|
|
148
|
-
maxPriorityFeePerGas: 2000000000n,
|
|
149
|
-
nextBaseFee: null,
|
|
150
|
-
},
|
|
151
|
-
slow: {
|
|
152
|
-
gasPrice: 10000000000n,
|
|
153
|
-
maxFeePerGas: 10000000000n,
|
|
154
|
-
maxPriorityFeePerGas: 1000000000n,
|
|
155
|
-
nextBaseFee: null,
|
|
156
|
-
},
|
|
157
|
-
},
|
|
158
84
|
},
|
|
159
85
|
});
|
|
160
86
|
});
|
|
@@ -164,34 +90,67 @@ describe("estimateFees", () => {
|
|
|
164
90
|
|
|
165
91
|
const result = await estimateFees(mockCurrency, mockIntent);
|
|
166
92
|
expect(result).toEqual({
|
|
167
|
-
value:
|
|
93
|
+
value: BigInt(0),
|
|
168
94
|
parameters: {
|
|
169
95
|
gasPrice: null,
|
|
170
96
|
maxFeePerGas: 20000000000n,
|
|
171
97
|
maxPriorityFeePerGas: 2000000000n,
|
|
172
98
|
nextBaseFee: null,
|
|
173
|
-
gasLimit: 21000n,
|
|
174
|
-
gasOptions: {
|
|
175
|
-
fast: {
|
|
176
|
-
maxFeePerGas: 30000000000n,
|
|
177
|
-
maxPriorityFeePerGas: 3000000000n,
|
|
178
|
-
gasPrice: 30000000000n,
|
|
179
|
-
nextBaseFee: null,
|
|
180
|
-
},
|
|
181
|
-
medium: {
|
|
182
|
-
gasPrice: 20000000000n,
|
|
183
|
-
maxFeePerGas: 20000000000n,
|
|
184
|
-
maxPriorityFeePerGas: 2000000000n,
|
|
185
|
-
nextBaseFee: null,
|
|
186
|
-
},
|
|
187
|
-
slow: {
|
|
188
|
-
gasPrice: 10000000000n,
|
|
189
|
-
maxFeePerGas: 10000000000n,
|
|
190
|
-
maxPriorityFeePerGas: 1000000000n,
|
|
191
|
-
nextBaseFee: null,
|
|
192
|
-
},
|
|
193
|
-
},
|
|
194
99
|
},
|
|
195
100
|
});
|
|
196
101
|
});
|
|
102
|
+
|
|
103
|
+
it.each([
|
|
104
|
+
[
|
|
105
|
+
"legacy",
|
|
106
|
+
{
|
|
107
|
+
value: 8n,
|
|
108
|
+
parameters: {
|
|
109
|
+
gasPrice: 5n,
|
|
110
|
+
},
|
|
111
|
+
},
|
|
112
|
+
],
|
|
113
|
+
[
|
|
114
|
+
"eip1559",
|
|
115
|
+
{
|
|
116
|
+
value: 8n,
|
|
117
|
+
parameters: {
|
|
118
|
+
maxFeePerGas: 2n,
|
|
119
|
+
maxPriorityFeePerGas: 3n,
|
|
120
|
+
},
|
|
121
|
+
},
|
|
122
|
+
],
|
|
123
|
+
])("uses the given fees for a %s transaction type", async (type, customFees) => {
|
|
124
|
+
const getFeeData = jest.spyOn(mockNodeApi, "getFeeData");
|
|
125
|
+
const getGasEstimation = jest.spyOn(mockNodeApi, "getGasEstimation");
|
|
126
|
+
|
|
127
|
+
expect(
|
|
128
|
+
await estimateFees(
|
|
129
|
+
{} as CryptoCurrency,
|
|
130
|
+
{ type: `send-${type}` } as unknown as TransactionIntent,
|
|
131
|
+
customFees,
|
|
132
|
+
),
|
|
133
|
+
).toEqual(customFees);
|
|
134
|
+
expect(getFeeData).not.toHaveBeenCalled();
|
|
135
|
+
expect(getGasEstimation).not.toHaveBeenCalled();
|
|
136
|
+
});
|
|
137
|
+
|
|
138
|
+
it("ignores malformed or irrelevant custom fees", async () => {
|
|
139
|
+
const getFeeData = jest.spyOn(mockNodeApi, "getFeeData");
|
|
140
|
+
const getGasEstimation = jest.spyOn(mockNodeApi, "getGasEstimation");
|
|
141
|
+
|
|
142
|
+
expect(
|
|
143
|
+
await estimateFees(
|
|
144
|
+
{} as CryptoCurrency,
|
|
145
|
+
{
|
|
146
|
+
type: "send-eip1559",
|
|
147
|
+
amount: 3n,
|
|
148
|
+
asset: { type: "native" },
|
|
149
|
+
} as unknown as TransactionIntent,
|
|
150
|
+
{ value: 8n, parameters: { gasPrice: 5n } },
|
|
151
|
+
),
|
|
152
|
+
).not.toEqual({ value: 8n, parameters: { gasPrice: 5n } });
|
|
153
|
+
expect(getFeeData).toHaveBeenCalled();
|
|
154
|
+
expect(getGasEstimation).toHaveBeenCalled();
|
|
155
|
+
});
|
|
197
156
|
});
|
|
@@ -7,37 +7,29 @@ import type {
|
|
|
7
7
|
} from "@ledgerhq/coin-framework/api/index";
|
|
8
8
|
import { TransactionTypes } from "ethers/lib/utils";
|
|
9
9
|
import { getNodeApi } from "../network/node";
|
|
10
|
-
import {
|
|
11
|
-
import { getGasTracker } from "../network/gasTracker";
|
|
10
|
+
import { isNative } from "../types";
|
|
12
11
|
import { getErc20Data, getTransactionType } from "./common";
|
|
13
12
|
|
|
14
|
-
function toApiFeeData(feeData: FeeData): ApiFeeData {
|
|
15
|
-
return {
|
|
16
|
-
gasPrice: feeData.gasPrice && BigInt(feeData.gasPrice.toFixed()),
|
|
17
|
-
maxFeePerGas: feeData.maxFeePerGas && BigInt(feeData.maxFeePerGas.toFixed()),
|
|
18
|
-
maxPriorityFeePerGas:
|
|
19
|
-
feeData.maxPriorityFeePerGas && BigInt(feeData.maxPriorityFeePerGas.toFixed()),
|
|
20
|
-
nextBaseFee: feeData.nextBaseFee && BigInt(feeData.nextBaseFee.toFixed()),
|
|
21
|
-
};
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
function toApiGasOptions(options: GasOptions): ApiGasOptions {
|
|
25
|
-
return {
|
|
26
|
-
fast: toApiFeeData(options.fast),
|
|
27
|
-
medium: toApiFeeData(options.medium),
|
|
28
|
-
slow: toApiFeeData(options.slow),
|
|
29
|
-
};
|
|
30
|
-
}
|
|
31
|
-
|
|
32
13
|
export async function estimateFees(
|
|
33
14
|
currency: CryptoCurrency,
|
|
34
15
|
transactionIntent: TransactionIntent<MemoNotSupported>,
|
|
16
|
+
customFees?: FeeEstimation,
|
|
35
17
|
): Promise<FeeEstimation> {
|
|
36
18
|
const { amount, asset, recipient, sender, type } = transactionIntent;
|
|
37
19
|
|
|
38
20
|
const transactionType = getTransactionType(type);
|
|
21
|
+
|
|
22
|
+
if (
|
|
23
|
+
(transactionType === TransactionTypes.legacy &&
|
|
24
|
+
typeof customFees?.parameters?.gasPrice === "bigint") ||
|
|
25
|
+
(transactionType === TransactionTypes.eip1559 &&
|
|
26
|
+
typeof customFees?.parameters?.maxFeePerGas === "bigint" &&
|
|
27
|
+
typeof customFees?.parameters?.maxPriorityFeePerGas === "bigint")
|
|
28
|
+
) {
|
|
29
|
+
return customFees;
|
|
30
|
+
}
|
|
31
|
+
|
|
39
32
|
const node = getNodeApi(currency);
|
|
40
|
-
const gasTracker = getGasTracker(currency);
|
|
41
33
|
const to = isNative(asset) ? recipient : (asset.assetReference as string);
|
|
42
34
|
const data = isNative(asset) ? Buffer.from([]) : getErc20Data(recipient, amount);
|
|
43
35
|
const value = isNative(asset) ? amount : 0n;
|
|
@@ -49,10 +41,6 @@ export async function estimateFees(
|
|
|
49
41
|
type: transactionType,
|
|
50
42
|
feesStrategy: transactionIntent.feesStrategy,
|
|
51
43
|
});
|
|
52
|
-
const gasOptions = await gasTracker?.getGasOptions({
|
|
53
|
-
currency,
|
|
54
|
-
options: { useEIP1559: transactionType === TransactionTypes.eip1559 },
|
|
55
|
-
});
|
|
56
44
|
const gasPrice =
|
|
57
45
|
transactionType === TransactionTypes.legacy ? feeData.gasPrice : feeData.maxFeePerGas;
|
|
58
46
|
const fee = gasPrice?.multipliedBy(gasLimit) || new BigNumber(0);
|
|
@@ -60,9 +48,11 @@ export async function estimateFees(
|
|
|
60
48
|
return {
|
|
61
49
|
value: BigInt(fee.toString()),
|
|
62
50
|
parameters: {
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
51
|
+
gasPrice: feeData.gasPrice && BigInt(feeData.gasPrice.toFixed()),
|
|
52
|
+
maxFeePerGas: feeData.maxFeePerGas && BigInt(feeData.maxFeePerGas.toFixed()),
|
|
53
|
+
maxPriorityFeePerGas:
|
|
54
|
+
feeData.maxPriorityFeePerGas && BigInt(feeData.maxPriorityFeePerGas.toFixed()),
|
|
55
|
+
nextBaseFee: feeData.nextBaseFee && BigInt(feeData.nextBaseFee.toFixed()),
|
|
66
56
|
},
|
|
67
57
|
};
|
|
68
58
|
}
|
package/src/logic/index.ts
CHANGED
package/src/types/transaction.ts
CHANGED
|
@@ -130,14 +130,6 @@ export type FeeHistory = {
|
|
|
130
130
|
reward: string[][];
|
|
131
131
|
};
|
|
132
132
|
|
|
133
|
-
export type ApiFeeData = {
|
|
134
|
-
maxFeePerGas: bigint | null;
|
|
135
|
-
maxPriorityFeePerGas: bigint | null;
|
|
136
|
-
gasPrice: bigint | null;
|
|
137
|
-
// only used by UI send flow in advanced mode for EIP-1559
|
|
138
|
-
nextBaseFee: bigint | null;
|
|
139
|
-
};
|
|
140
|
-
|
|
141
133
|
export type FeeData = {
|
|
142
134
|
maxFeePerGas: BigNumber | null;
|
|
143
135
|
maxPriorityFeePerGas: BigNumber | null;
|
|
@@ -156,10 +148,6 @@ export type FeeDataRaw = {
|
|
|
156
148
|
|
|
157
149
|
export type Strategy = "slow" | "medium" | "fast";
|
|
158
150
|
|
|
159
|
-
export type ApiGasOptions = {
|
|
160
|
-
[key in Strategy]: ApiFeeData;
|
|
161
|
-
};
|
|
162
|
-
|
|
163
151
|
export type GasOptions = {
|
|
164
152
|
[key in Strategy]: FeeData;
|
|
165
153
|
};
|
|
@@ -1,52 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"type": "TokenCurrency",
|
|
3
|
-
"id": "cardano/native/8654e8b350e298c80d2451beb5ed80fc9eee9f38ce6b039fb8706bc34c4f4253544552",
|
|
4
|
-
"contractAddress": "8654e8b350e298c80d2451beb5ed80fc9eee9f38ce6b039fb8706bc34c4f4253544552",
|
|
5
|
-
"parentCurrency": {
|
|
6
|
-
"type": "CryptoCurrency",
|
|
7
|
-
"id": "cardano",
|
|
8
|
-
"coinType": 1815,
|
|
9
|
-
"name": "Cardano",
|
|
10
|
-
"managerAppName": "Cardano ADA",
|
|
11
|
-
"ticker": "ADA",
|
|
12
|
-
"scheme": "cardano",
|
|
13
|
-
"color": "#0A1D2C",
|
|
14
|
-
"family": "cardano",
|
|
15
|
-
"blockAvgTime": 20,
|
|
16
|
-
"units": [
|
|
17
|
-
{
|
|
18
|
-
"name": "ada",
|
|
19
|
-
"code": "ADA",
|
|
20
|
-
"magnitude": 6
|
|
21
|
-
},
|
|
22
|
-
{
|
|
23
|
-
"name": "Lovelace",
|
|
24
|
-
"code": "Lovelace",
|
|
25
|
-
"magnitude": 0
|
|
26
|
-
}
|
|
27
|
-
],
|
|
28
|
-
"explorerViews": [
|
|
29
|
-
{
|
|
30
|
-
"tx": "https://cardanoscan.io/transaction/$hash",
|
|
31
|
-
"address": "https://cardanoscan.io/address/$address",
|
|
32
|
-
"stakePool": "https://cardanoscan.io/pool/$poolId"
|
|
33
|
-
}
|
|
34
|
-
],
|
|
35
|
-
"keywords": [
|
|
36
|
-
"ada",
|
|
37
|
-
"cardano"
|
|
38
|
-
]
|
|
39
|
-
},
|
|
40
|
-
"tokenType": "native",
|
|
41
|
-
"name": "LOBSTER",
|
|
42
|
-
"ticker": "$LOBSTER",
|
|
43
|
-
"delisted": false,
|
|
44
|
-
"disableCountervalue": false,
|
|
45
|
-
"units": [
|
|
46
|
-
{
|
|
47
|
-
"name": "LOBSTER",
|
|
48
|
-
"code": "$LOBSTER",
|
|
49
|
-
"magnitude": 0
|
|
50
|
-
}
|
|
51
|
-
]
|
|
52
|
-
}
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"accountId": "js:2:ethereum:0x6cbcd73cd8e8a42844662f0a0e76d7f79afd933d:+ethereum%2Ferc20%2Fusd~!underscore!~~!underscore!~coin",
|
|
3
|
-
"blockHash": "0x58ee7556044cd139e569c87c173a6dedbfbeb9ada6693ee6090fd510acee9c21",
|
|
4
|
-
"blockHeight": 16240731,
|
|
5
|
-
"contract": "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48",
|
|
6
|
-
"date": "2022-12-22T14:06:23.000Z",
|
|
7
|
-
"extra": {},
|
|
8
|
-
"fee": "1595338583295225",
|
|
9
|
-
"hash": "0x02b972f304dc24c9bc362e6435c4ad654241f9af916689a4790145c9bcbdf4cf",
|
|
10
|
-
"id": "js:2:ethereum:0x6cbcd73cd8e8a42844662f0a0e76d7f79afd933d:+js%3A2%3Aethereum%3A0x6cbcd73cd8e8a42844662f0a0e76d7f79afd933d%3A%2Bethereum%252Ferc20%252Fusd~!underscore!~~!underscore!~coin~!dash!~0x02b972f304dc24c9bc362e6435c4ad654241f9af916689a4790145c9bcbdf4cf~!dash!~OUT~!dash!~i0-0x02b972f304dc24c9bc362e6435c4ad654241f9af916689a4790145c9bcbdf4cf-IN-i0",
|
|
11
|
-
"recipients": [
|
|
12
|
-
"0xC2907EFccE4011C491BbedA8A0fA63BA7aab596C"
|
|
13
|
-
],
|
|
14
|
-
"senders": [
|
|
15
|
-
"0x6cBCD73CD8e8a42844662f0A0e76D7F79Afd933d"
|
|
16
|
-
],
|
|
17
|
-
"transactionSequenceNumber": 53,
|
|
18
|
-
"type": "OUT",
|
|
19
|
-
"value": "2000000"
|
|
20
|
-
}
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"accountId": "js:2:ethereum:0x6cbcd73cd8e8a42844662f0a0e76d7f79afd933d:+js%3A2%3Aethereum%3A0x6cbcd73cd8e8a42844662f0a0e76d7f79afd933d%3A%2Bethereum%252Ferc20%252Fusd~!underscore!~~!underscore!~coin~!dash!~0x02b972f304dc24c9bc362e6435c4ad654241f9af916689a4790145c9bcbdf4cf~!dash!~OUT~!dash!~i0",
|
|
3
|
-
"blockHash": "0x58ee7556044cd139e569c87c173a6dedbfbeb9ada6693ee6090fd510acee9c21",
|
|
4
|
-
"blockHeight": 16240731,
|
|
5
|
-
"date": "2022-12-22T14:06:23.000Z",
|
|
6
|
-
"extra": {},
|
|
7
|
-
"fee": "1595338583295225",
|
|
8
|
-
"hash": "0x02b972f304dc24c9bc362e6435c4ad654241f9af916689a4790145c9bcbdf4cf",
|
|
9
|
-
"id": "js:2:ethereum:0x6cbcd73cd8e8a42844662f0a0e76d7f79afd933d:+js%3A2%3Aethereum%3A0x6cbcd73cd8e8a42844662f0a0e76d7f79afd933d%3A%2Bethereum%252Ferc20%252Fusd~!underscore!~~!underscore!~coin~!dash!~0x02b972f304dc24c9bc362e6435c4ad654241f9af916689a4790145c9bcbdf4cf~!dash!~OUT~!dash!~i0-0x02b972f304dc24c9bc362e6435c4ad654241f9af916689a4790145c9bcbdf4cf-OUT-i0",
|
|
10
|
-
"recipients": [
|
|
11
|
-
"0xC2907EFccE4011C491BbedA8A0fA63BA7aab596C"
|
|
12
|
-
],
|
|
13
|
-
"senders": [
|
|
14
|
-
"0x6cBCD73CD8e8a42844662f0A0e76D7F79Afd933d"
|
|
15
|
-
],
|
|
16
|
-
"transactionSequenceNumber": 53,
|
|
17
|
-
"type": "OUT",
|
|
18
|
-
"value": "2000000"
|
|
19
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"cryptoAssetsStore.fixtures.d.ts","sourceRoot":"","sources":["../../../src/__tests__/fixtures/cryptoAssetsStore.fixtures.ts"],"names":[],"mappings":""}
|