Skip to content
instruction-design-and-validation logo

Instruction Design and Validation

instruction-design-and-validation

Design Solana/Anchor instructions with clear inputs, constraints, authority checks, and invariants. Use when defining or reviewing instruction APIs.

SKILL.md

Full skill instructions

Instruction Design and Validation

Role framing: You are an instruction architect. Your goal is to define minimal, safe instruction interfaces with explicit constraints and thorough validation.

Initial Assessment

  • What state changes are needed? Which accounts and authorities are involved?
  • Are inputs fixed-size or variable? Any untrusted user data?
  • Cross-program interactions? Which programs and CPIs?
  • Performance needs: expected tx size, compute budget, number of accounts?

Core Principles

  • Keep instructions single-responsibility; avoid multi-mode flags when possible.
  • Validate all caller-provided addresses; re-derive PDAs inside program.
  • Enforce authority at the smallest scope: signer + owner + custom invariants.
  • Fail fast with descriptive errors; keep error enum tight.
  • Bound untrusted data lengths; avoid realloc unless necessary.

Workflow

  1. Define intent: describe state transition in one sentence.
  2. Specify inputs
    • Accounts table (role, owner, signer, writable, seeds).
    • Instruction data struct with versioning field if necessary.
  3. Write validation logic
    • Ownership, signer, seeds/​bump, data length bounds, relationship checks (e.g., same mint).
    • Custom invariants (e.g., price bounds, timestamp windows).
  4. Compute budget planning
    • Estimate compute; add ComputeBudgetInstruction if needed; minimize account count.
  5. Error design
    • Add specific errors for each validation step; map to user-facing messages.
  6. Tests
    • Happy path; each validation failure; edge sizes; CPI failure propagation.

Templates / Playbooks

  • Account table format (reuse from solana-account-model).
  • Validation pattern in Anchor:
    • #[account(mut, seeds = [...], bump, has_one = ...)]
    • Manual checks in handler for cross-account relationships.
  • Versioned instruction data: include u8 version + enum payload.

Common Failure Modes + Debugging

  • Missing signer/​writable flags causing runtime failure: align Anchor constraints with client metas.
  • Seed mismatch between client and program: recompute seeds and confirm bump.
  • Data length overflow on realloc: pre-calc size, fund rent.
  • CPI returns Constraint... errors: inspect callee IDL and account order.

Quality Bar / Validation

  • Instruction spec includes account table + data schema + invariants.
  • All validations covered by tests with clear errors.
  • Compute budget measured; no unnecessary accounts.
  • Versioning/​compatibility plan noted when needed.

Output Format

Deliver instruction spec containing intent, accounts table, data schema, validation steps, error list, and test checklist.

Examples

  • Simple: Update config parameter
    • Accounts: config PDA (w), authority signer; validation: seeds, has_one authority.
  • Complex: Place order on orderbook via CPI
    • Accounts: user, market, event queue, bids/​asks, token accounts; validation of owner/​mint match; compute budget ix; error mapping for CPI failures; tests for bad mints and missing signer.

More Finance & Trading skills

ponytail-debt logo
Finance & Trading

ponytail-debt

Harvest every `ponytail:` comment in the codebase into a debt ledger, so the deliberate shortcuts and deferrals ponytail leaves behind get tracked instead of rotting into "later means never". One-shot report, changes nothing.

155.5K 27.9K
View
stripe-integration logo
Finance & Trading

stripe-integration

Stripe payment processing with checkout sessions, subscriptions, webhooks, and customer management.

40.2K 12.9K
View

Build comprehensive 3-5 year financial models with revenue projections, cost structures, cash flow analysis, and scenario planning for early-stage startups. Use this skill when creating financial projections, calculating burn rate or runway, modeling fundraising scenarios, or preparing investor-r...

40.2K 12K
View
stock-analysis logo
Finance & Trading

stock-analysis

Stock and cryptocurrency analysis with portfolio management and multi-dimensional scoring.

46 11.9K
View
coinglass logo
Finance & Trading

coinglass

Real-time crypto derivatives positioning, whale tracking, liquidations, and institutional ETF flows across 37 specialized tools.

27 11.5K
View

Master dbt (data build tool) for analytics engineering with model organization, testing, documentation, and incremental strategies. Use when building data transformations, creating data models, or implementing analytics engineering best practices.

40.2K 10.5K
View

Finance AI tools

C

ChainClarity explains 700+ crypto whitepapers in plain English, with layered summaries, comparisons, research tools, alerts, and a $4.99 Pro plan.

Freemium
View
Finalle.ai logo
Finance

Finalle.ai

Stay Ahead with Finalle.ai: The Ultimate Financial News and Tools Platform

Free
View

AI-powered Pine Script code generator for TradingView

Paid
View
TradeUI logo
Finance

TradeUI

Empower your investment strategies with AI signals, option flow data, and advanced chart patterns.

Paid
View
D
Finance

Danelfin

Danelfin review covering its AI stock and ETF scores, rankings, portfolio tools, current pricing, strengths, risks, and alternatives for investors.

Freemium
View
E
Finance

Ellisense

A software for comprehensive market sentiment analysis.

Paid
View

'Stock Correlations' App by Freshly.ai: Reveal Stock Patterns and Trends

Free
View