AI coding assistant configuration for production-ready Solana blockchain development. Provides modern tooling rules, security best practices, DeFi patterns, and frontend design guidelines.
AI coding assistant configuration for building production-ready Solana applications. This skill provides comprehensive rules, patterns, and best practices for both backend smart contract development and frontend dApp interfaces.
Configures AI assistants to generate secure, modern Solana code by enforcing:
When assisting with Solana development, follow these comprehensive guidelines across backend and frontend domains.
**ALWAYS use current versions:**
```toml
[dependencies]
anchor-lang = "0.32" # Framework with IDL
solana-program = "3.0" # Standard library
pinocchio = "0.10" # Zero-copy, minimal CUs
steel = "4.0" # Native with better DX
[dev-dependencies]
mollusk-svm = "0.7" # Unit testing
litesvm = "0.6" # Integration testing
trident-fuzz = "0.2" # Fuzz testing
```
```json
// Frontend Dependencies
{
"dependencies": {
"next": "^15.0.0",
"react": "^19.0.0",
"@solana/kit": "^2.0.0",
"@solana/wallet-adapter-react": "^0.15.0",
"tailwindcss": "^4.0.0",
"framer-motion": "^11.0.0"
}
}
```
**NEVER use deprecated:**
**ALWAYS validate:**
1. Account ownership: `require!(account.owner == expected_program_id)`
2. Signer status: `require!(authority.is_signer)`
3. PDA derivation: Verify seeds match expected
4. Initialized state: Check discriminators/flags
5. Arithmetic: Use `.checked_add()`, `.checked_mul()`, etc.
**NEVER:**
#### Account Validation Template
```rust
// Anchor pattern
#[account(mut, has_one = authority)]
pub vault: Account<'info, Vault>,
#[account(mut, constraint = user_token.owner == user.key())]
pub user_token: Account<'info, TokenAccount>,
// Native pattern with Pinocchio
let vault = Vault::from_account_info(vault_info)?;
require!(vault.authority == *authority_info.key, ErrorCode::Unauthorized);
require!(authority_info.is_signer, ErrorCode::MustSign);
```
#### DeFi Patterns
**AMM Constant Product:**
```rust
pub fn swap(&mut self, amount_in: u64, minimum_out: u64) -> Result<u64> {
let invariant = self.reserve_a.checked_mul(self.reserve_b)
.ok_or(ErrorCode::Overflow)?;
let new_reserve_a = self.reserve_a.checked_add(amount_in)
.ok_or(ErrorCode::Overflow)?;
let new_reserve_b = invariant.checked_div(new_reserve_a)
.ok_or(ErrorCode::DivisionByZero)?;
let amount_out = self.reserve_b.checked_sub(new_reserve_b)
.ok_or(ErrorCode::InsufficientLiquidity)?;
require!(amount_out >= minimum_out, ErrorCode::SlippageExceeded);
self.reserve_a = new_reserve_a;
self.reserve_b = new_reserve_b;
Ok(amount_out)
}
```
**Vault Share Accounting:**
```rust
pub fn deposit(&mut self, amount: u64) -> Result<u64> {
let shares = if self.total_shares == 0 {
amount // First deposit: 1:1 ratio
} else {
amount.checked_mul(self.total_shares)
.ok_or(ErrorCode::Overflow)?
.checked_div(self.total_assets)
.ok_or(ErrorCode::DivisionByZero)?
};
self.total_assets = self.total_assets.checked_add(amount)?;
self.total_shares = self.total_shares.checked_add(shares)?;
Ok(shares)
}
```
#### Testing Strategy
```rust
// Mollusk unit tests
#[test]
fn test_transfer() {
let program = load_program();
let vault = setup_vault();
let result = program.process_instruction(...);
assert!(result.is_ok());
assert_eq!(vault.balance, expected);
}
// LiteSVM integration
#[test]
fn test_full_flow() {
let svm = LiteSVM::new();
svm.airdrop(&payer, 10_000_000_000);
// Test complete user journey
}
// Trident fuzzing
#[test]
fn fuzz_deposit(amount: u64) {
// Test edge cases automatically
}
```
#### Design System Tokens
```typescript
// Semantic color tokens
const colors = {
background: 'hsl(var(--background))',
foreground: 'hsl(var(--foreground))',
primary: 'hsl(var(--primary))',
'primary-foreground': 'hsl(var(--primary-foreground))',
muted: 'hsl(var(--muted))',
'muted-foreground': 'hsl(var(--muted-foreground))',
}
// 8px grid system
const spacing = {
xs: '0.5rem', // 8px
sm: '1rem', // 16px
md: '1.5rem', // 24px
lg: '2rem', // 32px
xl: '3rem', // 48px
}
```
#### Wallet Connection Component
```typescript
'use client'
import { useWallet } from '@solana/wallet-adapter-react'
import { Button } from '@/components/ui/button'
export function WalletButton() {
const { publicKey, connecting, connect, disconnect } = useWallet()
return (
<Button
onClick={publicKey ? disconnect : connect}
disabled={connecting}
aria-label={publicKey ? 'Disconnect wallet' : 'Connect wallet'}
className="focus-visible:ring-2 focus-visible:ring-primary"
>
{connecting ? 'Connecting...' : publicKey ? `${publicKey.toBase58().slice(0, 4)}...` : 'Connect Wallet'}
</Button>
)
}
```
#### Transaction Flow Component
```typescript
export function TransferDialog() {
const [state, setState] = useState<'idle' | 'confirming' | 'success' | 'error'>('idle')
return (
<Dialog>
{state === 'confirming' && (
<div role="status" aria-live="polite">
<Loader2 className="animate-spin" />
<p>Confirming transaction...</p>
</div>
)}
{state === 'success' && (
<div role="alert">
<CheckCircle className="text-green-500" />
<p>Transfer successful!</p>
</div>
)}
{/* Additional states... */}
</Dialog>
)
}
```
#### Accessibility Requirements
**ALWAYS include:**
**Color contrast:**
| Use Case | Framework | Why |
|----------|-----------|-----|
| Complex DeFi protocol | Anchor 0.32 | IDL generation, rich ecosystem |
| High-performance program | Pinocchio 0.10 | Zero-copy, minimal compute units |
| Modern native Rust | Steel 4.0 | Better DX than raw native |
| Simple stateless logic | Native solana-program | Maximum control |
**Before mainnet deployment:**
1. ✅ All tests passing (unit, integration, fuzz)
2. ✅ Security audit completed
3. ✅ Compute unit optimization verified
4. ✅ Account validation reviewed
5. ✅ Arithmetic overflow checks in place
6. ✅ Upgrade authority configured
7. ✅ Emergency pause mechanism (if applicable)
8. ✅ Multisig for admin operations
**ALWAYS ask user:** "This will deploy to mainnet. Confirm? (yes/no)"
**Type Cosplay:**
```rust
// WRONG: No discriminator check
let vault = Vault::try_from_slice(&account.data.borrow())?;
// CORRECT: Verify account type
require!(account.discriminator == Vault::DISCRIMINATOR);
```
**PDA Exploitation:**
```rust
// CORRECT: Always verify PDA derivation
let (expected_pda, bump) = Pubkey::find_program_address(&[b"vault", user.as_ref()], program_id);
require!(vault.key() == expected_pda, ErrorCode::InvalidPDA);
```
**CPI Signer Spoofing:**
```rust
// CORRECT: Verify signer authority
require!(authority.is_signer, ErrorCode::Unauthorized);
require!(vault.authority == authority.key(), ErrorCode::InvalidAuthority);
```
**Duration guidelines:**
**Framer Motion patterns:**
```typescript
const fadeIn = {
initial: { opacity: 0, y: 20 },
animate: { opacity: 1, y: 0 },
transition: { duration: 0.3, ease: 'easeOut' }
}
<motion.div {...fadeIn}>
<Component />
</motion.div>
```
**Reduced motion:**
```typescript
const prefersReducedMotion = useReducedMotion()
<motion.div
animate={prefersReducedMotion ? { opacity: 1 } : fadeIn.animate}
>
```
1. **Always validate inputs** before state changes
2. **Use semantic naming**: `withdrawVault`, not `function1`
3. **Include error handling** with descriptive messages
4. **Add inline comments** for complex logic only
5. **Follow project formatting** (rustfmt, prettier)
6. **Generate complete examples** with all imports
When generating code:
1. **Explain approach** (1-2 sentences)
2. **Show code** with syntax highlighting
3. **Highlight security considerations** if applicable
4. **Provide usage example** if not obvious
When asked about best practices:
1. **State the principle** clearly
2. **Show correct pattern** with code
3. **Show incorrect pattern** with explanation
4. **Reference documentation** when available
**Example 1: Generate a token vault program**
> User: "Create a token vault program with deposit and withdraw functions"
>
> Agent: I'll create a secure token vault using Anchor 0.32 with proper account validation and checked arithmetic.
>
> [Generates complete Anchor program with validation, tests, and deployment script]
**Example 2: Build wallet connect UI**
> User: "Add a wallet connection button to my Next.js app"
>
> Agent: I'll create an accessible wallet button using @solana/wallet-adapter-react with proper loading states and ARIA labels.
>
> [Generates component with TypeScript, accessibility attributes, and error handling]
**Example 3: Security review**
> User: "Review this swap function for security issues"
>
> Agent: I've identified 3 issues: (1) Missing slippage check, (2) Unchecked arithmetic, (3) No owner validation.
>
> [Provides corrected code with explanations]
Leave a review
No reviews yet. Be the first to review this skill!
# Download SKILL.md from killerskills.ai/api/skills/solana-development-expert/raw