A minimal, Solana vault program in pinocchio and pinocchio-system crates. This program demonstrates secure deposit and withdrawal logic for lamports (native tokens) using program-derived addresses (PDAs) and cross-program invocations (CPIs).
- Deposit:
- Verifies the vault is empty (prevents double deposits)
- Ensures the deposit amount is nonzero
- Transfers lamports from the user to a vault PDA
- Withdraw:
- Verifies the vault contains lamports
- Uses the vault's PDA to sign the transfer
- Transfers all lamports from the vault back to the owner
- Each user has a unique vault account, derived as a PDA from their public key.
- Deposits require the vault to be empty and owned by the system program.
- Withdrawals require the vault to have a positive balance and use the PDA as a signer.
- All logic is implemented in a no_std Rust environment, suitable for blockchain smart contracts.
├── src/
│ ├── lib.rs # Program entrypoint and processor
│ └── instructions/
│ ├── deposit.rs # Deposit instruction logic
│ ├── withdraw.rs # Withdraw instruction logic
│ └── mod.rs # Instruction module exports
├── Cargo.toml # Project manifest and dependencies
├── .gitignore
- Install Rust (nightly recommended for Solana-like targets):
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh rustup default nightly
- Build the project:
The output will be in the
cargo build-sbf
target/directory.
This program is designed to be deployed as a smart contract on a Solana-like blockchain or used as a reference for vault logic. Example usage would involve:
- Creating a vault PDA for a user
- Sending a deposit instruction with the user's account and the vault PDA
- Sending a withdraw instruction to transfer funds back to the user
pinocchio- Solana-like no_std framework for smart contractspinocchio-system- System program instructions for lamport transfers