Skip to content

tusharpamnani/pinnochio-vault

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Pinnochio Vault

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).

Features

  • 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

How It Works

  • 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.

Directory Structure

├── 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

Build Instructions

  1. Install Rust (nightly recommended for Solana-like targets):
    curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
    rustup default nightly
  2. Build the project:
    cargo build-sbf
    The output will be in the target/ directory.

Example Usage

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

Dependencies

  • pinocchio - Solana-like no_std framework for smart contracts
  • pinocchio-system - System program instructions for lamport transfers

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages