Skip to content

Commit

Permalink
Merge pull request #59 from yieldnest/feature/enhance-events
Browse files Browse the repository at this point in the history
Feature/enhance events
  • Loading branch information
danoctavian authored Mar 26, 2024
2 parents fd3c618 + 91efb15 commit 8e4ece3
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 6 deletions.
5 changes: 3 additions & 2 deletions src/RewardsDistributor.sol
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {IynETH} from "./interfaces/IynETH.sol";


interface RewardsDistributorEvents {
event FeesCollected(uint256 amount);
event RewardsProcessed(uint256 totalRewards, uint256 elRewards, uint256 clRewards, uint256 netRewards, uint256 fees);
event FeeReceiverSet(address ewReceiver);
event FeesBasisPointsSet(uint256 feeBasisPoints);
}
Expand Down Expand Up @@ -123,12 +123,13 @@ contract RewardsDistributor is Initializable, AccessControlUpgradeable, RewardsD

// Send protocol fees (if they exist) to the fee receiver wallet.
if (fees > 0) {
emit FeesCollected(fees);
(bool success, ) = feesReceiver.call{value: fees}("");
if (!success) {
revert FeeSendFailed();
}
}

emit RewardsProcessed(totalRewards, elRewards, clRewards, netRewards, fees);
}

//--------------------------------------------------------------------------------------
Expand Down
22 changes: 18 additions & 4 deletions src/ynETH.sol
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,26 @@ pragma solidity ^0.8.24;
import {Math} from "@openzeppelin/contracts/utils/math/Math.sol";
import {IStakingNodesManager} from "./interfaces/IStakingNodesManager.sol";
import {IRewardsDistributor} from "./interfaces/IRewardsDistributor.sol";
import {IStakingNode,IStakingEvents} from "./interfaces/IStakingNode.sol";
import {IStakingNode} from "./interfaces/IStakingNode.sol";
import {IynETH} from "./interfaces/IynETH.sol";
import {ynBase} from "./ynBase.sol";


interface IYnETHEvents {
event DepositETHPausedUpdated(bool isPaused);
event Deposit(address indexed sender, address indexed receiver, uint256 assets, uint256 shares, uint256 totalDepositedInPool);
event RewardsReceived(uint256 value, uint256 totalDepositedInPool);
event ETHWithdrawn(uint256 ethAmount, uint256 totalDepositedInPool);
event WithdrawnETHProcessed(uint256 ethAmount, uint256 totalDepositedInPool);
}

/**
* @title ynETH
* @dev The ynETH contract is a core component of the YieldNEst restaking protocol, facilitating the native restaking of ETH
/// management of staking nodes, and distribution of rewards. It serves as the entry point for users to deposit ETH
/// in exchange for ynETH tokens, representing their share of the staked ETH.
*/
contract ynETH is IynETH, ynBase, IStakingEvents {
contract ynETH is IynETH, ynBase, IYnETHEvents {

//--------------------------------------------------------------------------------------
//---------------------------------- ERRORS -------------------------------------------
Expand Down Expand Up @@ -108,7 +117,7 @@ contract ynETH is IynETH, ynBase, IStakingEvents {
_mint(receiver, shares);

totalDepositedInPool += msg.value;
emit Deposit(msg.sender, receiver, assets, shares);
emit Deposit(msg.sender, receiver, assets, shares, totalDepositedInPool);
}

/// @notice Converts from ynETH to ETH using the current exchange rate.
Expand All @@ -120,7 +129,6 @@ contract ynETH is IynETH, ynBase, IStakingEvents {
return ethAmount;
}


// deltaynETH = (ynETHSupply / totalControlled) * ethAmount
return Math.mulDiv(
ethAmount,
Expand Down Expand Up @@ -174,6 +182,8 @@ contract ynETH is IynETH, ynBase, IStakingEvents {
revert NotRewardsDistributor();
}
totalDepositedInPool += msg.value;

emit RewardsReceived(msg.value, totalDepositedInPool);
}

/// @notice Withdraws a specified amount of ETH from the pool to the Staking Nodes Manager.
Expand All @@ -189,13 +199,17 @@ contract ynETH is IynETH, ynBase, IStakingEvents {
totalDepositedInPool -= ethAmount;
// Transfer the specified amount of ETH to the Staking Nodes Manager.
payable(address(stakingNodesManager)).transfer(ethAmount);

emit ETHWithdrawn(ethAmount, totalDepositedInPool);
}

/// @notice Processes ETH that has been withdrawn from the staking nodes and adds it to the pool.
/// @dev This function can only be called by the Staking Nodes Manager.
/// It increases the total deposited in the pool by the amount of ETH sent with the call.
function processWithdrawnETH() public payable onlyStakingNodesManager {
totalDepositedInPool += msg.value;

emit WithdrawnETHProcessed(msg.value, totalDepositedInPool);
}

/// @notice Updates the pause state of ETH deposits.
Expand Down

0 comments on commit 8e4ece3

Please sign in to comment.