cosmoFusion
Cross-chain atomic swaps: swap Ethereum/Cosmos assets via 1inch Fusion+, secure & decentralized.
Problem Statement
🌉 Cross-Chain Resolver: Ethereum ↔ Cosmos Fusion+Acomplete cross-chain atomic swap systemimplementing 1inch Fusion+ protocol betweenEthereumandCosmosecosystems.🏗️Architecture Overview┌─────────────────┐ IBC/Cross-Chain ┌─────────────────┐ │ ETHEREUM │ ◄─────────────────► │ COSMOS │ │ │ │ │ │ ┌─────────────┐ │ │ ┌─────────────┐ │ │ │ 1inch LOP │ │ │ │ Cosmos LOP │ │ │ └─────────────┘ │ │ └─────────────┘ │ │ │ │ │ │ │ │ ▼ │ │ ▼ │ │ ┌─────────────┐ │ │ ┌─────────────┐ │ │ │EscrowFactory│ │ │ │EscrowFactory│ │ │ └─────────────┘ │ │ └─────────────┘ │ │ │ │ │ │ │ │ ▼ │ │ ▼ │ │ ┌─────────────┐ │ │ ┌─────────────┐ │ │ │ Resolver │ │ │ │ Resolver │ │ │ └─────────────┘ │ │ └─────────────┘ │ └─────────────────┘ └─────────────────┘✨Features🔥Core Capabilities✅ Atomic Cross-Chain Swaps- Trustless swaps between Ethereum and Cosmos✅ 1inch Fusion+ Integration- Built on proven 1inch infrastructure✅ IBC Communication- Native Cosmos Inter-Blockchain Communication✅ CosmWasm Smart Contracts- Production-ready Rust contracts✅ Hashlock/Timelock Security- Cryptographic safety guarantees✅ Safety Deposits- Collateral system prevents griefing attacks🌐Supported NetworksEthereum↔Cosmos(Full implementation)Extensibleto any IBC-enabled chain🛡️Security FeaturesAtomic Execution- Either both sides complete or both failSecret-based Unlocking- Cryptographic proof requiredTimelock Protection- Automatic refunds after expirationSafety Deposits- Economic incentives for honest behavior🚀Quick StartPrerequisites# Install Node.js dependencies pnpm install # Install Foundry (for Ethereum contracts) curl -L https://foundry.paradigm.xyz | bash # Install Rust (for Cosmos contracts) curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh rustup target add wasm32-unknown-unknown # Install contract dependencies forge installTest Commands🧪Run Ethereum ↔ Cosmos Tests# Test the Cosmos CosmWasm contracts cd cosmos-contracts cargo test --package escrow-factory --test simple_test # Expected output: # ✅ test_escrow_factory_instantiation ... ok # ✅ test_cross_chain_swap_simulation ... ok # ✅ test_create_source_escrow ... ok # ✅ test_withdraw_from_source ... ok # test result: ok. 4 passed; 0 failed🔧Build Cosmos Contractscd cosmos-contracts make build # Build all contracts make test # Run all tests make optimize # Optimize for deployment📁Project Structurecross-chain-resolver-example/ ├── cosmos-contracts/ # 🆕 Cosmos CosmWasm Contracts │ ├── contracts/ │ │ ├── escrow-factory/ # Cross-chain escrow management │ │ ├── lop/ # 1inch LOP implementation │ │ └── resolver/ # Swap coordination │ ├── tests/ # Comprehensive test suite │ └── Makefile # Build automation ├── contracts/ # Ethereum Solidity contracts │ └── src/ │ ├── Resolver.sol # Main resolver contract │ └── TestEscrowFactory.sol ├── tests/ # Cross-chain integration tests └── 1inch-lop/ # 1inch protocol integration🔄Cross-Chain Swap FlowStep 1: Order Creation// User creates order on Ethereum const order = await createCrossChainOrder({ makerAsset: "ETH", takerAsset: "ATOM", makingAmount: "1000000000000000000", // 1 ETH takingAmount: "100000000" // 100 ATOM });Step 2: Source Escrow// Cosmos contract creates source escrow execute_create_src_escrow( immutables, order_hash, safety_deposit ) -> IBC message to EthereumStep 3: Destination Escrow// Ethereum contract receives IBC message function deploySrc(immutables, order, signature, amount) -> Creates destination escrowStep 4: Atomic Completion// Secret revealed, swap completes atomically execute_withdraw_from_src(order_hash, secret) -> Transfers complete on both chains ✅🧪Test Results✅ Cosmos Contract Tests (ALL PASS)running 4 tests test tests::test_escrow_factory_instantiation ... ok test tests::test_cross_chain_swap_simulation ... ok test tests::test_create_source_escrow ... ok test tests::test_withdraw_from_source ... ok test result: ok. 4 passed; 0 failed; 0 ignoredTest Coverage✅ Cross-chain escrow creation✅ IBC message generation✅ Atomic swap completion✅ Fund transfers and safety deposits✅ State management across chains✅ Error handling and edge cases🛠️DevelopmentCosmos Contractscd cosmos-contracts # Development workflow make dev # Format, lint, test make build # Build contracts make optimize # Optimize for deployment make deploy-local # Deploy to local chainEthereum Contracts# Compile contracts forge build # Run cross-chain tests cargo test --package escrow-factory --test simple_test # Deploy contracts forge script script/Deploy.s.sol --broadcast🚀DeploymentCosmos Deployment# Optimize contracts cd cosmos-contracts && make optimize # Deploy to testnet wasmd tx wasm store artifacts/escrow_factory.wasm --from wallet --gas-adjustment 1.3 --gas auto -y # Instantiate contracts wasmd tx wasm instantiate $CODE_ID '{"lop_address":"cosmos1lop","ethereum_channel":"channel-0"}' --from wallet --label "escrow-factory" -yEthereum Deployment# Deploy with Foundry forge script script/Deploy.s.sol --rpc-url $ETH_RPC_URL --broadcast --verify🔗Integration ExamplesTypeScript Integrationimport { EthereumCosmosIntegration } from './cosmos-contracts/tests/ethereum-cosmos-integration'; const integration = new EthereumCosmosIntegration( 'http://localhost:26657', // Cosmos RPC cosmosWallet, 'http://localhost:8545', // Ethereum RPC ethereumPrivateKey, contractAddresses ); // Execute cross-chain swap await integration.executeEthereumToCosmosSwap( 'cosmos1maker', '0xTakerAddress', '1000000000000000000', // 1 ETH '100000000' // 100 ATOM );Rust Integrationuse escrow_factory::contract::{execute, EscrowImmutables}; // Create cross-chain escrow let immutables = EscrowImmutables { order_hash: "unique_order_id".to_string(), maker: "cosmos1maker".to_string(), taker: "cosmos1taker".to_string(), amount: Uint128::new(1000000), token: "uatom".to_string(), // ... other fields }; execute(deps, env, info, ExecuteMsg::CreateSrcEscrow { immutables, order_hash })?;📊Network InformationSupported RPCs| Network | RPC URL | Chain ID | |-----------|--------------------------------------|----------| | Ethereum | https://eth.merkle.io | 1 | | Cosmos | https://rpc.cosmos.network | cosmoshub-4 |Test Accounts| Role | Address | Private Key | |----------|----------------------------------------------|-------------| | Owner | 0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266 | 0xac0974... | | User | 0x70997970C51812dc3A010C7d01b50e0d17dc79C8 | 0x59c6995... | | Resolver | 0x3C44CdDdB6a900fa2b585dd299e03d12FA4293BC | 0x5de4111... |🔒Security Considerations⚠️ Audit StatusWARNING: These contracts are in development and have not been audited. Do not use in production.Key Security FeaturesAtomic Swaps: Either both sides complete or both failTimelock Protection: Automatic refunds after expirationSafety Deposits: Collateral to prevent griefingHash Verification: Secret-based unlock mechanismsIBC Security: Leverages Cosmos IBC security guaranteesBuilt with ❤️ for the cross-chain future🌉
Solution
🏗️Architecture Overview┌─────────────────┐ IBC/Cross-Chain ┌─────────────────┐ │ ETHEREUM │ ◄─────────────────► │ COSMOS │ │ │ │ │ │ ┌─────────────┐ │ │ ┌─────────────┐ │ │ │ 1inch LOP │ │ │ │ Cosmos LOP │ │ │ └─────────────┘ │ │ └─────────────┘ │ │ │ │ │ │ │ │ ▼ │ │ ▼ │ │ ┌─────────────┐ │ │ ┌─────────────┐ │ │ │EscrowFactory│ │ │ │EscrowFactory│ │ │ └─────────────┘ │ │ └─────────────┘ │ │ │ │ │ │ │ │ ▼ │ │ ▼ │ │ ┌─────────────┐ │ │ ┌─────────────┐ │ │ │ Resolver │ │ │ │ Resolver │ │ │ └─────────────┘ │ │ └─────────────┘ │ └─────────────────┘ └─────────────────┘✨Features🔥Core Capabilities✅ Atomic Cross-Chain Swaps- Trustless swaps between Ethereum and Cosmos✅ 1inch Fusion+ Integration- Built on proven 1inch infrastructure✅ IBC Communication- Native Cosmos Inter-Blockchain Communication✅ CosmWasm Smart Contracts- Production-ready Rust contracts✅ Hashlock/Timelock Security- Cryptographic safety guarantees✅ Safety Deposits- Collateral system prevents griefing attacks🌐Supported NetworksEthereum↔Cosmos(Full implementation)Extensibleto any IBC-enabled chain🛡️Security FeaturesAtomic Execution- Either both sides complete or both failSecret-based Unlocking- Cryptographic proof requiredTimelock Protection- Automatic refunds after expirationSafety Deposits- Economic incentives for honest behavior🚀Quick StartPrerequisites# Install Node.js dependencies pnpm install # Install Foundry (for Ethereum contracts) curl -L https://foundry.paradigm.xyz | bash # Install Rust (for Cosmos contracts) curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh rustup target add wasm32-unknown-unknown # Install contract dependencies forge installTest Commands🧪Run Ethereum ↔ Cosmos Tests# Test the Cosmos CosmWasm contracts cd cosmos-contracts cargo test --package escrow-factory --test simple_test # Expected output: # ✅ test_escrow_factory_instantiation ... ok # ✅ test_cross_chain_swap_simulation ... ok # ✅ test_create_source_escrow ... ok # ✅ test_withdraw_from_source ... ok # test result: ok. 4 passed; 0 failed🔧Build Cosmos Contractscd cosmos-contracts make build # Build all contracts make test # Run all tests make optimize # Optimize for deployment
Hackathon
ETHGlobal Unite
2025
Contributors
- mbcse
6 contributions