diff --git a/.circleci/config.yml b/.circleci/config.yml index 43b37fd89b..24adec5182 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -103,10 +103,6 @@ jobs: - run: yarn wsrun test:circleci @0x/contracts-multisig @0x/contracts-utils @0x/contracts-exchange-libs @0x/contracts-erc20 @0x/contracts-erc721 @0x/contracts-erc1155 @0x/contracts-asset-proxy @0x/contracts-exchange @0x/contracts-exchange-forwarder @0x/contracts-dev-utils @0x/contracts-staking # TODO(dorothy-zbornak): Re-enable after updating this package for 3.0. # - run: yarn wsrun test:circleci @0x/contracts-extensions - # TODO(dorothy-zbornak): Re-enable after updating this package for 3.0. - # - run: yarn wsrun test:circleci @0x/contracts-exchange-forwarder - # TODO(dorothy-zbornak): Re-enable after this package is complete. - # - run: yarn wsrun test:circleci @0x/contracts-staking # TODO(abandeali): Re-enable after this package is complete. # - run: yarn wsrun test:circleci @0x/contracts-coordinator test-contracts-geth: diff --git a/contracts/exchange-forwarder/contracts/src/MixinAssets.sol b/contracts/exchange-forwarder/contracts/src/MixinAssets.sol index 42f74a2c95..9c2da48ed8 100644 --- a/contracts/exchange-forwarder/contracts/src/MixinAssets.sol +++ b/contracts/exchange-forwarder/contracts/src/MixinAssets.sol @@ -66,7 +66,7 @@ contract MixinAssets is if (proxyId == ERC20_DATA_ID) { address proxyAddress = EXCHANGE.getAssetProxy(ERC20_DATA_ID); if (proxyAddress == address(0)) { - LibRichErrors._rrevert(LibForwarderRichErrors.UnregisteredAssetProxyError()); + LibRichErrors.rrevert(LibForwarderRichErrors.UnregisteredAssetProxyError()); } IERC20Token assetToken = IERC20Token(assetData.readAddress(16)); if (assetToken.allowance(address(this), proxyAddress) != MAX_UINT) { @@ -91,7 +91,7 @@ contract MixinAssets is } else if (proxyId == ERC721_DATA_ID) { _transferERC721Token(assetData, amount); } else { - LibRichErrors._rrevert(LibForwarderRichErrors.UnsupportedAssetProxyError( + LibRichErrors.rrevert(LibForwarderRichErrors.UnsupportedAssetProxyError( proxyId )); } @@ -117,7 +117,7 @@ contract MixinAssets is amount )); if (!success) { - LibRichErrors._rrevert(LibForwarderRichErrors.TransferFailedError()); + LibRichErrors.rrevert(LibForwarderRichErrors.TransferFailedError()); } // Check return data. @@ -137,7 +137,7 @@ contract MixinAssets is } } if (!success) { - LibRichErrors._rrevert(LibForwarderRichErrors.TransferFailedError()); + LibRichErrors.rrevert(LibForwarderRichErrors.TransferFailedError()); } } @@ -151,7 +151,7 @@ contract MixinAssets is internal { if (amount != 1) { - LibRichErrors._rrevert(LibForwarderRichErrors.InvalidErc721AmountError( + LibRichErrors.rrevert(LibForwarderRichErrors.InvalidErc721AmountError( amount )); } diff --git a/contracts/exchange-forwarder/contracts/src/MixinExchangeWrapper.sol b/contracts/exchange-forwarder/contracts/src/MixinExchangeWrapper.sol index 38afe5d5a8..a879268f17 100644 --- a/contracts/exchange-forwarder/contracts/src/MixinExchangeWrapper.sol +++ b/contracts/exchange-forwarder/contracts/src/MixinExchangeWrapper.sol @@ -23,14 +23,16 @@ import "@0x/contracts-utils/contracts/src/LibRichErrors.sol"; import "@0x/contracts-exchange-libs/contracts/src/LibOrder.sol"; import "@0x/contracts-exchange-libs/contracts/src/LibFillResults.sol"; import "@0x/contracts-exchange-libs/contracts/src/LibMath.sol"; -import "@0x/contracts/exchange/contracts/src/interfaces/IExchange.sol"; +import "@0x/contracts-exchange/contracts/src/interfaces/IExchange.sol"; +import "./libs/LibConstants.sol"; import "./libs/LibForwarderRichErrors.sol"; + contract MixinExchangeWrapper is + LibConstants, LibFillResults, - LibMath, - LibConstants + LibMath { /// @dev Fills the input order. /// Returns false if the transaction would otherwise revert. @@ -95,10 +97,7 @@ contract MixinExchangeWrapper is returns (FillResults memory singleFillResults) { // The remaining amount of WETH to sell - uint256 remainingTakerAssetFillAmount = _safeSub( - wethSellAmount, - wethSpentAmount - ); + uint256 remainingTakerAssetFillAmount = wethSellAmount.safeSub(wethSpentAmount); // Percentage fee if (order.makerAssetData.equals(order.takerFeeAssetData)) { @@ -112,9 +111,9 @@ contract MixinExchangeWrapper is } else if (order.takerFeeAssetData.equals(order.takerAssetData)) { // We will first sell WETH as the takerAsset, then use it to pay the takerFee. // This ensures that we reserve enough to pay the fee. - uint256 takerAssetFillAmount = _getPartialAmountCeil( + uint256 takerAssetFillAmount = getPartialAmountCeil( order.takerAssetAmount, - _safeAdd(order.takerAssetAmount, order.takerFee), + order.takerAssetAmount.safeAdd(order.takerFee), remainingTakerAssetFillAmount ); @@ -124,7 +123,7 @@ contract MixinExchangeWrapper is signature ); } else { - LibRichErrors._rrevert(LibForwarderRichErrors.UnsupportedFeeError(order.takerFeeAssetData)); + LibRichErrors.rrevert(LibForwarderRichErrors.UnsupportedFeeError(order.takerFeeAssetData)); } } @@ -149,7 +148,7 @@ contract MixinExchangeWrapper is for (uint256 i = 0; i != ordersLength; i++) { if (!orders[i].makerAssetData.equals(orders[0].makerAssetData)) { - LibRichErrors._rrevert(LibForwarderRichErrors.MakerAssetMismatchError( + LibRichErrors.rrevert(LibForwarderRichErrors.MakerAssetMismatchError( orders[0].makerAssetData, orders[i].makerAssetData )); @@ -165,25 +164,19 @@ contract MixinExchangeWrapper is // Percentage fee if (orders[i].takerFeeAssetData.equals(orders[i].makerAssetData)) { // Subtract fee from makerAssetFilledAmount for the net amount acquired. - makerAssetAcquiredAmount = _safeAdd( - makerAssetAcquiredAmount, - _safeSub(singleFillResults.makerAssetFilledAmount, singleFillResults.takerFeePaid) - ); + makerAssetAcquiredAmount = makerAssetAcquiredAmount.safeAdd( + singleFillResults.makerAssetFilledAmount + ).safeSub(singleFillResults.takerFeePaid); - wethSpentAmount = _safeAdd( - wethSpentAmount, - singleFillResults.takerAssetFilledAmount - ); + wethSpentAmount = wethSpentAmount.safeAdd(singleFillResults.takerAssetFilledAmount); // WETH fee } else { // WETH is also spent on the taker fee, so we add it here. - wethSpentAmount = _safeAdd( - wethSpentAmount, - _safeAdd(singleFillResults.takerAssetFilledAmount, singleFillResults.takerFeePaid) - ); + wethSpentAmount = wethSpentAmount.safeAdd( + singleFillResults.takerAssetFilledAmount + ).safeAdd(singleFillResults.takerFeePaid); - makerAssetAcquiredAmount = _safeAdd( - makerAssetAcquiredAmount, + makerAssetAcquiredAmount = makerAssetAcquiredAmount.safeAdd( singleFillResults.makerAssetFilledAmount ); } @@ -215,10 +208,10 @@ contract MixinExchangeWrapper is // Percentage fee if (order.takerFeeAssetData.equals(order.makerAssetData)) { // Calculate the remaining amount of takerAsset to sell - uint256 remainingTakerAssetFillAmount = _getPartialAmountCeil( + uint256 remainingTakerAssetFillAmount = getPartialAmountCeil( order.takerAssetAmount, - _safeSub(order.makerAssetAmount, order.takerFee), - _safeSub(makerAssetBuyAmount, makerAssetAcquiredAmount) + order.makerAssetAmount.safeSub(order.takerFee), + makerAssetBuyAmount.safeSub(makerAssetAcquiredAmount) ); // Attempt to sell the remaining amount of takerAsset @@ -230,10 +223,10 @@ contract MixinExchangeWrapper is // WETH fee } else if (order.takerFeeAssetData.equals(order.takerAssetData)) { // Calculate the remaining amount of takerAsset to sell - uint256 remainingTakerAssetFillAmount = _getPartialAmountCeil( + uint256 remainingTakerAssetFillAmount = getPartialAmountCeil( order.takerAssetAmount, order.makerAssetAmount, - _safeSub(makerAssetBuyAmount, makerAssetAcquiredAmount) + makerAssetBuyAmount.safeSub(makerAssetAcquiredAmount) ); // Attempt to sell the remaining amount of takerAsset @@ -243,7 +236,7 @@ contract MixinExchangeWrapper is signature ); } else { - LibRichErrors._rrevert(LibForwarderRichErrors.UnsupportedFeeError(order.takerFeeAssetData)); + LibRichErrors.rrevert(LibForwarderRichErrors.UnsupportedFeeError(order.takerFeeAssetData)); } } @@ -269,7 +262,7 @@ contract MixinExchangeWrapper is uint256 ordersLength = orders.length; for (uint256 i = 0; i != ordersLength; i++) { if (!orders[i].makerAssetData.equals(orders[0].makerAssetData)) { - LibRichErrors._rrevert(LibForwarderRichErrors.MakerAssetMismatchError( + LibRichErrors.rrevert(LibForwarderRichErrors.MakerAssetMismatchError( orders[0].makerAssetData, orders[i].makerAssetData )); @@ -285,27 +278,23 @@ contract MixinExchangeWrapper is // Percentage fee if (orders[i].takerFeeAssetData.equals(orders[i].makerAssetData)) { // Subtract fee from makerAssetFilledAmount for the net amount acquired. - makerAssetAcquiredAmount = _safeAdd( - makerAssetAcquiredAmount, - _safeSub(singleFillResults.makerAssetFilledAmount, singleFillResults.takerFeePaid) - ); + makerAssetAcquiredAmount = makerAssetAcquiredAmount.safeAdd( + singleFillResults.makerAssetFilledAmount + ).safeSub(singleFillResults.takerFeePaid); - wethSpentAmount = _safeAdd( - wethSpentAmount, + wethSpentAmount = wethSpentAmount.safeAdd( singleFillResults.takerAssetFilledAmount ); // WETH fee } else { - makerAssetAcquiredAmount = _safeAdd( - makerAssetAcquiredAmount, + makerAssetAcquiredAmount = makerAssetAcquiredAmount.safeAdd( singleFillResults.makerAssetFilledAmount ); // WETH is also spent on the taker fee, so we add it here. - wethSpentAmount = _safeAdd( - wethSpentAmount, - _safeAdd(singleFillResults.takerAssetFilledAmount, singleFillResults.takerFeePaid) - ); + wethSpentAmount = wethSpentAmount.safeAdd( + singleFillResults.takerAssetFilledAmount + ).safeAdd(singleFillResults.takerFeePaid); } // Stop execution if the entire amount of makerAsset has been bought @@ -315,7 +304,7 @@ contract MixinExchangeWrapper is } if (makerAssetAcquiredAmount < makerAssetBuyAmount) { - LibRichErrors._rrevert(LibForwarderRichErrors.CompleteFillFailedError()); + LibRichErrors.rrevert(LibForwarderRichErrors.CompleteFillFailedError()); } return (wethSpentAmount, makerAssetAcquiredAmount); diff --git a/contracts/exchange-forwarder/contracts/src/MixinForwarderCore.sol b/contracts/exchange-forwarder/contracts/src/MixinForwarderCore.sol index b06d035565..25f3e6ee4e 100644 --- a/contracts/exchange-forwarder/contracts/src/MixinForwarderCore.sol +++ b/contracts/exchange-forwarder/contracts/src/MixinForwarderCore.sol @@ -51,7 +51,7 @@ contract MixinForwarderCore is { address proxyAddress = EXCHANGE.getAssetProxy(ERC20_DATA_ID); if (proxyAddress == address(0)) { - LibRichErrors._rrevert(LibForwarderRichErrors.UnregisteredAssetProxyError()); + LibRichErrors.rrevert(LibForwarderRichErrors.UnregisteredAssetProxyError()); } ETHER_TOKEN.approve(proxyAddress, MAX_UINT); } @@ -81,9 +81,9 @@ contract MixinForwarderCore is _convertEthToWeth(); // Calculate amount of WETH that won't be spent on the forwarder fee. - uint256 wethSellAmount = _getPartialAmountFloor( + uint256 wethSellAmount = getPartialAmountFloor( PERCENTAGE_DENOMINATOR, - _safeAdd(PERCENTAGE_DENOMINATOR, feePercentage), + feePercentage.safeAdd(PERCENTAGE_DENOMINATOR), msg.value ); diff --git a/contracts/exchange-forwarder/contracts/src/MixinWeth.sol b/contracts/exchange-forwarder/contracts/src/MixinWeth.sol index dce1dab29f..d14c284f37 100644 --- a/contracts/exchange-forwarder/contracts/src/MixinWeth.sol +++ b/contracts/exchange-forwarder/contracts/src/MixinWeth.sol @@ -34,7 +34,7 @@ contract MixinWeth is payable { if (msg.sender != address(ETHER_TOKEN)) { - LibRichErrors._rrevert(LibForwarderRichErrors.DefaultFunctionWethContractOnlyError( + LibRichErrors.rrevert(LibForwarderRichErrors.DefaultFunctionWethContractOnlyError( msg.sender )); } @@ -45,7 +45,7 @@ contract MixinWeth is internal { if (msg.value <= 0) { - LibRichErrors._rrevert(LibForwarderRichErrors.InvalidMsgValueError()); + LibRichErrors.rrevert(LibForwarderRichErrors.InvalidMsgValueError()); } ETHER_TOKEN.deposit.value(msg.value)(); } @@ -66,24 +66,24 @@ contract MixinWeth is { // Ensure feePercentage is less than 5%. if (feePercentage > MAX_FEE_PERCENTAGE) { - LibRichErrors._rrevert(LibForwarderRichErrors.FeePercentageTooLargeError( + LibRichErrors.rrevert(LibForwarderRichErrors.FeePercentageTooLargeError( feePercentage )); } // Ensure that no extra WETH owned by this contract has been sold. if (wethSold > msg.value) { - LibRichErrors._rrevert(LibForwarderRichErrors.OversoldWethError( + LibRichErrors.rrevert(LibForwarderRichErrors.OversoldWethError( wethSold, msg.value )); } // Calculate amount of WETH that hasn't been sold. - uint256 wethRemaining = _safeSub(msg.value, wethSold); + uint256 wethRemaining = msg.value.safeSub(wethSold); // Calculate ETH fee to pay to feeRecipient. - ethFee = _getPartialAmountFloor( + ethFee = getPartialAmountFloor( feePercentage, PERCENTAGE_DENOMINATOR, wethSold @@ -91,7 +91,7 @@ contract MixinWeth is // Ensure fee is less than amount of WETH remaining. if (ethFee > wethRemaining) { - LibRichErrors._rrevert(LibForwarderRichErrors.InsufficientEthForFeeError()); + LibRichErrors.rrevert(LibForwarderRichErrors.InsufficientEthForFeeError()); } // Do nothing if no WETH remaining @@ -105,7 +105,7 @@ contract MixinWeth is } // Refund remaining ETH to msg.sender. - uint256 ethRefund = _safeSub(wethRemaining, ethFee); + uint256 ethRefund = wethRemaining.safeSub(ethFee); if (ethRefund > 0) { msg.sender.transfer(ethRefund); }