Skip to content

Commit

Permalink
vault share pricing and unmatured position valuation (#4)
Browse files Browse the repository at this point in the history
* refactor position accounting into library

* positive interest works

* cleanup, rename playground to pricing test, add remappings.txt to massively speed up LSP

* add tests for hyperdrive w/ fees

* moving things around and adding tests for portfolio value estimation

* massively simplify calculateCloseLong and remove unused internal contracts

* hyperdrive execution math is exact

* wei-exact accounting

* comment all the things

* Update Everlong.sol

Co-authored-by: Alex Towle <[email protected]>

* Update IEverlong.sol

Co-authored-by: Alex Towle <[email protected]>

* Update contracts/interfaces/IEverlong.sol

Co-authored-by: Alex Towle <[email protected]>

* addressing feedback from @jalextowle

* addressing feedback from @jalextowle

* testing fixes (#5)

* tmp

* portfolio and 4626 fixes/tests

* fix rebase issues

* update existing tests, remove position tests (will re-add similar scope with idle liquidity feature)

* Update test/units/EverlongPortfolio.t.sol

Co-authored-by: Alex Towle <[email protected]>

* Update contracts/Everlong.sol

Co-authored-by: Alex Towle <[email protected]>

---------

Co-authored-by: Alex Towle <[email protected]>

---------

Co-authored-by: Alex Towle <[email protected]>
  • Loading branch information
mcclurejt and jalextowle authored Sep 9, 2024
1 parent 599067b commit 60ec1f1
Show file tree
Hide file tree
Showing 30 changed files with 1,844 additions and 1,449 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -137,3 +137,7 @@ lcov.info

# vscode workspace settings
.vscode

# notes
NOTES.md
TODO.md
339 changes: 297 additions & 42 deletions contracts/Everlong.sol

Large diffs are not rendered by default.

42 changes: 20 additions & 22 deletions contracts/interfaces/IEverlong.sol
Original file line number Diff line number Diff line change
@@ -1,31 +1,43 @@
// SPDX-License-Identifier: Apache-2.0
pragma solidity ^0.8.20;

import { IERC4626 } from "openzeppelin/interfaces/IERC4626.sol";
import { ERC4626 } from "solady/tokens/ERC4626.sol";
import { IEverlongAdmin } from "./IEverlongAdmin.sol";
import { IEverlongEvents } from "./IEverlongEvents.sol";
import { IEverlongPositions } from "./IEverlongPositions.sol";
import { IEverlongPortfolio } from "./IEverlongPortfolio.sol";

interface IEverlong is
abstract contract IEverlong is
ERC4626,
IEverlongAdmin,
IERC4626,
IEverlongEvents,
IEverlongPositions
IEverlongPortfolio
{
// ╭─────────────────────────────────────────────────────────╮
// │ Structs │
// ╰─────────────────────────────────────────────────────────╯

/// @notice Contains the information needed to identify an open Hyperdrive position.
struct Position {
/// @notice Time when the position matures.
uint128 maturityTime;
/// @notice Amount of bonds in the position.
uint128 bondAmount;
}

// ╭─────────────────────────────────────────────────────────╮
// │ Getters │
// ╰─────────────────────────────────────────────────────────╯

/// @notice Gets the address of the underlying Hyperdrive Instance
function hyperdrive() external view returns (address);
function hyperdrive() external view virtual returns (address);

/// @notice Gets the Everlong instance's kind.
/// @return The Everlong instance's kind.
function kind() external pure returns (string memory);
function kind() external pure virtual returns (string memory);

/// @notice Gets the Everlong instance's version.
/// @return The Everlong instance's version.
function version() external pure returns (string memory);
function version() external pure virtual returns (string memory);

// ╭─────────────────────────────────────────────────────────╮
// │ Errors │
Expand All @@ -35,18 +47,4 @@ interface IEverlong is

/// @notice Thrown when caller is not the admin.
error Unauthorized();

// ── Positions ──────────────────────────────────────────────

/// @notice Thrown when attempting to insert a position with
/// a `maturityTime` sooner than the most recent position's.
error InconsistentPositionMaturity();

/// @notice Thrown when attempting to close a position with
/// a `bondAmount` greater than that contained by the position.
error InconsistentPositionBondAmount();

/// @notice Thrown when a target idle amount is too high to be reached
/// even after closing all positions.
error TargetIdleTooHigh();
}
17 changes: 2 additions & 15 deletions contracts/interfaces/IEverlongEvents.sol
Original file line number Diff line number Diff line change
Expand Up @@ -10,25 +10,12 @@ interface IEverlongEvents {
// ── Positions ──────────────────────────────────────────────

/// @notice Emitted when a new position is added to the bond portfolio.
/// @dev This event will only be emitted with new `maturityTime`s in the portfolio.
/// TODO: Reconsider naming https://github.com/delvtech/hyperdrive/pull/1096#discussion_r1681337414
event PositionOpened(
uint128 indexed maturityTime,
uint128 bondAmount,
uint256 index
);

/// @notice Emitted when an existing position's `bondAmount` is modified.
/// TODO: Reconsider naming https://github.com/delvtech/hyperdrive/pull/1096#discussion_r1681337414
event PositionUpdated(
uint128 indexed maturityTime,
uint128 newBondAmount,
uint256 index
);
event PositionOpened(uint128 indexed maturityTime, uint128 bondAmount);

/// @notice Emitted when an existing position is closed.
/// TODO: Reconsider naming https://github.com/delvtech/hyperdrive/pull/1096#discussion_r1681337414
event PositionClosed(uint128 indexed maturityTime);
event PositionClosed(uint128 indexed maturityTime, uint128 bondAmount);

/// @notice Emitted when Everlong's underlying portfolio is rebalanced.
event Rebalanced();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
// SPDX-License-Identifier: Apache-2.0
pragma solidity ^0.8.20;

import { Position } from "../types/Position.sol";
import { IEverlong } from "./IEverlong.sol";

interface IEverlongPositions {
interface IEverlongPortfolio {
// ╭─────────────────────────────────────────────────────────╮
// │ Stateful │
// ╰─────────────────────────────────────────────────────────╯
Expand All @@ -17,25 +17,20 @@ interface IEverlongPositions {

/// @notice Gets the number of positions managed by the Everlong instance.
/// @return The number of positions.
function getPositionCount() external view returns (uint256);
function positionCount() external view returns (uint256);

/// @notice Gets the position at an index.
/// Position `maturityTime` increases with each index.
/// @param _index The index of the position.
/// @return The position.
function getPosition(
function positionAt(
uint256 _index
) external view returns (Position memory);
) external view returns (IEverlong.Position memory);

/// @notice Determines whether any positions are matured.
/// @return True if any positions are matured, false otherwise.
function hasMaturedPositions() external view returns (bool);

/// @notice Determines whether Everlong has sufficient excess liquidity
/// for opening a long.
/// @return True if sufficient excess liquidity, false otherwise.
function hasSufficientExcessLiquidity() external view returns (bool);

/// @notice Determines whether Everlong's portfolio can currently be rebalanced.
/// @return True if the portfolio can be rebalanced, false otherwise.
function canRebalance() external view returns (bool);
Expand Down
45 changes: 0 additions & 45 deletions contracts/internal/EverlongAdmin.sol

This file was deleted.

33 changes: 0 additions & 33 deletions contracts/internal/EverlongBase.sol

This file was deleted.

158 changes: 0 additions & 158 deletions contracts/internal/EverlongERC4626.sol

This file was deleted.

Loading

0 comments on commit 60ec1f1

Please sign in to comment.