From cd7e4e2016c728c50650a16a5093d46baf3a7ad1 Mon Sep 17 00:00:00 2001 From: KOSASIH Date: Sun, 16 Jun 2024 18:21:52 +0700 Subject: [PATCH] Create PILendingPool.sol --- .../contracts/PILendingPool.sol | 41 +++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 blockchain_integration/pi_network/defi_integration/contracts/PILendingPool.sol diff --git a/blockchain_integration/pi_network/defi_integration/contracts/PILendingPool.sol b/blockchain_integration/pi_network/defi_integration/contracts/PILendingPool.sol new file mode 100644 index 000000000..0fd0df456 --- /dev/null +++ b/blockchain_integration/pi_network/defi_integration/contracts/PILendingPool.sol @@ -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; + } +}