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
c35d8fc7
Unverified
Commit
c35d8fc7
authored
May 19, 2020
by
Moody Salem
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Quick fix to #800
parent
e6a043cd
Changes
5
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
47 additions
and
10 deletions
+47
-10
confirmPriceImpactWithoutFee.ts
src/components/swap/confirmPriceImpactWithoutFee.ts
+22
-0
index.ts
src/constants/index.ts
+8
-3
index.tsx
src/pages/Send/index.tsx
+5
-0
index.tsx
src/pages/Swap/index.tsx
+8
-3
prices.ts
src/utils/prices.ts
+4
-4
No files found.
src/components/swap/confirmPriceImpactWithoutFee.ts
0 → 100644
View file @
c35d8fc7
// gathers additional user consent for a high price impact
import
{
Percent
}
from
'
@uniswap/sdk
'
import
{
ALLOWED_PRICE_IMPACT_HIGH
,
PRICE_IMPACT_WITHOUT_FEE_CONFIRM_MIN
}
from
'
../../constants
'
export
default
function
confirmPriceImpactWithoutFee
(
priceImpactWithoutFee
:
Percent
):
boolean
{
if
(
!
priceImpactWithoutFee
.
lessThan
(
PRICE_IMPACT_WITHOUT_FEE_CONFIRM_MIN
))
{
return
(
window
.
prompt
(
`This swap has a price impact of at least
${
PRICE_IMPACT_WITHOUT_FEE_CONFIRM_MIN
.
toFixed
(
0
)}
%. Please type the word "confirm" to continue with this swap.`
)
===
'
confirm
'
)
}
else
if
(
!
priceImpactWithoutFee
.
lessThan
(
ALLOWED_PRICE_IMPACT_HIGH
))
{
return
window
.
confirm
(
`This swap has a price impact of at least
${
ALLOWED_PRICE_IMPACT_HIGH
.
toFixed
(
0
)}
%. Please confirm that you would like to continue with this swap.`
)
}
return
true
}
src/constants/index.ts
View file @
c35d8fc7
...
...
@@ -111,10 +111,15 @@ export const DEFAULT_DEADLINE_FROM_NOW = 60 * 15
// one basis point
export
const
ONE_BIPS
=
new
Percent
(
JSBI
.
BigInt
(
1
),
JSBI
.
BigInt
(
10000
))
export
const
BIPS_BASE
=
JSBI
.
BigInt
(
10000
)
// used for warning states
export
const
ALLOWED_SLIPPAGE_LOW
:
Percent
=
new
Percent
(
JSBI
.
BigInt
(
100
),
JSBI
.
BigInt
(
10000
))
export
const
ALLOWED_SLIPPAGE_MEDIUM
:
Percent
=
new
Percent
(
JSBI
.
BigInt
(
500
),
JSBI
.
BigInt
(
10000
))
export
const
ALLOWED_SLIPPAGE_HIGH
:
Percent
=
new
Percent
(
JSBI
.
BigInt
(
1000
),
JSBI
.
BigInt
(
10000
))
export
const
ALLOWED_PRICE_IMPACT_LOW
:
Percent
=
new
Percent
(
JSBI
.
BigInt
(
100
),
BIPS_BASE
)
// 1%
export
const
ALLOWED_PRICE_IMPACT_MEDIUM
:
Percent
=
new
Percent
(
JSBI
.
BigInt
(
500
),
BIPS_BASE
)
// 5%
export
const
ALLOWED_PRICE_IMPACT_HIGH
:
Percent
=
new
Percent
(
JSBI
.
BigInt
(
1000
),
BIPS_BASE
)
// 10%
// if the price slippage exceeds this number, force the user to type 'confirm' to execute
export
const
PRICE_IMPACT_WITHOUT_FEE_CONFIRM_MIN
:
Percent
=
new
Percent
(
JSBI
.
BigInt
(
2500
),
BIPS_BASE
)
// 25%
// used to ensure the user doesn't send so much ETH so they end up with <.01
export
const
MIN_ETH
:
JSBI
=
JSBI
.
exponentiate
(
JSBI
.
BigInt
(
10
),
JSBI
.
BigInt
(
16
))
// .01 ETH
export
const
V1_TRADE_LINK_THRESHOLD
=
new
Percent
(
JSBI
.
BigInt
(
50
),
JSBI
.
BigInt
(
10000
))
src/pages/Send/index.tsx
View file @
c35d8fc7
...
...
@@ -14,6 +14,7 @@ import CurrencyInputPanel from '../../components/CurrencyInputPanel'
import
QuestionHelper
from
'
../../components/Question
'
import
{
AutoRow
,
RowBetween
,
RowFixed
}
from
'
../../components/Row
'
import
AdvancedSwapDetailsDropdown
from
'
../../components/swap/AdvancedSwapDetailsDropdown
'
import
confirmPriceImpactWithoutFee
from
'
../../components/swap/confirmPriceImpactWithoutFee
'
import
FormattedPriceImpact
from
'
../../components/swap/FormattedPriceImpact
'
import
SwapModalFooter
from
'
../../components/swap/SwapModalFooter
'
import
{
ArrowWrapper
,
BottomGrouping
,
Dots
,
InputGroup
,
StyledNumerical
,
Wrapper
}
from
'
../../components/swap/styleds
'
...
...
@@ -134,6 +135,10 @@ export default function Send({ location: { search } }: RouteComponentProps) {
const
swapCallback
=
useSwapCallback
(
bestTrade
,
allowedSlippage
,
deadline
,
recipient
)
function
onSwap
()
{
if
(
priceImpactWithoutFee
&&
!
confirmPriceImpactWithoutFee
(
priceImpactWithoutFee
))
{
return
}
setAttemptingTxn
(
true
)
swapCallback
().
then
(
hash
=>
{
setTxHash
(
hash
)
...
...
src/pages/Swap/index.tsx
View file @
c35d8fc7
...
...
@@ -13,9 +13,11 @@ import CurrencyInputPanel from '../../components/CurrencyInputPanel'
import
QuestionHelper
from
'
../../components/Question
'
import
{
RowBetween
,
RowFixed
}
from
'
../../components/Row
'
import
AdvancedSwapDetailsDropdown
from
'
../../components/swap/AdvancedSwapDetailsDropdown
'
import
confirmPriceImpactWithoutFee
from
'
../../components/swap/confirmPriceImpactWithoutFee
'
import
FormattedPriceImpact
from
'
../../components/swap/FormattedPriceImpact
'
import
{
ArrowWrapper
,
BottomGrouping
,
Dots
,
Wrapper
}
from
'
../../components/swap/styleds
'
import
SwapModalFooter
from
'
../../components/swap/SwapModalFooter
'
import
SwapModalHeader
from
'
../../components/swap/SwapModalHeader
'
import
TradePrice
from
'
../../components/swap/TradePrice
'
import
V1TradeLink
from
'
../../components/swap/V1TradeLink
'
import
{
DEFAULT_DEADLINE_FROM_NOW
,
INITIAL_ALLOWED_SLIPPAGE
,
MIN_ETH
}
from
'
../../constants
'
...
...
@@ -28,7 +30,6 @@ import { useDefaultsFromURL, useDerivedSwapInfo, useSwapActionHandlers, useSwapS
import
{
useHasPendingApproval
}
from
'
../../state/transactions/hooks
'
import
{
CursorPointer
,
TYPE
}
from
'
../../theme
'
import
{
computeSlippageAdjustedAmounts
,
computeTradePriceBreakdown
,
warningServerity
}
from
'
../../utils/prices
'
import
SwapModalHeader
from
'
../../components/swap/SwapModalHeader
'
export
default
function
Swap
({
location
:
{
search
}
}:
RouteComponentProps
)
{
useDefaultsFromURL
(
search
)
...
...
@@ -105,7 +106,13 @@ export default function Swap({ location: { search } }: RouteComponentProps) {
// the callback to execute the swap
const
swapCallback
=
useSwapCallback
(
bestTrade
,
allowedSlippage
,
deadline
)
const
{
priceImpactWithoutFee
,
realizedLPFee
}
=
computeTradePriceBreakdown
(
bestTrade
)
function
onSwap
()
{
if
(
priceImpactWithoutFee
&&
!
confirmPriceImpactWithoutFee
(
priceImpactWithoutFee
))
{
return
}
setAttemptingTxn
(
true
)
swapCallback
().
then
(
hash
=>
{
setTxHash
(
hash
)
...
...
@@ -122,8 +129,6 @@ export default function Swap({ location: { search } }: RouteComponentProps) {
// errors
const
[
showInverted
,
setShowInverted
]
=
useState
<
boolean
>
(
false
)
const
{
priceImpactWithoutFee
,
realizedLPFee
}
=
computeTradePriceBreakdown
(
bestTrade
)
// warnings on slippage
const
priceImpactSeverity
=
warningServerity
(
priceImpactWithoutFee
)
...
...
src/utils/prices.ts
View file @
c35d8fc7
import
{
Fraction
,
JSBI
,
Percent
,
TokenAmount
,
Trade
}
from
'
@uniswap/sdk
'
import
{
ALLOWED_
SLIPPAGE_HIGH
,
ALLOWED_SLIPPAGE_LOW
,
ALLOWED_SLIPPAGE
_MEDIUM
}
from
'
../constants
'
import
{
ALLOWED_
PRICE_IMPACT_HIGH
,
ALLOWED_PRICE_IMPACT_LOW
,
ALLOWED_PRICE_IMPACT
_MEDIUM
}
from
'
../constants
'
import
{
Field
}
from
'
../state/swap/actions
'
import
{
basisPointsToPercent
}
from
'
./index
'
...
...
@@ -52,9 +52,9 @@ export function computeSlippageAdjustedAmounts(
}
export
function
warningServerity
(
priceImpact
:
Percent
):
0
|
1
|
2
|
3
{
if
(
!
priceImpact
?.
lessThan
(
ALLOWED_
SLIPPAGE
_HIGH
))
return
3
if
(
!
priceImpact
?.
lessThan
(
ALLOWED_
SLIPPAGE
_MEDIUM
))
return
2
if
(
!
priceImpact
?.
lessThan
(
ALLOWED_
SLIPPAGE
_LOW
))
return
1
if
(
!
priceImpact
?.
lessThan
(
ALLOWED_
PRICE_IMPACT
_HIGH
))
return
3
if
(
!
priceImpact
?.
lessThan
(
ALLOWED_
PRICE_IMPACT
_MEDIUM
))
return
2
if
(
!
priceImpact
?.
lessThan
(
ALLOWED_
PRICE_IMPACT
_LOW
))
return
1
return
0
}
...
...
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