Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
90 changes: 6 additions & 84 deletions contracts/Boardroomv3.sol
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import '@openzeppelin/contracts/token/ERC20/IERC20.sol';
import '@openzeppelin/contracts/token/ERC20/SafeERC20.sol';

import './lib/Safe112.sol';
import './lib/prb-math/PRBMathUD60x18.sol';
import './owner/Operator.sol';
import './utils/ContractGuard.sol';
import './interfaces/IBasisAsset.sol';
Expand All @@ -26,23 +27,6 @@ contract ShareWrapper {
function balanceOf(address account) public view returns (uint256) {
return _balances[account];
}

function stake(uint256 amount) public virtual {
_totalSupply = _totalSupply.add(amount);
_balances[msg.sender] = _balances[msg.sender].add(amount);
share.safeTransferFrom(msg.sender, address(this), amount);
}

function withdraw(uint256 amount) public virtual {
uint256 directorShare = _balances[msg.sender];
require(
directorShare >= amount,
'Boardroom: withdraw request greater than staked amount'
);
_totalSupply = _totalSupply.sub(amount);
_balances[msg.sender] = directorShare.sub(amount);
share.safeTransfer(msg.sender, amount);
}
}

contract Boardroomv3 is ShareWrapper, ContractGuard, Operator, IFeeDistributorRecipient {
Expand All @@ -57,7 +41,7 @@ contract Boardroomv3 is ShareWrapper, ContractGuard, Operator, IFeeDistributorRe
uint256 lastSnapshotIndex;
uint256 rewardEarned;
uint256 pendingWithdrawalBalance;
uint256 pendingWithdrawalTime;
uint256 startTime;
}

struct BoardSnapshot {
Expand Down Expand Up @@ -141,82 +125,20 @@ contract Boardroomv3 is ShareWrapper, ContractGuard, Operator, IFeeDistributorRe
}

function earned(address director) public view returns (uint256) {
uint256 latestRPS = getLatestSnapshot().rewardPerShare;
uint256 storedRPS = getLastSnapshotOf(director).rewardPerShare;
uint256 stakingPeriod = (now - directors[director].startTime) / 1 days;

return
balanceOf(director).mul(latestRPS.sub(storedRPS)).div(1e18).add(
directors[director].rewardEarned
);
return balanceOf(director).mul(PRBMathUD60x18.log10(stakingPeriod + 1)).div(1e18).add(directors[director].rewardEarned);
}

function pendingWithdrawalBalance(address director) public view returns (uint256) {
return directors[director].pendingWithdrawalBalance;
}

function pendingWithdrawalTime(address director) public view returns (uint256) {
return directors[director].pendingWithdrawalTime;
function startTime(address director) public view returns (uint256) {
return directors[director].startTime;
}

/* ========== MUTATIVE FUNCTIONS ========== */

function stake(uint256 amount)
public
override
onlyOneBlock
updateReward(msg.sender)
{
require(amount > 0, 'Boardroom: Cannot stake 0');
super.stake(amount);
emit Staked(msg.sender, amount);
}

function withdraw(uint256 amount)
public
override
onlyOneBlock
directorExists
updateReward(msg.sender)
{
require(amount > 0, 'Boardroom: Cannot withdraw 0');
super.withdraw(amount);
emit Withdrawn(msg.sender, amount);
}

function exit() external {
withdraw(balanceOf(msg.sender));
claimReward();
}

//Claim rewards after the 5 day delay
function claimReward() public {
uint256 timeCanWithdraw = directors[msg.sender].pendingWithdrawalTime;
require(timeCanWithdraw <= now, 'Boardroom: Need to wait more time before claiming reward');

uint256 reward = directors[msg.sender].pendingWithdrawalBalance;

if (reward > 0) {
directors[msg.sender].pendingWithdrawalBalance = 0;
directors[msg.sender].pendingWithdrawalTime = 0;

cash.safeTransfer(msg.sender, reward);
emit RewardPaid(msg.sender, reward);
}
}

//Initiates a reward claim with a 5 day delay
//This will reset the timer for any "mature" rewards the user has
function initiateRewardClaim() public updateReward(msg.sender) {
uint256 reward = directors[msg.sender].rewardEarned;
if (reward > 0) {
uint256 newPendingWithdrawalBalance = directors[msg.sender].pendingWithdrawalBalance.add(reward);
directors[msg.sender].rewardEarned = 0;
directors[msg.sender].pendingWithdrawalBalance = newPendingWithdrawalBalance;
directors[msg.sender].pendingWithdrawalTime = now + 5 days;
emit RewardPending(msg.sender, reward);
}
}

function allocateSeigniorage(uint256 amount)
external
onlyOneBlock
Expand Down
Loading