Skip to content

Commit

Permalink
more testing
Browse files Browse the repository at this point in the history
  • Loading branch information
kyscott18 committed Sep 18, 2023
1 parent 5e9382a commit 481b46a
Showing 1 changed file with 17 additions and 3 deletions.
20 changes: 17 additions & 3 deletions packages/uniswap-v3-sdk/src/amounts.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
createAmountFromString,
createFraction,
createPriceFromFraction,
rawPrice,
} from "reverse-mirage";
import { zeroAddress } from "viem";
import { expect, test } from "vitest";
Expand All @@ -16,6 +17,7 @@ import {
createPosition,
createTick,
createUniswapV3Pool,
fractionToQ96,
getPositionID,
q96ToFraction,
} from "./utils.js";
Expand Down Expand Up @@ -211,12 +213,16 @@ test("single tick swap", async () => {
createAmountFromString(token0, "-0.000005"),
);

const [uniAmount1, _] = await uniPool.getInputAmount(
const [uniAmount1, up] = await uniPool.getInputAmount(
CurrencyAmount.fromFractionalAmount(uniToken0, "5000000000000", "1"),
);

expect(amount0.amount).toBe(-5n * 10n ** 12n);
expect(amount1.amount).toBe(BigInt(uniAmount1.asFraction.toFixed(0)));
expect(poolData.liquidity).toBe(BigInt(up.liquidity.toString()));
expect(fractionToQ96(rawPrice(poolData.sqrtPrice))).toBe(
BigInt(up.sqrtRatioX96.toString()),
);
});

test("multi tick swap", async () => {
Expand Down Expand Up @@ -286,12 +292,16 @@ test("multi tick swap", async () => {
createAmountFromString(token0, "-0.00014"),
);

const [uniAmount1, _] = await uniPool.getInputAmount(
const [uniAmount1, up] = await uniPool.getInputAmount(
CurrencyAmount.fromFractionalAmount(uniToken0, "140000000000000", "1"),
);

expect(amount0.amount).toBe(-140000000000000n);
expect(amount1.amount).toBe(BigInt(uniAmount1.asFraction.toFixed(0)));
expect(poolData.liquidity).toBe(BigInt(up.liquidity.toString()));
expect(fractionToQ96(rawPrice(poolData.sqrtPrice))).toBe(
BigInt(up.sqrtRatioX96.toString()),
);
});

test("far tick swap", async () => {
Expand Down Expand Up @@ -366,10 +376,14 @@ test("far tick swap", async () => {
createAmountFromString(token0, "-0.00008"),
);

const [uniAmount1, _] = await uniPool.getInputAmount(
const [uniAmount1, up] = await uniPool.getInputAmount(
CurrencyAmount.fromFractionalAmount(uniToken0, "80000000000000", "1"),
);

expect(amount0.amount).toBe(-80000000000000n);
expect(amount1.amount).toBe(BigInt(uniAmount1.asFraction.toFixed(0)));
expect(poolData.liquidity).toBe(BigInt(up.liquidity.toString()));
expect(fractionToQ96(rawPrice(poolData.sqrtPrice))).toBe(
BigInt(up.sqrtRatioX96.toString()),
);
});

0 comments on commit 481b46a

Please sign in to comment.