From db0f741cb4edda8161abe2579bf9b59395c78233 Mon Sep 17 00:00:00 2001 From: Juliano Lazzarotto <30806844+stackchain@users.noreply.github.com> Date: Wed, 4 Oct 2023 08:59:10 +0100 Subject: [PATCH] wip: calcs --- .../swap/src/helpers/orders/makeOrderCalculations.ts | 12 ++++++++++++ packages/swap/src/translators/reactjs/state/state.ts | 1 + 2 files changed, 13 insertions(+) diff --git a/packages/swap/src/helpers/orders/makeOrderCalculations.ts b/packages/swap/src/helpers/orders/makeOrderCalculations.ts index f4aacbb670..5bf2a55a38 100644 --- a/packages/swap/src/helpers/orders/makeOrderCalculations.ts +++ b/packages/swap/src/helpers/orders/makeOrderCalculations.ts @@ -11,6 +11,7 @@ import {getMarketPrice} from './getMarketPrice' import {getBuyAmount} from './getBuyAmount' import {getSellAmount} from './getSellAmount' import {asQuantity} from '../../utils/asQuantity' +import {Quantities} from 'utils/quantities' export const makeOrderCalculations = ({ orderType, @@ -33,6 +34,7 @@ export const makeOrderCalculations = ({ buy: `${number}` | undefined sell: `${number}` | undefined } + hasSupply: boolean, pools: ReadonlyArray lpTokenHeld: Balance.Amount | undefined slippage: number @@ -159,6 +161,15 @@ export const makeOrderCalculations = ({ .times(100) .toString() + const poolSupply = + buy.tokenId === pool.tokenA.tokenId + ? pool.tokenA.quantity + : pool.tokenB.quantity + const hasSupply = !Quantities.isGreaterThan( + buy.quantity, + poolSupply ?? Quantities.zero, + ) + const orderCalculation: SwapOrderCalulation = { cost: { batcherFee: pool.batcherFee, @@ -167,6 +178,7 @@ export const makeOrderCalculations = ({ liquidityFee, }, buyAmountWithSlippage, + hasSupply, prices: { base: priceBase, market: marketPrice, diff --git a/packages/swap/src/translators/reactjs/state/state.ts b/packages/swap/src/translators/reactjs/state/state.ts index f65e0ebe84..ba7c297ca3 100644 --- a/packages/swap/src/translators/reactjs/state/state.ts +++ b/packages/swap/src/translators/reactjs/state/state.ts @@ -18,6 +18,7 @@ export type SwapOrderCalulation = Readonly<{ withSlippage: string withFeesAndSlippage: string } + hasSupply: boolean buyAmountWithSlippage: Balance.Amount cost: { liquidityFee: Balance.Amount