library WoeKeysCalc {
    using SafeMath for *;

    // 根据现有ETH，计算新入X个ETH能购买的Keys数量
    function keysRec(uint256 _curEth, uint256 _newEth)
        internal
        pure
        returns (uint256)
    {
        return(keys((_curEth).add(_newEth)).sub(keys(_curEth)));
    }
    
    // 根据当前Keys数量，计算卖出X数量的keys值多少ETH
    function ethRec(uint256 _curKeys, uint256 _sellKeys)
        internal
        pure
        returns (uint256)
    {
        return((eth(_curKeys)).sub(eth(_curKeys.sub(_sellKeys))));
    }

    // 根据池中ETH数量计算对应的Keys数量
    function keys(uint256 _eth) 
        internal
        pure
        returns(uint256)
    {
        return ((((((_eth).mul(1000000000000000000)).mul(312500000000000000000000000)).add(5624988281256103515625000000000000000000000000000000000000000000)).sqrt()).sub(74999921875000000000000000000000)) / (156250000000);
    }
    
    // 根据Keys数量，计算池中ETH的数量
    function eth(uint256 _keys) 
        internal
        pure
        returns(uint256)  
    {
        return ((78125000000000).mul(_keys.sq()).add(((149999843750000).mul(_keys.mul(1000000000000000000000))) / (2))) / ((1000000000000000000).sq());
    }
}
// main contract ends here
// Keys价格相关计算
function keysRec(uint256 _curEth, uint256 _newEth)
    internal
    pure
    returns (uint256)
{
    return(keys((_curEth).add(_newEth)).sub(keys(_curEth)));
}

// 根据现有ETH，计算新入X个ETH能购买的Keys数量