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

[Certora][H-02] NFT Withdrawal Price Finalization #158

Open
wants to merge 7 commits into
base: staging-2.5
Choose a base branch
from
Open
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
4 changes: 2 additions & 2 deletions script/upgrades/WithdrawRequestNFTUpgradeScript.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ contract WithdrawRequestNFTUpgrade is Script {
address addressProviderAddress = vm.envAddress("CONTRACT_REGISTRY");
addressProvider = AddressProvider(addressProviderAddress);

address proxyAddress = addressProvider.getContractAddress("WithdrawRequestNFT");
address payable proxyAddress = payable(addressProvider.getContractAddress("WithdrawRequestNFT"));

vm.startBroadcast(deployerPrivateKey);

Expand All @@ -26,4 +26,4 @@ contract WithdrawRequestNFTUpgrade is Script {

vm.stopBroadcast();
}
}
}
2 changes: 1 addition & 1 deletion src/EtherFiAdmin.sol
Original file line number Diff line number Diff line change
Expand Up @@ -274,4 +274,4 @@ contract EtherFiAdmin is Initializable, OwnableUpgradeable, UUPSUpgradeable {
}

function _authorizeUpgrade(address newImplementation) internal override onlyOwner {}
}
}
42 changes: 14 additions & 28 deletions src/LiquidityPool.sol
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ contract LiquidityPool is Initializable, OwnableUpgradeable, UUPSUpgradeable, IL
mapping(address => BnftHoldersIndex) public validatorSpawner;

bool public restakeBnftDeposits;
uint128 public ethAmountLockedForWithdrawal;
uint128 public DEPRECATED_ethAmountLockedForWithdrawal;
bool public paused;
IAuctionManager public auctionManager;
ILiquifier public liquifier;
Expand All @@ -75,7 +75,7 @@ contract LiquidityPool is Initializable, OwnableUpgradeable, UUPSUpgradeable, IL
RoleRegistry public roleRegistry;

//--------------------------------------------------------------------------------------
//------------------------------------- ROLES ---------------------------------------
//------------------------------------- ROLES ----------------------------------------
//--------------------------------------------------------------------------------------

bytes32 public constant LIQUIDITY_POOL_ADMIN_ROLE = keccak256("LIQUIDITY_POOL_ADMIN_ROLE");
Expand Down Expand Up @@ -136,7 +136,7 @@ contract LiquidityPool is Initializable, OwnableUpgradeable, UUPSUpgradeable, IL
tNft = ITNFT(_tNftAddress);
paused = true;
restakeBnftDeposits = false;
ethAmountLockedForWithdrawal = 0;
DEPRECATED_ethAmountLockedForWithdrawal = 0;
etherFiAdminContract = _etherFiAdminContract;
withdrawRequestNFT = IWithdrawRequestNFT(_withdrawRequestNFT);
DEPRECATED_admins[_etherFiAdminContract] = true;
Expand All @@ -152,8 +152,8 @@ contract LiquidityPool is Initializable, OwnableUpgradeable, UUPSUpgradeable, IL

function initializeV2dot5(address _roleRegistry) external onlyOwner {
require(address(roleRegistry) == address(0x00), "already initialized");
// TODO: compile list of values in DEPRECATED_admins to clear out

DEPRECATED_ethAmountLockedForWithdrawal = 0;
roleRegistry = RoleRegistry(_roleRegistry);
}

Expand Down Expand Up @@ -195,13 +195,10 @@ contract LiquidityPool is Initializable, OwnableUpgradeable, UUPSUpgradeable, IL
function withdraw(address _recipient, uint256 _amount) external whenNotPaused returns (uint256) {
uint256 share = sharesForWithdrawalAmount(_amount);
require(msg.sender == address(withdrawRequestNFT) || msg.sender == address(membershipManager) || msg.sender == address(liquifier), "Incorrect Caller");
if (totalValueInLp < _amount || (msg.sender == address(withdrawRequestNFT) && ethAmountLockedForWithdrawal < _amount) || eETH.balanceOf(msg.sender) < _amount) revert InsufficientLiquidity();
if (totalValueInLp < _amount || eETH.balanceOf(msg.sender) < _amount) revert InsufficientLiquidity();
if (_amount > type(uint128).max || _amount == 0 || share == 0) revert InvalidAmount();

totalValueInLp -= uint128(_amount);
if (msg.sender == address(withdrawRequestNFT)) {
ethAmountLockedForWithdrawal -= uint128(_amount);
}

eETH.burnShares(msg.sender, share);

Expand All @@ -216,15 +213,15 @@ contract LiquidityPool is Initializable, OwnableUpgradeable, UUPSUpgradeable, IL
/// @dev Transfers the amount of eETH from msg.senders account to the WithdrawRequestNFT contract & mints an NFT to the msg.sender
/// @param recipient address that will be issued the NFT
/// @param amount requested amount to withdraw from contract
/// @return uint256 requestId of the WithdrawRequestNFT
function requestWithdraw(address recipient, uint256 amount) public whenNotPaused returns (uint256) {
/// @return uint32 requestId of the WithdrawRequestNFT
function requestWithdraw(address recipient, uint256 amount) public whenNotPaused returns (uint32) {
uint256 share = sharesForAmount(amount);
if (amount > type(uint96).max || amount == 0 || share == 0) revert InvalidAmount();

// transfer shares to WithdrawRequestNFT contract from this contract
eETH.transferFrom(msg.sender, address(withdrawRequestNFT), amount);

uint256 requestId = withdrawRequestNFT.requestWithdraw(uint96(amount), uint96(share), recipient, 0);
uint32 requestId = withdrawRequestNFT.requestWithdraw(uint96(amount), uint96(share), recipient);

emit Withdraw(msg.sender, recipient, amount, SourceOfFunds.EETH);

Expand All @@ -236,11 +233,11 @@ contract LiquidityPool is Initializable, OwnableUpgradeable, UUPSUpgradeable, IL
/// @param _owner address that will be issued the NFT
/// @param _amount requested amount to withdraw from contract
/// @param _permit signed permit data to approve transfer of eETH
/// @return uint256 requestId of the WithdrawRequestNFT
/// @return uint32 requestId of the WithdrawRequestNFT
function requestWithdrawWithPermit(address _owner, uint256 _amount, PermitInput calldata _permit)
external
whenNotPaused
returns (uint256)
returns (uint32)
{
try eETH.permit(msg.sender, address(this), _permit.value, _permit.deadline, _permit.v, _permit.r, _permit.s) {} catch {}
return requestWithdraw(_owner, _amount);
Expand All @@ -251,7 +248,7 @@ contract LiquidityPool is Initializable, OwnableUpgradeable, UUPSUpgradeable, IL
/// @param recipient address that will be issued the NFT
/// @param amount requested amount to withdraw from contract
/// @param fee the burn fee to be paid by the recipient when the withdrawal is claimed (WithdrawRequestNFT.claimWithdraw)
/// @return uint256 requestId of the WithdrawRequestNFT
/// @return uint32 requestId of the WithdrawRequestNFT
function requestMembershipNFTWithdraw(address recipient, uint256 amount, uint256 fee) public whenNotPaused returns (uint256) {
if (msg.sender != address(membershipManager)) revert IncorrectCaller();
uint256 share = sharesForAmount(amount);
Expand All @@ -260,7 +257,7 @@ contract LiquidityPool is Initializable, OwnableUpgradeable, UUPSUpgradeable, IL
// transfer shares to WithdrawRequestNFT contract
eETH.transferFrom(msg.sender, address(withdrawRequestNFT), amount);

uint256 requestId = withdrawRequestNFT.requestWithdraw(uint96(amount), uint96(share), recipient, fee);
uint32 requestId = withdrawRequestNFT.requestWithdraw(uint96(amount), uint96(share), recipient);

emit Withdraw(msg.sender, recipient, amount, SourceOfFunds.ETHER_FAN);

Expand Down Expand Up @@ -426,6 +423,7 @@ contract LiquidityPool is Initializable, OwnableUpgradeable, UUPSUpgradeable, IL

emit Rebase(getTotalPooledEther(), eETH.totalShares());
}

/// @notice pay protocol fees including 5% to treaury, 5% to node operator and ethfund bnft holders
/// @param _protocolFees The amount of protocol fees to pay in ether
function payProtocolFees(uint128 _protocolFees) external {
Expand Down Expand Up @@ -473,12 +471,6 @@ contract LiquidityPool is Initializable, OwnableUpgradeable, UUPSUpgradeable, IL
isLpBnftHolder = _isLpBnftHolder;
}

function addEthAmountLockedForWithdrawal(uint128 _amount) external {
if (msg.sender != address(withdrawRequestNFT)) revert IncorrectCaller();

ethAmountLockedForWithdrawal += _amount;
}

// This function can't change the TVL
// but used only to correct the errors in tracking {totalValueOutOfLp} and {totalValueInLp}
function updateTvlSplits(int128 _diffTotalValueOutOfLp, int128 _diffTotalValueInLp) external onlyOwner {
Expand All @@ -490,12 +482,6 @@ contract LiquidityPool is Initializable, OwnableUpgradeable, UUPSUpgradeable, IL
if(tvl != getTotalPooledEther()) revert();
}

function reduceEthAmountLockedForWithdrawal(uint128 _amount) external {
if (msg.sender != address(withdrawRequestNFT)) revert IncorrectCaller();

ethAmountLockedForWithdrawal -= _amount;
}

//--------------------------------------------------------------------------------------
//------------------------------ INTERNAL FUNCTIONS ----------------------------------
//--------------------------------------------------------------------------------------
Expand Down
Loading
Loading