-
Notifications
You must be signed in to change notification settings - Fork 74
feat: integrate ekubo-v3 #1255
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: integrate ekubo-v3 #1255
Conversation
…call() to get block number
PR Compliance Guide 🔍Below is a summary of compliance checks for this PR:
Compliance status legend🟢 - Fully Compliant🟡 - Partial Compliant 🔴 - Not Compliant ⚪ - Requires Further Human Verification 🏷️ - Compliance label |
||||||||||||||||||||||||
PR Code Suggestions ✨Latest suggestions up to 84242eb
Previous suggestionsSuggestions up to commit 22d65dd
✅ Suggestions up to commit 5345172
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Persistent suggestions updated to latest commit 22d65dd |
Test coverage changes:
|
Co-authored-by: qodo-code-review[bot] <151058649+qodo-code-review[bot]@users.noreply.github.com> Signed-off-by: Minh Nhat Hoang <nhat.hm@outlook.com>
User description
Follow-up to #1253
PR Type
Enhancement, Tests
Description
Comprehensive integration of Ekubo v3 DEX support with full pool simulator, tracker, and event parsing implementations
Implements multiple pool types: Base, FullRange, Stableswap, Oracle, MEV-Capture, and TWAMM pools with quote calculations
Adds complete mathematical library for swap computations including tick conversions, amount deltas, sqrt ratio calculations, and TWAMM-specific exponential functions
Extensive test coverage with 30+ test files covering pool simulators, trackers, event parsers, and mathematical operations
Integrates on-chain data fetching with subgraph support and RPC fallback mechanisms for pool state management
Registers Ekubo v3 as a supported DEX type in factory and pool type systems with msgpack serialization support
Fixes address conversion utilities to use standardized
ZeroToWrappedLowerfunction and corrects zero value cloning in delta calculationsRefactors test utilities to use helper functions for CI detection and log sorting
Diagram Walkthrough
File Walkthrough
18 files
pool_simulator_test.go
Pool simulator test suite with comprehensive swap calculationspkg/liquidity-source/ekubo/v3/pool_simulator_test.go
PoolSimulatorwith 5 real poolconfigurations (lvlUSD-USDC, ETH-USDC, ETH-EKUBO in multiple variants)
CalcAmountOutwith 20+ test cases covering various swapscenarios, amounts, and expected outputs
CalcAmountInfor all pool configurations using utility functionbalance updates
twamm_test.go
TWAMM pool quoting test suitepkg/liquidity-source/ekubo/v3/pools/twamm_test.go
functionality
virtual order deltas, and complex scenarios
various liquidity and sale rate configurations
base_test.go
Base pool quoting and tick management testspkg/liquidity-source/ekubo/v3/pools/base_test.go
tick configurations
NearestInitializedTickIndexfunction with edge cases andmultiple tick scenarios
AddLiquidityCutoffswith positive/negative liquidity deltasand tick boundary conditions
pool_tracker_test.go
Pool tracker integration tests with real transactionspkg/liquidity-source/ekubo/v3/pool_tracker_test.go
PoolTrackerwith real Ethereum transactions andevent logs
different pool types (base, oracle, TWAMM)
stableswap_test.go
Stableswap pool unit testspkg/liquidity-source/ekubo/v3/pools/stableswap_test.go
tick positions
ranges
accounting
swap_test.go
Swap computation unit testspkg/liquidity-source/ekubo/v3/math/swap_test.go
calculations
and overflow conditions
handling
muldiv_test.go
Multiplication and division unit testspkg/liquidity-source/ekubo/v3/math/muldiv_test.go
large numbers
overflow conditions
sqrt_ratio_test.go
TWAMM sqrt ratio calculation testspkg/liquidity-source/ekubo/v3/math/twamm/sqrt_ratio_test.go
rate combinations
time elapsed
delta_test.go
Amount delta calculation unit testspkg/liquidity-source/ekubo/v3/math/delta_test.go
price ranges
conditions
sqrt_ratio_test.go
Sqrt ratio conversion unit testspkg/liquidity-source/ekubo/v3/math/sqrt_ratio_test.go
liquidity levels
mev_capture_test.go
MEV capture pool unit testspkg/liquidity-source/ekubo/v3/pools/mev_capture_test.go
amounts
tick_test.go
Tick conversion unit testspkg/liquidity-source/ekubo/v3/math/tick_test.go
values
factory_test.go
Add ekubo-v3 to factory test DEX typespkg/pooltypes/factory_test.go
ekubov3to the list of supported DEX types inTestCanCalcAmountInekubov3to the list of supported DEX types inTestPoolListerFactoryekubov3to the list of supported DEX types inTestPoolTrackerFactoryevent_parser_test.go
Add ekubo-v3 event parser test suitepkg/liquidity-source/ekubo/v3/event_parser_test.go
VirtualOrdersExecuted, and OrderUpdated events
pools_list_updater_test.go
Add ekubo-v3 pool list updater testpkg/liquidity-source/ekubo/v3/pools_list_updater_test.go
full_range_test.go
Add full-range pool quote calculation testspkg/liquidity-source/ekubo/v3/pools/full_range_test.go
scenarios
exp2_test.go
Add exp2 function tests for TWAMM mathpkg/liquidity-source/ekubo/v3/math/twamm/exp2_test.go
oracle_test.go
Add oracle pool quote calculation testspkg/liquidity-source/ekubo/v3/pools/oracle_test.go
36 files
exp2.go
Fixed-point exponential base-2 computation implementationpkg/liquidity-source/ekubo/v3/math/twamm/exp2.go
exp2) using precomputedmasks and factors for fixed-point arithmetic
handling
data_fetchers.go
On-chain pool data fetching and state constructionpkg/liquidity-source/ekubo/v3/data_fetchers.go
fetchers
MEV-capture, and TWAMM pools
construction from RPC data
base.go
Base pool swap computation and tick managementpkg/liquidity-source/ekubo/v3/pools/base.go
management
Quotemethod for computing swap amounts with tick crossingand fee calculations
UpdateTick,AddLiquidityCutoffs,and
NearestInitializedTickIndexevents.go
Event parsing and state update handlers for Ekubo poolspkg/liquidity-source/ekubo/v3/pools/events.go
BasePool,StableswapPool,FullRangePool,TwammPool) withApplyEventmethodsSwappedandPositionUpdatedevents from blockchain logs toupdate pool state
VirtualOrdersExecuted,OrderUpdated)with virtual order delta tracking
pool identifiers
twamm.go
TWAMM pool implementation with virtual order executionpkg/liquidity-source/ekubo/v3/pools/twamm.go
TwammPooltype with time-weighted average market maker(TWAMM) functionality
over time periods
processing
GetState,CloneState,SetSwapState)keys.go
Pool key structures and serialization logicpkg/liquidity-source/ekubo/v3/pools/keys.go
PoolKeystructure with support for multiple pool typeconfigurations
computation using Keccak256
(Concentrated, FullRange, Stableswap)
generation
pools_list_updater.go
Pool list updater with subgraph integrationpkg/liquidity-source/ekubo/v3/pools_list_updater.go
tracking for incremental updates
when needed
entity.Poolobjects with propertoken and reserve formatting
stableswap parameters
pool_tracker.go
Pool state tracker with event and RPC updatespkg/liquidity-source/ekubo/v3/pool_tracker.go
fallback mechanisms
reorg detection
processing fails
timing
swap.go
Swap step computation logicpkg/liquidity-source/ekubo/v3/math/swap.go
calculations
rounding
error handling
pool_simulator.go
Pool simulator for swap calculationspkg/liquidity-source/ekubo/v3/pool_simulator.go
PoolSimulatorfor swap amount calculations (in/out) usingEkubo pool quotes
error handling
stableswap.go
Stableswap pool implementationpkg/liquidity-source/ekubo/v3/pools/stableswap.go
StableswapPoolwith quote calculation across priceboundaries
detection
sqrt_ratio.go
Sqrt ratio conversion and calculation utilitiespkg/liquidity-source/ekubo/v3/math/sqrt_ratio.go
and vice versa)
representation
event_parser.go
Event parser for pool address extractionpkg/liquidity-source/ekubo/v3/event_parser.go
addresses
Swapped,PositionUpdated,VirtualOrdersExecuted, andOrderUpdatedeventsbalances.go
Add balance calculation methods for ekubo-v3 poolspkg/liquidity-source/ekubo/v3/pools/balances.go
CalcBalances()method forBasePoolStateto calculate tokenbalances from ticks
CalcBalances()forFullRangePoolStateusing amount deltacalculations
CalcBalances()forStableswapPoolwith conditional amountcalculations
full_range.go
Add full-range pool implementation for ekubo-v3pkg/liquidity-source/ekubo/v3/pools/full_range.go
FullRangePoolstruct and related state types for full-rangeliquidity pools
unmarshal.go
Add pool unmarshaling for ekubo-v3 typespkg/liquidity-source/ekubo/v3/unmarshal.go
Stableswap, Concentrated)
mev_capture.go
Add MEV capture pool implementation for ekubo-v3pkg/liquidity-source/ekubo/v3/pools/mev_capture.go
MevCapturePoolextendingBasePoolwith MEV capture feelogic
configuration
sqrt_ratio.go
Add TWAMM sqrt ratio calculation logicpkg/liquidity-source/ekubo/v3/math/twamm/sqrt_ratio.go
CalculateNextSqrtRatio()for TWAMM pools with time-weightedcalculations
elapsed
constants.go
Add ekubo-v3 mathematical constantspkg/liquidity-source/ekubo/v3/math/constants.go
log base
calculations
pool_tracker_test.go
Refactor ekubo pool tracker test utilitiespkg/liquidity-source/ekubo/pool_tracker_test.go
test.SkipCI()helperfunction
valueobject.ZeroToWrappedLower()instead of
FromEkuboAddress()osandtypes)tick.go
Add tick-to-ratio conversion functions for ekubo-v3pkg/liquidity-source/ekubo/v3/math/tick.go
ToSqrtRatio()to convert tick numbers to sqrt ratio valuesApproximateNumberOfTickSpacingsCrossed()for tick spacingcalculations
ApproximateSqrtRatioToTick()for inverse conversiondelta.go
Add amount delta calculations for ekubo-v3pkg/liquidity-source/ekubo/v3/math/delta.go
Amount0Delta()andAmount1Delta()for calculating tokenamount changes
pool_tracker.go
Refactor log sorting in ekubo pool trackerpkg/liquidity-source/ekubo/pool_tracker.go
eth.SortLogs()utility functionslicesandtypes)pools_list_updater.go
Update address conversion in ekubo pool list updaterpkg/liquidity-source/ekubo/pools_list_updater.go
valueobject.ZeroToWrappedLower()instead of
FromEkuboAddress()oracle.go
Add oracle pool implementation for ekubo-v3pkg/liquidity-source/ekubo/v3/pools/oracle.go
OraclePoolextendingFullRangePoolwith oracle snapshot gascosts
type.go
Add ekubo-v3 core type definitionspkg/liquidity-source/ekubo/v3/type.go
Poolinterface with quote, balance, and state managementmethods
StaticExtraandMetastructures for pool metadataconfig.go
Add ekubo-v3 configuration structurepkg/liquidity-source/ekubo/v3/config.go
Configstruct with DEX configuration parametersSupportedExtensions()method for extension type mappingabis.go
Add ABI initialization for ekubo-v3 contractspkg/liquidity-source/ekubo/v3/abis/abis.go
TwammDataFetcher contracts
muldiv.go
Add multiplication and division utilities for ekubo-v3pkg/liquidity-source/ekubo/v3/math/muldiv.go
MulDivOverflow()for safe multiplication and division withrounding
div()helper for division with optional rounding upquote.go
Add quote and swap info types for ekubo-v3pkg/liquidity-source/ekubo/v3/quoting/quote.go
Quotestruct containing swap results and gas costsSwapInfostruct with swap state and routing informationgas.go
Add gas cost constants for ekubo-v3 operationspkg/liquidity-source/ekubo/v3/quoting/gas.go
errors.go
Add error definitions for ekubo-v3 mathpkg/liquidity-source/ekubo/v3/math/errors.go
constants.go
Add ekubo-v3 constants and error definitionspkg/liquidity-source/ekubo/v3/constants.go
DexTypeconstant for ekubo-v3exchange.go
Add ekubo-v3 exchange type constantpkg/valueobject/exchange.go
ExchangeEkuboV3constant with value"ekubo-v3"uint.go
Add uint256 to float conversion utilitypkg/liquidity-source/ekubo/v3/math/uint.go
U256ToFloatBaseX128()for converting uint256 to float64with X128 scaling
extension_type.go
Add extension type enumeration for ekubo-v3pkg/liquidity-source/ekubo/v3/extension_type.go
ExtensionTypeenum with Base, Oracle, Twamm, and MevCapturevariants
1 files
event_parser_test.go
Refactor CI skip condition to use utility functionpkg/liquidity-source/ekubo/event_parser_test.go
test.SkipCIutility functioninstead of manual environment variable check
2 files
pool_simulator_test.go
Update address conversion utility usagepkg/liquidity-source/ekubo/pool_simulator_test.go
valueobject.ZeroToWrappedLowerinstead of
FromEkuboAddressdelta.go
Fix zero value cloning in ekubo delta calculationspkg/liquidity-source/ekubo/math/delta.go
Amount0Delta()to return cloned zero value instead of sharedreference
Amount1Delta()to return cloned zero value instead of sharedreference
7 files
register_pool_types.gen.go
Register ekubo-v3 pool simulator for msgpackpkg/msgpack/register_pool_types.gen.go
pkg_liquiditysource_ekubo_v3packageekubov3.PoolSimulatoras a concrete msgpack typepooltypes.go
Register ekubo-v3 DEX type in pool typespkg/pooltypes/pooltypes.go
ekubov3packageEkuboV3field toTypesstructekubov3.DexTypein default types initializationembed.go
Embed ekubo-v3 contract ABI filespkg/liquidity-source/ekubo/v3/abis/embed.go
TwammDataFetcher contracts
Core.json
Add Core contract ABI for ekubo-v3pkg/liquidity-source/ekubo/v3/abis/Core.json
Twamm.json
Add TWAMM contract ABI for ekubo-v3pkg/liquidity-source/ekubo/v3/abis/Twamm.json
TwammDataFetcher.json
Add TWAMM data fetcher ABI for ekubo-v3pkg/liquidity-source/ekubo/v3/abis/TwammDataFetcher.json
QuoteDataFetcher.json
Add quote data fetcher ABI for ekubo-v3pkg/liquidity-source/ekubo/v3/abis/QuoteDataFetcher.json
1 files