Skip to content

Commit

Permalink
fix: Fix fin near tick at negative tick
Browse files Browse the repository at this point in the history
  • Loading branch information
jinoosss committed Dec 6, 2023
1 parent a80b76e commit 8235402
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
4 changes: 2 additions & 2 deletions packages/web/src/utils/swap-utils.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,13 +93,13 @@ describe("price convert to near tick", () => {
test("0.60651549714 to -5002", () => {
const price = 0.60651549714;
const tickSpacing = 2;
expect(priceToNearTick(price, tickSpacing)).toBe(-5002);
expect(priceToNearTick(price, tickSpacing)).toBe(-5000);
});

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

Expand Down
5 changes: 3 additions & 2 deletions packages/web/src/utils/swap-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ export function priceToTick(price: number | bigint) {
return Math.round(BigNumber(logPrice).dividedBy(LOG10001).toNumber());
}

export function priceToNearTick(price: number | bigint, tickSpacing: number) {
export function priceToNearTick(price: number, tickSpacing: number) {
console.log(price);
const tickRaw = priceToTick(price);
const tickAbs = Math.abs(tickRaw);
const mod = tickAbs % tickSpacing;
Expand All @@ -37,7 +38,7 @@ export function priceToNearTick(price: number | bigint, tickSpacing: number) {
return maxTick * sign;
}

const nearTickAmount = tickAbs - mod;
const nearTickAmount = sign > 0 ? tickAbs - mod : tickAbs - mod - tickSpacing;
const nearTick =
mod > tickSpacing / 2
? (nearTickAmount + tickSpacing) * sign
Expand Down

0 comments on commit 8235402

Please sign in to comment.