Skip to content

Add OKX Router Solana preset#351

Draft
kyle-anchorage wants to merge 1 commit into
mainfrom
okx-router
Draft

Add OKX Router Solana preset#351
kyle-anchorage wants to merge 1 commit into
mainfrom
okx-router

Conversation

@kyle-anchorage

Copy link
Copy Markdown
Contributor

1. Why this PR exists

OKX Router (proVF4pMXVaYqmy4NjniPh4pqKNfMmsihgd4wdkCX3u) swaps on Solana fell through to the unknown-program catch-all visualizer. Signers saw raw instruction bytes instead of a decoded instruction name, named accounts, and arguments — making it hard to verify what they were signing.

This adds an IDL-backed preset so OKX Router instructions render as structured, human-readable fields.

2. What changed

  • New Solana preset presets/okx_router/ with OkxRouterVisualizer, following the existing IDL-preset pattern (mirrors neutral_trade).
  • Bundles the on-chain Anchor IDL (okx_router.json, ~3.5k lines) via include_str!; the visualizer parses instructions with parse_instruction_with_idl against the bundled IDL.
  • Decodes the 8-byte Anchor discriminator, maps account positions to IDL account names, and renders instruction name, program ID, discriminator, named accounts, and decoded args in condensed/expanded preview layouts, with a raw-hex fallback.
  • SolanaIntegrationConfig registers the program with a "*" -> "*" wildcard so all OKX Router instructions route to this visualizer.
  • Registered by adding pub mod okx_router; to presets/mod.rs — the build.rs script auto-discovers the directory and wires OkxRouterVisualizer into available_visualizers().

3. Why this is safe

  • Backward compatibility: Purely additive. No existing preset, type, or registration path is modified beyond one pub mod line. Before this, OKX Router txs hit the unknown-program catch-all; now they hit a dedicated visualizer. No other chain or program is affected.
  • How it was built: Reuses the established InstructionVisualizer + SolanaIntegrationConfig + build.rs auto-discovery mechanism already used by every other Solana preset, so it inherits their behavior and routing.
  • Risks mitigated: Instruction data shorter than 8 bytes and unknown discriminators return VisualSignError rather than panicking or mis-rendering. Decoding failures surface as errors; the field carries a raw-hex fallback so nothing is silently dropped.

Checks run (by agent)

  • cargo test -p visualsign-solana okx — 4 passed (IDL loads, all discriminators are 8 bytes, unknown discriminator errors, short data errors)
  • cargo clippy -p visualsign-solana --all-targets -- -D warnings — clean
  • cargo fmt --check -p visualsign-solana — clean

Manual steps needed (by human)

None — fully automated by CI.

4. How this is maintainable

  • Follows the exact same structure as other presets (neutral_trade, metadao_futarchy), so a fresh developer recognizes the pattern immediately. The solana-add-idl skill documents how to add more.
  • Registration is automatic via build.rs directory scanning — no central registry to keep in sync; the directory name (okx_router) deterministically maps to OkxRouterVisualizer.
  • Tests guard the IDL contract: that it loads, that every instruction has an 8-byte discriminator, and that malformed input errors rather than panics.

🤖 Generated with Claude Code

OKX Router (proVF4pMXVaYqmy4NjniPh4pqKNfMmsihgd4wdkCX3u) swaps were
falling through to the unknown-program catch-all, so signers saw raw
instruction bytes instead of decoded instruction names, accounts, and
arguments. This adds an IDL-backed visualizer so OKX Router instructions
render with structured fields.

User prompt: add okx router program

Co-Authored-By: Claude <noreply@anthropic.com>
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