Skip to content

Commit

Permalink
simplify reference order validator
Browse files Browse the repository at this point in the history
  • Loading branch information
0age committed Feb 28, 2024
1 parent e2b1894 commit a482291
Showing 1 changed file with 19 additions and 61 deletions.
80 changes: 19 additions & 61 deletions reference/lib/ReferenceOrderValidator.sol
Original file line number Diff line number Diff line change
Expand Up @@ -465,7 +465,10 @@ contract ReferenceOrderValidator is
}
} else {
// If the call fails, revert or return empty.
(orderHash, orderToExecute) = _revertOrReturnEmpty(revertOnInvalid, orderHash);
(orderHash, orderToExecute) = _revertOrReturnEmpty(
revertOnInvalid,
orderHash
);
return orderHash;
}
}
Expand All @@ -484,29 +487,15 @@ contract ReferenceOrderValidator is
SpentItem[] memory extendedSpent = new SpentItem[](
newOfferLength
);
uint256[]
memory extendedSpentItemOriginalAmounts = new uint256[](
newOfferLength
);

// Copy original spent items to new array.
for (uint256 i = 0; i < originalOfferLength; ++i) {
extendedSpent[i] = orderToExecute.spentItems[i];
extendedSpentItemOriginalAmounts[i] = (
orderToExecute.spentItemOriginalAmounts[i]
);
}

// Update order to execute with extended items.
orderToExecute.spentItems = extendedSpent;
orderToExecute.spentItemOriginalAmounts = (
extendedSpentItemOriginalAmounts
);
}
} else {
orderToExecute.spentItemOriginalAmounts = new uint256[](
originalOfferLength
);
}

// Loop through each new offer and ensure the new amounts are at
Expand Down Expand Up @@ -541,21 +530,16 @@ contract ReferenceOrderValidator is
) {
revert InvalidContractOrder(orderHash);
}

// Update the original amounts to use the generated amounts.
originalOffer.amount = newOffer.amount;
orderToExecute.spentItemOriginalAmounts[i] = newOffer.amount;
}

// Add new offer items if there are more than original.
for (uint256 i = originalOfferLength; i < newOfferLength; ++i) {
SpentItem memory newOffer = offer[i];
orderToExecute.spentItems = offer;
orderToExecute.spentItemOriginalAmounts = new uint256[](
offer.length
);

orderToExecute.spentItems[i].itemType = newOffer.itemType;
orderToExecute.spentItems[i].token = newOffer.token;
orderToExecute.spentItems[i].identifier = newOffer.identifier;
orderToExecute.spentItems[i].amount = newOffer.amount;
orderToExecute.spentItemOriginalAmounts[i] = newOffer.amount;
// Add new offer items if there are more than original.
for (uint256 i = 0; i < offer.length; ++i) {
orderToExecute.spentItemOriginalAmounts[i] = offer[i].amount;
}
}

Expand All @@ -571,10 +555,6 @@ contract ReferenceOrderValidator is
revert InvalidContractOrder(orderHash);
}

orderToExecute.receivedItemOriginalAmounts = new uint256[](
newConsiderationLength
);

// Loop through and check consideration.
for (uint256 i = 0; i < newConsiderationLength; ++i) {
ReceivedItem memory newConsideration = consideration[i];
Expand Down Expand Up @@ -610,45 +590,23 @@ contract ReferenceOrderValidator is
) {
revert InvalidContractOrder(orderHash);
}

// Update the original amounts to use the generated amounts.
originalConsideration.amount = newConsideration.amount;
originalConsideration.recipient = newConsideration.recipient;

orderToExecute.receivedItemOriginalAmounts[i] = (
newConsideration.amount
);
}

{
ReceivedItem[] memory shortenedReceivedItems = (
new ReceivedItem[](newConsiderationLength)
);

// Iterate over original consideration array and copy to new.
for (uint256 i = 0; i < newConsiderationLength; ++i) {
shortenedReceivedItems[i] = orderToExecute.receivedItems[i];
}

orderToExecute.receivedItems = shortenedReceivedItems;
}

uint256[] memory shortenedReceivedItemOriginalAmounts = (
new uint256[](newConsiderationLength)
orderToExecute.receivedItems = consideration;
orderToExecute.receivedItemOriginalAmounts = new uint256[](
consideration.length
);

// Iterate over original consideration array and copy to new.
for (uint256 i = 0; i < newConsiderationLength; ++i) {
shortenedReceivedItemOriginalAmounts[i] = (
orderToExecute.receivedItemOriginalAmounts[i]
for (uint256 i = 0; i < consideration.length; ++i) {
orderToExecute.receivedItemOriginalAmounts[i] = (
consideration[i].amount
);
}

orderToExecute.receivedItemOriginalAmounts = (
shortenedReceivedItemOriginalAmounts
);
}

orderToExecute.numerator = 1;

// Return the order hash.
return orderHash;
}
Expand Down

0 comments on commit a482291

Please sign in to comment.