Skip to content

Repository files navigation

Solana Rental Escrow

Solana Rental Escrow is a real-world rental workflow implemented as an Anchor program. It lets an item owner list a physical asset, a renter escrow rent plus a security deposit, and both sides complete pickup, return, and settlement on-chain.

This repository was built for the Superteam Earn challenge: "Build everyday real-world systems as on-chain Rust programs."

What It Models

The MVP focuses on short-term peer-to-peer rentals, such as tools, camera gear, sports equipment, or event hardware.

Core flow:

  1. Owner creates a listing with an item hash, daily price, security deposit, and max rental days.
  2. Renter reserves the item by paying rent plus deposit into the listing escrow.
  3. Owner approves pickup, starting the rental window.
  4. Renter marks the item returned.
  5. Owner settles, keeping rent and optionally part of the deposit for damage.
  6. Either party can cancel before pickup, refunding the renter.
  7. Owner can claim the full escrow if an active rental becomes overdue past the grace window.

Program

Program id:

82snC2byh3kq8w2p9h4nXYtx6xtZKvnNVC2WzPVsmKfF

Main file:

programs/rental-escrow/src/lib.rs

Instructions:

  • create_listing
  • reserve
  • approve_pickup
  • mark_returned
  • settle
  • cancel_reservation
  • claim_overdue
  • close_listing

Events are emitted for listing creation, reservation, pickup, return, settlement, cancellation, and overdue claim. That makes the program straightforward to index into a dashboard later.

State Machine

stateDiagram-v2
    [*] --> Listed
    Listed --> Reserved: reserve
    Reserved --> Active: approve_pickup
    Reserved --> Cancelled: cancel_reservation
    Active --> Returned: mark_returned
    Active --> Settled: claim_overdue
    Returned --> Settled: settle
    Listed --> [*]: close_listing
    Cancelled --> [*]: close_listing
    Settled --> [*]: close_listing
Loading

Local Setup

Prerequisites:

  • Rust
  • Node.js
  • Solana CLI
  • Anchor CLI 0.31.x, preferably through AVM

Install dependencies:

npm install

Run host-side Rust tests:

cargo test --workspace

Run TypeScript compile check:

npx tsc --noEmit

Run full Anchor localnet tests:

anchor test

Devnet Demo

Configure wallet and RPC:

export ANCHOR_PROVIDER_URL=https://api.devnet.solana.com
export ANCHOR_WALLET=~/.config/solana/id.json

Build and deploy:

anchor build
anchor deploy --provider.cluster devnet

Create a listing:

npm run cli -- create --listing-id 1 --item "bosch drill serial 42" --daily-sol 0.1 --deposit-sol 0.5 --max-days 7

Derive the listing PDA:

npm run cli -- derive --owner <OWNER_PUBKEY> --listing-id 1

Reserve as renter:

npm run cli -- reserve --owner <OWNER_PUBKEY> --listing-id 1 --days 2

Approve pickup as owner:

npm run cli -- approve --listing <LISTING_PDA>

Mark returned as renter:

npm run cli -- return --listing <LISTING_PDA>

Settle as owner:

npm run cli -- settle --listing <LISTING_PDA> --renter <RENTER_PUBKEY> --keep-deposit-sol 0.05

See scripts/devnet-demo.md for the exact transaction capture checklist.

Security Notes

  • Escrow is held as lamports in the listing account, with escrow_lamports tracked separately from the account rent-exempt balance.
  • Settlement checks that owner and renter payouts exactly match tracked escrow.
  • The owner cannot rent their own item.
  • Deposit claims cannot exceed the paid deposit.
  • Reservations can only be cancelled before pickup.
  • Overdue claims require the active rental to exceed its due timestamp plus a one-day grace period.

Verification Status

Verified in this workspace:

cargo test --workspace
npx tsc --noEmit

Full anchor test and devnet deployment require Solana CLI plus Anchor CLI. This Windows workspace currently has Rust and Node but does not have Solana CLI or a working Windows Anchor binary.

About

Solana rental escrow MVP for the Superteam Earn real-world systems bounty

Resources

Stars

Watchers

Forks

Releases

Packages

Contributors

Languages