func() swap

Func() Swap is an extension of 1inch Fusion+ that enables swaps b/w EVM and Cosmos/Near.

func() swap

Created At

Unite Defi

Project Description

πŸ” Cross-Chain Atomic Swap: Cosmos ↔ Ethereum This project implements a trustless, cross-chain atomic swap between the Cosmos and Ethereum ecosystems, enabling decentralized asset exchange between two fundamentally different blockchains.

βœ… Key Components πŸ›° Cosmos Side (e.g., Osmosis / Juno / Custom Zone) Custom CosmWasm Escrow Smart Contract implementing:

Hashlock: Ensures the recipient can only claim funds by revealing the correct preimage (secret).

Timelock: Refunds funds to the sender if the claim is not completed within a timeout window.

Users lock tokens (e.g., uosmo, uatom, CW20) into this contract using a createSwap method.

The claim function requires the secret, while refund is available after timeout expiration.

Built using cw-plus standards (e.g., CW1/CW20 where needed) for compatibility and auditability.

β›“ Ethereum Side Utilizes 1Inch’s Escrow Contracts (or similar EVM-compatible escrow logic).

These contracts also enforce hashlock + timelock principles.

Supports ERC-20 tokens and native ETH.

A swap participant locks ETH/ERC-20 tokens into the escrow contract.

The same secret used on the Cosmos side is used to unlock the funds.

πŸ” Atomic Swap Workflow Initiator (Alice) creates a hash of a random secret and locks tokens into a Cosmos escrow contract.

Responder (Bob) observes the hash and locks ETH/ERC-20 tokens into the Ethereum escrow with the same hash.

Alice claims ETH on Ethereum using the secret, which gets publicly revealed on-chain.

Bob extracts the secret from the Ethereum tx, and uses it to claim Cosmos tokens before timeout.

If either party fails to claim within the timelock window, they can issue a refund.

πŸ›  Technical Highlights Cosmos Stack:

CosmWasm contracts

Built/tested using wasmd, osmo-testnet, and cw-multi-test

Ethereum Stack:

Solidity contracts from 1Inch (or alternative audited escrow contracts)

Ethers.js or Web3.js integration

Frontend/Wallet Integration:

MetaMask (for Ethereum)

Keplr (for Cosmos)

Optionally: CLI tooling with @cosmjs and ethers.js

πŸŒ‰ Cross-Chain Coordination No bridging or intermediary is required.

Relies entirely on shared secret hash commitment scheme and chain-native smart contracts.

Both chains are independent but coordinated via off-chain orchestration and public on-chain events.

πŸ§ͺ Testing & Dev Environment Cosmos: local wasmd devnet, Osmosis testnet, Keplr wallet

Ethereum: Hardhat local testnet or Goerli/holesky testnet, MetaMask wallet

Includes scripts for:

Generating secrets & hashes

Deploying and interacting with both contracts

Monitoring claim/refund flow across both chains

How it's Made

πŸ–₯ Frontend The frontend is built using the Next.js framework, enabling a fast and modular user experience across browser and mobile devices. It integrates seamlessly with both ecosystems via:

Cosmos side:

Utilizes @cosmjs/proto-signing and @cosmjs/stargate to interact with CosmWasm-based smart contracts.

Supports Keplr wallet integration for user authentication and transaction signing.

Allows for transaction creation, monitoring, and secret submission within the Cosmos network.

Ethereum side:

Uses ethers.js to interact with Ethereum smart contracts.

Fully compatible with MetaMask and other browser wallets.

Supports sending transactions, monitoring receipts, and extracting secrets from events on-chain.

The frontend orchestrates the full atomic swap flow by tracking secret commitments and propagating state transitions across both chains.

πŸ”§ Backend / Smart Contracts 🧬 Cosmos Ecosystem Language: Rust

Framework: CosmWasm

Features:

Custom smart contracts implementing hashlock and timelock functionality.

Adheres to CW standards (CW20 for tokens, CW1 for access control).

Allows initSwap, claim, and refund operations.

Fully tested using cw-multi-test for local simulations and osmosisd for live testnets.

πŸ”— Ethereum / EVM-Compatible Networks Language: Solidity

Framework: Foundry

Features:

Uses either custom or audited Escrow contracts (e.g., from 1Inch).

Implements matching hashlock and timelock logic on the EVM side.

Emits events that enable secret discovery by counterparties.

Supports ERC20 and native ETH transfers.

Contracts are rigorously tested using forge test and fuzzing via Foundry's powerful test suite.

πŸ”„ Atomic Swap Workflow (Simplified) Alice locks Cosmos tokens in a Wasm escrow with a hash of a secret.

Bob observes the hash and locks ETH or ERC20 tokens on Ethereum with the same hash.

Alice claims the ETH on Ethereum by revealing the secret.

Bob retrieves the secret from the Ethereum transaction and claims the Cosmos tokens before the timelock expires.

background image mobile

Join the mailing list

Get the latest news and updates