Skip to content

Commit

Permalink
refacto examples and unused libs
Browse files Browse the repository at this point in the history
  • Loading branch information
zapaz committed Oct 9, 2023
1 parent 3f22c64 commit cee5fad
Show file tree
Hide file tree
Showing 31 changed files with 315 additions and 158 deletions.
6 changes: 0 additions & 6 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -1,9 +1,3 @@
[submodule "lib/forge-std"]
path = lib/forge-std
url = https://github.com/foundry-rs/forge-std
[submodule "lib/openzeppelin-contracts"]
path = lib/openzeppelin-contracts
url = https://github.com/Openzeppelin/openzeppelin-contracts
[submodule "lib/solmate"]
path = lib/solmate
url = https://github.com/transmissions11/solmate
170 changes: 44 additions & 126 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,148 +1,66 @@
```
___ ___ ___ ___
/ /\ / /\ / /\ /__/\
/ /::\ / /::\ / /:/_ \ \:\
/ /:/\:\ / /:/\:\ / /:/ /\ \ \:\
/ /:/ \:\ / /:/~/:/ / /:/ /:/_ _____\__\:\
/__/:/ \__\:\ /__/:/ /:/ /__/:/ /:/ /\ /__/::::::::\
\ \:\ / /:/ \ \:\/:/ \ \:\/:/ /:/ \ \:\~~\~~\/
\ \:\ /:/ \ \::/ \ \::/ /:/ \ \:\ ~~~
\ \:\/:/ \ \:\ \ \:\/:/ \ \:\
\ \::/ \ \:\ \ \::/ \ \:\
\__\/ \__\/ \__\/ \__\/
___ ___ ___
/__/\ / /\ ___ / /\
\ \:\ / /:/_ / /\ / /:/_
\ \:\ / /:/ /\ / /:/ / /:/ /\
_____\__\:\ / /:/ /:/ / /:/ / /:/ /::\
/__/::::::::\ /__/:/ /:/ / /::\ /__/:/ /:/\:\
\ \:\~~\~~\/ \ \:\/:/ /__/:/\:\ \ \:\/:/~/:/
\ \:\ ~~~ \ \::/ \__\/ \:\ \ \::/ /:/
\ \:\ \ \:\ \ \:\ \__\/ /:/
\ \:\ \ \:\ \__\/ /__/:/
\__\/ \__\/ \__\/
```

# OpenNFTs

*OpenNFTs is the NFT lego* : a library of smarcontract components, enabling the development of numerous NFT Collections


The general architeture of this library is mainly visible via the inheritance graph of the main OpenNFTs component:

```
//
// OpenERC165
// (supports)
// |
// ——————————————————————————————————————————————————————————————————————
// | | | |
// OpenERC721 OpenERC2981 OpenERC173 OpenCloneable
// (NFT) (RoyaltyInfo) (ownable) |
// | | | |
// —————————————————————————————————————— | ———————— |
// | | | | | | |
// OpenERC721Metadata OpenERC721Enumerable | ——————— | |
// | | | | | |
// | | OpenMarketable OpenPauseable |
// | | | | |
// ——————————————————————————————————————————————————————————————————————
// |
// OpenNFTs —— IOpenNFTs
//
```

