Skip to content

Liquidity Routing (LR) Feature Tracking Issue #2703

@shamardy

Description

@shamardy

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

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


Implementation Status

✅ Implemented (in @dimxy's branch, to be merged via #2546)

  • find_best_quote RPC with buy/sell actions and bid orders support
  • execute_routed_trade RPC 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_close price 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_fee field) - 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

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-api feature)
  • Use 1inch API call for eth_special_contract instead 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 OneInchError instead 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:

  1. Complete review of feat(LR): add buy action, bid order and LR_1 support to find_best_quote RPC #2545 (mostly done)
  2. Merge feat(LR): add buy action, bid order and LR_1 support to find_best_quote RPC #2545 into dev
  3. Resolve conflicts in feat(LR): execute_routed_trade RPC implementation #2546 and add commits from lr-swap-wip-current on top
  4. 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


References

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions