-
Notifications
You must be signed in to change notification settings - Fork 0
feat: adds erc20 wrapper example project #6
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
Open
sudoFerraz
wants to merge
15
commits into
main
Choose a base branch
from
feat/viol-1109-erc20-wrapper
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
3754624
feat: adds erc20 wrapper example project
sudoFerraz 3d1aa62
Updates README
sudoFerraz a347e54
fix: removes bytecode used on create2 operation
sudoFerraz f394bae
fix: removes unnecessary comment on deploy script
sudoFerraz baf2cfc
fix: removes unnecessary comment on compliantFactory tests
sudoFerraz 75b9641
adding styling updates
pedroapfilho efcbdf0
Merge pull request #7 from violetprotocol/fix/styling-updates
sudoFerraz f964b5c
Update erc20-wrapper-registry/README.md
sudoFerraz 0bfd0b4
Update erc20-wrapper-registry/README.md
sudoFerraz 86f933c
Update erc20-wrapper-registry/contracts/CompliantERC20.sol
sudoFerraz 5e15c21
fix: multiple review comments handled
sudoFerraz 480a3c8
Adds functional components to frontend code
sudoFerraz 0989d53
Removes isWriteLoading from index useEffect in favor of functional co…
sudoFerraz 8cdf9b4
formatting
ra-phael c67b3ae
changes deployed confirmation message
sudoFerraz File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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,37 @@ | ||
| # ERC20 Wrapper - Violet ID example | ||
|
|
||
| This project aims to demonstrate a simple example of how to wrap ERC20 tokens to a compliant version of it using VioletID. It comes with a sample Factory contract, and a CompliantERC20 contract on Optimism Goerli. | ||
|
|
||
| You can check a frontend with a live version of this demo [here](https://erc20-wrapper.violet.co/). | ||
| The frontend is located on the `frontend` folder, all relevant code can be found on the `frontend/pages/index.tsx` file | ||
|
|
||
| Find all VioletID live addresses in our [docs](https://docs.violet.co). | ||
|
|
||
|
|
||
| ## Setup | ||
|
|
||
| #### Install the project by running the command | ||
|
|
||
| ```shell | ||
| yarn install | ||
| ``` | ||
|
|
||
| #### Compile the test contract | ||
|
|
||
| ```shell | ||
| yarn hardhat compile | ||
| ``` | ||
|
|
||
| #### Deploy the test contract on optimismGoerli: | ||
|
|
||
| ```shell | ||
| yarn hardhat run scripts/deploy.ts --network optimismGoerli | ||
| ``` | ||
|
|
||
|
|
||
| #### Run the frontend locally | ||
|
|
||
| ```shell | ||
| cd frontend | ||
| yarn dev | ||
| ``` |
This file contains hidden or 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,71 @@ | ||
| // SPDX-License-Identifier: MIT | ||
|
|
||
| pragma solidity ^0.8.20; | ||
|
|
||
| import "@openzeppelin/contracts/token/ERC20/ERC20.sol"; | ||
| import {IVioletID} from "@violetprotocol/violetid/contracts/IVioletID.sol"; | ||
|
|
||
| error AccountWithoutVioletIDRequiredStatus(); | ||
|
|
||
| /** | ||
| * @dev ERC20 token contract that only allows wrapping and unwraping to valid VioletID holders | ||
| * | ||
| * Currently uses the VioletID status 1 representing enrollment, which includes initial screening and KYC/KYB. | ||
| */ | ||
| contract CompliantERC20 is ERC20 { | ||
| IERC20 permissionlessERC20; | ||
| uint256 public tokensWrapped; | ||
| IVioletID violetID; | ||
|
|
||
| constructor( | ||
| string memory name_, | ||
| string memory symbol_, | ||
| address violetID_, | ||
| address _nonCompliantERC20 | ||
| ) ERC20(name_, symbol_) { | ||
| violetID = IVioletID(violetID_); | ||
| permissionlessERC20 = IERC20(_nonCompliantERC20); | ||
| } | ||
|
|
||
| modifier onlyVioletIDHolders(address account) { | ||
| uint8 isEnrolledStatus = 1; | ||
| require( | ||
| violetID.hasStatus(account, isEnrolledStatus), | ||
| "account does not have a VioletID" | ||
| ); | ||
| if (!violetID.hasStatus(account, isEnrolledStatus)) | ||
| revert AccountWithoutVioletIDRequiredStatus(); | ||
| _; | ||
| } | ||
|
|
||
| // All customizations to transfers, mints, and burns should be done by overriding this function. | ||
| // https://docs.openzeppelin.com/contracts/5.x/api/token/erc20#ERC20-_transfer-address-address-uint256- | ||
| // Adding the onlyVioletIDHolders modifier ensures only addresses with VioletID status receive tokens | ||
| function _update( | ||
| address from, | ||
| address to, | ||
| uint256 amount | ||
| ) internal virtual override onlyVioletIDHolders(to) { | ||
| super._update(from, to, amount); | ||
| } | ||
|
|
||
| function wrap( | ||
| uint256 amount | ||
| ) public virtual onlyVioletIDHolders(msg.sender) { | ||
| permissionlessERC20.transferFrom(msg.sender, address(this), amount); | ||
| tokensWrapped += amount; | ||
| super._mint(msg.sender, amount); | ||
| } | ||
|
|
||
| function unwrap( | ||
| uint256 amount | ||
| ) public virtual onlyVioletIDHolders(msg.sender) { | ||
| require( | ||
| tokensWrapped >= amount, | ||
| "cERC20_unwrap: amount to unwrap exceeds total wrapped" | ||
| ); | ||
| tokensWrapped -= amount; | ||
| _burn(msg.sender, amount); | ||
| permissionlessERC20.transfer(msg.sender, amount); | ||
| } | ||
| } |
This file contains hidden or 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,33 @@ | ||
| // SPDX-License-Identifier: MIT | ||
|
|
||
| pragma solidity ^0.8.20; | ||
|
|
||
| import "@openzeppelin/contracts/token/ERC20/ERC20.sol"; | ||
| import {IVioletID} from "@violetprotocol/violetid/contracts/IVioletID.sol"; | ||
| import "./CompliantERC20.sol"; | ||
|
|
||
| /** | ||
| * @dev ERC20 token factory that builds a new ERC20 using the previous token address | ||
| * | ||
| * Saves the new wrapped token address on the erc20ToCompliantWrapped mapping | ||
| */ | ||
| contract CompliantFactory { | ||
| mapping(address => address) public erc20ToCompliantWrapped; | ||
|
|
||
| function deployCompliantErc( | ||
| address nonCompliantERC20, | ||
| address violetId_ | ||
| ) public payable { | ||
| address compliantErc20 = address( | ||
| new CompliantERC20{ | ||
| salt: keccak256(abi.encodePacked(nonCompliantERC20)) | ||
| }( | ||
| string.concat("c", ERC20(nonCompliantERC20).name()), | ||
| string.concat("c", ERC20(nonCompliantERC20).symbol()), | ||
| violetId_, | ||
| nonCompliantERC20 | ||
| ) | ||
| ); | ||
| erc20ToCompliantWrapped[nonCompliantERC20] = compliantErc20; | ||
| } | ||
| } | ||
This file contains hidden or 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 @@ | ||
| //SPDX-License-Identifier: MIT | ||
| pragma solidity ^0.8.14; | ||
|
|
||
| import "@openzeppelin/contracts/token/ERC20/ERC20.sol"; | ||
|
|
||
| contract MockERC20 is ERC20 { | ||
| constructor( | ||
| string memory name_, | ||
| string memory symbol_ | ||
| ) ERC20(name_, symbol_) {} | ||
|
|
||
| function mint(address account, uint256 amount) public virtual { | ||
| _mint(account, amount); | ||
| } | ||
| } |
This file contains hidden or 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 @@ | ||
| { | ||
| "extends": "next/core-web-vitals" | ||
| } |
This file contains hidden or 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,39 @@ | ||
| # See https://help.github.com/articles/ignoring-files/ for more about ignoring files. | ||
|
|
||
| # dependencies | ||
| /node_modules | ||
| /.pnp | ||
| .pnp.js | ||
|
|
||
| # testing | ||
| /coverage | ||
|
|
||
| # next.js | ||
| /.next/ | ||
| /out/ | ||
|
|
||
| # production | ||
| /build | ||
|
|
||
| # misc | ||
| .DS_Store | ||
| *.pem | ||
|
|
||
| # debug | ||
| npm-debug.log* | ||
| yarn-debug.log* | ||
| yarn-error.log* | ||
| .pnpm-debug.log* | ||
|
|
||
| # local env files | ||
| .env | ||
| .env.local | ||
| .env.development.local | ||
| .env.test.local | ||
| .env.production.local | ||
|
|
||
| # vercel | ||
| .vercel | ||
|
|
||
| # typescript | ||
| *.tsbuildinfo |
This file contains hidden or 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,5 @@ | ||
| module.exports = { | ||
| semi: false, | ||
| singleQuote: true, | ||
| trailingComma: 'all', | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How strong do you feel about this renaming? Asking bc with that, I will need to re-do all the fixtures and mocks + redeploy and change the frontend code to comply with the renaming
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok nevermind! 😅