Trustless, bidirectional cross-chain swaps between Ethereum & Cosmos via Hashed Time Lock Contracts
This project extends 1inch Fusion+ to the Cosmos ecosystem, enabling trustless and bidirectional cross-chain token swaps between Ethereum and Cosmos using the robust mechanism of Hashed Time Lock Contracts (HTLCs). Unlike traditional bridges or centralized exchange on/off-ramps, FusionCosmos leverages HTLCs to ensure users never lose custody of their funds or rely on intermediaries for the security of their assets.
Here’s how it works:
This project commenced by leveraging the crosschain resolver example GitHub repository. This TypeScript-based simulation provided the foundational understanding and boilerplate code for the EVM side of Fusion+ swaps, demonstrating interactions with 1inch's smart contracts, including the EscrowFactory and the mechanics of the safety deposit. We meticulously studied the main.spec.ts file to grasp the nuances of single and partial fills. For the Cosmos side, the core of the innovation lies in the native implementation of the HTLC contract. This involved developing the smart contract logic on Cosmos to precisely replicate the hashlock and timelock functionalities as seen in the EVM example. This ensures that tokens on the Cosmos side can be securely locked and released based on the same secret and expiration conditions, crucial for maintaining atomicity across chains. The cross-chain orchestration is managed by custom-built relayer and resolver components. These off-chain services are designed to: • Monitor the state of HTLCs on both the Ethereum (EVM) and Cosmos chains. • Verify the correct deposit and locking of funds according to the swap parameters. • Facilitate the secure revelation and transmission of the secret to enable the completion of the swap by the resolver. • The resolver component specifically provides the liquidity and executes the final claim transactions on both chains. For this Version 1 Proof of Concept, all functionalities are demonstrated via a Command Line Interface (CLI) and executed on testnets for both Ethereum and Cosmos. This ensures we can present clear on-chain execution of token transfers as required for the demo. It is critical to note that for this hackathon, we are working directly at the smart contract level. We are not posting orders to 1inch's official REST APIs, as the live resolvers operate within a whitelisted and KYC'd environment. Our solution is self-contained for demonstration purposes, mimicking the core logic of the 1inch Fusion+ protocol.