feat(core): implement core MEV bot functionality with market scanning and Uniswap V3 pricing
Co-authored-by: Qwen-Coder <qwen-coder@alibabacloud.com>
This commit is contained in:
@@ -12,7 +12,7 @@ import (
|
||||
func BenchmarkSqrtPriceX96ToPrice(b *testing.B) {
|
||||
sqrtPriceX96 := new(big.Int)
|
||||
sqrtPriceX96.SetString("79228162514264337593543950336", 10) // 2^96
|
||||
|
||||
|
||||
b.ResetTimer()
|
||||
for i := 0; i < b.N; i++ {
|
||||
_ = uniswap.SqrtPriceX96ToPrice(sqrtPriceX96)
|
||||
@@ -22,7 +22,7 @@ func BenchmarkSqrtPriceX96ToPrice(b *testing.B) {
|
||||
// BenchmarkPriceToSqrtPriceX96 benchmarks the PriceToSqrtPriceX96 function
|
||||
func BenchmarkPriceToSqrtPriceX96(b *testing.B) {
|
||||
price := new(big.Float).SetFloat64(1.0)
|
||||
|
||||
|
||||
b.ResetTimer()
|
||||
for i := 0; i < b.N; i++ {
|
||||
_ = uniswap.PriceToSqrtPriceX96(price)
|
||||
@@ -41,7 +41,7 @@ func BenchmarkTickToSqrtPriceX96(b *testing.B) {
|
||||
func BenchmarkSqrtPriceX96ToTick(b *testing.B) {
|
||||
sqrtPriceX96 := new(big.Int)
|
||||
sqrtPriceX96.SetString("79228162514264337593543950336", 10) // 2^96
|
||||
|
||||
|
||||
b.ResetTimer()
|
||||
for i := 0; i < b.N; i++ {
|
||||
_ = uniswap.SqrtPriceX96ToTick(sqrtPriceX96)
|
||||
@@ -51,7 +51,7 @@ func BenchmarkSqrtPriceX96ToTick(b *testing.B) {
|
||||
// BenchmarkPricingConversionsSequential benchmarks sequential pricing conversions
|
||||
func BenchmarkPricingConversionsSequential(b *testing.B) {
|
||||
price := new(big.Float).SetFloat64(1.0)
|
||||
|
||||
|
||||
b.ResetTimer()
|
||||
for i := 0; i < b.N; i++ {
|
||||
sqrtPriceX96 := uniswap.PriceToSqrtPriceX96(price)
|
||||
@@ -69,22 +69,22 @@ func BenchmarkPricingCalculationRealistic(b *testing.B) {
|
||||
}{
|
||||
{"ETH_USDC_1800", "2231455953840924584200896000"}, // ~1800 USDC per ETH
|
||||
{"ETH_USDC_3000", "2890903041336652768307200000"}, // ~3000 USDC per ETH
|
||||
{"WBTC_ETH_15", "977228162514264337593543950"}, // ~15 ETH per WBTC
|
||||
{"WBTC_ETH_15", "977228162514264337593543950"}, // ~15 ETH per WBTC
|
||||
{"DAI_USDC_1", "79228162514264337593543950336"}, // ~1 DAI per USDC
|
||||
}
|
||||
|
||||
|
||||
for _, tc := range testCases {
|
||||
b.Run(tc.name, func(b *testing.B) {
|
||||
sqrtPriceX96 := new(big.Int)
|
||||
sqrtPriceX96.SetString(tc.sqrtPriceX96, 10)
|
||||
|
||||
|
||||
b.ResetTimer()
|
||||
for i := 0; i < b.N; i++ {
|
||||
price := uniswap.SqrtPriceX96ToPrice(sqrtPriceX96)
|
||||
tick := uniswap.SqrtPriceX96ToTick(sqrtPriceX96)
|
||||
backToSqrt := uniswap.TickToSqrtPriceX96(tick)
|
||||
_ = uniswap.SqrtPriceX96ToPrice(backToSqrt)
|
||||
|
||||
|
||||
// Verify we get similar price back (within reasonable precision)
|
||||
require.NotNil(b, price)
|
||||
}
|
||||
@@ -104,11 +104,11 @@ func BenchmarkExtremePriceValues(b *testing.B) {
|
||||
{"High_100.0", 100.0},
|
||||
{"VeryHigh_1000000.0", 1000000.0},
|
||||
}
|
||||
|
||||
|
||||
for _, tc := range extremeCases {
|
||||
b.Run(tc.name, func(b *testing.B) {
|
||||
price := new(big.Float).SetFloat64(tc.price)
|
||||
|
||||
|
||||
b.ResetTimer()
|
||||
for i := 0; i < b.N; i++ {
|
||||
sqrtPriceX96 := uniswap.PriceToSqrtPriceX96(price)
|
||||
@@ -126,32 +126,32 @@ func BenchmarkBigIntOperations(b *testing.B) {
|
||||
x := big.NewInt(1000000)
|
||||
y := big.NewInt(2000000)
|
||||
result := new(big.Int)
|
||||
|
||||
|
||||
b.ResetTimer()
|
||||
for i := 0; i < b.N; i++ {
|
||||
result.Mul(x, y)
|
||||
}
|
||||
})
|
||||
|
||||
|
||||
b.Run("BigInt_Division", func(b *testing.B) {
|
||||
x := big.NewInt(1000000000000)
|
||||
y := big.NewInt(1000000)
|
||||
result := new(big.Int)
|
||||
|
||||
|
||||
b.ResetTimer()
|
||||
for i := 0; i < b.N; i++ {
|
||||
result.Div(x, y)
|
||||
}
|
||||
})
|
||||
|
||||
|
||||
b.Run("BigFloat_Operations", func(b *testing.B) {
|
||||
x := big.NewFloat(1000000.5)
|
||||
y := big.NewFloat(2000000.3)
|
||||
result := new(big.Float)
|
||||
|
||||
|
||||
b.ResetTimer()
|
||||
for i := 0; i < b.N; i++ {
|
||||
result.Mul(x, y)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user