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!

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