// SPDX-License-Identifier: MIT pragma solidity ^0.7.1; contract FastLoan { // consider using access control from openzepplin for Escrow part. struct LoanRequest { address borrower; uint projectID; string projectTitle; uint projectDuration; uint amount; //uint bonus; //uint certifications -offchain; //string description - offchain; } struct Loan { //uint id; uint projectID; address lender; address borrower; uint amount; uint interestAmount; uint paymentEndTime; uint numberOfInstallments; bool isClosed; //uint certTarget; // Target number of certifications //uint curCert; // Current number of certifications //string description; } struct CreditHistoryOracle{ uint creditScore; uint dateCreditScoreReceived; } mapping (address => CreditHistoryOracle) borroweCreditHistory; // Current implementation: nonce as state variable counter uint256 private nonce; // Request info bytes32[] public requestIDs; mapping(bytes32 => LoanRequest) public requests; // Loan info. // one loan per user. mapping(address => bytes8) public userLoan; mapping(bytes32 => Loan) public loanDB; // Aggregate Lenders info address[] public allLenders; //mapping(address => string) public userMap; // Aggregate borrowers' info address[] public allBorrowers; //mapping(address => string) public userMap; // User-specific information //mapping(address => Reputation) public reputation; //mapping (address => uint) public balanceOf; mapping(address => uint) public debt; // All projects ever started (excludes requests) bytes8[] public allProjects; mapping(address => bytes8[]) public userProjects; // Validators mapping(bytes8 => address[]) public Validators; // Super validator address public superValidator; constructor (){ superValidator = msg.sender; nonce = 0; } event Request(address, uint256, uint); // event LoanApproval(address, uint256, ) // create and submit request. function submitLoanRequest(address _borrower, uint256 _amount, uint256 _projectId, string memory _projectTitle, uint _projectDuration) public { bytes32 _requestId = keccak256(abi.encodePacked(_borrower, _amount, nonce, address(this))); nonce += 1; requests[_requestId] = LoanRequest(_borrower, _projectId, _projectTitle, _projectDuration, _amount); requestIDs.push(_requestId); emit Request(_borrower, _amount, _projectId); } // approve submitted request. Should be done by the superValidator or delegated validator function approveLoanRequest(address _validator, bytes32 _requestId, address _lender, uint _numberOfInstallments) public { require(_validator == superValidator, "Approval can only be set by superValidator"); loanDB[_requestId].lender = _lender; loanDB[_requestId].projectID = requests[_requestId].projectID; loanDB[_requestId].borrower = requests[_requestId].borrower; uint loanAmount = loanDB[_requestId].amount; //TASK: need to revise w/ SafeMath uint interest = loanAmount * 5 / 100; loanDB[_requestId].interestAmount = interest; //NOTE: fixed duration set at 6 months uint fixedDuration = 15552000; loanDB[_requestId].paymentEndTime = block.timestamp + fixedDuration; loanDB[_requestId].numberOfInstallments = _numberOfInstallments; loanDB[_requestId].isClosed = false; } //terminate Loan when the loan is paid function terminateLoan() public{ } // record the payments of the loans / the installment process function recordPayment() public { } //default in loan payments function defaultInPayment() public { } //getters function getRequests() public { } function getBorrowers() public { } function getLenders() public { } function getProjectIdOfLoanRequest() public returns (uint256) { } // returns the borrower's debt function getDebt() public { } // returns defaulted loans function getOutStandingLoan() public { } }
0.7.1