contract InitialDistributionVial is LPTokenWrapperVial {
   
	address internal constant superVillainToken = 0xc1Ee2FDac2096d80F6dF62AB4e8dD1DD01b8113A;
    
    SuperVillain internal superVillain = SuperVillain(superVillainToken); 
	using SafeERC20 for SuperVillain; 
   
    uint256 internal lastUpdate;
    uint256 internal rewardPerTokenStored;
	mapping(address => uint256) internal userRewardPerTokenPaid;
    mapping(address => uint256) internal rewards;

    event Staked(address indexed user, uint256 amount);
    event Withdrawn(address indexed user, uint256 amount);
    event RewardPaid(address indexed user, uint256 reward);

  
    modifier updateReward(address account) {
		
		if (superVillain.isController(address(this))){
			uint256 issuance = block.number          // newly minted coins 
                .sub(lastUpdate)
                .mul(1e18);
			
            superVillain.mint(address(this),issuance); 
		}
		rewardPerTokenStored = rewardPerToken();
		lastUpdate = block.number;
		
        if (account != address(0)) {
            rewards[account] = earned(account);
            userRewardPerTokenPaid[account] = rewardPerTokenStored;
        }
        _;
    }
  
    function rewardPerToken() public view returns (uint256) {
        if (totalSupply() == 0 || !(superVillain.isController(address(this)))) {
            return rewardPerTokenStored;
        }
        return
            rewardPerTokenStored.add(
                block.number
                    .sub(lastUpdate)
                    .mul(1e18)   // these lines are the new rewards allowcated
					.mul(1e18)   // this converts to reward per full coin, not per 'satoshi'
                    .div(totalSupply())  
			);
    }

    function earned(address account) public view returns (uint256) {
        return
            balanceOf(account)
                .mul(rewardPerToken().sub(userRewardPerTokenPaid[account])).div(1e18)
                .add(rewards[account]);
    }

    // stake visibility is public as overriding LPTokenWrapper's stake() function
    function stake(uint256 amount) public override updateReward(msg.sender) {
        require(amount > 0, "Cannot stake 0");
        super.stake(amount);
        emit Staked(msg.sender, amount);
    }

    function withdraw(uint256 amount) public override updateReward(msg.sender) {
        require(amount > 0, "Cannot withdraw 0");
        super.withdraw(amount);
        emit Withdrawn(msg.sender, amount);
    }

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

    function getReward() public updateReward(msg.sender) {
        uint256 reward = earned(msg.sender);
        if (reward > 0) {
            rewards[msg.sender] = 0;
            superVillain.safeTransfer(msg.sender, reward);
            emit RewardPaid(msg.sender, reward);
        }
    }
	
	
}
function stake(uint256 amount) public override updateReward(msg.sender) {
    require(amount > 0, "Cannot stake 0");
    super.stake(amount);
    emit Staked(msg.sender, amount);
}

// stake visibility is public as overriding LPTokenWrapper's stake() function