Skip to content

Commit

Permalink
update with 1.6 code changes
Browse files Browse the repository at this point in the history
  • Loading branch information
0age committed Mar 6, 2024
1 parent c3bfe7e commit d8e70cc
Show file tree
Hide file tree
Showing 5 changed files with 140 additions and 955 deletions.
2 changes: 2 additions & 0 deletions src/ZoneInterface.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,5 @@
pragma solidity ^0.8.17;

import { ZoneInterface } from "seaport-types/src/interfaces/ZoneInterface.sol";

interface LocalZoneInterface is ZoneInterface { }
131 changes: 52 additions & 79 deletions src/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 @@ -663,8 +641,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 @@ -693,35 +669,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 @@ -755,49 +719,42 @@ 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,
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
})
});
}

// zero out any executions with zero amount items.
for (uint256 i = 0; i < explicitExecutions.length; i++) {
if (explicitExecutions[i].item.amount == 0) {
explicitExecutions[i] = Execution({
offerer: address(0),
conduitKey: bytes32(0),
item: ReceivedItem({
itemType: firstItem.itemType,
token: firstItem.token,
identifier: firstItem.identifier,
amount: aggregatedAmount,
recipient: firstItem.recipient
itemType: ItemType.NATIVE,
token: address(0),
identifier: 0,
amount: 0,
recipient: payable(address(0))
})
});
}
}

// 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)
)
}
}
}

/**
Expand Down Expand Up @@ -1036,6 +993,22 @@ library ExecutionHelper {
(aggregatedConsiderationAmount - aggregatedOfferAmount);
}

// Return an empty execution if aggregated amount equals zero.
if (amount == 0) {
return Execution({
offerer: address(0),
conduitKey: bytes32(0),
item: ReceivedItem({
itemType: ItemType.NATIVE,
token: address(0),
identifier: 0,
amount: 0,
recipient: payable(address(0))
})
});
}

// Otherwise, return the full derived execution.
return Execution({
offerer: sourceOrder.offerer,
conduitKey: sourceOrder.conduitKey,
Expand Down
10 changes: 2 additions & 8 deletions src/fulfillments/lib/FulfillmentLib.sol
Original file line number Diff line number Diff line change
Expand Up @@ -404,10 +404,7 @@ library FulfillmentGeneratorLib {
internal
pure
returns (
function(FulfillmentItems memory, FulfillmentItems memory, uint256)
internal
pure
returns (Fulfillment memory)
function(FulfillmentItems memory, FulfillmentItems memory, uint256) internal pure returns (Fulfillment memory)
)
{
if (aggregationStrategy == AggregationStrategy.MAXIMUM) {
Expand Down Expand Up @@ -1124,10 +1121,7 @@ library FulfillmentGeneratorLib {
internal
pure
returns (
function(FulfillmentItems[] memory, uint256)
internal
pure
returns (FulfillmentComponent[][] memory, ItemCategory[] memory)
function(FulfillmentItems[] memory, uint256) internal pure returns (FulfillmentComponent[][] memory, ItemCategory[] memory)
)
{
if (aggregationStrategy == AggregationStrategy.MAXIMUM) {
Expand Down
Loading

0 comments on commit d8e70cc

Please sign in to comment.