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
f1dc5f8b
Unverified
Commit
f1dc5f8b
authored
Feb 14, 2020
by
Noah Zinsmeister
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
properly validate getInputAmount against balances
parent
d10e687c
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
1 addition
and
3 deletions
+1
-3
exchange.ts
src/entities/exchange.ts
+1
-0
trade.ts
src/entities/trade.ts
+0
-3
No files found.
src/entities/exchange.ts
View file @
f1dc5f8b
...
...
@@ -104,6 +104,7 @@ export class Exchange {
invariant
(
JSBI
.
greaterThan
(
outputAmount
.
raw
,
ZERO
),
'
ZERO
'
)
invariant
(
JSBI
.
greaterThan
(
this
.
reserve0
.
raw
,
ZERO
),
'
ZERO
'
)
invariant
(
JSBI
.
greaterThan
(
this
.
reserve1
.
raw
,
ZERO
),
'
ZERO
'
)
invariant
(
JSBI
.
lessThan
(
outputAmount
.
raw
,
this
.
reserveOf
(
outputAmount
.
token
).
raw
),
'
INSUFFICIENT_RESERVE
'
)
const
inputReserve
=
outputAmount
.
token
.
equals
(
this
.
reserve0
.
token
)
?
this
.
reserve1
:
this
.
reserve0
const
outputReserve
=
outputAmount
.
token
.
equals
(
this
.
reserve0
.
token
)
?
this
.
reserve0
:
this
.
reserve1
...
...
src/entities/trade.ts
View file @
f1dc5f8b
...
...
@@ -44,9 +44,6 @@ export class Trade {
constructor
(
route
:
Route
,
amount
:
TokenAmount
,
tradeType
:
TradeType
)
{
invariant
(
amount
.
token
.
equals
(
tradeType
===
TradeType
.
EXACT_INPUT
?
route
.
input
:
route
.
output
),
'
TOKEN
'
)
const
firstExchange
=
route
.
exchanges
[
tradeType
===
TradeType
.
EXACT_INPUT
?
0
:
route
.
exchanges
.
length
-
1
]
// ensure that the amount is strictly less that the exchange's balance
invariant
(
JSBI
.
lessThan
(
amount
.
raw
,
firstExchange
.
reserveOf
(
amount
.
token
).
raw
),
'
RESERVE
'
)
const
amounts
:
TokenAmount
[]
=
new
Array
(
route
.
path
.
length
)
const
nextExchanges
:
Exchange
[]
=
new
Array
(
route
.
exchanges
.
length
)
if
(
tradeType
===
TradeType
.
EXACT_INPUT
)
{
...
...
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