deploy new tick lens, fix hook
This commit is contained in:
parent
a037595e6e
commit
24521f0c92
@ -15,7 +15,7 @@ export const TICK_LENS_ADDRESSES: { [chainId in ChainId | 1337]: string } = {
|
|||||||
[ChainId.RINKEBY]: '',
|
[ChainId.RINKEBY]: '',
|
||||||
[ChainId.GÖRLI]: '',
|
[ChainId.GÖRLI]: '',
|
||||||
[ChainId.KOVAN]: '',
|
[ChainId.KOVAN]: '',
|
||||||
[1337]: '0xe0507a63E40Ce227CbF2ed7273a01066bAFE667B',
|
[1337]: '0x99Cb00560BFca3E5B7Cda8e820dDFF1ED403966E',
|
||||||
}
|
}
|
||||||
|
|
||||||
export const NONFUNGIBLE_POSITION_MANAGER_ADDRESSES: { [chainId in ChainId | 1337]: string } = {
|
export const NONFUNGIBLE_POSITION_MANAGER_ADDRESSES: { [chainId in ChainId | 1337]: string } = {
|
||||||
|
@ -1,3 +1,4 @@
|
|||||||
|
import { useMemo } from 'react'
|
||||||
import { Result, useSingleContractMultipleData } from 'state/multicall/hooks'
|
import { Result, useSingleContractMultipleData } from 'state/multicall/hooks'
|
||||||
import { useTickLens } from './useContract'
|
import { useTickLens } from './useContract'
|
||||||
|
|
||||||
@ -11,38 +12,80 @@ function MAX_TICK(tickSpacing: number) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function bitmapIndex(tick: number, tickSpacing: number) {
|
function bitmapIndex(tick: number, tickSpacing: number) {
|
||||||
return (tick / tickSpacing) >> 8
|
const compressed = tick / tickSpacing
|
||||||
|
return compressed >> 8
|
||||||
}
|
}
|
||||||
|
|
||||||
// todo this hook needs some tlc around return values
|
const REFRESH_FREQUENCY = { blocksPerFetch: 10 }
|
||||||
export function useAllV3Ticks(poolAddress: string, tickSpacing: number): Result[] | null {
|
|
||||||
|
interface TickData {
|
||||||
|
tick: number
|
||||||
|
liquidityNet: number
|
||||||
|
liquidityGross: number
|
||||||
|
}
|
||||||
|
|
||||||
|
export function useAllV3Ticks(
|
||||||
|
poolAddress: string,
|
||||||
|
tickSpacing: number
|
||||||
|
): {
|
||||||
|
loading: boolean
|
||||||
|
syncing: boolean
|
||||||
|
error: boolean
|
||||||
|
valid: boolean
|
||||||
|
tickData: TickData[]
|
||||||
|
} {
|
||||||
const tickLens = useTickLens()
|
const tickLens = useTickLens()
|
||||||
|
|
||||||
const min = MIN_TICK(tickSpacing)
|
const minIndex = useMemo(() => bitmapIndex(MIN_TICK(tickSpacing), tickSpacing), [tickSpacing])
|
||||||
const max = MAX_TICK(tickSpacing)
|
const maxIndex = useMemo(() => bitmapIndex(MAX_TICK(tickSpacing), tickSpacing), [tickSpacing])
|
||||||
const minIndex = bitmapIndex(min, tickSpacing)
|
|
||||||
const maxIndex = bitmapIndex(max, tickSpacing)
|
|
||||||
|
|
||||||
const tickLensArgs = new Array(maxIndex - minIndex + 1)
|
const tickLensArgs = useMemo(
|
||||||
|
() =>
|
||||||
|
new Array(maxIndex - minIndex + 1)
|
||||||
.fill(0)
|
.fill(0)
|
||||||
.map((_, i) => i + minIndex)
|
.map((_, i) => i + minIndex)
|
||||||
.map((wordIndex) => [poolAddress, wordIndex])
|
.map((wordIndex) => [poolAddress, wordIndex]),
|
||||||
|
[minIndex, maxIndex, poolAddress]
|
||||||
|
)
|
||||||
|
|
||||||
const callStates = useSingleContractMultipleData(
|
const callStates = useSingleContractMultipleData(
|
||||||
tickLens,
|
tickLens,
|
||||||
'getPopulatedTicksInWord',
|
'getPopulatedTicksInWord',
|
||||||
tickLensArgs,
|
tickLensArgs,
|
||||||
undefined,
|
REFRESH_FREQUENCY,
|
||||||
2_000_000
|
2_000_000
|
||||||
)
|
)
|
||||||
|
|
||||||
const canReturn = callStates.every(
|
const error = useMemo(() => callStates.some(({ error }) => error), [callStates])
|
||||||
(callState) => !callState.error && !callState.loading && !callState.syncing && callState.valid && callState.result
|
const loading = useMemo(() => callStates.some(({ loading }) => loading), [callStates])
|
||||||
|
const syncing = useMemo(() => callStates.some(({ syncing }) => syncing), [callStates])
|
||||||
|
const valid = useMemo(() => callStates.some(({ valid }) => valid), [callStates])
|
||||||
|
|
||||||
|
const tickData = useMemo(
|
||||||
|
() =>
|
||||||
|
callStates
|
||||||
|
.map(({ result }) => (result as Result)?.populatedTicks)
|
||||||
|
.reduce(
|
||||||
|
(accumulator, current) => [
|
||||||
|
...accumulator,
|
||||||
|
...(current?.map((tickData: TickData) => {
|
||||||
|
return {
|
||||||
|
tick: tickData.tick,
|
||||||
|
liquidityNet: tickData.liquidityNet,
|
||||||
|
liquidityGross: tickData.liquidityGross,
|
||||||
|
}
|
||||||
|
}) ?? []),
|
||||||
|
],
|
||||||
|
[]
|
||||||
|
),
|
||||||
|
[callStates]
|
||||||
)
|
)
|
||||||
|
|
||||||
return canReturn
|
return {
|
||||||
? callStates
|
loading,
|
||||||
.map(({ result }) => (result as Result).populatedTicks)
|
syncing,
|
||||||
.reduce((accumulator, current) => [...accumulator, ...current], [])
|
error,
|
||||||
: null
|
valid,
|
||||||
|
tickData,
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user