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

Commit

Permalink
time stretch hotfix (#58)
Browse files Browse the repository at this point in the history
The rust `get_time_stretch` formula was an incorrect port from solidity,
and the test was not sufficiently complicated to catch it. These are
resolved now, but the python wheels need to be rebuilt using Hyperdrive
0.5.1
  • Loading branch information
dpaiton authored Jan 18, 2024
1 parent a67cb2c commit 75bbfe6
Show file tree
Hide file tree
Showing 13 changed files with 38 additions and 28 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.0"
ref: "v0.5.1"
path: "./hyperdrive"
ssh-key: ${{ secrets.HYPERDRIVE_ACCESS_KEY }}

Expand Down
8 changes: 4 additions & 4 deletions .github/workflows/build_wasm.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ jobs:
uses: actions/setup-node@v3
with:
node-version: 16
registry-url: 'https://registry.npmjs.org'
registry-url: "https://registry.npmjs.org"

- name: setup foundry
uses: foundry-rs/foundry-toolchain@v1
Expand All @@ -49,8 +49,8 @@ jobs:
uses: actions/checkout@master
with:
repository: delvtech/hyperdrive
ref: 'v0.5.0'
path: './hyperdrive'
ref: "v0.5.1"
path: "./hyperdrive"
ssh-key: ${{ secrets.HYPERDRIVE_ACCESS_KEY }}

- name: build hyperdrive-wasm
Expand All @@ -60,4 +60,4 @@ jobs:
- name: publish hyperdrive-wasm
if: github.event_name == 'release'
working-directory: crates/hyperdrive-wasm/pkg
run: npm publish --access public
run: npm publish --access public
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.0"
ref: "v0.5.1"
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.0"
ref: "v0.5.1"
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.0"
ref: "v0.5.1"
path: "./hyperdrive"
ssh-key: ${{ secrets.HYPERDRIVE_ACCESS_KEY }}

Expand Down
4 changes: 2 additions & 2 deletions 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 crates/hyperdrive-wasm/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "hyperdrive-wasm"
version = "0.5.0"
version = "0.5.1"
edition = "2021"

[lib]
Expand Down
4 changes: 2 additions & 2 deletions crates/hyperdrive-wasm/example/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,6 @@
"webpack-dev-server": "^4.15.1"
},
"dependencies": {
"@delvtech/hyperdrive-wasm": "file:delvtech-hyperdrive-wasm-0.5.0.tgz"
"@delvtech/hyperdrive-wasm": "file:delvtech-hyperdrive-wasm-0.5.1.tgz"
}
}
}
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.0"
version = "0.5.1"
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.0"
version = "0.5.1"
requires-python = ">=3.7"
classifiers = [
"Programming Language :: Rust",
Expand Down
24 changes: 13 additions & 11 deletions crates/hyperdrivepy/python/hyperdrivepy/hyperdrive_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,14 @@ def get_time_stretch(rate: str, position_duration: str) -> str:
Arguments
---------
rate : str (FixedPoint)
rate: str (FixedPoint)
The pool's spot rate (aka apr, or fixed rate).
position_duration: str(FixedPoint)
The amount of time before a trade matures.
Returns
-------
time_stretch : str (FixedPoint)
time_stretch: str (FixedPoint)
The time stretch parameter (tau).
"""
return rust_module.get_time_stretch(rate, position_duration)
Expand All @@ -35,14 +37,14 @@ def get_effective_share_reserves(
Arguments
---------
share_reserves : str (FixedPoint)
share_reserves: str (FixedPoint)
The pool's share reserves.
share_adjustment : str (I256)
share_adjustment: str (I256)
The zeta factor for adjusting share reserves.
Returns
-------
effective_share_reserves : str (FixedPoint)
effective_share_reserves: str (FixedPoint)
The adjusted share reserves, accounting for the zeta factor.
"""
return rust_module.get_effective_share_reserves(share_reserves, share_adjustment)
Expand All @@ -65,22 +67,22 @@ def calculate_initial_bond_reserves(
Arguments
---------
effective_share_reserves : str (FixedPoint)
effective_share_reserves: str (FixedPoint)
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_share_price: str (FixedPoint)
The pool's initial share price.
apr : str (FixedPoint)
apr: str (FixedPoint)
The pool's APR.
position_duration : str (FixedPoint)
position_duration: str (FixedPoint)
The amount of time until maturity in seconds.
time_stretch : str (FixedPoint)
time_stretch: str (FixedPoint)
The time stretch parameter (tau).
Returns
-------
bond_reserves : str (FixedPoint)
bond_reserves: str (FixedPoint)
The bond reserves (without adjustment) that make
the pool have a specified APR.
"""
Expand Down
2 changes: 1 addition & 1 deletion crates/hyperdrivepy/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

setup(
name="hyperdrivepy",
version="0.5.0",
version="0.5.1",
packages=["hyperdrivepy"],
package_dir={"": "python"},
rust_extensions=[
Expand Down
10 changes: 9 additions & 1 deletion system_tests/wrapper_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,15 @@ def test_get_time_stretch():
"""test get_time_stretch."""
time_stretch = hyperdrivepy.get_time_stretch(
hyperdrivepy.get_spot_rate(POOL_CONFIG, POOL_INFO),
str(POOL_CONFIG.positionDuration),
str(60 * 60 * 24 * 365), # 1 year
)
assert time_stretch is not None, "Failed to get time_stretch."
assert isinstance(time_stretch, str), "Expected time_stretch to be a string."
assert float(time_stretch) > 0, "Expected time_stretch to be > 0."

time_stretch = hyperdrivepy.get_time_stretch(
hyperdrivepy.get_spot_rate(POOL_CONFIG, POOL_INFO),
str(60 * 60 * 24 * 30), # ~1 month
)
assert time_stretch is not None, "Failed to get time_stretch."
assert isinstance(time_stretch, str), "Expected time_stretch to be a string."
Expand Down

0 comments on commit 75bbfe6

Please sign in to comment.