Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions contracts/src/interfaces/IHyperdriveEvents.sol
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ interface IHyperdriveEvents is IMultiTokenEvents {
uint256 baseAmount,
uint256 vaultShareAmount,
bool asBase,
uint256 baseProceeds,
uint256 bondAmount
);

Expand Down
37 changes: 20 additions & 17 deletions contracts/src/internal/HyperdriveShort.sol
Original file line number Diff line number Diff line change
Expand Up @@ -61,23 +61,18 @@ abstract contract HyperdriveShort is IHyperdriveEvents, HyperdriveLP {
// backdate the bonds sold to the beginning of the checkpoint.
// Note: All state deltas are derived from the external function input.
uint256 maturityTime = latestCheckpoint + _positionDuration;
uint256 shareReservesDelta;
uint256 baseDeposit;
{
uint256 totalGovernanceFee;
(
baseDeposit,
shareReservesDelta,
totalGovernanceFee
) = _calculateOpenShort(
(
uint256 baseDeposit,
uint256 shareReservesDelta,
uint256 totalGovernanceFee
) = _calculateOpenShort(
_bondAmount,
vaultSharePrice,
openVaultSharePrice
);

// Attribute the governance fees.
_governanceFeesAccrued += totalGovernanceFee;
}
// Attribute the governance fees.
_governanceFeesAccrued += totalGovernanceFee;

// Take custody of the trader's deposit and ensure that the trader
// doesn't pay more than their max deposit. The trader's deposit is
Expand All @@ -87,15 +82,15 @@ abstract contract HyperdriveShort is IHyperdriveEvents, HyperdriveLP {
// Note: We don't check the maxDeposit against the output of deposit
// because slippage from a deposit could cause a larger deposit taken
// from the user to pass due to the shares being worth less after deposit.
uint256 traderDeposit = _convertToOptionFromBase(
uint256 shareDeposit = _convertToOptionFromBase(
baseDeposit,
vaultSharePrice,
_options
);
if (_maxDeposit < traderDeposit) {
if (_maxDeposit < shareDeposit) {
revert IHyperdrive.OutputLimit();
}
_deposit(traderDeposit, _options);
_deposit(shareDeposit, _options);

// Apply the state updates caused by opening the short.
// Note: Updating the state using the result using the
Expand All @@ -117,18 +112,26 @@ abstract contract HyperdriveShort is IHyperdriveEvents, HyperdriveLP {
_mint(assetId, _options.destination, bondAmount);

// Emit an OpenShort event.
uint256 vaultSharePrice_ = vaultSharePrice;
IHyperdrive.Options calldata options = _options;
emit OpenShort(
options.destination,
assetId,
maturityTime,
baseDeposit,
baseDeposit.divDown(vaultSharePrice),
baseDeposit.divDown(vaultSharePrice_),
options.asBase,
_convertToBaseFromOption(
// We add the governance fee to the share reserves delta since
// the user is responsible for paying the governance fee.
shareReservesDelta + totalGovernanceFee,
vaultSharePrice_,
options
),
bondAmount
);

return (maturityTime, traderDeposit);
return (maturityTime, shareDeposit);
}

/// @dev Closes a short position with a specified maturity time.
Expand Down
4 changes: 3 additions & 1 deletion test/units/hyperdrive/OpenShortTest.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -394,10 +394,11 @@ contract OpenShortTest is HyperdriveTest {
uint256 eventBaseAmount,
uint256 eventVaultShareAmount,
bool eventAsBase,
uint256 eventBaseProceeds,
uint256 eventBondAmount
) = abi.decode(
log.data,
(uint256, uint256, uint256, bool, uint256)
(uint256, uint256, uint256, bool, uint256, uint256)
);
assertEq(eventMaturityTime, maturityTime);
assertEq(eventBaseAmount, basePaid);
Expand All @@ -406,6 +407,7 @@ contract OpenShortTest is HyperdriveTest {
basePaid.divDown(hyperdrive.getPoolInfo().vaultSharePrice)
);
assertEq(eventAsBase, true);
assertEq(eventBaseProceeds, shortAmount - basePaid);
assertEq(eventBondAmount, shortAmount);
}

Expand Down