Skip to content

Commit

Permalink
revert changes to GenericSwapFacetV3
Browse files Browse the repository at this point in the history
  • Loading branch information
ezynda3 committed Jan 6, 2025
1 parent a8bde0f commit ff98810
Showing 1 changed file with 21 additions and 10 deletions.
31 changes: 21 additions & 10 deletions src/Facets/GenericSwapFacetV3.sol
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import { ERC20, SafeTransferLib } from "solmate/utils/SafeTransferLib.sol";
/// @author LI.FI (https://li.fi)
/// @notice Provides gas-optimized functionality for fee collection and for swapping through any APPROVED DEX
/// @dev Can only execute calldata for APPROVED function selectors
/// @custom:version 1.0.2
/// @custom:version 1.0.1
contract GenericSwapFacetV3 is ILiFi {
using SafeTransferLib for ERC20;

Expand Down Expand Up @@ -111,7 +111,9 @@ contract GenericSwapFacetV3 is ILiFi {
revert CumulativeSlippageTooHigh(_minAmountOut, amountReceived);

// transfer funds to receiver
SafeTransferLib.safeTransferETH(_receiver, amountReceived);
// solhint-disable-next-line avoid-low-level-calls
(bool success, ) = _receiver.call{ value: amountReceived }("");
if (!success) revert NativeAssetTransferFailed();

// emit events (both required for tracking)
address sendingAssetId = _swapData.sendingAssetId;
Expand Down Expand Up @@ -161,9 +163,10 @@ contract GenericSwapFacetV3 is ILiFi {
) revert ContractCallNotAllowed();

// execute swap
SafeTransferLib.safeTransferETH(callTo, msg.value);
// solhint-disable-next-line avoid-low-level-calls
(bool success, bytes memory res) = callTo.call(_swapData.callData);
(bool success, bytes memory res) = callTo.call{ value: msg.value }(
_swapData.callData
);
if (!success) {
LibUtil.revertWith(res);
}
Expand Down Expand Up @@ -408,10 +411,12 @@ contract GenericSwapFacetV3 is ILiFi {
if (LibAsset.isNativeAsset(sendingAssetId)) {
// Native
// execute the swap
SafeTransferLib.safeTransferETH(
currentSwap.callTo,
currentSwap.fromAmount
);
(success, returnData) = currentSwap.callTo.call{
value: currentSwap.fromAmount
}(currentSwap.callData);
if (!success) {
LibUtil.revertWith(returnData);
}

// return any potential leftover sendingAsset tokens
// but only for swaps, not for fee collections (otherwise the whole amount would be returned before the actual swap)
Expand Down Expand Up @@ -516,7 +521,11 @@ contract GenericSwapFacetV3 is ILiFi {
revert CumulativeSlippageTooHigh(_minAmountOut, amountReceived);

// transfer funds to receiver
SafeTransferLib.safeTransferETH(_receiver, amountReceived);
// solhint-disable-next-line avoid-low-level-calls
(bool success, ) = _receiver.call{ value: amountReceived }("");
if (!success) {
revert NativeAssetTransferFailed();
}

// emit event
emit ILiFi.LiFiGenericSwapCompleted(
Expand Down Expand Up @@ -554,7 +563,9 @@ contract GenericSwapFacetV3 is ILiFi {
uint256 nativeBalance = address(this).balance;

if (nativeBalance > 0) {
SafeTransferLib.safeTransferETH(receiver, nativeBalance);
// solhint-disable-next-line avoid-low-level-calls
(bool success, ) = receiver.call{ value: nativeBalance }("");
if (!success) revert NativeAssetTransferFailed();
}
}
}

0 comments on commit ff98810

Please sign in to comment.