Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Include OrderType in ZoneParameters #14

Open
wants to merge 27 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
ba92459
removed old version of seaport-types
Alec1017 Nov 9, 2023
b107a0f
forge install: seaport-types
Alec1017 Nov 9, 2023
800eadf
added .gitignore
Alec1017 Nov 9, 2023
ee3284e
replaced _assertRestrictedBasicOrderValidity with the reference imple…
Alec1017 Nov 9, 2023
6db188a
adding reference contracts
Alec1017 Nov 9, 2023
8777e56
removed basicOrderFulfiller and got the contracts compiling
Alec1017 Nov 9, 2023
8d8d0d9
changed function name to not clash with another contract
Alec1017 Nov 9, 2023
6864b65
keeping applyFraction() because other repos depend on it
Alec1017 Nov 9, 2023
e839dee
swapped in all reference files
Alec1017 Nov 9, 2023
c895ee8
added reference implementation with regular implementation
Alec1017 Nov 9, 2023
995f54f
renamed the reference consideration
Alec1017 Nov 9, 2023
eb1bb10
adjusted seaport core so that all executions are returned via the zone
Alec1017 Nov 10, 2023
9fea6ad
added basic test
Alec1017 Dec 11, 2023
051fa7e
forge install: forge-std
Alec1017 Dec 11, 2023
8688dab
working on adding tests
Alec1017 Dec 11, 2023
49bc99e
got zone interaction working properly
Alec1017 Dec 13, 2023
4accf68
added total executions for the order fulfiller contract
Alec1017 Dec 13, 2023
ef3a991
completed order combiner changes
Alec1017 Dec 14, 2023
ded97a1
cleaned up tests a bit
Alec1017 Dec 14, 2023
f02cf82
did some clean up and removed old reference contracts
Alec1017 Dec 14, 2023
eea0ce4
fixed some spacing
Alec1017 Dec 14, 2023
032a249
Merge pull request #1 from re-nft/rental
Alec1017 Dec 14, 2023
260da2d
fixed bug where added memory region was corrupting the accumulator
Alec1017 Dec 14, 2023
c100498
added stub contract for foundry scripts
Alec1017 Dec 14, 2023
3bccb8e
changed imports to use relative paths
Alec1017 Dec 14, 2023
8c605f9
added order type to zone parameters
Alec1017 Feb 9, 2024
14c0bfa
updated function selector for validateOrder
Alec1017 Feb 9, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# Compiler files
cache/
out/

# Dotenv file
.env

broadcast/

node_modules/

.vscode/
5 changes: 4 additions & 1 deletion .gitmodules
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
[submodule "lib/seaport-types"]
path = lib/seaport-types
url = https://github.com/projectopensea/seaport-types
url = https://github.com/projectOpensea/seaport-types
[submodule "lib/forge-std"]
path = lib/forge-std
url = https://github.com/foundry-rs/forge-std
12 changes: 10 additions & 2 deletions foundry.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,15 @@
[profile.default]
solc = "0.8.22"
src = "src"
out = "out"
libs = ["lib"]
remappings = ['seaport-types/=lib/seaport-types/']
remappings = [
"seaport-types/=lib/seaport-types/",
"ds-test/=lib/forge-std/lib/ds-test/src/",
"forge-std/=lib/forge-std/src/"
]

# See more config options https://github.com/foundry-rs/foundry/tree/master/config
# solidity 0.8.22 defaults to the shanghai fork which introduces the PUSH0 opcode.
# Most chains outside of mainnet have not implemented this opcode yet, so we explicitly
# make sure solidity compiles using the paris fork to maintain cross-chain compatibility
evm_version = "paris"
1 change: 1 addition & 0 deletions lib/forge-std
Submodule forge-std added at 2f1126
2 changes: 1 addition & 1 deletion lib/seaport-types
202 changes: 157 additions & 45 deletions src/lib/ConsiderationEncoder.sol
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,26 @@ import {
ZoneParameters_zoneHash_offset
} from "seaport-types/src/lib/ConsiderationConstants.sol";

