文件 1 的 19:AccessControl.sol
pragma solidity ^0.8.0;
import "../utils/EnumerableSet.sol";
import "../utils/Address.sol";
import "../utils/Context.sol";
abstract contract AccessControl is Context {
using EnumerableSet for EnumerableSet.AddressSet;
using Address for address;
struct RoleData {
EnumerableSet.AddressSet members;
bytes32 adminRole;
}
mapping (bytes32 => RoleData) private _roles;
bytes32 public constant DEFAULT_ADMIN_ROLE = 0x00;
event RoleAdminChanged(bytes32 indexed role, bytes32 indexed previousAdminRole, bytes32 indexed newAdminRole);
event RoleGranted(bytes32 indexed role, address indexed account, address indexed sender);
event RoleRevoked(bytes32 indexed role, address indexed account, address indexed sender);
function hasRole(bytes32 role, address account) public view returns (bool) {
return _roles[role].members.contains(account);
}
function getRoleMemberCount(bytes32 role) public view returns (uint256) {
return _roles[role].members.length();
}
function getRoleMember(bytes32 role, uint256 index) public view returns (address) {
return _roles[role].members.at(index);
}
function getRoleAdmin(bytes32 role) public view returns (bytes32) {
return _roles[role].adminRole;
}
function grantRole(bytes32 role, address account) public virtual {
require(hasRole(_roles[role].adminRole, _msgSender()), "AccessControl: sender must be an admin to grant");
_grantRole(role, account);
}
function revokeRole(bytes32 role, address account) public virtual {
require(hasRole(_roles[role].adminRole, _msgSender()), "AccessControl: sender must be an admin to revoke");
_revokeRole(role, account);
}
function renounceRole(bytes32 role, address account) public virtual {
require(account == _msgSender(), "AccessControl: can only renounce roles for self");
_revokeRole(role, account);
}
function _setupRole(bytes32 role, address account) internal virtual {
_grantRole(role, account);
}
function _setRoleAdmin(bytes32 role, bytes32 adminRole) internal virtual {
emit RoleAdminChanged(role, _roles[role].adminRole, adminRole);
_roles[role].adminRole = adminRole;
}
function _grantRole(bytes32 role, address account) private {
if (_roles[role].members.add(account)) {
emit RoleGranted(role, account, _msgSender());
}
}
function _revokeRole(bytes32 role, address account) private {
if (_roles[role].members.remove(account)) {
emit RoleRevoked(role, account, _msgSender());
}
}
}
文件 2 的 19:Address.sol
pragma solidity ^0.8.0;
library Address {
function isContract(address account) internal view returns (bool) {
uint256 size;
assembly { size := extcodesize(account) }
return size > 0;
}
function sendValue(address payable recipient, uint256 amount) internal {
require(address(this).balance >= amount, "Address: insufficient balance");
(bool success, ) = recipient.call{ value: amount }("");
require(success, "Address: unable to send value, recipient may have reverted");
}
function functionCall(address target, bytes memory data) internal returns (bytes memory) {
return functionCall(target, data, "Address: low-level call failed");
}
function functionCall(address target, bytes memory data, string memory errorMessage) internal returns (bytes memory) {
return functionCallWithValue(target, data, 0, errorMessage);
}
function functionCallWithValue(address target, bytes memory data, uint256 value) internal returns (bytes memory) {
return functionCallWithValue(target, data, value, "Address: low-level call with value failed");
}
function functionCallWithValue(address target, bytes memory data, uint256 value, string memory errorMessage) internal returns (bytes memory) {
require(address(this).balance >= value, "Address: insufficient balance for call");
require(isContract(target), "Address: call to non-contract");
(bool success, bytes memory returndata) = target.call{ value: value }(data);
return _verifyCallResult(success, returndata, errorMessage);
}
function functionStaticCall(address target, bytes memory data) internal view returns (bytes memory) {
return functionStaticCall(target, data, "Address: low-level static call failed");
}
function functionStaticCall(address target, bytes memory data, string memory errorMessage) internal view returns (bytes memory) {
require(isContract(target), "Address: static call to non-contract");
(bool success, bytes memory returndata) = target.staticcall(data);
return _verifyCallResult(success, returndata, errorMessage);
}
function functionDelegateCall(address target, bytes memory data) internal returns (bytes memory) {
return functionDelegateCall(target, data, "Address: low-level delegate call failed");
}
function functionDelegateCall(address target, bytes memory data, string memory errorMessage) internal returns (bytes memory) {
require(isContract(target), "Address: delegate call to non-contract");
(bool success, bytes memory returndata) = target.delegatecall(data);
return _verifyCallResult(success, returndata, errorMessage);
}
function _verifyCallResult(bool success, bytes memory returndata, string memory errorMessage) private pure returns(bytes memory) {
if (success) {
return returndata;
} else {
if (returndata.length > 0) {
assembly {
let returndata_size := mload(returndata)
revert(add(32, returndata), returndata_size)
}
} else {
revert(errorMessage);
}
}
}
}
文件 3 的 19:ArthArthBoardroomV2.sol
pragma solidity ^0.8.0;
import {Vault} from '../core/Vault.sol';
import {IERC20} from '@openzeppelin/contracts/contracts/token/ERC20/IERC20.sol';
import {VaultBoardroom} from '../core/VaultBoardroom.sol';
contract ArthArthBoardroomV2 is VaultBoardroom {
constructor(IERC20 cash_, Vault arthVault_)
VaultBoardroom(cash_, arthVault_)
{}
}
文件 4 的 19:Context.sol
pragma solidity ^0.8.0;
abstract contract Context {
function _msgSender() internal view virtual returns (address) {
return msg.sender;
}
function _msgData() internal view virtual returns (bytes calldata) {
this;
return msg.data;
}
}
文件 5 的 19:ContractGuard.sol
pragma solidity ^0.8.0;
contract ContractGuard {
mapping(uint256 => mapping(address => bool)) private _status;
function checkSameOriginReentranted() internal view returns (bool) {
return _status[block.number][tx.origin];
}
function checkSameSenderReentranted() internal view returns (bool) {
return _status[block.number][msg.sender];
}
modifier onlyOneBlock() {
require(
!checkSameOriginReentranted(),
'ContractGuard: one block, one function'
);
require(
!checkSameSenderReentranted(),
'ContractGuard: one block, one function'
);
_;
_status[block.number][tx.origin] = true;
_status[block.number][msg.sender] = true;
}
}
文件 6 的 19:EnumerableSet.sol
pragma solidity ^0.8.0;
library EnumerableSet {
struct Set {
bytes32[] _values;
mapping (bytes32 => uint256) _indexes;
}
function _add(Set storage set, bytes32 value) private returns (bool) {
if (!_contains(set, value)) {
set._values.push(value);
set._indexes[value] = set._values.length;
return true;
} else {
return false;
}
}
function _remove(Set storage set, bytes32 value) private returns (bool) {
uint256 valueIndex = set._indexes[value];
if (valueIndex != 0) {
uint256 toDeleteIndex = valueIndex - 1;
uint256 lastIndex = set._values.length - 1;
bytes32 lastvalue = set._values[lastIndex];
set._values[toDeleteIndex] = lastvalue;
set._indexes[lastvalue] = toDeleteIndex + 1;
set._values.pop();
delete set._indexes[value];
return true;
} else {
return false;
}
}
function _contains(Set storage set, bytes32 value) private view returns (bool) {
return set._indexes[value] != 0;
}
function _length(Set storage set) private view returns (uint256) {
return set._values.length;
}
function _at(Set storage set, uint256 index) private view returns (bytes32) {
require(set._values.length > index, "EnumerableSet: index out of bounds");
return set._values[index];
}
struct Bytes32Set {
Set _inner;
}
function add(Bytes32Set storage set, bytes32 value) internal returns (bool) {
return _add(set._inner, value);
}
function remove(Bytes32Set storage set, bytes32 value) internal returns (bool) {
return _remove(set._inner, value);
}
function contains(Bytes32Set storage set, bytes32 value) internal view returns (bool) {
return _contains(set._inner, value);
}
function length(Bytes32Set storage set) internal view returns (uint256) {
return _length(set._inner);
}
function at(Bytes32Set storage set, uint256 index) internal view returns (bytes32) {
return _at(set._inner, index);
}
struct AddressSet {
Set _inner;
}
function add(AddressSet storage set, address value) internal returns (bool) {
return _add(set._inner, bytes32(uint256(uint160(value))));
}
function remove(AddressSet storage set, address value) internal returns (bool) {
return _remove(set._inner, bytes32(uint256(uint160(value))));
}
function contains(AddressSet storage set, address value) internal view returns (bool) {
return _contains(set._inner, bytes32(uint256(uint160(value))));
}
function length(AddressSet storage set) internal view returns (uint256) {
return _length(set._inner);
}
function at(AddressSet storage set, uint256 index) internal view returns (address) {
return address(uint160(uint256(_at(set._inner, index))));
}
struct UintSet {
Set _inner;
}
function add(UintSet storage set, uint256 value) internal returns (bool) {
return _add(set._inner, bytes32(value));
}
function remove(UintSet storage set, uint256 value) internal returns (bool) {
return _remove(set._inner, bytes32(value));
}
function contains(UintSet storage set, uint256 value) internal view returns (bool) {
return _contains(set._inner, bytes32(value));
}
function length(UintSet storage set) internal view returns (uint256) {
return _length(set._inner);
}
function at(UintSet storage set, uint256 index) internal view returns (uint256) {
return uint256(_at(set._inner, index));
}
}
文件 7 的 19:IBasisAsset.sol
pragma solidity ^0.8.0;
import {IERC20} from '@openzeppelin/contracts/contracts/token/ERC20/IERC20.sol';
interface IBasisAsset is IERC20 {
function mint(address recipient, uint256 amount) external returns (bool);
function burn(uint256 amount) external;
function burnFrom(address from, uint256 amount) external;
function isOperator() external returns (bool);
function operator() external view returns (address);
function transferOperator(address newOperator_) external;
function transferOwnership(address newOwner) external;
}
文件 8 的 19:IBoardroom.sol
pragma solidity ^0.8.0;
import {IOperator} from './IOperator.sol';
interface IBoardroom is IOperator {
struct Boardseat {
uint256 rewardClaimed;
uint256 lastRPS;
uint256 firstRPS;
uint256 lastBoardSnapshotIndex;
uint256 rewardEarnedCurrEpoch;
uint256 lastClaimedOn;
uint256 lastSnapshotIndex;
}
struct BoardSnapshot {
uint256 number;
uint256 time;
uint256 rewardReceived;
uint256 rewardPerShare;
}
struct BondingSnapshot {
uint256 epoch;
uint256 when;
uint256 balance;
uint256 valid;
}
function allocateSeigniorage(uint256 amount) external;
function getDirector(address who) external view returns (Boardseat memory);
function getLastSnapshotIndexOf(address director)
external
view
returns (uint256);
}
文件 9 的 19:IERC20.sol
pragma solidity ^0.8.0;
interface IERC20 {
function totalSupply() external view returns (uint256);
function balanceOf(address account) external view returns (uint256);
function transfer(address recipient, uint256 amount) external returns (bool);
function allowance(address owner, address spender) external view returns (uint256);
function approve(address spender, uint256 amount) external returns (bool);
function transferFrom(address sender, address recipient, uint256 amount) external returns (bool);
event Transfer(address indexed from, address indexed to, uint256 value);
event Approval(address indexed owner, address indexed spender, uint256 value);
}
文件 10 的 19:IEpoch.sol
pragma solidity ^0.8.0;
interface IEpoch {
function callable() external view returns (bool);
function getLastEpoch() external view returns (uint256);
function getCurrentEpoch() external view returns (uint256);
function getNextEpoch() external view returns (uint256);
function nextEpochPoint() external view returns (uint256);
function getPeriod() external view returns (uint256);
function getStartTime() external view returns (uint256);
function setPeriod(uint256 _period) external;
}
文件 11 的 19:IOperator.sol
pragma solidity ^0.8.0;
import {IEpoch} from './IEpoch.sol';
interface IOperator {
function operator() external view returns (address);
function isOperator() external view returns (bool);
function transferOperator(address newOperator_) external;
}
文件 12 的 19:IVaultBoardroom.sol
pragma solidity ^0.8.0;
import {IBoardroom} from './IBoardroom.sol';
interface IVaultBoardroom is IBoardroom {
function updateReward(address who) external;
}
文件 13 的 19:Operator.sol
pragma solidity ^0.8.0;
import '@openzeppelin/contracts/contracts/GSN/Context.sol';
import '@openzeppelin/contracts/contracts/access/Ownable.sol';
import {IOperator} from '../interfaces/IOperator.sol';
abstract contract Operator is Context, Ownable, IOperator {
address private _operator;
event OperatorTransferred(
address indexed previousOperator,
address indexed newOperator
);
constructor() {
_operator = _msgSender();
emit OperatorTransferred(address(0), _operator);
}
function operator() public view override returns (address) {
return _operator;
}
modifier onlyOperator() {
require(
_operator == msg.sender,
'operator: caller is not the operator'
);
_;
}
function isOperator() public view override returns (bool) {
return _msgSender() == _operator;
}
function transferOperator(address newOperator_) public override onlyOwner {
_transferOperator(newOperator_);
}
function _transferOperator(address newOperator_) internal {
require(
newOperator_ != address(0),
'operator: zero address given for new operator'
);
emit OperatorTransferred(address(0), newOperator_);
_operator = newOperator_;
}
}
文件 14 的 19:Ownable.sol
pragma solidity ^0.8.0;
import "../utils/Context.sol";
abstract contract Ownable is Context {
address private _owner;
event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);
constructor () {
address msgSender = _msgSender();
_owner = msgSender;
emit OwnershipTransferred(address(0), msgSender);
}
function owner() public view virtual returns (address) {
return _owner;
}
modifier onlyOwner() {
require(owner() == _msgSender(), "Ownable: caller is not the owner");
_;
}
function renounceOwnership() public virtual onlyOwner {
emit OwnershipTransferred(_owner, address(0));
_owner = address(0);
}
function transferOwnership(address newOwner) public virtual onlyOwner {
require(newOwner != address(0), "Ownable: new owner is the zero address");
emit OwnershipTransferred(_owner, newOwner);
_owner = newOwner;
}
}
文件 15 的 19:Safe112.sol
pragma solidity ^0.8.0;
library Safe112 {
function add(uint112 a, uint112 b) internal pure returns (uint256) {
uint256 c = a + b;
require(c >= a, 'Safe112: addition overflow');
return c;
}
function sub(uint112 a, uint112 b) internal pure returns (uint256) {
return sub(a, b, 'Safe112: subtraction overflow');
}
function sub(
uint112 a,
uint112 b,
string memory errorMessage
) internal pure returns (uint112) {
require(b <= a, errorMessage);
uint112 c = a - b;
return c;
}
function mul(uint112 a, uint112 b) internal pure returns (uint256) {
if (a == 0) {
return 0;
}
uint256 c = a * b;
require(c / a == b, 'Safe112: multiplication overflow');
return c;
}
function div(uint112 a, uint112 b) internal pure returns (uint256) {
return div(a, b, 'Safe112: division by zero');
}
function div(
uint112 a,
uint112 b,
string memory errorMessage
) internal pure returns (uint112) {
require(b > 0, errorMessage);
uint112 c = a / b;
return c;
}
function mod(uint112 a, uint112 b) internal pure returns (uint256) {
return mod(a, b, 'Safe112: modulo by zero');
}
function mod(
uint112 a,
uint112 b,
string memory errorMessage
) internal pure returns (uint112) {
require(b != 0, errorMessage);
return a % b;
}
}
文件 16 的 19:SafeMath.sol
pragma solidity ^0.8.0;
library SafeMath {
function tryAdd(uint256 a, uint256 b) internal pure returns (bool, uint256) {
unchecked {
uint256 c = a + b;
if (c < a) return (false, 0);
return (true, c);
}
}
function trySub(uint256 a, uint256 b) internal pure returns (bool, uint256) {
unchecked {
if (b > a) return (false, 0);
return (true, a - b);
}
}
function tryMul(uint256 a, uint256 b) internal pure returns (bool, uint256) {
unchecked {
if (a == 0) return (true, 0);
uint256 c = a * b;
if (c / a != b) return (false, 0);
return (true, c);
}
}
function tryDiv(uint256 a, uint256 b) internal pure returns (bool, uint256) {
unchecked {
if (b == 0) return (false, 0);
return (true, a / b);
}
}
function tryMod(uint256 a, uint256 b) internal pure returns (bool, uint256) {
unchecked {
if (b == 0) return (false, 0);
return (true, a % b);
}
}
function add(uint256 a, uint256 b) internal pure returns (uint256) {
return a + b;
}
function sub(uint256 a, uint256 b) internal pure returns (uint256) {
return a - b;
}
function mul(uint256 a, uint256 b) internal pure returns (uint256) {
return a * b;
}
function div(uint256 a, uint256 b) internal pure returns (uint256) {
return a / b;
}
function mod(uint256 a, uint256 b) internal pure returns (uint256) {
return a % b;
}
function sub(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) {
unchecked {
require(b <= a, errorMessage);
return a - b;
}
}
function div(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) {
unchecked {
require(b > 0, errorMessage);
return a / b;
}
}
function mod(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) {
unchecked {
require(b > 0, errorMessage);
return a % b;
}
}
}
文件 17 的 19:StakingTimelock.sol
pragma solidity ^0.8.0;
import {SafeMath} from '@openzeppelin/contracts/contracts/math/SafeMath.sol';
import {Ownable} from '@openzeppelin/contracts/contracts/access/Ownable.sol';
abstract contract StakingTimelock is Ownable {
using SafeMath for uint256;
uint256 public duration = 1 days;
struct StakingDetails {
uint256 deadline;
uint256 amount;
uint256 updatedOn;
}
mapping(address => StakingDetails) public stakingDetails;
constructor(uint256 _duration) {
duration = _duration;
}
modifier checkLockDuration {
StakingDetails storage _stakerDetails = stakingDetails[msg.sender];
require(_stakerDetails.deadline != 0);
require(_stakerDetails.amount != 0);
require(_stakerDetails.deadline <= block.timestamp);
_;
}
modifier checkLockDurationFor(address who) {
StakingDetails storage _stakerDetails = stakingDetails[who];
require(_stakerDetails.deadline != 0);
require(_stakerDetails.amount != 0);
require(_stakerDetails.deadline <= block.timestamp);
_;
}
modifier checkLockDurationWithAmount(uint256 amount) {
StakingDetails storage _stakerDetails = stakingDetails[msg.sender];
require(_stakerDetails.deadline != 0);
require(_stakerDetails.amount <= amount);
require(_stakerDetails.deadline <= block.timestamp);
_;
}
function getStakerDetails(address who)
public
view
returns (
uint256,
uint256,
uint256
)
{
StakingDetails storage _stakerDetails = stakingDetails[who];
return (
_stakerDetails.amount,
_stakerDetails.deadline,
_stakerDetails.updatedOn
);
}
function getStakedAmount(address who) public view returns (uint256) {
StakingDetails storage _stakerDetails = stakingDetails[who];
return _stakerDetails.amount;
}
function _updateStakerDetails(address who, uint256 _amount) internal {
StakingDetails storage _stakerDetails = stakingDetails[who];
_stakerDetails.deadline = block.timestamp + duration;
_stakerDetails.updatedOn = block.timestamp;
_stakerDetails.amount = _amount;
}
function changeLockDuration(uint256 _duration) public onlyOwner {
duration = _duration;
}
function getLockDuration() public view returns (uint256) {
return duration;
}
}
文件 18 的 19:Vault.sol
pragma solidity ^0.8.0;
import {IERC20} from '@openzeppelin/contracts/contracts/token/ERC20/IERC20.sol';
import {
AccessControl
} from '@openzeppelin/contracts/contracts/access/AccessControl.sol';
import {Operator} from '../../owner/Operator.sol';
import {SafeMath} from '@openzeppelin/contracts/contracts/math/SafeMath.sol';
import {StakingTimelock} from '../../timelock/StakingTimelock.sol';
import {IVaultBoardroom} from '../../interfaces/IVaultBoardroom.sol';
contract Vault is AccessControl, StakingTimelock, Operator {
using SafeMath for uint256;
bytes32 public constant BOARDROOM_ROLE = keccak256('BOARDROOM_ROLE');
struct BondingDetail {
uint256 firstBondedOn;
uint256 latestBondedOn;
uint256 previousBondedOn;
}
IERC20 public token;
IVaultBoardroom public expansionBoardroom;
IVaultBoardroom public contractionBoardroom;
uint256 internal _totalSupply;
bool public enableDeposits = true;
uint256 internal _totalBondedSupply;
mapping(address => uint256) internal _balances;
modifier stakerExists(address who) {
require(balanceOf(who) > 0, 'Boardroom: The director does not exist');
_;
}
event Bonded(address indexed user, uint256 amount);
event Unbonded(address indexed user, uint256 amount);
event Withdrawn(address indexed user, uint256 amount);
constructor(IERC20 token_, uint256 duration_) StakingTimelock(duration_) {
token = token_;
_setupRole(DEFAULT_ADMIN_ROLE, _msgSender());
_setupRole(BOARDROOM_ROLE, _msgSender());
}
function totalSupply() public view returns (uint256) {
return _totalSupply;
}
function setBoardrooms(
IVaultBoardroom expansionBoardroom_,
IVaultBoardroom contractionBoardroom_
) public {
expansionBoardroom = expansionBoardroom_;
contractionBoardroom = contractionBoardroom_;
}
function balanceOf(address who) public view returns (uint256) {
return _balances[who];
}
function totalBondedSupply() public view returns (uint256) {
return _totalBondedSupply;
}
function balanceWithoutBonded(address who) public view returns (uint256) {
uint256 unbondingAmount = getStakedAmount(msg.sender);
return _balances[who].sub(unbondingAmount);
}
function toggleDeposits(bool val) external onlyOwner {
enableDeposits = val;
}
function bond(uint256 amount) external virtual {
_bond(msg.sender, amount);
}
function bondFor(address who, uint256 amount) external virtual {
require(
hasRole(BOARDROOM_ROLE, _msgSender()),
'Vault: must have boardroom role to bond for someone else'
);
_bond(who, amount);
}
function unbond(uint256 amount) external virtual {
_unbond(msg.sender, amount);
}
function withdraw() external virtual {
_withdraw(msg.sender);
}
function _updateRewards(address who) private {
if (address(expansionBoardroom) != address(0))
expansionBoardroom.updateReward(who);
if (address(contractionBoardroom) != address(0))
contractionBoardroom.updateReward(who);
}
function _bond(address who, uint256 amount) private {
require(amount > 0, 'Boardroom: cannot bond 0');
require(enableDeposits, 'Boardroom: deposits are disabled');
_totalSupply = _totalSupply.add(amount);
_balances[who] = _balances[who].add(amount);
_totalBondedSupply = _totalBondedSupply.add(amount);
token.transferFrom(who, address(this), amount);
_updateRewards(who);
emit Bonded(who, amount);
}
function _unbond(address who, uint256 amount) private stakerExists(who) {
require(amount > 0, 'Boardroom: cannot unbond 0');
uint256 directorShare = _balances[who];
require(
directorShare >= amount,
'Boardroom: unbond request greater than staked amount'
);
_updateStakerDetails(who, amount);
_updateRewards(who);
_totalBondedSupply = _totalBondedSupply.sub(amount);
emit Unbonded(who, amount);
}
function _withdraw(address who)
private
stakerExists(who)
checkLockDurationFor(who)
{
uint256 directorShare = _balances[who];
uint256 unbondingAmount = getStakedAmount(who);
require(
directorShare >= unbondingAmount,
'Boardroom: withdraw request greater than unbonded amount'
);
_totalSupply = _totalSupply.sub(unbondingAmount);
_balances[who] = directorShare.sub(unbondingAmount);
token.transfer(who, unbondingAmount);
_updateStakerDetails(who, 0);
_updateRewards(who);
emit Withdrawn(who, unbondingAmount);
}
}
文件 19 的 19:VaultBoardroom.sol
pragma solidity ^0.8.0;
import {IERC20} from '@openzeppelin/contracts/contracts/token/ERC20/IERC20.sol';
import {Vault} from './Vault.sol';
import {SafeMath} from '@openzeppelin/contracts/contracts/math/SafeMath.sol';
import {Safe112} from '../../lib/Safe112.sol';
import {ContractGuard} from '../../utils/ContractGuard.sol';
import {Operator} from '../../owner/Operator.sol';
import {IBoardroom} from '../../interfaces/IBoardroom.sol';
import {IBasisAsset} from '../../interfaces/IBasisAsset.sol';
contract VaultBoardroom is ContractGuard, Operator, IBoardroom {
using Safe112 for uint112;
using SafeMath for uint256;
Vault public vault;
IERC20 public token;
uint256 public currentEpoch = 1;
BoardSnapshot[] public boardHistory;
mapping(address => Boardseat) public directors;
mapping(address => mapping(uint256 => BondingSnapshot))
public bondingHistory;
mapping(address => mapping(uint256 => uint256)) directorBalanceForEpoch;
mapping(address => uint256) directorBalanceLastEpoch;
modifier directorExists {
require(
vault.balanceOf(msg.sender) > 0,
'Boardroom: The director does not exist'
);
_;
}
modifier onlyVault {
require(msg.sender == address(vault), 'Boardroom: not vault');
_;
}
event RewardPaid(address indexed user, uint256 reward);
event RewardAdded(address indexed user, uint256 reward);
constructor(IERC20 token_, Vault vault_) {
token = token_;
vault = vault_;
BoardSnapshot memory genesisSnapshot =
BoardSnapshot({
number: block.number,
time: 0,
rewardReceived: 0,
rewardPerShare: 0
});
boardHistory.push(genesisSnapshot);
}
function latestSnapshotIndex() public view returns (uint256) {
return boardHistory.length.sub(1);
}
function getDirector(address who)
external
view
override
returns (Boardseat memory)
{
return directors[who];
}
function getBoardhistory(uint256 i)
public
view
returns (BoardSnapshot memory)
{
return boardHistory[i];
}
function getBondingHistory(address who, uint256 epoch)
public
view
returns (BondingSnapshot memory)
{
return bondingHistory[who][epoch];
}
function getLatestSnapshot() public view returns (BoardSnapshot memory) {
return boardHistory[latestSnapshotIndex()];
}
function getLastSnapshotIndexOf(address director)
external
view
override
returns (uint256)
{
return directors[director].lastSnapshotIndex;
}
function getLastSnapshotOf(address director)
public
view
returns (BoardSnapshot memory)
{
return boardHistory[directors[director].lastSnapshotIndex];
}
function rewardPerShare() public view returns (uint256) {
return getLatestSnapshot().rewardPerShare;
}
function earned(address director) public view virtual returns (uint256) {
uint256 latestRPS = getLatestSnapshot().rewardPerShare;
uint256 storedRPS = getLastSnapshotOf(director).rewardPerShare;
return
vault
.balanceWithoutBonded(director)
.mul(latestRPS.sub(storedRPS))
.div(1e18)
.add(directors[director].rewardEarnedCurrEpoch);
}
function claimReward() external virtual directorExists returns (uint256) {
_updateReward(msg.sender);
uint256 reward = directors[msg.sender].rewardEarnedCurrEpoch;
if (reward > 0) {
directors[msg.sender].rewardEarnedCurrEpoch = 0;
token.transfer(msg.sender, reward);
emit RewardPaid(msg.sender, reward);
}
return reward;
}
function allocateSeigniorage(uint256 amount)
external
override
onlyOneBlock
onlyOperator
{
require(amount > 0, 'Boardroom: Cannot allocate 0');
uint256 totalSupply = vault.totalBondedSupply();
if (totalSupply == 0) return;
uint256 prevRPS = getLatestSnapshot().rewardPerShare;
uint256 nextRPS = prevRPS.add(amount.mul(1e18).div(totalSupply));
BoardSnapshot memory snap =
BoardSnapshot({
number: block.number,
time: block.timestamp,
rewardReceived: amount,
rewardPerShare: nextRPS
});
boardHistory.push(snap);
token.transferFrom(msg.sender, address(this), amount);
currentEpoch = currentEpoch.add(1);
emit RewardAdded(msg.sender, amount);
}
function updateReward(address director) external virtual onlyVault {
_updateReward(director);
}
function refundReward() external onlyOwner {
token.transfer(msg.sender, token.balanceOf(address(this)));
}
function _updateReward(address director) internal {
Boardseat memory seat = directors[director];
seat.rewardEarnedCurrEpoch = earned(director);
seat.lastSnapshotIndex = latestSnapshotIndex();
directors[director] = seat;
}
}
{
"compilationTarget": {
"contracts/boardoom/v2/ArthArthBoardroomV2.sol": "ArthArthBoardroomV2"
},
"evmVersion": "istanbul",
"libraries": {},
"metadata": {
"bytecodeHash": "ipfs"
},
"optimizer": {
"enabled": true,
"runs": 200
},
"remappings": []
}
[{"inputs":[{"internalType":"contract IERC20","name":"cash_","type":"address"},{"internalType":"contract Vault","name":"arthVault_","type":"address"}],"stateMutability":"nonpayable","type":"constructor"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"previousOperator","type":"address"},{"indexed":true,"internalType":"address","name":"newOperator","type":"address"}],"name":"OperatorTransferred","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"previousOwner","type":"address"},{"indexed":true,"internalType":"address","name":"newOwner","type":"address"}],"name":"OwnershipTransferred","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"user","type":"address"},{"indexed":false,"internalType":"uint256","name":"reward","type":"uint256"}],"name":"RewardAdded","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"user","type":"address"},{"indexed":false,"internalType":"uint256","name":"reward","type":"uint256"}],"name":"RewardPaid","type":"event"},{"inputs":[{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"allocateSeigniorage","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"","type":"uint256"}],"name":"boardHistory","outputs":[{"internalType":"uint256","name":"number","type":"uint256"},{"internalType":"uint256","name":"time","type":"uint256"},{"internalType":"uint256","name":"rewardReceived","type":"uint256"},{"internalType":"uint256","name":"rewardPerShare","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"},{"internalType":"uint256","name":"","type":"uint256"}],"name":"bondingHistory","outputs":[{"internalType":"uint256","name":"epoch","type":"uint256"},{"internalType":"uint256","name":"when","type":"uint256"},{"internalType":"uint256","name":"balance","type":"uint256"},{"internalType":"uint256","name":"valid","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"claimReward","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"currentEpoch","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"}],"name":"directors","outputs":[{"internalType":"uint256","name":"rewardClaimed","type":"uint256"},{"internalType":"uint256","name":"lastRPS","type":"uint256"},{"internalType":"uint256","name":"firstRPS","type":"uint256"},{"internalType":"uint256","name":"lastBoardSnapshotIndex","type":"uint256"},{"internalType":"uint256","name":"rewardEarnedCurrEpoch","type":"uint256"},{"internalType":"uint256","name":"lastClaimedOn","type":"uint256"},{"internalType":"uint256","name":"lastSnapshotIndex","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"director","type":"address"}],"name":"earned","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"i","type":"uint256"}],"name":"getBoardhistory","outputs":[{"components":[{"internalType":"uint256","name":"number","type":"uint256"},{"internalType":"uint256","name":"time","type":"uint256"},{"internalType":"uint256","name":"rewardReceived","type":"uint256"},{"internalType":"uint256","name":"rewardPerShare","type":"uint256"}],"internalType":"struct IBoardroom.BoardSnapshot","name":"","type":"tuple"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"who","type":"address"},{"internalType":"uint256","name":"epoch","type":"uint256"}],"name":"getBondingHistory","outputs":[{"components":[{"internalType":"uint256","name":"epoch","type":"uint256"},{"internalType":"uint256","name":"when","type":"uint256"},{"internalType":"uint256","name":"balance","type":"uint256"},{"internalType":"uint256","name":"valid","type":"uint256"}],"internalType":"struct IBoardroom.BondingSnapshot","name":"","type":"tuple"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"who","type":"address"}],"name":"getDirector","outputs":[{"components":[{"internalType":"uint256","name":"rewardClaimed","type":"uint256"},{"internalType":"uint256","name":"lastRPS","type":"uint256"},{"internalType":"uint256","name":"firstRPS","type":"uint256"},{"internalType":"uint256","name":"lastBoardSnapshotIndex","type":"uint256"},{"internalType":"uint256","name":"rewardEarnedCurrEpoch","type":"uint256"},{"internalType":"uint256","name":"lastClaimedOn","type":"uint256"},{"internalType":"uint256","name":"lastSnapshotIndex","type":"uint256"}],"internalType":"struct IBoardroom.Boardseat","name":"","type":"tuple"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"director","type":"address"}],"name":"getLastSnapshotIndexOf","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"director","type":"address"}],"name":"getLastSnapshotOf","outputs":[{"components":[{"internalType":"uint256","name":"number","type":"uint256"},{"internalType":"uint256","name":"time","type":"uint256"},{"internalType":"uint256","name":"rewardReceived","type":"uint256"},{"internalType":"uint256","name":"rewardPerShare","type":"uint256"}],"internalType":"struct IBoardroom.BoardSnapshot","name":"","type":"tuple"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"getLatestSnapshot","outputs":[{"components":[{"internalType":"uint256","name":"number","type":"uint256"},{"internalType":"uint256","name":"time","type":"uint256"},{"internalType":"uint256","name":"rewardReceived","type":"uint256"},{"internalType":"uint256","name":"rewardPerShare","type":"uint256"}],"internalType":"struct IBoardroom.BoardSnapshot","name":"","type":"tuple"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"isOperator","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"latestSnapshotIndex","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"operator","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"owner","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"refundReward","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"renounceOwnership","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"rewardPerShare","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"token","outputs":[{"internalType":"contract IERC20","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"newOperator_","type":"address"}],"name":"transferOperator","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"newOwner","type":"address"}],"name":"transferOwnership","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"director","type":"address"}],"name":"updateReward","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"vault","outputs":[{"internalType":"contract Vault","name":"","type":"address"}],"stateMutability":"view","type":"function"}]