Use _getOrderHashAndFilledAmount instead of getOrderInfo to reduce sloads
This commit is contained in:
parent
8317628c61
commit
10c62c10aa
@ -33,6 +33,7 @@ contract MixinMatchOrders is
|
|||||||
{
|
{
|
||||||
using LibBytes for bytes;
|
using LibBytes for bytes;
|
||||||
using LibSafeMath for uint256;
|
using LibSafeMath for uint256;
|
||||||
|
using LibOrder for LibOrder.Order;
|
||||||
|
|
||||||
/// @dev Match complementary orders that have a profitable spread.
|
/// @dev Match complementary orders that have a profitable spread.
|
||||||
/// Each order is filled at their respective price point, and
|
/// Each order is filled at their respective price point, and
|
||||||
@ -165,7 +166,7 @@ contract MixinMatchOrders is
|
|||||||
bytes32 rightOrderHash
|
bytes32 rightOrderHash
|
||||||
)
|
)
|
||||||
internal
|
internal
|
||||||
view
|
pure
|
||||||
{
|
{
|
||||||
// Make sure there is a profitable spread.
|
// Make sure there is a profitable spread.
|
||||||
// There is a profitable spread iff the cost per unit bought (OrderA.MakerAmount/OrderA.TakerAmount) for each order is greater
|
// There is a profitable spread iff the cost per unit bought (OrderA.MakerAmount/OrderA.TakerAmount) for each order is greater
|
||||||
@ -236,11 +237,11 @@ contract MixinMatchOrders is
|
|||||||
uint256 leftIdx = 0;
|
uint256 leftIdx = 0;
|
||||||
uint256 rightIdx = 0;
|
uint256 rightIdx = 0;
|
||||||
|
|
||||||
// Keep local variables for orders, order info, and signatures for efficiency.
|
// Keep local variables for orders, order filled amounts, and signatures for efficiency.
|
||||||
LibOrder.Order memory leftOrder = leftOrders[0];
|
LibOrder.Order memory leftOrder = leftOrders[0];
|
||||||
LibOrder.Order memory rightOrder = rightOrders[0];
|
LibOrder.Order memory rightOrder = rightOrders[0];
|
||||||
LibOrder.OrderInfo memory leftOrderInfo = getOrderInfo(leftOrder);
|
(, uint256 leftOrderTakerAssetFilledAmount) = _getOrderHashAndFilledAmount(leftOrder);
|
||||||
LibOrder.OrderInfo memory rightOrderInfo = getOrderInfo(rightOrder);
|
(, uint256 rightOrderTakerAssetFilledAmount) = _getOrderHashAndFilledAmount(rightOrder);
|
||||||
LibFillResults.FillResults memory leftFillResults;
|
LibFillResults.FillResults memory leftFillResults;
|
||||||
LibFillResults.FillResults memory rightFillResults;
|
LibFillResults.FillResults memory rightFillResults;
|
||||||
|
|
||||||
@ -256,13 +257,9 @@ contract MixinMatchOrders is
|
|||||||
shouldMaximallyFillOrders
|
shouldMaximallyFillOrders
|
||||||
);
|
);
|
||||||
|
|
||||||
// Update the orderInfo structs with the updated takerAssetFilledAmount
|
// Update the order filled amounts with the updated takerAssetFilledAmount
|
||||||
leftOrderInfo.orderTakerAssetFilledAmount = leftOrderInfo.orderTakerAssetFilledAmount.safeAdd(
|
leftOrderTakerAssetFilledAmount = leftOrderTakerAssetFilledAmount.safeAdd(matchResults.left.takerAssetFilledAmount);
|
||||||
matchResults.left.takerAssetFilledAmount
|
rightOrderTakerAssetFilledAmount = rightOrderTakerAssetFilledAmount.safeAdd(matchResults.right.takerAssetFilledAmount);
|
||||||
);
|
|
||||||
rightOrderInfo.orderTakerAssetFilledAmount = rightOrderInfo.orderTakerAssetFilledAmount.safeAdd(
|
|
||||||
matchResults.right.takerAssetFilledAmount
|
|
||||||
);
|
|
||||||
|
|
||||||
// Aggregate the new fill results with the previous fill results for the current orders.
|
// Aggregate the new fill results with the previous fill results for the current orders.
|
||||||
leftFillResults = LibFillResults.addFillResults(
|
leftFillResults = LibFillResults.addFillResults(
|
||||||
@ -285,7 +282,7 @@ contract MixinMatchOrders is
|
|||||||
|
|
||||||
// If the leftOrder is filled, update the leftIdx, leftOrder, and leftSignature,
|
// If the leftOrder is filled, update the leftIdx, leftOrder, and leftSignature,
|
||||||
// or break out of the loop if there are no more leftOrders to match.
|
// or break out of the loop if there are no more leftOrders to match.
|
||||||
if (leftOrderInfo.orderTakerAssetFilledAmount >= leftOrder.takerAssetAmount) {
|
if (leftOrderTakerAssetFilledAmount >= leftOrder.takerAssetAmount) {
|
||||||
// Update the batched fill results once the leftIdx is updated.
|
// Update the batched fill results once the leftIdx is updated.
|
||||||
batchMatchedFillResults.left[leftIdx++] = leftFillResults;
|
batchMatchedFillResults.left[leftIdx++] = leftFillResults;
|
||||||
// Clear the intermediate fill results value.
|
// Clear the intermediate fill results value.
|
||||||
@ -299,13 +296,13 @@ contract MixinMatchOrders is
|
|||||||
break;
|
break;
|
||||||
} else {
|
} else {
|
||||||
leftOrder = leftOrders[leftIdx];
|
leftOrder = leftOrders[leftIdx];
|
||||||
leftOrderInfo = getOrderInfo(leftOrder);
|
(, leftOrderTakerAssetFilledAmount) = _getOrderHashAndFilledAmount(leftOrder);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// If the rightOrder is filled, update the rightIdx, rightOrder, and rightSignature,
|
// If the rightOrder is filled, update the rightIdx, rightOrder, and rightSignature,
|
||||||
// or break out of the loop if there are no more rightOrders to match.
|
// or break out of the loop if there are no more rightOrders to match.
|
||||||
if (rightOrderInfo.orderTakerAssetFilledAmount >= rightOrder.takerAssetAmount) {
|
if (rightOrderTakerAssetFilledAmount >= rightOrder.takerAssetAmount) {
|
||||||
// Update the batched fill results once the rightIdx is updated.
|
// Update the batched fill results once the rightIdx is updated.
|
||||||
batchMatchedFillResults.right[rightIdx++] = rightFillResults;
|
batchMatchedFillResults.right[rightIdx++] = rightFillResults;
|
||||||
// Clear the intermediate fill results value.
|
// Clear the intermediate fill results value.
|
||||||
@ -319,7 +316,7 @@ contract MixinMatchOrders is
|
|||||||
break;
|
break;
|
||||||
} else {
|
} else {
|
||||||
rightOrder = rightOrders[rightIdx];
|
rightOrder = rightOrders[rightIdx];
|
||||||
rightOrderInfo = getOrderInfo(rightOrder);
|
(, rightOrderTakerAssetFilledAmount) = _getOrderHashAndFilledAmount(rightOrder);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -440,6 +437,8 @@ contract MixinMatchOrders is
|
|||||||
)
|
)
|
||||||
internal
|
internal
|
||||||
{
|
{
|
||||||
|
address leftMakerAddress = leftOrder.makerAddress;
|
||||||
|
address rightMakerAddress = rightOrder.makerAddress;
|
||||||
address leftFeeRecipientAddress = leftOrder.feeRecipientAddress;
|
address leftFeeRecipientAddress = leftOrder.feeRecipientAddress;
|
||||||
address rightFeeRecipientAddress = rightOrder.feeRecipientAddress;
|
address rightFeeRecipientAddress = rightOrder.feeRecipientAddress;
|
||||||
|
|
||||||
@ -447,8 +446,8 @@ contract MixinMatchOrders is
|
|||||||
_dispatchTransferFrom(
|
_dispatchTransferFrom(
|
||||||
rightOrderHash,
|
rightOrderHash,
|
||||||
rightOrder.makerAssetData,
|
rightOrder.makerAssetData,
|
||||||
rightOrder.makerAddress,
|
rightMakerAddress,
|
||||||
leftOrder.makerAddress,
|
leftMakerAddress,
|
||||||
matchedFillResults.left.takerAssetFilledAmount
|
matchedFillResults.left.takerAssetFilledAmount
|
||||||
);
|
);
|
||||||
|
|
||||||
@ -456,8 +455,8 @@ contract MixinMatchOrders is
|
|||||||
_dispatchTransferFrom(
|
_dispatchTransferFrom(
|
||||||
leftOrderHash,
|
leftOrderHash,
|
||||||
leftOrder.makerAssetData,
|
leftOrder.makerAssetData,
|
||||||
leftOrder.makerAddress,
|
leftMakerAddress,
|
||||||
rightOrder.makerAddress,
|
rightMakerAddress,
|
||||||
matchedFillResults.right.takerAssetFilledAmount
|
matchedFillResults.right.takerAssetFilledAmount
|
||||||
);
|
);
|
||||||
|
|
||||||
@ -465,7 +464,7 @@ contract MixinMatchOrders is
|
|||||||
_dispatchTransferFrom(
|
_dispatchTransferFrom(
|
||||||
rightOrderHash,
|
rightOrderHash,
|
||||||
rightOrder.makerFeeAssetData,
|
rightOrder.makerFeeAssetData,
|
||||||
rightOrder.makerAddress,
|
rightMakerAddress,
|
||||||
rightFeeRecipientAddress,
|
rightFeeRecipientAddress,
|
||||||
matchedFillResults.right.makerFeePaid
|
matchedFillResults.right.makerFeePaid
|
||||||
);
|
);
|
||||||
@ -474,7 +473,7 @@ contract MixinMatchOrders is
|
|||||||
_dispatchTransferFrom(
|
_dispatchTransferFrom(
|
||||||
leftOrderHash,
|
leftOrderHash,
|
||||||
leftOrder.makerFeeAssetData,
|
leftOrder.makerFeeAssetData,
|
||||||
leftOrder.makerAddress,
|
leftMakerAddress,
|
||||||
leftFeeRecipientAddress,
|
leftFeeRecipientAddress,
|
||||||
matchedFillResults.left.makerFeePaid
|
matchedFillResults.left.makerFeePaid
|
||||||
);
|
);
|
||||||
@ -483,14 +482,14 @@ contract MixinMatchOrders is
|
|||||||
_dispatchTransferFrom(
|
_dispatchTransferFrom(
|
||||||
leftOrderHash,
|
leftOrderHash,
|
||||||
leftOrder.makerAssetData,
|
leftOrder.makerAssetData,
|
||||||
leftOrder.makerAddress,
|
leftMakerAddress,
|
||||||
takerAddress,
|
takerAddress,
|
||||||
matchedFillResults.profitInLeftMakerAsset
|
matchedFillResults.profitInLeftMakerAsset
|
||||||
);
|
);
|
||||||
_dispatchTransferFrom(
|
_dispatchTransferFrom(
|
||||||
rightOrderHash,
|
rightOrderHash,
|
||||||
rightOrder.makerAssetData,
|
rightOrder.makerAssetData,
|
||||||
rightOrder.makerAddress,
|
rightMakerAddress,
|
||||||
takerAddress,
|
takerAddress,
|
||||||
matchedFillResults.profitInRightMakerAsset
|
matchedFillResults.profitInRightMakerAsset
|
||||||
);
|
);
|
||||||
@ -500,8 +499,8 @@ contract MixinMatchOrders is
|
|||||||
leftOrderHash,
|
leftOrderHash,
|
||||||
rightOrderHash,
|
rightOrderHash,
|
||||||
matchedFillResults.left.protocolFeePaid,
|
matchedFillResults.left.protocolFeePaid,
|
||||||
leftOrder.makerAddress,
|
leftMakerAddress,
|
||||||
rightOrder.makerAddress,
|
rightMakerAddress,
|
||||||
takerAddress
|
takerAddress
|
||||||
);
|
);
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user