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
467e80a4
Unverified
Commit
467e80a4
authored
Aug 26, 2020
by
Moody Salem
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
improvement(#1043): do not allow swapping to bad addresses
parent
58f25aa4
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
34 additions
and
2 deletions
+34
-2
useENSAddress.ts
src/hooks/useENSAddress.ts
+6
-1
hooks.ts
src/state/swap/hooks.ts
+28
-1
No files found.
src/hooks/useENSAddress.ts
View file @
467e80a4
import
{
namehash
}
from
'
ethers/lib/utils
'
import
{
useMemo
}
from
'
react
'
import
{
useSingleCallResult
}
from
'
../state/multicall/hooks
'
import
isZero
from
'
../utils/isZero
'
import
{
useENSRegistrarContract
,
useENSResolverContract
}
from
'
./useContract
'
import
useDebounce
from
'
./useDebounce
'
...
...
@@ -19,7 +20,11 @@ export default function useENSAddress(ensName?: string | null): { loading: boole
},
[
debouncedName
])
const
registrarContract
=
useENSRegistrarContract
(
false
)
const
resolverAddress
=
useSingleCallResult
(
registrarContract
,
'
resolver
'
,
ensNodeArgument
)
const
resolverContract
=
useENSResolverContract
(
resolverAddress
.
result
?.[
0
],
false
)
const
resolverAddressResult
=
resolverAddress
.
result
?.[
0
]
const
resolverContract
=
useENSResolverContract
(
resolverAddressResult
&&
!
isZero
(
resolverAddressResult
)
?
resolverAddressResult
:
undefined
,
false
)
const
addr
=
useSingleCallResult
(
resolverContract
,
'
addr
'
,
ensNodeArgument
)
const
changed
=
debouncedName
!==
ensName
...
...
src/state/swap/hooks.ts
View file @
467e80a4
...
...
@@ -88,6 +88,24 @@ export function tryParseAmount(value?: string, currency?: Currency): CurrencyAmo
return
}
const
BAD_RECIPIENT_ADDRESSES
:
string
[]
=
[
'
0x5C69bEe701ef814a2B6a3EDD4B1652CB9cc5aA6f
'
,
// v2 factory
'
0xf164fC0Ec4E93095b804a4795bBe1e041497b92a
'
,
// v2 router 01
'
0x7a250d5630B4cF539739dF2C5dAcb4c659F2488D
'
// v2 router 02
]
/**
* Returns true if any of the pairs or tokens in a trade have the given checksummed address
* @param trade to check for the given address
* @param checksummedAddress address to check in the pairs and tokens
*/
function
involvesAddress
(
trade
:
Trade
,
checksummedAddress
:
string
):
boolean
{
return
(
trade
.
route
.
path
.
some
(
token
=>
token
.
address
===
checksummedAddress
)
||
trade
.
route
.
pairs
.
some
(
pair
=>
pair
.
liquidityToken
.
address
===
checksummedAddress
)
)
}
// from the current swap inputs, compute the best trade and return it.
export
function
useDerivedSwapInfo
():
{
currencies
:
{
[
field
in
Field
]?:
Currency
}
...
...
@@ -153,8 +171,17 @@ export function useDerivedSwapInfo(): {
inputError
=
inputError
??
'
Select a token
'
}
if
(
!
to
)
{
const
formattedTo
=
isAddress
(
to
)
if
(
!
to
||
!
formattedTo
)
{
inputError
=
inputError
??
'
Enter a recipient
'
}
else
{
if
(
BAD_RECIPIENT_ADDRESSES
.
indexOf
(
formattedTo
)
!==
-
1
||
(
bestTradeExactIn
&&
involvesAddress
(
bestTradeExactIn
,
formattedTo
))
||
(
bestTradeExactOut
&&
involvesAddress
(
bestTradeExactOut
,
formattedTo
))
)
{
inputError
=
inputError
??
'
Invalid recipient
'
}
}
const
[
allowedSlippage
]
=
useUserSlippageTolerance
()
...
...
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