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

[Feature] Batch Offers #4

Open
wants to merge 28 commits into
base: main
Choose a base branch
from
Open

[Feature] Batch Offers #4

wants to merge 28 commits into from

Conversation

rymcol
Copy link

@rymcol rymcol commented Aug 23, 2024

Adds the first iteration for batch offer via Merkle

@rymcol rymcol self-assigned this Aug 23, 2024
make sure memory is cleaned up before transfers + uses currency from memory in offers rather than an input variable
creates a new storage mapping of creator -> root hash -> offer to prevent DoS style attacks from using the same merkle root to block offers
Copy link

@koloz193 koloz193 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall looks solid. There's also this old PR which has some extra functionality https://github.com/superrare/private-core/pull/1

Comment on lines +34 to +41
address _networkBeneficiary,
address _marketplaceSettings,
address _spaceOperatorRegistry,
address _royaltyEngine,
address _payments,
address _approvedTokenRegistry,
address _stakingSettings,
address _stakingRegistry

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

might want to check these for empty addresses

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

added in 3686be2

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

some of the requires need to be cleaned up (extra quotations/messages/etc)

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I noticed too, and fixed. The linter went haywire or copilot added syntax when I didn't ask it to....

marketConfig.checkIfCurrencyIsApproved(_currency);
require(_expiry > block.timestamp, "createBatchOffer::expiry must be in the future");
require(_amount > 0, "offer::Amount cannot be 0");

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe add a check for rootHash

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

added in d857556

) external payable nonReentrant {
require(_creatorToRootToOffer[msg.sender][_rootHash].creator == address(0), "createBatchOffer::offer exists");
marketConfig.checkIfCurrencyIsApproved(_currency);
require(_expiry > block.timestamp, "createBatchOffer::expiry must be in the future");

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i would convert requires to custom errors to save gas

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we talked internally and won't do this conversion at this time

require(_creatorToRootToOffer[msg.sender][_rootHash].creator == msg.sender, "createBatchOffer::must be owner");

// Load Offer
BatchOffer memory offer = _creatorToRootToOffer[msg.sender][_rootHash];

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you can put this above the require to avoid the extra MLOAD

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good call: 11485ec0ce19be8a3031173648bd2a22a25e56f1

marketConfig.checkIfCurrencyIsApproved(currency);
require(offer.creator != address(0), "acceptBatchOffer::offer does not exist");
require(offer.expiry > block.timestamp, "acceptBatchOffer::offer expired");
require(offer.rootHash == _rootHash, "acceptBatchOffer::root mismatch");

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

seems like this is redundant since you have it as the mapping

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

agreed: d20b368


// Transfer ERC721 token from the seller to the buyer
IERC721 erc721Token = IERC721(_contractAddress);
erc721Token.safeTransferFrom(msg.sender, offer.creator, _tokenId);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

might want to check if token is now owned by sender

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

6108a09 do want to

@rymcol rymcol changed the title Feature/sb 1481 [Feature] Batch Offers Sep 19, 2024
@rymcol
Copy link
Author

rymcol commented Sep 19, 2024

@koloz193 super nice to see you still active here, miss ya

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants