Skip to content

Commit

Permalink
wip: calcs
Browse files Browse the repository at this point in the history
  • Loading branch information
stackchain committed Oct 4, 2023
1 parent d33d810 commit db0f741
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
12 changes: 12 additions & 0 deletions packages/swap/src/helpers/orders/makeOrderCalculations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -33,6 +34,7 @@ export const makeOrderCalculations = ({
buy: `${number}` | undefined
sell: `${number}` | undefined
}
hasSupply: boolean,
pools: ReadonlyArray<Swap.Pool>
lpTokenHeld: Balance.Amount | undefined
slippage: number
Expand Down Expand Up @@ -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,
Expand All @@ -167,6 +178,7 @@ export const makeOrderCalculations = ({
liquidityFee,
},
buyAmountWithSlippage,
hasSupply,
prices: {
base: priceBase,
market: marketPrice,
Expand Down
1 change: 1 addition & 0 deletions packages/swap/src/translators/reactjs/state/state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ export type SwapOrderCalulation = Readonly<{
withSlippage: string
withFeesAndSlippage: string
}
hasSupply: boolean
buyAmountWithSlippage: Balance.Amount
cost: {
liquidityFee: Balance.Amount
Expand Down

0 comments on commit db0f741

Please sign in to comment.