Non-custodial β’ Threshold Signatures β’ $0.01 Fee β’ Open Source
π Get Started β’ π Documentation β’ π Security β’ π€ Contribute
- Trustless Swaps: No intermediaries or centralized custody
- Threshold Signatures: ICP canister uses distributed signing (no single private key)
- Automatic Refunds: Timeout protection if counterparty fails to deposit
- Real-time Monitoring: Background watchers track deposits and confirmations
- On-chain Verification: All transactions verifiable on Bitcoin and Solana explorers
- Wallet Integration: Connect Bitcoin (Leather/Xverse/Unisat) and Solana (Phantom/Solflare) wallets
- Low Fees: Only $0.01 per swap transaction
- Modern, professional UI with real-time status updates
- Wallet connection for Bitcoin and Solana
- Swap interface with automatic rate calculation
- Order management and history tracking
- Responsive design optimized for desktop and mobile
- Real-time polling (30s intervals) for order updates
The canister implements:
- Order creation and management
- Bitcoin deposit tracking via ICP Bitcoin API
- Solana deposit tracking via sol-rpc-canister
- Threshold ECDSA signing for BTC transactions
- Threshold Ed25519 signing for SOL transactions
- Timer-based background watchers (polling every 30s)
- Atomic settlement logic
- Timeout-based refund mechanisms (24-hour expiration)
- Internet Computer: Execution layer and escrow coordinator
- Bitcoin Integration: ICP's native Bitcoin API for UTXO tracking
- Solana Integration: sol-rpc-canister for Solana interactions
- Threshold Cryptography: Distributed signing without single keys
- Next.js 15: Modern React framework with App Router
- TailwindCSS v4: Utility-first styling
- shadcn/ui: High-quality component library
- Non-custodial: Funds held in canister with threshold signatures
- Timeout Protection: 24-hour deposit deadline with automatic refunds
- Confirmation Requirements: 6 confirmations for BTC, 32 for Solana
- Open Source: All code auditable and verifiable
- Rate Limiting: Per-swap caps for MVP safety
- No Single Point of Failure: Distributed key generation across subnet nodes
- Node.js 18+
- Rust toolchain with wasm32 target
- DFX (DFINITY SDK) - Install from https://internetcomputer.org/docs/current/developer-docs/setup/install/
- Bitcoin wallet (Leather, Xverse, or Unisat)
- Solana wallet (Phantom or Solflare)
```bash
git clone cd btc-sol-atomic-swap
npm install
rustup target add wasm32-unknown-unknown
dfx start --background --clean
dfx deploy btc_sol_swap_backend
echo "NEXT_PUBLIC_CANISTER_ID=$(dfx canister id btc_sol_swap_backend)" > .env.local echo "NEXT_PUBLIC_IC_HOST=http://localhost:8000" >> .env.local
npm run dev ```
Visit http://localhost:3000 to see the app.
Create a `.env.local` file:
```env
NEXT_PUBLIC_CANISTER_ID=your-canister-id-here NEXT_PUBLIC_IC_HOST=http://localhost:8000
NEXT_PUBLIC_IC_HOST=https://ic0.app
NEXT_PUBLIC_BTC_NETWORK=testnet
NEXT_PUBLIC_SOL_NETWORK=devnet ```
- `create_order()` - Create new swap order with BTC/SOL amounts
- `get_order(order_id)` - Fetch order details and status
- `notify_deposit(order_id, tx_id, asset)` - Notify deposit completion
- `request_refund(order_id)` - Request timeout refund after 24h
- `get_my_orders()` - List all orders for current user
- `get_btc_address()` - Get canister's Bitcoin address
- `get_sol_address()` - Get canister's Solana address
- `check_btc_confirmations()` - Verify Bitcoin confirmations via ICP API
- `check_sol_confirmations()` - Verify Solana confirmations via RPC
- `update_order_confirmations()` - Update order confirmation count
- `settle_order()` - Execute atomic settlement with threshold signatures
- `expire_order()` - Mark order as expired after timeout
Uses `ic_cdk_timers::set_timer_interval()` to poll every 30 seconds:
- Check pending deposits on both chains
- Update confirmation counts
- Trigger settlements when both deposits confirmed
- Process timeout refunds for expired orders
```bash
dfx canister call btc_sol_swap_backend create_order '(record { from_asset = variant { BTC }; to_asset = variant { SOL }; from_amount = 5000000:nat64; to_amount = 162500000000:nat64; })'
dfx canister call btc_sol_swap_backend get_order '("order_1234567890")'
dfx canister call btc_sol_swap_backend get_my_orders '()' ```
- Connect Wallets: User connects Bitcoin and Solana wallets
- Create Order: User specifies BTC amount to swap for SOL
- Deposit Addresses: Canister generates unique deposit addresses using threshold crypto
- Deposit Phase: User deposits BTC to provided address
- Verification: Canister monitors Bitcoin network for confirmations (6 required)
- Settlement: Once confirmed, canister atomically releases SOL to user
- Completion: Transaction complete with $0.01 fee
``` PendingDeposit β AwaitingConfirmations β ReadyToSettle β Settling β Completed β Alternative: PendingDeposit β (24h timeout) β Expired β Refunded ```
Transaction Fee: $0.01 per swap
Breakdown:
- ICP canister cycles: ~$0.005
- Bitcoin network fee: ~$0.003
- Solana network fee: ~$0.002
Fees are automatically deducted from the output amount.
See DEPLOYMENT.md for detailed deployment instructions.
```bash
dfx deploy --network ic btc_sol_swap_backend
echo "NEXT_PUBLIC_CANISTER_ID=$(dfx canister id btc_sol_swap_backend --network ic)" > .env.production echo "NEXT_PUBLIC_IC_HOST=https://ic0.app" >> .env.production
vercel --prod ```
- ARCHITECTURE.md - Detailed system architecture
- DEPLOYMENT.md - Deployment guide
- ICP Bitcoin Integration
- Threshold Signatures
- Order Book: Match makers and takers for better liquidity
- Partial Fills: Split large orders into smaller chunks
- More Assets: Add ETH, USDC, and other tokens
- Lightning Network: Instant BTC settlements
- True HTLC: Peer-to-peer hash-locked contracts
- Governance: DAO for protocol upgrades
- Oracle Integration: Real-time exchange rates
Contributions welcome! Please:
- Fork the repository
- Create a feature branch
- Make your changes
- Submit a pull request
MIT License - Open Source
- GitHub Issues: Report bugs and request features
- Discord: Join our community
- Documentation: Read the full docs
Built with β€οΈ on Internet Computer
Transaction Fee: Only $0.01 per swap | Non-custodial | Trustless | Open Source