Skip to content

darkswapfoundation/darkswap

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

18 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

DarkSwap

Testing

DarkSwap includes comprehensive tests for all components of the application. This ensures that the code is reliable and functions as expected.

Running Tests

To run all tests, use the following command:

./run-tests.sh

This will run both unit tests and end-to-end tests.

Unit Tests

Unit tests are written using Jest and test individual components of the application. To run only the unit tests:

npm test

End-to-End Tests

End-to-end tests are written using Playwright and test the application as a whole. To run only the end-to-end tests:

npm run test:e2e

Test Coverage

The tests cover all major components of the application:

  • Bitcoin transaction functionality
  • Runes protocol integration
  • Alkanes protocol integration
  • P2P orderbook synchronization
  • WebRTC functionality
  • WebRTC wallet integration

Debugging Tests

If you encounter issues with the tests, you can run them in debug mode:

# Debug unit tests
npx jest --config=jest.config.js --debug

# Debug end-to-end tests
npx playwright test tests/e2e/trading.test.js --debug

DarkSwap is a decentralized peer-to-peer trading platform for Bitcoin, runes, and alkanes. It enables trustless trading without requiring a central server or authority.

Features

  • P2P Networking: Decentralized peer-to-peer network for order discovery and matching
  • WebRTC Support: Browser compatibility for web-based trading
  • Circuit Relay: NAT traversal for peers behind firewalls
  • Orderbook Management: Decentralized orderbook for trading pairs
  • PSBT-Based Trading: Secure trade execution using PSBTs
  • Runes and Alkanes Support: Trading of Bitcoin-based assets
  • Web Interface: User-friendly web interface for trading

Architecture

DarkSwap consists of the following components:

  • DarkSwap Support: Shared code and protobuf definitions
  • DarkSwap P2P: Core P2P networking library with WebRTC support
  • DarkSwap SDK: Core library for building decentralized trading applications
  • DarkSwap Web-Sys: WebAssembly bindings for browser integration
  • DarkSwap Lib: TypeScript library for web applications
  • DarkSwap Relay: Circuit relay server for NAT traversal
  • DarkSwap Daemon: Background service for hosting an orderbook
  • DarkSwap CLI: Command-line interface for interacting with the SDK
  • DarkSwap Web: Web interface for trading

Getting Started

Prerequisites

  • Rust 1.70.0 or later
  • Node.js 18.0.0 or later
  • Yarn 1.22.0 or later

Building from Source

  1. Clone the repository:
git clone https://github.com/darkswap/darkswap.git
cd darkswap
  1. Build all components:
./build.sh --all
  1. Build specific components:
./build.sh --sdk --daemon --web

Running the CLI

cd darkswap-cli
cargo run -- --help

Starting the Daemon

cd darkswap-daemon
cargo run

Running the Web Interface

cd web
yarn dev

Usage

Creating an Order

darkswap-cli create-order --base-asset BTC --quote-asset "RUNE:test_rune" --side buy --amount 1.0 --price 50000

Taking an Order

darkswap-cli take-order --order-id <order_id> --amount 0.5

Listing Orders

darkswap-cli list-orders --base-asset BTC --quote-asset "RUNE:test_rune"

Getting Market Data

darkswap-cli market --base-asset BTC --quote-asset "RUNE:test_rune"

Development

Project Structure

darkswap/
├── darkswap-support/    # Shared code and protobuf definitions
├── darkswap-p2p/        # Core P2P networking library
├── darkswap-sdk/        # Core SDK
├── darkswap-web-sys/    # WebAssembly bindings
├── darkswap-lib/        # TypeScript library
├── darkswap-relay/      # Circuit relay server
├── darkswap-daemon/     # Background service
├── darkswap-cli/        # Command-line interface
├── web/                 # Web interface
├── reference/           # Reference documentation
└── memory-bank/         # Project documentation

Component Relationships

┌───────────────────────────────────────────────────────────────────────────┐
│                          darkswap-support                                 │
│                      (Protobuf & Shared Code)                             │
└───────────────────────────────────────────────────────────────────────────┘
                 ▲                                      ▲
                 │                                      │
                 │                                      │
┌────────────────┴─────────────────┐      ┌─────────────┴─────────────────┐
│                                  │      │                               │
│           darkswap-p2p           │      │         darkswap-web-sys      │
│      (Rust P2P Networking)       │      │        (WASM Bindings)        │
└────────────────┬─────────────────┘      └─────────────┬─────────────────┘
                 ▲                                      ▲
                 │                                      │
                 │                                      │
┌────────────────┴─────────────────┐      ┌─────────────┴─────────────────┐
│                                  │      │                               │
│           darkswap-sdk           │      │          darkswap-lib         │
│        (Rust Trading SDK)        │      │      (TypeScript Library)     │
└────────────────┬─────────────────┘      └─────────────┬─────────────────┘
                 ▲                                      ▲
                 │                                      │
                 │                                      │
┌────────────────┴─────────┐  ┌───────────┐  ┌─────────┴─────────────────┐
│                          │  │           │  │                           │
│      darkswap-relay      │  │darkswap-  │  │       darkswap-app        │
│    (Circuit Relay)       │  │ daemon    │  │     (Web Interface)       │
└──────────────────────────┘  └───────────┘  └───────────────────────────┘

Running Tests

cd darkswap-sdk
cargo test

Building Documentation

cd darkswap-sdk
cargo doc --open

Current Status

The project is currently in Phase 1 of development, focusing on the core P2P infrastructure. Recent achievements include:

  1. Fixed WebSocket event handling in handlers.rs
  2. Verified OrderId import from orderbook module in api.rs
  3. Implemented core SDK with P2P networking, orderbook management, and trade execution
  4. Added WebRTC transport for browser compatibility
  5. Implemented PSBT-based trade execution for secure atomic swaps
  6. Added Bitcoin wallet integration

Next steps include:

  1. Completing the runes and alkanes support
  2. Implementing the WebAssembly bindings
  3. Developing the TypeScript library
  4. Setting up the relay server

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

License

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

Acknowledgments

  • Subfrost for the circuit relay implementation
  • PintSwap for the P2P orderbook and trading functionality
  • rust-libp2p for the P2P networking library
  • bitcoin for the Bitcoin library

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published