diff --git a/contracts/erc20-bridge-sampler/CHANGELOG.json b/contracts/erc20-bridge-sampler/CHANGELOG.json index 8013240db3..58bd2367af 100644 --- a/contracts/erc20-bridge-sampler/CHANGELOG.json +++ b/contracts/erc20-bridge-sampler/CHANGELOG.json @@ -4,7 +4,7 @@ "changes": [ { "note": "Do not query empty/unsigned orders. Swallow revets on DEX quotes.", - "pr": 2395 + "pr": 2365 } ] }, diff --git a/contracts/erc20-bridge-sampler/contracts/src/DeploymentConstants.sol b/contracts/erc20-bridge-sampler/contracts/src/DeploymentConstants.sol deleted file mode 100644 index 3e49695829..0000000000 --- a/contracts/erc20-bridge-sampler/contracts/src/DeploymentConstants.sol +++ /dev/null @@ -1,93 +0,0 @@ -/* - - Copyright 2019 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.5.9; -pragma experimental ABIEncoderV2; - -import "@0x/contracts-asset-proxy/contracts/src/interfaces/IUniswapExchangeFactory.sol"; -import "@0x/contracts-exchange/contracts/src/interfaces/IExchange.sol"; -import "./IDevUtils.sol"; -import "./IEth2Dai.sol"; -import "./IKyberNetwork.sol"; - - -contract DeploymentConstants { - - /// @dev Address of the 0x DevUtils contract. - address constant public DEVUTILS_ADDRESS = 0xcCc2431a7335F21d9268bA62F0B32B0f2EFC463f; - /// @dev Address of the Eth2Dai MatchingMarket contract. - address constant public ETH2DAI_ADDRESS = 0x39755357759cE0d7f32dC8dC45414CCa409AE24e; - /// @dev Address of the UniswapExchangeFactory contract. - address constant public UNISWAP_EXCHANGE_FACTORY_ADDRESS = 0xc0a47dFe034B400B47bDaD5FecDa2621de6c4d95; - /// @dev Address of the KyberNeworkProxy contract. - address constant public KYBER_NETWORK_PROXY_ADDRESS = 0x818E6FECD516Ecc3849DAf6845e3EC868087B755; - /// @dev Address of the WETH contract. - address constant public WETH_ADDRESS = 0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2; - /// @dev Kyber ETH pseudo-address. - address constant public KYBER_ETH_ADDRESS = 0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE; - - /// @dev An overridable way to retrieve the 0x DevUtils contract address. - /// @return devUtils The 0x DevUtils contract address. - function _getDevUtilsAddress() - internal - view - returns (address devUtils) - { - return DEVUTILS_ADDRESS; - } - - /// @dev An overridable way to retrieve the Eth2Dai exchange contract address. - /// @return eth2dai The Eth2Dai exchange contract address. - function _getEth2DaiAddress() - internal - view - returns (address eth2dai) - { - return ETH2DAI_ADDRESS; - } - - /// @dev An overridable way to retrieve the Uniswap exchange factory contract address. - /// @return uniswap The UniswapExchangeFactory contract address. - function _getUniswapExchangeFactoryAddress() - internal - view - returns (address uniswap) - { - return UNISWAP_EXCHANGE_FACTORY_ADDRESS; - } - - /// @dev An overridable way to retrieve the Kyber network proxy contract address. - /// @return kyber The KyberNeworkProxy contract address. - function _getKyberNetworkAddress() - internal - view - returns (address kyber) - { - return KYBER_NETWORK_PROXY_ADDRESS; - } - - /// @dev An overridable way to retrieve the WETH contract address. - /// @return weth The WETH contract address. - function _getWETHAddress() - internal - view - returns (address weth) - { - return WETH_ADDRESS; - } -} diff --git a/contracts/erc20-bridge-sampler/contracts/src/ERC20BridgeSampler.sol b/contracts/erc20-bridge-sampler/contracts/src/ERC20BridgeSampler.sol index 4291adf7c9..052d4d64f5 100644 --- a/contracts/erc20-bridge-sampler/contracts/src/ERC20BridgeSampler.sol +++ b/contracts/erc20-bridge-sampler/contracts/src/ERC20BridgeSampler.sol @@ -24,7 +24,7 @@ import "@0x/contracts-erc20/contracts/src/LibERC20Token.sol"; import "@0x/contracts-exchange/contracts/src/interfaces/IExchange.sol"; import "@0x/contracts-exchange-libs/contracts/src/LibOrder.sol"; import "@0x/contracts-exchange-libs/contracts/src/LibMath.sol"; -import "./DeploymentConstants.sol"; +import "@0x/contracts-utils/contracts/src/DeploymentConstants.sol"; import "./IDevUtils.sol"; import "./IERC20BridgeSampler.sol"; import "./IEth2Dai.sol"; @@ -174,7 +174,7 @@ contract ERC20BridgeSampler is // convert them to maker asset amounts. for (uint256 i = 0; i < orders.length; ++i) { if (orderFillableMakerAssetAmounts[i] != 0) { - orderFillableMakerAssetAmounts[i] = LibMath.getPartialAmountFloor( + orderFillableMakerAssetAmounts[i] = LibMath.getPartialAmountCeil( orderFillableMakerAssetAmounts[i], orders[i].takerAssetAmount, orders[i].makerAssetAmount @@ -259,15 +259,15 @@ contract ERC20BridgeSampler is returns (uint256[] memory makerTokenAmounts) { _assertValidPair(makerToken, takerToken); - address _takerToken = takerToken == _getWETHAddress() ? KYBER_ETH_ADDRESS : takerToken; - address _makerToken = makerToken == _getWETHAddress() ? KYBER_ETH_ADDRESS : makerToken; + address _takerToken = takerToken == _getWethAddress() ? KYBER_ETH_ADDRESS : takerToken; + address _makerToken = makerToken == _getWethAddress() ? KYBER_ETH_ADDRESS : makerToken; uint256 takerTokenDecimals = _getTokenDecimals(takerToken); uint256 makerTokenDecimals = _getTokenDecimals(makerToken); uint256 numSamples = takerTokenAmounts.length; makerTokenAmounts = new uint256[](numSamples); for (uint256 i = 0; i < numSamples; i++) { (bool didSucceed, bytes memory resultData) = - _getKyberNetworkAddress().staticcall(abi.encodeWithSelector( + _getKyberNetworkProxyAddress().staticcall(abi.encodeWithSelector( IKyberNetwork(0).getExpectedRate.selector, _takerToken, _makerToken, @@ -275,7 +275,7 @@ contract ERC20BridgeSampler is )); uint256 rate = 0; if (didSucceed) { - (rate,) = abi.decode(resultData, (uint256, uint256)); + rate = abi.decode(resultData, (uint256)); } makerTokenAmounts[i] = rate * @@ -372,18 +372,18 @@ contract ERC20BridgeSampler is _assertValidPair(makerToken, takerToken); uint256 numSamples = takerTokenAmounts.length; makerTokenAmounts = new uint256[](numSamples); - IUniswapExchangeQuotes takerTokenExchange = takerToken == _getWETHAddress() ? + IUniswapExchangeQuotes takerTokenExchange = takerToken == _getWethAddress() ? IUniswapExchangeQuotes(0) : _getUniswapExchange(takerToken); - IUniswapExchangeQuotes makerTokenExchange = makerToken == _getWETHAddress() ? + IUniswapExchangeQuotes makerTokenExchange = makerToken == _getWethAddress() ? IUniswapExchangeQuotes(0) : _getUniswapExchange(makerToken); for (uint256 i = 0; i < numSamples; i++) { - if (makerToken == _getWETHAddress()) { + if (makerToken == _getWethAddress()) { makerTokenAmounts[i] = _callUniswapExchangePriceFunction( address(takerTokenExchange), takerTokenExchange.getTokenToEthInputPrice.selector, takerTokenAmounts[i] ); - } else if (takerToken == _getWETHAddress()) { + } else if (takerToken == _getWethAddress()) { makerTokenAmounts[i] = _callUniswapExchangePriceFunction( address(makerTokenExchange), makerTokenExchange.getEthToTokenInputPrice.selector, @@ -426,18 +426,18 @@ contract ERC20BridgeSampler is _assertValidPair(makerToken, takerToken); uint256 numSamples = makerTokenAmounts.length; takerTokenAmounts = new uint256[](numSamples); - IUniswapExchangeQuotes takerTokenExchange = takerToken == _getWETHAddress() ? + IUniswapExchangeQuotes takerTokenExchange = takerToken == _getWethAddress() ? IUniswapExchangeQuotes(0) : _getUniswapExchange(takerToken); - IUniswapExchangeQuotes makerTokenExchange = makerToken == _getWETHAddress() ? + IUniswapExchangeQuotes makerTokenExchange = makerToken == _getWethAddress() ? IUniswapExchangeQuotes(0) : _getUniswapExchange(makerToken); for (uint256 i = 0; i < numSamples; i++) { - if (makerToken == _getWETHAddress()) { + if (makerToken == _getWethAddress()) { takerTokenAmounts[i] = _callUniswapExchangePriceFunction( address(takerTokenExchange), takerTokenExchange.getTokenToEthOutputPrice.selector, makerTokenAmounts[i] ); - } else if (takerToken == _getWETHAddress()) { + } else if (takerToken == _getWethAddress()) { takerTokenAmounts[i] = _callUniswapExchangePriceFunction( address(makerTokenExchange), makerTokenExchange.getEthToTokenOutputPrice.selector, @@ -523,7 +523,7 @@ contract ERC20BridgeSampler is if (source == _getUniswapExchangeFactoryAddress()) { return sampleSellsFromUniswap(takerToken, makerToken, takerTokenAmounts); } - if (source == _getKyberNetworkAddress()) { + if (source == _getKyberNetworkProxyAddress()) { return sampleSellsFromKyberNetwork(takerToken, makerToken, takerTokenAmounts); } revert("ERC20BridgeSampler/UNSUPPORTED_SOURCE"); diff --git a/contracts/erc20-bridge-sampler/contracts/test/TestERC20BridgeSampler.sol b/contracts/erc20-bridge-sampler/contracts/test/TestERC20BridgeSampler.sol index 4ecbc6a233..dbc7fa0ec7 100644 --- a/contracts/erc20-bridge-sampler/contracts/test/TestERC20BridgeSampler.sol +++ b/contracts/erc20-bridge-sampler/contracts/test/TestERC20BridgeSampler.sol @@ -136,7 +136,7 @@ contract TestERC20BridgeSamplerUniswapExchange is return LibDeterministicQuotes.getDeterministicSellQuote( salt, tokenAddress, - WETH_ADDRESS, + _getWethAddress(), ethSold ); } @@ -152,7 +152,7 @@ contract TestERC20BridgeSamplerUniswapExchange is _revertIfShouldFail(); return LibDeterministicQuotes.getDeterministicBuyQuote( salt, - WETH_ADDRESS, + _getWethAddress(), tokenAddress, tokensBought ); @@ -170,7 +170,7 @@ contract TestERC20BridgeSamplerUniswapExchange is return LibDeterministicQuotes.getDeterministicSellQuote( salt, tokenAddress, - WETH_ADDRESS, + _getWethAddress(), tokensSold ); } @@ -186,7 +186,7 @@ contract TestERC20BridgeSamplerUniswapExchange is _revertIfShouldFail(); return LibDeterministicQuotes.getDeterministicBuyQuote( salt, - WETH_ADDRESS, + _getWethAddress(), tokenAddress, ethBought ); @@ -213,8 +213,8 @@ contract TestERC20BridgeSamplerKyberNetwork is returns (uint256 expectedRate, uint256) { _revertIfShouldFail(); - fromToken = fromToken == ETH_ADDRESS ? WETH_ADDRESS : fromToken; - toToken = toToken == ETH_ADDRESS ? WETH_ADDRESS : toToken; + fromToken = fromToken == ETH_ADDRESS ? _getWethAddress() : fromToken; + toToken = toToken == ETH_ADDRESS ? _getWethAddress() : toToken; expectedRate = LibDeterministicQuotes.getDeterministicRate( SALT, fromToken, @@ -381,7 +381,7 @@ contract TestERC20BridgeSampler is } // Overriden to point to a custom contract. - function _getKyberNetworkAddress() + function _getKyberNetworkProxyAddress() internal view returns (address kyberAddress) diff --git a/contracts/erc20-bridge-sampler/package.json b/contracts/erc20-bridge-sampler/package.json index 1a35c9e029..d1e94270a7 100644 --- a/contracts/erc20-bridge-sampler/package.json +++ b/contracts/erc20-bridge-sampler/package.json @@ -38,7 +38,7 @@ "config": { "publicInterfaceContracts": "ERC20BridgeSampler,IERC20BridgeSampler", "abis:comment": "This list is auto-generated by contracts-gen. Don't edit manually.", - "abis": "./test/generated-artifacts/@(DeploymentConstants|ERC20BridgeSampler|IDevUtils|IERC20BridgeSampler|IEth2Dai|IKyberNetwork|IUniswapExchangeQuotes|TestERC20BridgeSampler).json" + "abis": "./test/generated-artifacts/@(ERC20BridgeSampler|IDevUtils|IERC20BridgeSampler|IEth2Dai|IKyberNetwork|IUniswapExchangeQuotes|TestERC20BridgeSampler).json" }, "repository": { "type": "git", diff --git a/contracts/erc20-bridge-sampler/test/artifacts.ts b/contracts/erc20-bridge-sampler/test/artifacts.ts index 516e472b97..d6d708a2b8 100644 --- a/contracts/erc20-bridge-sampler/test/artifacts.ts +++ b/contracts/erc20-bridge-sampler/test/artifacts.ts @@ -5,7 +5,6 @@ */ import { ContractArtifact } from 'ethereum-types'; -import * as DeploymentConstants from '../test/generated-artifacts/DeploymentConstants.json'; import * as ERC20BridgeSampler from '../test/generated-artifacts/ERC20BridgeSampler.json'; import * as IDevUtils from '../test/generated-artifacts/IDevUtils.json'; import * as IERC20BridgeSampler from '../test/generated-artifacts/IERC20BridgeSampler.json'; @@ -14,7 +13,6 @@ import * as IKyberNetwork from '../test/generated-artifacts/IKyberNetwork.json'; import * as IUniswapExchangeQuotes from '../test/generated-artifacts/IUniswapExchangeQuotes.json'; import * as TestERC20BridgeSampler from '../test/generated-artifacts/TestERC20BridgeSampler.json'; export const artifacts = { - DeploymentConstants: DeploymentConstants as ContractArtifact, ERC20BridgeSampler: ERC20BridgeSampler as ContractArtifact, IDevUtils: IDevUtils as ContractArtifact, IERC20BridgeSampler: IERC20BridgeSampler as ContractArtifact, diff --git a/contracts/erc20-bridge-sampler/test/wrappers.ts b/contracts/erc20-bridge-sampler/test/wrappers.ts index e11496101d..669266fca6 100644 --- a/contracts/erc20-bridge-sampler/test/wrappers.ts +++ b/contracts/erc20-bridge-sampler/test/wrappers.ts @@ -3,7 +3,6 @@ * Warning: This file is auto-generated by contracts-gen. Don't edit manually. * ----------------------------------------------------------------------------- */ -export * from '../test/generated-wrappers/deployment_constants'; export * from '../test/generated-wrappers/erc20_bridge_sampler'; export * from '../test/generated-wrappers/i_dev_utils'; export * from '../test/generated-wrappers/i_erc20_bridge_sampler'; diff --git a/contracts/erc20-bridge-sampler/tsconfig.json b/contracts/erc20-bridge-sampler/tsconfig.json index e7e560ac19..866692f33f 100644 --- a/contracts/erc20-bridge-sampler/tsconfig.json +++ b/contracts/erc20-bridge-sampler/tsconfig.json @@ -5,7 +5,6 @@ "files": [ "generated-artifacts/ERC20BridgeSampler.json", "generated-artifacts/IERC20BridgeSampler.json", - "test/generated-artifacts/DeploymentConstants.json", "test/generated-artifacts/ERC20BridgeSampler.json", "test/generated-artifacts/IDevUtils.json", "test/generated-artifacts/IERC20BridgeSampler.json",