Skip to content

Commit

Permalink
rename short_base_volume to long_exposure
Browse files Browse the repository at this point in the history
  • Loading branch information
dpaiton committed Sep 13, 2023
1 parent 4c9cb79 commit aaef57c
Show file tree
Hide file tree
Showing 9 changed files with 20 additions and 22 deletions.
6 changes: 3 additions & 3 deletions lib/agent0/agent0/hyperdrive/state/hyperdrive_market_state.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ class HyperdriveMarketState(BaseMarketState):
The average maturity time of short positions.
long_base_volume: FixedPoint
The amount of base paid by outstanding longs.
short_base_volume: FixedPoint
long_exposure: FixedPoint
The amount of base paid to outstanding shorts.
checkpoints: dict[FixedPoint, elfpy.markets.hyperdrive.checkpoint.Checkpoint]
Time delimited checkpoints
Expand Down Expand Up @@ -91,7 +91,7 @@ class HyperdriveMarketState(BaseMarketState):
long_average_maturity_time: FixedPoint = FixedPoint(0)
short_average_maturity_time: FixedPoint = FixedPoint(0)
long_base_volume: FixedPoint = FixedPoint(0)
short_base_volume: FixedPoint = FixedPoint(0)
long_exposure: FixedPoint = FixedPoint(0)
checkpoint_duration: FixedPoint = FixedPoint("1.0").div_up(FixedPoint("365.0"))
checkpoint_duration_days: FixedPoint = FixedPoint("1.0")
total_supply_longs: dict[FixedPoint, FixedPoint] = field(default_factory=dict)
Expand All @@ -116,7 +116,7 @@ def apply_delta(self, delta: HyperdriveMarketState) -> None:
self.long_average_maturity_time += delta.long_average_maturity_time
self.short_average_maturity_time += delta.short_average_maturity_time
self.long_base_volume += delta.long_base_volume
self.short_base_volume += delta.short_base_volume
self.long_exposure += delta.long_exposure
# tracking shares after closing positions
self.total_supply_withdraw_shares += delta.total_supply_withdraw_shares
self.withdraw_shares_ready_to_withdraw += delta.withdraw_shares_ready_to_withdraw
Expand Down
2 changes: 1 addition & 1 deletion lib/chainsync/chainsync/dashboard/extract_data_logs.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ def get_combined_data(txn_data, pool_info_data):
"sharePrice": "share_price",
"shareReserves": "share_reserves",
"shortAverageMaturityTime": "short_average_maturity_time",
"shortBaseVolume": "short_base_volume",
"longExposure": "long_exposure",
"shortsOutstanding": "shorts_outstanding",
"timestamp": "block_timestamp",
"transactionHash": "transaction_hash",
Expand Down
2 changes: 1 addition & 1 deletion lib/chainsync/chainsync/db/hyperdrive/interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,7 @@ def get_checkpoint_info(
This includes
- `sharePrice` : The share price of the first transaction in the checkpoint.
- `longSharePrice` : The weighted average of the share prices that all longs in the checkpoint were opened at.
- `shortBaseVolume` : The aggregate amount of base committed by LPs to pay for bonds sold short in the checkpoint.
- `longExposure` : The aggregate amount of base committed by LPs to pay for bonds sold short in the checkpoint.
Arguments
---------
Expand Down
4 changes: 2 additions & 2 deletions lib/chainsync/chainsync/db/hyperdrive/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ class CheckpointInfo(Base):
timestamp: Mapped[datetime] = mapped_column(DateTime)
sharePrice: Mapped[Union[Decimal, None]] = mapped_column(FIXED_NUMERIC, default=None)
longSharePrice: Mapped[Union[Decimal, None]] = mapped_column(FIXED_NUMERIC, default=None)
shortBaseVolume: Mapped[Union[Decimal, None]] = mapped_column(FIXED_NUMERIC, default=None)
longExposure: Mapped[Union[Decimal, None]] = mapped_column(FIXED_NUMERIC, default=None)


class PoolInfo(Base):
Expand All @@ -75,7 +75,7 @@ class PoolInfo(Base):
longAverageMaturityTime: Mapped[Union[Decimal, None]] = mapped_column(FIXED_NUMERIC, default=None)
shortsOutstanding: Mapped[Union[Decimal, None]] = mapped_column(FIXED_NUMERIC, default=None)
shortAverageMaturityTime: Mapped[Union[Decimal, None]] = mapped_column(FIXED_NUMERIC, default=None)
shortBaseVolume: Mapped[Union[Decimal, None]] = mapped_column(FIXED_NUMERIC, default=None)
longExposure: Mapped[Union[Decimal, None]] = mapped_column(FIXED_NUMERIC, default=None)
withdrawalSharesReadyToWithdraw: Mapped[Union[Decimal, None]] = mapped_column(FIXED_NUMERIC, default=None)
withdrawalSharesProceeds: Mapped[Union[Decimal, None]] = mapped_column(FIXED_NUMERIC, default=None)
totalSupplyWithdrawalShares: Mapped[Union[Decimal, None]] = mapped_column(FIXED_NUMERIC, default=None)
Expand Down
2 changes: 1 addition & 1 deletion lib/elfpy/elfpy/markets/hyperdrive/checkpoint.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ def __setitem__(self, key, value):
share_price: FixedPoint = FixedPoint(0)
long_share_price: FixedPoint = FixedPoint(0)
long_base_volume: FixedPoint = FixedPoint(0)
short_base_volume: FixedPoint = FixedPoint(0)
long_exposure: FixedPoint = FixedPoint(0)


# all values zeroed
Expand Down
11 changes: 5 additions & 6 deletions lib/elfpy/elfpy/markets/hyperdrive/hyperdrive_market.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@
from dataclasses import dataclass, field
from typing import TYPE_CHECKING

from fixedpointmath import FixedPoint

import elfpy
import elfpy.errors.errors as errors
import elfpy.markets.hyperdrive.hyperdrive_actions as hyperdrive_actions
Expand All @@ -16,6 +14,7 @@
import elfpy.utils.price as price_utils
from elfpy.markets.base import BaseMarket, BaseMarketState
from elfpy.wallet.wallet_deltas import WalletDeltas
from fixedpointmath import FixedPoint

from .checkpoint import Checkpoint
from .hyperdrive_actions import HyperdriveMarketAction, MarketActionType
Expand Down Expand Up @@ -71,7 +70,7 @@ class HyperdriveMarketState(BaseMarketState):
The average maturity time of short positions.
long_base_volume: FixedPoint
The amount of base paid by outstanding longs.
short_base_volume: FixedPoint
long_exposure: FixedPoint
The amount of base paid to outstanding shorts.
checkpoints: dict[FixedPoint, elfpy.markets.hyperdrive.checkpoint.Checkpoint]
Time delimited checkpoints
Expand Down Expand Up @@ -115,7 +114,7 @@ def __setitem__(self, key, value):
long_average_maturity_time: FixedPoint = FixedPoint(0)
short_average_maturity_time: FixedPoint = FixedPoint(0)
long_base_volume: FixedPoint = FixedPoint(0)
short_base_volume: FixedPoint = FixedPoint(0)
long_exposure: FixedPoint = FixedPoint(0)
checkpoints: dict[FixedPoint, Checkpoint] = field(default_factory=dict)
checkpoint_duration: FixedPoint = FixedPoint("1.0").div_up(FixedPoint("365.0"))
checkpoint_duration_days: FixedPoint = FixedPoint("1.0")
Expand All @@ -141,7 +140,7 @@ def apply_delta(self, delta: HyperdriveMarketDeltas) -> None:
self.long_average_maturity_time += delta.long_average_maturity_time
self.short_average_maturity_time += delta.short_average_maturity_time
self.long_base_volume += delta.long_base_volume
self.short_base_volume += delta.short_base_volume
self.long_exposure += delta.long_exposure
# tracking shares after closing positions
self.total_supply_withdraw_shares += delta.total_supply_withdraw_shares
self.withdraw_shares_ready_to_withdraw += delta.withdraw_shares_ready_to_withdraw
Expand All @@ -151,7 +150,7 @@ def apply_delta(self, delta: HyperdriveMarketDeltas) -> None:
for mint_time, delta_checkpoint in delta.long_checkpoints.items():
self.checkpoints.get(mint_time, Checkpoint()).long_base_volume += delta_checkpoint
for mint_time, delta_checkpoint in delta.short_checkpoints.items():
self.checkpoints.get(mint_time, Checkpoint()).short_base_volume += delta_checkpoint
self.checkpoints.get(mint_time, Checkpoint()).long_exposure += delta_checkpoint
for mint_time, delta_supply in delta.total_supply_longs.items():
self.total_supply_longs[mint_time] = self.total_supply_longs.get(mint_time, FixedPoint(0)) + delta_supply
for mint_time, delta_supply in delta.total_supply_shorts.items():
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,9 @@

from dataclasses import dataclass, field

from fixedpointmath import FixedPoint

import elfpy.types as types
from elfpy.markets.base import BaseMarketDeltas
from fixedpointmath import FixedPoint


@types.freezable(frozen=True, no_new_attribs=True)
Expand All @@ -25,7 +24,7 @@ class HyperdriveMarketDeltas(BaseMarketDeltas):
long_average_maturity_time: FixedPoint = FixedPoint(0)
short_average_maturity_time: FixedPoint = FixedPoint(0)
long_base_volume: FixedPoint = FixedPoint(0)
short_base_volume: FixedPoint = FixedPoint(0)
long_exposure: FixedPoint = FixedPoint(0)
total_supply_withdraw_shares: FixedPoint = FixedPoint(0)
withdraw_shares_ready_to_withdraw: FixedPoint = FixedPoint(0)
withdraw_capital: FixedPoint = FixedPoint(0)
Expand Down
6 changes: 3 additions & 3 deletions lib/elfpy/tests/pricing_models/test_calc_max_long_short.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ def test_calculate_max_long(self):
longAverageMaturityTime 0
shortsOutstanding 0
shortAverageMaturityTime 0
shortBaseVolume 0
longExposure 0
withdrawalSharesReadyToWithdraw 0
# Expected result
Expand All @@ -71,7 +71,7 @@ def test_calculate_max_long(self):
longAverageMaturityTime 126144000000000000000000000
shortsOutstanding 0
shortAverageMaturityTime 0
shortBaseVolume 0
longExposure 0
withdrawalSharesReadyToWithdraw 0
withdrawalSharesProceeds 0
"""
Expand Down Expand Up @@ -147,7 +147,7 @@ def test_calculate_max_short(self):
# longAverageMaturityTime 0
# shortsOutstanding 0
# shortAverageMaturityTime 0
# shortBaseVolume 0
# longExposure 0
# withdrawalSharesReadyToWithdraw 0
# withdrawalSharesProceeds 0

Expand Down
4 changes: 2 additions & 2 deletions lib/ethpy/ethpy/hyperdrive/interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ def get_hyperdrive_checkpoint_info(
"timestamp": datetime.fromtimestamp(current_block_timestamp),
"sharePrice": FixedPoint(scaled_value=checkpoint_data["sharePrice"]),
"longSharePrice": FixedPoint(scaled_value=checkpoint_data["longSharePrice"]),
"shortBaseVolume": FixedPoint(scaled_value=checkpoint_data["shortBaseVolume"]),
"longExposure": FixedPoint(scaled_value=checkpoint_data["longExposure"]),
}


Expand Down Expand Up @@ -153,7 +153,7 @@ def get_hyperdrive_market(web3: Web3, hyperdrive_contract: Contract) -> Hyperdri
share_reserves=FixedPoint(pool_info["shareReserves"]),
minimum_share_reserves=FixedPoint(pool_config["minimumShareReserves"]),
short_average_maturity_time=FixedPoint(pool_info["shortAverageMaturityTime"]),
short_base_volume=FixedPoint(pool_info["shortBaseVolume"]),
long_exposure=FixedPoint(pool_info["longExposure"]),
shorts_outstanding=FixedPoint(pool_info["shortsOutstanding"]),
# TODO: We don't have checkpoint information, so the next two fields are indexed by 0
total_supply_longs={FixedPoint(0): FixedPoint(pool_info["longsOutstanding"])},
Expand Down

0 comments on commit aaef57c

Please sign in to comment.