contract Proceeds is Owned {
    using SafeMath for uint256;

    AutonomousConverter public autonomousConverter;
    Auctions public auctions;
    event LogProceedsIn(address indexed from, uint value); 
    event LogClosedAuction(address indexed from, uint value);
    uint latestAuctionClosed;

    function initProceeds(address _autonomousConverter, address _auctions) public onlyOwner {
        require(address(auctions) == 0x0 && _auctions != 0x0);
        require(address(autonomousConverter) == 0x0 && _autonomousConverter != 0x0);

        autonomousConverter = AutonomousConverter(_autonomousConverter);
        auctions = Auctions(_auctions);
    }

    function handleFund() public payable {
        require(msg.sender == address(auctions));
        emit LogProceedsIn(msg.sender, msg.value);
    }

    /// @notice Forward 0.25% of total ETH balance of proceeds to AutonomousConverter contract
    function closeAuction() public {
        uint lastPurchaseTick = auctions.lastPurchaseTick();
        uint currentAuction = auctions.currentAuction();
        uint val = ((address(this).balance).mul(25)).div(10000); 
        if (val > 0 && (currentAuction > auctions.whichAuction(lastPurchaseTick)) 
            && (latestAuctionClosed < currentAuction)) {
            latestAuctionClosed = currentAuction;
            autonomousConverter.handleFund.value(val)();
            emit LogClosedAuction(msg.sender, val);
        }
    }
}
/// @title Proceeds contract
function closeAuction() public {
    uint lastPurchaseTick = auctions.lastPurchaseTick();
    uint currentAuction = auctions.currentAuction();
    uint val = ((address(this).balance).mul(25)).div(10000); 
    if (val > 0 && (currentAuction > auctions.whichAuction(lastPurchaseTick)) 
        && (latestAuctionClosed < currentAuction)) {
        latestAuctionClosed = currentAuction;
        autonomousConverter.handleFund.value(val)();
        emit LogClosedAuction(msg.sender, val);
    }
}

/// @notice Forward 0.25% of total ETH balance of proceeds to AutonomousConverter contract