//Write your own contracts here. Currently compiles using solc v0.4.15+commit.bbb8e64f. pragma solidity ^0.7.1; contract Delegations { struct Delegation { uint256 shares; // nominal amount of shares held by the Delegation mapping(address => uint256) accumulatorCheckpoints; // checkpointed accumulators } struct Accumulator { mapping(uint256 => uint256) values; uint256 lastUpdate; } /** @notice A delegation pool accrues delegator rewards and fees for an orchestrator and handles accounting */ struct Pool { uint256 activeShares; uint256 nextShares; uint256 lastUpdate; uint256 totalStake; // total amount of tokens held by the EarningsPool mapping(address => Accumulator) public accumulators; // round => token => accumulator mapping(address => Delegation) delegations; } function updateShares(Pool storage _pool, uint256 _round) { if (_pool.lastUpdate >= _round) { return; } _pool.activeShares = _pool.nextShares; _pool.lastUpdate = _round; } function updateAccumulator(Pool storage _pool, uint256 _round, address _token, uint256 _amount) internal returns (uint256 fees) { Accumulator storage acc = accumulators[_token]; uint256 last = acc.values[acc.lastUpdate]; acc.lastUpdate = _round; acc.values[_round] = last + MathUtils.percPoints(_amount, _pool.activeFeeShares); } function rewardFor(Pool storage _pool, address _token, address _delegator) internal view returns (uint256 reward) { Accumulator storage acc = accumulators[_token]; uint256 accPerShare = acc.values[acc.lastUpdate]; Delegation storage del = _pool.delegations[_delegator]; reward = MathUtils.percOf(del.shares, accPerShare - del.accumulatorCheckpoints[_token]); } }
0.7.1