Skip to content

Commit d264165

Browse files
authored
Scrapped #847 for parts (#847)
1 parent 3cdf469 commit d264165

File tree

7 files changed

+201
-74
lines changed

7 files changed

+201
-74
lines changed

contracts/src/external/Hyperdrive.sol

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,7 @@ abstract contract Hyperdrive is
236236

237237
/// @inheritdoc IHyperdriveCore
238238
function checkpoint(uint256) external {
239-
_delegate(target2);
239+
_delegate(target4);
240240
}
241241

242242
/// Admin ///

contracts/src/external/HyperdriveTarget2.sol

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -71,12 +71,4 @@ abstract contract HyperdriveTarget2 is
7171
) external returns (uint256) {
7272
return _closeShort(_maturityTime, _bondAmount, _minOutput, _options);
7373
}
74-
75-
/// Checkpoints ///
76-
77-
/// @notice Allows anyone to mint a new checkpoint.
78-
/// @param _checkpointTime The time of the checkpoint to create.
79-
function checkpoint(uint256 _checkpointTime) external {
80-
_checkpoint(_checkpointTime);
81-
}
8274
}

contracts/src/external/HyperdriveTarget4.sol

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,4 +55,12 @@ abstract contract HyperdriveTarget4 is
5555
return
5656
_openShort(_bondAmount, _maxDeposit, _minVaultSharePrice, _options);
5757
}
58+
59+
/// Checkpoints ///
60+
61+
/// @notice Allows anyone to mint a new checkpoint.
62+
/// @param _checkpointTime The time of the checkpoint to create.
63+
function checkpoint(uint256 _checkpointTime) external {
64+
_checkpoint(_checkpointTime);
65+
}
5866
}

contracts/src/interfaces/IHyperdrive.sol

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -250,10 +250,6 @@ interface IHyperdrive is
250250
/// @notice Thrown when the present value calculation fails.
251251
error InvalidPresentValue();
252252

253-
/// @notice Thrown when update liquidity brings the share reserves below
254-
/// the minimum share reserves.
255-
error InvalidShareReserves();
256-
257253
/// @notice Thrown when an invalid signature is used provide permit access
258254
/// to the MultiToken. A signature is considered to be invalid if
259255
/// it fails to recover to the owner's address.
@@ -352,6 +348,9 @@ interface IHyperdrive is
352348
/// targets that are supported vary between instances.
353349
error UnsupportedToken();
354350

351+
/// @notice Thrown when `LPMath.calculateUpdateLiquidity` fails.
352+
error UpdateLiquidityFailed();
353+
355354
/// Getters ///
356355

357356
/// @notice Gets the target0 address.

contracts/src/libraries/HyperdriveMath.sol

Lines changed: 30 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -135,21 +135,45 @@ library HyperdriveMath {
135135
/// flat+curve trades.
136136
/// @param _shareReserves The pool's share reserves.
137137
/// @param _shareAdjustment The pool's share adjustment.
138-
/// @return The effective share reserves.
138+
/// @return effectiveShareReserves The effective share reserves.
139139
function calculateEffectiveShareReserves(
140140
uint256 _shareReserves,
141141
int256 _shareAdjustment
142-
) internal pure returns (uint256) {
143-
int256 effectiveShareReserves = _shareReserves.toInt256() -
144-
_shareAdjustment;
145-
if (effectiveShareReserves < 0) {
142+
) internal pure returns (uint256 effectiveShareReserves) {
143+
bool success;
144+
(effectiveShareReserves, success) = calculateEffectiveShareReservesSafe(
145+
_shareReserves,
146+
_shareAdjustment
147+
);
148+
if (!success) {
146149
Errors.throwInsufficientLiquidityError(
147150
IHyperdrive
148151
.InsufficientLiquidityReason
149152
.InvalidEffectiveShareReserves
150153
);
151154
}
152-
return uint256(effectiveShareReserves);
155+
}
156+
157+
/// @dev Calculates the effective share reserves. The effective share
158+
/// reserves are the share reserves minus the share adjustment or
159+
/// z - zeta. We use the effective share reserves as the z-parameter
160+
/// to the YieldSpace pricing model. The share adjustment is used to
161+
/// hold the pricing mechanism invariant under the flat component of
162+
/// flat+curve trades.
163+
/// @param _shareReserves The pool's share reserves.
164+
/// @param _shareAdjustment The pool's share adjustment.
165+
/// @return The effective share reserves.
166+
/// @return A flag indicating if the calculation succeeded.
167+
function calculateEffectiveShareReservesSafe(
168+
uint256 _shareReserves,
169+
int256 _shareAdjustment
170+
) internal pure returns (uint256, bool) {
171+
int256 effectiveShareReserves = _shareReserves.toInt256() -
172+
_shareAdjustment;
173+
if (effectiveShareReserves < 0) {
174+
return (0, false);
175+
}
176+
return (uint256(effectiveShareReserves), true);
153177
}
154178

155179
/// @dev Calculates the initial bond reserves assuming that the initial LP

0 commit comments

Comments
 (0)