Skip to content

Commit

Permalink
add metadata, 1155 contracts
Browse files Browse the repository at this point in the history
  • Loading branch information
ryanio committed Oct 17, 2023
1 parent afbd78c commit 328a9bd
Show file tree
Hide file tree
Showing 15 changed files with 460 additions and 59 deletions.
9 changes: 5 additions & 4 deletions script/DeployAndRedeemTokens-CampaignOnReceiveToken.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ contract DeployAndRedeemTokens_CampaignOnReceiveToken is Script, Test {
vm.startBroadcast();

ERC721OwnerMintable redeemToken = new ERC721OwnerMintable();
ERC721ShipyardRedeemableMintable receiveToken = new ERC721ShipyardRedeemableMintable();
ERC721ShipyardRedeemableMintable receiveToken =
new ERC721ShipyardRedeemableMintable("TestRedeemablesReceiveToken", "TEST");

// Configure the campaign.
OfferItem[] memory offer = new OfferItem[](1);
Expand Down Expand Up @@ -53,7 +54,7 @@ contract DeployAndRedeemTokens_CampaignOnReceiveToken is Script, Test {
maxCampaignRedemptions: 1_000,
manager: msg.sender
});
receiveToken.createCampaign(params, "");
receiveToken.createCampaign(params, "ipfs://QmQKc93y2Ev5k9Kz54mCw48ZM487bwGDktZYPLtrjJ3r1d");

