Skip to content

Commit

Permalink
chore: remove error for 100% fees
Browse files Browse the repository at this point in the history
  • Loading branch information
cjkoepke committed Jul 10, 2024
1 parent eb36ecf commit 45cf203
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
4 changes: 2 additions & 2 deletions packages/cpp/src/ConstantProductPool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -190,8 +190,8 @@ export const getSwapOutput = (
throw new Error("Input and reserves must be positive");

fee = Fraction.asFraction(fee);
if (fee.lt(Fraction.ZERO) || fee.gte(Fraction.ONE))
throw new Error("fee must be [0,1)");
if (fee.lt(Fraction.ZERO) || fee.gt(Fraction.ONE))
throw new Error("fee must be between 0 and 1");

const feeDiff = fee.denominator - fee.numerator;
const outputNumerator = outputReserve * input * feeDiff;
Expand Down
4 changes: 3 additions & 1 deletion packages/cpp/src/__tests__/ConstantProductPool.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,9 @@ describe("getSwapOutput", () => {
});

test("throws if fee is greater than or equal 1", () => {
expect(() => getSwapOutput(1n, 10n, 10n, Fraction.asFraction(1))).toThrow();
expect(() =>
getSwapOutput(1n, 10n, 10n, Fraction.asFraction(1)),
).not.toThrow();
expect(() =>
getSwapOutput(1n, 10n, 10n, Fraction.asFraction(1.132)),
).toThrow();
Expand Down

0 comments on commit 45cf203

Please sign in to comment.