Skip to content

Commit

Permalink
hotfix: crash farm due to token not found (#2370)
Browse files Browse the repository at this point in the history
* hotfix: crash farm due to token not found

* feat: update minzapamount
  • Loading branch information
viet-nv authored Nov 8, 2023
1 parent 4cddec4 commit 93cb63d
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 14 deletions.
4 changes: 2 additions & 2 deletions src/components/YieldPools/ElasticFarmGroup/FarmCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down
8 changes: 6 additions & 2 deletions src/components/YieldPools/ElasticFarmGroup/Row.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down
18 changes: 12 additions & 6 deletions src/hooks/elasticZap/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
20 changes: 18 additions & 2 deletions src/pages/Farm/ElasticFarmv2/components/FarmCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -208,6 +209,8 @@ function FarmCard({

const range = farm.ranges.find(range => range.index === activeRangeIndex)

const allTokens = useAllTokens()

return (
<>
<Wrapper hasRewards={canUnstake}>
Expand All @@ -221,8 +224,21 @@ function FarmCard({
}}
>
<Text fontSize="16px" lineHeight="20px" color={theme.primary}>
{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,
)}
</Text>
</Link>
<IconButton>
Expand Down
20 changes: 18 additions & 2 deletions src/pages/Farm/ElasticFarmv2/components/ListView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -114,6 +115,8 @@ export const ListView = ({
const [errorMessage, setErrorMessage] = useState('')
const [attemptingTxn, setAttemptingTxn] = useState(false)

const allTokens = useAllTokens()

const handleDismiss = () => {
setTxHash('')
setShowConfirmModal(false)
Expand Down Expand Up @@ -173,8 +176,21 @@ export const ListView = ({
}}
>
<Text fontSize={14} fontWeight={500}>
{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,
)}
</Text>
</Link>

Expand Down

0 comments on commit 93cb63d

Please sign in to comment.