GuardX

Stop crypto losses before they happen—automated price monitoring + emergency execution with GuardX

GuardX

Created At

ETHOnline 2025

Project Description

GuardX: Automated Cross-Chain DeFi Crash Protection

GuardX is an intelligent smart contract infrastructure that automatically safeguards cryptocurrency portfolios from market crashes by executing real-time emergency conversions to stablecoins across multiple blockchains. The platform combines high-frequency price monitoring, programmable security automation, and cross-chain coordination to protect user assets before catastrophic losses occur.

The Core Problem During market crashes, cryptocurrency investors face a critical challenge: by the time they realize their portfolio is crashing and attempt to sell, prices have already plummeted, liquidity has dried up, and gas fees have spiked. Manual intervention is too slow, panic selling leads to poor execution, and cross-chain assets compound the complexity. GuardX solves this with fully automated, pre-configured protection policies that execute instantly when crash conditions are detected.

How GuardX Works: The Complete Flow Phase 1: Setup & Configuration Users deposit their crypto assets (ETH, ERC-20 tokens) into the CrashGuardCore contract and configure their personalized protection policy:

Crash Threshold: Percentage drop that triggers protection (e.g., 20% decline) Max Slippage: Maximum acceptable price impact during emergency swaps (e.g., 10%) Preferred Stablecoin: Target safe-haven asset (USDC, USDT, DAI, etc.) Gas Limit: Maximum gas allocation for emergency transactions Time Window: Lookback period for price comparison (e.g., 1 hour, 24 hours)

For cross-chain protection, users authenticate with Lit Protocol's Programmable Key Pairs (PKPs), enabling the system to execute emergency actions across Ethereum, Polygon, Arbitrum, and Base simultaneously—all without requiring active user intervention.

Phase 2: Continuous Monitoring The PythPriceMonitor contract continuously tracks cryptocurrency prices using Pyth Network's high-frequency price feeds (updating every 400 milliseconds). The system:

Maintains a rolling history of the last 100 price points per asset Calculates percentage changes in real-time Compares current prices against user-defined thresholds Monitors both single-asset crashes and multi-asset correlation events Validates price feed freshness to prevent stale data exploitation All monitoring happens passively—users don't need to check prices, set alerts, or remain online. The system operates 24/7 autonomously.

Phase 3: Crash Detection When market conditions deteriorate, GuardX's detection algorithms identify crash scenarios:

Single-Asset Crash: One token drops below the user's threshold (e.g., ETH drops 25% when threshold is 20%) Multi-Asset Crash: Correlated declines across multiple portfolio holdings (e.g., ETH, LINK, and UNI all drop 20%+ simultaneously) Cross-Chain Crash: Same asset declining across multiple blockchains (e.g., WETH crashing on Ethereum, Polygon, and Arbitrum) The system uses volatility-adjusted thresholds to distinguish between normal market fluctuations and genuine crash events, reducing false positives.

Phase 4: Emergency Execution Once crash conditions are confirmed, the EmergencyExecutor contract orchestrates the protection sequence:

Authorization Check: Verifies the user's protection policy permits execution Asset Withdrawal: Retrieves risky assets from CrashGuardCore custody DEX Routing: Routes assets through the DEXAggregator for optimal swap execution Slippage Protection: Enforces max slippage limits, reverting if exceeded Stablecoin Conversion: Swaps volatile assets to user's preferred stablecoin Fund Return: Deposits stablecoins back to user's portfolio in CrashGuardCore Event Emission: Logs complete execution trail on-chain for transparency All steps execute atomically—either the entire protection succeeds or nothing happens, preventing partial failures. For batch operations, the system can protect multiple users simultaneously, dramatically reducing per-user gas costs during high-volatility periods when many portfolios trigger simultaneously.

Phase 5: Cross-Chain Coordination For users with assets across multiple blockchains, the CrossChainEmergencyCoordinator manages synchronized protection:

