Skip to content

feat(scenarios): add HumidiFi state preparation - #16

Open
92Infinitus92 wants to merge 2 commits into
feat/scenarios/raw-layoutfrom
wip/humidifi-rebuild
Open

feat(scenarios): add HumidiFi state preparation#16
92Infinitus92 wants to merge 2 commits into
feat/scenarios/raw-layoutfrom
wip/humidifi-rebuild

Conversation

@92Infinitus92

@92Infinitus92 92Infinitus92 commented Sep 14, 2026

Copy link
Copy Markdown
Collaborator

HumidiFi markets can now be discovered and prepared through the existing scenario and MCP paths. Adds fair-value, persistent-freshness, stale-quote and liquidity scenarios, with an explicitly selected market and guarded raw-layout writes. Fair-value scenarios fetch the market before Play, then keep its quote fresh locally.

Stacked on #15 (feat/scenarios/raw-layout). Reuses its raw-layout materializer and registry loader, adding an optional eight-byte XOR mask for HumidiFi account fields.

Validation:

  • cargo fmt --all -- --check
  • cargo test --offline --workspace --features surfpool-core/ignore_tests_ci -- --test-threads=1: 943 passed, 0 failed, 66 ignored.
  • cargo test --offline -p surfpool-core --features integration-tests tests::humidifi -- --test-threads=1 --nocapture: 10 passed, including deployed-program swap and exact account-byte checks.
  • cargo clippy --offline --workspace --all-targets: exit 0, existing warnings.
  • cargo build --offline --release --features supervisor_ui: exit 0.

The live integration tests execute the deployed HumidiFi program in the test VM through the documented DFlow test wrapper.

Greptile Summary

This PR adds HumidiFi market discovery and scenario preparation across the core scenario registry, MCP interface, and supporting HTTP serialization path.

  • Adds guarded XOR-aware raw-layout templates for fair value, freshness, and stale quotes.
  • Adds validated market and vault discovery plus fair-value and liquidity scenario builders.
  • Extends scenario types and registry loading with XOR masks and eager raw-layout write validation.
  • Adds unit, API, and live integration coverage for layout writes, persisted freshness, discovery, and swap behavior.

Confidence Score: 5/5

The PR appears safe to merge, with no outstanding previous findings or accepted new defects.

Both previous findings were resolved after Greptile conceded that creation-time Surfnet reads hydrate the targeted accounts and that Play-time refetching would overwrite prepared local state. The subsequent raw-layout validation changes are consistent with the loader and materializer contracts, and no new actionable failure remains.

Important Files Changed

Filename Overview
crates/core/src/scenarios/protocols/humidifi/v1/fair_value.rs Adds validated HumidiFi market metadata parsing and exact fair-value scenario construction with persistent freshness.
crates/core/src/scenarios/protocols/humidifi/v1/liquidity.rs Adds vault validation and balance-scaling liquidity scenarios while preserving hydrated account state.
crates/core/src/scenarios/protocols/humidifi/v1/markets.rs Adds deterministic discovery and validation of supported HumidiFi markets.
crates/core/src/scenarios/registry.rs Registers HumidiFi templates and now validates complete raw-layout collections before mutation.
crates/types/src/scenarios.rs Extends raw-layout support with XOR masking and validates writable byte ranges before registration.
crates/mcp/src/surfpool/mod.rs Exposes HumidiFi discovery, fair-value preparation, and liquidity preparation through MCP.
crates/core/src/tests/humidifi/mod.rs Adds extensive live-state validation of layout compatibility, scenario materialization, and swap behavior.

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart TD
    A[Client or Studio] --> B[MCP HumidiFi tool]
    B --> C[Surfnet RPC account reads]
    C --> D[Validate market owner, layout, schema, mints, and vaults]
    D --> E{Scenario type}
    E -->|Fair value| F[Convert human price to masked fixed-point value]
    E -->|Liquidity| G[Scale hydrated vault balances]
    F --> H[Build scenario overrides]
    G --> H
    H --> I[Register scenario]
    I --> J[Play through raw-layout materializer]
    J --> K[Prepared HumidiFi market and vault state]
    K --> L[Persistent freshness reapplied each slot]
Loading

Reviews (3): Last reviewed commit: "fix(humidifi): preserve prepared state i..." | Re-trigger Greptile

Comment thread crates/core/src/scenarios/protocols/humidifi/v1/liquidity.rs
Comment thread crates/core/src/scenarios/protocols/humidifi/v1/fair_value.rs
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