Functioning XCM-Swapping between Ethereum - Polkadot verifiable on-chain
đ Project: PolkadotSwap â Cross-Chain Swaps Between Ethereum and Polkadot via 1inch Fusion+
Overview PolkadotSwap is a fully functional MVP that extends the 1inch Fusion+ cross-chain swap protocol to support bidirectional swaps between Ethereum and Polkadot. Designed for seamless interoperability, it preserves Fusionâs core cryptographic guaranteesâhashlocks and timelocksâacross EVM and Substrate environments. The project was developed and demonstrated live with full on-chain execution on both sides.
Core Features ⢠đ Bidirectional Cross-Chain Swaps Swaps can be initiated from either Ethereum or Polkadot and settled atomically across both chains. ⢠đ Hashlock & Timelock Compatibility Achieves secure, trustless execution using cryptographic locks across heterogeneous chains. ⢠đ On-Chain Execution Live demo showcased real token transfers across Ethereum testnet and Polkadot parachains. ⢠đď¸ Fusion+ Integrated Ties directly into 1inch Fusion+ infrastructure, enabling Polkadot tokens to participate in Fusionâs auction-based swap mechanism.
User Interface ⢠đĽď¸ Beautiful, Intuitive UI A polished front end provides users with a seamless cross-chain swapping experience, complete with real-time status updates, swap history, and confirmation flows. ⢠đŚ Developer-Friendly Architecture Built with modularity and extensibility in mind, enabling future support for new chains, features, or integrations.
Stretch Goal Progress ⢠â UI: Fully delivered with production-grade interface ⢠đŤ Partial Fills: Not implemented in MVP
Technical Highlights ⢠Implemented non-EVM hashlock logic using Substrate smart contracts. ⢠Custom relayers used to propagate swap commitments and claims between chains. ⢠Limit Order Protocol deployed on Ethereum testnet to coordinate with Fusion+ bidding and execution model.
Impact PolkadotSwap is the first working integration of Polkadot into 1inch Fusion+. It unlocks access to Fusionâs liquidity and efficient pricing for Polkadot-native assets and demonstrates how permissionless, secure, cross-chain trading can be achieved across vastly different chain architectures.
FlipPay is a cutting-edge decentralized finance platform that enables secure, trustless atomic swaps between Ethereum and Polkadot ecosystems. Our solution addresses one of the most critical challenges in the multi-chain landscape: safely transferring assets across different blockchain networks without relying on centralized intermediaries or custodial bridges. Hash Time-Locked Contracts (HTLC) Architecture
At the core of FlipPay lies our sophisticated Hash Time-Locked Contract implementation, which ensures atomic swaps maintain their fundamental security guarantees across heterogeneous blockchain environments. Our HTLC system operates on a dual-constraint mechanism that provides both cryptographic security and temporal safety nets.
The cryptographic component utilizes hash locks, where funds are secured by a cryptographic hash that can only be unlocked with the corresponding preimage. This ensures that both parties in a cross-chain swap must reveal the same secret to claim their respective assets, creating an atomic execution guarantee. If one party claims their funds by revealing the secret, the other party automatically gains access to complete the swap.
The temporal component implements time locks that provide escape mechanisms for incomplete transactions. Each HTLC contract includes carefully calibrated timeouts that allow participants to reclaim their funds if the counterparty fails to complete the swap within the specified timeframe. This prevents funds from being permanently locked in failed transactions while maintaining sufficient time for normal swap completion.
Substrate Integration and Custom Pallet Development
Our Polkadot integration leverages a custom Substrate runtime with specialized HTLC pallets designed specifically for cross-chain interoperability. The Substrate implementation runs on a local solochain development environment, providing a controlled testing ground for atomic swap functionality while maintaining compatibility with the broader Polkadot ecosystem.
The custom HTLC pallet implements native support for hash time-locked contracts directly in the Substrate runtime, enabling efficient and gas-optimized cross-chain operations. This approach provides significant advantages over smart contract implementations, as runtime-level execution offers better performance, lower costs, and tighter integration with Substrate's inherent cross-chain messaging capabilities.
Our Substrate node operates with unsafe RPC methods enabled for development purposes, allowing comprehensive testing and debugging of the HTLC mechanisms. The runtime includes specialized extrinsics for creating, funding, and resolving HTLC contracts, with built-in validation logic that ensures all temporal and cryptographic constraints are properly enforced. EVM Smart Contract Infrastructure
On the Ethereum side, FlipPay deploys a comprehensive suite of smart contracts on Sepolia testnet that handle various aspects of the cross-chain swap process. The contract architecture includes specialized escrow contracts, resolver mechanisms, and limit order protocols that work in concert to facilitate seamless atomic swaps.
The EscrowSrc and EscrowDst contracts manage the source and destination sides of cross-chain transfers, ensuring proper fund locking and release mechanisms. The Resolver contract provides dispute resolution and timeout handling, while the limit order protocol enables users to create standing orders for automatic swap execution when favorable conditions are met. Atomic Swap Execution Flow
The atomic swap process begins with order creation, where users specify the desired exchange parameters including asset types, amounts, and acceptable exchange rates. The system automatically generates unique order identifiers that track each swap throughout its lifecycle. Once an order is matched, the platform creates corresponding HTLC contracts on both the Ethereum and Substrate sides. These contracts are cryptographically linked through shared hash locks while maintaining independent time lock mechanisms adjusted for the different block confirmation speeds of each network.
The swap execution involves a carefully orchestrated reveal process where the initiating party claims their funds by providing the secret preimage, which then enables the counterparty to complete the swap on their respective blockchain. This atomic execution ensures that either both parties receive their desired assets or both parties can safely reclaim their original funds.
Security and Trust Minimization
FlipPay's architecture eliminates the need for trusted intermediaries or bridge operators, instead relying on cryptographic proofs and deterministic smart contract execution. The HTLC implementation provides mathematical guarantees that funds cannot be lost or stolen during the swap process, even in the presence of malicious actors or network failures.
The dual-blockchain approach ensures that no single point of failure can compromise the entire system. Even if one blockchain experiences temporary issues, the time lock mechanisms provide sufficient flexibility for users to either complete their swaps when connectivity is restored or safely exit their positions.
Integration with Existing DeFi Infrastructure
Beyond the core HTLC functionality, FlipPay integrates with established DeFi protocols to provide enhanced user experiences. The platform includes comprehensive 1inch API integration for optimal swap routing and pricing, and native Polkadot ecosystem token support with real-time pricing data from CoinGecko.
This integration approach ensures that users can access the benefits of cross-chain atomic swaps without sacrificing the convenience and efficiency they expect from modern DeFi platforms. The system automatically handles complex routing decisions and optimizes for both cost and execution speed while maintaining the security guarantees of the underlying HTLC protocols.
Technologies Used Frontend Stack React with modern hooks and functional components for the user interface npm for package management and dependency resolution Cloudflare for deployment and global CDN distribution Web3 libraries for blockchain wallet integration and transaction signing Backend Infrastructure FastAPI (Python) for the main API server with async/await support Docker for containerization and consistent deployment environments Swagger/OpenAPI for automatic API documentation generation SQLite/PostgreSQL for user data and transaction state management Blockchain Technologies Substrate framework for custom Polkadot runtime development Rust for writing custom pallets and runtime logic Solidity for Ethereum smart contract development Web3.py/ethers.js for blockchain interactions Polkadot.js API for Substrate chain communication External API Integrations 1inch API for decentralized exchange aggregation and optimal routing CoinGecko API for real-time token pricing data Infura for reliable Ethereum RPC endpoints Polkadot RPC for direct chain state queries How Technologies Are Pieced Together Cross-Chain Communication Architecture The core innovation lies in our dual-blockchain HTLC implementation. On the Ethereum side, we deployed a comprehensive smart contract suite on Sepolia testnet, including specialized escrow contracts (EscrowSrc at 0x7D9bE409CAff73C6aa0E3eBe7e02393d678ecc46 and EscrowDst), a resolver contract, and a limit order protocol contracts. On the Polkadot side, we built a custom Substrate runtime with native HTLC pallets. The Substrate node runs locally with --dev --rpc-methods=Unsafe --rpc-port 9933, enabling full development capabilities and unrestricted RPC access for testing complex cross-chain scenarios. API Gateway Pattern Our FastAPI backend serves as a unified gateway that abstracts the complexity of multiple blockchain interactions. The /oneinch/ proxy endpoint forwards any 1inch API call by appending paths to their base URL (https://api.1inch.dev), automatically handling Bearer token authentication with our ONEINCH_KEY environment variable. This design allows the frontend to access the entire 1inch ecosystem (Swap API, Token API, Balance API, Spot Price API, Portfolio API, NFT API, Fusion API) through a single, consistent interface. Similarly, the /polkadot/ endpoints provide a unified interface for Polkadot ecosystem tokens, combining on-chain token registry data with CoinGecko pricing. The service supports 15+ major tokens (DOT, KSM, ACA, ASTR, GLMR, HDX, MOVR) and includes intelligent fallback mechanisms when direct RPC calls fail. HTLC State Synchronization The most complex aspect involves synchronizing HTLC states across both chains. We implemented a sophisticated state machine that tracks order creation, escrow contract deployment, and atomic swap execution phases. The system uses unique order IDs (like eth_dot_order_1754215281942) to maintain consistency across both blockchain environments. Partner Technology Benefits 1inch Integration The 1inch partnership provides massive value by giving us access to the entire DEX aggregation ecosystem without building our own routing algorithms. Their API handles complex pathfinding across dozens of DEXes, ensuring users get optimal prices for their swaps. The automatic slippage management and gas optimization features significantly improve user experience. CoinGecko Partnership CoinGecko's pricing API provides reliable, real-time market data for both Ethereum and Polkadot ecosystem tokens. This partnership was crucial because Polkadot's ecosystem lacks a unified price oracle, and CoinGecko's comprehensive coverage (with fallback modes) ensures our pricing remains accurate even when individual chains experience issues. Infura Infrastructure Infura provides enterprise-grade Ethereum RPC access, eliminating the need for us to run our own Ethereum nodes. This partnership ensures 99.9% uptime and handles the complex infrastructure challenges of maintaining reliable blockchain connectivity. Notable Hacks and Creative Solutions The "Universal Proxy" Pattern One of our cleverest implementations is the universal 1inch proxy. Instead of implementing individual endpoints for each 1inch service, we created a catch-all proxy that forwards any path after /oneinch/ directly to 1inch's API. This means we automatically support new 1inch features without code changes - when they launch new APIs, our users can access them immediately.
@app.api_route("/oneinch/{path:path}", methods=["GET", "POST"]) async def proxy_oneinch(path: str, request: Request): # Forward to https://api.1inch.dev/{path} Substrate Runtime Hot-Swapping We implemented a development pattern where the Substrate runtime can be rebuilt and restarted without losing HTLC state. This required careful design of the pallet storage structures and migration logic, allowing us to iterate rapidly on HTLC logic while maintaining active test swaps. Environment Variable Chain Configuration Rather than hardcoding contract addresses, we made the entire system configurable through environment variables. This allows the same codebase to work across testnets and mainnets simply by changing configuration, significantly simplifying deployment and testing workflows. Docker-First Development The entire backend runs in Docker from day one, not as an afterthought. This eliminated "works on my machine" issues and allowed team members to spin up the complete environment with a single docker run command. The Dockerfile includes all necessary dependencies for both Ethereum and Polkadot interactions. Automatic Database Reset for Demos We implemented an /admin/reset-db endpoint that completely resets the demo database state. This seemingly simple feature was crucial for hackathon demos and testing, allowing us to showcase clean user journeys repeatedly without manual database management. Hybrid On-Chain/Off-Chain State Management The most sophisticated hack involves our hybrid state management. While the actual HTLC contracts live on-chain, we maintain off-chain metadata about swap progress, user preferences, and transaction histories. This provides a responsive UI experience while maintaining the security guarantees of on-chain settlement. The state synchronization between our FastAPI backend and both blockchain networks required implementing custom event listeners and retry logic to handle network partitions and temporary node unavailability gracefully. Graceful Degradation Architecture We designed every external dependency to have fallback modes. If the Polkadot RPC is unavailable, we fall back to CoinGecko-only mode. If 1inch is down, we provide basic swap functionality through direct contract interactions. This resilience was crucial for demo reliability during the hackathon.
FlipPay: Technical Implementation Deep Dive Technologies Used Frontend Stack React with modern hooks and functional components for the user interface npm for package management and dependency resolution Cloudflare for deployment and global CDN distribution Web3 libraries for blockchain wallet integration and transaction signing Backend Infrastructure FastAPI (Python) for the main API server with async/await support Docker for containerization and consistent deployment environments Swagger/OpenAPI for automatic API documentation generation SQLite/PostgreSQL for user data and transaction state management Blockchain Technologies Substrate framework for custom Polkadot runtime development Rust for writing custom pallets and runtime logic Solidity for Ethereum smart contract development Web3.py/ethers.js for blockchain interactions Polkadot.js API for Substrate chain communication External API Integrations 1inch API for decentralized exchange aggregation and optimal routing CoinGecko API for real-time token pricing data Infura for reliable Ethereum RPC endpoints Polkadot RPC for direct chain state queries How Technologies Are Pieced Together Cross-Chain Communication Architecture The core innovation lies in our dual-blockchain HTLC implementation. On the Ethereum side, we deployed a comprehensive smart contract suite on Sepolia testnet, including specialized escrow contracts (EscrowSrc at 0x7D9bE409CAff73C6aa0E3eBe7e02393d678ecc46 and EscrowDst at 0xEc714A9f9e094B881e6B8087F51C6e03Dc6A500b), a resolver contract at 0xF6b928896E57955727C29d33a3B716C25E10A4e4, and a limit order protocol at 0x6af572bE6497d4Da120e51f310c6839E211E97AA. On the Polkadot side, we built a custom Substrate runtime with native HTLC pallets. The Substrate node runs locally with --dev --rpc-methods=Unsafe --rpc-port 9933, enabling full development capabilities and unrestricted RPC access for testing complex cross-chain scenarios. API Gateway Pattern Our FastAPI backend serves as a unified gateway that abstracts the complexity of multiple blockchain interactions. The /oneinch/ proxy endpoint forwards any 1inch API call by appending paths to their base URL (https://api.1inch.dev), automatically handling Bearer token authentication with our ONEINCH_KEY environment variable. This design allows the frontend to access the entire 1inch ecosystem (Swap API, Token API, Balance API, Spot Price API, Portfolio API, NFT API, Fusion API) through a single, consistent interface. Similarly, the /polkadot/ endpoints provide a unified interface for Polkadot ecosystem tokens, combining on-chain token registry data with CoinGecko pricing. The service supports 15+ major tokens (DOT, KSM, ACA, ASTR, GLMR, HDX, MOVR) and includes intelligent fallback mechanisms when direct RPC calls fail. HTLC State Synchronization The most complex aspect involves synchronizing HTLC states across both chains. We implemented a sophisticated state machine that tracks order creation, escrow contract deployment, and atomic swap execution phases. The system uses unique order IDs (like eth_dot_order_1754215281942) to maintain consistency across both blockchain environments. Partner Technology Benefits 1inch Integration The 1inch partnership provides massive value by giving us access to the entire DEX aggregation ecosystem without building our own routing algorithms. Their API handles complex pathfinding across dozens of DEXes, ensuring users get optimal prices for their swaps. The automatic slippage management and gas optimization features significantly improve user experience. CoinGecko Partnership CoinGecko's pricing API provides reliable, real-time market data for both Ethereum and Polkadot ecosystem tokens. This partnership was crucial because Polkadot's ecosystem lacks a unified price oracle, and CoinGecko's comprehensive coverage (with fallback modes) ensures our pricing remains accurate even when individual chains experience issues. Infura Infrastructure Infura provides enterprise-grade Ethereum RPC access, eliminating the need for us to run our own Ethereum nodes. This partnership ensures 99.9% uptime and handles the complex infrastructure challenges of maintaining reliable blockchain connectivity. Notable Hacks and Creative Solutions The "Universal Proxy" Pattern One of our cleverest implementations is the universal 1inch proxy. Instead of implementing individual endpoints for each 1inch service, we created a catch-all proxy that forwards any path after /oneinch/ directly to 1inch's API. This means we automatically support new 1inch features without code changes - when they launch new APIs, our users can access them immediately.
@app.api_route("/oneinch/{path:path}", methods=["GET", "POST"]) async def proxy_oneinch(path: str, request: Request): # Forward to https://api.1inch.dev/{path} Substrate Runtime Hot-Swapping We implemented a development pattern where the Substrate runtime can be rebuilt and restarted without losing HTLC state. This required careful design of the pallet storage structures and migration logic, allowing us to iterate rapidly on HTLC logic while maintaining active test swaps. Environment Variable Chain Configuration Rather than hardcoding contract addresses, we made the entire system configurable through environment variables. This allows the same codebase to work across testnets and mainnets simply by changing configuration, significantly simplifying deployment and testing workflows. Docker-First Development The entire backend runs in Docker from day one, not as an afterthought. This eliminated "works on my machine" issues and allowed team members to spin up the complete environment with a single docker run command. The Dockerfile includes all necessary dependencies for both Ethereum and Polkadot interactions. Automatic Database Reset for Demos We implemented an /admin/reset-db endpoint that completely resets the demo database state. This seemingly simple feature was crucial for hackathon demos and testing, allowing us to showcase clean user journeys repeatedly without manual database management. Hybrid On-Chain/Off-Chain State Management The most sophisticated hack involves our hybrid state management. While the actual HTLC contracts live on-chain, we maintain off-chain metadata about swap progress, user preferences, and transaction histories. This provides a responsive UI experience while maintaining the security guarantees of on-chain settlement. The state synchronization between our FastAPI backend and both blockchain networks required implementing custom event listeners and retry logic to handle network partitions and temporary node unavailability gracefully. Graceful Degradation Architecture We designed every external dependency to have fallback modes. If the Polkadot RPC is unavailable, we fall back to CoinGecko-only mode. If 1inch is down, we provide basic swap functionality through direct contract interactions. This resilience was crucial for demo reliability during the hackathon.