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
e3b3d9e8
Unverified
Commit
e3b3d9e8
authored
Jul 31, 2020
by
Moody Salem
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix(swaps): band-aid fix for gas estimates to disable multihop for eth-ampl
parent
3050e967
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
37 additions
and
3 deletions
+37
-3
Trades.ts
src/hooks/Trades.ts
+5
-3
maxHopsFor.ts
src/utils/maxHopsFor.ts
+32
-0
No files found.
src/hooks/Trades.ts
View file @
e3b3d9e8
...
...
@@ -4,6 +4,7 @@ import { useMemo } from 'react'
import
{
BASES_TO_CHECK_TRADES_AGAINST
}
from
'
../constants
'
import
{
PairState
,
usePairs
}
from
'
../data/Reserves
'
import
{
maxHopsFor
}
from
'
../utils/maxHopsFor
'
import
{
wrappedCurrency
}
from
'
../utils/wrappedCurrency
'
import
{
useActiveWeb3React
}
from
'
./index
'
...
...
@@ -58,8 +59,9 @@ export function useTradeExactIn(currencyAmountIn?: CurrencyAmount, currencyOut?:
return
useMemo
(()
=>
{
if
(
currencyAmountIn
&&
currencyOut
&&
allowedPairs
.
length
>
0
)
{
const
maxHops
=
maxHopsFor
(
currencyAmountIn
.
currency
,
currencyOut
)
return
(
Trade
.
bestTradeExactIn
(
allowedPairs
,
currencyAmountIn
,
currencyOut
,
{
maxHops
:
3
,
maxNumResults
:
1
})[
0
]
??
null
Trade
.
bestTradeExactIn
(
allowedPairs
,
currencyAmountIn
,
currencyOut
,
{
maxHops
,
maxNumResults
:
1
})[
0
]
??
null
)
}
return
null
...
...
@@ -74,9 +76,9 @@ export function useTradeExactOut(currencyIn?: Currency, currencyAmountOut?: Curr
return
useMemo
(()
=>
{
if
(
currencyIn
&&
currencyAmountOut
&&
allowedPairs
.
length
>
0
)
{
const
maxHops
=
maxHopsFor
(
currencyIn
,
currencyAmountOut
.
currency
)
return
(
Trade
.
bestTradeExactOut
(
allowedPairs
,
currencyIn
,
currencyAmountOut
,
{
maxHops
:
3
,
maxNumResults
:
1
})[
0
]
??
null
Trade
.
bestTradeExactOut
(
allowedPairs
,
currencyIn
,
currencyAmountOut
,
{
maxHops
,
maxNumResults
:
1
})[
0
]
??
null
)
}
return
null
...
...
src/utils/maxHopsFor.ts
0 → 100644
View file @
e3b3d9e8
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