Skip to main content
rule

solana-wallet-aware — Cursor rule for Solana security

This Cursor rule adds wallet and transaction safeguards to Solana code, from isolated signing to tests required before live transactions.

Install into Cursor · Manually: put the files in place All methods and platforms ↓
.cursor/rules/solana-wallet-aware.mdc
Open on GitHub

What solana-wallet-aware does

The rule applies to ts, tsx, js, jsx, py, and rs files. It bars raw private keys from .env files, configs, and source code, and calls for a signer in a separate process. That process accepts a prepared transaction and returns a signature; it has no network access and uses an explicit program ID allowlist.

For MEV defense, the guidance routes swaps through Jito bundles, compares Jupiter quotes with Pyth prices, and skips tokens whose deepest pool has less than $1M TVL. Before signing, code should inspect every instruction, cap SOL outflow, and check blockhash freshness. Compute budgets above 200k CU need explicit approval.

Live signing must wait for user approval and fault-injection tests covering signer and RPC failures, stale blockhashes, rejected allowlist entries, and spend-cap enforcement. A key that has touched .env on a developer machine is treated as compromised permanently.

What it helps with

  • keep raw private keys out of project files
  • run transaction signing in an isolated process
  • reject swaps that exceed the Pyth price threshold
  • block transactions that invoke unapproved program IDs
  • check transaction instructions and spending limits before signing

Example prompts for the agent

  • Review this Solana code against the wallet-safety and signing rules.
  • Add a program ID allowlist check before signing this transaction.
  • Check that the wallet automation passes simulation and fault-injection tests before live signing.

How to install solana-wallet-aware

Manually: put the files in place

.cursor/rules/solana-wallet-aware.mdc

Frontmatter: description, globs, alwaysApply

Step by step, with commands for each platform: Cursor rules: .mdc files, four modes and what replaced .cursorrules

Questions about solana-wallet-aware

How do I install solana-wallet-aware in Cursor?

Place the rule file at .cursor/rules/solana-wallet-aware.mdc.

What does solana-wallet-aware do?

It sets Solana wallet and transaction safeguards, including signer isolation, program allowlists, spending limits, and pre-signing checks.

When can wallet automation move from simulation to live signing?

Only after explicit user approval and fault-injection tests for signer and RPC failures, stale blockhashes, rejected allowlist entries, and spend-cap enforcement.

Source text

