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
452f2dc3
Unverified
Commit
452f2dc3
authored
May 09, 2021
by
Moody Salem
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix slippage amount bug
https://github.com/Uniswap/uniswap-interface/issues/1473
parent
b6bd59f2
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
6 additions
and
13 deletions
+6
-13
index.test.ts
src/utils/index.test.ts
+2
-2
index.ts
src/utils/index.ts
+4
-11
No files found.
src/utils/index.test.ts
View file @
452f2dc3
...
...
@@ -28,7 +28,8 @@ describe('utils', () => {
describe
(
'
#calculateSlippageAmount
'
,
()
=>
{
it
(
'
bounds are correct
'
,
()
=>
{
const
tokenAmount
=
new
TokenAmount
(
new
Token
(
ChainId
.
MAINNET
,
AddressZero
,
0
),
'
100
'
)
expect
(()
=>
calculateSlippageAmount
(
tokenAmount
,
new
Percent
(
-
1
,
10
_000
))).
toThrow
()
expect
(()
=>
calculateSlippageAmount
(
tokenAmount
,
new
Percent
(
-
1
,
10
_000
))).
toThrow
(
'
Unexpected slippage
'
)
expect
(()
=>
calculateSlippageAmount
(
tokenAmount
,
new
Percent
(
10
_001
,
10
_000
))).
toThrow
(
'
Unexpected slippage
'
)
expect
(
calculateSlippageAmount
(
tokenAmount
,
new
Percent
(
0
,
10
_000
)).
map
((
bound
)
=>
bound
.
toString
())).
toEqual
([
'
100
'
,
'
100
'
,
...
...
@@ -44,7 +45,6 @@ describe('utils', () => {
expect
(
calculateSlippageAmount
(
tokenAmount
,
new
Percent
(
10000
,
10
_000
)).
map
((
bound
)
=>
bound
.
toString
())
).
toEqual
([
'
0
'
,
'
200
'
])
expect
(()
=>
calculateSlippageAmount
(
tokenAmount
,
new
Percent
(
10001
,
10
_000
))).
toThrow
()
})
})
...
...
src/utils/index.ts
View file @
452f2dc3
...
...
@@ -3,7 +3,7 @@ import { getAddress } from '@ethersproject/address'
import
{
AddressZero
}
from
'
@ethersproject/constants
'
import
{
JsonRpcSigner
,
Web3Provider
}
from
'
@ethersproject/providers
'
import
{
BigNumber
}
from
'
@ethersproject/bignumber
'
import
{
ChainId
,
Percent
,
Token
,
CurrencyAmount
,
Currency
,
ETHER
}
from
'
@uniswap/sdk-core
'
import
{
ChainId
,
Percent
,
Token
,
CurrencyAmount
,
Currency
,
ETHER
,
Fraction
}
from
'
@uniswap/sdk-core
'
import
{
JSBI
}
from
'
@uniswap/v2-sdk
'
import
{
FeeAmount
}
from
'
@uniswap/v3-sdk/dist/
'
import
{
TokenAddressMap
}
from
'
../state/lists/hooks
'
...
...
@@ -63,17 +63,10 @@ export function calculateGasMargin(value: BigNumber): BigNumber {
return
value
.
mul
(
BigNumber
.
from
(
10000
).
add
(
BigNumber
.
from
(
1000
))).
div
(
BigNumber
.
from
(
10000
))
}
const
ONE
=
new
Fraction
(
1
,
1
)
export
function
calculateSlippageAmount
(
value
:
CurrencyAmount
,
slippage
:
Percent
):
[
JSBI
,
JSBI
]
{
if
(
JSBI
.
lessThan
(
slippage
.
numerator
,
JSBI
.
BigInt
(
0
))
||
JSBI
.
greaterThan
(
slippage
.
numerator
,
JSBI
.
BigInt
(
10
_000
))
||
!
JSBI
.
equal
(
slippage
.
denominator
,
JSBI
.
BigInt
(
10
_000
))
)
throw
new
Error
(
'
Unexpected slippage
'
)
return
[
JSBI
.
divide
(
JSBI
.
multiply
(
value
.
raw
,
JSBI
.
subtract
(
JSBI
.
BigInt
(
10000
),
slippage
.
numerator
)),
JSBI
.
BigInt
(
10000
)),
JSBI
.
divide
(
JSBI
.
multiply
(
value
.
raw
,
JSBI
.
add
(
JSBI
.
BigInt
(
10000
),
slippage
.
numerator
)),
JSBI
.
BigInt
(
10000
)),
]
if
(
slippage
.
lessThan
(
0
)
||
slippage
.
greaterThan
(
ONE
))
throw
new
Error
(
'
Unexpected slippage
'
)
return
[
value
.
multiply
(
ONE
.
subtract
(
slippage
)).
quotient
,
value
.
multiply
(
ONE
.
add
(
slippage
)).
quotient
]
}
// account is not optional
...
...
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