project-c6839733

byChris Arxate

Act as an elite Blockchain Engineer, Principal MEV Quantitative Developer, and Smart Contract Security Expert specializing in EVM networks. I am building an enterprise-grade trading, arbitrage, and liquidation bot suite on the Polygon PoS network, utilizing the split-architecture model inspired by the `pmuens/midas` repository. Please provide the complete repository structure and production-hardened, fully fleshed-out code for the core implementation files in TypeScript and Solidity. The codebase must be highly optimized for the brutal, fast-changing environment of Polygon. Do not use placeholders like '// implement logic here' for critical logic paths; all mathematical routing, gas strategies, and decoding loops must be fully written. ### I. System Architecture & Component Specifications #### 1. Hardened Execution Layer (`InstitutionalExecutor.sol`) - **Multi-DEX Multi-Hop Interface:** Build an execution entry point that accepts an array of token addresses (the swap path) and an array of custom market/DEX identifiers (e.g., Uniswap V3, Quickswap V3, Balancer, or V2 forks). - **Atomic Profit Guardrail & Minimum Output Check:** The function must accept a `minProfit` parameter. It must track the contract's starting balance of the base asset, execute the multi-hop route, and perform an atomic check: `require(finalBalance - startingBalance >= minProfit, "Slippage/Negative Profit")`. If this condition is not met, the entire transaction must revert to eliminate losing trades and prevent wasting gas on failed outcomes. - **Actinide-Grade Access Controls:** Implement a dual-layer defense system. Use standard administrative controls (`Ownable`) for parameter adjustments, but restrict the core execution function via a strict custom modifier that permits calls *only* from the explicit hot-wallet address of your off-chain TypeScript engine. - **Asset Resiliency & Circuit Breaker:** Include an `emergencyDrain(address token)` function allowing immediate sweeping of 100% of the contract's inventory to a hardware-secured cold wallet if an anomaly is flagged. Integrate flash loan callbacks (e.g., Balancer or Aave V3) ensuring zero-capital high-leverage execution. #### 2. Sub-Millisecond, Low-Latency Strategy Layer (`low-latency-engine.ts`) - **Raw Log Decoding Over Library Abstractions:** Standard provider abstractions introduce up to 50ms of overhead. Implement a performance-critical WebSocket listener using the raw `ws` library. Parse raw incoming JSON-RPC hex strings directly to instantly flag target `Swap` topics (`0xc4202...`) from targeted liquidity pools. - **Pre-Flight On-Chain Simulation:** Build an internal simulation step using `eth_call` or `multicall` to dry-run the generated execution calldata against the absolute latest block state *before* broadcasting a live transaction. - **Deep Reorg Protection & Caching:** Polygon suffers from micro-forks and deep block reorgs. Build a block listener that tracks state and cache-hashes previously sent transactions to prevent sending duplicate payloads if a block is temporarily dropped or rewritten. - **Fail-Closed State Machine:** If connection to your RPC network drops for more than 500 milliseconds, transition the engine into a global `PAUSED` state, freezing all pending executions and wiping the transaction pool cache. #### 3. Polygon Overdrive Gas & Routing Strategy - **EIP-1559 Dynamic Base-Fee Scaling:** Implement logic that directly polls the network's fee data. To secure top-of-block positioning during high-congestion events, automatically scale `maxPriorityFeePerGas` up to 30% higher than the network median, applying a protective max cap to prevent toxic gas burn. - **Private MEV Routing (FastLane/Flashbots):** Completely bypass public mempools to eliminate sandwich or front-running vulnerabilities. Structure the transaction broadcasting module to send transactions as private bundles directly to Polygon FastLane or equivalent private builder endpoints. - **Dynamic Flash-Slippage Optimization:** Before generating a payload, the off-chain engine must read depth across pools (e.g., Quickswap and Uniswap V3). If target paths exhibit high price-impact, dynamically adjust the size of the principal to minimize self-induced slippage. ### II. Code Deliverables Required Please output the exact, complete code for these four files, fully fleshed out with clean documentation: 1. `InstitutionalExecutor.sol` (The complete Solidity smart contract matching all specs above). 2. `low-latency-engine.ts` (The master TypeScript execution and ingestion engine using Ethers.js v6 or Viem where appropriate, and the raw `ws` library for the intake loop). 3. `package.json` (The exact production dependencies required, including TypeScript, Ethers, and Hardhat tool suites). 4. `hardhat.config.ts` (The complete configuration file configured for deployment and testing on Polygon Mainnet).

LandingDashboardExecutor
Landing

Comments (0)

No comments yet. Be the first!

System Requirements

System Requirement Document
Page 1 of 6

Project-c6839733 System Requirements Document

Introduction

This document outlines the system requirements for Project-c6839733, an enterprise-grade trading, arbitrage, and liquidation bot suite on the Polygon PoS network. The project utilizes a split-architecture model inspired by the pmuens/midas repository, focusing on high optimization for the fast-changing environment of Polygon.

System Overview

