Add new rich revert errors

This commit is contained in:
Amir Bandeali 2019-09-03 19:02:22 -07:00
parent e5706606a0
commit f792d403e5
2 changed files with 85 additions and 84 deletions

View File

@ -36,6 +36,12 @@ library LibExchangeRichErrors {
INVALID_LENGTH_RIGHT_SIGNATURES
}
enum ExchangeContextErrorCodes {
INVALID_MAKER,
INVALID_TAKER,
INVALID_SENDER
}
enum FillErrorCodes {
INVALID_TAKER_AMOUNT,
TAKER_OVERPAY,
@ -83,22 +89,14 @@ library LibExchangeRichErrors {
bytes4 internal constant ORDER_STATUS_ERROR_SELECTOR =
0xfdb6ca8d;
// bytes4(keccak256("InvalidSenderError(bytes32,address)"))
bytes4 internal constant INVALID_SENDER_ERROR_SELECTOR =
0x95b59997;
// bytes4(keccak256("InvalidMakerError(bytes32,address)"))
bytes4 internal constant INVALID_MAKER_ERROR_SELECTOR =
0x26bf55d9;
// bytes4(keccak256("ExchangeInvalidContextError(uint8,bytes32,address)"))
bytes4 internal constant EXCHANGE_INVALID_CONTEXT_ERROR_SELECTOR =
0xe53c76c8;
// bytes4(keccak256("FillError(uint8,bytes32)"))
bytes4 internal constant FILL_ERROR_SELECTOR =
0xe94a7ed0;
// bytes4(keccak256("InvalidTakerError(bytes32,address)"))
bytes4 internal constant INVALID_TAKER_ERROR_SELECTOR =
0xfdb328be;
// bytes4(keccak256("OrderEpochError(address,address,uint256)"))
bytes4 internal constant ORDER_EPOCH_ERROR_SELECTOR =
0x4ad31275;
@ -147,6 +145,10 @@ library LibExchangeRichErrors {
bytes4 internal constant BATCH_MATCH_ORDERS_ERROR_SELECTOR =
0xd4092f4f;
// bytes4(keccak256("PayProtocolFeeError(bytes32,uint256,address,address,bytes)"))
bytes4 internal constant PAY_PROTOCOL_FEE_ERROR_SELECTOR =
0x87cb1e75;
// solhint-disable func-name-mixedcase
function SignatureErrorSelector()
internal
@ -188,20 +190,12 @@ library LibExchangeRichErrors {
return ORDER_STATUS_ERROR_SELECTOR;
}
function InvalidSenderErrorSelector()
function ExchangeInvalidContextErrorSelector()
internal
pure
returns (bytes4)
{
return INVALID_SENDER_ERROR_SELECTOR;
}
function InvalidMakerErrorSelector()
internal
pure
returns (bytes4)
{
return INVALID_MAKER_ERROR_SELECTOR;
return EXCHANGE_INVALID_CONTEXT_ERROR_SELECTOR;
}
function FillErrorSelector()
@ -212,14 +206,6 @@ library LibExchangeRichErrors {
return FILL_ERROR_SELECTOR;
}
function InvalidTakerErrorSelector()
internal
pure
returns (bytes4)
{
return INVALID_TAKER_ERROR_SELECTOR;
}
function OrderEpochErrorSelector()
internal
pure
@ -316,6 +302,14 @@ library LibExchangeRichErrors {
return TRANSACTION_INVALID_CONTEXT_ERROR_SELECTOR;
}
function PayProtocolFeeErrorSelector()
internal
pure
returns (bytes4)
{
return PAY_PROTOCOL_FEE_ERROR_SELECTOR;
}
function BatchMatchOrdersError(
BatchMatchOrdersErrorCodes errorCode
)
@ -416,33 +410,20 @@ library LibExchangeRichErrors {
);
}
function InvalidSenderError(
function ExchangeInvalidContextError(
ExchangeContextErrorCodes errorCode,
bytes32 orderHash,
address senderAddress
address contextAddress
)
internal
pure
returns (bytes memory)
{
return abi.encodeWithSelector(
INVALID_SENDER_ERROR_SELECTOR,
EXCHANGE_INVALID_CONTEXT_ERROR_SELECTOR,
errorCode,
orderHash,
senderAddress
);
}
function InvalidMakerError(
bytes32 orderHash,
address makerAddress
)
internal
pure
returns (bytes memory)
{
return abi.encodeWithSelector(
INVALID_MAKER_ERROR_SELECTOR,
orderHash,
makerAddress
contextAddress
);
}
@ -461,21 +442,6 @@ library LibExchangeRichErrors {
);
}
function InvalidTakerError(
bytes32 orderHash,
address takerAddress
)
internal
pure
returns (bytes memory)
{
return abi.encodeWithSelector(
INVALID_TAKER_ERROR_SELECTOR,
orderHash,
takerAddress
);
}
function OrderEpochError(
address makerAddress,
address orderSenderAddress,
@ -652,4 +618,25 @@ library LibExchangeRichErrors {
actualAssetFillAmount
);
}
function PayProtocolFeeError(
bytes32 orderHash,
uint256 protocolFee,
address makerAddress,
address takerAddress,
bytes memory errorData
)
internal
pure
returns (bytes memory)
{
return abi.encodeWithSelector(
PAY_PROTOCOL_FEE_ERROR_SELECTOR,
orderHash,
protocolFee,
makerAddress,
takerAddress,
errorData
);
}
}

View File

@ -11,6 +11,12 @@ export enum BatchMatchOrdersErrorCodes {
InvalidLengthRightSignatures,
}
export enum ExchangeContextErrorCodes {
InvalidMaker,
InvalidTaker,
InvalidSender,
}
export enum FillErrorCode {
InvalidTakerAmount,
TakerOverpay,
@ -109,24 +115,6 @@ export class OrderStatusError extends RevertError {
}
}
export class InvalidSenderError extends RevertError {
constructor(orderHash?: string, sender?: string) {
super('InvalidSenderError', 'InvalidSenderError(bytes32 orderHash, address sender)', { orderHash, sender });
}
}
export class InvalidTakerError extends RevertError {
constructor(orderHash?: string, taker?: string) {
super('InvalidTakerError', 'InvalidTakerError(bytes32 orderHash, address taker)', { orderHash, taker });
}
}
export class InvalidMakerError extends RevertError {
constructor(orderHash?: string, maker?: string) {
super('InvalidMakerError', 'InvalidMakerError(bytes32 orderHash, address maker)', { orderHash, maker });
}
}
export class FillError extends RevertError {
constructor(error?: FillErrorCode, orderHash?: string) {
super('FillError', 'FillError(uint8 error, bytes32 orderHash)', { error, orderHash });
@ -259,6 +247,31 @@ export class IncompleteFillError extends RevertError {
}
}
export class ExchangeInvalidContextError extends RevertError {
constructor(error?: ExchangeContextErrorCodes, orderHash?: string, contextAddress?: string) {
super(
'ExchangeInvalidContextError',
'ExchangeInvalidContextError(uint8 error, bytes32 orderHash, address contextAddress)',
{ error, orderHash, contextAddress },
);
}
}
export class PayProtocolFeeError extends RevertError {
constructor(
orderHash?: string,
protocolFee?: BigNumber,
makerAddress?: string,
takerAddress?: string,
errorData?: string,
) {
super(
'PayProtocolFeeError',
'PayProtocolFeeError(bytes32 orderHash, uint256 protocolFee, address makerAddress, address takerAddress, bytes errorData)',
{ orderHash, protocolFee, makerAddress, takerAddress, errorData },
);
}
}
const types = [
BatchMatchOrdersError,
OrderStatusError,
@ -266,9 +279,6 @@ const types = [
SignatureValidatorNotApprovedError,
SignatureWalletError,
EIP1271SignatureError,
InvalidSenderError,
InvalidTakerError,
InvalidMakerError,
FillError,
OrderEpochError,
AssetProxyExistsError,
@ -276,9 +286,13 @@ const types = [
AssetProxyTransferError,
NegativeSpreadError,
TransactionError,
TransactionGasPriceError,
TransactionInvalidContextError,
TransactionSignatureError,
TransactionExecutionError,
IncompleteFillError,
PayProtocolFeeError,
ExchangeInvalidContextError,
];
// Register the types we've defined.