Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/fuzz yn lsd #32

Merged
merged 2 commits into from
Mar 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions src/RewardsDistributor.sol
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {IynETH} from "./interfaces/IynETH.sol";
interface RewardsDistributorEvents {
event FeesCollected(uint256 amount);
event FeeReceiverSet(address ewReceiver);
event FeesBasisPointsSet(uint256 feeBasisPoints);
}


Expand All @@ -25,6 +26,7 @@ contract RewardsDistributor is Initializable, AccessControlUpgradeable, RewardsD
error Paused();
error ZeroAddress();
error FeeSendFailed();
error InvalidBasisPoints();

//--------------------------------------------------------------------------------------
//---------------------------------- CONSTANTS ---------------------------------------
Expand Down Expand Up @@ -140,6 +142,17 @@ contract RewardsDistributor is Initializable, AccessControlUpgradeable, RewardsD
emit FeeReceiverSet(newReceiver);
}

/// @notice Sets the fees basis points for the protocol.
/// @param newFeesBasisPoints The new fees basis points.
function setFeesBasisPoints(uint16 newFeesBasisPoints)
external
onlyRole(DEFAULT_ADMIN_ROLE)
{
if (newFeesBasisPoints > _BASIS_POINTS_DENOMINATOR) revert InvalidBasisPoints();
feesBasisPoints = newFeesBasisPoints;
emit FeesBasisPointsSet(newFeesBasisPoints);
}

