contract BlootMinterProxy is Ownable { // start BlootMinterProxy contract

    using SafeMath for uint256;

    uint256 constant private BLOOT_REWARD_PER_DAY = 10 ether;
    
    uint256 constant private SECS_IN_DAY = 86400;
    uint256 constant private REWARD_DENOMINATOR = 1000000000000000000;
    
    address constant private BLOOT_ADDRESS = 0x4F8730E0b32B04beaa5757e5aea3aeF970E5B613;
    address constant private MINTER_PROXY_ADDRESS = 0xe664175081C887DA5894c1f39a94010b8316c8c3;
    address constant private SODA_ADDRESS = 0x2624bB7854D823e80b2BAFf2066e2979Cd5e0186;
    
    uint256 private contractBirthTime;
    
    address private minter;
    
    IERC721 bloot = IERC721(BLOOT_ADDRESS);
    IMinterProxy minterProxy = IMinterProxy(MINTER_PROXY_ADDRESS);
    IERC721 soda = IERC721(SODA_ADDRESS);
    
    mapping(uint256 => uint256) private blootTimeRewards;
    mapping(uint256 => uint256) private blootLastUpdate;
    
    constructor() public {
        contractBirthTime = now;
    }
    
    modifier onlyMinter {
        if (msg.sender != minter) revert();
        _;
    }
    
    function claimAllAccumulatedBlootRewards(uint256[] memory nftIds) public {
        for (uint i = 0; i < nftIds.length; i++){
            claimAccumulatedBlootRewards(nftIds[i]);
        }
    }
    
    function claimAccumulatedBlootRewards(uint256 nftId) public {
        require(soda.balanceOf(msg.sender) >= 1, "You need to hold a Lazer Soda in your wallet to claim the bloot time reward");
        require(bloot.ownerOf(nftId) ==  msg.sender, "You don't own this Bloot NFT");

        uint256 dailyReward = BLOOT_REWARD_PER_DAY;
        uint256 time = block.timestamp;
        uint256 lastTime = blootLastUpdate[nftId];
        if (lastTime == 0) {
            lastTime = contractBirthTime;
        }
        
        uint256 timePassed = time.sub(lastTime);
        uint256 additionalRewards = dailyReward.mul(timePassed).div(SECS_IN_DAY);
        blootTimeRewards[nftId] = blootTimeRewards[nftId].add(additionalRewards);

        blootLastUpdate[nftId] = time;
        uint256 payout = blootTimeRewards[nftId];
        
        blootTimeRewards[nftId] = 0;
        minterProxy.minterMint(msg.sender, payout);
    }
    
    function viewAccumulatedBlootDecimalRewards(uint256 nftId) public view returns (uint256[2] memory) {
        uint256 time = block.timestamp;
        uint256 lastTime = blootLastUpdate[nftId];
        if (lastTime == 0) {
            lastTime = contractBirthTime;
        }
  
        uint256 dailyReward = BLOOT_REWARD_PER_DAY;
        uint256 timePassed = time.sub(lastTime);
        uint256 additionalRewards = dailyReward.mul(timePassed).div(SECS_IN_DAY);
        uint256[2] memory res =  [blootTimeRewards[nftId].add(additionalRewards), REWARD_DENOMINATOR];
        return res;
    }
    
    // Minter 
    
    function getMinter() public view returns (address) {
        return minter;
    }
    
    function minterMint(address _to, uint256 _amount) external onlyMinter {
        minterProxy.minterMint(_to, _amount);
    }
    
    function setMinter(address _minter) public onlyOwner {
        minter = _minter;
    }
    
}
function getMinter() public view returns (address) {
    return minter;
}

// Minter 