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 12, 2024
1 parent 3f734ff commit ec1a181
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 @@ -23,6 +23,7 @@ import { Form } from "#/components/ui/form";
import { useManagedTransaction } from "#/hooks/tx-manager/useManagedTransaction";
import { useDebounce } from "#/hooks/useDebounce";
import { ConstantProductFactoryABI } from "#/lib/abis/ConstantProductFactory";
import { UNBALANCED_USD_DIFF_THRESHOLD } from "#/lib/constants";
import { COW_CONSTANT_PRODUCT_FACTORY } from "#/lib/contracts";
import { IToken } from "#/lib/fetchAmmData";
import { ammFormSchema } from "#/lib/schema";
Expand Down Expand Up @@ -227,7 +228,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 @@ -10,6 +10,10 @@ import { TokenInfo } from "#/components/TokenInfo";
import { Form, FormMessage } from "#/components/ui/form";
import { useManagedTransaction } from "#/hooks/tx-manager/useManagedTransaction";
import { useDebounce } from "#/hooks/useDebounce";
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 @@ -123,15 +127,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={
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 ec1a181

Please sign in to comment.