Skip to content

Commit

Permalink
v2.0.0-beta.10
Browse files Browse the repository at this point in the history
  • Loading branch information
NoahZinsmeister committed Feb 14, 2020
1 parent fd5d1e4 commit d10e687
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 1 deletion.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@uniswap/sdk",
"license": "GPL-3.0-or-later",
"version": "2.0.0-beta.9",
"version": "2.0.0-beta.10",
"main": "dist/index.js",
"typings": "dist/index.d.ts",
"files": [
Expand Down
5 changes: 5 additions & 0 deletions src/entities/exchange.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,11 @@ export class Exchange {
return this.tokenAmounts[1].token
}

public reserveOf(token: Token): TokenAmount {
invariant(token.equals(this.token0) || token.equals(this.token1), 'TOKEN')
return token.equals(this.token0) ? this.reserve0 : this.reserve1
}

public getOutputAmount(inputAmount: TokenAmount): [TokenAmount, Exchange] {
invariant(inputAmount.token.equals(this.token0) || inputAmount.token.equals(this.token1), 'TOKEN')
invariant(JSBI.greaterThan(inputAmount.raw, ZERO), 'ZERO')
Expand Down
3 changes: 3 additions & 0 deletions src/entities/trade.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ 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) {
Expand Down

0 comments on commit d10e687

Please sign in to comment.