Skip to content

Commit

Permalink
adjust tests and remove unused internal function
Browse files Browse the repository at this point in the history
  • Loading branch information
0age committed Mar 6, 2024
1 parent be38dd3 commit 7abe4d9
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 123 deletions.
39 changes: 0 additions & 39 deletions src/core/lib/OrderCombiner.sol
Original file line number Diff line number Diff line change
Expand Up @@ -1150,45 +1150,6 @@ contract OrderCombiner is OrderFulfiller, FulfillmentApplier {
return executions;
}

/**
* @dev Internal pure function to determine whether a given execution is
* filterable and may be removed from the executions array. The offerer
* and the recipient must be the same address and the item type cannot
* indicate a native token transfer.
*
* @param execution The execution to check for filterability.
*
* @return filterable A boolean indicating whether the execution in question
* can be filtered from the executions array.
*/
function _isFilterableExecution(Execution memory execution)
internal
pure
returns (bool filterable)
{
// Utilize assembly to efficiently determine if execution is filterable.
assembly {
// Retrieve the received item referenced by the execution.
let item := mload(execution)

// Determine whether the execution is filterable.
filterable :=
and(
// Determine if offerer and recipient are the same address.
eq(
// Retrieve recipient's address from the received item.
mload(add(item, ReceivedItem_recipient_offset)),
// Retrieve the offerer's address from the execution.
mload(add(execution, Execution_offerer_offset))
),
// Determine if received item's item type is non-zero,
// thereby indicating that the execution does not involve
// native tokens.
iszero(iszero(mload(item)))
)
}
}

/**
* @dev Internal view function to determine whether a status update failure
* should cause a revert or allow a skipped order. The call must revert
Expand Down
106 changes: 23 additions & 83 deletions src/sol/executions/ExecutionHelper.sol
Original file line number Diff line number Diff line change
Expand Up @@ -125,8 +125,6 @@ library ExecutionHelper {

explicitExecutions = new Execution[](fulfillments.length);

uint256 filteredExecutions = 0;

bool[] memory availableOrders = new bool[](details.orders.length);

for (uint256 i = 0; i < details.orders.length; ++i) {
Expand All @@ -137,28 +135,8 @@ library ExecutionHelper {
processImplicitPreOrderExecutions(details, availableOrders);

for (uint256 i = 0; i < fulfillments.length; i++) {
Execution memory execution =
explicitExecutions[i] =
processExecutionFromFulfillment(details, fulfillments[i]);

if (
execution.item.recipient == execution.offerer
&& execution.item.itemType != ItemType.NATIVE
) {
filteredExecutions++;
} else {
explicitExecutions[i - filteredExecutions] = execution;
}
}

// If some number of executions have been filtered...
if (filteredExecutions != 0) {
// reduce the total length of the executions array.
assembly {
mstore(
explicitExecutions,
sub(mload(explicitExecutions), filteredExecutions)
)
}
}

implicitExecutionsPost =
Expand Down Expand Up @@ -667,8 +645,6 @@ library ExecutionHelper {
offerComponents.length + considerationComponents.length
);

uint256 filteredExecutions = 0;

// process offer components
// iterate over each array of fulfillment components
for (uint256 i = 0; i < offerComponents.length; i++) {
Expand Down Expand Up @@ -697,35 +673,23 @@ library ExecutionHelper {
}
}

if (aggregatedAmount == 0) {
filteredExecutions++;
continue;
}

// use the first fulfillment component to get the order details
FulfillmentComponent memory first = aggregatedComponents[0];
OrderDetails memory details =
fulfillmentDetails.orders[first.orderIndex];
SpentItem memory firstItem = details.offer[first.itemIndex];

if (
fulfillmentDetails.recipient == details.offerer
&& firstItem.itemType != ItemType.NATIVE
) {
filteredExecutions++;
} else {
explicitExecutions[i - filteredExecutions] = Execution({
offerer: details.offerer,
conduitKey: details.conduitKey,
item: ReceivedItem({
itemType: firstItem.itemType,
token: firstItem.token,
identifier: firstItem.identifier,
amount: aggregatedAmount,
recipient: fulfillmentDetails.recipient
})
});
}
explicitExecutions[i] = Execution({
offerer: details.offerer,
conduitKey: details.conduitKey,
item: ReceivedItem({
itemType: firstItem.itemType,
token: firstItem.token,
identifier: firstItem.identifier,
amount: aggregatedAmount,
recipient: fulfillmentDetails.recipient
})
});
}

// process consideration components
Expand Down Expand Up @@ -759,48 +723,24 @@ library ExecutionHelper {
}
}

if (aggregatedAmount == 0) {
filteredExecutions++;
continue;
}

// use the first fulfillment component to get the order details
FulfillmentComponent memory first = aggregatedComponents[0];
OrderDetails memory details =
fulfillmentDetails.orders[first.orderIndex];
ReceivedItem memory firstItem =
details.consideration[first.itemIndex];

if (
firstItem.recipient == fulfillmentDetails.fulfiller
&& firstItem.itemType != ItemType.NATIVE
) {
filteredExecutions++;
} else {
explicitExecutions[i + offerComponents.length
- filteredExecutions] = Execution({
offerer: fulfillmentDetails.fulfiller,
conduitKey: fulfillmentDetails.fulfillerConduitKey,
item: ReceivedItem({
itemType: firstItem.itemType,
token: firstItem.token,
identifier: firstItem.identifier,
amount: aggregatedAmount,
recipient: firstItem.recipient
})
});
}
}

// If some number of executions have been filtered...
if (filteredExecutions != 0) {
// reduce the total length of the executions array.
assembly {
mstore(
explicitExecutions,
sub(mload(explicitExecutions), filteredExecutions)
)
}
explicitExecutions[i + offerComponents.length] = Execution({
offerer: fulfillmentDetails.fulfiller,
conduitKey: fulfillmentDetails.fulfillerConduitKey,
item: ReceivedItem({
itemType: firstItem.itemType,
token: firstItem.token,
identifier: firstItem.identifier,
amount: aggregatedAmount,
recipient: firstItem.recipient
})
});
}
}

Expand Down
18 changes: 17 additions & 1 deletion test/foundry/new/helpers/event-utils/ExpectedEventsUtil.sol
Original file line number Diff line number Diff line change
Expand Up @@ -117,10 +117,26 @@ library ExpectedEventsUtil {
"ExpectedEventsUtil: executions length mismatch"
);

Execution[] memory filteredExecutions = new Execution[](executions.length);

uint256 filteredExecutionIndex = 0;

for (uint256 i = 0; i < executions.length; ++i) {
if (
executions[i].item.amount > 0
) {
filteredExecutions[filteredExecutionIndex++] = executions[i];
}
}

assembly {
mstore(filteredExecutions, filteredExecutionIndex)
}

context.expectations.expectedTransferEventHashes = ArrayHelpers
.filterMapWithArg
.asExecutionsFilterMap()(
executions, TransferEventsLib.getTransferEventHash, context
filteredExecutions, TransferEventsLib.getTransferEventHash, context
);

vm.serializeBytes32(
Expand Down

0 comments on commit 7abe4d9

Please sign in to comment.