-
Notifications
You must be signed in to change notification settings - Fork 5.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: cleanup, correct errors & typos, add assets
- Loading branch information
Showing
13 changed files
with
16,953 additions
and
53 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
node_modules | ||
.env | ||
coverage | ||
coverage.json | ||
typechain | ||
typechain-types | ||
|
||
# Hardhat files | ||
cache | ||
artifacts | ||
|
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,55 @@ | ||
# ERC-7007 Reference Implementation | ||
|
||
This is a WIP implementation of ERC-7007 based on the discussions in the [EIP-7007 issue thread](https://github.com/ethereum/EIPs/issues/7007). | ||
|
||
## Setup | ||
Run `npm install` in the root directory. | ||
|
||
## Testing | ||
Try running some of the following tasks: | ||
|
||
```shell | ||
npx hardhat help | ||
npx hardhat test | ||
REPORT_GAS=true npx hardhat test | ||
``` | ||
|
||
## Metadata Standard | ||
|
||
```json | ||
{ | ||
"title": "AIGC Metadata", | ||
"type": "object", | ||
"properties": { | ||
"name": { | ||
"type": "string", | ||
"description": "Identifies the asset to which this NFT represents" | ||
}, | ||
"description": { | ||
"type": "string", | ||
"description": "Describes the asset to which this NFT represents" | ||
}, | ||
"image": { | ||
"type": "string", | ||
"description": "A URI pointing to a resource with mime type image/* representing the asset to which this NFT represents. Consider making any images at a width between 320 and 1080 pixels and aspect ratio between 1.91:1 and 4:5 inclusive." | ||
}, | ||
|
||
"prompt": { | ||
"type": "string", | ||
"description": "Identifies the prompt from which this AIGC NFT generated" | ||
}, | ||
"seed": { | ||
"type": "uint256", | ||
"description": "Identifies the seed from which this AIGC NFT generated" | ||
}, | ||
"aigc_type": { | ||
"type": "string", | ||
"description": "image/video/audio..." | ||
}, | ||
"aigc_data": { | ||
"type": "string", | ||
"description": "A URI pointing to a resource with mime type image/* representing the asset to which this AIGC NFT represents. Consider making any images at a width between 320 and 1080 pixels and aspect ratio between 1.91:1 and 4:5 inclusive." | ||
} | ||
} | ||
} | ||
``` |
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,79 @@ | ||
// SPDX-License-Identifier: UNLICENSED | ||
pragma solidity ^0.8.18; | ||
|
||
import "@openzeppelin/contracts/utils/introspection/ERC165.sol"; | ||
import "@openzeppelin/contracts/token/ERC721/extensions/ERC721URIStorage.sol"; | ||
import "./IERC7007.sol"; | ||
import "./IVerifier.sol"; | ||
|
||
/** | ||
* @dev Implementation of the {IERC7007} interface. | ||
*/ | ||
contract ERC7007 is ERC165, IERC7007, ERC721URIStorage { | ||
address public immutable verifier; | ||
|
||
/** | ||
* @dev Initializes the contract by setting a `name` and a `symbol` to the token collection. | ||
*/ | ||
constructor( | ||
string memory name_, | ||
string memory symbol_, | ||
address verifier_ | ||
) ERC721(name_, symbol_) { | ||
verifier = verifier_; | ||
} | ||
|
||
/** | ||
* @dev See {IERC7007-mint}. | ||
*/ | ||
function mint( | ||
bytes calldata prompt, | ||
bytes calldata aigcData, | ||
string calldata uri, | ||
bytes calldata proof | ||
) public virtual override returns (uint256 tokenId) { | ||
require(verify(prompt, aigcData, proof), "ERC7007: invalid proof"); | ||
tokenId = uint256(keccak256(prompt)); | ||
_safeMint(msg.sender, tokenId); | ||
string memory tokenUri = string( | ||
abi.encodePacked( | ||
"{", | ||
uri, | ||
', "prompt": "', | ||
string(prompt), | ||
'", "aigc_data": "', | ||
string(aigcData), | ||
'"}' | ||
) | ||
); | ||
_setTokenURI(tokenId, tokenUri); | ||
emit Mint(tokenId, prompt, aigcData, uri, proof); | ||
} | ||
|
||
/** | ||
* @dev See {IERC7007-verify}. | ||
*/ | ||
function verify( | ||
bytes calldata prompt, | ||
bytes calldata aigcData, | ||
bytes calldata proof | ||
) public view virtual override returns (bool success) { | ||
return | ||
IVerifier(verifier).verifyProof( | ||
proof, | ||
abi.encodePacked(prompt, aigcData) | ||
); | ||
} | ||
|
||
/** | ||
* @dev See {IERC165-supportsInterface}. | ||
*/ | ||
function supportsInterface( | ||
bytes4 interfaceId | ||
) public view virtual override(ERC165, ERC721, IERC165) returns (bool) { | ||
return | ||
interfaceId == type(IERC721).interfaceId || | ||
interfaceId == type(IERC721Metadata).interfaceId || | ||
super.supportsInterface(interfaceId); | ||
} | ||
} |
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,54 @@ | ||
// SPDX-License-Identifier: UNLICENSED | ||
pragma solidity ^0.8.18; | ||
|
||
import "./ERC7007.sol"; | ||
import "./IERC7007Enumerable.sol"; | ||
|
||
/** | ||
* @dev Implementation of the {IERC7007Enumerable} interface. | ||
*/ | ||
abstract contract ERC7007Enumerable is ERC7007, IERC7007Enumerable { | ||
/** | ||
* @dev See {IERC7007Enumerable-tokenId}. | ||
*/ | ||
mapping(uint256 => string) public prompt; | ||
|
||
|
||
/** | ||
* @dev See {IERC7007Enumerable-prompt}. | ||
*/ | ||
mapping(bytes => uint256) public tokenId; | ||
|
||
/** | ||
* @dev See {IERC165-supportsInterface}. | ||
*/ | ||
function supportsInterface( | ||
bytes4 interfaceId | ||
) public view virtual override(IERC165, ERC7007) returns (bool) { | ||
return | ||
interfaceId == type(IERC7007Enumerable).interfaceId || | ||
super.supportsInterface(interfaceId); | ||
} | ||
|
||
/** | ||
* @dev See {IERC7007-mint}. | ||
*/ | ||
function mint( | ||
bytes calldata prompt_, | ||
bytes calldata aigcData, | ||
string calldata uri, | ||
bytes calldata proof | ||
) public virtual override(ERC7007, IERC7007) returns (uint256 tokenId_) { | ||
tokenId_ = ERC7007.mint(prompt_, aigcData, uri, proof); | ||
prompt[tokenId_] = string(prompt_); | ||
tokenId[prompt_] = tokenId_; | ||
} | ||
} | ||
|
||
contract MockERC7007Enumerable is ERC7007Enumerable { | ||
constructor( | ||
string memory name_, | ||
string memory symbol_, | ||
address verifier_ | ||
) ERC7007(name_, symbol_, verifier_) {} | ||
} |
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,46 @@ | ||
// SPDX-License-Identifier: UNLICENSED | ||
pragma solidity ^0.8.18; | ||
|
||
import "@openzeppelin/contracts/utils/introspection/IERC165.sol"; | ||
|
||
/** | ||
* @dev Required interface of an ERC7007 compliant contract. | ||
*/ | ||
interface IERC7007 is IERC165 { | ||
/** | ||
* @dev Emitted when `tokenId` token is minted. | ||
*/ | ||
event Mint( | ||
uint256 indexed tokenId, | ||
bytes indexed prompt, | ||
bytes indexed aigcData, | ||
string uri, | ||
bytes proof | ||
); | ||
|
||
/** | ||
* @dev Mint token at `tokenId` given `prompt`, `aigcData`, `uri` and `proof`. | ||
* | ||
* Requirements: | ||
* - `tokenId` must not exist.' | ||
* - verify(`prompt`, `aigcData`, `proof`) must return true. | ||
* | ||
* Optional: | ||
* - `proof` should not include `aigcData` to save gas. | ||
*/ | ||
function mint( | ||
bytes calldata prompt, | ||
bytes calldata aigcData, | ||
string calldata uri, | ||
bytes calldata proof | ||
) external returns (uint256 tokenId); | ||
|
||
/** | ||
* @dev Verify the `prompt`, `aigcData` and `proof`. | ||
*/ | ||
function verify( | ||
bytes calldata prompt, | ||
bytes calldata aigcData, | ||
bytes calldata proof | ||
) external view returns (bool success); | ||
} |
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,19 @@ | ||
// SPDX-License-Identifier: UNLICENSED | ||
pragma solidity ^0.8.18; | ||
|
||
import "./IERC7007.sol"; | ||
|
||
/** | ||
* @title ERC7007 Token Standard, optional enumeration extension | ||
*/ | ||
interface IERC7007Enumerable is IERC7007 { | ||
/** | ||
* @dev Returns the token ID given `prompt`. | ||
*/ | ||
function tokenId(bytes calldata prompt) external view returns (uint256); | ||
|
||
/** | ||
* @dev Returns the prompt given `tokenId`. | ||
*/ | ||
function prompt(uint256 tokenId) external view returns (string calldata); | ||
} |
Oops, something went wrong.