Skip to content

Latest commit

Β 

History

History
129 lines (92 loc) Β· 3.71 KB

File metadata and controls

129 lines (92 loc) Β· 3.71 KB

πŸͺ™ Solana Programmable Money (Stablecoin Lending Protocol)

This project implements a collateralized stablecoin protocol on Solana, inspired by MakerDAO and other DeFi lending models.
Users can deposit SOL as collateral and mint a protocol-native stablecoin, with on-chain health factor and liquidation logic.


πŸ“Œ Features

  • βœ… Deposit SOL as collateral
  • βœ… Mint stablecoins against collateral
  • βœ… Redeem collateral by burning stablecoins
  • βœ… Liquidate undercollateralized positions
  • βœ… On-chain health factor enforcement
  • βœ… Configurable risk parameters (liquidation threshold, bonus, etc.)
  • βœ… Mocked price feed using Pyth PriceUpdateV2
  • βœ… Full PDA-driven state management
  • βœ… Built with Rust + Anchor Framework

πŸ›οΈ Program Architecture

πŸ“‚ Key Accounts:

Account Purpose
Config Stores global risk parameters & mint PDA
Collateral Per-user collateral state (SOL balance, debt)
SOL Account (PDA) PDA holding user’s deposited SOL (collateral)
Mint Account PDA minting the protocol stablecoin
Token Account User’s ATA for receiving stablecoins

🧱 Instructions Implemented:

Instruction Purpose
initialize_config Set up protocol config & mint
update_config Authority can update risk params
deposit_collateral_and_mint_tokens Deposit SOL + Mint stablecoins
redeem_collateral_and_burn_tokens Burn stablecoins + Redeem SOL
liquidate Liquidate unhealthy positions

πŸ§ͺ Testing (In Progress / Optional)

  • βœ… Local testing with mocked Pyth oracles
  • βœ… Health factor & liquidation edge cases
  • βœ… Token balances & mint authority checks

You can run:

anchor test --skip-build

(Make sure LiteSVM or local validator is set up)


βš™οΈ Tech Stack

  • Rust
  • Anchor
  • Solana Program Library (SPL Token2022)
  • Pyth Oracles (Mocked for testing)
  • Anchor LiteSVM (for fast in-memory testing)

🚨 Disclaimer

This is a learning-focused project built for educational purposes only. It is NOT audited, NOT production-ready, and has incomplete safety checks. Do NOT deploy this on Solana Mainnet.


πŸ“‚ Project Structure

programs/
└── stablecoin/
    └── src/
        β”œβ”€β”€ instructions/
        β”‚   β”œβ”€β”€ admin/
        β”‚   β”‚   β”œβ”€β”€ initialize_config.rs
        β”‚   β”‚   β”œβ”€β”€ update_config.rs
        β”‚   β”‚   └── mod.rs
        β”‚   β”œβ”€β”€ deposit/
        β”‚   β”‚   β”œβ”€β”€ deposit_collateral_and_mint_tokens.rs
        β”‚   β”‚   β”œβ”€β”€ utils.rs
        β”‚   β”‚   └── mod.rs
        β”‚   β”œβ”€β”€ withdraw/
        β”‚   β”‚   β”œβ”€β”€ redeem_collateral_and_burn_tokens.rs
        β”‚   β”‚   β”œβ”€β”€ liquidate.rs
        β”‚   β”‚   β”œβ”€β”€ utils.rs
        β”‚   β”‚   └── mod.rs
        β”‚   └── mod.rs
        β”œβ”€β”€ state.rs
        β”œβ”€β”€ constants.rs
        β”œβ”€β”€ error.rs
        β”œβ”€β”€ lib.rs
        └── mod.rs

βœ… Next Steps (Learning Roadmap)

  • Improve interest rate & debt modeling
  • Add real Pyth testnet feeds
  • Build a frontend (Next.js / React) for UI
  • Explore permissionless minting models

πŸ“ License

MIT License (For educational use only)