A Solana smart contract built with Quasar that lets users deposit and withdraw SOL into a personal vault secured by a PDA (Program Derived Address).
Quasar is a Solana program development framework for writing blazing fast SVM programs. Programs are #![no_std] by default — accounts are pointer-cast directly from the SVM input buffer with no deserialization, no heap allocation, and no copies.
You write #[program], #[account], and #[derive(Accounts)] like Anchor, but the generated code compiles down to near-hand-written CU efficiency.
Built by @blueshift — github.com/blueshift-gg/quasar
quasar_vault/
├── src/
│ ├── lib.rs # Program entrypoint — declares instructions
│ ├── instructions/
│ │ ├── mod.rs # Exports all instructions
│ │ ├── deposit.rs # Deposit instruction logic
│ │ └── withdraw.rs # Withdraw instruction logic
│ └── tests.rs # Integration tests using QuasarSvm
├── Cargo.toml
├── Quasar.toml
└── README.md
Each user gets their own vault — a PDA derived from their wallet address:
vault PDA = ["vault", user_pubkey] owned by quasar_vault program
- Deposit — User transfers SOL from their wallet into their vault via the system program
- Withdraw — Program transfers SOL back from the vault to the user
#[instruction(discriminator = 0)]
pub fn deposit(ctx: Ctx<Deposit>, amount: u64) -> Result<(), ProgramError>| Account | Type | Description |
|---|---|---|
user |
Signer |
The user depositing SOL |
vault |
UncheckedAccount |
PDA vault — seeds: ["vault", user] |
system_program |
Program<System> |
Solana system program for CPI transfer |
#[instruction(discriminator = 1)]
pub fn withdraw(ctx: Ctx<Withdraw>, amount: u64) -> Result<(), ProgramError>| Account | Type | Description |
|---|---|---|
user |
Signer |
The user withdrawing SOL |
vault |
UncheckedAccount |
PDA vault — seeds: ["vault", user] |
git clone https://github.com/mishalturkane/quasar_vault
cd quasar_vaultCompiles the program to a .so binary:
quasar buildOutput: target/deploy/quasar_vault.so
Runs integration tests using the local QuasarSvm simulator. No real SOL is used:
quasar testNote: Always run
quasar buildbeforequasar testso the.sofile exists.
Gives a per-instruction CU (Compute Unit) breakdown with an interactive flamegraph:
quasar profileOutput example:
quasar_vault 484 CU
441 91.1% entrypoint
43 8.9% [unknown]
flamegraph http://127.0.0.1:7777/?program=quasar_vault
# Get free devnet SOL first
solana airdrop 2 --url devnet
# Deploy to devnet
quasar deploy --devnet
# Deploy to mainnet
quasar deploy --mainnetTests are written using QuasarSvm — a local Solana VM that runs entirely in memory. No real SOL is used during tests.
Located in src/tests.rs.
User starts : 10 SOL
Deposits : 1 SOL → vault
──────────────────────────────────
User after : 9 SOL
Vault after : 1 SOL
User starts : 10 SOL
Deposits : 1 SOL → vault
Withdraws : 0.5 SOL ← vault
──────────────────────────────────
User after : 9.5 SOL
Vault after : 0.5 SOL
Account::from_paircreates fake in-memory accounts with any balance- Vault must be owned by
crate::IDso the program can debit it on withdraw - PDA derived with
Pubkey::find_program_address(&[b"vault", user.as_ref()], &crate::ID) assert_eq!verifies exact lamport values after each operation
A special account address with no private key — only the owning program can sign for it:
let (vault, _bump) = Pubkey::find_program_address(
&[b"vault", user.as_ref()],
&crate::ID,
);Only the owner of an account can debit its lamports. Setting vault owner to your program ID ensures only your program can withdraw from it — not any random caller.
1 SOL = 1,000,000,000 lamports
[dependencies]
quasar-lang = { git = "https://github.com/blueshift-gg/quasar" }
solana-instruction = { version = "3.2.0" }
[dev-dependencies]
quasar_vault-client = { path = "target/client/rust/quasar_vault-client" }
quasar-svm = { git = "https://github.com/blueshift-gg/quasar-svm" }
solana-account = { version = "3.4.0" }
solana-address = { version = "2.2.0", features = ["decode"] }
solana-instruction = { version = "3.2.0", features = ["bincode"] }
solana-pubkey = { version = "4.1.0" }- Quasar — Blazing fast Solana program framework by @blueshift
- QuasarSvm — Local Solana VM for testing
- Rust — Systems programming language
MIT