Skip to content

chore(sdk + twap-monitor): hex helpers via alloy_primitives::hex::encode#51

Closed
brunota20 wants to merge 1 commit into
fix/twap-calldata-helper-cow-1077from
chore/hex-via-alloy-mfw78-followup
Closed

chore(sdk + twap-monitor): hex helpers via alloy_primitives::hex::encode#51
brunota20 wants to merge 1 commit into
fix/twap-calldata-helper-cow-1077from
chore/hex-via-alloy-mfw78-followup

Conversation

@brunota20

Copy link
Copy Markdown

Summary

mfw78's review of PR #8 flagged: "we already pull alloy, so pulling hex via there is really not much of a deal". PR #47 (COW-1074, commit acc9654) then introduced two new custom hex helpers that recreate the same antipattern at a different scope.

This PR removes both:

File Helper Before After
crates/shepherd-sdk/src/cow/app_data.rs encode_hex(&[u8; 32]) 9-line manual nibble loop with a 0123456789abcdef table format!(\"0x{}\", alloy_primitives::hex::encode(b))
modules/twap-monitor/src/strategy.rs hex_short(&[u8; 32]) 10-line manual nibble loop, same table format!(\"0x{}…\", alloy_primitives::hex::encode(&b[..8]))

Both crates already depend on alloy-primitives (sdk 1.6, twap-monitor 1.5), so this is a pure simplification - no Cargo.toml change. Both helpers keep their signatures so call sites (resolve_app_data in the SDK, every host.log line in twap-monitor strategy) need no changes. Comments on both helpers now explicitly reference mfw78's PR #8 guidance so the next person tempted to hand-roll the table has a hook.

Stack

Stacked on fix/twap-calldata-helper-cow-1077 (PR #50) → feat/ethflow-expected-excessive-validto-cow-1076 (PR #49) → feat/forward-orderbook-error-cow-1075 (PR #48) → feat/resolve-app-data-cow-1074 (PR #47).

Why a separate PR rather than amending #47

PR #47 is already In Review and #48/#49/#50 stack on top. Amending #47 would force-push 4 branches and obscure the reviewer's history. A small follow-up PR keeps each commit bisectable and lets the alloy alignment be reviewed in isolation.

The other surfaces flagged by mfw78 on PRs #8 and #9 are also being addressed:

Validation

  • cargo test -p shepherd-sdk -p twap-monitor: 32 + 23 passed, 0 failed.
  • cargo clippy --all-targets --tests -- -D warnings: clean.
  • cargo fmt --check: clean.
  • Zero em-dash drift in touched files.

AI assistance disclosure: drafted by Claude (Opus 4.7, 1M context) while sweeping all open PRs for the same antipatterns mfw78 flagged on PRs #8 and #9.

mfw78 review of PR #8 (nullislabs#8) flagged "we already pull alloy, so pulling hex via there is really not much of a deal". The PR #47 (COW-1074) commit acc9654 then introduced two new custom hex helpers that recreate the same antipattern at a different scope:

- `crates/shepherd-sdk/src/cow/app_data.rs::encode_hex` - 32-byte hash → `0x...`. Used by `resolve_app_data` to format the orderbook lookup path.
- `modules/twap-monitor/src/strategy.rs::hex_short` - 8-byte prefix → `0x...…`. Used to format `appData` hashes in INFO log lines.

Both crates already depend on `alloy-primitives` (sdk: 1.6, twap-monitor: 1.5), so the swap is a one-liner per call site:

- `encode_hex(b)` → `format!("0x{}", alloy_primitives::hex::encode(b))`
- `hex_short(b)` → `format!("0x{}…", alloy_primitives::hex::encode(&b[..8]))`

Both functions keep their old signature so callers (`resolve_app_data` in the SDK, every `host.log` line in twap-monitor strategy) need no changes.

Comments on both helpers now explicitly reference mfw78's PR #8 guidance so the next person tempted to hand-roll a `0123456789abcdef` table has a hook.

Validation: cargo test -p shepherd-sdk -p twap-monitor: 32 + 23 passed; cargo clippy --all-targets -- -D warnings: clean; cargo fmt --check: clean; zero em-dash drift.

Why this PR sits in a separate branch rather than amending PR #47: PR #47 is already In Review, and #48/#49/#50 stack on top of it. Amending would require force-pushing 4 branches. A small follow-up PR keeps each one bisectable and lets mfw78 review the alloy alignment in isolation.

AI assistance disclosure: drafted by Claude (Opus 4.7, 1M context) while sweeping all open PRs for the same antipatterns mfw78 flagged on PRs #8 and #9.
@brunota20

Copy link
Copy Markdown
Author

Work landed via dev/m4-base creation @ 64cb6d8 (M4 production hardening + PR #66 rust-idiomatic compliance squashed). The HEAD commit of this PR is now an ancestor of dev/m4-base. Closing as merged-by-ancestor.

@brunota20 brunota20 closed this Jun 24, 2026
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