XChains
  • 💡Introduction
  • Understanding XChains
    • Getting Started
    • Actors
      • Liquidity Providers
      • Swappers
      • Bridgers
    • 9CP (IXCP)
  • How it works
    • Technology
    • Fees
    • Govenance
    • Tokenomics
  • Roadmaps
    • Product Roadmap
    • Business Roadmap
  • One-page Pitch Deck
  • 🏛️XChains Architecture
    • Design Strategy
    • Hashed Time-Locked Contracts (HTLCs)
    • Cross-chain Communication
      • Oracle
      • Relay Network
  • 🛠️XChains Implementation
    • Smart Contracts
      • Private Liquidity Pool Contracts
      • Bridge Contracts
    • Atomic Swap Protocol
    • Cross-Chain Transfer Flow
    • Security Considerations
    • Public Pool Integration
  • 🔐XChains Liquidity
    • Private Liquidity Pools
    • Shared Liquidity Pools
    • XChains Formula
  • 📬Contact Us
    • Email
    • Website
    • Telegram Channel
    • Telegram Chat
Powered by GitBook
On this page
  • Bridge Contracts:
  • Bridge Contract Sample
  1. XChains Implementation
  2. Smart Contracts

Bridge Contracts

Managing the private pools and coordinating swapping or transferring assets between chains

Bridge Contracts:

  • Bridge contracts facilitate the transfer of tokens between different chains.

  • They coordinate the locking, communication, and releasing of tokens across chains.

  • Bridge contracts interact with private pools on both chains to ensure seamless transfers.

Bridge Contract Sample

contract BridgeContract {
    mapping(address => address) public privatePools;
    mapping(unit256 => address) public bridges;
    mapping(unit256 => SendRequests) public sendRequests;
    
    struct SendReqMessage {
    }
    
    struct AskForFundReqMessage {
    }
    
    struct AskForFundResMessage {
    }

    event TokensLocked(address indexed user, uint256 amount, address indexed to);

    constructor(address[] memory _privatePools, address[] memory_bridges) {
        privatePools = _privatePools;
        bridges = _bridges;
    }

    function sendMessageXChainTo(address srcBridge, address dstBridge, address token, uint256 amount, address to) external {
        require(IPrivatePoolA(privatePoolA).balanceOf(msg.sender) >= amount, "Insufficient balance");
        // Add logic to send the request message of the transferring tokens 
        // to the target bridge address on the destination chain
    }
    
    function sendMessageTo(address from, address token, uint256 amount, address to) external {
        // Add logic to send the request message of the transferring tokens 
        // from a source chain to the address on the current chain
    }

    function broadcastAskForFundReq(address from, uint8 sourceChainId, address token, uint256 amount, address to) internal {
        // Add logic to broadcast the request message of the transferring tokens 
        // from a source chain to the address on the current chain to all private pools
    }
    
    function handleAskForFundRes(address from, uint8 sourceChainId, address token, uint256 amount, address to) external {
        // Add logic to handle the response message of asking for fund 
        // from a valid private pool
    }
    
    
}

interface IBridge {
    function sendMessageXChainTo(address token, uint256 amount, uint8 desChainId, address to) external;
    function sendMessageTo(address from, uint8 sourceChainId, address token, uint256 amount, address to) external;
    function broadcastAskForFundReq(address from, uint8 sourceChainId, address token, uint256 amount, address to) internal;
    function handleAskForFundRes(address privatePool) internal;
}
PreviousPrivate Liquidity Pool ContractsNextAtomic Swap Protocol

Last updated 9 months ago

🛠️