Skip to content

Commit

Permalink
fix: lower the highest tick boundary for extra safety
Browse files Browse the repository at this point in the history
(cherry picked from commit 99b5bf5)
  • Loading branch information
hallazzang authored and kingcre committed Oct 19, 2022
1 parent a7079c3 commit a3c646b
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 7 deletions.
4 changes: 3 additions & 1 deletion x/liquidity/amm/tick.go
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,9 @@ func DownTick(price sdk.Dec, prec int) sdk.Dec {

// HighestTick returns the highest possible price tick.
func HighestTick(prec int) sdk.Dec {
i := new(big.Int).SetBits([]big.Word{0, 0, 0, 0, 0x1000000000000000})
i := big.NewInt(2)
// Maximum 315 bits possible, but take slightly less value for safety.
i.Exp(i, big.NewInt(300), nil).Sub(i, big.NewInt(1))
return PriceToDownTick(sdk.NewDecFromBigIntWithPrec(i, sdk.Precision), prec)
}

Expand Down
9 changes: 3 additions & 6 deletions x/liquidity/amm/tick_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,18 +110,15 @@ func TestHighestTick(t *testing.T) {
prec int
expected string
}{
{3, "133400000000000000000000000000000000000000000000000000000000000000000000000000"},
{0, "100000000000000000000000000000000000000000000000000000000000000000000000000000"},
{1, "130000000000000000000000000000000000000000000000000000000000000000000000000000"},
{3, "2037000000000000000000000000000000000000000000000000000000000000000000000"},
{0, "2000000000000000000000000000000000000000000000000000000000000000000000000"},
{1, "2000000000000000000000000000000000000000000000000000000000000000000000000"},
} {
t.Run("", func(t *testing.T) {
i, ok := new(big.Int).SetString(tc.expected, 10)
require.True(t, ok)
tick := amm.HighestTick(tc.prec)
require.True(sdk.DecEq(t, sdk.NewDecFromBigInt(i), tick))
require.Panics(t, func() {
amm.UpTick(tick, tc.prec)
})
})
}
}
Expand Down

0 comments on commit a3c646b

Please sign in to comment.