degenbot.uniswap.v2_pool_calc ============================= .. py:module:: degenbot.uniswap.v2_pool_calc .. autoapi-nested-parse:: Calculation mixin for Uniswap V2-style constant-product pools. Provides read-only calculation methods that operate on state held by V2PoolState (or a compatible state mixin). All methods are non-mutating and delegate to standalone calculation functions where possible. Pools with different calculation paths (e.g., Aerodrome's stable mode, Camelot's k invariant) define their own calc mixin instead of using this one. See: contract_reference/uniswap/V2/UniswapV2Factory.sol (UniswapV2Pair swap/mint/burn) Module Contents --------------- .. py:class:: UniswapV2PoolCalc Calculation methods matching the Uniswap V2 contract. All methods operate on state held by the concrete class via V2PoolState. Subclasses override as needed for contract-specific differences. Class variables with Uniswap V2 defaults: FEE: Directional fee rate (default 0.3%) .. py:attribute:: reserves_token0 :type: int .. py:attribute:: reserves_token1 :type: int .. py:attribute:: state :type: degenbot.uniswap.v2_types.UniswapV2PoolState .. py:attribute:: tokens :type: tuple[degenbot.erc20.Erc20Token, degenbot.erc20.Erc20Token] .. py:attribute:: FEE :type: fractions.Fraction .. py:method:: calculate_tokens_in_from_tokens_out(token_out_quantity: int, token_out: degenbot.erc20.Erc20Token, override_state: degenbot.uniswap.v2_types.UniswapV2PoolState | None = None) -> int Calculate the required token INPUT for a target OUTPUT at current pool reserves. :returns: The required input token amount. :raises InvalidSwapInputAmount: If token_out_quantity is not positive. :raises DegenbotValueError: If token_out is not held by this pool. :raises LiquidityPoolError: If the requested output exceeds available reserves. .. py:method:: calculate_tokens_out_from_tokens_in(token_in: degenbot.erc20.Erc20Token, token_in_quantity: int, override_state: degenbot.uniswap.v2_types.UniswapV2PoolState | None = None) -> int Calculate the expected token OUTPUT for a target INPUT at current pool reserves. :returns: The expected output token amount. :raises InvalidSwapInputAmount: If token_in_quantity is not positive. :raises DegenbotValueError: If token_in is not held by this pool. :raises LiquidityPoolError: If `uint256` swap math overflows (on-chain revert). .. py:method:: get_absolute_price(token: degenbot.erc20.Erc20Token, override_state: degenbot.uniswap.v2_types.UniswapV2PoolState | None = None) -> fractions.Fraction Get the absolute price for the given token, expressed in units of the other. :returns: The absolute price as a Fraction. .. py:method:: get_absolute_exchange_rate(token: degenbot.erc20.Erc20Token, override_state: degenbot.uniswap.v2_types.UniswapV2PoolState | None = None) -> fractions.Fraction Get the absolute exchange rate for the given token. :returns: The absolute exchange rate as a Fraction. :raises DegenbotValueError: If the token is not held by this pool. .. py:method:: get_nominal_price(token: degenbot.erc20.Erc20Token, override_state: degenbot.uniswap.v2_types.UniswapV2PoolState | None = None) -> fractions.Fraction Get the nominal price for the given token, corrected for decimals. :returns: The nominal price as a Fraction. .. py:method:: get_nominal_exchange_rate(token: degenbot.erc20.Erc20Token, override_state: degenbot.uniswap.v2_types.UniswapV2PoolState | None = None) -> fractions.Fraction Get the nominal exchange rate, corrected for decimal place values. :returns: The nominal exchange rate as a Fraction.