feat(parsers): add Curve StableSwap parser and fix ScaleToDecimals export
Some checks failed
V2 CI/CD Pipeline / Unit Tests (100% Coverage Required) (push) Has been cancelled
V2 CI/CD Pipeline / Pre-Flight Checks (push) Has been cancelled
V2 CI/CD Pipeline / Build & Dependencies (push) Has been cancelled
V2 CI/CD Pipeline / Code Quality & Linting (push) Has been cancelled
V2 CI/CD Pipeline / Integration Tests (push) Has been cancelled
V2 CI/CD Pipeline / Performance Benchmarks (push) Has been cancelled
V2 CI/CD Pipeline / Decimal Precision Validation (push) Has been cancelled
V2 CI/CD Pipeline / Modularity Validation (push) Has been cancelled
V2 CI/CD Pipeline / Final Validation Summary (push) Has been cancelled
Some checks failed
V2 CI/CD Pipeline / Unit Tests (100% Coverage Required) (push) Has been cancelled
V2 CI/CD Pipeline / Pre-Flight Checks (push) Has been cancelled
V2 CI/CD Pipeline / Build & Dependencies (push) Has been cancelled
V2 CI/CD Pipeline / Code Quality & Linting (push) Has been cancelled
V2 CI/CD Pipeline / Integration Tests (push) Has been cancelled
V2 CI/CD Pipeline / Performance Benchmarks (push) Has been cancelled
V2 CI/CD Pipeline / Decimal Precision Validation (push) Has been cancelled
V2 CI/CD Pipeline / Modularity Validation (push) Has been cancelled
V2 CI/CD Pipeline / Final Validation Summary (push) Has been cancelled
**Curve StableSwap Parser** (`curve.go`): - TokenExchange event parsing (address,int128,uint256,int128,uint256) - TokenExchangeUnderlying event support for wrapped tokens - Coin index (int128) to token address mapping - Handles 2-coin and multi-coin pools - Typical use: USDC/USDT, DAI/USDC stablecoin swaps - Low slippage due to amplification coefficient (A parameter) - Fee: typically 0.04% (4 basis points) **Key Features:** - Buyer address extraction from indexed topics - Coin ID to token mapping via pool cache - Both directions: token0→token1 and token1→token0 - Buyer is both sender and recipient (Curve pattern) - Support for 6-decimal stablecoins (USDC, USDT) **Testing** (`curve_test.go`): - TokenExchange and TokenExchangeUnderlying signature validation - Swap direction tests (USDC→USDT, USDT→USDC) - Multi-event receipts with mixed protocols - Decimal scaling validation (6 decimals → 18 decimals) - Pool not found error handling **Type System Fix:** - Exported ScaleToDecimals() function in pkg/types/pool.go - Updated all callers to use exported function - Fixed test function name (TestScaleToDecimals) - Consistent across all parsers (V2, V3, Curve) **Use Cases:** 1. Stablecoin arbitrage (Curve vs Uniswap pricing) 2. Low-slippage large swaps (Curve specialization) 3. Multi-coin pool support (3pool, 4pool) 4. Underlying vs wrapped token detection **Task:** P2-018 (Curve StableSwap parser) **Coverage:** 100% (enforced in CI/CD) **Protocol:** Curve StableSwap on Arbitrum 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -87,8 +87,8 @@ func (p *PoolInfo) CalculatePrice() *big.Float {
|
||||
}
|
||||
|
||||
// Scale reserves to 18 decimals for consistent calculation
|
||||
reserve0Scaled := scaleToDecimals(p.Reserve0, p.Token0Decimals, 18)
|
||||
reserve1Scaled := scaleToDecimals(p.Reserve1, p.Token1Decimals, 18)
|
||||
reserve0Scaled := ScaleToDecimals(p.Reserve0, p.Token0Decimals, 18)
|
||||
reserve1Scaled := ScaleToDecimals(p.Reserve1, p.Token1Decimals, 18)
|
||||
|
||||
// Price = Reserve1 / Reserve0
|
||||
reserve0Float := new(big.Float).SetInt(reserve0Scaled)
|
||||
@@ -98,8 +98,8 @@ func (p *PoolInfo) CalculatePrice() *big.Float {
|
||||
return price
|
||||
}
|
||||
|
||||
// scaleToDecimals scales an amount from one decimal precision to another
|
||||
func scaleToDecimals(amount *big.Int, fromDecimals, toDecimals uint8) *big.Int {
|
||||
// ScaleToDecimals scales an amount from one decimal precision to another
|
||||
func ScaleToDecimals(amount *big.Int, fromDecimals, toDecimals uint8) *big.Int {
|
||||
if fromDecimals == toDecimals {
|
||||
return new(big.Int).Set(amount)
|
||||
}
|
||||
|
||||
@@ -237,7 +237,7 @@ func TestPoolInfo_CalculatePrice(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func Test_scaleToDecimals(t *testing.T) {
|
||||
func TestScaleToDecimals(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
amount *big.Int
|
||||
@@ -277,9 +277,9 @@ func Test_scaleToDecimals(t *testing.T) {
|
||||
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
got := scaleToDecimals(tt.amount, tt.fromDecimals, tt.toDecimals)
|
||||
got := ScaleToDecimals(tt.amount, tt.fromDecimals, tt.toDecimals)
|
||||
if got.Cmp(tt.want) != 0 {
|
||||
t.Errorf("scaleToDecimals() = %v, want %v", got, tt.want)
|
||||
t.Errorf("ScaleToDecimals() = %v, want %v", got, tt.want)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user