diff --git a/contracts/exchange/contracts/src/libs/LibExchangeRichErrorDecoder.sol b/contracts/exchange/contracts/src/libs/LibExchangeRichErrorDecoder.sol index 81b6f97630..e4ab2dcb7c 100644 --- a/contracts/exchange/contracts/src/libs/LibExchangeRichErrorDecoder.sol +++ b/contracts/exchange/contracts/src/libs/LibExchangeRichErrorDecoder.sol @@ -136,61 +136,27 @@ contract LibExchangeRichErrorDecoder { orderStatus = LibOrder.OrderStatus(_orderStatus); } - /// @dev Decompose an ABI-encoded InvalidSenderError. + /// @dev Decompose an ABI-encoded OrderStatusError. /// @param encoded ABI-encoded revert error. + /// @return errorCode Error code that corresponds to invalid maker, taker, or sender. /// @return orderHash The order hash. - /// @return senderAddress The sender. - function decodeInvalidSenderError(bytes memory encoded) + /// @return contextAddress The maker, taker, or sender address + function decodeExchangeInvalidContextError(bytes memory encoded) public pure returns ( + LibExchangeRichErrors.ExchangeContextErrorCodes errorCode, bytes32 orderHash, - address senderAddress + address contextAddress ) { - _assertSelectorBytes(encoded, LibExchangeRichErrors.InvalidSenderErrorSelector()); - (orderHash, senderAddress) = abi.decode( + _assertSelectorBytes(encoded, LibExchangeRichErrors.ExchangeInvalidContextErrorSelector()); + uint8 _errorCode; + (_errorCode, orderHash, contextAddress) = abi.decode( encoded.sliceDestructive(4, encoded.length), - (bytes32, address) - ); - } - - /// @dev Decompose an ABI-encoded InvalidMakerError. - /// @param encoded ABI-encoded revert error. - /// @return orderHash The order hash. - /// @return makerAddress The maker of the order. - function decodeInvalidMakerError(bytes memory encoded) - public - pure - returns ( - bytes32 orderHash, - address makerAddress - ) - { - _assertSelectorBytes(encoded, LibExchangeRichErrors.InvalidMakerErrorSelector()); - (orderHash, makerAddress) = abi.decode( - encoded.sliceDestructive(4, encoded.length), - (bytes32, address) - ); - } - - /// @dev Decompose an ABI-encoded InvalidTaker. - /// @param encoded ABI-encoded revert error. - /// @return orderHash The order hash. - /// @return takerAddress The taker of the order. - function decodeInvalidTakerError(bytes memory encoded) - public - pure - returns ( - bytes32 orderHash, - address takerAddress - ) - { - _assertSelectorBytes(encoded, LibExchangeRichErrors.InvalidTakerErrorSelector()); - (orderHash, takerAddress) = abi.decode( - encoded.sliceDestructive(4, encoded.length), - (bytes32, address) + (uint8, bytes32, address) ); + errorCode = LibExchangeRichErrors.ExchangeContextErrorCodes(_errorCode); } /// @dev Decompose an ABI-encoded FillError. diff --git a/contracts/exchange/contracts/test/TestExchangeInternals.sol b/contracts/exchange/contracts/test/TestExchangeInternals.sol index d26cc5b848..991928b13e 100644 --- a/contracts/exchange/contracts/test/TestExchangeInternals.sol +++ b/contracts/exchange/contracts/test/TestExchangeInternals.sol @@ -51,8 +51,8 @@ contract TestExchangeInternals is _assertValidMatch( leftOrder, rightOrder, - getOrderInfo(leftOrder), - getOrderInfo(rightOrder) + leftOrder.getTypedDataHash(EIP712_EXCHANGE_DOMAIN_HASH), + rightOrder.getTypedDataHash(EIP712_EXCHANGE_DOMAIN_HASH) ); } diff --git a/contracts/exchange/test/core.ts b/contracts/exchange/test/core.ts index 05cfd1dbba..83d1c4fb02 100644 --- a/contracts/exchange/test/core.ts +++ b/contracts/exchange/test/core.ts @@ -493,7 +493,11 @@ blockchainTests.resets('Exchange core', () => { it('should revert if not sent by maker', async () => { const orderHash = orderHashUtils.getOrderHashHex(signedOrder); - const expectedError = new ExchangeRevertErrors.InvalidMakerError(orderHash, takerAddress); + const expectedError = new ExchangeRevertErrors.ExchangeInvalidContextError( + ExchangeRevertErrors.ExchangeContextErrorCodes.InvalidMaker, + orderHash, + takerAddress, + ); const tx = exchangeWrapper.cancelOrderAsync(signedOrder, takerAddress); return expect(tx).to.revertWith(expectedError); }); diff --git a/contracts/exchange/test/isolated_fill_order.ts b/contracts/exchange/test/isolated_fill_order.ts index bb15855cf6..7d9b0d9afc 100644 --- a/contracts/exchange/test/isolated_fill_order.ts +++ b/contracts/exchange/test/isolated_fill_order.ts @@ -387,7 +387,8 @@ blockchainTests('Isolated fillOrder() tests', env => { const order = createOrder({ takerAddress: randomAddress(), }); - const expectedError = new ExchangeRevertErrors.InvalidTakerError( + const expectedError = new ExchangeRevertErrors.ExchangeInvalidContextError( + ExchangeRevertErrors.ExchangeContextErrorCodes.InvalidTaker, exchange.getOrderHash(order), takerAddress, ); @@ -398,7 +399,8 @@ blockchainTests('Isolated fillOrder() tests', env => { const order = createOrder({ senderAddress: randomAddress(), }); - const expectedError = new ExchangeRevertErrors.InvalidSenderError( + const expectedError = new ExchangeRevertErrors.ExchangeInvalidContextError( + ExchangeRevertErrors.ExchangeContextErrorCodes.InvalidSender, exchange.getOrderHash(order), takerAddress, ); diff --git a/contracts/exchange/test/lib_exchange_rich_error_decoder.ts b/contracts/exchange/test/lib_exchange_rich_error_decoder.ts index bf58515a86..34ea7b22cc 100644 --- a/contracts/exchange/test/lib_exchange_rich_error_decoder.ts +++ b/contracts/exchange/test/lib_exchange_rich_error_decoder.ts @@ -79,9 +79,21 @@ blockchainTests.resets('LibExchangeRichErrorDecoder', ({ provider, txDefaults }) (() => { const orderHash = orderUtils.generatePseudoRandomOrderHash(); const address = addressUtils.generatePseudoRandomAddress(); - createDecodeTest(ExchangeRevertErrors.InvalidSenderError, [orderHash, address]); - createDecodeTest(ExchangeRevertErrors.InvalidMakerError, [orderHash, address]); - createDecodeTest(ExchangeRevertErrors.InvalidTakerError, [orderHash, address]); + createDecodeTest(ExchangeRevertErrors.ExchangeInvalidContextError, [ + ExchangeRevertErrors.ExchangeContextErrorCodes.InvalidMaker, + orderHash, + address, + ]); + createDecodeTest(ExchangeRevertErrors.ExchangeInvalidContextError, [ + ExchangeRevertErrors.ExchangeContextErrorCodes.InvalidTaker, + orderHash, + address, + ]); + createDecodeTest(ExchangeRevertErrors.ExchangeInvalidContextError, [ + ExchangeRevertErrors.ExchangeContextErrorCodes.InvalidSender, + orderHash, + address, + ]); })(); (() => { diff --git a/contracts/exchange/test/transactions.ts b/contracts/exchange/test/transactions.ts index 1fe9b852ab..69c5dd3b65 100644 --- a/contracts/exchange/test/transactions.ts +++ b/contracts/exchange/test/transactions.ts @@ -423,7 +423,8 @@ blockchainTests.resets('Exchange transactions', env => { const data = exchangeDataEncoder.encodeOrdersToExchangeData(ExchangeFunctionName.CancelOrder, orders); const transaction = await takerTransactionFactory.newSignedTransactionAsync({ data }); const transactionHashHex = transactionHashUtils.getTransactionHashHex(transaction); - const nestedError = new ExchangeRevertErrors.InvalidMakerError( + const nestedError = new ExchangeRevertErrors.ExchangeInvalidContextError( + ExchangeRevertErrors.ExchangeContextErrorCodes.InvalidMaker, orderHashUtils.getOrderHashHex(order), takerAddress, ).encode(); @@ -479,7 +480,8 @@ blockchainTests.resets('Exchange transactions', env => { ); const transaction = await takerTransactionFactory.newSignedTransactionAsync({ data }); const transactionHashHex = transactionHashUtils.getTransactionHashHex(transaction); - const nestedError = new ExchangeRevertErrors.InvalidMakerError( + const nestedError = new ExchangeRevertErrors.ExchangeInvalidContextError( + ExchangeRevertErrors.ExchangeContextErrorCodes.InvalidMaker, orderHashUtils.getOrderHashHex(orders[0]), takerAddress, ).encode(); diff --git a/contracts/exchange/test/utils/fill_order_combinatorial_utils.ts b/contracts/exchange/test/utils/fill_order_combinatorial_utils.ts index d3ce5693ae..c53a51ead2 100644 --- a/contracts/exchange/test/utils/fill_order_combinatorial_utils.ts +++ b/contracts/exchange/test/utils/fill_order_combinatorial_utils.ts @@ -1045,7 +1045,10 @@ function fillErrorToRevertError(order: Order, error: FillOrderError): RevertErro const orderHash = orderHashUtils.getOrderHashHex(order); switch (error) { case FillOrderError.InvalidTaker: - return new ExchangeRevertErrors.InvalidTakerError(orderHash); + return new ExchangeRevertErrors.ExchangeInvalidContextError( + ExchangeRevertErrors.ExchangeContextErrorCodes.InvalidTaker, + orderHash, + ); case FillOrderError.InvalidMakerAmount: case FillOrderError.OrderUnfillable: return new ExchangeRevertErrors.OrderStatusError(orderHash);