Skip to content

Commit

Permalink
More refactoring of MultiLP
Browse files Browse the repository at this point in the history
deposit and swap not longer add to the withdrawal queue. Its only need on claim
  • Loading branch information
naddison36 committed Sep 25, 2024
1 parent 009c379 commit a989e85
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 28 deletions.
8 changes: 0 additions & 8 deletions src/contracts/LidoFixedPriceMultiLpARM.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down
29 changes: 10 additions & 19 deletions src/contracts/MultiLP.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down Expand Up @@ -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");
Expand All @@ -185,16 +183,17 @@ 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
uint256 queueShortfall = queue.queued - queue.claimable;

// 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));
Expand All @@ -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.
Expand Down Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion test/fork/LidoFixedPriceMultiLpARM/Deposit.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}

0 comments on commit a989e85

Please sign in to comment.