Skip to content

Commit

Permalink
progress, simplify extension contracts, more coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
ryanio committed Nov 15, 2023
1 parent 7f5a636 commit a98fb8c
Show file tree
Hide file tree
Showing 26 changed files with 270 additions and 234 deletions.
2 changes: 1 addition & 1 deletion script/DeployAndConfigure1155Receive.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {ItemType} from "seaport-types/src/lib/ConsiderationEnums.sol";
import {OfferItem, ConsiderationItem} from "seaport-types/src/lib/ConsiderationStructs.sol";
import {Campaign, CampaignParams, CampaignRequirements} from "../src/lib/RedeemablesStructs.sol";
import {BURN_ADDRESS} from "../src/lib/RedeemablesConstants.sol";
import {ERC721RedemptionMintable} from "../src/extensions/ERC721RedemptionMintable.sol";
import {ERC721ShipyardRedeemableMintable} from "../src/extensions/ERC721ShipyardRedeemableMintable.sol";
import {ERC721OwnerMintable} from "../src/test/ERC721OwnerMintable.sol";
import {ERC1155ShipyardRedeemableMintable} from "../src/extensions/ERC1155ShipyardRedeemableMintable.sol";

Expand Down
4 changes: 2 additions & 2 deletions script/DeployAndConfigureExampleCampaign.s.sol.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {OfferItem, ConsiderationItem} from "seaport-types/src/lib/ConsiderationS
import {RedeemableContractOfferer} from "../src/RedeemableContractOfferer.sol";
import {CampaignParams} from "../src/lib/RedeemablesStructs.sol";
import {BURN_ADDRESS} from "../src/lib/RedeemablesConstants.sol";
import {ERC721RedemptionMintable} from "../src/extensions/ERC721RedemptionMintable.sol";
import {ERC721ShipyardRedeemableMintable} from "../src/extensions/ERC721ShipyardRedeemableMintable.sol";
import {TestERC721} from "../test/utils/mocks/TestERC721.sol";

