Contracts
Lendingpoolcreator

Lending Pool

The LendingPool contract allows lenders to deposit tokens and earn interest on their deposits. Borrowers can borrow a limited amount of tokens and pay them back with interest within a specified time period. Lenders can withdraw their deposited tokens with earned interest.

Contract Details

  • Solidity Version: ^0.8.13
  • License: MIT

State Variables

  • token: The instance of the ERC20 token used in the pool.
  • tokenAddress: The address of the ERC20 token used in the pool.
  • totalPoolSupply: The total supply of tokens in the pool.

Structs

Amount

struct Amount {
    uint256 amount;
    uint256 start;
}

Represents the amount and start date of a borrowing or lending operation.

  • amount: The amount of tokens.
  • start: The timestamp when the operation started.

Mappings

  • lendAmount: Maps addresses to the Amount struct for lenders.
  • earnedInterest: Maps addresses to the earned interest by lenders.
  • lenders: Maps addresses to their lender status.
  • borrowers: Maps addresses to their borrower status.
  • borrowAmount: Maps addresses to the Amount struct for borrowers.
  • payInterest: Maps addresses to the interest to be paid by borrowers.

Events

Deposit

event Deposit(address user, uint256 amount);

Emitted when tokens are deposited into the pool.

  • user: The address of the user depositing tokens.
  • amount: The amount of tokens deposited.

Withdraw

event Withdraw(address user, uint256 amount);

Emitted when tokens are withdrawn from the pool.

  • user: The address of the user withdrawing tokens.
  • amount: The amount of tokens withdrawn.

Borrow

event Borrow(address user, uint256 amount);

Emitted when tokens are borrowed from the pool.

  • user: The address of the user borrowing tokens.
  • amount: The amount of tokens borrowed.

Repay

event Repay(address user, uint256 amount);

Emitted when tokens are repaid to the pool.

  • user: The address of the user repaying tokens.
  • amount: The amount of tokens repaid.

Public Functions

calculateRepayAmount

function calculateRepayAmount(address user, uint256 repayAmount) public view returns (uint256 amount)

Calculates the total amount to be repaid by the borrower, including interest.

  • user: The address of the borrower.
  • repayAmount: The amount to be repaid.

calculateWithdrawAmount

function calculateWithdrawAmount(address user, uint256 withdrawAmount) public view returns (uint256 amount)

Calculates the total amount to be withdrawn by the lender, including interest.

  • user: The address of the lender.
  • withdrawAmount: The amount to be withdrawn.

updateBorrow

function updateBorrow(address user) public returns (uint256 interestAmount)

Updates the interest amount to be paid by the borrower.

  • user: The address of the borrower.

updateLend

function updateLend(address user) public returns (uint256 interestAmount)

Updates the interest amount earned by the lender.

  • user: The address of the lender.

deposit

function deposit(uint256 _amount, address user) external

Allows users to deposit tokens into the lending

pool.

  • _amount: The amount of tokens to be deposited.
  • user: The address of the user depositing tokens.

borrow

function borrow(uint256 _amount, address user) external

Allows users to borrow tokens from the lending pool.

  • _amount: The amount of tokens to be borrowed.
  • user: The address of the user borrowing tokens.

repay

function repay(address user, uint256 amount) external

Allows borrowers to repay the borrowed tokens.

  • user: The address of the user repaying tokens.
  • amount: The amount of tokens to be repaid.

withdraw

function withdraw(address user, uint256 amount) external

Allows lenders to withdraw their deposited tokens.

  • user: The address of the user withdrawing tokens.
  • amount: The amount of tokens to be withdrawn.

liquidate

function liquidate(address user, uint256 amount) public

Liquidates the borrower's position, transferring the borrowed tokens to the pool and rewarding the liquidator with a percentage of the tokens.

  • user: The address of the borrower to be liquidated.
  • amount: The amount of tokens to be liquidated.