_These components have been initially created by the [Kredeum NFTs](https://github.com/Kredeum/kredeum) project_

### Install

Install with npm :

`npm install Kredeum/OpenNFTs`

or forge :
## Foundry

`forge install Kredeum/OpenNFTs`
**Foundry is a blazing fast, portable and modular toolkit for Ethereum application development written in Rust.**

### Components
Foundry consists of:

Components are abstracted smartcontracts to be inherited from :
- **Forge**: Ethereum testing framework (like Truffle, Hardhat and DappTools).
- **Cast**: Swiss army knife for interacting with EVM smart contracts, sending transactions and getting chain data.
- **Anvil**: Local Ethereum node, akin to Ganache, Hardhat Network.
- **Chisel**: Fast, utilitarian, and verbose solidity REPL.

#### OpenERC
OpenERC extension pack, implementation of some of NFT relative ERCs
- OpenERC165.sol : [EIP-165 'supportsInterface' standard](https://eips.ethereum.org/EIPS/eip-165)
- OpenERC173.sol : [EIP-173 'ownable' standard](https://eips.ethereum.org/EIPS/eip-173)
- OpenERC721.sol : [EIP-721 'NFT' standard](https://eips.ethereum.org/EIPS/eip-721)
- OpenERC721Enumerable.sol : EIP-721 Enumerable option
- OpenERC721Metadata.sol : : EIP-721 Metadata option
- OpenERC721TokenReceiver.sol : EIP-721 TokenReceiver option
- OpenERC2981.sol : [EIP-2981 'NFT Royalty' standard](https://eips.ethereum.org/EIPS/eip-2981)
## Documentation

#### OpenNFTs
OpenNFTs main pack, to be used by your NFT template
- OpenGuard.sol : Guard from reentrancy attack
- OpenMarketable.sol : AutoMarket component, to sell your NFT at a defined price with royalties (conformant to
EIP-2981) with no need of a centralized MarketPlace
- OpenNFT.sol : Generic NFT components
- OpenPauseable.sol : Pausable extension, obviously allows to pause smartcontract
https://book.getfoundry.sh/

#### OpenResolve
OpenResolve extension pack, to read whatever NFTs infos : free, no gas required !
- OpenChecker.sol : Checkable extension, to check multiple ERC165 extensions
- OpenGetter.sol : Get infos from whatever NFT Collection and list of minted NFTs
- OpenRegistry.sol : Register your favorite NFT Collections, to be queried multiple times
- OpenResolver.sol : Resolve all the infos from a set of Collections
## Usage

#### OpenClone
OpenClone extension pack, via the use of EIP-1167 "Minimal Proxy"
- OpenCloner.sol : inherited by factory cloner
- OpenCloneable.sol : inherited by template smartcontracts to be cloned
### Build

### Examples

Here are some smartcontracts given as example on howto "compose" components to make usable NFT Collections:

- OpenNFTsEx : a generic NFT template

- OpenAutoMarketEx : a template with AutoMarket

- OpenResolverEx : a generic Resolver to get NFT infos

- OpenBoundEx : a multichain SoulBound NFT template

- OpenClonerEx : a NFTs Factory template

*Be carefull, these templates are not production ready.*
```shell
$ forge build
```

### Tests
### Test

A full set of solidity 'forge' tests are available to validate components and templates, to run them :
```shell
$ forge test
```

`forge test`
### Format

Those tests are very generic and enable you to test whatever NFTs smartcontracts, with few added code.
```shell
$ forge fmt
```

### Misc
### Gas Snapshots

**This is still beta software, and has not been audited yet, so use at your own risks.**
```shell
$ forge snapshot
```

We are welcoming any help via PR to develop new components. Like, for example,
ERC1155 support or a OpenMuliMintable component (enabling minting of multiple NFTs in a single transaction).
### Anvil

OpenNFTs is not "gas optimized", so deploy it carefully on Ethereum mainnet. That's why it's more dedicated to
templates, to be cloned mutliple times, than for a unique NFT Collection deployment.
```shell
$ anvil
```

*You can also use [Kredeum Dapp](https://beta.kredeum.com) to create NFT Collection without any coding.*
### Deploy

```shell
$ forge script script/Counter.s.sol:CounterScript --rpc-url <your_rpc_url> --private-key <your_private_key>
```

### Acknowledgments
### Cast

This OpenSource project has been developped with the help of :
```shell
$ cast <subcommand>
```

- [ETH Global](https://ethglobal.com/): via various Hackathons and prices
- [Polygon](https://polygon.technology/funds/): via a grant on the multichain NFT feature
- [GitCoin and all donators](https://gitcoin.co/grants/4186/kredeum-decentralized-nfts-factory): via Grant Rounds 12 to 15
- [OpenZeppelin](https://github.com/OpenZeppelin/openzeppelin-contracts/tree/master/contracts): _OpenNFTs is heavily inspired by the more generic OpenZeppelin contracts_
### Help

Thanks to all of them.
```shell
$ forge --help
$ anvil --help
$ cast --help
```
2 changes: 1 addition & 1 deletion certora/src/OpenAutoMarketExHarness.sol
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

import {OpenAutoMarketEx} from "OpenNFTs/tests/examples/OpenAutoMarketEx.sol";
import {OpenAutoMarketEx} from "OpenNFTs/contracts/examples/OpenAutoMarketEx.sol";
import {Receiver} from "./Receiver.sol";

contract OpenAutoMarketExHarness is OpenAutoMarketEx {
Expand Down
7 changes: 7 additions & 0 deletions contracts/OpenTBA/OpenTBA.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
// SPDX-License-Identifier: MIT
// OpenGuard
//
pragma solidity ^0.8.0;

abstract contract OpenTBA {
}
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion lib/forge-std
Submodule forge-std updated 1 files
+1 −1 package.json
1 change: 0 additions & 1 deletion lib/openzeppelin-contracts
Submodule openzeppelin-contracts deleted from 0a25c1
1 change: 0 additions & 1 deletion lib/solmate
Submodule solmate deleted from 0384db
2 changes: 0 additions & 2 deletions remappings.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,3 @@ OpenNFTs/contracts=contracts
OpenNFTs/tests=tests
ds-test=lib/forge-std/lib/ds-test/src
forge-std=lib/forge-std/src
@openzeppelin/contracts=lib/openzeppelin-contracts/contracts
@solmate=lib/solmate/src
2 changes: 1 addition & 1 deletion tests/OpenAutoMarketEx/OpenAutoMarketExMintTest.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ pragma solidity ^0.8.0;

import "forge-std/Test.sol";

import {OpenAutoMarketEx} from "OpenNFTs/tests/examples/OpenAutoMarketEx.sol";
import {OpenAutoMarketEx} from "OpenNFTs/contracts/examples/OpenAutoMarketEx.sol";

abstract contract OpenAutoMarketExMintTest is Test {
address private _owner = makeAddr("owner");
Expand Down
2 changes: 1 addition & 1 deletion tests/OpenAutoMarketEx/OpenAutoMarketExTest.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ pragma solidity ^0.8.0;

import "forge-std/Test.sol";

import "OpenNFTs/tests/examples/OpenAutoMarketEx.sol";
import "OpenNFTs/contracts/examples/OpenAutoMarketEx.sol";
import "OpenNFTs/tests/OpenAutoMarketEx/OpenAutoMarketExHackTest.t.sol";
import "OpenNFTs/tests/OpenAutoMarketEx/OpenAutoMarketExMintTest.t.sol";

Expand Down
2 changes: 1 addition & 1 deletion tests/OpenBoundEx/OpenBoundExSupportsTest.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import "forge-std/Test.sol";

import "OpenNFTs/tests/interfaces/IAll.sol";
import "OpenNFTs/tests/interfaces/IOpenBoundEx.sol";
import "OpenNFTs/tests/examples/OpenResolverEx.sol";
import "OpenNFTs/contracts/examples/OpenResolverEx.sol";

abstract contract OpenBoundExSupportsTest is Test {
OpenResolverEx private _resolver;
Expand Down
2 changes: 1 addition & 1 deletion tests/OpenBoundEx/OpenBoundExTest.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ pragma solidity ^0.8.0;

import "forge-std/Test.sol";

import "OpenNFTs/tests/examples/OpenBoundEx.sol";
import "OpenNFTs/contracts/examples/OpenBoundEx.sol";
import "OpenNFTs/tests/OpenBoundEx/OpenBoundExSupportsTest.t.sol";

import "OpenNFTs/tests/sets/OpenNFTsTest.t.sol";
Expand Down
4 changes: 2 additions & 2 deletions tests/OpenClonerEx/OpenClonerExTest.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import "forge-std/Test.sol";

import "OpenNFTs/tests/interfaces/ITest.sol";
import "OpenNFTs/contracts/interfaces/IOpenCloneable.sol";
import "OpenNFTs/tests/examples/OpenClonerEx.sol";
import "OpenNFTs/tests/examples/OpenNFTsEx.sol";
import "OpenNFTs/contracts/examples/OpenClonerEx.sol";
import "OpenNFTs/contracts/examples/OpenNFTsEx.sol";

contract OpenClonerExTest is Test {
OpenNFTsEx private _collection;
Expand Down
4 changes: 2 additions & 2 deletions tests/OpenNFTsEx/OpenNFTsExCloneTest.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ pragma solidity ^0.8.0;
import "forge-std/Test.sol";

import "OpenNFTs/tests/interfaces/IAll.sol";
import "OpenNFTs/tests/examples/OpenNFTsEx.sol";
import "OpenNFTs/tests/examples/OpenClonerEx.sol";
import "OpenNFTs/contracts/examples/OpenNFTsEx.sol";
import "OpenNFTs/contracts/examples/OpenClonerEx.sol";

abstract contract OpenNFTsExCloneTest is Test {
OpenClonerEx private _cloner;
Expand Down
2 changes: 1 addition & 1 deletion tests/OpenNFTsEx/OpenNFTsExSupportsTest.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import "forge-std/Test.sol";
import "OpenNFTs/tests/interfaces/IAll.sol";
import "OpenNFTs/contracts/interfaces/IOpenNFTs.sol";
import "OpenNFTs/tests/interfaces/IOpenNFTsEx.sol";
import "OpenNFTs/tests/examples/OpenResolverEx.sol";
import "OpenNFTs/contracts/examples/OpenResolverEx.sol";

abstract contract OpenNFTsExSupportsTest is Test {
OpenResolverEx private _resolver;
Expand Down
2 changes: 1 addition & 1 deletion tests/OpenNFTsEx/OpenNFTsExTest.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ pragma solidity ^0.8.0;

import "forge-std/Test.sol";

import "OpenNFTs/tests/examples/OpenNFTsEx.sol";
import "OpenNFTs/contracts/examples/OpenNFTsEx.sol";

import "OpenNFTs/tests/OpenNFTsEx/OpenNFTsExInitializeTest.t.sol";
import "OpenNFTs/tests/OpenNFTsEx/OpenNFTsExCloneTest.t.sol";
Expand Down
2 changes: 1 addition & 1 deletion tests/OpenResolverEx/OpenResolverExTest.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ pragma solidity ^0.8.0;

import "forge-std/Test.sol";

import "OpenNFTs/tests/examples/OpenResolverEx.sol";
import "OpenNFTs/contracts/examples/OpenResolverEx.sol";

import "OpenNFTs/tests/interfaces/ITest.sol";
import "OpenNFTs/tests/units/OpenResolverTest.t.sol";
Expand Down
2 changes: 1 addition & 1 deletion tests/echidna/OpenAutoMarketEx.e.sol
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// SPDX-License-Identifier: MITs
pragma solidity ^0.8.0;

import "OpenNFTs/tests/examples/OpenAutoMarketEx.sol";
import "OpenNFTs/contracts/examples/OpenAutoMarketEx.sol";

contract OpenAutoMarketExFuzz is OpenAutoMarketEx {
address private _other = address(1);
Expand Down
2 changes: 1 addition & 1 deletion tests/echidna/OpenAutoMarketEx.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
pragma solidity ^0.8.0;

import "forge-std/Test.sol";
import "OpenNFTs/tests/examples/OpenAutoMarketEx.sol";
import "OpenNFTs/contracts/examples/OpenAutoMarketEx.sol";
import "OpenNFTs/contracts/OpenERC/OpenERC721TokenReceiver.sol";

contract OpenAutoMarketExFromInside is Test, OpenAutoMarketEx {
Expand Down
8 changes: 6 additions & 2 deletions tests/ERC1155Ex/ERC1155Ex.sol → tests/mocks/MockERC1155.sol
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

import "@openzeppelin/contracts/token/ERC1155/ERC1155.sol";
import {ERC1155} from "tests/mocks/SolmateERC1155.sol";

interface IERC1155Ex {
function mint(uint256) external;
Expand All @@ -10,7 +10,11 @@ interface IERC1155Ex {
contract ERC1155Ex is IERC1155Ex, ERC1155 {
uint256 id;

constructor() ERC1155("https://erc1155ex.test") {}
constructor() ERC1155() {}

function uri(uint256) public pure override(ERC1155) returns (string memory) {
return "";
}

function mint(uint256 amount) public override(IERC1155Ex) {
_mint(msg.sender, ++id, amount, "");
Expand Down
Loading

0 comments on commit cee5fad

Please sign in to comment.