fix: dont block trade when price impact is favorable (#6261)
* fix: dont block trade when price impact is favorable * fix: add comment
This commit is contained in:
parent
7b9a23d920
commit
fb8217ddea
@ -122,6 +122,9 @@ describe('prices', () => {
|
||||
it('0 for undefined', () => {
|
||||
expect(warningSeverity(undefined)).toEqual(0)
|
||||
})
|
||||
it('0 for negative', () => {
|
||||
expect(warningSeverity(new Percent(-1))).toEqual(0)
|
||||
})
|
||||
it('correct for 0', () => {
|
||||
expect(warningSeverity(new Percent(0))).toEqual(0)
|
||||
})
|
||||
|
@ -85,6 +85,12 @@ const IMPACT_TIERS = [
|
||||
type WarningSeverity = 0 | 1 | 2 | 3 | 4
|
||||
export function warningSeverity(priceImpact: Percent | undefined): WarningSeverity {
|
||||
if (!priceImpact) return 0
|
||||
// This function is used to calculate the Severity level for % changes in USD value and Price Impact.
|
||||
// Price Impact is always an absolute value (conceptually always negative, but represented in code with a positive value)
|
||||
// The USD value change can be positive or negative, and it follows the same standard as Price Impact (positive value is the typical case of a loss due to slippage).
|
||||
// We don't want to return a warning level for a favorable/profitable change, so when the USD value change is negative we return 0.
|
||||
// TODO (WEB-3133): Disambiguate Price Impact and USD value change, and flip the sign of USD Value change.
|
||||
if (priceImpact.lessThan(0)) return 0
|
||||
let impact: WarningSeverity = IMPACT_TIERS.length as WarningSeverity
|
||||
for (const impactLevel of IMPACT_TIERS) {
|
||||
if (impactLevel.lessThan(priceImpact)) return impact
|
||||
|
Loading…
Reference in New Issue
Block a user