agent0.hyperfuzz.unit_fuzz.fuzz_path_independence ================================================= .. py:module:: agent0.hyperfuzz.unit_fuzz.fuzz_path_independence .. autoapi-nested-parse:: Script to verify that the state of pool reserves is invariant to the order in which positions are closed. # Test procedure - spin up local chain, deploy hyperdrive without fees - execute random trades - from [open_long, open_short] - trade amount in uniform[min_trade_amount, max_trade_amount) base - advance one block (12 sec) betwen each trade. - advance time randomly between trades - the maximum time advance between first and last trade is in [0, position_duration) - set the variable rate to 0 - save a snapshot of the current chain state - repeat N times (where N is set as a command-line arg): - load chain state (all trades are opened, none are closed) - close the trades in a random order - invariance checks # Invariance checks (these should be True): # We are checking that the pool ends up in the same sate regardless of close transaction order - the following state values should equal in all checks: - effective share reserves - present value - shorts outstanding - withdrawal shares proceeds - lp share price - long exposure - bond reserves - lp total supply - longs outstanding .. !! processed by numpydoc !! Classes ------- .. autoapisummary:: agent0.hyperfuzz.unit_fuzz.fuzz_path_independence.Args Functions --------- .. autoapisummary:: agent0.hyperfuzz.unit_fuzz.fuzz_path_independence.main agent0.hyperfuzz.unit_fuzz.fuzz_path_independence.fuzz_path_independence agent0.hyperfuzz.unit_fuzz.fuzz_path_independence.namespace_to_args agent0.hyperfuzz.unit_fuzz.fuzz_path_independence.parse_arguments agent0.hyperfuzz.unit_fuzz.fuzz_path_independence.invariant_check Module Contents --------------- .. py:function:: main(argv: Sequence[str] | None = None) Primary entrypoint. :param argv: The argv values returned from argparser. :type argv: Sequence[str] .. !! processed by numpydoc !! .. py:function:: fuzz_path_independence(num_trades: int, num_paths_checked: int, lp_share_price_epsilon: float, effective_share_reserves_epsilon: float, present_value_epsilon: float, chain_config: agent0.core.hyperdrive.interactive.LocalChain.Config, steth: bool = False, pause_on_fail: bool = False) Does fuzzy invariant checks for opening and closing longs and shorts. :param num_trades: Number of trades to perform during the fuzz tests. :type num_trades: int :param num_paths_checked: Number of paths (order of operations for opening/closing) to perform. :type num_paths_checked: int :param lp_share_price_epsilon: The allowed error for LP share price equality tests. :type lp_share_price_epsilon: float :param effective_share_reserves_epsilon: The allowed error for effective share reserves equality tests. :type effective_share_reserves_epsilon: float :param present_value_epsilon: The allowed error for present value equality tests. :type present_value_epsilon: float :param chain_config: Configuration options for the local chain. :type chain_config: LocalChain.Config, optional :param steth: Whether to use steth instead of erc4626 :type steth: bool :param pause_on_fail: Whether to pause on failure. :type pause_on_fail: bool .. !! processed by numpydoc !! .. py:class:: Args Bases: :py:obj:`NamedTuple` Command line arguments for the invariant checker. .. !! processed by numpydoc !! .. py:attribute:: num_trades :type: int .. py:attribute:: num_paths_checked :type: int .. py:attribute:: lp_share_price_epsilon :type: float .. py:attribute:: effective_share_reserves_epsilon :type: float .. py:attribute:: present_value_epsilon :type: float .. py:attribute:: chain_config :type: agent0.core.hyperdrive.interactive.LocalChain.Config .. py:function:: namespace_to_args(namespace: argparse.Namespace) -> Args Converts argprase.Namespace to Args. :param namespace: Object for storing arg attributes. :type namespace: argparse.Namespace :returns: Formatted arguments :rtype: Args .. !! processed by numpydoc !! .. py:function:: parse_arguments(argv: Sequence[str] | None = None) -> Args Parses input arguments. :param argv: The argv values returned from argparser. :type argv: Sequence[str] :returns: Formatted arguments :rtype: Args .. !! processed by numpydoc !! .. py:function:: invariant_check(check_data: dict[str, Any], check_epsilon: dict[str, Any], interactive_hyperdrive: agent0.core.hyperdrive.interactive.LocalHyperdrive) -> None Check the pool state invariants and throws an assertion exception if fails. :param check_data: The trade data to check. :type check_data: dict[str, Any] :param check_epsilon: The expected epsilon for each invariants check. :type check_epsilon: dict[str, Any] :param interactive_hyperdrive: An instantiated InteractiveHyperdrive object. :type interactive_hyperdrive: InteractiveHyperdrive .. !! processed by numpydoc !!