contract DeployAndConfigureExampleCampaign is Script {
Expand All @@ -26,7 +26,7 @@ contract DeployAndConfigureExampleCampaign is Script {
seaport
);
TestERC721 redeemableToken = new TestERC721();
ERC721RedemptionMintable redemptionToken = new ERC721RedemptionMintable(
ERC721ShipyardRedeemableMintable redemptionToken = new ERC721ShipyardRedeemableMintable(
address(offerer),
address(redeemableToken)
);
Expand Down
2 changes: 1 addition & 1 deletion script/DeployAndRedeemTokens-CampaignOnReceiveToken.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {ItemType} from "seaport-types/src/lib/ConsiderationEnums.sol";
import {OfferItem, ConsiderationItem} from "seaport-types/src/lib/ConsiderationStructs.sol";
import {Campaign, CampaignParams, CampaignRequirements} from "../src/lib/RedeemablesStructs.sol";
import {BURN_ADDRESS} from "../src/lib/RedeemablesConstants.sol";
import {ERC721RedemptionMintable} from "../src/extensions/ERC721RedemptionMintable.sol";
import {ERC721ShipyardRedeemableMintable} from "../src/extensions/ERC721ShipyardRedeemableMintable.sol";
import {ERC721OwnerMintable} from "../src/test/ERC721OwnerMintable.sol";
import {ERC721ShipyardRedeemableMintable} from "../src/extensions/ERC721ShipyardRedeemableMintable.sol";

Expand Down
8 changes: 4 additions & 4 deletions script/DeployAndRedeemTokens.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {ItemType} from "seaport-types/src/lib/ConsiderationEnums.sol";
import {OfferItem, ConsiderationItem} from "seaport-types/src/lib/ConsiderationStructs.sol";
import {Campaign, CampaignParams, CampaignRequirements} from "../src/lib/RedeemablesStructs.sol";
import {BURN_ADDRESS} from "../src/lib/RedeemablesConstants.sol";
import {ERC721RedemptionMintable} from "../src/extensions/ERC721RedemptionMintable.sol";
import {ERC721ShipyardRedeemableMintable} from "../src/extensions/ERC721ShipyardRedeemableMintable.sol";
import {ERC721ShipyardRedeemableOwnerMintable} from "../src/test/ERC721ShipyardRedeemableOwnerMintable.sol";

contract DeployAndRedeemTokens is Script, Test {
Expand All @@ -20,11 +20,11 @@ contract DeployAndRedeemTokens is Script, Test {
);
address[] memory redeemTokens = new address[](1);
redeemTokens[0] = address(redeemToken);
ERC721RedemptionMintable receiveToken = new ERC721RedemptionMintable(
ERC721ShipyardRedeemableMintable receiveToken = new ERC721ShipyardRedeemableMintable(
"TestRedeemablesRecieveToken",
"TEST",
redeemTokens
"TEST"
);
receiveToken.setRedeemablesContracts(redeemTokens);

// Configure the campaign.
OfferItem[] memory offer = new OfferItem[](1);
Expand Down
8 changes: 3 additions & 5 deletions script/DeployAndRedeemTrait.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,9 @@ import {ItemType} from "seaport-types/src/lib/ConsiderationEnums.sol";
import {OfferItem, ConsiderationItem} from "seaport-types/src/lib/ConsiderationStructs.sol";
import {IERC7496} from "shipyard-core/src/dynamic-traits/interfaces/IERC7496.sol";
import {Campaign, CampaignParams, CampaignRequirements, TraitRedemption} from "../src/lib/RedeemablesStructs.sol";
import {ERC721RedemptionMintable} from "../src/extensions/ERC721RedemptionMintable.sol";
import {ERC721ShipyardRedeemableMintable} from "../src/extensions/ERC721ShipyardRedeemableMintable.sol";
import {ERC721ShipyardRedeemablePreapprovedTraitSetters} from
"../src/test/ERC721ShipyardRedeemablePreapprovedTraitSetters.sol";
import {ERC721ShipyardRedeemableMintable} from "../src/extensions/ERC721ShipyardRedeemableMintable.sol";
import {ERC721ShipyardRedeemableTraitSetters} from "../src/test/ERC721ShipyardRedeemableTraitSetters.sol";

contract DeployAndRedeemTrait is Script, Test {
function run() external {
Expand All @@ -27,8 +26,7 @@ contract DeployAndRedeemTrait is Script, Test {
allowedTraitSetters[0] = address(receiveToken);

// deploy the redeem token with the receive token as an allowed trait setter
ERC721ShipyardRedeemablePreapprovedTraitSetters redeemToken =
new ERC721ShipyardRedeemablePreapprovedTraitSetters(
ERC721ShipyardRedeemableTraitSetters redeemToken = new ERC721ShipyardRedeemableTraitSetters(
"DynamicTraitsRedeemToken",
"TEST",
allowedTraitSetters
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {ItemType} from "seaport-types/src/lib/ConsiderationEnums.sol";
import {OfferItem, ConsiderationItem} from "seaport-types/src/lib/ConsiderationStructs.sol";
import {Campaign, CampaignParams, CampaignRequirements} from "../src/lib/RedeemablesStructs.sol";
import {BURN_ADDRESS} from "../src/lib/RedeemablesConstants.sol";
import {ERC721RedemptionMintable} from "../src/extensions/ERC721RedemptionMintable.sol";
import {ERC721ShipyardRedeemableMintable} from "../src/extensions/ERC721ShipyardRedeemableMintable.sol";
import {ERC721OwnerMintable} from "../src/test/ERC721OwnerMintable.sol";
import {ERC721ShipyardRedeemableMintable} from "../src/extensions/ERC721ShipyardRedeemableMintable.sol";

Expand Down
2 changes: 1 addition & 1 deletion script/RedeemTokens.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {Test} from "forge-std/Test.sol";
import {ItemType} from "seaport-types/src/lib/ConsiderationEnums.sol";
import {OfferItem, ConsiderationItem} from "seaport-types/src/lib/ConsiderationStructs.sol";
import {CampaignParams, CampaignRequirements} from "../src/lib/RedeemablesStructs.sol";
import {ERC721RedemptionMintable} from "../src/extensions/ERC721RedemptionMintable.sol";
import {ERC721ShipyardRedeemableMintable} from "../src/extensions/ERC721ShipyardRedeemableMintable.sol";
import {ERC721OwnerMintable} from "../src/test/ERC721OwnerMintable.sol";
import {ERC1155ShipyardRedeemableMintable} from "../src/extensions/ERC1155ShipyardRedeemableMintable.sol";

Expand Down
8 changes: 2 additions & 6 deletions src/ERC721SeaDropRedeemable.sol
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,7 @@ contract ERC721SeaDropRedeemable is ERC721SeaDrop, ERC7498NFTRedeemables {
}

function setTrait(uint256 tokenId, bytes32 traitKey, bytes32 value) public virtual override onlyOwner {
if (!_exists(tokenId)) {
revert TokenDoesNotExist();
}
if (!_exists(tokenId)) revert TokenDoesNotExist();

DynamicTraits.setTrait(tokenId, traitKey, value);
}
Expand All @@ -40,9 +38,7 @@ contract ERC721SeaDropRedeemable is ERC721SeaDrop, ERC7498NFTRedeemables {
override
returns (bytes32 traitValue)
{
if (!_exists(tokenId)) {
revert TokenDoesNotExist();
}
if (!_exists(tokenId)) revert TokenDoesNotExist();

traitValue = DynamicTraits.getTraitValue(tokenId, traitKey);
}
Expand Down
8 changes: 2 additions & 6 deletions src/ERC721ShipyardRedeemable.sol
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,7 @@ contract ERC721ShipyardRedeemable is ERC721ShipyardContractMetadata, ERC7498NFTR
}

function setTrait(uint256 tokenId, bytes32 traitKey, bytes32 value) public virtual override onlyOwner {
if (!_exists(tokenId)) {
revert TokenDoesNotExist();
}
if (!_exists(tokenId)) revert TokenDoesNotExist();

DynamicTraits.setTrait(tokenId, traitKey, value);
}
Expand All @@ -33,9 +31,7 @@ contract ERC721ShipyardRedeemable is ERC721ShipyardContractMetadata, ERC7498NFTR
override
returns (bytes32 traitValue)
{
if (!_exists(tokenId)) {
revert TokenDoesNotExist();
}
if (!_exists(tokenId)) revert TokenDoesNotExist();

traitValue = DynamicTraits.getTraitValue(tokenId, traitKey);
}
Expand Down
59 changes: 0 additions & 59 deletions src/extensions/ERC1155RedemptionMintable.sol

This file was deleted.

32 changes: 27 additions & 5 deletions src/extensions/ERC1155ShipyardRedeemableMintable.sol
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ 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 ERC-7498 redeemables contracts.
address[] internal _erc7498RedeemablesContracts;

/// @dev The next token id to mint. Each token will have a supply of 1.
uint256 _nextTokenId = 1;
Expand All @@ -27,16 +27,38 @@ contract ERC1155ShipyardRedeemableMintable is ERC1155ShipyardRedeemable, IRedemp
ConsiderationItem[] calldata, /* consideration */
TraitRedemption[] calldata /* traitRedemptions */
) external {
if (msg.sender != address(this)) {
revert InvalidSender();
}
// Require that msg.sender is valid.
_requireValidRedeemablesCaller();

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

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

function getRedeemablesContracts() external view returns (address[] memory) {
return _erc7498RedeemablesContracts;
}

function setRedeemablesContracts(address[] calldata redeemablesContracts) external onlyOwner {
_erc7498RedeemablesContracts = redeemablesContracts;
}

function _requireValidRedeemablesCaller() internal view {
// Allow the contract to call itself.
if (msg.sender == address(this)) return;

bool validCaller;
for (uint256 i; i < _erc7498RedeemablesContracts.length; i++) {
if (msg.sender == _erc7498RedeemablesContracts[i]) {
validCaller = true;
}
}
if (!validCaller) {
revert InvalidCaller(msg.sender);
}
}

function supportsInterface(bytes4 interfaceId)
public
view
Expand Down
59 changes: 0 additions & 59 deletions src/extensions/ERC721RedemptionMintable.sol

This file was deleted.

31 changes: 26 additions & 5 deletions src/extensions/ERC721ShipyardRedeemableMintable.sol
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ import {IRedemptionMintable} from "../interfaces/IRedemptionMintable.sol";
import {TraitRedemption} from "../lib/RedeemablesStructs.sol";

contract ERC721ShipyardRedeemableMintable is ERC721ShipyardRedeemable, IRedemptionMintable {
/// @dev Revert if the sender of mintRedemption is not this contract.
error InvalidSender();
/// @dev The ERC-7498 redeemables contracts.
address[] internal _erc7498RedeemablesContracts;

/// @dev The next token id to mint.
uint256 _nextTokenId = 1;
Expand All @@ -27,15 +27,36 @@ contract ERC721ShipyardRedeemableMintable is ERC721ShipyardRedeemable, IRedempti
ConsiderationItem[] calldata, /* consideration */
TraitRedemption[] calldata /* traitRedemptions */
) external {
if (msg.sender != address(this)) {
revert InvalidSender();
}
// Require that msg.sender is valid.
_requireValidRedeemablesCaller();

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

_mint(recipient, _nextTokenId - 1);
}

function getRedeemablesContracts() external view returns (address[] memory) {
return _erc7498RedeemablesContracts;
}

function setRedeemablesContracts(address[] calldata redeemablesContracts) external onlyOwner {
_erc7498RedeemablesContracts = redeemablesContracts;
}

function _requireValidRedeemablesCaller() internal view {
// Allow the contract to call itself.
if (msg.sender == address(this)) return;

bool validCaller;
for (uint256 i; i < _erc7498RedeemablesContracts.length; i++) {
if (msg.sender == _erc7498RedeemablesContracts[i]) {
validCaller = true;
}
}
if (!validCaller) revert InvalidCaller(msg.sender);
}

function supportsInterface(bytes4 interfaceId)
public
view
Expand Down
Loading

0 comments on commit a98fb8c

Please sign in to comment.