# Role Act as an expert Quantitative DeFi Developer and Lead Blockchain Architect specializing in Mev/Arbitrage infrastructure. # Context & Objective I am upgrading a standard cross-DEX arbitrage bot to detect and execute Multi-Asset Triangular Arbitrage. The standard monitoring logic is too limited; I need a robust, production-grade TypeScript algorithm that builds a token/pool graph, detects profitable negative cycles, and calculates mathematically optimal input sizes to maximize arbitrage yield while accounting for slippage and price impact. # Scope & Technical Specifications ## 1. Graph Construction (Data Layer) - Write a modular TypeScript module that constructs a directed graph representing available liquidity pools. - **Filtering:** The graph must only include pools with a minimum liquidity threshold of $10,000 USD. - **Environment & Source:** Assume the target is the Polygon network, pulling from multiple DEXes (Uniswap v2 clones, e.g., SushiSwap, QuickSwap). - **Universe:** Scan *all* available pools/tokens meeting the $10k liquidity threshold (do not arbitrarily restrict to top-50 tokens). - **Data Structure:** Structure the graph nodes as tokens and directed edges as pools, where edge weights represent the effective exchange cost (logarithms of price ratios) to facilitate negative cycle detection. ## 2. Pathfinding Algorithms (Execution Layer) Implement both of the following graph-search algorithms within a clean, comparative interface: - **Bellman-Ford:** Optimized for sparse graphs, capable of early termination and explicitly returning the negative cycle path. - **Floyd-Warshall:** An all-pairs shortest path implementation ($O(V^3)$) to act as a benchmark comparison. - Ensure the algorithms account for DEX trading fees (e.g., 0.3% fee) directly within the edge weight calculation ($\text{weight} = -\ln(\text{price} \cdot (1 - \text{fee}))$). ## 3. Size Optimization (Quantitative Layer) - Do not use naive fixed-size trade inputs. - Implement an exact size optimization function using calculus. Use the first derivative of the Constant Product Formula ($x \cdot y = k$) compounded across a 3+ token path to solve for the exact maximum profit point ($d(\text{Profit})/d(\Delta x) = 0$). - This function must output the exact optimal input size in the origin token to maximize returns and prevent over-sizing a trade into price impact. # Deliverables Required 1. **TypeScript Codebase:** Modular, strongly-typed clean code (no `any`, no placeholders, no "implementation left as an exercise"). 2. **Mathematical Explanations:** A brief markdown section explaining the exact calculus derivatives used for the multi-pool composition optimization. 3. **UI/UX Mock Layout:** A conceptual architectural outline or schema for a full-stack dashboard (React UI + FastAPI/Node backend) that would visualize these detected triangular cycles and metrics (ROI, path, latency) in real-time.
Sign in to leave a comment

No comments yet. Be the first!