forked from jl777/SuperNET
-
Notifications
You must be signed in to change notification settings - Fork 113
Open
Labels
feature: APIfeature: swappriority: mediumModerately important tasks that should be completed but are not urgent.Moderately important tasks that should be completed but are not urgent.status: in progress
Description
Liquidity Routing (LR) Feature Tracking Issue
This issue tracks all remaining work for the Liquidity Routing feature in the Komodo DeFi Framework.
Background
Liquidity Routing enables users to execute swaps through intermediate token conversions using providers like 1inch. This allows trading Token A for Token D even when direct P2P orders only exist for Token B ↔ Token C.
Related PRs
- ✅ feat(swap): rpc to find best swap with liquidity routing for ask #2362 - [MERGED] Initial
find_best_quoteRPC for ask orders - ⏳ feat(LR): add buy action, bid order and LR_1 support to find_best_quote RPC #2545 - [OPEN] Add buy action, bid order, and LR_1 support to
find_best_quote - ⏳ feat(LR): execute_routed_trade RPC implementation #2546 - [OPEN]
execute_routed_tradeRPC and state machine implementation - ✅ feat(LRAPI): add 1inch classic swap rpc #2222 - [MERGED] 1inch classic swap RPC
- 📍 dimxy/lr-swap-wip-current - Contains additional fixes and dockerized tests after PRs 2545/2546
Related Issues/PRs in Other Repos
- ⏳ komodo-defi-proxy#28 - Add 1inch API to proxy (required for production)
- ⏳ komodo-docs-mdx#566 - Add new KDF method docs for
find_best_quote
Related Issues in This Repo
- 3 party "ABC swaps" #808 - 3 party "ABC swaps" (conceptually related multi-party routing)
- "native" swap contracts #1287 - "Native" swap contracts (EVM-to-EVM efficiency) - Consider closing in favor of this issue
- ERC721/ERC1155 support adding for EVM protocols #900 - ERC721/ERC1155 support (NFT swaps could benefit from LR)
- Swaps with Polygon tokens may fail due to payment transaction stuck not mined #2336 - Polygon gas price issues (affects LR swaps on Polygon)
Implementation Status
✅ Implemented (in @dimxy's branch, to be merged via #2546)
-
find_best_quoteRPC with buy/sell actions and bid orders support -
execute_routed_tradeRPC with full state machine (lr_swap_state_machine.rs) - Slippage support (passed through properly in swap creation)
- API mock for CI tests (
api_mock.rs) - Dockerized LR swap tests (
lr_swap_tests.rs) -
cross_prices_closeprice calculation (using close price instead of average)
⏳ Outstanding TODO Items
High Priority - Core Functionality
1. find_best_quote RPC Enhancements
- Return total fees in response (
trade_feefield) - requires trade_preimage for TPU - Develop more convenient RPC to find ask/bid orders for LR (get most liquid whitelisted tokens from LR provider)
2. execute_routed_trade RPC
- Make LR provider type an enum to allow other providers beyond 1inch
3. Price Calculation & Estimation
- Factor gas costs into best price calculation (different swaps have different gas costs)
- Handle slippage properly in
find_best_quote- current estimation uses quotes without slippage applied - Reserve platform coin amount for fees on other swap steps when doing LR_0 for platform coin
4. Trade Preimage Support
- Implement
trade_preimagefor TPU to calculate total fees - Related: Implement proper trade preimage tx fee calculations for TPU swaps #2621 - Implement proper trade preimage tx fee calculations for TPU swaps
Medium Priority - Infrastructure
5. 1inch API Integration
- komodo-defi-proxy#28 - Add 1inch API to komodo proxy (required for production, removes need for
test-ext-apifeature) - Use 1inch API call for
eth_special_contractinstead of const (not valid on zk chains) - Handle rate limit text body errors
- Check cross_prices v2 API
6. Code Quality & Optimization
- Don't repeat 1inch calls for same pair
- Use hash map instead of vec for src_dst pairs
- Extract only message from
OneInchErrorinstead of whole error - 1inch recommendation: increase gas estimate by 25%
Lower Priority - Future Enhancements
7. Streaming & UX
- Stream best quote price to GUI so user can wait for better price or refuse if price becomes unsatisfying
8. Extended Provider Support
- Architecture to support multiple LR providers (1inch, Jupiter for Solana, Uniswap, etc.)
- Cross-chain bridging via stablecoin swaps (e.g., WETH→USDC(ERC20)→USDC(SPL)→SOL)
- Consider "native" EVM swap contracts for same-chain efficiency (related to "native" swap contracts #1287) - Both LR and native contracts aim to optimize same-chain trades; LR uses DEX aggregators for token conversion while "native" swap contracts #1287 proposes native atomic swap contracts
Merge Strategy
Per discussion with @dimxy:
- Complete review of feat(LR): add buy action, bid order and LR_1 support to find_best_quote RPC #2545 (mostly done)
- Merge feat(LR): add buy action, bid order and LR_1 support to find_best_quote RPC #2545 into
dev - Resolve conflicts in feat(LR): execute_routed_trade RPC implementation #2546 and add commits from
lr-swap-wip-currenton top - Complete and merge feat(LR): execute_routed_trade RPC implementation #2546
Future Considerations
As noted by @dimxy:
The LR feature could be of practical use when we add account abstraction, as currently user would need to pay too much platform fees for the routing.
Related: #2699 - Account Abstraction PR
Housekeeping
- Close "native" swap contracts #1287 in favor of this tracking issue (covers native swap contracts concept)
References
- PR #2545 Documentation Comment - Detailed
find_best_quoteAPI documentation - komodo-docs-mdx#566 - Documentation issue for
find_best_quote - Source code docs
Metadata
Metadata
Assignees
Labels
feature: APIfeature: swappriority: mediumModerately important tasks that should be completed but are not urgent.Moderately important tasks that should be completed but are not urgent.status: in progress