import {BasicOrderParameters, OrderParameters} from "seaport-types/src/lib/ConsiderationStructs.sol";
import {
Rental_validateOrder_selector,
Rental_OrderParameters_orderType_offset,
Rental_ZoneParameters_orderHash_offset,
Rental_ZoneParameters_fulfiller_offset,
Rental_ZoneParameters_offerer_offset,
Rental_ZoneParameters_offer_head_offset,
Rental_ZoneParameters_consideration_head_offset,
Rental_ZoneParameters_totalExecutions_head_offset,
Rental_ZoneParameters_extraData_head_offset,
Rental_ZoneParameters_orderHashes_head_offset,
Rental_ZoneParameters_startTime_offset,
Rental_ZoneParameters_endTime_offset,
Rental_ZoneParameters_zoneHash_offset,
Rental_ZoneParameters_orderType_offset,
Rental_ZoneParameters_base_tail_offset
} from "./rental/ConsiderationConstants.sol";
import {StructPointers} from "./rental/ConsiderationStructs.sol";

import {BasicOrderParameters, OrderParameters, ReceivedItem} from "seaport-types/src/lib/ConsiderationStructs.sol";

import {CalldataPointer, getFreeMemoryPointer, MemoryPointer} from "seaport-types/src/helpers/PointerLibraries.sol";

