Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add trait redemptions to ERC7498 #7

Closed
wants to merge 10 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,19 @@
[submodule "lib/solarray"]
path = lib/solarray
url = https://github.com/evmcheb/solarray
[submodule "redeemables"]
path = redeemables
url = https://github.com/ProjectOpenSea/redeemables.git
[submodule "lib/ERC721A"]
path = lib/ERC721A
url = https://github.com/chiru-labs/ERC721A
[submodule "lib/openzeppelin-contracts-upgradeable"]
path = lib/openzeppelin-contracts-upgradeable
url = https://github.com/openzeppelin/openzeppelin-contracts-upgradeable
[submodule "lib/seadrop"]
path = lib/seadrop
url = https://github.com/ProjectOpenSea/seadrop
branch = v2
[submodule "lib/ds-test"]
path = lib/ds-test
url = https://github.com/dapphub/ds-test
11 changes: 10 additions & 1 deletion foundry.toml
Original file line number Diff line number Diff line change
@@ -1,21 +1,30 @@
[profile.default]
solc = "0.8.21"
src = "src"
out = "out"
libs = ["lib"]
remappings = [
'forge-std/=lib/forge-std/src',
'ds-test/=lib/ds-test/src',
'ERC721A/=lib/ERC721A/contracts/',
'solady/=lib/solady/src/',
'solady-test/=lib/solady/test/',
'openzeppelin-contracts/=lib/openzeppelin-contracts/contracts/',
'operator-filter-registry/=lib/seadrop/lib/operator-filter-registry/src/',
'shipyard-core/=src/',
'seaport-types/=lib/seaport-types/src/',
'solarray/=lib/solarray/src/',
'dynamic-traits/=lib/dynamic-traits/src/',
'openzeppelin-contracts/contracts/=lib/openzeppelin-contracts/contracts/',
'@openzeppelin/contracts/=lib/openzeppelin-contracts/contracts/',
'openzeppelin-contracts-upgradeable/=lib/openzeppelin-contracts-upgradeable/contracts/',
'utility-contracts/=lib/utility-contracts/src/',
'seadrop/=lib/seadrop/src/',
]
auto_detect_remappings = false
# bytecode_hash = 'none'
ignored_error_codes = ['license', 'code-size', 'init-code-size', 2519]
optimizer_runs = 99_999_999
optimizer_runs = 2_000_000

[profile.lite.fuzz]
runs = 1
Expand Down
1 change: 1 addition & 0 deletions lib/ERC721A
Submodule ERC721A added at 9be81f
1 change: 1 addition & 0 deletions lib/openzeppelin-contracts-upgradeable
25 changes: 25 additions & 0 deletions lib/redeemables/.github/pull_request_template.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<!--
Borrowed from foundry.

Thank you for your Pull Request. Please provide a description above and review
the requirements below.

Bug fixes and new features should include tests.
-->

## Motivation

<!--
Explain the context and why you're making that change. What is the problem
you're trying to solve? In some cases there is not a problem and this can be
thought of as being the motivation for your change.

If your PR solves a particular issue, tag that issue.
-->

## Solution

<!--
Summarize the solution and provide any necessary context needed to understand
the code change.
-->
45 changes: 45 additions & 0 deletions lib/redeemables/.github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
name: Test CI

on:
push:
branches: [main]
tags: ["*"]
pull_request:
types: [opened, reopened, synchronize]

env:
FOUNDRY_PROFILE: ci

jobs:
check:
strategy:
fail-fast: true

name: Foundry project
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
submodules: recursive

- name: Install Foundry
uses: foundry-rs/foundry-toolchain@v1
with:
version: nightly

- name: Run Forge build
run: |
forge --version
forge build --sizes
id: build

- name: Run Forge tests
run: |
forge test -vvv
id: test

