Skip to content
This repository has been archived by the owner on Jan 15, 2021. It is now read-only.

[1.6] Use limitPrice.eq(fillPrice) to check correctly when there shouldn't be a warning #1608

Merged
merged 1 commit into from
Nov 12, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 8 additions & 11 deletions src/components/trade/PriceImpact/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,18 +63,13 @@ function determinePriceWarning(params: PriceImpactArgs, impact: BigNumber | null

const limitPrice = limitPriceString && parseBigNumber(limitPriceString)

// No comparable prices, or user opting for suggested fill price
// round values before comparing
if (
// if any of the limit/fill/bestAsk params are
// null or zero, return null
!limitPrice ||
limitPrice.isZero() ||
!fillPrice ||
!bestAskPrice
)
// No calculatable prices: stop early
if (!limitPrice || limitPrice.isZero() || !fillPrice || !bestAskPrice) {
return null
}

// Limit price BigNumber === Fill price BigNumber - order is optimised, no warnings
const fillPriceMatchesLimitPrice = limitPrice.eq(fillPrice)
// Is user's limit price less than the suggested fill price?
const orderWontBeFullyExecuted = limitPrice.lt(fillPrice)
// Is user's limit price less than suggested fill price AND best ask?
Expand All @@ -93,6 +88,9 @@ function determinePriceWarning(params: PriceImpactArgs, impact: BigNumber | null
!isPriceAboveDeepMarketThreshold && limitPrice.gte(fillPrice.times(MID_PLACEHOLDER_SLIPPAGE))

switch (true) {
// CASE 4 & 3: price matches fill price, orders goes ahead
case fillPriceMatchesLimitPrice:
return null
// CASE 6: Limit price is GREATER THAN Fill price AND upper threshold 5%
case isPriceAboveDeepMarketThreshold:
return WARNINGS.DEEP_MARKET
Expand All @@ -104,7 +102,6 @@ function determinePriceWarning(params: PriceImpactArgs, impact: BigNumber | null
// CASE 2
case isPriceMidImpactAndExecutable:
return WARNINGS.MAYBE_FULLY_EXECUTED
// CASE 4 & 3
default:
return null
}
Expand Down