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
9eaa22f6
Unverified
Commit
9eaa22f6
authored
Nov 03, 2023
by
Jack Short
Committed by
GitHub
Nov 03, 2023
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
chore: converting useStablecoinPrice to useUsdPrice in autoslippage (#7543)
parent
1c924828
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
16 additions
and
24 deletions
+16
-24
useAutoSlippageTolerance.ts
src/hooks/useAutoSlippageTolerance.ts
+16
-24
No files found.
src/hooks/useAutoSlippageTolerance.ts
View file @
9eaa22f6
...
...
@@ -11,7 +11,8 @@ import { useMemo } from 'react'
import
{
ClassicTrade
}
from
'
state/routing/types
'
import
useGasPrice
from
'
./useGasPrice
'
import
useStablecoinPrice
,
{
useStablecoinAmountFromFiatValue
,
useStablecoinValue
}
from
'
./useStablecoinPrice
'
import
{
useStablecoinAmountFromFiatValue
,
useStablecoinValue
}
from
'
./useStablecoinPrice
'
import
{
useUSDPrice
}
from
'
./useUSDPrice
'
const
DEFAULT_AUTO_SLIPPAGE
=
new
Percent
(
5
,
1000
)
// 0.5%
...
...
@@ -77,30 +78,31 @@ export default function useClassicAutoSlippageTolerance(trade?: ClassicTrade): P
const
{
chainId
}
=
useWeb3React
()
const
onL2
=
chainId
&&
L2_CHAIN_IDS
.
includes
(
chainId
)
const
outputDollarValue
=
useStablecoinValue
(
trade
?.
outputAmount
)
const
nativeGasPrice
=
useGasPrice
()
const
nativeGasPrice
=
useGasPrice
()
const
gasEstimate
=
guesstimateGas
(
trade
)
const
gasEstimateUSD
=
useStablecoinAmountFromFiatValue
(
trade
?.
gasUseEstimateUSD
)
??
null
const
nativeCurrency
=
useNativeCurrency
(
chainId
)
const
nativeCurrencyPrice
=
useStablecoinPrice
((
trade
&&
nativeCurrency
)
??
undefined
)
const
nativeGasCost
=
nativeGasPrice
&&
typeof
gasEstimate
===
'
number
'
?
JSBI
.
multiply
(
nativeGasPrice
,
JSBI
.
BigInt
(
gasEstimate
))
:
undefined
const
gasCostUSD
=
useUSDPrice
(
trade
&&
nativeCurrency
&&
nativeGasCost
?
CurrencyAmount
.
fromRawAmount
(
nativeCurrency
,
nativeGasCost
)
:
undefined
)
const
gasCostStablecoinAmount
=
useStablecoinAmountFromFiatValue
(
gasCostUSD
.
data
)
return
useMemo
(()
=>
{
if
(
!
trade
||
onL2
)
return
DEFAULT_AUTO_SLIPPAGE
const
nativeGasCost
=
nativeGasPrice
&&
typeof
gasEstimate
===
'
number
'
?
JSBI
.
multiply
(
nativeGasPrice
,
JSBI
.
BigInt
(
gasEstimate
))
:
undefined
const
dollarGasCost
=
nativeCurrency
&&
nativeGasCost
&&
nativeCurrencyPrice
?
nativeCurrencyPrice
.
quote
(
CurrencyAmount
.
fromRawAmount
(
nativeCurrency
,
nativeGasCost
))
:
undefined
// if valid estimate from api and using api trade, use gas estimate from api
// NOTE - dont use gas estimate for L2s yet - need to verify accuracy
// if not, use local heuristic
const
dollarCostToUse
=
chainId
&&
SUPPORTED_GAS_ESTIMATE_CHAIN_IDS
.
includes
(
chainId
)
&&
gasEstimateUSD
?
gasEstimateUSD
:
dollarGasCost
chainId
&&
SUPPORTED_GAS_ESTIMATE_CHAIN_IDS
.
includes
(
chainId
)
&&
gasEstimateUSD
?
gasEstimateUSD
:
gasCostStablecoinAmount
if
(
outputDollarValue
&&
dollarCostToUse
)
{
// optimize for highest possible slippage without getting MEV'd
...
...
@@ -119,15 +121,5 @@ export default function useClassicAutoSlippageTolerance(trade?: ClassicTrade): P
}
return
DEFAULT_AUTO_SLIPPAGE
},
[
trade
,
onL2
,
nativeGasPrice
,
gasEstimate
,
nativeCurrency
,
nativeCurrencyPrice
,
chainId
,
gasEstimateUSD
,
outputDollarValue
,
])
},
[
trade
,
onL2
,
chainId
,
gasEstimateUSD
,
gasCostStablecoinAmount
,
outputDollarValue
])
}
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