From 29788bc6b640b6718eef53ce705338f48c68d2f2 Mon Sep 17 00:00:00 2001 From: Nam Nguyen Date: Wed, 13 Sep 2023 17:09:22 +0700 Subject: [PATCH 1/4] feat: autofill starting price --- src/pages/AddLiquidityV2/index.tsx | 31 +++++++++++++++++------------- 1 file changed, 18 insertions(+), 13 deletions(-) diff --git a/src/pages/AddLiquidityV2/index.tsx b/src/pages/AddLiquidityV2/index.tsx index 6b6de01c6f..3113cf9881 100644 --- a/src/pages/AddLiquidityV2/index.tsx +++ b/src/pages/AddLiquidityV2/index.tsx @@ -46,11 +46,9 @@ import Tooltip, { MouseoverTooltip } from 'components/Tooltip' import TransactionConfirmationModal, { ConfirmationModalContent } from 'components/TransactionConfirmationModal' import { TutorialType } from 'components/Tutorial' import { Dots } from 'components/swapv2/styleds' -import { ENV_LEVEL } from 'constants/env' import { APP_PATHS } from 'constants/index' import { EVMNetworkInfo } from 'constants/networks/type' import { NativeCurrencies } from 'constants/tokens' -import { ENV_TYPE } from 'constants/type' import { useActiveWeb3React, useWeb3React } from 'hooks' import { useCurrency } from 'hooks/Tokens' import { ApprovalState, useApproveCallback } from 'hooks/useApproveCallback' @@ -88,7 +86,7 @@ import { basisPointsToPercent, calculateGasMargin, formattedNum } from 'utils' import { currencyId } from 'utils/currencyId' import { friendlyError } from 'utils/errorMessage' import { maxAmountSpend } from 'utils/maxAmountSpend' -import { formatDisplayNumber } from 'utils/numbers' +import { formatDisplayNumber, toFixed } from 'utils/numbers' import { SLIPPAGE_STATUS, checkRangeSlippage } from 'utils/slippage' import { unwrappedToken } from 'utils/wrappedCurrency' @@ -384,6 +382,10 @@ export default function AddLiquidity() { fetchPrices, refetch, } = useTokenPricesWithLoading(tokens.map(t => t?.wrapped.address || '')) + const marketPrice = + usdPrices[quoteCurrency?.wrapped.address || ''] && + usdPrices[baseCurrency?.wrapped.address || ''] && + usdPrices[baseCurrency?.wrapped.address || ''] / usdPrices[quoteCurrency?.wrapped.address || ''] useInterval(refetch, 10_000) @@ -616,14 +618,22 @@ export default function AddLiquidity() { }, [navigate, networkInfo.route, onFieldAInput, txHash]) const handleDismissConfirmationRef = useRef(handleDismissConfirmation) + + const [waitForMarketPrice, setWaitForMarketPrice] = useState(false) useEffect(() => { - if (ENV_LEVEL > ENV_TYPE.LOCAL) { - setPositionIndex(0) - onResetMintState() - handleDismissConfirmationRef.current() - } + setPositionIndex(0) + onResetMintState() + handleDismissConfirmationRef.current() + setWaitForMarketPrice(true) }, [onResetMintState, baseCurrency?.wrapped.address, quoteCurrency?.wrapped.address, feeAmount, chainId]) + useEffect(() => { + if (waitForMarketPrice && marketPrice) { + onStartPriceInput(toFixed(marketPrice)) + setWaitForMarketPrice(false) + } + }, [waitForMarketPrice, marketPrice, onStartPriceInput]) + const leftPrice = isSorted ? priceLower : priceUpper?.invert() const rightPrice = isSorted ? priceUpper : priceLower?.invert() @@ -1287,11 +1297,6 @@ export default function AddLiquidity() { const tightTokenSelect = !upToMedium && upToLarge - const marketPrice = - usdPrices[quoteCurrency?.wrapped.address || ''] && - usdPrices[baseCurrency?.wrapped.address || ''] && - usdPrices[baseCurrency?.wrapped.address || ''] / usdPrices[quoteCurrency?.wrapped.address || ''] - const onFarmRangeSelected = useCallback( (tickLower: number, tickUpper: number) => { const tickSpacing = TICK_SPACINGS[feeAmount] From aa37eaf6cbea671b4ee470c5461f30be4570baca Mon Sep 17 00:00:00 2001 From: Nam Nguyen Date: Thu, 14 Sep 2023 11:30:32 +0700 Subject: [PATCH 2/4] prod env --- .github/workflows/pr.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/pr.yaml b/.github/workflows/pr.yaml index 4fc367b68b..0b9eaa7c9a 100644 --- a/.github/workflows/pr.yaml +++ b/.github/workflows/pr.yaml @@ -114,7 +114,7 @@ jobs: VITE_TAG: ${{ needs.prepare.outputs.image_tag }} CURRENT_BRANCH: ${{ needs.prepare.outputs.current_branch }} NODE_OPTIONS: '--max_old_space_size=4096' - run: yarn build-adpr + run: yarn build-prod - name: Docker build and push uses: docker/build-push-action@v2 From 833faf5e80e393360079c54e5888b3482bb1bb98 Mon Sep 17 00:00:00 2001 From: Nam Nguyen Date: Thu, 14 Sep 2023 16:49:20 +0700 Subject: [PATCH 3/4] fix: crash on add liquidity elastic on zksync --- src/constants/networks/zksync.ts | 15 +- src/pages/AddLiquidityV2/index.tsx | 441 +++++++++++++++-------------- 2 files changed, 240 insertions(+), 216 deletions(-) diff --git a/src/constants/networks/zksync.ts b/src/constants/networks/zksync.ts index a0294e035a..188b1e9330 100644 --- a/src/constants/networks/zksync.ts +++ b/src/constants/networks/zksync.ts @@ -47,14 +47,15 @@ const zkSyncInfo: EVMNetworkInfo = { fairlaunchV2: [], }, elastic: { - defaultSubgraph: '', + // zkSync not supports elastic + defaultSubgraph: 'https://api.thegraph.com/subgraphs/name/kybernetwork/kyberswap-elastic-zksync', startBlock: 0, - coreFactory: '', - nonfungiblePositionManager: '', - tickReader: '', - initCodeHash: '', - quoter: '', - routers: '', + coreFactory: '0x5F1dddbf348aC2fbe22a163e30F99F9ECE3DD50a', + nonfungiblePositionManager: '0x2B1c7b41f6A8F2b2bc45C3233a5d5FB3cD6dC9A8', + tickReader: '0x165c68077ac06c83800d19200e6E2B08D02dE75D', + initCodeHash: '0xc597aba1bb02db42ba24a8878837965718c032f8b46be94a6e46452a9f89ca01', + quoter: '0x0D125c15D54cA1F8a813C74A81aEe34ebB508C1f', + routers: '0xC1e7dFE73E1598E3910EF4C7845B68A9Ab6F4c83', farms: [], }, limitOrder: NOT_SUPPORT, diff --git a/src/pages/AddLiquidityV2/index.tsx b/src/pages/AddLiquidityV2/index.tsx index 3113cf9881..e1547b3d59 100644 --- a/src/pages/AddLiquidityV2/index.tsx +++ b/src/pages/AddLiquidityV2/index.tsx @@ -47,6 +47,7 @@ import TransactionConfirmationModal, { ConfirmationModalContent } from 'componen import { TutorialType } from 'components/Tutorial' import { Dots } from 'components/swapv2/styleds' import { APP_PATHS } from 'constants/index' +import { ELASTIC_NOT_SUPPORTED } from 'constants/networks' import { EVMNetworkInfo } from 'constants/networks/type' import { NativeCurrencies } from 'constants/tokens' import { useActiveWeb3React, useWeb3React } from 'hooks' @@ -61,7 +62,7 @@ import useTheme from 'hooks/useTheme' import useTransactionDeadline from 'hooks/useTransactionDeadline' import { convertTickToPrice } from 'pages/Farm/ElasticFarmv2/utils' import { ApplicationModal } from 'state/application/actions' -import { useNotify, useOpenModal, useWalletModalToggle } from 'state/application/hooks' +import { useNotify, useOpenModal, useOpenNetworkModal, useWalletModalToggle } from 'state/application/hooks' import { FarmUpdater } from 'state/farms/elastic/hooks' import { useElasticFarmsV2 } from 'state/farms/elasticv2/hooks' import ElasticFarmV2Updater from 'state/farms/elasticv2/updater' @@ -131,6 +132,7 @@ export default function AddLiquidity() { const { account, chainId, isEVM, networkInfo } = useActiveWeb3React() const { library } = useWeb3React() const theme = useTheme() + const openNetworkModal = useOpenNetworkModal() const toggleWalletModal = useWalletModalToggle() // toggle wallet when disconnected const [isDegenMode] = useDegenModeManager() const addTransactionWithType = useTransactionAdder() @@ -1400,222 +1402,243 @@ export default function AddLiquidity() { tutorialType={TutorialType.ELASTIC_ADD_LIQUIDITY} /> - - - - - Choose pool - -
- { - if (tokenA?.symbol && tokenB?.symbol) - mixpanelHandler(MIXPANEL_TYPE.ELASTIC_ADD_LIQUIDITY_CLICK_SWAP, { - token_1: tokenA?.symbol, - token_2: tokenB?.symbol, - }) - }} - > - - - Swap - - -
-
- + {ELASTIC_NOT_SUPPORTED[chainId]} + - - - { - if (!!rightPrice) { - onLeftRangeInput(rightPrice?.invert().toString()) - } - if (!!leftPrice) { - onRightRangeInput(leftPrice?.invert().toString()) - } - setRotate(prev => !prev) - }} - > - {!currencyIdA && !currencyIdB ? ( - - ) : ( - - - - )} - - - - - - - Select fee tier - - - - - {noLiquidity ? ( - - - - - Set Starting Price - - - - - - To initialize this pool, select a starting price for the pool then enter your liquidity price - range. - - - - - - - - - - - - Starting Price - - - {price ? ( - - - - - - ) : ( - '-' - )} - - - fetchPrices(tokens.map(t => t?.wrapped.address || ''))} - marketPrice={marketPrice} - baseCurrency={baseCurrency} - quoteCurrency={quoteCurrency} - /> - - - ) : ( - poolStatRef.current && ( - <> - - - Pool Stats - - { + Change network + + + ) : ( + <> + + + + + Choose pool + +
+ { if (tokenA?.symbol && tokenB?.symbol) - mixpanelHandler(MIXPANEL_TYPE.ELASTIC_ADD_LIQUIDITY_CLICK_POOL_ANALYTIC, { + mixpanelHandler(MIXPANEL_TYPE.ELASTIC_ADD_LIQUIDITY_CLICK_SWAP, { token_1: tokenA?.symbol, token_2: tokenB?.symbol, }) }} - /> - - + + + Swap + + +
+
+ + - - ) - )} - {upToMedium && chart} -
- {!upToMedium && {chart}} -
- - {warnings && ( - - {warnings} - - )} - - - - - - - + { + if (!!rightPrice) { + onLeftRangeInput(rightPrice?.invert().toString()) + } + if (!!leftPrice) { + onRightRangeInput(leftPrice?.invert().toString()) + } + setRotate(prev => !prev) + }} + > + {!currencyIdA && !currencyIdB ? ( + + ) : ( + + + + )} + + + + + + + Select fee tier + + + + + {noLiquidity ? ( + + + + + Set Starting Price + + + + + + To initialize this pool, select a starting price for the pool then enter your liquidity + price range. + + + + + + + + + + + + Starting Price + + + {price ? ( + + + + + + ) : ( + '-' + )} + + + fetchPrices(tokens.map(t => t?.wrapped.address || ''))} + marketPrice={marketPrice} + baseCurrency={baseCurrency} + quoteCurrency={quoteCurrency} + /> + + + ) : ( + poolStatRef.current && ( + <> + + + Pool Stats + + { + if (tokenA?.symbol && tokenB?.symbol) + mixpanelHandler(MIXPANEL_TYPE.ELASTIC_ADD_LIQUIDITY_CLICK_POOL_ANALYTIC, { + token_1: tokenA?.symbol, + token_2: tokenB?.symbol, + }) + }} + /> + + + + ) + )} + {upToMedium && chart} +
+ {!upToMedium && {chart}} +
+ + {warnings && ( + + {warnings} + + )} + + + + + + + + + + )}
From 456248b2ddefb2ef92eaba3abda2e693a02fd531 Mon Sep 17 00:00:00 2001 From: Nam Nguyen Date: Fri, 15 Sep 2023 17:15:43 +0700 Subject: [PATCH 4/4] revert env --- .github/workflows/pr.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/pr.yaml b/.github/workflows/pr.yaml index 0b9eaa7c9a..4fc367b68b 100644 --- a/.github/workflows/pr.yaml +++ b/.github/workflows/pr.yaml @@ -114,7 +114,7 @@ jobs: VITE_TAG: ${{ needs.prepare.outputs.image_tag }} CURRENT_BRANCH: ${{ needs.prepare.outputs.current_branch }} NODE_OPTIONS: '--max_old_space_size=4096' - run: yarn build-prod + run: yarn build-adpr - name: Docker build and push uses: docker/build-push-action@v2