Skip to content

Commit

Permalink
test two_trades_cancel
Browse files Browse the repository at this point in the history
  • Loading branch information
wakamex committed Jan 11, 2024
1 parent 87b5c32 commit 9b0870b
Showing 1 changed file with 22 additions and 0 deletions.
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,23 @@ 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}, diff={ending_fixed_rate - starting_fixed_rate}, diff(%)={Decimal(str((ending_fixed_rate - starting_fixed_rate) / starting_fixed_rate)):e}"

0 comments on commit 9b0870b

Please sign in to comment.