Skip to content

Commit

Permalink
Fund the withdrawal queue when WETH is swapped into the ARM
Browse files Browse the repository at this point in the history
  • Loading branch information
naddison36 committed Sep 25, 2024
1 parent 6554eab commit 009c379
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 4 deletions.
5 changes: 5 additions & 0 deletions src/contracts/AbstractARM.sol
Original file line number Diff line number Diff line change
Expand Up @@ -159,4 +159,9 @@ abstract contract AbstractARM is OwnableOperable {
function _transferAsset(address asset, address to, uint256 amount) internal virtual {
IERC20(asset).transfer(to, amount);
}

/// @dev Hook to transfer assets into the ARM contract
function _transferAssetFrom(address asset, address from, address to, uint256 amount) internal virtual {
IERC20(asset).transferFrom(from, to, amount);
}
}
4 changes: 2 additions & 2 deletions src/contracts/FixedPriceARM.sol
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ abstract contract FixedPriceARM is AbstractARM {
amountOut = amountIn * price / PRICE_SCALE;

// Transfer the input tokens from the caller to this ARM contract
inToken.transferFrom(msg.sender, address(this), amountIn);
_transferAssetFrom(address(inToken), msg.sender, address(this), amountIn);

// Transfer the output tokens to the recipient
_transferAsset(address(outToken), to, amountOut);
Expand All @@ -78,7 +78,7 @@ abstract contract FixedPriceARM is AbstractARM {
amountIn = ((amountOut * PRICE_SCALE) / price) + 1; // +1 to always round in our favor

// Transfer the input tokens from the caller to this ARM contract
inToken.transferFrom(msg.sender, address(this), amountIn);
_transferAssetFrom(address(inToken), msg.sender, address(this), amountIn);

// Transfer the output tokens to the recipient
_transferAsset(address(outToken), to, amountOut);
Expand Down
8 changes: 8 additions & 0 deletions src/contracts/LidoFixedPriceMultiLpARM.sol
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,14 @@ 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
11 changes: 10 additions & 1 deletion src/contracts/MultiLP.sol
Original file line number Diff line number Diff line change
Expand Up @@ -240,11 +240,20 @@ abstract contract MultiLP is AbstractARM, ERC20Upgradeable {
/// @dev Ensure any liquidity assets reserved for the withdrawal queue are not used
/// in swaps that send liquidity assets out of the ARM
function _transferAsset(address asset, address to, uint256 amount) internal virtual override {
require(asset == liquidityAsset && amount <= _liquidityAvailable(), "ARM: Insufficient liquidity");
if (asset == liquidityAsset) {
require(amount <= _liquidityAvailable(), "ARM: Insufficient liquidity");
}

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
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ contract Fork_Concrete_LidoFixedPriceMultiLpARM_SwapExactTokensForTokens_Test is

initialBalance = weth.balanceOf(address(lidoFixedPriceMulltiLpARM));
deal(address(steth), address(this), initialBalance * 2);
vm.expectRevert(); // Lido error
vm.expectRevert("ARM: Insufficient liquidity");
lidoFixedPriceMulltiLpARM.swapExactTokensForTokens(
steth, // inToken
weth, // outToken
Expand Down

0 comments on commit 009c379

Please sign in to comment.