Magpie Protocol
Everything you need to understand how Magpie works under the hood — from on-chain architecture to the credit system.
Overview
Magpie is a memecoin-collateralized lending protocol on Solana, delivered entirely through a Telegram bot. Users pledge memecoin holdings as collateral and receive SOL loans in seconds — no browser extensions, no seed phrases, no new apps to install.
The protocol is designed around three principles: speed (loans fund in under 10 seconds), simplicity (one flat fee, three tiers, no hidden mechanics), and safety (non-custodial, loan-scoped collateral, on-chain liquidation).
Architecture
Magpie's core lending logic lives in an Anchor program deployed on Solana mainnet. The program is the single source of truth for loan state, collateral custody, and liquidation execution.
Program Derived Addresses
Each loan creates a unique PDA (Program Derived Address) seeded by the borrower's public key and a loan nonce. The PDA holds all loan state on-chain:
// Loan PDA fields
{
borrower: Pubkey,
collateral_mint: Pubkey,
collateral_amount: u64,
borrowed_sol: u64,
due_date: i64,
ltv_tier: u8, // 0=Express, 1=Quick, 2=Standard
health_ratio: f64,
status: LoanStatus, // Active | Repaid | Liquidated
}Collateral custody
Collateral is held in loan-scoped token accounts owned by the program PDA — not the user's wallet. This means only the pledged collateral is ever at risk. The user's other holdings are untouchable by the protocol.
Liquidation
Liquidation is deterministic and on-chain. When a loan's health ratio drops below the 1.1x threshold, anyone can call the liquidation instruction. There is no admin override, no manual intervention — the logic is enforced by the program.
Loan Lifecycle
A typical loan moves through the following stages, all orchestrated from a Telegram chat.
Pricing & Oracles
Accurate, manipulation-resistant pricing is critical for a lending protocol. Magpie uses aggregated DEX liquidity via Jupiter's Price API v2 as the primary oracle.
| Source | Purpose | Update frequency |
|---|---|---|
| Jupiter Price API v2 | Loan quotes, health monitoring, liquidation triggers | Real-time per request |
| DexScreener API | Market data display (market cap, volume, 24h change) | ~15s polling |
Why Jupiter?
Jupiter aggregates liquidity across all major Solana DEXes (Raydium, Orca, Meteora, etc.). This makes price manipulation economically infeasible — an attacker would need to move prices across multiple venues simultaneously.
Price usage
- Loan origination: collateral valued in SOL to determine payout
- Health monitoring: continuous repricing to detect undercollateralization
- Liquidation triggers: when health ratio breaches 1.1x threshold
Fee Structure
Magpie uses a simple, transparent fee model. No dynamic APR, no variable haircuts, no hidden charges.
| Action | Fee | Notes |
|---|---|---|
| Loan origination | 1.5% flat | Deducted from SOL disbursement |
| Loan extension | 1.5% flat | Per extension, resets the due date |
| Partial repay | None | Reduces principal proportionally |
| Full repay | None | Collateral returned in full |
| Top-up collateral | None | Improves health ratio |
| Liquidation | None to user | Collateral seized, loan closed |
Credit System
The Magpie Credit Score is an on-platform reputation system that rewards consistent borrowing behavior with better terms. Scores range from 300 to 850 and update after every loan event (repayment, extension, liquidation).
Scoring factors
| Factor | Weight | Description |
|---|---|---|
| Repayment history | 40% | On-time full repayments vs late or liquidated |
| Loan volume | 20% | Total SOL borrowed across all loans |
| Account age | 15% | Time since first loan originated |
| Collateral diversity | 15% | Number of unique token mints pledged |
| Liquidation history | 10% | Inverse of liquidation frequency |
Credit tiers
- Standard rates
- Standard terms
- Community support
- +2% LTV bonus
- Priority support
- Early notifications
- +5% LTV bonus
- Reduced fees (1.25%)
- Extended terms available
- +8% LTV bonus
- 1% origination fee
- Custom terms & early access
Security Model
Security is a core design constraint, not a feature bolted on after the fact. Every layer of the stack is built to minimize trust assumptions.
Wallet Model
Magpie generates and manages Solana keypairs for users who interact through Telegram. The model prioritizes portability and user sovereignty.
Key lifecycle
/start → Fresh Ed25519 keypair generated
→ Private key encrypted with AES-256-GCM
→ Encrypted blob stored in database
→ Public key returned to user as deposit address
/export → Private key decrypted in memory
→ Sent to user via Telegram (ephemeral message)
→ Auto-deleted after 60 seconds
→ User can import into Phantom, Solflare, etc.Deposit addresses
Each loan gets its own deposit address. This is a program-derived token account scoped to the loan PDA. Collateral sent to one loan's address cannot be accessed by another loan or by Magpie directly.
Supported Tokens
Magpie currently supports 64+ Solana memecoins as loan collateral. Tokens are approved based on DEX liquidity depth, trading volume, and price stability requirements.
Approval criteria
- Sufficient DEX liquidity across at least two venues
- Consistent 24h trading volume above minimum threshold
- Price available via Jupiter Price API v2
- No evidence of rug-pull risk or contract vulnerabilities
API & Integration
Magpie integrates several external services and frameworks to deliver the lending experience.
| Layer | Technology | Purpose |
|---|---|---|
| User interface | Telegram Bot API | Chat-based loan management, notifications, wallet export |
| On-chain program | Anchor (Rust) | Loan PDA creation, collateral custody, liquidation logic |
| Blockchain client | Solana Web3.js | Transaction construction, signing, submission, and confirmation |
| Pricing oracle | Jupiter API v2 | Real-time aggregated token pricing across all Solana DEXes |
| Market data | DexScreener API | Market cap, volume, 24h change for display purposes |
| Frontend | Next.js + React | Marketing site, calculator, token browser, dashboard |
Transaction flow
User (Telegram)
│
├─ /borrow → Bot validates input
│ → Jupiter API: fetch price
│ → Anchor: create loan PDA + transfer collateral
│ → Solana Web3.js: disburse SOL
│ → Telegram: send confirmation
│
├─ /repay → Anchor: close loan PDA + return collateral
│ → Telegram: send receipt
│
└─ Health monitor (background)
→ Jupiter API: reprice collateral
→ If health < 1.1x → Anchor: liquidate
→ Telegram: alert user