Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

store open share price in Short #1353

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
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
3 changes: 2 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -152,9 +152,10 @@ unfixable = []
# We ignore the following rules:
# D203: 1 blank line required before class docstring (incompatible with D211: no blank lines before class docstring)
# D213: multi-line-summary-second-line (incompatible with D212: multi-line summary should start at the first line)
# D413: blank-line-after-last-section (not part of Numpy style guide)
# D415: First line should end with a period, question mark, or exclamation point (in period-only D400)
# D416: section-name-ends-in-colon (numpy style guide doesn't use colons after sections, i.e. Parameters)
ignore = ["D203", "D213", "D415", "D416"]
ignore = ["D203", "D213", "D413", "D415", "D416"]

# Default is: pycodestyle (E) and Pyflakes (F)
# We add flake8-builtins (A), pydocstyle (D), isort (I), pep8-naming (N), and pylint (PL).
Expand Down
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
8 changes: 8 additions & 0 deletions src/agent0/ethpy/hyperdrive/transactions.py
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,14 @@ 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
if all(x in log_args for x in ["baseAmount", "vaultShareAmount"]):
setattr(
trade_result,
"vault_share_price",
FixedPoint(scaled_value=log_args["baseAmount"]) / FixedPoint(scaled_value=log_args["vaultShareAmount"]),
)

return trade_result


Expand Down
Loading