Skip to content

This is lending contract like text.fi and rain.fi on solana

Notifications You must be signed in to change notification settings

hexnome/lending-contract

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

2 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Solana Lending Ecosystem Contract

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.

πŸ“ž Contact

  • Telegram: @Ee1030109
  • Project: Solana Lending Ecosystem Contract

πŸš€ Overview

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

πŸ† Competitive Advantage

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

✨ Features

Core Functionality

  • 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

Technical Features

  • 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

πŸ› οΈ Technology Stack

  • Blockchain: Solana
  • Framework: Anchor
  • Language: Rust
  • Frontend SDK: TypeScript
  • Token Standard: SPL Token

πŸ“‹ Prerequisites

πŸš€ Installation

  1. Clone the repository

    git clone <repository-url>
    cd lending-contract
  2. Install dependencies

    yarn install
  3. Build the program

    anchor build
  4. Deploy to localnet (for testing)

    anchor deploy

πŸ“– Usage

Program ID

EZZtc7TU4Dd5Bc1wdQZ9szhsv3cavuHzNCy8Laq1beLU

Available Instructions

1. Configure

Set global protocol configuration (admin only)

await program.methods
  .configure(config)
  .accounts({
    config: configPda,
    authority: admin.publicKey,
  })
  .signers([admin])
  .rpc();

2. Create Loan

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();

3. Borrow Loan

Borrow an existing loan by providing collateral

await program.methods
  .borrowLoan(collateralAmount)
  .accounts({
    loan: loanPda,
    borrower: borrower.publicKey,
    collateralMint: collateralMint,
  })
  .signers([borrower])
  .rpc();

4. Repay Loan

Repay a borrowed loan to retrieve collateral

await program.methods
  .repayLoan()
  .accounts({
    loan: loanPda,
    borrower: borrower.publicKey,
    loanMint: loanMint,
    collateralMint: collateralMint,
  })
  .signers([borrower])
  .rpc();

5. Cancel Loan

Cancel an unborrowed loan offer

await program.methods
  .cancelLoan()
  .accounts({
    loan: loanPda,
    lender: lender.publicKey,
  })
  .signers([lender])
  .rpc();

πŸ§ͺ Testing

Run the test suite:

anchor test

Or run specific tests:

yarn test

πŸ“ Project Structure

lending-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

πŸ”§ Configuration

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

πŸ”’ Security

  • 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

🀝 Contributing

  1. Fork the repository
  2. Create a feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

πŸ“„ License

This project is licensed under the ISC License.

πŸ™ Acknowledgments

  • 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

About

This is lending contract like text.fi and rain.fi on solana

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published