Skip to content

Commit

Permalink
get_idle_shares use passed in pool_state (#1447)
Browse files Browse the repository at this point in the history
  • Loading branch information
slundqui authored Apr 30, 2024
1 parent c4e145a commit 4a386ef
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 11 deletions.
15 changes: 7 additions & 8 deletions src/agent0/ethpy/hyperdrive/interface/read_interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -384,24 +384,23 @@ def get_vault_shares(self, block_number: BlockNumber | None) -> FixedPoint:
block_number = self.get_block_number(self.get_current_block())
return _get_vault_shares(self.vault_shares_token_contract, self.hyperdrive_contract, block_number)

def get_idle_shares(self, block_number: BlockNumber | None) -> FixedPoint:
def get_idle_shares(self, pool_state: PoolState | None) -> FixedPoint:
"""Get the balance of idle shares that the Hyperdrive pool has.
Arguments
---------
block_number: BlockNumber, optional
The number for any minted block.
Defaults to the current block number.
pool_state: PoolState, optional
The state of the pool, which includes block details, pool config, and pool info.
If not given, use the current pool state.
Returns
-------
FixedPoint
The quantity of vault shares for the yield source at the provided block.
"""
if block_number is None:
block_number = self.get_block_number(self.get_current_block())
pool_state = self.current_pool_state
long_exposure_shares = self.current_pool_state.pool_info.long_exposure / pool_state.pool_info.vault_share_price
if pool_state is None:
pool_state = self.current_pool_state
long_exposure_shares = pool_state.pool_info.long_exposure / pool_state.pool_info.vault_share_price
idle_shares = (
pool_state.pool_info.share_reserves - long_exposure_shares - pool_state.pool_config.minimum_share_reserves
)
Expand Down
3 changes: 1 addition & 2 deletions src/agent0/hyperfuzz/system_fuzz/invariant_checks.py
Original file line number Diff line number Diff line change
Expand Up @@ -282,8 +282,7 @@ def _check_present_value_greater_than_idle_shares(
exception_data: dict[str, Any] = {}

present_value = interface.calc_present_value(pool_state)
block_number = pool_state.block_number
idle_shares = interface.get_idle_shares(block_number)
idle_shares = interface.get_idle_shares(pool_state)

if not present_value >= idle_shares:
difference_in_wei = abs(present_value.scaled_value - idle_shares.scaled_value)
Expand Down
2 changes: 1 addition & 1 deletion src/agent0/hyperfuzz/unit_fuzz/fuzz_present_value.py
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,7 @@ def invariant_check(
# idle shares are the shares that are not reserved by open positions
# TODO: Add calculate_idle_share_reserves to hyperdrivepy and use that here.
current_present_value = interactive_hyperdrive.interface.calc_present_value(pool_state)
idle_shares = interactive_hyperdrive.interface.get_idle_shares(pool_state.block_number)
idle_shares = interactive_hyperdrive.interface.get_idle_shares(pool_state)
if current_present_value < idle_shares:
difference_in_wei = abs(current_present_value.scaled_value - idle_shares.scaled_value)
exception_message.append("The present value is not greater than or equal to the idle.")
Expand Down

0 comments on commit 4a386ef

Please sign in to comment.