-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit e73245e
Showing
28 changed files
with
17,420 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
ETHERSCAN_API_KEY=0000000000000000000000000000000000000000 | ||
RPC_URL=https://ropsten.infura.io/v3/0000000000000000000000000000000000000000 | ||
CONTRACT_OWNER_PRIVATE_KEY=0000000000000000000000000000000000000000000000000000000000000000 |
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,4 @@ | ||
node_modules | ||
artifacts | ||
cache | ||
coverage |
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,24 @@ | ||
module.exports = { | ||
env: { | ||
browser: false, | ||
es2021: true, | ||
mocha: true, | ||
node: true, | ||
}, | ||
plugins: ['@typescript-eslint'], | ||
extends: [ | ||
'standard', | ||
'plugin:prettier/recommended', | ||
'plugin:node/recommended', | ||
], | ||
parser: '@typescript-eslint/parser', | ||
parserOptions: { | ||
ecmaVersion: 12, | ||
}, | ||
rules: { | ||
'node/no-unsupported-features/es-syntax': [ | ||
'error', | ||
{ ignores: ['modules'] }, | ||
], | ||
}, | ||
} |
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,3 @@ | ||
- Explain what this PR changes | ||
- in one or more | ||
- bullet points |
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,17 @@ | ||
name: Compile and lint | ||
|
||
on: | ||
release: | ||
types: [synchronize, created] | ||
|
||
jobs: | ||
compile-code: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v2 | ||
- name: Install modules | ||
run: yarn | ||
- name: Compile code | ||
run: yarn compile | ||
- name: Lint code | ||
run: yarn lint |
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,23 @@ | ||
node_modules | ||
.env | ||
coverage | ||
coverage.json | ||
typechain | ||
.DS_Store | ||
dist | ||
|
||
# Hardhat files | ||
cache | ||
artifacts | ||
|
||
# logs | ||
*.log | ||
|
||
# yarn | ||
.pnp.* | ||
.yarn/* | ||
!.yarn/patches | ||
!.yarn/plugins | ||
!.yarn/releases | ||
!.yarn/sdks | ||
!.yarn/versions |
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,3 @@ | ||
hardhat.config.ts | ||
scripts | ||
test |
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 @@ | ||
v16.13.0 |
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,8 @@ | ||
node_modules | ||
artifacts | ||
cache | ||
coverage* | ||
gasReporterOutput.json | ||
typechain | ||
.yarn | ||
dist |
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,25 @@ | ||
{ | ||
"overrides": [ | ||
{ | ||
"files": "*.sol", | ||
"options": { | ||
"printWidth": 80, | ||
"tabWidth": 2, | ||
"useTabs": false, | ||
"singleQuote": false, | ||
"bracketSpacing": false, | ||
"explicitTypes": "always" | ||
} | ||
}, | ||
{ | ||
"files": ["*.ts", "*.js"], | ||
"options": { | ||
"trailingComma": "es5", | ||
"tabWidth": 2, | ||
"semi": false, | ||
"singleQuote": true, | ||
"endOfLine": "auto" | ||
} | ||
} | ||
] | ||
} |
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,14 @@ | ||
{ | ||
"extends": "solhint:recommended", | ||
"rules": { | ||
"compiler-version": ["error", "^0.8.1"], | ||
"func-visibility": [ | ||
"warn", | ||
{ | ||
"ignoreConstructors": true | ||
} | ||
], | ||
"no-empty-blocks": "off", | ||
"reason-string": "off" | ||
} | ||
} |
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 @@ | ||
node_modules |
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,10 @@ | ||
{ | ||
"recommendations": [ | ||
"dbaeumer.vscode-eslint", | ||
"esbenp.prettier-vscode", | ||
"hnw.vscode-auto-open-markdown-preview", | ||
"naumovs.color-highlight", | ||
"oderwat.indent-rainbow", | ||
"juanblanco.solidity" | ||
] | ||
} |
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,15 @@ | ||
{ | ||
"editor.defaultFormatter": "esbenp.prettier-vscode", | ||
"editor.formatOnSave": true, | ||
"editor.codeActionsOnSave": { "source.fixAll.eslint": true }, | ||
"eslint.enable": true, | ||
"eslint.validate": [ | ||
"javascript", | ||
"javascriptreact", | ||
"typescript", | ||
"typescriptreact" | ||
], | ||
"[json]": { | ||
"editor.defaultFormatter": "esbenp.prettier-vscode" | ||
} | ||
} |
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 @@ | ||
module.exports={name:"yarn-up-all-plugin",factory:a=>{const{Configuration:b,Project:c}=a("@yarnpkg/core"),{Cli:d,Command:e,Option:f}=a("clipanion"),g=a("@yarnpkg/plugin-essentials"),h=a("typanion"),i=(a,b)=>a?`@${a}/${b}`:b,j=(a,b)=>{const c=[...a.values()];return b?c.filter(a=>{const c=i(a[1].scope,a[1].name);return!b.includes(c)}):c};class k extends e{constructor(){super(),this.exclude=f.String("-e,--exclude",{validator:h.isString()})}async execute(){if(!g.default.commands)throw new Error("Yarn commands are not available!");const a=await b.find(this.context.cwd,this.context.plugins),{workspace:e}=await c.find(a,this.context.cwd),f=[...e.manifest.dependencies,...e.manifest.devDependencies],h=j(f,this.exclude?this.exclude.split(" "):null),k=h.map(a=>i(a[1].scope,a[1].name)),l=d.from(g.default.commands);return l.runExit(["up",...k],this.context)}}return k.paths=[["up-all"]],k.usage={category:"Utilities",description:"Yarn 2 plugin that will upgrade all dependencies to their latest version with one simple command",details:"This command will upgrade all dependencies to their latest version. You can exclude certain dependencies from being upgraded by using the `-e,--exclude` option.",examples:[["Upgrade all dependencies","yarn up-all"],["Upgrade all dependencies but exclude a single dependency","yarn up-all --exclude package"],["Upgrade all dependencies but exclude a single dependency","yarn up-all -e package"],["Upgrade all dependencies but exclude multiple dependencies","yarn up-all --exclude \"package1 package2\""]]},{commands:[k]}}}; |
Large diffs are not rendered by default.
Oops, something went wrong.
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,7 @@ | ||
nodeLinker: node-modules | ||
|
||
plugins: | ||
- path: .yarn/plugins/yarn-up-all-plugin.cjs | ||
spec: "https://github.com/e5mode/yarn-up-all/releases/download/1.1.0/index.js" | ||
|
||
yarnPath: .yarn/releases/yarn-3.1.1.cjs |
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,28 @@ | ||
# SealCred Ledger contract | ||
|
||
## Usage | ||
|
||
1. Clone the repository with `git clone [email protected]:BigWhaleLabs/seal-cred-ledger-contract.git` | ||
2. Install the dependencies with `yarn` | ||
3. Add environment vareables to your `.env` file | ||
4. Run the scripts below | ||
|
||
## Environment variables | ||
|
||
| Name | Description | | ||
| ---------------------------- | --------------------------------- | | ||
| `ETHERSCAN_API_KEY` | Etherscan API key | | ||
| `RPC_URL` | RPC URL | | ||
| `CONTRACT_OWNER_PRIVATE_KEY` | Private key of the contract owner | | ||
|
||
Also check out the `.env.example` file for more information. | ||
|
||
## Available scripts | ||
|
||
- `yarn compile` — compiles the contract ts interface to the `typechain` directory | ||
- `yarn test` — runs the test suite | ||
- `yarn deploy` — deploys the contract to the network | ||
- `yarn eth-lint` — runs the linter for the solidity contract | ||
- `yarn lint` — runs all the linters | ||
- `yarn prettify` — prettifies the code in th project | ||
- `yarn release` — relases the `typechain` directory to NPM |
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,62 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity ^0.8.4; | ||
|
||
import "@openzeppelin/contracts/token/ERC721/ERC721.sol"; | ||
import "@openzeppelin/contracts/utils/Counters.sol"; | ||
import "@openzeppelin/contracts/access/Ownable.sol"; | ||
import "./SealCredLedger.sol"; | ||
import "./Verifier.sol"; | ||
|
||
contract SCERC721Derivative is ERC721, Ownable { | ||
using Counters for Counters.Counter; | ||
|
||
Counters.Counter public tokenId; | ||
SealCredLedger public sealCred; | ||
address public immutable sealCredMapAddress; | ||
address private verifier; | ||
|
||
constructor( | ||
address _sealCredMapAddress, | ||
address _sealCredContractAddress, | ||
string memory tokenName, | ||
string memory tokenSymbol, | ||
address _verifier | ||
) ERC721(tokenName, tokenSymbol) { | ||
sealCred = SealCredLedger(_sealCredContractAddress); | ||
sealCredMapAddress = _sealCredMapAddress; | ||
verifier = _verifier; | ||
} | ||
|
||
function mint( | ||
uint256[2] memory a, | ||
uint256[2][2] memory b, | ||
uint256[2] memory c, | ||
uint256[2] memory input | ||
) external { | ||
require( | ||
bytes32(input[1]) == sealCred.getRoot(sealCredMapAddress), | ||
"Merkle Root does not match the contract" | ||
); | ||
require(Verifier(verifier).verifyProof(a, b, c, input), "Invalid Proof"); | ||
uint256 _tokenId = tokenId.current(); | ||
_safeMint(msg.sender, _tokenId); | ||
tokenId.increment(); | ||
} | ||
|
||
function _beforeTokenTransfer( | ||
address _from, | ||
address _to, | ||
uint256 _tokenId | ||
) internal override(ERC721) { | ||
super._beforeTokenTransfer(_from, _to, _tokenId); | ||
} | ||
|
||
function supportsInterface(bytes4 _interfaceId) | ||
public | ||
view | ||
override(ERC721) | ||
returns (bool) | ||
{ | ||
return 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,104 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity ^0.8.4; | ||
|
||
import "@openzeppelin/contracts/access/Ownable.sol"; | ||
import "@openzeppelin/contracts/token/ERC721/extensions/IERC721Metadata.sol"; | ||
import "./SCERC721Derivative.sol"; | ||
import "./Verifier.sol"; | ||
|
||
/** | ||
* @title SealCred Ledger | ||
* @dev Holds the Merkle roots for the registered ERC-721 tokens | ||
*/ | ||
contract SealCredLedger is Ownable { | ||
// State | ||
mapping(address => bytes32) private ledger; | ||
mapping(address => address) private tokenToDerivative; | ||
Verifier private verifier; | ||
// Events | ||
event SetMerkleRoot(address tokenAddress, bytes32 merkleRoot); | ||
event DeleteMerkleRoot(address tokenAddress); | ||
event CreateDerivative( | ||
address derivativeAddress, | ||
address sealCredMapAddress, | ||
address sealCredContractAddress, | ||
string tokenName, | ||
string tokenSymbol, | ||
address verifier | ||
); | ||
// Structs | ||
struct Root { | ||
address tokenAddress; | ||
bytes32 merkleRoot; | ||
} | ||
|
||
constructor() { | ||
verifier = new Verifier(); | ||
} | ||
|
||
function addRoots(Root[] memory roots) external onlyOwner { | ||
for (uint256 i = 0; i < roots.length; i++) { | ||
Root memory _currentRoot = roots[i]; | ||
IERC721Metadata metadata = IERC721Metadata(_currentRoot.tokenAddress); | ||
SCERC721Derivative derivative = new SCERC721Derivative( | ||
_currentRoot.tokenAddress, | ||
address(this), | ||
string(bytes.concat(bytes(metadata.name()), bytes(" (derivative)"))), | ||
string(bytes.concat(bytes(metadata.symbol()), bytes("-d"))), | ||
address(verifier) | ||
); | ||
emit CreateDerivative( | ||
address(derivative), | ||
_currentRoot.tokenAddress, | ||
address(this), | ||
string(bytes.concat(bytes(metadata.name()), bytes(" (derivative)"))), | ||
string(bytes.concat(bytes(metadata.symbol()), bytes("-d"))), | ||
address(verifier) | ||
); | ||
ledger[_currentRoot.tokenAddress] = _currentRoot.merkleRoot; | ||
tokenToDerivative[_currentRoot.tokenAddress] = address(derivative); | ||
emit SetMerkleRoot(_currentRoot.tokenAddress, _currentRoot.merkleRoot); | ||
} | ||
} | ||
|
||
/** | ||
* @dev Sets the Merkle roots for given ERC-721 tokens | ||
*/ | ||
function setRoots(Root[] memory roots) external onlyOwner { | ||
for (uint256 i = 0; i < roots.length; i++) { | ||
Root memory _currentRoot = roots[i]; | ||
|
||
if (ledger[_currentRoot.tokenAddress] != 0) { | ||
ledger[_currentRoot.tokenAddress] = _currentRoot.merkleRoot; | ||
emit SetMerkleRoot(_currentRoot.tokenAddress, _currentRoot.merkleRoot); | ||
} | ||
} | ||
} | ||
|
||
/** | ||
* @dev Returns the Merkle root for a given ERC-721 token | ||
*/ | ||
function getRoot(address tokenAddress) external view returns (bytes32) { | ||
return ledger[tokenAddress]; | ||
} | ||
|
||
/** | ||
* @dev Returns the drivative of a given ERC-721 token | ||
*/ | ||
function getDerivativeAddress(address tokenAddress) | ||
external | ||
view | ||
returns (address) | ||
{ | ||
return tokenToDerivative[tokenAddress]; | ||
} | ||
|
||
/** | ||
* @dev Deletes the Merkle root and derivative for a given ERC-721 token | ||
*/ | ||
function deleteRoot(address tokenAddress) external onlyOwner { | ||
delete ledger[tokenAddress]; | ||
delete tokenToDerivative[tokenAddress]; | ||
emit DeleteMerkleRoot(tokenAddress); | ||
} | ||
} |
Oops, something went wrong.