Uniswap / interface

🦄 Open source interfaces for the Uniswap protocol
https://app.uniswap.org
GNU General Public License v3.0
4.9k stars 4.98k forks source link

ActiveTick is incorrectly determined for stablecoin pools. #7675

Open beejuice opened 6 months ago

beejuice commented 6 months ago

Quite often in stablecoin pairs, the current tick can be equal to zero. And this check does not work correctly.

const getActiveTick = (tickCurrent: number | undefined, feeAmount: FeeAmount | undefined) => tickCurrent && feeAmount ? Math.floor(tickCurrent / TICK_SPACINGS[feeAmount]) * TICK_SPACINGS[feeAmount] : undefined

I suggest as a replacement:

const getActiveTick = (tickCurrent: number | undefined, feeAmount: FeeAmount | undefined) => typeof tickCurrent === 'number' && feeAmount ? Math.floor(tickCurrent / TICK_SPACINGS[feeAmount]) * TICK_SPACINGS[feeAmount] : undefined