Trustless cross-chain atomic swaps using Dutch auctions between Ethereum and Aptos
Project Description: Cyrofuzion – Trustless Cross-Chain Atomic Swaps via 1inch Fusion+ Cyrofuzion is a cross-chain atomic swap protocol designed to enable trustless, decentralized, and auction-based token exchanges between Ethereum (Base Sepolia) and Aptos Testnet. It is built as a powerful extension to the 1inch Fusion+ protocol, leveraging Dutch auction mechanisms and custom HTLC (Hash Time Locked Contract) implementations on both EVM and Move ecosystems. Cyrofuzion eliminates the need for centralized bridges or intermediaries, thereby removing counterparty risk and increasing security through cryptographic guarantees and time-bound enforcement. How It Works At the heart of Cyrofuzion is an event-driven, multi-layered architecture that connects users, relayers, and smart contracts across chains. Makers create cross-chain orders via a Web UI. These are posted to the Ethereum smart contract (FusionDutchAuction) and broadcasted to relayers. A Dutch auction begins: over time, the exchange rate decreases based on preset steps until a Resolver finds it profitable to fulfill. Resolvers (off-chain bots) monitor these auctions and can trigger escrow creation on Aptos once conditions are met. The Maker reveals the secret, and the relayer facilitates claims on both Ethereum and Aptos, completing the atomic swap. If anything fails or timeouts occur, both parties are refunded automatically via HTLC logic. Core Innovations Atomic Cross-Chain Swaps Utilizes HTLC contracts on both Ethereum and Aptos to enforce atomicity: either both sides of the trade succeed, or neither executes. Dutch Auction Pricing Dynamic pricing ensures resolvers compete over time for profitability, allowing price discovery and incentivizing fair execution. 1inch Fusion+ Integration Designed as a natural plug-in to 1inch’s Fusion+ protocol, inheriting its secure infrastructure and auction-based execution model. Custom Event Relayer A decentralized off-chain service monitors blockchain events and coordinates inter-chain messages to resolve orders. Move + Solidity Dual Contracts Ethereum uses Solidity-based escrow and auction contracts; Aptos uses Move modules for escrow logic—enabling seamless dual-chain compatibility. System Components
How We Built the Cross-Chain Swap System: A Hackathon Journey Project Overview Our team developed a trustless cross-chain swap system for a hackathon, enabling decentralized token exchanges between an EVM-based chain (Base Sepolia, an Ethereum testnet) and a non-EVM chain (Aptos testnet). The system facilitates atomic swaps using a Dutch auction mechanism, allowing multiple resolvers to compete for fulfilling swap orders. By leveraging hashlocks and timelocks, we ensured secure, all-or-nothing transactions without centralized bridges. Below, we dive into the nitty-gritty details of how we built this system, the technologies we used, how they were integrated, and the creative solutions we employed. Technologies Used We selected a focused technology stack to balance functionality, security, and hackathon timelines: Solidity (EVM Contracts): Purpose: Used to develop smart contracts for Base Sepolia, the source chain. Contracts: Limit Order Protocol (LOP): A custom contract that verifies signed orders from makers, emitting an OrderVerified event with details such as aptosAsset, crossChainRecepient, maker, takerAsset, makingAmount, takingAmount, escrowSrc, and hashlock. EscrowSrc: Locks the maker’s ERC20 tokens with a hashlock (secret hash) and timelock (deadline). Modified to transfer funds to a predefined taker address (not msg.sender) to support scenarios where the resolver and taker differ. EscrowFactorySrc: Deploys new EscrowSrc instances, emitting EscrowCreated events for tracking. Why Solidity?: As the standard for EVM-compatible chains, Solidity enabled us to leverage Ethereum’s robust ecosystem and tools like OpenZeppelin for secure token interactions. Move (Aptos Contracts): Purpose: Planned for writing escrow contracts on the Aptos testnet, the destination chain. Contracts (designed, to be implemented): EscrowDst: Locks the resolver’s assets with the same hashlock and a shorter timelock, allowing the maker to claim funds. EscrowFactoryDst: Deploys new EscrowDst instances, emitting events for resolver tracking. Why Move?: Aptos’s Move language offers type safety and resource-oriented programming, ideal for secure asset handling on a non-EVM chain. TypeScript and ethers.js (Resolver Logic): Purpose: Implemented the off-chain resolver logic to monitor orders, deploy escrows, and manage swaps. Details: A resolver.ts script uses ethers.js to interact with Base Sepolia contracts, integrating with MetaMask for transaction signing. Functions include deployEscrow (creates escrows on the source chain), submitSecret (claims funds with the secret), and refund (returns funds to the maker if timelock expires). Why TypeScript/ethers.js?: TypeScript’s type safety and ethers.js’s simplicity enabled rapid development and reliable EVM interactions. MetaMask integration provided a user-friendly way to sign transactions. Aptos SDK (Planned): Purpose: To extend the resolver logic for interacting with Aptos contracts (e.g., deploying EscrowDst, claiming funds). Details: Planned to use @aptos-labs/ts-sdk for Move contract calls, similar to ethers.js for EVM. Why Aptos SDK?: Offers a robust interface for Aptos transactions, ensuring compatibility with Move contracts. Node.js (Backend Services): Purpose: Runs the relayer and resolver logic as lightweight services. Why Node.js?: Its event-driven architecture and compatibility with TypeScript made it ideal for real-time event processing and cross-chain coordination. How They’re Pieced Together The system integrates on-chain and off-chain components to enable cross-chain swaps with Dutch auctions: Order Creation and Verification: The maker uses a frontend (or CLI) to generate a secret, compute its hash (hashlock), and deploy an EscrowSrc on Base Sepolia via EscrowFactorySrc using ethers.js and MetaMask. The maker signs an order specifying assets, amounts, hashlock, timelock, and Dutch auction parameters (start price, decay rate, minimum price) and submits it to the LOP contract. The LOP contract verifies the signature and emits OrderVerified, including the escrowSrc address, taker address, and auction details. Relayer Service: A Node.js service uses ethers.js to listen for OrderVerified events on Base Sepolia. It broadcasts these events to resolver nodes via a simple HTTP-based API or direct messaging (e.g., WebSocket), including order details and auction parameters. It also monitors EscrowCreated events from the Aptos EscrowFactoryDst (planned with Aptos SDK) to track resolver bids. Resolver Nodes: Each resolver runs a Node.js service with resolver.ts, listening for order events from the relayer. The resolver calculates the current auction price using a linear decay function (currentPrice = startPrice - (startPrice - minPrice) * (elapsedTime / auctionDuration)). If the price is profitable, the resolver deploys an EscrowDst on Aptos (planned with Aptos SDK), locking assets at the current price, and notifies the relayer of the bid. Dutch Auction Management: For the hackathon, we implemented a simplified auction mechanism in resolver.ts, where resolvers independently calculate the current price and bid by deploying EscrowDst contracts. The first resolver to deploy a valid EscrowDst (matching hashlock and timelock) wins the auction. The relayer tracks bids and notifies the winner to proceed. For scalability, we designed a lightweight in-memory store in the relayer to track bids, avoiding complex database setups for the hackathon. Swap Completion: The maker claims funds on Aptos by submitting the secret to EscrowDst, revealing it on-chain. The relayer captures the secret (via Aptos transaction logs, planned) and sends it to the winning resolver. The resolver calls submitSecret on Base Sepolia’s EscrowSrc using resolver.ts, transferring funds to the predefined taker address. If the timelock expires, the maker or resolver can call refund to reclaim funds. Partner Technologies and Benefits We leveraged partner technologies to accelerate development and ensure reliability: OpenZeppelin (Solidity): Provided audited IERC20 interfaces for secure ERC20 token transfers in EscrowSrc.sol, reducing the risk of token-related bugs. Benefit: Saved time on token handling and ensured compliance with ERC20 standards. ethers.js (TypeScript): Simplified EVM contract interactions and MetaMask integration, enabling rapid prototyping and user-friendly transaction signing. Benefit: Streamlined event listening and transaction management, crucial for hackathon speed. Aptos SDK (Planned): Designed to provide a robust interface for Move contract interactions, ensuring compatibility with Aptos’s non-EVM architecture. Benefit: Will enable seamless integration with Aptos once implemented. MetaMask: Used for transaction signing in resolver.ts, providing a browser-based wallet for testing. Benefit: Allowed quick setup and user interaction without managing private keys manually. These technologies reduced development overhead, improved security, and enabled us to focus on core swap logic. Notable Hacky Solutions To meet the hackathon’s tight deadlines, we employed creative solutions: Off-Chain Resolver for Cross-Chain Coordination: Instead of a resolver smart contract, we used a TypeScript script (resolver.ts) to handle cross-chain logic, monitoring OrderVerified events and coordinating with Aptos. Why Hacky?: Sacrifices on-chain automation for simplicity, avoiding the need for complex cross-chain oracles or contracts on both chains. Benefit: Enabled rapid integration with Base Sepolia and planned Aptos support, using ethers.js and MetaMask for EVM interactions. Modified Escrow for Taker Address: We modified EscrowSrc.sol to transfer funds to a predefined taker address instead of msg.sender, supporting scenarios where the resolver and taker differ. Why Hacky?: Deviates from standard atomic swap designs, requiring updates to EscrowFactorySrc and order creation to include the taker address. Benefit: Added flexibility for complex swap scenarios, such as third-party resolvers, enhancing system versatility. Simplified Dutch Auction Logic: Implemented a basic linear decay function in resolver.ts for auction pricing, with resolvers independently calculating bids. Team Effort Our team collaborated effectively to deliver this project: Smart Contract Developers: Built and tested EscrowSrc.sol, EscrowFactorySrc.sol, and designed Move contracts for Aptos, ensuring secure escrow logic. Backend Engineers: Developed the relayer service to bridge events between Base Sepolia and Aptos, using Node.js and HTTP/WebSocket for communication. Frontend/Resolver Developers: Created resolver.ts with TypeScript and ethers.js, integrating MetaMask for seamless transaction signing. Cross-Chain Specialists: Researched Aptos’s Move language and SDK, preparing for integration with non-EVM contracts. Project Managers: Coordinated tasks, prioritized features, and ensured alignment with the cross-chain swap workflow. Challenges and Solutions Challenge: Bridging events between EVM and non-EVM chains without a centralized database. Solution: Used a lightweight Node.js relayer with HTTP/WebSocket to broadcast events, avoiding complex infrastructure. Challenge: Implementing Dutch auctions for multiple resolvers in a short timeframe. Solution: Simplified auction logic in resolver.ts, with the relayer tracking bids in-memory for the hackathon. Future Improvements For a production system, we’d: Implement EscrowDst and EscrowFactoryDst on Aptos using Move. Deploy an on-chain Dutch auction contract for trustless bid resolution. Integrate the Aptos SDK into resolver.ts for full cross-chain functionality. Add monitoring tools (e.g., Prometheus) for resolver performance and system health. Conclusion Our cross-chain swap system demonstrates a secure, innovative solution for decentralized token exchanges between Base Sepolia and Aptos. By leveraging Solidity, Move, TypeScript, and partner technologies like OpenZeppelin, ethers.js, and MetaMask, we built a functional prototype optimized for the hackathon. Our hacky solutions, such as the off-chain resolver and modified escrow, enabled rapid development while maintaining core functionality. This project showcases our team’s ability to tackle complex cross-chain challenges, laying the groundwork for future DeFi advancements.