Files
mev-beta/pkg/dex/types.go

149 lines
3.3 KiB
Go

package dex
import (
"math/big"
"github.com/ethereum/go-ethereum/common"
)
// DEXProtocol represents supported DEX protocols
type DEXProtocol int
const (
ProtocolUnknown DEXProtocol = iota
ProtocolUniswapV2
ProtocolUniswapV3
ProtocolSushiSwap
ProtocolCurve
ProtocolBalancer
ProtocolCamelot
ProtocolTraderJoe
)
// String returns the protocol name
func (p DEXProtocol) String() string {
switch p {
case ProtocolUniswapV2:
return "UniswapV2"
case ProtocolUniswapV3:
return "UniswapV3"
case ProtocolSushiSwap:
return "SushiSwap"
case ProtocolCurve:
return "Curve"
case ProtocolBalancer:
return "Balancer"
case ProtocolCamelot:
return "Camelot"
case ProtocolTraderJoe:
return "TraderJoe"
default:
return "Unknown"
}
}
// PricingModel represents the pricing model used by a DEX
type PricingModel int
const (
PricingConstantProduct PricingModel = iota // x*y=k (UniswapV2, SushiSwap)
PricingConcentrated // Concentrated liquidity (UniswapV3)
PricingStableSwap // StableSwap (Curve)
PricingWeighted // Weighted pools (Balancer)
)
// String returns the pricing model name
func (pm PricingModel) String() string {
switch pm {
case PricingConstantProduct:
return "ConstantProduct"
case PricingConcentrated:
return "ConcentratedLiquidity"
case PricingStableSwap:
return "StableSwap"
case PricingWeighted:
return "WeightedPools"
default:
return "Unknown"
}
}
// DEXInfo contains information about a DEX
type DEXInfo struct {
Protocol DEXProtocol
Name string
RouterAddress common.Address
FactoryAddress common.Address
Fee *big.Int // Default fee in basis points (e.g., 30 = 0.3%)
PricingModel PricingModel
Decoder DEXDecoder
Active bool
}
// PoolReserves represents pool reserves and metadata
type PoolReserves struct {
Token0 common.Address
Token1 common.Address
Reserve0 *big.Int
Reserve1 *big.Int
Fee *big.Int
Protocol DEXProtocol
PoolAddress common.Address
// UniswapV3 specific
SqrtPriceX96 *big.Int
Tick int32
Liquidity *big.Int
// Curve specific
A *big.Int // Amplification coefficient
// Balancer specific
Weights []*big.Int
}
// SwapInfo represents decoded swap information
type SwapInfo struct {
Protocol DEXProtocol
PoolAddress common.Address
TokenIn common.Address
TokenOut common.Address
AmountIn *big.Int
AmountOut *big.Int
Recipient common.Address
Fee *big.Int
Deadline *big.Int
}
// PriceQuote represents a price quote from a DEX
type PriceQuote struct {
DEX DEXProtocol
PoolAddress common.Address
TokenIn common.Address
TokenOut common.Address
AmountIn *big.Int
ExpectedOut *big.Int
PriceImpact float64
Fee *big.Int
GasEstimate uint64
}
// ArbitragePath represents a multi-DEX arbitrage path
type ArbitragePath struct {
Hops []*PathHop
TotalProfit *big.Int
ProfitETH float64
ROI float64
GasCost *big.Int
NetProfit *big.Int
Confidence float64
}
// PathHop represents a single hop in an arbitrage path
type PathHop struct {
DEX DEXProtocol
PoolAddress common.Address
TokenIn common.Address
TokenOut common.Address
AmountIn *big.Int
AmountOut *big.Int
Fee *big.Int
}