Skip to content
Closed
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
12 changes: 9 additions & 3 deletions contracts/libraries/HyperdriveMath.sol
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,10 @@ library HyperdriveMath {
if (_isBondOut && _timeRemaining < 1) {
revert Errors.HyperdriveMath_BaseWithNonzeroTime();
}

// 1/timestretch necessary for YieldSpaceMath
uint256 oneDivT = FixedPointMath.ONE_18.divDown(_timeStretch);

if (_isBondOut) {
// If bonds are being purchased, then the entire trade occurs on the
// curved portion since t = 1.
Expand All @@ -138,7 +142,7 @@ library HyperdriveMath {
_bondReserveAdjustment,
_amountIn,
FixedPointMath.ONE_18,
_timeStretch,
oneDivT,
_sharePrice,
_initialSharePrice,
_isBondOut
Expand All @@ -164,7 +168,7 @@ library HyperdriveMath {
_bondReserveAdjustment,
curveIn,
FixedPointMath.ONE_18,
_timeStretch,
oneDivT,
_sharePrice,
_initialSharePrice,
_isBondOut
Expand Down Expand Up @@ -221,6 +225,8 @@ library HyperdriveMath {
.mulDown(FixedPointMath.ONE_18.sub(_timeRemaining))
.divDown(_sharePrice);
uint256 curveOut = _amountOut.mulDown(_timeRemaining);
// 1/timestretch necessary for YieldSpaceMath
uint256 oneDivT = FixedPointMath.ONE_18.divDown(_timeStretch);
uint256 curveIn = YieldSpaceMath.calculateInGivenOut(
// Credit the share reserves by the flat trade.
_shareReserves.add(flat.divDown(_sharePrice)),
Expand All @@ -229,7 +235,7 @@ library HyperdriveMath {
_bondReserveAdjustment,
curveOut,
FixedPointMath.ONE_18,
_timeStretch,
oneDivT,
_sharePrice,
_initialSharePrice,
false
Expand Down