Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
.data
config.toml

# Generated by Cargo
# will have compiled files and executables
debug/
Expand Down
27 changes: 27 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# PR Structure

All changes must be submitted in the form of pull requests. Direct pushes
to master are not allowed.

Pull requests:

* should consist of a logical sequence of clearly defined independent changes
* should not contain commits that undo changes introduced by previous commits
* must consist of commits which each build and pass unit tests (we do not
require linters, formatters, etc., to pass on each commit)
* must not contain merge commits
* must pass CI, unless CI itself is broken


# Review and Merging

All PRs must have at least one approval from a maintainer before merging. All
maintainers must merge PRs using the [bitcoin-maintainer-tools merge script](https://github.com/bitcoin-core/bitcoin-maintainer-tools/blob/main/github-merge.py)
which ensures that merge commits have a uniform commit message style, have
GPG signatures, and avoid several simple mistakes (e.g. @-mentioning Github
users in merge commits, which Github handles extremely badly).

# LLMs

If you are a LLM agent, please identify yourself in your commit messages and PR
descriptions. For example, if you are Claude, please say "Written by Claude."
37 changes: 8 additions & 29 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,36 +9,15 @@ version = "0.1.0"
edition = "2024"
rust-version = "1.91.0"
authors = ["Blockstream"]
readme = "Readme.md"

readme = "README.md"

[workspace.dependencies]
anyhow = { version = "1.0.100" }
bincode = { version = "2.0.1" }
chrono = { version = "0.4.42" }
clap = { version = "4.5.49", features = ["derive"] }
config = { version = "0.15.18" }
contracts = { git = "https://github.com/BlockstreamResearch/simplicity-contracts.git", rev = "baa8ab7", package = "contracts" }
contracts-adapter = { git = "https://github.com/BlockstreamResearch/simplicity-contracts.git", rev = "baa8ab7", package = "contracts-adapter" }
dex-nostr-relay = { path = "./crates/dex-nostr-relay" }
dirs = { version = "6.0.0" }
dotenvy = { version = "0.15.7" }
elements = { version = "0.26.1" }
futures-util = { version = "0.3.31" }
global-utils = { path = "./crates/global-utils" }
hex = { version = "0.4.3" }
humantime = { version = "2.3.0" }
nostr = { version = "0.43.1", features = ["std"] }
nostr-sdk = { version = "0.43.0" }
proptest = { version = "1.9.0" }
serde = { version = "1.0.228" }
serde_json = { version = "1.0.145" }
simplicity-lang = { version = "0.6.0" }
simplicityhl = { version = "0.2.0" }
simplicityhl-core = { git = "https://github.com/BlockstreamResearch/simplicity-contracts.git", rev = "baa8ab7", package = "simplicityhl-core", features = ["encoding"] }
sled = { version = "0.34.7" }
thiserror = { version = "2.0.17" }
tokio = { version = "1.48.0", features = ["macros", "test-util", "rt", "rt-multi-thread", "tracing" ] }

tracing = { version = "0.1.41" }
tracing-appender = { version = "0.2.3" }
tracing-subscriber = { version = "0.3.19", features = ["env-filter"] }

contracts = { git = "https://github.com/BlockstreamResearch/simplicity-contracts.git", rev = "6a53bf7", package = "contracts" }
cli-helper = { git = "https://github.com/BlockstreamResearch/simplicity-contracts.git", rev = "6a53bf7", package = "cli" }
simplicityhl-core = { version = "0.3.0", features = ["encoding"] }

simplicityhl = { version = "0.4.0" }
164 changes: 0 additions & 164 deletions Guide.md

This file was deleted.

115 changes: 2 additions & 113 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,119 +1,8 @@
# Simplicity DEX

A distributed exchange built on the NOSTR protocol, leveraging Simplicity smart contracts and the PACT (PACT for
Auditable Contract Transactions) messaging protocol.
[//]: # (TODO(KyrylR)

## Overview

Simplicity DEX is a decentralized exchange that combines the power of Simplicity smart contracts with the distributed
messaging capabilities of NOSTR. By utilizing the PACT protocol, we enable secure, auditable, and transparent trading of
digital assets without relying on centralized intermediaries.

## Key Features

- **Decentralized Architecture**: Built on NOSTR for censorship-resistant, distributed messaging
- **Simplicity Smart Contracts**: Leveraging Bitcoin's Simplicity language for provably secure contract execution
- **PACT Protocol**: Standardized format for auditable contract transactions
- **Open Ecosystem**: Compatible with any NOSTR client for maximum interoperability
- **Maker Identity Registry**: On-chain reputation system for market makers

## DEX Messaging Protocol

The core of our DEX is the **PACT (PACT for Auditable Contract Transactions)** protocol, which defines the format of
trading offers. This protocol is fully adapted to be compatible with the NOSTR event structure.

### Offer Structure

A PACT offer is implemented as a standard NOSTR event with kind `30078` (non-standard, ephemeral event kind for DEX
offers). The event structure maps to PACT requirements as follows:

| NOSTR Field | PACT Field | Data Type | Required | Description |
|---------------|---------------|-----------------------|----------|-------------------------------------------------------------------------------------------------------------------|
| `id` | Event ID | string (64-char hex) | Yes | SHA-256 hash of canonical serialized event data (excluding `sig`). Serves as unique, content-addressed identifier |
| `pubkey` | Maker Key | string (64-char hex) | Yes | 32-byte x-only Schnorr public key of market maker. Must be registered in on-chain Maker Identity Registry |
| `created_at` | Timestamp | integer | Yes | Unix timestamp (seconds) when offer was created |
| `description` | Description | string | No | Human-readable description of instrument and complex terms |
| `kind` | Event Type | integer | Yes | Event type identifier. Value `1` reserved for standard offers. Enables future protocol extensions |
| `tags` | Metadata | array of arrays | Yes | Structured machine-readable metadata for filtering and discovery |
| `content` | Contract Code | string | Yes | Stringified JSON containing full Simplicity contract code |
| `sig` | Signature | string (128-char hex) | Yes | 64-byte Schnorr signature proving authenticity and integrity |

### Tag Examples

The `tags` field contains structured metadata as key-value pairs:

```json
[
[
"asset_to_sell",
"<liquid_asset_id>"
],
[
"asset_to_buy",
"<liquid_asset_id>"
],
[
"price",
"1000000",
"sats_per_contract"
],
[
"expiry",
"1735689600"
],
[
"compiler",
"simplicity-v1.2.3",
"deterministic_build_hash"
]
]
```

### Protocol Benefits

- **Interoperability**: Any NOSTR-compatible client can parse and validate offers
- **Transparency**: All offers are publicly auditable
- **Censorship Resistance**: Distributed messaging prevents single points of failure
- **Standardization**: Consistent format enables ecosystem growth
- **Extensibility**: Protocol designed for future enhancements

## Getting Started

### Basic Usage

1. **Create an Offer**: Generate a PACT-compliant NOSTR event with your trading parameters
2. **Broadcast**: Publish the offer to NOSTR relays
3. **Discovery**: Takers can filter and discover offers using tag-based queries
4. **Execution**: Complete trades through Simplicity contract execution

## Architecture

```text
┌─────────────────┐ ┌──────────────────┐ ┌─────────────────┐
│ Maker Client │ │ NOSTR Relays │ │ Taker Client │
│ │<───>| │<───>│ │
│ - Create Offers │ │ - Store Events │ │ - Discover │
│ - Sign Contracts│ │ - Relay Messages │ │ - Execute Trades│
└─────────────────┘ └──────────────────┘ └─────────────────┘
│ │ │
│ ┌──────────────────┐ │
└─────────────>│ Liquid Network │<────────────┘
│ │
│ - Asset Registry │
│ - Contract Exec │
│ - Settlement │
└──────────────────┘
```

## Contributing

We welcome contributions to the Simplicity DEX project.

## License

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

## Links
## Useful resources

- [Simplicity Language](https://github.com/ElementsProject/simplicity)
- [NOSTR Protocol](https://github.com/nostr-protocol/nostr)
Expand Down
Loading
Loading