From f842f9890eca0bc55a4fe8f62c9e76c37966fc91 Mon Sep 17 00:00:00 2001 From: viet-nv Date: Wed, 8 Nov 2023 15:35:40 +0700 Subject: [PATCH 1/2] hotfix: crash farm due to token not found --- .../YieldPools/ElasticFarmGroup/FarmCard.tsx | 4 ++-- .../YieldPools/ElasticFarmGroup/Row.tsx | 8 ++++++-- .../ElasticFarmv2/components/FarmCard.tsx | 20 +++++++++++++++++-- .../ElasticFarmv2/components/ListView.tsx | 20 +++++++++++++++++-- 4 files changed, 44 insertions(+), 8 deletions(-) diff --git a/src/components/YieldPools/ElasticFarmGroup/FarmCard.tsx b/src/components/YieldPools/ElasticFarmGroup/FarmCard.tsx index da59ae8b83..119ecd2f3c 100644 --- a/src/components/YieldPools/ElasticFarmGroup/FarmCard.tsx +++ b/src/components/YieldPools/ElasticFarmGroup/FarmCard.tsx @@ -109,12 +109,12 @@ const FarmCard = ({ const token0Symbol = getTokenSymbolWithHardcode( chainId, pool?.token0?.wrapped?.address, - pool.token0.isNative ? pool.token0.symbol : allTokens[pool.token0.wrapped.address].symbol, + pool.token0.isNative ? pool.token0.symbol : allTokens[pool.token0.wrapped.address]?.symbol || pool.token0.symbol, ) const token1Symbol = getTokenSymbolWithHardcode( chainId, pool?.token1?.wrapped?.address, - pool.token1.isNative ? pool.token1.symbol : allTokens[pool.token1.wrapped.address].symbol, + pool.token1.isNative ? pool.token1.symbol : allTokens[pool.token1.wrapped.address]?.symbol || pool.token1.symbol, ) return ( diff --git a/src/components/YieldPools/ElasticFarmGroup/Row.tsx b/src/components/YieldPools/ElasticFarmGroup/Row.tsx index 1141ed3295..1cf7af8ec4 100644 --- a/src/components/YieldPools/ElasticFarmGroup/Row.tsx +++ b/src/components/YieldPools/ElasticFarmGroup/Row.tsx @@ -311,12 +311,16 @@ const Row = ({ const symbol0 = getTokenSymbolWithHardcode( chainId, farmingPool.token0.wrapped.address, - farmingPool.token0.isNative ? farmingPool.token0.symbol : allTokens[farmingPool.token0.wrapped.address].symbol, + farmingPool.token0.isNative + ? farmingPool.token0.symbol + : allTokens[farmingPool.token0.wrapped.address]?.symbol || farmingPool.token0.symbol, ) const symbol1 = getTokenSymbolWithHardcode( chainId, farmingPool.token1.wrapped.address, - farmingPool.token1.isNative ? farmingPool.token1.symbol : allTokens[farmingPool.token1.wrapped.address].symbol, + farmingPool.token1.isNative + ? farmingPool.token1.symbol + : allTokens[farmingPool.token1.wrapped.address]?.symbol || farmingPool.token1.symbol, ) return ( diff --git a/src/pages/Farm/ElasticFarmv2/components/FarmCard.tsx b/src/pages/Farm/ElasticFarmv2/components/FarmCard.tsx index 3de0fdcf6c..8466f71570 100644 --- a/src/pages/Farm/ElasticFarmv2/components/FarmCard.tsx +++ b/src/pages/Farm/ElasticFarmv2/components/FarmCard.tsx @@ -29,6 +29,7 @@ import { APRTooltipContent } from 'components/YieldPools/FarmingPoolAPRCell' import { PartnerFarmTag } from 'components/YieldPools/PartnerFarmTag' import { APP_PATHS, ELASTIC_BASE_FEE_UNIT } from 'constants/index' import { useActiveWeb3React } from 'hooks' +import { useAllTokens } from 'hooks/Tokens' import useTheme from 'hooks/useTheme' import { useShareFarmAddress } from 'state/farms/classic/hooks' import { useFarmV2Action, useUserFarmV2Info } from 'state/farms/elasticv2/hooks' @@ -208,6 +209,8 @@ function FarmCard({ const range = farm.ranges.find(range => range.index === activeRangeIndex) + const allTokens = useAllTokens() + return ( <> @@ -221,8 +224,21 @@ function FarmCard({ }} > - {getTokenSymbolWithHardcode(chainId, farm.token0.wrapped.address, farm.token0.symbol)} -{' '} - {getTokenSymbolWithHardcode(chainId, farm.token1.wrapped.address, farm.token1.symbol)} + {getTokenSymbolWithHardcode( + chainId, + farm.token0.wrapped.address, + farm.token0.isNative + ? farm.token0.symbol + : allTokens[farm.token0.address]?.symbol || farm.token0.symbol, + )}{' '} + -{' '} + {getTokenSymbolWithHardcode( + chainId, + farm.token1.wrapped.address, + farm.token1.isNative + ? farm.token1.symbol + : allTokens[farm.token1.address]?.symbol || farm.token1.symbol, + )} diff --git a/src/pages/Farm/ElasticFarmv2/components/ListView.tsx b/src/pages/Farm/ElasticFarmv2/components/ListView.tsx index a4058de4cc..5596654067 100644 --- a/src/pages/Farm/ElasticFarmv2/components/ListView.tsx +++ b/src/pages/Farm/ElasticFarmv2/components/ListView.tsx @@ -27,6 +27,7 @@ import { PartnerFarmTag } from 'components/YieldPools/PartnerFarmTag' import { ElasticFarmV2TableRow } from 'components/YieldPools/styleds' import { APP_PATHS, ELASTIC_BASE_FEE_UNIT } from 'constants/index' import { useActiveWeb3React } from 'hooks' +import { useAllTokens } from 'hooks/Tokens' import useTheme from 'hooks/useTheme' import { useShareFarmAddress } from 'state/farms/classic/hooks' import { useFarmV2Action, useUserFarmV2Info } from 'state/farms/elasticv2/hooks' @@ -114,6 +115,8 @@ export const ListView = ({ const [errorMessage, setErrorMessage] = useState('') const [attemptingTxn, setAttemptingTxn] = useState(false) + const allTokens = useAllTokens() + const handleDismiss = () => { setTxHash('') setShowConfirmModal(false) @@ -173,8 +176,21 @@ export const ListView = ({ }} > - {getTokenSymbolWithHardcode(chainId, farm.token0.wrapped.address, farm.token0.symbol)} -{' '} - {getTokenSymbolWithHardcode(chainId, farm.token1.wrapped.address, farm.token1.symbol)} + {getTokenSymbolWithHardcode( + chainId, + farm.token0.wrapped.address, + farm.token0.isNative + ? farm.token0.symbol + : allTokens[farm.token0.address]?.symbol || farm.token0.symbol, + )}{' '} + -{' '} + {getTokenSymbolWithHardcode( + chainId, + farm.token1.wrapped.address, + farm.token1.isNative + ? farm.token1.symbol + : allTokens[farm.token1.address]?.symbol || farm.token1.symbol, + )} From e1d3bc9bee47683ecd5cd5250ebe58e2049c6192 Mon Sep 17 00:00:00 2001 From: viet-nv Date: Wed, 8 Nov 2023 16:08:22 +0700 Subject: [PATCH 2/2] feat: update minzapamount --- src/hooks/elasticZap/index.ts | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/src/hooks/elasticZap/index.ts b/src/hooks/elasticZap/index.ts index 29450bc701..65c2deba0e 100644 --- a/src/hooks/elasticZap/index.ts +++ b/src/hooks/elasticZap/index.ts @@ -257,18 +257,24 @@ export function useZapInAction() { : abiEncoder.encode(['address', 'int24', 'int24', 'uint128'], [account, tickLower, tickUpper, minLiquidity]) const zeros = '0'.repeat(128) + + // max(1, 0.00001% * amount) + const exp6 = JSBI.BigInt(1_000_000) const minZapAmount0 = JSBI.divide( - JSBI.multiply(JSBI.BigInt(amountIn), JSBI.BigInt(slippage)), - JSBI.BigInt(10000), + JSBI.multiply(JSBI.greaterThan(JSBI.BigInt(amountIn), exp6) ? JSBI.BigInt(amountIn) : exp6, JSBI.BigInt(1)), + exp6, ).toString(2) const minZapAmount1 = JSBI.divide( - JSBI.multiply(JSBI.BigInt(equivalentQuoteAmount), JSBI.BigInt(slippage)), - JSBI.BigInt(10000), + JSBI.multiply( + JSBI.greaterThan(JSBI.BigInt(equivalentQuoteAmount), exp6) ? JSBI.BigInt(equivalentQuoteAmount) : exp6, + JSBI.BigInt(1), + ), + exp6, ).toString(2) - const minZapAmount = JSBI.BigInt( - parseInt((zeros + minZapAmount0).slice(-128) + (zeros + minZapAmount1).slice(-128), 2), + const minZapAmount = BigInt( + '0b' + (zeros + minZapAmount0).slice(-128) + (zeros + minZapAmount1).slice(-128), ).toString() const zapExecutorData = abiEncoder.encode(