- name: Run Forge format
run: |
forge fmt
[ -z "`git status --porcelain`" ] && echo "No diff for format" || { echo "Diff exists for format"; exit 1; }
id: lint
14 changes: 14 additions & 0 deletions lib/redeemables/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Compiler files
cache/
out/

# Ignores broadcast logs
/broadcast

# Docs
docs/

# Dotenv file
.env

.vscode
21 changes: 21 additions & 0 deletions lib/redeemables/.gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
[submodule "lib/forge-std"]
path = lib/forge-std
url = https://github.com/foundry-rs/forge-std
[submodule "lib/solady"]
path = lib/solady
url = [email protected]:Vectorized/solady.git
[submodule "lib/solarray"]
path = lib/solarray
url = https://github.com/evmcheb/solarray
[submodule "lib/seaport-types"]
path = lib/seaport-types
url = https://github.com/ProjectOpenSea/seaport-types
[submodule "lib/seaport-sol"]
path = lib/seaport-sol
url = https://github.com/ProjectOpenSea/seaport-sol
[submodule "lib/seaport-core"]
path = lib/seaport-core
url = https://github.com/ProjectOpenSea/seaport-core
[submodule "lib/murky"]
path = lib/murky
url = https://github.com/dmfxyz/murky.git
21 changes: 21 additions & 0 deletions lib/redeemables/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2023 Ozone Networks, Inc.

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
78 changes: 78 additions & 0 deletions lib/redeemables/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
# Redeemables

EVM smart contracts for redeemables and dynamic traits.

## Foundry

To install Foundry (assuming a Linux or macOS system):

```bash
curl -L https://foundry.paradigm.xyz | bash
```

This will download foundryup. To start Foundry, run:

```bash
foundryup
```

To install dependencies:

```
forge install
```

To run tests:

```
forge test
```

To run format:

```
forge fmt
```

<!--
To run gas snapshot:

```
forge snapshot
```
-->

The following modifiers are also available:

- Level 2 (-vv): Logs emitted during tests are also displayed.
- Level 3 (-vvv): Stack traces for failing tests are also displayed.
- Level 4 (-vvvv): Stack traces for all tests are displayed, and setup traces for failing tests are displayed.
- Level 5 (-vvvvv): Stack traces and setup traces are always displayed.

```bash
forge test -vv
```

