agent0.hyperfuzz.unit_fuzz.fuzz_long_short_maturity_values

Script to verify that longs and shorts which are closed at maturity supply the correct amounts.

# Test procedure - spin up local chain, deploy hyperdrive with fees - advance time to ensure we are in the middle of a checkpoint - execute random trades

  • from [open_long, open_short]

  • trade amount in uniform[min_trade_amount, max_trade_amount) base

  • advance one block (12 sec) between each trade.

  • advance time past the position duration, into a new checkpoint, create a checkpoint

  • close the trades one at a time in random order, run invariance checks after each close action

# Invariance checks (these should be True): if trade was open and close a long:

  • base out == bonds in minus flat fee

if trade was open and close a short:
  • base out == interest accrued

Classes

Args

Command line arguments for the invariant checker.

Functions

main([argv])

Primary entrypoint.

fuzz_long_short_maturity_values(num_trades, ...[, ...])

Does fuzzy invariant checks on closing longs and shorts past maturity.

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_long_short_maturity_values.main(argv: Sequence[str] | None = None)

Primary entrypoint.

Parameters:

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

agent0.hyperfuzz.unit_fuzz.fuzz_long_short_maturity_values.fuzz_long_short_maturity_values(num_trades: int, long_maturity_vals_epsilon: float, short_maturity_vals_epsilon: float, chain_config: agent0.core.hyperdrive.interactive.LocalChain.Config, steth: bool = False, pause_on_fail: bool = False)

Does fuzzy invariant checks on closing longs and shorts past maturity.

Parameters:
  • num_trades (int) – Number of trades to perform during the fuzz tests.

  • long_maturity_vals_epsilon (float) – The allowed error for maturity values equality tests for longs.

  • short_maturity_vals_epsilon (float) – The allowed error for maturity values equality tests for shorts.

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

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

  • pause_on_fail (bool) – If True, pause on test failure.

class agent0.hyperfuzz.unit_fuzz.fuzz_long_short_maturity_values.Args

Bases: NamedTuple

Command line arguments for the invariant checker.

num_trades: int
long_maturity_vals_epsilon: float
short_maturity_vals_epsilon: float
chain_config: agent0.core.hyperdrive.interactive.LocalChain.Config
agent0.hyperfuzz.unit_fuzz.fuzz_long_short_maturity_values.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_long_short_maturity_values.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_long_short_maturity_values.invariant_check(open_trade_event: hyperdrivetypes.OpenLongEventFP | hyperdrivetypes.OpenShortEventFP, close_trade_event: hyperdrivetypes.CloseLongEventFP | hyperdrivetypes.CloseShortEventFP, starting_checkpoint: hyperdrivetypes.CheckpointFP, maturity_checkpoint: hyperdrivetypes.CheckpointFP, long_maturity_vals_epsilon: float, short_maturity_vals_epsilon: float, interactive_hyperdrive: agent0.core.hyperdrive.interactive.LocalHyperdrive) None

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

Parameters:
  • open_trade_event (OpenLong | OpenShort) – The OpenLong or OpenShort event that resulted from opening the position.

  • close_trade_event (CloseLong | CloseShort) – The CloseLong or CloseShort event that resulted from closing the position.

  • starting_checkpoint (CheckpointFP) – The starting checkpoint.

  • maturity_checkpoint (CheckpointFP) – The maturity checkpoint.

  • long_maturity_vals_epsilon (float) – The epsilon value for the maturity values for longs.

  • short_maturity_vals_epsilon (float) – The epsilon value for the maturity values for shorts.

  • interactive_hyperdrive (InteractiveHyperdrive) – An instantiated InteractiveHyperdrive object.