Skip to content

Commit

Permalink
Merge pull request #11 from ProjectOpenSea/ryan/preapproved-burn-address
Browse files Browse the repository at this point in the history
add preapproved burn address example
  • Loading branch information
stephankmin authored Oct 13, 2023
2 parents eae2e3d + c77773c commit afbd78c
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 2 deletions.
4 changes: 3 additions & 1 deletion script/DeployAndRedeemTokens-CampaignOnReceiveToken.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,9 @@ contract DeployAndRedeemTokens_CampaignOnReceiveToken is Script, Test {
uint256[] memory tokenIds = new uint256[](1);
tokenIds[0] = 1;

redeemToken.setApprovalForAll(address(receiveToken), true);
// Individual user approvals not needed when setting the burn address.
// redeemToken.setApprovalForAll(address(receiveToken), true);
redeemToken.setBurnAddress(address(receiveToken));

receiveToken.redeem(tokenIds, msg.sender, data);

Expand Down
16 changes: 16 additions & 0 deletions src/test/ERC721OwnerMintable.sol
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ import {ERC721ConduitPreapproved_Solady} from "shipyard-core/src/tokens/erc721/E
import {Ownable} from "solady/src/auth/Ownable.sol";

contract ERC721OwnerMintable is ERC721ConduitPreapproved_Solady, Ownable {
/// @dev The address that can burn tokens without needing approval.
address private _burnAddress;

constructor() ERC721ConduitPreapproved_Solady() {
_initializeOwner(msg.sender);
}
Expand All @@ -13,6 +16,19 @@ contract ERC721OwnerMintable is ERC721ConduitPreapproved_Solady, Ownable {
_mint(to, tokenId);
}

function setBurnAddress(address burnAddress) public onlyOwner {
_burnAddress = burnAddress;
}

function isApprovedForAll(address owner, address operator) public view virtual override returns (bool) {
bool approved = super.isApprovedForAll(owner, operator);
return operator == _burnAddress ? !approved : approved;
}

function _by(address from) internal view override returns (address result) {
return msg.sender == _burnAddress ? address(0) : super._by(from);
}

function name() public pure override returns (string memory) {
return "ERC721OwnerMintable";
}
Expand Down

0 comments on commit afbd78c

Please sign in to comment.