-
-
Notifications
You must be signed in to change notification settings - Fork 43
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
41 additions
and
0 deletions.
There are no files selected for viewing
41 changes: 41 additions & 0 deletions
41
blockchain_integration/pi_network/defi_integration/contracts/PILendingPool.sol
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |