def _estimate_from_amount(self, from_token, to_token, to_desired_amount): max_error = 3e-15 exchange_contract = self._find_exchange_contract(from_token, to_token) conversion_func = self._get_conversion_function(exchange_contract, from_token, to_token) def root_func(x): return conversion_func(x) - to_desired_amount x_lower, y_lower, x_upper, y_upper = find_monotonic_increasing_bounds(root_func, to_desired_amount) new_x, new_y = false_position_method( root_func, x_lower, y_lower, x_upper, y_upper, max_error, max_iterations=6) return new_x, new_y + to_desired_amount
def test_find_monotonic_increasing_bounds(root_func, guess, root): x_lower, y_lower, x_upper, y_upper = find_monotonic_increasing_bounds( root_func, guess) assert x_lower <= root assert x_upper >= root