Skip to content

Commit

Permalink
Merge pull request #7 from Renzo-Protocol/v1.8-v1.9
Browse files Browse the repository at this point in the history
V1.8 v1.9
  • Loading branch information
pooleja authored Jul 9, 2024
2 parents 57f6b3e + 2aad4e6 commit 9be7ca8
Show file tree
Hide file tree
Showing 9 changed files with 847 additions and 195 deletions.
204 changes: 150 additions & 54 deletions contracts/Delegation/OperatorDelegator.sol

Large diffs are not rendered by default.

74 changes: 54 additions & 20 deletions contracts/Deposits/DepositQueue.sol
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,15 @@ import "./DepositQueueStorage.sol";
import "@openzeppelin/contracts-upgradeable/security/ReentrancyGuardUpgradeable.sol";
import "../Errors/Errors.sol";

contract DepositQueue is Initializable, ReentrancyGuardUpgradeable, DepositQueueStorageV2 {
contract DepositQueue is
Initializable,
ReentrancyGuardUpgradeable,
DepositQueueStorageV2
{
using SafeERC20 for IERC20;

address public constant IS_NATIVE = 0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE;
address public constant IS_NATIVE =
0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE;

event RewardsDeposited(IERC20 token, uint256 amount);

Expand All @@ -32,7 +37,10 @@ contract DepositQueue is Initializable, ReentrancyGuardUpgradeable, DepositQueue
event GasRefunded(address admin, uint256 gasRefunded);

/// @dev Event emitted when withdrawQueue is updated
event WithdrawQueueUpdated(address oldWithdrawQueue, address newWithdrawQueue);
event WithdrawQueueUpdated(
address oldWithdrawQueue,
address newWithdrawQueue
);

/// @dev Event emitted when withdrawQueue buffer is filled for specified token
event BufferFilled(address token, uint256 amount);
Expand All @@ -42,7 +50,8 @@ contract DepositQueue is Initializable, ReentrancyGuardUpgradeable, DepositQueue

/// @dev Allows only a whitelisted address to configure the contract
modifier onlyRestakeManagerAdmin() {
if (!roleManager.isRestakeManagerAdmin(msg.sender)) revert NotRestakeManagerAdmin();
if (!roleManager.isRestakeManagerAdmin(msg.sender))
revert NotRestakeManagerAdmin();
_;
}

Expand All @@ -54,13 +63,15 @@ contract DepositQueue is Initializable, ReentrancyGuardUpgradeable, DepositQueue

/// @dev Allows only a whitelisted address to trigger native ETH staking
modifier onlyNativeEthRestakeAdmin() {
if (!roleManager.isNativeEthRestakeAdmin(msg.sender)) revert NotNativeEthRestakeAdmin();
if (!roleManager.isNativeEthRestakeAdmin(msg.sender))
revert NotNativeEthRestakeAdmin();
_;
}

/// @dev Allows only a whitelisted address to trigger ERC20 rewards sweeping
modifier onlyERC20RewardsAdmin() {
if (!roleManager.isERC20RewardsAdmin(msg.sender)) revert NotERC20RewardsAdmin();
if (!roleManager.isERC20RewardsAdmin(msg.sender))
revert NotERC20RewardsAdmin();
_;
}

Expand All @@ -84,9 +95,14 @@ contract DepositQueue is Initializable, ReentrancyGuardUpgradeable, DepositQueue
* @dev permissioned call (onlyRestakeManagerAdmin)
* @param _withdrawQueue new withdraw Queue contract address
*/
function setWithdrawQueue(IWithdrawQueue _withdrawQueue) external onlyRestakeManagerAdmin {
function setWithdrawQueue(
IWithdrawQueue _withdrawQueue
) external onlyRestakeManagerAdmin {
if (address(_withdrawQueue) == address(0)) revert InvalidZeroInput();
emit WithdrawQueueUpdated(address(withdrawQueue), address(_withdrawQueue));
emit WithdrawQueueUpdated(
address(withdrawQueue),
address(_withdrawQueue)
);
withdrawQueue = _withdrawQueue;
}
/// @dev Sets the config for fees - if either value is set to 0 then fees are disabled
Expand All @@ -109,7 +125,9 @@ contract DepositQueue is Initializable, ReentrancyGuardUpgradeable, DepositQueue
}

/// @dev Sets the address of the RestakeManager contract
function setRestakeManager(IRestakeManager _restakeManager) external onlyRestakeManagerAdmin {
function setRestakeManager(
IRestakeManager _restakeManager
) external onlyRestakeManagerAdmin {
if (address(_restakeManager) == address(0x0)) revert InvalidZeroInput();

restakeManager = _restakeManager;
Expand All @@ -131,7 +149,10 @@ contract DepositQueue is Initializable, ReentrancyGuardUpgradeable, DepositQueue
* @param _asset address of asset to fill up the buffer for
* @param _amount amount of token to fill up the buffer with
*/
function fillERC20withdrawBuffer(address _asset, uint256 _amount) external nonReentrant {
function fillERC20withdrawBuffer(
address _asset,
uint256 _amount
) external nonReentrant {
if (_amount == 0 || _asset == address(0)) revert InvalidZeroInput();
// safeTransfer from restake manager to this address
IERC20(_asset).safeTransferFrom(msg.sender, address(this), _amount);
Expand Down Expand Up @@ -162,7 +183,7 @@ contract DepositQueue is Initializable, ReentrancyGuardUpgradeable, DepositQueue
// Take protocol cut of rewards if enabled
if (feeAddress != address(0x0) && feeBasisPoints > 0) {
feeAmount = (msg.value * feeBasisPoints) / 10000;
(bool success, ) = feeAddress.call{ value: feeAmount }("");
(bool success, ) = feeAddress.call{value: feeAmount}("");
if (!success) revert TransferFailed();

emit ProtocolFeesPaid(IERC20(address(0x0)), feeAmount, feeAddress);
Expand All @@ -186,14 +207,19 @@ contract DepositQueue is Initializable, ReentrancyGuardUpgradeable, DepositQueue
) external onlyNativeEthRestakeAdmin {
uint256 gasBefore = gasleft();
// Send the ETH and the params through to the restake manager
restakeManager.stakeEthInOperatorDelegator{ value: 32 ether }(
restakeManager.stakeEthInOperatorDelegator{value: 32 ether}(
operatorDelegator,
pubkey,
signature,
depositDataRoot
);

emit ETHStakedFromQueue(operatorDelegator, pubkey, 32 ether, address(this).balance);
emit ETHStakedFromQueue(
operatorDelegator,
pubkey,
32 ether,
address(this).balance
);

// Refund the gas to the Admin address if enough ETH available
_refundGas(gasBefore);
Expand All @@ -220,7 +246,7 @@ contract DepositQueue is Initializable, ReentrancyGuardUpgradeable, DepositQueue
uint256 arrayLength = operatorDelegators.length;
for (uint256 i = 0; i < arrayLength; ) {
// Send the ETH and the params through to the restake manager
restakeManager.stakeEthInOperatorDelegator{ value: 32 ether }(
restakeManager.stakeEthInOperatorDelegator{value: 32 ether}(
operatorDelegators[i],
pubkeys[i],
signatures[i],
Expand Down Expand Up @@ -259,8 +285,14 @@ contract DepositQueue is Initializable, ReentrancyGuardUpgradeable, DepositQueue
}

// Approve and deposit the rewards
token.safeIncreaseAllowance(address(restakeManager), balance - feeAmount);
restakeManager.depositTokenRewardsFromProtocol(token, balance - feeAmount);
token.safeIncreaseAllowance(
address(restakeManager),
balance - feeAmount
);
restakeManager.depositTokenRewardsFromProtocol(
token,
balance - feeAmount
);

// Emit the rewards event
emit RewardsDeposited(IERC20(address(token)), balance - feeAmount);
Expand All @@ -273,8 +305,10 @@ contract DepositQueue is Initializable, ReentrancyGuardUpgradeable, DepositQueue
*/
function _refundGas(uint256 initialGas) internal {
uint256 gasUsed = (initialGas - gasleft()) * block.basefee;
uint256 gasRefund = address(this).balance >= gasUsed ? gasUsed : address(this).balance;
(bool success, ) = payable(msg.sender).call{ value: gasRefund }("");
uint256 gasRefund = address(this).balance >= gasUsed
? gasUsed
: address(this).balance;
(bool success, ) = payable(msg.sender).call{value: gasRefund}("");
if (!success) revert TransferFailed();
emit GasRefunded(msg.sender, gasRefund);
}
Expand All @@ -284,13 +318,13 @@ contract DepositQueue is Initializable, ReentrancyGuardUpgradeable, DepositQueue
*/
function _checkAndFillETHWithdrawBuffer(uint256 _amount) internal {
// Check the withdraw buffer and fill if below buffer target
uint256 bufferToFill = withdrawQueue.getBufferDeficit(IS_NATIVE);
uint256 bufferToFill = withdrawQueue.getWithdrawDeficit(IS_NATIVE);

if (bufferToFill > 0) {
bufferToFill = (_amount <= bufferToFill) ? _amount : bufferToFill;

// fill withdraw buffer from received ETH
withdrawQueue.fillEthWithdrawBuffer{ value: bufferToFill }();
withdrawQueue.fillEthWithdrawBuffer{value: bufferToFill}();

emit BufferFilled(IS_NATIVE, bufferToFill);
}
Expand Down
8 changes: 7 additions & 1 deletion contracts/Errors/Errors.sol
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,10 @@ error InvalidZeroOutput();
error NotEnoughBalance(uint256 currentBalance, uint256 calculatedFees);

/// @dev error when source chain is not expected
error InvalidSourceChain(uint64 expectedCCIPChainSelector, uint64 actualCCIPChainSelector);
error InvalidSourceChain(
uint64 expectedCCIPChainSelector,
uint64 actualCCIPChainSelector
);

/// @dev Error when an unauthorized address tries to call the bridge function on the L2
error UnauthorizedBridgeSweeper();
Expand Down Expand Up @@ -168,3 +171,6 @@ error InvalidStrategy();

/// @dev Error when strategy already set and hold non zero token balance
error NonZeroUnderlyingStrategyExist();

/// @dev Error when caller tried to claim queued withdrawal when not filled
error QueuedWithdrawalNotFilled();
Loading

0 comments on commit 9be7ca8

Please sign in to comment.