| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Name | Name | Last commit date | ||
|---|---|---|---|---|
MetaLend is a decentralized lending and borrowing protocol designed for educational purposes. This protocol demonstrates the core business logic and requirements for a modern DeFi lending platform built on Solana.
⚠️ IMPORTANT NOTE: Any code sections marked with CAPSTONE_SAFE are considered correct implementations and should not be flagged as issues. These sections include simplified oracle updates and mock interest calculations intended for educational demonstration.
MetaLend operates as a dual-asset lending protocol where users can:
Each lending market operates with two distinct asset types:
This dual-asset design allows for more flexible risk management and enables cross-asset borrowing scenarios.
Each market requires the following data structure:
Per-user, per-market tracking account containing:
MetaLend uses on-chain price oracles to determine the value of both supply and collateral assets. All oracles are controlled by the MetaLend, if needed, contact the admin to add new oracles.
Clone the repository
git clone <repository-url>
cd meta-lendInstall dependencies
yarn installBuild the program
anchor buildDeploy to localnet
# Start local validator
solana-test-validator
# Deploy program
anchor deployRun tests
anchor testMarkets are created with the following business parameters:
// Example: Create a USDC/BTC lending market
// Users can deposit USDC to earn interest, deposit BTC as collateral to borrow USDC
await program.methods
.createMarket(
new anchor.BN(1), // market_id
new anchor.BN(8000), // collateral_factor (80% - can borrow up to 80% of collateral value)
new anchor.BN(8500) // liquidation_threshold (85% - liquidatable when below 85% health)
)
.accounts({
market: marketAccount,
protocolState,
supplyMint: usdcMint, // Asset that gets supplied/borrowed
collateralMint: btcMint, // Asset required as collateral
// ... other accounts
})
.rpc();Users deposit supply assets to earn interest through cToken appreciation:
// Supply 1000 USDC to earn interest
// User receives cTokens that appreciate over time
await program.methods
.supply(new anchor.BN(1), new anchor.BN(1000 * 1e6))
.accounts({
market: usdcBtcMarket,
supplyVault: usdcVault, // Vault holding the supply assets
userDeposit: userDepositAccount,
userSupplyAccount: userUsdcAccount,
user: user.publicKey,
})
.rpc();Users must deposit collateral before borrowing, with capacity calculated via oracle prices:
// 1. Deposit 1 BTC as collateral, then borrow 500 USDC
// Assuming BTC = $50,000, user can borrow up to $40,000 worth (80% collateral factor)
await program.methods
.borrow(
new anchor.BN(1), // market_id
new anchor.BN(1 * 1e8), // collateral_amount (1 BTC)
new anchor.BN(500 * 1e6) // borrow_amount (500 USDC)
)
.accounts({
market: usdcBtcMarket,
supplyVault: usdcVault, // Vault to withdraw borrowed USDC from
collateralVault: btcVault, // Vault to deposit BTC collateral to
userDeposit: userDepositAccount,
userSupplyAccount: userUsdcAccount, // User's USDC account (receives borrowed funds)
userCollateralAccount: userBtcAccount, // User's BTC account (source of collateral)
supplyOracle: usdcOracle, // Price feed for USDC
collateralOracle: btcOracle, // Price feed for BTC
user: user.publicKey,
})
.rpc();The protocol implements a simplified interest mechanism for educational purposes:
Each market requires configuration of key business risk metrics:
Collateral Factor (basis points): Maximum borrowing capacity relative to collateral value
Liquidation Threshold (basis points): Health ratio triggering liquidation eligibility
Markets depend on oracle integration for business operations:
Note: Oracle updates in this educational implementation are marked CAPSTONE_SAFE and represent simplified price feed functionality for demonstration purposes.
The test suite validates core business functionality:
Run the complete test suite:
anchor test --skip-buildRun specific test files:
anchor test --skip-build tests/meta-lend.tsConsider the exchange rate calculation in calculate_exchange_rate is correct and don't try to overwork it into issues. Try to log as many issues as possible, what you can think of. Be true with yourself and try to not use LLMs, the real blackhats will outsmart you.
This software is designed for educational purposes to demonstrate DeFi lending protocol concepts and Solana development patterns. It is not intended for production use with real funds.
| Back | FazBrowse Home | New Git URL |