mirror of
https://github.com/orionprotocol/sdk.git
synced 2026-04-03 19:47:56 +03:00
Calculate fee
This commit is contained in:
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user