118 lines
3.6 KiB
JavaScript
118 lines
3.6 KiB
JavaScript
|
|
"use strict";
|
||
|
|
Object.defineProperty(exports, "__esModule", { value: true });
|
||
|
|
exports.getMiscFeeLevels = exports.getEthereumFeeLevels = exports.getBitcoinFeeLevels = void 0;
|
||
|
|
const utils_1 = require("@trezor/utils");
|
||
|
|
const BLOCKS_FOR_FEE_LEVEL = {
|
||
|
|
btc: {
|
||
|
|
high: 1,
|
||
|
|
normal: 6,
|
||
|
|
economy: 36,
|
||
|
|
low: 144,
|
||
|
|
},
|
||
|
|
};
|
||
|
|
const getDefaultBlocksForFeeLevel = (shortcut, label) => BLOCKS_FOR_FEE_LEVEL[shortcut] && BLOCKS_FOR_FEE_LEVEL[shortcut][label]
|
||
|
|
? BLOCKS_FOR_FEE_LEVEL[shortcut][label]
|
||
|
|
: -1;
|
||
|
|
const EVM_GAS_PRICE_PER_CHAIN_IN_GWEI = {
|
||
|
|
eth: { min: 1, max: 10000, defaultGas: 15 },
|
||
|
|
pol: { min: 1, max: 10000000, defaultGas: 200 },
|
||
|
|
bsc: { min: 1, max: 100000, defaultGas: 3 },
|
||
|
|
base: { min: 0.0000001, max: 1000, defaultGas: 0.01 },
|
||
|
|
arb: { min: 0.001, max: 1000, defaultGas: 0.01 },
|
||
|
|
op: { min: 0.000000001, max: 1000, defaultGas: 0.01 },
|
||
|
|
};
|
||
|
|
const getEvmChainGweiGasPrice = (chain) => EVM_GAS_PRICE_PER_CHAIN_IN_GWEI[chain] ?? {
|
||
|
|
min: 0.000000001,
|
||
|
|
max: 10000,
|
||
|
|
defaultGas: 5,
|
||
|
|
};
|
||
|
|
const getBitcoinFeeLevels = (coin) => {
|
||
|
|
const defaultFees = coin.default_fee_b;
|
||
|
|
const shortcut = coin.shortcut.toLowerCase();
|
||
|
|
const keys = (0, utils_1.typedObjectKeys)(defaultFees);
|
||
|
|
const levels = keys
|
||
|
|
.sort((levelA, levelB) => defaultFees[levelB] - defaultFees[levelA])
|
||
|
|
.map(level => {
|
||
|
|
const label = level.toLowerCase();
|
||
|
|
return {
|
||
|
|
label,
|
||
|
|
feePerUnit: defaultFees[level].toString(),
|
||
|
|
blocks: getDefaultBlocksForFeeLevel(shortcut, label),
|
||
|
|
};
|
||
|
|
});
|
||
|
|
return {
|
||
|
|
blockTime: Math.max(1, Math.round(coin.blocktime_seconds / 60)),
|
||
|
|
dustLimit: coin.dust_limit,
|
||
|
|
maxFee: Math.round(coin.maxfee_kb / 1000),
|
||
|
|
minFee: Math.round(coin.minfee_kb / 1000),
|
||
|
|
defaultFees: levels,
|
||
|
|
};
|
||
|
|
};
|
||
|
|
exports.getBitcoinFeeLevels = getBitcoinFeeLevels;
|
||
|
|
const getEthereumFeeLevels = (chain) => {
|
||
|
|
const { min, max, defaultGas } = getEvmChainGweiGasPrice(chain);
|
||
|
|
return {
|
||
|
|
blockTime: -1,
|
||
|
|
defaultFees: [
|
||
|
|
{
|
||
|
|
label: 'normal',
|
||
|
|
feePerUnit: new utils_1.BigNumber(defaultGas).multipliedBy('1e+9').toString(),
|
||
|
|
feeLimit: '21000',
|
||
|
|
blocks: -1,
|
||
|
|
},
|
||
|
|
],
|
||
|
|
minFee: min,
|
||
|
|
maxFee: max,
|
||
|
|
dustLimit: -1,
|
||
|
|
};
|
||
|
|
};
|
||
|
|
exports.getEthereumFeeLevels = getEthereumFeeLevels;
|
||
|
|
const RIPPLE_FEE_INFO = {
|
||
|
|
blockTime: -1,
|
||
|
|
defaultFees: [{ label: 'normal', feePerUnit: '12', blocks: -1 }],
|
||
|
|
minFee: 10,
|
||
|
|
maxFee: 10000,
|
||
|
|
dustLimit: -1,
|
||
|
|
};
|
||
|
|
const CARDANO_FEE_INFO = {
|
||
|
|
blockTime: -1,
|
||
|
|
defaultFees: [{ label: 'normal', feePerUnit: '44', blocks: -1 }],
|
||
|
|
minFee: 44,
|
||
|
|
maxFee: 16384 * 44 + 155381,
|
||
|
|
dustLimit: -1,
|
||
|
|
};
|
||
|
|
const SOLANA_FEE_INFO = {
|
||
|
|
blockTime: -1,
|
||
|
|
defaultFees: [
|
||
|
|
{
|
||
|
|
label: 'normal',
|
||
|
|
feePerUnit: '100000',
|
||
|
|
feeLimit: '200000',
|
||
|
|
feePerTx: '25000',
|
||
|
|
blocks: -1,
|
||
|
|
},
|
||
|
|
],
|
||
|
|
minFee: 5000,
|
||
|
|
maxFee: 1000000000,
|
||
|
|
dustLimit: -1,
|
||
|
|
};
|
||
|
|
const MISC_FEE_LEVELS = {
|
||
|
|
xrp: RIPPLE_FEE_INFO,
|
||
|
|
txrp: RIPPLE_FEE_INFO,
|
||
|
|
ada: CARDANO_FEE_INFO,
|
||
|
|
tada: CARDANO_FEE_INFO,
|
||
|
|
sol: SOLANA_FEE_INFO,
|
||
|
|
dsol: SOLANA_FEE_INFO,
|
||
|
|
};
|
||
|
|
const getMiscFeeLevels = (data) => {
|
||
|
|
const shortcut = data.shortcut.toLowerCase();
|
||
|
|
return (MISC_FEE_LEVELS[shortcut] || {
|
||
|
|
blockTime: -1,
|
||
|
|
minFee: -1,
|
||
|
|
maxFee: -1,
|
||
|
|
defaultFees: [{ label: 'normal', feePerUnit: '-1', blocks: -1 }],
|
||
|
|
dustLimit: -1,
|
||
|
|
});
|
||
|
|
};
|
||
|
|
exports.getMiscFeeLevels = getMiscFeeLevels;
|
||
|
|
//# sourceMappingURL=defaultFeeLevels.js.map
|