Skip to content

Commit

Permalink
add pause to ynLSD.deposit
Browse files Browse the repository at this point in the history
  • Loading branch information
danoctavian committed Mar 27, 2024
1 parent f28a6f9 commit f66e341
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 0 deletions.
17 changes: 17 additions & 0 deletions src/ynLSD.sol
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ interface IynLSDEvents {
event AssetRetrieved(IERC20 asset, uint256 amount, uint256 nodeId, address sender);
event LSDStakingNodeCreated(uint256 nodeId, address nodeAddress);
event MaxNodeCountUpdated(uint256 maxNodeCount);
event DepositsPausedUpdated(bool paused);

event RegisteredStakingNodeImplementationContract(address upgradeableBeaconAddress, address implementationContract);
event UpgradedStakingNodeImplementationContract(address implementationContract, uint256 nodesCount);
Expand All @@ -35,6 +36,7 @@ contract ynLSD is IynLSD, ynBase, ReentrancyGuardUpgradeable, IynLSDEvents {
//--------------------------------------------------------------------------------------

error UnsupportedAsset(IERC20 asset);
error Paused();
error ZeroAmount();
error ZeroAddress();
error BeaconImplementationAlreadyExists();
Expand Down Expand Up @@ -76,6 +78,8 @@ contract ynLSD is IynLSD, ynBase, ReentrancyGuardUpgradeable, IynLSDEvents {
ILSDStakingNode[] public nodes;
uint256 public maxNodeCount;

bool public depositsPaused;

//--------------------------------------------------------------------------------------
//---------------------------------- INITIALIZATION ----------------------------------
//--------------------------------------------------------------------------------------
Expand Down Expand Up @@ -157,6 +161,11 @@ contract ynLSD is IynLSD, ynBase, ReentrancyGuardUpgradeable, IynLSDEvents {
uint256 amount,
address receiver
) public nonReentrant returns (uint256 shares) {

if (depositsPaused) {
revert Paused();
}

return _deposit(asset, amount, receiver, msg.sender);
}

Expand Down Expand Up @@ -315,6 +324,14 @@ contract ynLSD is IynLSD, ynBase, ReentrancyGuardUpgradeable, IynLSDEvents {
: assetPriceInETH * amount / 1e18;
}

/// @notice Updates the pause state of deposits.
/// @dev Can only be called by an account with the PAUSER_ROLE.
/// @param isPaused The new pause state to set for deposits.
function updateDepositsPaused(bool isPaused) external onlyRole(PAUSER_ROLE) {
depositsPaused = isPaused;
emit DepositsPausedUpdated(depositsPaused);
}

//--------------------------------------------------------------------------------------
//---------------------------------- STAKING NODE CREATION ---------------------------
//--------------------------------------------------------------------------------------
Expand Down
39 changes: 39 additions & 0 deletions test/foundry/integration/ynLSD.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -398,6 +398,45 @@ contract ynLSDAdminTest is IntegrationBaseTest {
ynlsd.setMaxNodeCount(maxNodeCount);
assertEq(ynlsd.maxNodeCount(), maxNodeCount, "Max node count does not match expected value");
}

function testPauseDepositsFunctionality() public {
IERC20 stETH = IERC20(chainAddresses.lsd.STETH_ADDRESS);

uint256 depositAmount = 1 ether;

// Obtain STETH
(bool success, ) = chainAddresses.lsd.STETH_ADDRESS.call{value: depositAmount * 10}("");
require(success, "ETH transfer failed");
uint256 balance = stETH.balanceOf(address(this));
assertEq(compareWithThreshold(balance, depositAmount * 10, 1), true, "Amount not received");

stETH.approve(address(ynlsd), 32 ether);

// Arrange
vm.prank(actors.PAUSE_ADMIN);
ynlsd.updateDepositsPaused(true);

// Act & Assert
bool pauseState = ynlsd.depositsPaused();
assertTrue(pauseState, "Deposit ETH should be paused after setting pause state to true");

// Trying to deposit ETH while pause
vm.expectRevert(ynLSD.Paused.selector);
ynlsd.deposit(stETH, depositAmount, address(this));

// Unpause and try depositing again
vm.prank(actors.PAUSE_ADMIN);
ynlsd.updateDepositsPaused(false);
pauseState = ynlsd.depositsPaused();

assertFalse(pauseState, "Deposit ETH should be unpaused after setting pause state to false");

// Deposit should succeed now
ynlsd.deposit(stETH, depositAmount, address(this));
uint256 ynLSDBalance = ynlsd.balanceOf(address(this));
assertGt(ynLSDBalance, 0, "ynLSD balance should be greater than 0 after deposit");
}

}

contract ynLSDTransferPauseTest is IntegrationBaseTest {
Expand Down

0 comments on commit f66e341

Please sign in to comment.