UniteSwap is a groundbreaking Rust CLI implementation that extends the 1inch Fusion+ protocol to enable secure, trustless atomic swaps between Ethereum (EVM) and NEAR Protocol. This is the first production-ready solution that
bridges the gap between EVM and NEAR ecosystems through atomic swaps.
The project addresses a critical limitation in the current DeFi ecosystem: while 1inch Fusion+ provides excellent cross-chain swap capabilities within the EVM ecosystem, it doesn't support swaps with non-EVM chains. UniteSwap
specifically focuses on bridging Ethereum with NEAR Protocol, chosen for its Rust-native development environment and growing DeFi ecosystem.
Key features include:
- Bidirectional Atomic Swaps: Full support for both ETH→NEAR and NEAR→ETH token transfers using Hash Time Lock Contracts (HTLC)
- 1inch Fusion+ Extension: Seamlessly integrates with the official 1inch Limit Order Protocol on Ethereum while adding NEAR support
- Real Blockchain Transactions: All operations create verifiable on-chain transactions on both Ethereum (Base Sepolia) and NEAR testnet
- Security First: Preserves all security guarantees of the original Fusion+ protocol including hashlock and timelock mechanisms
- Integrated Swap Command: Single CLI command orchestrates the entire cross-chain swap process automatically
- Event Monitoring: Real-time tracking of swap progress on both chains with automatic claim execution
Technical Implementation:
- Rust-based CLI: High-performance command-line interface with comprehensive error handling
- HTLC Smart Contracts: Custom implementation on NEAR (htlc-v2.testnet) that mirrors Ethereum's HTLC logic
- EIP-712 Integration: Embeds HTLC parameters directly into 1inch orders for seamless compatibility
- Modular Architecture: Clean separation between core logic (fusion-core) and CLI interface (fusion-cli)
UniteSwap demonstrates that secure, decentralized bridges between EVM and NEAR are not only possible but practical. By focusing specifically on NEAR integration, we've created a robust, production-ready solution that can handle real
value transfers. The project includes comprehensive testing with 100+ test cases and full documentation for developers. The success of this implementation paves the way for similar integrations with other non-EVM chains in the
future, but our current focus remains on perfecting the Ethereum↔NEAR bridge to provide maximum value to both ecosystems.
UniteSwap is built with Rust at its core, leveraging its memory safety and performance advantages for cross-chain atomic swaps. Here's how we architected and implemented the solution:
Tech Stack & Architecture:
- Rust CLI (fusion-cli): The main interface built with Clap for command parsing, Tokio for async operations, and Serde for data serialization. We chose Rust for its zero-cost abstractions and fearless concurrency, crucial for
handling multiple blockchain interactions simultaneously.
- fusion-core Library: The heart of our system, implementing HTLC trait abstractions that work across heterogeneous blockchains. Uses async-trait for defining common interfaces and thiserror for robust error handling.
- Multi-chain Integration:
- Ethereum: Direct integration with 1inch Limit Order Protocol using ethers-rs and custom EIP-712 signing implementation
- NEAR: Native Rust SDK integration with custom HTLC smart contracts written in Rust
- Cosmos/Stellar: Trait-based abstractions ready for implementation
Key Technical Innovations:
-
Unified HTLC Abstraction: We created a generic HTLCContract trait that abstracts the differences between EVM and non-EVM chains:
#[async_trait]
pub trait HTLCContract {
async fn create_lock(...) -> Result<String>;
async fn claim_with_secret(...) -> Result<TransactionHash>;
async fn refund_after_timeout(...) -> Result<TransactionHash>;
}
-
Cross-Chain Event Monitoring: Built a sophisticated event monitoring system using Tokio's async runtime that watches both Ethereum and NEAR events in parallel, enabling real-time swap tracking and automatic claim execution.
-
EIP-712 Integration: Implemented custom EIP-712 domain separation and struct encoding to embed HTLC parameters directly into 1inch limit orders, preserving all security guarantees while extending functionality.
-
Secret Management: Developed a cryptographically secure secret generation system using rand::rngs::OsRng and SHA3-256 hashing, ensuring each swap has unique, unpredictable secrets.
Partner Technology Integration:
- 1inch Fusion+ Protocol: We reverse-engineered and extended the 1inch Limit Order Protocol to support non-EVM chains. By embedding HTLC parameters in the order's interaction field, we maintain full compatibility while adding
cross-chain capabilities.
- NEAR Protocol: Leveraged NEAR's native Rust SDK and low transaction costs to implement efficient HTLC contracts. The 2-second finality and <$0.01 transaction costs make it ideal for high-frequency cross-chain swaps.
- Base (Ethereum L2): Used Base Sepolia for Ethereum-side operations, benefiting from lower costs than mainnet while maintaining EVM compatibility.
Notable Technical Hacks:
- Order Relay Mechanism: Created a novel relay system that monitors Ethereum orders and automatically creates corresponding HTLC contracts on NEAR, eliminating the need for centralized bridges.
- Partial Fill Support: Implemented multiple secret generation for gradual order execution, allowing large orders to be filled by multiple counterparties—a feature not native to standard HTLC implementations.
- Integrated Swap Command: Built a complex state machine that orchestrates the entire swap process across chains, handling errors, retries, and timeouts gracefully. This involved careful coordination of:
- Price oracle queries
- HTLC creation on both chains
- Order signing and submission
- Event monitoring and automatic claiming
- Gas Optimization: Used Rust's zero-copy serialization (borsh) for NEAR contracts and optimized Ethereum calldata encoding to minimize transaction costs.
- Development Workflow: Implemented Test-Driven Development (TDD) with 100+ test cases, ensuring reliability. Used proptest for property-based testing of cryptographic components.
The modular architecture allows easy extension to additional chains—implementers only need to provide the HTLCContract trait implementation for their target chain. This positions UniteSwap as a universal gateway for cross-chain
atomic swaps, dramatically reducing the complexity of multi-chain DeFi interactions.