Skip to content

Commit

Permalink
feat: adds tick price functions (#3072)
Browse files Browse the repository at this point in the history
* adds tick price functions

* add no lint
  • Loading branch information
czarcas7ic authored Oct 20, 2022
1 parent 4b26c71 commit 9f16171
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand Down Expand Up @@ -73,6 +74,22 @@ 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)
tick := logOfPrice.Quo(logInt.ApproxLog2())
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
}

func (p Pool) GetAddress() sdk.AccAddress {
return sdk.AccAddress{}
}
Expand Down

0 comments on commit 9f16171

Please sign in to comment.