From 538ae323d7d6b5585bda4efe76db7b3f8a5caa1c Mon Sep 17 00:00:00 2001 From: Austin Chen Date: Tue, 7 Jun 2022 08:54:17 -0700 Subject: [PATCH] Floor tick values --- common/calculate-swap3.ts | 2 +- web/pages/swap.tsx | 8 ++------ 2 files changed, 3 insertions(+), 7 deletions(-) diff --git a/common/calculate-swap3.ts b/common/calculate-swap3.ts index fc552e2b..5819ae8e 100644 --- a/common/calculate-swap3.ts +++ b/common/calculate-swap3.ts @@ -91,5 +91,5 @@ function toProb(tick: number) { export function fromProb(prob: number) { const ratio = prob / (1 - prob) - return Math.log(ratio) / Math.log(1.0001) + return Math.floor(Math.log(ratio) / Math.log(1.0001)) } diff --git a/web/pages/swap.tsx b/web/pages/swap.tsx index 9a22b11d..f5bbe7de 100644 --- a/web/pages/swap.tsx +++ b/web/pages/swap.tsx @@ -86,16 +86,12 @@ function PoolTable(props: { pool: Swap3Pool }) { ) } -// Stored as optimization. equal to floor(log_sqrt_1.0001(sqrtRatio)) -function tick(sqrtRatio: number) { - return Math.floor(Math.log(sqrtRatio) / Math.log(1.0001)) -} - export default function Swap() { const [pool, setPool] = useState({ liquidity: 100, sqrtRatio: 2, - tick: tick(0.1), + tick: fromProb(0.3), + ticks: [], }) const [minTick, setMinTick] = useState(0)