For more information on foundry testing and use, see [Foundry Book installation instructions](https://book.getfoundry.sh/getting-started/installation).

## Contributing

Contributions are welcome by anyone interested in writing more tests, improving readability, optimizing for gas efficiency, or extending the protocol with new features.

When making a pull request, ensure that:

- All tests pass.
- Code coverage remains at 100% (coverage tests must currently be written in hardhat).
- All new code adheres to the style guide:
- All lint checks pass.
- Code is thoroughly commented with natspec where relevant.
- If making a change to the contracts:
- Gas snapshots are provided and demonstrate an improvement (or an acceptable deficit given other improvements).
- Reference contracts are modified correspondingly if relevant.
- New tests (ideally via foundry) are included for all new features or code paths.
- If making a modification to third-party dependencies, `yarn audit` passes.
- A descriptive summary of the PR has been provided.

## License

[MIT](LICENSE) Copyright 2023 Ozone Networks, Inc.
14 changes: 14 additions & 0 deletions lib/redeemables/foundry.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
[profile.default]
src = "src"
out = "out"
libs = ["lib"]
solc_version = '0.8.19'
remappings = [
'ds-test/=lib/forge-std/lib/ds-test/src/',
'solady/=lib/solady/',
'seaport-core/=lib/seaport-core/',
'seaport-sol/=lib/seaport-sol/',
'seaport-types/=lib/seaport-types/'
]

# See more config options https://github.com/foundry-rs/foundry/tree/master/config
77 changes: 77 additions & 0 deletions lib/redeemables/script/DeployAndConfigureExampleCampaign.s.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.19;

import "forge-std/Script.sol";

import {ItemType} from "seaport-types/src/lib/ConsiderationEnums.sol";
import {OfferItem, ConsiderationItem} from "seaport-types/src/lib/ConsiderationStructs.sol";
import {RedeemableContractOfferer} from "../src/RedeemableContractOfferer.sol";
import {CampaignParams} from "../src/lib/RedeemableStructs.sol";
import {ERC721RedemptionMintable} from "../src/lib/ERC721RedemptionMintable.sol";
import {TestERC721} from "../test/utils/mocks/TestERC721.sol";

contract DeployAndConfigureExampleCampaign is Script {
// Addresses: Seaport
address seaport = 0x00000000000000ADc04C56Bf30aC9d3c0aAF14dC;
address conduit = 0x1E0049783F008A0085193E00003D00cd54003c71;
bytes32 conduitKey = 0x0000007b02230091a7ed01230072f7006a004d60a8d4e71d599b8104250f0000;

address constant _BURN_ADDRESS = 0x000000000000000000000000000000000000dEaD;

function run() external {
vm.startBroadcast();

RedeemableContractOfferer offerer = new RedeemableContractOfferer(
conduit,
conduitKey,
seaport
);
TestERC721 redeemableToken = new TestERC721();
ERC721RedemptionMintable redemptionToken = new ERC721RedemptionMintable(
address(offerer),
address(redeemableToken)
);

// Configure the campaign.
OfferItem[] memory offer = new OfferItem[](1);
offer[0] = OfferItem({
itemType: ItemType.ERC721_WITH_CRITERIA,
token: address(redemptionToken),
identifierOrCriteria: 0,
startAmount: 1,
endAmount: 1
});

ConsiderationItem[] memory consideration = new ConsiderationItem[](1);
consideration[0] = ConsiderationItem({
itemType: ItemType.ERC721_WITH_CRITERIA,
token: address(redeemableToken),
identifierOrCriteria: 0,
startAmount: 1,
endAmount: 1,
recipient: payable(_BURN_ADDRESS)
});

CampaignParams memory params = CampaignParams({
offer: offer,
consideration: consideration,
signer: address(0),
startTime: uint32(block.timestamp),
endTime: uint32(block.timestamp + 1_000_000),
maxCampaignRedemptions: 1_000,
manager: msg.sender
});
offerer.createCampaign(params, "ipfs://QmdChMVnMSq4U6oVKhud7wUSEZGnwuMuTY5rUQx57Ayp6H");

// Mint tokens 1 and 5 to redeem for tokens 1 and 5.
redeemableToken.mint(msg.sender, 1);
redeemableToken.mint(msg.sender, 5);

// Let's redeem them!
uint256 campaignId = 1;
bytes32 redemptionHash = bytes32(0);
bytes memory data = abi.encode(campaignId, redemptionHash);
redeemableToken.safeTransferFrom(msg.sender, address(offerer), 1, data);
redeemableToken.safeTransferFrom(msg.sender, address(offerer), 5, data);
}
}
8 changes: 8 additions & 0 deletions lib/redeemables/src/ERC1155Redeemable.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.19;

import {ERC1155} from "solady/src/tokens/ERC1155.sol";
import {IERCDynamicTraits} from "./interfaces/IDynamicTraits.sol";
import {SignedRedeem} from "./lib/SignedRedeem.sol";

// contract ERC1155Redeemable is ERC1155, IERCDynamicTraits, SignedRedeem {}
14 changes: 14 additions & 0 deletions lib/redeemables/src/ERC721Redeemable.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.19;

import {ERC721} from "solady/src/tokens/ERC721.sol";
import {DynamicTraits} from "./lib/DynamicTraits.sol";
import {SignedRedeem} from "./lib/SignedRedeem.sol";
import {RedeemableErrorsAndEvents} from "./lib/RedeemableErrorsAndEvents.sol";

// contract ERC721Redeemable is
// ERC721,
// RedeemableErrorsAndEvents,
// DynamicTraits,
// SignedRedeem
// {}
Loading
Loading