modifier assertBalanceUnchanged() {
uint256 before = address(this).balance;
_;
Expand Down
2 changes: 0 additions & 2 deletions src/ynETH.sol
Original file line number Diff line number Diff line change
Expand Up @@ -114,8 +114,6 @@ contract ynETH is IynETH, ynBase, IStakingEvents {
emit Deposit(msg.sender, receiver, assets, shares);
}

// TODO: solve for deposit and mint to adjust to new variables

/// @notice Converts from ynETH to ETH using the current exchange rate.
/// The exchange rate is given by the total supply of ynETH and total ETH controlled by the protocol.
function _convertToShares(uint256 ethAmount, Math.Rounding rounding) internal view returns (uint256) {
Expand Down
4 changes: 2 additions & 2 deletions test/foundry/ActorAddresses.sol
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ contract ActorAddresses {
PAUSE_ADMIN: 0x23618e81E3f5cdF7f54C3d65f7FBc0aBf5B21E8f,
LSD_RESTAKING_MANAGER: 0xa0Ee7A142d267C1f36714E4a8F75612F20a79720,
STAKING_NODE_CREATOR: 0xBcd4042DE499D14e55001CcbB24a551F3b954096,
ORACLE_MANAGER: 0x71bE63f3384f5fb98995898A86B02Fb2426c5788 // TODO: put the next addres here
ORACLE_MANAGER: 0x71bE63f3384f5fb98995898A86B02Fb2426c5788
});

actors[5] = Actors({
Expand All @@ -48,7 +48,7 @@ contract ActorAddresses {
PAUSE_ADMIN: 0x23618e81E3f5cdF7f54C3d65f7FBc0aBf5B21E8f,
LSD_RESTAKING_MANAGER: 0xa0Ee7A142d267C1f36714E4a8F75612F20a79720,
STAKING_NODE_CREATOR: 0xBcd4042DE499D14e55001CcbB24a551F3b954096,
ORACLE_MANAGER: 0x71bE63f3384f5fb98995898A86B02Fb2426c5788 // TODO: put the next addres here
ORACLE_MANAGER: 0x71bE63f3384f5fb98995898A86B02Fb2426c5788
});
}

Expand Down
15 changes: 15 additions & 0 deletions test/foundry/integration/RewardsDistributor.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -46,4 +46,19 @@ contract RewardsDistributorTest is IntegrationBaseTest {
rewardsDistributor.processRewards();
vm.stopPrank();
}

function testSetFeeBasisPoints() public {
uint16 newFeeBasisPoints = 500; // 5%
vm.prank(actors.ADMIN);
rewardsDistributor.setFeesBasisPoints(newFeeBasisPoints);
assertEq(rewardsDistributor.feesBasisPoints(), newFeeBasisPoints);
}

function testFailSetFeeBasisPointsExceedsLimit() public {

uint16 newFeeBasisPoints = 15000; // 150%, exceeds 100%
vm.prank(actors.ADMIN);
vm.expectRevert(abi.encodeWithSelector(RewardsDistributor.InvalidBasisPoints.selector, newFeeBasisPoints));
rewardsDistributor.setFeesBasisPoints(newFeeBasisPoints);
}
}
13 changes: 12 additions & 1 deletion test/foundry/integration/StakingNode.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,9 @@ contract StakingNodeEigenPod is StakingNodeTestBase {

function testCreateNodeAndVerifyPodStateIsValid() public {

(IStakingNode stakingNodeInstance, IEigenPod eigenPodInstance) = setupStakingNode(32 ether);
uint depositAmount = 32 ether;

(IStakingNode stakingNodeInstance, IEigenPod eigenPodInstance) = setupStakingNode(depositAmount);

// Collapsed variable declarations into direct usage within assertions and conditions

Expand Down Expand Up @@ -108,6 +110,15 @@ contract StakingNodeEigenPod is StakingNodeTestBase {
uint256 rewardsAmount = balanceAfterClaim - balanceBeforeClaim;

assertEq(rewardsAmount, rewardsSweeped, "Rewards amount does not match expected value");

rewardsDistributor.processRewards();

uint256 fee = uint256(rewardsDistributor.feesBasisPoints());
uint finalRewardsReceived = rewardsAmount - (rewardsAmount * fee / 10000);

// Assert total assets after claiming delayed withdrawals
uint256 totalAssets = yneth.totalAssets();
assertEq(totalAssets, finalRewardsReceived + depositAmount, "Total assets after claiming delayed withdrawals do not match expected value");
}
}

Expand Down
8 changes: 5 additions & 3 deletions test/foundry/integration/ynLSD.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ import {TestLSDStakingNodeV2} from "../mocks/TestLSDStakingNodeV2.sol";
import {TestYnLSDV2} from "../mocks/TestYnLSDV2.sol";
import {ynBase} from "../../../src/ynBase.sol";
import {Math} from "@openzeppelin/contracts/utils/math/Math.sol";
import "forge-std/console.sol";



contract ynLSDAssetTest is IntegrationBaseTest {
Expand Down Expand Up @@ -175,6 +177,7 @@ contract ynLSDAssetTest is IntegrationBaseTest {
emit log_uint(balance);
assertEq(balance, amount, "Amount not received");
asset.approve(address(ynlsd), amount);
ynlsd.deposit(asset, amount, address(this));

{
IERC20[] memory assets = new IERC20[](1);
Expand All @@ -184,8 +187,7 @@ contract ynLSDAssetTest is IntegrationBaseTest {

vm.prank(actors.LSD_RESTAKING_MANAGER);

// TODO: Come back to this
// lsdStakingNode.depositAssetsToEigenlayer(assets, amounts);
lsdStakingNode.depositAssetsToEigenlayer(assets, amounts);
}

uint256 totalAssetsAfterDeposit = ynlsd.totalAssets();
Expand All @@ -194,7 +196,7 @@ contract ynLSDAssetTest is IntegrationBaseTest {

IStrategy strategy = ynlsd.strategies(IERC20(chainAddresses.lsd.STETH_ADDRESS));
uint256 balanceInStrategyForNode = strategy.userUnderlyingView((address(lsdStakingNode)));

uint256 expectedBalance = balanceInStrategyForNode * oraclePrice / 1e18;

// Assert that totalAssets reflects the deposit
Expand Down