diff --git a/contracts/src/deployers/HyperdriveDeployerCoordinator.sol b/contracts/src/deployers/HyperdriveDeployerCoordinator.sol index d307c31dc..4b19debf6 100644 --- a/contracts/src/deployers/HyperdriveDeployerCoordinator.sol +++ b/contracts/src/deployers/HyperdriveDeployerCoordinator.sol @@ -59,9 +59,9 @@ abstract contract HyperdriveDeployerCoordinator is IHyperdriveDeployer { bytes memory _extraData ) external override returns (address) { // Convert the deploy config into the pool config and set the initial - // share price. + // vault share price. IHyperdrive.PoolConfig memory _config = _copyPoolConfig(_deployConfig); - _config.initialSharePrice = _getInitialSharePrice(_extraData); + _config.initialVaultSharePrice = _getInitialVaultSharePrice(_extraData); // Deploy the target0 contract. address target0 = IHyperdriveTargetDeployer(target0Deployer).deploy( @@ -93,10 +93,10 @@ abstract contract HyperdriveDeployerCoordinator is IHyperdriveDeployer { ); } - /// @dev Gets the initial share price of the Hyperdrive pool. + /// @dev Gets the initial vault share price of the Hyperdrive pool. /// @param _extraData The extra data passed to the child deployers. - /// @return The initial share price of the Hyperdrive pool. - function _getInitialSharePrice( + /// @return The initial vault share price of the Hyperdrive pool. + function _getInitialVaultSharePrice( bytes memory _extraData ) internal view virtual returns (uint256); diff --git a/contracts/src/deployers/erc4626/ERC4626HyperdriveCoreDeployer.sol b/contracts/src/deployers/erc4626/ERC4626HyperdriveCoreDeployer.sol index 09b2ff15b..f88603342 100644 --- a/contracts/src/deployers/erc4626/ERC4626HyperdriveCoreDeployer.sol +++ b/contracts/src/deployers/erc4626/ERC4626HyperdriveCoreDeployer.sol @@ -30,7 +30,7 @@ contract ERC4626HyperdriveCoreDeployer is IHyperdriveCoreDeployer { address target3 ) external override returns (address) { // Deploy the ERC4626Hyperdrive instance. - address pool = abi.decode(_extraData, (address)); + address vault = abi.decode(_extraData, (address)); return ( address( new ERC4626Hyperdrive( @@ -39,7 +39,7 @@ contract ERC4626HyperdriveCoreDeployer is IHyperdriveCoreDeployer { target1, target2, target3, - IERC4626(pool) + IERC4626(vault) ) ) ); diff --git a/contracts/src/deployers/erc4626/ERC4626HyperdriveDeployerCoordinator.sol b/contracts/src/deployers/erc4626/ERC4626HyperdriveDeployerCoordinator.sol index 5bbbd912f..1ccfbaf70 100644 --- a/contracts/src/deployers/erc4626/ERC4626HyperdriveDeployerCoordinator.sol +++ b/contracts/src/deployers/erc4626/ERC4626HyperdriveDeployerCoordinator.sol @@ -34,14 +34,14 @@ contract ERC4626HyperdriveDeployerCoordinator is HyperdriveDeployerCoordinator { ) {} - /// @dev Gets the initial share price of the Hyperdrive pool. + /// @dev Gets the initial vault share price of the Hyperdrive pool. /// @param _extraData The extra data passed to the child deployers. - /// @return The initial share price of the Hyperdrive pool. - function _getInitialSharePrice( + /// @return The initial vault share price of the Hyperdrive pool. + function _getInitialVaultSharePrice( bytes memory _extraData ) internal view override returns (uint256) { // Return the vault's current share price. - IERC4626 pool = IERC4626(abi.decode(_extraData, (address))); - return pool.convertToAssets(ONE); + IERC4626 vault = IERC4626(abi.decode(_extraData, (address))); + return vault.convertToAssets(ONE); } } diff --git a/contracts/src/deployers/erc4626/ERC4626Target0Deployer.sol b/contracts/src/deployers/erc4626/ERC4626Target0Deployer.sol index 879010357..ea69591ae 100644 --- a/contracts/src/deployers/erc4626/ERC4626Target0Deployer.sol +++ b/contracts/src/deployers/erc4626/ERC4626Target0Deployer.sol @@ -22,7 +22,7 @@ contract ERC4626Target0Deployer is IHyperdriveTargetDeployer { bytes memory _extraData ) external override returns (address) { // Deploy the ERC4626Target0 instance. - IERC4626 pool = IERC4626(abi.decode(_extraData, (address))); - return address(new ERC4626Target0(_config, pool)); + IERC4626 vault = IERC4626(abi.decode(_extraData, (address))); + return address(new ERC4626Target0(_config, vault)); } } diff --git a/contracts/src/deployers/erc4626/ERC4626Target1Deployer.sol b/contracts/src/deployers/erc4626/ERC4626Target1Deployer.sol index a05c5a9bb..98404d0ac 100644 --- a/contracts/src/deployers/erc4626/ERC4626Target1Deployer.sol +++ b/contracts/src/deployers/erc4626/ERC4626Target1Deployer.sol @@ -22,7 +22,7 @@ contract ERC4626Target1Deployer is IHyperdriveTargetDeployer { bytes memory _extraData ) external override returns (address) { // Deploy the ERC4626Target1 instance. - IERC4626 pool = IERC4626(abi.decode(_extraData, (address))); - return address(new ERC4626Target1(_config, pool)); + IERC4626 vault = IERC4626(abi.decode(_extraData, (address))); + return address(new ERC4626Target1(_config, vault)); } } diff --git a/contracts/src/deployers/erc4626/ERC4626Target2Deployer.sol b/contracts/src/deployers/erc4626/ERC4626Target2Deployer.sol index b3fb02aa4..807584d0e 100644 --- a/contracts/src/deployers/erc4626/ERC4626Target2Deployer.sol +++ b/contracts/src/deployers/erc4626/ERC4626Target2Deployer.sol @@ -22,7 +22,7 @@ contract ERC4626Target2Deployer is IHyperdriveTargetDeployer { bytes memory _extraData ) external override returns (address) { // Deploy the ERC4626Target2 instance. - IERC4626 pool = IERC4626(abi.decode(_extraData, (address))); - return address(new ERC4626Target2(_config, pool)); + IERC4626 vault = IERC4626(abi.decode(_extraData, (address))); + return address(new ERC4626Target2(_config, vault)); } } diff --git a/contracts/src/deployers/erc4626/ERC4626Target3Deployer.sol b/contracts/src/deployers/erc4626/ERC4626Target3Deployer.sol index eee744983..000d3abf7 100644 --- a/contracts/src/deployers/erc4626/ERC4626Target3Deployer.sol +++ b/contracts/src/deployers/erc4626/ERC4626Target3Deployer.sol @@ -22,7 +22,7 @@ contract ERC4626Target3Deployer is IHyperdriveTargetDeployer { bytes memory _extraData ) external override returns (address) { // Deploy the ERC4626Target3 instance. - IERC4626 pool = IERC4626(abi.decode(_extraData, (address))); - return address(new ERC4626Target3(_config, pool)); + IERC4626 vault = IERC4626(abi.decode(_extraData, (address))); + return address(new ERC4626Target3(_config, vault)); } } diff --git a/contracts/src/deployers/steth/StETHHyperdriveDeployerCoordinator.sol b/contracts/src/deployers/steth/StETHHyperdriveDeployerCoordinator.sol index 2b7b27380..412e03ae6 100644 --- a/contracts/src/deployers/steth/StETHHyperdriveDeployerCoordinator.sol +++ b/contracts/src/deployers/steth/StETHHyperdriveDeployerCoordinator.sol @@ -43,12 +43,12 @@ contract StETHHyperdriveDeployerCoordinator is HyperdriveDeployerCoordinator { lido = _lido; } - /// @dev Gets the initial share price of the Hyperdrive pool. - /// @return The initial share price of the Hyperdrive pool. - function _getInitialSharePrice( + /// @dev Gets the initial vault share price of the Hyperdrive pool. + /// @return The initial vault share price of the Hyperdrive pool. + function _getInitialVaultSharePrice( bytes memory // unused extra data ) internal view override returns (uint256) { - // Return the stETH's current share price. + // Return stETH's current vault share price. return lido.getPooledEthByShares(ONE); } } diff --git a/contracts/src/external/HyperdriveTarget0.sol b/contracts/src/external/HyperdriveTarget0.sol index d39b25d70..187fa8338 100644 --- a/contracts/src/external/HyperdriveTarget0.sol +++ b/contracts/src/external/HyperdriveTarget0.sol @@ -244,7 +244,7 @@ abstract contract HyperdriveTarget0 is baseToken: _baseToken, linkerFactory: _linkerFactory, linkerCodeHash: _linkerCodeHash, - initialSharePrice: _initialSharePrice, + initialVaultSharePrice: _initialVaultSharePrice, minimumShareReserves: _minimumShareReserves, minimumTransactionAmount: _minimumTransactionAmount, positionDuration: _positionDuration, @@ -267,14 +267,14 @@ abstract contract HyperdriveTarget0 is /// important to evaluate potential trades. /// @return The PoolInfo struct. function getPoolInfo() external view returns (IHyperdrive.PoolInfo memory) { - uint256 sharePrice = _pricePerShare(); + uint256 vaultSharePrice = _pricePerVaultShare(); uint256 lpTotalSupply = _totalSupply[AssetId._LP_ASSET_ID] + _totalSupply[AssetId._WITHDRAWAL_SHARE_ASSET_ID] - _withdrawPool.readyToWithdraw; - uint256 presentValue = sharePrice > 0 + uint256 presentValue = vaultSharePrice > 0 ? LPMath - .calculatePresentValue(_getPresentValueParams(sharePrice)) - .mulDown(sharePrice) + .calculatePresentValue(_getPresentValueParams(vaultSharePrice)) + .mulDown(vaultSharePrice) : 0; IHyperdrive.PoolInfo memory poolInfo = IHyperdrive.PoolInfo({ shareReserves: _marketState.shareReserves, @@ -282,7 +282,7 @@ abstract contract HyperdriveTarget0 is zombieBaseProceeds: _marketState.zombieBaseProceeds, zombieShareReserves: _marketState.zombieShareReserves, bondReserves: _marketState.bondReserves, - sharePrice: sharePrice, + vaultSharePrice: vaultSharePrice, longsOutstanding: _marketState.longsOutstanding, longAverageMaturityTime: _marketState.longAverageMaturityTime, shortsOutstanding: _marketState.shortsOutstanding, diff --git a/contracts/src/external/HyperdriveTarget2.sol b/contracts/src/external/HyperdriveTarget2.sol index 2bbb7542f..5c45fbf96 100644 --- a/contracts/src/external/HyperdriveTarget2.sol +++ b/contracts/src/external/HyperdriveTarget2.sol @@ -35,7 +35,7 @@ abstract contract HyperdriveTarget2 is /// @notice Opens a long position. /// @param _baseAmount The amount of base to use when trading. /// @param _minOutput The minium number of bonds to receive. - /// @param _minSharePrice The minium share price at which to open the long. + /// @param _minVaultSharePrice The minium share price at which to open the long. /// This allows traders to protect themselves from opening a long in /// a checkpoint where negative interest has accrued. /// @param _options The options that configure how the trade is settled. @@ -44,10 +44,11 @@ abstract contract HyperdriveTarget2 is function openLong( uint256 _baseAmount, uint256 _minOutput, - uint256 _minSharePrice, + uint256 _minVaultSharePrice, IHyperdrive.Options calldata _options ) external payable returns (uint256 maturityTime, uint256 bondProceeds) { - return _openLong(_baseAmount, _minOutput, _minSharePrice, _options); + return + _openLong(_baseAmount, _minOutput, _minVaultSharePrice, _options); } /// Shorts /// @@ -55,7 +56,7 @@ abstract contract HyperdriveTarget2 is /// @notice Opens a short position. /// @param _bondAmount The amount of bonds to short. /// @param _maxDeposit The most the user expects to deposit for this trade - /// @param _minSharePrice The minium share price at which to open the long. + /// @param _minVaultSharePrice The minium share price at which to open the long. /// This allows traders to protect themselves from opening a long in /// a checkpoint where negative interest has accrued. /// @param _options The options that configure how the trade is settled. @@ -64,9 +65,10 @@ abstract contract HyperdriveTarget2 is function openShort( uint256 _bondAmount, uint256 _maxDeposit, - uint256 _minSharePrice, + uint256 _minVaultSharePrice, IHyperdrive.Options calldata _options ) external payable returns (uint256 maturityTime, uint256 traderDeposit) { - return _openShort(_bondAmount, _maxDeposit, _minSharePrice, _options); + return + _openShort(_bondAmount, _maxDeposit, _minVaultSharePrice, _options); } } diff --git a/contracts/src/instances/erc4626/ERC4626Base.sol b/contracts/src/instances/erc4626/ERC4626Base.sol index 82688a772..51c0952cc 100644 --- a/contracts/src/instances/erc4626/ERC4626Base.sol +++ b/contracts/src/instances/erc4626/ERC4626Base.sol @@ -19,14 +19,14 @@ abstract contract ERC4626Base is HyperdriveBase { using FixedPointMath for uint256; using SafeTransferLib for ERC20; - /// @dev The yield source contract for this hyperdrive. - IERC4626 internal immutable _pool; + /// @dev The ERC4626 vault that this pool uses as a yield source. + IERC4626 internal immutable _vault; /// @notice Instantiates the ERC4626 Hyperdrive base contract. - /// @param __pool The ERC4626 compatible yield source. - constructor(IERC4626 __pool) { + /// @param __vault The ERC4626 compatible vault. + constructor(IERC4626 __vault) { // Initialize the pool immutable. - _pool = __pool; + _vault = __vault; } /// Yield Source /// @@ -40,11 +40,15 @@ abstract contract ERC4626Base is HyperdriveBase { /// used in this implementation is "asBase" which determines if /// the deposit is settled in base or vault shares. /// @return sharesMinted The shares this deposit creates. - /// @return sharePrice The share price at time of deposit. + /// @return vaultSharePrice The vault share price at time of deposit. function _deposit( uint256 _amount, IHyperdrive.Options calldata _options - ) internal override returns (uint256 sharesMinted, uint256 sharePrice) { + ) + internal + override + returns (uint256 sharesMinted, uint256 vaultSharePrice) + { if (_options.asBase) { // Take custody of the deposit in base. ERC20(address(_baseToken)).safeTransferFrom( @@ -54,8 +58,8 @@ abstract contract ERC4626Base is HyperdriveBase { ); // Deposit the base into the yield source. - ERC20(address(_baseToken)).safeApprove(address(_pool), _amount); - sharesMinted = _pool.deposit(_amount, address(this)); + ERC20(address(_baseToken)).safeApprove(address(_vault), _amount); + sharesMinted = _vault.deposit(_amount, address(this)); } else { // WARN: This logic doesn't account for slippage in the conversion // from base to shares. If deposits to the yield source incur @@ -63,13 +67,13 @@ abstract contract ERC4626Base is HyperdriveBase { sharesMinted = _amount; // Take custody of the deposit in vault shares. - ERC20(address(_pool)).safeTransferFrom( + ERC20(address(_vault)).safeTransferFrom( msg.sender, address(this), sharesMinted ); } - sharePrice = _pricePerShare(); + vaultSharePrice = _pricePerVaultShare(); } /// @notice Processes a trader's withdrawal in either base or vault shares. @@ -93,7 +97,7 @@ abstract contract ERC4626Base is HyperdriveBase { // amount by converting the shares to base and then back to shares // using the vault's share conversion logic. uint256 baseAmount = _shares.mulDown(_sharePrice); - _shares = _pool.convertToShares(baseAmount); + _shares = _vault.convertToShares(baseAmount); // If we're withdrawing zero shares, short circuit and return 0. if (_shares == 0) { @@ -105,7 +109,7 @@ abstract contract ERC4626Base is HyperdriveBase { if (_options.asBase) { // Redeem from the yield source and transfer the // resulting base to the destination address. - amountWithdrawn = _pool.redeem( + amountWithdrawn = _vault.redeem( _shares, _options.destination, address(this) @@ -115,16 +119,16 @@ abstract contract ERC4626Base is HyperdriveBase { // shares to the destination. else { // Transfer vault shares to the destination. - ERC20(address(_pool)).safeTransfer(_options.destination, _shares); + ERC20(address(_vault)).safeTransfer(_options.destination, _shares); amountWithdrawn = _shares; } } - /// @notice Loads the share price from the yield source. - /// @return The current share price. + /// @notice Loads the vault share price from the yield source. + /// @return The current vault share price. /// @dev must remain consistent with the impl inside of the DataProvider - function _pricePerShare() internal view override returns (uint256) { - return _pool.convertToAssets(ONE); + function _pricePerVaultShare() internal view override returns (uint256) { + return _vault.convertToAssets(ONE); } /// @dev Ensure that ether wasn't sent because ERC4626 vaults don't support diff --git a/contracts/src/instances/erc4626/ERC4626Hyperdrive.sol b/contracts/src/instances/erc4626/ERC4626Hyperdrive.sol index d0605708e..e9c0ae782 100644 --- a/contracts/src/instances/erc4626/ERC4626Hyperdrive.sol +++ b/contracts/src/instances/erc4626/ERC4626Hyperdrive.sol @@ -27,39 +27,39 @@ contract ERC4626Hyperdrive is Hyperdrive, ERC4626Base { /// @param _target1 The target1 address. /// @param _target2 The target2 address. /// @param _target3 The target3 address. - /// @param __pool The ERC4626 compatible yield source. + /// @param __vault The ERC4626 compatible yield source. constructor( IHyperdrive.PoolConfig memory _config, address _target0, address _target1, address _target2, address _target3, - IERC4626 __pool + IERC4626 __vault ) Hyperdrive(_config, _target0, _target1, _target2, _target3) - ERC4626Base(__pool) + ERC4626Base(__vault) { - // Ensure that the initial share price is properly configured. + // Ensure that the initial vault share price is properly configured. // // WARN: ERC4626 implementations should be checked that if they use an // asset with decimals less than 18 that the preview deposit is scale // invariant. EG - because this line uses a very large query to load - // price for USDC if the price per share changes based on size of + // price for USDC if the price per vault share changes based on size of // deposit then this line will read an incorrect and possibly dangerous // price. - if (_config.initialSharePrice != _pricePerShare()) { + if (_config.initialVaultSharePrice != _pricePerVaultShare()) { revert IHyperdrive.InvalidInitialSharePrice(); } // Ensure that the base token is the same as the vault's underlying // asset. - if (address(_config.baseToken) != IERC4626(_pool).asset()) { + if (address(_config.baseToken) != IERC4626(_vault).asset()) { revert IHyperdrive.InvalidBaseToken(); } // Approve the base token with 1 wei. This ensures that all of the // subsequent approvals will be writing to a dirty storage slot. - ERC20(address(_config.baseToken)).safeApprove(address(_pool), 1); + ERC20(address(_config.baseToken)).safeApprove(address(_vault), 1); } /// @notice Some yield sources [eg Morpho] pay rewards directly to this diff --git a/contracts/src/instances/erc4626/ERC4626Target0.sol b/contracts/src/instances/erc4626/ERC4626Target0.sol index edabf8d00..5060e238e 100644 --- a/contracts/src/instances/erc4626/ERC4626Target0.sol +++ b/contracts/src/instances/erc4626/ERC4626Target0.sol @@ -22,11 +22,11 @@ contract ERC4626Target0 is HyperdriveTarget0, ERC4626Base { /// @notice Initializes the target0 contract. /// @param _config The configuration of the Hyperdrive pool. - /// @param __pool The ERC4626 pool. + /// @param __vault The ERC4626 compatible vault. constructor( IHyperdrive.PoolConfig memory _config, - IERC4626 __pool - ) HyperdriveTarget0(_config) ERC4626Base(__pool) {} + IERC4626 __vault + ) HyperdriveTarget0(_config) ERC4626Base(__vault) {} /// Extras /// @@ -43,27 +43,27 @@ contract ERC4626Target0 is HyperdriveTarget0, ERC4626Base { revert IHyperdrive.Unauthorized(); } - // Ensure that thet target isn't the base or vault token + // Ensure that the target isn't the base or vault token. if ( address(_target) == address(_baseToken) || - address(_target) == address(_pool) + address(_target) == address(_vault) ) { revert IHyperdrive.UnsupportedToken(); } - // Get Hyperdrive's balance of the base and pool tokens prior to + // Get Hyperdrive's balance of the base and vault tokens prior to // sweeping. uint256 baseBalance = _baseToken.balanceOf(address(this)); - uint256 poolBalance = _pool.balanceOf(address(this)); + uint256 vaultBalance = _vault.balanceOf(address(this)); // Transfer the entire balance of the sweep target to the fee collector. uint256 balance = _target.balanceOf(address(this)); ERC20(address(_target)).safeTransfer(_feeCollector, balance); - // Ensure that the base and pool balances haven't changed. + // Ensure that the base and vault balances haven't changed. if ( _baseToken.balanceOf(address(this)) != baseBalance || - _pool.balanceOf(address(this)) != poolBalance + _vault.balanceOf(address(this)) != vaultBalance ) { revert IHyperdrive.SweepFailed(); } @@ -71,9 +71,9 @@ contract ERC4626Target0 is HyperdriveTarget0, ERC4626Base { /// Getters /// - /// @notice Gets the 4626 pool. - /// @return The 4626 pool. - function pool() external view returns (IERC4626) { - _revert(abi.encode(_pool)); + /// @notice Gets the ERC4626 compatible vault. + /// @return The ERC4626 compatible vault. + function vault() external view returns (IERC4626) { + _revert(abi.encode(_vault)); } } diff --git a/contracts/src/instances/erc4626/ERC4626Target1.sol b/contracts/src/instances/erc4626/ERC4626Target1.sol index 3a6cc704c..a24181757 100644 --- a/contracts/src/instances/erc4626/ERC4626Target1.sol +++ b/contracts/src/instances/erc4626/ERC4626Target1.sol @@ -15,9 +15,9 @@ import { ERC4626Base } from "./ERC4626Base.sol"; contract ERC4626Target1 is HyperdriveTarget1, ERC4626Base { /// @notice Initializes the target1 contract. /// @param _config The configuration of the Hyperdrive pool. - /// @param __pool The ERC4626 pool. + /// @param __vault The ERC4626 compatible vault. constructor( IHyperdrive.PoolConfig memory _config, - IERC4626 __pool - ) HyperdriveTarget1(_config) ERC4626Base(__pool) {} + IERC4626 __vault + ) HyperdriveTarget1(_config) ERC4626Base(__vault) {} } diff --git a/contracts/src/instances/erc4626/ERC4626Target2.sol b/contracts/src/instances/erc4626/ERC4626Target2.sol index e9fadf9dd..6f2ad54a2 100644 --- a/contracts/src/instances/erc4626/ERC4626Target2.sol +++ b/contracts/src/instances/erc4626/ERC4626Target2.sol @@ -17,9 +17,9 @@ import { ERC4626Base } from "./ERC4626Base.sol"; contract ERC4626Target2 is HyperdriveTarget2, ERC4626Base { /// @notice Initializes the target2 contract. /// @param _config The configuration of the Hyperdrive pool. - /// @param __pool The ERC4626 pool. + /// @param __vault The ERC4626 compatible vault. constructor( IHyperdrive.PoolConfig memory _config, - IERC4626 __pool - ) HyperdriveTarget2(_config) ERC4626Base(__pool) {} + IERC4626 __vault + ) HyperdriveTarget2(_config) ERC4626Base(__vault) {} } diff --git a/contracts/src/instances/erc4626/ERC4626Target3.sol b/contracts/src/instances/erc4626/ERC4626Target3.sol index e018866c6..1f4f8b81b 100644 --- a/contracts/src/instances/erc4626/ERC4626Target3.sol +++ b/contracts/src/instances/erc4626/ERC4626Target3.sol @@ -17,9 +17,9 @@ import { ERC4626Base } from "./ERC4626Base.sol"; contract ERC4626Target3 is HyperdriveTarget3, ERC4626Base { /// @notice Initializes the target3 contract. /// @param _config The configuration of the Hyperdrive pool. - /// @param __pool The ERC4626 pool. + /// @param __vault The ERC4626 compatible vault. constructor( IHyperdrive.PoolConfig memory _config, - IERC4626 __pool - ) HyperdriveTarget3(_config) ERC4626Base(__pool) {} + IERC4626 __vault + ) HyperdriveTarget3(_config) ERC4626Base(__vault) {} } diff --git a/contracts/src/instances/steth/StETHBase.sol b/contracts/src/instances/steth/StETHBase.sol index 6a3893cdc..296a83f61 100644 --- a/contracts/src/instances/steth/StETHBase.sol +++ b/contracts/src/instances/steth/StETHBase.sol @@ -45,11 +45,11 @@ abstract contract StETHBase is HyperdriveBase { /// used in this implementation is "asBase" which determines if /// the deposit is settled in ETH or stETH shares. /// @return shares The amount of shares that represents the amount deposited. - /// @return sharePrice The current share price. + /// @return vaultSharePrice The current vault share price. function _deposit( uint256 _amount, IHyperdrive.Options calldata _options - ) internal override returns (uint256 shares, uint256 sharePrice) { + ) internal override returns (uint256 shares, uint256 vaultSharePrice) { uint256 refund; if (_options.asBase) { // Ensure that sufficient ether was provided. @@ -67,8 +67,8 @@ abstract contract StETHBase is HyperdriveBase { // stETH instead of WETH. shares = _lido.submit{ value: _amount }(_feeCollector); - // Calculate the share price. - sharePrice = _pricePerShare(); + // Calculate the vault share price. + vaultSharePrice = _pricePerVaultShare(); } else { // Refund any ether that was sent to the contract. refund = msg.value; @@ -76,9 +76,9 @@ abstract contract StETHBase is HyperdriveBase { // Transfer stETH shares into the contract. _lido.transferSharesFrom(msg.sender, address(this), _amount); - // Calculate the share price. + // Calculate the vault share price. shares = _amount; - sharePrice = _pricePerShare(); + vaultSharePrice = _pricePerVaultShare(); } // Return excess ether that was sent to the contract. @@ -89,7 +89,7 @@ abstract contract StETHBase is HyperdriveBase { } } - return (shares, sharePrice); + return (shares, vaultSharePrice); } /// @notice Processes a trader's withdrawal. This yield source only supports @@ -132,10 +132,15 @@ abstract contract StETHBase is HyperdriveBase { return _shares; } - /// @dev Returns the current share price. We simply use Lido's share price. - /// @return price The current share price. - /// @dev must remain consistent with the impl inside of the DataProvider - function _pricePerShare() internal view override returns (uint256 price) { + /// @dev Returns the current vault share price. We simply use Lido's + /// internal share price. + /// @return price The current vault share price. + function _pricePerVaultShare() + internal + view + override + returns (uint256 price) + { return _lido.getPooledEthByShares(ONE); } diff --git a/contracts/src/instances/steth/StETHHyperdrive.sol b/contracts/src/instances/steth/StETHHyperdrive.sol index 386efae7d..d8a9a7b1a 100644 --- a/contracts/src/instances/steth/StETHHyperdrive.sol +++ b/contracts/src/instances/steth/StETHHyperdrive.sol @@ -39,8 +39,8 @@ contract StETHHyperdrive is Hyperdrive, StETHBase { revert IHyperdrive.InvalidBaseToken(); } - // Ensure that the initial share price is properly configured. - if (_config.initialSharePrice != _pricePerShare()) { + // Ensure that the initial vault share price is properly configured. + if (_config.initialVaultSharePrice != _pricePerVaultShare()) { revert IHyperdrive.InvalidInitialSharePrice(); } } diff --git a/contracts/src/interfaces/IERC4626HyperdriveRead.sol b/contracts/src/interfaces/IERC4626HyperdriveRead.sol index 083fddbf8..d9f3781e3 100644 --- a/contracts/src/interfaces/IERC4626HyperdriveRead.sol +++ b/contracts/src/interfaces/IERC4626HyperdriveRead.sol @@ -5,5 +5,5 @@ import { IERC4626 } from "./IERC4626.sol"; import { IHyperdriveRead } from "./IHyperdriveRead.sol"; interface IERC4626HyperdriveRead is IHyperdriveRead { - function pool() external view returns (IERC4626); + function vault() external view returns (IERC4626); } diff --git a/contracts/src/interfaces/IHyperdrive.sol b/contracts/src/interfaces/IHyperdrive.sol index 548f352de..d116c02ec 100644 --- a/contracts/src/interfaces/IHyperdrive.sol +++ b/contracts/src/interfaces/IHyperdrive.sol @@ -13,7 +13,7 @@ interface IHyperdrive is IHyperdriveRead, IHyperdriveCore, IMultiToken { address indexed provider, uint256 lpAmount, uint256 baseAmount, - uint256 sharePrice, + uint256 vaultSharePrice, uint256 apr ); @@ -21,7 +21,7 @@ interface IHyperdrive is IHyperdriveRead, IHyperdriveCore, IMultiToken { address indexed provider, uint256 lpAmount, uint256 baseAmount, - uint256 sharePrice, + uint256 vaultSharePrice, uint256 lpSharePrice ); @@ -29,7 +29,7 @@ interface IHyperdrive is IHyperdriveRead, IHyperdriveCore, IMultiToken { address indexed provider, uint256 lpAmount, uint256 baseAmount, - uint256 sharePrice, + uint256 vaultSharePrice, uint256 withdrawalShareAmount, uint256 lpSharePrice ); @@ -38,7 +38,7 @@ interface IHyperdrive is IHyperdriveRead, IHyperdriveCore, IMultiToken { address indexed provider, uint256 withdrawalShareAmount, uint256 baseAmount, - uint256 sharePrice + uint256 vaultSharePrice ); event OpenLong( @@ -46,7 +46,7 @@ interface IHyperdrive is IHyperdriveRead, IHyperdriveCore, IMultiToken { uint256 indexed assetId, uint256 maturityTime, uint256 baseAmount, - uint256 sharePrice, + uint256 vaultSharePrice, uint256 bondAmount ); @@ -55,7 +55,7 @@ interface IHyperdrive is IHyperdriveRead, IHyperdriveCore, IMultiToken { uint256 indexed assetId, uint256 maturityTime, uint256 baseAmount, - uint256 sharePrice, + uint256 vaultSharePrice, uint256 bondAmount ); @@ -64,7 +64,7 @@ interface IHyperdrive is IHyperdriveRead, IHyperdriveCore, IMultiToken { uint256 indexed assetId, uint256 maturityTime, uint256 baseAmount, - uint256 sharePrice, + uint256 vaultSharePrice, uint256 bondAmount ); @@ -73,13 +73,13 @@ interface IHyperdrive is IHyperdriveRead, IHyperdriveCore, IMultiToken { uint256 indexed assetId, uint256 maturityTime, uint256 baseAmount, - uint256 sharePrice, + uint256 vaultSharePrice, uint256 bondAmount ); event CreateCheckpoint( uint256 indexed checkpointTime, - uint256 sharePrice, + uint256 vaultSharePrice, uint256 maturedShorts, uint256 maturedLongs, uint256 lpSharePrice @@ -88,7 +88,7 @@ interface IHyperdrive is IHyperdriveRead, IHyperdriveCore, IMultiToken { event CollectGovernanceFee( address indexed collector, uint256 baseFees, - uint256 sharePrice + uint256 vaultSharePrice ); /// Structs /// @@ -122,11 +122,11 @@ interface IHyperdrive is IHyperdriveRead, IHyperdriveCore, IMultiToken { } struct Checkpoint { - /// @dev The share price of the first transaction in the checkpoint. - /// This is used to track the amount of interest accrued by shorts - /// as well as the share price at closing of matured longs and - /// shorts. - uint128 sharePrice; + /// @dev The vault share price during the first transaction in the + /// checkpoint. This is used to track the amount of interest + /// accrued by shorts as well as the vault share price at closing + // of matured longs and shorts. + uint128 vaultSharePrice; } struct WithdrawPool { @@ -182,8 +182,8 @@ interface IHyperdrive is IHyperdriveRead, IHyperdriveCore, IMultiToken { /// @dev The hash of the ERC20 linker's code. This is used to derive the /// create2 addresses of the ERC20 linkers used by this instance. bytes32 linkerCodeHash; - /// @dev The initial share price. - uint256 initialSharePrice; + /// @dev The initial vault share price. + uint256 initialVaultSharePrice; /// @dev The minimum share reserves. uint256 minimumShareReserves; /// @dev The minimum amount of tokens that a position can be opened or @@ -218,8 +218,8 @@ interface IHyperdrive is IHyperdriveRead, IHyperdriveCore, IMultiToken { uint256 bondReserves; /// @dev The total supply of LP shares. uint256 lpTotalSupply; - /// @dev The current share price. - uint256 sharePrice; + /// @dev The current vault share price. + uint256 vaultSharePrice; /// @dev An amount of bonds representing outstanding unmatured longs. uint256 longsOutstanding; /// @dev The average maturity time of the outstanding longs. diff --git a/contracts/src/interfaces/IHyperdriveCore.sol b/contracts/src/interfaces/IHyperdriveCore.sol index 68dd37dd8..b00a1b277 100644 --- a/contracts/src/interfaces/IHyperdriveCore.sol +++ b/contracts/src/interfaces/IHyperdriveCore.sol @@ -10,7 +10,7 @@ interface IHyperdriveCore is IMultiTokenCore { function openLong( uint256 _baseAmount, uint256 _minOutput, - uint256 _minSharePrice, + uint256 _minVaultSharePrice, IHyperdrive.Options calldata _options ) external payable returns (uint256 maturityTime, uint256 bondProceeds); @@ -26,7 +26,7 @@ interface IHyperdriveCore is IMultiTokenCore { function openShort( uint256 _bondAmount, uint256 _maxDeposit, - uint256 _minSharePrice, + uint256 _minVaultSharePrice, IHyperdrive.Options calldata _options ) external payable returns (uint256 maturityTime, uint256 traderDeposit); diff --git a/contracts/src/internal/HyperdriveAdmin.sol b/contracts/src/internal/HyperdriveAdmin.sol index c9bebf465..e7c98dfcc 100644 --- a/contracts/src/internal/HyperdriveAdmin.sol +++ b/contracts/src/internal/HyperdriveAdmin.sol @@ -39,12 +39,13 @@ abstract contract HyperdriveAdmin is HyperdriveBase { } // Withdraw the accrued governance fees to the fee collector. + uint256 vaultSharePrice = _pricePerVaultShare(); uint256 governanceFeesAccrued = _governanceFeesAccrued; delete _governanceFeesAccrued; - proceeds = _withdraw(governanceFeesAccrued, _pricePerShare(), _options); + proceeds = _withdraw(governanceFeesAccrued, vaultSharePrice, _options); emit CollectGovernanceFee( _feeCollector, - _convertToBaseFromOption(proceeds, _pricePerShare(), _options) + _convertToBaseFromOption(proceeds, vaultSharePrice, _options) ); } diff --git a/contracts/src/internal/HyperdriveBase.sol b/contracts/src/internal/HyperdriveBase.sol index ba9e35175..13b40d45d 100644 --- a/contracts/src/internal/HyperdriveBase.sol +++ b/contracts/src/internal/HyperdriveBase.sol @@ -27,7 +27,7 @@ abstract contract HyperdriveBase is HyperdriveStorage { address indexed provider, uint256 lpAmount, uint256 baseAmount, - uint256 sharePrice, + uint256 vaultSharePrice, uint256 apr ); @@ -35,7 +35,7 @@ abstract contract HyperdriveBase is HyperdriveStorage { address indexed provider, uint256 lpAmount, uint256 baseAmount, - uint256 sharePrice, + uint256 vaultSharePrice, uint256 lpSharePrice ); @@ -43,7 +43,7 @@ abstract contract HyperdriveBase is HyperdriveStorage { address indexed provider, uint256 lpAmount, uint256 baseAmount, - uint256 sharePrice, + uint256 vaultSharePrice, uint256 withdrawalShareAmount, uint256 lpSharePrice ); @@ -52,7 +52,7 @@ abstract contract HyperdriveBase is HyperdriveStorage { address indexed provider, uint256 withdrawalShareAmount, uint256 baseAmount, - uint256 sharePrice + uint256 vaultSharePrice ); event OpenLong( @@ -60,7 +60,7 @@ abstract contract HyperdriveBase is HyperdriveStorage { uint256 indexed assetId, uint256 maturityTime, uint256 baseAmount, - uint256 sharePrice, + uint256 vaultSharePrice, uint256 bondAmount ); @@ -69,7 +69,7 @@ abstract contract HyperdriveBase is HyperdriveStorage { uint256 indexed assetId, uint256 maturityTime, uint256 baseAmount, - uint256 sharePrice, + uint256 vaultSharePrice, uint256 bondAmount ); @@ -78,7 +78,7 @@ abstract contract HyperdriveBase is HyperdriveStorage { uint256 indexed assetId, uint256 maturityTime, uint256 baseAmount, - uint256 sharePrice, + uint256 vaultSharePrice, uint256 bondAmount ); @@ -87,13 +87,13 @@ abstract contract HyperdriveBase is HyperdriveStorage { uint256 indexed assetId, uint256 maturityTime, uint256 baseAmount, - uint256 sharePrice, + uint256 vaultSharePrice, uint256 bondAmount ); event CreateCheckpoint( uint256 indexed checkpointTime, - uint256 sharePrice, + uint256 vaultSharePrice, uint256 maturedShorts, uint256 maturedLongs, uint256 lpSharePrice @@ -132,11 +132,11 @@ abstract contract HyperdriveBase is HyperdriveStorage { /// specified here. Aside from those options, yield sources can /// choose to implement additional options. /// @return sharesMinted The shares created by this deposit. - /// @return sharePrice The share price. + /// @return vaultSharePrice The vault share price. function _deposit( uint256 _amount, IHyperdrive.Options calldata _options - ) internal virtual returns (uint256 sharesMinted, uint256 sharePrice); + ) internal virtual returns (uint256 sharesMinted, uint256 vaultSharePrice); /// @dev Withdraws shares from the yield source and sends the base /// released to the destination. @@ -154,12 +154,12 @@ abstract contract HyperdriveBase is HyperdriveStorage { ) internal virtual returns (uint256 amountWithdrawn); /// @dev Loads the share price from the yield source. - /// @return sharePrice The current share price. - function _pricePerShare() + /// @return vaultSharePrice The current vault share price. + function _pricePerVaultShare() internal view virtual - returns (uint256 sharePrice); + returns (uint256 vaultSharePrice); /// Pause /// @@ -173,12 +173,13 @@ abstract contract HyperdriveBase is HyperdriveStorage { /// @dev Creates a new checkpoint if necessary. /// @param _checkpointTime The time of the checkpoint to create. - /// @param _sharePrice The current share price. - /// @return openSharePrice The open share price of the latest checkpoint. + /// @param _vaultSharePrice The current vault share price. + /// @return openVaultSharePrice The open vault share price of the latest + /// checkpoint. function _applyCheckpoint( uint256 _checkpointTime, - uint256 _sharePrice - ) internal virtual returns (uint256 openSharePrice); + uint256 _vaultSharePrice + ) internal virtual returns (uint256 openVaultSharePrice); /// Helpers /// @@ -262,15 +263,17 @@ abstract contract HyperdriveBase is HyperdriveStorage { } /// @dev Gets the distribute excess idle parameters from the current state. - /// @param _sharePrice The current share price. + /// @param _vaultSharePrice The current vault share price. /// @return params The distribute excess idle parameters. function _getDistributeExcessIdleParams( uint256 _idle, uint256 _withdrawalSharesTotalSupply, - uint256 _sharePrice + uint256 _vaultSharePrice ) internal view returns (LPMath.DistributeExcessIdleParams memory params) { LPMath.PresentValueParams - memory presentValueParams = _getPresentValueParams(_sharePrice); + memory presentValueParams = _getPresentValueParams( + _vaultSharePrice + ); uint256 startingPresentValue = LPMath.calculatePresentValue( presentValueParams ); @@ -298,17 +301,17 @@ abstract contract HyperdriveBase is HyperdriveStorage { } /// @dev Gets the present value parameters from the current state. - /// @param _sharePrice The current share price. + /// @param _vaultSharePrice The current vault share price. /// @return params The present value parameters. function _getPresentValueParams( - uint256 _sharePrice + uint256 _vaultSharePrice ) internal view returns (LPMath.PresentValueParams memory params) { params = LPMath.PresentValueParams({ shareReserves: _marketState.shareReserves, shareAdjustment: _marketState.shareAdjustment, bondReserves: _marketState.bondReserves, - sharePrice: _sharePrice, - initialSharePrice: _initialSharePrice, + vaultSharePrice: _vaultSharePrice, + initialVaultSharePrice: _initialVaultSharePrice, minimumShareReserves: _minimumShareReserves, timeStretch: _timeStretch, longsOutstanding: _marketState.longsOutstanding, @@ -340,7 +343,7 @@ abstract contract HyperdriveBase is HyperdriveStorage { uint256 endingSpotPrice = HyperdriveMath.calculateSpotPrice( _effectiveShareReserves() + _shareCurveDelta, _marketState.bondReserves - _bondCurveDelta, - _initialSharePrice, + _initialVaultSharePrice, _timeStretch ); return endingSpotPrice > _maxSpotPrice; @@ -348,14 +351,16 @@ abstract contract HyperdriveBase is HyperdriveStorage { /// @dev Check solvency by verifying that the share reserves are greater /// than the exposure plus the minimum share reserves. - /// @param _sharePrice The current share price. + /// @param _vaultSharePrice The current vault share price. /// @return True if the share reserves are greater than the exposure plus /// the minimum share reserves. - function _isSolvent(uint256 _sharePrice) internal view returns (bool) { + function _isSolvent(uint256 _vaultSharePrice) internal view returns (bool) { return - int256((uint256(_marketState.shareReserves).mulDown(_sharePrice))) - + int256( + (uint256(_marketState.shareReserves).mulDown(_vaultSharePrice)) + ) - int128(_marketState.longExposure) >= - int256(_minimumShareReserves.mulDown(_sharePrice)); + int256(_minimumShareReserves.mulDown(_vaultSharePrice)); } /// @dev Updates the global long exposure. @@ -379,23 +384,23 @@ abstract contract HyperdriveBase is HyperdriveStorage { /// to account for any negative interest that has accrued in the /// zombie reserves. /// @param _shareProceeds The share proceeds. - /// @param _sharePrice The share price. + /// @param _vaultSharePrice The current vault share price. /// @return The adjusted share proceeds. function _applyZombieClose( uint256 _shareProceeds, - uint256 _sharePrice + uint256 _vaultSharePrice ) internal returns (uint256) { // Collect any zombie interest that has accrued since the last // collection. ( uint256 zombieBaseProceeds, uint256 zombieBaseReserves - ) = _collectZombieInterest(_sharePrice); + ) = _collectZombieInterest(_vaultSharePrice); // If negative interest has accrued in the zombie reserves, we // discount the share proceeds in proportion to the amount of // negative interest that has accrued. - uint256 baseProceeds = _shareProceeds.mulDown(_sharePrice); + uint256 baseProceeds = _shareProceeds.mulDown(_vaultSharePrice); if (zombieBaseProceeds > zombieBaseReserves) { _shareProceeds = _shareProceeds.mulDivDown( zombieBaseReserves, @@ -423,19 +428,19 @@ abstract contract HyperdriveBase is HyperdriveStorage { /// @dev Collect the interest earned on unredeemed matured positions. This /// interest is split between the LPs and governance. - /// @param _sharePrice The current share price. + /// @param _vaultSharePrice The current vault share price. /// @return zombieBaseProceeds The base proceeds reserved for zombie /// positions. /// @return zombieBaseReserves The updated base reserves reserved for zombie /// positions. function _collectZombieInterest( - uint256 _sharePrice + uint256 _vaultSharePrice ) internal returns (uint256 zombieBaseProceeds, uint256 zombieBaseReserves) { // Get the zombie base proceeds and reserves. - zombieBaseReserves = _sharePrice.mulDown( + zombieBaseReserves = _vaultSharePrice.mulDown( _marketState.zombieShareReserves ); zombieBaseProceeds = _marketState.zombieBaseProceeds; @@ -449,13 +454,15 @@ abstract contract HyperdriveBase is HyperdriveStorage { // Remove the zombie interest from the zombie share reserves. _marketState.zombieShareReserves -= zombieInterest - .divUp(_sharePrice) + .divUp(_vaultSharePrice) .toUint128(); // Calculate and collect the governance fee. // The fee is calculated in terms of shares and paid to // governance. - uint256 zombieInterestShares = zombieInterest.divDown(_sharePrice); + uint256 zombieInterestShares = zombieInterest.divDown( + _vaultSharePrice + ); uint256 governanceZombieFeeCollected = zombieInterestShares.mulDown( _governanceZombieFee ); @@ -479,14 +486,14 @@ abstract contract HyperdriveBase is HyperdriveStorage { /// @dev Calculates the number of share reserves that are not reserved by /// open positions. - /// @param _sharePrice The current share price. + /// @param _vaultSharePrice The current vault share price. /// @return idleShares The amount of shares that are available for LPs to /// withdraw. function _calculateIdleShareReserves( - uint256 _sharePrice + uint256 _vaultSharePrice ) internal view returns (uint256 idleShares) { uint256 longExposure = uint256(_marketState.longExposure).divDown( - _sharePrice + _vaultSharePrice ); if (_marketState.shareReserves > longExposure + _minimumShareReserves) { idleShares = @@ -498,15 +505,15 @@ abstract contract HyperdriveBase is HyperdriveStorage { } /// @dev Calculates the LP share price. - /// @param _sharePrice The current vault share price. + /// @param _vaultSharePrice The current vault share price. /// @return lpSharePrice The LP share price in units of (base / lp shares). function _calculateLPSharePrice( - uint256 _sharePrice + uint256 _vaultSharePrice ) internal view returns (uint256 lpSharePrice) { - uint256 presentValue = _sharePrice > 0 + uint256 presentValue = _vaultSharePrice > 0 ? LPMath - .calculatePresentValue(_getPresentValueParams(_sharePrice)) - .mulDown(_sharePrice) + .calculatePresentValue(_getPresentValueParams(_vaultSharePrice)) + .mulDown(_vaultSharePrice) : 0; uint256 lpTotalSupply = _totalSupply[AssetId._LP_ASSET_ID] + _totalSupply[AssetId._WITHDRAWAL_SHARE_ASSET_ID] - @@ -521,15 +528,14 @@ abstract contract HyperdriveBase is HyperdriveStorage { /// @param _shareAmount The amount of shares exchanged for bonds. /// @param _spotPrice The price without slippage of bonds in terms of base /// (base/bonds). - /// @param _sharePrice The current price of shares in terms of base - /// (base/shares). + /// @param _vaultSharePrice The current vault share price (base/shares). /// @return curveFee The curve fee. The fee is in terms of bonds. /// @return governanceCurveFee The curve fee that goes to governance. The /// fee is in terms of bonds. function _calculateFeesGivenShares( uint256 _shareAmount, uint256 _spotPrice, - uint256 _sharePrice + uint256 _vaultSharePrice ) internal view returns (uint256 curveFee, uint256 governanceCurveFee) { // Fixed Rate (r) = (value at maturity - purchase price)/(purchase price) // = (1-p)/p @@ -552,7 +558,7 @@ abstract contract HyperdriveBase is HyperdriveStorage { // = bonds * phi_curve curveFee = (ONE.divDown(_spotPrice) - ONE) .mulDown(_curveFee) - .mulDown(_sharePrice) + .mulDown(_vaultSharePrice) .mulDown(_shareAmount); // We leave the governance fee in terms of bonds: @@ -563,10 +569,11 @@ abstract contract HyperdriveBase is HyperdriveStorage { /// @dev Calculates the fees that go to the LPs and governance. /// @param _bondAmount The amount of bonds being exchanged for shares. - /// @param _normalizedTimeRemaining The normalized amount of time until maturity. + /// @param _normalizedTimeRemaining The normalized amount of time until + /// maturity. /// @param _spotPrice The price without slippage of bonds in terms of base /// (base/bonds). - /// @param _sharePrice The current price of shares in terms of base (base/shares). + /// @param _vaultSharePrice The current vault share price (base/shares). /// @return curveFee The curve fee. The fee is in terms of shares. /// @return flatFee The flat fee. The fee is in terms of shares. /// @return governanceCurveFee The curve fee that goes to governance. The @@ -575,7 +582,7 @@ abstract contract HyperdriveBase is HyperdriveStorage { uint256 _bondAmount, uint256 _normalizedTimeRemaining, uint256 _spotPrice, - uint256 _sharePrice + uint256 _vaultSharePrice ) internal view @@ -601,7 +608,7 @@ abstract contract HyperdriveBase is HyperdriveStorage { curveFee = _curveFee .mulDown(ONE - _spotPrice) .mulDown(_bondAmount) - .mulDivDown(_normalizedTimeRemaining, _sharePrice); + .mulDivDown(_normalizedTimeRemaining, _vaultSharePrice); // Calculate the curve portion of the governance fee: // @@ -619,7 +626,7 @@ abstract contract HyperdriveBase is HyperdriveStorage { // = shares * (1 - t) * phi_flat uint256 flat = _bondAmount.mulDivDown( ONE - _normalizedTimeRemaining, - _sharePrice + _vaultSharePrice ); flatFee = flat.mulDown(_flatFee); @@ -637,35 +644,35 @@ abstract contract HyperdriveBase is HyperdriveStorage { /// @dev Converts input to base if necessary according to what is specified /// in options. /// @param _amount The amount to convert. - /// @param _sharePrice The current share price. + /// @param _vaultSharePrice The current vault share price. /// @param _options The options that configure the conversion. /// @return The converted amount. function _convertToBaseFromOption( uint256 _amount, - uint256 _sharePrice, + uint256 _vaultSharePrice, IHyperdrive.Options calldata _options ) internal pure returns (uint256) { if (_options.asBase) { return _amount; } else { - return _amount.mulDown(_sharePrice); + return _amount.mulDown(_vaultSharePrice); } } /// @dev Converts input to what is specified in the options from base. /// @param _amount The amount to convert. - /// @param _sharePrice The current share price. + /// @param _vaultSharePrice The current vault share price. /// @param _options The options that configure the conversion. /// @return The converted amount. function _convertToOptionFromBase( uint256 _amount, - uint256 _sharePrice, + uint256 _vaultSharePrice, IHyperdrive.Options calldata _options ) internal pure returns (uint256) { if (_options.asBase) { return _amount; } else { - return _amount.divDown(_sharePrice); + return _amount.divDown(_vaultSharePrice); } } } diff --git a/contracts/src/internal/HyperdriveCheckpoint.sol b/contracts/src/internal/HyperdriveCheckpoint.sol index e45a21035..5e9458327 100644 --- a/contracts/src/internal/HyperdriveCheckpoint.sol +++ b/contracts/src/internal/HyperdriveCheckpoint.sol @@ -29,7 +29,7 @@ abstract contract HyperdriveCheckpoint is /// @param _checkpointTime The time of the checkpoint to create. function _checkpoint(uint256 _checkpointTime) internal { // If the checkpoint has already been set, return early. - if (_checkpoints[_checkpointTime].sharePrice != 0) { + if (_checkpoints[_checkpointTime].vaultSharePrice != 0) { return; } @@ -45,22 +45,23 @@ abstract contract HyperdriveCheckpoint is } // If the checkpoint time is the latest checkpoint, we use the current - // share price. Otherwise, we use a linear search to find the closest - // share price and use that to perform the checkpoint. + // vault share price. Otherwise, we use a linear search to find the + // closest vault share price and use that to perform the checkpoint. if (_checkpointTime == latestCheckpoint) { - _applyCheckpoint(latestCheckpoint, _pricePerShare()); + _applyCheckpoint(latestCheckpoint, _pricePerVaultShare()); } else { for ( uint256 time = _checkpointTime; ; time += _checkpointDuration ) { - uint256 closestSharePrice = _checkpoints[time].sharePrice; + uint256 closestVaultSharePrice = _checkpoints[time] + .vaultSharePrice; if (time == latestCheckpoint) { - closestSharePrice = _pricePerShare(); + closestVaultSharePrice = _pricePerVaultShare(); } - if (closestSharePrice != 0) { - _applyCheckpoint(_checkpointTime, closestSharePrice); + if (closestVaultSharePrice != 0) { + _applyCheckpoint(_checkpointTime, closestVaultSharePrice); break; } } @@ -69,25 +70,28 @@ abstract contract HyperdriveCheckpoint is /// @dev Creates a new checkpoint if necessary. /// @param _checkpointTime The time of the checkpoint to create. - /// @param _sharePrice The current share price. - /// @return The opening share price of the latest checkpoint. + /// @param _vaultSharePrice The current vault share price. + /// @return The opening vault share price of the latest checkpoint. function _applyCheckpoint( uint256 _checkpointTime, - uint256 _sharePrice + uint256 _vaultSharePrice ) internal override returns (uint256) { // Return early if the checkpoint has already been updated. IHyperdrive.Checkpoint storage checkpoint_ = _checkpoints[ _checkpointTime ]; - if (checkpoint_.sharePrice != 0 || _checkpointTime > block.timestamp) { - return checkpoint_.sharePrice; + if ( + checkpoint_.vaultSharePrice != 0 || + _checkpointTime > block.timestamp + ) { + return checkpoint_.vaultSharePrice; } - // Create the share price checkpoint. - checkpoint_.sharePrice = _sharePrice.toUint128(); + // Create the vault share price checkpoint. + checkpoint_.vaultSharePrice = _vaultSharePrice.toUint128(); // Collect the interest that has accrued since the last checkpoint. - _collectZombieInterest(_sharePrice); + _collectZombieInterest(_vaultSharePrice); // Close out all of the short positions that matured at the beginning of // this checkpoint. This ensures that shorts don't continue to collect @@ -95,9 +99,9 @@ abstract contract HyperdriveCheckpoint is // their side of the trade. Closing out shorts first helps with netting // by ensuring the LP funds that were netted with longs are back in the // shareReserves before we close out the longs. - uint256 openSharePrice = _checkpoints[ + uint256 openVaultSharePrice = _checkpoints[ _checkpointTime - _positionDuration - ].sharePrice; + ].vaultSharePrice; uint256 shortAssetId = AssetId.encodeAssetId( AssetId.AssetIdPrefix.Short, _checkpointTime @@ -110,8 +114,8 @@ abstract contract HyperdriveCheckpoint is uint256 governanceFee ) = _calculateMaturedProceeds( maturedShortsAmount, - _sharePrice, - openSharePrice, + _vaultSharePrice, + openVaultSharePrice, false ); _governanceFeesAccrued += governanceFee; @@ -123,18 +127,18 @@ abstract contract HyperdriveCheckpoint is _checkpointTime ); uint256 shareReservesDelta = maturedShortsAmount.divDown( - _sharePrice + _vaultSharePrice ); shareProceeds = HyperdriveMath.calculateShortProceeds( maturedShortsAmount, shareReservesDelta, - openSharePrice, - _sharePrice, - _sharePrice, + openVaultSharePrice, + _vaultSharePrice, + _vaultSharePrice, _flatFee ); _marketState.zombieBaseProceeds += shareProceeds - .mulDown(_sharePrice) + .mulDown(_vaultSharePrice) .toUint112(); _marketState.zombieShareReserves += shareProceeds.toUint128(); positionsClosed = true; @@ -153,8 +157,8 @@ abstract contract HyperdriveCheckpoint is uint256 governanceFee ) = _calculateMaturedProceeds( maturedLongsAmount, - _sharePrice, - openSharePrice, + _vaultSharePrice, + openVaultSharePrice, true ); _governanceFeesAccrued += governanceFee; @@ -167,7 +171,7 @@ abstract contract HyperdriveCheckpoint is checkpointTime ); _marketState.zombieBaseProceeds += shareProceeds - .mulDown(_sharePrice) + .mulDown(_vaultSharePrice) .toUint112(); _marketState.zombieShareReserves += shareProceeds.toUint128(); positionsClosed = true; @@ -185,41 +189,41 @@ abstract contract HyperdriveCheckpoint is ); // Distribute the excess idle to the withdrawal pool. - _distributeExcessIdle(_sharePrice); + _distributeExcessIdle(_vaultSharePrice); } // Emit an event about the checkpoint creation that includes the LP // share price. emit CreateCheckpoint( _checkpointTime, - _sharePrice, + _vaultSharePrice, maturedShortsAmount, maturedLongsAmount, - _calculateLPSharePrice(_sharePrice) + _calculateLPSharePrice(_vaultSharePrice) ); - return _sharePrice; + return _vaultSharePrice; } /// @dev Calculates the proceeds of the holders of a given position at /// maturity. /// @param _bondAmount The bond amount of the position. - /// @param _sharePrice The current share price. - /// @param _openSharePrice The share price at the beginning of the - /// position's checkpoint. + /// @param _vaultSharePrice The current vault share price. + /// @param _openVaultSharePrice The vault share price at the beginning of + /// the position's checkpoint. /// @param _isLong A flag indicating whether or not the position is a long. /// @return shareProceeds The proceeds of the holders in shares. /// @return governanceFee The fee paid to governance in shares. function _calculateMaturedProceeds( uint256 _bondAmount, - uint256 _sharePrice, - uint256 _openSharePrice, + uint256 _vaultSharePrice, + uint256 _openVaultSharePrice, bool _isLong ) internal view returns (uint256 shareProceeds, uint256 governanceFee) { // Calculate the share proceeds, flat fee, and governance fee. Since the // position is closed at maturity, the share proceeds are equal to the - // bond amount divided by the share price. - shareProceeds = _bondAmount.divDown(_sharePrice); + // bond amount divided by the vault share price. + shareProceeds = _bondAmount.divDown(_vaultSharePrice); uint256 flatFee = shareProceeds.mulDown(_flatFee); governanceFee = flatFee.mulDown(_governanceLPFee); @@ -244,14 +248,14 @@ abstract contract HyperdriveCheckpoint is // If negative interest accrued over the period, the proceeds and // governance fee are given a "haircut" proportional to the negative // interest that accrued. - if (_sharePrice < _openSharePrice) { + if (_vaultSharePrice < _openVaultSharePrice) { shareProceeds = shareProceeds.mulDivDown( - _sharePrice, - _openSharePrice + _vaultSharePrice, + _openVaultSharePrice ); governanceFee = governanceFee.mulDivDown( - _sharePrice, - _openSharePrice + _vaultSharePrice, + _openVaultSharePrice ); } } diff --git a/contracts/src/internal/HyperdriveLP.sol b/contracts/src/internal/HyperdriveLP.sol index 656e6caaf..ca28c66bc 100644 --- a/contracts/src/internal/HyperdriveLP.sol +++ b/contracts/src/internal/HyperdriveLP.sol @@ -41,7 +41,7 @@ abstract contract HyperdriveLP is HyperdriveBase, HyperdriveMultiToken { // Deposit the users contribution and get the amount of shares that // their contribution was worth. - (uint256 vaultShares, uint256 sharePrice) = _deposit( + (uint256 vaultShares, uint256 vaultSharePrice) = _deposit( _contribution, _options ); @@ -72,7 +72,7 @@ abstract contract HyperdriveLP is HyperdriveBase, HyperdriveMultiToken { _marketState.bondReserves = HyperdriveMath .calculateInitialBondReserves( vaultShares, - _initialSharePrice, + _initialVaultSharePrice, _apr, _positionDuration, _timeStretch @@ -90,19 +90,19 @@ abstract contract HyperdriveLP is HyperdriveBase, HyperdriveMultiToken { _mint(AssetId._LP_ASSET_ID, _options.destination, lpShares); // Create an initial checkpoint. - _applyCheckpoint(_latestCheckpoint(), sharePrice); + _applyCheckpoint(_latestCheckpoint(), vaultSharePrice); // Emit an Initialize event. uint256 baseContribution = _convertToBaseFromOption( _contribution, - sharePrice, + vaultSharePrice, _options ); emit Initialize( _options.destination, lpShares, baseContribution, - sharePrice, + vaultSharePrice, _apr ); @@ -131,7 +131,7 @@ abstract contract HyperdriveLP is HyperdriveBase, HyperdriveMultiToken { uint256 apr = HyperdriveMath.calculateSpotAPR( _effectiveShareReserves(), _marketState.bondReserves, - _initialSharePrice, + _initialVaultSharePrice, _positionDuration, _timeStretch ); @@ -140,13 +140,13 @@ abstract contract HyperdriveLP is HyperdriveBase, HyperdriveMultiToken { } // Deposit for the user, this call also transfers from them - (uint256 vaultShares, uint256 sharePrice) = _deposit( + (uint256 vaultShares, uint256 vaultSharePrice) = _deposit( _contribution, _options ); // Perform a checkpoint. - _applyCheckpoint(_latestCheckpoint(), sharePrice); + _applyCheckpoint(_latestCheckpoint(), vaultSharePrice); // Get the initial value for the total LP supply and the total supply // of withdrawal shares before the liquidity is added. The total LP @@ -166,7 +166,7 @@ abstract contract HyperdriveLP is HyperdriveBase, HyperdriveMultiToken { { // Calculate the present value before updating the reserves. LPMath.PresentValueParams memory params = _getPresentValueParams( - sharePrice + vaultSharePrice ); startingPresentValue = LPMath.calculatePresentValue(params); @@ -199,7 +199,7 @@ abstract contract HyperdriveLP is HyperdriveBase, HyperdriveMultiToken { _mint(AssetId._LP_ASSET_ID, _options.destination, lpShares); // Distribute the excess idle to the withdrawal pool. - _distributeExcessIdle(sharePrice); + _distributeExcessIdle(vaultSharePrice); // Emit an AddLiquidity event. uint256 lpSharePrice = lpTotalSupply == 0 @@ -207,14 +207,14 @@ abstract contract HyperdriveLP is HyperdriveBase, HyperdriveMultiToken { : startingPresentValue.divDown(lpTotalSupply); uint256 baseContribution = _convertToBaseFromOption( _contribution, - sharePrice, + vaultSharePrice, _options ); emit AddLiquidity( _options.destination, lpShares, baseContribution, - sharePrice, + vaultSharePrice, lpSharePrice ); } @@ -245,8 +245,8 @@ abstract contract HyperdriveLP is HyperdriveBase, HyperdriveMultiToken { } // Perform a checkpoint. - uint256 sharePrice = _pricePerShare(); - _applyCheckpoint(_latestCheckpoint(), sharePrice); + uint256 vaultSharePrice = _pricePerVaultShare(); + _applyCheckpoint(_latestCheckpoint(), vaultSharePrice); // Burn the LP's shares. _burn(AssetId._LP_ASSET_ID, msg.sender, _lpShares); @@ -259,13 +259,13 @@ abstract contract HyperdriveLP is HyperdriveBase, HyperdriveMultiToken { ); // Distribute excess idle to the withdrawal pool. - _distributeExcessIdle(sharePrice); + _distributeExcessIdle(vaultSharePrice); // Redeem as many of the withdrawal shares as possible. uint256 withdrawalSharesRedeemed; (proceeds, withdrawalSharesRedeemed) = _redeemWithdrawalSharesInternal( _lpShares, - sharePrice, + vaultSharePrice, _minOutputPerShare, _options ); @@ -274,16 +274,16 @@ abstract contract HyperdriveLP is HyperdriveBase, HyperdriveMultiToken { // Emit a RemoveLiquidity event. uint256 baseProceeds = _convertToBaseFromOption( proceeds, - sharePrice, + vaultSharePrice, _options ); emit RemoveLiquidity( _options.destination, _lpShares, baseProceeds, - sharePrice, // vault share price + vaultSharePrice, uint256(withdrawalShares), - _calculateLPSharePrice(sharePrice) // lp share price + _calculateLPSharePrice(vaultSharePrice) ); return (proceeds, withdrawalShares); @@ -310,17 +310,17 @@ abstract contract HyperdriveLP is HyperdriveBase, HyperdriveMultiToken { returns (uint256 proceeds, uint256 withdrawalSharesRedeemed) { // Perform a checkpoint. - uint256 sharePrice = _pricePerShare(); - _applyCheckpoint(_latestCheckpoint(), sharePrice); + uint256 vaultSharePrice = _pricePerVaultShare(); + _applyCheckpoint(_latestCheckpoint(), vaultSharePrice); // Distribute the excess idle to the withdrawal pool prior to redeeming // the withdrawal shares. - _distributeExcessIdle(sharePrice); + _distributeExcessIdle(vaultSharePrice); // Redeem as many of the withdrawal shares as possible. (proceeds, withdrawalSharesRedeemed) = _redeemWithdrawalSharesInternal( _withdrawalShares, - sharePrice, + vaultSharePrice, _minOutputPerShare, _options ); @@ -328,14 +328,14 @@ abstract contract HyperdriveLP is HyperdriveBase, HyperdriveMultiToken { // Emit a RedeemWithdrawalShares event. uint256 baseProceeds = _convertToBaseFromOption( proceeds, - sharePrice, + vaultSharePrice, _options ); emit RedeemWithdrawalShares( _options.destination, - withdrawalSharesRedeemed, // withdrawal shares + withdrawalSharesRedeemed, baseProceeds, - sharePrice // vault share price + vaultSharePrice ); return (proceeds, withdrawalSharesRedeemed); @@ -402,8 +402,8 @@ abstract contract HyperdriveLP is HyperdriveBase, HyperdriveMultiToken { /// @dev Distribute as much of the excess idle as possible to the withdrawal /// pool while holding the LP share price constant. - /// @param _sharePrice The current share price. - function _distributeExcessIdle(uint256 _sharePrice) internal { + /// @param _vaultSharePrice The current vault share price. + function _distributeExcessIdle(uint256 _vaultSharePrice) internal { // If there are no withdrawal shares, then there is nothing to // distribute. uint256 withdrawalSharesTotalSupply = _totalSupply[ @@ -414,7 +414,7 @@ abstract contract HyperdriveLP is HyperdriveBase, HyperdriveMultiToken { } // If there is no excess idle, then there is nothing to distribute. - uint256 idle = _calculateIdleShareReserves(_sharePrice); + uint256 idle = _calculateIdleShareReserves(_vaultSharePrice); if (idle == 0) { return; } @@ -426,7 +426,7 @@ abstract contract HyperdriveLP is HyperdriveBase, HyperdriveMultiToken { _getDistributeExcessIdleParams( idle, withdrawalSharesTotalSupply, - _sharePrice + _vaultSharePrice ) ); diff --git a/contracts/src/internal/HyperdriveLong.sol b/contracts/src/internal/HyperdriveLong.sol index c850d67ea..df02706ad 100644 --- a/contracts/src/internal/HyperdriveLong.sol +++ b/contracts/src/internal/HyperdriveLong.sol @@ -23,16 +23,17 @@ abstract contract HyperdriveLong is HyperdriveLP { /// @dev Opens a long position. /// @param _amount The amount to open a long with. /// @param _minOutput The minimum number of bonds to receive. - /// @param _minSharePrice The minimum share price at which to open the long. - /// This allows traders to protect themselves from opening a long in - /// a checkpoint where negative interest has accrued. + /// @param _minVaultSharePrice The minimum vault share price at which to + /// open the long. This allows traders to protect themselves from + /// opening a long in a checkpoint where negative interest has + /// accrued. /// @param _options The options that configure how the trade is settled. /// @return maturityTime The maturity time of the bonds. /// @return bondProceeds The amount of bonds the user received function _openLong( uint256 _amount, uint256 _minOutput, - uint256 _minSharePrice, + uint256 _minVaultSharePrice, IHyperdrive.Options calldata _options ) internal @@ -44,28 +45,28 @@ abstract contract HyperdriveLong is HyperdriveLP { _checkMessageValue(); // Deposit the user's input amount. - (uint256 sharesDeposited, uint256 sharePrice) = _deposit( + (uint256 sharesDeposited, uint256 vaultSharePrice) = _deposit( _amount, _options ); - // Enforce min user inputs and min share price - // Note: We use the value that is returned from the - // deposit to check against the min transaction - // amount because in the event of slippage on the - // deposit, we want the inputs to the state updates - // to respect the min transaction amount requirements. - uint256 baseDeposited = sharesDeposited.mulDown(sharePrice); + // Enforce the minimum user outputs and the mininum vault share price. + // + // NOTE: We use the value that is returned from the deposit to check + // against the minimum transaction amount because in the event of + // slippage on the deposit, we want the inputs to the state updates to + // respect the minimum transaction amount requirements. + uint256 baseDeposited = sharesDeposited.mulDown(vaultSharePrice); if (baseDeposited < _minimumTransactionAmount) { revert IHyperdrive.MinimumTransactionAmount(); } - if (sharePrice < _minSharePrice) { + if (vaultSharePrice < _minVaultSharePrice) { revert IHyperdrive.MinimumSharePrice(); } // Perform a checkpoint. uint256 latestCheckpoint = _latestCheckpoint(); - _applyCheckpoint(latestCheckpoint, sharePrice); + _applyCheckpoint(latestCheckpoint, vaultSharePrice); // Calculate the pool and user deltas using the trading function. We // backdate the bonds purchased to the beginning of the checkpoint. @@ -79,9 +80,9 @@ abstract contract HyperdriveLong is HyperdriveLP { bondReservesDelta, bondProceeds, totalGovernanceFee - ) = _calculateOpenLong(sharesDeposited, sharePrice); + ) = _calculateOpenLong(sharesDeposited, vaultSharePrice); - // Enforce min user outputs + // Enforce the minimum user outputs. if (_minOutput > bondProceeds) { revert IHyperdrive.OutputLimit(); } @@ -95,7 +96,7 @@ abstract contract HyperdriveLong is HyperdriveLP { shareReservesDelta, bondProceeds, bondReservesDelta, - sharePrice, + vaultSharePrice, maturityTime ); @@ -114,8 +115,8 @@ abstract contract HyperdriveLong is HyperdriveLP { _options.destination, assetId, maturityTime, - _convertToBaseFromOption(amount, sharePrice, options), - sharePrice, + _convertToBaseFromOption(amount, vaultSharePrice, options), + vaultSharePrice, _bondProceeds ); @@ -141,8 +142,8 @@ abstract contract HyperdriveLong is HyperdriveLP { // Perform a checkpoint at the maturity time. This ensures the long and // all of the other positions in the checkpoint are closed. This will // have no effect if the maturity time is in the future. - uint256 sharePrice = _pricePerShare(); - _applyCheckpoint(_maturityTime, sharePrice); + uint256 vaultSharePrice = _pricePerVaultShare(); + _applyCheckpoint(_maturityTime, vaultSharePrice); // Burn the longs that are being closed. _burn( @@ -159,7 +160,7 @@ abstract contract HyperdriveLong is HyperdriveLP { uint256 shareReservesDelta, int256 shareAdjustmentDelta, uint256 totalGovernanceFee - ) = _calculateCloseLong(_bondAmount, sharePrice, _maturityTime); + ) = _calculateCloseLong(_bondAmount, vaultSharePrice, _maturityTime); // If the position hasn't matured, apply the accounting updates that // result from closing the long to the reserves and pay out the @@ -185,16 +186,16 @@ abstract contract HyperdriveLong is HyperdriveLP { ); // Distribute the excess idle to the withdrawal pool. - _distributeExcessIdle(sharePrice); + _distributeExcessIdle(vaultSharePrice); } else { // Apply the zombie close to the state and adjust the share proceeds // to account for negative interest that might have accrued to the // zombie share reserves. - shareProceeds = _applyZombieClose(shareProceeds, sharePrice); + shareProceeds = _applyZombieClose(shareProceeds, vaultSharePrice); } // Withdraw the profit to the trader. - uint256 proceeds = _withdraw(shareProceeds, sharePrice, _options); + uint256 proceeds = _withdraw(shareProceeds, vaultSharePrice, _options); // Enforce min user outputs. // Note: We use the value that is returned from the @@ -203,7 +204,7 @@ abstract contract HyperdriveLong is HyperdriveLP { // it to be caught be the minOutput check. uint256 baseProceeds = _convertToBaseFromOption( proceeds, - sharePrice, + vaultSharePrice, _options ); if (_minOutput > baseProceeds) { @@ -217,7 +218,7 @@ abstract contract HyperdriveLong is HyperdriveLP { AssetId.encodeAssetId(AssetId.AssetIdPrefix.Long, maturityTime), maturityTime, baseProceeds, - sharePrice, + vaultSharePrice, bondAmount ); @@ -229,13 +230,13 @@ abstract contract HyperdriveLong is HyperdriveLP { /// @param _shareReservesDelta The amount of shares paid to the curve. /// @param _bondProceeds The amount of bonds purchased by the trader. /// @param _bondReservesDelta The amount of bonds sold by the curve. - /// @param _sharePrice The share price. + /// @param _vaultSharePrice The current vault share price. /// @param _maturityTime The maturity time of the long. function _applyOpenLong( uint256 _shareReservesDelta, uint256 _bondProceeds, uint256 _bondReservesDelta, - uint256 _sharePrice, + uint256 _vaultSharePrice, uint256 _maturityTime ) internal { // Update the average maturity time of long positions. @@ -267,12 +268,12 @@ abstract contract HyperdriveLong is HyperdriveLP { ); // We need to check solvency because longs increase the system's exposure. - if (!_isSolvent(_sharePrice)) { + if (!_isSolvent(_vaultSharePrice)) { revert IHyperdrive.InsufficientLiquidity(); } // Distribute the excess idle to the withdrawal pool. - _distributeExcessIdle(_sharePrice); + _distributeExcessIdle(_vaultSharePrice); } /// @dev Applies the trading deltas from a closed long to the reserves and @@ -340,14 +341,14 @@ abstract contract HyperdriveLong is HyperdriveLP { /// @dev Calculate the pool reserve and trader deltas that result from /// opening a long. This calculation includes trading fees. /// @param _shareAmount The amount of shares being paid to open the long. - /// @param _sharePrice The current share price. + /// @param _vaultSharePrice The current vault share price. /// @return shareReservesDelta The change in the share reserves. /// @return bondReservesDelta The change in the bond reserves. /// @return bondProceeds The proceeds in bonds. /// @return totalGovernanceFee The governance fee in shares. function _calculateOpenLong( uint256 _shareAmount, - uint256 _sharePrice + uint256 _vaultSharePrice ) internal view @@ -365,8 +366,8 @@ abstract contract HyperdriveLong is HyperdriveLP { _marketState.bondReserves, _shareAmount, // amountIn _timeStretch, - _sharePrice, - _initialSharePrice + _vaultSharePrice, + _initialVaultSharePrice ); // Ensure that the trader didn't purchase bonds at a negative interest @@ -374,7 +375,7 @@ abstract contract HyperdriveLong is HyperdriveLP { uint256 spotPrice = HyperdriveMath.calculateSpotPrice( _effectiveShareReserves(), _marketState.bondReserves, - _initialSharePrice, + _initialVaultSharePrice, _timeStretch ); if ( @@ -396,7 +397,11 @@ abstract contract HyperdriveLong is HyperdriveLP { ( uint256 curveFee, // bonds uint256 governanceCurveFee // bonds - ) = _calculateFeesGivenShares(_shareAmount, spotPrice, _sharePrice); + ) = _calculateFeesGivenShares( + _shareAmount, + spotPrice, + _vaultSharePrice + ); // Calculate the number of bonds the trader receives. // This is the amount of bonds the trader receives minus the fees. @@ -415,17 +420,17 @@ abstract contract HyperdriveLong is HyperdriveLP { // bonds = bonds + bonds bondReservesDelta = bondProceeds + governanceCurveFee; - // Calculate the fees owed to governance in shares. Open longs - // are calculated entirely on the curve so the curve fee is the - // total governance fee. In order to convert it to shares we need to - // multiply it by the spot price and divide it by the share price: + // Calculate the fees owed to governance in shares. Open longs are + // calculated entirely on the curve so the curve fee is the total + // governance fee. In order to convert it to shares we need to multiply + // it by the spot price and divide it by the vault share price: // // shares = (bonds * base/bonds) / (base/shares) // shares = bonds * shares/bonds // shares = shares totalGovernanceFee = governanceCurveFee.mulDivDown( spotPrice, - _sharePrice + _vaultSharePrice ); // Calculate the number of shares to add to the shareReserves. @@ -446,7 +451,7 @@ abstract contract HyperdriveLong is HyperdriveLP { /// @dev Calculate the pool reserve and trader deltas that result from /// closing a long. This calculation includes trading fees. /// @param _bondAmount The amount of bonds being purchased to close the short. - /// @param _sharePrice The current share price. + /// @param _vaultSharePrice The current vault share price. /// @param _maturityTime The maturity time of the short position. /// @return bondReservesDelta The bonds added to the reserves. /// @return shareProceeds The proceeds in shares of selling the bonds. @@ -455,7 +460,7 @@ abstract contract HyperdriveLong is HyperdriveLP { /// @return totalGovernanceFee The governance fee in shares. function _calculateCloseLong( uint256 _bondAmount, - uint256 _sharePrice, + uint256 _vaultSharePrice, uint256 _maturityTime ) internal @@ -488,8 +493,8 @@ abstract contract HyperdriveLong is HyperdriveLP { _bondAmount, timeRemaining, _timeStretch, - _sharePrice, - _initialSharePrice + _vaultSharePrice, + _initialVaultSharePrice ); // Calculate the fees that should be paid by the trader. The trader @@ -500,7 +505,7 @@ abstract contract HyperdriveLong is HyperdriveLP { uint256 spotPrice = HyperdriveMath.calculateSpotPrice( _effectiveShareReserves(), _marketState.bondReserves, - _initialSharePrice, + _initialVaultSharePrice, _timeStretch ); ( @@ -512,7 +517,7 @@ abstract contract HyperdriveLong is HyperdriveLP { _bondAmount, timeRemaining, spotPrice, - _sharePrice + _vaultSharePrice ); // The curve fee (shares) is paid to the LPs, so we subtract it from @@ -548,16 +553,17 @@ abstract contract HyperdriveLong is HyperdriveLP { shareReservesDelta, shareCurveDelta, totalGovernanceFee, - // NOTE: We use the share price from the beginning of the - // checkpoint as the open share price. This means that a trader - // that opens a long in a checkpoint that has negative interest - // accrued will be penalized for the negative interest when they - // try to close their position. The `_minSharePrice` parameter - // allows traders to protect themselves from this edge case. - _checkpoints[_maturityTime - _positionDuration].sharePrice, // open share price + // NOTE: We use the vault share price from the beginning of the + // checkpoint as the open vault share price. This means that a + // trader that opens a long in a checkpoint that has negative + // interest accrued will be penalized for the negative interest when + // they try to close their position. The `_minVaultSharePrice` + // parameter allows traders to protect themselves from this edge + // case. + _checkpoints[_maturityTime - _positionDuration].vaultSharePrice, // open vault share price block.timestamp < _maturityTime - ? _sharePrice - : _checkpoints[_maturityTime].sharePrice, // close share price + ? _vaultSharePrice + : _checkpoints[_maturityTime].vaultSharePrice, // close vault share price true ); } diff --git a/contracts/src/internal/HyperdriveShort.sol b/contracts/src/internal/HyperdriveShort.sol index f41816148..5dd008fdb 100644 --- a/contracts/src/internal/HyperdriveShort.sol +++ b/contracts/src/internal/HyperdriveShort.sol @@ -23,16 +23,16 @@ abstract contract HyperdriveShort is HyperdriveLP { /// @dev Opens a short position. /// @param _bondAmount The amount of bonds to short. /// @param _maxDeposit The most the user expects to deposit for this trade. - /// @param _minSharePrice The minium share price at which to open the long. - /// This allows traders to protect themselves from opening a long in - /// a checkpoint where negative interest has accrued. + /// @param _minVaultSharePrice The minium vault share price at which to open + /// the long. This allows traders to protect themselves from opening + /// a long in a checkpoint where negative interest has accrued. /// @param _options The options that configure how the trade is settled. /// @return The maturity time of the short. /// @return The amount the user deposited for this trade. function _openShort( uint256 _bondAmount, uint256 _maxDeposit, - uint256 _minSharePrice, + uint256 _minVaultSharePrice, IHyperdrive.Options calldata _options ) internal nonReentrant isNotPaused returns (uint256, uint256) { // Check that the message value and base amount are valid. @@ -45,12 +45,15 @@ abstract contract HyperdriveShort is HyperdriveLP { // would have received if they opened at the beginning of the checkpoint. // Since the short will receive interest from the beginning of the // checkpoint, they will receive this backdated interest back at closing. - uint256 sharePrice = _pricePerShare(); - if (sharePrice < _minSharePrice) { + uint256 vaultSharePrice = _pricePerVaultShare(); + if (vaultSharePrice < _minVaultSharePrice) { revert IHyperdrive.MinimumSharePrice(); } uint256 latestCheckpoint = _latestCheckpoint(); - uint256 openSharePrice = _applyCheckpoint(latestCheckpoint, sharePrice); + uint256 openVaultSharePrice = _applyCheckpoint( + latestCheckpoint, + vaultSharePrice + ); // Calculate the pool and user deltas using the trading function. We // backdate the bonds sold to the beginning of the checkpoint. @@ -64,7 +67,11 @@ abstract contract HyperdriveShort is HyperdriveLP { baseDeposit, shareReservesDelta, totalGovernanceFee - ) = _calculateOpenShort(_bondAmount, sharePrice, openSharePrice); + ) = _calculateOpenShort( + _bondAmount, + vaultSharePrice, + openVaultSharePrice + ); // Attribute the governance fees. _governanceFeesAccrued += totalGovernanceFee; @@ -80,7 +87,7 @@ abstract contract HyperdriveShort is HyperdriveLP { // from the user to pass due to the shares being worth less after deposit. uint256 traderDeposit = _convertToOptionFromBase( baseDeposit, - sharePrice, + vaultSharePrice, _options ); if (_maxDeposit < traderDeposit) { @@ -95,12 +102,11 @@ abstract contract HyperdriveShort is HyperdriveLP { _applyOpenShort( _bondAmount, shareReservesDelta, - sharePrice, + vaultSharePrice, maturityTime ); - // Mint the short tokens to the trader. The ID is a concatenation of the - // current share price and the maturity time of the shorts. + // Mint the short tokens to the trader. uint256 assetId = AssetId.encodeAssetId( AssetId.AssetIdPrefix.Short, maturityTime @@ -114,7 +120,7 @@ abstract contract HyperdriveShort is HyperdriveLP { assetId, maturityTime, baseDeposit, - sharePrice, + vaultSharePrice, bondAmount ); @@ -138,8 +144,8 @@ abstract contract HyperdriveShort is HyperdriveLP { } // Perform a checkpoint. - uint256 sharePrice = _pricePerShare(); - _applyCheckpoint(_maturityTime, sharePrice); + uint256 vaultSharePrice = _pricePerVaultShare(); + _applyCheckpoint(_maturityTime, vaultSharePrice); // Burn the shorts that are being closed. _burn( @@ -158,7 +164,7 @@ abstract contract HyperdriveShort is HyperdriveLP { uint256 shareReservesDelta, int256 shareAdjustmentDelta, uint256 totalGovernanceFee - ) = _calculateCloseShort(_bondAmount, sharePrice, _maturityTime); + ) = _calculateCloseShort(_bondAmount, vaultSharePrice, _maturityTime); // If the position hasn't matured, apply the accounting updates that // result from closing the short to the reserves and pay out the @@ -185,18 +191,18 @@ abstract contract HyperdriveShort is HyperdriveLP { ); // Distribute the excess idle to the withdrawal pool. - _distributeExcessIdle(sharePrice); + _distributeExcessIdle(vaultSharePrice); } else { // Apply the zombie close to the state and adjust the share proceeds // to account for negative interest that might have accrued to the // zombie share reserves. - shareProceeds = _applyZombieClose(shareProceeds, sharePrice); + shareProceeds = _applyZombieClose(shareProceeds, vaultSharePrice); } // Withdraw the profit to the trader. This includes the proceeds from // the short sale as well as the variable interest that was collected // on the face value of the bonds. - uint256 proceeds = _withdraw(shareProceeds, sharePrice, _options); + uint256 proceeds = _withdraw(shareProceeds, vaultSharePrice, _options); // Enforce the user's minimum output. // Note: We use the value that is returned from the @@ -205,7 +211,7 @@ abstract contract HyperdriveShort is HyperdriveLP { // it to be caught be the minOutput check. uint256 baseProceeds = _convertToBaseFromOption( proceeds, - sharePrice, + vaultSharePrice, _options ); if (baseProceeds < _minOutput) { @@ -220,7 +226,7 @@ abstract contract HyperdriveShort is HyperdriveLP { AssetId.encodeAssetId(AssetId.AssetIdPrefix.Short, maturityTime), maturityTime, baseProceeds, - sharePrice, + vaultSharePrice, bondAmount ); @@ -231,12 +237,12 @@ abstract contract HyperdriveShort is HyperdriveLP { /// reserves and maintaining the reserve invariants. /// @param _bondAmount The amount of bonds shorted. /// @param _shareReservesDelta The amount of shares paid to the curve. - /// @param _sharePrice The share price. + /// @param _vaultSharePrice The current vault share price. /// @param _maturityTime The maturity time of the long. function _applyOpenShort( uint256 _bondAmount, uint256 _shareReservesDelta, - uint256 _sharePrice, + uint256 _vaultSharePrice, uint256 _maturityTime ) internal { // Update the average maturity time of long positions. @@ -290,12 +296,12 @@ abstract contract HyperdriveShort is HyperdriveLP { // opening a short decreases the share reserves, which limits the amount // of capital available to back non-netted long exposure. Since both // quantities decrease, we need to check that the system is still solvent. - if (!_isSolvent(_sharePrice)) { + if (!_isSolvent(_vaultSharePrice)) { revert IHyperdrive.InsufficientLiquidity(); } // Distribute the excess idle to the withdrawal pool. - _distributeExcessIdle(_sharePrice); + _distributeExcessIdle(_vaultSharePrice); } /// @dev Applies the trading deltas from a closed short to the reserves and @@ -339,15 +345,16 @@ abstract contract HyperdriveShort is HyperdriveLP { /// @dev Calculate the pool reserve and trader deltas that result from /// opening a short. This calculation includes trading fees. /// @param _bondAmount The amount of bonds being sold to open the short. - /// @param _sharePrice The current share price. - /// @param _openSharePrice The share price at the beginning of the checkpoint. + /// @param _vaultSharePrice The current vault share price. + /// @param _openVaultSharePrice The vault share price at the beginning of + /// the checkpoint. /// @return baseDeposit The deposit, in base, required to open the short. /// @return shareReservesDelta The change in the share reserves. /// @return totalGovernanceFee The governance fee in shares. function _calculateOpenShort( uint256 _bondAmount, - uint256 _sharePrice, - uint256 _openSharePrice + uint256 _vaultSharePrice, + uint256 _openVaultSharePrice ) internal view @@ -365,14 +372,14 @@ abstract contract HyperdriveShort is HyperdriveLP { _marketState.bondReserves, _bondAmount, _timeStretch, - _sharePrice, - _initialSharePrice + _vaultSharePrice, + _initialVaultSharePrice ); // If the base proceeds of selling the bonds is greater than the bond // amount, then the trade occurred in the negative interest domain. We // revert in these pathological cases. - if (shareReservesDelta.mulDown(_sharePrice) > _bondAmount) { + if (shareReservesDelta.mulDown(_vaultSharePrice) > _bondAmount) { revert IHyperdrive.NegativeInterest(); } @@ -383,7 +390,7 @@ abstract contract HyperdriveShort is HyperdriveLP { uint256 spotPrice = HyperdriveMath.calculateSpotPrice( _effectiveShareReserves(), _marketState.bondReserves, - _initialSharePrice, + _initialVaultSharePrice, _timeStretch ); @@ -393,7 +400,7 @@ abstract contract HyperdriveShort is HyperdriveLP { _bondAmount, ONE, // shorts are opened at the beginning of the term spotPrice, - _sharePrice + _vaultSharePrice ); // Subtract the total curve fee minus the governance curve fee to the @@ -413,9 +420,10 @@ abstract contract HyperdriveShort is HyperdriveLP { // The trader will need to deposit capital to pay for the fixed rate, // the curve fee, the flat fee, and any back-paid interest that will be // received back upon closing the trade. If negative interest has - // accrued during the current checkpoint, we set close share price to - // equal the open share price. This ensures that shorts don't benefit - // from negative interest that accrued during the current checkpoint. + // accrued during the current checkpoint, we set the close vault share + // price to equal the open vault share price. This ensures that shorts + // don't benefit from negative interest that accrued during the current + // checkpoint. baseDeposit = HyperdriveMath .calculateShortProceeds( _bondAmount, @@ -423,12 +431,12 @@ abstract contract HyperdriveShort is HyperdriveLP { // delta here because the trader will need to provide this in // their deposit. shareReservesDelta - governanceCurveFee, - _openSharePrice, - _sharePrice.max(_openSharePrice), - _sharePrice, + _openVaultSharePrice, + _vaultSharePrice.max(_openVaultSharePrice), + _vaultSharePrice, _flatFee ) - .mulDown(_sharePrice); + .mulDown(_vaultSharePrice); return (baseDeposit, shareReservesDelta, governanceCurveFee); } @@ -437,7 +445,7 @@ abstract contract HyperdriveShort is HyperdriveLP { /// closing a short. This calculation includes trading fees. /// @param _bondAmount The amount of bonds being purchased to close the /// short. - /// @param _sharePrice The current share price. + /// @param _vaultSharePrice The current vault share price. /// @param _maturityTime The maturity time of the short position. /// @return bondReservesDelta The change in the bond reserves. /// @return shareProceeds The proceeds in shares of closing the short. @@ -446,7 +454,7 @@ abstract contract HyperdriveShort is HyperdriveLP { /// @return totalGovernanceFee The governance fee in shares. function _calculateCloseShort( uint256 _bondAmount, - uint256 _sharePrice, + uint256 _vaultSharePrice, uint256 _maturityTime ) internal @@ -482,8 +490,8 @@ abstract contract HyperdriveShort is HyperdriveLP { _bondAmount, timeRemaining, _timeStretch, - _sharePrice, - _initialSharePrice + _vaultSharePrice, + _initialVaultSharePrice ); // Ensure that the trader didn't purchase bonds at a negative interest @@ -491,7 +499,7 @@ abstract contract HyperdriveShort is HyperdriveLP { uint256 spotPrice = HyperdriveMath.calculateSpotPrice( _effectiveShareReserves(), _marketState.bondReserves, - _initialSharePrice, + _initialVaultSharePrice, _timeStretch ); if ( @@ -511,7 +519,7 @@ abstract contract HyperdriveShort is HyperdriveLP { // flatFee) and the portion of those fees that are paid to // governance (totalGovernanceFee). uint256 bondAmount = _bondAmount; // Avoid stack too deep. - uint256 sharePrice = _sharePrice; // Avoid stack too deep. + uint256 vaultSharePrice = _vaultSharePrice; // Avoid stack too deep. uint256 curveFee; uint256 flatFee; uint256 governanceCurveFee; @@ -524,7 +532,7 @@ abstract contract HyperdriveShort is HyperdriveLP { bondAmount, timeRemaining, spotPrice, - sharePrice + vaultSharePrice ); // Add the total curve fee minus the governance curve fee to the @@ -548,12 +556,12 @@ abstract contract HyperdriveShort is HyperdriveLP { // Calculate the share proceeds owed to the short and account for // negative interest that accrued over the period. { - uint256 openSharePrice = _checkpoints[ + uint256 openVaultSharePrice = _checkpoints[ _maturityTime - _positionDuration - ].sharePrice; - uint256 closeSharePrice = block.timestamp < _maturityTime - ? _sharePrice - : _checkpoints[_maturityTime].sharePrice; + ].vaultSharePrice; + uint256 closeVaultSharePrice = block.timestamp < _maturityTime + ? _vaultSharePrice + : _checkpoints[_maturityTime].vaultSharePrice; // Calculate the share proceeds owed to the short. We calculate this // before scaling the share payment for negative interest. Shorts @@ -565,9 +573,9 @@ abstract contract HyperdriveShort is HyperdriveLP { shareProceeds = HyperdriveMath.calculateShortProceeds( _bondAmount, shareReservesDelta, - openSharePrice, - closeSharePrice, - _sharePrice, + openVaultSharePrice, + closeVaultSharePrice, + _vaultSharePrice, _flatFee ); @@ -591,8 +599,8 @@ abstract contract HyperdriveShort is HyperdriveLP { shareReservesDelta, shareCurveDelta, totalGovernanceFee, - openSharePrice, - closeSharePrice, + openVaultSharePrice, + closeVaultSharePrice, false ); } diff --git a/contracts/src/internal/HyperdriveStorage.sol b/contracts/src/internal/HyperdriveStorage.sol index c3be18a2d..8ecf0ac07 100644 --- a/contracts/src/internal/HyperdriveStorage.sol +++ b/contracts/src/internal/HyperdriveStorage.sol @@ -23,7 +23,7 @@ abstract contract HyperdriveStorage is ReentrancyGuard { /// Time /// - /// @dev The amount of seconds between share price checkpoints. + /// @dev The amount of seconds between vault share price checkpoints. uint256 internal immutable _checkpointDuration; /// @dev The amount of seconds that elapse before a bond can be redeemed. @@ -48,8 +48,8 @@ abstract contract HyperdriveStorage is ReentrancyGuard { /// Market State /// - /// @dev The share price at the time the pool was created. - uint256 internal immutable _initialSharePrice; + /// @dev The vault share price at the time the pool was created. + uint256 internal immutable _initialVaultSharePrice; /// @dev The minimum amount of share reserves that must be maintained at all /// times. This is used to enforce practical limits on the share @@ -70,8 +70,8 @@ abstract contract HyperdriveStorage is ReentrancyGuard { /// @dev Hyperdrive positions are bucketed into checkpoints, which allows us /// to avoid poking in any period that has LP or trading activity. The - /// checkpoints contain the starting share price from the checkpoint as - /// well as aggregate volume values. + /// checkpoints contain the starting vault share price from the + /// checkpoint as well as aggregate volume values. mapping(uint256 checkpointNumber => IHyperdrive.Checkpoint checkpoint) internal _checkpoints; @@ -159,7 +159,7 @@ abstract contract HyperdriveStorage is ReentrancyGuard { } _positionDuration = _config.positionDuration; _timeStretch = _config.timeStretch; - _initialSharePrice = _config.initialSharePrice; + _initialVaultSharePrice = _config.initialVaultSharePrice; _governance = _config.governance; _feeCollector = _config.feeCollector; diff --git a/contracts/src/libraries/HyperdriveMath.sol b/contracts/src/libraries/HyperdriveMath.sol index 0bcd272a1..6e6ee6e7d 100644 --- a/contracts/src/libraries/HyperdriveMath.sol +++ b/contracts/src/libraries/HyperdriveMath.sol @@ -22,18 +22,18 @@ library HyperdriveMath { /// effective share reserves are a modified version of the share /// reserves used when pricing trades. /// @param _bondReserves The pool's bond reserves. - /// @param _initialSharePrice The initial share price. + /// @param _initialVaultSharePrice The initial vault share price. /// @param _timeStretch The time stretch parameter. /// @return spotPrice The spot price of bonds in terms of base. function calculateSpotPrice( uint256 _effectiveShareReserves, uint256 _bondReserves, - uint256 _initialSharePrice, + uint256 _initialVaultSharePrice, uint256 _timeStretch ) internal pure returns (uint256 spotPrice) { // p = (y / (mu * (z - zeta))) ** -t_s // = ((mu * (z - zeta)) / y) ** t_s - spotPrice = _initialSharePrice + spotPrice = _initialVaultSharePrice .mulDivDown(_effectiveShareReserves, _bondReserves) .pow(_timeStretch); } @@ -43,14 +43,14 @@ library HyperdriveMath { /// effective share reserves are a modified version of the share /// reserves used when pricing trades. /// @param _bondReserves The pool's bond reserves. - /// @param _initialSharePrice The pool's initial share price. + /// @param _initialVaultSharePrice The pool's initial vault share price. /// @param _positionDuration The amount of time until maturity in seconds. /// @param _timeStretch The time stretch parameter. /// @return apr The pool's spot APR. function calculateSpotAPR( uint256 _effectiveShareReserves, uint256 _bondReserves, - uint256 _initialSharePrice, + uint256 _initialVaultSharePrice, uint256 _positionDuration, uint256 _timeStretch ) internal pure returns (uint256 apr) { @@ -61,7 +61,7 @@ library HyperdriveMath { uint256 spotPrice = calculateSpotPrice( _effectiveShareReserves, _bondReserves, - _initialSharePrice, + _initialVaultSharePrice, _timeStretch ); return @@ -98,7 +98,7 @@ library HyperdriveMath { /// @param _effectiveShareReserves The pool's effective share reserves. The /// effective share reserves are a modified version of the share /// reserves used when pricing trades. - /// @param _initialSharePrice The pool's initial share price. + /// @param _initialVaultSharePrice The pool's initial vault share price. /// @param _apr The pool's APR. /// @param _positionDuration The amount of time until maturity in seconds. /// @param _timeStretch The time stretch parameter. @@ -106,7 +106,7 @@ library HyperdriveMath { /// the pool have a specified APR. function calculateInitialBondReserves( uint256 _effectiveShareReserves, - uint256 _initialSharePrice, + uint256 _initialVaultSharePrice, uint256 _apr, uint256 _positionDuration, uint256 _timeStretch @@ -116,7 +116,7 @@ library HyperdriveMath { // mu * (z - zeta) * (1 + apr * t) ** (1 / tau) return - _initialSharePrice.mulDown(_effectiveShareReserves).mulDown( + _initialVaultSharePrice.mulDown(_effectiveShareReserves).mulDown( (ONE + _apr.mulDown(t)).pow(ONE.divUp(_timeStretch)) ); } @@ -131,24 +131,24 @@ library HyperdriveMath { /// = (1 + flat_fee) * dy - c * dz + (c1 / c0) * dy - dy /// = (c1 / c0 + flat_fee) * dy - c * dz /// - /// We convert the proceeds to shares by dividing by the current share - /// price. In the event that the interest is negative and outweighs the - /// trading profits and margin released, the short's proceeds are - /// marked to zero. + /// We convert the proceeds to shares by dividing by the current vault + /// share price. In the event that the interest is negative and + /// outweighs the trading profits and margin released, the short's + /// proceeds are marked to zero. /// @param _bondAmount The amount of bonds underlying the closed short. /// @param _shareAmount The amount of shares that it costs to close the /// short. - /// @param _openSharePrice The share price at the short's open. - /// @param _closeSharePrice The share price at the short's close. - /// @param _sharePrice The current share price. + /// @param _openVaultSharePrice The vault share price at the short's open. + /// @param _closeVaultSharePrice The vault share price at the short's close. + /// @param _vaultSharePrice The current vault share price. /// @param _flatFee The flat fee currently within the pool /// @return shareProceeds The short proceeds in shares. function calculateShortProceeds( uint256 _bondAmount, uint256 _shareAmount, - uint256 _openSharePrice, - uint256 _closeSharePrice, - uint256 _sharePrice, + uint256 _openVaultSharePrice, + uint256 _closeVaultSharePrice, + uint256 _vaultSharePrice, uint256 _flatFee ) internal pure returns (uint256 shareProceeds) { // If the interest is more negative than the trading profits and margin @@ -156,13 +156,13 @@ library HyperdriveMath { // calculate the proceeds as the sum of the trading proceeds, the // interest proceeds, and the margin released. uint256 bondFactor = _bondAmount - .mulDivDown(_closeSharePrice, _openSharePrice) - .divDown(_sharePrice); + .mulDivDown(_closeVaultSharePrice, _openVaultSharePrice) + .divDown(_vaultSharePrice); // We increase the bondFactor by the flat fee amount, because the trader // has provided the flat fee as margin, and so it must be returned to // them if it's not charged. - bondFactor += _bondAmount.mulDivDown(_flatFee, _sharePrice); + bondFactor += _bondAmount.mulDivDown(_flatFee, _vaultSharePrice); if (bondFactor > _shareAmount) { // proceeds = (c1 / c0 * c) * dy - dz @@ -225,16 +225,16 @@ library HyperdriveMath { /// @param _bondReserves The pool's bond reserves. /// @param _shareAmount The amount of shares the user is depositing. /// @param _timeStretch The time stretch parameter. - /// @param _sharePrice The share price. - /// @param _initialSharePrice The initial share price. + /// @param _vaultSharePrice The vault share price. + /// @param _initialVaultSharePrice The initial vault share price. /// @return bondReservesDelta The bonds paid by the reserves in the trade. function calculateOpenLong( uint256 _effectiveShareReserves, uint256 _bondReserves, uint256 _shareAmount, uint256 _timeStretch, - uint256 _sharePrice, - uint256 _initialSharePrice + uint256 _vaultSharePrice, + uint256 _initialVaultSharePrice ) internal pure returns (uint256) { // NOTE: We underestimate the trader's bond proceeds to avoid sandwich // attacks. @@ -247,8 +247,8 @@ library HyperdriveMath { // we use a time remaining of 1. This means that we can use // `_timeStretch = t * _timeStretch`. ONE - _timeStretch, - _sharePrice, - _initialSharePrice + _vaultSharePrice, + _initialVaultSharePrice ); } @@ -262,8 +262,9 @@ library HyperdriveMath { /// @param _normalizedTimeRemaining The normalized time remaining of the /// position. /// @param _timeStretch The time stretch parameter. - /// @param _sharePrice The share price. - /// @param _initialSharePrice The share price when the pool was deployed. + /// @param _vaultSharePrice The vault share price. + /// @param _initialVaultSharePrice The vault share price when the pool was + /// deployed. /// @return shareCurveDelta The shares paid by the reserves in the trade. /// @return bondCurveDelta The bonds paid to the reserves in the trade. /// @return shareProceeds The shares that the user will receive. @@ -273,8 +274,8 @@ library HyperdriveMath { uint256 _amountIn, uint256 _normalizedTimeRemaining, uint256 _timeStretch, - uint256 _sharePrice, - uint256 _initialSharePrice + uint256 _vaultSharePrice, + uint256 _initialVaultSharePrice ) internal pure @@ -288,11 +289,11 @@ library HyperdriveMath { // matured and timeRemaining * amountIn of the bonds to be newly // minted. The fully matured bonds are redeemed one-to-one to base // (our result is given in shares, so we divide the one-to-one - // redemption by the share price) and the newly minted bonds are + // redemption by the vault share price) and the newly minted bonds are // traded on a YieldSpace curve configured to `timeRemaining = 1`. shareProceeds = _amountIn.mulDivDown( ONE - _normalizedTimeRemaining, - _sharePrice + _vaultSharePrice ); if (_normalizedTimeRemaining > 0) { // Calculate the curved part of the trade. @@ -308,8 +309,8 @@ library HyperdriveMath { // we use a time remaining of 1. This means that we can use // `_timeStretch = t * _timeStretch`. ONE - _timeStretch, - _sharePrice, - _initialSharePrice + _vaultSharePrice, + _initialVaultSharePrice ); shareProceeds += shareCurveDelta; } @@ -323,16 +324,16 @@ library HyperdriveMath { /// @param _bondReserves The pool's bonds reserves. /// @param _amountIn The amount of bonds the user is providing. /// @param _timeStretch The time stretch parameter. - /// @param _sharePrice The share price. - /// @param _initialSharePrice The initial share price. + /// @param _vaultSharePrice The vault share price. + /// @param _initialVaultSharePrice The initial vault share price. /// @return The shares paid by the reserves in the trade. function calculateOpenShort( uint256 _effectiveShareReserves, uint256 _bondReserves, uint256 _amountIn, uint256 _timeStretch, - uint256 _sharePrice, - uint256 _initialSharePrice + uint256 _vaultSharePrice, + uint256 _initialVaultSharePrice ) internal pure returns (uint256) { // NOTE: We underestimate the LP's share payment to avoid sandwiches. return @@ -344,8 +345,8 @@ library HyperdriveMath { // we use a time remaining of 1. This means that we can use // `_timeStretch = t * _timeStretch`. ONE - _timeStretch, - _sharePrice, - _initialSharePrice + _vaultSharePrice, + _initialVaultSharePrice ); } @@ -359,8 +360,8 @@ library HyperdriveMath { /// @param _normalizedTimeRemaining The amount of time remaining until /// maturity in seconds. /// @param _timeStretch The time stretch parameter. - /// @param _sharePrice The share price. - /// @param _initialSharePrice The initial share price. + /// @param _vaultSharePrice The vault share price. + /// @param _initialVaultSharePrice The initial vault share price. /// @return shareCurveDelta The shares paid to the reserves in the trade. /// @return bondCurveDelta The bonds paid by the reserves in the trade. /// @return sharePayment The shares that the user must pay. @@ -370,8 +371,8 @@ library HyperdriveMath { uint256 _amountOut, uint256 _normalizedTimeRemaining, uint256 _timeStretch, - uint256 _sharePrice, - uint256 _initialSharePrice + uint256 _vaultSharePrice, + uint256 _initialVaultSharePrice ) internal pure @@ -386,12 +387,12 @@ library HyperdriveMath { // purchased to be fully matured and `timeRemaining * amountOut of the // bonds to be newly minted. The fully matured bonds are redeemed // one-to-one to base (our result is given in shares, so we divide - // the one-to-one redemption by the share price) and the newly + // the one-to-one redemption by the vault share price) and the newly // minted bonds are traded on a YieldSpace curve configured to // timeRemaining = 1. sharePayment = _amountOut.mulDivDown( ONE - _normalizedTimeRemaining, - _sharePrice + _vaultSharePrice ); if (_normalizedTimeRemaining > 0) { bondCurveDelta = _amountOut.mulDown(_normalizedTimeRemaining); @@ -406,8 +407,8 @@ library HyperdriveMath { // we use a time remaining of 1. This means that we can use // `_timeStretch = t * _timeStretch`. ONE - _timeStretch, - _sharePrice, - _initialSharePrice + _vaultSharePrice, + _initialVaultSharePrice ); sharePayment += shareCurveDelta; } @@ -434,8 +435,9 @@ library HyperdriveMath { /// @param _shareReservesDelta The change in share reserves from the trade. /// @param _shareCurveDelta The curve portion of the change in share reserves. /// @param _totalGovernanceFee The total governance fee. - /// @param _openSharePrice The share price at the beginning of the term. - /// @param _closeSharePrice The share price at the end of the term. + /// @param _openVaultSharePrice The vault share price at the beginning of + /// the term. + /// @param _closeVaultSharePrice The vault share price at the end of the term. /// @param _isLong A flag indicating whether or not the trade is a long. /// @return The adjusted share proceeds. /// @return The adjusted share reserves delta. @@ -447,8 +449,8 @@ library HyperdriveMath { uint256 _shareReservesDelta, uint256 _shareCurveDelta, uint256 _totalGovernanceFee, - uint256 _openSharePrice, - uint256 _closeSharePrice, + uint256 _openVaultSharePrice, + uint256 _closeVaultSharePrice, bool _isLong ) internal pure returns (uint256, uint256, uint256, int256, uint256) { // The share reserves delta, share curve delta, and total governance fee @@ -466,33 +468,33 @@ library HyperdriveMath { // shareAdjustmentDelta = min(c_1 / c_0, 1) * shareReservesDelta - // shareCurveDelta int256 shareAdjustmentDelta; - if (_closeSharePrice < _openSharePrice) { + if (_closeVaultSharePrice < _openVaultSharePrice) { // We only need to scale the proceeds in the case that we're closing // a long since `calculateShortProceeds` accounts for negative // interest. if (_isLong) { _shareProceeds = _shareProceeds.mulDivDown( - _closeSharePrice, - _openSharePrice + _closeVaultSharePrice, + _openVaultSharePrice ); } // Scale the other values. _shareReservesDelta = _shareReservesDelta.mulDivDown( - _closeSharePrice, - _openSharePrice + _closeVaultSharePrice, + _openVaultSharePrice ); // NOTE: Using unscaled `shareCurveDelta`. shareAdjustmentDelta = int256(_shareReservesDelta) - int256(_shareCurveDelta); _shareCurveDelta = _shareCurveDelta.mulDivDown( - _closeSharePrice, - _openSharePrice + _closeVaultSharePrice, + _openVaultSharePrice ); _totalGovernanceFee = _totalGovernanceFee.mulDivDown( - _closeSharePrice, - _openSharePrice + _closeVaultSharePrice, + _openVaultSharePrice ); } else { shareAdjustmentDelta = diff --git a/contracts/src/libraries/LPMath.sol b/contracts/src/libraries/LPMath.sol index 50c094227..22bd49bfc 100644 --- a/contracts/src/libraries/LPMath.sol +++ b/contracts/src/libraries/LPMath.sol @@ -126,8 +126,8 @@ library LPMath { uint256 shareReserves; int256 shareAdjustment; uint256 bondReserves; - uint256 sharePrice; - uint256 initialSharePrice; + uint256 vaultSharePrice; + uint256 initialVaultSharePrice; uint256 minimumShareReserves; uint256 timeStretch; uint256 longsOutstanding; @@ -241,8 +241,8 @@ library LPMath { _params.bondReserves, _params.minimumShareReserves, ONE - _params.timeStretch, - _params.sharePrice, - _params.initialSharePrice + _params.vaultSharePrice, + _params.initialVaultSharePrice ); if (!success) { return (0, false); @@ -257,8 +257,8 @@ library LPMath { _params.bondReserves, netCurvePosition_, ONE - _params.timeStretch, - _params.sharePrice, - _params.initialSharePrice + _params.vaultSharePrice, + _params.initialVaultSharePrice ); return (-int256(netCurveTrade), true); } @@ -304,8 +304,8 @@ library LPMath { effectiveShareReserves, _params.bondReserves, ONE - _params.timeStretch, - _params.sharePrice, - _params.initialSharePrice + _params.vaultSharePrice, + _params.initialVaultSharePrice ); // If the max curve trade is greater than the net curve position, @@ -317,8 +317,8 @@ library LPMath { _params.bondReserves, netCurvePosition_, ONE - _params.timeStretch, - _params.sharePrice, - _params.initialSharePrice + _params.vaultSharePrice, + _params.initialVaultSharePrice ); return (int256(netCurveTrade), true); } @@ -331,14 +331,14 @@ library LPMath { effectiveShareReserves, _params.bondReserves, ONE - _params.timeStretch, - _params.sharePrice, - _params.initialSharePrice + _params.vaultSharePrice, + _params.initialVaultSharePrice ); return ( int256( maxSharePayment + (netCurvePosition_ - maxCurveTrade).divDown( - _params.sharePrice + _params.vaultSharePrice ) ), true @@ -368,13 +368,13 @@ library LPMath { int256( _params.shortsOutstanding.mulDivDown( ONE - _params.shortAverageTimeRemaining, - _params.sharePrice + _params.vaultSharePrice ) ) - int256( _params.longsOutstanding.mulDivDown( ONE - _params.longAverageTimeRemaining, - _params.sharePrice + _params.vaultSharePrice ) ); } @@ -615,8 +615,8 @@ library LPMath { _params.presentValueParams.bondReserves, _params.presentValueParams.minimumShareReserves, ONE - _params.presentValueParams.timeStretch, - _params.presentValueParams.sharePrice, - _params.presentValueParams.initialSharePrice + _params.presentValueParams.vaultSharePrice, + _params.presentValueParams.initialVaultSharePrice ); if (!success) { break; @@ -941,8 +941,8 @@ library LPMath { ), _params.presentValueParams.bondReserves, ONE - _params.presentValueParams.timeStretch, - _params.presentValueParams.sharePrice, - _params.presentValueParams.initialSharePrice + _params.presentValueParams.vaultSharePrice, + _params.presentValueParams.initialVaultSharePrice ); // If the maximum amount of bonds that can be purchased is greater @@ -982,8 +982,8 @@ library LPMath { ), _params.presentValueParams.bondReserves, ONE - _params.presentValueParams.timeStretch, - _params.presentValueParams.sharePrice, - _params.presentValueParams.initialSharePrice + _params.presentValueParams.vaultSharePrice, + _params.presentValueParams.initialVaultSharePrice ); // Calculate the derivative of `calculateMaxBuyBondsOut(x)` at the @@ -1101,8 +1101,8 @@ library LPMath { ), _params.presentValueParams.bondReserves, ONE - _params.presentValueParams.timeStretch, - _params.presentValueParams.sharePrice, - _params.presentValueParams.initialSharePrice + _params.presentValueParams.vaultSharePrice, + _params.presentValueParams.initialVaultSharePrice ); if (maxBondAmount >= netCurveTrade) { maxShareReservesDelta = maybeMaxShareReservesDelta; @@ -1148,12 +1148,12 @@ library LPMath { _originalEffectiveShareReserves, _params.originalBondReserves, ONE - _params.presentValueParams.timeStretch, - _params.presentValueParams.sharePrice, - _params.presentValueParams.initialSharePrice + _params.presentValueParams.vaultSharePrice, + _params.presentValueParams.initialVaultSharePrice ) .divUp( - _params.presentValueParams.sharePrice.divDown( - _params.presentValueParams.initialSharePrice + _params.presentValueParams.vaultSharePrice.divDown( + _params.presentValueParams.initialVaultSharePrice ) + ONE ); if (rhs >= ONE) { @@ -1244,10 +1244,10 @@ library LPMath { _params.presentValueParams.shareReserves, _params.presentValueParams.shareAdjustment ); - uint256 derivative = _params.presentValueParams.sharePrice.divUp( + uint256 derivative = _params.presentValueParams.vaultSharePrice.divUp( _params .presentValueParams - .initialSharePrice + .initialVaultSharePrice .mulDown(effectiveShareReserves) .pow(_params.presentValueParams.timeStretch) ) + @@ -1276,8 +1276,8 @@ library LPMath { effectiveShareReserves, _params.presentValueParams.bondReserves, ONE - _params.presentValueParams.timeStretch, - _params.presentValueParams.sharePrice, - _params.presentValueParams.initialSharePrice + _params.presentValueParams.vaultSharePrice, + _params.presentValueParams.initialVaultSharePrice ); uint256 inner = (_params.presentValueParams.bondReserves + _bondAmount) .pow(ONE - _params.presentValueParams.timeStretch); @@ -1286,9 +1286,9 @@ library LPMath { // idle since the derivative couldn't be computed. return (0, false); } - inner = _params.presentValueParams.initialSharePrice.mulDivUp( + inner = _params.presentValueParams.initialVaultSharePrice.mulDivUp( k - inner, - _params.presentValueParams.sharePrice + _params.presentValueParams.vaultSharePrice ); if (inner >= ONE) { // NOTE: Round the exponent up since this rounds the result up. @@ -1309,7 +1309,7 @@ library LPMath { // NOTE: Round up since this is on the rhs of the final subtraction. derivative = derivative.mulDivUp( inner, - _params.presentValueParams.sharePrice + _params.presentValueParams.vaultSharePrice ); // derivative = 1 - derivative @@ -1381,10 +1381,10 @@ library LPMath { _params.presentValueParams.shareReserves, _params.presentValueParams.shareAdjustment ); - uint256 derivative = _params.presentValueParams.sharePrice.divUp( + uint256 derivative = _params.presentValueParams.vaultSharePrice.divUp( _params .presentValueParams - .initialSharePrice + .initialVaultSharePrice .mulDown(effectiveShareReserves) .pow(_params.presentValueParams.timeStretch) ) + @@ -1413,8 +1413,8 @@ library LPMath { effectiveShareReserves, _params.presentValueParams.bondReserves, ONE - _params.presentValueParams.timeStretch, - _params.presentValueParams.sharePrice, - _params.presentValueParams.initialSharePrice + _params.presentValueParams.vaultSharePrice, + _params.presentValueParams.initialVaultSharePrice ); uint256 inner = (_params.presentValueParams.bondReserves - _bondAmount) .pow(ONE - _params.presentValueParams.timeStretch); @@ -1423,9 +1423,9 @@ library LPMath { // idle since the derivative couldn't be computed. return (0, false); } - inner = _params.presentValueParams.initialSharePrice.mulDivUp( + inner = _params.presentValueParams.initialVaultSharePrice.mulDivUp( k - inner, - _params.presentValueParams.sharePrice + _params.presentValueParams.vaultSharePrice ); if (inner >= 0) { // NOTE: Round the exponent up since this rounds the result up. @@ -1454,7 +1454,7 @@ library LPMath { // ) ** (t_s / (1 - t_s)) derivative = derivative.mulDivUp( inner, - _params.presentValueParams.sharePrice + _params.presentValueParams.vaultSharePrice ); // derivative = 1 - derivative @@ -1523,10 +1523,10 @@ library LPMath { _params.presentValueParams.shareReserves, _params.presentValueParams.shareAdjustment ); - uint256 derivative = _params.presentValueParams.sharePrice.divDown( + uint256 derivative = _params.presentValueParams.vaultSharePrice.divDown( _params .presentValueParams - .initialSharePrice + .initialVaultSharePrice .mulUp(effectiveShareReserves) .pow(_params.presentValueParams.timeStretch) ) + @@ -1545,8 +1545,8 @@ library LPMath { effectiveShareReserves, _params.presentValueParams.bondReserves, ONE - _params.presentValueParams.timeStretch, - _params.presentValueParams.sharePrice, - _params.presentValueParams.initialSharePrice + _params.presentValueParams.vaultSharePrice, + _params.presentValueParams.initialVaultSharePrice ); if (k >= ONE) { // NOTE: Round the exponent down since this rounds the result down. @@ -1574,8 +1574,8 @@ library LPMath { derivative = derivative.divDown( (// NOTE: Round up the divisor since this rounds the quotient // down. - _params.presentValueParams.sharePrice.divUp( - _params.presentValueParams.initialSharePrice + _params.presentValueParams.vaultSharePrice.divUp( + _params.presentValueParams.initialVaultSharePrice ) + ONE).pow( // NOTE: Round up the exponent since the base is greater // than 1 and rounding the divisor up rounds the diff --git a/contracts/src/libraries/YieldSpaceMath.sol b/contracts/src/libraries/YieldSpaceMath.sol index f23d6d086..2c8757390 100644 --- a/contracts/src/libraries/YieldSpaceMath.sol +++ b/contracts/src/libraries/YieldSpaceMath.sol @@ -38,8 +38,8 @@ library YieldSpaceMath { /// @param y The bond reserves. /// @param dz The amount of shares paid to the pool. /// @param t The time elapsed since the term's start. - /// @param c The share price. - /// @param mu The initial share price. + /// @param c The vault share price. + /// @param mu The initial vault share price. /// @return The amount of bonds the trader receives. function calculateBondsOutGivenSharesInDown( uint256 ze, @@ -84,8 +84,8 @@ library YieldSpaceMath { /// @param y The bond reserves. /// @param dy The amount of bonds paid to the trader. /// @param t The time elapsed since the term's start. - /// @param c The share price. - /// @param mu The initial share price. + /// @param c The vault share price. + /// @param mu The initial vault share price. /// @return The amount of shares the trader pays. function calculateSharesInGivenBondsOutUp( uint256 ze, @@ -128,8 +128,8 @@ library YieldSpaceMath { /// @param y The bond reserves. /// @param dy The amount of bonds paid to the trader. /// @param t The time elapsed since the term's start. - /// @param c The share price. - /// @param mu The initial share price. + /// @param c The vault share price. + /// @param mu The initial vault share price. /// @return The amount of shares the user pays. function calculateSharesInGivenBondsOutDown( uint256 ze, @@ -173,8 +173,8 @@ library YieldSpaceMath { /// @param y The bond reserves. /// @param dy The amount of bonds paid to the pool. /// @param t The time elapsed since the term's start. - /// @param c The share price. - /// @param mu The initial share price. + /// @param c The vault share price. + /// @param mu The initial vault share price. /// @return result The amount of shares the user receives. function calculateSharesOutGivenBondsInDown( uint256 ze, @@ -206,8 +206,8 @@ library YieldSpaceMath { /// @param y The bond reserves. /// @param dy The amount of bonds paid to the pool. /// @param t The time elapsed since the term's start. - /// @param c The share price. - /// @param mu The initial share price. + /// @param c The vault share price. + /// @param mu The initial vault share price. /// @return result The amount of shares the user receives /// @return success A flag indicating if the calculation succeeded. function calculateSharesOutGivenBondsInDownSafe( @@ -257,8 +257,8 @@ library YieldSpaceMath { /// @param ze The effective share reserves. /// @param y The bond reserves. /// @param t The time elapsed since the term's start. - /// @param c The share price. - /// @param mu The initial share price. + /// @param c The vault share price. + /// @param mu The initial vault share price. /// @return The share payment to purchase the maximum amount of bonds. function calculateMaxBuySharesIn( uint256 ze, @@ -298,8 +298,8 @@ library YieldSpaceMath { /// @param ze The effective share reserves. /// @param y The bond reserves. /// @param t The time elapsed since the term's start. - /// @param c The share price. - /// @param mu The initial share price. + /// @param c The vault share price. + /// @param mu The initial vault share price. /// @return The maximum amount of bonds that can be purchased. function calculateMaxBuyBondsOut( uint256 ze, @@ -334,8 +334,8 @@ library YieldSpaceMath { /// @param y The bond reserves. /// @param zMin The minimum share reserves. /// @param t The time elapsed since the term's start. - /// @param c The share price. - /// @param mu The initial share price. + /// @param c The vault share price. + /// @param mu The initial vault share price. /// @return The maximum amount of bonds that can be sold. /// @return A flag indicating whether or not the calculation was successful. function calculateMaxSellBondsInSafe( @@ -391,8 +391,8 @@ library YieldSpaceMath { /// @param ze The effective share reserves. /// @param y The bond reserves. /// @param t The time elapsed since the term's start. - /// @param c The share price. - /// @param mu The initial share price. + /// @param c The vault share price. + /// @param mu The initial vault share price. /// @return The YieldSpace invariant, k. function kUp( uint256 ze, @@ -413,8 +413,8 @@ library YieldSpaceMath { /// @param ze The effective share reserves. /// @param y The bond reserves. /// @param t The time elapsed since the term's start. - /// @param c The share price. - /// @param mu The initial share price. + /// @param c The vault share price. + /// @param mu The initial vault share price. /// @return The modified YieldSpace Constant. function kDown( uint256 ze, diff --git a/contracts/test/EtchingVault.sol b/contracts/test/EtchingVault.sol index 4203ea165..d5cd2c692 100644 --- a/contracts/test/EtchingVault.sol +++ b/contracts/test/EtchingVault.sol @@ -11,11 +11,11 @@ pragma solidity 0.8.19; /// particular legal or regulatory significance. contract EtchingVault { address internal immutable _baseToken; - uint256 internal immutable _sharePrice; + uint256 internal immutable _vaultSharePrice; - constructor(address _baseToken_, uint256 _sharePrice_) { + constructor(address _baseToken_, uint256 _vaultSharePrice_) { _baseToken = _baseToken_; - _sharePrice = _sharePrice_; + _vaultSharePrice = _vaultSharePrice_; } function asset() external view returns (address) { @@ -23,6 +23,6 @@ contract EtchingVault { } function convertToAssets(uint256) external view returns (uint256) { - return _sharePrice; + return _vaultSharePrice; } } diff --git a/contracts/test/MockERC4626Hyperdrive.sol b/contracts/test/MockERC4626Hyperdrive.sol index ba484a0e6..e10beff89 100644 --- a/contracts/test/MockERC4626Hyperdrive.sol +++ b/contracts/test/MockERC4626Hyperdrive.sol @@ -29,7 +29,7 @@ contract MockERC4626Hyperdrive is ERC4626Hyperdrive { function deposit( uint256 _amount, IHyperdrive.Options calldata _options - ) public returns (uint256 sharesMinted, uint256 sharePrice) { + ) public returns (uint256 sharesMinted, uint256 vaultSharePrice) { return _deposit(_amount, _options); } @@ -42,8 +42,12 @@ contract MockERC4626Hyperdrive is ERC4626Hyperdrive { } /// @notice Loads the share price from the yield source - /// @return sharePrice The current share price. - function pricePerShare() public view returns (uint256 sharePrice) { - return _pricePerShare(); + /// @return vaultSharePrice The current share price. + function pricePerVaultShare() + public + view + returns (uint256 vaultSharePrice) + { + return _pricePerVaultShare(); } } diff --git a/contracts/test/MockHyperdrive.sol b/contracts/test/MockHyperdrive.sol index 7499fd2d0..ca978d29c 100644 --- a/contracts/test/MockHyperdrive.sol +++ b/contracts/test/MockHyperdrive.sol @@ -80,12 +80,12 @@ abstract contract MockHyperdriveBase is HyperdriveBase { // Increase the total shares and return with the amount of shares minted // and the current share price. if (totalShares == 0) { - totalShares = amount.divDown(_initialSharePrice); - return (totalShares, _initialSharePrice); + totalShares = amount.divDown(_initialVaultSharePrice); + return (totalShares, _initialVaultSharePrice); } else { uint256 newShares = amount.mulDivDown(totalShares, assets); totalShares += newShares; - return (newShares, _pricePerShare()); + return (newShares, _pricePerVaultShare()); } } @@ -132,16 +132,16 @@ abstract contract MockHyperdriveBase is HyperdriveBase { } withdrawValue = options.asBase ? withdrawValue - : withdrawValue.divDown(_pricePerShare()); + : withdrawValue.divDown(_pricePerVaultShare()); return withdrawValue; } - function _pricePerShare() + function _pricePerVaultShare() internal view override - returns (uint256 sharePrice) + returns (uint256 vaultSharePrice) { // Get the total amount of base held in Hyperdrive. uint256 assets; @@ -153,7 +153,7 @@ abstract contract MockHyperdriveBase is HyperdriveBase { // The share price is the total amount of base divided by the total // amount of shares. - sharePrice = totalShares != 0 ? assets.divDown(totalShares) : 0; + vaultSharePrice = totalShares != 0 ? assets.divDown(totalShares) : 0; } // This overrides checkMessageValue to serve the dual purpose of making @@ -218,12 +218,12 @@ contract MockHyperdrive is Hyperdrive, MockHyperdriveBase { function calculateFeesGivenShares( uint256 _shareAmount, uint256 _spotPrice, - uint256 sharePrice + uint256 vaultSharePrice ) external view returns (uint256 curveFee, uint256 governanceCurveFee) { (curveFee, governanceCurveFee) = _calculateFeesGivenShares( _shareAmount, _spotPrice, - sharePrice + vaultSharePrice ); return (curveFee, governanceCurveFee); } @@ -232,7 +232,7 @@ contract MockHyperdrive is Hyperdrive, MockHyperdriveBase { uint256 _bondAmount, uint256 _normalizedTimeRemaining, uint256 _spotPrice, - uint256 sharePrice + uint256 vaultSharePrice ) external view @@ -252,7 +252,7 @@ contract MockHyperdrive is Hyperdrive, MockHyperdriveBase { _bondAmount, _normalizedTimeRemaining, _spotPrice, - sharePrice + vaultSharePrice ); return ( totalCurveFee, @@ -265,7 +265,7 @@ contract MockHyperdrive is Hyperdrive, MockHyperdriveBase { // Calls Hyperdrive._calculateOpenLong function calculateOpenLong( uint256 _shareAmount, - uint256 _sharePrice + uint256 _vaultSharePrice ) external view @@ -276,7 +276,7 @@ contract MockHyperdrive is Hyperdrive, MockHyperdriveBase { uint256 totalGovernanceFee ) { - return _calculateOpenLong(_shareAmount, _sharePrice); + return _calculateOpenLong(_shareAmount, _vaultSharePrice); } function calculateTimeRemaining( @@ -300,9 +300,9 @@ contract MockHyperdrive is Hyperdrive, MockHyperdriveBase { } function calculateIdleShareReserves( - uint256 _sharePrice + uint256 _vaultSharePrice ) external view returns (uint256) { - return _calculateIdleShareReserves(_sharePrice); + return _calculateIdleShareReserves(_vaultSharePrice); } function getTotalShares() external view returns (uint256) { diff --git a/contracts/test/MockHyperdriveDeployer.sol b/contracts/test/MockHyperdriveDeployer.sol index a49828d07..956a3f8aa 100644 --- a/contracts/test/MockHyperdriveDeployer.sol +++ b/contracts/test/MockHyperdriveDeployer.sol @@ -27,7 +27,7 @@ contract MockHyperdriveDeployer is IHyperdriveDeployer { _config.feeCollector = _deployConfig.feeCollector; _config.fees = _deployConfig.fees; - _config.initialSharePrice = 1e18; // TODO: Make setter + _config.initialVaultSharePrice = 1e18; // TODO: Make setter return (address(new MockHyperdrive(_config))); } diff --git a/contracts/test/MockHyperdriveMath.sol b/contracts/test/MockHyperdriveMath.sol index a56e10f01..d5c7aeeb8 100644 --- a/contracts/test/MockHyperdriveMath.sol +++ b/contracts/test/MockHyperdriveMath.sol @@ -8,14 +8,14 @@ contract MockHyperdriveMath { function calculateSpotAPR( uint256 _effectiveShareReserves, uint256 _bondReserves, - uint256 _initialSharePrice, + uint256 _initialVaultSharePrice, uint256 _positionDuration, uint256 _timeStretch ) external pure returns (uint256) { uint256 result = HyperdriveMath.calculateSpotAPR( _effectiveShareReserves, _bondReserves, - _initialSharePrice, + _initialVaultSharePrice, _positionDuration, _timeStretch ); @@ -24,14 +24,14 @@ contract MockHyperdriveMath { function calculateInitialBondReserves( uint256 _effectiveShareReserves, - uint256 _initialSharePrice, + uint256 _initialVaultSharePrice, uint256 _apr, uint256 _positionDuration, uint256 _timeStretch ) external pure returns (uint256) { uint256 result = HyperdriveMath.calculateInitialBondReserves( _effectiveShareReserves, - _initialSharePrice, + _initialVaultSharePrice, _apr, _positionDuration, _timeStretch @@ -44,16 +44,16 @@ contract MockHyperdriveMath { uint256 _bondReserves, uint256 _amountIn, uint256 _timeStretch, - uint256 _sharePrice, - uint256 _initialSharePrice + uint256 _vaultSharePrice, + uint256 _initialVaultSharePrice ) external pure returns (uint256) { uint256 result = HyperdriveMath.calculateOpenLong( _effectiveShareReserves, _bondReserves, _amountIn, _timeStretch, - _sharePrice, - _initialSharePrice + _vaultSharePrice, + _initialVaultSharePrice ); return result; } @@ -64,8 +64,8 @@ contract MockHyperdriveMath { uint256 _amountIn, uint256 _normalizedTimeRemaining, uint256 _timeStretch, - uint256 _sharePrice, - uint256 _initialSharePrice + uint256 _vaultSharePrice, + uint256 _initialVaultSharePrice ) external pure returns (uint256, uint256, uint256) { (uint256 result1, uint256 result2, uint256 result3) = HyperdriveMath .calculateCloseLong( @@ -74,8 +74,8 @@ contract MockHyperdriveMath { _amountIn, _normalizedTimeRemaining, _timeStretch, - _sharePrice, - _initialSharePrice + _vaultSharePrice, + _initialVaultSharePrice ); return (result1, result2, result3); } @@ -85,16 +85,16 @@ contract MockHyperdriveMath { uint256 _bondReserves, uint256 _amountIn, uint256 _timeStretch, - uint256 _sharePrice, - uint256 _initialSharePrice + uint256 _vaultSharePrice, + uint256 _initialVaultSharePrice ) external pure returns (uint256) { uint256 result = HyperdriveMath.calculateOpenShort( _effectiveShareReserves, _bondReserves, _amountIn, _timeStretch, - _sharePrice, - _initialSharePrice + _vaultSharePrice, + _initialVaultSharePrice ); return result; } @@ -105,8 +105,8 @@ contract MockHyperdriveMath { uint256 _amountOut, uint256 _normalizedTimeRemaining, uint256 _timeStretch, - uint256 _sharePrice, - uint256 _initialSharePrice + uint256 _vaultSharePrice, + uint256 _initialVaultSharePrice ) external pure returns (uint256, uint256, uint256) { (uint256 result1, uint256 result2, uint256 result3) = HyperdriveMath .calculateCloseShort( @@ -115,8 +115,8 @@ contract MockHyperdriveMath { _amountOut, _normalizedTimeRemaining, _timeStretch, - _sharePrice, - _initialSharePrice + _vaultSharePrice, + _initialVaultSharePrice ); return (result1, result2, result3); } @@ -134,8 +134,8 @@ contract MockHyperdriveMath { uint256 _shareReservesDelta, uint256 _shareCurveDelta, uint256 _totalGovernanceFee, - uint256 _openSharePrice, - uint256 _closeSharePrice, + uint256 _openVaultSharePrice, + uint256 _closeVaultSharePrice, bool _isLong ) external pure returns (uint256, uint256, uint256, int256, uint256) { NegativeInterestOnCloseOutput memory output; @@ -150,8 +150,8 @@ contract MockHyperdriveMath { _shareReservesDelta, _shareCurveDelta, _totalGovernanceFee, - _openSharePrice, - _closeSharePrice, + _openVaultSharePrice, + _closeVaultSharePrice, _isLong ); return ( @@ -217,13 +217,13 @@ contract MockHyperdriveMath { function calculateSpotPrice( uint256 _shareReserves, uint256 _bondReserves, - uint256 _initialSharePrice, + uint256 _initialVaultSharePrice, uint256 _timeStretch ) external pure returns (uint256) { uint256 result = HyperdriveMath.calculateSpotPrice( _shareReserves, _bondReserves, - _initialSharePrice, + _initialVaultSharePrice, _timeStretch ); return result; @@ -232,17 +232,17 @@ contract MockHyperdriveMath { function calculateShortProceeds( uint256 _bondAmount, uint256 _shareAmount, - uint256 _openSharePrice, - uint256 _closeSharePrice, - uint256 _sharePrice, + uint256 _openVaultSharePrice, + uint256 _closeVaultSharePrice, + uint256 _vaultSharePrice, uint256 _flatFee ) external pure returns (uint256) { uint256 result = HyperdriveMath.calculateShortProceeds( _bondAmount, _shareAmount, - _openSharePrice, - _closeSharePrice, - _sharePrice, + _openVaultSharePrice, + _closeVaultSharePrice, + _vaultSharePrice, _flatFee ); return result; diff --git a/contracts/test/MockMultiToken.sol b/contracts/test/MockMultiToken.sol index 5f5cfc7cd..703a68622 100644 --- a/contracts/test/MockMultiToken.sol +++ b/contracts/test/MockMultiToken.sol @@ -52,7 +52,7 @@ contract MockMultiToken is HyperdriveMultiToken, MockHyperdriveBase { baseToken: IERC20(address(0)), linkerFactory: _linkerFactory, linkerCodeHash: _linkerCodeHash, - initialSharePrice: 1e18, + initialVaultSharePrice: 1e18, minimumShareReserves: 1e18, minimumTransactionAmount: 1e15, positionDuration: 365 days, @@ -79,7 +79,7 @@ contract MockMultiToken is HyperdriveMultiToken, MockHyperdriveBase { baseToken: IERC20(address(0)), linkerFactory: _linkerFactory, linkerCodeHash: _linkerCodeHash, - initialSharePrice: 1e18, + initialVaultSharePrice: 1e18, minimumShareReserves: 1e18, minimumTransactionAmount: 1e15, positionDuration: 365 days, diff --git a/crates/hyperdrive-math/src/lib.rs b/crates/hyperdrive-math/src/lib.rs index 462a44de0..b53acf622 100644 --- a/crates/hyperdrive-math/src/lib.rs +++ b/crates/hyperdrive-math/src/lib.rs @@ -39,7 +39,7 @@ impl Distribution for Standard { governance_lp: rng.gen_range(fixed!(0.0001e18)..=fixed!(0.2e18)).into(), governance_zombie: rng.gen_range(fixed!(0.0001e18)..=fixed!(0.2e18)).into(), }, - initial_share_price: rng.gen_range(fixed!(0.5e18)..=fixed!(2.5e18)).into(), + initial_vault_share_price: rng.gen_range(fixed!(0.5e18)..=fixed!(2.5e18)).into(), minimum_share_reserves: rng.gen_range(fixed!(0.1e18)..=fixed!(1e18)).into(), minimum_transaction_amount: rng.gen_range(fixed!(0.1e18)..=fixed!(1e18)).into(), time_stretch: rng.gen_range(fixed!(0.005e18)..=fixed!(0.5e18)).into(), @@ -61,11 +61,11 @@ impl Distribution for Standard { zombie_share_reserves: fixed!(0).into(), bond_reserves: rng .gen_range( - share_reserves * FixedPoint::from(config.initial_share_price) + share_reserves * FixedPoint::from(config.initial_vault_share_price) ..=fixed!(1_000_000_000e18), ) .into(), - share_price: rng.gen_range(fixed!(0.5e18)..=fixed!(2.5e18)).into(), + vault_share_price: rng.gen_range(fixed!(0.5e18)..=fixed!(2.5e18)).into(), longs_outstanding: rng.gen_range(fixed!(0)..=fixed!(100_000e18)).into(), shorts_outstanding: rng.gen_range(fixed!(0)..=fixed!(100_000e18)).into(), long_exposure: rng.gen_range(fixed!(0)..=fixed!(100_000e18)).into(), @@ -153,8 +153,8 @@ impl State { self.config.time_stretch.into() } - fn initial_share_price(&self) -> FixedPoint { - self.config.initial_share_price.into() + fn initial_vault_share_price(&self) -> FixedPoint { + self.config.initial_vault_share_price.into() } fn minimum_share_reserves(&self) -> FixedPoint { @@ -175,8 +175,8 @@ impl State { /// Info /// - fn share_price(&self) -> FixedPoint { - self.info.share_price.into() + fn vault_share_price(&self) -> FixedPoint { + self.info.vault_share_price.into() } fn share_reserves(&self) -> FixedPoint { @@ -230,11 +230,11 @@ impl YieldSpace for State { } fn mu(&self) -> FixedPoint { - self.initial_share_price() + self.initial_vault_share_price() } fn c(&self) -> FixedPoint { - self.share_price() + self.vault_share_price() } fn t(&self) -> FixedPoint { diff --git a/crates/hyperdrive-math/src/long/close.rs b/crates/hyperdrive-math/src/long/close.rs index a5a071fbf..4119ae69a 100644 --- a/crates/hyperdrive-math/src/long/close.rs +++ b/crates/hyperdrive-math/src/long/close.rs @@ -13,8 +13,10 @@ impl State { let normalized_time_remaining = normalized_time_remaining.into(); // Calculate the flat part of the trade - let flat = - bond_amount.mul_div_down(fixed!(1e18) - normalized_time_remaining, self.share_price()); + let flat = bond_amount.mul_div_down( + fixed!(1e18) - normalized_time_remaining, + self.vault_share_price(), + ); // Calculate the curve part of the trade let curve = if normalized_time_remaining > fixed!(0) { diff --git a/crates/hyperdrive-math/src/long/fees.rs b/crates/hyperdrive-math/src/long/fees.rs index c5b66b870..2db0bd60b 100644 --- a/crates/hyperdrive-math/src/long/fees.rs +++ b/crates/hyperdrive-math/src/long/fees.rs @@ -39,7 +39,7 @@ impl State { // ((1 - p) * phi_curve * d_y * t) / c self.curve_fee() * (fixed!(1e18) - self.get_spot_price()) - * bond_amount.mul_div_down(normalized_time_remaining, self.share_price()) + * bond_amount.mul_div_down(normalized_time_remaining, self.vault_share_price()) } /// Gets the flat fee paid by longs for a given bond amount @@ -50,7 +50,9 @@ impl State { normalized_time_remaining: FixedPoint, ) -> FixedPoint { // flat fee = (d_y * (1 - t) * phi_flat) / c - bond_amount.mul_div_down(fixed!(1e18) - normalized_time_remaining, self.share_price()) - * self.flat_fee() + bond_amount.mul_div_down( + fixed!(1e18) - normalized_time_remaining, + self.vault_share_price(), + ) * self.flat_fee() } } diff --git a/crates/hyperdrive-math/src/long/max.rs b/crates/hyperdrive-math/src/long/max.rs index 156adfd02..e166a8b5c 100644 --- a/crates/hyperdrive-math/src/long/max.rs +++ b/crates/hyperdrive-math/src/long/max.rs @@ -26,7 +26,7 @@ impl State { /// Gets the pool's solvency. pub fn get_solvency(&self) -> FixedPoint { self.share_reserves() - - self.long_exposure() / self.share_price() + - self.long_exposure() / self.vault_share_price() - self.minimum_share_reserves() } @@ -173,7 +173,9 @@ impl State { // ) // ) ** (1 / (1 - t_s)) let inner = (self.k_down() - / (self.share_price().div_up(self.initial_share_price()) + / (self + .vault_share_price() + .div_up(self.initial_vault_share_price()) + ((fixed!(1e18) + self .curve_fee() @@ -182,7 +184,7 @@ impl State { .div_up(fixed!(1e18) - self.flat_fee())) .pow((fixed!(1e18) - self.time_stretch()) / (self.time_stretch())))) .pow(fixed!(1e18) / (fixed!(1e18) - self.time_stretch())); - let target_share_reserves = inner / self.initial_share_price(); + let target_share_reserves = inner / self.initial_vault_share_price(); // Now that we have the target share reserves, we can calculate the // target bond reserves using the formula: @@ -204,7 +206,7 @@ impl State { // // absoluteMaxBaseAmount = c * (z_t - z) let absolute_max_base_amount = - (target_share_reserves - self.effective_share_reserves()) * self.share_price(); + (target_share_reserves - self.effective_share_reserves()) * self.vault_share_price(); // The absolute max bond amount is given by: // @@ -287,8 +289,8 @@ impl State { checkpoint_exposure: I256, ) -> FixedPoint { let checkpoint_exposure = FixedPoint::from(-checkpoint_exposure.min(int256!(0))); - let mut estimate = self.get_solvency() + checkpoint_exposure / self.share_price(); - estimate = estimate.mul_div_down(self.share_price(), fixed!(2e18)); + let mut estimate = self.get_solvency() + checkpoint_exposure / self.vault_share_price(); + estimate = estimate.mul_div_down(self.vault_share_price(), fixed!(2e18)); estimate /= fixed!(1e18) / estimate_price + self.governance_lp_fee() * self.curve_fee() * (fixed!(1e18) - spot_price) - fixed!(1e18) @@ -338,16 +340,16 @@ impl State { checkpoint_exposure: I256, ) -> Option { let governance_fee = self.open_long_governance_fee(base_amount); - let share_reserves = self.share_reserves() + base_amount / self.share_price() - - governance_fee / self.share_price(); + let share_reserves = self.share_reserves() + base_amount / self.vault_share_price() + - governance_fee / self.vault_share_price(); let exposure = self.long_exposure() + bond_amount; let checkpoint_exposure = FixedPoint::from(-checkpoint_exposure.min(int256!(0))); - if share_reserves + checkpoint_exposure / self.share_price() - >= exposure / self.share_price() + self.minimum_share_reserves() + if share_reserves + checkpoint_exposure / self.vault_share_price() + >= exposure / self.vault_share_price() + self.minimum_share_reserves() { Some( - share_reserves + checkpoint_exposure / self.share_price() - - exposure / self.share_price() + share_reserves + checkpoint_exposure / self.vault_share_price() + - exposure / self.vault_share_price() - self.minimum_share_reserves(), ) } else { @@ -379,7 +381,7 @@ impl State { * self.curve_fee() * (fixed!(1e18) - self.get_spot_price()) - fixed!(1e18)) - .mul_div_down(fixed!(1e18), self.share_price()) + .mul_div_down(fixed!(1e18), self.vault_share_price()) }) } @@ -411,17 +413,19 @@ impl State { /// c'(x) = \phi_{c} \cdot \left( \tfrac{1}{p} - 1 \right) /// $$ fn long_amount_derivative(&self, base_amount: FixedPoint) -> Option { - let share_amount = base_amount / self.share_price(); - let inner = self.initial_share_price() * (self.effective_share_reserves() + share_amount); + let share_amount = base_amount / self.vault_share_price(); + let inner = + self.initial_vault_share_price() * (self.effective_share_reserves() + share_amount); let mut derivative = fixed!(1e18) / (inner).pow(self.time_stretch()); // It's possible that k is slightly larger than the rhs in the inner // calculation. If this happens, we are close to the root, and we short // circuit. let k = self.k_down(); - let rhs = self - .share_price() - .mul_div_down(inner.pow(self.time_stretch()), self.initial_share_price()); + let rhs = self.vault_share_price().mul_div_down( + inner.pow(self.time_stretch()), + self.initial_vault_share_price(), + ); if k < rhs { return None; } @@ -477,8 +481,8 @@ mod tests { long_exposure: state.info.long_exposure, share_adjustment: state.info.share_adjustment, time_stretch: state.config.time_stretch, - share_price: state.info.share_price, - initial_share_price: state.config.initial_share_price, + vault_share_price: state.info.vault_share_price, + initial_vault_share_price: state.config.initial_vault_share_price, minimum_share_reserves: state.config.minimum_share_reserves, curve_fee: state.config.fees.curve, flat_fee: state.config.fees.flat, @@ -541,8 +545,8 @@ mod tests { long_exposure: state.info.long_exposure, share_adjustment: state.info.share_adjustment, time_stretch: state.config.time_stretch, - share_price: state.info.share_price, - initial_share_price: state.config.initial_share_price, + vault_share_price: state.info.vault_share_price, + initial_vault_share_price: state.config.initial_vault_share_price, minimum_share_reserves: state.config.minimum_share_reserves, curve_fee: state.config.fees.curve, flat_fee: state.config.fees.flat, diff --git a/crates/hyperdrive-math/src/long/open.rs b/crates/hyperdrive-math/src/long/open.rs index 984671d19..3c1ab4775 100644 --- a/crates/hyperdrive-math/src/long/open.rs +++ b/crates/hyperdrive-math/src/long/open.rs @@ -25,7 +25,7 @@ impl State { pub fn calculate_open_long>(&self, base_amount: F) -> FixedPoint { let base_amount = base_amount.into(); let long_amount = - self.calculate_bonds_out_given_shares_in_down(base_amount / self.share_price()); + self.calculate_bonds_out_given_shares_in_down(base_amount / self.vault_share_price()); long_amount - self.open_long_curve_fees(base_amount) } @@ -39,9 +39,9 @@ impl State { pub fn get_spot_price_after_long(&self, long_amount: FixedPoint) -> FixedPoint { let mut state: State = self.clone(); state.info.bond_reserves -= state - .calculate_bonds_out_given_shares_in_down(long_amount / state.share_price()) + .calculate_bonds_out_given_shares_in_down(long_amount / state.vault_share_price()) .into(); - state.info.share_reserves += (long_amount / state.share_price()).into(); + state.info.share_reserves += (long_amount / state.vault_share_price()).into(); state.get_spot_price() } } diff --git a/crates/hyperdrive-math/src/lp.rs b/crates/hyperdrive-math/src/lp.rs index 67ea98fe2..465016614 100644 --- a/crates/hyperdrive-math/src/lp.rs +++ b/crates/hyperdrive-math/src/lp.rs @@ -80,7 +80,8 @@ impl State { let max_share_payment = self.calculate_max_buy_shares_in(); I256::from( max_share_payment - + (_net_curve_position - max_curve_trade).div_down(self.share_price()), + + (_net_curve_position - max_curve_trade) + .div_down(self.vault_share_price()), ) } } @@ -97,10 +98,10 @@ impl State { // apply this net to the reserves. I256::from(self.shorts_outstanding().mul_div_down( fixed!(1e18) - short_average_time_remaining, - self.share_price(), + self.vault_share_price(), )) - I256::from(self.longs_outstanding().mul_div_down( fixed!(1e18) - long_average_time_remaining, - self.share_price(), + self.vault_share_price(), )) } } @@ -136,8 +137,8 @@ mod tests { longs_outstanding: state.info.longs_outstanding, share_adjustment: state.info.share_adjustment, time_stretch: state.config.time_stretch, - share_price: state.info.share_price, - initial_share_price: state.config.initial_share_price, + vault_share_price: state.info.vault_share_price, + initial_vault_share_price: state.config.initial_vault_share_price, minimum_share_reserves: state.config.minimum_share_reserves, long_average_time_remaining: state .time_remaining_scaled( @@ -197,8 +198,8 @@ mod tests { longs_outstanding: state.info.longs_outstanding, share_adjustment: state.info.share_adjustment, time_stretch: state.config.time_stretch, - share_price: state.info.share_price, - initial_share_price: state.config.initial_share_price, + vault_share_price: state.info.vault_share_price, + initial_vault_share_price: state.config.initial_vault_share_price, minimum_share_reserves: state.config.minimum_share_reserves, long_average_time_remaining: long_average_time_remaining.into(), short_average_time_remaining: short_average_time_remaining.into(), @@ -248,8 +249,8 @@ mod tests { longs_outstanding: state.info.longs_outstanding, share_adjustment: state.info.share_adjustment, time_stretch: state.config.time_stretch, - share_price: state.info.share_price, - initial_share_price: state.config.initial_share_price, + vault_share_price: state.info.vault_share_price, + initial_vault_share_price: state.config.initial_vault_share_price, minimum_share_reserves: state.config.minimum_share_reserves, long_average_time_remaining: long_average_time_remaining.into(), short_average_time_remaining: short_average_time_remaining.into(), diff --git a/crates/hyperdrive-math/src/short/close.rs b/crates/hyperdrive-math/src/short/close.rs index c27623fd0..ff9545476 100644 --- a/crates/hyperdrive-math/src/short/close.rs +++ b/crates/hyperdrive-math/src/short/close.rs @@ -13,8 +13,10 @@ impl State { let normalized_time_remaining = normalized_time_remaining.into(); // Calculate the flat part of the trade - let flat = - bond_amount.mul_div_down(fixed!(1e18) - normalized_time_remaining, self.share_price()); + let flat = bond_amount.mul_div_down( + fixed!(1e18) - normalized_time_remaining, + self.vault_share_price(), + ); // Calculate the curve part of the trade let curve = if normalized_time_remaining > fixed!(0) { @@ -32,19 +34,19 @@ impl State { &self, bond_amount: FixedPoint, share_amount: FixedPoint, - open_share_price: FixedPoint, - close_share_price: FixedPoint, - share_price: FixedPoint, + open_vault_share_price: FixedPoint, + close_vault_share_price: FixedPoint, + vault_share_price: FixedPoint, flat_fee: FixedPoint, ) -> FixedPoint { let mut bond_factor = bond_amount .mul_div_down( - close_share_price, + close_vault_share_price, // We round up here do avoid overestimating the share proceeds. - open_share_price, + open_vault_share_price, ) - .div_down(share_price); - bond_factor += bond_amount.mul_div_down(flat_fee, share_price); + .div_down(vault_share_price); + bond_factor += bond_amount.mul_div_down(flat_fee, vault_share_price); if bond_factor > share_amount { // proceeds = (c1 / c0 * c) * dy - dz @@ -58,13 +60,13 @@ impl State { pub fn calculate_close_short>( &self, bond_amount: F, - open_share_price: F, - close_share_price: F, + open_vault_share_price: F, + close_vault_share_price: F, normalized_time_remaining: F, ) -> FixedPoint { let bond_amount = bond_amount.into(); - let open_share_price = open_share_price.into(); - let close_share_price = close_share_price.into(); + let open_vault_share_price = open_vault_share_price.into(); + let close_vault_share_price = close_vault_share_price.into(); let normalized_time_remaining = normalized_time_remaining.into(); // Calculate flat + curve and subtract the fees from the trade. @@ -77,9 +79,9 @@ impl State { self.calculate_short_proceeds( bond_amount, share_reserves_delta, - open_share_price, - close_share_price, - self.share_price(), + open_vault_share_price, + close_vault_share_price, + self.vault_share_price(), self.flat_fee(), ) } @@ -107,14 +109,14 @@ mod tests { let state = rng.gen::(); let bond_amount = rng.gen_range(fixed!(0)..=state.bond_reserves()); let share_amount = rng.gen_range(fixed!(0)..=bond_amount); - let open_share_price = rng.gen_range(fixed!(0)..=state.share_price()); + let open_vault_share_price = rng.gen_range(fixed!(0)..=state.vault_share_price()); let actual = panic::catch_unwind(|| { state.calculate_short_proceeds( bond_amount, share_amount, - open_share_price, - state.share_price(), - state.share_price(), + open_vault_share_price, + state.vault_share_price(), + state.vault_share_price(), state.flat_fee(), ) }); @@ -122,9 +124,9 @@ mod tests { .calculate_short_proceeds( bond_amount.into(), share_amount.into(), - open_share_price.into(), - state.share_price().into(), - state.share_price().into(), + open_vault_share_price.into(), + state.vault_share_price().into(), + state.vault_share_price().into(), state.flat_fee().into(), ) .call() diff --git a/crates/hyperdrive-math/src/short/fees.rs b/crates/hyperdrive-math/src/short/fees.rs index 05e18364c..1ccd9716d 100644 --- a/crates/hyperdrive-math/src/short/fees.rs +++ b/crates/hyperdrive-math/src/short/fees.rs @@ -32,7 +32,7 @@ impl State { // ((1 - p) * phi_curve * d_y * t) / c self.curve_fee() * (fixed!(1e18) - self.get_spot_price()) - * bond_amount.mul_div_down(normalized_time_remaining, self.share_price()) + * bond_amount.mul_div_down(normalized_time_remaining, self.vault_share_price()) } /// Gets the flat fee paid by shorts for a given bond amount @@ -43,7 +43,9 @@ impl State { normalized_time_remaining: FixedPoint, ) -> FixedPoint { // flat fee = (d_y * (1 - t) * phi_flat) / c - bond_amount.mul_div_down(fixed!(1e18) - normalized_time_remaining, self.share_price()) - * self.flat_fee() + bond_amount.mul_div_down( + fixed!(1e18) - normalized_time_remaining, + self.vault_share_price(), + ) * self.flat_fee() } } diff --git a/crates/hyperdrive-math/src/short/max.rs b/crates/hyperdrive-math/src/short/max.rs index 26afb1fae..a8889f6c9 100644 --- a/crates/hyperdrive-math/src/short/max.rs +++ b/crates/hyperdrive-math/src/short/max.rs @@ -27,11 +27,11 @@ impl State { /// $$ pub fn get_min_price(&self) -> FixedPoint { let y_max = (self.k_up() - - (self.share_price() / self.initial_share_price()) - * (self.initial_share_price() * self.minimum_share_reserves()) + - (self.vault_share_price() / self.initial_vault_share_price()) + * (self.initial_vault_share_price() * self.minimum_share_reserves()) .pow(fixed!(1e18) - self.time_stretch())) .pow(fixed!(1e18).div_up(fixed!(1e18) - self.time_stretch())); - ((self.initial_share_price() * self.minimum_share_reserves()) / y_max) + ((self.initial_vault_share_price() * self.minimum_share_reserves()) / y_max) .pow(self.time_stretch()) } @@ -51,13 +51,13 @@ impl State { pub fn get_max_short, F2: Into, I: Into>( &self, budget: F1, - open_share_price: F2, + open_vault_share_price: F2, checkpoint_exposure: I, maybe_conservative_price: Option, // TODO: Is there a nice way of abstracting the inner type? maybe_max_iterations: Option, ) -> FixedPoint { let budget = budget.into(); - let open_share_price = open_share_price.into(); + let open_vault_share_price = open_vault_share_price.into(); let checkpoint_exposure = checkpoint_exposure.into(); // If the budget is zero, then we return early. @@ -69,10 +69,10 @@ impl State { // is zero, then we'll use the current share price since the checkpoint // hasn't been minted yet. let spot_price = self.get_spot_price(); - let open_share_price = if open_share_price != fixed!(0) { - open_share_price + let open_vault_share_price = if open_vault_share_price != fixed!(0) { + open_vault_share_price } else { - self.share_price() + self.vault_share_price() }; // Assuming the budget is infinite, find the largest possible short that @@ -80,11 +80,11 @@ impl State { // short amount. let mut max_bond_amount = self.absolute_max_short(spot_price, checkpoint_exposure, maybe_max_iterations); - let deposit = match self.calculate_open_short(max_bond_amount, spot_price, open_share_price) - { - Ok(d) => d, - Err(_) => return max_bond_amount, - }; + let deposit = + match self.calculate_open_short(max_bond_amount, spot_price, open_vault_share_price) { + Ok(d) => d, + Err(_) => return max_bond_amount, + }; if deposit <= budget { return max_bond_amount; } @@ -112,23 +112,30 @@ impl State { max_bond_amount = self.max_short_guess( budget, spot_price, - open_share_price, + open_vault_share_price, maybe_conservative_price, ); for _ in 0..maybe_max_iterations.unwrap_or(7) { - let deposit = - match self.calculate_open_short(max_bond_amount, spot_price, open_share_price) { - Ok(d) => d, - Err(_) => return max_bond_amount, - }; + let deposit = match self.calculate_open_short( + max_bond_amount, + spot_price, + open_vault_share_price, + ) { + Ok(d) => d, + Err(_) => return max_bond_amount, + }; max_bond_amount += (budget - deposit) - / self.short_deposit_derivative(max_bond_amount, spot_price, open_share_price); + / self.short_deposit_derivative( + max_bond_amount, + spot_price, + open_vault_share_price, + ); } // Verify that the max short satisfies the budget. if budget < self - .calculate_open_short(max_bond_amount, spot_price, open_share_price) + .calculate_open_short(max_bond_amount, spot_price, open_vault_share_price) .unwrap() { panic!("max short exceeded budget"); @@ -146,7 +153,7 @@ impl State { &self, budget: FixedPoint, spot_price: FixedPoint, - open_share_price: FixedPoint, + open_vault_share_price: FixedPoint, maybe_conservative_price: Option, ) -> FixedPoint { // If a conservative price is given, we can use it to solve for an @@ -173,11 +180,13 @@ impl State { // return it as our guess. Otherwise, we revert to the worst case // scenario. let guess = budget - / (self.share_price().div_up(open_share_price) + / (self.vault_share_price().div_up(open_vault_share_price) + self.flat_fee() + self.curve_fee() * (fixed!(1e18) - spot_price) - conservative_price); - if let Ok(deposit) = self.calculate_open_short(guess, spot_price, open_share_price) { + if let Ok(deposit) = + self.calculate_open_short(guess, spot_price, open_vault_share_price) + { if budget >= deposit { return guess; } @@ -195,7 +204,7 @@ impl State { // the max bond amount. If subtracting these components results in a // negative number, we just 0 as our initial guess. let worst_case_deposit = - match self.calculate_open_short(budget, spot_price, open_share_price) { + match self.calculate_open_short(budget, spot_price, open_vault_share_price) { Ok(d) => d, Err(_) => return fixed!(0), }; @@ -230,8 +239,8 @@ impl State { let optimal_effective_share_reserves = get_effective_share_reserves(optimal_share_reserves, self.share_adjustment()); let optimal_bond_reserves = (self.k_down() - - (self.share_price() / self.initial_share_price()) - * (self.initial_share_price() * optimal_effective_share_reserves) + - (self.vault_share_price() / self.initial_vault_share_price()) + * (self.initial_vault_share_price() * optimal_effective_share_reserves) .pow(fixed!(1e18) - self.time_stretch())) .pow(fixed!(1e18).div_up(fixed!(1e18) - self.time_stretch())); optimal_bond_reserves - self.bond_reserves() @@ -334,8 +343,8 @@ impl State { ) -> FixedPoint { let estimate_price = spot_price; let checkpoint_exposure = - FixedPoint::from(checkpoint_exposure.max(I256::zero())) / self.share_price(); - (self.share_price() * (self.get_solvency() + checkpoint_exposure)) + FixedPoint::from(checkpoint_exposure.max(I256::zero())) / self.vault_share_price(); + (self.vault_share_price() * (self.get_solvency() + checkpoint_exposure)) / (estimate_price - self.curve_fee() * (fixed!(1e18) - spot_price) + self.governance_lp_fee() * self.curve_fee() * (fixed!(1e18) - spot_price)) } @@ -357,7 +366,7 @@ impl State { &self, short_amount: FixedPoint, spot_price: FixedPoint, - open_share_price: FixedPoint, + open_vault_share_price: FixedPoint, ) -> FixedPoint { // NOTE: The order of additions and subtractions is important to avoid underflows. let payment_factor = (fixed!(1e18) @@ -365,7 +374,7 @@ impl State { * self .theta(short_amount) .pow(self.time_stretch() / (fixed!(1e18) + self.time_stretch())); - (self.share_price() / open_share_price) + (self.vault_share_price() / open_vault_share_price) + self.flat_fee() + self.curve_fee() * (fixed!(1e18) - spot_price) - payment_factor @@ -417,10 +426,10 @@ impl State { - (principal - (self.open_short_curve_fee(short_amount, spot_price) - self.open_short_governance_fee(short_amount, spot_price)) - / self.share_price()); + / self.vault_share_price()); let exposure = { let checkpoint_exposure: FixedPoint = checkpoint_exposure.max(I256::zero()).into(); - (self.long_exposure() - checkpoint_exposure) / self.share_price() + (self.long_exposure() - checkpoint_exposure) / self.vault_share_price() }; if share_reserves >= exposure + self.minimum_share_reserves() { Some(share_reserves - exposure - self.minimum_share_reserves()) @@ -453,7 +462,7 @@ impl State { let rhs = self.curve_fee() * (fixed!(1e18) - spot_price) * (fixed!(1e18) - self.governance_lp_fee()) - / self.share_price(); + / self.vault_share_price(); if lhs >= rhs { Some(lhs - rhs) } else { @@ -474,9 +483,9 @@ impl State { fn short_principal_derivative(&self, short_amount: FixedPoint) -> FixedPoint { let lhs = fixed!(1e18) / (self - .share_price() + .vault_share_price() .mul_up((self.bond_reserves() + short_amount).pow(self.time_stretch()))); - let rhs = ((self.initial_share_price() / self.share_price()) + let rhs = ((self.initial_vault_share_price() / self.vault_share_price()) * (self.k_down() - (self.bond_reserves() + short_amount).pow(fixed!(1e18) - self.time_stretch()))) .pow( @@ -496,7 +505,7 @@ impl State { /// \theta(x) = \tfrac{\mu}{c} \cdot (k - (y + x)^{1 - t_s}) /// $$ fn theta(&self, short_amount: FixedPoint) -> FixedPoint { - (self.initial_share_price() / self.share_price()) + (self.initial_vault_share_price() / self.vault_share_price()) * (self.k_down() - (self.bond_reserves() + short_amount).pow(fixed!(1e18) - self.time_stretch())) } @@ -563,8 +572,8 @@ mod tests { long_exposure: state.info.long_exposure, share_adjustment: state.info.share_adjustment, time_stretch: state.config.time_stretch, - share_price: state.info.share_price, - initial_share_price: state.config.initial_share_price, + vault_share_price: state.info.vault_share_price, + initial_vault_share_price: state.config.initial_vault_share_price, minimum_share_reserves: state.config.minimum_share_reserves, curve_fee: state.config.fees.curve, flat_fee: state.config.fees.flat, @@ -632,15 +641,20 @@ mod tests { // Get the current state of the pool. let state = alice.get_state().await?; let Checkpoint { - share_price: open_share_price, + vault_share_price: open_vault_share_price, } = alice .get_checkpoint(state.to_checkpoint(alice.now().await?)) .await?; let checkpoint_exposure = alice .get_checkpoint_exposure(state.to_checkpoint(alice.now().await?)) .await?; - let global_max_short = - state.get_max_short(U256::MAX, open_share_price, checkpoint_exposure, None, None); + let global_max_short = state.get_max_short( + U256::MAX, + open_vault_share_price, + checkpoint_exposure, + None, + None, + ); // Bob opens a max short position. We allow for a very small amount // of slippage to account for interest accrual between the time the diff --git a/crates/hyperdrive-math/src/short/open.rs b/crates/hyperdrive-math/src/short/open.rs index af9efe463..eec6f05f6 100644 --- a/crates/hyperdrive-math/src/short/open.rs +++ b/crates/hyperdrive-math/src/short/open.rs @@ -32,21 +32,21 @@ impl State { &self, short_amount: FixedPoint, spot_price: FixedPoint, - mut open_share_price: FixedPoint, + mut open_vault_share_price: FixedPoint, ) -> Result { // If the open share price hasn't been set, we use the current share // price, since this is what will be set as the checkpoint share price // in the next transaction. - if open_share_price == fixed!(0) { - open_share_price = self.share_price(); + if open_vault_share_price == fixed!(0) { + open_vault_share_price = self.vault_share_price(); } // NOTE: The order of additions and subtractions is important to avoid underflows. Ok( - short_amount.mul_div_down(self.share_price(), open_share_price) + short_amount.mul_div_down(self.vault_share_price(), open_vault_share_price) + self.flat_fee() * short_amount + self.curve_fee() * (fixed!(1e18) - spot_price) * short_amount - - self.share_price() * self.short_principal(short_amount)?, + - self.vault_share_price() * self.short_principal(short_amount)?, ) } @@ -55,9 +55,9 @@ impl State { &self, short_amount: FixedPoint, spot_price: FixedPoint, - open_share_price: FixedPoint, + open_vault_share_price: FixedPoint, ) -> Result { - self.calculate_open_short(short_amount, spot_price, open_share_price) + self.calculate_open_short(short_amount, spot_price, open_vault_share_price) } /// Gets the amount of short principal that the LPs need to pay to back a @@ -137,8 +137,8 @@ mod tests { long_exposure: state.info.long_exposure, share_adjustment: state.info.share_adjustment, time_stretch: state.config.time_stretch, - share_price: state.info.share_price, - initial_share_price: state.config.initial_share_price, + vault_share_price: state.info.vault_share_price, + initial_vault_share_price: state.config.initial_vault_share_price, minimum_share_reserves: state.config.minimum_share_reserves, curve_fee: state.config.fees.curve, flat_fee: state.config.fees.flat, diff --git a/crates/hyperdrive-math/src/utils.rs b/crates/hyperdrive-math/src/utils.rs index f55abf3d4..cd771c3ea 100644 --- a/crates/hyperdrive-math/src/utils.rs +++ b/crates/hyperdrive-math/src/utils.rs @@ -75,7 +75,7 @@ pub fn get_effective_share_reserves( /// * effective_share_reserves : The pool's effective share reserves. The /// effective share reserves are a modified version of the share /// reserves used when pricing trades. -/// * initial_share_price : The pool's initial share price. +/// * initial_vault_share_price : The pool's initial vault share price. /// * apr : The pool's APR. /// * position_duration : The amount of time until maturity in seconds. /// * time_stretch : The time stretch parameter. @@ -86,14 +86,14 @@ pub fn get_effective_share_reserves( /// the pool have a specified APR. pub fn calculate_initial_bond_reserves( effective_share_reserves: FixedPoint, - initial_share_price: FixedPoint, + initial_vault_share_price: FixedPoint, apr: FixedPoint, position_duration: FixedPoint, time_stretch: FixedPoint, ) -> FixedPoint { let annualized_time = position_duration / FixedPoint::from(U256::from(60 * 60 * 24 * 365)); // mu * (z - zeta) * (1 + apr * t) ** (1 / tau) - initial_share_price + initial_vault_share_price .mul_down(effective_share_reserves) .mul_down( (fixed!(1e18) + apr.mul_down(annualized_time)).pow(fixed!(1e18).div_up(time_stretch)), @@ -157,7 +157,7 @@ mod tests { // Calculate the bonds let actual = calculate_initial_bond_reserves( effective_share_reserves, - state.config.initial_share_price.into(), + state.config.initial_vault_share_price.into(), fixed!(0.01e18), state.config.position_duration.into(), state.config.time_stretch.into(), @@ -165,7 +165,7 @@ mod tests { match mock .calculate_initial_bond_reserves( effective_share_reserves.into(), - state.config.initial_share_price, + state.config.initial_vault_share_price, fixed!(0.01e18).into(), state.config.position_duration, state.config.time_stretch, diff --git a/crates/hyperdrive-math/src/yield_space.rs b/crates/hyperdrive-math/src/yield_space.rs index c30cb7418..72089e3fd 100644 --- a/crates/hyperdrive-math/src/yield_space.rs +++ b/crates/hyperdrive-math/src/yield_space.rs @@ -25,7 +25,7 @@ pub trait YieldSpace { /// The share price. fn c(&self) -> FixedPoint; - /// The initial share price. + /// The initial vault share price. fn mu(&self) -> FixedPoint; /// The YieldSpace time parameter. diff --git a/crates/hyperdrive-math/tests/integration_tests.rs b/crates/hyperdrive-math/tests/integration_tests.rs index f9ffe36bd..0415e999a 100644 --- a/crates/hyperdrive-math/tests/integration_tests.rs +++ b/crates/hyperdrive-math/tests/integration_tests.rs @@ -117,15 +117,20 @@ pub async fn test_integration_get_max_short() -> Result<()> { // of her budget. let state = alice.get_state().await?; let Checkpoint { - share_price: open_share_price, + vault_share_price: open_vault_share_price, } = alice .get_checkpoint(state.to_checkpoint(alice.now().await?)) .await?; let checkpoint_exposure = alice .get_checkpoint_exposure(state.to_checkpoint(alice.now().await?)) .await?; - let global_max_short = - state.get_max_short(U256::MAX, open_share_price, checkpoint_exposure, None, None); + let global_max_short = state.get_max_short( + U256::MAX, + open_vault_share_price, + checkpoint_exposure, + None, + None, + ); let budget = bob.base(); let slippage_tolerance = fixed!(0.001e18); let max_short = bob.get_max_short(Some(slippage_tolerance)).await?; @@ -276,7 +281,7 @@ async fn test_calculate_bonds_given_shares_and_rate() -> Result<()> { ); let rust_reserves = calculate_initial_bond_reserves( effective_share_reserves, - state.config.initial_share_price.into(), + state.config.initial_vault_share_price.into(), state.get_spot_rate(), state.config.position_duration.into(), state.config.time_stretch.into(), diff --git a/crates/test-utils/src/agent.rs b/crates/test-utils/src/agent.rs index 8e78205cb..a6be59328 100644 --- a/crates/test-utils/src/agent.rs +++ b/crates/test-utils/src/agent.rs @@ -53,7 +53,7 @@ pub struct Agent { address: Address, provider: Provider>>, hyperdrive: IHyperdrive, - pool: MockERC4626, + vault: MockERC4626, base: ERC20Mintable, config: PoolConfig, wallet: Wallet, @@ -165,17 +165,17 @@ impl Agent { maybe_seed: Option, ) -> Result { let seed = maybe_seed.unwrap_or(17); - let pool = IERC4626Hyperdrive::new(addresses.hyperdrive, client.clone()) - .pool() + let vault = IERC4626Hyperdrive::new(addresses.hyperdrive, client.clone()) + .vault() .call() .await?; - let pool = MockERC4626::new(pool, client.clone()); + let vault = MockERC4626::new(vault, client.clone()); let hyperdrive = IHyperdrive::new(addresses.hyperdrive, client.clone()); Ok(Self { address: client.address(), provider: client.provider().clone(), hyperdrive: hyperdrive.clone(), - pool, + vault, base: ERC20Mintable::new(addresses.base, client), config: hyperdrive.get_pool_config().call().await?, wallet: Wallet::default(), @@ -794,7 +794,7 @@ impl Agent { /// interest accrues. pub async fn advance_time(&self, rate: FixedPoint, duration: FixedPoint) -> Result<()> { // Set the new variable rate. - self.pool.set_rate(rate.into()).send().await?; + self.vault.set_rate(rate.into()).send().await?; // Advance the chain's time and mine a block. Mining a block is // important because client's check the current block time by looking @@ -819,7 +819,7 @@ impl Agent { maybe_tx_options: Option, ) -> Result<()> { // Set the new variable rate. - self.pool.set_rate(rate.into()).send().await?; + self.vault.set_rate(rate.into()).send().await?; // Advance time one checkpoint at a time until we've advanced time by // the full duration. @@ -943,7 +943,7 @@ impl Agent { pub async fn calculate_open_short(&self, short_amount: FixedPoint) -> Result { let state = self.get_state().await?; let Checkpoint { - share_price: open_share_price, + vault_share_price: open_vault_share_price, .. } = self .hyperdrive @@ -952,7 +952,7 @@ impl Agent { state.calculate_open_short( short_amount, state.get_spot_price(), - open_share_price.into(), + open_vault_share_price.into(), ) } @@ -980,7 +980,7 @@ impl Agent { let state = self.get_state().await?; let Checkpoint { - share_price: open_share_price, + vault_share_price: open_vault_share_price, } = self .hyperdrive .get_checkpoint(state.to_checkpoint(self.now().await?)) @@ -1002,7 +1002,7 @@ impl Agent { let min_price = state.get_min_price(); // Calculate the linear interpolation. - let base_reserves = FixedPoint::from(state.info.share_price) + let base_reserves = FixedPoint::from(state.info.vault_share_price) * (FixedPoint::from(state.info.share_reserves)); let weight = (min(self.wallet.base, base_reserves) / base_reserves) .pow(fixed!(1e18) - FixedPoint::from(self.config.time_stretch)); @@ -1011,7 +1011,7 @@ impl Agent { Ok(state.get_max_short( budget, - open_share_price, + open_vault_share_price, checkpoint_exposure, Some(conservative_price), None, diff --git a/crates/test-utils/src/chain/test_chain.rs b/crates/test-utils/src/chain/test_chain.rs index c9b3a7ca2..1a39c559f 100644 --- a/crates/test-utils/src/chain/test_chain.rs +++ b/crates/test-utils/src/chain/test_chain.rs @@ -246,7 +246,7 @@ impl TestChain { .gas_price(DEFAULT_GAS_PRICE) .send() .await?; - let pool = MockERC4626::deploy( + let vault = MockERC4626::deploy( client.clone(), ( base.address(), @@ -266,7 +266,7 @@ impl TestChain { base_token: base.address(), linker_factory: Address::from_low_u64_be(1), linker_code_hash: [1; 32], - initial_share_price: uint256!(1e18), + initial_vault_share_price: uint256!(1e18), minimum_share_reserves: uint256!(10e18), minimum_transaction_amount: uint256!(0.001e18), position_duration: U256::from(60 * 60 * 24 * 365), // 1 year @@ -282,19 +282,19 @@ impl TestChain { governance_zombie: uint256!(0.15e18), }, }; - let target0 = ERC4626Target0::deploy(client.clone(), (config.clone(), pool.address()))? + let target0 = ERC4626Target0::deploy(client.clone(), (config.clone(), vault.address()))? .gas_price(DEFAULT_GAS_PRICE) .send() .await?; - let target1 = ERC4626Target1::deploy(client.clone(), (config.clone(), pool.address()))? + let target1 = ERC4626Target1::deploy(client.clone(), (config.clone(), vault.address()))? .gas_price(DEFAULT_GAS_PRICE) .send() .await?; - let target2 = ERC4626Target2::deploy(client.clone(), (config.clone(), pool.address()))? + let target2 = ERC4626Target2::deploy(client.clone(), (config.clone(), vault.address()))? .gas_price(DEFAULT_GAS_PRICE) .send() .await?; - let target3 = ERC4626Target3::deploy(client.clone(), (config.clone(), pool.address()))? + let target3 = ERC4626Target3::deploy(client.clone(), (config.clone(), vault.address()))? .gas_price(DEFAULT_GAS_PRICE) .send() .await?; @@ -306,7 +306,7 @@ impl TestChain { target1.address(), target2.address(), target3.address(), - pool.address(), + vault.address(), ), )? .gas_price(DEFAULT_GAS_PRICE) @@ -338,7 +338,7 @@ impl TestChain { let target1_address = hyperdrive.target_1().call().await?; let target2_address = hyperdrive.target_2().call().await?; let target3_address = hyperdrive.target_3().call().await?; - let vault_address = hyperdrive.pool().call().await?; + let vault_address = hyperdrive.vault().call().await?; // Deploy templates for each of the contracts that should be etched and // get a list of targets and templates. In order for the contracts to @@ -421,13 +421,15 @@ impl TestChain { // Etch the "etching vault" onto the current vault contract. The // etching vault implements `convertToAssets` to return the immutable // that was passed on deployment. This is necessary because the - // ERC4626Hyperdrive instance verifies that the initial share price - // is equal to the `_pricePerShare`. - let etching_vault_template = - EtchingVault::deploy(client.clone(), (addresses.base, config.initial_share_price))? - .gas_price(DEFAULT_GAS_PRICE) - .send() - .await?; + // ERC4626Hyperdrive instance verifies that the initial vault share price + // is equal to the `_pricePerVaultShare`. + let etching_vault_template = EtchingVault::deploy( + client.clone(), + (addresses.base, config.initial_vault_share_price), + )? + .gas_price(DEFAULT_GAS_PRICE) + .send() + .await?; let code = provider .get_code(etching_vault_template.address(), None) .await?; @@ -642,7 +644,7 @@ mod tests { assert_eq!(config.base_token, chain.addresses.base); assert_eq!(config.linker_factory, Address::from_low_u64_be(1)); assert_eq!(config.linker_code_hash, [1; 32]); - assert_eq!(config.initial_share_price, uint256!(1e18)); + assert_eq!(config.initial_vault_share_price, uint256!(1e18)); assert_eq!(config.minimum_share_reserves, uint256!(10e18)); assert_eq!(config.position_duration, U256::from(60 * 60 * 24 * 365)); assert_eq!(config.checkpoint_duration, U256::from(60 * 60 * 24)); diff --git a/crates/test-utils/src/crash_reports.rs b/crates/test-utils/src/crash_reports.rs index e8e5941b0..0e0dd3eda 100644 --- a/crates/test-utils/src/crash_reports.rs +++ b/crates/test-utils/src/crash_reports.rs @@ -167,7 +167,7 @@ mod tests { "baseToken": "0x5FbDB2315678afecb367f032d93F642f64180aa3", "linkerFactory": "0x33027547537D35728a741470dF1CCf65dE10b454", "linkerCodeHash": "0x33027547537d35728a741470df1ccf65de10b454ca0def7c5c20b257b7b8d161", - "initialSharePrice": 1000000000000000000, + "initialVaultSharePrice": 1000000000000000000, "minimumShareReserves": 10000000000000000000, "minimumTransactionAmount": 1000000000000000, "positionDuration": 604800, @@ -187,7 +187,7 @@ mod tests { "zombieShareReserves": 0, "bondReserves": 102178995195337961200000000, "lpTotalSupply": 99999990000000000000000000, - "sharePrice": 1000000006341958396, + "vaultSharePrice": 1000000006341958396, "longsOutstanding": 0, "longAverageMaturityTime": 0, "shortsOutstanding": 0, @@ -198,7 +198,7 @@ mod tests { "longExposure": 0 }, "raw_checkpoint": { - "sharePrice": 1000000000000000000, + "vaultSharePrice": 1000000000000000000, "exposure": 0 }, "anvil_dump_state": "0x7b22", @@ -236,7 +236,7 @@ mod tests { "baseToken": "0x5FbDB2315678afecb367f032d93F642f64180aa3", "linkerFactory": "0x33027547537D35728a741470dF1CCf65dE10b454", "linkerCodeHash": "0x33027547537d35728a741470df1ccf65de10b454ca0def7c5c20b257b7b8d161", - "initialSharePrice": "1.0", + "initialVaultSharePrice": "1.0", "minimumShareReserves": "10.0", "minimumTransactionAmount": "0.001", "positionDuration": 604800, @@ -261,7 +261,7 @@ mod tests { "zombieShareReserves": "0.0", "bondReserves": "102178995.1953379612", "lpTotalSupply": "99999990.0", - "sharePrice": "1.000000006341958396", + "vaultSharePrice": "1.000000006341958396", "longsOutstanding": "0.0", "longAverageMaturityTime": "0.0", "shortsOutstanding": "0.0", @@ -275,7 +275,7 @@ mod tests { "totalSupplyWithdrawalShares": 0 }, "checkpoint_info": { - "sharePrice": "1.0", + "vaultSharePrice": "1.0", "exposure": "0.0", "blockNumber": 16, "timestamp": "2023-10-20 14:28:34" diff --git a/test/instances/erc4626/ERC4626Hyperdrive.t.sol b/test/instances/erc4626/ERC4626Hyperdrive.t.sol index 5df271623..09e3627a3 100644 --- a/test/instances/erc4626/ERC4626Hyperdrive.t.sol +++ b/test/instances/erc4626/ERC4626Hyperdrive.t.sol @@ -101,7 +101,7 @@ contract ERC4626HyperdriveTest is HyperdriveTest { baseToken: dai, linkerFactory: address(0), linkerCodeHash: bytes32(0), - initialSharePrice: ONE, + initialVaultSharePrice: ONE, minimumShareReserves: ONE, minimumTransactionAmount: 0.001e18, positionDuration: 365 days, @@ -148,22 +148,23 @@ contract ERC4626HyperdriveTest is HyperdriveTest { vm.startPrank(alice); dai.transfer(address(pool), 5e18); // Now we try a deposit - (uint256 sharesMinted, uint256 sharePrice) = mockHyperdrive.deposit( - 1e18, - IHyperdrive.Options({ - destination: address(0), - asBase: true, - extraData: new bytes(0) - }) - ); - assertEq(sharePrice, 1.5e18); + (uint256 sharesMinted, uint256 vaultSharePrice) = mockHyperdrive + .deposit( + 1e18, + IHyperdrive.Options({ + destination: address(0), + asBase: true, + extraData: new bytes(0) + }) + ); + assertEq(vaultSharePrice, 1.5e18); // 1/1.5 = 0.666666666666666666 assertEq(sharesMinted, 666666666666666666); assertEq(pool.balanceOf(address(mockHyperdrive)), 666666666666666666); // Now we try to do a deposit from alice's shares pool.approve(address(mockHyperdrive), type(uint256).max); - (sharesMinted, sharePrice) = mockHyperdrive.deposit( + (sharesMinted, vaultSharePrice) = mockHyperdrive.deposit( 3e18, IHyperdrive.Options({ destination: address(0), @@ -171,7 +172,7 @@ contract ERC4626HyperdriveTest is HyperdriveTest { extraData: new bytes(0) }) ); - assertEq(sharePrice, 1.5e18); + assertEq(vaultSharePrice, 1.5e18); assertEq(sharesMinted, 3e18); // 666666666666666666 shares + 3e18 shares = 3666666666666666666 assertApproxEqAbs( @@ -190,7 +191,7 @@ contract ERC4626HyperdriveTest is HyperdriveTest { // test an underlying withdraw uint256 amountWithdrawn = mockHyperdrive.withdraw( 2e18, - mockHyperdrive.pricePerShare(), + mockHyperdrive.pricePerVaultShare(), IHyperdrive.Options({ destination: alice, asBase: true, @@ -204,7 +205,7 @@ contract ERC4626HyperdriveTest is HyperdriveTest { // Test a share withdraw amountWithdrawn = mockHyperdrive.withdraw( 2e18, - mockHyperdrive.pricePerShare(), + mockHyperdrive.pricePerVaultShare(), IHyperdrive.Options({ destination: alice, asBase: false, @@ -225,7 +226,7 @@ contract ERC4626HyperdriveTest is HyperdriveTest { // Test an underlying withdraw of zero. uint256 amountWithdrawn = mockHyperdrive.withdraw( 0, - mockHyperdrive.pricePerShare(), + mockHyperdrive.pricePerVaultShare(), IHyperdrive.Options({ destination: alice, asBase: true, @@ -239,7 +240,7 @@ contract ERC4626HyperdriveTest is HyperdriveTest { // Test a share withdraw of zero. amountWithdrawn = mockHyperdrive.withdraw( 0, - mockHyperdrive.pricePerShare(), + mockHyperdrive.pricePerVaultShare(), IHyperdrive.Options({ destination: alice, asBase: false, @@ -303,7 +304,7 @@ contract ERC4626HyperdriveTest is HyperdriveTest { ); } - function test_erc4626_sharePrice() public { + function test_erc4626_vaultSharePrice() public { // This test ensures that `getPoolInfo` returns the correct share price. vm.startPrank(alice); uint256 apr = 0.01e18; // 1% apr @@ -336,14 +337,14 @@ contract ERC4626HyperdriveTest is HyperdriveTest { ); // Ensure the share price is 1 after initialization. - assertEq(hyperdrive.getPoolInfo().sharePrice, 1e18); + assertEq(hyperdrive.getPoolInfo().vaultSharePrice, 1e18); // Simulate interest accrual by sending funds to the pool. dai.transfer(address(pool), contribution); // Ensure that the share price calculations are correct when share price is not equal to 1e18. assertEq( - hyperdrive.getPoolInfo().sharePrice, + hyperdrive.getPoolInfo().vaultSharePrice, (pool.totalAssets()).divDown(pool.totalSupply()) ); } diff --git a/test/instances/erc4626/ERC4626Validation.t.sol b/test/instances/erc4626/ERC4626Validation.t.sol index 828638ae9..bcd4d75a4 100644 --- a/test/instances/erc4626/ERC4626Validation.t.sol +++ b/test/instances/erc4626/ERC4626Validation.t.sol @@ -126,7 +126,7 @@ abstract contract ERC4626ValidationTest is HyperdriveTest { FIXED_RATE, POSITION_DURATION ); - // Required to support ERC4626, since the test config initialSharePrice is wrong + // Required to support ERC4626, since the test config initialVaultSharePrice is wrong config.baseToken = underlyingToken; // Designed to ensure compatibility ../../contracts/src/instances/ERC4626Hyperdrive.sol#L122C1-L122C1 config.minimumTransactionAmount = hyperdrive @@ -478,7 +478,9 @@ abstract contract ERC4626ValidationTest is HyperdriveTest { (uint256 maturityTime, ) = openShortERC4626(alice, shortAmount, true); // The term passes and interest accrues. - uint256 startingSharePrice = hyperdrive.getPoolInfo().sharePrice; + uint256 startingVaultSharePrice = hyperdrive + .getPoolInfo() + .vaultSharePrice; variableRate = variableRate.normalizeToRange(0, 2.5e18); advanceTimeWithYield(POSITION_DURATION, variableRate); @@ -504,8 +506,8 @@ abstract contract ERC4626ValidationTest is HyperdriveTest { // Ensure that the short received the correct amount of base and wasn't // overcompensated. uint256 expectedBaseProceeds = shortAmount.mulDivDown( - hyperdrive.getPoolInfo().sharePrice - startingSharePrice, - startingSharePrice + hyperdrive.getPoolInfo().vaultSharePrice - startingVaultSharePrice, + startingVaultSharePrice ); assertLe(baseProceeds, expectedBaseProceeds + 10); assertApproxEqAbs(baseProceeds, expectedBaseProceeds, 1e5); diff --git a/test/instances/erc4626/Sweep.t.sol b/test/instances/erc4626/Sweep.t.sol index 0e1526641..e33746ce4 100644 --- a/test/instances/erc4626/Sweep.t.sol +++ b/test/instances/erc4626/Sweep.t.sol @@ -50,7 +50,7 @@ contract SweepTest is BaseTest { baseToken: IERC20(address(leakyBase)), linkerFactory: address(0), linkerCodeHash: bytes32(0), - initialSharePrice: ONE, + initialVaultSharePrice: ONE, minimumShareReserves: ONE, minimumTransactionAmount: 0.001e18, positionDuration: 365 days, @@ -139,7 +139,7 @@ contract SweepTest is BaseTest { hyperdrive.sweep(IERC20(baseToken)); // Trying to sweep the vault token should fail. - address vaultToken = address(hyperdrive.pool()); + address vaultToken = address(hyperdrive.vault()); vm.expectRevert(IHyperdrive.UnsupportedToken.selector); hyperdrive.sweep(IERC20(vaultToken)); } diff --git a/test/instances/erc4626/UsdcERC4626.t.sol b/test/instances/erc4626/UsdcERC4626.t.sol index 04b670fd7..39a01e40c 100644 --- a/test/instances/erc4626/UsdcERC4626.t.sol +++ b/test/instances/erc4626/UsdcERC4626.t.sol @@ -87,7 +87,7 @@ contract UsdcERC4626 is ERC4626ValidationTest { }) ); - // Config changes required to support ERC4626 with the correct initial share price. + // Config changes required to support ERC4626 with the correct initial vault share price. IHyperdrive.PoolDeployConfig memory config = testDeployConfig( FIXED_RATE, POSITION_DURATION diff --git a/test/instances/steth/StETHHyperdrive.t.sol b/test/instances/steth/StETHHyperdrive.t.sol index e8fe2c488..fe108bfaf 100644 --- a/test/instances/steth/StETHHyperdrive.t.sol +++ b/test/instances/steth/StETHHyperdrive.t.sol @@ -119,9 +119,9 @@ contract StETHHyperdriveTest is HyperdriveTest { // zero address's initial LP contribution. assertApproxEqAbs( hyperdrive.balanceOf(AssetId._LP_ASSET_ID, alice), - contribution.divDown(hyperdrive.getPoolConfig().initialSharePrice) - - 2 * - hyperdrive.getPoolConfig().minimumShareReserves, + contribution.divDown( + hyperdrive.getPoolConfig().initialVaultSharePrice + ) - 2 * hyperdrive.getPoolConfig().minimumShareReserves, 1e5 ); @@ -186,9 +186,9 @@ contract StETHHyperdriveTest is HyperdriveTest { // zero address's initial LP contribution. assertApproxEqAbs( hyperdrive.balanceOf(AssetId._LP_ASSET_ID, bob), - contribution.divDown(hyperdrive.getPoolConfig().initialSharePrice) - - 2 * - hyperdrive.getPoolConfig().minimumShareReserves, + contribution.divDown( + hyperdrive.getPoolConfig().initialVaultSharePrice + ) - 2 * hyperdrive.getPoolConfig().minimumShareReserves, 1e5 ); @@ -222,12 +222,12 @@ contract StETHHyperdriveTest is HyperdriveTest { /// Price Per Share /// - function test__pricePerShare(uint256 basePaid) external { + function test__pricePerVaultShare(uint256 basePaid) external { // Ensure that the share price is the expected value. uint256 totalPooledEther = LIDO.getTotalPooledEther(); uint256 totalShares = LIDO.getTotalShares(); - uint256 sharePrice = hyperdrive.getPoolInfo().sharePrice; - assertEq(sharePrice, totalPooledEther.divDown(totalShares)); + uint256 vaultSharePrice = hyperdrive.getPoolInfo().vaultSharePrice; + assertEq(vaultSharePrice, totalPooledEther.divDown(totalShares)); // Ensure that the share price accurately predicts the amount of shares // that will be minted for depositing a given amount of ETH. This will @@ -241,7 +241,7 @@ contract StETHHyperdriveTest is HyperdriveTest { openLong(bob, basePaid); assertApproxEqAbs( LIDO.sharesOf(address(hyperdrive)), - hyperdriveSharesBefore + basePaid.divDown(sharePrice), + hyperdriveSharesBefore + basePaid.divDown(vaultSharePrice), 1e4 ); } @@ -593,7 +593,9 @@ contract StETHHyperdriveTest is HyperdriveTest { vm.deal(bob, balanceBefore - basePaid); // The term passes and interest accrues. - uint256 startingSharePrice = hyperdrive.getPoolInfo().sharePrice; + uint256 startingVaultSharePrice = hyperdrive + .getPoolInfo() + .vaultSharePrice; variableRate = variableRate.normalizeToRange(0, 2.5e18); advanceTime(POSITION_DURATION, variableRate); @@ -608,8 +610,8 @@ contract StETHHyperdriveTest is HyperdriveTest { // Bob closes his short with stETH as the target asset. Bob's proceeds // should be the variable interest that accrued on the shorted bonds. uint256 expectedBaseProceeds = shortAmount.mulDivDown( - hyperdrive.getPoolInfo().sharePrice - startingSharePrice, - startingSharePrice + hyperdrive.getPoolInfo().vaultSharePrice - startingVaultSharePrice, + startingVaultSharePrice ); uint256 shareProceeds = closeShort( bob, @@ -679,8 +681,8 @@ contract StETHHyperdriveTest is HyperdriveTest { // Ensure that the share price is the expected value. uint256 totalPooledEther = LIDO.getTotalPooledEther(); uint256 totalShares = LIDO.getTotalShares(); - uint256 sharePrice = hyperdrive.getPoolInfo().sharePrice; - assertEq(sharePrice, totalPooledEther.divDown(totalShares)); + uint256 vaultSharePrice = hyperdrive.getPoolInfo().vaultSharePrice; + assertEq(vaultSharePrice, totalPooledEther.divDown(totalShares)); // Ensure that the share price accurately predicts the amount of shares // that will be minted for depositing a given amount of ETH. This will @@ -695,7 +697,7 @@ contract StETHHyperdriveTest is HyperdriveTest { // Bob received longAmount == ", longAmount); assertApproxEqAbs( LIDO.sharesOf(address(hyperdrive)), - hyperdriveSharesBefore + basePaid.divDown(sharePrice), + hyperdriveSharesBefore + basePaid.divDown(vaultSharePrice), 1e4 ); diff --git a/test/instances/steth/Sweep.t.sol b/test/instances/steth/Sweep.t.sol index 45e211ae9..56d9100d8 100644 --- a/test/instances/steth/Sweep.t.sol +++ b/test/instances/steth/Sweep.t.sol @@ -50,7 +50,7 @@ contract SweepTest is BaseTest { baseToken: IERC20(address(ETH)), linkerFactory: address(0), linkerCodeHash: bytes32(0), - initialSharePrice: ONE, + initialVaultSharePrice: ONE, minimumShareReserves: 1e15, minimumTransactionAmount: 1e12, positionDuration: 365 days, diff --git a/test/integrations/hyperdrive/IntraCheckpointNettingTest.t.sol b/test/integrations/hyperdrive/IntraCheckpointNettingTest.t.sol index e809f88b5..9b454e876 100644 --- a/test/integrations/hyperdrive/IntraCheckpointNettingTest.t.sol +++ b/test/integrations/hyperdrive/IntraCheckpointNettingTest.t.sol @@ -16,11 +16,11 @@ contract IntraCheckpointNettingTest is HyperdriveTest { using Lib for *; function test_netting_basic_example() external { - uint256 initialSharePrice = 1e18; + uint256 initialVaultSharePrice = 1e18; // Initialize the market uint256 apr = 0.05e18; - deploy(alice, apr, initialSharePrice, 0, 0, 0, 0); + deploy(alice, apr, initialVaultSharePrice, 0, 0, 0, 0); uint256 contribution = 100e18; uint256 aliceLpShares = initialize(alice, apr, contribution); @@ -60,8 +60,9 @@ contract IntraCheckpointNettingTest is HyperdriveTest { // idle should be equal to shareReserves uint256 expectedShareReserves = MockHyperdrive(address(hyperdrive)) - .calculateIdleShareReserves(hyperdrive.getPoolInfo().sharePrice) + - hyperdrive.getPoolConfig().minimumShareReserves; + .calculateIdleShareReserves( + hyperdrive.getPoolInfo().vaultSharePrice + ) + hyperdrive.getPoolConfig().minimumShareReserves; assertEq(poolInfo.shareReserves, expectedShareReserves); } @@ -71,7 +72,7 @@ contract IntraCheckpointNettingTest is HyperdriveTest { // - payout the withdrawal pool only when the idle capital is // worth more than the active LP supply function test_netting_long_short_close_at_maturity() external { - uint256 initialSharePrice = 1e18; + uint256 initialVaultSharePrice = 1e18; int256 variableInterest = 0; uint256 timeElapsed = 10220546; //~118 days between each trade uint256 tradeSize = 100e18; @@ -80,7 +81,7 @@ contract IntraCheckpointNettingTest is HyperdriveTest { uint256 aliceLpShares = 0; { uint256 apr = 0.05e18; - deploy(alice, apr, initialSharePrice, 0, 0, 0, 0); + deploy(alice, apr, initialVaultSharePrice, 0, 0, 0, 0); uint256 contribution = 500_000_000e18; aliceLpShares = initialize(alice, apr, contribution); @@ -142,13 +143,14 @@ contract IntraCheckpointNettingTest is HyperdriveTest { redeemWithdrawalShares(alice, withdrawalShares); // idle should be equal to shareReserves uint256 expectedShareReserves = MockHyperdrive(address(hyperdrive)) - .calculateIdleShareReserves(hyperdrive.getPoolInfo().sharePrice) + - hyperdrive.getPoolConfig().minimumShareReserves; + .calculateIdleShareReserves( + hyperdrive.getPoolInfo().vaultSharePrice + ) + hyperdrive.getPoolConfig().minimumShareReserves; assertEq(poolInfo.shareReserves, expectedShareReserves); } function test_netting_mismatched_exposure_maturities() external { - uint256 initialSharePrice = 1e18; + uint256 initialVaultSharePrice = 1e18; int256 variableInterest = 0e18; uint256 timeElapsed = 10220546; //~118 days between each trade uint256 tradeSize = 100e18; @@ -157,7 +159,7 @@ contract IntraCheckpointNettingTest is HyperdriveTest { uint256 aliceLpShares = 0; { uint256 apr = 0.05e18; - deploy(alice, apr, initialSharePrice, 0, 0, 0, 0); + deploy(alice, apr, initialVaultSharePrice, 0, 0, 0, 0); uint256 contribution = 500_000_000e18; aliceLpShares = initialize(alice, apr, contribution); @@ -204,19 +206,22 @@ contract IntraCheckpointNettingTest is HyperdriveTest { redeemWithdrawalShares(alice, withdrawalShares); // idle should be equal to shareReserves uint256 expectedShareReserves = MockHyperdrive(address(hyperdrive)) - .calculateIdleShareReserves(hyperdrive.getPoolInfo().sharePrice) + - hyperdrive.getPoolConfig().minimumShareReserves; + .calculateIdleShareReserves( + hyperdrive.getPoolInfo().vaultSharePrice + ) + hyperdrive.getPoolConfig().minimumShareReserves; assertEq(poolInfo.shareReserves, expectedShareReserves); } - function test_netting_longs_close_with_initial_share_price_gt_1() external { - uint256 initialSharePrice = 1.017375020334083692e18; + function test_netting_longs_close_with_initial_vault_share_price_gt_1() + external + { + uint256 initialVaultSharePrice = 1.017375020334083692e18; int256 variableInterest = 0.050000000000000000e18; uint256 timeElapsed = 4924801; uint256 tradeSize = 3810533.716355891982851995e18; uint256 numTrades = 1; open_close_long( - initialSharePrice, + initialVaultSharePrice, variableInterest, timeElapsed, tradeSize, @@ -225,13 +230,13 @@ contract IntraCheckpointNettingTest is HyperdriveTest { } function test_netting_longs_can_close_with_no_shorts() external { - uint256 initialSharePrice = 1.000252541820033020e18; + uint256 initialVaultSharePrice = 1.000252541820033020e18; int256 variableInterest = 0.050000000000000000e18; uint256 timeElapsed = POSITION_DURATION / 2; uint256 tradeSize = 369599.308648593814273788e18; uint256 numTrades = 2; open_close_long( - initialSharePrice, + initialVaultSharePrice, variableInterest, timeElapsed, tradeSize, @@ -242,7 +247,7 @@ contract IntraCheckpointNettingTest is HyperdriveTest { // This test demonstrates that you can open longs and shorts indefinitely until // the interest drops so low that positions can't be closed. function test_netting_extreme_negative_interest_time_elapsed() external { - uint256 initialSharePrice = 1e18; + uint256 initialVaultSharePrice = 1e18; int256 variableInterest = -0.1e18; // NOTE: This is the lowest interest rate that can be used uint256 timeElapsed = 10220546; //~118 days between each trade uint256 tradeSize = 100e18; @@ -251,7 +256,7 @@ contract IntraCheckpointNettingTest is HyperdriveTest { // If you increase numTrades enough it will eventually fail due to sub underflow // caused by share price going so low that k-y is negative (on openShort) open_close_long_short_different_checkpoints( - initialSharePrice, + initialVaultSharePrice, variableInterest, timeElapsed, tradeSize, @@ -260,7 +265,7 @@ contract IntraCheckpointNettingTest is HyperdriveTest { } function test_netting_zero_interest_small_time_elapsed() external { - uint256 initialSharePrice = 1e18; + uint256 initialVaultSharePrice = 1e18; int256 variableInterest = 0e18; uint256 timeElapsed = CHECKPOINT_DURATION / 3; uint256 tradeSize = 100e18; //100_000_000 fails with sub underflow @@ -269,7 +274,7 @@ contract IntraCheckpointNettingTest is HyperdriveTest { // If you increase trade size enough it will eventually fail due to sub underflow // caused by share price going so low that k-y is negative (on openShort) open_close_long_short_different_checkpoints( - initialSharePrice, + initialVaultSharePrice, variableInterest, timeElapsed, tradeSize, @@ -279,7 +284,7 @@ contract IntraCheckpointNettingTest is HyperdriveTest { // This test shows that you can open/close long/shorts with extreme positive interest function test_netting_extreme_positive_interest_time_elapsed() external { - uint256 initialSharePrice = 0.5e18; + uint256 initialVaultSharePrice = 0.5e18; int256 variableInterest = 0.5e18; uint256 timeElapsed = 15275477; //176 days bewteen each trade uint256 tradeSize = 504168.031667365798150347e18; @@ -288,7 +293,7 @@ contract IntraCheckpointNettingTest is HyperdriveTest { // If you increase numTrades enough it will eventually fail in openLong() // due to minOutput > bondProceeds where minOutput = baseAmount from openLong() open_close_long_short_different_checkpoints( - initialSharePrice, + initialVaultSharePrice, variableInterest, timeElapsed, tradeSize, @@ -298,7 +303,7 @@ contract IntraCheckpointNettingTest is HyperdriveTest { // This test shows that you can open large long/shorts repeatedly then wait 10 years to close all the positions function test_large_long_large_short_many_wait_to_redeem() external { - uint256 initialSharePrice = 1e18; + uint256 initialVaultSharePrice = 1e18; int256 variableInterest = 1.05e18; uint256 timeElapsed = 3650 days; // 10 years uint256 tradeSize = 100_000_000e18; @@ -307,7 +312,7 @@ contract IntraCheckpointNettingTest is HyperdriveTest { // You can keep increasing the numTrades until the test fails from // NegativeInterest on the openLong() spotPrice > 1 check open_close_long_short( - initialSharePrice, + initialVaultSharePrice, variableInterest, timeElapsed, tradeSize, @@ -317,39 +322,42 @@ contract IntraCheckpointNettingTest is HyperdriveTest { /// forge-config: default.fuzz.runs = 1000 function test_netting_fuzz( - uint256 initialSharePrice, + uint256 initialVaultSharePrice, int256 variableInterest, uint256 timeElapsed, uint256 tradeSize, uint256 numTrades ) external { // Fuzz inputs Standard Range - // initialSharePrice [0.5,5] + // initialVaultSharePrice [0.5,5] // variableInterest [0,50] // timeElapsed [0,365] // numTrades [1,5] // tradeSize [1,50_000_000/numTrades] 10% of the TVL - initialSharePrice = initialSharePrice.normalizeToRange(0.5e18, 5e18); + initialVaultSharePrice = initialVaultSharePrice.normalizeToRange( + 0.5e18, + 5e18 + ); variableInterest = variableInterest.normalizeToRange(0e18, .5e18); timeElapsed = timeElapsed.normalizeToRange(0, POSITION_DURATION); numTrades = tradeSize.normalizeToRange(1, 5); tradeSize = tradeSize.normalizeToRange(1e18, 50_000_000e18 / numTrades); open_close_long( - initialSharePrice, + initialVaultSharePrice, variableInterest, timeElapsed, tradeSize, numTrades ); open_close_short( - initialSharePrice, + initialVaultSharePrice, variableInterest, timeElapsed, tradeSize, numTrades ); open_close_long_short( - initialSharePrice, + initialVaultSharePrice, variableInterest, timeElapsed, tradeSize, @@ -359,19 +367,19 @@ contract IntraCheckpointNettingTest is HyperdriveTest { function test_netting_open_close_long() external { // This tests the following scenario: - // - initial_share_price = 1 + // - initial_vault_share_price = 1 // - positive interest causes the share price to go to up // - a long is opened and immediately closed // - trade size is 1 million uint256 snapshotId = vm.snapshot(); { - uint256 initialSharePrice = 1e18; + uint256 initialVaultSharePrice = 1e18; int256 variableInterest = 0.05e18; uint256 timeElapsed = 0 days; uint256 tradeSize = 1_000_000e18; uint256 numTrades = 1; open_close_long( - initialSharePrice, + initialVaultSharePrice, variableInterest, timeElapsed, tradeSize, @@ -381,19 +389,19 @@ contract IntraCheckpointNettingTest is HyperdriveTest { vm.revertTo(snapshotId); // This tests the following scenario: - // - initial_share_price = 1 + // - initial_vault_share_price = 1 // - positive interest causes the share price to go to up // - a long is opened and closed after 182.5 days // - trade size is 1 million snapshotId = vm.snapshot(); { - uint256 initialSharePrice = 1e18; + uint256 initialVaultSharePrice = 1e18; int256 variableInterest = 0.05e18; uint256 timeElapsed = POSITION_DURATION / 2; uint256 tradeSize = 1_000_000e18; uint256 numTrades = 1; open_close_long( - initialSharePrice, + initialVaultSharePrice, variableInterest, timeElapsed, tradeSize, @@ -403,19 +411,19 @@ contract IntraCheckpointNettingTest is HyperdriveTest { vm.revertTo(snapshotId); // This tests the following scenario: - // - initial_share_price = 1 + // - initial_vault_share_price = 1 // - positive interest causes the share price to go to up // - a long is opened and closed after POSITION_DURATION // - trade size is 1 million snapshotId = vm.snapshot(); { - uint256 initialSharePrice = 1e18; + uint256 initialVaultSharePrice = 1e18; int256 variableInterest = 0.05e18; uint256 timeElapsed = POSITION_DURATION; uint256 tradeSize = 1_000_000e18; uint256 numTrades = 1; open_close_long( - initialSharePrice, + initialVaultSharePrice, variableInterest, timeElapsed, tradeSize, @@ -426,7 +434,7 @@ contract IntraCheckpointNettingTest is HyperdriveTest { } function open_close_long( - uint256 initialSharePrice, + uint256 initialVaultSharePrice, int256 variableInterest, uint256 timeElapsed, uint256 tradeSize, @@ -434,7 +442,7 @@ contract IntraCheckpointNettingTest is HyperdriveTest { ) internal { // Initialize the market uint256 apr = 0.05e18; - deploy(alice, apr, initialSharePrice, 0, 0, 0, 0); + deploy(alice, apr, initialVaultSharePrice, 0, 0, 0, 0); uint256 contribution = 500_000_000e18; uint256 aliceLpShares = initialize(alice, apr, contribution); @@ -467,26 +475,27 @@ contract IntraCheckpointNettingTest is HyperdriveTest { assertApproxEqAbs(poolInfo.longExposure, 0, 1); // idle should be equal to shareReserves uint256 expectedShareReserves = MockHyperdrive(address(hyperdrive)) - .calculateIdleShareReserves(hyperdrive.getPoolInfo().sharePrice) + - hyperdrive.getPoolConfig().minimumShareReserves; + .calculateIdleShareReserves( + hyperdrive.getPoolInfo().vaultSharePrice + ) + hyperdrive.getPoolConfig().minimumShareReserves; assertEq(poolInfo.shareReserves, expectedShareReserves); } function test_netting_open_close_short() external { // This tests the following scenario: - // - initial_share_price = 1 + // - initial_vault_share_price = 1 // - positive interest causes the share price to go to up // - a short is opened and immediately closed // - trade size is 1 million uint256 snapshotId = vm.snapshot(); { - uint256 initialSharePrice = 1e18; + uint256 initialVaultSharePrice = 1e18; int256 variableInterest = 0.05e18; uint256 timeElapsed = 0; uint256 tradeSize = 1_000_000e18; uint256 numTrades = 1; open_close_short( - initialSharePrice, + initialVaultSharePrice, variableInterest, timeElapsed, tradeSize, @@ -496,19 +505,19 @@ contract IntraCheckpointNettingTest is HyperdriveTest { vm.revertTo(snapshotId); // This tests the following scenario: - // - initial_share_price = 1 + // - initial_vault_share_price = 1 // - positive interest causes the share price to go to up // - a short is opened and closed after 182.5 days // - trade size is 1 million snapshotId = vm.snapshot(); { - uint256 initialSharePrice = 1e18; + uint256 initialVaultSharePrice = 1e18; int256 variableInterest = 0.05e18; uint256 timeElapsed = POSITION_DURATION / 2; uint256 tradeSize = 1_000_000e18; uint256 numTrades = 1; open_close_short( - initialSharePrice, + initialVaultSharePrice, variableInterest, timeElapsed, tradeSize, @@ -518,19 +527,19 @@ contract IntraCheckpointNettingTest is HyperdriveTest { vm.revertTo(snapshotId); // This tests the following scenario: - // - initial_share_price = 1 + // - initial_vault_share_price = 1 // - positive interest causes the share price to go to up // - a short is opened and closed after 365 days // - trade size is 1 million snapshotId = vm.snapshot(); { - uint256 initialSharePrice = 1e18; + uint256 initialVaultSharePrice = 1e18; int256 variableInterest = 0.05e18; uint256 timeElapsed = POSITION_DURATION; uint256 tradeSize = 1_000_000e18; uint256 numTrades = 1; open_close_short( - initialSharePrice, + initialVaultSharePrice, variableInterest, timeElapsed, tradeSize, @@ -545,13 +554,13 @@ contract IntraCheckpointNettingTest is HyperdriveTest { // it nets to zero. snapshotId = vm.snapshot(); { - uint256 initialSharePrice = 0.5e18; + uint256 initialVaultSharePrice = 0.5e18; int256 variableInterest = 0.0e18; uint256 timeElapsed = 8640001; uint256 tradeSize = 6283765.441079100693164485e18; uint256 numTrades = 5; open_close_short( - initialSharePrice, + initialVaultSharePrice, variableInterest, timeElapsed, tradeSize, @@ -562,7 +571,7 @@ contract IntraCheckpointNettingTest is HyperdriveTest { } function open_close_short( - uint256 initialSharePrice, + uint256 initialVaultSharePrice, int256 variableInterest, uint256 timeElapsed, uint256 tradeSize, @@ -570,7 +579,7 @@ contract IntraCheckpointNettingTest is HyperdriveTest { ) internal { // Initialize the market uint256 apr = 0.05e18; - deploy(alice, apr, initialSharePrice, 0, 0, 0, 0); + deploy(alice, apr, initialVaultSharePrice, 0, 0, 0, 0); uint256 contribution = 500_000_000e18; initialize(alice, apr, contribution); @@ -598,27 +607,28 @@ contract IntraCheckpointNettingTest is HyperdriveTest { // idle should be equal to shareReserves uint256 expectedShareReserves = MockHyperdrive(address(hyperdrive)) - .calculateIdleShareReserves(hyperdrive.getPoolInfo().sharePrice) + - hyperdrive.getPoolConfig().minimumShareReserves; + .calculateIdleShareReserves( + hyperdrive.getPoolInfo().vaultSharePrice + ) + hyperdrive.getPoolConfig().minimumShareReserves; assertEq(poolInfo.shareReserves, expectedShareReserves); } // All tests close at maturity function test_netting_open_close_long_short() external { // This tests the following scenario: - // - initial_share_price = 1 + // - initial_vault_share_price = 1 // - positive interest causes the share price to go to up // - 1 trade // - trade size is 1 million uint256 snapshotId = vm.snapshot(); { - uint256 initialSharePrice = 1e18; + uint256 initialVaultSharePrice = 1e18; int256 variableInterest = 0.05e18; uint256 timeElapsed = 0; uint256 tradeSize = 1_000_000e18; uint256 numTrades = 1; open_close_long_short( - initialSharePrice, + initialVaultSharePrice, variableInterest, timeElapsed, tradeSize, @@ -628,19 +638,19 @@ contract IntraCheckpointNettingTest is HyperdriveTest { vm.revertTo(snapshotId); // This tests the following scenario: - // - initial_share_price = 1 + // - initial_vault_share_price = 1 // - positive interest causes the share price to go to up // - 1 trade // - trade size is 1 million snapshotId = vm.snapshot(); { - uint256 initialSharePrice = 1e18; + uint256 initialVaultSharePrice = 1e18; int256 variableInterest = 0.05e18; uint256 timeElapsed = POSITION_DURATION / 2; uint256 tradeSize = 1_000_000e18; uint256 numTrades = 1; open_close_long_short( - initialSharePrice, + initialVaultSharePrice, variableInterest, timeElapsed, tradeSize, @@ -650,19 +660,19 @@ contract IntraCheckpointNettingTest is HyperdriveTest { vm.revertTo(snapshotId); // This tests the following scenario: - // - initial_share_price = 1 + // - initial_vault_share_price = 1 // - positive interest causes the share price to go to up // - 1 trade // - trade size is 1 million snapshotId = vm.snapshot(); { - uint256 initialSharePrice = 1e18; + uint256 initialVaultSharePrice = 1e18; int256 variableInterest = 0.05e18; uint256 timeElapsed = POSITION_DURATION; uint256 tradeSize = 1_000_000e18; uint256 numTrades = 1; open_close_long_short( - initialSharePrice, + initialVaultSharePrice, variableInterest, timeElapsed, tradeSize, @@ -672,20 +682,20 @@ contract IntraCheckpointNettingTest is HyperdriveTest { vm.revertTo(snapshotId); // This tests the following scenario: - // - initial_share_price = 1 + // - initial_vault_share_price = 1 // - positive interest causes the share price to go to up // - 1000 trades // - trade size is 1 million snapshotId = vm.snapshot(); { - uint256 initialSharePrice = 1e18; + uint256 initialVaultSharePrice = 1e18; int256 variableInterest = 0.05e18; uint256 timeElapsed = POSITION_DURATION; uint256 tradeSize = 1_000_000e18; uint256 numTrades = 1000; // You can increase the numTrades until the test fails from OutOfGas open_close_long_short( - initialSharePrice, + initialVaultSharePrice, variableInterest, timeElapsed, tradeSize, @@ -695,20 +705,20 @@ contract IntraCheckpointNettingTest is HyperdriveTest { vm.revertTo(snapshotId); // This tests the following scenario: - // - initial_share_price = 1 + // - initial_vault_share_price = 1 // - zero interest // - 1000 trades // - trade size is 1 million snapshotId = vm.snapshot(); { - uint256 initialSharePrice = 1e18; + uint256 initialVaultSharePrice = 1e18; int256 variableInterest = 0.0e18; uint256 timeElapsed = POSITION_DURATION; uint256 tradeSize = 1_000_000e18; uint256 numTrades = 1000; // You can increase the numTrades until the test fails from OutOfGas open_close_long_short( - initialSharePrice, + initialVaultSharePrice, variableInterest, timeElapsed, tradeSize, @@ -719,7 +729,7 @@ contract IntraCheckpointNettingTest is HyperdriveTest { } function open_close_long_short( - uint256 initialSharePrice, + uint256 initialVaultSharePrice, int256 variableInterest, uint256 timeElapsed, uint256 tradeSize, @@ -727,7 +737,7 @@ contract IntraCheckpointNettingTest is HyperdriveTest { ) internal { // initialize the market uint256 apr = 0.05e18; - deploy(alice, apr, initialSharePrice, 0, 0, 0, 0); + deploy(alice, apr, initialVaultSharePrice, 0, 0, 0, 0); uint256 contribution = 500_000_000e18; uint256 aliceLpShares = initialize(alice, apr, contribution); @@ -789,13 +799,14 @@ contract IntraCheckpointNettingTest is HyperdriveTest { // idle should be equal to shareReserves uint256 expectedShareReserves = MockHyperdrive(address(hyperdrive)) - .calculateIdleShareReserves(hyperdrive.getPoolInfo().sharePrice) + - hyperdrive.getPoolConfig().minimumShareReserves; + .calculateIdleShareReserves( + hyperdrive.getPoolInfo().vaultSharePrice + ) + hyperdrive.getPoolConfig().minimumShareReserves; assertEq(poolInfo.shareReserves, expectedShareReserves); } function open_close_long_short_different_checkpoints( - uint256 initialSharePrice, + uint256 initialVaultSharePrice, int256 variableInterest, uint256 timeElapsed, uint256 tradeSize, @@ -805,7 +816,7 @@ contract IntraCheckpointNettingTest is HyperdriveTest { uint256 aliceLpShares = 0; { uint256 apr = 0.05e18; - deploy(alice, apr, initialSharePrice, 0, 0, 0, 0); + deploy(alice, apr, initialVaultSharePrice, 0, 0, 0, 0); // JR TODO: we should add this as a parameter to fuzz to ensure that we are solvent with withdrawal shares uint256 contribution = 500_000_000e18; aliceLpShares = initialize(alice, apr, contribution); @@ -867,8 +878,9 @@ contract IntraCheckpointNettingTest is HyperdriveTest { // idle should be equal to shareReserves uint256 expectedShareReserves = MockHyperdrive(address(hyperdrive)) - .calculateIdleShareReserves(hyperdrive.getPoolInfo().sharePrice) + - hyperdrive.getPoolConfig().minimumShareReserves; + .calculateIdleShareReserves( + hyperdrive.getPoolInfo().vaultSharePrice + ) + hyperdrive.getPoolConfig().minimumShareReserves; assertEq(poolInfo.shareReserves, expectedShareReserves); } } diff --git a/test/integrations/hyperdrive/LPWithdrawalTest.t.sol b/test/integrations/hyperdrive/LPWithdrawalTest.t.sol index a00acb530..9358d6a3b 100644 --- a/test/integrations/hyperdrive/LPWithdrawalTest.t.sol +++ b/test/integrations/hyperdrive/LPWithdrawalTest.t.sol @@ -118,7 +118,8 @@ contract LPWithdrawalTest is HyperdriveTest { assertApproxEqAbs( baseToken.balanceOf(address(hyperdrive)), hyperdrive.getPoolConfig().minimumShareReserves.mulDown( - hyperdrive.getPoolInfo().sharePrice + hyperdrive.lpSharePrice() + hyperdrive.getPoolInfo().vaultSharePrice + + hyperdrive.lpSharePrice() ), 1e9 ); @@ -225,7 +226,8 @@ contract LPWithdrawalTest is HyperdriveTest { assertApproxEqAbs( baseToken.balanceOf(address(hyperdrive)), hyperdrive.getPoolConfig().minimumShareReserves.mulDown( - hyperdrive.getPoolInfo().sharePrice + hyperdrive.lpSharePrice() + hyperdrive.getPoolInfo().vaultSharePrice + + hyperdrive.lpSharePrice() ), 1e9 ); @@ -354,7 +356,8 @@ contract LPWithdrawalTest is HyperdriveTest { assertApproxEqAbs( baseToken.balanceOf(address(hyperdrive)), hyperdrive.getPoolConfig().minimumShareReserves.mulDown( - hyperdrive.getPoolInfo().sharePrice + hyperdrive.lpSharePrice() + hyperdrive.getPoolInfo().vaultSharePrice + + hyperdrive.lpSharePrice() ), 1e9 ); @@ -729,7 +732,8 @@ contract LPWithdrawalTest is HyperdriveTest { assertApproxEqAbs( baseToken.balanceOf(address(hyperdrive)), hyperdrive.getPoolConfig().minimumShareReserves.mulDown( - hyperdrive.getPoolInfo().sharePrice + hyperdrive.lpSharePrice() + hyperdrive.getPoolInfo().vaultSharePrice + + hyperdrive.lpSharePrice() ), 1e9 ); @@ -1027,7 +1031,8 @@ contract LPWithdrawalTest is HyperdriveTest { assertApproxEqAbs( baseToken.balanceOf(address(hyperdrive)), hyperdrive.getPoolConfig().minimumShareReserves.mulDown( - hyperdrive.getPoolInfo().sharePrice + hyperdrive.lpSharePrice() + hyperdrive.getPoolInfo().vaultSharePrice + + hyperdrive.lpSharePrice() ), 1e10 ); @@ -1215,7 +1220,8 @@ contract LPWithdrawalTest is HyperdriveTest { assertApproxEqAbs( baseToken.balanceOf(address(hyperdrive)), hyperdrive.getPoolConfig().minimumShareReserves.mulDown( - hyperdrive.getPoolInfo().sharePrice + hyperdrive.lpSharePrice() + hyperdrive.getPoolInfo().vaultSharePrice + + hyperdrive.lpSharePrice() ), 1e9 ); @@ -1713,7 +1719,7 @@ contract LPWithdrawalTest is HyperdriveTest { params.originalShareAdjustment ) ) - .mulDown(hyperdrive.getPoolInfo().sharePrice); + .mulDown(hyperdrive.getPoolInfo().vaultSharePrice); // Remove the liquidity. uint256 idleBefore = hyperdrive.idle(); diff --git a/test/integrations/hyperdrive/NegativeInterestLongFeeTest.t.sol b/test/integrations/hyperdrive/NegativeInterestLongFeeTest.t.sol index 3ad61cd03..fe8c47348 100644 --- a/test/integrations/hyperdrive/NegativeInterestLongFeeTest.t.sol +++ b/test/integrations/hyperdrive/NegativeInterestLongFeeTest.t.sol @@ -14,19 +14,22 @@ contract NegativeInterestLongFeeTest is HyperdriveTest { using Lib for *; function test_negative_interest_long_immediate_open_close_fees_fuzz( - uint256 initialSharePrice, + uint256 initialVaultSharePrice, int256 variableInterest ) external { // Fuzz inputs - // initialSharePrice [0.5,10] + // initialVaultSharePrice [0.5,10] // variableInterest [-50,0] - initialSharePrice = initialSharePrice.normalizeToRange(.5e18, 10e18); + initialVaultSharePrice = initialVaultSharePrice.normalizeToRange( + .5e18, + 10e18 + ); variableInterest = -variableInterest.normalizeToRange(0, .5e18); uint256 curveFee = 0.1e18; uint256 flatFee = 0.000e18; uint256 governanceFee = 1e18; test_negative_interest_long_immediate_open_close_fees( - initialSharePrice, + initialVaultSharePrice, variableInterest, curveFee, flatFee, @@ -36,19 +39,19 @@ contract NegativeInterestLongFeeTest is HyperdriveTest { function test_negative_interest_long_immediate_open_close_fees() external { // This tests the following scenario: - // - initial_share_price > 1 + // - initial_vault_share_price > 1 // - negative interest causes the share price to go down // - a long is opened and immediately closed // - set the curve fee to 10% and the governance fee to 100% to make the // test easier to verify { - uint256 initialSharePrice = 1.5e18; + uint256 initialVaultSharePrice = 1.5e18; int256 variableInterest = -0.1e18; uint256 curveFee = 0.1e18; uint256 flatFee = 0; uint256 governanceFee = 1e18; test_negative_interest_long_immediate_open_close_fees( - initialSharePrice, + initialVaultSharePrice, variableInterest, curveFee, flatFee, @@ -57,19 +60,19 @@ contract NegativeInterestLongFeeTest is HyperdriveTest { } // This tests the following scenario: - // - initial_share_price = 1 + // - initial_vault_share_price = 1 // - negative interest causes the share price to go down // - a long is opened and immediately closed // - set the curve fee to 10% and the governance fee to 100% to make the // test easier to verify { - uint256 initialSharePrice = 1e18; + uint256 initialVaultSharePrice = 1e18; int256 variableInterest = -0.1e18; uint256 curveFee = 0.1e18; uint256 flatFee = 0; uint256 governanceFee = 1e18; test_negative_interest_long_immediate_open_close_fees( - initialSharePrice, + initialVaultSharePrice, variableInterest, curveFee, flatFee, @@ -78,19 +81,19 @@ contract NegativeInterestLongFeeTest is HyperdriveTest { } // This tests the following scenario: - // - initial_share_price < 1 + // - initial_vault_share_price < 1 // - negative interest causes the share price to go down // - a long is opened and immediately closed // - set the curve fee to 10% and the governance fee to 100% to make the // test easier to verify { - uint256 initialSharePrice = 0.95e18; + uint256 initialVaultSharePrice = 0.95e18; int256 variableInterest = -0.1e18; uint256 curveFee = 0.1e18; uint256 flatFee = 0; uint256 governanceFee = 1e18; test_negative_interest_long_immediate_open_close_fees( - initialSharePrice, + initialVaultSharePrice, variableInterest, curveFee, flatFee, @@ -100,7 +103,7 @@ contract NegativeInterestLongFeeTest is HyperdriveTest { } function test_negative_interest_long_immediate_open_close_fees( - uint256 initialSharePrice, + uint256 initialVaultSharePrice, int256 variableInterest, uint256 curveFee, uint256 flatFee, @@ -111,7 +114,7 @@ contract NegativeInterestLongFeeTest is HyperdriveTest { deploy( alice, apr, - initialSharePrice, + initialVaultSharePrice, curveFee, flatFee, governanceFee, @@ -123,9 +126,9 @@ contract NegativeInterestLongFeeTest is HyperdriveTest { // fast forward time and accrue interest advanceTime(POSITION_DURATION, variableInterest); - // Record the sharePrice after interest accrual. - (uint256 sharePrice, ) = HyperdriveUtils.calculateCompoundInterest( - initialSharePrice, + // Record the vaultSharePrice after interest accrual. + (uint256 vaultSharePrice, ) = HyperdriveUtils.calculateCompoundInterest( + initialVaultSharePrice, variableInterest, POSITION_DURATION ); @@ -150,7 +153,7 @@ contract NegativeInterestLongFeeTest is HyperdriveTest { DepositOverrides({ asBase: true, depositAmount: basePaid, - minSharePrice: 0, + minVaultSharePrice: 0, minSlippage: 0, // TODO: This should never go below the base amount. Investigate this. maxSlippage: type(uint256).max, extraData: new bytes(0) @@ -170,7 +173,7 @@ contract NegativeInterestLongFeeTest is HyperdriveTest { uint256 expectedGovernanceFees = curveFee_ .mulDown(ONE.divDown(calculatedSpotPrice) - ONE) .mulDown(basePaid) - .mulDivDown(calculatedSpotPrice, sharePrice); + .mulDivDown(calculatedSpotPrice, vaultSharePrice); assertApproxEqAbs( governanceFeesAfterOpenLong, expectedGovernanceFees, @@ -188,7 +191,7 @@ contract NegativeInterestLongFeeTest is HyperdriveTest { // Calculate the expected fees from closing the long expectedGovernanceFees = curveFee_ .mulDown(ONE - calculatedSpotPrice) - .mulDivDown(bondAmount, sharePrice); + .mulDivDown(bondAmount, vaultSharePrice); assertApproxEqAbs( governanceFeesAfterCloseLong, expectedGovernanceFees, @@ -197,14 +200,17 @@ contract NegativeInterestLongFeeTest is HyperdriveTest { } function test_negative_interest_long_full_term_fees_fuzz( - uint256 initialSharePrice, + uint256 initialVaultSharePrice, int256 preTradeVariableInterest, int256 variableInterest ) external { // Fuzz inputs - // initialSharePrice [0.5,10] + // initialVaultSharePrice [0.5,10] // variableInterest [-50,0] - initialSharePrice = initialSharePrice.normalizeToRange(.5e18, 10e18); + initialVaultSharePrice = initialVaultSharePrice.normalizeToRange( + .5e18, + 10e18 + ); preTradeVariableInterest = -preTradeVariableInterest.normalizeToRange( 0, .5e18 @@ -214,7 +220,7 @@ contract NegativeInterestLongFeeTest is HyperdriveTest { uint256 flatFee = 0.01e18; uint256 governanceFee = 1e18; test_negative_interest_long_full_term_fees( - initialSharePrice, + initialVaultSharePrice, preTradeVariableInterest, variableInterest, curveFee, @@ -225,21 +231,21 @@ contract NegativeInterestLongFeeTest is HyperdriveTest { function test_negative_interest_long_full_term_fees() external { // This tests the following scenario: - // - initial_share_price > 1 + // - initial_vault_share_price > 1 // - negative interest causes the share price to go down // - a long is opened // - negative interest accrues over the full term // - long is closed // - set the flat fee to 10% and governance fee to 100% to make the test easier to verify { - uint256 initialSharePrice = 1.5e18; + uint256 initialVaultSharePrice = 1.5e18; int256 preTradeVariableInterest = -0.05e18; int256 variableInterest = -0.1e18; uint256 curveFee = 0e18; uint256 flatFee = 0.01e18; uint256 governanceFee = 1e18; test_negative_interest_long_full_term_fees( - initialSharePrice, + initialVaultSharePrice, preTradeVariableInterest, variableInterest, curveFee, @@ -249,21 +255,21 @@ contract NegativeInterestLongFeeTest is HyperdriveTest { } // This tests the following scenario: - // - initial_share_price = 1 + // - initial_vault_share_price = 1 // - negative interest causes the share price to go down // - a long is opened // - negative interest accrues over the full term // - long is closed // - set the flat fee to 10% and governance fee to 100% to make the test easier to verify { - uint256 initialSharePrice = 1e18; + uint256 initialVaultSharePrice = 1e18; int256 preTradeVariableInterest = -0.05e18; int256 variableInterest = -0.1e18; uint256 curveFee = 0e18; uint256 flatFee = 0.01e18; uint256 governanceFee = 1e18; test_negative_interest_long_full_term_fees( - initialSharePrice, + initialVaultSharePrice, preTradeVariableInterest, variableInterest, curveFee, @@ -273,21 +279,21 @@ contract NegativeInterestLongFeeTest is HyperdriveTest { } // This tests the following scenario: - // - initial_share_price < 1 + // - initial_vault_share_price < 1 // - negative interest causes the share price to go down // - a long is opened // - negative interest accrues over the full term // - long is closed // - set the flat fee to 10% and governance fee to 100% to make the test easier to verify { - uint256 initialSharePrice = 0.95e18; + uint256 initialVaultSharePrice = 0.95e18; int256 preTradeVariableInterest = -0.05e18; int256 variableInterest = -0.1e18; uint256 curveFee = 0e18; uint256 flatFee = 0.01e18; uint256 governanceFee = 1e18; test_negative_interest_long_full_term_fees( - initialSharePrice, + initialVaultSharePrice, preTradeVariableInterest, variableInterest, curveFee, @@ -298,7 +304,7 @@ contract NegativeInterestLongFeeTest is HyperdriveTest { } function test_negative_interest_long_full_term_fees( - uint256 initialSharePrice, + uint256 initialVaultSharePrice, int256 preTradeVariableInterest, int256 variableInterest, uint256 curveFee, @@ -310,7 +316,7 @@ contract NegativeInterestLongFeeTest is HyperdriveTest { deploy( alice, apr, - initialSharePrice, + initialVaultSharePrice, curveFee, flatFee, governanceFee, @@ -322,12 +328,13 @@ contract NegativeInterestLongFeeTest is HyperdriveTest { // fast forward time and accrue interest advanceTime(POSITION_DURATION, preTradeVariableInterest); - // Record the openSharePrice after interest accrual. - (uint256 openSharePrice, ) = HyperdriveUtils.calculateCompoundInterest( - initialSharePrice, - preTradeVariableInterest, - POSITION_DURATION - ); + // Record the openVaultSharePrice after interest accrual. + (uint256 openVaultSharePrice, ) = HyperdriveUtils + .calculateCompoundInterest( + initialVaultSharePrice, + preTradeVariableInterest, + POSITION_DURATION + ); // Ensure that the governance initially has zero balance uint256 governanceBalanceBefore = baseToken.balanceOf(feeCollector); @@ -347,7 +354,7 @@ contract NegativeInterestLongFeeTest is HyperdriveTest { DepositOverrides({ asBase: true, depositAmount: basePaid, - minSharePrice: 0, + minVaultSharePrice: 0, minSlippage: 0, // TODO: This should never go below the base amount. Investigate this. maxSlippage: type(uint256).max, extraData: new bytes(0) @@ -381,7 +388,7 @@ contract NegativeInterestLongFeeTest is HyperdriveTest { // is the share price at the beginning of the checkpoint. This gives // us a governance fee of `(c / c_0) * (g / c) = g / c_0`. uint256 expectedGovernanceFees = (bondAmount * flatFee) / - openSharePrice; + openVaultSharePrice; assertApproxEqAbs( governanceFeesAfterCloseLong, expectedGovernanceFees, @@ -391,14 +398,17 @@ contract NegativeInterestLongFeeTest is HyperdriveTest { } function test_negative_interest_long_half_term_fees_fuzz( - uint256 initialSharePrice, + uint256 initialVaultSharePrice, int256 preTradeVariableInterest, int256 variableInterest ) external { // Fuzz inputs - // initialSharePrice [0.5,10] + // initialVaultSharePrice [0.5,10] // variableInterest [-50,0] - initialSharePrice = initialSharePrice.normalizeToRange(.5e18, 10e18); + initialVaultSharePrice = initialVaultSharePrice.normalizeToRange( + .5e18, + 10e18 + ); preTradeVariableInterest = -preTradeVariableInterest.normalizeToRange( 0, .5e18 @@ -408,7 +418,7 @@ contract NegativeInterestLongFeeTest is HyperdriveTest { uint256 flatFee = 0.01e18; uint256 governanceFee = 1e18; test_negative_interest_long_half_term_fees( - initialSharePrice, + initialVaultSharePrice, preTradeVariableInterest, variableInterest, curveFee, @@ -419,7 +429,7 @@ contract NegativeInterestLongFeeTest is HyperdriveTest { function test_negative_interest_long_half_term_fees() external { // This tests the following scenario: - // - initial_share_price > 1 + // - initial_vault_share_price > 1 // - negative interest causes the share price to go down // - a long is opened // - negative interest accrues over the half the term @@ -427,14 +437,14 @@ contract NegativeInterestLongFeeTest is HyperdriveTest { // - set the flat fee to 10%, curve fee to 10% and governance fee to 100% to make the test easier to verify uint256 snapshotId = vm.snapshot(); { - uint256 initialSharePrice = 1.5e18; + uint256 initialVaultSharePrice = 1.5e18; int256 preTradeVariableInterest = -0.05e18; int256 variableInterest = -0.1e18; uint256 curveFee = 0.1e18; uint256 flatFee = 0.01e18; uint256 governanceFee = 1e18; test_negative_interest_long_half_term_fees( - initialSharePrice, + initialVaultSharePrice, preTradeVariableInterest, variableInterest, curveFee, @@ -445,7 +455,7 @@ contract NegativeInterestLongFeeTest is HyperdriveTest { vm.revertTo(snapshotId); // This tests the following scenario: - // - initial_share_price = 1 + // - initial_vault_share_price = 1 // - negative interest causes the share price to go down // - a long is opened // - negative interest accrues over the half the term @@ -453,14 +463,14 @@ contract NegativeInterestLongFeeTest is HyperdriveTest { // - set the flat fee to 10%, curve fee to 10% and governance fee to 100% to make the test easier to verify snapshotId = vm.snapshot(); { - uint256 initialSharePrice = 1e18; + uint256 initialVaultSharePrice = 1e18; int256 preTradeVariableInterest = -0.05e18; int256 variableInterest = -0.1e18; uint256 curveFee = 0.1e18; uint256 flatFee = 0.01e18; uint256 governanceFee = 1e18; test_negative_interest_long_half_term_fees( - initialSharePrice, + initialVaultSharePrice, preTradeVariableInterest, variableInterest, curveFee, @@ -471,7 +481,7 @@ contract NegativeInterestLongFeeTest is HyperdriveTest { vm.revertTo(snapshotId); // This tests the following scenario: - // - initial_share_price < 1 + // - initial_vault_share_price < 1 // - negative interest causes the share price to go down // - a long is opened // - negative interest accrues over the half the term @@ -479,14 +489,14 @@ contract NegativeInterestLongFeeTest is HyperdriveTest { // - set the flat fee to 10%, curve fee to 10% and governance fee to 100% to make the test easier to verify snapshotId = vm.snapshot(); { - uint256 initialSharePrice = 0.95e18; + uint256 initialVaultSharePrice = 0.95e18; int256 preTradeVariableInterest = -0.05e18; int256 variableInterest = -0.1e18; uint256 curveFee = 0.1e18; uint256 flatFee = 0.01e18; uint256 governanceFee = 1e18; test_negative_interest_long_half_term_fees( - initialSharePrice, + initialVaultSharePrice, preTradeVariableInterest, variableInterest, curveFee, @@ -498,7 +508,7 @@ contract NegativeInterestLongFeeTest is HyperdriveTest { } function test_negative_interest_long_half_term_fees( - uint256 initialSharePrice, + uint256 initialVaultSharePrice, int256 preTradeVariableInterest, int256 variableInterest, uint256 curveFee, @@ -510,7 +520,7 @@ contract NegativeInterestLongFeeTest is HyperdriveTest { deploy( alice, apr, - initialSharePrice, + initialVaultSharePrice, curveFee, flatFee, governanceFee, @@ -522,12 +532,13 @@ contract NegativeInterestLongFeeTest is HyperdriveTest { // fast forward time and accrue interest advanceTime(POSITION_DURATION, preTradeVariableInterest); - // Record the openSharePrice after interest accrual. - (uint256 openSharePrice, ) = HyperdriveUtils.calculateCompoundInterest( - initialSharePrice, - preTradeVariableInterest, - POSITION_DURATION - ); + // Record the openVaultSharePrice after interest accrual. + (uint256 openVaultSharePrice, ) = HyperdriveUtils + .calculateCompoundInterest( + initialVaultSharePrice, + preTradeVariableInterest, + POSITION_DURATION + ); { // Ensure that the governance initially has zero balance @@ -548,7 +559,7 @@ contract NegativeInterestLongFeeTest is HyperdriveTest { DepositOverrides({ asBase: true, depositAmount: basePaid, - minSharePrice: 0, + minVaultSharePrice: 0, minSlippage: 0, // TODO: This should never go below the base amount. Investigate this. maxSlippage: type(uint256).max, extraData: new bytes(0) @@ -568,7 +579,7 @@ contract NegativeInterestLongFeeTest is HyperdriveTest { uint256 expectedGovernanceFees = (ONE.divDown(calculatedSpotPrice) - ONE).mulDown(basePaid).mulDown(curveFee).mulDivDown( calculatedSpotPrice, - openSharePrice + openVaultSharePrice ); assertApproxEqAbs( governanceFeesAfterOpenLong, @@ -594,12 +605,12 @@ contract NegativeInterestLongFeeTest is HyperdriveTest { // Calculate the flat and curve fees and compare then to the actual fees uint256 expectedFlat = bondAmount - .mulDivDown(ONE - normalizedTimeRemaining, openSharePrice) + .mulDivDown(ONE - normalizedTimeRemaining, openVaultSharePrice) .mulDown(flatFee); uint256 expectedCurve = (ONE - calculatedSpotPrice) .mulDown(0.1e18) .mulDown(bondAmount) - .mulDivDown(normalizedTimeRemaining, openSharePrice); + .mulDivDown(normalizedTimeRemaining, openVaultSharePrice); assertApproxEqAbs( governanceFeesAfterCloseLong, (expectedFlat + expectedCurve), diff --git a/test/integrations/hyperdrive/NegativeInterestShortFeeTest.t.sol b/test/integrations/hyperdrive/NegativeInterestShortFeeTest.t.sol index 012c9665b..aeb869cf3 100644 --- a/test/integrations/hyperdrive/NegativeInterestShortFeeTest.t.sol +++ b/test/integrations/hyperdrive/NegativeInterestShortFeeTest.t.sol @@ -14,19 +14,22 @@ contract NegativeInterestShortFeeTest is HyperdriveTest { using Lib for *; function test_negative_interest_short_immediate_open_close_fees_fuzz( - uint256 initialSharePrice, + uint256 initialVaultSharePrice, int256 variableInterest ) external { // Fuzz inputs - // initialSharePrice [0.5,10] + // initialVaultSharePrice [0.5,10] // variableInterest [-50,0] - initialSharePrice = initialSharePrice.normalizeToRange(0.5e18, 10e18); + initialVaultSharePrice = initialVaultSharePrice.normalizeToRange( + 0.5e18, + 10e18 + ); variableInterest = -variableInterest.normalizeToRange(0, 0.5e18); uint256 curveFee = 0.1e18; uint256 flatFee = 0; uint256 governanceFee = 1e18; test_negative_interest_short_immediate_open_close_fees( - initialSharePrice, + initialVaultSharePrice, variableInterest, curveFee, flatFee, @@ -36,18 +39,18 @@ contract NegativeInterestShortFeeTest is HyperdriveTest { function test_negative_interest_short_immediate_open_close_fees() external { // This tests the following scenario: - // - initial_share_price > 1 + // - initial_vault_share_price > 1 // - negative interest causes the share price to go down // - a short is opened and immediately closed // - set the curve fee and governance fee to 100% to make the test easier to verify { - uint256 initialSharePrice = 1.5e18; + uint256 initialVaultSharePrice = 1.5e18; int256 variableInterest = -0.1e18; uint256 curveFee = 0.1e18; uint256 flatFee = 0; uint256 governanceFee = 1e18; test_negative_interest_short_immediate_open_close_fees( - initialSharePrice, + initialVaultSharePrice, variableInterest, curveFee, flatFee, @@ -56,18 +59,18 @@ contract NegativeInterestShortFeeTest is HyperdriveTest { } // This tests the following scenario: - // - initial_share_price = 1 + // - initial_vault_share_price = 1 // - negative interest causes the share price to go down // - a short is opened and immediately closed // - set the curve fee and governance fee to 100% to make the test easier to verify { - uint256 initialSharePrice = 1e18; + uint256 initialVaultSharePrice = 1e18; int256 variableInterest = -0.1e18; uint256 curveFee = 0.1e18; uint256 flatFee = 0; uint256 governanceFee = 1e18; test_negative_interest_short_immediate_open_close_fees( - initialSharePrice, + initialVaultSharePrice, variableInterest, curveFee, flatFee, @@ -76,18 +79,18 @@ contract NegativeInterestShortFeeTest is HyperdriveTest { } // This tests the following scenario: - // - initial_share_price < 1 + // - initial_vault_share_price < 1 // - negative interest causes the share price to go down // - a short is opened and immediately closed // - set the curve fee and governance fee to 100% to make the test easier to verify { - uint256 initialSharePrice = 0.95e18; + uint256 initialVaultSharePrice = 0.95e18; int256 variableInterest = -0.1e18; uint256 curveFee = 0.1e18; uint256 flatFee = 0; uint256 governanceFee = 1e18; test_negative_interest_short_immediate_open_close_fees( - initialSharePrice, + initialVaultSharePrice, variableInterest, curveFee, flatFee, @@ -97,7 +100,7 @@ contract NegativeInterestShortFeeTest is HyperdriveTest { } function test_negative_interest_short_immediate_open_close_fees( - uint256 initialSharePrice, + uint256 initialVaultSharePrice, int256 variableInterest, uint256 curveFee, uint256 flatFee, @@ -108,7 +111,7 @@ contract NegativeInterestShortFeeTest is HyperdriveTest { deploy( alice, apr, - initialSharePrice, + initialVaultSharePrice, curveFee, flatFee, governanceFee, @@ -120,9 +123,9 @@ contract NegativeInterestShortFeeTest is HyperdriveTest { // fast forward time and accrue interest advanceTime(POSITION_DURATION, variableInterest); - // Record the sharePrice after interest accrual. + // Record the vaultSharePrice after interest accrual. IHyperdrive.PoolInfo memory poolInfo = hyperdrive.getPoolInfo(); - uint256 sharePrice = poolInfo.sharePrice; + uint256 vaultSharePrice = poolInfo.vaultSharePrice; // Ensure that the governance initially has zero balance uint256 governanceBalanceBefore = baseToken.balanceOf(feeCollector); @@ -156,7 +159,7 @@ contract NegativeInterestShortFeeTest is HyperdriveTest { shortAmount, HyperdriveUtils.calculateTimeRemaining(hyperdrive, maturityTime), calculatedSpotPrice, - sharePrice, + vaultSharePrice, curveFee_, flatFee_, governanceFee_ @@ -177,8 +180,8 @@ contract NegativeInterestShortFeeTest is HyperdriveTest { shortAmount, HyperdriveUtils.calculateTimeRemaining(hyperdrive, maturityTime), calculatedSpotPrice, - sharePrice, - sharePrice, + vaultSharePrice, + vaultSharePrice, curveFee_, flatFee_, governanceFee_ @@ -191,14 +194,17 @@ contract NegativeInterestShortFeeTest is HyperdriveTest { } function test_negative_interest_short_full_term_fees_fuzz( - uint256 initialSharePrice, + uint256 initialVaultSharePrice, int256 preTradeVariableInterest, int256 variableInterest ) external { // Fuzz inputs - // initialSharePrice [0.5,10] + // initialVaultSharePrice [0.5,10] // variableInterest [-50,0] - initialSharePrice = initialSharePrice.normalizeToRange(.5e18, 10e18); + initialVaultSharePrice = initialVaultSharePrice.normalizeToRange( + .5e18, + 10e18 + ); preTradeVariableInterest = -preTradeVariableInterest.normalizeToRange( 0, .5e18 @@ -208,7 +214,7 @@ contract NegativeInterestShortFeeTest is HyperdriveTest { uint256 flatFee = 0.1e18; uint256 governanceFee = 1e18; test_negative_interest_short_full_term_fees( - initialSharePrice, + initialVaultSharePrice, preTradeVariableInterest, variableInterest, curveFee, @@ -219,21 +225,21 @@ contract NegativeInterestShortFeeTest is HyperdriveTest { function test_negative_interest_short_full_term_fees() external { // This tests the following scenario: - // - initial_share_price > 1 + // - initial_vault_share_price > 1 // - negative interest causes the share price to go down // - a short is opened // - negative interest accrues over the full term // - short is closed // - set the flat fee to 10% and governance fee to 100% to make the test easier to verify { - uint256 initialSharePrice = 1.5e18; + uint256 initialVaultSharePrice = 1.5e18; int256 preTradeVariableInterest = -0.05e18; int256 variableInterest = -0.1e18; uint256 curveFee = 0e18; uint256 flatFee = 0.1e18; uint256 governanceFee = 1e18; test_negative_interest_short_full_term_fees( - initialSharePrice, + initialVaultSharePrice, preTradeVariableInterest, variableInterest, curveFee, @@ -243,21 +249,21 @@ contract NegativeInterestShortFeeTest is HyperdriveTest { } // This tests the following scenario: - // - initial_share_price = 1 + // - initial_vault_share_price = 1 // - negative interest causes the share price to go down // - a short is opened // - negative interest accrues over the full term // - short is closed // - set the flat fee to 10% and governance fee to 100% to make the test easier to verify { - uint256 initialSharePrice = 1e18; + uint256 initialVaultSharePrice = 1e18; int256 preTradeVariableInterest = -0.05e18; int256 variableInterest = -0.1e18; uint256 curveFee = 0e18; uint256 flatFee = 0.1e18; uint256 governanceFee = 1e18; test_negative_interest_short_full_term_fees( - initialSharePrice, + initialVaultSharePrice, preTradeVariableInterest, variableInterest, curveFee, @@ -267,21 +273,21 @@ contract NegativeInterestShortFeeTest is HyperdriveTest { } // This tests the following scenario: - // - initial_share_price < 1 + // - initial_vault_share_price < 1 // - negative interest causes the share price to go down // - a short is opened // - negative interest accrues over the full term // - short is closed // - set the flat fee to 10% and governance fee to 100% to make the test easier to verify { - uint256 initialSharePrice = 0.95e18; + uint256 initialVaultSharePrice = 0.95e18; int256 preTradeVariableInterest = -0.05e18; int256 variableInterest = -0.1e18; uint256 curveFee = 0e18; uint256 flatFee = 0.1e18; uint256 governanceFee = 1e18; test_negative_interest_short_full_term_fees( - initialSharePrice, + initialVaultSharePrice, preTradeVariableInterest, variableInterest, curveFee, @@ -292,7 +298,7 @@ contract NegativeInterestShortFeeTest is HyperdriveTest { } function test_negative_interest_short_full_term_fees( - uint256 initialSharePrice, + uint256 initialVaultSharePrice, int256 preTradeVariableInterest, int256 variableInterest, uint256 curveFee, @@ -304,7 +310,7 @@ contract NegativeInterestShortFeeTest is HyperdriveTest { deploy( alice, apr, - initialSharePrice, + initialVaultSharePrice, curveFee, flatFee, governanceFee, @@ -316,8 +322,8 @@ contract NegativeInterestShortFeeTest is HyperdriveTest { // fast forward time and accrue interest advanceTime(POSITION_DURATION, preTradeVariableInterest); - // Record the openSharePrice after interest accrual. - uint256 openSharePrice = hyperdrive.getPoolInfo().sharePrice; + // Record the openVaultSharePrice after interest accrual. + uint256 openVaultSharePrice = hyperdrive.getPoolInfo().vaultSharePrice; // Ensure that the governance initially has zero balance uint256 governanceBalanceBefore = baseToken.balanceOf(feeCollector); @@ -341,7 +347,7 @@ contract NegativeInterestShortFeeTest is HyperdriveTest { asBase: true, // NOTE: Roughly double deposit amount needed to cover 100% flat fee depositAmount: shortAmount * 2, - minSharePrice: 0, + minVaultSharePrice: 0, minSlippage: 0, maxSlippage: type(uint256).max, extraData: new bytes(0) @@ -361,9 +367,9 @@ contract NegativeInterestShortFeeTest is HyperdriveTest { // Term matures and accrues interest advanceTime(POSITION_DURATION, variableInterest); - // Record the closeSharePrice after interest accrual. + // Record the closeVaultSharePrice after interest accrual. IHyperdrive.PoolInfo memory poolInfo = hyperdrive.getPoolInfo(); - uint256 closeSharePrice = poolInfo.sharePrice; + uint256 closeVaultSharePrice = poolInfo.vaultSharePrice; // Close the short. calculatedSpotPrice = HyperdriveUtils.calculateSpotPrice(hyperdrive); @@ -382,8 +388,8 @@ contract NegativeInterestShortFeeTest is HyperdriveTest { maturityTime ), calculatedSpotPrice, - closeSharePrice, - openSharePrice, + closeVaultSharePrice, + openVaultSharePrice, 0, .1e18, 1e18 @@ -393,14 +399,17 @@ contract NegativeInterestShortFeeTest is HyperdriveTest { } function test_negative_interest_short_half_term_fees_fuzz( - uint256 initialSharePrice, + uint256 initialVaultSharePrice, int256 preTradeVariableInterest, int256 variableInterest ) external { // Fuzz inputs - // initialSharePrice [0.5,10] + // initialVaultSharePrice [0.5,10] // variableInterest [-50,0] - initialSharePrice = initialSharePrice.normalizeToRange(.5e18, 10e18); + initialVaultSharePrice = initialVaultSharePrice.normalizeToRange( + .5e18, + 10e18 + ); preTradeVariableInterest = -preTradeVariableInterest.normalizeToRange( 0, .5e18 @@ -410,7 +419,7 @@ contract NegativeInterestShortFeeTest is HyperdriveTest { uint256 flatFee = 0.1e18; uint256 governanceFee = 1e18; test_negative_interest_short_half_term_fees( - initialSharePrice, + initialVaultSharePrice, preTradeVariableInterest, variableInterest, curveFee, @@ -421,7 +430,7 @@ contract NegativeInterestShortFeeTest is HyperdriveTest { function test_negative_interest_short_half_term_fees() external { // This tests the following scenario: - // - initial_share_price > 1 + // - initial_vault_share_price > 1 // - negative interest causes the share price to go down // - a short is opened // - negative interest accrues over the half the term @@ -429,14 +438,14 @@ contract NegativeInterestShortFeeTest is HyperdriveTest { // - set the flat fee to 10%, curve fee to 10% and governance fee to 100% to make the test easier to verify uint256 snapshotId = vm.snapshot(); { - uint256 initialSharePrice = 1.5e18; + uint256 initialVaultSharePrice = 1.5e18; int256 preTradeVariableInterest = -0.05e18; int256 variableInterest = -0.1e18; uint256 curveFee = 0.1e18; uint256 flatFee = 0.1e18; uint256 governanceFee = 1e18; test_negative_interest_short_half_term_fees( - initialSharePrice, + initialVaultSharePrice, preTradeVariableInterest, variableInterest, curveFee, @@ -447,7 +456,7 @@ contract NegativeInterestShortFeeTest is HyperdriveTest { vm.revertTo(snapshotId); // This tests the following scenario: - // - initial_share_price = 1 + // - initial_vault_share_price = 1 // - negative interest causes the share price to go down // - a short is opened // - negative interest accrues over the half the term @@ -455,14 +464,14 @@ contract NegativeInterestShortFeeTest is HyperdriveTest { // - set the flat fee to 10%, curve fee to 10% and governance fee to 100% to make the test easier to verify snapshotId = vm.snapshot(); { - uint256 initialSharePrice = 1e18; + uint256 initialVaultSharePrice = 1e18; int256 preTradeVariableInterest = -0.05e18; int256 variableInterest = -0.1e18; uint256 curveFee = 0.1e18; uint256 flatFee = 0.1e18; uint256 governanceFee = 1e18; test_negative_interest_short_half_term_fees( - initialSharePrice, + initialVaultSharePrice, preTradeVariableInterest, variableInterest, curveFee, @@ -473,7 +482,7 @@ contract NegativeInterestShortFeeTest is HyperdriveTest { vm.revertTo(snapshotId); // This tests the following scenario: - // - initial_share_price < 1 + // - initial_vault_share_price < 1 // - negative interest causes the share price to go down // - a short is opened // - negative interest accrues over the half the term @@ -481,14 +490,14 @@ contract NegativeInterestShortFeeTest is HyperdriveTest { // - set the flat fee to 10%, curve fee to 10% and governance fee to 100% to make the test easier to verify snapshotId = vm.snapshot(); { - uint256 initialSharePrice = 0.95e18; + uint256 initialVaultSharePrice = 0.95e18; int256 preTradeVariableInterest = -0.05e18; int256 variableInterest = -0.1e18; uint256 curveFee = 0.1e18; uint256 flatFee = 0.1e18; uint256 governanceFee = 1e18; test_negative_interest_short_half_term_fees( - initialSharePrice, + initialVaultSharePrice, preTradeVariableInterest, variableInterest, curveFee, @@ -500,7 +509,7 @@ contract NegativeInterestShortFeeTest is HyperdriveTest { } function test_negative_interest_short_half_term_fees( - uint256 initialSharePrice, + uint256 initialVaultSharePrice, int256 preTradeVariableInterest, int256 variableInterest, uint256 curveFee, @@ -512,7 +521,7 @@ contract NegativeInterestShortFeeTest is HyperdriveTest { deploy( alice, apr, - initialSharePrice, + initialVaultSharePrice, curveFee, flatFee, governanceFee, @@ -524,9 +533,9 @@ contract NegativeInterestShortFeeTest is HyperdriveTest { // fast forward time and accrue interest advanceTime(POSITION_DURATION, preTradeVariableInterest); - // Record the openSharePrice after interest accrual. + // Record the openVaultSharePrice after interest accrual. IHyperdrive.PoolInfo memory poolInfo = hyperdrive.getPoolInfo(); - uint256 openSharePrice = poolInfo.sharePrice; + uint256 openVaultSharePrice = poolInfo.vaultSharePrice; { // Ensure that the governance initially has zero balance uint256 governanceBalanceBefore = baseToken.balanceOf(feeCollector); @@ -550,7 +559,7 @@ contract NegativeInterestShortFeeTest is HyperdriveTest { asBase: true, // NOTE: Roughly double deposit amount needed to cover 100% flat fee depositAmount: shortAmount * 2, - minSharePrice: 0, + minVaultSharePrice: 0, minSlippage: 0, maxSlippage: type(uint256).max, extraData: new bytes(0) @@ -571,7 +580,7 @@ contract NegativeInterestShortFeeTest is HyperdriveTest { maturityTime ), calculatedSpotPrice, - openSharePrice, + openVaultSharePrice, .1e18, .1e18, 1e18 @@ -582,9 +591,9 @@ contract NegativeInterestShortFeeTest is HyperdriveTest { // 1/2 term matures and accrues interest advanceTime(POSITION_DURATION / 2, variableInterest); - // Record the closeSharePrice after interest accrual. + // Record the closeVaultSharePrice after interest accrual. poolInfo = hyperdrive.getPoolInfo(); - uint256 closeSharePrice = poolInfo.sharePrice; + uint256 closeVaultSharePrice = poolInfo.vaultSharePrice; // Close the short. calculatedSpotPrice = HyperdriveUtils.calculateSpotPrice(hyperdrive); @@ -603,8 +612,8 @@ contract NegativeInterestShortFeeTest is HyperdriveTest { maturityTime ), calculatedSpotPrice, - closeSharePrice, - openSharePrice, + closeVaultSharePrice, + openVaultSharePrice, .1e18, .1e18, 1e18 @@ -617,7 +626,7 @@ contract NegativeInterestShortFeeTest is HyperdriveTest { uint256 bondAmount, uint256 normalizedTimeRemaining, uint256 calculatedSpotPrice, - uint256 sharePrice, + uint256 vaultSharePrice, uint256 curveFee, uint256 flatFee, uint256 governanceFee @@ -625,11 +634,11 @@ contract NegativeInterestShortFeeTest is HyperdriveTest { uint256 totalCurveFee = (ONE - calculatedSpotPrice) .mulDown(curveFee) .mulDown(bondAmount) - .mulDivDown(normalizedTimeRemaining, sharePrice); + .mulDivDown(normalizedTimeRemaining, vaultSharePrice); uint256 totalGovernanceFee = totalCurveFee.mulDown(governanceFee); uint256 flat = bondAmount.mulDivDown( ONE - normalizedTimeRemaining, - sharePrice + vaultSharePrice ); uint256 totalFlatFee = (flat.mulDown(flatFee)); totalGovernanceFee += totalFlatFee.mulDown(governanceFee); @@ -640,8 +649,8 @@ contract NegativeInterestShortFeeTest is HyperdriveTest { uint256 bondAmount, uint256 normalizedTimeRemaining, uint256 calculatedSpotPrice, - uint256 sharePrice, - uint256 openSharePrice, + uint256 vaultSharePrice, + uint256 openVaultSharePrice, uint256 curveFee, uint256 flatFee, uint256 governanceFee @@ -650,14 +659,15 @@ contract NegativeInterestShortFeeTest is HyperdriveTest { totalCurveFee = totalCurveFee .mulDown(curveFee) .mulDown(bondAmount) - .mulDivDown(normalizedTimeRemaining, sharePrice); + .mulDivDown(normalizedTimeRemaining, vaultSharePrice); uint256 totalGovernanceFee = totalCurveFee.mulDown(governanceFee); uint256 flat = bondAmount.mulDivDown( ONE - normalizedTimeRemaining, - sharePrice + vaultSharePrice ); uint256 totalFlatFee = (flat.mulDown(flatFee)); totalGovernanceFee += totalFlatFee.mulDown(governanceFee); - return totalGovernanceFee.mulDivDown(sharePrice, openSharePrice); + return + totalGovernanceFee.mulDivDown(vaultSharePrice, openVaultSharePrice); } } diff --git a/test/integrations/hyperdrive/NonstandardDecimals.sol b/test/integrations/hyperdrive/NonstandardDecimals.sol index e28b969ed..951dd6087 100644 --- a/test/integrations/hyperdrive/NonstandardDecimals.sol +++ b/test/integrations/hyperdrive/NonstandardDecimals.sol @@ -36,7 +36,7 @@ contract NonstandardDecimalsTest is HyperdriveTest { 1e18, POSITION_DURATION ); - config.initialSharePrice = 0.7348e18; + config.initialVaultSharePrice = 0.7348e18; config.minimumShareReserves = 1e6; config.minimumTransactionAmount = 1e6; deploy(deployer, config); @@ -517,7 +517,7 @@ contract NonstandardDecimalsTest is HyperdriveTest { DepositOverrides memory overrides = DepositOverrides({ asBase: true, depositAmount: testParams.contribution, - minSharePrice: 0, // unused + minVaultSharePrice: 0, // unused minSlippage: spotAPRBefore - 0.015e18, // min spot rate of .5% maxSlippage: spotAPRBefore + 0.015e18, // max spot rate of 3.5% extraData: new bytes(0) // unused diff --git a/test/integrations/hyperdrive/ReentrancyTest.t.sol b/test/integrations/hyperdrive/ReentrancyTest.t.sol index c16e45b23..82251a869 100644 --- a/test/integrations/hyperdrive/ReentrancyTest.t.sol +++ b/test/integrations/hyperdrive/ReentrancyTest.t.sol @@ -289,7 +289,7 @@ contract ReentrancyTest is HyperdriveTest { DepositOverrides({ asBase: true, depositAmount: CONTRIBUTION + 1, - minSharePrice: 0, + minVaultSharePrice: 0, minSlippage: 0, maxSlippage: type(uint256).max, extraData: new bytes(0) @@ -318,7 +318,7 @@ contract ReentrancyTest is HyperdriveTest { DepositOverrides({ asBase: true, depositAmount: CONTRIBUTION + 1, - minSharePrice: 0, + minVaultSharePrice: 0, minSlippage: 0, maxSlippage: type(uint256).max, extraData: new bytes(0) @@ -385,7 +385,7 @@ contract ReentrancyTest is HyperdriveTest { DepositOverrides({ asBase: true, depositAmount: BASE_PAID + 1, - minSharePrice: 0, + minVaultSharePrice: 0, minSlippage: 0, maxSlippage: type(uint256).max, extraData: new bytes(0) @@ -426,7 +426,7 @@ contract ReentrancyTest is HyperdriveTest { asBase: true, // NOTE: Roughly double deposit amount needed to cover 100% flat fee depositAmount: BOND_AMOUNT * 2, - minSharePrice: 0, + minVaultSharePrice: 0, minSlippage: 0, maxSlippage: type(uint256).max, extraData: new bytes(0) @@ -445,7 +445,7 @@ contract ReentrancyTest is HyperdriveTest { asBase: true, // NOTE: Roughly double deposit amount needed to cover 100% flat fee depositAmount: BOND_AMOUNT * 2, - minSharePrice: 0, + minVaultSharePrice: 0, minSlippage: 0, maxSlippage: type(uint256).max, extraData: new bytes(0) diff --git a/test/integrations/hyperdrive/VariableInterestLongTest.t.sol b/test/integrations/hyperdrive/VariableInterestLongTest.t.sol index 13ec90b47..b0c312c98 100644 --- a/test/integrations/hyperdrive/VariableInterestLongTest.t.sol +++ b/test/integrations/hyperdrive/VariableInterestLongTest.t.sol @@ -13,88 +13,91 @@ contract VariableInterestLongTest is HyperdriveTest { using Lib for *; function test_positive_negative_interest_long_immediate_open_close_fuzz( - uint256 initialSharePrice, + uint256 initialVaultSharePrice, int256 variableInterest ) external { // Fuzz inputs - // initialSharePrice [0.1,5] + // initialVaultSharePrice [0.1,5] // variableInterest [-50,50] - initialSharePrice = initialSharePrice.normalizeToRange(.1e18, 5e18); + initialVaultSharePrice = initialVaultSharePrice.normalizeToRange( + .1e18, + 5e18 + ); variableInterest = variableInterest.normalizeToRange(-.5e18, .5e18); - immediate_open_close(initialSharePrice, variableInterest); + immediate_open_close(initialVaultSharePrice, variableInterest); } function test_positive_interest_long_immediate_open_close() external { // This tests the following scenario: - // - initial_share_price > 1 + // - initial_vault_share_price > 1 // - positive interest causes the share price to go up // - a long is opened and immediately closed { - uint256 initialSharePrice = 1.5e18; + uint256 initialVaultSharePrice = 1.5e18; int256 variableInterest = 0.05e18; - immediate_open_close(initialSharePrice, variableInterest); + immediate_open_close(initialVaultSharePrice, variableInterest); } // This tests the following scenario: - // - initial_share_price = 1 + // - initial_vault_share_price = 1 // - positive interest causes the share price to go to up // - a long is opened and immediately closed { - uint256 initialSharePrice = 1e18; + uint256 initialVaultSharePrice = 1e18; int256 variableInterest = 0.05e18; - immediate_open_close(initialSharePrice, variableInterest); + immediate_open_close(initialVaultSharePrice, variableInterest); } // This tests the following scenario: - // - initial_share_price < 1 + // - initial_vault_share_price < 1 // - positive interest causes the share price to go up // - a long is opened and immediately closed { - uint256 initialSharePrice = 0.95e18; + uint256 initialVaultSharePrice = 0.95e18; int256 variableInterest = 0.10e18; - immediate_open_close(initialSharePrice, variableInterest); + immediate_open_close(initialVaultSharePrice, variableInterest); } } function test_negative_interest_long_immediate_open_close() external { // This tests the following scenario: - // - initial_share_price > 1 + // - initial_vault_share_price > 1 // - negative interest causes the share price to go down // - a long is opened and immediately closed { - uint256 initialSharePrice = 1.5e18; + uint256 initialVaultSharePrice = 1.5e18; int256 variableInterest = -0.05e18; - immediate_open_close(initialSharePrice, variableInterest); + immediate_open_close(initialVaultSharePrice, variableInterest); } // This tests the following scenario: - // - initial_share_price = 1 + // - initial_vault_share_price = 1 // - negative interest causes the share price to go to < 1 // - a long is opened and immediately closed { - uint256 initialSharePrice = 1e18; + uint256 initialVaultSharePrice = 1e18; int256 variableInterest = -0.05e18; - immediate_open_close(initialSharePrice, variableInterest); + immediate_open_close(initialVaultSharePrice, variableInterest); } // This tests the following scenario: - // - initial_share_price < 1 + // - initial_vault_share_price < 1 // - negative interest causes the share price to go to further < 1 // - a long is opened and immediately closed { - uint256 initialSharePrice = 0.95e18; + uint256 initialVaultSharePrice = 0.95e18; int256 variableInterest = -0.05e18; - immediate_open_close(initialSharePrice, variableInterest); + immediate_open_close(initialVaultSharePrice, variableInterest); } } function immediate_open_close( - uint256 initialSharePrice, + uint256 initialVaultSharePrice, int256 variableInterest ) internal { // Initialize the market uint256 apr = 0.05e18; - deploy(alice, apr, initialSharePrice, 0, 0, 0, 0); + deploy(alice, apr, initialVaultSharePrice, 0, 0, 0, 0); uint256 contribution = 500_000_000e18; initialize(alice, apr, contribution); @@ -114,22 +117,25 @@ contract VariableInterestLongTest is HyperdriveTest { } function test_positive_negative_interest_long_full_term_fuzz( - uint256 initialSharePrice, + uint256 initialVaultSharePrice, int256 preTradeVariableInterest, int256 variableInterest ) external { // Fuzz inputs - // initialSharePrice [0.1,5] + // initialVaultSharePrice [0.1,5] // preTradeVariableInterest [-50,50] // variableInterest [-50,50] - initialSharePrice = initialSharePrice.normalizeToRange(.1e18, 5e18); + initialVaultSharePrice = initialVaultSharePrice.normalizeToRange( + .1e18, + 5e18 + ); preTradeVariableInterest = preTradeVariableInterest.normalizeToRange( -0.5e18, 0.5e18 ); variableInterest = variableInterest.normalizeToRange(-0.5e18, 0.5e18); full_term( - initialSharePrice, + initialVaultSharePrice, preTradeVariableInterest, variableInterest ); @@ -137,51 +143,51 @@ contract VariableInterestLongTest is HyperdriveTest { function test_positive_interest_long_full_term() external { // This tests the following scenario: - // - initial_share_price > 1 + // - initial_vault_share_price > 1 // - positive interest causes the share price to go up // - a long is opened // - positive interest accrues over the full term // - long is closed { - uint256 initialSharePrice = 1.5e18; + uint256 initialVaultSharePrice = 1.5e18; int256 preTradeVariableInterest = 0.10e18; int256 variableInterest = 0.05e18; full_term( - initialSharePrice, + initialVaultSharePrice, preTradeVariableInterest, variableInterest ); } // This tests the following scenario: - // - initial_share_price = 1 + // - initial_vault_share_price = 1 // - positive interest causes the share price to go up // - a long is opened // - positive interest accrues over the full term // - long is closed { - uint256 initialSharePrice = 1e18; + uint256 initialVaultSharePrice = 1e18; int256 preTradeVariableInterest = 0.10e18; int256 variableInterest = 0.05e18; full_term( - initialSharePrice, + initialVaultSharePrice, preTradeVariableInterest, variableInterest ); } // This tests the following scenario: - // - initial_share_price < 1 + // - initial_vault_share_price < 1 // - positive interest causes the share price to go up // - a long is opened // - positive interest accrues over the full term // - long is closed { - uint256 initialSharePrice = 0.95e18; + uint256 initialVaultSharePrice = 0.95e18; int256 preTradeVariableInterest = 0.10e18; int256 variableInterest = 0.05e18; full_term( - initialSharePrice, + initialVaultSharePrice, preTradeVariableInterest, variableInterest ); @@ -190,51 +196,51 @@ contract VariableInterestLongTest is HyperdriveTest { function test_negative_interest_long_full_term() external { // This tests the following scenario: - // - initial_share_price > 1 + // - initial_vault_share_price > 1 // - negative interest causes the share price to go down // - a long is opened // - negative interest accrues over the full term // - long is closed { - uint256 initialSharePrice = 1.5e18; + uint256 initialVaultSharePrice = 1.5e18; int256 preTradeVariableInterest = -0.10e18; int256 variableInterest = -0.05e18; full_term( - initialSharePrice, + initialVaultSharePrice, preTradeVariableInterest, variableInterest ); } // This tests the following scenario: - // - initial_share_price = 1 + // - initial_vault_share_price = 1 // - negative interest causes the share price to go down // - a long is opened // - negative interest accrues over the full term // - long is closed { - uint256 initialSharePrice = 1e18; + uint256 initialVaultSharePrice = 1e18; int256 preTradeVariableInterest = -0.10e18; int256 variableInterest = -0.05e18; full_term( - initialSharePrice, + initialVaultSharePrice, preTradeVariableInterest, variableInterest ); } // This tests the following scenario: - // - initial_share_price < 1 + // - initial_vault_share_price < 1 // - negative interest causes the share price to go further down // - a long is opened // - negative interest accrues over the full term // - long is closed { - uint256 initialSharePrice = 0.95e18; + uint256 initialVaultSharePrice = 0.95e18; int256 preTradeVariableInterest = -0.10e18; int256 variableInterest = -0.05e18; full_term( - initialSharePrice, + initialVaultSharePrice, preTradeVariableInterest, variableInterest ); @@ -242,20 +248,20 @@ contract VariableInterestLongTest is HyperdriveTest { } function full_term( - uint256 initialSharePrice, + uint256 initialVaultSharePrice, int256 preTradeVariableInterest, int256 variableInterest ) internal { // Initialize the market uint256 apr = 0.05e18; - deploy(alice, apr, initialSharePrice, 0, 0, 0, 0); + deploy(alice, apr, initialVaultSharePrice, 0, 0, 0, 0); uint256 contribution = 500_000_000e18; initialize(alice, apr, contribution); // fast forward time and accrue negative interest advanceTime(POSITION_DURATION, preTradeVariableInterest); IHyperdrive.PoolInfo memory poolInfo = hyperdrive.getPoolInfo(); - uint256 openSharePrice = poolInfo.sharePrice; + uint256 openVaultSharePrice = poolInfo.vaultSharePrice; // Open a long position. uint256 basePaid = 10_000e18; @@ -264,14 +270,14 @@ contract VariableInterestLongTest is HyperdriveTest { // Full term passes advanceTime(POSITION_DURATION, variableInterest); poolInfo = hyperdrive.getPoolInfo(); - uint256 closeSharePrice = poolInfo.sharePrice; + uint256 closeVaultSharePrice = poolInfo.vaultSharePrice; // Estimate the proceeds uint256 estimatedProceeds = estimateLongProceeds( bondAmount, HyperdriveUtils.calculateTimeRemaining(hyperdrive, maturityTime), - openSharePrice, - closeSharePrice + openVaultSharePrice, + closeVaultSharePrice ); // Close the long @@ -280,22 +286,25 @@ contract VariableInterestLongTest is HyperdriveTest { } function test_positive_negative_interest_long_half_term_fuzz( - uint256 initialSharePrice, + uint256 initialVaultSharePrice, int256 preTradeVariableInterest, int256 variableInterest ) external { // Fuzz inputs - // initialSharePrice [0.1,5] + // initialVaultSharePrice [0.1,5] // preTradeVariableInterest [-50,50] // variableInterest [-50,50] - initialSharePrice = initialSharePrice.normalizeToRange(.1e18, 5e18); + initialVaultSharePrice = initialVaultSharePrice.normalizeToRange( + .1e18, + 5e18 + ); preTradeVariableInterest = preTradeVariableInterest.normalizeToRange( -0.5e18, 0.5e18 ); variableInterest = variableInterest.normalizeToRange(-0.5e18, 0.5e18); half_term( - initialSharePrice, + initialVaultSharePrice, preTradeVariableInterest, variableInterest ); @@ -303,51 +312,51 @@ contract VariableInterestLongTest is HyperdriveTest { function test_positive_interest_long_half_term() external { // This tests the following scenario: - // - initial_share_price > 1 + // - initial_vault_share_price > 1 // - positive interest causes the share price to go up // - a long is opened // - positive interest accrues over half term // - long is closed { - uint256 initialSharePrice = 1.5e18; + uint256 initialVaultSharePrice = 1.5e18; int256 preTradeVariableInterest = 0.10e18; int256 variableInterest = 0.05e18; half_term( - initialSharePrice, + initialVaultSharePrice, preTradeVariableInterest, variableInterest ); } // This tests the following scenario: - // - initial_share_price = 1 + // - initial_vault_share_price = 1 // - positive interest causes the share price to go up // - a long is opened // - positive interest accrues over half term // - long is closed { - uint256 initialSharePrice = 1e18; + uint256 initialVaultSharePrice = 1e18; int256 preTradeVariableInterest = 0.10e18; int256 variableInterest = 0.05e18; half_term( - initialSharePrice, + initialVaultSharePrice, preTradeVariableInterest, variableInterest ); } // This tests the following scenario: - // - initial_share_price < 1 + // - initial_vault_share_price < 1 // - positive interest causes the share price to go up // - a long is opened // - positive interest accrues over half term // - long is closed { - uint256 initialSharePrice = 0.95e18; + uint256 initialVaultSharePrice = 0.95e18; int256 preTradeVariableInterest = 0.10e18; int256 variableInterest = 0.05e18; half_term( - initialSharePrice, + initialVaultSharePrice, preTradeVariableInterest, variableInterest ); @@ -356,51 +365,51 @@ contract VariableInterestLongTest is HyperdriveTest { function test_negative_interest_long_half_term() external { // This tests the following scenario: - // - initial_share_price > 1 + // - initial_vault_share_price > 1 // - negative interest causes the share price to go down // - a long is opened // - negative interest accrues over half term // - long is closed { - uint256 initialSharePrice = 1.5e18; + uint256 initialVaultSharePrice = 1.5e18; int256 preTradeVariableInterest = -0.10e18; int256 variableInterest = -0.05e18; half_term( - initialSharePrice, + initialVaultSharePrice, preTradeVariableInterest, variableInterest ); } // This tests the following scenario: - // - initial_share_price = 1 + // - initial_vault_share_price = 1 // - negative interest causes the share price to go down // - a long is opened // - negative interest accrues over half term // - long is closed { - uint256 initialSharePrice = 1e18; + uint256 initialVaultSharePrice = 1e18; int256 preTradeVariableInterest = -0.10e18; int256 variableInterest = -0.05e18; half_term( - initialSharePrice, + initialVaultSharePrice, preTradeVariableInterest, variableInterest ); } // This tests the following scenario: - // - initial_share_price < 1 + // - initial_vault_share_price < 1 // - negative interest causes the share price to go further down // - a long is opened // - negative interest accrues over half term // - long is closed { - uint256 initialSharePrice = 0.90e18; + uint256 initialVaultSharePrice = 0.90e18; int256 preTradeVariableInterest = -0.10e18; int256 variableInterest = -0.05e18; half_term( - initialSharePrice, + initialVaultSharePrice, preTradeVariableInterest, variableInterest ); @@ -408,20 +417,20 @@ contract VariableInterestLongTest is HyperdriveTest { } function half_term( - uint256 initialSharePrice, + uint256 initialVaultSharePrice, int256 preTradeVariableInterest, int256 variableInterest ) internal { // Initialize the market uint256 apr = 0.05e18; - deploy(alice, apr, initialSharePrice, 0, 0, 0, 0); + deploy(alice, apr, initialVaultSharePrice, 0, 0, 0, 0); uint256 contribution = 500_000_000e18; initialize(alice, apr, contribution); // fast forward time and accrue negative interest advanceTime(POSITION_DURATION, preTradeVariableInterest); IHyperdrive.PoolInfo memory poolInfo = hyperdrive.getPoolInfo(); - uint256 openSharePrice = poolInfo.sharePrice; + uint256 openVaultSharePrice = poolInfo.vaultSharePrice; // Open a long position. uint256 basePaid = 10_000e18; @@ -432,12 +441,12 @@ contract VariableInterestLongTest is HyperdriveTest { // Estimate the proceeds. poolInfo = hyperdrive.getPoolInfo(); - uint256 closeSharePrice = poolInfo.sharePrice; + uint256 closeVaultSharePrice = poolInfo.vaultSharePrice; uint256 estimatedProceeds = estimateLongProceeds( bondAmount, HyperdriveUtils.calculateTimeRemaining(hyperdrive, maturityTime), - openSharePrice, - closeSharePrice + openVaultSharePrice, + closeVaultSharePrice ); // Close the long. diff --git a/test/integrations/hyperdrive/VariableInterestShortTest.t.sol b/test/integrations/hyperdrive/VariableInterestShortTest.t.sol index d241a24fa..4f6368bc3 100644 --- a/test/integrations/hyperdrive/VariableInterestShortTest.t.sol +++ b/test/integrations/hyperdrive/VariableInterestShortTest.t.sol @@ -89,88 +89,91 @@ contract VariableInterestShortTest is HyperdriveTest { } function test_positive_negative_interest_short_immediate_open_close_fuzz( - uint256 initialSharePrice, + uint256 initialVaultSharePrice, int256 variableInterest ) external { // Fuzz inputs - // initialSharePrice [0.1,5] + // initialVaultSharePrice [0.1,5] // variableInterest [-50,50] - initialSharePrice = initialSharePrice.normalizeToRange(.1e18, 5e18); + initialVaultSharePrice = initialVaultSharePrice.normalizeToRange( + .1e18, + 5e18 + ); variableInterest = variableInterest.normalizeToRange(-.5e18, .5e18); - immediate_open_close(initialSharePrice, variableInterest); + immediate_open_close(initialVaultSharePrice, variableInterest); } function test_positive_interest_short_immediate_open_close() external { // This tests the following scenario: - // - initial_share_price > 1 + // - initial_vault_share_price > 1 // - positive interest causes the share price to go up // - a short is opened and immediately closed { - uint256 initialSharePrice = 1.5e18; + uint256 initialVaultSharePrice = 1.5e18; int256 variableInterest = 0.05e18; - immediate_open_close(initialSharePrice, variableInterest); + immediate_open_close(initialVaultSharePrice, variableInterest); } // This tests the following scenario: - // - initial_share_price = 1 + // - initial_vault_share_price = 1 // - positive interest causes the share price to go up // - a short is opened and immediately closed { - uint256 initialSharePrice = 1e18; + uint256 initialVaultSharePrice = 1e18; int256 variableInterest = 0.05e18; - immediate_open_close(initialSharePrice, variableInterest); + immediate_open_close(initialVaultSharePrice, variableInterest); } // This tests the following scenario: - // - initial_share_price < 1 + // - initial_vault_share_price < 1 // - positive interest causes the share price to go up // - a short is opened and immediately closed { - uint256 initialSharePrice = 0.95e18; + uint256 initialVaultSharePrice = 0.95e18; int256 variableInterest = 0.10e18; - immediate_open_close(initialSharePrice, variableInterest); + immediate_open_close(initialVaultSharePrice, variableInterest); } } function test_negative_interest_short_immediate_open_close() external { // This tests the following scenario: - // - initial_share_price > 1 + // - initial_vault_share_price > 1 // - negative interest causes the share price to go down // - a short is opened and immediately closed { - uint256 initialSharePrice = 1.5e18; + uint256 initialVaultSharePrice = 1.5e18; int256 variableInterest = -0.05e18; - immediate_open_close(initialSharePrice, variableInterest); + immediate_open_close(initialVaultSharePrice, variableInterest); } // This tests the following scenario: - // - initial_share_price = 1 + // - initial_vault_share_price = 1 // - negative interest causes the share price to go to < 1 // - a short is opened and immediately closed { - uint256 initialSharePrice = 1e18; + uint256 initialVaultSharePrice = 1e18; int256 variableInterest = -0.05e18; - immediate_open_close(initialSharePrice, variableInterest); + immediate_open_close(initialVaultSharePrice, variableInterest); } // This tests the following scenario: - // - initial_share_price < 1 + // - initial_vault_share_price < 1 // - negative interest causes the share price to go to further < 1 // - a short is opened and immediately closed { - uint256 initialSharePrice = 0.95e18; + uint256 initialVaultSharePrice = 0.95e18; int256 variableInterest = -0.05e18; - immediate_open_close(initialSharePrice, variableInterest); + immediate_open_close(initialVaultSharePrice, variableInterest); } } function immediate_open_close( - uint256 initialSharePrice, + uint256 initialVaultSharePrice, int256 variableInterest ) internal { // Initialize the market uint256 apr = 0.05e18; - deploy(alice, apr, initialSharePrice, 0, 0, 0, 0); + deploy(alice, apr, initialVaultSharePrice, 0, 0, 0, 0); uint256 contribution = 500_000_000e18; initialize(alice, apr, contribution); @@ -186,26 +189,29 @@ contract VariableInterestShortTest is HyperdriveTest { // It shouldn't be profitable to open and close a short position immediately assertGe(basePaid, baseProceeds); - assertApproxEqAbs(baseProceeds, basePaid, 1e11); // NOTE: This error grows with initialSharePrice and variableInterest + assertApproxEqAbs(baseProceeds, basePaid, 1e11); // NOTE: This error grows with initialVaultSharePrice and variableInterest } function test_positive_negative_interest_short_full_term_fuzz( - uint256 initialSharePrice, + uint256 initialVaultSharePrice, int256 preTradeVariableInterest, int256 variableInterest ) external { // Fuzz inputs - // initialSharePrice [0.1,5] + // initialVaultSharePrice [0.1,5] // preTradeVariableInterest [-50,50] // variableInterest [-50,50] - initialSharePrice = initialSharePrice.normalizeToRange(.1e18, 5e18); + initialVaultSharePrice = initialVaultSharePrice.normalizeToRange( + .1e18, + 5e18 + ); preTradeVariableInterest = preTradeVariableInterest.normalizeToRange( -0.5e18, 0.5e18 ); variableInterest = variableInterest.normalizeToRange(-0.5e18, 0.5e18); full_term( - initialSharePrice, + initialVaultSharePrice, preTradeVariableInterest, variableInterest ); @@ -213,51 +219,51 @@ contract VariableInterestShortTest is HyperdriveTest { function test_positive_interest_short_full_term() external { // This tests the following scenario: - // - initial_share_price > 1 + // - initial_vault_share_price > 1 // - positive interest causes the share price to go up // - a short is opened // - positive interest accrues over the full term // - short is closed { - uint256 initialSharePrice = 1.5e18; + uint256 initialVaultSharePrice = 1.5e18; int256 preTradeVariableInterest = 0.10e18; int256 variableInterest = 0.05e18; full_term( - initialSharePrice, + initialVaultSharePrice, preTradeVariableInterest, variableInterest ); } // This tests the following scenario: - // - initial_share_price = 1 + // - initial_vault_share_price = 1 // - positive interest causes the share price to go up // - a short is opened // - positive interest accrues over the full term // - short is closed { - uint256 initialSharePrice = 1e18; + uint256 initialVaultSharePrice = 1e18; int256 preTradeVariableInterest = 0.10e18; int256 variableInterest = 0.05e18; full_term( - initialSharePrice, + initialVaultSharePrice, preTradeVariableInterest, variableInterest ); } // This tests the following scenario: - // - initial_share_price < 1 + // - initial_vault_share_price < 1 // - positive interest causes the share price to go up // - a short is opened // - positive interest accrues over the full term // - short is closed { - uint256 initialSharePrice = 0.95e18; + uint256 initialVaultSharePrice = 0.95e18; int256 preTradeVariableInterest = 0.10e18; int256 variableInterest = 0.05e18; full_term( - initialSharePrice, + initialVaultSharePrice, preTradeVariableInterest, variableInterest ); @@ -266,17 +272,17 @@ contract VariableInterestShortTest is HyperdriveTest { function test_negative_interest_short_full_term() external { // This tests the following scenario: - // - initial_share_price > 1 + // - initial_vault_share_price > 1 // - negative interest causes the share price to go down // - a short is opened // - negative interest accrues over the full term // - short is closed { - uint256 initialSharePrice = 1.5e18; + uint256 initialVaultSharePrice = 1.5e18; int256 preTradeVariableInterest = -0.10e18; int256 variableInterest = -0.05e18; uint256 baseProceeds = full_term( - initialSharePrice, + initialVaultSharePrice, preTradeVariableInterest, variableInterest ); @@ -285,17 +291,17 @@ contract VariableInterestShortTest is HyperdriveTest { } // This tests the following scenario: - // - initial_share_price = 1 + // - initial_vault_share_price = 1 // - negative interest causes the share price to go down // - a short is opened // - negative interest accrues over the full term // - short is closed { - uint256 initialSharePrice = 1e18; + uint256 initialVaultSharePrice = 1e18; int256 preTradeVariableInterest = -0.10e18; int256 variableInterest = -0.05e18; uint256 baseProceeds = full_term( - initialSharePrice, + initialVaultSharePrice, preTradeVariableInterest, variableInterest ); @@ -304,17 +310,17 @@ contract VariableInterestShortTest is HyperdriveTest { } // This tests the following scenario: - // - initial_share_price < 1 + // - initial_vault_share_price < 1 // - negative interest causes the share price to go further down // - a short is opened // - negative interest accrues over the full term // - short is closed { - uint256 initialSharePrice = 0.95e18; + uint256 initialVaultSharePrice = 0.95e18; int256 preTradeVariableInterest = -0.10e18; int256 variableInterest = -0.05e18; uint256 baseProceeds = full_term( - initialSharePrice, + initialVaultSharePrice, preTradeVariableInterest, variableInterest ); @@ -324,13 +330,13 @@ contract VariableInterestShortTest is HyperdriveTest { } function full_term( - uint256 initialSharePrice, + uint256 initialVaultSharePrice, int256 preTradeVariableInterest, int256 variableInterest ) internal returns (uint256) { // Initialize the market uint256 apr = 0.05e18; - deploy(alice, apr, initialSharePrice, 0, 0, 0, 0); + deploy(alice, apr, initialVaultSharePrice, 0, 0, 0, 0); uint256 contribution = 500_000_000e18; initialize(alice, apr, contribution); @@ -359,22 +365,25 @@ contract VariableInterestShortTest is HyperdriveTest { } function test_positive_negative_interest_short_half_term_fuzz( - uint256 initialSharePrice, + uint256 initialVaultSharePrice, int256 preTradeVariableInterest, int256 variableInterest ) external { // Fuzz inputs - // initialSharePrice [0.1,5] + // initialVaultSharePrice [0.1,5] // preTradeVariableInterest [-50,50] // variableInterest [-50,50] - initialSharePrice = initialSharePrice.normalizeToRange(.1e18, 10e18); + initialVaultSharePrice = initialVaultSharePrice.normalizeToRange( + .1e18, + 10e18 + ); preTradeVariableInterest = preTradeVariableInterest.normalizeToRange( -0.5e18, 0.5e18 ); variableInterest = variableInterest.normalizeToRange(-0.5e18, 0.5e18); half_term( - initialSharePrice, + initialVaultSharePrice, preTradeVariableInterest, variableInterest ); @@ -382,51 +391,51 @@ contract VariableInterestShortTest is HyperdriveTest { function test_positive_interest_short_half_term() external { // This tests the following scenario: - // - initial_share_price > 1 + // - initial_vault_share_price > 1 // - positive interest causes the share price to go up // - a short is opened // - positive interest accrues over half term // - short is closed { - uint256 initialSharePrice = 1.5e18; + uint256 initialVaultSharePrice = 1.5e18; int256 preTradeVariableInterest = 0.10e18; int256 variableInterest = 0.05e18; half_term( - initialSharePrice, + initialVaultSharePrice, preTradeVariableInterest, variableInterest ); } // This tests the following scenario: - // - initial_share_price = 1 + // - initial_vault_share_price = 1 // - positive interest causes the share price to go up // - a short is opened // - positive interest accrues over half term // - short is closed { - uint256 initialSharePrice = 1e18; + uint256 initialVaultSharePrice = 1e18; int256 preTradeVariableInterest = 0.10e18; int256 variableInterest = 0.05e18; half_term( - initialSharePrice, + initialVaultSharePrice, preTradeVariableInterest, variableInterest ); } // This tests the following scenario: - // - initial_share_price < 1 + // - initial_vault_share_price < 1 // - positive interest causes the share price to go further down // - a short is opened // - positive interest accrues over half term // - short is closed { - uint256 initialSharePrice = 0.95e18; + uint256 initialVaultSharePrice = 0.95e18; int256 preTradeVariableInterest = 0.10e18; int256 variableInterest = 0.05e18; half_term( - initialSharePrice, + initialVaultSharePrice, preTradeVariableInterest, variableInterest ); @@ -435,51 +444,51 @@ contract VariableInterestShortTest is HyperdriveTest { function test_negative_interest_short_half_term() external { // This tests the following scenario: - // - initial_share_price > 1 + // - initial_vault_share_price > 1 // - negative interest causes the share price to go down // - a short is opened // - negative interest accrues over half term // - short is closed { - uint256 initialSharePrice = 1.5e18; + uint256 initialVaultSharePrice = 1.5e18; int256 preTradeVariableInterest = -0.10e18; int256 variableInterest = -0.05e18; half_term( - initialSharePrice, + initialVaultSharePrice, preTradeVariableInterest, variableInterest ); } // This tests the following scenario: - // - initial_share_price = 1 + // - initial_vault_share_price = 1 // - negative interest causes the share price to go down // - a short is opened // - negative interest accrues over half term // - short is closed { - uint256 initialSharePrice = 1e18; + uint256 initialVaultSharePrice = 1e18; int256 preTradeVariableInterest = -0.10e18; int256 variableInterest = -0.05e18; half_term( - initialSharePrice, + initialVaultSharePrice, preTradeVariableInterest, variableInterest ); } // This tests the following scenario: - // - initial_share_price < 1 + // - initial_vault_share_price < 1 // - negative interest causes the share price to go further down // - a short is opened // - negative interest accrues over half term // - short is closed { - uint256 initialSharePrice = 0.95e18; + uint256 initialVaultSharePrice = 0.95e18; int256 preTradeVariableInterest = -0.10e18; int256 variableInterest = -0.05e18; half_term( - initialSharePrice, + initialVaultSharePrice, preTradeVariableInterest, variableInterest ); @@ -487,13 +496,13 @@ contract VariableInterestShortTest is HyperdriveTest { } function half_term( - uint256 initialSharePrice, + uint256 initialVaultSharePrice, int256 preTradeVariableInterest, int256 variableInterest ) internal { // Initialize the market uint256 apr = 0.05e18; - deploy(alice, apr, initialSharePrice, 0, 0, 0, 0); + deploy(alice, apr, initialVaultSharePrice, 0, 0, 0, 0); uint256 contribution = 500_000_000e18; initialize(alice, apr, contribution); diff --git a/test/integrations/hyperdrive/ZombieInterestTest.t.sol b/test/integrations/hyperdrive/ZombieInterestTest.t.sol index fcfbede73..956052392 100644 --- a/test/integrations/hyperdrive/ZombieInterestTest.t.sol +++ b/test/integrations/hyperdrive/ZombieInterestTest.t.sol @@ -33,7 +33,7 @@ contract ZombieInterestTest is HyperdriveTest { function test_zombie_interest_long_lp_edge_cases() external { // This test found a case that resulted in: - // balanceOf(hyperdrive) = 0 and a sharePrice == 0 + // balanceOf(hyperdrive) = 0 and a vaultSharePrice == 0 // resulted in correcting the zombie interest formulat to: // dz * (c1 - c0)/c1 { @@ -142,12 +142,12 @@ contract ZombieInterestTest is HyperdriveTest { uint256 zombieBaseBefore = hyperdrive .getPoolInfo() .zombieShareReserves - .mulDown(hyperdrive.getPoolInfo().sharePrice); + .mulDown(hyperdrive.getPoolInfo().vaultSharePrice); advanceTimeWithCheckpoints2(POSITION_DURATION, variableRate); uint256 zombieBaseAfter = hyperdrive .getPoolInfo() .zombieShareReserves - .mulDown(hyperdrive.getPoolInfo().sharePrice); + .mulDown(hyperdrive.getPoolInfo().vaultSharePrice); assertApproxEqAbs(zombieBaseBefore, zombieBaseAfter, 1e5); // A random amount of time passes and interest is collected. @@ -184,19 +184,21 @@ contract ZombieInterestTest is HyperdriveTest { ); // If the share price is zero, then the hyperdrive balance is empty and there is a problem. - uint256 sharePrice = hyperdrive.getPoolInfo().sharePrice; - assertGt(sharePrice, 0); + uint256 vaultSharePrice = hyperdrive.getPoolInfo().vaultSharePrice; + assertGt(vaultSharePrice, 0); // Verify that the value represented in the share reserves is >= the actual amount in the contract. uint256 baseReserves = hyperdrive.getPoolInfo().shareReserves.mulDown( - sharePrice + vaultSharePrice ); assertGe(baseToken.balanceOf(address(hyperdrive)), baseReserves); // Ensure that whatever is left in the zombie share reserves is <= hyperdrive contract - baseReserves. // This is an important check bc it implies ongoing solvency. assertLe( - hyperdrive.getPoolInfo().zombieShareReserves.mulDown(sharePrice), + hyperdrive.getPoolInfo().zombieShareReserves.mulDown( + vaultSharePrice + ), baseToken.balanceOf(address(hyperdrive)) - baseReserves ); } @@ -366,12 +368,12 @@ contract ZombieInterestTest is HyperdriveTest { uint256 zombieBaseBefore = hyperdrive .getPoolInfo() .zombieShareReserves - .mulDown(hyperdrive.getPoolInfo().sharePrice); + .mulDown(hyperdrive.getPoolInfo().vaultSharePrice); advanceTimeWithCheckpoints2(POSITION_DURATION, variableRate); uint256 zombieBaseAfter = hyperdrive .getPoolInfo() .zombieShareReserves - .mulDown(hyperdrive.getPoolInfo().sharePrice); + .mulDown(hyperdrive.getPoolInfo().vaultSharePrice); assertApproxEqAbs(zombieBaseBefore, zombieBaseAfter, 1e5); // A random amount of time passes and interest is collected. @@ -409,12 +411,12 @@ contract ZombieInterestTest is HyperdriveTest { ); // If the share price is zero, then the hyperdrive balance is empty and there is a problem. - uint256 sharePrice = hyperdrive.getPoolInfo().sharePrice; - assertGt(sharePrice, 0); + uint256 vaultSharePrice = hyperdrive.getPoolInfo().vaultSharePrice; + assertGt(vaultSharePrice, 0); // Verify that the value represented in the share reserves is >= the actual amount in the contract. uint256 baseReserves = hyperdrive.getPoolInfo().shareReserves.mulDown( - sharePrice + vaultSharePrice ); assertGe(baseToken.balanceOf(address(hyperdrive)) + 1, baseReserves); @@ -422,7 +424,9 @@ contract ZombieInterestTest is HyperdriveTest { // less than `balance(hyperdrive) - baseReserves`. // This is an important check bc it implies ongoing solvency. assertLe( - hyperdrive.getPoolInfo().zombieShareReserves.mulDown(sharePrice), + hyperdrive.getPoolInfo().zombieShareReserves.mulDown( + vaultSharePrice + ), baseToken.balanceOf(address(hyperdrive)) + 10 wei - baseReserves ); } @@ -454,12 +458,12 @@ contract ZombieInterestTest is HyperdriveTest { uint256 zombieBaseBefore = hyperdrive .getPoolInfo() .zombieShareReserves - .mulDown(hyperdrive.getPoolInfo().sharePrice); + .mulDown(hyperdrive.getPoolInfo().vaultSharePrice); advanceTimeWithCheckpoints2(POSITION_DURATION, variableRate); uint256 zombieBaseAfter = hyperdrive .getPoolInfo() .zombieShareReserves - .mulDown(hyperdrive.getPoolInfo().sharePrice); + .mulDown(hyperdrive.getPoolInfo().vaultSharePrice); assertApproxEqAbs(zombieBaseBefore, zombieBaseAfter, 1e5); // Celina redeems her short late. @@ -476,19 +480,21 @@ contract ZombieInterestTest is HyperdriveTest { ); // If the share price is zero, then the hyperdrive balance is empty and there is a problem. - uint256 sharePrice = hyperdrive.getPoolInfo().sharePrice; - assertGt(sharePrice, 0); + uint256 vaultSharePrice = hyperdrive.getPoolInfo().vaultSharePrice; + assertGt(vaultSharePrice, 0); // Verify that the value represented in the share reserves is <= the actual amount in the contract. uint256 baseReserves = hyperdrive.getPoolInfo().shareReserves.mulDown( - sharePrice + vaultSharePrice ); assertGe(baseToken.balanceOf(address(hyperdrive)), baseReserves); // Ensure that whatever is left in the zombie share reserves is <= hyperdrive contract - baseReserves. // This is an important check bc it implies ongoing solvency. assertLe( - hyperdrive.getPoolInfo().zombieShareReserves.mulDown(sharePrice), + hyperdrive.getPoolInfo().zombieShareReserves.mulDown( + vaultSharePrice + ), baseToken.balanceOf(address(hyperdrive)) - baseReserves ); } diff --git a/test/units/ForceRevertDelegatecall.t.sol b/test/units/ForceRevertDelegatecall.t.sol index 91bd5cccc..1c055acfe 100644 --- a/test/units/ForceRevertDelegatecall.t.sol +++ b/test/units/ForceRevertDelegatecall.t.sol @@ -31,7 +31,7 @@ contract DummyHyperdrive is Hyperdrive, MockHyperdriveBase { baseToken: IERC20(address(0)), linkerFactory: address(0), linkerCodeHash: bytes32(0), - initialSharePrice: 1e18, + initialVaultSharePrice: 1e18, minimumShareReserves: 1e18, minimumTransactionAmount: 1e15, positionDuration: 365 days, diff --git a/test/units/hyperdrive/CheckpointTest.t.sol b/test/units/hyperdrive/CheckpointTest.t.sol index 0ca0e0ba1..cbfdee7b1 100644 --- a/test/units/hyperdrive/CheckpointTest.t.sol +++ b/test/units/hyperdrive/CheckpointTest.t.sol @@ -27,7 +27,7 @@ contract CheckpointTest is HyperdriveTest { // Update the share price. Since the long and short were opened in this // checkpoint, the checkpoint should be of the old checkpoint price. - uint256 sharePrice = hyperdrive.getPoolInfo().sharePrice; + uint256 vaultSharePrice = hyperdrive.getPoolInfo().vaultSharePrice; MockHyperdrive(address(hyperdrive)).accrue(CHECKPOINT_DURATION, 0.1e18); // Create a checkpoint. @@ -42,7 +42,7 @@ contract CheckpointTest is HyperdriveTest { IHyperdrive.Checkpoint memory checkpoint = hyperdrive.getCheckpoint( HyperdriveUtils.latestCheckpoint(hyperdrive) ); - assertEq(checkpoint.sharePrice, sharePrice); + assertEq(checkpoint.vaultSharePrice, vaultSharePrice); // Ensure that the long and short balance wasn't effected by the // checkpoint (the long and short haven't matured yet). @@ -60,7 +60,7 @@ contract CheckpointTest is HyperdriveTest { // short were opened in this checkpoint, the checkpoint should be of the // old checkpoint price. advanceTime(CHECKPOINT_DURATION, 0.1e18); - uint256 sharePrice = hyperdrive.getPoolInfo().sharePrice; + uint256 vaultSharePrice = hyperdrive.getPoolInfo().vaultSharePrice; // Create a checkpoint. uint256 aprBefore = HyperdriveUtils.calculateSpotAPR(hyperdrive); @@ -73,7 +73,7 @@ contract CheckpointTest is HyperdriveTest { IHyperdrive.Checkpoint memory checkpoint = hyperdrive.getCheckpoint( HyperdriveUtils.latestCheckpoint(hyperdrive) ); - assertEq(checkpoint.sharePrice, sharePrice); + assertEq(checkpoint.vaultSharePrice, vaultSharePrice); } function test_checkpoint_redemption() external { @@ -104,7 +104,7 @@ contract CheckpointTest is HyperdriveTest { HyperdriveUtils.latestCheckpoint(hyperdrive) ); IHyperdrive.PoolInfo memory poolInfo = hyperdrive.getPoolInfo(); - assertEq(checkpoint.sharePrice, poolInfo.sharePrice); + assertEq(checkpoint.vaultSharePrice, poolInfo.vaultSharePrice); // Ensure that the long and short balance has gone to zero (all of the // matured positions have been closed). @@ -145,11 +145,11 @@ contract CheckpointTest is HyperdriveTest { HyperdriveUtils.latestCheckpoint(hyperdrive) ); IHyperdrive.PoolInfo memory poolInfo = hyperdrive.getPoolInfo(); - assertEq(checkpoint.sharePrice, poolInfo.sharePrice); + assertEq(checkpoint.vaultSharePrice, poolInfo.vaultSharePrice); // Ensure that the previous checkpoint contains the closest share price. checkpoint = hyperdrive.getCheckpoint(previousCheckpoint); - assertEq(checkpoint.sharePrice, poolInfo.sharePrice); + assertEq(checkpoint.vaultSharePrice, poolInfo.vaultSharePrice); // Ensure that the long and short balance has gone to zero (all of the // matured positions have been closed). diff --git a/test/units/hyperdrive/CloseLongTest.t.sol b/test/units/hyperdrive/CloseLongTest.t.sol index cf03327f4..99f60fbcc 100644 --- a/test/units/hyperdrive/CloseLongTest.t.sol +++ b/test/units/hyperdrive/CloseLongTest.t.sol @@ -396,8 +396,8 @@ contract CloseLongTest is HyperdriveTest { // amount of shares, the base value of those shares are negative // relative to what they were at the start of the term. uint256 matureBondsValue = bondAmount - .divDown(hyperdrive.getPoolConfig().initialSharePrice) - .mulDown(poolInfoBefore.sharePrice); + .divDown(hyperdrive.getPoolConfig().initialVaultSharePrice) + .mulDown(poolInfoBefore.vaultSharePrice); // Verify that Bob received base equal to the full bond amount. assertApproxEqAbs(baseProceeds, bondFaceValue, 10); @@ -443,9 +443,9 @@ contract CloseLongTest is HyperdriveTest { uint256 baseProceeds = closeLong(bob, maturityTime, bondAmount); // Initial share price - uint256 initialSharePrice = hyperdrive + uint256 initialVaultSharePrice = hyperdrive .getPoolConfig() - .initialSharePrice; + .initialVaultSharePrice; // Ensure that the base proceeds are correct. { @@ -468,13 +468,13 @@ contract CloseLongTest is HyperdriveTest { poolInfoBefore.bondReserves, immatureBonds, ONE - hyperdrive.getPoolConfig().timeStretch, - poolInfoBefore.sharePrice, - initialSharePrice + poolInfoBefore.vaultSharePrice, + initialVaultSharePrice ) - .mulDown(poolInfoBefore.sharePrice); + .mulDown(poolInfoBefore.vaultSharePrice); - bondsValue = bondsValue.divDown(initialSharePrice).mulDown( - poolInfoBefore.sharePrice + bondsValue = bondsValue.divDown(initialVaultSharePrice).mulDown( + poolInfoBefore.vaultSharePrice ); assertLe(baseProceeds, bondsValue); @@ -521,13 +521,13 @@ contract CloseLongTest is HyperdriveTest { // Bob redeems the bonds. Ensure that the return value matches the // amount of base transferred to Bob. uint256 baseProceeds = closeLong(bob, maturityTime, bondAmount); - uint256 closeSharePrice = hyperdrive.getPoolInfo().sharePrice; + uint256 closeVaultSharePrice = hyperdrive.getPoolInfo().vaultSharePrice; // Bond holders take a proportional haircut on any negative interest // that accrues. uint256 bondValue = bondAmount - .divDown(hyperdrive.getPoolConfig().initialSharePrice) - .mulDown(closeSharePrice); + .divDown(hyperdrive.getPoolConfig().initialVaultSharePrice) + .mulDown(closeVaultSharePrice); // Calculate the value of the bonds compounded at the negative APR. (uint256 bondFaceValue, ) = HyperdriveUtils.calculateCompoundInterest( @@ -571,7 +571,7 @@ contract CloseLongTest is HyperdriveTest { // A checkpoint is created to lock in the close price. hyperdrive.checkpoint(HyperdriveUtils.latestCheckpoint(hyperdrive)); - uint256 closeSharePrice = hyperdrive.getPoolInfo().sharePrice; + uint256 closeVaultSharePrice = hyperdrive.getPoolInfo().vaultSharePrice; // Another term passes and a large amount of positive interest accrues. advanceTime(POSITION_DURATION, 0.7e18); @@ -591,8 +591,8 @@ contract CloseLongTest is HyperdriveTest { // Bond holders take a proportional haircut on any negative interest // that accrues. uint256 bondValue = bondAmount - .divDown(hyperdrive.getPoolConfig().initialSharePrice) - .mulDown(closeSharePrice); + .divDown(hyperdrive.getPoolConfig().initialVaultSharePrice) + .mulDown(closeVaultSharePrice); // Calculate the value of the bonds compounded at the negative APR. (uint256 bondFaceValue, ) = HyperdriveUtils.calculateCompoundInterest( @@ -637,7 +637,7 @@ contract CloseLongTest is HyperdriveTest { // A checkpoint is created to lock in the close price. hyperdrive.checkpoint(HyperdriveUtils.latestCheckpoint(hyperdrive)); - uint256 closeSharePrice = hyperdrive.getPoolInfo().sharePrice; + uint256 closeVaultSharePrice = hyperdrive.getPoolInfo().vaultSharePrice; // Another term passes and a large amount of negative interest accrues. int256 negativeApr = -0.2e18; @@ -657,8 +657,8 @@ contract CloseLongTest is HyperdriveTest { // Bond holders take a proportional haircut on any negative interest // that accrues. - uint256 bondValue = bondAmount.divDown(closeSharePrice).mulDown( - hyperdrive.getPoolInfo().sharePrice + uint256 bondValue = bondAmount.divDown(closeVaultSharePrice).mulDown( + hyperdrive.getPoolInfo().vaultSharePrice ); // Calculate the value of the bonds compounded at the negative APR. @@ -859,7 +859,7 @@ contract CloseLongTest is HyperdriveTest { ) = abi.decode(log.data, (uint256, uint256, uint256, uint256)); assertEq(eventMaturityTime, testCase.maturityTime); assertEq(eventBaseAmount, testCase.baseProceeds); - assertEq(eventSharePrice, hyperdrive.getPoolInfo().sharePrice); + assertEq(eventSharePrice, hyperdrive.getPoolInfo().vaultSharePrice); assertEq(eventBondAmount, testCase.bondAmount); } @@ -905,7 +905,7 @@ contract CloseLongTest is HyperdriveTest { poolInfoAfter.shareReserves, testCase.poolInfoBefore.shareReserves - testCase.baseProceeds.divDown( - testCase.poolInfoBefore.sharePrice + testCase.poolInfoBefore.vaultSharePrice ), 10 ); @@ -919,19 +919,19 @@ contract CloseLongTest is HyperdriveTest { // Without re-doing the calculation here, we can check that the // share adjustment delta is greater than or equal to the flat update // and verify that k remained invariant. - uint256 initialSharePrice = hyperdrive + uint256 initialVaultSharePrice = hyperdrive .getPoolConfig() - .initialSharePrice; + .initialVaultSharePrice; uint256 timeElapsed = ONE - hyperdrive.calculateTimeRemaining(testCase.maturityTime); uint256 shareAdjustmentDelta = testCase.bondAmount.mulDivDown( timeElapsed, - poolInfoAfter.sharePrice + poolInfoAfter.vaultSharePrice ); - if (poolInfoAfter.sharePrice < initialSharePrice) { + if (poolInfoAfter.vaultSharePrice < initialVaultSharePrice) { shareAdjustmentDelta = shareAdjustmentDelta.mulDivDown( - poolInfoAfter.sharePrice, - initialSharePrice + poolInfoAfter.vaultSharePrice, + initialVaultSharePrice ); } assertGe( @@ -947,8 +947,8 @@ contract CloseLongTest is HyperdriveTest { ), poolInfoAfter.bondReserves, ONE - hyperdrive.getPoolConfig().timeStretch, - poolInfoAfter.sharePrice, - initialSharePrice + poolInfoAfter.vaultSharePrice, + initialVaultSharePrice ), YieldSpaceMath.kDown( HyperdriveMath.calculateEffectiveShareReserves( @@ -957,13 +957,16 @@ contract CloseLongTest is HyperdriveTest { ), testCase.poolInfoBefore.bondReserves, ONE - hyperdrive.getPoolConfig().timeStretch, - testCase.poolInfoBefore.sharePrice, - initialSharePrice + testCase.poolInfoBefore.vaultSharePrice, + initialVaultSharePrice ), 1e10 ); } - assertEq(poolInfoAfter.sharePrice, testCase.poolInfoBefore.sharePrice); + assertEq( + poolInfoAfter.vaultSharePrice, + testCase.poolInfoBefore.vaultSharePrice + ); assertEq( poolInfoAfter.lpTotalSupply, testCase.poolInfoBefore.lpTotalSupply diff --git a/test/units/hyperdrive/CloseShortTest.t.sol b/test/units/hyperdrive/CloseShortTest.t.sol index faab017bb..e73264e29 100644 --- a/test/units/hyperdrive/CloseShortTest.t.sol +++ b/test/units/hyperdrive/CloseShortTest.t.sol @@ -446,7 +446,7 @@ contract CloseShortTest is HyperdriveTest { // A checkpoint is created to lock in the close price. hyperdrive.checkpoint(HyperdriveUtils.latestCheckpoint(hyperdrive)); - uint256 closeSharePrice = hyperdrive.getPoolInfo().sharePrice; + uint256 closeVaultSharePrice = hyperdrive.getPoolInfo().vaultSharePrice; // Another term passes and positive interest accrues. advanceTime(POSITION_DURATION, -0.2e18); @@ -465,11 +465,12 @@ contract CloseShortTest is HyperdriveTest { // the short was open. uint256 expectedProceeds = bondAmount .mulDivDown( - closeSharePrice - hyperdrive.getPoolConfig().initialSharePrice, - hyperdrive.getPoolConfig().initialSharePrice + closeVaultSharePrice - + hyperdrive.getPoolConfig().initialVaultSharePrice, + hyperdrive.getPoolConfig().initialVaultSharePrice ) - .divDown(closeSharePrice) - .mulDown(hyperdrive.getPoolInfo().sharePrice); + .divDown(closeVaultSharePrice) + .mulDown(hyperdrive.getPoolInfo().vaultSharePrice); assertApproxEqAbs(baseProceeds, expectedProceeds, 5); // Verify that the close long updates were correct. @@ -576,7 +577,7 @@ contract CloseShortTest is HyperdriveTest { asBase: false, // NOTE: Roughly double deposit amount needed to cover 100% flat fee depositAmount: 10e18 * 2, - minSharePrice: 0, + minVaultSharePrice: 0, minSlippage: 0, maxSlippage: type(uint128).max, extraData: new bytes(0) @@ -612,7 +613,7 @@ contract CloseShortTest is HyperdriveTest { asBase: false, // NOTE: Roughly double deposit amount needed to cover 100% flat fee depositAmount: 10e18 * 2, - minSharePrice: 0, + minVaultSharePrice: 0, minSlippage: 0, maxSlippage: type(uint128).max, extraData: new bytes(0) @@ -660,7 +661,7 @@ contract CloseShortTest is HyperdriveTest { asBase: false, // NOTE: Roughly double deposit amount needed to cover 100% flat fee depositAmount: 10e18 * 2, - minSharePrice: 0, + minVaultSharePrice: 0, minSlippage: 0, maxSlippage: type(uint128).max, extraData: new bytes(0) @@ -695,7 +696,7 @@ contract CloseShortTest is HyperdriveTest { asBase: false, // NOTE: Roughly double deposit amount needed to cover 100% flat fee depositAmount: 10e18 * 2, - minSharePrice: 0, + minVaultSharePrice: 0, minSlippage: 0, maxSlippage: type(uint128).max, extraData: new bytes(0) @@ -851,7 +852,7 @@ contract CloseShortTest is HyperdriveTest { ) = abi.decode(log.data, (uint256, uint256, uint256, uint256)); assertEq(eventMaturityTime, testCase.maturityTime); assertEq(eventBaseAmount, testCase.baseProceeds); - assertEq(eventSharePrice, hyperdrive.getPoolInfo().sharePrice); + assertEq(eventSharePrice, hyperdrive.getPoolInfo().vaultSharePrice); assertEq(eventBondAmount, testCase.bondAmount); } @@ -905,36 +906,36 @@ contract CloseShortTest is HyperdriveTest { // aren't repeating ourselves. uint256 shareReservesDelta = testCase.bondAmount.mulDivDown( ONE - timeRemaining, - testCase.poolInfoBefore.sharePrice + testCase.poolInfoBefore.vaultSharePrice ) + YieldSpaceMath.calculateSharesInGivenBondsOutUp( testCase.poolInfoBefore.shareReserves, testCase.poolInfoBefore.bondReserves, testCase.bondAmount.mulDown(timeRemaining), ONE - hyperdrive.getPoolConfig().timeStretch, - testCase.poolInfoBefore.sharePrice, - hyperdrive.getPoolConfig().initialSharePrice + testCase.poolInfoBefore.vaultSharePrice, + hyperdrive.getPoolConfig().initialVaultSharePrice ); uint256 timeElapsed = ONE - hyperdrive.calculateTimeRemaining(testCase.maturityTime); uint256 shareAdjustmentDelta = testCase.bondAmount.mulDivDown( timeElapsed, - poolInfoAfter.sharePrice + poolInfoAfter.vaultSharePrice ); - uint256 initialSharePrice = hyperdrive + uint256 initialVaultSharePrice = hyperdrive .getPoolConfig() - .initialSharePrice; + .initialVaultSharePrice; if ( - poolInfoAfter.sharePrice < - hyperdrive.getPoolConfig().initialSharePrice + poolInfoAfter.vaultSharePrice < + hyperdrive.getPoolConfig().initialVaultSharePrice ) { shareReservesDelta = shareReservesDelta.mulDivDown( - poolInfoAfter.sharePrice, - initialSharePrice + poolInfoAfter.vaultSharePrice, + initialVaultSharePrice ); shareAdjustmentDelta = shareAdjustmentDelta.mulDivDown( - poolInfoAfter.sharePrice, - initialSharePrice + poolInfoAfter.vaultSharePrice, + initialVaultSharePrice ); } assertApproxEqAbs( @@ -961,8 +962,8 @@ contract CloseShortTest is HyperdriveTest { ), poolInfoAfter.bondReserves, ONE - hyperdrive.getPoolConfig().timeStretch, - poolInfoAfter.sharePrice, - initialSharePrice + poolInfoAfter.vaultSharePrice, + initialVaultSharePrice ), YieldSpaceMath.kDown( HyperdriveMath.calculateEffectiveShareReserves( @@ -971,8 +972,8 @@ contract CloseShortTest is HyperdriveTest { ), testCase.poolInfoBefore.bondReserves, ONE - hyperdrive.getPoolConfig().timeStretch, - testCase.poolInfoBefore.sharePrice, - initialSharePrice + testCase.poolInfoBefore.vaultSharePrice, + initialVaultSharePrice ), 1e10 ); diff --git a/test/units/hyperdrive/ExtremeInputs.t.sol b/test/units/hyperdrive/ExtremeInputs.t.sol index 010f3f3a7..75e6d432b 100644 --- a/test/units/hyperdrive/ExtremeInputs.t.sol +++ b/test/units/hyperdrive/ExtremeInputs.t.sol @@ -202,8 +202,8 @@ contract ExtremeInputs is HyperdriveTest { longsOutstanding: poolInfo.longsOutstanding, longExposure: poolInfo.longExposure, timeStretch: poolConfig.timeStretch, - sharePrice: poolInfo.sharePrice, - initialSharePrice: poolConfig.initialSharePrice, + vaultSharePrice: poolInfo.vaultSharePrice, + initialVaultSharePrice: poolConfig.initialVaultSharePrice, minimumShareReserves: targetReserves, curveFee: poolConfig.fees.curve, flatFee: poolConfig.fees.flat, diff --git a/test/units/hyperdrive/FeeTest.t.sol b/test/units/hyperdrive/FeeTest.t.sol index 7c9e0b398..4809e3861 100644 --- a/test/units/hyperdrive/FeeTest.t.sol +++ b/test/units/hyperdrive/FeeTest.t.sol @@ -72,7 +72,7 @@ contract FeeTest is HyperdriveTest { uint256 governanceFeesAfterOpenLong = IMockHyperdrive( address(hyperdrive) ).getGovernanceFeesAccrued().mulDown( - hyperdrive.getPoolInfo().sharePrice + hyperdrive.getPoolInfo().vaultSharePrice ); // Time passes and the pool accrues interest at the current apr. @@ -93,13 +93,21 @@ contract FeeTest is HyperdriveTest { } function test_zombie_interest_governance_fee() external { - uint256 initialSharePrice = 1e18; + uint256 initialVaultSharePrice = 1e18; // Initialize the market uint256 apr = 0.05e18; // Set zombie fee to 100% to verify it works. uint256 governanceZombieFee = 1e18; - deploy(alice, apr, initialSharePrice, 0, 0, 0, governanceZombieFee); + deploy( + alice, + apr, + initialVaultSharePrice, + 0, + 0, + 0, + governanceZombieFee + ); uint256 contribution = 100e18; initialize(alice, apr, contribution); @@ -117,18 +125,18 @@ contract FeeTest is HyperdriveTest { closeLong(alice, maturityTimeLong, bondAmountLong); // Verify that the value represented in the share reserves is <= the actual amount in the contract. - uint256 sharePrice = hyperdrive.getPoolInfo().sharePrice; + uint256 vaultSharePrice = hyperdrive.getPoolInfo().vaultSharePrice; uint256 governanceFeesAccrued = IMockHyperdrive(address(hyperdrive)) .getGovernanceFeesAccrued(); uint256 baseReserves = hyperdrive.getPoolInfo().shareReserves.mulDown( - sharePrice + vaultSharePrice ); uint256 zombieShareReserves = hyperdrive .getPoolInfo() .zombieShareReserves; uint256 expectedBalance = baseReserves + - governanceFeesAccrued.mulDown(sharePrice) + - zombieShareReserves.mulDown(sharePrice); + governanceFeesAccrued.mulDown(vaultSharePrice) + + zombieShareReserves.mulDown(vaultSharePrice); assertApproxEqAbs( baseToken.balanceOf(address(hyperdrive)), expectedBalance, @@ -143,7 +151,7 @@ contract FeeTest is HyperdriveTest { POSITION_DURATION ); assertApproxEqAbs( - governanceFeesAccrued.mulDown(sharePrice), + governanceFeesAccrued.mulDown(vaultSharePrice), uint256(expectedGovernanceFeesAccrued), 1e4 ); @@ -154,7 +162,7 @@ contract FeeTest is HyperdriveTest { // This test demonstrates that the governance fees from flat fee are NOT included in the shareReserves. function test_flat_gov_fee_close_long() public { - uint256 initialSharePrice = 1e18; + uint256 initialVaultSharePrice = 1e18; int256 variableInterest = 0.0e18; uint256 curveFee = 0e18; // 0% uint256 flatFee = 0.001e18; // 0.1% @@ -171,7 +179,7 @@ contract FeeTest is HyperdriveTest { deploy( alice, apr, - initialSharePrice, + initialVaultSharePrice, curveFee, flatFee, governanceLPFee, @@ -188,7 +196,7 @@ contract FeeTest is HyperdriveTest { DepositOverrides({ asBase: true, depositAmount: basePaid, - minSharePrice: 0, + minVaultSharePrice: 0, minSlippage: 0, maxSlippage: type(uint256).max, extraData: new bytes(0) @@ -219,7 +227,7 @@ contract FeeTest is HyperdriveTest { uint256 shareReservesFlatFee = 0; { uint256 apr = 0.01e18; - deploy(alice, apr, initialSharePrice, curveFee, flatFee, 0, 0); + deploy(alice, apr, initialVaultSharePrice, curveFee, flatFee, 0, 0); uint256 contribution = 500_000_000e18; initialize(alice, apr, contribution); @@ -231,7 +239,7 @@ contract FeeTest is HyperdriveTest { DepositOverrides({ asBase: true, depositAmount: basePaid, - minSharePrice: 0, + minVaultSharePrice: 0, minSlippage: 0, maxSlippage: type(uint256).max, extraData: new bytes(0) @@ -264,7 +272,7 @@ contract FeeTest is HyperdriveTest { // This test demonstrates that the governance fees from curve fee are NOT included in the shareReserves. function test_curve_gov_fee_close_long() public { - uint256 initialSharePrice = 1e18; + uint256 initialVaultSharePrice = 1e18; uint256 curveFee = 0.1e18; // 10% uint256 flatFee = 0; // 0% uint256 governanceLPFee = 1e18; // 100% @@ -282,7 +290,7 @@ contract FeeTest is HyperdriveTest { deploy( alice, apr, - initialSharePrice, + initialVaultSharePrice, curveFee, flatFee, governanceLPFee, @@ -299,7 +307,7 @@ contract FeeTest is HyperdriveTest { DepositOverrides({ asBase: true, depositAmount: basePaid, - minSharePrice: 0, + minVaultSharePrice: 0, minSlippage: 0, maxSlippage: type(uint256).max, extraData: new bytes(0) @@ -350,7 +358,7 @@ contract FeeTest is HyperdriveTest { uint256 shareReservesCurveFee = 0; { uint256 apr = 0.01e18; - deploy(alice, apr, initialSharePrice, curveFee, flatFee, 0, 0); + deploy(alice, apr, initialVaultSharePrice, curveFee, flatFee, 0, 0); uint256 contribution = 500_000_000e18; initialize(alice, apr, contribution); @@ -362,7 +370,7 @@ contract FeeTest is HyperdriveTest { DepositOverrides({ asBase: true, depositAmount: basePaid, - minSharePrice: 0, + minVaultSharePrice: 0, minSlippage: 0, maxSlippage: type(uint256).max, extraData: new bytes(0) @@ -576,7 +584,7 @@ contract FeeTest is HyperdriveTest { ).calculateFeesGivenShares( 1 ether, // amountIn 0.5 ether, // spotPrice - 1 ether //sharePrice + 1 ether //vaultSharePrice ); // total curve fee = ((1 / p) - 1) * phi_curve * c * dz // ((1/.5)-1) * .1*1*1 = .1 @@ -609,7 +617,7 @@ contract FeeTest is HyperdriveTest { 1 ether, // amount 1 ether, // timeRemaining 0.9 ether, // spotPrice - 1 ether // sharePrice + 1 ether // vaultSharePrice ); // curve fee = ((1 - p) * phi_curve * d_y * t) / c // ((1-.9)*.1*1*1)/1 = .01 @@ -626,7 +634,7 @@ contract FeeTest is HyperdriveTest { 1 ether, // amount 0, // timeRemaining 0.9 ether, // spotPrice - 1 ether // sharePrice + 1 ether // vaultSharePrice ); assertEq(curveFee + flatFee, 0.1 ether); assertEq(totalGovernanceFee, 0.05 ether); @@ -655,7 +663,7 @@ contract FeeTest is HyperdriveTest { 1 ether, // amount 1 ether, // timeRemaining 0.9 ether, // spotPrice - 1 ether // sharePrice + 1 ether // vaultSharePrice ); assertEq(curveFee, .01 ether); assertEq(flatFee, 0 ether); @@ -671,7 +679,7 @@ contract FeeTest is HyperdriveTest { 1 ether, // amount 0, // timeRemaining 0.9 ether, // spotPrice - 1 ether // sharePrice + 1 ether // vaultSharePrice ); assertEq(curveFee, 0 ether); assertEq(flatFee, 0.1 ether); diff --git a/test/units/hyperdrive/InitializeTest.t.sol b/test/units/hyperdrive/InitializeTest.t.sol index 27bba4e70..4b29417a1 100644 --- a/test/units/hyperdrive/InitializeTest.t.sol +++ b/test/units/hyperdrive/InitializeTest.t.sol @@ -71,13 +71,16 @@ contract InitializeTest is HyperdriveTest { } function test_initialize_success( - uint256 initialSharePrice, + uint256 initialVaultSharePrice, uint256 checkpointDuration, uint256 checkpointsPerTerm, uint256 targetRate, uint256 contribution ) external { - initialSharePrice = initialSharePrice.normalizeToRange(0.5e18, 5e18); + initialVaultSharePrice = initialVaultSharePrice.normalizeToRange( + 0.5e18, + 5e18 + ); checkpointDuration = checkpointDuration.normalizeToRange(1, 24); checkpointDuration *= 1 hours; checkpointsPerTerm = checkpointsPerTerm.normalizeToRange(7, 2 * 365); @@ -89,7 +92,7 @@ contract InitializeTest is HyperdriveTest { 0.05e18, checkpointDuration * checkpointsPerTerm ); - config.initialSharePrice = initialSharePrice; + config.initialVaultSharePrice = initialVaultSharePrice; config.checkpointDuration = checkpointDuration; deploy(alice, config); @@ -136,12 +139,12 @@ contract InitializeTest is HyperdriveTest { ( uint256 lpShares, uint256 baseAmount, - uint256 sharePrice, + uint256 vaultSharePrice, uint256 spotRate ) = abi.decode(log.data, (uint256, uint256, uint256, uint256)); assertEq(lpShares, expectedLpShares); assertEq(baseAmount, expectedBaseAmount); - assertEq(sharePrice, hyperdrive.getPoolInfo().sharePrice); + assertEq(vaultSharePrice, hyperdrive.getPoolInfo().vaultSharePrice); assertEq(spotRate, expectedSpotRate); } } diff --git a/test/units/hyperdrive/OpenLongTest.t.sol b/test/units/hyperdrive/OpenLongTest.t.sol index d8a5f8f70..2a69cdc35 100644 --- a/test/units/hyperdrive/OpenLongTest.t.sol +++ b/test/units/hyperdrive/OpenLongTest.t.sol @@ -171,7 +171,7 @@ contract OpenLongTest is HyperdriveTest { ); } - function test_open_long_failure_minimum_share_price() external { + function test_open_long_failure_minimum_vault_share_price() external { uint256 apr = 0.05e18; // Initialize the pool with a large amount of capital. @@ -185,12 +185,13 @@ contract OpenLongTest is HyperdriveTest { uint256 baseAmount = 10e18; baseToken.mint(baseAmount); baseToken.approve(address(hyperdrive), baseAmount); - uint256 minSharePrice = 2 * hyperdrive.getPoolInfo().sharePrice; + uint256 minVaultSharePrice = 2 * + hyperdrive.getPoolInfo().vaultSharePrice; vm.expectRevert(IHyperdrive.MinimumSharePrice.selector); hyperdrive.openLong( baseAmount, 0, - minSharePrice, + minVaultSharePrice, IHyperdrive.Options({ destination: bob, asBase: true, @@ -354,7 +355,7 @@ contract OpenLongTest is HyperdriveTest { ) = abi.decode(log.data, (uint256, uint256, uint256, uint256)); assertEq(eventMaturityTime, maturityTime); assertEq(eventBaseAmount, baseAmount); - assertEq(eventSharePrice, hyperdrive.getPoolInfo().sharePrice); + assertEq(eventSharePrice, hyperdrive.getPoolInfo().vaultSharePrice); assertEq(eventBondAmount, bondAmount); } @@ -452,9 +453,9 @@ contract OpenLongTest is HyperdriveTest { assertEq( poolInfoAfter.shareReserves, poolInfoBefore.shareReserves + - baseAmount.divDown(poolInfoBefore.sharePrice) + baseAmount.divDown(poolInfoBefore.vaultSharePrice) ); - assertEq(poolInfoAfter.sharePrice, poolInfoBefore.sharePrice); + assertEq(poolInfoAfter.vaultSharePrice, poolInfoBefore.vaultSharePrice); assertEq(poolInfoAfter.shareAdjustment, poolInfoBefore.shareAdjustment); assertEq(poolInfoAfter.lpTotalSupply, poolInfoBefore.lpTotalSupply); assertApproxEqAbs( diff --git a/test/units/hyperdrive/OpenShortTest.t.sol b/test/units/hyperdrive/OpenShortTest.t.sol index f1ae73536..282414fce 100644 --- a/test/units/hyperdrive/OpenShortTest.t.sol +++ b/test/units/hyperdrive/OpenShortTest.t.sol @@ -121,7 +121,7 @@ contract OpenShortTest is HyperdriveTest { ); } - function test_open_short_failure_minimum_share_price() external { + function test_open_short_failure_minimum_vault_share_price() external { uint256 apr = 0.05e18; // Initialize the pool with a large amount of capital. @@ -135,12 +135,13 @@ contract OpenShortTest is HyperdriveTest { uint256 bondAmount = 10e18; baseToken.mint(bondAmount); baseToken.approve(address(hyperdrive), bondAmount); - uint256 minSharePrice = 2 * hyperdrive.getPoolInfo().sharePrice; + uint256 minVaultSharePrice = 2 * + hyperdrive.getPoolInfo().vaultSharePrice; vm.expectRevert(IHyperdrive.MinimumSharePrice.selector); hyperdrive.openShort( bondAmount, type(uint256).max, - minSharePrice, + minVaultSharePrice, IHyperdrive.Options({ destination: bob, asBase: true, @@ -238,7 +239,7 @@ contract OpenShortTest is HyperdriveTest { DepositOverrides memory depositOverrides = DepositOverrides({ asBase: false, depositAmount: bondAmount * 2, - minSharePrice: 0, + minVaultSharePrice: 0, minSlippage: 0, maxSlippage: type(uint128).max, extraData: new bytes(0) @@ -391,7 +392,7 @@ contract OpenShortTest is HyperdriveTest { ) = abi.decode(log.data, (uint256, uint256, uint256, uint256)); assertEq(eventMaturityTime, maturityTime); assertEq(eventBaseAmount, basePaid); - assertEq(eventSharePrice, hyperdrive.getPoolInfo().sharePrice); + assertEq(eventSharePrice, hyperdrive.getPoolInfo().vaultSharePrice); assertEq(eventBondAmount, shortAmount); } @@ -431,9 +432,12 @@ contract OpenShortTest is HyperdriveTest { assertEq( poolInfoAfter.shareReserves, poolInfoBefore.shareReserves - - baseProceeds.divDown(poolInfoBefore.sharePrice) + baseProceeds.divDown(poolInfoBefore.vaultSharePrice) + ); + assertEq( + poolInfoAfter.vaultSharePrice, + poolInfoBefore.vaultSharePrice ); - assertEq(poolInfoAfter.sharePrice, poolInfoBefore.sharePrice); assertEq( poolInfoAfter.shareAdjustment, poolInfoBefore.shareAdjustment diff --git a/test/units/hyperdrive/RemoveLiquidityTest.t.sol b/test/units/hyperdrive/RemoveLiquidityTest.t.sol index fb9764c40..53d7985b7 100644 --- a/test/units/hyperdrive/RemoveLiquidityTest.t.sol +++ b/test/units/hyperdrive/RemoveLiquidityTest.t.sol @@ -281,12 +281,12 @@ contract RemoveLiquidityTest is HyperdriveTest { ( uint256 lpShares, uint256 baseAmount, - uint256 sharePrice, + uint256 vaultSharePrice, uint256 withdrawalShares ) = abi.decode(log.data, (uint256, uint256, uint256, uint256)); assertEq(lpShares, expectedLpShares); assertEq(baseAmount, expectedBaseAmount); - assertEq(sharePrice, hyperdrive.getPoolInfo().sharePrice); + assertEq(vaultSharePrice, hyperdrive.getPoolInfo().vaultSharePrice); assertEq(withdrawalShares, expectedWithdrawalShares); } @@ -300,7 +300,9 @@ contract RemoveLiquidityTest is HyperdriveTest { function presentValueRatio() internal view returns (uint256) { return hyperdrive.presentValue().divDown( - lpTotalSupply().mulDown(hyperdrive.getPoolInfo().sharePrice) + lpTotalSupply().mulDown( + hyperdrive.getPoolInfo().vaultSharePrice + ) ); } } diff --git a/test/units/libraries/HyperdriveMath.t.sol b/test/units/libraries/HyperdriveMath.t.sol index 6847d3e0b..bcb20049f 100644 --- a/test/units/libraries/HyperdriveMath.t.sol +++ b/test/units/libraries/HyperdriveMath.t.sol @@ -26,7 +26,7 @@ contract HyperdriveMathTest is HyperdriveTest { hyperdriveMath.calculateSpotPrice( 1 ether, // shareReserves 1 ether, // bondReserves - 1 ether, // initialSharePrice + 1 ether, // initialVaultSharePrice 1 ether // timeStretch ), 1 ether // 1.0 spot price @@ -36,7 +36,7 @@ contract HyperdriveMathTest is HyperdriveTest { hyperdriveMath.calculateSpotPrice( 1.1 ether, // shareReserves 1 ether, // bondReserves - 1 ether, // initialSharePrice + 1 ether, // initialVaultSharePrice 1 ether // timeStretch ), 1.1 ether, // 1.1 spot price @@ -53,7 +53,7 @@ contract HyperdriveMathTest is HyperdriveTest { hyperdriveMath.calculateSpotAPR( 1 ether, // shareReserves 1 ether, // bondReserves - 1 ether, // initialSharePrice + 1 ether, // initialVaultSharePrice 365 days, // positionDuration 1 ether // timeStretch ), @@ -65,7 +65,7 @@ contract HyperdriveMathTest is HyperdriveTest { hyperdriveMath.calculateSpotAPR( 1 ether, // shareReserves 1.1 ether, // bondReserves - 1 ether, // initialSharePrice + 1 ether, // initialVaultSharePrice 365 days, // positionDuration 1 ether // timeStretch ), @@ -78,7 +78,7 @@ contract HyperdriveMathTest is HyperdriveTest { hyperdriveMath.calculateSpotAPR( 1 ether, // shareReserves 1.05 ether, // bondReserves - 1 ether, // initialSharePrice + 1 ether, // initialVaultSharePrice 182.5 days, // positionDuration 1 ether // timeStretch ), @@ -93,13 +93,13 @@ contract HyperdriveMathTest is HyperdriveTest { // Test .1% APR uint256 shareReserves = 500_000_000 ether; - uint256 initialSharePrice = 1 ether; + uint256 initialVaultSharePrice = 1 ether; uint256 apr = 0.001 ether; uint256 positionDuration = 365 days; uint256 timeStretch = ONE.divDown(1109.3438508425959e18); uint256 bondReserves = hyperdriveMath.calculateInitialBondReserves( shareReserves, - initialSharePrice, + initialVaultSharePrice, apr, positionDuration, timeStretch @@ -107,7 +107,7 @@ contract HyperdriveMathTest is HyperdriveTest { uint256 result = hyperdriveMath.calculateSpotAPR( shareReserves, bondReserves, - initialSharePrice, + initialVaultSharePrice, positionDuration, timeStretch ); @@ -118,7 +118,7 @@ contract HyperdriveMathTest is HyperdriveTest { timeStretch = ONE.divDown(110.93438508425959e18); bondReserves = hyperdriveMath.calculateInitialBondReserves( shareReserves, - initialSharePrice, + initialVaultSharePrice, apr, positionDuration, timeStretch @@ -126,7 +126,7 @@ contract HyperdriveMathTest is HyperdriveTest { result = hyperdriveMath.calculateSpotAPR( shareReserves, bondReserves, - initialSharePrice, + initialVaultSharePrice, positionDuration, timeStretch ); @@ -137,7 +137,7 @@ contract HyperdriveMathTest is HyperdriveTest { timeStretch = ONE.divDown(22.186877016851916266e18); bondReserves = hyperdriveMath.calculateInitialBondReserves( shareReserves, - initialSharePrice, + initialVaultSharePrice, apr, positionDuration, timeStretch @@ -145,7 +145,7 @@ contract HyperdriveMathTest is HyperdriveTest { result = hyperdriveMath.calculateSpotAPR( shareReserves, bondReserves, - initialSharePrice, + initialVaultSharePrice, positionDuration, timeStretch ); @@ -156,7 +156,7 @@ contract HyperdriveMathTest is HyperdriveTest { timeStretch = ONE.divDown(4.437375403370384e18); bondReserves = hyperdriveMath.calculateInitialBondReserves( shareReserves, - initialSharePrice, + initialVaultSharePrice, apr, positionDuration, timeStretch @@ -164,7 +164,7 @@ contract HyperdriveMathTest is HyperdriveTest { result = hyperdriveMath.calculateSpotAPR( shareReserves, bondReserves, - initialSharePrice, + initialVaultSharePrice, positionDuration, timeStretch ); @@ -175,7 +175,7 @@ contract HyperdriveMathTest is HyperdriveTest { timeStretch = ONE.divDown(2.218687701685192e18); bondReserves = hyperdriveMath.calculateInitialBondReserves( shareReserves, - initialSharePrice, + initialVaultSharePrice, apr, positionDuration, timeStretch @@ -183,7 +183,7 @@ contract HyperdriveMathTest is HyperdriveTest { result = hyperdriveMath.calculateSpotAPR( shareReserves, bondReserves, - initialSharePrice, + initialVaultSharePrice, positionDuration, timeStretch ); @@ -194,7 +194,7 @@ contract HyperdriveMathTest is HyperdriveTest { timeStretch = ONE.divDown(1.109343850842596e18); bondReserves = hyperdriveMath.calculateInitialBondReserves( shareReserves, - initialSharePrice, + initialVaultSharePrice, apr, positionDuration, timeStretch @@ -202,7 +202,7 @@ contract HyperdriveMathTest is HyperdriveTest { result = hyperdriveMath.calculateSpotAPR( shareReserves, bondReserves, - initialSharePrice, + initialVaultSharePrice, positionDuration, timeStretch ); @@ -218,7 +218,7 @@ contract HyperdriveMathTest is HyperdriveTest { uint256 bondReserves = 2 * 503_926_401.456553339958190918 ether + shareReserves; - uint256 initialSharePrice = 1 ether; + uint256 initialVaultSharePrice = 1 ether; uint256 positionDuration = 365 days; uint256 timeStretch = ONE.divDown(110.93438508425959e18); uint256 expectedAPR = 0.882004326279808182 ether; @@ -228,15 +228,15 @@ contract HyperdriveMathTest is HyperdriveTest { bondReserves, amountIn, timeStretch, - 1 ether, // sharePrice - initialSharePrice + 1 ether, // vaultSharePrice + initialVaultSharePrice ); bondReserves -= bondReservesDelta; shareReserves += amountIn; uint256 result = hyperdriveMath.calculateSpotAPR( shareReserves, bondReserves, - initialSharePrice, + initialVaultSharePrice, positionDuration, timeStretch ); @@ -316,7 +316,7 @@ contract HyperdriveMathTest is HyperdriveTest { // verify that the curve part is zero assertEq(shareReservesDelta, 0); assertEq(bondReservesDelta, 0); - // verify that the flat part is the amountIn * sharePrice (sharePrice = 1) + // verify that the flat part is the amountIn * vaultSharePrice (vaultSharePrice = 1) assertEq(shareProceeds, amountIn); } @@ -385,7 +385,7 @@ contract HyperdriveMathTest is HyperdriveTest { // verify that the curve part is zero assertEq(shareReservesDelta, 0); assertEq(bondReservesDelta, 0); - // verify that the flat part is the amountOut / sharePrice (sharePrice = 1) + // verify that the flat part is the amountOut / vaultSharePrice (vaultSharePrice = 1) assertEq(sharePayment, amountOut); } @@ -440,7 +440,7 @@ contract HyperdriveMathTest is HyperdriveTest { fixedRate = fixedRate.normalizeToRange(0.005e18, 1e18); uint256 initialShareReserves = 500_000_000e18; - uint256 initialSharePrice = INITIAL_SHARE_PRICE; + uint256 initialVaultSharePrice = INITIAL_SHARE_PRICE; uint256 timeStretch = HyperdriveUtils.calculateTimeStretch( fixedRate, POSITION_DURATION @@ -449,7 +449,7 @@ contract HyperdriveMathTest is HyperdriveTest { uint256 initialBondReserves = hyperdriveMath .calculateInitialBondReserves( initialShareReserves, - initialSharePrice, + initialVaultSharePrice, fixedRate, POSITION_DURATION, timeStretch @@ -468,8 +468,8 @@ contract HyperdriveMathTest is HyperdriveTest { bondReserves, baseAmountIn, timeStretch, - initialSharePrice, // sharePrice - initialSharePrice + initialVaultSharePrice, // vaultSharePrice + initialVaultSharePrice ); bondReserves -= bondReservesDelta; shareReserves += baseAmountIn; @@ -477,7 +477,7 @@ contract HyperdriveMathTest is HyperdriveTest { } { - uint256 _initialSharePrice = initialSharePrice; // Avoid stack too deep error + uint256 _initialVaultSharePrice = initialVaultSharePrice; // Avoid stack too deep error ( uint256 shareReservesDelta, uint256 bondReservesDelta, @@ -488,8 +488,8 @@ contract HyperdriveMathTest is HyperdriveTest { bondAmountIn, normalizedTimeRemaining, timeStretch, - _initialSharePrice, // sharePrice - _initialSharePrice + _initialVaultSharePrice, // vaultSharePrice + _initialVaultSharePrice ); bondReserves += bondReservesDelta; shareReserves -= shareReservesDelta; @@ -511,7 +511,7 @@ contract HyperdriveMathTest is HyperdriveTest { fixedRate = fixedRate.normalizeToRange(0.005e18, 1e18); uint256 initialShareReserves = 500_000_000e18; - uint256 initialSharePrice = INITIAL_SHARE_PRICE; + uint256 initialVaultSharePrice = INITIAL_SHARE_PRICE; uint256 timeStretch = HyperdriveUtils.calculateTimeStretch( fixedRate, POSITION_DURATION @@ -519,7 +519,7 @@ contract HyperdriveMathTest is HyperdriveTest { uint256 initialBondReserves = hyperdriveMath .calculateInitialBondReserves( initialShareReserves, - initialSharePrice, + initialVaultSharePrice, fixedRate, POSITION_DURATION, timeStretch @@ -538,8 +538,8 @@ contract HyperdriveMathTest is HyperdriveTest { bondReserves, baseAmountIn, timeStretch, - initialSharePrice, // sharePrice - initialSharePrice + initialVaultSharePrice, // vaultSharePrice + initialVaultSharePrice ); bondReserves -= bondReservesDelta; shareReserves += baseAmountIn; @@ -547,14 +547,14 @@ contract HyperdriveMathTest is HyperdriveTest { } { - uint256 _initialSharePrice = initialSharePrice; // Avoid stack too deep error + uint256 _initialVaultSharePrice = initialVaultSharePrice; // Avoid stack too deep error uint256 shareReservesDelta = hyperdriveMath.calculateOpenShort( shareReserves, bondReserves, bondAmountIn, timeStretch, - _initialSharePrice, // sharePrice - _initialSharePrice + _initialVaultSharePrice, // vaultSharePrice + _initialVaultSharePrice ); bondReserves += bondAmountIn; shareReserves -= shareReservesDelta; @@ -568,8 +568,8 @@ contract HyperdriveMathTest is HyperdriveTest { } struct TestCaseInput { - uint256 closeSharePrice; - uint256 openSharePrice; + uint256 closeVaultSharePrice; + uint256 openVaultSharePrice; uint256 shareProceeds; uint256 shareReservesDelta; uint256 shareCurveDelta; @@ -591,8 +591,8 @@ contract HyperdriveMathTest is HyperdriveTest { // interest rate of 0% { TestCaseInput memory input = TestCaseInput({ - closeSharePrice: 1e18, - openSharePrice: 1e18, + closeVaultSharePrice: 1e18, + openVaultSharePrice: 1e18, shareProceeds: 10_000_000e18, shareReservesDelta: 10_000_000e18, shareCurveDelta: 5_000_000e18, @@ -612,8 +612,8 @@ contract HyperdriveMathTest is HyperdriveTest { input.shareReservesDelta, input.shareCurveDelta, input.totalGovernanceFee, - input.openSharePrice, - input.closeSharePrice, + input.openVaultSharePrice, + input.closeVaultSharePrice, true ); assertEq(output.shareProceeds, input.shareProceeds); @@ -637,8 +637,8 @@ contract HyperdriveMathTest is HyperdriveTest { input.shareReservesDelta, input.shareCurveDelta, input.totalGovernanceFee, - input.openSharePrice, - input.closeSharePrice, + input.openVaultSharePrice, + input.closeVaultSharePrice, false ); assertEq(output.shareProceeds, input.shareProceeds); @@ -654,8 +654,8 @@ contract HyperdriveMathTest is HyperdriveTest { // interest rate of 10% { TestCaseInput memory input = TestCaseInput({ - closeSharePrice: 1.1e18, - openSharePrice: 1e18, + closeVaultSharePrice: 1.1e18, + openVaultSharePrice: 1e18, shareProceeds: 10_000_000e18, shareReservesDelta: 10_000_000e18, shareCurveDelta: 5_000_000e18, @@ -675,8 +675,8 @@ contract HyperdriveMathTest is HyperdriveTest { input.shareReservesDelta, input.shareCurveDelta, input.totalGovernanceFee, - input.openSharePrice, - input.closeSharePrice, + input.openVaultSharePrice, + input.closeVaultSharePrice, true ); assertEq(output.shareProceeds, input.shareProceeds); @@ -700,8 +700,8 @@ contract HyperdriveMathTest is HyperdriveTest { input.shareReservesDelta, input.shareCurveDelta, input.totalGovernanceFee, - input.openSharePrice, - input.closeSharePrice, + input.openVaultSharePrice, + input.closeVaultSharePrice, false ); assertEq(output.shareProceeds, input.shareProceeds); @@ -717,8 +717,8 @@ contract HyperdriveMathTest is HyperdriveTest { // interest rate of -10% { TestCaseInput memory input = TestCaseInput({ - closeSharePrice: 0.9e18, - openSharePrice: 1e18, + closeVaultSharePrice: 0.9e18, + openVaultSharePrice: 1e18, shareProceeds: 10_000_000e18, shareReservesDelta: 10_000_000e18, shareCurveDelta: 5_000_000e18, @@ -738,42 +738,42 @@ contract HyperdriveMathTest is HyperdriveTest { input.shareReservesDelta, input.shareCurveDelta, input.totalGovernanceFee, - input.openSharePrice, - input.closeSharePrice, + input.openVaultSharePrice, + input.closeVaultSharePrice, true ); assertEq( output.shareProceeds, input.shareProceeds.mulDivDown( - input.closeSharePrice, - input.openSharePrice + input.closeVaultSharePrice, + input.openVaultSharePrice ) ); assertEq( output.shareReservesDelta, input.shareReservesDelta.mulDivDown( - input.closeSharePrice, - input.openSharePrice + input.closeVaultSharePrice, + input.openVaultSharePrice ) ); assertEq( output.shareCurveDelta, input.shareCurveDelta.mulDivDown( - input.closeSharePrice, - input.openSharePrice + input.closeVaultSharePrice, + input.openVaultSharePrice ) ); assertEq( output.totalGovernanceFee, input.totalGovernanceFee.mulDivDown( - input.closeSharePrice, - input.openSharePrice + input.closeVaultSharePrice, + input.openVaultSharePrice ) ); assertEq( output.shareAdjustmentDelta, int256( - input.shareReservesDelta.mulDown(input.closeSharePrice) + input.shareReservesDelta.mulDown(input.closeVaultSharePrice) ) - int256(input.shareCurveDelta) ); @@ -789,8 +789,8 @@ contract HyperdriveMathTest is HyperdriveTest { input.shareReservesDelta, input.shareCurveDelta, input.totalGovernanceFee, - input.openSharePrice, - input.closeSharePrice, + input.openVaultSharePrice, + input.closeVaultSharePrice, false ); // NOTE: share proceeds aren't scaled @@ -798,28 +798,28 @@ contract HyperdriveMathTest is HyperdriveTest { assertEq( output.shareReservesDelta, input.shareReservesDelta.mulDivDown( - input.closeSharePrice, - input.openSharePrice + input.closeVaultSharePrice, + input.openVaultSharePrice ) ); assertEq( output.shareCurveDelta, input.shareCurveDelta.mulDivDown( - input.closeSharePrice, - input.openSharePrice + input.closeVaultSharePrice, + input.openVaultSharePrice ) ); assertEq( output.totalGovernanceFee, input.totalGovernanceFee.mulDivDown( - input.closeSharePrice, - input.openSharePrice + input.closeVaultSharePrice, + input.openVaultSharePrice ) ); assertEq( output.shareAdjustmentDelta, int256( - input.shareReservesDelta.mulDown(input.closeSharePrice) + input.shareReservesDelta.mulDown(input.closeVaultSharePrice) ) - int256(input.shareCurveDelta) ); } @@ -986,8 +986,8 @@ contract HyperdriveMathTest is HyperdriveTest { longsOutstanding: info.longsOutstanding, longExposure: info.longExposure, timeStretch: config.timeStretch, - sharePrice: info.sharePrice, - initialSharePrice: config.initialSharePrice, + vaultSharePrice: info.vaultSharePrice, + initialVaultSharePrice: config.initialVaultSharePrice, minimumShareReserves: config.minimumShareReserves, curveFee: config.fees.curve, flatFee: config.fees.flat, @@ -1143,8 +1143,8 @@ contract HyperdriveMathTest is HyperdriveTest { longsOutstanding: info.longsOutstanding, longExposure: info.longExposure, timeStretch: config.timeStretch, - sharePrice: info.sharePrice, - initialSharePrice: config.initialSharePrice, + vaultSharePrice: info.vaultSharePrice, + initialVaultSharePrice: config.initialVaultSharePrice, minimumShareReserves: config.minimumShareReserves, curveFee: config.fees.curve, flatFee: config.fees.flat, @@ -1187,117 +1187,117 @@ contract HyperdriveMathTest is HyperdriveTest { // 0% interest - 5% margin released - 0% interest after close uint256 bondAmount = 1.05e18; uint256 shareAmount = 1e18; - uint256 openSharePrice = 1e18; - uint256 closeSharePrice = 1e18; - uint256 sharePrice = 1e18; + uint256 openVaultSharePrice = 1e18; + uint256 closeVaultSharePrice = 1e18; + uint256 vaultSharePrice = 1e18; uint256 flatFee = 0; uint256 shortProceeds = hyperdriveMath.calculateShortProceeds( bondAmount, shareAmount, - openSharePrice, - closeSharePrice, - sharePrice, + openVaultSharePrice, + closeVaultSharePrice, + vaultSharePrice, flatFee ); - // proceeds = (margin + interest) / share_price = (0.05 + 0) / 1 + // proceeds = (margin + interest) / vault_share_price = (0.05 + 0) / 1 assertEq(shortProceeds, 0.05e18); // 5% interest - 5% margin released - 0% interest after close bondAmount = 1.05e18; - openSharePrice = 1e18; - closeSharePrice = 1.05e18; - sharePrice = 1.05e18; - shareAmount = uint256(1e18).divDown(sharePrice); + openVaultSharePrice = 1e18; + closeVaultSharePrice = 1.05e18; + vaultSharePrice = 1.05e18; + shareAmount = uint256(1e18).divDown(vaultSharePrice); flatFee = 0; shortProceeds = hyperdriveMath.calculateShortProceeds( bondAmount, shareAmount, - openSharePrice, - closeSharePrice, - sharePrice, + openVaultSharePrice, + closeVaultSharePrice, + vaultSharePrice, flatFee ); - // proceeds = (margin + interest) / share_price = (0.05 + 1.05 * 0.05) / 1.05 + // proceeds = (margin + interest) / vault_share_price = (0.05 + 1.05 * 0.05) / 1.05 assertApproxEqAbs( shortProceeds, - (0.05e18 + bondAmount.mulDown(0.05e18)).divDown(sharePrice), + (0.05e18 + bondAmount.mulDown(0.05e18)).divDown(vaultSharePrice), 1 ); // 5% interest - 0% margin released - 0% interest after close bondAmount = 1e18; - openSharePrice = 1e18; - closeSharePrice = 1.05e18; - sharePrice = 1.05e18; - shareAmount = uint256(1e18).divDown(sharePrice); + openVaultSharePrice = 1e18; + closeVaultSharePrice = 1.05e18; + vaultSharePrice = 1.05e18; + shareAmount = uint256(1e18).divDown(vaultSharePrice); flatFee = 0; shortProceeds = hyperdriveMath.calculateShortProceeds( bondAmount, shareAmount, - openSharePrice, - closeSharePrice, - sharePrice, + openVaultSharePrice, + closeVaultSharePrice, + vaultSharePrice, flatFee ); - // proceeds = (margin + interest) / share_price = (0 + 1 * 0.05) / 1.05 + // proceeds = (margin + interest) / vault_share_price = (0 + 1 * 0.05) / 1.05 assertApproxEqAbs( shortProceeds, - (bondAmount.mulDown(0.05e18)).divDown(sharePrice), + (bondAmount.mulDown(0.05e18)).divDown(vaultSharePrice), 1 ); // 5% interest - 5% margin released - 10% interest after close bondAmount = 1.05e18; - openSharePrice = 1e18; - closeSharePrice = 1.05e18; - sharePrice = 1.155e18; - shareAmount = uint256(1e18).divDown(sharePrice); + openVaultSharePrice = 1e18; + closeVaultSharePrice = 1.05e18; + vaultSharePrice = 1.155e18; + shareAmount = uint256(1e18).divDown(vaultSharePrice); flatFee = 0; shortProceeds = hyperdriveMath.calculateShortProceeds( bondAmount, shareAmount, - openSharePrice, - closeSharePrice, - sharePrice, + openVaultSharePrice, + closeVaultSharePrice, + vaultSharePrice, flatFee ); - // proceeds = (margin + interest) / share_price = (0.05 + 1.05 * 0.05) / 1.155 + // proceeds = (margin + interest) / vault_share_price = (0.05 + 1.05 * 0.05) / 1.155 assertApproxEqAbs( shortProceeds, - (0.05e18 + bondAmount.mulDown(0.05e18)).divDown(sharePrice), + (0.05e18 + bondAmount.mulDown(0.05e18)).divDown(vaultSharePrice), 1 ); // -10% interest - 5% margin released - 0% interest after close bondAmount = 1.05e18; - openSharePrice = 1e18; - closeSharePrice = 0.9e18; - sharePrice = 0.9e18; - shareAmount = uint256(1e18).divDown(sharePrice); + openVaultSharePrice = 1e18; + closeVaultSharePrice = 0.9e18; + vaultSharePrice = 0.9e18; + shareAmount = uint256(1e18).divDown(vaultSharePrice); flatFee = 0; shortProceeds = hyperdriveMath.calculateShortProceeds( bondAmount, shareAmount, - openSharePrice, - closeSharePrice, - sharePrice, + openVaultSharePrice, + closeVaultSharePrice, + vaultSharePrice, flatFee ); assertEq(shortProceeds, 0); // -10% interest - 5% margin released - 20% interest after close bondAmount = 1.05e18; - openSharePrice = 1e18; - closeSharePrice = 0.9e18; - sharePrice = 1.08e18; - shareAmount = uint256(1e18).divDown(sharePrice); + openVaultSharePrice = 1e18; + closeVaultSharePrice = 0.9e18; + vaultSharePrice = 1.08e18; + shareAmount = uint256(1e18).divDown(vaultSharePrice); flatFee = 0; shortProceeds = hyperdriveMath.calculateShortProceeds( bondAmount, shareAmount, - openSharePrice, - closeSharePrice, - sharePrice, + openVaultSharePrice, + closeVaultSharePrice, + vaultSharePrice, flatFee ); assertEq(shortProceeds, 0); @@ -1305,51 +1305,51 @@ contract HyperdriveMathTest is HyperdriveTest { // 5% interest - 0% margin released - 0% interest after close // 50% flatFee applied bondAmount = 1e18; - openSharePrice = 1e18; - closeSharePrice = 1.05e18; - sharePrice = 1.05e18; - shareAmount = uint256(1e18).divDown(sharePrice); + openVaultSharePrice = 1e18; + closeVaultSharePrice = 1.05e18; + vaultSharePrice = 1.05e18; + shareAmount = uint256(1e18).divDown(vaultSharePrice); flatFee = 0.5e18; shortProceeds = hyperdriveMath.calculateShortProceeds( bondAmount, shareAmount, - openSharePrice, - closeSharePrice, - sharePrice, + openVaultSharePrice, + closeVaultSharePrice, + vaultSharePrice, flatFee ); - // proceeds = (margin + interest) / share_price - // + (bondAmount * flatFee) / share_price + // proceeds = (margin + interest) / vault_share_price + // + (bondAmount * flatFee) / vault_share_price // = (0 + 1 * 0.05) / 1.05 + (1 * 0.5) / 1.05 assertApproxEqAbs( shortProceeds, - (bondAmount.mulDown(0.05e18)).divDown(sharePrice) + - (bondAmount.mulDivDown(flatFee, sharePrice)), + (bondAmount.mulDown(0.05e18)).divDown(vaultSharePrice) + + (bondAmount.mulDivDown(flatFee, vaultSharePrice)), 1 ); // 5% interest - 5% margin released - 0% interest after close bondAmount = 1.05e18; - openSharePrice = 1e18; - closeSharePrice = 1.05e18; - sharePrice = 1.05e18; - shareAmount = uint256(1e18).divDown(sharePrice); + openVaultSharePrice = 1e18; + closeVaultSharePrice = 1.05e18; + vaultSharePrice = 1.05e18; + shareAmount = uint256(1e18).divDown(vaultSharePrice); flatFee = 0.25e18; shortProceeds = hyperdriveMath.calculateShortProceeds( bondAmount, shareAmount, - openSharePrice, - closeSharePrice, - sharePrice, + openVaultSharePrice, + closeVaultSharePrice, + vaultSharePrice, flatFee ); - // proceeds = (margin + interest) / share_price - // + (bondAmount * flatFee) / share_price + // proceeds = (margin + interest) / vault_share_price + // + (bondAmount * flatFee) / vault_share_price // = ((0.05 + 1.05 * 0.05) / 1.05) + ((1 * 0.25) / 1.05) assertApproxEqAbs( shortProceeds, - (0.05e18 + bondAmount.mulDown(0.05e18)).divDown(sharePrice) + - bondAmount.mulDivDown(flatFee, sharePrice), + (0.05e18 + bondAmount.mulDown(0.05e18)).divDown(vaultSharePrice) + + bondAmount.mulDivDown(flatFee, vaultSharePrice), 1 ); } diff --git a/test/units/libraries/LPMath.t.sol b/test/units/libraries/LPMath.t.sol index 879ba9890..0ba121648 100644 --- a/test/units/libraries/LPMath.t.sol +++ b/test/units/libraries/LPMath.t.sol @@ -20,7 +20,7 @@ contract LPMathTest is HyperdriveTest { MockLPMath lpMath = new MockLPMath(); uint256 apr = 0.02e18; - uint256 initialSharePrice = 1e18; + uint256 initialVaultSharePrice = 1e18; uint256 positionDuration = 365 days; uint256 timeStretch = HyperdriveUtils.calculateTimeStretch( apr, @@ -35,14 +35,14 @@ contract LPMathTest is HyperdriveTest { shareAdjustment: 0, bondReserves: calculateBondReserves( 500_000_000e18, - initialSharePrice, + initialVaultSharePrice, apr, positionDuration, timeStretch ), minimumShareReserves: 1e5, - sharePrice: 2e18, - initialSharePrice: 1e18, + vaultSharePrice: 2e18, + initialVaultSharePrice: 1e18, timeStretch: timeStretch, longsOutstanding: 0, longAverageTimeRemaining: 0, @@ -64,13 +64,13 @@ contract LPMathTest is HyperdriveTest { shareAdjustment: 0, bondReserves: calculateBondReserves( 500_000_000e18, - initialSharePrice, + initialVaultSharePrice, apr, positionDuration, timeStretch ), - sharePrice: 2e18, - initialSharePrice: 1e18, + vaultSharePrice: 2e18, + initialVaultSharePrice: 1e18, minimumShareReserves: 1e5, timeStretch: timeStretch, longsOutstanding: 10_000_000e18, @@ -85,8 +85,8 @@ contract LPMathTest is HyperdriveTest { params.bondReserves, params.longsOutstanding, ONE - params.timeStretch, - params.sharePrice, - params.initialSharePrice + params.vaultSharePrice, + params.initialVaultSharePrice ); assertEq( presentValue, @@ -102,13 +102,13 @@ contract LPMathTest is HyperdriveTest { shareAdjustment: 0, bondReserves: calculateBondReserves( 500_000_000e18, - initialSharePrice, + initialVaultSharePrice, apr, positionDuration, timeStretch ), - sharePrice: 2e18, - initialSharePrice: 1e18, + vaultSharePrice: 2e18, + initialVaultSharePrice: 1e18, minimumShareReserves: 1e5, timeStretch: timeStretch, longsOutstanding: 10_000_000e18, @@ -118,7 +118,7 @@ contract LPMathTest is HyperdriveTest { }); uint256 presentValue = lpMath.calculatePresentValue(params); params.shareReserves -= params.longsOutstanding.divDown( - params.sharePrice + params.vaultSharePrice ); assertEq( presentValue, @@ -134,13 +134,13 @@ contract LPMathTest is HyperdriveTest { shareAdjustment: 0, bondReserves: calculateBondReserves( 500_000_000e18, - initialSharePrice, + initialVaultSharePrice, apr, positionDuration, timeStretch ), - sharePrice: 2e18, - initialSharePrice: 1e18, + vaultSharePrice: 2e18, + initialVaultSharePrice: 1e18, minimumShareReserves: 1e5, timeStretch: timeStretch, longsOutstanding: 0, @@ -155,8 +155,8 @@ contract LPMathTest is HyperdriveTest { params.bondReserves, params.shortsOutstanding, ONE - params.timeStretch, - params.sharePrice, - params.initialSharePrice + params.vaultSharePrice, + params.initialVaultSharePrice ); assertEq( presentValue, @@ -172,13 +172,13 @@ contract LPMathTest is HyperdriveTest { shareAdjustment: 0, bondReserves: calculateBondReserves( 500_000_000e18, - initialSharePrice, + initialVaultSharePrice, apr, positionDuration, timeStretch ), - sharePrice: 2e18, - initialSharePrice: 1e18, + vaultSharePrice: 2e18, + initialVaultSharePrice: 1e18, minimumShareReserves: 1e5, timeStretch: timeStretch, longsOutstanding: 0, @@ -188,7 +188,7 @@ contract LPMathTest is HyperdriveTest { }); uint256 presentValue = lpMath.calculatePresentValue(params); params.shareReserves += params.shortsOutstanding.divDown( - params.sharePrice + params.vaultSharePrice ); assertEq( presentValue, @@ -204,13 +204,13 @@ contract LPMathTest is HyperdriveTest { shareAdjustment: 0, bondReserves: calculateBondReserves( 500_000_000e18, - initialSharePrice, + initialVaultSharePrice, apr, positionDuration, timeStretch ), - sharePrice: 2e18, - initialSharePrice: 1e18, + vaultSharePrice: 2e18, + initialVaultSharePrice: 1e18, minimumShareReserves: 1e5, timeStretch: timeStretch, longsOutstanding: 10_000_000e18, @@ -233,13 +233,13 @@ contract LPMathTest is HyperdriveTest { shareAdjustment: 0, bondReserves: calculateBondReserves( 500_000_000e18, - initialSharePrice, + initialVaultSharePrice, apr, positionDuration, timeStretch ), - sharePrice: 2e18, - initialSharePrice: 1e18, + vaultSharePrice: 2e18, + initialVaultSharePrice: 1e18, minimumShareReserves: 1e5, timeStretch: timeStretch, longsOutstanding: 10_000_000e18, @@ -256,11 +256,11 @@ contract LPMathTest is HyperdriveTest { params.bondReserves, params.shortsOutstanding, ONE - params.timeStretch, - params.sharePrice, - params.initialSharePrice + params.vaultSharePrice, + params.initialVaultSharePrice ); params.shareReserves -= params.longsOutstanding.divDown( - params.sharePrice + params.vaultSharePrice ); assertEq( presentValue, @@ -276,13 +276,13 @@ contract LPMathTest is HyperdriveTest { shareAdjustment: 0, bondReserves: calculateBondReserves( 500_000_000e18, - initialSharePrice, + initialVaultSharePrice, apr, positionDuration, timeStretch ), - sharePrice: 2e18, - initialSharePrice: 1e18, + vaultSharePrice: 2e18, + initialVaultSharePrice: 1e18, minimumShareReserves: 1e5, timeStretch: timeStretch, longsOutstanding: 10_000_000e18, @@ -299,11 +299,11 @@ contract LPMathTest is HyperdriveTest { params.bondReserves, params.longsOutstanding, ONE - params.timeStretch, - params.sharePrice, - params.initialSharePrice + params.vaultSharePrice, + params.initialVaultSharePrice ); params.shareReserves += params.shortsOutstanding.divDown( - params.sharePrice + params.vaultSharePrice ); assertEq( presentValue, @@ -319,13 +319,13 @@ contract LPMathTest is HyperdriveTest { shareAdjustment: 0, bondReserves: calculateBondReserves( 500_000_000e18, - initialSharePrice, + initialVaultSharePrice, apr, positionDuration, timeStretch ), - sharePrice: 2e18, - initialSharePrice: 1e18, + vaultSharePrice: 2e18, + initialVaultSharePrice: 1e18, minimumShareReserves: 1e5, timeStretch: timeStretch, longsOutstanding: 100_000e18, @@ -349,17 +349,17 @@ contract LPMathTest is HyperdriveTest { params.longAverageTimeRemaining ), ONE - params.timeStretch, - params.sharePrice, - params.initialSharePrice + params.vaultSharePrice, + params.initialVaultSharePrice ); params.shareReserves += params.shortsOutstanding.mulDivDown( 1e18 - params.shortAverageTimeRemaining, - params.sharePrice + params.vaultSharePrice ) - params.longsOutstanding.mulDivDown( 1e18 - params.longAverageTimeRemaining, - params.sharePrice + params.vaultSharePrice ); assertEq( presentValue, @@ -375,13 +375,13 @@ contract LPMathTest is HyperdriveTest { shareAdjustment: 0, bondReserves: calculateBondReserves( 500_000_000e18, - initialSharePrice, + initialVaultSharePrice, apr, positionDuration, timeStretch ), - sharePrice: 2e18, - initialSharePrice: 1e18, + vaultSharePrice: 2e18, + initialVaultSharePrice: 1e18, minimumShareReserves: 1e5, timeStretch: timeStretch, longsOutstanding: 10_000_000e18, @@ -405,17 +405,17 @@ contract LPMathTest is HyperdriveTest { params.shortAverageTimeRemaining ), ONE - params.timeStretch, - params.sharePrice, - params.initialSharePrice + params.vaultSharePrice, + params.initialVaultSharePrice ); params.shareReserves -= params.longsOutstanding.mulDivDown( 1e18 - params.longAverageTimeRemaining, - params.sharePrice + params.vaultSharePrice ) - params.shortsOutstanding.mulDivDown( 1e18 - params.shortAverageTimeRemaining, - params.sharePrice + params.vaultSharePrice ); assertEq( presentValue, @@ -434,13 +434,13 @@ contract LPMathTest is HyperdriveTest { shareAdjustment: 0, bondReserves: calculateBondReserves( 100_000e18, - initialSharePrice, + initialVaultSharePrice, apr, positionDuration, timeStretch ), - sharePrice: 2e18, - initialSharePrice: 1e18, + vaultSharePrice: 2e18, + initialVaultSharePrice: 1e18, minimumShareReserves: 1e5, timeStretch: timeStretch, longsOutstanding: 100_000e18, @@ -462,30 +462,30 @@ contract LPMathTest is HyperdriveTest { uint256(int256(params.shareReserves) - params.shareAdjustment), params.bondReserves, ONE - params.timeStretch, - params.sharePrice, - params.initialSharePrice + params.vaultSharePrice, + params.initialVaultSharePrice ); uint256 maxShareProceeds = YieldSpaceMath.calculateMaxBuySharesIn( uint256(int256(params.shareReserves) - params.shareAdjustment), params.bondReserves, ONE - params.timeStretch, - params.sharePrice, - params.initialSharePrice + params.vaultSharePrice, + params.initialVaultSharePrice ); params.shareReserves += maxShareProceeds; params.shareReserves += (netCurveTrade - maxCurveTrade).divDown( - params.sharePrice + params.vaultSharePrice ); // Apply the flat part to the reserves. params.shareReserves += params.shortsOutstanding.mulDivDown( 1e18 - params.shortAverageTimeRemaining, - params.sharePrice + params.vaultSharePrice ) - params.longsOutstanding.mulDivDown( 1e18 - params.longAverageTimeRemaining, - params.sharePrice + params.vaultSharePrice ); assertEq( presentValue, @@ -501,13 +501,13 @@ contract LPMathTest is HyperdriveTest { shareAdjustment: 0, bondReserves: calculateBondReserves( 100_000e18, - initialSharePrice, + initialVaultSharePrice, apr, positionDuration, timeStretch ), - sharePrice: 2e18, - initialSharePrice: 1e18, + vaultSharePrice: 2e18, + initialVaultSharePrice: 1e18, minimumShareReserves: 1e18, timeStretch: timeStretch, longsOutstanding: 100_000e18, @@ -529,30 +529,30 @@ contract LPMathTest is HyperdriveTest { uint256(int256(params.shareReserves) - params.shareAdjustment), params.bondReserves, ONE - params.timeStretch, - params.sharePrice, - params.initialSharePrice + params.vaultSharePrice, + params.initialVaultSharePrice ); uint256 maxShareProceeds = YieldSpaceMath.calculateMaxBuySharesIn( uint256(int256(params.shareReserves) - params.shareAdjustment), params.bondReserves, ONE - params.timeStretch, - params.sharePrice, - params.initialSharePrice + params.vaultSharePrice, + params.initialVaultSharePrice ); params.shareReserves += maxShareProceeds; params.shareReserves += (netCurveTrade - maxCurveTrade).divDown( - params.sharePrice + params.vaultSharePrice ); // Apply the flat part to the reserves. params.shareReserves += params.shortsOutstanding.mulDivDown( 1e18 - params.shortAverageTimeRemaining, - params.sharePrice + params.vaultSharePrice ) - params.longsOutstanding.mulDivDown( 1e18 - params.longAverageTimeRemaining, - params.sharePrice + params.vaultSharePrice ); assertEq( presentValue, @@ -568,13 +568,13 @@ contract LPMathTest is HyperdriveTest { shareAdjustment: 10_000e18, bondReserves: calculateBondReserves( 100_000e18 - 10_000e18, - initialSharePrice, + initialVaultSharePrice, apr, positionDuration, timeStretch ), - sharePrice: 2e18, - initialSharePrice: 1e18, + vaultSharePrice: 2e18, + initialVaultSharePrice: 1e18, minimumShareReserves: 1e18, timeStretch: timeStretch, longsOutstanding: 100_000e18, @@ -596,30 +596,30 @@ contract LPMathTest is HyperdriveTest { uint256(int256(params.shareReserves) - params.shareAdjustment), params.bondReserves, ONE - params.timeStretch, - params.sharePrice, - params.initialSharePrice + params.vaultSharePrice, + params.initialVaultSharePrice ); uint256 maxShareProceeds = YieldSpaceMath.calculateMaxBuySharesIn( uint256(int256(params.shareReserves) - params.shareAdjustment), params.bondReserves, ONE - params.timeStretch, - params.sharePrice, - params.initialSharePrice + params.vaultSharePrice, + params.initialVaultSharePrice ); params.shareReserves += maxShareProceeds; params.shareReserves += (netCurveTrade - maxCurveTrade).divDown( - params.sharePrice + params.vaultSharePrice ); // Apply the flat part to the reserves. params.shareReserves += params.shortsOutstanding.mulDivDown( 1e18 - params.shortAverageTimeRemaining, - params.sharePrice + params.vaultSharePrice ) - params.longsOutstanding.mulDivDown( 1e18 - params.longAverageTimeRemaining, - params.sharePrice + params.vaultSharePrice ); assertEq( presentValue, @@ -633,7 +633,7 @@ contract LPMathTest is HyperdriveTest { MockLPMath lpMath = new MockLPMath(); uint256 apr = 0.02e18; - uint256 initialSharePrice = 0.5e18; + uint256 initialVaultSharePrice = 0.5e18; uint256 positionDuration = 365 days; uint256 timeStretch = HyperdriveUtils.calculateTimeStretch( apr, @@ -649,7 +649,7 @@ contract LPMathTest is HyperdriveTest { shareReserves, shareAdjustment ), - initialSharePrice, + initialVaultSharePrice, apr, positionDuration, timeStretch @@ -659,8 +659,8 @@ contract LPMathTest is HyperdriveTest { shareReserves: shareReserves, shareAdjustment: shareAdjustment, bondReserves: bondReserves, - sharePrice: 2e18, - initialSharePrice: initialSharePrice, + vaultSharePrice: 2e18, + initialVaultSharePrice: initialVaultSharePrice, minimumShareReserves: 1e5, timeStretch: timeStretch, longsOutstanding: 0, @@ -713,7 +713,7 @@ contract LPMathTest is HyperdriveTest { shareReserves, shareAdjustment ), - initialSharePrice, + initialVaultSharePrice, apr, positionDuration, timeStretch @@ -723,8 +723,8 @@ contract LPMathTest is HyperdriveTest { shareReserves: shareReserves, shareAdjustment: shareAdjustment, bondReserves: bondReserves, - sharePrice: 2e18, - initialSharePrice: initialSharePrice, + vaultSharePrice: 2e18, + initialVaultSharePrice: initialVaultSharePrice, minimumShareReserves: 1e5, timeStretch: timeStretch, longsOutstanding: 10_000_000e18, @@ -777,7 +777,7 @@ contract LPMathTest is HyperdriveTest { shareReserves, shareAdjustment ), - initialSharePrice, + initialVaultSharePrice, apr, positionDuration, timeStretch @@ -787,8 +787,8 @@ contract LPMathTest is HyperdriveTest { shareReserves: shareReserves, shareAdjustment: shareAdjustment, bondReserves: bondReserves, - sharePrice: 2e18, - initialSharePrice: initialSharePrice, + vaultSharePrice: 2e18, + initialVaultSharePrice: initialVaultSharePrice, minimumShareReserves: 1e5, timeStretch: timeStretch, longsOutstanding: 10_000_000e18, @@ -842,7 +842,7 @@ contract LPMathTest is HyperdriveTest { shareReserves, shareAdjustment ), - initialSharePrice, + initialVaultSharePrice, apr, positionDuration, timeStretch @@ -852,8 +852,8 @@ contract LPMathTest is HyperdriveTest { shareReserves: shareReserves, shareAdjustment: shareAdjustment, bondReserves: bondReserves, - sharePrice: 2e18, - initialSharePrice: initialSharePrice, + vaultSharePrice: 2e18, + initialVaultSharePrice: initialVaultSharePrice, minimumShareReserves: 1e5, timeStretch: timeStretch, longsOutstanding: 1_000_000e18, @@ -907,7 +907,7 @@ contract LPMathTest is HyperdriveTest { shareReserves, shareAdjustment ), - initialSharePrice, + initialVaultSharePrice, apr, positionDuration, timeStretch @@ -917,8 +917,8 @@ contract LPMathTest is HyperdriveTest { shareReserves: shareReserves, shareAdjustment: shareAdjustment, bondReserves: bondReserves, - sharePrice: 2e18, - initialSharePrice: initialSharePrice, + vaultSharePrice: 2e18, + initialVaultSharePrice: initialVaultSharePrice, minimumShareReserves: 1e5, timeStretch: timeStretch, longsOutstanding: 0, @@ -979,8 +979,8 @@ contract LPMathTest is HyperdriveTest { ), params.presentValueParams.bondReserves, ONE - params.presentValueParams.timeStretch, - params.presentValueParams.sharePrice, - params.presentValueParams.initialSharePrice + params.presentValueParams.vaultSharePrice, + params.presentValueParams.initialVaultSharePrice ); assertApproxEqAbs( maxBondAmount, @@ -995,7 +995,7 @@ contract LPMathTest is HyperdriveTest { MockLPMath lpMath = new MockLPMath(); uint256 apr = 0.02e18; - uint256 initialSharePrice = 1e18; + uint256 initialVaultSharePrice = 1e18; uint256 positionDuration = 365 days; uint256 timeStretch = HyperdriveUtils.calculateTimeStretch( apr, @@ -1011,7 +1011,7 @@ contract LPMathTest is HyperdriveTest { shareReserves, shareAdjustment ), - initialSharePrice, + initialVaultSharePrice, apr, positionDuration, timeStretch @@ -1021,8 +1021,8 @@ contract LPMathTest is HyperdriveTest { shareReserves: shareReserves, shareAdjustment: shareAdjustment, bondReserves: bondReserves, - sharePrice: 2e18, - initialSharePrice: initialSharePrice, + vaultSharePrice: 2e18, + initialVaultSharePrice: initialVaultSharePrice, minimumShareReserves: 1e5, timeStretch: timeStretch, longsOutstanding: 0, @@ -1105,7 +1105,7 @@ contract LPMathTest is HyperdriveTest { shareReserves, shareAdjustment ), - initialSharePrice, + initialVaultSharePrice, apr, positionDuration, timeStretch @@ -1115,8 +1115,8 @@ contract LPMathTest is HyperdriveTest { shareReserves: shareReserves, shareAdjustment: shareAdjustment, bondReserves: bondReserves, - sharePrice: 2e18, - initialSharePrice: initialSharePrice, + vaultSharePrice: 2e18, + initialVaultSharePrice: initialVaultSharePrice, minimumShareReserves: 1e5, timeStretch: timeStretch, longsOutstanding: 50_000_000e18, @@ -1199,7 +1199,7 @@ contract LPMathTest is HyperdriveTest { shareReserves, shareAdjustment ), - initialSharePrice, + initialVaultSharePrice, apr, positionDuration, timeStretch @@ -1209,8 +1209,8 @@ contract LPMathTest is HyperdriveTest { shareReserves: shareReserves, shareAdjustment: shareAdjustment, bondReserves: bondReserves, - sharePrice: 2e18, - initialSharePrice: initialSharePrice, + vaultSharePrice: 2e18, + initialVaultSharePrice: initialVaultSharePrice, minimumShareReserves: 1e5, timeStretch: timeStretch, longsOutstanding: 0, @@ -1292,7 +1292,7 @@ contract LPMathTest is HyperdriveTest { MockLPMath lpMath = new MockLPMath(); uint256 apr = 0.02e18; - uint256 initialSharePrice = 1e18; + uint256 initialVaultSharePrice = 1e18; uint256 positionDuration = 365 days; uint256 timeStretch = HyperdriveUtils.calculateTimeStretch( apr, @@ -1308,7 +1308,7 @@ contract LPMathTest is HyperdriveTest { shareReserves, shareAdjustment ), - initialSharePrice, + initialVaultSharePrice, apr, positionDuration, timeStretch @@ -1318,8 +1318,8 @@ contract LPMathTest is HyperdriveTest { shareReserves: shareReserves, shareAdjustment: shareAdjustment, bondReserves: bondReserves, - sharePrice: 2e18, - initialSharePrice: initialSharePrice, + vaultSharePrice: 2e18, + initialVaultSharePrice: initialVaultSharePrice, minimumShareReserves: 1e5, timeStretch: timeStretch, longsOutstanding: 0, @@ -1403,7 +1403,7 @@ contract LPMathTest is HyperdriveTest { shareReserves, shareAdjustment ), - initialSharePrice, + initialVaultSharePrice, apr, positionDuration, timeStretch @@ -1413,8 +1413,8 @@ contract LPMathTest is HyperdriveTest { shareReserves: shareReserves, shareAdjustment: shareAdjustment, bondReserves: bondReserves, - sharePrice: 2e18, - initialSharePrice: initialSharePrice, + vaultSharePrice: 2e18, + initialVaultSharePrice: initialVaultSharePrice, minimumShareReserves: 1e5, timeStretch: timeStretch, longsOutstanding: 50_000_000e18, @@ -1498,7 +1498,7 @@ contract LPMathTest is HyperdriveTest { shareReserves, shareAdjustment ), - initialSharePrice, + initialVaultSharePrice, apr, positionDuration, timeStretch @@ -1508,8 +1508,8 @@ contract LPMathTest is HyperdriveTest { shareReserves: shareReserves, shareAdjustment: shareAdjustment, bondReserves: bondReserves, - sharePrice: 2e18, - initialSharePrice: initialSharePrice, + vaultSharePrice: 2e18, + initialVaultSharePrice: initialVaultSharePrice, minimumShareReserves: 1e5, timeStretch: timeStretch, longsOutstanding: 0, @@ -1587,7 +1587,7 @@ contract LPMathTest is HyperdriveTest { function calculateBondReserves( uint256 _shareReserves, - uint256 _initialSharePrice, + uint256 _initialVaultSharePrice, uint256 _apr, uint256 _positionDuration, uint256 _timeStretch @@ -1602,7 +1602,7 @@ contract LPMathTest is HyperdriveTest { uint256 interestFactor = (ONE + _apr.mulDown(t)).pow(ONE.divDown(tau)); // bondReserves = mu * z * (1 + apr * t) ** (1 / tau) - bondReserves = _initialSharePrice.mulDown(_shareReserves).mulDown( + bondReserves = _initialVaultSharePrice.mulDown(_shareReserves).mulDown( interestFactor ); return bondReserves; diff --git a/test/units/libraries/YieldSpaceMath.t.sol b/test/units/libraries/YieldSpaceMath.t.sol index d0578f5d4..80b9dcc78 100644 --- a/test/units/libraries/YieldSpaceMath.t.sol +++ b/test/units/libraries/YieldSpaceMath.t.sol @@ -101,16 +101,22 @@ contract YieldSpaceMathTest is Test { function test__calculateSharesInGivenBondsOut__extremeValues( uint256 fixedRate, uint256 shareReserves, - uint256 sharePrice, - uint256 initialSharePrice, + uint256 vaultSharePrice, + uint256 initialVaultSharePrice, uint256 tradeSize ) external { MockYieldSpaceMath yieldSpaceMath = new MockYieldSpaceMath(); uint256 minimumShareReserves = 1e5; fixedRate = fixedRate.normalizeToRange(0.01e18, 1e18); - initialSharePrice = initialSharePrice.normalizeToRange(0.8e18, 5e18); - sharePrice = sharePrice.normalizeToRange(initialSharePrice, 5e18); + initialVaultSharePrice = initialVaultSharePrice.normalizeToRange( + 0.8e18, + 5e18 + ); + vaultSharePrice = vaultSharePrice.normalizeToRange( + initialVaultSharePrice, + 5e18 + ); // Test a large span of orders of magnitudes of both the reserves and // the size of the reserves. This test demonstrates that for the @@ -130,7 +136,7 @@ contract YieldSpaceMathTest is Test { uint256 bondReserves = HyperdriveMath .calculateInitialBondReserves( shareReserves, - initialSharePrice, + initialVaultSharePrice, fixedRate, 365 days, timeStretch @@ -145,8 +151,8 @@ contract YieldSpaceMathTest is Test { longsOutstanding: 0, longExposure: 0, timeStretch: timeStretch, - sharePrice: sharePrice, - initialSharePrice: initialSharePrice, + vaultSharePrice: vaultSharePrice, + initialVaultSharePrice: initialVaultSharePrice, minimumShareReserves: minimumShareReserves, curveFee: 0, flatFee: 0, @@ -166,8 +172,8 @@ contract YieldSpaceMathTest is Test { bondReserves, tradeSize, 1e18 - ONE.mulDown(timeStretch), - sharePrice, - initialSharePrice + vaultSharePrice, + initialVaultSharePrice ); assertGt(result, 0); } @@ -177,8 +183,8 @@ contract YieldSpaceMathTest is Test { function test__calculateMaxBuy( uint256 fixedRate, uint256 shareReserves, - uint256 sharePrice, - uint256 initialSharePrice + uint256 vaultSharePrice, + uint256 initialVaultSharePrice ) external { MockYieldSpaceMath yieldSpaceMath = new MockYieldSpaceMath(); @@ -187,8 +193,14 @@ contract YieldSpaceMathTest is Test { 0.0001e18, 500_000_000e18 ); - initialSharePrice = initialSharePrice.normalizeToRange(0.8e18, 5e18); - sharePrice = sharePrice.normalizeToRange(initialSharePrice, 5e18); + initialVaultSharePrice = initialVaultSharePrice.normalizeToRange( + 0.8e18, + 5e18 + ); + vaultSharePrice = vaultSharePrice.normalizeToRange( + initialVaultSharePrice, + 5e18 + ); // Calculate the bond reserves that give the pool the expected spot rate. uint256 timeStretch = HyperdriveUtils.calculateTimeStretch( @@ -197,7 +209,7 @@ contract YieldSpaceMathTest is Test { ); uint256 bondReserves = HyperdriveMath.calculateInitialBondReserves( shareReserves, - initialSharePrice, + initialVaultSharePrice, fixedRate, 365 days, timeStretch @@ -208,15 +220,15 @@ contract YieldSpaceMathTest is Test { shareReserves, bondReserves, 1e18 - ONE.mulDown(timeStretch), - sharePrice, - initialSharePrice + vaultSharePrice, + initialVaultSharePrice ); uint256 maxDz = yieldSpaceMath.calculateMaxBuySharesIn( shareReserves, bondReserves, 1e18 - ONE.mulDown(timeStretch), - sharePrice, - initialSharePrice + vaultSharePrice, + initialVaultSharePrice ); // Ensure that the maximum buy is a valid trade on this invariant and @@ -226,15 +238,15 @@ contract YieldSpaceMathTest is Test { shareReserves, bondReserves, ONE - timeStretch, - sharePrice, - initialSharePrice + vaultSharePrice, + initialVaultSharePrice ), yieldSpaceMath.kDown( shareReserves + maxDz, bondReserves - maxDy, ONE - timeStretch, - sharePrice, - initialSharePrice + vaultSharePrice, + initialVaultSharePrice ), 1e12 // TODO: Investigate this bound. ); @@ -242,7 +254,7 @@ contract YieldSpaceMathTest is Test { HyperdriveMath.calculateSpotPrice( shareReserves + maxDz, bondReserves - maxDy, - initialSharePrice, + initialVaultSharePrice, timeStretch ), 1e18, diff --git a/test/utils/HyperdriveTest.sol b/test/utils/HyperdriveTest.sol index 060db74ec..d339199ca 100644 --- a/test/utils/HyperdriveTest.sol +++ b/test/utils/HyperdriveTest.sol @@ -89,7 +89,7 @@ contract HyperdriveTest is BaseTest { function deploy( address deployer, uint256 apr, - uint256 initialSharePrice, + uint256 initialVaultSharePrice, uint256 curveFee, uint256 flatFee, uint256 governanceLPFee, @@ -99,7 +99,7 @@ contract HyperdriveTest is BaseTest { apr, POSITION_DURATION ); - config.initialSharePrice = initialSharePrice; + config.initialVaultSharePrice = initialVaultSharePrice; config.fees.curve = curveFee; config.fees.flat = flatFee; config.fees.governanceLP = governanceLPFee; @@ -129,7 +129,7 @@ contract HyperdriveTest is BaseTest { _config.feeCollector = _deployConfig.feeCollector; _config.fees = _deployConfig.fees; - _config.initialSharePrice = ONE; + _config.initialVaultSharePrice = ONE; } function testDeployConfig( @@ -176,7 +176,7 @@ contract HyperdriveTest is BaseTest { uint256 depositAmount; // The minimum share price that will be accepted. It may not be used by // some actions. - uint256 minSharePrice; + uint256 minVaultSharePrice; // This is the slippage parameter that defines a lower bound on the // quantity being measured. It may not be used by some actions. uint256 minSlippage; @@ -251,7 +251,7 @@ contract HyperdriveTest is BaseTest { DepositOverrides({ asBase: true, depositAmount: contribution, - minSharePrice: 0, // unused + minVaultSharePrice: 0, // unused minSlippage: 0, // unused maxSlippage: type(uint256).max, // unused extraData: new bytes(0) // unused @@ -273,7 +273,7 @@ contract HyperdriveTest is BaseTest { DepositOverrides({ asBase: asBase, depositAmount: contribution, - minSharePrice: 0, // unused + minVaultSharePrice: 0, // unused minSlippage: 0, // unused maxSlippage: type(uint256).max, // unused extraData: new bytes(0) // unused @@ -333,7 +333,7 @@ contract HyperdriveTest is BaseTest { DepositOverrides({ asBase: true, depositAmount: contribution, - minSharePrice: 0, // unused + minVaultSharePrice: 0, // unused minSlippage: 0, // min spot rate of 0 maxSlippage: type(uint256).max, // max spot rate of uint256 max extraData: new bytes(0) // unused @@ -353,7 +353,7 @@ contract HyperdriveTest is BaseTest { DepositOverrides({ asBase: asBase, depositAmount: contribution, - minSharePrice: 0, // unused + minVaultSharePrice: 0, // unused minSlippage: 0, // min spot rate of 0 maxSlippage: type(uint256).max, // max spot rate of uint256 max extraData: new bytes(0) // unused @@ -487,7 +487,7 @@ contract HyperdriveTest is BaseTest { hyperdrive.openLong{ value: overrides.depositAmount }( baseAmount, overrides.minSlippage, // min bond proceeds - overrides.minSharePrice, + overrides.minVaultSharePrice, IHyperdrive.Options({ destination: trader, asBase: overrides.asBase, @@ -501,7 +501,7 @@ contract HyperdriveTest is BaseTest { hyperdrive.openLong( baseAmount, overrides.minSlippage, // min bond proceeds - overrides.minSharePrice, + overrides.minVaultSharePrice, IHyperdrive.Options({ destination: trader, asBase: overrides.asBase, @@ -522,7 +522,7 @@ contract HyperdriveTest is BaseTest { DepositOverrides({ asBase: true, depositAmount: baseAmount, - minSharePrice: 0, // min share price of 0 + minVaultSharePrice: 0, // min share price of 0 minSlippage: baseAmount, // min bond proceeds of baseAmount maxSlippage: type(uint256).max, // unused extraData: new bytes(0) // unused @@ -542,7 +542,7 @@ contract HyperdriveTest is BaseTest { DepositOverrides({ asBase: asBase, depositAmount: baseAmount, - minSharePrice: 0, // min share price of 0 + minVaultSharePrice: 0, // min share price of 0 minSlippage: baseAmount, // min bond proceeds of baseAmount maxSlippage: type(uint256).max, // unused extraData: new bytes(0) // unused @@ -631,7 +631,7 @@ contract HyperdriveTest is BaseTest { }( bondAmount, overrides.maxSlippage, // max base payment - overrides.minSharePrice, + overrides.minVaultSharePrice, IHyperdrive.Options({ destination: trader, asBase: overrides.asBase, @@ -644,7 +644,7 @@ contract HyperdriveTest is BaseTest { (maturityTime, baseAmount) = hyperdrive.openShort( bondAmount, overrides.maxSlippage, // max base payment - overrides.minSharePrice, + overrides.minVaultSharePrice, IHyperdrive.Options({ destination: trader, asBase: overrides.asBase, @@ -668,7 +668,7 @@ contract HyperdriveTest is BaseTest { DepositOverrides({ asBase: true, depositAmount: bondAmount, - minSharePrice: 0, // min share price of 0 + minVaultSharePrice: 0, // min share price of 0 minSlippage: 0, // unused maxSlippage: bondAmount, // max base payment of bondAmount extraData: new bytes(0) // unused @@ -688,7 +688,7 @@ contract HyperdriveTest is BaseTest { DepositOverrides({ asBase: asBase, depositAmount: bondAmount, - minSharePrice: 0, // min share price of 0 + minVaultSharePrice: 0, // min share price of 0 minSlippage: 0, // unused maxSlippage: bondAmount, // max base payment of bondAmount extraData: new bytes(0) // unused @@ -808,8 +808,8 @@ contract HyperdriveTest is BaseTest { function estimateLongProceeds( uint256 bondAmount, uint256 normalizedTimeRemaining, - uint256 openSharePrice, - uint256 closeSharePrice + uint256 openVaultSharePrice, + uint256 closeVaultSharePrice ) internal view returns (uint256) { IHyperdrive.PoolInfo memory poolInfo = hyperdrive.getPoolInfo(); IHyperdrive.PoolConfig memory poolConfig = hyperdrive.getPoolConfig(); @@ -819,16 +819,16 @@ contract HyperdriveTest is BaseTest { bondAmount, normalizedTimeRemaining, poolConfig.timeStretch, - poolInfo.sharePrice, - poolConfig.initialSharePrice + poolInfo.vaultSharePrice, + poolConfig.initialVaultSharePrice ); - if (closeSharePrice < openSharePrice) { + if (closeVaultSharePrice < openVaultSharePrice) { shareProceeds = shareProceeds.mulDivDown( - closeSharePrice, - openSharePrice + closeVaultSharePrice, + openVaultSharePrice ); } - return shareProceeds.mulDivDown(poolInfo.sharePrice, 1e18); + return shareProceeds.mulDivDown(poolInfo.vaultSharePrice, 1e18); } function estimateShortProceeds( @@ -846,8 +846,8 @@ contract HyperdriveTest is BaseTest { shortAmount, normalizedTimeRemaining, poolConfig.timeStretch, - poolInfo.sharePrice, - poolConfig.initialSharePrice + poolInfo.vaultSharePrice, + poolConfig.initialVaultSharePrice ); (, int256 expectedInterest) = HyperdriveUtils.calculateCompoundInterest( shortAmount, @@ -855,7 +855,7 @@ contract HyperdriveTest is BaseTest { timeElapsed ); int256 delta = int256( - shortAmount - poolInfo.sharePrice.mulDown(expectedSharePayment) + shortAmount - poolInfo.vaultSharePrice.mulDown(expectedSharePayment) ); if (delta + expectedInterest > 0) { return uint256(delta + expectedInterest); @@ -876,7 +876,7 @@ contract HyperdriveTest is BaseTest { (uint256 withdrawalSharesRedeemed, uint256 shareProceeds) = LPMath .calculateDistributeExcessIdle(params); return ( - shareProceeds.mulDown(hyperdrive.getPoolInfo().sharePrice), + shareProceeds.mulDown(hyperdrive.getPoolInfo().vaultSharePrice), _lpShares - withdrawalSharesRedeemed ); } @@ -894,7 +894,7 @@ contract HyperdriveTest is BaseTest { address indexed provider, uint256 lpAmount, uint256 baseAmount, - uint256 sharePrice, + uint256 vaultSharePrice, uint256 apr ); @@ -902,7 +902,7 @@ contract HyperdriveTest is BaseTest { address indexed provider, uint256 lpAmount, uint256 baseAmount, - uint256 sharePrice, + uint256 vaultSharePrice, uint256 lpSharePrice ); @@ -910,7 +910,7 @@ contract HyperdriveTest is BaseTest { address indexed provider, uint256 lpAmount, uint256 baseAmount, - uint256 sharePrice, + uint256 vaultSharePrice, uint256 withdrawalShareAmount, uint256 lpSharePrice ); @@ -919,7 +919,7 @@ contract HyperdriveTest is BaseTest { address indexed provider, uint256 withdrawalShareAmount, uint256 baseAmount, - uint256 sharePrice + uint256 vaultSharePrice ); event OpenLong( @@ -927,7 +927,7 @@ contract HyperdriveTest is BaseTest { uint256 indexed assetId, uint256 maturityTime, uint256 baseAmount, - uint256 sharePrice, + uint256 vaultSharePrice, uint256 bondAmount ); @@ -936,7 +936,7 @@ contract HyperdriveTest is BaseTest { uint256 indexed assetId, uint256 maturityTime, uint256 baseAmount, - uint256 sharePrice, + uint256 vaultSharePrice, uint256 bondAmount ); @@ -945,7 +945,7 @@ contract HyperdriveTest is BaseTest { uint256 indexed assetId, uint256 maturityTime, uint256 baseAmount, - uint256 sharePrice, + uint256 vaultSharePrice, uint256 bondAmount ); @@ -954,13 +954,13 @@ contract HyperdriveTest is BaseTest { uint256 indexed assetId, uint256 maturityTime, uint256 baseAmount, - uint256 sharePrice, + uint256 vaultSharePrice, uint256 bondAmount ); event CreateCheckpoint( uint256 indexed checkpointTime, - uint256 sharePrice, + uint256 vaultSharePrice, uint256 maturedShorts, uint256 maturedLongs, uint256 lpSharePrice @@ -969,7 +969,7 @@ contract HyperdriveTest is BaseTest { event CollectGovernanceFee( address indexed collector, uint256 baseFees, - uint256 sharePrice + uint256 vaultSharePrice ); function verifyFactoryEvents( @@ -1082,12 +1082,15 @@ contract HyperdriveTest is BaseTest { assertApproxEqAbs( eventLpAmount, contribution_.divDown( - hyperdrive_.getPoolConfig().initialSharePrice + hyperdrive_.getPoolConfig().initialVaultSharePrice ) - 2 * minimumShareReserves, tolerance ); assertEq(eventBaseAmount, contribution_); - assertEq(eventSharePrice, hyperdrive_.getPoolInfo().sharePrice); + assertEq( + eventSharePrice, + hyperdrive_.getPoolInfo().vaultSharePrice + ); assertEq(eventApr, apr); } } diff --git a/test/utils/HyperdriveUtils.sol b/test/utils/HyperdriveUtils.sol index ece5e625b..41c86e25c 100644 --- a/test/utils/HyperdriveUtils.sol +++ b/test/utils/HyperdriveUtils.sol @@ -58,7 +58,7 @@ library HyperdriveUtils { poolInfo.shareAdjustment ), poolInfo.bondReserves, - poolConfig.initialSharePrice, + poolConfig.initialVaultSharePrice, poolConfig.timeStretch ); } @@ -75,7 +75,7 @@ library HyperdriveUtils { poolInfo.shareAdjustment ), poolInfo.bondReserves, - poolConfig.initialSharePrice, + poolConfig.initialVaultSharePrice, poolConfig.positionDuration, poolConfig.timeStretch ); @@ -232,8 +232,8 @@ library HyperdriveUtils { longsOutstanding: poolInfo.longsOutstanding, longExposure: poolInfo.longExposure, timeStretch: poolConfig.timeStretch, - sharePrice: poolInfo.sharePrice, - initialSharePrice: poolConfig.initialSharePrice, + vaultSharePrice: poolInfo.vaultSharePrice, + initialVaultSharePrice: poolConfig.initialVaultSharePrice, minimumShareReserves: poolConfig.minimumShareReserves, curveFee: poolConfig.fees.curve, flatFee: poolConfig.fees.flat, @@ -273,8 +273,8 @@ library HyperdriveUtils { longsOutstanding: poolInfo.longsOutstanding, longExposure: poolInfo.longExposure, timeStretch: poolConfig.timeStretch, - sharePrice: poolInfo.sharePrice, - initialSharePrice: poolConfig.initialSharePrice, + vaultSharePrice: poolInfo.vaultSharePrice, + initialVaultSharePrice: poolConfig.initialVaultSharePrice, minimumShareReserves: poolConfig.minimumShareReserves, curveFee: poolConfig.fees.curve, flatFee: poolConfig.fees.flat, @@ -303,8 +303,8 @@ library HyperdriveUtils { uint256 longsOutstanding; uint256 longExposure; uint256 timeStretch; - uint256 sharePrice; - uint256 initialSharePrice; + uint256 vaultSharePrice; + uint256 initialVaultSharePrice; uint256 minimumShareReserves; uint256 curveFee; uint256 flatFee; @@ -337,7 +337,7 @@ library HyperdriveUtils { uint256 spotPrice = HyperdriveMath.calculateSpotPrice( effectiveShareReserves, _params.bondReserves, - _params.initialSharePrice, + _params.initialVaultSharePrice, _params.timeStretch ); uint256 absoluteMaxBaseAmount; @@ -506,8 +506,8 @@ library HyperdriveUtils { _effectiveShareReserves, _params.bondReserves, ONE - _params.timeStretch, - _params.sharePrice, - _params.initialSharePrice + _params.vaultSharePrice, + _params.initialVaultSharePrice ); inner = _params.curveFee.mulUp(ONE.divUp(_spotPrice) - ONE).mulUp( ONE - _params.flatFee @@ -516,11 +516,15 @@ library HyperdriveUtils { inner = inner.pow( (ONE - _params.timeStretch).divDown(_params.timeStretch) ); - inner += _params.sharePrice.divUp(_params.initialSharePrice); + inner += _params.vaultSharePrice.divUp( + _params.initialVaultSharePrice + ); inner = k_.divDown(inner); inner = inner.pow(ONE.divDown(ONE - _params.timeStretch)); } - uint256 targetShareReserves = inner.divDown(_params.initialSharePrice); + uint256 targetShareReserves = inner.divDown( + _params.initialVaultSharePrice + ); // Now that we have the target share reserves, we can calculate the // target bond reserves using the formula: @@ -543,7 +547,7 @@ library HyperdriveUtils { // // absoluteMaxBaseAmount = c * (z_t - z) absoluteMaxBaseAmount = (targetShareReserves - _effectiveShareReserves) - .mulDown(_params.sharePrice); + .mulDown(_params.vaultSharePrice); // The absolute max bond amount is given by: // @@ -655,9 +659,12 @@ library HyperdriveUtils { ) internal pure returns (uint256) { uint256 checkpointExposure = uint256(-_checkpointExposure.min(0)); uint256 estimate = (_params.shareReserves + - checkpointExposure.divDown(_params.sharePrice) - - _params.longExposure.divDown(_params.sharePrice) - - _params.minimumShareReserves).mulDivDown(_params.sharePrice, 2e18); + checkpointExposure.divDown(_params.vaultSharePrice) - + _params.longExposure.divDown(_params.vaultSharePrice) - + _params.minimumShareReserves).mulDivDown( + _params.vaultSharePrice, + 2e18 + ); estimate = estimate.divDown( ONE.divDown(_estimatePrice) + _params.governanceLPFee.mulDown(_params.curveFee).mulDown( @@ -730,18 +737,20 @@ library HyperdriveUtils { _params.governanceLPFee ); uint256 shareReserves = _params.shareReserves + - _baseAmount.divDown(_params.sharePrice) - - governanceFee.divDown(_params.sharePrice); + _baseAmount.divDown(_params.vaultSharePrice) - + governanceFee.divDown(_params.vaultSharePrice); uint256 exposure = _params.longExposure + _bondAmount; uint256 checkpointExposure = uint256(-_checkpointExposure.min(0)); if ( - shareReserves + checkpointExposure.divDown(_params.sharePrice) >= - exposure.divDown(_params.sharePrice) + _params.minimumShareReserves + shareReserves + + checkpointExposure.divDown(_params.vaultSharePrice) >= + exposure.divDown(_params.vaultSharePrice) + + _params.minimumShareReserves ) { return ( shareReserves + - checkpointExposure.divDown(_params.sharePrice) - - exposure.divDown(_params.sharePrice) - + checkpointExposure.divDown(_params.vaultSharePrice) - + exposure.divDown(_params.vaultSharePrice) - _params.minimumShareReserves, true ); @@ -802,7 +811,7 @@ library HyperdriveUtils { ); derivative -= ONE; - return (derivative.mulDivDown(1e18, _params.sharePrice), success); + return (derivative.mulDivDown(1e18, _params.vaultSharePrice), success); } /// @dev Gets the long amount that will be opened for a given base amount. @@ -838,10 +847,10 @@ library HyperdriveUtils { uint256 longAmount = HyperdriveMath.calculateOpenLong( _effectiveShareReserves, _params.bondReserves, - _baseAmount.divDown(_params.sharePrice), + _baseAmount.divDown(_params.vaultSharePrice), _params.timeStretch, - _params.sharePrice, - _params.initialSharePrice + _params.vaultSharePrice, + _params.initialVaultSharePrice ); return longAmount - @@ -890,25 +899,25 @@ library HyperdriveUtils { uint256 _spotPrice ) internal pure returns (uint256 derivative, bool) { // Compute the first part of the derivative. - uint256 shareAmount = _baseAmount.divDown(_params.sharePrice); - uint256 inner = _params.initialSharePrice.mulDown( + uint256 shareAmount = _baseAmount.divDown(_params.vaultSharePrice); + uint256 inner = _params.initialVaultSharePrice.mulDown( _effectiveShareReserves + shareAmount ); uint256 k_ = YieldSpaceMath.kDown( _effectiveShareReserves, _params.bondReserves, ONE - _params.timeStretch, - _params.sharePrice, - _params.initialSharePrice + _params.vaultSharePrice, + _params.initialVaultSharePrice ); derivative = ONE.divDown(inner.pow(_params.timeStretch)); // It's possible that k is slightly larger than the rhs in the inner // calculation. If this happens, we are close to the root, and we short // circuit. - uint256 rhs = _params.sharePrice.mulDivDown( + uint256 rhs = _params.vaultSharePrice.mulDivDown( inner.pow(_params.timeStretch), - _params.initialSharePrice + _params.initialVaultSharePrice ); if (k_ < rhs) { return (0, false); @@ -1000,7 +1009,7 @@ library HyperdriveUtils { uint256 spotPrice = HyperdriveMath.calculateSpotPrice( effectiveShareReserves, _params.bondReserves, - _params.initialSharePrice, + _params.initialVaultSharePrice, _params.timeStretch ); uint256 absoluteMaxBondAmount = calculateMaxShortUpperBound( @@ -1133,21 +1142,22 @@ library HyperdriveUtils { _effectiveShareReserves, _params.bondReserves, ONE - _params.timeStretch, - _params.sharePrice, - _params.initialSharePrice + _params.vaultSharePrice, + _params.initialVaultSharePrice ); uint256 optimalBondReserves = (k_ - - (_params.sharePrice.divDown(_params.initialSharePrice)).mulDown( - _params - .initialSharePrice - .mulDown( - HyperdriveMath.calculateEffectiveShareReserves( - optimalShareReserves, - _params.shareAdjustment + (_params.vaultSharePrice.divDown(_params.initialVaultSharePrice)) + .mulDown( + _params + .initialVaultSharePrice + .mulDown( + HyperdriveMath.calculateEffectiveShareReserves( + optimalShareReserves, + _params.shareAdjustment + ) ) - ) - .pow(ONE - _params.timeStretch) - )).pow(ONE.divUp(ONE - _params.timeStretch)); + .pow(ONE - _params.timeStretch) + )).pow(ONE.divUp(ONE - _params.timeStretch)); return optimalBondReserves - _params.bondReserves; } @@ -1186,12 +1196,12 @@ library HyperdriveUtils { int256 _checkpointExposure ) internal pure returns (uint256) { uint256 estimatePrice = _spotPrice; - uint256 guess = _params.sharePrice.mulDown( + uint256 guess = _params.vaultSharePrice.mulDown( _params.shareReserves + uint256(_checkpointExposure.max(0)).divDown( - _params.sharePrice + _params.vaultSharePrice ) - - _params.longExposure.divDown(_params.sharePrice) - + _params.longExposure.divDown(_params.vaultSharePrice) - _params.minimumShareReserves ); return @@ -1265,8 +1275,8 @@ library HyperdriveUtils { _params.bondReserves, _shortAmount, ONE - _params.timeStretch, - _params.sharePrice, - _params.initialSharePrice + _params.vaultSharePrice, + _params.initialVaultSharePrice ); if (!success) { return (0, false); @@ -1285,9 +1295,11 @@ library HyperdriveUtils { _spotPrice, _params.curveFee, _params.governanceLPFee - )).divDown(_params.sharePrice)); + )).divDown(_params.vaultSharePrice)); uint256 exposure = (_params.longExposure - - uint256(_checkpointExposure.max(0))).divDown(_params.sharePrice); + uint256(_checkpointExposure.max(0))).divDown( + _params.vaultSharePrice + ); if (shareReserves >= exposure + _params.minimumShareReserves) { return ( shareReserves - exposure - _params.minimumShareReserves, @@ -1332,7 +1344,7 @@ library HyperdriveUtils { .curveFee .mulDown(ONE - _spotPrice) .mulDown(ONE - _params.governanceLPFee) - .divDown(_params.sharePrice); + .divDown(_params.vaultSharePrice); if (lhs >= rhs) { return (lhs - rhs, true); } else { @@ -1363,17 +1375,17 @@ library HyperdriveUtils { _effectiveShareReserves, _params.bondReserves, ONE - _params.timeStretch, - _params.sharePrice, - _params.initialSharePrice + _params.vaultSharePrice, + _params.initialVaultSharePrice ); uint256 lhs = ONE.divDown( - _params.sharePrice.mulUp( + _params.vaultSharePrice.mulUp( (_params.bondReserves + _shortAmount).pow(_params.timeStretch) ) ); uint256 rhs = _params - .initialSharePrice - .divDown(_params.sharePrice) + .initialVaultSharePrice + .divDown(_params.vaultSharePrice) .mulDown( k_ - (_params.bondReserves + _shortAmount).pow( @@ -1427,8 +1439,8 @@ library HyperdriveUtils { shareReserves: poolInfo.shareReserves, shareAdjustment: poolInfo.shareAdjustment, bondReserves: poolInfo.bondReserves, - sharePrice: poolInfo.sharePrice, - initialSharePrice: poolConfig.initialSharePrice, + vaultSharePrice: poolInfo.vaultSharePrice, + initialVaultSharePrice: poolConfig.initialVaultSharePrice, minimumShareReserves: poolConfig.minimumShareReserves, timeStretch: poolConfig.timeStretch, longsOutstanding: poolInfo.longsOutstanding, @@ -1487,7 +1499,7 @@ library HyperdriveUtils { return LPMath .calculatePresentValue(hyperdrive.getPresentValueParams()) - .mulDown(hyperdrive.getPoolInfo().sharePrice); + .mulDown(hyperdrive.getPoolInfo().vaultSharePrice); } function lpSharePrice( @@ -1508,7 +1520,7 @@ library HyperdriveUtils { function idle(IHyperdrive hyperdrive) internal view returns (uint256) { return uint256(hyperdrive.solvency().max(0)).mulDown( - hyperdrive.getPoolInfo().sharePrice + hyperdrive.getPoolInfo().vaultSharePrice ); } @@ -1517,7 +1529,7 @@ library HyperdriveUtils { IHyperdrive.PoolInfo memory info = hyperdrive.getPoolInfo(); return int256(info.shareReserves) - - int256(info.longExposure.divDown(info.sharePrice)) - + int256(info.longExposure.divDown(info.vaultSharePrice)) - int256(config.minimumShareReserves); } @@ -1532,8 +1544,8 @@ library HyperdriveUtils { ), info.bondReserves, ONE - config.timeStretch, - info.sharePrice, - config.initialSharePrice + info.vaultSharePrice, + config.initialVaultSharePrice ); }