-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
CoW AMM: Price impact information on deposit and creation of AMMs (#703)
* Add usd value and price impact warning on deposit form * add create amm unbalanced amm warning * refactor: separete thresholds into constants file * run formatter * update cowAmmData to ammData and run formatter
- Loading branch information
1 parent
41cd197
commit e058f5b
Showing
5 changed files
with
135 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import { useEffect, useState } from "react"; | ||
|
||
export function useDebounce<T>(value: T, delay: number) { | ||
const [debouncedValue, setDebouncedValue] = useState<T>(value); | ||
|
||
useEffect(() => { | ||
const handler = setTimeout(() => { | ||
setDebouncedValue(value); | ||
}, delay); | ||
|
||
return () => { | ||
clearTimeout(handler); | ||
}; | ||
}, [value, delay]); | ||
|
||
return debouncedValue; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,8 @@ | ||
export const BLEU_APP_DATA = | ||
"0x4d821ddc9d656177dad4d5c2f76a4bff2ed514ff69fa4aa4fd869d6e98d55c89"; | ||
|
||
export const PRICE_IMPACT_THRESHOLD = 0.05; | ||
|
||
export const UNBALANCED_USD_DIFF_THRESHOLD = 5000; | ||
|
||
export const USD_VALUE_FOR_PRICE_IMPACT_WARNING = 5000; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
export function calculatePriceImpact({ | ||
balance0, | ||
balance1, | ||
amount0, | ||
amount1, | ||
}: { | ||
balance0: number; | ||
balance1: number; | ||
amount0: number; | ||
amount1: number; | ||
}) { | ||
const token0Ratio = amount0 / balance0; | ||
const token1Ratio = amount1 / balance1; | ||
const ratio0BiggerThan1 = token0Ratio > token1Ratio; | ||
|
||
const currentSpotPrice = ratio0BiggerThan1 | ||
? balance1 / balance0 | ||
: balance0 / balance1; | ||
const newSpotPrice = ratio0BiggerThan1 | ||
? (balance1 + amount1) / (balance0 + amount0) | ||
: (balance0 + amount0) / (balance1 + amount1); | ||
|
||
return Math.abs(newSpotPrice - currentSpotPrice) / currentSpotPrice; | ||
} |