You need to keep WETH in the contract I believe to make the swaps.
To withdraw, you can call the call(_to, _value, _data)
function with:
_to = WETH_ADDRESS
_value = 0
_data
:
_data = ethers.utils.hexConcat([
'0xa9059cbb', // selector of transfer(address,uint256)
ethers.utils.defaultAbiCoder.encode(
['address', 'uint256'],
[MY_ADDRESS, WETH_AMOUNT_IN_WEI]
)
])
with MY_ADDRESS
your wallet address, and WETH_AMOUNT_IN_WEI
the amount in the contract you want to withdraw.
Basically with this method your contract will call WETH to make a transfer to your wallet.