Skip to content

Commit

Permalink
Create LendingProtocol.sol
Browse files Browse the repository at this point in the history
  • Loading branch information
KOSASIH authored Jul 28, 2024
1 parent f0b4866 commit 7b3bb22
Showing 1 changed file with 63 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
pragma solidity ^0.8.0;

import {DeFiIntegration} from "./DeFiIntegration.sol";
import {ERC20} from "./ERC20.sol";

contract LendingProtocol {
// Mapping of lenders to their corresponding lending balances
mapping (address => uint256) public lendingBalances;

// Mapping of borrowers to their corresponding borrowing balances
mapping (address => uint256) public borrowingBalances;

// Event emitted when a lender deposits Pi Coin into the lending protocol
event LenderDeposit(address indexed lender, uint256 amount);

// Event emitted when a borrower borrows Pi Coin from the lending protocol
event BorrowerBorrow(address indexed borrower, uint256 amount);

// Event emitted when a borrower repays a loan on the lending protocol
event BorrowerRepay(address indexed borrower, uint256 amount);

// Function to deposit Pi Coin into the lending protocol
function deposit(uint256 _amount) public {
// Transfer Pi Coin from lender to lending protocol
DeFiIntegration.transferFrom(msg.sender, address(this), _amount);

// Update lender's lending balance
lendingBalances[msg.sender] += _amount;

// Emit lender deposit event
emit LenderDeposit(msg.sender, _amount);
}

// Function to borrow Pi Coin from the lending protocol
function borrow(uint256 _amount) public {
// Check if borrowing protocol has sufficient liquidity
require(lendingBalances[msg.sender] >= _amount, "Insufficient liquidity");

// Transfer Pi Coin from lending protocol to borrower
DeFiIntegration.transfer(msg.sender, _amount);

// Update borrower's borrowing balance
borrowingBalances[msg.sender] += _amount;

// Emit borrower borrow event
emit BorrowerBorrow(msg.sender, _amount);
}

// Function to repay a loan on the lending protocol
function repay(uint256 _amount) public {
// Check if borrower has sufficient DeFi balance
require(DeFiIntegration.defiBalances[msg.sender] >= _amount, "Insufficient DeFi balance");

// Transfer Pi Coin from borrower to lending protocol
DeFiIntegration.transferFrom(msg.sender, address(this), _amount);

// Update borrower's borrowing balance
borrowingBalances[msg.sender] -= _amount;

// Emit borrower repay event
emit BorrowerRepay(msg.sender, _amount);
}
}

0 comments on commit 7b3bb22

Please sign in to comment.