-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #15 from ProjectOpenSea/stephan/dynamic-traits
add trait redemptions to ERC7498Redeemables
- Loading branch information
Showing
24 changed files
with
704 additions
and
333 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,112 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity ^0.8.19; | ||
|
||
import {Script} from "forge-std/Script.sol"; | ||
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 {IERC7496} from "shipyard-core/src/dynamic-traits/interfaces/IERC7496.sol"; | ||
import {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"; | ||
|
||
contract DeployAndRedeemTrait is Script, Test { | ||
function run() external { | ||
vm.startBroadcast(); | ||
|
||
// deploy the receive token first | ||
ERC721ShipyardRedeemableMintable receiveToken = new ERC721ShipyardRedeemableMintable( | ||
"TestRedeemablesRecieveToken", | ||
"TEST" | ||
); | ||
|
||
// add the receive token address to allowed trait setters array | ||
address[] memory allowedTraitSetters = new address[](1); | ||
allowedTraitSetters[0] = address(receiveToken); | ||
|
||
// deploy the redeem token with the receive token as an allowed trait setter | ||
ERC721ShipyardRedeemablePreapprovedTraitSetters redeemToken = | ||
new ERC721ShipyardRedeemablePreapprovedTraitSetters( | ||
"DynamicTraitsRedeemToken", | ||
"TEST", | ||
allowedTraitSetters | ||
); | ||
|
||
// configure the campaign. | ||
OfferItem[] memory offer = new OfferItem[](1); | ||
|
||
// offer is receive token | ||
offer[0] = OfferItem({ | ||
itemType: ItemType.ERC721_WITH_CRITERIA, | ||
token: address(receiveToken), | ||
identifierOrCriteria: 0, | ||
startAmount: 1, | ||
endAmount: 1 | ||
}); | ||
|
||
// consideration is empty | ||
ConsiderationItem[] memory consideration = new ConsiderationItem[](0); | ||
|
||
TraitRedemption[] memory traitRedemptions = new TraitRedemption[](1); | ||
|
||
// trait key is "hasRedeemed" | ||
bytes32 traitKey = bytes32("hasRedeemed"); | ||
|
||
// previous trait value (`substandardValue`) should be 0 | ||
bytes32 substandardValue = bytes32(uint256(0)); | ||
|
||
// new trait value should be 1 | ||
bytes32 traitValue = bytes32(uint256(1)); | ||
|
||
traitRedemptions[0] = TraitRedemption({ | ||
substandard: 1, | ||
token: address(redeemToken), | ||
traitKey: traitKey, | ||
traitValue: traitValue, | ||
substandardValue: substandardValue | ||
}); | ||
|
||
CampaignRequirements[] memory requirements = new CampaignRequirements[]( | ||
1 | ||
); | ||
requirements[0].offer = offer; | ||
requirements[0].consideration = consideration; | ||
requirements[0].traitRedemptions = traitRedemptions; | ||
|
||
CampaignParams memory params = CampaignParams({ | ||
requirements: requirements, | ||
signer: address(0), | ||
startTime: uint32(block.timestamp), | ||
endTime: uint32(block.timestamp + 1_000_000), | ||
maxCampaignRedemptions: 1_000, | ||
manager: msg.sender | ||
}); | ||
receiveToken.createCampaign(params, ""); | ||
|
||
// Mint token 1 to redeem for token 1. | ||
redeemToken.mint(msg.sender, 1); | ||
|
||
// Let's redeem them! | ||
uint256[] memory traitRedemptionTokenIds = new uint256[](1); | ||
traitRedemptionTokenIds[0] = 1; | ||
|
||
bytes memory data = abi.encode( | ||
1, // campaignId | ||
0, // requirementsIndex | ||
bytes32(0), // redemptionHash | ||
traitRedemptionTokenIds, | ||
uint256(0), // salt | ||
bytes("") // signature | ||
); | ||
|
||
receiveToken.redeem(new uint256[](0), msg.sender, data); | ||
|
||
// Assert new trait has been set and redemption token is minted. | ||
bytes32 actualTraitValue = IERC7496(address(redeemToken)).getTraitValue(1, traitKey); | ||
// "hasRedeemed" should be 1 (true) | ||
assertEq(bytes32(uint256(1)), actualTraitValue); | ||
assertEq(receiveToken.ownerOf(1), msg.sender); | ||
} | ||
} |
86 changes: 86 additions & 0 deletions
86
script/DeployERC721ReceiveTokenWithPredeployedSeadropRedeemToken.s.sol
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity ^0.8.19; | ||
|
||
import {Script} from "forge-std/Script.sol"; | ||
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 {BURN_ADDRESS} from "../src/lib/RedeemablesConstants.sol"; | ||
import {ERC721RedemptionMintable} from "../src/extensions/ERC721RedemptionMintable.sol"; | ||
import {ERC721OwnerMintable} from "../src/test/ERC721OwnerMintable.sol"; | ||
import {ERC721ShipyardRedeemableMintable} from "../src/extensions/ERC721ShipyardRedeemableMintable.sol"; | ||
|
||
contract DeployERC721ReceiveTokenWithPredeployedSeaDropRedeemToken is Script, Test { | ||
function run() external { | ||
vm.startBroadcast(); | ||
|
||
ERC721ShipyardRedeemableMintable redeemToken = | ||
ERC721ShipyardRedeemableMintable(0xa1783E74857736b2AEE610A36b537B31CC333048); | ||
ERC721ShipyardRedeemableMintable receiveToken = | ||
ERC721ShipyardRedeemableMintable(0x343B9aEC7fAB02d07c6747Bace112920822334B4); | ||
|
||
// Configure the campaign. | ||
OfferItem[] memory offer = new OfferItem[](1); | ||
offer[0] = OfferItem({ | ||
itemType: ItemType.ERC721_WITH_CRITERIA, | ||
token: address(receiveToken), | ||
identifierOrCriteria: 0, | ||
startAmount: 1, | ||
endAmount: 1 | ||
}); | ||
|
||
ConsiderationItem[] memory consideration = new ConsiderationItem[](1); | ||
consideration[0] = ConsiderationItem({ | ||
itemType: ItemType.ERC721_WITH_CRITERIA, | ||
token: address(redeemToken), | ||
identifierOrCriteria: 0, | ||
startAmount: 1, | ||
endAmount: 1, | ||
recipient: payable(BURN_ADDRESS) | ||
}); | ||
|
||
CampaignRequirements[] memory requirements = new CampaignRequirements[]( | ||
1 | ||
); | ||
requirements[0].offer = offer; | ||
requirements[0].consideration = consideration; | ||
|
||
CampaignParams memory params = CampaignParams({ | ||
requirements: requirements, | ||
signer: address(0), | ||
startTime: uint32(block.timestamp), | ||
endTime: uint32(block.timestamp + 1_000_000), | ||
maxCampaignRedemptions: 1_000, | ||
manager: msg.sender | ||
}); | ||
uint256 campaignId = | ||
receiveToken.createCampaign(params, "ipfs://QmQKc93y2Ev5k9Kz54mCw48ZM487bwGDktZYPLtrjJ3r1d"); | ||
|
||
// redeemToken.setBaseURI( | ||
// "ipfs://QmYTSupCtriDLBHgPBBhZ98wYdp6N9S8jTL5sKSZwbASeT" | ||
// ); | ||
|
||
// receiveToken.setBaseURI( | ||
// "ipfs://QmWxgnz8T9wsMBmpCY4Cvanj3RR1obFD2hqDKPZhKN5Tsq/" | ||
// ); | ||
|
||
// Let's redeem them! | ||
uint256 requirementsIndex = 0; | ||
bytes32 redemptionHash; | ||
uint256 salt; | ||
bytes memory signature; | ||
bytes memory data = abi.encode(campaignId, requirementsIndex, redemptionHash, salt, signature); | ||
|
||
uint256[] memory tokenIds = new uint256[](1); | ||
tokenIds[0] = 1; | ||
|
||
redeemToken.setApprovalForAll(address(receiveToken), true); | ||
|
||
receiveToken.redeem(tokenIds, msg.sender, data); | ||
|
||
// Assert redeemable token is burned and redemption token is minted. | ||
assertEq(redeemToken.balanceOf(msg.sender), 2); | ||
assertEq(receiveToken.ownerOf(1), msg.sender); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.