-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmoreComplexDivs.sol
More file actions
33 lines (29 loc) · 885 Bytes
/
moreComplexDivs.sol
File metadata and controls
33 lines (29 loc) · 885 Bytes
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
pragma solidity ^0.4.15;
contract naiveDiv {
uint pointMultiplier = 10e18;
struct Account {
uint balance;
uint lastDividendPoints;
}
mapping(address=>Account) accounts;
uint totalSupply;
uint totalDividendPoints;
uint unclaimedDividends;
function dividendsOwing(address account) internal returns(uint) {
var newDividendPoints = totalDividendPoints - accounts[account].lastDividendPoints;
return (accounts[account].balance * newDividendPoints) / pointMultiplier;
}
modifier updateAccount(address account) {
var owing = dividendsOwing(account);
if(owing > 0) {
unclaimedDividends -= owing;
accounts[account].balance += owing;
accounts[account].lastDividendPoints = totalDividendPoints;
}
_;
}
function disburse(uint amount) {
totalDividendPoints += (amount * pointMultiplier / totalSupply);
totalSupply += amount;
unclaimedDividends += amount;
}}