use new lib function names

This commit is contained in:
Michael Zhu 2019-08-17 15:51:20 -07:00
parent 1934dddcbe
commit 146d56be84
5 changed files with 50 additions and 65 deletions

View File

@ -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 - 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. # TODO(dorothy-zbornak): Re-enable after updating this package for 3.0.
# - run: yarn wsrun test:circleci @0x/contracts-extensions # - 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. # TODO(abandeali): Re-enable after this package is complete.
# - run: yarn wsrun test:circleci @0x/contracts-coordinator # - run: yarn wsrun test:circleci @0x/contracts-coordinator
test-contracts-geth: test-contracts-geth:

View File

@ -66,7 +66,7 @@ contract MixinAssets is
if (proxyId == ERC20_DATA_ID) { if (proxyId == ERC20_DATA_ID) {
address proxyAddress = EXCHANGE.getAssetProxy(ERC20_DATA_ID); address proxyAddress = EXCHANGE.getAssetProxy(ERC20_DATA_ID);
if (proxyAddress == address(0)) { if (proxyAddress == address(0)) {
LibRichErrors._rrevert(LibForwarderRichErrors.UnregisteredAssetProxyError()); LibRichErrors.rrevert(LibForwarderRichErrors.UnregisteredAssetProxyError());
} }
IERC20Token assetToken = IERC20Token(assetData.readAddress(16)); IERC20Token assetToken = IERC20Token(assetData.readAddress(16));
if (assetToken.allowance(address(this), proxyAddress) != MAX_UINT) { if (assetToken.allowance(address(this), proxyAddress) != MAX_UINT) {
@ -91,7 +91,7 @@ contract MixinAssets is
} else if (proxyId == ERC721_DATA_ID) { } else if (proxyId == ERC721_DATA_ID) {
_transferERC721Token(assetData, amount); _transferERC721Token(assetData, amount);
} else { } else {
LibRichErrors._rrevert(LibForwarderRichErrors.UnsupportedAssetProxyError( LibRichErrors.rrevert(LibForwarderRichErrors.UnsupportedAssetProxyError(
proxyId proxyId
)); ));
} }
@ -117,7 +117,7 @@ contract MixinAssets is
amount amount
)); ));
if (!success) { if (!success) {
LibRichErrors._rrevert(LibForwarderRichErrors.TransferFailedError()); LibRichErrors.rrevert(LibForwarderRichErrors.TransferFailedError());
} }
// Check return data. // Check return data.
@ -137,7 +137,7 @@ contract MixinAssets is
} }
} }
if (!success) { if (!success) {
LibRichErrors._rrevert(LibForwarderRichErrors.TransferFailedError()); LibRichErrors.rrevert(LibForwarderRichErrors.TransferFailedError());
} }
} }
@ -151,7 +151,7 @@ contract MixinAssets is
internal internal
{ {
if (amount != 1) { if (amount != 1) {
LibRichErrors._rrevert(LibForwarderRichErrors.InvalidErc721AmountError( LibRichErrors.rrevert(LibForwarderRichErrors.InvalidErc721AmountError(
amount amount
)); ));
} }

View File

@ -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/LibOrder.sol";
import "@0x/contracts-exchange-libs/contracts/src/LibFillResults.sol"; import "@0x/contracts-exchange-libs/contracts/src/LibFillResults.sol";
import "@0x/contracts-exchange-libs/contracts/src/LibMath.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"; import "./libs/LibForwarderRichErrors.sol";
contract MixinExchangeWrapper is contract MixinExchangeWrapper is
LibConstants,
LibFillResults, LibFillResults,
LibMath, LibMath
LibConstants
{ {
/// @dev Fills the input order. /// @dev Fills the input order.
/// Returns false if the transaction would otherwise revert. /// Returns false if the transaction would otherwise revert.
@ -95,10 +97,7 @@ contract MixinExchangeWrapper is
returns (FillResults memory singleFillResults) returns (FillResults memory singleFillResults)
{ {
// The remaining amount of WETH to sell // The remaining amount of WETH to sell
uint256 remainingTakerAssetFillAmount = _safeSub( uint256 remainingTakerAssetFillAmount = wethSellAmount.safeSub(wethSpentAmount);
wethSellAmount,
wethSpentAmount
);
// Percentage fee // Percentage fee
if (order.makerAssetData.equals(order.takerFeeAssetData)) { if (order.makerAssetData.equals(order.takerFeeAssetData)) {
@ -112,9 +111,9 @@ contract MixinExchangeWrapper is
} else if (order.takerFeeAssetData.equals(order.takerAssetData)) { } else if (order.takerFeeAssetData.equals(order.takerAssetData)) {
// We will first sell WETH as the takerAsset, then use it to pay the takerFee. // 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. // This ensures that we reserve enough to pay the fee.
uint256 takerAssetFillAmount = _getPartialAmountCeil( uint256 takerAssetFillAmount = getPartialAmountCeil(
order.takerAssetAmount, order.takerAssetAmount,
_safeAdd(order.takerAssetAmount, order.takerFee), order.takerAssetAmount.safeAdd(order.takerFee),
remainingTakerAssetFillAmount remainingTakerAssetFillAmount
); );
@ -124,7 +123,7 @@ contract MixinExchangeWrapper is
signature signature
); );
} else { } 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++) { for (uint256 i = 0; i != ordersLength; i++) {
if (!orders[i].makerAssetData.equals(orders[0].makerAssetData)) { if (!orders[i].makerAssetData.equals(orders[0].makerAssetData)) {
LibRichErrors._rrevert(LibForwarderRichErrors.MakerAssetMismatchError( LibRichErrors.rrevert(LibForwarderRichErrors.MakerAssetMismatchError(
orders[0].makerAssetData, orders[0].makerAssetData,
orders[i].makerAssetData orders[i].makerAssetData
)); ));
@ -165,25 +164,19 @@ contract MixinExchangeWrapper is
// Percentage fee // Percentage fee
if (orders[i].takerFeeAssetData.equals(orders[i].makerAssetData)) { if (orders[i].takerFeeAssetData.equals(orders[i].makerAssetData)) {
// Subtract fee from makerAssetFilledAmount for the net amount acquired. // Subtract fee from makerAssetFilledAmount for the net amount acquired.
makerAssetAcquiredAmount = _safeAdd( makerAssetAcquiredAmount = makerAssetAcquiredAmount.safeAdd(
makerAssetAcquiredAmount, singleFillResults.makerAssetFilledAmount
_safeSub(singleFillResults.makerAssetFilledAmount, singleFillResults.takerFeePaid) ).safeSub(singleFillResults.takerFeePaid);
);
wethSpentAmount = _safeAdd( wethSpentAmount = wethSpentAmount.safeAdd(singleFillResults.takerAssetFilledAmount);
wethSpentAmount,
singleFillResults.takerAssetFilledAmount
);
// WETH fee // WETH fee
} else { } else {
// WETH is also spent on the taker fee, so we add it here. // WETH is also spent on the taker fee, so we add it here.
wethSpentAmount = _safeAdd( wethSpentAmount = wethSpentAmount.safeAdd(
wethSpentAmount, singleFillResults.takerAssetFilledAmount
_safeAdd(singleFillResults.takerAssetFilledAmount, singleFillResults.takerFeePaid) ).safeAdd(singleFillResults.takerFeePaid);
);
makerAssetAcquiredAmount = _safeAdd( makerAssetAcquiredAmount = makerAssetAcquiredAmount.safeAdd(
makerAssetAcquiredAmount,
singleFillResults.makerAssetFilledAmount singleFillResults.makerAssetFilledAmount
); );
} }
@ -215,10 +208,10 @@ contract MixinExchangeWrapper is
// Percentage fee // Percentage fee
if (order.takerFeeAssetData.equals(order.makerAssetData)) { if (order.takerFeeAssetData.equals(order.makerAssetData)) {
// Calculate the remaining amount of takerAsset to sell // Calculate the remaining amount of takerAsset to sell
uint256 remainingTakerAssetFillAmount = _getPartialAmountCeil( uint256 remainingTakerAssetFillAmount = getPartialAmountCeil(
order.takerAssetAmount, order.takerAssetAmount,
_safeSub(order.makerAssetAmount, order.takerFee), order.makerAssetAmount.safeSub(order.takerFee),
_safeSub(makerAssetBuyAmount, makerAssetAcquiredAmount) makerAssetBuyAmount.safeSub(makerAssetAcquiredAmount)
); );
// Attempt to sell the remaining amount of takerAsset // Attempt to sell the remaining amount of takerAsset
@ -230,10 +223,10 @@ contract MixinExchangeWrapper is
// WETH fee // WETH fee
} else if (order.takerFeeAssetData.equals(order.takerAssetData)) { } else if (order.takerFeeAssetData.equals(order.takerAssetData)) {
// Calculate the remaining amount of takerAsset to sell // Calculate the remaining amount of takerAsset to sell
uint256 remainingTakerAssetFillAmount = _getPartialAmountCeil( uint256 remainingTakerAssetFillAmount = getPartialAmountCeil(
order.takerAssetAmount, order.takerAssetAmount,
order.makerAssetAmount, order.makerAssetAmount,
_safeSub(makerAssetBuyAmount, makerAssetAcquiredAmount) makerAssetBuyAmount.safeSub(makerAssetAcquiredAmount)
); );
// Attempt to sell the remaining amount of takerAsset // Attempt to sell the remaining amount of takerAsset
@ -243,7 +236,7 @@ contract MixinExchangeWrapper is
signature signature
); );
} else { } else {
LibRichErrors._rrevert(LibForwarderRichErrors.UnsupportedFeeError(order.takerFeeAssetData)); LibRichErrors.rrevert(LibForwarderRichErrors.UnsupportedFeeError(order.takerFeeAssetData));
} }
} }
@ -269,7 +262,7 @@ contract MixinExchangeWrapper is
uint256 ordersLength = orders.length; uint256 ordersLength = orders.length;
for (uint256 i = 0; i != ordersLength; i++) { for (uint256 i = 0; i != ordersLength; i++) {
if (!orders[i].makerAssetData.equals(orders[0].makerAssetData)) { if (!orders[i].makerAssetData.equals(orders[0].makerAssetData)) {
LibRichErrors._rrevert(LibForwarderRichErrors.MakerAssetMismatchError( LibRichErrors.rrevert(LibForwarderRichErrors.MakerAssetMismatchError(
orders[0].makerAssetData, orders[0].makerAssetData,
orders[i].makerAssetData orders[i].makerAssetData
)); ));
@ -285,27 +278,23 @@ contract MixinExchangeWrapper is
// Percentage fee // Percentage fee
if (orders[i].takerFeeAssetData.equals(orders[i].makerAssetData)) { if (orders[i].takerFeeAssetData.equals(orders[i].makerAssetData)) {
// Subtract fee from makerAssetFilledAmount for the net amount acquired. // Subtract fee from makerAssetFilledAmount for the net amount acquired.
makerAssetAcquiredAmount = _safeAdd( makerAssetAcquiredAmount = makerAssetAcquiredAmount.safeAdd(
makerAssetAcquiredAmount, singleFillResults.makerAssetFilledAmount
_safeSub(singleFillResults.makerAssetFilledAmount, singleFillResults.takerFeePaid) ).safeSub(singleFillResults.takerFeePaid);
);
wethSpentAmount = _safeAdd( wethSpentAmount = wethSpentAmount.safeAdd(
wethSpentAmount,
singleFillResults.takerAssetFilledAmount singleFillResults.takerAssetFilledAmount
); );
// WETH fee // WETH fee
} else { } else {
makerAssetAcquiredAmount = _safeAdd( makerAssetAcquiredAmount = makerAssetAcquiredAmount.safeAdd(
makerAssetAcquiredAmount,
singleFillResults.makerAssetFilledAmount singleFillResults.makerAssetFilledAmount
); );
// WETH is also spent on the taker fee, so we add it here. // WETH is also spent on the taker fee, so we add it here.
wethSpentAmount = _safeAdd( wethSpentAmount = wethSpentAmount.safeAdd(
wethSpentAmount, singleFillResults.takerAssetFilledAmount
_safeAdd(singleFillResults.takerAssetFilledAmount, singleFillResults.takerFeePaid) ).safeAdd(singleFillResults.takerFeePaid);
);
} }
// Stop execution if the entire amount of makerAsset has been bought // Stop execution if the entire amount of makerAsset has been bought
@ -315,7 +304,7 @@ contract MixinExchangeWrapper is
} }
if (makerAssetAcquiredAmount < makerAssetBuyAmount) { if (makerAssetAcquiredAmount < makerAssetBuyAmount) {
LibRichErrors._rrevert(LibForwarderRichErrors.CompleteFillFailedError()); LibRichErrors.rrevert(LibForwarderRichErrors.CompleteFillFailedError());
} }
return (wethSpentAmount, makerAssetAcquiredAmount); return (wethSpentAmount, makerAssetAcquiredAmount);

View File

@ -51,7 +51,7 @@ contract MixinForwarderCore is
{ {
address proxyAddress = EXCHANGE.getAssetProxy(ERC20_DATA_ID); address proxyAddress = EXCHANGE.getAssetProxy(ERC20_DATA_ID);
if (proxyAddress == address(0)) { if (proxyAddress == address(0)) {
LibRichErrors._rrevert(LibForwarderRichErrors.UnregisteredAssetProxyError()); LibRichErrors.rrevert(LibForwarderRichErrors.UnregisteredAssetProxyError());
} }
ETHER_TOKEN.approve(proxyAddress, MAX_UINT); ETHER_TOKEN.approve(proxyAddress, MAX_UINT);
} }
@ -81,9 +81,9 @@ contract MixinForwarderCore is
_convertEthToWeth(); _convertEthToWeth();
// Calculate amount of WETH that won't be spent on the forwarder fee. // Calculate amount of WETH that won't be spent on the forwarder fee.
uint256 wethSellAmount = _getPartialAmountFloor( uint256 wethSellAmount = getPartialAmountFloor(
PERCENTAGE_DENOMINATOR, PERCENTAGE_DENOMINATOR,
_safeAdd(PERCENTAGE_DENOMINATOR, feePercentage), feePercentage.safeAdd(PERCENTAGE_DENOMINATOR),
msg.value msg.value
); );

View File

@ -34,7 +34,7 @@ contract MixinWeth is
payable payable
{ {
if (msg.sender != address(ETHER_TOKEN)) { if (msg.sender != address(ETHER_TOKEN)) {
LibRichErrors._rrevert(LibForwarderRichErrors.DefaultFunctionWethContractOnlyError( LibRichErrors.rrevert(LibForwarderRichErrors.DefaultFunctionWethContractOnlyError(
msg.sender msg.sender
)); ));
} }
@ -45,7 +45,7 @@ contract MixinWeth is
internal internal
{ {
if (msg.value <= 0) { if (msg.value <= 0) {
LibRichErrors._rrevert(LibForwarderRichErrors.InvalidMsgValueError()); LibRichErrors.rrevert(LibForwarderRichErrors.InvalidMsgValueError());
} }
ETHER_TOKEN.deposit.value(msg.value)(); ETHER_TOKEN.deposit.value(msg.value)();
} }
@ -66,24 +66,24 @@ contract MixinWeth is
{ {
// Ensure feePercentage is less than 5%. // Ensure feePercentage is less than 5%.
if (feePercentage > MAX_FEE_PERCENTAGE) { if (feePercentage > MAX_FEE_PERCENTAGE) {
LibRichErrors._rrevert(LibForwarderRichErrors.FeePercentageTooLargeError( LibRichErrors.rrevert(LibForwarderRichErrors.FeePercentageTooLargeError(
feePercentage feePercentage
)); ));
} }
// Ensure that no extra WETH owned by this contract has been sold. // Ensure that no extra WETH owned by this contract has been sold.
if (wethSold > msg.value) { if (wethSold > msg.value) {
LibRichErrors._rrevert(LibForwarderRichErrors.OversoldWethError( LibRichErrors.rrevert(LibForwarderRichErrors.OversoldWethError(
wethSold, wethSold,
msg.value msg.value
)); ));
} }
// Calculate amount of WETH that hasn't been sold. // 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. // Calculate ETH fee to pay to feeRecipient.
ethFee = _getPartialAmountFloor( ethFee = getPartialAmountFloor(
feePercentage, feePercentage,
PERCENTAGE_DENOMINATOR, PERCENTAGE_DENOMINATOR,
wethSold wethSold
@ -91,7 +91,7 @@ contract MixinWeth is
// Ensure fee is less than amount of WETH remaining. // Ensure fee is less than amount of WETH remaining.
if (ethFee > wethRemaining) { if (ethFee > wethRemaining) {
LibRichErrors._rrevert(LibForwarderRichErrors.InsufficientEthForFeeError()); LibRichErrors.rrevert(LibForwarderRichErrors.InsufficientEthForFeeError());
} }
// Do nothing if no WETH remaining // Do nothing if no WETH remaining
@ -105,7 +105,7 @@ contract MixinWeth is
} }
// Refund remaining ETH to msg.sender. // Refund remaining ETH to msg.sender.
uint256 ethRefund = _safeSub(wethRemaining, ethFee); uint256 ethRefund = wethRemaining.safeSub(ethFee);
if (ethRefund > 0) { if (ethRefund > 0) {
msg.sender.transfer(ethRefund); msg.sender.transfer(ethRefund);
} }