Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
46 commits
Select commit Hold shift + click to select a range
b75b09e
Update README.md
ikripaka Nov 19, 2025
6e08581
remove readmes
ikripaka Nov 19, 2025
be70bb1
add only one Readme.md
ikripaka Nov 19, 2025
73bee4a
rename binary to simplicity-dex, set name of package the same as folder
ikripaka Nov 19, 2025
64acc27
move code from previous pr, make it compile
ikripaka Nov 20, 2025
706cf63
update contract adapter version
ikripaka Nov 20, 2025
6296b8e
change config to parse
ikripaka Nov 20, 2025
a374c8e
correct config interaction and example.toml
ikripaka Nov 21, 2025
8780528
correct commands and fields about
ikripaka Nov 21, 2025
8557959
add cache logic for storing dcd_args
ikripaka Nov 21, 2025
cd8808e
Minor fixes. Linting.
KyrylR Nov 21, 2025
cfb15bc
Fixed config parsing.
KyrylR Nov 21, 2025
d87ad72
Deleted unused CliConfigArgs structure
KyrylR Nov 21, 2025
ed1a637
Added clippy::pedantic.
KyrylR Nov 21, 2025
f864a9e
Fixed some warnings
KyrylR Nov 21, 2025
954830f
Added TODOs
KyrylR Nov 21, 2025
299e400
add functionality of replying to events by default in dcd commands
ikripaka Nov 21, 2025
3102af6
Merge remote-tracking branch 'origin/feature/contract_impl' into feat…
ikripaka Nov 21, 2025
8981e90
fix pedantic lints
ikripaka Nov 24, 2025
9c770c2
remove unused store initialization in contract handlers
ikripaka Nov 24, 2025
cc727ee
change utxo defining from Vec to separate args
ikripaka Nov 24, 2025
a3d7d16
change broadcast field on offline
ikripaka Nov 24, 2025
9d078bd
move DcdArgs retrieval to events
ikripaka Nov 24, 2025
6616de2
move MAKER_EXPIRATION_TIME into config and expose as CLI option
zahorodnyi Nov 24, 2025
8024e97
comment expiration tag, remove done todo
ikripaka Nov 25, 2025
ed5120a
fix test
ikripaka Nov 25, 2025
ed1f435
add seed_hex and maker_expiration_time to config parsing
zahorodnyi Nov 25, 2025
9503f02
code improvements
ikripaka Nov 26, 2025
db3fa6f
Update seed_hex parsing
zahorodnyi Nov 26, 2025
515dfd0
Delete settings.rs and fix all dependencies
zahorodnyi Nov 26, 2025
0e1999e
Clean up code
zahorodnyi Nov 26, 2025
e3dfd9d
Merge branch 'refactor/config_system' into feature/contract_impl and …
zahorodnyi Nov 27, 2025
8550e19
Fix CI: delete unused import from test
zahorodnyi Nov 27, 2025
56c7bc4
Fix CI: fmt
zahorodnyi Nov 27, 2025
9e8aca3
use tokio::spawn_blocking for sync blocking context
ikripaka Nov 27, 2025
510ef84
Minor fixes
KyrylR Nov 27, 2025
8819905
cli fixes
ikripaka Nov 27, 2025
abc643a
fix ci
ikripaka Nov 27, 2025
c787035
fix ci 2
ikripaka Nov 27, 2025
cd0201a
Make maker_expiration_time tag optional (draft solution)
zahorodnyi Nov 27, 2025
aad3bd9
add draft guide, use full names in cli params
ikripaka Nov 28, 2025
92eb7d5
update guide
ikripaka Nov 28, 2025
19dce7f
Make Seed hex optional, fix bugs
zahorodnyi Nov 28, 2025
51c36d8
Merge remote-tracking branch 'blockstream/feature/contract_impl' into…
zahorodnyi Nov 29, 2025
7a2ec0c
fix bug with incorrect hex parsing
ikripaka Dec 1, 2025
7d5517e
add tests for config parsing
ikripaka Dec 1, 2025
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
7 changes: 6 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,9 @@ dist/
**/.DS_Store

