Skip to content

Latest commit

Β 

History

6 Commits

Folders and files

NameName
Last commit message
Last commit date
Β 
Β 
Β 
Β 

Repository files navigation

🏦 Pinocchio Vault on Solana

This project implements a simple lamport vault on Solana using Pinocchio, a lightweight Solana-compatible framework.

Users can securely deposit and withdraw lamports (Solana’s smallest denomination) into a vault derived from their public key using a Program Derived Address (PDA). Only the original depositor can withdraw the funds.

πŸ’‘ Built as part of the Blueshift Pinocchio Vault Challenge


πŸ”§ Features

  • πŸ“₯ Deposit lamports into a vault securely
  • πŸ“€ Withdraw lamports back to the depositor
  • πŸ›‘οΈ Enforces PDA ownership and vault uniqueness
  • πŸ”’ Rent-exempt checks for deposit safety
  • 🧠 Demonstrates PDA signing and CPI (Cross-Program Invocation)

πŸ› οΈ Installation & Setup

Make sure you have Rust and the Pinocchio toolchain installed.

# Create a new cargo workspace
cargo new blueshift_vault --lib --edition 2021
cd blueshift_vault

# Add dependencies
cargo add pinocchio pinocchio-system

Update your Cargo.toml to support dynamic libraries:

[lib]
crate-type = ["lib", "cdylib"]

πŸ“ Project Structure

All logic is implemented inside lib.rs, including:

  • Vault PDA Derivation
  • Deposit & Withdraw Instructions
  • Account Validation & Ownership Checks

πŸ“€ Deposit Flow

  • Validates the vault is empty (no double deposits)
  • Checks that deposit amount is non-zero and rent-exempt
  • Transfers lamports using a CPI to the system program

πŸ“₯ Withdraw Flow

  • Ensures the vault contains lamports
  • Re-derives the PDA from the owner's pubkey
  • Vault signs the transfer using PDA signing via invoke_signed

πŸ§ͺ Build

To compile the program for Solana’s SBF (Sealevel BPF) format:

cargo build-sbf

This will generate a .so file in target/deploy/.

πŸ§ͺ Deploy

To deploy

solana program deploy target/deploy/example_program.so --program-id ./target/deploy/example_program-keypair.json

Deployed on devnet:

https://explorer.solana.com/tx/2hoKMpqNnwAsokRfEKqg4rD7ufY9bpZf9sKYEDzam7uKN3NTZuLu9oWkurukSSvxYavdvWPY9ywyNvC3wvFLFf4?cluster=devnet

🏁 Taking the Challenge

Once built, go to the Pinocchio Vault Challenge page and upload your .so file to test it and claim your on-chain NFT.


πŸ™ Credits

This project is based on the excellent guide by Blueshift.
Special thanks to their educational challenge:
πŸ‘‰ Pinocchio Vault Challenge


πŸ“œ License

MIT License Β© 2025
Built with ❀️ by [Your Name or GitHub handle]

About

Pinocchio Vault Challenge @ https://learn.blueshift.gg/

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages