Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

481 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

DLC Dev Kit

Crate Documentation Crates.io Total Downloads

A ready-to-go Discreet Log Contract node library built using BDK.

DLC Dev Kit is a self-custodial DLC node in library form. Its central goal is to provide a small, simple, and straightforward interface that enables users to easily set up and run a DLC node with an integrated on-chain wallet. While minimalism is at its core, DDK aims to be sufficiently modular and configurable to be useful for a variety of use cases.

Getting Started

The primary abstraction of the library is the DlcDevKit, which can be retrieved by setting up and configuring a Builder to your liking and calling finish(). DlcDevKit can then be controlled via commands such as start, stop, send_dlc_offer, accept_dlc_offer, etc.

use ddk::builder::{Builder, SeedConfig};
use ddk::logger::{LogLevel, Logger};
use ddk::oracle::kormir::KormirOracleClient;
use ddk::storage::sled::SledStorage;
use ddk::transport::lightning::LightningTransport;
use std::sync::Arc;

type ApplicationDdk = ddk::DlcDevKit<LightningTransport, SledStorage, KormirOracleClient>;

#[tokio::main]
async fn main() -> Result<(), ddk::error::Error> {
    let logger = Arc::new(Logger::console("ddk-example".to_string(), LogLevel::Info));

    let transport = Arc::new(LightningTransport::new(&[0u8; 32], 1776, logger.clone())?);
    let storage = Arc::new(SledStorage::new("/tmp/ddk-example", logger.clone())?);
    let oracle = Arc::new(KormirOracleClient::new("http://localhost:8082", None, logger.clone()).await?);

    let mut builder: Builder<LightningTransport, SledStorage, KormirOracleClient> = Builder::new();
    builder.set_seed_bytes(SeedConfig::Random)?;
    builder.set_esplora_host("https://mutinynet.com/api".to_string());
    builder.set_transport(transport);
    builder.set_storage(storage);
    builder.set_oracle(oracle);
    builder.set_logger(logger);

    let ddk: ApplicationDdk = builder.finish().await?;

    ddk.start()?;

    // ... open contracts, accept offers, etc.

    ddk.stop()?;
    Ok(())
}

Modularity

DDK is designed with a pluggable architecture, allowing you to choose or implement your own components:

  • Transport: Communication layer for DLC messages between peers. Implementations include Lightning Network gossip and Nostr protocol messaging.
  • Storage: Persistence backend for contracts and wallet data. Implementations include Sled (embedded) and PostgreSQL.
  • Oracle: External data source for contract attestations. Implementations include HTTP and Nostr-based oracle clients.

You can create a custom DDK instance by implementing the required traits defined in ddk/src/lib.rs.

Crates

Crate Description
ddk The main DDK library with an integrated BDK wallet for building DLC applications. Crate
ddk-node A ready-to-go DLC node with a gRPC server and accompanying CLI. Crate
ddk-payouts Functions to build payout curves for DLC contracts. Crate
ddk-manager Core DLC contract creation and state machine management. Crate
ddk-dlc Low-level DLC transaction creation, signing, and verification. Crate
ddk-messages Serialization and structs for the DLC protocol messages. Crate
ddk-trie Data structures for storage and retrieval of numerical DLCs. Crate
kormir Oracle implementation for creating and attesting to DLC events. Crate

Development

Tests

Tests need nothing running beforehand:

$ cargo test --all-features

Each test binary starts and tears down its own regtest bitcoind, electrs (serving the esplora HTTP API), PostgreSQL server, and nostr relay on ephemeral ports. The bitcoind and electrs executables are downloaded once at build time by the ddk-testenv crate's dependencies; PostgreSQL is fetched on first use and cached under ~/.theseus/postgresql.

The long-running integration tests are marked #[ignore]; run them with:

$ NB_CONFIRMATIONS=6 cargo test --all-features -- --ignored

NB_CONFIRMATIONS is not optional here. It sets the depth at which the manager treats a contract as confirmed, and the cooperative close tests assume 6; at the default of 3 they fail.

Running a node

A bitcoin node, esplora server, and oracle server are required to run DDK (as opposed to testing it). Developers can spin up a development environment with the justfile provided.

$ cp .env.sample .env
$ just deps

To run your own Kormir oracle server for development, see the Kormir repository.

See the ddk-node README for more development information.

Language Bindings

For Node.js and React Native bindings, see ddk-ffi.

Resources

License

This project is licensed under the MIT License.

About

application tooling for dlc's 🌊

Topics

Resources

Stars

Watchers

Forks

Releases

Used by

Contributors

Languages