contract OutgoingTransferSupportV1 {
    using SafeERC20 for IERC20;

    IWETH immutable weth;

    constructor(address _wethAddress) {
        weth = IWETH(_wethAddress);
    }

    /// @notice Handle an outgoing funds transfer
    /// @dev Wraps ETH in WETH if the receiver cannot receive ETH, noop if the funds to be sent are 0 or recipient is invalid
    /// @param _dest The destination for the funds
    /// @param _amount The amount to be sent
    /// @param _currency The currency to send funds in, or address(0) for ETH
    /// @param _gasLimit The gas limit to use when attempting a payment (if 0, gasleft() is used)
    function _handleOutgoingTransfer(
        address _dest,
        uint256 _amount,
        address _currency,
        uint256 _gasLimit
    ) internal {
        if (_amount == 0 || _dest == address(0)) {
            return;
        }

        // Handle ETH payment
        if (_currency == address(0)) {
            require(address(this).balance >= _amount, "_handleOutgoingTransfer insolvent");

            // If no gas limit was provided or provided gas limit greater than gas left, just use the remaining gas.
            uint256 gas = (_gasLimit == 0 || _gasLimit > gasleft()) ? gasleft() : _gasLimit;
            (bool success, ) = _dest.call{value: _amount, gas: gas}("");
            // If the ETH transfer fails (sigh), wrap the ETH and try send it as WETH.
            if (!success) {
                weth.deposit{value: _amount}();
                IERC20(address(weth)).safeTransfer(_dest, _amount);
            }
        } else {
            IERC20(_currency).safeTransfer(_dest, _amount);
        }
    }
}
/// @title OutgoingTransferSupportV1
/// @author tbtstl <t@zora.co>
/// @notice This contract extension supports paying out funds to an external recipient
function _handleOutgoingTransfer(
    address _dest,
    uint256 _amount,
    address _currency,
    uint256 _gasLimit
) internal {
    if (_amount == 0 || _dest == address(0)) {
        return;
    }

    // Handle ETH payment
    if (_currency == address(0)) {
        require(address(this).balance >= _amount, "_handleOutgoingTransfer insolvent");

        // If no gas limit was provided or provided gas limit greater than gas left, just use the remaining gas.
        uint256 gas = (_gasLimit == 0 || _gasLimit > gasleft()) ? gasleft() : _gasLimit;
        (bool success, ) = _dest.call{value: _amount, gas: gas}("");
        // If the ETH transfer fails (sigh), wrap the ETH and try send it as WETH.
        if (!success) {
            weth.deposit{value: _amount}();
            IERC20(address(weth)).safeTransfer(_dest, _amount);
        }
    } else {
        IERC20(_currency).safeTransfer(_dest, _amount);
    }
}

/// @notice Handle an outgoing funds transfer
/// @dev Wraps ETH in WETH if the receiver cannot receive ETH, noop if the funds to be sent are 0 or recipient is invalid
/// @param _dest The destination for the funds
/// @param _amount The amount to be sent
/// @param _currency The currency to send funds in, or address(0) for ETH
/// @param _gasLimit The gas limit to use when attempting a payment (if 0, gasleft() is used)