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
e5b779f6
Unverified
Commit
e5b779f6
authored
May 09, 2020
by
Moody Salem
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix reliability of error checking
parent
dcd2fccf
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
7 additions
and
3 deletions
+7
-3
trade.ts
src/entities/trade.ts
+3
-3
errors.ts
src/errors.ts
+4
-0
No files found.
src/entities/trade.ts
View file @
e5b779f6
...
...
@@ -8,7 +8,6 @@ import { Price } from './fractions/price'
import
{
Percent
}
from
'
./fractions/percent
'
import
{
Token
}
from
'
entities/token
'
import
{
sortedInsert
}
from
'
../utils
'
import
{
InsufficientReservesError
,
InsufficientInputAmountError
}
from
'
../errors
'
function
getSlippage
(
midPrice
:
Price
,
inputAmount
:
TokenAmount
,
outputAmount
:
TokenAmount
):
Percent
{
const
exactQuote
=
midPrice
.
raw
.
multiply
(
inputAmount
.
raw
)
...
...
@@ -143,7 +142,8 @@ export class Trade {
try
{
;[
amountOut
]
=
pair
.
getOutputAmount
(
amountIn
)
}
catch
(
error
)
{
if
(
error
instanceof
InsufficientInputAmountError
)
{
// input too low
if
(
error
.
isInsufficientInputAmountError
)
{
continue
}
throw
error
...
...
@@ -211,7 +211,7 @@ export class Trade {
;[
amountIn
]
=
pair
.
getInputAmount
(
amountOut
)
}
catch
(
error
)
{
// not enough liquidity in this pair
if
(
error
instanceof
InsufficientReservesError
)
{
if
(
error
.
is
InsufficientReservesError
)
{
continue
}
throw
error
...
...
src/errors.ts
View file @
e5b779f6
...
...
@@ -2,6 +2,8 @@
const
CAN_SET_PROTOTYPE
=
'
setPrototypeOf
'
in
Object
export
class
InsufficientReservesError
extends
Error
{
public
readonly
isInsufficientReservesError
:
true
=
true
public
constructor
()
{
super
()
this
.
name
=
this
.
constructor
.
name
...
...
@@ -10,6 +12,8 @@ export class InsufficientReservesError extends Error {
}
export
class
InsufficientInputAmountError
extends
Error
{
public
readonly
isInsufficientInputAmountError
:
true
=
true
public
constructor
()
{
super
()
this
.
name
=
this
.
constructor
.
name
...
...
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