From 5b05c3e447b6e4630cf9d2d8b0ef49135298eaa7 Mon Sep 17 00:00:00 2001 From: Adam Tucker Date: Wed, 19 Oct 2022 17:10:30 -0700 Subject: [PATCH 1/2] adds tick price functions --- x/concentrated-liquidity/pool.go | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/x/concentrated-liquidity/pool.go b/x/concentrated-liquidity/pool.go index 0094986a411..879d90152ff 100644 --- a/x/concentrated-liquidity/pool.go +++ b/x/concentrated-liquidity/pool.go @@ -5,6 +5,7 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/osmosis-labs/osmosis/v12/osmomath" "github.com/osmosis-labs/osmosis/v12/x/gamm/types" ) @@ -73,6 +74,18 @@ func calcAmount1(liq, pa, pb sdk.Dec) sdk.Dec { return liq.Mul(diff) } +func priceToTick(price sdk.Dec) sdk.Int { + logOfPrice := osmomath.BigDecFromSDKDec(price).ApproxLog2() + logInt := osmomath.NewDecWithPrec(10001, 4) + tick := logOfPrice.Quo(logInt.ApproxLog2()) + return tick.SDKDec().TruncateInt() +} + +func tickToPrice(tick sdk.Int) sdk.Dec { + price := sdk.NewDecWithPrec(10001, 4).Power(tick.Uint64()) + return price +} + func (p Pool) GetAddress() sdk.AccAddress { return sdk.AccAddress{} } From 9b21ace31b7c737043a610bc63039cf377b9d3dd Mon Sep 17 00:00:00 2001 From: Adam Tucker Date: Wed, 19 Oct 2022 17:19:44 -0700 Subject: [PATCH 2/2] add no lint --- x/concentrated-liquidity/pool.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/x/concentrated-liquidity/pool.go b/x/concentrated-liquidity/pool.go index 879d90152ff..26ee8dad246 100644 --- a/x/concentrated-liquidity/pool.go +++ b/x/concentrated-liquidity/pool.go @@ -74,6 +74,8 @@ func calcAmount1(liq, pa, pb sdk.Dec) sdk.Dec { return liq.Mul(diff) } +// TODO: remove nolint +// nolint: unused func priceToTick(price sdk.Dec) sdk.Int { logOfPrice := osmomath.BigDecFromSDKDec(price).ApproxLog2() logInt := osmomath.NewDecWithPrec(10001, 4) @@ -81,6 +83,8 @@ func priceToTick(price sdk.Dec) sdk.Int { return tick.SDKDec().TruncateInt() } +// TODO: remove nolint +// nolint: unused func tickToPrice(tick sdk.Int) sdk.Dec { price := sdk.NewDecWithPrec(10001, 4).Power(tick.Uint64()) return price