Technical documentation

Magpie Protocol

Everything you need to understand how Magpie works under the hood — from on-chain architecture to the credit system.

Introduction

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 thesis: Memecoins represent billions in dormant capital. Holders refuse to sell but can't use that value. Magpie unlocks it as liquidity without forcing a sale.

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

On-chain

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.

Flow

Loan Lifecycle

A typical loan moves through the following stages, all orchestrated from a Telegram chat.

1
Wallet creation
User opens the bot and sends /start. A fresh Solana keypair is generated, encrypted with AES-256-GCM, and stored. The wallet is non-custodial and exportable at any time via /export.
2
Collateral deposit
User receives a unique deposit address scoped to the loan. They send memecoin collateral to this address. A deposit watcher monitors the chain and confirms receipt within 8-12 seconds.
3
Tier selection & quote
User selects a tier: Express (30% LTV, 2 days), Quick (25% LTV, 3 days), or Standard (20% LTV, 7 days). Oracle pricing via Jupiter API values the collateral in SOL and generates a quote.
4
SOL disbursement
SOL is sent to the user's wallet minus the 1.5% origination fee. The loan PDA is created on-chain with all parameters locked in.
5
Active management
While the loan is active, the user can: top-up collateral to improve health, partial-repay to reduce principal, extend the term (1.5% fee), or repay in full to reclaim collateral.
6
Health monitoring
The system continuously monitors collateral value. Alerts fire at 90% health and 24 hours before the due date. Users receive Telegram messages with current health ratio and suggested actions.
7
Resolution
The loan ends one of two ways: the user repays (collateral returned) or health drops below 1.1x and on-chain liquidation executes automatically.
Data

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.

SourcePurposeUpdate frequency
Jupiter Price API v2Loan quotes, health monitoring, liquidation triggersReal-time per request
DexScreener APIMarket 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
Economics

Fee Structure

Magpie uses a simple, transparent fee model. No dynamic APR, no variable haircuts, no hidden charges.

ActionFeeNotes
Loan origination1.5% flatDeducted from SOL disbursement
Loan extension1.5% flatPer extension, resets the due date
Partial repayNoneReduces principal proportionally
Full repayNoneCollateral returned in full
Top-up collateralNoneImproves health ratio
LiquidationNone to userCollateral seized, loan closed
Example: A 30% LTV loan on $1,000 of collateral disburses $300 in SOL. The 1.5% fee is $4.50, so the user receives $295.50 in SOL. Extending once costs another $4.50.
New

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

FactorWeightDescription
Repayment history40%On-time full repayments vs late or liquidated
Loan volume20%Total SOL borrowed across all loans
Account age15%Time since first loan originated
Collateral diversity15%Number of unique token mints pledged
Liquidation history10%Inverse of liquidation frequency

Credit tiers

Bronze
300 - 499
  • Standard rates
  • Standard terms
  • Community support
Silver
500 - 649
  • +2% LTV bonus
  • Priority support
  • Early notifications
Gold
650 - 749
  • +5% LTV bonus
  • Reduced fees (1.25%)
  • Extended terms available
Platinum
750 - 850
  • +8% LTV bonus
  • 1% origination fee
  • Custom terms & early access
All new users start at 500 (Silver). A single on-time repayment can move the score up by 15-25 points. A liquidation can drop it by 50-80 points.
Security

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.

Non-custodial wallets
Users can export their private keys anytime via /export. Magpie never controls assets outside of pledged collateral.
Loan-scoped addresses
Only the specific collateral pledged to a loan is at risk. The user's wallet contents are never accessible to the protocol.
AES-256-GCM encryption
Private keys are encrypted at rest using AES-256-GCM before storage. Keys are never stored in plaintext.
On-chain liquidation
Liquidation is deterministic, auditable, and has no admin override. The program logic is the final authority.
Open source
Both the site and bot code are publicly available on GitHub. Anyone can audit the protocol logic.
Rate limiting & input sanitization
All API endpoints are rate-limited. All user-facing inputs are sanitized to prevent injection attacks.
Infrastructure

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.

Non-custodial guarantee: At no point does Magpie have unilateral access to user funds outside of explicitly pledged collateral held in loan-scoped PDAs.
Collateral

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
Browse all supported tokens
Live prices, market caps, 24h performance, and token request form.
View tokens →
Technical

API & Integration

Magpie integrates several external services and frameworks to deliver the lending experience.

LayerTechnologyPurpose
User interfaceTelegram Bot APIChat-based loan management, notifications, wallet export
On-chain programAnchor (Rust)Loan PDA creation, collateral custody, liquidation logic
Blockchain clientSolana Web3.jsTransaction construction, signing, submission, and confirmation
Pricing oracleJupiter API v2Real-time aggregated token pricing across all Solana DEXes
Market dataDexScreener APIMarket cap, volume, 24h change for display purposes
FrontendNext.js + ReactMarketing 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
Questions? Reach out on Telegram.
← Back to home