Skip to content

Commit

Permalink
fix(newSwap): move guard out of conditional; tests pass
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelfig committed May 4, 2021
1 parent 8970dca commit dc67e67
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions packages/zoe/src/contracts/newSwap/swap.js
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,11 @@ export const makeMakeSwapInvitation = (
centralAmount,
} = getPriceGivenRequiredOutput(brandIn, amountOut);

if (!amountMath.isGTE(offeredAmountIn, amountIn)) {
const reason = `offeredAmountIn ${offeredAmountIn} is insufficient to buy amountOut ${amountOut}`;
throw seat.fail(Error(reason));
}

const stagings = [];
stagings.push(stageProtocolSeatFee(protocolFee));
stagings.push(
Expand All @@ -186,10 +191,6 @@ export const makeMakeSwapInvitation = (
// central to secondary, secondary to central, or secondary to secondary
const pools = [];
if (isCentral(brandOut) && isSecondary(brandIn)) {
if (!amountMath.isGTE(offeredAmountIn, amountIn)) {
const reason = `offeredAmountIn ${offeredAmountIn} is insufficient to buy amountOut ${amountOut}`;
throw seat.fail(Error(reason));
}
stagings.push(
poolStagingToCentral(amountIn, improvedAmountOut, protocolFee),
);
Expand Down

0 comments on commit dc67e67

Please sign in to comment.