diff --git a/src/ZoneInterface.sol b/src/ZoneInterface.sol index e8d232b..06d1efe 100644 --- a/src/ZoneInterface.sol +++ b/src/ZoneInterface.sol @@ -2,3 +2,5 @@ pragma solidity ^0.8.17; import { ZoneInterface } from "seaport-types/src/interfaces/ZoneInterface.sol"; + +interface LocalZoneInterface is ZoneInterface { } diff --git a/src/executions/ExecutionHelper.sol b/src/executions/ExecutionHelper.sol index 382f053..325c18d 100644 --- a/src/executions/ExecutionHelper.sol +++ b/src/executions/ExecutionHelper.sol @@ -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) { @@ -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 = @@ -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++) { @@ -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 @@ -755,11 +719,6 @@ 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 = @@ -767,37 +726,35 @@ library ExecutionHelper { 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) - ) - } - } } /** @@ -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, diff --git a/src/fulfillments/lib/FulfillmentLib.sol b/src/fulfillments/lib/FulfillmentLib.sol index 9da3d31..a25a36f 100644 --- a/src/fulfillments/lib/FulfillmentLib.sol +++ b/src/fulfillments/lib/FulfillmentLib.sol @@ -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) { @@ -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) { diff --git a/src/helm.sol b/src/helm.sol index 621a484..3229723 100644 --- a/src/helm.sol +++ b/src/helm.sol @@ -30,64 +30,11 @@ import { ZoneParameters } from "seaport-types/src/lib/ConsiderationStructs.sol"; -import { ConduitItemType } from "seaport-types/src/conduit/lib/ConduitEnums.sol"; - -import { - ConduitBatch1155Transfer, - ConduitTransfer -} from "seaport-types/src/conduit/lib/ConduitStructs.sol"; - -import { - TransferHelperItem, - TransferHelperItemsWithRecipient -} from "seaport-types/src/helpers/TransferHelperStructs.sol"; - -import { - Amount, - BroadOrderType, - Caller, - ConduitChoice, - ContractOrderRebate, - Criteria, - EOASignature, - ExtraData, - FulfillmentRecipient, - Offerer, - Recipient, - SignatureMethod, - Time, - Tips, - TokenIndex, - UnavailableReason, - Zone, - ZoneHash -} from "./SpaceEnums.sol"; - -import { - AggregationStrategy, - FulfillAvailableStrategy, - FulfillmentStrategy, - MatchStrategy -} from "./fulfillments/lib/FulfillmentLib.sol"; - -import { - FulfillmentDetails, OrderDetails -} from "./fulfillments/lib/Structs.sol"; - -import { - AdvancedOrdersSpace, - ConsiderationItemSpace, - OfferItemSpace, - OrderComponentsSpace, - ReceivedItemSpace, - SpentItemSpace -} from "./StructSpace.sol"; - /** * @title helm * @author snotrocket.eth * @notice helm is an extension of the console.sol library that provides - * additional logging functionality for Seaport-related structs. + * additional logging functionality for Seaport structs. */ library helm { function log(OrderComponents memory orderComponents) public view { @@ -546,458 +493,6 @@ library helm { console.log(gStr(i, "}")); } - function log(ConduitTransfer memory conduitTransfer) public view { - logConduitTransfer(conduitTransfer, 0); - } - - function log(ConduitTransfer[] memory conduitTransferArray) public view { - console.log(gStr(0, "conduitTransferArray: [")); - for (uint256 j = 0; j < conduitTransferArray.length; j++) { - logConduitTransfer(conduitTransferArray[j], 1); - } - console.log(gStr(0, "]")); - } - - function logConduitTransfer( - ConduitTransfer memory ct, - uint256 i // indent - ) internal view { - console.log(gStr(i, "ConduitTransfer: {")); - console.log(gStr(i + 1, "itemType", _conduitItemTypeStr(ct.itemType))); - console.log(gStr(i + 1, "token", ct.token)); - console.log(gStr(i + 1, "from", ct.from)); - console.log(gStr(i + 1, "to", ct.to)); - console.log(gStr(i + 1, "identifier", ct.identifier)); - console.log(gStr(i + 1, "amount", ct.amount)); - console.log(gStr(i, "}")); - } - - function log(ConduitBatch1155Transfer memory conduitBatch1155Transfer) - public - view - { - logConduitBatch1155Transfer(conduitBatch1155Transfer, 0); - } - - function log( - ConduitBatch1155Transfer[] memory conduitBatch1155TransferArray - ) public view { - console.log(gStr(0, "conduitBatch1155TransferArray: [")); - for (uint256 j = 0; j < conduitBatch1155TransferArray.length; j++) { - logConduitBatch1155Transfer(conduitBatch1155TransferArray[j], 1); - } - console.log(gStr(0, "]")); - } - - function logConduitBatch1155Transfer( - ConduitBatch1155Transfer memory cbt, - uint256 i // indent - ) internal view { - console.log(gStr(i, "ConduitBatch1155Transfer: {")); - console.log(gStr(i + 1, "token", cbt.token)); - console.log(gStr(i + 1, "from", cbt.from)); - console.log(gStr(i + 1, "to", cbt.to)); - console.log(gStr(i + 1, "ids: [")); - for (uint256 j = 0; j < cbt.ids.length; j++) { - console.log(gStr(i + 2, "", cbt.ids[j])); - } - console.log(gStr(i + 1, "]")); - console.log(gStr(i + 1, "amounts: [")); - for (uint256 j = 0; j < cbt.amounts.length; j++) { - console.log(gStr(i + 2, "", cbt.amounts[j])); - } - console.log(gStr(i + 1, "]")); - console.log(gStr(i, "}")); - } - - function log(TransferHelperItem memory transferHelperItem) public view { - logTransferHelperItem(transferHelperItem, 0); - } - - function log(TransferHelperItem[] memory transferHelperItemArray) - public - view - { - console.log(gStr(0, "transferHelperItemArray: [")); - for (uint256 j = 0; j < transferHelperItemArray.length; j++) { - logTransferHelperItem(transferHelperItemArray[j], 1); - } - console.log(gStr(0, "]")); - } - - function logTransferHelperItem( - TransferHelperItem memory thi, - uint256 i // indent - ) internal view { - console.log(gStr(i, "TransferHelperItem: {")); - console.log(gStr(i + 1, "itemType", _conduitItemTypeStr(thi.itemType))); - console.log(gStr(i + 1, "token", thi.token)); - console.log(gStr(i + 1, "identifier", thi.identifier)); - console.log(gStr(i + 1, "amount", thi.amount)); - console.log(gStr(i, "}")); - } - - function log( - TransferHelperItemsWithRecipient memory transferHelperItemsWithRecipient - ) public view { - logTransferHelperItemsWithRecipient(transferHelperItemsWithRecipient, 0); - } - - function log( - TransferHelperItemsWithRecipient[] memory - transferHelperItemsWithRecipientArray - ) public view { - console.log(gStr(0, "transferHelperItemsWithRecipientArray: [")); - for ( - uint256 j = 0; j < transferHelperItemsWithRecipientArray.length; j++ - ) { - logTransferHelperItemsWithRecipient( - transferHelperItemsWithRecipientArray[j], 1 - ); - } - console.log(gStr(0, "]")); - } - - function logTransferHelperItemsWithRecipient( - TransferHelperItemsWithRecipient memory thiwr, - uint256 i // indent - ) internal view { - console.log(gStr(i, "TransferHelperItemsWithRecipient: {")); - console.log(gStr(i + 1, "items: [")); - for (uint256 j = 0; j < thiwr.items.length; j++) { - logTransferHelperItem(thiwr.items[j], i + 2); - } - console.log(gStr(i + 1, "]")); - console.log(gStr(i + 1, "recipient", thiwr.recipient)); - console.log( - gStr(i + 1, "validateERC721Receiver", thiwr.validateERC721Receiver) - ); - console.log(gStr(i, "}")); - } - - function log(OrderDetails memory orderDetails) public view { - logOrderDetails(orderDetails, 0); - } - - function log(OrderDetails[] memory orderDetailsArray) public view { - console.log(gStr(0, "orderDetailsArray: [")); - for (uint256 j = 0; j < orderDetailsArray.length; j++) { - logOrderDetails(orderDetailsArray[j], 1); - } - console.log(gStr(0, "]")); - } - - function logOrderDetails( - OrderDetails memory od, - uint256 i // indent - ) internal view { - console.log(gStr(i, "OrderDetails: {")); - console.log(gStr(i + 1, "offerer", od.offerer)); - console.log(gStr(i + 1, "conduitKey", od.conduitKey)); - console.log(gStr(i + 1, "offer: [")); - for (uint256 j = 0; j < od.offer.length; j++) { - logSpentItem(od.offer[j], i + 2); - } - console.log(gStr(i + 1, "]")); - console.log(gStr(i + 1, "consideration: [")); - for (uint256 j = 0; j < od.consideration.length; j++) { - logReceivedItem(od.consideration[j], i + 2); - } - console.log(gStr(i + 1, "]")); - console.log(gStr(i + 1, "isContract", od.isContract)); - console.log(gStr(i + 1, "orderHash", od.orderHash)); - console.log( - gStr( - i + 1, - "unavailableReason", - _unavailableReasonStr(od.unavailableReason) - ) - ); - console.log(gStr(i, "}")); - } - - function log(FulfillmentDetails memory fulfillmentDetails) public view { - logFulfillmentDetails(fulfillmentDetails, 0); - } - - function log(FulfillmentDetails[] memory fulfillmentDetailsArray) - public - view - { - console.log(gStr(0, "fulfillmentDetailsArray: [")); - for (uint256 j = 0; j < fulfillmentDetailsArray.length; j++) { - logFulfillmentDetails(fulfillmentDetailsArray[j], 1); - } - console.log(gStr(0, "]")); - } - - function logFulfillmentDetails( - FulfillmentDetails memory fd, - uint256 i // indent - ) internal view { - console.log(gStr(i, "FulfillmentDetails: {")); - console.log(gStr(i + 1, "orders: [")); - for (uint256 j = 0; j < fd.orders.length; j++) { - logOrderDetails(fd.orders[j], i + 2); - } - console.log(gStr(i + 1, "]")); - console.log(gStr(i + 1, "recipient", fd.recipient)); - console.log(gStr(i + 1, "fulfiller", fd.fulfiller)); - console.log( - gStr(i + 1, "nativeTokensSupplied", fd.nativeTokensSupplied) - ); - console.log(gStr(i + 1, "fulfillerConduitKey", fd.fulfillerConduitKey)); - console.log(gStr(i + 1, "seaport", fd.seaport)); - console.log(gStr(i, "}")); - } - - function log(OfferItemSpace memory offerItemSpace) public view { - logOfferItemSpace(offerItemSpace, 0); - } - - function log(OfferItemSpace[] memory offerItemSpaceArray) public view { - console.log(gStr(0, "offerItemSpaceArray: [")); - for (uint256 j = 0; j < offerItemSpaceArray.length; j++) { - logOfferItemSpace(offerItemSpaceArray[j], 1); - } - console.log(gStr(0, "]")); - } - - function logOfferItemSpace( - OfferItemSpace memory ois, - uint256 i // indent - ) internal view { - console.log(gStr(i, "OfferItemSpace: {")); - console.log(gStr(i + 1, "itemType", _itemTypeStr(ois.itemType))); - console.log(gStr(i + 1, "tokenIndex", _tokenIndexStr(ois.tokenIndex))); - console.log(gStr(i + 1, "criteria", _criteriaStr(ois.criteria))); - console.log(gStr(i + 1, "amount", _amountStr(ois.amount))); - console.log(gStr(i, "}")); - } - - function log(ConsiderationItemSpace memory considerationItemSpace) - public - view - { - logConsiderationItemSpace(considerationItemSpace, 0); - } - - function log(ConsiderationItemSpace[] memory considerationItemSpaceArray) - public - view - { - console.log(gStr(0, "considerationItemSpaceArray: [")); - for (uint256 j = 0; j < considerationItemSpaceArray.length; j++) { - logConsiderationItemSpace(considerationItemSpaceArray[j], 1); - } - console.log(gStr(0, "]")); - } - - function logConsiderationItemSpace( - ConsiderationItemSpace memory cis, - uint256 i // indent - ) internal view { - console.log(gStr(i, "ConsiderationItemSpace: {")); - console.log(gStr(i + 1, "itemType", _itemTypeStr(cis.itemType))); - console.log(gStr(i + 1, "tokenIndex", _tokenIndexStr(cis.tokenIndex))); - console.log(gStr(i + 1, "criteria", _criteriaStr(cis.criteria))); - console.log(gStr(i + 1, "amount", _amountStr(cis.amount))); - console.log(gStr(i + 1, "recipient", _recipientStr(cis.recipient))); - console.log(gStr(i, "}")); - } - - function log(SpentItemSpace memory spentItemSpace) public view { - logSpentItemSpace(spentItemSpace, 0); - } - - function log(SpentItemSpace[] memory spentItemSpaceArray) public view { - console.log(gStr(0, "spentItemSpaceArray: [")); - for (uint256 j = 0; j < spentItemSpaceArray.length; j++) { - logSpentItemSpace(spentItemSpaceArray[j], 1); - } - console.log(gStr(0, "]")); - } - - function logSpentItemSpace( - SpentItemSpace memory sis, - uint256 i // indent - ) internal view { - console.log(gStr(i, "SpentItemSpace: {")); - console.log(gStr(i + 1, "itemType", _itemTypeStr(sis.itemType))); - console.log(gStr(i + 1, "tokenIndex", _tokenIndexStr(sis.tokenIndex))); - console.log(gStr(i, "}")); - } - - function log(ReceivedItemSpace memory receivedItemSpace) public view { - logReceivedItemSpace(receivedItemSpace, 0); - } - - function log(ReceivedItemSpace[] memory receivedItemSpaceArray) - public - view - { - console.log(gStr(0, "receivedItemSpaceArray: [")); - for (uint256 j = 0; j < receivedItemSpaceArray.length; j++) { - logReceivedItemSpace(receivedItemSpaceArray[j], 1); - } - console.log(gStr(0, "]")); - } - - function logReceivedItemSpace( - ReceivedItemSpace memory ris, - uint256 i // indent - ) internal view { - console.log(gStr(i, "ReceivedItemSpace: {")); - console.log(gStr(i + 1, "itemType", _itemTypeStr(ris.itemType))); - console.log(gStr(i + 1, "tokenIndex", _tokenIndexStr(ris.tokenIndex))); - console.log(gStr(i + 1, "recipient", _recipientStr(ris.recipient))); - console.log(gStr(i, "}")); - } - - function log(OrderComponentsSpace memory orderComponentsSpace) - public - view - { - logOrderComponentsSpace(orderComponentsSpace, 0); - } - - function log(OrderComponentsSpace[] memory orderComponentsSpaceArray) - public - view - { - console.log(gStr(0, "orderComponentsSpaceArray: [")); - for (uint256 j = 0; j < orderComponentsSpaceArray.length; j++) { - logOrderComponentsSpace(orderComponentsSpaceArray[j], 1); - } - console.log(gStr(0, "]")); - } - - function logOrderComponentsSpace( - OrderComponentsSpace memory ocs, - uint256 i // indent - ) internal view { - console.log(gStr(i, "OrderComponentsSpace: {")); - console.log(gStr(i + 1, "offerer", _offererStr(ocs.offerer))); - console.log(gStr(i + 1, "zone", _zoneStr(ocs.zone))); - console.log(gStr(i + 1, "offer: [")); - for (uint256 j = 0; j < ocs.offer.length; j++) { - logOfferItemSpace(ocs.offer[j], i + 2); - } - console.log(gStr(i + 1, "]")); - console.log(gStr(i + 1, "consideration: [")); - for (uint256 j = 0; j < ocs.consideration.length; j++) { - logConsiderationItemSpace(ocs.consideration[j], i + 2); - } - console.log(gStr(i + 1, "]")); - console.log(gStr(i + 1, "orderType", _broadOrderTypeStr(ocs.orderType))); - console.log(gStr(i + 1, "time", _timeStr(ocs.time))); - console.log(gStr(i + 1, "zoneHash", _zoneHashStr(ocs.zoneHash))); - console.log( - gStr( - i + 1, - "signatureMethod", - _signatureMethodStr(ocs.signatureMethod) - ) - ); - console.log( - gStr( - i + 1, - "eoaSignatureType", - _eoaSignatureTypeStr(ocs.eoaSignatureType) - ) - ); - console.log(gStr(i + 1, "bulkSigHeight", ocs.bulkSigHeight)); - console.log(gStr(i + 1, "bulkSigIndex", ocs.bulkSigIndex)); - console.log(gStr(i + 1, "conduit", _conduitChoiceStr(ocs.conduit))); - console.log(gStr(i + 1, "tips", _tipsStr(ocs.tips))); - console.log( - gStr( - i + 1, - "unavailableReason", - _unavailableReasonStr(ocs.unavailableReason) - ) - ); - console.log(gStr(i + 1, "extraData", _extraDataStr(ocs.extraData))); - console.log(gStr(i + 1, "rebate", _contractOrderRebateStr(ocs.rebate))); - console.log(gStr(i, "}")); - } - - function log(AdvancedOrdersSpace memory advancedOrdersSpace) public view { - logAdvancedOrdersSpace(advancedOrdersSpace, 0); - } - - function log(AdvancedOrdersSpace[] memory advancedOrdersSpaceArray) - public - view - { - console.log(gStr(0, "advancedOrdersSpaceArray: [")); - for (uint256 j = 0; j < advancedOrdersSpaceArray.length; j++) { - logAdvancedOrdersSpace(advancedOrdersSpaceArray[j], 1); - } - console.log(gStr(0, "]")); - } - - function logAdvancedOrdersSpace( - AdvancedOrdersSpace memory aos, - uint256 i // indent - ) internal view { - console.log(gStr(i, "AdvancedOrdersSpace: {")); - console.log(gStr(i + 1, "orders: [")); - for (uint256 j = 0; j < aos.orders.length; j++) { - logOrderComponentsSpace(aos.orders[j], i + 2); - } - console.log(gStr(i + 1, "]")); - console.log(gStr(i + 1, "isMatchable", aos.isMatchable)); - console.log(gStr(i + 1, "maximumFulfilled", aos.maximumFulfilled)); - console.log( - gStr(i + 1, "recipient", _fulfillmentRecipientStr(aos.recipient)) - ); - console.log(gStr(i + 1, "conduit", _conduitChoiceStr(aos.conduit))); - console.log(gStr(i + 1, "caller", _callerStr(aos.caller))); - logFulfillmentStrategy(aos.strategy, i + 1); - console.log(gStr(i, "}")); - } - - function log(FulfillmentStrategy memory fulfillmentStrategy) public view { - logFulfillmentStrategy(fulfillmentStrategy, 0); - } - - function log(FulfillmentStrategy[] memory fulfillmentStrategyArray) - public - view - { - console.log(gStr(0, "fulfillmentStrategyArray: [")); - for (uint256 j = 0; j < fulfillmentStrategyArray.length; j++) { - logFulfillmentStrategy(fulfillmentStrategyArray[j], 1); - } - console.log(gStr(0, "]")); - } - - function logFulfillmentStrategy( - FulfillmentStrategy memory fs, - uint256 i // indent - ) internal view { - console.log(gStr(i, "FulfillmentStrategy: {")); - console.log( - gStr( - i + 1, - "aggregationStrategy", - _aggregationStrategyStr(fs.aggregationStrategy) - ) - ); - console.log( - gStr( - i + 1, - "fulfillAvailableStrategy", - _fulfillAvailableStrategyStr(fs.fulfillAvailableStrategy) - ) - ); - console.log( - gStr(i + 1, "matchStrategy", _matchStrategyStr(fs.matchStrategy)) - ); - console.log(gStr(i, "}")); - } - //////////////////////////////////////////////////////////////////////////// // Helpers // //////////////////////////////////////////////////////////////////////////// @@ -1082,18 +577,6 @@ library helm { ); } - function gStr( - uint256 i, // indent - string memory labelString, - bool value - ) public pure returns (string memory) { - string memory indentString = generateIndentString(i); - return string.concat( - indentString, - string.concat(labelString, ": ", value ? "True" : "False") - ); - } - //////////////////////////////////////////////////////////////////////////// // Log Arrays // //////////////////////////////////////////////////////////////////////////// @@ -1253,342 +736,4 @@ library helm { return "UNKNOWN"; } - - function _conduitItemTypeStr(ConduitItemType conduitItemType) - internal - pure - returns (string memory) - { - if (conduitItemType == ConduitItemType.NATIVE) return "NATIVE"; - if (conduitItemType == ConduitItemType.ERC20) return "ERC20"; - if (conduitItemType == ConduitItemType.ERC721) return "ERC721"; - if (conduitItemType == ConduitItemType.ERC1155) return "ERC1155"; - - return "UNKNOWN"; - } - - function _amountStr(Amount amount) internal pure returns (string memory) { - if (amount == Amount.FIXED) return "FIXED"; - if (amount == Amount.ASCENDING) return "ASCENDING"; - if (amount == Amount.DESCENDING) return "DESCENDING"; - - return "UNKNOWN"; - } - - function _broadOrderTypeStr(BroadOrderType broadOrderType) - internal - pure - returns (string memory) - { - if (broadOrderType == BroadOrderType.FULL) return "FULL"; - if (broadOrderType == BroadOrderType.PARTIAL) return "PARTIAL"; - if (broadOrderType == BroadOrderType.CONTRACT) return "CONTRACT"; - - return "UNKNOWN"; - } - - function _callerStr(Caller caller) internal pure returns (string memory) { - if (caller == Caller.TEST_CONTRACT) return "TEST_CONTRACT"; - if (caller == Caller.ALICE) return "ALICE"; - if (caller == Caller.BOB) return "BOB"; - if (caller == Caller.CAROL) return "CAROL"; - if (caller == Caller.DILLON) return "DILLON"; - if (caller == Caller.EVE) return "EVE"; - if (caller == Caller.FRANK) return "FRANK"; - - return "UNKNOWN"; - } - - function _conduitChoiceStr(ConduitChoice conduitChoice) - internal - pure - returns (string memory) - { - if (conduitChoice == ConduitChoice.NONE) return "NONE"; - if (conduitChoice == ConduitChoice.ONE) return "ONE"; - if (conduitChoice == ConduitChoice.TWO) return "TWO"; - - return "UNKNOWN"; - } - - function _contractOrderRebateStr(ContractOrderRebate contractOrderRebate) - internal - pure - returns (string memory) - { - if (contractOrderRebate == ContractOrderRebate.NONE) return "NONE"; - if (contractOrderRebate == ContractOrderRebate.MORE_OFFER_ITEMS) { - return "MORE_OFFER_ITEMS"; - } - if (contractOrderRebate == ContractOrderRebate.MORE_OFFER_ITEM_AMOUNTS) - { - return "MORE_OFFER_ITEM_AMOUNTS"; - } - if (contractOrderRebate == ContractOrderRebate.LESS_CONSIDERATION_ITEMS) - { - return "LESS_CONSIDERATION_ITEMS"; - } - if ( - contractOrderRebate - == ContractOrderRebate.LESS_CONSIDERATION_ITEM_AMOUNTS - ) { - return "LESS_CONSIDERATION_ITEM_AMOUNTS"; - } - - return "UNKNOWN"; - } - - function _criteriaStr(Criteria criteria) - internal - pure - returns (string memory) - { - if (criteria == Criteria.MERKLE) return "MERKLE"; - if (criteria == Criteria.WILDCARD) return "WILDCARD"; - - return "UNKNOWN"; - } - - function _eoaSignatureTypeStr(EOASignature eoaSignature) - internal - pure - returns (string memory) - { - if (eoaSignature == EOASignature.STANDARD) return "STANDARD"; - if (eoaSignature == EOASignature.EIP2098) return "EIP2098"; - if (eoaSignature == EOASignature.BULK) return "BULK"; - if (eoaSignature == EOASignature.BULK2098) return "BULK2098"; - - return "UNKNOWN"; - } - - function _extraDataStr(ExtraData extraData) - internal - pure - returns (string memory) - { - if (extraData == ExtraData.NONE) return "NONE"; - if (extraData == ExtraData.RANDOM) return "RANDOM"; - - return "UNKNOWN"; - } - - function _fulfillmentRecipientStr(FulfillmentRecipient fulfillmentRecipient) - internal - pure - returns (string memory) - { - if (fulfillmentRecipient == FulfillmentRecipient.ZERO) return "ZERO"; - if (fulfillmentRecipient == FulfillmentRecipient.ALICE) return "ALICE"; - if (fulfillmentRecipient == FulfillmentRecipient.BOB) return "BOB"; - if (fulfillmentRecipient == FulfillmentRecipient.EVE) return "EVE"; - - return "UNKNOWN"; - } - - function _offererStr(Offerer offerer) - internal - pure - returns (string memory) - { - if (offerer == Offerer.TEST_CONTRACT) return "TEST_CONTRACT"; - if (offerer == Offerer.ALICE) return "ALICE"; - if (offerer == Offerer.BOB) return "BOB"; - if (offerer == Offerer.CONTRACT_OFFERER) return "CONTRACT_OFFERER"; - if (offerer == Offerer.EIP1271) return "EIP1271"; - - return "UNKNOWN"; - } - - function _recipientStr(Recipient recipient) - internal - pure - returns (string memory) - { - if (recipient == Recipient.OFFERER) return "OFFERER"; - if (recipient == Recipient.RECIPIENT) return "RECIPIENT"; - if (recipient == Recipient.DILLON) return "DILLON"; - if (recipient == Recipient.EVE) return "EVE"; - if (recipient == Recipient.FRANK) return "FRANK"; - - return "UNKNOWN"; - } - - function _signatureMethodStr(SignatureMethod signatureMethod) - internal - pure - returns (string memory) - { - if (signatureMethod == SignatureMethod.EOA) return "EOA"; - if (signatureMethod == SignatureMethod.VALIDATE) return "VALIDATE"; - if (signatureMethod == SignatureMethod.EIP1271) return "EIP1271"; - if (signatureMethod == SignatureMethod.CONTRACT) return "CONTRACT"; - if (signatureMethod == SignatureMethod.SELF_AD_HOC) { - return "SELF_AD_HOC"; - } - - return "UNKNOWN"; - } - - function _timeStr(Time time) internal pure returns (string memory) { - if (time == Time.STARTS_IN_FUTURE) return "STARTS_IN_FUTURE"; - if (time == Time.EXACT_START) return "EXACT_START"; - if (time == Time.ONGOING) return "ONGOING"; - if (time == Time.EXACT_END) return "EXACT_END"; - if (time == Time.EXPIRED) return "EXPIRED"; - - return "UNKNOWN"; - } - - function _tipsStr(Tips tips) internal pure returns (string memory) { - if (tips == Tips.NONE) return "NONE"; - if (tips == Tips.TIPS) return "TIPS"; - - return "UNKNOWN"; - } - - function _tokenIndexStr(TokenIndex tokenIndex) - internal - pure - returns (string memory) - { - if (tokenIndex == TokenIndex.ONE) return "ONE"; - if (tokenIndex == TokenIndex.TWO) return "TWO"; - if (tokenIndex == TokenIndex.THREE) return "THREE"; - - return "UNKNOWN"; - } - - function _unavailableReasonStr(UnavailableReason unavailableReason) - internal - pure - returns (string memory) - { - if (unavailableReason == UnavailableReason.AVAILABLE) { - return "AVAILABLE"; - } - if (unavailableReason == UnavailableReason.EXPIRED) return "EXPIRED"; - if (unavailableReason == UnavailableReason.STARTS_IN_FUTURE) { - return "STARTS_IN_FUTURE"; - } - if (unavailableReason == UnavailableReason.CANCELLED) { - return "CANCELLED"; - } - if (unavailableReason == UnavailableReason.ALREADY_FULFILLED) { - return "ALREADY_FULFILLED"; - } - if (unavailableReason == UnavailableReason.MAX_FULFILLED_SATISFIED) { - return "MAX_FULFILLED_SATISFIED"; - } - if (unavailableReason == UnavailableReason.GENERATE_ORDER_FAILURE) { - return "GENERATE_ORDER_FAILURE"; - } - - return "UNKNOWN"; - } - - function _zoneStr(Zone zone) internal pure returns (string memory) { - if (zone == Zone.NONE) return "NONE"; - if (zone == Zone.PASS) return "PASS"; - if (zone == Zone.FAIL) return "FAIL"; - - return "UNKNOWN"; - } - - function _zoneHashStr(ZoneHash zoneHash) - internal - pure - returns (string memory) - { - if (zoneHash == ZoneHash.NONE) return "NONE"; - if (zoneHash == ZoneHash.VALID) return "VALID"; - if (zoneHash == ZoneHash.INVALID) return "INVALID"; - - return "UNKNOWN"; - } - - function _aggregationStrategyStr(AggregationStrategy aggregationStrategy) - internal - pure - returns (string memory) - { - if (aggregationStrategy == AggregationStrategy.MINIMUM) { - return "MINIMUM"; - } - if (aggregationStrategy == AggregationStrategy.MAXIMUM) { - return "MAXIMUM"; - } - if (aggregationStrategy == AggregationStrategy.RANDOM) return "RANDOM"; - - return "UNKNOWN"; - } - - function _fulfillAvailableStrategyStr( - FulfillAvailableStrategy fulfillAvailableStrategy - ) internal pure returns (string memory) { - if (fulfillAvailableStrategy == FulfillAvailableStrategy.KEEP_ALL) { - return "KEEP_ALL"; - } - if ( - fulfillAvailableStrategy - == FulfillAvailableStrategy.DROP_SINGLE_OFFER - ) return "DROP_SINGLE_OFFER"; - if (fulfillAvailableStrategy == FulfillAvailableStrategy.DROP_ALL_OFFER) - { - return "DROP_ALL_OFFER"; - } - if ( - fulfillAvailableStrategy - == FulfillAvailableStrategy.DROP_RANDOM_OFFER - ) return "DROP_RANDOM_OFFER"; - if ( - fulfillAvailableStrategy - == FulfillAvailableStrategy.DROP_SINGLE_KEEP_FILTERED - ) { - return "DROP_SINGLE_KEEP_FILTERED"; - } - if ( - fulfillAvailableStrategy - == FulfillAvailableStrategy.DROP_ALL_KEEP_FILTERED - ) { - return "DROP_ALL_KEEP_FILTERED"; - } - if ( - fulfillAvailableStrategy - == FulfillAvailableStrategy.DROP_RANDOM_KEEP_FILTERED - ) { - return "DROP_RANDOM_KEEP_FILTERED"; - } - - return "UNKNOWN"; - } - - function _matchStrategyStr(MatchStrategy matchStrategy) - internal - pure - returns (string memory) - { - if (matchStrategy == MatchStrategy.MAX_FILTERS) return "MAX_FILTERS"; - if (matchStrategy == MatchStrategy.MIN_FILTERS) return "MIN_FILTERS"; - if (matchStrategy == MatchStrategy.MAX_INCLUSION) { - return "MAX_INCLUSION"; - } - if (matchStrategy == MatchStrategy.MIN_INCLUSION) { - return "MIN_INCLUSION"; - } - if (matchStrategy == MatchStrategy.MIN_INCLUSION_MAX_FILTERS) { - return "MIN_INCLUSION_MAX_FILTERS"; - } - if (matchStrategy == MatchStrategy.MAX_EXECUTIONS) { - return "MAX_EXECUTIONS"; - } - if (matchStrategy == MatchStrategy.MIN_EXECUTIONS) { - return "MIN_EXECUTIONS"; - } - if (matchStrategy == MatchStrategy.MIN_EXECUTIONS_MAX_FILTERS) { - return "MIN_EXECUTIONS_MAX_FILTERS"; - } - - return "UNKNOWN"; - } } diff --git a/src/lib/ZoneParametersLib.sol b/src/lib/ZoneParametersLib.sol index 6f14b07..3823ed7 100644 --- a/src/lib/ZoneParametersLib.sol +++ b/src/lib/ZoneParametersLib.sol @@ -72,7 +72,66 @@ library ZoneParametersLib { bytes32[] orderHashes; } - function getZoneParameters( + function getZoneAuthorizeParameters( + AdvancedOrder memory advancedOrder, + address fulfiller, + uint256 counter, + address seaport, + CriteriaResolver[] memory criteriaResolvers + ) internal view returns (ZoneParameters memory zoneParameters) { + SeaportInterface seaportInterface = SeaportInterface(seaport); + // Get orderParameters from advancedOrder + OrderParameters memory orderParameters = advancedOrder.parameters; + + // Get orderHash + bytes32 orderHash = + advancedOrder.getTipNeutralizedOrderHash(seaportInterface, counter); + + (SpentItem[] memory spentItems, ReceivedItem[] memory receivedItems) = + orderParameters.getSpentAndReceivedItems( + advancedOrder.numerator, + advancedOrder.denominator, + 0, + criteriaResolvers + ); + + // Create ZoneParameters and add to zoneParameters array + zoneParameters = ZoneParameters({ + orderHash: orderHash, + fulfiller: fulfiller, + offerer: orderParameters.offerer, + offer: spentItems, + consideration: receivedItems, + extraData: advancedOrder.extraData, + orderHashes: new bytes32[](0), + startTime: orderParameters.startTime, + endTime: orderParameters.endTime, + zoneHash: orderParameters.zoneHash + }); + } + + function getZoneAuthorizeParameters( + AdvancedOrder[] memory advancedOrders, + address fulfiller, + uint256 maximumFulfilled, + address seaport, + CriteriaResolver[] memory criteriaResolvers, + UnavailableReason[] memory unavailableReasons + ) internal view returns (ZoneParameters[] memory) { + return _getZoneParametersFromStruct( + _getZoneParametersStruct( + advancedOrders, + fulfiller, + maximumFulfilled, + seaport, + criteriaResolvers + ), + unavailableReasons, + true + ); + } + + function getZoneValidateParameters( AdvancedOrder memory advancedOrder, address fulfiller, uint256 counter, @@ -107,14 +166,14 @@ library ZoneParametersLib { offer: spentItems, consideration: receivedItems, extraData: advancedOrder.extraData, - orderHashes: orderHashes, + orderHashes: new bytes32[](0), startTime: orderParameters.startTime, endTime: orderParameters.endTime, zoneHash: orderParameters.zoneHash }); } - function getZoneParameters( + function getZoneValidateParameters( AdvancedOrder[] memory advancedOrders, address fulfiller, uint256 maximumFulfilled, @@ -130,7 +189,8 @@ library ZoneParametersLib { seaport, criteriaResolvers ), - unavailableReasons + unavailableReasons, + false ); } @@ -152,7 +212,8 @@ library ZoneParametersLib { function _getZoneParametersFromStruct( ZoneParametersStruct memory zoneParametersStruct, - UnavailableReason[] memory unavailableReasons + UnavailableReason[] memory unavailableReasons, + bool isAuthorize ) internal view returns (ZoneParameters[] memory) { // TODO: use testHelpers pattern to use single amount deriver helper ZoneDetails memory details = _getZoneDetails(zoneParametersStruct); @@ -163,7 +224,7 @@ library ZoneParametersLib { // Iterate over advanced orders to calculate orderHashes _applyOrderHashes(details, zoneParametersStruct.seaport); - return _finalizeZoneParameters(details); + return _finalizeZoneParameters(details, isAuthorize); } function _getZoneDetails(ZoneParametersStruct memory zoneParametersStruct) @@ -251,11 +312,10 @@ library ZoneParametersLib { ); } - function _finalizeZoneParameters(ZoneDetails memory zoneDetails) - internal - pure - returns (ZoneParameters[] memory zoneParameters) - { + function _finalizeZoneParameters( + ZoneDetails memory zoneDetails, + bool isAuthorize + ) internal pure returns (ZoneParameters[] memory zoneParameters) { zoneParameters = new ZoneParameters[](zoneDetails.advancedOrders.length); // Iterate through advanced orders to create zoneParameters @@ -266,6 +326,17 @@ library ZoneParametersLib { break; } + bytes32[] memory orderHashes; + + if (isAuthorize) { + orderHashes = new bytes32[](i); + for (uint256 j = 0; j < i; j++) { + orderHashes[j] = zoneDetails.orderHashes[j]; + } + } else { + orderHashes = zoneDetails.orderHashes; + } + if (zoneDetails.orderHashes[i] != bytes32(0)) { // Create ZoneParameters and add to zoneParameters array zoneParameters[i] = _createZoneParameters( @@ -273,7 +344,7 @@ library ZoneParametersLib { zoneDetails.orderDetails[i], zoneDetails.advancedOrders[i], zoneDetails.fulfiller, - zoneDetails.orderHashes + orderHashes ); ++totalFulfilled; }