- Add new math package with optimized implementations for major DEX protocols - Implement Uniswap V2, V3, V4, Curve, Kyber, Balancer, and Algebra mathematical functions - Optimize Uniswap V3 pricing functions with caching and uint256 optimizations - Add lookup table optimizations for frequently used calculations - Implement price impact and slippage calculation functions - Add comprehensive benchmarks showing 12-24% performance improvements - Fix test expectations to use correct mathematical formulas - Document mathematical optimization strategies and results
37 lines
739 B
Go
37 lines
739 B
Go
package lookup
|
|
|
|
import (
|
|
"math/big"
|
|
"testing"
|
|
)
|
|
|
|
func BenchmarkSqrtPriceX96ToPriceWithLookup(b *testing.B) {
|
|
// Create a test sqrtPriceX96 value
|
|
sqrtPriceX96 := new(big.Int)
|
|
sqrtPriceX96.SetString("79228162514264337593543950336", 10) // 2^96
|
|
|
|
b.ResetTimer()
|
|
for i := 0; i < b.N; i++ {
|
|
_ = SqrtPriceX96ToPriceWithLookup(sqrtPriceX96)
|
|
}
|
|
}
|
|
|
|
func BenchmarkPriceToSqrtPriceX96WithLookup(b *testing.B) {
|
|
// Create a test price value
|
|
price := new(big.Float).SetFloat64(1.0)
|
|
|
|
b.ResetTimer()
|
|
for i := 0; i < b.N; i++ {
|
|
_ = PriceToSqrtPriceX96WithLookup(price)
|
|
}
|
|
}
|
|
|
|
func BenchmarkTickToSqrtPriceX96WithLookup(b *testing.B) {
|
|
tick := 100000
|
|
|
|
b.ResetTimer()
|
|
for i := 0; i < b.N; i++ {
|
|
_ = TickToSqrtPriceX96WithLookup(tick)
|
|
}
|
|
}
|