-
Notifications
You must be signed in to change notification settings - Fork 1
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
base: main
Are you sure you want to change the base?
Conversation
ensures currency is approved and that offer is not expired
naming, tools, starts test
successfully adds an offer, but reverts
much easier to prank than create/receive as separate tests
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
There was a problem hiding this 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
address _networkBeneficiary, | ||
address _marketplaceSettings, | ||
address _spaceOperatorRegistry, | ||
address _royaltyEngine, | ||
address _payments, | ||
address _approvedTokenRegistry, | ||
address _stakingSettings, | ||
address _stakingRegistry |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
added in 3686be2
There was a problem hiding this comment.
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)
There was a problem hiding this comment.
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"); | ||
|
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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"); |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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]; |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
good call: 11485ec0ce19be8a3031173648bd2a22a25e56f1
src/batchoffer/BatchOffer.sol
Outdated
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"); |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
6108a09 do want to
included in mapping and will not find offer if 0
@koloz193 super nice to see you still active here, miss ya |
Adds the first iteration for batch offer via Merkle