From ec41782968012844cd8ff85b84e3ee55a8148833 Mon Sep 17 00:00:00 2001 From: lilchizh Date: Fri, 29 Mar 2024 20:21:32 +0700 Subject: [PATCH 1/3] fix: APR calculation --- src/hooks/positions/usePositionAPR.ts | 6 +++++- src/utils/positions/getPositionAPR.ts | 6 +++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/src/hooks/positions/usePositionAPR.ts b/src/hooks/positions/usePositionAPR.ts index 7392fe49..c5d1ebb2 100644 --- a/src/hooks/positions/usePositionAPR.ts +++ b/src/hooks/positions/usePositionAPR.ts @@ -29,7 +29,11 @@ export function usePositionAPR( const nativePrice = bundles?.bundles[0] && Number(bundles.bundles[0].maticPriceUSD) - const poolDayFees = poolFeeData && Boolean(poolFeeData.poolDayDatas.length) && poolFeeData.poolDayDatas.reduce((acc, v) => acc + Number(v.feesUSD), 0) + // Today fees + const poolDayFees = poolFeeData && Boolean(poolFeeData.poolDayDatas.length) && Number(poolFeeData.poolDayDatas[0].feesUSD) + + // Avg fees + // const poolDayFees = poolFeeData && Boolean(poolFeeData.poolDayDatas.length) && poolFeeData.poolDayDatas.reduce((acc, v) => acc + Number(v.feesUSD), 0) / poolFeeData.poolDayDatas.length const yearFee = poolDayFees && poolDayFees * 365 diff --git a/src/utils/positions/getPositionAPR.ts b/src/utils/positions/getPositionAPR.ts index 3a64b0a5..3057c62b 100644 --- a/src/utils/positions/getPositionAPR.ts +++ b/src/utils/positions/getPositionAPR.ts @@ -21,7 +21,11 @@ export async function getPositionAPR( const liquidity = await algebraPool.read.liquidity() - const poolDayFees = poolFeeData && Boolean(poolFeeData.length) && poolFeeData.reduce((acc, v) => acc + Number(v.feesUSD), 0) + // Today fees + const poolDayFees = poolFeeData && Boolean(poolFeeData.length) && Number(poolFeeData[0].feesUSD) + + // Avg fees + // const poolDayFees = poolFeeData && Boolean(poolFeeData.length) && poolFeeData.reduce((acc, v) => acc + Number(v.feesUSD), 0) / poolFeeData.length const yearFee = poolDayFees && poolDayFees * 365 From c0ce330cbb0eab1d1d751ac5e366285d1bb6c79c Mon Sep 17 00:00:00 2001 From: lilchizh Date: Fri, 29 Mar 2024 20:40:53 +0700 Subject: [PATCH 2/3] fix: pool initial price --- .../create-pool/CreatePoolForm/index.tsx | 16 ++++++++-------- src/components/create-pool/SelectPair/index.tsx | 13 ++++++------- 2 files changed, 14 insertions(+), 15 deletions(-) diff --git a/src/components/create-pool/CreatePoolForm/index.tsx b/src/components/create-pool/CreatePoolForm/index.tsx index 3de4de1e..f740dac9 100644 --- a/src/components/create-pool/CreatePoolForm/index.tsx +++ b/src/components/create-pool/CreatePoolForm/index.tsx @@ -11,7 +11,7 @@ import { import { usePrepareAlgebraPositionManagerMulticall } from '@/generated'; import { useTransitionAwait } from '@/hooks/common/useTransactionAwait'; import { Address, useContractWrite } from 'wagmi'; -import { useDerivedMintInfo } from '@/state/mintStore'; +import { useDerivedMintInfo, useMintState } from '@/state/mintStore'; import Loader from '@/components/common/Loader'; import { PoolState, usePool } from '@/hooks/pools/usePool'; import Summary from '../Summary'; @@ -21,7 +21,9 @@ import { STABLECOINS } from '@/constants/tokens'; const CreatePoolForm = () => { const { currencies } = useDerivedSwapInfo(); - const { typedValue, actions: { selectCurrency, typeInput } } = useSwapState(); + const { actions: { selectCurrency } } = useSwapState(); + + const { startPriceTypedValue, actions: { typeStartPriceInput } } = useMintState() const currencyA = currencies[SwapField.INPUT]; const currencyB = currencies[SwapField.OUTPUT]; @@ -83,14 +85,12 @@ const CreatePoolForm = () => { useEffect(() => { selectCurrency(SwapField.INPUT, undefined) selectCurrency(SwapField.OUTPUT, undefined) - typeInput(SwapField.INPUT, '') - typeInput(SwapField.OUTPUT, '') + typeStartPriceInput('') return () => { selectCurrency(SwapField.INPUT, ADDRESS_ZERO) selectCurrency(SwapField.OUTPUT, STABLECOINS.USDT.address as Account) - typeInput(SwapField.INPUT, '') - typeInput(SwapField.OUTPUT, '') + typeStartPriceInput('') } }, []) @@ -114,7 +114,7 @@ const CreatePoolForm = () => { disabled={ isLoading || isPoolExists || - !typedValue || + !startPriceTypedValue || !areCurrenciesSelected || isSameToken } @@ -128,7 +128,7 @@ const CreatePoolForm = () => { 'Select currencies' ) : isPoolExists ? ( 'Pool already exists' - ) : !typedValue ? ( + ) : !startPriceTypedValue ? ( 'Enter initial price' ) : ( 'Create Pool' diff --git a/src/components/create-pool/SelectPair/index.tsx b/src/components/create-pool/SelectPair/index.tsx index 09285582..b5849b84 100644 --- a/src/components/create-pool/SelectPair/index.tsx +++ b/src/components/create-pool/SelectPair/index.tsx @@ -1,6 +1,6 @@ import TokenCard from '@/components/swap/TokenCard'; -import { IDerivedMintInfo, useMintActionHandlers } from '@/state/mintStore'; -import { useSwapActionHandlers, useSwapState } from '@/state/swapStore'; +import { IDerivedMintInfo, useMintActionHandlers, useMintState } from '@/state/mintStore'; +import { useSwapActionHandlers } from '@/state/swapStore'; import { SwapField } from '@/types/swap-field'; import { Currency } from '@cryptoalgebra/integral-sdk'; import { ChevronsUpDownIcon } from 'lucide-react'; @@ -13,12 +13,12 @@ interface ISelectPair { } const SelectPair = ({ mintInfo, currencyA, currencyB }: ISelectPair) => { - const { onCurrencySelection, onUserInput, onSwitchTokens } = + const { onCurrencySelection, onSwitchTokens } = useSwapActionHandlers(); const { onStartPriceInput } = useMintActionHandlers(mintInfo.noLiquidity); - const { typedValue } = useSwapState(); + const { startPriceTypedValue } = useMintState(); const handleInputSelect = useCallback( (inputCurrency: Currency) => { @@ -36,17 +36,16 @@ const SelectPair = ({ mintInfo, currencyA, currencyB }: ISelectPair) => { const handleTypeInput = useCallback( (value: string) => { - onUserInput(SwapField.INPUT, value); onStartPriceInput(value); }, - [onUserInput, onStartPriceInput] + [onStartPriceInput] ); return (
Date: Fri, 29 Mar 2024 21:12:13 +0700 Subject: [PATCH 3/3] fix: swap prices --- src/components/create-pool/SelectPair/index.tsx | 13 +++++++------ src/components/create-pool/Summary/index.tsx | 12 ++++++------ 2 files changed, 13 insertions(+), 12 deletions(-) diff --git a/src/components/create-pool/SelectPair/index.tsx b/src/components/create-pool/SelectPair/index.tsx index b5849b84..03f11f09 100644 --- a/src/components/create-pool/SelectPair/index.tsx +++ b/src/components/create-pool/SelectPair/index.tsx @@ -44,12 +44,12 @@ const SelectPair = ({ mintInfo, currencyA, currencyB }: ISelectPair) => { return (
+
); }; diff --git a/src/components/create-pool/Summary/index.tsx b/src/components/create-pool/Summary/index.tsx index 7c367ab5..176515ee 100644 --- a/src/components/create-pool/Summary/index.tsx +++ b/src/components/create-pool/Summary/index.tsx @@ -1,7 +1,7 @@ import CurrencyLogo from '@/components/common/CurrencyLogo'; import { Skeleton } from '@/components/ui/skeleton'; import { useSingleTokenQuery } from '@/graphql/generated/graphql'; -import { useSwapState } from '@/state/swapStore'; +import { useMintState } from '@/state/mintStore'; import { Currency } from '@cryptoalgebra/integral-sdk'; import { useEffect, useState } from 'react'; import { Address } from 'viem'; @@ -13,7 +13,7 @@ interface ISummary { const Summary = ({ currencyA, currencyB }: ISummary) => { const [suggestedPrice, setSuggestedPrice] = useState(0); - const { typedValue } = useSwapState(); + const { startPriceTypedValue } = useMintState(); const token0 = currencyA?.wrapped.address.toLowerCase() as Address; const token1 = currencyB?.wrapped.address.toLowerCase() as Address; @@ -67,15 +67,15 @@ const Summary = ({ currencyA, currencyB }: ISummary) => { )}
- {`1 ${currencyB?.symbol} = ${typedValue || 0} ${ - currencyA?.symbol + {`1 ${currencyA?.symbol} = ${startPriceTypedValue || 0} ${ + currencyB?.symbol }`}
{suggestedPrice > 0 && (
-

Suggested price:

-

{` 1 ${currencyB?.symbol} = ${suggestedPrice} ${currencyA?.symbol}`}

+

Suggested price:

+

{` 1 ${currencyA?.symbol} = ${suggestedPrice} ${currencyB?.symbol}`}

)}