Skip to content

Shashwat-Nautiyal/-Fusion

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

26 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

πŸš€ Fusion+ Cross-Chain Escrow Swaps

πŸ”— Trustless atomic swaps between Base Sepolia and Etherlink testnets

Fusion+ is a cutting-edge proof-of-concept blockchain application that enables atomic, trustless token swaps between different blockchain networks without relying on centralized bridges or intermediaries. Currently supporting Base Sepolia and Etherlink testnets, this project demonstrates how cryptographic primitives can solve one of DeFi's biggest challenges: secure cross-chain asset transfers.

🎯 Problem Statement

Traditional cross-chain swaps suffer from:

  • πŸ” Trust Requirements: Relying on centralized bridges
  • ⚑ Security Risks: Vulnerability to bridge hacks and exploits
  • πŸ• Timing Issues: Risk of funds being permanently locked
  • πŸ’Έ High Fees: Expensive intermediary costs

✨ Key Features

πŸ”’ Cryptographic Security

  • Hashlock Mechanism: Uses SHA-256 hashes for secure secret-based unlocking
  • Timelock Safety: Built-in expiration prevents permanent fund loss
  • Atomic Guarantees: Either both sides complete or neither does

🌐 Cross-Chain Support

  • Base Sepolia: Ethereum Layer 2 testnet integration
  • Etherlink: Tezos-based blockchain support
  • Extensible Design: Architecture supports additional chains

🏭 Smart Contract Factory Pattern

  • Scalable Deployment: Factory contracts create individual escrows
  • Gas Optimization: Efficient contract instantiation
  • Modular Architecture: Clean separation of concerns

πŸ›‘οΈ Advanced Security Features

  • No Bridge Dependencies: Eliminates bridge-related vulnerabilities
  • Trustless Design: No need for trusted third parties
  • Timeout Protection: Automatic fund recovery mechanisms

πŸ”„ How It Works

Step 1: Order Creation πŸ“

πŸ‘€ Maker creates swap order:
β”œβ”€β”€ Source Chain: Base Sepolia
β”œβ”€β”€ Offer: 100 USDC
β”œβ”€β”€ Target Chain: Etherlink  
└── Want: 95 DAI

Step 2: Order Acceptance 🀝

πŸ‘€ Taker accepts order:
β”œβ”€β”€ Generates shared secret
β”œβ”€β”€ Creates cryptographic hashlock
└── Initiates escrow deployment

Step 3: Escrow Deployment & Fund Locking πŸ”

🏭 Factory Contracts Deploy:
β”œβ”€β”€ Base Sepolia Escrow
β”‚   β”œβ”€β”€ Locks 100 USDC
β”‚   β”œβ”€β”€ Hashlock: 0xabc123...
β”‚   └── Timelock: 24 hours
└── Etherlink Escrow
    β”œβ”€β”€ Locks 95 DAI
    β”œβ”€β”€ Same Hashlock: 0xabc123...
    └── Timelock: 12 hours

Step 4: Atomic Settlement ⚑

πŸ”“ Settlement Process:
β”œβ”€β”€ Taker reveals secret on Etherlink β†’ Claims 95 DAI
β”œβ”€β”€ Secret becomes public on blockchain
β”œβ”€β”€ Maker uses revealed secret on Base β†’ Claims 100 USDC
└── βœ… Swap Complete!

⏰ Fallback: If timeout expires β†’ Both parties reclaim funds

πŸ› οΈ Technical Stack

Smart Contracts πŸ“‹

  • Language: Solidity ^0.8.0
  • Framework: Foundry
  • Pattern: Factory + Implementation contracts
  • Security: Hashlock + Timelock mechanisms

Integration Layer πŸ”Œ

  • Cross-Chain SDK: 1inch Cross-Chain SDK
  • Blockchain Interaction: Ethers.js
  • Language: TypeScript
  • Package Manager: PNPM

Supported Networks 🌐

Network Type RPC Factory Contract
Base Sepolia L2 Testnet Custom RPC 0x...
Etherlink Tezos-based Custom RPC 0x...

πŸš€ Quick Start

Prerequisites πŸ“‹

# Required tools
- Node.js v18+
- PNPM
- Foundry
- Git

Installation πŸ’»

# Clone the repository
git clone https://github.com/Shashwat-Nautiyal/-Fusion.git
cd Fusion

# Install dependencies
pnpm install

# Install Foundry dependencies
forge install

Environment Setup πŸ”§

Create a .env file:

# Network RPCs
BASE_SEPOLIA_RPC=your_base_sepolia_rpc_url
ETHERLINK_RPC=your_etherlink_rpc_url

