Skip to content

Commit

Permalink
Take fees of locked swaps
Browse files Browse the repository at this point in the history
  • Loading branch information
skubarenko committed Sep 11, 2022
1 parent b4b93ed commit 4216774
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions src/atomex/atomexSwapPreviewManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,15 @@ export class AtomexSwapPreviewManager implements Disposable {
if (!fromCurrencyBalance || !fromNativeCurrencyBalance)
throw new Error('Can not get from currency balances');

const maxFromNativeCurrencyFee = AtomexSwapPreviewManager.calculateMaxTotalFee(swapPreviewFees, fromNativeCurrencyInfo.currency.id);
const isFromCurrencyNative = fromCurrencyInfo.currency.id === fromNativeCurrencyInfo.currency.id;
const maxFromNativeCurrencyFeePerSwap = AtomexSwapPreviewManager.calculateMaxTotalFee(swapPreviewFees, fromNativeCurrencyInfo.currency.id);
const userInvolvedSwapsInfo = isFromCurrencyNative
? await this.getUserInvolvedSwapsInfo(fromAddress, fromCurrencyInfo.currency.id)
: null;
const maxFromNativeCurrencyFee = userInvolvedSwapsInfo
? maxFromNativeCurrencyFeePerSwap.multipliedBy(userInvolvedSwapsInfo.swapIds.length + 1)
: maxFromNativeCurrencyFeePerSwap;

if (fromNativeCurrencyBalance.isLessThan(maxFromNativeCurrencyFee)) {
errors.push({
id: 'not-enough-funds',
Expand All @@ -206,10 +214,7 @@ export class AtomexSwapPreviewManager implements Disposable {
});
}

const balanceIncludingFees = fromCurrencyInfo.currency.id === fromNativeCurrencyInfo.currency.id
? fromCurrencyBalance.minus(maxFromNativeCurrencyFee)
: fromCurrencyBalance;

const balanceIncludingFees = isFromCurrencyNative ? fromCurrencyBalance.minus(maxFromNativeCurrencyFee) : fromCurrencyBalance;
maxOrderPreview = await this.getMaxOrderPreview(
actualOrderPreview,
availableLiquidity,
Expand Down

0 comments on commit 4216774

Please sign in to comment.