Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
74 commits
Select commit Hold shift + click to select a range
0274554
chore(workspace): hoist [workspace.dependencies] + [workspace.lints]
brunota20 Jun 25, 2026
be1972f
feat(nexum-engine): migrate CLI from hand-rolled parser to clap
brunota20 Jun 25, 2026
0b37c70
docs(07-rpc-namespace-design): mark allowlist enforcement as future d…
brunota20 Jun 25, 2026
b2fe663
chore(deps): pull cowprotocol, alloy, redb, reqwest, tracing
brunota20 Jun 1, 2026
2966262
runtime: implement cow-api, chain, local-store host backends
brunota20 Jun 1, 2026
be7a3b1
runtime: multi-module supervisor + block/log event loop
brunota20 Jun 1, 2026
9ebbeea
feat(supervisor): apply ADR-0001/0003/0005/0016 and trap-based module…
brunota20 Jun 9, 2026
473c95f
feat(supervisor): add fuel + memory limits per module store (BLEU-818)
brunota20 Jun 9, 2026
ad3d798
docs: rename nexum.toml -> module.toml in example, justfile, and READ…
brunota20 Jun 10, 2026
62c5811
test: fill host backend test gaps — manifest parsing, cow-api, provid…
brunota20 Jun 10, 2026
881965d
test: E2E supervisor tests + fix wit_import_to_cap to skip type-only …
brunota20 Jun 10, 2026
7d1c0b6
style: apply rust-idiomatic rules (em-dashes, #[from] Orderbook, unus…
brunota20 Jun 10, 2026
605b1d9
review: apply lgahdl feedback on PR #9 (+ rebase PR #8 fixes)
brunota20 Jun 12, 2026
aca680d
refactor(manifest): split into types/load/capabilities/error submodules
brunota20 Jun 13, 2026
0ff9ba9
refactor(main): extract host impls + CLI + event loop + limits
brunota20 Jun 13, 2026
33b4d56
refactor: move large #[cfg(test)] modules to sibling files
brunota20 Jun 13, 2026
8c848dd
chore(deps): patch cowprotocol to bleu/cow-rs main (post-alpha.3)
brunota20 Jun 1, 2026
edbafca
docs(adr): add 0001-0007 capturing engine and CoW architecture decisions
brunota20 Jun 2, 2026
c21378e
docs(adr): unwrap hard-wrapped paragraphs to single line each
brunota20 Jun 2, 2026
e5010c4
docs(adr): revise CoW design and reorder ADRs (0001-0008)
brunota20 Jun 3, 2026
821db88
fix(docs): reviewed ADRs by bleu
brunota20 Jun 3, 2026
e8744b5
fix(docs): revised ADRs and diagrams
brunota20 Jun 8, 2026
1ee0ca9
chore(deps): bump cowprotocol patch to bleu/cow-rs main (BLEU-822 + B…
brunota20 Jun 15, 2026
8649d59
feat(modules): module.toml for twap-monitor + ethflow-watcher (BLEU-834)
brunota20 Jun 15, 2026
dd783fc
review: address jeffersonBastos feedback on PR #54 (BLEU-834 manifests)
brunota20 Jun 22, 2026
568c7ea
chore(rust-idiomatic): M2 compliance pass (filtered from M4/M5 compli…
brunota20 Jun 23, 2026
895d78c
docs(nexum-engine): fix rustdoc intra-doc links after pub(crate) sweep
brunota20 Jun 25, 2026
0d39d89
chore(nexum-engine): derive strum::IntoStaticStr on error enums
brunota20 Jun 25, 2026
61dbd4b
refactor(local-store): extract `local_store_err` map closure helper
brunota20 Jun 25, 2026
8f0a4fe
fix(supervisor): emit nexum.toml deprecation via tracing::warn!
brunota20 Jun 25, 2026
ee72dce
test(nexum-engine): cover untested error variants and concurrent acce…
jean-neiverth Jun 29, 2026
21204ba
Merge pull request #88 from bleu/test/m2-error-variant-coverage
jean-neiverth Jun 29, 2026
353347c
feat(twap-monitor): workspace + skeleton (BLEU-825)
brunota20 Jun 15, 2026
3f55cec
feat(twap-monitor): index ConditionalOrderCreated → local-store (BLEU…
brunota20 Jun 15, 2026
bb3f918
feat(twap-monitor): eth_call poll path + PollOutcome decoder (BLEU-827)
brunota20 Jun 15, 2026
aa1d08b
feat(twap-monitor): build OrderCreation and submit via cow-api (BLEU-…
brunota20 Jun 15, 2026
3537c2a
feat(twap-monitor): wire OrderPostError retry_hint on submit (BLEU-829)
brunota20 Jun 15, 2026
2dbe22e
feat(twap-monitor): PollOutcome lifecycle dispatch (BLEU-830)
brunota20 Jun 15, 2026
310bc83
feat(ethflow-watcher): workspace + skeleton (BLEU-831)
brunota20 Jun 15, 2026
5b62995
feat(ethflow-watcher): decode CoWSwapEthFlow OrderPlacement (BLEU-832)
brunota20 Jun 15, 2026
d9fb04a
feat(ethflow-watcher): build OrderCreation, submit, apply retry_hint …
brunota20 Jun 15, 2026
a782382
fix(ethflow-watcher): idempotency guard on re-delivered placements
brunota20 Jun 15, 2026
b5d59ec
feat(shepherd-sdk): workspace + skeleton (BLEU-835)
brunota20 Jun 17, 2026
dc6a82d
feat(shepherd-sdk): extract shared helpers from M2 modules (BLEU-840)
brunota20 Jun 17, 2026
883ee82
refactor(modules): consume shepherd-sdk helpers (BLEU-843)
brunota20 Jun 17, 2026
3674177
feat(shepherd-sdk-test): in-memory host mocks for module tests (BLEU-…
brunota20 Jun 17, 2026
05a7b58
docs(shepherd-sdk): rustdoc polish + README + docs/sdk.md (BLEU-844)
brunota20 Jun 17, 2026
351f106
feat(examples): price-alert Chainlink oracle reader (BLEU-846)
brunota20 Jun 17, 2026
8b0dd45
feat(examples): balance-tracker example module (BLEU-847)
brunota20 Jun 17, 2026
8945cb1
docs(tutorial): first-module walkthrough (BLEU-848)
brunota20 Jun 17, 2026
b920828
chore: rust-idiomatic compliance pass across M3 + M2 modules
brunota20 Jun 17, 2026
93981aa
refactor(price-alert): port to Host trait + MockHost tests (BLEU-851)
brunota20 Jun 17, 2026
862cabf
feat(examples): stop-loss module + tutorial as guided tour (BLEU-852)
brunota20 Jun 17, 2026
abba8f1
refactor(twap-monitor): port to Host trait + MockHost tests (BLEU-854)
brunota20 Jun 17, 2026
cd161ba
refactor(ethflow-watcher): port to Host trait + MockHost tests (BLEU-…
brunota20 Jun 17, 2026
9176828
chore(qa): workspace cargo fmt sweep + em-dash cleanup (COW-1063)
brunota20 Jun 17, 2026
dcb4daa
docs(qa): COW-1063 sign-off matrix + architectural findings
brunota20 Jun 17, 2026
1e4bd98
docs: resolve QA findings - ADR-0009 + doc 05 status callouts
brunota20 Jun 17, 2026
7471489
ci: build all production module .wasm targets via matrix (COW-1066)
brunota20 Jun 17, 2026
09c9f76
ci: gate cargo doc warnings (-D warnings) + fix 3 broken intra-doc li…
brunota20 Jun 17, 2026
4b25de2
docs(shepherd-sdk): add 6 doctests covering Host trait + helper API (…
brunota20 Jun 17, 2026
22fbe76
test(nexum-engine): supervisor integration tests for 5 production mod…
brunota20 Jun 17, 2026
3d8a1ef
docs(m2): testnet runbook + engine.m2.toml + `just run-m2` (validated…
brunota20 Jun 17, 2026
73cc928
fix(event_loop): do not bail boot when block / log stream Vec is empty
brunota20 Jun 18, 2026
caa59f0
docs(m3): testnet runbook + engine.m3.toml + `just run-m3` (validated…
brunota20 Jun 18, 2026
e7eeed9
docs(m3): testnet edge-case validation report - 5 scenarios run, all …
brunota20 Jun 18, 2026
af4a788
fix(supervisor): mark module alive=false when init returns Err (COW-1…
brunota20 Jun 18, 2026
66fc164
review: address jeffersonBastos M3 epic feedback (PR #55)
brunota20 Jun 22, 2026
299dfd3
chore(rust-idiomatic): M3 compliance pass (filtered from M4/M5 compli…
brunota20 Jun 23, 2026
2e83e90
docs(deployment): operator runbook (BLEU-836) (#17)
brunota20 Jun 24, 2026
5c465f7
chore(shepherd-sdk): derive strum::IntoStaticStr + non_exhaustive on …
brunota20 Jun 25, 2026
0da45ba
chore(twap-monitor): derive strum::IntoStaticStr + non_exhaustive on …
brunota20 Jun 25, 2026
75a581a
fix(balance-tracker): replace Result<_, String> with typed AddressLis…
brunota20 Jun 25, 2026
7ccb93c
feat(shepherd-sdk): consolidate AddressParse helper from balance-trac…
brunota20 Jun 25, 2026
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
36 changes: 34 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -55,14 +55,46 @@ jobs:
- uses: Swatinem/rust-cache@c19371144df3bb44fab255c43d04cbc2ab54d1c4 # v2.9.1
- run: cargo test --workspace --all-features --no-fail-fast

docs:
name: rustdoc
runs-on: ubuntu-latest
env:
RUSTDOCFLAGS: "-D warnings"
steps:
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
- uses: dtolnay/rust-toolchain@3c5f7ea28cd621ae0bf5283f0e981fb97b8a7af9 # master 2026-03-27
with:
toolchain: nightly
targets: wasm32-wasip2
- uses: Swatinem/rust-cache@c19371144df3bb44fab255c43d04cbc2ab54d1c4 # v2.9.1
- run: cargo doc --workspace --no-deps

build-module:
name: build example module
name: build ${{ matrix.module }} (wasm32-wasip2)
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
module:
- example
- twap-monitor
- ethflow-watcher
- price-alert
- balance-tracker
- stop-loss
steps:
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
- uses: dtolnay/rust-toolchain@3c5f7ea28cd621ae0bf5283f0e981fb97b8a7af9 # master 2026-03-27
with:
toolchain: nightly
targets: wasm32-wasip2
- uses: Swatinem/rust-cache@c19371144df3bb44fab255c43d04cbc2ab54d1c4 # v2.9.1
- run: cargo build -p example --target wasm32-wasip2 --release
- run: cargo build -p ${{ matrix.module }} --target wasm32-wasip2 --release
- name: report wasm size
run: |
artifact_name=$(echo "${{ matrix.module }}" | tr '-' '_')
wasm_path="target/wasm32-wasip2/release/${artifact_name}.wasm"
if [ -f "$wasm_path" ]; then
size=$(wc -c < "$wasm_path")
echo "${{ matrix.module }} .wasm size: ${size} bytes"
fi
8 changes: 8 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,11 @@ Thumbs.db
# Environment
.env
.env.*

# Agent skills / AI tooling — installed locally, never committed.
.agents/
.claude/
skills-lock.json

# Engine runtime state (default state_dir from engine.toml).
data/
109 changes: 109 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,14 @@
[workspace]
members = [
"crates/nexum-engine",
"crates/shepherd-sdk",
"crates/shepherd-sdk-test",
"modules/ethflow-watcher",
"modules/example",
"modules/examples/balance-tracker",
"modules/examples/price-alert",
"modules/examples/stop-loss",
"modules/twap-monitor",
]
resolver = "2"

Expand All @@ -10,6 +17,108 @@ edition = "2024"
license = "AGPL-3.0"
repository = "https://github.com/nullisLabs/shepherd"

# Shared dependency table. Only deps consumed by 2+ crates across the
# full workspace (nexum-engine + every downstream module crate) are
# hoisted here; single-consumer deps stay per-crate. Crates inherit
# with `dep.workspace = true` and may add features per call site via
# `dep = { workspace = true, features = ["extra"] }`. Version drift
# across crates (the failure mode that prompted hoisting in the first
# place, e.g. cowprotocol on `1.0.0-alpha` vs `1.0.0-alpha.3`) is now
# impossible by construction.
[workspace.dependencies]
# Error + async plumbing.
anyhow = "1"
thiserror = "2"
tokio = { version = "1", features = ["full"] }
futures = "0.3"

# Serde + config.
serde = { version = "1", features = ["derive"] }
serde_json = "1"

# Observability.
tracing = "0.1"
tracing-subscriber = { version = "0.3", default-features = false, features = ["fmt", "env-filter", "ansi", "json"] }

# `strum::IntoStaticStr` on every error / event enum gives a free
# snake_case `&'static str` for every variant, which feeds directly
# into `metrics::counter!(..., "error_kind" => name)` and
# `tracing::warn!(error_kind = name, ...)` recordings without an
# ad-hoc `match err { ... => "connect" ... }` ladder per call site.
strum = { version = "0.26", features = ["derive"] }

# `auto_impl::auto_impl(&, Arc, Box)` forwarding impls for traits
# held through smart pointers. Available workspace-wide so any future
# `Arc<dyn Trait>` boundary can opt in without touching root manifest.
auto_impl = "1"

# `derive_more` newtype boilerplate (`Deref`, `From`, `Display`, ...).
# `default-features = false, features = ["full"]` keeps the proc-macro
# surface predictable; per-derive opt-in via the standard `#[derive(...)]`
# syntax. Available workspace-wide; not pulled in by default.
derive_more = { version = "1", default-features = false, features = ["full"] }

# CLI parser. Used by every binary crate (engine, load-gen,
# orderbook-mock, shepherd-backtest) via the derive macro.
clap = { version = "4", features = ["derive"] }

# alloy stack. Engine uses the full provider/transport surface;
# guest-facing crates use `alloy-primitives` + `alloy-sol-types` for
# typed protocol values. Pinned together so a single workspace bump
# moves every consumer at once.
alloy-primitives = { version = "1.5", default-features = false, features = ["std", "serde"] }
alloy-sol-types = { version = "1.5", default-features = false, features = ["std"] }
alloy-provider = { version = "1.5", default-features = false, features = ["ws", "ipc", "pubsub", "reqwest"] }
alloy-rpc-types-eth = { version = "1.5", default-features = false, features = ["std"] }
alloy-transport-ws = { version = "1.5", default-features = false }

# CoW Protocol bindings. Pinned to one version across the workspace
# (was `1.0.0-alpha` in engine vs `1.0.0-alpha.3` in SDK before
# hoisting). Default features stay on so the engine picks up
# `http-client` for `OrderBookApi`; guest-side consumers (SDK,
# strategies) opt out with `default-features = false` for the
# `cdylib` wasm-target builds.
cowprotocol = "1.0.0-alpha.3"

# HTTP transport for `cow_api::request` REST passthrough and the
# orderbook-mock test surface.
reqwest = { version = "0.12", default-features = false, features = ["json", "rustls-tls"] }

# `wit-bindgen` is consumed by every guest module crate (example +
# every strategy + every fixture). Hoisted so a single bump moves
# them in lock-step.
wit-bindgen = { version = "0.57", default-features = false, features = ["macros", "realloc"] }

# Workspace-standard lint set. New crates inherit via
# `[lints] workspace = true` in their package manifest. `unsafe_code`
# cannot be denied workspace-wide because every wit-bindgen guest
# module emits an `unsafe extern "C"` shim; modules carrying that
# macro keep the default-warn allowance, and unsafe in non-binding
# code still trips review by convention.
[workspace.lints.rust]
unsafe_op_in_unsafe_fn = "warn"

[workspace.lints.clippy]
# Deny the easy footguns. Each crate carries its own narrower
# `#![deny(...)]` where the cost of a violation is high (e.g. the
# binary entrypoints carry `unused_crate_dependencies` warn).
dbg_macro = "deny"
todo = "deny"

# `cowprotocol` v1.0.0-alpha.3 (the crates.io release the engine
# depends on) was cut from `cowdao-grants/cow-rs` PR #5 at commit
# `1742ffa`. `bleu/cow-rs` main has diverged since with: the
# `composable::Proof` width fix (relevant to the TWAP poll path),
# `OrderCreation` zero-from-address fast-fail, the `order_book` /
# `composable` submodule splits, `OrderPostErrorKind` + `retry_hint()`
# (BLEU-822, the protocol-level retry contract M2 modules dispatch
# on), and `OrderBookApi::with_base_url(chain, base_url)` for barn /
# staging routing (BLEU-823). Patching to that commit picks the lot
# up without waiting for an alpha.4 publish. Drop once
# `cowprotocol >= 1.0.0-alpha.4` ships.
[patch.crates-io]
cowprotocol = { git = "https://github.com/bleu/cow-rs", rev = "57f5f553ab28c9fff54089daf2d39b4282f3e4dd" }

[profile.dev]
panic = "abort"

Expand Down
61 changes: 61 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,71 @@ just build

# Run the runtime against the example module
just run

# Run unit tests
just test
```

Without Nix, you need: Rust (edition 2024, see `rust-toolchain.toml` if present), the `wasm32-wasip2` target, and `wasm-tools`.

## Running

### Single-module (development)

```sh
nexum-engine <path-to-component.wasm> [<module.toml>]
```

The `module.toml` is optional; without it the engine prints a deprecation warning and loads the module with empty capabilities and config (0.1 fallback).

### Multi-module (production)

```sh
nexum-engine --engine-config engine.toml
```

`engine.toml` declares RPC endpoints, the state directory, and a `[[modules]]` list:

```toml
[engine]
state_dir = "/var/lib/shepherd"
log_level = "info"

[chains.1]
rpc_url = "wss://mainnet.infura.io/ws/v3/..."

[[modules]]
path = "modules/twap-monitor/twap-monitor.wasm"
manifest = "modules/twap-monitor/module.toml"

[[modules]]
path = "modules/ethflow-watcher/ethflow-watcher.wasm"
```

### Module manifest (`module.toml`)

```toml
[module]
name = "twap-monitor"
version = "0.1.0"

[capabilities]
required = ["chain", "local-store", "cow-api"]
optional = ["http"]

[capabilities.http]
allow = ["api.cow.fi"]

[[subscription]]
kind = "log"
chain_id = 1
address = "0xfdaFc9d1902f4e0b84f65F49f244b32b31013b74" # ComposableCoW (canonical CREATE2 address, same on every supported chain)

[[subscription]]
kind = "block"
chain_id = 1
```

## Documentation

The `docs/` directory contains the design corpus:
Expand Down
67 changes: 63 additions & 4 deletions crates/nexum-engine/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,70 @@ edition.workspace = true
license.workspace = true
repository.workspace = true

[lints]
workspace = true

[dependencies]
# WASM Component Model runtime.
wasmtime = { version = "45", features = ["component-model"] }
wasmtime-wasi = "45"
anyhow = "1"
tokio = { version = "1", features = ["full"] }
getrandom = "0.4"
serde = { version = "1", features = ["derive"] }

# Async + error plumbing.
anyhow.workspace = true
thiserror.workspace = true
# `strum::IntoStaticStr` on error enums gives metric labels (`error_kind`)
# free via a snake_case `&'static str` for every variant. Used at
# `tracing::warn!(error_kind = <variant_name>.into(), ...)` sites and
# any `metrics::counter!(... "error_kind" => kind)` recordings, so the
# Prometheus labels stay in lock-step with the Rust enum source of
# truth instead of needing a `match err { ... => "connect" ... }`
# ladder per call site. Pinned via the workspace so every consumer
# moves in lockstep.
strum.workspace = true
tokio.workspace = true
clap.workspace = true

# Manifest parsing.
serde.workspace = true
toml = "1"
serde_json.workspace = true

# Observability. `tracing` replaces the prior `eprintln!` debug log
# so the engine can drop into a structured log pipeline in production.
tracing.workspace = true
tracing-subscriber = { workspace = true, default-features = false, features = ["fmt", "env-filter", "ansi"] }

# `cow-api` backend. cowprotocol pulls `OrderBookApi`, `OrderCreation`,
# `OrderUid`, the orderbook base URL table per `Chain`, and the typed
# error surface the host re-projects into `HostError`. Pinned via the
# workspace so every crate that touches cowprotocol moves in lockstep.
cowprotocol.workspace = true
# REST passthrough for `cow_api::request`. cowprotocol pulls reqwest
# transitively for its own client; we depend on it directly so the
# import is explicit and survives any future cowprotocol feature
# rearrangement.
reqwest.workspace = true

# `chain` backend. Each configured chain owns a `DynProvider` built
# from a `WsConnect`/`Http` transport so the host's `request` /
# `request-batch` impls can hand a raw `(method, params)` pair to
# alloy's JSON-RPC layer without reimplementing the codec.
alloy-provider.workspace = true
alloy-rpc-client = { version = "1.5", default-features = false }
alloy-rpc-types-eth = { version = "1.5", default-features = false, features = ["std"] }
alloy-transport = { version = "1.5", default-features = false }
alloy-transport-ws.workspace = true
alloy-primitives.workspace = true
futures.workspace = true

# `local-store` backend. Per-module namespacing is enforced
# host-side via a `[len:u8][module_name][raw_key]` prefix.
redb = "2"

# Misc.
getrandom = "0.4"
url = "2"

[dev-dependencies]
tempfile = "3"
wiremock = "0.6"
16 changes: 16 additions & 0 deletions crates/nexum-engine/src/bindings.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
//! WIT bindings generated by `wasmtime::component::bindgen!`.
//!
//! Both `wit/nexum-host` and `wit/shepherd-cow` packages are listed
//! explicitly so wit-parser can resolve the cross-package reference
//! natively - no vendored `deps/` tree needed. The world name is fully
//! qualified.
//!
//! Every `Host` trait impl in `crate::host::impls` consumes types
//! generated here.

wasmtime::component::bindgen!({
path: ["../../wit/nexum-host", "../../wit/shepherd-cow"],
world: "shepherd:cow/shepherd",
imports: { default: async },
exports: { default: async },
});
38 changes: 38 additions & 0 deletions crates/nexum-engine/src/cli.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
//! CLI surface for the `nexum-engine` binary, derived via clap.
//!
//! The 0.2 binary accepts either a positional `<wasm-path> [<manifest-path>]`
//! shortcut that synthesises a one-module engine config, or a
//! `--engine-config <path>` flag that points at a TOML declaring
//! multiple modules. Production deployments use the second form; the
//! positional shortcut stays for parity with the M1 reference CLI and
//! for smoke tests.

use std::path::PathBuf;

use clap::Parser;

/// Parsed CLI surface.
///
/// `nexum-engine [<wasm-path> [<manifest-path>]] [--engine-config <path>]`
#[derive(Parser, Debug, Default)]
#[command(
name = "nexum-engine",
about = "Run one or more Wasm Component modules under the Shepherd supervisor",
long_about = None,
version,
)]
pub struct Cli {
/// Optional positional path to a Wasm Component file. Synthesises
/// a one-module engine config when no `--engine-config` is given.
pub wasm: Option<PathBuf>,

/// Optional positional path to the module's `nexum.toml` manifest.
/// Only consulted alongside the positional `wasm` shortcut.
pub manifest: Option<PathBuf>,

/// Optional explicit path to the engine-wide `engine.toml` config.
/// When omitted, the engine resolves the default search path
/// documented in `engine_config::load_or_default`.
#[arg(long = "engine-config")]
pub engine_config: Option<PathBuf>,
}
Loading