agent0.hyperfuzz.unit_fuzz.fuzz_present_value

Script to confirm present value and LP share price invariance.

# Test procedure - spin up local chain, deploy hyperdrive without fees - given trade list [open_long, close_long, open_short, close_short, add_liquidity, remove_liquidity]

  • trade amount in uniform[min_trade_amount, max_trade_amount) base

  • execute the trade and allow the block to tick (12 seconds)

  • check invariances after each trade

# Invariance checks (these should be True): - the following state values should equal:

  • for any trade, LP share price shouldn’t change by more than 0.1%

  • for any trade, present value should always be >= idle

  • open or close trades shouldn’t affect PV within 0.1

  • removing liquidity shouldn’t result in the PV increasing (it should decrease)

  • adding liquidity shouldn’t result in the PV decreasing (it should increase)

Classes

Args

Command line arguments for the invariant checker.

Functions

main([argv])

Primary entrypoint.

fuzz_present_value(test_epsilon, chain_config[, ...])

Does fuzzy invariant checks for opening and closing longs and shorts.

namespace_to_args(→ Args)

Converts argprase.Namespace to Args.

parse_arguments(→ Args)

Parses input arguments.

invariant_check(→ None)

Check the pool state invariants and throws an assertion exception if fails.

Module Contents

agent0.hyperfuzz.unit_fuzz.fuzz_present_value.main(argv: Sequence[str] | None = None)

Primary entrypoint.

Parameters:

argv (Sequence[str]) – The argv values returned from argparser.

agent0.hyperfuzz.unit_fuzz.fuzz_present_value.fuzz_present_value(test_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.

Parameters:
  • test_epsilon (float) – The allowed error for present value equality tests.

  • chain_config (LocalChain.Config, optional) – Configuration options for the local chain.

  • steth (bool) – Whether to use steth instead of erc4626

  • pause_on_fail (bool) – Whether to pause on failure.

class agent0.hyperfuzz.unit_fuzz.fuzz_present_value.Args

Bases: NamedTuple

Command line arguments for the invariant checker.

test_epsilon: float
chain_config: agent0.core.hyperdrive.interactive.LocalChain.Config
agent0.hyperfuzz.unit_fuzz.fuzz_present_value.namespace_to_args(namespace: argparse.Namespace) Args

Converts argprase.Namespace to Args.

Parameters:

namespace (argparse.Namespace) – Object for storing arg attributes.

Returns:

Formatted arguments

Return type:

Args

agent0.hyperfuzz.unit_fuzz.fuzz_present_value.parse_arguments(argv: Sequence[str] | None = None) Args

Parses input arguments.

Parameters:

argv (Sequence[str]) – The argv values returned from argparser.

Returns:

Formatted arguments

Return type:

Args

agent0.hyperfuzz.unit_fuzz.fuzz_present_value.invariant_check(check_data: dict[str, Any], test_epsilon: float, interactive_hyperdrive: agent0.core.hyperdrive.interactive.LocalHyperdrive) None

Check the pool state invariants and throws an assertion exception if fails.

Parameters:
  • check_data (dict[str, Any]) – The trade data to check.

  • test_epsilon (float) – The allowed error for present value equality tests. It is a float representing the proportional error tolerated. For example, test_epsilon = 0.01 means the actual_value must be within 1% of the expected_value.

  • interactive_hyperdrive (InteractiveHyperdrive) – An instantiated InteractiveHyperdrive object.