From 74bd3f15bc961e36a18cd2688bf164fa1f4f60ba Mon Sep 17 00:00:00 2001 From: moshui <sme_moshui@outlook.com> Date: Wed, 26 Jul 2023 11:06:52 +0800 Subject: [PATCH 01/10] remove three functions --- src/interfaces/ConsiderationInterface.sol | 185 ---------------------- 1 file changed, 185 deletions(-) diff --git a/src/interfaces/ConsiderationInterface.sol b/src/interfaces/ConsiderationInterface.sol index 3a3d07d..a126501 100644 --- a/src/interfaces/ConsiderationInterface.sol +++ b/src/interfaces/ConsiderationInterface.sol @@ -118,141 +118,6 @@ interface ConsiderationInterface { address recipient ) external payable returns (bool fulfilled); - /** - * @notice Attempt to fill a group of orders, each with an arbitrary number - * of items for offer and consideration. Any order that is not - * currently active, has already been fully filled, or has been - * cancelled will be omitted. Remaining offer and consideration - * items will then be aggregated where possible as indicated by the - * supplied offer and consideration component arrays and aggregated - * items will be transferred to the fulfiller or to each intended - * recipient, respectively. Note that a failing item transfer or an - * issue with order formatting will cause the entire batch to fail. - * Note that this function does not support criteria-based orders or - * partial filling of orders (though filling the remainder of a - * partially-filled order is supported). - * - * @param orders The orders to fulfill. Note that both - * the offerer and the fulfiller must first - * approve this contract (or the - * corresponding conduit if indicated) to - * transfer any relevant tokens on their - * behalf and that contracts must implement - * `onERC1155Received` to receive ERC1155 - * tokens as consideration. - * @param offerFulfillments An array of FulfillmentComponent arrays - * indicating which offer items to attempt - * to aggregate when preparing executions. - * @param considerationFulfillments An array of FulfillmentComponent arrays - * indicating which consideration items to - * attempt to aggregate when preparing - * executions. - * @param fulfillerConduitKey A bytes32 value indicating what conduit, - * if any, to source the fulfiller's token - * approvals from. The zero hash signifies - * that no conduit should be used, with - * direct approvals set on this contract. - * @param maximumFulfilled The maximum number of orders to fulfill. - * - * @return availableOrders An array of booleans indicating if each order - * with an index corresponding to the index of the - * returned boolean was fulfillable or not. - * @return executions An array of elements indicating the sequence of - * transfers performed as part of matching the given - * orders. Note that unspent offer item amounts or - * native tokens will not be reflected as part of - * this array. - */ - function fulfillAvailableOrders( - Order[] calldata orders, - FulfillmentComponent[][] calldata offerFulfillments, - FulfillmentComponent[][] calldata considerationFulfillments, - bytes32 fulfillerConduitKey, - uint256 maximumFulfilled - ) - external - payable - returns (bool[] memory availableOrders, Execution[] memory executions); - - /** - * @notice Attempt to fill a group of orders, fully or partially, with an - * arbitrary number of items for offer and consideration per order - * alongside criteria resolvers containing specific token - * identifiers and associated proofs. Any order that is not - * currently active, has already been fully filled, or has been - * cancelled will be omitted. Remaining offer and consideration - * items will then be aggregated where possible as indicated by the - * supplied offer and consideration component arrays and aggregated - * items will be transferred to the fulfiller or to each intended - * recipient, respectively. Note that a failing item transfer or an - * issue with order formatting will cause the entire batch to fail. - * - * @param advancedOrders The orders to fulfill along with the - * fraction of those orders to attempt to - * fill. Note that both the offerer and the - * fulfiller must first approve this - * contract (or their preferred conduit if - * indicated by the order) to transfer any - * relevant tokens on their behalf and that - * contracts must implement - * `onERC1155Received` to enable receipt of - * ERC1155 tokens as consideration. Also - * note that all offer and consideration - * components must have no remainder after - * multiplication of the respective amount - * with the supplied fraction for an - * order's partial fill amount to be - * considered valid. - * @param criteriaResolvers An array where each element contains a - * reference to a specific offer or - * consideration, a token identifier, and a - * proof that the supplied token identifier - * is contained in the merkle root held by - * the item in question's criteria element. - * Note that an empty criteria indicates - * that any (transferable) token - * identifier on the token in question is - * valid and that no associated proof needs - * to be supplied. - * @param offerFulfillments An array of FulfillmentComponent arrays - * indicating which offer items to attempt - * to aggregate when preparing executions. - * @param considerationFulfillments An array of FulfillmentComponent arrays - * indicating which consideration items to - * attempt to aggregate when preparing - * executions. - * @param fulfillerConduitKey A bytes32 value indicating what conduit, - * if any, to source the fulfiller's token - * approvals from. The zero hash signifies - * that no conduit should be used, with - * direct approvals set on this contract. - * @param recipient The intended recipient for all received - * items, with `address(0)` indicating that - * the caller should receive the items. - * @param maximumFulfilled The maximum number of orders to fulfill. - * - * @return availableOrders An array of booleans indicating if each order - * with an index corresponding to the index of the - * returned boolean was fulfillable or not. - * @return executions An array of elements indicating the sequence of - * transfers performed as part of matching the given - * orders. Note that unspent offer item amounts or - * native tokens will not be reflected as part of - * this array. - */ - function fulfillAvailableAdvancedOrders( - AdvancedOrder[] calldata advancedOrders, - CriteriaResolver[] calldata criteriaResolvers, - FulfillmentComponent[][] calldata offerFulfillments, - FulfillmentComponent[][] calldata considerationFulfillments, - bytes32 fulfillerConduitKey, - address recipient, - uint256 maximumFulfilled - ) - external - payable - returns (bool[] memory availableOrders, Execution[] memory executions); - /** * @notice Match an arbitrary number of orders, each with an arbitrary * number of items for offer and consideration along with a set of @@ -285,56 +150,6 @@ interface ConsiderationInterface { Fulfillment[] calldata fulfillments ) external payable returns (Execution[] memory executions); - /** - * @notice Match an arbitrary number of full or partial orders, each with an - * arbitrary number of items for offer and consideration, supplying - * criteria resolvers containing specific token identifiers and - * associated proofs as well as fulfillments allocating offer - * components to consideration components. Any unspent offer item - * amounts will be transferred to the designated recipient (with the - * null address signifying to use the caller) and any unspent native - * tokens will be returned to the caller. - * - * @param orders The advanced orders to match. Note that both the - * offerer and fulfiller on each order must first - * approve this contract (or a preferred conduit if - * indicated by the order) to transfer any relevant - * tokens on their behalf and each consideration - * recipient must implement `onERC1155Received` in - * order to receive ERC1155 tokens. Also note that - * the offer and consideration components for each - * order must have no remainder after multiplying - * the respective amount with the supplied fraction - * in order for the group of partial fills to be - * considered valid. - * @param criteriaResolvers An array where each element contains a reference - * to a specific order as well as that order's - * offer or consideration, a token identifier, and - * a proof that the supplied token identifier is - * contained in the order's merkle root. Note that - * an empty root indicates that any (transferable) - * token identifier is valid and that no associated - * proof needs to be supplied. - * @param fulfillments An array of elements allocating offer components - * to consideration components. Note that each - * consideration component must be fully met in - * order for the match operation to be valid. - * @param recipient The intended recipient for all unspent offer - * item amounts, or the caller if the null address - * is supplied. - * - * @return executions An array of elements indicating the sequence of - * transfers performed as part of matching the given - * orders. Note that unspent offer item amounts or native - * tokens will not be reflected as part of this array. - */ - function matchAdvancedOrders( - AdvancedOrder[] calldata orders, - CriteriaResolver[] calldata criteriaResolvers, - Fulfillment[] calldata fulfillments, - address recipient - ) external payable returns (Execution[] memory executions); - /** * @notice Cancel an arbitrary number of orders. Note that only the offerer * or the zone of a given order may cancel it. Callers should ensure From ce8870ec14b5e6e6f8f53a260fe006e39a2d407f Mon Sep 17 00:00:00 2001 From: moshui <sme_moshui@outlook.com> Date: Thu, 24 Aug 2023 11:02:32 +0800 Subject: [PATCH 02/10] remove useless interface --- src/interfaces/ConsiderationInterface.sol | 47 ----------------------- 1 file changed, 47 deletions(-) diff --git a/src/interfaces/ConsiderationInterface.sol b/src/interfaces/ConsiderationInterface.sol index a126501..c956afa 100644 --- a/src/interfaces/ConsiderationInterface.sol +++ b/src/interfaces/ConsiderationInterface.sol @@ -71,53 +71,6 @@ interface ConsiderationInterface { bytes32 fulfillerConduitKey ) external payable returns (bool fulfilled); - /** - * @notice Fill an order, fully or partially, with an arbitrary number of - * items for offer and consideration alongside criteria resolvers - * containing specific token identifiers and associated proofs. - * - * @param advancedOrder The order to fulfill along with the fraction - * of the order to attempt to fill. Note that - * both the offerer and the fulfiller must first - * approve this contract (or their preferred - * conduit if indicated by the order) to transfer - * any relevant tokens on their behalf and that - * contracts must implement `onERC1155Received` - * to receive ERC1155 tokens as consideration. - * Also note that all offer and consideration - * components must have no remainder after - * multiplication of the respective amount with - * the supplied fraction for the partial fill to - * be considered valid. - * @param criteriaResolvers An array where each element contains a - * reference to a specific offer or - * consideration, a token identifier, and a proof - * that the supplied token identifier is - * contained in the merkle root held by the item - * in question's criteria element. Note that an - * empty criteria indicates that any - * (transferable) token identifier on the token - * in question is valid and that no associated - * proof needs to be supplied. - * @param fulfillerConduitKey A bytes32 value indicating what conduit, if - * any, to source the fulfiller's token approvals - * from. The zero hash signifies that no conduit - * should be used, with direct approvals set on - * Consideration. - * @param recipient The intended recipient for all received items, - * with `address(0)` indicating that the caller - * should receive the items. - * - * @return fulfilled A boolean indicating whether the order has been - * successfully fulfilled. - */ - function fulfillAdvancedOrder( - AdvancedOrder calldata advancedOrder, - CriteriaResolver[] calldata criteriaResolvers, - bytes32 fulfillerConduitKey, - address recipient - ) external payable returns (bool fulfilled); - /** * @notice Match an arbitrary number of orders, each with an arbitrary * number of items for offer and consideration along with a set of From 1683726185a57ef79c14a182a81ec856aa9b8df4 Mon Sep 17 00:00:00 2001 From: moshui <sme_moshui@outlook.com> Date: Thu, 24 Aug 2023 11:21:28 +0800 Subject: [PATCH 03/10] remove fulfill --- src/interfaces/ConsiderationInterface.sol | 95 ----------------------- 1 file changed, 95 deletions(-) diff --git a/src/interfaces/ConsiderationInterface.sol b/src/interfaces/ConsiderationInterface.sol index c956afa..e7164e1 100644 --- a/src/interfaces/ConsiderationInterface.sol +++ b/src/interfaces/ConsiderationInterface.sol @@ -25,79 +25,6 @@ import { * Consideration. */ interface ConsiderationInterface { - /** - * @notice Fulfill an order offering an ERC721 token by supplying Ether (or - * the native token for the given chain) as consideration for the - * order. An arbitrary number of "additional recipients" may also be - * supplied which will each receive native tokens from the fulfiller - * as consideration. - * - * @param parameters Additional information on the fulfilled order. Note - * that the offerer must first approve this contract (or - * their preferred conduit if indicated by the order) for - * their offered ERC721 token to be transferred. - * - * @return fulfilled A boolean indicating whether the order has been - * successfully fulfilled. - */ - function fulfillBasicOrder( - BasicOrderParameters calldata parameters - ) external payable returns (bool fulfilled); - - /** - * @notice Fulfill an order with an arbitrary number of items for offer and - * consideration. Note that this function does not support - * criteria-based orders or partial filling of orders (though - * filling the remainder of a partially-filled order is supported). - * - * @param order The order to fulfill. Note that both the - * offerer and the fulfiller must first approve - * this contract (or the corresponding conduit if - * indicated) to transfer any relevant tokens on - * their behalf and that contracts must implement - * `onERC1155Received` to receive ERC1155 tokens - * as consideration. - * @param fulfillerConduitKey A bytes32 value indicating what conduit, if - * any, to source the fulfiller's token approvals - * from. The zero hash signifies that no conduit - * should be used, with direct approvals set on - * Consideration. - * - * @return fulfilled A boolean indicating whether the order has been - * successfully fulfilled. - */ - function fulfillOrder( - Order calldata order, - bytes32 fulfillerConduitKey - ) external payable returns (bool fulfilled); - - /** - * @notice Match an arbitrary number of orders, each with an arbitrary - * number of items for offer and consideration along with a set of - * fulfillments allocating offer components to consideration - * components. Note that this function does not support - * criteria-based or partial filling of orders (though filling the - * remainder of a partially-filled order is supported). Any unspent - * offer item amounts or native tokens will be transferred to the - * caller. - * - * @param orders The orders to match. Note that both the offerer and - * fulfiller on each order must first approve this - * contract (or their conduit if indicated by the order) - * to transfer any relevant tokens on their behalf and - * each consideration recipient must implement - * `onERC1155Received` to enable ERC1155 token receipt. - * @param fulfillments An array of elements allocating offer components to - * consideration components. Note that each - * consideration component must be fully met for the - * match operation to be valid. - * - * @return executions An array of elements indicating the sequence of - * transfers performed as part of matching the given - * orders. Note that unspent offer item amounts or - * native tokens will not be reflected as part of this - * array. - */ function matchOrders( Order[] calldata orders, Fulfillment[] calldata fulfillments @@ -146,28 +73,6 @@ interface ConsiderationInterface { */ function incrementCounter() external returns (uint256 newCounter); - /** - * @notice Fulfill an order offering an ERC721 token by supplying Ether (or - * the native token for the given chain) as consideration for the - * order. An arbitrary number of "additional recipients" may also be - * supplied which will each receive native tokens from the fulfiller - * as consideration. Note that this function costs less gas than - * `fulfillBasicOrder` due to the zero bytes in the function - * selector (0x00000000) which also results in earlier function - * dispatch. - * - * @param parameters Additional information on the fulfilled order. Note - * that the offerer must first approve this contract (or - * their preferred conduit if indicated by the order) for - * their offered ERC721 token to be transferred. - * - * @return fulfilled A boolean indicating whether the order has been - * successfully fulfilled. - */ - function fulfillBasicOrder_efficient_6GL6yc( - BasicOrderParameters calldata parameters - ) external payable returns (bool fulfilled); - /** * @notice Retrieve the order hash for a given order. * From 5247b0dc11538f82583b8c9e606af61719da7409 Mon Sep 17 00:00:00 2001 From: moshui <sme_moshui@outlook.com> Date: Mon, 28 Aug 2023 16:54:34 +0800 Subject: [PATCH 04/10] change interface --- src/interfaces/ConsiderationInterface.sol | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/interfaces/ConsiderationInterface.sol b/src/interfaces/ConsiderationInterface.sol index e7164e1..58accad 100644 --- a/src/interfaces/ConsiderationInterface.sol +++ b/src/interfaces/ConsiderationInterface.sol @@ -27,7 +27,9 @@ import { interface ConsiderationInterface { function matchOrders( Order[] calldata orders, - Fulfillment[] calldata fulfillments + Fulfillment[] calldata fulfillments, + uint256 limit, + bytes calldata _limitSig ) external payable returns (Execution[] memory executions); /** From e1ebd6fe9efcff33b5f63b32da55a8769034bc57 Mon Sep 17 00:00:00 2001 From: moshui <sme_moshui@outlook.com> Date: Wed, 6 Sep 2023 13:56:47 +0800 Subject: [PATCH 05/10] change interface --- src/interfaces/ConsiderationInterface.sol | 24 +++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/src/interfaces/ConsiderationInterface.sol b/src/interfaces/ConsiderationInterface.sol index 58accad..b13058d 100644 --- a/src/interfaces/ConsiderationInterface.sol +++ b/src/interfaces/ConsiderationInterface.sol @@ -25,12 +25,28 @@ import { * Consideration. */ interface ConsiderationInterface { - function matchOrders( + function matchOrdersWithRandom( + /** + * @custom:name orders + */ Order[] calldata orders, + uint256 requestId, + uint256 numerator, + uint256 denominator + ) external payable returns (Execution[] memory /* executions */); + + function prepare( + /** + * @custom:name orders + */ + Order[] calldata orders, + /** + * @custom:name fulfillments + */ Fulfillment[] calldata fulfillments, - uint256 limit, - bytes calldata _limitSig - ) external payable returns (Execution[] memory executions); + uint256 premium, + bytes calldata _premiumSig + ) external payable returns (bytes32[] memory /* orderHashes */ ) { /** * @notice Cancel an arbitrary number of orders. Note that only the offerer From cf972ad6f3e567f13deb15ce10d2b85a3439c268 Mon Sep 17 00:00:00 2001 From: moshui <sme_moshui@outlook.com> Date: Wed, 6 Sep 2023 13:58:03 +0800 Subject: [PATCH 06/10] fix --- src/interfaces/ConsiderationInterface.sol | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/interfaces/ConsiderationInterface.sol b/src/interfaces/ConsiderationInterface.sol index b13058d..a4d9c1b 100644 --- a/src/interfaces/ConsiderationInterface.sol +++ b/src/interfaces/ConsiderationInterface.sol @@ -46,7 +46,7 @@ interface ConsiderationInterface { Fulfillment[] calldata fulfillments, uint256 premium, bytes calldata _premiumSig - ) external payable returns (bytes32[] memory /* orderHashes */ ) { + ) external payable returns (bytes32[] memory /* orderHashes */ ); /** * @notice Cancel an arbitrary number of orders. Note that only the offerer From f7f77b63f66c16e420b8d145ab07cc1124bb2589 Mon Sep 17 00:00:00 2001 From: moshui <sme_moshui@outlook.com> Date: Fri, 15 Sep 2023 14:23:14 +0800 Subject: [PATCH 07/10] add extra types --- src/lib/ConsiderationStructs.sol | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/lib/ConsiderationStructs.sol b/src/lib/ConsiderationStructs.sol index 04cd4aa..7758ef1 100644 --- a/src/lib/ConsiderationStructs.sol +++ b/src/lib/ConsiderationStructs.sol @@ -275,6 +275,12 @@ struct Schema { bytes metadata; } + +struct OrderProbility { + bytes32 orderHash; + uint256 numerator; + uint256 denominator; +} using StructPointers for OrderComponents global; using StructPointers for OfferItem global; using StructPointers for ConsiderationItem global; From 5d8eae7c596db24511c14c677462dc8f722f6d23 Mon Sep 17 00:00:00 2001 From: moshui <sme_moshui@outlook.com> Date: Fri, 15 Sep 2023 14:24:20 +0800 Subject: [PATCH 08/10] change interface --- src/interfaces/ConsiderationInterface.sol | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/src/interfaces/ConsiderationInterface.sol b/src/interfaces/ConsiderationInterface.sol index a4d9c1b..365dbaf 100644 --- a/src/interfaces/ConsiderationInterface.sol +++ b/src/interfaces/ConsiderationInterface.sol @@ -9,7 +9,8 @@ import { Fulfillment, FulfillmentComponent, Order, - OrderComponents + OrderComponents, + OrderProbility } from "../lib/ConsiderationStructs.sol"; /** @@ -29,10 +30,13 @@ interface ConsiderationInterface { /** * @custom:name orders */ - Order[] calldata orders, + Order[] calldata, + /** + * @custom:name fulfillments + */ + Fulfillment[] calldata, uint256 requestId, - uint256 numerator, - uint256 denominator + OrderProbility[] calldata orderProbility ) external payable returns (Execution[] memory /* executions */); function prepare( @@ -40,12 +44,9 @@ interface ConsiderationInterface { * @custom:name orders */ Order[] calldata orders, - /** - * @custom:name fulfillments - */ - Fulfillment[] calldata fulfillments, - uint256 premium, - bytes calldata _premiumSig + uint256[] calldata premiumOrdersIndex, + address[] calldata recipients, + uint32 numWords ) external payable returns (bytes32[] memory /* orderHashes */ ); /** From 2ade3918002606bb1e3db01707bb6bc44743e02f Mon Sep 17 00:00:00 2001 From: moshui <sme_moshui@outlook.com> Date: Mon, 18 Sep 2023 13:57:12 +0800 Subject: [PATCH 09/10] fix --- src/interfaces/ConsiderationInterface.sol | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/interfaces/ConsiderationInterface.sol b/src/interfaces/ConsiderationInterface.sol index 365dbaf..2b267fc 100644 --- a/src/interfaces/ConsiderationInterface.sol +++ b/src/interfaces/ConsiderationInterface.sol @@ -47,7 +47,7 @@ interface ConsiderationInterface { uint256[] calldata premiumOrdersIndex, address[] calldata recipients, uint32 numWords - ) external payable returns (bytes32[] memory /* orderHashes */ ); + ) external payable returns (uint256); /** * @notice Cancel an arbitrary number of orders. Note that only the offerer From dec05daabe6c9a22889543ec51f7c369cfde8f6c Mon Sep 17 00:00:00 2001 From: moshui <sme_moshui@outlook.com> Date: Mon, 25 Sep 2023 14:00:36 +0800 Subject: [PATCH 10/10] improve to advanced orders add match status --- src/interfaces/ConsiderationInterface.sol | 4 ++-- src/lib/ConsiderationStructs.sol | 6 ++++++ 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/src/interfaces/ConsiderationInterface.sol b/src/interfaces/ConsiderationInterface.sol index 2b267fc..99b8d31 100644 --- a/src/interfaces/ConsiderationInterface.sol +++ b/src/interfaces/ConsiderationInterface.sol @@ -30,7 +30,7 @@ interface ConsiderationInterface { /** * @custom:name orders */ - Order[] calldata, + AdvancedOrder[] calldata, /** * @custom:name fulfillments */ @@ -43,7 +43,7 @@ interface ConsiderationInterface { /** * @custom:name orders */ - Order[] calldata orders, + AdvancedOrder[] calldata orders, uint256[] calldata premiumOrdersIndex, address[] calldata recipients, uint32 numWords diff --git a/src/lib/ConsiderationStructs.sol b/src/lib/ConsiderationStructs.sol index 7758ef1..d812332 100644 --- a/src/lib/ConsiderationStructs.sol +++ b/src/lib/ConsiderationStructs.sol @@ -281,6 +281,12 @@ struct OrderProbility { uint256 numerator; uint256 denominator; } + +struct LastMatchStatus { + uint120 numerator; + uint120 denominator; +} + using StructPointers for OrderComponents global; using StructPointers for OfferItem global; using StructPointers for ConsiderationItem global;