saving in place

This commit is contained in:
Krypto Kajun
2025-10-04 09:31:02 -05:00
parent 76c1b5cee1
commit f358f49aa9
295 changed files with 72071 additions and 17209 deletions

72
pkg/uniswap/constants.go Normal file
View File

@@ -0,0 +1,72 @@
// Package uniswap provides mathematical functions for Uniswap V3 calculations.
package uniswap
import (
"math"
"math/big"
"sync"
)
var (
// Global cached constants initialized once to avoid recomputing them
q96 *big.Int
q192 *big.Int
lnBase float64 // ln(1.0001)
invLnBase float64 // 1 / ln(1.0001)
q96Float *big.Float
q192Float *big.Float
once sync.Once
)
// InitConstants initializes all global cached constants
func InitConstants() {
once.Do(func() {
q96 = new(big.Int).Exp(big.NewInt(2), big.NewInt(96), nil)
q192 = new(big.Int).Exp(big.NewInt(2), big.NewInt(192), nil)
lnBase = math.Log(1.0001)
invLnBase = 1.0 / lnBase
q96Float = new(big.Float).SetInt(q96)
q192Float = new(big.Float).SetInt(q192)
})
}
// initConstants initializes all global cached constants (alias for internal use)
func initConstants() {
InitConstants()
}
// GetQ96 returns the cached value of 2^96
func GetQ96() *big.Int {
initConstants()
return q96
}
// GetQ192 returns the cached value of 2^192
func GetQ192() *big.Int {
initConstants()
return q192
}
// GetLnBase returns the cached value of ln(1.0001)
func GetLnBase() float64 {
initConstants()
return lnBase
}
// GetInvLnBase returns the cached value of 1/ln(1.0001)
func GetInvLnBase() float64 {
initConstants()
return invLnBase
}
// GetQ96Float returns the cached value of 2^96 as big.Float
func GetQ96Float() *big.Float {
initConstants()
return q96Float
}
// GetQ192Float returns the cached value of 2^192 as big.Float
func GetQ192Float() *big.Float {
initConstants()
return q192Float
}