Skip to content
Merged
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion contracts/src/external/Hyperdrive.sol
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ abstract contract Hyperdrive is

/// @inheritdoc IHyperdriveCore
function checkpoint(uint256) external {
_delegate(target2);
_delegate(target4);
}

/// Admin ///
Expand Down
8 changes: 0 additions & 8 deletions contracts/src/external/HyperdriveTarget2.sol
Original file line number Diff line number Diff line change
Expand Up @@ -71,12 +71,4 @@ abstract contract HyperdriveTarget2 is
) external returns (uint256) {
return _closeShort(_maturityTime, _bondAmount, _minOutput, _options);
}

/// Checkpoints ///

/// @notice Allows anyone to mint a new checkpoint.
/// @param _checkpointTime The time of the checkpoint to create.
function checkpoint(uint256 _checkpointTime) external {
_checkpoint(_checkpointTime);
}
}
8 changes: 8 additions & 0 deletions contracts/src/external/HyperdriveTarget4.sol
Original file line number Diff line number Diff line change
Expand Up @@ -55,4 +55,12 @@ abstract contract HyperdriveTarget4 is
return
_openShort(_bondAmount, _maxDeposit, _minVaultSharePrice, _options);
}

/// Checkpoints ///

/// @notice Allows anyone to mint a new checkpoint.
/// @param _checkpointTime The time of the checkpoint to create.
function checkpoint(uint256 _checkpointTime) external {
_checkpoint(_checkpointTime);
}
}
7 changes: 3 additions & 4 deletions contracts/src/interfaces/IHyperdrive.sol
Original file line number Diff line number Diff line change
Expand Up @@ -250,10 +250,6 @@ interface IHyperdrive is
/// @notice Thrown when the present value calculation fails.
error InvalidPresentValue();

/// @notice Thrown when update liquidity brings the share reserves below
/// the minimum share reserves.
error InvalidShareReserves();

/// @notice Thrown when an invalid signature is used provide permit access
/// to the MultiToken. A signature is considered to be invalid if
/// it fails to recover to the owner's address.
Expand Down Expand Up @@ -352,6 +348,9 @@ interface IHyperdrive is
/// targets that are supported vary between instances.
error UnsupportedToken();

/// @notice Thrown when `LPMath.calculateUpdateLiquidity` fails.
error UpdateLiquidityFailed();

/// Getters ///

/// @notice Gets the target0 address.
Expand Down
36 changes: 30 additions & 6 deletions contracts/src/libraries/HyperdriveMath.sol
Original file line number Diff line number Diff line change
Expand Up @@ -135,21 +135,45 @@ library HyperdriveMath {
/// flat+curve trades.
/// @param _shareReserves The pool's share reserves.
/// @param _shareAdjustment The pool's share adjustment.
/// @return The effective share reserves.
/// @return effectiveShareReserves The effective share reserves.
function calculateEffectiveShareReserves(
uint256 _shareReserves,
int256 _shareAdjustment
) internal pure returns (uint256) {
int256 effectiveShareReserves = _shareReserves.toInt256() -
_shareAdjustment;
if (effectiveShareReserves < 0) {
) internal pure returns (uint256 effectiveShareReserves) {
bool success;
(effectiveShareReserves, success) = calculateEffectiveShareReservesSafe(
_shareReserves,
_shareAdjustment
);
if (!success) {
Errors.throwInsufficientLiquidityError(
IHyperdrive
.InsufficientLiquidityReason
.InvalidEffectiveShareReserves
);
}
return uint256(effectiveShareReserves);
}

/// @dev Calculates the effective share reserves. The effective share
/// reserves are the share reserves minus the share adjustment or
/// z - zeta. We use the effective share reserves as the z-parameter
/// to the YieldSpace pricing model. The share adjustment is used to
/// hold the pricing mechanism invariant under the flat component of
/// flat+curve trades.
/// @param _shareReserves The pool's share reserves.
/// @param _shareAdjustment The pool's share adjustment.
/// @return The effective share reserves.
/// @return A flag indicating if the calculation succeeded.
function calculateEffectiveShareReservesSafe(
uint256 _shareReserves,
int256 _shareAdjustment
) internal pure returns (uint256, bool) {
int256 effectiveShareReserves = _shareReserves.toInt256() -
_shareAdjustment;
if (effectiveShareReserves < 0) {
return (0, false);
}
return (uint256(effectiveShareReserves), true);
}

/// @dev Calculates the initial bond reserves assuming that the initial LP
Expand Down
Loading