Skip to content
Draft
Show file tree
Hide file tree
Changes from 1 commit
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
2 changes: 2 additions & 0 deletions src/agent0/core/hyperdrive/agent/hyperdrive_wallet.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ class Short:
"""The amount of bonds that the position is short."""
maturity_time: int
"""The maturity time of the short."""
open_vault_share_price: FixedPoint = FixedPoint(0)
"""The vault share price at the time of opening the short."""


@dataclass(kw_only=True)
Expand Down
7 changes: 5 additions & 2 deletions src/agent0/core/hyperdrive/exec/execute_agent_trades.py
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,9 @@ async def async_match_contract_call_to_trade(
),
shorts={
trade_result.maturity_time_seconds: Short(
balance=trade_result.bond_amount, maturity_time=trade_result.maturity_time_seconds
open_vault_share_price=trade_result.vault_share_price,
balance=trade_result.bond_amount,
maturity_time=trade_result.maturity_time_seconds,
)
},
)
Expand All @@ -290,7 +292,8 @@ async def async_match_contract_call_to_trade(
),
shorts={
trade.maturity_time: Short(
balance=-trade_result.bond_amount, maturity_time=trade_result.maturity_time_seconds
balance=-trade_result.bond_amount,
maturity_time=trade_result.maturity_time_seconds,
)
},
)
Expand Down
7 changes: 7 additions & 0 deletions src/agent0/ethpy/hyperdrive/transactions.py
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,13 @@ def parse_logs(tx_receipt: TxReceipt, hyperdrive_contract: Contract, fn_name: st
if value in log_args and hasattr(trade_result, camel_to_snake(value)):
setattr(trade_result, camel_to_snake(value), FixedPoint(scaled_value=log_args[value]))

# special handling for vault_share_price since it's not emitted, but calculated as base_amount / vault_share_amount
setattr(
trade_result,
"vault_share_price",
FixedPoint(scaled_value=log_args["baseAmount"]) / FixedPoint(scaled_value=log_args["vaultShareAmount"]),
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tests are saying not all results contain baseAmount or vaultShareAmount (e.g., in createCheckpoint). Lets wrap this in a check for these keys.

)

return trade_result


Expand Down