From 83aa40cdbbfc4e7c44e0090c2c383e77f4a3adc7 Mon Sep 17 00:00:00 2001 From: 0age <0age@protonmail.com> Date: Wed, 6 Mar 2024 16:50:03 -0500 Subject: [PATCH 1/4] update seaport-types & seaport-core --- lib/seaport-core | 2 +- lib/seaport-types | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/seaport-core b/lib/seaport-core index 275c85c..81232cf 160000 --- a/lib/seaport-core +++ b/lib/seaport-core @@ -1 +1 @@ -Subproject commit 275c85ca8c6f3c9027464d99c634290c10cf7b58 +Subproject commit 81232cf3a3dc977ead1911d167a6756c197ac8fd diff --git a/lib/seaport-types b/lib/seaport-types index 0bd56c0..d72955b 160000 --- a/lib/seaport-types +++ b/lib/seaport-types @@ -1 +1 @@ -Subproject commit 0bd56c08d485ee5b3d5a20b0482a35a8ada60256 +Subproject commit d72955b25b6cf324bbf85ed59aca316f5329eb61 From 8605ac28ddd1de97a046f2c411515c838842a3ce Mon Sep 17 00:00:00 2001 From: 0age <0age@protonmail.com> Date: Wed, 6 Mar 2024 17:56:59 -0500 Subject: [PATCH 2/4] update foundry.toml --- foundry.toml | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/foundry.toml b/foundry.toml index e059bf8..4455d08 100644 --- a/foundry.toml +++ b/foundry.toml @@ -1,11 +1,16 @@ [profile.default] +solc = "0.8.24" +evm_version = "cancun" src = "src" out = "out" libs = ["lib", "node_modules"] remappings = [ - 'seaport-types/=lib/seaport-types/', - 'seaport-core/=lib/seaport-core/', - 'solady/=lib/solady/', + "seaport-types/=lib/seaport-types/", + "seaport-core/=lib/seaport-core/", + "solady/=lib/solady/", ] -# See more config options https://github.com/foundry-rs/foundry/tree/master/config +[fmt] +line_length = 80 +tab_width = 4 +bracket_spacing = true From c3bfe7ef97cf9f7aed4b021c3303c2c0d874ed06 Mon Sep 17 00:00:00 2001 From: 0age <0age@protonmail.com> Date: Wed, 6 Mar 2024 17:57:48 -0500 Subject: [PATCH 3/4] forge fmt --- src/ConduitControllerInterface.sol | 3 +- src/ConduitInterface.sol | 3 +- src/ContractOffererInterface.sol | 3 +- src/SeaportInterface.sol | 3 +- src/SeaportSol.sol | 28 +- src/Solarray.sol | 1034 ++++++++-------- src/SpaceEnums.sol | 10 +- src/StructSpace.sol | 4 +- src/ZoneInterface.sol | 2 +- src/executions/ExecutionHelper.sol | 355 +++--- src/executions/FulfillmentComponentSet.sol | 46 +- .../FulfillmentComponentSortLib.sol | 8 +- src/executions/GenericEnumerableMapping.sol | 46 +- .../available/FulfillAvailableHelper.sol | 150 ++- .../available/FulfillAvailableLayout.sol | 56 +- src/fulfillments/lib/Constants.sol | 20 +- src/fulfillments/lib/FulfillmentLib.sol | 927 +++++++------- src/fulfillments/lib/MatchArrays.sol | 1063 ++++++++++------- src/fulfillments/lib/Structs.sol | 43 +- .../match/MatchFulfillmentHelper.sol | 109 +- .../match/MatchFulfillmentLayout.sol | 41 +- .../match/MatchFulfillmentLib.sol | 87 +- src/helm.sol | 507 ++++++-- src/lib/AdditionalRecipientLib.sol | 110 +- src/lib/AdvancedOrderLib.sol | 314 +++-- src/lib/ArrayLib.sol | 15 +- src/lib/BasicOrderParametersLib.sol | 244 ++-- src/lib/ConsiderationItemLib.sol | 133 ++- src/lib/CriteriaResolverLib.sol | 138 +-- src/lib/ExecutionLib.sol | 120 +- src/lib/FulfillmentComponentLib.sol | 95 +- src/lib/FulfillmentLib.sol | 82 +- src/lib/OfferItemLib.sol | 193 +-- src/lib/OrderComponentsLib.sol | 190 +-- src/lib/OrderLib.sol | 149 ++- src/lib/OrderParametersLib.sol | 279 +++-- src/lib/ReceivedItemLib.sol | 179 +-- src/lib/SeaportArrays.sol | 168 +-- src/lib/SeaportEnumsLib.sol | 10 +- src/lib/SpentItemLib.sol | 138 ++- src/lib/StructCopier.sol | 75 +- src/lib/ZoneParametersLib.sol | 118 +- src/lib/fulfillment/AmountDeriverHelper.sol | 231 ++-- src/lib/types/MatchComponentType.sol | 99 +- 44 files changed, 4219 insertions(+), 3409 deletions(-) diff --git a/src/ConduitControllerInterface.sol b/src/ConduitControllerInterface.sol index 1b0a6c4..56aded3 100644 --- a/src/ConduitControllerInterface.sol +++ b/src/ConduitControllerInterface.sol @@ -1,4 +1,5 @@ // SPDX-License-Identifier: MIT pragma solidity ^0.8.17; -import {ConduitControllerInterface} from "seaport-types/src/interfaces/ConduitControllerInterface.sol"; +import { ConduitControllerInterface } from + "seaport-types/src/interfaces/ConduitControllerInterface.sol"; diff --git a/src/ConduitInterface.sol b/src/ConduitInterface.sol index e6acc4c..b1258d3 100644 --- a/src/ConduitInterface.sol +++ b/src/ConduitInterface.sol @@ -1,4 +1,5 @@ // SPDX-License-Identifier: MIT pragma solidity ^0.8.17; -import {ConduitInterface} from "seaport-types/src/interfaces/ConduitInterface.sol"; +import { ConduitInterface } from + "seaport-types/src/interfaces/ConduitInterface.sol"; diff --git a/src/ContractOffererInterface.sol b/src/ContractOffererInterface.sol index 1c03145..c7240a2 100644 --- a/src/ContractOffererInterface.sol +++ b/src/ContractOffererInterface.sol @@ -1,4 +1,5 @@ // SPDX-License-Identifier: MIT pragma solidity ^0.8.17; -import {ContractOffererInterface} from "seaport-types/src/interfaces/ContractOffererInterface.sol"; +import { ContractOffererInterface } from + "seaport-types/src/interfaces/ContractOffererInterface.sol"; diff --git a/src/SeaportInterface.sol b/src/SeaportInterface.sol index 6f4c9aa..738a514 100644 --- a/src/SeaportInterface.sol +++ b/src/SeaportInterface.sol @@ -1,4 +1,5 @@ // SPDX-License-Identifier: MIT pragma solidity ^0.8.17; -import {ConsiderationInterface as SeaportInterface} from "seaport-types/src/interfaces/ConsiderationInterface.sol"; +import { ConsiderationInterface as SeaportInterface } from + "seaport-types/src/interfaces/ConsiderationInterface.sol"; diff --git a/src/SeaportSol.sol b/src/SeaportSol.sol index befac5f..39a5b72 100644 --- a/src/SeaportSol.sol +++ b/src/SeaportSol.sol @@ -6,14 +6,20 @@ import "./SeaportEnums.sol"; import "./lib/SeaportStructLib.sol"; import "./lib/SeaportEnumsLib.sol"; import "./fulfillments/lib/Structs.sol"; -import {SeaportArrays} from "./lib/SeaportArrays.sol"; -import {SeaportInterface} from "./SeaportInterface.sol"; -import {ConsiderationInterface} from "seaport-types/src/interfaces/ConsiderationInterface.sol"; -import {ConduitInterface} from "./ConduitInterface.sol"; -import {ConduitControllerInterface} from "./ConduitControllerInterface.sol"; -import {ZoneInterface} from "./ZoneInterface.sol"; -import {ContractOffererInterface} from "./ContractOffererInterface.sol"; -import {Solarray} from "./Solarray.sol"; -import {FulfillAvailableHelper} from "./fulfillments/available/FulfillAvailableHelper.sol"; -import {MatchFulfillmentHelper} from "./fulfillments/match/MatchFulfillmentHelper.sol"; -import {MatchComponent, MatchComponentType} from "./lib/types/MatchComponentType.sol"; +import { SeaportArrays } from "./lib/SeaportArrays.sol"; +import { SeaportInterface } from "./SeaportInterface.sol"; +import { ConsiderationInterface } from + "seaport-types/src/interfaces/ConsiderationInterface.sol"; +import { ConduitInterface } from "./ConduitInterface.sol"; +import { ConduitControllerInterface } from "./ConduitControllerInterface.sol"; +import { ZoneInterface } from "./ZoneInterface.sol"; +import { ContractOffererInterface } from "./ContractOffererInterface.sol"; +import { Solarray } from "./Solarray.sol"; +import { FulfillAvailableHelper } from + "./fulfillments/available/FulfillAvailableHelper.sol"; +import { MatchFulfillmentHelper } from + "./fulfillments/match/MatchFulfillmentHelper.sol"; +import { + MatchComponent, + MatchComponentType +} from "./lib/types/MatchComponentType.sol"; diff --git a/src/Solarray.sol b/src/Solarray.sol index 827bbf4..d2db7a9 100644 --- a/src/Solarray.sol +++ b/src/Solarray.sol @@ -15,11 +15,11 @@ library Solarray { return arr; } - function uint8s( - uint8 a, - uint8 b, - uint8 c - ) internal pure returns (uint8[] memory) { + function uint8s(uint8 a, uint8 b, uint8 c) + internal + pure + returns (uint8[] memory) + { uint8[] memory arr = new uint8[](3); arr[0] = a; arr[1] = b; @@ -27,12 +27,11 @@ library Solarray { return arr; } - function uint8s( - uint8 a, - uint8 b, - uint8 c, - uint8 d - ) internal pure returns (uint8[] memory) { + function uint8s(uint8 a, uint8 b, uint8 c, uint8 d) + internal + pure + returns (uint8[] memory) + { uint8[] memory arr = new uint8[](4); arr[0] = a; arr[1] = b; @@ -41,13 +40,11 @@ library Solarray { return arr; } - function uint8s( - uint8 a, - uint8 b, - uint8 c, - uint8 d, - uint8 e - ) internal pure returns (uint8[] memory) { + function uint8s(uint8 a, uint8 b, uint8 c, uint8 d, uint8 e) + internal + pure + returns (uint8[] memory) + { uint8[] memory arr = new uint8[](5); arr[0] = a; arr[1] = b; @@ -57,14 +54,11 @@ library Solarray { return arr; } - function uint8s( - uint8 a, - uint8 b, - uint8 c, - uint8 d, - uint8 e, - uint8 f - ) internal pure returns (uint8[] memory) { + function uint8s(uint8 a, uint8 b, uint8 c, uint8 d, uint8 e, uint8 f) + internal + pure + returns (uint8[] memory) + { uint8[] memory arr = new uint8[](6); arr[0] = a; arr[1] = b; @@ -101,21 +95,22 @@ library Solarray { return arr; } - function uint16s( - uint16 a, - uint16 b - ) internal pure returns (uint16[] memory) { + function uint16s(uint16 a, uint16 b) + internal + pure + returns (uint16[] memory) + { uint16[] memory arr = new uint16[](2); arr[0] = a; arr[1] = b; return arr; } - function uint16s( - uint16 a, - uint16 b, - uint16 c - ) internal pure returns (uint16[] memory) { + function uint16s(uint16 a, uint16 b, uint16 c) + internal + pure + returns (uint16[] memory) + { uint16[] memory arr = new uint16[](3); arr[0] = a; arr[1] = b; @@ -123,12 +118,11 @@ library Solarray { return arr; } - function uint16s( - uint16 a, - uint16 b, - uint16 c, - uint16 d - ) internal pure returns (uint16[] memory) { + function uint16s(uint16 a, uint16 b, uint16 c, uint16 d) + internal + pure + returns (uint16[] memory) + { uint16[] memory arr = new uint16[](4); arr[0] = a; arr[1] = b; @@ -137,13 +131,11 @@ library Solarray { return arr; } - function uint16s( - uint16 a, - uint16 b, - uint16 c, - uint16 d, - uint16 e - ) internal pure returns (uint16[] memory) { + function uint16s(uint16 a, uint16 b, uint16 c, uint16 d, uint16 e) + internal + pure + returns (uint16[] memory) + { uint16[] memory arr = new uint16[](5); arr[0] = a; arr[1] = b; @@ -153,14 +145,11 @@ library Solarray { return arr; } - function uint16s( - uint16 a, - uint16 b, - uint16 c, - uint16 d, - uint16 e, - uint16 f - ) internal pure returns (uint16[] memory) { + function uint16s(uint16 a, uint16 b, uint16 c, uint16 d, uint16 e, uint16 f) + internal + pure + returns (uint16[] memory) + { uint16[] memory arr = new uint16[](6); arr[0] = a; arr[1] = b; @@ -197,21 +186,22 @@ library Solarray { return arr; } - function uint32s( - uint32 a, - uint32 b - ) internal pure returns (uint32[] memory) { + function uint32s(uint32 a, uint32 b) + internal + pure + returns (uint32[] memory) + { uint32[] memory arr = new uint32[](2); arr[0] = a; arr[1] = b; return arr; } - function uint32s( - uint32 a, - uint32 b, - uint32 c - ) internal pure returns (uint32[] memory) { + function uint32s(uint32 a, uint32 b, uint32 c) + internal + pure + returns (uint32[] memory) + { uint32[] memory arr = new uint32[](3); arr[0] = a; arr[1] = b; @@ -219,12 +209,11 @@ library Solarray { return arr; } - function uint32s( - uint32 a, - uint32 b, - uint32 c, - uint32 d - ) internal pure returns (uint32[] memory) { + function uint32s(uint32 a, uint32 b, uint32 c, uint32 d) + internal + pure + returns (uint32[] memory) + { uint32[] memory arr = new uint32[](4); arr[0] = a; arr[1] = b; @@ -233,13 +222,11 @@ library Solarray { return arr; } - function uint32s( - uint32 a, - uint32 b, - uint32 c, - uint32 d, - uint32 e - ) internal pure returns (uint32[] memory) { + function uint32s(uint32 a, uint32 b, uint32 c, uint32 d, uint32 e) + internal + pure + returns (uint32[] memory) + { uint32[] memory arr = new uint32[](5); arr[0] = a; arr[1] = b; @@ -249,14 +236,11 @@ library Solarray { return arr; } - function uint32s( - uint32 a, - uint32 b, - uint32 c, - uint32 d, - uint32 e, - uint32 f - ) internal pure returns (uint32[] memory) { + function uint32s(uint32 a, uint32 b, uint32 c, uint32 d, uint32 e, uint32 f) + internal + pure + returns (uint32[] memory) + { uint32[] memory arr = new uint32[](6); arr[0] = a; arr[1] = b; @@ -293,21 +277,22 @@ library Solarray { return arr; } - function uint40s( - uint40 a, - uint40 b - ) internal pure returns (uint40[] memory) { + function uint40s(uint40 a, uint40 b) + internal + pure + returns (uint40[] memory) + { uint40[] memory arr = new uint40[](2); arr[0] = a; arr[1] = b; return arr; } - function uint40s( - uint40 a, - uint40 b, - uint40 c - ) internal pure returns (uint40[] memory) { + function uint40s(uint40 a, uint40 b, uint40 c) + internal + pure + returns (uint40[] memory) + { uint40[] memory arr = new uint40[](3); arr[0] = a; arr[1] = b; @@ -315,12 +300,11 @@ library Solarray { return arr; } - function uint40s( - uint40 a, - uint40 b, - uint40 c, - uint40 d - ) internal pure returns (uint40[] memory) { + function uint40s(uint40 a, uint40 b, uint40 c, uint40 d) + internal + pure + returns (uint40[] memory) + { uint40[] memory arr = new uint40[](4); arr[0] = a; arr[1] = b; @@ -329,13 +313,11 @@ library Solarray { return arr; } - function uint40s( - uint40 a, - uint40 b, - uint40 c, - uint40 d, - uint40 e - ) internal pure returns (uint40[] memory) { + function uint40s(uint40 a, uint40 b, uint40 c, uint40 d, uint40 e) + internal + pure + returns (uint40[] memory) + { uint40[] memory arr = new uint40[](5); arr[0] = a; arr[1] = b; @@ -345,14 +327,11 @@ library Solarray { return arr; } - function uint40s( - uint40 a, - uint40 b, - uint40 c, - uint40 d, - uint40 e, - uint40 f - ) internal pure returns (uint40[] memory) { + function uint40s(uint40 a, uint40 b, uint40 c, uint40 d, uint40 e, uint40 f) + internal + pure + returns (uint40[] memory) + { uint40[] memory arr = new uint40[](6); arr[0] = a; arr[1] = b; @@ -389,21 +368,22 @@ library Solarray { return arr; } - function uint64s( - uint64 a, - uint64 b - ) internal pure returns (uint64[] memory) { + function uint64s(uint64 a, uint64 b) + internal + pure + returns (uint64[] memory) + { uint64[] memory arr = new uint64[](2); arr[0] = a; arr[1] = b; return arr; } - function uint64s( - uint64 a, - uint64 b, - uint64 c - ) internal pure returns (uint64[] memory) { + function uint64s(uint64 a, uint64 b, uint64 c) + internal + pure + returns (uint64[] memory) + { uint64[] memory arr = new uint64[](3); arr[0] = a; arr[1] = b; @@ -411,12 +391,11 @@ library Solarray { return arr; } - function uint64s( - uint64 a, - uint64 b, - uint64 c, - uint64 d - ) internal pure returns (uint64[] memory) { + function uint64s(uint64 a, uint64 b, uint64 c, uint64 d) + internal + pure + returns (uint64[] memory) + { uint64[] memory arr = new uint64[](4); arr[0] = a; arr[1] = b; @@ -425,13 +404,11 @@ library Solarray { return arr; } - function uint64s( - uint64 a, - uint64 b, - uint64 c, - uint64 d, - uint64 e - ) internal pure returns (uint64[] memory) { + function uint64s(uint64 a, uint64 b, uint64 c, uint64 d, uint64 e) + internal + pure + returns (uint64[] memory) + { uint64[] memory arr = new uint64[](5); arr[0] = a; arr[1] = b; @@ -441,14 +418,11 @@ library Solarray { return arr; } - function uint64s( - uint64 a, - uint64 b, - uint64 c, - uint64 d, - uint64 e, - uint64 f - ) internal pure returns (uint64[] memory) { + function uint64s(uint64 a, uint64 b, uint64 c, uint64 d, uint64 e, uint64 f) + internal + pure + returns (uint64[] memory) + { uint64[] memory arr = new uint64[](6); arr[0] = a; arr[1] = b; @@ -485,21 +459,22 @@ library Solarray { return arr; } - function uint128s( - uint128 a, - uint128 b - ) internal pure returns (uint128[] memory) { + function uint128s(uint128 a, uint128 b) + internal + pure + returns (uint128[] memory) + { uint128[] memory arr = new uint128[](2); arr[0] = a; arr[1] = b; return arr; } - function uint128s( - uint128 a, - uint128 b, - uint128 c - ) internal pure returns (uint128[] memory) { + function uint128s(uint128 a, uint128 b, uint128 c) + internal + pure + returns (uint128[] memory) + { uint128[] memory arr = new uint128[](3); arr[0] = a; arr[1] = b; @@ -507,12 +482,11 @@ library Solarray { return arr; } - function uint128s( - uint128 a, - uint128 b, - uint128 c, - uint128 d - ) internal pure returns (uint128[] memory) { + function uint128s(uint128 a, uint128 b, uint128 c, uint128 d) + internal + pure + returns (uint128[] memory) + { uint128[] memory arr = new uint128[](4); arr[0] = a; arr[1] = b; @@ -521,13 +495,11 @@ library Solarray { return arr; } - function uint128s( - uint128 a, - uint128 b, - uint128 c, - uint128 d, - uint128 e - ) internal pure returns (uint128[] memory) { + function uint128s(uint128 a, uint128 b, uint128 c, uint128 d, uint128 e) + internal + pure + returns (uint128[] memory) + { uint128[] memory arr = new uint128[](5); arr[0] = a; arr[1] = b; @@ -581,21 +553,22 @@ library Solarray { return arr; } - function uint256s( - uint256 a, - uint256 b - ) internal pure returns (uint256[] memory) { + function uint256s(uint256 a, uint256 b) + internal + pure + returns (uint256[] memory) + { uint256[] memory arr = new uint256[](2); arr[0] = a; arr[1] = b; return arr; } - function uint256s( - uint256 a, - uint256 b, - uint256 c - ) internal pure returns (uint256[] memory) { + function uint256s(uint256 a, uint256 b, uint256 c) + internal + pure + returns (uint256[] memory) + { uint256[] memory arr = new uint256[](3); arr[0] = a; arr[1] = b; @@ -603,12 +576,11 @@ library Solarray { return arr; } - function uint256s( - uint256 a, - uint256 b, - uint256 c, - uint256 d - ) internal pure returns (uint256[] memory) { + function uint256s(uint256 a, uint256 b, uint256 c, uint256 d) + internal + pure + returns (uint256[] memory) + { uint256[] memory arr = new uint256[](4); arr[0] = a; arr[1] = b; @@ -617,13 +589,11 @@ library Solarray { return arr; } - function uint256s( - uint256 a, - uint256 b, - uint256 c, - uint256 d, - uint256 e - ) internal pure returns (uint256[] memory) { + function uint256s(uint256 a, uint256 b, uint256 c, uint256 d, uint256 e) + internal + pure + returns (uint256[] memory) + { uint256[] memory arr = new uint256[](5); arr[0] = a; arr[1] = b; @@ -684,11 +654,11 @@ library Solarray { return arr; } - function int8s( - int8 a, - int8 b, - int8 c - ) internal pure returns (int8[] memory) { + function int8s(int8 a, int8 b, int8 c) + internal + pure + returns (int8[] memory) + { int8[] memory arr = new int8[](3); arr[0] = a; arr[1] = b; @@ -696,12 +666,11 @@ library Solarray { return arr; } - function int8s( - int8 a, - int8 b, - int8 c, - int8 d - ) internal pure returns (int8[] memory) { + function int8s(int8 a, int8 b, int8 c, int8 d) + internal + pure + returns (int8[] memory) + { int8[] memory arr = new int8[](4); arr[0] = a; arr[1] = b; @@ -710,13 +679,11 @@ library Solarray { return arr; } - function int8s( - int8 a, - int8 b, - int8 c, - int8 d, - int8 e - ) internal pure returns (int8[] memory) { + function int8s(int8 a, int8 b, int8 c, int8 d, int8 e) + internal + pure + returns (int8[] memory) + { int8[] memory arr = new int8[](5); arr[0] = a; arr[1] = b; @@ -726,14 +693,11 @@ library Solarray { return arr; } - function int8s( - int8 a, - int8 b, - int8 c, - int8 d, - int8 e, - int8 f - ) internal pure returns (int8[] memory) { + function int8s(int8 a, int8 b, int8 c, int8 d, int8 e, int8 f) + internal + pure + returns (int8[] memory) + { int8[] memory arr = new int8[](6); arr[0] = a; arr[1] = b; @@ -744,15 +708,11 @@ library Solarray { return arr; } - function int8s( - int8 a, - int8 b, - int8 c, - int8 d, - int8 e, - int8 f, - int8 g - ) internal pure returns (int8[] memory) { + function int8s(int8 a, int8 b, int8 c, int8 d, int8 e, int8 f, int8 g) + internal + pure + returns (int8[] memory) + { int8[] memory arr = new int8[](7); arr[0] = a; arr[1] = b; @@ -777,11 +737,11 @@ library Solarray { return arr; } - function int16s( - int16 a, - int16 b, - int16 c - ) internal pure returns (int16[] memory) { + function int16s(int16 a, int16 b, int16 c) + internal + pure + returns (int16[] memory) + { int16[] memory arr = new int16[](3); arr[0] = a; arr[1] = b; @@ -789,12 +749,11 @@ library Solarray { return arr; } - function int16s( - int16 a, - int16 b, - int16 c, - int16 d - ) internal pure returns (int16[] memory) { + function int16s(int16 a, int16 b, int16 c, int16 d) + internal + pure + returns (int16[] memory) + { int16[] memory arr = new int16[](4); arr[0] = a; arr[1] = b; @@ -803,13 +762,11 @@ library Solarray { return arr; } - function int16s( - int16 a, - int16 b, - int16 c, - int16 d, - int16 e - ) internal pure returns (int16[] memory) { + function int16s(int16 a, int16 b, int16 c, int16 d, int16 e) + internal + pure + returns (int16[] memory) + { int16[] memory arr = new int16[](5); arr[0] = a; arr[1] = b; @@ -819,14 +776,11 @@ library Solarray { return arr; } - function int16s( - int16 a, - int16 b, - int16 c, - int16 d, - int16 e, - int16 f - ) internal pure returns (int16[] memory) { + function int16s(int16 a, int16 b, int16 c, int16 d, int16 e, int16 f) + internal + pure + returns (int16[] memory) + { int16[] memory arr = new int16[](6); arr[0] = a; arr[1] = b; @@ -870,11 +824,11 @@ library Solarray { return arr; } - function int32s( - int32 a, - int32 b, - int32 c - ) internal pure returns (int32[] memory) { + function int32s(int32 a, int32 b, int32 c) + internal + pure + returns (int32[] memory) + { int32[] memory arr = new int32[](3); arr[0] = a; arr[1] = b; @@ -882,12 +836,11 @@ library Solarray { return arr; } - function int32s( - int32 a, - int32 b, - int32 c, - int32 d - ) internal pure returns (int32[] memory) { + function int32s(int32 a, int32 b, int32 c, int32 d) + internal + pure + returns (int32[] memory) + { int32[] memory arr = new int32[](4); arr[0] = a; arr[1] = b; @@ -896,13 +849,11 @@ library Solarray { return arr; } - function int32s( - int32 a, - int32 b, - int32 c, - int32 d, - int32 e - ) internal pure returns (int32[] memory) { + function int32s(int32 a, int32 b, int32 c, int32 d, int32 e) + internal + pure + returns (int32[] memory) + { int32[] memory arr = new int32[](5); arr[0] = a; arr[1] = b; @@ -912,14 +863,11 @@ library Solarray { return arr; } - function int32s( - int32 a, - int32 b, - int32 c, - int32 d, - int32 e, - int32 f - ) internal pure returns (int32[] memory) { + function int32s(int32 a, int32 b, int32 c, int32 d, int32 e, int32 f) + internal + pure + returns (int32[] memory) + { int32[] memory arr = new int32[](6); arr[0] = a; arr[1] = b; @@ -963,11 +911,11 @@ library Solarray { return arr; } - function int64s( - int64 a, - int64 b, - int64 c - ) internal pure returns (int64[] memory) { + function int64s(int64 a, int64 b, int64 c) + internal + pure + returns (int64[] memory) + { int64[] memory arr = new int64[](3); arr[0] = a; arr[1] = b; @@ -975,12 +923,11 @@ library Solarray { return arr; } - function int64s( - int64 a, - int64 b, - int64 c, - int64 d - ) internal pure returns (int64[] memory) { + function int64s(int64 a, int64 b, int64 c, int64 d) + internal + pure + returns (int64[] memory) + { int64[] memory arr = new int64[](4); arr[0] = a; arr[1] = b; @@ -989,13 +936,11 @@ library Solarray { return arr; } - function int64s( - int64 a, - int64 b, - int64 c, - int64 d, - int64 e - ) internal pure returns (int64[] memory) { + function int64s(int64 a, int64 b, int64 c, int64 d, int64 e) + internal + pure + returns (int64[] memory) + { int64[] memory arr = new int64[](5); arr[0] = a; arr[1] = b; @@ -1005,14 +950,11 @@ library Solarray { return arr; } - function int64s( - int64 a, - int64 b, - int64 c, - int64 d, - int64 e, - int64 f - ) internal pure returns (int64[] memory) { + function int64s(int64 a, int64 b, int64 c, int64 d, int64 e, int64 f) + internal + pure + returns (int64[] memory) + { int64[] memory arr = new int64[](6); arr[0] = a; arr[1] = b; @@ -1049,21 +991,22 @@ library Solarray { return arr; } - function int128s( - int128 a, - int128 b - ) internal pure returns (int128[] memory) { + function int128s(int128 a, int128 b) + internal + pure + returns (int128[] memory) + { int128[] memory arr = new int128[](2); arr[0] = a; arr[1] = b; return arr; } - function int128s( - int128 a, - int128 b, - int128 c - ) internal pure returns (int128[] memory) { + function int128s(int128 a, int128 b, int128 c) + internal + pure + returns (int128[] memory) + { int128[] memory arr = new int128[](3); arr[0] = a; arr[1] = b; @@ -1071,12 +1014,11 @@ library Solarray { return arr; } - function int128s( - int128 a, - int128 b, - int128 c, - int128 d - ) internal pure returns (int128[] memory) { + function int128s(int128 a, int128 b, int128 c, int128 d) + internal + pure + returns (int128[] memory) + { int128[] memory arr = new int128[](4); arr[0] = a; arr[1] = b; @@ -1085,13 +1027,11 @@ library Solarray { return arr; } - function int128s( - int128 a, - int128 b, - int128 c, - int128 d, - int128 e - ) internal pure returns (int128[] memory) { + function int128s(int128 a, int128 b, int128 c, int128 d, int128 e) + internal + pure + returns (int128[] memory) + { int128[] memory arr = new int128[](5); arr[0] = a; arr[1] = b; @@ -1101,14 +1041,11 @@ library Solarray { return arr; } - function int128s( - int128 a, - int128 b, - int128 c, - int128 d, - int128 e, - int128 f - ) internal pure returns (int128[] memory) { + function int128s(int128 a, int128 b, int128 c, int128 d, int128 e, int128 f) + internal + pure + returns (int128[] memory) + { int128[] memory arr = new int128[](6); arr[0] = a; arr[1] = b; @@ -1145,21 +1082,22 @@ library Solarray { return arr; } - function int256s( - int256 a, - int256 b - ) internal pure returns (int256[] memory) { + function int256s(int256 a, int256 b) + internal + pure + returns (int256[] memory) + { int256[] memory arr = new int256[](2); arr[0] = a; arr[1] = b; return arr; } - function int256s( - int256 a, - int256 b, - int256 c - ) internal pure returns (int256[] memory) { + function int256s(int256 a, int256 b, int256 c) + internal + pure + returns (int256[] memory) + { int256[] memory arr = new int256[](3); arr[0] = a; arr[1] = b; @@ -1167,12 +1105,11 @@ library Solarray { return arr; } - function int256s( - int256 a, - int256 b, - int256 c, - int256 d - ) internal pure returns (int256[] memory) { + function int256s(int256 a, int256 b, int256 c, int256 d) + internal + pure + returns (int256[] memory) + { int256[] memory arr = new int256[](4); arr[0] = a; arr[1] = b; @@ -1181,13 +1118,11 @@ library Solarray { return arr; } - function int256s( - int256 a, - int256 b, - int256 c, - int256 d, - int256 e - ) internal pure returns (int256[] memory) { + function int256s(int256 a, int256 b, int256 c, int256 d, int256 e) + internal + pure + returns (int256[] memory) + { int256[] memory arr = new int256[](5); arr[0] = a; arr[1] = b; @@ -1197,14 +1132,11 @@ library Solarray { return arr; } - function int256s( - int256 a, - int256 b, - int256 c, - int256 d, - int256 e, - int256 f - ) internal pure returns (int256[] memory) { + function int256s(int256 a, int256 b, int256 c, int256 d, int256 e, int256 f) + internal + pure + returns (int256[] memory) + { int256[] memory arr = new int256[](6); arr[0] = a; arr[1] = b; @@ -1241,21 +1173,22 @@ library Solarray { return arr; } - function bytes1s( - bytes1 a, - bytes1 b - ) internal pure returns (bytes1[] memory) { + function bytes1s(bytes1 a, bytes1 b) + internal + pure + returns (bytes1[] memory) + { bytes1[] memory arr = new bytes1[](2); arr[0] = a; arr[1] = b; return arr; } - function bytes1s( - bytes1 a, - bytes1 b, - bytes1 c - ) internal pure returns (bytes1[] memory) { + function bytes1s(bytes1 a, bytes1 b, bytes1 c) + internal + pure + returns (bytes1[] memory) + { bytes1[] memory arr = new bytes1[](3); arr[0] = a; arr[1] = b; @@ -1263,12 +1196,11 @@ library Solarray { return arr; } - function bytes1s( - bytes1 a, - bytes1 b, - bytes1 c, - bytes1 d - ) internal pure returns (bytes1[] memory) { + function bytes1s(bytes1 a, bytes1 b, bytes1 c, bytes1 d) + internal + pure + returns (bytes1[] memory) + { bytes1[] memory arr = new bytes1[](4); arr[0] = a; arr[1] = b; @@ -1277,13 +1209,11 @@ library Solarray { return arr; } - function bytes1s( - bytes1 a, - bytes1 b, - bytes1 c, - bytes1 d, - bytes1 e - ) internal pure returns (bytes1[] memory) { + function bytes1s(bytes1 a, bytes1 b, bytes1 c, bytes1 d, bytes1 e) + internal + pure + returns (bytes1[] memory) + { bytes1[] memory arr = new bytes1[](5); arr[0] = a; arr[1] = b; @@ -1293,14 +1223,11 @@ library Solarray { return arr; } - function bytes1s( - bytes1 a, - bytes1 b, - bytes1 c, - bytes1 d, - bytes1 e, - bytes1 f - ) internal pure returns (bytes1[] memory) { + function bytes1s(bytes1 a, bytes1 b, bytes1 c, bytes1 d, bytes1 e, bytes1 f) + internal + pure + returns (bytes1[] memory) + { bytes1[] memory arr = new bytes1[](6); arr[0] = a; arr[1] = b; @@ -1337,21 +1264,22 @@ library Solarray { return arr; } - function bytes8s( - bytes8 a, - bytes8 b - ) internal pure returns (bytes8[] memory) { + function bytes8s(bytes8 a, bytes8 b) + internal + pure + returns (bytes8[] memory) + { bytes8[] memory arr = new bytes8[](2); arr[0] = a; arr[1] = b; return arr; } - function bytes8s( - bytes8 a, - bytes8 b, - bytes8 c - ) internal pure returns (bytes8[] memory) { + function bytes8s(bytes8 a, bytes8 b, bytes8 c) + internal + pure + returns (bytes8[] memory) + { bytes8[] memory arr = new bytes8[](3); arr[0] = a; arr[1] = b; @@ -1359,12 +1287,11 @@ library Solarray { return arr; } - function bytes8s( - bytes8 a, - bytes8 b, - bytes8 c, - bytes8 d - ) internal pure returns (bytes8[] memory) { + function bytes8s(bytes8 a, bytes8 b, bytes8 c, bytes8 d) + internal + pure + returns (bytes8[] memory) + { bytes8[] memory arr = new bytes8[](4); arr[0] = a; arr[1] = b; @@ -1373,13 +1300,11 @@ library Solarray { return arr; } - function bytes8s( - bytes8 a, - bytes8 b, - bytes8 c, - bytes8 d, - bytes8 e - ) internal pure returns (bytes8[] memory) { + function bytes8s(bytes8 a, bytes8 b, bytes8 c, bytes8 d, bytes8 e) + internal + pure + returns (bytes8[] memory) + { bytes8[] memory arr = new bytes8[](5); arr[0] = a; arr[1] = b; @@ -1389,14 +1314,11 @@ library Solarray { return arr; } - function bytes8s( - bytes8 a, - bytes8 b, - bytes8 c, - bytes8 d, - bytes8 e, - bytes8 f - ) internal pure returns (bytes8[] memory) { + function bytes8s(bytes8 a, bytes8 b, bytes8 c, bytes8 d, bytes8 e, bytes8 f) + internal + pure + returns (bytes8[] memory) + { bytes8[] memory arr = new bytes8[](6); arr[0] = a; arr[1] = b; @@ -1433,21 +1355,22 @@ library Solarray { return arr; } - function bytes16s( - bytes16 a, - bytes16 b - ) internal pure returns (bytes16[] memory) { + function bytes16s(bytes16 a, bytes16 b) + internal + pure + returns (bytes16[] memory) + { bytes16[] memory arr = new bytes16[](2); arr[0] = a; arr[1] = b; return arr; } - function bytes16s( - bytes16 a, - bytes16 b, - bytes16 c - ) internal pure returns (bytes16[] memory) { + function bytes16s(bytes16 a, bytes16 b, bytes16 c) + internal + pure + returns (bytes16[] memory) + { bytes16[] memory arr = new bytes16[](3); arr[0] = a; arr[1] = b; @@ -1455,12 +1378,11 @@ library Solarray { return arr; } - function bytes16s( - bytes16 a, - bytes16 b, - bytes16 c, - bytes16 d - ) internal pure returns (bytes16[] memory) { + function bytes16s(bytes16 a, bytes16 b, bytes16 c, bytes16 d) + internal + pure + returns (bytes16[] memory) + { bytes16[] memory arr = new bytes16[](4); arr[0] = a; arr[1] = b; @@ -1469,13 +1391,11 @@ library Solarray { return arr; } - function bytes16s( - bytes16 a, - bytes16 b, - bytes16 c, - bytes16 d, - bytes16 e - ) internal pure returns (bytes16[] memory) { + function bytes16s(bytes16 a, bytes16 b, bytes16 c, bytes16 d, bytes16 e) + internal + pure + returns (bytes16[] memory) + { bytes16[] memory arr = new bytes16[](5); arr[0] = a; arr[1] = b; @@ -1529,21 +1449,22 @@ library Solarray { return arr; } - function bytes20s( - bytes20 a, - bytes20 b - ) internal pure returns (bytes20[] memory) { + function bytes20s(bytes20 a, bytes20 b) + internal + pure + returns (bytes20[] memory) + { bytes20[] memory arr = new bytes20[](2); arr[0] = a; arr[1] = b; return arr; } - function bytes20s( - bytes20 a, - bytes20 b, - bytes20 c - ) internal pure returns (bytes20[] memory) { + function bytes20s(bytes20 a, bytes20 b, bytes20 c) + internal + pure + returns (bytes20[] memory) + { bytes20[] memory arr = new bytes20[](3); arr[0] = a; arr[1] = b; @@ -1551,12 +1472,11 @@ library Solarray { return arr; } - function bytes20s( - bytes20 a, - bytes20 b, - bytes20 c, - bytes20 d - ) internal pure returns (bytes20[] memory) { + function bytes20s(bytes20 a, bytes20 b, bytes20 c, bytes20 d) + internal + pure + returns (bytes20[] memory) + { bytes20[] memory arr = new bytes20[](4); arr[0] = a; arr[1] = b; @@ -1565,13 +1485,11 @@ library Solarray { return arr; } - function bytes20s( - bytes20 a, - bytes20 b, - bytes20 c, - bytes20 d, - bytes20 e - ) internal pure returns (bytes20[] memory) { + function bytes20s(bytes20 a, bytes20 b, bytes20 c, bytes20 d, bytes20 e) + internal + pure + returns (bytes20[] memory) + { bytes20[] memory arr = new bytes20[](5); arr[0] = a; arr[1] = b; @@ -1625,21 +1543,22 @@ library Solarray { return arr; } - function bytes32s( - bytes32 a, - bytes32 b - ) internal pure returns (bytes32[] memory) { + function bytes32s(bytes32 a, bytes32 b) + internal + pure + returns (bytes32[] memory) + { bytes32[] memory arr = new bytes32[](2); arr[0] = a; arr[1] = b; return arr; } - function bytes32s( - bytes32 a, - bytes32 b, - bytes32 c - ) internal pure returns (bytes32[] memory) { + function bytes32s(bytes32 a, bytes32 b, bytes32 c) + internal + pure + returns (bytes32[] memory) + { bytes32[] memory arr = new bytes32[](3); arr[0] = a; arr[1] = b; @@ -1647,12 +1566,11 @@ library Solarray { return arr; } - function bytes32s( - bytes32 a, - bytes32 b, - bytes32 c, - bytes32 d - ) internal pure returns (bytes32[] memory) { + function bytes32s(bytes32 a, bytes32 b, bytes32 c, bytes32 d) + internal + pure + returns (bytes32[] memory) + { bytes32[] memory arr = new bytes32[](4); arr[0] = a; arr[1] = b; @@ -1661,13 +1579,11 @@ library Solarray { return arr; } - function bytes32s( - bytes32 a, - bytes32 b, - bytes32 c, - bytes32 d, - bytes32 e - ) internal pure returns (bytes32[] memory) { + function bytes32s(bytes32 a, bytes32 b, bytes32 c, bytes32 d, bytes32 e) + internal + pure + returns (bytes32[] memory) + { bytes32[] memory arr = new bytes32[](5); arr[0] = a; arr[1] = b; @@ -1721,21 +1637,22 @@ library Solarray { return arr; } - function bytess( - bytes memory a, - bytes memory b - ) internal pure returns (bytes[] memory) { + function bytess(bytes memory a, bytes memory b) + internal + pure + returns (bytes[] memory) + { bytes[] memory arr = new bytes[](2); arr[0] = a; arr[1] = b; return arr; } - function bytess( - bytes memory a, - bytes memory b, - bytes memory c - ) internal pure returns (bytes[] memory) { + function bytess(bytes memory a, bytes memory b, bytes memory c) + internal + pure + returns (bytes[] memory) + { bytes[] memory arr = new bytes[](3); arr[0] = a; arr[1] = b; @@ -1817,21 +1734,22 @@ library Solarray { return arr; } - function addresses( - address a, - address b - ) internal pure returns (address[] memory) { + function addresses(address a, address b) + internal + pure + returns (address[] memory) + { address[] memory arr = new address[](2); arr[0] = a; arr[1] = b; return arr; } - function addresses( - address a, - address b, - address c - ) internal pure returns (address[] memory) { + function addresses(address a, address b, address c) + internal + pure + returns (address[] memory) + { address[] memory arr = new address[](3); arr[0] = a; arr[1] = b; @@ -1839,12 +1757,11 @@ library Solarray { return arr; } - function addresses( - address a, - address b, - address c, - address d - ) internal pure returns (address[] memory) { + function addresses(address a, address b, address c, address d) + internal + pure + returns (address[] memory) + { address[] memory arr = new address[](4); arr[0] = a; arr[1] = b; @@ -1853,13 +1770,11 @@ library Solarray { return arr; } - function addresses( - address a, - address b, - address c, - address d, - address e - ) internal pure returns (address[] memory) { + function addresses(address a, address b, address c, address d, address e) + internal + pure + returns (address[] memory) + { address[] memory arr = new address[](5); arr[0] = a; arr[1] = b; @@ -1920,11 +1835,11 @@ library Solarray { return arr; } - function bools( - bool a, - bool b, - bool c - ) internal pure returns (bool[] memory) { + function bools(bool a, bool b, bool c) + internal + pure + returns (bool[] memory) + { bool[] memory arr = new bool[](3); arr[0] = a; arr[1] = b; @@ -1932,12 +1847,11 @@ library Solarray { return arr; } - function bools( - bool a, - bool b, - bool c, - bool d - ) internal pure returns (bool[] memory) { + function bools(bool a, bool b, bool c, bool d) + internal + pure + returns (bool[] memory) + { bool[] memory arr = new bool[](4); arr[0] = a; arr[1] = b; @@ -1946,13 +1860,11 @@ library Solarray { return arr; } - function bools( - bool a, - bool b, - bool c, - bool d, - bool e - ) internal pure returns (bool[] memory) { + function bools(bool a, bool b, bool c, bool d, bool e) + internal + pure + returns (bool[] memory) + { bool[] memory arr = new bool[](5); arr[0] = a; arr[1] = b; @@ -1962,14 +1874,11 @@ library Solarray { return arr; } - function bools( - bool a, - bool b, - bool c, - bool d, - bool e, - bool f - ) internal pure returns (bool[] memory) { + function bools(bool a, bool b, bool c, bool d, bool e, bool f) + internal + pure + returns (bool[] memory) + { bool[] memory arr = new bool[](6); arr[0] = a; arr[1] = b; @@ -1980,15 +1889,11 @@ library Solarray { return arr; } - function bools( - bool a, - bool b, - bool c, - bool d, - bool e, - bool f, - bool g - ) internal pure returns (bool[] memory) { + function bools(bool a, bool b, bool c, bool d, bool e, bool f, bool g) + internal + pure + returns (bool[] memory) + { bool[] memory arr = new bool[](7); arr[0] = a; arr[1] = b; @@ -2006,21 +1911,22 @@ library Solarray { return arr; } - function strings( - string memory a, - string memory b - ) internal pure returns (string[] memory) { + function strings(string memory a, string memory b) + internal + pure + returns (string[] memory) + { string[] memory arr = new string[](2); arr[0] = a; arr[1] = b; return arr; } - function strings( - string memory a, - string memory b, - string memory c - ) internal pure returns (string[] memory) { + function strings(string memory a, string memory b, string memory c) + internal + pure + returns (string[] memory) + { string[] memory arr = new string[](3); arr[0] = a; arr[1] = b; diff --git a/src/SpaceEnums.sol b/src/SpaceEnums.sol index b84f010..dc01d5a 100644 --- a/src/SpaceEnums.sol +++ b/src/SpaceEnums.sol @@ -27,6 +27,7 @@ enum OrderStatusEnum { CANCELLED_EXPLICIT, // explicit cancellation CANCELLED_COUNTER, // canceled via counter increment (reverts due to invalid sig) REVERT // fulfilling reverts + } enum BroadOrderType { @@ -58,6 +59,7 @@ enum OrdersComposition { enum OrderStatusRevertReason { NATIVE, // receive hook fails ERC1155 // receive hook fails + } // ItemType.ERC20/ERC1155/ERC721 <- TokenIndex @@ -71,6 +73,7 @@ enum TokenIndex { enum Criteria { MERKLE, // non-zero criteria WILDCARD // criteria zero + } // Criteria.WILDCARD/MERKLE <- CriteriaResolved @@ -78,6 +81,7 @@ enum CriteriaResolved { VALID, // correctly resolved INVALID, // incorrectly resolved UNAVAILABLE // resolved but not owned/approved + } enum Amount { @@ -109,8 +113,8 @@ enum Recipient { DILLON, EVE, FRANK - // INVALID } +// INVALID enum RecipientDirty { CLEAN, @@ -268,6 +272,7 @@ enum BulkSignatureSize { enum Salt { VALID, DUPLICATE // ? + } enum ConduitChoice { @@ -311,12 +316,14 @@ enum InvalidFraction { INVALID, // order is a full order UNEVEN, // cannot divide into amount IRREGULAR // N/M where N > M + } enum CriteriaProofs { LESS, // too few proofs EQUAL, // sufficient number of proofs GREATER // extra proofs + } // Method.FULFILL_AVAILABLE* <= FulfillAvailableFulfillments @@ -338,6 +345,7 @@ enum InvalidFulfillAvailableFulfillmentsCondition { INVALID, // ie not correctly constructed, duplicates, etc LESS, // ie missing fulfillments GREATER // ie including duplicates + } // FulfillAvailableFulfillments.AGGREGATED <- AggregatedFulfillAvailableFulfillments diff --git a/src/StructSpace.sol b/src/StructSpace.sol index e2291e6..ed9fcf6 100644 --- a/src/StructSpace.sol +++ b/src/StructSpace.sol @@ -24,9 +24,7 @@ import { ZoneHash } from "./SpaceEnums.sol"; -import { - FulfillmentStrategy -} from "./fulfillments/lib/FulfillmentLib.sol"; +import { FulfillmentStrategy } from "./fulfillments/lib/FulfillmentLib.sol"; struct OfferItemSpace { ItemType itemType; diff --git a/src/ZoneInterface.sol b/src/ZoneInterface.sol index e051471..e8d232b 100644 --- a/src/ZoneInterface.sol +++ b/src/ZoneInterface.sol @@ -1,4 +1,4 @@ // SPDX-License-Identifier: MIT pragma solidity ^0.8.17; -import {ZoneInterface} from "seaport-types/src/interfaces/ZoneInterface.sol"; +import { ZoneInterface } from "seaport-types/src/interfaces/ZoneInterface.sol"; diff --git a/src/executions/ExecutionHelper.sol b/src/executions/ExecutionHelper.sol index f81e5e4..382f053 100644 --- a/src/executions/ExecutionHelper.sol +++ b/src/executions/ExecutionHelper.sol @@ -1,9 +1,7 @@ // SPDX-License-Identifier: MIT pragma solidity ^0.8.17; -import { - AmountDeriverHelper -} from "../lib/fulfillment/AmountDeriverHelper.sol"; +import { AmountDeriverHelper } from "../lib/fulfillment/AmountDeriverHelper.sol"; import { AdvancedOrderLib } from "../lib/AdvancedOrderLib.sol"; @@ -25,8 +23,7 @@ import { import { ItemType, Side } from "seaport-types/src/lib/ConsiderationEnums.sol"; import { - FulfillmentDetails, - OrderDetails + FulfillmentDetails, OrderDetails } from "../fulfillments/lib/Structs.sol"; import { UnavailableReason } from "../SpaceEnums.sol"; @@ -76,14 +73,11 @@ library ExecutionHelper { for (uint256 i = 0; i < orderDetails.length; ++i) { availableOrders[i] = - orderDetails[i].unavailableReason == - UnavailableReason.AVAILABLE; + orderDetails[i].unavailableReason == UnavailableReason.AVAILABLE; } - implicitExecutionsPre = processImplicitPreOrderExecutions( - details, - availableOrders - ); + implicitExecutionsPre = + processImplicitPreOrderExecutions(details, availableOrders); explicitExecutions = processExplicitExecutionsFromAggregatedComponents( details, @@ -92,10 +86,8 @@ library ExecutionHelper { availableOrders ); - implicitExecutionsPost = processImplicitPostOrderExecutions( - details, - availableOrders - ); + implicitExecutionsPost = + processImplicitPostOrderExecutions(details, availableOrders); nativeTokensReturned = _handleExcessNativeTokens( details, @@ -141,20 +133,16 @@ library ExecutionHelper { availableOrders[i] = true; } - implicitExecutionsPre = processImplicitPreOrderExecutions( - details, - availableOrders - ); + implicitExecutionsPre = + processImplicitPreOrderExecutions(details, availableOrders); for (uint256 i = 0; i < fulfillments.length; i++) { - Execution memory execution = processExecutionFromFulfillment( - details, - fulfillments[i] - ); + Execution memory execution = + processExecutionFromFulfillment(details, fulfillments[i]); if ( - execution.item.recipient == execution.offerer && - execution.item.itemType != ItemType.NATIVE + execution.item.recipient == execution.offerer + && execution.item.itemType != ItemType.NATIVE ) { filteredExecutions++; } else { @@ -173,10 +161,8 @@ library ExecutionHelper { } } - implicitExecutionsPost = processImplicitPostOrderExecutions( - details, - availableOrders - ); + implicitExecutionsPost = + processImplicitPostOrderExecutions(details, availableOrders); nativeTokensReturned = _handleExcessNativeTokens( details, @@ -218,9 +204,7 @@ library ExecutionHelper { } } - function getStandardExecutions( - FulfillmentDetails memory details - ) + function getStandardExecutions(FulfillmentDetails memory details) internal pure returns ( @@ -232,15 +216,14 @@ library ExecutionHelper { revert("ExecutionHelper: bad orderDetails length for standard"); } - return - getStandardExecutions( - details.orders[0], - details.fulfiller, - details.fulfillerConduitKey, - details.recipient, - details.nativeTokensSupplied, - details.seaport - ); + return getStandardExecutions( + details.orders[0], + details.fulfiller, + details.fulfillerConduitKey, + details.recipient, + details.nativeTokensSupplied, + details.seaport + ); } /** @@ -270,10 +253,8 @@ library ExecutionHelper { // - transferring consideration items to each recipient (consideration.length) // - returning unspent native tokens (0-1) implicitExecutions = new Execution[]( - 2 * - orderDetails.offer.length + - orderDetails.consideration.length + - 2 + 2 * orderDetails.offer.length + orderDetails.consideration.length + + 2 ); uint256 executionIndex = 0; @@ -379,9 +360,7 @@ library ExecutionHelper { } } - function getBasicExecutions( - FulfillmentDetails memory details - ) + function getBasicExecutions(FulfillmentDetails memory details) internal pure returns ( @@ -393,14 +372,13 @@ library ExecutionHelper { revert("ExecutionHelper: bad orderDetails length for basic"); } - return - getBasicExecutions( - details.orders[0], - details.fulfiller, - details.fulfillerConduitKey, - details.nativeTokensSupplied, - details.seaport - ); + return getBasicExecutions( + details.orders[0], + details.fulfiller, + details.fulfillerConduitKey, + details.nativeTokensSupplied, + details.seaport + ); } /** @@ -429,9 +407,8 @@ library ExecutionHelper { require(nativeTokensSupplied == 0, "native tokens not allowed"); require(orderDetails.consideration.length > 0, "no items received"); - implicitExecutions = new Execution[]( - 1 + orderDetails.consideration.length - ); + implicitExecutions = + new Execution[](1 + orderDetails.consideration.length); implicitExecutions[0] = Execution({ offerer: fulfiller, @@ -470,9 +447,8 @@ library ExecutionHelper { // - transfer additional recipient consideration items (consideration.length - 1) // - transfer first consideration item to the fulfiller (1) // - returning unspent native tokens (0-1) - implicitExecutions = new Execution[]( - orderDetails.consideration.length + 3 - ); + implicitExecutions = + new Execution[](orderDetails.consideration.length + 3); uint256 executionIndex = 0; @@ -512,9 +488,7 @@ library ExecutionHelper { for (uint256 i = 1; i < orderDetails.consideration.length; i++) { ReceivedItem memory item = orderDetails.consideration[i]; implicitExecutions[executionIndex++] = Execution({ - offerer: item.itemType == ItemType.NATIVE - ? seaport - : fulfiller, + offerer: item.itemType == ItemType.NATIVE ? seaport : fulfiller, conduitKey: fulfillerConduitKey, item: item }); @@ -537,9 +511,7 @@ library ExecutionHelper { } ReceivedItem memory item = orderDetails.consideration[0]; implicitExecutions[executionIndex++] = Execution({ - offerer: item.itemType == ItemType.NATIVE - ? seaport - : fulfiller, + offerer: item.itemType == ItemType.NATIVE ? seaport : fulfiller, conduitKey: fulfillerConduitKey, item: item }); @@ -598,17 +570,15 @@ library ExecutionHelper { pure returns (SpentItem memory item, address payable trueRecipient) { - OrderDetails memory details = fulfillmentDetails.orders[ - component.orderIndex - ]; + OrderDetails memory details = + fulfillmentDetails.orders[component.orderIndex]; if (side == Side.OFFER) { item = details.offer[component.itemIndex]; trueRecipient = offerRecipient; } else { - ReceivedItem memory _item = details.consideration[ - component.itemIndex - ]; + ReceivedItem memory _item = + details.consideration[component.itemIndex]; // cast to SpentItem assembly { item := _item @@ -639,7 +609,7 @@ library ExecutionHelper { // aggregate the amounts of each item uint256 aggregatedAmount; for (uint256 j = 0; j < aggregatedComponents.length; j++) { - (SpentItem memory item, ) = getItemAndRecipient( + (SpentItem memory item,) = getItemAndRecipient( fulfillmentDetails, offerRecipient, aggregatedComponents[j], @@ -650,35 +620,26 @@ library ExecutionHelper { // use the first fulfillment component to get the order details FulfillmentComponent memory first = aggregatedComponents[0]; - ( - SpentItem memory firstItem, - address payable trueRecipient - ) = getItemAndRecipient( - fulfillmentDetails, - offerRecipient, - first, - side - ); - OrderDetails memory details = fulfillmentDetails.orders[ - first.orderIndex - ]; - - return - Execution({ - offerer: side == Side.OFFER - ? details.offerer - : fulfillmentDetails.fulfiller, - conduitKey: side == Side.OFFER - ? details.conduitKey - : fulfillmentDetails.fulfillerConduitKey, - item: ReceivedItem({ - itemType: firstItem.itemType, - token: firstItem.token, - identifier: firstItem.identifier, - amount: aggregatedAmount, - recipient: trueRecipient - }) - }); + (SpentItem memory firstItem, address payable trueRecipient) = + getItemAndRecipient(fulfillmentDetails, offerRecipient, first, side); + OrderDetails memory details = + fulfillmentDetails.orders[first.orderIndex]; + + return Execution({ + offerer: side == Side.OFFER + ? details.offerer + : fulfillmentDetails.fulfiller, + conduitKey: side == Side.OFFER + ? details.conduitKey + : fulfillmentDetails.fulfillerConduitKey, + item: ReceivedItem({ + itemType: firstItem.itemType, + token: firstItem.token, + identifier: firstItem.identifier, + amount: aggregatedAmount, + recipient: trueRecipient + }) + }); } /** @@ -707,8 +668,8 @@ library ExecutionHelper { // process offer components // iterate over each array of fulfillment components for (uint256 i = 0; i < offerComponents.length; i++) { - FulfillmentComponent[] - memory aggregatedComponents = offerComponents[i]; + FulfillmentComponent[] memory aggregatedComponents = + offerComponents[i]; // aggregate & zero-out the amounts of each offer item uint256 aggregatedAmount; @@ -719,13 +680,12 @@ library ExecutionHelper { continue; } - OrderDetails memory offerOrderDetails = fulfillmentDetails - .orders[component.orderIndex]; + OrderDetails memory offerOrderDetails = + fulfillmentDetails.orders[component.orderIndex]; if (component.itemIndex < offerOrderDetails.offer.length) { - SpentItem memory item = offerOrderDetails.offer[ - component.itemIndex - ]; + SpentItem memory item = + offerOrderDetails.offer[component.itemIndex]; aggregatedAmount += item.amount; @@ -740,14 +700,13 @@ library ExecutionHelper { // use the first fulfillment component to get the order details FulfillmentComponent memory first = aggregatedComponents[0]; - OrderDetails memory details = fulfillmentDetails.orders[ - first.orderIndex - ]; + OrderDetails memory details = + fulfillmentDetails.orders[first.orderIndex]; SpentItem memory firstItem = details.offer[first.itemIndex]; if ( - fulfillmentDetails.recipient == details.offerer && - firstItem.itemType != ItemType.NATIVE + fulfillmentDetails.recipient == details.offerer + && firstItem.itemType != ItemType.NATIVE ) { filteredExecutions++; } else { @@ -768,8 +727,8 @@ library ExecutionHelper { // process consideration components // iterate over each array of fulfillment components for (uint256 i; i < considerationComponents.length; i++) { - FulfillmentComponent[] - memory aggregatedComponents = considerationComponents[i]; + FulfillmentComponent[] memory aggregatedComponents = + considerationComponents[i]; // aggregate & zero-out the amounts of each offer item uint256 aggregatedAmount; @@ -780,13 +739,12 @@ library ExecutionHelper { continue; } - OrderDetails - memory considerationOrderDetails = fulfillmentDetails - .orders[component.orderIndex]; + OrderDetails memory considerationOrderDetails = + fulfillmentDetails.orders[component.orderIndex]; if ( - component.itemIndex < - considerationOrderDetails.consideration.length + component.itemIndex + < considerationOrderDetails.consideration.length ) { ReceivedItem memory item = considerationOrderDetails .consideration[component.itemIndex]; @@ -804,22 +762,19 @@ library ExecutionHelper { // 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 - ]; + OrderDetails memory details = + fulfillmentDetails.orders[first.orderIndex]; + ReceivedItem memory firstItem = + details.consideration[first.itemIndex]; if ( - firstItem.recipient == fulfillmentDetails.fulfiller && - firstItem.itemType != ItemType.NATIVE + firstItem.recipient == fulfillmentDetails.fulfiller + && firstItem.itemType != ItemType.NATIVE ) { filteredExecutions++; } else { - explicitExecutions[ - i + offerComponents.length - filteredExecutions - ] = Execution({ + explicitExecutions[i + offerComponents.length + - filteredExecutions] = Execution({ offerer: fulfillmentDetails.fulfiller, conduitKey: fulfillmentDetails.fulfillerConduitKey, item: ReceivedItem({ @@ -1023,18 +978,15 @@ library ExecutionHelper { // aggregate & zero-out the amounts of each offer item uint256 aggregatedOfferAmount; for (uint256 j = 0; j < fulfillment.offerComponents.length; j++) { - FulfillmentComponent memory component = fulfillment.offerComponents[ - j - ]; + FulfillmentComponent memory component = + fulfillment.offerComponents[j]; - OrderDetails memory details = fulfillmentDetails.orders[ - component.orderIndex - ]; + OrderDetails memory details = + fulfillmentDetails.orders[component.orderIndex]; if (component.itemIndex < details.offer.length) { - SpentItem memory offerSpentItem = details.offer[ - component.itemIndex - ]; + SpentItem memory offerSpentItem = + details.offer[component.itemIndex]; aggregatedOfferAmount += offerSpentItem.amount; @@ -1044,21 +996,17 @@ library ExecutionHelper { // aggregate & zero-out the amounts of each offer item uint256 aggregatedConsiderationAmount; - for ( - uint256 j = 0; - j < fulfillment.considerationComponents.length; - j++ - ) { - FulfillmentComponent memory component = fulfillment - .considerationComponents[j]; - - OrderDetails memory details = fulfillmentDetails.orders[ - component.orderIndex - ]; + for (uint256 j = 0; j < fulfillment.considerationComponents.length; j++) + { + FulfillmentComponent memory component = + fulfillment.considerationComponents[j]; + + OrderDetails memory details = + fulfillmentDetails.orders[component.orderIndex]; if (component.itemIndex < details.consideration.length) { - ReceivedItem memory considerationSpentItem = details - .consideration[component.itemIndex]; + ReceivedItem memory considerationSpentItem = + details.consideration[component.itemIndex]; aggregatedConsiderationAmount += considerationSpentItem.amount; @@ -1067,43 +1015,38 @@ library ExecutionHelper { } // Get the first item on each side - FulfillmentComponent memory firstOfferComponent = fulfillment - .offerComponents[0]; - OrderDetails memory sourceOrder = fulfillmentDetails.orders[ - firstOfferComponent.orderIndex - ]; - - FulfillmentComponent memory firstConsiderationComponent = fulfillment - .considerationComponents[0]; - ReceivedItem memory item = fulfillmentDetails - .orders[firstConsiderationComponent.orderIndex] - .consideration[firstConsiderationComponent.itemIndex]; + FulfillmentComponent memory firstOfferComponent = + fulfillment.offerComponents[0]; + OrderDetails memory sourceOrder = + fulfillmentDetails.orders[firstOfferComponent.orderIndex]; + + FulfillmentComponent memory firstConsiderationComponent = + fulfillment.considerationComponents[0]; + ReceivedItem memory item = fulfillmentDetails.orders[firstConsiderationComponent + .orderIndex].consideration[firstConsiderationComponent.itemIndex]; // put back any extra (TODO: put it on first *in-range* item) uint256 amount = aggregatedOfferAmount; if (aggregatedOfferAmount > aggregatedConsiderationAmount) { - sourceOrder - .offer[firstOfferComponent.itemIndex] - .amount += (aggregatedOfferAmount - - aggregatedConsiderationAmount); + sourceOrder.offer[firstOfferComponent.itemIndex].amount += + (aggregatedOfferAmount - aggregatedConsiderationAmount); amount = aggregatedConsiderationAmount; } else if (aggregatedOfferAmount < aggregatedConsiderationAmount) { - item.amount += (aggregatedConsiderationAmount - - aggregatedOfferAmount); + item.amount += + (aggregatedConsiderationAmount - aggregatedOfferAmount); } - return - Execution({ - offerer: sourceOrder.offerer, - conduitKey: sourceOrder.conduitKey, - item: ReceivedItem({ - itemType: item.itemType, - token: item.token, - identifier: item.identifier, - amount: amount, - recipient: item.recipient - }) - }); + return Execution({ + offerer: sourceOrder.offerer, + conduitKey: sourceOrder.conduitKey, + item: ReceivedItem({ + itemType: item.itemType, + token: item.token, + identifier: item.identifier, + amount: amount, + recipient: item.recipient + }) + }); } /** @@ -1123,15 +1066,12 @@ library ExecutionHelper { Execution[] memory implicitExecutionsPost ) internal pure returns (uint256 excessNativeTokens) { excessNativeTokens = processExcessNativeTokens( - explicitExecutions, - implicitExecutionsPre, - implicitExecutionsPost + explicitExecutions, implicitExecutionsPre, implicitExecutionsPost ); if (excessNativeTokens > 0) { - implicitExecutionsPost[ - implicitExecutionsPost.length - 1 - ] = Execution({ + implicitExecutionsPost[implicitExecutionsPost.length - 1] = + Execution({ offerer: fulfillmentDetails.seaport, conduitKey: bytes32(0), item: ReceivedItem({ @@ -1153,9 +1093,11 @@ library ExecutionHelper { } } - function copy( - OrderDetails[] memory orderDetails - ) internal pure returns (OrderDetails[] memory copiedOrderDetails) { + function copy(OrderDetails[] memory orderDetails) + internal + pure + returns (OrderDetails[] memory copiedOrderDetails) + { copiedOrderDetails = new OrderDetails[](orderDetails.length); for (uint256 i = 0; i < orderDetails.length; ++i) { OrderDetails memory order = orderDetails[i]; @@ -1172,17 +1114,18 @@ library ExecutionHelper { } } - function copy( - FulfillmentDetails memory fulfillmentDetails - ) internal pure returns (FulfillmentDetails memory) { - return - FulfillmentDetails({ - orders: copy(fulfillmentDetails.orders), - recipient: fulfillmentDetails.recipient, - fulfiller: fulfillmentDetails.fulfiller, - nativeTokensSupplied: fulfillmentDetails.nativeTokensSupplied, - fulfillerConduitKey: fulfillmentDetails.fulfillerConduitKey, - seaport: fulfillmentDetails.seaport - }); + function copy(FulfillmentDetails memory fulfillmentDetails) + internal + pure + returns (FulfillmentDetails memory) + { + return FulfillmentDetails({ + orders: copy(fulfillmentDetails.orders), + recipient: fulfillmentDetails.recipient, + fulfiller: fulfillmentDetails.fulfiller, + nativeTokensSupplied: fulfillmentDetails.nativeTokensSupplied, + fulfillerConduitKey: fulfillmentDetails.fulfillerConduitKey, + seaport: fulfillmentDetails.seaport + }); } } diff --git a/src/executions/FulfillmentComponentSet.sol b/src/executions/FulfillmentComponentSet.sol index f307c14..d3b5073 100644 --- a/src/executions/FulfillmentComponentSet.sol +++ b/src/executions/FulfillmentComponentSet.sol @@ -1,7 +1,7 @@ // SPDX-License-Identifier: MIT pragma solidity ^0.8.17; -import {FulfillmentComponent} from "../SeaportStructs.sol"; +import { FulfillmentComponent } from "../SeaportStructs.sol"; struct FulfillmentComponentSet { mapping(bytes32 => uint256) offByOneIndex; @@ -11,10 +11,10 @@ struct FulfillmentComponentSet { library FulfillmentComponentSetLib { error NotPresent(); - function add(FulfillmentComponentSet storage set, FulfillmentComponent memory value) - internal - returns (bool added) - { + function add( + FulfillmentComponentSet storage set, + FulfillmentComponent memory value + ) internal returns (bool added) { // add value to enumeration; hash it to set its entry in the offByOneIndex bytes32 key = keccak256(abi.encode(value)); if (set.offByOneIndex[key] == 0) { @@ -28,10 +28,10 @@ library FulfillmentComponentSetLib { // remove value from enumeration and replace it with last member of enumeration // if not last member, update offByOneIndex of last member - function remove(FulfillmentComponentSet storage set, FulfillmentComponent memory value) - internal - returns (bool removed) - { + function remove( + FulfillmentComponentSet storage set, + FulfillmentComponent memory value + ) internal returns (bool removed) { bytes32 key = keccak256(abi.encode(value)); uint256 index = set.offByOneIndex[key]; if (index > 0) { @@ -51,27 +51,36 @@ library FulfillmentComponentSetLib { } } - function removeAll(FulfillmentComponentSet storage set, FulfillmentComponent[] memory values) internal { + function removeAll( + FulfillmentComponentSet storage set, + FulfillmentComponent[] memory values + ) internal { for (uint256 i = 0; i < values.length; i++) { remove(set, values[i]); } } - function removeAll(FulfillmentComponentSet storage set, FulfillmentComponent[][] memory values) internal { + function removeAll( + FulfillmentComponentSet storage set, + FulfillmentComponent[][] memory values + ) internal { for (uint256 i = 0; i < values.length; i++) { removeAll(set, values[i]); } } - function contains(FulfillmentComponentSet storage set, FulfillmentComponent memory value) - internal - view - returns (bool) - { + function contains( + FulfillmentComponentSet storage set, + FulfillmentComponent memory value + ) internal view returns (bool) { return set.offByOneIndex[keccak256(abi.encode(value))] > 0; } - function length(FulfillmentComponentSet storage set) internal view returns (uint256) { + function length(FulfillmentComponentSet storage set) + internal + view + returns (uint256) + { return set.enumeration.length; } @@ -85,7 +94,8 @@ library FulfillmentComponentSetLib { function clear(FulfillmentComponentSet storage set) internal { while (set.enumeration.length > 0) { - FulfillmentComponent memory component = set.enumeration[set.enumeration.length - 1]; + FulfillmentComponent memory component = + set.enumeration[set.enumeration.length - 1]; delete set.offByOneIndex[keccak256(abi.encode(component))]; set.enumeration.pop(); } diff --git a/src/executions/FulfillmentComponentSortLib.sol b/src/executions/FulfillmentComponentSortLib.sol index 356abaf..e2af864 100644 --- a/src/executions/FulfillmentComponentSortLib.sol +++ b/src/executions/FulfillmentComponentSortLib.sol @@ -1,10 +1,14 @@ // SPDX-License-Identifier: MIT pragma solidity ^0.8.17; -import {FulfillmentComponent} from "../SeaportStructs.sol"; +import { FulfillmentComponent } from "../SeaportStructs.sol"; library FulfillmentComponentSortLib { - function key(FulfillmentComponent memory component) internal pure returns (uint256) { + function key(FulfillmentComponent memory component) + internal + pure + returns (uint256) + { return (uint256(component.orderIndex) << 8) | component.itemIndex; } diff --git a/src/executions/GenericEnumerableMapping.sol b/src/executions/GenericEnumerableMapping.sol index f307c14..d3b5073 100644 --- a/src/executions/GenericEnumerableMapping.sol +++ b/src/executions/GenericEnumerableMapping.sol @@ -1,7 +1,7 @@ // SPDX-License-Identifier: MIT pragma solidity ^0.8.17; -import {FulfillmentComponent} from "../SeaportStructs.sol"; +import { FulfillmentComponent } from "../SeaportStructs.sol"; struct FulfillmentComponentSet { mapping(bytes32 => uint256) offByOneIndex; @@ -11,10 +11,10 @@ struct FulfillmentComponentSet { library FulfillmentComponentSetLib { error NotPresent(); - function add(FulfillmentComponentSet storage set, FulfillmentComponent memory value) - internal - returns (bool added) - { + function add( + FulfillmentComponentSet storage set, + FulfillmentComponent memory value + ) internal returns (bool added) { // add value to enumeration; hash it to set its entry in the offByOneIndex bytes32 key = keccak256(abi.encode(value)); if (set.offByOneIndex[key] == 0) { @@ -28,10 +28,10 @@ library FulfillmentComponentSetLib { // remove value from enumeration and replace it with last member of enumeration // if not last member, update offByOneIndex of last member - function remove(FulfillmentComponentSet storage set, FulfillmentComponent memory value) - internal - returns (bool removed) - { + function remove( + FulfillmentComponentSet storage set, + FulfillmentComponent memory value + ) internal returns (bool removed) { bytes32 key = keccak256(abi.encode(value)); uint256 index = set.offByOneIndex[key]; if (index > 0) { @@ -51,27 +51,36 @@ library FulfillmentComponentSetLib { } } - function removeAll(FulfillmentComponentSet storage set, FulfillmentComponent[] memory values) internal { + function removeAll( + FulfillmentComponentSet storage set, + FulfillmentComponent[] memory values + ) internal { for (uint256 i = 0; i < values.length; i++) { remove(set, values[i]); } } - function removeAll(FulfillmentComponentSet storage set, FulfillmentComponent[][] memory values) internal { + function removeAll( + FulfillmentComponentSet storage set, + FulfillmentComponent[][] memory values + ) internal { for (uint256 i = 0; i < values.length; i++) { removeAll(set, values[i]); } } - function contains(FulfillmentComponentSet storage set, FulfillmentComponent memory value) - internal - view - returns (bool) - { + function contains( + FulfillmentComponentSet storage set, + FulfillmentComponent memory value + ) internal view returns (bool) { return set.offByOneIndex[keccak256(abi.encode(value))] > 0; } - function length(FulfillmentComponentSet storage set) internal view returns (uint256) { + function length(FulfillmentComponentSet storage set) + internal + view + returns (uint256) + { return set.enumeration.length; } @@ -85,7 +94,8 @@ library FulfillmentComponentSetLib { function clear(FulfillmentComponentSet storage set) internal { while (set.enumeration.length > 0) { - FulfillmentComponent memory component = set.enumeration[set.enumeration.length - 1]; + FulfillmentComponent memory component = + set.enumeration[set.enumeration.length - 1]; delete set.offByOneIndex[keccak256(abi.encode(component))]; set.enumeration.pop(); } diff --git a/src/fulfillments/available/FulfillAvailableHelper.sol b/src/fulfillments/available/FulfillAvailableHelper.sol index c19a2cd..26278fa 100644 --- a/src/fulfillments/available/FulfillAvailableHelper.sol +++ b/src/fulfillments/available/FulfillAvailableHelper.sol @@ -9,9 +9,12 @@ import { AggregatableOffer, AggregatableConsideration } from "../lib/Structs.sol"; -import {FulfillAvailableLayout} from "./FulfillAvailableLayout.sol"; -import {FULFILL_AVAILABLE_COUNTER_KEY, FULFILL_AVAILABLE_STORAGE_BASE_KEY} from "../lib/Constants.sol"; -import {OrderDetails} from "../lib/Structs.sol"; +import { FulfillAvailableLayout } from "./FulfillAvailableLayout.sol"; +import { + FULFILL_AVAILABLE_COUNTER_KEY, + FULFILL_AVAILABLE_STORAGE_BASE_KEY +} from "../lib/Constants.sol"; +import { OrderDetails } from "../lib/Structs.sol"; contract FulfillAvailableHelper { /** @@ -25,11 +28,13 @@ contract FulfillAvailableHelper { function getNaiveFulfillmentComponents(Order[] memory orders) public pure - returns (FulfillmentComponent[][] memory offer, FulfillmentComponent[][] memory consideration) + returns ( + FulfillmentComponent[][] memory offer, + FulfillmentComponent[][] memory consideration + ) { - OrderParameters[] memory orderParameters = new OrderParameters[]( - orders.length - ); + OrderParameters[] memory orderParameters = + new OrderParameters[](orders.length); for (uint256 i = 0; i < orders.length; i++) { orderParameters[i] = orders[i].parameters; } @@ -47,11 +52,13 @@ contract FulfillAvailableHelper { function getNaiveFulfillmentComponents(AdvancedOrder[] memory orders) public pure - returns (FulfillmentComponent[][] memory offer, FulfillmentComponent[][] memory consideration) + returns ( + FulfillmentComponent[][] memory offer, + FulfillmentComponent[][] memory consideration + ) { - OrderParameters[] memory orderParameters = new OrderParameters[]( - orders.length - ); + OrderParameters[] memory orderParameters = + new OrderParameters[](orders.length); for (uint256 i = 0; i < orders.length; i++) { orderParameters[i] = orders[i].parameters; } @@ -66,10 +73,15 @@ contract FulfillAvailableHelper { * @return offer * @return consideration */ - function getNaiveFulfillmentComponents(OrderParameters[] memory orderParameters) + function getNaiveFulfillmentComponents( + OrderParameters[] memory orderParameters + ) public pure - returns (FulfillmentComponent[][] memory offer, FulfillmentComponent[][] memory consideration) + returns ( + FulfillmentComponent[][] memory offer, + FulfillmentComponent[][] memory consideration + ) { { // get total number of offer items and consideration items @@ -93,14 +105,17 @@ contract FulfillAvailableHelper { for (uint256 i = 0; i < orderParameters.length; i++) { OrderParameters memory parameters = orderParameters[i]; for (uint256 j; j < parameters.offer.length; j++) { - offer[offerIndex] = - SeaportArrays.FulfillmentComponents(FulfillmentComponent({orderIndex: i, itemIndex: j})); + offer[offerIndex] = SeaportArrays.FulfillmentComponents( + FulfillmentComponent({ orderIndex: i, itemIndex: j }) + ); ++offerIndex; } // do the same for consideration for (uint256 j; j < parameters.consideration.length; j++) { - consideration[considerationIndex] = - SeaportArrays.FulfillmentComponents(FulfillmentComponent({orderIndex: i, itemIndex: j})); + consideration[considerationIndex] = SeaportArrays + .FulfillmentComponents( + FulfillmentComponent({ orderIndex: i, itemIndex: j }) + ); ++considerationIndex; } } @@ -118,7 +133,10 @@ contract FulfillAvailableHelper { function getNaiveFulfillmentComponents(OrderDetails[] memory orders) public pure - returns (FulfillmentComponent[][] memory offer, FulfillmentComponent[][] memory consideration) + returns ( + FulfillmentComponent[][] memory offer, + FulfillmentComponent[][] memory consideration + ) { { // get total number of offer items and consideration items @@ -142,14 +160,17 @@ contract FulfillAvailableHelper { for (uint256 i = 0; i < orders.length; i++) { OrderDetails memory order = orders[i]; for (uint256 j; j < order.offer.length; j++) { - offer[offerIndex] = - SeaportArrays.FulfillmentComponents(FulfillmentComponent({orderIndex: i, itemIndex: j})); + offer[offerIndex] = SeaportArrays.FulfillmentComponents( + FulfillmentComponent({ orderIndex: i, itemIndex: j }) + ); ++offerIndex; } // do the same for consideration for (uint256 j; j < order.consideration.length; j++) { - consideration[considerationIndex] = - SeaportArrays.FulfillmentComponents(FulfillmentComponent({orderIndex: i, itemIndex: j})); + consideration[considerationIndex] = SeaportArrays + .FulfillmentComponents( + FulfillmentComponent({ orderIndex: i, itemIndex: j }) + ); ++considerationIndex; } } @@ -166,11 +187,13 @@ contract FulfillAvailableHelper { */ function getAggregatedFulfillmentComponents(Order[] memory orders) public - returns (FulfillmentComponent[][] memory offer, FulfillmentComponent[][] memory consideration) + returns ( + FulfillmentComponent[][] memory offer, + FulfillmentComponent[][] memory consideration + ) { - OrderParameters[] memory orderParameters = new OrderParameters[]( - orders.length - ); + OrderParameters[] memory orderParameters = + new OrderParameters[](orders.length); for (uint256 i = 0; i < orders.length; i++) { orderParameters[i] = orders[i].parameters; } @@ -187,11 +210,13 @@ contract FulfillAvailableHelper { */ function getAggregatedFulfillmentComponents(AdvancedOrder[] memory orders) public - returns (FulfillmentComponent[][] memory offer, FulfillmentComponent[][] memory consideration) + returns ( + FulfillmentComponent[][] memory offer, + FulfillmentComponent[][] memory consideration + ) { - OrderParameters[] memory orderParameters = new OrderParameters[]( - orders.length - ); + OrderParameters[] memory orderParameters = + new OrderParameters[](orders.length); for (uint256 i = 0; i < orders.length; i++) { orderParameters[i] = orders[i].parameters; } @@ -208,16 +233,26 @@ contract FulfillAvailableHelper { */ function getAggregatedFulfillmentComponents(OrderParameters[] memory orders) public - returns (FulfillmentComponent[][] memory offer, FulfillmentComponent[][] memory consideration) + returns ( + FulfillmentComponent[][] memory offer, + FulfillmentComponent[][] memory consideration + ) { // increment counter to get clean mappings and enumeration FulfillAvailableLayout.incrementFulfillmentCounter(); - FulfillAvailableHelperStorageLayout storage layout = FulfillAvailableLayout.getStorageLayout(); + FulfillAvailableHelperStorageLayout storage layout = + FulfillAvailableLayout.getStorageLayout(); // iterate over each order for (uint256 i; i < orders.length; ++i) { OrderParameters memory parameters = orders[i]; - preProcessOffer(parameters.offer, parameters.offerer, parameters.conduitKey, i, layout); + preProcessOffer( + parameters.offer, + parameters.offerer, + parameters.conduitKey, + i, + layout + ); preProcessConsideration(parameters.consideration, i, layout); } @@ -227,24 +262,25 @@ contract FulfillAvailableHelper { for (uint256 i; i < layout.offerEnumeration.length; ++i) { AggregatableOffer memory token = layout.offerEnumeration[i]; - offer[i] = layout.offerMap[token.contractAddress][token.tokenId][token.offerer][token.conduitKey]; + offer[i] = layout.offerMap[token.contractAddress][token.tokenId][token + .offerer][token.conduitKey]; } // do the same for considerations - consideration = new FulfillmentComponent[][]( - layout.considerationEnumeration.length - ); + consideration = + new FulfillmentComponent[][](layout.considerationEnumeration.length); for (uint256 i; i < layout.considerationEnumeration.length; ++i) { - AggregatableConsideration memory token = layout.considerationEnumeration[i]; - consideration[i] = layout.considerationMap[token.recipient][token.contractAddress][token.tokenId]; + AggregatableConsideration memory token = + layout.considerationEnumeration[i]; + consideration[i] = layout.considerationMap[token.recipient][token + .contractAddress][token.tokenId]; } return (offer, consideration); } - function extend(FulfillmentComponent[][] memory array, FulfillmentComponent[] memory toAdd) - internal - pure - returns (FulfillmentComponent[][] memory extended) - { + function extend( + FulfillmentComponent[][] memory array, + FulfillmentComponent[] memory toAdd + ) internal pure returns (FulfillmentComponent[][] memory extended) { extended = new FulfillmentComponent[][](array.length + 1); for (uint256 i = 0; i < array.length; i++) { extended[i] = array[i]; @@ -269,7 +305,8 @@ contract FulfillAvailableHelper { // iterate over each offer item for (uint256 j; j < offer.length; ++j) { // create the fulfillment component for this offer item - FulfillmentComponent memory component = FulfillmentComponent({orderIndex: orderIndex, itemIndex: j}); + FulfillmentComponent memory component = + FulfillmentComponent({ orderIndex: orderIndex, itemIndex: j }); // grab order parameters to get offerer // grab offer item OfferItem memory item = offer[j]; @@ -281,12 +318,17 @@ contract FulfillAvailableHelper { tokenId: item.identifierOrCriteria }); // if it does not exist in the map, add it to our enumeration - if (!FulfillAvailableLayout.aggregatableOfferExists(aggregatableOffer, layout)) { + if ( + !FulfillAvailableLayout.aggregatableOfferExists( + aggregatableOffer, layout + ) + ) { layout.offerEnumeration.push(aggregatableOffer); } // update mapping with this component - layout.offerMap[aggregatableOffer.contractAddress][aggregatableOffer.tokenId][aggregatableOffer.offerer][aggregatableOffer - .conduitKey].push(component); + layout.offerMap[aggregatableOffer.contractAddress][aggregatableOffer + .tokenId][aggregatableOffer.offerer][aggregatableOffer.conduitKey] + .push(component); } } @@ -304,7 +346,8 @@ contract FulfillAvailableHelper { // iterate over each offer item for (uint256 j; j < consideration.length; ++j) { // create the fulfillment component for this offer item - FulfillmentComponent memory component = FulfillmentComponent({orderIndex: orderIndex, itemIndex: j}); + FulfillmentComponent memory component = + FulfillmentComponent({ orderIndex: orderIndex, itemIndex: j }); // grab consideration item ConsiderationItem memory item = consideration[j]; // create enumeration struct @@ -314,11 +357,16 @@ contract FulfillAvailableHelper { tokenId: item.identifierOrCriteria }); // if it does not exist in the map, add it to our enumeration - if (!FulfillAvailableLayout.aggregatableConsiderationExists(token, layout)) { + if ( + !FulfillAvailableLayout.aggregatableConsiderationExists( + token, layout + ) + ) { layout.considerationEnumeration.push(token); } // update mapping with this component - layout.considerationMap[token.recipient][token.contractAddress][token.tokenId].push(component); + layout.considerationMap[token.recipient][token.contractAddress][token + .tokenId].push(component); } } } diff --git a/src/fulfillments/available/FulfillAvailableLayout.sol b/src/fulfillments/available/FulfillAvailableLayout.sol index d872464..49a2a68 100644 --- a/src/fulfillments/available/FulfillAvailableLayout.sol +++ b/src/fulfillments/available/FulfillAvailableLayout.sol @@ -1,14 +1,20 @@ // SPDX-License-Identifier: MIT pragma solidity ^0.8.17; -import {MatchComponent, MatchComponentType} from "../../lib/types/MatchComponentType.sol"; +import { + MatchComponent, + MatchComponentType +} from "../../lib/types/MatchComponentType.sol"; import { FulfillAvailableHelperStorageLayout, FulfillmentHelperCounterLayout, AggregatableConsideration, AggregatableOffer } from "../lib/Structs.sol"; -import {FULFILL_AVAILABLE_COUNTER_KEY, FULFILL_AVAILABLE_STORAGE_BASE_KEY} from "../lib/Constants.sol"; +import { + FULFILL_AVAILABLE_COUNTER_KEY, + FULFILL_AVAILABLE_STORAGE_BASE_KEY +} from "../lib/Constants.sol"; library FulfillAvailableLayout { /** @@ -20,25 +26,31 @@ library FulfillAvailableLayout { AggregatableConsideration memory token, FulfillAvailableHelperStorageLayout storage layout ) internal view returns (bool) { - return layout.considerationMap[token.recipient][token.contractAddress][token.tokenId].length > 0; + return layout.considerationMap[token.recipient][token.contractAddress][token + .tokenId].length > 0; } /** * @notice Check if an entry into the offer component mapping already exists by checking its length */ - function aggregatableOfferExists(AggregatableOffer memory offer, FulfillAvailableHelperStorageLayout storage layout) - internal - view - returns (bool) - { - return layout.offerMap[offer.contractAddress][offer.tokenId][offer.offerer][offer.conduitKey].length > 0; + function aggregatableOfferExists( + AggregatableOffer memory offer, + FulfillAvailableHelperStorageLayout storage layout + ) internal view returns (bool) { + return layout.offerMap[offer.contractAddress][offer.tokenId][offer + .offerer][offer.conduitKey].length > 0; } /** * @notice load storage layout for the current fulfillmentCounter */ - function getStorageLayout() internal view returns (FulfillAvailableHelperStorageLayout storage layout) { - FulfillmentHelperCounterLayout storage counterLayout = getCounterLayout(); + function getStorageLayout() + internal + view + returns (FulfillAvailableHelperStorageLayout storage layout) + { + FulfillmentHelperCounterLayout storage counterLayout = + getCounterLayout(); uint256 counter = counterLayout.fulfillmentCounter; bytes32 storageLayoutKey = FULFILL_AVAILABLE_STORAGE_BASE_KEY; assembly { @@ -51,7 +63,11 @@ library FulfillAvailableLayout { /** * @notice load storage layout for the counter itself */ - function getCounterLayout() internal pure returns (FulfillmentHelperCounterLayout storage layout) { + function getCounterLayout() + internal + pure + returns (FulfillmentHelperCounterLayout storage layout) + { bytes32 counterLayoutKey = FULFILL_AVAILABLE_COUNTER_KEY; assembly { layout.slot := counterLayoutKey @@ -62,7 +78,8 @@ library FulfillAvailableLayout { * @notice increment the fulfillmentCounter to effectively clear the mappings and enumerations between calls */ function incrementFulfillmentCounter() internal { - FulfillmentHelperCounterLayout storage counterLayout = getCounterLayout(); + FulfillmentHelperCounterLayout storage counterLayout = + getCounterLayout(); counterLayout.fulfillmentCounter += 1; } @@ -76,7 +93,12 @@ library FulfillAvailableLayout { returns ( mapping( address /*offererOrRecipient*/ - => mapping(address /*tokenContract*/ => mapping(uint256 /*identifier*/ => MatchComponent[] /*components*/)) + => mapping( + address /*tokenContract*/ + => mapping( + uint256 /*identifier*/ => MatchComponent[] /*components*/ + ) + ) ) storage map ) { @@ -92,7 +114,11 @@ library FulfillAvailableLayout { * @notice Get the enumeration of AggregatableConsiderations for a given key (offer or consideration), derived from the hash of the key and the current fulfillmentCounter value * @param key Original key used to derive the slot of the enumeration */ - function getEnumeration(bytes32 key) internal view returns (AggregatableConsideration[] storage tokens) { + function getEnumeration(bytes32 key) + internal + view + returns (AggregatableConsideration[] storage tokens) + { bytes32 counterKey = FULFILL_AVAILABLE_COUNTER_KEY; assembly { mstore(0, key) diff --git a/src/fulfillments/lib/Constants.sol b/src/fulfillments/lib/Constants.sol index d97eb31..43855c2 100644 --- a/src/fulfillments/lib/Constants.sol +++ b/src/fulfillments/lib/Constants.sol @@ -2,19 +2,15 @@ pragma solidity ^0.8.17; // used to effectively "wipe" the mappings and enumerations each time getAggregated is called -bytes32 constant MATCH_FULFILLMENT_COUNTER_KEY = keccak256( - "MatchFulfillmentHelper.fulfillmentCounter" -); +bytes32 constant MATCH_FULFILLMENT_COUNTER_KEY = + keccak256("MatchFulfillmentHelper.fulfillmentCounter"); -bytes32 constant MATCH_FULFILLMENT_STORAGE_BASE_KEY = keccak256( - "MatchFulfillmentHelper.storageBase" -); +bytes32 constant MATCH_FULFILLMENT_STORAGE_BASE_KEY = + keccak256("MatchFulfillmentHelper.storageBase"); // used to effectively "wipe" the mappings and enumerations each time getAggregated is called -bytes32 constant FULFILL_AVAILABLE_COUNTER_KEY = keccak256( - "FulfillAvailableHelper.fulfillmentCounter" -); +bytes32 constant FULFILL_AVAILABLE_COUNTER_KEY = + keccak256("FulfillAvailableHelper.fulfillmentCounter"); -bytes32 constant FULFILL_AVAILABLE_STORAGE_BASE_KEY = keccak256( - "FulfillAvailableHelper.storageBase" -); +bytes32 constant FULFILL_AVAILABLE_STORAGE_BASE_KEY = + keccak256("FulfillAvailableHelper.storageBase"); diff --git a/src/fulfillments/lib/FulfillmentLib.sol b/src/fulfillments/lib/FulfillmentLib.sol index 1555367..9da3d31 100644 --- a/src/fulfillments/lib/FulfillmentLib.sol +++ b/src/fulfillments/lib/FulfillmentLib.sol @@ -31,7 +31,8 @@ enum AggregationStrategy { MINIMUM, // Aggregate as few items as possible MAXIMUM, // Aggregate as many items as possible RANDOM // Randomize aggregation quantity - // NOTE: for match cases, there may be more sophisticated optimal strategies + // NOTE: for match cases, there may be more sophisticated optimal strategies + } enum FulfillAvailableStrategy { @@ -42,6 +43,7 @@ enum FulfillAvailableStrategy { DROP_SINGLE_KEEP_FILTERED, // Exclude single unless it would be filtered DROP_ALL_KEEP_FILTERED, // Exclude all unfilterable offer aggregations DROP_RANDOM_KEEP_FILTERED // Exclude random, unfilterable offer aggregations + } enum MatchStrategy { @@ -53,7 +55,8 @@ enum MatchStrategy { MAX_EXECUTIONS, // use as many fulfillments as possible given aggregations MIN_EXECUTIONS, // use as few fulfillments as possible given aggregations MIN_EXECUTIONS_MAX_FILTERS // minimize fulfillments and prioritize filters - // NOTE: more sophisticated match strategies require modifying aggregations + // NOTE: more sophisticated match strategies require modifying aggregations + } enum ItemCategory { @@ -115,12 +118,11 @@ library DefaultFulfillmentGeneratorLib { pure returns (FulfillmentStrategy memory) { - return - FulfillmentStrategy({ - aggregationStrategy: AggregationStrategy.MAXIMUM, - fulfillAvailableStrategy: FulfillAvailableStrategy.KEEP_ALL, - matchStrategy: MatchStrategy.MAX_INCLUSION - }); + return FulfillmentStrategy({ + aggregationStrategy: AggregationStrategy.MAXIMUM, + fulfillAvailableStrategy: FulfillAvailableStrategy.KEEP_ALL, + matchStrategy: MatchStrategy.MAX_INCLUSION + }); } // This uses the "default" set of strategies and applies no randomization. @@ -142,21 +144,18 @@ library DefaultFulfillmentGeneratorLib { { uint256 seed = 0; - return - FulfillmentGeneratorLib.getFulfillments( - orderDetails, - getDefaultFulfillmentStrategy(), - recipient, - caller, - seed - ); + return FulfillmentGeneratorLib.getFulfillments( + orderDetails, + getDefaultFulfillmentStrategy(), + recipient, + caller, + seed + ); } // This uses the "default" set of strategies, applies no randomization, and // does not give a recipient & will not properly detect filtered executions. - function getMatchedFulfillments( - OrderDetails[] memory orderDetails - ) + function getMatchedFulfillments(OrderDetails[] memory orderDetails) internal pure returns ( @@ -165,18 +164,15 @@ library DefaultFulfillmentGeneratorLib { MatchComponent[] memory unmetConsiderationComponents ) { - return - getMatchFulfillments( - orderDetails.getItemReferences(0).getMatchDetailsFromReferences( - address(0) - ) - ); + return getMatchFulfillments( + orderDetails.getItemReferences(0).getMatchDetailsFromReferences( + address(0) + ) + ); } // This uses the "default" set of strategies and applies no randomization. - function getMatchFulfillments( - MatchDetails memory matchDetails - ) + function getMatchFulfillments(MatchDetails memory matchDetails) internal pure returns ( @@ -187,12 +183,9 @@ library DefaultFulfillmentGeneratorLib { { uint256 seed = 0; - return - FulfillmentGeneratorLib.getMatchFulfillments( - matchDetails, - getDefaultFulfillmentStrategy(), - seed - ); + return FulfillmentGeneratorLib.getMatchFulfillments( + matchDetails, getDefaultFulfillmentStrategy(), seed + ); } } @@ -240,21 +233,17 @@ library FulfillmentGeneratorLib { MatchComponent[] memory unmetConsiderationComponents ) { - ItemReferenceLib.ItemReference[] memory references = orderDetails - .getItemReferences(seed); + ItemReferenceLib.ItemReference[] memory references = + orderDetails.getItemReferences(seed); ( FulfillAvailableDetails memory fulfillAvailableDetails, MatchDetails memory matchDetails ) = references.getDetails(recipient, caller); - return - getFulfillmentsFromDetails( - fulfillAvailableDetails, - matchDetails, - strategy, - seed - ); + return getFulfillmentsFromDetails( + fulfillAvailableDetails, matchDetails, strategy, seed + ); } function getFulfillmentsFromDetails( @@ -276,35 +265,28 @@ library FulfillmentGeneratorLib { { assertSupportedStrategy(strategy); - ( - fulfillments, - unspentOfferComponents, - unmetConsiderationComponents - ) = getMatchFulfillments(matchDetails, strategy, seed); + (fulfillments, unspentOfferComponents, unmetConsiderationComponents) = + getMatchFulfillments(matchDetails, strategy, seed); eligibility = determineEligibility( - fulfillAvailableDetails, - unmetConsiderationComponents.length + fulfillAvailableDetails, unmetConsiderationComponents.length ); if ( - eligibility == FulfillmentEligibility.FULFILL_AVAILABLE || - eligibility == FulfillmentEligibility.BOTH + eligibility == FulfillmentEligibility.FULFILL_AVAILABLE + || eligibility == FulfillmentEligibility.BOTH ) { - ( - offerFulfillments, - considerationFulfillments - ) = getFulfillAvailableFulfillments( - fulfillAvailableDetails, - strategy, - seed + (offerFulfillments, considerationFulfillments) = + getFulfillAvailableFulfillments( + fulfillAvailableDetails, strategy, seed ); } } - function assertSupportedStrategy( - FulfillmentStrategy memory strategy - ) internal pure { + function assertSupportedStrategy(FulfillmentStrategy memory strategy) + internal + pure + { // TODO: add more strategies here as support is added for them. if (uint256(strategy.fulfillAvailableStrategy) > 3) { revert UnsupportedFulfillAvailableStrategy(); @@ -325,25 +307,22 @@ library FulfillmentGeneratorLib { // There must also be at least one unfiltered explicit execution. Note // that it is also *very* tricky to use FulfillAvailable in cases where // ERC721 items are present on both the offer side & consideration side. - bool eligibleForFulfillAvailable = determineFulfillAvailableEligibility( - fulfillAvailableDetails - ); + bool eligibleForFulfillAvailable = + determineFulfillAvailableEligibility(fulfillAvailableDetails); // Match: cannot be used if there is no way to meet each consideration // item. In these cases, remaining offer components should be returned. bool eligibleForMatch = totalUnmetConsiderationComponents == 0; if (eligibleForFulfillAvailable) { - return - eligibleForMatch - ? FulfillmentEligibility.BOTH - : FulfillmentEligibility.FULFILL_AVAILABLE; + return eligibleForMatch + ? FulfillmentEligibility.BOTH + : FulfillmentEligibility.FULFILL_AVAILABLE; } - return - eligibleForMatch - ? FulfillmentEligibility.MATCH - : FulfillmentEligibility.NONE; + return eligibleForMatch + ? FulfillmentEligibility.MATCH + : FulfillmentEligibility.NONE; } // This does not give a recipient & so will not detect filtered executions. @@ -360,14 +339,13 @@ library FulfillmentGeneratorLib { MatchComponent[] memory unmetConsiderationComponents ) { - return - getMatchFulfillments( - orderDetails.getItemReferences(0).getMatchDetailsFromReferences( - address(0) - ), - strategy, - seed - ); + return getMatchFulfillments( + orderDetails.getItemReferences(0).getMatchDetailsFromReferences( + address(0) + ), + strategy, + seed + ); } function getMatchDetails( @@ -384,14 +362,13 @@ library FulfillmentGeneratorLib { MatchComponent[] memory unmetConsiderationComponents ) { - return - getMatchFulfillments( - orderDetails - .getItemReferences(seed) - .getMatchDetailsFromReferences(recipient), - strategy, - seed - ); + return getMatchFulfillments( + orderDetails.getItemReferences(seed).getMatchDetailsFromReferences( + recipient + ), + strategy, + seed + ); } function getMatchFulfillments( @@ -410,11 +387,8 @@ library FulfillmentGeneratorLib { MatchStrategy matchStrategy = strategy.matchStrategy; if (matchStrategy == MatchStrategy.MAX_INCLUSION) { - ( - fulfillments, - unspentOfferComponents, - unmetConsiderationComponents - ) = getMatchFulfillmentsUsingConsumeMethod( + (fulfillments, unspentOfferComponents, unmetConsiderationComponents) + = getMatchFulfillmentsUsingConsumeMethod( matchDetails, getMaxInclusionConsumeMethod(strategy.aggregationStrategy), seed @@ -431,9 +405,9 @@ library FulfillmentGeneratorLib { pure returns ( function(FulfillmentItems memory, FulfillmentItems memory, uint256) - internal - pure - returns (Fulfillment memory) + internal + pure + returns (Fulfillment memory) ) { if (aggregationStrategy == AggregationStrategy.MAXIMUM) { @@ -470,9 +444,7 @@ library FulfillmentGeneratorLib { } } - function getUncoveredComponents( - MatchDetails memory matchDetails - ) + function getUncoveredComponents(MatchDetails memory matchDetails) internal pure returns ( @@ -485,13 +457,11 @@ library FulfillmentGeneratorLib { uint256 totalUnmetConsiderationComponents ) = getTotalUncoveredComponents(matchDetails.context); - unspentOfferComponents = ( - new MatchComponent[](totalUnspentOfferComponents) - ); + unspentOfferComponents = + (new MatchComponent[](totalUnspentOfferComponents)); - unmetConsiderationComponents = ( - new MatchComponent[](totalUnmetConsiderationComponents) - ); + unmetConsiderationComponents = + (new MatchComponent[](totalUnmetConsiderationComponents)); if ( totalUnspentOfferComponents + totalUnmetConsiderationComponents == 0 @@ -503,19 +473,18 @@ library FulfillmentGeneratorLib { totalUnmetConsiderationComponents = 0; for (uint256 i = 0; i < matchDetails.items.length; ++i) { - DualFulfillmentMatchContext memory context = ( - matchDetails.context[i] - ); + DualFulfillmentMatchContext memory context = + (matchDetails.context[i]); FulfillmentItems[] memory offer = matchDetails.items[i].offer; - FulfillmentItems[] memory consideration = ( - matchDetails.items[i].consideration - ); + FulfillmentItems[] memory consideration = + (matchDetails.items[i].consideration); if (context.totalConsiderationAmount > context.totalOfferAmount) { - uint256 amount = (context.totalConsiderationAmount - - context.totalOfferAmount); + uint256 amount = ( + context.totalConsiderationAmount - context.totalOfferAmount + ); if (consideration.length == 0) { revert EmptyConsiderationArray(); @@ -528,15 +497,14 @@ library FulfillmentGeneratorLib { FulfillmentItem memory item = consideration[0].items[0]; if ( - item.orderIndex > type(uint8).max || - item.itemIndex > type(uint8).max + item.orderIndex > type(uint8).max + || item.itemIndex > type(uint8).max ) { revert OutOfRangeConsiderationItemIndex(); } - unmetConsiderationComponents[ - totalUnmetConsiderationComponents++ - ] = MatchComponent({ + unmetConsiderationComponents[totalUnmetConsiderationComponents++] + = MatchComponent({ amount: amount, orderIndex: uint8(item.orderIndex), itemIndex: uint8(item.itemIndex) @@ -544,8 +512,9 @@ library FulfillmentGeneratorLib { } else if ( context.totalConsiderationAmount < context.totalOfferAmount ) { - uint256 amount = (context.totalOfferAmount - - context.totalConsiderationAmount); + uint256 amount = ( + context.totalOfferAmount - context.totalConsiderationAmount + ); if (offer.length == 0) { revert EmptyOfferArray(); @@ -558,15 +527,14 @@ library FulfillmentGeneratorLib { FulfillmentItem memory item = offer[0].items[0]; if ( - item.orderIndex > type(uint8).max || - item.itemIndex > type(uint8).max + item.orderIndex > type(uint8).max + || item.itemIndex > type(uint8).max ) { revert OutOfRangeOfferItemIndex(); } - unspentOfferComponents[ - totalUnspentOfferComponents++ - ] = MatchComponent({ + unspentOfferComponents[totalUnspentOfferComponents++] = + MatchComponent({ amount: amount, orderIndex: uint8(item.orderIndex), itemIndex: uint8(item.itemIndex) @@ -580,8 +548,8 @@ library FulfillmentGeneratorLib { } if ( - unmetConsiderationComponents.length != - totalUnmetConsiderationComponents + unmetConsiderationComponents.length + != totalUnmetConsiderationComponents ) { revert UnmetMatchItemAssignmentError(); } @@ -623,10 +591,8 @@ library FulfillmentGeneratorLib { ); } - ( - unspentOfferComponents, - unmetConsiderationComponents - ) = getUncoveredComponents(matchDetails); + (unspentOfferComponents, unmetConsiderationComponents) = + getUncoveredComponents(matchDetails); // Allocate based on max possible fulfillments; reduce after assignment. fulfillments = new Fulfillment[](matchDetails.totalItems - 1); @@ -637,11 +603,8 @@ library FulfillmentGeneratorLib { // This is actually a "while" loop, but bound it as a sanity check. bool allProcessed = false; for (uint256 j = 0; j < matchDetails.totalItems; ++j) { - Fulfillment memory fulfillment = consumeItems( - matchDetails.items[i], - consumeMethod, - seed - ); + Fulfillment memory fulfillment = + consumeItems(matchDetails.items[i], consumeMethod, seed); // Exit the inner loop if no fulfillment was located. if (fulfillment.offerComponents.length == 0) { @@ -678,9 +641,8 @@ library FulfillmentGeneratorLib { if (offerItems.totalAmount != 0) { // Search for something it can be matched against. for (uint256 j = 0; j < matchItems.consideration.length; ++j) { - FulfillmentItems memory considerationItems = ( - matchItems.consideration[j] - ); + FulfillmentItems memory considerationItems = + (matchItems.consideration[j]); if (considerationItems.totalAmount != 0) { return @@ -699,19 +661,16 @@ library FulfillmentGeneratorLib { FulfillmentItems memory considerationItems, uint256 /* seed */ ) internal pure returns (Fulfillment memory) { - if ( - offerItems.totalAmount == 0 || considerationItems.totalAmount == 0 - ) { + if (offerItems.totalAmount == 0 || considerationItems.totalAmount == 0) + { revert MissingItemAmountsToConsume(); } // Allocate fulfillment component arrays with a single element. - FulfillmentComponent[] memory offerComponents = ( - new FulfillmentComponent[](1) - ); - FulfillmentComponent[] memory considerationComponents = ( - new FulfillmentComponent[](1) - ); + FulfillmentComponent[] memory offerComponents = + (new FulfillmentComponent[](1)); + FulfillmentComponent[] memory considerationComponents = + (new FulfillmentComponent[](1)); FulfillmentItem memory offerItem; for (uint256 i = 0; i < offerItems.items.length; ++i) { @@ -746,11 +705,10 @@ library FulfillmentGeneratorLib { considerationItem.amount = 0; } - return - Fulfillment({ - offerComponents: offerComponents, - considerationComponents: considerationComponents - }); + return Fulfillment({ + offerComponents: offerComponents, + considerationComponents: considerationComponents + }); } function consumeMaximumItemsAndGetFulfillment( @@ -758,25 +716,22 @@ library FulfillmentGeneratorLib { FulfillmentItems memory considerationItems, uint256 /* seed */ ) internal pure returns (Fulfillment memory) { - if ( - offerItems.totalAmount == 0 || considerationItems.totalAmount == 0 - ) { + if (offerItems.totalAmount == 0 || considerationItems.totalAmount == 0) + { revert MissingItemAmountsToConsume(); } // Allocate fulfillment component arrays using total items; reduce // length after based on the total number of elements assigned to each. - FulfillmentComponent[] memory offerComponents = ( - new FulfillmentComponent[](offerItems.items.length) - ); - FulfillmentComponent[] memory considerationComponents = ( - new FulfillmentComponent[](considerationItems.items.length) - ); + FulfillmentComponent[] memory offerComponents = + (new FulfillmentComponent[](offerItems.items.length)); + FulfillmentComponent[] memory considerationComponents = + (new FulfillmentComponent[](considerationItems.items.length)); uint256 assignmentIndex = 0; - uint256 amountToConsume = offerItems.totalAmount > - considerationItems.totalAmount + uint256 amountToConsume = offerItems.totalAmount + > considerationItems.totalAmount ? considerationItems.totalAmount : offerItems.totalAmount; @@ -793,18 +748,16 @@ library FulfillmentGeneratorLib { firstConsumedItemIndex = i; } - offerComponents[assignmentIndex++] = getFulfillmentComponent( - item - ); + offerComponents[assignmentIndex++] = + getFulfillmentComponent(item); if (item.amount >= amountToConsume) { uint256 amountToAddBack = item.amount - amountToConsume; item.amount = 0; - offerItems.items[firstConsumedItemIndex].amount += ( - amountToAddBack - ); + offerItems.items[firstConsumedItemIndex].amount += + (amountToAddBack); offerItems.totalAmount -= amountToConsume; @@ -840,18 +793,16 @@ library FulfillmentGeneratorLib { firstConsumedItemIndex = i; } - considerationComponents[assignmentIndex++] = ( - getFulfillmentComponent(item) - ); + considerationComponents[assignmentIndex++] = + (getFulfillmentComponent(item)); if (item.amount >= amountToCredit) { uint256 amountToAddBack = item.amount - amountToCredit; item.amount = 0; - considerationItems.items[firstConsumedItemIndex].amount += ( - amountToAddBack - ); + considerationItems.items[firstConsumedItemIndex].amount += + (amountToAddBack); considerationItems.totalAmount -= amountToCredit; @@ -877,17 +828,15 @@ library FulfillmentGeneratorLib { } // Sanity check - if ( - offerComponents.length == 0 || considerationComponents.length == 0 - ) { + if (offerComponents.length == 0 || considerationComponents.length == 0) + { revert EmptyMatchComponentGenerated(); } - return - Fulfillment({ - offerComponents: offerComponents, - considerationComponents: considerationComponents - }); + return Fulfillment({ + offerComponents: offerComponents, + considerationComponents: considerationComponents + }); } function consumeRandomItemsAndGetFulfillment( @@ -895,28 +844,23 @@ library FulfillmentGeneratorLib { FulfillmentItems memory considerationItems, uint256 seed ) internal pure returns (Fulfillment memory) { - if ( - offerItems.totalAmount == 0 || considerationItems.totalAmount == 0 - ) { + if (offerItems.totalAmount == 0 || considerationItems.totalAmount == 0) + { revert MissingItemAmountsToConsume(); } // Allocate fulfillment component arrays using total items; reduce // length after based on the total number of elements assigned to each. - FulfillmentComponent[] memory offerComponents = ( - new FulfillmentComponent[](offerItems.items.length) - ); + FulfillmentComponent[] memory offerComponents = + (new FulfillmentComponent[](offerItems.items.length)); - FulfillmentComponent[] memory considerationComponents = ( - new FulfillmentComponent[](considerationItems.items.length) - ); + FulfillmentComponent[] memory considerationComponents = + (new FulfillmentComponent[](considerationItems.items.length)); - uint256[] memory consumableOfferIndices = new uint256[]( - offerItems.items.length - ); - uint256[] memory consumableConsiderationIndices = new uint256[]( - considerationItems.items.length - ); + uint256[] memory consumableOfferIndices = + new uint256[](offerItems.items.length); + uint256[] memory consumableConsiderationIndices = + new uint256[](considerationItems.items.length); { uint256 assignmentIndex = 0; @@ -947,8 +891,8 @@ library FulfillmentGeneratorLib { // Sanity check if ( - consumableOfferIndices.length == 0 || - consumableConsiderationIndices.length == 0 + consumableOfferIndices.length == 0 + || consumableConsiderationIndices.length == 0 ) { revert DidNotFindConsumableItems(); } @@ -966,8 +910,7 @@ library FulfillmentGeneratorLib { } assignmentIndex = - prng.uniform(consumableConsiderationIndices.length) + - 1; + prng.uniform(consumableConsiderationIndices.length) + 1; assembly { mstore(considerationComponents, assignmentIndex) mstore(consumableConsiderationIndices, assignmentIndex) @@ -978,9 +921,8 @@ library FulfillmentGeneratorLib { uint256 totalConsiderationAmount = 0; for (uint256 i = 0; i < consumableOfferIndices.length; ++i) { - FulfillmentItem memory item = offerItems.items[ - consumableOfferIndices[i] - ]; + FulfillmentItem memory item = + offerItems.items[consumableOfferIndices[i]]; offerComponents[i] = getFulfillmentComponent(item); @@ -989,9 +931,8 @@ library FulfillmentGeneratorLib { } for (uint256 i = 0; i < consumableConsiderationIndices.length; ++i) { - FulfillmentItem memory item = considerationItems.items[ - consumableConsiderationIndices[i] - ]; + FulfillmentItem memory item = + considerationItems.items[consumableConsiderationIndices[i]]; considerationComponents[i] = getFulfillmentComponent(item); @@ -1000,43 +941,39 @@ library FulfillmentGeneratorLib { } if (totalOfferAmount > totalConsiderationAmount) { - uint256 remainingAmount = (totalOfferAmount - - totalConsiderationAmount); + uint256 remainingAmount = + (totalOfferAmount - totalConsiderationAmount); // add back excess to first offer item - offerItems.items[consumableOfferIndices[0]].amount += ( - remainingAmount - ); + offerItems.items[consumableOfferIndices[0]].amount += + (remainingAmount); offerItems.totalAmount -= totalConsiderationAmount; considerationItems.totalAmount -= totalConsiderationAmount; } else { - uint256 remainingAmount = (totalConsiderationAmount - - totalOfferAmount); + uint256 remainingAmount = + (totalConsiderationAmount - totalOfferAmount); // add back excess to first consideration item - considerationItems - .items[consumableConsiderationIndices[0]] - .amount += remainingAmount; + considerationItems.items[consumableConsiderationIndices[0]].amount + += remainingAmount; offerItems.totalAmount -= totalOfferAmount; considerationItems.totalAmount -= totalOfferAmount; } - return - Fulfillment({ - offerComponents: offerComponents, - considerationComponents: considerationComponents - }); + return Fulfillment({ + offerComponents: offerComponents, + considerationComponents: considerationComponents + }); } function emptyFulfillment() internal pure returns (Fulfillment memory) { FulfillmentComponent[] memory components; - return - Fulfillment({ - offerComponents: components, - considerationComponents: components - }); + return Fulfillment({ + offerComponents: components, + considerationComponents: components + }); } function getFulfillAvailableFulfillments( @@ -1052,20 +989,15 @@ library FulfillmentGeneratorLib { ) { ItemCategory[] memory offerCategories; - ( - offerFulfillments, - offerCategories, - considerationFulfillments, - - ) = getFulfillmentComponentsUsingMethod( + (offerFulfillments, offerCategories, considerationFulfillments,) = + getFulfillmentComponentsUsingMethod( fulfillAvailableDetails, getFulfillmentMethod(strategy.aggregationStrategy), seed ); - FulfillAvailableStrategy dropStrategy = ( - strategy.fulfillAvailableStrategy - ); + FulfillAvailableStrategy dropStrategy = + (strategy.fulfillAvailableStrategy); if (dropStrategy == FulfillAvailableStrategy.KEEP_ALL) { return (offerFulfillments, considerationFulfillments); @@ -1092,9 +1024,8 @@ library FulfillmentGeneratorLib { ); } - if ( - dropStrategy == FulfillAvailableStrategy.DROP_SINGLE_KEEP_FILTERED - ) { + if (dropStrategy == FulfillAvailableStrategy.DROP_SINGLE_KEEP_FILTERED) + { revert StrategyUnsupported(); } @@ -1102,9 +1033,8 @@ library FulfillmentGeneratorLib { revert StrategyUnsupported(); } - if ( - dropStrategy == FulfillAvailableStrategy.DROP_RANDOM_KEEP_FILTERED - ) { + if (dropStrategy == FulfillAvailableStrategy.DROP_RANDOM_KEEP_FILTERED) + { revert StrategyUnsupported(); } @@ -1115,17 +1045,16 @@ library FulfillmentGeneratorLib { FulfillmentComponent[][] memory offerFulfillments, ItemCategory[] memory offerCategories ) internal pure returns (FulfillmentComponent[][] memory) { - FulfillmentComponent[][] memory fulfillments = ( - new FulfillmentComponent[][](offerFulfillments.length) - ); + FulfillmentComponent[][] memory fulfillments = + (new FulfillmentComponent[][](offerFulfillments.length)); uint256 assignmentIndex = 0; for (uint256 i = 0; i < offerFulfillments.length; ++i) { FulfillmentComponent[] memory components = offerFulfillments[i]; if ( - offerCategories[i] == ItemCategory.ERC721 || - components.length > 1 + offerCategories[i] == ItemCategory.ERC721 + || components.length > 1 ) { fulfillments[assignmentIndex++] = components; } @@ -1142,9 +1071,8 @@ library FulfillmentGeneratorLib { FulfillmentComponent[][] memory offerFulfillments, ItemCategory[] memory offerCategories ) internal pure returns (FulfillmentComponent[][] memory) { - FulfillmentComponent[][] memory fulfillments = ( - new FulfillmentComponent[][](offerFulfillments.length) - ); + FulfillmentComponent[][] memory fulfillments = + (new FulfillmentComponent[][](offerFulfillments.length)); uint256 assignmentIndex = 0; @@ -1170,17 +1098,16 @@ library FulfillmentGeneratorLib { LibPRNG.PRNG memory prng; prng.seed(seed ^ 0xbb); - FulfillmentComponent[][] memory fulfillments = ( - new FulfillmentComponent[][](offerFulfillments.length) - ); + FulfillmentComponent[][] memory fulfillments = + (new FulfillmentComponent[][](offerFulfillments.length)); uint256 assignmentIndex = 0; for (uint256 i = 0; i < offerFulfillments.length; ++i) { FulfillmentComponent[] memory components = offerFulfillments[i]; if ( - offerCategories[i] == ItemCategory.ERC721 || - prng.uniform(2) == 0 + offerCategories[i] == ItemCategory.ERC721 + || prng.uniform(2) == 0 ) { fulfillments[assignmentIndex++] = components; } @@ -1193,16 +1120,14 @@ library FulfillmentGeneratorLib { return fulfillments; } - function getFulfillmentMethod( - AggregationStrategy aggregationStrategy - ) + function getFulfillmentMethod(AggregationStrategy aggregationStrategy) internal pure returns ( function(FulfillmentItems[] memory, uint256) - internal - pure - returns (FulfillmentComponent[][] memory, ItemCategory[] memory) + internal + pure + returns (FulfillmentComponent[][] memory, ItemCategory[] memory) ) { if (aggregationStrategy == AggregationStrategy.MAXIMUM) { @@ -1236,18 +1161,11 @@ library FulfillmentGeneratorLib { ItemCategory[] memory considerationCategories ) { - (offerFulfillments, offerCategories) = fulfillmentMethod( - fulfillAvailableDetails.items.offer, - seed - ); + (offerFulfillments, offerCategories) = + fulfillmentMethod(fulfillAvailableDetails.items.offer, seed); - ( - considerationFulfillments, - considerationCategories - ) = fulfillmentMethod( - fulfillAvailableDetails.items.consideration, - seed - ); + (considerationFulfillments, considerationCategories) = + fulfillmentMethod(fulfillAvailableDetails.items.consideration, seed); } function getMaxFulfillmentComponents( @@ -1258,18 +1176,15 @@ library FulfillmentGeneratorLib { pure returns (FulfillmentComponent[][] memory, ItemCategory[] memory) { - FulfillmentComponent[][] memory fulfillments = ( - new FulfillmentComponent[][](fulfillmentItems.length) - ); + FulfillmentComponent[][] memory fulfillments = + (new FulfillmentComponent[][](fulfillmentItems.length)); - ItemCategory[] memory categories = new ItemCategory[]( - fulfillmentItems.length - ); + ItemCategory[] memory categories = + new ItemCategory[](fulfillmentItems.length); for (uint256 i = 0; i < fulfillmentItems.length; ++i) { - fulfillments[i] = getFulfillmentComponents( - fulfillmentItems[i].items - ); + fulfillments[i] = + getFulfillmentComponents(fulfillmentItems[i].items); categories[i] = fulfillmentItems[i].itemCategory; } @@ -1290,9 +1205,8 @@ library FulfillmentGeneratorLib { fulfillmentCount += fulfillmentItems[i].items.length; } - FulfillmentComponent[][] memory fulfillments = ( - new FulfillmentComponent[][](fulfillmentCount) - ); + FulfillmentComponent[][] memory fulfillments = + (new FulfillmentComponent[][](fulfillmentCount)); ItemCategory[] memory categories = new ItemCategory[](fulfillmentCount); @@ -1304,9 +1218,8 @@ library FulfillmentGeneratorLib { FulfillmentItem[] memory items = fulfillmentItems[i].items; for (uint256 j = 0; j < items.length; ++j) { - FulfillmentComponent[] memory fulfillment = ( - consumeRandomFulfillmentItems(items, prng) - ); + FulfillmentComponent[] memory fulfillment = + (consumeRandomFulfillmentItems(items, prng)); if (fulfillment.length == 0) { break; @@ -1329,13 +1242,11 @@ library FulfillmentGeneratorLib { prng.shuffle(componentIndices); - FulfillmentComponent[][] memory shuffledFulfillments = ( - new FulfillmentComponent[][](fulfillments.length) - ); + FulfillmentComponent[][] memory shuffledFulfillments = + (new FulfillmentComponent[][](fulfillments.length)); - ItemCategory[] memory shuffledCategories = ( - new ItemCategory[](fulfillments.length) - ); + ItemCategory[] memory shuffledCategories = + (new ItemCategory[](fulfillments.length)); for (uint256 i = 0; i < fulfillments.length; ++i) { uint256 priorIndex = componentIndices[i]; @@ -1374,9 +1285,8 @@ library FulfillmentGeneratorLib { mstore(consumableItemIndices, assignmentIndex) } - FulfillmentComponent[] memory fulfillment = new FulfillmentComponent[]( - consumableItemIndices.length - ); + FulfillmentComponent[] memory fulfillment = + new FulfillmentComponent[](consumableItemIndices.length); for (uint256 i = 0; i < consumableItemIndices.length; ++i) { FulfillmentItem memory item = items[consumableItemIndices[i]]; @@ -1403,22 +1313,19 @@ library FulfillmentGeneratorLib { fulfillmentCount += fulfillmentItems[i].items.length; } - FulfillmentComponent[][] memory fulfillments = ( - new FulfillmentComponent[][](fulfillmentCount) - ); + FulfillmentComponent[][] memory fulfillments = + (new FulfillmentComponent[][](fulfillmentCount)); - ItemCategory[] memory categories = ( - new ItemCategory[](fulfillmentCount) - ); + ItemCategory[] memory categories = + (new ItemCategory[](fulfillmentCount)); fulfillmentCount = 0; for (uint256 i = 0; i < fulfillmentItems.length; ++i) { FulfillmentItem[] memory items = fulfillmentItems[i].items; for (uint256 j = 0; j < items.length; ++j) { - FulfillmentComponent[] memory fulfillment = ( - new FulfillmentComponent[](1) - ); + FulfillmentComponent[] memory fulfillment = + (new FulfillmentComponent[](1)); fulfillment[0] = getFulfillmentComponent(items[j]); categories[fulfillmentCount] = fulfillmentItems[i].itemCategory; fulfillments[fulfillmentCount++] = fulfillment; @@ -1428,12 +1335,13 @@ library FulfillmentGeneratorLib { return (fulfillments, categories); } - function getFulfillmentComponents( - FulfillmentItem[] memory items - ) internal pure returns (FulfillmentComponent[] memory) { - FulfillmentComponent[] memory fulfillment = new FulfillmentComponent[]( - items.length - ); + function getFulfillmentComponents(FulfillmentItem[] memory items) + internal + pure + returns (FulfillmentComponent[] memory) + { + FulfillmentComponent[] memory fulfillment = + new FulfillmentComponent[](items.length); for (uint256 i = 0; i < items.length; ++i) { fulfillment[i] = getFulfillmentComponent(items[i]); @@ -1442,14 +1350,15 @@ library FulfillmentGeneratorLib { return fulfillment; } - function getFulfillmentComponent( - FulfillmentItem memory item - ) internal pure returns (FulfillmentComponent memory) { - return - FulfillmentComponent({ - orderIndex: item.orderIndex, - itemIndex: item.itemIndex - }); + function getFulfillmentComponent(FulfillmentItem memory item) + internal + pure + returns (FulfillmentComponent memory) + { + return FulfillmentComponent({ + orderIndex: item.orderIndex, + itemIndex: item.itemIndex + }); } function determineFulfillAvailableEligibility( @@ -1461,9 +1370,11 @@ library FulfillmentGeneratorLib { for (uint256 i = 0; i < offer.length; ++i) { FulfillmentItems memory fulfillmentItems = offer[i]; if ( - fulfillmentItems.itemCategory == ItemCategory.NATIVE || - (fulfillmentItems.itemCategory == ItemCategory.ERC721 && - fulfillmentItems.totalAmount != 1) + fulfillmentItems.itemCategory == ItemCategory.NATIVE + || ( + fulfillmentItems.itemCategory == ItemCategory.ERC721 + && fulfillmentItems.totalAmount != 1 + ) ) { return false; } @@ -1483,14 +1394,13 @@ library FulfillmentGeneratorLib { } } - FulfillmentItems[] memory consideration = ( - fulfillAvailableDetails.items.consideration - ); + FulfillmentItems[] memory consideration = + (fulfillAvailableDetails.items.consideration); for (uint256 i = 0; i < consideration.length; ++i) { FulfillmentItems memory fulfillmentItems = consideration[i]; if ( - fulfillmentItems.itemCategory == ItemCategory.ERC721 && - fulfillmentItems.totalAmount != 1 + fulfillmentItems.itemCategory == ItemCategory.ERC721 + && fulfillmentItems.totalAmount != 1 ) { return false; } @@ -1514,8 +1424,12 @@ library FulfillmentPrepLib { using ItemReferenceLib for OrderDetails[]; using ItemReferenceGroupLib for ItemReferenceLib.ItemReference[]; using ItemReferenceGroupLib for ItemReferenceGroupLib.ItemReferenceGroup[]; - using MatchableItemReferenceGroupLib for MatchableItemReferenceGroupLib.MatchableItemReferenceGroup[]; - using FulfillAvailableReferenceGroupLib for FulfillAvailableReferenceGroupLib.FulfillAvailableReferenceGroup; + using + MatchableItemReferenceGroupLib + for MatchableItemReferenceGroupLib.MatchableItemReferenceGroup[]; + using + FulfillAvailableReferenceGroupLib + for FulfillAvailableReferenceGroupLib.FulfillAvailableReferenceGroup; error MismatchedItemCategories(); error EmptyItemReferencesSupplied(); @@ -1526,12 +1440,9 @@ library FulfillmentPrepLib { address caller, uint256 seed ) internal pure returns (FulfillAvailableDetails memory) { - return - getFulfillAvailableDetailsFromReferences( - orderDetails.getItemReferences(seed), - recipient, - caller - ); + return getFulfillAvailableDetailsFromReferences( + orderDetails.getItemReferences(seed), recipient, caller + ); } function getDetails( @@ -1543,8 +1454,8 @@ library FulfillmentPrepLib { pure returns (FulfillAvailableDetails memory, MatchDetails memory) { - ItemReferenceGroupLib.ItemReferenceGroup[] - memory groups = itemReferences.bundleByAggregatable(); + ItemReferenceGroupLib.ItemReferenceGroup[] memory groups = + itemReferences.bundleByAggregatable(); return ( groups.splitBySide(recipient, caller).getFulfillAvailableDetails(), @@ -1557,11 +1468,9 @@ library FulfillmentPrepLib { address recipient, address caller ) internal pure returns (FulfillAvailableDetails memory) { - return - itemReferences - .bundleByAggregatable() - .splitBySide(recipient, caller) - .getFulfillAvailableDetails(); + return itemReferences.bundleByAggregatable().splitBySide( + recipient, caller + ).getFulfillAvailableDetails(); } function getMatchDetails( @@ -1569,30 +1478,25 @@ library FulfillmentPrepLib { address recipient, uint256 seed ) internal pure returns (MatchDetails memory) { - return - getMatchDetailsFromReferences( - orderDetails.getItemReferences(seed), - recipient - ); + return getMatchDetailsFromReferences( + orderDetails.getItemReferences(seed), recipient + ); } function getMatchDetailsFromReferences( ItemReferenceLib.ItemReference[] memory itemReferences, address recipient ) internal pure returns (MatchDetails memory) { - return + return itemReferences.bundleByAggregatable().bundleByMatchable( itemReferences - .bundleByAggregatable() - .bundleByMatchable(itemReferences) - .getMatchDetails(recipient); + ).getMatchDetails(recipient); } function getFulfillmentMatchContext( DualFulfillmentItems[] memory matchItems ) internal pure returns (DualFulfillmentMatchContext[] memory) { - DualFulfillmentMatchContext[] memory context = ( - new DualFulfillmentMatchContext[](matchItems.length) - ); + DualFulfillmentMatchContext[] memory context = + (new DualFulfillmentMatchContext[](matchItems.length)); for (uint256 i = 0; i < matchItems.length; ++i) { bool itemCategorySet = false; @@ -1613,9 +1517,8 @@ library FulfillmentPrepLib { totalOfferAmount += items.totalAmount; } - FulfillmentItems[] memory consideration = ( - matchItems[i].consideration - ); + FulfillmentItems[] memory consideration = + (matchItems[i].consideration); for (uint256 j = 0; j < consideration.length; ++j) { FulfillmentItems memory items = consideration[j]; @@ -1650,17 +1553,15 @@ library FulfillmentPrepLib { uint256 currentItems; for (uint256 i = 0; i < offerGroups.length; ++i) { - (items.offer[i], currentItems) = getFulfillmentItems( - offerGroups[i].references - ); + (items.offer[i], currentItems) = + getFulfillmentItems(offerGroups[i].references); totalItems += currentItems; } for (uint256 i = 0; i < considerationGroups.length; ++i) { - (items.consideration[i], currentItems) = getFulfillmentItems( - considerationGroups[i].references - ); + (items.consideration[i], currentItems) = + getFulfillmentItems(considerationGroups[i].references); totalItems += currentItems; } @@ -1676,9 +1577,7 @@ library FulfillmentPrepLib { revert EmptyItemReferencesSupplied(); } - ItemReferenceLib.ItemReference memory firstReference = itemReferences[ - 0 - ]; + ItemReferenceLib.ItemReference memory firstReference = itemReferences[0]; FulfillmentItems memory fulfillmentItems = FulfillmentItems({ itemCategory: firstReference.itemCategory, totalAmount: 0, @@ -1686,8 +1585,8 @@ library FulfillmentPrepLib { }); for (uint256 i = 0; i < itemReferences.length; ++i) { - ItemReferenceLib.ItemReference - memory itemReference = itemReferences[i]; + ItemReferenceLib.ItemReference memory itemReference = + itemReferences[i]; uint256 amount = itemReference.amount; fulfillmentItems.totalAmount += amount; fulfillmentItems.items[i] = FulfillmentItem({ @@ -1715,21 +1614,17 @@ library FulfillAvailableReferenceGroupLib { function getFulfillAvailableDetails( FulfillAvailableReferenceGroup memory group ) internal pure returns (FulfillAvailableDetails memory) { - ( - DualFulfillmentItems memory items, - uint256 totalItems - ) = FulfillmentPrepLib.getDualFulfillmentItems( - group.offerGroups, - group.considerationGroups - ); + (DualFulfillmentItems memory items, uint256 totalItems) = + FulfillmentPrepLib.getDualFulfillmentItems( + group.offerGroups, group.considerationGroups + ); - return - FulfillAvailableDetails({ - items: items, - caller: group.caller, - recipient: group.recipient, - totalItems: totalItems - }); + return FulfillAvailableDetails({ + items: items, + caller: group.caller, + recipient: group.recipient, + totalItems: totalItems + }); } } @@ -1746,34 +1641,30 @@ library MatchableItemReferenceGroupLib { MatchableItemReferenceGroup[] memory matchableGroups, address recipient ) internal pure returns (MatchDetails memory) { - DualFulfillmentItems[] memory items = new DualFulfillmentItems[]( - matchableGroups.length - ); + DualFulfillmentItems[] memory items = + new DualFulfillmentItems[](matchableGroups.length); uint256 totalItems = 0; uint256 itemsInGroup = 0; for (uint256 i = 0; i < matchableGroups.length; ++i) { - MatchableItemReferenceGroup memory matchableGroup = ( - matchableGroups[i] - ); + MatchableItemReferenceGroup memory matchableGroup = + (matchableGroups[i]); (items[i], itemsInGroup) = FulfillmentPrepLib .getDualFulfillmentItems( - matchableGroup.offerGroups, - matchableGroup.considerationGroups - ); + matchableGroup.offerGroups, matchableGroup.considerationGroups + ); totalItems += itemsInGroup; } - return - MatchDetails({ - items: items, - context: FulfillmentPrepLib.getFulfillmentMatchContext(items), - recipient: recipient, - totalItems: totalItems - }); + return MatchDetails({ + items: items, + context: FulfillmentPrepLib.getFulfillmentMatchContext(items), + recipient: recipient, + totalItems: totalItems + }); } } @@ -1795,13 +1686,12 @@ library ItemReferenceGroupLib { function bundleByAggregatable( ItemReferenceLib.ItemReference[] memory itemReferences ) internal pure returns (ItemReferenceGroup[] memory) { - ItemReferenceGroup[] memory groups = itemReferences - .getUniqueFullHashes() - .allocateItemReferenceGroup(); + ItemReferenceGroup[] memory groups = + itemReferences.getUniqueFullHashes().allocateItemReferenceGroup(); for (uint256 i = 0; i < itemReferences.length; ++i) { - ItemReferenceLib.ItemReference - memory itemReference = itemReferences[i]; + ItemReferenceLib.ItemReference memory itemReference = + itemReferences[i]; for (uint256 j = 0; j < groups.length; ++j) { ItemReferenceGroup memory group = groups[j]; if (group.fullHash == itemReference.fullHash) { @@ -1829,17 +1719,14 @@ library ItemReferenceGroupLib { internal pure returns ( - FulfillAvailableReferenceGroupLib.FulfillAvailableReferenceGroup - memory + FulfillAvailableReferenceGroupLib.FulfillAvailableReferenceGroup memory ) { // NOTE: lengths are overallocated; reduce after assignment. - ItemReferenceGroup[] memory offerGroups = ( - new ItemReferenceGroup[](groups.length) - ); - ItemReferenceGroup[] memory considerationGroups = ( - new ItemReferenceGroup[](groups.length) - ); + ItemReferenceGroup[] memory offerGroups = + (new ItemReferenceGroup[](groups.length)); + ItemReferenceGroup[] memory considerationGroups = + (new ItemReferenceGroup[](groups.length)); uint256 offerItems = 0; uint256 considerationItems = 0; @@ -1865,13 +1752,12 @@ library ItemReferenceGroupLib { mstore(considerationGroups, considerationItems) } - return - FulfillAvailableReferenceGroupLib.FulfillAvailableReferenceGroup({ - offerGroups: offerGroups, - considerationGroups: considerationGroups, - recipient: recipient, - caller: caller - }); + return FulfillAvailableReferenceGroupLib.FulfillAvailableReferenceGroup({ + offerGroups: offerGroups, + considerationGroups: considerationGroups, + recipient: recipient, + caller: caller + }); } function bundleByMatchable( @@ -1884,10 +1770,9 @@ library ItemReferenceGroupLib { MatchableItemReferenceGroupLib.MatchableItemReferenceGroup[] memory ) { - MatchableItemReferenceGroupLib.MatchableItemReferenceGroup[] - memory matchableGroups = ( - itemReferences - .getUniqueDataHashes() + MatchableItemReferenceGroupLib.MatchableItemReferenceGroup[] memory + matchableGroups = ( + itemReferences.getUniqueDataHashes() .allocateMatchableItemReferenceGroup() ); @@ -1898,21 +1783,19 @@ library ItemReferenceGroupLib { revert EmptyItemReferenceGroupSupplied(); } - ItemReferenceLib.ItemReference memory firstReference = group - .references[0]; + ItemReferenceLib.ItemReference memory firstReference = + group.references[0]; for (uint256 j = 0; j < matchableGroups.length; ++j) { MatchableItemReferenceGroupLib.MatchableItemReferenceGroup memory matchableGroup = (matchableGroups[j]); if (matchableGroup.dataHash == firstReference.dataHash) { if (firstReference.side == Side.OFFER) { - matchableGroup.offerGroups[ - matchableGroup.offerAssigned++ - ] = group; + matchableGroup.offerGroups[matchableGroup.offerAssigned++] + = group; } else if (firstReference.side == Side.CONSIDERATION) { - matchableGroup.considerationGroups[ - matchableGroup.considerationAssigned++ - ] = group; + matchableGroup.considerationGroups[matchableGroup + .considerationAssigned++] = group; } else { revert InvalidMatchSideLocated(); } @@ -1924,14 +1807,13 @@ library ItemReferenceGroupLib { // Reduce reference group array lengths based on assigned elements. for (uint256 i = 0; i < matchableGroups.length; ++i) { - MatchableItemReferenceGroupLib.MatchableItemReferenceGroup - memory group = matchableGroups[i]; + MatchableItemReferenceGroupLib.MatchableItemReferenceGroup memory + group = matchableGroups[i]; uint256 offerAssigned = group.offerAssigned; uint256 considerationAssigned = group.considerationAssigned; ItemReferenceGroup[] memory offerGroups = (group.offerGroups); - ItemReferenceGroup[] memory considerationGroups = ( - group.considerationGroups - ); + ItemReferenceGroup[] memory considerationGroups = + (group.considerationGroups); assembly { mstore(offerGroups, offerAssigned) @@ -1951,17 +1833,13 @@ library HashAllocatorLib { pure returns (ItemReferenceGroupLib.ItemReferenceGroup[] memory) { - ItemReferenceGroupLib.ItemReferenceGroup[] - memory group = new ItemReferenceGroupLib.ItemReferenceGroup[]( - hashCount.length - ); + ItemReferenceGroupLib.ItemReferenceGroup[] memory group = + new ItemReferenceGroupLib.ItemReferenceGroup[](hashCount.length); for (uint256 i = 0; i < hashCount.length; ++i) { group[i] = ItemReferenceGroupLib.ItemReferenceGroup({ fullHash: hashCount[i].hash, - references: new ItemReferenceLib.ItemReference[]( - hashCount[i].count - ), + references: new ItemReferenceLib.ItemReference[](hashCount[i].count), assigned: 0 }); } @@ -1978,8 +1856,8 @@ library HashAllocatorLib { MatchableItemReferenceGroupLib.MatchableItemReferenceGroup[] memory ) { - MatchableItemReferenceGroupLib.MatchableItemReferenceGroup[] - memory group = ( + MatchableItemReferenceGroupLib.MatchableItemReferenceGroup[] memory + group = ( new MatchableItemReferenceGroupLib.MatchableItemReferenceGroup[]( hashCount.length ) @@ -1991,16 +1869,14 @@ library HashAllocatorLib { uint256 count = hashCount[i].count; group[i] = MatchableItemReferenceGroupLib .MatchableItemReferenceGroup({ - dataHash: hashCount[i].hash, - offerGroups: new ItemReferenceGroupLib.ItemReferenceGroup[]( - count + dataHash: hashCount[i].hash, + offerGroups: new ItemReferenceGroupLib.ItemReferenceGroup[](count), + considerationGroups: ( + new ItemReferenceGroupLib.ItemReferenceGroup[](count) ), - considerationGroups: ( - new ItemReferenceGroupLib.ItemReferenceGroup[](count) - ), - offerAssigned: 0, - considerationAssigned: 0 - }); + offerAssigned: 0, + considerationAssigned: 0 + }); } return group; @@ -2042,9 +1918,11 @@ library HashCountLib { return getHashCount(dataHashes); } - function getHashCount( - uint256[] memory hashes - ) internal pure returns (HashCount[] memory) { + function getHashCount(uint256[] memory hashes) + internal + pure + returns (HashCount[] memory) + { if (hashes.length == 0) { return new HashCount[](0); } @@ -2059,10 +1937,8 @@ library HashCountLib { bytes32 element = bytes32(hashes[i]); if (element != hashCount[hashCountPointer].hash) { - hashCount[++hashCountPointer] = HashCount({ - hash: element, - count: 1 - }); + hashCount[++hashCountPointer] = + HashCount({ hash: element, count: 1 }); } else { ++hashCount[hashCountPointer].count; } @@ -2092,13 +1968,13 @@ library ItemReferenceLib { address account; } - function getItemReferences( - OrderDetails[] memory orderDetails, - uint256 seed - ) internal pure returns (ItemReference[] memory) { - ItemReference[] memory itemReferences = new ItemReference[]( - getTotalItems(orderDetails) - ); + function getItemReferences(OrderDetails[] memory orderDetails, uint256 seed) + internal + pure + returns (ItemReference[] memory) + { + ItemReference[] memory itemReferences = + new ItemReference[](getTotalItems(orderDetails)); uint256 itemReferenceIndex = 0; @@ -2127,9 +2003,7 @@ library ItemReferenceLib { ++itemIndex ) { itemReferences[itemReferenceIndex++] = getItemReference( - order.consideration[itemIndex], - orderIndex, - itemIndex + order.consideration[itemIndex], orderIndex, itemIndex ); } } @@ -2141,13 +2015,13 @@ library ItemReferenceLib { return shuffle(itemReferences, seed); } - function shuffle( - ItemReference[] memory itemReferences, - uint256 seed - ) internal pure returns (ItemReference[] memory) { - ItemReference[] memory shuffledItemReferences = new ItemReference[]( - itemReferences.length - ); + function shuffle(ItemReference[] memory itemReferences, uint256 seed) + internal + pure + returns (ItemReference[] memory) + { + ItemReference[] memory shuffledItemReferences = + new ItemReference[](itemReferences.length); uint256[] memory indices = new uint256[](itemReferences.length); for (uint256 i = 0; i < indices.length; ++i) { @@ -2172,18 +2046,17 @@ library ItemReferenceLib { address offerer, bytes32 conduitKey ) internal pure returns (ItemReference memory) { - return - getItemReference( - orderIndex, - itemIndex, - Side.OFFER, - item.itemType, - item.token, - item.identifier, - offerer, - conduitKey, - item.amount - ); + return getItemReference( + orderIndex, + itemIndex, + Side.OFFER, + item.itemType, + item.token, + item.identifier, + offerer, + conduitKey, + item.amount + ); } function getItemReference( @@ -2191,18 +2064,17 @@ library ItemReferenceLib { uint256 orderIndex, uint256 itemIndex ) internal pure returns (ItemReference memory) { - return - getItemReference( - orderIndex, - itemIndex, - Side.CONSIDERATION, - item.itemType, - item.token, - item.identifier, - item.recipient, - bytes32(0), - item.amount - ); + return getItemReference( + orderIndex, + itemIndex, + Side.CONSIDERATION, + item.itemType, + item.token, + item.identifier, + item.recipient, + bytes32(0), + item.amount + ); } function getItemReference( @@ -2216,15 +2088,13 @@ library ItemReferenceLib { bytes32 conduitKey, uint256 amount ) internal pure returns (ItemReference memory) { - bytes32 dataHash = keccak256( - abi.encodePacked(itemType, token, identifier) - ); + bytes32 dataHash = + keccak256(abi.encodePacked(itemType, token, identifier)); bytes32 fullHash; if (side == Side.OFFER) { - fullHash = keccak256( - abi.encodePacked(dataHash, account, conduitKey) - ); + fullHash = + keccak256(abi.encodePacked(dataHash, account, conduitKey)); } else { fullHash = keccak256(abi.encodePacked(dataHash, account)); } @@ -2238,22 +2108,23 @@ library ItemReferenceLib { itemCategory = ItemCategory.OTHER; } - return - ItemReference({ - orderIndex: orderIndex, - itemIndex: itemIndex, - side: side, - dataHash: dataHash, - fullHash: fullHash, - amount: amount, - itemCategory: itemCategory, - account: account - }); + return ItemReference({ + orderIndex: orderIndex, + itemIndex: itemIndex, + side: side, + dataHash: dataHash, + fullHash: fullHash, + amount: amount, + itemCategory: itemCategory, + account: account + }); } - function getTotalItems( - OrderDetails[] memory orderDetails - ) internal pure returns (uint256) { + function getTotalItems(OrderDetails[] memory orderDetails) + internal + pure + returns (uint256) + { uint256 totalItems = 0; for (uint256 i = 0; i < orderDetails.length; ++i) { @@ -2263,9 +2134,11 @@ library ItemReferenceLib { return totalItems; } - function getTotalItems( - OrderDetails memory order - ) internal pure returns (uint256) { + function getTotalItems(OrderDetails memory order) + internal + pure + returns (uint256) + { return (order.offer.length + order.consideration.length); } } diff --git a/src/fulfillments/lib/MatchArrays.sol b/src/fulfillments/lib/MatchArrays.sol index e47ded1..0b14e5f 100644 --- a/src/fulfillments/lib/MatchArrays.sol +++ b/src/fulfillments/lib/MatchArrays.sol @@ -15,11 +15,10 @@ library MatchArrays { return arr; } - function FulfillmentComponents(FulfillmentComponent memory a, FulfillmentComponent memory b) - internal - pure - returns (FulfillmentComponent[] memory) - { + function FulfillmentComponents( + FulfillmentComponent memory a, + FulfillmentComponent memory b + ) internal pure returns (FulfillmentComponent[] memory) { FulfillmentComponent[] memory arr = new FulfillmentComponent[](2); arr[0] = a; arr[1] = b; @@ -106,14 +105,12 @@ library MatchArrays { return arr; } - function FulfillmentComponentsWithMaxLength(uint256 maxLength, FulfillmentComponent memory a) - internal - pure - returns (FulfillmentComponent[] memory) - { - FulfillmentComponent[] memory arr = new FulfillmentComponent[]( - maxLength - ); + function FulfillmentComponentsWithMaxLength( + uint256 maxLength, + FulfillmentComponent memory a + ) internal pure returns (FulfillmentComponent[] memory) { + FulfillmentComponent[] memory arr = + new FulfillmentComponent[](maxLength); assembly { mstore(arr, 1) } @@ -126,9 +123,8 @@ library MatchArrays { FulfillmentComponent memory a, FulfillmentComponent memory b ) internal pure returns (FulfillmentComponent[] memory) { - FulfillmentComponent[] memory arr = new FulfillmentComponent[]( - maxLength - ); + FulfillmentComponent[] memory arr = + new FulfillmentComponent[](maxLength); assembly { mstore(arr, 2) } @@ -143,9 +139,8 @@ library MatchArrays { FulfillmentComponent memory b, FulfillmentComponent memory c ) internal pure returns (FulfillmentComponent[] memory) { - FulfillmentComponent[] memory arr = new FulfillmentComponent[]( - maxLength - ); + FulfillmentComponent[] memory arr = + new FulfillmentComponent[](maxLength); assembly { mstore(arr, 3) } @@ -162,9 +157,8 @@ library MatchArrays { FulfillmentComponent memory c, FulfillmentComponent memory d ) internal pure returns (FulfillmentComponent[] memory) { - FulfillmentComponent[] memory arr = new FulfillmentComponent[]( - maxLength - ); + FulfillmentComponent[] memory arr = + new FulfillmentComponent[](maxLength); assembly { mstore(arr, 4) } @@ -183,9 +177,8 @@ library MatchArrays { FulfillmentComponent memory d, FulfillmentComponent memory e ) internal pure returns (FulfillmentComponent[] memory) { - FulfillmentComponent[] memory arr = new FulfillmentComponent[]( - maxLength - ); + FulfillmentComponent[] memory arr = + new FulfillmentComponent[](maxLength); assembly { mstore(arr, 5) } @@ -206,9 +199,8 @@ library MatchArrays { FulfillmentComponent memory e, FulfillmentComponent memory f ) internal pure returns (FulfillmentComponent[] memory) { - FulfillmentComponent[] memory arr = new FulfillmentComponent[]( - maxLength - ); + FulfillmentComponent[] memory arr = + new FulfillmentComponent[](maxLength); assembly { mstore(arr, 6) } @@ -231,9 +223,8 @@ library MatchArrays { FulfillmentComponent memory f, FulfillmentComponent memory g ) internal pure returns (FulfillmentComponent[] memory) { - FulfillmentComponent[] memory arr = new FulfillmentComponent[]( - maxLength - ); + FulfillmentComponent[] memory arr = + new FulfillmentComponent[](maxLength); assembly { mstore(arr, 7) } @@ -247,11 +238,10 @@ library MatchArrays { return arr; } - function extend(FulfillmentComponent[] memory arr1, FulfillmentComponent[] memory arr2) - internal - pure - returns (FulfillmentComponent[] memory newArr) - { + function extend( + FulfillmentComponent[] memory arr1, + FulfillmentComponent[] memory arr2 + ) internal pure returns (FulfillmentComponent[] memory newArr) { uint256 length1 = arr1.length; uint256 length2 = arr2.length; newArr = new FulfillmentComponent[](length1 + length2); @@ -273,7 +263,11 @@ library MatchArrays { } } - function allocateFulfillmentComponents(uint256 length) internal pure returns (FulfillmentComponent[] memory arr) { + function allocateFulfillmentComponents(uint256 length) + internal + pure + returns (FulfillmentComponent[] memory arr) + { arr = new FulfillmentComponent[](length); assembly { mstore(arr, 0) @@ -288,17 +282,18 @@ library MatchArrays { // truncate the array assembly { let oldLength := mload(arr) - returndatacopy(returndatasize(), returndatasize(), gt(newLength, oldLength)) + returndatacopy( + returndatasize(), returndatasize(), gt(newLength, oldLength) + ) mstore(arr, newLength) _arr := arr } } - function truncateUnsafe(FulfillmentComponent[] memory arr, uint256 newLength) - internal - pure - returns (FulfillmentComponent[] memory _arr) - { + function truncateUnsafe( + FulfillmentComponent[] memory arr, + uint256 newLength + ) internal pure returns (FulfillmentComponent[] memory _arr) { // truncate the array assembly { mstore(arr, newLength) @@ -306,11 +301,10 @@ library MatchArrays { } } - function append(FulfillmentComponent[] memory arr, FulfillmentComponent memory value) - internal - pure - returns (FulfillmentComponent[] memory newArr) - { + function append( + FulfillmentComponent[] memory arr, + FulfillmentComponent memory value + ) internal pure returns (FulfillmentComponent[] memory newArr) { uint256 length = arr.length; newArr = new FulfillmentComponent[](length + 1); newArr[length] = value; @@ -322,11 +316,10 @@ library MatchArrays { } } - function appendUnsafe(FulfillmentComponent[] memory arr, FulfillmentComponent memory value) - internal - pure - returns (FulfillmentComponent[] memory modifiedArr) - { + function appendUnsafe( + FulfillmentComponent[] memory arr, + FulfillmentComponent memory value + ) internal pure returns (FulfillmentComponent[] memory modifiedArr) { uint256 length = arr.length; modifiedArr = arr; assembly { @@ -335,7 +328,11 @@ library MatchArrays { } } - function copy(FulfillmentComponent[] memory arr) internal pure returns (FulfillmentComponent[] memory newArr) { + function copy(FulfillmentComponent[] memory arr) + internal + pure + returns (FulfillmentComponent[] memory newArr) + { uint256 length = arr.length; newArr = new FulfillmentComponent[](length); for (uint256 i = 0; i < length;) { @@ -364,11 +361,10 @@ library MatchArrays { // TODO: consider writing 0-pointer to the rest of the array if longer for dynamic elements } - function copyAndAllocate(FulfillmentComponent[] memory arr, uint256 maxLength) - internal - pure - returns (FulfillmentComponent[] memory newArr) - { + function copyAndAllocate( + FulfillmentComponent[] memory arr, + uint256 maxLength + ) internal pure returns (FulfillmentComponent[] memory newArr) { newArr = new FulfillmentComponent[](maxLength); uint256 originalLength = arr.length; for (uint256 i = 0; i < originalLength;) { @@ -382,7 +378,11 @@ library MatchArrays { } } - function pop(FulfillmentComponent[] memory arr) internal pure returns (FulfillmentComponent memory value) { + function pop(FulfillmentComponent[] memory arr) + internal + pure + returns (FulfillmentComponent memory value) + { assembly { let length := mload(arr) returndatacopy(returndatasize(), returndatasize(), iszero(length)) @@ -391,7 +391,11 @@ library MatchArrays { } } - function popUnsafe(FulfillmentComponent[] memory arr) internal pure returns (FulfillmentComponent memory value) { + function popUnsafe(FulfillmentComponent[] memory arr) + internal + pure + returns (FulfillmentComponent memory value) + { // This function is unsafe because it does not check if the array is empty. assembly { let length := mload(arr) @@ -403,7 +407,10 @@ library MatchArrays { function popLeft(FulfillmentComponent[] memory arr) internal pure - returns (FulfillmentComponent[] memory newArr, FulfillmentComponent memory value) + returns ( + FulfillmentComponent[] memory newArr, + FulfillmentComponent memory value + ) { assembly { let length := mload(arr) @@ -417,7 +424,10 @@ library MatchArrays { function popLeftUnsafe(FulfillmentComponent[] memory arr) internal pure - returns (FulfillmentComponent[] memory newArr, FulfillmentComponent memory value) + returns ( + FulfillmentComponent[] memory newArr, + FulfillmentComponent memory value + ) { // This function is unsafe because it does not check if the array is empty. assembly { @@ -442,11 +452,10 @@ library MatchArrays { } } - function fromFixedWithMaxLength(FulfillmentComponent[1] memory arr, uint256 maxLength) - internal - pure - returns (FulfillmentComponent[] memory newArr) - { + function fromFixedWithMaxLength( + FulfillmentComponent[1] memory arr, + uint256 maxLength + ) internal pure returns (FulfillmentComponent[] memory newArr) { newArr = new FulfillmentComponent[](maxLength); for (uint256 i = 0; i < 1;) { newArr[i] = arr[i]; @@ -473,11 +482,10 @@ library MatchArrays { } } - function fromFixedWithMaxLength(FulfillmentComponent[2] memory arr, uint256 maxLength) - internal - pure - returns (FulfillmentComponent[] memory newArr) - { + function fromFixedWithMaxLength( + FulfillmentComponent[2] memory arr, + uint256 maxLength + ) internal pure returns (FulfillmentComponent[] memory newArr) { newArr = new FulfillmentComponent[](maxLength); for (uint256 i = 0; i < 2;) { newArr[i] = arr[i]; @@ -504,11 +512,10 @@ library MatchArrays { } } - function fromFixedWithMaxLength(FulfillmentComponent[3] memory arr, uint256 maxLength) - internal - pure - returns (FulfillmentComponent[] memory newArr) - { + function fromFixedWithMaxLength( + FulfillmentComponent[3] memory arr, + uint256 maxLength + ) internal pure returns (FulfillmentComponent[] memory newArr) { newArr = new FulfillmentComponent[](maxLength); for (uint256 i = 0; i < 3;) { newArr[i] = arr[i]; @@ -535,11 +542,10 @@ library MatchArrays { } } - function fromFixedWithMaxLength(FulfillmentComponent[4] memory arr, uint256 maxLength) - internal - pure - returns (FulfillmentComponent[] memory newArr) - { + function fromFixedWithMaxLength( + FulfillmentComponent[4] memory arr, + uint256 maxLength + ) internal pure returns (FulfillmentComponent[] memory newArr) { newArr = new FulfillmentComponent[](maxLength); for (uint256 i = 0; i < 4;) { newArr[i] = arr[i]; @@ -566,11 +572,10 @@ library MatchArrays { } } - function fromFixedWithMaxLength(FulfillmentComponent[5] memory arr, uint256 maxLength) - internal - pure - returns (FulfillmentComponent[] memory newArr) - { + function fromFixedWithMaxLength( + FulfillmentComponent[5] memory arr, + uint256 maxLength + ) internal pure returns (FulfillmentComponent[] memory newArr) { newArr = new FulfillmentComponent[](maxLength); for (uint256 i = 0; i < 5;) { newArr[i] = arr[i]; @@ -597,11 +602,10 @@ library MatchArrays { } } - function fromFixedWithMaxLength(FulfillmentComponent[6] memory arr, uint256 maxLength) - internal - pure - returns (FulfillmentComponent[] memory newArr) - { + function fromFixedWithMaxLength( + FulfillmentComponent[6] memory arr, + uint256 maxLength + ) internal pure returns (FulfillmentComponent[] memory newArr) { newArr = new FulfillmentComponent[](maxLength); for (uint256 i = 0; i < 6;) { newArr[i] = arr[i]; @@ -628,11 +632,10 @@ library MatchArrays { } } - function fromFixedWithMaxLength(FulfillmentComponent[7] memory arr, uint256 maxLength) - internal - pure - returns (FulfillmentComponent[] memory newArr) - { + function fromFixedWithMaxLength( + FulfillmentComponent[7] memory arr, + uint256 maxLength + ) internal pure returns (FulfillmentComponent[] memory newArr) { newArr = new FulfillmentComponent[](maxLength); for (uint256 i = 0; i < 7;) { newArr[i] = arr[i]; @@ -655,11 +658,10 @@ library MatchArrays { return arr; } - function FulfillmentComponentArrays(FulfillmentComponent[] memory a, FulfillmentComponent[] memory b) - internal - pure - returns (FulfillmentComponent[][] memory) - { + function FulfillmentComponentArrays( + FulfillmentComponent[] memory a, + FulfillmentComponent[] memory b + ) internal pure returns (FulfillmentComponent[][] memory) { FulfillmentComponent[][] memory arr = new FulfillmentComponent[][](2); arr[0] = a; arr[1] = b; @@ -746,14 +748,12 @@ library MatchArrays { return arr; } - function FulfillmentComponentArraysWithMaxLength(uint256 maxLength, FulfillmentComponent[] memory a) - internal - pure - returns (FulfillmentComponent[][] memory) - { - FulfillmentComponent[][] memory arr = new FulfillmentComponent[][]( - maxLength - ); + function FulfillmentComponentArraysWithMaxLength( + uint256 maxLength, + FulfillmentComponent[] memory a + ) internal pure returns (FulfillmentComponent[][] memory) { + FulfillmentComponent[][] memory arr = + new FulfillmentComponent[][](maxLength); assembly { mstore(arr, 1) } @@ -766,9 +766,8 @@ library MatchArrays { FulfillmentComponent[] memory a, FulfillmentComponent[] memory b ) internal pure returns (FulfillmentComponent[][] memory) { - FulfillmentComponent[][] memory arr = new FulfillmentComponent[][]( - maxLength - ); + FulfillmentComponent[][] memory arr = + new FulfillmentComponent[][](maxLength); assembly { mstore(arr, 2) } @@ -783,9 +782,8 @@ library MatchArrays { FulfillmentComponent[] memory b, FulfillmentComponent[] memory c ) internal pure returns (FulfillmentComponent[][] memory) { - FulfillmentComponent[][] memory arr = new FulfillmentComponent[][]( - maxLength - ); + FulfillmentComponent[][] memory arr = + new FulfillmentComponent[][](maxLength); assembly { mstore(arr, 3) } @@ -802,9 +800,8 @@ library MatchArrays { FulfillmentComponent[] memory c, FulfillmentComponent[] memory d ) internal pure returns (FulfillmentComponent[][] memory) { - FulfillmentComponent[][] memory arr = new FulfillmentComponent[][]( - maxLength - ); + FulfillmentComponent[][] memory arr = + new FulfillmentComponent[][](maxLength); assembly { mstore(arr, 4) } @@ -823,9 +820,8 @@ library MatchArrays { FulfillmentComponent[] memory d, FulfillmentComponent[] memory e ) internal pure returns (FulfillmentComponent[][] memory) { - FulfillmentComponent[][] memory arr = new FulfillmentComponent[][]( - maxLength - ); + FulfillmentComponent[][] memory arr = + new FulfillmentComponent[][](maxLength); assembly { mstore(arr, 5) } @@ -846,9 +842,8 @@ library MatchArrays { FulfillmentComponent[] memory e, FulfillmentComponent[] memory f ) internal pure returns (FulfillmentComponent[][] memory) { - FulfillmentComponent[][] memory arr = new FulfillmentComponent[][]( - maxLength - ); + FulfillmentComponent[][] memory arr = + new FulfillmentComponent[][](maxLength); assembly { mstore(arr, 6) } @@ -871,9 +866,8 @@ library MatchArrays { FulfillmentComponent[] memory f, FulfillmentComponent[] memory g ) internal pure returns (FulfillmentComponent[][] memory) { - FulfillmentComponent[][] memory arr = new FulfillmentComponent[][]( - maxLength - ); + FulfillmentComponent[][] memory arr = + new FulfillmentComponent[][](maxLength); assembly { mstore(arr, 7) } @@ -887,11 +881,10 @@ library MatchArrays { return arr; } - function extend(FulfillmentComponent[][] memory arr1, FulfillmentComponent[][] memory arr2) - internal - pure - returns (FulfillmentComponent[][] memory newArr) - { + function extend( + FulfillmentComponent[][] memory arr1, + FulfillmentComponent[][] memory arr2 + ) internal pure returns (FulfillmentComponent[][] memory newArr) { uint256 length1 = arr1.length; uint256 length2 = arr2.length; newArr = new FulfillmentComponent[][](length1 + length2); @@ -932,17 +925,18 @@ library MatchArrays { // truncate the array assembly { let oldLength := mload(arr) - returndatacopy(returndatasize(), returndatasize(), gt(newLength, oldLength)) + returndatacopy( + returndatasize(), returndatasize(), gt(newLength, oldLength) + ) mstore(arr, newLength) _arr := arr } } - function truncateUnsafe(FulfillmentComponent[][] memory arr, uint256 newLength) - internal - pure - returns (FulfillmentComponent[][] memory _arr) - { + function truncateUnsafe( + FulfillmentComponent[][] memory arr, + uint256 newLength + ) internal pure returns (FulfillmentComponent[][] memory _arr) { // truncate the array assembly { mstore(arr, newLength) @@ -950,11 +944,10 @@ library MatchArrays { } } - function append(FulfillmentComponent[][] memory arr, FulfillmentComponent[] memory value) - internal - pure - returns (FulfillmentComponent[][] memory newArr) - { + function append( + FulfillmentComponent[][] memory arr, + FulfillmentComponent[] memory value + ) internal pure returns (FulfillmentComponent[][] memory newArr) { uint256 length = arr.length; newArr = new FulfillmentComponent[][](length + 1); newArr[length] = value; @@ -966,11 +959,10 @@ library MatchArrays { } } - function appendUnsafe(FulfillmentComponent[][] memory arr, FulfillmentComponent[] memory value) - internal - pure - returns (FulfillmentComponent[][] memory modifiedArr) - { + function appendUnsafe( + FulfillmentComponent[][] memory arr, + FulfillmentComponent[] memory value + ) internal pure returns (FulfillmentComponent[][] memory modifiedArr) { uint256 length = arr.length; modifiedArr = arr; assembly { @@ -979,7 +971,11 @@ library MatchArrays { } } - function copy(FulfillmentComponent[][] memory arr) internal pure returns (FulfillmentComponent[][] memory newArr) { + function copy(FulfillmentComponent[][] memory arr) + internal + pure + returns (FulfillmentComponent[][] memory newArr) + { uint256 length = arr.length; newArr = new FulfillmentComponent[][](length); for (uint256 i = 0; i < length;) { @@ -990,11 +986,10 @@ library MatchArrays { } } - function copyAndResize(FulfillmentComponent[][] memory arr, uint256 newLength) - internal - pure - returns (FulfillmentComponent[][] memory newArr) - { + function copyAndResize( + FulfillmentComponent[][] memory arr, + uint256 newLength + ) internal pure returns (FulfillmentComponent[][] memory newArr) { newArr = new FulfillmentComponent[][](newLength); uint256 length = arr.length; // allow shrinking a copy without copying extra members @@ -1008,11 +1003,10 @@ library MatchArrays { // TODO: consider writing 0-pointer to the rest of the array if longer for dynamic elements } - function copyAndAllocate(FulfillmentComponent[][] memory arr, uint256 maxLength) - internal - pure - returns (FulfillmentComponent[][] memory newArr) - { + function copyAndAllocate( + FulfillmentComponent[][] memory arr, + uint256 maxLength + ) internal pure returns (FulfillmentComponent[][] memory newArr) { newArr = new FulfillmentComponent[][](maxLength); uint256 originalLength = arr.length; for (uint256 i = 0; i < originalLength;) { @@ -1026,7 +1020,11 @@ library MatchArrays { } } - function pop(FulfillmentComponent[][] memory arr) internal pure returns (FulfillmentComponent[] memory value) { + function pop(FulfillmentComponent[][] memory arr) + internal + pure + returns (FulfillmentComponent[] memory value) + { assembly { let length := mload(arr) returndatacopy(returndatasize(), returndatasize(), iszero(length)) @@ -1051,7 +1049,10 @@ library MatchArrays { function popLeft(FulfillmentComponent[][] memory arr) internal pure - returns (FulfillmentComponent[][] memory newArr, FulfillmentComponent[] memory value) + returns ( + FulfillmentComponent[][] memory newArr, + FulfillmentComponent[] memory value + ) { assembly { let length := mload(arr) @@ -1065,7 +1066,10 @@ library MatchArrays { function popLeftUnsafe(FulfillmentComponent[][] memory arr) internal pure - returns (FulfillmentComponent[][] memory newArr, FulfillmentComponent[] memory value) + returns ( + FulfillmentComponent[][] memory newArr, + FulfillmentComponent[] memory value + ) { // This function is unsafe because it does not check if the array is empty. assembly { @@ -1090,11 +1094,10 @@ library MatchArrays { } } - function fromFixedWithMaxLength(FulfillmentComponent[][1] memory arr, uint256 maxLength) - internal - pure - returns (FulfillmentComponent[][] memory newArr) - { + function fromFixedWithMaxLength( + FulfillmentComponent[][1] memory arr, + uint256 maxLength + ) internal pure returns (FulfillmentComponent[][] memory newArr) { newArr = new FulfillmentComponent[][](maxLength); for (uint256 i = 0; i < 1;) { newArr[i] = arr[i]; @@ -1121,11 +1124,10 @@ library MatchArrays { } } - function fromFixedWithMaxLength(FulfillmentComponent[][2] memory arr, uint256 maxLength) - internal - pure - returns (FulfillmentComponent[][] memory newArr) - { + function fromFixedWithMaxLength( + FulfillmentComponent[][2] memory arr, + uint256 maxLength + ) internal pure returns (FulfillmentComponent[][] memory newArr) { newArr = new FulfillmentComponent[][](maxLength); for (uint256 i = 0; i < 2;) { newArr[i] = arr[i]; @@ -1152,11 +1154,10 @@ library MatchArrays { } } - function fromFixedWithMaxLength(FulfillmentComponent[][3] memory arr, uint256 maxLength) - internal - pure - returns (FulfillmentComponent[][] memory newArr) - { + function fromFixedWithMaxLength( + FulfillmentComponent[][3] memory arr, + uint256 maxLength + ) internal pure returns (FulfillmentComponent[][] memory newArr) { newArr = new FulfillmentComponent[][](maxLength); for (uint256 i = 0; i < 3;) { newArr[i] = arr[i]; @@ -1183,11 +1184,10 @@ library MatchArrays { } } - function fromFixedWithMaxLength(FulfillmentComponent[][4] memory arr, uint256 maxLength) - internal - pure - returns (FulfillmentComponent[][] memory newArr) - { + function fromFixedWithMaxLength( + FulfillmentComponent[][4] memory arr, + uint256 maxLength + ) internal pure returns (FulfillmentComponent[][] memory newArr) { newArr = new FulfillmentComponent[][](maxLength); for (uint256 i = 0; i < 4;) { newArr[i] = arr[i]; @@ -1214,11 +1214,10 @@ library MatchArrays { } } - function fromFixedWithMaxLength(FulfillmentComponent[][5] memory arr, uint256 maxLength) - internal - pure - returns (FulfillmentComponent[][] memory newArr) - { + function fromFixedWithMaxLength( + FulfillmentComponent[][5] memory arr, + uint256 maxLength + ) internal pure returns (FulfillmentComponent[][] memory newArr) { newArr = new FulfillmentComponent[][](maxLength); for (uint256 i = 0; i < 5;) { newArr[i] = arr[i]; @@ -1245,11 +1244,10 @@ library MatchArrays { } } - function fromFixedWithMaxLength(FulfillmentComponent[][6] memory arr, uint256 maxLength) - internal - pure - returns (FulfillmentComponent[][] memory newArr) - { + function fromFixedWithMaxLength( + FulfillmentComponent[][6] memory arr, + uint256 maxLength + ) internal pure returns (FulfillmentComponent[][] memory newArr) { newArr = new FulfillmentComponent[][](maxLength); for (uint256 i = 0; i < 6;) { newArr[i] = arr[i]; @@ -1276,11 +1274,10 @@ library MatchArrays { } } - function fromFixedWithMaxLength(FulfillmentComponent[][7] memory arr, uint256 maxLength) - internal - pure - returns (FulfillmentComponent[][] memory newArr) - { + function fromFixedWithMaxLength( + FulfillmentComponent[][7] memory arr, + uint256 maxLength + ) internal pure returns (FulfillmentComponent[][] memory newArr) { newArr = new FulfillmentComponent[][](maxLength); for (uint256 i = 0; i < 7;) { newArr[i] = arr[i]; @@ -1293,24 +1290,32 @@ library MatchArrays { } } - function Fulfillments(Fulfillment memory a) internal pure returns (Fulfillment[] memory) { + function Fulfillments(Fulfillment memory a) + internal + pure + returns (Fulfillment[] memory) + { Fulfillment[] memory arr = new Fulfillment[](1); arr[0] = a; return arr; } - function Fulfillments(Fulfillment memory a, Fulfillment memory b) internal pure returns (Fulfillment[] memory) { + function Fulfillments(Fulfillment memory a, Fulfillment memory b) + internal + pure + returns (Fulfillment[] memory) + { Fulfillment[] memory arr = new Fulfillment[](2); arr[0] = a; arr[1] = b; return arr; } - function Fulfillments(Fulfillment memory a, Fulfillment memory b, Fulfillment memory c) - internal - pure - returns (Fulfillment[] memory) - { + function Fulfillments( + Fulfillment memory a, + Fulfillment memory b, + Fulfillment memory c + ) internal pure returns (Fulfillment[] memory) { Fulfillment[] memory arr = new Fulfillment[](3); arr[0] = a; arr[1] = b; @@ -1318,11 +1323,12 @@ library MatchArrays { return arr; } - function Fulfillments(Fulfillment memory a, Fulfillment memory b, Fulfillment memory c, Fulfillment memory d) - internal - pure - returns (Fulfillment[] memory) - { + function Fulfillments( + Fulfillment memory a, + Fulfillment memory b, + Fulfillment memory c, + Fulfillment memory d + ) internal pure returns (Fulfillment[] memory) { Fulfillment[] memory arr = new Fulfillment[](4); arr[0] = a; arr[1] = b; @@ -1398,11 +1404,11 @@ library MatchArrays { return arr; } - function FulfillmentsWithMaxLength(uint256 maxLength, Fulfillment memory a, Fulfillment memory b) - internal - pure - returns (Fulfillment[] memory) - { + function FulfillmentsWithMaxLength( + uint256 maxLength, + Fulfillment memory a, + Fulfillment memory b + ) internal pure returns (Fulfillment[] memory) { Fulfillment[] memory arr = new Fulfillment[](maxLength); assembly { mstore(arr, 2) @@ -1538,18 +1544,28 @@ library MatchArrays { } } - function allocateFulfillments(uint256 length) internal pure returns (Fulfillment[] memory arr) { + function allocateFulfillments(uint256 length) + internal + pure + returns (Fulfillment[] memory arr) + { arr = new Fulfillment[](length); assembly { mstore(arr, 0) } } - function truncate(Fulfillment[] memory arr, uint256 newLength) internal pure returns (Fulfillment[] memory _arr) { + function truncate(Fulfillment[] memory arr, uint256 newLength) + internal + pure + returns (Fulfillment[] memory _arr) + { // truncate the array assembly { let oldLength := mload(arr) - returndatacopy(returndatasize(), returndatasize(), gt(newLength, oldLength)) + returndatacopy( + returndatasize(), returndatasize(), gt(newLength, oldLength) + ) mstore(arr, newLength) _arr := arr } @@ -1596,7 +1612,11 @@ library MatchArrays { } } - function copy(Fulfillment[] memory arr) internal pure returns (Fulfillment[] memory newArr) { + function copy(Fulfillment[] memory arr) + internal + pure + returns (Fulfillment[] memory newArr) + { uint256 length = arr.length; newArr = new Fulfillment[](length); for (uint256 i = 0; i < length;) { @@ -1643,7 +1663,11 @@ library MatchArrays { } } - function pop(Fulfillment[] memory arr) internal pure returns (Fulfillment memory value) { + function pop(Fulfillment[] memory arr) + internal + pure + returns (Fulfillment memory value) + { assembly { let length := mload(arr) returndatacopy(returndatasize(), returndatasize(), iszero(length)) @@ -1652,7 +1676,11 @@ library MatchArrays { } } - function popUnsafe(Fulfillment[] memory arr) internal pure returns (Fulfillment memory value) { + function popUnsafe(Fulfillment[] memory arr) + internal + pure + returns (Fulfillment memory value) + { // This function is unsafe because it does not check if the array is empty. assembly { let length := mload(arr) @@ -1689,7 +1717,11 @@ library MatchArrays { } } - function fromFixed(Fulfillment[1] memory arr) internal pure returns (Fulfillment[] memory newArr) { + function fromFixed(Fulfillment[1] memory arr) + internal + pure + returns (Fulfillment[] memory newArr) + { newArr = new Fulfillment[](1); for (uint256 i = 0; i < 1;) { newArr[i] = arr[i]; @@ -1699,11 +1731,10 @@ library MatchArrays { } } - function fromFixedWithMaxLength(Fulfillment[1] memory arr, uint256 maxLength) - internal - pure - returns (Fulfillment[] memory newArr) - { + function fromFixedWithMaxLength( + Fulfillment[1] memory arr, + uint256 maxLength + ) internal pure returns (Fulfillment[] memory newArr) { newArr = new Fulfillment[](maxLength); for (uint256 i = 0; i < 1;) { newArr[i] = arr[i]; @@ -1716,7 +1747,11 @@ library MatchArrays { } } - function fromFixed(Fulfillment[2] memory arr) internal pure returns (Fulfillment[] memory newArr) { + function fromFixed(Fulfillment[2] memory arr) + internal + pure + returns (Fulfillment[] memory newArr) + { newArr = new Fulfillment[](2); for (uint256 i = 0; i < 2;) { newArr[i] = arr[i]; @@ -1726,11 +1761,10 @@ library MatchArrays { } } - function fromFixedWithMaxLength(Fulfillment[2] memory arr, uint256 maxLength) - internal - pure - returns (Fulfillment[] memory newArr) - { + function fromFixedWithMaxLength( + Fulfillment[2] memory arr, + uint256 maxLength + ) internal pure returns (Fulfillment[] memory newArr) { newArr = new Fulfillment[](maxLength); for (uint256 i = 0; i < 2;) { newArr[i] = arr[i]; @@ -1743,7 +1777,11 @@ library MatchArrays { } } - function fromFixed(Fulfillment[3] memory arr) internal pure returns (Fulfillment[] memory newArr) { + function fromFixed(Fulfillment[3] memory arr) + internal + pure + returns (Fulfillment[] memory newArr) + { newArr = new Fulfillment[](3); for (uint256 i = 0; i < 3;) { newArr[i] = arr[i]; @@ -1753,11 +1791,10 @@ library MatchArrays { } } - function fromFixedWithMaxLength(Fulfillment[3] memory arr, uint256 maxLength) - internal - pure - returns (Fulfillment[] memory newArr) - { + function fromFixedWithMaxLength( + Fulfillment[3] memory arr, + uint256 maxLength + ) internal pure returns (Fulfillment[] memory newArr) { newArr = new Fulfillment[](maxLength); for (uint256 i = 0; i < 3;) { newArr[i] = arr[i]; @@ -1770,7 +1807,11 @@ library MatchArrays { } } - function fromFixed(Fulfillment[4] memory arr) internal pure returns (Fulfillment[] memory newArr) { + function fromFixed(Fulfillment[4] memory arr) + internal + pure + returns (Fulfillment[] memory newArr) + { newArr = new Fulfillment[](4); for (uint256 i = 0; i < 4;) { newArr[i] = arr[i]; @@ -1780,11 +1821,10 @@ library MatchArrays { } } - function fromFixedWithMaxLength(Fulfillment[4] memory arr, uint256 maxLength) - internal - pure - returns (Fulfillment[] memory newArr) - { + function fromFixedWithMaxLength( + Fulfillment[4] memory arr, + uint256 maxLength + ) internal pure returns (Fulfillment[] memory newArr) { newArr = new Fulfillment[](maxLength); for (uint256 i = 0; i < 4;) { newArr[i] = arr[i]; @@ -1797,7 +1837,11 @@ library MatchArrays { } } - function fromFixed(Fulfillment[5] memory arr) internal pure returns (Fulfillment[] memory newArr) { + function fromFixed(Fulfillment[5] memory arr) + internal + pure + returns (Fulfillment[] memory newArr) + { newArr = new Fulfillment[](5); for (uint256 i = 0; i < 5;) { newArr[i] = arr[i]; @@ -1807,11 +1851,10 @@ library MatchArrays { } } - function fromFixedWithMaxLength(Fulfillment[5] memory arr, uint256 maxLength) - internal - pure - returns (Fulfillment[] memory newArr) - { + function fromFixedWithMaxLength( + Fulfillment[5] memory arr, + uint256 maxLength + ) internal pure returns (Fulfillment[] memory newArr) { newArr = new Fulfillment[](maxLength); for (uint256 i = 0; i < 5;) { newArr[i] = arr[i]; @@ -1824,7 +1867,11 @@ library MatchArrays { } } - function fromFixed(Fulfillment[6] memory arr) internal pure returns (Fulfillment[] memory newArr) { + function fromFixed(Fulfillment[6] memory arr) + internal + pure + returns (Fulfillment[] memory newArr) + { newArr = new Fulfillment[](6); for (uint256 i = 0; i < 6;) { newArr[i] = arr[i]; @@ -1834,11 +1881,10 @@ library MatchArrays { } } - function fromFixedWithMaxLength(Fulfillment[6] memory arr, uint256 maxLength) - internal - pure - returns (Fulfillment[] memory newArr) - { + function fromFixedWithMaxLength( + Fulfillment[6] memory arr, + uint256 maxLength + ) internal pure returns (Fulfillment[] memory newArr) { newArr = new Fulfillment[](maxLength); for (uint256 i = 0; i < 6;) { newArr[i] = arr[i]; @@ -1851,7 +1897,11 @@ library MatchArrays { } } - function fromFixed(Fulfillment[7] memory arr) internal pure returns (Fulfillment[] memory newArr) { + function fromFixed(Fulfillment[7] memory arr) + internal + pure + returns (Fulfillment[] memory newArr) + { newArr = new Fulfillment[](7); for (uint256 i = 0; i < 7;) { newArr[i] = arr[i]; @@ -1861,11 +1911,10 @@ library MatchArrays { } } - function fromFixedWithMaxLength(Fulfillment[7] memory arr, uint256 maxLength) - internal - pure - returns (Fulfillment[] memory newArr) - { + function fromFixedWithMaxLength( + Fulfillment[7] memory arr, + uint256 maxLength + ) internal pure returns (Fulfillment[] memory newArr) { newArr = new Fulfillment[](maxLength); for (uint256 i = 0; i < 7;) { newArr[i] = arr[i]; @@ -1878,7 +1927,11 @@ library MatchArrays { } } - function MatchComponents(MatchComponent memory a) internal pure returns (MatchComponent[] memory) { + function MatchComponents(MatchComponent memory a) + internal + pure + returns (MatchComponent[] memory) + { MatchComponent[] memory arr = new MatchComponent[](1); arr[0] = a; return arr; @@ -1895,11 +1948,11 @@ library MatchArrays { return arr; } - function MatchComponents(MatchComponent memory a, MatchComponent memory b, MatchComponent memory c) - internal - pure - returns (MatchComponent[] memory) - { + function MatchComponents( + MatchComponent memory a, + MatchComponent memory b, + MatchComponent memory c + ) internal pure returns (MatchComponent[] memory) { MatchComponent[] memory arr = new MatchComponent[](3); arr[0] = a; arr[1] = b; @@ -1975,11 +2028,10 @@ library MatchArrays { return arr; } - function MatchComponentsWithMaxLength(uint256 maxLength, MatchComponent memory a) - internal - pure - returns (MatchComponent[] memory) - { + function MatchComponentsWithMaxLength( + uint256 maxLength, + MatchComponent memory a + ) internal pure returns (MatchComponent[] memory) { MatchComponent[] memory arr = new MatchComponent[](maxLength); assembly { mstore(arr, 1) @@ -1988,11 +2040,11 @@ library MatchArrays { return arr; } - function MatchComponentsWithMaxLength(uint256 maxLength, MatchComponent memory a, MatchComponent memory b) - internal - pure - returns (MatchComponent[] memory) - { + function MatchComponentsWithMaxLength( + uint256 maxLength, + MatchComponent memory a, + MatchComponent memory b + ) internal pure returns (MatchComponent[] memory) { MatchComponent[] memory arr = new MatchComponent[](maxLength); assembly { mstore(arr, 2) @@ -2128,7 +2180,11 @@ library MatchArrays { } } - function allocateMatchComponents(uint256 length) internal pure returns (MatchComponent[] memory arr) { + function allocateMatchComponents(uint256 length) + internal + pure + returns (MatchComponent[] memory arr) + { arr = new MatchComponent[](length); assembly { mstore(arr, 0) @@ -2143,7 +2199,9 @@ library MatchArrays { // truncate the array assembly { let oldLength := mload(arr) - returndatacopy(returndatasize(), returndatasize(), gt(newLength, oldLength)) + returndatacopy( + returndatasize(), returndatasize(), gt(newLength, oldLength) + ) mstore(arr, newLength) _arr := arr } @@ -2177,11 +2235,10 @@ library MatchArrays { } } - function appendUnsafe(MatchComponent[] memory arr, MatchComponent memory value) - internal - pure - returns (MatchComponent[] memory modifiedArr) - { + function appendUnsafe( + MatchComponent[] memory arr, + MatchComponent memory value + ) internal pure returns (MatchComponent[] memory modifiedArr) { uint256 length = arr.length; modifiedArr = arr; assembly { @@ -2190,7 +2247,11 @@ library MatchArrays { } } - function copy(MatchComponent[] memory arr) internal pure returns (MatchComponent[] memory newArr) { + function copy(MatchComponent[] memory arr) + internal + pure + returns (MatchComponent[] memory newArr) + { uint256 length = arr.length; newArr = new MatchComponent[](length); for (uint256 i = 0; i < length;) { @@ -2237,7 +2298,11 @@ library MatchArrays { } } - function pop(MatchComponent[] memory arr) internal pure returns (MatchComponent memory value) { + function pop(MatchComponent[] memory arr) + internal + pure + returns (MatchComponent memory value) + { assembly { let length := mload(arr) returndatacopy(returndatasize(), returndatasize(), iszero(length)) @@ -2246,7 +2311,11 @@ library MatchArrays { } } - function popUnsafe(MatchComponent[] memory arr) internal pure returns (MatchComponent memory value) { + function popUnsafe(MatchComponent[] memory arr) + internal + pure + returns (MatchComponent memory value) + { // This function is unsafe because it does not check if the array is empty. assembly { let length := mload(arr) @@ -2283,7 +2352,11 @@ library MatchArrays { } } - function fromFixed(MatchComponent[1] memory arr) internal pure returns (MatchComponent[] memory newArr) { + function fromFixed(MatchComponent[1] memory arr) + internal + pure + returns (MatchComponent[] memory newArr) + { newArr = new MatchComponent[](1); for (uint256 i = 0; i < 1;) { newArr[i] = arr[i]; @@ -2293,11 +2366,10 @@ library MatchArrays { } } - function fromFixedWithMaxLength(MatchComponent[1] memory arr, uint256 maxLength) - internal - pure - returns (MatchComponent[] memory newArr) - { + function fromFixedWithMaxLength( + MatchComponent[1] memory arr, + uint256 maxLength + ) internal pure returns (MatchComponent[] memory newArr) { newArr = new MatchComponent[](maxLength); for (uint256 i = 0; i < 1;) { newArr[i] = arr[i]; @@ -2310,7 +2382,11 @@ library MatchArrays { } } - function fromFixed(MatchComponent[2] memory arr) internal pure returns (MatchComponent[] memory newArr) { + function fromFixed(MatchComponent[2] memory arr) + internal + pure + returns (MatchComponent[] memory newArr) + { newArr = new MatchComponent[](2); for (uint256 i = 0; i < 2;) { newArr[i] = arr[i]; @@ -2320,11 +2396,10 @@ library MatchArrays { } } - function fromFixedWithMaxLength(MatchComponent[2] memory arr, uint256 maxLength) - internal - pure - returns (MatchComponent[] memory newArr) - { + function fromFixedWithMaxLength( + MatchComponent[2] memory arr, + uint256 maxLength + ) internal pure returns (MatchComponent[] memory newArr) { newArr = new MatchComponent[](maxLength); for (uint256 i = 0; i < 2;) { newArr[i] = arr[i]; @@ -2337,7 +2412,11 @@ library MatchArrays { } } - function fromFixed(MatchComponent[3] memory arr) internal pure returns (MatchComponent[] memory newArr) { + function fromFixed(MatchComponent[3] memory arr) + internal + pure + returns (MatchComponent[] memory newArr) + { newArr = new MatchComponent[](3); for (uint256 i = 0; i < 3;) { newArr[i] = arr[i]; @@ -2347,11 +2426,10 @@ library MatchArrays { } } - function fromFixedWithMaxLength(MatchComponent[3] memory arr, uint256 maxLength) - internal - pure - returns (MatchComponent[] memory newArr) - { + function fromFixedWithMaxLength( + MatchComponent[3] memory arr, + uint256 maxLength + ) internal pure returns (MatchComponent[] memory newArr) { newArr = new MatchComponent[](maxLength); for (uint256 i = 0; i < 3;) { newArr[i] = arr[i]; @@ -2364,7 +2442,11 @@ library MatchArrays { } } - function fromFixed(MatchComponent[4] memory arr) internal pure returns (MatchComponent[] memory newArr) { + function fromFixed(MatchComponent[4] memory arr) + internal + pure + returns (MatchComponent[] memory newArr) + { newArr = new MatchComponent[](4); for (uint256 i = 0; i < 4;) { newArr[i] = arr[i]; @@ -2374,11 +2456,10 @@ library MatchArrays { } } - function fromFixedWithMaxLength(MatchComponent[4] memory arr, uint256 maxLength) - internal - pure - returns (MatchComponent[] memory newArr) - { + function fromFixedWithMaxLength( + MatchComponent[4] memory arr, + uint256 maxLength + ) internal pure returns (MatchComponent[] memory newArr) { newArr = new MatchComponent[](maxLength); for (uint256 i = 0; i < 4;) { newArr[i] = arr[i]; @@ -2391,7 +2472,11 @@ library MatchArrays { } } - function fromFixed(MatchComponent[5] memory arr) internal pure returns (MatchComponent[] memory newArr) { + function fromFixed(MatchComponent[5] memory arr) + internal + pure + returns (MatchComponent[] memory newArr) + { newArr = new MatchComponent[](5); for (uint256 i = 0; i < 5;) { newArr[i] = arr[i]; @@ -2401,11 +2486,10 @@ library MatchArrays { } } - function fromFixedWithMaxLength(MatchComponent[5] memory arr, uint256 maxLength) - internal - pure - returns (MatchComponent[] memory newArr) - { + function fromFixedWithMaxLength( + MatchComponent[5] memory arr, + uint256 maxLength + ) internal pure returns (MatchComponent[] memory newArr) { newArr = new MatchComponent[](maxLength); for (uint256 i = 0; i < 5;) { newArr[i] = arr[i]; @@ -2418,7 +2502,11 @@ library MatchArrays { } } - function fromFixed(MatchComponent[6] memory arr) internal pure returns (MatchComponent[] memory newArr) { + function fromFixed(MatchComponent[6] memory arr) + internal + pure + returns (MatchComponent[] memory newArr) + { newArr = new MatchComponent[](6); for (uint256 i = 0; i < 6;) { newArr[i] = arr[i]; @@ -2428,11 +2516,10 @@ library MatchArrays { } } - function fromFixedWithMaxLength(MatchComponent[6] memory arr, uint256 maxLength) - internal - pure - returns (MatchComponent[] memory newArr) - { + function fromFixedWithMaxLength( + MatchComponent[6] memory arr, + uint256 maxLength + ) internal pure returns (MatchComponent[] memory newArr) { newArr = new MatchComponent[](maxLength); for (uint256 i = 0; i < 6;) { newArr[i] = arr[i]; @@ -2445,7 +2532,11 @@ library MatchArrays { } } - function fromFixed(MatchComponent[7] memory arr) internal pure returns (MatchComponent[] memory newArr) { + function fromFixed(MatchComponent[7] memory arr) + internal + pure + returns (MatchComponent[] memory newArr) + { newArr = new MatchComponent[](7); for (uint256 i = 0; i < 7;) { newArr[i] = arr[i]; @@ -2455,11 +2546,10 @@ library MatchArrays { } } - function fromFixedWithMaxLength(MatchComponent[7] memory arr, uint256 maxLength) - internal - pure - returns (MatchComponent[] memory newArr) - { + function fromFixedWithMaxLength( + MatchComponent[7] memory arr, + uint256 maxLength + ) internal pure returns (MatchComponent[] memory newArr) { newArr = new MatchComponent[](maxLength); for (uint256 i = 0; i < 7;) { newArr[i] = arr[i]; @@ -2473,28 +2563,40 @@ library MatchArrays { } function uints(uint256 a) internal pure returns (uint256[] memory) { - uint256[] memory arr = new uint[](1); + uint256[] memory arr = new uint256[](1); arr[0] = a; return arr; } - function uints(uint256 a, uint256 b) internal pure returns (uint256[] memory) { - uint256[] memory arr = new uint[](2); + function uints(uint256 a, uint256 b) + internal + pure + returns (uint256[] memory) + { + uint256[] memory arr = new uint256[](2); arr[0] = a; arr[1] = b; return arr; } - function uints(uint256 a, uint256 b, uint256 c) internal pure returns (uint256[] memory) { - uint256[] memory arr = new uint[](3); + function uints(uint256 a, uint256 b, uint256 c) + internal + pure + returns (uint256[] memory) + { + uint256[] memory arr = new uint256[](3); arr[0] = a; arr[1] = b; arr[2] = c; return arr; } - function uints(uint256 a, uint256 b, uint256 c, uint256 d) internal pure returns (uint256[] memory) { - uint256[] memory arr = new uint[](4); + function uints(uint256 a, uint256 b, uint256 c, uint256 d) + internal + pure + returns (uint256[] memory) + { + uint256[] memory arr = new uint256[](4); arr[0] = a; arr[1] = b; arr[2] = c; @@ -2502,8 +2604,12 @@ library MatchArrays { return arr; } - function uints(uint256 a, uint256 b, uint256 c, uint256 d, uint256 e) internal pure returns (uint256[] memory) { - uint256[] memory arr = new uint[](5); + function uints(uint256 a, uint256 b, uint256 c, uint256 d, uint256 e) + internal + pure + returns (uint256[] memory) + { + uint256[] memory arr = new uint256[](5); arr[0] = a; arr[1] = b; arr[2] = c; @@ -2512,12 +2618,15 @@ library MatchArrays { return arr; } - function uints(uint256 a, uint256 b, uint256 c, uint256 d, uint256 e, uint256 f) - internal - pure - returns (uint256[] memory) - { - uint256[] memory arr = new uint[](6); + function uints( + uint256 a, + uint256 b, + uint256 c, + uint256 d, + uint256 e, + uint256 f + ) internal pure returns (uint256[] memory) { + uint256[] memory arr = new uint256[](6); arr[0] = a; arr[1] = b; arr[2] = c; @@ -2527,12 +2636,16 @@ library MatchArrays { return arr; } - function uints(uint256 a, uint256 b, uint256 c, uint256 d, uint256 e, uint256 f, uint256 g) - internal - pure - returns (uint256[] memory) - { - uint256[] memory arr = new uint[](7); + function uints( + uint256 a, + uint256 b, + uint256 c, + uint256 d, + uint256 e, + uint256 f, + uint256 g + ) internal pure returns (uint256[] memory) { + uint256[] memory arr = new uint256[](7); arr[0] = a; arr[1] = b; arr[2] = c; @@ -2543,8 +2656,12 @@ library MatchArrays { return arr; } - function uintsWithMaxLength(uint256 maxLength, uint256 a) internal pure returns (uint256[] memory) { - uint256[] memory arr = new uint[](maxLength); + function uintsWithMaxLength(uint256 maxLength, uint256 a) + internal + pure + returns (uint256[] memory) + { + uint256[] memory arr = new uint256[](maxLength); assembly { mstore(arr, 1) } @@ -2552,8 +2669,12 @@ library MatchArrays { return arr; } - function uintsWithMaxLength(uint256 maxLength, uint256 a, uint256 b) internal pure returns (uint256[] memory) { - uint256[] memory arr = new uint[](maxLength); + function uintsWithMaxLength(uint256 maxLength, uint256 a, uint256 b) + internal + pure + returns (uint256[] memory) + { + uint256[] memory arr = new uint256[](maxLength); assembly { mstore(arr, 2) } @@ -2562,12 +2683,13 @@ library MatchArrays { return arr; } - function uintsWithMaxLength(uint256 maxLength, uint256 a, uint256 b, uint256 c) - internal - pure - returns (uint256[] memory) - { - uint256[] memory arr = new uint[](maxLength); + function uintsWithMaxLength( + uint256 maxLength, + uint256 a, + uint256 b, + uint256 c + ) internal pure returns (uint256[] memory) { + uint256[] memory arr = new uint256[](maxLength); assembly { mstore(arr, 3) } @@ -2577,12 +2699,14 @@ library MatchArrays { return arr; } - function uintsWithMaxLength(uint256 maxLength, uint256 a, uint256 b, uint256 c, uint256 d) - internal - pure - returns (uint256[] memory) - { - uint256[] memory arr = new uint[](maxLength); + function uintsWithMaxLength( + uint256 maxLength, + uint256 a, + uint256 b, + uint256 c, + uint256 d + ) internal pure returns (uint256[] memory) { + uint256[] memory arr = new uint256[](maxLength); assembly { mstore(arr, 4) } @@ -2593,12 +2717,15 @@ library MatchArrays { return arr; } - function uintsWithMaxLength(uint256 maxLength, uint256 a, uint256 b, uint256 c, uint256 d, uint256 e) - internal - pure - returns (uint256[] memory) - { - uint256[] memory arr = new uint[](maxLength); + function uintsWithMaxLength( + uint256 maxLength, + uint256 a, + uint256 b, + uint256 c, + uint256 d, + uint256 e + ) internal pure returns (uint256[] memory) { + uint256[] memory arr = new uint256[](maxLength); assembly { mstore(arr, 5) } @@ -2610,12 +2737,16 @@ library MatchArrays { return arr; } - function uintsWithMaxLength(uint256 maxLength, uint256 a, uint256 b, uint256 c, uint256 d, uint256 e, uint256 f) - internal - pure - returns (uint256[] memory) - { - uint256[] memory arr = new uint[](maxLength); + function uintsWithMaxLength( + uint256 maxLength, + uint256 a, + uint256 b, + uint256 c, + uint256 d, + uint256 e, + uint256 f + ) internal pure returns (uint256[] memory) { + uint256[] memory arr = new uint256[](maxLength); assembly { mstore(arr, 6) } @@ -2638,7 +2769,7 @@ library MatchArrays { uint256 f, uint256 g ) internal pure returns (uint256[] memory) { - uint256[] memory arr = new uint[](maxLength); + uint256[] memory arr = new uint256[](maxLength); assembly { mstore(arr, 7) } @@ -2652,36 +2783,48 @@ library MatchArrays { return arr; } - function allocateUints(uint256 length) internal pure returns (uint256[] memory arr) { - arr = new uint[](length); + function allocateUints(uint256 length) + internal + pure + returns (uint256[] memory arr) + { + arr = new uint256[](length); assembly { mstore(arr, 0) } } function ints(int256 a) internal pure returns (int256[] memory) { - int256[] memory arr = new int[](1); + int256[] memory arr = new int256[](1); arr[0] = a; return arr; } function ints(int256 a, int256 b) internal pure returns (int256[] memory) { - int256[] memory arr = new int[](2); + int256[] memory arr = new int256[](2); arr[0] = a; arr[1] = b; return arr; } - function ints(int256 a, int256 b, int256 c) internal pure returns (int256[] memory) { - int256[] memory arr = new int[](3); + function ints(int256 a, int256 b, int256 c) + internal + pure + returns (int256[] memory) + { + int256[] memory arr = new int256[](3); arr[0] = a; arr[1] = b; arr[2] = c; return arr; } - function ints(int256 a, int256 b, int256 c, int256 d) internal pure returns (int256[] memory) { - int256[] memory arr = new int[](4); + function ints(int256 a, int256 b, int256 c, int256 d) + internal + pure + returns (int256[] memory) + { + int256[] memory arr = new int256[](4); arr[0] = a; arr[1] = b; arr[2] = c; @@ -2689,8 +2832,12 @@ library MatchArrays { return arr; } - function ints(int256 a, int256 b, int256 c, int256 d, int256 e) internal pure returns (int256[] memory) { - int256[] memory arr = new int[](5); + function ints(int256 a, int256 b, int256 c, int256 d, int256 e) + internal + pure + returns (int256[] memory) + { + int256[] memory arr = new int256[](5); arr[0] = a; arr[1] = b; arr[2] = c; @@ -2699,8 +2846,12 @@ library MatchArrays { return arr; } - function ints(int256 a, int256 b, int256 c, int256 d, int256 e, int256 f) internal pure returns (int256[] memory) { - int256[] memory arr = new int[](6); + function ints(int256 a, int256 b, int256 c, int256 d, int256 e, int256 f) + internal + pure + returns (int256[] memory) + { + int256[] memory arr = new int256[](6); arr[0] = a; arr[1] = b; arr[2] = c; @@ -2710,12 +2861,16 @@ library MatchArrays { return arr; } - function ints(int256 a, int256 b, int256 c, int256 d, int256 e, int256 f, int256 g) - internal - pure - returns (int256[] memory) - { - int256[] memory arr = new int[](7); + function ints( + int256 a, + int256 b, + int256 c, + int256 d, + int256 e, + int256 f, + int256 g + ) internal pure returns (int256[] memory) { + int256[] memory arr = new int256[](7); arr[0] = a; arr[1] = b; arr[2] = c; @@ -2726,8 +2881,12 @@ library MatchArrays { return arr; } - function intsWithMaxLength(uint256 maxLength, int256 a) internal pure returns (int256[] memory) { - int256[] memory arr = new int[](maxLength); + function intsWithMaxLength(uint256 maxLength, int256 a) + internal + pure + returns (int256[] memory) + { + int256[] memory arr = new int256[](maxLength); assembly { mstore(arr, 1) } @@ -2735,8 +2894,12 @@ library MatchArrays { return arr; } - function intsWithMaxLength(uint256 maxLength, int256 a, int256 b) internal pure returns (int256[] memory) { - int256[] memory arr = new int[](maxLength); + function intsWithMaxLength(uint256 maxLength, int256 a, int256 b) + internal + pure + returns (int256[] memory) + { + int256[] memory arr = new int256[](maxLength); assembly { mstore(arr, 2) } @@ -2750,7 +2913,7 @@ library MatchArrays { pure returns (int256[] memory) { - int256[] memory arr = new int[](maxLength); + int256[] memory arr = new int256[](maxLength); assembly { mstore(arr, 3) } @@ -2760,12 +2923,14 @@ library MatchArrays { return arr; } - function intsWithMaxLength(uint256 maxLength, int256 a, int256 b, int256 c, int256 d) - internal - pure - returns (int256[] memory) - { - int256[] memory arr = new int[](maxLength); + function intsWithMaxLength( + uint256 maxLength, + int256 a, + int256 b, + int256 c, + int256 d + ) internal pure returns (int256[] memory) { + int256[] memory arr = new int256[](maxLength); assembly { mstore(arr, 4) } @@ -2776,12 +2941,15 @@ library MatchArrays { return arr; } - function intsWithMaxLength(uint256 maxLength, int256 a, int256 b, int256 c, int256 d, int256 e) - internal - pure - returns (int256[] memory) - { - int256[] memory arr = new int[](maxLength); + function intsWithMaxLength( + uint256 maxLength, + int256 a, + int256 b, + int256 c, + int256 d, + int256 e + ) internal pure returns (int256[] memory) { + int256[] memory arr = new int256[](maxLength); assembly { mstore(arr, 5) } @@ -2793,12 +2961,16 @@ library MatchArrays { return arr; } - function intsWithMaxLength(uint256 maxLength, int256 a, int256 b, int256 c, int256 d, int256 e, int256 f) - internal - pure - returns (int256[] memory) - { - int256[] memory arr = new int[](maxLength); + function intsWithMaxLength( + uint256 maxLength, + int256 a, + int256 b, + int256 c, + int256 d, + int256 e, + int256 f + ) internal pure returns (int256[] memory) { + int256[] memory arr = new int256[](maxLength); assembly { mstore(arr, 6) } @@ -2811,12 +2983,17 @@ library MatchArrays { return arr; } - function intsWithMaxLength(uint256 maxLength, int256 a, int256 b, int256 c, int256 d, int256 e, int256 f, int256 g) - internal - pure - returns (int256[] memory) - { - int256[] memory arr = new int[](maxLength); + function intsWithMaxLength( + uint256 maxLength, + int256 a, + int256 b, + int256 c, + int256 d, + int256 e, + int256 f, + int256 g + ) internal pure returns (int256[] memory) { + int256[] memory arr = new int256[](maxLength); assembly { mstore(arr, 7) } @@ -2830,18 +3007,30 @@ library MatchArrays { return arr; } - function allocateInts(uint256 length) internal pure returns (int256[] memory arr) { - arr = new int[](length); + function allocateInts(uint256 length) + internal + pure + returns (int256[] memory arr) + { + arr = new int256[](length); assembly { mstore(arr, 0) } } - function amountKey(MatchComponent memory component) internal pure returns (uint256) { + function amountKey(MatchComponent memory component) + internal + pure + returns (uint256) + { return component.amount; } - function indexKey(MatchComponent memory component) internal pure returns (uint256) { + function indexKey(MatchComponent memory component) + internal + pure + returns (uint256) + { return (component.orderIndex << 8) | component.itemIndex; } @@ -2854,10 +3043,10 @@ library MatchArrays { } // Sorts the array in-place with intro-quicksort. - function sort(MatchComponent[] memory a, function(MatchComponent memory) internal pure returns (uint256) accessor) - internal - pure - { + function sort( + MatchComponent[] memory a, + function(MatchComponent memory) internal pure returns (uint256) accessor + ) internal pure { if (a.length < 2) { return; } diff --git a/src/fulfillments/lib/Structs.sol b/src/fulfillments/lib/Structs.sol index 97264bb..84d6422 100644 --- a/src/fulfillments/lib/Structs.sol +++ b/src/fulfillments/lib/Structs.sol @@ -1,11 +1,18 @@ // SPDX-License-Identifier: MIT pragma solidity ^0.8.17; -import {MatchComponent, MatchComponentType} from "../../lib/types/MatchComponentType.sol"; +import { + MatchComponent, + MatchComponentType +} from "../../lib/types/MatchComponentType.sol"; -import {FulfillmentComponent, SpentItem, ReceivedItem} from "../../SeaportStructs.sol"; +import { + FulfillmentComponent, + SpentItem, + ReceivedItem +} from "../../SeaportStructs.sol"; -import {UnavailableReason} from "../../SpaceEnums.sol"; +import { UnavailableReason } from "../../SpaceEnums.sol"; struct FulfillmentHelperCounterLayout { uint256 fulfillmentCounter; @@ -19,17 +26,29 @@ struct MatchFulfillmentStorageLayout { => mapping( uint256 /*identifier*/ => mapping( - address /*offerer*/ => mapping(bytes32 /*conduitKey*/ => MatchComponent[] /*components*/) + address /*offerer*/ + => mapping( + bytes32 /*conduitKey*/ => MatchComponent[] /*components*/ + ) ) ) ) offerMap; mapping( address /*recipient*/ - => mapping(address /*tokenContract*/ => mapping(uint256 /*identifier*/ => MatchComponent[] /*components*/)) + => mapping( + address /*tokenContract*/ + => mapping( + uint256 /*identifier*/ => MatchComponent[] /*components*/ + ) + ) ) considerationMap; // a given aggregatable consideration component will have its own set of aggregatable offer components - mapping(address /*token*/ => mapping(uint256 /*tokenId*/ => AggregatableOfferer[] /*offererEnumeration*/)) - tokenToOffererEnumeration; + mapping( + address /*token*/ + => mapping( + uint256 /*tokenId*/ => AggregatableOfferer[] /*offererEnumeration*/ + ) + ) tokenToOffererEnumeration; // aggregatable consideration components can be enumerated normally AggregatableConsideration[] considerationEnumeration; } @@ -40,14 +59,20 @@ struct FulfillAvailableHelperStorageLayout { => mapping( uint256 /*identifier*/ => mapping( - address /*offerer*/ => mapping(bytes32 /*conduitKey*/ => FulfillmentComponent[] /*components*/) + address /*offerer*/ + => mapping( + bytes32 /*conduitKey*/ => FulfillmentComponent[] /*components*/ + ) ) ) ) offerMap; mapping( address /*recipient*/ => mapping( - address /*tokenContract*/ => mapping(uint256 /*identifier*/ => FulfillmentComponent[] /*components*/) + address /*tokenContract*/ + => mapping( + uint256 /*identifier*/ => FulfillmentComponent[] /*components*/ + ) ) ) considerationMap; // a given aggregatable consideration component will have its own set of aggregatable offer components diff --git a/src/fulfillments/match/MatchFulfillmentHelper.sol b/src/fulfillments/match/MatchFulfillmentHelper.sol index 052554b..1b4cce5 100644 --- a/src/fulfillments/match/MatchFulfillmentHelper.sol +++ b/src/fulfillments/match/MatchFulfillmentHelper.sol @@ -8,7 +8,10 @@ import { OrderDetails, MatchFulfillmentStorageLayout } from "../lib/Structs.sol"; -import {MatchComponent, MatchComponentType} from "../../lib/types/MatchComponentType.sol"; +import { + MatchComponent, + MatchComponentType +} from "../../lib/types/MatchComponentType.sol"; import { FulfillmentComponent, Fulfillment, @@ -19,12 +22,13 @@ import { ReceivedItem, CriteriaResolver } from "../../SeaportStructs.sol"; -import {UnavailableReason} from "../../SpaceEnums.sol"; -import {MatchFulfillmentLib} from "./MatchFulfillmentLib.sol"; -import {MatchFulfillmentLayout} from "./MatchFulfillmentLayout.sol"; +import { UnavailableReason } from "../../SpaceEnums.sol"; +import { MatchFulfillmentLib } from "./MatchFulfillmentLib.sol"; +import { MatchFulfillmentLayout } from "./MatchFulfillmentLayout.sol"; -import {AmountDeriverHelper} from "../../lib/fulfillment/AmountDeriverHelper.sol"; -import {MatchArrays} from "../lib/MatchArrays.sol"; +import { AmountDeriverHelper } from + "../../lib/fulfillment/AmountDeriverHelper.sol"; +import { MatchArrays } from "../lib/MatchArrays.sol"; contract MatchFulfillmentHelper is AmountDeriverHelper { /** @@ -46,7 +50,8 @@ contract MatchFulfillmentHelper is AmountDeriverHelper { MatchComponent[] memory remainingConsiderationComponents ) { - OrderDetails[] memory orderDetails = toOrderDetails(orders, orderHashes, unavailableReasons); + OrderDetails[] memory orderDetails = + toOrderDetails(orders, orderHashes, unavailableReasons); return getMatchedFulfillments(orderDetails); } @@ -72,7 +77,8 @@ contract MatchFulfillmentHelper is AmountDeriverHelper { MatchComponent[] memory remainingConsiderationComponents ) { - OrderDetails[] memory details = toOrderDetails(orders, resolvers, orderHashes, unavailableReasons); + OrderDetails[] memory details = + toOrderDetails(orders, resolvers, orderHashes, unavailableReasons); return getMatchedFulfillments(details); } @@ -94,7 +100,8 @@ contract MatchFulfillmentHelper is AmountDeriverHelper { // increment counter to get clean mappings and enumeration MatchFulfillmentLayout.incrementFulfillmentCounter(); // load the storage layout - MatchFulfillmentStorageLayout storage layout = MatchFulfillmentLayout.getStorageLayout(); + MatchFulfillmentStorageLayout storage layout = + MatchFulfillmentLayout.getStorageLayout(); // iterate over each order and process the offer and consideration components for (uint256 i; i < orders.length; ++i) { @@ -103,7 +110,9 @@ contract MatchFulfillmentHelper is AmountDeriverHelper { // insert MatchComponents into the offer mapping, grouped by token, tokenId, offerer, and conduitKey // also update per-token+tokenId enumerations of AggregatableOfferer - preProcessSpentItems(details.offer, details.offerer, details.conduitKey, i, layout); + preProcessSpentItems( + details.offer, details.offerer, details.conduitKey, i, layout + ); // insert MatchComponents into the offer mapping, grouped by token, tokenId, and recipient // also update AggregatableConsideration enumeration preProcessSpentItems(details.consideration, i, layout); @@ -113,13 +122,15 @@ contract MatchFulfillmentHelper is AmountDeriverHelper { uint256 considerationLength = layout.considerationEnumeration.length; for (uint256 i; i < considerationLength; ++i) { // get the token information - AggregatableConsideration storage token = layout.considerationEnumeration[i]; + AggregatableConsideration storage token = + layout.considerationEnumeration[i]; // load the consideration components - MatchComponent[] storage considerationComponents = - layout.considerationMap[token.recipient][token.contractAddress][token.tokenId]; + MatchComponent[] storage considerationComponents = layout + .considerationMap[token.recipient][token.contractAddress][token + .tokenId]; // load the enumeration of offerer+conduit keys for offer components that match this token - AggregatableOfferer[] storage offererEnumeration = - layout.tokenToOffererEnumeration[token.contractAddress][token.tokenId]; + AggregatableOfferer[] storage offererEnumeration = layout + .tokenToOffererEnumeration[token.contractAddress][token.tokenId]; // iterate over each offerer+conduit with offer components that match this token and create matching fulfillments // this will update considerationComponents in-place in storage, which we check at the beginning of each loop for (uint256 j; j < offererEnumeration.length; ++j) { @@ -128,10 +139,12 @@ contract MatchFulfillmentHelper is AmountDeriverHelper { break; } // load the AggregatableOfferer - AggregatableOfferer storage aggregatableOfferer = offererEnumeration[j]; + AggregatableOfferer storage aggregatableOfferer = + offererEnumeration[j]; // load the associated offer components for this offerer+conduit - MatchComponent[] storage offerComponents = layout.offerMap[token.contractAddress][token.tokenId][aggregatableOfferer - .offerer][aggregatableOfferer.conduitKey]; + MatchComponent[] storage offerComponents = layout.offerMap[token + .contractAddress][token.tokenId][aggregatableOfferer.offerer][aggregatableOfferer + .conduitKey]; // if there are no offer components left, continue // TODO: remove from enumeration? if (offerComponents.length == 0) { @@ -139,8 +152,8 @@ contract MatchFulfillmentHelper is AmountDeriverHelper { } // create a fulfillment matching the offer and consideration components until either or both are exhausted - Fulfillment memory fulfillment = - MatchFulfillmentLib.createFulfillment(offerComponents, considerationComponents); + Fulfillment memory fulfillment = MatchFulfillmentLib + .createFulfillment(offerComponents, considerationComponents); // append the fulfillment to the array of fulfillments fulfillments = MatchArrays.append(fulfillments, fulfillment); // loop back around in case not all considerationComponents have been completely fulfilled @@ -155,15 +168,20 @@ contract MatchFulfillmentHelper is AmountDeriverHelper { // also update per-token+tokenId enumerations of AggregatableOfferer remainingOfferComponents = MatchArrays.extend( remainingOfferComponents, - postProcessSpentItems(details.offer, details.offerer, details.conduitKey, layout) + postProcessSpentItems( + details.offer, details.offerer, details.conduitKey, layout + ) ); remainingConsiderationComponents = MatchArrays.extend( - remainingConsiderationComponents, postProcessReceivedItems(details.consideration, layout) + remainingConsiderationComponents, + postProcessReceivedItems(details.consideration, layout) ); } - remainingOfferComponents = MatchFulfillmentLib.dedupe(remainingOfferComponents); - remainingConsiderationComponents = MatchFulfillmentLib.dedupe(remainingConsiderationComponents); + remainingOfferComponents = + MatchFulfillmentLib.dedupe(remainingOfferComponents); + remainingConsiderationComponents = + MatchFulfillmentLib.dedupe(remainingConsiderationComponents); } /** @@ -185,23 +203,30 @@ contract MatchFulfillmentHelper is AmountDeriverHelper { // grab offer item // TODO: spentItems? SpentItem memory item = offer[j]; - MatchComponent memory component = MatchComponentType.createMatchComponent({ + MatchComponent memory component = MatchComponentType + .createMatchComponent({ amount: uint240(item.amount), orderIndex: uint8(orderIndex), itemIndex: uint8(j) }); - AggregatableOfferer memory aggregatableOfferer = - AggregatableOfferer({offerer: offerer, conduitKey: conduitKey}); + AggregatableOfferer memory aggregatableOfferer = AggregatableOfferer({ + offerer: offerer, + conduitKey: conduitKey + }); // if it does not exist in the map, add it to our per-token+id enumeration if ( - !MatchFulfillmentLib.aggregatableOffererExists(item.token, item.identifier, aggregatableOfferer, layout) + !MatchFulfillmentLib.aggregatableOffererExists( + item.token, item.identifier, aggregatableOfferer, layout + ) ) { // add to enumeration for specific tokenhash (tokenAddress+tokenId) - layout.tokenToOffererEnumeration[item.token][item.identifier].push(aggregatableOfferer); + layout.tokenToOffererEnumeration[item.token][item.identifier] + .push(aggregatableOfferer); } // update aggregatable mapping array with this component - layout.offerMap[item.token][item.identifier][offerer][conduitKey].push(component); + layout.offerMap[item.token][item.identifier][offerer][conduitKey] + .push(component); } } @@ -219,7 +244,8 @@ contract MatchFulfillmentHelper is AmountDeriverHelper { // update aggregatable mapping array with this component remainingOfferComponents = MatchArrays.extend( - remainingOfferComponents, layout.offerMap[item.token][item.identifier][offerer][conduitKey] + remainingOfferComponents, + layout.offerMap[item.token][item.identifier][offerer][conduitKey] ); } } @@ -240,7 +266,8 @@ contract MatchFulfillmentHelper is AmountDeriverHelper { // grab consideration item ReceivedItem memory item = consideration[j]; // TODO: use receivedItem here? - MatchComponent memory component = MatchComponentType.createMatchComponent({ + MatchComponent memory component = MatchComponentType + .createMatchComponent({ amount: uint240(item.amount), orderIndex: uint8(orderIndex), itemIndex: uint8(j) @@ -252,15 +279,23 @@ contract MatchFulfillmentHelper is AmountDeriverHelper { tokenId: item.identifier }); // if it does not exist in the map, add it to our enumeration - if (!MatchFulfillmentLib.aggregatableConsiderationExists(token, layout)) { + if ( + !MatchFulfillmentLib.aggregatableConsiderationExists( + token, layout + ) + ) { layout.considerationEnumeration.push(token); } // update mapping with this component - layout.considerationMap[token.recipient][token.contractAddress][token.tokenId].push(component); + layout.considerationMap[token.recipient][token.contractAddress][token + .tokenId].push(component); } } - function postProcessReceivedItems(ReceivedItem[] memory consideration, MatchFulfillmentStorageLayout storage layout) + function postProcessReceivedItems( + ReceivedItem[] memory consideration, + MatchFulfillmentStorageLayout storage layout + ) private view returns (MatchComponent[] memory remainingConsiderationComponents) @@ -271,7 +306,9 @@ contract MatchFulfillmentHelper is AmountDeriverHelper { ReceivedItem memory item = consideration[j]; remainingConsiderationComponents = MatchArrays.extend( - remainingConsiderationComponents, layout.considerationMap[item.recipient][item.token][item.identifier] + remainingConsiderationComponents, + layout.considerationMap[item.recipient][item.token][item + .identifier] ); } } diff --git a/src/fulfillments/match/MatchFulfillmentLayout.sol b/src/fulfillments/match/MatchFulfillmentLayout.sol index 7737f62..a1d5ed5 100644 --- a/src/fulfillments/match/MatchFulfillmentLayout.sol +++ b/src/fulfillments/match/MatchFulfillmentLayout.sol @@ -1,20 +1,31 @@ // SPDX-License-Identifier: MIT pragma solidity ^0.8.17; -import {MatchComponent, MatchComponentType} from "../../lib/types/MatchComponentType.sol"; +import { + MatchComponent, + MatchComponentType +} from "../../lib/types/MatchComponentType.sol"; import { MatchFulfillmentStorageLayout, FulfillmentHelperCounterLayout, AggregatableConsideration } from "../lib/Structs.sol"; -import {MATCH_FULFILLMENT_COUNTER_KEY, MATCH_FULFILLMENT_STORAGE_BASE_KEY} from "../lib/Constants.sol"; +import { + MATCH_FULFILLMENT_COUNTER_KEY, + MATCH_FULFILLMENT_STORAGE_BASE_KEY +} from "../lib/Constants.sol"; library MatchFulfillmentLayout { /** * @notice load storage layout for the current fulfillmentCounter */ - function getStorageLayout() internal view returns (MatchFulfillmentStorageLayout storage layout) { - FulfillmentHelperCounterLayout storage counterLayout = getCounterLayout(); + function getStorageLayout() + internal + view + returns (MatchFulfillmentStorageLayout storage layout) + { + FulfillmentHelperCounterLayout storage counterLayout = + getCounterLayout(); uint256 counter = counterLayout.fulfillmentCounter; bytes32 storageLayoutKey = MATCH_FULFILLMENT_STORAGE_BASE_KEY; assembly { @@ -27,7 +38,11 @@ library MatchFulfillmentLayout { /** * @notice load storage layout for the counter itself */ - function getCounterLayout() internal pure returns (FulfillmentHelperCounterLayout storage layout) { + function getCounterLayout() + internal + pure + returns (FulfillmentHelperCounterLayout storage layout) + { bytes32 counterLayoutKey = MATCH_FULFILLMENT_COUNTER_KEY; assembly { layout.slot := counterLayoutKey @@ -38,7 +53,8 @@ library MatchFulfillmentLayout { * @notice increment the fulfillmentCounter to effectively clear the mappings and enumerations between calls */ function incrementFulfillmentCounter() internal { - FulfillmentHelperCounterLayout storage counterLayout = getCounterLayout(); + FulfillmentHelperCounterLayout storage counterLayout = + getCounterLayout(); counterLayout.fulfillmentCounter += 1; } @@ -52,7 +68,12 @@ library MatchFulfillmentLayout { returns ( mapping( address /*offererOrRecipient*/ - => mapping(address /*tokenContract*/ => mapping(uint256 /*identifier*/ => MatchComponent[] /*components*/)) + => mapping( + address /*tokenContract*/ + => mapping( + uint256 /*identifier*/ => MatchComponent[] /*components*/ + ) + ) ) storage map ) { @@ -68,7 +89,11 @@ library MatchFulfillmentLayout { * @notice Get the enumeration of AggregatableConsiderations for a given key (offer or consideration), derived from the hash of the key and the current fulfillmentCounter value * @param key Original key used to derive the slot of the enumeration */ - function getEnumeration(bytes32 key) internal view returns (AggregatableConsideration[] storage tokens) { + function getEnumeration(bytes32 key) + internal + view + returns (AggregatableConsideration[] storage tokens) + { bytes32 counterKey = MATCH_FULFILLMENT_COUNTER_KEY; assembly { mstore(0, key) diff --git a/src/fulfillments/match/MatchFulfillmentLib.sol b/src/fulfillments/match/MatchFulfillmentLib.sol index 0269f62..4c22ca6 100644 --- a/src/fulfillments/match/MatchFulfillmentLib.sol +++ b/src/fulfillments/match/MatchFulfillmentLib.sol @@ -7,10 +7,13 @@ import { MatchFulfillmentStorageLayout, AggregatableOfferer } from "../lib/Structs.sol"; -import {MatchComponent, MatchComponentType} from "../../lib/types/MatchComponentType.sol"; -import {FulfillmentComponent, Fulfillment} from "../../SeaportStructs.sol"; -import {LibSort} from "solady/src/utils/LibSort.sol"; -import {MatchArrays} from "../lib/MatchArrays.sol"; +import { + MatchComponent, + MatchComponentType +} from "../../lib/types/MatchComponentType.sol"; +import { FulfillmentComponent, Fulfillment } from "../../SeaportStructs.sol"; +import { LibSort } from "solady/src/utils/LibSort.sol"; +import { MatchArrays } from "../lib/MatchArrays.sol"; library MatchFulfillmentLib { using MatchComponentType for MatchComponent[]; @@ -25,7 +28,8 @@ library MatchFulfillmentLib { AggregatableConsideration memory token, MatchFulfillmentStorageLayout storage layout ) internal view returns (bool) { - return layout.considerationMap[token.recipient][token.contractAddress][token.tokenId].length > 0; + return layout.considerationMap[token.recipient][token.contractAddress][token + .tokenId].length > 0; } /** @@ -37,7 +41,8 @@ library MatchFulfillmentLib { AggregatableOfferer memory offerer, MatchFulfillmentStorageLayout storage layout ) internal view returns (bool) { - return layout.offerMap[token][tokenId][offerer.offerer][offerer.conduitKey].length > 0; + return layout.offerMap[token][tokenId][offerer.offerer][offerer + .conduitKey].length > 0; } function processConsiderationComponent( @@ -46,7 +51,8 @@ library MatchFulfillmentLib { ProcessComponentParams memory params ) internal { while (params.offerItemIndex < offerComponents.length) { - MatchComponent memory considerationComponent = considerationComponents[params.considerationItemIndex]; + MatchComponent memory considerationComponent = + considerationComponents[params.considerationItemIndex]; // if consideration has been completely credited, break to next consideration component if (considerationComponent.getAmount() == 0) { @@ -61,7 +67,8 @@ library MatchFulfillmentLib { MatchArrays.appendUnsafe( params.considerationFulfillmentComponents, - considerationComponents[params.considerationItemIndex].toFulfillmentComponent() + considerationComponents[params.considerationItemIndex] + .toFulfillmentComponent() ); } @@ -71,24 +78,30 @@ library MatchFulfillmentLib { ProcessComponentParams memory params ) internal { // re-load components each iteration as they may have been modified - MatchComponent memory offerComponent = offerComponents[params.offerItemIndex]; - MatchComponent memory considerationComponent = considerationComponents[params.considerationItemIndex]; + MatchComponent memory offerComponent = + offerComponents[params.offerItemIndex]; + MatchComponent memory considerationComponent = + considerationComponents[params.considerationItemIndex]; if (offerComponent.getAmount() > considerationComponent.getAmount()) { // if offer amount is greater than consideration amount, set consideration to zero and credit from offer amount - offerComponent = offerComponent.subtractAmount(considerationComponent); + offerComponent = + offerComponent.subtractAmount(considerationComponent); considerationComponent = considerationComponent.setAmount(0); offerComponents[params.offerItemIndex] = offerComponent; - considerationComponents[params.considerationItemIndex] = considerationComponent; + considerationComponents[params.considerationItemIndex] = + considerationComponent; // note that this offerItemIndex should be included when consolidating params.midCredit = true; } else { // otherwise deplete offer amount and credit consideration amount - considerationComponent = considerationComponent.subtractAmount(offerComponent); + considerationComponent = + considerationComponent.subtractAmount(offerComponent); offerComponent = offerComponent.setAmount(0); - considerationComponents[params.considerationItemIndex] = considerationComponent; + considerationComponents[params.considerationItemIndex] = + considerationComponent; offerComponents[params.offerItemIndex] = offerComponent; ++params.offerItemIndex; @@ -96,27 +109,38 @@ library MatchFulfillmentLib { params.midCredit = false; } // an offer component may have already been added if it was not depleted by an earlier consideration item - if (!previouslyAdded(params.offerFulfillmentComponents, offerComponent.toFulfillmentComponent())) { - MatchArrays.appendUnsafe(params.offerFulfillmentComponents, offerComponent.toFulfillmentComponent()); + if ( + !previouslyAdded( + params.offerFulfillmentComponents, + offerComponent.toFulfillmentComponent() + ) + ) { + MatchArrays.appendUnsafe( + params.offerFulfillmentComponents, + offerComponent.toFulfillmentComponent() + ); } } - function scuffLength(FulfillmentComponent[] memory components, uint256 newLength) internal pure { + function scuffLength( + FulfillmentComponent[] memory components, + uint256 newLength + ) internal pure { assembly { mstore(components, newLength) } } - function previouslyAdded(FulfillmentComponent[] memory components, FulfillmentComponent memory fulfillmentComponent) - internal - pure - returns (bool) - { + function previouslyAdded( + FulfillmentComponent[] memory components, + FulfillmentComponent memory fulfillmentComponent + ) internal pure returns (bool) { if (components.length == 0) { return false; } - FulfillmentComponent memory lastComponent = components[components.length - 1]; + FulfillmentComponent memory lastComponent = + components[components.length - 1]; return lastComponent.orderIndex == fulfillmentComponent.orderIndex && lastComponent.itemIndex == fulfillmentComponent.itemIndex; } @@ -135,7 +159,9 @@ library MatchFulfillmentLib { FulfillmentComponent[] memory offerFulfillmentComponents = MatchArrays.allocateFulfillmentComponents(offerComponents.length); FulfillmentComponent[] memory considerationFulfillmentComponents = - MatchArrays.allocateFulfillmentComponents(considerationComponents.length); + MatchArrays.allocateFulfillmentComponents( + considerationComponents.length + ); // iterate over consideration components ProcessComponentParams memory params = ProcessComponentParams({ offerFulfillmentComponents: offerFulfillmentComponents, @@ -170,14 +196,18 @@ library MatchFulfillmentLib { consolidateComponents( offerComponents, // if mid-credit, offerItemIndex should be included in consolidation - (params.midCredit) ? params.offerItemIndex + 1 : params.offerItemIndex + (params.midCredit) + ? params.offerItemIndex + 1 + : params.offerItemIndex ); // all eligible consideration components will be processed when matched // with the first eligible offer components, whether or not there are // enough offer items to credit each consideration item. This means // that all remaining amounts will be consolidated into the first // consideration component for later fulfillments. - consolidateComponents(considerationComponents, considerationComponents.length); + consolidateComponents( + considerationComponents, considerationComponents.length + ); // return a discrete fulfillment since either or both of the sets of components have been exhausted // if offer or consideration items remain, they will be revisited in subsequent calls @@ -194,7 +224,10 @@ library MatchFulfillmentLib { * offerComponents this is the index after the last credited item, * for considerationComponents, this is the length of the array */ - function consolidateComponents(MatchComponent[] storage components, uint256 excludeIndex) internal { + function consolidateComponents( + MatchComponent[] storage components, + uint256 excludeIndex + ) internal { // cache components in memory MatchComponent[] memory cachedComponents = components; if (cachedComponents.length == 0) { diff --git a/src/helm.sol b/src/helm.sol index 6d2f2b5..621a484 100644 --- a/src/helm.sol +++ b/src/helm.sol @@ -1,11 +1,16 @@ // SPDX-License-Identifier: MIT pragma solidity ^0.8.13; -import {console} from "forge-std/console.sol"; +import { console } from "forge-std/console.sol"; -import {LibString} from "solady/src/utils/LibString.sol"; +import { LibString } from "solady/src/utils/LibString.sol"; -import {BasicOrderType, ItemType, OrderType, Side} from "seaport-types/src/lib/ConsiderationEnums.sol"; +import { + BasicOrderType, + ItemType, + OrderType, + Side +} from "seaport-types/src/lib/ConsiderationEnums.sol"; import { AdditionalRecipient, @@ -25,12 +30,16 @@ import { ZoneParameters } from "seaport-types/src/lib/ConsiderationStructs.sol"; -import {ConduitItemType} from "seaport-types/src/conduit/lib/ConduitEnums.sol"; +import { ConduitItemType } from "seaport-types/src/conduit/lib/ConduitEnums.sol"; -import {ConduitBatch1155Transfer, ConduitTransfer} from "seaport-types/src/conduit/lib/ConduitStructs.sol"; +import { + ConduitBatch1155Transfer, + ConduitTransfer +} from "seaport-types/src/conduit/lib/ConduitStructs.sol"; import { - TransferHelperItem, TransferHelperItemsWithRecipient + TransferHelperItem, + TransferHelperItemsWithRecipient } from "seaport-types/src/helpers/TransferHelperStructs.sol"; import { @@ -61,7 +70,9 @@ import { MatchStrategy } from "./fulfillments/lib/FulfillmentLib.sol"; -import {FulfillmentDetails, OrderDetails} from "./fulfillments/lib/Structs.sol"; +import { + FulfillmentDetails, OrderDetails +} from "./fulfillments/lib/Structs.sol"; import { AdvancedOrdersSpace, @@ -129,7 +140,9 @@ library helm { console.log(gStr(i, "OfferItem: {")); console.log(gStr(i + 1, "itemType", _itemTypeStr(oi.itemType))); console.log(gStr(i + 1, "token", oi.token)); - console.log(gStr(i + 1, "identifierOrCriteria", oi.identifierOrCriteria)); + console.log( + gStr(i + 1, "identifierOrCriteria", oi.identifierOrCriteria) + ); console.log(gStr(i + 1, "startAmount", oi.startAmount)); console.log(gStr(i + 1, "endAmount", oi.endAmount)); console.log(gStr(i, "}")); @@ -139,7 +152,10 @@ library helm { logConsiderationItem(considerationItem, 0); } - function log(ConsiderationItem[] memory considerationItemArray) public view { + function log(ConsiderationItem[] memory considerationItemArray) + public + view + { console.log(gStr(0, "considerationItemArray: [")); for (uint256 j = 0; j < considerationItemArray.length; j++) { logConsiderationItem(considerationItemArray[j], 1); @@ -154,7 +170,9 @@ library helm { console.log(gStr(i, "ConsiderationItem: {")); console.log(gStr(i + 1, "itemType", _itemTypeStr(ci.itemType))); console.log(gStr(i + 1, "token", ci.token)); - console.log(gStr(i + 1, "identifierOrCriteria", ci.identifierOrCriteria)); + console.log( + gStr(i + 1, "identifierOrCriteria", ci.identifierOrCriteria) + ); console.log(gStr(i + 1, "startAmount", ci.startAmount)); console.log(gStr(i + 1, "endAmount", ci.endAmount)); console.log(gStr(i, "}")); @@ -209,11 +227,17 @@ library helm { console.log(gStr(i, "}")); } - function log(BasicOrderParameters memory basicOrderParameters) public view { + function log(BasicOrderParameters memory basicOrderParameters) + public + view + { logBasicOrderParameters(basicOrderParameters, 0); } - function log(BasicOrderParameters[] memory basicOrderParametersArray) public view { + function log(BasicOrderParameters[] memory basicOrderParametersArray) + public + view + { console.log(gStr(0, "basicOrderParametersArray: [")); for (uint256 j = 0; j < basicOrderParametersArray.length; j++) { logBasicOrderParameters(basicOrderParametersArray[j], 1); @@ -227,21 +251,33 @@ library helm { ) internal view { console.log(gStr(i, "BasicOrderParameters: {")); console.log(gStr(i + 1, "considerationToken", bop.considerationToken)); - console.log(gStr(i + 1, "considerationIdentifier", bop.considerationIdentifier)); + console.log( + gStr(i + 1, "considerationIdentifier", bop.considerationIdentifier) + ); console.log(gStr(i + 1, "considerationAmount", bop.considerationAmount)); console.log(gStr(i + 1, "offerer", bop.offerer)); console.log(gStr(i + 1, "zone", bop.zone)); console.log(gStr(i + 1, "offerToken", bop.offerToken)); console.log(gStr(i + 1, "offerIdentifier", bop.offerIdentifier)); console.log(gStr(i + 1, "offerAmount", bop.offerAmount)); - console.log(gStr(i + 1, "basicOrderType", _basicOrderTypeStr(bop.basicOrderType))); + console.log( + gStr( + i + 1, "basicOrderType", _basicOrderTypeStr(bop.basicOrderType) + ) + ); console.log(gStr(i + 1, "startTime", bop.startTime)); console.log(gStr(i + 1, "endTime", bop.endTime)); console.log(gStr(i + 1, "zoneHash", bop.zoneHash)); console.log(gStr(i + 1, "salt", bop.salt)); console.log(gStr(i + 1, "offererConduitKey", bop.offererConduitKey)); console.log(gStr(i + 1, "fulfillerConduitKey", bop.fulfillerConduitKey)); - console.log(gStr(i + 1, "totalOriginalAdditionalRecipients", bop.totalOriginalAdditionalRecipients)); + console.log( + gStr( + i + 1, + "totalOriginalAdditionalRecipients", + bop.totalOriginalAdditionalRecipients + ) + ); console.log(gStr(i + 1, "additionalRecipients: [")); for (uint256 j = 0; j < bop.additionalRecipients.length; j++) { logAdditionalRecipient(bop.additionalRecipients[j], i + 1); @@ -255,7 +291,10 @@ library helm { logAdditionalRecipient(additionalRecipient, 0); } - function log(AdditionalRecipient[] memory additionalRecipientArray) public view { + function log(AdditionalRecipient[] memory additionalRecipientArray) + public + view + { console.log(gStr(0, "additionalRecipientArray: [")); for (uint256 j = 0; j < additionalRecipientArray.length; j++) { logAdditionalRecipient(additionalRecipientArray[j], 1); @@ -300,7 +339,13 @@ library helm { console.log(gStr(i + 1, "zoneHash", op.zoneHash)); console.log(gStr(i + 1, "salt", op.salt)); console.log(gStr(i + 1, "conduitKey", op.conduitKey)); - console.log(gStr(i + 1, "totalOriginalConsiderationItems", op.totalOriginalConsiderationItems)); + console.log( + gStr( + i + 1, + "totalOriginalConsiderationItems", + op.totalOriginalConsiderationItems + ) + ); console.log(gStr(i, "}")); } @@ -316,7 +361,10 @@ library helm { console.log(gStr(0, "]")); } - function logOrder(Order memory order, uint256 i /* indent */ ) internal view { + function logOrder(Order memory order, uint256 i /* indent */ ) + internal + view + { console.log(gStr(i, "Order: {")); logOrderParameters(order.parameters, i + 1); console.log(gStr(i + 1, "signature", order.signature)); @@ -405,11 +453,17 @@ library helm { console.log(gStr(i, "}")); } - function log(FulfillmentComponent memory fulfillmentComponent) public view { + function log(FulfillmentComponent memory fulfillmentComponent) + public + view + { logFulfillmentComponent(fulfillmentComponent, 0); } - function log(FulfillmentComponent[] memory fulfillmentComponentArray) public view { + function log(FulfillmentComponent[] memory fulfillmentComponentArray) + public + view + { console.log(gStr(0, "fulfillmentComponentArray: [")); for (uint256 j = 0; j < fulfillmentComponentArray.length; j++) { logFulfillmentComponent(fulfillmentComponentArray[j], 1); @@ -518,11 +572,16 @@ library helm { console.log(gStr(i, "}")); } - function log(ConduitBatch1155Transfer memory conduitBatch1155Transfer) public view { + function log(ConduitBatch1155Transfer memory conduitBatch1155Transfer) + public + view + { logConduitBatch1155Transfer(conduitBatch1155Transfer, 0); } - function log(ConduitBatch1155Transfer[] memory conduitBatch1155TransferArray) public view { + function log( + ConduitBatch1155Transfer[] memory conduitBatch1155TransferArray + ) public view { console.log(gStr(0, "conduitBatch1155TransferArray: [")); for (uint256 j = 0; j < conduitBatch1155TransferArray.length; j++) { logConduitBatch1155Transfer(conduitBatch1155TransferArray[j], 1); @@ -555,7 +614,10 @@ library helm { logTransferHelperItem(transferHelperItem, 0); } - function log(TransferHelperItem[] memory transferHelperItemArray) public view { + function log(TransferHelperItem[] memory transferHelperItemArray) + public + view + { console.log(gStr(0, "transferHelperItemArray: [")); for (uint256 j = 0; j < transferHelperItemArray.length; j++) { logTransferHelperItem(transferHelperItemArray[j], 1); @@ -575,14 +637,23 @@ library helm { console.log(gStr(i, "}")); } - function log(TransferHelperItemsWithRecipient memory transferHelperItemsWithRecipient) public view { + function log( + TransferHelperItemsWithRecipient memory transferHelperItemsWithRecipient + ) public view { logTransferHelperItemsWithRecipient(transferHelperItemsWithRecipient, 0); } - function log(TransferHelperItemsWithRecipient[] memory transferHelperItemsWithRecipientArray) public view { + function log( + TransferHelperItemsWithRecipient[] memory + transferHelperItemsWithRecipientArray + ) public view { console.log(gStr(0, "transferHelperItemsWithRecipientArray: [")); - for (uint256 j = 0; j < transferHelperItemsWithRecipientArray.length; j++) { - logTransferHelperItemsWithRecipient(transferHelperItemsWithRecipientArray[j], 1); + for ( + uint256 j = 0; j < transferHelperItemsWithRecipientArray.length; j++ + ) { + logTransferHelperItemsWithRecipient( + transferHelperItemsWithRecipientArray[j], 1 + ); } console.log(gStr(0, "]")); } @@ -598,7 +669,9 @@ library helm { } 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 + 1, "validateERC721Receiver", thiwr.validateERC721Receiver) + ); console.log(gStr(i, "}")); } @@ -633,7 +706,13 @@ library helm { 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 + 1, + "unavailableReason", + _unavailableReasonStr(od.unavailableReason) + ) + ); console.log(gStr(i, "}")); } @@ -641,7 +720,10 @@ library helm { logFulfillmentDetails(fulfillmentDetails, 0); } - function log(FulfillmentDetails[] memory fulfillmentDetailsArray) public view { + function log(FulfillmentDetails[] memory fulfillmentDetailsArray) + public + view + { console.log(gStr(0, "fulfillmentDetailsArray: [")); for (uint256 j = 0; j < fulfillmentDetailsArray.length; j++) { logFulfillmentDetails(fulfillmentDetailsArray[j], 1); @@ -661,7 +743,9 @@ library helm { 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, "nativeTokensSupplied", fd.nativeTokensSupplied) + ); console.log(gStr(i + 1, "fulfillerConduitKey", fd.fulfillerConduitKey)); console.log(gStr(i + 1, "seaport", fd.seaport)); console.log(gStr(i, "}")); @@ -691,11 +775,17 @@ library helm { console.log(gStr(i, "}")); } - function log(ConsiderationItemSpace memory considerationItemSpace) public view { + function log(ConsiderationItemSpace memory considerationItemSpace) + public + view + { logConsiderationItemSpace(considerationItemSpace, 0); } - function log(ConsiderationItemSpace[] memory considerationItemSpaceArray) public view { + function log(ConsiderationItemSpace[] memory considerationItemSpaceArray) + public + view + { console.log(gStr(0, "considerationItemSpaceArray: [")); for (uint256 j = 0; j < considerationItemSpaceArray.length; j++) { logConsiderationItemSpace(considerationItemSpaceArray[j], 1); @@ -742,7 +832,10 @@ library helm { logReceivedItemSpace(receivedItemSpace, 0); } - function log(ReceivedItemSpace[] memory receivedItemSpaceArray) public view { + function log(ReceivedItemSpace[] memory receivedItemSpaceArray) + public + view + { console.log(gStr(0, "receivedItemSpaceArray: [")); for (uint256 j = 0; j < receivedItemSpaceArray.length; j++) { logReceivedItemSpace(receivedItemSpaceArray[j], 1); @@ -761,11 +854,17 @@ library helm { console.log(gStr(i, "}")); } - function log(OrderComponentsSpace memory orderComponentsSpace) public view { + function log(OrderComponentsSpace memory orderComponentsSpace) + public + view + { logOrderComponentsSpace(orderComponentsSpace, 0); } - function log(OrderComponentsSpace[] memory orderComponentsSpaceArray) public view { + function log(OrderComponentsSpace[] memory orderComponentsSpaceArray) + public + view + { console.log(gStr(0, "orderComponentsSpaceArray: [")); for (uint256 j = 0; j < orderComponentsSpaceArray.length; j++) { logOrderComponentsSpace(orderComponentsSpaceArray[j], 1); @@ -793,13 +892,31 @@ library helm { 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, + "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, + "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, "}")); @@ -809,7 +926,10 @@ library helm { logAdvancedOrdersSpace(advancedOrdersSpace, 0); } - function log(AdvancedOrdersSpace[] memory advancedOrdersSpaceArray) public view { + function log(AdvancedOrdersSpace[] memory advancedOrdersSpaceArray) + public + view + { console.log(gStr(0, "advancedOrdersSpaceArray: [")); for (uint256 j = 0; j < advancedOrdersSpaceArray.length; j++) { logAdvancedOrdersSpace(advancedOrdersSpaceArray[j], 1); @@ -829,7 +949,9 @@ library helm { 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, "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); @@ -840,7 +962,10 @@ library helm { logFulfillmentStrategy(fulfillmentStrategy, 0); } - function log(FulfillmentStrategy[] memory fulfillmentStrategyArray) public view { + function log(FulfillmentStrategy[] memory fulfillmentStrategyArray) + public + view + { console.log(gStr(0, "fulfillmentStrategyArray: [")); for (uint256 j = 0; j < fulfillmentStrategyArray.length; j++) { logFulfillmentStrategy(fulfillmentStrategyArray[j], 1); @@ -853,9 +978,23 @@ library helm { 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 + 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, "}")); } @@ -888,7 +1027,9 @@ library helm { string memory valueString ) public pure returns (string memory) { string memory indentString = generateIndentString(i); - return string.concat(indentString, string.concat(labelString, ": ", valueString)); + return string.concat( + indentString, string.concat(labelString, ": ", valueString) + ); } function gStr( @@ -897,7 +1038,10 @@ library helm { uint256 value ) public pure returns (string memory) { string memory indentString = generateIndentString(i); - return string.concat(indentString, string.concat(labelString, ": ", LibString.toString(value))); + return string.concat( + indentString, + string.concat(labelString, ": ", LibString.toString(value)) + ); } function gStr( @@ -906,7 +1050,10 @@ library helm { address value ) public pure returns (string memory) { string memory indentString = generateIndentString(i); - return string.concat(indentString, string.concat(labelString, ": ", LibString.toHexString(value))); + return string.concat( + indentString, + string.concat(labelString, ": ", LibString.toHexString(value)) + ); } function gStr( @@ -915,7 +1062,12 @@ library helm { bytes32 value ) public pure returns (string memory) { string memory indentString = generateIndentString(i); - return string.concat(indentString, string.concat(labelString, ": ", LibString.toHexString(uint256(value)))); + return string.concat( + indentString, + string.concat( + labelString, ": ", LibString.toHexString(uint256(value)) + ) + ); } function gStr( @@ -924,7 +1076,10 @@ library helm { bytes memory value ) public pure returns (string memory) { string memory indentString = generateIndentString(i); - return string.concat(indentString, string.concat(labelString, ": ", LibString.toHexString(value))); + return string.concat( + indentString, + string.concat(labelString, ": ", LibString.toHexString(value)) + ); } function gStr( @@ -933,14 +1088,20 @@ library helm { bool value ) public pure returns (string memory) { string memory indentString = generateIndentString(i); - return string.concat(indentString, string.concat(labelString, ": ", value ? "True" : "False")); + return string.concat( + indentString, + string.concat(labelString, ": ", value ? "True" : "False") + ); } //////////////////////////////////////////////////////////////////////////// // Log Arrays // //////////////////////////////////////////////////////////////////////////// - function logOffer(OfferItem[] memory offer, uint256 i /* indent */ ) public view { + function logOffer(OfferItem[] memory offer, uint256 i /* indent */ ) + public + view + { console.log(gStr(i, "offer: [")); for (uint256 j = 0; j < offer.length; j++) { logOfferItem(offer[j], i + 1); @@ -963,7 +1124,11 @@ library helm { // Get Enum String Values // //////////////////////////////////////////////////////////////////////////// - function _itemTypeStr(ItemType itemType) internal pure returns (string memory) { + function _itemTypeStr(ItemType itemType) + internal + pure + returns (string memory) + { if (itemType == ItemType.NATIVE) return "NATIVE"; if (itemType == ItemType.ERC20) return "ERC20"; if (itemType == ItemType.ERC721) return "ERC721"; @@ -978,7 +1143,11 @@ library helm { return "UNKNOWN"; } - function _orderTypeStr(OrderType orderType) internal pure returns (string memory) { + function _orderTypeStr(OrderType orderType) + internal + pure + returns (string memory) + { if (orderType == OrderType.FULL_OPEN) return "FULL_OPEN"; if (orderType == OrderType.PARTIAL_OPEN) return "PARTIAL_OPEN"; if (orderType == OrderType.FULL_RESTRICTED) return "FULL_RESTRICTED"; @@ -990,7 +1159,11 @@ library helm { return "UNKNOWN"; } - function _basicOrderTypeStr(BasicOrderType basicOrderType) internal pure returns (string memory) { + function _basicOrderTypeStr(BasicOrderType basicOrderType) + internal + pure + returns (string memory) + { if (basicOrderType == BasicOrderType.ETH_TO_ERC721_FULL_OPEN) { return "ETH_TO_ERC721_FULL_OPEN"; } @@ -1012,7 +1185,8 @@ library helm { if (basicOrderType == BasicOrderType.ETH_TO_ERC1155_FULL_RESTRICTED) { return "ETH_TO_ERC1155_FULL_RESTRICTED"; } - if (basicOrderType == BasicOrderType.ETH_TO_ERC1155_PARTIAL_RESTRICTED) { + if (basicOrderType == BasicOrderType.ETH_TO_ERC1155_PARTIAL_RESTRICTED) + { return "ETH_TO_ERC1155_PARTIAL_RESTRICTED"; } if (basicOrderType == BasicOrderType.ERC20_TO_ERC721_FULL_OPEN) { @@ -1024,7 +1198,8 @@ library helm { if (basicOrderType == BasicOrderType.ERC20_TO_ERC721_FULL_RESTRICTED) { return "ERC20_TO_ERC721_FULL_RESTRICTED"; } - if (basicOrderType == BasicOrderType.ERC20_TO_ERC721_PARTIAL_RESTRICTED) { + if (basicOrderType == BasicOrderType.ERC20_TO_ERC721_PARTIAL_RESTRICTED) + { return "ERC20_TO_ERC721_PARTIAL_RESTRICTED"; } if (basicOrderType == BasicOrderType.ERC20_TO_ERC1155_FULL_OPEN) { @@ -1036,7 +1211,9 @@ library helm { if (basicOrderType == BasicOrderType.ERC20_TO_ERC1155_FULL_RESTRICTED) { return "ERC20_TO_ERC1155_FULL_RESTRICTED"; } - if (basicOrderType == BasicOrderType.ERC20_TO_ERC1155_PARTIAL_RESTRICTED) { + if ( + basicOrderType == BasicOrderType.ERC20_TO_ERC1155_PARTIAL_RESTRICTED + ) { return "ERC20_TO_ERC1155_PARTIAL_RESTRICTED"; } if (basicOrderType == BasicOrderType.ERC721_TO_ERC20_FULL_OPEN) { @@ -1048,7 +1225,8 @@ library helm { if (basicOrderType == BasicOrderType.ERC721_TO_ERC20_FULL_RESTRICTED) { return "ERC721_TO_ERC20_FULL_RESTRICTED"; } - if (basicOrderType == BasicOrderType.ERC721_TO_ERC20_PARTIAL_RESTRICTED) { + if (basicOrderType == BasicOrderType.ERC721_TO_ERC20_PARTIAL_RESTRICTED) + { return "ERC721_TO_ERC20_PARTIAL_RESTRICTED"; } if (basicOrderType == BasicOrderType.ERC1155_TO_ERC20_FULL_OPEN) { @@ -1060,7 +1238,9 @@ library helm { if (basicOrderType == BasicOrderType.ERC1155_TO_ERC20_FULL_RESTRICTED) { return "ERC1155_TO_ERC20_FULL_RESTRICTED"; } - if (basicOrderType == BasicOrderType.ERC1155_TO_ERC20_PARTIAL_RESTRICTED) { + if ( + basicOrderType == BasicOrderType.ERC1155_TO_ERC20_PARTIAL_RESTRICTED + ) { return "ERC1155_TO_ERC20_PARTIAL_RESTRICTED"; } @@ -1074,7 +1254,11 @@ library helm { return "UNKNOWN"; } - function _conduitItemTypeStr(ConduitItemType conduitItemType) internal pure returns (string memory) { + 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"; @@ -1091,7 +1275,11 @@ library helm { return "UNKNOWN"; } - function _broadOrderTypeStr(BroadOrderType broadOrderType) internal pure returns (string memory) { + 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"; @@ -1111,7 +1299,11 @@ library helm { return "UNKNOWN"; } - function _conduitChoiceStr(ConduitChoice conduitChoice) internal pure returns (string memory) { + 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"; @@ -1119,30 +1311,49 @@ library helm { return "UNKNOWN"; } - function _contractOrderRebateStr(ContractOrderRebate contractOrderRebate) internal pure returns (string memory) { + 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) { + 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) { + if (contractOrderRebate == ContractOrderRebate.LESS_CONSIDERATION_ITEMS) + { return "LESS_CONSIDERATION_ITEMS"; } - if (contractOrderRebate == ContractOrderRebate.LESS_CONSIDERATION_ITEM_AMOUNTS) { + if ( + contractOrderRebate + == ContractOrderRebate.LESS_CONSIDERATION_ITEM_AMOUNTS + ) { return "LESS_CONSIDERATION_ITEM_AMOUNTS"; } return "UNKNOWN"; } - function _criteriaStr(Criteria criteria) internal pure returns (string memory) { + 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) { + 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"; @@ -1151,7 +1362,11 @@ library helm { return "UNKNOWN"; } - function _extraDataStr(ExtraData extraData) internal pure returns (string memory) { + function _extraDataStr(ExtraData extraData) + internal + pure + returns (string memory) + { if (extraData == ExtraData.NONE) return "NONE"; if (extraData == ExtraData.RANDOM) return "RANDOM"; @@ -1171,7 +1386,11 @@ library helm { return "UNKNOWN"; } - function _offererStr(Offerer offerer) internal pure returns (string memory) { + 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"; @@ -1181,7 +1400,11 @@ library helm { return "UNKNOWN"; } - function _recipientStr(Recipient recipient) internal pure returns (string memory) { + 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"; @@ -1191,12 +1414,18 @@ library helm { return "UNKNOWN"; } - function _signatureMethodStr(SignatureMethod signatureMethod) internal pure returns (string memory) { + 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"; + if (signatureMethod == SignatureMethod.SELF_AD_HOC) { + return "SELF_AD_HOC"; + } return "UNKNOWN"; } @@ -1218,7 +1447,11 @@ library helm { return "UNKNOWN"; } - function _tokenIndexStr(TokenIndex tokenIndex) internal pure returns (string memory) { + 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"; @@ -1226,14 +1459,30 @@ library helm { return "UNKNOWN"; } - function _unavailableReasonStr(UnavailableReason unavailableReason) internal pure returns (string memory) { - if (unavailableReason == UnavailableReason.AVAILABLE) return "AVAILABLE"; + 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"; + 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"; } @@ -1246,7 +1495,11 @@ library helm { return "UNKNOWN"; } - function _zoneHashStr(ZoneHash zoneHash) internal pure returns (string memory) { + 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"; @@ -1254,45 +1507,87 @@ library helm { return "UNKNOWN"; } - function _aggregationStrategyStr(AggregationStrategy aggregationStrategy) internal pure returns (string memory) { - if (aggregationStrategy == AggregationStrategy.MINIMUM) return "MINIMUM"; - if (aggregationStrategy == AggregationStrategy.MAXIMUM) return "MAXIMUM"; + 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) { + 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) { + if ( + fulfillAvailableStrategy + == FulfillAvailableStrategy.DROP_ALL_KEEP_FILTERED + ) { return "DROP_ALL_KEEP_FILTERED"; } - if (fulfillAvailableStrategy == FulfillAvailableStrategy.DROP_RANDOM_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) { + 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"; + 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/AdditionalRecipientLib.sol b/src/lib/AdditionalRecipientLib.sol index 6525a2b..4d04130 100644 --- a/src/lib/AdditionalRecipientLib.sol +++ b/src/lib/AdditionalRecipientLib.sol @@ -1,7 +1,8 @@ // SPDX-License-Identifier: MIT pragma solidity ^0.8.17; -import { AdditionalRecipient } from "seaport-types/src/lib/ConsiderationStructs.sol"; +import { AdditionalRecipient } from + "seaport-types/src/lib/ConsiderationStructs.sol"; import { StructCopier } from "./StructCopier.sol"; @@ -17,15 +18,11 @@ library AdditionalRecipientLib { keccak256("seaport.AdditionalRecipientDefaults"); bytes32 private constant ADDITIONAL_RECIPIENTS_MAP_POSITION = keccak256("seaport.AdditionalRecipientsDefaults"); - bytes32 private constant EMPTY_ADDITIONAL_RECIPIENT = - keccak256( - abi.encode( - AdditionalRecipient({ - amount: 0, - recipient: payable(address(0)) - }) - ) - ); + bytes32 private constant EMPTY_ADDITIONAL_RECIPIENT = keccak256( + abi.encode( + AdditionalRecipient({ amount: 0, recipient: payable(address(0)) }) + ) + ); /** * @dev Clears a default AdditionalRecipient from storage. @@ -33,8 +30,8 @@ library AdditionalRecipientLib { * @param defaultName the name of the default to clear */ function clear(string memory defaultName) internal { - mapping(string => AdditionalRecipient) - storage additionalRecipientMap = _additionalRecipientMap(); + mapping(string => AdditionalRecipient) storage additionalRecipientMap = + _additionalRecipientMap(); AdditionalRecipient storage item = additionalRecipientMap[defaultName]; clear(item); } @@ -69,11 +66,13 @@ library AdditionalRecipientLib { * * @return item the AdditionalRecipient retrieved from storage */ - function fromDefault( - string memory defaultName - ) internal view returns (AdditionalRecipient memory item) { - mapping(string => AdditionalRecipient) - storage additionalRecipientMap = _additionalRecipientMap(); + function fromDefault(string memory defaultName) + internal + view + returns (AdditionalRecipient memory item) + { + mapping(string => AdditionalRecipient) storage additionalRecipientMap = + _additionalRecipientMap(); item = additionalRecipientMap[defaultName]; if (keccak256(abi.encode(item)) == EMPTY_ADDITIONAL_RECIPIENT) { @@ -88,11 +87,13 @@ library AdditionalRecipientLib { * * @return items the AdditionalRecipients retrieved from storage */ - function fromDefaultMany( - string memory defaultName - ) internal view returns (AdditionalRecipient[] memory items) { - mapping(string => AdditionalRecipient[]) - storage additionalRecipientsMap = _additionalRecipientsMap(); + function fromDefaultMany(string memory defaultName) + internal + view + returns (AdditionalRecipient[] memory items) + { + mapping(string => AdditionalRecipient[]) storage additionalRecipientsMap = + _additionalRecipientsMap(); items = additionalRecipientsMap[defaultName]; if (items.length == 0) { @@ -112,8 +113,8 @@ library AdditionalRecipientLib { AdditionalRecipient memory additionalRecipient, string memory defaultName ) internal returns (AdditionalRecipient memory _additionalRecipient) { - mapping(string => AdditionalRecipient) - storage additionalRecipientMap = _additionalRecipientMap(); + mapping(string => AdditionalRecipient) storage additionalRecipientMap = + _additionalRecipientMap(); additionalRecipientMap[defaultName] = additionalRecipient; return additionalRecipient; } @@ -130,11 +131,10 @@ library AdditionalRecipientLib { AdditionalRecipient[] memory additionalRecipients, string memory defaultName ) internal returns (AdditionalRecipient[] memory _additionalRecipients) { - mapping(string => AdditionalRecipient[]) - storage additionalRecipientsMap = _additionalRecipientsMap(); + mapping(string => AdditionalRecipient[]) storage additionalRecipientsMap = + _additionalRecipientsMap(); StructCopier.setAdditionalRecipients( - additionalRecipientsMap[defaultName], - additionalRecipients + additionalRecipientsMap[defaultName], additionalRecipients ); return additionalRecipients; } @@ -146,14 +146,15 @@ library AdditionalRecipientLib { * * @custom:return additionalRecipient the copy of the AdditionalRecipient */ - function copy( - AdditionalRecipient memory item - ) internal pure returns (AdditionalRecipient memory) { - return - AdditionalRecipient({ - amount: item.amount, - recipient: item.recipient - }); + function copy(AdditionalRecipient memory item) + internal + pure + returns (AdditionalRecipient memory) + { + return AdditionalRecipient({ + amount: item.amount, + recipient: item.recipient + }); } /** @@ -163,12 +164,13 @@ library AdditionalRecipientLib { * * @custom:return additionalRecipients the copy of the AdditionalRecipients */ - function copy( - AdditionalRecipient[] memory items - ) internal pure returns (AdditionalRecipient[] memory) { - AdditionalRecipient[] memory copiedItems = new AdditionalRecipient[]( - items.length - ); + function copy(AdditionalRecipient[] memory items) + internal + pure + returns (AdditionalRecipient[] memory) + { + AdditionalRecipient[] memory copiedItems = + new AdditionalRecipient[](items.length); for (uint256 i = 0; i < items.length; i++) { copiedItems[i] = copy(items[i]); } @@ -195,8 +197,7 @@ library AdditionalRecipientLib { private pure returns ( - mapping(string => AdditionalRecipient) - storage additionalRecipientMap + mapping(string => AdditionalRecipient) storage additionalRecipientMap ) { bytes32 position = ADDITIONAL_RECIPIENT_MAP_POSITION; @@ -217,8 +218,7 @@ library AdditionalRecipientLib { private pure returns ( - mapping(string => AdditionalRecipient[]) - storage additionalRecipientsMap + mapping(string => AdditionalRecipient[]) storage additionalRecipientsMap ) { bytes32 position = ADDITIONAL_RECIPIENTS_MAP_POSITION; @@ -238,10 +238,11 @@ library AdditionalRecipientLib { * * @custom:return _item the modified AdditionalRecipient */ - function withAmount( - AdditionalRecipient memory item, - uint256 amount - ) internal pure returns (AdditionalRecipient memory) { + function withAmount(AdditionalRecipient memory item, uint256 amount) + internal + pure + returns (AdditionalRecipient memory) + { item.amount = amount; return item; } @@ -254,10 +255,11 @@ library AdditionalRecipientLib { * * @custom:return _item the modified AdditionalRecipient */ - function withRecipient( - AdditionalRecipient memory item, - address recipient - ) internal pure returns (AdditionalRecipient memory) { + function withRecipient(AdditionalRecipient memory item, address recipient) + internal + pure + returns (AdditionalRecipient memory) + { item.recipient = payable(recipient); return item; } diff --git a/src/lib/AdvancedOrderLib.sol b/src/lib/AdvancedOrderLib.sol index d591a67..1291543 100644 --- a/src/lib/AdvancedOrderLib.sol +++ b/src/lib/AdvancedOrderLib.sol @@ -16,17 +16,20 @@ import { SpentItem } from "seaport-types/src/lib/ConsiderationStructs.sol"; -import {BasicOrderType, ItemType} from "seaport-types/src/lib/ConsiderationEnums.sol"; +import { + BasicOrderType, + ItemType +} from "seaport-types/src/lib/ConsiderationEnums.sol"; -import {UnavailableReason} from "../SpaceEnums.sol"; +import { UnavailableReason } from "../SpaceEnums.sol"; -import {OrderParametersLib} from "./OrderParametersLib.sol"; +import { OrderParametersLib } from "./OrderParametersLib.sol"; -import {StructCopier} from "./StructCopier.sol"; +import { StructCopier } from "./StructCopier.sol"; -import {SeaportInterface} from "../SeaportInterface.sol"; +import { SeaportInterface } from "../SeaportInterface.sol"; -import {OrderDetails} from "../fulfillments/lib/Structs.sol"; +import { OrderDetails } from "../fulfillments/lib/Structs.sol"; struct ContractNonceDetails { bool set; @@ -42,8 +45,10 @@ struct ContractNonceDetails { * creation more readable. */ library AdvancedOrderLib { - bytes32 private constant ADVANCED_ORDER_MAP_POSITION = keccak256("seaport.AdvancedOrderDefaults"); - bytes32 private constant ADVANCED_ORDERS_MAP_POSITION = keccak256("seaport.AdvancedOrdersDefaults"); + bytes32 private constant ADVANCED_ORDER_MAP_POSITION = + keccak256("seaport.AdvancedOrderDefaults"); + bytes32 private constant ADVANCED_ORDERS_MAP_POSITION = + keccak256("seaport.AdvancedOrdersDefaults"); bytes32 private constant EMPTY_ADVANCED_ORDER = keccak256( abi.encode( AdvancedOrder({ @@ -76,7 +81,8 @@ library AdvancedOrderLib { * @param defaultName the name of the default to clear */ function clear(string memory defaultName) internal { - mapping(string => AdvancedOrder) storage advancedOrderMap = _advancedOrderMap(); + mapping(string => AdvancedOrder) storage advancedOrderMap = + _advancedOrderMap(); AdvancedOrder storage item = advancedOrderMap[defaultName]; clear(item); } @@ -114,8 +120,13 @@ library AdvancedOrderLib { * * @return item the AdvancedOrder retrieved from storage */ - function fromDefault(string memory defaultName) internal view returns (AdvancedOrder memory item) { - mapping(string => AdvancedOrder) storage advancedOrderMap = _advancedOrderMap(); + function fromDefault(string memory defaultName) + internal + view + returns (AdvancedOrder memory item) + { + mapping(string => AdvancedOrder) storage advancedOrderMap = + _advancedOrderMap(); item = advancedOrderMap[defaultName]; if (keccak256(abi.encode(item)) == EMPTY_ADVANCED_ORDER) { @@ -130,8 +141,13 @@ library AdvancedOrderLib { * * @return items the AdvancedOrders retrieved from storage */ - function fromDefaultMany(string memory defaultName) internal view returns (AdvancedOrder[] memory items) { - mapping(string => AdvancedOrder[]) storage advancedOrdersMap = _advancedOrdersMap(); + function fromDefaultMany(string memory defaultName) + internal + view + returns (AdvancedOrder[] memory items) + { + mapping(string => AdvancedOrder[]) storage advancedOrdersMap = + _advancedOrdersMap(); items = advancedOrdersMap[defaultName]; if (items.length == 0) { @@ -156,12 +172,15 @@ library AdvancedOrderLib { * * @return _advancedOrder the AdvancedOrder saved as a default */ - function saveDefault(AdvancedOrder memory advancedOrder, string memory defaultName) - internal - returns (AdvancedOrder memory _advancedOrder) - { - mapping(string => AdvancedOrder) storage advancedOrderMap = _advancedOrderMap(); - StructCopier.setAdvancedOrder(advancedOrderMap[defaultName], advancedOrder); + function saveDefault( + AdvancedOrder memory advancedOrder, + string memory defaultName + ) internal returns (AdvancedOrder memory _advancedOrder) { + mapping(string => AdvancedOrder) storage advancedOrderMap = + _advancedOrderMap(); + StructCopier.setAdvancedOrder( + advancedOrderMap[defaultName], advancedOrder + ); return advancedOrder; } @@ -173,12 +192,15 @@ library AdvancedOrderLib { * * @return _advancedOrders the AdvancedOrders saved as a default */ - function saveDefaultMany(AdvancedOrder[] memory advancedOrders, string memory defaultName) - internal - returns (AdvancedOrder[] memory _advancedOrders) - { - mapping(string => AdvancedOrder[]) storage advancedOrdersMap = _advancedOrdersMap(); - StructCopier.setAdvancedOrders(advancedOrdersMap[defaultName], advancedOrders); + function saveDefaultMany( + AdvancedOrder[] memory advancedOrders, + string memory defaultName + ) internal returns (AdvancedOrder[] memory _advancedOrders) { + mapping(string => AdvancedOrder[]) storage advancedOrdersMap = + _advancedOrdersMap(); + StructCopier.setAdvancedOrders( + advancedOrdersMap[defaultName], advancedOrders + ); return advancedOrders; } @@ -189,7 +211,11 @@ library AdvancedOrderLib { * * @custom:return item the copied AdvancedOrder */ - function copy(AdvancedOrder memory item) internal pure returns (AdvancedOrder memory) { + function copy(AdvancedOrder memory item) + internal + pure + returns (AdvancedOrder memory) + { return AdvancedOrder({ parameters: item.parameters.copy(), numerator: item.numerator, @@ -206,7 +232,11 @@ library AdvancedOrderLib { * * @custom:return items the copied AdvancedOrders */ - function copy(AdvancedOrder[] memory items) internal pure returns (AdvancedOrder[] memory) { + function copy(AdvancedOrder[] memory items) + internal + pure + returns (AdvancedOrder[] memory) + { AdvancedOrder[] memory copiedItems = new AdvancedOrder[](items.length); for (uint256 i = 0; i < items.length; i++) { copiedItems[i] = copy(items[i]); @@ -220,7 +250,11 @@ library AdvancedOrderLib { * @return advancedOrderMap the storage position of the default * AdvancedOrder map */ - function _advancedOrderMap() private pure returns (mapping(string => AdvancedOrder) storage advancedOrderMap) { + function _advancedOrderMap() + private + pure + returns (mapping(string => AdvancedOrder) storage advancedOrderMap) + { bytes32 position = ADVANCED_ORDER_MAP_POSITION; assembly { advancedOrderMap.slot := position @@ -233,7 +267,11 @@ library AdvancedOrderLib { * @return advancedOrdersMap the storage position of the default * AdvancedOrder array map */ - function _advancedOrdersMap() private pure returns (mapping(string => AdvancedOrder[]) storage advancedOrdersMap) { + function _advancedOrdersMap() + private + pure + returns (mapping(string => AdvancedOrder[]) storage advancedOrdersMap) + { bytes32 position = ADVANCED_ORDERS_MAP_POSITION; assembly { advancedOrdersMap.slot := position @@ -251,11 +289,10 @@ library AdvancedOrderLib { * * @custom:return _advancedOrder the configured AdvancedOrder */ - function withParameters(AdvancedOrder memory advancedOrder, OrderParameters memory parameters) - internal - pure - returns (AdvancedOrder memory) - { + function withParameters( + AdvancedOrder memory advancedOrder, + OrderParameters memory parameters + ) internal pure returns (AdvancedOrder memory) { advancedOrder.parameters = parameters.copy(); return advancedOrder; } @@ -268,11 +305,10 @@ library AdvancedOrderLib { * * @custom:return _advancedOrder the configured AdvancedOrder */ - function withNumerator(AdvancedOrder memory advancedOrder, uint120 numerator) - internal - pure - returns (AdvancedOrder memory) - { + function withNumerator( + AdvancedOrder memory advancedOrder, + uint120 numerator + ) internal pure returns (AdvancedOrder memory) { advancedOrder.numerator = numerator; return advancedOrder; } @@ -285,11 +321,10 @@ library AdvancedOrderLib { * * @custom:return _advancedOrder the configured AdvancedOrder */ - function withDenominator(AdvancedOrder memory advancedOrder, uint120 denominator) - internal - pure - returns (AdvancedOrder memory) - { + function withDenominator( + AdvancedOrder memory advancedOrder, + uint120 denominator + ) internal pure returns (AdvancedOrder memory) { advancedOrder.denominator = denominator; return advancedOrder; } @@ -302,11 +337,10 @@ library AdvancedOrderLib { * * @custom:return _advancedOrder the configured AdvancedOrder */ - function withSignature(AdvancedOrder memory advancedOrder, bytes memory signature) - internal - pure - returns (AdvancedOrder memory) - { + function withSignature( + AdvancedOrder memory advancedOrder, + bytes memory signature + ) internal pure returns (AdvancedOrder memory) { advancedOrder.signature = signature; return advancedOrder; } @@ -319,11 +353,10 @@ library AdvancedOrderLib { * * @custom:return _advancedOrder the configured AdvancedOrder */ - function withExtraData(AdvancedOrder memory advancedOrder, bytes memory extraData) - internal - pure - returns (AdvancedOrder memory) - { + function withExtraData( + AdvancedOrder memory advancedOrder, + bytes memory extraData + ) internal pure returns (AdvancedOrder memory) { advancedOrder.extraData = extraData; return advancedOrder; } @@ -335,7 +368,11 @@ library AdvancedOrderLib { * * @return order the converted Order */ - function toOrder(AdvancedOrder memory advancedOrder) internal pure returns (Order memory order) { + function toOrder(AdvancedOrder memory advancedOrder) + internal + pure + returns (Order memory order) + { order.parameters = advancedOrder.parameters.copy(); order.signature = advancedOrder.signature; } @@ -347,7 +384,11 @@ library AdvancedOrderLib { * * @return the converted Order[] */ - function toOrders(AdvancedOrder[] memory advancedOrders) internal pure returns (Order[] memory) { + function toOrders(AdvancedOrder[] memory advancedOrders) + internal + pure + returns (Order[] memory) + { Order[] memory orders = new Order[](advancedOrders.length); for (uint256 i; i < advancedOrders.length; ++i) { @@ -364,33 +405,48 @@ library AdvancedOrderLib { * * @return basicOrderParameters the BasicOrderParameters */ - function toBasicOrderParameters(AdvancedOrder memory advancedOrder, BasicOrderType basicOrderType) + function toBasicOrderParameters( + AdvancedOrder memory advancedOrder, + BasicOrderType basicOrderType + ) internal pure returns (BasicOrderParameters memory basicOrderParameters) { - basicOrderParameters.considerationToken = advancedOrder.parameters.consideration[0].token; - basicOrderParameters.considerationIdentifier = advancedOrder.parameters.consideration[0].identifierOrCriteria; - basicOrderParameters.considerationAmount = advancedOrder.parameters.consideration[0].endAmount; + basicOrderParameters.considerationToken = + advancedOrder.parameters.consideration[0].token; + basicOrderParameters.considerationIdentifier = + advancedOrder.parameters.consideration[0].identifierOrCriteria; + basicOrderParameters.considerationAmount = + advancedOrder.parameters.consideration[0].endAmount; basicOrderParameters.offerer = payable(advancedOrder.parameters.offerer); basicOrderParameters.zone = advancedOrder.parameters.zone; - basicOrderParameters.offerToken = advancedOrder.parameters.offer[0].token; - basicOrderParameters.offerIdentifier = advancedOrder.parameters.offer[0].identifierOrCriteria; - basicOrderParameters.offerAmount = advancedOrder.parameters.offer[0].endAmount; + basicOrderParameters.offerToken = + advancedOrder.parameters.offer[0].token; + basicOrderParameters.offerIdentifier = + advancedOrder.parameters.offer[0].identifierOrCriteria; + basicOrderParameters.offerAmount = + advancedOrder.parameters.offer[0].endAmount; basicOrderParameters.basicOrderType = basicOrderType; basicOrderParameters.startTime = advancedOrder.parameters.startTime; basicOrderParameters.endTime = advancedOrder.parameters.endTime; basicOrderParameters.zoneHash = advancedOrder.parameters.zoneHash; basicOrderParameters.salt = advancedOrder.parameters.salt; - basicOrderParameters.offererConduitKey = advancedOrder.parameters.conduitKey; - basicOrderParameters.fulfillerConduitKey = advancedOrder.parameters.conduitKey; + basicOrderParameters.offererConduitKey = + advancedOrder.parameters.conduitKey; + basicOrderParameters.fulfillerConduitKey = + advancedOrder.parameters.conduitKey; basicOrderParameters.totalOriginalAdditionalRecipients = advancedOrder.parameters.totalOriginalConsiderationItems - 1; AdditionalRecipient[] memory additionalRecipients = new AdditionalRecipient[]( - advancedOrder.parameters.consideration.length - 1 - ); - for (uint256 i = 1; i < advancedOrder.parameters.consideration.length; i++) { + advancedOrder.parameters.consideration.length - 1 + ); + for ( + uint256 i = 1; + i < advancedOrder.parameters.consideration.length; + i++ + ) { additionalRecipients[i - 1] = AdditionalRecipient({ recipient: advancedOrder.parameters.consideration[i].recipient, amount: advancedOrder.parameters.consideration[i].startAmount @@ -414,7 +470,10 @@ library AdvancedOrderLib { uint256 newEndAmount; OfferItem memory item = orderParams.offer[i]; - if (item.itemType == ItemType.ERC721 || item.itemType == ItemType.ERC721_WITH_CRITERIA) { + if ( + item.itemType == ItemType.ERC721 + || item.itemType == ItemType.ERC721_WITH_CRITERIA + ) { uint256 amount = uint256(order.denominator / order.numerator); newStartAmount = amount; newEndAmount = amount; @@ -439,7 +498,10 @@ library AdvancedOrderLib { uint256 newEndAmount; ConsiderationItem memory item = orderParams.consideration[i]; - if (item.itemType == ItemType.ERC721 || item.itemType == ItemType.ERC721_WITH_CRITERIA) { + if ( + item.itemType == ItemType.ERC721 + || item.itemType == ItemType.ERC721_WITH_CRITERIA + ) { uint256 amount = uint256(order.denominator / order.numerator); newStartAmount = amount; newEndAmount = amount; @@ -470,17 +532,24 @@ library AdvancedOrderLib { uint256 denominator ) internal pure returns (uint256 newStartAmount, uint256 newEndAmount) { if ( - startTime >= endTime || numerator > denominator || numerator == 0 || denominator == 0 + startTime >= endTime || numerator > denominator || numerator == 0 + || denominator == 0 || (originalStartAmount == 0 && originalEndAmount == 0) ) { - revert("AdvancedOrderLib: bad inputs to deriveFractionCompatibleAmounts"); + revert( + "AdvancedOrderLib: bad inputs to deriveFractionCompatibleAmounts" + ); } bool ensureNotHuge = originalStartAmount != originalEndAmount; - newStartAmount = minimalChange(originalStartAmount, numerator, denominator, ensureNotHuge); + newStartAmount = minimalChange( + originalStartAmount, numerator, denominator, ensureNotHuge + ); - newEndAmount = minimalChange(originalEndAmount, numerator, denominator, ensureNotHuge); + newEndAmount = minimalChange( + originalEndAmount, numerator, denominator, ensureNotHuge + ); if (newStartAmount == 0 && newEndAmount == 0) { revert("AdvancedOrderLib: derived amount will always be zero"); @@ -490,11 +559,12 @@ library AdvancedOrderLib { // Function to find the minimal change in the value so that it results in a // new value with no remainder when the numerator and the denominator are // applied. - function minimalChange(uint256 value, uint256 numerator, uint256 denominator, bool ensureNotHuge) - public - pure - returns (uint256 newValue) - { + function minimalChange( + uint256 value, + uint256 numerator, + uint256 denominator, + bool ensureNotHuge + ) public pure returns (uint256 newValue) { require(denominator != 0, "AdvancedOrderLib: no denominator supplied."); if (ensureNotHuge) { @@ -523,20 +593,26 @@ library AdvancedOrderLib { /** * @dev Get the orderHashes of an array of orders. */ - function getOrderHashes(AdvancedOrder[] memory orders, address seaport) internal view returns (bytes32[] memory) { + function getOrderHashes(AdvancedOrder[] memory orders, address seaport) + internal + view + returns (bytes32[] memory) + { SeaportInterface seaportInterface = SeaportInterface(seaport); bytes32[] memory orderHashes = new bytes32[](orders.length); // Array of (contract offerer, currentNonce) - ContractNonceDetails[] memory detailsArray = new ContractNonceDetails[]( - orders.length - ); + ContractNonceDetails[] memory detailsArray = + new ContractNonceDetails[](orders.length); for (uint256 i = 0; i < orders.length; ++i) { OrderParameters memory order = orders[i].parameters; bytes32 orderHash; - if (order.orderType == OrderType.CONTRACT && _hasValidTime(order.startTime, order.endTime)) { + if ( + order.orderType == OrderType.CONTRACT + && _hasValidTime(order.startTime, order.endTime) + ) { bool noneYetLocated = false; uint256 j = 0; uint256 currentNonce; @@ -552,17 +628,22 @@ library AdvancedOrderLib { } if (noneYetLocated) { - currentNonce = seaportInterface.getContractOffererNonce(order.offerer); - - detailsArray[j] = - ContractNonceDetails({set: true, offerer: order.offerer, currentNonce: currentNonce}); + currentNonce = + seaportInterface.getContractOffererNonce(order.offerer); + + detailsArray[j] = ContractNonceDetails({ + set: true, + offerer: order.offerer, + currentNonce: currentNonce + }); } uint256 shiftedOfferer = uint256(uint160(order.offerer)) << 96; orderHash = bytes32(shiftedOfferer ^ currentNonce); } else { - orderHash = getTipNeutralizedOrderHash(orders[i], seaportInterface); + orderHash = + getTipNeutralizedOrderHash(orders[i], seaportInterface); } orderHashes[i] = orderHash; @@ -571,7 +652,11 @@ library AdvancedOrderLib { return orderHashes; } - function _hasValidTime(uint256 startTime, uint256 endTime) internal view returns (bool) { + function _hasValidTime(uint256 startTime, uint256 endTime) + internal + view + returns (bool) + { return block.timestamp >= startTime && block.timestamp < endTime; } @@ -589,24 +674,24 @@ library AdvancedOrderLib { * different orders, so e.g. cancelling or validating order with a tip * on it is not the same as cancelling the order without a tip on it. */ - function getTipNeutralizedOrderHash(AdvancedOrder memory order, SeaportInterface seaport) - internal - view - returns (bytes32 orderHash) - { + function getTipNeutralizedOrderHash( + AdvancedOrder memory order, + SeaportInterface seaport + ) internal view returns (bytes32 orderHash) { // Get the counter of the order offerer. uint256 counter = seaport.getCounter(order.parameters.offerer); return getTipNeutralizedOrderHash(order, seaport, counter); } - function getTipNeutralizedOrderHash(AdvancedOrder memory order, SeaportInterface seaport, uint256 counter) - internal - view - returns (bytes32 orderHash) - { + function getTipNeutralizedOrderHash( + AdvancedOrder memory order, + SeaportInterface seaport, + uint256 counter + ) internal view returns (bytes32 orderHash) { // Get the OrderComponents from the OrderParameters. - OrderComponents memory components = (order.parameters.toOrderComponents(counter)); + OrderComponents memory components = + (order.parameters.toOrderComponents(counter)); // Get the length of the consideration array (which might have // additional consideration items set as tips). @@ -614,10 +699,12 @@ library AdvancedOrderLib { // Get the length of the consideration array without tips, which is // stored in the totalOriginalConsiderationItems field. - uint256 lengthSansTips = (order.parameters.totalOriginalConsiderationItems); + uint256 lengthSansTips = + (order.parameters.totalOriginalConsiderationItems); // Get a reference to the consideration array. - ConsiderationItem[] memory considerationSansTips = (components.consideration); + ConsiderationItem[] memory considerationSansTips = + (components.consideration); // Set proper length of the considerationSansTips array. assembly { @@ -639,13 +726,17 @@ library AdvancedOrderLib { bytes32[] memory orderHashes, UnavailableReason[] memory unavailableReasons ) internal view returns (OrderDetails[] memory) { - OrderDetails[] memory orderDetails = new OrderDetails[]( - advancedOrders.length - ); + OrderDetails[] memory orderDetails = + new OrderDetails[](advancedOrders.length); for (uint256 i = 0; i < advancedOrders.length; i++) { - orderDetails[i] = - toOrderDetails(advancedOrders[i], i, criteriaResolvers, orderHashes[i], unavailableReasons[i]); + orderDetails[i] = toOrderDetails( + advancedOrders[i], + i, + criteriaResolvers, + orderHashes[i], + unavailableReasons[i] + ); } return orderDetails; @@ -658,8 +749,11 @@ library AdvancedOrderLib { bytes32 orderHash, UnavailableReason unavailableReason ) internal view returns (OrderDetails memory) { - (SpentItem[] memory offer, ReceivedItem[] memory consideration) = - order.parameters.getSpentAndReceivedItems(order.numerator, order.denominator, orderIndex, resolvers); + (SpentItem[] memory offer, ReceivedItem[] memory consideration) = order + .parameters + .getSpentAndReceivedItems( + order.numerator, order.denominator, orderIndex, resolvers + ); return OrderDetails({ offerer: order.parameters.offerer, diff --git a/src/lib/ArrayLib.sol b/src/lib/ArrayLib.sol index 8c74c1f..9371cef 100644 --- a/src/lib/ArrayLib.sol +++ b/src/lib/ArrayLib.sol @@ -13,10 +13,9 @@ library ArrayLib { * @param array the array to set * @param values the values to set */ - function setBytes32s( - bytes32[] storage array, - bytes32[] memory values - ) internal { + function setBytes32s(bytes32[] storage array, bytes32[] memory values) + internal + { while (array.length > 0) { array.pop(); } @@ -32,9 +31,11 @@ library ArrayLib { * * @custom:return copiedArray the copied array */ - function copy( - bytes32[] memory array - ) internal pure returns (bytes32[] memory) { + function copy(bytes32[] memory array) + internal + pure + returns (bytes32[] memory) + { bytes32[] memory copiedArray = new bytes32[](array.length); for (uint256 i = 0; i < array.length; i++) { copiedArray[i] = array[i]; diff --git a/src/lib/BasicOrderParametersLib.sol b/src/lib/BasicOrderParametersLib.sol index 9f2f504..fb733d0 100644 --- a/src/lib/BasicOrderParametersLib.sol +++ b/src/lib/BasicOrderParametersLib.sol @@ -28,31 +28,30 @@ library BasicOrderParametersLib { keccak256("seaport.BasicOrderParametersDefaults"); bytes32 private constant BASIC_ORDER_PARAMETERS_ARRAY_MAP_POSITION = keccak256("seaport.BasicOrderParametersArrayDefaults"); - bytes32 private constant EMPTY_BASIC_ORDER_PARAMETERS = - keccak256( - abi.encode( - BasicOrderParameters({ - considerationToken: address(0), - considerationIdentifier: 0, - considerationAmount: 0, - offerer: payable(address(0)), - zone: address(0), - offerToken: address(0), - offerIdentifier: 0, - offerAmount: 0, - basicOrderType: BasicOrderType(0), - startTime: 0, - endTime: 0, - zoneHash: bytes32(0), - salt: 0, - offererConduitKey: bytes32(0), - fulfillerConduitKey: bytes32(0), - totalOriginalAdditionalRecipients: 0, - additionalRecipients: new AdditionalRecipient[](0), - signature: "" - }) - ) - ); + bytes32 private constant EMPTY_BASIC_ORDER_PARAMETERS = keccak256( + abi.encode( + BasicOrderParameters({ + considerationToken: address(0), + considerationIdentifier: 0, + considerationAmount: 0, + offerer: payable(address(0)), + zone: address(0), + offerToken: address(0), + offerIdentifier: 0, + offerAmount: 0, + basicOrderType: BasicOrderType(0), + startTime: 0, + endTime: 0, + zoneHash: bytes32(0), + salt: 0, + offererConduitKey: bytes32(0), + fulfillerConduitKey: bytes32(0), + totalOriginalAdditionalRecipients: 0, + additionalRecipients: new AdditionalRecipient[](0), + signature: "" + }) + ) + ); /** * @dev Clears a default BasicOrderParameters from storage. @@ -80,8 +79,7 @@ library BasicOrderParametersLib { basicParameters.fulfillerConduitKey = bytes32(0); basicParameters.totalOriginalAdditionalRecipients = 0; StructCopier.setAdditionalRecipients( - basicParameters.additionalRecipients, - additionalRecipients + basicParameters.additionalRecipients, additionalRecipients ); basicParameters.signature = new bytes(0); } @@ -91,9 +89,9 @@ library BasicOrderParametersLib { * * @param basicParametersArray the name of the default to clear */ - function clear( - BasicOrderParameters[] storage basicParametersArray - ) internal { + function clear(BasicOrderParameters[] storage basicParametersArray) + internal + { while (basicParametersArray.length > 0) { basicParametersArray[basicParametersArray.length - 1].clear(); basicParametersArray.pop(); @@ -106,11 +104,10 @@ library BasicOrderParametersLib { * @param defaultName the name of the default to clear */ function clear(string memory defaultName) internal { - mapping(string => BasicOrderParameters) - storage orderParametersMap = _orderParametersMap(); - BasicOrderParameters storage basicParameters = orderParametersMap[ - defaultName - ]; + mapping(string => BasicOrderParameters) storage orderParametersMap = + _orderParametersMap(); + BasicOrderParameters storage basicParameters = + orderParametersMap[defaultName]; basicParameters.clear(); } @@ -150,11 +147,13 @@ library BasicOrderParametersLib { * * @return item the selected default BasicOrderParameters */ - function fromDefault( - string memory defaultName - ) internal view returns (BasicOrderParameters memory item) { - mapping(string => BasicOrderParameters) - storage orderParametersMap = _orderParametersMap(); + function fromDefault(string memory defaultName) + internal + view + returns (BasicOrderParameters memory item) + { + mapping(string => BasicOrderParameters) storage orderParametersMap = + _orderParametersMap(); item = orderParametersMap[defaultName]; if (keccak256(abi.encode(item)) == EMPTY_BASIC_ORDER_PARAMETERS) { @@ -169,11 +168,13 @@ library BasicOrderParametersLib { * * @return items the selected default BasicOrderParameters array */ - function fromDefaultMany( - string memory defaultName - ) internal view returns (BasicOrderParameters[] memory items) { - mapping(string => BasicOrderParameters[]) - storage orderParametersArrayMap = _orderParametersArrayMap(); + function fromDefaultMany(string memory defaultName) + internal + view + returns (BasicOrderParameters[] memory items) + { + mapping(string => BasicOrderParameters[]) storage + orderParametersArrayMap = _orderParametersArrayMap(); items = orderParametersArrayMap[defaultName]; if (items.length == 0) { @@ -193,11 +194,10 @@ library BasicOrderParametersLib { BasicOrderParameters memory orderParameters, string memory defaultName ) internal returns (BasicOrderParameters memory _orderParameters) { - mapping(string => BasicOrderParameters) - storage orderParametersMap = _orderParametersMap(); - BasicOrderParameters storage destination = orderParametersMap[ - defaultName - ]; + mapping(string => BasicOrderParameters) storage orderParametersMap = + _orderParametersMap(); + BasicOrderParameters storage destination = + orderParametersMap[defaultName]; StructCopier.setBasicOrderParameters(destination, orderParameters); return orderParameters; } @@ -214,11 +214,10 @@ library BasicOrderParametersLib { BasicOrderParameters[] memory orderParameters, string memory defaultName ) internal returns (BasicOrderParameters[] memory _orderParameters) { - mapping(string => BasicOrderParameters[]) - storage orderParametersArrayMap = _orderParametersArrayMap(); - BasicOrderParameters[] storage destination = orderParametersArrayMap[ - defaultName - ]; + mapping(string => BasicOrderParameters[]) storage + orderParametersArrayMap = _orderParametersArrayMap(); + BasicOrderParameters[] storage destination = + orderParametersArrayMap[defaultName]; StructCopier.setBasicOrderParameters(destination, orderParameters); return orderParameters; } @@ -230,31 +229,32 @@ library BasicOrderParametersLib { * * @return copy the copied BasicOrderParameters */ - function copy( - BasicOrderParameters memory item - ) internal pure returns (BasicOrderParameters memory) { - return - BasicOrderParameters({ - considerationToken: item.considerationToken, - considerationIdentifier: item.considerationIdentifier, - considerationAmount: item.considerationAmount, - offerer: item.offerer, - zone: item.zone, - offerToken: item.offerToken, - offerIdentifier: item.offerIdentifier, - offerAmount: item.offerAmount, - basicOrderType: item.basicOrderType, - startTime: item.startTime, - endTime: item.endTime, - zoneHash: item.zoneHash, - salt: item.salt, - offererConduitKey: item.offererConduitKey, - fulfillerConduitKey: item.fulfillerConduitKey, - totalOriginalAdditionalRecipients: item - .totalOriginalAdditionalRecipients, - additionalRecipients: item.additionalRecipients.copy(), - signature: item.signature - }); + function copy(BasicOrderParameters memory item) + internal + pure + returns (BasicOrderParameters memory) + { + return BasicOrderParameters({ + considerationToken: item.considerationToken, + considerationIdentifier: item.considerationIdentifier, + considerationAmount: item.considerationAmount, + offerer: item.offerer, + zone: item.zone, + offerToken: item.offerToken, + offerIdentifier: item.offerIdentifier, + offerAmount: item.offerAmount, + basicOrderType: item.basicOrderType, + startTime: item.startTime, + endTime: item.endTime, + zoneHash: item.zoneHash, + salt: item.salt, + offererConduitKey: item.offererConduitKey, + fulfillerConduitKey: item.fulfillerConduitKey, + totalOriginalAdditionalRecipients: item + .totalOriginalAdditionalRecipients, + additionalRecipients: item.additionalRecipients.copy(), + signature: item.signature + }); } /** @@ -287,8 +287,7 @@ library BasicOrderParametersLib { private pure returns ( - mapping(string => BasicOrderParameters[]) - storage orderParametersArrayMap + mapping(string => BasicOrderParameters[]) storage orderParametersArrayMap ) { bytes32 position = BASIC_ORDER_PARAMETERS_ARRAY_MAP_POSITION; @@ -368,10 +367,11 @@ library BasicOrderParametersLib { * * @custom:return item the modified BasicOrderParameters */ - function withOfferer( - BasicOrderParameters memory item, - address value - ) internal pure returns (BasicOrderParameters memory) { + function withOfferer(BasicOrderParameters memory item, address value) + internal + pure + returns (BasicOrderParameters memory) + { item.offerer = payable(value); return item; } @@ -386,10 +386,11 @@ library BasicOrderParametersLib { * * @custom:return item the modified BasicOrderParameters */ - function withZone( - BasicOrderParameters memory item, - address value - ) internal pure returns (BasicOrderParameters memory) { + function withZone(BasicOrderParameters memory item, address value) + internal + pure + returns (BasicOrderParameters memory) + { item.zone = value; return item; } @@ -404,10 +405,11 @@ library BasicOrderParametersLib { * * @custom:return item the modified BasicOrderParameters */ - function withOfferToken( - BasicOrderParameters memory item, - address value - ) internal pure returns (BasicOrderParameters memory) { + function withOfferToken(BasicOrderParameters memory item, address value) + internal + pure + returns (BasicOrderParameters memory) + { item.offerToken = value; return item; } @@ -440,10 +442,11 @@ library BasicOrderParametersLib { * * @custom:return item the modified BasicOrderParameters */ - function withOfferAmount( - BasicOrderParameters memory item, - uint256 value - ) internal pure returns (BasicOrderParameters memory) { + function withOfferAmount(BasicOrderParameters memory item, uint256 value) + internal + pure + returns (BasicOrderParameters memory) + { item.offerAmount = value; return item; } @@ -476,10 +479,11 @@ library BasicOrderParametersLib { * * @custom:return item the modified BasicOrderParameters */ - function withStartTime( - BasicOrderParameters memory item, - uint256 value - ) internal pure returns (BasicOrderParameters memory) { + function withStartTime(BasicOrderParameters memory item, uint256 value) + internal + pure + returns (BasicOrderParameters memory) + { item.startTime = value; return item; } @@ -494,10 +498,11 @@ library BasicOrderParametersLib { * * @custom:return item the modified BasicOrderParameters */ - function withEndTime( - BasicOrderParameters memory item, - uint256 value - ) internal pure returns (BasicOrderParameters memory) { + function withEndTime(BasicOrderParameters memory item, uint256 value) + internal + pure + returns (BasicOrderParameters memory) + { item.endTime = value; return item; } @@ -512,10 +517,11 @@ library BasicOrderParametersLib { * * @custom:return item the modified BasicOrderParameters */ - function withZoneHash( - BasicOrderParameters memory item, - bytes32 value - ) internal pure returns (BasicOrderParameters memory) { + function withZoneHash(BasicOrderParameters memory item, bytes32 value) + internal + pure + returns (BasicOrderParameters memory) + { item.zoneHash = value; return item; } @@ -530,10 +536,11 @@ library BasicOrderParametersLib { * * @custom:return item the modified BasicOrderParameters */ - function withSalt( - BasicOrderParameters memory item, - uint256 value - ) internal pure returns (BasicOrderParameters memory) { + function withSalt(BasicOrderParameters memory item, uint256 value) + internal + pure + returns (BasicOrderParameters memory) + { item.salt = value; return item; } @@ -622,10 +629,11 @@ library BasicOrderParametersLib { * * @custom:return item the modified BasicOrderParameters */ - function withSignature( - BasicOrderParameters memory item, - bytes memory value - ) internal pure returns (BasicOrderParameters memory) { + function withSignature(BasicOrderParameters memory item, bytes memory value) + internal + pure + returns (BasicOrderParameters memory) + { item.signature = value; return item; } diff --git a/src/lib/ConsiderationItemLib.sol b/src/lib/ConsiderationItemLib.sol index 0165db4..2b4d76e 100644 --- a/src/lib/ConsiderationItemLib.sol +++ b/src/lib/ConsiderationItemLib.sol @@ -1,11 +1,16 @@ // SPDX-License-Identifier: MIT pragma solidity ^0.8.17; -import {ConsiderationItem, OfferItem, ReceivedItem, SpentItem} from "seaport-types/src/lib/ConsiderationStructs.sol"; +import { + ConsiderationItem, + OfferItem, + ReceivedItem, + SpentItem +} from "seaport-types/src/lib/ConsiderationStructs.sol"; -import {ItemType} from "seaport-types/src/lib/ConsiderationEnums.sol"; +import { ItemType } from "seaport-types/src/lib/ConsiderationEnums.sol"; -import {StructCopier} from "./StructCopier.sol"; +import { StructCopier } from "./StructCopier.sol"; /** * @title ConsiderationItemLib @@ -15,8 +20,10 @@ import {StructCopier} from "./StructCopier.sol"; * struct creation more readable. */ library ConsiderationItemLib { - bytes32 private constant CONSIDERATION_ITEM_MAP_POSITION = keccak256("seaport.ConsiderationItemDefaults"); - bytes32 private constant CONSIDERATION_ITEMS_MAP_POSITION = keccak256("seaport.ConsiderationItemsDefaults"); + bytes32 private constant CONSIDERATION_ITEM_MAP_POSITION = + keccak256("seaport.ConsiderationItemDefaults"); + bytes32 private constant CONSIDERATION_ITEMS_MAP_POSITION = + keccak256("seaport.ConsiderationItemsDefaults"); bytes32 private constant EMPTY_CONSIDERATION_ITEM = keccak256( abi.encode( ConsiderationItem({ @@ -51,7 +58,8 @@ library ConsiderationItemLib { * @param defaultName the name of the default to clear */ function clear(string memory defaultName) internal { - mapping(string => ConsiderationItem) storage considerationItemMap = _considerationItemMap(); + mapping(string => ConsiderationItem) storage considerationItemMap = + _considerationItemMap(); ConsiderationItem storage item = considerationItemMap[defaultName]; _clear(item); } @@ -62,7 +70,8 @@ library ConsiderationItemLib { * @param defaultsName the name of the array to clear */ function clearMany(string memory defaultsName) internal { - mapping(string => ConsiderationItem[]) storage considerationItemsMap = _considerationItemsMap(); + mapping(string => ConsiderationItem[]) storage considerationItemsMap = + _considerationItemsMap(); ConsiderationItem[] storage items = considerationItemsMap[defaultsName]; while (items.length > 0) { _clear(items[items.length - 1]); @@ -77,8 +86,13 @@ library ConsiderationItemLib { * * @return item the ConsiderationItem retrieved from storage */ - function fromDefault(string memory defaultName) internal view returns (ConsiderationItem memory item) { - mapping(string => ConsiderationItem) storage considerationItemMap = _considerationItemMap(); + function fromDefault(string memory defaultName) + internal + view + returns (ConsiderationItem memory item) + { + mapping(string => ConsiderationItem) storage considerationItemMap = + _considerationItemMap(); item = considerationItemMap[defaultName]; if (keccak256(abi.encode(item)) == EMPTY_CONSIDERATION_ITEM) { @@ -93,8 +107,13 @@ library ConsiderationItemLib { * * @return items the array of ConsiderationItems retrieved from storage */ - function fromDefaultMany(string memory defaultsName) internal view returns (ConsiderationItem[] memory items) { - mapping(string => ConsiderationItem[]) storage considerationItemsMap = _considerationItemsMap(); + function fromDefaultMany(string memory defaultsName) + internal + view + returns (ConsiderationItem[] memory items) + { + mapping(string => ConsiderationItem[]) storage considerationItemsMap = + _considerationItemsMap(); items = considerationItemsMap[defaultsName]; if (items.length == 0) { @@ -127,11 +146,12 @@ library ConsiderationItemLib { * * @return _considerationItem the saved ConsiderationItem */ - function saveDefault(ConsiderationItem memory considerationItem, string memory defaultName) - internal - returns (ConsiderationItem memory _considerationItem) - { - mapping(string => ConsiderationItem) storage considerationItemMap = _considerationItemMap(); + function saveDefault( + ConsiderationItem memory considerationItem, + string memory defaultName + ) internal returns (ConsiderationItem memory _considerationItem) { + mapping(string => ConsiderationItem) storage considerationItemMap = + _considerationItemMap(); considerationItemMap[defaultName] = considerationItem; return considerationItem; } @@ -145,11 +165,12 @@ library ConsiderationItemLib { * * @return _considerationItems the saved array of ConsiderationItems */ - function saveDefaultMany(ConsiderationItem[] memory considerationItems, string memory defaultsName) - internal - returns (ConsiderationItem[] memory _considerationItems) - { - mapping(string => ConsiderationItem[]) storage considerationItemsMap = _considerationItemsMap(); + function saveDefaultMany( + ConsiderationItem[] memory considerationItems, + string memory defaultsName + ) internal returns (ConsiderationItem[] memory _considerationItems) { + mapping(string => ConsiderationItem[]) storage considerationItemsMap = + _considerationItemsMap(); ConsiderationItem[] storage items = considerationItemsMap[defaultsName]; clearMany(defaultsName); StructCopier.setConsiderationItems(items, considerationItems); @@ -163,7 +184,11 @@ library ConsiderationItemLib { * * @custom:return copy the copy of the ConsiderationItem */ - function copy(ConsiderationItem memory item) internal pure returns (ConsiderationItem memory) { + function copy(ConsiderationItem memory item) + internal + pure + returns (ConsiderationItem memory) + { return ConsiderationItem({ itemType: item.itemType, token: item.token, @@ -181,10 +206,13 @@ library ConsiderationItemLib { * * @custom:return copy the copy of the array of ConsiderationItems */ - function copy(ConsiderationItem[] memory items) internal pure returns (ConsiderationItem[] memory) { - ConsiderationItem[] memory copies = new ConsiderationItem[]( - items.length - ); + function copy(ConsiderationItem[] memory items) + internal + pure + returns (ConsiderationItem[] memory) + { + ConsiderationItem[] memory copies = + new ConsiderationItem[](items.length); for (uint256 i = 0; i < items.length; i++) { copies[i] = ConsiderationItem({ itemType: items[i].itemType, @@ -207,7 +235,9 @@ library ConsiderationItemLib { function _considerationItemMap() private pure - returns (mapping(string => ConsiderationItem) storage considerationItemMap) + returns ( + mapping(string => ConsiderationItem) storage considerationItemMap + ) { bytes32 position = CONSIDERATION_ITEM_MAP_POSITION; assembly { @@ -225,7 +255,9 @@ library ConsiderationItemLib { function _considerationItemsMap() private pure - returns (mapping(string => ConsiderationItem[]) storage considerationItemsMap) + returns ( + mapping(string => ConsiderationItem[]) storage considerationItemsMap + ) { bytes32 position = CONSIDERATION_ITEMS_MAP_POSITION; assembly { @@ -261,7 +293,11 @@ library ConsiderationItemLib { * * @custom:return item the modified ConsiderationItem */ - function withToken(ConsiderationItem memory item, address token) internal pure returns (ConsiderationItem memory) { + function withToken(ConsiderationItem memory item, address token) + internal + pure + returns (ConsiderationItem memory) + { item.token = token; return item; } @@ -274,11 +310,10 @@ library ConsiderationItemLib { * * @custom:return item the modified ConsiderationItem */ - function withIdentifierOrCriteria(ConsiderationItem memory item, uint256 identifierOrCriteria) - internal - pure - returns (ConsiderationItem memory) - { + function withIdentifierOrCriteria( + ConsiderationItem memory item, + uint256 identifierOrCriteria + ) internal pure returns (ConsiderationItem memory) { item.identifierOrCriteria = identifierOrCriteria; return item; } @@ -359,7 +394,11 @@ library ConsiderationItemLib { * * @custom:return receivedItem the converted ReceivedItem */ - function toReceivedItem(ConsiderationItem memory item) internal pure returns (ReceivedItem memory) { + function toReceivedItem(ConsiderationItem memory item) + internal + pure + returns (ReceivedItem memory) + { return ReceivedItem({ itemType: item.itemType, token: item.token, @@ -369,7 +408,11 @@ library ConsiderationItemLib { }); } - function toReceivedItemArray(ConsiderationItem[] memory items) internal pure returns (ReceivedItem[] memory) { + function toReceivedItemArray(ConsiderationItem[] memory items) + internal + pure + returns (ReceivedItem[] memory) + { ReceivedItem[] memory receivedItems = new ReceivedItem[](items.length); for (uint256 i = 0; i < items.length; i++) { receivedItems[i] = toReceivedItem(items[i]); @@ -377,7 +420,11 @@ library ConsiderationItemLib { return receivedItems; } - function toSpentItem(ConsiderationItem memory item) internal pure returns (SpentItem memory) { + function toSpentItem(ConsiderationItem memory item) + internal + pure + returns (SpentItem memory) + { return SpentItem({ itemType: item.itemType, token: item.token, @@ -386,7 +433,11 @@ library ConsiderationItemLib { }); } - function toSpentItemArray(ConsiderationItem[] memory items) internal pure returns (SpentItem[] memory) { + function toSpentItemArray(ConsiderationItem[] memory items) + internal + pure + returns (SpentItem[] memory) + { SpentItem[] memory spentItems = new SpentItem[](items.length); for (uint256 i = 0; i < items.length; i++) { spentItems[i] = toSpentItem(items[i]); @@ -394,7 +445,11 @@ library ConsiderationItemLib { return spentItems; } - function toOfferItem(ConsiderationItem memory item) internal pure returns (OfferItem memory) { + function toOfferItem(ConsiderationItem memory item) + internal + pure + returns (OfferItem memory) + { return OfferItem({ itemType: item.itemType, token: item.token, diff --git a/src/lib/CriteriaResolverLib.sol b/src/lib/CriteriaResolverLib.sol index 32250d4..a9c785c 100644 --- a/src/lib/CriteriaResolverLib.sol +++ b/src/lib/CriteriaResolverLib.sol @@ -1,7 +1,8 @@ // SPDX-License-Identifier: MIT pragma solidity ^0.8.17; -import { CriteriaResolver } from "seaport-types/src/lib/ConsiderationStructs.sol"; +import { CriteriaResolver } from + "seaport-types/src/lib/ConsiderationStructs.sol"; import { Side } from "seaport-types/src/lib/ConsiderationEnums.sol"; @@ -21,18 +22,17 @@ library CriteriaResolverLib { keccak256("seaport.CriteriaResolverDefaults"); bytes32 private constant CRITERIA_RESOLVERS_MAP_POSITION = keccak256("seaport.CriteriaResolversDefaults"); - bytes32 private constant EMPTY_CRITERIA_RESOLVER = - keccak256( - abi.encode( - CriteriaResolver({ - orderIndex: 0, - side: Side(0), - index: 0, - identifier: 0, - criteriaProof: new bytes32[](0) - }) - ) - ); + bytes32 private constant EMPTY_CRITERIA_RESOLVER = keccak256( + abi.encode( + CriteriaResolver({ + orderIndex: 0, + side: Side(0), + index: 0, + identifier: 0, + criteriaProof: new bytes32[](0) + }) + ) + ); using ArrayLib for bytes32[]; @@ -42,8 +42,8 @@ library CriteriaResolverLib { * @param defaultName the name of the default to clear */ function clear(string memory defaultName) internal { - mapping(string => CriteriaResolver) - storage criteriaResolverMap = _criteriaResolverMap(); + mapping(string => CriteriaResolver) storage criteriaResolverMap = + _criteriaResolverMap(); CriteriaResolver storage resolver = criteriaResolverMap[defaultName]; // clear all fields clear(resolver); @@ -80,11 +80,13 @@ library CriteriaResolverLib { * * @param item the name of the default for retrieval */ - function fromDefault( - string memory defaultName - ) internal view returns (CriteriaResolver memory item) { - mapping(string => CriteriaResolver) - storage criteriaResolverMap = _criteriaResolverMap(); + function fromDefault(string memory defaultName) + internal + view + returns (CriteriaResolver memory item) + { + mapping(string => CriteriaResolver) storage criteriaResolverMap = + _criteriaResolverMap(); item = criteriaResolverMap[defaultName]; if (keccak256(abi.encode(item)) == EMPTY_CRITERIA_RESOLVER) { @@ -99,11 +101,13 @@ library CriteriaResolverLib { * * @return items the CriteriaResolvers retrieved from storage */ - function fromDefaultMany( - string memory defaultsName - ) internal view returns (CriteriaResolver[] memory items) { - mapping(string => CriteriaResolver[]) - storage criteriaResolversMap = _criteriaResolversMap(); + function fromDefaultMany(string memory defaultsName) + internal + view + returns (CriteriaResolver[] memory items) + { + mapping(string => CriteriaResolver[]) storage criteriaResolversMap = + _criteriaResolversMap(); items = criteriaResolversMap[defaultsName]; if (items.length == 0) { @@ -123,16 +127,15 @@ library CriteriaResolverLib { CriteriaResolver memory criteriaResolver, string memory defaultName ) internal returns (CriteriaResolver memory _criteriaResolver) { - mapping(string => CriteriaResolver) - storage criteriaResolverMap = _criteriaResolverMap(); + mapping(string => CriteriaResolver) storage criteriaResolverMap = + _criteriaResolverMap(); CriteriaResolver storage resolver = criteriaResolverMap[defaultName]; resolver.orderIndex = criteriaResolver.orderIndex; resolver.side = criteriaResolver.side; resolver.index = criteriaResolver.index; resolver.identifier = criteriaResolver.identifier; ArrayLib.setBytes32s( - resolver.criteriaProof, - criteriaResolver.criteriaProof + resolver.criteriaProof, criteriaResolver.criteriaProof ); return criteriaResolver; } @@ -149,11 +152,9 @@ library CriteriaResolverLib { CriteriaResolver[] memory criteriaResolvers, string memory defaultName ) internal returns (CriteriaResolver[] memory _criteriaResolvers) { - mapping(string => CriteriaResolver[]) - storage criteriaResolversMap = _criteriaResolversMap(); - CriteriaResolver[] storage resolvers = criteriaResolversMap[ - defaultName - ]; + mapping(string => CriteriaResolver[]) storage criteriaResolversMap = + _criteriaResolversMap(); + CriteriaResolver[] storage resolvers = criteriaResolversMap[defaultName]; // todo: make sure we do this elsewhere clear(resolvers); StructCopier.setCriteriaResolvers(resolvers, criteriaResolvers); @@ -167,17 +168,18 @@ library CriteriaResolverLib { * * @custom:return copiedItem the copied CriteriaResolver */ - function copy( - CriteriaResolver memory resolver - ) internal pure returns (CriteriaResolver memory) { - return - CriteriaResolver({ - orderIndex: resolver.orderIndex, - side: resolver.side, - index: resolver.index, - identifier: resolver.identifier, - criteriaProof: resolver.criteriaProof.copy() - }); + function copy(CriteriaResolver memory resolver) + internal + pure + returns (CriteriaResolver memory) + { + return CriteriaResolver({ + orderIndex: resolver.orderIndex, + side: resolver.side, + index: resolver.index, + identifier: resolver.identifier, + criteriaProof: resolver.criteriaProof.copy() + }); } /** @@ -187,12 +189,13 @@ library CriteriaResolverLib { * * @custom:return copiedItems the copied CriteriaResolvers */ - function copy( - CriteriaResolver[] memory resolvers - ) internal pure returns (CriteriaResolver[] memory) { - CriteriaResolver[] memory copiedItems = new CriteriaResolver[]( - resolvers.length - ); + function copy(CriteriaResolver[] memory resolvers) + internal + pure + returns (CriteriaResolver[] memory) + { + CriteriaResolver[] memory copiedItems = + new CriteriaResolver[](resolvers.length); for (uint256 i = 0; i < resolvers.length; i++) { copiedItems[i] = copy(resolvers[i]); } @@ -206,14 +209,13 @@ library CriteriaResolverLib { */ function empty() internal pure returns (CriteriaResolver memory) { bytes32[] memory proof; - return - CriteriaResolver({ - orderIndex: 0, - side: Side(0), - index: 0, - identifier: 0, - criteriaProof: proof - }); + return CriteriaResolver({ + orderIndex: 0, + side: Side(0), + index: 0, + identifier: 0, + criteriaProof: proof + }); } /** @@ -283,10 +285,11 @@ library CriteriaResolverLib { * * @return _resolver the CriteriaResolver with the side set */ - function withSide( - CriteriaResolver memory resolver, - Side side - ) internal pure returns (CriteriaResolver memory) { + function withSide(CriteriaResolver memory resolver, Side side) + internal + pure + returns (CriteriaResolver memory) + { resolver.side = side; return resolver; } @@ -299,10 +302,11 @@ library CriteriaResolverLib { * * @return _resolver the CriteriaResolver with the index set */ - function withIndex( - CriteriaResolver memory resolver, - uint256 index - ) internal pure returns (CriteriaResolver memory) { + function withIndex(CriteriaResolver memory resolver, uint256 index) + internal + pure + returns (CriteriaResolver memory) + { resolver.index = index; return resolver; } diff --git a/src/lib/ExecutionLib.sol b/src/lib/ExecutionLib.sol index acd6d24..c841d37 100644 --- a/src/lib/ExecutionLib.sol +++ b/src/lib/ExecutionLib.sol @@ -23,22 +23,21 @@ library ExecutionLib { keccak256("seaport.ExecutionDefaults"); bytes32 private constant EXECUTIONS_MAP_POSITION = keccak256("seaport.ExecutionsDefaults"); - bytes32 private constant EMPTY_EXECUTION = - keccak256( - abi.encode( - Execution({ - item: ReceivedItem({ - itemType: ItemType(0), - token: address(0), - identifier: 0, - amount: 0, - recipient: payable(address(0)) - }), - offerer: address(0), - conduitKey: bytes32(0) - }) - ) - ); + bytes32 private constant EMPTY_EXECUTION = keccak256( + abi.encode( + Execution({ + item: ReceivedItem({ + itemType: ItemType(0), + token: address(0), + identifier: 0, + amount: 0, + recipient: payable(address(0)) + }), + offerer: address(0), + conduitKey: bytes32(0) + }) + ) + ); using ReceivedItemLib for ReceivedItem; using ReceivedItemLib for ReceivedItem[]; @@ -85,9 +84,11 @@ library ExecutionLib { * * @return item the Execution retrieved from storage */ - function fromDefault( - string memory defaultName - ) internal view returns (Execution memory item) { + function fromDefault(string memory defaultName) + internal + view + returns (Execution memory item) + { mapping(string => Execution) storage executionMap = _executionMap(); item = executionMap[defaultName]; @@ -103,9 +104,11 @@ library ExecutionLib { * * @return items the Executions retrieved from storage */ - function fromDefaultMany( - string memory defaultName - ) internal view returns (Execution[] memory items) { + function fromDefaultMany(string memory defaultName) + internal + view + returns (Execution[] memory items) + { mapping(string => Execution[]) storage executionsMap = _executionsMap(); items = executionsMap[defaultName]; @@ -122,10 +125,10 @@ library ExecutionLib { * * @return _execution the Execution saved as a default */ - function saveDefault( - Execution memory execution, - string memory defaultName - ) internal returns (Execution memory _execution) { + function saveDefault(Execution memory execution, string memory defaultName) + internal + returns (Execution memory _execution) + { mapping(string => Execution) storage executionMap = _executionMap(); executionMap[defaultName] = execution; return execution; @@ -155,15 +158,16 @@ library ExecutionLib { * * @custom:return copy the copy of the Execution in-memory */ - function copy( - Execution memory item - ) internal pure returns (Execution memory) { - return - Execution({ - item: item.item.copy(), - offerer: item.offerer, - conduitKey: item.conduitKey - }); + function copy(Execution memory item) + internal + pure + returns (Execution memory) + { + return Execution({ + item: item.item.copy(), + offerer: item.offerer, + conduitKey: item.conduitKey + }); } /** @@ -173,9 +177,11 @@ library ExecutionLib { * * @custom:return copy the copy of the array of Executions in-memory */ - function copy( - Execution[] memory items - ) internal pure returns (Execution[] memory) { + function copy(Execution[] memory items) + internal + pure + returns (Execution[] memory) + { Execution[] memory copies = new Execution[](items.length); for (uint256 i = 0; i < items.length; i++) { copies[i] = copy(items[i]); @@ -189,12 +195,11 @@ library ExecutionLib { * @custom:return empty the empty Execution */ function empty() internal pure returns (Execution memory) { - return - Execution({ - item: ReceivedItemLib.empty(), - offerer: address(0), - conduitKey: bytes32(0) - }); + return Execution({ + item: ReceivedItemLib.empty(), + offerer: address(0), + conduitKey: bytes32(0) + }); } /** @@ -240,10 +245,11 @@ library ExecutionLib { * * @return _execution the configured Execution */ - function withItem( - Execution memory execution, - ReceivedItem memory item - ) internal pure returns (Execution memory) { + function withItem(Execution memory execution, ReceivedItem memory item) + internal + pure + returns (Execution memory) + { execution.item = item.copy(); return execution; } @@ -256,10 +262,11 @@ library ExecutionLib { * * @return _execution the configured Execution */ - function withOfferer( - Execution memory execution, - address offerer - ) internal pure returns (Execution memory) { + function withOfferer(Execution memory execution, address offerer) + internal + pure + returns (Execution memory) + { execution.offerer = offerer; return execution; } @@ -272,10 +279,11 @@ library ExecutionLib { * * @return _execution the configured Execution */ - function withConduitKey( - Execution memory execution, - bytes32 conduitKey - ) internal pure returns (Execution memory) { + function withConduitKey(Execution memory execution, bytes32 conduitKey) + internal + pure + returns (Execution memory) + { execution.conduitKey = conduitKey; return execution; } diff --git a/src/lib/FulfillmentComponentLib.sol b/src/lib/FulfillmentComponentLib.sol index 422bfb9..4418f0f 100644 --- a/src/lib/FulfillmentComponentLib.sol +++ b/src/lib/FulfillmentComponentLib.sol @@ -1,7 +1,8 @@ // SPDX-License-Identifier: MIT pragma solidity ^0.8.17; -import { FulfillmentComponent } from "seaport-types/src/lib/ConsiderationStructs.sol"; +import { FulfillmentComponent } from + "seaport-types/src/lib/ConsiderationStructs.sol"; import { ArrayLib } from "./ArrayLib.sol"; @@ -28,11 +29,10 @@ library FulfillmentComponentLib { * @param defaultName the name of the default to clear */ function clear(string memory defaultName) internal { - mapping(string => FulfillmentComponent) - storage fulfillmentComponentMap = _fulfillmentComponentMap(); - FulfillmentComponent storage component = fulfillmentComponentMap[ - defaultName - ]; + mapping(string => FulfillmentComponent) storage fulfillmentComponentMap = + _fulfillmentComponentMap(); + FulfillmentComponent storage component = + fulfillmentComponentMap[defaultName]; clear(component); } @@ -65,11 +65,13 @@ library FulfillmentComponentLib { * * @return item the FulfillmentComponent retrieved from storage */ - function fromDefault( - string memory defaultName - ) internal view returns (FulfillmentComponent memory item) { - mapping(string => FulfillmentComponent) - storage fulfillmentComponentMap = _fulfillmentComponentMap(); + function fromDefault(string memory defaultName) + internal + view + returns (FulfillmentComponent memory item) + { + mapping(string => FulfillmentComponent) storage fulfillmentComponentMap = + _fulfillmentComponentMap(); item = fulfillmentComponentMap[defaultName]; } @@ -80,11 +82,13 @@ library FulfillmentComponentLib { * * @return items the FulfillmentComponents retrieved from storage */ - function fromDefaultMany( - string memory defaultName - ) internal view returns (FulfillmentComponent[] memory items) { - mapping(string => FulfillmentComponent[]) - storage fulfillmentComponentMap = _fulfillmentComponentsMap(); + function fromDefaultMany(string memory defaultName) + internal + view + returns (FulfillmentComponent[] memory items) + { + mapping(string => FulfillmentComponent[]) storage + fulfillmentComponentMap = _fulfillmentComponentsMap(); items = fulfillmentComponentMap[defaultName]; } @@ -100,11 +104,10 @@ library FulfillmentComponentLib { FulfillmentComponent memory fulfillmentComponent, string memory defaultName ) internal returns (FulfillmentComponent memory _fulfillmentComponent) { - mapping(string => FulfillmentComponent) - storage fulfillmentComponentMap = _fulfillmentComponentMap(); - FulfillmentComponent storage component = fulfillmentComponentMap[ - defaultName - ]; + mapping(string => FulfillmentComponent) storage fulfillmentComponentMap = + _fulfillmentComponentMap(); + FulfillmentComponent storage component = + fulfillmentComponentMap[defaultName]; component.orderIndex = fulfillmentComponent.orderIndex; component.itemIndex = fulfillmentComponent.itemIndex; return fulfillmentComponent; @@ -124,16 +127,12 @@ library FulfillmentComponentLib { FulfillmentComponent[] memory fulfillmentComponents, string memory defaultName ) internal returns (FulfillmentComponent[] memory _fulfillmentComponents) { - mapping(string => FulfillmentComponent[]) - storage fulfillmentComponentsMap = _fulfillmentComponentsMap(); - FulfillmentComponent[] storage components = fulfillmentComponentsMap[ - defaultName - ]; + mapping(string => FulfillmentComponent[]) storage + fulfillmentComponentsMap = _fulfillmentComponentsMap(); + FulfillmentComponent[] storage components = + fulfillmentComponentsMap[defaultName]; clear(components); - StructCopier.setFulfillmentComponents( - components, - fulfillmentComponents - ); + StructCopier.setFulfillmentComponents(components, fulfillmentComponents); return fulfillmentComponents; } @@ -145,14 +144,15 @@ library FulfillmentComponentLib { * * @return copiedComponent the copied FulfillmentComponent */ - function copy( - FulfillmentComponent memory component - ) internal pure returns (FulfillmentComponent memory) { - return - FulfillmentComponent({ - orderIndex: component.orderIndex, - itemIndex: component.itemIndex - }); + function copy(FulfillmentComponent memory component) + internal + pure + returns (FulfillmentComponent memory) + { + return FulfillmentComponent({ + orderIndex: component.orderIndex, + itemIndex: component.itemIndex + }); } /** @@ -162,12 +162,13 @@ library FulfillmentComponentLib { * * @return copiedComponents the copied FulfillmentComponents */ - function copy( - FulfillmentComponent[] memory components - ) internal pure returns (FulfillmentComponent[] memory) { - FulfillmentComponent[] memory copiedItems = new FulfillmentComponent[]( - components.length - ); + function copy(FulfillmentComponent[] memory components) + internal + pure + returns (FulfillmentComponent[] memory) + { + FulfillmentComponent[] memory copiedItems = + new FulfillmentComponent[](components.length); for (uint256 i = 0; i < components.length; i++) { copiedItems[i] = copy(components[i]); } @@ -195,8 +196,7 @@ library FulfillmentComponentLib { private pure returns ( - mapping(string => FulfillmentComponent) - storage fulfillmentComponentMap + mapping(string => FulfillmentComponent) storage fulfillmentComponentMap ) { bytes32 position = FULFILLMENT_COMPONENT_MAP_POSITION; @@ -216,8 +216,7 @@ library FulfillmentComponentLib { private pure returns ( - mapping(string => FulfillmentComponent[]) - storage fulfillmentComponentsMap + mapping(string => FulfillmentComponent[]) storage fulfillmentComponentsMap ) { bytes32 position = FULFILLMENT_COMPONENTS_MAP_POSITION; diff --git a/src/lib/FulfillmentLib.sol b/src/lib/FulfillmentLib.sol index 11e5043..5ad1e43 100644 --- a/src/lib/FulfillmentLib.sol +++ b/src/lib/FulfillmentLib.sol @@ -32,8 +32,8 @@ library FulfillmentLib { * @param defaultName the name of the default to clear */ function clear(string memory defaultName) internal { - mapping(string => Fulfillment) - storage fulfillmentMap = _fulfillmentMap(); + mapping(string => Fulfillment) storage fulfillmentMap = + _fulfillmentMap(); Fulfillment storage _fulfillment = fulfillmentMap[defaultName]; // clear all fields FulfillmentComponent[] memory components; @@ -50,11 +50,13 @@ library FulfillmentLib { * * @return item the Fulfillment retrieved from storage */ - function fromDefault( - string memory defaultName - ) internal view returns (Fulfillment memory item) { - mapping(string => Fulfillment) - storage fulfillmentMap = _fulfillmentMap(); + function fromDefault(string memory defaultName) + internal + view + returns (Fulfillment memory item) + { + mapping(string => Fulfillment) storage fulfillmentMap = + _fulfillmentMap(); item = fulfillmentMap[defaultName]; } @@ -65,11 +67,13 @@ library FulfillmentLib { * * @return items the Fulfillment array retrieved from storage */ - function fromDefaultMany( - string memory defaultName - ) internal view returns (Fulfillment[] memory items) { - mapping(string => Fulfillment[]) - storage fulfillmentsMap = _fulfillmentsMap(); + function fromDefaultMany(string memory defaultName) + internal + view + returns (Fulfillment[] memory items) + { + mapping(string => Fulfillment[]) storage fulfillmentsMap = + _fulfillmentsMap(); items = fulfillmentsMap[defaultName]; } @@ -85,8 +89,8 @@ library FulfillmentLib { Fulfillment memory fulfillment, string memory defaultName ) internal returns (Fulfillment memory _fulfillment) { - mapping(string => Fulfillment) - storage fulfillmentMap = _fulfillmentMap(); + mapping(string => Fulfillment) storage fulfillmentMap = + _fulfillmentMap(); StructCopier.setFulfillment(fulfillmentMap[defaultName], fulfillment); return fulfillment; @@ -104,12 +108,9 @@ library FulfillmentLib { Fulfillment[] memory fulfillments, string memory defaultName ) internal returns (Fulfillment[] memory _fulfillments) { - mapping(string => Fulfillment[]) - storage fulfillmentsMap = _fulfillmentsMap(); - StructCopier.setFulfillments( - fulfillmentsMap[defaultName], - fulfillments - ); + mapping(string => Fulfillment[]) storage fulfillmentsMap = + _fulfillmentsMap(); + StructCopier.setFulfillments(fulfillmentsMap[defaultName], fulfillments); return fulfillments; } @@ -120,16 +121,15 @@ library FulfillmentLib { * * @custom:return copiedFulfillment the copied Fulfillment */ - function copy( - Fulfillment memory _fulfillment - ) internal pure returns (Fulfillment memory) { - return - Fulfillment({ - offerComponents: _fulfillment.offerComponents.copy(), - considerationComponents: _fulfillment - .considerationComponents - .copy() - }); + function copy(Fulfillment memory _fulfillment) + internal + pure + returns (Fulfillment memory) + { + return Fulfillment({ + offerComponents: _fulfillment.offerComponents.copy(), + considerationComponents: _fulfillment.considerationComponents.copy() + }); } /** @@ -139,12 +139,13 @@ library FulfillmentLib { * * @custom:return copiedFulfillments the copied Fulfillment array */ - function copy( - Fulfillment[] memory _fulfillments - ) internal pure returns (Fulfillment[] memory) { - Fulfillment[] memory copiedItems = new Fulfillment[]( - _fulfillments.length - ); + function copy(Fulfillment[] memory _fulfillments) + internal + pure + returns (Fulfillment[] memory) + { + Fulfillment[] memory copiedItems = + new Fulfillment[](_fulfillments.length); for (uint256 i = 0; i < _fulfillments.length; i++) { copiedItems[i] = copy(_fulfillments[i]); } @@ -158,11 +159,10 @@ library FulfillmentLib { */ function empty() internal pure returns (Fulfillment memory) { FulfillmentComponent[] memory components; - return - Fulfillment({ - offerComponents: components, - considerationComponents: components - }); + return Fulfillment({ + offerComponents: components, + considerationComponents: components + }); } /** diff --git a/src/lib/OfferItemLib.sol b/src/lib/OfferItemLib.sol index f1a1e2a..cb6087e 100644 --- a/src/lib/OfferItemLib.sol +++ b/src/lib/OfferItemLib.sol @@ -22,18 +22,17 @@ library OfferItemLib { keccak256("seaport.OfferItemDefaults"); bytes32 private constant OFFER_ITEMS_MAP_POSITION = keccak256("seaport.OfferItemsDefaults"); - bytes32 private constant EMPTY_OFFER_ITEM = - keccak256( - abi.encode( - OfferItem({ - itemType: ItemType(0), - token: address(0), - identifierOrCriteria: 0, - startAmount: 0, - endAmount: 0 - }) - ) - ); + bytes32 private constant EMPTY_OFFER_ITEM = keccak256( + abi.encode( + OfferItem({ + itemType: ItemType(0), + token: address(0), + identifierOrCriteria: 0, + startAmount: 0, + endAmount: 0 + }) + ) + ); /** * @dev Clears an OfferItem from storage. @@ -81,9 +80,11 @@ library OfferItemLib { * * @return item the OfferItem retrieved from storage */ - function fromDefault( - string memory defaultName - ) internal view returns (OfferItem memory item) { + function fromDefault(string memory defaultName) + internal + view + returns (OfferItem memory item) + { mapping(string => OfferItem) storage offerItemMap = _offerItemMap(); item = offerItemMap[defaultName]; @@ -99,9 +100,11 @@ library OfferItemLib { * * @return items the OfferItems retrieved from storage */ - function fromDefaultMany( - string memory defaultsName - ) internal view returns (OfferItem[] memory items) { + function fromDefaultMany(string memory defaultsName) + internal + view + returns (OfferItem[] memory items) + { mapping(string => OfferItem[]) storage offerItemsMap = _offerItemsMap(); items = offerItemsMap[defaultsName]; @@ -118,10 +121,10 @@ library OfferItemLib { * * @return _offerItem the OfferItem saved as a default */ - function saveDefault( - OfferItem memory offerItem, - string memory defaultName - ) internal returns (OfferItem memory _offerItem) { + function saveDefault(OfferItem memory offerItem, string memory defaultName) + internal + returns (OfferItem memory _offerItem) + { mapping(string => OfferItem) storage offerItemMap = _offerItemMap(); offerItemMap[defaultName] = offerItem; return offerItem; @@ -153,17 +156,18 @@ library OfferItemLib { * * @custom:return copiedItem the copied OfferItem */ - function copy( - OfferItem memory item - ) internal pure returns (OfferItem memory) { - return - OfferItem({ - itemType: item.itemType, - token: item.token, - identifierOrCriteria: item.identifierOrCriteria, - startAmount: item.startAmount, - endAmount: item.endAmount - }); + function copy(OfferItem memory item) + internal + pure + returns (OfferItem memory) + { + return OfferItem({ + itemType: item.itemType, + token: item.token, + identifierOrCriteria: item.identifierOrCriteria, + startAmount: item.startAmount, + endAmount: item.endAmount + }); } /** @@ -173,9 +177,11 @@ library OfferItemLib { * * @custom:return copiedItems the copied OfferItems */ - function copy( - OfferItem[] memory items - ) internal pure returns (OfferItem[] memory) { + function copy(OfferItem[] memory items) + internal + pure + returns (OfferItem[] memory) + { OfferItem[] memory copiedItems = new OfferItem[](items.length); for (uint256 i = 0; i < items.length; i++) { copiedItems[i] = copy(items[i]); @@ -189,14 +195,13 @@ library OfferItemLib { * @custom:return emptyItem the empty OfferItem */ function empty() internal pure returns (OfferItem memory) { - return - OfferItem({ - itemType: ItemType.NATIVE, - token: address(0), - identifierOrCriteria: 0, - startAmount: 0, - endAmount: 0 - }); + return OfferItem({ + itemType: ItemType.NATIVE, + token: address(0), + identifierOrCriteria: 0, + startAmount: 0, + endAmount: 0 + }); } /** @@ -242,10 +247,11 @@ library OfferItemLib { * * @custom:return _offerItem the modified OfferItem */ - function withItemType( - OfferItem memory item, - ItemType itemType - ) internal pure returns (OfferItem memory) { + function withItemType(OfferItem memory item, ItemType itemType) + internal + pure + returns (OfferItem memory) + { item.itemType = itemType; return item; } @@ -258,10 +264,11 @@ library OfferItemLib { * * @custom:return _offerItem the modified OfferItem */ - function withToken( - OfferItem memory item, - address token - ) internal pure returns (OfferItem memory) { + function withToken(OfferItem memory item, address token) + internal + pure + returns (OfferItem memory) + { item.token = token; return item; } @@ -290,10 +297,11 @@ library OfferItemLib { * * @custom:return _offerItem the modified OfferItem */ - function withStartAmount( - OfferItem memory item, - uint256 startAmount - ) internal pure returns (OfferItem memory) { + function withStartAmount(OfferItem memory item, uint256 startAmount) + internal + pure + returns (OfferItem memory) + { item.startAmount = startAmount; return item; } @@ -306,10 +314,11 @@ library OfferItemLib { * * @custom:return _offerItem the modified OfferItem */ - function withEndAmount( - OfferItem memory item, - uint256 endAmount - ) internal pure returns (OfferItem memory) { + function withEndAmount(OfferItem memory item, uint256 endAmount) + internal + pure + returns (OfferItem memory) + { item.endAmount = endAmount; return item; } @@ -322,10 +331,11 @@ library OfferItemLib { * * @custom:return _offerItem the modified OfferItem */ - function withAmount( - OfferItem memory item, - uint256 amount - ) internal pure returns (OfferItem memory) { + function withAmount(OfferItem memory item, uint256 amount) + internal + pure + returns (OfferItem memory) + { item.startAmount = amount; item.endAmount = amount; return item; @@ -338,16 +348,17 @@ library OfferItemLib { * * @custom:return spentItem the converted SpentItem */ - function toSpentItem( - OfferItem memory item - ) internal pure returns (SpentItem memory) { - return - SpentItem({ - itemType: item.itemType, - token: item.token, - identifier: item.identifierOrCriteria, - amount: item.startAmount - }); + function toSpentItem(OfferItem memory item) + internal + pure + returns (SpentItem memory) + { + return SpentItem({ + itemType: item.itemType, + token: item.token, + identifier: item.identifierOrCriteria, + amount: item.startAmount + }); } /** @@ -357,9 +368,11 @@ library OfferItemLib { * * @custom:return spentItems the converted SpentItem[] */ - function toSpentItemArray( - OfferItem[] memory items - ) internal pure returns (SpentItem[] memory) { + function toSpentItemArray(OfferItem[] memory items) + internal + pure + returns (SpentItem[] memory) + { SpentItem[] memory spentItems = new SpentItem[](items.length); for (uint256 i = 0; i < items.length; i++) { spentItems[i] = toSpentItem(items[i]); @@ -375,18 +388,18 @@ library OfferItemLib { * * @custom:return considerationItem the converted ConsiderationItem */ - function toConsiderationItem( - OfferItem memory item, - address recipient - ) internal pure returns (ConsiderationItem memory) { - return - ConsiderationItem({ - itemType: item.itemType, - token: item.token, - identifierOrCriteria: item.identifierOrCriteria, - startAmount: item.startAmount, - endAmount: item.endAmount, - recipient: payable(recipient) - }); + function toConsiderationItem(OfferItem memory item, address recipient) + internal + pure + returns (ConsiderationItem memory) + { + return ConsiderationItem({ + itemType: item.itemType, + token: item.token, + identifierOrCriteria: item.identifierOrCriteria, + startAmount: item.startAmount, + endAmount: item.endAmount, + recipient: payable(recipient) + }); } } diff --git a/src/lib/OrderComponentsLib.sol b/src/lib/OrderComponentsLib.sol index 5be9096..88e68b6 100644 --- a/src/lib/OrderComponentsLib.sol +++ b/src/lib/OrderComponentsLib.sol @@ -36,24 +36,23 @@ library OrderComponentsLib { keccak256("seaport.OrderComponentsDefaults"); bytes32 private constant ORDER_COMPONENTS_ARRAY_MAP_POSITION = keccak256("seaport.OrderComponentsArrayDefaults"); - bytes32 private constant EMPTY_ORDER_COMPONENTS = - keccak256( - abi.encode( - OrderComponents({ - offerer: address(0), - zone: address(0), - offer: new OfferItem[](0), - consideration: new ConsiderationItem[](0), - orderType: OrderType(0), - startTime: 0, - endTime: 0, - zoneHash: bytes32(0), - salt: 0, - conduitKey: bytes32(0), - counter: 0 - }) - ) - ); + bytes32 private constant EMPTY_ORDER_COMPONENTS = keccak256( + abi.encode( + OrderComponents({ + offerer: address(0), + zone: address(0), + offer: new OfferItem[](0), + consideration: new ConsiderationItem[](0), + orderType: OrderType(0), + startTime: 0, + endTime: 0, + zoneHash: bytes32(0), + salt: 0, + conduitKey: bytes32(0), + counter: 0 + }) + ) + ); /** * @dev Clears anOrderComponents from storage. @@ -70,8 +69,7 @@ library OrderComponentsLib { components.zone = address(0); StructCopier.setOfferItems(components.offer, offer); StructCopier.setConsiderationItems( - components.consideration, - consideration + components.consideration, consideration ); components.orderType = OrderType(0); components.startTime = 0; @@ -100,8 +98,8 @@ library OrderComponentsLib { * @param defaultName the name of the default to clear */ function clear(string memory defaultName) internal { - mapping(string => OrderComponents) - storage orderComponentsMap = _orderComponentsMap(); + mapping(string => OrderComponents) storage orderComponentsMap = + _orderComponentsMap(); OrderComponents storage components = orderComponentsMap[defaultName]; components.clear(); } @@ -136,11 +134,13 @@ library OrderComponentsLib { * * @return item the default OrderComponents */ - function fromDefault( - string memory defaultName - ) internal view returns (OrderComponents memory item) { - mapping(string => OrderComponents) - storage orderComponentsMap = _orderComponentsMap(); + function fromDefault(string memory defaultName) + internal + view + returns (OrderComponents memory item) + { + mapping(string => OrderComponents) storage orderComponentsMap = + _orderComponentsMap(); item = orderComponentsMap[defaultName]; if (keccak256(abi.encode(item)) == EMPTY_ORDER_COMPONENTS) { @@ -155,11 +155,13 @@ library OrderComponentsLib { * * @return items the default OrderComponents array */ - function fromDefaultMany( - string memory defaultName - ) internal view returns (OrderComponents[] memory items) { - mapping(string => OrderComponents[]) - storage orderComponentsArrayMap = _orderComponentsArrayMap(); + function fromDefaultMany(string memory defaultName) + internal + view + returns (OrderComponents[] memory items) + { + mapping(string => OrderComponents[]) storage orderComponentsArrayMap = + _orderComponentsArrayMap(); items = orderComponentsArrayMap[defaultName]; if (items.length == 0) { @@ -179,8 +181,8 @@ library OrderComponentsLib { OrderComponents memory orderComponents, string memory defaultName ) internal returns (OrderComponents memory _orderComponents) { - mapping(string => OrderComponents) - storage orderComponentsMap = _orderComponentsMap(); + mapping(string => OrderComponents) storage orderComponentsMap = + _orderComponentsMap(); OrderComponents storage destination = orderComponentsMap[defaultName]; StructCopier.setOrderComponents(destination, orderComponents); return orderComponents; @@ -198,11 +200,10 @@ library OrderComponentsLib { OrderComponents[] memory orderComponents, string memory defaultName ) internal returns (OrderComponents[] memory _orderComponents) { - mapping(string => OrderComponents[]) - storage orderComponentsArrayMap = _orderComponentsArrayMap(); - OrderComponents[] storage destination = orderComponentsArrayMap[ - defaultName - ]; + mapping(string => OrderComponents[]) storage orderComponentsArrayMap = + _orderComponentsArrayMap(); + OrderComponents[] storage destination = + orderComponentsArrayMap[defaultName]; StructCopier.setOrderComponents(destination, orderComponents); return orderComponents; } @@ -214,23 +215,24 @@ library OrderComponentsLib { * * @return the copy of the OrderComponents */ - function copy( - OrderComponents memory item - ) internal pure returns (OrderComponents memory) { - return - OrderComponents({ - offerer: item.offerer, - zone: item.zone, - offer: item.offer.copy(), - consideration: item.consideration.copy(), - orderType: item.orderType, - startTime: item.startTime, - endTime: item.endTime, - zoneHash: item.zoneHash, - salt: item.salt, - conduitKey: item.conduitKey, - counter: item.counter - }); + function copy(OrderComponents memory item) + internal + pure + returns (OrderComponents memory) + { + return OrderComponents({ + offerer: item.offerer, + zone: item.zone, + offer: item.offer.copy(), + consideration: item.consideration.copy(), + orderType: item.orderType, + startTime: item.startTime, + endTime: item.endTime, + zoneHash: item.zoneHash, + salt: item.salt, + conduitKey: item.conduitKey, + counter: item.counter + }); } /** @@ -280,10 +282,11 @@ library OrderComponentsLib { * * @custom:return _orderComponents the modified OrderComponents struct */ - function withOfferer( - OrderComponents memory components, - address offerer - ) internal pure returns (OrderComponents memory) { + function withOfferer(OrderComponents memory components, address offerer) + internal + pure + returns (OrderComponents memory) + { components.offerer = offerer; return components; } @@ -296,10 +299,11 @@ library OrderComponentsLib { * * @custom:return _orderComponents the modified OrderComponents struct */ - function withZone( - OrderComponents memory components, - address zone - ) internal pure returns (OrderComponents memory) { + function withZone(OrderComponents memory components, address zone) + internal + pure + returns (OrderComponents memory) + { components.zone = zone; return components; } @@ -360,10 +364,11 @@ library OrderComponentsLib { * * @custom:return _orderComponents the modified OrderComponents struct */ - function withStartTime( - OrderComponents memory components, - uint256 startTime - ) internal pure returns (OrderComponents memory) { + function withStartTime(OrderComponents memory components, uint256 startTime) + internal + pure + returns (OrderComponents memory) + { components.startTime = startTime; return components; } @@ -376,10 +381,11 @@ library OrderComponentsLib { * * @custom:return _orderComponents the modified OrderComponents struct */ - function withEndTime( - OrderComponents memory components, - uint256 endTime - ) internal pure returns (OrderComponents memory) { + function withEndTime(OrderComponents memory components, uint256 endTime) + internal + pure + returns (OrderComponents memory) + { components.endTime = endTime; return components; } @@ -392,10 +398,11 @@ library OrderComponentsLib { * * @custom:return _orderComponents the modified OrderComponents struct */ - function withZoneHash( - OrderComponents memory components, - bytes32 zoneHash - ) internal pure returns (OrderComponents memory) { + function withZoneHash(OrderComponents memory components, bytes32 zoneHash) + internal + pure + returns (OrderComponents memory) + { components.zoneHash = zoneHash; return components; } @@ -408,10 +415,11 @@ library OrderComponentsLib { * * @custom:return _orderComponents the modified OrderComponents struct */ - function withSalt( - OrderComponents memory components, - uint256 salt - ) internal pure returns (OrderComponents memory) { + function withSalt(OrderComponents memory components, uint256 salt) + internal + pure + returns (OrderComponents memory) + { components.salt = salt; return components; } @@ -440,10 +448,11 @@ library OrderComponentsLib { * * @custom:return _orderComponents the modified OrderComponents struct */ - function withCounter( - OrderComponents memory components, - uint256 counter - ) internal pure returns (OrderComponents memory) { + function withCounter(OrderComponents memory components, uint256 counter) + internal + pure + returns (OrderComponents memory) + { components.counter = counter; return components; } @@ -455,9 +464,11 @@ library OrderComponentsLib { * * @custom:return _orderParameters the converted OrderParameters struct */ - function toOrderParameters( - OrderComponents memory components - ) internal pure returns (OrderParameters memory parameters) { + function toOrderParameters(OrderComponents memory components) + internal + pure + returns (OrderParameters memory parameters) + { parameters.offerer = components.offerer; parameters.zone = components.zone; parameters.offer = components.offer.copy(); @@ -468,8 +479,7 @@ library OrderComponentsLib { parameters.zoneHash = components.zoneHash; parameters.salt = components.salt; parameters.conduitKey = components.conduitKey; - parameters.totalOriginalConsiderationItems = components - .consideration - .length; + parameters.totalOriginalConsiderationItems = + components.consideration.length; } } diff --git a/src/lib/OrderLib.sol b/src/lib/OrderLib.sol index a9f0fa4..265e59b 100644 --- a/src/lib/OrderLib.sol +++ b/src/lib/OrderLib.sol @@ -30,27 +30,26 @@ library OrderLib { keccak256("seaport.OrderDefaults"); bytes32 private constant ORDERS_MAP_POSITION = keccak256("seaport.OrdersDefaults"); - bytes32 private constant EMPTY_ORDER = - keccak256( - abi.encode( - Order({ - parameters: OrderParameters({ - offerer: address(0), - zone: address(0), - offer: new OfferItem[](0), - consideration: new ConsiderationItem[](0), - orderType: OrderType(0), - startTime: 0, - endTime: 0, - zoneHash: bytes32(0), - salt: 0, - conduitKey: bytes32(0), - totalOriginalConsiderationItems: 0 - }), - signature: "" - }) - ) - ); + bytes32 private constant EMPTY_ORDER = keccak256( + abi.encode( + Order({ + parameters: OrderParameters({ + offerer: address(0), + zone: address(0), + offer: new OfferItem[](0), + consideration: new ConsiderationItem[](0), + orderType: OrderType(0), + startTime: 0, + endTime: 0, + zoneHash: bytes32(0), + salt: 0, + conduitKey: bytes32(0), + totalOriginalConsiderationItems: 0 + }), + signature: "" + }) + ) + ); using OrderParametersLib for OrderParameters; @@ -95,9 +94,11 @@ library OrderLib { * * @return item the default Order */ - function fromDefault( - string memory defaultName - ) internal view returns (Order memory item) { + function fromDefault(string memory defaultName) + internal + view + returns (Order memory item) + { mapping(string => Order) storage orderMap = _orderMap(); item = orderMap[defaultName]; @@ -113,9 +114,11 @@ library OrderLib { * * @return items the default Order array */ - function fromDefaultMany( - string memory defaultName - ) internal view returns (Order[] memory) { + function fromDefaultMany(string memory defaultName) + internal + view + returns (Order[] memory) + { mapping(string => Order[]) storage ordersMap = _ordersMap(); Order[] memory items = ordersMap[defaultName]; @@ -134,10 +137,10 @@ library OrderLib { * * @return _order the Order saved as a default */ - function saveDefault( - Order memory order, - string memory defaultName - ) internal returns (Order memory _order) { + function saveDefault(Order memory order, string memory defaultName) + internal + returns (Order memory _order) + { mapping(string => Order) storage orderMap = _orderMap(); StructCopier.setOrder(orderMap[defaultName], order); return order; @@ -151,10 +154,10 @@ library OrderLib { * * @return _orders the Order array saved as a default */ - function saveDefaultMany( - Order[] memory orders, - string memory defaultName - ) internal returns (Order[] memory _orders) { + function saveDefaultMany(Order[] memory orders, string memory defaultName) + internal + returns (Order[] memory _orders) + { mapping(string => Order[]) storage ordersMap = _ordersMap(); StructCopier.setOrders(ordersMap[defaultName], orders); return orders; @@ -168,11 +171,10 @@ library OrderLib { * @custom:return copiedOrder the copied Order */ function copy(Order memory item) internal pure returns (Order memory) { - return - Order({ - parameters: item.parameters.copy(), - signature: item.signature - }); + return Order({ + parameters: item.parameters.copy(), + signature: item.signature + }); } /** @@ -182,7 +184,11 @@ library OrderLib { * * @custom:return copiedOrders the copied Order array */ - function copy(Order[] memory items) internal pure returns (Order[] memory) { + function copy(Order[] memory items) + internal + pure + returns (Order[] memory) + { Order[] memory copiedItems = new Order[](items.length); for (uint256 i = 0; i < items.length; i++) { copiedItems[i] = copy(items[i]); @@ -258,10 +264,11 @@ library OrderLib { * * @return _order the Order with the signature set */ - function withSignature( - Order memory order, - bytes memory signature - ) internal pure returns (Order memory) { + function withSignature(Order memory order, bytes memory signature) + internal + pure + returns (Order memory) + { order.signature = signature; return order; } @@ -305,16 +312,11 @@ library OrderLib { uint120 denominator, bytes memory extraData ) internal pure returns (AdvancedOrder[] memory _advancedOrders) { - AdvancedOrder[] memory advancedOrders = new AdvancedOrder[]( - orders.length - ); + AdvancedOrder[] memory advancedOrders = + new AdvancedOrder[](orders.length); for (uint256 i = 0; i < orders.length; i++) { - advancedOrders[i] = toAdvancedOrder( - orders[i], - numerator, - denominator, - extraData - ); + advancedOrders[i] = + toAdvancedOrder(orders[i], numerator, denominator, extraData); } return advancedOrders; } @@ -330,26 +332,22 @@ library OrderLib { function toBasicOrderParameters( Order memory order, BasicOrderType basicOrderType - ) internal pure returns (BasicOrderParameters memory basicOrderParameters) { - basicOrderParameters.considerationToken = order - .parameters - .consideration[0] - .token; - basicOrderParameters.considerationIdentifier = order - .parameters - .consideration[0] - .identifierOrCriteria; - basicOrderParameters.considerationAmount = order - .parameters - .consideration[0] - .endAmount; + ) + internal + pure + returns (BasicOrderParameters memory basicOrderParameters) + { + basicOrderParameters.considerationToken = + order.parameters.consideration[0].token; + basicOrderParameters.considerationIdentifier = + order.parameters.consideration[0].identifierOrCriteria; + basicOrderParameters.considerationAmount = + order.parameters.consideration[0].endAmount; basicOrderParameters.offerer = payable(order.parameters.offerer); basicOrderParameters.zone = order.parameters.zone; basicOrderParameters.offerToken = order.parameters.offer[0].token; - basicOrderParameters.offerIdentifier = order - .parameters - .offer[0] - .identifierOrCriteria; + basicOrderParameters.offerIdentifier = + order.parameters.offer[0].identifierOrCriteria; basicOrderParameters.offerAmount = order.parameters.offer[0].endAmount; basicOrderParameters.basicOrderType = basicOrderType; basicOrderParameters.startTime = order.parameters.startTime; @@ -359,13 +357,10 @@ library OrderLib { basicOrderParameters.offererConduitKey = order.parameters.conduitKey; basicOrderParameters.fulfillerConduitKey = order.parameters.conduitKey; basicOrderParameters.totalOriginalAdditionalRecipients = - order.parameters.totalOriginalConsiderationItems - - 1; + order.parameters.totalOriginalConsiderationItems - 1; - AdditionalRecipient[] - memory additionalRecipients = new AdditionalRecipient[]( - order.parameters.consideration.length - 1 - ); + AdditionalRecipient[] memory additionalRecipients = + new AdditionalRecipient[](order.parameters.consideration.length - 1); for (uint256 i = 1; i < order.parameters.consideration.length; i++) { additionalRecipients[i - 1] = AdditionalRecipient({ recipient: order.parameters.consideration[i].recipient, diff --git a/src/lib/OrderParametersLib.sol b/src/lib/OrderParametersLib.sol index 21da08a..f98458d 100644 --- a/src/lib/OrderParametersLib.sol +++ b/src/lib/OrderParametersLib.sol @@ -39,24 +39,23 @@ library OrderParametersLib { keccak256("seaport.OrderParametersDefaults"); bytes32 private constant ORDER_PARAMETERS_ARRAY_MAP_POSITION = keccak256("seaport.OrderParametersArrayDefaults"); - bytes32 private constant EMPTY_ORDER_PARAMETERS = - keccak256( - abi.encode( - OrderParameters({ - offerer: address(0), - zone: address(0), - offer: new OfferItem[](0), - consideration: new ConsiderationItem[](0), - orderType: OrderType(0), - startTime: 0, - endTime: 0, - zoneHash: bytes32(0), - salt: 0, - conduitKey: bytes32(0), - totalOriginalConsiderationItems: 0 - }) - ) - ); + bytes32 private constant EMPTY_ORDER_PARAMETERS = keccak256( + abi.encode( + OrderParameters({ + offerer: address(0), + zone: address(0), + offer: new OfferItem[](0), + consideration: new ConsiderationItem[](0), + orderType: OrderType(0), + startTime: 0, + endTime: 0, + zoneHash: bytes32(0), + salt: 0, + conduitKey: bytes32(0), + totalOriginalConsiderationItems: 0 + }) + ) + ); /** * @dev Clears an OrderParameters from storage. @@ -73,8 +72,7 @@ library OrderParametersLib { parameters.zone = address(0); StructCopier.setOfferItems(parameters.offer, offer); StructCopier.setConsiderationItems( - parameters.consideration, - consideration + parameters.consideration, consideration ); parameters.orderType = OrderType(0); parameters.startTime = 0; @@ -103,8 +101,8 @@ library OrderParametersLib { * @param defaultName the name of the default to clear */ function clear(string memory defaultName) internal { - mapping(string => OrderParameters) - storage orderParametersMap = _orderParametersMap(); + mapping(string => OrderParameters) storage orderParametersMap = + _orderParametersMap(); OrderParameters storage parameters = orderParametersMap[defaultName]; parameters.clear(); } @@ -139,11 +137,13 @@ library OrderParametersLib { * * @return item the default OrderParameters */ - function fromDefault( - string memory defaultName - ) internal view returns (OrderParameters memory item) { - mapping(string => OrderParameters) - storage orderParametersMap = _orderParametersMap(); + function fromDefault(string memory defaultName) + internal + view + returns (OrderParameters memory item) + { + mapping(string => OrderParameters) storage orderParametersMap = + _orderParametersMap(); item = orderParametersMap[defaultName]; if (keccak256(abi.encode(item)) == EMPTY_ORDER_PARAMETERS) { @@ -158,11 +158,13 @@ library OrderParametersLib { * * @return items the default OrderParameters array */ - function fromDefaultMany( - string memory defaultName - ) internal view returns (OrderParameters[] memory items) { - mapping(string => OrderParameters[]) - storage orderParametersArrayMap = _orderParametersArrayMap(); + function fromDefaultMany(string memory defaultName) + internal + view + returns (OrderParameters[] memory items) + { + mapping(string => OrderParameters[]) storage orderParametersArrayMap = + _orderParametersArrayMap(); items = orderParametersArrayMap[defaultName]; if (items.length == 0) { @@ -182,8 +184,8 @@ library OrderParametersLib { OrderParameters memory orderParameters, string memory defaultName ) internal returns (OrderParameters memory _orderParameters) { - mapping(string => OrderParameters) - storage orderParametersMap = _orderParametersMap(); + mapping(string => OrderParameters) storage orderParametersMap = + _orderParametersMap(); OrderParameters storage destination = orderParametersMap[defaultName]; StructCopier.setOrderParameters(destination, orderParameters); return orderParameters; @@ -201,11 +203,10 @@ library OrderParametersLib { OrderParameters[] memory orderParameters, string memory defaultName ) internal returns (OrderParameters[] memory _orderParameters) { - mapping(string => OrderParameters[]) - storage orderParametersArrayMap = _orderParametersArrayMap(); - OrderParameters[] storage destination = orderParametersArrayMap[ - defaultName - ]; + mapping(string => OrderParameters[]) storage orderParametersArrayMap = + _orderParametersArrayMap(); + OrderParameters[] storage destination = + orderParametersArrayMap[defaultName]; StructCopier.setOrderParameters(destination, orderParameters); return orderParameters; } @@ -217,24 +218,24 @@ library OrderParametersLib { * * @custom:return copiedOrderParameters the copied OrderParameters */ - function copy( - OrderParameters memory item - ) internal pure returns (OrderParameters memory) { - return - OrderParameters({ - offerer: item.offerer, - zone: item.zone, - offer: item.offer.copy(), - consideration: item.consideration.copy(), - orderType: item.orderType, - startTime: item.startTime, - endTime: item.endTime, - zoneHash: item.zoneHash, - salt: item.salt, - conduitKey: item.conduitKey, - totalOriginalConsiderationItems: item - .totalOriginalConsiderationItems - }); + function copy(OrderParameters memory item) + internal + pure + returns (OrderParameters memory) + { + return OrderParameters({ + offerer: item.offerer, + zone: item.zone, + offer: item.offer.copy(), + consideration: item.consideration.copy(), + orderType: item.orderType, + startTime: item.startTime, + endTime: item.endTime, + zoneHash: item.zoneHash, + salt: item.salt, + conduitKey: item.conduitKey, + totalOriginalConsiderationItems: item.totalOriginalConsiderationItems + }); } /** @@ -284,10 +285,11 @@ library OrderParametersLib { * * @custom:return _parameters the modified OrderParameters struct */ - function withOfferer( - OrderParameters memory parameters, - address offerer - ) internal pure returns (OrderParameters memory) { + function withOfferer(OrderParameters memory parameters, address offerer) + internal + pure + returns (OrderParameters memory) + { parameters.offerer = offerer; return parameters; } @@ -300,10 +302,11 @@ library OrderParametersLib { * * @custom:return _parameters the modified OrderParameters struct */ - function withZone( - OrderParameters memory parameters, - address zone - ) internal pure returns (OrderParameters memory) { + function withZone(OrderParameters memory parameters, address zone) + internal + pure + returns (OrderParameters memory) + { parameters.zone = zone; return parameters; } @@ -382,10 +385,11 @@ library OrderParametersLib { * * @custom:return _parameters the modified OrderParameters struct */ - function withStartTime( - OrderParameters memory parameters, - uint256 startTime - ) internal pure returns (OrderParameters memory) { + function withStartTime(OrderParameters memory parameters, uint256 startTime) + internal + pure + returns (OrderParameters memory) + { parameters.startTime = startTime; return parameters; } @@ -398,10 +402,11 @@ library OrderParametersLib { * * @custom:return _parameters the modified OrderParameters struct */ - function withEndTime( - OrderParameters memory parameters, - uint256 endTime - ) internal pure returns (OrderParameters memory) { + function withEndTime(OrderParameters memory parameters, uint256 endTime) + internal + pure + returns (OrderParameters memory) + { parameters.endTime = endTime; return parameters; } @@ -414,10 +419,11 @@ library OrderParametersLib { * * @custom:return _parameters the modified OrderParameters struct */ - function withZoneHash( - OrderParameters memory parameters, - bytes32 zoneHash - ) internal pure returns (OrderParameters memory) { + function withZoneHash(OrderParameters memory parameters, bytes32 zoneHash) + internal + pure + returns (OrderParameters memory) + { parameters.zoneHash = zoneHash; return parameters; } @@ -430,10 +436,11 @@ library OrderParametersLib { * * @custom:return _parameters the modified OrderParameters struct */ - function withSalt( - OrderParameters memory parameters, - uint256 salt - ) internal pure returns (OrderParameters memory) { + function withSalt(OrderParameters memory parameters, uint256 salt) + internal + pure + returns (OrderParameters memory) + { parameters.salt = salt; return parameters; } @@ -470,8 +477,8 @@ library OrderParametersLib { OrderParameters memory parameters, uint256 totalOriginalConsiderationItems ) internal pure returns (OrderParameters memory) { - parameters - .totalOriginalConsiderationItems = totalOriginalConsiderationItems; + parameters.totalOriginalConsiderationItems = + totalOriginalConsiderationItems; return parameters; } @@ -500,12 +507,13 @@ library OrderParametersLib { components.counter = counter; } - function isAvailable( - OrderParameters memory parameters - ) internal view returns (bool) { - return - block.timestamp >= parameters.startTime && - block.timestamp < parameters.endTime; + function isAvailable(OrderParameters memory parameters) + internal + view + returns (bool) + { + return block.timestamp >= parameters.startTime + && block.timestamp < parameters.endTime; } function getSpentAndReceivedItems( @@ -524,10 +532,7 @@ library OrderParametersLib { received = getReceivedItems(parameters, numerator, denominator); applyCriteriaResolvers( - spent, - received, - orderIndex, - criteriaResolvers + spent, received, orderIndex, criteriaResolvers ); } } @@ -555,9 +560,11 @@ library OrderParametersLib { } } - function convertCriteriaItemType( - ItemType itemType - ) internal pure returns (ItemType) { + function convertCriteriaItemType(ItemType itemType) + internal + pure + returns (ItemType) + { if (itemType == ItemType.ERC721_WITH_CRITERIA) { return ItemType.ERC721; } else if (itemType == ItemType.ERC1155_WITH_CRITERIA) { @@ -574,14 +581,13 @@ library OrderParametersLib { uint256 numerator, uint256 denominator ) internal view returns (SpentItem[] memory) { - return - getSpentItems( - parameters.offer, - parameters.startTime, - parameters.endTime, - numerator, - denominator - ); + return getSpentItems( + parameters.offer, + parameters.startTime, + parameters.endTime, + numerator, + denominator + ); } function getReceivedItems( @@ -589,14 +595,13 @@ library OrderParametersLib { uint256 numerator, uint256 denominator ) internal view returns (ReceivedItem[] memory) { - return - getReceivedItems( - parameters.consideration, - parameters.startTime, - parameters.endTime, - numerator, - denominator - ); + return getReceivedItems( + parameters.consideration, + parameters.startTime, + parameters.endTime, + numerator, + denominator + ); } function getSpentItems( @@ -609,11 +614,7 @@ library OrderParametersLib { SpentItem[] memory spentItems = new SpentItem[](items.length); for (uint256 i = 0; i < items.length; i++) { spentItems[i] = getSpentItem( - items[i], - startTime, - endTime, - numerator, - denominator + items[i], startTime, endTime, numerator, denominator ); } return spentItems; @@ -626,9 +627,8 @@ library OrderParametersLib { uint256 numerator, uint256 denominator ) internal view returns (ReceivedItem[] memory) { - ReceivedItem[] memory receivedItems = new ReceivedItem[]( - considerationItems.length - ); + ReceivedItem[] memory receivedItems = + new ReceivedItem[](considerationItems.length); for (uint256 i = 0; i < considerationItems.length; i++) { receivedItems[i] = getReceivedItem( considerationItems[i], @@ -713,11 +713,11 @@ library OrderParametersLib { } } - function _getFraction( - uint256 numerator, - uint256 denominator, - uint256 value - ) internal pure returns (uint256 newValue) { + function _getFraction(uint256 numerator, uint256 denominator, uint256 value) + internal + pure + returns (uint256 newValue) + { // Return value early in cases where the fraction resolves to 1. if (numerator == denominator) { return value; @@ -730,9 +730,7 @@ library OrderParametersLib { assembly { // Ensure new value contains no remainder via mulmod operator. // Credit to @hrkrshnn + @axic for proposing this optimal solution. - if mulmod(value, numerator, denominator) { - failure := true - } + if mulmod(value, numerator, denominator) { failure := true } } if (failure) { @@ -776,25 +774,26 @@ library OrderParametersLib { } // Aggregate new amounts weighted by time with rounding factor. - uint256 totalBeforeDivision = ((startAmount * remaining) + - (endAmount * elapsed)); + uint256 totalBeforeDivision = + ((startAmount * remaining) + (endAmount * elapsed)); // Use assembly to combine operations and skip divide-by-zero check. assembly { // Multiply by iszero(iszero(totalBeforeDivision)) to ensure // amount is set to zero if totalBeforeDivision is zero, // as intermediate overflow can occur if it is zero. - amount := mul( - iszero(iszero(totalBeforeDivision)), - // Subtract 1 from the numerator and add 1 to the result if - // roundUp is true to get the proper rounding direction. - // Division is performed with no zero check as duration - // cannot be zero as long as startTime < endTime. - add( - div(sub(totalBeforeDivision, roundUp), duration), - roundUp + amount := + mul( + iszero(iszero(totalBeforeDivision)), + // Subtract 1 from the numerator and add 1 to the result if + // roundUp is true to get the proper rounding direction. + // Division is performed with no zero check as duration + // cannot be zero as long as startTime < endTime. + add( + div(sub(totalBeforeDivision, roundUp), duration), + roundUp + ) ) - ) } // Return the current amount. diff --git a/src/lib/ReceivedItemLib.sol b/src/lib/ReceivedItemLib.sol index 92fd19c..67a022a 100644 --- a/src/lib/ReceivedItemLib.sol +++ b/src/lib/ReceivedItemLib.sol @@ -22,18 +22,17 @@ library ReceivedItemLib { keccak256("seaport.ReceivedItemDefaults"); bytes32 private constant RECEIVED_ITEMS_MAP_POSITION = keccak256("seaport.ReceivedItemsDefaults"); - bytes32 private constant EMPTY_RECEIVED_ITEM = - keccak256( - abi.encode( - ReceivedItem({ - itemType: ItemType(0), - token: address(0), - identifier: 0, - amount: 0, - recipient: payable(address(0)) - }) - ) - ); + bytes32 private constant EMPTY_RECEIVED_ITEM = keccak256( + abi.encode( + ReceivedItem({ + itemType: ItemType(0), + token: address(0), + identifier: 0, + amount: 0, + recipient: payable(address(0)) + }) + ) + ); /** * @dev Clears a default ReceivedItem from storage. @@ -41,8 +40,8 @@ library ReceivedItemLib { * @param defaultName the name of the default to clear */ function clear(string memory defaultName) internal { - mapping(string => ReceivedItem) - storage receivedItemMap = _receivedItemMap(); + mapping(string => ReceivedItem) storage receivedItemMap = + _receivedItemMap(); ReceivedItem storage item = receivedItemMap[defaultName]; clear(item); } @@ -67,8 +66,8 @@ library ReceivedItemLib { * @param defaultsName the name of the default to clear */ function clearMany(string memory defaultsName) internal { - mapping(string => ReceivedItem[]) - storage receivedItemsMap = _receivedItemsMap(); + mapping(string => ReceivedItem[]) storage receivedItemsMap = + _receivedItemsMap(); ReceivedItem[] storage items = receivedItemsMap[defaultsName]; clearMany(items); } @@ -91,14 +90,13 @@ library ReceivedItemLib { * @return the empty ReceivedItem */ function empty() internal pure returns (ReceivedItem memory) { - return - ReceivedItem({ - itemType: ItemType(0), - token: address(0), - identifier: 0, - amount: 0, - recipient: payable(address(0)) - }); + return ReceivedItem({ + itemType: ItemType(0), + token: address(0), + identifier: 0, + amount: 0, + recipient: payable(address(0)) + }); } /** @@ -108,11 +106,13 @@ library ReceivedItemLib { * * @return item the default ReceivedItem */ - function fromDefault( - string memory defaultName - ) internal view returns (ReceivedItem memory item) { - mapping(string => ReceivedItem) - storage receivedItemMap = _receivedItemMap(); + function fromDefault(string memory defaultName) + internal + view + returns (ReceivedItem memory item) + { + mapping(string => ReceivedItem) storage receivedItemMap = + _receivedItemMap(); item = receivedItemMap[defaultName]; if (keccak256(abi.encode(item)) == EMPTY_RECEIVED_ITEM) { @@ -127,11 +127,13 @@ library ReceivedItemLib { * * @return items the default ReceivedItem */ - function fromDefaultMany( - string memory defaultsName - ) internal view returns (ReceivedItem[] memory items) { - mapping(string => ReceivedItem[]) - storage receivedItemsMap = _receivedItemsMap(); + function fromDefaultMany(string memory defaultsName) + internal + view + returns (ReceivedItem[] memory items) + { + mapping(string => ReceivedItem[]) storage receivedItemsMap = + _receivedItemsMap(); items = receivedItemsMap[defaultsName]; if (items.length == 0) { @@ -151,8 +153,8 @@ library ReceivedItemLib { ReceivedItem memory receivedItem, string memory defaultName ) internal returns (ReceivedItem memory _receivedItem) { - mapping(string => ReceivedItem) - storage receivedItemMap = _receivedItemMap(); + mapping(string => ReceivedItem) storage receivedItemMap = + _receivedItemMap(); receivedItemMap[defaultName] = receivedItem; return receivedItem; } @@ -169,8 +171,8 @@ library ReceivedItemLib { ReceivedItem[] memory receivedItems, string memory defaultsName ) internal returns (ReceivedItem[] memory _receivedItems) { - mapping(string => ReceivedItem[]) - storage receivedItemsMap = _receivedItemsMap(); + mapping(string => ReceivedItem[]) storage receivedItemsMap = + _receivedItemsMap(); ReceivedItem[] storage items = receivedItemsMap[defaultsName]; setReceivedItems(items, receivedItems); return receivedItems; @@ -201,17 +203,18 @@ library ReceivedItemLib { * * @custom:return copiedReceivedItem the copied ReceivedItem */ - function copy( - ReceivedItem memory item - ) internal pure returns (ReceivedItem memory) { - return - ReceivedItem({ - itemType: item.itemType, - token: item.token, - identifier: item.identifier, - amount: item.amount, - recipient: item.recipient - }); + function copy(ReceivedItem memory item) + internal + pure + returns (ReceivedItem memory) + { + return ReceivedItem({ + itemType: item.itemType, + token: item.token, + identifier: item.identifier, + amount: item.amount, + recipient: item.recipient + }); } /** @@ -221,9 +224,11 @@ library ReceivedItemLib { * * @custom:return copiedReceivedItems the copied ReceivedItems */ - function copy( - ReceivedItem[] memory item - ) internal pure returns (ReceivedItem[] memory) { + function copy(ReceivedItem[] memory item) + internal + pure + returns (ReceivedItem[] memory) + { ReceivedItem[] memory copies = new ReceivedItem[](item.length); for (uint256 i = 0; i < item.length; i++) { copies[i] = ReceivedItemLib.copy(item[i]); @@ -276,10 +281,11 @@ library ReceivedItemLib { * * @custom:return item the ReceivedItem with the itemType field set */ - function withItemType( - ReceivedItem memory item, - ItemType itemType - ) internal pure returns (ReceivedItem memory) { + function withItemType(ReceivedItem memory item, ItemType itemType) + internal + pure + returns (ReceivedItem memory) + { item.itemType = itemType; return item; } @@ -292,10 +298,11 @@ library ReceivedItemLib { * * @custom:return item the ReceivedItem with the token field set */ - function withToken( - ReceivedItem memory item, - address token - ) internal pure returns (ReceivedItem memory) { + function withToken(ReceivedItem memory item, address token) + internal + pure + returns (ReceivedItem memory) + { item.token = token; return item; } @@ -308,10 +315,11 @@ library ReceivedItemLib { * * @custom:return item the ReceivedItem with the identifier field set */ - function withIdentifier( - ReceivedItem memory item, - uint256 identifier - ) internal pure returns (ReceivedItem memory) { + function withIdentifier(ReceivedItem memory item, uint256 identifier) + internal + pure + returns (ReceivedItem memory) + { item.identifier = identifier; return item; } @@ -324,10 +332,11 @@ library ReceivedItemLib { * * @custom:return item the ReceivedItem with the amount field set */ - function withAmount( - ReceivedItem memory item, - uint256 amount - ) internal pure returns (ReceivedItem memory) { + function withAmount(ReceivedItem memory item, uint256 amount) + internal + pure + returns (ReceivedItem memory) + { item.amount = amount; return item; } @@ -340,10 +349,11 @@ library ReceivedItemLib { * * @custom:return item the ReceivedItem with the recipient field set */ - function withRecipient( - ReceivedItem memory item, - address recipient - ) internal pure returns (ReceivedItem memory) { + function withRecipient(ReceivedItem memory item, address recipient) + internal + pure + returns (ReceivedItem memory) + { item.recipient = payable(recipient); return item; } @@ -355,17 +365,18 @@ library ReceivedItemLib { * * @custom:return considerationItem the converted ConsiderationItem */ - function toConsiderationItem( - ReceivedItem memory item - ) internal pure returns (ConsiderationItem memory) { - return - ConsiderationItem({ - itemType: item.itemType, - token: item.token, - identifierOrCriteria: item.identifier, - startAmount: item.amount, - endAmount: item.amount, - recipient: item.recipient - }); + function toConsiderationItem(ReceivedItem memory item) + internal + pure + returns (ConsiderationItem memory) + { + return ConsiderationItem({ + itemType: item.itemType, + token: item.token, + identifierOrCriteria: item.identifier, + startAmount: item.amount, + endAmount: item.amount, + recipient: item.recipient + }); } } diff --git a/src/lib/SeaportArrays.sol b/src/lib/SeaportArrays.sol index b8dac57..a692f32 100644 --- a/src/lib/SeaportArrays.sol +++ b/src/lib/SeaportArrays.sol @@ -24,21 +24,22 @@ library SeaportArrays { return arr; } - function Orders( - Order memory a, - Order memory b - ) internal pure returns (Order[] memory) { + function Orders(Order memory a, Order memory b) + internal + pure + returns (Order[] memory) + { Order[] memory arr = new Order[](2); arr[0] = a; arr[1] = b; return arr; } - function Orders( - Order memory a, - Order memory b, - Order memory c - ) internal pure returns (Order[] memory) { + function Orders(Order memory a, Order memory b, Order memory c) + internal + pure + returns (Order[] memory) + { Order[] memory arr = new Order[](3); arr[0] = a; arr[1] = b; @@ -114,18 +115,21 @@ library SeaportArrays { return arr; } - function AdvancedOrders( - AdvancedOrder memory a - ) internal pure returns (AdvancedOrder[] memory) { + function AdvancedOrders(AdvancedOrder memory a) + internal + pure + returns (AdvancedOrder[] memory) + { AdvancedOrder[] memory arr = new AdvancedOrder[](1); arr[0] = a; return arr; } - function AdvancedOrders( - AdvancedOrder memory a, - AdvancedOrder memory b - ) internal pure returns (AdvancedOrder[] memory) { + function AdvancedOrders(AdvancedOrder memory a, AdvancedOrder memory b) + internal + pure + returns (AdvancedOrder[] memory) + { AdvancedOrder[] memory arr = new AdvancedOrder[](2); arr[0] = a; arr[1] = b; @@ -212,9 +216,11 @@ library SeaportArrays { return arr; } - function OrderComponentsArray( - OrderComponents memory a - ) internal pure returns (OrderComponents[] memory) { + function OrderComponentsArray(OrderComponents memory a) + internal + pure + returns (OrderComponents[] memory) + { OrderComponents[] memory arr = new OrderComponents[](1); arr[0] = a; return arr; @@ -310,9 +316,11 @@ library SeaportArrays { return arr; } - function OrderParametersArray( - OrderParameters memory a - ) internal pure returns (OrderParameters[] memory) { + function OrderParametersArray(OrderParameters memory a) + internal + pure + returns (OrderParameters[] memory) + { OrderParameters[] memory arr = new OrderParameters[](1); arr[0] = a; return arr; @@ -408,18 +416,21 @@ library SeaportArrays { return arr; } - function OfferItems( - OfferItem memory a - ) internal pure returns (OfferItem[] memory) { + function OfferItems(OfferItem memory a) + internal + pure + returns (OfferItem[] memory) + { OfferItem[] memory arr = new OfferItem[](1); arr[0] = a; return arr; } - function OfferItems( - OfferItem memory a, - OfferItem memory b - ) internal pure returns (OfferItem[] memory) { + function OfferItems(OfferItem memory a, OfferItem memory b) + internal + pure + returns (OfferItem[] memory) + { OfferItem[] memory arr = new OfferItem[](2); arr[0] = a; arr[1] = b; @@ -506,9 +517,11 @@ library SeaportArrays { return arr; } - function ConsiderationItems( - ConsiderationItem memory a - ) internal pure returns (ConsiderationItem[] memory) { + function ConsiderationItems(ConsiderationItem memory a) + internal + pure + returns (ConsiderationItem[] memory) + { ConsiderationItem[] memory arr = new ConsiderationItem[](1); arr[0] = a; return arr; @@ -604,18 +617,21 @@ library SeaportArrays { return arr; } - function SpentItems( - SpentItem memory a - ) internal pure returns (SpentItem[] memory) { + function SpentItems(SpentItem memory a) + internal + pure + returns (SpentItem[] memory) + { SpentItem[] memory arr = new SpentItem[](1); arr[0] = a; return arr; } - function SpentItems( - SpentItem memory a, - SpentItem memory b - ) internal pure returns (SpentItem[] memory) { + function SpentItems(SpentItem memory a, SpentItem memory b) + internal + pure + returns (SpentItem[] memory) + { SpentItem[] memory arr = new SpentItem[](2); arr[0] = a; arr[1] = b; @@ -702,18 +718,21 @@ library SeaportArrays { return arr; } - function ReceivedItems( - ReceivedItem memory a - ) internal pure returns (ReceivedItem[] memory) { + function ReceivedItems(ReceivedItem memory a) + internal + pure + returns (ReceivedItem[] memory) + { ReceivedItem[] memory arr = new ReceivedItem[](1); arr[0] = a; return arr; } - function ReceivedItems( - ReceivedItem memory a, - ReceivedItem memory b - ) internal pure returns (ReceivedItem[] memory) { + function ReceivedItems(ReceivedItem memory a, ReceivedItem memory b) + internal + pure + returns (ReceivedItem[] memory) + { ReceivedItem[] memory arr = new ReceivedItem[](2); arr[0] = a; arr[1] = b; @@ -800,9 +819,11 @@ library SeaportArrays { return arr; } - function FulfillmentComponents( - FulfillmentComponent memory a - ) internal pure returns (FulfillmentComponent[] memory) { + function FulfillmentComponents(FulfillmentComponent memory a) + internal + pure + returns (FulfillmentComponent[] memory) + { FulfillmentComponent[] memory arr = new FulfillmentComponent[](1); arr[0] = a; return arr; @@ -898,9 +919,11 @@ library SeaportArrays { return arr; } - function FulfillmentComponentArrays( - FulfillmentComponent[] memory a - ) internal pure returns (FulfillmentComponent[][] memory) { + function FulfillmentComponentArrays(FulfillmentComponent[] memory a) + internal + pure + returns (FulfillmentComponent[][] memory) + { FulfillmentComponent[][] memory arr = new FulfillmentComponent[][](1); arr[0] = a; return arr; @@ -996,9 +1019,11 @@ library SeaportArrays { return arr; } - function CriteriaResolvers( - CriteriaResolver memory a - ) internal pure returns (CriteriaResolver[] memory) { + function CriteriaResolvers(CriteriaResolver memory a) + internal + pure + returns (CriteriaResolver[] memory) + { CriteriaResolver[] memory arr = new CriteriaResolver[](1); arr[0] = a; return arr; @@ -1094,9 +1119,11 @@ library SeaportArrays { return arr; } - function AdditionalRecipients( - AdditionalRecipient memory a - ) internal pure returns (AdditionalRecipient[] memory) { + function AdditionalRecipients(AdditionalRecipient memory a) + internal + pure + returns (AdditionalRecipient[] memory) + { AdditionalRecipient[] memory arr = new AdditionalRecipient[](1); arr[0] = a; return arr; @@ -1192,9 +1219,11 @@ library SeaportArrays { return arr; } - function BasicOrderParametersArray( - BasicOrderParameters memory a - ) internal pure returns (BasicOrderParameters[] memory) { + function BasicOrderParametersArray(BasicOrderParameters memory a) + internal + pure + returns (BasicOrderParameters[] memory) + { BasicOrderParameters[] memory arr = new BasicOrderParameters[](1); arr[0] = a; return arr; @@ -1290,18 +1319,21 @@ library SeaportArrays { return arr; } - function Fulfillments( - Fulfillment memory a - ) internal pure returns (Fulfillment[] memory) { + function Fulfillments(Fulfillment memory a) + internal + pure + returns (Fulfillment[] memory) + { Fulfillment[] memory arr = new Fulfillment[](1); arr[0] = a; return arr; } - function Fulfillments( - Fulfillment memory a, - Fulfillment memory b - ) internal pure returns (Fulfillment[] memory) { + function Fulfillments(Fulfillment memory a, Fulfillment memory b) + internal + pure + returns (Fulfillment[] memory) + { Fulfillment[] memory arr = new Fulfillment[](2); arr[0] = a; arr[1] = b; diff --git a/src/lib/SeaportEnumsLib.sol b/src/lib/SeaportEnumsLib.sol index f15d7ef..8ddb444 100644 --- a/src/lib/SeaportEnumsLib.sol +++ b/src/lib/SeaportEnumsLib.sol @@ -22,9 +22,7 @@ library SeaportEnumsLib { * @return offerTypeIsAdditionalRecipientsType whether the offer type is the * additional recipients type */ - function parseBasicOrderType( - BasicOrderType basicOrderType - ) + function parseBasicOrderType(BasicOrderType basicOrderType) internal pure returns ( @@ -48,10 +46,8 @@ library SeaportEnumsLib { // If route > 2, receivedItemType is route - 2. If route is 2, // the receivedItemType is ERC20 (1). Otherwise, it is Eth (0). - considerationType := add( - mul(sub(route, 2), gt(route, 2)), - eq(route, 2) - ) + considerationType := + add(mul(sub(route, 2), gt(route, 2)), eq(route, 2)) // If route > 3, offeredItemType is ERC20 (1). Route is 2 or 3, // offeredItemType = route. Route is 0 or 1, it is route + 2. diff --git a/src/lib/SpentItemLib.sol b/src/lib/SpentItemLib.sol index 077e2b9..5568f72 100644 --- a/src/lib/SpentItemLib.sol +++ b/src/lib/SpentItemLib.sol @@ -1,7 +1,10 @@ // SPDX-License-Identifier: MIT pragma solidity ^0.8.17; -import { OfferItem, SpentItem } from "seaport-types/src/lib/ConsiderationStructs.sol"; +import { + OfferItem, + SpentItem +} from "seaport-types/src/lib/ConsiderationStructs.sol"; import { ItemType } from "seaport-types/src/lib/ConsiderationEnums.sol"; @@ -17,17 +20,16 @@ library SpentItemLib { keccak256("seaport.SpentItemDefaults"); bytes32 private constant SPENT_ITEMS_MAP_POSITION = keccak256("seaport.SpentItemsDefaults"); - bytes32 private constant EMPTY_SPENT_ITEM = - keccak256( - abi.encode( - SpentItem({ - itemType: ItemType(0), - token: address(0), - identifier: 0, - amount: 0 - }) - ) - ); + bytes32 private constant EMPTY_SPENT_ITEM = keccak256( + abi.encode( + SpentItem({ + itemType: ItemType(0), + token: address(0), + identifier: 0, + amount: 0 + }) + ) + ); /** * @dev Creates an empty SpentItem. @@ -92,9 +94,11 @@ library SpentItemLib { * * @return item the SpentItem */ - function fromDefault( - string memory defaultName - ) internal view returns (SpentItem memory item) { + function fromDefault(string memory defaultName) + internal + view + returns (SpentItem memory item) + { mapping(string => SpentItem) storage spentItemMap = _spentItemMap(); item = spentItemMap[defaultName]; @@ -110,9 +114,11 @@ library SpentItemLib { * * @return items the SpentItems */ - function fromDefaultMany( - string memory defaultsName - ) internal view returns (SpentItem[] memory items) { + function fromDefaultMany(string memory defaultsName) + internal + view + returns (SpentItem[] memory items) + { mapping(string => SpentItem[]) storage spentItemsMap = _spentItemsMap(); items = spentItemsMap[defaultsName]; @@ -129,10 +135,10 @@ library SpentItemLib { * * @return _spentItem the saved SpentItem */ - function saveDefault( - SpentItem memory spentItem, - string memory defaultName - ) internal returns (SpentItem memory _spentItem) { + function saveDefault(SpentItem memory spentItem, string memory defaultName) + internal + returns (SpentItem memory _spentItem) + { mapping(string => SpentItem) storage spentItemMap = _spentItemMap(); spentItemMap[defaultName] = spentItem; return spentItem; @@ -181,16 +187,17 @@ library SpentItemLib { * * @custom:return copiedItem the copied SpentItem */ - function copy( - SpentItem memory item - ) internal pure returns (SpentItem memory) { - return - SpentItem({ - itemType: item.itemType, - token: item.token, - identifier: item.identifier, - amount: item.amount - }); + function copy(SpentItem memory item) + internal + pure + returns (SpentItem memory) + { + return SpentItem({ + itemType: item.itemType, + token: item.token, + identifier: item.identifier, + amount: item.amount + }); } /** @@ -200,9 +207,11 @@ library SpentItemLib { * * @custom:return copiedItems the copied SpentItems */ - function copy( - SpentItem[] memory items - ) internal pure returns (SpentItem[] memory) { + function copy(SpentItem[] memory items) + internal + pure + returns (SpentItem[] memory) + { SpentItem[] memory copiedItems = new SpentItem[](items.length); for (uint256 i = 0; i < items.length; i++) { copiedItems[i] = copy(items[i]); @@ -254,10 +263,11 @@ library SpentItemLib { * * @custom:return item the SpentItem with the itemType field set */ - function withItemType( - SpentItem memory item, - ItemType itemType - ) internal pure returns (SpentItem memory) { + function withItemType(SpentItem memory item, ItemType itemType) + internal + pure + returns (SpentItem memory) + { item.itemType = itemType; return item; } @@ -270,10 +280,11 @@ library SpentItemLib { * * @custom:return item the SpentItem with the token field set */ - function withToken( - SpentItem memory item, - address token - ) internal pure returns (SpentItem memory) { + function withToken(SpentItem memory item, address token) + internal + pure + returns (SpentItem memory) + { item.token = token; return item; } @@ -286,10 +297,11 @@ library SpentItemLib { * * @custom:return item the SpentItem with the identifier field set */ - function withIdentifier( - SpentItem memory item, - uint256 identifier - ) internal pure returns (SpentItem memory) { + function withIdentifier(SpentItem memory item, uint256 identifier) + internal + pure + returns (SpentItem memory) + { item.identifier = identifier; return item; } @@ -302,10 +314,11 @@ library SpentItemLib { * * @custom:return item the SpentItem with the amount field set */ - function withAmount( - SpentItem memory item, - uint256 amount - ) internal pure returns (SpentItem memory) { + function withAmount(SpentItem memory item, uint256 amount) + internal + pure + returns (SpentItem memory) + { item.amount = amount; return item; } @@ -317,16 +330,17 @@ library SpentItemLib { * * @custom:return offerItem the converted OfferItem */ - function toOfferItem( - SpentItem memory item - ) internal pure returns (OfferItem memory) { - return - OfferItem({ - itemType: item.itemType, - token: item.token, - identifierOrCriteria: item.identifier, - startAmount: item.amount, - endAmount: item.amount - }); + function toOfferItem(SpentItem memory item) + internal + pure + returns (OfferItem memory) + { + return OfferItem({ + itemType: item.itemType, + token: item.token, + identifierOrCriteria: item.identifier, + startAmount: item.amount, + endAmount: item.amount + }); } } diff --git a/src/lib/StructCopier.sol b/src/lib/StructCopier.sol index 5c615b0..88a5369 100644 --- a/src/lib/StructCopier.sol +++ b/src/lib/StructCopier.sol @@ -102,11 +102,10 @@ library StructCopier { dest.salt = src.salt; dest.offererConduitKey = src.offererConduitKey; dest.fulfillerConduitKey = src.fulfillerConduitKey; - dest.totalOriginalAdditionalRecipients = src - .totalOriginalAdditionalRecipients; + dest.totalOriginalAdditionalRecipients = + src.totalOriginalAdditionalRecipients; setAdditionalRecipients( - dest.additionalRecipients, - src.additionalRecipients + dest.additionalRecipients, src.additionalRecipients ); dest.signature = src.signature; } @@ -225,9 +224,10 @@ library StructCopier { return counter; } - function _deriveTempSlotWithCounter( - bytes32 libSlot - ) internal returns (uint256 derivedSlot) { + function _deriveTempSlotWithCounter(bytes32 libSlot) + internal + returns (uint256 derivedSlot) + { uint256 counter = _getAndIncrementTempCounter(); assembly { // store lib slot in first mem position @@ -311,14 +311,13 @@ library StructCopier { dest.zoneHash = src.zoneHash; dest.salt = src.salt; dest.conduitKey = src.conduitKey; - dest.totalOriginalConsiderationItems = src - .totalOriginalConsiderationItems; + dest.totalOriginalConsiderationItems = + src.totalOriginalConsiderationItems; } - function setOfferItems( - OfferItem[] storage dest, - OfferItem[] memory src - ) internal { + function setOfferItems(OfferItem[] storage dest, OfferItem[] memory src) + internal + { while (dest.length != 0) { dest.pop(); } @@ -339,14 +338,12 @@ library StructCopier { } } - function setFulfillment( - Fulfillment storage dest, - Fulfillment memory src - ) internal { + function setFulfillment(Fulfillment storage dest, Fulfillment memory src) + internal + { setFulfillmentComponents(dest.offerComponents, src.offerComponents); setFulfillmentComponents( - dest.considerationComponents, - src.considerationComponents + dest.considerationComponents, src.considerationComponents ); } @@ -394,8 +391,8 @@ library StructCopier { FulfillmentComponent[][] storage dest, FulfillmentComponent[] memory src ) internal { - FulfillmentComponent[] - storage _tempFulfillmentComponents = _getTempFulfillmentComponents(); + FulfillmentComponent[] storage _tempFulfillmentComponents = + _getTempFulfillmentComponents(); setFulfillmentComponents(_tempFulfillmentComponents, src); dest.push(_tempFulfillmentComponents); } @@ -416,9 +413,8 @@ library StructCopier { OfferItem[] memory _offerItems, address payable receiver ) internal pure returns (ConsiderationItem[] memory) { - ConsiderationItem[] memory considerationItems = new ConsiderationItem[]( - _offerItems.length - ); + ConsiderationItem[] memory considerationItems = + new ConsiderationItem[](_offerItems.length); for (uint256 i = 0; i < _offerItems.length; ++i) { considerationItems[i] = ConsiderationItem( _offerItems[i].itemType, @@ -432,12 +428,13 @@ library StructCopier { return considerationItems; } - function toOfferItems( - ConsiderationItem[] memory _considerationItems - ) internal pure returns (OfferItem[] memory) { - OfferItem[] memory _offerItems = new OfferItem[]( - _considerationItems.length - ); + function toOfferItems(ConsiderationItem[] memory _considerationItems) + internal + pure + returns (OfferItem[] memory) + { + OfferItem[] memory _offerItems = + new OfferItem[](_considerationItems.length); for (uint256 i = 0; i < _offerItems.length; i++) { _offerItems[i] = OfferItem( _considerationItems[i].itemType, @@ -456,13 +453,10 @@ library StructCopier { address zone, bytes32 conduitKey ) public pure returns (OrderParameters memory) { - OfferItem[] memory _offerItems = toOfferItems( - orderParameters.consideration - ); - ConsiderationItem[] memory _considerationItems = toConsiderationItems( - orderParameters.offer, - offerer - ); + OfferItem[] memory _offerItems = + toOfferItems(orderParameters.consideration); + ConsiderationItem[] memory _considerationItems = + toConsiderationItems(orderParameters.offer, offerer); OrderParameters memory _mirrorOrderParameters = OrderParameters( offerer, @@ -480,10 +474,9 @@ library StructCopier { return _mirrorOrderParameters; } - function setExecutions( - Execution[] storage dest, - Execution[] memory src - ) internal { + function setExecutions(Execution[] storage dest, Execution[] memory src) + internal + { while (dest.length != 0) { dest.pop(); } diff --git a/src/lib/ZoneParametersLib.sol b/src/lib/ZoneParametersLib.sol index 2fc6166..6f14b07 100644 --- a/src/lib/ZoneParametersLib.sol +++ b/src/lib/ZoneParametersLib.sol @@ -1,7 +1,11 @@ // SPDX-License-Identifier: MIT pragma solidity ^0.8.17; -import {ItemType, Side, OrderType} from "seaport-types/src/lib/ConsiderationEnums.sol"; +import { + ItemType, + Side, + OrderType +} from "seaport-types/src/lib/ConsiderationEnums.sol"; import { AdvancedOrder, @@ -17,27 +21,27 @@ import { CriteriaResolver } from "seaport-types/src/lib/ConsiderationStructs.sol"; -import {SeaportInterface} from "../SeaportInterface.sol"; +import { SeaportInterface } from "../SeaportInterface.sol"; -import {GettersAndDerivers} from "seaport-core/src/lib/GettersAndDerivers.sol"; +import { GettersAndDerivers } from "seaport-core/src/lib/GettersAndDerivers.sol"; -import {UnavailableReason} from "../SpaceEnums.sol"; +import { UnavailableReason } from "../SpaceEnums.sol"; -import {AdvancedOrderLib} from "./AdvancedOrderLib.sol"; +import { AdvancedOrderLib } from "./AdvancedOrderLib.sol"; -import {ConsiderationItemLib} from "./ConsiderationItemLib.sol"; +import { ConsiderationItemLib } from "./ConsiderationItemLib.sol"; -import {OfferItemLib} from "./OfferItemLib.sol"; +import { OfferItemLib } from "./OfferItemLib.sol"; -import {ReceivedItemLib} from "./ReceivedItemLib.sol"; +import { ReceivedItemLib } from "./ReceivedItemLib.sol"; -import {OrderParametersLib} from "./OrderParametersLib.sol"; +import { OrderParametersLib } from "./OrderParametersLib.sol"; -import {StructCopier} from "./StructCopier.sol"; +import { StructCopier } from "./StructCopier.sol"; -import {AmountDeriverHelper} from "./fulfillment/AmountDeriverHelper.sol"; +import { AmountDeriverHelper } from "./fulfillment/AmountDeriverHelper.sol"; -import {OrderDetails} from "../fulfillments/lib/Structs.sol"; +import { OrderDetails } from "../fulfillments/lib/Structs.sol"; interface FailingContractOfferer { function failureReasons(bytes32) external view returns (uint256); @@ -80,10 +84,15 @@ library ZoneParametersLib { 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 + bytes32 orderHash = + advancedOrder.getTipNeutralizedOrderHash(seaportInterface, counter); + + (SpentItem[] memory spentItems, ReceivedItem[] memory receivedItems) = + orderParameters.getSpentAndReceivedItems( + advancedOrder.numerator, + advancedOrder.denominator, + 0, + criteriaResolvers ); // Store orderHash in orderHashes array to pass into zoneParameters @@ -114,7 +123,13 @@ library ZoneParametersLib { UnavailableReason[] memory unavailableReasons ) internal view returns (ZoneParameters[] memory) { return _getZoneParametersFromStruct( - _getZoneParametersStruct(advancedOrders, fulfiller, maximumFulfilled, seaport, criteriaResolvers), + _getZoneParametersStruct( + advancedOrders, + fulfiller, + maximumFulfilled, + seaport, + criteriaResolvers + ), unavailableReasons ); } @@ -126,7 +141,13 @@ library ZoneParametersLib { address seaport, CriteriaResolver[] memory criteriaResolvers ) internal pure returns (ZoneParametersStruct memory) { - return ZoneParametersStruct(advancedOrders, fulfiller, maximumFulfilled, seaport, criteriaResolvers); + return ZoneParametersStruct( + advancedOrders, + fulfiller, + maximumFulfilled, + seaport, + criteriaResolvers + ); } function _getZoneParametersFromStruct( @@ -155,11 +176,9 @@ library ZoneParametersLib { fulfiller: zoneParametersStruct.fulfiller, maximumFulfilled: zoneParametersStruct.maximumFulfilled, orderDetails: new OrderDetails[]( - zoneParametersStruct.advancedOrders.length - ), - orderHashes: new bytes32[]( - zoneParametersStruct.advancedOrders.length - ) + zoneParametersStruct.advancedOrders.length + ), + orderHashes: new bytes32[](zoneParametersStruct.advancedOrders.length) }); } @@ -168,15 +187,24 @@ library ZoneParametersLib { ZoneParametersStruct memory zoneParametersStruct, UnavailableReason[] memory unavailableReasons ) internal view { - bytes32[] memory orderHashes = details.advancedOrders.getOrderHashes(zoneParametersStruct.seaport); - - details.orderDetails = zoneParametersStruct.advancedOrders.getOrderDetails( - zoneParametersStruct.criteriaResolvers, orderHashes, unavailableReasons + bytes32[] memory orderHashes = + details.advancedOrders.getOrderHashes(zoneParametersStruct.seaport); + + details.orderDetails = zoneParametersStruct + .advancedOrders + .getOrderDetails( + zoneParametersStruct.criteriaResolvers, + orderHashes, + unavailableReasons ); } - function _applyOrderHashes(ZoneDetails memory details, address seaport) internal view { - bytes32[] memory orderHashes = details.advancedOrders.getOrderHashes(seaport); + function _applyOrderHashes(ZoneDetails memory details, address seaport) + internal + view + { + bytes32[] memory orderHashes = + details.advancedOrders.getOrderHashes(seaport); uint256 totalFulfilled = 0; // Iterate over advanced orders to calculate orderHashes @@ -185,7 +213,11 @@ library ZoneParametersLib { if ( totalFulfilled >= details.maximumFulfilled - || _isUnavailable(details.advancedOrders[i].parameters, orderHash, SeaportInterface(seaport)) + || _isUnavailable( + details.advancedOrders[i].parameters, + orderHash, + SeaportInterface(seaport) + ) ) { // Set orderHash to 0 if order index exceeds maximumFulfilled details.orderHashes[i] = bytes32(0); @@ -197,21 +229,25 @@ library ZoneParametersLib { } } - function _isUnavailable(OrderParameters memory order, bytes32 orderHash, SeaportInterface seaport) - internal - view - returns (bool) - { - (, bool isCancelled, uint256 totalFilled, uint256 totalSize) = seaport.getOrderStatus(orderHash); + function _isUnavailable( + OrderParameters memory order, + bytes32 orderHash, + SeaportInterface seaport + ) internal view returns (bool) { + (, bool isCancelled, uint256 totalFilled, uint256 totalSize) = + seaport.getOrderStatus(orderHash); bool isRevertingContractOrder = false; if (order.orderType == OrderType.CONTRACT) { - isRevertingContractOrder = FailingContractOfferer(order.offerer).failureReasons(orderHash) != 0; + isRevertingContractOrder = FailingContractOfferer(order.offerer) + .failureReasons(orderHash) != 0; } return ( - block.timestamp >= order.endTime || block.timestamp < order.startTime || isCancelled - || isRevertingContractOrder || (totalFilled >= totalSize && totalSize > 0) + block.timestamp >= order.endTime + || block.timestamp < order.startTime || isCancelled + || isRevertingContractOrder + || (totalFilled >= totalSize && totalSize > 0) ); } @@ -220,9 +256,7 @@ library ZoneParametersLib { pure returns (ZoneParameters[] memory zoneParameters) { - zoneParameters = new ZoneParameters[]( - zoneDetails.advancedOrders.length - ); + zoneParameters = new ZoneParameters[](zoneDetails.advancedOrders.length); // Iterate through advanced orders to create zoneParameters uint256 totalFulfilled = 0; diff --git a/src/lib/fulfillment/AmountDeriverHelper.sol b/src/lib/fulfillment/AmountDeriverHelper.sol index 22d40b0..458270b 100644 --- a/src/lib/fulfillment/AmountDeriverHelper.sol +++ b/src/lib/fulfillment/AmountDeriverHelper.sol @@ -1,8 +1,9 @@ // SPDX-License-Identifier: MIT pragma solidity ^0.8.17; -import {SeaportInterface} from "seaport-types/src/interfaces/SeaportInterface.sol"; -import {AmountDeriver} from "seaport-core/src/lib/AmountDeriver.sol"; +import { SeaportInterface } from + "seaport-types/src/interfaces/SeaportInterface.sol"; +import { AmountDeriver } from "seaport-core/src/lib/AmountDeriver.sol"; import { AdvancedOrder, ConsiderationItem, @@ -15,12 +16,12 @@ import { ReceivedItem, SpentItem } from "seaport-types/src/lib/ConsiderationStructs.sol"; -import {Side, ItemType} from "seaport-types/src/lib/ConsiderationEnums.sol"; -import {OfferItemLib} from "../OfferItemLib.sol"; -import {ConsiderationItemLib} from "../ConsiderationItemLib.sol"; -import {OrderParametersLib} from "../OrderParametersLib.sol"; -import {OrderDetails} from "../../fulfillments/lib/Structs.sol"; -import {UnavailableReason} from "../../SpaceEnums.sol"; +import { Side, ItemType } from "seaport-types/src/lib/ConsiderationEnums.sol"; +import { OfferItemLib } from "../OfferItemLib.sol"; +import { ConsiderationItemLib } from "../ConsiderationItemLib.sol"; +import { OrderParametersLib } from "../OrderParametersLib.sol"; +import { OrderDetails } from "../../fulfillments/lib/Structs.sol"; +import { UnavailableReason } from "../../SpaceEnums.sol"; /** * @notice Note that this contract relies on current block.timestamp to determine amounts. @@ -50,16 +51,26 @@ contract AmountDeriverHelper is AmountDeriver { returns (SpentItem[] memory spent, ReceivedItem[] memory received) { CriteriaResolver[] memory resolvers; - return getSpentAndReceivedItems(order.parameters, order.numerator, order.denominator, 0, resolvers); + return getSpentAndReceivedItems( + order.parameters, order.numerator, order.denominator, 0, resolvers + ); } function getSpentAndReceivedItems( AdvancedOrder calldata order, uint256 orderIndex, CriteriaResolver[] calldata criteriaResolvers - ) external view returns (SpentItem[] memory spent, ReceivedItem[] memory received) { + ) + external + view + returns (SpentItem[] memory spent, ReceivedItem[] memory received) + { return getSpentAndReceivedItems( - order.parameters, order.numerator, order.denominator, orderIndex, criteriaResolvers + order.parameters, + order.numerator, + order.denominator, + orderIndex, + criteriaResolvers ); } @@ -74,12 +85,13 @@ contract AmountDeriverHelper is AmountDeriver { } } - function toOrderDetails(OrderParameters memory order, bytes32 orderHash, UnavailableReason unavailableReason) - internal - view - returns (OrderDetails memory) - { - (SpentItem[] memory offer, ReceivedItem[] memory consideration) = this.getSpentAndReceivedItems(order); + function toOrderDetails( + OrderParameters memory order, + bytes32 orderHash, + UnavailableReason unavailableReason + ) internal view returns (OrderDetails memory) { + (SpentItem[] memory offer, ReceivedItem[] memory consideration) = + this.getSpentAndReceivedItems(order); return OrderDetails({ offerer: order.offerer, conduitKey: order.conduitKey, @@ -98,7 +110,9 @@ contract AmountDeriverHelper is AmountDeriver { ) public view returns (OrderDetails[] memory) { OrderDetails[] memory orderDetails = new OrderDetails[](order.length); for (uint256 i = 0; i < order.length; i++) { - orderDetails[i] = toOrderDetails(order[i].parameters, orderHashes[i], unavailableReasons[i]); + orderDetails[i] = toOrderDetails( + order[i].parameters, orderHashes[i], unavailableReasons[i] + ); } return orderDetails; } @@ -111,7 +125,9 @@ contract AmountDeriverHelper is AmountDeriver { ) public view returns (OrderDetails[] memory) { OrderDetails[] memory orderDetails = new OrderDetails[](orders.length); for (uint256 i = 0; i < orders.length; i++) { - orderDetails[i] = toOrderDetails(orders[i], i, resolvers, orderHashes[i], unavailableReasons[i]); + orderDetails[i] = toOrderDetails( + orders[i], i, resolvers, orderHashes[i], unavailableReasons[i] + ); } return orderDetails; } @@ -143,12 +159,18 @@ contract AmountDeriverHelper is AmountDeriver { uint256 denominator, uint256 orderIndex, CriteriaResolver[] memory criteriaResolvers - ) private view returns (SpentItem[] memory spent, ReceivedItem[] memory received) { + ) + private + view + returns (SpentItem[] memory spent, ReceivedItem[] memory received) + { if (parameters.isAvailable()) { spent = getSpentItems(parameters, numerator, denominator); received = getReceivedItems(parameters, numerator, denominator); - applyCriteriaResolvers(spent, received, orderIndex, criteriaResolvers); + applyCriteriaResolvers( + spent, received, orderIndex, criteriaResolvers + ); } } @@ -175,7 +197,11 @@ contract AmountDeriverHelper is AmountDeriver { } } - function convertCriteriaItemType(ItemType itemType) internal pure returns (ItemType) { + function convertCriteriaItemType(ItemType itemType) + internal + pure + returns (ItemType) + { if (itemType == ItemType.ERC721_WITH_CRITERIA) { return ItemType.ERC721; } else if (itemType == ItemType.ERC1155_WITH_CRITERIA) { @@ -185,23 +211,35 @@ contract AmountDeriverHelper is AmountDeriver { } } - function getSpentItems(OrderParameters memory parameters, uint256 numerator, uint256 denominator) - private - view - returns (SpentItem[] memory) - { - return getSpentItems(parameters.offer, parameters.startTime, parameters.endTime, numerator, denominator); - } - - function getSpentItems(OrderParameters memory parameters) private view returns (SpentItem[] memory) { - return getSpentItems(parameters.offer, parameters.startTime, parameters.endTime); + function getSpentItems( + OrderParameters memory parameters, + uint256 numerator, + uint256 denominator + ) private view returns (SpentItem[] memory) { + return getSpentItems( + parameters.offer, + parameters.startTime, + parameters.endTime, + numerator, + denominator + ); } - function getSpentItems(OfferItem[] memory offerItems, uint256 startTime, uint256 endTime) + function getSpentItems(OrderParameters memory parameters) private view returns (SpentItem[] memory) { + return getSpentItems( + parameters.offer, parameters.startTime, parameters.endTime + ); + } + + function getSpentItems( + OfferItem[] memory offerItems, + uint256 startTime, + uint256 endTime + ) private view returns (SpentItem[] memory) { SpentItem[] memory spentItems = new SpentItem[](offerItems.length); for (uint256 i = 0; i < offerItems.length; i++) { spentItems[i] = getSpentItem(offerItems[i], startTime, endTime); @@ -218,21 +256,27 @@ contract AmountDeriverHelper is AmountDeriver { ) private view returns (SpentItem[] memory) { SpentItem[] memory spentItems = new SpentItem[](items.length); for (uint256 i = 0; i < items.length; i++) { - spentItems[i] = getSpentItem(items[i], startTime, endTime, numerator, denominator); + spentItems[i] = getSpentItem( + items[i], startTime, endTime, numerator, denominator + ); } return spentItems; } - function getSpentItem(OfferItem memory offerItem, uint256 startTime, uint256 endTime) - private - view - returns (SpentItem memory spent) - { + function getSpentItem( + OfferItem memory offerItem, + uint256 startTime, + uint256 endTime + ) private view returns (SpentItem memory spent) { spent = SpentItem({ itemType: offerItem.itemType, token: offerItem.token, identifier: offerItem.identifierOrCriteria, - amount: _locateCurrentAmount({item: offerItem, startTime: startTime, endTime: endTime}) + amount: _locateCurrentAmount({ + item: offerItem, + startTime: startTime, + endTime: endTime + }) }); } @@ -261,29 +305,40 @@ contract AmountDeriverHelper is AmountDeriver { }); } - function getReceivedItems(OrderParameters memory parameters) private view returns (ReceivedItem[] memory) { - return getReceivedItems(parameters.consideration, parameters.startTime, parameters.endTime); - } - - function getReceivedItems(OrderParameters memory parameters, uint256 numerator, uint256 denominator) + function getReceivedItems(OrderParameters memory parameters) private view returns (ReceivedItem[] memory) { - return - getReceivedItems(parameters.consideration, parameters.startTime, parameters.endTime, numerator, denominator); + return getReceivedItems( + parameters.consideration, parameters.startTime, parameters.endTime + ); } - function getReceivedItems(ConsiderationItem[] memory considerationItems, uint256 startTime, uint256 endTime) - private - view - returns (ReceivedItem[] memory) - { - ReceivedItem[] memory receivedItems = new ReceivedItem[]( - considerationItems.length + function getReceivedItems( + OrderParameters memory parameters, + uint256 numerator, + uint256 denominator + ) private view returns (ReceivedItem[] memory) { + return getReceivedItems( + parameters.consideration, + parameters.startTime, + parameters.endTime, + numerator, + denominator ); + } + + function getReceivedItems( + ConsiderationItem[] memory considerationItems, + uint256 startTime, + uint256 endTime + ) private view returns (ReceivedItem[] memory) { + ReceivedItem[] memory receivedItems = + new ReceivedItem[](considerationItems.length); for (uint256 i = 0; i < considerationItems.length; i++) { - receivedItems[i] = getReceivedItem(considerationItems[i], startTime, endTime); + receivedItems[i] = + getReceivedItem(considerationItems[i], startTime, endTime); } return receivedItems; } @@ -295,25 +350,34 @@ contract AmountDeriverHelper is AmountDeriver { uint256 numerator, uint256 denominator ) private view returns (ReceivedItem[] memory) { - ReceivedItem[] memory receivedItems = new ReceivedItem[]( - considerationItems.length - ); + ReceivedItem[] memory receivedItems = + new ReceivedItem[](considerationItems.length); for (uint256 i = 0; i < considerationItems.length; i++) { - receivedItems[i] = getReceivedItem(considerationItems[i], startTime, endTime, numerator, denominator); + receivedItems[i] = getReceivedItem( + considerationItems[i], + startTime, + endTime, + numerator, + denominator + ); } return receivedItems; } - function getReceivedItem(ConsiderationItem memory considerationItem, uint256 startTime, uint256 endTime) - private - view - returns (ReceivedItem memory received) - { + function getReceivedItem( + ConsiderationItem memory considerationItem, + uint256 startTime, + uint256 endTime + ) private view returns (ReceivedItem memory received) { received = ReceivedItem({ itemType: considerationItem.itemType, token: considerationItem.token, identifier: considerationItem.identifierOrCriteria, - amount: _locateCurrentAmount({item: considerationItem, startTime: startTime, endTime: endTime}), + amount: _locateCurrentAmount({ + item: considerationItem, + startTime: startTime, + endTime: endTime + }), recipient: considerationItem.recipient }); } @@ -344,11 +408,11 @@ contract AmountDeriverHelper is AmountDeriver { }); } - function _locateCurrentAmount(OfferItem memory item, uint256 startTime, uint256 endTime) - private - view - returns (uint256) - { + function _locateCurrentAmount( + OfferItem memory item, + uint256 startTime, + uint256 endTime + ) private view returns (uint256) { return _locateCurrentAmount({ startAmount: item.startAmount, endAmount: item.endAmount, @@ -367,19 +431,24 @@ contract AmountDeriverHelper is AmountDeriver { uint256 denominator ) public pure returns (uint256 newStartAmount, uint256 newEndAmount) { if ( - startTime >= endTime || numerator > denominator || numerator == 0 || denominator == 0 + startTime >= endTime || numerator > denominator || numerator == 0 + || denominator == 0 || (originalStartAmount == 0 && originalEndAmount == 0) ) { - revert("AmountDeriverHelper: bad inputs to deriveFractionCompatibleAmounts"); + revert( + "AmountDeriverHelper: bad inputs to deriveFractionCompatibleAmounts" + ); } uint256 duration = endTime - startTime; // determine if duration or numerator is more likely to overflow when multiplied by value - uint256 overflowBottleneck = (numerator > duration) ? numerator : duration; + uint256 overflowBottleneck = + (numerator > duration) ? numerator : duration; uint256 absoluteMax = type(uint256).max / overflowBottleneck; - uint256 fractionCompatibleMax = (absoluteMax / denominator) * denominator; + uint256 fractionCompatibleMax = + (absoluteMax / denominator) * denominator; newStartAmount = originalStartAmount % fractionCompatibleMax; newStartAmount = (newStartAmount / denominator) * denominator; @@ -394,11 +463,11 @@ contract AmountDeriverHelper is AmountDeriver { } } - function _locateCurrentAmount(ConsiderationItem memory item, uint256 startTime, uint256 endTime) - private - view - returns (uint256) - { + function _locateCurrentAmount( + ConsiderationItem memory item, + uint256 startTime, + uint256 endTime + ) private view returns (uint256) { return _locateCurrentAmount({ startAmount: item.startAmount, endAmount: item.endAmount, @@ -425,7 +494,7 @@ contract AmountDeriverHelper is AmountDeriver { startTime: startTime, endTime: endTime, roundUp: false // don't round up offers - }); + }); } function _applyFraction( @@ -446,6 +515,6 @@ contract AmountDeriverHelper is AmountDeriver { startTime: startTime, endTime: endTime, roundUp: true // round up considerations - }); + }); } } diff --git a/src/lib/types/MatchComponentType.sol b/src/lib/types/MatchComponentType.sol index 78e5d90..99a5df6 100644 --- a/src/lib/types/MatchComponentType.sol +++ b/src/lib/types/MatchComponentType.sol @@ -1,7 +1,7 @@ // SPDX-License-Identifier: MIT pragma solidity ^0.8.17; -import {FulfillmentComponent} from "../../SeaportStructs.sol"; +import { FulfillmentComponent } from "../../SeaportStructs.sol"; struct MatchComponent { uint256 amount; @@ -15,18 +15,21 @@ library MatchComponentType { uint256 private constant AMOUNT_SHL_OFFSET = 16; uint256 private constant ORDER_INDEX_SHL_OFFSET = 8; uint256 private constant BYTE_MASK = 0xFF; - uint256 private constant AMOUNT_MASK = 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF0000; + uint256 private constant AMOUNT_MASK = + 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF0000; uint256 private constant ORDER_INDEX_MASK = 0xFF00; uint256 private constant ITEM_INDEX_MASK = 0xFF; uint256 private constant NOT_AMOUNT_MASK = 0xFFFF; - uint256 private constant NOT_ORDER_INDEX_MASK = 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF00FF; - uint256 private constant NOT_ITEM_INDEX_MASK = 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF00; - - function createMatchComponent(uint256 amount, uint8 orderIndex, uint8 itemIndex) - internal - pure - returns (MatchComponent memory component) - { + uint256 private constant NOT_ORDER_INDEX_MASK = + 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF00FF; + uint256 private constant NOT_ITEM_INDEX_MASK = + 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF00; + + function createMatchComponent( + uint256 amount, + uint8 orderIndex, + uint8 itemIndex + ) internal pure returns (MatchComponent memory component) { component.amount = amount; component.orderIndex = orderIndex; component.itemIndex = itemIndex; @@ -38,11 +41,19 @@ library MatchComponentType { // } } - function getAmount(MatchComponent memory component) internal pure returns (uint256 amount) { + function getAmount(MatchComponent memory component) + internal + pure + returns (uint256 amount) + { return component.amount; } - function copy(MatchComponent memory component) internal pure returns (MatchComponent memory copy_) { + function copy(MatchComponent memory component) + internal + pure + returns (MatchComponent memory copy_) + { copy_.amount = component.amount; copy_.orderIndex = component.orderIndex; copy_.itemIndex = component.itemIndex; @@ -57,7 +68,11 @@ library MatchComponentType { newComponent.amount = amount; } - function getOrderIndex(MatchComponent memory component) internal pure returns (uint8 orderIndex) { + function getOrderIndex(MatchComponent memory component) + internal + pure + returns (uint8 orderIndex) + { return component.orderIndex; } @@ -70,7 +85,11 @@ library MatchComponentType { newComponent.orderIndex = orderIndex; } - function getItemIndex(MatchComponent memory component) internal pure returns (uint8 itemIndex) { + function getItemIndex(MatchComponent memory component) + internal + pure + returns (uint8 itemIndex) + { return component.itemIndex; } @@ -91,11 +110,10 @@ library MatchComponentType { return (component.amount, component.orderIndex, component.itemIndex); } - function subtractAmount(MatchComponent memory minuend, MatchComponent memory subtrahend) - internal - pure - returns (MatchComponent memory newComponent) - { + function subtractAmount( + MatchComponent memory minuend, + MatchComponent memory subtrahend + ) internal pure returns (MatchComponent memory newComponent) { uint256 minuendAmount = minuend.getAmount(); uint256 subtrahendAmount = subtrahend.getAmount(); uint256 newAmount = uint256(minuendAmount - subtrahendAmount); @@ -119,7 +137,10 @@ library MatchComponentType { returns (FulfillmentComponent memory) { (, uint8 orderIndex, uint8 itemIndex) = component.unpack(); - return FulfillmentComponent({orderIndex: orderIndex, itemIndex: itemIndex}); + return FulfillmentComponent({ + orderIndex: orderIndex, + itemIndex: itemIndex + }); } function toFulfillmentComponents(MatchComponent[] memory components) @@ -127,31 +148,47 @@ library MatchComponentType { pure returns (FulfillmentComponent[] memory) { - FulfillmentComponent[] memory fulfillmentComponents = new FulfillmentComponent[]( - components.length - ); + FulfillmentComponent[] memory fulfillmentComponents = + new FulfillmentComponent[](components.length); for (uint256 i = 0; i < components.length; i++) { fulfillmentComponents[i] = components[i].toFulfillmentComponent(); } return fulfillmentComponents; } - function toStruct(MatchComponent memory component) internal pure returns (MatchComponent memory) { + function toStruct(MatchComponent memory component) + internal + pure + returns (MatchComponent memory) + { (uint256 amount, uint8 orderIndex, uint8 itemIndex) = component.unpack(); - return MatchComponent({amount: amount, orderIndex: orderIndex, itemIndex: itemIndex}); + return MatchComponent({ + amount: amount, + orderIndex: orderIndex, + itemIndex: itemIndex + }); } - function toStructs(MatchComponent[] memory components) internal pure returns (MatchComponent[] memory) { - MatchComponent[] memory structs = new MatchComponent[]( - components.length - ); + function toStructs(MatchComponent[] memory components) + internal + pure + returns (MatchComponent[] memory) + { + MatchComponent[] memory structs = + new MatchComponent[](components.length); for (uint256 i = 0; i < components.length; i++) { structs[i] = components[i].toStruct(); } return structs; } - function equals(MatchComponent memory left, MatchComponent memory right) internal pure returns (bool) { - return left.amount == right.amount && left.orderIndex == right.orderIndex && left.itemIndex == right.itemIndex; + function equals(MatchComponent memory left, MatchComponent memory right) + internal + pure + returns (bool) + { + return left.amount == right.amount + && left.orderIndex == right.orderIndex + && left.itemIndex == right.itemIndex; } } From d8e70cc2c952a3fa1d72b1ebc0cc89e39496ba93 Mon Sep 17 00:00:00 2001 From: 0age <0age@protonmail.com> Date: Wed, 6 Mar 2024 18:01:13 -0500 Subject: [PATCH 4/4] update with 1.6 code changes --- src/ZoneInterface.sol | 2 + src/executions/ExecutionHelper.sol | 131 ++-- src/fulfillments/lib/FulfillmentLib.sol | 10 +- src/helm.sol | 857 +----------------------- src/lib/ZoneParametersLib.sol | 95 ++- 5 files changed, 140 insertions(+), 955 deletions(-) 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; }