-
Notifications
You must be signed in to change notification settings - Fork 0
/
AssociateProfitSplitter_20_Homeowork.sol
46 lines (36 loc) · 1.47 KB
/
AssociateProfitSplitter_20_Homeowork.sol
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
pragma solidity ^0.5.0;
////import "https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/contracts/math/SafeMath.sol";
///"SPDX-License-Identifier: SPDX-License-Identifier: UNLICENSED"
// lvl 1: equal split
contract AssociateProfitSplitter {
//// using SafeMath for uint;
// @TODO: Create three payable addresses representing `employee_one`, `employee_two` and `employee_three`.
address payable employee_one;
address payable employee_two;
address payable employee_three;
constructor(address payable _one, address payable _two, address payable _three) public {
employee_one = _one;
employee_two = _two;
employee_three = _three;
}
function balance() public view returns(uint) {
return address(this).balance;
}
function deposit() public payable {
// @TODO: Split `msg.value` into three
uint amount = msg.value / 3; // Your code here!
// @TODO: Transfer the amount to each employee
// Your code here!
employee_one.transfer(amount);
employee_two.transfer(amount);
employee_three.transfer(amount);
// @TODO: take care of a potential remainder by sending back to HR (`msg.sender`)
// Your code here!
msg.sender.transfer(msg.value - amount * 3);
}
function() external payable {
// @TODO: Enforce that the `deposit` function is called in the fallback function!
// Your code here!
deposit;
}
}