-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPartnership.sol
More file actions
64 lines (53 loc) · 1.72 KB
/
Partnership.sol
File metadata and controls
64 lines (53 loc) · 1.72 KB
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
//SPDX-License-Identifier: Unlicense
pragma solidity ^0.8.4;
contract Partnership {
address payable[] public addresses;
uint256[] public splitRatios;
uint256 private splitRatiosTotal;
constructor(
address payable[] memory _addresses,
uint256[] memory _splitRatios
) {
require(
_addresses.length > 1,
"More than one address should be provided to establish a partnership"
);
require(
_splitRatios.length == _addresses.length,
"The address amount and the split ratio amount should be equal"
);
addresses = _addresses;
splitRatios = _splitRatios;
splitRatiosTotal = getSplitRatiosTotal(splitRatios);
}
function getSplitRatiosTotal(uint256[] memory _splitRatios)
private
pure
returns (uint256)
{
uint256 total = 0;
for (uint256 i = 0; i < _splitRatios.length; i++) {
require(_splitRatios[i] > 0, "Split ratio can not be 0 or less");
total += _splitRatios[i];
}
return total;
}
receive() external payable {}
function getBalance() public view returns (uint256) {
return address(this).balance;
}
function withdraw() public {
uint256 balance = getBalance();
uint256 addressesLength = addresses.length;
require(balance > 0, "Insufficient balance");
require(
balance >= splitRatiosTotal,
"Balance should be greater than the total split ratios"
);
for (uint256 i = 0; i < addressesLength; i++) {
addresses[i].transfer(
(balance / splitRatiosTotal) * splitRatios[i]
);
}
}
}