Calculate fee

This commit is contained in:
Aleksandr Kraiz
2023-08-01 21:27:17 +04:00
parent 7eebb2bb9e
commit f9605e3d1a
9 changed files with 212 additions and 50 deletions

View File

@@ -1,20 +1,22 @@
import { BigNumber } from 'bignumber.js';
import type { BigNumber } from 'bignumber.js';
import calculateNetworkFee from './calculateNetworkFee.js';
import convertPrice from './convertPrice.js';
const calculateNetworkFeeInFeeAsset = (
gasPriceGwei: BigNumber.Value,
gasLimit: BigNumber.Value,
baseCurrencyPrice: BigNumber.Value,
feeAssetPrice: BigNumber.Value,
feeAssetPriceInQuoteAsset: BigNumber.Value,
baseCurrencyAddress: string,
feeAssetAddress: string,
prices: Partial<Record<string, string>>
) => {
const networkFee = calculateNetworkFee(gasPriceGwei, gasLimit);
const networkFeeInQuoteAsset = new BigNumber(networkFee).multipliedBy(baseCurrencyPrice);
const networkFeeInFeeAsset = networkFeeInQuoteAsset
.div(new BigNumber(feeAssetPriceInQuoteAsset).multipliedBy(feeAssetPrice));
return networkFeeInFeeAsset.toString();
return convertPrice(
networkFee,
baseCurrencyAddress, // from
feeAssetAddress, // to
prices
);
};
export default calculateNetworkFeeInFeeAsset;