From 2d16f83e3713bd029e00a673b6f3027a9edb24c7 Mon Sep 17 00:00:00 2001 From: Kyu Date: Thu, 19 May 2022 17:39:02 -0700 Subject: [PATCH] Offboard/clean up Oasis, CoFix, and legacy Kyber [TKR-405] (#482) * Remove Oasis * Remove CoFix code * Remove MixinKyber * Remove Kyber from asset-swapper * Delete unused imports, interface, and etc. * Fix the test failure issue when it's run with neon-router * Update CHANGELOG.json --- .../transformers/bridges/BridgeAdapter.sol | 10 - .../transformers/bridges/BridgeProtocols.sol | 6 +- .../bridges/mixins/MixinCoFiX.sol | 92 ------ .../bridges/mixins/MixinKyber.sol | 124 -------- .../bridges/mixins/MixinOasis.sol | 76 ----- contracts/zero-ex/package.json | 2 +- contracts/zero-ex/test/artifacts.ts | 6 - contracts/zero-ex/test/wrappers.ts | 3 - contracts/zero-ex/tsconfig.json | 3 - packages/asset-swapper/CHANGELOG.json | 9 + .../contracts/src/ERC20BridgeSampler.sol | 2 - .../contracts/src/KyberSampler.sol | 301 ------------------ .../src/interfaces/IKyberNetwork.sol | 96 ------ packages/asset-swapper/package.json | 2 +- packages/asset-swapper/src/index.ts | 1 - .../bridge_source_utils.ts | 26 +- .../utils/market_operation_utils/constants.ts | 42 --- .../utils/market_operation_utils/orders.ts | 13 - .../sampler_operations.ts | 74 ----- .../src/utils/market_operation_utils/types.ts | 13 - packages/asset-swapper/test/artifacts.ts | 4 - .../test/comparison_price_test.ts | 6 +- .../contracts/bridge_sampler_mainnet_test.ts | 60 +--- .../asset-swapper/test/dex_sampler_test.ts | 37 +-- .../test/market_operation_utils_test.ts | 18 +- .../test/quote_report_generator_test.ts | 40 +-- .../test/utils/mock_sampler_contract.ts | 32 +- packages/asset-swapper/test/wrappers.ts | 2 - packages/asset-swapper/tsconfig.json | 2 - .../protocol-utils/src/transformer_utils.ts | 3 - 30 files changed, 48 insertions(+), 1057 deletions(-) delete mode 100644 contracts/zero-ex/contracts/src/transformers/bridges/mixins/MixinCoFiX.sol delete mode 100644 contracts/zero-ex/contracts/src/transformers/bridges/mixins/MixinKyber.sol delete mode 100644 contracts/zero-ex/contracts/src/transformers/bridges/mixins/MixinOasis.sol delete mode 100644 packages/asset-swapper/contracts/src/KyberSampler.sol delete mode 100644 packages/asset-swapper/contracts/src/interfaces/IKyberNetwork.sol diff --git a/contracts/zero-ex/contracts/src/transformers/bridges/BridgeAdapter.sol b/contracts/zero-ex/contracts/src/transformers/bridges/BridgeAdapter.sol index 63670ffc49..7cc088c624 100644 --- a/contracts/zero-ex/contracts/src/transformers/bridges/BridgeAdapter.sol +++ b/contracts/zero-ex/contracts/src/transformers/bridges/BridgeAdapter.sol @@ -40,7 +40,6 @@ import "./mixins/MixinMakerPSM.sol"; import "./mixins/MixinMooniswap.sol"; import "./mixins/MixinMStable.sol"; import "./mixins/MixinNerve.sol"; -import "./mixins/MixinOasis.sol"; import "./mixins/MixinPlatypus.sol"; import "./mixins/MixinShell.sol"; import "./mixins/MixinUniswap.sol"; @@ -68,7 +67,6 @@ contract BridgeAdapter is MixinMooniswap, MixinMStable, MixinNerve, - MixinOasis, MixinPlatypus, MixinShell, MixinUniswap, @@ -94,7 +92,6 @@ contract BridgeAdapter is MixinMooniswap(weth) MixinMStable() MixinNerve() - MixinOasis() MixinPlatypus() MixinShell() MixinUniswap(weth) @@ -187,13 +184,6 @@ contract BridgeAdapter is sellAmount, order.bridgeData ); - } else if (protocolId == BridgeProtocols.OASIS) { - boughtAmount = _tradeOasis( - sellToken, - buyToken, - sellAmount, - order.bridgeData - ); } else if (protocolId == BridgeProtocols.SHELL) { boughtAmount = _tradeShell( sellToken, diff --git a/contracts/zero-ex/contracts/src/transformers/bridges/BridgeProtocols.sol b/contracts/zero-ex/contracts/src/transformers/bridges/BridgeProtocols.sol index ea08e6924c..d7ff6914bd 100644 --- a/contracts/zero-ex/contracts/src/transformers/bridges/BridgeProtocols.sol +++ b/contracts/zero-ex/contracts/src/transformers/bridges/BridgeProtocols.sol @@ -32,16 +32,16 @@ library BridgeProtocols { uint128 internal constant UNISWAPV2 = 2; uint128 internal constant UNISWAP = 3; uint128 internal constant BALANCER = 4; - uint128 internal constant KYBER = 5; + uint128 internal constant KYBER = 5; // Not used: deprecated. uint128 internal constant MOONISWAP = 6; uint128 internal constant MSTABLE = 7; - uint128 internal constant OASIS = 8; + uint128 internal constant OASIS = 8; // Not used: deprecated. uint128 internal constant SHELL = 9; uint128 internal constant DODO = 10; uint128 internal constant DODOV2 = 11; uint128 internal constant CRYPTOCOM = 12; uint128 internal constant BANCOR = 13; - uint128 internal constant COFIX = 14; + uint128 internal constant COFIX = 14; // Not used: deprecated. uint128 internal constant NERVE = 15; uint128 internal constant MAKERPSM = 16; uint128 internal constant BALANCERV2 = 17; diff --git a/contracts/zero-ex/contracts/src/transformers/bridges/mixins/MixinCoFiX.sol b/contracts/zero-ex/contracts/src/transformers/bridges/mixins/MixinCoFiX.sol deleted file mode 100644 index 65a8e84b06..0000000000 --- a/contracts/zero-ex/contracts/src/transformers/bridges/mixins/MixinCoFiX.sol +++ /dev/null @@ -1,92 +0,0 @@ -// 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/LibERC20TokenV06.sol"; -import "@0x/contracts-erc20/contracts/src/v06/IERC20TokenV06.sol"; -import "@0x/contracts-erc20/contracts/src/v06/IEtherTokenV06.sol"; - - -interface ICoFiXRouter { - // msg.value = fee - function swapExactTokensForETH( - address token, - uint amountIn, - uint amountOutMin, - address to, - address rewardTo, - uint deadline - ) external payable returns (uint _amountIn, uint _amountOut); - - // msg.value = amountIn + fee - function swapExactETHForTokens( - address token, - uint amountIn, - uint amountOutMin, - address to, - address rewardTo, - uint deadline - ) external payable returns (uint _amountIn, uint _amountOut); -} - -interface ICoFiXPair { - - function swapWithExact(address outToken, address to) - external - payable - returns ( - uint amountIn, - uint amountOut, - uint oracleFeeChange, - uint256[4] memory tradeInfo - ); -} - -contract MixinCoFiX { - - using LibERC20TokenV06 for IERC20TokenV06; - - function _tradeCoFiX( - IERC20TokenV06 sellToken, - IERC20TokenV06 buyToken, - uint256 sellAmount, - bytes memory bridgeData - ) - internal - returns (uint256 boughtAmount) - { - (uint256 fee, ICoFiXPair pool) = abi.decode(bridgeData, (uint256, ICoFiXPair)); - // Transfer tokens into the pool - LibERC20TokenV06.compatTransfer( - sellToken, - address(pool), - sellAmount - ); - // Call the swap exact with the tokens now in the pool - // pay the NEST Oracle fee with ETH - (/* In */, boughtAmount, , ) = pool.swapWithExact{value: fee}( - address(buyToken), - address(this) - ); - - return boughtAmount; - } -} diff --git a/contracts/zero-ex/contracts/src/transformers/bridges/mixins/MixinKyber.sol b/contracts/zero-ex/contracts/src/transformers/bridges/mixins/MixinKyber.sol deleted file mode 100644 index 03bd7df6ab..0000000000 --- a/contracts/zero-ex/contracts/src/transformers/bridges/mixins/MixinKyber.sol +++ /dev/null @@ -1,124 +0,0 @@ -// 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/LibERC20TokenV06.sol"; -import "@0x/contracts-erc20/contracts/src/v06/IERC20TokenV06.sol"; -import "@0x/contracts-erc20/contracts/src/v06/IEtherTokenV06.sol"; -import "../IBridgeAdapter.sol"; - -interface IKyberNetworkProxy { - - /// @dev Sells `sellTokenAddress` tokens for `buyTokenAddress` tokens - /// using a hint for the reserve. - /// @param sellToken Token to sell. - /// @param sellAmount Amount of tokens to sell. - /// @param buyToken Token to buy. - /// @param recipientAddress Address to send bought tokens to. - /// @param maxBuyTokenAmount A limit on the amount of tokens to buy. - /// @param minConversionRate The minimal conversion rate. If actual rate - /// is lower, trade is canceled. - /// @param walletId The wallet ID to send part of the fees - /// @param hint The hint for the selective inclusion (or exclusion) of reserves - /// @return boughtAmount Amount of tokens bought. - function tradeWithHint( - IERC20TokenV06 sellToken, - uint256 sellAmount, - IERC20TokenV06 buyToken, - address payable recipientAddress, - uint256 maxBuyTokenAmount, - uint256 minConversionRate, - address payable walletId, - bytes calldata hint - ) - external - payable - returns (uint256 boughtAmount); -} - -contract MixinKyber { - - using LibERC20TokenV06 for IERC20TokenV06; - - /// @dev Address indicating the trade is using ETH - IERC20TokenV06 private immutable KYBER_ETH_ADDRESS = - IERC20TokenV06(0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE); - /// @dev Mainnet address of the WETH contract. - IEtherTokenV06 private immutable WETH; - - constructor(IEtherTokenV06 weth) - public - { - WETH = weth; - } - - function _tradeKyber( - IERC20TokenV06 sellToken, - IERC20TokenV06 buyToken, - uint256 sellAmount, - bytes memory bridgeData - ) - internal - returns (uint256 boughtAmount) - { - (IKyberNetworkProxy kyber, bytes memory hint) = - abi.decode(bridgeData, (IKyberNetworkProxy, bytes)); - - uint256 payableAmount = 0; - if (sellToken != WETH) { - // If the input token is not WETH, grant an allowance to the exchange - // to spend them. - sellToken.approveIfBelow( - address(kyber), - sellAmount - ); - } else { - // If the input token is WETH, unwrap it and attach it to the call. - payableAmount = sellAmount; - WETH.withdraw(payableAmount); - } - - // Try to sell all of this contract's input token balance through - // `KyberNetworkProxy.trade()`. - boughtAmount = kyber.tradeWithHint{ value: payableAmount }( - // Input token. - sellToken == WETH ? KYBER_ETH_ADDRESS : sellToken, - // Sell amount. - sellAmount, - // Output token. - buyToken == WETH ? KYBER_ETH_ADDRESS : buyToken, - // Transfer to this contract - address(uint160(address(this))), - // Buy as much as possible. - uint256(-1), - // Lowest minimum conversion rate - 1, - // No affiliate address. - address(0), - hint - ); - // If receving ETH, wrap it to WETH. - if (buyToken == WETH) { - WETH.deposit{ value: boughtAmount }(); - } - return boughtAmount; - } -} diff --git a/contracts/zero-ex/contracts/src/transformers/bridges/mixins/MixinOasis.sol b/contracts/zero-ex/contracts/src/transformers/bridges/mixins/MixinOasis.sol deleted file mode 100644 index 544b750156..0000000000 --- a/contracts/zero-ex/contracts/src/transformers/bridges/mixins/MixinOasis.sol +++ /dev/null @@ -1,76 +0,0 @@ -// 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/LibERC20TokenV06.sol"; -import "@0x/contracts-erc20/contracts/src/v06/IERC20TokenV06.sol"; -import "../IBridgeAdapter.sol"; - -interface IOasis { - - /// @dev Sell `sellAmount` of `sellToken` token and receive `buyToken` token. - /// @param sellToken The token being sold. - /// @param sellAmount The amount of `sellToken` token being sold. - /// @param buyToken The token being bought. - /// @param minBoughtAmount Minimum amount of `buyToken` token to buy. - /// @return boughtAmount Amount of `buyToken` bought. - function sellAllAmount( - IERC20TokenV06 sellToken, - uint256 sellAmount, - IERC20TokenV06 buyToken, - uint256 minBoughtAmount - ) - external - returns (uint256 boughtAmount); -} - -contract MixinOasis { - - using LibERC20TokenV06 for IERC20TokenV06; - - function _tradeOasis( - IERC20TokenV06 sellToken, - IERC20TokenV06 buyToken, - uint256 sellAmount, - bytes memory bridgeData - ) - internal - returns (uint256 boughtAmount) - { - - (IOasis oasis) = abi.decode(bridgeData, (IOasis)); - - // Grant an allowance to the exchange to spend `sellToken` token. - sellToken.approveIfBelow( - address(oasis), - sellAmount - ); - // Try to sell all of this contract's `sellToken` token balance. - boughtAmount = oasis.sellAllAmount( - sellToken, - sellAmount, - buyToken, - // min fill amount - 1 - ); - return boughtAmount; - } -} diff --git a/contracts/zero-ex/package.json b/contracts/zero-ex/package.json index e1ca11a65b..b5ba12b808 100644 --- a/contracts/zero-ex/package.json +++ b/contracts/zero-ex/package.json @@ -43,7 +43,7 @@ "config": { "publicInterfaceContracts": "IZeroEx,ZeroEx,FullMigration,InitialMigration,IFlashWallet,IERC20Transformer,IOwnableFeature,ISimpleFunctionRegistryFeature,ITransformERC20Feature,FillQuoteTransformer,PayTakerTransformer,PositiveSlippageFeeTransformer,WethTransformer,OwnableFeature,SimpleFunctionRegistryFeature,TransformERC20Feature,AffiliateFeeTransformer,MetaTransactionsFeature,LogMetadataTransformer,BridgeAdapter,LiquidityProviderFeature,ILiquidityProviderFeature,NativeOrdersFeature,INativeOrdersFeature,FeeCollectorController,FeeCollector,CurveLiquidityProvider,BatchFillNativeOrdersFeature,IBatchFillNativeOrdersFeature,MultiplexFeature,IMultiplexFeature,OtcOrdersFeature,IOtcOrdersFeature", "abis:comment": "This list is auto-generated by contracts-gen. Don't edit manually.", - "abis": "./test/generated-artifacts/@(AffiliateFeeTransformer|BatchFillNativeOrdersFeature|BootstrapFeature|BridgeAdapter|BridgeProtocols|CurveLiquidityProvider|ERC1155OrdersFeature|ERC165Feature|ERC721OrdersFeature|FeeCollector|FeeCollectorController|FillQuoteTransformer|FixinCommon|FixinEIP712|FixinERC1155Spender|FixinERC721Spender|FixinProtocolFees|FixinReentrancyGuard|FixinTokenSpender|FlashWallet|FullMigration|FundRecoveryFeature|IBatchFillNativeOrdersFeature|IBootstrapFeature|IBridgeAdapter|IERC1155OrdersFeature|IERC1155Token|IERC165Feature|IERC20Bridge|IERC20Transformer|IERC721OrdersFeature|IERC721Token|IFeature|IFeeRecipient|IFlashWallet|IFundRecoveryFeature|ILiquidityProvider|ILiquidityProviderFeature|ILiquidityProviderSandbox|IMetaTransactionsFeature|IMooniswapPool|IMultiplexFeature|INativeOrdersEvents|INativeOrdersFeature|IOtcOrdersFeature|IOwnableFeature|IPancakeSwapFeature|IPropertyValidator|ISimpleFunctionRegistryFeature|IStaking|ITakerCallback|ITestSimpleFunctionRegistryFeature|ITokenSpenderFeature|ITransformERC20Feature|IUniswapFeature|IUniswapV2Pair|IUniswapV3Feature|IUniswapV3Pool|IZeroEx|InitialMigration|LibBootstrap|LibCommonRichErrors|LibERC1155OrdersStorage|LibERC20Transformer|LibERC721OrdersStorage|LibFeeCollector|LibLiquidityProviderRichErrors|LibMetaTransactionsRichErrors|LibMetaTransactionsStorage|LibMigrate|LibNFTOrder|LibNFTOrdersRichErrors|LibNativeOrder|LibNativeOrdersRichErrors|LibNativeOrdersStorage|LibOtcOrdersStorage|LibOwnableRichErrors|LibOwnableStorage|LibProxyRichErrors|LibProxyStorage|LibReentrancyGuardStorage|LibSignature|LibSignatureRichErrors|LibSimpleFunctionRegistryRichErrors|LibSimpleFunctionRegistryStorage|LibStorage|LibTransformERC20RichErrors|LibTransformERC20Storage|LibWalletRichErrors|LiquidityProviderFeature|LiquidityProviderSandbox|LogMetadataTransformer|MetaTransactionsFeature|MixinAaveV2|MixinBalancer|MixinBalancerV2|MixinBalancerV2Batch|MixinBancor|MixinCoFiX|MixinCompound|MixinCryptoCom|MixinCurve|MixinCurveV2|MixinDodo|MixinDodoV2|MixinGMX|MixinKyber|MixinKyberDmm|MixinLido|MixinMStable|MixinMakerPSM|MixinMooniswap|MixinNerve|MixinOasis|MixinPlatypus|MixinShell|MixinUniswap|MixinUniswapV2|MixinUniswapV3|MixinZeroExBridge|MooniswapLiquidityProvider|MultiplexFeature|MultiplexLiquidityProvider|MultiplexOtc|MultiplexRfq|MultiplexTransformERC20|MultiplexUniswapV2|MultiplexUniswapV3|NFTOrders|NativeOrdersCancellation|NativeOrdersFeature|NativeOrdersInfo|NativeOrdersProtocolFees|NativeOrdersSettlement|OtcOrdersFeature|OwnableFeature|PancakeSwapFeature|PayTakerTransformer|PermissionlessTransformerDeployer|PositiveSlippageFeeTransformer|SimpleFunctionRegistryFeature|TestBridge|TestCallTarget|TestCurve|TestDelegateCaller|TestFeeCollectorController|TestFeeRecipient|TestFillQuoteTransformerBridge|TestFillQuoteTransformerExchange|TestFillQuoteTransformerHost|TestFixinProtocolFees|TestFixinTokenSpender|TestFullMigration|TestInitialMigration|TestLibNativeOrder|TestLibSignature|TestLiquidityProvider|TestMetaTransactionsNativeOrdersFeature|TestMetaTransactionsTransformERC20Feature|TestMigrator|TestMintTokenERC20Transformer|TestMintableERC1155Token|TestMintableERC20Token|TestMintableERC721Token|TestMooniswap|TestNFTOrderPresigner|TestNativeOrdersFeature|TestNoEthRecipient|TestOrderSignerRegistryWithContractWallet|TestPermissionlessTransformerDeployerSuicidal|TestPermissionlessTransformerDeployerTransformer|TestPropertyValidator|TestRfqOriginRegistration|TestSimpleFunctionRegistryFeatureImpl1|TestSimpleFunctionRegistryFeatureImpl2|TestStaking|TestTokenSpenderERC20Token|TestTransformERC20|TestTransformerBase|TestTransformerDeployerTransformer|TestTransformerHost|TestUniswapV2Factory|TestUniswapV2Pool|TestUniswapV3Factory|TestUniswapV3Feature|TestUniswapV3Pool|TestWeth|TestWethTransformerHost|TestZeroExFeature|TransformERC20Feature|Transformer|TransformerDeployer|UniswapFeature|UniswapV3Feature|WethTransformer|ZeroEx|ZeroExOptimized).json" + "abis": "./test/generated-artifacts/@(AffiliateFeeTransformer|BatchFillNativeOrdersFeature|BootstrapFeature|BridgeAdapter|BridgeProtocols|CurveLiquidityProvider|ERC1155OrdersFeature|ERC165Feature|ERC721OrdersFeature|FeeCollector|FeeCollectorController|FillQuoteTransformer|FixinCommon|FixinEIP712|FixinERC1155Spender|FixinERC721Spender|FixinProtocolFees|FixinReentrancyGuard|FixinTokenSpender|FlashWallet|FullMigration|FundRecoveryFeature|IBatchFillNativeOrdersFeature|IBootstrapFeature|IBridgeAdapter|IERC1155OrdersFeature|IERC1155Token|IERC165Feature|IERC20Bridge|IERC20Transformer|IERC721OrdersFeature|IERC721Token|IFeature|IFeeRecipient|IFlashWallet|IFundRecoveryFeature|ILiquidityProvider|ILiquidityProviderFeature|ILiquidityProviderSandbox|IMetaTransactionsFeature|IMooniswapPool|IMultiplexFeature|INativeOrdersEvents|INativeOrdersFeature|IOtcOrdersFeature|IOwnableFeature|IPancakeSwapFeature|IPropertyValidator|ISimpleFunctionRegistryFeature|IStaking|ITakerCallback|ITestSimpleFunctionRegistryFeature|ITokenSpenderFeature|ITransformERC20Feature|IUniswapFeature|IUniswapV2Pair|IUniswapV3Feature|IUniswapV3Pool|IZeroEx|InitialMigration|LibBootstrap|LibCommonRichErrors|LibERC1155OrdersStorage|LibERC20Transformer|LibERC721OrdersStorage|LibFeeCollector|LibLiquidityProviderRichErrors|LibMetaTransactionsRichErrors|LibMetaTransactionsStorage|LibMigrate|LibNFTOrder|LibNFTOrdersRichErrors|LibNativeOrder|LibNativeOrdersRichErrors|LibNativeOrdersStorage|LibOtcOrdersStorage|LibOwnableRichErrors|LibOwnableStorage|LibProxyRichErrors|LibProxyStorage|LibReentrancyGuardStorage|LibSignature|LibSignatureRichErrors|LibSimpleFunctionRegistryRichErrors|LibSimpleFunctionRegistryStorage|LibStorage|LibTransformERC20RichErrors|LibTransformERC20Storage|LibWalletRichErrors|LiquidityProviderFeature|LiquidityProviderSandbox|LogMetadataTransformer|MetaTransactionsFeature|MixinAaveV2|MixinBalancer|MixinBalancerV2|MixinBalancerV2Batch|MixinBancor|MixinCompound|MixinCryptoCom|MixinCurve|MixinCurveV2|MixinDodo|MixinDodoV2|MixinGMX|MixinKyberDmm|MixinLido|MixinMStable|MixinMakerPSM|MixinMooniswap|MixinNerve|MixinPlatypus|MixinShell|MixinUniswap|MixinUniswapV2|MixinUniswapV3|MixinZeroExBridge|MooniswapLiquidityProvider|MultiplexFeature|MultiplexLiquidityProvider|MultiplexOtc|MultiplexRfq|MultiplexTransformERC20|MultiplexUniswapV2|MultiplexUniswapV3|NFTOrders|NativeOrdersCancellation|NativeOrdersFeature|NativeOrdersInfo|NativeOrdersProtocolFees|NativeOrdersSettlement|OtcOrdersFeature|OwnableFeature|PancakeSwapFeature|PayTakerTransformer|PermissionlessTransformerDeployer|PositiveSlippageFeeTransformer|SimpleFunctionRegistryFeature|TestBridge|TestCallTarget|TestCurve|TestDelegateCaller|TestFeeCollectorController|TestFeeRecipient|TestFillQuoteTransformerBridge|TestFillQuoteTransformerExchange|TestFillQuoteTransformerHost|TestFixinProtocolFees|TestFixinTokenSpender|TestFullMigration|TestInitialMigration|TestLibNativeOrder|TestLibSignature|TestLiquidityProvider|TestMetaTransactionsNativeOrdersFeature|TestMetaTransactionsTransformERC20Feature|TestMigrator|TestMintTokenERC20Transformer|TestMintableERC1155Token|TestMintableERC20Token|TestMintableERC721Token|TestMooniswap|TestNFTOrderPresigner|TestNativeOrdersFeature|TestNoEthRecipient|TestOrderSignerRegistryWithContractWallet|TestPermissionlessTransformerDeployerSuicidal|TestPermissionlessTransformerDeployerTransformer|TestPropertyValidator|TestRfqOriginRegistration|TestSimpleFunctionRegistryFeatureImpl1|TestSimpleFunctionRegistryFeatureImpl2|TestStaking|TestTokenSpenderERC20Token|TestTransformERC20|TestTransformerBase|TestTransformerDeployerTransformer|TestTransformerHost|TestUniswapV2Factory|TestUniswapV2Pool|TestUniswapV3Factory|TestUniswapV3Feature|TestUniswapV3Pool|TestWeth|TestWethTransformerHost|TestZeroExFeature|TransformERC20Feature|Transformer|TransformerDeployer|UniswapFeature|UniswapV3Feature|WethTransformer|ZeroEx|ZeroExOptimized).json" }, "repository": { "type": "git", diff --git a/contracts/zero-ex/test/artifacts.ts b/contracts/zero-ex/test/artifacts.ts index 205e1146ce..98e3786634 100644 --- a/contracts/zero-ex/test/artifacts.ts +++ b/contracts/zero-ex/test/artifacts.ts @@ -103,7 +103,6 @@ import * as MixinBalancer from '../test/generated-artifacts/MixinBalancer.json'; import * as MixinBalancerV2 from '../test/generated-artifacts/MixinBalancerV2.json'; import * as MixinBalancerV2Batch from '../test/generated-artifacts/MixinBalancerV2Batch.json'; import * as MixinBancor from '../test/generated-artifacts/MixinBancor.json'; -import * as MixinCoFiX from '../test/generated-artifacts/MixinCoFiX.json'; import * as MixinCompound from '../test/generated-artifacts/MixinCompound.json'; import * as MixinCryptoCom from '../test/generated-artifacts/MixinCryptoCom.json'; import * as MixinCurve from '../test/generated-artifacts/MixinCurve.json'; @@ -111,14 +110,12 @@ import * as MixinCurveV2 from '../test/generated-artifacts/MixinCurveV2.json'; import * as MixinDodo from '../test/generated-artifacts/MixinDodo.json'; import * as MixinDodoV2 from '../test/generated-artifacts/MixinDodoV2.json'; import * as MixinGMX from '../test/generated-artifacts/MixinGMX.json'; -import * as MixinKyber from '../test/generated-artifacts/MixinKyber.json'; import * as MixinKyberDmm from '../test/generated-artifacts/MixinKyberDmm.json'; import * as MixinLido from '../test/generated-artifacts/MixinLido.json'; import * as MixinMakerPSM from '../test/generated-artifacts/MixinMakerPSM.json'; import * as MixinMooniswap from '../test/generated-artifacts/MixinMooniswap.json'; import * as MixinMStable from '../test/generated-artifacts/MixinMStable.json'; import * as MixinNerve from '../test/generated-artifacts/MixinNerve.json'; -import * as MixinOasis from '../test/generated-artifacts/MixinOasis.json'; import * as MixinPlatypus from '../test/generated-artifacts/MixinPlatypus.json'; import * as MixinShell from '../test/generated-artifacts/MixinShell.json'; import * as MixinUniswap from '../test/generated-artifacts/MixinUniswap.json'; @@ -318,7 +315,6 @@ export const artifacts = { MixinBalancerV2: MixinBalancerV2 as ContractArtifact, MixinBalancerV2Batch: MixinBalancerV2Batch as ContractArtifact, MixinBancor: MixinBancor as ContractArtifact, - MixinCoFiX: MixinCoFiX as ContractArtifact, MixinCompound: MixinCompound as ContractArtifact, MixinCryptoCom: MixinCryptoCom as ContractArtifact, MixinCurve: MixinCurve as ContractArtifact, @@ -326,14 +322,12 @@ export const artifacts = { MixinDodo: MixinDodo as ContractArtifact, MixinDodoV2: MixinDodoV2 as ContractArtifact, MixinGMX: MixinGMX as ContractArtifact, - MixinKyber: MixinKyber as ContractArtifact, MixinKyberDmm: MixinKyberDmm as ContractArtifact, MixinLido: MixinLido as ContractArtifact, MixinMStable: MixinMStable as ContractArtifact, MixinMakerPSM: MixinMakerPSM as ContractArtifact, MixinMooniswap: MixinMooniswap as ContractArtifact, MixinNerve: MixinNerve as ContractArtifact, - MixinOasis: MixinOasis as ContractArtifact, MixinPlatypus: MixinPlatypus as ContractArtifact, MixinShell: MixinShell as ContractArtifact, MixinUniswap: MixinUniswap as ContractArtifact, diff --git a/contracts/zero-ex/test/wrappers.ts b/contracts/zero-ex/test/wrappers.ts index 6ef4c9246d..4590c9149f 100644 --- a/contracts/zero-ex/test/wrappers.ts +++ b/contracts/zero-ex/test/wrappers.ts @@ -101,7 +101,6 @@ export * from '../test/generated-wrappers/mixin_balancer'; export * from '../test/generated-wrappers/mixin_balancer_v2'; export * from '../test/generated-wrappers/mixin_balancer_v2_batch'; export * from '../test/generated-wrappers/mixin_bancor'; -export * from '../test/generated-wrappers/mixin_co_fi_x'; export * from '../test/generated-wrappers/mixin_compound'; export * from '../test/generated-wrappers/mixin_crypto_com'; export * from '../test/generated-wrappers/mixin_curve'; @@ -109,14 +108,12 @@ export * from '../test/generated-wrappers/mixin_curve_v2'; export * from '../test/generated-wrappers/mixin_dodo'; export * from '../test/generated-wrappers/mixin_dodo_v2'; export * from '../test/generated-wrappers/mixin_g_m_x'; -export * from '../test/generated-wrappers/mixin_kyber'; export * from '../test/generated-wrappers/mixin_kyber_dmm'; export * from '../test/generated-wrappers/mixin_lido'; export * from '../test/generated-wrappers/mixin_m_stable'; export * from '../test/generated-wrappers/mixin_maker_p_s_m'; export * from '../test/generated-wrappers/mixin_mooniswap'; export * from '../test/generated-wrappers/mixin_nerve'; -export * from '../test/generated-wrappers/mixin_oasis'; export * from '../test/generated-wrappers/mixin_platypus'; export * from '../test/generated-wrappers/mixin_shell'; export * from '../test/generated-wrappers/mixin_uniswap'; diff --git a/contracts/zero-ex/tsconfig.json b/contracts/zero-ex/tsconfig.json index d054207ffd..e5cd44a9ba 100644 --- a/contracts/zero-ex/tsconfig.json +++ b/contracts/zero-ex/tsconfig.json @@ -134,7 +134,6 @@ "test/generated-artifacts/MixinBalancerV2.json", "test/generated-artifacts/MixinBalancerV2Batch.json", "test/generated-artifacts/MixinBancor.json", - "test/generated-artifacts/MixinCoFiX.json", "test/generated-artifacts/MixinCompound.json", "test/generated-artifacts/MixinCryptoCom.json", "test/generated-artifacts/MixinCurve.json", @@ -142,14 +141,12 @@ "test/generated-artifacts/MixinDodo.json", "test/generated-artifacts/MixinDodoV2.json", "test/generated-artifacts/MixinGMX.json", - "test/generated-artifacts/MixinKyber.json", "test/generated-artifacts/MixinKyberDmm.json", "test/generated-artifacts/MixinLido.json", "test/generated-artifacts/MixinMStable.json", "test/generated-artifacts/MixinMakerPSM.json", "test/generated-artifacts/MixinMooniswap.json", "test/generated-artifacts/MixinNerve.json", - "test/generated-artifacts/MixinOasis.json", "test/generated-artifacts/MixinPlatypus.json", "test/generated-artifacts/MixinShell.json", "test/generated-artifacts/MixinUniswap.json", diff --git a/packages/asset-swapper/CHANGELOG.json b/packages/asset-swapper/CHANGELOG.json index 4376baf36e..a884063ddb 100644 --- a/packages/asset-swapper/CHANGELOG.json +++ b/packages/asset-swapper/CHANGELOG.json @@ -1,4 +1,13 @@ [ + { + "version": "16.61.0", + "changes": [ + { + "note": "Offboard/clean up Oasis, CoFix, and legacy Kyber", + "pr": 482 + } + ] + }, { "version": "16.60.1", "changes": [ diff --git a/packages/asset-swapper/contracts/src/ERC20BridgeSampler.sol b/packages/asset-swapper/contracts/src/ERC20BridgeSampler.sol index 3cebb98f87..6c7304d305 100644 --- a/packages/asset-swapper/contracts/src/ERC20BridgeSampler.sol +++ b/packages/asset-swapper/contracts/src/ERC20BridgeSampler.sol @@ -29,7 +29,6 @@ import "./CurveSampler.sol"; import "./DODOSampler.sol"; import "./DODOV2Sampler.sol"; import "./GMXSampler.sol"; -import "./KyberSampler.sol"; import "./KyberDmmSampler.sol"; import "./LidoSampler.sol"; import "./LiquidityProviderSampler.sol"; @@ -57,7 +56,6 @@ contract ERC20BridgeSampler is DODOSampler, DODOV2Sampler, GMXSampler, - KyberSampler, KyberDmmSampler, LidoSampler, LiquidityProviderSampler, diff --git a/packages/asset-swapper/contracts/src/KyberSampler.sol b/packages/asset-swapper/contracts/src/KyberSampler.sol deleted file mode 100644 index 17c91cc8f7..0000000000 --- a/packages/asset-swapper/contracts/src/KyberSampler.sol +++ /dev/null @@ -1,301 +0,0 @@ -// 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; -pragma experimental ABIEncoderV2; - -import "./interfaces/IKyberNetwork.sol"; -import "./ApproximateBuys.sol"; -import "./SamplerUtils.sol"; - - -contract KyberSampler is - SamplerUtils, - ApproximateBuys -{ - /// @dev Gas limit for Kyber calls. - uint256 constant private KYBER_CALL_GAS = 500e3; // 500k - /// @dev Kyber ETH pseudo-address. - address constant internal KYBER_ETH_ADDRESS = 0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE; - - struct KyberSamplerOpts { - uint256 reserveOffset; - address hintHandler; - address networkProxy; - address weth; - bytes hint; - } - - /// @dev Sample sell quotes from Kyber. - /// @param opts KyberSamplerOpts The nth reserve - /// @param takerToken Address of the taker token (what to sell). - /// @param makerToken Address of the maker token (what to buy). - /// @param takerTokenAmounts Taker token sell amount for each sample. - /// @return reserveId The id of the reserve found at reserveOffset - /// @return hint The hint for the selected reserve - /// @return makerTokenAmounts Maker amounts bought at each taker token amount. - function sampleSellsFromKyberNetwork( - KyberSamplerOpts memory opts, - address takerToken, - address makerToken, - uint256[] memory takerTokenAmounts - ) - public - view - returns (bytes32 reserveId, bytes memory hint, uint256[] memory makerTokenAmounts) - { - _assertValidPair(makerToken, takerToken); - reserveId = _getNextReserveId(opts, takerToken, makerToken); - if (reserveId == 0x0) { - return (reserveId, hint, makerTokenAmounts); - } - opts.hint = this.encodeKyberHint(opts, reserveId, takerToken, makerToken); - hint = opts.hint; - - uint256 numSamples = takerTokenAmounts.length; - makerTokenAmounts = new uint256[](numSamples); - for (uint256 i = 0; i < numSamples; i++) { - uint256 value = this.sampleSellFromKyberNetwork( - opts, - takerToken, - makerToken, - takerTokenAmounts[i] - ); - makerTokenAmounts[i] = value; - // Break early if there are 0 amounts - if (makerTokenAmounts[i] == 0) { - break; - } - } - } - - /// @dev Sample buy quotes from Kyber. - /// @param opts KyberSamplerOpts The nth reserve - /// @param takerToken Address of the taker token (what to sell). - /// @param makerToken Address of the maker token (what to buy). - /// @param makerTokenAmounts Maker token buy amount for each sample. - /// @return reserveId The id of the reserve found at reserveOffset - /// @return hint The hint for the selected reserve - /// @return takerTokenAmounts Taker amounts sold at each maker token amount. - function sampleBuysFromKyberNetwork( - KyberSamplerOpts memory opts, - address takerToken, - address makerToken, - uint256[] memory makerTokenAmounts - ) - public - view - returns (bytes32 reserveId, bytes memory hint, uint256[] memory takerTokenAmounts) - { - _assertValidPair(makerToken, takerToken); - - reserveId = _getNextReserveId(opts, takerToken, makerToken); - if (reserveId == 0x0) { - return (reserveId, hint, takerTokenAmounts); - } - opts.hint = this.encodeKyberHint(opts, reserveId, takerToken, makerToken); - hint = opts.hint; - - takerTokenAmounts = _sampleApproximateBuys( - ApproximateBuyQuoteOpts({ - makerTokenData: abi.encode(makerToken, opts), - takerTokenData: abi.encode(takerToken, opts), - getSellQuoteCallback: _sampleSellForApproximateBuyFromKyber - }), - makerTokenAmounts - ); - return (reserveId, hint, takerTokenAmounts); - } - - function encodeKyberHint( - KyberSamplerOpts memory opts, - bytes32 reserveId, - address takerToken, - address makerToken - ) - public - view - returns (bytes memory hint) - { - // Build a hint selecting the single reserve - IKyberHintHandler kyberHint = IKyberHintHandler(opts.hintHandler); - - // All other reserves should be ignored with this hint - bytes32[] memory selectedReserves = new bytes32[](1); - selectedReserves[0] = reserveId; - uint256[] memory emptySplits = new uint256[](0); - - if (takerToken == opts.weth) { - // ETH to Token - try - kyberHint.buildEthToTokenHint - {gas: KYBER_CALL_GAS} - ( - makerToken, - IKyberHintHandler.TradeType.MaskIn, - selectedReserves, - emptySplits - ) - returns (bytes memory result) - { - return result; - } catch (bytes memory) { - // Swallow failures, leaving all results as zero. - } - } else if (makerToken == opts.weth) { - // Token to ETH - try - kyberHint.buildTokenToEthHint - {gas: KYBER_CALL_GAS} - ( - takerToken, - IKyberHintHandler.TradeType.MaskIn, - selectedReserves, - emptySplits - ) - returns (bytes memory result) - { - return result; - } catch (bytes memory) { - // Swallow failures, leaving all results as zero. - } - - } else { - // Token to Token - // We use the same reserve both ways - try - kyberHint.buildTokenToTokenHint - {gas: KYBER_CALL_GAS} - ( - takerToken, - IKyberHintHandler.TradeType.MaskIn, - selectedReserves, - emptySplits, - makerToken, - IKyberHintHandler.TradeType.MaskIn, - selectedReserves, - emptySplits - ) - returns (bytes memory result) - { - return result; - } catch (bytes memory) { - // Swallow failures, leaving all results as zero. - } - } - } - - function _sampleSellForApproximateBuyFromKyber( - bytes memory takerTokenData, - bytes memory makerTokenData, - uint256 sellAmount - ) - private - view - returns (uint256) - { - (address makerToken, KyberSamplerOpts memory opts) = - abi.decode(makerTokenData, (address, KyberSamplerOpts)); - (address takerToken, ) = - abi.decode(takerTokenData, (address, KyberSamplerOpts)); - try - this.sampleSellFromKyberNetwork - (opts, takerToken, makerToken, sellAmount) - returns (uint256 amount) - { - return amount; - } catch (bytes memory) { - // Swallow failures, leaving all results as zero. - return 0; - } - } - - function sampleSellFromKyberNetwork( - KyberSamplerOpts memory opts, - address takerToken, - address makerToken, - uint256 takerTokenAmount - ) - public - view - returns (uint256 makerTokenAmount) - { - // If there is no hint do not continue - if (opts.hint.length == 0) { - return 0; - } - - try - IKyberNetworkProxy(opts.networkProxy).getExpectedRateAfterFee - {gas: KYBER_CALL_GAS} - ( - takerToken == opts.weth ? KYBER_ETH_ADDRESS : takerToken, - makerToken == opts.weth ? KYBER_ETH_ADDRESS : makerToken, - takerTokenAmount, - 0, // fee - opts.hint - ) - returns (uint256 rate) - { - uint256 makerTokenDecimals = _getTokenDecimals(makerToken); - uint256 takerTokenDecimals = _getTokenDecimals(takerToken); - makerTokenAmount = - rate * - takerTokenAmount * - 10 ** makerTokenDecimals / - 10 ** takerTokenDecimals / - 10 ** 18; - return makerTokenAmount; - } catch (bytes memory) { - // Swallow failures, leaving all results as zero. - return 0; - } - } - - function _getNextReserveId( - KyberSamplerOpts memory opts, - address takerToken, - address makerToken - ) - internal - view - returns (bytes32 reserveId) - { - // Fetch the registered reserves for this pair - IKyberHintHandler kyberHint = IKyberHintHandler(opts.hintHandler); - (bytes32[] memory reserveIds, ,) = kyberHint.getTradingReserves( - takerToken == opts.weth ? KYBER_ETH_ADDRESS : takerToken, - makerToken == opts.weth ? KYBER_ETH_ADDRESS : makerToken, - true, - new bytes(0) // empty hint - ); - - if (opts.reserveOffset >= reserveIds.length) { - return 0x0; - } - - reserveId = reserveIds[opts.reserveOffset]; - // Ignore Kyber Bridged Reserves (0xbb) - if (uint256(reserveId >> 248) == 0xbb) { - return 0x0; - } - - return reserveId; - } -} diff --git a/packages/asset-swapper/contracts/src/interfaces/IKyberNetwork.sol b/packages/asset-swapper/contracts/src/interfaces/IKyberNetwork.sol deleted file mode 100644 index 7e9dcc9044..0000000000 --- a/packages/asset-swapper/contracts/src/interfaces/IKyberNetwork.sol +++ /dev/null @@ -1,96 +0,0 @@ -// 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; - -// Keepin everything together -interface IKyberNetwork { - - -} - - -interface IKyberNetworkProxy { - - function getExpectedRateAfterFee( - address src, - address dest, - uint256 srcQty, - uint256 platformFeeBps, - bytes calldata hint - ) - external - view - returns (uint256 expectedRate); -} - -interface IKyberHintHandler { - - enum TradeType {BestOfAll, MaskIn, MaskOut, Split} - - enum ProcessWithRate {NotRequired, Required} - - function getTradingReserves( - address tokenSrc, - address tokenDest, - bool isTokenToToken, - bytes calldata hint - ) - external - view - returns ( - bytes32[] memory reserveIds, - uint256[] memory splitValuesBps, - ProcessWithRate processWithRate - ); - - function buildTokenToEthHint( - address tokenSrc, - TradeType tokenToEthType, - bytes32[] calldata tokenToEthReserveIds, - uint256[] calldata tokenToEthSplits - ) - external - view - returns (bytes memory hint); - - function buildEthToTokenHint( - address tokenDest, - TradeType ethToTokenType, - bytes32[] calldata ethToTokenReserveIds, - uint256[] calldata ethToTokenSplits - ) - external - view - returns (bytes memory hint); - - function buildTokenToTokenHint( - address tokenSrc, - TradeType tokenToEthType, - bytes32[] calldata tokenToEthReserveIds, - uint256[] calldata tokenToEthSplits, - address tokenDest, - TradeType ethToTokenType, - bytes32[] calldata ethToTokenReserveIds, - uint256[] calldata ethToTokenSplits - ) - external - view - returns (bytes memory hint); -} diff --git a/packages/asset-swapper/package.json b/packages/asset-swapper/package.json index ab38c73d24..0323e39178 100644 --- a/packages/asset-swapper/package.json +++ b/packages/asset-swapper/package.json @@ -39,7 +39,7 @@ "config": { "publicInterfaceContracts": "ERC20BridgeSampler,BalanceChecker,FakeTaker", "abis:comment": "This list is auto-generated by contracts-gen. Don't edit manually.", - "abis": "./test/generated-artifacts/@(ApproximateBuys|BalanceChecker|BalancerSampler|BalancerV2BatchSampler|BalancerV2Common|BalancerV2Sampler|BancorSampler|CompoundSampler|CurveSampler|DODOSampler|DODOV2Sampler|ERC20BridgeSampler|FakeTaker|GMXSampler|IBalancer|IBalancerV2Vault|IBancor|ICurve|IGMX|IKyberNetwork|IMStable|IMooniswap|IMultiBridge|IPlatypus|IShell|ISmoothy|IUniswapExchangeQuotes|IUniswapV2Router01|KyberDmmSampler|KyberSampler|LidoSampler|LiquidityProviderSampler|MStableSampler|MakerPSMSampler|MooniswapSampler|NativeOrderSampler|PlatypusSampler|SamplerUtils|ShellSampler|SmoothySampler|TestNativeOrderSampler|TwoHopSampler|UniswapSampler|UniswapV2Sampler|UniswapV3Sampler|UtilitySampler).json", + "abis": "./test/generated-artifacts/@(ApproximateBuys|BalanceChecker|BalancerSampler|BalancerV2BatchSampler|BalancerV2Common|BalancerV2Sampler|BancorSampler|CompoundSampler|CurveSampler|DODOSampler|DODOV2Sampler|ERC20BridgeSampler|FakeTaker|GMXSampler|IBalancer|IBalancerV2Vault|IBancor|ICurve|IGMX|IMStable|IMooniswap|IMultiBridge|IPlatypus|IShell|ISmoothy|IUniswapExchangeQuotes|IUniswapV2Router01|KyberDmmSampler|LidoSampler|LiquidityProviderSampler|MStableSampler|MakerPSMSampler|MooniswapSampler|NativeOrderSampler|PlatypusSampler|SamplerUtils|ShellSampler|SmoothySampler|TestNativeOrderSampler|TwoHopSampler|UniswapSampler|UniswapV2Sampler|UniswapV3Sampler|UtilitySampler).json", "postpublish": { "assets": [] } diff --git a/packages/asset-swapper/src/index.ts b/packages/asset-swapper/src/index.ts index adddb13bd6..c13b2d942e 100644 --- a/packages/asset-swapper/src/index.ts +++ b/packages/asset-swapper/src/index.ts @@ -153,7 +153,6 @@ export { Fill, FillData, GetMarketOrdersRfqOpts, - KyberFillData, LiquidityProviderFillData, LiquidityProviderRegistry, MarketDepth, diff --git a/packages/asset-swapper/src/utils/market_operation_utils/bridge_source_utils.ts b/packages/asset-swapper/src/utils/market_operation_utils/bridge_source_utils.ts index 189f8cfaf1..82af9bafd0 100644 --- a/packages/asset-swapper/src/utils/market_operation_utils/bridge_source_utils.ts +++ b/packages/asset-swapper/src/utils/market_operation_utils/bridge_source_utils.ts @@ -1,5 +1,5 @@ import { ChainId } from '@0x/contract-addresses'; -import { BigNumber, NULL_BYTES } from '@0x/utils'; +import { BigNumber } from '@0x/utils'; import { ACRYPTOS_BSC_INFOS, @@ -28,10 +28,7 @@ import { IRONSWAP_POLYGON_INFOS, JETSWAP_ROUTER_BY_CHAIN_ID, JULSWAP_ROUTER_BY_CHAIN_ID, - KYBER_BANNED_RESERVES, - KYBER_BRIDGED_LIQUIDITY_PREFIX, MAX_DODOV2_POOLS_QUERIED, - MAX_KYBER_RESERVES_QUERIED, MOBIUSMONEY_CELO_INFOS, MORPHEUSSWAP_ROUTER_BY_CHAIN_ID, MSTABLE_POOLS_BY_CHAIN_ID, @@ -66,32 +63,11 @@ import { } from './constants'; import { CurveInfo, ERC20BridgeSource, PlatypusInfo } from './types'; -/** - * Filter Kyber reserves which should not be used (0xbb bridged reserves) - * @param reserveId Kyber reserveId - */ -export function isAllowedKyberReserveId(reserveId: string): boolean { - return ( - reserveId !== NULL_BYTES && - !reserveId.startsWith(KYBER_BRIDGED_LIQUIDITY_PREFIX) && - !KYBER_BANNED_RESERVES.includes(reserveId) - ); -} - // tslint:disable-next-line: completed-docs ban-types export function isValidAddress(address: string | String): address is string { return (typeof address === 'string' || address instanceof String) && address.toString() !== NULL_ADDRESS; } -/** - * Returns the offsets to be used to discover Kyber reserves - */ -export function getKyberOffsets(): BigNumber[] { - return Array(MAX_KYBER_RESERVES_QUERIED) - .fill(0) - .map((_v, i) => new BigNumber(i)); -} - // tslint:disable completed-docs export function getDodoV2Offsets(): BigNumber[] { return Array(MAX_DODOV2_POOLS_QUERIED) diff --git a/packages/asset-swapper/src/utils/market_operation_utils/constants.ts b/packages/asset-swapper/src/utils/market_operation_utils/constants.ts index 3043ef0d2b..2bd7a999f1 100644 --- a/packages/asset-swapper/src/utils/market_operation_utils/constants.ts +++ b/packages/asset-swapper/src/utils/market_operation_utils/constants.ts @@ -22,7 +22,6 @@ import { GeistFillData, GetMarketOrdersOpts, isFinalUniswapV3FillData, - KyberSamplerOpts, LidoInfo, LiquidityProviderFillData, LiquidityProviderRegistry, @@ -80,7 +79,6 @@ export const SELL_SOURCE_FILTER_BY_CHAIN_ID = valueByChainId( ERC20BridgeSource.Native, ERC20BridgeSource.Uniswap, ERC20BridgeSource.UniswapV2, - ERC20BridgeSource.Kyber, ERC20BridgeSource.Curve, ERC20BridgeSource.Balancer, ERC20BridgeSource.BalancerV2, @@ -111,7 +109,6 @@ export const SELL_SOURCE_FILTER_BY_CHAIN_ID = valueByChainId( // ERC20BridgeSource.Compound, ]), [ChainId.Ropsten]: new SourceFilters([ - ERC20BridgeSource.Kyber, ERC20BridgeSource.Native, ERC20BridgeSource.SushiSwap, ERC20BridgeSource.Uniswap, @@ -226,7 +223,6 @@ export const BUY_SOURCE_FILTER_BY_CHAIN_ID = valueByChainId( ERC20BridgeSource.Native, ERC20BridgeSource.Uniswap, ERC20BridgeSource.UniswapV2, - ERC20BridgeSource.Kyber, ERC20BridgeSource.Curve, ERC20BridgeSource.Balancer, ERC20BridgeSource.BalancerV2, @@ -257,7 +253,6 @@ export const BUY_SOURCE_FILTER_BY_CHAIN_ID = valueByChainId( // ERC20BridgeSource.Compound, ]), [ChainId.Ropsten]: new SourceFilters([ - ERC20BridgeSource.Kyber, ERC20BridgeSource.Native, ERC20BridgeSource.SushiSwap, ERC20BridgeSource.Uniswap, @@ -1847,35 +1842,6 @@ export const PLATYPUS_AVALANCHE_INFOS: { [name: string]: PlatypusInfo } = { }, }; -/** - * Kyber reserve prefixes - * 0xff Fed price reserve - * 0xaa Automated price reserve - * 0xbb Bridged price reserve (i.e Uniswap/Curve) - */ -export const KYBER_BRIDGED_LIQUIDITY_PREFIX = '0xbb'; -export const KYBER_BANNED_RESERVES = ['0xff4f6e65426974205175616e7400000000000000000000000000000000000000']; -export const MAX_KYBER_RESERVES_QUERIED = 5; -export const KYBER_CONFIG_BY_CHAIN_ID = valueByChainId( - { - [ChainId.Mainnet]: { - networkProxy: '0x9aab3f75489902f3a48495025729a0af77d4b11e', - hintHandler: '0xa1C0Fa73c39CFBcC11ec9Eb1Afc665aba9996E2C', - weth: MAINNET_TOKENS.WETH, - }, - [ChainId.Ropsten]: { - networkProxy: '0x818e6fecd516ecc3849daf6845e3ec868087b755', - hintHandler: '0x63f773c026093eef988e803bdd5772dd235a8e71', - weth: getContractAddressesForChainOrThrow(ChainId.Ropsten).etherToken, - }, - }, - { - networkProxy: NULL_ADDRESS, - hintHandler: NULL_ADDRESS, - weth: NULL_ADDRESS, - }, -); - export const LIQUIDITY_PROVIDER_REGISTRY_BY_CHAIN_ID = valueByChainId( { [ChainId.Mainnet]: { @@ -1980,13 +1946,6 @@ export const MSTABLE_POOLS_BY_CHAIN_ID = valueByChainId( }, ); -export const OASIS_ROUTER_BY_CHAIN_ID = valueByChainId( - { - [ChainId.Mainnet]: '0x5e3e0548935a83ad29fb2a9153d331dc6d49020f', - }, - NULL_ADDRESS, -); - export const KYBER_DMM_ROUTER_BY_CHAIN_ID = valueByChainId( { [ChainId.Mainnet]: '0x1c87257f5e8609940bc751a07bb085bb7f8cdbe6', @@ -2471,7 +2430,6 @@ export const DEFAULT_GAS_SCHEDULE: Required = { [ERC20BridgeSource.LiquidityProvider]: fillData => { return (fillData as LiquidityProviderFillData).gasCost || 100e3; }, - [ERC20BridgeSource.Kyber]: () => 450e3, [ERC20BridgeSource.Curve]: fillData => (fillData as CurveFillData).pool.gasSchedule, [ERC20BridgeSource.CurveV2]: fillData => (fillData as CurveFillData).pool.gasSchedule, [ERC20BridgeSource.Nerve]: fillData => (fillData as CurveFillData).pool.gasSchedule, diff --git a/packages/asset-swapper/src/utils/market_operation_utils/orders.ts b/packages/asset-swapper/src/utils/market_operation_utils/orders.ts index 26fca42f60..f23869a22b 100644 --- a/packages/asset-swapper/src/utils/market_operation_utils/orders.ts +++ b/packages/asset-swapper/src/utils/market_operation_utils/orders.ts @@ -23,7 +23,6 @@ import { GenericRouterFillData, GMXFillData, KyberDmmFillData, - KyberFillData, LidoFillData, LiquidityProviderFillData, MakerPsmFillData, @@ -92,8 +91,6 @@ export function getErc20BridgeSourceToBridgeSource(source: ERC20BridgeSource): s return encodeBridgeSourceId(BridgeProtocol.BalancerV2Batch, 'BalancerV2'); case ERC20BridgeSource.Bancor: return encodeBridgeSourceId(BridgeProtocol.Bancor, 'Bancor'); - // case ERC20BridgeSource.CoFiX: - // return encodeBridgeSourceId(BridgeProtocol.CoFiX, 'CoFiX'); case ERC20BridgeSource.Curve: return encodeBridgeSourceId(BridgeProtocol.Curve, 'Curve'); case ERC20BridgeSource.Cream: @@ -102,8 +99,6 @@ export function getErc20BridgeSourceToBridgeSource(source: ERC20BridgeSource): s return encodeBridgeSourceId(BridgeProtocol.CryptoCom, 'CryptoCom'); case ERC20BridgeSource.Dodo: return encodeBridgeSourceId(BridgeProtocol.Dodo, 'Dodo'); - case ERC20BridgeSource.Kyber: - return encodeBridgeSourceId(BridgeProtocol.Kyber, 'Kyber'); case ERC20BridgeSource.LiquidityProvider: // "LiquidityProvider" is too long to encode (17 characters). return encodeBridgeSourceId(BridgeProtocol.Unknown, 'LP'); @@ -305,10 +300,6 @@ export function createBridgeDataForBridgeOrder(order: OptimizedMarketBridgeOrder const uniswapV2FillData = (order as OptimizedMarketBridgeOrder).fillData; bridgeData = encoder.encode([uniswapV2FillData.router, uniswapV2FillData.tokenAddressPath]); break; - case ERC20BridgeSource.Kyber: - const kyberFillData = (order as OptimizedMarketBridgeOrder).fillData; - bridgeData = encoder.encode([kyberFillData.networkProxy, kyberFillData.hint]); - break; case ERC20BridgeSource.Mooniswap: const mooniswapFillData = (order as OptimizedMarketBridgeOrder).fillData; bridgeData = encoder.encode([mooniswapFillData.poolAddress]); @@ -490,10 +481,6 @@ export const BRIDGE_ENCODERS: { { name: 'provider', type: 'address' }, { name: 'data', type: 'bytes' }, ]), - [ERC20BridgeSource.Kyber]: AbiEncoder.create([ - { name: 'kyberNetworkProxy', type: 'address' }, - { name: 'hint', type: 'bytes' }, - ]), [ERC20BridgeSource.Dodo]: AbiEncoder.create([ { name: 'helper', type: 'address' }, { name: 'poolAddress', type: 'address' }, diff --git a/packages/asset-swapper/src/utils/market_operation_utils/sampler_operations.ts b/packages/asset-swapper/src/utils/market_operation_utils/sampler_operations.ts index cebd5bada2..243f994b94 100644 --- a/packages/asset-swapper/src/utils/market_operation_utils/sampler_operations.ts +++ b/packages/asset-swapper/src/utils/market_operation_utils/sampler_operations.ts @@ -13,10 +13,8 @@ import { BancorService } from './bancor_service'; import { getCurveLikeInfosForPair, getDodoV2Offsets, - getKyberOffsets, getPlatypusInfoForPair, getShellLikeInfosForPair, - isAllowedKyberReserveId, isBadTokenForSource, isValidAddress, uniswapV2LikeRouterAddress, @@ -35,7 +33,6 @@ import { GMX_READER_BY_CHAIN_ID, GMX_ROUTER_BY_CHAIN_ID, GMX_VAULT_BY_CHAIN_ID, - KYBER_CONFIG_BY_CHAIN_ID, KYBER_DMM_ROUTER_BY_CHAIN_ID, LIDO_INFO_BY_CHAIN, LIQUIDITY_PROVIDER_REGISTRY_BY_CHAIN_ID, @@ -44,7 +41,6 @@ import { MOONISWAP_REGISTRIES_BY_CHAIN_ID, NATIVE_FEE_TOKEN_BY_CHAIN_ID, NULL_ADDRESS, - NULL_BYTES, PLATYPUS_ROUTER_BY_CHAIN_ID, SELL_SOURCE_FILTER_BY_CHAIN_ID, UNISWAPV1_ROUTER_BY_CHAIN_ID, @@ -81,8 +77,6 @@ import { GMXFillData, HopInfo, KyberDmmFillData, - KyberFillData, - KyberSamplerOpts, LidoFillData, LidoInfo, LiquidityProviderFillData, @@ -266,54 +260,6 @@ export class SamplerOperations { }); } - public getKyberSellQuotes( - kyberOpts: KyberSamplerOpts, - reserveOffset: BigNumber, - makerToken: string, - takerToken: string, - takerFillAmounts: BigNumber[], - ): SourceQuoteOperation { - return new SamplerContractOperation({ - source: ERC20BridgeSource.Kyber, - contract: this._samplerContract, - function: this._samplerContract.sampleSellsFromKyberNetwork, - params: [{ ...kyberOpts, reserveOffset, hint: NULL_BYTES }, takerToken, makerToken, takerFillAmounts], - callback: (callResults: string, fillData: KyberFillData): BigNumber[] => { - const [reserveId, hint, samples] = this._samplerContract.getABIDecodedReturnData< - [string, string, BigNumber[]] - >('sampleSellsFromKyberNetwork', callResults); - fillData.hint = hint; - fillData.reserveId = reserveId; - fillData.networkProxy = kyberOpts.networkProxy; - return isAllowedKyberReserveId(reserveId) ? samples : []; - }, - }); - } - - public getKyberBuyQuotes( - kyberOpts: KyberSamplerOpts, - reserveOffset: BigNumber, - makerToken: string, - takerToken: string, - makerFillAmounts: BigNumber[], - ): SourceQuoteOperation { - return new SamplerContractOperation({ - source: ERC20BridgeSource.Kyber, - contract: this._samplerContract, - function: this._samplerContract.sampleBuysFromKyberNetwork, - params: [{ ...kyberOpts, reserveOffset, hint: NULL_BYTES }, takerToken, makerToken, makerFillAmounts], - callback: (callResults: string, fillData: KyberFillData): BigNumber[] => { - const [reserveId, hint, samples] = this._samplerContract.getABIDecodedReturnData< - [string, string, BigNumber[]] - >('sampleBuysFromKyberNetwork', callResults); - fillData.hint = hint; - fillData.reserveId = reserveId; - fillData.networkProxy = kyberOpts.networkProxy; - return isAllowedKyberReserveId(reserveId) ? samples : []; - }, - }); - } - public getKyberDmmSellQuotes( router: string, tokenAddressPath: string[], @@ -1479,16 +1425,6 @@ export class SamplerOperations { return []; } return this.getKyberDmmSellQuotes(kyberDmmRouter, [takerToken, makerToken], takerFillAmounts); - case ERC20BridgeSource.Kyber: - return getKyberOffsets().map(offset => - this.getKyberSellQuotes( - KYBER_CONFIG_BY_CHAIN_ID[this.chainId], - offset, - makerToken, - takerToken, - takerFillAmounts, - ), - ); case ERC20BridgeSource.Curve: case ERC20BridgeSource.CurveV2: case ERC20BridgeSource.Nerve: @@ -1810,16 +1746,6 @@ export class SamplerOperations { return []; } return this.getKyberDmmBuyQuotes(kyberDmmRouter, [takerToken, makerToken], makerFillAmounts); - case ERC20BridgeSource.Kyber: - return getKyberOffsets().map(offset => - this.getKyberBuyQuotes( - KYBER_CONFIG_BY_CHAIN_ID[this.chainId], - offset, - makerToken, - takerToken, - makerFillAmounts, - ), - ); case ERC20BridgeSource.Curve: case ERC20BridgeSource.CurveV2: case ERC20BridgeSource.Nerve: diff --git a/packages/asset-swapper/src/utils/market_operation_utils/types.ts b/packages/asset-swapper/src/utils/market_operation_utils/types.ts index dce156a88b..141b30020a 100644 --- a/packages/asset-swapper/src/utils/market_operation_utils/types.ts +++ b/packages/asset-swapper/src/utils/market_operation_utils/types.ts @@ -38,7 +38,6 @@ export enum ERC20BridgeSource { Native = 'Native', Uniswap = 'Uniswap', UniswapV2 = 'Uniswap_V2', - Kyber = 'Kyber', Curve = 'Curve', LiquidityProvider = 'LiquidityProvider', MultiBridge = 'MultiBridge', @@ -262,12 +261,6 @@ export interface BancorFillData extends FillData { networkAddress: string; } -export interface KyberFillData extends FillData { - hint: string; - reserveId: string; - networkProxy: string; -} - export interface MooniswapFillData extends FillData { poolAddress: string; } @@ -693,9 +686,3 @@ export interface GenerateOptimizedOrdersOpts { export interface ComparisonPrice { wholeOrder: BigNumber | undefined; } - -export interface KyberSamplerOpts { - networkProxy: string; - hintHandler: string; - weth: string; -} diff --git a/packages/asset-swapper/test/artifacts.ts b/packages/asset-swapper/test/artifacts.ts index 5093e118e3..8be87fcc48 100644 --- a/packages/asset-swapper/test/artifacts.ts +++ b/packages/asset-swapper/test/artifacts.ts @@ -24,7 +24,6 @@ import * as IBalancerV2Vault from '../test/generated-artifacts/IBalancerV2Vault. import * as IBancor from '../test/generated-artifacts/IBancor.json'; import * as ICurve from '../test/generated-artifacts/ICurve.json'; import * as IGMX from '../test/generated-artifacts/IGMX.json'; -import * as IKyberNetwork from '../test/generated-artifacts/IKyberNetwork.json'; import * as IMooniswap from '../test/generated-artifacts/IMooniswap.json'; import * as IMStable from '../test/generated-artifacts/IMStable.json'; import * as IMultiBridge from '../test/generated-artifacts/IMultiBridge.json'; @@ -34,7 +33,6 @@ import * as ISmoothy from '../test/generated-artifacts/ISmoothy.json'; import * as IUniswapExchangeQuotes from '../test/generated-artifacts/IUniswapExchangeQuotes.json'; import * as IUniswapV2Router01 from '../test/generated-artifacts/IUniswapV2Router01.json'; import * as KyberDmmSampler from '../test/generated-artifacts/KyberDmmSampler.json'; -import * as KyberSampler from '../test/generated-artifacts/KyberSampler.json'; import * as LidoSampler from '../test/generated-artifacts/LidoSampler.json'; import * as LiquidityProviderSampler from '../test/generated-artifacts/LiquidityProviderSampler.json'; import * as MakerPSMSampler from '../test/generated-artifacts/MakerPSMSampler.json'; @@ -67,7 +65,6 @@ export const artifacts = { FakeTaker: FakeTaker as ContractArtifact, GMXSampler: GMXSampler as ContractArtifact, KyberDmmSampler: KyberDmmSampler as ContractArtifact, - KyberSampler: KyberSampler as ContractArtifact, LidoSampler: LidoSampler as ContractArtifact, LiquidityProviderSampler: LiquidityProviderSampler as ContractArtifact, MStableSampler: MStableSampler as ContractArtifact, @@ -88,7 +85,6 @@ export const artifacts = { IBancor: IBancor as ContractArtifact, ICurve: ICurve as ContractArtifact, IGMX: IGMX as ContractArtifact, - IKyberNetwork: IKyberNetwork as ContractArtifact, IMStable: IMStable as ContractArtifact, IMooniswap: IMooniswap as ContractArtifact, IMultiBridge: IMultiBridge as ContractArtifact, diff --git a/packages/asset-swapper/test/comparison_price_test.ts b/packages/asset-swapper/test/comparison_price_test.ts index cc0ba6d2f2..1076b11967 100644 --- a/packages/asset-swapper/test/comparison_price_test.ts +++ b/packages/asset-swapper/test/comparison_price_test.ts @@ -21,8 +21,8 @@ const GAS_PRICE = new BigNumber(50e9); // 50 gwei const NATIVE_ORDER_FEE = new BigNumber(220e3); // 220K gas // DEX samples to fill in MarketSideLiquidity -const kyberSample1: DexSample = { - source: ERC20BridgeSource.Kyber, +const curveSample: DexSample = { + source: ERC20BridgeSource.Curve, input: new BigNumber(10000), output: new BigNumber(10001), fillData: {}, @@ -33,7 +33,7 @@ const uniswapSample1: DexSample = { output: new BigNumber(10004), fillData: {}, }; -const dexQuotes: DexSample[] = [kyberSample1, uniswapSample1]; +const dexQuotes: DexSample[] = [curveSample, uniswapSample1]; const feeSchedule = { [ERC20BridgeSource.Native]: _.constant(GAS_PRICE.times(NATIVE_ORDER_FEE)), diff --git a/packages/asset-swapper/test/contracts/bridge_sampler_mainnet_test.ts b/packages/asset-swapper/test/contracts/bridge_sampler_mainnet_test.ts index 00bfb5e438..777ee8277c 100644 --- a/packages/asset-swapper/test/contracts/bridge_sampler_mainnet_test.ts +++ b/packages/asset-swapper/test/contracts/bridge_sampler_mainnet_test.ts @@ -1,9 +1,7 @@ -import { ChainId } from '@0x/contract-addresses'; import { blockchainTests, describe, expect, toBaseUnitAmount, Web3ProviderEngine } from '@0x/contracts-test-utils'; import { RPCSubprovider } from '@0x/subproviders'; -import { BigNumber, NULL_BYTES, providerUtils } from '@0x/utils'; +import { BigNumber, providerUtils } from '@0x/utils'; -import { KYBER_CONFIG_BY_CHAIN_ID, MAINNET_TOKENS } from '../../src/utils/market_operation_utils/constants'; import { artifacts } from '../artifacts'; import { ERC20BridgeSamplerContract } from '../wrappers'; @@ -79,60 +77,4 @@ blockchainTests.skip('Mainnet Sampler Tests', env => { }); }); }); - describe('Kyber', () => { - const WETH = MAINNET_TOKENS.WETH; - const DAI = MAINNET_TOKENS.DAI; - const USDC = MAINNET_TOKENS.USDC; - const RESERVE_OFFSET = new BigNumber(0); - const KYBER_OPTS = { - ...KYBER_CONFIG_BY_CHAIN_ID[ChainId.Mainnet], - reserveOffset: RESERVE_OFFSET, - hint: NULL_BYTES, - }; - describe('sampleSellsFromKyberNetwork()', () => { - it('samples sells from Kyber DAI->WETH', async () => { - const [, samples] = await testContract - .sampleSellsFromKyberNetwork(KYBER_OPTS, DAI, WETH, [toBaseUnitAmount(1)]) - .callAsync({ overrides }); - expect(samples.length).to.be.bignumber.greaterThan(0); - expect(samples[0]).to.be.bignumber.greaterThan(0); - }); - it('samples sells from Kyber WETH->DAI', async () => { - const [, samples] = await testContract - .sampleSellsFromKyberNetwork(KYBER_OPTS, WETH, DAI, [toBaseUnitAmount(1)]) - .callAsync({ overrides }); - expect(samples.length).to.be.bignumber.greaterThan(0); - expect(samples[0]).to.be.bignumber.greaterThan(0); - }); - it('samples sells from Kyber DAI->USDC', async () => { - const [, samples] = await testContract - .sampleSellsFromKyberNetwork(KYBER_OPTS, DAI, USDC, [toBaseUnitAmount(1)]) - .callAsync({ overrides }); - expect(samples.length).to.be.bignumber.greaterThan(0); - expect(samples[0]).to.be.bignumber.greaterThan(0); - }); - }); - - describe('sampleBuysFromKyber()', () => { - it('samples buys from Kyber WETH->DAI', async () => { - // From ETH to DAI - // I want to buy 1 DAI - const [, samples] = await testContract - .sampleBuysFromKyberNetwork(KYBER_OPTS, WETH, DAI, [toBaseUnitAmount(1)]) - .callAsync({ overrides }); - expect(samples.length).to.be.bignumber.greaterThan(0); - expect(samples[0]).to.be.bignumber.greaterThan(0); - }); - - it('samples buys from Kyber DAI->WETH', async () => { - // From USDC to DAI - // I want to buy 1 WETH - const [, samples] = await testContract - .sampleBuysFromKyberNetwork(KYBER_OPTS, DAI, WETH, [toBaseUnitAmount(1)]) - .callAsync({ overrides }); - expect(samples.length).to.be.bignumber.greaterThan(0); - expect(samples[0]).to.be.bignumber.greaterThan(0); - }); - }); - }); }); diff --git a/packages/asset-swapper/test/dex_sampler_test.ts b/packages/asset-swapper/test/dex_sampler_test.ts index 79d6eb400c..b7da4c4a4a 100644 --- a/packages/asset-swapper/test/dex_sampler_test.ts +++ b/packages/asset-swapper/test/dex_sampler_test.ts @@ -21,7 +21,7 @@ import { generatePseudoRandomSalt } from './utils/utils'; const CHAIN_ID = 1; const EMPTY_BYTES32 = '0x0000000000000000000000000000000000000000000000000000000000000000'; // tslint:disable: custom-no-magic-numbers -describe.skip('DexSampler tests', () => { +describe('DexSampler tests', () => { const MAKER_TOKEN = randomAddress(); const TAKER_TOKEN = randomAddress(); const chainId = ChainId.Mainnet; @@ -142,40 +142,6 @@ describe.skip('DexSampler tests', () => { expect(fillableAmounts).to.deep.eq(expectedFillableAmounts); }); - it('getKyberSellQuotes()', async () => { - const expectedTakerToken = randomAddress(); - const expectedMakerToken = randomAddress(); - const expectedTakerFillAmounts = getSampleAmounts(new BigNumber(100e18), 10); - const expectedMakerFillAmounts = getSampleAmounts(new BigNumber(100e18), 10); - const sampler = new MockSamplerContract({ - sampleSellsFromKyberNetwork: (_reserveOffset, takerToken, makerToken, fillAmounts) => { - expect(takerToken).to.eq(expectedTakerToken); - expect(makerToken).to.eq(expectedMakerToken); - expect(fillAmounts).to.deep.eq(expectedTakerFillAmounts); - return ['0x', '0x', expectedMakerFillAmounts]; - }, - }); - const dexOrderSampler = new DexOrderSampler( - chainId, - sampler, - undefined, - undefined, - undefined, - undefined, - async () => undefined, - ); - const [fillableAmounts] = await dexOrderSampler.executeAsync( - dexOrderSampler.getKyberSellQuotes( - { hintHandler: randomAddress(), networkProxy: randomAddress(), weth: randomAddress() }, - new BigNumber(0), - expectedMakerToken, - expectedTakerToken, - expectedTakerFillAmounts, - ), - ); - expect(fillableAmounts).to.deep.eq(expectedMakerFillAmounts); - }); - it('getLiquidityProviderSellQuotes()', async () => { const expectedMakerToken = randomAddress(); const expectedTakerToken = randomAddress(); @@ -370,7 +336,6 @@ describe.skip('DexSampler tests', () => { const expectedMakerToken = randomAddress(); const sources = [ERC20BridgeSource.Uniswap, ERC20BridgeSource.UniswapV2]; const ratesBySource: RatesBySource = { - [ERC20BridgeSource.Kyber]: getRandomFloat(0, 100), [ERC20BridgeSource.Uniswap]: getRandomFloat(0, 100), [ERC20BridgeSource.UniswapV2]: getRandomFloat(0, 100), }; diff --git a/packages/asset-swapper/test/market_operation_utils_test.ts b/packages/asset-swapper/test/market_operation_utils_test.ts index d8a20f20ae..16276a5f04 100644 --- a/packages/asset-swapper/test/market_operation_utils_test.ts +++ b/packages/asset-swapper/test/market_operation_utils_test.ts @@ -50,9 +50,9 @@ const TAKER_TOKEN = randomAddress(); const DEFAULT_INCLUDED = [ ERC20BridgeSource.SushiSwap, - ERC20BridgeSource.Kyber, ERC20BridgeSource.Native, ERC20BridgeSource.Uniswap, + ERC20BridgeSource.Curve, ]; const DEFAULT_EXCLUDED = SELL_SOURCE_FILTER_BY_CHAIN_ID[ChainId.Mainnet].sources.filter( @@ -321,7 +321,7 @@ describe('MarketOperationUtils tests', () => { [ERC20BridgeSource.Native]: createDecreasingRates(NUM_SAMPLES), [ERC20BridgeSource.SushiSwap]: createDecreasingRates(NUM_SAMPLES), [ERC20BridgeSource.Uniswap]: createDecreasingRates(NUM_SAMPLES), - [ERC20BridgeSource.Kyber]: createDecreasingRates(NUM_SAMPLES), + [ERC20BridgeSource.Curve]: createDecreasingRates(NUM_SAMPLES), }; interface FillDataBySource { @@ -337,7 +337,6 @@ describe('MarketOperationUtils tests', () => { deadline: Math.floor(Date.now() / 1000) + 300, }, [ERC20BridgeSource.Bancor]: { path: [], networkAddress: randomAddress() }, - [ERC20BridgeSource.Kyber]: { hint: '0x', reserveId: '0x', networkAddress: randomAddress() }, [ERC20BridgeSource.Curve]: { pool: { poolAddress: randomAddress(), @@ -1034,7 +1033,7 @@ describe('MarketOperationUtils tests', () => { rates[ERC20BridgeSource.Native] = [0.4, 0.3, 0.2, 0.1]; rates[ERC20BridgeSource.Uniswap] = [0.5, 0.05, 0.05, 0.05]; rates[ERC20BridgeSource.SushiSwap] = [0.6, 0.05, 0.05, 0.05]; - rates[ERC20BridgeSource.Kyber] = [0, 0, 0, 0]; // unused + rates[ERC20BridgeSource.Curve] = [0, 0, 0, 0]; // unused replaceSamplerOps({ getSellQuotes: createGetMultipleSellQuotesOperationFromRates(rates), }); @@ -1066,7 +1065,6 @@ describe('MarketOperationUtils tests', () => { [ERC20BridgeSource.Native]: [1, 0.99, 0.98, 0.97], // Effectively [0.94, 0.93, 0.92, 0.91] [ERC20BridgeSource.Uniswap]: [0.96, 0.1, 0.1, 0.1], [ERC20BridgeSource.SushiSwap]: [0.95, 0.1, 0.1, 0.1], - [ERC20BridgeSource.Kyber]: [0.1, 0.1, 0.1, 0.1], }; const feeSchedule = { [ERC20BridgeSource.Native]: _.constant( @@ -1097,12 +1095,10 @@ describe('MarketOperationUtils tests', () => { }); it('factors in fees for dexes', async () => { - // Kyber will have the best rates but will have fees, - // dropping its effective rates. const uniswapFeeRate = 0.2; const rates: RatesBySource = { [ERC20BridgeSource.Native]: [0.95, 0.1, 0.1, 0.1], - [ERC20BridgeSource.Kyber]: [0.1, 0.1, 0.1, 0.1], + [ERC20BridgeSource.Curve]: [0.1, 0.1, 0.1, 0.1], [ERC20BridgeSource.SushiSwap]: [0.92, 0.1, 0.1, 0.1], // Effectively [0.8, ~0.5, ~0, ~0] [ERC20BridgeSource.Uniswap]: [1, 0.7, 0.2, 0.2], @@ -1136,7 +1132,7 @@ describe('MarketOperationUtils tests', () => { it('can mix one concave source', async () => { const rates: RatesBySource = { - [ERC20BridgeSource.Kyber]: [0, 0, 0, 0], // Won't use + [ERC20BridgeSource.Curve]: [0, 0, 0, 0], // Won't use [ERC20BridgeSource.SushiSwap]: [0.5, 0.85, 0.75, 0.75], // Concave [ERC20BridgeSource.Uniswap]: [0.96, 0.2, 0.1, 0.1], [ERC20BridgeSource.Native]: [0.95, 0.2, 0.2, 0.1], @@ -1168,7 +1164,7 @@ describe('MarketOperationUtils tests', () => { rates[ERC20BridgeSource.Native] = [1, 1, 0.01, 0.01]; rates[ERC20BridgeSource.Uniswap] = [1, 1, 0.01, 0.01]; rates[ERC20BridgeSource.SushiSwap] = [0.49, 0.49, 0.49, 0.49]; - rates[ERC20BridgeSource.Kyber] = [0.35, 0.2, 0.01, 0.01]; + rates[ERC20BridgeSource.Curve] = [0.35, 0.2, 0.01, 0.01]; replaceSamplerOps({ getSellQuotes: createGetMultipleSellQuotesOperationFromRates(rates), }); @@ -1517,7 +1513,7 @@ describe('MarketOperationUtils tests', () => { [ERC20BridgeSource.Native]: [1, 0.99, 0.98, 0.97], // Effectively [0.94, ~0.93, ~0.92, ~0.91] [ERC20BridgeSource.Uniswap]: [0.96, 0.1, 0.1, 0.1], [ERC20BridgeSource.SushiSwap]: [0.95, 0.1, 0.1, 0.1], - [ERC20BridgeSource.Kyber]: [0.1, 0.1, 0.1, 0.1], + [ERC20BridgeSource.Curve]: [0.1, 0.1, 0.1, 0.1], }; const feeSchedule = { [ERC20BridgeSource.Native]: _.constant( diff --git a/packages/asset-swapper/test/quote_report_generator_test.ts b/packages/asset-swapper/test/quote_report_generator_test.ts index ba482ce4c8..df7e50058f 100644 --- a/packages/asset-swapper/test/quote_report_generator_test.ts +++ b/packages/asset-swapper/test/quote_report_generator_test.ts @@ -58,8 +58,8 @@ describe('generateQuoteReport', async () => { it('should generate report properly for sell', () => { const marketOperation: MarketOperation = MarketOperation.Sell; - const kyberSample2: DexSample = { - source: ERC20BridgeSource.Kyber, + const balancerSample2: DexSample = { + source: ERC20BridgeSource.BalancerV2, input: new BigNumber(10003), output: new BigNumber(10004), fillData: {}, @@ -117,15 +117,15 @@ describe('generateQuoteReport', async () => { sourcePathId: hexUtils.random(), type: FillQuoteTransformerOrderType.Bridge, }; - const kyber2Fill: CollapsedFill = { - ...kyberSample2, + const balancer2Fill: CollapsedFill = { + ...balancerSample2, subFills: [], sourcePathId: hexUtils.random(), type: FillQuoteTransformerOrderType.Bridge, }; const orderbookOrder2Fill: CollapsedFill = collapsedFillFromNativeOrder(orderbookOrder2); const rfqtOrder2Fill: CollapsedFill = collapsedFillFromNativeOrder(rfqtOrder2); - const pathGenerated: CollapsedFill[] = [rfqtOrder2Fill, orderbookOrder2Fill, uniswap2Fill, kyber2Fill]; + const pathGenerated: CollapsedFill[] = [rfqtOrder2Fill, orderbookOrder2Fill, uniswap2Fill, balancer2Fill]; // quote generator mock const quoteRequestor = TypeMoq.Mock.ofType(); @@ -190,10 +190,10 @@ describe('generateQuoteReport', async () => { takerAmount: uniswapSample2.input, fillData: {}, }; - const kyber2Source: BridgeQuoteReportEntry = { - liquiditySource: ERC20BridgeSource.Kyber, - makerAmount: kyberSample2.output, - takerAmount: kyberSample2.input, + const balancer2Source: BridgeQuoteReportEntry = { + liquiditySource: ERC20BridgeSource.BalancerV2, + makerAmount: balancerSample2.output, + takerAmount: balancerSample2.input, fillData: {}, }; @@ -202,7 +202,7 @@ describe('generateQuoteReport', async () => { rfqtOrder2Source, orderbookOrder2Source, uniswap2Source, - kyber2Source, + balancer2Source, ]; expectEqualQuoteReportEntries(orderReport.sourcesConsidered, expectedSourcesConsidered, `sourcesConsidered`); expectEqualQuoteReportEntries(orderReport.sourcesDelivered, expectedSourcesDelivered, `sourcesDelivered`); @@ -210,8 +210,8 @@ describe('generateQuoteReport', async () => { }); it('should handle properly for buy without quoteRequestor', () => { const marketOperation: MarketOperation = MarketOperation.Buy; - const kyberSample1: DexSample = { - source: ERC20BridgeSource.Kyber, + const balancerSample1: DexSample = { + source: ERC20BridgeSource.BalancerV2, input: new BigNumber(10000), output: new BigNumber(10001), fillData: {}, @@ -248,13 +248,13 @@ describe('generateQuoteReport', async () => { sourcePathId: hexUtils.random(), type: FillQuoteTransformerOrderType.Bridge, }; - const kyber1Fill: CollapsedFill = { - ...kyberSample1, + const balancer1Fill: CollapsedFill = { + ...balancerSample1, subFills: [], sourcePathId: hexUtils.random(), type: FillQuoteTransformerOrderType.Bridge, }; - const pathGenerated: CollapsedFill[] = [orderbookOrder1Fill, uniswap1Fill, kyber1Fill]; + const pathGenerated: CollapsedFill[] = [orderbookOrder1Fill, uniswap1Fill, balancer1Fill]; const orderReport = generateQuoteReport(marketOperation, nativeOrders, pathGenerated); @@ -274,16 +274,16 @@ describe('generateQuoteReport', async () => { takerAmount: uniswapSample1.output, fillData: {}, }; - const kyber1Source: BridgeQuoteReportEntry = { - liquiditySource: ERC20BridgeSource.Kyber, - makerAmount: kyberSample1.input, - takerAmount: kyberSample1.output, + const balancer1Source: BridgeQuoteReportEntry = { + liquiditySource: ERC20BridgeSource.BalancerV2, + makerAmount: balancerSample1.input, + takerAmount: balancerSample1.output, fillData: {}, }; // No order is considered here because only Native RFQ orders are considered. const expectedSourcesConsidered: QuoteReportEntry[] = []; - const expectedSourcesDelivered: QuoteReportEntry[] = [orderbookOrder1Source, uniswap1Source, kyber1Source]; + const expectedSourcesDelivered: QuoteReportEntry[] = [orderbookOrder1Source, uniswap1Source, balancer1Source]; expectEqualQuoteReportEntries(orderReport.sourcesConsidered, expectedSourcesConsidered, `sourcesConsidered`); expectEqualQuoteReportEntries(orderReport.sourcesDelivered, expectedSourcesDelivered, `sourcesDelivered`); }); diff --git a/packages/asset-swapper/test/utils/mock_sampler_contract.ts b/packages/asset-swapper/test/utils/mock_sampler_contract.ts index 70c58e3e13..23df160747 100644 --- a/packages/asset-swapper/test/utils/mock_sampler_contract.ts +++ b/packages/asset-swapper/test/utils/mock_sampler_contract.ts @@ -1,10 +1,9 @@ import { ContractTxFunctionObj } from '@0x/base-contract'; import { constants } from '@0x/contracts-test-utils'; import { LimitOrderFields, Signature } from '@0x/protocol-utils'; -import { BigNumber, hexUtils, NULL_BYTES } from '@0x/utils'; +import { BigNumber, hexUtils } from '@0x/utils'; import { SamplerCallResult } from '../../src/types'; -import { KyberSamplerOpts } from '../../src/utils/market_operation_utils/types'; import { ERC20BridgeSamplerContract } from '../../src/wrappers'; export type GetOrderFillableAssetAmountResult = BigNumber[]; @@ -39,18 +38,6 @@ export type SampleBuysEth2DaiHandler = ( makerToken: string, makerTokenAmounts: BigNumber[], ) => SampleResults; -export type SampleSellsKyberHandler = ( - opts: KyberSamplerOpts, - takerToken: string, - makerToken: string, - takerTokenAmounts: BigNumber[], -) => [string, string, SampleResults]; -export type SampleBuysKyberHandler = ( - reserveId: string, - takerToken: string, - makerToken: string, - makerTokenAmounts: BigNumber[], -) => [string, SampleResults]; export type SampleUniswapV2Handler = (router: string, path: string[], assetAmounts: BigNumber[]) => SampleResults; export type SampleBuysMultihopHandler = (path: string[], takerTokenAmounts: BigNumber[]) => SampleResults; export type SampleSellsLPHandler = ( @@ -70,7 +57,6 @@ const DUMMY_PROVIDER = { interface Handlers { getLimitOrderFillableMakerAssetAmounts: GetOrderFillableAssetAmountHandler; getLimitOrderFillableTakerAssetAmounts: GetOrderFillableAssetAmountHandler; - sampleSellsFromKyberNetwork: SampleSellsKyberHandler; sampleSellsFromLiquidityProvider: SampleSellsLPHandler; sampleSellsFromUniswap: SampleSellsUniswapHandler; sampleSellsFromUniswapV2: SampleUniswapV2Handler; @@ -123,22 +109,6 @@ export class MockSamplerContract extends ERC20BridgeSamplerContract { ); } - public sampleSellsFromKyberNetwork( - opts: KyberSamplerOpts, - takerToken: string, - makerToken: string, - takerAssetAmounts: BigNumber[], - ): ContractTxFunctionObj<[string, string, BigNumber[]]> { - return this._wrapCall( - super.sampleSellsFromKyberNetwork, - this._handlers.sampleSellsFromKyberNetwork, - { ...opts, reserveOffset: new BigNumber(1), hint: NULL_BYTES }, - takerToken, - makerToken, - takerAssetAmounts, - ); - } - public sampleSellsFromUniswap( router: string, takerToken: string, diff --git a/packages/asset-swapper/test/wrappers.ts b/packages/asset-swapper/test/wrappers.ts index e58661f1d2..4b8e9976f5 100644 --- a/packages/asset-swapper/test/wrappers.ts +++ b/packages/asset-swapper/test/wrappers.ts @@ -21,7 +21,6 @@ export * from '../test/generated-wrappers/i_balancer'; export * from '../test/generated-wrappers/i_balancer_v2_vault'; export * from '../test/generated-wrappers/i_bancor'; export * from '../test/generated-wrappers/i_curve'; -export * from '../test/generated-wrappers/i_kyber_network'; export * from '../test/generated-wrappers/i_m_stable'; export * from '../test/generated-wrappers/i_mooniswap'; export * from '../test/generated-wrappers/i_multi_bridge'; @@ -32,7 +31,6 @@ export * from '../test/generated-wrappers/i_uniswap_exchange_quotes'; export * from '../test/generated-wrappers/i_uniswap_v2_router01'; export * from '../test/generated-wrappers/igmx'; export * from '../test/generated-wrappers/kyber_dmm_sampler'; -export * from '../test/generated-wrappers/kyber_sampler'; export * from '../test/generated-wrappers/lido_sampler'; export * from '../test/generated-wrappers/liquidity_provider_sampler'; export * from '../test/generated-wrappers/m_stable_sampler'; diff --git a/packages/asset-swapper/tsconfig.json b/packages/asset-swapper/tsconfig.json index c83c5ead5c..11b06e0537 100644 --- a/packages/asset-swapper/tsconfig.json +++ b/packages/asset-swapper/tsconfig.json @@ -25,7 +25,6 @@ "test/generated-artifacts/IBancor.json", "test/generated-artifacts/ICurve.json", "test/generated-artifacts/IGMX.json", - "test/generated-artifacts/IKyberNetwork.json", "test/generated-artifacts/IMStable.json", "test/generated-artifacts/IMooniswap.json", "test/generated-artifacts/IMultiBridge.json", @@ -35,7 +34,6 @@ "test/generated-artifacts/IUniswapExchangeQuotes.json", "test/generated-artifacts/IUniswapV2Router01.json", "test/generated-artifacts/KyberDmmSampler.json", - "test/generated-artifacts/KyberSampler.json", "test/generated-artifacts/LidoSampler.json", "test/generated-artifacts/LiquidityProviderSampler.json", "test/generated-artifacts/MStableSampler.json", diff --git a/packages/protocol-utils/src/transformer_utils.ts b/packages/protocol-utils/src/transformer_utils.ts index 3fd4a779f6..43000763fc 100644 --- a/packages/protocol-utils/src/transformer_utils.ts +++ b/packages/protocol-utils/src/transformer_utils.ts @@ -114,16 +114,13 @@ export enum BridgeProtocol { UniswapV2, Uniswap, Balancer, - Kyber, Mooniswap, MStable, - Oasis, Shell, Dodo, DodoV2, CryptoCom, Bancor, - CoFiX, Nerve, MakerPsm, BalancerV2,