@@ -4,13 +4,16 @@ pragma solidity ^0.8.20;
44import { console2 as console } from "forge-std/console2.sol " ;
55import { IERC20 , IHyperdrive } from "hyperdrive/contracts/src/interfaces/IHyperdrive.sol " ;
66import { ILido } from "hyperdrive/contracts/src/interfaces/ILido.sol " ;
7+ import { FixedPointMath } from "hyperdrive/contracts/src/libraries/FixedPointMath.sol " ;
78import { IEverlongStrategy } from "../../../contracts/interfaces/IEverlongStrategy.sol " ;
89import { EVERLONG_STRATEGY_KIND, EVERLONG_VERSION } from "../../../contracts/libraries/Constants.sol " ;
910import { EverlongForkSDAITest } from "../EverlongForkSDAITest.sol " ;
1011
1112/// @dev Tests Everlong functionality when using the existing SDAIHyperdrive
1213/// instance on a fork.
1314contract TestEverlongForkSDAI is EverlongForkSDAITest {
15+ using FixedPointMath for uint256 ;
16+
1417 /// @dev Ensure the deposit functions work as expected.
1518 function test_deposit () external {
1619 // Alice and Bob deposit into the vault.
@@ -72,4 +75,31 @@ contract TestEverlongForkSDAI is EverlongForkSDAITest {
7275 assertGt (maturityTime, 0 );
7376 assertGt (bondAmount, 0 );
7477 }
78+
79+ /// @dev Tests that when a partial closure would result in a remaining
80+ /// position value less than the minimum transaction amount, the entire
81+ /// position is closed.
82+ function test_partial_closures_min_transaction_amount () external {
83+ // Alice deposits into Everlong.
84+ uint256 aliceDepositAmount = 10e18 ;
85+ uint256 aliceShares = depositSDAIStrategy (aliceDepositAmount, alice);
86+ rebalance ();
87+
88+ // Ensure there is now one position.
89+ assertEq (IEverlongStrategy (address (strategy)).positionCount (), 1 );
90+
91+ // Calculate how many shares are neeed to reach the minimum transaction
92+ // amount.
93+ uint256 minTxShareAmount = IEverlongStrategy (address (strategy))
94+ .minimumTransactionAmount ()
95+ .mulDivDown (aliceShares, aliceDepositAmount);
96+
97+ // Redeem shares such that the remaining share value should be less
98+ // than the minimum transaction amount.
99+ redeemSDAIStrategy (aliceShares - minTxShareAmount, alice);
100+ rebalance ();
101+
102+ // There should be no positions left.
103+ assertEq (IEverlongStrategy (address (strategy)).positionCount (), 0 );
104+ }
75105}
0 commit comments