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
f5fc5da3
Unverified
Commit
f5fc5da3
authored
May 12, 2021
by
Noah Zinsmeister
Committed by
GitHub
May 12, 2021
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix erroneous addition of tokensOwned{0,1} (#1533)
only pass tokenId to useV3PositionFees
parent
bea5c048
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
13 additions
and
16 deletions
+13
-16
useV3PositionFees.ts
src/hooks/useV3PositionFees.ts
+11
-14
PositionPage.tsx
src/pages/Pool/PositionPage.tsx
+1
-1
hooks.ts
src/state/burn/v3/hooks.ts
+1
-1
No files found.
src/hooks/useV3PositionFees.ts
View file @
f5fc5da3
import
{
useSingleCallResult
}
from
'
state/multicall/hooks
'
import
{
useSingleCallResult
}
from
'
state/multicall/hooks
'
import
{
useEffect
,
useState
}
from
'
react
'
import
{
useEffect
,
useState
}
from
'
react
'
import
{
PositionDetails
}
from
'
types/position
'
import
{
useV3NFTPositionManagerContract
}
from
'
./useContract
'
import
{
useV3NFTPositionManagerContract
}
from
'
./useContract
'
import
{
BigNumber
}
from
'
@ethersproject/bignumber
'
import
{
BigNumber
}
from
'
@ethersproject/bignumber
'
import
{
Pool
}
from
'
@uniswap/v3-sdk
'
import
{
Pool
}
from
'
@uniswap/v3-sdk
'
...
@@ -12,26 +11,24 @@ const MAX_UINT128 = BigNumber.from(2).pow(128).sub(1)
...
@@ -12,26 +11,24 @@ const MAX_UINT128 = BigNumber.from(2).pow(128).sub(1)
// compute current + counterfactual fees for a v3 position
// compute current + counterfactual fees for a v3 position
export
function
useV3PositionFees
(
export
function
useV3PositionFees
(
pool
?:
Pool
,
pool
?:
Pool
,
positionDetails
?:
PositionDetails
tokenId
?:
BigNumber
):
[
CurrencyAmount
<
Token
>
,
CurrencyAmount
<
Token
>
]
|
[
undefined
,
undefined
]
{
):
[
CurrencyAmount
<
Token
>
,
CurrencyAmount
<
Token
>
]
|
[
undefined
,
undefined
]
{
const
positionManager
=
useV3NFTPositionManagerContract
(
false
)
const
positionManager
=
useV3NFTPositionManagerContract
(
false
)
const
owner
=
useSingleCallResult
(
positionDetails
?.
tokenId
?
positionManager
:
null
,
'
ownerOf
'
,
[
const
owner
=
useSingleCallResult
(
tokenId
?
positionManager
:
null
,
'
ownerOf
'
,
[
tokenId
]).
result
?.[
0
]
positionDetails
?.
tokenId
,
]).
result
?.[
0
]
const
tokenId
=
positionDetails
?.
tokenId
?.
toHexString
()
const
tokenId
HexString
=
tokenId
?.
toHexString
()
const
latestBlockNumber
=
useBlockNumber
()
const
latestBlockNumber
=
useBlockNumber
()
// TODO find a way to get this into multicall
// TODO find a way to get this into multicall
// because
fee
s don't ever go down, we don't actually need to clear this state
// because
these amount
s don't ever go down, we don't actually need to clear this state
// latestBlockNumber is included to ensure data stays up-to-date
fresh
// latestBlockNumber is included to ensure data stays up-to-date
every block
const
[
amounts
,
setAmounts
]
=
useState
<
[
BigNumber
,
BigNumber
]
>
()
const
[
amounts
,
setAmounts
]
=
useState
<
[
BigNumber
,
BigNumber
]
>
()
useEffect
(()
=>
{
useEffect
(()
=>
{
if
(
positionManager
&&
tokenId
&&
owner
&&
typeof
latestBlockNumber
===
'
number
'
)
{
if
(
positionManager
&&
tokenId
HexString
&&
owner
&&
typeof
latestBlockNumber
===
'
number
'
)
{
positionManager
.
callStatic
positionManager
.
callStatic
.
collect
(
.
collect
(
{
{
tokenId
,
tokenId
:
tokenIdHexString
,
recipient
:
owner
,
// some tokens might fail if transferred to address(0)
recipient
:
owner
,
// some tokens might fail if transferred to address(0)
amount0Max
:
MAX_UINT128
,
amount0Max
:
MAX_UINT128
,
amount1Max
:
MAX_UINT128
,
amount1Max
:
MAX_UINT128
,
...
@@ -42,12 +39,12 @@ export function useV3PositionFees(
...
@@ -42,12 +39,12 @@ export function useV3PositionFees(
setAmounts
([
results
.
amount0
,
results
.
amount1
])
setAmounts
([
results
.
amount0
,
results
.
amount1
])
})
})
}
}
},
[
positionManager
,
tokenId
,
owner
,
latestBlockNumber
])
},
[
positionManager
,
tokenId
HexString
,
owner
,
latestBlockNumber
])
if
(
pool
&&
positionDetails
&&
amounts
)
{
if
(
pool
&&
amounts
)
{
return
[
return
[
CurrencyAmount
.
fromRawAmount
(
pool
.
token0
,
positionDetails
.
tokensOwed0
.
add
(
amounts
[
0
])
.
toString
()),
CurrencyAmount
.
fromRawAmount
(
pool
.
token0
,
amounts
[
0
]
.
toString
()),
CurrencyAmount
.
fromRawAmount
(
pool
.
token1
,
positionDetails
.
tokensOwed1
.
add
(
amounts
[
1
])
.
toString
()),
CurrencyAmount
.
fromRawAmount
(
pool
.
token1
,
amounts
[
1
]
.
toString
()),
]
]
}
else
{
}
else
{
return
[
undefined
,
undefined
]
return
[
undefined
,
undefined
]
...
...
src/pages/Pool/PositionPage.tsx
View file @
f5fc5da3
...
@@ -243,7 +243,7 @@ export function PositionPage({
...
@@ -243,7 +243,7 @@ export function PositionPage({
},
[
inverted
,
pool
,
priceLower
,
priceUpper
])
},
[
inverted
,
pool
,
priceLower
,
priceUpper
])
// fees
// fees
const
[
feeValue0
,
feeValue1
]
=
useV3PositionFees
(
pool
??
undefined
,
positionDetails
)
const
[
feeValue0
,
feeValue1
]
=
useV3PositionFees
(
pool
??
undefined
,
positionDetails
?.
tokenId
)
const
[
collecting
,
setCollecting
]
=
useState
<
boolean
>
(
false
)
const
[
collecting
,
setCollecting
]
=
useState
<
boolean
>
(
false
)
const
[
collectMigrationHash
,
setCollectMigrationHash
]
=
useState
<
string
|
null
>
(
null
)
const
[
collectMigrationHash
,
setCollectMigrationHash
]
=
useState
<
string
|
null
>
(
null
)
...
...
src/state/burn/v3/hooks.ts
View file @
f5fc5da3
...
@@ -63,7 +63,7 @@ export function useDerivedV3BurnInfo(
...
@@ -63,7 +63,7 @@ export function useDerivedV3BurnInfo(
liquidityPercentage
.
multiply
(
positionSDK
.
amount1
.
quotient
).
quotient
liquidityPercentage
.
multiply
(
positionSDK
.
amount1
.
quotient
).
quotient
)
)
const
[
feeValue0
,
feeValue1
]
=
useV3PositionFees
(
pool
??
undefined
,
position
)
const
[
feeValue0
,
feeValue1
]
=
useV3PositionFees
(
pool
??
undefined
,
position
?.
tokenId
)
const
outOfRange
=
const
outOfRange
=
pool
&&
position
?
pool
.
tickCurrent
<
position
.
tickLower
||
pool
.
tickCurrent
>
position
.
tickUpper
:
false
pool
&&
position
?
pool
.
tickCurrent
<
position
.
tickLower
||
pool
.
tickCurrent
>
position
.
tickUpper
:
false
...
...
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