From b6cb9ae1a1affc0b2c53e89ed49ec8fe71973592 Mon Sep 17 00:00:00 2001 From: Aleksandr Kraiz Date: Sat, 5 Aug 2023 01:10:20 +0400 Subject: [PATCH] Fix price conversion --- package.json | 2 +- src/utils/calculateFeeInFeeAsset.ts | 20 ++++++++++---------- src/utils/calculateNetworkFeeInFeeAsset.ts | 8 ++++---- src/utils/calculateServiceFeeInFeeAsset.ts | 8 ++++---- src/utils/convertPrice.ts | 14 +++++++------- 5 files changed, 26 insertions(+), 26 deletions(-) diff --git a/package.json b/package.json index 908b26e..4506f78 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@orionprotocol/sdk", - "version": "0.19.44", + "version": "0.19.45", "description": "Orion Protocol SDK", "main": "./lib/index.cjs", "module": "./lib/index.js", diff --git a/src/utils/calculateFeeInFeeAsset.ts b/src/utils/calculateFeeInFeeAsset.ts index e4dd53d..2cde7e4 100644 --- a/src/utils/calculateFeeInFeeAsset.ts +++ b/src/utils/calculateFeeInFeeAsset.ts @@ -7,30 +7,30 @@ const calculateFeeInFeeAsset = ( amount: BigNumber.Value, gasPriceGwei: BigNumber.Value, feePercent: BigNumber.Value, - baseAssetAddress: string, - baseCurrencyAddress: string, - feeAssetAddress: string, + baseAssetName: string, + baseCurrencyName: string, + feeAssetName: string, prices: Partial>, ) => { - const feeAssetPrice = prices[feeAssetAddress]; + const feeAssetPrice = prices[feeAssetName]; if (feeAssetPrice === undefined) throw Error(`Fee asset price not found. Available prices: ${Object.keys(prices).join(', ')}`); - const baseAssetPrice = prices[baseAssetAddress]; + const baseAssetPrice = prices[baseAssetName]; if (baseAssetPrice === undefined) throw Error(`Base asset price not found. Available prices: ${Object.keys(prices).join(', ')}`); - const baseCurrencyPrice = prices[baseCurrencyAddress]; // ETH, BNB, MATIC, etc. + const baseCurrencyPrice = prices[baseCurrencyName]; // ETH, BNB, MATIC, etc. if (baseCurrencyPrice === undefined) throw Error(`Base currency price not found. Available prices: ${Object.keys(prices).join(', ')}`); const serviceFeeInFeeAsset = calculateServiceFeeInFeeAsset( amount, - baseAssetAddress, - feeAssetAddress, + baseAssetName, + feeAssetName, feePercent, prices, ); const networkFeeInFeeAsset = calculateNetworkFeeInFeeAsset( gasPriceGwei, FILL_ORDERS_GAS_LIMIT, - baseCurrencyAddress, - feeAssetAddress, + baseCurrencyName, + feeAssetName, prices, ); diff --git a/src/utils/calculateNetworkFeeInFeeAsset.ts b/src/utils/calculateNetworkFeeInFeeAsset.ts index 8e399eb..4157756 100644 --- a/src/utils/calculateNetworkFeeInFeeAsset.ts +++ b/src/utils/calculateNetworkFeeInFeeAsset.ts @@ -5,16 +5,16 @@ import convertPrice from './convertPrice.js'; const calculateNetworkFeeInFeeAsset = ( gasPriceGwei: BigNumber.Value, gasLimit: BigNumber.Value, - baseCurrencyAddress: string, - feeAssetAddress: string, + baseCurrencyName: string, + feeAssetName: string, prices: Partial> ) => { const networkFee = calculateNetworkFee(gasPriceGwei, gasLimit); return convertPrice( networkFee, - baseCurrencyAddress, // from - feeAssetAddress, // to + baseCurrencyName, // from + feeAssetName, // to prices ); }; diff --git a/src/utils/calculateServiceFeeInFeeAsset.ts b/src/utils/calculateServiceFeeInFeeAsset.ts index d329d9e..599eefd 100644 --- a/src/utils/calculateServiceFeeInFeeAsset.ts +++ b/src/utils/calculateServiceFeeInFeeAsset.ts @@ -3,8 +3,8 @@ import convertPrice from './convertPrice.js'; export default function calculateServiceFeeInFeeAsset( amount: BigNumber.Value, - baseAssetAddress: string, - feeAssetAddress: string, + baseAssetName: string, + feeAssetName: string, feePercent: BigNumber.Value, prices: Partial> ) { @@ -12,8 +12,8 @@ export default function calculateServiceFeeInFeeAsset( const feeAssetAmount = convertPrice( feeAmount, - baseAssetAddress, - feeAssetAddress, + baseAssetName, + feeAssetName, prices ); diff --git a/src/utils/convertPrice.ts b/src/utils/convertPrice.ts index 3055b9b..3a56e9c 100644 --- a/src/utils/convertPrice.ts +++ b/src/utils/convertPrice.ts @@ -2,15 +2,15 @@ import { BigNumber } from 'bignumber.js'; export default function convertPrice( amount: BigNumber.Value, - assetInAddress: string, - assetOutAddress: string, - prices: Partial> // quoted in quoteAsset. [address]: priceQuotedInQuoteAsset + assetInName: string, + assetOutName: string, + prices: Partial> // quoted in quoteAsset. [name]: priceQuotedInQuoteAsset ) { - const assetInPrice = prices[assetInAddress.toLowerCase()]; - if (assetInPrice === undefined) throw Error(`Price conversion: AssetIn (${assetInAddress}) price is undefined`); + const assetInPrice = prices[assetInName]; + if (assetInPrice === undefined) throw Error(`Price conversion: AssetIn (${assetInName}) price is undefined`); - const assetOutPrice = prices[assetOutAddress.toLowerCase()]; - if (assetOutPrice === undefined) throw Error(`Price conversion: AssetOut (${assetOutAddress}) price is undefined`); + const assetOutPrice = prices[assetOutName]; + if (assetOutPrice === undefined) throw Error(`Price conversion: AssetOut (${assetOutName}) price is undefined`); const assetInPriceBN = new BigNumber(assetInPrice); const assetOutPriceBN = new BigNumber(assetOutPrice);