Global Crash Detection: CrossChainEmergencyCoordinator monitors prices across all supported chains PKP Authentication: Verifies Lit Protocol PKP signatures authorizing multi-chain actions Message Broadcasting: LitRelayContract sends signed emergency messages to all chains Parallel Execution: EmergencyExecutor on each chain processes protection simultaneously Confirmation Aggregation: Coordinator collects execution confirmations from all chains Portfolio Reconciliation: Updates user's global portfolio state across chains The cross-chain flow includes a 30-minute timeout mechanism—if any chain fails to respond, the system isolates that chain while completing protection on others, ensuring partial protection is better than none.

Technical Architecture: Eight Interconnected Smart Contracts

  1. CrashGuardCore (Asset Custody & Portfolio Management) The central vault managing user deposits, withdrawals, and protection policies. Functions include:

depositAsset(): Accept user deposits of ETH or ERC-20 tokens withdrawAsset(): Enable user withdrawals anytime setProtectionPolicy(): Configure individual crash protection parameters getUserPortfolio(): Query real-time portfolio composition getUserBalance(): Check per-token balances

Key Feature: Maintains separate accounting per user while pooling assets efficiently for gas optimization.

  1. EmergencyExecutor (Protection Orchestration) Executes the actual emergency conversions when crashes are detected:

executeEmergencyProtection(): Trigger full portfolio protection for a user emergencyConvertToStable(): Convert specific assets to stablecoins batchEmergencyActions(): Protect multiple users in one transaction canExecuteEmergency(): Pre-flight check for execution eligibility Key Feature: Includes reentrancy guards, slippage enforcement, and MEV protection to prevent exploitation during execution.

  1. PythPriceMonitor (Real-Time Price Intelligence) Interfaces with Pyth Network's oracle infrastructure for millisecond-precision pricing:

updatePrices(): Fetch latest prices from Pyth Network getLatestPrice(): Retrieve current price for any supported asset detectMultiAssetCrash(): Identify correlated market declines checkAssetsCrash(): Validate crash conditions for specific tokens getPriceHistory(): Access historical price data for analysis Key Feature: Stores price history in efficient circular buffers, preventing unbounded storage growth while maintaining adequate lookback data.

  1. DEXAggregator (Swap Execution Engine) Handles token swaps through decentralized exchange protocols (currently mock, production will integrate 1inch/uniswap):

swapTokens(): Execute token-to-token swaps getQuote(): Obtain expected swap outputs before execution executeSwap(): Perform individual swaps with slippage protection batchSwaps(): Execute multiple swaps atomically Production Integration Plan: Will connect to battle-tested DEX aggregators like 1inch Router V5, 0x Exchange Proxy, and ParaSwap Augustus Swapper for optimal routing and pricing.

  1. LitProtocolIntegration (Automation Security Layer) Enables programmable, conditional asset access through Lit Protocol:

authenticateWithPKP(): Initialize PKP authentication for a user createConditionalAccess(): Define conditions under which automated actions are permitted storeEncryptedData(): Encrypt and store sensitive portfolio configuration isAuthorizedByLitAction(): Verify whether a proposed action meets authorization criteria Key Feature: PKPs allow the system to execute emergency actions on behalf of users without ever having direct control of user private keys—automation without custody.

  1. LitRelayContract (Cross-Chain Messaging Hub) Facilitates secure communication between blockchains using Lit Protocol's relay network:

verifyPKPSignature(): Cryptographically verify PKP-signed messages executeLitAction(): Execute pre-approved automated actions sendCrossChainMessage(): Transmit signed messages to other chains processCrossChainMessage(): Receive and validate incoming cross-chain messages registerPKP(): Register new PKPs for cross-chain operations Key Feature: Uses ECDSA signature recovery and timestamp validation to prevent replay attacks and unauthorized cross-chain operations.

  1. CrossChainManager (Multi-Chain Asset Coordination) Manages asset movements and portfolio state across supported blockchains:

lockAsset(): Lock assets on source chain for cross-chain migration unlockAsset(): Release assets with PKP signature verification initiateCrossChainMigration(): Begin asset transfer to another blockchain completeCrossChainMigration(): Finalize cross-chain asset receipt getCrossChainPortfolio(): View aggregated portfolio across all chains Key Feature: Implements atomic lock-and-mint mechanics, ensuring assets can never exist on two chains simultaneously.

  1. CrossChainEmergencyCoordinator (Global Protection Orchestrator) Coordinates emergency protection across multiple blockchains simultaneously:

initiateMultiChainEmergency(): Trigger protection across all chains for a user executeChainEmergency(): Execute protection on a specific chain getEmergencyCoordination(): Query status of ongoing multi-chain emergency emergencyPauseChain(): Disable operations on a compromised chain proposeGovernanceAction(): Submit governance proposals for system upgrades Key Feature: Maintains a unified view of crash conditions across chains, preventing desynchronization and ensuring consistent protection execution.

How it's Made

How GuardX Was Built: Technical Deep Dive Core Technology Stack Smart Contract Development

Solidity 0.8.20: Latest stable version with built-in overflow protection and gas optimizations

Hardhat 3: Development environment upgrade from v2.19.0, leveraging new Ignition deployment system via @nomicfoundation/hardhat-ignition-ethers

OpenZeppelin Contracts 5.0: Battle-tested security primitives (ReentrancyGuard, Ownable, Pausable, ERC20)

TypeScript: Strongly-typed deployment scripts, tests, and integration code

Oracle & Price Feed Infrastructure

Pyth Network SDK: Real-time price feeds updating every 400ms across 300+ crypto assets

@pythnetwork/pyth-evm-js: EVM-compatible Pyth integration for on-chain price verification

Custom Price History Storage: Circular buffer implementation storing last 100 price points per asset for crash detection

Cross-Chain & Automation

Lit Protocol: PKP (Programmable Key Pairs) for automated, non-custodial cross-chain execution

Lit Actions: Conditional logic execution triggered by market conditions

Lit Relay Network: Cross-chain messaging infrastructure for coordinated emergency execution

Development Workflow

Git/GitHub: Version control and collaboration

Vercel: Planned frontend deployment (based on your previous projects)

MongoDB + Express.js: Backend API for aggregating cross-chain portfolio data and historical analytics

Architecture & Contract Interactions The system consists of 8 interconnected smart contracts deployed across multiple EVM chains. Here's how they piece together:

┌─────────────────────────────────────────────────────────────┐ │ USER INTERACTION LAYER │ │ (Web3 Wallet + Frontend Interface) │ └────────────────────────┬────────────────────────────────────┘ │ ┌───────────────┴───────────────┐ ▼ ▼ ┌─────────────────┐ ┌─────────────────────┐ │ CrashGuardCore │◄──────────►│ PythPriceMonitor │ │ (Asset Custody) │ │ (Price Oracle) │ └────────┬────────┘ └──────────┬──────────┘ │ │ │ │ Price Check │ ▼ │ ┌─────────────────────────┐ │ │ EmergencyExecutor │ └───────────────────►│ (Protection Logic) │ └──────────┬──────────────┘ │ ┌──────────┴──────────┐ ▼ ▼ ┌──────────────────┐ ┌──────────────────────┐ │ DEXAggregator │ │ LitProtocolIntegration│ │ (Token Swaps) │ │ (PKP Authentication) │ └──────────────────┘ └──────────┬────────────┘ │ ┌──────────────────────┴──────────┐ ▼ ▼ ┌────────────────────┐ ┌──────────────────────┐ │ LitRelayContract │◄───────►│ CrossChainManager │ │ (Cross-Chain Msgs) │ │ (Multi-Chain Assets) │ └────────────────────┘ └───────────────────────┘ │ ▼ ┌───────────────────────────────┐ │ CrossChainEmergencyCoordinator │ │ (Global Protection Orchestrator│ └───────────────────────────────┘

background image mobile

Join the mailing list

Get the latest news and updates