Expand Down Expand Up @@ -312,6 +331,7 @@ contract ConsiderationEncoder {
* updated/written to in this function.
*
* @param orderHash The order hash.
* @param totalExecutions The total transfers that occur during this order fulfillment
* @param orderParameters The OrderParameters struct used to construct the
* encoded `validateOrder` calldata.
* @param extraData The extraData bytes array used to construct the
Expand All @@ -326,6 +346,7 @@ contract ConsiderationEncoder {
*/
function _encodeValidateOrder(
bytes32 orderHash,
ReceivedItem[] memory totalExecutions,
OrderParameters memory orderParameters,
bytes memory extraData,
bytes32[] memory orderHashes
Expand All @@ -335,7 +356,7 @@ contract ConsiderationEncoder {
dst = getFreeMemoryPointer();

// Write validateOrder selector and get pointer to start of calldata.
dst.write(validateOrder_selector);
dst.write(Rental_validateOrder_selector);
dst = dst.offset(validateOrder_selector_offset);

// Get pointer to the beginning of the encoded data.
Expand All @@ -349,74 +370,104 @@ contract ConsiderationEncoder {

// Write orderHash and fulfiller to zoneParameters.
dstHead.writeBytes32(orderHash);
dstHead.offset(ZoneParameters_fulfiller_offset).write(msg.sender);
dstHead.offset(Rental_ZoneParameters_fulfiller_offset).write(msg.sender);

// Get the memory pointer to the order parameters struct.
MemoryPointer src = orderParameters.toMemoryPointer();

// Copy offerer, startTime, endTime and zoneHash to zoneParameters.
dstHead.offset(ZoneParameters_offerer_offset).write(src.readUint256());
dstHead.offset(ZoneParameters_startTime_offset).write(
// Copy offerer, startTime, endTime, zoneHash, and orderType to zoneParameters.
dstHead.offset(Rental_ZoneParameters_offerer_offset).write(src.readUint256());
dstHead.offset(Rental_ZoneParameters_startTime_offset).write(
src.offset(OrderParameters_startTime_offset).readUint256()
);
dstHead.offset(ZoneParameters_endTime_offset).write(src.offset(OrderParameters_endTime_offset).readUint256());
dstHead.offset(ZoneParameters_zoneHash_offset).write(src.offset(OrderParameters_zoneHash_offset).readUint256());
dstHead.offset(Rental_ZoneParameters_endTime_offset).write(src.offset(OrderParameters_endTime_offset).readUint256());
dstHead.offset(Rental_ZoneParameters_zoneHash_offset).write(src.offset(OrderParameters_zoneHash_offset).readUint256());
dstHead.offset(Rental_ZoneParameters_orderType_offset).write(src.offset(Rental_OrderParameters_orderType_offset).readUint256());

// Initialize tail offset, used to populate the offer array.
uint256 tailOffset = ZoneParameters_base_tail_offset;
uint256 tailOffset = Rental_ZoneParameters_base_tail_offset;

// Write offset to `offer`.
dstHead.offset(ZoneParameters_offer_head_offset).write(tailOffset);
// Encode offer
{
// Write offset to `offer`.
dstHead.offset(Rental_ZoneParameters_offer_head_offset).write(tailOffset);

// Get pointer to `orderParameters.offer.length`.
MemoryPointer srcOfferPointer = src.offset(OrderParameters_offer_head_offset).readMemoryPointer();
// Get pointer to `orderParameters.offer.length`.
MemoryPointer srcOfferPointer = src.offset(OrderParameters_offer_head_offset).readMemoryPointer();

// Encode the offer array as a `SpentItem[]`.
uint256 offerSize = _encodeSpentItems(srcOfferPointer, dstHead.offset(tailOffset));
// Encode the offer array as a `SpentItem[]`.
uint256 offerSize = _encodeSpentItems(srcOfferPointer, dstHead.offset(tailOffset));

unchecked {
// Increment tail offset, now used to populate consideration array.
tailOffset += offerSize;
unchecked {
// Increment tail offset, now used to populate consideration array.
tailOffset += offerSize;
}
}

// Write offset to consideration.
dstHead.offset(ZoneParameters_consideration_head_offset).write(tailOffset);
// Encode consideration
{
// Write offset to consideration.
dstHead.offset(Rental_ZoneParameters_consideration_head_offset).write(tailOffset);

// Get pointer to `orderParameters.consideration.length`.
MemoryPointer srcConsiderationPointer =
src.offset(OrderParameters_consideration_head_offset).readMemoryPointer();
// Get pointer to `orderParameters.consideration.length`.
MemoryPointer srcConsiderationPointer =
src.offset(OrderParameters_consideration_head_offset).readMemoryPointer();

// Encode the consideration array as a `ReceivedItem[]`.
uint256 considerationSize =
_encodeConsiderationAsReceivedItems(srcConsiderationPointer, dstHead.offset(tailOffset));
// Encode the consideration array as a `ReceivedItem[]`.
uint256 considerationSize =
_encodeConsiderationAsReceivedItems(srcConsiderationPointer, dstHead.offset(tailOffset));

unchecked {
// Increment tail offset, now used to populate extraData array.
tailOffset += considerationSize;
unchecked {
// Increment tail offset, now used to populate totalExecutions array.
tailOffset += considerationSize;
}
}

// Write offset to extraData.
dstHead.offset(ZoneParameters_extraData_head_offset).write(tailOffset);
// Copy extraData.
uint256 extraDataSize = _encodeBytes(toMemoryPointer(extraData), dstHead.offset(tailOffset));
// Encode totalExecutions
{
// Write offset to totalExecutions.
dstHead.offset(Rental_ZoneParameters_totalExecutions_head_offset).write(tailOffset);

unchecked {
// Increment tail offset, now used to populate orderHashes array.
tailOffset += extraDataSize;
// Encode the total exuections array.
uint256 totalExecutionsSize = _encodeConsiderationAsReceivedItems(
StructPointers.toMemoryPointer(totalExecutions),
dstHead.offset(tailOffset)
);

unchecked {
// Increment tail offset, now used to populate extraData array.
tailOffset += totalExecutionsSize;
}
}

// Write offset to orderHashes.
dstHead.offset(ZoneParameters_orderHashes_head_offset).write(tailOffset);
// Encode extraData
{
// Write offset to extraData.
dstHead.offset(Rental_ZoneParameters_extraData_head_offset).write(tailOffset);
// Copy extraData.
uint256 extraDataSize = _encodeBytes(toMemoryPointer(extraData), dstHead.offset(tailOffset));

// Encode the order hashes array.
uint256 orderHashesSize = _encodeOrderHashes(toMemoryPointer(orderHashes), dstHead.offset(tailOffset));
unchecked {
// Increment tail offset, now used to populate orderHashes array.
tailOffset += extraDataSize;
}
}

unchecked {
// Increment the tail offset, now used to determine final size.
tailOffset += orderHashesSize;
// Encode orderHashes
{
// Write offset to orderHashes.
dstHead.offset(Rental_ZoneParameters_orderHashes_head_offset).write(tailOffset);

// Encode the order hashes array.
uint256 orderHashesSize = _encodeOrderHashes(toMemoryPointer(orderHashes), dstHead.offset(tailOffset));

// Derive final size including selector and ZoneParameters pointer.
size = ZoneParameters_selectorAndPointer_length + tailOffset;
unchecked {
// Increment the tail offset, now used to determine final size.
tailOffset += orderHashesSize;

// Derive final size including selector and ZoneParameters pointer.
size = ZoneParameters_selectorAndPointer_length + tailOffset;
}
}
}

Expand Down Expand Up @@ -652,4 +703,65 @@ contract ConsiderationEncoder {
size = OneWord + (length * ReceivedItem_size);
}
}

/**
* @dev Takes a memory pointer to order parameters and a memory
* pointer to a total executions array to copy it to, and copies
* the offer and consideration items as a ReceivedItem array.
*
* @param totalExecutions A memory pointer referencing the total executions
* that occur during this fulfillment.
* @param orderParameters A memory pointer referencing the location in memory to
* the order parameters, where the offer and consideration items
* will be copied from
*/
function _encodeTotalExecutions(ReceivedItem[] memory totalExecutions, OrderParameters memory orderParameters) internal view {
// Get the pointer to the length of the execution array
MemoryPointer executionLengthPtr = StructPointers.toMemoryPointer(totalExecutions);

// Keep track of a memory pointer to the head of the execution array
MemoryPointer executionHeadPtr = executionLengthPtr.next();

// Keep track of a memory pointer to the tail of the execution array
MemoryPointer offerHeadEndPtr = executionLengthPtr.next().offset(
orderParameters.offer.length << OneWordShift
);

MemoryPointer considerationHeadEndPtr = offerHeadEndPtr.offset(
orderParameters.consideration.length << OneWordShift
);

// Get the memory pointer to the order parameters struct.
MemoryPointer opPtr = orderParameters.toMemoryPointer();

// Get pointer to `orderParameters.offer.length` plus one word to get to the start of the data
MemoryPointer opOfferPointer = opPtr.offset(OrderParameters_offer_head_offset).readMemoryPointer().next();

// Get pointer to `orderParameters.consideration.length` plus one word to get to the start of the data
MemoryPointer opConsiderationPointer = opPtr.offset(OrderParameters_consideration_head_offset).readMemoryPointer().next();

while (executionHeadPtr.lt(offerHeadEndPtr)) {
// load the memory location where the execution head pointer is
MemoryPointer offerTail = executionHeadPtr.pptr();

// copy the offer item into the execution array
opOfferPointer.pptr().copy(offerTail, ReceivedItem_size);

// increment the head pointer and the offer pointer by one word
executionHeadPtr = executionHeadPtr.next();
opOfferPointer = opOfferPointer.next();
}

while (executionHeadPtr.lt(considerationHeadEndPtr)) {
// load the memory location where the execution head pointer is
MemoryPointer considerationTail = executionHeadPtr.pptr();

// copy the consideration item into the execution array
opConsiderationPointer.pptr().copy(considerationTail, ReceivedItem_size);

// increment the head pointer and the consideration pointer by one word
executionHeadPtr = executionHeadPtr.next();
opConsiderationPointer = opConsiderationPointer.next();
}
}
}
Loading