project screenshot 1
project screenshot 2
project screenshot 3

FusionCosmos

Trustless, bidirectional cross-chain swaps between Ethereum & Cosmos via Hashed Time Lock Contracts

FusionCosmos

Created At

Unite Defi

Project Description

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:

  1. A user initiates a swap request on either Ethereum or Cosmos.
  2. On the Ethereum side, the system interacts with the official 1inch Escrow Factory to deploy a 1inch Escrow (HTLC) contract, where the user's funds are locked by a cryptographic hash of a secret. This process also involves the resolver depositing a "safety deposit" to ensure the swap’s completion.
  3. Simultaneously, a native HTLC contract on Cosmos is created. This contract mirrors the hashlock and timelock logic of its EVM counterpart, ensuring funds on the Cosmos side can only be claimed by revealing the same secret within a defined timeframe, or they revert to the resolver.
  4. An off-chain relayer service monitors both the Ethereum and Cosmos HTLCs. Once it confirms funds are properly locked on both chains, it signals the user to reveal their secret. This secret is then relayed to the resolver.
  5. A custom resolver component for Cosmos uses this secret to claim the user’s funds from the Ethereum HTLC and simultaneously allows the user to claim the resolver's funds from the Cosmos HTLC, thereby completing the atomic swap. This architecture guarantees that funds are never truly "stuck," and the swap is either completed atomically or funds are safely returned to their origin, fully preserving the trustless nature of DeFi. This project demonstrates the fundamental building blocks required for extending 1inch Fusion+ functionality to new blockchain environments like Cosmos, supporting both EVM-to-Cosmos and Cosmos-to-EVM swap directions.

How it's Made

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.

background image mobile

Join the mailing list

Get the latest news and updates