Skip to content

Commit

Permalink
fix: Fix tick testcases
Browse files Browse the repository at this point in the history
  • Loading branch information
jinoosss committed Nov 15, 2023
1 parent cd674d0 commit 7cfb250
Showing 1 changed file with 19 additions and 10 deletions.
29 changes: 19 additions & 10 deletions packages/web/src/utils/swap-utils.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@ describe("tick convert to price", () => {
expect(tickToPrice(tick)).toBe(1);
});

test("10000 to 1.6486800559311758", () => {
test("10000 to 2.718145926825225", () => {
const tick = 10000;
expect(tickToPrice(tick)).toBe(1.6486800559311758);
expect(tickToPrice(tick)).toBe(2.718145926825225);
});

test("10001 to 1.6487624878732252", () => {
test("10001 to 2.7184177414179076", () => {
const tick = 10001;
expect(tickToPrice(tick)).toBe(1.6487624878732252);
expect(tickToPrice(tick)).toBe(2.7184177414179076);
});
});

Expand All @@ -30,17 +30,17 @@ describe("price convert to tick", () => {

test("1.6486800559311758 to 10000", () => {
const price = 1.6486800559311758;
expect(priceToTick(price)).toBe(10000);
expect(priceToTick(price)).toBe(5000);
});

test("1.6487624878732252 to 10001", () => {
const price = 1.6487624878732252;
expect(priceToTick(price)).toBe(10001);
expect(priceToTick(price)).toBe(5001);
});

test("0.60651549714 to -10001", () => {
const price = 0.60651549714;
expect(priceToTick(price)).toBe(-10001);
expect(priceToTick(price)).toBe(-5001);
});
});

Expand All @@ -54,23 +54,32 @@ describe("price convert to near tick", () => {
test("1.6486800559311758 to 10002", () => {
const price = 1.6489273641220126;
const tickSpacing = 2;
expect(priceToNearTick(price, tickSpacing)).toBe(10002);
expect(priceToNearTick(price, tickSpacing)).toBe(5002);
});

test("0.60651549714 to -10002", () => {
const price = 0.60651549714;
const tickSpacing = 2;
expect(priceToNearTick(price, tickSpacing)).toBe(-10002);
expect(priceToNearTick(price, tickSpacing)).toBe(-5002);
});

test("0.60651549714 to -10004", () => {
const price = 0.60651549714;
const tickSpacing = 4;
expect(priceToNearTick(price, tickSpacing)).toBe(-10004);
expect(priceToNearTick(price, tickSpacing)).toBe(-5004);
});
});

describe("fee boost by prices", () => {
test("0 ~ 2 tick price to 20001.50", () => {
const minTick = 0;
const maxTick = 2;
const minPrice = tickToPrice(minTick);
const maxPrice = tickToPrice(maxTick);
const feeBoost = feeBoostRateByPrices(minPrice, maxPrice);
expect(feeBoost).toBe("20001.50");
});

test("0.8976, 1.1041 to 19.82", () => {
const feeBoost = feeBoostRateByPrices(0.8976, 1.1041);
expect(feeBoost).toBe("19.82");
Expand Down

0 comments on commit 7cfb250

Please sign in to comment.