diff --git a/src/Unit/Exchange/getSwapInfo.ts b/src/Unit/Exchange/getSwapInfo.ts index e6c0f9e..aa3e315 100644 --- a/src/Unit/Exchange/getSwapInfo.ts +++ b/src/Unit/Exchange/getSwapInfo.ts @@ -18,7 +18,8 @@ export type GetSwapInfoParams = { options?: { instantSettlement?: boolean poolOnly?: boolean - } + }, + walletAddress?: string, } export default async function getSwapInfo({ @@ -30,6 +31,7 @@ export default async function getSwapInfo({ blockchainService, aggregator, options, + walletAddress, }: GetSwapInfoParams) { if (amount === '') throw new Error('Amount can not be empty'); if (assetIn === '') throw new Error('AssetIn can not be empty'); @@ -45,7 +47,7 @@ export default async function getSwapInfo({ } = await simpleFetch(blockchainService.getInfo)(); const nativeCryptocurrencyName = getNativeCryptocurrencyName(assetToAddress); - const feeAssets = await simpleFetch(blockchainService.getTokensFee)(); + const feeAssets = await simpleFetch(blockchainService.getPlatformFees)({ walletAddress, assetIn, assetOut }); const allPrices = await simpleFetch(blockchainService.getPricesWithQuoteAsset)(); const gasPriceWei = await simpleFetch(blockchainService.getGasPriceWei)(); diff --git a/src/Unit/Exchange/swapLimit.ts b/src/Unit/Exchange/swapLimit.ts index 3b62706..11a9d06 100644 --- a/src/Unit/Exchange/swapLimit.ts +++ b/src/Unit/Exchange/swapLimit.ts @@ -89,7 +89,7 @@ export default async function swapLimit({ const nativeCryptocurrency = getNativeCryptocurrencyName(assetToAddress); const exchangeContract = Exchange__factory.connect(exchangeContractAddress, provider); - const feeAssets = await simpleFetch(blockchainService.getTokensFee)(); + const feeAssets = await simpleFetch(blockchainService.getPlatformFees)({ walletAddress, assetIn, assetOut }); const allPrices = await simpleFetch(blockchainService.getPricesWithQuoteAsset)(); const gasPriceWei = await simpleFetch(blockchainService.getGasPriceWei)(); const { factories } = await simpleFetch(blockchainService.getPoolsConfig)(); diff --git a/src/Unit/Exchange/swapMarket.ts b/src/Unit/Exchange/swapMarket.ts index 2ac8e2f..22ceaf1 100644 --- a/src/Unit/Exchange/swapMarket.ts +++ b/src/Unit/Exchange/swapMarket.ts @@ -74,7 +74,7 @@ export default async function swapMarket({ const nativeCryptocurrency = getNativeCryptocurrencyName(assetToAddress); const exchangeContract = Exchange__factory.connect(exchangeContractAddress, provider); - const feeAssets = await simpleFetch(blockchainService.getTokensFee)(); + const feeAssets = await simpleFetch(blockchainService.getPlatformFees)({ walletAddress, assetIn, assetOut }); const allPrices = await simpleFetch(blockchainService.getPricesWithQuoteAsset)(); const gasPriceWei = await simpleFetch(blockchainService.getGasPriceWei)(); const { factories } = await simpleFetch(blockchainService.getPoolsConfig)(); diff --git a/src/services/BlockchainService/index.ts b/src/services/BlockchainService/index.ts index df239e9..5cda0ff 100644 --- a/src/services/BlockchainService/index.ts +++ b/src/services/BlockchainService/index.ts @@ -86,6 +86,7 @@ class BlockchainService { this.getHistory = this.getHistory.bind(this); this.getPricesWithQuoteAsset = this.getPricesWithQuoteAsset.bind(this); this.getTokensFee = this.getTokensFee.bind(this); + this.getPlatformFees = this.getPlatformFees.bind(this); this.getGasPriceWei = this.getGasPriceWei.bind(this); this.checkFreeRedeemAvailable = this.checkFreeRedeemAvailable.bind(this); this.redeemAtomicSwap = this.redeemAtomicSwap.bind(this); @@ -221,12 +222,43 @@ class BlockchainService { { headers: this.basicAuthHeaders } ); + /** + * @deprecated In favor of getPlatformFees + */ getTokensFee = () => fetchWithValidation( `${this.apiUrl}/api/tokensFee`, z.record(z.string()).transform(makePartial), { headers: this.basicAuthHeaders } ); + getPlatformFees = ( + { assetIn, assetOut, walletAddress }: { + assetIn?: string | undefined, + assetOut?: string | undefined, + walletAddress?: string | undefined + } + ) => { + const url = new URL(`${this.apiUrl}/api/platform-fees`); + + if (assetIn) { + url.searchParams.append('assetIn', assetIn); + } + + if (assetOut) { + url.searchParams.append('assetOut', assetOut); + } + + if (walletAddress) { + url.searchParams.append('walletAddress', walletAddress); + } + + return fetchWithValidation( + url.toString(), + z.record(z.string()).transform(makePartial), + { headers: this.basicAuthHeaders } + ) + }; + getGasPriceWei = () => fetchWithValidation( `${this.apiUrl}/api/gasPrice`, z.string(),