---
A reproducible Solana smart contract boilerplate starts with Anchor v0.29+. Run `anchor init <project-name>` to generate the canonical structure:
```text
/programs/<project-name>/src/lib.rs // On-chain logic
/tests/<project-name>.ts // TypeScript integration tests
/app/ // Optional: React/Next.js client SDK
/Anchor.toml // Cluster config & program IDs
/migrations/ // Deploy scripts (optional)
```
Why it matters: This layout separates consensus-critical code from off-chain tooling, making it easier for auditors to scope the review. Keep `lib.rs` lean—delegate instruction handlers to modules under `src/instructions/` and state definitions to `src/state/`.
---
Before pushing to CI, run the Rust toolchain’s built-in checks and Solana-specific linters:
```bash
cargo fmt --all -- --check
cargo clippy --workspace -- -D warnings
cargo audit
cargo test-sbf -- --nocapture
```
Add a `.pre-commit-config.yaml` or GitHub Actions workflow to block merges that fail these steps. This satisfies the baseline hygiene expected in any Web3 developer starter kit and reduces audit finding noise.
---
| Layer | Tool | Scope |
|-------|------|-------|
| Unit | `#[test]` in Rust | Pure logic (math, PDA derivation, state transitions) without runtime. |
| Integration | `solana-test-validator` + TypeScript (Mocha/Jest) | Full transaction lifecycle: rent, CPI, account resizing, clock sysvar. |
| Fuzzing/Property | `trident-fuzz` or `proptest` | Invariant checking (e.g., "total supply never exceeds minted"). |
Practical tip: Use Bankrun (`solana-bankrun`) for deterministic, parallelizable integration tests that don’t require a local validator process. It cuts CI runtime by 60–80% compared to `solana-test-validator`.
---
Auditors charge premium rates for findings you can catch in 30 minutes. Complete these before signing an engagement letter:
1. Integer Safety: Replace all `+`/`-`/`*` with `checked_*` or `saturating_*`; use `anchor_lang::prelude::*` safe math traits.
2. Account Validation: Every `#[account]` struct implements `AccountDeserialize` + `AccountSerialize`; enforce `has_one` / `constraint` checks on cross-program invocations.
3. Signer & Authority Checks: Verify `Signer` constraints on all mutating instructions; ensure `mint_authority` and `freeze_authority` are set to `None` or a multisig *before* mainnet deploy.
4. Token-2022 Compliance: If using extensions (confidential transfers, transfer hooks), run `spl-token-2022` CLI simulations against your program ID.
5. Event & Log Hygiene: Emit typed events (`#[event]`) for all state changes; avoid `msg!` for critical data—indexers rely on events.
---
If your program handles a token sale, vesting, or liquidity bootstrapping, treat this as a distinct workstream. A Solana token sale checklist should cover:
---
1. Scaffold: `anchor init` → modularize `src/` into `instructions/`, `state/`, `errors/`, `events/`.
2. Hardening: Enable `cargo clippy -D warnings`, `cargo audit`, `cargo fmt