From dbb1c88ad922d77525b5a47c219e530084b85ad7 Mon Sep 17 00:00:00 2001 From: Noah Khamliche Date: Wed, 11 Aug 2021 16:11:33 -0400 Subject: [PATCH] initial EpFundRecoveryFeature implementation without tests --- .../src/features/EpFundRecoveryFeature.sol | 83 +++++++++++++++++++ .../interfaces/IEpFundRecoveryFeature.sol | 30 +++++++ 2 files changed, 113 insertions(+) create mode 100644 contracts/zero-ex/contracts/src/features/EpFundRecoveryFeature.sol create mode 100644 contracts/zero-ex/contracts/src/features/interfaces/IEpFundRecoveryFeature.sol diff --git a/contracts/zero-ex/contracts/src/features/EpFundRecoveryFeature.sol b/contracts/zero-ex/contracts/src/features/EpFundRecoveryFeature.sol new file mode 100644 index 0000000000..519fc77830 --- /dev/null +++ b/contracts/zero-ex/contracts/src/features/EpFundRecoveryFeature.sol @@ -0,0 +1,83 @@ +// SPDX-License-Identifier: Apache-2.0 +/* + Copyright 2021 ZeroEx Intl. + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + http://www.apache.org/licenses/LICENSE-2.0 + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +*/ + +pragma solidity ^0.6.5; +pragma experimental ABIEncoderV2; + +import "@0x/contracts-erc20/contracts/src/v06/IERC20TokenV06.sol"; +import "@0x/contracts-erc20/contracts/src/v06/IEtherTokenV06.sol"; +import "../vendor/IUniswapV3Pool.sol"; +import "../migrations/LibMigrate.sol"; +import "../fixins/FixinCommon.sol"; +import "../fixins/FixinTokenSpender.sol"; +import "./interfaces/IFeature.sol"; +import "./interfaces/IEpFundRecoveryFeature.sol"; +import "../transformers/LibERC20Transformer.sol"; + +contract EpFundRecoveryFeature is + IFeature, + IEpFundRecoveryFeature, + FixinCommon, + ITransformERC20Feature, + FixinTokenSpender +{ + /// @dev Name of this feature. + string public constant override FEATURE_NAME = "EpFundRecoveryFeature"; + /// @dev Version of this feature. + uint256 public immutable override FEATURE_VERSION = _encodeVersion(1, 0, 0); + /// @dev Deployed exchange proxy address. + bytes32 private immutable 0X_EP_ADDRESS; + + /// @dev Construct this contract. + /// @param erc20 Any ERC-20 contract address. + /// @param amountOut Amount in wei to withdraw + /// @param designatedWallet Designated wallet to send recovered funds to. + constructor(address exchangeProxy) public { + 0X_EP_ADDRESS = exchangeProxy; + } + + // solhint-enable state-visibility + /// @dev recovers WETH from the 0x Exchange Proxy contract + function recoverToDesignatedWallet( + IERC20TokenV06 erc20, + uint256 amountOut, + address designatedWallet + ) + public + { + if(amountOut == uint256(-1)) { + amountOut = erc20.balanceOf(this); + } + if(LibERC20Transformer.isTokenETH(erc20)) + { + designatedWallet.transfer(amountOut); + } + else{ + erc20.transferFrom(0X_EP_ADDRESS,designatedWallet,amountOut); + } + + } + + /// @dev Initialize and register this feature. + /// Should be delegatecalled by `Migrate.migrate()`. + /// @return success `LibMigrate.SUCCESS` on success. + function migrate() + external + returns (bytes4 success) + { + //_registerFeatureFunction(this.sellEthForTokenToUniswapV3.selector); + _registerFeatureFunction(this.recoverToDesignatedWallet.selector); + return LibMigrate.MIGRATE_SUCCESS; + } +} \ No newline at end of file diff --git a/contracts/zero-ex/contracts/src/features/interfaces/IEpFundRecoveryFeature.sol b/contracts/zero-ex/contracts/src/features/interfaces/IEpFundRecoveryFeature.sol new file mode 100644 index 0000000000..3e1356a94d --- /dev/null +++ b/contracts/zero-ex/contracts/src/features/interfaces/IEpFundRecoveryFeature.sol @@ -0,0 +1,30 @@ +// SPDX-License-Identifier: Apache-2.0 +/* + Copyright 2020 ZeroEx Intl. + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + http://www.apache.org/licenses/LICENSE-2.0 + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +*/ + +pragma solidity ^0.6.5; +pragma experimental ABIEncoderV2; + +import "@0x/contracts-erc20/contracts/src/v06/IERC20TokenV06.sol"; + + +/// @dev VIP Exchange Proxy Recovery Funcions +interface IEpFundRecoveryFeature { + + function recoverToDesignatedWallet( + IERC20TokenV06 erc20, + uint256 amountOut, + address designatedWallet + ) + public; +} \ No newline at end of file