Skip to content

Commit

Permalink
Create PILendingPool.sol
Browse files Browse the repository at this point in the history
  • Loading branch information
KOSASIH authored Jun 16, 2024
1 parent e49e972 commit cd7e4e2
Showing 1 changed file with 41 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
pragma solidity ^0.8.0;

import "https://github.com/OpenZeppelin/openzeppelin-solidity/contracts/math/SafeMath.sol";
import "https://github.com/OpenZeppelin/openzeppelin-solidity/contracts/token/ERC20/SafeERC20.sol";

contract PILendingPool {
using SafeMath for uint256;
using SafeERC20 for ERC20;

// Mapping of user addresses to their loan histories
mapping (address => mapping (address => Loan[])) public loanHistory;

// Event emitted when a new loan is created
event LoanCreated(address lender, address borrower, uint256 amount, uint256 interestRate, uint256 maturityDate, uint256 timestamp);

// Function to create a new loan
function createLoan(address borrower, uint256 amount, uint256 interestRate, uint256 maturityDate) public {
require(amount > 0, "Invalid loan amount");
require(interestRate > 0, "Invalid interest rate");
require(maturityDate > block.timestamp, "Invalid maturity date");
ERC20(0x1234567890123456789012345678901234567890).safeTransferFrom(msg.sender, address(this), amount);
Loan memory newLoan = Loan(msg.sender, borrower, amount, interestRate, maturityDate, block.timestamp);
loanHistory[msg.sender][borrower].push(newLoan);
emit LoanCreated(msg.sender, borrower, amount, interestRate, maturityDate, block.timestamp);
}

// Function to calculate the interest on a loan
function calculateInterest(Loanmemory loan) internal pure returns (uint256) {
return loan.amount * loan.interestRate / 100;
}

// Struct to represent a loan
struct Loan {
address lender;
address borrower;
uint256 amount;
uint256 interestRate;
uint256 maturityDate;
uint256 timestamp;
}
}

0 comments on commit cd7e4e2

Please sign in to comment.