A decentralized lending protocol built on Solana blockchain using Anchor framework and Rust. This project enables peer-to-peer lending with collateralized loans, providing a secure and efficient lending ecosystem.
- Telegram: @Ee1030109
- Project: Solana Lending Ecosystem Contract
This lending contract allows users to:
- Create Loans: Lenders can create loan offers with specified terms
- Borrow Loans: Borrowers can take loans by providing collateral
- Repay Loans: Borrowers can repay loans to retrieve their collateral
- Cancel Loans: Lenders can cancel unborrowed loan offers
Built to compete with established lending protocols like:
- text.fi - Offering enhanced features and better user experience
- rain.fi - Providing more flexible lending terms and lower fees
- Collateralized Lending: Secure loans backed by digital assets
- Flexible Terms: Customizable loan amounts, interest rates, and durations
- Automatic Expiration: Built-in loan expiration mechanism
- Fee System: Configurable lending and borrowing fees
- Authority Management: Multi-level authority system for protocol governance
- Anchor Framework: Built with Anchor for Solana program development
- Rust Implementation: High-performance, memory-safe smart contracts
- SPL Token Support: Native integration with Solana's token standard
- TypeScript SDK: Full TypeScript support for frontend integration
- Blockchain: Solana
- Framework: Anchor
- Language: Rust
- Frontend SDK: TypeScript
- Token Standard: SPL Token
- Node.js (v16 or higher)
- Rust (latest stable)
- Solana CLI
- Anchor CLI
- Yarn or npm
-
Clone the repository
git clone <repository-url> cd lending-contract
-
Install dependencies
yarn install
-
Build the program
anchor build
-
Deploy to localnet (for testing)
anchor deploy
EZZtc7TU4Dd5Bc1wdQZ9szhsv3cavuHzNCy8Laq1beLU
Set global protocol configuration (admin only)
await program.methods
.configure(config)
.accounts({
config: configPda,
authority: admin.publicKey,
})
.signers([admin])
.rpc();Create a new loan offer
await program.methods
.createLoan(loanAmount, interestRate, duration, collateralAmount)
.accounts({
loan: loanPda,
lender: lender.publicKey,
loanMint: loanMint,
collateralMint: collateralMint,
})
.signers([lender])
.rpc();Borrow an existing loan by providing collateral
await program.methods
.borrowLoan(collateralAmount)
.accounts({
loan: loanPda,
borrower: borrower.publicKey,
collateralMint: collateralMint,
})
.signers([borrower])
.rpc();Repay a borrowed loan to retrieve collateral
await program.methods
.repayLoan()
.accounts({
loan: loanPda,
borrower: borrower.publicKey,
loanMint: loanMint,
collateralMint: collateralMint,
})
.signers([borrower])
.rpc();Cancel an unborrowed loan offer
await program.methods
.cancelLoan()
.accounts({
loan: loanPda,
lender: lender.publicKey,
})
.signers([lender])
.rpc();Run the test suite:
anchor testOr run specific tests:
yarn testlending-contract/
βββ Anchor.toml # Anchor configuration
βββ Cargo.toml # Rust dependencies
βββ package.json # Node.js dependencies
βββ programs/
β βββ lending/
β βββ src/
β β βββ lib.rs # Main program entry point
β β βββ state.rs # Account structures
β β βββ errors.rs # Custom error definitions
β β βββ constants.rs # Program constants
β β βββ utils.rs # Utility functions
β β βββ instructions/
β β βββ mod.rs # Instruction module
β β βββ configure.rs
β β βββ create_loan.rs
β β βββ borrow_loan.rs
β β βββ repay_loan.rs
β β βββ cancel_loan.rs
β βββ Cargo.toml
βββ migrations/
β βββ deploy.ts # Deployment script
βββ tests/ # Test files
The protocol supports the following configurable parameters:
- Authority: Protocol admin address
- Team Wallet: Fee collection address
- Lend Fee: Fee charged to lenders (in basis points)
- Borrow Fee: Fee charged to borrowers (in basis points)
- Expire Duration: Default loan expiration time
- Collateral Verification: All loans require sufficient collateral
- Authority Checks: Proper permission validation for admin functions
- Expiration Handling: Automatic loan expiration to prevent stale offers
- Fee Management: Secure fee collection and distribution
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
This project is licensed under the ISC License.
- Anchor Framework for Solana program development
- Solana Labs for the blockchain infrastructure
- The Solana community for continuous support and feedback
Built with β€οΈ for the Solana ecosystem