Skip to content
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
# pylint: disable=redefined-outer-name
# ruff: noqa: PLR2004 (comparison against magic values (literals like numbers))

YEAR_IN_SECONDS = 31_536_000


@pytest.mark.anvil
def _ensure_db_wallet_matches_agent_wallet(
Expand Down Expand Up @@ -592,3 +594,25 @@ def test_policy_config_forgotten(chain: LocalChain):
policy=Zoo.random,
)
assert alice.agent.policy is not None


@pytest.mark.anvil
def test_two_trades_cancel(chain: LocalChain):
"""The economic impact of two trades on the same number of bonds, but in opposite directions, should cancel."""
initial_liquidity = FixedPoint(10_000_000)
interactive_config = InteractiveHyperdrive.Config(
position_duration=YEAR_IN_SECONDS, governance_lp_fee=FixedPoint(0), initial_liquidity=initial_liquidity
)
interactive_hyperdrive = InteractiveHyperdrive(chain, interactive_config)
starting_fixed_rate = interactive_hyperdrive.hyperdrive_interface.calc_fixed_rate()
# give them same amount of base as in the pool, so they can trade whatever they want
alice = interactive_hyperdrive.init_agent(base=initial_liquidity)
bob = interactive_hyperdrive.init_agent(base=initial_liquidity)
event = alice.open_long(base=FixedPoint(1e6)) # trade 1 million in a pool with 10 million liquidity
bob.open_short(bonds=event.bond_amount)
ending_fixed_rate = interactive_hyperdrive.hyperdrive_interface.calc_fixed_rate()
assert ending_fixed_rate == starting_fixed_rate, (
f"Expected {starting_fixed_rate} but got {ending_fixed_rate}"
f", diff={ending_fixed_rate - starting_fixed_rate}"
f", diff(%)={Decimal(str((ending_fixed_rate - starting_fixed_rate) / starting_fixed_rate)):e}"
)