solana-wallet-aware.mdc · CC0-1.0
---
description: "Guidelines for writing Solana-native code with wallet-security awareness, isolated signer subprocesses, MEV defense, oracle gates, and transaction safety checks"
globs: **/*.{ts,tsx,js,jsx,py,rs}
alwaysApply: false
---
# Solana Wallet-Aware Coding

When writing Solana on-chain or off-chain code, apply these wallet-safety and transaction-safety rules.

## Wallet architecture

- Never store a raw private key in `.env`, config files, or source. Encrypt with a passphrase-derived key (HKDF-SHA256 + AES-256-GCM, or `eth-account`'s scrypt V3 keystore, or `libsodium`'s sealed-box).
- Use a three-tier wallet split at $1k+ scale: **hot** (bot-signing, ≤10% of AUM), **warm** (manual-top-up buffer on founder phone, ~30%), **cold** (hardware wallet or Squads 2-of-2 multisig, ~60%, untouchable ≥6 months).
- Treat the hot wallet as burnable. Any key that ever touched a `.env` file on a dev machine is compromised forever.
- Isolate the signer in a subprocess with only two capabilities: (a) receive a pre-built transaction over a local Unix socket / stdin, (b) return a signature. No network access, no program-scope escalation, explicit allowlist of program IDs.

## MEV defense on Solana

- Never broadcast swaps to the public mempool. Always use Jito bundles with a per-bundle tip (start at 10k lamports, scale with expected profit).
- Add an oracle gate: reject a trade if Jupiter's quoted price is > 0.5% off Pyth's spot price. Update threshold dynamically with 1-minute realized volatility.
- Maintain an illiquidity blocklist: skip any token where the deepest pool has < $1M TVL (use GeckoTerminal or Birdeye API to check).
- For limit-style orders, prefer Jupiter's limit-order program (built-in MEV protection) over composing your own.

## Program-ID allowlist pattern

When building a signer, hard-code the list of program IDs your bot may invoke. Reject any transaction whose instructions touch a program outside the allowlist. At minimum for a Solana trading bot:

```
const ALLOWED_PROGRAMS = new Set([
  "JUP6LkbZbjS1jKKwapdHNy74zcZ3tLUZoi5QNyVTaV4",  // Jupiter v6
  "opnb2LAfJYbRMAHHvqjCwQxanZn7ReEHp1k81EohpZb",  // OpenBook v2
  "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA",  // SPL Token
  "ComputeBudget111111111111111111111111111111",  // Compute budget
  // add your DEX IDs here — NEVER include unknown programs
]);
```

## Transaction-safety invariants

Before signing ANY transaction:
- Deserialize + inspect every instruction. No opaque "signTransaction(bytes)" without parsing.
- Enforce a max SOL outflow per transaction AND per rolling 24h window (spend-cap circuit breaker).
- Require a freshness check on the blockhash (slot age < 150 or transaction will likely expire).
- Compute budget ≤ 200k CU default; require explicit opt-in for higher.

## Simulation gate

Do not move wallet-automation code from simulation to live signing until the user has explicitly approved it and the implementation has passed fault-injection tests for signer failure, RPC failure, stale blockhashes, rejected allowlist entries, and spend-cap enforcement.

## Operational safety

- Keep deployment credentials, wallet keys, RPC credentials, and monitoring tokens out of source control.
- Add health checks for signer availability, stale blockhashes, RPC error rate, and transaction failure rate.
- Require an explicit manual approval path before raising spend caps, program allowlists, or compute-unit limits.

© PatrickJS · CC0-1.0 · PatrickJS/awesome-cursorrules

Similar IDE rules

Everything for Finance and business →

From the same set210

solidjs-typescript-cursorrules-prompt-file This rule guides Cursor through Solid.js and TypeScript conventions, from typed reactive state to component props. Use it when you want those practices reflected in code suggestions. ★ 41,024repo stars solidjs-tailwind-cursorrules-prompt-file A Cursor rule that tells the agent how to write Solid.js code with Tailwind CSS: signals, utility classes, folder layout. ★ 41,024repo stars solidity-react-blockchain-apps-cursorrules-prompt- This Cursor rule guides Solidity contracts and React apps that connect to blockchain services. Use it when reviewing contract safety or Web3 frontend code. ★ 41,024repo stars solidity-hardhat-cursorrules-prompt-file A Cursor rule that turns the AI assistant into a Solidity and smart contract security expert, with Hardhat-based testing and gas work. ★ 41,024repo stars snowflake-snowpark-dbt-cursorrules-prompt-file A Cursor rule that gives the agent context for Snowpark Python and dbt with the Snowflake adapter. Useful when you write transformation pipelines in either tool. ★ 41,024repo stars snowflake-data-engineering-cursorrules-prompt-file Snowflake data engineering rules for Cursor: SQL standards, semi-structured VARIANT handling, declarative Dynamic Tables, and warehouse cost control. ★ 41,024repo stars snowflake-cortex-ai-cursorrules-prompt-file This Cursor rule covers Snowflake Cortex AI Functions and Cortex Search. Use it for SQL-based AI tasks or to build a retrieval-augmented search flow. ★ 41,024repo stars shopify-theme-dev-liquid A Cursor rule collecting Shopify theme practices across Liquid, JavaScript, CSS, accessibility and performance. Useful when you build a theme and want the agent to keep the structure. ★ 41,024repo stars

Project sponsors

Companies that keep this analytics open
Gold sponsor

Impressions, clicks and code copies — open statistics. We keep the numbers public for the same reason NeBlask itself is public. Become a sponsor