-
-
Notifications
You must be signed in to change notification settings - Fork 41
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
63 additions
and
0 deletions.
There are no files selected for viewing
63 changes: 63 additions & 0 deletions
63
blockchain_integration/pi_network/DeFi_Integration/LendingProtocol.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,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); | ||
} | ||
} |