library CalcCarrots {
    using SafeMath for *;

    /**
     * @dev calculates number of carrots recieved given X eth
     */
    function carrotsReceived(uint256 _currEth, uint256 _newEth)
        internal
        pure
        returns (uint256)
    {
        return carrots((_currEth).add(_newEth)).sub(carrots(_currEth));
    }

    /**
     * @dev calculates amount of eth received if you sold X carrots
     */
    function ethReceived(uint256 _currCarrots, uint256 _sellCarrots)
        internal
        pure
        returns (uint256)
    {
        return eth(_currCarrots).sub(eth(_currCarrots.sub(_sellCarrots)));
    }

    /**
     * @dev calculates how many carrots for a single horse given an amount
     * of eth spent on that horse
     */
    function carrots(uint256 _eth)
        internal
        pure
        returns (uint256)
    {
        return ((((_eth).mul(62831853072000000000000000000000000000000000000)
            .add(9996858654086510028837239824000000000000000000000000000000000000)).sqrt())
            .sub(99984292036732000000000000000000)) / (31415926536);
    }

    /**
     * @dev calculates how much eth would be in the contract for a single
     * horse given an amount of carrots bought for that horse
     */
    function eth(uint256 _carrots)
        internal
        pure
        returns (uint256)
    {
        return ((15707963268).mul(_carrots.mul(_carrots)).add(((199968584073464)
            .mul(_carrots.mul(1000000000000000000))) / (2))) / (1000000000000000000000000000000000000);
    }
}
//   __   _   ___ ___  _ ___    __   _   _   __  _ _  _     _  ___ _  ___
//  / _| / \ | o \ o \/ \_ _|  / _| / \ | | / _|| | || |   / \|_ _/ \| o \
// ( (_ | o ||   /   ( o ) |  ( (_ | o || |( (_ | U || |_ | o || ( o )   /
//  \__||_n_||_|\\_|\\\_/|_|   \__||_n_||___\__||___||___||_n_||_|\_/|_|\\
//
function carrotsReceived(uint256 _currEth, uint256 _newEth)
    internal
    pure
    returns (uint256)
{
    return carrots((_currEth).add(_newEth)).sub(carrots(_currEth));
}

/**
 * @dev calculates number of carrots recieved given X eth
 */