Skip to content

laina-defi/laina

Repository files navigation

Laina DeFi Protocol

Laina is a low fee, trustless, and easy-to-use decentralized loan platform.

We are focusing on making a simple and efficient DeFi product, where there is minimal need for token swapping or liquidity other than what is used for lending. Our vision is to change DeFi by making it accessible and understandable for everyone, regardless of their technical knowledge or financial status. By providing efficient single-token lending pools, we eliminate the complexities often associated with multi-token systems.

Project Structure

This repository uses the following structure:

.
├── contracts (Stellar Smart Contracts)
│   ├── loan_manager (Deploys pools and manages loans)
│   ├── loan_pool (Holds a single type of token for lending)
│   └── reflector_mock (Mock price oracle for testing)
├── liquidation-bot (Example bot for liquidating unhealthy loans)
├── public (assets)
├── scripts (scripts for deploying & updating Smart Contracts)
├── src (dApp)
│   ├── components (Reusable UI components)
│   ├── contexts (State Contexts)
│   ├── contracts (autogenerated RPC bindings for Smart Contracts)
│   ├── images (Static image assets)
│   ├── layouts (Astro layouts)
│   ├── lib
│   ├── pages
│   └── App.tsx
├── Cargo.toml
└── README.md

Soroban Frontend in Astro

Getting Started

  • cp .env.example .env

Create a stellar account and store it in .env

  • stellar keys generate <name>
  • Change SOROBAN_ACCOUNT in .env to the output of stellar keys address <name>
  • Change SOROBAN_SECRET_KEY in .env to the output of stellar keys show <name>

Initialize contracts

  • npm run init

Install frontend dependencies and start the dev-server

  • npm install
  • npm run dev

Formatting the code

Lint web code

npm run lint

Format web code

npm run format

Format Rust code

cargo fmt

Architecture

Lending flow

sequenceDiagram
    box Front-end
    participant UI
    end
    box Laina Contracts
    participant LendingPool
    participant LoanManager
    end
    box Oracle Contract
    participant PriceOracle
    end

    UI->>LendingPool: get_balance()
    LendingPool-->>UI: Balance

    UI->>LoanManager: get_price()
    LoanManager->>PriceOracle: last_price(Token)
    PriceOracle-->>LoanManager: PriceData
    LoanManager-->>UI: Price

    UI->>LendingPool: get_interest_rate()
    LendingPool->>LoanManager: get_interest_rate(Pool)
    LoanManager-->>LendingPool: Interest rate
    LendingPool-->>UI: Interest rate

    UI->>LendingPool: deposit()
    LendingPool-->>UI: OK/Error
Loading

Borrow flow

sequenceDiagram
    box Front-end
    participant UI
    end
    box Laina Contracts
    participant LendingPool
    participant LoanManager
    end
    box Oracle Contracts
    participant PriceOracle
    end

    UI->>LendingPool: get_available_balance()
    LendingPool-->>UI: Available Balance

    UI->>LendingPool: get_interest_rate()
    LendingPool->>LoanManager: get_interest_rate(Pool)
    LoanManager-->>UI: Interest rate

    UI->>LoanManager: get_price()
    LoanManager->>PriceOracle: last_price(Token)
    PriceOracle-->>LoanManager: PriceData
    LoanManager-->>UI: Price

    UI->>LoanManager: init_loan(token_borrow, borrow_amount, token_collat, collat_amount)
    loop calculate_health_factor()
        LoanManager->>PriceOracle: last_price(token_borrow)
        PriceOracle-->>LoanManager: PriceData
        LoanManager->>PriceOracle: last_price(token_collat)
        PriceOracle-->>LoanManager: PriceData
        LoanManager->>LoanManager: Check that health-factor is over minimum threshold
    end
    LoanManager-->>LendingPool: deposit_collateral()
    LoanManager-->>LendingPool: borrow()
    LoanManager-->>UI: OK/Error
Loading

Liquidate flow

sequenceDiagram
    box Front-end
    participant UI
    end
    box Laina Contracts
    participant LendingPool
    participant LoanManager
    end
    box Oracle Contracts
    participant PriceOracle
    end

    UI->>LoanManager: get_undercol_loans()
    loop calculate_health_factor()
        LoanManager->>PriceOracle: last_price(token_borrow)
        PriceOracle-->>LoanManager: PriceData
        LoanManager->>PriceOracle: last_price(token_collat)
        PriceOracle-->>LoanManager: PriceData
        LoanManager->>LoanManager: Check that health-factor is under minimum threshold
    end
    LoanManager-->>UI: Available Loans

    UI->>LoanManager: liquidate_loan(token_borrow, amount)
    LoanManager-->>UI: OK/Error
    LoanManager-->>UI: if OK: transfer(token_collat, amount+liquidation_bonus)

Loading

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published