Skip to content

Commit

Permalink
testing fixes (#5)
Browse files Browse the repository at this point in the history
* 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 <jalextowle@gmail.com>

* Update contracts/Everlong.sol

Co-authored-by: Alex Towle <jalextowle@gmail.com>

---------

Co-authored-by: Alex Towle <jalextowle@gmail.com>
  • Loading branch information
mcclurejt and jalextowle authored Sep 9, 2024
1 parent 190c41b commit 1dde190
Show file tree
Hide file tree
Showing 8 changed files with 100 additions and 404 deletions.
32 changes: 22 additions & 10 deletions contracts/Everlong.sol
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,13 @@ contract Everlong is IEverlong {
);
}

/// @dev Rebalance after a deposit if needed.
function _afterDeposit(uint256, uint256) internal virtual override {
if (canRebalance()) {
rebalance();
}
}

/// @dev Frees sufficient assets for a withdrawal by closing positions.
/// @param assets Amount of assets owed to the withdrawer.
function _beforeWithdraw(
Expand Down Expand Up @@ -246,6 +253,14 @@ contract Everlong is IEverlong {
_portfolio.handleOpenPosition(maturityTime, bondAmount);
}

// FIXME: Consider idle liquidity + maybe maxLong?
//
/// @notice Returns whether the portfolio needs rebalancing.
/// @return True if the portfolio needs rebalancing, false otherwise.
function canRebalance() public view returns (bool) {
return true;
}

// ╭─────────────────────────────────────────────────────────╮
// │ Hyperdrive │
// ╰─────────────────────────────────────────────────────────╯
Expand Down Expand Up @@ -310,21 +325,18 @@ contract Everlong is IEverlong {
return _decimals;
}

/// @notice Returns the address of the token used to interact with the Hyperdrive
/// instance.
/// @dev The decimal offset used for virtual shares.
/// @return The decimal offset used for virtual shares.
function _decimalsOffset() internal view virtual override returns (uint8) {
return decimalsOffset;
}

/// @notice Address of the token used to interact with the Hyperdrive instance.
/// @return Address of the token used to interact with the Hyperdrive instance.
function asset() public view override returns (address) {
return address(_asset);
}

// FIXME: Consider idle liquidity + maybe maxLong?
//
/// @notice Returns whether the portfolio needs rebalancing.
/// @return True if the portfolio needs rebalancing, false otherwise.
function canRebalance() external view returns (bool) {
return IHyperdrive(hyperdrive).isMature(_portfolio.head());
}

/// @notice Returns whether the portfolio has matured positions.
/// @return True if the portfolio has matured positions, false otherwise.
function hasMaturedPositions() external view returns (bool) {
Expand Down
2 changes: 1 addition & 1 deletion contracts/libraries/HyperdriveExecution.sol
Original file line number Diff line number Diff line change
Expand Up @@ -128,8 +128,8 @@ library HyperdriveExecutionLibrary {
poolConfig.timeStretch
);
bondReservesDelta = _calculateOpenLongFees(
bondReservesDelta,
_shareAmount,
bondReservesDelta,
_vaultSharePrice,
spotPrice,
poolConfig.fees.curve
Expand Down
1 change: 0 additions & 1 deletion test/integration/CloseImmatureLongs.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,6 @@ contract PricingTest is EverlongTest {
ERC20Mintable(everlong.asset()).mint(basePaid);
ERC20Mintable(everlong.asset()).approve(address(everlong), basePaid);
uint256 shares = everlong.deposit(basePaid, bob);
everlong.rebalance();

// half term passes
advanceTimeWithCheckpoints(POSITION_DURATION / 2, variableInterest);
Expand Down
5 changes: 5 additions & 0 deletions test/units/Everlong.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@ import { EverlongTest } from "../harnesses/EverlongTest.sol";

/// @dev Tests Everlong functionality.
contract TestEverlong is EverlongTest {
function setUp() public override {
super.setUp();
deployEverlong();
}

/// @dev Ensure that the `hyperdrive()` view function is implemented.
function test_hyperdrive() external view {
assertEq(
Expand Down
5 changes: 5 additions & 0 deletions test/units/EverlongAdmin.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@ import { IEverlong } from "../../contracts/interfaces/IEverlong.sol";

/// @dev Tests Everlong Admin functionality.
contract TestEverlongAdmin is EverlongTest {
function setUp() public override {
super.setUp();
deployEverlong();
}

/// @dev Validates revert when `setAdmin` called by non-admin.
function test_setAdmin_failure_unauthorized() external {
// Ensure that an unauthorized user cannot set the admin address.
Expand Down
Loading

0 comments on commit 1dde190

Please sign in to comment.