Skip to content
This repository was archived by the owner on Sep 1, 2023. It is now read-only.

Commit 528218b

Browse files
Merge pull request #13 from ProjectOpenSea/upgradeable
Add Upgradeable Contracts and Examples
2 parents f51b968 + 05684f7 commit 528218b

20 files changed

+449
-20
lines changed

.gitignore

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# Compiler files
2+
cache/
3+
out/
4+
5+
# Ignores development broadcast logs
6+
!/broadcast
7+
/broadcast/*/31337/
8+
/broadcast/**/dry-run/
9+
10+
# Dotenv file
11+
.env
12+
remappings.txt

.gitmodules

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,6 @@
44
[submodule "lib/forge-std"]
55
path = lib/forge-std
66
url = https://github.com/foundry-rs/forge-std
7+
[submodule "lib/openzeppelin-contracts-upgradeable"]
8+
path = lib/openzeppelin-contracts-upgradeable
9+
url = https://github.com/openzeppelin/openzeppelin-contracts-upgradeable

foundry.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,8 @@ out = 'out'
44
libs = ['lib']
55
optimizer_runs = 1_000_000
66
solc = '0.8.17'
7+
remappings = [
8+
'openzeppelin-contracts-upgradeable/=lib/openzeppelin-contracts-upgradeable/contracts',
9+
]
710

811
# See more config options https://github.com/foundry-rs/foundry/tree/master/config

src/example/ExampleERC1155.sol

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
pragma solidity ^0.8.13;
33

44
import {ERC1155} from "openzeppelin-contracts/token/ERC1155/ERC1155.sol";
5-
import {DefaultOperatorFilterer1155, OperatorFilterer1155} from "./DefaultOperatorFilterer1155.sol";
5+
import {DefaultOperatorFilterer1155} from "./DefaultOperatorFilterer1155.sol";
66
import {Ownable} from "openzeppelin-contracts/access/Ownable.sol";
77

