Skip to content

Commit

Permalink
refactor: separete thresholds into constants file
Browse files Browse the repository at this point in the history
  • Loading branch information
yvesfracari committed Jun 11, 2024
1 parent 49d38db commit 513f9a8
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import {
import { Form } from "#/components/ui/form";
import { useDebounce } from "#/hooks/useDebounce";
import { useRawTxData } from "#/hooks/useRawTxData";
import { UNBALANCED_USD_DIFF_THRESHOLD } from "#/lib/constants";
import { IToken } from "#/lib/fetchAmmData";
import { ammFormSchema } from "#/lib/schema";
import { fetchTokenUsdPrice, getNewMinTradeToken0 } from "#/lib/tokenUtils";
Expand Down Expand Up @@ -212,7 +213,7 @@ export function CreateAMMForm({ userId }: { userId: string }) {
<span>
{amountUsdDiff} {debouncedAmountUsdDiff}
</span>
{(debouncedAmountUsdDiff || 0) > 5000 && (
{(debouncedAmountUsdDiff || 0) > UNBALANCED_USD_DIFF_THRESHOLD && (
<AlertCard title="Unbalanced amounts" style="warning">
<p>
The difference between the USD value of the two token amounts is
Expand Down
23 changes: 14 additions & 9 deletions apps/cow-amm-deployer/src/components/DepositForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ import { TokenInfo } from "#/components/TokenInfo";
import { Form, FormMessage } from "#/components/ui/form";
import { useDebounce } from "#/hooks/useDebounce";
import { useRawTxData } from "#/hooks/useRawTxData";
import {
PRICE_IMPACT_THRESHOLD,
USD_VALUE_FOR_PRICE_IMPACT_WARNING,
} from "#/lib/constants";
import { ICowAmm } from "#/lib/fetchAmmData";
import { calculatePriceImpact } from "#/lib/priceImpact";
import { getDepositSchema } from "#/lib/schema";
Expand Down Expand Up @@ -116,15 +120,16 @@ export function DepositForm({
</FormMessage>
)
}
{debouncedDepositUsdValue > 5000 && debouncedPriceImpact > 0.1 && (
<AlertCard style="warning" title="High Price Impact">
<p>
The price impact of this deposit is{" "}
{formatNumber(debouncedPriceImpact * 100, 2)}%. Deposits with high
price impact may result in lost funds.
</p>
</AlertCard>
)}
{debouncedDepositUsdValue > USD_VALUE_FOR_PRICE_IMPACT_WARNING &&
debouncedPriceImpact > PRICE_IMPACT_THRESHOLD && (
<AlertCard style="warning" title="High Price Impact">
<p>
The price impact of this deposit is{" "}
{formatNumber(debouncedPriceImpact * 100, 2)}%. Deposits with high
price impact may result in lost funds.
</p>
</AlertCard>
)}

<Button
loading={isSubmitting}
Expand Down
6 changes: 6 additions & 0 deletions apps/cow-amm-deployer/src/lib/constants.ts
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;

0 comments on commit 513f9a8

Please sign in to comment.