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
1,424 changes: 1,290 additions & 134 deletions Cargo.lock

Large diffs are not rendered by default.

12 changes: 7 additions & 5 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,18 @@ edition = "2024"
multiple_crate_versions = "allow"

[workspace.dependencies]
ring = "0.17.14"
simplex-core = { path = "./crates/core" }

bincode = { version = "2.0.1", features = ["serde"] }
ring = { version = "0.17.14" }
sha2 = { version = "0.10.9", features = ["compress"] }

hex = "0.4.3"
hex = { version = "0.4.3" }
tracing = { version = "0.1.41" }

minreq = { version = "2.14.1", features = ["https", "json-using-serde"]}
minreq = { version = "2.14.1", features = ["https", "json-using-serde"] }

simplicityhl = { version = "0.4.0" }
simplicityhl-core = { version = "0.4.2", features = ["encoding"] }
simplicityhl = { git = "https://github.com/ikripaka/SimplicityHL/", branch = "feature/rich-params" }

[patch.crates-io]
simplicity-sys = { git = "https://github.com/BlockstreamResearch/rust-simplicity", tag = "simplicity-sys-0.6.1" }
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
# Simplex SDK

This collection of useful crates provides useful utilities for working with Simplicity on Elements.

- `simplex-macro` - provides common macros related utitiles which would provide and thrive DX.
- `simplex-core` - provides useful utilities.
- `simplex-cli` - provides common cli interface and ability to setup your contract development environment.

## License

Expand Down
23 changes: 10 additions & 13 deletions crates/cli/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[package]
name = "cli"
name = "simplex-cli"
version = "0.1.0"
edition = "2024"
description = "Simplicity helper CLI for Liquid testnet"
Expand All @@ -9,23 +9,20 @@ publish = false

[[bin]]
name = "simplex"
path = "src/main.rs"
path = "src/bin/main.rs"

[lints]
workspace = true

[dependencies]
anyhow = "1"
thiserror = "2"

sled = "0.34.7"

dotenvy = "0.15"
clap = { version = "4.5", features = ["derive"] }
clap = { version = "4", features = ["derive", "env"] }
tokio = { version = "1", features = ["rt-multi-thread", "macros"] }
config = { version = "0.15.16", default-features = true }

minreq = { version = "2.14", features = ["https"] }
tokio = { version = "1", features = ["rt-multi-thread", "macros", "fs", "sync"] }

hex = { workspace = true }
simplex-simplicity = { path = "../sdk" }
toml = { version = "0.9.8" }
serde = { version = "1", features = ["derive"] }
simplicityhl = { workspace = true }
tracing = { version = "0.1.44" }
thiserror = { version = "2.0.18" }
tracing-subscriber = { version = "0.3.22", features = ["env-filter"] }
11 changes: 11 additions & 0 deletions crates/cli/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Simplex-CLI

CLI instrument to support easy building and creation of contracts on SimplicityHL.

## License

Dual-licensed under either of:
- Apache License, Version 2.0 (Apache-2.0)
- MIT license (MIT)

at your option.
14 changes: 14 additions & 0 deletions crates/cli/src/bin/main.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#![warn(clippy::all, clippy::pedantic)]

use clap::Parser;

#[tokio::main]
async fn main() -> anyhow::Result<()> {
let _ = dotenvy::dotenv();

simplex_cli::logging::init();

Box::pin(simplex_cli::cli::Cli::parse().run()).await?;

Ok(())
}
7 changes: 7 additions & 0 deletions crates/cli/src/cli/commands.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
use clap::Subcommand;

#[derive(Debug, Subcommand)]
pub enum Command {
/// Show current configuration
Config,
}
43 changes: 43 additions & 0 deletions crates/cli/src/cli/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
pub mod commands;

use crate::error::Error;

use crate::config::{Config, default_config_path};

use clap::Parser;
use std::path::PathBuf;

pub use commands::Command;

#[derive(Debug, Parser)]
#[command(name = "simplicity-dex")]
#[command(about = "CLI for Simplicity Options trading on Liquid")]
pub struct Cli {
#[arg(short, long, default_value_os_t = default_config_path(), env = "SIMPLEX_CONFIG")]
pub config: PathBuf,

#[command(subcommand)]
pub command: Command,
}

impl Cli {
#[must_use]
pub fn load_config(&self) -> Config {
Config::load_or_default(&self.config)
}

/// Runs the CLI command.
///
/// # Errors
/// Returns an error if the command execution fails.
pub async fn run(&self) -> Result<(), Error> {
let config = self.load_config();

match &self.command {
Command::Config => {
println!("{config:#?}");
Ok(())
}
}
}
}
75 changes: 75 additions & 0 deletions crates/cli/src/config.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
use crate::error::Error;
use serde::{Deserialize, Serialize};
use simplicityhl::elements::AddressParams;
use std::path::{Path, PathBuf};

