Skip to content

Commit 4827596

Browse files
authored
Updated PoolInfo (#535)
1 parent 2324420 commit 4827596

5 files changed

Lines changed: 91 additions & 71 deletions

File tree

contracts/src/HyperdriveBase.sol

Lines changed: 0 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -217,46 +217,6 @@ abstract contract HyperdriveBase is MultiToken, HyperdriveStorage {
217217

218218
/// Helpers ///
219219

220-
/// @dev Calculates the normalized time remaining of a position.
221-
/// @param _maturityTime The maturity time of the position.
222-
/// @return timeRemaining The normalized time remaining (in [0, 1]).
223-
function _calculateTimeRemaining(
224-
uint256 _maturityTime
225-
) internal view returns (uint256 timeRemaining) {
226-
uint256 latestCheckpoint = _latestCheckpoint();
227-
timeRemaining = _maturityTime > latestCheckpoint
228-
? _maturityTime - latestCheckpoint
229-
: 0;
230-
timeRemaining = (timeRemaining).divDown(_positionDuration);
231-
}
232-
233-
/// @dev Calculates the normalized time remaining of a position when the
234-
/// maturity time is scaled up 18 decimals.
235-
/// @param _maturityTime The maturity time of the position.
236-
function _calculateTimeRemainingScaled(
237-
uint256 _maturityTime
238-
) internal view returns (uint256 timeRemaining) {
239-
uint256 latestCheckpoint = _latestCheckpoint() * FixedPointMath.ONE_18;
240-
timeRemaining = _maturityTime > latestCheckpoint
241-
? _maturityTime - latestCheckpoint
242-
: 0;
243-
timeRemaining = (timeRemaining).divDown(
244-
_positionDuration * FixedPointMath.ONE_18
245-
);
246-
}
247-
248-
/// @dev Gets the most recent checkpoint time.
249-
/// @return latestCheckpoint The latest checkpoint.
250-
function _latestCheckpoint()
251-
internal
252-
view
253-
returns (uint256 latestCheckpoint)
254-
{
255-
latestCheckpoint =
256-
block.timestamp -
257-
(block.timestamp % _checkpointDuration);
258-
}
259-
260220
/// @dev Calculates the fees that go to the LPs and governance.
261221
/// @param _amountIn Amount in shares.
262222
/// @param _spotPrice The price without slippage of bonds in terms of base (base/bonds).

contracts/src/HyperdriveDataProvider.sol

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { HyperdriveStorage } from "./HyperdriveStorage.sol";
55
import { IHyperdrive } from "./interfaces/IHyperdrive.sol";
66
import { AssetId } from "./libraries/AssetId.sol";
77
import { FixedPointMath } from "./libraries/FixedPointMath.sol";
8+
import { HyperdriveMath } from "./libraries/HyperdriveMath.sol";
89
import { MultiTokenDataProvider } from "./token/MultiTokenDataProvider.sol";
910

1011
/// @author DELV
@@ -85,16 +86,26 @@ abstract contract HyperdriveDataProvider is
8586
/// important to evaluate potential trades.
8687
/// @return The PoolInfo struct.
8788
function getPoolInfo() external view returns (IHyperdrive.PoolInfo memory) {
89+
uint256 sharePrice = _pricePerShare();
90+
uint256 lpTotalSupply = _totalSupply[AssetId._LP_ASSET_ID] +
91+
_totalSupply[AssetId._WITHDRAWAL_SHARE_ASSET_ID] -
92+
_withdrawPool.readyToWithdraw;
93+
uint256 presentValue = HyperdriveMath
94+
.calculatePresentValue(_getPresentValueParams(sharePrice))
95+
.mulDown(sharePrice);
8896
IHyperdrive.PoolInfo memory poolInfo = IHyperdrive.PoolInfo({
8997
shareReserves: _marketState.shareReserves,
9098
bondReserves: _marketState.bondReserves,
91-
lpTotalSupply: _totalSupply[AssetId._LP_ASSET_ID],
92-
sharePrice: _pricePerShare(),
99+
sharePrice: sharePrice,
93100
longsOutstanding: _marketState.longsOutstanding,
94101
longAverageMaturityTime: _marketState.longAverageMaturityTime,
95102
shortsOutstanding: _marketState.shortsOutstanding,
96103
shortAverageMaturityTime: _marketState.shortAverageMaturityTime,
97104
shortBaseVolume: _marketState.shortBaseVolume,
105+
lpTotalSupply: lpTotalSupply,
106+
lpSharePrice: lpTotalSupply == 0
107+
? 0
108+
: presentValue.divDown(lpTotalSupply),
98109
withdrawalSharesReadyToWithdraw: _withdrawPool.readyToWithdraw,
99110
withdrawalSharesProceeds: _withdrawPool.proceeds
100111
});

contracts/src/HyperdriveLP.sol

Lines changed: 0 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -557,33 +557,4 @@ abstract contract HyperdriveLP is HyperdriveTWAP {
557557
// Remove the withdrawal pool proceeds from the reserves.
558558
_updateLiquidity(-int256(withdrawalPoolProceeds));
559559
}
560-
561-
/// @dev Gets the present value parameters from the current state.
562-
/// @param _sharePrice The current share price.
563-
/// @return presentValue The present value parameters.
564-
function _getPresentValueParams(
565-
uint256 _sharePrice
566-
)
567-
internal
568-
view
569-
returns (HyperdriveMath.PresentValueParams memory presentValue)
570-
{
571-
presentValue = HyperdriveMath.PresentValueParams({
572-
shareReserves: _marketState.shareReserves,
573-
bondReserves: _marketState.bondReserves,
574-
sharePrice: _sharePrice,
575-
initialSharePrice: _initialSharePrice,
576-
minimumShareReserves: _minimumShareReserves,
577-
timeStretch: _timeStretch,
578-
longsOutstanding: _marketState.longsOutstanding,
579-
longAverageTimeRemaining: _calculateTimeRemainingScaled(
580-
_marketState.longAverageMaturityTime
581-
),
582-
shortsOutstanding: _marketState.shortsOutstanding,
583-
shortAverageTimeRemaining: _calculateTimeRemainingScaled(
584-
_marketState.shortAverageMaturityTime
585-
),
586-
shortBaseVolume: _marketState.shortBaseVolume
587-
});
588-
}
589560
}

contracts/src/HyperdriveStorage.sol

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ pragma solidity 0.8.19;
44
import { ReentrancyGuard } from "solmate/utils/ReentrancyGuard.sol";
55
import { IERC20 } from "./interfaces/IERC20.sol";
66
import { IHyperdrive } from "./interfaces/IHyperdrive.sol";
7+
import { FixedPointMath } from "./libraries/FixedPointMath.sol";
8+
import { HyperdriveMath } from "./libraries/HyperdriveMath.sol";
79
import { MultiTokenStorage } from "./token/MultiTokenStorage.sol";
810

911
/// @author DELV
@@ -13,6 +15,8 @@ import { MultiTokenStorage } from "./token/MultiTokenStorage.sol";
1315
/// only, and is not intended to, and does not, have any
1416
/// particular legal or regulatory significance.
1517
abstract contract HyperdriveStorage is ReentrancyGuard, MultiTokenStorage {
18+
using FixedPointMath for uint256;
19+
1620
/// Tokens ///
1721

1822
/// @notice The base asset.
@@ -143,4 +147,75 @@ abstract contract HyperdriveStorage is ReentrancyGuard, MultiTokenStorage {
143147
// Initialize the oracle.
144148
_updateGap = _config.updateGap;
145149
}
150+
151+
/// Helpers ///
152+
153+
/// @dev Calculates the normalized time remaining of a position.
154+
/// @param _maturityTime The maturity time of the position.
155+
/// @return timeRemaining The normalized time remaining (in [0, 1]).
156+
function _calculateTimeRemaining(
157+
uint256 _maturityTime
158+
) internal view returns (uint256 timeRemaining) {
159+
uint256 latestCheckpoint = _latestCheckpoint();
160+
timeRemaining = _maturityTime > latestCheckpoint
161+
? _maturityTime - latestCheckpoint
162+
: 0;
163+
timeRemaining = (timeRemaining).divDown(_positionDuration);
164+
}
165+
166+
/// @dev Calculates the normalized time remaining of a position when the
167+
/// maturity time is scaled up 18 decimals.
168+
/// @param _maturityTime The maturity time of the position.
169+
function _calculateTimeRemainingScaled(
170+
uint256 _maturityTime
171+
) internal view returns (uint256 timeRemaining) {
172+
uint256 latestCheckpoint = _latestCheckpoint() * FixedPointMath.ONE_18;
173+
timeRemaining = _maturityTime > latestCheckpoint
174+
? _maturityTime - latestCheckpoint
175+
: 0;
176+
timeRemaining = (timeRemaining).divDown(
177+
_positionDuration * FixedPointMath.ONE_18
178+
);
179+
}
180+
181+
/// @dev Gets the most recent checkpoint time.
182+
/// @return latestCheckpoint The latest checkpoint.
183+
function _latestCheckpoint()
184+
internal
185+
view
186+
returns (uint256 latestCheckpoint)
187+
{
188+
latestCheckpoint =
189+
block.timestamp -
190+
(block.timestamp % _checkpointDuration);
191+
}
192+
193+
/// @dev Gets the present value parameters from the current state.
194+
/// @param _sharePrice The current share price.
195+
/// @return presentValue The present value parameters.
196+
function _getPresentValueParams(
197+
uint256 _sharePrice
198+
)
199+
internal
200+
view
201+
returns (HyperdriveMath.PresentValueParams memory presentValue)
202+
{
203+
presentValue = HyperdriveMath.PresentValueParams({
204+
shareReserves: _marketState.shareReserves,
205+
bondReserves: _marketState.bondReserves,
206+
sharePrice: _sharePrice,
207+
initialSharePrice: _initialSharePrice,
208+
minimumShareReserves: _minimumShareReserves,
209+
timeStretch: _timeStretch,
210+
longsOutstanding: _marketState.longsOutstanding,
211+
longAverageTimeRemaining: _calculateTimeRemainingScaled(
212+
_marketState.longAverageMaturityTime
213+
),
214+
shortsOutstanding: _marketState.shortsOutstanding,
215+
shortAverageTimeRemaining: _calculateTimeRemainingScaled(
216+
_marketState.shortAverageMaturityTime
217+
),
218+
shortBaseVolume: _marketState.shortBaseVolume
219+
});
220+
}
146221
}

contracts/src/interfaces/IHyperdrive.sol

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,9 @@ interface IHyperdrive is IHyperdriveRead, IHyperdriveWrite, IMultiToken {
177177
uint256 withdrawalSharesReadyToWithdraw;
178178
/// @dev The proceeds recovered by the withdrawal pool.
179179
uint256 withdrawalSharesProceeds;
180+
/// @dev The share price of LP shares. This can be used to mark LP
181+
/// shares to market.
182+
uint256 lpSharePrice;
180183
}
181184

182185
struct OracleState {

0 commit comments

Comments
 (0)