Inspiration
We were inspired by a simple but powerful idea:
What if decentralized financial markets could be modeled and optimized using classical graph algorithms?
The XRP Ledger (XRPL) includes built-in order books and liquidity routing. Underneath the financial surface, it is essentially a dynamic directed multi-graph:
• Nodes represent assets
• Edges represent exchange offers
• Edge weights represent exchange rates
• Edge capacities represent liquidity depth
This observation led us to explore whether routing, arbitrage detection, and strategy design could be framed as computational problems — and what would happen once real-world market frictions (fees, spreads, slippage) were introduced.
What it does
XRPL Liquidity Routing & Opportunity Engine is a Python-based simulation and analysis framework that:
• Connects to XRPL (Testnet or mock mode)
• Builds a liquidity graph from order books
• Finds optimal conversion routes using shortest-path algorithms
• Detects arbitrage via negative cycle detection
• Simulates realistic execution with slippage and fees
• Implements strategy engines (greedy and extended-greedy with lookahead)
• Evaluates trades using base-asset valuation and expected value scoring
The engine demonstrates how naive trading strategies can fail in realistic markets — and how improved decision logic can prevent capital erosion.
How we built it
We built the system in modular layers:
1. Data Layer
• Fetch order books from XRPL or use synthetic mock data
• Normalize assets and liquidity levels
2. Graph Construction
• Represent assets as nodes (issuer-aware)
• Represent order book levels as capacity-constrained edges
3. Algorithm Layer
• Dijkstra for optimal routing
• Bellman-Ford for arbitrage detection
• k-candidate path evaluation
4. Execution Simulation
• Level-by-level fill simulation
• Fee deduction
• Capacity exhaustion handling
5. Strategy Engine
• Base-asset scoring to prevent meaningless asset wandering
• Cooldown and reversal protection
• Two-step lookahead planning (extended-greedy)
Each layer builds on classical computer science principles applied to decentralized finance.
Challenges we ran into
• Greedy collapse problem
A naive greedy strategy repeatedly flipped between assets, slowly losing value due to bid-ask spreads and fees. Over many steps, the portfolio approached zero. This revealed how dangerous over-trading is in frictional markets.
• Modeling slippage realistically
Handling multi-level order books and partial fills required careful simulation logic.
• Issuer-aware assets
On XRPL, “USD” is not a single node — each issuer defines a distinct asset. Supporting this required redesigning the graph model.
• Balancing realism with performance
Adding lookahead and base valuation increased computational cost. We had to cap search depth and candidate counts to keep simulations efficient.
Accomplishments that we’re proud of
• Successfully modeling liquidity routing as a graph optimization problem
• Implementing realistic slippage and fee-aware simulation
• Demonstrating how arbitrage disappears when fees are introduced
• Preventing churn-loss through base-asset scoring and cooldown logic
• Building an extended-greedy two-step lookahead strategy that avoids naive round-trip traps
• Creating a modular, testable architecture that separates data, graph logic, and strategy
What we learned
• Markets with spreads punish over-trading — even if each step appears locally optimal.
• Local optimization (greedy) is not sufficient in dynamic systems.
• Adding realistic friction fundamentally changes algorithm performance.
• Arbitrage detection (negative cycles) is elegant in theory but fragile under fees.
• Financial systems can be studied using classical algorithms — but real-world constraints dominate outcomes.
What’s next for XRPL Liquidity Routing & Opportunity Engine
• Multi-path flow optimization (min-cost flow) for partial allocation
• Contextual bandit or reinforcement learning strategies
• Real-time streaming updates from XRPL
• Risk modeling with volatility-aware scoring
• Performance benchmarking on larger graphs
• Visualization tools for route graphs and arbitrage cycles
Ultimately, we want to explore how decentralized liquidity behaves under increasingly realistic constraints — and how algorithmic strategies must evolve to survive in efficient markets.
Log in or sign up for Devpost to join the conversation.