# Private Keys (for testing only!)
PRIVATE_KEY_1=your_test_private_key_1
PRIVATE_KEY_2=your_test_private_key_2

# Factory Contract Addresses
BASE_FACTORY_ADDRESS=0x...
ETHERLINK_FACTORY_ADDRESS=0x...

Build & Test πŸ§ͺ

# Compile contracts
forge build

# Run comprehensive test suite
pnpm test

# Run specific test
forge test -vvv

πŸ“Š Contract Architecture

Factory Contracts 🏭

contract EscrowFactory {
    function createEscrow(
        bytes32 hashlock,
        uint256 timelock,
        address recipient,
        uint256 amount
    ) external returns (address escrow);
}

Escrow Implementation πŸ”

contract Escrow {
    // Hashlock: Cryptographic security
    bytes32 public hashlock;
    
    // Timelock: Time-based safety
    uint256 public timelock;
    
    // Claim with secret
    function claim(string calldata secret) external;
    
    // Reclaim after timeout
    function reclaim() external;
}

πŸ” Security Model

Hashlock Security πŸ›‘οΈ

  • One-way Function: SHA-256 ensures secret cannot be reverse-engineered
  • Atomic Revelation: Secret revealed on one chain enables claim on other
  • Cryptographic Proof: Mathematical guarantee of authenticity

Timelock Safety ⏰

  • Asymmetric Timeouts: Different expiration times prevent deadlocks
  • Automatic Recovery: Funds automatically recoverable after timeout
  • Fail-Safe Design: System defaults to returning funds to owners

Economic Incentives πŸ’°

  • Completion Reward: Both parties benefit from successful completion
  • Time Pressure: Earlier timeout encourages prompt execution
  • Risk Mitigation: No permanent fund loss possible

πŸ§ͺ Testing Framework

Comprehensive Test Suite βœ…

tests/
β”œβ”€β”€ unit/
β”‚   β”œβ”€β”€ EscrowFactory.t.sol      # Factory functionality
β”‚   β”œβ”€β”€ Escrow.t.sol             # Individual escrow logic
β”‚   └── Hashlock.t.sol           # Cryptographic primitives
β”œβ”€β”€ integration/
β”‚   β”œβ”€β”€ CrossChainSwap.t.sol     # End-to-end swap flows
β”‚   └── TimeoutScenarios.t.sol   # Edge case handling
└── e2e/
    └── FullSwapCycle.t.sol      # Complete user journey

Test Coverage πŸ“ˆ

  • βœ… Happy Path: Successful swap completion
  • βœ… Timeout Scenarios: Fund recovery mechanisms
  • βœ… Invalid Secrets: Security boundary testing
  • βœ… Cross-Chain Coordination: Network interaction verification

🌍 Use Cases

DeFi Protocols πŸ’±

  • DEX Integration: Enable cross-chain trading pairs
  • Liquidity Bridging: Move assets between ecosystems
  • Yield Farming: Access opportunities across chains

Individual Traders πŸ‘€

  • Portfolio Rebalancing: Move assets without centralized risk
  • Arbitrage Opportunities: Exploit price differences across chains
  • Ecosystem Migration: Transfer holdings between preferred networks

Developers πŸ‘¨πŸ’»

  • dApp Integration: Build cross-chain functionality
  • Research Platform: Study atomic swap mechanisms
  • Infrastructure Building: Create trustless bridge alternatives

⚠️ Important Disclaimers

Testnet Only πŸ§ͺ

  • Current Status: Proof-of-concept on testnets
  • Not Production Ready: Requires security audits
  • Educational Purpose: Designed for learning and testing

Risk Considerations ⚠️

  • Smart Contract Risk: Potential bugs in contract logic
  • Network Risk: Testnet instability
  • Key Management: Secure private key handling required

🀝 Contributing

We welcome contributions! Please see our Contributing Guidelines for details.

Development Workflow πŸ”„

  1. 🍴 Fork the repository
  2. 🌿 Create feature branch (git checkout -b feature/amazing-feature)
  3. πŸ’Ύ Commit changes (git commit -m 'Add amazing feature')
  4. πŸ“€ Push to branch (git push origin feature/amazing-feature)
  5. πŸ”„ Open Pull Request

πŸ“„ License

This project is licensed under the MIT License - see the LICENSE file for details.

πŸ™ Acknowledgments

  • 1inch Network: Cross-chain SDK integration
  • Foundry Team: Development framework
  • Base: Testnet infrastructure
  • Tezos: Etherlink blockchain support

πŸ“ž Contact & Support

⭐ Star this repository if you find it useful! ⭐

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors 3

  •  
  •  
  •