Skip to content

Commit

Permalink
add test with asBase=false
Browse files Browse the repository at this point in the history
  • Loading branch information
mcclurejt committed Dec 31, 2024
1 parent ddb1783 commit e6060fd
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 4 deletions.
36 changes: 36 additions & 0 deletions test/everlong/EverlongForkSDAITest.sol
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,29 @@ contract EverlongForkSDAITest is EverlongTest {
vm.stopPrank();
}

/// @dev Deposit into the SDAI everlong strategy.
/// @param _assets Amount of assets to deposit.
/// @param _from Source of the tokens.
/// @return shares Amount of shares received from the deposit.
function depositSDAIStrategy(
uint256 _assets,
address _from
) internal returns (uint256 shares) {
// Mint _from some SDAI.
mintSDAI(_assets, _from);

// Enable deposits from _from.
vm.startPrank(management);
strategy.setDepositor(_from, true);
vm.stopPrank();

// Make the approval and deposit.
vm.startPrank(_from);
asset.approve(address(strategy), _assets);
shares = strategy.deposit(_assets, _from);
vm.stopPrank();
}

/// @dev Redeem shares from the SDAI everlong vault.
/// @param _shares Amount of shares to redeem.
/// @param _from Source of the shares.
Expand All @@ -69,4 +92,17 @@ contract EverlongForkSDAITest is EverlongTest {
assets = vault.redeem(_shares, _from, _from);
vm.stopPrank();
}

/// @dev Redeem shares from the SDAI everlong strategy.
/// @param _shares Amount of shares to redeem.
/// @param _from Source of the shares.
/// @return assets Amount of assets received from the redemption.
function redeemSDAIStrategy(
uint256 _shares,
address _from
) internal returns (uint256 assets) {
vm.startPrank(_from);
assets = strategy.redeem(_shares, _from, _from);
vm.stopPrank();
}
}
5 changes: 1 addition & 4 deletions test/everlong/integration/PartialClosures.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -119,9 +119,7 @@ contract TestPartialClosures is EverlongTest {
/// @dev Tests that when a partial closure would result in a remaining
/// position value less than the minimum transaction amount, the entire
/// position is closed.
function test_partial_closures_position_remainder_gt_minTransactionAmount()
external
{
function test_partial_closures_position_min_transaction_amount() external {
// Alice deposits into Everlong.
uint256 aliceDepositAmount = 1000e18;
uint256 aliceShares = depositStrategy(aliceDepositAmount, alice, true);
Expand All @@ -138,7 +136,6 @@ contract TestPartialClosures is EverlongTest {
// Redeem shares such that the remaining share value should be less
// than the minimum transaction amount.
redeemStrategy(aliceShares - minTxShareAmount, alice, true);
redeemStrategy(minTxShareAmount, alice, true);

// There should be no positions left.
assertEq(IEverlongStrategy(address(strategy)).positionCount(), 0);
Expand Down
30 changes: 30 additions & 0 deletions test/everlong/units/EverlongForkSDAITest.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,16 @@ pragma solidity ^0.8.20;
import { console2 as console } from "forge-std/console2.sol";
import { IERC20, IHyperdrive } from "hyperdrive/contracts/src/interfaces/IHyperdrive.sol";
import { ILido } from "hyperdrive/contracts/src/interfaces/ILido.sol";
import { FixedPointMath } from "hyperdrive/contracts/src/libraries/FixedPointMath.sol";
import { IEverlongStrategy } from "../../../contracts/interfaces/IEverlongStrategy.sol";
import { EVERLONG_STRATEGY_KIND, EVERLONG_VERSION } from "../../../contracts/libraries/Constants.sol";
import { EverlongForkSDAITest } from "../EverlongForkSDAITest.sol";

/// @dev Tests Everlong functionality when using the existing SDAIHyperdrive
/// instance on a fork.
contract TestEverlongForkSDAI is EverlongForkSDAITest {
using FixedPointMath for uint256;

/// @dev Ensure the deposit functions work as expected.
function test_deposit() external {
// Alice and Bob deposit into the vault.
Expand Down Expand Up @@ -72,4 +75,31 @@ contract TestEverlongForkSDAI is EverlongForkSDAITest {
assertGt(maturityTime, 0);
assertGt(bondAmount, 0);
}

/// @dev Tests that when a partial closure would result in a remaining
/// position value less than the minimum transaction amount, the entire
/// position is closed.
function test_partial_closures_min_transaction_amount() external {
// Alice deposits into Everlong.
uint256 aliceDepositAmount = 10e18;
uint256 aliceShares = depositSDAIStrategy(aliceDepositAmount, alice);
rebalance();

// Ensure there is now one position.
assertEq(IEverlongStrategy(address(strategy)).positionCount(), 1);

// Calculate how many shares are neeed to reach the minimum transaction
// amount.
uint256 minTxShareAmount = IEverlongStrategy(address(strategy))
.minimumTransactionAmount()
.mulDivDown(aliceShares, aliceDepositAmount);

// Redeem shares such that the remaining share value should be less
// than the minimum transaction amount.
redeemSDAIStrategy(aliceShares - minTxShareAmount, alice);
rebalance();

// There should be no positions left.
assertEq(IEverlongStrategy(address(strategy)).positionCount(), 0);
}
}

0 comments on commit e6060fd

Please sign in to comment.