Skip to content

Commit

Permalink
Merge pull request #18 from ProjectOpenSea/ryan/add-burn
Browse files Browse the repository at this point in the history
add burn fns to shipyard redeemable
  • Loading branch information
ryanio authored Nov 20, 2023
2 parents 0aaf396 + e13d712 commit 52dcff9
Show file tree
Hide file tree
Showing 5 changed files with 106 additions and 1 deletion.
8 changes: 8 additions & 0 deletions src/ERC1155ShipyardRedeemable.sol
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,14 @@ contract ERC1155ShipyardRedeemable is ERC1155ShipyardContractMetadata, ERC7498NF
DynamicTraits.setTrait(tokenId, traitKey, value);
}

function burn(address from, uint256 id, uint256 amount) public {
_burn(msg.sender, from, id, amount);
}

function batchBurn(address from, uint256[] calldata ids, uint256[] calldata amounts) public {
_batchBurn(msg.sender, from, ids, amounts);
}

function _useInternalBurn() internal pure virtual override returns (bool) {
return true;
}
Expand Down
4 changes: 4 additions & 0 deletions src/ERC721ShipyardRedeemable.sol
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,10 @@ contract ERC721ShipyardRedeemable is ERC721ShipyardContractMetadata, ERC7498NFTR
traitValues = DynamicTraits.getTraitValues(tokenId, traitKeys);
}

function burn(uint256 tokenId) public {
_burn(msg.sender, tokenId);
}

function _useInternalBurn() internal pure virtual override returns (bool) {
return true;
}
Expand Down
47 changes: 47 additions & 0 deletions test/ERC1155ShipyardRedeemable.t.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.19;

import {Solarray} from "solarray/Solarray.sol";
import {BaseRedeemablesTest} from "./utils/BaseRedeemablesTest.sol";
import {ERC1155} from "solady/src/tokens/ERC1155.sol";
import {ERC1155ShipyardRedeemableOwnerMintable} from "../src/test/ERC1155ShipyardRedeemableOwnerMintable.sol";

contract TestERC1155ShipyardRedeemable is BaseRedeemablesTest {
event TransferBatch(
address indexed operator, address indexed from, address indexed to, uint256[] ids, uint256[] amounts
);

function testBurn() public {
uint256 tokenId = 1;
ERC1155ShipyardRedeemableOwnerMintable token = new ERC1155ShipyardRedeemableOwnerMintable("Test", "TEST");
address fred = makeAddr("fred");
_mintToken(address(token), tokenId, fred);

vm.expectRevert(ERC1155.InsufficientBalance.selector);
token.burn(address(this), tokenId, 1);

vm.expectEmit(true, true, true, true);
emit TransferSingle(fred, fred, address(0), tokenId, 1);
vm.prank(fred);
token.burn(fred, tokenId, 1);

vm.prank(fred);
vm.expectRevert(ERC1155.InsufficientBalance.selector);
token.burn(fred, tokenId + 1, 1);

_mintToken(address(token), tokenId + 1, fred);
_mintToken(address(token), tokenId + 2, fred);

uint256[] memory ids = Solarray.uint256s(tokenId + 1, tokenId + 2);
uint256[] memory amounts = Solarray.uint256s(1, 1);
vm.expectRevert(ERC1155.NotOwnerNorApproved.selector);
token.batchBurn(fred, ids, amounts);

vm.prank(fred);
token.setApprovalForAll(address(this), true);

vm.expectEmit(true, true, true, true);
emit TransferBatch(address(this), fred, address(0), ids, amounts);
token.batchBurn(fred, ids, amounts);
}
}
46 changes: 46 additions & 0 deletions test/ERC721ShipyardRedeemable.t.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.19;

import {Test} from "forge-std/Test.sol";
import {ERC721} from "solady/src/tokens/ERC721.sol";
import {ERC721ShipyardRedeemableOwnerMintable} from "../src/test/ERC721ShipyardRedeemableOwnerMintable.sol";

contract TestERC721ShipyardRedeemable is Test {
// This Transfer event is different than the one in BaseOrderTest, since `id` is indexed.
// We don't inherit BaseRedeemablesTest to avoid this conflict.
// For more details see https://github.com/ethereum/solidity/issues/4168#issuecomment-1819912098
event Transfer(address indexed from, address indexed to, uint256 indexed id);

function testBurn() public {
uint256 tokenId = 1;
ERC721ShipyardRedeemableOwnerMintable token = new ERC721ShipyardRedeemableOwnerMintable("Test", "TEST");
address fred = makeAddr("fred");
_mintToken(address(token), tokenId, fred);

vm.expectRevert(ERC721.NotOwnerNorApproved.selector);
token.burn(tokenId);

vm.expectEmit(true, true, false, false);
emit Transfer(fred, address(0), tokenId);
vm.prank(fred);
token.burn(tokenId);

vm.expectRevert(ERC721.TokenDoesNotExist.selector);
token.burn(tokenId + 1);

_mintToken(address(token), tokenId + 1, fred);
vm.expectRevert(ERC721.NotOwnerNorApproved.selector);
token.burn(tokenId + 1);

vm.prank(fred);
token.setApprovalForAll(address(this), true);

vm.expectEmit(true, true, false, false);
emit Transfer(fred, address(0), tokenId + 1);
token.burn(tokenId + 1);
}

function _mintToken(address token, uint256 tokenId, address recipient) internal {
ERC721ShipyardRedeemableOwnerMintable(address(token)).mint(recipient, tokenId);
}
}
2 changes: 1 addition & 1 deletion test/ERC7498-MultiRedeem.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ contract ERC7498_MultiRedeem is BaseRedeemablesTest {
context.erc7498Token.redeem(tokenIds, address(this), extraData);

_checkTokenDoesNotExist(address(context.erc7498Token), tokenId);
_checkTokenSentToBurnAddress(secondRedeemTokenAddress, tokenId);
_checkTokenDoesNotExist(secondRedeemTokenAddress, tokenId);
assertEq(receiveToken.ownerOf(1), address(this));
assertEq(receiveToken.balanceOf(address(this)), 1);
}
Expand Down

0 comments on commit 52dcff9

Please sign in to comment.