Skip to content

Commit

Permalink
Speedup SpotPrice impl
Browse files Browse the repository at this point in the history
  • Loading branch information
ValarDragon committed Apr 12, 2024
1 parent aabae07 commit a33352f
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
5 changes: 5 additions & 0 deletions osmomath/decimal.go
Original file line number Diff line number Diff line change
Expand Up @@ -1247,6 +1247,11 @@ func (d BigDec) PowerInteger(power uint64) BigDec {
func (d BigDec) PowerIntegerMut(power uint64) BigDec {
if power == 0 {
return OneBigDec()
} else if power == 1 {
return d
} else if power == 2 {
// save a oneBigDec allocation
return d.MulMut(d)
}
tmp := OneBigDec()

Expand Down
2 changes: 1 addition & 1 deletion x/concentrated-liquidity/model/pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ func (p Pool) SpotPrice(ctx sdk.Context, quoteAssetDenom string, baseAssetDenom
if baseAssetDenom == p.Token0 {
return osmomath.BigDecFromDecMut(priceSquared.Dec()), nil
}
return osmomath.BigDecFromDecMut(osmomath.OneBigDec().Quo(priceSquared).Dec()), nil
return osmomath.BigDecFromDecMut(osmomath.OneBigDec().QuoMut(priceSquared).Dec()), nil
}

// GetToken0 returns the token0 of the pool
Expand Down

0 comments on commit a33352f

Please sign in to comment.