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
ab5114c5
Unverified
Commit
ab5114c5
authored
May 04, 2021
by
Moody Salem
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
move the compute price impact function out to a utility file
parent
28c7cfa1
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
19 additions
and
16 deletions
+19
-16
AdvancedSwapDetails.tsx
src/components/swap/AdvancedSwapDetails.tsx
+1
-16
computePriceImpactWithMaximumSlippage.tsx
src/utils/computePriceImpactWithMaximumSlippage.tsx
+18
-0
No files found.
src/components/swap/AdvancedSwapDetails.tsx
View file @
ab5114c5
import
{
CurrencyAmount
,
Percent
,
Price
}
from
'
@uniswap/sdk-core
'
import
{
Trade
as
V2Trade
}
from
'
@uniswap/v2-sdk
'
import
{
Trade
as
V3Trade
}
from
'
@uniswap/v3-sdk
'
import
React
,
{
useContext
}
from
'
react
'
import
{
ThemeContext
}
from
'
styled-components
'
import
{
useUserSlippageTolerance
}
from
'
../../state/user/hooks
'
import
{
TYPE
}
from
'
../../theme
'
import
{
computePriceImpactWithMaximumSlippage
}
from
'
../../utils/computePriceImpactWithMaximumSlippage
'
import
{
computeRealizedLPFeeAmount
}
from
'
../../utils/prices
'
import
{
AutoColumn
}
from
'
../Column
'
import
{
RowBetween
,
RowFixed
}
from
'
../Row
'
...
...
@@ -15,21 +15,6 @@ export interface AdvancedSwapDetailsProps {
trade
?:
V2Trade
|
V3Trade
}
function
computePriceImpact
(
midPrice
:
Price
,
inputAmount
:
CurrencyAmount
,
outputAmount
:
CurrencyAmount
):
Percent
{
const
exactQuote
=
midPrice
.
raw
.
multiply
(
inputAmount
.
raw
)
// calculate slippage := (exactQuote - outputAmount) / exactQuote
const
slippage
=
exactQuote
.
subtract
(
outputAmount
.
raw
).
divide
(
exactQuote
)
return
new
Percent
(
slippage
.
numerator
,
slippage
.
denominator
)
}
function
computePriceImpactWithMaximumSlippage
(
trade
:
V2Trade
|
V3Trade
,
allowedSlippage
:
Percent
):
Percent
{
return
computePriceImpact
(
trade
.
route
.
midPrice
,
trade
.
maximumAmountIn
(
allowedSlippage
),
trade
.
minimumAmountOut
(
allowedSlippage
)
)
}
export
function
AdvancedSwapDetails
({
trade
}:
AdvancedSwapDetailsProps
)
{
const
theme
=
useContext
(
ThemeContext
)
...
...
src/utils/computePriceImpactWithMaximumSlippage.tsx
0 → 100644
View file @
ab5114c5
import
{
CurrencyAmount
,
Percent
,
Price
}
from
'
@uniswap/sdk-core
'
import
{
Trade
as
V2Trade
}
from
'
@uniswap/v2-sdk
'
import
{
Trade
as
V3Trade
}
from
'
@uniswap/v3-sdk
'
function
computePriceImpact
(
midPrice
:
Price
,
inputAmount
:
CurrencyAmount
,
outputAmount
:
CurrencyAmount
):
Percent
{
const
exactQuote
=
midPrice
.
raw
.
multiply
(
inputAmount
.
raw
)
// calculate slippage := (exactQuote - outputAmount) / exactQuote
const
slippage
=
exactQuote
.
subtract
(
outputAmount
.
raw
).
divide
(
exactQuote
)
return
new
Percent
(
slippage
.
numerator
,
slippage
.
denominator
)
}
export
function
computePriceImpactWithMaximumSlippage
(
trade
:
V2Trade
|
V3Trade
,
allowedSlippage
:
Percent
):
Percent
{
return
computePriceImpact
(
trade
.
route
.
midPrice
,
trade
.
maximumAmountIn
(
allowedSlippage
),
trade
.
minimumAmountOut
(
allowedSlippage
)
)
}
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