diff options
-rw-r--r-- | packages/contracts/src/contracts/current/protocol/Exchange/MixinExchangeCore.sol | 126 | ||||
-rw-r--r-- | packages/contracts/src/contracts/current/protocol/Exchange/interfaces/IExchangeCore.sol | 28 |
2 files changed, 77 insertions, 77 deletions
diff --git a/packages/contracts/src/contracts/current/protocol/Exchange/MixinExchangeCore.sol b/packages/contracts/src/contracts/current/protocol/Exchange/MixinExchangeCore.sol index 3e14e4cb4..5ad36f501 100644 --- a/packages/contracts/src/contracts/current/protocol/Exchange/MixinExchangeCore.sol +++ b/packages/contracts/src/contracts/current/protocol/Exchange/MixinExchangeCore.sol @@ -67,69 +67,6 @@ contract MixinExchangeCore is emit CancelUpTo(msg.sender, newMakerEpoch); } - /// @dev Gets information about an order: status, hash, and amount filled. - /// @param order Order to gather information on. - /// @return status Status of order. Statuses are defined in the LibStatus.Status struct. - /// @return orderHash Keccak-256 EIP712 hash of the order. - /// @return takerAssetFilledAmount Amount of order that has been filled. - function getOrderInfo(Order memory order) - public - view - returns ( - uint8 orderStatus, - bytes32 orderHash, - uint256 takerAssetFilledAmount - ) - { - // Compute the order hash - orderHash = getOrderHash(order); - - // If order.makerAssetAmount is zero, we also reject the order. - // While the Exchange contract handles them correctly, they create - // edge cases in the supporting infrastructure because they have - // an 'infinite' price when computed by a simple division. - if (order.makerAssetAmount == 0) { - orderStatus = uint8(Status.ORDER_INVALID_MAKER_ASSET_AMOUNT); - return (orderStatus, orderHash, takerAssetFilledAmount); - } - - // If order.takerAssetAmount is zero, then the order will always - // be considered filled because 0 == takerAssetAmount == takerAssetFilledAmount - // Instead of distinguishing between unfilled and filled zero taker - // amount orders, we choose not to support them. - if (order.takerAssetAmount == 0) { - orderStatus = uint8(Status.ORDER_INVALID_TAKER_ASSET_AMOUNT); - return (orderStatus, orderHash, takerAssetFilledAmount); - } - - // Validate order expiration - if (block.timestamp >= order.expirationTimeSeconds) { - orderStatus = uint8(Status.ORDER_EXPIRED); - return (orderStatus, orderHash, takerAssetFilledAmount); - } - - // Check if order has been cancelled - if (cancelled[orderHash]) { - orderStatus = uint8(Status.ORDER_CANCELLED); - return (orderStatus, orderHash, takerAssetFilledAmount); - } - if (makerEpoch[order.makerAddress] > order.salt) { - orderStatus = uint8(Status.ORDER_CANCELLED); - return (orderStatus, orderHash, takerAssetFilledAmount); - } - - // Fetch filled amount and validate order availability - takerAssetFilledAmount = filled[orderHash]; - if (takerAssetFilledAmount >= order.takerAssetAmount) { - orderStatus = uint8(Status.ORDER_FULLY_FILLED); - return (orderStatus, orderHash, takerAssetFilledAmount); - } - - // All other statuses are ruled out: order is Fillable - orderStatus = uint8(Status.ORDER_FILLABLE); - return (orderStatus, orderHash, takerAssetFilledAmount); - } - /// @dev Fills the input order. /// @param order Order struct containing order specifications. /// @param takerAssetFillAmount Desired amount of takerToken to sell. @@ -450,4 +387,67 @@ contract MixinExchangeCore is return stateUpdated; } + + /// @dev Gets information about an order: status, hash, and amount filled. + /// @param order Order to gather information on. + /// @return status Status of order. Statuses are defined in the LibStatus.Status struct. + /// @return orderHash Keccak-256 EIP712 hash of the order. + /// @return takerAssetFilledAmount Amount of order that has been filled. + function getOrderInfo(Order memory order) + public + view + returns ( + uint8 orderStatus, + bytes32 orderHash, + uint256 takerAssetFilledAmount + ) + { + // Compute the order hash + orderHash = getOrderHash(order); + + // If order.makerAssetAmount is zero, we also reject the order. + // While the Exchange contract handles them correctly, they create + // edge cases in the supporting infrastructure because they have + // an 'infinite' price when computed by a simple division. + if (order.makerAssetAmount == 0) { + orderStatus = uint8(Status.ORDER_INVALID_MAKER_ASSET_AMOUNT); + return (orderStatus, orderHash, takerAssetFilledAmount); + } + + // If order.takerAssetAmount is zero, then the order will always + // be considered filled because 0 == takerAssetAmount == takerAssetFilledAmount + // Instead of distinguishing between unfilled and filled zero taker + // amount orders, we choose not to support them. + if (order.takerAssetAmount == 0) { + orderStatus = uint8(Status.ORDER_INVALID_TAKER_ASSET_AMOUNT); + return (orderStatus, orderHash, takerAssetFilledAmount); + } + + // Validate order expiration + if (block.timestamp >= order.expirationTimeSeconds) { + orderStatus = uint8(Status.ORDER_EXPIRED); + return (orderStatus, orderHash, takerAssetFilledAmount); + } + + // Check if order has been cancelled + if (cancelled[orderHash]) { + orderStatus = uint8(Status.ORDER_CANCELLED); + return (orderStatus, orderHash, takerAssetFilledAmount); + } + if (makerEpoch[order.makerAddress] > order.salt) { + orderStatus = uint8(Status.ORDER_CANCELLED); + return (orderStatus, orderHash, takerAssetFilledAmount); + } + + // Fetch filled amount and validate order availability + takerAssetFilledAmount = filled[orderHash]; + if (takerAssetFilledAmount >= order.takerAssetAmount) { + orderStatus = uint8(Status.ORDER_FULLY_FILLED); + return (orderStatus, orderHash, takerAssetFilledAmount); + } + + // All other statuses are ruled out: order is Fillable + orderStatus = uint8(Status.ORDER_FILLABLE); + return (orderStatus, orderHash, takerAssetFilledAmount); + } } diff --git a/packages/contracts/src/contracts/current/protocol/Exchange/interfaces/IExchangeCore.sol b/packages/contracts/src/contracts/current/protocol/Exchange/interfaces/IExchangeCore.sol index f97c74123..d62690933 100644 --- a/packages/contracts/src/contracts/current/protocol/Exchange/interfaces/IExchangeCore.sol +++ b/packages/contracts/src/contracts/current/protocol/Exchange/interfaces/IExchangeCore.sol @@ -29,20 +29,6 @@ contract IExchangeCore { function cancelOrdersUpTo(uint256 salt) external; - /// @dev Gets information about an order: status, hash, and amount filled. - /// @param order Order to gather information on. - /// @return status Status of order. Statuses are defined in the LibStatus.Status struct. - /// @return orderHash Keccak-256 EIP712 hash of the order. - /// @return takerAssetFilledAmount Amount of order that has been filled. - function getOrderInfo(LibOrder.Order memory order) - public - view - returns ( - uint8 orderStatus, - bytes32 orderHash, - uint256 takerAssetFilledAmount - ); - /// @dev Fills the input order. /// @param order Order struct containing order specifications. /// @param takerAssetFillAmount Desired amount of takerAsset to sell. @@ -62,4 +48,18 @@ contract IExchangeCore { function cancelOrder(LibOrder.Order memory order) public returns (bool); + + /// @dev Gets information about an order: status, hash, and amount filled. + /// @param order Order to gather information on. + /// @return status Status of order. Statuses are defined in the LibStatus.Status struct. + /// @return orderHash Keccak-256 EIP712 hash of the order. + /// @return takerAssetFilledAmount Amount of order that has been filled. + function getOrderInfo(LibOrder.Order memory order) + public + view + returns ( + uint8 orderStatus, + bytes32 orderHash, + uint256 takerAssetFilledAmount + ); } |