# Logs
logs/*
logs/*

/.simplicity-dex.config.toml
/.cache
taker/
simplicity-dex
7 changes: 7 additions & 0 deletions .simplicity-dex.example/.simplicity-dex.config.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Keypair can be generated here: https://start.nostr.net/
nostr_keypair = "keypair..."
relays = [
"wss://relay.damus.io",
"wss://nostr.wine/",
]
seed_hex = "your_hex_value"
1 change: 0 additions & 1 deletion .simplicity-dex.example/keypair.txt

This file was deleted.

1 change: 0 additions & 1 deletion .simplicity-dex.example/relays.txt

This file was deleted.

29 changes: 22 additions & 7 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,23 +9,38 @@ 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"] }
dirs = {version = "6.0.0"}
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" }
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" }
dex-nostr-relay = { path = "./crates/dex-nostr-relay"}
serde = { version = "1.0.228", features = ["derive"] }
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" }
tempfile = { version = "3.23.0" }
thiserror = { version = "2.0.17" }
tokio = { version = "1.48.0", features = ["macros", "test-util", "rt", "rt-multi-thread"] }
tokio = { version = "1.48.0", features = ["macros", "test-util", "rt", "rt-multi-thread", "tracing" ] }
toml = { version = "0.9.8" }
tracing = { version = "0.1.41" }
tracing-appender = { version = "0.2.3" }
tracing-subscriber = { version = "0.3.19", features = ["env-filter"] }
url = { version = "2.5.7" }
164 changes: 164 additions & 0 deletions Guide.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,164 @@
# Simplicity DEX — Developer Guide

This short guide helps contributors understand, build, test and extend the project. It focuses on practical commands and
the patterns used across crates (not exhaustive; follow Rust and crate docs for deeper dives).

## Project layout

- crates/dex-cli — command line client and UX helpers
- crates/dex-nostr-relay — relay logic, event parsing and storage
- crates/global-utils — other helpers

## Prerequisites

- Install Rust
- Create your nostr keypair (Can be generated here: https://start.nostr.net/)

## Quick start

1. Build:
- cargo build -r
2. Run CLI (local dev):
- `cargo build -r`
- `mkdir -p ./demo`
- `mv ./target/release/simplicity-dex ./demo/simplicity-dex`
- `cp ./.simplicity-dex.example/.simplicity-dex.config.toml ./demo/.simplicity-dex.config.toml`
- `echo SEED_HEX=ffff0123456789abcdef0123456789abcdef0123456789abcdef0123456789ab > ./demo/.env`
3. Insert your valid nostr keypair into `.simplicity-dex.config.toml`

## Commands example execution

Overall trading for dcd contracts can be split in two sides: taker and maker.

Maker and Taker responsible for taking such steps:

1) Maker initializes contract in Liquid;
2) Maker funds contract with collateral and settlement tokens. (by now for test **collateral** = LBTC-Testnet, **settlement** = minted token from scratch)
3) Taker funds contract with collateral tokens and takes contract parameters from already discovered maker event_id.
4) Maker now can make:
* Early collateral termination
* Early settlement termination
5) Taker now can make:
* Early termination
6) After `settlement-height` both maker and taker can use settlement exit to receive their tokens (collateral or settlement) depending on the settlement token price, which is signed with oracle.

1. Create your own contract with your values. For example can be taken

* `taker-funding-start-time` 1764328373 (timestamp can be taken from https://www.epochconverter.com/)
* `taker-funding-end-time` 1764358373 (Block time when taker funding period ends)
* `contract-expiry-time` 1764359373 (Block time when contract expires)
* `early-termination-end-time` 1764359373 (Block time when early termination is no longer allowed)
* `settlement-height` 2169368 (Block height at which oracle price is attested)
* `principal-collateral-amount` 2000 (Base collateral amount)
* `incentive-basis-points` 1000 (Incentive in basis points (1 bp = 0.01%))
* `filler-per-principal-collateral` 100 (Filler token ratio)
* `strike-price` 25 (Oracle strike price for settlement)
* `settlement-asset-entropy` `0ffa97b7ee6fcaac30b0c04803726f13c5176af59596874a3a770cbfd2a8d183` (Asset entropy (hex) for settlement)
* `oracle-pubkey` `757f7c05d2d8f92ab37b880710491222a0d22b66be83ae68ff75cc6cb15dd2eb` (`./simplicity-dex helpers address --account-index 5`)

Actual command in cli:
```bash
./simplicity-dex maker init
--utxo-1 <FIRST_LBTC_UTXO>
--utxo-2 <SECOND_LBTC_UTXO>
--utxo-3 <THIRD_LBTC_UTXO>
--taker-funding-start-time <TAKER_FUNDING_START_TIME>
--taker-funding-end-time <TAKER_FUNDING_END_TIME>
--contract-expiry-time <CONTRACT_EXPIRY_TIME>
--early-termination-end-time <EARLY_TERMINATION_END_TIME>
--settlement-height <SETTLEMENT_HEIGHT>
--principal-collateral-amount <PRINCIPAL_COLLATERAL_AMOUNT>
--incentive-basis-points <INCENTIVE_BASIS_POINTS>
--filler-per-principal-collateral <FILLER_PER_PRINCIPAL_COLLATERAL>
--strike-price <STRIKE_PRICE>
--settlement-asset-entropy <SETTLEMENT_ASSET_ENTROPY>
--oracle-pubkey <ORACLE_PUBLIC_KEY>
```

2. Maker fund cli command:
```bash
./simplicity-dex maker fund
--filler-utxo <FILLER_TOKEN_UTXO>
--grant-coll-utxo <GRANTOR_COLLATERAL_TOKEN_UTXO>
--grant-settl-utxo <GRANTOR_SETTLEMENT_TOKEN_UTXO>
--settl-asset-utxo <SETTLEMENT_ASSET_UTXO>
--fee-utxo <FEE_UTXO>
--taproot-pubkey-gen <DCD_TAPROOT_PUBKEY_GEN>
```

3. Taker has to fund

```bash
./simplicity-dex taker fund
--filler-utxo <FILLER_TOKEN_UTXO>
--collateral-utxo <COLLATERAL_TOKEN_UTXO>
--collateral-amount-deposit <COLLATERAL_AMOUNT_TO_DEPOSIT>
--maker-order-event-id <MAKER_ORDER_EVENT_ID>
```

4. Taker can wait for specific `settlement-height` and gracefully exit contract:
```bash
./simplicity-dex taker settlement
--filler-utxo <FILLER_TOKEN_UTXO>
--asset-utxo <ASSET_UTXO>
--fee-utxo <FEE_UTXO>
--filler-to-burn <FILLER_AMOUNT_TO_BURN>
--price-now <PRICE_AT_CURRENT_BLOCK_HEIGHT>
--oracle-sign <ORACLE_SIGNATURE>
--maker-order-event-id <MAKER_ORDER_EVENT_ID>
```

5. Maker can wait for specific `settlement-height` and gracefully exit contract:
```bash
./simplicity-dex maker settlement
--grant-collateral-utxo <GRANTOR_COLLATERAL_TOKEN_UTXO>
--grant-settlement-utxo <GRANTOR_SETTLEMENT_TOKEN_UTXO>
--asset-utxo <ASSET_UTXO>
--fee-utxo <FEE_UTXO>
--grantor-amount-burn <GRANTOR_AMOUNT_TO_BURN>
--price-now <PRICE_AT_CURRENT_BLOCK_HEIGHT>
--oracle-sign <ORACLE_SIGNATURE>
--maker-order-event-id <MAKER_ORDER_EVENT_ID>
```

* Maker or Taker depending on the can use Merge(2/3/4) command to merge collateral tokens.
This is made exactly for combining outs into one to eliminate execution of contract with usage of little fragments
```bash
./simplicity-dex helpers merge-tokens4
--token-utxo-1 <TOKEN_UTXO_1>
--token-utxo-2 <TOKEN_UTXO_2>
--token-utxo-3 <TOKEN_UTXO_3>
--token-utxo-4 <TOKEN_UTXO_4>
--fee-utxo <FEE_UTXO>
--maker-order-event-id <MAKER_ORDER_EVENT_ID>
```

* For early collateral termination Maker can use command:
```bash
./simplicity-dex maker termination-collateral
--grantor-collateral-utxo <GRANTOR_COLLATERAL_TOKEN_UTXO>
--collateral-utxo <COLLATERAL_TOKEN_UTXO>
--fee-utxo <FEE_UTXO>
--grantor-collateral-burn <GRANTOR_COLLATERAL_AMOUNT_TO_BURN>
--maker-order-event-id <MAKER_ORDER_EVENT_ID>
```

* For early settlement termination Maker can use command:
```bash
./simplicity-dex maker termination-settlement
--settlement-asset-utxo <SETTLEMENT_ASSET_UTXO>
--grantor-settlement-utxo <GRANTOR_SETTLEMENT_TOKEN_UTXO>
--fee-utxo <FEE_UTXO>
--grantor-settlement-amount-burn <GRANTOR_SETTLEMENT_AMOUNT_TO_BURN>
--maker-order-event-id <MAKER_ORDER_EVENT_ID>
```

* For early termination Taker can use command:
```bash
./simplicity-dex taker termination-early
--filler-utxo <FILLER_TOKEN_UTXO>
--collateral-utxo <COLLATERAL_TOKEN_UTXO>
--fee-utxo <FEE_UTXO>
--filler-to-return <FILLER_TOKEN_AMOUNT_TO_RETURN>
--maker-order-event-id <MAKER_ORDER_EVENT_ID
```
27 changes: 0 additions & 27 deletions Makefile

This file was deleted.

102 changes: 0 additions & 102 deletions README.md

This file was deleted.

2 changes: 1 addition & 1 deletion Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -122,4 +122,4 @@ This project is licensed under the MIT License - see the LICENSE file for detail
## Disclaimer

This software is experimental and should be used with caution. Always verify contract code and understand the risks
before trading.
before trading.
Loading