Skip to content

feat(examples): stop-loss module + tutorial as guided tour (BLEU-852)#23

Open
brunota20 wants to merge 1 commit into
feat/price-alert-host-trait-bleu-851from
feat/example-stop-loss-bleu-852
Open

feat(examples): stop-loss module + tutorial as guided tour (BLEU-852)#23
brunota20 wants to merge 1 commit into
feat/price-alert-host-trait-bleu-851from
feat/example-stop-loss-bleu-852

Conversation

@brunota20

Copy link
Copy Markdown
Collaborator

Summary

Closes the open loop in the M3 tutorial. Was a stop-loss walkthrough with `build_order_body` as a `todo!()`. Now:

  1. `modules/examples/stop-loss/` ships as a real workspace member. Same recipe as the price-alert refactor (refactor(price-alert): port to Host trait + MockHost tests (BLEU-851) #22): pure logic in `strategy.rs` against `&impl Host`, wit-bindgen adapter + Guest impl in `lib.rs`.
  2. The strategy is complete — reads a Chainlink oracle, builds an `OrderCreation` with `Signature::PreSign` (owner pre-signs via `setPreSignature` on-chain; module ships zero ECDSA), dedups via `submitted:{uid}`, persists `dropped:{uid}` on permanent submit errors.
  3. 7 host tests cover the dispatch matrix against `MockHost`: idle, triggers-and-submits, dedup-on-resubmit, permanent error → dropped, transient error → idle next-block, oracle RPC error → warn-and-continue, config round-trip + missing-owner rejection.
  4. `docs/tutorial-first-module.md` rewritten as a guided tour. Reads the real `stop-loss` source top-to-bottom and explains why each piece is shaped the way it is. No more inlined snippets, no more `todo!()`. Shorter (449 vs 580 lines) because it points at files instead of transcribing them.

Numbers

.wasm (release) 304 KB
Host tests 7
Tutorial length 449 lines (was 580)

Stacks on #22 (BLEU-851 price-alert refactor) so both modules + the tutorial land alongside the wit-bindgen adapter recipe.

Linear: BLEU-852.

Test plan

  • `cargo test -p stop-loss` — 7 host tests.
  • `cargo clippy --all-targets --workspace -- -D warnings` clean.
  • `cargo build --target wasm32-wasip2 --release -p stop-loss` — 304 KB.
  • `grep -rn '—' modules/examples/stop-loss/ docs/tutorial-first-module.md` — 0 matches.
  • External-reviewer dry-run of the tutorial - tracked under BLEU-848's external-reviewer follow-up.

Closes the loop opened by BLEU-848 (tutorial). The tutorial used to
walk through a stop-loss scenario but left `build_order_body` as a
`todo!()` cross-referencing twap-monitor. Now:

1. `modules/examples/stop-loss/` ships as a real workspace member,
   shaped the same way as the price-alert refactor (BLEU-851 / PR
   #22): pure logic in `strategy.rs` against `&impl Host`,
   wit-bindgen adapter + Guest impl in `lib.rs`.

2. The strategy is complete - reads a Chainlink oracle, builds an
   `OrderCreation` with `Signature::PreSign` (owner pre-signs
   via setPreSignature on-chain ahead of the trigger; module
   ships zero ECDSA), dedups via `submitted:{uid}`, persists
   `dropped:{uid}` on permanent submit errors.

3. Tests (7 total) cover the dispatch matrix end-to-end against
   `shepherd_sdk_test::MockHost`:

     - idle_when_price_above_trigger
     - triggers_and_submits_once_then_dedups
     - permanent_submit_error_marks_dropped (+ dedup on the next
       block)
     - transient_submit_error_leaves_state_unchanged
     - oracle_rpc_error_is_warn_and_continue
     - parse_config_round_trips_settings
     - parse_config_rejects_missing_owner

4. `docs/tutorial-first-module.md` rewritten as a guided tour
   instead of inlined snippets. The tutorial now reads the real
   `modules/examples/stop-loss/` source top-to-bottom and explains
   *why* each piece is shaped the way it is - sections on the
   wit-bindgen adapter, the `OrderCreation` assembly with
   PreSign, the dedup matrix, and the test recipe against MockHost.
   No more `todo!()`.

Numbers:

- `.wasm` 304 KB optimised (release build).
- 7 host tests passing; clippy clean on host + wasm32-wasip2.
- Tutorial is 449 lines (was 580 with the duplicated inline code);
  shorter because it points at real files instead of transcribing.

Stacks on PR #22 (price-alert host-trait refactor) so both modules
land alongside the wit-bindgen adapter recipe the tutorial
documents.
@linear-code

linear-code Bot commented Jun 17, 2026

Copy link
Copy Markdown

BLEU-852

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant