From a989e854d58cda9950e0fb138ef1fd615168eebd Mon Sep 17 00:00:00 2001 From: Nicholas Addison Date: Wed, 25 Sep 2024 15:55:09 +1000 Subject: [PATCH] More refactoring of MultiLP deposit and swap not longer add to the withdrawal queue. Its only need on claim --- src/contracts/LidoFixedPriceMultiLpARM.sol | 8 ----- src/contracts/MultiLP.sol | 29 +++++++------------ .../LidoFixedPriceMultiLpARM/Deposit.t.sol | 2 +- 3 files changed, 11 insertions(+), 28 deletions(-) diff --git a/src/contracts/LidoFixedPriceMultiLpARM.sol b/src/contracts/LidoFixedPriceMultiLpARM.sol index 460a162..d0f2cd7 100644 --- a/src/contracts/LidoFixedPriceMultiLpARM.sol +++ b/src/contracts/LidoFixedPriceMultiLpARM.sol @@ -71,14 +71,6 @@ contract LidoFixedPriceMultiLpARM is MultiLP._transferAsset(asset, to, transferAmount); } - /// @dev Funds the ARM's withdrawal queue when swaps send WETH to the ARM - function _transferAssetFrom(address asset, address from, address to, uint256 amount) - internal - override(AbstractARM, MultiLP) - { - MultiLP._transferAssetFrom(asset, from, to, amount); - } - function _externalWithdrawQueue() internal view override(MultiLP, LidoLiquidityManager) returns (uint256) { return LidoLiquidityManager._externalWithdrawQueue(); } diff --git a/src/contracts/MultiLP.sol b/src/contracts/MultiLP.sol index 5ed6759..66320bd 100644 --- a/src/contracts/MultiLP.sol +++ b/src/contracts/MultiLP.sol @@ -101,9 +101,6 @@ abstract contract MultiLP is AbstractARM, ERC20Upgradeable { // mint shares _mint(msg.sender, shares); - // Add WETH to the withdrawal queue if the queue has a shortfall - _addWithdrawalQueueLiquidity(); - _postDepositHook(assets); } @@ -159,11 +156,12 @@ abstract contract MultiLP is AbstractARM, ERC20Upgradeable { /// @param requestId The index of the withdrawal request /// @return assets The amount of liquidity assets that were transferred to the redeemer function claimRedeem(uint256 requestId) external returns (uint256 assets) { - // Update the ARM's withdrawal queue details - _addWithdrawalQueueLiquidity(); + // Update the ARM's withdrawal queue's claimable amount + _updateWithdrawalQueueLiquidity(); // Load the structs from storage into memory WithdrawalRequest memory request = withdrawalRequests[requestId]; + // This reads back the queue metadata that was updated in _updateWithdrawalQueueLiquidity WithdrawalQueueMetadata memory queue = withdrawalQueueMetadata; require(request.claimTimestamp <= block.timestamp, "Claim delay not met"); @@ -185,8 +183,9 @@ abstract contract MultiLP is AbstractARM, ERC20Upgradeable { IERC20(liquidityAsset).transfer(msg.sender, assets); } - /// @dev Adds liquidity to the withdrawal queue if there is a funding shortfall. - function _addWithdrawalQueueLiquidity() internal returns (uint256 addedClaimable) { + /// @dev Updates the claimable amount in the ARM's withdrawal queue. + /// That's the amount that is used to check if a request can be claimed or not. + function _updateWithdrawalQueueLiquidity() internal { WithdrawalQueueMetadata memory queue = withdrawalQueueMetadata; // Check if the claimable amount is less than the queued amount @@ -194,7 +193,7 @@ abstract contract MultiLP is AbstractARM, ERC20Upgradeable { // No need to do anything is the withdrawal queue is fully funded if (queueShortfall == 0) { - return 0; + return; } uint256 liquidityBalance = IERC20(liquidityAsset).balanceOf(address(this)); @@ -205,17 +204,16 @@ abstract contract MultiLP is AbstractARM, ERC20Upgradeable { // If there is no unallocated liquidity assets then there is nothing to add to the queue if (liquidityBalance <= allocatedLiquidity) { - return 0; + return; } uint256 unallocatedLiquidity = liquidityBalance - allocatedLiquidity; // the new claimable amount is the smaller of the queue shortfall or unallocated weth - addedClaimable = queueShortfall < unallocatedLiquidity ? queueShortfall : unallocatedLiquidity; - uint256 newClaimable = queue.claimable + addedClaimable; + uint256 addedClaimable = queueShortfall < unallocatedLiquidity ? queueShortfall : unallocatedLiquidity; // Store the new claimable amount back to storage - withdrawalQueueMetadata.claimable = SafeCast.toUint128(newClaimable); + withdrawalQueueMetadata.claimable = SafeCast.toUint128(queue.claimable + addedClaimable); } /// @dev Calculate how much of the liquidity asset in the ARM is not reserved for the withdrawal queue. @@ -247,13 +245,6 @@ abstract contract MultiLP is AbstractARM, ERC20Upgradeable { IERC20(asset).transfer(to, amount); } - /// @dev Funds the ARM's withdrawal queue when swaps send liquidity assets to the ARM - function _transferAssetFrom(address asset, address from, address to, uint256 amount) internal virtual override { - IERC20(asset).transferFrom(from, to, amount); - - _addWithdrawalQueueLiquidity(); - } - /// @notice The total amount of assets in the ARM and external withdrawal queue, /// less the liquidity assets reserved for the withdrawal queue function totalAssets() public view virtual returns (uint256 assets) { diff --git a/test/fork/LidoFixedPriceMultiLpARM/Deposit.t.sol b/test/fork/LidoFixedPriceMultiLpARM/Deposit.t.sol index 13d0bbf..3878c93 100644 --- a/test/fork/LidoFixedPriceMultiLpARM/Deposit.t.sol +++ b/test/fork/LidoFixedPriceMultiLpARM/Deposit.t.sol @@ -371,7 +371,7 @@ contract Fork_Concrete_LidoFixedPriceMultiLpARM_Deposit_Test_ is Fork_Shared_Tes assertEq(lidoFixedPriceMulltiLpARM.totalAssets(), MIN_TOTAL_SUPPLY + amount, "total assets after"); assertEq(liquidityProviderController.liquidityProviderCaps(alice), DEFAULT_AMOUNT * 3, "alice cap after"); // All the caps are used // withdrawal request is now claimable - assertEqQueueMetadata(DEFAULT_AMOUNT, DEFAULT_AMOUNT, 0, 1); + assertEqQueueMetadata(DEFAULT_AMOUNT, 0, 0, 1); assertEq(shares, amount); // No perfs, so 1 ether * totalSupply (1e18 + 1e12) / totalAssets (1e18 + 1e12) = 1 ether } }