Skip to content

Commit

Permalink
Fix naming of error and parameter
Browse files Browse the repository at this point in the history
  • Loading branch information
moodysalem committed May 11, 2020
1 parent 3f22d17 commit 9938cc1
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 12 deletions.
16 changes: 8 additions & 8 deletions src/entities/trade.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 slippage
public minimumAmountOut(additionalSlippageTolerance: Percent): TokenAmount {
invariant(!additionalSlippageTolerance.lessThan(ZERO), 'ADDITIONAL_SLIPPAGE_TOLERANCE')
// get the minimum amount that must be received from this trade for the given slippage tolerance
public minimumAmountOut(slippageTolerance: 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(additionalSlippageTolerance)
.add(slippageTolerance)
.invert()
.multiply(this.outputAmount.raw).quotient
)
}
}

// get the maximum amount in that can be spent via this trade for the given allowed slippage
public maximumAmountIn(additionalSlippageTolerance: 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 tolerance
public maximumAmountIn(slippageTolerance: 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(additionalSlippageTolerance).multiply(this.inputAmount.raw).quotient
new Fraction(ONE).add(slippageTolerance).multiply(this.inputAmount.raw).quotient
)
}
}
Expand Down
8 changes: 4 additions & 4 deletions test/trade.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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', () => {
Expand All @@ -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', () => {
Expand Down Expand Up @@ -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', () => {
Expand All @@ -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', () => {
Expand Down

0 comments on commit 9938cc1

Please sign in to comment.