// Mint token 1 to redeem for token 1.
redeemToken.mint(msg.sender, 1);
Expand All @@ -68,8 +69,8 @@ contract DeployAndRedeemTokens_CampaignOnReceiveToken is Script, Test {
tokenIds[0] = 1;

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

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

Expand Down
4 changes: 3 additions & 1 deletion script/DeployAndRedeemTokens.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,10 @@ contract DeployAndRedeemTokens is Script, Test {
function run() external {
vm.startBroadcast();

ERC721ShipyardRedeemableOwnerMintable redeemToken = new ERC721ShipyardRedeemableOwnerMintable();
ERC721ShipyardRedeemableOwnerMintable redeemToken =
new ERC721ShipyardRedeemableOwnerMintable("TestRedeemablesRedeemToken", "TEST");
ERC721RedemptionMintable receiveToken = new ERC721RedemptionMintable(
"TestRedeemablesRecieveToken", "TEST",
address(redeemToken)
);

Expand Down
39 changes: 39 additions & 0 deletions src/ERC1155ShipyardRedeemable.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.19;

import {ERC1155ShipyardContractMetadata} from "./lib/ERC1155ShipyardContractMetadata.sol";
import {Ownable} from "solady/src/auth/Ownable.sol";
import {ERC7498NFTRedeemables} from "./lib/ERC7498NFTRedeemables.sol";
import {CampaignParams} from "./lib/RedeemablesStructs.sol";

contract ERC1155ShipyardRedeemable is ERC1155ShipyardContractMetadata, ERC7498NFTRedeemables {
constructor(string memory name_, string memory symbol_) ERC1155ShipyardContractMetadata(name_, symbol_) {}

function createCampaign(CampaignParams calldata params, string calldata uri_)
public
override
onlyOwner
returns (uint256 campaignId)
{
campaignId = ERC7498NFTRedeemables.createCampaign(params, uri_);
}

function _useInternalBurn() internal pure virtual override returns (bool) {
return true;
}

function _internalBurn(address from, uint256 id, uint256 amount) internal virtual override {
_burn(from, id, amount);
}

function supportsInterface(bytes4 interfaceId)
public
view
virtual
override(ERC1155ShipyardContractMetadata, ERC7498NFTRedeemables)
returns (bool)
{
return ERC1155ShipyardContractMetadata.supportsInterface(interfaceId)
|| ERC7498NFTRedeemables.supportsInterface(interfaceId);
}
}
2 changes: 1 addition & 1 deletion src/ERC721SeaDropRedeemable.sol
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ contract ERC721SeaDropRedeemable is ERC721SeaDrop, ERC7498NFTRedeemables, Dynami
return true;
}

function _internalBurn(uint256 id, uint256 /* amount */ ) internal virtual override {
function _internalBurn(address, /* from */ uint256 id, uint256 /* amount */ ) internal virtual override {
_burn(id);
}

Expand Down
29 changes: 7 additions & 22 deletions src/ERC721ShipyardRedeemable.sol
Original file line number Diff line number Diff line change
@@ -1,28 +1,12 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.19;

import {ERC721ConduitPreapproved_Solady} from "shipyard-core/src/tokens/erc721/ERC721ConduitPreapproved_Solady.sol";
import {ERC721} from "solady/src/tokens/ERC721.sol";
import {Ownable} from "solady/src/auth/Ownable.sol";
import {ERC721ShipyardContractMetadata} from "./lib/ERC721ShipyardContractMetadata.sol";
import {ERC7498NFTRedeemables} from "./lib/ERC7498NFTRedeemables.sol";
import {CampaignParams} from "./lib/RedeemablesStructs.sol";

contract ERC721ShipyardRedeemable is ERC721ConduitPreapproved_Solady, ERC7498NFTRedeemables, Ownable {
constructor() ERC721ConduitPreapproved_Solady() {
_initializeOwner(msg.sender);
}

function name() public pure override returns (string memory) {
return "ERC721ShipyardRedeemable";
}

function symbol() public pure override returns (string memory) {
return "SY-RDM";
}

function tokenURI(uint256 /* tokenId */ ) public pure override returns (string memory) {
return "https://example.com/";
}
contract ERC721ShipyardRedeemable is ERC721ShipyardContractMetadata, ERC7498NFTRedeemables {
constructor(string memory name_, string memory symbol_) ERC721ShipyardContractMetadata(name_, symbol_) {}

function createCampaign(CampaignParams calldata params, string calldata uri)
public
Expand All @@ -37,17 +21,18 @@ contract ERC721ShipyardRedeemable is ERC721ConduitPreapproved_Solady, ERC7498NFT
return true;
}

function _internalBurn(uint256 id, uint256 /* amount */ ) internal virtual override {
function _internalBurn(address, /* from */ uint256 id, uint256 /* amount */ ) internal virtual override {
_burn(id);
}

function supportsInterface(bytes4 interfaceId)
public
view
virtual
override(ERC721, ERC7498NFTRedeemables)
override(ERC721ShipyardContractMetadata, ERC7498NFTRedeemables)
returns (bool)
{
return ERC721.supportsInterface(interfaceId) || ERC7498NFTRedeemables.supportsInterface(interfaceId);
return ERC721ShipyardContractMetadata.supportsInterface(interfaceId)
|| ERC7498NFTRedeemables.supportsInterface(interfaceId);
}
}
21 changes: 16 additions & 5 deletions src/extensions/ERC1155RedemptionMintable.sol
Original file line number Diff line number Diff line change
@@ -1,18 +1,22 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.19;

import {ERC1155} from "solady/src/tokens/ERC1155.sol";
import {ConsiderationItem} from "seaport-types/src/lib/ConsiderationStructs.sol";
import {ERC1155ShipyardContractMetadata} from "../lib/ERC1155ShipyardContractMetadata.sol";
import {IRedemptionMintable} from "../interfaces/IRedemptionMintable.sol";
import {TraitRedemption} from "../lib/RedeemablesStructs.sol";

contract ERC1155RedemptionMintable is ERC1155, IRedemptionMintable {
contract ERC1155RedemptionMintable is ERC1155ShipyardContractMetadata, IRedemptionMintable {
/// @dev The ERC-7498 redeemables contract.
address internal immutable _ERC7498_REDEEMABLES_CONTRACT;

/// @dev Revert if the sender of mintRedemption is not the redeemable contract offerer.
error InvalidSender();

constructor(address redeemableContractOfferer) {
constructor(string memory name_, string memory symbol_, address redeemableContractOfferer)
ERC1155ShipyardContractMetadata(name_, symbol_)
{
// Set the redeemables contract address.
_ERC7498_REDEEMABLES_CONTRACT = redeemableContractOfferer;
}

Expand All @@ -36,7 +40,14 @@ contract ERC1155RedemptionMintable is ERC1155, IRedemptionMintable {
}
}

function uri(uint256 id) public pure override returns (string memory) {
return string(abi.encodePacked("https://example.com/", id));
function supportsInterface(bytes4 interfaceId)
public
view
virtual
override(ERC1155ShipyardContractMetadata)
returns (bool)
{
return ERC1155ShipyardContractMetadata.supportsInterface(interfaceId)
|| interfaceId == type(IRedemptionMintable).interfaceId;
}
}
38 changes: 38 additions & 0 deletions src/extensions/ERC1155ShipyardRedeemableMintable.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.19;

import {ERC721ConduitPreapproved_Solady} from "shipyard-core/src/tokens/erc721/ERC721ConduitPreapproved_Solady.sol";
import {ConsiderationItem} from "seaport-types/src/lib/ConsiderationStructs.sol";
import {Ownable} from "solady/src/auth/Ownable.sol";
import {ERC7498NFTRedeemables} from "../lib/ERC7498NFTRedeemables.sol";
import {CampaignParams} from "../lib/RedeemablesStructs.sol";
import {IRedemptionMintable} from "../interfaces/IRedemptionMintable.sol";
import {ERC1155ShipyardRedeemable} from "../ERC1155ShipyardRedeemable.sol";
import {IRedemptionMintable} from "../interfaces/IRedemptionMintable.sol";
import {TraitRedemption} from "../lib/RedeemablesStructs.sol";

contract ERC1155ShipyardRedeemableMintable is ERC1155ShipyardRedeemable, IRedemptionMintable {
/// @dev Revert if the sender of mintRedemption is not this contract.
error InvalidSender();

/// @dev The next token id to mint. Each token will have a supply of 1.
uint256 _nextTokenId = 1;

function mintRedemption(
uint256, /* campaignId */
address recipient,
ConsiderationItem[] calldata, /* consideration */
TraitRedemption[] calldata /* traitRedemptions */
) external {
if (msg.sender != address(this)) {
revert InvalidSender();
}

// Increment nextTokenId first so more of the same token id cannot be minted through reentrancy.
++_nextTokenId;

_mint(recipient, _nextTokenId - 1, 1, "");
}

constructor(string memory name_, string memory symbol_) ERC1155ShipyardRedeemable(name_, symbol_) {}
}
34 changes: 21 additions & 13 deletions src/extensions/ERC721RedemptionMintable.sol
Original file line number Diff line number Diff line change
@@ -1,19 +1,25 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.19;

import {ERC721} from "solady/src/tokens/ERC721.sol";
import {ConsiderationItem} from "seaport-types/src/lib/ConsiderationStructs.sol";
import {ERC721ShipyardContractMetadata} from "../lib/ERC721ShipyardContractMetadata.sol";
import {IRedemptionMintable} from "../interfaces/IRedemptionMintable.sol";
import {TraitRedemption} from "../lib/RedeemablesStructs.sol";

contract ERC721RedemptionMintable is ERC721, IRedemptionMintable {
contract ERC721RedemptionMintable is ERC721ShipyardContractMetadata, IRedemptionMintable {
/// @dev The ERC-7498 redeemables contract.
address internal immutable _ERC7498_REDEEMABLES_CONTRACT;

/// @dev The next token id to mint.
uint256 internal _nextTokenId = 1;

/// @dev Revert if the sender of mintRedemption is not the redeemable contract offerer.
error InvalidSender();

constructor(address redeemablesContractAddress) {
constructor(string memory name_, string memory symbol_, address redeemablesContractAddress)
ERC721ShipyardContractMetadata(name_, symbol_)
{
// Set the redeemables contract address.
_ERC7498_REDEEMABLES_CONTRACT = redeemablesContractAddress;
}

Expand All @@ -26,19 +32,21 @@ contract ERC721RedemptionMintable is ERC721, IRedemptionMintable {
if (msg.sender != _ERC7498_REDEEMABLES_CONTRACT) {
revert InvalidSender();
}
_mint(recipient, _nextTokenId);
++_nextTokenId;
}

function name() public pure override returns (string memory) {
return "ERC721RedemptionMintable";
}
// Increment nextTokenId first so more of the same token id cannot be minted through reentrancy.
++_nextTokenId;

function symbol() public pure override returns (string memory) {
return "721RM";
_mint(recipient, _nextTokenId - 1);
}

function tokenURI(uint256 tokenId) public pure override returns (string memory) {
return string(abi.encodePacked("https://example.com/", tokenId));
function supportsInterface(bytes4 interfaceId)
public
view
virtual
override(ERC721ShipyardContractMetadata)
returns (bool)
{
return ERC721ShipyardContractMetadata.supportsInterface(interfaceId)
|| interfaceId == type(IRedemptionMintable).interfaceId;
}
}
6 changes: 1 addition & 5 deletions src/extensions/ERC721ShipyardRedeemableMintable.sol
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,5 @@ contract ERC721ShipyardRedeemableMintable is ERC721ShipyardRedeemable, IRedempti
_mint(recipient, 1);
}

constructor() ERC721ShipyardRedeemable() {}

function _useInternalBurn() internal pure override returns (bool) {
return false;
}
constructor(string memory name_, string memory symbol_) ERC721ShipyardRedeemable(name_, symbol_) {}
}
Loading

0 comments on commit 328a9bd

Please sign in to comment.