Project-c6839733 is designed to operate as a sophisticated trading bot suite, leveraging blockchain technology on the Polygon network. The system architecture is divided into several key components, each with specific functionalities to ensure efficient and secure trading operations.

Page 2 of 6

System Architecture & Component Specifications

  1. Hardened Execution Layer (InstitutionalExecutor.sol)

    • Multi-DEX Multi-Hop Interface
    • Atomic Profit Guardrail & Minimum Output Check
    • Actinide-Grade Access Controls
    • Asset Resiliency & Circuit Breaker
  2. Sub-Millisecond, Low-Latency Strategy Layer (low-latency-engine.ts)

    • Raw Log Decoding Over Library Abstractions
    • Pre-Flight On-Chain Simulation
    • Deep Reorg Protection & Caching
    • Fail-Closed State Machine
  3. Polygon Overdrive Gas & Routing Strategy

    • EIP-1559 Dynamic Base-Fee Scaling
    • Private MEV Routing (FastLane/Flashbots)
    • Dynamic Flash-Slippage Optimization
Page 3 of 6

Functional Requirements as Story Points

  • As a Developer, I should be able to execute multi-hop trades across multiple DEXs using the InstitutionalExecutor.sol.
  • As a Developer, I should be able to ensure trades meet a minimum profit threshold to prevent losses.
  • As a Developer, I should be able to restrict execution access to a specific hot-wallet address.
  • As a Developer, I should be able to drain contract assets to a secure wallet in case of an emergency.
  • As a Developer, I should be able to decode raw logs for low-latency strategy execution.
  • As a Developer, I should be able to simulate trades on-chain before execution to ensure accuracy.
  • As a Developer, I should be able to protect against deep block reorgs and cache transaction hashes.
  • As a Developer, I should be able to pause operations if the network connection drops.
  • As a Developer, I should be able to dynamically adjust gas fees based on network conditions.
  • As a Developer, I should be able to route transactions privately to avoid MEV attacks.
  • As a Developer, I should be able to optimize trade sizes to minimize slippage.

User Personas

  • Developer: Responsible for implementing and maintaining the trading bot suite, ensuring all components function correctly and securely.

Core User Flows

  • Developer deploys InstitutionalExecutor.sol -> Configures access controls -> Executes trades -> Monitors profit thresholds
  • Developer sets up low-latency-engine.ts -> Decodes logs -> Simulates trades -> Executes transactions
  • Developer configures gas and routing strategies -> Monitors network conditions -> Adjusts fees and routes transactions
Page 4 of 6

Visuals Colors and Theme

  • primary: #1E3A8A (Deep Blue)
  • primary_light: #3B82F6 (Light Blue)
  • secondary: #F97316 (Orange)
  • accent: #10B981 (Green)
  • highlight: #F59E0B (Amber)
  • bg: #F3F4F6 (Light Gray)
  • surface: rgba(255, 255, 255, 0.8)
  • text: #111827 (Dark Gray)
  • text_muted: #6B7280 (Muted Gray)
  • border: rgba(209, 213, 219, 0.2)

Signature Design Concept

The homepage will feature an interactive blockchain network visualization. Users can click on nodes representing different DEXs and trading paths, which will expand to show real-time data and trading opportunities. This 3D visualization will be powered by @react-three/fiber and @react-three/drei, allowing users to rotate and zoom into the network, providing an engaging and informative experience.

Interaction Model & Motion Direction

  • Interaction Model: Parallax
  • Motion Direction: The landing page will feature layered depth via scroll, with interactive elements such as the blockchain network visualization providing a dynamic and engaging user experience.
Page 5 of 6

Non-Functional Requirements

  • The system must handle high-frequency trading operations with minimal latency.
  • Security measures must be in place to protect against unauthorized access and MEV attacks.
  • The system should be scalable to accommodate increasing trading volumes.

Tech Stack

  • Frontend: React
  • Backend: Node.js, TypeScript
  • Blockchain: Solidity for smart contracts
  • Database: Not specified
  • AI Models: Not applicable
  • Local Orchestration: Docker, docker-compose
  • Server-Side Orchestration: Kubernetes

Assumptions and Constraints

  • The system will operate exclusively on the Polygon PoS network.
  • All trading operations must comply with relevant financial regulations.
  • The system must be optimized for low-latency execution.
Page 6 of 6

Glossary

  • DEX: Decentralized Exchange
  • MEV: Miner Extractable Value
  • PoS: Proof of Stake
  • RPC: Remote Procedure Call
  • EIP-1559: Ethereum Improvement Proposal 1559

This document provides a comprehensive overview of the requirements and specifications for Project-c6839733, ensuring all components are designed and implemented to meet the project's objectives.

Landing design preview
Landing: View Network
Landing: Connect Wallet
Dashboard: View Overview
Executor: Deploy Contract
Executor: Configure Access
Executor: Execute Trades
Executor: Monitor Profit
Executor: Emergency Drain
Engine: Configure Engine
Engine: Decode Logs
Engine: Simulate Trades
Engine: Execute Transactions
GasRouting: Configure Strategy
Network: Monitor Conditions
GasRouting: Adjust Fees