Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
I
interface
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
LuckySwap
interface
Commits
24521f0c
Unverified
Commit
24521f0c
authored
Apr 02, 2021
by
Noah Zinsmeister
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
deploy new tick lens, fix hook
parent
a037595e
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
63 additions
and
20 deletions
+63
-20
index.ts
src/constants/v3/index.ts
+1
-1
useAllV3Ticks.ts
src/hooks/useAllV3Ticks.ts
+62
-19
No files found.
src/constants/v3/index.ts
View file @
24521f0c
...
@@ -15,7 +15,7 @@ export const TICK_LENS_ADDRESSES: { [chainId in ChainId | 1337]: string } = {
...
@@ -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
]:
'
0x
e0507a63E40Ce227CbF2ed7273a01066bAFE667B
'
,
[
1337
]:
'
0x
99Cb00560BFca3E5B7Cda8e820dDFF1ED403966E
'
,
}
}
export
const
NONFUNGIBLE_POSITION_MANAGER_ADDRESSES
:
{
[
chainId
in
ChainId
|
1337
]:
string
}
=
{
export
const
NONFUNGIBLE_POSITION_MANAGER_ADDRESSES
:
{
[
chainId
in
ChainId
|
1337
]:
string
}
=
{
...
...
src/hooks/useAllV3Ticks.ts
View file @
24521f0c
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) {
...
@@ -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
(
.
fill
(
0
)
()
=>
.
map
((
_
,
i
)
=>
i
+
minIndex
)
new
Array
(
maxIndex
-
minIndex
+
1
)
.
map
((
wordIndex
)
=>
[
poolAddress
,
wordIndex
])
.
fill
(
0
)
.
map
((
_
,
i
)
=>
i
+
minIndex
)
.
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
,
}
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment