forwarder rich errors first pass

This commit is contained in:
Michael Zhu
2019-08-07 11:47:18 -07:00
parent c73ae579d3
commit 5879aeac52
4 changed files with 213 additions and 1 deletions

View File

@@ -63,6 +63,10 @@ contract MixinAssets is
// For now we only care about ERC20, since percentage fees on ERC721 tokens are invalid.
if (proxyId == ERC20_DATA_ID) {
address proxyAddress = EXCHANGE.getAssetProxy(ERC20_DATA_ID);
require(
proxyAddress != address(0),
"UNREGISTERED_ASSET_PROXY"
);
IERC20Token assetToken = IERC20Token(assetData.readAddress(16));
if (assetToken.allowance(address(this), proxyAddress) != MAX_UINT) {
assetToken.approve(proxyAddress, MAX_UINT);

View File

@@ -0,0 +1,10 @@
pragma solidity ^0.5.9;
contract IForwarderRichErrors {
enum AssetProxyErrorCodes {
UNREGISTERED_ASSET_PROXY,
UNSUPPORTED_ASSET_PROXY
}
}

View File

@@ -0,0 +1,198 @@
/*
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;
import "@0x/contracts-utils/contracts/src/LibRichErrors.sol";
import "@0x/contracts-exchange-libs/contracts/src/LibOrder.sol";
import "./interfaces/IExchangeRichErrors.sol";
library LibExchangeRichErrors {
// bytes4(keccak256("AssetProxyError(bytes4)"))
bytes4 internal constant ASEST_PROXY_ERROR_SELECTOR =
0xaa3ff166;
// bytes4(keccak256("CompleteFillFailedError(uint256,uint256)"))
bytes4 internal constant COMPLETE_FILL_FAILED_ERROR_SELECTOR =
0x7675a605;
// bytes4(keccak256("MakerAssetMismatchError(bytes,bytes)"))
bytes4 internal constant MAKER_ASSET_MISMATCH_ERROR_SELECTOR =
0x56677f2c;
// bytes4(keccak256("FeePercentageTooLargeError(uint256)"))
bytes4 internal constant FEE_PERCENTAGE_TOO_LARGE_ERROR_SELECTOR =
0x1174fb80;
// bytes4(keccak256("InsufficientEthRemainingError(uint256,uint256)"))
bytes4 internal constant INSUFFICIENT_ETH_REMAINING_ERROR_SELECTOR =
0x01b718a6;
// bytes4(keccak256("OversoldWethError(uint256,uint256)"))
bytes4 internal constant OVERSOLD_WETH_ERROR_SELECTOR =
0x5cc555c8;
// bytes4(keccak256("TransferFailedError()"))
bytes4 internal constant TRANSFER_FAILED_ERROR_SELECTOR =
0x570f1df4;
// bytes4(keccak256("DefaultFunctionWethContractOnlyError(address)"))
bytes4 internal constant DEFAULT_FUNCTION_WETH_CONTRACT_ONLY_ERROR_SELECTOR =
0x08b18698;
// bytes4(keccak256("InvalidMsgValueError()"))
bytes4 internal constant INVALID_MSG_VALUE_ERROR_SELECTOR =
0xb0658a43;
// bytes4(keccak256("InvalidErc721AmountError(uint256)"))
bytes4 internal constant INVALID_ERC721_AMOUNT_ERROR_SELECTOR =
0x27ed87bf;
// solhint-disable func-name-mixedcase
function AssetProxyError(
IForwarderRichErrors.AssetProxyErrorCodes errorCode,
bytes4 proxyId
)
internal
pure
returns (bytes memory)
{
return abi.encodeWithSelector(
ASSET_PROXY_ERROR_SELECTOR,
proxyId
);
}
function CompleteFillFailedError(
uint256 desiredFillAmount,
uint256 actualFillAmount
)
internal
pure
returns (bytes memory)
{
return abi.encodeWithSelector(
COMPLETE_FILL_FAILED_ERROR_SELECTOR,
desiredFillAmount,
actualFillAmount
);
}
function MakerAssetMismatchError(
bytes memory firstOrderMakerAssetData,
bytes memory mismatchedMakerAssetData
)
internal
pure
returns (bytes memory)
{
return abi.encodeWithSelector(
MAKER_ASSET_MISMATCH_ERROR_SELECTOR,
firstOrderMakerAssetData,
mismatchedMakerAssetData
);
}
function FeePercentageTooLargeError(
uint256 feePercentage
)
internal
pure
returns (bytes memory)
{
return abi.encodeWithSelector(
FEE_PERCENTAGE_TOO_LARGE_ERROR_SELECTOR,
feePercentage
);
}
function InsufficientEthRemainingError(
uint256 ethFee,
uint256 wethRemaining
)
internal
pure
returns (bytes memory)
{
return abi.encodeWithSelector(
INSUFFICIENT_ETH_REMAINING_ERROR_SELECTOR,
ethFee,
wethRemaining
);
}
function OversoldWethError(
uint256 wethSold,
uint256 msgValue
)
internal
pure
returns (bytes memory)
{
return abi.encodeWithSelector(
OVERSOLD_WETH_ERROR_SELECTOR,
wethSold,
msgValue
);
}
function TransferFailedError()
internal
pure
returns (bytes memory)
{
return TRANSFER_FAILED_ERROR_SELECTOR;
}
function DefaultFunctionWethContractOnlyError(
address callerAddress
)
internal
pure
returns (bytes memory)
{
return abi.encodeWithSelector(
DEFAULT_FUNCTION_WETH_CONTRACT_ONLY_ERROR_SELECTOR,
callerAddress
);
}
function InvalidMsgValueError()
internal
pure
returns (bytes memory)
{
return INVALID_MSG_VALUE_ERROR_SELECTOR;
}
function InvalidErc721AmountError(
uint256 amount
)
internal
pure
returns (bytes memory)
{
return abi.encodeWithSelector(
INVALID_ERC721_AMOUNT_ERROR_SELECTOR,
amount
);
}
}