Skip to content

feat(visualsign-solana): add Titan Swap preset visualizer#415

Open
kyle-anchorage wants to merge 1 commit into
mainfrom
titan
Open

feat(visualsign-solana): add Titan Swap preset visualizer#415
kyle-anchorage wants to merge 1 commit into
mainfrom
titan

Conversation

@kyle-anchorage

@kyle-anchorage kyle-anchorage commented Jul 16, 2026

Copy link
Copy Markdown
Contributor

Why this PR exists

Adds a Solana visualizer preset for Titan Swap (program T1TANpTeScyeqVzzgNViGDNrkQ6qHz9KrSBS4aNXvGT), so initialize, swap_route, and swap_route_v2 instructions render as structured, human-readable fields instead of falling through to the generic unknown_program fallback.

Titan is a swap-routing program; the IDL was pulled directly from Titan's public CPI example repo (Titan-Pathfinder/titan-v2-cpi-example) and validated to have a well-formed instructions array with 8-byte discriminators before scaffolding.

This follows the established IDL-preset pattern (dflow_aggregator as the template): InstructionView::from_context for infallible account/program resolution, IDL-driven parsing via solana_parser, and a quote-free format_arg_value renderer so nested args (e.g. swap_route's swaps: Vec<SwapSpecInput>) don't explode into per-field noise.

What changed (architecture + key decisions)

  • New src/chain_parsers/visualsign-solana/src/presets/titan_swap/ module: config.rs (program ID registration, wildcard instruction match), mod.rs (TitanSwapVisualizer, VisualizerKind::Dex), titan_swap.json (bundled IDL).
  • No manual registration needed — build.rs auto-discovers TitanSwapVisualizer from the new preset directory and generates presets/mod.rs at build time.
  • Failure-mode shape: no changes — this is new, additive code; no existing visualizer or shared helper was modified.

Test plan

Agent-verified (automated)

  • cargo fmt -p visualsign-solana — clean
  • cargo clippy -p visualsign-solana --all-targets -- -D warnings — clean (both with and without --features diagnostics)
  • cargo test -p visualsign-solana — 264 passed, 0 failed. 8 titan_swap tests: IDL loads, discriminators are 8 bytes, unknown-discriminator/short-data error paths, successful parse of both swap_route and swap_route_v2 (exercising their differing nested SwapSpecInput/SwapSpecInputV2 shapes via hand-built instruction bytes), named-account mapping with overflow into extra_accounts, and "Remaining Account N" label rendering
  • cargo test -p visualsign-solana --features diagnostics — same, all green
  • make -C src test (full workspace build + test) — all green
  • Review: 4-lens adversarial review (review-changes) run against the diff. Lens 3 (goal coverage) flagged that the initial 4-test scaffold only covered error paths, not a successful parse of either instruction or the named-accounts mapping — both gaps fixed by adding the 4 tests above. Lenses 1, 2, 4 had no titan_swap-specific findings; noted pre-existing crate-wide format_arg_value duplication as out-of-scope debt, not introduced by this PR.

Human QA (manual checklist)

  • No UI to exercise manually — this is a pure data-visualization preset consumed by parser_cli/parser_app/gRPC server, covered by the automated fixture-style tests above.

How this is maintainable by Claude

  • Structure mirrors every other Solana IDL preset (dflow_aggregator, kamino_vault, etc.) — a fresh agent can orient from any sibling preset without extra exploration.
  • config.rs + mod.rs + bundled .json IDL is the whole surface area; no cross-cutting changes.
  • Guarded by the workspace lint policy (unwrap_used/expect_used/panic denied outside tests) and the four required preset tests, which will fail loudly if the bundled IDL or discriminator logic regresses.
  • CLAUDE.md's field-builder rule (create_text_field/create_raw_data_field, never raw field structs) and ASCII-only rule are both followed.

Manual steps needed (by human)

None — fully automated by CI. No migrations, flags, or backfills.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds a new Solana preset visualizer for the Titan Swap program so key instructions decode via the bundled Anchor IDL and render as structured fields instead of falling back to unknown_program.

Changes:

  • Added a titan_swap preset visualizer that IDL-parses instruction data and renders condensed/expanded field layouts.
  • Added preset config registering Titan Swap’s program ID for visualizer dispatch.
  • Bundled Titan Swap’s Anchor IDL JSON to drive discriminator + argument parsing (with preset-level regression tests in the module).

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.

File Description
src/chain_parsers/visualsign-solana/src/presets/titan_swap/mod.rs Implements TitanSwapVisualizer, IDL loading/parsing, field rendering, and preset tests.
src/chain_parsers/visualsign-solana/src/presets/titan_swap/config.rs Registers the Titan Swap program ID in SolanaIntegrationConfigData so the visualizer can be selected.
src/chain_parsers/visualsign-solana/src/presets/titan_swap/titan_swap.json Bundled Anchor IDL used for discriminator matching and argument decoding.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.

Comment on lines +252 to +255
/// Strips `"` and `\` (to preserve the quote-free rendering above) and any
/// other non-printable-ASCII bytes (`SignablePayload::validate_charset` forbids
/// them). IDL strings here (pubkeys, enum names) are already clean; this is a
/// defensive guard so the function's charset-safe contract always holds.
Comment on lines +454 to +461
#[test]
fn test_short_data_returns_error() {
let short_data = [0x01, 0x02, 0x03];
let accounts = vec![];
let result = parse_titan_swap_instruction(&short_data, &accounts);
assert!(result.is_err(), "Short data should return error");
}
}
Adds an IDL-based visualizer preset for Titan Swap
(T1TANpTeScyeqVzzgNViGDNrkQ6qHz9KrSBS4aNXvGT), covering initialize,
swap_route, and swap_route_v2. Follows the dflow_aggregator template:
InstructionView-based resolution, IDL-driven parsing, and a quote-free
format_arg_value renderer for nested args.

Tests cover IDL/discriminator validation, error paths (short/unknown
data), successful parsing of swap_route and swap_route_v2 (including
their differing nested SwapSpecInput/SwapSpecInputV2 shapes), and
named/remaining-account mapping.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 3 out of 3 changed files in this pull request and generated no new comments.

@kyle-anchorage
kyle-anchorage marked this pull request as ready for review July 16, 2026 18:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants