Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
S
swap-v2-sdk
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
swap-v2-sdk
Commits
9938cc18
Unverified
Commit
9938cc18
authored
May 11, 2020
by
Moody Salem
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix naming of error and parameter
parent
3f22d17e
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
12 additions
and
12 deletions
+12
-12
trade.ts
src/entities/trade.ts
+8
-8
trade.test.ts
test/trade.test.ts
+4
-4
No files found.
src/entities/trade.ts
View file @
9938cc18
...
...
@@ -115,31 +115,31 @@ export class Trade {
this
.
slippage
=
getSlippage
(
route
.
midPrice
,
inputAmount
,
outputAmount
)
}
// get the minimum amount that must be received from this trade for the given
allowed slippag
e
public
minimumAmountOut
(
additionalS
lippageTolerance
:
Percent
):
TokenAmount
{
invariant
(
!
additionalSlippageTolerance
.
lessThan
(
ZERO
),
'
ADDITIONAL_
SLIPPAGE_TOLERANCE
'
)
// get the minimum amount that must be received from this trade for the given
slippage toleranc
e
public
minimumAmountOut
(
s
lippageTolerance
:
Percent
):
TokenAmount
{
invariant
(
!
slippageTolerance
.
lessThan
(
ZERO
),
'
SLIPPAGE_TOLERANCE
'
)
if
(
this
.
tradeType
===
TradeType
.
EXACT_OUTPUT
)
{
return
this
.
outputAmount
}
else
{
return
new
TokenAmount
(
this
.
outputAmount
.
token
,
new
Fraction
(
ONE
)
.
add
(
additionalS
lippageTolerance
)
.
add
(
s
lippageTolerance
)
.
invert
()
.
multiply
(
this
.
outputAmount
.
raw
).
quotient
)
}
}
// get the maximum amount in that can be spent via this trade for the given
allowed slippag
e
public
maximumAmountIn
(
additionalS
lippageTolerance
:
Percent
):
TokenAmount
{
invariant
(
!
additionalSlippageTolerance
.
lessThan
(
ZERO
),
'
ADDITIONAL_
SLIPPAGE_TOLERANCE
'
)
// get the maximum amount in that can be spent via this trade for the given
slippage toleranc
e
public
maximumAmountIn
(
s
lippageTolerance
:
Percent
):
TokenAmount
{
invariant
(
!
slippageTolerance
.
lessThan
(
ZERO
),
'
SLIPPAGE_TOLERANCE
'
)
if
(
this
.
tradeType
===
TradeType
.
EXACT_INPUT
)
{
return
this
.
inputAmount
}
else
{
return
new
TokenAmount
(
this
.
inputAmount
.
token
,
new
Fraction
(
ONE
).
add
(
additionalS
lippageTolerance
).
multiply
(
this
.
inputAmount
.
raw
).
quotient
new
Fraction
(
ONE
).
add
(
s
lippageTolerance
).
multiply
(
this
.
inputAmount
.
raw
).
quotient
)
}
}
...
...
test/trade.test.ts
View file @
9938cc18
...
...
@@ -94,7 +94,7 @@ describe('Trade', () => {
)
it
(
'
throws if less than 0
'
,
()
=>
{
expect
(()
=>
exactIn
.
maximumAmountIn
(
new
Percent
(
JSBI
.
BigInt
(
-
1
),
JSBI
.
BigInt
(
100
)))).
toThrow
(
'
ADDITIONAL_
SLIPPAGE_TOLERANCE
'
'
SLIPPAGE_TOLERANCE
'
)
})
it
(
'
returns exact if 0
'
,
()
=>
{
...
...
@@ -121,7 +121,7 @@ describe('Trade', () => {
it
(
'
throws if less than 0
'
,
()
=>
{
expect
(()
=>
exactOut
.
maximumAmountIn
(
new
Percent
(
JSBI
.
BigInt
(
-
1
),
JSBI
.
BigInt
(
100
)))).
toThrow
(
'
ADDITIONAL_
SLIPPAGE_TOLERANCE
'
'
SLIPPAGE_TOLERANCE
'
)
})
it
(
'
returns exact if 0
'
,
()
=>
{
...
...
@@ -150,7 +150,7 @@ describe('Trade', () => {
)
it
(
'
throws if less than 0
'
,
()
=>
{
expect
(()
=>
exactIn
.
minimumAmountOut
(
new
Percent
(
JSBI
.
BigInt
(
-
1
),
JSBI
.
BigInt
(
100
)))).
toThrow
(
'
ADDITIONAL_
SLIPPAGE_TOLERANCE
'
'
SLIPPAGE_TOLERANCE
'
)
})
it
(
'
returns exact if 0
'
,
()
=>
{
...
...
@@ -177,7 +177,7 @@ describe('Trade', () => {
it
(
'
throws if less than 0
'
,
()
=>
{
expect
(()
=>
exactOut
.
minimumAmountOut
(
new
Percent
(
JSBI
.
BigInt
(
-
1
),
JSBI
.
BigInt
(
100
)))).
toThrow
(
'
ADDITIONAL_
SLIPPAGE_TOLERANCE
'
'
SLIPPAGE_TOLERANCE
'
)
})
it
(
'
returns exact if 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