Skip to content

Commit e6060fd

Browse files
committed
add test with asBase=false
1 parent ddb1783 commit e6060fd

3 files changed

Lines changed: 67 additions & 4 deletions

File tree

test/everlong/EverlongForkSDAITest.sol

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,29 @@ contract EverlongForkSDAITest is EverlongTest {
5757
vm.stopPrank();
5858
}
5959

60+
/// @dev Deposit into the SDAI everlong strategy.
61+
/// @param _assets Amount of assets to deposit.
62+
/// @param _from Source of the tokens.
63+
/// @return shares Amount of shares received from the deposit.
64+
function depositSDAIStrategy(
65+
uint256 _assets,
66+
address _from
67+
) internal returns (uint256 shares) {
68+
// Mint _from some SDAI.
69+
mintSDAI(_assets, _from);
70+
71+
// Enable deposits from _from.
72+
vm.startPrank(management);
73+
strategy.setDepositor(_from, true);
74+
vm.stopPrank();
75+
76+
// Make the approval and deposit.
77+
vm.startPrank(_from);
78+
asset.approve(address(strategy), _assets);
79+
shares = strategy.deposit(_assets, _from);
80+
vm.stopPrank();
81+
}
82+
6083
/// @dev Redeem shares from the SDAI everlong vault.
6184
/// @param _shares Amount of shares to redeem.
6285
/// @param _from Source of the shares.
@@ -69,4 +92,17 @@ contract EverlongForkSDAITest is EverlongTest {
6992
assets = vault.redeem(_shares, _from, _from);
7093
vm.stopPrank();
7194
}
95+
96+
/// @dev Redeem shares from the SDAI everlong strategy.
97+
/// @param _shares Amount of shares to redeem.
98+
/// @param _from Source of the shares.
99+
/// @return assets Amount of assets received from the redemption.
100+
function redeemSDAIStrategy(
101+
uint256 _shares,
102+
address _from
103+
) internal returns (uint256 assets) {
104+
vm.startPrank(_from);
105+
assets = strategy.redeem(_shares, _from, _from);
106+
vm.stopPrank();
107+
}
72108
}

test/everlong/integration/PartialClosures.t.sol

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -119,9 +119,7 @@ contract TestPartialClosures is EverlongTest {
119119
/// @dev Tests that when a partial closure would result in a remaining
120120
/// position value less than the minimum transaction amount, the entire
121121
/// position is closed.
122-
function test_partial_closures_position_remainder_gt_minTransactionAmount()
123-
external
124-
{
122+
function test_partial_closures_position_min_transaction_amount() external {
125123
// Alice deposits into Everlong.
126124
uint256 aliceDepositAmount = 1000e18;
127125
uint256 aliceShares = depositStrategy(aliceDepositAmount, alice, true);
@@ -138,7 +136,6 @@ contract TestPartialClosures is EverlongTest {
138136
// Redeem shares such that the remaining share value should be less
139137
// than the minimum transaction amount.
140138
redeemStrategy(aliceShares - minTxShareAmount, alice, true);
141-
redeemStrategy(minTxShareAmount, alice, true);
142139

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

test/everlong/units/EverlongForkSDAITest.t.sol

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,16 @@ pragma solidity ^0.8.20;
44
import { console2 as console } from "forge-std/console2.sol";
55
import { IERC20, IHyperdrive } from "hyperdrive/contracts/src/interfaces/IHyperdrive.sol";
66
import { ILido } from "hyperdrive/contracts/src/interfaces/ILido.sol";
7+
import { FixedPointMath } from "hyperdrive/contracts/src/libraries/FixedPointMath.sol";
78
import { IEverlongStrategy } from "../../../contracts/interfaces/IEverlongStrategy.sol";
89
import { EVERLONG_STRATEGY_KIND, EVERLONG_VERSION } from "../../../contracts/libraries/Constants.sol";
910
import { EverlongForkSDAITest } from "../EverlongForkSDAITest.sol";
1011

1112
/// @dev Tests Everlong functionality when using the existing SDAIHyperdrive
1213
/// instance on a fork.
1314
contract 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

Comments
 (0)