88
/**

src/example/ExampleERC721.sol

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
pragma solidity ^0.8.13;
33

44
import {ERC721} from "openzeppelin-contracts/token/ERC721/ERC721.sol";
5-
import {DefaultOperatorFilterer721, OperatorFilterer721} from "./DefaultOperatorFilterer721.sol";
5+
import {DefaultOperatorFilterer721} from "./DefaultOperatorFilterer721.sol";
66
import {Ownable} from "openzeppelin-contracts/access/Ownable.sol";
77

88
/**
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
// SPDX-License-Identifier: MIT
2+
pragma solidity ^0.8.13;
3+
4+
import {OperatorFilterer1155Upgradeable} from "./OperatorFilterer1155Upgradeable.sol";
5+
6+
abstract contract DefaultOperatorFilterer1155Upgradeable is OperatorFilterer1155Upgradeable {
7+
address constant DEFAULT_SUBSCRIPTION = address(0x3cc6CddA760b79bAfa08dF41ECFA224f810dCeB6);
8+
9+
function __DefaultOperatorFilterer1155_init() public onlyInitializing {
10+
OperatorFilterer1155Upgradeable.__OperatorFilterer1155_init(DEFAULT_SUBSCRIPTION, true);
11+
}
12+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
// SPDX-License-Identifier: MIT
2+
pragma solidity ^0.8.13;
3+
4+
import {OperatorFilterer721Upgradeable} from "./OperatorFilterer721Upgradeable.sol";
5+
6+
abstract contract DefaultOperatorFilterer721Upgradeable is OperatorFilterer721Upgradeable {
7+
address constant DEFAULT_SUBSCRIPTION = address(0x3cc6CddA760b79bAfa08dF41ECFA224f810dCeB6);
8+
9+
function __DefaultOperatorFilterer721_init() public onlyInitializing {
10+
OperatorFilterer721Upgradeable.__OperatorFilterer721_init(DEFAULT_SUBSCRIPTION, true);
11+
}
12+
}
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
// SPDX-License-Identifier: MIT
2+
pragma solidity ^0.8.13;
3+
4+
import {ERC1155Upgradeable} from "openzeppelin-contracts-upgradeable/token/ERC1155/ERC1155Upgradeable.sol";
5+
import {DefaultOperatorFilterer1155Upgradeable} from "./DefaultOperatorFilterer1155Upgradeable.sol";
6+
import {OwnableUpgradeable} from "openzeppelin-contracts-upgradeable/access/OwnableUpgradeable.sol";
7+
8+
/**
9+
* @title ExampleERC1155Upgradeable
10+
* @notice This example contract is configured to use the DefaultOperatorFilterer, which automatically registers the
11+
* token and subscribes it to OpenSea's curated filters.
12+
* Adding the onlyAllowedOperator modifier to the transferFrom and both safeTransferFrom methods ensures that
13+
* the msg.sender (operator) is allowed by the OperatorFilterRegistry.
14+
*/
15+
abstract contract ExampleERC1155Upgradeable is
16+
ERC1155Upgradeable,
17+
DefaultOperatorFilterer1155Upgradeable,
18+
OwnableUpgradeable
19+
{
20+
function initialize() public initializer {
21+
__ERC1155_init("");
22+
__Ownable_init();
23+
__DefaultOperatorFilterer1155_init();
24+
}
25+
26+
function safeTransferFrom(address from, address to, uint256 tokenId, uint256 amount, bytes memory data)
27+
public
28+
override
29+
onlyAllowedOperator(from, tokenId)
30+
{
31+
super.safeTransferFrom(from, to, tokenId, amount, data);
32+
}
33+
34+
function safeBatchTransferFrom(
35+
address from,
36+
address to,
37+
uint256[] memory ids,
38+
uint256[] memory amounts,
39+
bytes memory data
40+
) public virtual override onlyAllowedOperatorBatch(from, ids) {
41+
super.safeBatchTransferFrom(from, to, ids, amounts, data);
42+
}
43+
}
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
// SPDX-License-Identifier: MIT
2+
pragma solidity ^0.8.13;
3+
4+
import {ERC721Upgradeable} from "openzeppelin-contracts-upgradeable/token/ERC721/ERC721Upgradeable.sol";
5+
import {DefaultOperatorFilterer721Upgradeable} from "./DefaultOperatorFilterer721Upgradeable.sol";
6+
import {OwnableUpgradeable} from "openzeppelin-contracts-upgradeable/access/OwnableUpgradeable.sol";
7+
8+
/**
9+
* @title ExampleERC721Upgradeable
10+
* @notice This example contract is configured to use the DefaultOperatorFilterer, which automatically registers the
11+
* token and subscribes it to OpenSea's curated filters.
12+
* Adding the onlyAllowedOperator modifier to the transferFrom and both safeTransferFrom methods ensures that
13+
* the msg.sender (operator) is allowed by the OperatorFilterRegistry.
14+
*/
15+
abstract contract ExampleERC721Upgradeable is
16+
ERC721Upgradeable,
17+
DefaultOperatorFilterer721Upgradeable,
18+
OwnableUpgradeable
19+
{
20+
function initialize() public initializer {
21+
__ERC721_init("Example", "EXAMPLE");
22+
__Ownable_init();
23+
__DefaultOperatorFilterer721_init();
24+
}
25+
26+
function transferFrom(address from, address to, uint256 tokenId) public override onlyAllowedOperator(from) {
27+
super.transferFrom(from, to, tokenId);
28+
}
29+
30+
function safeTransferFrom(address from, address to, uint256 tokenId) public override onlyAllowedOperator(from) {
31+
super.safeTransferFrom(from, to, tokenId);
32+
}
33+
34+
function safeTransferFrom(address from, address to, uint256 tokenId, bytes memory data)
35+
public
36+
override
37+
onlyAllowedOperator(from)
38+
{
39+
super.safeTransferFrom(from, to, tokenId, data);
40+
}
41+
42+
function tokenURI(uint256) public pure override returns (string memory) {
43+
return "";
44+
}
45+
}

0 commit comments

Comments
 (0)