feat: create v2-prep branch with comprehensive planning
Restructured project for V2 refactor: **Structure Changes:** - Moved all V1 code to orig/ folder (preserved with git mv) - Created docs/planning/ directory - Added orig/README_V1.md explaining V1 preservation **Planning Documents:** - 00_V2_MASTER_PLAN.md: Complete architecture overview - Executive summary of critical V1 issues - High-level component architecture diagrams - 5-phase implementation roadmap - Success metrics and risk mitigation - 07_TASK_BREAKDOWN.md: Atomic task breakdown - 99+ hours of detailed tasks - Every task < 2 hours (atomic) - Clear dependencies and success criteria - Organized by implementation phase **V2 Key Improvements:** - Per-exchange parsers (factory pattern) - Multi-layer strict validation - Multi-index pool cache - Background validation pipeline - Comprehensive observability **Critical Issues Addressed:** - Zero address tokens (strict validation + cache enrichment) - Parsing accuracy (protocol-specific parsers) - No audit trail (background validation channel) - Inefficient lookups (multi-index cache) - Stats disconnection (event-driven metrics) Next Steps: 1. Review planning documents 2. Begin Phase 1: Foundation (P1-001 through P1-010) 3. Implement parsers in Phase 2 4. Build cache system in Phase 3 5. Add validation pipeline in Phase 4 6. Migrate and test in Phase 5 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
78
orig/pkg/uniswap/pricing_test.go
Normal file
78
orig/pkg/uniswap/pricing_test.go
Normal file
@@ -0,0 +1,78 @@
|
||||
package uniswap
|
||||
|
||||
import (
|
||||
"math/big"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestSqrtPriceX96ToPrice(t *testing.T) {
|
||||
// Test case 1: Basic conversion
|
||||
sqrtPriceX96 := new(big.Int)
|
||||
sqrtPriceX96.SetString("79228162514264337593543950336", 10) // 2^96
|
||||
expected := 1.0
|
||||
actual := SqrtPriceX96ToPrice(sqrtPriceX96)
|
||||
actualFloat, _ := actual.Float64()
|
||||
|
||||
assert.InDelta(t, expected, actualFloat, 0.0001, "SqrtPriceX96ToPrice should convert correctly")
|
||||
|
||||
// Test case 2: Another value - we'll check the relative error instead
|
||||
sqrtPriceX96 = new(big.Int)
|
||||
sqrtPriceX96.SetString("158556325028528675187087900672", 10) // 2 * 2^96
|
||||
expected = 4.0 // (2)^2
|
||||
actual = SqrtPriceX96ToPrice(sqrtPriceX96)
|
||||
actualFloat, _ = actual.Float64()
|
||||
|
||||
// Check that it's close to 4.0 (allowing for floating point precision issues)
|
||||
assert.InDelta(t, expected, actualFloat, 0.01, "SqrtPriceX96ToPrice should convert correctly for 2*2^96")
|
||||
}
|
||||
|
||||
func TestPriceToSqrtPriceX96(t *testing.T) {
|
||||
// Test case 1: Basic conversion
|
||||
price := new(big.Float).SetFloat64(1.0)
|
||||
sqrtPriceX96 := new(big.Int)
|
||||
sqrtPriceX96.SetString("79228162514264337593543950336", 10) // 2^96
|
||||
actual := PriceToSqrtPriceX96(price)
|
||||
|
||||
// Allow for small differences due to floating point precision
|
||||
diff := new(big.Int).Sub(sqrtPriceX96, actual)
|
||||
assert.True(t, diff.Cmp(big.NewInt(1000000000000)) < 0, "PriceToSqrtPriceX96 should convert correctly")
|
||||
|
||||
// Test case 2: Another value
|
||||
price = new(big.Float).SetFloat64(4.0)
|
||||
sqrtPriceX96 = new(big.Int)
|
||||
sqrtPriceX96.SetString("158556325028528675187087900672", 10) // 2 * 2^96
|
||||
actual = PriceToSqrtPriceX96(price)
|
||||
|
||||
// Allow for small differences due to floating point precision
|
||||
diff = new(big.Int).Sub(sqrtPriceX96, actual)
|
||||
// Print actual and expected for debugging
|
||||
t.Logf("Expected: %s, Actual: %s, Diff: %s", sqrtPriceX96.String(), actual.String(), diff.String())
|
||||
// Create a large tolerance value
|
||||
tolerance := new(big.Int)
|
||||
tolerance.SetString("200000000000000000000000000", 10)
|
||||
// Increase the tolerance for the test to account for the large difference
|
||||
assert.True(t, diff.Cmp(tolerance) < 0, "PriceToSqrtPriceX96 should convert correctly for price=4.0")
|
||||
}
|
||||
|
||||
func TestTickToSqrtPriceX96(t *testing.T) {
|
||||
// Test case 1: Tick 0 should result in price 1.0
|
||||
expected := new(big.Int)
|
||||
expected.SetString("79228162514264337593543950336", 10) // 2^96
|
||||
actual := TickToSqrtPriceX96(0)
|
||||
|
||||
// Allow for small differences due to floating point precision
|
||||
diff := new(big.Int).Sub(expected, actual)
|
||||
assert.True(t, diff.Cmp(big.NewInt(1000000000000)) < 0, "TickToSqrtPriceX96 should convert tick 0 correctly")
|
||||
}
|
||||
|
||||
func TestSqrtPriceX96ToTick(t *testing.T) {
|
||||
// Test case 1: sqrtPriceX96 for price 1.0 should result in tick 0
|
||||
sqrtPriceX96 := new(big.Int)
|
||||
sqrtPriceX96.SetString("79228162514264337593543950336", 10) // 2^96
|
||||
expected := 0
|
||||
actual := SqrtPriceX96ToTick(sqrtPriceX96)
|
||||
|
||||
assert.Equal(t, expected, actual, "SqrtPriceX96ToTick should convert sqrtPriceX96 for price 1.0 correctly")
|
||||
}
|
||||
Reference in New Issue
Block a user