merged with develop

This commit is contained in:
lomonoshka
2023-08-10 15:18:55 +03:00
28 changed files with 461 additions and 154 deletions

View File

@@ -46,7 +46,7 @@ export default async function getSwapInfo({
const nativeCryptocurrencyName = getNativeCryptocurrencyName(assetToAddress);
const feeAssets = await simpleFetch(blockchainService.getTokensFee)();
const pricesInOrn = await simpleFetch(blockchainService.getPrices)();
const allPrices = await simpleFetch(blockchainService.getPricesWithQuoteAsset)();
const gasPriceWei = await simpleFetch(blockchainService.getGasPriceWei)();
const gasPriceGwei = ethers.utils.formatUnits(gasPriceWei, 'gwei').toString();
@@ -121,12 +121,6 @@ export default async function getSwapInfo({
if (baseAssetAddress === undefined) throw new Error(`No asset address for ${baseAssetName}`);
// Fee calculation
const baseAssetPriceInOrn = pricesInOrn[baseAssetAddress];
if (baseAssetPriceInOrn === undefined) throw new Error(`Base asset price ${baseAssetName} in ORN not found`);
const baseCurrencyPriceInOrn = pricesInOrn[ethers.constants.AddressZero];
if (baseCurrencyPriceInOrn === undefined) throw new Error('Base currency price in ORN not found');
const feeAssetPriceInOrn = pricesInOrn[feeAssetAddress];
if (feeAssetPriceInOrn === undefined) throw new Error(`Fee asset price ${feeAsset} in ORN not found`);
const feePercent = feeAssets[feeAsset];
if (feePercent === undefined) throw new Error(`Fee asset ${feeAsset} not available`);
@@ -135,11 +129,12 @@ export default async function getSwapInfo({
networkFeeInFeeAsset,
} = calculateFeeInFeeAsset(
swapInfo.orderInfo.amount,
feeAssetPriceInOrn,
baseAssetPriceInOrn,
baseCurrencyPriceInOrn,
gasPriceGwei,
feePercent,
baseAssetAddress,
ethers.constants.AddressZero,
feeAssetAddress,
allPrices.prices
);
return {

View File

@@ -90,7 +90,7 @@ export default async function swapLimit({
const exchangeContract = Exchange__factory.connect(exchangeContractAddress, provider);
const feeAssets = await simpleFetch(blockchainService.getTokensFee)();
const pricesInOrn = await simpleFetch(blockchainService.getPrices)();
const allPrices = await simpleFetch(blockchainService.getPricesWithQuoteAsset)();
const gasPriceWei = await simpleFetch(blockchainService.getGasPriceWei)();
const { factories } = await simpleFetch(blockchainService.getPoolsConfig)();
const poolExchangesList = factories !== undefined ? Object.keys(factories) : [];
@@ -372,22 +372,17 @@ export default async function swapLimit({
});
// Fee calculation
const baseAssetPriceInOrn = pricesInOrn[baseAssetAddress];
if (baseAssetPriceInOrn === undefined) throw new Error(`Base asset price ${baseAssetName} in ORN not found`);
const baseCurrencyPriceInOrn = pricesInOrn[ethers.constants.AddressZero];
if (baseCurrencyPriceInOrn === undefined) throw new Error('Base currency price in ORN not found');
const feeAssetPriceInOrn = pricesInOrn[feeAssetAddress];
if (feeAssetPriceInOrn === undefined) throw new Error(`Fee asset price ${feeAsset} in ORN not found`);
const feePercent = feeAssets[feeAsset];
if (feePercent === undefined) throw new Error(`Fee asset ${feeAsset} not available`);
const { serviceFeeInFeeAsset, networkFeeInFeeAsset, totalFeeInFeeAsset } = calculateFeeInFeeAsset(
swapInfo.orderInfo.amount,
feeAssetPriceInOrn,
baseAssetPriceInOrn,
baseCurrencyPriceInOrn,
gasPriceGwei,
feePercent,
baseAssetAddress,
ethers.constants.AddressZero,
feeAssetAddress,
allPrices.prices,
);
if (feeAsset === assetOut) {
@@ -403,7 +398,7 @@ export default async function swapLimit({
name: feeAsset,
address: feeAssetAddress,
},
amount: networkFeeInFeeAsset,
amount: networkFeeInFeeAsset.toString(),
spenderAddress: exchangeContractAddress,
sources: getAvailableSources('network_fee', feeAssetAddress, 'aggregator'),
});
@@ -414,7 +409,7 @@ export default async function swapLimit({
name: feeAsset,
address: feeAssetAddress,
},
amount: serviceFeeInFeeAsset,
amount: serviceFeeInFeeAsset.toString(),
spenderAddress: exchangeContractAddress,
sources: getAvailableSources('service_fee', feeAssetAddress, 'aggregator'),
});

View File

@@ -75,7 +75,7 @@ export default async function swapMarket({
const exchangeContract = Exchange__factory.connect(exchangeContractAddress, provider);
const feeAssets = await simpleFetch(blockchainService.getTokensFee)();
const pricesInOrn = await simpleFetch(blockchainService.getPrices)();
const allPrices = await simpleFetch(blockchainService.getPricesWithQuoteAsset)();
const gasPriceWei = await simpleFetch(blockchainService.getGasPriceWei)();
const { factories } = await simpleFetch(blockchainService.getPoolsConfig)();
const poolExchangesList = factories !== undefined ? Object.keys(factories) : [];
@@ -330,22 +330,17 @@ export default async function swapMarket({
});
// Fee calculation
const baseAssetPriceInOrn = pricesInOrn[baseAssetAddress];
if (baseAssetPriceInOrn === undefined) throw new Error(`Base asset price ${baseAssetName} in ORN not found`);
const baseCurrencyPriceInOrn = pricesInOrn[ethers.constants.AddressZero];
if (baseCurrencyPriceInOrn === undefined) throw new Error('Base currency price in ORN not found');
const feeAssetPriceInOrn = pricesInOrn[feeAssetAddress];
if (feeAssetPriceInOrn === undefined) throw new Error(`Fee asset price ${feeAsset} in ORN not found`);
const feePercent = feeAssets[feeAsset];
if (feePercent === undefined) throw new Error(`Fee asset ${feeAsset} not available`);
const { serviceFeeInFeeAsset, networkFeeInFeeAsset, totalFeeInFeeAsset } = calculateFeeInFeeAsset(
swapInfo.orderInfo.amount,
feeAssetPriceInOrn,
baseAssetPriceInOrn,
baseCurrencyPriceInOrn,
gasPriceGwei,
feePercent,
baseAssetAddress,
ethers.constants.AddressZero,
feeAssetAddress,
allPrices.prices,
);
if (feeAsset === assetOut) {
@@ -361,7 +356,7 @@ export default async function swapMarket({
name: feeAsset,
address: feeAssetAddress,
},
amount: networkFeeInFeeAsset,
amount: networkFeeInFeeAsset.toString(),
spenderAddress: exchangeContractAddress,
sources: getAvailableSources('network_fee', feeAssetAddress, 'aggregator'),
});
@@ -372,7 +367,7 @@ export default async function swapMarket({
name: feeAsset,
address: feeAssetAddress,
},
amount: serviceFeeInFeeAsset,
amount: serviceFeeInFeeAsset.toString(),
spenderAddress: exchangeContractAddress,
sources: getAvailableSources('service_fee', feeAssetAddress, 'aggregator'),
});