const DEFAULT_CONFIG_PATH: &str = "config.toml";

#[derive(Debug, Clone, Serialize, Deserialize, Default)]
pub struct Config {
#[serde(default)]
pub network: NetworkConfig,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct NetworkConfig {
#[serde(default = "default_network")]
pub name: NetworkName,
}

#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize, Default)]
#[serde(rename_all = "lowercase")]
pub enum NetworkName {
#[default]
Testnet,
Mainnet,
}

impl NetworkName {
#[must_use]
pub const fn address_params(self) -> &'static AddressParams {
match self {
Self::Testnet => &AddressParams::LIQUID_TESTNET,
Self::Mainnet => &AddressParams::LIQUID,
}
}
}

impl Config {
/// Loads configuration from the specified path.
///
/// # Errors
/// Returns `Error::Io` if the file cannot be read, or `Error::TomlParse` if the content
/// is not valid TOML.
pub fn load(path: impl AsRef<Path>) -> Result<Self, Error> {
let content = std::fs::read_to_string(path)?;
let config: Self = toml::from_str(&content)?;
Ok(config)
}

pub fn load_or_default(path: impl AsRef<Path>) -> Self {
Self::load(path).unwrap_or_default()
}

#[must_use]
pub const fn address_params(&self) -> &'static AddressParams {
self.network.name.address_params()
}
}

impl Default for NetworkConfig {
fn default() -> Self {
Self {
name: default_network(),
}
}
}

const fn default_network() -> NetworkName {
NetworkName::Testnet
}

#[must_use]
pub fn default_config_path() -> PathBuf {
PathBuf::from(DEFAULT_CONFIG_PATH)
}
25 changes: 25 additions & 0 deletions crates/cli/src/error.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
use simplicityhl::simplicity::hex::HexToArrayError;

/// Errors that can occur when using the Simplex CLI.
#[derive(thiserror::Error, Debug)]
pub enum Error {
/// Errors related to configuration loading or validation.
#[error("Configuration error: {0}")]
Config(String),

/// Standard I/O errors.
#[error("IO error: {0}")]
Io(#[from] std::io::Error),

/// Errors when parsing TOML configuration files.
#[error("TOML parse error: {0}")]
TomlParse(#[from] toml::de::Error),

/// Errors related to Partially Signed Elements Transactions (PSET).
#[error("PSET error: {0}")]
Pset(#[from] simplicityhl::elements::pset::Error),

/// Errors when converting hex strings to byte arrays.
#[error("Hex to array error: {0}")]
HexToArray(#[from] HexToArrayError),
}
4 changes: 4 additions & 0 deletions crates/cli/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
pub mod cli;
pub mod config;
pub mod error;
pub mod logging;
10 changes: 10 additions & 0 deletions crates/cli/src/logging.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
use tracing_subscriber::{EnvFilter, fmt, prelude::*};

pub fn init() {
let filter = EnvFilter::try_from_default_env().unwrap_or_else(|_| EnvFilter::new("info"));

tracing_subscriber::registry()
.with(fmt::layer().with_target(true))
.with(filter)
.init();
}
3 changes: 0 additions & 3 deletions crates/cli/src/main.rs

This file was deleted.

12 changes: 4 additions & 8 deletions crates/sdk/Cargo.toml → crates/core/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[package]
name = "simplex-simplicity"
name = "simplex-core"
version = "0.1.0"
edition = "2024"
rust-version = "1.90"
Expand All @@ -19,14 +19,10 @@ workspace = true
encoding = ["dep:bincode"]

[dependencies]
thiserror = "2"

bincode = { version = "2.0.1", optional = true }

thiserror = { version = "2.0.18" }
bincode = { workspace = true, optional = true }
sha2 = { workspace = true }

hex = { workspace = true }

simplicityhl = { workspace = true }

minreq = { workspace = true }
serde = { version = "1.0.228" }
20 changes: 20 additions & 0 deletions crates/core/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Simpelex HL Core

This crate provides useful utilities for working with Simplicity on Elements.

- `blinder.rs` — derives deterministic blinder keypair from a "public secret"
- `constants.rs` — Liquid network constants (policy asset IDs, genesis hashes)
- `explorer.rs` — explorer API utilities (behind `explorer` feature)
- `runner.rs` — program execution helpers with logging
- `scripts.rs` — P2TR address creation, Taproot control block, and asset entropy utilities
- `lib.rs` — P2PK program helpers and transaction finalization

Consider this more like a test helper tool rather than a production-ready version.

## License

Dual-licensed under either of:
- Apache License, Version 2.0 (Apache-2.0)
- MIT license (MIT)

at your option.
Loading
Loading