AgentSkillsCN

solana-core

用Rust打造Solana区块链——交易、账户、RPC与实时数据。

SKILL.md
--- frontmatter
name: solana-core
description: Solana blockchain engineering in Rust — transactions, accounts, RPC, and real-time data

What I do

  • Guide Solana transaction construction with versioned transactions, ALTs, and compute budget
  • Provide RPC provider selection and real-time data streaming patterns
  • Document solana-sdk and solana-client crate patterns for Rust engineers
  • Define error handling and retry strategies for Solana-specific failure modes

When to use me

Use this skill for any Solana blockchain project in Rust. Pair with solana-arb for trading/arbitrage systems, rust-pro for Rust engineering patterns, and perf-rust for performance optimization.

Solana Programming Model

ConceptWhat It IsKey Property
AccountData container with SOL balanceOwned by exactly one program
ProgramStateless executable codeCannot store state; uses accounts
TransactionAtomic batch of instructionsAll succeed or all revert
InstructionSingle program invocationSpecifies program, accounts, and data
  • Account ownership -- each account owned by exactly one program. Only the owner can modify data. System program owns SOL accounts; token program owns token accounts.
  • Rent exemption -- accounts must maintain minimum SOL balance (2 years rent) or be garbage collected. Always fund to rent-exempt minimum.
  • Program Derived Addresses (PDAs) -- deterministic addresses generated via Pubkey::find_program_address(&[seeds], &program_id). No private key exists; only the deriving program can sign for them.
  • Key difference from Ethereum -- code and state are separate. Programs are stateless; all state lives in accounts passed to instructions.

Transaction Construction

Always use Versioned (v0) transactions -- legacy transactions lack ALT support and hit account limits sooner. Use VersionedTransaction with MessageV0.

  • Address Lookup Tables (ALTs) -- use when >3 unique accounts. Compress 32-byte addresses to 1-byte indices. Must be active 1 slot after creation.
  • Compute Budget -- set_compute_unit_limit(units) and set_compute_unit_price(micro_lamports). Place compute budget instructions FIRST. Simulate to get actual usage, set limit to 1.2x actual.
  • Transaction size limit: 1232 bytes -- plan instruction packing carefully. Use ALTs aggressively to fit more instructions per transaction.

RPC Provider Selection

code
Need sub-50ms latency to validator?
  YES --> Self-hosted validator + Geyser plugin
  NO  --> Need real-time account streaming?
    YES --> Helius or Triton (Yellowstone gRPC)
    NO  --> Need Solana-specific APIs (priority fees, DAS)?
      YES --> Helius
      NO  --> Any provider (DRPC, QuickNode, Alchemy)
ProviderSolana FocusYellowstone gRPCPriority Fee APIBest For
HeliusDedicatedYesYesTrading, DeFi, NFTs
TritonDedicatedYesNoHigh-throughput streaming
DRPCMulti-chainNoNoGeneral development
QuickNodeMulti-chainNoNoMulti-chain projects

Real-Time Data Patterns

MethodLatencyComplexityUse When
getAccountInfo polling400-1000msLowInfrequent checks, simple apps
WebSocket subscriptions100-400msMediumAccount/program monitoring
Yellowstone gRPC (Geyser)10-50msHighTrading, arbitrage, real-time feeds
  • WebSocket: accountSubscribe (specific accounts), programSubscribe (all accounts owned by a program), logsSubscribe (transaction logs)
  • Yellowstone gRPC: managed (Helius/Triton) or self-hosted validator with Geyser plugin. Streams account updates, transactions, and slot notifications.
  • Reconnection: always implement reconnection with exponential backoff. WebSocket connections drop frequently on Solana RPC nodes. Cap backoff at 30 seconds, reset on successful reconnection.

solana-sdk / solana-client Patterns

CratePurposeKey Types
solana-sdkCore types and signingPubkey, Keypair, VersionedTransaction, V0Message
solana-clientRPC communicationnonblocking::rpc_client::RpcClient
solana-transaction-statusTransaction parsingUiTransactionEncoding, TransactionDetails
spl-tokenSPL token operationsinstruction::transfer, state::Account

ALWAYS use nonblocking RPC client -- solana_client::nonblocking::rpc_client::RpcClient. Using the sync RpcClient in async context blocks the tokio runtime.

  • Single signer: VersionedTransaction::try_new(message, &[&keypair])
  • Multi-signer: pass all signers in the slice
  • Always simulate_transaction before send_transaction -- catches errors without fees

Priority Fee Estimation

  • Query getRecentPrioritizationFees for accounts your transaction touches
  • Percentile selection: p50 normal, p75 important, p90+ urgent
  • Dynamic adjustment: increase when recent slot skip rate is high
  • Helius API: getPriorityFeeEstimate returns recommended fee tiers
  • Formula: compute_unit_price = (fee_lamports * 1_000_000) / compute_units

Error Handling

ErrorCauseRecovery
BlockhashNotFoundBlockhash expired (>150 slots / ~60s)Refresh blockhash, rebuild and resend
InsufficientFundsNot enough SOL for feesCheck balance before send, maintain reserve
AccountNotFoundToken account doesn't existCreate ATA before transacting
ProgramFailedToCompleteExceeded compute budgetIncrease compute unit limit
SlippageToleranceExceededPrice moved during executionRetry with fresh quote
TransactionTooLarge>1232 bytesUse ALTs, split into multiple transactions
  • Retry on: BlockhashNotFound, transient network errors, rate limits (429)
  • Abort on: program errors (InstructionError), InsufficientFunds, invalid accounts
  • Blockhash management: fetch a fresh blockhash before each retry, not once upfront
  • Backoff: exponential with jitter, starting at 100ms, capping at 5 seconds

Anti-Patterns

Anti-PatternConsequence
Using legacy transactionsMiss ALT benefits, hit account limit sooner
Hardcoded compute budgetWastes SOL (too high) or gets dropped (too low)
Ignoring simulation resultsTransactions fail on-chain, wasting fees
Not handling blockhash expiryTransactions silently fail after ~60 seconds
Polling when streaming is availableAdds 100-500ms latency vs WebSocket/Geyser
Using sync RpcClient in async contextBlocks the tokio runtime, degrades throughput
Single RPC endpoint with no failoverOne provider outage stops your system
Ignoring rent costsUnexpected SOL drain from account creation

Companion Skills

DomainSkillCoverage
Arbitrage engineeringsolana-arbJupiter integration, MEV protection, profit optimization
Rust engineeringrust-proOwnership, error handling, unsafe audit, async patterns
Performance optimizationperf-rustProfiling, benchmarking, allocation analysis