Commit d10e687c authored by Noah Zinsmeister's avatar Noah Zinsmeister

v2.0.0-beta.10

parent fd5d1e4d
{
"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": [
......
......@@ -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')
......
......@@ -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) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment