{
    "Function": "slitherConstructorVariables",
    "File": "contracts/contracts/Voter.sol",
    "Parent Contracts": [],
    "High-Level Calls": [],
    "Internal Calls": [],
    "Library Calls": [],
    "Low-Level Calls": [],
    "Code": "contract Voter {\n\n    address public immutable _ve; // the ve token that governs these contracts\n    address public immutable factory; // the PairFactory\n    address internal immutable base;\n    address public immutable gaugefactory;\n    address public immutable bribefactory;\n    uint internal constant DURATION = 5 days; // rewards are released over 5 days\n    uint internal constant BRIBE_LAG = 1 days;\n    address public minter;\n    address public governor; // should be set to an IGovernor\n    address public emergencyCouncil; // credibly neutral party similar to Curve's Emergency DAO\n\n    uint public totalWeight; // total voting weight\n\n    address[] public pools; // all pools viable for incentives\n    mapping(address => address) public gauges; // pool => gauge\n    mapping(address => address) public poolForGauge; // gauge => pool\n    mapping(address => address) public bribes; // gauge => bribe\n    mapping(address => uint256) public weights; // pool => weight\n    mapping(uint => mapping(address => uint256)) public votes; // nft => pool => votes\n    mapping(uint => address[]) public poolVote; // nft => pools\n    mapping(uint => uint) public usedWeights;  // nft => total voting weight of user\n    mapping(address => bool) public isGauge;\n    mapping(address => bool) public isWhitelisted;\n    mapping(address => bool) public isAlive;\n\n    event GaugeCreated(address indexed gauge, address creator, address indexed bribe, address indexed pool);\n    event GaugeKilled(address indexed gauge);\n    event GaugeRevived(address indexed gauge);\n    event Voted(address indexed voter, uint tokenId, uint256 weight);\n    event Abstained(uint tokenId, uint256 weight);\n    event Deposit(address indexed lp, address indexed gauge, uint tokenId, uint amount);\n    event Withdraw(address indexed lp, address indexed gauge, uint tokenId, uint amount);\n    event NotifyReward(address indexed sender, address indexed reward, uint amount);\n    event DistributeReward(address indexed sender, address indexed gauge, uint amount);\n    event Attach(address indexed owner, address indexed gauge, uint tokenId);\n    event Detach(address indexed owner, address indexed gauge, uint tokenId);\n    event Whitelisted(address indexed whitelister, address indexed token);\n\n    constructor(address __ve, address _factory, address  _gauges, address _bribes) {\n        _ve = __ve;\n        factory = _factory;\n        base = IVotingEscrow(__ve).token();\n        gaugefactory = _gauges;\n        bribefactory = _bribes;\n        minter = msg.sender;\n        governor = msg.sender;\n        emergencyCouncil = msg.sender;\n    }\n\n    // simple re-entrancy check\n    uint internal _unlocked = 1;\n    modifier lock() {\n        require(_unlocked == 1);\n        _unlocked = 2;\n        _;\n        _unlocked = 1;\n    }\n\n    function initialize(address[] memory _tokens, address _minter) external {\n        require(msg.sender == minter);\n        for (uint i = 0; i < _tokens.length; i++) {\n            _whitelist(_tokens[i]);\n        }\n        minter = _minter;\n    }\n\n    function setGovernor(address _governor) public {\n        require(msg.sender == governor);\n        governor = _governor;\n    }\n\n    function setEmergencyCouncil(address _council) public {\n        require(msg.sender == emergencyCouncil);\n        emergencyCouncil = _council;\n    }\n\n    function reset(uint _tokenId) external {\n        require(IVotingEscrow(_ve).isApprovedOrOwner(msg.sender, _tokenId));\n        _reset(_tokenId);\n        IVotingEscrow(_ve).abstain(_tokenId);\n    }\n\n    function _reset(uint _tokenId) internal {\n        address[] storage _poolVote = poolVote[_tokenId];\n        uint _poolVoteCnt = _poolVote.length;\n        uint256 _totalWeight = 0;\n\n        for (uint i = 0; i < _poolVoteCnt; i ++) {\n            address _pool = _poolVote[i];\n            uint256 _votes = votes[_tokenId][_pool];\n\n            if (_votes != 0) {\n                _updateFor(gauges[_pool]);\n                weights[_pool] -= _votes;\n                votes[_tokenId][_pool] -= _votes;\n                if (_votes > 0) {\n                    _totalWeight += _votes;\n                }\n                IGauge(gauges[_pool]).setVoteStatus(IVotingEscrow(_ve).ownerOf(_tokenId), false);\n                emit Abstained(_tokenId, _votes);\n            }\n        }\n        totalWeight -= uint256(_totalWeight);\n        usedWeights[_tokenId] = 0;\n        delete poolVote[_tokenId];\n    }\n\n    function poke(uint _tokenId) external {\n        address[] memory _poolVote = poolVote[_tokenId];\n        uint _poolCnt = _poolVote.length;\n        uint256[] memory _weights = new uint256[](_poolCnt);\n\n        for (uint i = 0; i < _poolCnt; i ++) {\n            _weights[i] = votes[_tokenId][_poolVote[i]];\n        }\n\n        _vote(_tokenId, _poolVote, _weights);\n    }\n\n    function _vote(uint _tokenId, address[] memory _poolVote, uint256[] memory _weights) internal {\n        _reset(_tokenId);\n        uint _poolCnt = _poolVote.length;\n        uint256 _weight = IVotingEscrow(_ve).balanceOfNFT(_tokenId);\n        uint256 _totalVoteWeight = 0;\n        uint256 _totalWeight = 0;\n        uint256 _usedWeight = 0;\n\n        for (uint i = 0; i < _poolCnt; i++) {\n            _totalVoteWeight += _weights[i];\n        }\n\n        for (uint i = 0; i < _poolCnt; i++) {\n            address _pool = _poolVote[i];\n            address _gauge = gauges[_pool];\n\n            if (isGauge[_gauge]) {\n                uint256 _poolWeight = _weights[i] * _weight / _totalVoteWeight;\n                require(votes[_tokenId][_pool] == 0);\n                require(_poolWeight != 0);\n                _updateFor(_gauge);\n\n                poolVote[_tokenId].push(_pool);\n\n                weights[_pool] += _poolWeight;\n                votes[_tokenId][_pool] += _poolWeight;\n                _usedWeight += _poolWeight;\n                _totalWeight += _poolWeight;\n                IGauge(gauges[_pool]).setVoteStatus(IVotingEscrow(_ve).ownerOf(_tokenId), true);\n                emit Voted(msg.sender, _tokenId, _poolWeight);\n            }\n        }\n        if (_usedWeight > 0) IVotingEscrow(_ve).voting(_tokenId);\n        totalWeight += uint256(_totalWeight);\n        usedWeights[_tokenId] = uint256(_usedWeight);\n    }\n\n    function vote(uint tokenId, address[] calldata _poolVote, uint256[] calldata _weights) external {\n        require(IVotingEscrow(_ve).isApprovedOrOwner(msg.sender, tokenId));\n        require(_poolVote.length == _weights.length);\n        _vote(tokenId, _poolVote, _weights);\n    }\n\n    function whitelist(address _token) public {\n        require(msg.sender == governor);\n        _whitelist(_token);\n    }\n\n    function _whitelist(address _token) internal {\n        require(!isWhitelisted[_token]);\n        isWhitelisted[_token] = true;\n        emit Whitelisted(msg.sender, _token);\n    }\n\n    function createGauge(address _pool) external returns (address) {\n        require(gauges[_pool] == address(0x0), \"exists\");\n        if (msg.sender != governor) { // gov can create for any pool, even non-Velodrome pairs\n            require(IPairFactory(factory).isPair(_pool), \"!_pool\");\n            (address tokenA, address tokenB) = IPair(_pool).tokens();\n            require(isWhitelisted[tokenA] && isWhitelisted[tokenB], \"!whitelisted\");\n        }\n        address _bribe = IBribeFactory(bribefactory).createBribe();\n        address _gauge = IGaugeFactory(gaugefactory).createGauge(_pool, _bribe, _ve);\n        IERC20(base).approve(_gauge, type(uint).max);\n        bribes[_gauge] = _bribe;\n        gauges[_pool] = _gauge;\n        poolForGauge[_gauge] = _pool;\n        isGauge[_gauge] = true;\n        isAlive[_gauge] = true;\n        _updateFor(_gauge);\n        pools.push(_pool);\n        emit GaugeCreated(_gauge, msg.sender, _bribe, _pool);\n        return _gauge;\n    }\n\n    function killGauge(address _gauge) external {\n        require(msg.sender == emergencyCouncil, \"not emergency council\");\n        require(isAlive[_gauge], \"gauge already dead\");\n        isAlive[_gauge] = false;\n        emit GaugeKilled(_gauge);\n    }\n\n    function reviveGauge(address _gauge) external {\n        require(msg.sender == emergencyCouncil, \"not emergency council\");\n        require(!isAlive[_gauge], \"gauge already alive\");\n        isAlive[_gauge] = true;\n        emit GaugeRevived(_gauge);\n    }\n\n    function attachTokenToGauge(uint tokenId, address account) external {\n        require(isGauge[msg.sender]);\n        require(isAlive[msg.sender]); // killed gauges cannot attach tokens to themselves\n        if (tokenId > 0) IVotingEscrow(_ve).attach(tokenId);\n        emit Attach(account, msg.sender, tokenId);\n    }\n\n    function emitDeposit(uint tokenId, address account, uint amount) external {\n        require(isGauge[msg.sender]);\n        require(isAlive[msg.sender]);\n        emit Deposit(account, msg.sender, tokenId, amount);\n    }\n\n    function detachTokenFromGauge(uint tokenId, address account) external {\n        require(isGauge[msg.sender]);\n        if (tokenId > 0) IVotingEscrow(_ve).detach(tokenId);\n        emit Detach(account, msg.sender, tokenId);\n    }\n\n    function emitWithdraw(uint tokenId, address account, uint amount) external {\n        require(isGauge[msg.sender]);\n        emit Withdraw(account, msg.sender, tokenId, amount);\n    }\n\n    function length() external view returns (uint) {\n        return pools.length;\n    }\n\n    uint internal index;\n    mapping(address => uint) internal supplyIndex;\n    mapping(address => uint) public claimable;\n\n    function notifyRewardAmount(uint amount) external {\n        _safeTransferFrom(base, msg.sender, address(this), amount); // transfer the distro in\n        uint256 _ratio = amount * 1e18 / totalWeight; // 1e18 adjustment is removed during claim\n        if (_ratio > 0) {\n            index += _ratio;\n        }\n        emit NotifyReward(msg.sender, base, amount);\n    }\n\n    function updateFor(address[] memory _gauges) external {\n        for (uint i = 0; i < _gauges.length; i++) {\n            _updateFor(_gauges[i]);\n        }\n    }\n\n    function updateForRange(uint start, uint end) public {\n        for (uint i = start; i < end; i++) {\n            _updateFor(gauges[pools[i]]);\n        }\n    }\n\n    function updateAll() external {\n        updateForRange(0, pools.length);\n    }\n\n    function updateGauge(address _gauge) external {\n        _updateFor(_gauge);\n    }\n\n    function _updateFor(address _gauge) internal {\n        require(isAlive[_gauge]); // killed gauges cannot be updated\n        address _pool = poolForGauge[_gauge];\n        uint256 _supplied = weights[_pool];\n        if (_supplied > 0) {\n            uint _supplyIndex = supplyIndex[_gauge];\n            uint _index = index; // get global index0 for accumulated distro\n            supplyIndex[_gauge] = _index; // update _gauge current position to global position\n            uint _delta = _index - _supplyIndex; // see if there is any difference that need to be accrued\n            if (_delta > 0) {\n                uint _share = uint(_supplied) * _delta / 1e18; // add accrued difference for each supplied token\n                claimable[_gauge] += _share;\n            }\n        } else {\n            supplyIndex[_gauge] = index; // new users are set to the default global state\n        }\n    }\n\n    function claimRewards(address[] memory _gauges, address[][] memory _tokens) external {\n        for (uint i = 0; i < _gauges.length; i++) {\n            IGauge(_gauges[i]).getReward(msg.sender, _tokens[i]);\n        }\n    }\n\n    function distributeFees(address[] memory _gauges) external {\n        for (uint i = 0; i < _gauges.length; i++) {\n            IGauge(_gauges[i]).claimFees();\n        }\n    }\n\n    function distribute(address _gauge) public lock {\n        require(isAlive[_gauge]); // killed gauges cannot distribute\n        uint dayCalc = block.timestamp % (7 days);\n        require((dayCalc < BRIBE_LAG) || (dayCalc > (DURATION + BRIBE_LAG)), \"cannot claim during votes period\");\n        IMinter(minter).update_period();\n        _updateFor(_gauge);\n        uint _claimable = claimable[_gauge];\n        if (_claimable > IGauge(_gauge).left(base) && _claimable / DURATION > 0) {\n            claimable[_gauge] = 0;\n            IGauge(_gauge).notifyRewardAmount(base, _claimable);\n            emit DistributeReward(msg.sender, _gauge, _claimable);\n            // distribute bribes & fees too\n            IGauge(_gauge).deliverBribes();\n        }\n    }\n\n    function distro() external {\n        distribute(0, pools.length);\n    }\n\n    function distribute() external {\n        distribute(0, pools.length);\n    }\n\n    function distribute(uint start, uint finish) public {\n        for (uint x = start; x < finish; x++) {\n            distribute(gauges[pools[x]]);\n        }\n    }\n\n    function distribute(address[] memory _gauges) external {\n        for (uint x = 0; x < _gauges.length; x++) {\n            distribute(_gauges[x]);\n        }\n    }\n\n    function _safeTransferFrom(address token, address from, address to, uint256 value) internal {\n        require(token.code.length > 0);\n        (bool success, bytes memory data) =\n        token.call(abi.encodeWithSelector(IERC20.transferFrom.selector, from, to, value));\n        require(success && (data.length == 0 || abi.decode(data, (bool))));\n    }\n}"
}