← Back to home

SafeStake.AI

AI-powered cross-chain staking platform enabling seamless multi-chain DeFi yield optimization.

Problem Statement

This project is a groundbreaking decentralized finance (DeFi) platform designed to empower users to stake their digital assets seamlessly across multiple Ethereum-compatible blockchains, including Ethereum, Polygon, Arbitrum, and Base. It uniquely combines advanced artificial intelligence, cross-chain infrastructure, real-time price oracles, and intuitive user interfaces to automate and optimize the staking experience. At its core, the platform employs AI agents that analyze a user's portfolio spread across different chains, assess risk tolerance, and dynamically compute optimized staking strategies that maximize yields while minimizing transaction costs and slippage. By integrating the Avail Nexus SDK, the platform enables atomic cross-chain bridging and staking operations—meaning a user can bridge assets and stake in a single transaction without worrying about manual token transfers or complex steps. Real-time price data is sourced through the Pyth Network, which provides highly reliable and timely on-chain oracle updates, ensuring accurate valuation of collateral and risk management. To enhance transparency and user engagement, the system incorporates the Blockscout SDK for seamless transaction notifications and in-application explorer functionalities, allowing users to monitor each step of their cross-chain operations live. The frontend is built on a robust Next.js application enhanced by modern React libraries that handle wallet connections, real-time data fetching, and state management, delivering a responsive and user-friendly interface. This project brings together multiple cutting-edge technologies—smart contracts optimized with Hardhat 3.0+, AI agents built with the uAgents framework, cross-chain bridging via Avail Nexus, decentralized oracle data from Pyth, and explorer integration through Blockscout—to create a fully automated, secure, and efficient cross-chain staking protocol. It represents a new paradigm in DeFi, where user intent is intelligently translated into complex blockchain interactions executed atomically, eliminating friction and expanding the possibilities of multi-chain asset management.

Solution

Tech Stack and Architecture: Smart Contracts (Solidity + Hardhat 3.0+) Solidity v0.8.x with viaIR optimizer enabled for gas efficiency. Hardhat 3.0.0+ as the development framework: TypeScript project configuration Plugins: @nomicfoundation/hardhat-toolbox (Ethers, Waffle, Chai) and hardhat-verify Gas reporting via hardhat-gas-reporter and coverage with solidity-coverageContracts:AIAgentController: Role-based agent authorization, request lifecycle, rate limiting, emergency pause CollateralManager: Multi-asset collateral, PYUSD support, Pyth pull-model oracle integration for on-chain USD valuation, dynamic risk parameters, fee handling StakingProxy: Cross-chain stake execution (post‐bridge), liquid token issuance, reward accounting, AI-adjustable reward rates, unstake workflow BridgeCoordinator: Cross-chain operation record‐keeping, Avail Nexus callback handler, multi-chain configuration, simulation endpointAI Agents (Python + uAgents Framework)uAgents v0.15.0 for decentralized agent-to-agent messaging (A2A standard)Agents run as standalone Python processes communicating over WebSockets: Master Coordinator: Orchestrates entire flow—receives optimization requests, delegates to specialist agents, aggregates responses, tracks progress Strategy Optimization Agent: Connects to Web3 nodes via web3.py to fetch balances, mocks additional data for yield estimation, applies risk/yield scoring, generates multi-step plan Bridge Agent: Evaluates bridge options (Avail Nexus, LayerZero, Wormhole), scores by cost/time/security, simulates Nexus SDK bridge and returns an operation ID Conversion Agent: Queries DEX quotes (Uniswap V3 quoter, 1inch API, Quickswap, Camelot), simulates slippage, selects optimal route, and prepares execution details Python libraries: aiohttp, asyncio for nonblocking I/O; pydantic for message schemas; dotenv for config; web3.py for blockchain accessCross-Chain Bridging (Avail Nexus SDK)avail-nexus-sdk@^1.2.0 for atomic bridgeAndExecute calls BridgeAndExecuteButton widget from @avail-project/nexus-widgets for one-click UI integrationBenefits: Atomicity: Single transaction bridges assets and executes staking, eliminating cross‐chain fragmentation Multi‐chain support: Ethereum, Polygon, Arbitrum, Base via unified SDK Simulation API: Pre‐execution cost/time estimates for UX feedbackPrice Oracles (Pyth Network): @pythnetwork/hermes-client for off‐chain pull model, fetching VAA messages from Hermes On‐chain integration via pyth-sdk-solidity’s updatePriceFeeds methodBenefits: High‐frequency, low‐latency feeds with confidence intervals On‐chain weight for collateral valuations and risk enforcementExplorer Integration (Blockscout SDK): @blockscout/app-sdk for in‐app transaction toasts and popups settlemint/sdk-blockscout under the hood for GraphQL queriesFeatures: Real‐time toast notifications on each transaction step In‐page “View in Explorer” popups for addresses and transactionsFrontend (Next.js 14 + React + Tailwind CSS) Next.js App Router for file‐based layouts and server components Wagmi + ConnectKit for wallet management (RainbowKit style) React Query for asynchronous data fetching and caching (Nexus, Pyth, Blockscout calls) Zustand for lightweight local state (agent status, execution flow) Tailwind CSS with custom theming for responsive UI and animationsIntegration WorkflowUser Connects Wallet Wagmi detects network, Chain ID, and signer Nexus SDK initialized with provider to fetch unified balancesPortfolio Display nexusClient.getUnifiedBalances(address) returns holdings across chains Pyth client fetches USD prices; UI shows balances and USD valueStrategy Configuration & Optimization User inputs stake parameters Frontend sends an OptimizationRequest via WebSocket to Master Coordinator Coordinator forwards to Strategy Agent; agent analyzes on‐chain data and portfolio, computes a plan, and repliesBridge & Convert (if needed) Coordinator sends BridgeRequest to Bridge Agent for cross‐chain steps Bridge Agent chooses Nexus SDK option, simulates, and returns BridgeResponse If intermediary token conversion is needed, Coordinator sends ConversionRequest to Conversion Agent Conversion Agent simulates DEX swap routes, returns ConversionResponseExecute Staking Coordinator or frontend invokes Nexus SDK’s bridgeAndExecute directly (via widget) with prepared calldata Nexus executes atomic bridge + staking call on StakingProxy.executeStakeAfterBridge Each transaction step triggers Blockscout toasts and logsMonitoring & Completion Blockscout SDK displays popups, in‐page logs, and explorer links Agent network sends an ExecutionResponse back to Coordinator, which updates UI statePartner Technologies & Benefits: Avail Nexus SDK: Simplified atomic cross‐chain flows, robust multi‐chain support Pyth Network: Enterprise‐grade oracles, protects against stale or manipulated prices uAgents Framework: Standardized agent communication, on‐chain governance compatibility Blockscout SDK: Seamless explorer integration, real‐time UX enhancementsNotable Workarounds Bytecode Cache Clearing: Automated removal of stalepycachewhen swapping uAgents API versions Dynamic ABI Generation: Used a small Python script to extract contract ABIs at build time for agent simulation Simulated Quotes: While waiting on full DEX SDK integration, we mock DEX quotes using on‐chain quoter contracts for speed Unified ENV Management: Centralized all SDK endpoint and contract addresses via a single .env and propagated into both Python and Next.js environmentsThis end-to-end integration leverages multiple cutting-edge DeFi and AI tools to deliver a painless, secure, and intelligent cross-chain staking experience.

Hackathon

ETHOnline 2025

2025

Contributors