Skip to content
Merged
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
19 changes: 18 additions & 1 deletion contracts/src/internal/HyperdriveLong.sol
Original file line number Diff line number Diff line change
Expand Up @@ -436,7 +436,7 @@ abstract contract HyperdriveLong is IHyperdriveEvents, HyperdriveLP {
_vaultSharePrice
);

// Calculate the impact of the curve fee on the bond reservse. The curve
// Calculate the impact of the curve fee on the bond reserves. The curve
// fee benefits the LPs by causing less bonds to be deducted from the
// bond reserves.
bondReservesDelta -= curveFee;
Expand All @@ -463,6 +463,23 @@ abstract contract HyperdriveLong is IHyperdriveEvents, HyperdriveLP {
// shares = shares - shares
shareReservesDelta = _shareAmount - totalGovernanceFee;

// Ensure that the ending spot price is less than or equal to one.
// Despite the fact that the earlier negative interest check should
// imply this, we perform this check out of an abundance of caution
// since the `pow` function is known to not be monotonic.
if (
HyperdriveMath.calculateSpotPrice(
_effectiveShareReserves() + shareReservesDelta,
_marketState.bondReserves - bondReservesDelta,
_initialVaultSharePrice,
_timeStretch
) > ONE
) {
Errors.throwInsufficientLiquidityError(
IHyperdrive.InsufficientLiquidityReason.NegativeInterest
);
}

return (shareReservesDelta, bondReservesDelta, totalGovernanceFee);
}

Expand Down