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
f6a464cb
Unverified
Commit
f6a464cb
authored
Aug 10, 2020
by
Moody Salem
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix(ampl): do not swap ampl via pairs other than DAI/ETH
parent
e589c751
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
45 additions
and
50 deletions
+45
-50
index.ts
src/constants/index.ts
+11
-0
Trades.ts
src/hooks/Trades.ts
+34
-18
maxHopsFor.ts
src/utils/maxHopsFor.ts
+0
-32
No files found.
src/constants/index.ts
View file @
f6a464cb
...
@@ -15,6 +15,7 @@ export const USDC = new Token(ChainId.MAINNET, '0xA0b86991c6218b36c1d19D4a2e9Eb0
...
@@ -15,6 +15,7 @@ export const USDC = new Token(ChainId.MAINNET, '0xA0b86991c6218b36c1d19D4a2e9Eb0
export
const
USDT
=
new
Token
(
ChainId
.
MAINNET
,
'
0xdAC17F958D2ee523a2206206994597C13D831ec7
'
,
6
,
'
USDT
'
,
'
Tether USD
'
)
export
const
USDT
=
new
Token
(
ChainId
.
MAINNET
,
'
0xdAC17F958D2ee523a2206206994597C13D831ec7
'
,
6
,
'
USDT
'
,
'
Tether USD
'
)
export
const
COMP
=
new
Token
(
ChainId
.
MAINNET
,
'
0xc00e94Cb662C3520282E6f5717214004A7f26888
'
,
18
,
'
COMP
'
,
'
Compound
'
)
export
const
COMP
=
new
Token
(
ChainId
.
MAINNET
,
'
0xc00e94Cb662C3520282E6f5717214004A7f26888
'
,
18
,
'
COMP
'
,
'
Compound
'
)
export
const
MKR
=
new
Token
(
ChainId
.
MAINNET
,
'
0x9f8F72aA9304c8B593d555F12eF6589cC3A579A2
'
,
18
,
'
MKR
'
,
'
Maker
'
)
export
const
MKR
=
new
Token
(
ChainId
.
MAINNET
,
'
0x9f8F72aA9304c8B593d555F12eF6589cC3A579A2
'
,
18
,
'
MKR
'
,
'
Maker
'
)
export
const
AMPL
=
new
Token
(
ChainId
.
MAINNET
,
'
0xD46bA6D942050d489DBd938a2C909A5d5039A161
'
,
9
,
'
AMPL
'
,
'
Ampleforth
'
)
const
WETH_ONLY
:
ChainTokenList
=
{
const
WETH_ONLY
:
ChainTokenList
=
{
[
ChainId
.
MAINNET
]:
[
WETH
[
ChainId
.
MAINNET
]],
[
ChainId
.
MAINNET
]:
[
WETH
[
ChainId
.
MAINNET
]],
...
@@ -30,6 +31,16 @@ export const BASES_TO_CHECK_TRADES_AGAINST: ChainTokenList = {
...
@@ -30,6 +31,16 @@ export const BASES_TO_CHECK_TRADES_AGAINST: ChainTokenList = {
[
ChainId
.
MAINNET
]:
[...
WETH_ONLY
[
ChainId
.
MAINNET
],
DAI
,
USDC
,
USDT
,
COMP
,
MKR
]
[
ChainId
.
MAINNET
]:
[...
WETH_ONLY
[
ChainId
.
MAINNET
],
DAI
,
USDC
,
USDT
,
COMP
,
MKR
]
}
}
/**
* Some tokens can only be swapped via certain pairs, so we override the list of bases that are considered for these
* tokens.
*/
export
const
CUSTOM_BASES
:
{
[
chainId
in
ChainId
]?:
{
[
tokenAddress
:
string
]:
Token
[]
}
}
=
{
[
ChainId
.
MAINNET
]:
{
[
AMPL
.
address
]:
[
DAI
,
WETH
[
ChainId
.
MAINNET
]]
}
}
// used for display in the default list when adding liquidity
// used for display in the default list when adding liquidity
export
const
SUGGESTED_BASES
:
ChainTokenList
=
{
export
const
SUGGESTED_BASES
:
ChainTokenList
=
{
...
WETH_ONLY
,
...
WETH_ONLY
,
...
...
src/hooks/Trades.ts
View file @
f6a464cb
...
@@ -2,9 +2,8 @@ import { Currency, CurrencyAmount, Pair, Token, Trade } from '@uniswap/sdk'
...
@@ -2,9 +2,8 @@ import { Currency, CurrencyAmount, Pair, Token, Trade } from '@uniswap/sdk'
import
flatMap
from
'
lodash.flatmap
'
import
flatMap
from
'
lodash.flatmap
'
import
{
useMemo
}
from
'
react
'
import
{
useMemo
}
from
'
react
'
import
{
BASES_TO_CHECK_TRADES_AGAINST
}
from
'
../constants
'
import
{
BASES_TO_CHECK_TRADES_AGAINST
,
CUSTOM_BASES
}
from
'
../constants
'
import
{
PairState
,
usePairs
}
from
'
../data/Reserves
'
import
{
PairState
,
usePairs
}
from
'
../data/Reserves
'
import
{
maxHopsFor
}
from
'
../utils/maxHopsFor
'
import
{
wrappedCurrency
}
from
'
../utils/wrappedCurrency
'
import
{
wrappedCurrency
}
from
'
../utils/wrappedCurrency
'
import
{
useActiveWeb3React
}
from
'
./index
'
import
{
useActiveWeb3React
}
from
'
./index
'
...
@@ -18,8 +17,9 @@ function useAllCommonPairs(currencyA?: Currency, currencyB?: Currency): Pair[] {
...
@@ -18,8 +17,9 @@ function useAllCommonPairs(currencyA?: Currency, currencyB?: Currency): Pair[] {
?
[
wrappedCurrency
(
currencyA
,
chainId
),
wrappedCurrency
(
currencyB
,
chainId
)]
?
[
wrappedCurrency
(
currencyA
,
chainId
),
wrappedCurrency
(
currencyB
,
chainId
)]
:
[
undefined
,
undefined
]
:
[
undefined
,
undefined
]
const
allPairCombinations
:
[
Token
|
undefined
,
Token
|
undefined
][]
=
useMemo
(
const
allPairCombinations
:
[
Token
,
Token
][]
=
useMemo
(
()
=>
[
()
=>
[
// the direct pair
// the direct pair
[
tokenA
,
tokenB
],
[
tokenA
,
tokenB
],
// token A against all bases
// token A against all bases
...
@@ -28,8 +28,25 @@ function useAllCommonPairs(currencyA?: Currency, currencyB?: Currency): Pair[] {
...
@@ -28,8 +28,25 @@ function useAllCommonPairs(currencyA?: Currency, currencyB?: Currency): Pair[] {
...
bases
.
map
((
base
):
[
Token
|
undefined
,
Token
|
undefined
]
=>
[
tokenB
,
base
]),
...
bases
.
map
((
base
):
[
Token
|
undefined
,
Token
|
undefined
]
=>
[
tokenB
,
base
]),
// each base against all bases
// each base against all bases
...
flatMap
(
bases
,
(
base
):
[
Token
,
Token
][]
=>
bases
.
map
(
otherBase
=>
[
base
,
otherBase
]))
...
flatMap
(
bases
,
(
base
):
[
Token
,
Token
][]
=>
bases
.
map
(
otherBase
=>
[
base
,
otherBase
]))
],
]
[
tokenA
,
tokenB
,
bases
]
.
filter
((
tokens
):
tokens
is
[
Token
,
Token
]
=>
Boolean
(
tokens
[
0
]
&&
tokens
[
1
]))
.
filter
(([
tokenA
,
tokenB
])
=>
{
if
(
!
chainId
)
return
true
const
customBases
=
CUSTOM_BASES
[
chainId
]
if
(
!
customBases
)
return
true
const
customBasesA
:
Token
[]
|
undefined
=
customBases
[
tokenA
.
address
]
const
customBasesB
:
Token
[]
|
undefined
=
customBases
[
tokenB
.
address
]
if
(
!
customBasesA
&&
!
customBasesB
)
return
true
if
(
customBasesA
&&
customBasesA
.
findIndex
(
base
=>
tokenB
.
equals
(
base
))
===
-
1
)
return
false
if
(
customBasesB
&&
customBasesB
.
findIndex
(
base
=>
tokenA
.
equals
(
base
))
===
-
1
)
return
false
console
.
log
(
tokenA
,
tokenB
,
customBasesA
,
customBasesB
,
'
allowing
'
)
return
true
}),
[
tokenA
,
tokenB
,
bases
,
chainId
]
)
)
const
allPairs
=
usePairs
(
allPairCombinations
)
const
allPairs
=
usePairs
(
allPairCombinations
)
...
@@ -59,9 +76,8 @@ export function useTradeExactIn(currencyAmountIn?: CurrencyAmount, currencyOut?:
...
@@ -59,9 +76,8 @@ export function useTradeExactIn(currencyAmountIn?: CurrencyAmount, currencyOut?:
return
useMemo
(()
=>
{
return
useMemo
(()
=>
{
if
(
currencyAmountIn
&&
currencyOut
&&
allowedPairs
.
length
>
0
)
{
if
(
currencyAmountIn
&&
currencyOut
&&
allowedPairs
.
length
>
0
)
{
const
maxHops
=
maxHopsFor
(
currencyAmountIn
.
currency
,
currencyOut
)
return
(
return
(
Trade
.
bestTradeExactIn
(
allowedPairs
,
currencyAmountIn
,
currencyOut
,
{
maxHops
,
maxNumResults
:
1
})[
0
]
??
null
Trade
.
bestTradeExactIn
(
allowedPairs
,
currencyAmountIn
,
currencyOut
,
{
maxHops
:
3
,
maxNumResults
:
1
})[
0
]
??
null
)
)
}
}
return
null
return
null
...
@@ -76,9 +92,9 @@ export function useTradeExactOut(currencyIn?: Currency, currencyAmountOut?: Curr
...
@@ -76,9 +92,9 @@ export function useTradeExactOut(currencyIn?: Currency, currencyAmountOut?: Curr
return
useMemo
(()
=>
{
return
useMemo
(()
=>
{
if
(
currencyIn
&&
currencyAmountOut
&&
allowedPairs
.
length
>
0
)
{
if
(
currencyIn
&&
currencyAmountOut
&&
allowedPairs
.
length
>
0
)
{
const
maxHops
=
maxHopsFor
(
currencyIn
,
currencyAmountOut
.
currency
)
return
(
return
(
Trade
.
bestTradeExactOut
(
allowedPairs
,
currencyIn
,
currencyAmountOut
,
{
maxHops
,
maxNumResults
:
1
})[
0
]
??
null
Trade
.
bestTradeExactOut
(
allowedPairs
,
currencyIn
,
currencyAmountOut
,
{
maxHops
:
3
,
maxNumResults
:
1
})[
0
]
??
null
)
)
}
}
return
null
return
null
...
...
src/utils/maxHopsFor.ts
deleted
100644 → 0
View file @
e589c751
import
{
ChainId
,
Currency
,
ETHER
,
Token
,
WETH
}
from
'
@uniswap/sdk
'
function
isEtherish
(
currency
:
Currency
):
boolean
{
return
currency
===
ETHER
||
(
currency
instanceof
Token
&&
WETH
[
currency
.
chainId
].
equals
(
currency
))
}
const
AMPL_TOKEN_ADDRESS
=
'
0xD46bA6D942050d489DBd938a2C909A5d5039A161
'
/**
* Band-aid on maxHops because some tokens seems to always fail with multihop swaps
* @param currencyIn currency in
* @param currencyOut currency out
*/
export
function
maxHopsFor
(
currencyIn
:
Currency
,
currencyOut
:
Currency
):
number
{
if
(
isEtherish
(
currencyIn
)
&&
currencyOut
instanceof
Token
&&
currencyOut
.
chainId
===
ChainId
.
MAINNET
&&
currencyOut
.
address
===
AMPL_TOKEN_ADDRESS
)
{
return
1
}
else
if
(
isEtherish
(
currencyOut
)
&&
currencyIn
instanceof
Token
&&
currencyIn
.
chainId
===
ChainId
.
MAINNET
&&
currencyIn
.
address
===
AMPL_TOKEN_ADDRESS
)
{
return
1
}
return
3
}
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