2021-04-23 05:58:03 +03:00
|
|
|
import { Pool, Position } from '@uniswap/v3-sdk'
|
2021-04-24 01:31:36 +03:00
|
|
|
import { usePool } from 'hooks/usePools'
|
2021-04-23 05:58:03 +03:00
|
|
|
import { PositionDetails } from 'types/position'
|
|
|
|
import { useCurrency } from './Tokens'
|
|
|
|
|
2021-04-24 05:12:34 +03:00
|
|
|
export function useDerivedPositionInfo(
|
2021-04-23 05:58:03 +03:00
|
|
|
positionDetails: PositionDetails | undefined
|
|
|
|
): {
|
|
|
|
position: Position | undefined
|
|
|
|
pool: Pool | undefined
|
2021-04-24 05:12:34 +03:00
|
|
|
} {
|
2021-04-23 05:58:03 +03:00
|
|
|
const currency0 = useCurrency(positionDetails?.token0)
|
|
|
|
const currency1 = useCurrency(positionDetails?.token1)
|
|
|
|
|
|
|
|
// construct pool data
|
|
|
|
const [, pool] = usePool(currency0 ?? undefined, currency1 ?? undefined, positionDetails?.fee)
|
|
|
|
|
|
|
|
let position = undefined
|
|
|
|
if (pool && positionDetails) {
|
|
|
|
position = new Position({
|
|
|
|
pool,
|
2021-04-24 05:12:34 +03:00
|
|
|
liquidity: positionDetails.liquidity.toString(),
|
2021-04-23 05:58:03 +03:00
|
|
|
tickLower: positionDetails.tickLower,
|
|
|
|
tickUpper: positionDetails.tickUpper,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
return {
|
|
|
|
position,
|
|
|
|
pool: pool ?? undefined,
|
|
|
|
}
|
|
|
|
}
|