“ExampleofLoanContract”的版本间的差异
跳到导航
跳到搜索
(建立内容为“=== <div style=" background:#EBEBEB; padding-top: 10px; height:45px; padding-left:15px "> Loan contract </div> === {| class="wikitable" || &nbs…”的新页面) |
|||
| 第1行: | 第1行: | ||
| + | {{DISPLAYTITLE:<span style="position: absolute; clip: rect(1px 1px 1px 1px); clip: rect(1px, 1px, 1px, 1px);">{{FULLPAGENAME}}</span>}} | ||
=== <div style=" background:#EBEBEB; padding-top: 10px; height:45px; padding-left:15px "> Loan contract </div> === | === <div style=" background:#EBEBEB; padding-top: 10px; height:45px; padding-left:15px "> Loan contract </div> === | ||
{| class="wikitable" | {| class="wikitable" | ||
2021年3月9日 (二) 14:48的版本
Loan contract
| Loan contract, refers to a contract where a lender delivers a certain amount of funds to a borrower, and the latter returns the same amount of funds within a certain period of time and pays interests to the lender. There are 6 terms in the contract that consists of two aspects: 1) the borrower shall submit a loan application stating the amount he/she wants to borrow, and 2) the lender may deposit funds into the contract account until the target of loan is reached. Before borrowing, the contract requires that the borrower must confirm the loan information and check the historical loan records, and then calculate the corresponding interests. Meanwhile, the contract asserts that the borrower pays off the loan amount before the loan date comes. |
1 // Lend Spesc.scs
2 contract Lend{
3 party User{
4 loan : Loan
5 SubmitLoanApplication(l : Loan)
6 confirm()
7 getHisLoan()
8 payback()
9 }
10
11 party Funder{
12 moneyFunded : Money
13 moneyWillGet : Money
14 Contribute(uid : User)
15 refund(uid : User)
16 }
17
18 term term1 : User can SubmitLoanApplication.
19
20 term term2 : Funder can Contribute
21 when before uid::loan::timelimit
22 while deposit $ value <= uid::loan::fundingGoal.
23
24 term term3 : Funder can refund
25 when after uid::loan::timelimit and uid::loan::amount < uid::loan::fundingGoal
26 while withdraw $ his::moneyFunded.
27
28 term term4 : User must confirm
29 when within 3 day after his::loan::timelimit and his::loan::amount = his::loan::fundingGoal.
30
31 term term5 : User can getHisLoan
32 when after User did confirm
33 while withdraw $ his::loan::amount.
34
35 term term6 : User must payback
36 when after User did confirm and before his::loan::tenorM
37 while
38 deposit $ his::loan::balance + his::loan::installment
39 transfer $ his::loan::funders::moneyWillGet to his::loan::funders.
40
41 type Loan
42 {
43 operationName : Name//use of money
44 beneficiary : User//Borrower
45 timelimit : Date//time limit of collecting money
46 fundingGoal : integer//the amount borrower want to borrow
47 amount : integer//the money collected now
48 balance : integer//the Capital have to pay back
49 numFunders : integer
50 interestRateM : integer// monthly
51 gracePeriod : integer//the period you don't have to pay the interest
52 tenorM : integer//monthly//you have to pay back tenorM month later
53 installment : integer//monthly//the interest have to pay back
54 funders : set Funder
55 }
56 }
1 /* FunderT.sol */
2 pragma solidity >=0.4.0 <0.6.0;
3
4 contract FunderT{
5
6 uint moneyFunded;
7 uint moneyWillGet;
8
9 address _FunderAddress;
10 uint _max;
11
12 function funderT() public{
13 _max = now*1000;
14 }
15 function regist(address a) public {
16 _FunderAddress = a;
17 }
18
19 function getAddress() public returns (address a){
20 return _FunderAddress;
21 }
22
23 function getmoneyFunded() public returns(uint _result){
24 return moneyFunded;
25 }
26
27 function setmoneyFunded ( uint a) public{
28 moneyFunded = a;
29 }
30
31 /* function getmoneyWillGet() public returns(uint _result){
32 return moneyWillGet;
33 }
34
35 function setmoneyWillGet(uint a) public {
36 moneyWillGet = a;
37 }*/
38
39
40
41 function setmoneyWillGet(uint256 newValue) public {
42 moneyWillGet = newValue;
43 }
44
45
46 function getmoneyWillGet() public view returns (uint256) {
47 return moneyWillGet;
48 }
49 }
1 /* Lend.sol */
2 pragma solidity >=0.4.0 <0.6.0;
3 pragma experimental ABIEncoderV2;
4
5 import "./UserT.sol";
6 import "./FunderT.sol";
7
8 contract Lend {
9
10 UserT User;
11 FunderT Funder;
12 uint start;
13
14
15 mapping (string => Loan) loan;
16
17 struct Loan{
18 bytes32 operationName;
19 address beneficiary;
20 uint timelimit;
21 uint fundingGoal;
22 uint amount;
23 uint balance;
24 uint numFunders;
25 uint interestRateM;
26 uint gracePeriod;
27 uint tenorM;
28 uint installment;
29 address funders;
30 }
31
32
33
34 constructor() public{
35 start = now;
36 User = new UserT();
37 Funder = new FunderT();
38 }
39
40 /* constructor() public{
41 start = now;
42 User = new UserT();
43 Funder = new FunderT();
44 }*/
45
46 modifier onlyUser{
47 require(User.getAddress()==msg.sender);
48 _;
49 }
50
51 modifier onlyFunder{
52 require(Funder.getAddress()==msg.sender);
53 _;
54 }
55
56 modifier term2Modifier(UserT uid){
57 // require(now < uid.loan.timelimit);
58 // require(msg.value <= uid.loan.fundingGoal);
59 _;
60 }
61
62 modifier term3Modifier(UserT uid){
63 // require(now > (uid.loan.timelimit && uid.loan.amount < uid.loan.fundingGoal));
64 _;
65 }
66
67 modifier term4Modifier{
68 // require((now > (User.getloan.timelimit(msg.sender) && User.getloan.amount(msg.sender) == User.getloan.fundingGoal(msg.sender))) &&(now < (User.getloan.timelimit(msg.sender) && User.getloan.amount(msg.sender) == User.getloan.fundingGoal(msg.sender))+259200));
69 _;
70 }
71
72 modifier term5Modifier{
73 require(now > User.confirmTime());
74 _;
75 }
76
77 modifier term6Modifier{
78 // require(now > (User.confirmTime() && now < User.getloan.tenorM(msg.sender)));
79 // require(User.getloan.balance(msg.sender) + User.getloan.installment(msg.sender));
80 _;
81 }
82
83 function SubmitLoanApplication( Loan memory l) onlyUser() public {
84 //USER CODE HERE
85 //CHECK
86
87 }
88
89 function Contribute(UserT uid) onlyFunder() term2Modifier(uid) public payable {
90 //USER CODE HERE
91 //CHECK
92
93 }
94
95 function refund(UserT uid) onlyFunder() term3Modifier(uid) public payable {
96 //USER CODE HERE
97 msg.sender.transfer(Funder.getmoneyFunded());
98 //CHECK
99
100 }
101
102 function confirm() onlyUser() term4Modifier() public {
103 //USER CODE HERE
104 //CHECK
105
106 }
107
108 function getHisLoan() onlyUser() term5Modifier() public payable {
109 //USER CODE HERE
110 msg.sender.transfer(User.getloan().amount);
111 //CHECK
112
113 }
114
115 function payback() onlyUser() term6Modifier() public payable {
116 //USER CODE HERE
117 //User.getloan().funders.transfer(msg.sender);
118 msg.sender.transfer(User.getloan().amount);
119 //CHECK
120
121 }
122
123 }
1 /* UserT.sol */
2 pragma solidity >=0.4.0 <0.6.0;
3 pragma experimental ABIEncoderV2;
4
5
6 import "./Lend.sol";
7
8 contract UserT{
9
10 struct Loan{
11 bytes32 operationName;
12 address beneficiary;
13 uint timelimit;
14 uint fundingGoal;
15 uint amount;
16 uint balance;
17 uint numFunders;
18 uint interestRateM;
19 uint gracePeriod;
20 uint tenorM;
21 uint installment;
22 address funders;
23 }
24
25
26
27
28 Loan loan;
29 //attributes of actionconfirm
30 bool _isconfirmDone;
31 uint _confirmTime;
32
33 address _UserAddress;
34 uint _max;
35
36 constructor ()public{
37 _max = now*1000;
38 }
39
40 function regist(address a) public {
41 _UserAddress = a;
42 }
43
44 function getAddress() public returns (address a){
45 return _UserAddress;
46 }
47
48 function getloan() public returns(Loan memory _result) {
49 return loan;
50 }
51
52 function setloan(Loan memory a) public{
53 loan = a;
54 }
55
56 function confirmDone() public{
57 _confirmTime = now;
58 _isconfirmDone = true;
59 }
60
61 function confirmTime() public returns (uint result){
62 if(_isconfirmDone){
63 return _confirmTime;
64 }
65 return _max;
66 }
67
68 }