Skip to content
This repository has been archived by the owner on May 2, 2024. It is now read-only.

Commit

Permalink
Update to hyperdrive v0.6.0 (#59)
Browse files Browse the repository at this point in the history
  • Loading branch information
slundqui authored Jan 26, 2024
1 parent 75bbfe6 commit ee5e623
Show file tree
Hide file tree
Showing 27 changed files with 503 additions and 308 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build_linux_wheel.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ jobs:
uses: actions/checkout@master
with:
repository: delvtech/hyperdrive
ref: "v0.5.1"
ref: "v0.6.0"
path: "./hyperdrive"
ssh-key: ${{ secrets.HYPERDRIVE_ACCESS_KEY }}

Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/build_wheels.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ jobs:
uses: actions/checkout@master
with:
repository: delvtech/hyperdrive
ref: "v0.5.1"
ref: "v0.6.0"
path: "./hyperdrive"
ssh-key: ${{ secrets.HYPERDRIVE_ACCESS_KEY }}

Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ jobs:
uses: actions/checkout@master
with:
repository: delvtech/hyperdrive
ref: "v0.5.1"
ref: "v0.6.0"
path: "./hyperdrive"
ssh-key: ${{ secrets.HYPERDRIVE_ACCESS_KEY }}

Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ jobs:
uses: actions/checkout@master
with:
repository: delvtech/hyperdrive
ref: "v0.5.1"
ref: "v0.6.0"
path: "./hyperdrive"
ssh-key: ${{ secrets.HYPERDRIVE_ACCESS_KEY }}

Expand Down
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,5 +39,5 @@ From the hyperdrive-sdk project root, run:

```shell
pip install --upgrade -r requirements-dev.txt
pypechain --line_length 120 --output_dir crates/hyperdrivepy/python/hyperdrivepy/pypechain_types hyperdrive/out/IERC4626Hyperdrive.sol/
pypechain --line-length 120 --output-dir crates/hyperdrivepy/python/hyperdrivepy/pypechain_types hyperdrive/out/IERC4626Hyperdrive.sol/
```
8 changes: 4 additions & 4 deletions crates/hyperdrive-wasm/src/short.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ pub fn calcOpenShort(
///
/// @param poolConfig - The pool's configuration
///
/// @param openSharePrice - The open share price of the pool's current
/// @param openVaultSharePrice - The open share price of the pool's current
/// checkpoint
///
/// @param checkpointExposure - The exposure of the pool's current checkpoint
Expand All @@ -59,7 +59,7 @@ pub fn getMaxShort(
poolInfo: &JsPoolInfo,
poolConfig: &JsPoolConfig,
budget: String,
openSharePrice: String,
openVaultSharePrice: String,
checkpointExposure: String,
maybeConservativePrice: Option<String>,
maybeMaxIterations: Option<u8>,
Expand All @@ -72,15 +72,15 @@ pub fn getMaxShort(
let _budget = U256::from_dec_str(&budget).unwrap();
let checkpoint_exposure: I256 =
I256::from_raw(U256::from_dec_str(&checkpointExposure).unwrap());
let open_share_price: I256 = I256::from_raw(U256::from_dec_str(&openSharePrice).unwrap());
let open_vault_share_price: I256 = I256::from_raw(U256::from_dec_str(&openVaultSharePrice).unwrap());

let _maybe_conservative_price: Option<FixedPoint> = maybeConservativePrice
.as_ref()
.map(|price_str| FixedPoint::from(U256::from_dec_str(price_str).unwrap()));

let result_fp = state.get_max_short(
_budget,
open_share_price,
open_vault_share_price,
checkpoint_exposure,
_maybe_conservative_price,
maybeMaxIterations.map(|x| x.into()),
Expand Down
2 changes: 1 addition & 1 deletion crates/hyperdrivepy/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
name = "hyperdrivepy"
edition = "2021"
version = "0.5.1"
version = "0.6.0"
authors = [
"Dylan Paiton",
"Matt Brown",
Expand Down
2 changes: 1 addition & 1 deletion crates/hyperdrivepy/pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[project]
name = "hyperdrivepy"
version = "0.5.1"
version = "0.6.0"
requires-python = ">=3.7"
classifiers = [
"Programming Language :: Rust",
Expand Down
1 change: 1 addition & 0 deletions crates/hyperdrivepy/python/hyperdrivepy/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
"""Python module wrapping the Rust implementation of HyperdriveMath"""

from .hyperdrive_state import * # pylint: disable=cyclic-import
from .hyperdrive_utils import * # pylint: disable=cyclic-import
29 changes: 15 additions & 14 deletions crates/hyperdrivepy/python/hyperdrivepy/hyperdrive_state.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Python wrapper for the rust hyperdrive_math::State module."""

from __future__ import annotations

from . import types
Expand Down Expand Up @@ -76,7 +77,7 @@ def get_solvency(
Returns
-------
str (FixedPoint)
solvency = share_reserves - long_exposure / share_price - minimum_share_reserves
solvency = share_reserves - long_exposure / vault_share_price - minimum_share_reserves
"""
return _get_interface(pool_config, pool_info).get_solvency()

Expand Down Expand Up @@ -187,7 +188,7 @@ def calculate_open_short(
pool_info: types.PoolInfoType,
short_amount: str,
spot_price: str,
open_share_price: str | None = None,
open_vault_share_price: str | None = None,
) -> str:
"""Gets the amount of base the trader will need to deposit for a short of a given size.
Expand All @@ -203,7 +204,7 @@ def calculate_open_short(
The amount to of bonds to short.
spot_price: str (FixedPoint)
The pool's current price for bonds.
open_share_price: str (FixedPoint) | None, optional
open_vault_share_price: str (FixedPoint) | None, optional
Optionally provide the open share price for the short.
If this is not provided or is None, then we will use the pool's current share price.
Expand All @@ -212,19 +213,19 @@ def calculate_open_short(
str (FixedPoint)
The amount of base required to short the bonds (aka the "max loss").
"""
if open_share_price is None:
if open_vault_share_price is None:
# the underlying rust code uses current market share price if this is 0
# zero value is used because the smart contract will return 0 if the checkpoint hasn't been minted
open_share_price = "0"
return _get_interface(pool_config, pool_info).calculate_open_short(short_amount, spot_price, open_share_price)
open_vault_share_price = "0"
return _get_interface(pool_config, pool_info).calculate_open_short(short_amount, spot_price, open_vault_share_price)


def calculate_close_short(
pool_config: types.PoolConfigType,
pool_info: types.PoolInfoType,
bond_amount: str,
open_share_price: str,
close_share_price: str,
open_vault_share_price: str,
close_vault_share_price: str,
normalized_time_remaining: str,
) -> str:
"""Gets the amount of shares the trader will receive from closing a short.
Expand All @@ -239,9 +240,9 @@ def calculate_close_short(
Includes attributes like reserve levels and share prices.
bond_amount: str (FixedPoint)
The amount to of bonds provided.
open_share_price: str (FixedPoint)
open_vault_share_price: str (FixedPoint)
The share price when the short was opened.
close_share_price: str (FixedPoint)
close_vault_share_price: str (FixedPoint)
The share price when the short was closed.
normalized_time_remaining: str (FixedPoint)
The time remaining before the short reaches maturity, normalized such that 0 is at opening and 1 is at maturity.
Expand All @@ -252,7 +253,7 @@ def calculate_close_short(
The amount of shares the trader will receive for closing the short.
"""
return _get_interface(pool_config, pool_info).calculate_close_short(
bond_amount, open_share_price, close_share_price, normalized_time_remaining
bond_amount, open_vault_share_price, close_vault_share_price, normalized_time_remaining
)


Expand Down Expand Up @@ -318,7 +319,7 @@ def get_max_short(
pool_config: types.PoolConfigType,
pool_info: types.PoolInfoType,
budget: str,
open_share_price: str,
open_vault_share_price: str,
checkpoint_exposure: str,
maybe_conservative_price: str | None,
maybe_max_iterations: int | None,
Expand All @@ -335,7 +336,7 @@ def get_max_short(
Includes attributes like reserve levels and share prices.
budget: str (FixedPoint)
The account budget in base for making a short.
open_share_price: str (FixedPoint)
open_vault_share_price: str (FixedPoint)
The share price of underlying vault.
checkpoint_exposure: str (FixedPoint)
The net exposure for the given checkpoint.
Expand All @@ -351,7 +352,7 @@ def get_max_short(
"""
return _get_interface(pool_config, pool_info).get_max_short(
budget,
open_share_price,
open_vault_share_price,
checkpoint_exposure,
maybe_conservative_price,
maybe_max_iterations,
Expand Down
7 changes: 4 additions & 3 deletions crates/hyperdrivepy/python/hyperdrivepy/hyperdrive_utils.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Python wrapper for the rust hyperdrive_math::utils module."""

from __future__ import annotations

# pylint: disable=no-name-in-module
Expand Down Expand Up @@ -52,7 +53,7 @@ def get_effective_share_reserves(

def calculate_initial_bond_reserves(
effective_share_reserves: str,
initial_share_price: str,
initial_vault_share_price: str,
apr: str,
position_duration: str,
time_stretch: str,
Expand All @@ -71,7 +72,7 @@ def calculate_initial_bond_reserves(
The pool's effective share reserves. The effective share
reserves are a modified version of the share reserves
used when pricing trades.
initial_share_price: str (FixedPoint)
initial_vault_share_price: str (FixedPoint)
The pool's initial share price.
apr: str (FixedPoint)
The pool's APR.
Expand All @@ -87,5 +88,5 @@ def calculate_initial_bond_reserves(
the pool have a specified APR.
"""
return rust_module.calculate_initial_bond_reserves(
effective_share_reserves, initial_share_price, apr, position_duration, time_stretch
effective_share_reserves, initial_vault_share_price, apr, position_duration, time_stretch
)
Loading

0 comments on commit ee5e623

Please sign in to comment.