Skip to content

Commit

Permalink
Merge pull request #10 from ProjectOpenSea/forge-tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ryanio authored Oct 13, 2023
2 parents b7b22fd + 73aeed8 commit eae2e3d
Show file tree
Hide file tree
Showing 3 changed files with 407 additions and 165 deletions.
46 changes: 22 additions & 24 deletions src/lib/ERC7498NFTRedeemables.sol
Original file line number Diff line number Diff line change
Expand Up @@ -182,34 +182,32 @@ contract ERC7498NFTRedeemables is IERC7498, RedeemablesErrors {
}

function _transferConsiderationItem(uint256 id, ConsiderationItem memory c) internal {
// WITH_CRITERIA with identifier 0 is wildcard: any id is valid.
// Criteria is not yet implemented, for that functionality use the contract offerer.
if (
id != c.identifierOrCriteria && c.identifierOrCriteria != 0
&& (c.itemType != ItemType.ERC721_WITH_CRITERIA || c.itemType != ItemType.ERC1155_WITH_CRITERIA)
) {
revert InvalidConsiderationTokenIdSupplied(c.token, id, c.identifierOrCriteria);
}

// If consideration item is this contract, recipient is burn address, and _useInternalBurn() fn returns true,
// call the internal burn function and return.
if (c.token == address(this) && c.recipient == payable(_BURN_ADDRESS) && _useInternalBurn()) {
_internalBurn(id, c.startAmount);
return;
}

// Transfer the token to the consideration recipient.
if (c.itemType == ItemType.ERC721 || c.itemType == ItemType.ERC721_WITH_CRITERIA) {
// ERC721_WITH_CRITERIA with identifier 0 is wildcard: any id is valid.
// Criteria is not yet implemented, for that functionality use the contract offerer.
if (c.itemType == ItemType.ERC721 && id != c.identifierOrCriteria) {
revert InvalidConsiderationTokenIdSupplied(c.token, id, c.identifierOrCriteria);
}
IERC721(c.token).safeTransferFrom(msg.sender, c.recipient, id);
} else if ((c.itemType == ItemType.ERC1155 || c.itemType == ItemType.ERC1155_WITH_CRITERIA)) {
// ERC1155_WITH_CRITERIA with identifier 0 is wildcard: any id is valid.
// Criteria is not yet implemented, for that functionality use the contract offerer.
if (c.itemType == ItemType.ERC1155 && id != c.identifierOrCriteria) {
revert InvalidConsiderationTokenIdSupplied(c.token, id, c.identifierOrCriteria);
}
IERC1155(c.token).safeTransferFrom(msg.sender, c.recipient, id, c.startAmount, "");
} else if (c.itemType == ItemType.ERC20) {
IERC20(c.token).transferFrom(msg.sender, c.recipient, c.startAmount);
} else {
// ItemType.NATIVE
(bool success,) = c.recipient.call{value: msg.value}("");
if (!success) revert EtherTransferFailed();
// Transfer the token to the consideration recipient.
if (c.itemType == ItemType.ERC721 || c.itemType == ItemType.ERC721_WITH_CRITERIA) {
IERC721(c.token).safeTransferFrom(msg.sender, c.recipient, id);
} else if ((c.itemType == ItemType.ERC1155 || c.itemType == ItemType.ERC1155_WITH_CRITERIA)) {
IERC1155(c.token).safeTransferFrom(msg.sender, c.recipient, id, c.startAmount, "");
} else if (c.itemType == ItemType.ERC20) {
IERC20(c.token).transferFrom(msg.sender, c.recipient, c.startAmount);
} else {
// ItemType.NATIVE
(bool success,) = c.recipient.call{value: msg.value}("");
if (!success) revert EtherTransferFailed();
}
}
}

Expand Down Expand Up @@ -272,7 +270,7 @@ contract ERC7498NFTRedeemables is IERC7498, RedeemablesErrors {
}

// Ensure the balance is sufficient.
if (balance < c.startAmount) {
if (c.itemType != ItemType.NATIVE && balance < c.startAmount) {
revert ConsiderationItemInsufficientBalance(c.token, balance, c.startAmount);
}

Expand Down
Loading

0 comments on commit eae2e3d

Please sign in to comment.