Do not inherit libs

This commit is contained in:
Amir Bandeali
2019-07-24 13:55:48 -07:00
parent 65f17fd76e
commit 242715240b
6 changed files with 76 additions and 76 deletions

View File

@@ -113,10 +113,10 @@ contract LibOrder is
// Assembly for more efficiently computing:
// keccak256(abi.encodePacked(
// EIP712_ORDER_SCHEMA_HASH,
// bytes32(order.makerAddress),
// bytes32(order.takerAddress),
// bytes32(order.feeRecipientAddress),
// bytes32(order.senderAddress),
// uint256(order.makerAddress),
// uint256(order.takerAddress),
// uint256(order.feeRecipientAddress),
// uint256(order.senderAddress),
// order.makerAssetAmount,
// order.takerAssetAmount,
// order.makerFee,

View File

@@ -33,7 +33,6 @@ import "./MixinSignatureValidator.sol";
contract MixinExchangeCore is
IExchangeCore,
LibMath,
LibFillResults,
MixinAssetProxyDispatcher,
MixinSignatureValidator
{
@@ -89,13 +88,13 @@ contract MixinExchangeCore is
/// @param signature Proof that order has been created by maker.
/// @return Amounts filled and fees paid by maker and taker.
function fillOrder(
Order memory order,
LibOrder.Order memory order,
uint256 takerAssetFillAmount,
bytes memory signature
)
public
nonReentrant
returns (FillResults memory fillResults)
returns (LibFillResults.FillResults memory fillResults)
{
fillResults = _fillOrder(
order,
@@ -108,7 +107,7 @@ contract MixinExchangeCore is
/// @dev After calling, the order can not be filled anymore.
/// Throws if order is invalid or sender does not have permission to cancel.
/// @param order Order to cancel. Order must be OrderStatus.FILLABLE.
function cancelOrder(Order memory order)
function cancelOrder(LibOrder.Order memory order)
public
nonReentrant
{
@@ -119,13 +118,13 @@ contract MixinExchangeCore is
/// @param order Order to gather information on.
/// @return OrderInfo Information about the order and its state.
/// See LibOrder.OrderInfo for a complete description.
function getOrderInfo(Order memory order)
function getOrderInfo(LibOrder.Order memory order)
public
view
returns (OrderInfo memory orderInfo)
returns (LibOrder.OrderInfo memory orderInfo)
{
// Compute the order hash
orderInfo.orderHash = getOrderHash(order);
orderInfo.orderHash = LibOrder.getOrderHash(order);
// Fetch filled amount
orderInfo.orderTakerAssetFilledAmount = filled[orderInfo.orderHash];
@@ -135,7 +134,7 @@ contract MixinExchangeCore is
// edge cases in the supporting infrastructure because they have
// an 'infinite' price when computed by a simple division.
if (order.makerAssetAmount == 0) {
orderInfo.orderStatus = uint8(OrderStatus.INVALID_MAKER_ASSET_AMOUNT);
orderInfo.orderStatus = uint8(LibOrder.OrderStatus.INVALID_MAKER_ASSET_AMOUNT);
return orderInfo;
}
@@ -144,35 +143,35 @@ contract MixinExchangeCore is
// Instead of distinguishing between unfilled and filled zero taker
// amount orders, we choose not to support them.
if (order.takerAssetAmount == 0) {
orderInfo.orderStatus = uint8(OrderStatus.INVALID_TAKER_ASSET_AMOUNT);
orderInfo.orderStatus = uint8(LibOrder.OrderStatus.INVALID_TAKER_ASSET_AMOUNT);
return orderInfo;
}
// Validate order availability
if (orderInfo.orderTakerAssetFilledAmount >= order.takerAssetAmount) {
orderInfo.orderStatus = uint8(OrderStatus.FULLY_FILLED);
orderInfo.orderStatus = uint8(LibOrder.OrderStatus.FULLY_FILLED);
return orderInfo;
}
// Validate order expiration
// solhint-disable-next-line not-rely-on-time
if (block.timestamp >= order.expirationTimeSeconds) {
orderInfo.orderStatus = uint8(OrderStatus.EXPIRED);
orderInfo.orderStatus = uint8(LibOrder.OrderStatus.EXPIRED);
return orderInfo;
}
// Check if order has been cancelled
if (cancelled[orderInfo.orderHash]) {
orderInfo.orderStatus = uint8(OrderStatus.CANCELLED);
orderInfo.orderStatus = uint8(LibOrder.OrderStatus.CANCELLED);
return orderInfo;
}
if (orderEpoch[order.makerAddress][order.senderAddress] > order.salt) {
orderInfo.orderStatus = uint8(OrderStatus.CANCELLED);
orderInfo.orderStatus = uint8(LibOrder.OrderStatus.CANCELLED);
return orderInfo;
}
// All other statuses are ruled out: order is Fillable
orderInfo.orderStatus = uint8(OrderStatus.FILLABLE);
orderInfo.orderStatus = uint8(LibOrder.OrderStatus.FILLABLE);
return orderInfo;
}
@@ -182,15 +181,15 @@ contract MixinExchangeCore is
/// @param signature Proof that order has been created by maker.
/// @return Amounts filled and fees paid by maker and taker.
function _fillOrder(
Order memory order,
LibOrder.Order memory order,
uint256 takerAssetFillAmount,
bytes memory signature
)
internal
returns (FillResults memory fillResults)
returns (LibFillResults.FillResults memory fillResults)
{
// Fetch order info
OrderInfo memory orderInfo = getOrderInfo(order);
LibOrder.OrderInfo memory orderInfo = getOrderInfo(order);
// Fetch taker address
address takerAddress = _getCurrentContextAddress();
@@ -235,11 +234,11 @@ contract MixinExchangeCore is
/// @dev After calling, the order can not be filled anymore.
/// Throws if order is invalid or sender does not have permission to cancel.
/// @param order Order to cancel. Order must be OrderStatus.FILLABLE.
function _cancelOrder(Order memory order)
function _cancelOrder(LibOrder.Order memory order)
internal
{
// Fetch current order status
OrderInfo memory orderInfo = getOrderInfo(order);
LibOrder.OrderInfo memory orderInfo = getOrderInfo(order);
// Validate context
_assertValidCancel(order, orderInfo);
@@ -258,11 +257,11 @@ contract MixinExchangeCore is
/// @param takerAddress Address of taker who filled the order.
/// @param orderTakerAssetFilledAmount Amount of order already filled.
function _updateFilledState(
Order memory order,
LibOrder.Order memory order,
address takerAddress,
bytes32 orderHash,
uint256 orderTakerAssetFilledAmount,
FillResults memory fillResults
LibFillResults.FillResults memory fillResults
)
internal
{
@@ -294,7 +293,7 @@ contract MixinExchangeCore is
/// @param order that was cancelled.
/// @param orderHash Hash of order that was cancelled.
function _updateCancelledState(
Order memory order,
LibOrder.Order memory order,
bytes32 orderHash
)
internal
@@ -319,8 +318,8 @@ contract MixinExchangeCore is
/// @param takerAddress Address of order taker.
/// @param signature Proof that the orders was created by its maker.
function _assertFillableOrder(
Order memory order,
OrderInfo memory orderInfo,
LibOrder.Order memory order,
LibOrder.OrderInfo memory orderInfo,
address takerAddress,
bytes memory signature
)
@@ -328,10 +327,10 @@ contract MixinExchangeCore is
view
{
// An order can only be filled if its status is FILLABLE.
if (orderInfo.orderStatus != uint8(OrderStatus.FILLABLE)) {
if (orderInfo.orderStatus != uint8(LibOrder.OrderStatus.FILLABLE)) {
LibRichErrors._rrevert(LibExchangeRichErrors.OrderStatusError(
orderInfo.orderHash,
OrderStatus(orderInfo.orderStatus)
LibOrder.OrderStatus(orderInfo.orderStatus)
));
}
@@ -367,7 +366,7 @@ contract MixinExchangeCore is
orderInfo.orderHash,
signature)) {
LibRichErrors._rrevert(LibExchangeRichErrors.SignatureError(
SignatureErrorCodes.BAD_SIGNATURE,
IExchangeRichErrors.SignatureErrorCodes.BAD_SIGNATURE,
orderInfo.orderHash,
makerAddress,
signature
@@ -380,8 +379,8 @@ contract MixinExchangeCore is
/// @param order to be cancelled.
/// @param orderInfo OrderStatus, orderHash, and amount already filled of order.
function _assertValidCancel(
Order memory order,
OrderInfo memory orderInfo
LibOrder.Order memory order,
LibOrder.OrderInfo memory orderInfo
)
internal
view
@@ -405,12 +404,12 @@ contract MixinExchangeCore is
/// @param takerAssetFilledAmount Amount of takerAsset that will be filled.
/// @return fillResults Amounts filled and fees paid by maker and taker.
function _calculateFillResults(
Order memory order,
LibOrder.Order memory order,
uint256 takerAssetFilledAmount
)
internal
pure
returns (FillResults memory fillResults)
returns (LibFillResults.FillResults memory fillResults)
{
// Compute proportional transfer amounts
fillResults.takerAssetFilledAmount = takerAssetFilledAmount;

View File

@@ -234,9 +234,13 @@ contract MixinMatchOrders is
/// @dev Validates context for matchOrders. Succeeds or throws.
/// @param leftOrder First order to match.
/// @param rightOrder Second order to match.
/// @param leftOrderInfo OrderStatus, orderHash, and amount already filled of leftOrder.
/// @param rightOrderInfo OrderStatus, orderHash, and amount already filled of rightOrder.
function _assertValidMatch(
LibOrder.Order memory leftOrder,
LibOrder.Order memory rightOrder
LibOrder.Order memory rightOrder,
LibOrder.OrderInfo memory leftOrderInfo,
LibOrder.OrderInfo memory rightOrderInfo
)
internal
view
@@ -252,8 +256,8 @@ contract MixinMatchOrders is
if (_safeMul(leftOrder.makerAssetAmount, rightOrder.makerAssetAmount) <
_safeMul(leftOrder.takerAssetAmount, rightOrder.takerAssetAmount)) {
LibRichErrors._rrevert(LibExchangeRichErrors.NegativeSpreadError(
getOrderHash(leftOrder),
getOrderHash(rightOrder)
leftOrderInfo.orderHash,
rightOrderInfo.orderHash
));
}
}
@@ -268,7 +272,7 @@ contract MixinMatchOrders is
/// @param rightMakerAssetAmountRemaining The amount of the right order maker asset that can still be filled.
/// @param rightTakerAssetAmountRemaining The amount of the right order taker asset that can still be filled.
function _calculateMatchedFillResults(
MatchedFillResults memory matchedFillResults,
LibFillResults.MatchedFillResults memory matchedFillResults,
LibOrder.Order memory leftOrder,
LibOrder.Order memory rightOrder,
uint256 leftMakerAssetAmountRemaining,
@@ -339,7 +343,7 @@ contract MixinMatchOrders is
/// @param rightMakerAssetAmountRemaining The amount of the right order maker asset that can still be filled.
/// @param rightTakerAssetAmountRemaining The amount of the right order taker asset that can still be filled.
function _calculateMatchedFillResultsWithMaximalFill(
MatchedFillResults memory matchedFillResults,
LibFillResults.MatchedFillResults memory matchedFillResults,
LibOrder.Order memory leftOrder,
LibOrder.Order memory rightOrder,
uint256 leftMakerAssetAmountRemaining,
@@ -428,7 +432,7 @@ contract MixinMatchOrders is
/// @param rightMakerAssetAmountRemaining The amount of the right maker asset that is remaining to be filled.
/// @param rightTakerAssetAmountRemaining The amount of the right taker asset that is remaining to be filled.
function _calculateCompleteFillBoth(
MatchedFillResults memory matchedFillResults,
LibFillResults.MatchedFillResults memory matchedFillResults,
uint256 leftMakerAssetAmountRemaining,
uint256 leftTakerAssetAmountRemaining,
uint256 rightMakerAssetAmountRemaining,
@@ -452,7 +456,7 @@ contract MixinMatchOrders is
/// @param rightMakerAssetAmountRemaining The amount of the right maker asset that is remaining to be filled.
/// @param rightTakerAssetAmountRemaining The amount of the right taker asset that is remaining to be filled.
function _calculateCompleteRightFill(
MatchedFillResults memory matchedFillResults,
LibFillResults.MatchedFillResults memory matchedFillResults,
LibOrder.Order memory leftOrder,
uint256 rightMakerAssetAmountRemaining,
uint256 rightTakerAssetAmountRemaining
@@ -497,24 +501,24 @@ contract MixinMatchOrders is
// Ensure that the left and right orders have nonzero lengths.
if (leftOrders.length == 0) {
LibRichErrors._rrevert(LibExchangeRichErrors.BatchMatchOrdersError(
BatchMatchOrdersErrorCodes.ZERO_LEFT_ORDERS
IExchangeRichErrors.BatchMatchOrdersErrorCodes.ZERO_LEFT_ORDERS
));
}
if (rightOrders.length == 0) {
LibRichErrors._rrevert(LibExchangeRichErrors.BatchMatchOrdersError(
BatchMatchOrdersErrorCodes.ZERO_RIGHT_ORDERS
IExchangeRichErrors.BatchMatchOrdersErrorCodes.ZERO_RIGHT_ORDERS
));
}
// Ensure that the left and right arrays are compatible.
if (leftOrders.length != leftSignatures.length) {
LibRichErrors._rrevert(LibExchangeRichErrors.BatchMatchOrdersError(
BatchMatchOrdersErrorCodes.INVALID_LENGTH_LEFT_SIGNATURES
IExchangeRichErrors.BatchMatchOrdersErrorCodes.INVALID_LENGTH_LEFT_SIGNATURES
));
}
if (rightOrders.length != rightSignatures.length) {
LibRichErrors._rrevert(LibExchangeRichErrors.BatchMatchOrdersError(
BatchMatchOrdersErrorCodes.INVALID_LENGTH_RIGHT_SIGNATURES
IExchangeRichErrors.BatchMatchOrdersErrorCodes.INVALID_LENGTH_RIGHT_SIGNATURES
));
}
@@ -556,11 +560,11 @@ contract MixinMatchOrders is
);
// Aggregate the new fill results with the previous fill results for the current orders.
_addFillResults(
LibFillResults._addFillResults(
leftFillResults,
matchResults.left
);
_addFillResults(
LibFillResults._addFillResults(
rightFillResults,
matchResults.right
);

View File

@@ -36,8 +36,6 @@ import "./MixinTransactions.sol";
contract MixinSignatureValidator is
ReentrancyGuard,
LibEIP1271,
LibOrder,
LibZeroExTransaction,
ISignatureValidator,
MixinTransactions
{
@@ -129,14 +127,14 @@ contract MixinSignatureValidator is
/// @param signature Proof that the order has been signed by signer.
/// @return isValid `true` if the signature is valid for the given order and signer.
function isValidOrderSignature(
Order memory order,
LibOrder.Order memory order,
bytes memory signature
)
public
view
returns (bool isValid)
{
bytes32 orderHash = getOrderHash(order);
bytes32 orderHash = LibOrder.getOrderHash(order);
return _isValidOrderWithHashSignature(
order,
orderHash,
@@ -149,14 +147,14 @@ contract MixinSignatureValidator is
/// @param signature Proof that the order has been signed by signer.
/// @return isValid `true` if the signature is valid for the given transaction and signer.
function isValidTransactionSignature(
ZeroExTransaction memory transaction,
LibZeroExTransaction.ZeroExTransaction memory transaction,
bytes memory signature
)
public
view
returns (bool isValid)
{
bytes32 transactionHash = getTransactionHash(transaction);
bytes32 transactionHash = LibZeroExTransaction.getTransactionHash(transaction);
isValid = _isValidTransactionWithHashSignature(
transaction,
transactionHash,
@@ -198,7 +196,7 @@ contract MixinSignatureValidator is
/// @param signature Proof that the hash has been signed by signer.
/// @return isValid True if the signature is valid for the given order and signer.
function _isValidOrderWithHashSignature(
Order memory order,
LibOrder.Order memory order,
bytes32 orderHash,
bytes memory signature
)
@@ -246,7 +244,7 @@ contract MixinSignatureValidator is
/// @param signature Proof that the hash has been signed by signer.
/// @return isValid True if the signature is valid for the given transaction and signer.
function _isValidTransactionWithHashSignature(
ZeroExTransaction memory transaction,
LibZeroExTransaction.ZeroExTransaction memory transaction,
bytes32 transactionHash,
bytes memory signature
)

View File

@@ -28,7 +28,6 @@ import "./LibExchangeRichErrors.sol";
contract MixinTransactions is
LibZeroExTransaction,
ISignatureValidator,
ITransactions
{
@@ -44,7 +43,7 @@ contract MixinTransactions is
/// @param signature Proof that transaction has been signed by signer.
/// @return ABI encoded return data of the underlying Exchange function call.
function executeTransaction(
ZeroExTransaction memory transaction,
LibZeroExTransaction.ZeroExTransaction memory transaction,
bytes memory signature
)
public
@@ -58,7 +57,7 @@ contract MixinTransactions is
/// @param signatures Array of proofs that transactions have been signed by signer(s).
/// @return Array containing ABI encoded return data for each of the underlying Exchange function calls.
function batchExecuteTransactions(
ZeroExTransaction[] memory transactions,
LibZeroExTransaction.ZeroExTransaction[] memory transactions,
bytes[] memory signatures
)
public
@@ -77,13 +76,13 @@ contract MixinTransactions is
/// @param signature Proof that transaction has been signed by signer.
/// @return ABI encoded return data of the underlying Exchange function call.
function _executeTransaction(
ZeroExTransaction memory transaction,
LibZeroExTransaction.ZeroExTransaction memory transaction,
bytes memory signature
)
internal
returns (bytes memory)
{
bytes32 transactionHash = getTransactionHash(transaction);
bytes32 transactionHash = LibZeroExTransaction.getTransactionHash(transaction);
// Check transaction is not expired
// solhint-disable-next-line not-rely-on-time

View File

@@ -46,7 +46,7 @@ contract MixinWrapperFunctions is
)
public
nonReentrant
returns (FillResults memory fillResults)
returns (LibFillResults.FillResults memory fillResults)
{
fillResults = _fillOrKillOrder(
order,
@@ -68,7 +68,7 @@ contract MixinWrapperFunctions is
bytes memory signature
)
public
returns (FillResults memory fillResults)
returns (LibFillResults.FillResults memory fillResults)
{
// ABI encode calldata for `fillOrder`
bytes memory fillOrderCalldata = abi.encodeWithSelector(
@@ -99,10 +99,10 @@ contract MixinWrapperFunctions is
)
public
nonReentrant
returns (FillResults[] memory fillResults)
returns (LibFillResults.FillResults[] memory fillResults)
{
uint256 ordersLength = orders.length;
fillResults = new FillResults[](ordersLength);
fillResults = new LibFillResults.FillResults[](ordersLength);
for (uint256 i = 0; i != ordersLength; i++) {
fillResults[i] = _fillOrder(
orders[i],
@@ -125,10 +125,10 @@ contract MixinWrapperFunctions is
)
public
nonReentrant
returns (FillResults[] memory fillResults)
returns (LibFillResults.FillResults[] memory fillResults)
{
uint256 ordersLength = orders.length;
fillResults = new FillResults[](ordersLength);
fillResults = new LibFillResults.FillResults[](ordersLength);
for (uint256 i = 0; i != ordersLength; i++) {
fillResults[i] = _fillOrKillOrder(
orders[i],
@@ -150,10 +150,10 @@ contract MixinWrapperFunctions is
bytes[] memory signatures
)
public
returns (FillResults[] memory fillResults)
returns (LibFillResults.FillResults[] memory fillResults)
{
uint256 ordersLength = orders.length;
fillResults = new FillResults[](ordersLength);
fillResults = new LibFillResults.FillResults[](ordersLength);
for (uint256 i = 0; i != ordersLength; i++) {
fillResults[i] = fillOrderNoThrow(
orders[i],
@@ -175,7 +175,7 @@ contract MixinWrapperFunctions is
bytes[] memory signatures
)
public
returns (FillResults memory fillResults)
returns (LibFillResults.FillResults memory fillResults)
{
bytes memory takerAssetData = orders[0].takerAssetData;
@@ -191,14 +191,14 @@ contract MixinWrapperFunctions is
uint256 remainingTakerAssetFillAmount = _safeSub(takerAssetFillAmount, fillResults.takerAssetFilledAmount);
// Attempt to sell the remaining amount of takerAsset
FillResults memory singleFillResults = fillOrderNoThrow(
LibFillResults.FillResults memory singleFillResults = fillOrderNoThrow(
orders[i],
remainingTakerAssetFillAmount,
signatures[i]
);
// Update amounts filled and fees paid by maker and taker
_addFillResults(fillResults, singleFillResults);
LibFillResults._addFillResults(fillResults, singleFillResults);
// Stop execution if the entire amount of takerAsset has been sold
if (fillResults.takerAssetFilledAmount >= takerAssetFillAmount) {
@@ -219,7 +219,7 @@ contract MixinWrapperFunctions is
bytes[] memory signatures
)
public
returns (FillResults memory fillResults)
returns (LibFillResults.FillResults memory fillResults)
{
bytes memory makerAssetData = orders[0].makerAssetData;
@@ -243,14 +243,14 @@ contract MixinWrapperFunctions is
);
// Attempt to sell the remaining amount of takerAsset
FillResults memory singleFillResults = fillOrderNoThrow(
LibFillResults.FillResults memory singleFillResults = fillOrderNoThrow(
orders[i],
remainingTakerAssetFillAmount,
signatures[i]
);
// Update amounts filled and fees paid by maker and taker
_addFillResults(fillResults, singleFillResults);
LibFillResults._addFillResults(fillResults, singleFillResults);
// Stop execution if the entire amount of makerAsset has been bought
if (fillResults.makerAssetFilledAmount >= makerAssetFillAmount) {
@@ -298,7 +298,7 @@ contract MixinWrapperFunctions is
bytes memory signature
)
internal
returns (FillResults memory fillResults)
returns (LibFillResults.FillResults memory fillResults)
{
fillResults = _fillOrder(
order,