Skip to content

Commit

Permalink
HyperdriveMathLib tests (#101)
Browse files Browse the repository at this point in the history
* tests

* fix calculateBondReserves tests

* add test for 100%

* add test for calculateOpenLong

* test close long at maturity and halfway thru maturity

* test open short

* test close short at maturity

* test close short halfway to  maturity

* tests for calculate base volume

* remove return statement increases coverage

* testing calculate lpAllocationAdjustment

* test__calculateOutForLpSharesIn

* removing return statement in calculateLpAllocationAdjustment increases coverage

* remove console import

* address review comments
  • Loading branch information
jrhea authored Feb 23, 2023
1 parent a78c198 commit 0fc0087
Show file tree
Hide file tree
Showing 3 changed files with 655 additions and 5 deletions.
8 changes: 3 additions & 5 deletions contracts/libraries/HyperdriveMath.sol
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ library HyperdriveMath {
_lpTotalSupply,
_initialSharePrice,
// full time remaining of position
annualizedTime,
FixedPointMath.ONE_18,
_timeStretch
);

Expand Down Expand Up @@ -72,12 +72,12 @@ library HyperdriveMath {
) internal pure returns (uint256 bondReserves) {
// NOTE: Using divDown to convert to fixed point format.
uint256 t = _positionDuration.divDown(365 days);
uint256 tau = t.mulDown(_timeStretch);
uint256 tau = FixedPointMath.ONE_18.mulDown(_timeStretch);
// mu * (1 + apr * t) ** (1 / tau) - c
uint256 rhs = _initialSharePrice
.mulDown(
FixedPointMath.ONE_18.add(_apr.mulDown(t)).pow(
FixedPointMath.ONE_18.divDown(tau)
FixedPointMath.ONE_18.divUp(tau)
)
)
.sub(_sharePrice);
Expand Down Expand Up @@ -513,7 +513,6 @@ library HyperdriveMath {
(FixedPointMath.ONE_18.sub(_timeRemaining)).mulDown(_bondAmount)
)
).divDown(_timeRemaining);
return baseVolume;
}

/// @dev Computes the LP allocation adjustment for a position. This is used
Expand All @@ -538,7 +537,6 @@ library HyperdriveMath {
);
// adjustment = baseAdjustment / c
adjustment = adjustment.divDown(_sharePrice);
return adjustment;
}

/// @dev Calculates the amount of base shares released from burning a
Expand Down
Loading

0 comments on commit 0fc0087

Please sign in to comment.