Skip to content

Commit

Permalink
remove unused code
Browse files Browse the repository at this point in the history
  • Loading branch information
bxmmm1 committed Dec 17, 2024
1 parent 64cf816 commit 29a6d34
Show file tree
Hide file tree
Showing 9 changed files with 25 additions and 256 deletions.
19 changes: 4 additions & 15 deletions mainnet-contracts/script/GenerateAccessManagerCallData.sol
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,13 @@ import { PUBLIC_ROLE, ROLE_ID_DAO, ROLE_ID_PUFFER_PROTOCOL, ROLE_ID_OPERATIONS_M
*/
contract GenerateAccessManagerCallData is Script {
function run(address pufferVaultProxy, address pufferDepositorProxy) public pure returns (bytes memory) {
bytes[] memory calldatas = new bytes[](5);
bytes[] memory calldatas = new bytes[](4);

// Combine the two calldatas
calldatas[0] = _getPublicSelectorsCalldata({ pufferVaultProxy: pufferVaultProxy });
calldatas[1] = _getDaoSelectorsCalldataCalldata({ pufferVaultProxy: pufferVaultProxy });
calldatas[2] = _getProtocolSelectorsCalldata({ pufferVaultProxy: pufferVaultProxy });
calldatas[3] = _getOperationsSelectorsCalldata({ pufferVaultProxy: pufferVaultProxy });
calldatas[4] = _getPublicSelectorsForDepositor({ pufferDepositorProxy: pufferDepositorProxy });
calldatas[1] = _getProtocolSelectorsCalldata({ pufferVaultProxy: pufferVaultProxy });
calldatas[2] = _getOperationsSelectorsCalldata({ pufferVaultProxy: pufferVaultProxy });
calldatas[3] = _getPublicSelectorsForDepositor({ pufferDepositorProxy: pufferDepositorProxy });

bytes memory encodedMulticall = abi.encodeCall(Multicall.multicall, (calldatas));

Expand All @@ -52,16 +51,6 @@ contract GenerateAccessManagerCallData is Script {
);
}

function _getDaoSelectorsCalldataCalldata(address pufferVaultProxy) internal pure returns (bytes memory) {
// DAO selectors
bytes4[] memory daoSelectors = new bytes4[](1);
daoSelectors[0] = PufferVaultV2.setDailyWithdrawalLimit.selector;

return abi.encodeWithSelector(
AccessManager.setTargetFunctionRole.selector, pufferVaultProxy, daoSelectors, ROLE_ID_DAO
);
}

function _getProtocolSelectorsCalldata(address pufferVaultProxy) internal pure returns (bytes memory) {
// Puffer Protocol only
// PufferProtocol will get `ROLE_ID_PUFFER_PROTOCOL` when it's deployed
Expand Down
47 changes: 18 additions & 29 deletions mainnet-contracts/script/SetupAccess.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ contract SetupAccess is BaseScript {
bytes[] memory coordinatorAccess,
bytes[] memory validatorTicketAccess
) internal view returns (bytes[] memory calldatas) {
calldatas = new bytes[](31);
calldatas = new bytes[](30);
calldatas[0] = _setupGuardianModuleRoles();
calldatas[1] = _setupEnclaveVerifierRoles();
calldatas[2] = rolesCalldatas[0];
Expand All @@ -105,27 +105,26 @@ contract SetupAccess is BaseScript {
calldatas[13] = validatorTicketRoles[1];

calldatas[14] = vaultMainnetAccess[0];
calldatas[15] = vaultMainnetAccess[1];

calldatas[16] = pufferOracleAccess[0];
calldatas[17] = pufferOracleAccess[1];
calldatas[18] = pufferOracleAccess[2];
calldatas[15] = pufferOracleAccess[0];
calldatas[16] = pufferOracleAccess[1];
calldatas[17] = pufferOracleAccess[2];

calldatas[19] = moduleManagerAccess[0];
calldatas[20] = moduleManagerAccess[1];
calldatas[18] = moduleManagerAccess[0];
calldatas[19] = moduleManagerAccess[1];

calldatas[21] = roleLabels[0];
calldatas[22] = roleLabels[1];
calldatas[23] = roleLabels[2];
calldatas[24] = roleLabels[3];
calldatas[20] = roleLabels[0];
calldatas[21] = roleLabels[1];
calldatas[22] = roleLabels[2];
calldatas[23] = roleLabels[3];

calldatas[25] = coordinatorAccess[0];
calldatas[26] = coordinatorAccess[1];
calldatas[24] = coordinatorAccess[0];
calldatas[25] = coordinatorAccess[1];

calldatas[27] = validatorTicketAccess[0];
calldatas[28] = validatorTicketAccess[1];
calldatas[29] = validatorTicketAccess[2];
calldatas[30] = validatorTicketAccess[3];
calldatas[26] = validatorTicketAccess[0];
calldatas[27] = validatorTicketAccess[1];
calldatas[28] = validatorTicketAccess[2];
calldatas[29] = validatorTicketAccess[3];
}

function _labelRoles() internal pure returns (bytes[] memory) {
Expand Down Expand Up @@ -219,22 +218,12 @@ contract SetupAccess is BaseScript {
}

function _setupPufferVaultMainnetAccess() internal view returns (bytes[] memory) {
bytes[] memory calldatas = new bytes[](2);

bytes4[] memory operationsSelectors = new bytes4[](1);
operationsSelectors[0] = PufferVaultV2.setDailyWithdrawalLimit.selector;

calldatas[0] = abi.encodeWithSelector(
AccessManager.setTargetFunctionRole.selector,
pufferDeployment.pufferVault,
operationsSelectors,
ROLE_ID_OPERATIONS_MULTISIG
);
bytes[] memory calldatas = new bytes[](1);

bytes4[] memory protocolSelectors = new bytes4[](1);
protocolSelectors[0] = PufferVaultV2.transferETH.selector;

calldatas[1] = abi.encodeWithSelector(
calldatas[0] = abi.encodeWithSelector(
AccessManager.setTargetFunctionRole.selector,
pufferDeployment.pufferVault,
protocolSelectors,
Expand Down
6 changes: 3 additions & 3 deletions mainnet-contracts/src/PufferVaultStorage.sol
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ abstract contract PufferVaultStorage {
EnumerableSet.Bytes32Set deprecated_eigenLayerWithdrawals; // Not in use anymore
EnumerableMap.UintToUintMap lidoWithdrawalAmounts;
// 1 Slot for daily withdrawal limits
uint96 dailyAssetsWithdrawalLimit;
uint96 assetsWithdrawnToday;
uint64 lastWithdrawalDay;
uint96 deprecated_dailyAssetsWithdrawalLimit;
uint96 deprecated_assetsWithdrawnToday;
uint64 deprecated_lastWithdrawalDay;
// 1 slot for withdrawal fee
uint256 exitFeeBasisPoints;
// ETH rewards amount
Expand Down
93 changes: 0 additions & 93 deletions mainnet-contracts/src/PufferVaultV2.sol
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,6 @@ contract PufferVaultV2 is PufferVault, IPufferVaultV2 {
PUFFER_ORACLE = oracle;
ERC4626Storage storage erc4626Storage = _getERC4626StorageInternal();
erc4626Storage._asset = _WETH;
// This redundant code is for the Echidna fuzz testing
_setDailyWithdrawalLimit(100 ether);
_updateDailyWithdrawals(0);
_setExitFeeBasisPoints(100); // 1%
_disableInitializers();
}
Expand All @@ -76,8 +73,6 @@ contract PufferVaultV2 is PufferVault, IPufferVaultV2 {
// In this initialization, we swap out the underlying stETH with WETH
ERC4626Storage storage erc4626Storage = _getERC4626StorageInternal();
erc4626Storage._asset = _WETH;
_setDailyWithdrawalLimit(100 ether);
_updateDailyWithdrawals(0);
_setExitFeeBasisPoints(100); // 1%

// Return pufETH to Puffers
Expand Down Expand Up @@ -144,8 +139,6 @@ contract PufferVaultV2 is PufferVault, IPufferVaultV2 {
revert ERC4626ExceededMaxWithdraw(owner, assets, maxAssets);
}

_updateDailyWithdrawals(assets);

_wrapETH(assets);

uint256 shares = previewWithdraw(assets);
Expand Down Expand Up @@ -179,8 +172,6 @@ contract PufferVaultV2 is PufferVault, IPufferVaultV2 {

uint256 assets = previewRedeem(shares);

_updateDailyWithdrawals(assets);

_wrapETH(assets);

_withdraw({ caller: _msgSender(), receiver: receiver, owner: owner, assets: assets, shares: shares });
Expand Down Expand Up @@ -370,16 +361,6 @@ contract PufferVaultV2 is PufferVault, IPufferVaultV2 {
return _convertToShares(assets, Math.Rounding.Ceil);
}

/**
* @notice Sets a new daily withdrawal limit
* @dev Restricted to the DAO
* @param newLimit The new daily limit to be set
*/
function setDailyWithdrawalLimit(uint96 newLimit) external restricted {
_setDailyWithdrawalLimit(newLimit);
_resetDailyWithdrawals();
}

/**
* @param newExitFeeBasisPoints is the new exit fee basis points
* @dev Restricted to the DAO
Expand All @@ -388,48 +369,6 @@ contract PufferVaultV2 is PufferVault, IPufferVaultV2 {
_setExitFeeBasisPoints(newExitFeeBasisPoints);
}

/**
* @inheritdoc IPufferVaultV2
*/
function getRemainingAssetsDailyWithdrawalLimit() public view virtual returns (uint256) {
VaultStorage storage $ = _getPufferVaultStorage();
uint96 dailyAssetsWithdrawalLimit = $.dailyAssetsWithdrawalLimit;
uint96 assetsWithdrawnToday = $.assetsWithdrawnToday;

// If we are in a new day, return the full daily limit
if ($.lastWithdrawalDay < block.timestamp / 1 days) {
return dailyAssetsWithdrawalLimit;
}

return dailyAssetsWithdrawalLimit - assetsWithdrawnToday;
}

/**
* @notice Calculates the maximum amount of assets (WETH) that can be withdrawn by the `owner`.
* @dev This function considers both the remaining daily withdrawal limit and the `owner`'s balance.
* See {IERC4626-maxWithdraw}
* @param owner The address of the owner for which the maximum withdrawal amount is calculated.
* @return maxAssets The maximum amount of assets that can be withdrawn by the `owner`.
*/
function maxWithdraw(address owner) public view virtual override returns (uint256 maxAssets) {
uint256 remainingAssets = getRemainingAssetsDailyWithdrawalLimit();
uint256 maxUserAssets = previewRedeem(balanceOf(owner));
return remainingAssets < maxUserAssets ? remainingAssets : maxUserAssets;
}

/**
* @notice Calculates the maximum amount of shares (pufETH) that can be redeemed by the `owner`.
* @dev This function considers both the remaining daily withdrawal limit in terms of assets and converts it to shares, and the `owner`'s share balance.
* See {IERC4626-maxRedeem}
* @param owner The address of the owner for which the maximum redeemable shares are calculated.
* @return maxShares The maximum amount of shares that can be redeemed by the `owner`.
*/
function maxRedeem(address owner) public view virtual override returns (uint256 maxShares) {
uint256 remainingShares = previewWithdraw(getRemainingAssetsDailyWithdrawalLimit());
uint256 userShares = balanceOf(owner);
return remainingShares < userShares ? remainingShares : userShares;
}

/**
* @dev Preview adding an exit fee on withdraw. See {IERC4626-previewWithdraw}.
*/
Expand Down Expand Up @@ -483,31 +422,6 @@ contract PufferVaultV2 is PufferVault, IPufferVaultV2 {
}
}

/**
* @notice Updates the amount of assets (WETH) withdrawn today
* @param withdrawalAmount is the assets (WETH) amount
*/
function _updateDailyWithdrawals(uint256 withdrawalAmount) internal virtual {
VaultStorage storage $ = _getPufferVaultStorage();

// Check if it's a new day to reset the withdrawal count
if ($.lastWithdrawalDay < block.timestamp / 1 days) {
_resetDailyWithdrawals();
}
$.assetsWithdrawnToday += uint96(withdrawalAmount);
emit AssetsWithdrawnToday($.assetsWithdrawnToday);
}

/**
* @notice Updates the maximum amount of assets (WETH) that can be withdrawn daily
* @param newLimit is the assets (WETH) amount
*/
function _setDailyWithdrawalLimit(uint96 newLimit) internal virtual {
VaultStorage storage $ = _getPufferVaultStorage();
emit DailyWithdrawalLimitSet($.dailyAssetsWithdrawalLimit, newLimit);
$.dailyAssetsWithdrawalLimit = newLimit;
}

/**
* @notice Updates the exit fee basis points
* @dev 200 Basis points = 2% is the maximum exit fee
Expand Down Expand Up @@ -542,13 +456,6 @@ contract PufferVaultV2 is PufferVault, IPufferVaultV2 {
_;
}

function _resetDailyWithdrawals() internal virtual {
VaultStorage storage $ = _getPufferVaultStorage();
$.lastWithdrawalDay = uint64(block.timestamp / 1 days);
$.assetsWithdrawnToday = 0;
emit DailyWithdrawalLimitReset();
}

function _authorizeUpgrade(address newImplementation) internal virtual override restricted { }

function _getERC4626StorageInternal() private pure returns (ERC4626Storage storage $) {
Expand Down
24 changes: 0 additions & 24 deletions mainnet-contracts/src/interface/IPufferVaultV2.sol
Original file line number Diff line number Diff line change
Expand Up @@ -24,24 +24,6 @@ interface IPufferVaultV2 is IPufferVault {
*/
error InvalidExitFeeBasisPoints();

/**
* Emitted when assets (WETH) are withdrawn
* @dev Signature: 0x139f9ee0762f3b0c92a4b8c7b8fe8be6b12aaece4b9b22de6bf1ba1094dcd998
*/
event AssetsWithdrawnToday(uint256 withdrawalAmount);

/**
* Emitted daily withdrawal limit is reset
* @dev Signature: 0x190567136e3dd93d29bef98a7c7c87cff34ee88e71d634b52f5fb3b531085f40
*/
event DailyWithdrawalLimitReset();

/**
* Emitted when the daily withdrawal limit is set
* @dev Signature: 0x8d5f7487ce1fd25059bd15204a55ea2c293160362b849a6f9244aec7d5a3700b
*/
event DailyWithdrawalLimitSet(uint96 oldLimit, uint96 newLimit);

/**
* Emitted when the Vault transfers ETH to a specified address
* @dev Signature: 0xba7bb5aa419c34d8776b86cc0e9d41e72d74a893a511f361a11af6c05e920c3d
Expand All @@ -65,12 +47,6 @@ interface IPufferVaultV2 is IPufferVault {
*/
function getExitFeeBasisPoints() external view returns (uint256);

/**
* @notice Returns the remaining assets that can be withdrawn today
* @return The remaining assets that can be withdrawn today
*/
function getRemainingAssetsDailyWithdrawalLimit() external view returns (uint256);

/**
* @notice Deposits native ETH into the Puffer Vault
* @param receiver The recipient of pufETH tokens
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -279,8 +279,6 @@ contract PufferTest is Test {

assertEq(pufferVault.totalAssets(), assetsBefore + 10 ether, "Previous assets should increase");

PufferVaultV2(payable(address(pufferVault))).getRemainingAssetsDailyWithdrawalLimit();

pufferVault.balanceOf(eve);
uint256 maxWithdraw = pufferVault.maxWithdraw(eve);

Expand Down
Loading

0 comments on commit 29a6d34

Please sign in to comment.